tcDealerSays

decompiled_code:
__int64 __fastcall tcDealerSays(unsigned __int16 *a1, unsigned __int8 a2, int a3)
{
__int64 v4; // r14
__int64 v5; // rbp
unsigned int v6; // eax
__int64 v7; // rbx
__int64 v8; // rax
__int64 v9; // rax
__int64 v11; // rax
int v12; // er8
__int64 **v13; // r15
int v14; // ebx
__int64 v15; // rsi
unsigned int v16; // ebx
unsigned __int8 v17; // r13
__int64 v18; // r12
__int64 v19; // rax
__int64 v20; // rax
__int64 *v21; // r13
__int64 v22; // rbx
__int64 v23; // rax
unsigned int v24; // er12
__int64 v25; // rax
__int64 v26; // rax
__int64 v27; // rax
unsigned int v28; // er11
unsigned int v29; // eax
int v30; // er12
unsigned int v31; // eax
unsigned int v32; // er13
__int64 v33; // r12
char *v34; // rbx
unsigned int v35; // [rsp+4h] [rbp-194h]
__int64 v36; // [rsp+10h] [rbp-188h]
__int64 v37; // [rsp+18h] [rbp-180h]
__int64 v38; // [rsp+20h] [rbp-178h]
__int64 v39; // [rsp+28h] [rbp-170h]
__int64 v40; // [rsp+28h] [rbp-170h]
__int64 v41; // [rsp+30h] [rbp-168h]
int i; // [rsp+38h] [rbp-160h]
unsigned int v43; // [rsp+3Ch] [rbp-15Ch]
__int64 v44[3]; // [rsp+40h] [rbp-158h] BYREF
char v45; // [rsp+58h] [rbp-140h] BYREF
char s[312]; // [rsp+60h] [rbp-138h] BYREF

v36 = txtGoKey(7LL, "enum_LootE");
v37 = txtGoKey(7LL, "enum_LootNameE");
v4 = txtGoKey(2LL, "DEALER_OFFER");
v5 = CreateList();
v6 = getKey(1LL);
v38 = dbGetObject(v6);
v41 = dbGetObject(9814LL);
v44[0] = v41;
v44[1] = dbGetObject(9825LL);
v44[2] = dbGetObject(9820LL);
if ( a3 )
{
SetObjectListAttr(0LL, 9910LL);
v11 = dbGetObject(9801LL);
AskAll(v11, 4LL, &BuildObjectList);
v12 = 255;
v13 = (__int64 **)*ObjectList;
v35 = a2;
v14 = a3 * (127 - *((unsigned __int8 *)a1 + 20)) / 1270 + a3;
if ( v14 <= 255 )
v12 = v14;
for ( i = v12; *v13; v13 = (__int64 **)*v13 )
{
v21 = v13[5];
v22 = dbGetObject(*((unsigned int *)v13 + 8));
v23 = dbGetObject(9801LL);
v24 = GetP(v23, 4LL, v22);
RemoveNode(v5, 0LL);
if ( *(_DWORD *)v21 == v35 )
{
v15 = *((unsigned int *)v21 + 1);
v16 = (int)(v24 * i) / 255;
if ( !v16 )
v16 = 1;
if ( (_DWORD)v15 )
{
v17 = 10;
v18 = *(_QWORD *)(GetNthNode(v37, v15) + 16);
v19 = GetNthNode(v4, 2LL);
sprintf(s, *(const char **)(v19 + 16), v18);
CreateNode(v5, 0LL, s);
v20 = GetNthNode(v4, 3LL);
sprintf(s, *(const char **)(v20 + 16), v16);
}
else
{
v17 = 1;
v39 = *(_QWORD *)(GetNthNode(v36, v35) + 16);
v25 = GetNthNode(v4, 0LL);
sprintf(s, *(const char **)(v25 + 16), v39);
CreateNode(v5, 0LL, s);
v26 = GetNthNode(v4, 1LL);
sprintf(s, *(const char **)(v26 + 16), v24, v16);
}
CreateNode(v5, 0LL, s);
SetPictID(*a1);
Bubble(v5, 0LL, 0LL, 0LL);
if ( !(unsigned __int8)Say(2LL, 0LL, 7LL, "DEALER_ANSWER") )
{
v40 = dbGetObject(*((unsigned int *)v13 + 8));
v27 = dbGetObject(9801LL);
UnSet(v27, 4LL, v40);
v28 = 1;
if ( v16 * *(unsigned __int8 *)(v38 + 14) > 0xC7 )
v28 = v16 * *(unsigned __int8 *)(v38 + 14) / 0x64;
v43 = v28;
*((_BYTE *)a1 + 20) = ChangeAbs(*((unsigned __int8 *)a1 + 20), v17, 0LL, 255LL);
v29 = getKey(1LL);
v30 = *(_DWORD *)dbGetObject(v29);
v31 = getKey(1LL);
v32 = -v17;
*(_DWORD *)dbGetObject(v31) = v43 + v30;
v33 = v41;
*(_DWORD *)(v38 + 4) += v16;
v34 = (char *)v44;
*(_DWORD *)(v38 + 8) += v43;
if ( a1 != (unsigned __int16 *)v41 )
LABEL_20:
*(_BYTE *)(v33 + 20) = ChangeAbs(*(unsigned __int8 *)(v33 + 20), v32, 0LL, 255LL);
while ( 1 )
{
v34 += 8;
if ( v34 == &v45 )
break;
v33 = *(_QWORD *)v34;
if ( a1 != *(unsigned __int16 **)v34 )
goto LABEL_20;
}
}
}
}
}
else
{
v7 = *(_QWORD *)(GetNthNode(v36, a2) + 16);
v8 = GetNthNode(v4, 4LL);
sprintf(s, *(const char **)(v8 + 16), v7);
CreateNode(v5, 0LL, s);
v9 = GetNthNode(v4, 5LL);
CreateNode(v5, 0LL, *(_QWORD *)(v9 + 16));
SetPictID(*a1);
Bubble(v5, 0LL, 0LL, 0LL);
}
RemoveList(v37);
RemoveList(v5);
RemoveList(v4);
return RemoveList(v36);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 *a1, unsigned __int8 a2, int a3)
{
__int64 v4; // r14
__int64 v5; // rbp
unsigned int v6; // eax
__int64 v7; // rbx
__int64 v8; // rax
__int64 v9; // rax
__int64 v11; // rax
int v12; // er8
__int64 **v13; // r15
int v14; // ebx
__int64 v15; // rsi
unsigned int v16; // ebx
unsigned __int8 v17; // r13
__int64 v18; // r12
__int64 v19; // rax
__int64 v20; // rax
__int64 *v21; // r13
__int64 v22; // rbx
__int64 v23; // rax
unsigned int v24; // er12
__int64 v25; // rax
__int64 v26; // rax
__int64 v27; // rax
unsigned int v28; // er11
unsigned int v29; // eax
int v30; // er12
unsigned int v31; // eax
unsigned int v32; // er13
__int64 v33; // r12
char *v34; // rbx
unsigned int v35; // [rsp+4h] [rbp-194h]
__int64 v36; // [rsp+10h] [rbp-188h]
__int64 v37; // [rsp+18h] [rbp-180h]
__int64 v38; // [rsp+20h] [rbp-178h]
__int64 v39; // [rsp+28h] [rbp-170h]
__int64 v40; // [rsp+28h] [rbp-170h]
__int64 v41; // [rsp+30h] [rbp-168h]
int i; // [rsp+38h] [rbp-160h]
unsigned int v43; // [rsp+3Ch] [rbp-15Ch]
__int64 v44[3]; // [rsp+40h] [rbp-158h] BYREF
char v45; // [rsp+58h] [rbp-140h] BYREF
char s[312]; // [rsp+60h] [rbp-138h] BYREF

v36 = txtGoKey(7LL, "enum_LootE");
v37 = txtGoKey(7LL, "enum_LootNameE");
v4 = txtGoKey(2LL, "DEALER_OFFER");
v5 = CreateList();
v6 = getKey(1LL);
v38 = dbGetObject(v6);
v41 = dbGetObject(9814LL);
v44[0] = v41;
v44[1] = dbGetObject(9825LL);
v44[2] = dbGetObject(9820LL);
if ( a3 )
{
SetObjectListAttr(0LL, 9910LL);
v11 = dbGetObject(9801LL);
AskAll(v11, 4LL, &BuildObjectList);
v12 = 255;
v13 = (__int64 **)*ObjectList;
v35 = a2;
v14 = a3 * (127 - *((unsigned __int8 *)a1 + 20)) / 1270 + a3;
if ( v14 <= 255 )
v12 = v14;
for ( i = v12; *v13; v13 = (__int64 **)*v13 )
{
v21 = v13[5];
v22 = dbGetObject(*((unsigned int *)v13 + 8));
v23 = dbGetObject(9801LL);
v24 = GetP(v23, 4LL, v22);
RemoveNode(v5, 0LL);
if ( *(_DWORD *)v21 == v35 )
{
v15 = *((unsigned int *)v21 + 1);
v16 = (int)(v24 * i) / 255;
if ( !v16 )
v16 = 1;
if ( (_DWORD)v15 )
{
v17 = 10;
v18 = *(_QWORD *)(GetNthNode(v37, v15) + 16);
v19 = GetNthNode(v4, 2LL);
sprintf(s, *(const char **)(v19 + 16), v18);
CreateNode(v5, 0LL, s);
v20 = GetNthNode(v4, 3LL);
sprintf(s, *(const char **)(v20 + 16), v16);
}
else
{
v17 = 1;
v39 = *(_QWORD *)(GetNthNode(v36, v35) + 16);
v25 = GetNthNode(v4, 0LL);
sprintf(s, *(const char **)(v25 + 16), v39);
CreateNode(v5, 0LL, s);
v26 = GetNthNode(v4, 1LL);
sprintf(s, *(const char **)(v26 + 16), v24, v16);
}
CreateNode(v5, 0LL, s);
SetPictID(*a1);
Bubble(v5, 0LL, 0LL, 0LL);
if ( !(unsigned __int8)Say(2LL, 0LL, 7LL, "DEALER_ANSWER") )
{
v40 = dbGetObject(*((unsigned int *)v13 + 8));
v27 = dbGetObject(9801LL);
UnSet(v27, 4LL, v40);
v28 = 1;
if ( v16 * *(unsigned __int8 *)(v38 + 14) > 0xC7 )
v28 = v16 * *(unsigned __int8 *)(v38 + 14) / 0x64;
v43 = v28;
*((_BYTE *)a1 + 20) = ChangeAbs(*((unsigned __int8 *)a1 + 20), v17, 0LL, 255LL);
v29 = getKey(1LL);
v30 = *(_DWORD *)dbGetObject(v29);
v31 = getKey(1LL);
v32 = -v17;
*(_DWORD *)dbGetObject(v31) = v43 + v30;
v33 = v41;
*(_DWORD *)(v38 + 4) += v16;
v34 = (char *)v44;
*(_DWORD *)(v38 + 8) += v43;
if ( a1 != (unsigned __int16 *)v41 )
LABEL_20:
*(_BYTE *)(v33 + 20) = ChangeAbs(*(unsigned __int8 *)(v33 + 20), v32, 0LL, 255LL);
while ( 1 )
{
v34 += 8;
if ( v34 == &v45 )
break;
v33 = *(_QWORD *)v34;
if ( a1 != *(unsigned __int16 **)v34 )
goto LABEL_20;
}
}
}
}
}
else
{
v7 = *(_QWORD *)(GetNthNode(v36, a2) + 16);
v8 = GetNthNode(v4, 4LL);
sprintf(s, *(const char **)(v8 + 16), v7);
CreateNode(v5, 0LL, s);
v9 = GetNthNode(v4, 5LL);
CreateNode(v5, 0LL, *(_QWORD *)(v9 + 16));
SetPictID(*a1);
Bubble(v5, 0LL, 0LL, 0LL);
}
RemoveList(v37);
RemoveList(v5);
RemoveList(v4);
return RemoveList(v36);
}

original_code:
void tcDealerSays(Person dealer, ubyte textNr, S32 perc)
{
    LIST *lootNames = txtGoKey(7U, "enum_LootE");
    LIST *specialLoot = txtGoKey(7U, "enum_LootNameE");
    LIST *dealerText = txtGoKey(2U, "DEALER_OFFER");
    LIST *dealerOffer = CreateList();
    char line[256];
    ubyte symp, i;
    struct ObjectNode *n;
    Person others[3];
    Player player = dbGetObject(getKey(_Player_Player_1));
    others[0] = dbGetObject(9814U);
    others[1] = dbGetObject(9825U);
    others[2] = dbGetObject(9820U);
    if (perc == 0) {
 sprintf(line, (((NODE *)(GetNthNode(dealerText, 4)))->Name),
  (((NODE *)(GetNthNode(lootNames, (U32) textNr)))->Name));
 CreateNode(dealerOffer, 0L, line);
 CreateNode(dealerOffer, 0L, (((NODE *)(GetNthNode(dealerText, 5)))->Name));
 SetPictID(dealer->PictID);
 Bubble(dealerOffer, 0, 0L, 0L);
    } else {
 { SetObjectListAttr ((0),9910L); AskAll (dbGetObject (9801U), 4, BuildObjectList); };
 perc = ((((perc + (((S32)perc * ((S32)127L - (S32)dealer->Known)) / (S32)1270))) < (255) ? ((perc + (((S32)perc * ((S32)127L - (S32)dealer->Known)) / (S32)1270))) : (255)));
 for (n = (struct ObjectNode *) ((((NODE *)((&((ObjectList))->Head)))->Succ)); (((NODE *)(n))->Succ);
      n = (struct ObjectNode *) (((NODE *)(n))->Succ)) {
     Loot loot = (((struct ObjectNode *)n)->data);
     U32 price = GetP (dbGetObject (9801U), 4, dbGetObject ((((struct ObjectNode *)n)->nr))), offer;
     offer = (((S32)price * (S32)perc) / (S32)255);
     offer = ((offer) > (1) ? (offer) : (1));
     RemoveNode(dealerOffer, ((void *)0));
     if ((loot->Type) == textNr) {
  if (loot->Name) {
      symp = 10;
      sprintf(line, (((NODE *)(GetNthNode(dealerText, 2)))->Name),
       (((NODE *)(GetNthNode (specialLoot, (U32) loot->Name)))->Name));
      CreateNode(dealerOffer, 0L, line);
      sprintf(line, (((NODE *)(GetNthNode(dealerText, 3)))->Name), offer);
      CreateNode(dealerOffer, 0L, line);
  } else {
      symp = 1;
      sprintf(line, (((NODE *)(GetNthNode(dealerText, 0)))->Name),
       (((NODE *)(GetNthNode(lootNames, (U32) textNr)))->Name));
      CreateNode(dealerOffer, 0L, line);
      sprintf(line, (((NODE *)(GetNthNode(dealerText, 1)))->Name), price,
       offer);
      CreateNode(dealerOffer, 0L, line);
  }
  SetPictID(dealer->PictID);
  Bubble(dealerOffer, 0, 0L, 0L);
  if (!(Say(2U, 0, 7, "DEALER_ANSWER"))) {
      S32 mattsMoney;
      UnSet (dbGetObject (9801U), 4, dbGetObject ((((struct ObjectNode *)n)->nr)));
      mattsMoney = ((((offer * (player->MattsPart)) / 100)) > (1) ? (((offer * (player->MattsPart)) / 100)) : (1));
      ((dealer)->Known = ChangeAbs ((dealer)->Known, symp, 0, 255));
      (((Player)dbGetObject(getKey(_Player_Player_1)))->Money = ((((Player)dbGetObject(getKey(_Player_Player_1)))->Money) + mattsMoney));
      player->StolenMoney += offer;
      player->MyStolenMoney += mattsMoney;
      for (i = 0; i < 3; i++)
   if (dealer != others[i])
       (((others[i]))->Known = ChangeAbs (((others[i]))->Known, (symp * (-1)), 0, 255));
  }
     }
 }
    }
    RemoveList(specialLoot);
    RemoveList(dealerOffer);
    RemoveList(dealerText);
    RemoveList(lootNames);
}

canonical_original_code:
void tcDealerSays(struct _Person *dealer, unsigned char textNr, int perc)
{
    struct List *lootNames = txtGoKey(7U, "enum_LootE");
    struct List *specialLoot = txtGoKey(7U, "enum_LootNameE");
    struct List *dealerText = txtGoKey(2U, "DEALER_OFFER");
    struct List *dealerOffer = CreateList();
    char line[256];
    unsigned char symp; unsigned char i;
    struct ObjectNode *n;
    struct _Person *others[3];
    struct _Player *player = dbGetObject(getKey(_Player_Player_1));
    others[0] = dbGetObject(9814U);
    others[1] = dbGetObject(9825U);
    others[2] = dbGetObject(9820U);
    if (perc == 0) {
 sprintf(line, (((struct Node *)(GetNthNode(dealerText, 4)))->Name),
  (((struct Node *)(GetNthNode(lootNames, (unsigned int) textNr)))->Name));
 CreateNode(dealerOffer, 0L, line);
 CreateNode(dealerOffer, 0L, (((struct Node *)(GetNthNode(dealerText, 5)))->Name));
 SetPictID(dealer->PictID);
 Bubble(dealerOffer, 0, 0L, 0L);
    } else {
 { SetObjectListAttr ((0),9910L); AskAll (dbGetObject (9801U), 4, BuildObjectList); };
 perc = ((((perc + (((int)perc * ((int)127L - (int)dealer->Known)) / (int)1270))) < (255) ? ((perc + (((int)perc * ((int)127L - (int)dealer->Known)) / (int)1270))) : (255)));
 for (n = (struct ObjectNode *) ((((struct Node *)((&((ObjectList))->Head)))->Succ)); (((struct Node *)(n))->Succ);
      n = (struct ObjectNode *) (((struct Node *)(n))->Succ)) {
     struct _Loot *loot = (((struct ObjectNode *)n)->data);
     unsigned int price = GetP (dbGetObject (9801U), 4, dbGetObject ((((struct ObjectNode *)n)->nr))); unsigned int offer;
     offer = (((int)price * (int)perc) / (int)255);
     offer = ((offer) > (1) ? (offer) : (1));
     RemoveNode(dealerOffer, ((void *)0));
     if ((loot->Type) == textNr) {
  if (loot->Name) {
      symp = 10;
      sprintf(line, (((struct Node *)(GetNthNode(dealerText, 2)))->Name),
       (((struct Node *)(GetNthNode (specialLoot, (unsigned int) loot->Name)))->Name));
      CreateNode(dealerOffer, 0L, line);
      sprintf(line, (((struct Node *)(GetNthNode(dealerText, 3)))->Name), offer);
      CreateNode(dealerOffer, 0L, line);
  } else {
      symp = 1;
      sprintf(line, (((struct Node *)(GetNthNode(dealerText, 0)))->Name),
       (((struct Node *)(GetNthNode(lootNames, (unsigned int) textNr)))->Name));
      CreateNode(dealerOffer, 0L, line);
      sprintf(line, (((struct Node *)(GetNthNode(dealerText, 1)))->Name), price,
       offer);
      CreateNode(dealerOffer, 0L, line);
  }
  SetPictID(dealer->PictID);
  Bubble(dealerOffer, 0, 0L, 0L);
  if (!(Say(2U, 0, 7, "DEALER_ANSWER"))) {
      int mattsMoney;
      UnSet (dbGetObject (9801U), 4, dbGetObject ((((struct ObjectNode *)n)->nr)));
      mattsMoney = ((((offer * (player->MattsPart)) / 100)) > (1) ? (((offer * (player->MattsPart)) / 100)) : (1));
      ((dealer)->Known = ChangeAbs ((dealer)->Known, symp, 0, 255));
      (((struct _Player *)dbGetObject(getKey(_Player_Player_1)))->Money = ((((struct _Player *)dbGetObject(getKey(_Player_Player_1)))->Money) + mattsMoney));
      player->StolenMoney += offer;
      player->MyStolenMoney += mattsMoney;
      for (i = 0; i < 3; i++)
   if (dealer != others[i])
       (((others[i]))->Known = ChangeAbs (((others[i]))->Known, (symp * (-1)), 0, 255));
  }
     }
 }
    }
    RemoveList(specialLoot);
    RemoveList(dealerOffer);
    RemoveList(dealerText);
    RemoveList(lootNames);
}

variable_types:
textNr
unsigned char

variable_types: perc int

variable_types:
symp
unsigned char

variable_types:
i
unsigned char

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

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; } *[3]

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

variable_types: struct _Loot { enum LootE { Ein_Bild=0, Gold=1, Geld=2, Juwelen=3, Delikatessen=4, Eine_Statue=5, Eine_Kuriositaet=6, Ein_historisches_Kunstobjekt=7, Gebrauchsartikel=8, Eine_Vase=9 } Type; enum LootNameE { Kein_Name=0, Eine_Zigarrenkiste=1, Ein_Tiefgekuehlter_Hummer=2, Eine_Cartier_Uhr=3, Ein_Sanskrit_Buch=4, Ein_Autogramm_von_Oscar_Wilde=5, Ein_Beauty_Case=6, Ein_Sparstrumpf=7, Eine_Toilettetasche=8, Die_Gebeine_von_Karl_Marx=9, Eine_Bibel=10, Eine_Bronzestatue=11, Ein_Silbergeschirr=12, Eine_Buddhastatue=13, Eine_Chinavase=14, Der_Stein_von_Rosetta=15, Die_Magna_Charta=16, Eine_Muenzsammlung=17, Ein_Goldring=18, Ein_Saurierknochen=19, Eine_Insektensammlung=20, Ein_Bernstein=21, Das_Jadepferd=22, Eine_Victorianische_Vase=23, Die_Kronjuwelen=24, Der_Ring_des_Abtes=25, Ein_Koffer=26, Ein_Dokument=27, Sherlock_Holmes_Opiumpfeife=28, Eine_Hottentotten_Figur=29, Eine_Batman_Figur=30, Ein_Dicker_Man=31, Ein_Unbekannter=32, Eine_Jack_the_Ripper_Figur=33, Eine_Koenigs_Figur=34, Eine_Wache_Figur=35, Eine_Miss_World_1952_Figur=36, Eine_Formel=37, Die_Unterhose_der_Queen=38, Der_Stone_of_Cone=39 } Name; unsigned int Volume; unsigned short Weight; unsigned short PictID; } *

variable_types:
offer
unsigned int

variable_types: mattsMoney int

user_defined_types: struct _Loot { enum LootE Type; enum LootNameE Name; unsigned int Volume; unsigned short Weight; unsigned short PictID; }


tcMakeLootList

repo: vcosta/derclou

decompiled_code:
__int64 __fastcall tcMakeLootList(unsigned int a1, unsigned int a2)
{
__int64 v4; // rdi
__int64 v5; // r14
__int64 v6; // r12
__int64 v7; // rax
_QWORD *v8; // rax
__int64 *v9; // r15
bool v10; // zf
unsigned int *v11; // r13
__int64 v12; // rax
unsigned int v13; // eax
__int64 v14; // rsi
unsigned int v15; // er10
unsigned int v16; // er9
__int64 v17; // rax
unsigned int v19; // [rsp+4h] [rbp-154h]
__int64 v20; // [rsp+8h] [rbp-150h]
__int64 v21; // [rsp+10h] [rbp-148h]
_QWORD *v22; // [rsp+18h] [rbp-140h]
char dest[312]; // [rsp+20h] [rbp-138h] BYREF

v4 = (unsigned int)getKey(6LL);
v5 = dbGetObject(v4);
v6 = CreateList();
v20 = txtGoKey(7LL, "enum_LootE");
v21 = txtGoKey(7LL, "enum_LootNameE");
SetObjectListAttr(4LL, 9910LL);
v7 = dbGetObject(a1);
AskAll(v7, a2, &BuildObjectList);
v8 = (_QWORD *)ObjectListPrivate;
*(_QWORD *)(v5 + 8) = 0LL;
*(_QWORD *)v5 = 0LL;
v9 = (__int64 *)*v8;
v22 = v8;
*(_QWORD *)(v5 + 16) = 0LL;
v10 = *v9 == 0;
*(_QWORD *)(v5 + 24) = 0LL;
*(_QWORD *)(v5 + 32) = 0LL;
*(_QWORD *)(v5 + 40) = 0LL;
if ( !v10 )
{
do
{
while ( *((_DWORD *)v9 + 9) != 9910 )
{
v9 = (__int64 *)*v9;
if ( !*v9 )
goto LABEL_10;
}
v11 = (unsigned int *)v9[5];
v12 = dbGetObject(a1);
v13 = GetP(v12, a2, v11);
v14 = *v11;
v19 = v13;
switch ( (int)v14 )
{
case 0:
*(_DWORD *)v5 += v13;
break;
case 1:
*(_DWORD *)(v5 + 4) += v13;
break;
case 2:
*(_DWORD *)(v5 + 8) += v13;
break;
case 3:
*(_DWORD *)(v5 + 12) += v13;
break;
case 4:
*(_DWORD *)(v5 + 16) += v13;
break;
case 5:
*(_DWORD *)(v5 + 20) += v13;
break;
case 6:
*(_DWORD *)(v5 + 24) += v13;
break;
case 7:
*(_DWORD *)(v5 + 28) += v13;
break;
case 8:
*(_DWORD *)(v5 + 32) += v13;
break;
case 9:
*(_DWORD *)(v5 + 36) += v13;
break;
default:
break;
}
v15 = v11[1];
v16 = v11[2];
*(_DWORD *)(v5 + 40) += *((unsigned __int16 *)v11 + 6);
*(_DWORD *)(v5 + 44) += v16;
if ( v15 )
v17 = GetNthNode(v21, v15);
else
v17 = GetNthNode(v20, v14);
strcpy(dest, *(const char **)(v17 + 16));
CreateNode(v6, 0LL, dest);
sprintf(dest, "%u", v19);
CreateNode(v6, 0LL, dest);
sprintf(dest, "%u", v11[2]);
CreateNode(v6, 0LL, dest);
sprintf(dest, "%u", *((unsigned __int16 *)v11 + 6));
CreateNode(v6, 0LL, dest);
v9 = (__int64 *)*v9;
}
while ( *v9 );
}
LABEL_10:
RemoveList(v20);
RemoveList(v21);
RemoveList(v22);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 v4; // rdi
__int64 v5; // r14
__int64 v6; // r12
__int64 v7; // rax
_QWORD *v8; // rax
__int64 *v9; // r15
bool v10; // zf
unsigned int *v11; // r13
__int64 v12; // rax
unsigned int v13; // eax
__int64 v14; // rsi
unsigned int v15; // er10
unsigned int v16; // er9
__int64 v17; // rax
unsigned int v19; // [rsp+4h] [rbp-154h]
__int64 v20; // [rsp+8h] [rbp-150h]
__int64 v21; // [rsp+10h] [rbp-148h]
_QWORD *v22; // [rsp+18h] [rbp-140h]
char dest[312]; // [rsp+20h] [rbp-138h] BYREF

v4 = (unsigned int)getKey(6LL);
v5 = dbGetObject(v4);
v6 = CreateList();
v20 = txtGoKey(7LL, "enum_LootE");
v21 = txtGoKey(7LL, "enum_LootNameE");
SetObjectListAttr(4LL, 9910LL);
v7 = dbGetObject(a1);
AskAll(v7, a2, &BuildObjectList);
v8 = (_QWORD *)ObjectListPrivate;
*(_QWORD *)(v5 + 8) = 0LL;
*(_QWORD *)v5 = 0LL;
v9 = (__int64 *)*v8;
v22 = v8;
*(_QWORD *)(v5 + 16) = 0LL;
v10 = *v9 == 0;
*(_QWORD *)(v5 + 24) = 0LL;
*(_QWORD *)(v5 + 32) = 0LL;
*(_QWORD *)(v5 + 40) = 0LL;
if ( !v10 )
{
do
{
while ( *((_DWORD *)v9 + 9) != 9910 )
{
v9 = (__int64 *)*v9;
if ( !*v9 )
goto LABEL_10;
}
v11 = (unsigned int *)v9[5];
v12 = dbGetObject(a1);
v13 = GetP(v12, a2, v11);
v14 = *v11;
v19 = v13;
switch ( (int)v14 )
{
case 0:
*(_DWORD *)v5 += v13;
break;
case 1:
*(_DWORD *)(v5 + 4) += v13;
break;
case 2:
*(_DWORD *)(v5 + 8) += v13;
break;
case 3:
*(_DWORD *)(v5 + 12) += v13;
break;
case 4:
*(_DWORD *)(v5 + 16) += v13;
break;
case 5:
*(_DWORD *)(v5 + 20) += v13;
break;
case 6:
*(_DWORD *)(v5 + 24) += v13;
break;
case 7:
*(_DWORD *)(v5 + 28) += v13;
break;
case 8:
*(_DWORD *)(v5 + 32) += v13;
break;
case 9:
*(_DWORD *)(v5 + 36) += v13;
break;
default:
break;
}
v15 = v11[1];
v16 = v11[2];
*(_DWORD *)(v5 + 40) += *((unsigned __int16 *)v11 + 6);
*(_DWORD *)(v5 + 44) += v16;
if ( v15 )
v17 = GetNthNode(v21, v15);
else
v17 = GetNthNode(v20, v14);
strcpy(dest, *(const char **)(v17 + 16));
CreateNode(v6, 0LL, dest);
sprintf(dest, "%u", v19);
CreateNode(v6, 0LL, dest);
sprintf(dest, "%u", v11[2]);
CreateNode(v6, 0LL, dest);
sprintf(dest, "%u", *((unsigned __int16 *)v11 + 6));
CreateNode(v6, 0LL, dest);
v9 = (__int64 *)*v9;
}
while ( *v9 );
}
LABEL_10:
RemoveList(v20);
RemoveList(v21);
RemoveList(v22);
return v6;
}

original_code:
LIST *tcMakeLootList(U32 containerID, U32 relID)
{
    NODE *n;
    Loot loot;
    CompleteLoot comp = dbGetObject(getKey(_CompleteLoot_LastLoot));
    char data[256];
    U32 value;
    LIST *out = CreateList();
    LIST *loots;
    LIST *lootE = txtGoKey(7U, "enum_LootE");
    LIST *lootNameE = txtGoKey(7U, "enum_LootNameE");
    SetObjectListAttr((1 << 2), 9910L);
    AskAll(dbGetObject(containerID), relID, BuildObjectList);
    loots = ObjectListPrivate;
    comp->Bild = comp->Gold = comp->Geld = comp->Juwelen = 0;
    comp->Delikates = comp->Statue = comp->Kuriositaet = 0;
    comp->HistKunst = comp->GebrauchsArt = comp->Vase = 0;
    comp->TotalWeight = comp->TotalVolume = 0;
    if (!((!(((NODE *)(((((NODE *)((&(((loots)))->Head)))->Succ))))->Succ)))) {
 for (n = (NODE *) ((((NODE *)((&((loots))->Head)))->Succ)); (((NODE *)(n))->Succ);
      n = (NODE *) (((NODE *)(n))->Succ)) {
     if ((((struct ObjectNode *)n)->type) == 9910L) {
  loot = (((struct ObjectNode *)n)->data);
  value = GetP(dbGetObject(containerID), relID, loot);
  switch (loot->Type) {
  case Ein_Bild:
      comp->Bild += value;
      break;
  case Gold:
      comp->Gold += value;
      break;
  case Geld:
      comp->Geld += value;
      break;
  case Juwelen:
      comp->Juwelen += value;
      break;
  case Delikatessen:
      comp->Delikates += value;
      break;
  case Eine_Statue:
      comp->Statue += value;
      break;
  case Eine_Kuriositaet:
      comp->Kuriositaet += value;
      break;
  case Eine_Vase:
      comp->Vase += value;
      break;
  case Ein_historisches_Kunstobjekt:
      comp->HistKunst += value;
      break;
  case Gebrauchsartikel:
      comp->GebrauchsArt += value;
      break;
  default:
      break;
  }
  comp->TotalWeight += loot->Weight;
  comp->TotalVolume += loot->Volume;
  if (loot->Name)
      strcpy(data, (((NODE *)(GetNthNode(lootNameE, loot->Name)))->Name));
  else
      strcpy(data, (((NODE *)(GetNthNode(lootE, loot->Type)))->Name));
  CreateNode(out, 0L, data);
  sprintf(data, "%" "u", value);
  CreateNode(out, 0L, data);
  sprintf(data, "%" "u", loot->Volume);
  CreateNode(out, 0L, data);
  sprintf(data, "%" "u", loot->Weight);
  CreateNode(out, 0L, data);
     }
 }
    }
    RemoveList(lootE);
    RemoveList(lootNameE);
    RemoveList(loots);
    return (out);
}

canonical_original_code:
struct List *tcMakeLootList(unsigned int containerID, unsigned int relID)
{
    struct Node *n;
    struct _Loot *loot;
    struct _CompleteLoot *comp = dbGetObject(getKey(_CompleteLoot_LastLoot));
    char data[256];
    unsigned int value;
    struct List *out = CreateList();
    struct List *loots;
    struct List *lootE = txtGoKey(7U, "enum_LootE");
    struct List *lootNameE = txtGoKey(7U, "enum_LootNameE");
    SetObjectListAttr((1 << 2), 9910L);
    AskAll(dbGetObject(containerID), relID, BuildObjectList);
    loots = ObjectListPrivate;
    comp->Bild = comp->Gold = comp->Geld = comp->Juwelen = 0;
    comp->Delikates = comp->Statue = comp->Kuriositaet = 0;
    comp->HistKunst = comp->GebrauchsArt = comp->Vase = 0;
    comp->TotalWeight = comp->TotalVolume = 0;
    if (!((!(((struct Node *)(((((struct Node *)((&(((loots)))->Head)))->Succ))))->Succ)))) {
 for (n = (struct Node *) ((((struct Node *)((&((loots))->Head)))->Succ)); (((struct Node *)(n))->Succ);
      n = (struct Node *) (((struct Node *)(n))->Succ)) {
     if ((((struct ObjectNode *)n)->type) == 9910L) {
  loot = (((struct ObjectNode *)n)->data);
  value = GetP(dbGetObject(containerID), relID, loot);
  switch (loot->Type) {
  case Ein_Bild:
      comp->Bild += value;
      break;
  case Gold:
      comp->Gold += value;
      break;
  case Geld:
      comp->Geld += value;
      break;
  case Juwelen:
      comp->Juwelen += value;
      break;
  case Delikatessen:
      comp->Delikates += value;
      break;
  case Eine_Statue:
      comp->Statue += value;
      break;
  case Eine_Kuriositaet:
      comp->Kuriositaet += value;
      break;
  case Eine_Vase:
      comp->Vase += value;
      break;
  case Ein_historisches_Kunstobjekt:
      comp->HistKunst += value;
      break;
  case Gebrauchsartikel:
      comp->GebrauchsArt += value;
      break;
  default:
      break;
  }
  comp->TotalWeight += loot->Weight;
  comp->TotalVolume += loot->Volume;
  if (loot->Name)
      strcpy(data, (((struct Node *)(GetNthNode(lootNameE, loot->Name)))->Name));
  else
      strcpy(data, (((struct Node *)(GetNthNode(lootE, loot->Type)))->Name));
  CreateNode(out, 0L, data);
  sprintf(data, "%" "u", value);
  CreateNode(out, 0L, data);
  sprintf(data, "%" "u", loot->Volume);
  CreateNode(out, 0L, data);
  sprintf(data, "%" "u", loot->Weight);
  CreateNode(out, 0L, data);
     }
 }
    }
    RemoveList(lootE);
    RemoveList(lootNameE);
    RemoveList(loots);
    return (out);
}

variable_types:
containerID
unsigned int

variable_types:
relID
unsigned int

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

variable_types: struct _CompleteLoot { unsigned int Bild; unsigned int Gold; unsigned int Geld; unsigned int Juwelen; unsigned int Delikates; unsigned int Statue; unsigned int Kuriositaet; unsigned int HistKunst; unsigned int GebrauchsArt; unsigned int Vase; unsigned int TotalWeight; unsigned int TotalVolume; } *

variable_types:
data
char [256]

variable_types:
value
unsigned int

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

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

user_defined_types: enum LootE { Ein_Bild=0, Gold=1, Geld=2, Juwelen=3, Delikatessen=4, Eine_Statue=5, Eine_Kuriositaet=6, Ein_historisches_Kunstobjekt=7, Gebrauchsartikel=8, Eine_Vase=9 }

user_defined_types: enum LootNameE { Kein_Name=0, Eine_Zigarrenkiste=1, Ein_Tiefgekuehlter_Hummer=2, Eine_Cartier_Uhr=3, Ein_Sanskrit_Buch=4, Ein_Autogramm_von_Oscar_Wilde=5, Ein_Beauty_Case=6, Ein_Sparstrumpf=7, Eine_Toilettetasche=8, Die_Gebeine_von_Karl_Marx=9, Eine_Bibel=10, Eine_Bronzestatue=11, Ein_Silbergeschirr=12, Eine_Buddhastatue=13, Eine_Chinavase=14, Der_Stein_von_Rosetta=15, Die_Magna_Charta=16, Eine_Muenzsammlung=17, Ein_Goldring=18, Ein_Saurierknochen=19, Eine_Insektensammlung=20, Ein_Bernstein=21, Das_Jadepferd=22, Eine_Victorianische_Vase=23, Die_Kronjuwelen=24, Der_Ring_des_Abtes=25, Ein_Koffer=26, Ein_Dokument=27, Sherlock_Holmes_Opiumpfeife=28, Eine_Hottentotten_Figur=29, Eine_Batman_Figur=30, Ein_Dicker_Man=31, Ein_Unbekannter=32, Eine_Jack_the_Ripper_Figur=33, Eine_Koenigs_Figur=34, Eine_Wache_Figur=35, Eine_Miss_World_1952_Figur=36, Eine_Formel=37, Die_Unterhose_der_Queen=38, Der_Stone_of_Cone=39 }


tcDealerOffer

decompiled_code:
__int64 __fastcall tcDealerOffer(unsigned __int16 *a1, unsigned __int8 a2)
{
unsigned int v2; // eax
_DWORD *v3; // rbx
__int64 v4; // rax
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-38h]
__int16 v7; // [rsp+8h] [rbp-30h]
__int64 v8; // [rsp+Ah] [rbp-2Eh]
__int16 v9; // [rsp+12h] [rbp-26h]
__int64 v10; // [rsp+14h] [rbp-24h]
__int16 v11; // [rsp+1Ch] [rbp-1Ch]

v11 = -32236;
v8 = 0x6E4FDCB4C878LL;
v9 = -14226;
v10 = 0xD400DC006E0042DCLL;
v7 = 20670;
v6 = 0xC86ED25ADC9646LL;
v2 = getKey(6LL);
v3 = (_DWORD *)dbGetObject(v2);
v4 = tcMakeLootList(0x2649u, 4u);
result = RemoveList(v4);
if ( *v3 )
{
result = tcDealerSays(a1, 0, *((unsigned __int8 *)&v6 + 10 * a2));
if ( !v3[1] )
{
LABEL_3:
if ( !v3[2] )
goto LABEL_4;
goto LABEL_14;
}
}
else if ( !v3[1] )
{
goto LABEL_3;
}
result = tcDealerSays(a1, 1u, *((unsigned __int8 *)&v6 + 10 * a2 + 1));
if ( !v3[2] )
{
LABEL_4:
if ( !v3[3] )
goto LABEL_5;
goto LABEL_15;
}
LABEL_14:
result = tcDealerSays(a1, 2u, *((unsigned __int8 *)&v6 + 10 * a2 + 2));
if ( !v3[3] )
{
LABEL_5:
if ( !v3[4] )
goto LABEL_6;
goto LABEL_16;
}
LABEL_15:
result = tcDealerSays(a1, 3u, *((unsigned __int8 *)&v6 + 10 * a2 + 3));
if ( !v3[4] )
{
LABEL_6:
if ( !v3[5] )
goto LABEL_7;
goto LABEL_17;
}
LABEL_16:
result = tcDealerSays(a1, 4u, *((unsigned __int8 *)&v6 + 10 * a2 + 4));
if ( !v3[5] )
{
LABEL_7:
if ( !v3[6] )
goto LABEL_8;
goto LABEL_18;
}
LABEL_17:
result = tcDealerSays(a1, 5u, *((unsigned __int8 *)&v6 + 10 * a2 + 5));
if ( !v3[6] )
{
LABEL_8:
if ( !v3[7] )
goto LABEL_9;
goto LABEL_19;
}
LABEL_18:
result = tcDealerSays(a1, 6u, *((unsigned __int8 *)&v6 + 10 * a2 + 6));
if ( !v3[7] )
{
LABEL_9:
if ( !v3[8] )
goto LABEL_10;
goto LABEL_20;
}
LABEL_19:
result = tcDealerSays(a1, 7u, *((unsigned __int8 *)&v6 + 10 * a2 + 7));
if ( !v3[8] )
{
LABEL_10:
if ( !v3[9] )
return result;
return tcDealerSays(a1, 9u, *((unsigned __int8 *)&v7 + 10 * a2 + 1));
}
LABEL_20:
result = tcDealerSays(a1, 8u, *((unsigned __int8 *)&v7 + 10 * a2));
if ( v3[9] )
return tcDealerSays(a1, 9u, *((unsigned __int8 *)&v7 + 10 * a2 + 1));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int16 *a1, unsigned __int8 a2)
{
unsigned int v2; // eax
_DWORD *v3; // rbx
__int64 v4; // rax
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-38h]
__int16 v7; // [rsp+8h] [rbp-30h]
__int64 v8; // [rsp+Ah] [rbp-2Eh]
__int16 v9; // [rsp+12h] [rbp-26h]
__int64 v10; // [rsp+14h] [rbp-24h]
__int16 v11; // [rsp+1Ch] [rbp-1Ch]

v11 = -32236;
v8 = 0x6E4FDCB4C878LL;
v9 = -14226;
v10 = 0xD400DC006E0042DCLL;
v7 = 20670;
v6 = 0xC86ED25ADC9646LL;
v2 = getKey(6LL);
v3 = (_DWORD *)dbGetObject(v2);
v4 = func1(0x2649u, 4u);
result = RemoveList(v4);
if ( *v3 )
{
result = func0(a1, 0, *((unsigned __int8 *)&v6 + 10 * a2));
if ( !v3[1] )
{
LABEL_3:
if ( !v3[2] )
goto LABEL_4;
goto LABEL_14;
}
}
else if ( !v3[1] )
{
goto LABEL_3;
}
result = func0(a1, 1u, *((unsigned __int8 *)&v6 + 10 * a2 + 1));
if ( !v3[2] )
{
LABEL_4:
if ( !v3[3] )
goto LABEL_5;
goto LABEL_15;
}
LABEL_14:
result = func0(a1, 2u, *((unsigned __int8 *)&v6 + 10 * a2 + 2));
if ( !v3[3] )
{
LABEL_5:
if ( !v3[4] )
goto LABEL_6;
goto LABEL_16;
}
LABEL_15:
result = func0(a1, 3u, *((unsigned __int8 *)&v6 + 10 * a2 + 3));
if ( !v3[4] )
{
LABEL_6:
if ( !v3[5] )
goto LABEL_7;
goto LABEL_17;
}
LABEL_16:
result = func0(a1, 4u, *((unsigned __int8 *)&v6 + 10 * a2 + 4));
if ( !v3[5] )
{
LABEL_7:
if ( !v3[6] )
goto LABEL_8;
goto LABEL_18;
}
LABEL_17:
result = func0(a1, 5u, *((unsigned __int8 *)&v6 + 10 * a2 + 5));
if ( !v3[6] )
{
LABEL_8:
if ( !v3[7] )
goto LABEL_9;
goto LABEL_19;
}
LABEL_18:
result = func0(a1, 6u, *((unsigned __int8 *)&v6 + 10 * a2 + 6));
if ( !v3[7] )
{
LABEL_9:
if ( !v3[8] )
goto LABEL_10;
goto LABEL_20;
}
LABEL_19:
result = func0(a1, 7u, *((unsigned __int8 *)&v6 + 10 * a2 + 7));
if ( !v3[8] )
{
LABEL_10:
if ( !v3[9] )
return result;
return func0(a1, 9u, *((unsigned __int8 *)&v7 + 10 * a2 + 1));
}
LABEL_20:
result = func0(a1, 8u, *((unsigned __int8 *)&v7 + 10 * a2));
if ( v3[9] )
return func0(a1, 9u, *((unsigned __int8 *)&v7 + 10 * a2 + 1));
return result;
}

original_code:
void tcDealerOffer(Person dealer, ubyte which)
{
    ubyte Price[3][10] = { {70, 150, 220, 90, 210, 110, 200, 0, 190, 80},
    {120, 200, 180, 220, 79, 110, 0, 0, 110, 200},
    {220, 66, 0, 110, 0, 220, 0, 212, 20, 130}
    };
    CompleteLoot comp = dbGetObject(getKey(_CompleteLoot_LastLoot));
    RemoveList(tcMakeLootList(9801U, 4));
    if (comp->Bild)
 tcDealerSays(dealer, 0, (S32) Price[which][0]);
    if (comp->Gold)
 tcDealerSays(dealer, 1, (S32) Price[which][1]);
    if (comp->Geld)
 tcDealerSays(dealer, 2, (S32) Price[which][2]);
    if (comp->Juwelen)
 tcDealerSays(dealer, 3, (S32) Price[which][3]);
    if (comp->Delikates)
 tcDealerSays(dealer, 4, (S32) Price[which][4]);
    if (comp->Statue)
 tcDealerSays(dealer, 5, (S32) Price[which][5]);
    if (comp->Kuriositaet)
 tcDealerSays(dealer, 6, (S32) Price[which][6]);
    if (comp->HistKunst)
 tcDealerSays(dealer, 7, (S32) Price[which][7]);
    if (comp->GebrauchsArt)
 tcDealerSays(dealer, 8, (S32) Price[which][8]);
    if (comp->Vase)
 tcDealerSays(dealer, 9, (S32) Price[which][9]);
}

canonical_original_code:
void tcDealerOffer(struct _Person *dealer, unsigned char which)
{
    unsigned char Price[3][10] = { {70, 150, 220, 90, 210, 110, 200, 0, 190, 80},
    {120, 200, 180, 220, 79, 110, 0, 0, 110, 200},
    {220, 66, 0, 110, 0, 220, 0, 212, 20, 130}
    };
    struct _CompleteLoot *comp = dbGetObject(getKey(_CompleteLoot_LastLoot));
    RemoveList(tcMakeLootList(9801U, 4));
    if (comp->Bild)
 tcDealerSays(dealer, 0, (int) Price[which][0]);
    if (comp->Gold)
 tcDealerSays(dealer, 1, (int) Price[which][1]);
    if (comp->Geld)
 tcDealerSays(dealer, 2, (int) Price[which][2]);
    if (comp->Juwelen)
 tcDealerSays(dealer, 3, (int) Price[which][3]);
    if (comp->Delikates)
 tcDealerSays(dealer, 4, (int) Price[which][4]);
    if (comp->Statue)
 tcDealerSays(dealer, 5, (int) Price[which][5]);
    if (comp->Kuriositaet)
 tcDealerSays(dealer, 6, (int) Price[which][6]);
    if (comp->HistKunst)
 tcDealerSays(dealer, 7, (int) Price[which][7]);
    if (comp->GebrauchsArt)
 tcDealerSays(dealer, 8, (int) Price[which][8]);
    if (comp->Vase)
 tcDealerSays(dealer, 9, (int) Price[which][9]);
}

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

variable_types:
Price
unsigned char [3][10]

return_type: void

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 _CompleteLoot { unsigned int Bild; unsigned int Gold; unsigned int Geld; unsigned int Juwelen; unsigned int Delikates; unsigned int Statue; unsigned int Kuriositaet; unsigned int HistKunst; unsigned int GebrauchsArt; unsigned int Vase; unsigned int TotalWeight; unsigned int TotalVolume; }


tcDealerDlg

decompiled_code:
__int64 tcDealerDlg()
{
int v0; // ebp
__int64 result; // rax
unsigned __int8 v2; // r13
unsigned __int16 *v3; // r12
__int64 v4; // rbx
__int64 v5; // rax
char v6; // bl
char v7; // al
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // r13
__int64 v13; // rax
__int64 v14; // rdx

v0 = GetObjNrOfLocation(*(unsigned int *)(film + 52LL));
if ( (unsigned int)getKey(16LL) == v0 )
{
v3 = (unsigned __int16 *)dbGetObject(9820LL);
v9 = dbGetObject(9820LL);
v10 = dbGetObject(9801LL);
v11 = v9;
v2 = 2;
SetP(v10, 5LL, v11, 0xFFFFFFFFLL);
}
else if ( (unsigned int)getKey(17LL) == v0 )
{
v2 = 0;
v3 = (unsigned __int16 *)dbGetObject(9814LL);
v4 = dbGetObject(9814LL);
v5 = dbGetObject(9801LL);
SetP(v5, 5LL, v4, 0xFFFFFFFFLL);
}
else
{
result = getKey(18LL);
if ( (_DWORD)result != v0 )
return result;
v3 = (unsigned __int16 *)dbGetObject(9825LL);
v12 = dbGetObject(9825LL);
v13 = dbGetObject(9801LL);
v14 = v12;
v2 = 1;
SetP(v13, 5LL, v14, 0xFFFFFFFFLL);
}
v6 = 0;
LABEL_7:
if ( v6 != 2 )
{
while ( v6 != -1 )
{
v7 = Say(2LL, 0LL, 7LL, "DEALER_QUEST");
v6 = v7;
if ( !v7 )
{
if ( (unsigned int)getKey(16LL) == v0 )
{
Say(2LL, 0LL, *v3, "DEALER_PARKER");
}
else if ( (unsigned int)getKey(17LL) == v0 )
{
Say(2LL, 0LL, *v3, "DEALER_MALOYA");
}
else if ( (unsigned int)getKey(18LL) == v0 )
{
Say(2LL, 0LL, *v3, "DEALER_POOLY");
}
goto LABEL_7;
}
if ( v7 != 1 )
goto LABEL_7;
SetObjectListAttr(0LL, 9910LL);
v8 = dbGetObject(9801LL);
AskAll(v8, 4LL, &BuildObjectList);
if ( !*(_QWORD *)*ObjectList )
{
Say(2LL, 0LL, *v3, "NO_LOOT");
AddVTime(17LL);
goto LABEL_7;
}
tcDealerOffer(v3, v2);
if ( v6 == 2 )
break;
}
}
AddVTime(11LL);
return ShowTime(2LL);
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebp
__int64 result; // rax
unsigned __int8 v2; // r13
unsigned __int16 *v3; // r12
__int64 v4; // rbx
__int64 v5; // rax
char v6; // bl
char v7; // al
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // r13
__int64 v13; // rax
__int64 v14; // rdx

v0 = GetObjNrOfLocation(*(unsigned int *)(film + 52LL));
if ( (unsigned int)getKey(16LL) == v0 )
{
v3 = (unsigned __int16 *)dbGetObject(9820LL);
v9 = dbGetObject(9820LL);
v10 = dbGetObject(9801LL);
v11 = v9;
v2 = 2;
SetP(v10, 5LL, v11, 0xFFFFFFFFLL);
}
else if ( (unsigned int)getKey(17LL) == v0 )
{
v2 = 0;
v3 = (unsigned __int16 *)dbGetObject(9814LL);
v4 = dbGetObject(9814LL);
v5 = dbGetObject(9801LL);
SetP(v5, 5LL, v4, 0xFFFFFFFFLL);
}
else
{
result = getKey(18LL);
if ( (_DWORD)result != v0 )
return result;
v3 = (unsigned __int16 *)dbGetObject(9825LL);
v12 = dbGetObject(9825LL);
v13 = dbGetObject(9801LL);
v14 = v12;
v2 = 1;
SetP(v13, 5LL, v14, 0xFFFFFFFFLL);
}
v6 = 0;
LABEL_7:
if ( v6 != 2 )
{
while ( v6 != -1 )
{
v7 = Say(2LL, 0LL, 7LL, "DEALER_QUEST");
v6 = v7;
if ( !v7 )
{
if ( (unsigned int)getKey(16LL) == v0 )
{
Say(2LL, 0LL, *v3, "DEALER_PARKER");
}
else if ( (unsigned int)getKey(17LL) == v0 )
{
Say(2LL, 0LL, *v3, "DEALER_MALOYA");
}
else if ( (unsigned int)getKey(18LL) == v0 )
{
Say(2LL, 0LL, *v3, "DEALER_POOLY");
}
goto LABEL_7;
}
if ( v7 != 1 )
goto LABEL_7;
SetObjectListAttr(0LL, 9910LL);
v8 = dbGetObject(9801LL);
AskAll(v8, 4LL, &BuildObjectList);
if ( !*(_QWORD *)*ObjectList )
{
Say(2LL, 0LL, *v3, "NO_LOOT");
AddVTime(17LL);
goto LABEL_7;
}
func2(v3, v2);
if ( v6 == 2 )
break;
}
}
AddVTime(11LL);
return ShowTime(2LL);
}

original_code:
void tcDealerDlg(void)
{
    U32 locNr = GetObjNrOfLocation((film->akt_Ort));
    Person dealer = ((void *)0);
    ubyte dealerNr, choice = 0;
    if (locNr == getKey(_Location_Parker)) {
        dealer = dbGetObject(9820U);
        SetP (dbGetObject (9801U), 5, dbGetObject (9820U), (4294967295U));
        dealerNr = 2;
    } else if (locNr == getKey(_Location_Maloya)) {
        dealer = dbGetObject(9814U);
        SetP (dbGetObject (9801U), 5, dbGetObject (9814U), (4294967295U));
        dealerNr = 0;
    } else if (locNr == getKey(_Location_Pooly)) {
        dealer = dbGetObject(9825U);
        SetP (dbGetObject (9801U), 5, dbGetObject (9825U), (4294967295U));
        dealerNr = 1;
    } else {
        return;
    }
    while ((choice != 2) && (choice != ((U8)-1))) {
 choice = Say(2U, 0, 7, "DEALER_QUEST");
 switch (choice) {
 case 0:
            if (locNr == getKey(_Location_Parker)) {
  Say(2U, 0, dealer->PictID, "DEALER_PARKER");
            } else if (locNr == getKey(_Location_Maloya)) {
  Say(2U, 0, dealer->PictID, "DEALER_MALOYA");
            } else if (locNr == getKey(_Location_Pooly)) {
  Say(2U, 0, dealer->PictID, "DEALER_POOLY");
            }
     break;
 case 1:
     { SetObjectListAttr ((0),9910L); AskAll (dbGetObject (9801U), 4, BuildObjectList); };
     if ((!(((NODE *)(((((NODE *)((&(((ObjectList)))->Head)))->Succ))))->Succ))) {
  Say(2U, 0, dealer->PictID, "NO_LOOT");
  AddVTime(17);
     } else
  tcDealerOffer(dealer, dealerNr);
     break;
 case 2:
 default:
     break;
 }
    }
    AddVTime(11);
    ShowTime(2);
}

canonical_original_code:
void tcDealerDlg()
{
    unsigned int locNr = GetObjNrOfLocation((film->akt_Ort));
    struct _Person *dealer = ((void *)0);
    unsigned char dealerNr; unsigned char choice = 0;
    if (locNr == getKey(_Location_Parker)) {
        dealer = dbGetObject(9820U);
        SetP (dbGetObject (9801U), 5, dbGetObject (9820U), (4294967295U));
        dealerNr = 2;
    } else if (locNr == getKey(_Location_Maloya)) {
        dealer = dbGetObject(9814U);
        SetP (dbGetObject (9801U), 5, dbGetObject (9814U), (4294967295U));
        dealerNr = 0;
    } else if (locNr == getKey(_Location_Pooly)) {
        dealer = dbGetObject(9825U);
        SetP (dbGetObject (9801U), 5, dbGetObject (9825U), (4294967295U));
        dealerNr = 1;
    } else {
        return;
    }
    while ((choice != 2) && (choice != ((U8)-1))) {
 choice = Say(2U, 0, 7, "DEALER_QUEST");
 switch (choice) {
 case 0:
            if (locNr == getKey(_Location_Parker)) {
  Say(2U, 0, dealer->PictID, "DEALER_PARKER");
            } else if (locNr == getKey(_Location_Maloya)) {
  Say(2U, 0, dealer->PictID, "DEALER_MALOYA");
            } else if (locNr == getKey(_Location_Pooly)) {
  Say(2U, 0, dealer->PictID, "DEALER_POOLY");
            }
     break;
 case 1:
     { SetObjectListAttr ((0),9910L); AskAll (dbGetObject (9801U), 4, BuildObjectList); };
     if ((!(((struct Node *)(((((struct Node *)((&(((ObjectList)))->Head)))->Succ))))->Succ))) {
  Say(2U, 0, dealer->PictID, "NO_LOOT");
  AddVTime(17);
     } else
  tcDealerOffer(dealer, dealerNr);
     break;
 case 2:
 default:
     break;
 }
    }
    AddVTime(11);
    ShowTime(2);
}

variable_types:
locNr
unsigned int

variable_types:
dealerNr
unsigned char

variable_types:
choice
unsigned char

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

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 }


FindRelation

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

for ( result = relationsDefBase; result; result = *(_QWORD *)result )
{
if ( *(_DWORD *)(result + 8) == a1 )
break;
}
return result;
}

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

for ( result = relationsDefBase; result; result = *(_QWORD *)result )
{
if ( *(_DWORD *)(result + 8) == a1 )
break;
}
return result;
}

original_code:
static struct relationDef *FindRelation(U32 id)
{
    register struct relationDef *rd;
    for (rd = relationsDefBase; rd; rd = rd->rd_next) {
 if (rd->rd_id == id)
     return rd;
    }
    return ((void *)0);
}

canonical_original_code:
static struct relationDef *FindRelation(unsigned int id)
{
    register struct relationDef *rd;
    for (rd = relationsDefBase; rd; rd = rd->rd_next) {
 if (rd->rd_id == id)
     return rd;
    }
    return ((void *)0);
}

variable_types:
id
unsigned int

variable_types: struct relationDef { struct relationDef *rd_next; unsigned int rd_id; struct relation { struct relation *r_next; void *r_leftKey; void *r_rightKey; unsigned int r_parameter; } *rd_relationsTable; } *

user_defined_types: struct relationDef { struct relationDef *rd_next; unsigned int rd_id; struct relation *rd_relationsTable; }


AddRelation

decompiled_code:
__int64 __fastcall AddRelation(unsigned int a1)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( FindRelation(a1) )
return 0LL;
v2 = TCAllocMem(24LL, 0LL);
if ( !v2 )
return 0LL;
v3 = relationsDefBase;
*(_DWORD *)(v2 + 8) = a1;
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)v2 = v3;
++nrOfRelations;
relationsDefBase = v2;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( func0(a1) )
return 0LL;
v2 = TCAllocMem(24LL, 0LL);
if ( !v2 )
return 0LL;
v3 = relationsDefBase;
*(_DWORD *)(v2 + 8) = a1;
*(_QWORD *)(v2 + 16) = 0LL;
*(_QWORD *)v2 = v3;
++nrOfRelations;
relationsDefBase = v2;
return a1;
}

original_code:
U32 AddRelation(U32 id)
{
    register struct relationDef *rd;
    if (!FindRelation(id)) {
 if ((rd = (struct relationDef *) TCAllocMem(sizeof(*rd), 0))) {
     rd->rd_next = relationsDefBase;
     relationsDefBase = rd;
     rd->rd_id = id;
     nrOfRelations++;
     rd->rd_relationsTable = ((void *)0);
     return rd->rd_id;
 }
    }
    return 0;
}

canonical_original_code:
unsigned int AddRelation(unsigned int id)
{
    register struct relationDef *rd;
    if (!FindRelation(id)) {
 if ((rd = (struct relationDef *) TCAllocMem(sizeof(*rd), 0))) {
     rd->rd_next = relationsDefBase;
     relationsDefBase = rd;
     rd->rd_id = id;
     nrOfRelations++;
     rd->rd_relationsTable = ((void *)0);
     return rd->rd_id;
 }
    }
    return 0;
}

return_type: unsigned int

user_defined_types: struct relation { struct relation *r_next; void *r_leftKey; void *r_rightKey; unsigned int r_parameter; }


SetP

decompiled_code:
__int64 __fastcall SetP(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
int v4; // ecx
__int64 v5; // r14
unsigned int (__fastcall *v6)(__int64, __int64); // rax
__int64 *v7; // rbx
__int64 v8; // r13
int v9; // er15
__int64 v10; // rax
__int64 result; // rax

v2 = FindRelation(a2);
if ( !v2 )
return 0LL;
v5 = v2;
v6 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
if ( !CompareKey )
return 0LL;
v7 = *(__int64 **)(v5 + 16);
v8 = v3;
v9 = v4;
if ( !v7 )
{
LABEL_9:
v10 = TCAllocMem(32LL, 0LL);
if ( v10 )
{
*(_QWORD *)v10 = *(_QWORD *)(v5 + 16);
*(_QWORD *)(v5 + 16) = v10;
*(_QWORD *)(v10 + 8) = a1;
*(_QWORD *)(v10 + 16) = v8;
*(_DWORD *)(v10 + 24) = v9;
return a2;
}
return 0LL;
}
while ( !v6(v7[1], a1) || !(unsigned int)CompareKey(v7[2], v8) )
{
v7 = (__int64 *)*v7;
if ( !v7 )
goto LABEL_9;
v6 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
}
result = a2;
if ( v9 != -1 )
*((_DWORD *)v7 + 6) = v9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
int v4; // ecx
__int64 v5; // r14
unsigned int (__fastcall *v6)(__int64, __int64); // rax
__int64 *v7; // rbx
__int64 v8; // r13
int v9; // er15
__int64 v10; // rax
__int64 result; // rax

v2 = func0(a2);
if ( !v2 )
return 0LL;
v5 = v2;
v6 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
if ( !CompareKey )
return 0LL;
v7 = *(__int64 **)(v5 + 16);
v8 = v3;
v9 = v4;
if ( !v7 )
{
LABEL_9:
v10 = TCAllocMem(32LL, 0LL);
if ( v10 )
{
*(_QWORD *)v10 = *(_QWORD *)(v5 + 16);
*(_QWORD *)(v5 + 16) = v10;
*(_QWORD *)(v10 + 8) = a1;
*(_QWORD *)(v10 + 16) = v8;
*(_DWORD *)(v10 + 24) = v9;
return a2;
}
return 0LL;
}
while ( !v6(v7[1], a1) || !(unsigned int)CompareKey(v7[2], v8) )
{
v7 = (__int64 *)*v7;
if ( !v7 )
goto LABEL_9;
v6 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
}
result = a2;
if ( v9 != -1 )
*((_DWORD *)v7 + 6) = v9;
return result;
}

original_code:
U32 SetP(void * leftKey, U32 id, void * rightKey, U32 parameter)
{
    register struct relationDef *rd = FindRelation(id);
    if (rd && CompareKey) {
 register struct relation *r;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, leftKey)
  && CompareKey(r->r_rightKey, rightKey)) {
  if (parameter != (4294967295U))
      r->r_parameter = parameter;
  return id;
     }
 }
 if ((r = (struct relation *) TCAllocMem(sizeof(*r), 0))) {
     r->r_next = rd->rd_relationsTable;
     rd->rd_relationsTable = r;
     r->r_leftKey = leftKey;
     r->r_rightKey = rightKey;
     r->r_parameter = parameter;
     return id;
 }
    }
    return 0;
}

canonical_original_code:
unsigned int SetP(void *leftKey, unsigned int id, void *rightKey, unsigned int parameter)
{
    register struct relationDef *rd = FindRelation(id);
    if (rd && CompareKey) {
 register struct relation *r;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, leftKey)
  && CompareKey(r->r_rightKey, rightKey)) {
  if (parameter != (4294967295U))
      r->r_parameter = parameter;
  return id;
     }
 }
 if ((r = (struct relation *) TCAllocMem(sizeof(*r), 0))) {
     r->r_next = rd->rd_relationsTable;
     rd->rd_relationsTable = r;
     r->r_leftKey = leftKey;
     r->r_rightKey = rightKey;
     r->r_parameter = parameter;
     return id;
 }
    }
    return 0;
}

variable_types:
leftKey
void *

variable_types:
rightKey
void *

variable_types:
parameter
unsigned int

variable_types: struct relation { struct relation *r_next; void *r_leftKey; void *r_rightKey; unsigned int r_parameter; } *


CloneRelation

decompiled_code:
__int64 __fastcall CloneRelation(int a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbx
_QWORD *i; // rbx

v2 = FindRelation(a1);
if ( !v2 )
return 0LL;
v3 = v2;
if ( !(unsigned int)AddRelation(a2) && !FindRelation(a2) )
return 0LL;
for ( i = *(_QWORD **)(v3 + 16); i; i = (_QWORD *)*i )
SetP(i[1], a2);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rbx
_QWORD *i; // rbx

v2 = func0(a1);
if ( !v2 )
return 0LL;
v3 = v2;
if ( !(unsigned int)func1(a2) && !func0(a2) )
return 0LL;
for ( i = *(_QWORD **)(v3 + 16); i; i = (_QWORD *)*i )
func3(i[1], a2);
return a2;
}

original_code:
U32 CloneRelation(U32 id, U32 cloneId)
{
    register struct relationDef *rd;
    if ((rd = FindRelation(id))) {
 if (AddRelation(cloneId) || FindRelation(cloneId)) {
     register struct relation *r;
     for (r = rd->rd_relationsTable; r; r = r->r_next) {
  SetP(r->r_leftKey, cloneId, r->r_rightKey, r->r_parameter);
     }
     return cloneId;
 }
    }
    return 0;
}

canonical_original_code:
unsigned int CloneRelation(unsigned int id, unsigned int cloneId)
{
    register struct relationDef *rd;
    if ((rd = FindRelation(id))) {
 if (AddRelation(cloneId) || FindRelation(cloneId)) {
     register struct relation *r;
     for (r = rd->rd_relationsTable; r; r = r->r_next) {
  SetP(r->r_leftKey, cloneId, r->r_rightKey, r->r_parameter);
     }
     return cloneId;
 }
    }
    return 0;
}

variable_types:
cloneId
unsigned int


UnSet

decompiled_code:
__int64 __fastcall UnSet(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // r14
__int64 v5; // rdx
unsigned int (__fastcall *v6)(_QWORD, __int64); // rax
_QWORD *v7; // rbp
_QWORD *v8; // r12

v2 = FindRelation(a2);
if ( !v2 )
return 0LL;
v4 = v3;
v5 = v2;
v6 = (unsigned int (__fastcall *)(_QWORD, __int64))CompareKey;
if ( !CompareKey )
return 0LL;
v7 = *(_QWORD **)(v5 + 16);
v8 = (_QWORD *)(v5 + 16);
if ( !v7 )
return 0LL;
while ( !v6(v7[1], a1) || !(unsigned int)CompareKey(v7[2], v4) )
{
v8 = v7;
v7 = (_QWORD *)*v7;
if ( !v7 )
return 0LL;
v6 = (unsigned int (__fastcall *)(_QWORD, __int64))CompareKey;
}
*v8 = *v7;
TCFreeMem(v7, 32LL);
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // r14
__int64 v5; // rdx
unsigned int (__fastcall *v6)(_QWORD, __int64); // rax
_QWORD *v7; // rbp
_QWORD *v8; // r12

v2 = func0(a2);
if ( !v2 )
return 0LL;
v4 = v3;
v5 = v2;
v6 = (unsigned int (__fastcall *)(_QWORD, __int64))CompareKey;
if ( !CompareKey )
return 0LL;
v7 = *(_QWORD **)(v5 + 16);
v8 = (_QWORD *)(v5 + 16);
if ( !v7 )
return 0LL;
while ( !v6(v7[1], a1) || !(unsigned int)CompareKey(v7[2], v4) )
{
v8 = v7;
v7 = (_QWORD *)*v7;
if ( !v7 )
return 0LL;
v6 = (unsigned int (__fastcall *)(_QWORD, __int64))CompareKey;
}
*v8 = *v7;
TCFreeMem(v7, 32LL);
return a2;
}

original_code:
U32 UnSet(void * leftKey, U32 id, void * rightKey)
{
    register struct relationDef *rd = FindRelation(id);
    if (rd && CompareKey) {
 register struct relation *r;
 register struct relation **h;
 h = &rd->rd_relationsTable;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, leftKey)
  && CompareKey(r->r_rightKey, rightKey)) {
  *h = r->r_next;
  TCFreeMem(r, sizeof(*r));
  return id;
     }
     h = &r->r_next;
 }
    }
    return 0;
}

canonical_original_code:
unsigned int UnSet(void *leftKey, unsigned int id, void *rightKey)
{
    register struct relationDef *rd = FindRelation(id);
    if (rd && CompareKey) {
 register struct relation *r;
 register struct relation **h;
 h = &rd->rd_relationsTable;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, leftKey)
  && CompareKey(r->r_rightKey, rightKey)) {
  *h = r->r_next;
  TCFreeMem(r, sizeof(*r));
  return id;
     }
     h = &r->r_next;
 }
    }
    return 0;
}

variable_types: struct relation { struct relation *r_next; void *r_leftKey; void *r_rightKey; unsigned int r_parameter; } **


GetP

decompiled_code:
__int64 __fastcall GetP(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // r12
__int64 v5; // rdx
unsigned int (__fastcall *v6)(__int64, __int64); // rax
__int64 **v7; // rbx

v2 = FindRelation(a2);
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = v3;
v5 = v2;
v6 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
if ( !CompareKey )
return 0xFFFFFFFFLL;
v7 = *(__int64 ***)(v5 + 16);
if ( !v7 )
return 0xFFFFFFFFLL;
while ( !v6((__int64)v7[1], a1) || !(unsigned int)CompareKey(v7[2], v4) )
{
v7 = (__int64 **)*v7;
if ( !v7 )
return 0xFFFFFFFFLL;
v6 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
}
return *((unsigned int *)v7 + 6);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // r12
__int64 v5; // rdx
unsigned int (__fastcall *v6)(__int64, __int64); // rax
__int64 **v7; // rbx

v2 = func0(a2);
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = v3;
v5 = v2;
v6 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
if ( !CompareKey )
return 0xFFFFFFFFLL;
v7 = *(__int64 ***)(v5 + 16);
if ( !v7 )
return 0xFFFFFFFFLL;
while ( !v6((__int64)v7[1], a1) || !(unsigned int)CompareKey(v7[2], v4) )
{
v7 = (__int64 **)*v7;
if ( !v7 )
return 0xFFFFFFFFLL;
v6 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
}
return *((unsigned int *)v7 + 6);
}

original_code:
U32 GetP(void * leftKey, U32 id, void * rightKey)
{
    register struct relationDef *rd = FindRelation(id);
    if (rd && CompareKey) {
 register struct relation *r;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, leftKey)
  && CompareKey(r->r_rightKey, rightKey))
  return r->r_parameter;
 }
    }
    return (4294967295U);
}

canonical_original_code:
unsigned int GetP(void *leftKey, unsigned int id, void *rightKey)
{
    register struct relationDef *rd = FindRelation(id);
    if (rd && CompareKey) {
 register struct relation *r;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, leftKey)
  && CompareKey(r->r_rightKey, rightKey))
  return r->r_parameter;
 }
    }
    return (4294967295U);
}


AskP

decompiled_code:
__int64 __fastcall AskP(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
unsigned int v4; // ecx
char v5; // r8
__int64 v6; // r13
__int64 v7; // rdx
unsigned int (__fastcall *v8)(__int64, __int64); // rax
__int64 *v9; // rbx
unsigned int v11; // er15
char v12; // r14
__int64 result; // rax
char v14; // cl
unsigned int v15; // esi

v2 = FindRelation(a2);
if ( !v2 )
return 0LL;
v6 = v3;
v7 = v2;
v8 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
if ( !CompareKey )
return 0LL;
v9 = *(__int64 **)(v7 + 16);
v11 = v4;
v12 = v5;
if ( !v9 )
return 0LL;
while ( !v8(v9[1], a1) || !(unsigned int)CompareKey(v9[2], v6) )
{
v9 = (__int64 *)*v9;
if ( !v9 )
return 0LL;
v8 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
}
if ( !v12 || v11 == -1 )
return a2;
v14 = v12 & 4;
if ( (v12 & 1) != 0 )
{
v15 = *((_DWORD *)v9 + 6);
result = a2;
if ( v14 )
{
if ( v15 < v11 )
return 0LL;
}
else if ( (v12 & 8) != 0 )
{
if ( v15 > v11 )
return 0LL;
}
else if ( v15 != v11 )
{
return 0LL;
}
}
else if ( v14 )
{
result = a2;
if ( *((_DWORD *)v9 + 6) <= v11 )
return 0LL;
}
else if ( (v12 & 8) != 0 )
{
result = a2;
if ( *((_DWORD *)v9 + 6) >= v11 )
return 0LL;
}
else
{
if ( (v12 & 2) == 0 )
return 0LL;
result = a2;
if ( *((_DWORD *)v9 + 6) == v11 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
unsigned int v4; // ecx
char v5; // r8
__int64 v6; // r13
__int64 v7; // rdx
unsigned int (__fastcall *v8)(__int64, __int64); // rax
__int64 *v9; // rbx
unsigned int v11; // er15
char v12; // r14
__int64 result; // rax
char v14; // cl
unsigned int v15; // esi

v2 = func0(a2);
if ( !v2 )
return 0LL;
v6 = v3;
v7 = v2;
v8 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
if ( !CompareKey )
return 0LL;
v9 = *(__int64 **)(v7 + 16);
v11 = v4;
v12 = v5;
if ( !v9 )
return 0LL;
while ( !v8(v9[1], a1) || !(unsigned int)CompareKey(v9[2], v6) )
{
v9 = (__int64 *)*v9;
if ( !v9 )
return 0LL;
v8 = (unsigned int (__fastcall *)(__int64, __int64))CompareKey;
}
if ( !v12 || v11 == -1 )
return a2;
v14 = v12 & 4;
if ( (v12 & 1) != 0 )
{
v15 = *((_DWORD *)v9 + 6);
result = a2;
if ( v14 )
{
if ( v15 < v11 )
return 0LL;
}
else if ( (v12 & 8) != 0 )
{
if ( v15 > v11 )
return 0LL;
}
else if ( v15 != v11 )
{
return 0LL;
}
}
else if ( v14 )
{
result = a2;
if ( *((_DWORD *)v9 + 6) <= v11 )
return 0LL;
}
else if ( (v12 & 8) != 0 )
{
result = a2;
if ( *((_DWORD *)v9 + 6) >= v11 )
return 0LL;
}
else
{
if ( (v12 & 2) == 0 )
return 0LL;
result = a2;
if ( *((_DWORD *)v9 + 6) == v11 )
return 0LL;
}
return result;
}

original_code:
U32 AskP(void * leftKey, U32 id, void * rightKey, U32 parameter,
       U8 comparsion)
{
    register struct relationDef *rd = FindRelation(id);
    if (rd && CompareKey) {
 register struct relation *r;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, leftKey)
  && CompareKey(r->r_rightKey, rightKey)) {
  if (comparsion && (parameter != (4294967295U))) {
      if (comparsion & ((U8)(1))) {
   if (comparsion & ((U8)(1 << 2)))
       return (r->r_parameter >= parameter ? id : 0);
   else if (comparsion & ((U8)(1 << 3)))
       return (r->r_parameter <= parameter ? id : 0);
   return (r->r_parameter == parameter ? id : 0);
      } else if (comparsion & ((U8)(1 << 2)))
   return (r->r_parameter > parameter ? id : 0);
      else if (comparsion & ((U8)(1 << 3)))
   return (r->r_parameter < parameter ? id : 0);
      else if (comparsion & ((U8)(1 << 1)))
   return (r->r_parameter != parameter ? id : 0);
      return 0;
  }
  return id;
     }
 }
    }
    return 0;
}

canonical_original_code:
unsigned int AskP(void *leftKey, unsigned int id, void *rightKey, unsigned int parameter, unsigned char comparsion)
{
    register struct relationDef *rd = FindRelation(id);
    if (rd && CompareKey) {
 register struct relation *r;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, leftKey)
  && CompareKey(r->r_rightKey, rightKey)) {
  if (comparsion && (parameter != (4294967295U))) {
      if (comparsion & ((U8)(1))) {
   if (comparsion & ((U8)(1 << 2)))
       return (r->r_parameter >= parameter ? id : 0);
   else if (comparsion & ((U8)(1 << 3)))
       return (r->r_parameter <= parameter ? id : 0);
   return (r->r_parameter == parameter ? id : 0);
      } else if (comparsion & ((U8)(1 << 2)))
   return (r->r_parameter > parameter ? id : 0);
      else if (comparsion & ((U8)(1 << 3)))
   return (r->r_parameter < parameter ? id : 0);
      else if (comparsion & ((U8)(1 << 1)))
   return (r->r_parameter != parameter ? id : 0);
      return 0;
  }
  return id;
     }
 }
    }
    return 0;
}

variable_types:
comparsion
unsigned char


UnSetAll

decompiled_code:
void __fastcall UnSetAll(__int64 a1, void (__fastcall *a2)(__int64))
{
_QWORD *v2; // r14
_QWORD *v3; // rbx
_QWORD *i; // r12

v2 = (_QWORD *)relationsDefBase;
if ( relationsDefBase )
{
do
{
v3 = (_QWORD *)v2[2];
for ( i = v2 + 2; v3; v3 = (_QWORD *)*v3 )
{
if ( (unsigned int)CompareKey(v3[1], a1) || (unsigned int)CompareKey(v3[2], a1) )
{
if ( a2 )
a2(a1);
*i = *v3;
TCFreeMem(v3, 32LL);
}
i = v3;
}
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, void (__fastcall *a2)(__int64))
{
_QWORD *v2; // r14
_QWORD *v3; // rbx
_QWORD *i; // r12

v2 = (_QWORD *)relationsDefBase;
if ( relationsDefBase )
{
do
{
v3 = (_QWORD *)v2[2];
for ( i = v2 + 2; v3; v3 = (_QWORD *)*v3 )
{
if ( (unsigned int)CompareKey(v3[1], a1) || (unsigned int)CompareKey(v3[2], a1) )
{
if ( a2 )
a2(a1);
*i = *v3;
TCFreeMem(v3, 32LL);
}
i = v3;
}
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
}

original_code:
void UnSetAll(void * key, void (*UseKey) (void *))
{
    register struct relationDef *rd;
    for (rd = relationsDefBase; rd; rd = rd->rd_next) {
 register struct relation *r;
 register struct relation **h;
 h = &rd->rd_relationsTable;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, key) || CompareKey(r->r_rightKey, key)) {
  if (UseKey)
      UseKey(key);
  *h = r->r_next;
  TCFreeMem(r, sizeof(*r));
     }
     h = &r->r_next;
 }
    }
}

canonical_original_code:
void UnSetAll(void *key, void (*UseKey)(void *))
{
    register struct relationDef *rd;
    for (rd = relationsDefBase; rd; rd = rd->rd_next) {
 register struct relation *r;
 register struct relation **h;
 h = &rd->rd_relationsTable;
 for (r = rd->rd_relationsTable; r; r = r->r_next) {
     if (CompareKey(r->r_leftKey, key) || CompareKey(r->r_rightKey, key)) {
  if (UseKey)
      UseKey(key);
  *h = r->r_next;
  TCFreeMem(r, sizeof(*r));
     }
     h = &r->r_next;
 }
    }
}

variable_types:
key
void *

variable_types:
UseKey
void (*)(void *)


RemRelations

decompiled_code:
__int64 __fastcall RemRelations(unsigned int a1, int a2)
{
_QWORD *v2; // rbx
unsigned int v4; // er13
__int64 result; // rax
unsigned int v6; // edi

v2 = (_QWORD *)relationsDefBase;
if ( relationsDefBase )
{
v4 = a1 + a2;
do
{
result = (__int64)v2;
v2 = (_QWORD *)*v2;
v6 = *(_DWORD *)(result + 8);
if ( v6 > a1 && (!a2 || v6 <= v4) )
result = RemRelation(v6);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, int a2)
{
_QWORD *v2; // rbx
unsigned int v4; // er13
__int64 result; // rax
unsigned int v6; // edi

v2 = (_QWORD *)relationsDefBase;
if ( relationsDefBase )
{
v4 = a1 + a2;
do
{
result = (__int64)v2;
v2 = (_QWORD *)*v2;
v6 = *(_DWORD *)(result + 8);
if ( v6 > a1 && (!a2 || v6 <= v4) )
result = func2(v6);
}
while ( v2 );
}
return result;
}

original_code:
void RemRelations(U32 offset, U32 size)
{
    register struct relationDef *rd, *rd_next;
    for (rd = relationsDefBase; rd; rd = rd_next) {
 rd_next = rd->rd_next;
 if (rd->rd_id > offset) {
     if (size && (rd->rd_id > offset + size)) {
  continue;
     }
     RemRelation(rd->rd_id);
 }
    }
}

canonical_original_code:
void RemRelations(unsigned int offset, unsigned int size)
{
    register struct relationDef *rd; register struct relationDef *rd_next;
    for (rd = relationsDefBase; rd; rd = rd_next) {
 rd_next = rd->rd_next;
 if (rd->rd_id > offset) {
     if (size && (rd->rd_id > offset + size)) {
  continue;
     }
     RemRelation(rd->rd_id);
 }
    }
}

variable_types:
offset
unsigned int

variable_types:
size
unsigned int


plInit

decompiled_code:
__int64 plInit()
{
__int64 v0; // rbp
__int64 v1; // rbp
__int64 v2; // rbp
__int64 v3; // rbp
__int64 result; // rax

v0 = txtGoKey(11LL, "TXT_TOO_LOUD");
strcpy(txtTooLoud, *(const char **)(*(_QWORD *)v0 + 16LL));
RemoveList(v0);
v1 = txtGoKey(11LL, "TXT_TIMER");
strcpy(txtTimer, *(const char **)(*(_QWORD *)v1 + 16LL));
RemoveList(v1);
v2 = txtGoKey(11LL, "TXT_WEIGHT");
strcpy(txtWeight, *(const char **)(*(_QWORD *)v2 + 16LL));
RemoveList(v2);
v3 = txtGoKey(11LL, "TXT_SECONDS");
strcpy(txtSeconds, *(const char **)(*(_QWORD *)v3 + 16LL));
RemoveList(v3);
result = InitSystem();
plSys = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbp
__int64 v1; // rbp
__int64 v2; // rbp
__int64 v3; // rbp
__int64 result; // rax

v0 = txtGoKey(11LL, "TXT_TOO_LOUD");
strcpy(txtTooLoud, *(const char **)(*(_QWORD *)v0 + 16LL));
RemoveList(v0);
v1 = txtGoKey(11LL, "TXT_TIMER");
strcpy(txtTimer, *(const char **)(*(_QWORD *)v1 + 16LL));
RemoveList(v1);
v2 = txtGoKey(11LL, "TXT_WEIGHT");
strcpy(txtWeight, *(const char **)(*(_QWORD *)v2 + 16LL));
RemoveList(v2);
v3 = txtGoKey(11LL, "TXT_SECONDS");
strcpy(txtSeconds, *(const char **)(*(_QWORD *)v3 + 16LL));
RemoveList(v3);
result = InitSystem();
plSys = result;
return result;
}

original_code:
void plInit(void)
{
    LIST *l;
    l = txtGoKey(11U, "TXT_TOO_LOUD");
    sprintf(txtTooLoud, "%s", (((NODE *)(((((NODE *)((&((l))->Head)))->Succ))))->Name));
    RemoveList(l);
    l = txtGoKey(11U, "TXT_TIMER");
    sprintf(txtTimer, "%s", (((NODE *)(((((NODE *)((&((l))->Head)))->Succ))))->Name));
    RemoveList(l);
    l = txtGoKey(11U, "TXT_WEIGHT");
    sprintf(txtWeight, "%s", (((NODE *)(((((NODE *)((&((l))->Head)))->Succ))))->Name));
    RemoveList(l);
    l = txtGoKey(11U, "TXT_SECONDS");
    sprintf(txtSeconds, "%s", (((NODE *)(((((NODE *)((&((l))->Head)))->Succ))))->Name));
    RemoveList(l);
    plSys = InitSystem();
}

canonical_original_code:
void plInit()
{
    struct List *l;
    l = txtGoKey(11U, "TXT_TOO_LOUD");
    sprintf(txtTooLoud, "%s", (((struct Node *)(((((struct Node *)((&((l))->Head)))->Succ))))->Name));
    RemoveList(l);
    l = txtGoKey(11U, "TXT_TIMER");
    sprintf(txtTimer, "%s", (((struct Node *)(((((struct Node *)((&((l))->Head)))->Succ))))->Name));
    RemoveList(l);
    l = txtGoKey(11U, "TXT_WEIGHT");
    sprintf(txtWeight, "%s", (((struct Node *)(((((struct Node *)((&((l))->Head)))->Succ))))->Name));
    RemoveList(l);
    l = txtGoKey(11U, "TXT_SECONDS");
    sprintf(txtSeconds, "%s", (((struct Node *)(((((struct Node *)((&((l))->Head)))->Succ))))->Name));
    RemoveList(l);
    plSys = InitSystem();
}

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


plDone

decompiled_code:
__int64 plDone()
{
return CloseSystem(plSys);
}

canonical_decompiled_code:
__int64 func1()
{
return CloseSystem(plSys);
}

original_code:
void plDone(void)
{
    CloseSystem(plSys);
}

canonical_original_code:
void plDone()
{
    CloseSystem(plSys);
}


rndInit

decompiled_code:
void rndInit()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
}

original_code:
void rndInit(void)
{
    srand((unsigned int) time(((void *)0)));
}

canonical_original_code:
void rndInit()
{
    srand((unsigned int) time(((void *)0)));
}


rndDone

decompiled_code:
void rndDone()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void rndDone(void)
{
    return;
}

canonical_original_code:
void rndDone()
{
    return;
}


CalcRandomNr

decompiled_code:
__int64 __fastcall CalcRandomNr(int a1, int a2)
{
return rand() % (unsigned int)(a2 - a1) + a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return rand() % (unsigned int)(a2 - a1) + a1;
}

original_code:
U32 CalcRandomNr(U32 l_limit, U32 u_limit)
{
    U32 x = l_limit + (rand() % (u_limit - l_limit));
    return x;
}

canonical_original_code:
unsigned int CalcRandomNr(unsigned int l_limit, unsigned int u_limit)
{
    unsigned int x = l_limit + (rand() % (u_limit - l_limit));
    return x;
}

variable_types:
x
unsigned int


tcShowPatrol

decompiled_code:
__int64 __fastcall tcShowPatrol(__int64 a1, const char *a2, const char *a3, unsigned __int8 a4, __int64 a5, unsigned int a6)
{
unsigned __int8 v9; // bl
char v11[296]; // [rsp+0h] [rbp-128h] BYREF

sprintf(v11, "%s %s", a2, a3);
CreateNode(a1, 0LL, v11);
SetBubbleType(13LL);
Bubble(a1, a4, 0LL, 140LL);
v9 = GetExtBubbleActionInfo();
*(_BYTE *)(a5 + 8) = ChangeAbs(*(unsigned __int8 *)(a5 + 8), a6, 0LL, 255LL);
ShowTime(0LL);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2, const char *a3, unsigned __int8 a4, __int64 a5, unsigned int a6)
{
unsigned __int8 v9; // bl
char v11[296]; // [rsp+0h] [rbp-128h] BYREF

sprintf(v11, "%s %s", a2, a3);
CreateNode(a1, 0LL, v11);
SetBubbleType(13LL);
Bubble(a1, a4, 0LL, 140LL);
v9 = GetExtBubbleActionInfo();
*(_BYTE *)(a5 + 8) = ChangeAbs(*(unsigned __int8 *)(a5 + 8), a6, 0LL, 255LL);
ShowTime(0LL);
return v9;
}

original_code:
static U32 tcShowPatrol(LIST * bubble_l, char *c_time, char *patr, ubyte first,
          Building bui, U32 raise)
{
    char patrolie[256];
    U32 choice = 0;
    sprintf(patrolie, "%s  %s", c_time, patr);
    CreateNode(bubble_l, 0L, patrolie);
    SetBubbleType(13);
    Bubble(bubble_l, (ubyte) first, 0, 140L);
    choice = GetExtBubbleActionInfo();
    (bui->Exactlyness = (U8)ChangeAbs((S32)bui->Exactlyness,(S32)raise, 0, 255));
    ShowTime(0);
    return choice;
}

canonical_original_code:
static unsigned int tcShowPatrol(struct List *bubble_l, char *c_time, char *patr, unsigned char first, struct _Building *bui, unsigned int raise)
{
    char patrolie[256];
    unsigned int choice = 0;
    sprintf(patrolie, "%s  %s", c_time, patr);
    CreateNode(bubble_l, 0L, patrolie);
    SetBubbleType(13);
    Bubble(bubble_l, (unsigned char) first, 0, 140L);
    choice = GetExtBubbleActionInfo();
    (bui->Exactlyness = (unsigned char)ChangeAbs((int)bui->Exactlyness,(int)raise, 0, 255));
    ShowTime(0);
    return choice;
}

variable_types:
patr
char *

variable_types:
first
unsigned char

variable_types: struct _Building { unsigned int LocationNr; unsigned short PoliceTime; unsigned short GTime; unsigned char Exactlyness; unsigned char GRate; unsigned char Strike; unsigned int Values; enum RouteE { Innenstadt=0, Stadt=1, Landstrasse=2, Autobahn=3 } EscapeRoute; unsigned char EscapeRouteLength; unsigned char RadioGuarding; unsigned char MaxVolume; unsigned char GuardStrength; unsigned short CarXPos; unsigned short CarYPos; unsigned char DiskId; } *

variable_types:
raise
unsigned int

variable_types:
patrolie
char [256]

variable_types:
choice
unsigned int

user_defined_types: struct _Building { unsigned int LocationNr; unsigned short PoliceTime; unsigned short GTime; unsigned char Exactlyness; unsigned char GRate; unsigned char Strike; unsigned int Values; enum RouteE EscapeRoute; unsigned char EscapeRouteLength; unsigned char RadioGuarding; unsigned char MaxVolume; unsigned char GuardStrength; unsigned short CarXPos; unsigned short CarYPos; unsigned char DiskId; }


Investigate

decompiled_code:
__int64 __fastcall Investigate(__int64 a1)
{
int v1; // er12
_QWORD **v2; // r13
__int64 v3; // r14
int v4; // eax
__int64 v5; // r15
__int64 v6; // rax
_QWORD **v7; // r15
_QWORD *v8; // rbp
_QWORD *v9; // rbx
int v10; // ebp
__int64 v11; // r13
__int64 v12; // rdi
char v13; // al
bool v14; // zf
__int64 v15; // rbx
int v16; // eax
const char *v17; // r15
char v18; // al
__int64 v20; // r12
unsigned int v21; // [rsp+0h] [rbp-568h]
char v22; // [rsp+4h] [rbp-564h]
int v23; // [rsp+4h] [rbp-564h]
__int64 v24; // [rsp+8h] [rbp-560h]
int v25; // [rsp+8h] [rbp-560h]
_QWORD *v26; // [rsp+10h] [rbp-558h]
unsigned int v27; // [rsp+18h] [rbp-550h]
unsigned int v28; // [rsp+1Ch] [rbp-54Ch]
char s2[10]; // [rsp+26h] [rbp-542h] BYREF
char v30[256]; // [rsp+30h] [rbp-538h] BYREF
char v31[256]; // [rsp+130h] [rbp-438h] BYREF
char v32[824]; // [rsp+230h] [rbp-338h] BYREF

v28 = GetObjNrOfBuilding(*(unsigned int *)(film + 52LL));
v24 = dbGetObject(v28);
if ( setup[1] && v28 == 509107 )
{
v20 = txtGoKey(5LL, "BuckinghamBeobachtet");
SetBubbleType(13LL);
Bubble(v20, 0LL, 0LL, 0LL);
return RemoveList(v20);
}
if ( (*((_BYTE *)&GamePlayMode + 1) & 1) == 0 )
sndPlaySound("invest.bk", 0LL);
v1 = 0;
inpTurnESC(0LL);
ShowMenuBackground();
ShowTime(0LL);
inpSetWaitTicks(50LL);
gfxSetRect(0LL, 320LL);
gfxSetPens(l_gc, 249LL, 255LL, 0LL);
txtGetNthString(5LL, "Abbrechen", 0LL, v31);
txtGetNthString(5LL, "Patrolie", 0LL, v30);
gfxPrint(m_gc, v31, 24LL, 1LL);
v2 = (_QWORD **)txtGoKey(5LL, a1);
v26 = v2;
v3 = CreateList();
v4 = GetNrOfNodes(v2);
v21 = ((270 - (unsigned int)*(unsigned __int8 *)(v24 + 9)) >> 2) + 1;
v27 = 0xFF / (0x59F / v21 + v4 + 1) + 3;
v5 = dbGetObject(v28);
v6 = dbGetObject(9801LL);
SetP(v6, 4LL, v5, 0xFFFFFFFFLL);
v22 = 0;
do
{
BuildTime(*(unsigned int *)(film + 48LL), s2);
if ( __ROR4__(-286331153 * *(_DWORD *)(film + 48LL), 2) <= 0x4444444u )
{
ShowTime(0LL);
v7 = (_QWORD **)*v2;
v8 = (_QWORD *)**v2;
if ( !v8 )
goto LABEL_41;
}
else
{
v7 = (_QWORD **)*v2;
v8 = (_QWORD *)**v2;
if ( !v8 )
goto LABEL_41;
}
v9 = 0LL;
while ( 1 )
{
if ( !strncmp((const char *)v7[2], s2, 5uLL) )
v9 = v7;
v7 = (_QWORD **)v8;
if ( !*v8 )
break;
v8 = (_QWORD *)*v8;
}
if ( !v9 )
{
LABEL_41:
v9 = 0LL;
AddVTime(1LL);
}
if ( !(*(_DWORD *)(film + 48LL) % v21) )
v22 = tcShowPatrol(v3, s2, v30, v1++, v24, v27);
if ( (unsigned int)CalcRandomNr(0LL, 6LL) == 1 )
*(_BYTE *)(v24 + 10) = ChangeAbs(*(unsigned __int8 *)(v24 + 10), 1LL, 0LL, 255LL);
}
while ( !v9 );
LOBYTE(v10) = v22;
v11 = v24;
v23 = 1440;
while ( 1 )
{
v10 &= 0xB0u;
if ( v10 )
break;
v12 = *(unsigned int *)(film + 48LL);
if ( __ROR4__(-286331153 * v12, 2) <= 0x4444444u )
{
ShowTime(0LL);
v12 = *(unsigned int *)(film + 48LL);
}
BuildTime(v12, s2);
if ( !(*(_DWORD *)(film + 48LL) % v21) )
{
v16 = tcShowPatrol(v3, s2, v30, v1, v11, v27);
if ( v16 )
{
v25 = v16;
if ( (unsigned int)CalcRandomNr(0LL, 6LL) != 1 )
{
++v1;
AddVTime(1LL);
LOBYTE(v10) = v25;
goto LABEL_26;
}
++v1;
v10 = v25;
goto LABEL_39;
}
++v1;
}
v17 = (const char *)v9[2];
if ( !strncmp(v17, s2, 5uLL) )
{
if ( __ROR4__(-286331153 * *(_DWORD *)(film + 48LL), 2) > 0x4444444u )
{
ShowTime(0LL);
v17 = (const char *)v9[2];
}
CreateNode(v3, 0LL, v17);
SetBubbleType(13LL);
Bubble(v3, (unsigned __int8)v1, 0LL, 140LL);
v10 = (unsigned __int8)GetExtBubbleActionInfo();
*(_BYTE *)(v11 + 8) = ChangeAbs(*(unsigned __int8 *)(v11 + 8), v27, 0LL, 255LL);
ShowTime(0LL);
v9 = (_QWORD *)*v9;
if ( !*v9 )
v9 = (_QWORD *)*v26;
++v1;
if ( (unsigned int)CalcRandomNr(0LL, 6LL) != 1 )
goto LABEL_25;
}
else if ( (unsigned int)CalcRandomNr(0LL, 6LL) != 1 )
{
AddVTime(1LL);
goto LABEL_34;
}
LABEL_39:
*(_BYTE *)(v11 + 10) = ChangeAbs(*(unsigned __int8 *)(v11 + 10), 1LL, 0LL, 255LL);
LABEL_25:
AddVTime(1LL);
if ( v10 )
{
LABEL_26:
if ( !--v23 )
goto LABEL_35;
}
else
{
LABEL_34:
v13 = inpWaitFor(2224LL);
v14 = v23-- == 1;
LOBYTE(v10) = v13;
if ( v14 )
{
LABEL_35:
RemoveList(v3);
v15 = txtGoKey(5LL, "24StundenBeobachtet");
SetBubbleType(13LL);
Bubble(v15, 0LL, 0LL, 0LL);
RemoveList(v15);
goto LABEL_45;
}
}
}
RemoveList(v3);
LABEL_45:
RemoveList(v26);
Present(v28, "Building", &InitBuildingPresent);
ShowMenuBackground();
tcRefreshLocationInTitle(*(unsigned int *)(film + 52LL));
inpSetWaitTicks(0LL);
ShowTime(0LL);
v18 = GamePlayMode;
if ( (*(&GamePlayMode + 1) & 1) == 0 )
{
tcPlayStreetSound();
v18 = GamePlayMode;
}
if ( (v18 & 4) != 0 )
{
SuspendAnim();
gfxPrepareRefresh();
gfxGetPaletteFromReg(v32);
gfxShow(224LL, 39LL, 2LL, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
inpWaitFor(32LL);
gfxChangeColors(l_gc, 0LL, 4LL, 0LL);
gfxClearArea(l_gc);
gfxChangeColors(l_gc, 0LL, 2LL, v32);
gfxRefresh();
ContinueAnim();
}
return inpTurnESC(1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // er12
_QWORD **v2; // r13
__int64 v3; // r14
int v4; // eax
__int64 v5; // r15
__int64 v6; // rax
_QWORD **v7; // r15
_QWORD *v8; // rbp
_QWORD *v9; // rbx
int v10; // ebp
__int64 v11; // r13
__int64 v12; // rdi
char v13; // al
bool v14; // zf
__int64 v15; // rbx
int v16; // eax
const char *v17; // r15
char v18; // al
__int64 v20; // r12
unsigned int v21; // [rsp+0h] [rbp-568h]
char v22; // [rsp+4h] [rbp-564h]
int v23; // [rsp+4h] [rbp-564h]
__int64 v24; // [rsp+8h] [rbp-560h]
int v25; // [rsp+8h] [rbp-560h]
_QWORD *v26; // [rsp+10h] [rbp-558h]
unsigned int v27; // [rsp+18h] [rbp-550h]
unsigned int v28; // [rsp+1Ch] [rbp-54Ch]
char s2[10]; // [rsp+26h] [rbp-542h] BYREF
char v30[256]; // [rsp+30h] [rbp-538h] BYREF
char v31[256]; // [rsp+130h] [rbp-438h] BYREF
char v32[824]; // [rsp+230h] [rbp-338h] BYREF

v28 = GetObjNrOfBuilding(*(unsigned int *)(film + 52LL));
v24 = dbGetObject(v28);
if ( setup[1] && v28 == 509107 )
{
v20 = txtGoKey(5LL, "BuckinghamBeobachtet");
SetBubbleType(13LL);
Bubble(v20, 0LL, 0LL, 0LL);
return RemoveList(v20);
}
if ( (*((_BYTE *)&GamePlayMode + 1) & 1) == 0 )
sndPlaySound("invest.bk", 0LL);
v1 = 0;
inpTurnESC(0LL);
ShowMenuBackground();
ShowTime(0LL);
inpSetWaitTicks(50LL);
gfxSetRect(0LL, 320LL);
gfxSetPens(l_gc, 249LL, 255LL, 0LL);
txtGetNthString(5LL, "Abbrechen", 0LL, v31);
txtGetNthString(5LL, "Patrolie", 0LL, v30);
gfxPrint(m_gc, v31, 24LL, 1LL);
v2 = (_QWORD **)txtGoKey(5LL, a1);
v26 = v2;
v3 = CreateList();
v4 = GetNrOfNodes(v2);
v21 = ((270 - (unsigned int)*(unsigned __int8 *)(v24 + 9)) >> 2) + 1;
v27 = 0xFF / (0x59F / v21 + v4 + 1) + 3;
v5 = dbGetObject(v28);
v6 = dbGetObject(9801LL);
SetP(v6, 4LL, v5, 0xFFFFFFFFLL);
v22 = 0;
do
{
BuildTime(*(unsigned int *)(film + 48LL), s2);
if ( __ROR4__(-286331153 * *(_DWORD *)(film + 48LL), 2) <= 0x4444444u )
{
ShowTime(0LL);
v7 = (_QWORD **)*v2;
v8 = (_QWORD *)**v2;
if ( !v8 )
goto LABEL_41;
}
else
{
v7 = (_QWORD **)*v2;
v8 = (_QWORD *)**v2;
if ( !v8 )
goto LABEL_41;
}
v9 = 0LL;
while ( 1 )
{
if ( !strncmp((const char *)v7[2], s2, 5uLL) )
v9 = v7;
v7 = (_QWORD **)v8;
if ( !*v8 )
break;
v8 = (_QWORD *)*v8;
}
if ( !v9 )
{
LABEL_41:
v9 = 0LL;
AddVTime(1LL);
}
if ( !(*(_DWORD *)(film + 48LL) % v21) )
v22 = func0(v3, s2, v30, v1++, v24, v27);
if ( (unsigned int)CalcRandomNr(0LL, 6LL) == 1 )
*(_BYTE *)(v24 + 10) = ChangeAbs(*(unsigned __int8 *)(v24 + 10), 1LL, 0LL, 255LL);
}
while ( !v9 );
LOBYTE(v10) = v22;
v11 = v24;
v23 = 1440;
while ( 1 )
{
v10 &= 0xB0u;
if ( v10 )
break;
v12 = *(unsigned int *)(film + 48LL);
if ( __ROR4__(-286331153 * v12, 2) <= 0x4444444u )
{
ShowTime(0LL);
v12 = *(unsigned int *)(film + 48LL);
}
BuildTime(v12, s2);
if ( !(*(_DWORD *)(film + 48LL) % v21) )
{
v16 = func0(v3, s2, v30, v1, v11, v27);
if ( v16 )
{
v25 = v16;
if ( (unsigned int)CalcRandomNr(0LL, 6LL) != 1 )
{
++v1;
AddVTime(1LL);
LOBYTE(v10) = v25;
goto LABEL_26;
}
++v1;
v10 = v25;
goto LABEL_39;
}
++v1;
}
v17 = (const char *)v9[2];
if ( !strncmp(v17, s2, 5uLL) )
{
if ( __ROR4__(-286331153 * *(_DWORD *)(film + 48LL), 2) > 0x4444444u )
{
ShowTime(0LL);
v17 = (const char *)v9[2];
}
CreateNode(v3, 0LL, v17);
SetBubbleType(13LL);
Bubble(v3, (unsigned __int8)v1, 0LL, 140LL);
v10 = (unsigned __int8)GetExtBubbleActionInfo();
*(_BYTE *)(v11 + 8) = ChangeAbs(*(unsigned __int8 *)(v11 + 8), v27, 0LL, 255LL);
ShowTime(0LL);
v9 = (_QWORD *)*v9;
if ( !*v9 )
v9 = (_QWORD *)*v26;
++v1;
if ( (unsigned int)CalcRandomNr(0LL, 6LL) != 1 )
goto LABEL_25;
}
else if ( (unsigned int)CalcRandomNr(0LL, 6LL) != 1 )
{
AddVTime(1LL);
goto LABEL_34;
}
LABEL_39:
*(_BYTE *)(v11 + 10) = ChangeAbs(*(unsigned __int8 *)(v11 + 10), 1LL, 0LL, 255LL);
LABEL_25:
AddVTime(1LL);
if ( v10 )
{
LABEL_26:
if ( !--v23 )
goto LABEL_35;
}
else
{
LABEL_34:
v13 = inpWaitFor(2224LL);
v14 = v23-- == 1;
LOBYTE(v10) = v13;
if ( v14 )
{
LABEL_35:
RemoveList(v3);
v15 = txtGoKey(5LL, "24StundenBeobachtet");
SetBubbleType(13LL);
Bubble(v15, 0LL, 0LL, 0LL);
RemoveList(v15);
goto LABEL_45;
}
}
}
RemoveList(v3);
LABEL_45:
RemoveList(v26);
Present(v28, "Building", &InitBuildingPresent);
ShowMenuBackground();
tcRefreshLocationInTitle(*(unsigned int *)(film + 52LL));
inpSetWaitTicks(0LL);
ShowTime(0LL);
v18 = GamePlayMode;
if ( (*(&GamePlayMode + 1) & 1) == 0 )
{
tcPlayStreetSound();
v18 = GamePlayMode;
}
if ( (v18 & 4) != 0 )
{
SuspendAnim();
gfxPrepareRefresh();
gfxGetPaletteFromReg(v32);
gfxShow(224LL, 39LL, 2LL, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
inpWaitFor(32LL);
gfxChangeColors(l_gc, 0LL, 4LL, 0LL);
gfxClearArea(l_gc);
gfxChangeColors(l_gc, 0LL, 2LL, v32);
gfxRefresh();
ContinueAnim();
}
return inpTurnESC(1LL);
}

original_code:
void Investigate(char *location)
{
    NODE *n, *nextMsg;
    LIST *origin, *bubble_l;
    char patr[256], line[256], c_time[10];
    U32 minutes = 0, guarding = 0, choice = 0, count = 0, buiID = 0, first =
 0, raise;
    Building bui;
    U32 patrolCount;
    buiID = GetObjNrOfBuilding((film->akt_Ort));
    bui = (Building) dbGetObject(buiID);
    if (setup.Profidisk) {
        if (buiID == 509107U) {
     bubble_l = txtGoKey(5U, "BuckinghamBeobachtet");
     SetBubbleType(13);
     Bubble(bubble_l, 0, 0L, 0L);
     RemoveList(bubble_l);
     return;
        }
    }
    if (!(GamePlayMode & (1<< 8)))
 sndPlaySound("invest.bk", 0);
    inpTurnESC(0);
    ShowMenuBackground();
    ShowTime(0);
    inpSetWaitTicks(50);
    gfxSetRect(0, 320);
    gfxSetPens(l_gc, 249, ((ubyte)255), 0);
    (txtGetNthString(5U, "Abbrechen", 0, line));
    (txtGetNthString(5U, "Patrolie", 0, patr));
    gfxPrint(m_gc, line, 24, (1));
    origin = txtGoKey(5U, location);
    bubble_l = CreateList();
    count = GetNrOfNodes(origin);
    guarding = (U32) (bui->GRate);
    patrolCount = (270 - guarding) / 4 + 1;
    raise = 255 / (1439 / patrolCount + count + 1) + 3;
    SetP (dbGetObject (9801U), 4, dbGetObject (buiID), (4294967295U));
    for (nextMsg = 0; nextMsg == 0;) {
 BuildTime((film->akt_Minute), c_time);
 if (!((film->akt_Minute) % 60))
     ShowTime(0);
 for (n = (NODE *) ((((NODE *)((&((origin))->Head)))->Succ)); (((NODE *)(n))->Succ);
      n = (NODE *) (((NODE *)(n))->Succ)) {
     if (strncmp((((NODE *)(n))->Name), c_time, 5) == 0)
  nextMsg = n;
 }
 if (!nextMsg)
     AddVTime(1);
 if (((film->akt_Minute) % patrolCount) == 0)
     choice = tcShowPatrol(bubble_l, c_time, patr, first++, bui, raise);
 if (CalcRandomNr(0L, 6L) == 1)
     (bui->Strike = (U8)ChangeAbs((S32)bui->Strike,(S32)1, 0, 255));
    }
    while (((minutes) < 1440L) && (!(choice & (1<<5)))
    && (!(choice & (1<<7))) && (!(choice & (1<<4)))) {
 choice = 0;
 if (((film->akt_Minute) % 60) == 0)
     ShowTime(0);
 BuildTime((film->akt_Minute), c_time);
 if (((film->akt_Minute) % patrolCount) == 0)
     choice = tcShowPatrol(bubble_l, c_time, patr, first++, bui, raise);
 if (!choice) {
     if (strncmp((((NODE *)(nextMsg))->Name), c_time, 5) == 0) {
  if (((film->akt_Minute) % 60) != 0)
      ShowTime(0);
  n = CreateNode(bubble_l, 0L, (((NODE *)(nextMsg))->Name));
  SetBubbleType(13);
  Bubble(bubble_l, (ubyte) first++, 0, 140L);
  choice = GetExtBubbleActionInfo();
  (bui->Exactlyness = (U8)ChangeAbs((S32)bui->Exactlyness,(S32)raise, 0, 255));
  ShowTime(0);
  if ((((NODE *)((((NODE *)(nextMsg))->Succ)))->Succ))
      nextMsg = (NODE *) (((NODE *)(nextMsg))->Succ);
  else
      nextMsg = (NODE *) ((((NODE *)((&((origin))->Head)))->Succ));
     }
 }
 if (CalcRandomNr(0L, 6L) == 1)
     (bui->Strike = (U8)ChangeAbs((S32)bui->Strike,(S32)1, 0, 255));
 AddVTime(1L);
 minutes++;
 if (!choice)
     choice =
  inpWaitFor((1<<11) | (1<<5) | (1<<7) | (1<<4));
    }
    RemoveList(bubble_l);
    if (minutes >= 1440) {
 bubble_l = txtGoKey(5U, "24StundenBeobachtet");
 SetBubbleType(13);
 Bubble(bubble_l, 0, 0L, 0L);
 RemoveList(bubble_l);
    }
    RemoveList(origin);
    Present(buiID, "Building", InitBuildingPresent);
    ShowMenuBackground();
    tcRefreshLocationInTitle((film->akt_Ort));
    inpSetWaitTicks(0);
    ShowTime(0);
    if (!(GamePlayMode & (1<< 8)))
 tcPlayStreetSound();
    if (GamePlayMode & (1<< 2)) {
 U8 palette[768];
 SuspendAnim();
 gfxPrepareRefresh();
 gfxGetPaletteFromReg(palette);
 gfxShow(224,
  1 | 4 | 2 | 32, 2,
  -1, -1);
 inpWaitFor((1<<5));
 gfxChangeColors(l_gc, 0, 4, ((void *)0));
 gfxClearArea(l_gc);
 gfxChangeColors(l_gc, 0, 2, palette);
 gfxRefresh();
 ContinueAnim();
    }
    inpTurnESC(1);
}

canonical_original_code:
void Investigate(char *location)
{
    struct Node *n; struct Node *nextMsg;
    struct List *origin; struct List *bubble_l;
    char patr[256]; char line[256]; char c_time[10];
    unsigned int minutes = 0; unsigned int guarding = 0; unsigned int choice = 0; unsigned int count = 0; unsigned int buiID = 0; unsigned int first = 0; unsigned int raise;
    struct _Building *bui;
    unsigned int patrolCount;
    buiID = GetObjNrOfBuilding((film->akt_Ort));
    bui = (struct _Building *) dbGetObject(buiID);
    if (setup.Profidisk) {
        if (buiID == 509107U) {
     bubble_l = txtGoKey(5U, "BuckinghamBeobachtet");
     SetBubbleType(13);
     Bubble(bubble_l, 0, 0L, 0L);
     RemoveList(bubble_l);
     return;
        }
    }
    if (!(GamePlayMode & (1<< 8)))
 sndPlaySound("invest.bk", 0);
    inpTurnESC(0);
    ShowMenuBackground();
    ShowTime(0);
    inpSetWaitTicks(50);
    gfxSetRect(0, 320);
    gfxSetPens(l_gc, 249, ((unsigned char)255), 0);
    (txtGetNthString(5U, "Abbrechen", 0, line));
    (txtGetNthString(5U, "Patrolie", 0, patr));
    gfxPrint(m_gc, line, 24, (1));
    origin = txtGoKey(5U, location);
    bubble_l = CreateList();
    count = GetNrOfNodes(origin);
    guarding = (U32) (bui->GRate);
    patrolCount = (270 - guarding) / 4 + 1;
    raise = 255 / (1439 / patrolCount + count + 1) + 3;
    SetP (dbGetObject (9801U), 4, dbGetObject (buiID), (4294967295U));
    for (nextMsg = 0; nextMsg == 0;) {
 BuildTime((film->akt_Minute), c_time);
 if (!((film->akt_Minute) % 60))
     ShowTime(0);
 for (n = (struct Node *) ((((struct Node *)((&((origin))->Head)))->Succ)); (((struct Node *)(n))->Succ);
      n = (struct Node *) (((struct Node *)(n))->Succ)) {
     if (strncmp((((struct Node *)(n))->Name), c_time, 5) == 0)
  nextMsg = n;
 }
 if (!nextMsg)
     AddVTime(1);
 if (((film->akt_Minute) % patrolCount) == 0)
     choice = tcShowPatrol(bubble_l, c_time, patr, first++, bui, raise);
 if (CalcRandomNr(0L, 6L) == 1)
     (bui->Strike = (unsigned char)ChangeAbs((int)bui->Strike,(int)1, 0, 255));
    }
    while (((minutes) < 1440L) && (!(choice & (1<<5)))
    && (!(choice & (1<<7))) && (!(choice & (1<<4)))) {
 choice = 0;
 if (((film->akt_Minute) % 60) == 0)
     ShowTime(0);
 BuildTime((film->akt_Minute), c_time);
 if (((film->akt_Minute) % patrolCount) == 0)
     choice = tcShowPatrol(bubble_l, c_time, patr, first++, bui, raise);
 if (!choice) {
     if (strncmp((((struct Node *)(nextMsg))->Name), c_time, 5) == 0) {
  if (((film->akt_Minute) % 60) != 0)
      ShowTime(0);
  n = CreateNode(bubble_l, 0L, (((struct Node *)(nextMsg))->Name));
  SetBubbleType(13);
  Bubble(bubble_l, (unsigned char) first++, 0, 140L);
  choice = GetExtBubbleActionInfo();
  (bui->Exactlyness = (unsigned char)ChangeAbs((int)bui->Exactlyness,(int)raise, 0, 255));
  ShowTime(0);
  if ((((struct Node *)((((struct Node *)(nextMsg))->Succ)))->Succ))
      nextMsg = (struct Node *) (((struct Node *)(nextMsg))->Succ);
  else
      nextMsg = (struct Node *) ((((struct Node *)((&((origin))->Head)))->Succ));
     }
 }
 if (CalcRandomNr(0L, 6L) == 1)
     (bui->Strike = (unsigned char)ChangeAbs((int)bui->Strike,(int)1, 0, 255));
 AddVTime(1L);
 minutes++;
 if (!choice)
     choice =
  inpWaitFor((1<<11) | (1<<5) | (1<<7) | (1<<4));
    }
    RemoveList(bubble_l);
    if (minutes >= 1440) {
 bubble_l = txtGoKey(5U, "24StundenBeobachtet");
 SetBubbleType(13);
 Bubble(bubble_l, 0, 0L, 0L);
 RemoveList(bubble_l);
    }
    RemoveList(origin);
    Present(buiID, "Building", InitBuildingPresent);
    ShowMenuBackground();
    tcRefreshLocationInTitle((film->akt_Ort));
    inpSetWaitTicks(0);
    ShowTime(0);
    if (!(GamePlayMode & (1<< 8)))
 tcPlayStreetSound();
    if (GamePlayMode & (1<< 2)) {
 unsigned char palette[768];
 SuspendAnim();
 gfxPrepareRefresh();
 gfxGetPaletteFromReg(palette);
 gfxShow(224,
  1 | 4 | 2 | 32, 2,
  -1, -1);
 inpWaitFor((1<<5));
 gfxChangeColors(l_gc, 0, 4, ((void *)0));
 gfxClearArea(l_gc);
 gfxChangeColors(l_gc, 0, 2, palette);
 gfxRefresh();
 ContinueAnim();
    }
    inpTurnESC(1);
}

variable_types:
location
char *

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

variable_types:
patr
char [256]

variable_types:
line
char [256]

variable_types:
minutes
unsigned int

variable_types:
guarding
unsigned int

variable_types:
count
unsigned int

variable_types:
buiID
unsigned int

variable_types:
first
unsigned int

variable_types:
patrolCount
unsigned int

variable_types:
palette
unsigned char [768]

user_defined_types: enum RouteE { Innenstadt=0, Stadt=1, Landstrasse=2, Autobahn=3 }


TCAllocMem

decompiled_code:
void *__fastcall TCAllocMem(size_t size, char a2)
{
void *result; // rax

if ( a2 )
result = calloc(1uLL, size);
else
result = malloc(size);
if ( result )
{
MemControl += size;
}
else
{
ErrorMsg(2LL, 6LL, 1LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t size, char a2)
{
void *result; // rax

if ( a2 )
result = calloc(1uLL, size);
else
result = malloc(size);
if ( result )
{
MemControl += size;
}
else
{
ErrorMsg(2LL, 6LL, 1LL);
result = 0LL;
}
return result;
}

original_code:
void *TCAllocMem(size_t size, _Bool clear)
{
    void *p;
    if (clear) {
        p = calloc(1, size);
    } else {
        p = malloc(size);
    }
    if (!p)
 ErrorMsg(No_Mem, ERROR_MODULE_MEMORY, 1);
    else
 MemControl.allocated += size;
    return p;
}

canonical_original_code:
void *TCAllocMem(unsigned long size, _Bool clear)
{
    void *p;
    if (clear) {
        p = calloc(1, size);
    } else {
        p = malloc(size);
    }
    if (!p)
 ErrorMsg(No_Mem, ERROR_MODULE_MEMORY, 1);
    else
 MemControl.allocated += size;
    return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


memGetAllocatedMem

decompiled_code:
__int64 memGetAllocatedMem()
{
return MemControl;
}

canonical_decompiled_code:
__int64 func1()
{
return MemControl;
}

original_code:
ptrdiff_t memGetAllocatedMem(void)
{
    return MemControl.allocated;
}

canonical_original_code:
long memGetAllocatedMem()
{
    return MemControl.allocated;
}

return_type: long


TCFreeMem

decompiled_code:
void __fastcall TCFreeMem(void *a1, __int64 a2)
{
if ( a1 )
{
free(a1);
MemControl -= a2;
}
}

canonical_decompiled_code:
void __fastcall func2(void *a1, __int64 a2)
{
if ( a1 )
{
free(a1);
MemControl -= a2;
}
}

original_code:
void TCFreeMem(void *ptr, size_t size)
{
    if (ptr) {
 free(ptr);
 MemControl.allocated -= size;
    }
}

canonical_original_code:
void TCFreeMem(void *ptr, unsigned long size)
{
    if (ptr) {
 free(ptr);
 MemControl.allocated -= size;
    }
}

variable_types:
ptr
void *


plSaveChanged

decompiled_code:
void __fastcall plSaveChanged(unsigned int a1)
{
__int64 v1; // r12

if ( PlanChanged )
{
v1 = txtGoKey(11LL, "PLAN_CHANGED");
inpTurnESC(0LL);
if ( (unsigned __int8)Bubble(v1, 0LL, 0LL, 0LL) )
{
inpTurnESC(1LL);
RemoveList(v1);
}
else
{
inpTurnESC(1LL);
if ( !(unsigned __int8)plAllInCar(a1) )
plSay("PLAN_NOT_FINISHED", 0LL);
plSave(a1);
RemoveList(v1);
}
}
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1)
{
__int64 v1; // r12

if ( PlanChanged )
{
v1 = txtGoKey(11LL, "PLAN_CHANGED");
inpTurnESC(0LL);
if ( (unsigned __int8)Bubble(v1, 0LL, 0LL, 0LL) )
{
inpTurnESC(1LL);
RemoveList(v1);
}
else
{
inpTurnESC(1LL);
if ( !(unsigned __int8)plAllInCar(a1) )
plSay("PLAN_NOT_FINISHED", 0LL);
func3(a1);
RemoveList(v1);
}
}
}

original_code:
void plSaveChanged(U32 objId)
{
    if (PlanChanged) {
 LIST *l = txtGoKey(11U, "PLAN_CHANGED");
 inpTurnESC(0);
 if (Bubble(l, 0, ((void *)0), 0L) == 0) {
     inpTurnESC(1);
     if (!plAllInCar(objId))
  plSay("PLAN_NOT_FINISHED", 0);
     plSave(objId);
 } else
     inpTurnESC(1);
 RemoveList(l);
    }
}

canonical_original_code:
void plSaveChanged(unsigned int objId)
{
    if (PlanChanged) {
 struct List *l = txtGoKey(11U, "PLAN_CHANGED");
 inpTurnESC(0);
 if (Bubble(l, 0, ((void *)0), 0L) == 0) {
     inpTurnESC(1);
     if (!plAllInCar(objId))
  plSay("PLAN_NOT_FINISHED", 0);
     plSave(objId);
 } else
     inpTurnESC(1);
 RemoveList(l);
    }
}

variable_types:
objId
unsigned int

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


grdAddToList

decompiled_code:
__int64 __fastcall grdAddToList(unsigned int a1, __int64 a2)
{
__int64 v2; // rax
__int64 **v3; // rbx
__int64 result; // rax

SetObjectListAttr(3LL, 509991LL);
v2 = dbGetObject(a1);
AskAll(v2, 500003LL, &BuildObjectList);
v3 = (__int64 **)*ObjectList;
result = 0LL;
if ( *(_QWORD *)*ObjectList )
{
do
{
dbAddObjectNode(a2, *((unsigned int *)v3 + 8), 3LL);
v3 = (__int64 **)*v3;
}
while ( *v3 );
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2)
{
__int64 v2; // rax
__int64 **v3; // rbx
__int64 result; // rax

SetObjectListAttr(3LL, 509991LL);
v2 = dbGetObject(a1);
AskAll(v2, 500003LL, &BuildObjectList);
v3 = (__int64 **)*ObjectList;
result = 0LL;
if ( *(_QWORD *)*ObjectList )
{
do
{
dbAddObjectNode(a2, *((unsigned int *)v3 + 8), 3LL);
v3 = (__int64 **)*v3;
}
while ( *v3 );
result = 1LL;
}
return result;
}

original_code:
ubyte grdAddToList(U32 bldId, LIST * l)
{
    struct ObjectNode *n;
    { SetObjectListAttr ((1) | (1 << 1),509991L); AskAll (dbGetObject (bldId), 500003, BuildObjectList); };
    if (!(!(((NODE *)(((((NODE *)((&(((ObjectList)))->Head)))->Succ))))->Succ))) {
 for (n = (struct ObjectNode *) ((((NODE *)((&((ObjectList))->Head)))->Succ)); (((NODE *)(n))->Succ);
      n = (struct ObjectNode *) (((NODE *)(n))->Succ))
     dbAddObjectNode(l, (((struct ObjectNode *)n)->nr), (1) | (1 << 1));
 return 1;
    }
    return 0;
}

canonical_original_code:
unsigned char grdAddToList(unsigned int bldId, struct List *l)
{
    struct ObjectNode *n;
    { SetObjectListAttr ((1) | (1 << 1),509991L); AskAll (dbGetObject (bldId), 500003, BuildObjectList); };
    if (!(!(((struct Node *)(((((struct Node *)((&(((ObjectList)))->Head)))->Succ))))->Succ))) {
 for (n = (struct ObjectNode *) ((((struct Node *)((&((ObjectList))->Head)))->Succ)); (((struct Node *)(n))->Succ);
      n = (struct ObjectNode *) (((struct Node *)(n))->Succ))
     dbAddObjectNode(l, (((struct ObjectNode *)n)->nr), (1) | (1 << 1));
 return 1;
    }
    return 0;
}

variable_types:
bldId
unsigned int

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

return_type: unsigned char


repo: vdaras/Huffman-Compression

decompiled_code:
__int64 __fastcall binary_heap_get_parent(int a1)
{
return (unsigned int)((a1 - 1) / 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)((a1 - 1) / 2);
}

original_code:
static int binary_heap_get_parent(int node) {
    return (node - 1) / 2;
}

variable_types: node int

return_type: int


decompiled_code:
__int64 __fastcall binary_heap_get_left(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)(2 * a1 + 1);
}

original_code:
static int binary_heap_get_left(int node) {
    return node * 2 + 1;
}


decompiled_code:
__int64 __fastcall binary_heap_get_right(int a1)
{
return (unsigned int)(2 * a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (unsigned int)(2 * a1 + 2);
}

original_code:
static int binary_heap_get_right(int node) {
    return node * 2 + 2;
}


decompiled_code:
__int64 __fastcall binary_heap_increase_storage(__int64 a1)
{
int v1; // er12
int v4; // er12
void *v5; // rax
void *v6; // rax

v1 = *(_DWORD *)(a1 + 4);
if ( v1 )
{
if ( v1 > *(_DWORD *)a1 + 1 )
return 0;
v4 = 2 * v1;
v5 = realloc(*(void **)(a1 + 8), 8LL * v4);
if ( v5 )
{
*(_QWORD *)(a1 + 8) = v5;
*(_DWORD *)(a1 + 4) = v4;
return 0LL;
}
return (unsigned int)-1;
}
v6 = malloc(8uLL);
*(_QWORD *)(a1 + 8) = v6;
if ( !v6 )
return (unsigned int)-1;
*(_DWORD *)(a1 + 4) = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // er12
int v4; // er12
void *v5; // rax
void *v6; // rax

v1 = *(_DWORD *)(a1 + 4);
if ( v1 )
{
if ( v1 > *(_DWORD *)a1 + 1 )
return 0;
v4 = 2 * v1;
v5 = realloc(*(void **)(a1 + 8), 8LL * v4);
if ( v5 )
{
*(_QWORD *)(a1 + 8) = v5;
*(_DWORD *)(a1 + 4) = v4;
return 0LL;
}
return (unsigned int)-1;
}
v6 = malloc(8uLL);
*(_QWORD *)(a1 + 8) = v6;
if ( !v6 )
return (unsigned int)-1;
*(_DWORD *)(a1 + 4) = 1;
return 0LL;
}

original_code:
static int binary_heap_increase_storage(binary_heap* heap) {
    if(heap->storage_size == 0) {
        heap->tree = malloc(sizeof(void *));
        if(heap->tree == ((void *)0)) {
            return -1;
        }
        heap->storage_size = 1;
    } else {
        if(heap->size + 1 >= heap->storage_size) {
            int new_storage_size = heap->storage_size * 2;
            void **temp_storage = realloc(heap->tree, sizeof(void *) * new_storage_size);
            if(temp_storage == ((void *)0)) {
                return -1;
            }
            heap->tree = temp_storage;
            heap->storage_size = new_storage_size;
        }
    }
    return 0;
}

canonical_original_code:
static int binary_heap_increase_storage(struct binary_heap *heap) {
    if(heap->storage_size == 0) {
        heap->tree = malloc(sizeof(void *));
        if(heap->tree == ((void *)0)) {
            return -1;
        }
        heap->storage_size = 1;
    } else {
        if(heap->size + 1 >= heap->storage_size) {
            int new_storage_size = heap->storage_size * 2;
            void **temp_storage = realloc(heap->tree, sizeof(void *) * new_storage_size);
            if(temp_storage == ((void *)0)) {
                return -1;
            }
            heap->tree = temp_storage;
            heap->storage_size = new_storage_size;
        }
    }
    return 0;
}

variable_types: struct binary_heap { int size; int storage_size; void **tree; int (*comparator)(void *node1, void *node2); void (*destroy)(void *data); } *