itemweight

repo: RoguelikeRestorationProject/urogue

decompiled_code:
__int64 __fastcall itemweight(__int64 a1)
{
char v1; // dl
__int64 result; // rax
__int64 v3; // rdx

v1 = *(_BYTE *)(a1 + 64);
result = *(unsigned int *)(a1 + 96);
if ( v1 == 41 )
{
if ( *(_DWORD *)(a1 + 80) + *(_DWORD *)(a1 + 84) > 0 )
result = (unsigned int)((int)result / 2);
}
else if ( v1 == 93 )
{
result = (unsigned int)((10 - (armors[8 * *(int *)(a1 + 76) + 5] - *(_DWORD *)(a1 + 88))) / 10 * result);
}
v3 = *(_QWORD *)(a1 + 48);
if ( (v3 & 1) != 0 )
{
result = (unsigned int)((int)result / 2 + result);
goto LABEL_6;
}
if ( (v3 & 0x20) == 0 )
{
LABEL_6:
if ( (int)result < 0 )
result = 0LL;
return result;
}
result = (unsigned int)((int)result / -5 + result);
if ( (int)result < 0 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
char v1; // dl
__int64 result; // rax
__int64 v3; // rdx

v1 = *(_BYTE *)(a1 + 64);
result = *(unsigned int *)(a1 + 96);
if ( v1 == 41 )
{
if ( *(_DWORD *)(a1 + 80) + *(_DWORD *)(a1 + 84) > 0 )
result = (unsigned int)((int)result / 2);
}
else if ( v1 == 93 )
{
result = (unsigned int)((10 - (armors[8 * *(int *)(a1 + 76) + 5] - *(_DWORD *)(a1 + 88))) / 10 * result);
}
v3 = *(_QWORD *)(a1 + 48);
if ( (v3 & 1) != 0 )
{
result = (unsigned int)((int)result / 2 + result);
goto LABEL_6;
}
if ( (v3 & 0x20) == 0 )
{
LABEL_6:
if ( (int)result < 0 )
result = 0LL;
return result;
}
result = (unsigned int)((int)result / -5 + result);
if ( (int)result < 0 )
result = 0LL;
return result;
}

original_code:
int
itemweight(struct object *wh)
{
    int weight = wh->o_weight;
    int ac;
    switch (wh->o_type)
    {
        case ']':
            ac = armors[wh->o_which].a_class - wh->o_ac;
            weight *= (10 - ac) / 10;
            break;
        case ')':
            if ((wh->o_hplus + wh->o_dplus) > 0)
                weight /= 2;
    }
    if (wh->o_flags & 0x00000001UL)
        weight += weight / 2;
    else if (wh->o_flags & 0x00000020UL)
        weight -= weight / 5;
    if (weight < 0)
        weight = 0;
    return (weight);
}

variable_types: struct object { struct coord { int x; int y; } o_pos; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *

variable_types: weight int

variable_types: ac int

user_defined_types: struct object { struct coord o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; }

user_defined_types: struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing *th; void *l_data; } data; }

user_defined_types: struct thing { long chasee_index; struct linked_list *t_pack; struct stats t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; }


packweight

decompiled_code:
__int64 packweight()
{
_QWORD *v0; // rsi
__int64 v1; // rdi
int v2; // eax
int v3; // er8
int v4; // er8
__int64 result; // rax

v0 = (_QWORD *)player[2];
if ( !v0 )
return 0LL;
do
{
v1 = v0[2];
v2 = itemweight(v1);
v0 = (_QWORD *)*v0;
v4 = *(_DWORD *)(v1 + 72) * v2 + v3;
}
while ( v0 );
result = 0LL;
if ( v4 >= 0 )
result = (unsigned int)v4;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rsi
__int64 v1; // rdi
int v2; // eax
int v3; // er8
int v4; // er8
__int64 result; // rax

v0 = (_QWORD *)player[2];
if ( !v0 )
return 0LL;
do
{
v1 = v0[2];
v2 = func0(v1);
v0 = (_QWORD *)*v0;
v4 = *(_DWORD *)(v1 + 72) * v2 + v3;
}
while ( v0 );
result = 0LL;
if ( v4 >= 0 )
result = (unsigned int)v4;
return result;
}

original_code:
int
packweight(void)
{
    struct linked_list *pc;
    int weight = 0;
    for (pc = player.t_pack; pc != ((void *)0); pc = ((pc)?(pc->l_next):((void *)0)))
    {
        struct object *obj = ((*pc).data.obj);
        weight += itemweight(obj) * obj->o_count;
    }
    if (weight < 0)
        weight = 0;
    return (weight);
}

canonical_original_code:
int packweight()
{
    struct linked_list *pc;
    int weight = 0;
    for (pc = player.t_pack; pc != ((void *)0); pc = ((pc)?(pc->l_next):((void *)0)))
    {
        struct object *obj = ((*pc).data.obj);
        weight += itemweight(obj) * obj->o_count;
    }
    if (weight < 0)
        weight = 0;
    return (weight);
}

variable_types: struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object { struct coord { int x; int y; } o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *

return_type: int


playenc

decompiled_code:
__int64 playenc()
{
unsigned int v0; // er12
__int64 result; // rax

v0 = 50 * (LODWORD(player[9]) - 10);
if ( (unsigned int)is_wearing(19LL) )
result = 300 * (unsigned int)ring_value(19LL) + v0;
else
result = v0;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er12
__int64 result; // rax

v0 = 50 * (LODWORD(player[9]) - 10);
if ( (unsigned int)is_wearing(19LL) )
result = 300 * (unsigned int)ring_value(19LL) + v0;
else
result = v0;
return result;
}

original_code:
int
playenc(void)
{
    int ret_val = (player.t_stats.s_str - 10) * 50;
    if (is_wearing(19))
        ret_val += ring_value(19) * 300;
    return (ret_val);
}

canonical_original_code:
int playenc()
{
    int ret_val = (player.t_stats.s_str - 10) * 50;
    if (is_wearing(19))
        ret_val += ring_value(19) * 300;
    return (ret_val);
}


totalenc

decompiled_code:
__int64 totalenc()
{
int v0; // eax
int v1; // er8
__int64 result; // rax
int v3; // eax

v0 = playenc();
v1 = v0 + 1400;
if ( hungry_state == 2 )
{
v3 = v0 + 1403;
if ( v1 >= 0 )
v3 = v1;
result = (unsigned int)(v1 - (v3 >> 2));
}
else
{
if ( hungry_state == 3 )
v1 /= 2;
result = (unsigned int)v1;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
int v1; // er8
__int64 result; // rax
int v3; // eax

v0 = func2();
v1 = v0 + 1400;
if ( hungry_state == 2 )
{
v3 = v0 + 1403;
if ( v1 >= 0 )
v3 = v1;
result = (unsigned int)(v1 - (v3 >> 2));
}
else
{
if ( hungry_state == 3 )
v1 /= 2;
result = (unsigned int)v1;
}
return result;
}

original_code:
int
totalenc(void)
{
    int wtotal = 1400 + playenc();
    switch (hungry_state)
    {
        case 0:
        case 1:
            break;
        case 2:
            wtotal -= wtotal / 4;
            break;
        case 3:
            wtotal /= 2;
            break;
    }
    return (wtotal);
}

canonical_original_code:
int totalenc()
{
    int wtotal = 1400 + playenc();
    switch (hungry_state)
    {
        case 0:
        case 1:
            break;
        case 2:
            wtotal -= wtotal / 4;
            break;
        case 3:
            wtotal /= 2;
            break;
    }
    return (wtotal);
}

variable_types: wtotal int


updpack

decompiled_code:
__int64 __fastcall updpack(__int64 a1, __int64 a2)
{
int v2; // ebx
int v3; // eax
int v4; // ecx
__int64 v5; // rdx
int v6; // eax
__int64 result; // rax

v2 = packweight();
HIDWORD(player[6]) = totalenc();
v3 = is_carrying(0LL);
v4 = HIDWORD(player[6]);
if ( v3 )
{
v4 = HIDWORD(player[6]) + 1000;
HIDWORD(player[6]) = v4;
}
foodlev = 0;
v5 = (unsigned int)((5 * v2) >> 31);
LODWORD(v5) = 5 * v2 % v4;
switch ( 5 * v2 / v4 )
{
case 0:
v6 = 1;
goto LABEL_13;
case 1:
goto LABEL_11;
case 2:
goto LABEL_9;
case 3:
goto LABEL_7;
case 4:
goto LABEL_5;
case 5:
foodlev = 1;
LABEL_5:
if ( (int)rnd(100LL, a2, v5) <= 79 )
++foodlev;
LABEL_7:
if ( (int)rnd(100LL, a2, v5) <= 59 )
++foodlev;
LABEL_9:
if ( (int)rnd(100LL, a2, v5) <= 39 )
++foodlev;
LABEL_11:
if ( (int)rnd(100LL, a2, v5) <= 19 )
v6 = foodlev + 2;
else
v6 = foodlev + 1;
LABEL_13:
foodlev = v6;
break;
default:
break;
}
LODWORD(player[6]) = v2;
result = is_carrying(0LL);
if ( (_DWORD)result )
--foodlev;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
int v2; // ebx
int v3; // eax
int v4; // ecx
__int64 v5; // rdx
int v6; // eax
__int64 result; // rax

v2 = func1();
HIDWORD(player[6]) = func3();
v3 = is_carrying(0LL);
v4 = HIDWORD(player[6]);
if ( v3 )
{
v4 = HIDWORD(player[6]) + 1000;
HIDWORD(player[6]) = v4;
}
foodlev = 0;
v5 = (unsigned int)((5 * v2) >> 31);
LODWORD(v5) = 5 * v2 % v4;
switch ( 5 * v2 / v4 )
{
case 0:
v6 = 1;
goto LABEL_13;
case 1:
goto LABEL_11;
case 2:
goto LABEL_9;
case 3:
goto LABEL_7;
case 4:
goto LABEL_5;
case 5:
foodlev = 1;
LABEL_5:
if ( (int)rnd(100LL, a2, v5) <= 79 )
++foodlev;
LABEL_7:
if ( (int)rnd(100LL, a2, v5) <= 59 )
++foodlev;
LABEL_9:
if ( (int)rnd(100LL, a2, v5) <= 39 )
++foodlev;
LABEL_11:
if ( (int)rnd(100LL, a2, v5) <= 19 )
v6 = foodlev + 2;
else
v6 = foodlev + 1;
LABEL_13:
foodlev = v6;
break;
default:
break;
}
LODWORD(player[6]) = v2;
result = is_carrying(0LL);
if ( (_DWORD)result )
--foodlev;
return result;
}

original_code:
void
updpack(void)
{
    int curcarry = packweight();
    player.t_stats.s_carry = totalenc();
    if (is_carrying(0))
        player.t_stats.s_carry += 1000;
    foodlev = 0;
    switch ((curcarry * 5) / player.t_stats.s_carry)
    {
        case 5:
            foodlev++;
        case 4:
            if (rnd(100) < 80)
                foodlev++;
        case 3:
            if (rnd(100) < 60)
                foodlev++;
        case 2:
            if (rnd(100) < 40)
                foodlev++;
        case 1:
            if (rnd(100) < 20)
                foodlev++;
        case 0:
            foodlev++;
    }
    player.t_stats.s_pack = curcarry;
    if (is_carrying(0))
        foodlev--;
}

canonical_original_code:
void updpack()
{
    int curcarry = packweight();
    player.t_stats.s_carry = totalenc();
    if (is_carrying(0))
        player.t_stats.s_carry += 1000;
    foodlev = 0;
    switch ((curcarry * 5) / player.t_stats.s_carry)
    {
        case 5:
            foodlev++;
        case 4:
            if (rnd(100) < 80)
                foodlev++;
        case 3:
            if (rnd(100) < 60)
                foodlev++;
        case 2:
            if (rnd(100) < 40)
                foodlev++;
        case 1:
            if (rnd(100) < 20)
                foodlev++;
        case 0:
            foodlev++;
    }
    player.t_stats.s_pack = curcarry;
    if (is_carrying(0))
        foodlev--;
}

variable_types: curcarry int

return_type: void


hitweight

decompiled_code:
__int64 hitweight()
{
return (unsigned int)(3 - foodlev);
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)(3 - foodlev);
}

original_code:
int
hitweight(void)
{
    return(3 - foodlev);
}

canonical_original_code:
int hitweight()
{
    return(3 - foodlev);
}


fatal

decompiled_code:
void __fastcall __noreturn fatal(const char *a1)
{
wclear(stdscr);
wmove(stdscr, LINES - 2, 0);
printw("%s", a1);
wrefresh(stdscr);
endwin();
putchar(10);
exit(100);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
wclear(stdscr);
wmove(stdscr, LINES - 2, 0);
printw("%s", a1);
wrefresh(stdscr);
endwin();
putchar(10);
exit(100);
}

original_code:
void
fatal(char *s)
{
    wclear(stdscr);
    wmove(stdscr,(LINES - 2),(0));
    printw("%s", s);
    wrefresh(stdscr);
    endwin();
    printf("\n");
    exit(100);
}

variable_types:
s
char *


ucrnd

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

if ( (_BYTE)a1 )
result = (ur_random() & 0x7FFFFFFF) % (unsigned __int8)a1;
else
result = a1;
return result;
}

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

if ( (_BYTE)a1 )
result = (ur_random() & 0x7FFFFFFF) % (unsigned __int8)a1;
else
result = a1;
return result;
}

original_code:
unsigned char
ucrnd(unsigned char range)
{
    return (unsigned char)(range <= 0 ? 0 : (ur_random() & 0x7fffffffL) % range);
}

variable_types:
range
unsigned char

return_type: unsigned char


srnd

decompiled_code:
__int64 __fastcall srnd(__int16 a1)
{
__int64 result; // rax

if ( a1 > 0 )
result = (unsigned int)((ur_random() & 0x7FFFFFFF) % a1);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1)
{
__int64 result; // rax

if ( a1 > 0 )
result = (unsigned int)((ur_random() & 0x7FFFFFFF) % a1);
else
result = 0LL;
return result;
}

original_code:
short
srnd(short range)
{
    return (short)(range <= 0 ? 0 : (ur_random() & 0x7fffffffL) % range);
}

variable_types: range short

return_type: short


rnd

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

result = 0LL;
if ( a1 > 0 )
result = (unsigned int)((ur_random() & 0x7FFFFFFF) % a1);
return result;
}

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

result = 0LL;
if ( a1 > 0 )
result = (unsigned int)((ur_random() & 0x7FFFFFFF) % a1);
return result;
}

original_code:
int
rnd(int range)
{
    return (range <= 0 ? 0 : (ur_random() & 0x7fffffffL) % range);
}

variable_types: range int


ulrnd

decompiled_code:
unsigned __int64 __fastcall ulrnd(unsigned __int64 a1)
{
unsigned __int64 result; // rax

if ( a1 )
result = (ur_random() & 0x7FFFFFFFuLL) % a1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(unsigned __int64 a1)
{
unsigned __int64 result; // rax

if ( a1 )
result = (ur_random() & 0x7FFFFFFFuLL) % a1;
else
result = 0LL;
return result;
}

original_code:
unsigned long
ulrnd(unsigned long range)
{
    return(range <= 0 ? 0 : (ur_random() & 0x7fffffffL) % range);
}

variable_types:
range
unsigned long

return_type: unsigned long


roll

decompiled_code:
__int64 __fastcall roll(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // er12

if ( !a1 )
return 0LL;
v2 = a1;
v3 = 0;
do
{
v3 += rnd(a2) + 1;
--v2;
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // er12

if ( !a1 )
return 0LL;
v2 = a1;
v3 = 0;
do
{
v3 += func3(a2) + 1;
--v2;
}
while ( v2 );
return v3;
}

original_code:
int
roll(int number, int sides)
{
    int dtotal = 0;
    while (number--)
        dtotal += rnd(sides) + 1;
    return(dtotal);
}

variable_types: number int

variable_types: sides int

variable_types: dtotal int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // rbx
const char **v5; // rdx
int v6; // edi
int v7; // esi
const char *v8; // rax
char *v9; // rax
char *v10; // r13
char *v11; // rsi
int v12; // er12
int v13; // edi
int v14; // eax
__int64 v15; // rax
bool v16; // zf
int v17; // eax
__int64 v18; // rax
char *v19; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v3 = argc;
v4 = argv;
if ( argc <= 1 )
{
v7 = 1;
}
else
{
v5 = argv + 1;
v6 = 0;
v7 = 1;
do
{
v8 = *v5;
if ( **v5 != 45 )
break;
switch ( v8[1] )
{
case 's':
prscore = 1;
break;
case 'v':
prversion = 1;
break;
case 'r':
v6 = 1;
break;
default:
fprintf(stderr, "%s: Unknown option '%c'.\n", *v4, (unsigned int)v8[1]);
exit(1);
}
++v7;
++v5;
}
while ( v3 != v7 );
if ( v6 )
{
LABEL_11:
strcpy(&score_file, "urogue.scr");
fd_score = (__int64)fopen(&score_file, "r+");
if ( !fd_score )
fd_score = (__int64)fopen(&score_file, "a+");
v9 = getenv("OPTIONS");
v10 = v9;
if ( v9 )
parse_opts(v9);
v11 = getenv("USER");
if ( v11 )
{
strcpy(&whoami, v11);
}
else
{
*((_WORD *)&whoami + 4) = 115;
*(_QWORD *)&whoami = 0x756F6D796E6F6E61LL;
}
v12 = time(&timer);
if ( wizard && getenv("SEED") )
{
v19 = getenv("SEED");
v13 = atoi(v19);
}
else
{
v13 = v12;
}
dnum = v13;
ur_srandom();
if ( !v10 || !fruit )
{
v14 = rnd(20);
strcpy(&fruit, funfruit_0[v14]);
}
v15 = md_strdup(&fruit);
v16 = prscore == 0;
fd_data[5] = v15;
if ( v16 )
{
if ( !prversion )
{
if ( wizard )
printf("Hello %s, welcome to dungeon #%d", &whoami, dnum);
else
printf("Hello %s, just a moment while I dig the dungeon...", &whoami);
mem_debug(2LL);
mem_tracking(1LL);
fflush(stdout);
init_things();
init_fd();
init_colors();
init_stones();
init_materials();
initscr();
wrefresh(stdscr);
init_names();
cbreak();
cbreak();
noecho();
nonl();
food_left = (int)(float)((float)((float)(COLS * LINES) / 2000.0) * (float)food_left);
cw = newwin(LINES, COLS, 0, 0);
mw = newwin(LINES, COLS, 0, 0);
hw = newwin(LINES, COLS, 0, 0);
if ( v3 == 2 && *v4[1] && !(unsigned int)restore() )
exit(1);
waswizard = wizard;
init_player();
resurrect = *((_DWORD *)&player + 22);
init_exp();
init_flags();
wclear(hw);
wrefresh(hw);
new_level(1LL, 0LL);
start_daemon(1LL, &player, 2LL);
light_fuse(1LL, 0LL, 140LL, 2LL);
start_daemon(3LL, 0LL, 2LL);
start_daemon(4LL, 0LL, 2LL);
v17 = *((_DWORD *)&player + 90);
*((_QWORD *)&player + 25) = *((_QWORD *)&player + 24);
char_type = v17;
v18 = roomin();
after = 1;
oldrp = v18;
signal(2, (__sighandler_t)&quit_handler);
while ( playing )
{
do_daemons(1LL);
do_fuses(1LL);
command();
if ( after )
do_after_effects();
}
fatal((const char *)&unk_1C8);
}
printf("UltraRogue Version %s.\n", release);
exit(0);
}
waswizard = 1;
score(0LL, 0LL, 0xFFFFFFFFLL, 0LL);
exit(0);
}
}
v3 -= v7 - 1;
v4 = &v4[v7 - 1];
goto LABEL_11;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char **v4; // rbx
const char **v5; // rdx
int v6; // edi
int v7; // esi
const char *v8; // rax
char *v9; // rax
char *v10; // r13
char *v11; // rsi
int v12; // er12
int v13; // edi
int v14; // eax
__int64 v15; // rax
bool v16; // zf
int v17; // eax
__int64 v18; // rax
char *v19; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

v3 = argc;
v4 = argv;
if ( argc <= 1 )
{
v7 = 1;
}
else
{
v5 = argv + 1;
v6 = 0;
v7 = 1;
do
{
v8 = *v5;
if ( **v5 != 45 )
break;
switch ( v8[1] )
{
case 's':
prscore = 1;
break;
case 'v':
prversion = 1;
break;
case 'r':
v6 = 1;
break;
default:
fprintf(stderr, "%s: Unknown option '%c'.\n", *v4, (unsigned int)v8[1]);
exit(1);
}
++v7;
++v5;
}
while ( v3 != v7 );
if ( v6 )
{
LABEL_11:
strcpy(&score_file, "urogue.scr");
fd_score = (__int64)fopen(&score_file, "r+");
if ( !fd_score )
fd_score = (__int64)fopen(&score_file, "a+");
v9 = getenv("OPTIONS");
v10 = v9;
if ( v9 )
parse_opts(v9);
v11 = getenv("USER");
if ( v11 )
{
strcpy(&whoami, v11);
}
else
{
*((_WORD *)&whoami + 4) = 115;
*(_QWORD *)&whoami = 0x756F6D796E6F6E61LL;
}
v12 = time(&timer);
if ( wizard && getenv("SEED") )
{
v19 = getenv("SEED");
v13 = atoi(v19);
}
else
{
v13 = v12;
}
dnum = v13;
ur_srandom();
if ( !v10 || !fruit )
{
v14 = func3(20);
strcpy(&fruit, funfruit_0[v14]);
}
v15 = md_strdup(&fruit);
v16 = prscore == 0;
fd_data[5] = v15;
if ( v16 )
{
if ( !prversion )
{
if ( wizard )
printf("Hello %s, welcome to dungeon #%d", &whoami, dnum);
else
printf("Hello %s, just a moment while I dig the dungeon...", &whoami);
mem_debug(2LL);
mem_tracking(1LL);
fflush(stdout);
init_things();
init_fd();
init_colors();
init_stones();
init_materials();
initscr();
wrefresh(stdscr);
init_names();
cbreak();
cbreak();
noecho();
nonl();
food_left = (int)(float)((float)((float)(COLS * LINES) / 2000.0) * (float)food_left);
cw = newwin(LINES, COLS, 0, 0);
mw = newwin(LINES, COLS, 0, 0);
hw = newwin(LINES, COLS, 0, 0);
if ( v3 == 2 && *v4[1] && !(unsigned int)restore() )
exit(1);
waswizard = wizard;
init_player();
resurrect = *((_DWORD *)&player + 22);
init_exp();
init_flags();
wclear(hw);
wrefresh(hw);
new_level(1LL, 0LL);
start_daemon(1LL, &player, 2LL);
light_fuse(1LL, 0LL, 140LL, 2LL);
start_daemon(3LL, 0LL, 2LL);
start_daemon(4LL, 0LL, 2LL);
v17 = *((_DWORD *)&player + 90);
*((_QWORD *)&player + 25) = *((_QWORD *)&player + 24);
char_type = v17;
v18 = roomin();
after = 1;
oldrp = v18;
signal(2, (__sighandler_t)&quit_handler);
while ( playing )
{
do_daemons(1LL);
do_fuses(1LL);
command();
if ( after )
do_after_effects();
}
func0((const char *)&unk_1C8);
}
printf("UltraRogue Version %s.\n", release);
exit(0);
}
waswizard = 1;
score(0LL, 0LL, 0xFFFFFFFFLL, 0LL);
exit(0);
}
}
v3 -= v7 - 1;
v4 = &v4[v7 - 1];
goto LABEL_11;
}

original_code:
int
main(int argc, char *argv[])
{
    int x;
    char *env;
    time_t lowtime;
    time_t now;
    int rflag = 0;
    char *nm;
 float scale;
    for (x = 1; x < argc; x++)
    {
        if (argv[x][0] != '-')
            break;
        switch (argv[x][1])
        {
            case 's':
                prscore = 1;
                break;
            case 'v':
                prversion = 1;
                break;
            case 'r':
                rflag = 1;
                break;
            default:
                fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]);
                exit(1);
        }
    }
    if (!rflag)
    {
        argc -= (x - 1);
        argv += (x - 1);
    }
    strcpy(score_file, "urogue.scr");
    fd_score = fopen(score_file, "r+");
    if (fd_score == ((void *)0))
        fd_score = fopen(score_file, "a+");
    if ((env = getenv("OPTIONS")) != ((void *)0))
        parse_opts(env);
    nm = getenv("USER");
    if (nm != ((void *)0))
        strcpy(whoami,nm);
    else
        strcpy(whoami,"anonymous");
 lowtime = time(&now);
 dnum = (wizard && getenv("SEED") != ((void *)0) ? atoi( getenv("SEED")) : (int)lowtime);
 ur_srandom(dnum);
    if (env == ((void *)0) || fruit[0] == '\0')
    {
        static const char *funfruit[] =
        {
            "candleberry", "caprifig", "dewberry", "elderberry",
            "gooseberry", "guanabana", "hagberry", "ilama", "imbu",
            "jaboticaba", "jujube", "litchi", "mombin", "pitanga",
            "prickly pear", "rambutan", "sapodilla", "soursop",
            "sweetsop", "whortleberry"
        };
        strcpy(fruit, funfruit[rnd(sizeof(funfruit) / sizeof(funfruit[0]))]);
    }
    fd_data[1].mi_name = md_strdup(fruit);
    if (prscore)
    {
        waswizard = 1;
        score(0L, 0, -1, 0);
        exit(0);
    }
    if (prversion)
    {
        printf("UltraRogue Version %s.\n", release);
        exit(0);
    }
    if (wizard)
        printf("Hello %s, welcome to dungeon #%d", whoami, dnum);
    else
        printf("Hello %s, just a moment while I dig the dungeon...", whoami);
    mem_debug(2);
 mem_tracking(1);
    fflush(stdout);
    init_things();
    init_fd();
    init_colors();
    init_stones();
    init_materials();
    initscr();
    wrefresh(stdscr);
    init_names();
    cbreak();
    cbreak();
    noecho();
    nonl();
    scale = (float) (LINES * COLS) / (80.0F * 25.0F);
    food_left = (int) (food_left * scale);
    cw = newwin(LINES, COLS, 0, 0);
    mw = newwin(LINES, COLS, 0, 0);
    hw = newwin(LINES, COLS, 0, 0);
    if (argc == 2 && argv[1][0] != '\0' && !restore(argv[1]))
        exit(1);
    waswizard = wizard;
    init_player();
    resurrect = player.t_stats.s_const;
    init_exp();
    init_flags();
    wclear(hw);
    wrefresh(hw);
    new_level(POSTLEV,0);
    start_daemon(1, &player, 2);
    light_fuse(1, 0, 140, 2);
    start_daemon(3, 0, 2);
    start_daemon(4, 0, 2);
    char_type = player.t_ctype;
    player.t_oldpos = player.t_pos;
    oldrp = roomin(player.t_pos);
    after = 1;
    signal(2, quit_handler);
    while(playing)
    {
        do_daemons(1);
        do_fuses(1);
        command();
        if (after)
            do_after_effects();
    }
    fatal("");
    return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int x;
    char *env;
    long lowtime;
    long now;
    int rflag = 0;
    char *nm;
 float scale;
    for (x = 1; x < argc; x++)
    {
        if (argv[x][0] != '-')
            break;
        switch (argv[x][1])
        {
            case 's':
                prscore = 1;
                break;
            case 'v':
                prversion = 1;
                break;
            case 'r':
                rflag = 1;
                break;
            default:
                fprintf(stderr,"%s: Unknown option '%c'.\n",argv[0],argv[x][1]);
                exit(1);
        }
    }
    if (!rflag)
    {
        argc -= (x - 1);
        argv += (x - 1);
    }
    strcpy(score_file, "urogue.scr");
    fd_score = fopen(score_file, "r+");
    if (fd_score == ((void *)0))
        fd_score = fopen(score_file, "a+");
    if ((env = getenv("OPTIONS")) != ((void *)0))
        parse_opts(env);
    nm = getenv("USER");
    if (nm != ((void *)0))
        strcpy(whoami,nm);
    else
        strcpy(whoami,"anonymous");
 lowtime = time(&now);
 dnum = (wizard && getenv("SEED") != ((void *)0) ? atoi( getenv("SEED")) : (int)lowtime);
 ur_srandom(dnum);
    if (env == ((void *)0) || fruit[0] == '\0')
    {
        static char *funfruit[] = {
            "candleberry", "caprifig", "dewberry", "elderberry",
            "gooseberry", "guanabana", "hagberry", "ilama", "imbu",
            "jaboticaba", "jujube", "litchi", "mombin", "pitanga",
            "prickly pear", "rambutan", "sapodilla", "soursop",
            "sweetsop", "whortleberry"
        };
        strcpy(fruit, funfruit[rnd(sizeof(funfruit) / sizeof(funfruit[0]))]);
    }
    fd_data[1].mi_name = md_strdup(fruit);
    if (prscore)
    {
        waswizard = 1;
        score(0L, 0, -1, 0);
        exit(0);
    }
    if (prversion)
    {
        printf("UltraRogue Version %s.\n", release);
        exit(0);
    }
    if (wizard)
        printf("Hello %s, welcome to dungeon #%d", whoami, dnum);
    else
        printf("Hello %s, just a moment while I dig the dungeon...", whoami);
    mem_debug(2);
 mem_tracking(1);
    fflush(stdout);
    init_things();
    init_fd();
    init_colors();
    init_stones();
    init_materials();
    initscr();
    wrefresh(stdscr);
    init_names();
    cbreak();
    cbreak();
    noecho();
    nonl();
    scale = (float) (LINES * COLS) / (80.0F * 25.0F);
    food_left = (int) (food_left * scale);
    cw = newwin(LINES, COLS, 0, 0);
    mw = newwin(LINES, COLS, 0, 0);
    hw = newwin(LINES, COLS, 0, 0);
    if (argc == 2 && argv[1][0] != '\0' && !restore(argv[1]))
        exit(1);
    waswizard = wizard;
    init_player();
    resurrect = player.t_stats.s_const;
    init_exp();
    init_flags();
    wclear(hw);
    wrefresh(hw);
    new_level(POSTLEV,0);
    start_daemon(1, &player, 2);
    light_fuse(1, 0, 140, 2);
    start_daemon(3, 0, 2);
    start_daemon(4, 0, 2);
    char_type = player.t_ctype;
    player.t_oldpos = player.t_pos;
    oldrp = roomin(player.t_pos);
    after = 1;
    signal(2, quit_handler);
    while(playing)
    {
        do_daemons(1);
        do_fuses(1);
        command();
        if (after)
            do_after_effects();
    }
    fatal("");
    return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: x int

variable_types:
env
char *

variable_types: lowtime long

variable_types: now long

variable_types: rflag int

variable_types:
nm
char *

variable_types: scale float

variable_types:
funfruit
char *[]


original_code:
void
swap_top(struct linked_list *top, struct linked_list *node)
{
    struct object *obt, *obn;
    obt = ((*top).data.obj);
    obn = ((*node).data.obj);
    _detach(&(obt->next_obj), node);
    _attach(&lvl_obj, node);
    _detach(&lvl_obj, top);
    obn->next_obj = obt->next_obj;
    if (obn->next_obj)
        obn->next_obj->l_prev = ((void *)0);
    _attach(&(obn->next_obj), top);
}

canonical_original_code:
void swap_top(struct linked_list *top, struct linked_list *node)
{
    struct object *obt; struct object *obn;
    obt = ((*top).data.obj);
    obn = ((*node).data.obj);
    _detach(&(obt->next_obj), node);
    _attach(&lvl_obj, node);
    _detach(&lvl_obj, top);
    obn->next_obj = obt->next_obj;
    if (obn->next_obj)
        obn->next_obj->l_prev = ((void *)0);
    _attach(&(obn->next_obj), top);
}

variable_types: struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object { struct coord { int x; int y; } o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *

variable_types:
node
struct linked_list *

variable_types: struct object { struct coord { int x; int y; } o_pos; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *


decompiled_code:
__int64 __fastcall pack_report(__int64 a1, int a2, __int64 a3)
{
int v3; // eax
const char *v4; // r12
int v5; // eax
__int64 v7; // rcx
__int64 v8; // rax

if ( a2 )
{
v3 = terse;
if ( !terse )
{
addmsg(a3);
v3 = terse;
}
v4 = (const char *)inv_name(a1, v3 == 0);
v5 = get_ident(a1);
msg("(%c%c) %s.", (unsigned int)*(char *)(a1 + 64), (unsigned int)*((char *)&print_letters + v5), v4);
}
if ( *(_BYTE *)(a1 + 64) == 44 )
{
v7 = *(int *)(a1 + 76);
has_artifact |= 1 << v7;
picked_artifact |= 1 << v7;
v8 = *(_QWORD *)(a1 + 56);
if ( (v8 & 1) == 0 )
{
*(_QWORD *)(a1 + 56) = v8 | 1;
player[4] += arts[10 * v7 + 7] / 10;
check_level();
}
}
return updpack();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3)
{
int v3; // eax
const char *v4; // r12
int v5; // eax
__int64 v7; // rcx
__int64 v8; // rax

if ( a2 )
{
v3 = terse;
if ( !terse )
{
addmsg(a3);
v3 = terse;
}
v4 = (const char *)inv_name(a1, v3 == 0);
v5 = get_ident(a1);
msg("(%c%c) %s.", (unsigned int)*(char *)(a1 + 64), (unsigned int)*((char *)&print_letters + v5), v4);
}
if ( *(_BYTE *)(a1 + 64) == 44 )
{
v7 = *(int *)(a1 + 76);
has_artifact |= 1 << v7;
picked_artifact |= 1 << v7;
v8 = *(_QWORD *)(a1 + 56);
if ( (v8 & 1) == 0 )
{
*(_QWORD *)(a1 + 56) = v8 | 1;
player[4] += arts[10 * v7 + 7] / 10;
check_level();
}
}
return updpack();
}

original_code:
void
pack_report(object *obj, int print_message, char *message)
{
    if (print_message)
    {
        if (!terse)
            addmsg(message);
        msg("(%c%c) %s.", obj->o_type, print_letters[get_ident(obj)],
            inv_name(obj, !terse));
    }
    if (obj->o_type == ',')
    {
        has_artifact |= (1 << obj->o_which);
        picked_artifact |= (1 << obj->o_which);
        if (!(obj->ar_flags & 01))
        {
            obj->ar_flags |= 01;
            player.t_stats.s_exp += arts[obj->o_which].ar_worth / 10;
            check_level();
        }
    }
    updpack();
    return;
}

canonical_original_code:
void pack_report(struct object *obj, int print_message, char *message)
{
    if (print_message)
    {
        if (!terse)
            addmsg(message);
        msg("(%c%c) %s.", obj->o_type, print_letters[get_ident(obj)],
            inv_name(obj, !terse));
    }
    if (obj->o_type == ',')
    {
        has_artifact |= (1 << obj->o_which);
        picked_artifact |= (1 << obj->o_which);
        if (!(obj->ar_flags & 01))
        {
            obj->ar_flags |= 01;
            player.t_stats.s_exp += arts[obj->o_which].ar_worth / 10;
            check_level();
        }
    }
    updpack();
    return;
}

variable_types:
message
char *

user_defined_types: struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; }


decompiled_code:
__int64 __fastcall add_pack(__int64 a1, int a2)
{
unsigned int v2; // er14
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // r15
_QWORD *v7; // rax
__int64 v8; // rdx
__int64 v9; // rax
const char *v10; // rsi
int v11; // er15
__int64 v12; // rdi
const char *v13; // rax
const char *v14; // rsi
__int64 v15; // rdx

v2 = 0;
v3 = a1;
if ( !a1 )
{
v12 = find_obj(HIDWORD(player[24]), LODWORD(player[24]));
if ( !v12 )
{
msg("Nothing to pick up.");
return v2;
}
v2 = 1;
v3 = get_stack(v12);
if ( !v3 )
return 0LL;
}
v4 = *(_QWORD *)(v3 + 16);
if ( *(_BYTE *)(v4 + 64) != 42 )
{
if ( (signed int)(LODWORD(player[6]) + itemweight(*(_QWORD *)(v3 + 16))) > SHIDWORD(player[6]) )
{
msg("Too much for you to carry.");
if ( a2 )
{
v9 = inv_name(v4, 1LL);
v10 = "Moved";
if ( !terse )
v10 = "You moved";
v2 = 0;
msg("%s onto %s", v10, v9);
return v2;
}
}
else
{
v5 = apply_to_bag(player[2], (unsigned int)*(char *)(v4 + 64), &bff_group, 0LL, v4);
if ( v5 )
{
*(_DWORD *)(v5 + 72) += *(_DWORD *)(v4 + 72);
if ( v2 )
rem_obj(v3, 0LL);
v2 = 1;
pack_report(v5, a2, (__int64)"You now have ");
return v2;
}
if ( *(_BYTE *)(v4 + 64) == 63 && *(_DWORD *)(v4 + 76) == 7 && (*(_BYTE *)(v4 + 48) & 1) != 0 )
{
v2 = 1;
msg("The scroll turns to dust as you pick it up.");
rem_obj(v3, 1LL);
return v2;
}
v11 = count_bag(player[2], (unsigned int)*(char *)(v4 + 64), 0LL);
if ( v11 != (unsigned int)max_print() )
{
if ( v2 )
rem_obj(v3, 0LL);
push_bag((unsigned int)((_DWORD)player + 16), v4);
pack_report(v4, a2, (__int64)"You now have ");
ur_free(v3);
return 1LL;
}
v13 = (const char *)name_type((unsigned int)*(char *)(v4 + 64));
msg("You have no room for more %s.", v13);
if ( a2 )
{
v14 = "Moved";
v15 = inv_name(*(_QWORD *)(v3 + 16), 1LL);
if ( !terse )
v14 = "You moved";
msg("%s onto %s.", v14, v15);
}
}
return 0LL;
}
if ( a2 )
{
if ( !terse )
addmsg("You found ");
msg("%d gold pieces.", *(unsigned int *)(v4 + 72));
}
v7 = (_QWORD *)mlist;
if ( mlist )
{
do
{
while ( 1 )
{
v8 = v7[2];
if ( *(_QWORD *)(v8 + 184) == v4 )
break;
v7 = (_QWORD *)*v7;
if ( !v7 )
goto LABEL_17;
}
*(_DWORD *)(v8 + 168) = 1;
v7 = (_QWORD *)*v7;
*(_QWORD *)(v8 + 176) = player;
*(_QWORD *)(v8 + 184) = 0LL;
}
while ( v7 );
}
LABEL_17:
if ( LODWORD(player[45]) == 7 )
{
player[4] += *(_DWORD *)(v4 + 72) >> 2;
check_level();
}
purse += *(unsigned int *)(v4 + 72);
if ( !v2 )
return 1LL;
rem_obj(v3, 1LL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // er14
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // r15
_QWORD *v7; // rax
__int64 v8; // rdx
__int64 v9; // rax
const char *v10; // rsi
int v11; // er15
__int64 v12; // rdi
const char *v13; // rax
const char *v14; // rsi
__int64 v15; // rdx

v2 = 0;
v3 = a1;
if ( !a1 )
{
v12 = find_obj(HIDWORD(player[24]), LODWORD(player[24]));
if ( !v12 )
{
msg("Nothing to pick up.");
return v2;
}
v2 = 1;
v3 = get_stack(v12);
if ( !v3 )
return 0LL;
}
v4 = *(_QWORD *)(v3 + 16);
if ( *(_BYTE *)(v4 + 64) != 42 )
{
if ( (signed int)(LODWORD(player[6]) + itemweight(*(_QWORD *)(v3 + 16))) > SHIDWORD(player[6]) )
{
msg("Too much for you to carry.");
if ( a2 )
{
v9 = inv_name(v4, 1LL);
v10 = "Moved";
if ( !terse )
v10 = "You moved";
v2 = 0;
msg("%s onto %s", v10, v9);
return v2;
}
}
else
{
v5 = apply_to_bag(player[2], (unsigned int)*(char *)(v4 + 64), &bff_group, 0LL, v4);
if ( v5 )
{
*(_DWORD *)(v5 + 72) += *(_DWORD *)(v4 + 72);
if ( v2 )
rem_obj(v3, 0LL);
v2 = 1;
func1(v5, a2, (__int64)"You now have ");
return v2;
}
if ( *(_BYTE *)(v4 + 64) == 63 && *(_DWORD *)(v4 + 76) == 7 && (*(_BYTE *)(v4 + 48) & 1) != 0 )
{
v2 = 1;
msg("The scroll turns to dust as you pick it up.");
rem_obj(v3, 1LL);
return v2;
}
v11 = count_bag(player[2], (unsigned int)*(char *)(v4 + 64), 0LL);
if ( v11 != (unsigned int)max_print() )
{
if ( v2 )
rem_obj(v3, 0LL);
push_bag((unsigned int)((_DWORD)player + 16), v4);
func1(v4, a2, (__int64)"You now have ");
ur_free(v3);
return 1LL;
}
v13 = (const char *)name_type((unsigned int)*(char *)(v4 + 64));
msg("You have no room for more %s.", v13);
if ( a2 )
{
v14 = "Moved";
v15 = inv_name(*(_QWORD *)(v3 + 16), 1LL);
if ( !terse )
v14 = "You moved";
msg("%s onto %s.", v14, v15);
}
}
return 0LL;
}
if ( a2 )
{
if ( !terse )
addmsg("You found ");
msg("%d gold pieces.", *(unsigned int *)(v4 + 72));
}
v7 = (_QWORD *)mlist;
if ( mlist )
{
do
{
while ( 1 )
{
v8 = v7[2];
if ( *(_QWORD *)(v8 + 184) == v4 )
break;
v7 = (_QWORD *)*v7;
if ( !v7 )
goto LABEL_17;
}
*(_DWORD *)(v8 + 168) = 1;
v7 = (_QWORD *)*v7;
*(_QWORD *)(v8 + 176) = player;
*(_QWORD *)(v8 + 184) = 0LL;
}
while ( v7 );
}
LABEL_17:
if ( LODWORD(player[45]) == 7 )
{
player[4] += *(_DWORD *)(v4 + 72) >> 2;
check_level();
}
purse += *(unsigned int *)(v4 + 72);
if ( !v2 )
return 1LL;
rem_obj(v3, 1LL);
return v2;
}

original_code:
int
add_pack(struct linked_list *item, int print_message)
{
    struct object *obj, *op;
    int from_floor;
    if (item == ((void *)0))
    {
        from_floor = 1;
        if ((item = find_obj(player.t_pos.y, player.t_pos.x)) == ((void *)0))
        {
            msg("Nothing to pick up.");
            return(0);
        }
    }
    else
        from_floor = 0;
    if (from_floor)
    {
        item = get_stack(item);
        if (!item)
            return(0);
    }
    obj = ((*item).data.obj);
    if (obj->o_type == '*')
    {
        struct linked_list *mitem;
        struct thing *tp;
        if (print_message)
        {
            if (!terse)
                addmsg("You found ");
            msg("%d gold pieces.", obj->o_count);
        }
        for (mitem = mlist; mitem != ((void *)0); mitem = ((mitem)?(mitem->l_next):((void *)0)))
        {
            tp = ((*mitem).data.th);
            if (tp->t_horde==obj)
            {
                tp->t_ischasing = 1;
                tp->t_chasee = &player;
                tp->t_horde = ((void *)0);
            }
        }
        if (player.t_ctype == 7)
        {
            player.t_stats.s_exp += obj->o_count / 4;
            check_level();
        }
        purse += obj->o_count;
        if (from_floor)
            rem_obj(item, 1);
        return (1);
    }
    if (itemweight(obj) + player.t_stats.s_pack > player.t_stats.s_carry)
    {
        msg("Too much for you to carry.");
        if (print_message)
        {
            msg("%s onto %s", terse ? "Moved" : "You moved",
                inv_name(obj, 1));
        }
        return(0);
    }
    if ((op = apply_to_bag(player.t_pack, obj->o_type, bff_group, ((void *)0), obj)) != ((void *)0))
    {
        op->o_count += obj->o_count;
        if (from_floor)
            rem_obj(item, 0);
        pack_report(op, print_message, "You now have ");
        return(1);
    }
    if (obj->o_type == '?' && obj->o_which == 7)
        if (obj->o_flags & 0x00000001UL)
        {
            msg("The scroll turns to dust as you pick it up.");
            rem_obj(item, 1);
            return(1);
        }
    if (count_bag(player.t_pack, obj->o_type, ((void *)0)) == max_print())
    {
        msg("You have no room for more %s.", name_type(obj->o_type));
        if (print_message)
        {
            obj = ((*item).data.obj);
            msg("%s onto %s.", terse ? "Moved" : "You moved",
                inv_name(obj, 1));
        }
        return(0);
    }
    if (from_floor)
        rem_obj(item, 0);
    push_bag(&player.t_pack, obj);
    pack_report(obj, print_message, "You now have ");
    ur_free(item);
    return(1);
}

canonical_original_code:
int add_pack(struct linked_list *item, int print_message)
{
    struct object *obj; struct object *op;
    int from_floor;
    if (item == ((void *)0))
    {
        from_floor = 1;
        if ((item = find_obj(player.t_pos.y, player.t_pos.x)) == ((void *)0))
        {
            msg("Nothing to pick up.");
            return(0);
        }
    }
    else
        from_floor = 0;
    if (from_floor)
    {
        item = get_stack(item);
        if (!item)
            return(0);
    }
    obj = ((*item).data.obj);
    if (obj->o_type == '*')
    {
        struct linked_list *mitem;
        struct thing *tp;
        if (print_message)
        {
            if (!terse)
                addmsg("You found ");
            msg("%d gold pieces.", obj->o_count);
        }
        for (mitem = mlist; mitem != ((void *)0); mitem = ((mitem)?(mitem->l_next):((void *)0)))
        {
            tp = ((*mitem).data.th);
            if (tp->t_horde==obj)
            {
                tp->t_ischasing = 1;
                tp->t_chasee = &player;
                tp->t_horde = ((void *)0);
            }
        }
        if (player.t_ctype == 7)
        {
            player.t_stats.s_exp += obj->o_count / 4;
            check_level();
        }
        purse += obj->o_count;
        if (from_floor)
            rem_obj(item, 1);
        return (1);
    }
    if (itemweight(obj) + player.t_stats.s_pack > player.t_stats.s_carry)
    {
        msg("Too much for you to carry.");
        if (print_message)
        {
            msg("%s onto %s", terse ? "Moved" : "You moved",
                inv_name(obj, 1));
        }
        return(0);
    }
    if ((op = apply_to_bag(player.t_pack, obj->o_type, bff_group, ((void *)0), obj)) != ((void *)0))
    {
        op->o_count += obj->o_count;
        if (from_floor)
            rem_obj(item, 0);
        pack_report(op, print_message, "You now have ");
        return(1);
    }
    if (obj->o_type == '?' && obj->o_which == 7)
        if (obj->o_flags & 0x00000001UL)
        {
            msg("The scroll turns to dust as you pick it up.");
            rem_obj(item, 1);
            return(1);
        }
    if (count_bag(player.t_pack, obj->o_type, ((void *)0)) == max_print())
    {
        msg("You have no room for more %s.", name_type(obj->o_type));
        if (print_message)
        {
            obj = ((*item).data.obj);
            msg("%s onto %s.", terse ? "Moved" : "You moved",
                inv_name(obj, 1));
        }
        return(0);
    }
    if (from_floor)
        rem_obj(item, 0);
    push_bag(&player.t_pack, obj);
    pack_report(obj, print_message, "You now have ");
    ur_free(item);
    return(1);
}

variable_types: struct thing { long chasee_index; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object { struct coord { int x; int y; } o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *obj; struct thing *th; void *l_data; } data; } *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *


decompiled_code:
void __fastcall get_all(__int64 a1)
{
__int64 v2; // rbx

while ( a1 )
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
rem_obj(a1, 0LL);
if ( !(unsigned int)add_pack(a1, 0) )
break;
a1 = v2;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
__int64 v2; // rbx

while ( a1 )
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL);
rem_obj(a1, 0LL);
if ( !(unsigned int)func2(a1, 0) )
break;
a1 = v2;
}
}

original_code:
void
get_all(struct linked_list *top)
{
    struct linked_list *node;
    struct object *obt;
    while (top)
    {
        obt = ((*top).data.obj);
        node = obt->next_obj;
        rem_obj(top, 0);
        if (!add_pack(top, 0))
            return;
        top = node;
    }
}


inventory

decompiled_code:
__int64 __fastcall inventory(__int64 a1, __int64 a2)
{
__int64 result; // rax
const char *v3; // rax
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = a2;
if ( (_DWORD)a2
|| (msg("What kind of item <%s> to inventory (* for all)?", type_list),
a2 = (unsigned int)(char)readchar(),
v4[0] = a2,
(_DWORD)a2 != 27) )
{
if ( (_DWORD)a2 == 42 )
{
v4[0] = 0;
a2 = 0LL;
}
mpos = 0;
if ( (unsigned int)count_bag(a1, a2, 0LL) )
{
apply_to_bag(a1, v4[0], 0LL, &baf_print_item, v4);
end_line();
result = msg((const char *)&unk_DDC);
}
else
{
v3 = (const char *)name_type(v4[0]);
result = msg("You don't have any %s.", v3);
}
}
else
{
after = 0;
result = msg((const char *)&unk_DDC);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
const char *v3; // rax
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = a2;
if ( (_DWORD)a2
|| (msg("What kind of item <%s> to inventory (* for all)?", type_list),
a2 = (unsigned int)(char)readchar(),
v4[0] = a2,
(_DWORD)a2 != 27) )
{
if ( (_DWORD)a2 == 42 )
{
v4[0] = 0;
a2 = 0LL;
}
mpos = 0;
if ( (unsigned int)count_bag(a1, a2, 0LL) )
{
apply_to_bag(a1, v4[0], 0LL, &baf_print_item, v4);
end_line();
result = msg((const char *)&unk_DDC);
}
else
{
v3 = (const char *)name_type(v4[0]);
result = msg("You don't have any %s.", v3);
}
}
else
{
after = 0;
result = msg((const char *)&unk_DDC);
}
return result;
}

original_code:
void
inventory(struct linked_list *container, int type)
{
    int cnt;
    if (type == 0)
    {
        msg("What kind of item <%s> to inventory (* for all)?", type_list);
        type = readchar();
        if (type == 27)
        {
            after = 0;
            msg("");
            return;
        }
    }
    if (type == '*')
        type = 0;
    mpos = 0;
    if ((cnt = count_bag(container, type, ((void *)0))) == 0)
        msg("You don't have any %s.", name_type(type));
    else
    {
        apply_to_bag(container, type, ((void *)0), baf_print_item, &type);
        end_line();
        msg("");
    }
    return;
}

variable_types: type int

variable_types: cnt int


decompiled_code:
__int64 __fastcall pick_up(char a1)
{
__int64 result; // rax

switch ( a1 )
{
case '!':
case ')':
case '*':
case ',':
case '/':
case ':':
case '=':
case '?':
case ']':
result = add_pack(0LL, 1);
break;
default:
if ( wizard )
{
result = wiz_verbose;
if ( wiz_verbose )
result = msg("Where did you pick that up???");
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
__int64 result; // rax

switch ( a1 )
{
case '!':
case ')':
case '*':
case ',':
case '/':
case ':':
case '=':
case '?':
case ']':
result = func2(0LL, 1);
break;
default:
if ( wizard )
{
result = wiz_verbose;
if ( wiz_verbose )
result = msg("Where did you pick that up???");
}
break;
}
return result;
}

original_code:
void
pick_up(char ch)
{
    switch(ch)
    {
        default:
            if (wizard && wiz_verbose) msg("Where did you pick that up???");
            break;
        case '*':
        case ']':
        case '!':
        case ':':
        case ')':
        case '?':
        case ',':
        case '=':
        case '/':
            add_pack(((void *)0), 1);
            break;
    }
}

variable_types: ch char


decompiled_code:
__int64 __fastcall get_object(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
__int64 v5; // r12
char v6; // al
unsigned int v7; // er12
char v8; // bl
unsigned int v9; // er12
unsigned int v10; // eax
const char *v12; // rax
unsigned int v13[4]; // [rsp+Ch] [rbp-3Ch] BYREF
char v14[41]; // [rsp+1Fh] [rbp-29h] BYREF

v13[0] = a3;
if ( a1 )
{
v5 = apply_to_bag(a1, v13[0], a4, 0LL, 0LL);
if ( v5 )
{
while ( 1 )
{
if ( v13[0] )
goto LABEL_9;
msg("What kind of item <%s> do you want to %s (* for list)?", type_list, a2);
v6 = readchar();
v7 = v6;
if ( v6 == 27 )
break;
msg((const char *)&unk_DDC);
if ( (_BYTE)v7 == 42 )
{
add_line("! Potion");
add_line("? Scroll");
add_line("= Ring");
add_line("/ Stick");
add_line("] Armor");
add_line(") Weapon");
add_line(": Food");
end_line();
}
else if ( (unsigned int)is_member(type_list, v7) )
{
if ( (unsigned int)count_bag(a1, v7, 0LL) )
{
v13[0] = v7;
LABEL_9:
while ( 1 )
{
msg("What item do you want to %s (* for list)?", a2);
v8 = readchar();
msg((const char *)&unk_DDC);
if ( v8 == 27 )
break;
v9 = v13[0];
if ( v8 == 42 )
{
mpos = 0;
apply_to_bag(a1, v13[0], a4, &baf_print_item, v13);
end_line();
}
else
{
v14[0] = v8;
v10 = unprint_id(v14);
v5 = scan_bag(a1, v9, v10);
if ( v5 )
{
mpos = 0;
msg((const char *)&unk_DDC);
return v5;
}
}
}
break;
}
v12 = (const char *)name_type(v7);
msg("You don't have any %s.", v12);
}
else
{
beep();
}
}
v5 = 0LL;
after = 0;
msg((const char *)&unk_DDC);
}
else
{
msg("You seem to have nothing to %s.", a2);
after = 0;
}
}
else
{
v5 = 0LL;
msg("There isn't anything in there.");
after = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, unsigned int a3, __int64 a4)
{
__int64 v5; // r12
char v6; // al
unsigned int v7; // er12
char v8; // bl
unsigned int v9; // er12
unsigned int v10; // eax
const char *v12; // rax
unsigned int v13[4]; // [rsp+Ch] [rbp-3Ch] BYREF
char v14[41]; // [rsp+1Fh] [rbp-29h] BYREF

v13[0] = a3;
if ( a1 )
{
v5 = apply_to_bag(a1, v13[0], a4, 0LL, 0LL);
if ( v5 )
{
while ( 1 )
{
if ( v13[0] )
goto LABEL_9;
msg("What kind of item <%s> do you want to %s (* for list)?", type_list, a2);
v6 = readchar();
v7 = v6;
if ( v6 == 27 )
break;
msg((const char *)&unk_DDC);
if ( (_BYTE)v7 == 42 )
{
add_line("! Potion");
add_line("? Scroll");
add_line("= Ring");
add_line("/ Stick");
add_line("] Armor");
add_line(") Weapon");
add_line(": Food");
end_line();
}
else if ( (unsigned int)is_member(type_list, v7) )
{
if ( (unsigned int)count_bag(a1, v7, 0LL) )
{
v13[0] = v7;
LABEL_9:
while ( 1 )
{
msg("What item do you want to %s (* for list)?", a2);
v8 = readchar();
msg((const char *)&unk_DDC);
if ( v8 == 27 )
break;
v9 = v13[0];
if ( v8 == 42 )
{
mpos = 0;
apply_to_bag(a1, v13[0], a4, &baf_print_item, v13);
end_line();
}
else
{
v14[0] = v8;
v10 = unprint_id(v14);
v5 = scan_bag(a1, v9, v10);
if ( v5 )
{
mpos = 0;
msg((const char *)&unk_DDC);
return v5;
}
}
}
break;
}
v12 = (const char *)name_type(v7);
msg("You don't have any %s.", v12);
}
else
{
beep();
}
}
v5 = 0LL;
after = 0;
msg((const char *)&unk_DDC);
}
else
{
msg("You seem to have nothing to %s.", a2);
after = 0;
}
}
else
{
v5 = 0LL;
msg("There isn't anything in there.");
after = 0;
}
return v5;
}

original_code:
struct object *
get_object(struct linked_list *container, char *purpose, int type, int (*bff_p)(struct object *obj, bag_arg *junk))
{
    struct object *obj_p = ((void *)0);
    char sel_id;
    int sel_type;
    char response;
    if (container == ((void *)0))
    {
        msg("There isn't anything in there.");
        after = 0;
        return(((void *)0));
    }
    if (apply_to_bag(container, type, bff_p, ((void *)0), ((void *)0)) == ((void *)0))
    {
        msg("You seem to have nothing to %s.", purpose);
        after = 0;
        return(((void *)0));
    }
    while (obj_p == ((void *)0))
    {
        if (type == 0)
        {
            msg("What kind of item <%s> do you want to %s (* for list)?", type_list, purpose);
            response = readchar();
            if (response == 27) {after = 0; msg(""); return(((void *)0));};
            msg("");
            if (response == '*')
            {
                add_line("! Potion");
                add_line("? Scroll");
                add_line("= Ring");
                add_line("/ Stick");
                add_line("] Armor");
                add_line(") Weapon");
                add_line(": Food");
                end_line();
                continue;
            }
            if (!is_member(type_list, response)) { beep();
               continue; }
            if (count_bag(container, response, ((void *)0)) == 0)
            {
                msg("You don't have any %s.", name_type(response));
                continue;
            }
            type = response;
        }
        while(obj_p == ((void *)0))
        {
            msg("What item do you want to %s (* for list)?", purpose);
            response = readchar();
            msg("");
            if (response == 27) {after = 0; msg(""); return(((void *)0));};
            if (response == '*')
            {
                mpos = 0;
                apply_to_bag(container, type, bff_p, baf_print_item, &type);
                end_line();
                continue;
            }
            sel_type = type;
            sel_id = response;
            obj_p = scan_bag(container, sel_type,unprint_id(&sel_id));
        }
    }
    mpos = 0;
    msg("");
    return(obj_p);
}

canonical_original_code:
struct object *get_object(struct linked_list *container, char *purpose, int type, int (*bff_p)(struct object *obj, union bag_arg *junk))
{
    struct object *obj_p = ((void *)0);
    char sel_id;
    int sel_type;
    char response;
    if (container == ((void *)0))
    {
        msg("There isn't anything in there.");
        after = 0;
        return(((void *)0));
    }
    if (apply_to_bag(container, type, bff_p, ((void *)0), ((void *)0)) == ((void *)0))
    {
        msg("You seem to have nothing to %s.", purpose);
        after = 0;
        return(((void *)0));
    }
    while (obj_p == ((void *)0))
    {
        if (type == 0)
        {
            msg("What kind of item <%s> do you want to %s (* for list)?", type_list, purpose);
            response = readchar();
            if (response == 27) {after = 0; msg(""); return(((void *)0));};
            msg("");
            if (response == '*')
            {
                add_line("! Potion");
                add_line("? Scroll");
                add_line("= Ring");
                add_line("/ Stick");
                add_line("] Armor");
                add_line(") Weapon");
                add_line(": Food");
                end_line();
                continue;
            }
            if (!is_member(type_list, response)) { beep();
               continue; }
            if (count_bag(container, response, ((void *)0)) == 0)
            {
                msg("You don't have any %s.", name_type(response));
                continue;
            }
            type = response;
        }
        while(obj_p == ((void *)0))
        {
            msg("What item do you want to %s (* for list)?", purpose);
            response = readchar();
            msg("");
            if (response == 27) {after = 0; msg(""); return(((void *)0));};
            if (response == '*')
            {
                mpos = 0;
                apply_to_bag(container, type, bff_p, baf_print_item, &type);
                end_line();
                continue;
            }
            sel_type = type;
            sel_id = response;
            obj_p = scan_bag(container, sel_type,unprint_id(&sel_id));
        }
    }
    mpos = 0;
    msg("");
    return(obj_p);
}

variable_types:
container
struct linked_list *

variable_types:
purpose
char *

variable_types: int (*)(struct object *obj, union bag_arg { void *varg; int *iarg; struct object *obj; } *junk)

variable_types: response char

return_type: struct object { struct coord { int x; int y; } o_pos; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *


decompiled_code:
__int64 __fastcall get_item(const char *a1, unsigned int a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = get_object(player[2], a1, a2, 0LL);
if ( v2 )
result = make_item(v2);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, unsigned int a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = func6(player[2], a1, a2, 0LL);
if ( v2 )
result = make_item(v2);
else
result = 0LL;
return result;
}

original_code:
struct linked_list *
get_item(char *purpose, int type)
{
    struct object *obj_p;
    if ((obj_p = get_object(player.t_pack, purpose, type, ((void *)0))) == ((void *)0))
        return(((void *)0));
    return(make_item(obj_p));
}

canonical_original_code:
struct linked_list *get_item(char *purpose, int type)
{
    struct object *obj_p;
    if ((obj_p = get_object(player.t_pack, purpose, type, ((void *)0))) == ((void *)0))
        return(((void *)0));
    return(make_item(obj_p));
}

return_type: struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object { struct coord { int x; int y; } o_pos; struct linked_list *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *


decompiled_code:
void __fastcall cur_null(__int64 a1)
{
if ( cur_weapon == a1 )
{
cur_weapon = 0LL;
}
else if ( cur_armor == a1 )
{
cur_armor = 0LL;
}
else if ( cur_ring[0] == a1 )
{
cur_ring[0] = 0LL;
}
else if ( cur_ring[1] == a1 )
{
cur_ring[1] = 0LL;
}
else if ( cur_ring[2] == a1 )
{
cur_ring[2] = 0LL;
}
else if ( cur_ring[3] == a1 )
{
cur_ring[3] = 0LL;
}
else if ( cur_ring[4] == a1 )
{
cur_ring[4] = 0LL;
}
else if ( cur_ring[5] == a1 )
{
cur_ring[5] = 0LL;
}
else if ( cur_ring[6] == a1 )
{
cur_ring[6] = 0LL;
}
else if ( cur_ring[7] == a1 )
{
cur_ring[7] = 0LL;
}
else if ( cur_ring[8] == a1 )
{
cur_ring[8] = 0LL;
}
else if ( cur_ring[9] == a1 )
{
cur_ring[9] = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
if ( cur_weapon == a1 )
{
cur_weapon = 0LL;
}
else if ( cur_armor == a1 )
{
cur_armor = 0LL;
}
else if ( cur_ring[0] == a1 )
{
cur_ring[0] = 0LL;
}
else if ( cur_ring[1] == a1 )
{
cur_ring[1] = 0LL;
}
else if ( cur_ring[2] == a1 )
{
cur_ring[2] = 0LL;
}
else if ( cur_ring[3] == a1 )
{
cur_ring[3] = 0LL;
}
else if ( cur_ring[4] == a1 )
{
cur_ring[4] = 0LL;
}
else if ( cur_ring[5] == a1 )
{
cur_ring[5] = 0LL;
}
else if ( cur_ring[6] == a1 )
{
cur_ring[6] = 0LL;
}
else if ( cur_ring[7] == a1 )
{
cur_ring[7] = 0LL;
}
else if ( cur_ring[8] == a1 )
{
cur_ring[8] = 0LL;
}
else if ( cur_ring[9] == a1 )
{
cur_ring[9] = 0LL;
}
}

original_code:
void
cur_null(struct object *op)
{
    if (op == cur_weapon)
        cur_weapon = ((void *)0);
    else if (op == cur_armor)
        cur_armor = ((void *)0);
    else if (op == cur_ring[0])
        cur_ring[0] = ((void *)0);
    else if (op == cur_ring[1])
        cur_ring[1] = ((void *)0);
    else if (op == cur_ring[2])
        cur_ring[2] = ((void *)0);
    else if (op == cur_ring[3])
        cur_ring[3] = ((void *)0);
    else if (op == cur_ring[4])
        cur_ring[4] = ((void *)0);
    else if (op == cur_ring[5])
        cur_ring[5] = ((void *)0);
    else if (op == cur_ring[6])
        cur_ring[6] = ((void *)0);
    else if (op == cur_ring[7])
        cur_ring[7] = ((void *)0);
    else if (op == cur_ring[8])
        cur_ring[8] = ((void *)0);
    else if (op == cur_ring[9])
        cur_ring[9] = ((void *)0);
}


decompiled_code:
__int64 __fastcall rem_pack(__int64 a1)
{
cur_null(a1);
pop_bag((unsigned int)((_DWORD)player + 16), a1);
return updpack();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
func8(a1);
pop_bag((unsigned int)((_DWORD)player + 16), a1);
return updpack();
}

original_code:
void
rem_pack(struct object *obj_p)
{
    cur_null(obj_p);
    pop_bag(&player.t_pack, obj_p);
    updpack();
    return;
}


decompiled_code:
__int64 __fastcall del_pack(__int64 a1)
{
rem_pack(*(_QWORD *)(a1 + 16));
return discard(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
func9(*(_QWORD *)(a1 + 16));
return discard(a1);
}

original_code:
void
del_pack(struct linked_list *what)
{
    rem_pack(((*what).data.obj));
    discard(what);
}


decompiled_code:
__int64 __fastcall discard_pack(__int64 a1)
{
rem_pack(a1);
return throw_away(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
func9(a1);
return throw_away(a1);
}

original_code:
void
discard_pack(struct object *obj_p)
{
    rem_pack(obj_p);
    throw_away(obj_p);
}


idenpack

decompiled_code:
__int64 idenpack()
{
return apply_to_bag(player[2], 0LL, 0LL, &baf_identify, 0LL);
}

canonical_decompiled_code:
__int64 func12()
{
return apply_to_bag(player[2], 0LL, 0LL, &baf_identify, 0LL);
}

original_code:
void
idenpack(void)
{
    apply_to_bag(player.t_pack, 0, ((void *)0), baf_identify, ((void *)0));
}

canonical_original_code:
void idenpack()
{
    apply_to_bag(player.t_pack, 0, ((void *)0), baf_identify, ((void *)0));
}


decompiled_code:
__int64 show_floor()
{
__int64 result; // rax
__int64 v1; // rbx
const char *v2; // rsi
__int64 v3; // rdi
__int64 v4; // rax

result = find_obj(player[49], player[48]);
if ( result )
{
v1 = result;
v2 = "Moved";
if ( !terse )
v2 = "You moved";
addmsg("%s onto ");
v3 = *(_QWORD *)(v1 + 16);
if ( *(_QWORD *)(v3 + 8) )
{
result = msg("a stack of things.", v2);
}
else if ( *(_BYTE *)(v3 + 64) == 42 )
{
result = msg("%d gold pieces.", *(unsigned int *)(v3 + 72));
}
else
{
v4 = inv_name(v3, 1LL);
addmsg(v4);
addmsg(".");
result = endmsg();
}
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
__int64 v1; // rbx
const char *v2; // rsi
__int64 v3; // rdi
__int64 v4; // rax

result = find_obj(player[49], player[48]);
if ( result )
{
v1 = result;
v2 = "Moved";
if ( !terse )
v2 = "You moved";
addmsg("%s onto ");
v3 = *(_QWORD *)(v1 + 16);
if ( *(_QWORD *)(v3 + 8) )
{
result = msg("a stack of things.", v2);
}
else if ( *(_BYTE *)(v3 + 64) == 42 )
{
result = msg("%d gold pieces.", *(unsigned int *)(v3 + 72));
}
else
{
v4 = inv_name(v3, 1LL);
addmsg(v4);
addmsg(".");
result = endmsg();
}
}
return result;
}

original_code:
void
show_floor(void)
{
    struct linked_list *item;
    struct object *obj;
    item = find_obj(player.t_pos.y, player.t_pos.x);
    if (item != ((void *)0))
    {
        addmsg("%s onto ", terse ? "Moved" : "You moved");
        obj = ((*item).data.obj);
        if (obj->next_obj != ((void *)0))
      msg("a stack of things.");
  else if (obj->o_type == '*')
            msg("%d gold pieces.", obj->o_count);
        else
        {
            addmsg(inv_name(obj, 1));
            addmsg(".");
            endmsg();
        }
    }
}

canonical_original_code:
void show_floor()
{
    struct linked_list *item;
    struct object *obj;
    item = find_obj(player.t_pos.y, player.t_pos.x);
    if (item != ((void *)0))
    {
        addmsg("%s onto ", terse ? "Moved" : "You moved");
        obj = ((*item).data.obj);
        if (obj->next_obj != ((void *)0))
      msg("a stack of things.");
  else if (obj->o_type == '*')
            msg("%d gold pieces.", obj->o_count);
        else
        {
            addmsg(inv_name(obj, 1));
            addmsg(".");
            endmsg();
        }
    }
}


decompiled_code:
__int64 ring_on()
{
__int64 result; // rax
__int64 v1; // rbx
const char *v2; // rdi
int v3; // eax
__int64 v4; // rdx
size_t v5; // rax
__int64 v6; // rbp
char v7[1048]; // [rsp+0h] [rbp-418h] BYREF

result = get_item("put on", 61LL);
if ( result )
{
v1 = *(_QWORD *)(result + 16);
v2 = "You can't put that on!";
if ( *(_BYTE *)(v1 + 64) != 61 )
return msg(v2);
v3 = is_current(*(_QWORD *)(result + 16));
v2 = "Already wearing that!";
if ( v3 )
return msg(v2);
if ( cur_ring[0] )
{
if ( cur_ring[1] )
{
if ( cur_ring[2] )
{
if ( cur_ring[3] )
{
if ( cur_ring[4] )
{
if ( cur_ring[5] )
{
if ( cur_ring[6] )
{
if ( cur_ring[7] )
{
if ( cur_ring[8] )
{
v3 = 9;
if ( cur_ring[9] )
{
v2 = "You already have on ten rings.";
return msg(v2);
}
}
else
{
v3 = 8;
}
}
else
{
v3 = 7;
}
}
else
{
v3 = 6;
}
}
else
{
v3 = 5;
}
}
else
{
v3 = 4;
}
}
else
{
v3 = 3;
}
}
else
{
v3 = 2;
}
}
else
{
v3 = 1;
}
}
cur_ring[v3] = v1;
switch ( *(_DWORD *)(v1 + 76) )
{
case 1:
*((_DWORD *)&player + 18) += *(_DWORD *)(v1 + 88);
break;
case 4:
if ( (*((_BYTE *)&player + 232) & 8) == 0 )
{
*((_QWORD *)&player + 32) |= 0x4000uLL;
msg("Your eyes begin to tingle.");
sight(0LL);
goto LABEL_35;
}
break;
case 6:
aggravate("Already wearing that!");
break;
case 7:
*((_DWORD *)&player + 21) += *(_DWORD *)(v1 + 88);
break;
case 0xD:
*((_DWORD *)&player + 19) += *(_DWORD *)(v1 + 88);
break;
case 0xE:
*((_DWORD *)&player + 20) += *(_DWORD *)(v1 + 88);
break;
case 0x11:
if ( roomin(*((_QWORD *)&player + 24)) )
goto LABEL_35;
break;
case 0x13:
updpack("Already wearing that!");
break;
case 0x15:
msg("You begin to float in the air!");
break;
case 0x1B:
*((_QWORD *)&player + 27) &= 0xFFFFFFFFFFFFFEFFLL;
hold_count = 0;
break;
case 0x1F:
if ( (*((_BYTE *)&player + 232) & 8) == 0 )
{
*((_QWORD *)&player + 32) |= 0x4000uLL;
msg("You become more aware of your surroundings.");
sight(0LL);
LABEL_35:
light((unsigned int)((_DWORD)&player + 192));
if ( wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
waddch(cw, (unsigned int)PLAYER);
}
break;
default:
break;
}
status(0LL);
result = *(int *)(v1 + 76);
v4 = result + 100;
if ( know_items[result + 100] )
{
if ( *((_QWORD *)&guess_items + v4) )
{
mem_free();
result = *(int *)(v1 + 76);
*((_QWORD *)&guess_items + result + 100) = 0LL;
}
}
else
{
result = askme;
if ( askme && (*(_BYTE *)(v1 + 48) & 2) == 0 && !*((_QWORD *)&guess_items + v4) )
{
mpos = 0;
msg("What do you want to call it? ");
if ( !(unsigned int)get_string(v7, cw) )
{
v5 = strlen(v7);
v6 = *(int *)(v1 + 76);
*((_QWORD *)&guess_items + v6 + 100) = new_alloc(v5 + 1);
strcpy(*((char **)&guess_items + *(int *)(v1 + 76) + 100), v7);
}
result = msg(&unk_8E7);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // rbx
const char *v2; // rdi
int v3; // eax
__int64 v4; // rdx
size_t v5; // rax
__int64 v6; // rbp
char v7[1048]; // [rsp+0h] [rbp-418h] BYREF

result = get_item("put on", 61LL);
if ( result )
{
v1 = *(_QWORD *)(result + 16);
v2 = "You can't put that on!";
if ( *(_BYTE *)(v1 + 64) != 61 )
return msg(v2);
v3 = is_current(*(_QWORD *)(result + 16));
v2 = "Already wearing that!";
if ( v3 )
return msg(v2);
if ( cur_ring[0] )
{
if ( cur_ring[1] )
{
if ( cur_ring[2] )
{
if ( cur_ring[3] )
{
if ( cur_ring[4] )
{
if ( cur_ring[5] )
{
if ( cur_ring[6] )
{
if ( cur_ring[7] )
{
if ( cur_ring[8] )
{
v3 = 9;
if ( cur_ring[9] )
{
v2 = "You already have on ten rings.";
return msg(v2);
}
}
else
{
v3 = 8;
}
}
else
{
v3 = 7;
}
}
else
{
v3 = 6;
}
}
else
{
v3 = 5;
}
}
else
{
v3 = 4;
}
}
else
{
v3 = 3;
}
}
else
{
v3 = 2;
}
}
else
{
v3 = 1;
}
}
cur_ring[v3] = v1;
switch ( *(_DWORD *)(v1 + 76) )
{
case 1:
*((_DWORD *)&player + 18) += *(_DWORD *)(v1 + 88);
break;
case 4:
if ( (*((_BYTE *)&player + 232) & 8) == 0 )
{
*((_QWORD *)&player + 32) |= 0x4000uLL;
msg("Your eyes begin to tingle.");
sight(0LL);
goto LABEL_35;
}
break;
case 6:
aggravate("Already wearing that!");
break;
case 7:
*((_DWORD *)&player + 21) += *(_DWORD *)(v1 + 88);
break;
case 0xD:
*((_DWORD *)&player + 19) += *(_DWORD *)(v1 + 88);
break;
case 0xE:
*((_DWORD *)&player + 20) += *(_DWORD *)(v1 + 88);
break;
case 0x11:
if ( roomin(*((_QWORD *)&player + 24)) )
goto LABEL_35;
break;
case 0x13:
updpack("Already wearing that!");
break;
case 0x15:
msg("You begin to float in the air!");
break;
case 0x1B:
*((_QWORD *)&player + 27) &= 0xFFFFFFFFFFFFFEFFLL;
hold_count = 0;
break;
case 0x1F:
if ( (*((_BYTE *)&player + 232) & 8) == 0 )
{
*((_QWORD *)&player + 32) |= 0x4000uLL;
msg("You become more aware of your surroundings.");
sight(0LL);
LABEL_35:
light((unsigned int)((_DWORD)&player + 192));
if ( wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
waddch(cw, (unsigned int)PLAYER);
}
break;
default:
break;
}
status(0LL);
result = *(int *)(v1 + 76);
v4 = result + 100;
if ( know_items[result + 100] )
{
if ( *((_QWORD *)&guess_items + v4) )
{
mem_free();
result = *(int *)(v1 + 76);
*((_QWORD *)&guess_items + result + 100) = 0LL;
}
}
else
{
result = askme;
if ( askme && (*(_BYTE *)(v1 + 48) & 2) == 0 && !*((_QWORD *)&guess_items + v4) )
{
mpos = 0;
msg("What do you want to call it? ");
if ( !(unsigned int)get_string(v7, cw) )
{
v5 = strlen(v7);
v6 = *(int *)(v1 + 76);
*((_QWORD *)&guess_items + v6 + 100) = new_alloc(v5 + 1);
strcpy(*((char **)&guess_items + *(int *)(v1 + 76) + 100), v7);
}
result = msg(&unk_8E7);
}
}
}
return result;
}

original_code:
void
ring_on(void)
{
    struct object *obj;
    struct linked_list *item;
    int ring;
    char buf[2 * 512];
    if ((item = get_item("put on", '=')) == ((void *)0))
        return;
    obj = ((*item).data.obj);
    if (obj->o_type != '=')
    {
        msg("You can't put that on!");
        return;
    }
    if (is_current(obj))
    {
        msg("Already wearing that!");
        return;
    }
    if (cur_ring[0] == ((void *)0))
        ring = 0;
    else if (cur_ring[1] == ((void *)0))
        ring = 1;
    else if (cur_ring[2] == ((void *)0))
        ring = 2;
    else if (cur_ring[3] == ((void *)0))
        ring = 3;
    else if (cur_ring[4] == ((void *)0))
        ring = 4;
    else if (cur_ring[5] == ((void *)0))
        ring = 5;
    else if (cur_ring[6] == ((void *)0))
        ring = 6;
    else if (cur_ring[7] == ((void *)0))
        ring = 7;
    else if (cur_ring[8] == ((void *)0))
        ring = 8;
    else if (cur_ring[9] == ((void *)0))
        ring = 9;
    else
    {
        msg("You already have on ten rings.");
        return;
    }
    cur_ring[ring] = obj;
    switch (obj->o_which)
    {
        case 1:
            player.t_stats.s_str += obj->o_ac;
            break;
        case 7:
            player.t_stats.s_dext += obj->o_ac;
            break;
        case 13:
            player.t_stats.s_intel += obj->o_ac;
            break;
        case 14:
            player.t_stats.s_wisdom += obj->o_ac;
            break;
        case 27:
            ( (player).t_flags[(0x00000100UL >> 28UL) & 0x0000000fL] &= ~(0x00000100UL & 0x0fffffffL));
            hold_count = 0;
            break;
        case 31:
            if ((!((player).t_flags[(0x20000008UL >> 28UL) & 0x0000000fL] & (0x20000008UL & 0x0fffffffL))))
            {
                ( (player).t_flags[(0x50004000UL >> 28UL) & 0x0000000fL] |= (0x50004000UL & 0x0fffffffL));
                msg("You become more aware of your surroundings.");
                sight(((void *)0));
                light(&player.t_pos);
                (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
            }
            break;
        case 4:
            if ((!((player).t_flags[(0x20000008UL >> 28UL) & 0x0000000fL] & (0x20000008UL & 0x0fffffffL))))
            {
                ( (player).t_flags[(0x50004000UL >> 28UL) & 0x0000000fL] |= (0x50004000UL & 0x0fffffffL));
                msg("Your eyes begin to tingle.");
                sight(((void *)0));
                light(&player.t_pos);
                (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
            }
            break;
        case 6:
            aggravate();
            break;
        case 19:
            updpack();
            break;
        case 21:
            msg("You begin to float in the air!");
            break;
        case 17:
            if (roomin(player.t_pos) != ((void *)0))
            {
                light(&player.t_pos);
                (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
            }
    }
    status(0);
    if (know_items[2][obj->o_which] &&
        guess_items[2][obj->o_which])
    {
        mem_free(guess_items[2][obj->o_which]);
        guess_items[2][obj->o_which] = ((void *)0);
    }
    else if (!know_items[2][obj->o_which] &&
         askme &&
         (obj->o_flags & 0x00000002UL) == 0 &&
         guess_items[2][obj->o_which] == ((void *)0))
    {
        mpos = 0;
        msg("What do you want to call it? ");
        if (get_string(buf, cw) == 0)
        {
            guess_items[2][obj->o_which] =
                new_alloc(strlen(buf) + 1);
            strcpy(guess_items[2][obj->o_which], buf);
        }
        msg("");
    }
}

canonical_original_code:
void ring_on()
{
    struct object *obj;
    struct linked_list *item;
    int ring;
    char buf[-1];
    if ((item = get_item("put on", '=')) == ((void *)0))
        return;
    obj = ((*item).data.obj);
    if (obj->o_type != '=')
    {
        msg("You can't put that on!");
        return;
    }
    if (is_current(obj))
    {
        msg("Already wearing that!");
        return;
    }
    if (cur_ring[0] == ((void *)0))
        ring = 0;
    else if (cur_ring[1] == ((void *)0))
        ring = 1;
    else if (cur_ring[2] == ((void *)0))
        ring = 2;
    else if (cur_ring[3] == ((void *)0))
        ring = 3;
    else if (cur_ring[4] == ((void *)0))
        ring = 4;
    else if (cur_ring[5] == ((void *)0))
        ring = 5;
    else if (cur_ring[6] == ((void *)0))
        ring = 6;
    else if (cur_ring[7] == ((void *)0))
        ring = 7;
    else if (cur_ring[8] == ((void *)0))
        ring = 8;
    else if (cur_ring[9] == ((void *)0))
        ring = 9;
    else
    {
        msg("You already have on ten rings.");
        return;
    }
    cur_ring[ring] = obj;
    switch (obj->o_which)
    {
        case 1:
            player.t_stats.s_str += obj->o_ac;
            break;
        case 7:
            player.t_stats.s_dext += obj->o_ac;
            break;
        case 13:
            player.t_stats.s_intel += obj->o_ac;
            break;
        case 14:
            player.t_stats.s_wisdom += obj->o_ac;
            break;
        case 27:
            ( (player).t_flags[(0x00000100UL >> 28UL) & 0x0000000fL] &= ~(0x00000100UL & 0x0fffffffL));
            hold_count = 0;
            break;
        case 31:
            if ((!((player).t_flags[(0x20000008UL >> 28UL) & 0x0000000fL] & (0x20000008UL & 0x0fffffffL))))
            {
                ( (player).t_flags[(0x50004000UL >> 28UL) & 0x0000000fL] |= (0x50004000UL & 0x0fffffffL));
                msg("You become more aware of your surroundings.");
                sight(((void *)0));
                light(&player.t_pos);
                (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
            }
            break;
        case 4:
            if ((!((player).t_flags[(0x20000008UL >> 28UL) & 0x0000000fL] & (0x20000008UL & 0x0fffffffL))))
            {
                ( (player).t_flags[(0x50004000UL >> 28UL) & 0x0000000fL] |= (0x50004000UL & 0x0fffffffL));
                msg("Your eyes begin to tingle.");
                sight(((void *)0));
                light(&player.t_pos);
                (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
            }
            break;
        case 6:
            aggravate();
            break;
        case 19:
            updpack();
            break;
        case 21:
            msg("You begin to float in the air!");
            break;
        case 17:
            if (roomin(player.t_pos) != ((void *)0))
            {
                light(&player.t_pos);
                (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
            }
    }
    status(0);
    if (know_items[2][obj->o_which] &&
        guess_items[2][obj->o_which])
    {
        mem_free(guess_items[2][obj->o_which]);
        guess_items[2][obj->o_which] = ((void *)0);
    }
    else if (!know_items[2][obj->o_which] &&
         askme &&
         (obj->o_flags & 0x00000002UL) == 0 &&
         guess_items[2][obj->o_which] == ((void *)0))
    {
        mpos = 0;
        msg("What do you want to call it? ");
        if (get_string(buf, cw) == 0)
        {
            guess_items[2][obj->o_which] =
                new_alloc(strlen(buf) + 1);
            strcpy(guess_items[2][obj->o_which], buf);
        }
        msg("");
    }
}

variable_types: ring int

variable_types:
buf
char [-1]


decompiled_code:
__int64 ring_off()
{
__int64 result; // rax
__int64 v1; // rbp
const char *v2; // rax

if ( !cur_ring[0]
&& !cur_ring[1]
&& !cur_ring[2]
&& !cur_ring[3]
&& !cur_ring[4]
&& !cur_ring[5]
&& !cur_ring[6]
&& !cur_ring[7]
&& !cur_ring[8]
&& !cur_ring[9] )
{
return msg("You aren't wearing any rings.");
}
result = get_item("remove", 61LL);
if ( result )
{
mpos = 0;
v1 = *(_QWORD *)(result + 16);
if ( !v1 )
msg("You are not wearing that!");
result = dropcheck(v1);
if ( (_DWORD)result )
{
switch ( *(_DWORD *)(v1 + 76) )
{
case 4:
msg("Your eyes stop tingling.");
break;
case 0x11:
if ( roomin(*((_QWORD *)&player + 24)) )
{
light((unsigned int)((_DWORD)&player + 192));
if ( wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
waddch(cw, (unsigned int)PLAYER);
}
break;
case 0x13:
updpack(v1);
break;
case 0x15:
msg("You float gently to the ground.");
break;
case 0x1F:
msg("Your sensory perceptions return to normal.");
break;
default:
break;
}
v2 = (const char *)inv_name(v1, 1LL);
result = msg("Was wearing %s.", v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // rbp
const char *v2; // rax

if ( !cur_ring[0]
&& !cur_ring[1]
&& !cur_ring[2]
&& !cur_ring[3]
&& !cur_ring[4]
&& !cur_ring[5]
&& !cur_ring[6]
&& !cur_ring[7]
&& !cur_ring[8]
&& !cur_ring[9] )
{
return msg("You aren't wearing any rings.");
}
result = get_item("remove", 61LL);
if ( result )
{
mpos = 0;
v1 = *(_QWORD *)(result + 16);
if ( !v1 )
msg("You are not wearing that!");
result = dropcheck(v1);
if ( (_DWORD)result )
{
switch ( *(_DWORD *)(v1 + 76) )
{
case 4:
msg("Your eyes stop tingling.");
break;
case 0x11:
if ( roomin(*((_QWORD *)&player + 24)) )
{
light((unsigned int)((_DWORD)&player + 192));
if ( wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
waddch(cw, (unsigned int)PLAYER);
}
break;
case 0x13:
updpack(v1);
break;
case 0x15:
msg("You float gently to the ground.");
break;
case 0x1F:
msg("Your sensory perceptions return to normal.");
break;
default:
break;
}
v2 = (const char *)inv_name(v1, 1LL);
result = msg("Was wearing %s.", v2);
}
}
return result;
}

original_code:
void
ring_off(void)
{
    struct object *obj;
    struct linked_list *item;
    if (cur_ring[0] == ((void *)0) && cur_ring[1] == ((void *)0) &&
        cur_ring[2] == ((void *)0) && cur_ring[3] == ((void *)0) &&
        cur_ring[4] == ((void *)0) &&
        cur_ring[5] == ((void *)0) && cur_ring[6] == ((void *)0) &&
        cur_ring[7] == ((void *)0) && cur_ring[8] == ((void *)0) &&
        cur_ring[9] == ((void *)0))
    {
        msg("You aren't wearing any rings.");
        return;
    }
    else if ((item = get_item("remove", '=')) == ((void *)0))
        return;
    mpos = 0;
    obj = ((*item).data.obj);
    if ((obj = ((*item).data.obj)) == ((void *)0))
        msg("You are not wearing that!");
    if (dropcheck(obj))
    {
        switch (obj->o_which)
        {
            case 4:
                msg("Your eyes stop tingling.");
                break;
            case 19:
                updpack();
                break;
            case 21:
                msg("You float gently to the ground.");
                break;
            case 17:
                if (roomin(player.t_pos) != ((void *)0))
                {
                    light(&player.t_pos);
                    (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
                }
                break;
            case 31:
                msg("Your sensory perceptions return to normal.");
                break;
        }
        msg("Was wearing %s.", inv_name(obj, 1));
    }
}

canonical_original_code:
void ring_off()
{
    struct object *obj;
    struct linked_list *item;
    if (cur_ring[0] == ((void *)0) && cur_ring[1] == ((void *)0) &&
        cur_ring[2] == ((void *)0) && cur_ring[3] == ((void *)0) &&
        cur_ring[4] == ((void *)0) &&
        cur_ring[5] == ((void *)0) && cur_ring[6] == ((void *)0) &&
        cur_ring[7] == ((void *)0) && cur_ring[8] == ((void *)0) &&
        cur_ring[9] == ((void *)0))
    {
        msg("You aren't wearing any rings.");
        return;
    }
    else if ((item = get_item("remove", '=')) == ((void *)0))
        return;
    mpos = 0;
    obj = ((*item).data.obj);
    if ((obj = ((*item).data.obj)) == ((void *)0))
        msg("You are not wearing that!");
    if (dropcheck(obj))
    {
        switch (obj->o_which)
        {
            case 4:
                msg("Your eyes stop tingling.");
                break;
            case 19:
                updpack();
                break;
            case 21:
                msg("You float gently to the ground.");
                break;
            case 17:
                if (roomin(player.t_pos) != ((void *)0))
                {
                    light(&player.t_pos);
                    (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
                }
                break;
            case 31:
                msg("Your sensory perceptions return to normal.");
                break;
        }
        msg("Was wearing %s.", inv_name(obj, 1));
    }
}


decompiled_code:
__int64 __fastcall ring_eat(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdx
int v4; // eax
__int64 v5; // rdi
int v6; // eax
int v7; // ebp
int v8; // kr00_4
int v9; // ebp

v1 = a1;
LODWORD(v2) = 0;
v3 = cur_ring[a1];
if ( v3 )
{
v4 = *(_DWORD *)(v3 + 76);
if ( v4 != 10 )
{
if ( v4 > 10 )
{
LODWORD(v2) = 1;
if ( v4 != 16 )
return (unsigned int)v2 + (unsigned int)rnd((unsigned int)luck);
}
else
{
if ( v4 == 3 )
{
v2 = (int)rnd(100LL) <= 32;
return (unsigned int)v2 + (unsigned int)rnd((unsigned int)luck);
}
if ( v4 != 9 )
{
LODWORD(v2) = 1;
return (unsigned int)v2 + (unsigned int)rnd((unsigned int)luck);
}
}
v5 = 10LL;
if ( (int)player[14] <= 10 )
v5 = player[14];
v6 = rnd(v5);
v3 = cur_ring[v1];
LODWORD(v2) = v6;
}
v7 = *(_DWORD *)(v3 + 88);
if ( v7 >= 0 || (unsigned int)rnd((unsigned int)(v7 / -3 + 1)) )
{
v8 = v7;
v9 = ~v7;
if ( !(unsigned int)rnd((unsigned int)(v8 / 2 + 2)) )
LODWORD(v2) = v9;
}
else
{
LODWORD(v2) = 1 - v7;
}
}
return (unsigned int)v2 + (unsigned int)rnd((unsigned int)luck);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
__int64 v3; // rdx
int v4; // eax
__int64 v5; // rdi
int v6; // eax
int v7; // ebp
int v8; // kr00_4
int v9; // ebp

v1 = a1;
LODWORD(v2) = 0;
v3 = cur_ring[a1];
if ( v3 )
{
v4 = *(_DWORD *)(v3 + 76);
if ( v4 != 10 )
{
if ( v4 > 10 )
{
LODWORD(v2) = 1;
if ( v4 != 16 )
return (unsigned int)v2 + (unsigned int)rnd((unsigned int)luck);
}
else
{
if ( v4 == 3 )
{
v2 = (int)rnd(100LL) <= 32;
return (unsigned int)v2 + (unsigned int)rnd((unsigned int)luck);
}
if ( v4 != 9 )
{
LODWORD(v2) = 1;
return (unsigned int)v2 + (unsigned int)rnd((unsigned int)luck);
}
}
v5 = 10LL;
if ( (int)player[14] <= 10 )
v5 = player[14];
v6 = rnd(v5);
v3 = cur_ring[v1];
LODWORD(v2) = v6;
}
v7 = *(_DWORD *)(v3 + 88);
if ( v7 >= 0 || (unsigned int)rnd((unsigned int)(v7 / -3 + 1)) )
{
v8 = v7;
v9 = ~v7;
if ( !(unsigned int)rnd((unsigned int)(v8 / 2 + 2)) )
LODWORD(v2) = v9;
}
else
{
LODWORD(v2) = 1 - v7;
}
}
return (unsigned int)v2 + (unsigned int)rnd((unsigned int)luck);
}

original_code:
int
ring_eat(int hand)
{
    int ret_val = 0;
    int ac;
    if (cur_ring[hand] != ((void *)0))
    {
        switch (cur_ring[hand]->o_which)
        {
            case 9:
            case 16:
                ret_val = rnd(player.t_stats.s_lvl > 10 ? 10 : player.t_stats.s_lvl);
            case 10:
                ac = cur_ring[hand]->o_ac;
                if (ac < 0 && rnd(1 - (ac / 3)) == 0)
                    ret_val = -ac + 1;
                else if (rnd((ac / 2) + 2) == 0)
                    ret_val = -1 - ac;
                break;
            case 3:
                ret_val = rnd(100) < 33;
                break;
   default:
       ret_val = 1;
        }
    }
    ret_val += rnd(luck);
    return(ret_val);
}

variable_types: hand int

variable_types: ac int


decompiled_code:
const char *__fastcall ring_num(__int64 a1, _BYTE *a2)
{
__int64 v2; // rax
__int64 v3; // rdi
const char *v4; // rax
__int64 v6; // [rsp+0h] [rbp-408h] BYREF

if ( !a2 )
return "A bug in UltraRogue #101";
*a2 = 0;
v2 = *(_QWORD *)(a1 + 48);
if ( (v2 & 2) != 0 )
{
switch ( *(_DWORD *)(a1 + 76) )
{
case 0:
case 1:
case 3:
case 7:
case 8:
case 9:
case 0xD:
case 0xE:
case 0x10:
case 0x13:
case 0x19:
case 0x1C:
case 0x1D:
case 0x1E:
*a2 = 32;
v3 = *(unsigned int *)(a1 + 88);
goto LABEL_5;
case 0xA:
*a2 = 32;
v3 = *(_DWORD *)(a1 + 88) - (unsigned int)(*(_DWORD *)(a1 + 88) < 0x80000000);
LABEL_5:
v4 = (const char *)num(v3, 0LL, &v6);
strcpy(a2 + 1, v4);
break;
default:
if ( (v2 & 1) != 0 )
*(_QWORD *)a2 = 0x64657372756320LL;
break;
}
}
return a2;
}

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1, _BYTE *a2)
{
__int64 v2; // rax
__int64 v3; // rdi
const char *v4; // rax
__int64 v6; // [rsp+0h] [rbp-408h] BYREF

if ( !a2 )
return "A bug in UltraRogue #101";
*a2 = 0;
v2 = *(_QWORD *)(a1 + 48);
if ( (v2 & 2) != 0 )
{
switch ( *(_DWORD *)(a1 + 76) )
{
case 0:
case 1:
case 3:
case 7:
case 8:
case 9:
case 0xD:
case 0xE:
case 0x10:
case 0x13:
case 0x19:
case 0x1C:
case 0x1D:
case 0x1E:
*a2 = 32;
v3 = *(unsigned int *)(a1 + 88);
goto LABEL_5;
case 0xA:
*a2 = 32;
v3 = *(_DWORD *)(a1 + 88) - (unsigned int)(*(_DWORD *)(a1 + 88) < 0x80000000);
LABEL_5:
v4 = (const char *)num(v3, 0LL, &v6);
strcpy(a2 + 1, v4);
break;
default:
if ( (v2 & 1) != 0 )
*(_QWORD *)a2 = 0x64657372756320LL;
break;
}
}
return a2;
}

original_code:
char *
ring_num(struct object *obj, char *buf)
{
    char buffer[1024];
    if (buf == ((void *)0))
        return("A bug in UltraRogue #101");
    buf[0] = 0;
    if (obj->o_flags & 0x00000002UL)
    {
        switch (obj->o_which)
        {
            case 3:
            case 0:
            case 1:
            case 8:
            case 7:
            case 13:
            case 14:
            case 19:
            case 16:
            case 25:
            case 30:
            case 9:
            case 29:
            case 28:
                buf[0] = ' ';
                strcpy(&buf[1], num(obj->o_ac, 0,buffer));
                break;
            case 10:
                buf[0] = ' ';
                strcpy(&buf[1], num(obj->o_ac < 0 ?
                obj->o_ac : obj->o_ac - 1, 0, buffer));
                break;
            default:
                if (obj->o_flags & 0x00000001UL)
                    strcpy(buf, " cursed");
                break;
        }
    }
    return(buf);
}

canonical_original_code:
char *ring_num(struct object *obj, char *buf)
{
    char buffer[1024];
    if (buf == ((void *)0))
        return("A bug in UltraRogue #101");
    buf[0] = 0;
    if (obj->o_flags & 0x00000002UL)
    {
        switch (obj->o_which)
        {
            case 3:
            case 0:
            case 1:
            case 8:
            case 7:
            case 13:
            case 14:
            case 19:
            case 16:
            case 25:
            case 30:
            case 9:
            case 29:
            case 28:
                buf[0] = ' ';
                strcpy(&buf[1], num(obj->o_ac, 0,buffer));
                break;
            case 10:
                buf[0] = ' ';
                strcpy(&buf[1], num(obj->o_ac < 0 ?
                obj->o_ac : obj->o_ac - 1, 0, buffer));
                break;
            default:
                if (obj->o_flags & 0x00000001UL)
                    strcpy(buf, " cursed");
                break;
        }
    }
    return(buf);
}

variable_types:
buf
char *

variable_types:
buffer
char [1024]

return_type: char *


decompiled_code:
__int64 __fastcall ring_value(int a1)
{
__int64 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx

result = 0LL;
if ( cur_ring[0] && *(_DWORD *)(cur_ring[0] + 76LL) == a1 )
result = *(unsigned int *)(cur_ring[0] + 88LL);
v2 = cur_ring[1];
if ( v2 && *(_DWORD *)(v2 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v2 + 88) + result);
v3 = cur_ring[2];
if ( v3 && *(_DWORD *)(v3 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v3 + 88) + result);
v4 = cur_ring[3];
if ( v4 && *(_DWORD *)(v4 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v4 + 88) + result);
v5 = cur_ring[4];
if ( v5 && *(_DWORD *)(v5 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v5 + 88) + result);
v6 = cur_ring[5];
if ( v6 && *(_DWORD *)(v6 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v6 + 88) + result);
v7 = cur_ring[6];
if ( v7 && *(_DWORD *)(v7 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v7 + 88) + result);
v8 = cur_ring[7];
if ( v8 && *(_DWORD *)(v8 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v8 + 88) + result);
v9 = cur_ring[8];
if ( v9 && *(_DWORD *)(v9 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v9 + 88) + result);
v10 = cur_ring[9];
if ( v10 )
{
if ( *(_DWORD *)(v10 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v10 + 88) + result);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
__int64 result; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx

result = 0LL;
if ( cur_ring[0] && *(_DWORD *)(cur_ring[0] + 76LL) == a1 )
result = *(unsigned int *)(cur_ring[0] + 88LL);
v2 = cur_ring[1];
if ( v2 && *(_DWORD *)(v2 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v2 + 88) + result);
v3 = cur_ring[2];
if ( v3 && *(_DWORD *)(v3 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v3 + 88) + result);
v4 = cur_ring[3];
if ( v4 && *(_DWORD *)(v4 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v4 + 88) + result);
v5 = cur_ring[4];
if ( v5 && *(_DWORD *)(v5 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v5 + 88) + result);
v6 = cur_ring[5];
if ( v6 && *(_DWORD *)(v6 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v6 + 88) + result);
v7 = cur_ring[6];
if ( v7 && *(_DWORD *)(v7 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v7 + 88) + result);
v8 = cur_ring[7];
if ( v8 && *(_DWORD *)(v8 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v8 + 88) + result);
v9 = cur_ring[8];
if ( v9 && *(_DWORD *)(v9 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v9 + 88) + result);
v10 = cur_ring[9];
if ( v10 )
{
if ( *(_DWORD *)(v10 + 76) == a1 )
result = (unsigned int)(*(_DWORD *)(v10 + 88) + result);
}
return result;
}

original_code:
int
ring_value(int type)
{
    int result = 0;
    if ((cur_ring[0] != ((void *)0) && cur_ring[0]->o_which == type))
        result += cur_ring[0]->o_ac;
    if ((cur_ring[1] != ((void *)0) && cur_ring[1]->o_which == type))
        result += cur_ring[1]->o_ac;
    if ((cur_ring[2] != ((void *)0) && cur_ring[2]->o_which == type))
        result += cur_ring[2]->o_ac;
    if ((cur_ring[3] != ((void *)0) && cur_ring[3]->o_which == type))
        result += cur_ring[3]->o_ac;
    if ((cur_ring[4] != ((void *)0) && cur_ring[4]->o_which == type))
        result += cur_ring[4]->o_ac;
    if ((cur_ring[5] != ((void *)0) && cur_ring[5]->o_which == type))
        result += cur_ring[5]->o_ac;
    if ((cur_ring[6] != ((void *)0) && cur_ring[6]->o_which == type))
        result += cur_ring[6]->o_ac;
    if ((cur_ring[7] != ((void *)0) && cur_ring[7]->o_which == type))
        result += cur_ring[7]->o_ac;
    if ((cur_ring[8] != ((void *)0) && cur_ring[8]->o_which == type))
        result += cur_ring[8]->o_ac;
    if ((cur_ring[9] != ((void *)0) && cur_ring[9]->o_which == type))
        result += cur_ring[9]->o_ac;
    return(result);
}

variable_types: result int


decompiled_code:
__int64 __fastcall verify_function(const char *a1, unsigned int a2)
{
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

sprintf(v3, "Verify failure in %s at line %d\n", a1, a2);
return fatal(v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned int a2)
{
char v3[88]; // [rsp+0h] [rbp-58h] BYREF

sprintf(v3, "Verify failure in %s at line %d\n", a1, a2);
return fatal(v3);
}

original_code:
void verify_function(const char *file, const int line)
{
 char s[80];
 sprintf(s, "Verify failure in %s at line %d\n", file, line);
 fatal(s);
}

canonical_original_code:
void verify_function(char *file, int line)
{
 char s[80];
 sprintf(s, "Verify failure in %s at line %d\n", file, line);
 fatal(s);
}

variable_types:
file
char *

variable_types: line int

variable_types:
s
char [80]


decompiled_code:
__int64 __fastcall baf_increment(__int64 a1, _DWORD **a2)
{
++**a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD **a2)
{
++**a2;
return 1LL;
}

original_code:
int
baf_increment(object *obj_p, bag_arg *count_p, int id)
{
    (obj_p += 0);
    (id += 0);
    (*count_p->iarg)++;
    return(1);
}

canonical_original_code:
int baf_increment(struct object *obj_p, union bag_arg *count_p, int id)
{
    (obj_p += 0);
    (id += 0);
    (*count_p->iarg)++;
    return(1);
}

variable_types: struct object { struct coord { int x; int y; } o_pos; struct linked_list { struct linked_list *l_next; struct linked_list *l_prev; union { struct object *obj; struct thing { long chasee_index; struct linked_list *t_pack; struct stats { char *s_dmg; long s_exp; long s_hpt; int s_pack; int s_carry; int s_lvl; int s_arm; int s_acmod; int s_power; int s_str; int s_intel; int s_wisdom; int s_dext; int s_const; int s_charisma; } t_stats; struct stats maxstats; int t_ischasing; struct thing *t_chasee; struct object *t_horde; struct coord t_pos; struct coord t_oldpos; struct coord t_nxtpos; long t_flags[16]; int t_praycnt; int t_trans; int t_turn; int t_wasshot; int t_ctype; int t_index; int t_no_move; int t_rest_hpt; int t_rest_pow; int t_doorgoal; char t_type; char t_disguise; char t_oldch; } *th; void *l_data; } data; } *next_obj; struct linked_list *o_bag; char *o_text; char *o_damage; char *o_hurldmg; long o_flags; long ar_flags; char o_type; int o_ident; unsigned int o_count; int o_which; int o_hplus; int o_dplus; int o_ac; int o_group; int o_weight; char o_launch; char o_mark[20]; long o_worth; } *

variable_types: union bag_arg { void *varg; int *iarg; struct object *obj; } *

variable_types: id int