lsInitRelations

decompiled_code:
__int64 __fastcall lsInitRelations(__int64 a1)
{
__int64 v1; // rbx

v1 = dbGetObject(a1);
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 3));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 4));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 5));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 6));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 7));
return AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 10));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx

v1 = dbGetObject(a1);
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 3));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 4));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 5));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 6));
AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 7));
return AddRelation((unsigned int)(*(_DWORD *)(v1 + 20) + 10));
}

original_code:
void lsInitRelations(U32 areaID)
{
    LSArea area = dbGetObject(areaID);
    AddRelation(area->ul_ObjectBaseNr + 3);
    AddRelation(area->ul_ObjectBaseNr + 4);
    AddRelation(area->ul_ObjectBaseNr + 5);
    AddRelation(area->ul_ObjectBaseNr + 6);
    AddRelation(area->ul_ObjectBaseNr + 7);
    AddRelation(area->ul_ObjectBaseNr + 10);
}

canonical_original_code:
void lsInitRelations(unsigned int areaID)
{
    struct _LSArea *area = dbGetObject(areaID);
    AddRelation(area->ul_ObjectBaseNr + 3);
    AddRelation(area->ul_ObjectBaseNr + 4);
    AddRelation(area->ul_ObjectBaseNr + 5);
    AddRelation(area->ul_ObjectBaseNr + 6);
    AddRelation(area->ul_ObjectBaseNr + 7);
    AddRelation(area->ul_ObjectBaseNr + 10);
}

variable_types:
areaID
unsigned int

variable_types: struct _LSArea { unsigned short us_Coll16ID; unsigned short us_Coll32ID; unsigned short us_Coll48ID; unsigned short us_PlanColl16ID; unsigned short us_PlanColl32ID; unsigned short us_PlanColl48ID; unsigned short us_FloorCollID; unsigned short us_PlanFloorCollID; unsigned short us_Width; unsigned short us_Height; unsigned int ul_ObjectBaseNr; unsigned char uch_Darkness; unsigned short us_StartX0; unsigned short us_StartX1; unsigned short us_StartX2; unsigned short us_StartX3; unsigned short us_StartX4; unsigned short us_StartX5; unsigned short us_StartY0; unsigned short us_StartY1; unsigned short us_StartY2; unsigned short us_StartY3; unsigned short us_StartY4; unsigned short us_StartY5; } *


lsSetRelations

repo: vcosta/derclou

decompiled_code:
__int64 __fastcall lsSetRelations(__int64 a1)
{
int v1; // eax
int v2; // ecx
int v3; // esi
int v4; // edi
int v5; // er8
__int64 result; // rax

v1 = *(_DWORD *)(dbGetObject(a1) + 20);
v2 = v1 + 4;
v3 = v1 + 5;
v4 = v1 + 6;
ConsistOfRelationID = v1 + 3;
v5 = v1 + 7;
result = (unsigned int)(v1 + 10);
hasLockRelationID = v2;
hasAlarmRelationID = v3;
hasPowerRelationID = v4;
hasLootRelationID = v5;
hasRoomRelationID = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // eax
int v2; // ecx
int v3; // esi
int v4; // edi
int v5; // er8
__int64 result; // rax

v1 = *(_DWORD *)(dbGetObject(a1) + 20);
v2 = v1 + 4;
v3 = v1 + 5;
v4 = v1 + 6;
ConsistOfRelationID = v1 + 3;
v5 = v1 + 7;
result = (unsigned int)(v1 + 10);
hasLockRelationID = v2;
hasAlarmRelationID = v3;
hasPowerRelationID = v4;
hasLootRelationID = v5;
hasRoomRelationID = result;
return result;
}

original_code:
void lsSetRelations(U32 areaID)
{
    LSArea area = dbGetObject(areaID);
    ConsistOfRelationID = area->ul_ObjectBaseNr + 3;
    hasLockRelationID = area->ul_ObjectBaseNr + 4;
    hasAlarmRelationID = area->ul_ObjectBaseNr + 5;
    hasPowerRelationID = area->ul_ObjectBaseNr + 6;
    hasLootRelationID = area->ul_ObjectBaseNr + 7;
    hasRoomRelationID = area->ul_ObjectBaseNr + 10;
}

canonical_original_code:
void lsSetRelations(unsigned int areaID)
{
    struct _LSArea *area = dbGetObject(areaID);
    ConsistOfRelationID = area->ul_ObjectBaseNr + 3;
    hasLockRelationID = area->ul_ObjectBaseNr + 4;
    hasAlarmRelationID = area->ul_ObjectBaseNr + 5;
    hasPowerRelationID = area->ul_ObjectBaseNr + 6;
    hasLootRelationID = area->ul_ObjectBaseNr + 7;
    hasRoomRelationID = area->ul_ObjectBaseNr + 10;
}

return_type: void

user_defined_types: struct _LSArea { unsigned short us_Coll16ID; unsigned short us_Coll32ID; unsigned short us_Coll48ID; unsigned short us_PlanColl16ID; unsigned short us_PlanColl32ID; unsigned short us_PlanColl48ID; unsigned short us_FloorCollID; unsigned short us_PlanFloorCollID; unsigned short us_Width; unsigned short us_Height; unsigned int ul_ObjectBaseNr; unsigned char uch_Darkness; unsigned short us_StartX0; unsigned short us_StartX1; unsigned short us_StartX2; unsigned short us_StartX3; unsigned short us_StartX4; unsigned short us_StartX5; unsigned short us_StartY0; unsigned short us_StartY1; unsigned short us_StartY2; unsigned short us_StartY3; unsigned short us_StartY4; unsigned short us_StartY5; }


lsInitActivArea

decompiled_code:
__int64 __fastcall lsInitActivArea(__int64 a1, unsigned __int16 a2, unsigned __int16 a3)
{
unsigned __int16 v3; // r15
unsigned __int16 v4; // r14
unsigned __int16 *v7; // rbx
__int64 v8; // rcx
unsigned __int16 v9; // si

v3 = a3;
v4 = a2;
v7 = (unsigned __int16 *)dbGetObject(a1);
*(_DWORD *)(ls + 4LL) = a1;
lsSetRelations((unsigned int)a1);
lsSetObjectRetrievalList((unsigned int)a1);
v8 = ls;
v9 = v7[9];
*(_WORD *)(ls + 10LL) = v7[8];
*(_WORD *)(v8 + 12) = v9;
if ( a2 == 0xFFFF )
v4 = v7[13];
if ( a3 == 0xFFFF )
v3 = v7[19];
lsSetVisibleWindow(v4, v3);
livSetActivAreaId((unsigned int)a1);
lsSetCurrFloorSquares(a1);
gfxCollToMem(*v7, &AnimRPInMem);
gfxCollToMem(v7[1], &AddRPInMem);
gfxCollToMem(v7[2], &LSObjectRPInMem);
gfxCollToMem(v7[6], &LSFloorRPInMem);
lsBuildScrollWindow();
return lsRefreshAllLootBags();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int16 a2, unsigned __int16 a3)
{
unsigned __int16 v3; // r15
unsigned __int16 v4; // r14
unsigned __int16 *v7; // rbx
__int64 v8; // rcx
unsigned __int16 v9; // si

v3 = a3;
v4 = a2;
v7 = (unsigned __int16 *)dbGetObject(a1);
*(_DWORD *)(ls + 4LL) = a1;
func5((unsigned int)a1);
lsSetObjectRetrievalList((unsigned int)a1);
v8 = ls;
v9 = v7[9];
*(_WORD *)(ls + 10LL) = v7[8];
*(_WORD *)(v8 + 12) = v9;
if ( a2 == 0xFFFF )
v4 = v7[13];
if ( a3 == 0xFFFF )
v3 = v7[19];
lsSetVisibleWindow(v4, v3);
livSetActivAreaId((unsigned int)a1);
func0(a1);
gfxCollToMem(*v7, &AnimRPInMem);
gfxCollToMem(v7[1], &AddRPInMem);
gfxCollToMem(v7[2], &LSObjectRPInMem);
gfxCollToMem(v7[6], &LSFloorRPInMem);
lsBuildScrollWindow();
return lsRefreshAllLootBags();
}

original_code:
void lsInitActivArea(U32 areaID, uword x, uword y, char *livingName)
{
    LSArea area = (LSArea) dbGetObject(areaID);
    ls->ul_AreaID = areaID;
    lsSetRelations(areaID);
    lsSetObjectRetrievalList(areaID);
    ls->us_WindowXSize = area->us_Width;
    ls->us_WindowYSize = area->us_Height;
    if (x == (uword) - 1)
 x = area->us_StartX0;
    if (y == (uword) - 1)
 y = area->us_StartY0;
    lsSetVisibleWindow(x, y);
    livSetActivAreaId(areaID);
    lsSetCurrFloorSquares(areaID);
    gfxCollToMem(area->us_Coll16ID, &AnimRPInMem);
    gfxCollToMem(area->us_Coll32ID, &AddRPInMem);
    gfxCollToMem(area->us_Coll48ID, &LSObjectRPInMem);
    gfxCollToMem(area->us_FloorCollID, &LSFloorRPInMem);
    lsBuildScrollWindow();
    lsRefreshAllLootBags();
}

canonical_original_code:
void lsInitActivArea(unsigned int areaID, unsigned short x, unsigned short y, char *livingName)
{
    struct _LSArea *area = (LSArea) dbGetObject(areaID);
    ls->ul_AreaID = areaID;
    lsSetRelations(areaID);
    lsSetObjectRetrievalList(areaID);
    ls->us_WindowXSize = area->us_Width;
    ls->us_WindowYSize = area->us_Height;
    if (x == (uword) - 1)
 x = area->us_StartX0;
    if (y == (uword) - 1)
 y = area->us_StartY0;
    lsSetVisibleWindow(x, y);
    livSetActivAreaId(areaID);
    lsSetCurrFloorSquares(areaID);
    gfxCollToMem(area->us_Coll16ID, &AnimRPInMem);
    gfxCollToMem(area->us_Coll32ID, &AddRPInMem);
    gfxCollToMem(area->us_Coll48ID, &LSObjectRPInMem);
    gfxCollToMem(area->us_FloorCollID, &LSFloorRPInMem);
    lsBuildScrollWindow();
    lsRefreshAllLootBags();
}

variable_types:
x
unsigned short

variable_types:
y
unsigned short

variable_types:
livingName
char *


lsLoadGlobalData

decompiled_code:
__int64 __fastcall lsLoadGlobalData(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3[257]; // [rsp+1h] [rbp-309h]
char v4[256]; // [rsp+2h] [rbp-308h] BYREF
char v5[520]; // [rsp+102h] [rbp-208h] BYREF

dbGetObjectName(a2, v4);
v3[strlen(v4)] = 0;
strcat(v4, ".gre");
dskBuildPathName(0LL, "data", v4, v5);
result = LoadRelations(v5, 0LL);
if ( !(_DWORD)result )
result = ErrorMsg(3LL, 10LL, 2LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
__int64 result; // rax
char v3[257]; // [rsp+1h] [rbp-309h]
char v4[256]; // [rsp+2h] [rbp-308h] BYREF
char v5[520]; // [rsp+102h] [rbp-208h] BYREF

dbGetObjectName(a2, v4);
v3[strlen(v4)] = 0;
strcat(v4, ".gre");
dskBuildPathName(0LL, "data", v4, v5);
result = LoadRelations(v5, 0LL);
if ( !(_DWORD)result )
result = ErrorMsg(3LL, 10LL, 2LL);
return result;
}

original_code:
void lsLoadGlobalData(U32 bld, U32 ul_AreaId)
{
    char areaName[256], fileName[512];
    dbGetObjectName(ul_AreaId, areaName);
    areaName[strlen(areaName) - 1] = '\0';
    strcat(areaName, (".gre"));
    dskBuildPathName(DISK_CHECK_FILE, "data", areaName, fileName);
    if (!(LoadRelations(fileName, 0)))
 ErrorMsg(Disk_Defect, ERROR_MODULE_LANDSCAP, 2);
}

canonical_original_code:
void lsLoadGlobalData(unsigned int bld, unsigned int ul_AreaId)
{
    char areaName[256]; char fileName[512];
    dbGetObjectName(ul_AreaId, areaName);
    areaName[strlen(areaName) - 1] = '\0';
    strcat(areaName, (".gre"));
    dskBuildPathName(DISK_CHECK_FILE, "data", areaName, fileName);
    if (!(LoadRelations(fileName, 0)))
 ErrorMsg(Disk_Defect, ERROR_MODULE_LANDSCAP, 2);
}

variable_types:
bld
unsigned int

variable_types:
areaName
char [256]

variable_types:
fileName
char [512]


lsInitObjectDB

decompiled_code:
__int64 __fastcall lsInitObjectDB(__int64 a1, unsigned int a2)
{
char v3[256]; // [rsp+0h] [rbp-308h] BYREF
char v4[520]; // [rsp+100h] [rbp-208h] BYREF

dbGetObjectName(a2, v3);
strcat(v3, ".dat");
dskBuildPathName(0LL, "data", v3, v4);
dbSetLoadObjectsMode(0LL);
if ( (unsigned __int8)dbLoadAllObjects(v4, 0LL) )
{
dbGetObjectName(a2, v3);
strcat(v3, ".rel");
dskBuildPathName(0LL, "data", v3, v4);
if ( !(unsigned int)LoadRelations(v4, 0LL) )
ErrorMsg(3LL, 10LL, 3LL);
}
else
{
ErrorMsg(3LL, 10LL, 4LL);
}
return dbSetLoadObjectsMode(1LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
char v3[256]; // [rsp+0h] [rbp-308h] BYREF
char v4[520]; // [rsp+100h] [rbp-208h] BYREF

dbGetObjectName(a2, v3);
strcat(v3, ".dat");
dskBuildPathName(0LL, "data", v3, v4);
dbSetLoadObjectsMode(0LL);
if ( (unsigned __int8)dbLoadAllObjects(v4, 0LL) )
{
dbGetObjectName(a2, v3);
strcat(v3, ".rel");
dskBuildPathName(0LL, "data", v3, v4);
if ( !(unsigned int)LoadRelations(v4, 0LL) )
ErrorMsg(3LL, 10LL, 3LL);
}
else
{
ErrorMsg(3LL, 10LL, 4LL);
}
return dbSetLoadObjectsMode(1LL);
}

original_code:
void lsInitObjectDB(U32 bld, U32 areaID)
{
    char fileName[512], areaName[256];
    dbGetObjectName(areaID, areaName);
    strcat(areaName, (".dat"));
    dskBuildPathName(DISK_CHECK_FILE, "data", areaName, fileName);
    dbSetLoadObjectsMode(0);
    if (dbLoadAllObjects(fileName, 0)) {
 dbGetObjectName(areaID, areaName);
 strcat(areaName, (".rel"));
 dskBuildPathName(DISK_CHECK_FILE, "data", areaName, fileName);
 if (!(LoadRelations(fileName, 0)))
     ErrorMsg(Disk_Defect, ERROR_MODULE_LANDSCAP, 3);
    } else
 ErrorMsg(Disk_Defect, ERROR_MODULE_LANDSCAP, 4);
    dbSetLoadObjectsMode(1);
}

canonical_original_code:
void lsInitObjectDB(unsigned int bld, unsigned int areaID)
{
    char fileName[512]; char areaName[256];
    dbGetObjectName(areaID, areaName);
    strcat(areaName, (".dat"));
    dskBuildPathName(DISK_CHECK_FILE, "data", areaName, fileName);
    dbSetLoadObjectsMode(0);
    if (dbLoadAllObjects(fileName, 0)) {
 dbGetObjectName(areaID, areaName);
 strcat(areaName, (".rel"));
 dskBuildPathName(DISK_CHECK_FILE, "data", areaName, fileName);
 if (!(LoadRelations(fileName, 0)))
     ErrorMsg(Disk_Defect, ERROR_MODULE_LANDSCAP, 3);
    } else
 ErrorMsg(Disk_Defect, ERROR_MODULE_LANDSCAP, 4);
    dbSetLoadObjectsMode(1);
}


lsInitObjects

decompiled_code:
__int64 lsInitObjects()
{
__int64 v0; // rax
__int64 **v1; // r12
unsigned int *v2; // rdi
__int64 *v3; // rbx
bool v4; // zf
unsigned int v5; // ebp
unsigned int v6; // er8
__int64 v7; // rsi

SetObjectListAttr(4LL, 509992LL);
v0 = dbGetObject((unsigned int)*ls);
AskAll(v0, 500002LL, &BuildObjectList);
v1 = (__int64 **)ObjectListPrivate;
v2 = (unsigned int *)ls;
*(_QWORD *)(ls + 344LL) = 0LL;
v3 = *v1;
*((_QWORD *)v2 + 44) = 0LL;
*((_QWORD *)v2 + 45) = 0LL;
v4 = *v3 == 0;
*((_QWORD *)v2 + 46) = 0LL;
v2[94] = 0;
if ( !v4 )
{
v5 = 0;
do
{
lsInitRelations(*((unsigned int *)v3 + 8));
lsInitObjectDB((unsigned int)*ls, *((_DWORD *)v3 + 8));
lsSetRelations(*((unsigned int *)v3 + 8));
lsRefreshObjectList(*((unsigned int *)v3 + 8));
lsPatchObjects();
v2 = (unsigned int *)ls;
v6 = *((_DWORD *)v3 + 8);
v7 = v5;
v3 = (__int64 *)*v3;
++v5;
v4 = *v3 == 0;
*(_QWORD *)(ls + 8 * v7 + 344) = *(_QWORD *)(ls + 336LL);
v2[v7 + 92] = v6;
}
while ( !v4 );
}
lsLoadGlobalData(*v2, *(_DWORD *)(v3[1] + 32));
return RemoveList(v1);
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rax
__int64 **v1; // r12
unsigned int *v2; // rdi
__int64 *v3; // rbx
bool v4; // zf
unsigned int v5; // ebp
unsigned int v6; // er8
__int64 v7; // rsi

SetObjectListAttr(4LL, 509992LL);
v0 = dbGetObject((unsigned int)*ls);
AskAll(v0, 500002LL, &BuildObjectList);
v1 = (__int64 **)ObjectListPrivate;
v2 = (unsigned int *)ls;
*(_QWORD *)(ls + 344LL) = 0LL;
v3 = *v1;
*((_QWORD *)v2 + 44) = 0LL;
*((_QWORD *)v2 + 45) = 0LL;
v4 = *v3 == 0;
*((_QWORD *)v2 + 46) = 0LL;
v2[94] = 0;
if ( !v4 )
{
v5 = 0;
do
{
func4(*((unsigned int *)v3 + 8));
func8((unsigned int)*ls, *((_DWORD *)v3 + 8));
func5(*((unsigned int *)v3 + 8));
lsRefreshObjectList(*((unsigned int *)v3 + 8));
lsPatchObjects();
v2 = (unsigned int *)ls;
v6 = *((_DWORD *)v3 + 8);
v7 = v5;
v3 = (__int64 *)*v3;
++v5;
v4 = *v3 == 0;
*(_QWORD *)(ls + 8 * v7 + 344) = *(_QWORD *)(ls + 336LL);
v2[v7 + 92] = v6;
}
while ( !v4 );
}
func7(*v2, *(_DWORD *)(v3[1] + 32));
return RemoveList(v1);
}

original_code:
void lsInitObjects(void)
{
    U32 areaCount = 0, i;
    LIST *areas;
    NODE *n;
    { SetObjectListAttr ((1 << 2),509992L); AskAll (dbGetObject (ls->ul_BuildingID), 500002, BuildObjectList); };
    areas = ObjectListPrivate;
    for (i = 0; i < 3; i++) {
 ls->ul_ObjectRetrievalAreaId[i] = 0;
 ls->p_ObjectRetrievalLists[i] = ((void *)0);
    }
    for (n = (NODE *) ((((NODE *)((&((areas))->Head)))->Succ)); (((NODE *)(n))->Succ); n = (NODE *) (((NODE *)(n))->Succ)) {
 lsInitRelations((((struct ObjectNode *)n)->nr));
 lsInitObjectDB(ls->ul_BuildingID, (((struct ObjectNode *)n)->nr));
 lsSetRelations((((struct ObjectNode *)n)->nr));
 lsRefreshObjectList((((struct ObjectNode *)n)->nr));
 lsPatchObjects();
 ls->p_ObjectRetrievalLists[areaCount] = ls->p_ObjectRetrieval;
 ls->ul_ObjectRetrievalAreaId[areaCount] = (((struct ObjectNode *)n)->nr);
 areaCount++;
    }
    lsLoadGlobalData(ls->ul_BuildingID, (((struct ObjectNode *)(((NODE *)(n))->Pred))->nr));
    RemoveList(areas);
}

canonical_original_code:
void lsInitObjects()
{
    unsigned int areaCount = 0; unsigned int i;
    struct List *areas;
    struct Node *n;
    { SetObjectListAttr ((1 << 2),509992L); AskAll (dbGetObject (ls->ul_BuildingID), 500002, BuildObjectList); };
    areas = ObjectListPrivate;
    for (i = 0; i < 3; i++) {
 ls->ul_ObjectRetrievalAreaId[i] = 0;
 ls->p_ObjectRetrievalLists[i] = ((void *)0);
    }
    for (n = (struct Node *) ((((struct Node *)((&((areas))->Head)))->Succ)); (((struct Node *)(n))->Succ); n = (struct Node *) (((struct Node *)(n))->Succ)) {
 lsInitRelations((((struct ObjectNode *)n)->nr));
 lsInitObjectDB(ls->ul_BuildingID, (((struct ObjectNode *)n)->nr));
 lsSetRelations((((struct ObjectNode *)n)->nr));
 lsRefreshObjectList((((struct ObjectNode *)n)->nr));
 lsPatchObjects();
 ls->p_ObjectRetrievalLists[areaCount] = ls->p_ObjectRetrieval;
 ls->ul_ObjectRetrievalAreaId[areaCount] = (((struct ObjectNode *)n)->nr);
 areaCount++;
    }
    lsLoadGlobalData(ls->ul_BuildingID, (((struct ObjectNode *)(((struct Node *)(n))->Pred))->nr));
    RemoveList(areas);
}

variable_types:
areaCount
unsigned int

variable_types:
i
unsigned int

variable_types: struct List { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Head; struct Node Tail; } *

variable_types: struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } *

user_defined_types: struct List { struct Node Head; struct Node Tail; }

user_defined_types: struct ObjectNode { struct Node Link; unsigned int nr; unsigned int type; void *data; }


lsInitLandScape

decompiled_code:
__int64 __fastcall lsInitLandScape(int a1, unsigned __int8 a2)
{
_DWORD *v2; // rax
__int64 v3; // rax
unsigned int v4; // ebx
__int64 v5; // r12
__int64 v6; // rbp
_WORD *v7; // r12
__int64 v8; // rbp
__int64 v9; // rax
_WORD *v10; // r12
__int64 v11; // rbp
__int64 v12; // rax
_WORD *v13; // r12
__int64 v14; // rbp
__int64 v15; // rax
__int64 v16; // rdx
_WORD *v17; // r12
__int64 v18; // rbp
__int64 v19; // rax
__int64 v20; // rbx
__int64 v21; // rdi
__int64 v23; // [rsp-8h] [rbp-20h]

v2 = (_DWORD *)ls;
if ( !ls )
{
v2 = (_DWORD *)TCAllocMem(408LL, 0LL);
ls = v2;
}
*v2 = a1;
v2[99] = 0;
lsInitGfx();
v3 = ls;
v4 = 9701;
*(_BYTE *)(ls + 8LL) = 2;
*(_BYTE *)(v3 + 407) = 0;
lsSetCollMode(a2);
lsInitObjects();
lsInitSpots();
lsLoadAllSpots();
v5 = ls;
*(_WORD *)(ls + 22LL) = 5128;
*(_DWORD *)(v5 + 4) = lsGetStartArea();
BobInitLists();
v6 = ls;
*(_WORD *)(v6 + 400) = BobInit(14LL, 14LL);
do
{
v7 = (_WORD *)dbGetObject(v4);
*v7 = BobInit(14LL, 14LL);
v8 = dbGetObject(v4);
v9 = dbGetObject(*(unsigned int *)(ls + 4LL));
UnSet(v9, 19LL, v8);
v10 = (_WORD *)dbGetObject(v4 + 1);
*v10 = BobInit(14LL, 14LL);
v11 = dbGetObject(v4 + 1);
v12 = dbGetObject(*(unsigned int *)(ls + 4LL));
UnSet(v12, 19LL, v11);
v13 = (_WORD *)dbGetObject(v4 + 2);
*v13 = BobInit(14LL, 14LL);
v14 = dbGetObject(v4 + 2);
v15 = dbGetObject(*(unsigned int *)(ls + 4LL));
v16 = v14;
LODWORD(v14) = v4 + 3;
v4 += 4;
UnSet(v15, 19LL, v16);
v17 = (_WORD *)dbGetObject((unsigned int)v14);
*v17 = BobInit(14LL, 14LL);
v18 = dbGetObject((unsigned int)v14);
v19 = dbGetObject(*(unsigned int *)(ls + 4LL));
UnSet(v19, 19LL, v18);
}
while ( v4 != 9709 );
livInit(0LL, 0LL, 320LL, 128LL, 640LL, 256LL, 8LL, *(unsigned int *)(ls + 4LL));
v20 = ls;
*(_QWORD *)(ls + 288LL) = 0LL;
*(_DWORD *)(v20 + 402) = 0x200000;
*(_QWORD *)(v20 + 384) = CreateList();
lsInitFloorSquares();
v21 = *(unsigned int *)(ls + 4LL);
lsInitActivArea(v21, 0xFFFFu, 0xFFFFu);
return lsShowEscapeCar(v21, 0xFFFFLL, v23);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, unsigned __int8 a2)
{
_DWORD *v2; // rax
__int64 v3; // rax
unsigned int v4; // ebx
__int64 v5; // r12
__int64 v6; // rbp
_WORD *v7; // r12
__int64 v8; // rbp
__int64 v9; // rax
_WORD *v10; // r12
__int64 v11; // rbp
__int64 v12; // rax
_WORD *v13; // r12
__int64 v14; // rbp
__int64 v15; // rax
__int64 v16; // rdx
_WORD *v17; // r12
__int64 v18; // rbp
__int64 v19; // rax
__int64 v20; // rbx
__int64 v21; // rdi
__int64 v23; // [rsp-8h] [rbp-20h]

v2 = (_DWORD *)ls;
if ( !ls )
{
v2 = (_DWORD *)TCAllocMem(408LL, 0LL);
ls = v2;
}
*v2 = a1;
v2[99] = 0;
lsInitGfx();
v3 = ls;
v4 = 9701;
*(_BYTE *)(ls + 8LL) = 2;
*(_BYTE *)(v3 + 407) = 0;
lsSetCollMode(a2);
func9();
lsInitSpots();
func1();
v5 = ls;
*(_WORD *)(ls + 22LL) = 5128;
*(_DWORD *)(v5 + 4) = lsGetStartArea();
BobInitLists();
v6 = ls;
*(_WORD *)(v6 + 400) = BobInit(14LL, 14LL);
do
{
v7 = (_WORD *)dbGetObject(v4);
*v7 = BobInit(14LL, 14LL);
v8 = dbGetObject(v4);
v9 = dbGetObject(*(unsigned int *)(ls + 4LL));
UnSet(v9, 19LL, v8);
v10 = (_WORD *)dbGetObject(v4 + 1);
*v10 = BobInit(14LL, 14LL);
v11 = dbGetObject(v4 + 1);
v12 = dbGetObject(*(unsigned int *)(ls + 4LL));
UnSet(v12, 19LL, v11);
v13 = (_WORD *)dbGetObject(v4 + 2);
*v13 = BobInit(14LL, 14LL);
v14 = dbGetObject(v4 + 2);
v15 = dbGetObject(*(unsigned int *)(ls + 4LL));
v16 = v14;
LODWORD(v14) = v4 + 3;
v4 += 4;
UnSet(v15, 19LL, v16);
v17 = (_WORD *)dbGetObject((unsigned int)v14);
*v17 = BobInit(14LL, 14LL);
v18 = dbGetObject((unsigned int)v14);
v19 = dbGetObject(*(unsigned int *)(ls + 4LL));
UnSet(v19, 19LL, v18);
}
while ( v4 != 9709 );
livInit(0LL, 0LL, 320LL, 128LL, 640LL, 256LL, 8LL, *(unsigned int *)(ls + 4LL));
v20 = ls;
*(_QWORD *)(ls + 288LL) = 0LL;
*(_DWORD *)(v20 + 402) = 0x200000;
*(_QWORD *)(v20 + 384) = CreateList();
func2();
v21 = *(unsigned int *)(ls + 4LL);
func6(v21, 0xFFFFu, 0xFFFFu);
return lsShowEscapeCar(v21, 0xFFFFLL, v23);
}

original_code:
void lsInitLandScape(U32 bID, ubyte mode)
{
    S32 i;
    if (!ls)
 ls = TCAllocMem(sizeof(*ls), 0);
    ls->ul_BuildingID = bID;
    ls->us_RasInfoScrollX = 0;
    ls->us_RasInfoScrollY = 0;
    lsInitGfx();
    ls->uch_ScrollSpeed = 2;
    ls->uch_ShowObjectMask = 0;
    lsSetCollMode(mode);
    lsInitObjects();
    lsInitSpots();
    lsLoadAllSpots();
    ls->uch_FloorsPerWindowColumn = (ubyte) ((256/32));
    ls->uch_FloorsPerWindowLine = (ubyte) ((640/32));
    ls->ul_AreaID = lsGetStartArea();
    BobInitLists();
    ls->us_EscapeCarBobId = BobInit(14, 14);
    for (i = 9701; i <= 9708; i++) {
 LSObject lso = dbGetObject(i);
 lso->us_OffsetFact = BobInit(14, 14);
 UnSet (dbGetObject (ls->ul_AreaID), 19, dbGetObject ((U32) i));
    }
    livInit(0, 0, 320, 128, 640,
     256, 8, ls->ul_AreaID);
    ls->p_CurrFloor = ((void *)0);
    ls->us_DoorXOffset = 0;
    ls->us_DoorYOffset = 32;
    ls->p_DoorRefreshList = CreateList();
    lsInitFloorSquares();
    lsInitActivArea(ls->ul_AreaID, (uword) - 1, (uword) - 1, ((void *)0));
    lsShowEscapeCar();
}

canonical_original_code:
void lsInitLandScape(unsigned int bID, unsigned char mode)
{
    int i;
    if (!ls)
 ls = TCAllocMem(sizeof(*ls), 0);
    ls->ul_BuildingID = bID;
    ls->us_RasInfoScrollX = 0;
    ls->us_RasInfoScrollY = 0;
    lsInitGfx();
    ls->uch_ScrollSpeed = 2;
    ls->uch_ShowObjectMask = 0;
    lsSetCollMode(mode);
    lsInitObjects();
    lsInitSpots();
    lsLoadAllSpots();
    ls->uch_FloorsPerWindowColumn = (ubyte) ((256/32));
    ls->uch_FloorsPerWindowLine = (ubyte) ((640/32));
    ls->ul_AreaID = lsGetStartArea();
    BobInitLists();
    ls->us_EscapeCarBobId = BobInit(14, 14);
    for (i = 9701; i <= 9708; i++) {
 struct _LSObject *lso = dbGetObject(i);
 lso->us_OffsetFact = BobInit(14, 14);
 UnSet (dbGetObject (ls->ul_AreaID), 19, dbGetObject ((unsigned int) i));
    }
    livInit(0, 0, 320, 128, 640,
     256, 8, ls->ul_AreaID);
    ls->p_CurrFloor = ((void *)0);
    ls->us_DoorXOffset = 0;
    ls->us_DoorYOffset = 32;
    ls->p_DoorRefreshList = CreateList();
    lsInitFloorSquares();
    lsInitActivArea(ls->ul_AreaID, (uword) - 1, (uword) - 1, ((void *)0));
    lsShowEscapeCar();
}

variable_types:
bID
unsigned int

variable_types:
mode
unsigned char

variable_types: i int

variable_types: struct _LSObject { unsigned short us_OffsetFact; unsigned short us_DestX; unsigned short us_DestY; unsigned char uch_ExactX; unsigned char uch_ExactY; unsigned char uch_ExactX1; unsigned char uch_ExactY1; unsigned char uch_Size; unsigned char uch_Visible; unsigned char uch_Chained; unsigned int ul_Status; unsigned int Type; } *


lsDoneObjectDB

decompiled_code:
__int64 __fastcall lsDoneObjectDB(__int64 a1)
{
__int64 v1; // rbx

v1 = dbGetObject(a1);
RemRelations(*(unsigned int *)(v1 + 20), 10000LL);
dbDeleteAllObjects(*(unsigned int *)(v1 + 20), 10000LL);
RemRelations(0LL, 3LL);
AddRelation(1LL);
AddRelation(2LL);
return AddRelation(3LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v1; // rbx

v1 = dbGetObject(a1);
RemRelations(*(unsigned int *)(v1 + 20), 10000LL);
dbDeleteAllObjects(*(unsigned int *)(v1 + 20), 10000LL);
RemRelations(0LL, 3LL);
AddRelation(1LL);
AddRelation(2LL);
return AddRelation(3LL);
}

original_code:
void lsDoneObjectDB(U32 areaID)
{
    LSArea area = dbGetObject(areaID);
    RemRelations(area->ul_ObjectBaseNr, 10000);
    dbDeleteAllObjects(area->ul_ObjectBaseNr, 10000);
    RemRelations(1 - 1, 3);
    AddRelation(1);
    AddRelation(2);
    AddRelation(3);
}

canonical_original_code:
void lsDoneObjectDB(unsigned int areaID)
{
    struct _LSArea *area = dbGetObject(areaID);
    RemRelations(area->ul_ObjectBaseNr, 10000);
    dbDeleteAllObjects(area->ul_ObjectBaseNr, 10000);
    RemRelations(1 - 1, 3);
    AddRelation(1);
    AddRelation(2);
    AddRelation(3);
}


lsDoneActivArea

decompiled_code:
// attributes: thunk
__int64 lsDoneActivArea()
{
return livSetAllInvisible();
}

canonical_decompiled_code:
__int64 func12()
{
return livSetAllInvisible();
}

original_code:
void lsDoneActivArea(U32 newAreaID)
{
    livSetAllInvisible();
}

canonical_original_code:
void lsDoneActivArea(unsigned int newAreaID)
{
    livSetAllInvisible();
}

variable_types:
newAreaID
unsigned int


lsDoneLandScape

decompiled_code:
void lsDoneLandScape()
{
int v0; // ebp
__int64 v1; // rax
__int64 v2; // r14
__int64 **i; // rbx
__int64 v4; // r13
__int64 v5; // rdi
__int64 v6; // rcx
__int64 v7; // rdi
unsigned int v8; // er14
__int64 v9; // rdi
unsigned __int16 *v10; // rax
__int64 v11; // rdi

if ( ls )
{
v0 = 0;
SetObjectListAttr(4LL, 509992LL);
v1 = dbGetObject((unsigned int)*ls);
AskAll(v1, 500002LL, &BuildObjectList);
v2 = ObjectListPrivate;
for ( i = (__int64 **)*ObjectListPrivate; *i; ++v0 )
{
v4 = v0 + 42LL;
lsDoneObjectDB(*((unsigned int *)i + 8));
v5 = *(_QWORD *)(ls + 8 * v4 + 8);
if ( v5 )
{
RemoveList(v5);
v6 = ls;
*(_QWORD *)(ls + 8 * v4 + 8) = 0LL;
*(_DWORD *)(v6 + 4LL * v0 + 368) = 0;
}
i = (__int64 **)*i;
}
v7 = v2;
v8 = 9701;
RemoveList(v7);
lsDoneActivArea(0LL);
livDone();
do
{
v9 = v8++;
v10 = (unsigned __int16 *)dbGetObject(v9);
BobDone(*v10);
}
while ( v8 != 9709 );
BobDone(*(unsigned __int16 *)(ls + 400LL));
lsDoneSpots();
lsCloseGfx();
lsDoneFloorSquares();
v11 = ls;
if ( *(_QWORD *)(ls + 384LL) )
{
RemoveList(*(_QWORD *)(ls + 384LL));
v11 = ls;
}
TCFreeMem(v11, 408LL);
ls = 0LL;
}
}

canonical_decompiled_code:
void func13()
{
int v0; // ebp
__int64 v1; // rax
__int64 v2; // r14
__int64 **i; // rbx
__int64 v4; // r13
__int64 v5; // rdi
__int64 v6; // rcx
__int64 v7; // rdi
unsigned int v8; // er14
__int64 v9; // rdi
unsigned __int16 *v10; // rax
__int64 v11; // rdi

if ( ls )
{
v0 = 0;
SetObjectListAttr(4LL, 509992LL);
v1 = dbGetObject((unsigned int)*ls);
AskAll(v1, 500002LL, &BuildObjectList);
v2 = ObjectListPrivate;
for ( i = (__int64 **)*ObjectListPrivate; *i; ++v0 )
{
v4 = v0 + 42LL;
func11(*((unsigned int *)i + 8));
v5 = *(_QWORD *)(ls + 8 * v4 + 8);
if ( v5 )
{
RemoveList(v5);
v6 = ls;
*(_QWORD *)(ls + 8 * v4 + 8) = 0LL;
*(_DWORD *)(v6 + 4LL * v0 + 368) = 0;
}
i = (__int64 **)*i;
}
v7 = v2;
v8 = 9701;
RemoveList(v7);
func12(0LL);
livDone();
do
{
v9 = v8++;
v10 = (unsigned __int16 *)dbGetObject(v9);
BobDone(*v10);
}
while ( v8 != 9709 );
BobDone(*(unsigned __int16 *)(ls + 400LL));
lsDoneSpots();
lsCloseGfx();
func3();
v11 = ls;
if ( *(_QWORD *)(ls + 384LL) )
{
RemoveList(*(_QWORD *)(ls + 384LL));
v11 = ls;
}
TCFreeMem(v11, 408LL);
ls = 0LL;
}
}

original_code:
void lsDoneLandScape(void)
{
    NODE *n;
    S32 areaCount = 0, i;
    if (ls) {
 LIST *areas;
 { SetObjectListAttr ((1 << 2),509992L); AskAll (dbGetObject (ls->ul_BuildingID), 500002, BuildObjectList); };
 areas = ObjectListPrivate;
 for (n = (NODE *) ((((NODE *)((&((areas))->Head)))->Succ)); (((NODE *)(n))->Succ);
      n = (NODE *) (((NODE *)(n))->Succ), areaCount++) {
     lsDoneObjectDB((((struct ObjectNode *)n)->nr));
     if (ls->p_ObjectRetrievalLists[areaCount]) {
  RemoveList(ls->p_ObjectRetrievalLists[areaCount]);
  ls->p_ObjectRetrievalLists[areaCount] = ((void *)0);
  ls->ul_ObjectRetrievalAreaId[areaCount] = 0;
     }
 }
 RemoveList(areas);
 lsDoneActivArea(0L);
 livDone();
 for (i = 9701; i <= 9708; i++) {
     LSObject lso = dbGetObject(i);
     BobDone(lso->us_OffsetFact);
 }
 BobDone(ls->us_EscapeCarBobId);
 lsDoneSpots();
 lsCloseGfx();
 lsDoneFloorSquares();
 if (ls->p_DoorRefreshList)
     RemoveList(ls->p_DoorRefreshList);
 TCFreeMem(ls, sizeof(*ls));
 ls = ((void *)0);
    }
}

canonical_original_code:
void lsDoneLandScape()
{
    struct Node *n;
    int areaCount = 0; int i;
    if (ls) {
 struct List *areas;
 { SetObjectListAttr ((1 << 2),509992L); AskAll (dbGetObject (ls->ul_BuildingID), 500002, BuildObjectList); };
 areas = ObjectListPrivate;
 for (n = (struct Node *) ((((struct Node *)((&((areas))->Head)))->Succ)); (((struct Node *)(n))->Succ);
      n = (struct Node *) (((struct Node *)(n))->Succ), areaCount++) {
     lsDoneObjectDB((((struct ObjectNode *)n)->nr));
     if (ls->p_ObjectRetrievalLists[areaCount]) {
  RemoveList(ls->p_ObjectRetrievalLists[areaCount]);
  ls->p_ObjectRetrievalLists[areaCount] = ((void *)0);
  ls->ul_ObjectRetrievalAreaId[areaCount] = 0;
     }
 }
 RemoveList(areas);
 lsDoneActivArea(0L);
 livDone();
 for (i = 9701; i <= 9708; i++) {
     struct _LSObject *lso = dbGetObject(i);
     BobDone(lso->us_OffsetFact);
 }
 BobDone(ls->us_EscapeCarBobId);
 lsDoneSpots();
 lsCloseGfx();
 lsDoneFloorSquares();
 if (ls->p_DoorRefreshList)
     RemoveList(ls->p_DoorRefreshList);
 TCFreeMem(ls, sizeof(*ls));
 ls = ((void *)0);
    }
}

variable_types: areaCount int

user_defined_types: struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; }

user_defined_types: struct _LSObject { unsigned short us_OffsetFact; unsigned short us_DestX; unsigned short us_DestY; unsigned char uch_ExactX; unsigned char uch_ExactY; unsigned char uch_ExactX1; unsigned char uch_ExactY1; unsigned char uch_Size; unsigned char uch_Visible; unsigned char uch_Chained; unsigned int ul_Status; unsigned int Type; }


lsAddSpot

original_code:
struct Spot *lsAddSpot(uword us_Size, uword us_Speed, U32 ul_CtrlObjId)
{
    struct Spot *spot;
    U32 SpotNr;
    char line[256];
    SpotNr = GetNrOfNodes(sc->p_spots);
    sprintf(line, "*%s%" "u", ((ubyte*)"s"), SpotNr);
    spot =
 (struct Spot *) CreateNode(sc->p_spots, sizeof(*spot), line);
    spot->us_Size = us_Size;
    spot->us_Speed = us_Speed;
    spot->p_positions = CreateList();
    spot->us_OldXPos = (uword) - 1;
    spot->us_OldYPos = (uword) - 1;
    spot->uch_Status = 1;
    spot->us_PosCount = 0;
    spot->p_CurrPos = ((void *)0);
    spot->ul_CtrlObjId = ul_CtrlObjId;
    lsGetAreaForSpot(spot);
    return (spot);
}

canonical_original_code:
struct Spot *lsAddSpot(unsigned short us_Size, unsigned short us_Speed, unsigned int ul_CtrlObjId)
{
    struct Spot *spot;
    unsigned int SpotNr;
    char line[256];
    SpotNr = GetNrOfNodes(sc->p_spots);
    sprintf(line, "*%s%" "u", ((unsigned char *)"s"), SpotNr);
    spot =
 (struct Spot *) CreateNode(sc->p_spots, sizeof(*spot), line);
    spot->us_Size = us_Size;
    spot->us_Speed = us_Speed;
    spot->p_positions = CreateList();
    spot->us_OldXPos = (uword) - 1;
    spot->us_OldYPos = (uword) - 1;
    spot->uch_Status = 1;
    spot->us_PosCount = 0;
    spot->p_CurrPos = ((void *)0);
    spot->ul_CtrlObjId = ul_CtrlObjId;
    lsGetAreaForSpot(spot);
    return (spot);
}

variable_types: struct Spot { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Link; unsigned short us_Size; unsigned short us_Speed; unsigned int ul_CtrlObjId; unsigned int ul_AreaId; unsigned char uch_Status; unsigned short us_OldXPos; unsigned short us_OldYPos; unsigned short us_PosCount; struct List { struct Node Head; struct Node Tail; } *p_positions; struct SpotPosition { struct Node Link; unsigned short us_XPos; unsigned short us_YPos; } *p_CurrPos; } *

variable_types:
SpotNr
unsigned int

variable_types:
line
char [256]

user_defined_types: struct Spot { struct Node Link; unsigned short us_Size; unsigned short us_Speed; unsigned int ul_CtrlObjId; unsigned int ul_AreaId; unsigned char uch_Status; unsigned short us_OldXPos; unsigned short us_OldYPos; unsigned short us_PosCount; struct List *p_positions; struct SpotPosition *p_CurrPos; }


lsAddSpotPosition

decompiled_code:
__int64 __fastcall lsAddSpotPosition(__int64 a1, __int16 a2, __int16 a3)
{
__int16 v3; // bp
__int64 result; // rax

v3 = a3 + 19;
result = CreateNode(*(_QWORD *)(a1 + 56), 40LL, 0LL);
*(_WORD *)(result + 32) = a2 - 9;
*(_WORD *)(result + 34) = v3;
++*(_WORD *)(a1 + 50);
return result;
}

original_code:
void lsAddSpotPosition(struct Spot *spot, uword us_XPos, uword us_YPos)
{
    struct SpotPosition *pos;
    pos =
 (struct SpotPosition *) CreateNode(spot->p_positions, sizeof(*pos),
        ((void *)0));
    pos->us_XPos = (word) us_XPos + (word) (-9);
    pos->us_YPos = (word) us_YPos + (word) (19);
    spot->us_PosCount++;
}

canonical_original_code:
void lsAddSpotPosition(struct Spot *spot, unsigned short us_XPos, unsigned short us_YPos)
{
    struct SpotPosition *pos;
    pos =
 (struct SpotPosition *) CreateNode(spot->p_positions, sizeof(*pos),
        ((void *)0));
    pos->us_XPos = (short) us_XPos + (word) (-9);
    pos->us_YPos = (short) us_YPos + (word) (19);
    spot->us_PosCount++;
}

variable_types: struct SpotPosition { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Link; unsigned short us_XPos; unsigned short us_YPos; } *

user_defined_types: struct SpotPosition { struct Node Link; unsigned short us_XPos; unsigned short us_YPos; }


lsFreeAllSpots

decompiled_code:
__int64 lsFreeAllSpots()
{
__int64 result; // rax
_QWORD *i; // rbx

result = sc;
for ( i = **(_QWORD ***)sc; *i; i = (_QWORD *)*i )
result = RemoveList(i[7]);
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
_QWORD *i; // rbx

result = sc;
for ( i = **(_QWORD ***)sc; *i; i = (_QWORD *)*i )
result = RemoveList(i[7]);
return result;
}

original_code:
void lsFreeAllSpots(void)
{
    struct Spot *spot;
    for (spot = (struct Spot *) ((((NODE *)((&((sc->p_spots))->Head)))->Succ)); (((NODE *)(spot))->Succ);
  spot = (struct Spot *) (((NODE *)(spot))->Succ))
 RemoveList(spot->p_positions);
}

canonical_original_code:
void lsFreeAllSpots()
{
    struct Spot *spot;
    for (spot = (struct Spot *) ((((struct Node *)((&((sc->p_spots))->Head)))->Succ)); (((struct Node *)(spot))->Succ);
  spot = (struct Spot *) (((struct Node *)(spot))->Succ))
 RemoveList(spot->p_positions);
}


lsDoneSpots

decompiled_code:
__int64 lsDoneSpots()
{
__int64 result; // rax

if ( sc )
{
lsFreeAllSpots();
RemoveList(*(_QWORD *)sc);
gfxDoneMemRastPort(sc + 8);
result = TCFreeMem(sc, 800LL);
}
sc = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax

if ( sc )
{
func7();
RemoveList(*(_QWORD *)sc);
gfxDoneMemRastPort(sc + 8);
result = TCFreeMem(sc, 800LL);
}
sc = 0LL;
return result;
}

original_code:
void lsDoneSpots(void)
{
    if (sc) {
 lsFreeAllSpots();
 RemoveList(sc->p_spots);
        gfxDoneMemRastPort(&sc->RP);
 TCFreeMem(sc, sizeof(*sc));
    }
    sc = ((void *)0);
}

canonical_original_code:
void lsDoneSpots()
{
    if (sc) {
 lsFreeAllSpots();
 RemoveList(sc->p_spots);
        gfxDoneMemRastPort(&sc->RP);
 TCFreeMem(sc, sizeof(*sc));
    }
    sc = ((void *)0);
}


lsInitSpots

decompiled_code:
__int64 lsInitSpots()
{
if ( sc )
lsDoneSpots();
sc = TCAllocMem(800LL, 0LL);
*(_QWORD *)sc = CreateList();
gfxInitMemRastPort(sc + 8, 96LL, 48LL);
return lsLoadSpotBitMap((unsigned __int16 *)(sc + 8));
}

canonical_decompiled_code:
__int64 func9()
{
if ( sc )
func8();
sc = TCAllocMem(800LL, 0LL);
*(_QWORD *)sc = CreateList();
gfxInitMemRastPort(sc + 8, 96LL, 48LL);
return func5((unsigned __int16 *)(sc + 8));
}

original_code:
void lsInitSpots(void)
{
    if (sc)
 lsDoneSpots();
    sc = TCAllocMem(sizeof(*sc), 0);
    sc->p_spots = CreateList();
    gfxInitMemRastPort(&sc->RP, (96), (48));
    lsLoadSpotBitMap(&sc->RP);
}

canonical_original_code:
void lsInitSpots()
{
    if (sc)
 lsDoneSpots();
    sc = TCAllocMem(sizeof(*sc), 0);
    sc->p_spots = CreateList();
    gfxInitMemRastPort(&sc->RP, (96), (48));
    lsLoadSpotBitMap(&sc->RP);
}


lsGetSpot

decompiled_code:
__int64 __fastcall lsGetSpot(__int64 a1)
{
return GetNode(*(_QWORD *)sc, a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return GetNode(*(_QWORD *)sc, a1);
}

original_code:
struct Spot *lsGetSpot(char *uch_Name)
{
    return ((struct Spot *) GetNode(sc->p_spots, uch_Name));
}

return_type: struct Spot { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Link; unsigned short us_Size; unsigned short us_Speed; unsigned int ul_CtrlObjId; unsigned int ul_AreaId; unsigned char uch_Status; unsigned short us_OldXPos; unsigned short us_OldYPos; unsigned short us_PosCount; struct List { struct Node Head; struct Node Tail; } *p_positions; struct SpotPosition { struct Node Link; unsigned short us_XPos; unsigned short us_YPos; } *p_CurrPos; } *


lsGetSpotList

decompiled_code:
__int64 lsGetSpotList()
{
return *(_QWORD *)sc;
}

canonical_decompiled_code:
__int64 func11()
{
return *(_QWORD *)sc;
}

original_code:
LIST *lsGetSpotList(void)
{
    return (sc->p_spots);
}

canonical_original_code:
struct List *lsGetSpotList()
{
    return (sc->p_spots);
}

return_type: struct List { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Head; struct Node Tail; } *


lsBlitSpot

decompiled_code:
__int64 __fastcall lsBlitSpot(unsigned __int16 a1, unsigned __int16 a2, unsigned __int16 a3, char a4)
{
__int64 v4; // r9
unsigned int v5; // er10
__int64 v6; // rdi
__int64 v8; // [rsp-10h] [rbp-18h]

v4 = a1;
v5 = 80;
if ( a1 != 16 )
{
v5 = 48;
if ( a1 != 32 )
v5 = 0;
}
v6 = sc + 8;
v8 = v4;
if ( a4 )
return gfxLSPutSet(v6, v5, 0LL, a2, a3);
gfxLSPutClr(v6, v5, 0LL, a2, a3);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned __int16 a1, unsigned __int16 a2, unsigned __int16 a3, char a4)
{
__int64 v4; // r9
unsigned int v5; // er10
__int64 v6; // rdi
__int64 v8; // [rsp-10h] [rbp-18h]

v4 = a1;
v5 = 80;
if ( a1 != 16 )
{
v5 = 48;
if ( a1 != 32 )
v5 = 0;
}
v6 = sc + 8;
v8 = v4;
if ( a4 )
return gfxLSPutSet(v6, v5, 0LL, a2, a3);
gfxLSPutClr(v6, v5, 0LL, a2, a3);
return v8;
}

original_code:
void lsBlitSpot(uword us_Size, uword us_XPos, uword us_YPos, ubyte visible)
{
    U16 sourceX = 0;
    switch (us_Size) {
    case 16:
 sourceX = 48 + 32;
 break;
    case 32:
 sourceX = 48;
 break;
    case 48:
 break;
    }
    if (visible)
        gfxLSPutSet(&sc->RP, sourceX, 0, us_XPos, us_YPos, us_Size, us_Size);
    else
        gfxLSPutClr(&sc->RP, sourceX, 0, us_XPos, us_YPos, us_Size, us_Size);
}

canonical_original_code:
void lsBlitSpot(unsigned short us_Size, unsigned short us_XPos, unsigned short us_YPos, unsigned char visible)
{
    unsigned short sourceX = 0;
    switch (us_Size) {
    case 16:
 sourceX = 48 + 32;
 break;
    case 32:
 sourceX = 48;
 break;
    case 48:
 break;
    }
    if (visible)
        gfxLSPutSet(&sc->RP, sourceX, 0, us_XPos, us_YPos, us_Size, us_Size);
    else
        gfxLSPutClr(&sc->RP, sourceX, 0, us_XPos, us_YPos, us_Size, us_Size);
}

variable_types:
visible
unsigned char

variable_types:
sourceX
unsigned short


lsHideSpot

decompiled_code:
__int64 __fastcall lsHideSpot(unsigned __int16 *a1)
{
unsigned __int16 v1; // si
unsigned __int16 v2; // dx
__int64 result; // rax

v1 = a1[23];
if ( v1 != 0xFFFF )
{
v2 = a1[24];
if ( v2 != 0xFFFF )
result = lsBlitSpot(a1[16], v1, v2, 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int16 *a1)
{
unsigned __int16 v1; // si
unsigned __int16 v2; // dx
__int64 result; // rax

v1 = a1[23];
if ( v1 != 0xFFFF )
{
v2 = a1[24];
if ( v2 != 0xFFFF )
result = func12(a1[16], v1, v2, 0);
}
return result;
}

original_code:
void lsHideSpot(struct Spot *s)
{
    if ((s->us_OldXPos != (uword) - 1) && (s->us_OldYPos != (uword) - 1))
 lsBlitSpot(s->us_Size, s->us_OldXPos, s->us_OldYPos, 0);
}


lsShowSpot

decompiled_code:
__int64 __fastcall lsShowSpot(__int64 a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // edx
unsigned __int16 v4; // si
unsigned int v5; // ebp
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // rbp
__int16 v9; // r9

v3 = a2 % *(unsigned __int16 *)(a1 + 34);
result = a2 / *(unsigned __int16 *)(a1 + 34);
if ( !v3 )
{
v4 = *(_WORD *)(a1 + 50);
if ( v4 > 1u )
{
v5 = 2 * v4 - 2;
v3 = (unsigned int)result % v5;
v6 = v5 - (unsigned int)result % v5;
if ( v4 <= v3 )
v3 = v6;
}
v7 = GetNthNode(*(_QWORD *)(a1 + 56), v3);
*(_QWORD *)(a1 + 64) = v7;
v8 = v7;
lsHideSpot((unsigned __int16 *)a1);
result = lsBlitSpot(*(_WORD *)(a1 + 32), *(_WORD *)(v8 + 32), *(_WORD *)(v8 + 34), 1);
v9 = *(_WORD *)(v8 + 34);
*(_WORD *)(a1 + 46) = *(_WORD *)(v8 + 32);
*(_WORD *)(a1 + 48) = v9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // edx
unsigned __int16 v4; // si
unsigned int v5; // ebp
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // rbp
__int16 v9; // r9

v3 = a2 % *(unsigned __int16 *)(a1 + 34);
result = a2 / *(unsigned __int16 *)(a1 + 34);
if ( !v3 )
{
v4 = *(_WORD *)(a1 + 50);
if ( v4 > 1u )
{
v5 = 2 * v4 - 2;
v3 = (unsigned int)result % v5;
v6 = v5 - (unsigned int)result % v5;
if ( v4 <= v3 )
v3 = v6;
}
v7 = GetNthNode(*(_QWORD *)(a1 + 56), v3);
*(_QWORD *)(a1 + 64) = v7;
v8 = v7;
func13((unsigned __int16 *)a1);
result = func12(*(_WORD *)(a1 + 32), *(_WORD *)(v8 + 32), *(_WORD *)(v8 + 34), 1);
v9 = *(_WORD *)(v8 + 34);
*(_WORD *)(a1 + 46) = *(_WORD *)(v8 + 32);
*(_WORD *)(a1 + 48) = v9;
}
return result;
}

original_code:
void lsShowSpot(struct Spot *s, U32 time)
{
    struct SpotPosition *pos;
    if (!(time % s->us_Speed)) {
 U32 count = (time / s->us_Speed);
 if (s->us_PosCount > 1) {
     count = count % (s->us_PosCount * 2 - 2);
     if (count >= s->us_PosCount)
  count = (s->us_PosCount * 2 - 2) - count;
 } else
     count = 0;
 s->p_CurrPos = pos =
     (struct SpotPosition *) GetNthNode(s->p_positions, count);
 lsHideSpot(s);
 lsBlitSpot(s->us_Size, pos->us_XPos, pos->us_YPos, 1);
 s->us_OldXPos = pos->us_XPos;
 s->us_OldYPos = pos->us_YPos;
    }
}

canonical_original_code:
void lsShowSpot(struct Spot *s, unsigned int time)
{
    struct SpotPosition *pos;
    if (!(time % s->us_Speed)) {
 unsigned int count = (time / s->us_Speed);
 if (s->us_PosCount > 1) {
     count = count % (s->us_PosCount * 2 - 2);
     if (count >= s->us_PosCount)
  count = (s->us_PosCount * 2 - 2) - count;
 } else
     count = 0;
 s->p_CurrPos = pos =
     (struct SpotPosition *) GetNthNode(s->p_positions, count);
 lsHideSpot(s);
 lsBlitSpot(s->us_Size, pos->us_XPos, pos->us_YPos, 1);
 s->us_OldXPos = pos->us_XPos;
 s->us_OldYPos = pos->us_YPos;
    }
}

variable_types:
time
unsigned int

variable_types:
count
unsigned int


PrintStatus

decompiled_code:
__int64 __fastcall PrintStatus(__int64 a1)
{
gfxSetDrMd(m_gc, 0LL);
gfxSetRect(0LL, 320LL);
gfxSetPens(m_gc, 249LL, 254LL, 255LL);
return gfxPrint(m_gc, a1, 10LL, 9LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
gfxSetDrMd(m_gc, 0LL);
gfxSetRect(0LL, 320LL);
gfxSetPens(m_gc, 249LL, 254LL, 255LL);
return gfxPrint(m_gc, a1, 10LL, 9LL);
}

original_code:
void PrintStatus(char *text)
{
    gfxSetDrMd(m_gc, GFX_JAM_1);
    gfxSetRect(0, 320);
    gfxSetPens(m_gc, 249, 254, ((ubyte)255));
    gfxPrint(m_gc, text, 10, (1<<3) | (1));
}

canonical_original_code:
void PrintStatus(char *text)
{
    gfxSetDrMd(m_gc, GFX_JAM_1);
    gfxSetRect(0, 320);
    gfxSetPens(m_gc, 249, 254, ((unsigned char)255));
    gfxPrint(m_gc, text, 10, (1<<3) | (1));
}

variable_types:
text
char *


ShowTheClouRequester

decompiled_code:
__int64 __fastcall ShowTheClouRequester(int a1)
{
unsigned int v1; // eax
__int64 v2; // rbp
__int64 v4; // r12
unsigned __int8 v5; // bl

v1 = getKey(1LL);
v2 = dbGetObject(v1);
inpTurnESC(0LL);
ShowMenuBackground();
if ( a1 == 2 )
{
PrintStatus((__int64)"Speichermangel !! - No Memory !!");
inpWaitFor(32LL);
ShowMenuBackground();
goto LABEL_6;
}
if ( a1 <= 2 )
{
if ( a1 )
{
if ( a1 == 1 )
{
PrintStatus((__int64)"Gravierender Fehler !");
inpWaitFor(32LL);
ShowMenuBackground();
}
goto LABEL_6;
}
ShowMenuBackground();
v4 = txtGoKey(0LL, "ESCMenu_STD");
inpTurnFunctionKey(0LL);
if ( (GamePlayMode & 4) != 0 )
v5 = Menu(v4, 3LL, 0LL, 0LL, 0LL);
else
v5 = Menu(v4, 15LL, 0LL, 0LL, 0LL);
inpTurnFunctionKey(1LL);
if ( v5 == 2 )
{
tcSaveTheClou();
}
else
{
if ( v5 > 2u )
{
if ( v5 == 3 )
{
tcLoadTheClou();
ShowMenuBackground();
}
goto LABEL_16;
}
if ( v5 )
{
*(_DWORD *)(v2 + 16) = 3932160;
ShowMenuBackground();
LABEL_16:
RemoveList(v4);
goto LABEL_6;
}
}
*(_DWORD *)(v2 + 16) = 0;
ShowMenuBackground();
tcRefreshLocationInTitle(*(unsigned int *)(film + 52LL));
goto LABEL_16;
}
if ( a1 == 3 )
{
PrintStatus((__int64)"Disk Defekt !");
inpWaitFor(32LL);
ShowMenuBackground();
}
LABEL_6:
inpTurnESC(1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned int v1; // eax
__int64 v2; // rbp
__int64 v4; // r12
unsigned __int8 v5; // bl

v1 = getKey(1LL);
v2 = dbGetObject(v1);
inpTurnESC(0LL);
ShowMenuBackground();
if ( a1 == 2 )
{
func0((__int64)"Speichermangel !! - No Memory !!");
inpWaitFor(32LL);
ShowMenuBackground();
goto LABEL_6;
}
if ( a1 <= 2 )
{
if ( a1 )
{
if ( a1 == 1 )
{
func0((__int64)"Gravierender Fehler !");
inpWaitFor(32LL);
ShowMenuBackground();
}
goto LABEL_6;
}
ShowMenuBackground();
v4 = txtGoKey(0LL, "ESCMenu_STD");
inpTurnFunctionKey(0LL);
if ( (GamePlayMode & 4) != 0 )
v5 = Menu(v4, 3LL, 0LL, 0LL, 0LL);
else
v5 = Menu(v4, 15LL, 0LL, 0LL, 0LL);
inpTurnFunctionKey(1LL);
if ( v5 == 2 )
{
tcSaveTheClou();
}
else
{
if ( v5 > 2u )
{
if ( v5 == 3 )
{
tcLoadTheClou();
ShowMenuBackground();
}
goto LABEL_16;
}
if ( v5 )
{
*(_DWORD *)(v2 + 16) = 3932160;
ShowMenuBackground();
LABEL_16:
RemoveList(v4);
goto LABEL_6;
}
}
*(_DWORD *)(v2 + 16) = 0;
ShowMenuBackground();
tcRefreshLocationInTitle(*(unsigned int *)(film + 52LL));
goto LABEL_16;
}
if ( a1 == 3 )
{
func0((__int64)"Disk Defekt !");
inpWaitFor(32LL);
ShowMenuBackground();
}
LABEL_6:
inpTurnESC(1LL);
return 0LL;
}

original_code:
U32 ShowTheClouRequester(S32 error_class)
{
    LIST *menu;
    U32 answer = 0;
    ubyte choices;
    Player player = dbGetObject(getKey(_Player_Player_1));
    inpTurnESC(0);
    ShowMenuBackground();
    switch (error_class) {
    case No_Error:
 ShowMenuBackground();
 menu = txtGoKey(0U, "ESCMenu_STD");
 inpTurnFunctionKey(0);
 if (GamePlayMode & (1<< 2))
     choices = Menu(menu, 3, 0, ((void *)0), 0);
 else
     choices = Menu(menu, 15, 0, ((void *)0), 0);
 inpTurnFunctionKey(1);
 switch (choices) {
 case 0:
     player->CurrScene = 0;
     ShowMenuBackground();
     tcRefreshLocationInTitle((film->akt_Ort));
     break;
 case 1:
     player->CurrScene = 3932160L;
     ShowMenuBackground();
     break;
 case 2:
     tcSaveTheClou();
     player->CurrScene = 0;
     ShowMenuBackground();
     tcRefreshLocationInTitle((film->akt_Ort));
     break;
 case 3:
     tcLoadTheClou();
     ShowMenuBackground();
     break;
 default:
     break;
 }
 RemoveList(menu);
 break;
    case Internal_Error:
 PrintStatus("Gravierender Fehler !");
 inpWaitFor((1<<5));
 ShowMenuBackground();
 break;
    case No_Mem:
 PrintStatus("Speichermangel !! - No Memory !!");
 inpWaitFor((1<<5));
 ShowMenuBackground();
 break;
    case Disk_Defect:
 PrintStatus("Disk Defekt !");
 inpWaitFor((1<<5));
 ShowMenuBackground();
 break;
    }
    inpTurnESC(1);
    return (answer);
}

canonical_original_code:
unsigned int ShowTheClouRequester(int error_class)
{
    struct List *menu;
    unsigned int answer = 0;
    unsigned char choices;
    struct _Player *player = dbGetObject(getKey(_Player_Player_1));
    inpTurnESC(0);
    ShowMenuBackground();
    switch (error_class) {
    case No_Error:
 ShowMenuBackground();
 menu = txtGoKey(0U, "ESCMenu_STD");
 inpTurnFunctionKey(0);
 if (GamePlayMode & (1<< 2))
     choices = Menu(menu, 3, 0, ((void *)0), 0);
 else
     choices = Menu(menu, 15, 0, ((void *)0), 0);
 inpTurnFunctionKey(1);
 switch (choices) {
 case 0:
     player->CurrScene = 0;
     ShowMenuBackground();
     tcRefreshLocationInTitle((film->akt_Ort));
     break;
 case 1:
     player->CurrScene = 3932160L;
     ShowMenuBackground();
     break;
 case 2:
     tcSaveTheClou();
     player->CurrScene = 0;
     ShowMenuBackground();
     tcRefreshLocationInTitle((film->akt_Ort));
     break;
 case 3:
     tcLoadTheClou();
     ShowMenuBackground();
     break;
 default:
     break;
 }
 RemoveList(menu);
 break;
    case Internal_Error:
 PrintStatus("Gravierender Fehler !");
 inpWaitFor((1<<5));
 ShowMenuBackground();
 break;
    case No_Mem:
 PrintStatus("Speichermangel !! - No Memory !!");
 inpWaitFor((1<<5));
 ShowMenuBackground();
 break;
    case Disk_Defect:
 PrintStatus("Disk Defekt !");
 inpWaitFor((1<<5));
 ShowMenuBackground();
 break;
    }
    inpTurnESC(1);
    return (answer);
}

variable_types: struct List { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Head; struct Node Tail; } *

variable_types:
answer
unsigned int

variable_types:
choices
unsigned char

variable_types: struct _Player { unsigned int Money; unsigned int StolenMoney; unsigned int MyStolenMoney; unsigned char NrOfBurglaries; unsigned char JobOfferCount; unsigned char MattsPart; unsigned int CurrScene; unsigned int CurrDay; unsigned int CurrMinute; unsigned int CurrLocation; } *

return_type: unsigned int


tcJobOffer

decompiled_code:
__int64 __fastcall tcJobOffer(unsigned __int16 *a1)
{
unsigned int v1; // eax
__int64 v2; // rbp
unsigned int v3; // eax
__int64 v4; // r12
__int64 v5; // rax
char v6; // al
unsigned int v7; // eax
__int64 v8; // rbp
unsigned int v9; // eax
__int64 v10; // r12
__int64 v11; // rax
unsigned int v12; // eax
__int64 v13; // rbp
__int64 v14; // rax
__int64 result; // rax
char v16; // al
__int64 v17; // rdx

v1 = getKey(1LL);
v2 = dbGetObject(v1);
v3 = dbGetObjectNr(a1);
v4 = dbGetObject(v3);
v5 = dbGetObject(9801LL);
if ( !(unsigned int)AskP(v5, 7LL, v4, 0xFFFFFFFFLL, 0LL) )
++*(_BYTE *)(v2 + 13);
v6 = Say(2LL, 0LL, 7LL, "PERS_ANZ");
v7 = tcGetPersOffer(a1, (unsigned __int8)(v6 + 2));
v8 = txtGoKeyAndInsert(2LL, "JOB_ANSWER", v7, 0LL);
SetPictID(*a1);
Bubble(v8, 0LL, 0LL, 0LL);
RemoveList(v8);
if ( (unsigned __int8)Say(2LL, 0LL, 7LL, "NEW_THEEF") )
{
v16 = CalcValue(*((unsigned __int8 *)a1 + 20), 0LL, 255LL, 0LL, 20LL);
v17 = *a1;
*((_BYTE *)a1 + 20) = v16;
result = Say(2LL, 0LL, v17, "MY_OFFER");
}
else
{
v9 = dbGetObjectNr(a1);
v10 = dbGetObject(v9);
v11 = dbGetObject(9801LL);
SetP(v11, 7LL, v10, 0xFFFFFFFFLL);
v12 = dbGetObjectNr(a1);
v13 = dbGetObject(v12);
v14 = dbGetObject(9801LL);
result = SetP(v14, 4LL, v13, 0xFFFFFFFFLL);
*((_DWORD *)a1 + 7) &= 0xFFFFFFFE;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 *a1)
{
unsigned int v1; // eax
__int64 v2; // rbp
unsigned int v3; // eax
__int64 v4; // r12
__int64 v5; // rax
char v6; // al
unsigned int v7; // eax
__int64 v8; // rbp
unsigned int v9; // eax
__int64 v10; // r12
__int64 v11; // rax
unsigned int v12; // eax
__int64 v13; // rbp
__int64 v14; // rax
__int64 result; // rax
char v16; // al
__int64 v17; // rdx

v1 = getKey(1LL);
v2 = dbGetObject(v1);
v3 = dbGetObjectNr(a1);
v4 = dbGetObject(v3);
v5 = dbGetObject(9801LL);
if ( !(unsigned int)AskP(v5, 7LL, v4, 0xFFFFFFFFLL, 0LL) )
++*(_BYTE *)(v2 + 13);
v6 = Say(2LL, 0LL, 7LL, "PERS_ANZ");
v7 = tcGetPersOffer(a1, (unsigned __int8)(v6 + 2));
v8 = txtGoKeyAndInsert(2LL, "JOB_ANSWER", v7, 0LL);
SetPictID(*a1);
Bubble(v8, 0LL, 0LL, 0LL);
RemoveList(v8);
if ( (unsigned __int8)Say(2LL, 0LL, 7LL, "NEW_THEEF") )
{
v16 = CalcValue(*((unsigned __int8 *)a1 + 20), 0LL, 255LL, 0LL, 20LL);
v17 = *a1;
*((_BYTE *)a1 + 20) = v16;
result = Say(2LL, 0LL, v17, "MY_OFFER");
}
else
{
v9 = dbGetObjectNr(a1);
v10 = dbGetObject(v9);
v11 = dbGetObject(9801LL);
SetP(v11, 7LL, v10, 0xFFFFFFFFLL);
v12 = dbGetObjectNr(a1);
v13 = dbGetObject(v12);
v14 = dbGetObject(9801LL);
result = SetP(v14, 4LL, v13, 0xFFFFFFFFLL);
*((_DWORD *)a1 + 7) &= 0xFFFFFFFE;
}
return result;
}

original_code:
void tcJobOffer(Person p)
{
    LIST *bubble;
    ubyte choice;
    S32 part;
    Player player = dbGetObject(getKey(_Player_Player_1));
    if (!(AskP (dbGetObject (9801U), 7, dbGetObject (dbGetObjectNr(p)), (4294967295U), ((U8)0))))
 player->JobOfferCount++;
    choice = Say(2U, 0, 7, "PERS_ANZ");
    part = tcGetPersOffer(p, (choice + 2));
    bubble = txtGoKeyAndInsert(2U, "JOB_ANSWER", (U32) part, ((void *)0));
    SetPictID(p->PictID);
    Bubble(bubble, 0, 0L, 0L);
    RemoveList(bubble);
    choice = Say(2U, 0, 7, "NEW_THEEF");
    if (choice == 0) {
 SetP (dbGetObject (9801U), 7, dbGetObject (dbGetObjectNr(p)), (4294967295U));
 SetP (dbGetObject (9801U), 4, dbGetObject (dbGetObjectNr(p)), (4294967295U));
 p->TalkBits &= (0xffffffffL - (1 << 0));
    } else {
 p->Known = CalcValue(p->Known, 0, 255, 0, 20);
 Say(2U, 0, p->PictID, "MY_OFFER");
    }
}

canonical_original_code:
void tcJobOffer(struct _Person *p)
{
    struct List *bubble;
    unsigned char choice;
    int part;
    struct _Player *player = dbGetObject(getKey(_Player_Player_1));
    if (!(AskP (dbGetObject (9801U), 7, dbGetObject (dbGetObjectNr(p)), (4294967295U), ((unsigned char)0))))
 player->JobOfferCount++;
    choice = Say(2U, 0, 7, "PERS_ANZ");
    part = tcGetPersOffer(p, (choice + 2));
    bubble = txtGoKeyAndInsert(2U, "JOB_ANSWER", (unsigned int) part, ((void *)0));
    SetPictID(p->PictID);
    Bubble(bubble, 0, 0L, 0L);
    RemoveList(bubble);
    choice = Say(2U, 0, 7, "NEW_THEEF");
    if (choice == 0) {
 SetP (dbGetObject (9801U), 7, dbGetObject (dbGetObjectNr(p)), (4294967295U));
 SetP (dbGetObject (9801U), 4, dbGetObject (dbGetObjectNr(p)), (4294967295U));
 p->TalkBits &= (0xffffffffL - (1 << 0));
    } else {
 p->Known = CalcValue(p->Known, 0, 255, 0, 20);
 Say(2U, 0, p->PictID, "MY_OFFER");
    }
}

variable_types: struct _Person { unsigned short PictID; enum JobE { Detektiv=0, Sprengmeister=1, Schlosser=2, Hehler=3, Haendler=4, Taxifahrer=5, Mechaniker=6, Elektriker=7, Sekretaerin=8, Anwalt=9, Unbekannt=10, Profiboxer=11, Angestellte=12, Soldat=13, Student=14, Literat=15, Professor=16, Hausfrau=17, Politiker=18, Abenteurer=19, Agent=20, Musiker=21, Pilot=22, Kellner=23, Rezeptionist=24, Polizeichef=25, Polizist=26, Moench=27, Inspektor=28, Pizzafahrer=29, Kellner_und_Student=30, Arbeiter=31, Butler=32, Krankenschwester=33 } Job; enum SexE { Maennlich=0, Weiblich=1 } Sex; char Age; unsigned char Health; unsigned char Mood; unsigned char Intelligence; unsigned char Strength; unsigned char Stamina; unsigned char Loyality; unsigned char Skill; unsigned char Known; unsigned char Popularity; unsigned char Avarice; unsigned char Panic; unsigned char KnownToPolice; unsigned int TalkBits; unsigned char TalkFileID; unsigned char OldHealth; } *

variable_types:
choice
unsigned char

variable_types: part int

user_defined_types: struct _Person { unsigned short PictID; enum JobE Job; enum SexE Sex; char Age; unsigned char Health; unsigned char Mood; unsigned char Intelligence; unsigned char Strength; unsigned char Stamina; unsigned char Loyality; unsigned char Skill; unsigned char Known; unsigned char Popularity; unsigned char Avarice; unsigned char Panic; unsigned char KnownToPolice; unsigned int TalkBits; unsigned char TalkFileID; unsigned char OldHealth; }

user_defined_types: struct _Player { unsigned int Money; unsigned int StolenMoney; unsigned int MyStolenMoney; unsigned char NrOfBurglaries; unsigned char JobOfferCount; unsigned char MattsPart; unsigned int CurrScene; unsigned int CurrDay; unsigned int CurrMinute; unsigned int CurrLocation; }


tcMyJobAnswer

decompiled_code:
__int64 __fastcall tcMyJobAnswer(unsigned __int16 *a1)
{
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rax
char v6[256]; // [rsp+0h] [rbp-328h] BYREF
char dest[256]; // [rsp+100h] [rbp-228h] BYREF
char format[296]; // [rsp+200h] [rbp-128h] BYREF

v1 = CreateList();
v2 = txtGoKey(7LL, "enum_JobE");
v3 = GetNthNode(v2, *((unsigned int *)a1 + 1));
strcpy(dest, *(const char **)(v3 + 16));
v4 = GetNthNode(v2, 10LL);
if ( !strcmp(dest, *(const char **)(v4 + 16)) )
{
txtGetNthString(2LL, "NO_JOB", 0LL, v6);
}
else
{
txtGetNthString(2LL, "MY_JOB_IS", 0LL, format);
sprintf(v6, format, dest);
}
SetPictID(*a1);
CreateNode(v1, 0LL, v6);
Bubble(v1, 0LL, 0LL, 0LL);
RemoveList(v2);
return RemoveList(v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 *a1)
{
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // rax
char v6[256]; // [rsp+0h] [rbp-328h] BYREF
char dest[256]; // [rsp+100h] [rbp-228h] BYREF
char format[296]; // [rsp+200h] [rbp-128h] BYREF

v1 = CreateList();
v2 = txtGoKey(7LL, "enum_JobE");
v3 = GetNthNode(v2, *((unsigned int *)a1 + 1));
strcpy(dest, *(const char **)(v3 + 16));
v4 = GetNthNode(v2, 10LL);
if ( !strcmp(dest, *(const char **)(v4 + 16)) )
{
txtGetNthString(2LL, "NO_JOB", 0LL, v6);
}
else
{
txtGetNthString(2LL, "MY_JOB_IS", 0LL, format);
sprintf(v6, format, dest);
}
SetPictID(*a1);
CreateNode(v1, 0LL, v6);
Bubble(v1, 0LL, 0LL, 0LL);
RemoveList(v2);
return RemoveList(v1);
}

original_code:
void tcMyJobAnswer(Person p)
{
    LIST *bubble = CreateList();
    LIST *jobs = txtGoKey(7U, "enum_JobE");
    char line[256], job[256], temp[256];
    strcpy(job, (((NODE *)(GetNthNode(jobs, p->Job)))->Name));
    if (strcmp(job, (((NODE *)(GetNthNode(jobs, 10)))->Name))) {
 (txtGetNthString(2U, "MY_JOB_IS", 0, temp));
 sprintf(line, temp, job);
    } else
 (txtGetNthString(2U, "NO_JOB", 0, line));
    SetPictID(p->PictID);
    CreateNode(bubble, 0L, line);
    Bubble(bubble, 0, 0L, 0L);
    RemoveList(jobs);
    RemoveList(bubble);
}

canonical_original_code:
void tcMyJobAnswer(struct _Person *p)
{
    struct List *bubble = CreateList();
    struct List *jobs = txtGoKey(7U, "enum_JobE");
    char line[256]; char job[256]; char temp[256];
    strcpy(job, (((struct Node *)(GetNthNode(jobs, p->Job)))->Name));
    if (strcmp(job, (((struct Node *)(GetNthNode(jobs, 10)))->Name))) {
 (txtGetNthString(2U, "MY_JOB_IS", 0, temp));
 sprintf(line, temp, job);
    } else
 (txtGetNthString(2U, "NO_JOB", 0, line));
    SetPictID(p->PictID);
    CreateNode(bubble, 0L, line);
    Bubble(bubble, 0, 0L, 0L);
    RemoveList(jobs);
    RemoveList(bubble);
}

variable_types:
job
char [256]

variable_types:
temp
char [256]

user_defined_types: enum JobE { Detektiv=0, Sprengmeister=1, Schlosser=2, Hehler=3, Haendler=4, Taxifahrer=5, Mechaniker=6, Elektriker=7, Sekretaerin=8, Anwalt=9, Unbekannt=10, Profiboxer=11, Angestellte=12, Soldat=13, Student=14, Literat=15, Professor=16, Hausfrau=17, Politiker=18, Abenteurer=19, Agent=20, Musiker=21, Pilot=22, Kellner=23, Rezeptionist=24, Polizeichef=25, Polizist=26, Moench=27, Inspektor=28, Pizzafahrer=29, Kellner_und_Student=30, Arbeiter=31, Butler=32, Krankenschwester=33 }


tcPrisonAnswer

decompiled_code:
__int64 __fastcall tcPrisonAnswer(unsigned __int16 *a1)
{
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // rax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = CreateList();
v2 = txtGoKey(2LL, "IN_PRISON_ANSWER");
v3 = GetNthNode(v2, *((_BYTE *)a1 + 24) / 0x34u);
strcpy(v5, *(const char **)(v3 + 16));
SetPictID(*a1);
CreateNode(v1, 0LL, v5);
Bubble(v1, 0LL, 0LL, 0LL);
RemoveList(v2);
return RemoveList(v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 *a1)
{
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // rax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = CreateList();
v2 = txtGoKey(2LL, "IN_PRISON_ANSWER");
v3 = GetNthNode(v2, *((_BYTE *)a1 + 24) / 0x34u);
strcpy(v5, *(const char **)(v3 + 16));
SetPictID(*a1);
CreateNode(v1, 0LL, v5);
Bubble(v1, 0LL, 0LL, 0LL);
RemoveList(v2);
return RemoveList(v1);
}

original_code:
void tcPrisonAnswer(Person p)
{
    LIST *bubble = CreateList();
    LIST *source = txtGoKey(2U, "IN_PRISON_ANSWER");
    char line[256];
    strcpy(line, (((NODE *)(GetNthNode(source, p->KnownToPolice / 52)))->Name));
    SetPictID(p->PictID);
    CreateNode(bubble, 0L, line);
    Bubble(bubble, 0, 0, 0);
    RemoveList(source);
    RemoveList(bubble);
}

canonical_original_code:
void tcPrisonAnswer(struct _Person *p)
{
    struct List *bubble = CreateList();
    struct List *source = txtGoKey(2U, "IN_PRISON_ANSWER");
    char line[256];
    strcpy(line, (((struct Node *)(GetNthNode(source, p->KnownToPolice / 52)))->Name));
    SetPictID(p->PictID);
    CreateNode(bubble, 0L, line);
    Bubble(bubble, 0, 0, 0);
    RemoveList(source);
    RemoveList(bubble);
}


tcAbilityAnswer

decompiled_code:
__int64 __fastcall tcAbilityAnswer(__int64 a1)
{
unsigned __int16 *v1; // rbx
__int64 v2; // rbp
_BYTE v4[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = (unsigned __int16 *)dbGetObject(a1);
dbGetObjectName((unsigned int)a1, v4);
v2 = txtGoKey(14LL, v4);
SetPictID(*v1);
Bubble(v2, 0LL, 0LL, 0LL);
return RemoveList(v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int16 *v1; // rbx
__int64 v2; // rbp
_BYTE v4[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = (unsigned __int16 *)dbGetObject(a1);
dbGetObjectName((unsigned int)a1, v4);
v2 = txtGoKey(14LL, v4);
SetPictID(*v1);
Bubble(v2, 0LL, 0LL, 0LL);
return RemoveList(v2);
}

original_code:
void tcAbilityAnswer(U32 personID)
{
    char name[256];
    LIST *bubble;
    Person p = dbGetObject(personID);
    dbGetObjectName(personID, name);
    bubble = txtGoKey(14U, name);
    SetPictID(p->PictID);
    Bubble(bubble, 0, 0, 0);
    RemoveList(bubble);
}

canonical_original_code:
void tcAbilityAnswer(unsigned int personID)
{
    char name[256];
    struct List *bubble;
    struct _Person *p = dbGetObject(personID);
    dbGetObjectName(personID, name);
    bubble = txtGoKey(14U, name);
    SetPictID(p->PictID);
    Bubble(bubble, 0, 0, 0);
    RemoveList(bubble);
}

variable_types:
personID
unsigned int

variable_types:
name
char [256]


lsIsCollision

decompiled_code:
__int64 __fastcall lsIsCollision(int a1, int a2, unsigned __int8 a3)
{
int v3; // ebp
__int64 result; // rax
char v5; // r14
char v6; // al
unsigned int v7; // edx
char v8; // al
__int64 v9; // rbx
char v10; // al
char v11; // al
__int64 v12; // [rsp+12h] [rbp-46h]
int v13; // [rsp+1Ah] [rbp-3Eh]
__int16 v14; // [rsp+1Eh] [rbp-3Ah]

if ( (GamePlayMode[1] & 0x10) != 0 )
return 0LL;
v3 = a2;
if ( a1 <= 2 )
{
result = 5LL;
if ( a2 > 2 )
{
LOBYTE(v3) = a2 > 238;
result = (unsigned int)(8 * v3 + 1);
}
return result;
}
if ( a1 <= 622 )
{
result = 4LL;
if ( a2 <= 2 )
return result;
result = 8LL;
if ( a2 > 238 )
return result;
v13 = -1;
v12 = -1LL;
v14 = -1;
if ( a3 == 4 )
{
v5 = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 - 3));
BYTE1(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 - 3));
BYTE2(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 4), (unsigned __int16)(a2 - 3));
BYTE3(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 6), (unsigned __int16)(a2 - 3));
v9 = (unsigned __int16)(a2 - 4);
BYTE4(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 9), (unsigned __int16)(a2 - 3));
BYTE5(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 - 3));
BYTE6(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 - 3));
HIBYTE(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 3), v9);
LOBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 3), v9);
BYTE1(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 4), v9);
BYTE2(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 6), v9);
HIBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 9), v9);
LOBYTE(v14) = gfxLSReadPixel((unsigned __int16)(a1 + 11), v9);
v10 = gfxLSReadPixel((unsigned __int16)(a1 + 11), v9);
v7 = 4;
HIBYTE(v14) = v10;
goto LABEL_14;
}
if ( a3 > 4u )
{
if ( a3 == 8 )
{
v5 = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 + 13));
BYTE1(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 + 13));
BYTE2(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 4), (unsigned __int16)(a2 + 13));
BYTE3(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 6), (unsigned __int16)(a2 + 13));
BYTE4(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 9), (unsigned __int16)(a2 + 13));
BYTE5(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 + 13));
BYTE6(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 + 13));
HIBYTE(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 + 14));
LOBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 + 14));
BYTE1(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 4), (unsigned __int16)(a2 + 14));
BYTE2(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 6), (unsigned __int16)(a2 + 14));
HIBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 9), (unsigned __int16)(a2 + 14));
LOBYTE(v14) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 + 14));
v8 = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 + 14));
v7 = 8;
HIBYTE(v14) = v8;
goto LABEL_14;
}
}
else
{
if ( a3 == 1 )
{
v5 = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 - 2));
BYTE1(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned int)a2);
BYTE2(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 2));
BYTE3(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 4));
BYTE4(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 6));
BYTE5(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 8));
BYTE6(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 10));
HIBYTE(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 - 2));
LOBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned int)a2);
BYTE1(v13) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 2));
BYTE2(v13) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 4));
HIBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 6));
LOBYTE(v14) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 8));
v11 = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 10));
v7 = 1;
HIBYTE(v14) = v11;
goto LABEL_14;
}
if ( a3 == 2 )
{
v5 = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 - 2));
BYTE1(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned int)a2);
BYTE2(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 2));
BYTE3(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 4));
BYTE4(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 6));
BYTE5(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 8));
BYTE6(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 10));
HIBYTE(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 - 2));
LOBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned int)a2);
BYTE1(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 2));
BYTE2(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 4));
HIBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 6));
LOBYTE(v14) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 8));
v6 = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 10));
v7 = 2;
HIBYTE(v14) = v6;
LABEL_14:
result = 0LL;
if ( (v5 & 0xBE) == 0 )
result = v7;
if ( (v12 & 0xBE00) == 0 )
result = v7;
if ( (v12 & 0xBE0000) == 0 )
result = v7;
if ( (v12 & 0xBE000000LL) == 0 )
result = v7;
if ( (v12 & 0xBE00000000LL) == 0 )
result = v7;
if ( (v12 & 0xBE0000000000LL) == 0 )
result = v7;
if ( (v12 & 0xBE000000000000LL) == 0 )
result = v7;
if ( (v12 & 0xBE00000000000000LL) == 0 )
result = v7;
if ( (v13 & 0xBE) == 0 )
result = v7;
if ( (v13 & 0xBE00) == 0 )
result = v7;
if ( (v13 & 0xBE0000) == 0 )
result = v7;
if ( (v13 & 0xBE000000) == 0 )
result = v7;
if ( (v14 & 0xBE) == 0 )
result = v7;
if ( (v14 & 0xBE00u) == 0 )
result = v7;
if ( ((v5 & 0xBE) == 0 || (v12 & 0xBE00) == 0)
&& ((v12 & 0xBE0000000000LL) == 0 || (v12 & 0xBE000000000000LL) == 0)
&& (v12 & 0xBE000000LL) != 0 )
{
result = 0LL;
}
if ( ((v12 & 0xBE00000000000000LL) == 0 || (v13 & 0xBE) == 0)
&& ((v14 & 0xBE00u) == 0 || (v14 & 0xBE) == 0)
&& (v13 & 0xBE0000) != 0 )
{
result = 0LL;
}
return result;
}
}
v5 = -1;
v7 = 0;
goto LABEL_14;
}
result = 6LL;
if ( a2 > 2 )
{
LOBYTE(result) = a2 >= 239;
result = (unsigned int)(8 * result + 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, unsigned __int8 a3)
{
int v3; // ebp
__int64 result; // rax
char v5; // r14
char v6; // al
unsigned int v7; // edx
char v8; // al
__int64 v9; // rbx
char v10; // al
char v11; // al
__int64 v12; // [rsp+12h] [rbp-46h]
int v13; // [rsp+1Ah] [rbp-3Eh]
__int16 v14; // [rsp+1Eh] [rbp-3Ah]

if ( (GamePlayMode[1] & 0x10) != 0 )
return 0LL;
v3 = a2;
if ( a1 <= 2 )
{
result = 5LL;
if ( a2 > 2 )
{
LOBYTE(v3) = a2 > 238;
result = (unsigned int)(8 * v3 + 1);
}
return result;
}
if ( a1 <= 622 )
{
result = 4LL;
if ( a2 <= 2 )
return result;
result = 8LL;
if ( a2 > 238 )
return result;
v13 = -1;
v12 = -1LL;
v14 = -1;
if ( a3 == 4 )
{
v5 = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 - 3));
BYTE1(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 - 3));
BYTE2(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 4), (unsigned __int16)(a2 - 3));
BYTE3(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 6), (unsigned __int16)(a2 - 3));
v9 = (unsigned __int16)(a2 - 4);
BYTE4(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 9), (unsigned __int16)(a2 - 3));
BYTE5(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 - 3));
BYTE6(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 - 3));
HIBYTE(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 3), v9);
LOBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 3), v9);
BYTE1(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 4), v9);
BYTE2(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 6), v9);
HIBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 9), v9);
LOBYTE(v14) = gfxLSReadPixel((unsigned __int16)(a1 + 11), v9);
v10 = gfxLSReadPixel((unsigned __int16)(a1 + 11), v9);
v7 = 4;
HIBYTE(v14) = v10;
goto LABEL_14;
}
if ( a3 > 4u )
{
if ( a3 == 8 )
{
v5 = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 + 13));
BYTE1(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 + 13));
BYTE2(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 4), (unsigned __int16)(a2 + 13));
BYTE3(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 6), (unsigned __int16)(a2 + 13));
BYTE4(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 9), (unsigned __int16)(a2 + 13));
BYTE5(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 + 13));
BYTE6(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 + 13));
HIBYTE(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 + 14));
LOBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 3), (unsigned __int16)(a2 + 14));
BYTE1(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 4), (unsigned __int16)(a2 + 14));
BYTE2(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 6), (unsigned __int16)(a2 + 14));
HIBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 9), (unsigned __int16)(a2 + 14));
LOBYTE(v14) = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 + 14));
v8 = gfxLSReadPixel((unsigned __int16)(a1 + 11), (unsigned __int16)(a2 + 14));
v7 = 8;
HIBYTE(v14) = v8;
goto LABEL_14;
}
}
else
{
if ( a3 == 1 )
{
v5 = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 - 2));
BYTE1(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned int)a2);
BYTE2(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 2));
BYTE3(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 4));
BYTE4(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 6));
BYTE5(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 8));
BYTE6(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 2), (unsigned __int16)(a2 + 10));
HIBYTE(v12) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 - 2));
LOBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned int)a2);
BYTE1(v13) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 2));
BYTE2(v13) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 4));
HIBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 6));
LOBYTE(v14) = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 8));
v11 = gfxLSReadPixel((unsigned __int16)(a1 - 1), (unsigned __int16)(a2 + 10));
v7 = 1;
HIBYTE(v14) = v11;
goto LABEL_14;
}
if ( a3 == 2 )
{
v5 = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 - 2));
BYTE1(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned int)a2);
BYTE2(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 2));
BYTE3(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 4));
BYTE4(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 6));
BYTE5(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 8));
BYTE6(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 16), (unsigned __int16)(a2 + 10));
HIBYTE(v12) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 - 2));
LOBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned int)a2);
BYTE1(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 2));
BYTE2(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 4));
HIBYTE(v13) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 6));
LOBYTE(v14) = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 8));
v6 = gfxLSReadPixel((unsigned __int16)(a1 + 17), (unsigned __int16)(a2 + 10));
v7 = 2;
HIBYTE(v14) = v6;
LABEL_14:
result = 0LL;
if ( (v5 & 0xBE) == 0 )
result = v7;
if ( (v12 & 0xBE00) == 0 )
result = v7;
if ( (v12 & 0xBE0000) == 0 )
result = v7;
if ( (v12 & 0xBE000000LL) == 0 )
result = v7;
if ( (v12 & 0xBE00000000LL) == 0 )
result = v7;
if ( (v12 & 0xBE0000000000LL) == 0 )
result = v7;
if ( (v12 & 0xBE000000000000LL) == 0 )
result = v7;
if ( (v12 & 0xBE00000000000000LL) == 0 )
result = v7;
if ( (v13 & 0xBE) == 0 )
result = v7;
if ( (v13 & 0xBE00) == 0 )
result = v7;
if ( (v13 & 0xBE0000) == 0 )
result = v7;
if ( (v13 & 0xBE000000) == 0 )
result = v7;
if ( (v14 & 0xBE) == 0 )
result = v7;
if ( (v14 & 0xBE00u) == 0 )
result = v7;
if ( ((v5 & 0xBE) == 0 || (v12 & 0xBE00) == 0)
&& ((v12 & 0xBE0000000000LL) == 0 || (v12 & 0xBE000000000000LL) == 0)
&& (v12 & 0xBE000000LL) != 0 )
{
result = 0LL;
}
if ( ((v12 & 0xBE00000000000000LL) == 0 || (v13 & 0xBE) == 0)
&& ((v14 & 0xBE00u) == 0 || (v14 & 0xBE) == 0)
&& (v13 & 0xBE0000) != 0 )
{
result = 0LL;
}
return result;
}
}
v5 = -1;
v7 = 0;
goto LABEL_14;
}
result = 6LL;
if ( a2 > 2 )
{
LOBYTE(result) = a2 >= 239;
result = (unsigned int)(8 * result + 2);
}
return result;
}

original_code:
ubyte lsIsCollision(S32 x, S32 y, ubyte direction)
{
    S32 i;
    ubyte collis = 0;
    ubyte color[14], collisDir = 0;
    if (GamePlayMode & (1<<12))
 return 0;
    if (x <= 2)
 collis |= 1;
    if (x >= (640 - 14 - 3))
 collis |= 2;
    if (y <= 2)
 collis |= 4;
    if (y >= (256 - 14 - 3))
 collis |= 8;
    if (collis)
 return collis;
    for (i = 0; i < 14; i++)
 color[i] = 255;
    switch (direction) {
    case 1:
 color[0] = gfxLSReadPixel(x - 2, y - 2);
 color[1] = gfxLSReadPixel(x - 2, y + 0);
 color[2] = gfxLSReadPixel(x - 2, y + 2);
 color[3] = gfxLSReadPixel(x - 2, y + 4);
 color[4] = gfxLSReadPixel(x - 2, y + 6);
 color[5] = gfxLSReadPixel(x - 2, y + 8);
 color[6] = gfxLSReadPixel(x - 2, y + 10);
 color[7] = gfxLSReadPixel(x - 1, y - 2);
 color[8] = gfxLSReadPixel(x - 1, y + 0);
 color[9] = gfxLSReadPixel(x - 1, y + 2);
 color[10] = gfxLSReadPixel(x - 1, y + 4);
 color[11] = gfxLSReadPixel(x - 1, y + 6);
 color[12] = gfxLSReadPixel(x - 1, y + 8);
 color[13] = gfxLSReadPixel(x - 1, y + 10);
 collisDir |= 1;
 break;
    case 2:
 color[0] = gfxLSReadPixel(x + 16, y - 2);
 color[1] = gfxLSReadPixel(x + 16, y + 0);
 color[2] = gfxLSReadPixel(x + 16, y + 2);
 color[3] = gfxLSReadPixel(x + 16, y + 4);
 color[4] = gfxLSReadPixel(x + 16, y + 6);
 color[5] = gfxLSReadPixel(x + 16, y + 8);
 color[6] = gfxLSReadPixel(x + 16, y + 10);
 color[7] = gfxLSReadPixel(x + 17, y - 2);
 color[8] = gfxLSReadPixel(x + 17, y + 0);
 color[9] = gfxLSReadPixel(x + 17, y + 2);
 color[10] = gfxLSReadPixel(x + 17, y + 4);
 color[11] = gfxLSReadPixel(x + 17, y + 6);
 color[12] = gfxLSReadPixel(x + 17, y + 8);
 color[13] = gfxLSReadPixel(x + 17, y + 10);
 collisDir |= 2;
 break;
    case 4:
 color[0] = gfxLSReadPixel(x + 3, y - 3);
 color[1] = gfxLSReadPixel(x + 3, y - 3);
 color[2] = gfxLSReadPixel(x + 4, y - 3);
 color[3] = gfxLSReadPixel(x + 6, y - 3);
 color[4] = gfxLSReadPixel(x + 9, y - 3);
 color[5] = gfxLSReadPixel(x + 11, y - 3);
 color[6] = gfxLSReadPixel(x + 11, y - 3);
 color[7] = gfxLSReadPixel(x + 3, y - 4);
 color[8] = gfxLSReadPixel(x + 3, y - 4);
 color[9] = gfxLSReadPixel(x + 4, y - 4);
 color[10] = gfxLSReadPixel( x + 6, y - 4);
 color[11] = gfxLSReadPixel( x + 9, y - 4);
 color[12] = gfxLSReadPixel( x + 11, y - 4);
 color[13] = gfxLSReadPixel( x + 11, y - 4);
 collisDir |= 4;
 break;
    case 8:
 color[0] = gfxLSReadPixel(x + 3, y + 13);
 color[1] = gfxLSReadPixel(x + 3, y + 13);
 color[2] = gfxLSReadPixel(x + 4, y + 13);
 color[3] = gfxLSReadPixel(x + 6, y + 13);
 color[4] = gfxLSReadPixel(x + 9, y + 13);
 color[5] = gfxLSReadPixel(x + 11, y + 13);
 color[6] = gfxLSReadPixel(x + 11, y + 13);
 color[7] = gfxLSReadPixel(x + 3, y + 14);
 color[8] = gfxLSReadPixel(x + 3, y + 14);
 color[9] = gfxLSReadPixel(x + 4, y + 14);
 color[10] = gfxLSReadPixel(x + 6, y + 14);
 color[11] = gfxLSReadPixel(x + 9, y + 14);
 color[12] = gfxLSReadPixel(x + 11, y + 14);
 color[13] = gfxLSReadPixel(x + 11, y + 14);
 collisDir |= 8;
 break;
    default:
 break;
    }
    for (i = 0; i < 14; i++) {
 if ((color[i] != 1) && (color[i] != 65)
     && (color[i] != 0)
     && (color[i] != 64))
     color[i] = 0;
 else
     color[i] = 1;
    }
    for (i = 0; i < 14; i++)
 if (color[i])
     collis = collisDir;
    if ((color[0] || color[1]) && (color[6] || color[5]) && !color[3])
 collis = 0;
    if ((color[7] || color[8]) && (color[13] || color[12]) && !color[10])
 collis = 0;
    return collis;
}

canonical_original_code:
unsigned char lsIsCollision(int x, int y, unsigned char direction)
{
    int i;
    unsigned char collis = 0;
    unsigned char color[14]; unsigned char collisDir = 0;
    if (GamePlayMode & (1<<12))
 return 0;
    if (x <= 2)
 collis |= 1;
    if (x >= (640 - 14 - 3))
 collis |= 2;
    if (y <= 2)
 collis |= 4;
    if (y >= (256 - 14 - 3))
 collis |= 8;
    if (collis)
 return collis;
    for (i = 0; i < 14; i++)
 color[i] = 255;
    switch (direction) {
    case 1:
 color[0] = gfxLSReadPixel(x - 2, y - 2);
 color[1] = gfxLSReadPixel(x - 2, y + 0);
 color[2] = gfxLSReadPixel(x - 2, y + 2);
 color[3] = gfxLSReadPixel(x - 2, y + 4);
 color[4] = gfxLSReadPixel(x - 2, y + 6);
 color[5] = gfxLSReadPixel(x - 2, y + 8);
 color[6] = gfxLSReadPixel(x - 2, y + 10);
 color[7] = gfxLSReadPixel(x - 1, y - 2);
 color[8] = gfxLSReadPixel(x - 1, y + 0);
 color[9] = gfxLSReadPixel(x - 1, y + 2);
 color[10] = gfxLSReadPixel(x - 1, y + 4);
 color[11] = gfxLSReadPixel(x - 1, y + 6);
 color[12] = gfxLSReadPixel(x - 1, y + 8);
 color[13] = gfxLSReadPixel(x - 1, y + 10);
 collisDir |= 1;
 break;
    case 2:
 color[0] = gfxLSReadPixel(x + 16, y - 2);
 color[1] = gfxLSReadPixel(x + 16, y + 0);
 color[2] = gfxLSReadPixel(x + 16, y + 2);
 color[3] = gfxLSReadPixel(x + 16, y + 4);
 color[4] = gfxLSReadPixel(x + 16, y + 6);
 color[5] = gfxLSReadPixel(x + 16, y + 8);
 color[6] = gfxLSReadPixel(x + 16, y + 10);
 color[7] = gfxLSReadPixel(x + 17, y - 2);
 color[8] = gfxLSReadPixel(x + 17, y + 0);
 color[9] = gfxLSReadPixel(x + 17, y + 2);
 color[10] = gfxLSReadPixel(x + 17, y + 4);
 color[11] = gfxLSReadPixel(x + 17, y + 6);
 color[12] = gfxLSReadPixel(x + 17, y + 8);
 color[13] = gfxLSReadPixel(x + 17, y + 10);
 collisDir |= 2;
 break;
    case 4:
 color[0] = gfxLSReadPixel(x + 3, y - 3);
 color[1] = gfxLSReadPixel(x + 3, y - 3);
 color[2] = gfxLSReadPixel(x + 4, y - 3);
 color[3] = gfxLSReadPixel(x + 6, y - 3);
 color[4] = gfxLSReadPixel(x + 9, y - 3);
 color[5] = gfxLSReadPixel(x + 11, y - 3);
 color[6] = gfxLSReadPixel(x + 11, y - 3);
 color[7] = gfxLSReadPixel(x + 3, y - 4);
 color[8] = gfxLSReadPixel(x + 3, y - 4);
 color[9] = gfxLSReadPixel(x + 4, y - 4);
 color[10] = gfxLSReadPixel( x + 6, y - 4);
 color[11] = gfxLSReadPixel( x + 9, y - 4);
 color[12] = gfxLSReadPixel( x + 11, y - 4);
 color[13] = gfxLSReadPixel( x + 11, y - 4);
 collisDir |= 4;
 break;
    case 8:
 color[0] = gfxLSReadPixel(x + 3, y + 13);
 color[1] = gfxLSReadPixel(x + 3, y + 13);
 color[2] = gfxLSReadPixel(x + 4, y + 13);
 color[3] = gfxLSReadPixel(x + 6, y + 13);
 color[4] = gfxLSReadPixel(x + 9, y + 13);
 color[5] = gfxLSReadPixel(x + 11, y + 13);
 color[6] = gfxLSReadPixel(x + 11, y + 13);
 color[7] = gfxLSReadPixel(x + 3, y + 14);
 color[8] = gfxLSReadPixel(x + 3, y + 14);
 color[9] = gfxLSReadPixel(x + 4, y + 14);
 color[10] = gfxLSReadPixel(x + 6, y + 14);
 color[11] = gfxLSReadPixel(x + 9, y + 14);
 color[12] = gfxLSReadPixel(x + 11, y + 14);
 color[13] = gfxLSReadPixel(x + 11, y + 14);
 collisDir |= 8;
 break;
    default:
 break;
    }
    for (i = 0; i < 14; i++) {
 if ((color[i] != 1) && (color[i] != 65)
     && (color[i] != 0)
     && (color[i] != 64))
     color[i] = 0;
 else
     color[i] = 1;
    }
    for (i = 0; i < 14; i++)
 if (color[i])
     collis = collisDir;
    if ((color[0] || color[1]) && (color[6] || color[5]) && !color[3])
 collis = 0;
    if ((color[7] || color[8]) && (color[13] || color[12]) && !color[10])
 collis = 0;
    return collis;
}

variable_types: x int

variable_types: y int

variable_types:
direction
unsigned char

variable_types: i int

variable_types:
collis
unsigned char

variable_types:
color
unsigned char [14]

variable_types:
collisDir
unsigned char

return_type: unsigned char


lsInitScrollLandScape

original_code:
ubyte lsInitScrollLandScape(ubyte direction, ubyte mode)
{
    register struct LandScape *l = ls;
    S32 dx = 0, dy = 0, px = 0, py = 0, tx = 0, ty = 0, speed =
 (S32) l->uch_ScrollSpeed;
    ubyte collis = 0;
    if (direction & 1) {
 if ((l->us_WindowXPos >= speed) && (l->us_PersonXPos <= (320 / 2))) {
     dx = -1L;
     l->us_LivingXSpeed = (word) dx;
     l->us_LivingYSpeed = 0;
     l->uch_LivingAction = ((ubyte)3);
 } else {
     if (l->us_PersonXPos > speed) {
  px = -1L;
  l->us_LivingXSpeed = (word) px;
  l->us_LivingYSpeed = 0;
  l->uch_LivingAction = ((ubyte)3);
     }
 }
    }
    if (direction & 2) {
 if ((l->us_WindowXPos <=
      (640 - 320 - speed))
     && (l->us_PersonXPos >= (320 / 2))) {
     dx = 1;
     l->us_LivingXSpeed = (word) dx;
     l->us_LivingYSpeed = 0;
     l->uch_LivingAction = ((ubyte)2);
 } else {
     if (l->us_PersonXPos < (320 - speed)) {
  px = 1L;
  l->us_LivingXSpeed = (word) px;
  l->us_LivingYSpeed = 0;
  l->uch_LivingAction = ((ubyte)2);
     }
 }
    }
    if (direction & 4) {
 if ((l->us_WindowYPos >= (speed)) && (l->us_PersonYPos <= (128 / 2))) {
     dy = -1L;
     l->us_LivingXSpeed = 0;
     l->us_LivingYSpeed = (word) dy;
     l->uch_LivingAction = ((ubyte)0);
 } else {
     if (l->us_PersonYPos > (speed)) {
  py = -1L;
  l->us_LivingXSpeed = 0;
  l->us_LivingYSpeed = (word) py;
  l->uch_LivingAction = ((ubyte)0);
     }
 }
    }
    if (direction & 8) {
 if (l->us_WindowYPos <= (256 - 128 - speed)
     && (l->us_PersonYPos >= (128 / 2))) {
     dy = 1L;
     l->us_LivingXSpeed = 0;
     l->us_LivingYSpeed = (word) dy;
     l->uch_LivingAction = ((ubyte)1);
 } else {
     if (l->us_PersonYPos < (128 - speed)) {
  py = 1L;
  l->us_LivingXSpeed = 0;
  l->us_LivingYSpeed = (word) py;
  l->uch_LivingAction = ((ubyte)1);
     }
 }
    }
    tx = livGetXPos(l->uch_ActivLiving) + (px + dx) * speed;
    ty = livGetYPos(l->uch_ActivLiving) + (py + dy) * speed;
    collis = lsIsCollision(tx, ty, direction);
    if (mode & 1) {
 DX = dx;
 DY = dy;
 PX = px;
 PY = py;
    }
    return (collis);
}

canonical_original_code:
unsigned char lsInitScrollLandScape(unsigned char direction, unsigned char mode)
{
    register struct LandScape *l = ls;
    int dx = 0; int dy = 0; int px = 0; int py = 0; int tx = 0; int ty = 0; int speed = (S32) l->uch_ScrollSpeed;
    unsigned char collis = 0;
    if (direction & 1) {
 if ((l->us_WindowXPos >= speed) && (l->us_PersonXPos <= (320 / 2))) {
     dx = -1L;
     l->us_LivingXSpeed = (short) dx;
     l->us_LivingYSpeed = 0;
     l->uch_LivingAction = ((unsigned char)3);
 } else {
     if (l->us_PersonXPos > speed) {
  px = -1L;
  l->us_LivingXSpeed = (short) px;
  l->us_LivingYSpeed = 0;
  l->uch_LivingAction = ((unsigned char)3);
     }
 }
    }
    if (direction & 2) {
 if ((l->us_WindowXPos <=
      (640 - 320 - speed))
     && (l->us_PersonXPos >= (320 / 2))) {
     dx = 1;
     l->us_LivingXSpeed = (short) dx;
     l->us_LivingYSpeed = 0;
     l->uch_LivingAction = ((unsigned char)2);
 } else {
     if (l->us_PersonXPos < (320 - speed)) {
  px = 1L;
  l->us_LivingXSpeed = (short) px;
  l->us_LivingYSpeed = 0;
  l->uch_LivingAction = ((unsigned char)2);
     }
 }
    }
    if (direction & 4) {
 if ((l->us_WindowYPos >= (speed)) && (l->us_PersonYPos <= (128 / 2))) {
     dy = -1L;
     l->us_LivingXSpeed = 0;
     l->us_LivingYSpeed = (short) dy;
     l->uch_LivingAction = ((unsigned char)0);
 } else {
     if (l->us_PersonYPos > (speed)) {
  py = -1L;
  l->us_LivingXSpeed = 0;
  l->us_LivingYSpeed = (short) py;
  l->uch_LivingAction = ((unsigned char)0);
     }
 }
    }
    if (direction & 8) {
 if (l->us_WindowYPos <= (256 - 128 - speed)
     && (l->us_PersonYPos >= (128 / 2))) {
     dy = 1L;
     l->us_LivingXSpeed = 0;
     l->us_LivingYSpeed = (short) dy;
     l->uch_LivingAction = ((unsigned char)1);
 } else {
     if (l->us_PersonYPos < (128 - speed)) {
  py = 1L;
  l->us_LivingXSpeed = 0;
  l->us_LivingYSpeed = (short) py;
  l->uch_LivingAction = ((unsigned char)1);
     }
 }
    }
    tx = livGetXPos(l->uch_ActivLiving) + (px + dx) * speed;
    ty = livGetYPos(l->uch_ActivLiving) + (py + dy) * speed;
    collis = lsIsCollision(tx, ty, direction);
    if (mode & 1) {
 DX = dx;
 DY = dy;
 PX = px;
 PY = py;
    }
    return (collis);
}

variable_types:
mode
unsigned char

variable_types: struct LandScape { unsigned int ul_BuildingID; unsigned int ul_AreaID; unsigned char uch_ScrollSpeed; unsigned short us_WindowXSize; unsigned short us_WindowYSize; unsigned short us_WindowXPos; unsigned short us_WindowYPos; unsigned short us_PersonXPos; unsigned short us_PersonYPos; unsigned char uch_FloorsPerWindowColumn; unsigned char uch_FloorsPerWindowLine; unsigned char uch_CollMode; char uch_ActivLiving[256]; struct LSFloorSquare { unsigned char uch_FloorType; } *p_CurrFloor; struct LSFloorSquare *p_AllFloors[3]; unsigned int ul_FloorAreaId[3]; struct List { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Head; struct Node Tail; } *p_ObjectRetrieval; struct List *p_ObjectRetrievalLists[3]; unsigned int ul_ObjectRetrievalAreaId[3]; struct List *p_DoorRefreshList; unsigned short us_LivingXSpeed; unsigned short us_LivingYSpeed; short us_RasInfoScrollX; short us_RasInfoScrollY; unsigned short us_EscapeCarBobId; unsigned short us_DoorXOffset; unsigned short us_DoorYOffset; unsigned char uch_LivingAction; unsigned char uch_ShowObjectMask; } *

variable_types: dx int

variable_types: dy int

variable_types: px int

variable_types: py int

variable_types: tx int

variable_types: ty int

variable_types: speed int

user_defined_types: struct LandScape { unsigned int ul_BuildingID; unsigned int ul_AreaID; unsigned char uch_ScrollSpeed; unsigned short us_WindowXSize; unsigned short us_WindowYSize; unsigned short us_WindowXPos; unsigned short us_WindowYPos; unsigned short us_PersonXPos; unsigned short us_PersonYPos; unsigned char uch_FloorsPerWindowColumn; unsigned char uch_FloorsPerWindowLine; unsigned char uch_CollMode; char uch_ActivLiving[256]; struct LSFloorSquare *p_CurrFloor; struct LSFloorSquare *p_AllFloors[3]; unsigned int ul_FloorAreaId[3]; struct List *p_ObjectRetrieval; struct List *p_ObjectRetrievalLists[3]; unsigned int ul_ObjectRetrievalAreaId[3]; struct List *p_DoorRefreshList; unsigned short us_LivingXSpeed; unsigned short us_LivingYSpeed; short us_RasInfoScrollX; short us_RasInfoScrollY; unsigned short us_EscapeCarBobId; unsigned short us_DoorXOffset; unsigned short us_DoorYOffset; unsigned char uch_LivingAction; unsigned char uch_ShowObjectMask; }


lsScrollLandScape

decompiled_code:
__int64 __fastcall lsScrollLandScape(unsigned int a1)
{
__int64 v1; // r12
__int16 v2; // bp
__int64 result; // rax

v1 = ls;
v2 = *(unsigned __int8 *)(ls + 8LL);
if ( (_BYTE)a1 != 0xFF && (unsigned __int8)lsInitScrollLandScape(a1, 1) )
return 0LL;
lsScrollCorrectData(
(unsigned __int8)v2 * (unsigned int)(unsigned __int16)word_9BE,
(unsigned __int8)v2 * (unsigned int)(unsigned __int16)DY);
result = a1;
*(_WORD *)(v1 + 18) += v2 * PX;
*(_WORD *)(v1 + 20) += PY * v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 v1; // r12
__int16 v2; // bp
__int64 result; // rax

v1 = ls;
v2 = *(unsigned __int8 *)(ls + 8LL);
if ( (_BYTE)a1 != 0xFF && (unsigned __int8)func1(a1, 1) )
return 0LL;
lsScrollCorrectData(
(unsigned __int8)v2 * (unsigned int)(unsigned __int16)word_9BE,
(unsigned __int8)v2 * (unsigned int)(unsigned __int16)DY);
result = a1;
*(_WORD *)(v1 + 18) += v2 * PX;
*(_WORD *)(v1 + 20) += PY * v2;
return result;
}

original_code:
ubyte lsScrollLandScape(ubyte direction)
{
    struct LandScape *l = ls;
    ubyte collis = 0, back = 0, speed = ls->uch_ScrollSpeed;
    if (direction != (ubyte) - 1)
 collis = lsInitScrollLandScape(direction, 1);
    if (!collis) {
 lsScrollCorrectData(DX * speed, DY * speed);
 l->us_PersonXPos += (PX * speed);
 l->us_PersonYPos += (PY * speed);
 back = (ubyte) direction;
    }
    return back;
}

canonical_original_code:
unsigned char lsScrollLandScape(unsigned char direction)
{
    struct LandScape *l = ls;
    unsigned char collis = 0; unsigned char back = 0; unsigned char speed = ls->uch_ScrollSpeed;
    if (direction != (ubyte) - 1)
 collis = lsInitScrollLandScape(direction, 1);
    if (!collis) {
 lsScrollCorrectData(DX * speed, DY * speed);
 l->us_PersonXPos += (PX * speed);
 l->us_PersonYPos += (PY * speed);
 back = (unsigned char) direction;
    }
    return back;
}

variable_types:
back
unsigned char

variable_types:
speed
unsigned char

user_defined_types: struct LSFloorSquare { unsigned char uch_FloorType; }


lsExtendGetList

decompiled_code:
__int64 __fastcall lsExtendGetList(__int64 a1, int a2, unsigned int a3, __int64 a4)
{
__int64 result; // rax

result = dbAddObjectNode(a1, a3, 3LL);
*(_DWORD *)(result + 32) = a2;
*(_DWORD *)(result + 36) = a3;
*(_QWORD *)(result + 40) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, unsigned int a3, __int64 a4)
{
__int64 result; // rax

result = dbAddObjectNode(a1, a3, 3LL);
*(_DWORD *)(result + 32) = a2;
*(_DWORD *)(result + 36) = a3;
*(_QWORD *)(result + 40) = a4;
return result;
}

original_code:
static void lsExtendGetList(LIST * list, U32 nr, U32 type, void *data)
{
    struct ObjectNode *new =
 dbAddObjectNode(list, type, (1) | (1 << 1));
    new->nr = nr;
    new->type = type;
    new->data = data;
}

canonical_original_code:
static void lsExtendGetList(struct List *list, unsigned int nr, unsigned int type, void *data)
{
    struct ObjectNode *new = dbAddObjectNode(list, type, (1) | (1 << 1));
    new->nr = nr;
    new->type = type;
    new->data = data;
}

variable_types: struct List { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Head; struct Node Tail; } *

variable_types:
nr
unsigned int

variable_types:
type
unsigned int

variable_types:
data
void *

variable_types: struct ObjectNode { struct Node { struct Node *Succ; struct Node *Pred; char *Name; unsigned long Size; } Link; unsigned int nr; unsigned int type; void *data; } *


lsIsLSObjectInActivArea

decompiled_code:
bool __fastcall lsIsLSObjectInActivArea(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // rax

v1 = ConsistOfRelationID;
v2 = dbGetObject(*(unsigned int *)(ls + 4LL));
return (unsigned int)AskP(v2, v1, a1, 0xFFFFFFFFLL, 0LL) != 0;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // rax

v1 = ConsistOfRelationID;
v2 = dbGetObject(*(unsigned int *)(ls + 4LL));
return (unsigned int)AskP(v2, v1, a1, 0xFFFFFFFFLL, 0LL) != 0;
}

original_code:
_Bool lsIsLSObjectInActivArea(LSObject lso)
{
    if (AskP
 (dbGetObject(ls->ul_AreaID), ConsistOfRelationID, lso, (4294967295U),
  ((U8)0)))
 return 1;
    return 0;
}

canonical_original_code:
_Bool lsIsLSObjectInActivArea(struct _LSObject *lso)
{
    if (AskP
 (dbGetObject(ls->ul_AreaID), ConsistOfRelationID, lso, (4294967295U),
  ((unsigned char)0)))
 return 1;
    return 0;
}

variable_types: struct _LSObject { unsigned short us_OffsetFact; unsigned short us_DestX; unsigned short us_DestY; unsigned char uch_ExactX; unsigned char uch_ExactY; unsigned char uch_ExactX1; unsigned char uch_ExactY1; unsigned char uch_Size; unsigned char uch_Visible; unsigned char uch_Chained; unsigned int ul_Status; unsigned int Type; } *


lsSetObjectRetrievalList

decompiled_code:
__int64 __fastcall lsSetObjectRetrievalList(int a1)
{
__int64 result; // rax

result = ls;
if ( a1 == *(_DWORD *)(ls + 368LL) )
*(_QWORD *)(ls + 336LL) = *(_QWORD *)(ls + 344LL);
if ( a1 == *(_DWORD *)(result + 372) )
*(_QWORD *)(result + 336) = *(_QWORD *)(result + 352);
if ( *(_DWORD *)(result + 376) == a1 )
*(_QWORD *)(result + 336) = *(_QWORD *)(result + 360);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 result; // rax

result = ls;
if ( a1 == *(_DWORD *)(ls + 368LL) )
*(_QWORD *)(ls + 336LL) = *(_QWORD *)(ls + 344LL);
if ( a1 == *(_DWORD *)(result + 372) )
*(_QWORD *)(result + 336) = *(_QWORD *)(result + 352);
if ( *(_DWORD *)(result + 376) == a1 )
*(_QWORD *)(result + 336) = *(_QWORD *)(result + 360);
return result;
}

original_code:
void lsSetObjectRetrievalList(U32 ul_AreaId)
{
    S32 i;
    for (i = 0; i < 3; i++)
 if (ul_AreaId == ls->ul_ObjectRetrievalAreaId[i])
     ls->p_ObjectRetrieval = ls->p_ObjectRetrievalLists[i];
}

canonical_original_code:
void lsSetObjectRetrievalList(unsigned int ul_AreaId)
{
    int i;
    for (i = 0; i < 3; i++)
 if (ul_AreaId == ls->ul_ObjectRetrievalAreaId[i])
     ls->p_ObjectRetrieval = ls->p_ObjectRetrievalLists[i];
}

variable_types: i int


lsGetCurrObjectRetrieval

decompiled_code:
__int64 lsGetCurrObjectRetrieval()
{
__int64 v0; // rdx
__int64 v2; // rcx

v0 = *(_QWORD *)(ls + 336LL);
if ( v0 == *(_QWORD *)(ls + 344LL) )
{
v2 = 0LL;
}
else if ( v0 == *(_QWORD *)(ls + 352LL) )
{
v2 = 1LL;
}
else
{
if ( v0 != *(_QWORD *)(ls + 360LL) )
return 0LL;
v2 = 2LL;
}
return *(unsigned int *)(ls + 4 * v2 + 368);
}

original_code:
U32 lsGetCurrObjectRetrieval(void)
{
    S32 i;
    for (i = 0; i < 3; i++)
 if (ls->p_ObjectRetrieval == ls->p_ObjectRetrievalLists[i])
     return ls->ul_ObjectRetrievalAreaId[i];
    return 0;
}

canonical_original_code:
unsigned int lsGetCurrObjectRetrieval()
{
    int i;
    for (i = 0; i < 3; i++)
 if (ls->p_ObjectRetrieval == ls->p_ObjectRetrievalLists[i])
     return ls->ul_ObjectRetrievalAreaId[i];
    return 0;
}


lsIsObjectADoor

decompiled_code:
bool __fastcall lsIsObjectADoor(__int64 a1)
{
bool result; // al

if ( (unsigned int)(*(_DWORD *)(a1 + 20) - 9201) > 0x31 )
result = 0;
else
result = ((1LL << (*(_BYTE *)(a1 + 20) + 15)) & 0x2000000000043LL) != 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1)
{
bool result; // al

if ( (unsigned int)(*(_DWORD *)(a1 + 20) - 9201) > 0x31 )
result = 0;
else
result = ((1LL << (*(_BYTE *)(a1 + 20) + 15)) & 0x2000000000043LL) != 0;
return result;
}

original_code:
_Bool lsIsObjectADoor(LSObject lso)
{
    switch (lso->Type) {
    case 9201U:
    case 9202U:
    case 9250U:
    case 9207U:
 return 1;
    }
    return 0;
}

canonical_original_code:
_Bool lsIsObjectADoor(struct _LSObject *lso)
{
    switch (lso->Type) {
    case 9201U:
    case 9202U:
    case 9250U:
    case 9207U:
 return 1;
    }
    return 0;
}


lsIsObjectAWall

decompiled_code:
char __fastcall lsIsObjectAWall(__int64 a1)
{
unsigned int v1; // ecx
unsigned __int64 v2; // rax
__int64 v3; // rdx
char result; // al
unsigned int v5; // ecx

v1 = *(_DWORD *)(a1 + 20);
v2 = v1 - 9208;
if ( (unsigned int)v2 <= 0x35 )
{
v3 = 0x20200000000003LL;
if ( _bittest64(&v3, v2) )
return 1;
}
result = setup[1];
if ( result )
{
if ( v1 <= 0x127 )
{
result = v1 > 0x121;
}
else
{
v5 = v1 - 9284;
if ( v5 > 0x16 )
result = 0;
else
result = ((1LL << v5) & 0x400103) != 0;
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func5(__int64 a1)
{
unsigned int v1; // ecx
unsigned __int64 v2; // rax
__int64 v3; // rdx
char result; // al
unsigned int v5; // ecx

v1 = *(_DWORD *)(a1 + 20);
v2 = v1 - 9208;
if ( (unsigned int)v2 <= 0x35 )
{
v3 = 0x20200000000003LL;
if ( _bittest64(&v3, v2) )
return 1;
}
result = setup[1];
if ( result )
{
if ( v1 <= 0x127 )
{
result = v1 > 0x121;
}
else
{
v5 = v1 - 9284;
if ( v5 > 0x16 )
result = 0;
else
result = ((1LL << v5) & 0x400103) != 0;
}
}
return result;
}

original_code:
_Bool lsIsObjectAWall(LSObject lso)
{
    switch (lso->Type) {
    case 9208U:
    case 9209U:
    case 9253U:
    case 9261U:
 return 1;
    }
    if (setup.Profidisk) {
        switch (lso->Type) {
        case 9285U:
        case 9284U:
        case 9292U:
        case 9306U:
        case 290U:
        case 291U:
        case 292U:
        case 293U:
        case 294U:
        case 295U:
     return 1;
        }
    }
    return 0;
}

canonical_original_code:
_Bool lsIsObjectAWall(struct _LSObject *lso)
{
    switch (lso->Type) {
    case 9208U:
    case 9209U:
    case 9253U:
    case 9261U:
 return 1;
    }
    if (setup.Profidisk) {
        switch (lso->Type) {
        case 9285U:
        case 9284U:
        case 9292U:
        case 9306U:
        case 290U:
        case 291U:
        case 292U:
        case 293U:
        case 294U:
        case 295U:
     return 1;
        }
    }
    return 0;
}