decompiled_code:
unsigned __int64 __fastcall sell_price(int a1, unsigned __int64 *a2, unsigned __int64 *a3, __int64 a4)
{
__int64 v6; // rax
unsigned __int64 v7; // r8
__int64 v8; // rax
unsigned __int64 result; // rax

v6 = item_value((unsigned __int16 *)a4);
if ( *(__int64 *)(a4 + 32) <= 0 || v6 <= 0 )
return 0LL;
v7 = 1LL;
v8 = *((unsigned __int8 *)&rgold_adj + 8 * owners[16 * store[1552 * a1 + 10] + 13] + py[105]) * v6;
if ( v8 > 99 )
v7 = v8 / 0x64uLL;
*a2 = v7 * owners[16 * store[1552 * a1 + 10] + 10] / 0x64;
result = v7;
*a3 = v7 * owners[16 * store[1552 * a1 + 10] + 11] / 0x64;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(int a1, unsigned __int64 *a2, unsigned __int64 *a3, __int64 a4)
{
__int64 v6; // rax
unsigned __int64 v7; // r8
__int64 v8; // rax
unsigned __int64 result; // rax

v6 = func1((unsigned __int16 *)a4);
if ( *(__int64 *)(a4 + 32) <= 0 || v6 <= 0 )
return 0LL;
v7 = 1LL;
v8 = *((unsigned __int8 *)&rgold_adj + 8 * owners[16 * store[1552 * a1 + 10] + 13] + py[105]) * v6;
if ( v8 > 99 )
v7 = v8 / 0x64uLL;
*a2 = v7 * owners[16 * store[1552 * a1 + 10] + 10] / 0x64;
result = v7;
*a3 = v7 * owners[16 * store[1552 * a1 + 10] + 11] / 0x64;
return result;
}

original_code:
int32 sell_price(int snum, int32 *max_sell, int32 *min_sell, inven_type *item)
{
  register int32 i;
  register store_type *s_ptr;
  s_ptr = &store[snum];
  i = item_value(item);
  if ((item->cost > 0) && (i > 0))
    {
      i = i * rgold_adj[owners[s_ptr->owner].owner_race][py.misc.prace] / 100;
      if (i < 1) i = 1;
      *max_sell = i * owners[s_ptr->owner].max_inflate / 100;
      *min_sell = i * owners[s_ptr->owner].min_inflate / 100;
      if (min_sell > max_sell) min_sell = max_sell;
      return(i);
    }
  else
    return(0);
}

canonical_original_code:
long sell_price(int snum, long *max_sell, long *min_sell, struct inven_type *item)
{
  register long i;
  register struct store_type *s_ptr;
  s_ptr = &store[snum];
  i = item_value(item);
  if ((item->cost > 0) && (i > 0))
    {
      i = i * rgold_adj[owners[s_ptr->owner].owner_race][py.misc.prace] / 100;
      if (i < 1) i = 1;
      *max_sell = i * owners[s_ptr->owner].max_inflate / 100;
      *min_sell = i * owners[s_ptr->owner].min_inflate / 100;
      if (min_sell > max_sell) min_sell = max_sell;
      return(i);
    }
  else
    return(0);
}

variable_types: snum int

variable_types: struct inven_type { unsigned short index; unsigned char name2; char inscrip[13]; unsigned long flags; unsigned char tval; unsigned char tchar; short p1; long cost; unsigned char subval; unsigned char number; unsigned short weight; short tohit; short todam; short ac; short toac; unsigned char damage[2]; unsigned char level; unsigned char ident; } *

variable_types: i long

variable_types: struct store_type { long store_open; short insult_cur; unsigned char owner; unsigned char store_ctr; unsigned short good_buy; unsigned short bad_buy; struct inven_record { long scost; struct inven_type { unsigned short index; unsigned char name2; char inscrip[13]; unsigned long flags; unsigned char tval; unsigned char tchar; short p1; long cost; unsigned char subval; unsigned char number; unsigned short weight; short tohit; short todam; short ac; short toac; unsigned char damage[2]; unsigned char level; unsigned char ident; } sitem; } store_inven[24]; } *

user_defined_types: struct store_type { long store_open; short insult_cur; unsigned char owner; unsigned char store_ctr; unsigned short good_buy; unsigned short bad_buy; struct inven_record store_inven[24]; }

user_defined_types: struct inven_record { long scost; struct inven_type sitem; }


repo: lollek/how-to-slay-your-balrog

original_code:
int store_check_num(inven_type *t_ptr, int store_num)
{
  register int store_check, i;
  register store_type *s_ptr;
  register inven_type *i_ptr;
  store_check = 0;
  s_ptr = &store[store_num];
  if (s_ptr->store_ctr < 24)
    store_check = 1;
  else if (t_ptr->subval >= 64)
    for (i = 0; i < s_ptr->store_ctr; i++)
      {
 i_ptr = &s_ptr->store_inven[i].sitem;
 if (i_ptr->tval == t_ptr->tval && i_ptr->subval == t_ptr->subval
     && ((int)i_ptr->number + (int)t_ptr->number < 256)
     && (t_ptr->subval < 192
  || (i_ptr->p1 == t_ptr->p1)))
   store_check = 1;
      }
  return(store_check);
}

canonical_original_code:
int store_check_num(struct inven_type *t_ptr, int store_num)
{
  register int store_check; register int i;
  register struct store_type *s_ptr;
  register struct inven_type *i_ptr;
  store_check = 0;
  s_ptr = &store[store_num];
  if (s_ptr->store_ctr < 24)
    store_check = 1;
  else if (t_ptr->subval >= 64)
    for (i = 0; i < s_ptr->store_ctr; i++)
      {
 i_ptr = &s_ptr->store_inven[i].sitem;
 if (i_ptr->tval == t_ptr->tval && i_ptr->subval == t_ptr->subval
     && ((int)i_ptr->number + (int)t_ptr->number < 256)
     && (t_ptr->subval < 192
  || (i_ptr->p1 == t_ptr->p1)))
   store_check = 1;
      }
  return(store_check);
}

variable_types: i int

return_type: int

user_defined_types: struct inven_type { unsigned short index; unsigned char name2; char inscrip[13]; unsigned long flags; unsigned char tval; unsigned char tchar; short p1; long cost; unsigned char subval; unsigned char number; unsigned short weight; short tohit; short todam; short ac; short toac; unsigned char damage[2]; unsigned char level; unsigned char ident; }


original_code:
void store_init()
{
  register int i, j, k;
  register store_type *s_ptr;
  i = 18 / 6;
  for (j = 0; j < 6; j++)
    {
      s_ptr = &store[j];
      s_ptr->owner = 6*(randint(i)-1) + j;
      s_ptr->insult_cur = 0;
      s_ptr->store_open = 0;
      s_ptr->store_ctr = 0;
      s_ptr->good_buy = 0;
      s_ptr->bad_buy = 0;
      for (k = 0; k < 24; k++)
 {
   invcopy(&s_ptr->store_inven[k].sitem, 417);
   s_ptr->store_inven[k].scost = 0;
 }
    }
}

canonical_original_code:
void store_init()
{
  register int i; register int j; register int k;
  register struct store_type *s_ptr;
  i = 18 / 6;
  for (j = 0; j < 6; j++)
    {
      s_ptr = &store[j];
      s_ptr->owner = 6*(randint(i)-1) + j;
      s_ptr->insult_cur = 0;
      s_ptr->store_open = 0;
      s_ptr->store_ctr = 0;
      s_ptr->good_buy = 0;
      s_ptr->bad_buy = 0;
      for (k = 0; k < 24; k++)
 {
   invcopy(&s_ptr->store_inven[k].sitem, 417);
   s_ptr->store_inven[k].scost = 0;
 }
    }
}

variable_types: j int

variable_types: k int

return_type: void


decompiled_code:
__int64 store_maint()
{
int v0; // ebp
unsigned __int64 v1; // rbx
bool v2; // cc
int v3; // er13
__int64 result; // rax
int v5; // er13
bool v6; // cf
__int64 v7; // rdi
int v8; // er13
int v9; // er13
int v10; // eax

v0 = 0;
v1 = (unsigned int)((_DWORD)store + 11);
do
{
while ( 1 )
{
v2 = *(_BYTE *)v1 <= 9u;
*(_WORD *)(v1 - 3) = 0;
if ( v2 )
break;
result = randint(9LL);
v7 = *(unsigned __int8 *)v1;
v8 = result;
if ( (unsigned __int8)v7 > 0x11u )
{
result = (unsigned __int8)v7;
v8 = v8 + (unsigned __int8)v7 - 17;
}
v9 = v8 - 1;
if ( v9 >= 0 )
{
while ( 1 )
{
v10 = randint(v7);
result = store_destroy(v0, v10 - 1, 0);
v6 = v9-- == 0;
if ( v6 )
break;
v7 = *(unsigned __int8 *)v1;
}
LOBYTE(v7) = *(_BYTE *)v1;
}
if ( (unsigned __int8)v7 <= 0x12u )
break;
++v0;
v1 += 1552LL;
if ( v0 == 6 )
return result;
}
v3 = randint(9LL);
result = *(unsigned __int8 *)v1;
if ( (unsigned __int8)result <= 9u )
v3 += 10 - result;
v5 = v3 - 1;
if ( v5 >= 0 )
{
do
{
result = store_create(v0);
v6 = v5-- == 0;
}
while ( !v6 );
}
++v0;
v1 += 1552LL;
}
while ( v0 != 6 );
return result;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebp
unsigned __int64 v1; // rbx
bool v2; // cc
int v3; // er13
__int64 result; // rax
int v5; // er13
bool v6; // cf
__int64 v7; // rdi
int v8; // er13
int v9; // er13
int v10; // eax

v0 = 0;
v1 = (unsigned int)((_DWORD)store + 11);
do
{
while ( 1 )
{
v2 = *(_BYTE *)v1 <= 9u;
*(_WORD *)(v1 - 3) = 0;
if ( v2 )
break;
result = randint(9LL);
v7 = *(unsigned __int8 *)v1;
v8 = result;
if ( (unsigned __int8)v7 > 0x11u )
{
result = (unsigned __int8)v7;
v8 = v8 + (unsigned __int8)v7 - 17;
}
v9 = v8 - 1;
if ( v9 >= 0 )
{
while ( 1 )
{
v10 = randint(v7);
result = func6(v0, v10 - 1, 0);
v6 = v9-- == 0;
if ( v6 )
break;
v7 = *(unsigned __int8 *)v1;
}
LOBYTE(v7) = *(_BYTE *)v1;
}
if ( (unsigned __int8)v7 <= 0x12u )
break;
++v0;
v1 += 1552LL;
if ( v0 == 6 )
return result;
}
v3 = randint(9LL);
result = *(unsigned __int8 *)v1;
if ( (unsigned __int8)result <= 9u )
v3 += 10 - result;
v5 = v3 - 1;
if ( v5 >= 0 )
{
do
{
result = func5(v0);
v6 = v5-- == 0;
}
while ( !v6 );
}
++v0;
v1 += 1552LL;
}
while ( v0 != 6 );
return result;
}

original_code:
void store_maint()
{
  register int i, j;
  register store_type *s_ptr;
  for (i = 0; i < 6; i++)
    {
      s_ptr = &store[i];
      s_ptr->insult_cur = 0;
      if (s_ptr->store_ctr >= 10)
 {
   j = randint(9);
   if (s_ptr->store_ctr >= 18)
     j += 1 + s_ptr->store_ctr - 18;
   while (--j >= 0)
     store_destroy(i, randint((int)s_ptr->store_ctr)-1, 0);
 }
      if (s_ptr->store_ctr <= 18)
 {
   j = randint(9);
   if (s_ptr->store_ctr < 10)
     j += 10 - s_ptr->store_ctr;
   while (--j >= 0)
     store_create(i);
 }
    }
}

canonical_original_code:
void store_maint()
{
  register int i; register int j;
  register struct store_type *s_ptr;
  for (i = 0; i < 6; i++)
    {
      s_ptr = &store[i];
      s_ptr->insult_cur = 0;
      if (s_ptr->store_ctr >= 10)
 {
   j = randint(9);
   if (s_ptr->store_ctr >= 18)
     j += 1 + s_ptr->store_ctr - 18;
   while (--j >= 0)
     store_destroy(i, randint((int)s_ptr->store_ctr)-1, 0);
 }
      if (s_ptr->store_ctr <= 18)
 {
   j = randint(9);
   if (s_ptr->store_ctr < 10)
     j += 10 - s_ptr->store_ctr;
   while (--j >= 0)
     store_create(i);
 }
    }
}


decompiled_code:
__int64 ident_char()
{
__int64 v0; // rbx
int v1; // er12
__int64 result; // rax
char v4; // bp
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( (unsigned int)get_com("Enter character to be identified :", v5) )
{
switch ( v5[0] )
{
case ' ':
prt(" - An open pit.", 0LL, 0LL);
break;
case '!':
prt("! - A potion.", 0LL, 0LL);
break;
case '"':
prt("\" - An amulet, periapt, or necklace.", 0LL, 0LL);
break;
case '#':
prt("# - A stone wall.", 0LL, 0LL);
break;
case '$':
prt("$ - Treasure.", 0LL, 0LL);
break;
case '%':
if ( highlight_seams == 1 )
prt("% - A magma or quartz vein.", 0LL, 0LL);
else
prt("% - Not used.", 0LL, 0LL);
break;
case '&':
prt("& - Treasure chest.", 0LL, 0LL);
break;
case '\'':
prt("' - An open door.", 0LL, 0LL);
break;
case '(':
prt("( - Soft armor.", 0LL, 0LL);
break;
case ')':
prt(") - A shield.", 0LL, 0LL);
break;
case '*':
prt("* - Gems.", 0LL, 0LL);
break;
case '+':
prt("+ - A closed door.", 0LL, 0LL);
break;
case ',':
prt(", - Food or mushroom patch.", 0LL, 0LL);
break;
case '-':
prt("- - A wand", 0LL, 0LL);
break;
case '.':
prt(". - Floor.", 0LL, 0LL);
break;
case '/':
prt("/ - A pole weapon.", 0LL, 0LL);
break;
case '1':
prt("1 - Entrance to General Store.", 0LL, 0LL);
break;
case '2':
prt("2 - Entrance to Armory.", 0LL, 0LL);
break;
case '3':
prt("3 - Entrance to Weaponsmith.", 0LL, 0LL);
break;
case '4':
prt("4 - Entrance to Temple.", 0LL, 0LL);
break;
case '5':
prt("5 - Entrance to Alchemy shop.", 0LL, 0LL);
break;
case '6':
prt("6 - Entrance to Magic-Users store.", 0LL, 0LL);
break;
case ':':
prt(": - Rubble.", 0LL, 0LL);
break;
case ';':
prt("; - A loose rock.", 0LL, 0LL);
break;
case '<':
prt("< - An up staircase.", 0LL, 0LL);
break;
case '=':
prt("= - A ring.", 0LL, 0LL);
break;
case '>':
prt("> - A down staircase.", 0LL, 0LL);
break;
case '?':
prt("? - A scroll.", 0LL, 0LL);
break;
case '@':
prt((const char *)&py, 0LL, 0LL);
break;
case 'A':
prt("A - Giant Ant Lion.", 0LL, 0LL);
break;
case 'B':
prt("B - The Balrog.", 0LL, 0LL);
break;
case 'C':
prt("C - Gelatinous Cube.", 0LL, 0LL);
break;
case 'D':
prt("D - An Ancient Dragon (Beware).", 0LL, 0LL);
break;
case 'E':
prt("E - Elemental.", 0LL, 0LL);
break;
case 'F':
prt("F - Giant Fly.", 0LL, 0LL);
break;
case 'G':
prt("G - Ghost.", 0LL, 0LL);
break;
case 'H':
prt("H - Hobgoblin.", 0LL, 0LL);
break;
case 'J':
prt("J - Jelly.", 0LL, 0LL);
break;
case 'K':
prt("K - Killer Beetle.", 0LL, 0LL);
break;
case 'L':
prt("L - Lich.", 0LL, 0LL);
break;
case 'M':
prt("M - Mummy.", 0LL, 0LL);
break;
case 'O':
prt("O - Ooze.", 0LL, 0LL);
break;
case 'P':
prt("P - Giant humanoid.", 0LL, 0LL);
break;
case 'Q':
prt("Q - Quylthulg (Pulsing Flesh Mound).", 0LL, 0LL);
break;
case 'R':
prt("R - Reptile.", 0LL, 0LL);
break;
case 'S':
prt("S - Giant Scorpion.", 0LL, 0LL);
break;
case 'T':
prt("T - Troll.", 0LL, 0LL);
break;
case 'U':
prt("U - Umber Hulk.", 0LL, 0LL);
break;
case 'V':
prt("V - Vampire.", 0LL, 0LL);
break;
case 'W':
prt("W - Wight or Wraith.", 0LL, 0LL);
break;
case 'X':
prt("X - Xorn.", 0LL, 0LL);
break;
case 'Y':
prt("Y - Yeti.", 0LL, 0LL);
break;
case '[':
prt("[ - Hard armor.", 0LL, 0LL);
break;
case '\\':
prt("\\ - A hafted weapon.", 0LL, 0LL);
break;
case ']':
prt("] - Misc. armor.", 0LL, 0LL);
break;
case '^':
prt("^ - A trap.", 0LL, 0LL);
break;
case '_':
prt("_ - A staff.", 0LL, 0LL);
break;
case 'a':
prt("a - Giant Ant.", 0LL, 0LL);
break;
case 'b':
prt("b - Giant Bat.", 0LL, 0LL);
break;
case 'c':
prt("c - Giant Centipede.", 0LL, 0LL);
break;
case 'd':
prt("d - Dragon.", 0LL, 0LL);
break;
case 'e':
prt("e - Floating Eye.", 0LL, 0LL);
break;
case 'f':
prt("f - Giant Frog.", 0LL, 0LL);
break;
case 'g':
prt("g - Golem.", 0LL, 0LL);
break;
case 'h':
prt("h - Harpy.", 0LL, 0LL);
break;
case 'i':
prt("i - Icky Thing.", 0LL, 0LL);
break;
case 'j':
prt("j - Jackal.", 0LL, 0LL);
break;
case 'k':
prt("k - Kobold.", 0LL, 0LL);
break;
case 'l':
prt("l - Giant Louse.", 0LL, 0LL);
break;
case 'm':
prt("m - Mold.", 0LL, 0LL);
break;
case 'n':
prt("n - Naga.", 0LL, 0LL);
break;
case 'o':
prt("o - Orc or Ogre.", 0LL, 0LL);
break;
case 'p':
prt("p - Person (Humanoid).", 0LL, 0LL);
break;
case 'q':
prt("q - Quasit.", 0LL, 0LL);
break;
case 'r':
prt("r - Rodent.", 0LL, 0LL);
break;
case 's':
prt("s - Skeleton.", 0LL, 0LL);
break;
case 't':
prt("t - Giant Tick.", 0LL, 0LL);
break;
case 'w':
prt("w - Worm or Worm Mass.", 0LL, 0LL);
break;
case 'y':
prt("y - Yeek.", 0LL, 0LL);
break;
case 'z':
prt("z - Zombie.", 0LL, 0LL);
break;
case '{':
prt("{ - Arrow, bolt, or bullet.", 0LL, 0LL);
break;
case '|':
prt("| - A sword or dagger.", 0LL, 0LL);
break;
case '}':
prt("} - Bow, crossbow, or sling.", 0LL, 0LL);
break;
case '~':
prt("~ - Miscellaneous item.", 0LL, 0LL);
break;
default:
prt("Not Used.", 0LL, 0LL);
break;
}
}
v0 = 278LL;
v1 = 0;
do
{
result = (unsigned int)v5[0];
if ( c_list[40 * v0 + 32] == (_DWORD)result )
{
result = bool_roff_recall((unsigned int)v0);
if ( (_DWORD)result )
{
if ( !v1 )
{
put_buffer("You recall those details? [y/n]", 0LL, 40LL);
result = inkey() & 0xFFFFFFDFLL;
if ( (_BYTE)result != 89 )
return result;
erase_line(0LL, 40LL);
save_screen();
}
++v1;
v4 = roff_recall((unsigned int)v0);
result = restore_screen();
if ( v4 == 27 )
break;
}
}
}
while ( v0-- != 0 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
int v1; // er12
__int64 result; // rax
char v4; // bp
char v5[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( (unsigned int)get_com("Enter character to be identified :", v5) )
{
switch ( v5[0] )
{
case ' ':
prt(" - An open pit.", 0LL, 0LL);
break;
case '!':
prt("! - A potion.", 0LL, 0LL);
break;
case '"':
prt("\" - An amulet, periapt, or necklace.", 0LL, 0LL);
break;
case '#':
prt("# - A stone wall.", 0LL, 0LL);
break;
case '$':
prt("$ - Treasure.", 0LL, 0LL);
break;
case '%':
if ( highlight_seams == 1 )
prt("% - A magma or quartz vein.", 0LL, 0LL);
else
prt("% - Not used.", 0LL, 0LL);
break;
case '&':
prt("& - Treasure chest.", 0LL, 0LL);
break;
case '\'':
prt("' - An open door.", 0LL, 0LL);
break;
case '(':
prt("( - Soft armor.", 0LL, 0LL);
break;
case ')':
prt(") - A shield.", 0LL, 0LL);
break;
case '*':
prt("* - Gems.", 0LL, 0LL);
break;
case '+':
prt("+ - A closed door.", 0LL, 0LL);
break;
case ',':
prt(", - Food or mushroom patch.", 0LL, 0LL);
break;
case '-':
prt("- - A wand", 0LL, 0LL);
break;
case '.':
prt(". - Floor.", 0LL, 0LL);
break;
case '/':
prt("/ - A pole weapon.", 0LL, 0LL);
break;
case '1':
prt("1 - Entrance to General Store.", 0LL, 0LL);
break;
case '2':
prt("2 - Entrance to Armory.", 0LL, 0LL);
break;
case '3':
prt("3 - Entrance to Weaponsmith.", 0LL, 0LL);
break;
case '4':
prt("4 - Entrance to Temple.", 0LL, 0LL);
break;
case '5':
prt("5 - Entrance to Alchemy shop.", 0LL, 0LL);
break;
case '6':
prt("6 - Entrance to Magic-Users store.", 0LL, 0LL);
break;
case ':':
prt(": - Rubble.", 0LL, 0LL);
break;
case ';':
prt("; - A loose rock.", 0LL, 0LL);
break;
case '<':
prt("< - An up staircase.", 0LL, 0LL);
break;
case '=':
prt("= - A ring.", 0LL, 0LL);
break;
case '>':
prt("> - A down staircase.", 0LL, 0LL);
break;
case '?':
prt("? - A scroll.", 0LL, 0LL);
break;
case '@':
prt((const char *)&py, 0LL, 0LL);
break;
case 'A':
prt("A - Giant Ant Lion.", 0LL, 0LL);
break;
case 'B':
prt("B - The Balrog.", 0LL, 0LL);
break;
case 'C':
prt("C - Gelatinous Cube.", 0LL, 0LL);
break;
case 'D':
prt("D - An Ancient Dragon (Beware).", 0LL, 0LL);
break;
case 'E':
prt("E - Elemental.", 0LL, 0LL);
break;
case 'F':
prt("F - Giant Fly.", 0LL, 0LL);
break;
case 'G':
prt("G - Ghost.", 0LL, 0LL);
break;
case 'H':
prt("H - Hobgoblin.", 0LL, 0LL);
break;
case 'J':
prt("J - Jelly.", 0LL, 0LL);
break;
case 'K':
prt("K - Killer Beetle.", 0LL, 0LL);
break;
case 'L':
prt("L - Lich.", 0LL, 0LL);
break;
case 'M':
prt("M - Mummy.", 0LL, 0LL);
break;
case 'O':
prt("O - Ooze.", 0LL, 0LL);
break;
case 'P':
prt("P - Giant humanoid.", 0LL, 0LL);
break;
case 'Q':
prt("Q - Quylthulg (Pulsing Flesh Mound).", 0LL, 0LL);
break;
case 'R':
prt("R - Reptile.", 0LL, 0LL);
break;
case 'S':
prt("S - Giant Scorpion.", 0LL, 0LL);
break;
case 'T':
prt("T - Troll.", 0LL, 0LL);
break;
case 'U':
prt("U - Umber Hulk.", 0LL, 0LL);
break;
case 'V':
prt("V - Vampire.", 0LL, 0LL);
break;
case 'W':
prt("W - Wight or Wraith.", 0LL, 0LL);
break;
case 'X':
prt("X - Xorn.", 0LL, 0LL);
break;
case 'Y':
prt("Y - Yeti.", 0LL, 0LL);
break;
case '[':
prt("[ - Hard armor.", 0LL, 0LL);
break;
case '\\':
prt("\\ - A hafted weapon.", 0LL, 0LL);
break;
case ']':
prt("] - Misc. armor.", 0LL, 0LL);
break;
case '^':
prt("^ - A trap.", 0LL, 0LL);
break;
case '_':
prt("_ - A staff.", 0LL, 0LL);
break;
case 'a':
prt("a - Giant Ant.", 0LL, 0LL);
break;
case 'b':
prt("b - Giant Bat.", 0LL, 0LL);
break;
case 'c':
prt("c - Giant Centipede.", 0LL, 0LL);
break;
case 'd':
prt("d - Dragon.", 0LL, 0LL);
break;
case 'e':
prt("e - Floating Eye.", 0LL, 0LL);
break;
case 'f':
prt("f - Giant Frog.", 0LL, 0LL);
break;
case 'g':
prt("g - Golem.", 0LL, 0LL);
break;
case 'h':
prt("h - Harpy.", 0LL, 0LL);
break;
case 'i':
prt("i - Icky Thing.", 0LL, 0LL);
break;
case 'j':
prt("j - Jackal.", 0LL, 0LL);
break;
case 'k':
prt("k - Kobold.", 0LL, 0LL);
break;
case 'l':
prt("l - Giant Louse.", 0LL, 0LL);
break;
case 'm':
prt("m - Mold.", 0LL, 0LL);
break;
case 'n':
prt("n - Naga.", 0LL, 0LL);
break;
case 'o':
prt("o - Orc or Ogre.", 0LL, 0LL);
break;
case 'p':
prt("p - Person (Humanoid).", 0LL, 0LL);
break;
case 'q':
prt("q - Quasit.", 0LL, 0LL);
break;
case 'r':
prt("r - Rodent.", 0LL, 0LL);
break;
case 's':
prt("s - Skeleton.", 0LL, 0LL);
break;
case 't':
prt("t - Giant Tick.", 0LL, 0LL);
break;
case 'w':
prt("w - Worm or Worm Mass.", 0LL, 0LL);
break;
case 'y':
prt("y - Yeek.", 0LL, 0LL);
break;
case 'z':
prt("z - Zombie.", 0LL, 0LL);
break;
case '{':
prt("{ - Arrow, bolt, or bullet.", 0LL, 0LL);
break;
case '|':
prt("| - A sword or dagger.", 0LL, 0LL);
break;
case '}':
prt("} - Bow, crossbow, or sling.", 0LL, 0LL);
break;
case '~':
prt("~ - Miscellaneous item.", 0LL, 0LL);
break;
default:
prt("Not Used.", 0LL, 0LL);
break;
}
}
v0 = 278LL;
v1 = 0;
do
{
result = (unsigned int)v5[0];
if ( c_list[40 * v0 + 32] == (_DWORD)result )
{
result = bool_roff_recall((unsigned int)v0);
if ( (_DWORD)result )
{
if ( !v1 )
{
put_buffer("You recall those details? [y/n]", 0LL, 40LL);
result = inkey() & 0xFFFFFFDFLL;
if ( (_BYTE)result != 89 )
return result;
erase_line(0LL, 40LL);
save_screen();
}
++v1;
v4 = roff_recall((unsigned int)v0);
result = restore_screen();
if ( v4 == 27 )
break;
}
}
}
while ( v0-- != 0 );
return result;
}

original_code:
void ident_char()
{
  char command, query;
  register int i, n;
  if (get_com("Enter character to be identified :", &command))
    switch(command)
      {
      case ' ': prt("  - An open pit.", 0, 0); break;
      case '!': prt("! - A potion.", 0, 0); break;
      case '"': prt("\" - An amulet, periapt, or necklace.", 0, 0); break;
      case '#': prt("# - A stone wall.", 0, 0); break;
      case '$': prt("$ - Treasure.", 0, 0); break;
      case '%':
 if (highlight_seams == 1)
   prt("% - A magma or quartz vein.", 0, 0);
 else
   prt("% - Not used.", 0, 0);
 break;
      case '&': prt("& - Treasure chest.", 0, 0); break;
      case '\'': prt("' - An open door.", 0, 0); break;
      case '(': prt("( - Soft armor.", 0, 0); break;
      case ')': prt(") - A shield.", 0, 0); break;
      case '*': prt("* - Gems.", 0, 0); break;
      case '+': prt("+ - A closed door.", 0, 0); break;
      case ',': prt(", - Food or mushroom patch.", 0, 0); break;
      case '-': prt("- - A wand", 0, 0); break;
      case '.': prt(". - Floor.", 0, 0); break;
      case '/': prt("/ - A pole weapon.", 0, 0); break;
      case '1': prt("1 - Entrance to General Store.", 0, 0); break;
      case '2': prt("2 - Entrance to Armory.", 0, 0); break;
      case '3': prt("3 - Entrance to Weaponsmith.", 0, 0); break;
      case '4': prt("4 - Entrance to Temple.", 0, 0); break;
      case '5': prt("5 - Entrance to Alchemy shop.", 0, 0); break;
      case '6': prt("6 - Entrance to Magic-Users store.", 0, 0); break;
      case ':': prt(": - Rubble.", 0, 0); break;
      case ';': prt("; - A loose rock.", 0, 0); break;
      case '<': prt("< - An up staircase.", 0, 0); break;
      case '=': prt("= - A ring.", 0, 0); break;
      case '>': prt("> - A down staircase.", 0, 0); break;
      case '?': prt("? - A scroll.", 0, 0); break;
      case '@': prt(py.misc.name, 0, 0); break;
      case 'A': prt("A - Giant Ant Lion.", 0, 0); break;
      case 'B': prt("B - The Balrog.", 0, 0); break;
      case 'C': prt("C - Gelatinous Cube.", 0, 0); break;
      case 'D': prt("D - An Ancient Dragon (Beware).", 0, 0); break;
      case 'E': prt("E - Elemental.", 0, 0); break;
      case 'F': prt("F - Giant Fly.", 0, 0); break;
      case 'G': prt("G - Ghost.", 0, 0); break;
      case 'H': prt("H - Hobgoblin.", 0, 0); break;
      case 'J': prt("J - Jelly.", 0, 0); break;
      case 'K': prt("K - Killer Beetle.", 0, 0); break;
      case 'L': prt("L - Lich.", 0, 0); break;
      case 'M': prt("M - Mummy.", 0, 0); break;
      case 'O': prt("O - Ooze.", 0, 0); break;
      case 'P': prt("P - Giant humanoid.", 0, 0); break;
      case 'Q': prt("Q - Quylthulg (Pulsing Flesh Mound).", 0, 0); break;
      case 'R': prt("R - Reptile.", 0, 0); break;
      case 'S': prt("S - Giant Scorpion.", 0, 0); break;
      case 'T': prt("T - Troll.", 0, 0); break;
      case 'U': prt("U - Umber Hulk.", 0, 0); break;
      case 'V': prt("V - Vampire.", 0, 0); break;
      case 'W': prt("W - Wight or Wraith.", 0, 0); break;
      case 'X': prt("X - Xorn.", 0, 0); break;
      case 'Y': prt("Y - Yeti.", 0, 0); break;
      case '[': prt("[ - Hard armor.", 0, 0); break;
      case '\\': prt("\\ - A hafted weapon.", 0, 0); break;
      case ']': prt("] - Misc. armor.", 0, 0); break;
      case '^': prt("^ - A trap.", 0, 0); break;
      case '_': prt("_ - A staff.", 0, 0); break;
      case 'a': prt("a - Giant Ant.", 0, 0); break;
      case 'b': prt("b - Giant Bat.", 0, 0); break;
      case 'c': prt("c - Giant Centipede.", 0, 0); break;
      case 'd': prt("d - Dragon.", 0, 0); break;
      case 'e': prt("e - Floating Eye.", 0, 0); break;
      case 'f': prt("f - Giant Frog.", 0, 0); break;
      case 'g': prt("g - Golem.", 0, 0); break;
      case 'h': prt("h - Harpy.", 0, 0); break;
      case 'i': prt("i - Icky Thing.", 0, 0); break;
      case 'j': prt("j - Jackal.", 0, 0); break;
      case 'k': prt("k - Kobold.", 0, 0); break;
      case 'l': prt("l - Giant Louse.", 0, 0); break;
      case 'm': prt("m - Mold.", 0, 0); break;
      case 'n': prt("n - Naga.", 0, 0); break;
      case 'o': prt("o - Orc or Ogre.", 0, 0); break;
      case 'p': prt("p - Person (Humanoid).", 0, 0); break;
      case 'q': prt("q - Quasit.", 0, 0); break;
      case 'r': prt("r - Rodent.", 0, 0); break;
      case 's': prt("s - Skeleton.", 0, 0); break;
      case 't': prt("t - Giant Tick.", 0, 0); break;
      case 'w': prt("w - Worm or Worm Mass.", 0, 0); break;
      case 'y': prt("y - Yeek.", 0, 0); break;
      case 'z': prt("z - Zombie.", 0, 0); break;
      case '{': prt("{ - Arrow, bolt, or bullet.", 0, 0); break;
      case '|': prt("| - A sword or dagger.", 0, 0); break;
      case '}': prt("} - Bow, crossbow, or sling.", 0, 0); break;
      case '~': prt("~ - Miscellaneous item.", 0, 0); break;
      default: prt("Not Used.", 0, 0); break;
      }
  n = 0;
  for (i = 279 -1; i >= 0; i--)
    if ((c_list[i].cchar == command) && bool_roff_recall (i))
      {
 if (n == 0)
   {
     put_buffer ("You recall those details? [y/n]", 0, 40);
     query = inkey();
     if (query != 'y' && query != 'Y')
       break;
     erase_line (0, 40);
     save_screen ();
   }
 n++;
 query = roff_recall (i);
 restore_screen ();
 if (query == '\033')
   break;
      }
}

canonical_original_code:
void ident_char()
{
  char command; char query;
  register int i; register int n;
  if (get_com("Enter character to be identified :", &command))
    switch(command)
      {
      case ' ': prt("  - An open pit.", 0, 0); break;
      case '!': prt("! - A potion.", 0, 0); break;
      case '"': prt("\" - An amulet, periapt, or necklace.", 0, 0); break;
      case '#': prt("# - A stone wall.", 0, 0); break;
      case '$': prt("$ - Treasure.", 0, 0); break;
      case '%':
 if (highlight_seams == 1)
   prt("% - A magma or quartz vein.", 0, 0);
 else
   prt("% - Not used.", 0, 0);
 break;
      case '&': prt("& - Treasure chest.", 0, 0); break;
      case '\'': prt("' - An open door.", 0, 0); break;
      case '(': prt("( - Soft armor.", 0, 0); break;
      case ')': prt(") - A shield.", 0, 0); break;
      case '*': prt("* - Gems.", 0, 0); break;
      case '+': prt("+ - A closed door.", 0, 0); break;
      case ',': prt(", - Food or mushroom patch.", 0, 0); break;
      case '-': prt("- - A wand", 0, 0); break;
      case '.': prt(". - Floor.", 0, 0); break;
      case '/': prt("/ - A pole weapon.", 0, 0); break;
      case '1': prt("1 - Entrance to General Store.", 0, 0); break;
      case '2': prt("2 - Entrance to Armory.", 0, 0); break;
      case '3': prt("3 - Entrance to Weaponsmith.", 0, 0); break;
      case '4': prt("4 - Entrance to Temple.", 0, 0); break;
      case '5': prt("5 - Entrance to Alchemy shop.", 0, 0); break;
      case '6': prt("6 - Entrance to Magic-Users store.", 0, 0); break;
      case ':': prt(": - Rubble.", 0, 0); break;
      case ';': prt("; - A loose rock.", 0, 0); break;
      case '<': prt("< - An up staircase.", 0, 0); break;
      case '=': prt("= - A ring.", 0, 0); break;
      case '>': prt("> - A down staircase.", 0, 0); break;
      case '?': prt("? - A scroll.", 0, 0); break;
      case '@': prt(py.misc.name, 0, 0); break;
      case 'A': prt("A - Giant Ant Lion.", 0, 0); break;
      case 'B': prt("B - The Balrog.", 0, 0); break;
      case 'C': prt("C - Gelatinous Cube.", 0, 0); break;
      case 'D': prt("D - An Ancient Dragon (Beware).", 0, 0); break;
      case 'E': prt("E - Elemental.", 0, 0); break;
      case 'F': prt("F - Giant Fly.", 0, 0); break;
      case 'G': prt("G - Ghost.", 0, 0); break;
      case 'H': prt("H - Hobgoblin.", 0, 0); break;
      case 'J': prt("J - Jelly.", 0, 0); break;
      case 'K': prt("K - Killer Beetle.", 0, 0); break;
      case 'L': prt("L - Lich.", 0, 0); break;
      case 'M': prt("M - Mummy.", 0, 0); break;
      case 'O': prt("O - Ooze.", 0, 0); break;
      case 'P': prt("P - Giant humanoid.", 0, 0); break;
      case 'Q': prt("Q - Quylthulg (Pulsing Flesh Mound).", 0, 0); break;
      case 'R': prt("R - Reptile.", 0, 0); break;
      case 'S': prt("S - Giant Scorpion.", 0, 0); break;
      case 'T': prt("T - Troll.", 0, 0); break;
      case 'U': prt("U - Umber Hulk.", 0, 0); break;
      case 'V': prt("V - Vampire.", 0, 0); break;
      case 'W': prt("W - Wight or Wraith.", 0, 0); break;
      case 'X': prt("X - Xorn.", 0, 0); break;
      case 'Y': prt("Y - Yeti.", 0, 0); break;
      case '[': prt("[ - Hard armor.", 0, 0); break;
      case '\\': prt("\\ - A hafted weapon.", 0, 0); break;
      case ']': prt("] - Misc. armor.", 0, 0); break;
      case '^': prt("^ - A trap.", 0, 0); break;
      case '_': prt("_ - A staff.", 0, 0); break;
      case 'a': prt("a - Giant Ant.", 0, 0); break;
      case 'b': prt("b - Giant Bat.", 0, 0); break;
      case 'c': prt("c - Giant Centipede.", 0, 0); break;
      case 'd': prt("d - Dragon.", 0, 0); break;
      case 'e': prt("e - Floating Eye.", 0, 0); break;
      case 'f': prt("f - Giant Frog.", 0, 0); break;
      case 'g': prt("g - Golem.", 0, 0); break;
      case 'h': prt("h - Harpy.", 0, 0); break;
      case 'i': prt("i - Icky Thing.", 0, 0); break;
      case 'j': prt("j - Jackal.", 0, 0); break;
      case 'k': prt("k - Kobold.", 0, 0); break;
      case 'l': prt("l - Giant Louse.", 0, 0); break;
      case 'm': prt("m - Mold.", 0, 0); break;
      case 'n': prt("n - Naga.", 0, 0); break;
      case 'o': prt("o - Orc or Ogre.", 0, 0); break;
      case 'p': prt("p - Person (Humanoid).", 0, 0); break;
      case 'q': prt("q - Quasit.", 0, 0); break;
      case 'r': prt("r - Rodent.", 0, 0); break;
      case 's': prt("s - Skeleton.", 0, 0); break;
      case 't': prt("t - Giant Tick.", 0, 0); break;
      case 'w': prt("w - Worm or Worm Mass.", 0, 0); break;
      case 'y': prt("y - Yeek.", 0, 0); break;
      case 'z': prt("z - Zombie.", 0, 0); break;
      case '{': prt("{ - Arrow, bolt, or bullet.", 0, 0); break;
      case '|': prt("| - A sword or dagger.", 0, 0); break;
      case '}': prt("} - Bow, crossbow, or sling.", 0, 0); break;
      case '~': prt("~ - Miscellaneous item.", 0, 0); break;
      default: prt("Not Used.", 0, 0); break;
      }
  n = 0;
  for (i = 279 -1; i >= 0; i--)
    if ((c_list[i].cchar == command) && bool_roff_recall (i))
      {
 if (n == 0)
   {
     put_buffer ("You recall those details? [y/n]", 0, 40);
     query = inkey();
     if (query != 'y' && query != 'Y')
       break;
     erase_line (0, 40);
     save_screen ();
   }
 n++;
 query = roff_recall (i);
 restore_screen ();
 if (query == '\033')
   break;
      }
}

variable_types: command char

variable_types: query char

variable_types: n int


aim

decompiled_code:
__int64 aim()
{
__int64 result; // rax
__int64 v1; // rbp
int v2; // er12
int v3; // ebx
__int64 v4; // rdi
unsigned __int8 *v5; // r13
__int16 v6; // ax
__int64 v7; // rdx
int v8; // er12
int v9; // eax
__int64 v10; // rsi
unsigned int v11; // er15
__int64 v12; // rax
unsigned __int8 *v13; // rdi
__int64 v14; // rdx
__int64 v15; // rdx
__int64 v16; // rdx
__int64 v17; // rdx
__int64 v18; // rdx
__int64 v19; // rbx
unsigned int v20; // eax
__int64 v21; // rcx
int v22; // eax
__int64 v23; // rbx
unsigned int v24; // eax
__int64 v25; // rbx
unsigned int v26; // eax
__int64 v27; // rbx
unsigned int v28; // eax
__int64 v29; // rdx
unsigned int v30; // [rsp+0h] [rbp-50h] BYREF
unsigned int v31; // [rsp+4h] [rbp-4Ch] BYREF
unsigned int v32; // [rsp+8h] [rbp-48h] BYREF
unsigned int v33; // [rsp+Ch] [rbp-44h] BYREF
__int64 v34[8]; // [rsp+10h] [rbp-40h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(65LL, 0xFFFFFFFFLL, &v31, &v32) )
return msg_print("You are not carrying any wands.");
result = get_item(&v30, "Aim which wand?", v31, v32, 0LL, 0LL);
if ( (_DWORD)result )
{
v1 = (int)v30;
free_turn_flag = 0;
result = get_dir(0LL, &v33);
if ( (_DWORD)result )
{
if ( *((__int16 *)&py + 203) > 0 )
{
msg_print("You are confused.");
do
v33 = randint(9LL);
while ( v33 == 5 );
}
v2 = *((__int16 *)&py + 49);
v3 = *((unsigned __int16 *)&py + 32) * class_level_adj[5 * *((unsigned __int8 *)&py + 104) + 2] / 3
+ stat_adj(1LL)
+ v2
- inventory[56 * v1 + 54];
if ( *((__int16 *)&py + 203) > 0 )
v3 /= 2;
if ( v3 <= 2 && (unsigned int)randint((unsigned int)(4 - v3)) == 1 )
{
v4 = 3LL;
}
else
{
v4 = 1LL;
if ( v3 > 0 )
v4 = (unsigned int)v3;
}
if ( (int)randint(v4) <= 2 )
{
result = msg_print("You failed to use the wand properly.");
}
else
{
v5 = &inventory[56 * v1];
v6 = *((_WORD *)v5 + 13);
if ( v6 <= 0 )
{
msg_print("The wand has no charges left.");
result = known2_p(&inventory[56 * v1]);
if ( !(_DWORD)result )
result = add_inscribe(&inventory[56 * v1], 4LL);
}
else
{
v7 = *((_QWORD *)v5 + 2);
*((_WORD *)v5 + 13) = v6 - 1;
v34[0] = v7;
if ( !v7 )
goto LABEL_62;
v8 = 0;
do
{
v9 = bit_pos(v34);
v10 = (unsigned int)char_row;
v11 = char_col;
v31 = v9 + 1;
v32 = char_row;
switch ( v9 )
{
case 0:
v8 = v9 + 1;
msg_print("A line of blue shimmering light appears.");
v10 = (unsigned int)char_row;
light_line(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 1:
v27 = spell_names[8];
v28 = damroll(4LL, 8LL);
v10 = v33;
fire_bolt(1LL, v33, v32, v11, v28, v27);
v8 = 1;
v12 = v34[0];
break;
case 2:
v25 = spell_names[14];
v26 = damroll(6LL, 8LL);
v10 = v33;
fire_bolt(4LL, v33, v32, v11, v26, v25);
v8 = 1;
v12 = v34[0];
break;
case 3:
v23 = spell_names[22];
v24 = damroll(9LL, 8LL);
v10 = v33;
fire_bolt(5LL, v33, v32, v11, v24, v23);
v8 = 1;
v12 = v34[0];
break;
case 4:
v8 = wall_to_mud(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 5:
v8 = poly_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 6:
v22 = damroll(4LL, 6LL);
v10 = v32;
v8 = hp_monster(v33, v32, v11, (unsigned int)-v22);
v12 = v34[0];
break;
case 7:
v21 = 1LL;
goto LABEL_40;
case 8:
v21 = 0xFFFFFFFFLL;
LABEL_40:
v8 = speed_monster(v33, v10, (unsigned int)char_col, v21);
v12 = v34[0];
break;
case 9:
v8 = confuse_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 10:
v8 = sleep_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 11:
v8 = drain_life(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 12:
v8 = td_destroy2(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 13:
v19 = spell_names[0];
v20 = damroll(2LL, 6LL);
v10 = v33;
fire_bolt(0LL, v33, v32, v11, v20, v19);
v8 = 1;
v12 = v34[0];
break;
case 14:
v8 = build_wall(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 15:
v8 = clone_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 16:
v8 = teleport_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 17:
v8 = disarm_all(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 18:
v18 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(1LL, v33, v18, (unsigned int)char_col, 32LL, "Lightning Ball");
v12 = v34[0];
break;
case 19:
v17 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(4LL, v33, v17, (unsigned int)char_col, 48LL, "Cold Ball");
v12 = v34[0];
break;
case 20:
v16 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(5LL, v33, v16, (unsigned int)char_col, 72LL, spell_names[28]);
v12 = v34[0];
break;
case 21:
v15 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(2LL, v33, v15, (unsigned int)char_col, 12LL, spell_names[6]);
v12 = v34[0];
break;
case 22:
v14 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(3LL, v33, v14, (unsigned int)char_col, 60LL, "Acid Ball");
v12 = v34[0];
break;
case 23:
v12 = 1LL << ((unsigned __int8)randint(23LL) - 1);
v34[0] = v12;
break;
default:
msg_print("Internal error in wands()");
v12 = v34[0];
break;
}
}
while ( v12 );
if ( v8 )
{
v13 = &inventory[56 * v1];
if ( !(unsigned int)known1_p(v13) )
{
v29 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + inventory[56 * v1 + 54]) >> 31);
LODWORD(v29) = ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v1 + 54]) % *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v1 + 54])
/ *((unsigned __int16 *)&py + 32);
prt_experience(v13, v10, v29);
identify(&v30);
}
}
else
{
LABEL_62:
if ( !(unsigned int)known1_p(&inventory[56 * v1]) )
sample(&inventory[56 * v1]);
}
result = desc_charges(v30);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rbp
int v2; // er12
int v3; // ebx
__int64 v4; // rdi
unsigned __int8 *v5; // r13
__int16 v6; // ax
__int64 v7; // rdx
int v8; // er12
int v9; // eax
__int64 v10; // rsi
unsigned int v11; // er15
__int64 v12; // rax
unsigned __int8 *v13; // rdi
__int64 v14; // rdx
__int64 v15; // rdx
__int64 v16; // rdx
__int64 v17; // rdx
__int64 v18; // rdx
__int64 v19; // rbx
unsigned int v20; // eax
__int64 v21; // rcx
int v22; // eax
__int64 v23; // rbx
unsigned int v24; // eax
__int64 v25; // rbx
unsigned int v26; // eax
__int64 v27; // rbx
unsigned int v28; // eax
__int64 v29; // rdx
unsigned int v30; // [rsp+0h] [rbp-50h] BYREF
unsigned int v31; // [rsp+4h] [rbp-4Ch] BYREF
unsigned int v32; // [rsp+8h] [rbp-48h] BYREF
unsigned int v33; // [rsp+Ch] [rbp-44h] BYREF
__int64 v34[8]; // [rsp+10h] [rbp-40h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(65LL, 0xFFFFFFFFLL, &v31, &v32) )
return msg_print("You are not carrying any wands.");
result = get_item(&v30, "Aim which wand?", v31, v32, 0LL, 0LL);
if ( (_DWORD)result )
{
v1 = (int)v30;
free_turn_flag = 0;
result = get_dir(0LL, &v33);
if ( (_DWORD)result )
{
if ( *((__int16 *)&py + 203) > 0 )
{
msg_print("You are confused.");
do
v33 = randint(9LL);
while ( v33 == 5 );
}
v2 = *((__int16 *)&py + 49);
v3 = *((unsigned __int16 *)&py + 32) * class_level_adj[5 * *((unsigned __int8 *)&py + 104) + 2] / 3
+ stat_adj(1LL)
+ v2
- inventory[56 * v1 + 54];
if ( *((__int16 *)&py + 203) > 0 )
v3 /= 2;
if ( v3 <= 2 && (unsigned int)randint((unsigned int)(4 - v3)) == 1 )
{
v4 = 3LL;
}
else
{
v4 = 1LL;
if ( v3 > 0 )
v4 = (unsigned int)v3;
}
if ( (int)randint(v4) <= 2 )
{
result = msg_print("You failed to use the wand properly.");
}
else
{
v5 = &inventory[56 * v1];
v6 = *((_WORD *)v5 + 13);
if ( v6 <= 0 )
{
msg_print("The wand has no charges left.");
result = known2_p(&inventory[56 * v1]);
if ( !(_DWORD)result )
result = add_inscribe(&inventory[56 * v1], 4LL);
}
else
{
v7 = *((_QWORD *)v5 + 2);
*((_WORD *)v5 + 13) = v6 - 1;
v34[0] = v7;
if ( !v7 )
goto LABEL_62;
v8 = 0;
do
{
v9 = bit_pos(v34);
v10 = (unsigned int)char_row;
v11 = char_col;
v31 = v9 + 1;
v32 = char_row;
switch ( v9 )
{
case 0:
v8 = v9 + 1;
msg_print("A line of blue shimmering light appears.");
v10 = (unsigned int)char_row;
light_line(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 1:
v27 = spell_names[8];
v28 = damroll(4LL, 8LL);
v10 = v33;
fire_bolt(1LL, v33, v32, v11, v28, v27);
v8 = 1;
v12 = v34[0];
break;
case 2:
v25 = spell_names[14];
v26 = damroll(6LL, 8LL);
v10 = v33;
fire_bolt(4LL, v33, v32, v11, v26, v25);
v8 = 1;
v12 = v34[0];
break;
case 3:
v23 = spell_names[22];
v24 = damroll(9LL, 8LL);
v10 = v33;
fire_bolt(5LL, v33, v32, v11, v24, v23);
v8 = 1;
v12 = v34[0];
break;
case 4:
v8 = wall_to_mud(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 5:
v8 = poly_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 6:
v22 = damroll(4LL, 6LL);
v10 = v32;
v8 = hp_monster(v33, v32, v11, (unsigned int)-v22);
v12 = v34[0];
break;
case 7:
v21 = 1LL;
goto LABEL_40;
case 8:
v21 = 0xFFFFFFFFLL;
LABEL_40:
v8 = speed_monster(v33, v10, (unsigned int)char_col, v21);
v12 = v34[0];
break;
case 9:
v8 = confuse_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 10:
v8 = sleep_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 11:
v8 = drain_life(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 12:
v8 = td_destroy2(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 13:
v19 = spell_names[0];
v20 = damroll(2LL, 6LL);
v10 = v33;
fire_bolt(0LL, v33, v32, v11, v20, v19);
v8 = 1;
v12 = v34[0];
break;
case 14:
v8 = build_wall(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 15:
v8 = clone_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 16:
v8 = teleport_monster(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 17:
v8 = disarm_all(v33, v10, (unsigned int)char_col);
v12 = v34[0];
break;
case 18:
v18 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(1LL, v33, v18, (unsigned int)char_col, 32LL, "Lightning Ball");
v12 = v34[0];
break;
case 19:
v17 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(4LL, v33, v17, (unsigned int)char_col, 48LL, "Cold Ball");
v12 = v34[0];
break;
case 20:
v16 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(5LL, v33, v16, (unsigned int)char_col, 72LL, spell_names[28]);
v12 = v34[0];
break;
case 21:
v15 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(2LL, v33, v15, (unsigned int)char_col, 12LL, spell_names[6]);
v12 = v34[0];
break;
case 22:
v14 = (unsigned int)v10;
v10 = v33;
v8 = 1;
fire_ball(3LL, v33, v14, (unsigned int)char_col, 60LL, "Acid Ball");
v12 = v34[0];
break;
case 23:
v12 = 1LL << ((unsigned __int8)randint(23LL) - 1);
v34[0] = v12;
break;
default:
msg_print("Internal error in wands()");
v12 = v34[0];
break;
}
}
while ( v12 );
if ( v8 )
{
v13 = &inventory[56 * v1];
if ( !(unsigned int)known1_p(v13) )
{
v29 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + inventory[56 * v1 + 54]) >> 31);
LODWORD(v29) = ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v1 + 54]) % *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v1 + 54])
/ *((unsigned __int16 *)&py + 32);
prt_experience(v13, v10, v29);
identify(&v30);
}
}
else
{
LABEL_62:
if ( !(unsigned int)known1_p(&inventory[56 * v1]) )
sample(&inventory[56 * v1]);
}
result = desc_charges(v30);
}
}
}
}
return result;
}

original_code:
void aim()
{
  int32u i;
  register int l, ident;
  int item_val, j, k, chance, dir;
  register inven_type *i_ptr;
  register struct misc *m_ptr;
  free_turn_flag = 1;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(65, -1, &j, &k))
    msg_print("You are not carrying any wands.");
  else if (get_item(&item_val, "Aim which wand?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = 0;
      if (get_dir((char *)0, &dir))
 {
   if (py.flags.confused > 0)
     {
       msg_print("You are confused.");
       do
  {
    dir = randint(9);
  }
       while (dir == 5);
     }
   ident = 0;
   m_ptr = &py.misc;
   chance = m_ptr->save + stat_adj(1) - (int)i_ptr->level
     + (class_level_adj[m_ptr->pclass][2] * m_ptr->lev / 3);
   if (py.flags.confused > 0)
     chance = chance / 2;
   if ((chance < 3) && (randint(3 - chance + 1) == 1))
     chance = 3;
   if (chance <= 0) chance = 1;
   if (randint(chance) < 3)
     msg_print("You failed to use the wand properly.");
   else if (i_ptr->p1 > 0)
     {
       i = i_ptr->flags;
       (i_ptr->p1)--;
       while (i != 0)
  {
    j = bit_pos(&i) + 1;
    k = char_row;
    l = char_col;
    switch(j)
      {
      case 1:
        msg_print("A line of blue shimmering light appears.");
        light_line(dir, char_row, char_col);
        ident = 1;
        break;
      case 2:
        fire_bolt(1, dir, k, l, damroll(4, 8),
    spell_names[8]);
        ident = 1;
        break;
      case 3:
        fire_bolt(4, dir, k, l, damroll(6, 8),
    spell_names[14]);
        ident = 1;
        break;
      case 4:
        fire_bolt(5, dir, k, l, damroll(9, 8),
    spell_names[22]);
        ident = 1;
        break;
      case 5:
        ident = wall_to_mud(dir, k, l);
        break;
      case 6:
        ident = poly_monster(dir, k, l);
        break;
      case 7:
        ident = hp_monster(dir, k, l, -damroll(4, 6));
        break;
      case 8:
        ident = speed_monster(dir, k, l, 1);
        break;
      case 9:
        ident = speed_monster(dir, k, l, -1);
        break;
      case 10:
        ident = confuse_monster(dir, k, l);
        break;
      case 11:
        ident = sleep_monster(dir, k, l);
        break;
      case 12:
        ident = drain_life(dir, k, l);
        break;
      case 13:
        ident = td_destroy2(dir, k, l);
        break;
      case 14:
        fire_bolt(0, dir, k, l, damroll(2, 6),
    spell_names[0]);
        ident = 1;
        break;
      case 15:
        ident = build_wall(dir, k, l);
        break;
      case 16:
        ident = clone_monster(dir, k, l);
        break;
      case 17:
        ident = teleport_monster(dir, k, l);
        break;
      case 18:
        ident = disarm_all(dir, k, l);
        break;
      case 19:
        fire_ball(1, dir, k, l, 32, "Lightning Ball");
        ident = 1;
        break;
      case 20:
        fire_ball(4, dir, k, l, 48, "Cold Ball");
        ident = 1;
        break;
      case 21:
        fire_ball(5, dir, k, l, 72, spell_names[28]);
        ident = 1;
        break;
      case 22:
        fire_ball(2, dir, k, l, 12, spell_names[6]);
        ident = 1;
        break;
      case 23:
        fire_ball(3, dir, k, l, 60, "Acid Ball");
        ident = 1;
        break;
      case 24:
        i = 1L << (randint(23) - 1);
        break;
      default:
        msg_print("Internal error in wands()");
        break;
      }
  }
       if (ident)
  {
    if (!known1_p(i_ptr))
      {
        m_ptr = &py.misc;
        m_ptr->exp += (i_ptr->level +(m_ptr->lev >> 1)) /
   m_ptr->lev;
        prt_experience();
        identify(&item_val);
        i_ptr = &inventory[item_val];
      }
  }
       else if (!known1_p(i_ptr))
  sample (i_ptr);
       desc_charges(item_val);
     }
   else
     {
       msg_print("The wand has no charges left.");
       if (!known2_p(i_ptr))
  add_inscribe(i_ptr, 0x4);
     }
 }
    }
}

canonical_original_code:
void aim()
{
  unsigned long i;
  register int l; register int ident;
  int item_val; int j; int k; int chance; int dir;
  register struct inven_type *i_ptr;
  register struct misc *m_ptr;
  free_turn_flag = 1;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(65, -1, &j, &k))
    msg_print("You are not carrying any wands.");
  else if (get_item(&item_val, "Aim which wand?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = 0;
      if (get_dir((char *)0, &dir))
 {
   if (py.flags.confused > 0)
     {
       msg_print("You are confused.");
       do
  {
    dir = randint(9);
  }
       while (dir == 5);
     }
   ident = 0;
   m_ptr = &py.misc;
   chance = m_ptr->save + stat_adj(1) - (int)i_ptr->level
     + (class_level_adj[m_ptr->pclass][2] * m_ptr->lev / 3);
   if (py.flags.confused > 0)
     chance = chance / 2;
   if ((chance < 3) && (randint(3 - chance + 1) == 1))
     chance = 3;
   if (chance <= 0) chance = 1;
   if (randint(chance) < 3)
     msg_print("You failed to use the wand properly.");
   else if (i_ptr->p1 > 0)
     {
       i = i_ptr->flags;
       (i_ptr->p1)--;
       while (i != 0)
  {
    j = bit_pos(&i) + 1;
    k = char_row;
    l = char_col;
    switch(j)
      {
      case 1:
        msg_print("A line of blue shimmering light appears.");
        light_line(dir, char_row, char_col);
        ident = 1;
        break;
      case 2:
        fire_bolt(1, dir, k, l, damroll(4, 8),
    spell_names[8]);
        ident = 1;
        break;
      case 3:
        fire_bolt(4, dir, k, l, damroll(6, 8),
    spell_names[14]);
        ident = 1;
        break;
      case 4:
        fire_bolt(5, dir, k, l, damroll(9, 8),
    spell_names[22]);
        ident = 1;
        break;
      case 5:
        ident = wall_to_mud(dir, k, l);
        break;
      case 6:
        ident = poly_monster(dir, k, l);
        break;
      case 7:
        ident = hp_monster(dir, k, l, -damroll(4, 6));
        break;
      case 8:
        ident = speed_monster(dir, k, l, 1);
        break;
      case 9:
        ident = speed_monster(dir, k, l, -1);
        break;
      case 10:
        ident = confuse_monster(dir, k, l);
        break;
      case 11:
        ident = sleep_monster(dir, k, l);
        break;
      case 12:
        ident = drain_life(dir, k, l);
        break;
      case 13:
        ident = td_destroy2(dir, k, l);
        break;
      case 14:
        fire_bolt(0, dir, k, l, damroll(2, 6),
    spell_names[0]);
        ident = 1;
        break;
      case 15:
        ident = build_wall(dir, k, l);
        break;
      case 16:
        ident = clone_monster(dir, k, l);
        break;
      case 17:
        ident = teleport_monster(dir, k, l);
        break;
      case 18:
        ident = disarm_all(dir, k, l);
        break;
      case 19:
        fire_ball(1, dir, k, l, 32, "Lightning Ball");
        ident = 1;
        break;
      case 20:
        fire_ball(4, dir, k, l, 48, "Cold Ball");
        ident = 1;
        break;
      case 21:
        fire_ball(5, dir, k, l, 72, spell_names[28]);
        ident = 1;
        break;
      case 22:
        fire_ball(2, dir, k, l, 12, spell_names[6]);
        ident = 1;
        break;
      case 23:
        fire_ball(3, dir, k, l, 60, "Acid Ball");
        ident = 1;
        break;
      case 24:
        i = 1L << (randint(23) - 1);
        break;
      default:
        msg_print("Internal error in wands()");
        break;
      }
  }
       if (ident)
  {
    if (!known1_p(i_ptr))
      {
        m_ptr = &py.misc;
        m_ptr->exp += (i_ptr->level +(m_ptr->lev >> 1)) /
   m_ptr->lev;
        prt_experience();
        identify(&item_val);
        i_ptr = &inventory[item_val];
      }
  }
       else if (!known1_p(i_ptr))
  sample (i_ptr);
       desc_charges(item_val);
     }
   else
     {
       msg_print("The wand has no charges left.");
       if (!known2_p(i_ptr))
  add_inscribe(i_ptr, 0x4);
     }
 }
    }
}

variable_types:
i
unsigned long

variable_types: l int

variable_types: ident int

variable_types: chance int

variable_types: dir int

variable_types: struct misc { char name[27]; unsigned char male; long au; long max_exp; long exp; unsigned short exp_frac; unsigned short age; unsigned short ht; unsigned short wt; unsigned short lev; unsigned short max_dlv; short srh; short fos; short bth; short bthb; short mana; short mhp; short ptohit; short ptodam; short pac; short ptoac; short dis_th; short dis_td; short dis_ac; short dis_tac; short disarm; short save; short sc; short stl; unsigned char pclass; unsigned char prace; unsigned char hitdie; unsigned char expfact; short cmana; unsigned short cmana_frac; short chp; unsigned short chp_frac; char history[4][60]; } *


use

decompiled_code:
__int64 use()
{
__int64 result; // rax
unsigned __int64 v1; // rsi
__int64 v2; // rbp
int v3; // er12
int v4; // ebx
__int64 v5; // rdi
char *v6; // r12
__int16 v7; // dx
__int64 v8; // rax
int v9; // ebx
int v10; // eax
unsigned int v11; // eax
int v12; // eax
char *v13; // rdi
__int64 v14; // rdx
unsigned int v15; // [rsp+0h] [rbp-34h] BYREF
int v16; // [rsp+4h] [rbp-30h] BYREF
unsigned int v17; // [rsp+8h] [rbp-2Ch] BYREF
int v18; // [rsp+Ch] [rbp-28h] BYREF
int v19; // [rsp+10h] [rbp-24h] BYREF
__int64 v20[4]; // [rsp+14h] [rbp-20h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(55LL, 0xFFFFFFFFLL, &v15, &v16) )
return msg_print("You are not carrying any staffs.");
v1 = (unsigned __int64)"Use which staff?";
result = get_item(&v17, "Use which staff?", v15, (unsigned int)v16, 0LL, 0LL);
if ( (_DWORD)result )
{
v2 = (int)v17;
v3 = *((__int16 *)&py + 49);
free_turn_flag = 0;
v4 = v3
- inventory[56 * v2 + 54]
+ stat_adj(1LL)
- 5
+ *((unsigned __int16 *)&py + 32) * class_level_adj[5 * *((unsigned __int8 *)&py + 104) + 2] / 3;
if ( *((__int16 *)&py + 203) > 0 )
v4 /= 2;
if ( v4 <= 2 && (unsigned int)randint((unsigned int)(4 - v4)) == 1 )
{
v5 = 3LL;
}
else
{
v5 = 1LL;
if ( v4 > 0 )
v5 = (unsigned int)v4;
}
if ( (int)randint(v5) <= 2 )
{
result = msg_print("You failed to use the staff properly.");
}
else
{
v6 = (char *)&inventory[56 * v2];
v7 = *((_WORD *)v6 + 13);
if ( v7 <= 0 )
{
msg_print("The staff has no charges left.");
result = known2_p(&inventory[56 * v2]);
if ( !(_DWORD)result )
result = add_inscribe(&inventory[56 * v2], 4LL);
}
else
{
v8 = *((_QWORD *)v6 + 2);
v9 = 0;
*((_WORD *)v6 + 13) = v7 - 1;
v20[0] = v8;
while ( v8 )
{
v10 = bit_pos(v20);
v15 = v10 + 1;
switch ( v10 )
{
case 0:
v1 = (unsigned int)char_col;
v9 = light_area((unsigned int)char_row, v1);
break;
case 1:
v9 = detect_sdoor();
break;
case 2:
v9 = detect_trap();
break;
case 3:
v9 = detect_treasure();
break;
case 4:
v9 = detect_object();
break;
case 5:
v9 = 1;
teleport(100LL);
break;
case 6:
v9 = 1;
earthquake();
break;
case 7:
v16 = 0;
v9 = 0;
while ( (int)randint(4LL) > v16 )
{
v1 = (unsigned __int64)&v19;
v18 = char_row;
v19 = char_col;
v12 = summon_monster(&v18, &v19, 0LL);
++v16;
v9 |= v12;
}
break;
case 9:
v1 = (unsigned int)char_col;
v9 = 1;
destroy_area((unsigned int)char_row, v1);
break;
case 10:
v1 = (unsigned int)char_col;
v9 = 1;
starlite((unsigned int)char_row, v1);
break;
case 11:
v9 = speed_monsters(1LL);
break;
case 12:
v9 = speed_monsters(0xFFFFFFFFLL);
break;
case 13:
v9 = sleep_monsters2();
break;
case 14:
v11 = randint(8LL);
v9 = hp_player(v11);
break;
case 15:
v9 = detect_invisible();
break;
case 16:
if ( !*((_WORD *)&py + 208) )
v9 = 1;
*((_WORD *)&py + 208) += randint(30LL) + 15;
break;
case 17:
if ( !*((_WORD *)&py + 209) )
v9 = 1;
*((_WORD *)&py + 209) += randint(30LL) + 15;
break;
case 18:
v9 = mass_poly();
break;
case 19:
if ( (unsigned int)remove_curse() )
{
if ( *((__int16 *)&py + 201) <= 0 )
msg_print("The staff glows blue for a moment..");
goto LABEL_22;
}
break;
case 20:
v9 = detect_evil();
break;
case 21:
if ( (unsigned int)cure_blindness() || (unsigned int)cure_poison() || (unsigned int)cure_confusion() )
LABEL_22:
v9 = 1;
break;
case 22:
v1 = 60LL;
v9 = dispel_creature(4LL, 60LL);
break;
case 24:
v1 = (unsigned int)char_col;
v9 = unlight_area((unsigned int)char_row, v1);
break;
case 31:
break;
default:
msg_print("Internal error in staffs()");
break;
}
v8 = v20[0];
}
v13 = (char *)&inventory[56 * v2];
if ( v9 )
{
if ( !(unsigned int)known1_p(v13) )
{
v14 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) >> 31);
LODWORD(v14) = ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) % *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54])
/ *((unsigned __int16 *)&py + 32);
prt_experience(v13, v1, v14);
identify(&v17);
}
}
else if ( !(unsigned int)known1_p(v13) )
{
sample(&inventory[56 * v2]);
}
result = desc_charges(v17);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
unsigned __int64 v1; // rsi
__int64 v2; // rbp
int v3; // er12
int v4; // ebx
__int64 v5; // rdi
char *v6; // r12
__int16 v7; // dx
__int64 v8; // rax
int v9; // ebx
int v10; // eax
unsigned int v11; // eax
int v12; // eax
char *v13; // rdi
__int64 v14; // rdx
unsigned int v15; // [rsp+0h] [rbp-34h] BYREF
int v16; // [rsp+4h] [rbp-30h] BYREF
unsigned int v17; // [rsp+8h] [rbp-2Ch] BYREF
int v18; // [rsp+Ch] [rbp-28h] BYREF
int v19; // [rsp+10h] [rbp-24h] BYREF
__int64 v20[4]; // [rsp+14h] [rbp-20h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(55LL, 0xFFFFFFFFLL, &v15, &v16) )
return msg_print("You are not carrying any staffs.");
v1 = (unsigned __int64)"Use which staff?";
result = get_item(&v17, "Use which staff?", v15, (unsigned int)v16, 0LL, 0LL);
if ( (_DWORD)result )
{
v2 = (int)v17;
v3 = *((__int16 *)&py + 49);
free_turn_flag = 0;
v4 = v3
- inventory[56 * v2 + 54]
+ stat_adj(1LL)
- 5
+ *((unsigned __int16 *)&py + 32) * class_level_adj[5 * *((unsigned __int8 *)&py + 104) + 2] / 3;
if ( *((__int16 *)&py + 203) > 0 )
v4 /= 2;
if ( v4 <= 2 && (unsigned int)randint((unsigned int)(4 - v4)) == 1 )
{
v5 = 3LL;
}
else
{
v5 = 1LL;
if ( v4 > 0 )
v5 = (unsigned int)v4;
}
if ( (int)randint(v5) <= 2 )
{
result = msg_print("You failed to use the staff properly.");
}
else
{
v6 = (char *)&inventory[56 * v2];
v7 = *((_WORD *)v6 + 13);
if ( v7 <= 0 )
{
msg_print("The staff has no charges left.");
result = known2_p(&inventory[56 * v2]);
if ( !(_DWORD)result )
result = add_inscribe(&inventory[56 * v2], 4LL);
}
else
{
v8 = *((_QWORD *)v6 + 2);
v9 = 0;
*((_WORD *)v6 + 13) = v7 - 1;
v20[0] = v8;
while ( v8 )
{
v10 = bit_pos(v20);
v15 = v10 + 1;
switch ( v10 )
{
case 0:
v1 = (unsigned int)char_col;
v9 = light_area((unsigned int)char_row, v1);
break;
case 1:
v9 = detect_sdoor();
break;
case 2:
v9 = detect_trap();
break;
case 3:
v9 = detect_treasure();
break;
case 4:
v9 = detect_object();
break;
case 5:
v9 = 1;
teleport(100LL);
break;
case 6:
v9 = 1;
earthquake();
break;
case 7:
v16 = 0;
v9 = 0;
while ( (int)randint(4LL) > v16 )
{
v1 = (unsigned __int64)&v19;
v18 = char_row;
v19 = char_col;
v12 = summon_monster(&v18, &v19, 0LL);
++v16;
v9 |= v12;
}
break;
case 9:
v1 = (unsigned int)char_col;
v9 = 1;
destroy_area((unsigned int)char_row, v1);
break;
case 10:
v1 = (unsigned int)char_col;
v9 = 1;
starlite((unsigned int)char_row, v1);
break;
case 11:
v9 = speed_monsters(1LL);
break;
case 12:
v9 = speed_monsters(0xFFFFFFFFLL);
break;
case 13:
v9 = sleep_monsters2();
break;
case 14:
v11 = randint(8LL);
v9 = hp_player(v11);
break;
case 15:
v9 = detect_invisible();
break;
case 16:
if ( !*((_WORD *)&py + 208) )
v9 = 1;
*((_WORD *)&py + 208) += randint(30LL) + 15;
break;
case 17:
if ( !*((_WORD *)&py + 209) )
v9 = 1;
*((_WORD *)&py + 209) += randint(30LL) + 15;
break;
case 18:
v9 = mass_poly();
break;
case 19:
if ( (unsigned int)remove_curse() )
{
if ( *((__int16 *)&py + 201) <= 0 )
msg_print("The staff glows blue for a moment..");
goto LABEL_22;
}
break;
case 20:
v9 = detect_evil();
break;
case 21:
if ( (unsigned int)cure_blindness() || (unsigned int)cure_poison() || (unsigned int)cure_confusion() )
LABEL_22:
v9 = 1;
break;
case 22:
v1 = 60LL;
v9 = dispel_creature(4LL, 60LL);
break;
case 24:
v1 = (unsigned int)char_col;
v9 = unlight_area((unsigned int)char_row, v1);
break;
case 31:
break;
default:
msg_print("Internal error in staffs()");
break;
}
v8 = v20[0];
}
v13 = (char *)&inventory[56 * v2];
if ( v9 )
{
if ( !(unsigned int)known1_p(v13) )
{
v14 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) >> 31);
LODWORD(v14) = ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) % *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54])
/ *((unsigned __int16 *)&py + 32);
prt_experience(v13, v1, v14);
identify(&v17);
}
}
else if ( !(unsigned int)known1_p(v13) )
{
sample(&inventory[56 * v2]);
}
result = desc_charges(v17);
}
}
}
return result;
}

original_code:
void use()
{
  int32u i;
  int j, k, item_val, chance, y, x;
  register int ident;
  register struct misc *m_ptr;
  register inven_type *i_ptr;
  free_turn_flag = 1;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(55, -1, &j, &k))
    msg_print("You are not carrying any staffs.");
  else if (get_item(&item_val, "Use which staff?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = 0;
      m_ptr = &py.misc;
      chance = m_ptr->save + stat_adj(1) - (int)i_ptr->level - 5
 + (class_level_adj[m_ptr->pclass][2] * m_ptr->lev / 3);
      if (py.flags.confused > 0)
 chance = chance / 2;
      if ((chance < 3) && (randint(3 - chance + 1) == 1))
 chance = 3;
      if (chance <= 0) chance = 1;
      if (randint(chance) < 3)
 msg_print("You failed to use the staff properly.");
      else if (i_ptr->p1 > 0)
 {
   i = i_ptr->flags;
   ident = 0;
   (i_ptr->p1)--;
   while (i != 0)
     {
       j = bit_pos(&i) + 1;
       switch(j)
  {
  case 1:
    ident = light_area(char_row, char_col);
    break;
  case 2:
    ident = detect_sdoor();
    break;
  case 3:
    ident = detect_trap();
    break;
  case 4:
    ident = detect_treasure();
    break;
  case 5:
    ident = detect_object();
    break;
  case 6:
    teleport(100);
    ident = 1;
    break;
  case 7:
    ident = 1;
    earthquake();
    break;
  case 8:
    ident = 0;
    for (k = 0; k < randint(4); k++)
      {
        y = char_row;
        x = char_col;
        ident |= summon_monster(&y, &x, 0);
      }
    break;
  case 10:
    ident = 1;
    destroy_area(char_row, char_col);
    break;
  case 11:
    ident = 1;
    starlite(char_row, char_col);
    break;
  case 12:
    ident = speed_monsters(1);
    break;
  case 13:
    ident = speed_monsters(-1);
    break;
  case 14:
    ident = sleep_monsters2();
    break;
  case 15:
    ident = hp_player(randint(8));
    break;
  case 16:
    ident = detect_invisible();
    break;
  case 17:
    if (py.flags.fast == 0)
      ident = 1;
    py.flags.fast += randint(30) + 15;
    break;
  case 18:
    if (py.flags.slow == 0)
      ident = 1;
    py.flags.slow += randint(30) + 15;
    break;
  case 19:
    ident = mass_poly();
    break;
  case 20:
    if (remove_curse())
      {
        if (py.flags.blind < 1)
   msg_print("The staff glows blue for a moment..");
        ident = 1;
      }
    break;
  case 21:
    ident = detect_evil();
    break;
  case 22:
    if ((cure_blindness()) || (cure_poison()) ||
        (cure_confusion()))
      ident = 1;
    break;
  case 23:
    ident = dispel_creature(0x0004, 60);
    break;
  case 25:
    ident = unlight_area(char_row, char_col);
    break;
  case 32:
    break;
  default:
    msg_print("Internal error in staffs()");
    break;
  }
     }
   if (ident)
     {
       if (!known1_p(i_ptr))
  {
    m_ptr = &py.misc;
    m_ptr->exp += (i_ptr->level + (m_ptr->lev >> 1)) /
      m_ptr->lev;
    prt_experience();
    identify(&item_val);
    i_ptr = &inventory[item_val];
  }
     }
   else if (!known1_p(i_ptr))
     sample (i_ptr);
   desc_charges(item_val);
 }
      else
 {
   msg_print("The staff has no charges left.");
   if (!known2_p(i_ptr))
     add_inscribe(i_ptr, 0x4);
 }
    }
}

canonical_original_code:
void use()
{
  unsigned long i;
  int j; int k; int item_val; int chance; int y; int x;
  register int ident;
  register struct misc *m_ptr;
  register struct inven_type *i_ptr;
  free_turn_flag = 1;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(55, -1, &j, &k))
    msg_print("You are not carrying any staffs.");
  else if (get_item(&item_val, "Use which staff?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = 0;
      m_ptr = &py.misc;
      chance = m_ptr->save + stat_adj(1) - (int)i_ptr->level - 5
 + (class_level_adj[m_ptr->pclass][2] * m_ptr->lev / 3);
      if (py.flags.confused > 0)
 chance = chance / 2;
      if ((chance < 3) && (randint(3 - chance + 1) == 1))
 chance = 3;
      if (chance <= 0) chance = 1;
      if (randint(chance) < 3)
 msg_print("You failed to use the staff properly.");
      else if (i_ptr->p1 > 0)
 {
   i = i_ptr->flags;
   ident = 0;
   (i_ptr->p1)--;
   while (i != 0)
     {
       j = bit_pos(&i) + 1;
       switch(j)
  {
  case 1:
    ident = light_area(char_row, char_col);
    break;
  case 2:
    ident = detect_sdoor();
    break;
  case 3:
    ident = detect_trap();
    break;
  case 4:
    ident = detect_treasure();
    break;
  case 5:
    ident = detect_object();
    break;
  case 6:
    teleport(100);
    ident = 1;
    break;
  case 7:
    ident = 1;
    earthquake();
    break;
  case 8:
    ident = 0;
    for (k = 0; k < randint(4); k++)
      {
        y = char_row;
        x = char_col;
        ident |= summon_monster(&y, &x, 0);
      }
    break;
  case 10:
    ident = 1;
    destroy_area(char_row, char_col);
    break;
  case 11:
    ident = 1;
    starlite(char_row, char_col);
    break;
  case 12:
    ident = speed_monsters(1);
    break;
  case 13:
    ident = speed_monsters(-1);
    break;
  case 14:
    ident = sleep_monsters2();
    break;
  case 15:
    ident = hp_player(randint(8));
    break;
  case 16:
    ident = detect_invisible();
    break;
  case 17:
    if (py.flags.fast == 0)
      ident = 1;
    py.flags.fast += randint(30) + 15;
    break;
  case 18:
    if (py.flags.slow == 0)
      ident = 1;
    py.flags.slow += randint(30) + 15;
    break;
  case 19:
    ident = mass_poly();
    break;
  case 20:
    if (remove_curse())
      {
        if (py.flags.blind < 1)
   msg_print("The staff glows blue for a moment..");
        ident = 1;
      }
    break;
  case 21:
    ident = detect_evil();
    break;
  case 22:
    if ((cure_blindness()) || (cure_poison()) ||
        (cure_confusion()))
      ident = 1;
    break;
  case 23:
    ident = dispel_creature(0x0004, 60);
    break;
  case 25:
    ident = unlight_area(char_row, char_col);
    break;
  case 32:
    break;
  default:
    msg_print("Internal error in staffs()");
    break;
  }
     }
   if (ident)
     {
       if (!known1_p(i_ptr))
  {
    m_ptr = &py.misc;
    m_ptr->exp += (i_ptr->level + (m_ptr->lev >> 1)) /
      m_ptr->lev;
    prt_experience();
    identify(&item_val);
    i_ptr = &inventory[item_val];
  }
     }
   else if (!known1_p(i_ptr))
     sample (i_ptr);
   desc_charges(item_val);
 }
      else
 {
   msg_print("The staff has no charges left.");
   if (!known2_p(i_ptr))
     add_inscribe(i_ptr, 0x4);
 }
    }
}

variable_types: y int

variable_types: x int

user_defined_types: struct misc { char name[27]; unsigned char male; long au; long max_exp; long exp; unsigned short exp_frac; unsigned short age; unsigned short ht; unsigned short wt; unsigned short lev; unsigned short max_dlv; short srh; short fos; short bth; short bthb; short mana; short mhp; short ptohit; short ptodam; short pac; short ptoac; short dis_th; short dis_td; short dis_ac; short dis_tac; short disarm; short save; short sc; short stl; unsigned char pclass; unsigned char prace; unsigned char hitdie; unsigned char expfact; short cmana; unsigned short cmana_frac; short chp; unsigned short chp_frac; char history[4][60]; }


bell

decompiled_code:
int __fastcall Graphics::bell(Graphics *this)
{
return beep();
}

canonical_decompiled_code:
int __fastcall Graphics::func1(Graphics *this)
{
return beep();
}

original_code:
void bell()
{
  put_qio();
  if (! sound_beep_flag)
    return;
  (void) write(1, "\007", 1);
}


repo: lomegor/procs

decompiled_code:
void __fastcall __noreturn wait_for_receive(void *a1)
{
int v1; // eax
const char *v2; // rsi
int v3; // ebx
socklen_t v4; // edx
socklen_t v5; // [rsp+0h] [rbp-38h] BYREF
int arg; // [rsp+4h] [rbp-34h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-28h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

v1 = socket(2, 1, 0);
v2 = "Error creating receiving socket";
if ( v1 >= 0 )
{
v3 = v1;
v8.sa_family = 2;
*(_DWORD *)&v8.sa_data[2] = inet_addr(cp);
*(_WORD *)v8.sa_data = _bswap_16(port);
if ( bind(v3, &v8, v4) >= 0 )
{
listen(v3, 5);
while ( 1 )
{
v5 = 16;
arg = accept(v3, &addr, &v5);
if ( pthread_create(&newthread, 0LL, receive_client, &arg) )
syslog(4, "Error binding receiving socket");
else
syslog(6, "Receiving process...");
}
}
v2 = "Error binding receiving socket";
}
syslog(3, v2);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
int v1; // eax
const char *v2; // rsi
int v3; // ebx
socklen_t v4; // edx
socklen_t v5; // [rsp+0h] [rbp-38h] BYREF
int arg; // [rsp+4h] [rbp-34h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-28h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

v1 = socket(2, 1, 0);
v2 = "Error creating receiving socket";
if ( v1 >= 0 )
{
v3 = v1;
v8.sa_family = 2;
*(_DWORD *)&v8.sa_data[2] = inet_addr(cp);
*(_WORD *)v8.sa_data = func0(port);
if ( bind(v3, &v8, v4) >= 0 )
{
listen(v3, 5);
while ( 1 )
{
v5 = 16;
arg = accept(v3, &addr, &v5);
if ( pthread_create(&newthread, 0LL, receive_client, &arg) )
syslog(4, "Error binding receiving socket");
else
syslog(6, "Receiving process...");
}
}
v2 = "Error binding receiving socket";
}
syslog(3, v2);
pthread_exit(0LL);
}

original_code:
void*
wait_for_receive(void* nothing) {
 int receiver;
 struct sockaddr_in mine;
 receiver = socket(2, SOCK_STREAM, 0);
 if (receiver < 0) {
   syslog(3,"Error creating receiving socket");
   pthread_exit(((void *)0));
  return ((void *)0);
 }
 mine.sin_family = 2;
 mine.sin_addr.s_addr = inet_addr(ip);
 mine.sin_port = htons(port);
 if (bind(receiver,(struct sockaddr *)&mine,sizeof(mine)) < 0) {
   syslog(3,"Error binding receiving socket");
   pthread_exit(((void *)0));
  return ((void *)0);
 }
 listen(receiver,5);
 while (1) {
  struct sockaddr_in them;
  pthread_t threadn;
  socklen_t cliente_len = sizeof(them);
  int client = accept(receiver,(struct sockaddr *)&them, &cliente_len);
  if (pthread_create(&threadn,((void *)0),receive_client,(void *) &client))
   syslog(4,"Error binding receiving socket");
  else
   syslog(6,"Receiving process...");
 }
  close(receiver);
 pthread_exit(((void *)0));
 return ((void *)0);
}

canonical_original_code:
void *wait_for_receive(void *nothing) {
 int receiver;
 struct sockaddr_in mine;
 receiver = socket(2, SOCK_STREAM, 0);
 if (receiver < 0) {
   syslog(3,"Error creating receiving socket");
   pthread_exit(((void *)0));
  return ((void *)0);
 }
 mine.sin_family = 2;
 mine.sin_addr.s_addr = inet_addr(ip);
 mine.sin_port = htons(port);
 if (bind(receiver,(struct sockaddr *)&mine,sizeof(mine)) < 0) {
   syslog(3,"Error binding receiving socket");
   pthread_exit(((void *)0));
  return ((void *)0);
 }
 listen(receiver,5);
 while (1) {
  struct sockaddr_in them;
  unsigned long threadn;
  unsigned int cliente_len = sizeof(them);
  int client = accept(receiver,(struct sockaddr *)&them, &cliente_len);
  if (pthread_create(&threadn,((void *)0),receive_client,(void *) &client))
   syslog(4,"Error binding receiving socket");
  else
   syslog(6,"Receiving process...");
 }
  close(receiver);
 pthread_exit(((void *)0));
 return ((void *)0);
}

variable_types:
nothing
void *

variable_types: receiver int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
threadn
unsigned long

variable_types: client int

return_type: void *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
ssize_t __fastcall write_id(void *buf, int *a2)
{
int v2; // eax
int v3; // edi
char bufa[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = strlen((const char *)buf);
write(*a2, buf, v2);
v3 = *a2;
bufa[0] = 10;
return write(v3, bufa, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func2(void *buf, int *a2)
{
int v2; // eax
int v3; // edi
char bufa[25]; // [rsp+Fh] [rbp-19h] BYREF

v2 = strlen((const char *)buf);
write(*a2, buf, v2);
v3 = *a2;
bufa[0] = 10;
return write(v3, bufa, 1uLL);
}

original_code:
void
write_id(void* item,void* other) {
 int l = strlen(((struct procs *)item)->id);
 write(*(int*)other,((struct procs *)item)->id,l);
 unsigned char type = '\n';
 write(*(int*)other,&type,sizeof(type));
}

canonical_original_code:
void write_id(void *item, void *other) {
 int l = strlen(((struct procs *)item)->id);
 write(*(int *)other,((struct procs *)item)->id,l);
 unsigned char type = '\n';
 write(*(int *)other,&type,sizeof(type));
}

variable_types:
item
void *

variable_types:
other
void *

variable_types:
type
unsigned char

user_defined_types: struct procs { char id[30]; struct proc_process *proc; }

user_defined_types: struct proc_process { char *name; struct list *chunks; }

user_defined_types: struct list { struct item *head; int len; }

user_defined_types: struct item { void *p; struct item *next; }


decompiled_code:
_BOOL8 __fastcall is_id(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( a2 )
result = strcmp(a1, a2) == 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( a2 )
result = strcmp(a1, a2) == 0;
else
result = 0LL;
return result;
}

original_code:
int
is_id(void* item,void* id) {
 return (id!=((void *)0) && !strcmp(((struct procs *)item)->id,(char*)id));
}

canonical_original_code:
int is_id(void *item, void *id) {
 return (id!=((void *)0) && !strcmp(((struct procs *)item)->id,(char *)id));
}

variable_types:
id
void *


decompiled_code:
int __fastcall send_process_to_admin(__int64 a1, const char *a2, int *a3)
{
int result; // eax

result = is_id((const char *)a1, a2);
if ( result )
{
write_process(**(_QWORD **)(a1 + 32), *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL), a3, &write_to_socket);
result = close(*a3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, const char *a2, int *a3)
{
int result; // eax

result = func3((const char *)a1, a2);
if ( result )
{
write_process(**(_QWORD **)(a1 + 32), *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL), a3, &write_to_socket);
result = close(*a3);
}
return result;
}

original_code:
void
send_process_to_admin(void*other, void* id, void* c) {
 if (!is_id(other,id))
   return;
 id = ((void *)0);
 write_process(*(((struct procs *)other)->proc),c,write_to_socket);
 close(*(int*)c);
 return;
}

canonical_original_code:
void send_process_to_admin(void *other, void *id, void *c) {
 if (!is_id(other,id))
   return;
 id = ((void *)0);
 write_process(*(((struct procs *)other)->proc),c,write_to_socket);
 close(*(int *)c);
 return;
}

variable_types:
c
void *


decompiled_code:
void __fastcall __noreturn wait_for_admin(void *a1)
{
int v1; // eax
const char *v2; // rsi
int v3; // ebx
socklen_t v4; // [rsp+0h] [rbp-B8h] BYREF
int arg; // [rsp+4h] [rbp-B4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-B0h] BYREF
struct sockaddr v7; // [rsp+10h] [rbp-A8h] BYREF
char s[32]; // [rsp+20h] [rbp-98h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-78h] BYREF

sprintf(s, "rm -f %s", "/etc/procs/procs.sock");
system(s);
v1 = socket(1, 1, 0);
v2 = "Error creating admin socket";
if ( v1 >= 0 )
{
v3 = v1;
addr.sa_family = 1;
strcpy(addr.sa_data, "/etc/procs/procs.sock");
if ( bind(v1, &addr, 0x6Eu) >= 0 )
{
listen(v3, 5);
while ( 1 )
{
v4 = 16;
arg = accept(v3, &v7, &v4);
if ( pthread_create(&newthread, 0LL, admin, &arg) )
syslog(4, "Error creating admin");
else
syslog(6, "Receiving admin");
}
}
v2 = "Error binding admins socket";
}
syslog(3, v2);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(void *a1)
{
int v1; // eax
const char *v2; // rsi
int v3; // ebx
socklen_t v4; // [rsp+0h] [rbp-B8h] BYREF
int arg; // [rsp+4h] [rbp-B4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-B0h] BYREF
struct sockaddr v7; // [rsp+10h] [rbp-A8h] BYREF
char s[32]; // [rsp+20h] [rbp-98h] BYREF
struct sockaddr addr; // [rsp+40h] [rbp-78h] BYREF

sprintf(s, "rm -f %s", "/etc/procs/procs.sock");
system(s);
v1 = socket(1, 1, 0);
v2 = "Error creating admin socket";
if ( v1 >= 0 )
{
v3 = v1;
addr.sa_family = 1;
strcpy(addr.sa_data, "/etc/procs/procs.sock");
if ( bind(v1, &addr, 0x6Eu) >= 0 )
{
listen(v3, 5);
while ( 1 )
{
v4 = 16;
arg = accept(v3, &v7, &v4);
if ( pthread_create(&newthread, 0LL, admin, &arg) )
syslog(4, "Error creating admin");
else
syslog(6, "Receiving admin");
}
}
v2 = "Error binding admins socket";
}
syslog(3, v2);
pthread_exit(0LL);
}

original_code:
void*
wait_for_admin(void* nothing) {
 char tmp[30];
 sprintf(tmp,"rm -f %s","/etc/procs/procs.sock");
 system(tmp);
 int receiver;
 struct sockaddr_un mine;
 receiver = socket(1, SOCK_STREAM, 0);
 if (receiver < 0) {
  syslog(3,"Error creating admin socket");
  pthread_exit(((void *)0));
  return ((void *)0);
 }
 mine.sun_family = 1;
 strcpy(mine.sun_path,"/etc/procs/procs.sock");
 if (bind(receiver,(struct sockaddr *)&mine,sizeof(mine)) < 0) {
   syslog(3,"Error binding admins socket");
   pthread_exit(((void *)0));
  return ((void *)0);
 }
 listen(receiver,5);
 while (1) {
  struct sockaddr_in them;
  pthread_t threadn;
  socklen_t cliente_len = sizeof(them);
  int client = accept(receiver,(struct sockaddr *)&them, &cliente_len);
  if (pthread_create(&threadn,((void *)0),admin,(void *) &client))
   syslog(4,"Error creating admin");
  else
   syslog(6,"Receiving admin");
 }
  close(receiver);
 pthread_exit(((void *)0));
 return ((void *)0);
}

canonical_original_code:
void *wait_for_admin(void *nothing) {
 char tmp[30];
 sprintf(tmp,"rm -f %s","/etc/procs/procs.sock");
 system(tmp);
 int receiver;
 struct sockaddr_un mine;
 receiver = socket(1, SOCK_STREAM, 0);
 if (receiver < 0) {
  syslog(3,"Error creating admin socket");
  pthread_exit(((void *)0));
  return ((void *)0);
 }
 mine.sun_family = 1;
 strcpy(mine.sun_path,"/etc/procs/procs.sock");
 if (bind(receiver,(struct sockaddr *)&mine,sizeof(mine)) < 0) {
   syslog(3,"Error binding admins socket");
   pthread_exit(((void *)0));
  return ((void *)0);
 }
 listen(receiver,5);
 while (1) {
  struct sockaddr_in them;
  unsigned long threadn;
  unsigned int cliente_len = sizeof(them);
  int client = accept(receiver,(struct sockaddr *)&them, &cliente_len);
  if (pthread_create(&threadn,((void *)0),admin,(void *) &client))
   syslog(4,"Error creating admin");
  else
   syslog(6,"Receiving admin");
 }
  close(receiver);
 pthread_exit(((void *)0));
 return ((void *)0);
}

variable_types:
tmp
char [30]

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }


decompiled_code:
void __fastcall __noreturn signal_handler(unsigned int a1)
{
char *v1; // rax

if ( a1 == 1 )
{
syslog(4, "Received SIGHUP signal.");
}
else if ( a1 == 15 )
{
syslog(4, "Received SIGTERM signal.");
}
else
{
v1 = strsignal(a1);
syslog(4, "Unhandled signal (%d) %s", a1, v1);
}
sem_destroy(&mutex);
sem_destroy(&next);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(unsigned int a1)
{
char *v1; // rax

if ( a1 == 1 )
{
syslog(4, "Received SIGHUP signal.");
}
else if ( a1 == 15 )
{
syslog(4, "Received SIGTERM signal.");
}
else
{
v1 = strsignal(a1);
syslog(4, "Unhandled signal (%d) %s", a1, v1);
}
sem_destroy(&mutex);
sem_destroy(&next);
exit(0);
}

original_code:
void signal_handler(int sig) {
 switch(sig) {
  case 1:
   syslog(4, "Received SIGHUP signal.");
   break;
  case 15:
   syslog(4, "Received SIGTERM signal.");
   break;
  default:
   syslog(4, "Unhandled signal (%d) %s", sig, strsignal(sig));
   break;
 }
 sem_destroy(&mutex);
 sem_destroy(&next);
 exit(0);
}

variable_types: sig int


decompiled_code:
char *__fastcall receive_process(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
char *v3; // r12
int v5; // [rsp+Ch] [rbp-3Ch] BYREF
char s[56]; // [rsp+10h] [rbp-38h] BYREF

v5 = a1;
v1 = read_process(&v5, &read_from_socket);
syslog(6, "Process received... adding to list");
sem_wait(&mutex);
v2 = (unsigned int)current_id++;
sprintf(s, "PROCS%d", v2);
v3 = (char *)malloc(0x28uLL);
strcpy(v3, s);
*((_QWORD *)v3 + 4) = v1;
list_append_constprop_0((__int64)v3);
next_process = v1;
sem_post(&next);
sem_post(&mutex);
return v3;
}

canonical_decompiled_code:
char *__fastcall func11(int a1)
{
__int64 v1; // rbx
__int64 v2; // rdx
char *v3; // r12
int v5; // [rsp+Ch] [rbp-3Ch] BYREF
char s[56]; // [rsp+10h] [rbp-38h] BYREF

v5 = a1;
v1 = read_process(&v5, &read_from_socket);
syslog(6, "Process received... adding to list");
sem_wait(&mutex);
v2 = (unsigned int)current_id++;
sprintf(s, "PROCS%d", v2);
v3 = (char *)malloc(0x28uLL);
strcpy(v3, s);
*((_QWORD *)v3 + 4) = v1;
list_append_constprop_0((__int64)v3);
next_process = v1;
sem_post(&next);
sem_post(&mutex);
return v3;
}

original_code:
void*
receive_process(int sock) {
 struct proc_process *pp = read_process(&sock,read_from_socket);
 syslog(6,"Process received... adding to list");
 sem_wait(&mutex);
 char tmp[30];
 sprintf(tmp,"PROCS%d",current_id++);
 struct procs* p = malloc(sizeof(struct procs));
 strcpy(p->id,tmp);
 p->proc=pp;
 list_append(&procs_id,p);
 next_process=pp;
 sem_post(&next);
 sem_post(&mutex);
 return p;
}

canonical_original_code:
void *receive_process(int sock) {
 struct proc_process *pp = read_process(&sock,read_from_socket);
 syslog(6,"Process received... adding to list");
 sem_wait(&mutex);
 char tmp[30];
 sprintf(tmp,"PROCS%d",current_id++);
 struct procs *p = malloc(sizeof(struct procs));
 strcpy(p->id,tmp);
 p->proc=pp;
 list_append(&procs_id,p);
 next_process=pp;
 sem_post(&next);
 sem_post(&mutex);
 return p;
}

variable_types: sock int

variable_types: struct procs { char id[30]; struct proc_process { char *name; struct list { struct item { void *p; struct item *next; } *head; int len; } *chunks; } *proc; } *


decompiled_code:
void __fastcall __noreturn receive_client(void *a1)
{
receive_process(*(_DWORD *)a1);
close(*(_DWORD *)a1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(void *a1)
{
func11(*(_DWORD *)a1);
close(*(_DWORD *)a1);
pthread_exit(0LL);
}

original_code:
void*
receive_client(void* other) {
 receive_process(*(int*)other);
  close(*(int*)other);
 pthread_exit(((void *)0));
 return ((void *)0);
}

canonical_original_code:
void *receive_client(void *other) {
 receive_process(*(int *)other);
  close(*(int *)other);
 pthread_exit(((void *)0));
 return ((void *)0);
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v5; // rax
unsigned int v6; // eax
const char *v7; // rbp
char *v8; // rax
__pid_t v9; // eax
__pid_t v10; // eax
const char *v11; // rsi
int longind; // [rsp+Ch] [rbp-2Ch] BYREF
pthread_t newthread; // [rsp+10h] [rbp-28h] BYREF
pthread_t v14[4]; // [rsp+18h] [rbp-20h] BYREF

v3 = 1;
list_init_constprop_0();
v5 = *argv;
longind = 0;
program_name = (__int64)v5;
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "vhf", &long_options_0, &longind);
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'h':
usage();
exit(0);
case 'v':
verbose = 1;
break;
case 'f':
v3 = 0;
break;
default:
fprintf(stderr, "?? getopt returned character code 0%o ??\n", v6);
break;
}
}
openlog("procs_log", 2, 8);
if ( !v3 )
{
LABEL_11:
cp = "127.0.0.1";
port = 12092;
if ( optind < argc )
{
v7 = argv[optind];
v8 = strchr(v7, 58);
if ( v8 )
{
*v8 = 0;
cp = (char *)argv[optind];
port = v8[1];
}
else
{
cp = (char *)v7;
}
}
sem_init(&mutex, 0, 1u);
sem_init(&next, 0, 1u);
pthread_create(&newthread, 0LL, (void *(*)(void *))wait_for_admin, 0LL);
pthread_create(v14, 0LL, (void *(*)(void *))wait_for_receive, 0LL);
while ( 1 )
sleep(0x2710u);
}
v9 = fork();
if ( v9 >= 0 )
{
if ( v9 )
goto LABEL_23;
signal(1, (__sighandler_t)signal_handler);
signal(15, (__sighandler_t)signal_handler);
signal(2, (__sighandler_t)signal_handler);
signal(3, (__sighandler_t)signal_handler);
v10 = fork();
if ( v10 < 0 )
goto LABEL_26;
if ( v10 )
LABEL_23:
exit(0);
umask(0);
if ( setsid() < 0 )
{
v11 = "Couldn't get sid";
}
else
{
v11 = "Couldn't change dir";
if ( chdir("/") >= 0 )
{
close(0);
close(1);
close(2);
goto LABEL_11;
}
}
syslog(3, v11);
}
LABEL_26:
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
const char *v5; // rax
unsigned int v6; // eax
const char *v7; // rbp
char *v8; // rax
__pid_t v9; // eax
__pid_t v10; // eax
const char *v11; // rsi
int longind; // [rsp+Ch] [rbp-2Ch] BYREF
pthread_t newthread; // [rsp+10h] [rbp-28h] BYREF
pthread_t v14[4]; // [rsp+18h] [rbp-20h] BYREF

v3 = 1;
func8();
v5 = *argv;
longind = 0;
program_name = (__int64)v5;
while ( 1 )
{
v6 = getopt_long(argc, (char *const *)argv, "vhf", &long_options_0, &longind);
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'h':
func14();
exit(0);
case 'v':
verbose = 1;
break;
case 'f':
v3 = 0;
break;
default:
fprintf(stderr, "?? getopt returned character code 0%o ??\n", v6);
break;
}
}
openlog("procs_log", 2, 8);
if ( !v3 )
{
LABEL_11:
cp = "127.0.0.1";
port = 12092;
if ( optind < argc )
{
v7 = argv[optind];
v8 = strchr(v7, 58);
if ( v8 )
{
*v8 = 0;
cp = (char *)argv[optind];
port = v8[1];
}
else
{
cp = (char *)v7;
}
}
sem_init(&mutex, 0, 1u);
sem_init(&next, 0, 1u);
pthread_create(&newthread, 0LL, (void *(*)(void *))wait_for_admin, 0LL);
pthread_create(v14, 0LL, (void *(*)(void *))wait_for_receive, 0LL);
while ( 1 )
sleep(0x2710u);
}
v9 = fork();
if ( v9 >= 0 )
{
if ( v9 )
goto LABEL_23;
signal(1, (__sighandler_t)signal_handler);
signal(15, (__sighandler_t)signal_handler);
signal(2, (__sighandler_t)signal_handler);
signal(3, (__sighandler_t)signal_handler);
v10 = fork();
if ( v10 < 0 )
goto LABEL_26;
if ( v10 )
LABEL_23:
exit(0);
umask(0);
if ( setsid() < 0 )
{
v11 = "Couldn't get sid";
}
else
{
v11 = "Couldn't change dir";
if ( chdir("/") >= 0 )
{
close(0);
close(1);
close(2);
goto LABEL_11;
}
}
syslog(3, v11);
}
LABEL_26:
exit(1);
}

original_code:
int
main(int argc, char** argv) {
 list_init(&procs_id);
 program_name = argv[0];
 static struct option long_options[] = {
  {"nofork", 1, 0, 'f'},
  {"verbose", 0, 0, 'v'},
  {"help", 0, 0, 'h'},
  {((void *)0), 0, ((void *)0), 0}
 };
 int c,option_index = 0;
 int forkit = !0;
 while ((c = getopt_long(argc, argv, "vhf", long_options, &option_index)) != -1) {
  switch (c) {
   case 'f':
    forkit=0;
    break;
   case 'v':
    verbose=!0;
    break;
   case 'h':
    usage();
    exit(0);
    break;
   default:
    fprintf(stderr,"?? getopt returned character code 0%o ??\n", c);
  }
 }
 openlog("procs_log",0x02,(1<<3));
 pid_t pid, sid;
 if (forkit) {
  pid = fork();
  if (pid < 0)
   exit(1);
  if (pid > 0)
   exit(0);
  signal(1, signal_handler);
  signal(15, signal_handler);
  signal(2, signal_handler);
  signal(3, signal_handler);
  sid = fork();
  if (sid < 0)
   exit(1);
  else if (sid > 0)
   exit(0);
  umask(0);
  sid = setsid();
  if (sid < 0) {
   syslog(3,"Couldn't get sid");
   exit(1);
  }
  if ((chdir("/")) < 0) {
   syslog(3,"Couldn't change dir");
   exit(1);
  }
  close(0);
  close(1);
  close(2);
 }
 ip="127.0.0.1";
 port=12092;
 if (optind < argc) {
  char* pos = strchr(argv[optind],':');
  if (pos!=((void *)0)) {
   *pos='\0';
   ip=argv[optind];
   port=*(++pos);
  } else {
   ip=argv[optind];
   port = 12092;
  }
 }
 sem_init(&mutex, 0, 1);
 sem_init(&next, 0, 1);
 pthread_t admin,receiver;
 pthread_create(&admin,((void *)0),wait_for_admin,(void*)((void *)0));
 pthread_create(&receiver,((void *)0),wait_for_receive,(void*)((void *)0));
 while(1) {
  sleep(10000);
 }
 closelog();
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv) {
 list_init(&procs_id);
 program_name = argv[0];
 static struct option long_options[] = {
  {"nofork", 1, 0, 'f'},
  {"verbose", 0, 0, 'v'},
  {"help", 0, 0, 'h'},
  {((void *)0), 0, ((void *)0), 0}
 };
 int c; int option_index = 0;
 int forkit = !0;
 while ((c = getopt_long(argc, argv, "vhf", long_options, &option_index)) != -1) {
  switch (c) {
   case 'f':
    forkit=0;
    break;
   case 'v':
    verbose=!0;
    break;
   case 'h':
    usage();
    exit(0);
    break;
   default:
    fprintf(stderr,"?? getopt returned character code 0%o ??\n", c);
  }
 }
 openlog("procs_log",0x02,(1<<3));
 int pid; int sid;
 if (forkit) {
  pid = fork();
  if (pid < 0)
   exit(1);
  if (pid > 0)
   exit(0);
  signal(1, signal_handler);
  signal(15, signal_handler);
  signal(2, signal_handler);
  signal(3, signal_handler);
  sid = fork();
  if (sid < 0)
   exit(1);
  else if (sid > 0)
   exit(0);
  umask(0);
  sid = setsid();
  if (sid < 0) {
   syslog(3,"Couldn't get sid");
   exit(1);
  }
  if ((chdir("/")) < 0) {
   syslog(3,"Couldn't change dir");
   exit(1);
  }
  close(0);
  close(1);
  close(2);
 }
 ip="127.0.0.1";
 port=12092;
 if (optind < argc) {
  char *pos = strchr(argv[optind],':');
  if (pos!=((void *)0)) {
   *pos='\0';
   ip=argv[optind];
   port=*(++pos);
  } else {
   ip=argv[optind];
   port = 12092;
  }
 }
 sem_init(&mutex, 0, 1);
 sem_init(&next, 0, 1);
 unsigned long admin; unsigned long receiver;
 pthread_create(&admin,((void *)0),wait_for_admin,(void *)((void *)0));
 pthread_create(&receiver,((void *)0),wait_for_receive,(void *)((void *)0));
 while(1) {
  sleep(10000);
 }
 closelog();
 exit(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: c int

variable_types: forkit int

variable_types: pid int

variable_types: sid int

variable_types:
pos
char *

variable_types:
admin
unsigned long

variable_types:
receiver
unsigned long


original_code:
static void
as_memcpy(long src,long dst, long length) {
 char *p = (char*)code_addr;
 *p++=0x48; *p++=0xbe;
 *(long*)(p) = src; p+=8;
 *p++=0x48; *p++=0xbf;
 *(long*)(p) = dst; p+=8;
 *p++=0x48; *p++=0xb9;
 *(long*)(p) = length>>3; p+=8;
 *p++=0xf3;*p++=0x48;*p++=0xa5;
 code_addr = (long)p;
}

canonical_original_code:
static void as_memcpy(long src, long dst, long length) {
 char *p = (char*)code_addr;
 *p++=0x48; *p++=0xbe;
 *(long *)(p) = src; p+=8;
 *p++=0x48; *p++=0xbf;
 *(long *)(p) = dst; p+=8;
 *p++=0x48; *p++=0xb9;
 *(long *)(p) = length>>3; p+=8;
 *p++=0xf3;*p++=0x48;*p++=0xa5;
 code_addr = (long)p;
}

variable_types: src long

variable_types: dst long

variable_types: length long

variable_types:
p
char *


decompiled_code:
__int64 __fastcall restore_chunk_tls(const __m128i *a1)
{
__int64 v1; // rax
__int64 result; // rax

if ( a1->m128i_i32[1] )
{
*(__m128i *)data_addr = _mm_loadu_si128(a1);
v1 = code_addr;
*(_QWORD *)(code_addr + 1) = 0xBB000000CDLL;
result = v1 + 12;
*(_BYTE *)(result - 12) = -72;
*(_QWORD *)(result - 6) = data_addr;
data_addr = (char *)data_addr + 16;
*(_WORD *)(result - 2) = -32563;
code_addr = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const __m128i *a1)
{
__int64 v1; // rax
__int64 result; // rax

if ( a1->m128i_i32[1] )
{
*(__m128i *)data_addr = _mm_loadu_si128(a1);
v1 = code_addr;
*(_QWORD *)(code_addr + 1) = 0xBB000000CDLL;
result = v1 + 12;
*(_BYTE *)(result - 12) = -72;
*(_QWORD *)(result - 6) = data_addr;
data_addr = (char *)data_addr + 16;
*(_WORD *)(result - 2) = -32563;
code_addr = result;
}
return result;
}

original_code:
void
restore_chunk_tls(struct proc_tls tls)
{
 if (!tls.u->base_addr)
  return;
 memcpy((void*)data_addr,tls.u,sizeof(struct user_desc));
 char* p = (char*)code_addr;
 *p++=0xb8;*(long*)(p)=205; p+=4;
 *p++=0xbb;*(long*)(p)=data_addr; p+=4;
 *p++=0xcd;*p++=0x80;
 code_addr = (long) p;
 data_addr+=sizeof(struct user_desc);
}

canonical_original_code:
void restore_chunk_tls(struct proc_tls tls)
{
 if (!tls.u->base_addr)
  return;
 memcpy((void *)data_addr,tls.u,sizeof(struct user_desc));
 char *p = (char*)code_addr;
 *p++=0xb8;*(long *)(p)=205; p+=4;
 *p++=0xbb;*(long *)(p)=data_addr; p+=4;
 *p++=0xcd;*p++=0x80;
 code_addr = (long) p;
 data_addr+=sizeof(struct user_desc);
}

variable_types: struct proc_tls { struct user_desc { unsigned int entry_number; unsigned int base_addr; unsigned int limit; unsigned int seg_32bit; unsigned int contents; unsigned int read_exec_only; unsigned int limit_in_pages; unsigned int seg_not_present; unsigned int useable; unsigned int lm; } *u; }

user_defined_types: struct proc_tls { struct user_desc *u; }


decompiled_code:
__int64 __fastcall restore_chunk_vma(int a1, int a2, int a3, int a4, int a5, int a6, __int64 a7, size_t n, __int64 a9, int a10, int a11, int a12, int a13, char *file, void *src)
{
__int64 result; // rax
void *v16; // rax
int v17; // eax

if ( a12 )
{
memcpy(data_addr, src, n);
v16 = sbrk(n);
result = as_memcpy((__int64)data_addr, (__int64)v16, n);
data_addr = (char *)data_addr + n;
}
else
{
result = (unsigned int)a11;
if ( a11 )
{
memcpy(data_addr, src, n);
result = as_mmap_memcpy_constprop_0(a7, n, HIDWORD(a9) | 0x20u, 0, 0, (__int64)data_addr);
data_addr = (char *)data_addr + n;
}
else if ( *file )
{
v17 = open(file, 0);
result = as_mmap_memcpy_constprop_0(a7, n, HIDWORD(a9) | 0x20u, v17, a13, 0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, int a3, int a4, int a5, int a6, __int64 a7, size_t n, __int64 a9, int a10, int a11, int a12, int a13, char *file, void *src)
{
__int64 result; // rax
void *v16; // rax
int v17; // eax

if ( a12 )
{
memcpy(data_addr, src, n);
v16 = sbrk(n);
result = func0((__int64)data_addr, (__int64)v16, n);
data_addr = (char *)data_addr + n;
}
else
{
result = (unsigned int)a11;
if ( a11 )
{
memcpy(data_addr, src, n);
result = func1(a7, n, HIDWORD(a9) | 0x20u, 0, 0, (__int64)data_addr);
data_addr = (char *)data_addr + n;
}
else if ( *file )
{
v17 = open(file, 0);
result = func1(a7, n, HIDWORD(a9) | 0x20u, v17, a13, 0LL);
}
}
return result;
}

original_code:
void
restore_chunk_vma(struct proc_vma vma)
{
 if (vma.is_heap) {
  memcpy((void*)data_addr,vma.data,vma.length);
  as_memcpy(data_addr,(long)sbrk(vma.length),vma.length);
  data_addr+=vma.length;
 } else if (vma.have_data) {
  memcpy((void*)data_addr,vma.data,vma.length);
  as_mmap_memcpy(vma.start,vma.length,0x1|0x2|0x4,0x20|vma.flags,0,0,data_addr);
  data_addr+=vma.length;
 } else if (vma.filename[0]) {
  int fd = open(vma.filename, 00);
  as_mmap_memcpy(vma.start,vma.length,0x1|0x2|0x4,0x20|vma.flags,fd,vma.pg_off,0);
 }
}

canonical_original_code:
void restore_chunk_vma(struct proc_vma vma)
{
 if (vma.is_heap) {
  memcpy((void *)data_addr,vma.data,vma.length);
  as_memcpy(data_addr,(long)sbrk(vma.length),vma.length);
  data_addr+=vma.length;
 } else if (vma.have_data) {
  memcpy((void *)data_addr,vma.data,vma.length);
  as_mmap_memcpy(vma.start,vma.length,0x1|0x2|0x4,0x20|vma.flags,0,0,data_addr);
  data_addr+=vma.length;
 } else if (vma.filename[0]) {
  int fd = open(vma.filename, 00);
  as_mmap_memcpy(vma.start,vma.length,0x1|0x2|0x4,0x20|vma.flags,fd,vma.pg_off,0);
 }
}

variable_types: struct proc_vma { unsigned long start; int prot; long pg_off; char *filename; long *data; }

variable_types: fd int


decompiled_code:
int __fastcall restore_chunk_fd(int a1, int a2, int a3, int a4, int a5, int a6, __int64 fd2, int a8, __off_t offset, int a10, char *file, void *buf, int a13, size_t n)
{
int v14; // ebp
__m128i v16; // [rsp+0h] [rbp-48h] BYREF
__int16 v17; // [rsp+10h] [rbp-38h]

v17 = 88;
v16 = _mm_load_si128((const __m128i *)&LC6);
if ( a10 == 1 )
{
if ( buf && restore_file || (v14 = open(file, SHIDWORD(fd2)), v14 <= 0) )
{
v14 = mkstemp(v16.m128i_i8);
fprintf(stderr, "Restoring file %s as %s\n", file, v16.m128i_i8);
write(v14, buf, n);
lseek(v14, offset, 0);
}
}
else
{
v14 = open(file, SHIDWORD(fd2));
if ( v14 <= 0 )
return printf("Could not open %s\n", file);
}
dup2(v14, fd2);
if ( v14 != (_DWORD)fd2 )
close(v14);
return lseek(fd2, offset, 0);
}

canonical_decompiled_code:
int __fastcall func6(int a1, int a2, int a3, int a4, int a5, int a6, __int64 fd2, int a8, __off_t offset, int a10, char *file, void *buf, int a13, size_t n)
{
int v14; // ebp
__m128i v16; // [rsp+0h] [rbp-48h] BYREF
__int16 v17; // [rsp+10h] [rbp-38h]

v17 = 88;
v16 = _mm_load_si128((const __m128i *)&LC6);
if ( a10 == 1 )
{
if ( buf && restore_file || (v14 = open(file, SHIDWORD(fd2)), v14 <= 0) )
{
v14 = mkstemp(v16.m128i_i8);
fprintf(stderr, "Restoring file %s as %s\n", file, v16.m128i_i8);
write(v14, buf, n);
lseek(v14, offset, 0);
}
}
else
{
v14 = open(file, SHIDWORD(fd2));
if ( v14 <= 0 )
return printf("Could not open %s\n", file);
}
dup2(v14, fd2);
if ( v14 != (_DWORD)fd2 )
close(v14);
return lseek(fd2, offset, 0);
}

original_code:
void
restore_chunk_fd(struct proc_fd pf) {
 char tmpname[] = "/tmp/procs_XXXXXX";
 int ftmp;
 if (pf.type==0x01) {
  if (pf.file.contents==((void *)0) || !restore_file) {
   ftmp = open(pf.file.filename,pf.mode);
   if (ftmp>0) {
    dup2(ftmp,pf.fd);
    if (ftmp!=pf.fd) {
     close(ftmp);
    }
    lseek(pf.fd,pf.offset,0);
    return;
   }
  }
  ftmp = mkstemp(tmpname);
  fprintf(stderr,"Restoring file %s as %s\n",pf.file.filename,tmpname);
  write(ftmp,pf.file.contents,pf.file.size);
  lseek(ftmp,pf.offset,0);
  dup2(ftmp,pf.fd);
  if (ftmp!=pf.fd) {
   close(ftmp);
  }
  lseek(pf.fd,pf.offset,0);
 } else {
  ftmp = open(pf.file.filename,pf.mode);
  if (ftmp>0) {
   dup2(ftmp,pf.fd);
   if (ftmp!=pf.fd) {
    close(ftmp);
   }
   lseek(pf.fd,pf.offset,0);
   return;
  }
  printf("Could not open %s\n",pf.file.filename);
 }
}

variable_types: struct proc_fd { int fd; int mode; int close_on_exec; int fcntl_status; long offset; int type; union { struct proc_console { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[19]; } termios; } console; struct proc_file { char *filename; char *contents; int deleted; long size; } file; struct proc_fifo { char *fifoname; char *contents; int size; int target_pid; int self_other_fd; } fifo; struct proc_socket { char *contents; int size; int proto; union { struct proc_socket_tcp { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } sin; void *ici; } s_tcp; struct proc_socket_udp { struct sockaddr_in sin; } s_udp; struct proc_socket_unix { int type; struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } sockname; struct sockaddr_un peername; } s_unix; }; } socket; }; }

variable_types:
tmpname
char []

variable_types: ftmp int

user_defined_types: struct proc_fd { int fd; int mode; int close_on_exec; int fcntl_status; long offset; int type; union { struct proc_console console; struct proc_file file; struct proc_fifo fifo; struct proc_socket socket; }; }

user_defined_types: struct proc_console { struct termios termios; }

user_defined_types: struct proc_socket { char *contents; int size; int proto; union { struct proc_socket_tcp s_tcp; struct proc_socket_udp s_udp; struct proc_socket_unix s_unix; }; }

user_defined_types: struct proc_socket_tcp { struct sockaddr_in sin; void *ici; }

user_defined_types: struct proc_socket_unix { int type; struct sockaddr_un sockname; struct sockaddr_un peername; }


original_code:
static inline void
list_init(struct list *l) {
 l->head = l->tail = ((void *)0);
 l->len=0;
}

variable_types: struct list { struct item { void *p; struct item *next; } *head; int len; } *


checksum

decompiled_code:
unsigned __int64 __fastcall checksum(char *a1, __int64 a2)
{
char *v2; // rsi
unsigned __int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v2 = &a1[a2];
result = 0LL;
do
result = *a1++ ^ (33 * result);
while ( v2 != a1 );
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(char *a1, __int64 a2)
{
char *v2; // rsi
unsigned __int64 result; // rax

if ( a2 <= 0 )
return 0LL;
v2 = &a1[a2];
result = 0LL;
do
result = *a1++ ^ (33 * result);
while ( v2 != a1 );
return result;
}

original_code:
unsigned long
checksum(char *ptr, long len) {
 long sum=0,i;
 for (i = 0; i < len; i++)
  sum = ((sum << 5) + sum) ^ ptr[i];
 return sum;
}

canonical_original_code:
unsigned long checksum(char *ptr, long len) {
 long sum = 0; long i;
 for (i = 0; i < len; i++)
  sum = ((sum << 5) + sum) ^ ptr[i];
 return sum;
}

variable_types:
ptr
char *

variable_types: len long

variable_types: sum long

variable_types: i long

return_type: unsigned long