cast

decompiled_code:
__int64 cast()
{
bool v0; // cc
__int64 result; // rax
const char *v2; // rdi
int v3; // ebx
__int64 v4; // rbp
int v5; // ebx
__int64 v6; // rbp
int v7; // eax
int v8; // esi
__int16 v9; // ax
__int64 v10; // r12
unsigned int v11; // eax
unsigned int v12; // eax
__int64 i; // rax
__int64 v14; // r12
unsigned int v15; // eax
__int64 v16; // r12
unsigned int v17; // eax
__int64 v18; // r12
unsigned int v19; // eax
unsigned int v20; // [rsp+0h] [rbp-30h] BYREF
unsigned int v21; // [rsp+4h] [rbp-2Ch] BYREF
unsigned int v22; // [rsp+8h] [rbp-28h] BYREF
unsigned int v23; // [rsp+Ch] [rbp-24h] BYREF
int v24; // [rsp+10h] [rbp-20h] BYREF
int v25[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 spell book!");
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);
if ( class[32 * *((unsigned __int8 *)&py + 104) + 28] != 1 )
{
v2 = "You can't cast spells!";
return msg_print(v2);
}
if ( !(unsigned int)find_range(90LL, 0xFFFFFFFFLL, &v20, &v21) )
return msg_print("But you are not carrying any spell-books!");
result = get_item(&v22, "Use which spell-book?", v20, v21, 0LL, 0LL);
if ( (_DWORD)result )
{
result = cast_spell("Cast which spell?", v22, &v24, v25);
if ( (int)result < 0 )
return msg_print("You don't know any spells in that book.");
if ( (_DWORD)result )
{
v3 = *((unsigned __int8 *)&py + 104);
free_turn_flag = 0;
v4 = v24;
v5 = v3 - 1;
if ( (int)randint(100LL) < v25[0] )
{
result = msg_print("You failed to get the spell off!");
goto LABEL_24;
}
switch ( v24 )
{
case 0:
if ( (unsigned int)get_dir(0LL, &v23) )
{
v10 = spell_names[0];
v11 = damroll(2LL, 6LL);
fire_bolt(0LL, v23, (unsigned int)char_row, (unsigned int)char_col, v11, v10);
}
break;
case 1:
detect_monsters();
break;
case 2:
teleport(10LL);
break;
case 3:
light_area((unsigned int)char_row, (unsigned int)char_col);
break;
case 4:
v12 = damroll(4LL, 4LL);
hp_player(v12);
break;
case 5:
detect_sdoor();
detect_trap();
break;
case 6:
if ( (unsigned int)get_dir(0LL, &v23) )
fire_ball(2LL, v23, (unsigned int)char_row, (unsigned int)char_col, 12LL, spell_names[6]);
break;
case 7:
if ( (unsigned int)get_dir(0LL, &v23) )
confuse_monster(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 8:
if ( (unsigned int)get_dir(0LL, &v23) )
{
v14 = spell_names[8];
v15 = damroll(4LL, 8LL);
fire_bolt(1LL, v23, (unsigned int)char_row, (unsigned int)char_col, v15, v14);
}
break;
case 9:
td_destroy();
break;
case 10:
if ( (unsigned int)get_dir(0LL, &v23) )
sleep_monster(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 11:
cure_poison();
break;
case 12:
teleport(5 * (unsigned int)*((unsigned __int16 *)&py + 32));
break;
case 13:
for ( i = 0LL; i != 672; i += 56LL )
*(_QWORD *)((char *)&inventory + i + 1248) &= 0xFFFFFFFF7FFFFFFFLL;
v20 = 34;
break;
case 14:
if ( (unsigned int)get_dir(0LL, &v23) )
{
v18 = spell_names[14];
v19 = damroll(6LL, 8LL);
fire_bolt(4LL, v23, (unsigned int)char_row, (unsigned int)char_col, v19, v18);
}
break;
case 15:
if ( (unsigned int)get_dir(0LL, &v23) )
wall_to_mud(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 16:
create_food();
break;
case 17:
recharge(20LL);
break;
case 18:
sleep_monsters1((unsigned int)char_row, (unsigned int)char_col);
break;
case 19:
if ( (unsigned int)get_dir(0LL, &v23) )
poly_monster(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 20:
ident_spell();
break;
case 21:
sleep_monsters2();
break;
case 22:
if ( (unsigned int)get_dir(0LL, &v23) )
{
v16 = spell_names[22];
v17 = damroll(9LL, 8LL);
fire_bolt(5LL, v23, (unsigned int)char_row, (unsigned int)char_col, v17, v16);
}
break;
case 23:
if ( (unsigned int)get_dir(0LL, &v23) )
speed_monster(v23, (unsigned int)char_row, (unsigned int)char_col, 0xFFFFFFFFLL);
break;
case 24:
if ( (unsigned int)get_dir(0LL, &v23) )
fire_ball(4LL, v23, (unsigned int)char_row, (unsigned int)char_col, 48LL, spell_names[24]);
break;
case 25:
recharge(60LL);
break;
case 26:
if ( (unsigned int)get_dir(0LL, &v23) )
teleport_monster(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 27:
*((_WORD *)&py + 208) += randint(20LL) + *((_WORD *)&py + 32);
break;
case 28:
if ( (unsigned int)get_dir(0LL, &v23) )
fire_ball(5LL, v23, (unsigned int)char_row, (unsigned int)char_col, 72LL, spell_names[28]);
break;
case 29:
destroy_area((unsigned int)char_row, (unsigned int)char_col);
break;
case 30:
genocide();
break;
default:
break;
}
result = free_turn_flag;
if ( !free_turn_flag )
{
if ( (spell_worked & (1LL << v24)) != 0 )
{
LABEL_20:
v6 = 31LL * v5 + v4;
v7 = *((__int16 *)&py + 54);
v8 = *((unsigned __int8 *)&magic_spell + 4 * v6 + 1);
if ( v8 > v7 )
{
msg_print("You faint from the effort!");
v9 = randint(5 * ((unsigned int)*((unsigned __int8 *)&magic_spell + 4 * v6 + 1) - *((__int16 *)&py + 54)));
*((_DWORD *)&py + 27) = 0;
*((_WORD *)&py + 202) = v9;
if ( (unsigned int)randint(3LL) == 1 )
{
msg_print("You have damaged your health!");
dec_stat(4LL);
}
}
else
{
*((_WORD *)&py + 54) = v7 - v8;
}
return prt_cmana();
}
spell_worked |= 1LL << v24;
*((_QWORD *)&py + 6) += 4 * *((unsigned __int8 *)&magic_spell + 124 * v5 + 4 * (int)v4 + 3);
result = prt_experience();
LABEL_24:
if ( free_turn_flag )
return result;
goto LABEL_20;
}
}
}
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; // rbp
int v7; // eax
int v8; // esi
__int16 v9; // ax
__int64 v10; // r12
unsigned int v11; // eax
unsigned int v12; // eax
__int64 i; // rax
__int64 v14; // r12
unsigned int v15; // eax
__int64 v16; // r12
unsigned int v17; // eax
__int64 v18; // r12
unsigned int v19; // eax
unsigned int v20; // [rsp+0h] [rbp-30h] BYREF
unsigned int v21; // [rsp+4h] [rbp-2Ch] BYREF
unsigned int v22; // [rsp+8h] [rbp-28h] BYREF
unsigned int v23; // [rsp+Ch] [rbp-24h] BYREF
int v24; // [rsp+10h] [rbp-20h] BYREF
int v25[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 spell book!");
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);
if ( class[32 * *((unsigned __int8 *)&py + 104) + 28] != 1 )
{
v2 = "You can't cast spells!";
return msg_print(v2);
}
if ( !(unsigned int)find_range(90LL, 0xFFFFFFFFLL, &v20, &v21) )
return msg_print("But you are not carrying any spell-books!");
result = get_item(&v22, "Use which spell-book?", v20, v21, 0LL, 0LL);
if ( (_DWORD)result )
{
result = cast_spell("Cast which spell?", v22, &v24, v25);
if ( (int)result < 0 )
return msg_print("You don't know any spells in that book.");
if ( (_DWORD)result )
{
v3 = *((unsigned __int8 *)&py + 104);
free_turn_flag = 0;
v4 = v24;
v5 = v3 - 1;
if ( (int)randint(100LL) < v25[0] )
{
result = msg_print("You failed to get the spell off!");
goto LABEL_24;
}
switch ( v24 )
{
case 0:
if ( (unsigned int)get_dir(0LL, &v23) )
{
v10 = spell_names[0];
v11 = damroll(2LL, 6LL);
fire_bolt(0LL, v23, (unsigned int)char_row, (unsigned int)char_col, v11, v10);
}
break;
case 1:
detect_monsters();
break;
case 2:
teleport(10LL);
break;
case 3:
light_area((unsigned int)char_row, (unsigned int)char_col);
break;
case 4:
v12 = damroll(4LL, 4LL);
hp_player(v12);
break;
case 5:
detect_sdoor();
detect_trap();
break;
case 6:
if ( (unsigned int)get_dir(0LL, &v23) )
fire_ball(2LL, v23, (unsigned int)char_row, (unsigned int)char_col, 12LL, spell_names[6]);
break;
case 7:
if ( (unsigned int)get_dir(0LL, &v23) )
confuse_monster(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 8:
if ( (unsigned int)get_dir(0LL, &v23) )
{
v14 = spell_names[8];
v15 = damroll(4LL, 8LL);
fire_bolt(1LL, v23, (unsigned int)char_row, (unsigned int)char_col, v15, v14);
}
break;
case 9:
td_destroy();
break;
case 10:
if ( (unsigned int)get_dir(0LL, &v23) )
sleep_monster(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 11:
cure_poison();
break;
case 12:
teleport(5 * (unsigned int)*((unsigned __int16 *)&py + 32));
break;
case 13:
for ( i = 0LL; i != 672; i += 56LL )
*(_QWORD *)((char *)&inventory + i + 1248) &= 0xFFFFFFFF7FFFFFFFLL;
v20 = 34;
break;
case 14:
if ( (unsigned int)get_dir(0LL, &v23) )
{
v18 = spell_names[14];
v19 = damroll(6LL, 8LL);
fire_bolt(4LL, v23, (unsigned int)char_row, (unsigned int)char_col, v19, v18);
}
break;
case 15:
if ( (unsigned int)get_dir(0LL, &v23) )
wall_to_mud(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 16:
create_food();
break;
case 17:
recharge(20LL);
break;
case 18:
sleep_monsters1((unsigned int)char_row, (unsigned int)char_col);
break;
case 19:
if ( (unsigned int)get_dir(0LL, &v23) )
poly_monster(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 20:
ident_spell();
break;
case 21:
sleep_monsters2();
break;
case 22:
if ( (unsigned int)get_dir(0LL, &v23) )
{
v16 = spell_names[22];
v17 = damroll(9LL, 8LL);
fire_bolt(5LL, v23, (unsigned int)char_row, (unsigned int)char_col, v17, v16);
}
break;
case 23:
if ( (unsigned int)get_dir(0LL, &v23) )
speed_monster(v23, (unsigned int)char_row, (unsigned int)char_col, 0xFFFFFFFFLL);
break;
case 24:
if ( (unsigned int)get_dir(0LL, &v23) )
fire_ball(4LL, v23, (unsigned int)char_row, (unsigned int)char_col, 48LL, spell_names[24]);
break;
case 25:
recharge(60LL);
break;
case 26:
if ( (unsigned int)get_dir(0LL, &v23) )
teleport_monster(v23, (unsigned int)char_row, (unsigned int)char_col);
break;
case 27:
*((_WORD *)&py + 208) += randint(20LL) + *((_WORD *)&py + 32);
break;
case 28:
if ( (unsigned int)get_dir(0LL, &v23) )
fire_ball(5LL, v23, (unsigned int)char_row, (unsigned int)char_col, 72LL, spell_names[28]);
break;
case 29:
destroy_area((unsigned int)char_row, (unsigned int)char_col);
break;
case 30:
genocide();
break;
default:
break;
}
result = free_turn_flag;
if ( !free_turn_flag )
{
if ( (spell_worked & (1LL << v24)) != 0 )
{
LABEL_20:
v6 = 31LL * v5 + v4;
v7 = *((__int16 *)&py + 54);
v8 = *((unsigned __int8 *)&magic_spell + 4 * v6 + 1);
if ( v8 > v7 )
{
msg_print("You faint from the effort!");
v9 = randint(5 * ((unsigned int)*((unsigned __int8 *)&magic_spell + 4 * v6 + 1) - *((__int16 *)&py + 54)));
*((_DWORD *)&py + 27) = 0;
*((_WORD *)&py + 202) = v9;
if ( (unsigned int)randint(3LL) == 1 )
{
msg_print("You have damaged your health!");
dec_stat(4LL);
}
}
else
{
*((_WORD *)&py + 54) = v7 - v8;
}
return prt_cmana();
}
spell_worked |= 1LL << v24;
*((_QWORD *)&py + 6) += 4 * *((unsigned __int8 *)&magic_spell + 124 * v5 + 4 * (int)v4 + 3);
result = prt_experience();
LABEL_24:
if ( free_turn_flag )
return result;
goto LABEL_20;
}
}
}
return result;
}

original_code:
void cast()
{
  int i, j, item_val, dir;
  int choice, chance, result;
  register struct flags *f_ptr;
  register struct misc *p_ptr;
  register inven_type *i_ptr;
  register spell_type *m_ptr;
  free_turn_flag = 1;
  if (py.flags.blind > 0)
    msg_print("You can't see to read your spell book!");
  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 != 1)
    msg_print("You can't cast spells!");
  else if (!find_range(90, -1, &i, &j))
    msg_print("But you are not carrying any spell-books!");
  else if (get_item(&item_val, "Use which spell-book?", i, j, (char *)0, (char *)0))
    {
      result = cast_spell("Cast which spell?", item_val, &choice, &chance);
      if (result < 0)
 msg_print("You don't know any spells in that book.");
      else if (result > 0)
 {
   m_ptr = &magic_spell[py.misc.pclass-1][choice];
   free_turn_flag = 0;
   if (randint(100) < chance)
     msg_print("You failed to get the spell off!");
   else
     {
       switch(choice+1)
  {
  case 1:
    if (get_dir((char *)0, &dir))
      fire_bolt(0, dir, char_row, char_col,
         damroll(2, 6), spell_names[0]);
    break;
  case 2:
    (void) detect_monsters();
    break;
  case 3:
    teleport(10);
    break;
  case 4:
    (void) light_area(char_row, char_col);
    break;
  case 5:
    (void) hp_player(damroll(4, 4));
    break;
  case 6:
    (void) detect_sdoor();
    (void) detect_trap();
    break;
  case 7:
    if (get_dir((char *)0, &dir))
      fire_ball(2, dir, char_row, char_col, 12,
         spell_names[6]);
    break;
  case 8:
    if (get_dir((char *)0, &dir))
      (void) confuse_monster(dir, char_row, char_col);
    break;
  case 9:
    if (get_dir((char *)0, &dir))
      fire_bolt(1, dir, char_row, char_col,
         damroll(4, 8), spell_names[8]);
    break;
  case 10:
    (void) td_destroy();
    break;
  case 11:
    if (get_dir((char *)0, &dir))
      (void) sleep_monster(dir, char_row, char_col);
    break;
  case 12:
    (void) cure_poison();
    break;
  case 13:
    teleport((int)(py.misc.lev*5));
    break;
  case 14:
    for (i = 22; i < 34; i++)
      {
        i_ptr = &inventory[i];
        i_ptr->flags = (i_ptr->flags & ~0x80000000L);
      }
    break;
  case 15:
    if (get_dir((char *)0, &dir))
      fire_bolt(4, dir, char_row, char_col,
         damroll(6, 8), spell_names[14]);
    break;
  case 16:
    if (get_dir((char *)0, &dir))
      (void) wall_to_mud(dir, char_row, char_col);
    break;
  case 17:
    create_food();
    break;
  case 18:
    (void) recharge(20);
    break;
  case 19:
    (void) sleep_monsters1(char_row, char_col);
    break;
  case 20:
    if (get_dir((char *)0, &dir))
      (void) poly_monster(dir, char_row, char_col);
    break;
  case 21:
    (void) ident_spell();
    break;
  case 22:
    (void) sleep_monsters2();
    break;
  case 23:
    if (get_dir((char *)0, &dir))
      fire_bolt(5, dir, char_row, char_col,
         damroll(9, 8), spell_names[22]);
    break;
  case 24:
    if (get_dir((char *)0, &dir))
      (void)speed_monster(dir, char_row, char_col, -1);
    break;
  case 25:
    if (get_dir((char *)0, &dir))
      fire_ball(4, dir, char_row, char_col, 48,
         spell_names[24]);
    break;
  case 26:
    (void) recharge(60);
    break;
  case 27:
    if (get_dir((char *)0, &dir))
      (void) teleport_monster(dir, char_row, char_col);
    break;
  case 28:
    f_ptr = &py.flags;
    f_ptr->fast += randint(20) + py.misc.lev;
    break;
  case 29:
    if (get_dir((char *)0, &dir))
      fire_ball(5, dir, char_row, char_col, 72,
         spell_names[28]);
    break;
  case 30:
    destroy_area(char_row, char_col);
    break;
  case 31:
    (void) genocide();
    break;
  default:
    break;
  }
       if (!free_turn_flag)
  {
    p_ptr = &py.misc;
    if ((spell_worked & (1L << choice)) == 0)
      {
        p_ptr->exp += m_ptr->sexp << 2;
        spell_worked |= (1L << choice);
        prt_experience();
      }
  }
     }
   p_ptr = &py.misc;
   if (!free_turn_flag)
     {
       if (m_ptr->smana > p_ptr->cmana)
  {
    msg_print("You faint from the effort!");
    py.flags.paralysis =
      randint((int)(5*(m_ptr->smana-p_ptr->cmana)));
    p_ptr->cmana = 0;
    p_ptr->cmana_frac = 0;
    if (randint(3) == 1)
      {
        msg_print("You have damaged your health!");
        (void) dec_stat (4);
      }
  }
       else
  p_ptr->cmana -= m_ptr->smana;
       prt_cmana();
     }
 }
    }
}

canonical_original_code:
void cast()
{
  int i; int j; int item_val; int dir;
  int choice; int chance; int result;
  register struct flags *f_ptr;
  register struct misc *p_ptr;
  register struct inven_type *i_ptr;
  register struct spell_type *m_ptr;
  free_turn_flag = 1;
  if (py.flags.blind > 0)
    msg_print("You can't see to read your spell book!");
  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 != 1)
    msg_print("You can't cast spells!");
  else if (!find_range(90, -1, &i, &j))
    msg_print("But you are not carrying any spell-books!");
  else if (get_item(&item_val, "Use which spell-book?", i, j, (char *)0, (char *)0))
    {
      result = cast_spell("Cast which spell?", item_val, &choice, &chance);
      if (result < 0)
 msg_print("You don't know any spells in that book.");
      else if (result > 0)
 {
   m_ptr = &magic_spell[py.misc.pclass-1][choice];
   free_turn_flag = 0;
   if (randint(100) < chance)
     msg_print("You failed to get the spell off!");
   else
     {
       switch(choice+1)
  {
  case 1:
    if (get_dir((char *)0, &dir))
      fire_bolt(0, dir, char_row, char_col,
         damroll(2, 6), spell_names[0]);
    break;
  case 2:
    (void) detect_monsters();
    break;
  case 3:
    teleport(10);
    break;
  case 4:
    (void) light_area(char_row, char_col);
    break;
  case 5:
    (void) hp_player(damroll(4, 4));
    break;
  case 6:
    (void) detect_sdoor();
    (void) detect_trap();
    break;
  case 7:
    if (get_dir((char *)0, &dir))
      fire_ball(2, dir, char_row, char_col, 12,
         spell_names[6]);
    break;
  case 8:
    if (get_dir((char *)0, &dir))
      (void) confuse_monster(dir, char_row, char_col);
    break;
  case 9:
    if (get_dir((char *)0, &dir))
      fire_bolt(1, dir, char_row, char_col,
         damroll(4, 8), spell_names[8]);
    break;
  case 10:
    (void) td_destroy();
    break;
  case 11:
    if (get_dir((char *)0, &dir))
      (void) sleep_monster(dir, char_row, char_col);
    break;
  case 12:
    (void) cure_poison();
    break;
  case 13:
    teleport((int)(py.misc.lev*5));
    break;
  case 14:
    for (i = 22; i < 34; i++)
      {
        i_ptr = &inventory[i];
        i_ptr->flags = (i_ptr->flags & ~0x80000000L);
      }
    break;
  case 15:
    if (get_dir((char *)0, &dir))
      fire_bolt(4, dir, char_row, char_col,
         damroll(6, 8), spell_names[14]);
    break;
  case 16:
    if (get_dir((char *)0, &dir))
      (void) wall_to_mud(dir, char_row, char_col);
    break;
  case 17:
    create_food();
    break;
  case 18:
    (void) recharge(20);
    break;
  case 19:
    (void) sleep_monsters1(char_row, char_col);
    break;
  case 20:
    if (get_dir((char *)0, &dir))
      (void) poly_monster(dir, char_row, char_col);
    break;
  case 21:
    (void) ident_spell();
    break;
  case 22:
    (void) sleep_monsters2();
    break;
  case 23:
    if (get_dir((char *)0, &dir))
      fire_bolt(5, dir, char_row, char_col,
         damroll(9, 8), spell_names[22]);
    break;
  case 24:
    if (get_dir((char *)0, &dir))
      (void)speed_monster(dir, char_row, char_col, -1);
    break;
  case 25:
    if (get_dir((char *)0, &dir))
      fire_ball(4, dir, char_row, char_col, 48,
         spell_names[24]);
    break;
  case 26:
    (void) recharge(60);
    break;
  case 27:
    if (get_dir((char *)0, &dir))
      (void) teleport_monster(dir, char_row, char_col);
    break;
  case 28:
    f_ptr = &py.flags;
    f_ptr->fast += randint(20) + py.misc.lev;
    break;
  case 29:
    if (get_dir((char *)0, &dir))
      fire_ball(5, dir, char_row, char_col, 72,
         spell_names[28]);
    break;
  case 30:
    destroy_area(char_row, char_col);
    break;
  case 31:
    (void) genocide();
    break;
  default:
    break;
  }
       if (!free_turn_flag)
  {
    p_ptr = &py.misc;
    if ((spell_worked & (1L << choice)) == 0)
      {
        p_ptr->exp += m_ptr->sexp << 2;
        spell_worked |= (1L << choice);
        prt_experience();
      }
  }
     }
   p_ptr = &py.misc;
   if (!free_turn_flag)
     {
       if (m_ptr->smana > p_ptr->cmana)
  {
    msg_print("You faint from the effort!");
    py.flags.paralysis =
      randint((int)(5*(m_ptr->smana-p_ptr->cmana)));
    p_ptr->cmana = 0;
    p_ptr->cmana_frac = 0;
    if (randint(3) == 1)
      {
        msg_print("You have damaged your health!");
        (void) dec_stat (4);
      }
  }
       else
  p_ptr->cmana -= m_ptr->smana;
       prt_cmana();
     }
 }
    }
}

variable_types: i int

variable_types: j int

variable_types: dir int

variable_types: choice int

variable_types: chance int

variable_types: result int

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

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 spell_type { unsigned char slevel; unsigned char smana; unsigned char sfail; unsigned char sexp; } *


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

decompiled_code:
__int64 read_scroll()
{
bool v0; // cc
__int64 result; // rax
const char *v2; // rdi
__int64 v3; // rsi
unsigned __int64 v4; // rbp
int v5; // ebx
int v6; // er12
int v7; // eax
bool v8; // zf
int v9; // er13
char *v10; // rbp
int v11; // eax
int v12; // eax
__int64 v13; // rdi
unsigned int v14; // eax
__int16 v15; // bx
__int16 v16; // bx
__int16 v17; // ax
int v18; // eax
int v19; // eax
int v20; // eax
__int16 v21; // ax
__int16 v22; // ax
int v23; // eax
unsigned int v24; // edx
char v25; // cl
char *v26; // rax
__int64 v27; // r13
int v28; // eax
__int64 v29; // rbp
__int64 v30; // rbx
__int64 v31; // rdx
__int16 v32; // bx
__int16 v33; // ax
unsigned int v34; // [rsp+Ch] [rbp-1B4h] BYREF
int i; // [rsp+10h] [rbp-1B0h] BYREF
unsigned int v36; // [rsp+14h] [rbp-1ACh] BYREF
int v37; // [rsp+18h] [rbp-1A8h] BYREF
int v38; // [rsp+1Ch] [rbp-1A4h] BYREF
__int64 v39; // [rsp+20h] [rbp-1A0h] BYREF
int v40[8]; // [rsp+28h] [rbp-198h]
char s[160]; // [rsp+48h] [rbp-178h] BYREF
char v42[216]; // [rsp+E8h] [rbp-D8h] BYREF

v0 = *((_WORD *)&py + 201) <= 0;
free_turn_flag = 1;
if ( !v0 )
return msg_print("You can't see to read the scroll.");
v2 = "You have no light to read by.";
if ( (unsigned int)no_light() )
return msg_print(v2);
v2 = "You are too confused to read a scroll.";
if ( *((__int16 *)&py + 203) > 0 )
return msg_print(v2);
if ( !inven_ctr )
{
v2 = "You are not carrying anything!";
return msg_print(v2);
}
if ( !(unsigned int)find_range(70LL, 71LL, &v34, &i) )
return msg_print("You are not carrying any scrolls!");
v3 = (__int64)"Read which scroll?";
result = get_item(&v36, "Read which scroll?", v34, (unsigned int)i, 0LL, 0LL);
if ( (_DWORD)result )
{
free_turn_flag = 0;
v4 = (unsigned __int64)&inventory + 56 * (int)v36;
v39 = *(_QWORD *)(v4 + 16);
if ( v39 )
{
v5 = 0;
v6 = 1;
while ( 2 )
{
v7 = bit_pos(&v39);
v8 = *(_BYTE *)(v4 + 24) == 71;
v9 = v7 + 1;
v34 = v7 + 1;
if ( v8 )
{
v9 = v7 + 33;
v34 = v7 + 33;
}
switch ( v9 )
{
case 1:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
if ( *((_BYTE *)&inventory + 1256) )
{
objdes(v42, (unsigned int)((_DWORD)&inventory + 1232), 0LL);
sprintf(s, "Your %s glows faintly!", v42);
msg_print(s);
v3 = 10LL;
if ( (unsigned int)enchant((unsigned int)((_DWORD)&inventory + 1276), 10LL) )
{
*((_QWORD *)&inventory + 156) &= 0xFFFFFFFF7FFFFFFFLL;
v5 = v9;
calc_bonuses();
}
else
{
v5 = v9;
msg_print("The enchantment fails.");
}
}
goto LABEL_18;
case 2:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
if ( *((_BYTE *)&inventory + 1256) )
{
objdes(v42, (unsigned int)((_DWORD)&inventory + 1232), 0LL);
sprintf(s, "Your %s glows faintly!", v42);
msg_print(s);
v3 = 10LL;
if ( (unsigned __int8)(*((_BYTE *)&inventory + 1256) - 21) <= 4u )
v3 = *((unsigned __int8 *)&inventory + 1285) * (unsigned int)*((unsigned __int8 *)&inventory + 1284);
v34 = v3;
if ( !(unsigned int)enchant((unsigned int)((_DWORD)&inventory + 1278), v3) )
goto LABEL_182;
v4 = (unsigned int)((_DWORD)&inventory + 1232);
v5 = 1;
*((_QWORD *)&inventory + 156) &= 0xFFFFFFFF7FFFFFFFLL;
calc_bonuses();
}
goto LABEL_18;
case 3:
v27 = 0LL;
v8 = *((_BYTE *)&inventory + 1424) == 0;
i = 0;
if ( !v8 )
{
i = 1;
v27 = 1LL;
v40[0] = 25;
}
if ( *((_BYTE *)&inventory + 1480) )
{
v40[v27] = 26;
i = v27 + 1;
v27 = (int)v27 + 1;
}
if ( *((_BYTE *)&inventory + 1760) )
{
v40[v27] = 31;
i = v27 + 1;
v27 = (int)v27 + 1;
}
if ( *((_BYTE *)&inventory + 1536) )
{
v40[v27] = 27;
i = v27 + 1;
v27 = (int)v27 + 1;
}
if ( *((_BYTE *)&inventory + 1312) )
{
v28 = v27 + 1;
v8 = *((_BYTE *)&inventory + 1704) == 0;
v40[v27] = 23;
i = v27 + 1;
if ( !v8 )
goto LABEL_126;
LODWORD(v27) = v27 + 1;
goto LABEL_127;
}
if ( *((_BYTE *)&inventory + 1704) )
{
v28 = v27;
LABEL_126:
LODWORD(v27) = v28 + 1;
i = v28 + 1;
v40[v28] = 30;
LABEL_127:
v27 = v40[(int)(randint((unsigned int)v27) - 1)];
goto LABEL_128;
}
if ( (_DWORD)v27 )
goto LABEL_127;
LABEL_128:
if ( *((char *)&inventory + 1419) < 0 )
{
v30 = 1450LL;
v29 = 1400LL;
v27 = 25LL;
}
else if ( *((char *)&inventory + 1475) < 0 )
{
v30 = 1506LL;
v29 = 1456LL;
v27 = 26LL;
}
else if ( *((char *)&inventory + 1755) < 0 )
{
v30 = 1786LL;
v29 = 1736LL;
v27 = 31LL;
}
else if ( *((char *)&inventory + 1307) < 0 )
{
v30 = 1338LL;
v29 = 1288LL;
v27 = 23LL;
}
else if ( *((char *)&inventory + 1531) < 0 )
{
v30 = 1562LL;
v29 = 1512LL;
v27 = 27LL;
}
else if ( *((char *)&inventory + 1699) < 0 )
{
v30 = 1730LL;
v29 = 1680LL;
v27 = 30LL;
}
else
{
if ( (int)v27 <= 0 )
goto LABEL_18;
v29 = 56LL * (int)v27;
v30 = v29 + 50;
}
v4 = (unsigned __int64)&inventory + v29;
objdes(v42, v4, 0LL);
sprintf(s, "Your %s glows faintly!", v42);
msg_print(s);
v3 = 10LL;
if ( !(unsigned int)enchant((char *)&inventory + v30, 10LL) )
goto LABEL_164;
v5 = 1;
*((_QWORD *)&inventory + 7 * v27 + 2) &= 0xFFFFFFFF7FFFFFFFLL;
calc_bonuses();
LABEL_18:
if ( v39 )
continue;
v10 = (char *)&inventory + 56 * (int)v36;
if ( v5 )
{
result = known1_p(v10);
if ( !(_DWORD)result )
{
v31 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + (unsigned __int8)v10[54]) >> 31);
LODWORD(v31) = ((*((_WORD *)&py + 32) >> 1) + (unsigned __int8)v10[54])
% *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + (unsigned __int8)v10[54])
/ *((unsigned __int16 *)&py + 32);
prt_experience(v10, v3, v31);
result = identify(&v36);
}
}
else
{
result = known1_p(v10);
if ( !(_DWORD)result )
result = sample(v10);
}
if ( v6 )
goto LABEL_23;
return result;
case 4:
msg_print("This is an identify scroll.");
v6 = ident_spell();
v24 = v36;
v25 = 0;
v26 = (char *)&inventory + 56 * (int)v36 - 56;
while ( *(_BYTE *)(v4 + 24) != 70 || *(_QWORD *)(v4 + 16) != 8LL )
{
v4 = (unsigned __int64)v26;
--v24;
v26 -= 56;
v25 = 1;
}
if ( v25 )
v36 = v24;
goto LABEL_115;
case 5:
if ( (unsigned int)remove_curse() )
{
v5 = 1;
msg_print("You feel as if someone is watching over you.");
}
goto LABEL_18;
case 6:
v3 = (unsigned int)char_col;
v5 = light_area((unsigned int)char_row, v3);
goto LABEL_18;
case 7:
i = 0;
while ( (int)randint(3LL) > i )
{
v3 = (__int64)&v38;
v37 = char_row;
v38 = char_col;
v23 = summon_monster(&v37, &v38, 0LL);
++i;
v5 |= v23;
}
goto LABEL_18;
case 8:
v5 = 1;
teleport(10LL);
goto LABEL_18;
case 9:
v5 = 1;
teleport(100LL);
goto LABEL_18;
case 10:
v5 = 1;
v21 = randint(2LL);
new_level_flag = 1;
v22 = dun_level + 2 * v21 - 3;
if ( v22 <= 0 )
v22 = 1;
dun_level = v22;
goto LABEL_18;
case 11:
if ( !*((_BYTE *)&py + 465) )
{
v5 = 1;
msg_print("Your hands begin to glow.");
*((_BYTE *)&py + 465) = 1;
}
goto LABEL_18;
case 12:
v5 = 1;
map_area();
goto LABEL_18;
case 13:
v3 = (unsigned int)char_col;
v5 = sleep_monsters1((unsigned int)char_row, v3);
goto LABEL_18;
case 14:
v5 = 1;
warding_glyph();
goto LABEL_18;
case 15:
v5 = detect_treasure();
goto LABEL_18;
case 16:
v5 = detect_object();
goto LABEL_18;
case 17:
v5 = detect_trap();
goto LABEL_18;
case 18:
v5 = detect_sdoor();
goto LABEL_18;
case 19:
msg_print("This is a mass genocide scroll.");
v5 = mass_genocide();
goto LABEL_18;
case 20:
v5 = detect_invisible();
goto LABEL_18;
case 21:
v5 = aggravate_monster(20LL);
if ( v5 )
msg_print("There is a high pitched humming noise.");
goto LABEL_18;
case 22:
v5 = trap_creation();
goto LABEL_18;
case 23:
v5 = td_destroy();
goto LABEL_18;
case 24:
v5 = door_creation();
goto LABEL_18;
case 25:
v5 = 1;
msg_print("This is a Recharge-Item scroll.");
v6 = recharge(60LL);
goto LABEL_18;
case 26:
msg_print("This is a genocide scroll.");
v5 = genocide();
goto LABEL_18;
case 27:
v3 = (unsigned int)char_col;
v5 = unlight_area((unsigned int)char_row, v3);
goto LABEL_18;
case 28:
v5 = protect_evil();
goto LABEL_18;
case 29:
v5 = 1;
create_food();
goto LABEL_18;
case 30:
v3 = 60LL;
v5 = dispel_creature(8LL, 60LL);
goto LABEL_18;
case 33:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
if ( *((_BYTE *)&inventory + 1256) )
{
objdes(v42, (unsigned int)((_DWORD)&inventory + 1232), 0LL);
v3 = (__int64)"Your %s glows brightly!";
v5 = 0;
sprintf(s, "Your %s glows brightly!", v42);
msg_print(s);
for ( i = 0; (int)randint(2LL) > i; ++i )
{
v3 = 10LL;
if ( (unsigned int)enchant((unsigned int)((_DWORD)&inventory + 1276), 10LL) )
v5 = 1;
}
v20 = 10;
if ( (unsigned __int8)(*((_BYTE *)&inventory + 1256) - 21) <= 4u )
v20 = *((unsigned __int8 *)&inventory + 1285) * *((unsigned __int8 *)&inventory + 1284);
v34 = v20;
for ( i = 0; (int)randint(2LL) > i; ++i )
{
v3 = v34;
if ( (unsigned int)enchant((unsigned int)((_DWORD)&inventory + 1278), v34) )
v5 = 1;
}
if ( v5 )
{
*((_QWORD *)&inventory + 156) &= 0xFFFFFFFF7FFFFFFFLL;
v4 = (unsigned int)((_DWORD)&inventory + 1232);
calc_bonuses();
}
else
{
LABEL_182:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
v5 = 1;
msg_print("The enchantment fails.");
}
}
goto LABEL_18;
case 34:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
if ( *((_BYTE *)&inventory + 1256) )
{
objdes(v42, (unsigned int)((_DWORD)&inventory + 1232), 0LL);
sprintf(s, "Your %s glows black, fades.", v42);
msg_print(s);
unmagic_name((unsigned int)((_DWORD)&inventory + 1232));
v15 = randint(5LL);
*((_WORD *)&inventory + 638) = -(__int16)(v15 + randint(5LL));
v16 = randint(5LL);
v3 = 0xFFFFFFFFLL;
v17 = v16 + randint(5LL);
v5 = 1;
*((_WORD *)&inventory + 639) = -v17;
py_bonuses((unsigned int)((_DWORD)&inventory + 1232), 0xFFFFFFFFLL);
*((_QWORD *)&inventory + 156) = 0x80000000LL;
calc_bonuses();
}
goto LABEL_18;
case 35:
v13 = 0LL;
v8 = *((_BYTE *)&inventory + 1424) == 0;
i = 0;
if ( !v8 )
{
i = 1;
v13 = 1LL;
v40[0] = 25;
}
if ( *((_BYTE *)&inventory + 1480) )
{
v40[v13] = 26;
i = v13 + 1;
v13 = (int)v13 + 1;
}
if ( *((_BYTE *)&inventory + 1760) )
{
v40[v13] = 31;
i = v13 + 1;
v13 = (int)v13 + 1;
}
if ( *((_BYTE *)&inventory + 1536) )
{
v40[v13] = 27;
i = v13 + 1;
v13 = (int)v13 + 1;
}
if ( *((_BYTE *)&inventory + 1312) )
{
v14 = v13 + 1;
v8 = *((_BYTE *)&inventory + 1704) == 0;
v40[v13] = 23;
i = v13 + 1;
if ( !v8 )
goto LABEL_55;
v13 = v14;
goto LABEL_56;
}
if ( *((_BYTE *)&inventory + 1704) )
{
v14 = v13;
LABEL_55:
v13 = v14 + 1;
i = v14 + 1;
v40[v14] = 30;
LABEL_56:
LODWORD(v13) = v40[(int)(randint(v13) - 1)];
goto LABEL_57;
}
if ( (_DWORD)v13 )
goto LABEL_56;
LABEL_57:
if ( *((char *)&inventory + 1419) < 0 )
{
LODWORD(v13) = 25;
}
else if ( *((char *)&inventory + 1475) < 0 )
{
LODWORD(v13) = 26;
}
else if ( *((char *)&inventory + 1755) < 0 )
{
LODWORD(v13) = 31;
}
else if ( *((char *)&inventory + 1307) < 0 )
{
LODWORD(v13) = 23;
}
else if ( *((char *)&inventory + 1531) < 0 )
{
LODWORD(v13) = 27;
}
else if ( *((char *)&inventory + 1699) < 0 )
{
LODWORD(v13) = 30;
}
else if ( (int)v13 <= 0 )
{
goto LABEL_18;
}
v5 = 0;
v4 = (unsigned __int64)&inventory + 56 * (int)v13;
objdes(v42, v4, 0LL);
v3 = (__int64)"Your %s glows brightly!";
sprintf(s, "Your %s glows brightly!", v42);
msg_print(s);
for ( i = 0; (int)randint(2LL) >= i; ++i )
{
v3 = 10LL;
if ( (unsigned int)enchant((char *)&inventory + 56 * (int)v13 + 50, 10LL) )
v5 = 1;
}
if ( v5 )
{
*((_QWORD *)&inventory + 7 * (int)v13 + 2) &= 0xFFFFFFFF7FFFFFFFLL;
calc_bonuses();
}
else
{
LABEL_164:
msg_print("The enchantment fails.");
LABEL_115:
v5 = 1;
}
goto LABEL_18;
case 36:
if ( *((_BYTE *)&inventory + 1424) && (unsigned int)randint(4LL) == 1 )
goto LABEL_174;
if ( *((_BYTE *)&inventory + 1480) && (unsigned int)randint(3LL) == 1 )
goto LABEL_179;
if ( *((_BYTE *)&inventory + 1760) && (unsigned int)randint(3LL) == 1 )
goto LABEL_181;
if ( *((_BYTE *)&inventory + 1312) && (unsigned int)randint(3LL) == 1 )
goto LABEL_185;
if ( *((_BYTE *)&inventory + 1536) && (unsigned int)randint(3LL) == 1 )
goto LABEL_187;
if ( *((_BYTE *)&inventory + 1704) && (unsigned int)randint(3LL) == 1 )
goto LABEL_189;
if ( *((_BYTE *)&inventory + 1424) )
{
LABEL_174:
i = 25;
}
else if ( *((_BYTE *)&inventory + 1480) )
{
LABEL_179:
i = 26;
}
else if ( *((_BYTE *)&inventory + 1760) )
{
LABEL_181:
i = 31;
}
else if ( *((_BYTE *)&inventory + 1312) )
{
LABEL_185:
i = 23;
}
else if ( *((_BYTE *)&inventory + 1536) )
{
LABEL_187:
i = 27;
}
else
{
if ( !*((_BYTE *)&inventory + 1704) )
{
i = 0;
goto LABEL_18;
}
LABEL_189:
i = 30;
}
v4 = (unsigned __int64)&inventory + 56 * i;
objdes(v42, v4, 0LL);
v3 = (__int64)"Your %s glows black, fades.";
sprintf(s, "Your %s glows black, fades.", v42);
msg_print(s);
unmagic_name(v4);
*(_QWORD *)(v4 + 16) = 0x80000000LL;
v32 = randint(5LL);
v33 = v32 + randint(5LL);
v5 = 1;
*(_WORD *)(v4 + 50) = -v33;
calc_bonuses();
goto LABEL_18;
case 37:
i = 0;
v5 = 0;
while ( (int)randint(3LL) > i )
{
v3 = (__int64)&v38;
v37 = char_row;
v38 = char_col;
v12 = summon_undead(&v37, &v38);
++i;
v5 |= v12;
}
goto LABEL_18;
case 38:
v5 = 1;
v19 = randint(12LL);
bless((unsigned int)(v19 + 6));
goto LABEL_18;
case 39:
v5 = 1;
v18 = randint(24LL);
bless((unsigned int)(v18 + 12));
goto LABEL_18;
case 40:
v5 = 1;
v11 = randint(48LL);
bless((unsigned int)(v11 + 24));
goto LABEL_18;
case 41:
if ( !*((_WORD *)&py + 221) )
*((_WORD *)&py + 221) = randint(30LL) + 25;
v5 = 1;
msg_print("The air about you becomes charged.");
goto LABEL_18;
case 42:
v3 = (unsigned int)char_col;
v5 = 1;
destroy_area((unsigned int)char_row, v3);
goto LABEL_18;
default:
msg_print("Internal error in scroll()");
goto LABEL_18;
}
}
}
if ( !(unsigned int)known1_p((char *)&inventory + 56 * (int)v36) )
sample(v4);
LABEL_23:
desc_remain(v36);
result = inven_destroy(v36);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
bool v0; // cc
__int64 result; // rax
const char *v2; // rdi
__int64 v3; // rsi
unsigned __int64 v4; // rbp
int v5; // ebx
int v6; // er12
int v7; // eax
bool v8; // zf
int v9; // er13
char *v10; // rbp
int v11; // eax
int v12; // eax
__int64 v13; // rdi
unsigned int v14; // eax
__int16 v15; // bx
__int16 v16; // bx
__int16 v17; // ax
int v18; // eax
int v19; // eax
int v20; // eax
__int16 v21; // ax
__int16 v22; // ax
int v23; // eax
unsigned int v24; // edx
char v25; // cl
char *v26; // rax
__int64 v27; // r13
int v28; // eax
__int64 v29; // rbp
__int64 v30; // rbx
__int64 v31; // rdx
__int16 v32; // bx
__int16 v33; // ax
unsigned int v34; // [rsp+Ch] [rbp-1B4h] BYREF
int i; // [rsp+10h] [rbp-1B0h] BYREF
unsigned int v36; // [rsp+14h] [rbp-1ACh] BYREF
int v37; // [rsp+18h] [rbp-1A8h] BYREF
int v38; // [rsp+1Ch] [rbp-1A4h] BYREF
__int64 v39; // [rsp+20h] [rbp-1A0h] BYREF
int v40[8]; // [rsp+28h] [rbp-198h]
char s[160]; // [rsp+48h] [rbp-178h] BYREF
char v42[216]; // [rsp+E8h] [rbp-D8h] BYREF

v0 = *((_WORD *)&py + 201) <= 0;
free_turn_flag = 1;
if ( !v0 )
return msg_print("You can't see to read the scroll.");
v2 = "You have no light to read by.";
if ( (unsigned int)no_light() )
return msg_print(v2);
v2 = "You are too confused to read a scroll.";
if ( *((__int16 *)&py + 203) > 0 )
return msg_print(v2);
if ( !inven_ctr )
{
v2 = "You are not carrying anything!";
return msg_print(v2);
}
if ( !(unsigned int)find_range(70LL, 71LL, &v34, &i) )
return msg_print("You are not carrying any scrolls!");
v3 = (__int64)"Read which scroll?";
result = get_item(&v36, "Read which scroll?", v34, (unsigned int)i, 0LL, 0LL);
if ( (_DWORD)result )
{
free_turn_flag = 0;
v4 = (unsigned __int64)&inventory + 56 * (int)v36;
v39 = *(_QWORD *)(v4 + 16);
if ( v39 )
{
v5 = 0;
v6 = 1;
while ( 2 )
{
v7 = bit_pos(&v39);
v8 = *(_BYTE *)(v4 + 24) == 71;
v9 = v7 + 1;
v34 = v7 + 1;
if ( v8 )
{
v9 = v7 + 33;
v34 = v7 + 33;
}
switch ( v9 )
{
case 1:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
if ( *((_BYTE *)&inventory + 1256) )
{
objdes(v42, (unsigned int)((_DWORD)&inventory + 1232), 0LL);
sprintf(s, "Your %s glows faintly!", v42);
msg_print(s);
v3 = 10LL;
if ( (unsigned int)enchant((unsigned int)((_DWORD)&inventory + 1276), 10LL) )
{
*((_QWORD *)&inventory + 156) &= 0xFFFFFFFF7FFFFFFFLL;
v5 = v9;
calc_bonuses();
}
else
{
v5 = v9;
msg_print("The enchantment fails.");
}
}
goto LABEL_18;
case 2:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
if ( *((_BYTE *)&inventory + 1256) )
{
objdes(v42, (unsigned int)((_DWORD)&inventory + 1232), 0LL);
sprintf(s, "Your %s glows faintly!", v42);
msg_print(s);
v3 = 10LL;
if ( (unsigned __int8)(*((_BYTE *)&inventory + 1256) - 21) <= 4u )
v3 = *((unsigned __int8 *)&inventory + 1285) * (unsigned int)*((unsigned __int8 *)&inventory + 1284);
v34 = v3;
if ( !(unsigned int)enchant((unsigned int)((_DWORD)&inventory + 1278), v3) )
goto LABEL_182;
v4 = (unsigned int)((_DWORD)&inventory + 1232);
v5 = 1;
*((_QWORD *)&inventory + 156) &= 0xFFFFFFFF7FFFFFFFLL;
calc_bonuses();
}
goto LABEL_18;
case 3:
v27 = 0LL;
v8 = *((_BYTE *)&inventory + 1424) == 0;
i = 0;
if ( !v8 )
{
i = 1;
v27 = 1LL;
v40[0] = 25;
}
if ( *((_BYTE *)&inventory + 1480) )
{
v40[v27] = 26;
i = v27 + 1;
v27 = (int)v27 + 1;
}
if ( *((_BYTE *)&inventory + 1760) )
{
v40[v27] = 31;
i = v27 + 1;
v27 = (int)v27 + 1;
}
if ( *((_BYTE *)&inventory + 1536) )
{
v40[v27] = 27;
i = v27 + 1;
v27 = (int)v27 + 1;
}
if ( *((_BYTE *)&inventory + 1312) )
{
v28 = v27 + 1;
v8 = *((_BYTE *)&inventory + 1704) == 0;
v40[v27] = 23;
i = v27 + 1;
if ( !v8 )
goto LABEL_126;
LODWORD(v27) = v27 + 1;
goto LABEL_127;
}
if ( *((_BYTE *)&inventory + 1704) )
{
v28 = v27;
LABEL_126:
LODWORD(v27) = v28 + 1;
i = v28 + 1;
v40[v28] = 30;
LABEL_127:
v27 = v40[(int)(randint((unsigned int)v27) - 1)];
goto LABEL_128;
}
if ( (_DWORD)v27 )
goto LABEL_127;
LABEL_128:
if ( *((char *)&inventory + 1419) < 0 )
{
v30 = 1450LL;
v29 = 1400LL;
v27 = 25LL;
}
else if ( *((char *)&inventory + 1475) < 0 )
{
v30 = 1506LL;
v29 = 1456LL;
v27 = 26LL;
}
else if ( *((char *)&inventory + 1755) < 0 )
{
v30 = 1786LL;
v29 = 1736LL;
v27 = 31LL;
}
else if ( *((char *)&inventory + 1307) < 0 )
{
v30 = 1338LL;
v29 = 1288LL;
v27 = 23LL;
}
else if ( *((char *)&inventory + 1531) < 0 )
{
v30 = 1562LL;
v29 = 1512LL;
v27 = 27LL;
}
else if ( *((char *)&inventory + 1699) < 0 )
{
v30 = 1730LL;
v29 = 1680LL;
v27 = 30LL;
}
else
{
if ( (int)v27 <= 0 )
goto LABEL_18;
v29 = 56LL * (int)v27;
v30 = v29 + 50;
}
v4 = (unsigned __int64)&inventory + v29;
objdes(v42, v4, 0LL);
sprintf(s, "Your %s glows faintly!", v42);
msg_print(s);
v3 = 10LL;
if ( !(unsigned int)enchant((char *)&inventory + v30, 10LL) )
goto LABEL_164;
v5 = 1;
*((_QWORD *)&inventory + 7 * v27 + 2) &= 0xFFFFFFFF7FFFFFFFLL;
calc_bonuses();
LABEL_18:
if ( v39 )
continue;
v10 = (char *)&inventory + 56 * (int)v36;
if ( v5 )
{
result = known1_p(v10);
if ( !(_DWORD)result )
{
v31 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + (unsigned __int8)v10[54]) >> 31);
LODWORD(v31) = ((*((_WORD *)&py + 32) >> 1) + (unsigned __int8)v10[54])
% *((unsigned __int16 *)&py + 32);
*((_QWORD *)&py + 6) += ((*((_WORD *)&py + 32) >> 1) + (unsigned __int8)v10[54])
/ *((unsigned __int16 *)&py + 32);
prt_experience(v10, v3, v31);
result = identify(&v36);
}
}
else
{
result = known1_p(v10);
if ( !(_DWORD)result )
result = sample(v10);
}
if ( v6 )
goto LABEL_23;
return result;
case 4:
msg_print("This is an identify scroll.");
v6 = ident_spell();
v24 = v36;
v25 = 0;
v26 = (char *)&inventory + 56 * (int)v36 - 56;
while ( *(_BYTE *)(v4 + 24) != 70 || *(_QWORD *)(v4 + 16) != 8LL )
{
v4 = (unsigned __int64)v26;
--v24;
v26 -= 56;
v25 = 1;
}
if ( v25 )
v36 = v24;
goto LABEL_115;
case 5:
if ( (unsigned int)remove_curse() )
{
v5 = 1;
msg_print("You feel as if someone is watching over you.");
}
goto LABEL_18;
case 6:
v3 = (unsigned int)char_col;
v5 = light_area((unsigned int)char_row, v3);
goto LABEL_18;
case 7:
i = 0;
while ( (int)randint(3LL) > i )
{
v3 = (__int64)&v38;
v37 = char_row;
v38 = char_col;
v23 = summon_monster(&v37, &v38, 0LL);
++i;
v5 |= v23;
}
goto LABEL_18;
case 8:
v5 = 1;
teleport(10LL);
goto LABEL_18;
case 9:
v5 = 1;
teleport(100LL);
goto LABEL_18;
case 10:
v5 = 1;
v21 = randint(2LL);
new_level_flag = 1;
v22 = dun_level + 2 * v21 - 3;
if ( v22 <= 0 )
v22 = 1;
dun_level = v22;
goto LABEL_18;
case 11:
if ( !*((_BYTE *)&py + 465) )
{
v5 = 1;
msg_print("Your hands begin to glow.");
*((_BYTE *)&py + 465) = 1;
}
goto LABEL_18;
case 12:
v5 = 1;
map_area();
goto LABEL_18;
case 13:
v3 = (unsigned int)char_col;
v5 = sleep_monsters1((unsigned int)char_row, v3);
goto LABEL_18;
case 14:
v5 = 1;
warding_glyph();
goto LABEL_18;
case 15:
v5 = detect_treasure();
goto LABEL_18;
case 16:
v5 = detect_object();
goto LABEL_18;
case 17:
v5 = detect_trap();
goto LABEL_18;
case 18:
v5 = detect_sdoor();
goto LABEL_18;
case 19:
msg_print("This is a mass genocide scroll.");
v5 = mass_genocide();
goto LABEL_18;
case 20:
v5 = detect_invisible();
goto LABEL_18;
case 21:
v5 = aggravate_monster(20LL);
if ( v5 )
msg_print("There is a high pitched humming noise.");
goto LABEL_18;
case 22:
v5 = trap_creation();
goto LABEL_18;
case 23:
v5 = td_destroy();
goto LABEL_18;
case 24:
v5 = door_creation();
goto LABEL_18;
case 25:
v5 = 1;
msg_print("This is a Recharge-Item scroll.");
v6 = recharge(60LL);
goto LABEL_18;
case 26:
msg_print("This is a genocide scroll.");
v5 = genocide();
goto LABEL_18;
case 27:
v3 = (unsigned int)char_col;
v5 = unlight_area((unsigned int)char_row, v3);
goto LABEL_18;
case 28:
v5 = protect_evil();
goto LABEL_18;
case 29:
v5 = 1;
create_food();
goto LABEL_18;
case 30:
v3 = 60LL;
v5 = dispel_creature(8LL, 60LL);
goto LABEL_18;
case 33:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
if ( *((_BYTE *)&inventory + 1256) )
{
objdes(v42, (unsigned int)((_DWORD)&inventory + 1232), 0LL);
v3 = (__int64)"Your %s glows brightly!";
v5 = 0;
sprintf(s, "Your %s glows brightly!", v42);
msg_print(s);
for ( i = 0; (int)randint(2LL) > i; ++i )
{
v3 = 10LL;
if ( (unsigned int)enchant((unsigned int)((_DWORD)&inventory + 1276), 10LL) )
v5 = 1;
}
v20 = 10;
if ( (unsigned __int8)(*((_BYTE *)&inventory + 1256) - 21) <= 4u )
v20 = *((unsigned __int8 *)&inventory + 1285) * *((unsigned __int8 *)&inventory + 1284);
v34 = v20;
for ( i = 0; (int)randint(2LL) > i; ++i )
{
v3 = v34;
if ( (unsigned int)enchant((unsigned int)((_DWORD)&inventory + 1278), v34) )
v5 = 1;
}
if ( v5 )
{
*((_QWORD *)&inventory + 156) &= 0xFFFFFFFF7FFFFFFFLL;
v4 = (unsigned int)((_DWORD)&inventory + 1232);
calc_bonuses();
}
else
{
LABEL_182:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
v5 = 1;
msg_print("The enchantment fails.");
}
}
goto LABEL_18;
case 34:
v4 = (unsigned int)((_DWORD)&inventory + 1232);
if ( *((_BYTE *)&inventory + 1256) )
{
objdes(v42, (unsigned int)((_DWORD)&inventory + 1232), 0LL);
sprintf(s, "Your %s glows black, fades.", v42);
msg_print(s);
unmagic_name((unsigned int)((_DWORD)&inventory + 1232));
v15 = randint(5LL);
*((_WORD *)&inventory + 638) = -(__int16)(v15 + randint(5LL));
v16 = randint(5LL);
v3 = 0xFFFFFFFFLL;
v17 = v16 + randint(5LL);
v5 = 1;
*((_WORD *)&inventory + 639) = -v17;
py_bonuses((unsigned int)((_DWORD)&inventory + 1232), 0xFFFFFFFFLL);
*((_QWORD *)&inventory + 156) = 0x80000000LL;
calc_bonuses();
}
goto LABEL_18;
case 35:
v13 = 0LL;
v8 = *((_BYTE *)&inventory + 1424) == 0;
i = 0;
if ( !v8 )
{
i = 1;
v13 = 1LL;
v40[0] = 25;
}
if ( *((_BYTE *)&inventory + 1480) )
{
v40[v13] = 26;
i = v13 + 1;
v13 = (int)v13 + 1;
}
if ( *((_BYTE *)&inventory + 1760) )
{
v40[v13] = 31;
i = v13 + 1;
v13 = (int)v13 + 1;
}
if ( *((_BYTE *)&inventory + 1536) )
{
v40[v13] = 27;
i = v13 + 1;
v13 = (int)v13 + 1;
}
if ( *((_BYTE *)&inventory + 1312) )
{
v14 = v13 + 1;
v8 = *((_BYTE *)&inventory + 1704) == 0;
v40[v13] = 23;
i = v13 + 1;
if ( !v8 )
goto LABEL_55;
v13 = v14;
goto LABEL_56;
}
if ( *((_BYTE *)&inventory + 1704) )
{
v14 = v13;
LABEL_55:
v13 = v14 + 1;
i = v14 + 1;
v40[v14] = 30;
LABEL_56:
LODWORD(v13) = v40[(int)(randint(v13) - 1)];
goto LABEL_57;
}
if ( (_DWORD)v13 )
goto LABEL_56;
LABEL_57:
if ( *((char *)&inventory + 1419) < 0 )
{
LODWORD(v13) = 25;
}
else if ( *((char *)&inventory + 1475) < 0 )
{
LODWORD(v13) = 26;
}
else if ( *((char *)&inventory + 1755) < 0 )
{
LODWORD(v13) = 31;
}
else if ( *((char *)&inventory + 1307) < 0 )
{
LODWORD(v13) = 23;
}
else if ( *((char *)&inventory + 1531) < 0 )
{
LODWORD(v13) = 27;
}
else if ( *((char *)&inventory + 1699) < 0 )
{
LODWORD(v13) = 30;
}
else if ( (int)v13 <= 0 )
{
goto LABEL_18;
}
v5 = 0;
v4 = (unsigned __int64)&inventory + 56 * (int)v13;
objdes(v42, v4, 0LL);
v3 = (__int64)"Your %s glows brightly!";
sprintf(s, "Your %s glows brightly!", v42);
msg_print(s);
for ( i = 0; (int)randint(2LL) >= i; ++i )
{
v3 = 10LL;
if ( (unsigned int)enchant((char *)&inventory + 56 * (int)v13 + 50, 10LL) )
v5 = 1;
}
if ( v5 )
{
*((_QWORD *)&inventory + 7 * (int)v13 + 2) &= 0xFFFFFFFF7FFFFFFFLL;
calc_bonuses();
}
else
{
LABEL_164:
msg_print("The enchantment fails.");
LABEL_115:
v5 = 1;
}
goto LABEL_18;
case 36:
if ( *((_BYTE *)&inventory + 1424) && (unsigned int)randint(4LL) == 1 )
goto LABEL_174;
if ( *((_BYTE *)&inventory + 1480) && (unsigned int)randint(3LL) == 1 )
goto LABEL_179;
if ( *((_BYTE *)&inventory + 1760) && (unsigned int)randint(3LL) == 1 )
goto LABEL_181;
if ( *((_BYTE *)&inventory + 1312) && (unsigned int)randint(3LL) == 1 )
goto LABEL_185;
if ( *((_BYTE *)&inventory + 1536) && (unsigned int)randint(3LL) == 1 )
goto LABEL_187;
if ( *((_BYTE *)&inventory + 1704) && (unsigned int)randint(3LL) == 1 )
goto LABEL_189;
if ( *((_BYTE *)&inventory + 1424) )
{
LABEL_174:
i = 25;
}
else if ( *((_BYTE *)&inventory + 1480) )
{
LABEL_179:
i = 26;
}
else if ( *((_BYTE *)&inventory + 1760) )
{
LABEL_181:
i = 31;
}
else if ( *((_BYTE *)&inventory + 1312) )
{
LABEL_185:
i = 23;
}
else if ( *((_BYTE *)&inventory + 1536) )
{
LABEL_187:
i = 27;
}
else
{
if ( !*((_BYTE *)&inventory + 1704) )
{
i = 0;
goto LABEL_18;
}
LABEL_189:
i = 30;
}
v4 = (unsigned __int64)&inventory + 56 * i;
objdes(v42, v4, 0LL);
v3 = (__int64)"Your %s glows black, fades.";
sprintf(s, "Your %s glows black, fades.", v42);
msg_print(s);
unmagic_name(v4);
*(_QWORD *)(v4 + 16) = 0x80000000LL;
v32 = randint(5LL);
v33 = v32 + randint(5LL);
v5 = 1;
*(_WORD *)(v4 + 50) = -v33;
calc_bonuses();
goto LABEL_18;
case 37:
i = 0;
v5 = 0;
while ( (int)randint(3LL) > i )
{
v3 = (__int64)&v38;
v37 = char_row;
v38 = char_col;
v12 = summon_undead(&v37, &v38);
++i;
v5 |= v12;
}
goto LABEL_18;
case 38:
v5 = 1;
v19 = randint(12LL);
bless((unsigned int)(v19 + 6));
goto LABEL_18;
case 39:
v5 = 1;
v18 = randint(24LL);
bless((unsigned int)(v18 + 12));
goto LABEL_18;
case 40:
v5 = 1;
v11 = randint(48LL);
bless((unsigned int)(v11 + 24));
goto LABEL_18;
case 41:
if ( !*((_WORD *)&py + 221) )
*((_WORD *)&py + 221) = randint(30LL) + 25;
v5 = 1;
msg_print("The air about you becomes charged.");
goto LABEL_18;
case 42:
v3 = (unsigned int)char_col;
v5 = 1;
destroy_area((unsigned int)char_row, v3);
goto LABEL_18;
default:
msg_print("Internal error in scroll()");
goto LABEL_18;
}
}
}
if ( !(unsigned int)known1_p((char *)&inventory + 56 * (int)v36) )
sample(v4);
LABEL_23:
desc_remain(v36);
result = inven_destroy(v36);
}
return result;
}

original_code:
void read_scroll()
{
  int32u i;
  int j, k, item_val, y, x;
  int tmp[6], flag, used_up;
  bigvtype out_val, tmp_str;
  register int ident, l;
  register inven_type *i_ptr;
  register struct misc *m_ptr;
  free_turn_flag = 1;
  if (py.flags.blind > 0)
    msg_print("You can't see to read the scroll.");
  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 to read a scroll.");
  else if (inven_ctr == 0)
    msg_print("You are not carrying anything!");
  else if (!find_range(70, 71, &j, &k))
    msg_print ("You are not carrying any scrolls!");
  else if (get_item(&item_val, "Read which scroll?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = 0;
      used_up = 1;
      i = i_ptr->flags;
      ident = 0;
      while (i != 0)
 {
   j = bit_pos(&i) + 1;
   if (i_ptr->tval == 71)
     j += 32;
   switch(j)
     {
     case 1:
       i_ptr = &inventory[22];
       if (i_ptr->tval != 0)
  {
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
    msg_print(out_val);
    if (enchant(&i_ptr->tohit, 10))
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 2:
       i_ptr = &inventory[22];
       if (i_ptr->tval != 0)
  {
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
    msg_print(out_val);
    if ((i_ptr->tval >= 21)&&(i_ptr->tval <= 25))
      j = i_ptr->damage[0] * i_ptr->damage[1];
    else
      j = 10;
    if (enchant(&i_ptr->todam, j))
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses ();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 3:
       k = 0;
       l = 0;
       if (inventory[25].tval != 0)
  tmp[k++] = 25;
       if (inventory[26].tval != 0)
  tmp[k++] = 26;
       if (inventory[31].tval != 0)
  tmp[k++] = 31;
       if (inventory[27].tval != 0)
  tmp[k++] = 27;
       if (inventory[23].tval != 0)
  tmp[k++] = 23;
       if (inventory[30].tval != 0)
  tmp[k++] = 30;
       if (k > 0) l = tmp[randint(k)-1];
       if (0x80000000L & inventory[25].flags)
  l = 25;
       else if (0x80000000L & inventory[26].flags)
  l = 26;
       else if (0x80000000L & inventory[31].flags)
  l = 31;
       else if (0x80000000L & inventory[23].flags)
  l = 23;
       else if (0x80000000L & inventory[27].flags)
  l = 27;
       else if (0x80000000L & inventory[30].flags)
  l = 30;
       if (l > 0)
  {
    i_ptr = &inventory[l];
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
    msg_print(out_val);
    if (enchant(&i_ptr->toac, 10))
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses ();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 4:
       msg_print("This is an identify scroll.");
       ident = 1;
       used_up = ident_spell();
       while (i_ptr->tval != 70 || i_ptr->flags != 0x00000008)
  {
    item_val--;
    i_ptr = &inventory[item_val];
  }
       break;
     case 5:
       if (remove_curse())
  {
    msg_print("You feel as if someone is watching over you.");
    ident = 1;
  }
       break;
     case 6:
       ident = light_area(char_row, char_col);
       break;
     case 7:
       for (k = 0; k < randint(3); k++)
  {
    y = char_row;
    x = char_col;
    ident |= summon_monster(&y, &x, 0);
  }
       break;
     case 8:
       teleport(10);
       ident = 1;
       break;
     case 9:
       teleport(100);
       ident = 1;
       break;
     case 10:
       dun_level += (-3) + 2*randint(2);
       if (dun_level < 1)
  dun_level = 1;
       new_level_flag = 1;
       ident = 1;
       break;
     case 11:
       if (py.flags.confuse_monster == 0)
  {
    msg_print("Your hands begin to glow.");
    py.flags.confuse_monster = 1;
    ident = 1;
  }
       break;
     case 12:
       ident = 1;
       map_area();
       break;
     case 13:
       ident = sleep_monsters1(char_row, char_col);
       break;
     case 14:
       ident = 1;
       warding_glyph();
       break;
     case 15:
       ident = detect_treasure();
       break;
     case 16:
       ident = detect_object();
       break;
     case 17:
       ident = detect_trap();
       break;
     case 18:
       ident = detect_sdoor();
       break;
     case 19:
       msg_print("This is a mass genocide scroll.");
       ident = mass_genocide();
       break;
     case 20:
       ident = detect_invisible();
       break;
     case 21:
       ident = aggravate_monster(20);
       if (ident)
  msg_print("There is a high pitched humming noise.");
       break;
     case 22:
       ident = trap_creation();
       break;
     case 23:
       ident = td_destroy();
       break;
     case 24:
       ident = door_creation();
       break;
     case 25:
       msg_print("This is a Recharge-Item scroll.");
       ident = 1;
       used_up = recharge(60);
       break;
     case 26:
       msg_print("This is a genocide scroll.");
       ident = genocide();
       break;
     case 27:
       ident = unlight_area(char_row, char_col);
       break;
     case 28:
       ident = protect_evil();
       break;
     case 29:
       ident = 1;
       create_food();
       break;
     case 30:
       ident = dispel_creature(0x0008, 60);
       break;
     case 33:
       i_ptr = &inventory[22];
       if (i_ptr->tval != 0)
  {
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val, "Your %s glows brightly!", tmp_str);
    msg_print(out_val);
    flag = 0;
    for (k = 0; k < randint(2); k++)
      if (enchant(&i_ptr->tohit, 10))
        flag = 1;
    if ((i_ptr->tval >= 21)&&(i_ptr->tval <= 25))
      j = i_ptr->damage[0] * i_ptr->damage[1];
    else
      j = 10;
    for (k = 0; k < randint(2); k++)
      if (enchant(&i_ptr->todam, j))
        flag = 1;
    if (flag)
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses ();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 34:
       i_ptr = &inventory[22];
       if (i_ptr->tval != 0)
  {
    objdes(tmp_str, i_ptr, 0);
    (void)sprintf(out_val,"Your %s glows black, fades.",tmp_str);
    msg_print(out_val);
    unmagic_name(i_ptr);
    i_ptr->tohit = -randint(5) - randint(5);
    i_ptr->todam = -randint(5) - randint(5);
    py_bonuses(i_ptr, -1);
    i_ptr->flags = 0x80000000L;
    calc_bonuses ();
    ident = 1;
  }
       break;
     case 35:
       k = 0;
       l = 0;
       if (inventory[25].tval != 0)
  tmp[k++] = 25;
       if (inventory[26].tval != 0)
  tmp[k++] = 26;
       if (inventory[31].tval != 0)
  tmp[k++] = 31;
       if (inventory[27].tval != 0)
  tmp[k++] = 27;
       if (inventory[23].tval != 0)
  tmp[k++] = 23;
       if (inventory[30].tval != 0)
  tmp[k++] = 30;
       if (k > 0) l = tmp[randint(k)-1];
       if (0x80000000L & inventory[25].flags)
  l = 25;
       else if (0x80000000L & inventory[26].flags)
  l = 26;
       else if (0x80000000L & inventory[31].flags)
  l = 31;
       else if (0x80000000L & inventory[23].flags)
  l = 23;
       else if (0x80000000L & inventory[27].flags)
  l = 27;
       else if (0x80000000L & inventory[30].flags)
  l = 30;
       if (l > 0)
  {
    i_ptr = &inventory[l];
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val,"Your %s glows brightly!", tmp_str);
    msg_print(out_val);
    flag = 0;
    for (k = 0; k < randint(2) + 1; k++)
      if (enchant(&i_ptr->toac, 10))
        flag = 1;
    if (flag)
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses ();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 36:
       if ((inventory[25].tval != 0)
    && (randint(4) == 1))
  k = 25;
       else if ((inventory[26].tval != 0)
         && (randint(3) ==1))
  k = 26;
       else if ((inventory[31].tval != 0)
         && (randint(3) ==1))
  k = 31;
       else if ((inventory[23].tval != 0)
         && (randint(3) ==1))
  k = 23;
       else if ((inventory[27].tval != 0)
         && (randint(3) ==1))
  k = 27;
       else if ((inventory[30].tval != 0)
         && (randint(3) ==1))
  k = 30;
       else if (inventory[25].tval != 0)
  k = 25;
       else if (inventory[26].tval != 0)
  k = 26;
       else if (inventory[31].tval != 0)
  k = 31;
       else if (inventory[23].tval != 0)
  k = 23;
       else if (inventory[27].tval != 0)
  k = 27;
       else if (inventory[30].tval != 0)
  k = 30;
       else
  k = 0;
       if (k > 0)
  {
    i_ptr = &inventory[k];
    objdes(tmp_str, i_ptr, 0);
    (void)sprintf(out_val,"Your %s glows black, fades.",tmp_str);
    msg_print(out_val);
    unmagic_name(i_ptr);
    i_ptr->flags = 0x80000000L;
    i_ptr->toac = -randint(5) - randint(5);
    calc_bonuses ();
    ident = 1;
  }
       break;
     case 37:
       ident = 0;
       for (k = 0; k < randint(3); k++)
  {
    y = char_row;
    x = char_col;
    ident |= summon_undead(&y, &x);
  }
       break;
     case 38:
       ident = 1;
       bless(randint(12)+6);
       break;
     case 39:
       ident = 1;
       bless(randint(24)+12);
       break;
     case 40:
       ident = 1;
       bless(randint(48)+24);
       break;
     case 41:
       ident = 1;
       if (py.flags.word_recall == 0)
  py.flags.word_recall = 25 + randint(30);
       msg_print("The air about you becomes charged.");
       break;
     case 42:
       destroy_area(char_row, char_col);
       ident = 1;
       break;
     default:
       msg_print("Internal error in scroll()");
       break;
     }
 }
      i_ptr = &inventory[item_val];
      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);
      if (used_up)
 {
   desc_remain(item_val);
   inven_destroy(item_val);
 }
    }
}

canonical_original_code:
void read_scroll()
{
  unsigned long i;
  int j; int k; int item_val; int y; int x;
  int tmp[6]; int flag; int used_up;
  char out_val[160]; char tmp_str[160];
  register int ident; register int l;
  register struct inven_type *i_ptr;
  register struct misc *m_ptr;
  free_turn_flag = 1;
  if (py.flags.blind > 0)
    msg_print("You can't see to read the scroll.");
  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 to read a scroll.");
  else if (inven_ctr == 0)
    msg_print("You are not carrying anything!");
  else if (!find_range(70, 71, &j, &k))
    msg_print ("You are not carrying any scrolls!");
  else if (get_item(&item_val, "Read which scroll?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = 0;
      used_up = 1;
      i = i_ptr->flags;
      ident = 0;
      while (i != 0)
 {
   j = bit_pos(&i) + 1;
   if (i_ptr->tval == 71)
     j += 32;
   switch(j)
     {
     case 1:
       i_ptr = &inventory[22];
       if (i_ptr->tval != 0)
  {
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
    msg_print(out_val);
    if (enchant(&i_ptr->tohit, 10))
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 2:
       i_ptr = &inventory[22];
       if (i_ptr->tval != 0)
  {
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
    msg_print(out_val);
    if ((i_ptr->tval >= 21)&&(i_ptr->tval <= 25))
      j = i_ptr->damage[0] * i_ptr->damage[1];
    else
      j = 10;
    if (enchant(&i_ptr->todam, j))
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses ();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 3:
       k = 0;
       l = 0;
       if (inventory[25].tval != 0)
  tmp[k++] = 25;
       if (inventory[26].tval != 0)
  tmp[k++] = 26;
       if (inventory[31].tval != 0)
  tmp[k++] = 31;
       if (inventory[27].tval != 0)
  tmp[k++] = 27;
       if (inventory[23].tval != 0)
  tmp[k++] = 23;
       if (inventory[30].tval != 0)
  tmp[k++] = 30;
       if (k > 0) l = tmp[randint(k)-1];
       if (0x80000000L & inventory[25].flags)
  l = 25;
       else if (0x80000000L & inventory[26].flags)
  l = 26;
       else if (0x80000000L & inventory[31].flags)
  l = 31;
       else if (0x80000000L & inventory[23].flags)
  l = 23;
       else if (0x80000000L & inventory[27].flags)
  l = 27;
       else if (0x80000000L & inventory[30].flags)
  l = 30;
       if (l > 0)
  {
    i_ptr = &inventory[l];
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val, "Your %s glows faintly!", tmp_str);
    msg_print(out_val);
    if (enchant(&i_ptr->toac, 10))
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses ();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 4:
       msg_print("This is an identify scroll.");
       ident = 1;
       used_up = ident_spell();
       while (i_ptr->tval != 70 || i_ptr->flags != 0x00000008)
  {
    item_val--;
    i_ptr = &inventory[item_val];
  }
       break;
     case 5:
       if (remove_curse())
  {
    msg_print("You feel as if someone is watching over you.");
    ident = 1;
  }
       break;
     case 6:
       ident = light_area(char_row, char_col);
       break;
     case 7:
       for (k = 0; k < randint(3); k++)
  {
    y = char_row;
    x = char_col;
    ident |= summon_monster(&y, &x, 0);
  }
       break;
     case 8:
       teleport(10);
       ident = 1;
       break;
     case 9:
       teleport(100);
       ident = 1;
       break;
     case 10:
       dun_level += (-3) + 2*randint(2);
       if (dun_level < 1)
  dun_level = 1;
       new_level_flag = 1;
       ident = 1;
       break;
     case 11:
       if (py.flags.confuse_monster == 0)
  {
    msg_print("Your hands begin to glow.");
    py.flags.confuse_monster = 1;
    ident = 1;
  }
       break;
     case 12:
       ident = 1;
       map_area();
       break;
     case 13:
       ident = sleep_monsters1(char_row, char_col);
       break;
     case 14:
       ident = 1;
       warding_glyph();
       break;
     case 15:
       ident = detect_treasure();
       break;
     case 16:
       ident = detect_object();
       break;
     case 17:
       ident = detect_trap();
       break;
     case 18:
       ident = detect_sdoor();
       break;
     case 19:
       msg_print("This is a mass genocide scroll.");
       ident = mass_genocide();
       break;
     case 20:
       ident = detect_invisible();
       break;
     case 21:
       ident = aggravate_monster(20);
       if (ident)
  msg_print("There is a high pitched humming noise.");
       break;
     case 22:
       ident = trap_creation();
       break;
     case 23:
       ident = td_destroy();
       break;
     case 24:
       ident = door_creation();
       break;
     case 25:
       msg_print("This is a Recharge-Item scroll.");
       ident = 1;
       used_up = recharge(60);
       break;
     case 26:
       msg_print("This is a genocide scroll.");
       ident = genocide();
       break;
     case 27:
       ident = unlight_area(char_row, char_col);
       break;
     case 28:
       ident = protect_evil();
       break;
     case 29:
       ident = 1;
       create_food();
       break;
     case 30:
       ident = dispel_creature(0x0008, 60);
       break;
     case 33:
       i_ptr = &inventory[22];
       if (i_ptr->tval != 0)
  {
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val, "Your %s glows brightly!", tmp_str);
    msg_print(out_val);
    flag = 0;
    for (k = 0; k < randint(2); k++)
      if (enchant(&i_ptr->tohit, 10))
        flag = 1;
    if ((i_ptr->tval >= 21)&&(i_ptr->tval <= 25))
      j = i_ptr->damage[0] * i_ptr->damage[1];
    else
      j = 10;
    for (k = 0; k < randint(2); k++)
      if (enchant(&i_ptr->todam, j))
        flag = 1;
    if (flag)
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses ();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 34:
       i_ptr = &inventory[22];
       if (i_ptr->tval != 0)
  {
    objdes(tmp_str, i_ptr, 0);
    (void)sprintf(out_val,"Your %s glows black, fades.",tmp_str);
    msg_print(out_val);
    unmagic_name(i_ptr);
    i_ptr->tohit = -randint(5) - randint(5);
    i_ptr->todam = -randint(5) - randint(5);
    py_bonuses(i_ptr, -1);
    i_ptr->flags = 0x80000000L;
    calc_bonuses ();
    ident = 1;
  }
       break;
     case 35:
       k = 0;
       l = 0;
       if (inventory[25].tval != 0)
  tmp[k++] = 25;
       if (inventory[26].tval != 0)
  tmp[k++] = 26;
       if (inventory[31].tval != 0)
  tmp[k++] = 31;
       if (inventory[27].tval != 0)
  tmp[k++] = 27;
       if (inventory[23].tval != 0)
  tmp[k++] = 23;
       if (inventory[30].tval != 0)
  tmp[k++] = 30;
       if (k > 0) l = tmp[randint(k)-1];
       if (0x80000000L & inventory[25].flags)
  l = 25;
       else if (0x80000000L & inventory[26].flags)
  l = 26;
       else if (0x80000000L & inventory[31].flags)
  l = 31;
       else if (0x80000000L & inventory[23].flags)
  l = 23;
       else if (0x80000000L & inventory[27].flags)
  l = 27;
       else if (0x80000000L & inventory[30].flags)
  l = 30;
       if (l > 0)
  {
    i_ptr = &inventory[l];
    objdes(tmp_str, i_ptr, 0);
    (void) sprintf(out_val,"Your %s glows brightly!", tmp_str);
    msg_print(out_val);
    flag = 0;
    for (k = 0; k < randint(2) + 1; k++)
      if (enchant(&i_ptr->toac, 10))
        flag = 1;
    if (flag)
      {
        i_ptr->flags &= ~0x80000000L;
        calc_bonuses ();
      }
    else
      msg_print("The enchantment fails.");
    ident = 1;
  }
       break;
     case 36:
       if ((inventory[25].tval != 0)
    && (randint(4) == 1))
  k = 25;
       else if ((inventory[26].tval != 0)
         && (randint(3) ==1))
  k = 26;
       else if ((inventory[31].tval != 0)
         && (randint(3) ==1))
  k = 31;
       else if ((inventory[23].tval != 0)
         && (randint(3) ==1))
  k = 23;
       else if ((inventory[27].tval != 0)
         && (randint(3) ==1))
  k = 27;
       else if ((inventory[30].tval != 0)
         && (randint(3) ==1))
  k = 30;
       else if (inventory[25].tval != 0)
  k = 25;
       else if (inventory[26].tval != 0)
  k = 26;
       else if (inventory[31].tval != 0)
  k = 31;
       else if (inventory[23].tval != 0)
  k = 23;
       else if (inventory[27].tval != 0)
  k = 27;
       else if (inventory[30].tval != 0)
  k = 30;
       else
  k = 0;
       if (k > 0)
  {
    i_ptr = &inventory[k];
    objdes(tmp_str, i_ptr, 0);
    (void)sprintf(out_val,"Your %s glows black, fades.",tmp_str);
    msg_print(out_val);
    unmagic_name(i_ptr);
    i_ptr->flags = 0x80000000L;
    i_ptr->toac = -randint(5) - randint(5);
    calc_bonuses ();
    ident = 1;
  }
       break;
     case 37:
       ident = 0;
       for (k = 0; k < randint(3); k++)
  {
    y = char_row;
    x = char_col;
    ident |= summon_undead(&y, &x);
  }
       break;
     case 38:
       ident = 1;
       bless(randint(12)+6);
       break;
     case 39:
       ident = 1;
       bless(randint(24)+12);
       break;
     case 40:
       ident = 1;
       bless(randint(48)+24);
       break;
     case 41:
       ident = 1;
       if (py.flags.word_recall == 0)
  py.flags.word_recall = 25 + randint(30);
       msg_print("The air about you becomes charged.");
       break;
     case 42:
       destroy_area(char_row, char_col);
       ident = 1;
       break;
     default:
       msg_print("Internal error in scroll()");
       break;
     }
 }
      i_ptr = &inventory[item_val];
      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);
      if (used_up)
 {
   desc_remain(item_val);
   inven_destroy(item_val);
 }
    }
}

variable_types:
i
unsigned long

variable_types: k int

variable_types: y int

variable_types: x int

variable_types:
tmp
int [6]

variable_types: flag int

variable_types: ident int

variable_types: l 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; } *

return_type: void

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


original_code:
int attack_blows(int weight, int *wtohit)
{
  register int adj_weight;
  register int str_index, dex_index, s, d;
  s = py.stats.use_stat[0];
  d = py.stats.use_stat[3];
  if (s * 15 < weight)
    {
      *wtohit = s * 15 - weight;
      return 1;
    }
  else
    {
      *wtohit = 0;
      if (d < 10) dex_index = 0;
      else if (d < 19) dex_index = 1;
      else if (d < 68) dex_index = 2;
      else if (d < 108) dex_index = 3;
      else if (d < 118) dex_index = 4;
      else dex_index = 5;
      adj_weight = (s * 10 / weight);
      if (adj_weight < 2) str_index = 0;
      else if (adj_weight < 3) str_index = 1;
      else if (adj_weight < 4) str_index = 2;
      else if (adj_weight < 5) str_index = 3;
      else if (adj_weight < 7) str_index = 4;
      else if (adj_weight < 9) str_index = 5;
      else str_index = 6;
      return (int)blows_table[str_index][dex_index];
    }
}

canonical_original_code:
int attack_blows(int weight, int *wtohit)
{
  register int adj_weight;
  register int str_index; register int dex_index; register int s; register int d;
  s = py.stats.use_stat[0];
  d = py.stats.use_stat[3];
  if (s * 15 < weight)
    {
      *wtohit = s * 15 - weight;
      return 1;
    }
  else
    {
      *wtohit = 0;
      if (d < 10) dex_index = 0;
      else if (d < 19) dex_index = 1;
      else if (d < 68) dex_index = 2;
      else if (d < 108) dex_index = 3;
      else if (d < 118) dex_index = 4;
      else dex_index = 5;
      adj_weight = (s * 10 / weight);
      if (adj_weight < 2) str_index = 0;
      else if (adj_weight < 3) str_index = 1;
      else if (adj_weight < 4) str_index = 2;
      else if (adj_weight < 5) str_index = 3;
      else if (adj_weight < 7) str_index = 4;
      else if (adj_weight < 9) str_index = 5;
      else str_index = 6;
      return (int)blows_table[str_index][dex_index];
    }
}

variable_types: weight int

variable_types:
wtohit
int *

variable_types: s int

variable_types: d int

return_type: int


original_code:
int critical_blow(register int weight, register int plus, register int dam,
                  int attack_type)
{
  register int critical;
  critical = dam;
  if (randint(5000) <= (int)(weight + 5 * plus
        + (class_level_adj[py.misc.pclass][attack_type]
    * py.misc.lev)))
    {
      weight += randint(650);
      if (weight < 400)
 {
   critical = 2*dam + 5;
   msg_print("It was a good hit! (x2 damage)");
 }
      else if (weight < 700)
 {
   critical = 3*dam + 10;
   msg_print("It was an excellent hit! (x3 damage)");
 }
      else if (weight < 900)
 {
   critical = 4*dam + 15;
   msg_print("It was a superb hit! (x4 damage)");
 }
      else
 {
   critical = 5*dam + 20;
   msg_print("It was a *GREAT* hit! (x5 damage)");
 }
    }
  return(critical);
}

canonical_original_code:
int critical_blow(int weight, int plus, int dam, int attack_type)
{
  register int critical;
  critical = dam;
  if (randint(5000) <= (int)(weight + 5 * plus
        + (class_level_adj[py.misc.pclass][attack_type]
    * py.misc.lev)))
    {
      weight += randint(650);
      if (weight < 400)
 {
   critical = 2*dam + 5;
   msg_print("It was a good hit! (x2 damage)");
 }
      else if (weight < 700)
 {
   critical = 3*dam + 10;
   msg_print("It was an excellent hit! (x3 damage)");
 }
      else if (weight < 900)
 {
   critical = 4*dam + 15;
   msg_print("It was a superb hit! (x4 damage)");
 }
      else
 {
   critical = 5*dam + 20;
   msg_print("It was a *GREAT* hit! (x5 damage)");
 }
    }
  return(critical);
}

variable_types: plus int

variable_types: dam int

variable_types: critical int


decompiled_code:
__int64 get_rnd_seed()
{
return rnd_seed;
}

canonical_decompiled_code:
__int64 func0()
{
return rnd_seed;
}

original_code:
int32u get_rnd_seed ()
{
  return rnd_seed;
}

canonical_original_code:
unsigned long get_rnd_seed()
{
  return rnd_seed;
}

return_type: unsigned long


rnd

decompiled_code:
signed __int64 rnd()
{
signed __int64 result; // rax

result = -2836LL * (rnd_seed / 0x1F31DuLL) + 16807 * (rnd_seed % 0x1F31DuLL);
if ( result <= 0 )
result += 0x7FFFFFFFLL;
rnd_seed = result;
return result;
}

canonical_decompiled_code:
signed __int64 func2()
{
signed __int64 result; // rax

result = -2836LL * (rnd_seed / 0x1F31DuLL) + 16807 * (rnd_seed % 0x1F31DuLL);
if ( result <= 0 )
result += 0x7FFFFFFFLL;
rnd_seed = result;
return result;
}

original_code:
int32 rnd ()
{
  register long low, high, test;
  high = rnd_seed / 127773L;
  low = rnd_seed % 127773L;
  test = 16807L * low - 2836L * high;
  if (test > 0)
    rnd_seed = test;
  else
    rnd_seed = test + 2147483647L;
  return rnd_seed;
}

canonical_original_code:
long rnd()
{
  register long low; register long high; register long test;
  high = rnd_seed / 127773L;
  low = rnd_seed % 127773L;
  test = 16807L * low - 2836L * high;
  if (test > 0)
    rnd_seed = test;
  else
    rnd_seed = test + 2147483647L;
  return rnd_seed;
}

variable_types: low long

variable_types: high long

variable_types: test long

return_type: long


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

result = find_flag;
if ( find_flag )
{
find_flag = 0;
result = move_light((unsigned int)char_row, (unsigned int)char_col, (unsigned int)char_row, (unsigned int)char_col);
}
return result;
}

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

result = find_flag;
if ( find_flag )
{
find_flag = 0;
result = move_light((unsigned int)char_row, (unsigned int)char_col, (unsigned int)char_row, (unsigned int)char_col);
}
return result;
}

original_code:
void end_find()
{
  if (find_flag)
    {
      find_flag = 0;
      move_light(char_row, char_col, char_row, char_col);
    }
}


decompiled_code:
__int64 find_run()
{
int v0; // eax

v0 = find_flag++;
if ( v0 <= 100 )
return move_char((unsigned int)find_direction, 1LL);
msg_print("You stop running to catch your breath.");
return end_find();
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax

v0 = find_flag++;
if ( v0 <= 100 )
return move_char((unsigned int)find_direction, 1LL);
msg_print("You stop running to catch your breath.");
return func4();
}

original_code:
void find_run()
{
  if (find_flag++ > 100)
    {
      msg_print("You stop running to catch your breath.");
      end_find();
    }
  else
    move_char(find_direction, 1);
}


eat

decompiled_code:
__int64 eat()
{
__int64 result; // rax
const char *v1; // rsi
__int64 v2; // r13
unsigned __int8 *v3; // r12
int v4; // ebp
int v5; // eax
__int64 v6; // rdx
unsigned int v7; // eax
unsigned int v8; // eax
__int64 v9; // rdi
unsigned int v10; // eax
unsigned int v11; // [rsp+0h] [rbp-3Ch] BYREF
unsigned int v12; // [rsp+4h] [rbp-38h] BYREF
unsigned int v13; // [rsp+8h] [rbp-34h] BYREF
__int64 v14[6]; // [rsp+Ch] [rbp-30h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(80LL, 0xFFFFFFFFLL, &v11, &v12) )
return msg_print("You are not carrying any food.");
v1 = "Eat what?";
result = get_item(&v13, "Eat what?", v11, v12, 0LL, 0LL);
if ( (_DWORD)result )
{
free_turn_flag = 0;
v2 = (int)v13;
v3 = &inventory[56 * v13];
v14[0] = *((_QWORD *)v3 + 2);
if ( !v14[0] )
goto LABEL_50;
v4 = 0;
do
{
v5 = bit_pos(v14);
v11 = v5 + 1;
switch ( v5 )
{
case 0:
v4 = v5 + 1;
*((_WORD *)&py + 211) += randint(10LL) + v3[54];
break;
case 1:
v4 = 1;
*((_WORD *)&py + 201) += randint(250LL) + 10 * v3[54] + 100;
draw_cave();
msg_print("A veil of darkness surrounds you.");
break;
case 2:
v4 = 1;
*((_WORD *)&py + 210) += randint(10LL) + v3[54];
msg_print("You feel terrified!");
break;
case 3:
v4 = 1;
*((_WORD *)&py + 203) += randint(10LL) + v3[54];
msg_print("You feel drugged.");
break;
case 4:
v4 = 1;
*((_WORD *)&py + 212) += 25 * v3[54] + randint(200LL) + 200;
msg_print("You feel drugged.");
break;
case 5:
v4 = cure_poison();
break;
case 6:
v4 = cure_blindness();
break;
case 7:
if ( *((__int16 *)&py + 210) > 1 )
{
v4 = 1;
*((_WORD *)&py + 210) = 1;
}
break;
case 8:
v4 = cure_confusion();
break;
case 9:
v4 = 1;
lose_str();
break;
case 10:
v4 = 1;
lose_con();
break;
case 15:
if ( (unsigned int)res_stat(0LL) )
{
v4 = 1;
msg_print("You feel your strength returning.");
}
break;
case 16:
if ( (unsigned int)res_stat(4LL) )
{
v4 = 1;
msg_print("You feel your health returning.");
}
break;
case 17:
if ( (unsigned int)res_stat(1LL) )
{
v4 = 1;
msg_print("Your head spins a moment.");
}
break;
case 18:
if ( (unsigned int)res_stat(2LL) )
{
v4 = 1;
msg_print("You feel your wisdom returning.");
}
break;
case 19:
if ( (unsigned int)res_stat(3LL) )
{
v4 = 1;
msg_print("You feel more dextrous.");
}
break;
case 20:
if ( (unsigned int)res_stat(5LL) )
{
v4 = 1;
msg_print("Your skin stops itching.");
}
break;
case 21:
v9 = 6LL;
goto LABEL_21;
case 22:
v9 = 12LL;
goto LABEL_21;
case 23:
v9 = 18LL;
LABEL_21:
v10 = randint(v9);
v4 = hp_player(v10);
break;
case 25:
v1 = (_BYTE *)(&loc_8 + 4);
v8 = damroll(3LL, 12LL);
v4 = hp_player(v8);
break;
case 26:
v4 = 1;
v7 = randint(18LL);
v1 = "poisonous food.";
take_hit(v7, "poisonous food.");
break;
default:
msg_print("Internal error in eat()");
break;
}
}
while ( v14[0] );
if ( v4 )
{
if ( !(unsigned int)known1_p(v3) )
{
v6 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) >> 31);
LODWORD(v6) = ((*((_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(v3, v1, v6);
identify(&v13);
v3 = &inventory[56 * v13];
}
}
else
{
LABEL_50:
if ( !(unsigned int)known1_p(v3) )
sample(v3);
}
add_food((unsigned int)*((__int16 *)v3 + 13));
*((_QWORD *)&py + 49) &= 0xFFFFFFFFFFFFFFFCLL;
prt_hunger();
desc_remain(v13);
result = inven_destroy(v13);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
const char *v1; // rsi
__int64 v2; // r13
unsigned __int8 *v3; // r12
int v4; // ebp
int v5; // eax
__int64 v6; // rdx
unsigned int v7; // eax
unsigned int v8; // eax
__int64 v9; // rdi
unsigned int v10; // eax
unsigned int v11; // [rsp+0h] [rbp-3Ch] BYREF
unsigned int v12; // [rsp+4h] [rbp-38h] BYREF
unsigned int v13; // [rsp+8h] [rbp-34h] BYREF
__int64 v14[6]; // [rsp+Ch] [rbp-30h] BYREF

free_turn_flag = 1;
if ( !inven_ctr )
return msg_print("But you are not carrying anything.");
if ( !(unsigned int)find_range(80LL, 0xFFFFFFFFLL, &v11, &v12) )
return msg_print("You are not carrying any food.");
v1 = "Eat what?";
result = get_item(&v13, "Eat what?", v11, v12, 0LL, 0LL);
if ( (_DWORD)result )
{
free_turn_flag = 0;
v2 = (int)v13;
v3 = &inventory[56 * v13];
v14[0] = *((_QWORD *)v3 + 2);
if ( !v14[0] )
goto LABEL_50;
v4 = 0;
do
{
v5 = bit_pos(v14);
v11 = v5 + 1;
switch ( v5 )
{
case 0:
v4 = v5 + 1;
*((_WORD *)&py + 211) += randint(10LL) + v3[54];
break;
case 1:
v4 = 1;
*((_WORD *)&py + 201) += randint(250LL) + 10 * v3[54] + 100;
draw_cave();
msg_print("A veil of darkness surrounds you.");
break;
case 2:
v4 = 1;
*((_WORD *)&py + 210) += randint(10LL) + v3[54];
msg_print("You feel terrified!");
break;
case 3:
v4 = 1;
*((_WORD *)&py + 203) += randint(10LL) + v3[54];
msg_print("You feel drugged.");
break;
case 4:
v4 = 1;
*((_WORD *)&py + 212) += 25 * v3[54] + randint(200LL) + 200;
msg_print("You feel drugged.");
break;
case 5:
v4 = cure_poison();
break;
case 6:
v4 = cure_blindness();
break;
case 7:
if ( *((__int16 *)&py + 210) > 1 )
{
v4 = 1;
*((_WORD *)&py + 210) = 1;
}
break;
case 8:
v4 = cure_confusion();
break;
case 9:
v4 = 1;
lose_str();
break;
case 10:
v4 = 1;
lose_con();
break;
case 15:
if ( (unsigned int)res_stat(0LL) )
{
v4 = 1;
msg_print("You feel your strength returning.");
}
break;
case 16:
if ( (unsigned int)res_stat(4LL) )
{
v4 = 1;
msg_print("You feel your health returning.");
}
break;
case 17:
if ( (unsigned int)res_stat(1LL) )
{
v4 = 1;
msg_print("Your head spins a moment.");
}
break;
case 18:
if ( (unsigned int)res_stat(2LL) )
{
v4 = 1;
msg_print("You feel your wisdom returning.");
}
break;
case 19:
if ( (unsigned int)res_stat(3LL) )
{
v4 = 1;
msg_print("You feel more dextrous.");
}
break;
case 20:
if ( (unsigned int)res_stat(5LL) )
{
v4 = 1;
msg_print("Your skin stops itching.");
}
break;
case 21:
v9 = 6LL;
goto LABEL_21;
case 22:
v9 = 12LL;
goto LABEL_21;
case 23:
v9 = 18LL;
LABEL_21:
v10 = randint(v9);
v4 = hp_player(v10);
break;
case 25:
v1 = (_BYTE *)(&loc_8 + 4);
v8 = damroll(3LL, 12LL);
v4 = hp_player(v8);
break;
case 26:
v4 = 1;
v7 = randint(18LL);
v1 = "poisonous food.";
take_hit(v7, "poisonous food.");
break;
default:
msg_print("Internal error in eat()");
break;
}
}
while ( v14[0] );
if ( v4 )
{
if ( !(unsigned int)known1_p(v3) )
{
v6 = (unsigned int)(((*((_WORD *)&py + 32) >> 1) + inventory[56 * v2 + 54]) >> 31);
LODWORD(v6) = ((*((_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(v3, v1, v6);
identify(&v13);
v3 = &inventory[56 * v13];
}
}
else
{
LABEL_50:
if ( !(unsigned int)known1_p(v3) )
sample(v3);
}
add_food((unsigned int)*((__int16 *)v3 + 13));
*((_QWORD *)&py + 49) &= 0xFFFFFFFFFFFFFFFCLL;
prt_hunger();
desc_remain(v13);
result = inven_destroy(v13);
}
return result;
}

original_code:
void eat()
{
  int32u i;
  int j, k, item_val, ident;
  register struct flags *f_ptr;
  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(80, -1, &j, &k))
    msg_print("You are not carrying any food.");
  else if (get_item(&item_val, "Eat what?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = 0;
      i = i_ptr->flags;
      ident = 0;
      while (i != 0)
 {
   j = bit_pos(&i) + 1;
   switch(j)
     {
     case 1:
       f_ptr = &py.flags;
       f_ptr->poisoned += randint(10) + i_ptr->level;
       ident = 1;
       break;
     case 2:
       f_ptr = &py.flags;
       f_ptr->blind += randint(250) + 10*i_ptr->level + 100;
       draw_cave();
       msg_print("A veil of darkness surrounds you.");
       ident = 1;
       break;
     case 3:
       f_ptr = &py.flags;
       f_ptr->afraid += randint(10) + i_ptr->level;
       msg_print("You feel terrified!");
       ident = 1;
       break;
     case 4:
       f_ptr = &py.flags;
       f_ptr->confused += randint(10) + i_ptr->level;
       msg_print("You feel drugged.");
       ident = 1;
       break;
     case 5:
       f_ptr = &py.flags;
       f_ptr->image += randint(200) + 25*i_ptr->level + 200;
       msg_print("You feel drugged.");
       ident = 1;
       break;
     case 6:
       ident = cure_poison();
       break;
     case 7:
       ident = cure_blindness();
       break;
     case 8:
       f_ptr = &py.flags;
       if (f_ptr->afraid > 1)
  {
    f_ptr->afraid = 1;
    ident = 1;
  }
       break;
     case 9:
       ident = cure_confusion();
       break;
     case 10:
       ident = 1;
       lose_str();
       break;
     case 11:
       ident = 1;
       lose_con();
       break;
     case 16:
       if (res_stat (0))
  {
    msg_print("You feel your strength returning.");
    ident = 1;
  }
       break;
     case 17:
       if (res_stat (4))
  {
    msg_print("You feel your health returning.");
    ident = 1;
  }
       break;
     case 18:
       if (res_stat (1))
  {
    msg_print("Your head spins a moment.");
    ident = 1;
  }
       break;
     case 19:
       if (res_stat (2))
  {
    msg_print("You feel your wisdom returning.");
    ident = 1;
  }
       break;
     case 20:
       if (res_stat (3))
  {
    msg_print("You feel more dextrous.");
    ident = 1;
  }
       break;
     case 21:
       if (res_stat (5))
  {
    msg_print("Your skin stops itching.");
    ident = 1;
  }
       break;
     case 22:
       ident = hp_player(randint(6));
       break;
     case 23:
       ident = hp_player(randint(12));
       break;
     case 24:
       ident = hp_player(randint(18));
       break;
     case 26:
       ident = hp_player(damroll(3, 12));
       break;
     case 27:
       take_hit(randint(18), "poisonous food.");
       ident = 1;
       break;
     default:
       msg_print("Internal error in eat()");
       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);
      py.flags.status &= ~(0x00000002L|0x00000001L);
      prt_hunger();
      desc_remain(item_val);
      inven_destroy(item_val);
    }
}

canonical_original_code:
void eat()
{
  unsigned long i;
  int j; int k; int item_val; int ident;
  register struct flags *f_ptr;
  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(80, -1, &j, &k))
    msg_print("You are not carrying any food.");
  else if (get_item(&item_val, "Eat what?", j, k, (char *)0, (char *)0))
    {
      i_ptr = &inventory[item_val];
      free_turn_flag = 0;
      i = i_ptr->flags;
      ident = 0;
      while (i != 0)
 {
   j = bit_pos(&i) + 1;
   switch(j)
     {
     case 1:
       f_ptr = &py.flags;
       f_ptr->poisoned += randint(10) + i_ptr->level;
       ident = 1;
       break;
     case 2:
       f_ptr = &py.flags;
       f_ptr->blind += randint(250) + 10*i_ptr->level + 100;
       draw_cave();
       msg_print("A veil of darkness surrounds you.");
       ident = 1;
       break;
     case 3:
       f_ptr = &py.flags;
       f_ptr->afraid += randint(10) + i_ptr->level;
       msg_print("You feel terrified!");
       ident = 1;
       break;
     case 4:
       f_ptr = &py.flags;
       f_ptr->confused += randint(10) + i_ptr->level;
       msg_print("You feel drugged.");
       ident = 1;
       break;
     case 5:
       f_ptr = &py.flags;
       f_ptr->image += randint(200) + 25*i_ptr->level + 200;
       msg_print("You feel drugged.");
       ident = 1;
       break;
     case 6:
       ident = cure_poison();
       break;
     case 7:
       ident = cure_blindness();
       break;
     case 8:
       f_ptr = &py.flags;
       if (f_ptr->afraid > 1)
  {
    f_ptr->afraid = 1;
    ident = 1;
  }
       break;
     case 9:
       ident = cure_confusion();
       break;
     case 10:
       ident = 1;
       lose_str();
       break;
     case 11:
       ident = 1;
       lose_con();
       break;
     case 16:
       if (res_stat (0))
  {
    msg_print("You feel your strength returning.");
    ident = 1;
  }
       break;
     case 17:
       if (res_stat (4))
  {
    msg_print("You feel your health returning.");
    ident = 1;
  }
       break;
     case 18:
       if (res_stat (1))
  {
    msg_print("Your head spins a moment.");
    ident = 1;
  }
       break;
     case 19:
       if (res_stat (2))
  {
    msg_print("You feel your wisdom returning.");
    ident = 1;
  }
       break;
     case 20:
       if (res_stat (3))
  {
    msg_print("You feel more dextrous.");
    ident = 1;
  }
       break;
     case 21:
       if (res_stat (5))
  {
    msg_print("Your skin stops itching.");
    ident = 1;
  }
       break;
     case 22:
       ident = hp_player(randint(6));
       break;
     case 23:
       ident = hp_player(randint(12));
       break;
     case 24:
       ident = hp_player(randint(18));
       break;
     case 26:
       ident = hp_player(damroll(3, 12));
       break;
     case 27:
       take_hit(randint(18), "poisonous food.");
       ident = 1;
       break;
     default:
       msg_print("Internal error in eat()");
       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);
      py.flags.status &= ~(0x00000002L|0x00000001L);
      prt_hunger();
      desc_remain(item_val);
      inven_destroy(item_val);
    }
}

variable_types:
i
unsigned long

variable_types: j int

variable_types: k int

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

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

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:
int32 item_value(register inven_type *i_ptr)
{
  register int32 value;
  value = i_ptr->cost;
  if (i_ptr->ident & 0x2)
    value = 0;
  else if (((i_ptr->tval >= 20) && (i_ptr->tval <= 23)) ||
    ((i_ptr->tval >= 30) && (i_ptr->tval <= 36)))
    {
      if (!known2_p(i_ptr))
 value = object_list[i_ptr->index].cost;
      else if ((i_ptr->tval >= 20) && (i_ptr->tval <= 23))
 {
   if (i_ptr->tohit < 0)
     value = 0;
   else if (i_ptr->todam < 0)
     value = 0;
   else if (i_ptr->toac < 0)
     value = 0;
   else
     value = i_ptr->cost+(i_ptr->tohit+i_ptr->todam+i_ptr->toac)*100;
 }
      else
 {
   if (i_ptr->toac < 0)
     value = 0;
   else
     value = i_ptr->cost+i_ptr->toac*100;
 }
    }
  else if ((i_ptr->tval >= 10) && (i_ptr->tval <= 13))
    {
      if (!known2_p(i_ptr))
 value = object_list[i_ptr->index].cost;
      else
 {
   if (i_ptr->tohit < 0)
     value = 0;
   else if (i_ptr->todam < 0)
     value = 0;
   else if (i_ptr->toac < 0)
     value = 0;
   else
     value = i_ptr->cost+(i_ptr->tohit+i_ptr->todam+i_ptr->toac)*5;
 }
    }
  else if ((i_ptr->tval == 70) || (i_ptr->tval == 71) ||
    (i_ptr->tval == 75) || (i_ptr->tval == 76))
    {
      if (!known1_p(i_ptr))
 value = 20;
    }
  else if (i_ptr->tval == 80)
    {
      if ((i_ptr->subval < (64 + 22))
   && !known1_p(i_ptr))
 value = 1;
    }
  else if ((i_ptr->tval == 40) || (i_ptr->tval == 45))
    {
      if (!known1_p(i_ptr))
 value = 45;
      else if (!known2_p(i_ptr))
 value = object_list[i_ptr->index].cost;
    }
  else if ((i_ptr->tval == 55) || (i_ptr->tval == 65))
    {
      if (!known1_p(i_ptr))
 {
   if (i_ptr->tval == 65)
     value = 50;
   else
     value = 70;
 }
      else if (known2_p(i_ptr))
 value = i_ptr->cost + (i_ptr->cost / 20) * i_ptr->p1;
    }
  else if (i_ptr->tval == 25)
    {
      if (!known2_p(i_ptr))
 value = object_list[i_ptr->index].cost;
      else
 {
   if (i_ptr->p1 < 0)
     value = 0;
   else
     {
       value = i_ptr->cost
  + (i_ptr->p1 - object_list[i_ptr->index].p1) * 100;
       if (value < 0)
  value = 0;
     }
 }
    }
  if (i_ptr->subval > 192)
    value = value * i_ptr->number;
  return(value);
}

canonical_original_code:
long item_value(struct inven_type *i_ptr)
{
  register long value;
  value = i_ptr->cost;
  if (i_ptr->ident & 0x2)
    value = 0;
  else if (((i_ptr->tval >= 20) && (i_ptr->tval <= 23)) ||
    ((i_ptr->tval >= 30) && (i_ptr->tval <= 36)))
    {
      if (!known2_p(i_ptr))
 value = object_list[i_ptr->index].cost;
      else if ((i_ptr->tval >= 20) && (i_ptr->tval <= 23))
 {
   if (i_ptr->tohit < 0)
     value = 0;
   else if (i_ptr->todam < 0)
     value = 0;
   else if (i_ptr->toac < 0)
     value = 0;
   else
     value = i_ptr->cost+(i_ptr->tohit+i_ptr->todam+i_ptr->toac)*100;
 }
      else
 {
   if (i_ptr->toac < 0)
     value = 0;
   else
     value = i_ptr->cost+i_ptr->toac*100;
 }
    }
  else if ((i_ptr->tval >= 10) && (i_ptr->tval <= 13))
    {
      if (!known2_p(i_ptr))
 value = object_list[i_ptr->index].cost;
      else
 {
   if (i_ptr->tohit < 0)
     value = 0;
   else if (i_ptr->todam < 0)
     value = 0;
   else if (i_ptr->toac < 0)
     value = 0;
   else
     value = i_ptr->cost+(i_ptr->tohit+i_ptr->todam+i_ptr->toac)*5;
 }
    }
  else if ((i_ptr->tval == 70) || (i_ptr->tval == 71) ||
    (i_ptr->tval == 75) || (i_ptr->tval == 76))
    {
      if (!known1_p(i_ptr))
 value = 20;
    }
  else if (i_ptr->tval == 80)
    {
      if ((i_ptr->subval < (64 + 22))
   && !known1_p(i_ptr))
 value = 1;
    }
  else if ((i_ptr->tval == 40) || (i_ptr->tval == 45))
    {
      if (!known1_p(i_ptr))
 value = 45;
      else if (!known2_p(i_ptr))
 value = object_list[i_ptr->index].cost;
    }
  else if ((i_ptr->tval == 55) || (i_ptr->tval == 65))
    {
      if (!known1_p(i_ptr))
 {
   if (i_ptr->tval == 65)
     value = 50;
   else
     value = 70;
 }
      else if (known2_p(i_ptr))
 value = i_ptr->cost + (i_ptr->cost / 20) * i_ptr->p1;
    }
  else if (i_ptr->tval == 25)
    {
      if (!known2_p(i_ptr))
 value = object_list[i_ptr->index].cost;
      else
 {
   if (i_ptr->p1 < 0)
     value = 0;
   else
     {
       value = i_ptr->cost
  + (i_ptr->p1 - object_list[i_ptr->index].p1) * 100;
       if (value < 0)
  value = 0;
     }
 }
    }
  if (i_ptr->subval > 192)
    value = value * i_ptr->number;
  return(value);
}

variable_types: value long