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


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
char v2; // bp
__int64 result; // rax
char v4[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( (unsigned int)get_com("Enter character to be identified :", v4) )
{
switch ( v4[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;
while ( 1 )
{
result = (unsigned int)v4[0];
if ( c_list[40 * v0 + 32] == (_DWORD)result )
{
result = bool_roff_recall((unsigned int)v0);
if ( (_DWORD)result )
break;
}
LABEL_92:
if ( --v0 == -1 )
return result;
}
if ( v1 )
{
LABEL_91:
++v1;
v2 = roff_recall((unsigned int)v0);
result = restore_screen();
if ( v2 == 27 )
return result;
goto LABEL_92;
}
put_buffer("You recall those details? [y/n]", 0LL, 40LL);
result = inkey() & 0xFFFFFFDFLL;
if ( (_BYTE)result == 89 )
{
erase_line(0LL, 40LL);
save_screen();
goto LABEL_91;
}
return result;
}

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

if ( (unsigned int)get_com("Enter character to be identified :", v4) )
{
switch ( v4[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;
while ( 1 )
{
result = (unsigned int)v4[0];
if ( c_list[40 * v0 + 32] == (_DWORD)result )
{
result = bool_roff_recall((unsigned int)v0);
if ( (_DWORD)result )
break;
}
LABEL_92:
if ( --v0 == -1 )
return result;
}
if ( v1 )
{
LABEL_91:
++v1;
v2 = roff_recall((unsigned int)v0);
result = restore_screen();
if ( v2 == 27 )
return result;
goto LABEL_92;
}
put_buffer("You recall those details? [y/n]", 0LL, 40LL);
result = inkey() & 0xFFFFFFDFLL;
if ( (_BYTE)result == 89 )
{
erase_line(0LL, 40LL);
save_screen();
goto LABEL_91;
}
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
unsigned int v1; // ebp
int v2; // er12
int v3; // ebx
__int64 v4; // rdi
__int16 v5; // ax
__int64 v6; // rsi
int v7; // er12
__int64 v8; // rsi
int v9; // eax
int v10; // ebx
unsigned int v11; // er13
__int64 v12; // rbx
unsigned int v13; // eax
__int64 v14; // rbx
unsigned int v15; // eax
__int64 v16; // rbx
unsigned int v17; // eax
int v18; // eax
__int64 v19; // rbx
unsigned int v20; // eax
__int64 v21; // rdx
__int64 v22; // rdx
__int64 v23; // rdx
__int64 v24; // rdx
__int64 v25; // rdx
char *v26; // rdi
__int64 v27; // rdx
unsigned int v28; // [rsp+8h] [rbp-40h] BYREF
unsigned int v29; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v30; // [rsp+10h] [rbp-38h] BYREF
unsigned int v31; // [rsp+14h] [rbp-34h] BYREF
__int64 v32[6]; // [rsp+18h] [rbp-30h] BYREF

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

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
unsigned int v1; // ebp
int v2; // er12
int v3; // ebx
__int64 v4; // rdi
__int16 v5; // ax
__int64 v6; // rsi
int v7; // er12
__int64 v8; // rsi
int v9; // eax
int v10; // ebx
unsigned int v11; // er13
__int64 v12; // rbx
unsigned int v13; // eax
__int64 v14; // rbx
unsigned int v15; // eax
__int64 v16; // rbx
unsigned int v17; // eax
int v18; // eax
__int64 v19; // rbx
unsigned int v20; // eax
__int64 v21; // rdx
__int64 v22; // rdx
__int64 v23; // rdx
__int64 v24; // rdx
__int64 v25; // rdx
char *v26; // rdi
__int64 v27; // rdx
unsigned int v28; // [rsp+8h] [rbp-40h] BYREF
unsigned int v29; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v30; // [rsp+10h] [rbp-38h] BYREF
unsigned int v31; // [rsp+14h] [rbp-34h] BYREF
__int64 v32[6]; // [rsp+18h] [rbp-30h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(65LL, 0xFFFFFFFFLL, &v30, &v29) )
return msg_print("You are not carrying any wands.");
result = get_item(&v31, "Aim which wand?", v30, v29, 0LL, 0LL);
if ( (_DWORD)result )
{
v1 = v31;
free_turn_flag = 0;
result = get_dir(0LL, &v28);
if ( (_DWORD)result )
{
if ( *((__int16 *)&py + 203) > 0 )
{
msg_print("You are confused.");
do
v28 = randint(9LL);
while ( v28 == 5 );
}
v2 = *((__int16 *)&py + 49);
v3 = *((unsigned __int16 *)&py + 32) * class_level_adj[5 * *((unsigned __int8 *)&py + 104) + 2] / 3
+ stat_adj(1LL)
+ v2
- *((unsigned __int8 *)&inventory + 56 * (int)v1 + 54);
if ( *((__int16 *)&py + 203) > 0 )
v3 /= 2;
if ( v3 > 2 || (v4 = 3LL, (unsigned int)randint((unsigned int)(4 - v3)) != 1) )
{
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 = *((_WORD *)&inventory + 28 * (int)v1 + 13);
if ( v5 <= 0 )
{
msg_print("The wand has no charges left.");
result = known2_p((char *)&inventory + 56 * (int)v1);
if ( !(_DWORD)result )
result = add_inscribe((char *)&inventory + 56 * (int)v1, 4LL);
}
else
{
v32[0] = *((_QWORD *)&inventory + 7 * (int)v1 + 2);
v6 = v32[0];
*((_WORD *)&inventory + 28 * (int)v1 + 13) = v5 - 1;
if ( !v6 )
goto LABEL_61;
v7 = 0;
do
{
v9 = bit_pos(v32);
v10 = v9 + 1;
v30 = v9 + 1;
v8 = (unsigned int)char_row;
v29 = char_row;
v11 = char_col;
switch ( v9 )
{
case 0:
msg_print("A line of blue shimmering light appears.");
v8 = (unsigned int)char_row;
light_line(v28, v8, (unsigned int)char_col);
v7 = v10;
break;
case 1:
v12 = spell_names[8];
v13 = damroll(4LL, 8LL);
v8 = v28;
fire_bolt(1LL, v28, v29, v11, v13, v12);
v7 = 1;
break;
case 2:
v14 = spell_names[14];
v15 = damroll(6LL, 8LL);
v8 = v28;
fire_bolt(4LL, v28, v29, v11, v15, v14);
v7 = 1;
break;
case 3:
v16 = spell_names[22];
v17 = damroll(9LL, 8LL);
v8 = v28;
fire_bolt(5LL, v28, v29, v11, v17, v16);
v7 = 1;
break;
case 4:
v7 = wall_to_mud(v28, v8, (unsigned int)char_col);
break;
case 5:
v7 = poly_monster(v28, v8, (unsigned int)char_col);
break;
case 6:
v18 = damroll(4LL, 6LL);
v8 = v29;
v7 = hp_monster(v28, v29, v11, (unsigned int)-v18);
break;
case 7:
v7 = speed_monster(v28, v8, (unsigned int)char_col, 1LL);
break;
case 8:
v7 = speed_monster(v28, v8, (unsigned int)char_col, 0xFFFFFFFFLL);
break;
case 9:
v7 = confuse_monster(v28, v8, (unsigned int)char_col);
break;
case 10:
v7 = sleep_monster(v28, v8, (unsigned int)char_col);
break;
case 11:
v7 = drain_life(v28, v8, (unsigned int)char_col);
break;
case 12:
v7 = td_destroy2(v28, v8, (unsigned int)char_col);
break;
case 13:
v19 = spell_names[0];
v20 = damroll(2LL, 6LL);
v8 = v28;
fire_bolt(0LL, v28, v29, v11, v20, v19);
v7 = 1;
break;
case 14:
v7 = build_wall(v28, v8, (unsigned int)char_col);
break;
case 15:
v7 = clone_monster(v28, v8, (unsigned int)char_col);
break;
case 16:
v7 = teleport_monster(v28, v8, (unsigned int)char_col);
break;
case 17:
v7 = disarm_all(v28, v8, (unsigned int)char_col);
break;
case 18:
v21 = (unsigned int)v8;
v8 = v28;
fire_ball(1LL, v28, v21, (unsigned int)char_col, 32LL, "Lightning Ball");
v7 = 1;
break;
case 19:
v22 = (unsigned int)v8;
v8 = v28;
fire_ball(4LL, v28, v22, (unsigned int)char_col, 48LL, "Cold Ball");
v7 = 1;
break;
case 20:
v23 = (unsigned int)v8;
v8 = v28;
fire_ball(5LL, v28, v23, (unsigned int)char_col, 72LL, spell_names[28]);
v7 = 1;
break;
case 21:
v24 = (unsigned int)v8;
v8 = v28;
fire_ball(2LL, v28, v24, (unsigned int)char_col, 12LL, spell_names[6]);
v7 = 1;
break;
case 22:
v25 = (unsigned int)v8;
v8 = v28;
fire_ball(3LL, v28, v25, (unsigned int)char_col, 60LL, "Acid Ball");
v7 = 1;
break;
case 23:
v32[0] = 1LL << ((unsigned __int8)randint(23LL) - 1);
break;
default:
msg_print("Internal error in wands()");
break;
}
}
while ( v32[0] );
if ( v7 )
{
v26 = (char *)&inventory + 56 * (int)v1;
if ( !(unsigned int)known1_p(v26) )
{
v27 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + *((unsigned __int8 *)&inventory + 56 * (int)v1 + 54)) >> 31);
LODWORD(v27) = ((*((_WORD *)&py + 32) >> 1) + *((unsigned __int8 *)&inventory + 56 * (int)v1 + 54))
% *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + *((unsigned __int8 *)&inventory + 56 * (int)v1 + 54))
/ *((unsigned __int16 *)&py + 32);
prt_experience(v26, v8, v27);
identify(&v31);
}
}
else
{
LABEL_61:
if ( !(unsigned int)known1_p((char *)&inventory + 56 * (int)v1) )
sample((char *)&inventory + 56 * (int)v1);
}
result = desc_charges(v31);
}
}
}
}
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 int v1; // ebp
int v2; // er12
int v3; // ebx
__int64 v4; // rdi
__int16 v5; // ax
__int64 v6; // rsi
int v7; // ebx
int v8; // eax
unsigned int v9; // eax
char *v10; // rdi
__int64 v11; // rdx
int v12; // [rsp+4h] [rbp-34h] BYREF
int v13; // [rsp+8h] [rbp-30h] BYREF
unsigned int v14; // [rsp+Ch] [rbp-2Ch] BYREF
int v15; // [rsp+10h] [rbp-28h] BYREF
unsigned int v16; // [rsp+14h] [rbp-24h] BYREF
__int64 v17[4]; // [rsp+18h] [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, &v16, &v15) )
return msg_print("You are not carrying any staffs.");
result = get_item(&v14, "Use which staff?", v16, (unsigned int)v15, 0LL, 0LL);
if ( (_DWORD)result )
{
v1 = v14;
free_turn_flag = 0;
v2 = *((__int16 *)&py + 49);
v3 = v2
- *((unsigned __int8 *)&inventory + 56 * (int)v1 + 54)
+ stat_adj(1LL)
- 5
+ *((unsigned __int16 *)&py + 32) * class_level_adj[5 * *((unsigned __int8 *)&py + 104) + 2] / 3;
if ( *((__int16 *)&py + 203) > 0 )
v3 /= 2;
if ( v3 > 2 || (v4 = 3LL, (unsigned int)randint((unsigned int)(4 - v3)) != 1) )
{
v4 = 1LL;
if ( v3 > 0 )
v4 = (unsigned int)v3;
}
if ( (int)randint(v4) <= 2 )
{
result = msg_print("You failed to use the staff properly.");
}
else
{
v5 = *((_WORD *)&inventory + 28 * (int)v1 + 13);
if ( v5 <= 0 )
{
msg_print("The staff has no charges left.");
result = known2_p((char *)&inventory + 56 * (int)v1);
if ( !(_DWORD)result )
result = add_inscribe((char *)&inventory + 56 * (int)v1, 4LL);
}
else
{
v6 = *((_QWORD *)&inventory + 7 * (int)v1 + 2);
v17[0] = v6;
*((_WORD *)&inventory + 28 * (int)v1 + 13) = v5 - 1;
v7 = 0;
LABEL_28:
while ( v17[0] )
{
v8 = bit_pos(v17);
v16 = v8 + 1;
switch ( v8 )
{
case 0:
v6 = (unsigned int)char_col;
v7 = light_area((unsigned int)char_row, v6);
break;
case 1:
v7 = detect_sdoor();
break;
case 2:
v7 = detect_trap();
break;
case 3:
v7 = detect_treasure();
break;
case 4:
v7 = detect_object();
break;
case 5:
teleport(100LL);
v7 = 1;
break;
case 6:
earthquake();
v7 = 1;
break;
case 7:
v15 = 0;
v7 = 0;
while ( (int)randint(4LL) > v15 )
{
v13 = char_row;
v12 = char_col;
v6 = (__int64)&v12;
v7 |= summon_monster(&v13, &v12, 0LL);
++v15;
}
break;
case 9:
v6 = (unsigned int)char_col;
destroy_area((unsigned int)char_row, v6);
v7 = 1;
break;
case 10:
v6 = (unsigned int)char_col;
starlite((unsigned int)char_row, v6);
v7 = 1;
break;
case 11:
v7 = speed_monsters(1LL);
break;
case 12:
v7 = speed_monsters(0xFFFFFFFFLL);
break;
case 13:
v7 = sleep_monsters2();
break;
case 14:
v9 = randint(8LL);
v7 = hp_player(v9);
break;
case 15:
v7 = detect_invisible();
break;
case 16:
if ( !*((_WORD *)&py + 208) )
v7 = 1;
*((_WORD *)&py + 208) += randint(30LL) + 15;
break;
case 17:
if ( !*((_WORD *)&py + 209) )
v7 = 1;
*((_WORD *)&py + 209) += randint(30LL) + 15;
break;
case 18:
v7 = mass_poly();
break;
case 19:
if ( (unsigned int)remove_curse() )
{
v7 = 1;
if ( *((__int16 *)&py + 201) <= 0 )
msg_print("The staff glows blue for a moment..");
}
break;
case 20:
v7 = detect_evil();
break;
case 21:
if ( (unsigned int)cure_blindness() )
{
v7 = 1;
}
else if ( (unsigned int)cure_poison() )
{
v7 = 1;
}
else if ( (unsigned int)cure_confusion() )
{
v7 = 1;
}
break;
case 22:
v6 = 60LL;
v7 = dispel_creature(4LL, 60LL);
break;
case 24:
v6 = (unsigned int)char_col;
v7 = unlight_area((unsigned int)char_row, v6);
break;
case 31:
goto LABEL_28;
default:
msg_print("Internal error in staffs()");
break;
}
}
if ( v7 )
{
v10 = (char *)&inventory + 56 * (int)v1;
if ( !(unsigned int)known1_p(v10) )
{
v11 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + *((unsigned __int8 *)&inventory + 56 * (int)v1 + 54)) >> 31);
LODWORD(v11) = ((*((_WORD *)&py + 32) >> 1) + *((unsigned __int8 *)&inventory + 56 * (int)v1 + 54))
% *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + *((unsigned __int8 *)&inventory + 56 * (int)v1 + 54))
/ *((unsigned __int16 *)&py + 32);
prt_experience(v10, v6, v11);
identify(&v14);
}
}
else if ( !(unsigned int)known1_p((char *)&inventory + 56 * (int)v1) )
{
sample((char *)&inventory + 56 * (int)v1);
}
result = desc_charges(v14);
}
}
}
return result;
}

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

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

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

v1 = socket(2, 1, 0);
if ( v1 >= 0 )
{
v2 = v1;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = inet_addr(cp);
*(_WORD *)addr.sa_data = func3(port);
if ( bind(v2, &addr, 0x10u) >= 0 )
{
listen(v2, 5);
while ( 1 )
{
v3 = 16;
arg = accept(v2, &v6, &v3);
if ( pthread_create(&newthread, 0LL, receive_client, &arg) )
syslog(4, "Error binding receiving socket");
else
syslog(6, "Receiving process...");
}
}
syslog(3, "Error binding receiving socket");
pthread_exit(0LL);
}
syslog(3, "Error creating receiving socket");
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
char bufa[25]; // [rsp+Fh] [rbp-19h] BYREF

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

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

v2 = strlen((const char *)buf);
write(*a2, buf, v2);
bufa[0] = 10;
return write(*a2, 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

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

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

result = 0LL;
if ( a2 )
result = strcmp(a1, a2) == 0;
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 func7(__int64 a1, const char *a2, int *a3)
{
int result; // eax

result = func6((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
int v2; // ebx
socklen_t v3; // [rsp+0h] [rbp-B8h] BYREF
int arg; // [rsp+4h] [rbp-B4h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-B0h] BYREF
struct sockaddr v6; // [rsp+10h] [rbp-A8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-98h] BYREF
char s[40]; // [rsp+90h] [rbp-28h] BYREF

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

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

sprintf(s, "rm -f %s", "/etc/procs/procs.sock");
system(s);
v1 = socket(1, 1, 0);
if ( v1 >= 0 )
{
v2 = v1;
addr.sa_family = 1;
strcpy(addr.sa_data, "/etc/procs/procs.sock");
if ( bind(v1, &addr, 0x6Eu) >= 0 )
{
listen(v2, 5);
while ( 1 )
{
v3 = 16;
arg = accept(v2, &v6, &v3);
if ( pthread_create(&newthread, 0LL, admin, &arg) )
syslog(4, "Error creating admin");
else
syslog(6, "Receiving admin");
}
}
syslog(3, "Error binding admins socket");
pthread_exit(0LL);
}
syslog(3, "Error creating admin socket");
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 func9(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; // rbp
__int64 v2; // rdx
char *v3; // rbx
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((__int64)&procs_id, (__int64)v3);
next_process = v1;
sem_post(&next);
sem_post(&mutex);
return v3;
}

canonical_decompiled_code:
char *__fastcall func10(int a1)
{
__int64 v1; // rbp
__int64 v2; // rdx
char *v3; // rbx
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((__int64)&procs_id, (__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 func11(void *a1)
{
func10(*(_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
unsigned int v4; // eax
const char *v5; // rbp
char *v6; // rax
__pid_t v7; // eax
__pid_t v8; // eax
pthread_t v9; // [rsp+8h] [rbp-30h] BYREF
pthread_t newthread; // [rsp+10h] [rbp-28h] BYREF
int longind[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

list_init((__int64)&procs_id);
program_name = (__int64)*argv;
longind[0] = 0;
v3 = 1;
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "vhf", &long_options_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
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", v4);
break;
}
}
openlog("procs_log", 2, 8);
if ( v3 )
{
v7 = fork();
if ( v7 < 0 )
exit(1);
if ( v7 > 0 )
exit(0);
signal(1, (__sighandler_t)signal_handler);
signal(15, (__sighandler_t)signal_handler);
signal(2, (__sighandler_t)signal_handler);
signal(3, (__sighandler_t)signal_handler);
v8 = fork();
if ( v8 < 0 )
exit(1);
if ( v8 > 0 )
exit(0);
umask(0);
if ( setsid() < 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);
}
cp = "127.0.0.1";
port = 12092;
if ( optind < argc )
{
v5 = argv[optind];
v6 = strchr(v5, 58);
if ( v6 )
{
*v6 = 0;
cp = (char *)argv[optind];
port = v6[1];
}
else
{
cp = (char *)v5;
}
}
sem_init(&mutex, 0, 1u);
sem_init(&next, 0, 1u);
pthread_create(&newthread, 0LL, (void *(*)(void *))wait_for_admin, 0LL);
pthread_create(&v9, 0LL, (void *(*)(void *))wait_for_receive, 0LL);
while ( 1 )
sleep(0x2710u);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // eax
const char *v5; // rbp
char *v6; // rax
__pid_t v7; // eax
__pid_t v8; // eax
pthread_t v9; // [rsp+8h] [rbp-30h] BYREF
pthread_t newthread; // [rsp+10h] [rbp-28h] BYREF
int longind[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

func0((__int64)&procs_id);
program_name = (__int64)*argv;
longind[0] = 0;
v3 = 1;
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "vhf", &long_options_0, longind);
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'h':
func13();
exit(0);
case 'v':
verbose = 1;
break;
case 'f':
v3 = 0;
break;
default:
fprintf(stderr, "?? getopt returned character code 0%o ??\n", v4);
break;
}
}
openlog("procs_log", 2, 8);
if ( v3 )
{
v7 = fork();
if ( v7 < 0 )
exit(1);
if ( v7 > 0 )
exit(0);
signal(1, (__sighandler_t)signal_handler);
signal(15, (__sighandler_t)signal_handler);
signal(2, (__sighandler_t)signal_handler);
signal(3, (__sighandler_t)signal_handler);
v8 = fork();
if ( v8 < 0 )
exit(1);
if ( v8 > 0 )
exit(0);
umask(0);
if ( setsid() < 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);
}
cp = "127.0.0.1";
port = 12092;
if ( optind < argc )
{
v5 = argv[optind];
v6 = strchr(v5, 58);
if ( v6 )
{
*v6 = 0;
cp = (char *)argv[optind];
port = v6[1];
}
else
{
cp = (char *)v5;
}
}
sem_init(&mutex, 0, 1u);
sem_init(&next, 0, 1u);
pthread_create(&newthread, 0LL, (void *(*)(void *))wait_for_admin, 0LL);
pthread_create(&v9, 0LL, (void *(*)(void *))wait_for_receive, 0LL);
while ( 1 )
sleep(0x2710u);
}

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(__int64 *a1)
{
__int64 v1; // rsi
__int64 v2; // rdi
_QWORD *v3; // rax
__int64 v4; // rax
__int64 result; // rax

if ( *((_DWORD *)a1 + 1) )
{
v1 = *a1;
v2 = a1[1];
v3 = data_addr;
*(_QWORD *)data_addr = v1;
v3[1] = v2;
v4 = code_addr;
*(_BYTE *)code_addr = -72;
*(_QWORD *)(v4 + 1) = 205LL;
*(_BYTE *)(v4 + 5) = -69;
*(_QWORD *)(v4 + 6) = data_addr;
*(_BYTE *)(v4 + 10) = -51;
*(_BYTE *)(v4 + 11) = 0x80;
result = v4 + 12;
code_addr = result;
data_addr = (char *)data_addr + 16;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1)
{
__int64 v1; // rsi
__int64 v2; // rdi
_QWORD *v3; // rax
__int64 v4; // rax
__int64 result; // rax

if ( *((_DWORD *)a1 + 1) )
{
v1 = *a1;
v2 = a1[1];
v3 = data_addr;
*(_QWORD *)data_addr = v1;
v3[1] = v2;
v4 = code_addr;
*(_BYTE *)code_addr = -72;
*(_QWORD *)(v4 + 1) = 205LL;
*(_BYTE *)(v4 + 5) = -69;
*(_QWORD *)(v4 + 6) = data_addr;
*(_BYTE *)(v4 + 10) = -51;
*(_BYTE *)(v4 + 11) = 0x80;
result = v4 + 12;
code_addr = result;
data_addr = (char *)data_addr + 16;
}
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:
void __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)
{
int v15; // eax
void *v16; // rax

if ( a12 )
{
memcpy(data_addr, src, n);
v16 = sbrk(n);
as_memcpy((__int64)data_addr, (__int64)v16, n);
data_addr = (char *)data_addr + n;
}
else if ( a11 )
{
memcpy(data_addr, src, n);
as_mmap_memcpy(a7, n, 7, HIDWORD(a9) | 0x20, 0, 0, (__int64)data_addr);
data_addr = (char *)data_addr + n;
}
else if ( *file )
{
v15 = open(file, 0);
as_mmap_memcpy(a7, n, 7, HIDWORD(a9) | 0x20, v15, a13, 0LL);
}
}

canonical_decompiled_code:
void __fastcall func5(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)
{
int v15; // eax
void *v16; // rax

if ( a12 )
{
memcpy(data_addr, src, n);
v16 = sbrk(n);
func1((__int64)data_addr, (__int64)v16, n);
data_addr = (char *)data_addr + n;
}
else if ( a11 )
{
memcpy(data_addr, src, n);
func2(a7, n, 7, HIDWORD(a9) | 0x20, 0, 0, (__int64)data_addr);
data_addr = (char *)data_addr + n;
}
else if ( *file )
{
v15 = open(file, 0);
func2(a7, n, 7, HIDWORD(a9) | 0x20, v15, a13, 0LL);
}
}

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; // eax
int v15; // ebx
int v16; // ebx
int v18; // eax
int v19; // ebx
char v20[72]; // [rsp+0h] [rbp-48h] BYREF

strcpy(v20, "/tmp/procs_XXXXXX");
if ( a10 != 1 )
{
v18 = open(file, SHIDWORD(fd2));
v19 = v18;
if ( v18 <= 0 )
return printf("Could not open %s\n", file);
dup2(v18, fd2);
if ( v19 != (_DWORD)fd2 )
close(v19);
return lseek(fd2, offset, 0);
}
if ( !buf || !restore_file )
{
v14 = open(file, SHIDWORD(fd2));
v15 = v14;
if ( v14 > 0 )
{
dup2(v14, fd2);
if ( v15 != (_DWORD)fd2 )
close(v15);
return lseek(fd2, offset, 0);
}
}
v16 = mkstemp(v20);
fprintf(stderr, "Restoring file %s as %s\n", file, v20);
write(v16, buf, n);
lseek(v16, offset, 0);
dup2(v16, fd2);
if ( v16 != (_DWORD)fd2 )
close(v16);
return lseek(fd2, offset, 0);
}

canonical_decompiled_code:
int __fastcall func7(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; // eax
int v15; // ebx
int v16; // ebx
int v18; // eax
int v19; // ebx
char v20[72]; // [rsp+0h] [rbp-48h] BYREF

strcpy(v20, "/tmp/procs_XXXXXX");
if ( a10 != 1 )
{
v18 = open(file, SHIDWORD(fd2));
v19 = v18;
if ( v18 <= 0 )
return printf("Could not open %s\n", file);
dup2(v18, fd2);
if ( v19 != (_DWORD)fd2 )
close(v19);
return lseek(fd2, offset, 0);
}
if ( !buf || !restore_file )
{
v14 = open(file, SHIDWORD(fd2));
v15 = v14;
if ( v14 > 0 )
{
dup2(v14, fd2);
if ( v15 != (_DWORD)fd2 )
close(v15);
return lseek(fd2, offset, 0);
}
}
v16 = mkstemp(v20);
fprintf(stderr, "Restoring file %s as %s\n", file, v20);
write(v16, buf, n);
lseek(v16, offset, 0);
dup2(v16, fd2);
if ( v16 != (_DWORD)fd2 )
close(v16);
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; // rdx
char *v3; // rsi
unsigned __int64 result; // rax

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

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

if ( a2 <= 0 )
return 0LL;
v2 = a1;
v3 = &a1[a2];
result = 0LL;
do
result = *v2++ ^ (33 * result);
while ( v2 != v3 );
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


decompiled_code:
void __fastcall free_process(void *ptr, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
int v6; // edx
int v7; // ecx
int v8; // er8
int v9; // er9

list_iterate((__int64 (__fastcall *)(_QWORD))free_chunk, a2, a3, a4, a5, a6, **((_QWORD ***)ptr + 1));
list_free((int)free_chunk, a2, v6, v7, v8, v9, **((void ***)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
int v6; // edx
int v7; // ecx
int v8; // er8
int v9; // er9

func1((__int64 (__fastcall *)(_QWORD))free_chunk, a2, a3, a4, a5, a6, **((_QWORD ***)ptr + 1));
func4((int)free_chunk, a2, v6, v7, v8, v9, **((void ***)ptr + 1));
free(ptr);
}

original_code:
void
free_process(struct proc_process* p) {
 list_iterate(*p->chunks,free_chunk);
 list_free(*p->chunks);
 free(p);
}

canonical_original_code:
void free_process(struct proc_process *p) {
 list_iterate(*p->chunks,free_chunk);
 list_free(*p->chunks);
 free(p);
}

variable_types: struct proc_process { char *name; struct list { struct item { void *p; struct item *next; } *head; int len; } *chunks; } *


decompiled_code:
unsigned __int64 __fastcall get_long(const char **a1, char a2, int a3)
{
const char *v4; // r12
char *v5; // rax
unsigned __int64 v6; // rdx

v4 = *a1;
v5 = strchr(*a1, a2);
v6 = 0LL;
if ( v5 )
{
*v5 = 0;
*a1 = v5;
v6 = strtoul(v4, 0LL, a3);
}
return v6;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(const char **a1, char a2, int a3)
{
const char *v4; // r12
char *v5; // rax
unsigned __int64 v6; // rdx

v4 = *a1;
v5 = strchr(*a1, a2);
v6 = 0LL;
if ( v5 )
{
*v5 = 0;
*a1 = v5;
v6 = strtoul(v4, 0LL, a3);
}
return v6;
}

original_code:
unsigned long
get_long(char** start, char search, unsigned int base) {
 char *ptr1,*ptr2;
 ptr1 = *start;
 if ((ptr2 = strchr(ptr1, search)) == ((void *)0))
  return 0;
 *ptr2 = '\0';
 *start = ptr2;
 return strtoul(ptr1, ((void *)0), base);
}

canonical_original_code:
unsigned long get_long(char **start, char search, unsigned int base) {
 char *ptr1; char *ptr2;
 ptr1 = *start;
 if ((ptr2 = strchr(ptr1, search)) == ((void *)0))
  return 0;
 *ptr2 = '\0';
 *start = ptr2;
 return strtoul(ptr1, ((void *)0), base);
}

variable_types:
start
char **

variable_types: search char

variable_types:
base
unsigned int


decompiled_code:
size_t __fastcall read_from_file_pointer(FILE *stream, void *ptr, size_t size)
{
size_t result; // rax

result = fread(ptr, size, 1uLL, stream);
if ( !result )
result = -1LL;
return result;
}

canonical_decompiled_code:
size_t __fastcall func10(FILE *stream, void *ptr, size_t size)
{
size_t result; // rax

result = fread(ptr, size, 1uLL, stream);
if ( !result )
result = -1LL;
return result;
}

original_code:
long
read_from_file_pointer(void* fp, void* mem, size_t s) {
 long i = fread(mem,s,1,(FILE*)fp);
 if (i==0) return -1;
 return i;
}

canonical_original_code:
long read_from_file_pointer(void *fp, void *mem, unsigned long s) {
 long i = fread(mem,s,1,(FILE*)fp);
 if (i==0) return -1;
 return i;
}

variable_types:
fp
void *

variable_types:
mem
void *

variable_types:
s
unsigned long

return_type: long