decompiled_code:
__int64 __fastcall valid_placement(unsigned __int8 *a1)
{
unsigned __int8 v1; // dl
unsigned __int8 v2; // cl
__int64 result; // rax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

write_to_log("ships ahoy! Checking ship placement...");
v1 = a1[10];
if ( v1 > 9u || (v2 = a1[11], v2 > 9u) )
{
sprintf(v4, "Bad placement: x: %d, y: %d\n", v1, a1[11]);
write_to_log(v4);
result = 0LL;
}
else if ( a1[12] )
{
result = 0LL;
if ( v2 + a1[8] <= 10 )
{
LABEL_5:
sprintf(v4, "Good placement: x: %d, y: %d\n", v1, v2);
write_to_log(v4);
return 1LL;
}
}
else
{
result = 0LL;
if ( v1 + a1[8] <= 10 )
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1)
{
unsigned __int8 v1; // dl
unsigned __int8 v2; // cl
__int64 result; // rax
char v4[72]; // [rsp+0h] [rbp-48h] BYREF

write_to_log("ships ahoy! Checking ship placement...");
v1 = a1[10];
if ( v1 > 9u || (v2 = a1[11], v2 > 9u) )
{
sprintf(v4, "Bad placement: x: %d, y: %d\n", v1, a1[11]);
write_to_log(v4);
result = 0LL;
}
else if ( a1[12] )
{
result = 0LL;
if ( v2 + a1[8] <= 10 )
{
LABEL_5:
sprintf(v4, "Good placement: x: %d, y: %d\n", v1, v2);
write_to_log(v4);
return 1LL;
}
}
else
{
result = 0LL;
if ( v1 + a1[8] <= 10 )
goto LABEL_5;
}
return result;
}

original_code:
_Bool valid_placement(Ship *ship)
{
  char msg[50];
  write_to_log("ships ahoy! Checking ship placement...");
  if (ship->x < 0 || ship->y < 0 || ship->x > 10 -1 || ship->y > 10 -1) {
    sprintf(msg, "Bad placement: x: %d, y: %d\n", ship->x, ship->y);
    write_to_log(msg);
    return 0;
  }
  if (ship->direction) {
    if (ship->y + ship->size > 10) return 0;
  } else {
    if (ship->x + ship->size > 10) return 0;
  }
  sprintf(msg, "Good placement: x: %d, y: %d\n", ship->x, ship->y);
  write_to_log(msg);
  return 1;
}

canonical_original_code:
_Bool valid_placement(struct Ship_ *ship)
{
  char msg[50];
  write_to_log("ships ahoy! Checking ship placement...");
  if (ship->x < 0 || ship->y < 0 || ship->x > 10 -1 || ship->y > 10 -1) {
    sprintf(msg, "Bad placement: x: %d, y: %d\n", ship->x, ship->y);
    write_to_log(msg);
    return 0;
  }
  if (ship->direction) {
    if (ship->y + ship->size > 10) return 0;
  } else {
    if (ship->x + ship->size > 10) return 0;
  }
  sprintf(msg, "Good placement: x: %d, y: %d\n", ship->x, ship->y);
  write_to_log(msg);
  return 1;
}

variable_types: struct Ship_ { char *name; unsigned char size; unsigned char sunk; unsigned char x; unsigned char y; unsigned char direction; unsigned char slots[5]; } *

variable_types:
msg
char [50]


initShips

repo: mgalgs/termship

decompiled_code:
__int64 initShips()
{
char v0; // r12
int i; // ebp
int v2; // ebx
unsigned __int8 *v3; // r15
int j; // ebx
char *v5; // rbx
unsigned int k; // er15
__int64 result; // rax
char v8; // r14
int v9; // eax
__int64 v10; // rax
char v11; // dl
__int64 v12; // rdx
char v13; // [rsp+Eh] [rbp-12Ah]
char v14; // [rsp+Fh] [rbp-129h]
char v15[112]; // [rsp+10h] [rbp-128h] BYREF
char v16[8]; // [rsp+80h] [rbp-B8h] BYREF
__int64 v17; // [rsp+88h] [rbp-B0h]
__int64 v18; // [rsp+90h] [rbp-A8h]
__int64 v19; // [rsp+98h] [rbp-A0h]
__int64 v20; // [rsp+A0h] [rbp-98h]
__int64 v21; // [rsp+A8h] [rbp-90h]
__int16 v22; // [rsp+B0h] [rbp-88h]
char s[120]; // [rsp+C0h] [rbp-78h] BYREF

*(_QWORD *)v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0;
curs_set(0);
v0 = 0;
for ( i = 0; ; i = v2 )
{
v13 = *((_BYTE *)&Shipset + 24 * i + 10);
v14 = *((_BYTE *)&Shipset + 24 * i + 11);
v8 = *((_BYTE *)&Shipset + 24 * i + 12);
display_boards();
mvprintw(0, 1, "Use arrows to place ship, 'r' to rotate, space to select another ship.");
mvprintw(1, 1, "Press enter to finish. %s", v16);
mvprintw(2, 8, "Placing your \"%s\"", (&Shipset)[3 * i]);
echo();
v9 = wgetch(stdscr);
v16[0] = 0;
if ( v9 == 259 )
{
--*((_BYTE *)&Shipset + 24 * i + 11);
v2 = i;
goto LABEL_19;
}
if ( v9 > 259 )
{
if ( v9 == 261 )
{
++*((_BYTE *)&Shipset + 24 * i + 10);
v2 = i;
goto LABEL_19;
}
if ( v9 != 343 )
{
if ( v9 == 260 )
--*((_BYTE *)&Shipset + 24 * i + 10);
v2 = i;
LABEL_19:
result = valid_placement((unsigned __int8 *)&(&Shipset)[3 * i]);
if ( (_BYTE)result )
goto LABEL_20;
goto LABEL_44;
}
}
else
{
if ( v9 == 114 )
{
*((_BYTE *)&Shipset + 24 * i + 12) = *((_BYTE *)&Shipset + 24 * i + 12) == 0;
v2 = i;
goto LABEL_19;
}
if ( v9 > 114 )
{
v2 = i;
if ( v9 == 258 )
++*((_BYTE *)&Shipset + 24 * i + 11);
goto LABEL_19;
}
if ( v9 != 10 )
{
if ( v9 == 32 )
{
v2 = 0;
if ( i != 4 )
v2 = i + 1;
}
else
{
v2 = i;
}
goto LABEL_19;
}
}
write_to_log("maybe continuing...\n");
v3 = (unsigned __int8 *)&Shipset;
for ( j = 0; j != 5; ++j )
{
v0 = valid_placement(v3);
if ( !v0 )
{
sprintf(s, "%s hasn't been placed yet", (&Shipset)[3 * j]);
show_message_box(s);
sleep(2u);
goto LABEL_41;
}
v3 += 24;
}
create_grid((__int64)v15, (__int64)&Shipset);
v5 = v15;
for ( k = 0; k != 10; ++k )
{
v10 = 0LL;
while ( 1 )
{
v11 = v5[v10];
if ( v11 != 42 && v11 != 95 )
break;
if ( ++v10 == 10 )
goto LABEL_35;
}
sprintf(s, "Can't continue, there's an overlap at: %d,%d\n", k, (unsigned int)v10);
write_to_log(s);
strcpy(s, "There are overlapping pieces");
v0 = 0;
LABEL_35:
v5 += 10;
}
if ( v0 )
{
result = valid_placement((unsigned __int8 *)&(&Shipset)[3 * i]);
if ( (_BYTE)result )
return result;
v2 = i;
goto LABEL_44;
}
sprintf(v16, "[Can't continue: %s]", s);
show_message_box(v16);
sleep(2u);
write_to_log("Can't continue! Not all ships in valid locations.\n");
LABEL_41:
v2 = i;
if ( (unsigned __int8)valid_placement((unsigned __int8 *)&(&Shipset)[3 * i]) )
continue;
LABEL_44:
write_to_log("Undoing changes because of bad placement...\n");
result = 2LL * i;
v12 = 3LL * i;
*((_BYTE *)&Shipset + 8 * v12 + 10) = v13;
*((_BYTE *)&Shipset + 8 * v12 + 11) = v14;
*((_BYTE *)&Shipset + 8 * v12 + 12) = v8;
LABEL_20:
if ( v0 )
break;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
char v0; // r12
int i; // ebp
int v2; // ebx
unsigned __int8 *v3; // r15
int j; // ebx
char *v5; // rbx
unsigned int k; // er15
__int64 result; // rax
char v8; // r14
int v9; // eax
__int64 v10; // rax
char v11; // dl
__int64 v12; // rdx
char v13; // [rsp+Eh] [rbp-12Ah]
char v14; // [rsp+Fh] [rbp-129h]
char v15[112]; // [rsp+10h] [rbp-128h] BYREF
char v16[8]; // [rsp+80h] [rbp-B8h] BYREF
__int64 v17; // [rsp+88h] [rbp-B0h]
__int64 v18; // [rsp+90h] [rbp-A8h]
__int64 v19; // [rsp+98h] [rbp-A0h]
__int64 v20; // [rsp+A0h] [rbp-98h]
__int64 v21; // [rsp+A8h] [rbp-90h]
__int16 v22; // [rsp+B0h] [rbp-88h]
char s[120]; // [rsp+C0h] [rbp-78h] BYREF

*(_QWORD *)v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0LL;
v22 = 0;
curs_set(0);
v0 = 0;
for ( i = 0; ; i = v2 )
{
v13 = *((_BYTE *)&Shipset + 24 * i + 10);
v14 = *((_BYTE *)&Shipset + 24 * i + 11);
v8 = *((_BYTE *)&Shipset + 24 * i + 12);
display_boards();
mvprintw(0, 1, "Use arrows to place ship, 'r' to rotate, space to select another ship.");
mvprintw(1, 1, "Press enter to finish. %s", v16);
mvprintw(2, 8, "Placing your \"%s\"", (&Shipset)[3 * i]);
echo();
v9 = wgetch(stdscr);
v16[0] = 0;
if ( v9 == 259 )
{
--*((_BYTE *)&Shipset + 24 * i + 11);
v2 = i;
goto LABEL_19;
}
if ( v9 > 259 )
{
if ( v9 == 261 )
{
++*((_BYTE *)&Shipset + 24 * i + 10);
v2 = i;
goto LABEL_19;
}
if ( v9 != 343 )
{
if ( v9 == 260 )
--*((_BYTE *)&Shipset + 24 * i + 10);
v2 = i;
LABEL_19:
result = func4((unsigned __int8 *)&(&Shipset)[3 * i]);
if ( (_BYTE)result )
goto LABEL_20;
goto LABEL_44;
}
}
else
{
if ( v9 == 114 )
{
*((_BYTE *)&Shipset + 24 * i + 12) = *((_BYTE *)&Shipset + 24 * i + 12) == 0;
v2 = i;
goto LABEL_19;
}
if ( v9 > 114 )
{
v2 = i;
if ( v9 == 258 )
++*((_BYTE *)&Shipset + 24 * i + 11);
goto LABEL_19;
}
if ( v9 != 10 )
{
if ( v9 == 32 )
{
v2 = 0;
if ( i != 4 )
v2 = i + 1;
}
else
{
v2 = i;
}
goto LABEL_19;
}
}
write_to_log("maybe continuing...\n");
v3 = (unsigned __int8 *)&Shipset;
for ( j = 0; j != 5; ++j )
{
v0 = func4(v3);
if ( !v0 )
{
sprintf(s, "%s hasn't been placed yet", (&Shipset)[3 * j]);
show_message_box(s);
sleep(2u);
goto LABEL_41;
}
v3 += 24;
}
func0((__int64)v15, (__int64)&Shipset);
v5 = v15;
for ( k = 0; k != 10; ++k )
{
v10 = 0LL;
while ( 1 )
{
v11 = v5[v10];
if ( v11 != 42 && v11 != 95 )
break;
if ( ++v10 == 10 )
goto LABEL_35;
}
sprintf(s, "Can't continue, there's an overlap at: %d,%d\n", k, (unsigned int)v10);
write_to_log(s);
strcpy(s, "There are overlapping pieces");
v0 = 0;
LABEL_35:
v5 += 10;
}
if ( v0 )
{
result = func4((unsigned __int8 *)&(&Shipset)[3 * i]);
if ( (_BYTE)result )
return result;
v2 = i;
goto LABEL_44;
}
sprintf(v16, "[Can't continue: %s]", s);
show_message_box(v16);
sleep(2u);
write_to_log("Can't continue! Not all ships in valid locations.\n");
LABEL_41:
v2 = i;
if ( (unsigned __int8)func4((unsigned __int8 *)&(&Shipset)[3 * i]) )
continue;
LABEL_44:
write_to_log("Undoing changes because of bad placement...\n");
result = 2LL * i;
v12 = 3LL * i;
*((_BYTE *)&Shipset + 8 * v12 + 10) = v13;
*((_BYTE *)&Shipset + 8 * v12 + 11) = v14;
*((_BYTE *)&Shipset + 8 * v12 + 12) = v8;
LABEL_20:
if ( v0 )
break;
}
return result;
}

original_code:
void initShips()
{
  int i,j;
  int ch;
  int current_editing_ship = 0;
  int origx, origy, origdir;
  Ship *curship;
  _Bool done = 0;
  int scratch=0;
  char msg[50];
  char extramsg[50] = "";
  char players_grid[10][10];
  curs_set(0);
  while (!done) {
    scratch++;
    curship = &(Shipset[current_editing_ship]);
    origx = curship->x;
    origy = curship->y;
    origdir = curship->direction;
    display_boards();
    mvprintw(0,1,"Use arrows to place ship, 'r' to rotate, space to select another ship.");
    mvprintw(1,1,"Press enter to finish. %s", extramsg);
    mvprintw(2,8, "Placing your \"%s\"", curship->name);
    echo();
    ch = wgetch(stdscr);
    strcpy(extramsg, "");
    switch (ch) {
    case 0402:
      curship->y++;
      break;
    case 0403:
      curship->y--;
      break;
    case 0404:
      curship->x--;
      break;
    case 0405:
      curship->x++;
      break;
    case ' ':
      current_editing_ship = current_editing_ship == 5 -1 ? 0 : current_editing_ship+1;
      break;
    case 'r':
      curship->direction = !curship->direction;
      break;
    case 10:
    case 0527:
      write_to_log("maybe continuing...\n");
      done = 1;
      for (i=0; i<5; i++) {
 if (!valid_placement(&(Shipset[i]))) {
   sprintf(msg, "%s hasn't been placed yet", Shipset[i].name);
   show_message_box(msg);
   sleep(2);
   done = 0;
   break;
 }
      }
      if (!done) break;
      create_grid(players_grid, Shipset);
      for (i=0; i<10; ++i) {
 for (j=0; j<10; ++j) {
   if (players_grid[i][j] != '*' && players_grid[i][j] != '_' ) {
     sprintf(msg, "Can't continue, there's an overlap at: %d,%d\n", i, j);
     write_to_log(msg);
     strcpy(msg, "There are overlapping pieces");
     done = 0;
     break;
   }
 }
      }
      if (!done) {
 sprintf(extramsg,"[Can't continue: %s]", msg);
 show_message_box(extramsg);
 sleep(2);
 write_to_log("Can't continue! Not all ships in valid locations.\n");
      }
      break;
    }
    if (!valid_placement(curship)) {
      write_to_log("Undoing changes because of bad placement...\n");
      curship->x = origx;
      curship->y = origy;
      curship->direction = origdir;
    }
  }
}

canonical_original_code:
void initShips()
{
  int i; int j;
  int ch;
  int current_editing_ship = 0;
  int origx; int origy; int origdir;
  struct Ship_ *curship;
  _Bool done = 0;
  int scratch = 0;
  char msg[50];
  char extramsg[50] = "";
  char players_grid[10][10];
  curs_set(0);
  while (!done) {
    scratch++;
    curship = &(Shipset[current_editing_ship]);
    origx = curship->x;
    origy = curship->y;
    origdir = curship->direction;
    display_boards();
    mvprintw(0,1,"Use arrows to place ship, 'r' to rotate, space to select another ship.");
    mvprintw(1,1,"Press enter to finish. %s", extramsg);
    mvprintw(2,8, "Placing your \"%s\"", curship->name);
    echo();
    ch = wgetch(stdscr);
    strcpy(extramsg, "");
    switch (ch) {
    case 0402:
      curship->y++;
      break;
    case 0403:
      curship->y--;
      break;
    case 0404:
      curship->x--;
      break;
    case 0405:
      curship->x++;
      break;
    case ' ':
      current_editing_ship = current_editing_ship == 5 -1 ? 0 : current_editing_ship+1;
      break;
    case 'r':
      curship->direction = !curship->direction;
      break;
    case 10:
    case 0527:
      write_to_log("maybe continuing...\n");
      done = 1;
      for (i=0; i<5; i++) {
 if (!valid_placement(&(Shipset[i]))) {
   sprintf(msg, "%s hasn't been placed yet", Shipset[i].name);
   show_message_box(msg);
   sleep(2);
   done = 0;
   break;
 }
      }
      if (!done) break;
      create_grid(players_grid, Shipset);
      for (i=0; i<10; ++i) {
 for (j=0; j<10; ++j) {
   if (players_grid[i][j] != '*' && players_grid[i][j] != '_' ) {
     sprintf(msg, "Can't continue, there's an overlap at: %d,%d\n", i, j);
     write_to_log(msg);
     strcpy(msg, "There are overlapping pieces");
     done = 0;
     break;
   }
 }
      }
      if (!done) {
 sprintf(extramsg,"[Can't continue: %s]", msg);
 show_message_box(extramsg);
 sleep(2);
 write_to_log("Can't continue! Not all ships in valid locations.\n");
      }
      break;
    }
    if (!valid_placement(curship)) {
      write_to_log("Undoing changes because of bad placement...\n");
      curship->x = origx;
      curship->y = origy;
      curship->direction = origdir;
    }
  }
}

variable_types: i int

variable_types: j int

variable_types: ch int

variable_types: origx int

variable_types: origy int

variable_types: origdir int

variable_types: scratch int

variable_types:
extramsg
char [50]

return_type: void

user_defined_types: struct Ship_ { char *name; unsigned char size; unsigned char sunk; unsigned char x; unsigned char y; unsigned char direction; unsigned char slots[5]; }


printShips

decompiled_code:
int printShips()
{
__int64 i; // rbp
__int64 v1; // rbx

scr_dump(".Bstatesave");
wclear(stdscr);
wrefresh(stdscr);
for ( i = 0LL; i != 15; i += 3LL )
{
printw("%s: ", (&Shipset)[i]);
if ( LOBYTE((&Shipset)[i + 1]) )
{
v1 = 0LL;
do
printw("%d", *((unsigned __int8 *)&Shipset + i * 8 + v1++ + 13));
while ( LOBYTE((&Shipset)[i + 1]) > (int)v1 );
}
printw("\n");
}
printw("\nPress any key to continue\n");
wrefresh(stdscr);
wgetch(stdscr);
return scr_restore(".Bstatesave");
}

canonical_decompiled_code:
int func6()
{
__int64 i; // rbp
__int64 v1; // rbx

scr_dump(".Bstatesave");
wclear(stdscr);
wrefresh(stdscr);
for ( i = 0LL; i != 15; i += 3LL )
{
printw("%s: ", (&Shipset)[i]);
if ( LOBYTE((&Shipset)[i + 1]) )
{
v1 = 0LL;
do
printw("%d", *((unsigned __int8 *)&Shipset + i * 8 + v1++ + 13));
while ( LOBYTE((&Shipset)[i + 1]) > (int)v1 );
}
printw("\n");
}
printw("\nPress any key to continue\n");
wrefresh(stdscr);
wgetch(stdscr);
return scr_restore(".Bstatesave");
}

original_code:
void printShips()
{
  int i,j;
  scr_dump(".Bstatesave");
  wclear(stdscr);
  wrefresh(stdscr);
  for (i=0; i<5; i++) {
    printw("%s: ", Shipset[i].name);
    for (j=0; j<Shipset[i].size; j++)
      printw("%d",Shipset[i].slots[j]);
    printw("\n");
  }
  printw("\nPress any key to continue\n");
  wrefresh(stdscr);
  wgetch(stdscr);
  scr_restore(".Bstatesave");
}

canonical_original_code:
void printShips()
{
  int i; int j;
  scr_dump(".Bstatesave");
  wclear(stdscr);
  wrefresh(stdscr);
  for (i=0; i<5; i++) {
    printw("%s: ", Shipset[i].name);
    for (j=0; j<Shipset[i].size; j++)
      printw("%d",Shipset[i].slots[j]);
    printw("\n");
  }
  printw("\nPress any key to continue\n");
  wrefresh(stdscr);
  wgetch(stdscr);
  scr_restore(".Bstatesave");
}


Init

decompiled_code:
__int64 __fastcall Init(_DWORD *a1, int a2)
{
__int64 result; // rax

if ( a2 > 512 )
{
*a1 = 1024;
result = Skein1024_Init(a1 + 2, a2);
}
else
{
*a1 = 512;
result = Skein_512_Init(a1 + 2, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, int a2)
{
__int64 result; // rax

if ( a2 > 512 )
{
*a1 = 1024;
result = Skein1024_Init(a1 + 2, a2);
}
else
{
*a1 = 512;
result = Skein_512_Init(a1 + 2, a2);
}
return result;
}

original_code:
HashReturn Init(hashState *state, int hashbitlen)
    {
    if (hashbitlen <= (512))
        {
        state->statebits = 64*( 8);
        return Skein_512_Init(&state->u.ctx_512,(size_t) hashbitlen);
        }
    else
        {
        state->statebits = 64*(16);
        return Skein1024_Init(&state->u.ctx1024,(size_t) hashbitlen);
        }
    }

canonical_original_code:
enum HashReturn Init(struct hashState *state, int hashbitlen)
    {
    if (hashbitlen <= (512))
        {
        state->statebits = 64*( 8);
        return Skein_512_Init(&state->u.ctx_512,(unsigned long) hashbitlen);
        }
    else
        {
        state->statebits = 64*(16);
        return Skein1024_Init(&state->u.ctx1024,(unsigned long) hashbitlen);
        }
    }

variable_types: struct hashState { unsigned int statebits; union { struct Skein_Ctxt_Hdr_t { unsigned long hashBitLen; unsigned long bCnt; unsigned long T[-1]; } h; struct Skein_256_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; } ctx_256; struct Skein_512_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; } ctx_512; struct Skein1024_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; } ctx1024; } u; } *

variable_types: hashbitlen int

return_type: enum HashReturn { SUCCESS=expr, FAIL=expr, BAD_HASHLEN=expr }

user_defined_types: struct hashState { unsigned int statebits; union { struct Skein_Ctxt_Hdr_t h; struct Skein_256_Ctxt_t ctx_256; struct Skein_512_Ctxt_t ctx_512; struct Skein1024_Ctxt_t ctx1024; } u; }


Update

original_code:
HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen)
    {
    ;
    ;
    if ((databitlen & 7) == 0)
        {
        switch ((state->statebits >> 8) & 3)
            {
            case 2: return Skein_512_Update(&state->u.ctx_512,data,databitlen >> 3);
            case 1: return Skein_256_Update(&state->u.ctx_256,data,databitlen >> 3);
            case 0: return Skein1024_Update(&state->u.ctx1024,data,databitlen >> 3);
            default: return FAIL;
            }
        }
    else
        {
        size_t bCnt = (databitlen >> 3) + 1;
        u08b_t b,mask;
        mask = (u08b_t) (1u << (7 - (databitlen & 7)));
        b = (u08b_t) ((data[bCnt-1] & (0-mask)) | mask);
        switch ((state->statebits >> 8) & 3)
            {
            case 2: Skein_512_Update(&state->u.ctx_512,data,bCnt-1);
                     Skein_512_Update(&state->u.ctx_512,&b , 1 );
                     break;
            case 1: Skein_256_Update(&state->u.ctx_256,data,bCnt-1);
                     Skein_256_Update(&state->u.ctx_256,&b , 1 );
                     break;
            case 0: Skein1024_Update(&state->u.ctx1024,data,bCnt-1);
                     Skein1024_Update(&state->u.ctx1024,&b , 1 );
                     break;
            default: return FAIL;
            }
        { (state->u.h).T[1] |= (((u64b_t) 1 ) << ((119) - 64)); };
        return SUCCESS;
        }
    }

canonical_original_code:
enum HashReturn Update(struct hashState *state, unsigned char *data, unsigned long databitlen)
    {
    ;
    ;
    if ((databitlen & 7) == 0)
        {
        switch ((state->statebits >> 8) & 3)
            {
            case 2: return Skein_512_Update(&state->u.ctx_512,data,databitlen >> 3);
            case 1: return Skein_256_Update(&state->u.ctx_256,data,databitlen >> 3);
            case 0: return Skein1024_Update(&state->u.ctx1024,data,databitlen >> 3);
            default: return FAIL;
            }
        }
    else
        {
        unsigned long bCnt = (databitlen >> 3) + 1;
        unsigned char b; unsigned char mask;
        mask = (u08b_t) (1u << (7 - (databitlen & 7)));
        b = (u08b_t) ((data[bCnt-1] & (0-mask)) | mask);
        switch ((state->statebits >> 8) & 3)
            {
            case 2: Skein_512_Update(&state->u.ctx_512,data,bCnt-1);
                     Skein_512_Update(&state->u.ctx_512,&b , 1 );
                     break;
            case 1: Skein_256_Update(&state->u.ctx_256,data,bCnt-1);
                     Skein_256_Update(&state->u.ctx_256,&b , 1 );
                     break;
            case 0: Skein1024_Update(&state->u.ctx1024,data,bCnt-1);
                     Skein1024_Update(&state->u.ctx1024,&b , 1 );
                     break;
            default: return FAIL;
            }
        { (state->u.h).T[1] |= (((unsigned long) 1 ) << ((119) - 64)); };
        return SUCCESS;
        }
    }

variable_types:
data
unsigned char *

variable_types:
databitlen
unsigned long

variable_types:
bCnt
unsigned long

variable_types:
b
unsigned char

variable_types:
mask
unsigned char

user_defined_types: enum HashReturn { SUCCESS=expr, FAIL=expr, BAD_HASHLEN=expr }

user_defined_types: struct Skein_Ctxt_Hdr_t { unsigned long hashBitLen; unsigned long bCnt; unsigned long T[-1]; }

user_defined_types: struct Skein_256_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; }

user_defined_types: struct Skein_512_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; }

user_defined_types: struct Skein1024_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; }


Final

decompiled_code:
__int64 __fastcall Final(_DWORD *a1)
{
int v1; // eax

v1 = (*a1 >> 8) & 3;
if ( v1 == 1 )
return Skein_256_Final(a1 + 2);
if ( v1 == 2 )
return Skein_512_Final(a1 + 2);
if ( v1 )
return 1LL;
return Skein1024_Final(a1 + 2);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
int v1; // eax

v1 = (*a1 >> 8) & 3;
if ( v1 == 1 )
return Skein_256_Final(a1 + 2);
if ( v1 == 2 )
return Skein_512_Final(a1 + 2);
if ( v1 )
return 1LL;
return Skein1024_Final(a1 + 2);
}

original_code:
HashReturn Final(hashState *state, BitSequence *hashval)
    {
    ;
    switch ((state->statebits >> 8) & 3)
        {
        case 2: return Skein_512_Final(&state->u.ctx_512,hashval);
        case 1: return Skein_256_Final(&state->u.ctx_256,hashval);
        case 0: return Skein1024_Final(&state->u.ctx1024,hashval);
        default: return FAIL;
        }
    }

canonical_original_code:
enum HashReturn Final(struct hashState *state, unsigned char *hashval)
    {
    ;
    switch ((state->statebits >> 8) & 3)
        {
        case 2: return Skein_512_Final(&state->u.ctx_512,hashval);
        case 1: return Skein_256_Final(&state->u.ctx_256,hashval);
        case 0: return Skein1024_Final(&state->u.ctx1024,hashval);
        default: return FAIL;
        }
    }

variable_types:
hashval
unsigned char *


Hash

decompiled_code:
__int64 __fastcall Hash(int a1, __int64 a2, unsigned __int64 a3)
{
unsigned int v4; // ebx
_DWORD v6[86]; // [rsp+0h] [rbp-158h] BYREF

v4 = Init(v6, a1);
if ( !v4 )
{
v4 = Update((__int64)v6, a2, a3);
Final(v6);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2, unsigned __int64 a3)
{
unsigned int v4; // ebx
_DWORD v6[86]; // [rsp+0h] [rbp-158h] BYREF

v4 = func0(v6, a1);
if ( !v4 )
{
v4 = func1((__int64)v6, a2, a3);
func2(v6);
}
return v4;
}

original_code:
HashReturn Hash(int hashbitlen, const BitSequence *data,
                DataLength databitlen,BitSequence *hashval)
    {
    hashState state;
    HashReturn r = Init(&state,hashbitlen);
    if (r == SUCCESS)
        {
        r = Update(&state,data,databitlen);
        Final(&state,hashval);
        }
    return r;
    }

canonical_original_code:
enum HashReturn Hash(int hashbitlen, unsigned char *data, unsigned long databitlen, unsigned char *hashval)
    {
    struct hashState state;
    enum HashReturn r = Init(&state,hashbitlen);
    if (r == SUCCESS)
        {
        r = Update(&state,data,databitlen);
        Final(&state,hashval);
        }
    return r;
    }

variable_types: struct hashState { unsigned int statebits; union { struct Skein_Ctxt_Hdr_t { unsigned long hashBitLen; unsigned long bCnt; unsigned long T[-1]; } h; struct Skein_256_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; } ctx_256; struct Skein_512_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; } ctx_512; struct Skein1024_Ctxt_t { struct Skein_Ctxt_Hdr_t h; unsigned long X[-1]; unsigned char b[-1]; } ctx1024; } u; }

variable_types: enum HashReturn { SUCCESS=expr, FAIL=expr, BAD_HASHLEN=expr }


decompiled_code:
__int64 __fastcall get_hash(char *s, __int64 a2)
{
size_t v2; // rax
_BYTE v4[312]; // [rsp+0h] [rbp-138h] BYREF

Skein1024_Init(v4, 1024LL);
v2 = strlen(s);
Skein1024_Update(v4, s, v2);
return Skein1024_Final(v4, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, __int64 a2)
{
size_t v2; // rax
_BYTE v4[312]; // [rsp+0h] [rbp-138h] BYREF

Skein1024_Init(v4, 1024LL);
v2 = strlen(s);
Skein1024_Update(v4, s, v2);
return Skein1024_Final(v4, a2);
}

original_code:
static void get_hash(u08b_t *inbuf, u08b_t *outbuf)
{
        Skein1024_Ctxt_t ctx;
        Skein1024_Init(&ctx, 1024);
        Skein1024_Update(&ctx, inbuf, strlen((char *)inbuf));
        Skein1024_Final(&ctx, outbuf);
}

canonical_original_code:
static void get_hash(unsigned char *inbuf, unsigned char *outbuf)
{
        struct Skein1024_Ctxt_t ctx;
        Skein1024_Init(&ctx, 1024);
        Skein1024_Update(&ctx, inbuf, strlen((char *)inbuf));
        Skein1024_Final(&ctx, outbuf);
}

variable_types:
inbuf
unsigned char *

variable_types:
outbuf
unsigned char *

variable_types: struct Skein1024_Ctxt_t { struct Skein_Ctxt_Hdr_t { unsigned long hashBitLen; unsigned long bCnt; unsigned long T[-1]; } h; unsigned long X[-1]; unsigned char b[-1]; }


decompiled_code:
__int64 get_random_char()
{
return (unsigned __int8)byte_398[rand() % 98];
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned __int8)byte_398[rand() % 98];
}

original_code:
static const char get_random_char()
{
        return candidate_chars[rand() % candidate_chars_len];
}

canonical_original_code:
static char get_random_char()
{
        return candidate_chars[rand() % candidate_chars_len];
}

return_type: char


sendit

decompiled_code:
int __fastcall sendit(char *a1)
{
char v2[1008]; // [rsp+0h] [rbp-BC8h] BYREF
char s[2008]; // [rsp+3F0h] [rbp-7D8h] BYREF

shellquote(a1, v2);
sprintf(s, "%s %s", "../sendit.sh", v2);
puts("will run:");
puts(s);
return system(s);
}

canonical_decompiled_code:
int __fastcall func3(char *a1)
{
char v2[1008]; // [rsp+0h] [rbp-BC8h] BYREF
char s[2008]; // [rsp+3F0h] [rbp-7D8h] BYREF

shellquote(a1, v2);
sprintf(s, "%s %s", "../sendit.sh", v2);
puts("will run:");
puts(s);
return system(s);
}

original_code:
static void sendit(const u08b_t * const buf)
{
        char cmd[2000];
        u08b_t msg[(1000 + 1)];
        shellquote(buf, &msg[0]);
        sprintf(cmd, "%s %s", "../sendit.sh", msg);
        puts("will run:");
        puts(cmd);
        system(cmd);
}

canonical_original_code:
static void sendit(unsigned char *buf)
{
        char cmd[2000];
        unsigned char msg[-1];
        shellquote(buf, &msg[0]);
        sprintf(cmd, "%s %s", "../sendit.sh", msg);
        puts("will run:");
        puts(cmd);
        system(cmd);
}

variable_types:
buf
unsigned char *

variable_types:
cmd
char [2000]

variable_types:
msg
unsigned char [-1]


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
int v4; // er15
int v5; // er14
char *v6; // r13
int v7; // er12
void *v8; // rsi
unsigned __int8 *v9; // rdi
int v10; // eax
unsigned int v11; // ebx
char *v12; // rbp
unsigned int i; // [rsp+Ch] [rbp-4ACh]
unsigned __int8 v14[128]; // [rsp+10h] [rbp-4A8h] BYREF
char s; // [rsp+90h] [rbp-428h] BYREF
char v16; // [rsp+91h] [rbp-427h] BYREF

v3 = (const char *)time(0LL);
srand((unsigned int)v3);
v4 = 411;
v5 = 1025;
for ( i = 0; ; printf("\r%d hashes compared. Best so far is %d ", i, (unsigned int)v5) )
{
s = get_random_char(v3, argv);
v16 = 0;
v7 = 1000;
v6 = &v16;
do
{
get_hash(&s, (__int64)v14);
v8 = ⌖
v9 = v14;
v10 = get_bit_diff((__int64)v14, (__int64)&target, 128LL);
v11 = v10;
v12 = v6;
if ( v10 < v5 )
{
v5 = v10;
v12 = &s;
if ( v10 < v4 )
{
puts("\n\nNew best hash found!");
puts("---BEGIN STRING:---");
puts(&s);
puts("---END STRING---");
printf("(should be off by %d)\n", v11);
puts("hex digest of computed hash:");
v8 = &loc_7F + 1;
print_hash_hex_digest(v14, 128LL);
puts("Now attempting to upload to the xkcd server...");
sendit(&s);
v9 = "Done!";
puts("Done!");
v4 = v11;
}
}
v6 = v12 + 1;
*(_WORD *)v12 = (unsigned __int8)get_random_char(v9, v8);
--v7;
}
while ( v7 );
i += 1000;
argv = (const char **)i;
v3 = "\r%d hashes compared. Best so far is %d ";
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi
int v4; // er15
int v5; // er14
char *v6; // r13
int v7; // er12
void *v8; // rsi
unsigned __int8 *v9; // rdi
int v10; // eax
unsigned int v11; // ebx
char *v12; // rbp
unsigned int i; // [rsp+Ch] [rbp-4ACh]
unsigned __int8 v14[128]; // [rsp+10h] [rbp-4A8h] BYREF
char s; // [rsp+90h] [rbp-428h] BYREF
char v16; // [rsp+91h] [rbp-427h] BYREF

v3 = (const char *)time(0LL);
srand((unsigned int)v3);
v4 = 411;
v5 = 1025;
for ( i = 0; ; printf("\r%d hashes compared. Best so far is %d ", i, (unsigned int)v5) )
{
s = func4(v3, argv);
v16 = 0;
v7 = 1000;
v6 = &v16;
do
{
func1(&s, (__int64)v14);
v8 = ⌖
v9 = v14;
v10 = func0((__int64)v14, (__int64)&target, 128LL);
v11 = v10;
v12 = v6;
if ( v10 < v5 )
{
v5 = v10;
v12 = &s;
if ( v10 < v4 )
{
puts("\n\nNew best hash found!");
puts("---BEGIN STRING:---");
puts(&s);
puts("---END STRING---");
printf("(should be off by %d)\n", v11);
puts("hex digest of computed hash:");
v8 = &loc_7F + 1;
func2(v14, 128LL);
puts("Now attempting to upload to the xkcd server...");
func3(&s);
v9 = "Done!";
puts("Done!");
v4 = v11;
}
}
v6 = v12 + 1;
*(_WORD *)v12 = (unsigned __int8)func4(v9, v8);
--v7;
}
while ( v7 );
i += 1000;
argv = (const char **)i;
v3 = "\r%d hashes compared. Best so far is %d ";
}
}

original_code:
int main(int argc, char *argv[])
{
        int nattempts = 0, n, best = 1025, threshold = 411;
        u08b_t inbuf[(1000 + 1)], hashbuf[128];
        u08b_t *iter;
        srand(time(((void *)0)));
        for (;;) {
                iter = &inbuf[0];
                *iter++ = get_random_char();
                *iter = '\0';
                for (n = 0; n < 1000; ++n) {
                        int nbits;
                        get_hash(inbuf, hashbuf);
                        nbits = get_bit_diff(hashbuf, target, 128);
                        if (nbits < best) {
                                best = nbits;
                                iter = &inbuf[0];
                                if (nbits < threshold) {
                                        puts("\n\nNew best hash found!");
                                        puts("---BEGIN STRING:---");
                                        puts((char *)inbuf);
                                        puts("---END STRING---");
                                        printf("(should be off by %d)\n", nbits);
                                        puts("hex digest of computed hash:");
                                        print_hash_hex_digest(hashbuf, 128);
                                        threshold = nbits;
                                        puts("Now attempting to upload to the xkcd server...");
                                        sendit(inbuf);
                                        puts("Done!");
                                }
                        }
                        *iter++ = get_random_char();
                        *iter = '\0';
                        nattempts++;
                }
                printf("\r%d hashes compared. Best so far is %d       ",
                       nattempts, best);
        }
        return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
        int nattempts = 0; int n; int best = 1025; int threshold = 411;
        unsigned char inbuf[-1]; unsigned char hashbuf[128];
        unsigned char *iter;
        srand(time(((void *)0)));
        for (;;) {
                iter = &inbuf[0];
                *iter++ = get_random_char();
                *iter = '\0';
                for (n = 0; n < 1000; ++n) {
                        int nbits;
                        get_hash(inbuf, hashbuf);
                        nbits = get_bit_diff(hashbuf, target, 128);
                        if (nbits < best) {
                                best = nbits;
                                iter = &inbuf[0];
                                if (nbits < threshold) {
                                        puts("\n\nNew best hash found!");
                                        puts("---BEGIN STRING:---");
                                        puts((char *)inbuf);
                                        puts("---END STRING---");
                                        printf("(should be off by %d)\n", nbits);
                                        puts("hex digest of computed hash:");
                                        print_hash_hex_digest(hashbuf, 128);
                                        threshold = nbits;
                                        puts("Now attempting to upload to the xkcd server...");
                                        sendit(inbuf);
                                        puts("Done!");
                                }
                        }
                        *iter++ = get_random_char();
                        *iter = '\0';
                        nattempts++;
                }
                printf("\r%d hashes compared. Best so far is %d       ",
                       nattempts, best);
        }
        return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nattempts int

variable_types: n int

variable_types: best int

variable_types: threshold int

variable_types:
inbuf
unsigned char [-1]

variable_types:
hashbuf
unsigned char [128]

variable_types:
iter
unsigned char *

variable_types: nbits int

return_type: int


repo: mgius/zork

decompiled_code:
void __noreturn exit_()
{
fwrite("The game is over.\n", 1uLL, 0x12uLL, stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("The game is over.\n", 1uLL, 0x12uLL, stderr);
exit(0);
}

original_code:
void exit_()
{
    fprintf(stderr, "The game is over.\n");
    exit(0);
}


decompiled_code:
int more_init()
{
char *v0; // rax
char v2[2056]; // [rsp+0h] [rbp-808h] BYREF

v0 = getenv("TERM");
if ( v0 )
{
tgetent(v2, v0);
LODWORD(v0) = tgetnum("li");
crows = (int)v0;
}
else
{
crows = 0;
}
return (int)v0;
}

canonical_decompiled_code:
int func3()
{
char *v0; // rax
char v2[2056]; // [rsp+0h] [rbp-808h] BYREF

v0 = getenv("TERM");
if ( v0 )
{
tgetent(v2, v0);
LODWORD(v0) = tgetnum("li");
crows = (int)v0;
}
else
{
crows = 0;
}
return (int)v0;
}

original_code:
void more_init()
{
    char buf[2048];
    char *term;
    term = getenv("TERM");
    if (term == ((void *)0))
 crows = 0;
    else {
 tgetent(buf, term);
 crows = tgetnum("li");
    }
}

variable_types:
buf
char [2048]

variable_types:
term
char *


decompiled_code:
void more_input()
{
coutput = 0;
}

canonical_decompiled_code:
void func5()
{
coutput = 0;
}

original_code:
void more_input()
{
    coutput = 0;
}

canonical_original_code:
void more_input()
{
    coutput = 0;
}


decompiled_code:
__int64 __fastcall gttime_(_DWORD *a1)
{
int v1; // eax
__int64 result; // rax
char v3[4]; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

itime_(v5, &v4, v3);
v1 = v4 + 60 * v5[0] - (*((_DWORD *)&time_ + 2) + 60 * HIDWORD(time_));
*a1 = v1 + (v1 < 0 ? 0x5A0 : 0);
result = (unsigned int)time_;
*a1 += (_DWORD)time_;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
int v1; // eax
__int64 result; // rax
char v3[4]; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

itime_(v5, &v4, v3);
v1 = v4 + 60 * v5[0] - (*((_DWORD *)&time_ + 2) + 60 * HIDWORD(time_));
*a1 = v1 + (v1 < 0 ? 0x5A0 : 0);
result = (unsigned int)time_;
*a1 += (_DWORD)time_;
return result;
}

original_code:
void gttime_(integer *t)
{
   integer h, m, s;
   itime_(&h, &m, &s);
   *t = h * 60 + m - (time_.shour * 60 + time_.smin);
   if (*t < 0) {
      *t += 1440;
   }
   *t += time_.pltime;
}

canonical_original_code:
void gttime_(int *t)
{
   int h; int m; int s;
   itime_(&h, &m, &s);
   *t = h * 60 + m - (time_.shour * 60 + time_.smin);
   if (*t < 0) {
      *t += 1440;
   }
   *t += time_.pltime;
}

variable_types:
t
int *

variable_types: h int

variable_types: m int

variable_types: s int


decompiled_code:
__int64 __fastcall opncls_(int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // edx
int v5; // eax

if ( prsvec_ == vindex_[34] )
{
if ( (objcts_[a1 + 1100] & 8) != 0 )
{
rspeak_(a3);
objcts_[a1 + 1100] &= 0xFFFFFFF7;
return 1;
}
LABEL_5:
v5 = rnd_(3LL);
rspeak_((unsigned int)(v5 + 125));
return 1;
}
v3 = 0;
if ( prsvec_ == vindex_[33] )
{
if ( (objcts_[a1 + 1100] & 8) == 0 )
{
rspeak_(a2);
objcts_[a1 + 1100] |= 8u;
return 1;
}
goto LABEL_5;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // edx
int v5; // eax

if ( prsvec_ == vindex_[34] )
{
if ( (objcts_[a1 + 1100] & 8) != 0 )
{
rspeak_(a3);
objcts_[a1 + 1100] &= 0xFFFFFFF7;
return 1;
}
LABEL_5:
v5 = rnd_(3LL);
rspeak_((unsigned int)(v5 + 125));
return 1;
}
v3 = 0;
if ( prsvec_ == vindex_[33] )
{
if ( (objcts_[a1 + 1100] & 8) == 0 )
{
rspeak_(a2);
objcts_[a1 + 1100] |= 8u;
return 1;
}
goto LABEL_5;
}
return v3;
}

original_code:
logical opncls_(integer obj, integer so, integer sc)
{
   logical ret_val;
   ret_val = (1);
   if (prsvec_.prsa == vindex_.closew) {
      goto L100;
   }
   if (prsvec_.prsa == vindex_.openw) {
      goto L50;
   }
   ret_val = (0);
   return ret_val;
L50:
   if ((objcts_.oflag2[obj - 1] & (8)) != 0) {
      goto L200;
   }
   rspeak_(so);
   objcts_.oflag2[obj - 1] |= (8);
   return ret_val;
L100:
   if (! ((objcts_.oflag2[obj - 1] & (8)) != 0)) {
      goto L200;
   }
   rspeak_(sc);
   objcts_.oflag2[obj - 1] &= ~ (8);
   return ret_val;
L200:
   rspeak_(rnd_(3) + 125);
   return ret_val;
}

canonical_original_code:
int opncls_(int obj, int so, int sc)
{
   int ret_val;
   ret_val = (1);
   if (prsvec_.prsa == vindex_.closew) {
      goto L100;
   }
   if (prsvec_.prsa == vindex_.openw) {
      goto L50;
   }
   ret_val = (0);
   return ret_val;
L50:
   if ((objcts_.oflag2[obj - 1] & (8)) != 0) {
      goto L200;
   }
   rspeak_(so);
   objcts_.oflag2[obj - 1] |= (8);
   return ret_val;
L100:
   if (! ((objcts_.oflag2[obj - 1] & (8)) != 0)) {
      goto L200;
   }
   rspeak_(sc);
   objcts_.oflag2[obj - 1] &= ~ (8);
   return ret_val;
L200:
   rspeak_(rnd_(3) + 125);
   return ret_val;
}

variable_types: obj int

variable_types: so int

variable_types: sc int


original_code:
logical lit_(integer rm)
{
   logical ret_val;
   integer i, j, oa;
   ret_val = (1);
   if ((rooms_.rflag[rm - 1] & (16384)) != 0) {
      return ret_val;
   }
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (qhere_(i, rm)) {
         goto L100;
      }
      oa = objcts_.oadv[i - 1];
      if (oa <= 0) {
         goto L1000;
      }
      if (advs_.aroom[oa - 1] != rm) {
         goto L1000;
      }
L100:
      if ((objcts_.oflag1[i - 1] & (1)) != 0) {
         return ret_val;
      }
      if ((objcts_.oflag1[i - 1] & (32768)) == 0 || (
               objcts_.oflag1[i - 1] & (2048)) == 0 && (
                  objcts_.oflag2[i - 1] & (8)) == 0) {
         goto L1000;
      }
      for (j = 1; j <= objcts_.olnt; ++j) {
         if (objcts_.ocan[j - 1] == i && (objcts_.oflag1[j - 1] &
                  (1)) != 0) {
            return ret_val;
         }
      }
L1000:
      ;
   }
   ret_val = (0);
   return ret_val;
}

canonical_original_code:
int lit_(int rm)
{
   int ret_val;
   int i; int j; int oa;
   ret_val = (1);
   if ((rooms_.rflag[rm - 1] & (16384)) != 0) {
      return ret_val;
   }
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (qhere_(i, rm)) {
         goto L100;
      }
      oa = objcts_.oadv[i - 1];
      if (oa <= 0) {
         goto L1000;
      }
      if (advs_.aroom[oa - 1] != rm) {
         goto L1000;
      }
L100:
      if ((objcts_.oflag1[i - 1] & (1)) != 0) {
         return ret_val;
      }
      if ((objcts_.oflag1[i - 1] & (32768)) == 0 || (
               objcts_.oflag1[i - 1] & (2048)) == 0 && (
                  objcts_.oflag2[i - 1] & (8)) == 0) {
         goto L1000;
      }
      for (j = 1; j <= objcts_.olnt; ++j) {
         if (objcts_.ocan[j - 1] == i && (objcts_.oflag1[j - 1] &
                  (1)) != 0) {
            return ret_val;
         }
      }
L1000:
      ;
   }
   ret_val = (0);
   return ret_val;
}

variable_types: rm int

variable_types: i int

variable_types: j int

variable_types: oa int


decompiled_code:
__int64 __fastcall weight_(unsigned int a1, int a2, __int64 a3)
{
int v3; // er14
__int64 v4; // rbp
unsigned int v5; // er15
int v6; // ebx
int v7; // eax

if ( objcts_[0] <= 0 )
return 0;
v3 = a3;
v4 = 1LL;
v5 = 0;
do
{
v6 = v4;
if ( (int)objcts_[v4 + 1760] <= 9999 )
{
v7 = qhere_((unsigned int)v4, a1, a3);
if ( a1 && v7 || objcts_[v4 + 2420] == v3 && v3 )
{
LABEL_3:
v5 += objcts_[v4 + 1760];
}
else
{
while ( 1 )
{
v6 = objcts_[v6 + 2640];
if ( !v6 )
break;
if ( v6 == a2 )
goto LABEL_3;
}
}
}
++v4;
}
while ( objcts_[0] >= (int)v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2, __int64 a3)
{
int v3; // er14
__int64 v4; // rbp
unsigned int v5; // er15
int v6; // ebx
int v7; // eax

if ( objcts_[0] <= 0 )
return 0;
v3 = a3;
v4 = 1LL;
v5 = 0;
do
{
v6 = v4;
if ( (int)objcts_[v4 + 1760] <= 9999 )
{
v7 = qhere_((unsigned int)v4, a1, a3);
if ( a1 && v7 || objcts_[v4 + 2420] == v3 && v3 )
{
LABEL_3:
v5 += objcts_[v4 + 1760];
}
else
{
while ( 1 )
{
v6 = objcts_[v6 + 2640];
if ( !v6 )
break;
if ( v6 == a2 )
goto LABEL_3;
}
}
}
++v4;
}
while ( objcts_[0] >= (int)v4 );
return v5;
}

original_code:
integer weight_(integer rm, integer cn, integer ad)
{
   integer ret_val, i__1;
   integer i, j;
   ret_val = 0;
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (objcts_.osize[i - 1] >= 10000) {
         continue;
      }
      if (qhere_(i, rm) && rm != 0 || objcts_.oadv[i - 1] == ad && ad
            != 0) {
         goto L50;
      }
      j = i;
      do {
         j = objcts_.ocan[j - 1];
         if (j == 0) {
            goto L51;
         }
      } while (j != cn);
L50:
      ret_val += objcts_.osize[i - 1];
L51:
      (void)ret_val;
   }
   return ret_val;
}

canonical_original_code:
int weight_(int rm, int cn, int ad)
{
   int ret_val; int i__1;
   int i; int j;
   ret_val = 0;
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (objcts_.osize[i - 1] >= 10000) {
         continue;
      }
      if (qhere_(i, rm) && rm != 0 || objcts_.oadv[i - 1] == ad && ad
            != 0) {
         goto L50;
      }
      j = i;
      do {
         j = objcts_.ocan[j - 1];
         if (j == 0) {
            goto L51;
         }
      } while (j != cn);
L50:
      ret_val += objcts_.osize[i - 1];
L51:
      (void)ret_val;
   }
   return ret_val;
}

variable_types: cn int

variable_types: ad int


original_code:
logical synmch_()
{
    const integer r50min = 1600;
    integer i__1;
    logical ret_val;
    integer j;
    integer newj;
    integer drive, limit, qprep, sprep, dforce;
    ret_val = (0);
    j = pv_.act;
    drive = 0;
    dforce = 0;
    qprep = orphs_.oflag & orphs_.oprep;
L100:
    j += 2;
    if (vvoc[j - 1] <= 0 || vvoc[j - 1] >= r50min) {
 goto L100;
    }
    limit = j + vvoc[j - 1] + 1;
    ++j;
L200:
    unpack_(j, &newj);
    sprep = syntax_.dobj & (511);
    if (! syneql_(pv_.p1, pv_.o1, syntax_.dobj, syntax_.dfl1,
     syntax_.dfl2)) {
 goto L1000;
    }
    sprep = syntax_.iobj & (511);
    if (syneql_(pv_.p2, pv_.o2, syntax_.iobj, syntax_.ifl1,
     syntax_.ifl2)) {
 goto L6000;
    }
    if (pv_.o2 != 0) {
 goto L3000;
    } else {
 goto L500;
    }
L1000:
    if (pv_.o1 != 0) {
 goto L3000;
    } else {
 goto L500;
    }
L500:
    if (qprep == 0 || qprep == sprep) {
 dforce = j;
    }
    if ((syntax_.vflag & (1024)) != 0) {
 drive = j;
    }
L3000:
    j = newj;
    if (j < limit) {
 goto L200;
    }
    if (drive == 0) {
 drive = dforce;
    }
    if (drive == 0) {
 goto L10000;
    }
    unpack_(drive, &dforce);
    if ((syntax_.vflag & (16384)) == 0 || pv_.o1 != 0) {
 goto L4000;
    }
    pv_.o1 = orphs_.oflag & orphs_.oslot;
    if (pv_.o1 == 0) {
 goto L3500;
    }
    if (syneql_(pv_.p1, pv_.o1, syntax_.dobj, syntax_.dfl1,
     syntax_.dfl2)) {
 goto L4000;
    }
L3500:
    pv_.o1 = gwim_(syntax_.dobj, syntax_.dfw1, syntax_.dfw2);
    if (pv_.o1 > 0) {
 goto L4000;
    }
    i__1 = syntax_.dobj & (511);
    orphan_(- 1, pv_.act, 0, i__1, 0);
    rspeak_(623);
    return ret_val;
L4000:
    if ((syntax_.vflag & (8192)) == 0 || pv_.o2 != 0) {
 goto L6000;
    }
    pv_.o2 = gwim_(syntax_.iobj, syntax_.ifw1, syntax_.ifw2);
    if (pv_.o2 > 0) {
 goto L6000;
    }
    if (pv_.o1 == 0) {
 pv_.o1 = orphs_.oflag & orphs_.oslot;
    }
    i__1 = syntax_.dobj & (511);
    orphan_(- 1, pv_.act, pv_.o1, i__1, 0);
    rspeak_(624);
    return ret_val;
L10000:
    rspeak_(601);
    return ret_val;
L6000:
    if ((syntax_.vflag & (2048)) == 0) {
 goto L5000;
    }
    j = pv_.o1;
    pv_.o1 = pv_.o2;
    pv_.o2 = j;
L5000:
    prsvec_.prsa = syntax_.vflag & (511);
    prsvec_.prso = pv_.o1;
    prsvec_.prsi = pv_.o2;
    if (! takeit_(prsvec_.prso, syntax_.dobj)) {
 return ret_val;
    }
    if (! takeit_(prsvec_.prsi, syntax_.iobj)) {
 return ret_val;
    }
    ret_val = (1);
    return ret_val;
}

canonical_original_code:
int synmch_()
{
    int r50min = 1600;
    int i__1;
    int ret_val;
    int j;
    int newj;
    int drive; int limit; int qprep; int sprep; int dforce;
    ret_val = (0);
    j = pv_.act;
    drive = 0;
    dforce = 0;
    qprep = orphs_.oflag & orphs_.oprep;
L100:
    j += 2;
    if (vvoc[j - 1] <= 0 || vvoc[j - 1] >= r50min) {
 goto L100;
    }
    limit = j + vvoc[j - 1] + 1;
    ++j;
L200:
    unpack_(j, &newj);
    sprep = syntax_.dobj & (511);
    if (! syneql_(pv_.p1, pv_.o1, syntax_.dobj, syntax_.dfl1,
     syntax_.dfl2)) {
 goto L1000;
    }
    sprep = syntax_.iobj & (511);
    if (syneql_(pv_.p2, pv_.o2, syntax_.iobj, syntax_.ifl1,
     syntax_.ifl2)) {
 goto L6000;
    }
    if (pv_.o2 != 0) {
 goto L3000;
    } else {
 goto L500;
    }
L1000:
    if (pv_.o1 != 0) {
 goto L3000;
    } else {
 goto L500;
    }
L500:
    if (qprep == 0 || qprep == sprep) {
 dforce = j;
    }
    if ((syntax_.vflag & (1024)) != 0) {
 drive = j;
    }
L3000:
    j = newj;
    if (j < limit) {
 goto L200;
    }
    if (drive == 0) {
 drive = dforce;
    }
    if (drive == 0) {
 goto L10000;
    }
    unpack_(drive, &dforce);
    if ((syntax_.vflag & (16384)) == 0 || pv_.o1 != 0) {
 goto L4000;
    }
    pv_.o1 = orphs_.oflag & orphs_.oslot;
    if (pv_.o1 == 0) {
 goto L3500;
    }
    if (syneql_(pv_.p1, pv_.o1, syntax_.dobj, syntax_.dfl1,
     syntax_.dfl2)) {
 goto L4000;
    }
L3500:
    pv_.o1 = gwim_(syntax_.dobj, syntax_.dfw1, syntax_.dfw2);
    if (pv_.o1 > 0) {
 goto L4000;
    }
    i__1 = syntax_.dobj & (511);
    orphan_(- 1, pv_.act, 0, i__1, 0);
    rspeak_(623);
    return ret_val;
L4000:
    if ((syntax_.vflag & (8192)) == 0 || pv_.o2 != 0) {
 goto L6000;
    }
    pv_.o2 = gwim_(syntax_.iobj, syntax_.ifw1, syntax_.ifw2);
    if (pv_.o2 > 0) {
 goto L6000;
    }
    if (pv_.o1 == 0) {
 pv_.o1 = orphs_.oflag & orphs_.oslot;
    }
    i__1 = syntax_.dobj & (511);
    orphan_(- 1, pv_.act, pv_.o1, i__1, 0);
    rspeak_(624);
    return ret_val;
L10000:
    rspeak_(601);
    return ret_val;
L6000:
    if ((syntax_.vflag & (2048)) == 0) {
 goto L5000;
    }
    j = pv_.o1;
    pv_.o1 = pv_.o2;
    pv_.o2 = j;
L5000:
    prsvec_.prsa = syntax_.vflag & (511);
    prsvec_.prso = pv_.o1;
    prsvec_.prsi = pv_.o2;
    if (! takeit_(prsvec_.prso, syntax_.dobj)) {
 return ret_val;
    }
    if (! takeit_(prsvec_.prsi, syntax_.iobj)) {
 return ret_val;
    }
    ret_val = (1);
    return ret_val;
}

variable_types: newj int

variable_types: drive int

variable_types: limit int

variable_types: qprep int

variable_types: sprep int

variable_types: dforce int


decompiled_code:
void __fastcall rspsb2nl_(int a1, unsigned int a2, unsigned int a3, int a4)
{
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // r14
int v10; // eax
int v11; // edx
int v12; // edi

v7 = a1;
if ( a1 <= 0 )
{
if ( !a1 )
return;
}
else
{
v7 = *((int *)&rmsg_ + a1 + 1);
}
play_[2] = 1;
v8 = 8 * ~v7;
fseek(dbfile, v8 + *((int *)&rmsg_ + 1), 0);
if ( !a4 )
goto LABEL_10;
LABEL_4:
more_output(0LL);
LABEL_10:
while ( 1 )
{
v10 = getc(dbfile);
v11 = (unsigned __int8)v8 ^ byte_87C[v8 & 0xF];
v12 = v10 ^ v11;
++v8;
if ( v11 == v10 )
break;
if ( v12 == 10 )
{
putchar(10);
if ( a4 )
goto LABEL_4;
}
else if ( v12 == 35 && a2 )
{
v9 = ftell(dbfile);
rspsb2nl_(a2, 0LL, 0LL, 0LL);
fseek(dbfile, v9, 0);
a2 = a3;
a3 = 0;
}
else
{
putchar(v12);
}
}
if ( a4 )
putchar(10);
}

canonical_decompiled_code:
void __fastcall func0(int a1, unsigned int a2, unsigned int a3, int a4)
{
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // r14
int v10; // eax
int v11; // edx
int v12; // edi

v7 = a1;
if ( a1 <= 0 )
{
if ( !a1 )
return;
}
else
{
v7 = *((int *)&rmsg_ + a1 + 1);
}
play_[2] = 1;
v8 = 8 * ~v7;
fseek(dbfile, v8 + *((int *)&rmsg_ + 1), 0);
if ( !a4 )
goto LABEL_10;
LABEL_4:
more_output(0LL);
LABEL_10:
while ( 1 )
{
v10 = getc(dbfile);
v11 = (unsigned __int8)v8 ^ byte_87C[v8 & 0xF];
v12 = v10 ^ v11;
++v8;
if ( v11 == v10 )
break;
if ( v12 == 10 )
{
putchar(10);
if ( a4 )
goto LABEL_4;
}
else if ( v12 == 35 && a2 )
{
v9 = ftell(dbfile);
func0(a2, 0LL, 0LL, 0LL);
fseek(dbfile, v9, 0);
a2 = a3;
a3 = 0;
}
else
{
putchar(v12);
}
}
if ( a4 )
putchar(10);
}

original_code:
static void rspsb2nl_(integer n, integer y, integer z, integer nl)
{
   int res;
   const char *zkey = "IanLanceTaylorJr";
   long x = (long)n;
   if (x > 0) {
      x = rmsg_.rtext[x - 1];
   }
   else if (x == 0) {
      return;
   }
   play_.telflg = (1);
   x = ((- x) - 1) * 8;
   res = fseek(dbfile, x + (long)rmsg_.mrloc, 0);
   if (nl)
      more_output(((void *)0));
   while (1) {
      integer i;
      i = getc(dbfile);
      i ^= zkey[x & 0xf] ^ (x & 0xff);
      x = x + 1;
      if (i == '\0')
         break;
      else if (i == '\n') {
         putchar('\n');
         if (nl)
            more_output(((void *)0));
      }
      else if (i == '#' && y != 0) {
         long iloc;
         iloc = ftell(dbfile);
         rspsb2nl_(y, 0, 0, 0);
  res = fseek(dbfile, iloc, 0);
         y = z;
         z = 0;
      }
      else
         putchar(i);
   }
   if (nl)
      putchar('\n');
}

canonical_original_code:
static void rspsb2nl_(int n, int y, int z, int nl)
{
   int res;
   char *zkey = "IanLanceTaylorJr";
   long x = (long)n;
   if (x > 0) {
      x = rmsg_.rtext[x - 1];
   }
   else if (x == 0) {
      return;
   }
   play_.telflg = (1);
   x = ((- x) - 1) * 8;
   res = fseek(dbfile, x + (long)rmsg_.mrloc, 0);
   if (nl)
      more_output(((void *)0));
   while (1) {
      int i;
      i = getc(dbfile);
      i ^= zkey[x & 0xf] ^ (x & 0xff);
      x = x + 1;
      if (i == '\0')
         break;
      else if (i == '\n') {
         putchar('\n');
         if (nl)
            more_output(((void *)0));
      }
      else if (i == '#' && y != 0) {
         long iloc;
         iloc = ftell(dbfile);
         rspsb2nl_(y, 0, 0, 0);
  res = fseek(dbfile, iloc, 0);
         y = z;
         z = 0;
      }
      else
         putchar(i);
   }
   if (nl)
      putchar('\n');
}

variable_types: n int

variable_types: y int

variable_types: z int

variable_types: nl int

variable_types: res int

variable_types:
zkey
char *

variable_types: x long

variable_types: iloc long


decompiled_code:
__int64 objact_()
{
unsigned int v0; // eax
__int64 result; // rax
int v2; // edx

v0 = prsvec_[1];
if ( !v0 || (v2 = oappli_(objcts_[v0 - 1 + 661], 0LL), result = 1LL, !v2) )
{
result = prsvec_[2];
if ( (_DWORD)result )
result = (unsigned int)oappli_(objcts_[(int)result + 660], 0LL) != 0;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // eax
__int64 result; // rax
int v2; // edx

v0 = prsvec_[1];
if ( !v0 || (v2 = oappli_(objcts_[v0 - 1 + 661], 0LL), result = 1LL, !v2) )
{
result = prsvec_[2];
if ( (_DWORD)result )
result = (unsigned int)oappli_(objcts_[(int)result + 660], 0LL) != 0;
}
return result;
}

original_code:
logical objact_()
{
   if (prsvec_.prsi != 0 &&
         oappli_(objcts_.oactio[prsvec_.prsi - 1], 0)) {
      return (1);
   }
   if (prsvec_.prso != 0 &&
         oappli_(objcts_.oactio[prsvec_.prso - 1], 0)) {
      return (1);
   }
   return (0);
}

canonical_original_code:
int objact_()
{
   if (prsvec_.prsi != 0 &&
         oappli_(objcts_.oactio[prsvec_.prsi - 1], 0)) {
      return (1);
   }
   if (prsvec_.prso != 0 &&
         oappli_(objcts_.oactio[prsvec_.prso - 1], 0)) {
      return (1);
   }
   return (0);
}


decompiled_code:
void bug_()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void bug_(integer a, integer b)
{
}

canonical_original_code:
void bug_(int a, int b)
{
}

variable_types: a int

variable_types: b int


decompiled_code:
void __fastcall newsta_(int a1, int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int64 v8; // rdi

rspeak_(a2);
v8 = a1 - 1;
objcts_[v8 + 2201] = a3;
objcts_[v8 + 2641] = a4;
objcts_[v8 + 2421] = a5;
}

canonical_decompiled_code:
void __fastcall func6(int a1, int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int64 v8; // rdi

func1(a2);
v8 = a1 - 1;
objcts_[v8 + 2201] = a3;
objcts_[v8 + 2641] = a4;
objcts_[v8 + 2421] = a5;
}

original_code:
void newsta_(integer o, integer r, integer rm, integer cn, integer ad)
{
   rspeak_(r);
   objcts_.oroom[o - 1] = rm;
   objcts_.ocan[o - 1] = cn;
   objcts_.oadv[o - 1] = ad;
}

canonical_original_code:
void newsta_(int o, int r, int rm, int cn, int ad)
{
   rspeak_(r);
   objcts_.oroom[o - 1] = rm;
   objcts_.ocan[o - 1] = cn;
   objcts_.oadv[o - 1] = ad;
}

variable_types: o int

variable_types: r int

variable_types: rm int

variable_types: cn int

variable_types: ad int


decompiled_code:
__int64 __fastcall qhere_(int a1, int a2)
{
unsigned int v2; // edx
__int64 v3; // rax

v2 = 1;
if ( objcts_[a1 + 2200] != a2 )
{
if ( oroom2_[0] <= 0 )
{
v2 = 0;
}
else
{
v3 = 1LL;
do
{
if ( oroom2_[v3] == a1 && oroom2_[v3 + 20] == a2 )
return 1;
++v3;
}
while ( oroom2_[0] >= (int)v3 );
v2 = 0;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
unsigned int v2; // edx
__int64 v3; // rax

v2 = 1;
if ( objcts_[a1 + 2200] != a2 )
{
if ( oroom2_[0] <= 0 )
{
v2 = 0;
}
else
{
v3 = 1LL;
do
{
if ( oroom2_[v3] == a1 && oroom2_[v3 + 20] == a2 )
return 1;
++v3;
}
while ( oroom2_[0] >= (int)v3 );
v2 = 0;
}
}
return v2;
}

original_code:
logical qhere_(integer obj, integer rm)
{
   integer i;
   if (objcts_.oroom[obj - 1] == rm) {
      return (1);
   }
   for (i = 1; i <= oroom2_.r2lnt; ++i) {
      if (oroom2_.oroom2[i - 1] == obj && oroom2_.rroom2[i - 1] == rm) {
         return (1);
      }
   }
   return (0);
}

canonical_original_code:
int qhere_(int obj, int rm)
{
   int i;
   if (objcts_.oroom[obj - 1] == rm) {
      return (1);
   }
   for (i = 1; i <= oroom2_.r2lnt; ++i) {
      if (oroom2_.oroom2[i - 1] == obj && oroom2_.rroom2[i - 1] == rm) {
         return (1);
      }
   }
   return (0);
}

variable_types: obj int

variable_types: i int


decompiled_code:
__int64 __fastcall qempty_(int a1)
{
__int64 v1; // rax

if ( (int)objcts_[0] <= 0 )
return 1LL;
v1 = 1LL;
while ( objcts_[v1 + 2640] != a1 )
{
if ( (int)objcts_[0] < (int)++v1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // rax

if ( (int)objcts_[0] <= 0 )
return 1LL;
v1 = 1LL;
while ( objcts_[v1 + 2640] != a1 )
{
if ( (int)objcts_[0] < (int)++v1 )
return 1LL;
}
return 0LL;
}

original_code:
logical qempty_(integer obj)
{
   integer i;
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (objcts_.ocan[i - 1] == obj) {
         return (0);
      }
   }
   return (1);
}

canonical_original_code:
int qempty_(int obj)
{
   int i;
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (objcts_.ocan[i - 1] == obj) {
         return (0);
      }
   }
   return (1);
}


original_code:
void jigsup_(integer desc)
{
   static const integer rlist[9] = { 8,6,36,35,34,4,34,6,5 };
   integer nonofl;
   logical f;
   integer i, j;
   rspeak_(desc);
   prsvec_.prscon = 1;
   advs_.avehic[play_.winner - 1] = 0;
   if (!(play_.winner == aindex_.player)) {
      rspsub_(432, objcts_.odesc2[advs_.aobj[play_.winner - 1] - 1]);
      newsta_(advs_.aobj[play_.winner - 1], 0, 0, 0, 0);
      return;
   }
   if (findex_.endgmf) {
      goto L900;
   }
   if (state_.deaths >= 2) {
      goto L1000;
   }
   if (! yesno_(10, 9, 8)) {
      goto L1100;
   }
   for (j = 1; j <= objcts_.olnt; ++j) {
      if (qhere_(j, play_.here)) {
         objcts_.oflag2[j - 1] &= ~ (256);
      }
   }
   ++state_.deaths;
   scrupd_(- 10);
   f = moveto_(rindex_.fore1, play_.winner);
   findex_.egyptf = (1);
   if (objcts_.oadv[oindex_.coffi - 1] == play_.winner) {
      newsta_(oindex_.coffi, 0, rindex_.egypt, 0, 0);
   }
   objcts_.oflag2[oindex_.door - 1] &= ~ (4);
   objcts_.oflag1[oindex_.robot - 1] = (objcts_.oflag1[oindex_.robot - 1]
         | (32768)) & ~ (512);
   if (objcts_.oroom[oindex_.lamp - 1] != 0 || objcts_.oadv[oindex_.lamp
         - 1] == play_.winner) {
      newsta_(oindex_.lamp, 0, rindex_.lroom, 0, 0);
   }
   i = 1;
   for (j = 1; j <= objcts_.olnt; ++j) {
      if (objcts_.oadv[j - 1] != play_.winner || objcts_.otval[j - 1] !=
            0) {
         goto L200;
      }
      ++i;
      if (i > 9) {
         goto L400;
      }
      newsta_(j, 0, rlist[i - 1], 0, 0);
L200:
      ;
   }
L400:
   i = rooms_.rlnt + 1;
   nonofl = (2048) + (4096) + (1024) + (16);
   for (j = 1; j <= objcts_.olnt; ++j) {
      if (objcts_.oadv[j - 1] != play_.winner || objcts_.otval[j - 1] ==
            0) {
         goto L300;
      }
L250:
      --i;
      if ((rooms_.rflag[i - 1] & nonofl) != 0) {
         goto L250;
      }
      newsta_(j, 0, i, 0, 0);
L300:
      ;
   }
   for (j = 1; j <= objcts_.olnt; ++j) {
      if (objcts_.oadv[j - 1] != play_.winner) {
         goto L500;
      }
L450:
      --i;
      if ((rooms_.rflag[i - 1] & nonofl) != 0) {
         goto L450;
      }
      newsta_(j, 0, i, 0, 0);
L500:
      ;
   }
   return;
L900:
   rspeak_(625);
   goto L1100;
L1000:
   rspeak_(7);
L1100:
   score_(0);
   (void) fclose(dbfile);
   exit_();
}

canonical_original_code:
void jigsup_(int desc)
{
   static int rlist[9] = { 8,6,36,35,34,4,34,6,5 };
   int nonofl;
   int f;
   int i; int j;
   rspeak_(desc);
   prsvec_.prscon = 1;
   advs_.avehic[play_.winner - 1] = 0;
   if (!(play_.winner == aindex_.player)) {
      rspsub_(432, objcts_.odesc2[advs_.aobj[play_.winner - 1] - 1]);
      newsta_(advs_.aobj[play_.winner - 1], 0, 0, 0, 0);
      return;
   }
   if (findex_.endgmf) {
      goto L900;
   }
   if (state_.deaths >= 2) {
      goto L1000;
   }
   if (! yesno_(10, 9, 8)) {
      goto L1100;
   }
   for (j = 1; j <= objcts_.olnt; ++j) {
      if (qhere_(j, play_.here)) {
         objcts_.oflag2[j - 1] &= ~ (256);
      }
   }
   ++state_.deaths;
   scrupd_(- 10);
   f = moveto_(rindex_.fore1, play_.winner);
   findex_.egyptf = (1);
   if (objcts_.oadv[oindex_.coffi - 1] == play_.winner) {
      newsta_(oindex_.coffi, 0, rindex_.egypt, 0, 0);
   }
   objcts_.oflag2[oindex_.door - 1] &= ~ (4);
   objcts_.oflag1[oindex_.robot - 1] = (objcts_.oflag1[oindex_.robot - 1]
         | (32768)) & ~ (512);
   if (objcts_.oroom[oindex_.lamp - 1] != 0 || objcts_.oadv[oindex_.lamp
         - 1] == play_.winner) {
      newsta_(oindex_.lamp, 0, rindex_.lroom, 0, 0);
   }
   i = 1;
   for (j = 1; j <= objcts_.olnt; ++j) {
      if (objcts_.oadv[j - 1] != play_.winner || objcts_.otval[j - 1] !=
            0) {
         goto L200;
      }
      ++i;
      if (i > 9) {
         goto L400;
      }
      newsta_(j, 0, rlist[i - 1], 0, 0);
L200:
      ;
   }
L400:
   i = rooms_.rlnt + 1;
   nonofl = (2048) + (4096) + (1024) + (16);
   for (j = 1; j <= objcts_.olnt; ++j) {
      if (objcts_.oadv[j - 1] != play_.winner || objcts_.otval[j - 1] ==
            0) {
         goto L300;
      }
L250:
      --i;
      if ((rooms_.rflag[i - 1] & nonofl) != 0) {
         goto L250;
      }
      newsta_(j, 0, i, 0, 0);
L300:
      ;
   }
   for (j = 1; j <= objcts_.olnt; ++j) {
      if (objcts_.oadv[j - 1] != play_.winner) {
         goto L500;
      }
L450:
      --i;
      if ((rooms_.rflag[i - 1] & nonofl) != 0) {
         goto L450;
      }
      newsta_(j, 0, i, 0, 0);
L500:
      ;
   }
   return;
L900:
   rspeak_(625);
   goto L1100;
L1000:
   rspeak_(7);
L1100:
   score_(0);
   (void) fclose(dbfile);
   exit_();
}

variable_types: desc int

variable_types:
rlist
int [9]

variable_types: nonofl int

variable_types: f int

variable_types: j int


decompiled_code:
__int64 __fastcall oactor_(int a1)
{
__int64 v1; // rax
unsigned int v2; // ecx

if ( advs_[0] <= 0 )
return (unsigned int)(advs_[0] + 1);
v1 = 1LL;
while ( 1 )
{
v2 = v1;
if ( advs_[v1 + 12] == a1 )
break;
if ( advs_[0] < (int)++v1 )
return (unsigned int)(advs_[0] + 1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
__int64 v1; // rax
unsigned int v2; // ecx

if ( advs_[0] <= 0 )
return (unsigned int)(advs_[0] + 1);
v1 = 1LL;
while ( 1 )
{
v2 = v1;
if ( advs_[v1 + 12] == a1 )
break;
if ( advs_[0] < (int)++v1 )
return (unsigned int)(advs_[0] + 1);
}
return v2;
}

original_code:
integer oactor_(integer obj)
{
   integer i;
   for (i = 1; i <= advs_.alnt; ++i) {
      if (advs_.aobj[i - 1] == obj) {
         return i;
      }
   }
   return advs_.alnt + 1;
}

canonical_original_code:
int oactor_(int obj)
{
   int i;
   for (i = 1; i <= advs_.alnt; ++i) {
      if (advs_.aobj[i - 1] == obj) {
         return i;
      }
   }
   return advs_.alnt + 1;
}


decompiled_code:
_BOOL8 __fastcall prob_(int a1, int a2)
{
if ( !findex_[33] )
a2 = a1;
return (int)rnd_(100LL) < a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(int a1, int a2)
{
if ( !findex_[33] )
a2 = a1;
return (int)rnd_(100LL) < a2;
}

original_code:
logical prob_(integer g, integer b)
{
   integer i;
   i = g;
   if (findex_.badlkf) {
      i = b;
   }
   return (rnd_(100) < i);
}

canonical_original_code:
int prob_(int g, int b)
{
   int i;
   i = g;
   if (findex_.badlkf) {
      i = b;
   }
   return (rnd_(100) < i);
}

variable_types: g int


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

result = 1LL;
if ( a1 )
{
if ( a1 <= 37 )
result = rappl1_();
else
result = rappl2_();
}
return result;
}

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

result = 1LL;
if ( a1 )
{
if ( a1 <= 37 )
result = rappl1_();
else
result = rappl2_();
}
return result;
}

original_code:
logical rappli_(integer ri)
{
   const integer newrms = 38;
   if (ri == 0) {
      return (1);
   }
   if (ri >= newrms) {
      return rappl2_(ri);
   }
   else if (ri < newrms) {
      return rappl1_(ri);
   }
}

canonical_original_code:
int rappli_(int ri)
{
   int newrms = 38;
   if (ri == 0) {
      return (1);
   }
   if (ri >= newrms) {
      return rappl2_(ri);
   }
   else if (ri < newrms) {
      return rappl1_(ri);
   }
}

variable_types: ri int

variable_types: newrms int


decompiled_code:
__int64 __fastcall robadv_(int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rbx
unsigned int v7; // er12

if ( objcts_ <= 0 )
return 0;
v6 = 1LL;
v7 = 0;
do
{
if ( *((_DWORD *)&objcts_ + v6 + 2420) == a1
&& *((int *)&objcts_ + v6 + 1540) > 0
&& (*((_BYTE *)&objcts_ + 4 * v6 + 4401) & 0x20) == 0 )
{
newsta_((unsigned int)v6, 0LL, a2, a3, a4);
++v7;
}
++v6;
}
while ( objcts_ >= (int)v6 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // rbx
unsigned int v7; // er12

if ( objcts_ <= 0 )
return 0;
v6 = 1LL;
v7 = 0;
do
{
if ( *((_DWORD *)&objcts_ + v6 + 2420) == a1
&& *((int *)&objcts_ + v6 + 1540) > 0
&& (*((_BYTE *)&objcts_ + 4 * v6 + 4401) & 0x20) == 0 )
{
newsta_((unsigned int)v6, 0LL, a2, a3, a4);
++v7;
}
++v6;
}
while ( objcts_ >= (int)v6 );
return v7;
}

original_code:
integer robadv_(integer adv, integer nr, integer nc, integer na)
{
   integer ret_val;
   integer i;
   ret_val = 0;
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (objcts_.oadv[i - 1] != adv || objcts_.otval[i - 1] <= 0 || (
               objcts_.oflag2[i - 1] & (8192)) != 0) {
         continue;
      }
      newsta_(i, 0, nr, nc, na);
      ++ret_val;
   }
   return ret_val;
}

canonical_original_code:
int robadv_(int adv, int nr, int nc, int na)
{
   int ret_val;
   int i;
   ret_val = 0;
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (objcts_.oadv[i - 1] != adv || objcts_.otval[i - 1] <= 0 || (
               objcts_.oflag2[i - 1] & (8192)) != 0) {
         continue;
      }
      newsta_(i, 0, nr, nc, na);
      ++ret_val;
   }
   return ret_val;
}

variable_types: adv int

variable_types: nr int

variable_types: nc int


decompiled_code:
__int64 __fastcall robrm_(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int64 v7; // rbx
unsigned int v8; // er13
int v9; // eax

if ( objcts_ <= 0 )
return 0;
v7 = 1LL;
v8 = 0;
do
{
if ( (unsigned int)qhere_((unsigned int)v7, a1) )
{
if ( *((int *)&objcts_ + v7 + 1540) <= 0
|| (*((_BYTE *)&objcts_ + 4 * v7 + 4401) & 0x20) != 0
|| *((char *)&objcts_ + 4 * v7 + 3521) >= 0
|| !(unsigned int)prob_(a2) )
{
if ( (*((_BYTE *)&objcts_ + 4 * v7 + 4401) & 4) != 0 )
{
v9 = oactor_((unsigned int)v7);
v8 += robadv_(v9, a3, a4, a5);
}
}
else
{
newsta_((unsigned int)v7, 0LL, a3, a4, a5);
++v8;
*((_DWORD *)&objcts_ + v7 + 1100) |= 4u;
}
}
++v7;
}
while ( objcts_ >= (int)v7 );
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int64 v7; // rbx
unsigned int v8; // er13
int v9; // eax

if ( objcts_ <= 0 )
return 0;
v7 = 1LL;
v8 = 0;
do
{
if ( (unsigned int)qhere_((unsigned int)v7, a1) )
{
if ( *((int *)&objcts_ + v7 + 1540) <= 0
|| (*((_BYTE *)&objcts_ + 4 * v7 + 4401) & 0x20) != 0
|| *((char *)&objcts_ + 4 * v7 + 3521) >= 0
|| !(unsigned int)prob_(a2) )
{
if ( (*((_BYTE *)&objcts_ + 4 * v7 + 4401) & 4) != 0 )
{
v9 = oactor_((unsigned int)v7);
v8 += func0(v9, a3, a4, a5);
}
}
else
{
newsta_((unsigned int)v7, 0LL, a3, a4, a5);
++v8;
*((_DWORD *)&objcts_ + v7 + 1100) |= 4u;
}
}
++v7;
}
while ( objcts_ >= (int)v7 );
return v8;
}

original_code:
integer robrm_(integer rm, integer pr, integer nr, integer nc, integer na)
{
   integer ret_val;
   integer i;
   ret_val = 0;
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (! qhere_(i, rm)) {
         continue;
      }
      if (objcts_.otval[i - 1] <= 0 || (objcts_.oflag2[i - 1] &
               (8192)) != 0 || (objcts_.oflag1[i - 1] &
                  (32768)) == 0 || ! prob_(pr, pr)) {
         if ((objcts_.oflag2[i - 1] & (1024)) != 0) {
            ret_val += robadv_(oactor_(i), nr, nc, na);
         }
      }
      else {
         newsta_(i, 0, nr, nc, na);
         ++ret_val;
         objcts_.oflag2[i - 1] |= (4);
         continue;
      }
   }
   return ret_val;
}

canonical_original_code:
int robrm_(int rm, int pr, int nr, int nc, int na)
{
   int ret_val;
   int i;
   ret_val = 0;
   for (i = 1; i <= objcts_.olnt; ++i) {
      if (! qhere_(i, rm)) {
         continue;
      }
      if (objcts_.otval[i - 1] <= 0 || (objcts_.oflag2[i - 1] &
               (8192)) != 0 || (objcts_.oflag1[i - 1] &
                  (32768)) == 0 || ! prob_(pr, pr)) {
         if ((objcts_.oflag2[i - 1] & (1024)) != 0) {
            ret_val += robadv_(oactor_(i), nr, nc, na);
         }
      }
      else {
         newsta_(i, 0, nr, nc, na);
         ++ret_val;
         objcts_.oflag2[i - 1] |= (4);
         continue;
      }
   }
   return ret_val;
}

variable_types: pr int


decompiled_code:
__int64 __fastcall fights_(int a1, int a2)
{
int v2; // edi
__int64 result; // rax

v2 = a1 - 1;
result = (unsigned int)((5 * advs_[v2 + 5] + state_[3] / 2) / state_[3] + 2);
if ( a2 )
result = (unsigned int)(advs_[v2 + 21] + result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
int v2; // edi
__int64 result; // rax

v2 = a1 - 1;
result = (unsigned int)((5 * advs_[v2 + 5] + state_[3] / 2) / state_[3] + 2);
if ( a2 )
result = (unsigned int)(advs_[v2 + 21] + result);
return result;
}

original_code:
integer fights_(integer h, logical flg)
{
   const integer smin = 2;
   const integer smax = 7;
   integer ret_val;
   ret_val = smin + ((smax - smin) * advs_.ascore[h - 1] + state_.mxscor /
         2) / state_.mxscor;
   if (flg) {
      ret_val += advs_.astren[h - 1];
   }
   return ret_val;
}

canonical_original_code:
int fights_(int h, int flg)
{
   int smin = 2;
   int smax = 7;
   int ret_val;
   ret_val = smin + ((smax - smin) * advs_.ascore[h - 1] + state_.mxscor /
         2) / state_.mxscor;
   if (flg) {
      ret_val += advs_.astren[h - 1];
   }
   return ret_val;
}

variable_types: h int

variable_types: flg int

variable_types: smin int

variable_types: smax int


decompiled_code:
__int64 __fastcall winnin_(int a1, int a2)
{
int v2; // ebx
int v3; // eax

v2 = objcts_[a1 + 1980];
v3 = v2 - fights_(a2, 1);
if ( v3 > 3 )
return prob_(90LL);
if ( v3 > 0 )
return prob_(75LL);
if ( !v3 )
return prob_(50LL);
if ( v2 <= 1 )
return prob_(10LL);
return prob_(25LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
int v2; // ebx
int v3; // eax

v2 = objcts_[a1 + 1980];
v3 = v2 - func2(a2, 1);
if ( v3 > 3 )
return prob_(90LL);
if ( v3 > 0 )
return prob_(75LL);
if ( !v3 )
return prob_(50LL);
if ( v2 <= 1 )
return prob_(10LL);
return prob_(25LL);
}

original_code:
logical winnin_(integer vl, integer hr)
{
   logical ret_val;
   integer ps, vs;
   vs = objcts_.ocapac[vl - 1];
   ps = vs - fights_(hr, 1);
   if (ps > 3) {
      ret_val = prob_(90, 100);
   }
   else if (ps > 0) {
      ret_val = prob_(75, 85);
   }
   else if (ps == 0) {
      ret_val = prob_(50, 30);
   }
   else if (vs > 1) {
      ret_val = prob_(25, 25);
   }
   else {
      ret_val = prob_(10, 0);
   }
   return ret_val;
}

canonical_original_code:
int winnin_(int vl, int hr)
{
   int ret_val;
   int ps; int vs;
   vs = objcts_.ocapac[vl - 1];
   ps = vs - fights_(hr, 1);
   if (ps > 3) {
      ret_val = prob_(90, 100);
   }
   else if (ps > 0) {
      ret_val = prob_(75, 85);
   }
   else if (ps == 0) {
      ret_val = prob_(50, 30);
   }
   else if (vs > 1) {
      ret_val = prob_(25, 25);
   }
   else {
      ret_val = prob_(10, 0);
   }
   return ret_val;
}

variable_types: vl int

variable_types: hr int

variable_types: ps int

variable_types: vs int


original_code:
integer vilstr_(integer v)
{
   integer ret_val, i__1, i__2, i__3;
   integer i;
   ret_val = objcts_.ocapac[v - 1];
   if (ret_val <= 0) {
      return ret_val;
   }
   if (v == oindex_.thief && findex_.thfenf) {
      findex_.thfenf = (0);
      ret_val = ((ret_val) <= (2) ? (ret_val) : (2));
   }
   for (i = 1; i <= vill_.vlnt; ++i) {
      if (vill_.villns[i - 1] == v && prsvec_.prsi == vill_.vbest[i - 1]
         ) {
         i__2 = 1, i__3 = ret_val - 1;
         ret_val = ((i__2) >= (i__3) ? (i__2) : (i__3));
      }
   }
   return ret_val;
}

canonical_original_code:
int vilstr_(int v)
{
   int ret_val; int i__1; int i__2; int i__3;
   int i;
   ret_val = objcts_.ocapac[v - 1];
   if (ret_val <= 0) {
      return ret_val;
   }
   if (v == oindex_.thief && findex_.thfenf) {
      findex_.thfenf = (0);
      ret_val = ((ret_val) <= (2) ? (ret_val) : (2));
   }
   for (i = 1; i <= vill_.vlnt; ++i) {
      if (vill_.villns[i - 1] == v && prsvec_.prsi == vill_.vbest[i - 1]
         ) {
         i__2 = 1, i__3 = ret_val - 1;
         ret_val = ((i__2) >= (i__3) ? (i__2) : (i__3));
      }
   }
   return ret_val;
}

variable_types: v int

variable_types: i int


decompiled_code:
_BOOL8 __fastcall ghere_(int a1, int a2)
{
_BOOL8 result; // rax

switch ( a1 - star_[1] )
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
result = 1LL;
break;
case 13:
if ( *((_DWORD *)&rindex_ + 7) <= a2 )
{
result = 0LL;
if ( *((_DWORD *)&rindex_ + 9) > a2 )
result = *((_DWORD *)&rindex_ + 8) != a2;
}
else
{
result = 0LL;
}
break;
case 14:
if ( *((_DWORD *)&rindex_ + 56) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 59) < a2) )
result = *((_DWORD *)&rindex_ + 85) == a2;
break;
case 15:
case 16:
case 17:
if ( *((_DWORD *)&rindex_ + 56) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 59) <= a2) )
result = *((_DWORD *)&rindex_ + 85) == a2;
break;
case 18:
result = (rooms_[a2 + 1000] & 0x1200) != 0;
break;
case 19:
if ( *((_DWORD *)&rindex_ + 66) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 68) < a2) )
{
if ( *((_DWORD *)&rindex_ + 71) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 75) < a2) )
result = *((_DWORD *)&rindex_ + 76) == a2;
}
break;
case 20:
case 23:
if ( *((_DWORD *)&rindex_ + 64) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 68) < a2) )
result = *((_DWORD *)&rindex_ + 76) == a2;
break;
case 21:
goto LABEL_12;
case 22:
result = 1LL;
if ( *((_DWORD *)&rindex_ + 69) != a2 )
{
LABEL_12:
if ( *((_DWORD *)&rindex_ + 64) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 66) < a2) )
{
result = 0LL;
if ( *((_DWORD *)&rindex_ + 70) <= a2 )
result = *((_DWORD *)&rindex_ + 72) >= a2;
}
}
break;
case 24:
result = 1LL;
if ( *((_DWORD *)&rindex_ + 69) != a2 )
{
result = 1LL;
if ( *((_DWORD *)&rindex_ + 78) != a2 && *((_DWORD *)&rindex_ + 79) != a2 )
result = *((_DWORD *)&rindex_ + 80) == a2;
}
break;
case 25:
result = *((_DWORD *)&rindex_ + 85) == a2;
break;
default:
if ( *((_DWORD *)&rindex_ + 7) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 9) <= a2) )
result = *((_DWORD *)&rindex_ + 54) == a2;
break;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, int a2)
{
_BOOL8 result; // rax

switch ( a1 - star_[1] )
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
result = 1LL;
break;
case 13:
if ( *((_DWORD *)&rindex_ + 7) <= a2 )
{
result = 0LL;
if ( *((_DWORD *)&rindex_ + 9) > a2 )
result = *((_DWORD *)&rindex_ + 8) != a2;
}
else
{
result = 0LL;
}
break;
case 14:
if ( *((_DWORD *)&rindex_ + 56) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 59) < a2) )
result = *((_DWORD *)&rindex_ + 85) == a2;
break;
case 15:
case 16:
case 17:
if ( *((_DWORD *)&rindex_ + 56) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 59) <= a2) )
result = *((_DWORD *)&rindex_ + 85) == a2;
break;
case 18:
result = (rooms_[a2 + 1000] & 0x1200) != 0;
break;
case 19:
if ( *((_DWORD *)&rindex_ + 66) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 68) < a2) )
{
if ( *((_DWORD *)&rindex_ + 71) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 75) < a2) )
result = *((_DWORD *)&rindex_ + 76) == a2;
}
break;
case 20:
case 23:
if ( *((_DWORD *)&rindex_ + 64) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 68) < a2) )
result = *((_DWORD *)&rindex_ + 76) == a2;
break;
case 21:
goto LABEL_12;
case 22:
result = 1LL;
if ( *((_DWORD *)&rindex_ + 69) != a2 )
{
LABEL_12:
if ( *((_DWORD *)&rindex_ + 64) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 66) < a2) )
{
result = 0LL;
if ( *((_DWORD *)&rindex_ + 70) <= a2 )
result = *((_DWORD *)&rindex_ + 72) >= a2;
}
}
break;
case 24:
result = 1LL;
if ( *((_DWORD *)&rindex_ + 69) != a2 )
{
result = 1LL;
if ( *((_DWORD *)&rindex_ + 78) != a2 && *((_DWORD *)&rindex_ + 79) != a2 )
result = *((_DWORD *)&rindex_ + 80) == a2;
}
break;
case 25:
result = *((_DWORD *)&rindex_ + 85) == a2;
break;
default:
if ( *((_DWORD *)&rindex_ + 7) > a2 || (result = 1LL, *((_DWORD *)&rindex_ + 9) <= a2) )
result = *((_DWORD *)&rindex_ + 54) == a2;
break;
}
return result;
}

original_code:
logical ghere_(integer obj, integer rm)
{
   logical ret_val;
   ret_val = (1);
   switch (obj - star_.strbit) {
   case 1:
   case 2:
   case 3:
   case 4:
   case 5:
   case 6:
   case 7:
   case 8:
   case 9:
   case 10:
   case 11:
      return (1);
   case 12: goto L2000;
   case 13: goto L3000;
   case 14: goto L4000;
   case 15: goto L5000;
   case 16: goto L5000;
   case 17: goto L5000;
   case 18: goto L6000;
   case 19: goto L7000;
   case 20: goto L8000;
   case 21: goto L9000;
   case 22: goto L9100;
   case 23: goto L8000;
   case 24: goto L10000;
   case 25: goto L11000;
   }
L2000:
   ret_val = rm >= rindex_.fore1 && rm < rindex_.clear || rm ==
      rindex_.mtree;
   return ret_val;
L3000:
   ret_val = rm >= rindex_.fore1 && rm < rindex_.clear && rm !=
      rindex_.fore3;
   return ret_val;
L4000:
   ret_val = rm >= rindex_.bkvw && rm <= rindex_.bkbox || rm ==
      rindex_.cpuzz;
   return ret_val;
L5000:
   ret_val = rm >= rindex_.bkvw && rm < rindex_.bkbox || rm ==
      rindex_.cpuzz;
   return ret_val;
L6000:
   ret_val = (rooms_.rflag[rm - 1] & (4096) + (512)) != 0;
   return ret_val;
L7000:
   ret_val = rm >= rindex_.mrc && rm <= rindex_.mrd || rm >=
      rindex_.mrce && rm <= rindex_.mrdw || rm == rindex_.inmir;
   return ret_val;
L8000:
   ret_val = rm >= rindex_.mra && rm <= rindex_.mrd || rm ==
      rindex_.inmir;
   return ret_val;
L9100:
   if (rm == rindex_.fdoor) {
      return ret_val;
   }
L9000:
   ret_val = rm >= rindex_.mra && rm <= rindex_.mrc || rm >=
      rindex_.mrae && rm <= rindex_.mrcw;
   return ret_val;
L10000:
   ret_val = rm == rindex_.fdoor || rm == rindex_.ncorr || rm ==
      rindex_.parap || rm == rindex_.cell;
   return ret_val;
L11000:
   ret_val = rm == rindex_.cpuzz;
   return ret_val;
}

canonical_original_code:
int ghere_(int obj, int rm)
{
   int ret_val;
   ret_val = (1);
   switch (obj - star_.strbit) {
   case 1:
   case 2:
   case 3:
   case 4:
   case 5:
   case 6:
   case 7:
   case 8:
   case 9:
   case 10:
   case 11:
      return (1);
   case 12: goto L2000;
   case 13: goto L3000;
   case 14: goto L4000;
   case 15: goto L5000;
   case 16: goto L5000;
   case 17: goto L5000;
   case 18: goto L6000;
   case 19: goto L7000;
   case 20: goto L8000;
   case 21: goto L9000;
   case 22: goto L9100;
   case 23: goto L8000;
   case 24: goto L10000;
   case 25: goto L11000;
   }
L2000:
   ret_val = rm >= rindex_.fore1 && rm < rindex_.clear || rm ==
      rindex_.mtree;
   return ret_val;
L3000:
   ret_val = rm >= rindex_.fore1 && rm < rindex_.clear && rm !=
      rindex_.fore3;
   return ret_val;
L4000:
   ret_val = rm >= rindex_.bkvw && rm <= rindex_.bkbox || rm ==
      rindex_.cpuzz;
   return ret_val;
L5000:
   ret_val = rm >= rindex_.bkvw && rm < rindex_.bkbox || rm ==
      rindex_.cpuzz;
   return ret_val;
L6000:
   ret_val = (rooms_.rflag[rm - 1] & (4096) + (512)) != 0;
   return ret_val;
L7000:
   ret_val = rm >= rindex_.mrc && rm <= rindex_.mrd || rm >=
      rindex_.mrce && rm <= rindex_.mrdw || rm == rindex_.inmir;
   return ret_val;
L8000:
   ret_val = rm >= rindex_.mra && rm <= rindex_.mrd || rm ==
      rindex_.inmir;
   return ret_val;
L9100:
   if (rm == rindex_.fdoor) {
      return ret_val;
   }
L9000:
   ret_val = rm >= rindex_.mra && rm <= rindex_.mrc || rm >=
      rindex_.mrae && rm <= rindex_.mrcw;
   return ret_val;
L10000:
   ret_val = rm == rindex_.fdoor || rm == rindex_.ncorr || rm ==
      rindex_.parap || rm == rindex_.cell;
   return ret_val;
L11000:
   ret_val = rm == rindex_.cpuzz;
   return ret_val;
}

variable_types: obj int

variable_types: rm int


decompiled_code:
__int64 __fastcall mrhere_(int a1)
{
__int64 result; // rax
int v2; // esi
int v3; // ecx

if ( *((_DWORD *)&rindex_ + 70) <= a1 && *((_DWORD *)&rindex_ + 75) >= a1 )
return (unsigned int)((a1 - *((_DWORD *)&rindex_ + 70)) % 2 == findex_[57] / 180) + 1;
v2 = findex_[58];
result = abs32(v2 - a1);
if ( (_DWORD)result != 1 )
return 0LL;
v3 = findex_[57];
if ( !(v3 % 180) )
return 0LL;
if ( v3 <= 179 && v2 > a1 )
return 2LL;
if ( v3 > 180 && v2 < a1 )
result = 2LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
int v2; // esi
int v3; // ecx

if ( *((_DWORD *)&rindex_ + 70) <= a1 && *((_DWORD *)&rindex_ + 75) >= a1 )
return (unsigned int)((a1 - *((_DWORD *)&rindex_ + 70)) % 2 == findex_[57] / 180) + 1;
v2 = findex_[58];
result = abs32(v2 - a1);
if ( (_DWORD)result != 1 )
return 0LL;
v3 = findex_[57];
if ( !(v3 % 180) )
return 0LL;
if ( v3 <= 179 && v2 > a1 )
return 2LL;
if ( v3 > 180 && v2 < a1 )
result = 2LL;
return result;
}

original_code:
integer mrhere_(integer rm)
{
   integer ret_val;
   if (rm < rindex_.mrae || rm > rindex_.mrdw) {
      goto L100;
   }
   ret_val = 1;
   if ((rm - rindex_.mrae) % 2 == findex_.mdir / 180) {
      ret_val = 2;
   }
   return ret_val;
L100:
   ret_val = 0;
   if ((((findex_.mloc - rm) >= 0 ? (findex_.mloc - rm) : -(findex_.mloc - rm))) != 1 || findex_.mdir % 180 ==
         0) {
      return ret_val;
   }
   ret_val = 1;
   if (rm < findex_.mloc && findex_.mdir < 180 || rm > findex_.mloc &&
         findex_.mdir > 180) {
      ret_val = 2;
   }
   return ret_val;
}

canonical_original_code:
int mrhere_(int rm)
{
   int ret_val;
   if (rm < rindex_.mrae || rm > rindex_.mrdw) {
      goto L100;
   }
   ret_val = 1;
   if ((rm - rindex_.mrae) % 2 == findex_.mdir / 180) {
      ret_val = 2;
   }
   return ret_val;
L100:
   ret_val = 0;
   if ((((findex_.mloc - rm) >= 0 ? (findex_.mloc - rm) : -(findex_.mloc - rm))) != 1 || findex_.mdir % 180 ==
         0) {
      return ret_val;
   }
   ret_val = 1;
   if (rm < findex_.mloc && findex_.mdir < 180 || rm > findex_.mloc &&
         findex_.mdir > 180) {
      ret_val = 2;
   }
   return ret_val;
}


decompiled_code:
__int64 __fastcall valuac_(int a1)
{
unsigned int v2; // ebp
int v3; // er13
int v4; // er12
__int64 result; // rax
__int64 v6; // rdi
unsigned int v7; // eax
unsigned int v8; // edx
int v9; // er14
int v10; // eax
int v11; // edx
__int64 v12; // rdi

if ( (unsigned int)lit_(*((unsigned int *)&play_ + 1)) )
{
v2 = prsvec_[2];
v3 = *((_DWORD *)&play_ + 1);
if ( prsvec_[0] == vindex_[40] )
{
prsvec_[2] = 1;
if ( (int)objcts_[0] > 0 )
{
v4 = 1;
v6 = 1LL;
do
{
if ( (unsigned int)qhere_(v6, *((unsigned int *)&play_ + 1)) )
{
v7 = prsvec_[2] - 1;
if ( (BYTE1(objcts_[v7 + 881]) & 0x80u) != 0 )
{
v8 = objcts_[v7 + 1101];
v9 = v8 & 0x400;
if ( (v8 & 0x400) == 0 && (v2 != a1 || (int)objcts_[v7 + 1541] > 0) )
{
if ( v8 & 0x20 | objcts_[v7 + 881] & 0x2000 )
{
rspsub_(580LL, objcts_[v7 + 221]);
result = take_(1);
if ( *((_DWORD *)&play_ + 1) != v3 )
return result;
v4 = v9;
}
}
}
}
result = prsvec_[2];
v6 = (unsigned int)(result + 1);
prsvec_[2] = v6;
}
while ( (int)v6 <= (int)objcts_[0] );
LABEL_37:
v12 = (unsigned int)(v2 == a1) + 581;
if ( !v4 )
return result;
return rspeak_(v12);
}
}
else
{
if ( prsvec_[0] != vindex_[53] )
{
if ( prsvec_[0] == vindex_[52] )
{
prsvec_[2] = 1;
if ( (int)objcts_[0] > 0 )
{
v4 = 1;
LODWORD(result) = 1;
while ( 1 )
{
v11 = result - 1;
if ( objcts_[(int)result + 2420] == play_
&& prsvec_[1] != (_DWORD)result
&& (v2 != a1 || (int)objcts_[v11 + 1541] > 0)
&& (objcts_[v11 + 881] & 0x8000) != 0 )
{
rspsub_(580LL, objcts_[v11 + 221]);
result = put_(1LL);
if ( *((_DWORD *)&play_ + 1) != v3 )
return result;
v4 = 0;
}
result = prsvec_[2] + 1;
prsvec_[2] = result;
if ( (int)result > (int)objcts_[0] )
goto LABEL_37;
}
}
}
v12 = (unsigned int)(v2 == a1) + 581;
return rspeak_(v12);
}
prsvec_[2] = 1;
if ( (int)objcts_[0] > 0 )
{
v4 = 1;
LODWORD(result) = 1;
do
{
v10 = result - 1;
if ( objcts_[v10 + 2421] == play_ && (v2 != a1 || (int)objcts_[v10 + 1541] > 0) )
{
rspsub_(580LL, objcts_[v10 + 221]);
result = drop_(1LL);
if ( *((_DWORD *)&play_ + 1) != v3 )
return result;
v4 = 0;
}
result = prsvec_[2] + 1;
prsvec_[2] = result;
}
while ( (int)result <= (int)objcts_[0] );
goto LABEL_37;
}
}
v12 = (unsigned int)(v2 == a1) + 581;
}
else
{
v12 = 579LL;
}
return rspeak_(v12);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
unsigned int v2; // ebp
int v3; // er13
int v4; // er12
__int64 result; // rax
__int64 v6; // rdi
unsigned int v7; // eax
unsigned int v8; // edx
int v9; // er14
int v10; // eax
int v11; // edx
__int64 v12; // rdi

if ( (unsigned int)lit_(*((unsigned int *)&play_ + 1)) )
{
v2 = prsvec_[2];
v3 = *((_DWORD *)&play_ + 1);
if ( prsvec_[0] == vindex_[40] )
{
prsvec_[2] = 1;
if ( (int)objcts_[0] > 0 )
{
v4 = 1;
v6 = 1LL;
do
{
if ( (unsigned int)qhere_(v6, *((unsigned int *)&play_ + 1)) )
{
v7 = prsvec_[2] - 1;
if ( (BYTE1(objcts_[v7 + 881]) & 0x80u) != 0 )
{
v8 = objcts_[v7 + 1101];
v9 = v8 & 0x400;
if ( (v8 & 0x400) == 0 && (v2 != a1 || (int)objcts_[v7 + 1541] > 0) )
{
if ( v8 & 0x20 | objcts_[v7 + 881] & 0x2000 )
{
rspsub_(580LL, objcts_[v7 + 221]);
result = func0(1);
if ( *((_DWORD *)&play_ + 1) != v3 )
return result;
v4 = v9;
}
}
}
}
result = prsvec_[2];
v6 = (unsigned int)(result + 1);
prsvec_[2] = v6;
}
while ( (int)v6 <= (int)objcts_[0] );
LABEL_37:
v12 = (unsigned int)(v2 == a1) + 581;
if ( !v4 )
return result;
return rspeak_(v12);
}
}
else
{
if ( prsvec_[0] != vindex_[53] )
{
if ( prsvec_[0] == vindex_[52] )
{
prsvec_[2] = 1;
if ( (int)objcts_[0] > 0 )
{
v4 = 1;
LODWORD(result) = 1;
while ( 1 )
{
v11 = result - 1;
if ( objcts_[(int)result + 2420] == play_
&& prsvec_[1] != (_DWORD)result
&& (v2 != a1 || (int)objcts_[v11 + 1541] > 0)
&& (objcts_[v11 + 881] & 0x8000) != 0 )
{
rspsub_(580LL, objcts_[v11 + 221]);
result = func1(1LL);
if ( *((_DWORD *)&play_ + 1) != v3 )
return result;
v4 = 0;
}
result = prsvec_[2] + 1;
prsvec_[2] = result;
if ( (int)result > (int)objcts_[0] )
goto LABEL_37;
}
}
}
v12 = (unsigned int)(v2 == a1) + 581;
return rspeak_(v12);
}
prsvec_[2] = 1;
if ( (int)objcts_[0] > 0 )
{
v4 = 1;
LODWORD(result) = 1;
do
{
v10 = result - 1;
if ( objcts_[v10 + 2421] == play_ && (v2 != a1 || (int)objcts_[v10 + 1541] > 0) )
{
rspsub_(580LL, objcts_[v10 + 221]);
result = func2(1LL);
if ( *((_DWORD *)&play_ + 1) != v3 )
return result;
v4 = 0;
}
result = prsvec_[2] + 1;
prsvec_[2] = result;
}
while ( (int)result <= (int)objcts_[0] );
goto LABEL_37;
}
}
v12 = (unsigned int)(v2 == a1) + 581;
}
else
{
v12 = 579LL;
}
return rspeak_(v12);
}

original_code:
void valuac_(integer v)
{
   logical f;
   integer i;
   logical f1;
   integer savep, saveh;
   f = (1);
   i = 579;
   if (! lit_(play_.here)) {
      goto L4000;
   }
   i = 677;
   savep = prsvec_.prso;
   saveh = play_.here;
   if (prsvec_.prsa != vindex_.takew) {
      goto L1000;
   }
   for (prsvec_.prso = 1; prsvec_.prso <= objcts_.olnt; ++prsvec_.prso) {
      if (! qhere_(prsvec_.prso, play_.here) || (objcts_.oflag1[
               prsvec_.prso - 1] & (32768)) == 0 || (
                  objcts_.oflag2[prsvec_.prso - 1] & (1024)) != 0 ||
            savep == v && objcts_.otval[prsvec_.prso - 1] <= 0) {
         continue;
      }
      if ((objcts_.oflag1[prsvec_.prso - 1] & (8192)) == 0 && (
               objcts_.oflag2[prsvec_.prso - 1] & (32)) == 0) {
         continue;
      }
      f = (0);
      rspsub_(580, objcts_.odesc2[prsvec_.prso - 1]);
      f1 = take_(1);
      if (saveh != play_.here) {
         return;
      }
   }
   goto L3000;
L1000:
   if (prsvec_.prsa != vindex_.dropw) {
      goto L2000;
   }
   for (prsvec_.prso = 1; prsvec_.prso <= objcts_.olnt; ++prsvec_.prso) {
      if (objcts_.oadv[prsvec_.prso - 1] != play_.winner || savep == v
            && objcts_.otval[prsvec_.prso - 1] <= 0) {
         continue;
      }
      f = (0);
      rspsub_(580, objcts_.odesc2[prsvec_.prso - 1]);
      f1 = drop_(1);
      if (saveh != play_.here) {
         return;
      }
   }
   goto L3000;
L2000:
   if (prsvec_.prsa != vindex_.putw) {
      goto L3000;
   }
   for (prsvec_.prso = 1; prsvec_.prso <= objcts_.olnt; ++prsvec_.prso) {
      if (objcts_.oadv[prsvec_.prso - 1] != play_.winner ||
            prsvec_.prso == prsvec_.prsi || savep == v &&
            objcts_.otval[prsvec_.prso - 1] <= 0 || (objcts_.oflag1[
               prsvec_.prso - 1] & (32768)) == 0) {
         continue;
      }
      f = (0);
      rspsub_(580, objcts_.odesc2[prsvec_.prso - 1]);
      f1 = put_(1);
      if (saveh != play_.here) {
         return;
      }
   }
L3000:
   i = 581;
   if (savep == v) {
      i = 582;
   }
L4000:
   if (f) {
      rspeak_(i);
   }
}

canonical_original_code:
void valuac_(int v)
{
   int f;
   int i;
   int f1;
   int savep; int saveh;
   f = (1);
   i = 579;
   if (! lit_(play_.here)) {
      goto L4000;
   }
   i = 677;
   savep = prsvec_.prso;
   saveh = play_.here;
   if (prsvec_.prsa != vindex_.takew) {
      goto L1000;
   }
   for (prsvec_.prso = 1; prsvec_.prso <= objcts_.olnt; ++prsvec_.prso) {
      if (! qhere_(prsvec_.prso, play_.here) || (objcts_.oflag1[
               prsvec_.prso - 1] & (32768)) == 0 || (
                  objcts_.oflag2[prsvec_.prso - 1] & (1024)) != 0 ||
            savep == v && objcts_.otval[prsvec_.prso - 1] <= 0) {
         continue;
      }
      if ((objcts_.oflag1[prsvec_.prso - 1] & (8192)) == 0 && (
               objcts_.oflag2[prsvec_.prso - 1] & (32)) == 0) {
         continue;
      }
      f = (0);
      rspsub_(580, objcts_.odesc2[prsvec_.prso - 1]);
      f1 = take_(1);
      if (saveh != play_.here) {
         return;
      }
   }
   goto L3000;
L1000:
   if (prsvec_.prsa != vindex_.dropw) {
      goto L2000;
   }
   for (prsvec_.prso = 1; prsvec_.prso <= objcts_.olnt; ++prsvec_.prso) {
      if (objcts_.oadv[prsvec_.prso - 1] != play_.winner || savep == v
            && objcts_.otval[prsvec_.prso - 1] <= 0) {
         continue;
      }
      f = (0);
      rspsub_(580, objcts_.odesc2[prsvec_.prso - 1]);
      f1 = drop_(1);
      if (saveh != play_.here) {
         return;
      }
   }
   goto L3000;
L2000:
   if (prsvec_.prsa != vindex_.putw) {
      goto L3000;
   }
   for (prsvec_.prso = 1; prsvec_.prso <= objcts_.olnt; ++prsvec_.prso) {
      if (objcts_.oadv[prsvec_.prso - 1] != play_.winner ||
            prsvec_.prso == prsvec_.prsi || savep == v &&
            objcts_.otval[prsvec_.prso - 1] <= 0 || (objcts_.oflag1[
               prsvec_.prso - 1] & (32768)) == 0) {
         continue;
      }
      f = (0);
      rspsub_(580, objcts_.odesc2[prsvec_.prso - 1]);
      f1 = put_(1);
      if (saveh != play_.here) {
         return;
      }
   }
L3000:
   i = 581;
   if (savep == v) {
      i = 582;
   }
L4000:
   if (f) {
      rspeak_(i);
   }
}

variable_types: f int

variable_types: savep int

variable_types: saveh int