pray

decompiled_code:
__int64 pray()
{
bool v0; // cc
__int64 result; // rax
const char *v2; // rdi
int v3; // ebx
__int64 v4; // rbp
int v5; // ebx
__int64 v6; // rsi
__int64 v7; // rdi
unsigned int v8; // eax
int v9; // eax
__int64 v10; // rbx
int v11; // esi
__int16 v12; // ax
int v13; // eax
int v14; // eax
int v15; // eax
int v16; // eax
int v17; // eax
__int64 i; // rax
unsigned int v19; // [rsp+0h] [rbp-30h] BYREF
unsigned int v20; // [rsp+4h] [rbp-2Ch] BYREF
unsigned int v21; // [rsp+8h] [rbp-28h] BYREF
unsigned int v22; // [rsp+Ch] [rbp-24h] BYREF
int v23; // [rsp+10h] [rbp-20h] BYREF
int v24[7]; // [rsp+14h] [rbp-1Ch] BYREF

v0 = *((_WORD *)&py + 201) <= 0;
free_turn_flag = 1;
if ( !v0 )
return msg_print("You can't see to read your prayer!");
v2 = "You have no light to read by.";
if ( (unsigned int)no_light() )
return msg_print(v2);
v2 = "You are too confused.";
if ( *((__int16 *)&py + 203) > 0 )
return msg_print(v2);
v2 = "Pray hard enough and your prayers may be answered.";
if ( class[32 * *((unsigned __int8 *)&py + 104) + 28] != 2 )
return msg_print(v2);
if ( !inven_ctr )
{
v2 = "But you are not carrying anything!";
return msg_print(v2);
}
if ( !(unsigned int)find_range(91LL, 0xFFFFFFFFLL, &v19, &v20) )
return msg_print("You are not carrying any Holy Books!");
result = get_item(&v21, "Use which Holy Book?", v19, v20, 0LL, 0LL);
if ( (_DWORD)result )
{
result = cast_spell("Recite which prayer?", v21, &v23, v24);
if ( (int)result < 0 )
return msg_print("You don't know any prayers in that book.");
if ( (_DWORD)result )
{
v3 = *((unsigned __int8 *)&py + 104);
free_turn_flag = 0;
v4 = v23;
v5 = v3 - 1;
if ( (int)randint(100LL) < v24[0] )
{
result = msg_print("You lost your concentration!");
goto LABEL_26;
}
switch ( v23 )
{
case 0:
detect_evil();
break;
case 1:
v6 = 3LL;
v7 = 3LL;
goto LABEL_19;
case 2:
v13 = randint(12LL);
bless((unsigned int)(v13 + 12));
break;
case 3:
remove_fear();
break;
case 4:
light_area((unsigned int)char_row, (unsigned int)char_col);
break;
case 5:
detect_trap();
break;
case 6:
detect_sdoor();
break;
case 7:
slow_poison();
break;
case 8:
if ( (unsigned int)get_dir(0LL, &v22) )
confuse_monster(v22, (unsigned int)char_row, (unsigned int)char_col);
break;
case 9:
teleport(3 * (unsigned int)*((unsigned __int16 *)&py + 32));
break;
case 10:
v6 = 4LL;
v7 = 4LL;
goto LABEL_19;
case 11:
v14 = randint(24LL);
bless((unsigned int)(v14 + 24));
break;
case 12:
sleep_monsters1((unsigned int)char_row, (unsigned int)char_col);
break;
case 13:
create_food();
break;
case 14:
for ( i = 0LL; i != 1904; i += 56LL )
{
if ( (unsigned __int8)(inventory[i + 24] - 10) <= 0x28u )
*(_QWORD *)&inventory[i + 16] &= 0xFFFFFFFF7FFFFFFFLL;
}
v19 = 34;
break;
case 15:
*((_WORD *)&py + 218) += randint(10LL) + 10;
*((_WORD *)&py + 219) += randint(10LL) + 10;
break;
case 16:
cure_poison();
break;
case 17:
if ( (unsigned int)get_dir(0LL, &v22) )
{
v17 = damroll(3LL, 6LL);
fire_ball(
6LL,
v22,
(unsigned int)char_row,
(unsigned int)char_col,
(unsigned int)*((unsigned __int16 *)&py + 32) + v17,
"Black Sphere");
}
break;
case 18:
v6 = 4LL;
v7 = 8LL;
goto LABEL_19;
case 19:
v16 = randint(24LL);
detect_inv2((unsigned int)(v16 + 24));
break;
case 20:
protect_evil();
break;
case 21:
earthquake();
break;
case 22:
map_area();
break;
case 23:
v6 = 4LL;
v7 = 16LL;
LABEL_19:
v8 = damroll(v7, v6);
hp_player(v8);
break;
case 24:
turn_undead();
break;
case 25:
v15 = randint(48LL);
bless((unsigned int)(v15 + 48));
break;
case 26:
dispel_creature(8LL, 3 * (unsigned int)*((unsigned __int16 *)&py + 32));
break;
case 27:
hp_player(200LL);
break;
case 28:
dispel_creature(4LL, 3 * (unsigned int)*((unsigned __int16 *)&py + 32));
break;
case 29:
warding_glyph();
break;
case 30:
dispel_creature(4LL, 4 * (unsigned int)*((unsigned __int16 *)&py + 32));
remove_fear();
cure_poison();
hp_player(1000LL);
break;
default:
break;
}
result = free_turn_flag;
if ( !free_turn_flag )
{
if ( (spell_worked & (1LL << v23)) != 0 )
{
LABEL_22:
v9 = *((__int16 *)&py + 54);
v10 = v4 + 31LL * v5;
v11 = *((unsigned __int8 *)&magic_spell + 4 * v10 + 1);
if ( v11 > v9 )
{
msg_print("You faint from fatigue!");
v12 = randint(5 * ((unsigned int)*((unsigned __int8 *)&magic_spell + 4 * v10 + 1) - *((__int16 *)&py + 54)));
*((_DWORD *)&py + 27) = 0;
*((_WORD *)&py + 202) = v12;
if ( (unsigned int)randint(3LL) == 1 )
{
msg_print("You have damaged your health!");
dec_stat(4LL);
}
}
else
{
*((_WORD *)&py + 54) = v9 - v11;
}
return prt_cmana();
}
*((_QWORD *)&py + 6) += 4 * *((unsigned __int8 *)&magic_spell + 124 * v5 + 4 * (int)v4 + 3);
result = prt_experience();
spell_worked |= 1LL << v23;
LABEL_26:
if ( free_turn_flag )
return result;
goto LABEL_22;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
bool v0; // cc
__int64 result; // rax
const char *v2; // rdi
int v3; // ebx
__int64 v4; // rbp
int v5; // ebx
__int64 v6; // rsi
__int64 v7; // rdi
unsigned int v8; // eax
int v9; // eax
__int64 v10; // rbx
int v11; // esi
__int16 v12; // ax
int v13; // eax
int v14; // eax
int v15; // eax
int v16; // eax
int v17; // eax
__int64 i; // rax
unsigned int v19; // [rsp+0h] [rbp-30h] BYREF
unsigned int v20; // [rsp+4h] [rbp-2Ch] BYREF
unsigned int v21; // [rsp+8h] [rbp-28h] BYREF
unsigned int v22; // [rsp+Ch] [rbp-24h] BYREF
int v23; // [rsp+10h] [rbp-20h] BYREF
int v24[7]; // [rsp+14h] [rbp-1Ch] BYREF

v0 = *((_WORD *)&py + 201) <= 0;
free_turn_flag = 1;
if ( !v0 )
return msg_print("You can't see to read your prayer!");
v2 = "You have no light to read by.";
if ( (unsigned int)no_light() )
return msg_print(v2);
v2 = "You are too confused.";
if ( *((__int16 *)&py + 203) > 0 )
return msg_print(v2);
v2 = "Pray hard enough and your prayers may be answered.";
if ( class[32 * *((unsigned __int8 *)&py + 104) + 28] != 2 )
return msg_print(v2);
if ( !inven_ctr )
{
v2 = "But you are not carrying anything!";
return msg_print(v2);
}
if ( !(unsigned int)find_range(91LL, 0xFFFFFFFFLL, &v19, &v20) )
return msg_print("You are not carrying any Holy Books!");
result = get_item(&v21, "Use which Holy Book?", v19, v20, 0LL, 0LL);
if ( (_DWORD)result )
{
result = cast_spell("Recite which prayer?", v21, &v23, v24);
if ( (int)result < 0 )
return msg_print("You don't know any prayers in that book.");
if ( (_DWORD)result )
{
v3 = *((unsigned __int8 *)&py + 104);
free_turn_flag = 0;
v4 = v23;
v5 = v3 - 1;
if ( (int)randint(100LL) < v24[0] )
{
result = msg_print("You lost your concentration!");
goto LABEL_26;
}
switch ( v23 )
{
case 0:
detect_evil();
break;
case 1:
v6 = 3LL;
v7 = 3LL;
goto LABEL_19;
case 2:
v13 = randint(12LL);
bless((unsigned int)(v13 + 12));
break;
case 3:
remove_fear();
break;
case 4:
light_area((unsigned int)char_row, (unsigned int)char_col);
break;
case 5:
detect_trap();
break;
case 6:
detect_sdoor();
break;
case 7:
slow_poison();
break;
case 8:
if ( (unsigned int)get_dir(0LL, &v22) )
confuse_monster(v22, (unsigned int)char_row, (unsigned int)char_col);
break;
case 9:
teleport(3 * (unsigned int)*((unsigned __int16 *)&py + 32));
break;
case 10:
v6 = 4LL;
v7 = 4LL;
goto LABEL_19;
case 11:
v14 = randint(24LL);
bless((unsigned int)(v14 + 24));
break;
case 12:
sleep_monsters1((unsigned int)char_row, (unsigned int)char_col);
break;
case 13:
create_food();
break;
case 14:
for ( i = 0LL; i != 1904; i += 56LL )
{
if ( (unsigned __int8)(inventory[i + 24] - 10) <= 0x28u )
*(_QWORD *)&inventory[i + 16] &= 0xFFFFFFFF7FFFFFFFLL;
}
v19 = 34;
break;
case 15:
*((_WORD *)&py + 218) += randint(10LL) + 10;
*((_WORD *)&py + 219) += randint(10LL) + 10;
break;
case 16:
cure_poison();
break;
case 17:
if ( (unsigned int)get_dir(0LL, &v22) )
{
v17 = damroll(3LL, 6LL);
fire_ball(
6LL,
v22,
(unsigned int)char_row,
(unsigned int)char_col,
(unsigned int)*((unsigned __int16 *)&py + 32) + v17,
"Black Sphere");
}
break;
case 18:
v6 = 4LL;
v7 = 8LL;
goto LABEL_19;
case 19:
v16 = randint(24LL);
detect_inv2((unsigned int)(v16 + 24));
break;
case 20:
protect_evil();
break;
case 21:
earthquake();
break;
case 22:
map_area();
break;
case 23:
v6 = 4LL;
v7 = 16LL;
LABEL_19:
v8 = damroll(v7, v6);
hp_player(v8);
break;
case 24:
turn_undead();
break;
case 25:
v15 = randint(48LL);
bless((unsigned int)(v15 + 48));
break;
case 26:
dispel_creature(8LL, 3 * (unsigned int)*((unsigned __int16 *)&py + 32));
break;
case 27:
hp_player(200LL);
break;
case 28:
dispel_creature(4LL, 3 * (unsigned int)*((unsigned __int16 *)&py + 32));
break;
case 29:
warding_glyph();
break;
case 30:
dispel_creature(4LL, 4 * (unsigned int)*((unsigned __int16 *)&py + 32));
remove_fear();
cure_poison();
hp_player(1000LL);
break;
default:
break;
}
result = free_turn_flag;
if ( !free_turn_flag )
{
if ( (spell_worked & (1LL << v23)) != 0 )
{
LABEL_22:
v9 = *((__int16 *)&py + 54);
v10 = v4 + 31LL * v5;
v11 = *((unsigned __int8 *)&magic_spell + 4 * v10 + 1);
if ( v11 > v9 )
{
msg_print("You faint from fatigue!");
v12 = randint(5 * ((unsigned int)*((unsigned __int8 *)&magic_spell + 4 * v10 + 1) - *((__int16 *)&py + 54)));
*((_DWORD *)&py + 27) = 0;
*((_WORD *)&py + 202) = v12;
if ( (unsigned int)randint(3LL) == 1 )
{
msg_print("You have damaged your health!");
dec_stat(4LL);
}
}
else
{
*((_WORD *)&py + 54) = v9 - v11;
}
return prt_cmana();
}
*((_QWORD *)&py + 6) += 4 * *((unsigned __int8 *)&magic_spell + 124 * v5 + 4 * (int)v4 + 3);
result = prt_experience();
spell_worked |= 1LL << v23;
LABEL_26:
if ( free_turn_flag )
return result;
goto LABEL_22;
}
}
}
return result;
}

original_code:
void pray()
{
  int i, j, item_val, dir;
  int choice, chance, result;
  register spell_type *s_ptr;
  register struct misc *m_ptr;
  register struct flags *f_ptr;
  register inven_type *i_ptr;
  free_turn_flag = 1;
  if (py.flags.blind > 0)
    msg_print("You can't see to read your prayer!");
  else if (no_light())
    msg_print("You have no light to read by.");
  else if (py.flags.confused > 0)
    msg_print("You are too confused.");
  else if (class[py.misc.pclass].spell != 2)
    msg_print("Pray hard enough and your prayers may be answered.");
  else if (inven_ctr == 0)
    msg_print ("But you are not carrying anything!");
  else if (!find_range(91, -1, &i, &j))
    msg_print ("You are not carrying any Holy Books!");
  else if (get_item(&item_val, "Use which Holy Book?", i, j, (char *)0, (char *)0))
    {
      result = cast_spell("Recite which prayer?", item_val, &choice, &chance);
      if (result < 0)
 msg_print("You don't know any prayers in that book.");
      else if (result > 0)
 {
   s_ptr = &magic_spell[py.misc.pclass-1][choice];
   free_turn_flag = 0;
   if (randint(100) < chance)
     msg_print("You lost your concentration!");
   else
     {
       switch(choice+1)
  {
  case 1:
    (void) detect_evil();
    break;
  case 2:
    (void) hp_player(damroll(3, 3));
    break;
  case 3:
    bless(randint(12)+12);
    break;
  case 4:
    (void) remove_fear();
    break;
  case 5:
    (void) light_area(char_row, char_col);
    break;
  case 6:
    (void) detect_trap();
    break;
  case 7:
    (void) detect_sdoor();
    break;
  case 8:
    (void) slow_poison();
    break;
  case 9:
    if (get_dir((char *)0, &dir))
      (void) confuse_monster(dir, char_row, char_col);
    break;
  case 10:
    teleport((int)(py.misc.lev*3));
    break;
  case 11:
    (void) hp_player(damroll(4, 4));
    break;
  case 12:
    bless(randint(24)+24);
    break;
  case 13:
    (void) sleep_monsters1(char_row, char_col);
    break;
  case 14:
    create_food();
    break;
  case 15:
    for (i = 0; i < 34; i++)
      {
        i_ptr = &inventory[i];
        if (i_ptr->tval >= 10
     && i_ptr->tval <= 50)
   i_ptr->flags &= ~0x80000000L;
      }
    break;
  case 16:
    f_ptr = &py.flags;
    f_ptr->resist_heat += randint(10) + 10;
    f_ptr->resist_cold += randint(10) + 10;
    break;
  case 17:
    (void) cure_poison();
    break;
  case 18:
    if (get_dir((char *)0, &dir))
      fire_ball(6, dir, char_row, char_col,
         (int)(damroll(3, 6)+py.misc.lev),
         "Black Sphere");
    break;
  case 19:
    (void) hp_player(damroll(8, 4));
    break;
  case 20:
    detect_inv2(randint(24)+24);
    break;
  case 21:
    (void) protect_evil();
    break;
  case 22:
    earthquake();
    break;
  case 23:
    map_area();
    break;
  case 24:
    (void) hp_player(damroll(16, 4));
    break;
  case 25:
    (void) turn_undead();
    break;
  case 26:
    bless(randint(48)+48);
    break;
  case 27:
    (void) dispel_creature(0x0008, (int)(3*py.misc.lev));
    break;
  case 28:
    (void) hp_player(200);
    break;
  case 29:
    (void) dispel_creature(0x0004, (int)(3*py.misc.lev));
    break;
  case 30:
    warding_glyph();
    break;
  case 31:
    (void) dispel_creature(0x0004, (int)(4*py.misc.lev));
    (void) remove_fear();
    (void) cure_poison();
    (void) hp_player(1000);
    break;
  default:
    break;
  }
       if (!free_turn_flag)
  {
    m_ptr = &py.misc;
    if ((spell_worked & (1L << choice)) == 0)
      {
        m_ptr->exp += s_ptr->sexp << 2;
        prt_experience();
        spell_worked |= (1L << choice);
      }
  }
     }
   m_ptr = &py.misc;
   if (!free_turn_flag)
     {
       if (s_ptr->smana > m_ptr->cmana)
  {
    msg_print("You faint from fatigue!");
    py.flags.paralysis =
      randint((int)(5 * (s_ptr->smana-m_ptr->cmana)));
    m_ptr->cmana = 0;
    m_ptr->cmana_frac = 0;
    if (randint(3) == 1)
      {
        msg_print("You have damaged your health!");
        (void) dec_stat (4);
      }
  }
       else
  m_ptr->cmana -= s_ptr->smana;
       prt_cmana();
     }
 }
    }
}

canonical_original_code:
void pray()
{
  int i; int j; int item_val; int dir;
  int choice; int chance; int result;
  register struct spell_type *s_ptr;
  register struct misc *m_ptr;
  register struct flags *f_ptr;
  register struct inven_type *i_ptr;
  free_turn_flag = 1;
  if (py.flags.blind > 0)
    msg_print("You can't see to read your prayer!");
  else if (no_light())
    msg_print("You have no light to read by.");
  else if (py.flags.confused > 0)
    msg_print("You are too confused.");
  else if (class[py.misc.pclass].spell != 2)
    msg_print("Pray hard enough and your prayers may be answered.");
  else if (inven_ctr == 0)
    msg_print ("But you are not carrying anything!");
  else if (!find_range(91, -1, &i, &j))
    msg_print ("You are not carrying any Holy Books!");
  else if (get_item(&item_val, "Use which Holy Book?", i, j, (char *)0, (char *)0))
    {
      result = cast_spell("Recite which prayer?", item_val, &choice, &chance);
      if (result < 0)
 msg_print("You don't know any prayers in that book.");
      else if (result > 0)
 {
   s_ptr = &magic_spell[py.misc.pclass-1][choice];
   free_turn_flag = 0;
   if (randint(100) < chance)
     msg_print("You lost your concentration!");
   else
     {
       switch(choice+1)
  {
  case 1:
    (void) detect_evil();
    break;
  case 2:
    (void) hp_player(damroll(3, 3));
    break;
  case 3:
    bless(randint(12)+12);
    break;
  case 4:
    (void) remove_fear();
    break;
  case 5:
    (void) light_area(char_row, char_col);
    break;
  case 6:
    (void) detect_trap();
    break;
  case 7:
    (void) detect_sdoor();
    break;
  case 8:
    (void) slow_poison();
    break;
  case 9:
    if (get_dir((char *)0, &dir))
      (void) confuse_monster(dir, char_row, char_col);
    break;
  case 10:
    teleport((int)(py.misc.lev*3));
    break;
  case 11:
    (void) hp_player(damroll(4, 4));
    break;
  case 12:
    bless(randint(24)+24);
    break;
  case 13:
    (void) sleep_monsters1(char_row, char_col);
    break;
  case 14:
    create_food();
    break;
  case 15:
    for (i = 0; i < 34; i++)
      {
        i_ptr = &inventory[i];
        if (i_ptr->tval >= 10
     && i_ptr->tval <= 50)
   i_ptr->flags &= ~0x80000000L;
      }
    break;
  case 16:
    f_ptr = &py.flags;
    f_ptr->resist_heat += randint(10) + 10;
    f_ptr->resist_cold += randint(10) + 10;
    break;
  case 17:
    (void) cure_poison();
    break;
  case 18:
    if (get_dir((char *)0, &dir))
      fire_ball(6, dir, char_row, char_col,
         (int)(damroll(3, 6)+py.misc.lev),
         "Black Sphere");
    break;
  case 19:
    (void) hp_player(damroll(8, 4));
    break;
  case 20:
    detect_inv2(randint(24)+24);
    break;
  case 21:
    (void) protect_evil();
    break;
  case 22:
    earthquake();
    break;
  case 23:
    map_area();
    break;
  case 24:
    (void) hp_player(damroll(16, 4));
    break;
  case 25:
    (void) turn_undead();
    break;
  case 26:
    bless(randint(48)+48);
    break;
  case 27:
    (void) dispel_creature(0x0008, (int)(3*py.misc.lev));
    break;
  case 28:
    (void) hp_player(200);
    break;
  case 29:
    (void) dispel_creature(0x0004, (int)(3*py.misc.lev));
    break;
  case 30:
    warding_glyph();
    break;
  case 31:
    (void) dispel_creature(0x0004, (int)(4*py.misc.lev));
    (void) remove_fear();
    (void) cure_poison();
    (void) hp_player(1000);
    break;
  default:
    break;
  }
       if (!free_turn_flag)
  {
    m_ptr = &py.misc;
    if ((spell_worked & (1L << choice)) == 0)
      {
        m_ptr->exp += s_ptr->sexp << 2;
        prt_experience();
        spell_worked |= (1L << choice);
      }
  }
     }
   m_ptr = &py.misc;
   if (!free_turn_flag)
     {
       if (s_ptr->smana > m_ptr->cmana)
  {
    msg_print("You faint from fatigue!");
    py.flags.paralysis =
      randint((int)(5 * (s_ptr->smana-m_ptr->cmana)));
    m_ptr->cmana = 0;
    m_ptr->cmana_frac = 0;
    if (randint(3) == 1)
      {
        msg_print("You have damaged your health!");
        (void) dec_stat (4);
      }
  }
       else
  m_ptr->cmana -= s_ptr->smana;
       prt_cmana();
     }
 }
    }
}

variable_types: dir int

variable_types: choice int

variable_types: chance int

variable_types: struct spell_type { unsigned char slevel; unsigned char smana; unsigned char sfail; unsigned char sexp; } *

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

variable_types: struct flags { unsigned long status; short rest; short blind; short paralysis; short confused; short food; short food_digested; short protection; short speed; short fast; short slow; short afraid; short poisoned; short image; short protevil; short invuln; short hero; short shero; short blessed; short resist_heat; short resist_cold; short detect_inv; short word_recall; short see_infra; short tim_infra; unsigned char see_inv; unsigned char teleport; unsigned char free_act; unsigned char slow_digest; unsigned char aggravate; unsigned char fire_resist; unsigned char cold_resist; unsigned char acid_resist; unsigned char regenerate; unsigned char lght_resist; unsigned char ffall; unsigned char sustain_str; unsigned char sustain_int; unsigned char sustain_wis; unsigned char sustain_con; unsigned char sustain_dex; unsigned char sustain_chr; unsigned char confuse_monster; unsigned char new_spells; } *

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


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

original_code:
void wizard_light()
{
  register cave_type *c_ptr;
  register int k, l, i, j;
  int flag;
  if (cave[char_row][char_col].pl)
    flag = 0;
  else
    flag = 1;
  for (i = 0; i < cur_height; i++)
    for (j = 0; j < cur_width; j++)
      if (cave[i][j].fval <= 4)
 for (k = i-1; k <= i+1; k++)
   for (l = j-1; l <= j+1; l++)
     {
       c_ptr = &cave[k][l];
       c_ptr->pl = flag;
       if (!flag)
  c_ptr->fm = 0;
     }
  prt_map();
}

canonical_original_code:
void wizard_light()
{
  register struct cave_type *c_ptr;
  register int k; register int l; register int i; register int j;
  int flag;
  if (cave[char_row][char_col].pl)
    flag = 0;
  else
    flag = 1;
  for (i = 0; i < cur_height; i++)
    for (j = 0; j < cur_width; j++)
      if (cave[i][j].fval <= 4)
 for (k = i-1; k <= i+1; k++)
   for (l = j-1; l <= j+1; l++)
     {
       c_ptr = &cave[k][l];
       c_ptr->pl = flag;
       if (!flag)
  c_ptr->fm = 0;
     }
  prt_map();
}

variable_types: struct cave_type { unsigned char cptr; unsigned char tptr; unsigned char fval; unsigned int lr; unsigned int fm; unsigned int pl; unsigned int tl; } *

variable_types: k int

variable_types: l int

variable_types: i int

variable_types: j int

variable_types: flag int

return_type: void


decompiled_code:
__int64 change_character()
{
__int64 result; // rax
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
unsigned int v8; // eax
unsigned int v9; // ebx
__int64 v10; // rax
unsigned int v11; // ebx
unsigned int v12; // eax
unsigned int v13; // ebx
int v14; // eax
unsigned int v15; // ebx
unsigned int v16; // eax
unsigned int v17; // ebx
unsigned int v18; // eax
unsigned int v19; // ebx
unsigned int v20; // eax
unsigned int v21; // ebx
unsigned int v22; // eax
unsigned int v23; // ebx
int v24; // eax
char v25[88]; // [rsp+0h] [rbp-58h] BYREF

prt("(3 - 118) Strength = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v1 = atoi(v25);
if ( (unsigned int)(v1 - 3) <= 0x73 )
{
*((_BYTE *)&py + 360) = v1;
res_stat(0LL);
}
prt("(3 - 118) Intelligence = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v2 = atoi(v25);
if ( (unsigned int)(v2 - 3) <= 0x73 )
{
*((_BYTE *)&py + 361) = v2;
res_stat(1LL);
}
prt("(3 - 118) Wisdom = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v3 = atoi(v25);
if ( (unsigned int)(v3 - 3) <= 0x73 )
{
*((_BYTE *)&py + 362) = v3;
res_stat(2LL);
}
prt("(3 - 118) Dexterity = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v4 = atoi(v25);
if ( (unsigned int)(v4 - 3) <= 0x73 )
{
*((_BYTE *)&py + 363) = v4;
res_stat(3LL);
}
prt("(3 - 118) Constitution = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v5 = atoi(v25);
if ( (unsigned int)(v5 - 3) <= 0x73 )
{
*((_BYTE *)&py + 364) = v5;
res_stat(4LL);
}
prt("(3 - 118) Charisma = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v6 = atoi(v25);
if ( (unsigned int)(v6 - 3) <= 0x73 )
{
*((_BYTE *)&py + 365) = v6;
res_stat(5LL);
}
prt("(1 - 32767) Hit points = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 5LL);
if ( (_DWORD)result )
{
v7 = atoi(v25);
if ( (unsigned int)(v7 - 1) <= 0x7FFE )
{
*((_WORD *)&py + 39) = v7;
*((_WORD *)&py + 56) = v7;
*((_WORD *)&py + 57) = 0;
prt_mhp();
prt_chp();
}
prt("(0 - 32767) Mana = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 5LL);
if ( (_DWORD)result )
{
v8 = atoi(v25);
if ( v8 <= 0x7FFF && v25[0] )
{
*((_WORD *)&py + 38) = v8;
*((_WORD *)&py + 54) = v8;
*((_WORD *)&py + 55) = 0;
prt_cmana();
}
sprintf(v25, "Current=%ld Gold = ", *((_QWORD *)&py + 4));
v9 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v9, 7LL);
if ( (_DWORD)result )
{
v10 = atol(v25);
if ( v10 >= 0 && v25[0] )
{
*((_QWORD *)&py + 4) = v10;
prt_gold();
}
sprintf(v25, "Current=%d (0-200) Searching = ", (unsigned int)*((__int16 *)&py + 34));
v11 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v11, 3LL);
if ( (_DWORD)result )
{
v12 = atoi(v25);
if ( v12 <= 0xC8 && v25[0] )
*((_WORD *)&py + 34) = v12;
sprintf(v25, "Current=%d (-1-18) Stealth = ", (unsigned int)*((__int16 *)&py + 51));
v13 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v13, 3LL);
if ( (_DWORD)result )
{
v14 = atoi(v25);
if ( (unsigned int)(v14 + 1) <= 0x13 && v25[0] )
*((_WORD *)&py + 51) = v14;
sprintf(v25, "Current=%d (0-200) Disarming = ", (unsigned int)*((__int16 *)&py + 48));
v15 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v15, 3LL);
if ( (_DWORD)result )
{
v16 = atoi(v25);
if ( v16 <= 0xC8 && v25[0] )
*((_WORD *)&py + 48) = v16;
sprintf(v25, "Current=%d (0-100) Save = ", (unsigned int)*((__int16 *)&py + 49));
v17 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v17, 3LL);
if ( (_DWORD)result )
{
v18 = atoi(v25);
if ( v18 <= 0xC8 && v25[0] )
*((_WORD *)&py + 49) = v18;
sprintf(v25, "Current=%d (0-200) Base to hit = ", (unsigned int)*((__int16 *)&py + 36));
v19 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v19, 3LL);
if ( (_DWORD)result )
{
v20 = atoi(v25);
if ( v20 <= 0xC8 && v25[0] )
*((_WORD *)&py + 36) = v20;
sprintf(v25, "Current=%d (0-200) Bows/Throwing = ", (unsigned int)*((__int16 *)&py + 37));
v21 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v21, 3LL);
if ( (_DWORD)result )
{
v22 = atoi(v25);
if ( v22 <= 0xC8 && v25[0] )
*((_WORD *)&py + 37) = v22;
sprintf(v25, "Current=%d Weight = ", *((unsigned __int16 *)&py + 31));
v23 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v23, 3LL);
if ( (_DWORD)result )
{
v24 = atoi(v25);
if ( v24 >= 0 )
{
if ( v25[0] )
*((_WORD *)&py + 31) = v24;
}
while ( 1 )
{
result = get_com("Alter speed? (+/-)", v25);
if ( !(_DWORD)result )
break;
result = (unsigned __int8)v25[0];
if ( v25[0] == 43 )
{
change_speed(0xFFFFFFFFLL);
}
else
{
if ( v25[0] != 45 )
return result;
change_speed(1LL);
}
prt_speed();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
unsigned int v8; // eax
unsigned int v9; // ebx
__int64 v10; // rax
unsigned int v11; // ebx
unsigned int v12; // eax
unsigned int v13; // ebx
int v14; // eax
unsigned int v15; // ebx
unsigned int v16; // eax
unsigned int v17; // ebx
unsigned int v18; // eax
unsigned int v19; // ebx
unsigned int v20; // eax
unsigned int v21; // ebx
unsigned int v22; // eax
unsigned int v23; // ebx
int v24; // eax
char v25[88]; // [rsp+0h] [rbp-58h] BYREF

prt("(3 - 118) Strength = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v1 = atoi(v25);
if ( (unsigned int)(v1 - 3) <= 0x73 )
{
*((_BYTE *)&py + 360) = v1;
res_stat(0LL);
}
prt("(3 - 118) Intelligence = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v2 = atoi(v25);
if ( (unsigned int)(v2 - 3) <= 0x73 )
{
*((_BYTE *)&py + 361) = v2;
res_stat(1LL);
}
prt("(3 - 118) Wisdom = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v3 = atoi(v25);
if ( (unsigned int)(v3 - 3) <= 0x73 )
{
*((_BYTE *)&py + 362) = v3;
res_stat(2LL);
}
prt("(3 - 118) Dexterity = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v4 = atoi(v25);
if ( (unsigned int)(v4 - 3) <= 0x73 )
{
*((_BYTE *)&py + 363) = v4;
res_stat(3LL);
}
prt("(3 - 118) Constitution = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v5 = atoi(v25);
if ( (unsigned int)(v5 - 3) <= 0x73 )
{
*((_BYTE *)&py + 364) = v5;
res_stat(4LL);
}
prt("(3 - 118) Charisma = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 3LL);
if ( (_DWORD)result )
{
v6 = atoi(v25);
if ( (unsigned int)(v6 - 3) <= 0x73 )
{
*((_BYTE *)&py + 365) = v6;
res_stat(5LL);
}
prt("(1 - 32767) Hit points = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 5LL);
if ( (_DWORD)result )
{
v7 = atoi(v25);
if ( (unsigned int)(v7 - 1) <= 0x7FFE )
{
*((_WORD *)&py + 39) = v7;
*((_WORD *)&py + 56) = v7;
*((_WORD *)&py + 57) = 0;
prt_mhp();
prt_chp();
}
prt("(0 - 32767) Mana = ", 0LL, 0LL);
result = get_string(v25, 0LL, 25LL, 5LL);
if ( (_DWORD)result )
{
v8 = atoi(v25);
if ( v8 <= 0x7FFF && v25[0] )
{
*((_WORD *)&py + 38) = v8;
*((_WORD *)&py + 54) = v8;
*((_WORD *)&py + 55) = 0;
prt_cmana();
}
sprintf(v25, "Current=%ld Gold = ", *((_QWORD *)&py + 4));
v9 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v9, 7LL);
if ( (_DWORD)result )
{
v10 = atol(v25);
if ( v10 >= 0 && v25[0] )
{
*((_QWORD *)&py + 4) = v10;
prt_gold();
}
sprintf(v25, "Current=%d (0-200) Searching = ", (unsigned int)*((__int16 *)&py + 34));
v11 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v11, 3LL);
if ( (_DWORD)result )
{
v12 = atoi(v25);
if ( v12 <= 0xC8 && v25[0] )
*((_WORD *)&py + 34) = v12;
sprintf(v25, "Current=%d (-1-18) Stealth = ", (unsigned int)*((__int16 *)&py + 51));
v13 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v13, 3LL);
if ( (_DWORD)result )
{
v14 = atoi(v25);
if ( (unsigned int)(v14 + 1) <= 0x13 && v25[0] )
*((_WORD *)&py + 51) = v14;
sprintf(v25, "Current=%d (0-200) Disarming = ", (unsigned int)*((__int16 *)&py + 48));
v15 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v15, 3LL);
if ( (_DWORD)result )
{
v16 = atoi(v25);
if ( v16 <= 0xC8 && v25[0] )
*((_WORD *)&py + 48) = v16;
sprintf(v25, "Current=%d (0-100) Save = ", (unsigned int)*((__int16 *)&py + 49));
v17 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v17, 3LL);
if ( (_DWORD)result )
{
v18 = atoi(v25);
if ( v18 <= 0xC8 && v25[0] )
*((_WORD *)&py + 49) = v18;
sprintf(v25, "Current=%d (0-200) Base to hit = ", (unsigned int)*((__int16 *)&py + 36));
v19 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v19, 3LL);
if ( (_DWORD)result )
{
v20 = atoi(v25);
if ( v20 <= 0xC8 && v25[0] )
*((_WORD *)&py + 36) = v20;
sprintf(v25, "Current=%d (0-200) Bows/Throwing = ", (unsigned int)*((__int16 *)&py + 37));
v21 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v21, 3LL);
if ( (_DWORD)result )
{
v22 = atoi(v25);
if ( v22 <= 0xC8 && v25[0] )
*((_WORD *)&py + 37) = v22;
sprintf(v25, "Current=%d Weight = ", *((unsigned __int16 *)&py + 31));
v23 = strlen(v25);
prt(v25, 0LL, 0LL);
result = get_string(v25, 0LL, v23, 3LL);
if ( (_DWORD)result )
{
v24 = atoi(v25);
if ( v24 >= 0 )
{
if ( v25[0] )
*((_WORD *)&py + 31) = v24;
}
while ( 1 )
{
result = get_com("Alter speed? (+/-)", v25);
if ( !(_DWORD)result )
break;
result = (unsigned __int8)v25[0];
if ( v25[0] == 43 )
{
change_speed(0xFFFFFFFFLL);
}
else
{
if ( v25[0] != 45 )
return result;
change_speed(1LL);
}
prt_speed();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
void change_character()
{
  register int tmp_val;
  register int32 tmp_lval;
  int8u *a_ptr;
  vtype tmp_str;
  register struct misc *m_ptr;
  a_ptr = py.stats.max_stat;
  prt("(3 - 118) Strength     = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[0] = tmp_val;
   (void) res_stat(0);
 }
    }
  else
    return;
  prt("(3 - 118) Intelligence = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[1] = tmp_val;
   (void) res_stat(1);
 }
    }
  else
    return;
  prt("(3 - 118) Wisdom       = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[2] = tmp_val;
   (void) res_stat(2);
 }
    }
  else
    return;
  prt("(3 - 118) Dexterity    = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[3] = tmp_val;
   (void) res_stat(3);
 }
    }
  else
    return;
  prt("(3 - 118) Constitution = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[4] = tmp_val;
   (void) res_stat(4);
 }
    }
  else
    return;
  prt("(3 - 118) Charisma     = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[5] = tmp_val;
   (void) res_stat(5);
 }
    }
  else
    return;
  m_ptr = &py.misc;
  prt("(1 - 32767) Hit points = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 5))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 0) && (tmp_val <= 32767))
 {
   m_ptr->mhp = tmp_val;
   m_ptr->chp = tmp_val;
   m_ptr->chp_frac = 0;
   prt_mhp();
   prt_chp();
 }
    }
  else
    return;
  prt("(0 - 32767) Mana       = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 5))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val <= 32767) && (*tmp_str != '\0'))
 {
   m_ptr->mana = tmp_val;
   m_ptr->cmana = tmp_val;
   m_ptr->cmana_frac = 0;
   prt_cmana();
 }
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%ld  Gold = ", m_ptr->au);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 7))
    {
      tmp_lval = atol(tmp_str);
      if (tmp_lval > -1 && (*tmp_str != '\0'))
 {
   m_ptr->au = tmp_lval;
   prt_gold();
 }
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-200) Searching = ", m_ptr->srh);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->srh = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (-1-18) Stealth = ", m_ptr->stl);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -2) && (tmp_val < 19) && (*tmp_str != '\0'))
 m_ptr->stl = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-200) Disarming = ", m_ptr->disarm);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->disarm = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-100) Save = ", m_ptr->save);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->save = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-200) Base to hit = ", m_ptr->bth);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->bth = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-200) Bows/Throwing = ",
   m_ptr->bthb);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->bthb = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  Weight = ", m_ptr->wt);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if (tmp_val > -1 && (*tmp_str != '\0'))
 m_ptr->wt = tmp_val;
    }
  else
    return;
  while(get_com("Alter speed? (+/-)", tmp_str))
    {
      if (*tmp_str == '+')
 change_speed(-1);
      else if (*tmp_str == '-')
 change_speed(1);
      else
 break;
      prt_speed();
    }
}

canonical_original_code:
void change_character()
{
  register int tmp_val;
  register long tmp_lval;
  unsigned char *a_ptr;
  char tmp_str[80];
  register struct misc *m_ptr;
  a_ptr = py.stats.max_stat;
  prt("(3 - 118) Strength     = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[0] = tmp_val;
   (void) res_stat(0);
 }
    }
  else
    return;
  prt("(3 - 118) Intelligence = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[1] = tmp_val;
   (void) res_stat(1);
 }
    }
  else
    return;
  prt("(3 - 118) Wisdom       = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[2] = tmp_val;
   (void) res_stat(2);
 }
    }
  else
    return;
  prt("(3 - 118) Dexterity    = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[3] = tmp_val;
   (void) res_stat(3);
 }
    }
  else
    return;
  prt("(3 - 118) Constitution = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[4] = tmp_val;
   (void) res_stat(4);
 }
    }
  else
    return;
  prt("(3 - 118) Charisma     = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 2) && (tmp_val < 119))
 {
   a_ptr[5] = tmp_val;
   (void) res_stat(5);
 }
    }
  else
    return;
  m_ptr = &py.misc;
  prt("(1 - 32767) Hit points = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 5))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > 0) && (tmp_val <= 32767))
 {
   m_ptr->mhp = tmp_val;
   m_ptr->chp = tmp_val;
   m_ptr->chp_frac = 0;
   prt_mhp();
   prt_chp();
 }
    }
  else
    return;
  prt("(0 - 32767) Mana       = ", 0, 0);
  if (get_string(tmp_str, 0, 25, 5))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val <= 32767) && (*tmp_str != '\0'))
 {
   m_ptr->mana = tmp_val;
   m_ptr->cmana = tmp_val;
   m_ptr->cmana_frac = 0;
   prt_cmana();
 }
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%ld  Gold = ", m_ptr->au);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 7))
    {
      tmp_lval = atol(tmp_str);
      if (tmp_lval > -1 && (*tmp_str != '\0'))
 {
   m_ptr->au = tmp_lval;
   prt_gold();
 }
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-200) Searching = ", m_ptr->srh);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->srh = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (-1-18) Stealth = ", m_ptr->stl);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -2) && (tmp_val < 19) && (*tmp_str != '\0'))
 m_ptr->stl = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-200) Disarming = ", m_ptr->disarm);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->disarm = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-100) Save = ", m_ptr->save);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->save = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-200) Base to hit = ", m_ptr->bth);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->bth = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  (0-200) Bows/Throwing = ",
   m_ptr->bthb);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if ((tmp_val > -1) && (tmp_val < 201) && (*tmp_str != '\0'))
 m_ptr->bthb = tmp_val;
    }
  else
    return;
  (void) sprintf(tmp_str, "Current=%d  Weight = ", m_ptr->wt);
  tmp_val = strlen(tmp_str);
  prt(tmp_str, 0, 0);
  if (get_string(tmp_str, 0, tmp_val, 3))
    {
      tmp_val = atoi(tmp_str);
      if (tmp_val > -1 && (*tmp_str != '\0'))
 m_ptr->wt = tmp_val;
    }
  else
    return;
  while(get_com("Alter speed? (+/-)", tmp_str))
    {
      if (*tmp_str == '+')
 change_speed(-1);
      else if (*tmp_str == '-')
 change_speed(1);
      else
 break;
      prt_speed();
    }
}

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


decompiled_code:
__int64 wizard_create()
{
__int64 result; // rax
__int64 v1; // rbx
__int64 v2; // r12
__int64 v3; // rdi
__int64 v4; // rsi
int v5; // eax
__int16 *v6; // rsi
__int64 v7; // rcx
_DWORD *v8; // rdi
int v9; // [rsp+4h] [rbp-B4h] BYREF
__int64 v10; // [rsp+8h] [rbp-B0h] BYREF
__int16 v11; // [rsp+10h] [rbp-A8h] BYREF
char v12; // [rsp+12h] [rbp-A6h]
__int64 v13; // [rsp+20h] [rbp-98h]
char v14; // [rsp+28h] [rbp-90h]
char v15; // [rsp+29h] [rbp-8Fh]
__int16 v16; // [rsp+2Ah] [rbp-8Eh]
__int64 v17; // [rsp+30h] [rbp-88h]
char v18; // [rsp+38h] [rbp-80h]
char v19; // [rsp+39h] [rbp-7Fh]
__int16 v20; // [rsp+3Ah] [rbp-7Eh]
__int16 v21; // [rsp+3Ch] [rbp-7Ch]
__int16 v22; // [rsp+3Eh] [rbp-7Ah]
__int16 v23; // [rsp+40h] [rbp-78h]
__int16 v24; // [rsp+42h] [rbp-76h]
char v25; // [rsp+44h] [rbp-74h]
char v26; // [rsp+45h] [rbp-73h]
char v27; // [rsp+46h] [rbp-72h]
char v28; // [rsp+47h] [rbp-71h]
char nptr[104]; // [rsp+50h] [rbp-68h] BYREF

msg_print("Warning: This routine can cause a fatal error.");
v11 = 419;
v12 = 0;
inscribe(&v11, "wizard item");
v28 = 24;
prt("Tval : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v14 = atoi(nptr);
prt("Tchar : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 1LL);
if ( (_DWORD)result )
{
v15 = nptr[0];
prt("Subval : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 5LL);
if ( (_DWORD)result )
{
v18 = atoi(nptr);
prt("Weight : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 5LL);
if ( (_DWORD)result )
{
v20 = atoi(nptr);
prt("Number : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 5LL);
if ( (_DWORD)result )
{
v19 = atoi(nptr);
prt("Damage (dice): ", 0LL, 0LL);
result = get_string(nptr, 0LL, 15LL, 3LL);
if ( (_DWORD)result )
{
v25 = atoi(nptr);
prt("Damage (sides): ", 0LL, 0LL);
result = get_string(nptr, 0LL, 16LL, 3LL);
if ( (_DWORD)result )
{
v26 = atoi(nptr);
prt("+To hit: ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v21 = atoi(nptr);
prt("+To dam: ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v22 = atoi(nptr);
prt("AC : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v23 = atoi(nptr);
prt("+To AC : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v24 = atoi(nptr);
prt("P1 : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 5LL);
if ( (_DWORD)result )
{
v16 = atoi(nptr);
prt("Flags (In HEX): ", 0LL, 0LL);
result = get_string(nptr, 0LL, 16LL, 8LL);
if ( (_DWORD)result )
{
v9 = 7892005;
_isoc99_sscanf(nptr, &v9, &v10);
v13 = v10;
prt("Cost : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 8LL);
if ( (_DWORD)result )
{
v10 = atol(nptr);
v17 = v10;
prt("Level : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 10LL, 3LL);
if ( (_DWORD)result )
{
v27 = atoi(nptr);
if ( (unsigned int)get_check("Allocate?") )
{
v1 = char_row;
v2 = char_col;
v3 = char_row;
v4 = char_col;
if ( cave[792 * char_row + 1 + 4 * char_col] )
delete_object(char_row, char_col);
v5 = popt(v3, v4);
v6 = &v11;
v7 = 14LL;
v8 = (_DWORD *)((char *)&t_list + 56 * v5);
while ( v7 )
{
*v8 = *(_DWORD *)v6;
v6 += 2;
++v8;
--v7;
}
cave[792 * v1 + 1 + 4 * v2] = v5;
result = msg_print("Allocated.");
}
else
{
result = msg_print("Aborted.");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
__int64 v1; // rbx
__int64 v2; // r12
__int64 v3; // rdi
__int64 v4; // rsi
int v5; // eax
__int16 *v6; // rsi
__int64 v7; // rcx
_DWORD *v8; // rdi
int v9; // [rsp+4h] [rbp-B4h] BYREF
__int64 v10; // [rsp+8h] [rbp-B0h] BYREF
__int16 v11; // [rsp+10h] [rbp-A8h] BYREF
char v12; // [rsp+12h] [rbp-A6h]
__int64 v13; // [rsp+20h] [rbp-98h]
char v14; // [rsp+28h] [rbp-90h]
char v15; // [rsp+29h] [rbp-8Fh]
__int16 v16; // [rsp+2Ah] [rbp-8Eh]
__int64 v17; // [rsp+30h] [rbp-88h]
char v18; // [rsp+38h] [rbp-80h]
char v19; // [rsp+39h] [rbp-7Fh]
__int16 v20; // [rsp+3Ah] [rbp-7Eh]
__int16 v21; // [rsp+3Ch] [rbp-7Ch]
__int16 v22; // [rsp+3Eh] [rbp-7Ah]
__int16 v23; // [rsp+40h] [rbp-78h]
__int16 v24; // [rsp+42h] [rbp-76h]
char v25; // [rsp+44h] [rbp-74h]
char v26; // [rsp+45h] [rbp-73h]
char v27; // [rsp+46h] [rbp-72h]
char v28; // [rsp+47h] [rbp-71h]
char nptr[104]; // [rsp+50h] [rbp-68h] BYREF

msg_print("Warning: This routine can cause a fatal error.");
v11 = 419;
v12 = 0;
inscribe(&v11, "wizard item");
v28 = 24;
prt("Tval : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v14 = atoi(nptr);
prt("Tchar : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 1LL);
if ( (_DWORD)result )
{
v15 = nptr[0];
prt("Subval : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 5LL);
if ( (_DWORD)result )
{
v18 = atoi(nptr);
prt("Weight : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 5LL);
if ( (_DWORD)result )
{
v20 = atoi(nptr);
prt("Number : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 5LL);
if ( (_DWORD)result )
{
v19 = atoi(nptr);
prt("Damage (dice): ", 0LL, 0LL);
result = get_string(nptr, 0LL, 15LL, 3LL);
if ( (_DWORD)result )
{
v25 = atoi(nptr);
prt("Damage (sides): ", 0LL, 0LL);
result = get_string(nptr, 0LL, 16LL, 3LL);
if ( (_DWORD)result )
{
v26 = atoi(nptr);
prt("+To hit: ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v21 = atoi(nptr);
prt("+To dam: ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v22 = atoi(nptr);
prt("AC : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v23 = atoi(nptr);
prt("+To AC : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 3LL);
if ( (_DWORD)result )
{
v24 = atoi(nptr);
prt("P1 : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 5LL);
if ( (_DWORD)result )
{
v16 = atoi(nptr);
prt("Flags (In HEX): ", 0LL, 0LL);
result = get_string(nptr, 0LL, 16LL, 8LL);
if ( (_DWORD)result )
{
v9 = 7892005;
_isoc99_sscanf(nptr, &v9, &v10);
v13 = v10;
prt("Cost : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 9LL, 8LL);
if ( (_DWORD)result )
{
v10 = atol(nptr);
v17 = v10;
prt("Level : ", 0LL, 0LL);
result = get_string(nptr, 0LL, 10LL, 3LL);
if ( (_DWORD)result )
{
v27 = atoi(nptr);
if ( (unsigned int)get_check("Allocate?") )
{
v1 = char_row;
v2 = char_col;
v3 = char_row;
v4 = char_col;
if ( cave[792 * char_row + 1 + 4 * char_col] )
delete_object(char_row, char_col);
v5 = popt(v3, v4);
v6 = &v11;
v7 = 14LL;
v8 = (_DWORD *)((char *)&t_list + 56 * v5);
while ( v7 )
{
*v8 = *(_DWORD *)v6;
v6 += 2;
++v8;
--v7;
}
cave[792 * v1 + 1 + 4 * v2] = v5;
result = msg_print("Allocated.");
}
else
{
result = msg_print("Aborted.");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
void wizard_create()
{
  register int tmp_val;
  int32 tmp_lval;
  vtype tmp_str;
  register inven_type *i_ptr;
  inven_type forge;
  register cave_type *c_ptr;
  char pattern[4];
  msg_print("Warning: This routine can cause a fatal error.");
  i_ptr = &forge;
  i_ptr->index = 419;
  i_ptr->name2 = 0;
  inscribe(i_ptr, "wizard item");
  i_ptr->ident = 0x8|0x10;
  prt("Tval   : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->tval = tmp_val;
  prt("Tchar  : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 1))
    return;
  i_ptr->tchar = tmp_str[0];
  prt("Subval : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 5))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->subval = tmp_val;
  prt("Weight : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 5))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->weight = tmp_val;
  prt("Number : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 5))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->number = tmp_val;
  prt("Damage (dice): ", 0, 0);
  if (!get_string(tmp_str, 0, 15, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->damage[0] = tmp_val;
  prt("Damage (sides): ", 0, 0);
  if (!get_string(tmp_str, 0, 16, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->damage[1] = tmp_val;
  prt("+To hit: ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->tohit = tmp_val;
  prt("+To dam: ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->todam = tmp_val;
  prt("AC     : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->ac = tmp_val;
  prt("+To AC : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->toac = tmp_val;
  prt("P1     : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 5))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->p1 = tmp_val;
  prt("Flags (In HEX): ", 0, 0);
  if (!get_string(tmp_str, 0, 16, 8))
    return;
  (void) strcpy (pattern, "%lx");
  (void) sscanf(tmp_str, pattern, &tmp_lval);
  i_ptr->flags = tmp_lval;
  prt("Cost : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 8))
    return;
  tmp_lval = atol(tmp_str);
  i_ptr->cost = tmp_lval;
  prt("Level : ", 0, 0);
  if (!get_string(tmp_str, 0, 10, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->level = tmp_val;
  if (get_check("Allocate?"))
    {
      c_ptr = &cave[char_row][char_col];
      if (c_ptr->tptr != 0)
 (void) delete_object(char_row, char_col);
      tmp_val = popt();
      t_list[tmp_val] = forge;
      c_ptr->tptr = tmp_val;
      msg_print("Allocated.");
    }
  else
    msg_print("Aborted.");
}

canonical_original_code:
void wizard_create()
{
  register int tmp_val;
  long tmp_lval;
  char tmp_str[80];
  register struct inven_type *i_ptr;
  struct inven_type forge;
  register struct cave_type *c_ptr;
  char pattern[4];
  msg_print("Warning: This routine can cause a fatal error.");
  i_ptr = &forge;
  i_ptr->index = 419;
  i_ptr->name2 = 0;
  inscribe(i_ptr, "wizard item");
  i_ptr->ident = 0x8|0x10;
  prt("Tval   : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->tval = tmp_val;
  prt("Tchar  : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 1))
    return;
  i_ptr->tchar = tmp_str[0];
  prt("Subval : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 5))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->subval = tmp_val;
  prt("Weight : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 5))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->weight = tmp_val;
  prt("Number : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 5))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->number = tmp_val;
  prt("Damage (dice): ", 0, 0);
  if (!get_string(tmp_str, 0, 15, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->damage[0] = tmp_val;
  prt("Damage (sides): ", 0, 0);
  if (!get_string(tmp_str, 0, 16, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->damage[1] = tmp_val;
  prt("+To hit: ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->tohit = tmp_val;
  prt("+To dam: ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->todam = tmp_val;
  prt("AC     : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->ac = tmp_val;
  prt("+To AC : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->toac = tmp_val;
  prt("P1     : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 5))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->p1 = tmp_val;
  prt("Flags (In HEX): ", 0, 0);
  if (!get_string(tmp_str, 0, 16, 8))
    return;
  (void) strcpy (pattern, "%lx");
  (void) sscanf(tmp_str, pattern, &tmp_lval);
  i_ptr->flags = tmp_lval;
  prt("Cost : ", 0, 0);
  if (!get_string(tmp_str, 0, 9, 8))
    return;
  tmp_lval = atol(tmp_str);
  i_ptr->cost = tmp_lval;
  prt("Level : ", 0, 0);
  if (!get_string(tmp_str, 0, 10, 3))
    return;
  tmp_val = atoi(tmp_str);
  i_ptr->level = tmp_val;
  if (get_check("Allocate?"))
    {
      c_ptr = &cave[char_row][char_col];
      if (c_ptr->tptr != 0)
 (void) delete_object(char_row, char_col);
      tmp_val = popt();
      t_list[tmp_val] = forge;
      c_ptr->tptr = tmp_val;
      msg_print("Allocated.");
    }
  else
    msg_print("Aborted.");
}

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:
pattern
char [4]

user_defined_types: struct cave_type { unsigned char cptr; unsigned char tptr; unsigned char fval; unsigned int lr; unsigned int fm; unsigned int pl; unsigned int tl; }


quaff

decompiled_code:
__int64 quaff()
{
__int64 result; // rax
const char *v1; // rsi
__int64 v2; // r13
int v3; // ebx
char *v4; // r12
int v5; // eax
bool v6; // zf
int v7; // edx
__int64 v8; // rdx
unsigned __int64 v9; // rax
__int64 v10; // rdi
unsigned int v11; // eax
__int64 v12; // rdi
__int64 v13; // rbx
int v14; // eax
__int64 v15; // rcx
__int64 v16; // rdx
__int64 v17; // rdi
__int16 v18; // ax
int v19; // eax
__int64 v20; // rdx
int v21; // eax
int v22; // [rsp+0h] [rbp-60h]
unsigned int v23; // [rsp+14h] [rbp-4Ch] BYREF
unsigned int v24; // [rsp+18h] [rbp-48h] BYREF
unsigned int v25; // [rsp+1Ch] [rbp-44h] BYREF
__int64 v26[8]; // [rsp+20h] [rbp-40h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(75LL, 76LL, &v23, &v24) )
return msg_print("You are not carrying any potions.");
v1 = "Quaff which potion?";
result = get_item(&v25, "Quaff which potion?", v23, v24, 0LL, 0LL);
if ( (_DWORD)result )
{
v2 = (int)v25;
v3 = 0;
free_turn_flag = 0;
v4 = (char *)&inventory[56 * v25];
v26[0] = *((_QWORD *)v4 + 2);
if ( v26[0] )
{
do
{
v5 = bit_pos(v26);
v6 = v4[24] == 76;
v7 = v5 + 1;
v23 = v5 + 1;
if ( v6 )
{
v7 = v5 + 33;
v23 = v5 + 33;
}
switch ( v7 )
{
case 1:
v22 = v7;
if ( (unsigned int)inc_stat(0LL) )
{
msg_print("Wow! What bulging muscles!");
v3 = v22;
}
break;
case 2:
v3 = 1;
lose_str();
break;
case 3:
if ( (unsigned int)res_stat(0LL) )
{
v3 = 1;
msg_print("You feel warm all over.");
}
break;
case 4:
if ( (unsigned int)inc_stat(1LL) )
{
v3 = 1;
msg_print("Aren't you brilliant!");
}
break;
case 5:
v3 = 1;
lose_int();
break;
case 6:
if ( (unsigned int)res_stat(1LL) )
{
v3 = 1;
msg_print("You have have a warm feeling.");
}
break;
case 7:
if ( (unsigned int)inc_stat(2LL) )
{
v3 = 1;
msg_print("You suddenly have a profound thought!");
}
break;
case 8:
v3 = 1;
lose_wis();
break;
case 9:
if ( (unsigned int)res_stat(2LL) )
{
v3 = 1;
msg_print("You feel your wisdom returning.");
}
break;
case 10:
if ( (unsigned int)inc_stat(5LL) )
{
v3 = 1;
msg_print("Gee, ain't you cute!");
}
break;
case 11:
v3 = 1;
lose_chr();
break;
case 12:
if ( (unsigned int)res_stat(5LL) )
{
v3 = 1;
msg_print("You feel your looks returning.");
}
break;
case 13:
v1 = (_BYTE *)(quaff + 7);
v10 = 2LL;
goto LABEL_53;
case 14:
v1 = (_BYTE *)(quaff + 7);
v10 = 4LL;
goto LABEL_53;
case 15:
v1 = (_BYTE *)(quaff + 7);
v10 = 6LL;
LABEL_53:
v11 = damroll(v10, 7LL);
v3 = hp_player(v11);
break;
case 16:
v3 = hp_player(1000LL);
break;
case 17:
if ( (unsigned int)inc_stat(4LL) )
{
v3 = 1;
msg_print("You feel tingly for a moment.");
}
break;
case 18:
v8 = *((_QWORD *)&py + 6);
if ( v8 <= 9999998 )
{
v3 = 1;
v9 = v8 / 2 + 10;
if ( v9 > 0x186A0 )
v9 = 100000LL;
*((_QWORD *)&py + 6) = v8 + v9;
msg_print("You feel more experienced.");
((void (*)(void))prt_experience)();
}
break;
case 19:
if ( !*((_BYTE *)&py + 450) )
{
v3 = 1;
msg_print("You fall asleep.");
*((_WORD *)&py + 202) += randint(4LL) + 4;
}
break;
case 20:
if ( !*((_WORD *)&py + 201) )
{
v3 = 1;
msg_print("You are covered by a veil of darkness.");
}
*((_WORD *)&py + 201) += randint(100LL) + 100;
break;
case 21:
if ( !*((_WORD *)&py + 203) )
{
v3 = 1;
msg_print("Hey! This is good stuff! * Hick! *");
}
*((_WORD *)&py + 203) += randint(20LL) + 12;
break;
case 22:
if ( !*((_WORD *)&py + 211) )
{
v3 = 1;
msg_print("You feel very sick.");
}
*((_WORD *)&py + 211) += randint(15LL) + 10;
break;
case 23:
if ( !*((_WORD *)&py + 208) )
v3 = 1;
*((_WORD *)&py + 208) += randint(25LL) + 15;
break;
case 24:
if ( !*((_WORD *)&py + 209) )
v3 = 1;
*((_WORD *)&py + 209) += randint(25LL) + 15;
break;
case 26:
if ( (unsigned int)inc_stat(3LL) )
{
v3 = 1;
msg_print("You feel more limber!");
}
break;
case 27:
if ( (unsigned int)res_stat(3LL) )
{
v3 = 1;
msg_print("You feel less clumsy.");
}
break;
case 28:
if ( (unsigned int)res_stat(4LL) )
{
v3 = 1;
msg_print("You feel your health returning!");
}
break;
case 29:
v3 = cure_blindness();
break;
case 30:
v3 = cure_confusion();
break;
case 31:
case 45:
v3 = cure_poison();
break;
case 34:
if ( *((__int64 *)&py + 6) > 0 )
{
msg_print("You feel your memories fade.");
v12 = *((_QWORD *)&py + 6);
v13 = v12 / 5;
if ( v12 <= 0x7FFF )
{
v21 = randint(v12);
v16 = (unsigned int)(v21 >> 31);
v17 = v21 / 5 + v13;
}
else
{
v14 = randint((unsigned int)(0x7FFFFFFF / v12));
v15 = 5 * (0x7FFFFFFF / v12);
v16 = *((_QWORD *)&py + 6) * v14 % v15;
v17 = *((_QWORD *)&py + 6) * v14 / v15 + v13;
}
v3 = 1;
lose_exp(v17, v1, v16);
}
break;
case 35:
cure_poison();
if ( *((__int16 *)&py + 204) > 150 )
*((_WORD *)&py + 204) = 150;
v3 = 1;
*((_WORD *)&py + 202) = 4;
msg_print("The potion makes you vomit!");
break;
case 36:
if ( !*((_WORD *)&py + 214) )
v3 = 1;
*((_WORD *)&py + 214) += randint(10LL) + 10;
break;
case 37:
if ( !*((_WORD *)&py + 215) )
v3 = 1;
*((_WORD *)&py + 215) += randint(25LL) + 25;
break;
case 38:
if ( !*((_WORD *)&py + 216) )
v3 = 1;
*((_WORD *)&py + 216) += randint(25LL) + 25;
break;
case 39:
v3 = remove_fear();
break;
case 40:
v3 = restore_level();
break;
case 41:
if ( !*((_WORD *)&py + 218) )
v3 = 1;
*((_WORD *)&py + 218) += randint(10LL) + 10;
break;
case 42:
if ( !*((_WORD *)&py + 219) )
v3 = 1;
*((_WORD *)&py + 219) += randint(10LL) + 10;
break;
case 43:
if ( !*((_WORD *)&py + 220) )
v3 = 1;
v19 = randint(12LL);
detect_inv2((unsigned int)(v19 + 12));
break;
case 44:
v3 = slow_poison();
break;
case 46:
v18 = *((_WORD *)&py + 38);
if ( *((__int16 *)&py + 54) < v18 )
{
*((_WORD *)&py + 54) = v18;
v3 = 1;
msg_print("Your feel your head clear.");
prt_cmana();
}
break;
case 47:
if ( !*((_WORD *)&py + 223) )
{
v3 = 1;
msg_print("Your eyes begin to tingle.");
}
*((_WORD *)&py + 223) += randint(100LL) + 100;
break;
default:
msg_print("Internal error in potion()");
break;
}
}
while ( v26[0] );
if ( !v3 )
{
if ( !(unsigned int)known1_p(v4) )
sample(v4);
goto LABEL_16;
}
}
else
{
msg_print("You feel less thirsty.");
}
if ( !(unsigned int)known1_p(v4) )
{
v20 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) >> 31);
LODWORD(v20) = ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) % *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) / *((unsigned __int16 *)&py + 32);
prt_experience(v4, v1, v20);
identify(&v25);
v4 = (char *)&inventory[56 * v25];
}
LABEL_16:
add_food((unsigned int)*((__int16 *)v4 + 13));
desc_remain(v25);
result = inven_destroy(v25);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
const char *v1; // rsi
__int64 v2; // r13
int v3; // ebx
char *v4; // r12
int v5; // eax
bool v6; // zf
int v7; // edx
__int64 v8; // rdx
unsigned __int64 v9; // rax
__int64 v10; // rdi
unsigned int v11; // eax
__int64 v12; // rdi
__int64 v13; // rbx
int v14; // eax
__int64 v15; // rcx
__int64 v16; // rdx
__int64 v17; // rdi
__int16 v18; // ax
int v19; // eax
__int64 v20; // rdx
int v21; // eax
int v22; // [rsp+0h] [rbp-60h]
unsigned int v23; // [rsp+14h] [rbp-4Ch] BYREF
unsigned int v24; // [rsp+18h] [rbp-48h] BYREF
unsigned int v25; // [rsp+1Ch] [rbp-44h] BYREF
__int64 v26[8]; // [rsp+20h] [rbp-40h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(75LL, 76LL, &v23, &v24) )
return msg_print("You are not carrying any potions.");
v1 = "Quaff which potion?";
result = get_item(&v25, "Quaff which potion?", v23, v24, 0LL, 0LL);
if ( (_DWORD)result )
{
v2 = (int)v25;
v3 = 0;
free_turn_flag = 0;
v4 = (char *)&inventory[56 * v25];
v26[0] = *((_QWORD *)v4 + 2);
if ( v26[0] )
{
do
{
v5 = bit_pos(v26);
v6 = v4[24] == 76;
v7 = v5 + 1;
v23 = v5 + 1;
if ( v6 )
{
v7 = v5 + 33;
v23 = v5 + 33;
}
switch ( v7 )
{
case 1:
v22 = v7;
if ( (unsigned int)inc_stat(0LL) )
{
msg_print("Wow! What bulging muscles!");
v3 = v22;
}
break;
case 2:
v3 = 1;
lose_str();
break;
case 3:
if ( (unsigned int)res_stat(0LL) )
{
v3 = 1;
msg_print("You feel warm all over.");
}
break;
case 4:
if ( (unsigned int)inc_stat(1LL) )
{
v3 = 1;
msg_print("Aren't you brilliant!");
}
break;
case 5:
v3 = 1;
lose_int();
break;
case 6:
if ( (unsigned int)res_stat(1LL) )
{
v3 = 1;
msg_print("You have have a warm feeling.");
}
break;
case 7:
if ( (unsigned int)inc_stat(2LL) )
{
v3 = 1;
msg_print("You suddenly have a profound thought!");
}
break;
case 8:
v3 = 1;
lose_wis();
break;
case 9:
if ( (unsigned int)res_stat(2LL) )
{
v3 = 1;
msg_print("You feel your wisdom returning.");
}
break;
case 10:
if ( (unsigned int)inc_stat(5LL) )
{
v3 = 1;
msg_print("Gee, ain't you cute!");
}
break;
case 11:
v3 = 1;
lose_chr();
break;
case 12:
if ( (unsigned int)res_stat(5LL) )
{
v3 = 1;
msg_print("You feel your looks returning.");
}
break;
case 13:
v1 = (_BYTE *)(quaff + 7);
v10 = 2LL;
goto LABEL_53;
case 14:
v1 = (_BYTE *)(quaff + 7);
v10 = 4LL;
goto LABEL_53;
case 15:
v1 = (_BYTE *)(quaff + 7);
v10 = 6LL;
LABEL_53:
v11 = damroll(v10, 7LL);
v3 = hp_player(v11);
break;
case 16:
v3 = hp_player(1000LL);
break;
case 17:
if ( (unsigned int)inc_stat(4LL) )
{
v3 = 1;
msg_print("You feel tingly for a moment.");
}
break;
case 18:
v8 = *((_QWORD *)&py + 6);
if ( v8 <= 9999998 )
{
v3 = 1;
v9 = v8 / 2 + 10;
if ( v9 > 0x186A0 )
v9 = 100000LL;
*((_QWORD *)&py + 6) = v8 + v9;
msg_print("You feel more experienced.");
((void (*)(void))prt_experience)();
}
break;
case 19:
if ( !*((_BYTE *)&py + 450) )
{
v3 = 1;
msg_print("You fall asleep.");
*((_WORD *)&py + 202) += randint(4LL) + 4;
}
break;
case 20:
if ( !*((_WORD *)&py + 201) )
{
v3 = 1;
msg_print("You are covered by a veil of darkness.");
}
*((_WORD *)&py + 201) += randint(100LL) + 100;
break;
case 21:
if ( !*((_WORD *)&py + 203) )
{
v3 = 1;
msg_print("Hey! This is good stuff! * Hick! *");
}
*((_WORD *)&py + 203) += randint(20LL) + 12;
break;
case 22:
if ( !*((_WORD *)&py + 211) )
{
v3 = 1;
msg_print("You feel very sick.");
}
*((_WORD *)&py + 211) += randint(15LL) + 10;
break;
case 23:
if ( !*((_WORD *)&py + 208) )
v3 = 1;
*((_WORD *)&py + 208) += randint(25LL) + 15;
break;
case 24:
if ( !*((_WORD *)&py + 209) )
v3 = 1;
*((_WORD *)&py + 209) += randint(25LL) + 15;
break;
case 26:
if ( (unsigned int)inc_stat(3LL) )
{
v3 = 1;
msg_print("You feel more limber!");
}
break;
case 27:
if ( (unsigned int)res_stat(3LL) )
{
v3 = 1;
msg_print("You feel less clumsy.");
}
break;
case 28:
if ( (unsigned int)res_stat(4LL) )
{
v3 = 1;
msg_print("You feel your health returning!");
}
break;
case 29:
v3 = cure_blindness();
break;
case 30:
v3 = cure_confusion();
break;
case 31:
case 45:
v3 = cure_poison();
break;
case 34:
if ( *((__int64 *)&py + 6) > 0 )
{
msg_print("You feel your memories fade.");
v12 = *((_QWORD *)&py + 6);
v13 = v12 / 5;
if ( v12 <= 0x7FFF )
{
v21 = randint(v12);
v16 = (unsigned int)(v21 >> 31);
v17 = v21 / 5 + v13;
}
else
{
v14 = randint((unsigned int)(0x7FFFFFFF / v12));
v15 = 5 * (0x7FFFFFFF / v12);
v16 = *((_QWORD *)&py + 6) * v14 % v15;
v17 = *((_QWORD *)&py + 6) * v14 / v15 + v13;
}
v3 = 1;
lose_exp(v17, v1, v16);
}
break;
case 35:
cure_poison();
if ( *((__int16 *)&py + 204) > 150 )
*((_WORD *)&py + 204) = 150;
v3 = 1;
*((_WORD *)&py + 202) = 4;
msg_print("The potion makes you vomit!");
break;
case 36:
if ( !*((_WORD *)&py + 214) )
v3 = 1;
*((_WORD *)&py + 214) += randint(10LL) + 10;
break;
case 37:
if ( !*((_WORD *)&py + 215) )
v3 = 1;
*((_WORD *)&py + 215) += randint(25LL) + 25;
break;
case 38:
if ( !*((_WORD *)&py + 216) )
v3 = 1;
*((_WORD *)&py + 216) += randint(25LL) + 25;
break;
case 39:
v3 = remove_fear();
break;
case 40:
v3 = restore_level();
break;
case 41:
if ( !*((_WORD *)&py + 218) )
v3 = 1;
*((_WORD *)&py + 218) += randint(10LL) + 10;
break;
case 42:
if ( !*((_WORD *)&py + 219) )
v3 = 1;
*((_WORD *)&py + 219) += randint(10LL) + 10;
break;
case 43:
if ( !*((_WORD *)&py + 220) )
v3 = 1;
v19 = randint(12LL);
detect_inv2((unsigned int)(v19 + 12));
break;
case 44:
v3 = slow_poison();
break;
case 46:
v18 = *((_WORD *)&py + 38);
if ( *((__int16 *)&py + 54) < v18 )
{
*((_WORD *)&py + 54) = v18;
v3 = 1;
msg_print("Your feel your head clear.");
prt_cmana();
}
break;
case 47:
if ( !*((_WORD *)&py + 223) )
{
v3 = 1;
msg_print("Your eyes begin to tingle.");
}
*((_WORD *)&py + 223) += randint(100LL) + 100;
break;
default:
msg_print("Internal error in potion()");
break;
}
}
while ( v26[0] );
if ( !v3 )
{
if ( !(unsigned int)known1_p(v4) )
sample(v4);
goto LABEL_16;
}
}
else
{
msg_print("You feel less thirsty.");
}
if ( !(unsigned int)known1_p(v4) )
{
v20 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) >> 31);
LODWORD(v20) = ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) % *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) / *((unsigned __int16 *)&py + 32);
prt_experience(v4, v1, v20);
identify(&v25);
v4 = (char *)&inventory[56 * v25];
}
LABEL_16:
add_food((unsigned int)*((__int16 *)v4 + 13));
desc_remain(v25);
result = inven_destroy(v25);
}
return result;
}

original_code:
void quaff()
{
  int32u i, l;
  int j, k, item_val;
  int ident;
  register inven_type *i_ptr;
  register struct misc *m_ptr;
  register struct flags *f_ptr;
  free_turn_flag = 1;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(75, 76, &j, &k))
    msg_print("You are not carrying any potions.");
  else if (get_item(&item_val, "Quaff which potion?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      i = i_ptr->flags;
      free_turn_flag = 0;
      ident = 0;
      if (i == 0)
 {
   msg_print ("You feel less thirsty.");
   ident = 1;
 }
      else while (i != 0)
 {
   j = bit_pos(&i) + 1;
   if (i_ptr->tval == 76)
     j += 32;
   switch(j)
     {
     case 1:
       if (inc_stat (0))
  {
    msg_print("Wow!  What bulging muscles!");
    ident = 1;
  }
       break;
     case 2:
       ident = 1;
       lose_str();
       break;
     case 3:
       if (res_stat (0))
  {
    msg_print("You feel warm all over.");
    ident = 1;
  }
       break;
     case 4:
       if (inc_stat (1))
  {
    msg_print("Aren't you brilliant!");
    ident = 1;
  }
       break;
     case 5:
       ident = 1;
       lose_int();
       break;
     case 6:
       if (res_stat (1))
  {
    msg_print("You have have a warm feeling.");
    ident = 1;
  }
       break;
     case 7:
       if (inc_stat (2))
  {
    msg_print("You suddenly have a profound thought!");
    ident = 1;
  }
       break;
     case 8:
       ident = 1;
       lose_wis();
       break;
     case 9:
       if (res_stat (2))
  {
    msg_print("You feel your wisdom returning.");
    ident = 1;
  }
       break;
     case 10:
       if (inc_stat (5))
  {
    msg_print("Gee, ain't you cute!");
    ident = 1;
  }
       break;
     case 11:
       ident = 1;
       lose_chr();
       break;
     case 12:
       if (res_stat (5))
  {
    msg_print("You feel your looks returning.");
    ident = 1;
  }
       break;
     case 13:
       ident = hp_player(damroll(2, 7));
       break;
     case 14:
       ident = hp_player(damroll(4, 7));
       break;
     case 15:
       ident = hp_player(damroll(6, 7));
       break;
     case 16:
       ident = hp_player(1000);
       break;
     case 17:
       if (inc_stat (4))
  {
    msg_print("You feel tingly for a moment.");
    ident = 1;
  }
       break;
     case 18:
       m_ptr = &py.misc;
       if (m_ptr->exp < 9999999L)
  {
    l = (m_ptr->exp / 2) + 10;
    if (l > 100000L) l = 100000L;
    m_ptr->exp += l;
    msg_print("You feel more experienced.");
    prt_experience();
    ident = 1;
  }
       break;
     case 19:
       f_ptr = &py.flags;
       if (!f_ptr->free_act)
  {
    msg_print("You fall asleep.");
    f_ptr->paralysis += randint(4) + 4;
    ident = 1;
  }
       break;
     case 20:
       f_ptr = &py.flags;
       if (f_ptr->blind == 0)
  {
    msg_print("You are covered by a veil of darkness.");
    ident = 1;
  }
       f_ptr->blind += randint(100) + 100;
       break;
     case 21:
       f_ptr = &py.flags;
       if (f_ptr->confused == 0)
  {
    msg_print("Hey!  This is good stuff!  * Hick! *");
    ident = 1;
  }
       f_ptr->confused += randint(20) + 12;
       break;
     case 22:
       f_ptr = &py.flags;
       if (f_ptr->poisoned == 0)
  {
    msg_print("You feel very sick.");
    ident = 1;
  }
       f_ptr->poisoned += randint(15) + 10;
       break;
     case 23:
       if (py.flags.fast == 0)
  ident = 1;
       py.flags.fast += randint(25) + 15;
       break;
     case 24:
       if (py.flags.slow == 0)
  ident = 1;
       py.flags.slow += randint(25) + 15;
       break;
     case 26:
       if (inc_stat (3))
  {
    msg_print("You feel more limber!");
    ident = 1;
  }
       break;
     case 27:
       if (res_stat (3))
  {
    msg_print("You feel less clumsy.");
    ident = 1;
  }
       break;
     case 28:
       if (res_stat (4))
  {
    msg_print("You feel your health returning!");
    ident = 1;
  }
       break;
     case 29:
       ident = cure_blindness();
       break;
     case 30:
       ident = cure_confusion();
       break;
     case 31:
       ident = cure_poison();
       break;
     case 34:
       if (py.misc.exp > 0)
  {
    int32 m, scale;
    msg_print("You feel your memories fade.");
    m = py.misc.exp / 5;
    if (py.misc.exp > 32767)
      {
        scale = 0x7FFFFFFFL / py.misc.exp;
        m += (randint((int)scale) * py.misc.exp) / (scale * 5);
      }
    else
      m += randint((int)py.misc.exp) / 5;
    lose_exp(m);
    ident = 1;
  }
       break;
     case 35:
       f_ptr = &py.flags;
       (void) cure_poison();
       if (f_ptr->food > 150) f_ptr->food = 150;
       f_ptr->paralysis = 4;
       msg_print("The potion makes you vomit!");
       ident = 1;
       break;
     case 36:
       if (py.flags.invuln == 0)
  ident = 1;
       py.flags.invuln += randint(10) + 10;
       break;
     case 37:
       if (py.flags.hero == 0)
  ident = 1;
       py.flags.hero += randint(25) + 25;
       break;
     case 38:
       if (py.flags.shero == 0)
  ident = 1;
       py.flags.shero += randint(25) + 25;
       break;
     case 39:
       ident = remove_fear();
       break;
     case 40:
       ident = restore_level();
       break;
     case 41:
       f_ptr = &py.flags;
       if (f_ptr->resist_heat == 0)
  ident = 1;
       f_ptr->resist_heat += randint(10) + 10;
       break;
     case 42:
       f_ptr = &py.flags;
       if (f_ptr->resist_cold == 0)
  ident = 1;
       f_ptr->resist_cold += randint(10) + 10;
       break;
     case 43:
       if (py.flags.detect_inv == 0)
  ident = 1;
       detect_inv2(randint(12)+12);
       break;
     case 44:
       ident = slow_poison();
       break;
     case 45:
       ident = cure_poison();
       break;
     case 46:
       m_ptr = &py.misc;
       if (m_ptr->cmana < m_ptr->mana)
  {
    m_ptr->cmana = m_ptr->mana;
    ident = 1;
    msg_print("Your feel your head clear.");
    prt_cmana();
  }
       break;
     case 47:
       f_ptr = &py.flags;
       if (f_ptr->tim_infra == 0)
  {
    msg_print("Your eyes begin to tingle.");
    ident = 1;
  }
       f_ptr->tim_infra += 100 + randint(100);
       break;
     default:
       msg_print ("Internal error in potion()");
       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);
      add_food(i_ptr->p1);
      desc_remain(item_val);
      inven_destroy(item_val);
    }
}

canonical_original_code:
void quaff()
{
  unsigned long i; unsigned long l;
  int j; int k; int item_val;
  int ident;
  register struct inven_type *i_ptr;
  register struct misc *m_ptr;
  register struct flags *f_ptr;
  free_turn_flag = 1;
  if (inven_ctr == 0)
    msg_print("But you are not carrying anything.");
  else if (!find_range(75, 76, &j, &k))
    msg_print("You are not carrying any potions.");
  else if (get_item(&item_val, "Quaff which potion?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      i = i_ptr->flags;
      free_turn_flag = 0;
      ident = 0;
      if (i == 0)
 {
   msg_print ("You feel less thirsty.");
   ident = 1;
 }
      else while (i != 0)
 {
   j = bit_pos(&i) + 1;
   if (i_ptr->tval == 76)
     j += 32;
   switch(j)
     {
     case 1:
       if (inc_stat (0))
  {
    msg_print("Wow!  What bulging muscles!");
    ident = 1;
  }
       break;
     case 2:
       ident = 1;
       lose_str();
       break;
     case 3:
       if (res_stat (0))
  {
    msg_print("You feel warm all over.");
    ident = 1;
  }
       break;
     case 4:
       if (inc_stat (1))
  {
    msg_print("Aren't you brilliant!");
    ident = 1;
  }
       break;
     case 5:
       ident = 1;
       lose_int();
       break;
     case 6:
       if (res_stat (1))
  {
    msg_print("You have have a warm feeling.");
    ident = 1;
  }
       break;
     case 7:
       if (inc_stat (2))
  {
    msg_print("You suddenly have a profound thought!");
    ident = 1;
  }
       break;
     case 8:
       ident = 1;
       lose_wis();
       break;
     case 9:
       if (res_stat (2))
  {
    msg_print("You feel your wisdom returning.");
    ident = 1;
  }
       break;
     case 10:
       if (inc_stat (5))
  {
    msg_print("Gee, ain't you cute!");
    ident = 1;
  }
       break;
     case 11:
       ident = 1;
       lose_chr();
       break;
     case 12:
       if (res_stat (5))
  {
    msg_print("You feel your looks returning.");
    ident = 1;
  }
       break;
     case 13:
       ident = hp_player(damroll(2, 7));
       break;
     case 14:
       ident = hp_player(damroll(4, 7));
       break;
     case 15:
       ident = hp_player(damroll(6, 7));
       break;
     case 16:
       ident = hp_player(1000);
       break;
     case 17:
       if (inc_stat (4))
  {
    msg_print("You feel tingly for a moment.");
    ident = 1;
  }
       break;
     case 18:
       m_ptr = &py.misc;
       if (m_ptr->exp < 9999999L)
  {
    l = (m_ptr->exp / 2) + 10;
    if (l > 100000L) l = 100000L;
    m_ptr->exp += l;
    msg_print("You feel more experienced.");
    prt_experience();
    ident = 1;
  }
       break;
     case 19:
       f_ptr = &py.flags;
       if (!f_ptr->free_act)
  {
    msg_print("You fall asleep.");
    f_ptr->paralysis += randint(4) + 4;
    ident = 1;
  }
       break;
     case 20:
       f_ptr = &py.flags;
       if (f_ptr->blind == 0)
  {
    msg_print("You are covered by a veil of darkness.");
    ident = 1;
  }
       f_ptr->blind += randint(100) + 100;
       break;
     case 21:
       f_ptr = &py.flags;
       if (f_ptr->confused == 0)
  {
    msg_print("Hey!  This is good stuff!  * Hick! *");
    ident = 1;
  }
       f_ptr->confused += randint(20) + 12;
       break;
     case 22:
       f_ptr = &py.flags;
       if (f_ptr->poisoned == 0)
  {
    msg_print("You feel very sick.");
    ident = 1;
  }
       f_ptr->poisoned += randint(15) + 10;
       break;
     case 23:
       if (py.flags.fast == 0)
  ident = 1;
       py.flags.fast += randint(25) + 15;
       break;
     case 24:
       if (py.flags.slow == 0)
  ident = 1;
       py.flags.slow += randint(25) + 15;
       break;
     case 26:
       if (inc_stat (3))
  {
    msg_print("You feel more limber!");
    ident = 1;
  }
       break;
     case 27:
       if (res_stat (3))
  {
    msg_print("You feel less clumsy.");
    ident = 1;
  }
       break;
     case 28:
       if (res_stat (4))
  {
    msg_print("You feel your health returning!");
    ident = 1;
  }
       break;
     case 29:
       ident = cure_blindness();
       break;
     case 30:
       ident = cure_confusion();
       break;
     case 31:
       ident = cure_poison();
       break;
     case 34:
       if (py.misc.exp > 0)
  {
    long m; long scale;
    msg_print("You feel your memories fade.");
    m = py.misc.exp / 5;
    if (py.misc.exp > 32767)
      {
        scale = 0x7FFFFFFFL / py.misc.exp;
        m += (randint((int)scale) * py.misc.exp) / (scale * 5);
      }
    else
      m += randint((int)py.misc.exp) / 5;
    lose_exp(m);
    ident = 1;
  }
       break;
     case 35:
       f_ptr = &py.flags;
       (void) cure_poison();
       if (f_ptr->food > 150) f_ptr->food = 150;
       f_ptr->paralysis = 4;
       msg_print("The potion makes you vomit!");
       ident = 1;
       break;
     case 36:
       if (py.flags.invuln == 0)
  ident = 1;
       py.flags.invuln += randint(10) + 10;
       break;
     case 37:
       if (py.flags.hero == 0)
  ident = 1;
       py.flags.hero += randint(25) + 25;
       break;
     case 38:
       if (py.flags.shero == 0)
  ident = 1;
       py.flags.shero += randint(25) + 25;
       break;
     case 39:
       ident = remove_fear();
       break;
     case 40:
       ident = restore_level();
       break;
     case 41:
       f_ptr = &py.flags;
       if (f_ptr->resist_heat == 0)
  ident = 1;
       f_ptr->resist_heat += randint(10) + 10;
       break;
     case 42:
       f_ptr = &py.flags;
       if (f_ptr->resist_cold == 0)
  ident = 1;
       f_ptr->resist_cold += randint(10) + 10;
       break;
     case 43:
       if (py.flags.detect_inv == 0)
  ident = 1;
       detect_inv2(randint(12)+12);
       break;
     case 44:
       ident = slow_poison();
       break;
     case 45:
       ident = cure_poison();
       break;
     case 46:
       m_ptr = &py.misc;
       if (m_ptr->cmana < m_ptr->mana)
  {
    m_ptr->cmana = m_ptr->mana;
    ident = 1;
    msg_print("Your feel your head clear.");
    prt_cmana();
  }
       break;
     case 47:
       f_ptr = &py.flags;
       if (f_ptr->tim_infra == 0)
  {
    msg_print("Your eyes begin to tingle.");
    ident = 1;
  }
       f_ptr->tim_infra += 100 + randint(100);
       break;
     default:
       msg_print ("Internal error in potion()");
       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);
      add_food(i_ptr->p1);
      desc_remain(item_val);
      inven_destroy(item_val);
    }
}

variable_types:
i
unsigned long

variable_types:
l
unsigned long

variable_types: ident int

variable_types: m long

variable_types: scale long

user_defined_types: struct flags { unsigned long status; short rest; short blind; short paralysis; short confused; short food; short food_digested; short protection; short speed; short fast; short slow; short afraid; short poisoned; short image; short protevil; short invuln; short hero; short shero; short blessed; short resist_heat; short resist_cold; short detect_inv; short word_recall; short see_infra; short tim_infra; unsigned char see_inv; unsigned char teleport; unsigned char free_act; unsigned char slow_digest; unsigned char aggravate; unsigned char fire_resist; unsigned char cold_resist; unsigned char acid_resist; unsigned char regenerate; unsigned char lght_resist; unsigned char ffall; unsigned char sustain_str; unsigned char sustain_int; unsigned char sustain_wis; unsigned char sustain_con; unsigned char sustain_dex; unsigned char sustain_chr; unsigned char confuse_monster; unsigned char new_spells; }


moriaterm

decompiled_code:
int moriaterm()
{
curses_on = 1;
cbreak();
return noecho();
}

canonical_decompiled_code:
int func0()
{
curses_on = 1;
cbreak();
return noecho();
}

original_code:
void moriaterm()
{
  curses_on = 1;
  cbreak();
  noecho();
}


decompiled_code:
int init_curses()
{
if ( !initscr() )
{
puts("Error allocating screen in curses package.");
exit(1);
}
if ( LINES <= 23 || COLS <= 79 )
{
puts("Screen too small for moria.");
exit(1);
}
wclear(stdscr);
wrefresh(stdscr);
return moriaterm();
}

canonical_decompiled_code:
int func1()
{
if ( !initscr() )
{
puts("Error allocating screen in curses package.");
exit(1);
}
if ( LINES <= 23 || COLS <= 79 )
{
puts("Screen too small for moria.");
exit(1);
}
wclear(stdscr);
wrefresh(stdscr);
return func0();
}

original_code:
void init_curses()
{
  if (initscr() == ((void *)0))
    {
      (void) printf("Error allocating screen in curses package.\n");
      exit(1);
    }
  if (LINES < 24 || COLS < 80)
    {
      (void) printf("Screen too small for moria.\n");
      exit (1);
    }
  (void) wclear(stdscr);
  (void) wrefresh(stdscr);
  moriaterm ();
}


decompiled_code:
int put_qio()
{
screen_change = 1;
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func3()
{
screen_change = 1;
return wrefresh(stdscr);
}

original_code:
void put_qio()
{
  screen_change = 1;
  (void) wrefresh(stdscr);
}


decompiled_code:
int restore_term()
{
int result; // eax

result = curses_on;
if ( curses_on )
{
put_qio();
mvcur(stdscr->_cury, stdscr->_curx, LINES - 1, 0);
endwin();
result = fflush(stdout);
curses_on = 0;
}
return result;
}

canonical_decompiled_code:
int func4()
{
int result; // eax

result = curses_on;
if ( curses_on )
{
func3();
mvcur(stdscr->_cury, stdscr->_curx, LINES - 1, 0);
endwin();
result = fflush(stdout);
curses_on = 0;
}
return result;
}

original_code:
void restore_term()
{
  if (!curses_on)
    return;
  put_qio();
  mvcur(stdscr->_cury, stdscr->_curx, LINES-1, 0);
  endwin();
  (void) fflush (stdout);
  curses_on = 0;
}


inkey

decompiled_code:
int inkey()
{
int result; // eax
__m128i v1; // xmm0

put_qio();
command_count = 0;
while ( 1 )
{
result = wgetch(stdscr);
if ( result == -1 )
break;
if ( result != 18 )
return result;
wrefresh(curscr);
moriaterm();
}
++eof_flag;
msg_flag = 0;
wrefresh(stdscr);
if ( !character_generated || character_saved )
exit_game();
disturb(1LL, 0LL);
result = 27;
if ( eof_flag > 100 )
{
v1 = _mm_load_si128((const __m128i *)&LC3);
*((_DWORD *)&died_from + 6) = 2712677;
*((_QWORD *)&died_from + 2) = 0x7661732063696E61LL;
died_from = v1;
if ( !(unsigned int)save_char() )
{
strcpy((char *)&died_from + 16, "d eof");
death = 1;
died_from = _mm_load_si128((const __m128i *)&LC4);
}
exit_game();
result = 27;
}
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax
__m128i v1; // xmm0

func3();
command_count = 0;
while ( 1 )
{
result = wgetch(stdscr);
if ( result == -1 )
break;
if ( result != 18 )
return result;
wrefresh(curscr);
func0();
}
++eof_flag;
msg_flag = 0;
wrefresh(stdscr);
if ( !character_generated || character_saved )
exit_game();
disturb(1LL, 0LL);
result = 27;
if ( eof_flag > 100 )
{
v1 = _mm_load_si128((const __m128i *)&LC3);
*((_DWORD *)&died_from + 6) = 2712677;
*((_QWORD *)&died_from + 2) = 0x7661732063696E61LL;
died_from = v1;
if ( !(unsigned int)save_char() )
{
strcpy((char *)&died_from + 16, "d eof");
death = 1;
died_from = _mm_load_si128((const __m128i *)&LC4);
}
exit_game();
result = 27;
}
return result;
}

original_code:
char inkey()
{
  int i;
  put_qio();
  command_count = 0;
  while (1)
    {
      i = wgetch(stdscr);
      if (i == (-1))
 {
   eof_flag++;
   msg_flag = 0;
   (void) wrefresh(stdscr);
   if (!character_generated || character_saved)
     exit_game();
   disturb(1, 0);
   if (eof_flag > 100)
     {
       panic_save = 1;
       (void) strcpy(died_from, "(end of input: panic saved)");
       if (!save_char())
  {
    (void) strcpy(died_from, "panic: unexpected eof");
    death = 1;
  }
       exit_game();
     }
   return '\033';
 }
      if (i != ('R' & 0x1F))
 return (char)i;
      (void) wrefresh (curscr);
      moriaterm();
    }
}

return_type: char


flush

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

result = eof_flag;
if ( !eof_flag )
{
do
result = check_input(0LL);
while ( (_DWORD)result );
}
return result;
}

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

result = eof_flag;
if ( !eof_flag )
{
do
result = check_input(0LL);
while ( (_DWORD)result );
}
return result;
}

original_code:
void flush()
{
  if (!eof_flag)
    while (check_input(0));
}


decompiled_code:
int clear_screen()
{
if ( msg_flag )
msg_print(0LL);
return wclear(stdscr);
}

canonical_decompiled_code:
int func13()
{
if ( msg_flag )
func11(0LL);
return wclear(stdscr);
}

original_code:
void clear_screen()
{
  if (msg_flag)
    msg_print((char *)0);
  (void) wclear(stdscr);
}


decompiled_code:
int save_screen()
{
return overwrite(stdscr, 0LL);
}

canonical_decompiled_code:
int func20()
{
return overwrite(stdscr, 0LL);
}

original_code:
void save_screen()
{
  overwrite(stdscr, savescr);
}


decompiled_code:
int restore_screen()
{
int v0; // edx

overwrite(0LL, stdscr);
v0 = -1;
if ( stdscr )
v0 = stdscr->_maxy + 1;
return wtouchln(stdscr, 0, v0, 1);
}

canonical_decompiled_code:
int func21()
{
int v0; // edx

overwrite(0LL, stdscr);
v0 = -1;
if ( stdscr )
v0 = stdscr->_maxy + 1;
return wtouchln(stdscr, 0, v0, 1);
}

original_code:
void restore_screen()
{
  overwrite(savescr, stdscr);
  wtouchln((stdscr), 0, ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), 1);
}

canonical_original_code:
void restore_screen()
{
  overwrite(savescr, stdscr);
  wtouchln((stdscr), 0, ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), 1);
}


bell

decompiled_code:
ssize_t bell()
{
ssize_t result; // rax

put_qio();
result = sound_beep_flag;
if ( sound_beep_flag )
result = write(1, "\a", 1uLL);
return result;
}

canonical_decompiled_code:
ssize_t func22()
{
ssize_t result; // rax

func3();
result = sound_beep_flag;
if ( sound_beep_flag )
result = write(1, "\a", 1uLL);
return result;
}

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


original_code:
void screen_map()
{
  register int i, j;
  static int8u screen_border[2][6] = {
    {'+', '+', '+', '+', '-', '|'},
    {201, 187, 200, 188, 205, 186}
  };
  int8u map[198 / 3 + 1];
  int8u tmp;
  int priority[256];
  int row, orow, col, myrow, mycol = 0;
  char prntscrnbuf[80];
  for (i = 0; i < 256; i++)
    priority[i] = 0;
  priority['<'] = 5;
  priority['>'] = 5;
  priority['@'] = 10;
  priority['#'] = -5;
  priority['.'] = -10;
  priority['\''] = -3;
  priority[' '] = -15;
  save_screen();
  clear_screen();
  (wmove((stdscr),((0)),((0))) == (-1) ? (-1) : waddch((stdscr),(((screen_border[0][0])))));
  for (i = 0; i < 198 / 3; i++)
    (void) waddch(stdscr,((screen_border[0][4])));
  (void) waddch(stdscr,((screen_border[0][1])));
  orow = -1;
  map[198 / 3] = '\0';
  for (i = 0; i < 66; i++)
    {
      row = i / 3;
      if (row != orow)
 {
   if (orow >= 0)
     {
       (void) sprintf(prntscrnbuf,"%c%s%c",(screen_border[0][5]), map, (screen_border[0][5]));
       (wmove((stdscr),((orow+1)),((0))) == (-1) ? (-1) : waddnstr((stdscr),((prntscrnbuf)),-1));
     }
   for (j = 0; j < 198 / 3; j++)
     map[j] = ' ';
   orow = row;
 }
      for (j = 0; j < 198; j++)
 {
   col = j / 3;
   tmp = loc_symbol(i, j);
   if (priority[map[col]] < priority[tmp])
     map[col] = tmp;
   if (map[col] == '@')
     {
       mycol = col + 1;
       myrow = row + 1;
     }
 }
    }
  if (orow >= 0)
    {
      (void) sprintf(prntscrnbuf,"%c%s%c",(screen_border[0][5]), map, (screen_border[0][5]));
      (wmove((stdscr),((orow+1)),((0))) == (-1) ? (-1) : waddnstr((stdscr),((prntscrnbuf)),-1));
    }
  (wmove((stdscr),((orow + 2)),((0))) == (-1) ? (-1) : waddch((stdscr),(((screen_border[0][2])))));
  for (i = 0; i < 198 / 3; i++)
    (void) waddch(stdscr,((screen_border[0][4])));
  (void) waddch(stdscr,((screen_border[0][3])));
  (wmove((stdscr),((23)),((23))) == (-1) ? (-1) : waddnstr((stdscr),(("Hit any key to continue")),-1));
  if (mycol > 0)
    (void) wmove(stdscr,(myrow),(mycol));
  (void) inkey();
  restore_screen();
}

canonical_original_code:
void screen_map()
{
  register int i; register int j;
  static unsigned char screen_border[2][6] = {
    {'+', '+', '+', '+', '-', '|'},
    {201, 187, 200, 188, 205, 186}
  };
  unsigned char map[-1];
  unsigned char tmp;
  int priority[256];
  int row; int orow; int col; int myrow; int mycol = 0;
  char prntscrnbuf[80];
  for (i = 0; i < 256; i++)
    priority[i] = 0;
  priority['<'] = 5;
  priority['>'] = 5;
  priority['@'] = 10;
  priority['#'] = -5;
  priority['.'] = -10;
  priority['\''] = -3;
  priority[' '] = -15;
  save_screen();
  clear_screen();
  (wmove((stdscr),((0)),((0))) == (-1) ? (-1) : waddch((stdscr),(((screen_border[0][0])))));
  for (i = 0; i < 198 / 3; i++)
    (void) waddch(stdscr,((screen_border[0][4])));
  (void) waddch(stdscr,((screen_border[0][1])));
  orow = -1;
  map[198 / 3] = '\0';
  for (i = 0; i < 66; i++)
    {
      row = i / 3;
      if (row != orow)
 {
   if (orow >= 0)
     {
       (void) sprintf(prntscrnbuf,"%c%s%c",(screen_border[0][5]), map, (screen_border[0][5]));
       (wmove((stdscr),((orow+1)),((0))) == (-1) ? (-1) : waddnstr((stdscr),((prntscrnbuf)),-1));
     }
   for (j = 0; j < 198 / 3; j++)
     map[j] = ' ';
   orow = row;
 }
      for (j = 0; j < 198; j++)
 {
   col = j / 3;
   tmp = loc_symbol(i, j);
   if (priority[map[col]] < priority[tmp])
     map[col] = tmp;
   if (map[col] == '@')
     {
       mycol = col + 1;
       myrow = row + 1;
     }
 }
    }
  if (orow >= 0)
    {
      (void) sprintf(prntscrnbuf,"%c%s%c",(screen_border[0][5]), map, (screen_border[0][5]));
      (wmove((stdscr),((orow+1)),((0))) == (-1) ? (-1) : waddnstr((stdscr),((prntscrnbuf)),-1));
    }
  (wmove((stdscr),((orow + 2)),((0))) == (-1) ? (-1) : waddch((stdscr),(((screen_border[0][2])))));
  for (i = 0; i < 198 / 3; i++)
    (void) waddch(stdscr,((screen_border[0][4])));
  (void) waddch(stdscr,((screen_border[0][3])));
  (wmove((stdscr),((23)),((23))) == (-1) ? (-1) : waddnstr((stdscr),(("Hit any key to continue")),-1));
  if (mycol > 0)
    (void) wmove(stdscr,(myrow),(mycol));
  (void) inkey();
  restore_screen();
}

variable_types:
map
unsigned char [-1]

variable_types:
tmp
unsigned char

variable_types:
priority
int [256]

variable_types: row int

variable_types: orow int

variable_types: col int

variable_types: myrow int

variable_types: mycol int

variable_types:
prntscrnbuf
char [80]