plDisplayTimer

decompiled_code:
__int64 __fastcall plDisplayTimer(unsigned int a1, char a2)
{
unsigned int v2; // ebx
unsigned __int16 v3; // r12
unsigned __int16 v4; // ax
__int64 result; // rax
char s[104]; // [rsp+0h] [rbp-68h] BYREF

v2 = a1;
if ( !a1 )
v2 = (unsigned int)CurrentTimer(plSys) / 3;
if ( (GamePlayMode & 0x10) != 0 )
{
v3 = livGetYPos((char *)&Planing_Name + 20 * CurrentPerson);
v4 = livGetXPos((char *)&Planing_Name + 20 * CurrentPerson);
sprintf(
s,
"x:%d, y:%d %s %.2d:%.2d:%.2d %s",
v4,
v3,
(const char *)&txtTimer,
v2 / 0xE10uLL,
v2 / 0x3C % 0x3C,
v2 % 0x3C,
(const char *)&txtSeconds);
gfxSetPens(m_gc, 0LL, 0LL, 0LL);
gfxRectFill(m_gc, 120LL, 0LL, 320LL, 10LL);
}
else
{
sprintf(
s,
"%s %.2d:%.2d:%.2d %s",
(const char *)&txtTimer,
v2 / 0xE10uLL,
v2 / 0x3C % 0x3C,
v2 % 0x3C,
(const char *)&txtSeconds);
gfxSetPens(m_gc, 0LL, 0LL, 0LL);
gfxRectFill(m_gc, 220LL, 0LL, 320LL, 10LL);
}
gfxSetRect(2LL, 320LL);
gfxSetPens(m_gc, 248LL, 255LL, 255LL);
gfxPrint(m_gc, s, 2LL, 2LL);
if ( a2 || (result = CurrentTimer(plSys), (_DWORD)result != -1) )
{
CurrentTimer(plSys);
result = lsMoveAllSpots(v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, char a2)
{
unsigned int v2; // ebx
unsigned __int16 v3; // r12
unsigned __int16 v4; // ax
__int64 result; // rax
char s[104]; // [rsp+0h] [rbp-68h] BYREF

v2 = a1;
if ( !a1 )
v2 = (unsigned int)CurrentTimer(plSys) / 3;
if ( (GamePlayMode & 0x10) != 0 )
{
v3 = livGetYPos((char *)&Planing_Name + 20 * CurrentPerson);
v4 = livGetXPos((char *)&Planing_Name + 20 * CurrentPerson);
sprintf(
s,
"x:%d, y:%d %s %.2d:%.2d:%.2d %s",
v4,
v3,
(const char *)&txtTimer,
v2 / 0xE10uLL,
v2 / 0x3C % 0x3C,
v2 % 0x3C,
(const char *)&txtSeconds);
gfxSetPens(m_gc, 0LL, 0LL, 0LL);
gfxRectFill(m_gc, 120LL, 0LL, 320LL, 10LL);
}
else
{
sprintf(
s,
"%s %.2d:%.2d:%.2d %s",
(const char *)&txtTimer,
v2 / 0xE10uLL,
v2 / 0x3C % 0x3C,
v2 % 0x3C,
(const char *)&txtSeconds);
gfxSetPens(m_gc, 0LL, 0LL, 0LL);
gfxRectFill(m_gc, 220LL, 0LL, 320LL, 10LL);
}
gfxSetRect(2LL, 320LL);
gfxSetPens(m_gc, 248LL, 255LL, 255LL);
gfxPrint(m_gc, s, 2LL, 2LL);
if ( a2 || (result = CurrentTimer(plSys), (_DWORD)result != -1) )
{
CurrentTimer(plSys);
result = lsMoveAllSpots(v2);
}
return result;
}

original_code:
void plDisplayTimer(U32 time, ubyte doSpotsImmediatly)
{
    char info[80];
    U32 oldTimer = -1;
    if (!time)
 time = CurrentTimer(plSys) / 3;
    if (GamePlayMode & (1<< 4)) {
 sprintf(info, "x:%d, y:%d   %s %.2d:%.2d:%.2d %s",
  livGetXPos(Planing_Name[CurrentPerson]),
  livGetYPos(Planing_Name[CurrentPerson]), txtTimer,
  (U32) (time / 3600), (U32) ((time / 60) % 60),
  (U32) (time % 60), txtSeconds);
 gfxSetPens(m_gc, 0, 0, 0);
 gfxRectFill(m_gc, 120, 0, 320, 10);
 gfxSetRect(2, 320);
 gfxSetPens(m_gc, 248, ((ubyte)255), ((ubyte)255));
 gfxPrint(m_gc, info, 2, (1<<1));
    } else {
 sprintf(info, "%s %.2d:%.2d:%.2d %s", txtTimer, (U32) (time / 3600),
  (U32) ((time / 60) % 60), (U32) (time % 60), txtSeconds);
 gfxSetPens(m_gc, 0, 0, 0);
 gfxRectFill(m_gc, 220, 0, 320, 10);
 gfxSetRect(2, 320);
 gfxSetPens(m_gc, 248, ((ubyte)255), ((ubyte)255));
 gfxPrint(m_gc, info, 2, (1<<1));
    }
    if (doSpotsImmediatly || (oldTimer != CurrentTimer(plSys))) {
 oldTimer = CurrentTimer(plSys);
 lsMoveAllSpots(time);
    }
}

canonical_original_code:
void plDisplayTimer(unsigned int time, unsigned char doSpotsImmediatly)
{
    char info[80];
    unsigned int oldTimer = -1;
    if (!time)
 time = CurrentTimer(plSys) / 3;
    if (GamePlayMode & (1<< 4)) {
 sprintf(info, "x:%d, y:%d   %s %.2d:%.2d:%.2d %s",
  livGetXPos(Planing_Name[CurrentPerson]),
  livGetYPos(Planing_Name[CurrentPerson]), txtTimer,
  (U32) (time / 3600), (U32) ((time / 60) % 60),
  (U32) (time % 60), txtSeconds);
 gfxSetPens(m_gc, 0, 0, 0);
 gfxRectFill(m_gc, 120, 0, 320, 10);
 gfxSetRect(2, 320);
 gfxSetPens(m_gc, 248, ((unsigned char)255), ((unsigned char)255));
 gfxPrint(m_gc, info, 2, (1<<1));
    } else {
 sprintf(info, "%s %.2d:%.2d:%.2d %s", txtTimer, (U32) (time / 3600),
  (U32) ((time / 60) % 60), (U32) (time % 60), txtSeconds);
 gfxSetPens(m_gc, 0, 0, 0);
 gfxRectFill(m_gc, 220, 0, 320, 10);
 gfxSetRect(2, 320);
 gfxSetPens(m_gc, 248, ((unsigned char)255), ((unsigned char)255));
 gfxPrint(m_gc, info, 2, (1<<1));
    }
    if (doSpotsImmediatly || (oldTimer != CurrentTimer(plSys))) {
 oldTimer = CurrentTimer(plSys);
 lsMoveAllSpots(time);
    }
}

variable_types:
time
unsigned int

variable_types:
doSpotsImmediatly
unsigned char

variable_types:
oldTimer
unsigned int


plDisplayInfo

repo: vcosta/derclou

decompiled_code:
__int64 plDisplayInfo()
{
__int64 v0; // rax
_BYTE v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = GetNthNode(PersonsList, CurrentPerson);
dbGetObjectName(*(unsigned int *)(v0 + 32), v2);
gfxSetPens(m_gc, 0LL, 0LL, 0LL);
gfxRectFill(m_gc, 0LL, 0LL, 120LL, 10LL);
gfxSetRect(2LL, 320LL);
gfxSetPens(m_gc, 248LL, 255LL, 255LL);
return gfxPrint(m_gc, v2, 2LL, 12LL);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
_BYTE v2[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = GetNthNode(PersonsList, CurrentPerson);
dbGetObjectName(*(unsigned int *)(v0 + 32), v2);
gfxSetPens(m_gc, 0LL, 0LL, 0LL);
gfxRectFill(m_gc, 0LL, 0LL, 120LL, 10LL);
gfxSetRect(2LL, 320LL);
gfxSetPens(m_gc, 248LL, 255LL, 255LL);
return gfxPrint(m_gc, v2, 2LL, 12LL);
}

original_code:
void plDisplayInfo(void)
{
    char info[80];
    dbGetObjectName((((struct ObjectNode *)GetNthNode(PersonsList, CurrentPerson))->nr), info);
    gfxSetPens(m_gc, 0, 0, 0);
    gfxRectFill(m_gc, 0, 0, 120, 10);
    gfxSetRect(2, 320);
    gfxSetPens(m_gc, 248, ((ubyte)255), ((ubyte)255));
    gfxPrint(m_gc, info, 2, (1<<2) | (1<<3));
}

canonical_original_code:
void plDisplayInfo()
{
    char info[80];
    dbGetObjectName((((struct ObjectNode *)GetNthNode(PersonsList, CurrentPerson))->nr), info);
    gfxSetPens(m_gc, 0, 0, 0);
    gfxRectFill(m_gc, 0, 0, 120, 10);
    gfxSetRect(2, 320);
    gfxSetPens(m_gc, 248, ((unsigned char)255), ((unsigned char)255));
    gfxPrint(m_gc, info, 2, (1<<2) | (1<<3));
}

variable_types:
info
char [80]

return_type: void

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

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


plSay

decompiled_code:
__int64 __fastcall plSay(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
__int64 v3; // rax
unsigned __int16 *v4; // rax
unsigned int v5; // ebp

v2 = txtGoKey(11LL, a1);
v3 = GetNthNode(PersonsList, a2);
v4 = (unsigned __int16 *)dbGetObject(*(unsigned int *)(v3 + 32));
SetPictID(*v4);
inpTurnESC(0LL);
inpTurnFunctionKey(0LL);
v5 = Bubble(v2, 0LL, 0LL, 200LL);
inpTurnFunctionKey(1LL);
inpTurnESC(1LL);
RemoveList(v2);
plDisplayTimer(0, 1);
plDisplayInfo();
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
__int64 v3; // rax
unsigned __int16 *v4; // rax
unsigned int v5; // ebp

v2 = txtGoKey(11LL, a1);
v3 = GetNthNode(PersonsList, a2);
v4 = (unsigned __int16 *)dbGetObject(*(unsigned int *)(v3 + 32));
SetPictID(*v4);
inpTurnESC(0LL);
inpTurnFunctionKey(0LL);
v5 = Bubble(v2, 0LL, 0LL, 200LL);
inpTurnFunctionKey(1LL);
inpTurnESC(1LL);
RemoveList(v2);
func2(0, 1);
func3();
return v5;
}

original_code:
ubyte plSay(char *msg, U32 persId)
{
    register LIST *l = txtGoKey(11U, msg);
    register ubyte choice;
    SetPictID(((Person) dbGetObject((((struct ObjectNode *)GetNthNode(PersonsList, persId))->nr)))->
       PictID);
    inpTurnESC(0);
    inpTurnFunctionKey(0);
    choice = Bubble(l, 0, ((void *)0), 200);
    inpTurnFunctionKey(1);
    inpTurnESC(1);
    RemoveList(l);
    plDisplayTimer(0, 1);
    plDisplayInfo();
    return choice;
}

canonical_original_code:
unsigned char plSay(char *msg, unsigned int persId)
{
    register struct List *l = txtGoKey(11U, msg);
    register unsigned char choice;
    SetPictID(((struct _Person *) dbGetObject((((struct ObjectNode *)GetNthNode(PersonsList, persId))->nr)))->
       PictID);
    inpTurnESC(0);
    inpTurnFunctionKey(0);
    choice = Bubble(l, 0, ((void *)0), 200);
    inpTurnFunctionKey(1);
    inpTurnESC(1);
    RemoveList(l);
    plDisplayTimer(0, 1);
    plDisplayInfo();
    return choice;
}

variable_types:
msg
char *

variable_types:
persId
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:
choice
unsigned char

return_type: unsigned char

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

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: 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 }


plDrawWait

decompiled_code:
__int64 __fastcall plDrawWait(unsigned int a1)
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

sprintf(s, "%.2d:%.2d", a1 / 0x3CuLL, a1 % 0x3C);
gfxSetDrMd(m_gc, 1LL);
gfxSetPens(m_gc, 248LL, 255LL, 255LL);
gfxSetRect(0LL, 320LL);
gfxPrint(m_gc, s, 31LL, 1LL);
return gfxSetDrMd(m_gc, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

sprintf(s, "%.2d:%.2d", a1 / 0x3CuLL, a1 % 0x3C);
gfxSetDrMd(m_gc, 1LL);
gfxSetPens(m_gc, 248LL, 255LL, 255LL);
gfxSetRect(0LL, 320LL);
gfxPrint(m_gc, s, 31LL, 1LL);
return gfxSetDrMd(m_gc, 0LL);
}

original_code:
void plDrawWait(U32 sec)
{
    char time[10];
    sprintf(time, "%.2d:%.2d", (U32) (sec / 60), (U32) (sec % 60));
    gfxSetDrMd(m_gc, GFX_JAM_2);
    gfxSetPens(m_gc, 248, ((ubyte)255), ((ubyte)255));
    gfxSetRect(0, 320);
    gfxPrint(m_gc, time, 31, (1));
    gfxSetDrMd(m_gc, GFX_JAM_1);
}

canonical_original_code:
void plDrawWait(unsigned int sec)
{
    char time[10];
    sprintf(time, "%.2d:%.2d", (U32) (sec / 60), (U32) (sec % 60));
    gfxSetDrMd(m_gc, GFX_JAM_2);
    gfxSetPens(m_gc, 248, ((unsigned char)255), ((unsigned char)255));
    gfxSetRect(0, 320);
    gfxPrint(m_gc, time, 31, (1));
    gfxSetDrMd(m_gc, GFX_JAM_1);
}

variable_types:
sec
unsigned int

variable_types:
time
char [10]


plRefresh

decompiled_code:
__int64 __fastcall plRefresh(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebx

v1 = dbGetObject(a1);
if ( (unsigned __int8)lsIsLSObjectInActivArea(v1) )
lsFastRefresh(v1);
v2 = lsGetStartArea();
if ( v2 == (unsigned int)lsGetActivAreaID() )
lsShowEscapeCar();
return lsRefreshAllLootBags();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebx

v1 = dbGetObject(a1);
if ( (unsigned __int8)lsIsLSObjectInActivArea(v1) )
lsFastRefresh(v1);
v2 = lsGetStartArea();
if ( v2 == (unsigned int)lsGetActivAreaID() )
lsShowEscapeCar();
return lsRefreshAllLootBags();
}

original_code:
void plRefresh(U32 ItemId)
{
    register LSObject obj = (LSObject) dbGetObject(ItemId);
    if (lsIsLSObjectInActivArea(obj))
 lsFastRefresh(obj);
    if (lsGetStartArea() == lsGetActivAreaID())
 lsShowEscapeCar();
    lsRefreshAllLootBags();
}

canonical_original_code:
void plRefresh(unsigned int ItemId)
{
    register struct _LSObject *obj = (LSObject) dbGetObject(ItemId);
    if (lsIsLSObjectInActivArea(obj))
 lsFastRefresh(obj);
    if (lsGetStartArea() == lsGetActivAreaID())
 lsShowEscapeCar();
    lsRefreshAllLootBags();
}

variable_types:
ItemId
unsigned 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; } *


sndResetBuffer

decompiled_code:
void __fastcall sndResetBuffer(__int64 a1)
{
*(_DWORD *)(a1 + 12) = 0;
*(_DWORD *)(a1 + 16) = 0;
}

original_code:
void sndResetBuffer(SND_BUFFER *buffer)
{
    buffer->insertPos = 0;
    buffer->removePos = 0;
}

canonical_original_code:
void sndResetBuffer(struct SndBuffer *buffer)
{
    buffer->insertPos = 0;
    buffer->removePos = 0;
}

variable_types: struct SndBuffer { unsigned char *data; unsigned int size; unsigned int insertPos; unsigned int removePos; } *


sndCreateBuffer

decompiled_code:
__int64 __fastcall sndCreateBuffer(unsigned int a1)
{
__int64 v1; // rbx

v1 = TCAllocMem(24LL, 0LL);
*(_QWORD *)v1 = TCAllocMem(a1, 1LL);
*(_DWORD *)(v1 + 8) = a1;
sndResetBuffer(v1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 v1; // rbx

v1 = TCAllocMem(24LL, 0LL);
*(_QWORD *)v1 = TCAllocMem(a1, 1LL);
*(_DWORD *)(v1 + 8) = a1;
func0(v1);
return v1;
}

original_code:
SND_BUFFER *sndCreateBuffer(unsigned size)
{
    SND_BUFFER *buffer;
    unsigned char *data;
    buffer = TCAllocMem(sizeof(*buffer), 0);
    data = TCAllocMem(size, 1);
    buffer->data = data;
    buffer->size = size;
    sndResetBuffer(buffer);
    return buffer;
}

canonical_original_code:
struct SndBuffer *sndCreateBuffer(unsigned int size)
{
    struct SndBuffer *buffer;
    unsigned char *data;
    buffer = TCAllocMem(sizeof(*buffer), 0);
    data = TCAllocMem(size, 1);
    buffer->data = data;
    buffer->size = size;
    sndResetBuffer(buffer);
    return buffer;
}

variable_types:
size
unsigned int

variable_types:
data
unsigned char *

return_type: struct SndBuffer { unsigned char *data; unsigned int size; unsigned int insertPos; unsigned int removePos; } *


sndFreeBuffer

decompiled_code:
__int64 __fastcall sndFreeBuffer(__int64 a1)
{
TCFreeMem(*(_QWORD *)a1, *(unsigned int *)(a1 + 8));
return TCFreeMem(a1, 24LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
TCFreeMem(*(_QWORD *)a1, *(unsigned int *)(a1 + 8));
return TCFreeMem(a1, 24LL);
}

original_code:
void sndFreeBuffer(SND_BUFFER *buffer)
{
    TCFreeMem(buffer->data, buffer->size);
    TCFreeMem(buffer, sizeof(*buffer));
}

canonical_original_code:
void sndFreeBuffer(struct SndBuffer *buffer)
{
    TCFreeMem(buffer->data, buffer->size);
    TCFreeMem(buffer, sizeof(*buffer));
}

user_defined_types: struct SndBuffer { unsigned char *data; unsigned int size; unsigned int insertPos; unsigned int removePos; }


sndLenBuffer

decompiled_code:
__int64 __fastcall sndLenBuffer(__int64 a1)
{
return (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 16));
}

original_code:
unsigned sndLenBuffer(SND_BUFFER *buffer)
{
    return buffer->insertPos - buffer->removePos;
}

canonical_original_code:
unsigned int sndLenBuffer(struct SndBuffer *buffer)
{
    return buffer->insertPos - buffer->removePos;
}

return_type: unsigned int


sndInsertBuffer

decompiled_code:
__int64 __fastcall sndInsertBuffer(__int64 a1, char *a2, unsigned int a3)
{
unsigned int v4; // ebx
unsigned int v5; // edx
unsigned int v6; // edx
unsigned int v7; // ebx

v4 = *(_DWORD *)(a1 + 8);
v5 = v4 - sndLenBuffer(a1);
if ( v5 <= a3 )
a3 = v5;
v6 = *(_DWORD *)(a1 + 12) % v4;
v7 = v4 - v6;
if ( v7 > a3 )
v7 = a3;
memcpy((void *)(*(_QWORD *)a1 + v6), a2, v7);
memcpy(*(void **)a1, &a2[v7], a3 - v7);
*(_DWORD *)(a1 + 12) += a3;
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2, unsigned int a3)
{
unsigned int v4; // ebx
unsigned int v5; // edx
unsigned int v6; // edx
unsigned int v7; // ebx

v4 = *(_DWORD *)(a1 + 8);
v5 = v4 - func3(a1);
if ( v5 <= a3 )
a3 = v5;
v6 = *(_DWORD *)(a1 + 12) % v4;
v7 = v4 - v6;
if ( v7 > a3 )
v7 = a3;
memcpy((void *)(*(_QWORD *)a1 + v6), a2, v7);
memcpy(*(void **)a1, &a2[v7], a3 - v7);
*(_DWORD *)(a1 + 12) += a3;
return a3;
}

original_code:
unsigned sndInsertBuffer(SND_BUFFER *buffer, const void *src, unsigned srcLen)
{
    const unsigned char *psrc = src;
    unsigned len, pos;
    srcLen = ((srcLen) < (buffer->size - sndLenBuffer(buffer)) ? (srcLen) : (buffer->size - sndLenBuffer(buffer)));
    pos = buffer->insertPos % buffer->size;
    len = ((srcLen) < (buffer->size - pos) ? (srcLen) : (buffer->size - pos));
    memcpy(buffer->data + pos, psrc, len);
    memcpy(buffer->data, psrc + len, srcLen - len);
    buffer->insertPos += srcLen;
    return srcLen;
}

canonical_original_code:
unsigned int sndInsertBuffer(struct SndBuffer *buffer, void *src, unsigned int srcLen)
{
    unsigned char *psrc = src;
    unsigned int len; unsigned int pos;
    srcLen = ((srcLen) < (buffer->size - sndLenBuffer(buffer)) ? (srcLen) : (buffer->size - sndLenBuffer(buffer)));
    pos = buffer->insertPos % buffer->size;
    len = ((srcLen) < (buffer->size - pos) ? (srcLen) : (buffer->size - pos));
    memcpy(buffer->data + pos, psrc, len);
    memcpy(buffer->data, psrc + len, srcLen - len);
    buffer->insertPos += srcLen;
    return srcLen;
}

variable_types:
src
void *

variable_types:
srcLen
unsigned int

variable_types:
psrc
unsigned char *

variable_types:
len
unsigned int

variable_types:
pos
unsigned int


sndRemoveBuffer

decompiled_code:
__int64 __fastcall sndRemoveBuffer(__int64 a1, char *a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // er12
unsigned int v6; // edx
unsigned int v7; // er12

v4 = sndLenBuffer(a1);
if ( v4 <= a3 )
a3 = v4;
v5 = *(_DWORD *)(a1 + 8);
v6 = *(_DWORD *)(a1 + 16) % v5;
v7 = v5 - v6;
if ( v7 > a3 )
v7 = a3;
memcpy(a2, (const void *)(*(_QWORD *)a1 + v6), v7);
memcpy(&a2[v7], *(const void **)a1, a3 - v7);
*(_DWORD *)(a1 + 16) += a3;
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char *a2, unsigned int a3)
{
unsigned int v4; // eax
unsigned int v5; // er12
unsigned int v6; // edx
unsigned int v7; // er12

v4 = func3(a1);
if ( v4 <= a3 )
a3 = v4;
v5 = *(_DWORD *)(a1 + 8);
v6 = *(_DWORD *)(a1 + 16) % v5;
v7 = v5 - v6;
if ( v7 > a3 )
v7 = a3;
memcpy(a2, (const void *)(*(_QWORD *)a1 + v6), v7);
memcpy(&a2[v7], *(const void **)a1, a3 - v7);
*(_DWORD *)(a1 + 16) += a3;
return a3;
}

original_code:
unsigned sndRemoveBuffer(SND_BUFFER *buffer, void *dst, unsigned dstLen)
{
    unsigned char *pdst = dst;
    unsigned len, pos;
    dstLen = ((dstLen) < (sndLenBuffer(buffer)) ? (dstLen) : (sndLenBuffer(buffer)));
    pos = buffer->removePos % buffer->size;
    len = ((dstLen) < (buffer->size - pos) ? (dstLen) : (buffer->size - pos));
    memcpy(pdst, buffer->data + pos, len);
    memcpy(pdst + len, buffer->data, dstLen - len);
    buffer->removePos += dstLen;
    return dstLen;
}

canonical_original_code:
unsigned int sndRemoveBuffer(struct SndBuffer *buffer, void *dst, unsigned int dstLen)
{
    unsigned char *pdst = dst;
    unsigned int len; unsigned int pos;
    dstLen = ((dstLen) < (sndLenBuffer(buffer)) ? (dstLen) : (sndLenBuffer(buffer)));
    pos = buffer->removePos % buffer->size;
    len = ((dstLen) < (buffer->size - pos) ? (dstLen) : (buffer->size - pos));
    memcpy(pdst, buffer->data + pos, len);
    memcpy(pdst + len, buffer->data, dstLen - len);
    buffer->removePos += dstLen;
    return dstLen;
}

variable_types:
dst
void *

variable_types:
dstLen
unsigned int

variable_types:
pdst
unsigned char *


GetNthBob

decompiled_code:
char *__fastcall GetNthBob(unsigned __int16 a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 0xFFu )
result = (char *)list + 20 * a1;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int16 a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 0xFFu )
result = (char *)list + 20 * a1;
return result;
}

original_code:
static struct Bob *GetNthBob(uword BobID)
{
    if (BobID < 256)
 return &list[BobID];
    else
 return ((void *)0);
}

canonical_original_code:
static struct Bob *GetNthBob(unsigned short BobID)
{
    if (BobID < 256)
 return &list[BobID];
    else
 return ((void *)0);
}

variable_types:
BobID
unsigned short

return_type: struct Bob { unsigned short w; unsigned short xsrc; unsigned short xdst; unsigned short sx; int flags; } *


BobInitLists

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

if ( !init_0 )
{
result = gfxCollToMem(137LL, &BobRPInMem);
init_0 = 1;
}
return result;
}

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

if ( !init_0 )
{
result = gfxCollToMem(137LL, &BobRPInMem);
init_0 = 1;
}
return result;
}

original_code:
void BobInitLists(void)
{
    static _Bool init;
    if (!init) {
        gfxCollToMem(137, &BobRPInMem);
 init = 1;
    }
}

canonical_original_code:
void BobInitLists()
{
    static _Bool init;
    if (!init) {
        gfxCollToMem(137, &BobRPInMem);
 init = 1;
    }
}


BobInit

decompiled_code:
__int64 __fastcall BobInit(__int16 a1, __int16 a2)
{
unsigned __int64 v4; // r10
__int64 result; // rax
int v6; // edx
__int64 v7; // rsi
__int64 v8; // rcx

v4 = (unsigned int)((_DWORD)list + 16);
result = 0LL;
while ( *(_DWORD *)v4 )
{
v6 = result + 1;
result = (unsigned int)(result + 1);
if ( !*(_DWORD *)(v4 + 20) )
break;
result = (unsigned int)(v6 + 1);
if ( !*(_DWORD *)(v4 + 40) )
break;
result = (unsigned int)(v6 + 2);
if ( !*(_DWORD *)(v4 + 60) )
break;
result = (unsigned int)(v6 + 3);
if ( !*(_DWORD *)(v4 + 80) )
break;
result = (unsigned int)(v6 + 4);
if ( !*(_DWORD *)(v4 + 100) )
break;
result = (unsigned int)(v6 + 5);
if ( !*(_DWORD *)(v4 + 120) )
break;
result = (unsigned int)(v6 + 6);
if ( !*(_DWORD *)(v4 + 140) )
break;
result = (unsigned int)(v6 + 7);
v4 += 160LL;
if ( (_WORD)v6 == 249 )
return result;
}
if ( (unsigned __int16)result <= 0xFFu )
{
v7 = 10LL * (unsigned __int16)result;
*(__m128i *)&list[v7] = _mm_load_si128((const __m128i *)&bob_zero);
*(_DWORD *)&list[v7 + 8] = *((_DWORD *)&bob_zero + 4);
v8 = 5LL * (unsigned __int16)result;
list[2 * v8] = a1;
list[2 * v8 + 1] = a2;
*(_DWORD *)&list[2 * v8 + 8] = *(_DWORD *)&list[v7 + 8] | 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1, __int16 a2)
{
unsigned __int64 v4; // r10
__int64 result; // rax
int v6; // edx
__int64 v7; // rsi
__int64 v8; // rcx

v4 = (unsigned int)((_DWORD)list + 16);
result = 0LL;
while ( *(_DWORD *)v4 )
{
v6 = result + 1;
result = (unsigned int)(result + 1);
if ( !*(_DWORD *)(v4 + 20) )
break;
result = (unsigned int)(v6 + 1);
if ( !*(_DWORD *)(v4 + 40) )
break;
result = (unsigned int)(v6 + 2);
if ( !*(_DWORD *)(v4 + 60) )
break;
result = (unsigned int)(v6 + 3);
if ( !*(_DWORD *)(v4 + 80) )
break;
result = (unsigned int)(v6 + 4);
if ( !*(_DWORD *)(v4 + 100) )
break;
result = (unsigned int)(v6 + 5);
if ( !*(_DWORD *)(v4 + 120) )
break;
result = (unsigned int)(v6 + 6);
if ( !*(_DWORD *)(v4 + 140) )
break;
result = (unsigned int)(v6 + 7);
v4 += 160LL;
if ( (_WORD)v6 == 249 )
return result;
}
if ( (unsigned __int16)result <= 0xFFu )
{
v7 = 10LL * (unsigned __int16)result;
*(__m128i *)&list[v7] = _mm_load_si128((const __m128i *)&bob_zero);
*(_DWORD *)&list[v7 + 8] = *((_DWORD *)&bob_zero + 4);
v8 = 5LL * (unsigned __int16)result;
list[2 * v8] = a1;
list[2 * v8 + 1] = a2;
*(_DWORD *)&list[2 * v8 + 8] = *(_DWORD *)&list[v7 + 8] | 1;
}
return result;
}

original_code:
uword BobInit(uword width, uword height)
{
    struct Bob *bob;
    uword BobID;
    for (BobID = 0; BobID < 256 && list[BobID].flags != 0; BobID++);
    if (BobID < 256) {
 bob = &list[BobID];
 *bob = bob_zero;
 bob->w = width;
 bob->h = height;
 bob->flags |= 1;
    }
    return BobID;
}

canonical_original_code:
unsigned short BobInit(unsigned short width, unsigned short height)
{
    struct Bob *bob;
    unsigned short BobID;
    for (BobID = 0; BobID < 256 && list[BobID].flags != 0; BobID++);
    if (BobID < 256) {
 bob = &list[BobID];
 *bob = bob_zero;
 bob->w = width;
 bob->h = height;
 bob->flags |= 1;
    }
    return BobID;
}

variable_types:
width
unsigned short

variable_types:
height
unsigned short

variable_types: struct Bob { unsigned short w; unsigned short xsrc; unsigned short xdst; unsigned short sx; int flags; } *

return_type: unsigned short


BobDone

decompiled_code:
char *__fastcall BobDone(unsigned __int16 a1)
{
char *result; // rax

result = GetNthBob(a1);
*((_DWORD *)result + 4) = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned __int16 a1)
{
char *result; // rax

result = func0(a1);
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
void BobDone(uword BobID)
{
    struct Bob *bob = GetNthBob(BobID);
    bob->flags = 0;
}

canonical_original_code:
void BobDone(unsigned short BobID)
{
    struct Bob *bob = GetNthBob(BobID);
    bob->flags = 0;
}

user_defined_types: struct Bob { unsigned short w; unsigned short xsrc; unsigned short xdst; unsigned short sx; int flags; }


BobSet

original_code:
ubyte BobSet(uword BobID, uword xdst, uword ydst, uword xsrc, uword ysrc)
{
    struct Bob *bob = GetNthBob(BobID);
    bob->xsrc = xsrc;
    bob->ysrc = ysrc;
    bob->xdst = xdst;
    bob->ydst = ydst;
    return 1;
}

canonical_original_code:
unsigned char BobSet(unsigned short BobID, unsigned short xdst, unsigned short ydst, unsigned short xsrc, unsigned short ysrc)
{
    struct Bob *bob = GetNthBob(BobID);
    bob->xsrc = xsrc;
    bob->ysrc = ysrc;
    bob->xdst = xdst;
    bob->ydst = ydst;
    return 1;
}

variable_types:
xdst
unsigned short

variable_types:
ydst
unsigned short

variable_types:
xsrc
unsigned short

variable_types:
ysrc
unsigned short


BobVis

decompiled_code:
__int64 __fastcall BobVis(unsigned __int16 a1)
{
char *v1; // rax

v1 = GetNthBob(a1);
*((_DWORD *)v1 + 4) |= 2u;
return gfxNCH4Refresh();
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 a1)
{
char *v1; // rax

v1 = func0(a1);
*((_DWORD *)v1 + 4) |= 2u;
return gfxNCH4Refresh();
}

original_code:
void BobVis(uword BobID)
{
    struct Bob *bob = GetNthBob(BobID);
    bob->flags |= 2;
    gfxNCH4Refresh();
}

canonical_original_code:
void BobVis(unsigned short BobID)
{
    struct Bob *bob = GetNthBob(BobID);
    bob->flags |= 2;
    gfxNCH4Refresh();
}


BobInVis

decompiled_code:
__int64 __fastcall BobInVis(unsigned __int16 a1)
{
char *v1; // rax

v1 = GetNthBob(a1);
*((_DWORD *)v1 + 4) &= 0xFFFFFFFD;
return gfxNCH4Refresh();
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 a1)
{
char *v1; // rax

v1 = func0(a1);
*((_DWORD *)v1 + 4) &= 0xFFFFFFFD;
return gfxNCH4Refresh();
}

original_code:
void BobInVis(uword BobID)
{
    struct Bob *bob = GetNthBob(BobID);
    bob->flags &= ~2;
    gfxNCH4Refresh();
}

canonical_original_code:
void BobInVis(unsigned short BobID)
{
    struct Bob *bob = GetNthBob(BobID);
    bob->flags &= ~2;
    gfxNCH4Refresh();
}


BobSetDarkness

decompiled_code:
void BobSetDarkness()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void BobSetDarkness(ubyte darkness)
{
}

canonical_original_code:
void BobSetDarkness(unsigned char darkness)
{
}

variable_types:
darkness
unsigned char


FadeInsideObject

decompiled_code:
__int64 FadeInsideObject()
{
char v0; // dl

v0 = status_0++;
return lsFadeRasterObject((unsigned int)CurrAreaId, CurrLSO, v0 & 1);
}

canonical_decompiled_code:
__int64 func0()
{
char v0; // dl

v0 = status_0++;
return lsFadeRasterObject((unsigned int)CurrAreaId, CurrLSO, v0 & 1);
}

original_code:
static void FadeInsideObject(void)
{
    static ubyte status = 1;
    lsFadeRasterObject(CurrAreaId, CurrLSO, (status++) % 2);
}

canonical_original_code:
static void FadeInsideObject()
{
    static unsigned char status = 1;
    lsFadeRasterObject(CurrAreaId, CurrLSO, (status++) % 2);
}

variable_types:
status
unsigned char


tcGoInsideOfHouse

decompiled_code:
__int64 __fastcall tcGoInsideOfHouse(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rax
unsigned int v3; // ebp
unsigned int v4; // er12
unsigned int i; // er12
__int64 v6; // rax
__int64 v7; // rax
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = txtGoKey(0LL, "INSIDE_MENU");
SetObjectListAttr(5LL, 509992LL);
v2 = dbGetObject(a1);
AskAll(v2, 500002LL, &BuildObjectList);
v9[0] = ObjectListPrivate;
dbSortObjectList(v9, &dbStdCompareObjects);
v3 = GetNrOfNodes(v9[0]) + 1;
v4 = 0;
if ( v3 > 2 )
{
if ( v3 <= 4 )
{
for ( i = v3; i != 5; ++i )
{
v6 = GetNthNode(v1, v3);
RemoveNode(v1, *(_QWORD *)(v6 + 16));
}
}
ShowMenuBackground();
inpTurnFunctionKey(0LL);
inpTurnESC(0LL);
v4 = (unsigned __int8)Menu(v1, (unsigned int)(1LL << v3) - 1, 0LL, 0LL, 0LL);
inpTurnESC(1LL);
inpTurnFunctionKey(1LL);
SetObjectListAttr(0LL, 509992LL);
v7 = dbGetObject(a1);
AskAll(v7, 500002LL, &BuildObjectList);
if ( v4 )
v4 = *(_DWORD *)(GetNthNode(v9[0], v4 - 1) + 32);
}
ShowMenuBackground();
ShowTime(0LL);
RemoveList(v9[0]);
RemoveList(v1);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rax
unsigned int v3; // ebp
unsigned int v4; // er12
unsigned int i; // er12
__int64 v6; // rax
__int64 v7; // rax
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = txtGoKey(0LL, "INSIDE_MENU");
SetObjectListAttr(5LL, 509992LL);
v2 = dbGetObject(a1);
AskAll(v2, 500002LL, &BuildObjectList);
v9[0] = ObjectListPrivate;
dbSortObjectList(v9, &dbStdCompareObjects);
v3 = GetNrOfNodes(v9[0]) + 1;
v4 = 0;
if ( v3 > 2 )
{
if ( v3 <= 4 )
{
for ( i = v3; i != 5; ++i )
{
v6 = GetNthNode(v1, v3);
RemoveNode(v1, *(_QWORD *)(v6 + 16));
}
}
ShowMenuBackground();
inpTurnFunctionKey(0LL);
inpTurnESC(0LL);
v4 = (unsigned __int8)Menu(v1, (unsigned int)(1LL << v3) - 1, 0LL, 0LL, 0LL);
inpTurnESC(1LL);
inpTurnFunctionKey(1LL);
SetObjectListAttr(0LL, 509992LL);
v7 = dbGetObject(a1);
AskAll(v7, 500002LL, &BuildObjectList);
if ( v4 )
v4 = *(_DWORD *)(GetNthNode(v9[0], v4 - 1) + 32);
}
ShowMenuBackground();
ShowTime(0LL);
RemoveList(v9[0]);
RemoveList(v1);
return v4;
}

original_code:
U32 tcGoInsideOfHouse(U32 buildingID)
{
    LIST *menu = txtGoKey(0U, "INSIDE_MENU"), *areas;
    U32 count, i, areaID = 0;
    { SetObjectListAttr ((1 << 2) | (1),509992L); AskAll (dbGetObject (buildingID), 500002, BuildObjectList); };
    areas = ObjectListPrivate;
    dbSortObjectList(&areas, dbStdCompareObjects);
    count = GetNrOfNodes(areas) + 1;
    if (count > 2) {
 for (i = count; i < 5; i++)
     RemoveNode(menu, (((NODE *)(GetNthNode(menu, count)))->Name));
 ShowMenuBackground();
 inpTurnFunctionKey(0);
 inpTurnESC(0);
 i = (U32) Menu(menu, (1L << count) - 1, 0, 0L, 0L);
 inpTurnESC(1);
 inpTurnFunctionKey(1);
 { SetObjectListAttr ((0),509992L); AskAll (dbGetObject (buildingID), 500002, BuildObjectList); };
 if (i)
     areaID = (((struct ObjectNode *)GetNthNode(areas, i - 1))->nr);
    }
    ShowMenuBackground();
    ShowTime(0);
    RemoveList(areas);
    RemoveList(menu);
    return (areaID);
}

canonical_original_code:
unsigned int tcGoInsideOfHouse(unsigned int buildingID)
{
    struct List *menu = txtGoKey(0U, "INSIDE_MENU"); struct List *areas;
    unsigned int count; unsigned int i; unsigned int areaID = 0;
    { SetObjectListAttr ((1 << 2) | (1),509992L); AskAll (dbGetObject (buildingID), 500002, BuildObjectList); };
    areas = ObjectListPrivate;
    dbSortObjectList(&areas, dbStdCompareObjects);
    count = GetNrOfNodes(areas) + 1;
    if (count > 2) {
 for (i = count; i < 5; i++)
     RemoveNode(menu, (((struct Node *)(GetNthNode(menu, count)))->Name));
 ShowMenuBackground();
 inpTurnFunctionKey(0);
 inpTurnESC(0);
 i = (unsigned int) Menu(menu, (1L << count) - 1, 0, 0L, 0L);
 inpTurnESC(1);
 inpTurnFunctionKey(1);
 { SetObjectListAttr ((0),509992L); AskAll (dbGetObject (buildingID), 500002, BuildObjectList); };
 if (i)
     areaID = (((struct ObjectNode *)GetNthNode(areas, i - 1))->nr);
    }
    ShowMenuBackground();
    ShowTime(0);
    RemoveList(areas);
    RemoveList(menu);
    return (areaID);
}

variable_types:
buildingID
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:
count
unsigned int

variable_types:
i
unsigned int

variable_types:
areaID
unsigned int


tcShowObjectData

decompiled_code:
__int64 __fastcall tcShowObjectData(unsigned int a1, __int64 a2, unsigned __int8 a3)
{
__int64 **i; // rbx
unsigned int v5; // eax

Present(*(unsigned int *)(a2 + 32), "RasterObject", &InitObjectPresent);
SetObjectListAttr(0LL, 9910LL);
AskAll(*(_QWORD *)(a2 + 40), hasLootRelationID, &BuildObjectList);
for ( i = (__int64 **)*ObjectList; *i; i = (__int64 **)*i )
{
v5 = GetP(*(_QWORD *)(a2 + 40), hasLootRelationID, i[5]);
SetP(i[5], hasLootRelationID, i[5], v5);
Present(*((unsigned int *)i + 8), "RasterObject", &InitOneLootPresent);
UnSet(i[5], hasLootRelationID, i[5]);
}
return lsShowAllConnections(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2, unsigned __int8 a3)
{
__int64 **i; // rbx
unsigned int v5; // eax

Present(*(unsigned int *)(a2 + 32), "RasterObject", &InitObjectPresent);
SetObjectListAttr(0LL, 9910LL);
AskAll(*(_QWORD *)(a2 + 40), hasLootRelationID, &BuildObjectList);
for ( i = (__int64 **)*ObjectList; *i; i = (__int64 **)*i )
{
v5 = GetP(*(_QWORD *)(a2 + 40), hasLootRelationID, i[5]);
SetP(i[5], hasLootRelationID, i[5], v5);
Present(*((unsigned int *)i + 8), "RasterObject", &InitOneLootPresent);
UnSet(i[5], hasLootRelationID, i[5]);
}
return lsShowAllConnections(a1, a2, a3);
}

original_code:
void tcShowObjectData(U32 areaID, NODE * node, ubyte perc)
{
    NODE *n;
    Present((((struct ObjectNode *)node)->nr), "RasterObject", InitObjectPresent);
    SetObjectListAttr((0), 9910L);
    AskAll((((struct ObjectNode *)node)->data), hasLootRelationID, BuildObjectList);
    if (!(!(((NODE *)(((((NODE *)((&(((ObjectList)))->Head)))->Succ))))->Succ))) {
 for (n = (NODE *) ((((NODE *)((&((ObjectList))->Head)))->Succ)); (((NODE *)(n))->Succ);
      n = (NODE *) (((NODE *)(n))->Succ)) {
     SetP((((struct ObjectNode *)n)->data), hasLootRelationID, (((struct ObjectNode *)n)->data),
   GetP((((struct ObjectNode *)node)->data), hasLootRelationID, (((struct ObjectNode *)n)->data)));
     Present((((struct ObjectNode *)n)->nr), "RasterObject", InitOneLootPresent);
     UnSet((((struct ObjectNode *)n)->data), hasLootRelationID, (((struct ObjectNode *)n)->data));
 }
    }
    lsShowAllConnections(areaID, node, perc);
}

canonical_original_code:
void tcShowObjectData(unsigned int areaID, struct Node *node, unsigned char perc)
{
    struct Node *n;
    Present((((struct ObjectNode *)node)->nr), "RasterObject", InitObjectPresent);
    SetObjectListAttr((0), 9910L);
    AskAll((((struct ObjectNode *)node)->data), hasLootRelationID, BuildObjectList);
    if (!(!(((struct Node *)(((((struct Node *)((&(((ObjectList)))->Head)))->Succ))))->Succ))) {
 for (n = (struct Node *) ((((struct Node *)((&((ObjectList))->Head)))->Succ)); (((struct Node *)(n))->Succ);
      n = (struct Node *) (((struct Node *)(n))->Succ)) {
     SetP((((struct ObjectNode *)n)->data), hasLootRelationID, (((struct ObjectNode *)n)->data),
   GetP((((struct ObjectNode *)node)->data), hasLootRelationID, (((struct ObjectNode *)n)->data)));
     Present((((struct ObjectNode *)n)->nr), "RasterObject", InitOneLootPresent);
     UnSet((((struct ObjectNode *)n)->data), hasLootRelationID, (((struct ObjectNode *)n)->data));
 }
    }
    lsShowAllConnections(areaID, node, perc);
}

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

variable_types:
perc
unsigned char


tcInsideOfHouse

decompiled_code:
__int64 __fastcall tcInsideOfHouse(unsigned int a1, unsigned int a2, unsigned __int8 a3)
{
unsigned __int8 v3; // bl
__int64 v4; // rbp
__int64 v5; // r14
_QWORD *v6; // r15
__int64 v7; // r12
unsigned int v8; // ebx
char v9; // al
__int64 v10; // rbx
__int64 v11; // rbp
char v12; // bl
__int64 v13; // rax
unsigned int v15; // [rsp+4h] [rbp-344h]
char v17[256]; // [rsp+10h] [rbp-338h] BYREF
char src[256]; // [rsp+110h] [rbp-238h] BYREF
char s[312]; // [rsp+210h] [rbp-138h] BYREF

v3 = a3;
v4 = dbGetObject(a2);
v5 = txtGoKey(0LL, "LookMenu");
txtGetNthString(2LL, "PROTECTED", 0LL, src);
txtGetNthString(2LL, "SUPPLIED", 0LL, v17);
inpTurnESC(0LL);
inpTurnFunctionKey(0LL);
SetObjectListAttr(4LL, 9913LL);
AskAll(v4, ConsistOfRelationID, &BuildObjectList);
v6 = (_QWORD *)ObjectListPrivate;
v15 = (unsigned int)GetNrOfNodes(ObjectListPrivate) * v3 / 0xFF;
v7 = lsGetSuccObject(*v6);
CurrAreaId = a2;
v8 = 0;
if ( (unsigned int)GetNodeNrByAddr(v6, v7) <= v15 )
{
while ( 1 )
{
v11 = *(_QWORD *)(v7 + 40);
dbGetObjectName(*(unsigned int *)(v11 + 20), s);
if ( *(_BYTE *)(v11 + 12) )
{
*(_WORD *)&s[strlen(s)] = 40;
v9 = *(_BYTE *)(v11 + 12);
if ( (v9 & 1) != 0 )
{
strcat(s, src);
if ( (*(_BYTE *)(v11 + 12) & 2) != 0 )
{
strcat(s, ", ");
strcat(s, v17);
}
}
else if ( (v9 & 2) != 0 )
{
strcat(s, v17);
}
*(_WORD *)&s[strlen(s)] = 41;
}
ShowMenuBackground();
PrintStatus(s);
CurrLSO = v11;
SetMenuTimeOutFunc(FadeInsideObject);
inpTurnFunctionKey(0LL);
inpTurnESC(0LL);
v12 = Menu(v5, 31LL, v8, 0LL, 10LL);
inpTurnESC(1LL);
inpTurnFunctionKey(1LL);
lsFadeRasterObject(a2, v11, 1LL);
switch ( v12 )
{
case 0:
v10 = lsGetSuccObject(v7);
if ( (unsigned int)GetNodeNrByAddr(v6, v10) < v15 - 1 )
v7 = v10;
v8 = 0;
goto LABEL_12;
case 1:
v7 = lsGetPredObject(v7);
v8 = 1;
goto LABEL_12;
case 2:
tcShowObjectData(a2, v7, a3);
v8 = 2;
goto LABEL_12;
case 3:
SetObjectListAttr(0LL, 509991LL);
v13 = dbGetObject(a1);
AskAll(v13, 500003LL, &BuildObjectList);
if ( *(_QWORD *)*ObjectList )
{
gfxSetPens(l_gc, 4LL, 255LL, 255LL);
grdDraw(l_gc, a1, a2);
}
else
{
Say(2LL, 0LL, 7LL, "NO_GUARD");
}
v8 = 3;
goto LABEL_12;
case 4:
lsFadeRasterObject(a2, *(_QWORD *)(v7 + 40), 1LL);
goto LABEL_22;
default:
v8 = 0;
LABEL_12:
lsFadeRasterObject(a2, *(_QWORD *)(v7 + 40), 1LL);
break;
}
}
}
SetBubbleType(13LL);
Say(2LL, 0LL, 7LL, "CANT_LOOK");
LABEL_22:
RemoveList(v5);
RemoveList(v6);
return inpSetWaitTicks(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2, unsigned __int8 a3)
{
unsigned __int8 v3; // bl
__int64 v4; // rbp
__int64 v5; // r14
_QWORD *v6; // r15
__int64 v7; // r12
unsigned int v8; // ebx
char v9; // al
__int64 v10; // rbx
__int64 v11; // rbp
char v12; // bl
__int64 v13; // rax
unsigned int v15; // [rsp+4h] [rbp-344h]
char v17[256]; // [rsp+10h] [rbp-338h] BYREF
char src[256]; // [rsp+110h] [rbp-238h] BYREF
char s[312]; // [rsp+210h] [rbp-138h] BYREF

v3 = a3;
v4 = dbGetObject(a2);
v5 = txtGoKey(0LL, "LookMenu");
txtGetNthString(2LL, "PROTECTED", 0LL, src);
txtGetNthString(2LL, "SUPPLIED", 0LL, v17);
inpTurnESC(0LL);
inpTurnFunctionKey(0LL);
SetObjectListAttr(4LL, 9913LL);
AskAll(v4, ConsistOfRelationID, &BuildObjectList);
v6 = (_QWORD *)ObjectListPrivate;
v15 = (unsigned int)GetNrOfNodes(ObjectListPrivate) * v3 / 0xFF;
v7 = lsGetSuccObject(*v6);
CurrAreaId = a2;
v8 = 0;
if ( (unsigned int)GetNodeNrByAddr(v6, v7) <= v15 )
{
while ( 1 )
{
v11 = *(_QWORD *)(v7 + 40);
dbGetObjectName(*(unsigned int *)(v11 + 20), s);
if ( *(_BYTE *)(v11 + 12) )
{
*(_WORD *)&s[strlen(s)] = 40;
v9 = *(_BYTE *)(v11 + 12);
if ( (v9 & 1) != 0 )
{
strcat(s, src);
if ( (*(_BYTE *)(v11 + 12) & 2) != 0 )
{
strcat(s, ", ");
strcat(s, v17);
}
}
else if ( (v9 & 2) != 0 )
{
strcat(s, v17);
}
*(_WORD *)&s[strlen(s)] = 41;
}
ShowMenuBackground();
PrintStatus(s);
CurrLSO = v11;
SetMenuTimeOutFunc(FadeInsideObject);
inpTurnFunctionKey(0LL);
inpTurnESC(0LL);
v12 = Menu(v5, 31LL, v8, 0LL, 10LL);
inpTurnESC(1LL);
inpTurnFunctionKey(1LL);
lsFadeRasterObject(a2, v11, 1LL);
switch ( v12 )
{
case 0:
v10 = lsGetSuccObject(v7);
if ( (unsigned int)GetNodeNrByAddr(v6, v10) < v15 - 1 )
v7 = v10;
v8 = 0;
goto LABEL_12;
case 1:
v7 = lsGetPredObject(v7);
v8 = 1;
goto LABEL_12;
case 2:
func2(a2, v7, a3);
v8 = 2;
goto LABEL_12;
case 3:
SetObjectListAttr(0LL, 509991LL);
v13 = dbGetObject(a1);
AskAll(v13, 500003LL, &BuildObjectList);
if ( *(_QWORD *)*ObjectList )
{
gfxSetPens(l_gc, 4LL, 255LL, 255LL);
grdDraw(l_gc, a1, a2);
}
else
{
Say(2LL, 0LL, 7LL, "NO_GUARD");
}
v8 = 3;
goto LABEL_12;
case 4:
lsFadeRasterObject(a2, *(_QWORD *)(v7 + 40), 1LL);
goto LABEL_22;
default:
v8 = 0;
LABEL_12:
lsFadeRasterObject(a2, *(_QWORD *)(v7 + 40), 1LL);
break;
}
}
}
SetBubbleType(13LL);
Say(2LL, 0LL, 7LL, "CANT_LOOK");
LABEL_22:
RemoveList(v5);
RemoveList(v6);
return inpSetWaitTicks(0LL);
}

original_code:
void tcInsideOfHouse(U32 buildingID, U32 areaID, ubyte perc)
{
    LIST *objects;
    NODE *node, *n;
    U32 action = 0, count;
    char name[256];
    char alarm[256], power[256];
    LSObject lso;
    LSArea area = dbGetObject(areaID);
    LIST *menu = txtGoKey(0U, "LookMenu");
    (txtGetNthString(2U, "PROTECTED", 0, alarm));
    (txtGetNthString(2U, "SUPPLIED", 0, power));
    inpTurnESC(0);
    inpTurnFunctionKey(0);
    SetObjectListAttr((1 << 2), 9913L);
    AskAll(area, ConsistOfRelationID, BuildObjectList);
    objects = ObjectListPrivate;
    count = (GetNrOfNodes(objects) * perc) / 255;
    node = lsGetSuccObject((NODE *) ((((NODE *)((&((objects))->Head)))->Succ)));
    CurrAreaId = areaID;
    if ((GetNodeNrByAddr(objects, node)) > count) {
 SetBubbleType(13);
 Say(2U, 0, 7, "CANT_LOOK");
    } else {
 while (action != 4) {
     lso = (LSObject) (((struct ObjectNode *)node)->data);
     dbGetObjectName(lso->Type, name);
     if (lso->uch_Chained) {
  strcat(name, "(");
  if (lso->uch_Chained & 1) {
      strcat(name, alarm);
      if (lso->uch_Chained & 2) {
   strcat(name, ", ");
   strcat(name, power);
      }
  } else {
      if (lso->uch_Chained & 2)
   strcat(name, power);
  }
  strcat(name, ")");
     }
     ShowMenuBackground();
     PrintStatus(name);
     CurrLSO = lso;
     SetMenuTimeOutFunc(FadeInsideObject);
     inpTurnFunctionKey(0);
     inpTurnESC(0);
     action = Menu(menu, 31, (ubyte) action, 0, 10);
     inpTurnESC(1);
     inpTurnFunctionKey(1);
     lsFadeRasterObject(areaID, lso, 1);
     switch (action) {
     case 0:
  if ((GetNodeNrByAddr(objects, n = lsGetSuccObject(node))) <
      (count - 1))
      node = n;
  break;
     case 1:
  node = lsGetPredObject(node);
  break;
     case 2:
  tcShowObjectData(areaID, node, perc);
  break;
     case 3:
  { SetObjectListAttr ((0),509991L); AskAll (dbGetObject (buildingID), 500003, BuildObjectList); };
  if (!((!(((NODE *)(((((NODE *)((&(((ObjectList)))->Head)))->Succ))))->Succ)))) {
      gfxSetPens(l_gc, 4, ((ubyte)255), ((ubyte)255));
      grdDraw(l_gc, buildingID, areaID);
  } else
      Say(2U, 0, 7, "NO_GUARD");
  break;
     case 4:
  break;
     default:
  action = 0;
  break;
     }
     lso = (LSObject) (((struct ObjectNode *)node)->data);
     lsFadeRasterObject(areaID, lso, 1);
 }
    }
    RemoveList(menu);
    RemoveList(objects);
    inpSetWaitTicks(0);
}

canonical_original_code:
void tcInsideOfHouse(unsigned int buildingID, unsigned int areaID, unsigned char perc)
{
    struct List *objects;
    struct Node *node; struct Node *n;
    unsigned int action = 0; unsigned int count;
    char name[256];
    char alarm[256]; char power[256];
    struct _LSObject *lso;
    struct _LSArea *area = dbGetObject(areaID);
    struct List *menu = txtGoKey(0U, "LookMenu");
    (txtGetNthString(2U, "PROTECTED", 0, alarm));
    (txtGetNthString(2U, "SUPPLIED", 0, power));
    inpTurnESC(0);
    inpTurnFunctionKey(0);
    SetObjectListAttr((1 << 2), 9913L);
    AskAll(area, ConsistOfRelationID, BuildObjectList);
    objects = ObjectListPrivate;
    count = (GetNrOfNodes(objects) * perc) / 255;
    node = lsGetSuccObject((struct Node *) ((((struct Node *)((&((objects))->Head)))->Succ)));
    CurrAreaId = areaID;
    if ((GetNodeNrByAddr(objects, node)) > count) {
 SetBubbleType(13);
 Say(2U, 0, 7, "CANT_LOOK");
    } else {
 while (action != 4) {
     lso = (LSObject) (((struct ObjectNode *)node)->data);
     dbGetObjectName(lso->Type, name);
     if (lso->uch_Chained) {
  strcat(name, "(");
  if (lso->uch_Chained & 1) {
      strcat(name, alarm);
      if (lso->uch_Chained & 2) {
   strcat(name, ", ");
   strcat(name, power);
      }
  } else {
      if (lso->uch_Chained & 2)
   strcat(name, power);
  }
  strcat(name, ")");
     }
     ShowMenuBackground();
     PrintStatus(name);
     CurrLSO = lso;
     SetMenuTimeOutFunc(FadeInsideObject);
     inpTurnFunctionKey(0);
     inpTurnESC(0);
     action = Menu(menu, 31, (unsigned char) action, 0, 10);
     inpTurnESC(1);
     inpTurnFunctionKey(1);
     lsFadeRasterObject(areaID, lso, 1);
     switch (action) {
     case 0:
  if ((GetNodeNrByAddr(objects, n = lsGetSuccObject(node))) <
      (count - 1))
      node = n;
  break;
     case 1:
  node = lsGetPredObject(node);
  break;
     case 2:
  tcShowObjectData(areaID, node, perc);
  break;
     case 3:
  { SetObjectListAttr ((0),509991L); AskAll (dbGetObject (buildingID), 500003, BuildObjectList); };
  if (!((!(((struct Node *)(((((struct Node *)((&(((ObjectList)))->Head)))->Succ))))->Succ)))) {
      gfxSetPens(l_gc, 4, ((unsigned char)255), ((unsigned char)255));
      grdDraw(l_gc, buildingID, areaID);
  } else
      Say(2U, 0, 7, "NO_GUARD");
  break;
     case 4:
  break;
     default:
  action = 0;
  break;
     }
     lso = (LSObject) (((struct ObjectNode *)node)->data);
     lsFadeRasterObject(areaID, lso, 1);
 }
    }
    RemoveList(menu);
    RemoveList(objects);
    inpSetWaitTicks(0);
}

variable_types:
action
unsigned int

variable_types:
name
char [256]

variable_types:
alarm
char [256]

variable_types:
power
char [256]

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; } *

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; } *


strUpper

decompiled_code:
void __fastcall strUpper(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func0(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
static void strUpper(char *s)
{
    while (*s != '\0') {
        *s = toupper(*s);
        s++;
    }
}

variable_types:
s
char *


strLower

decompiled_code:
void __fastcall strLower(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func1(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_tolower_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
static void strLower(char *s)
{
    while (*s != '\0') {
        *s = tolower(*s);
        s++;
    }
}


dskSetRootPath

decompiled_code:
char *__fastcall dskSetRootPath(char *src)
{
return strcpy(RootPathName, src);
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
return strcpy(RootPathName, src);
}

original_code:
void dskSetRootPath(const char *newRootPath)
{
    strcpy(RootPathName, newRootPath);
}

canonical_original_code:
void dskSetRootPath(char *newRootPath)
{
    strcpy(RootPathName, newRootPath);
}

variable_types:
newRootPath
char *


dskGetRootPath

decompiled_code:
char *__fastcall dskGetRootPath(char *a1)
{
return strcpy(a1, RootPathName);
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
return strcpy(a1, RootPathName);
}

original_code:
char *dskGetRootPath(char *result)
{
    return strcpy(result, RootPathName);
}

variable_types:
result
char *

return_type: char *


dskBuildPathName

decompiled_code:
__int64 __fastcall dskBuildPathName(int a1, const char *a2, const char *a3, char *a4)
{
int v6; // ebx
__int64 result; // rax
int v8; // eax
struct stat v9; // [rsp+0h] [rbp-4B8h] BYREF
char src[512]; // [rsp+90h] [rbp-428h] BYREF
char dest[552]; // [rsp+290h] [rbp-228h] BYREF

v6 = 0;
do
{
v8 = v6++;
if ( v8 == 2 )
{
strLower(dest);
strLower(src);
}
else if ( v8 > 2 )
{
if ( v8 == 3 )
{
sprintf(a4, "%s/%s/%s", RootPathName, a2, a3);
DebugMsg(2LL, 5LL, "Path failure: %s", a4);
return 0LL;
}
}
else if ( v8 )
{
if ( v8 == 1 )
{
strUpper(dest);
strUpper(src);
}
}
else
{
strcpy(dest, a2);
strcpy(src, a3);
}
if ( a1 )
sprintf(a4, "%s/%s", RootPathName, dest);
else
sprintf(a4, "%s/%s/%s", RootPathName, dest, src);
}
while ( stat(a4, &v9) == -1 );
result = 1LL;
if ( a1 == 1 )
{
*(_WORD *)&a4[strlen(a4)] = 47;
strcat(a4, src);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, const char *a2, const char *a3, char *a4)
{
int v6; // ebx
__int64 result; // rax
int v8; // eax
struct stat v9; // [rsp+0h] [rbp-4B8h] BYREF
char src[512]; // [rsp+90h] [rbp-428h] BYREF
char dest[552]; // [rsp+290h] [rbp-228h] BYREF

v6 = 0;
do
{
v8 = v6++;
if ( v8 == 2 )
{
func1(dest);
func1(src);
}
else if ( v8 > 2 )
{
if ( v8 == 3 )
{
sprintf(a4, "%s/%s/%s", RootPathName, a2, a3);
DebugMsg(2LL, 5LL, "Path failure: %s", a4);
return 0LL;
}
}
else if ( v8 )
{
if ( v8 == 1 )
{
func0(dest);
func0(src);
}
}
else
{
strcpy(dest, a2);
strcpy(src, a3);
}
if ( a1 )
sprintf(a4, "%s/%s", RootPathName, dest);
else
sprintf(a4, "%s/%s/%s", RootPathName, dest, src);
}
while ( stat(a4, &v9) == -1 );
result = 1LL;
if ( a1 == 1 )
{
*(_WORD *)&a4[strlen(a4)] = 47;
strcat(a4, src);
result = 1LL;
}
return result;
}

original_code:
_Bool dskBuildPathName(DiskCheckE check,
        const char *Directory, const char *Filename, char *Result)
{
    char Dir [512];
    char File[512];
    struct stat status;
    int step = 0;
    do {
        switch (step++) {
        case 0:
            strcpy(Dir, Directory);
            strcpy(File, Filename);
            break;
        case 1:
            strUpper(Dir);
            strUpper(File);
            break;
        case 2:
            strLower(Dir);
            strLower(File);
            break;
        case 3:
            sprintf(Result, "%s" "/" "%s" "/" "%s",
                RootPathName, Directory, Filename);
            DebugMsg(ERR_DEBUG, ERROR_MODULE_DISK,
                "Path failure: %s", Result);
            return 0;
        }
        if (check == DISK_CHECK_FILE) {
            sprintf(Result, "%s" "/" "%s" "/" "%s",
                RootPathName, Dir, File);
         } else {
            sprintf(Result, "%s" "/" "%s", RootPathName, Dir);
         }
    } while (stat(Result, &status) == -1);
    if (check == DISK_CHECK_DIR) {
        strcat(Result, "/");
        strcat(Result, File);
    }
    return 1;
}

canonical_original_code:
_Bool dskBuildPathName(enum DiskCheckE check, char *Directory, char *Filename, char *Result)
{
    char Dir[512];
    char File[512];
    struct stat status;
    int step = 0;
    do {
        switch (step++) {
        case 0:
            strcpy(Dir, Directory);
            strcpy(File, Filename);
            break;
        case 1:
            strUpper(Dir);
            strUpper(File);
            break;
        case 2:
            strLower(Dir);
            strLower(File);
            break;
        case 3:
            sprintf(Result, "%s" "/" "%s" "/" "%s",
                RootPathName, Directory, Filename);
            DebugMsg(ERR_DEBUG, ERROR_MODULE_DISK,
                "Path failure: %s", Result);
            return 0;
        }
        if (check == DISK_CHECK_FILE) {
            sprintf(Result, "%s" "/" "%s" "/" "%s",
                RootPathName, Dir, File);
         } else {
            sprintf(Result, "%s" "/" "%s", RootPathName, Dir);
         }
    } while (stat(Result, &status) == -1);
    if (check == DISK_CHECK_DIR) {
        strcat(Result, "/");
        strcat(Result, File);
    }
    return 1;
}

variable_types: enum DiskCheckE { DISK_CHECK_FILE=0, DISK_CHECK_DIR=1 }

variable_types:
Directory
char *

variable_types:
Filename
char *

variable_types:
Result
char *

variable_types:
Dir
char [512]

variable_types:
File
char [512]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

variable_types: step int


dskFileLength

decompiled_code:
__off_t __fastcall dskFileLength(const char *a1)
{
bool v1; // zf
__off_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) == -1;
result = 0LL;
if ( !v1 )
result = v3.st_size;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func5(const char *a1)
{
bool v1; // zf
__off_t result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) == -1;
result = 0LL;
if ( !v1 )
result = v3.st_size;
return result;
}

original_code:
size_t dskFileLength(const char *Pathname)
{
    struct stat status;
    if (stat(Pathname, &status) == -1) {
        return 0;
    } else {
        return status.st_size;
    }
}

canonical_original_code:
unsigned long dskFileLength(char *Pathname)
{
    struct stat status;
    if (stat(Pathname, &status) == -1) {
        return 0;
    } else {
        return status.st_size;
    }
}

variable_types:
Pathname
char *

return_type: unsigned long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


stricmp

decompiled_code:
__int64 __fastcall stricmp(char *a1, char *a2)
{
char v4; // bl
char v5; // bp
const __int32_t **v6; // rax
__int32_t v7; // edi
__int32_t v8; // er9

while ( 1 )
{
v4 = *a1;
if ( !*a1 )
return (unsigned int)-(*a2 != 0);
v5 = *a2;
if ( !*a2 )
return *a2 == 0;
v6 = _ctype_toupper_loc();
++a1;
v7 = (*v6)[v4];
++a2;
v8 = (*v6)[v5];
if ( v8 > v7 )
break;
if ( v8 < v7 )
return 1LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func24(char *a1, char *a2)
{
char v4; // bl
char v5; // bp
const __int32_t **v6; // rax
__int32_t v7; // edi
__int32_t v8; // er9

while ( 1 )
{
v4 = *a1;
if ( !*a1 )
return (unsigned int)-(*a2 != 0);
v5 = *a2;
if ( !*a2 )
return *a2 == 0;
v6 = _ctype_toupper_loc();
++a1;
v7 = (*v6)[v4];
++a2;
v8 = (*v6)[v5];
if ( v8 > v7 )
break;
if ( v8 < v7 )
return 1LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int stricmp(const char *s1, const char *s2)
{
    while (*s1 && *s2) {
        int a, b;
        a = toupper(*s1++);
        b = toupper(*s2++);
        if (a < b) {
            return -1;
        }
        if (a > b) {
            return +1;
        }
    }
    if (*s1 == '\0' && *s2 != '\0')
        return -1;
    if (*s1 != '\0' && *s2 == '\0')
        return +1;
    return 0;
}

variable_types: a int

variable_types: b int

return_type: int


strnicmp

original_code:
int strnicmp(const char *s1, const char *s2, size_t n)
{
    while (*s1 && *s2 && n--) {
        int a, b;
        a = toupper(*s1++);
        b = toupper(*s2++);
        if (a < b) {
            return -1;
        }
        if (a > b) {
            return +1;
        }
    }
    if (*s1 == '\0' && *s2 != '\0')
        return -1;
    if (*s1 != '\0' && *s2 == '\0')
        return +1;
    return 0;
}

canonical_original_code:
int strnicmp(char *s1, char *s2, unsigned long n)
{
    while (*s1 && *s2 && n--) {
        int a; int b;
        a = toupper(*s1++);
        b = toupper(*s2++);
        if (a < b) {
            return -1;
        }
        if (a > b) {
            return +1;
        }
    }
    if (*s1 == '\0' && *s2 != '\0')
        return -1;
    if (*s1 != '\0' && *s2 == '\0')
        return +1;
    return 0;
}

variable_types:
n
unsigned long


tcShowPriceOfTool

decompiled_code:
char *__fastcall tcShowPriceOfTool(__int64 a1, __int64 a2, __int64 a3)
{
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

txtGetNthString(2LL, "PRICE_AND_MONEY", 0LL, v5);
sprintf(line_1, v5, *(unsigned int *)(a3 + 4));
return line_1;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

txtGetNthString(2LL, "PRICE_AND_MONEY", 0LL, v5);
sprintf(line_1, v5, *(unsigned int *)(a3 + 4));
return line_1;
}

original_code:
char *tcShowPriceOfTool(U32 nr, U32 type, void *data)
{
    static char line[256];
    char line1[256];
    Tool tool = (Tool) data;
    (txtGetNthString(2U, "PRICE_AND_MONEY", 0, line1));
    sprintf(line, line1, tool->Value);
    return line;
}

canonical_original_code:
char *tcShowPriceOfTool(unsigned int nr, unsigned int type, void *data)
{
    static char line[256];
    char line1[256];
    struct _Tool *tool = (Tool) data;
    (txtGetNthString(2U, "PRICE_AND_MONEY", 0, line1));
    sprintf(line, line1, tool->Value);
    return line;
}

variable_types:
nr
unsigned int

variable_types:
type
unsigned int

variable_types:
data
void *

variable_types:
line
char [256]

variable_types: struct _Tool { unsigned short PictID; unsigned int Value; unsigned char Danger; unsigned char Volume; unsigned char Effect; } *


tcBuyTool

decompiled_code:
__int64 __fastcall tcBuyTool(unsigned __int8 a1)
{
unsigned __int16 *v1; // r15
__int64 v2; // rax
__int64 v3; // r12
unsigned int v4; // eax
unsigned __int8 v5; // bl
__int64 v7; // r13
unsigned int v8; // er14
__int64 v9; // rbp
__int64 v10; // rax
__int64 v11; // r13
__int64 v12; // rax
unsigned __int8 v13; // [rsp+Fh] [rbp-139h]
char v14[312]; // [rsp+10h] [rbp-138h] BYREF

v1 = (unsigned __int16 *)dbGetObject(9824LL);
ObjectListSuccString = tcShowPriceOfTool;
ObjectListWidth = 48;
SetObjectListAttr(55LL, 9906LL);
v2 = dbGetObject(9824LL);
AskAll(v2, 4LL, &BuildObjectList);
v3 = ObjectListPrivate;
ObjectListSuccString = 0LL;
ObjectListWidth = 0;
txtGetNthString(2LL, "THANKS", 0LL, v14);
ExpandObjectList(v3, v14);
SetBubbleType(13LL);
v4 = GetNrOfNodes(v3) - 1;
if ( v4 > a1 )
LOBYTE(v4) = a1;
v5 = v4;
if ( (_BYTE)v4 == 0xFF )
{
v13 = -1;
}
else
{
do
{
SetPictID(7LL);
v13 = v5;
v5 = Bubble(v3, v5, 0LL, 0LL);
if ( !(unsigned __int8)ChoiceOk(v5, 255LL, v3) )
break;
v7 = *(unsigned int *)(GetNthNode(v3, v5) + 32);
v8 = *(_DWORD *)(dbGetObject(v7) + 4);
v9 = dbGetObject((unsigned int)v7);
v10 = dbGetObject(9801LL);
if ( (unsigned int)AskP(v10, 4LL, v9, 0xFFFFFFFFLL, 0LL) )
{
Say(2LL, 0LL, *v1, "AUSVERKAUFT");
}
else if ( (unsigned __int8)tcSpendMoney(v8, 0LL) )
{
v11 = dbGetObject((unsigned int)v7);
v12 = dbGetObject(9801LL);
SetP(v12, 4LL, v11, 0xFFFFFFFFLL);
Say(2LL, 0LL, *v1, "GOOD TOOL");
}
}
while ( v5 != 0xFF );
}
RemoveList(v3);
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
unsigned __int16 *v1; // r15
__int64 v2; // rax
__int64 v3; // r12
unsigned int v4; // eax
unsigned __int8 v5; // bl
__int64 v7; // r13
unsigned int v8; // er14
__int64 v9; // rbp
__int64 v10; // rax
__int64 v11; // r13
__int64 v12; // rax
unsigned __int8 v13; // [rsp+Fh] [rbp-139h]
char v14[312]; // [rsp+10h] [rbp-138h] BYREF

v1 = (unsigned __int16 *)dbGetObject(9824LL);
ObjectListSuccString = tcShowPriceOfTool;
ObjectListWidth = 48;
SetObjectListAttr(55LL, 9906LL);
v2 = dbGetObject(9824LL);
AskAll(v2, 4LL, &BuildObjectList);
v3 = ObjectListPrivate;
ObjectListSuccString = 0LL;
ObjectListWidth = 0;
txtGetNthString(2LL, "THANKS", 0LL, v14);
ExpandObjectList(v3, v14);
SetBubbleType(13LL);
v4 = GetNrOfNodes(v3) - 1;
if ( v4 > a1 )
LOBYTE(v4) = a1;
v5 = v4;
if ( (_BYTE)v4 == 0xFF )
{
v13 = -1;
}
else
{
do
{
SetPictID(7LL);
v13 = v5;
v5 = Bubble(v3, v5, 0LL, 0LL);
if ( !(unsigned __int8)ChoiceOk(v5, 255LL, v3) )
break;
v7 = *(unsigned int *)(GetNthNode(v3, v5) + 32);
v8 = *(_DWORD *)(dbGetObject(v7) + 4);
v9 = dbGetObject((unsigned int)v7);
v10 = dbGetObject(9801LL);
if ( (unsigned int)AskP(v10, 4LL, v9, 0xFFFFFFFFLL, 0LL) )
{
Say(2LL, 0LL, *v1, "AUSVERKAUFT");
}
else if ( (unsigned __int8)tcSpendMoney(v8, 0LL) )
{
v11 = dbGetObject((unsigned int)v7);
v12 = dbGetObject(9801LL);
SetP(v12, 4LL, v11, 0xFFFFFFFFLL);
Say(2LL, 0LL, *v1, "GOOD TOOL");
}
}
while ( v5 != 0xFF );
}
RemoveList(v3);
return v13;
}

original_code:
ubyte tcBuyTool(ubyte choice)
{
    LIST *tools;
    NODE *node;
    U32 toolID, price, count;
    Person mary = dbGetObject(9824U);
    Tool tool;
    U8 oldChoice = ((U8)-1);
    char exp[256];
    ObjectListSuccString = tcShowPriceOfTool;
    ObjectListWidth = 48;
    { SetObjectListAttr ((1 << 5) | (1 << 2) | (1) | (1 << 1) | (1 << 4),9906L); AskAll (dbGetObject (9824U), 4, BuildObjectList); };
    tools = ObjectListPrivate;
    ObjectListSuccString = ((void *)0);
    ObjectListWidth = 0;
    (txtGetNthString(2U, "THANKS", 0, exp));
    ExpandObjectList(tools, exp);
    SetBubbleType(13);
    count = GetNrOfNodes(tools) - 1;
    choice = ((choice) < (count) ? (choice) : (count));
    while (choice != ((U8)-1)) {
 SetPictID(7);
 oldChoice = choice;
 if (ChoiceOk(choice = Bubble(tools, choice, 0L, 0L), ((U8)-1), tools)) {
     node = GetNthNode(tools, (U32) choice);
     toolID = (((struct ObjectNode *)node)->nr);
     tool = (Tool) dbGetObject(toolID);
     price = (tool->Value);
     if (AskP (dbGetObject (9801U), 4, dbGetObject (toolID), (4294967295U), ((U8)0)))
  Say(2U, 0, mary->PictID, "AUSVERKAUFT");
     else {
  if (tcSpendMoney(price, 0)) {
      SetP (dbGetObject (9801U), 4, dbGetObject (toolID), (4294967295U));
      Say(2U, 0, mary->PictID, "GOOD TOOL");
  }
     }
 } else
     choice = ((U8)-1);
    }
    RemoveList(tools);
    return (oldChoice);
}

canonical_original_code:
unsigned char tcBuyTool(unsigned char choice)
{
    struct List *tools;
    struct Node *node;
    unsigned int toolID; unsigned int price; unsigned int count;
    struct _Person *mary = dbGetObject(9824U);
    struct _Tool *tool;
    unsigned char oldChoice = ((U8)-1);
    char exp[256];
    ObjectListSuccString = tcShowPriceOfTool;
    ObjectListWidth = 48;
    { SetObjectListAttr ((1 << 5) | (1 << 2) | (1) | (1 << 1) | (1 << 4),9906L); AskAll (dbGetObject (9824U), 4, BuildObjectList); };
    tools = ObjectListPrivate;
    ObjectListSuccString = ((void *)0);
    ObjectListWidth = 0;
    (txtGetNthString(2U, "THANKS", 0, exp));
    ExpandObjectList(tools, exp);
    SetBubbleType(13);
    count = GetNrOfNodes(tools) - 1;
    choice = ((choice) < (count) ? (choice) : (count));
    while (choice != ((U8)-1)) {
 SetPictID(7);
 oldChoice = choice;
 if (ChoiceOk(choice = Bubble(tools, choice, 0L, 0L), ((U8)-1), tools)) {
     node = GetNthNode(tools, (unsigned int) choice);
     toolID = (((struct ObjectNode *)node)->nr);
     tool = (struct _Tool *) dbGetObject(toolID);
     price = (tool->Value);
     if (AskP (dbGetObject (9801U), 4, dbGetObject (toolID), (4294967295U), ((unsigned char)0)))
  Say(2U, 0, mary->PictID, "AUSVERKAUFT");
     else {
  if (tcSpendMoney(price, 0)) {
      SetP (dbGetObject (9801U), 4, dbGetObject (toolID), (4294967295U));
      Say(2U, 0, mary->PictID, "GOOD TOOL");
  }
     }
 } else
     choice = ((U8)-1);
    }
    RemoveList(tools);
    return (oldChoice);
}

variable_types:
choice
unsigned char

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; } *

variable_types:
toolID
unsigned int

variable_types:
price
unsigned int

variable_types:
count
unsigned int

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:
oldChoice
unsigned char

variable_types:
exp
char [256]

user_defined_types: struct _Tool { unsigned short PictID; unsigned int Value; unsigned char Danger; unsigned char Volume; unsigned char Effect; }


tcDescTool

decompiled_code:
__int64 __fastcall tcDescTool(unsigned int a1)
{
unsigned int v1; // ebx
unsigned __int16 *v2; // r13
__int64 v3; // rax
__int64 v4; // r12
unsigned int v5; // er14
__int64 v6; // rax
__int64 v7; // rbp
_BYTE v9[256]; // [rsp+0h] [rbp-228h] BYREF
char v10[296]; // [rsp+100h] [rbp-128h] BYREF

v1 = a1;
v2 = (unsigned __int16 *)dbGetObject(9824LL);
ObjectListSuccString = tcShowPriceOfTool;
ObjectListWidth = 48;
SetObjectListAttr(55LL, 9906LL);
v3 = dbGetObject(9824LL);
AskAll(v3, 4LL, &BuildObjectList);
v4 = ObjectListPrivate;
ObjectListWidth = 0;
ObjectListSuccString = 0LL;
txtGetNthString(2LL, "THANKS", 0LL, v9);
ExpandObjectList(v4, v9);
if ( (unsigned __int8)a1 >= (unsigned int)GetNrOfNodes(v4) - 1 )
v1 = GetNrOfNodes(v4) - 1;
if ( (_BYTE)v1 == 0xFF )
{
v5 = v1;
}
else
{
do
{
SetPictID(7LL);
v5 = v1;
v1 = Bubble(v4, (unsigned __int8)v1, 0LL, 0LL);
if ( !(unsigned __int8)ChoiceOk((unsigned __int8)v1, 255LL, v4) )
break;
v6 = GetNthNode(v4, (unsigned __int8)v1);
dbGetObjectName(*(unsigned int *)(v6 + 32), v10);
v7 = txtGoKey(12LL, v10);
SetPictID(*v2);
Bubble(v7, 0LL, 0LL, 0LL);
RemoveList(v7);
}
while ( (_BYTE)v1 != 0xFF );
}
RemoveList(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
unsigned int v1; // ebx
unsigned __int16 *v2; // r13
__int64 v3; // rax
__int64 v4; // r12
unsigned int v5; // er14
__int64 v6; // rax
__int64 v7; // rbp
_BYTE v9[256]; // [rsp+0h] [rbp-228h] BYREF
char v10[296]; // [rsp+100h] [rbp-128h] BYREF

v1 = a1;
v2 = (unsigned __int16 *)dbGetObject(9824LL);
ObjectListSuccString = tcShowPriceOfTool;
ObjectListWidth = 48;
SetObjectListAttr(55LL, 9906LL);
v3 = dbGetObject(9824LL);
AskAll(v3, 4LL, &BuildObjectList);
v4 = ObjectListPrivate;
ObjectListWidth = 0;
ObjectListSuccString = 0LL;
txtGetNthString(2LL, "THANKS", 0LL, v9);
ExpandObjectList(v4, v9);
if ( (unsigned __int8)a1 >= (unsigned int)GetNrOfNodes(v4) - 1 )
v1 = GetNrOfNodes(v4) - 1;
if ( (_BYTE)v1 == 0xFF )
{
v5 = v1;
}
else
{
do
{
SetPictID(7LL);
v5 = v1;
v1 = Bubble(v4, (unsigned __int8)v1, 0LL, 0LL);
if ( !(unsigned __int8)ChoiceOk((unsigned __int8)v1, 255LL, v4) )
break;
v6 = GetNthNode(v4, (unsigned __int8)v1);
dbGetObjectName(*(unsigned int *)(v6 + 32), v10);
v7 = txtGoKey(12LL, v10);
SetPictID(*v2);
Bubble(v7, 0LL, 0LL, 0LL);
RemoveList(v7);
}
while ( (_BYTE)v1 != 0xFF );
}
RemoveList(v4);
return v5;
}

original_code:
ubyte tcDescTool(ubyte choice)
{
    LIST *tools, *desc;
    char line[256], exp[256];
    U8 oldChoice = ((U8)-1);
    Person mary = (Person) dbGetObject(9824U);
    ObjectListSuccString = tcShowPriceOfTool;
    ObjectListWidth = 48;
    { SetObjectListAttr ((1 << 5) | (1 << 2) | (1) | (1 << 1) | (1 << 4),9906L); AskAll (dbGetObject (9824U), 4, BuildObjectList); };
    tools = ObjectListPrivate;
    ObjectListWidth = 0;
    ObjectListSuccString = ((void *)0);
    (txtGetNthString(2U, "THANKS", 0, exp));
    ExpandObjectList(tools, exp);
    choice = ((choice) < ((GetNrOfNodes(tools) - 1)) ? (choice) : ((GetNrOfNodes(tools) - 1)));
    while (choice != ((U8)-1)) {
 SetPictID(7);
 oldChoice = choice;
 if (ChoiceOk(choice = Bubble(tools, choice, 0L, 0L), ((U8)-1), tools)) {
     dbGetObjectName((((struct ObjectNode *)GetNthNode(tools, (U32) choice))->nr), line);
     desc = txtGoKey(12U, line);
     SetPictID(mary->PictID);
     Bubble(desc, 0, 0L, 0L);
     RemoveList(desc);
 } else
     choice = ((U8)-1);
    }
    RemoveList(tools);
    return (oldChoice);
}

canonical_original_code:
unsigned char tcDescTool(unsigned char choice)
{
    struct List *tools; struct List *desc;
    char line[256]; char exp[256];
    unsigned char oldChoice = ((U8)-1);
    struct _Person *mary = (Person) dbGetObject(9824U);
    ObjectListSuccString = tcShowPriceOfTool;
    ObjectListWidth = 48;
    { SetObjectListAttr ((1 << 5) | (1 << 2) | (1) | (1 << 1) | (1 << 4),9906L); AskAll (dbGetObject (9824U), 4, BuildObjectList); };
    tools = ObjectListPrivate;
    ObjectListWidth = 0;
    ObjectListSuccString = ((void *)0);
    (txtGetNthString(2U, "THANKS", 0, exp));
    ExpandObjectList(tools, exp);
    choice = ((choice) < ((GetNrOfNodes(tools) - 1)) ? (choice) : ((GetNrOfNodes(tools) - 1)));
    while (choice != ((U8)-1)) {
 SetPictID(7);
 oldChoice = choice;
 if (ChoiceOk(choice = Bubble(tools, choice, 0L, 0L), ((U8)-1), tools)) {
     dbGetObjectName((((struct ObjectNode *)GetNthNode(tools, (unsigned int) choice))->nr), line);
     desc = txtGoKey(12U, line);
     SetPictID(mary->PictID);
     Bubble(desc, 0, 0L, 0L);
     RemoveList(desc);
 } else
     choice = ((U8)-1);
    }
    RemoveList(tools);
    return (oldChoice);
}


tcShowTool

decompiled_code:
__int64 __fastcall tcShowTool(unsigned int a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rbp
unsigned int v4; // er12
__int64 v5; // rax
_BYTE v7[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = a1;
ObjectListSuccString = tcShowPriceOfTool;
ObjectListWidth = 48;
SetObjectListAttr(55LL, 9906LL);
v2 = dbGetObject(9824LL);
AskAll(v2, 4LL, &BuildObjectList);
v3 = ObjectListPrivate;
ObjectListSuccString = 0LL;
ObjectListWidth = 0;
txtGetNthString(2LL, "THANKS", 0LL, v7);
ExpandObjectList(v3, v7);
if ( (unsigned __int8)a1 >= (unsigned int)GetNrOfNodes(v3) - 1 )
v1 = GetNrOfNodes(v3) - 1;
if ( (_BYTE)v1 == 0xFF )
{
v4 = v1;
}
else
{
do
{
SetPictID(7LL);
v4 = v1;
v1 = Bubble(v3, (unsigned __int8)v1, 0LL, 0LL);
if ( !(unsigned __int8)ChoiceOk((unsigned __int8)v1, 255LL, v3) )
break;
v5 = GetNthNode(v3, (unsigned __int8)v1);
Present(*(unsigned int *)(v5 + 32), "Tool", &InitToolPresent);
}
while ( (_BYTE)v1 != 0xFF );
}
RemoveList(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
__int64 v3; // rbp
unsigned int v4; // er12
__int64 v5; // rax
_BYTE v7[280]; // [rsp+0h] [rbp-118h] BYREF

v1 = a1;
ObjectListSuccString = tcShowPriceOfTool;
ObjectListWidth = 48;
SetObjectListAttr(55LL, 9906LL);
v2 = dbGetObject(9824LL);
AskAll(v2, 4LL, &BuildObjectList);
v3 = ObjectListPrivate;
ObjectListSuccString = 0LL;
ObjectListWidth = 0;
txtGetNthString(2LL, "THANKS", 0LL, v7);
ExpandObjectList(v3, v7);
if ( (unsigned __int8)a1 >= (unsigned int)GetNrOfNodes(v3) - 1 )
v1 = GetNrOfNodes(v3) - 1;
if ( (_BYTE)v1 == 0xFF )
{
v4 = v1;
}
else
{
do
{
SetPictID(7LL);
v4 = v1;
v1 = Bubble(v3, (unsigned __int8)v1, 0LL, 0LL);
if ( !(unsigned __int8)ChoiceOk((unsigned __int8)v1, 255LL, v3) )
break;
v5 = GetNthNode(v3, (unsigned __int8)v1);
Present(*(unsigned int *)(v5 + 32), "Tool", &InitToolPresent);
}
while ( (_BYTE)v1 != 0xFF );
}
RemoveList(v3);
return v4;
}

original_code:
ubyte tcShowTool(ubyte choice)
{
    LIST *tools;
    NODE *node;
    U32 toolID;
    U8 oldChoice = ((U8)-1);
    char exp[256];
    ObjectListSuccString = tcShowPriceOfTool;
    ObjectListWidth = 48;
    { SetObjectListAttr ((1 << 5) | (1 << 2) | (1) | (1 << 1) | (1 << 4),9906L); AskAll (dbGetObject (9824U), 4, BuildObjectList); };
    tools = ObjectListPrivate;
    ObjectListSuccString = ((void *)0);
    ObjectListWidth = 0;
    (txtGetNthString(2U, "THANKS", 0, exp));
    ExpandObjectList(tools, exp);
    choice = ((choice) < ((GetNrOfNodes(tools) - 1)) ? (choice) : ((GetNrOfNodes(tools) - 1)));
    while (choice != ((U8)-1)) {
 SetPictID(7);
 oldChoice = choice;
 if (ChoiceOk(choice = Bubble(tools, choice, 0L, 0L), ((U8)-1), tools)) {
     node = GetNthNode(tools, (U32) choice);
     toolID = (((struct ObjectNode *)node)->nr);
     Present(toolID, "Tool", InitToolPresent);
 } else
     choice = ((U8)-1);
    }
    RemoveList(tools);
    return (oldChoice);
}

canonical_original_code:
unsigned char tcShowTool(unsigned char choice)
{
    struct List *tools;
    struct Node *node;
    unsigned int toolID;
    unsigned char oldChoice = ((U8)-1);
    char exp[256];
    ObjectListSuccString = tcShowPriceOfTool;
    ObjectListWidth = 48;
    { SetObjectListAttr ((1 << 5) | (1 << 2) | (1) | (1 << 1) | (1 << 4),9906L); AskAll (dbGetObject (9824U), 4, BuildObjectList); };
    tools = ObjectListPrivate;
    ObjectListSuccString = ((void *)0);
    ObjectListWidth = 0;
    (txtGetNthString(2U, "THANKS", 0, exp));
    ExpandObjectList(tools, exp);
    choice = ((choice) < ((GetNrOfNodes(tools) - 1)) ? (choice) : ((GetNrOfNodes(tools) - 1)));
    while (choice != ((U8)-1)) {
 SetPictID(7);
 oldChoice = choice;
 if (ChoiceOk(choice = Bubble(tools, choice, 0L, 0L), ((U8)-1), tools)) {
     node = GetNthNode(tools, (unsigned int) choice);
     toolID = (((struct ObjectNode *)node)->nr);
     Present(toolID, "Tool", InitToolPresent);
 } else
     choice = ((U8)-1);
    }
    RemoveList(tools);
    return (oldChoice);
}


tcSellTool

decompiled_code:
__int64 tcSellTool()
{
__int64 v0; // rax
_QWORD **v1; // rbx
__int64 v2; // r15
__int64 v3; // r12
unsigned int v4; // er13
unsigned int v5; // er14
__int64 v6; // r12
__int64 v7; // r12
unsigned __int8 v8; // r13
char v9; // al
__int64 v10; // rax
unsigned __int8 v11; // bp
__int64 v12; // rax
unsigned int v14; // er14
unsigned int v15; // eax
int v16; // er13
unsigned int v17; // eax
__int64 v18; // r14
__int64 v19; // rax
__int64 v20; // r15
__int64 v21; // rax
unsigned __int16 *v22; // [rsp+8h] [rbp-140h]
char v23[312]; // [rsp+10h] [rbp-138h] BYREF

v22 = (unsigned __int16 *)dbGetObject(9824LL);
SetObjectListAttr(7LL, 9906LL);
v0 = dbGetObject(9801LL);
AskAll(v0, 4LL, &BuildObjectList);
v1 = (_QWORD **)ObjectListPrivate;
dbRemObjectNode(ObjectListPrivate, 9501LL);
dbRemObjectNode(v1, 9525LL);
if ( !**v1 )
Say(2LL, 0LL, 7LL, "MATT_HAS_NO_TOOL");
while ( **v1 )
{
txtGetNthString(2LL, "NO_CHOICE", 0LL, v23);
ExpandObjectList(v1, v23);
SetPictID(7LL);
v11 = Bubble(v1, 0LL, 0LL, 0LL);
if ( !(unsigned __int8)ChoiceOk(v11, 255LL, v1) )
{
RemoveList(v1);
SetObjectListAttr(7LL, 9906LL);
v12 = dbGetObject(9801LL);
AskAll(v12, 4LL, &BuildObjectList);
v1 = (_QWORD **)ObjectListPrivate;
dbRemObjectNode(ObjectListPrivate, 9501LL);
dbRemObjectNode(v1, 9525LL);
return RemoveList(v1);
}
v2 = *(unsigned int *)(GetNthNode(v1, v11) + 32);
v3 = dbGetObject(v2);
v4 = *(_DWORD *)(v3 + 4);
v5 = 1;
if ( v4 - v4 / (unsigned int)CalcRandomNr(10LL, 20LL) > 1 )
{
v14 = *(_DWORD *)(v3 + 4);
v5 = v14 - v14 / (unsigned int)CalcRandomNr(10LL, 20LL);
}
v6 = txtGoKeyAndInsert(2LL, "ANGEBOT_WERKZ", v5);
SetPictID(*v22);
Bubble(v6, 0LL, 0LL, 0LL);
RemoveList(v6);
v7 = txtGoKey(2LL, "VERKAUF");
v8 = Bubble(v7, 0LL, 0LL, 0LL);
v9 = ChoiceOk(v8, 255LL, v7);
if ( !v8 && v9 )
{
v15 = getKey(1LL);
v16 = *(_DWORD *)dbGetObject(v15);
v17 = getKey(1LL);
*(_DWORD *)dbGetObject(v17) = v5 + v16;
v18 = dbGetObject((unsigned int)v2);
v19 = dbGetObject(9824LL);
SetP(v19, 4LL, v18, 0xFFFFFFFFLL);
v20 = dbGetObject((unsigned int)v2);
v21 = dbGetObject(9801LL);
UnSet(v21, 4LL, v20);
}
RemoveList(v7);
RemoveList(v1);
SetObjectListAttr(7LL, 9906LL);
v10 = dbGetObject(9801LL);
AskAll(v10, 4LL, &BuildObjectList);
v1 = (_QWORD **)ObjectListPrivate;
dbRemObjectNode(ObjectListPrivate, 9501LL);
dbRemObjectNode(v1, 9525LL);
if ( v11 == 0xFF )
return RemoveList(v1);
}
return RemoveList(v1);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
_QWORD **v1; // rbx
__int64 v2; // r15
__int64 v3; // r12
unsigned int v4; // er13
unsigned int v5; // er14
__int64 v6; // r12
__int64 v7; // r12
unsigned __int8 v8; // r13
char v9; // al
__int64 v10; // rax
unsigned __int8 v11; // bp
__int64 v12; // rax
unsigned int v14; // er14
unsigned int v15; // eax
int v16; // er13
unsigned int v17; // eax
__int64 v18; // r14
__int64 v19; // rax
__int64 v20; // r15
__int64 v21; // rax
unsigned __int16 *v22; // [rsp+8h] [rbp-140h]
char v23[312]; // [rsp+10h] [rbp-138h] BYREF

v22 = (unsigned __int16 *)dbGetObject(9824LL);
SetObjectListAttr(7LL, 9906LL);
v0 = dbGetObject(9801LL);
AskAll(v0, 4LL, &BuildObjectList);
v1 = (_QWORD **)ObjectListPrivate;
dbRemObjectNode(ObjectListPrivate, 9501LL);
dbRemObjectNode(v1, 9525LL);
if ( !**v1 )
Say(2LL, 0LL, 7LL, "MATT_HAS_NO_TOOL");
while ( **v1 )
{
txtGetNthString(2LL, "NO_CHOICE", 0LL, v23);
ExpandObjectList(v1, v23);
SetPictID(7LL);
v11 = Bubble(v1, 0LL, 0LL, 0LL);
if ( !(unsigned __int8)ChoiceOk(v11, 255LL, v1) )
{
RemoveList(v1);
SetObjectListAttr(7LL, 9906LL);
v12 = dbGetObject(9801LL);
AskAll(v12, 4LL, &BuildObjectList);
v1 = (_QWORD **)ObjectListPrivate;
dbRemObjectNode(ObjectListPrivate, 9501LL);
dbRemObjectNode(v1, 9525LL);
return RemoveList(v1);
}
v2 = *(unsigned int *)(GetNthNode(v1, v11) + 32);
v3 = dbGetObject(v2);
v4 = *(_DWORD *)(v3 + 4);
v5 = 1;
if ( v4 - v4 / (unsigned int)CalcRandomNr(10LL, 20LL) > 1 )
{
v14 = *(_DWORD *)(v3 + 4);
v5 = v14 - v14 / (unsigned int)CalcRandomNr(10LL, 20LL);
}
v6 = txtGoKeyAndInsert(2LL, "ANGEBOT_WERKZ", v5);
SetPictID(*v22);
Bubble(v6, 0LL, 0LL, 0LL);
RemoveList(v6);
v7 = txtGoKey(2LL, "VERKAUF");
v8 = Bubble(v7, 0LL, 0LL, 0LL);
v9 = ChoiceOk(v8, 255LL, v7);
if ( !v8 && v9 )
{
v15 = getKey(1LL);
v16 = *(_DWORD *)dbGetObject(v15);
v17 = getKey(1LL);
*(_DWORD *)dbGetObject(v17) = v5 + v16;
v18 = dbGetObject((unsigned int)v2);
v19 = dbGetObject(9824LL);
SetP(v19, 4LL, v18, 0xFFFFFFFFLL);
v20 = dbGetObject((unsigned int)v2);
v21 = dbGetObject(9801LL);
UnSet(v21, 4LL, v20);
}
RemoveList(v7);
RemoveList(v1);
SetObjectListAttr(7LL, 9906LL);
v10 = dbGetObject(9801LL);
AskAll(v10, 4LL, &BuildObjectList);
v1 = (_QWORD **)ObjectListPrivate;
dbRemObjectNode(ObjectListPrivate, 9501LL);
dbRemObjectNode(v1, 9525LL);
if ( v11 == 0xFF )
return RemoveList(v1);
}
return RemoveList(v1);
}

original_code:
void tcSellTool()
{
    LIST *bubble, *tools;
    NODE *node;
    U32 toolID, price;
    ubyte choice = 0;
    Tool tool;
    Person mary;
    mary = (Person) dbGetObject(9824U);
    { SetObjectListAttr ((1 << 2) | (1) | (1 << 1),9906L); AskAll (dbGetObject (9801U), 4, BuildObjectList); };
    tools = ObjectListPrivate;
    dbRemObjectNode(tools, 9501U);
    dbRemObjectNode(tools, 9525U);
    if ((!(((NODE *)(((((NODE *)((&(((tools)))->Head)))->Succ))))->Succ)))
 Say(2U, 0, 7, "MATT_HAS_NO_TOOL");
    while ((choice != ((U8)-1)) && (!(!(((NODE *)(((((NODE *)((&(((tools)))->Head)))->Succ))))->Succ)))) {
 char exp[256];
 (txtGetNthString(2U, "NO_CHOICE", 0, exp));
 ExpandObjectList(tools, exp);
 SetPictID(7);
 if (ChoiceOk(choice = Bubble(tools, 0, ((void *)0), 0L), ((U8)-1), tools)) {
     ubyte choice2 = 0;
     node = GetNthNode(tools, (U32) choice);
     toolID = (((struct ObjectNode *)node)->nr);
     tool = (Tool) dbGetObject(toolID);
     price = (((((tool->Value) - ((tool->Value) / (CalcRandomNr(10,20))))) > (1) ? (((tool->Value) - ((tool->Value) / (CalcRandomNr(10,20))))) : (1)));
     bubble = txtGoKeyAndInsert(2U, "ANGEBOT_WERKZ", price);
     SetPictID(mary->PictID);
     Bubble(bubble, 0, 0L, 0L);
     RemoveList(bubble);
     bubble = txtGoKey(2U, "VERKAUF");
     if (ChoiceOk
  (choice2 = Bubble(bubble, choice2, 0L, 0L), ((U8)-1), bubble)) {
  if (choice2 == 0) {
      (((Player)dbGetObject(getKey(_Player_Player_1)))->Money = ((((Player)dbGetObject(getKey(_Player_Player_1)))->Money) + price));
      SetP (dbGetObject (9824U), 4, dbGetObject (toolID), (4294967295U));
      UnSet (dbGetObject (9801U), 4, dbGetObject (toolID));
  }
     }
     RemoveList(bubble);
 } else
     choice = ((U8)-1);
 RemoveList(tools);
 { SetObjectListAttr ((1 << 2) | (1) | (1 << 1),9906L); AskAll (dbGetObject (9801U), 4, BuildObjectList); };
 tools = ObjectListPrivate;
 dbRemObjectNode(tools, 9501U);
 dbRemObjectNode(tools, 9525U);
    }
    RemoveList(tools);
}

canonical_original_code:
void tcSellTool()
{
    struct List *bubble; struct List *tools;
    struct Node *node;
    unsigned int toolID; unsigned int price;
    unsigned char choice = 0;
    struct _Tool *tool;
    struct _Person *mary;
    mary = (struct _Person *) dbGetObject(9824U);
    { SetObjectListAttr ((1 << 2) | (1) | (1 << 1),9906L); AskAll (dbGetObject (9801U), 4, BuildObjectList); };
    tools = ObjectListPrivate;
    dbRemObjectNode(tools, 9501U);
    dbRemObjectNode(tools, 9525U);
    if ((!(((struct Node *)(((((struct Node *)((&(((tools)))->Head)))->Succ))))->Succ)))
 Say(2U, 0, 7, "MATT_HAS_NO_TOOL");
    while ((choice != ((U8)-1)) && (!(!(((struct Node *)(((((struct Node *)((&(((tools)))->Head)))->Succ))))->Succ)))) {
 char exp[256];
 (txtGetNthString(2U, "NO_CHOICE", 0, exp));
 ExpandObjectList(tools, exp);
 SetPictID(7);
 if (ChoiceOk(choice = Bubble(tools, 0, ((void *)0), 0L), ((U8)-1), tools)) {
     unsigned char choice2 = 0;
     node = GetNthNode(tools, (unsigned int) choice);
     toolID = (((struct ObjectNode *)node)->nr);
     tool = (struct _Tool *) dbGetObject(toolID);
     price = (((((tool->Value) - ((tool->Value) / (CalcRandomNr(10,20))))) > (1) ? (((tool->Value) - ((tool->Value) / (CalcRandomNr(10,20))))) : (1)));
     bubble = txtGoKeyAndInsert(2U, "ANGEBOT_WERKZ", price);
     SetPictID(mary->PictID);
     Bubble(bubble, 0, 0L, 0L);
     RemoveList(bubble);
     bubble = txtGoKey(2U, "VERKAUF");
     if (ChoiceOk
  (choice2 = Bubble(bubble, choice2, 0L, 0L), ((U8)-1), bubble)) {
  if (choice2 == 0) {
      (((struct _Player *)dbGetObject(getKey(_Player_Player_1)))->Money = ((((struct _Player *)dbGetObject(getKey(_Player_Player_1)))->Money) + price));
      SetP (dbGetObject (9824U), 4, dbGetObject (toolID), (4294967295U));
      UnSet (dbGetObject (9801U), 4, dbGetObject (toolID));
  }
     }
     RemoveList(bubble);
 } else
     choice = ((U8)-1);
 RemoveList(tools);
 { SetObjectListAttr ((1 << 2) | (1) | (1 << 1),9906L); AskAll (dbGetObject (9801U), 4, BuildObjectList); };
 tools = ObjectListPrivate;
 dbRemObjectNode(tools, 9501U);
 dbRemObjectNode(tools, 9525U);
    }
    RemoveList(tools);
}

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; }


tcToolsShop

decompiled_code:
__int64 tcToolsShop()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned __int8 v2; // bl
__int64 v3; // rbp
__int64 v4; // rax
__int64 result; // rax

v0 = dbGetObject(9824LL);
v1 = dbGetObject(9801LL);
if ( !(unsigned int)AskP(v1, 5LL, v0, 0xFFFFFFFFLL, 0LL) )
{
v3 = dbGetObject(9824LL);
v4 = dbGetObject(9801LL);
SetP(v4, 5LL, v3, 0xFFFFFFFFLL);
}
v2 = 0;
do
{
while ( 1 )
{
result = Say(2LL, v2, 7LL, "Tools Shop");
v2 = result;
if ( (_BYTE)result == 2 )
{
result = tcShowTool((unsigned __int8)choice1_0);
choice1_0 = result;
goto LABEL_7;
}
if ( (unsigned __int8)result <= 2u )
{
if ( (_BYTE)result )
{
result = tcSellTool();
v2 = 1;
}
else
{
result = tcBuyTool(choice1_0);
choice1_0 = result;
}
goto LABEL_7;
}
if ( (_BYTE)result != 3 )
break;
result = tcDescTool((unsigned __int8)choice1_0);
choice1_0 = result;
LABEL_7:
if ( choice1_0 == -1 )
goto LABEL_15;
}
if ( choice1_0 != -1 )
return result;
v2 = 4;
LABEL_15:
choice1_0 = 0;
}
while ( v2 != 4 );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned __int8 v2; // bl
__int64 v3; // rbp
__int64 v4; // rax
__int64 result; // rax

v0 = dbGetObject(9824LL);
v1 = dbGetObject(9801LL);
if ( !(unsigned int)AskP(v1, 5LL, v0, 0xFFFFFFFFLL, 0LL) )
{
v3 = dbGetObject(9824LL);
v4 = dbGetObject(9801LL);
SetP(v4, 5LL, v3, 0xFFFFFFFFLL);
}
v2 = 0;
do
{
while ( 1 )
{
result = Say(2LL, v2, 7LL, "Tools Shop");
v2 = result;
if ( (_BYTE)result == 2 )
{
result = func3((unsigned __int8)choice1_0);
choice1_0 = result;
goto LABEL_7;
}
if ( (unsigned __int8)result <= 2u )
{
if ( (_BYTE)result )
{
result = func4();
v2 = 1;
}
else
{
result = func1(choice1_0);
choice1_0 = result;
}
goto LABEL_7;
}
if ( (_BYTE)result != 3 )
break;
result = func2((unsigned __int8)choice1_0);
choice1_0 = result;
LABEL_7:
if ( choice1_0 == -1 )
goto LABEL_15;
}
if ( choice1_0 != -1 )
return result;
v2 = 4;
LABEL_15:
choice1_0 = 0;
}
while ( v2 != 4 );
return result;
}

original_code:
void tcToolsShop(void)
{
    ubyte choice = 0;
    static ubyte choice1 = 0;
    if (!(AskP (dbGetObject (9801U), 5, dbGetObject (9824U), (4294967295U), ((U8)0))))
 SetP (dbGetObject (9801U), 5, dbGetObject (9824U), (4294967295U));
    while (choice != 4) {
 choice = Say(2U, choice, 7, "Tools Shop");
 switch (choice) {
 case 0:
     choice1 = tcBuyTool(choice1);
     break;
 case 1:
     tcSellTool();
     break;
 case 2:
     choice1 = tcShowTool(choice1);
     break;
 case 3:
     choice1 = tcDescTool(choice1);
     break;
 default:
     choice = 4;
     break;
 }
 if (choice1 == ((U8)-1))
     choice1 = 0;
    }
}

canonical_original_code:
void tcToolsShop()
{
    unsigned char choice = 0;
    static unsigned char choice1 = 0;
    if (!(AskP (dbGetObject (9801U), 5, dbGetObject (9824U), (4294967295U), ((unsigned char)0))))
 SetP (dbGetObject (9801U), 5, dbGetObject (9824U), (4294967295U));
    while (choice != 4) {
 choice = Say(2U, choice, 7, "Tools Shop");
 switch (choice) {
 case 0:
     choice1 = tcBuyTool(choice1);
     break;
 case 1:
     tcSellTool();
     break;
 case 2:
     choice1 = tcShowTool(choice1);
     break;
 case 3:
     choice1 = tcDescTool(choice1);
     break;
 default:
     choice = 4;
     break;
 }
 if (choice1 == ((U8)-1))
     choice1 = 0;
    }
}