decompiled_code:
__int64 init_colors()
{
int v0; // edx
unsigned __int64 v1; // r12
__int64 v2; // rbp
char *v3; // rbx
_BYTE *v4; // rbx

v0 = maxpotions;
if ( maxpotions > 0 )
{
v1 = (unsigned int)((_DWORD)p_magic + 16);
v2 = 0LL;
do
{
do
v3 = rainbow[(int)rnd(32LL)];
while ( ((*_ctype_b_loc())[*v3] & 0x100) == 0 );
v4 = (_BYTE *)md_strdup(v3);
*((_QWORD *)&p_colors + v2) = v4;
*v4 = (*_ctype_tolower_loc())[(char)*v4];
*((_DWORD *)&know_items + v2) = 0;
*((_QWORD *)&guess_items + v2) = 0LL;
if ( (int)v2 > 0 )
*(_DWORD *)v1 += *(_DWORD *)(v1 - 40);
v0 = maxpotions;
++v2;
v1 += 40LL;
}
while ( maxpotions > (int)v2 );
}
return badcheck("potions", (unsigned __int64)p_magic, v0);
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // edx
unsigned __int64 v1; // r12
__int64 v2; // rbp
char *v3; // rbx
_BYTE *v4; // rbx

v0 = maxpotions;
if ( maxpotions > 0 )
{
v1 = (unsigned int)((_DWORD)p_magic + 16);
v2 = 0LL;
do
{
do
v3 = rainbow[(int)rnd(32LL)];
while ( ((*_ctype_b_loc())[*v3] & 0x100) == 0 );
v4 = (_BYTE *)md_strdup(v3);
*((_QWORD *)&p_colors + v2) = v4;
*v4 = (*_ctype_tolower_loc())[(char)*v4];
*((_DWORD *)&know_items + v2) = 0;
*((_QWORD *)&guess_items + v2) = 0LL;
if ( (int)v2 > 0 )
*(_DWORD *)v1 += *(_DWORD *)(v1 - 40);
v0 = maxpotions;
++v2;
v1 += 40LL;
}
while ( maxpotions > (int)v2 );
}
return func2("potions", (unsigned __int64)p_magic, v0);
}

original_code:
void
init_colors(void)
{
    int i;
    char *str;
    for (i = 0; i < maxpotions; i++)
    {
        do
            str = rainbow[rnd((sizeof rainbow / sizeof (char *)))];
        while( !((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISupper) );
        p_colors[i] = md_strdup(str);
        p_colors[i][0] = (char) tolower(p_colors[i][0]);
        know_items[0][i] = 0;
        guess_items[0][i] = ((void *)0);
        if (i > 0)
            p_magic[i].mi_prob += p_magic[i - 1].mi_prob;
    }
    badcheck("potions", p_magic, maxpotions);
}

canonical_original_code:
void init_colors()
{
    int i;
    char *str;
    for (i = 0; i < maxpotions; i++)
    {
        do
            str = rainbow[rnd((sizeof rainbow / sizeof (char *)))];
        while( !((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISupper) );
        p_colors[i] = md_strdup(str);
        p_colors[i][0] = (char) tolower(p_colors[i][0]);
        know_items[0][i] = 0;
        guess_items[0][i] = ((void *)0);
        if (i > 0)
            p_magic[i].mi_prob += p_magic[i - 1].mi_prob;
    }
    badcheck("potions", p_magic, maxpotions);
}

variable_types: i int

variable_types:
str
char *


repo: RoguelikeRestorationProject/urogue

decompiled_code:
__int64 init_names()
{
int v0; // edx
unsigned __int64 v1; // r14
__int64 v2; // r13
int v3; // ebp
char *v4; // rdx
char i; // al
char *v6; // rbx
char *v7; // rax
int v8; // er12
size_t v9; // rax
char *v10; // rax
int v11; // eax
_BOOL4 v12; // edx

v0 = maxscrolls;
if ( maxscrolls > 0 )
{
v1 = (unsigned int)((_DWORD)s_magic + 16);
v2 = 0LL;
do
{
v11 = rnd((unsigned int)(COLS / 20));
v12 = COLS > 40;
v8 = v12 + v11 + 1;
if ( v12 + v11 == -1 )
{
v6 = &prbuf;
}
else
{
v6 = &prbuf;
do
{
v3 = rnd(3LL);
if ( v3 == -1 )
{
v7 = v6;
}
else
{
while ( 1 )
{
v4 = sylls[(int)rnd(159LL)];
for ( i = *v4; *v4; i = *v4 )
{
++v4;
*v6++ = i;
}
if ( !v3 )
break;
--v3;
}
v7 = v6;
}
v6 = v7 + 1;
*v7 = 32;
--v8;
}
while ( v8 );
}
*(v6 - 1) = 0;
v9 = strlen(&prbuf);
v10 = (char *)new_alloc(v9 + 1);
*((_QWORD *)&s_names + v2) = v10;
know_items[v2 + 50] = 0;
guess_items[v2 + 50] = 0LL;
strcpy(v10, &prbuf);
if ( (int)v2 > 0 )
*(_DWORD *)v1 += *(_DWORD *)(v1 - 40);
v0 = maxscrolls;
++v2;
v1 += 40LL;
}
while ( maxscrolls > (int)v2 );
}
return badcheck("scrolls", (unsigned __int64)s_magic, v0);
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // edx
unsigned __int64 v1; // r14
__int64 v2; // r13
int v3; // ebp
char *v4; // rdx
char i; // al
char *v6; // rbx
char *v7; // rax
int v8; // er12
size_t v9; // rax
char *v10; // rax
int v11; // eax
_BOOL4 v12; // edx

v0 = maxscrolls;
if ( maxscrolls > 0 )
{
v1 = (unsigned int)((_DWORD)s_magic + 16);
v2 = 0LL;
do
{
v11 = rnd((unsigned int)(COLS / 20));
v12 = COLS > 40;
v8 = v12 + v11 + 1;
if ( v12 + v11 == -1 )
{
v6 = &prbuf;
}
else
{
v6 = &prbuf;
do
{
v3 = rnd(3LL);
if ( v3 == -1 )
{
v7 = v6;
}
else
{
while ( 1 )
{
v4 = sylls[(int)rnd(159LL)];
for ( i = *v4; *v4; i = *v4 )
{
++v4;
*v6++ = i;
}
if ( !v3 )
break;
--v3;
}
v7 = v6;
}
v6 = v7 + 1;
*v7 = 32;
--v8;
}
while ( v8 );
}
*(v6 - 1) = 0;
v9 = strlen(&prbuf);
v10 = (char *)new_alloc(v9 + 1);
*((_QWORD *)&s_names + v2) = v10;
know_items[v2 + 50] = 0;
guess_items[v2 + 50] = 0LL;
strcpy(v10, &prbuf);
if ( (int)v2 > 0 )
*(_DWORD *)v1 += *(_DWORD *)(v1 - 40);
v0 = maxscrolls;
++v2;
v1 += 40LL;
}
while ( maxscrolls > (int)v2 );
}
return func2("scrolls", (unsigned __int64)s_magic, v0);
}

original_code:
void
init_names(void)
{
    int nsyl;
    char *cp, *sp;
    int i, nwords;
    for (i = 0; i < maxscrolls; i++)
    {
        cp = prbuf;
        nwords = rnd(COLS / 20) + 1 + (COLS > 40 ? 1 : 0);
        while (nwords--)
        {
            nsyl = rnd(3) + 1;
            while (nsyl--)
            {
                sp = sylls[rnd((sizeof sylls) /
                    (sizeof(char *)))];
                while (*sp)
                    *cp++ = *sp++;
            }
            *cp++ = ' ';
        }
        *--cp = '\0';
        s_names[i] = (char *) new_alloc(strlen(prbuf) + 1);
        know_items[1][i] = 0;
        guess_items[1][i] = 0;
        strcpy(s_names[i], prbuf);
        if (i > 0)
            s_magic[i].mi_prob += s_magic[i - 1].mi_prob;
    }
    badcheck("scrolls", s_magic, maxscrolls);
}

canonical_original_code:
void init_names()
{
    int nsyl;
    char *cp; char *sp;
    int i; int nwords;
    for (i = 0; i < maxscrolls; i++)
    {
        cp = prbuf;
        nwords = rnd(COLS / 20) + 1 + (COLS > 40 ? 1 : 0);
        while (nwords--)
        {
            nsyl = rnd(3) + 1;
            while (nsyl--)
            {
                sp = sylls[rnd((sizeof sylls) /
                    (sizeof(char *)))];
                while (*sp)
                    *cp++ = *sp++;
            }
            *cp++ = ' ';
        }
        *--cp = '\0';
        s_names[i] = (char *) new_alloc(strlen(prbuf) + 1);
        know_items[1][i] = 0;
        guess_items[1][i] = 0;
        strcpy(s_names[i], prbuf);
        if (i > 0)
            s_magic[i].mi_prob += s_magic[i - 1].mi_prob;
    }
    badcheck("scrolls", s_magic, maxscrolls);
}

variable_types: nsyl int

variable_types:
cp
char *

variable_types:
sp
char *

variable_types: nwords int

return_type: void


decompiled_code:
__int64 init_stones()
{
int v0; // edx
unsigned __int64 v1; // r12
__int64 v2; // rbp
char *v3; // rbx
_BYTE *v4; // rbx

v0 = maxrings;
if ( maxrings > 0 )
{
v1 = (unsigned int)((_DWORD)&r_magic + 16);
v2 = 0LL;
do
{
do
v3 = stones[(int)rnd(35LL)];
while ( ((*_ctype_b_loc())[*v3] & 0x100) == 0 );
v4 = (_BYTE *)md_strdup(v3);
*((_QWORD *)&r_stones + v2) = v4;
*v4 = (*_ctype_tolower_loc())[(char)*v4];
know_items[v2 + 100] = 0;
guess_items[v2 + 100] = 0LL;
if ( (int)v2 > 0 )
*(_DWORD *)v1 += *(_DWORD *)(v1 - 40);
v0 = maxrings;
++v2;
v1 += 40LL;
}
while ( maxrings > (int)v2 );
}
return badcheck("rings", (unsigned __int64)&r_magic, v0);
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // edx
unsigned __int64 v1; // r12
__int64 v2; // rbp
char *v3; // rbx
_BYTE *v4; // rbx

v0 = maxrings;
if ( maxrings > 0 )
{
v1 = (unsigned int)((_DWORD)&r_magic + 16);
v2 = 0LL;
do
{
do
v3 = stones[(int)rnd(35LL)];
while ( ((*_ctype_b_loc())[*v3] & 0x100) == 0 );
v4 = (_BYTE *)md_strdup(v3);
*((_QWORD *)&r_stones + v2) = v4;
*v4 = (*_ctype_tolower_loc())[(char)*v4];
know_items[v2 + 100] = 0;
guess_items[v2 + 100] = 0LL;
if ( (int)v2 > 0 )
*(_DWORD *)v1 += *(_DWORD *)(v1 - 40);
v0 = maxrings;
++v2;
v1 += 40LL;
}
while ( maxrings > (int)v2 );
}
return func2("rings", (unsigned __int64)&r_magic, v0);
}

original_code:
void
init_stones(void)
{
    int i;
    char *str;
    for (i = 0; i < maxrings; i++)
    {
        do
            str = stones[rnd((sizeof stones / sizeof (char *)))];
        while(!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISupper));
        r_stones[i] = md_strdup(str);
        r_stones[i][0] = (char) tolower( r_stones[i][0] );
        know_items[2][i] = 0;
        guess_items[2][i] = ((void *)0);
        if (i > 0)
            r_magic[i].mi_prob += r_magic[i - 1].mi_prob;
    }
    badcheck("rings", r_magic, maxrings);
}

canonical_original_code:
void init_stones()
{
    int i;
    char *str;
    for (i = 0; i < maxrings; i++)
    {
        do
            str = stones[rnd((sizeof stones / sizeof (char *)))];
        while(!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISupper));
        r_stones[i] = md_strdup(str);
        r_stones[i][0] = (char) tolower( r_stones[i][0] );
        know_items[2][i] = 0;
        guess_items[2][i] = ((void *)0);
        if (i > 0)
            r_magic[i].mi_prob += r_magic[i - 1].mi_prob;
    }
    badcheck("rings", r_magic, maxrings);
}


decompiled_code:
__int64 init_materials()
{
int v0; // edx
unsigned __int64 v1; // r12
__int64 v2; // rbp
char *v3; // rbx
_BYTE *v4; // rbx

v0 = maxsticks;
if ( maxsticks > 0 )
{
v1 = (unsigned int)((_DWORD)ws_magic + 16);
v2 = 0LL;
while ( 1 )
{
if ( (int)rnd(100LL) <= 50 )
{
v3 = wood[(int)rnd(24LL)];
if ( ((*_ctype_b_loc())[*v3] & 0x100) != 0 )
*((_QWORD *)&ws_type + v2) = "staff";
}
else
{
v3 = metal[(int)rnd(23LL)];
if ( ((*_ctype_b_loc())[*v3] & 0x100) != 0 )
*((_QWORD *)&ws_type + v2) = "wand";
}
if ( ((*_ctype_b_loc())[*v3] & 0x100) != 0 )
{
v4 = (_BYTE *)md_strdup(v3);
*((_QWORD *)&ws_made + v2) = v4;
*v4 = (*_ctype_tolower_loc())[(char)*v4];
know_items[v2 + 150] = 0;
guess_items[v2 + 150] = 0LL;
if ( (int)v2 > 0 )
*(_DWORD *)v1 += *(_DWORD *)(v1 - 40);
v0 = maxsticks;
++v2;
v1 += 40LL;
if ( maxsticks <= (int)v2 )
break;
}
}
}
return badcheck("sticks", (unsigned __int64)ws_magic, v0);
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // edx
unsigned __int64 v1; // r12
__int64 v2; // rbp
char *v3; // rbx
_BYTE *v4; // rbx

v0 = maxsticks;
if ( maxsticks > 0 )
{
v1 = (unsigned int)((_DWORD)ws_magic + 16);
v2 = 0LL;
while ( 1 )
{
if ( (int)rnd(100LL) <= 50 )
{
v3 = wood[(int)rnd(24LL)];
if ( ((*_ctype_b_loc())[*v3] & 0x100) != 0 )
*((_QWORD *)&ws_type + v2) = "staff";
}
else
{
v3 = metal[(int)rnd(23LL)];
if ( ((*_ctype_b_loc())[*v3] & 0x100) != 0 )
*((_QWORD *)&ws_type + v2) = "wand";
}
if ( ((*_ctype_b_loc())[*v3] & 0x100) != 0 )
{
v4 = (_BYTE *)md_strdup(v3);
*((_QWORD *)&ws_made + v2) = v4;
*v4 = (*_ctype_tolower_loc())[(char)*v4];
know_items[v2 + 150] = 0;
guess_items[v2 + 150] = 0LL;
if ( (int)v2 > 0 )
*(_DWORD *)v1 += *(_DWORD *)(v1 - 40);
v0 = maxsticks;
++v2;
v1 += 40LL;
if ( maxsticks <= (int)v2 )
break;
}
}
}
return func2("sticks", (unsigned __int64)ws_magic, v0);
}

original_code:
void
init_materials(void)
{
    int i;
    char *str;
    for (i = 0; i < maxsticks; i++)
    {
        do
        {
            if (rnd(100) > 50)
            {
                str = metal[rnd((sizeof metal / sizeof (char *)))];
                if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISupper))
                    ws_type[i] = "wand";
            }
            else
            {
                str = wood[rnd((sizeof wood / sizeof (char *)))];
                if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISupper))
                    ws_type[i] = "staff";
            }
        }
        while(!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISupper));
        ws_made[i] = md_strdup(str);
        ws_made[i][0] = (char) tolower( ws_made[i][0] );
        know_items[3][i] = 0;
        guess_items[3][i] = 0;
        if (i > 0)
            ws_magic[i].mi_prob += ws_magic[i - 1].mi_prob;
    }
    badcheck("sticks", ws_magic, maxsticks);
}

canonical_original_code:
void init_materials()
{
    int i;
    char *str;
    for (i = 0; i < maxsticks; i++)
    {
        do
        {
            if (rnd(100) > 50)
            {
                str = metal[rnd((sizeof metal / sizeof (char *)))];
                if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISupper))
                    ws_type[i] = "wand";
            }
            else
            {
                str = wood[rnd((sizeof wood / sizeof (char *)))];
                if (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISupper))
                    ws_type[i] = "staff";
            }
        }
        while(!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISupper));
        ws_made[i] = md_strdup(str);
        ws_made[i][0] = (char) tolower( ws_made[i][0] );
        know_items[3][i] = 0;
        guess_items[3][i] = 0;
        if (i > 0)
            ws_magic[i].mi_prob += ws_magic[i - 1].mi_prob;
    }
    badcheck("sticks", ws_magic, maxsticks);
}


original_code:
int
get_ident(struct object *obj_p)
{
    int obj_type = obj_p->o_type;
    linked_list *list_p;
    int new_id = 1;
    struct object *tmp_obj_p;
    struct linked_list *new_place_p = ((void *)0);
    if ((obj_p->o_ident) != 0)
        return ((obj_p->o_ident));
    for (list_p = ident_list; list_p != ((void *)0); list_p = ((list_p)?(list_p->l_next):((void *)0)))
    {
        tmp_obj_p = ((*list_p).data.obj);
        if (tmp_obj_p->o_type == obj_type)
        {
            if ((tmp_obj_p->o_ident) == new_id)
            {
                new_place_p = list_p;
                new_id++;
            }
        }
    }
    list_p = new_list();
    _attach_after(&ident_list, new_place_p, list_p);
    (obj_p->o_ident) = new_id;
    list_p->data.obj = obj_p;
    return(new_id);
}

canonical_original_code:
int get_ident(struct object *obj_p)
{
    int obj_type = obj_p->o_type;
    struct linked_list *list_p;
    int new_id = 1;
    struct object *tmp_obj_p;
    struct linked_list *new_place_p = ((void *)0);
    if ((obj_p->o_ident) != 0)
        return ((obj_p->o_ident));
    for (list_p = ident_list; list_p != ((void *)0); list_p = ((list_p)?(list_p->l_next):((void *)0)))
    {
        tmp_obj_p = ((*list_p).data.obj);
        if (tmp_obj_p->o_type == obj_type)
        {
            if ((tmp_obj_p->o_ident) == new_id)
            {
                new_place_p = list_p;
                new_id++;
            }
        }
    }
    list_p = new_list();
    _attach_after(&ident_list, new_place_p, list_p);
    (obj_p->o_ident) = new_id;
    list_p->data.obj = obj_p;
    return(new_id);
}

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: 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

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


decompiled_code:
__int64 __fastcall free_ident(__int64 a1)
{
_QWORD *v1; // rbx
__int64 result; // rax

v1 = (_QWORD *)ident_list;
if ( ident_list )
{
while ( v1[2] != a1 )
{
v1 = (_QWORD *)*v1;
if ( !v1 )
return result;
}
detach(&ident_list, v1);
result = ur_free(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
_QWORD *v1; // rbx
__int64 result; // rax

v1 = (_QWORD *)ident_list;
if ( ident_list )
{
while ( v1[2] != a1 )
{
v1 = (_QWORD *)*v1;
if ( !v1 )
return result;
}
detach(&ident_list, v1);
result = ur_free(v1);
}
return result;
}

original_code:
void
free_ident(struct object *obj_p)
{
    linked_list *list_p;
    for (list_p = ident_list; list_p != ((void *)0); list_p = ((list_p)?(list_p->l_next):((void *)0)))
    {
        if (obj_p == ((*list_p).data.obj))
        {
            _detach(&ident_list, list_p);
            ur_free(list_p);
            break;
        }
    }
}

canonical_original_code:
void free_ident(struct object *obj_p)
{
    struct linked_list *list_p;
    for (list_p = ident_list; list_p != ((void *)0); list_p = ((list_p)?(list_p->l_next):((void *)0)))
    {
        if (obj_p == ((*list_p).data.obj))
        {
            _detach(&ident_list, list_p);
            ur_free(list_p);
            break;
        }
    }
}

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:
signed __int64 __fastcall unprint_id(_BYTE *a1)
{
char *i; // rax

for ( i = print_letters; *i != *a1; ++i )
;
return i - print_letters;
}

canonical_decompiled_code:
signed __int64 __fastcall func2(_BYTE *a1)
{
char *i; // rax

for ( i = print_letters; *i != *a1; ++i )
;
return i - print_letters;
}

original_code:
int
unprint_id(char *print_id)
{
    char *id_p;
    for (id_p = print_letters; id_p != ((void *)0); id_p++)
        if (*id_p == *print_id)
            break;
    return( (int) (id_p - print_letters) );
}


decompiled_code:
__int64 max_print()
{
return 52LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 52LL;
}

original_code:
int
max_print(void)
{
    return(sizeof(print_letters) - 2);
}

canonical_original_code:
int max_print()
{
    return(sizeof(print_letters) - 2);
}


horiz

decompiled_code:
int __fastcall horiz(int a1)
{
int i; // ebx
int result; // eax

for ( i = a1; i; --i )
result = waddch(stdscr, 0x2DuLL);
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int i; // ebx
int result; // eax

for ( i = a1; i; --i )
result = waddch(stdscr, 0x2DuLL);
return result;
}

original_code:
void
horiz(int cnt)
{
    while(cnt--)
        waddch(stdscr,('-'));
}

variable_types: cnt int


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

result = 0LL;
if ( !levtype )
{
do
result = rnd(9LL);
while ( (rooms[60 * (int)result + 48] & 2) != 0 );
}
return result;
}

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

result = 0LL;
if ( !levtype )
{
do
result = rnd(9LL);
while ( (rooms[60 * (int)result + 48] & 2) != 0 );
}
return result;
}

original_code:
int
rnd_room(void)
{
    int rm;
    if (levtype != NORMLEV)
        rm = 0;
    else
        do
        {
            rm = rnd(9);
        }
        while (rooms[rm].r_flags & 0x00000002UL);
    return(rm);
}

canonical_original_code:
int rnd_room()
{
    int rm;
    if (levtype != NORMLEV)
        rm = 0;
    else
        do
        {
            rm = rnd(9);
        }
        while (rooms[rm].r_flags & 0x00000002UL);
    return(rm);
}

variable_types: rm int


original_code:
void
do_rooms(void)
{
    int i;
    struct room *rp;
    struct linked_list *item;
    struct thing *tp;
    int left_out;
    coord top;
    coord bsze;
    coord mp;
    bsze.x = COLS / 3;
    bsze.y = (LINES - 2) / 3;
    for (rp = rooms; rp < &rooms[9]; rp++)
        rp->r_nexits = rp->r_flags = rp->r_fires = 0;
    left_out = rnd(3);
    for (i = 0; i < left_out; i++)
        rooms[rnd_room()].r_flags |= 0x00000002UL;
    for (i = 0, rp = rooms; i < 9; rp++, i++)
    {
        int has_gold = 0;
        top.x = (i % 3) * bsze.x;
        top.y = i / 3 * bsze.y + 1;
        if (rp->r_flags & 0x00000002UL)
        {
            do
            {
                rp->r_pos.x = top.x + rnd(bsze.x - 2) + 1;
                rp->r_pos.y = top.y + rnd(bsze.y - 2) + 1;
                rp->r_max.x = -COLS;
                rp->r_max.x = -LINES;
            }
            while (rp->r_pos.y < 1 || rp->r_pos.y > LINES - 3);
            continue;
        }
        if (rnd(40) < level - 5)
            rp->r_flags |= 0x00000001UL;
        do
        {
            rp->r_max.x = rnd(bsze.x - 4) + 4;
            rp->r_max.y = rnd(bsze.y - 4) + 4;
            rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x);
            rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y);
        }
        while (rp->r_pos.y == 0);
        draw_room(rp);
        if (rnd(10) < 3 && (!has_artifact || level >= max_level))
        {
            struct linked_list *itm;
            struct object *cur;
            coord tpos;
            has_gold = 1;
            itm = spec_item('*', 0, 0, 0);
            cur = ((*itm).data.obj);
            rnd_pos(rp, &tpos);
            cur->o_pos = tpos;
            add_obj(itm, tpos.y, tpos.x);
            if (roomin(tpos) != rp)
            {
                endwin();
                abort();
            }
        }
        if (rnd(100) < (has_gold ? 80 : 40))
        {
            int which;
            int n, cnt;
            item = new_item(sizeof *tp);
            tp = ((*item).data.th);
            do
                rnd_pos(rp, &mp);
            while ((wmove((stdscr),(mp.y),(mp.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) != '.');
            which = randmonster(0, 0);
            new_monster(item, which, &mp, 0);
            if (rnd(100) < monsters[tp->t_index].m_carry)
                _attach(&tp->t_pack, new_thing());
            if (((*tp).t_flags[(0x00002000UL >> 28UL) & 0x0000000fL] & (0x00002000UL & 0x0fffffffL)))
            {
                rp->r_flags |= 0x00002000UL;
                rp->r_fires++;
            }
            if (((*tp).t_flags[(0x10001000UL >> 28UL) & 0x0000000fL] & (0x10001000UL & 0x0fffffffL)))
            {
                struct object *cur;
                item = spec_item('*', 0, 0, 0);
                cur = ((*item).data.obj);
                cur->o_count = (rnd(50 + 30 * level) + 2) + (rnd(50 + 30 * level) + 2) + (rnd(50 + 30 * level) + 2);
                cur->o_pos = tp->t_pos;
                _attach(&tp->t_pack, item);
            }
            n = rnd(7);
            if (((*tp).t_flags[(0x40010000UL >> 28UL) & 0x0000000fL] & (0x40010000UL & 0x0fffffffL)) && n < 5)
                cnt = roll(2, 4);
            else if (((*tp).t_flags[(0x40008000UL >> 28UL) & 0x0000000fL] & (0x40008000UL & 0x0fffffffL)) && n < 5)
                cnt = roll(1, 4);
            else
                cnt = 0;
            for (n = 1; n <= cnt; n++)
            {
                coord pos;
                if (place_mons(mp.y, mp.x, &pos)!= 0)
                {
                    struct linked_list *nitem;
                    nitem = new_item(sizeof(struct thing));
                    new_monster(nitem, which, &pos, 0);
                    if (isatrap((wmove((stdscr),((pos.y)),((pos.x))) == (-1) ? (chtype)((-1)) : winch(stdscr))))
                        be_trapped(((*nitem).data.th), mp);
                    if (((*tp).t_flags[(0x10800000UL >> 28UL) & 0x0000000fL] & (0x10800000UL & 0x0fffffffL)))
                        ( (*(((*nitem).data.th))).t_flags[(0x10800000UL >> 28UL) & 0x0000000fL] |= (0x10800000UL & 0x0fffffffL));
                    else
                        ( (*(((*nitem).data.th))).t_flags[(0x10800000UL >> 28UL) & 0x0000000fL] &= ~(0x10800000UL & 0x0fffffffL));
                }
            }
            if (cnt > 0)
            {
                int boost = rnd(3) + 1;
                if (((*tp).t_flags[(0x50000200UL >> 28UL) & 0x0000000fL] & (0x50000200UL & 0x0fffffffL)) || ((*tp).t_flags[(0x50000400UL >> 28UL) & 0x0000000fL] & (0x50000400UL & 0x0fffffffL)) || ((*tp).t_flags[(0x50000800UL >> 28UL) & 0x0000000fL] & (0x50000800UL & 0x0fffffffL)))
                    ( (*tp).t_flags[(0x38000000UL >> 28UL) & 0x0000000fL] |= (0x38000000UL & 0x0fffffffL));
                tp->t_stats.s_hpt += 3 * boost;
                tp->t_stats.s_arm -= 2 * boost;
                tp->t_stats.s_lvl += 2 * boost;
                tp->t_stats.s_str += 2 * boost;
                tp->t_stats.s_intel += 2 * boost;
                tp->t_stats.s_exp += 4 * boost * monsters[which].m_add_exp;
            }
        }
    }
}

canonical_original_code:
void do_rooms()
{
    int i;
    struct room *rp;
    struct linked_list *item;
    struct thing *tp;
    int left_out;
    struct coord top;
    struct coord bsze;
    struct coord mp;
    bsze.x = COLS / 3;
    bsze.y = (LINES - 2) / 3;
    for (rp = rooms; rp < &rooms[9]; rp++)
        rp->r_nexits = rp->r_flags = rp->r_fires = 0;
    left_out = rnd(3);
    for (i = 0; i < left_out; i++)
        rooms[rnd_room()].r_flags |= 0x00000002UL;
    for (i = 0, rp = rooms; i < 9; rp++, i++)
    {
        int has_gold = 0;
        top.x = (i % 3) * bsze.x;
        top.y = i / 3 * bsze.y + 1;
        if (rp->r_flags & 0x00000002UL)
        {
            do
            {
                rp->r_pos.x = top.x + rnd(bsze.x - 2) + 1;
                rp->r_pos.y = top.y + rnd(bsze.y - 2) + 1;
                rp->r_max.x = -COLS;
                rp->r_max.x = -LINES;
            }
            while (rp->r_pos.y < 1 || rp->r_pos.y > LINES - 3);
            continue;
        }
        if (rnd(40) < level - 5)
            rp->r_flags |= 0x00000001UL;
        do
        {
            rp->r_max.x = rnd(bsze.x - 4) + 4;
            rp->r_max.y = rnd(bsze.y - 4) + 4;
            rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x);
            rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y);
        }
        while (rp->r_pos.y == 0);
        draw_room(rp);
        if (rnd(10) < 3 && (!has_artifact || level >= max_level))
        {
            struct linked_list *itm;
            struct object *cur;
            struct coord tpos;
            has_gold = 1;
            itm = spec_item('*', 0, 0, 0);
            cur = ((*itm).data.obj);
            rnd_pos(rp, &tpos);
            cur->o_pos = tpos;
            add_obj(itm, tpos.y, tpos.x);
            if (roomin(tpos) != rp)
            {
                endwin();
                abort();
            }
        }
        if (rnd(100) < (has_gold ? 80 : 40))
        {
            int which;
            int n; int cnt;
            item = new_item(sizeof *tp);
            tp = ((*item).data.th);
            do
                rnd_pos(rp, &mp);
            while ((wmove((stdscr),(mp.y),(mp.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) != '.');
            which = randmonster(0, 0);
            new_monster(item, which, &mp, 0);
            if (rnd(100) < monsters[tp->t_index].m_carry)
                _attach(&tp->t_pack, new_thing());
            if (((*tp).t_flags[(0x00002000UL >> 28UL) & 0x0000000fL] & (0x00002000UL & 0x0fffffffL)))
            {
                rp->r_flags |= 0x00002000UL;
                rp->r_fires++;
            }
            if (((*tp).t_flags[(0x10001000UL >> 28UL) & 0x0000000fL] & (0x10001000UL & 0x0fffffffL)))
            {
                struct object *cur;
                item = spec_item('*', 0, 0, 0);
                cur = ((*item).data.obj);
                cur->o_count = (rnd(50 + 30 * level) + 2) + (rnd(50 + 30 * level) + 2) + (rnd(50 + 30 * level) + 2);
                cur->o_pos = tp->t_pos;
                _attach(&tp->t_pack, item);
            }
            n = rnd(7);
            if (((*tp).t_flags[(0x40010000UL >> 28UL) & 0x0000000fL] & (0x40010000UL & 0x0fffffffL)) && n < 5)
                cnt = roll(2, 4);
            else if (((*tp).t_flags[(0x40008000UL >> 28UL) & 0x0000000fL] & (0x40008000UL & 0x0fffffffL)) && n < 5)
                cnt = roll(1, 4);
            else
                cnt = 0;
            for (n = 1; n <= cnt; n++)
            {
                struct coord pos;
                if (place_mons(mp.y, mp.x, &pos)!= 0)
                {
                    struct linked_list *nitem;
                    nitem = new_item(sizeof(struct thing));
                    new_monster(nitem, which, &pos, 0);
                    if (isatrap((wmove((stdscr),((pos.y)),((pos.x))) == (-1) ? (chtype)((-1)) : winch(stdscr))))
                        be_trapped(((*nitem).data.th), mp);
                    if (((*tp).t_flags[(0x10800000UL >> 28UL) & 0x0000000fL] & (0x10800000UL & 0x0fffffffL)))
                        ( (*(((*nitem).data.th))).t_flags[(0x10800000UL >> 28UL) & 0x0000000fL] |= (0x10800000UL & 0x0fffffffL));
                    else
                        ( (*(((*nitem).data.th))).t_flags[(0x10800000UL >> 28UL) & 0x0000000fL] &= ~(0x10800000UL & 0x0fffffffL));
                }
            }
            if (cnt > 0)
            {
                int boost = rnd(3) + 1;
                if (((*tp).t_flags[(0x50000200UL >> 28UL) & 0x0000000fL] & (0x50000200UL & 0x0fffffffL)) || ((*tp).t_flags[(0x50000400UL >> 28UL) & 0x0000000fL] & (0x50000400UL & 0x0fffffffL)) || ((*tp).t_flags[(0x50000800UL >> 28UL) & 0x0000000fL] & (0x50000800UL & 0x0fffffffL)))
                    ( (*tp).t_flags[(0x38000000UL >> 28UL) & 0x0000000fL] |= (0x38000000UL & 0x0fffffffL));
                tp->t_stats.s_hpt += 3 * boost;
                tp->t_stats.s_arm -= 2 * boost;
                tp->t_stats.s_lvl += 2 * boost;
                tp->t_stats.s_str += 2 * boost;
                tp->t_stats.s_intel += 2 * boost;
                tp->t_stats.s_exp += 4 * boost * monsters[which].m_add_exp;
            }
        }
    }
}

variable_types: struct room { struct coord { int x; int y; } r_pos; struct coord r_max; struct coord r_exit[4]; int r_flags; int r_nexits; short r_fires; } *

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

variable_types:
top
struct coord { int x; int y; }

variable_types:
bsze
struct coord { int x; int y; }

variable_types:
mp
struct coord { int x; int y; }

variable_types:
tpos
struct coord { int x; int y; }

variable_types: which int

variable_types: n int

variable_types:
pos
struct coord { int x; int y; }

variable_types: boost int

user_defined_types: struct room { struct coord r_pos; struct coord r_max; struct coord r_exit[4]; int r_flags; int r_nexits; short r_fires; }


decompiled_code:
__int64 __fastcall ur_srandom(unsigned int a1)
{
return md_srandom(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return md_srandom(a1);
}

original_code:
void
ur_srandom(unsigned x)
{
    md_srandom(x);
}

canonical_original_code:
void ur_srandom(unsigned int x)
{
    md_srandom(x);
}

variable_types:
x
unsigned int


decompiled_code:
__int64 ur_random()
{
return md_random();
}

canonical_decompiled_code:
__int64 func1()
{
return md_random();
}

original_code:
long
ur_random(void)
{
    return( md_random() );
}

canonical_original_code:
long ur_random()
{
    return( md_random() );
}

return_type: long


original_code:
void
init_weapon(struct object *weap, int type)
{
    struct init_weps *iwp = &weaps[type];
    weap->o_damage = iwp->w_dam;
    weap->o_hurldmg = iwp->w_hrl;
    weap->o_launch = iwp->w_launch;
    weap->o_flags = iwp->w_flags;
    weap->o_weight = iwp->w_wght;
    if (weap->o_flags & 0x00004000UL)
    {
        weap->o_count = rnd(8) + 8;
        weap->o_group = ++group;
    }
    else
        weap->o_count = 1;
}

variable_types: type int

variable_types: struct init_weps { char *w_name; char *w_dam; char *w_hrl; char w_launch; int w_wght; long w_worth; long w_flags; } *


decompiled_code:
__int64 __fastcall hit_monster(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v6; // rsi
__int64 result; // rax
int v8[8]; // [rsp+8h] [rbp-20h] BYREF

v8[1] = a1;
v8[0] = a2;
if ( (_DWORD *)a4 == player )
return fight(v8, a3, 1LL);
if ( player[48] == a2 && player[49] == a1 )
{
if ( (*(_QWORD *)(a4 + 224) & 0x900000LL) != 0 )
{
if ( (*(_BYTE *)(a4 + 251) & 2) == 0 )
{
msg("Get out of the way %s!", (const char *)&whoami);
return 0LL;
}
}
else if ( (*(_BYTE *)(a4 + 251) & 2) == 0 )
{
return attack(a4, a3, 1LL);
}
msg("Please get out of the way, Master! I nearly hit you.");
return 0LL;
}
v6 = find_mons();
result = 0LL;
if ( v6 )
result = mon_mon_attack(a4, v6, a3, 1LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v6; // rsi
__int64 result; // rax
int v8[8]; // [rsp+8h] [rbp-20h] BYREF

v8[1] = a1;
v8[0] = a2;
if ( (_DWORD *)a4 == player )
return fight(v8, a3, 1LL);
if ( player[48] == a2 && player[49] == a1 )
{
if ( (*(_QWORD *)(a4 + 224) & 0x900000LL) != 0 )
{
if ( (*(_BYTE *)(a4 + 251) & 2) == 0 )
{
msg("Get out of the way %s!", (const char *)&whoami);
return 0LL;
}
}
else if ( (*(_BYTE *)(a4 + 251) & 2) == 0 )
{
return attack(a4, a3, 1LL);
}
msg("Please get out of the way, Master! I nearly hit you.");
return 0LL;
}
v6 = find_mons();
result = 0LL;
if ( v6 )
result = mon_mon_attack(a4, v6, a3, 1LL);
return result;
}

original_code:
int
hit_monster(int y, int x, struct object *weapon, struct thing *thrower)
{
    struct linked_list *mon;
    coord target;
    target.y = y;
    target.x = x;
    if (thrower == &player)
        return(fight(&target, weapon, 1));
    if (((target).x == (player.t_pos).x && (target).y == (player.t_pos).y))
    {
        if ((((*thrower).t_flags[(0x10100000UL >> 28UL) & 0x0000000fL] & (0x10100000UL & 0x0fffffffL)) || ((*thrower).t_flags[(0x10800000UL >> 28UL) & 0x0000000fL] & (0x10800000UL & 0x0fffffffL)) || ((*thrower).t_flags[(0x42000000UL >> 28UL) & 0x0000000fL] & (0x42000000UL & 0x0fffffffL))))
        {
            if (((*thrower).t_flags[(0x42000000UL >> 28UL) & 0x0000000fL] & (0x42000000UL & 0x0fffffffL)))
                msg("Please get out of the way, Master!  I nearly hit you.");
            else
                msg("Get out of the way %s!", whoami);
            return(0);
        }
        return(attack(thrower, weapon, 1));
    }
    if ((mon = find_mons(y, x)) != ((void *)0))
        return(mon_mon_attack(thrower, mon, weapon, 1));
    else
        return(0);
}

canonical_original_code:
int hit_monster(int y, int x, struct object *weapon, struct thing *thrower)
{
    struct linked_list *mon;
    struct coord target;
    target.y = y;
    target.x = x;
    if (thrower == &player)
        return(fight(&target, weapon, 1));
    if (((target).x == (player.t_pos).x && (target).y == (player.t_pos).y))
    {
        if ((((*thrower).t_flags[(0x10100000UL >> 28UL) & 0x0000000fL] & (0x10100000UL & 0x0fffffffL)) || ((*thrower).t_flags[(0x10800000UL >> 28UL) & 0x0000000fL] & (0x10800000UL & 0x0fffffffL)) || ((*thrower).t_flags[(0x42000000UL >> 28UL) & 0x0000000fL] & (0x42000000UL & 0x0fffffffL))))
        {
            if (((*thrower).t_flags[(0x42000000UL >> 28UL) & 0x0000000fL] & (0x42000000UL & 0x0fffffffL)))
                msg("Please get out of the way, Master!  I nearly hit you.");
            else
                msg("Get out of the way %s!", whoami);
            return(0);
        }
        return(attack(thrower, weapon, 1));
    }
    if ((mon = find_mons(y, x)) != ((void *)0))
        return(mon_mon_attack(thrower, mon, weapon, 1));
    else
        return(0);
}

variable_types: y int

variable_types: x int

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:
thrower
struct thing *

variable_types:
target
struct coord { int x; int y; }


num

decompiled_code:
const char *__fastcall num(int a1, int a2, char *a3)
{
const char *v4; // rdx
const char *result; // rax
const char *v6; // r8
const char *v7; // rdx

if ( !a3 )
return "UltraRogue Error #104";
if ( a2 | a1 )
{
if ( a2 )
{
v6 = (const char *)&unk_E24;
if ( a2 >= 0 )
v6 = "+";
v7 = (const char *)&unk_E24;
if ( a1 >= 0 )
v7 = "+";
sprintf(a3, "%s%d, %s%d", v7, (unsigned int)a1, v6, (unsigned int)a2);
result = a3;
}
else
{
v4 = (const char *)&unk_E24;
if ( a1 >= 0 )
v4 = "+";
sprintf(a3, "%s%d", v4, (unsigned int)a1);
result = a3;
}
}
else
{
strcpy(a3, "+0");
result = a3;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(int a1, int a2, char *a3)
{
const char *v4; // rdx
const char *result; // rax
const char *v6; // r8
const char *v7; // rdx

if ( !a3 )
return "UltraRogue Error #104";
if ( a2 | a1 )
{
if ( a2 )
{
v6 = (const char *)&unk_E24;
if ( a2 >= 0 )
v6 = "+";
v7 = (const char *)&unk_E24;
if ( a1 >= 0 )
v7 = "+";
sprintf(a3, "%s%d, %s%d", v7, (unsigned int)a1, v6, (unsigned int)a2);
result = a3;
}
else
{
v4 = (const char *)&unk_E24;
if ( a1 >= 0 )
v4 = "+";
sprintf(a3, "%s%d", v4, (unsigned int)a1);
result = a3;
}
}
else
{
strcpy(a3, "+0");
result = a3;
}
return result;
}

original_code:
char *
num(int n1, int n2, char *buf)
{
    if (buf == ((void *)0))
        return("UltraRogue Error #104");
    if (n1 == 0 && n2 == 0)
    {
        strcpy(buf,"+0");
        return(buf);
    }
    if (n2 == 0)
        sprintf(buf, "%s%d", n1 < 0 ? "" : "+", n1);
    else
        sprintf(buf, "%s%d, %s%d", n1 < 0 ? "" : "+",
            n1, n2 < 0 ? "" : "+", n2);
    return(buf);
}

canonical_original_code:
char *num(int n1, int n2, char *buf)
{
    if (buf == ((void *)0))
        return("UltraRogue Error #104");
    if (n1 == 0 && n2 == 0)
    {
        strcpy(buf,"+0");
        return(buf);
    }
    if (n2 == 0)
        sprintf(buf, "%s%d", n1 < 0 ? "" : "+", n1);
    else
        sprintf(buf, "%s%d, %s%d", n1 < 0 ? "" : "+",
            n1, n2 < 0 ? "" : "+", n2);
    return(buf);
}

variable_types:
buf
char *

return_type: char *


fallpos

decompiled_code:
__int64 __fastcall fallpos(__int64 a1, _DWORD *a2)
{
int v2; // ebp
int v3; // er13
int i; // ebx
int v6; // eax
__int64 v7; // rsi
__int64 v8; // rdx
int v10[34]; // [rsp+10h] [rbp-88h]

v2 = HIDWORD(a1) - 1;
v3 = 0;
while ( 1 )
{
for ( i = a1 - 1; ; ++i )
{
if ( wmove(stdscr, v2, i) != -1 )
{
switch ( (unsigned __int8)winch(stdscr) )
{
case '!':
case '#':
case ')':
case '*':
case ',':
case '.':
case '/':
case ':':
case '=':
case '?':
case ']':
v10[2 * v3 + 1] = v2;
v10[2 * v3++] = i;
break;
default:
break;
}
}
if ( (int)a1 < i )
break;
}
if ( SHIDWORD(a1) < v2 )
break;
++v2;
}
if ( v3 > 0 )
{
v6 = rnd((unsigned int)v3);
v7 = (unsigned int)v10[2 * v6 + 1];
a2[1] = v7;
v8 = (unsigned int)v10[2 * v6];
*a2 = v8;
if ( wizard )
{
if ( wiz_verbose )
msg("Dropping object at %d, %d", v7, v8);
}
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2)
{
int v2; // ebp
int v3; // er13
int i; // ebx
int v6; // eax
__int64 v7; // rsi
__int64 v8; // rdx
int v10[34]; // [rsp+10h] [rbp-88h]

v2 = HIDWORD(a1) - 1;
v3 = 0;
while ( 1 )
{
for ( i = a1 - 1; ; ++i )
{
if ( wmove(stdscr, v2, i) != -1 )
{
switch ( (unsigned __int8)winch(stdscr) )
{
case '!':
case '#':
case ')':
case '*':
case ',':
case '.':
case '/':
case ':':
case '=':
case '?':
case ']':
v10[2 * v3 + 1] = v2;
v10[2 * v3++] = i;
break;
default:
break;
}
}
if ( (int)a1 < i )
break;
}
if ( SHIDWORD(a1) < v2 )
break;
++v2;
}
if ( v3 > 0 )
{
v6 = rnd((unsigned int)v3);
v7 = (unsigned int)v10[2 * v6 + 1];
a2[1] = v7;
v8 = (unsigned int)v10[2 * v6];
*a2 = v8;
if ( wizard )
{
if ( wiz_verbose )
msg("Dropping object at %d, %d", v7, v8);
}
}
return (unsigned int)v3;
}

original_code:
int
fallpos(coord pos, coord *newpos)
{
    int y, x, cnt;
 coord places[9];
    cnt = 0;
    for (y = pos.y - 1; y <= pos.y + 1; y++)
 {
        for (x = pos.x - 1; x <= pos.x + 1; x++)
        {
            switch(( (char) ((wmove((stdscr),(y),(x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) & (((chtype)((1U)) << ((0) + 8)) - 1U)) ))
            {
                case '*':
                case '!':
                case '?':
                case ':':
                case ')':
                case ']':
                case '=':
                case '/':
                case '.':
                case '#':
                case ',':
                    places[cnt].y = y;
                    places[cnt].x = x;
                    cnt++;
            }
        }
    }
    if (cnt > 0)
 {
        int which = rnd(cnt);
        newpos->y = places[which].y;
        newpos->x = places[which].x;
        if (wizard && wiz_verbose) msg("Dropping object at %d, %d", newpos->y, newpos->x);
    }
    return(cnt);
}

canonical_original_code:
int fallpos(struct coord pos, struct coord *newpos)
{
    int y; int x; int cnt;
 struct coord places[9];
    cnt = 0;
    for (y = pos.y - 1; y <= pos.y + 1; y++)
 {
        for (x = pos.x - 1; x <= pos.x + 1; x++)
        {
            switch(( (char) ((wmove((stdscr),(y),(x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) & (((chtype)((1U)) << ((0) + 8)) - 1U)) ))
            {
                case '*':
                case '!':
                case '?':
                case ':':
                case ')':
                case ']':
                case '=':
                case '/':
                case '.':
                case '#':
                case ',':
                    places[cnt].y = y;
                    places[cnt].x = x;
                    cnt++;
            }
        }
    }
    if (cnt > 0)
 {
        int which = rnd(cnt);
        newpos->y = places[which].y;
        newpos->x = places[which].x;
        if (wizard && wiz_verbose) msg("Dropping object at %d, %d", newpos->y, newpos->x);
    }
    return(cnt);
}

variable_types:
newpos
struct coord *

variable_types: cnt int

variable_types:
places
struct coord { int x; int y; } [9]


fall

decompiled_code:
int __fastcall fall(__int64 a1, __int64 a2, int a3, int a4)
{
unsigned int *v6; // rbp
__int64 v7; // r14
int result; // eax
const char *v9; // rax
int v10; // ecx
__int64 v11; // rsi
const char *v12; // rax
int v13[2]; // [rsp+8h] [rbp-30h] BYREF

v6 = *(unsigned int **)(a2 + 16);
v7 = roomin(*(_QWORD *)(a1 + 192));
if ( a4 && (*((_BYTE *)v6 + 49) & 4) != 0 )
{
add_pack(a2, 0LL);
v9 = (const char *)inv_name(v6, 1LL);
return msg("You have %s.", v9);
}
if ( !(unsigned int)fallpos(*(_QWORD *)v6, v13) )
{
if ( a3 && (unsigned int)((__int64 (__fastcall *)(_QWORD, _QWORD))cansee)(v6[1], *v6) )
{
if ( *((_BYTE *)v6 + 64) == 41 )
{
addmsg("The %s", *((const char **)&weaps + 6 * (int)v6[19]));
}
else
{
v12 = (const char *)inv_name(v6, 1LL);
addmsg(v12);
}
msg(" vanishes as it hits the ground.");
}
return discard(a2);
}
if ( *((char *)v6 + 49) >= 0 || *((_BYTE *)v6 + 64) != 41 || v6[19] != 23 || ntraps > 158 )
{
*(_QWORD *)v6 = *(_QWORD *)v13;
result = add_obj(a2, (unsigned int)v13[1], (unsigned int)v13[0]);
if ( !v7 )
return result;
goto LABEL_11;
}
if ( wmove(stdscr, v13[1], v13[0]) != -1 )
waddch(stdscr, 0x3CuLL);
v10 = ntraps;
result = 2 * ntraps;
v11 = 3LL * ntraps;
*((_BYTE *)&traps + 8 * v11 + 16) = 60;
*((_QWORD *)&traps + v11 + 1) = 8LL;
*((_BYTE *)&traps + 8 * v11 + 17) = 60;
*((_QWORD *)&traps + v11) = *(_QWORD *)v13;
ntraps = v10 + 1;
if ( v7 )
{
*(_DWORD *)(v7 + 48) &= 0xFFFFFFFE;
LABEL_11:
result = *(_DWORD *)(v7 + 48) & 0x2001;
if ( result != 1 )
{
light((unsigned int)((_DWORD)player + 192));
result = wmove(cw, player[49], player[48]);
if ( result != -1 )
result = waddch(cw, (unsigned int)PLAYER);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, int a3, int a4)
{
unsigned int *v6; // rbp
__int64 v7; // r14
int result; // eax
const char *v9; // rax
int v10; // ecx
__int64 v11; // rsi
const char *v12; // rax
int v13[2]; // [rsp+8h] [rbp-30h] BYREF

v6 = *(unsigned int **)(a2 + 16);
v7 = roomin(*(_QWORD *)(a1 + 192));
if ( a4 && (*((_BYTE *)v6 + 49) & 4) != 0 )
{
add_pack(a2, 0LL);
v9 = (const char *)inv_name(v6, 1LL);
return msg("You have %s.", v9);
}
if ( !(unsigned int)func3(*(_QWORD *)v6, v13) )
{
if ( a3 && (unsigned int)((__int64 (__fastcall *)(_QWORD, _QWORD))cansee)(v6[1], *v6) )
{
if ( *((_BYTE *)v6 + 64) == 41 )
{
addmsg("The %s", *((const char **)&weaps + 6 * (int)v6[19]));
}
else
{
v12 = (const char *)inv_name(v6, 1LL);
addmsg(v12);
}
msg(" vanishes as it hits the ground.");
}
return discard(a2);
}
if ( *((char *)v6 + 49) >= 0 || *((_BYTE *)v6 + 64) != 41 || v6[19] != 23 || ntraps > 158 )
{
*(_QWORD *)v6 = *(_QWORD *)v13;
result = add_obj(a2, (unsigned int)v13[1], (unsigned int)v13[0]);
if ( !v7 )
return result;
goto LABEL_11;
}
if ( wmove(stdscr, v13[1], v13[0]) != -1 )
waddch(stdscr, 0x3CuLL);
v10 = ntraps;
result = 2 * ntraps;
v11 = 3LL * ntraps;
*((_BYTE *)&traps + 8 * v11 + 16) = 60;
*((_QWORD *)&traps + v11 + 1) = 8LL;
*((_BYTE *)&traps + 8 * v11 + 17) = 60;
*((_QWORD *)&traps + v11) = *(_QWORD *)v13;
ntraps = v10 + 1;
if ( v7 )
{
*(_DWORD *)(v7 + 48) &= 0xFFFFFFFE;
LABEL_11:
result = *(_DWORD *)(v7 + 48) & 0x2001;
if ( result != 1 )
{
light((unsigned int)((_DWORD)player + 192));
result = wmove(cw, player[49], player[48]);
if ( result != -1 )
result = waddch(cw, (unsigned int)PLAYER);
}
}
return result;
}

original_code:
void
fall(struct thing *tp, struct linked_list *item, int pr, int player_owned)
{
    struct object *obj;
    struct room *rp;
    coord fpos;
    obj = ((*item).data.obj);
    rp = roomin(tp->t_pos);
    if (player_owned && obj->o_flags & 0x00000400UL)
    {
        add_pack(item, 0);
        msg("You have %s.", inv_name(obj, 1));
        return;
    }
    else if (fallpos(obj->o_pos, &fpos))
    {
        if (obj->o_flags & 0x00008000UL && obj->o_type == ')'
            && obj->o_which == 23
            && ntraps + 1 < 2 * 80)
        {
            (wmove((stdscr),((fpos.y)),((fpos.x))) == (-1) ? (-1) : waddch((stdscr),(('<'))));
            traps[ntraps].tr_type = '<';
            traps[ntraps].tr_flags = 0x00000008UL;
            traps[ntraps].tr_show = '<';
            traps[ntraps].tr_pos = fpos;
            ntraps++;
            if (rp != ((void *)0))
                rp->r_flags &= ~0x00000001UL;
        }
        else
        {
            obj->o_pos = fpos;
            add_obj(item, fpos.y, fpos.x);
        }
        if (rp != ((void *)0) &&
            (!(rp->r_flags & 0x00000001UL) ||
             (rp->r_flags & 0x00002000UL)))
        {
            light(&player.t_pos);
            (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
        }
        return;
    }
    if (pr)
    {
        if (cansee(obj->o_pos.y, obj->o_pos.x))
        {
            if (obj->o_type == ')')
                addmsg("The %s", weaps[obj->o_which].w_name);
            else
                addmsg(inv_name(obj, 1));
            msg(" vanishes as it hits the ground.");
        }
    }
    discard(item);
}

canonical_original_code:
void fall(struct thing *tp, struct linked_list *item, int pr, int player_owned)
{
    struct object *obj;
    struct room *rp;
    struct coord fpos;
    obj = ((*item).data.obj);
    rp = roomin(tp->t_pos);
    if (player_owned && obj->o_flags & 0x00000400UL)
    {
        add_pack(item, 0);
        msg("You have %s.", inv_name(obj, 1));
        return;
    }
    else if (fallpos(obj->o_pos, &fpos))
    {
        if (obj->o_flags & 0x00008000UL && obj->o_type == ')'
            && obj->o_which == 23
            && ntraps + 1 < 2 * 80)
        {
            (wmove((stdscr),((fpos.y)),((fpos.x))) == (-1) ? (-1) : waddch((stdscr),(('<'))));
            traps[ntraps].tr_type = '<';
            traps[ntraps].tr_flags = 0x00000008UL;
            traps[ntraps].tr_show = '<';
            traps[ntraps].tr_pos = fpos;
            ntraps++;
            if (rp != ((void *)0))
                rp->r_flags &= ~0x00000001UL;
        }
        else
        {
            obj->o_pos = fpos;
            add_obj(item, fpos.y, fpos.x);
        }
        if (rp != ((void *)0) &&
            (!(rp->r_flags & 0x00000001UL) ||
             (rp->r_flags & 0x00002000UL)))
        {
            light(&player.t_pos);
            (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
        }
        return;
    }
    if (pr)
    {
        if (cansee(obj->o_pos.y, obj->o_pos.x))
        {
            if (obj->o_type == ')')
                addmsg("The %s", weaps[obj->o_which].w_name);
            else
                addmsg(inv_name(obj, 1));
            msg(" vanishes as it hits the ground.");
        }
    }
    discard(item);
}

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

variable_types:
item
struct linked_list *

variable_types: pr int

variable_types: struct room { struct coord { int x; int y; } r_pos; struct coord r_max; struct coord r_exit[4]; int r_flags; int r_nexits; short r_fires; } *

variable_types:
fpos
struct coord { int x; int y; }


decompiled_code:
__int64 __fastcall wield_ok(_DWORD *a1, __int64 a2, int a3)
{
unsigned int v3; // ebx
int v5; // er14

v3 = 0;
if ( *(_BYTE *)(a2 + 64) == 41 )
{
v5 = a1[90];
switch ( v5 )
{
case 0:
case 2:
case 10:
v3 = 1;
goto LABEL_14;
case 1:
v3 = *(_WORD *)(a2 + 50) & 1;
goto LABEL_14;
case 3:
v3 = ((unsigned __int8)BYTE2(*(_QWORD *)(a2 + 48)) ^ 1) & 1;
goto LABEL_14;
case 4:
v3 = (*(_QWORD *)(a2 + 48) & 0x108LL) != 8;
goto LABEL_14;
case 5:
case 6:
v3 = ((unsigned __int8)(*(_QWORD *)(a2 + 48) >> 17) ^ 1) & 1;
goto LABEL_14;
case 7:
case 8:
case 9:
v3 = ((unsigned __int8)(*(_QWORD *)(a2 + 48) >> 17) ^ 1) & 1;
LABEL_14:
if ( (int)itemweight(a2) > 18 * player[18] )
goto LABEL_22;
if ( !v3 && a3 == 1 )
{
if ( v5 > 6 )
{
v3 = 0;
if ( (unsigned int)(v5 - 7) <= 2 )
{
msg("Don't expect to backstab anyone while wielding that!");
v3 = 0;
}
}
else if ( v5 > 4 )
{
msg("You'll find it hard to cast spells while wielding that!");
v3 = 0;
}
else if ( v5 == 1 || (unsigned int)(v5 - 3) <= 1 )
{
msg("Your god strongly disapproves of your wielding that!");
v3 = 0;
}
}
break;
default:
if ( wizard && wiz_verbose )
msg("Unknown class %d.", (unsigned int)v5);
if ( (int)itemweight(a2) > 18 * player[18] )
{
LABEL_22:
if ( a3 == 1 && a1 == player )
{
msg("That is too heavy for you to swing effectively!");
v3 = 0;
}
else
{
v3 = 0;
}
}
else
{
v3 = 1;
}
break;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, __int64 a2, int a3)
{
unsigned int v3; // ebx
int v5; // er14

v3 = 0;
if ( *(_BYTE *)(a2 + 64) == 41 )
{
v5 = a1[90];
switch ( v5 )
{
case 0:
case 2:
case 10:
v3 = 1;
goto LABEL_14;
case 1:
v3 = *(_WORD *)(a2 + 50) & 1;
goto LABEL_14;
case 3:
v3 = ((unsigned __int8)BYTE2(*(_QWORD *)(a2 + 48)) ^ 1) & 1;
goto LABEL_14;
case 4:
v3 = (*(_QWORD *)(a2 + 48) & 0x108LL) != 8;
goto LABEL_14;
case 5:
case 6:
v3 = ((unsigned __int8)(*(_QWORD *)(a2 + 48) >> 17) ^ 1) & 1;
goto LABEL_14;
case 7:
case 8:
case 9:
v3 = ((unsigned __int8)(*(_QWORD *)(a2 + 48) >> 17) ^ 1) & 1;
LABEL_14:
if ( (int)itemweight(a2) > 18 * player[18] )
goto LABEL_22;
if ( !v3 && a3 == 1 )
{
if ( v5 > 6 )
{
v3 = 0;
if ( (unsigned int)(v5 - 7) <= 2 )
{
msg("Don't expect to backstab anyone while wielding that!");
v3 = 0;
}
}
else if ( v5 > 4 )
{
msg("You'll find it hard to cast spells while wielding that!");
v3 = 0;
}
else if ( v5 == 1 || (unsigned int)(v5 - 3) <= 1 )
{
msg("Your god strongly disapproves of your wielding that!");
v3 = 0;
}
}
break;
default:
if ( wizard && wiz_verbose )
msg("Unknown class %d.", (unsigned int)v5);
if ( (int)itemweight(a2) > 18 * player[18] )
{
LABEL_22:
if ( a3 == 1 && a1 == player )
{
msg("That is too heavy for you to swing effectively!");
v3 = 0;
}
else
{
v3 = 0;
}
}
else
{
v3 = 1;
}
break;
}
}
return v3;
}

original_code:
int
wield_ok(struct thing *wieldee, struct object *obj, int print_message)
{
    int ret_val = 1;
    int class_type = wieldee->t_ctype;
    if (obj->o_type != ')')
    {
        ret_val = 0;
        return(ret_val);
    }
    else
        switch (class_type)
        {
            case 5:
            case 6:
                if (obj->o_flags & 0x00020000UL)
                    ret_val = 0;
                break;
            case 7:
            case 8:
            case 9:
                if (obj->o_flags & 0x00020000UL)
                    ret_val = 0;
                break;
            case 3:
                if (obj->o_flags & 0x00010000UL)
                    ret_val = 0;
                break;
            case 4:
                if (obj->o_flags & 0x00000008UL && !(obj->o_flags & 0x00000100UL))
                    ret_val = 0;
                break;
            case 1:
                if ((obj->o_flags & 0x00010000UL) == 0)
                    ret_val = 0;
                break;
            case 0:
            case 2:
            case 10:
                break;
            default:
                if (wizard && wiz_verbose) msg("Unknown class %d.", class_type);
                break;
        }
    if (itemweight(obj) > 18 * player.t_stats.s_str)
    {
        if (wieldee == &player && print_message == 1)
            msg("That is too heavy for you to swing effectively!");
        ret_val = 0;
        return(ret_val);
    }
    if (ret_val == 0 && print_message == 1)
        switch (class_type)
        {
            case 5:
            case 6:
                msg("You'll find it hard to cast spells while wielding that!");
                break;
            case 7:
            case 8:
            case 9:
                msg("Don't expect to backstab anyone while wielding that!");
                break;
            case 3:
            case 4:
            case 1:
                msg("Your god strongly disapproves of your wielding that!");
                break;
            case 0:
            case 2:
            case 10:
                break;
        }
    return(ret_val);
}

variable_types:
obj
struct object *


wield

decompiled_code:
__int64 wield()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rbx
const char *v3; // rax

v0 = cur_weapon;
result = dropcheck(cur_weapon);
if ( (_DWORD)result )
{
cur_weapon = v0;
result = get_item("wield", 41LL);
if ( result )
{
v2 = *(_QWORD *)(result + 16);
result = is_current(v2);
if ( (_DWORD)result )
{
after = 0;
}
else
{
wield_ok(player, v2, 1);
v3 = (const char *)inv_name(v2, 1LL);
result = msg("You are now wielding %s.", v3);
cur_weapon = v2;
}
}
else
{
after = 0;
}
}
else
{
cur_weapon = v0;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rbx
const char *v3; // rax

v0 = cur_weapon;
result = dropcheck(cur_weapon);
if ( (_DWORD)result )
{
cur_weapon = v0;
result = get_item("wield", 41LL);
if ( result )
{
v2 = *(_QWORD *)(result + 16);
result = is_current(v2);
if ( (_DWORD)result )
{
after = 0;
}
else
{
func5(player, v2, 1);
v3 = (const char *)inv_name(v2, 1LL);
result = msg("You are now wielding %s.", v3);
cur_weapon = v2;
}
}
else
{
after = 0;
}
}
else
{
cur_weapon = v0;
}
return result;
}

original_code:
void
wield(void)
{
    struct linked_list *item;
    struct object *obj, *oweapon;
    oweapon = cur_weapon;
    if (!dropcheck(cur_weapon))
    {
        cur_weapon = oweapon;
        return;
    }
    cur_weapon = oweapon;
    if ((item = get_item("wield", ')')) == ((void *)0))
    {
        after = 0;
        return;
    }
    obj = ((*item).data.obj);
    if (is_current(obj))
    {
        after = 0;
        return;
    }
    wield_ok(&player, obj, 1);
    msg("You are now wielding %s.", inv_name(obj, 1));
    cur_weapon = obj;
}

canonical_original_code:
void wield()
{
    struct linked_list *item;
    struct object *obj; struct object *oweapon;
    oweapon = cur_weapon;
    if (!dropcheck(cur_weapon))
    {
        cur_weapon = oweapon;
        return;
    }
    cur_weapon = oweapon;
    if ((item = get_item("wield", ')')) == ((void *)0))
    {
        after = 0;
        return;
    }
    obj = ((*item).data.obj);
    if (is_current(obj))
    {
        after = 0;
        return;
    }
    wield_ok(&player, obj, 1);
    msg("You are now wielding %s.", inv_name(obj, 1));
    cur_weapon = obj;
}

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


original_code:
int
shoot_ok(int ch)
{
    switch(ch)
    {
        case ' ':
        case '|':
        case '-':
        case '&':
            return(0);
        default:
            return(!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISalpha));
    }
}

canonical_original_code:
int shoot_ok(int ch)
{
    switch(ch)
    {
        case ' ':
        case '|':
        case '-':
        case '&':
            return(0);
        default:
            return(!((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISalpha));
    }
}

variable_types: ch int


decompiled_code:
__int64 __fastcall do_motion(unsigned int a1, int a2, int a3, __int64 a4)
{
unsigned int v5; // ebx
unsigned int v6; // ebp
char v7; // al
int v8; // er12
int v9; // eax
__int64 v10; // rax

v5 = *(_DWORD *)(a4 + 192);
v6 = *(_DWORD *)(a4 + 196);
while ( 1 )
{
if ( (*(_DWORD *)(a4 + 192) != v5 || *(_DWORD *)(a4 + 196) != v6)
&& (unsigned int)((__int64 (__fastcall *)(_QWORD, _QWORD))cansee)(v6, v5)
&& (wmove(cw, v6, v5) == -1 || (unsigned int)winch(cw) != 32)
&& wmove(cw, v6, v5) != -1 )
{
v7 = show(v6, v5);
waddch(cw, (unsigned int)v7);
}
v6 += a2;
v5 += a3;
if ( wmove(mw, v6, v5) != -1 && (unsigned int)winch(mw) == 32 )
{
v8 = wmove(stdscr, v6, v5);
if ( v8 != -1 )
v8 = (char)winch(stdscr);
}
else
{
v8 = (char)winch(mw);
}
v9 = shoot_ok(v8);
if ( v8 == 43 || !v9 )
break;
if ( v5 == player[48] )
{
v10 = (unsigned int)player[49];
if ( v6 == (_DWORD)v10 )
return (v10 << 32) | v5;
}
if ( (unsigned int)((__int64 (__fastcall *)(_QWORD, _QWORD))cansee)(v6, v5)
&& (wmove(cw, v6, v5) == -1 || (unsigned int)winch(cw) != 32) )
{
if ( wmove(cw, v6, v5) != -1 )
waddch(cw, a1);
wrefresh(cw);
}
}
v10 = v6;
return (v10 << 32) | v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2, int a3, __int64 a4)
{
unsigned int v5; // ebx
unsigned int v6; // ebp
char v7; // al
int v8; // er12
int v9; // eax
__int64 v10; // rax

v5 = *(_DWORD *)(a4 + 192);
v6 = *(_DWORD *)(a4 + 196);
while ( 1 )
{
if ( (*(_DWORD *)(a4 + 192) != v5 || *(_DWORD *)(a4 + 196) != v6)
&& (unsigned int)((__int64 (__fastcall *)(_QWORD, _QWORD))cansee)(v6, v5)
&& (wmove(cw, v6, v5) == -1 || (unsigned int)winch(cw) != 32)
&& wmove(cw, v6, v5) != -1 )
{
v7 = show(v6, v5);
waddch(cw, (unsigned int)v7);
}
v6 += a2;
v5 += a3;
if ( wmove(mw, v6, v5) != -1 && (unsigned int)winch(mw) == 32 )
{
v8 = wmove(stdscr, v6, v5);
if ( v8 != -1 )
v8 = (char)winch(stdscr);
}
else
{
v8 = (char)winch(mw);
}
v9 = func7(v8);
if ( v8 == 43 || !v9 )
break;
if ( v5 == player[48] )
{
v10 = (unsigned int)player[49];
if ( v6 == (_DWORD)v10 )
return (v10 << 32) | v5;
}
if ( (unsigned int)((__int64 (__fastcall *)(_QWORD, _QWORD))cansee)(v6, v5)
&& (wmove(cw, v6, v5) == -1 || (unsigned int)winch(cw) != 32) )
{
if ( wmove(cw, v6, v5) != -1 )
waddch(cw, a1);
wrefresh(cw);
}
}
v10 = v6;
return (v10 << 32) | v5;
}

original_code:
coord
do_motion(int ob, int ydelta, int xdelta, struct thing *tp)
{
    coord pos;
    pos = tp->t_pos;
    for (;;)
    {
        int ch;
        if (!((pos).x == (tp->t_pos).x && (pos).y == (tp->t_pos).y) &&
            cansee(pos.y, pos.x) &&
            (wmove((cw),(pos.y),(pos.x)) == (-1) ? (chtype)((-1)) : winch(cw)) != ' ')
        {
            (wmove((cw),(pos.y),(pos.x)) == (-1) ? (-1) : waddch((cw),(show(pos.y, pos.x))));
        }
        pos.y += ydelta;
        pos.x += xdelta;
        if (shoot_ok(ch = ( (char) (((wmove((mw),(pos.y),(pos.x)) == (-1) ? (chtype)((-1)) : winch(mw)) == ' ') ? (wmove((stdscr),(pos.y),(pos.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) : winch(mw)) )) &&
            ch != '+' && !((pos).x == (player.t_pos).x && (pos).y == (player.t_pos).y))
        {
            if (cansee(pos.y, pos.x) &&
                (wmove((cw),(pos.y),(pos.x)) == (-1) ? (chtype)((-1)) : winch(cw)) != ' ')
            {
                (wmove((cw),(pos.y),(pos.x)) == (-1) ? (-1) : waddch((cw),(ob)));
                wrefresh(cw);
            }
            continue;
        }
        break;
    }
    return(pos);
}

canonical_original_code:
struct coord do_motion(int ob, int ydelta, int xdelta, struct thing *tp)
{
    struct coord pos;
    pos = tp->t_pos;
    for (;;)
    {
        int ch;
        if (!((pos).x == (tp->t_pos).x && (pos).y == (tp->t_pos).y) &&
            cansee(pos.y, pos.x) &&
            (wmove((cw),(pos.y),(pos.x)) == (-1) ? (chtype)((-1)) : winch(cw)) != ' ')
        {
            (wmove((cw),(pos.y),(pos.x)) == (-1) ? (-1) : waddch((cw),(show(pos.y, pos.x))));
        }
        pos.y += ydelta;
        pos.x += xdelta;
        if (shoot_ok(ch = ( (char) (((wmove((mw),(pos.y),(pos.x)) == (-1) ? (chtype)((-1)) : winch(mw)) == ' ') ? (wmove((stdscr),(pos.y),(pos.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) : winch(mw)) )) &&
            ch != '+' && !((pos).x == (player.t_pos).x && (pos).y == (player.t_pos).y))
        {
            if (cansee(pos.y, pos.x) &&
                (wmove((cw),(pos.y),(pos.x)) == (-1) ? (chtype)((-1)) : winch(cw)) != ' ')
            {
                (wmove((cw),(pos.y),(pos.x)) == (-1) ? (-1) : waddch((cw),(ob)));
                wrefresh(cw);
            }
            continue;
        }
        break;
    }
    return(pos);
}

variable_types: ob int

variable_types: ydelta int

variable_types: xdelta int

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

variable_types:
pos
struct coord { int x; int y; }

return_type: struct coord { int x; int y; }


missile

original_code:
void
missile(int ydelta, int xdelta, struct linked_list *item, struct thing *tp)
{
    struct object *obj;
    struct linked_list *nitem;
    if (item == ((void *)0))
        return;
    obj = ((*item).data.obj);
    if (!dropcheck(obj) || is_current(obj))
        return;
    if (obj->o_count < 2)
    {
        if (tp->t_pack == player.t_pack)
            rem_pack(obj);
        else
            _detach(&tp->t_pack, item);
    }
    else
    {
        obj->o_count--;
        nitem = (struct linked_list *) new_item(sizeof *obj);
        obj = ((*nitem).data.obj);
        *obj = *(((*item).data.obj));
        obj->o_count = 1;
        item = nitem;
    }
    switch (obj->o_type)
    {
        case ',':
            has_artifact &= ~(1 << obj->o_which);
            break;
        case '?':
            if (obj->o_which == 7 && obj->o_flags & 0x00000020UL)
                obj->o_flags &= ~0x00000020UL;
            else
                obj->o_flags |= 0x00000001UL;
    }
    updpack();
    obj->o_pos = do_motion(obj->o_type, ydelta, xdelta, tp);
    if (!hit_monster(obj->o_pos.y, obj->o_pos.x, obj, tp))
    {
        if (obj->o_type == ')' && obj->o_which == 24)
        {
            hearmsg("BOOOM!");
            aggravate();
            if (ntraps + 1 < 2 * 80 &&
                fallpos(obj->o_pos, &traps[ntraps].tr_pos))
            {
                (wmove((stdscr),((traps[ntraps].tr_pos.y)),((traps[ntraps].tr_pos.x))) == (-1) ? (-1) : waddch((stdscr),(('>'))));
                traps[ntraps].tr_type = '>';
                traps[ntraps].tr_flags = 0x00000008UL;
                traps[ntraps].tr_show = '>';
                ntraps++;
                light(&player.t_pos);
            }
            discard(item);
        }
        else if (obj->o_flags & 0x00001000UL)
        {
            if (obj->o_type == ')')
                addmsg("The %s", weaps[obj->o_which].w_name);
            else
                addmsg(inv_name(obj, 1));
            msg(" vanishes in a puff of greasy smoke.");
            discard(item);
        }
        else
        {
            fall(&player, item, 1, 1);
            if (obj->o_flags & 0x00000400UL)
                msg("You have %s.", inv_name(obj, 1));
        }
    }
    else if (obj->o_flags & 0x00000800UL)
    {
        add_pack(item, 0);
        msg("You have %s.", inv_name(obj, 1));
    }
    (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
}

variable_types:
tp
struct thing *

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:
void *__fastcall ur_alloc(size_t n)
{
void *v1; // rax
void *v2; // rbx

++total;
v1 = (void *)mem_malloc();
v2 = v1;
if ( v1 )
memset(v1, 0, n);
return v2;
}

canonical_decompiled_code:
void *__fastcall func0(size_t n)
{
void *v1; // rax
void *v2; // rbx

++total;
v1 = (void *)mem_malloc();
v2 = v1;
if ( v1 )
memset(v1, 0, n);
return v2;
}

original_code:
void *
ur_alloc(size_t size)
{
    char *buf_p;
    total++;
    buf_p = mem_malloc(size);
    if (buf_p == ((void *)0))
        return(((void *)0));
    memset(buf_p,0,size);
    return(buf_p);
}

canonical_original_code:
void *ur_alloc(unsigned long size)
{
    char *buf_p;
    total++;
    buf_p = mem_malloc(size);
    if (buf_p == ((void *)0))
        return(((void *)0));
    memset(buf_p,0,size);
    return(buf_p);
}

variable_types:
size
unsigned long

return_type: void *


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

result = mem_free();
--total;
return result;
}

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

result = mem_free();
--total;
return result;
}

original_code:
void
ur_free(void *buf_p)
{
    mem_free(buf_p);
    total--;
}


decompiled_code:
__int64 __fastcall throw_away(__int64 a1)
{
free_ident();
return ur_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
free_ident();
return func1(a1);
}

original_code:
void
throw_away(struct object *ptr)
{
    free_ident(ptr);
    ur_free(ptr);
}


discard

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
func5(*(_QWORD *)(a1 + 16));
return func1(a1);
}

original_code:
void
discard(struct linked_list *item)
{
    throw_away(item->data.obj);
    ur_free(item);
}


decompiled_code:
void *__fastcall new_alloc(size_t a1)
{
void *v1; // rbx

v1 = ur_alloc(a1);
if ( !v1 )
{
strcpy((char *)&errbuf, "Rogue ran out of memory.");
fatal(&errbuf);
}
return v1;
}

canonical_decompiled_code:
void *__fastcall func8(size_t a1)
{
void *v1; // rbx

v1 = func0(a1);
if ( !v1 )
{
strcpy((char *)&errbuf, "Rogue ran out of memory.");
fatal(&errbuf);
}
return v1;
}

original_code:
void *
new_alloc(size_t size)
{
    void *space = ur_alloc(size);
    if (space == ((void *)0))
    {
        sprintf(errbuf, "Rogue ran out of memory.");
        fatal(errbuf);
    }
    return(space);
}

canonical_original_code:
void *new_alloc(unsigned long size)
{
    void *space = ur_alloc(size);
    if (space == ((void *)0))
    {
        sprintf(errbuf, "Rogue ran out of memory.");
        fatal(errbuf);
    }
    return(space);
}

variable_types:
space
void *


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


whatis

decompiled_code:
__int64 __fastcall whatis(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
int v3; // er12
int v4; // ebp
__int64 v5; // rax
char v6; // al
__int64 v7; // rax

if ( !a1 )
{
do
v5 = get_item("identify", 0LL);
while ( !v5 );
v1 = *(_QWORD *)(v5 + 16);
*(_QWORD *)(v1 + 48) |= 2uLL;
v6 = *(_BYTE *)(v1 + 64);
if ( v6 != 61 )
{
if ( v6 > 61 )
{
if ( v6 == 63 )
{
know_items[*(int *)(v1 + 76) + 50] = 1;
if ( guess_items[*(int *)(v1 + 76) + 50] )
{
v3 = 1;
v4 = 1;
goto LABEL_28;
}
}
}
else
{
if ( v6 == 33 )
{
v3 = 1;
LABEL_21:
v4 = 0;
LABEL_17:
know_items[50 * v4 + *(int *)(v1 + 76)] = 1;
result = *(int *)(v1 + 76) + 50LL * v4;
if ( !guess_items[result] )
{
LABEL_29:
if ( !v3 )
return result;
goto LABEL_30;
}
LABEL_28:
ur_free();
result = *(int *)(v1 + 76) + 50LL * v4;
guess_items[result] = 0LL;
goto LABEL_29;
}
if ( v6 == 47 )
{
v3 = 1;
LABEL_7:
v4 = 3;
goto LABEL_17;
}
}
LABEL_30:
v7 = inv_name(v1, 0LL);
return msg(v7);
}
v3 = 1;
LABEL_16:
v4 = 2;
goto LABEL_17;
}
v1 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(v1 + 48) |= 2uLL;
result = *(unsigned __int8 *)(v1 + 64);
if ( (_BYTE)result == 61 )
{
v3 = 0;
goto LABEL_16;
}
if ( (char)result <= 61 )
{
if ( (_BYTE)result != 33 )
{
if ( (_BYTE)result != 47 )
return result;
v3 = 0;
goto LABEL_7;
}
v3 = 0;
goto LABEL_21;
}
if ( (_BYTE)result == 63 )
{
know_items[*(int *)(v1 + 76) + 50] = 1;
result = *(int *)(v1 + 76);
if ( guess_items[result + 50] )
{
v3 = 0;
v4 = 1;
goto LABEL_28;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax
int v3; // er12
int v4; // ebp
__int64 v5; // rax
char v6; // al
__int64 v7; // rax

if ( !a1 )
{
do
v5 = get_item("identify", 0LL);
while ( !v5 );
v1 = *(_QWORD *)(v5 + 16);
*(_QWORD *)(v1 + 48) |= 2uLL;
v6 = *(_BYTE *)(v1 + 64);
if ( v6 != 61 )
{
if ( v6 > 61 )
{
if ( v6 == 63 )
{
know_items[*(int *)(v1 + 76) + 50] = 1;
if ( guess_items[*(int *)(v1 + 76) + 50] )
{
v3 = 1;
v4 = 1;
goto LABEL_28;
}
}
}
else
{
if ( v6 == 33 )
{
v3 = 1;
LABEL_21:
v4 = 0;
LABEL_17:
know_items[50 * v4 + *(int *)(v1 + 76)] = 1;
result = *(int *)(v1 + 76) + 50LL * v4;
if ( !guess_items[result] )
{
LABEL_29:
if ( !v3 )
return result;
goto LABEL_30;
}
LABEL_28:
ur_free();
result = *(int *)(v1 + 76) + 50LL * v4;
guess_items[result] = 0LL;
goto LABEL_29;
}
if ( v6 == 47 )
{
v3 = 1;
LABEL_7:
v4 = 3;
goto LABEL_17;
}
}
LABEL_30:
v7 = inv_name(v1, 0LL);
return msg(v7);
}
v3 = 1;
LABEL_16:
v4 = 2;
goto LABEL_17;
}
v1 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(v1 + 48) |= 2uLL;
result = *(unsigned __int8 *)(v1 + 64);
if ( (_BYTE)result == 61 )
{
v3 = 0;
goto LABEL_16;
}
if ( (char)result <= 61 )
{
if ( (_BYTE)result != 33 )
{
if ( (_BYTE)result != 47 )
return result;
v3 = 0;
goto LABEL_7;
}
v3 = 0;
goto LABEL_21;
}
if ( (_BYTE)result == 63 )
{
know_items[*(int *)(v1 + 76) + 50] = 1;
result = *(int *)(v1 + 76);
if ( guess_items[result + 50] )
{
v3 = 0;
v4 = 1;
goto LABEL_28;
}
}
return result;
}

original_code:
void
whatis(struct linked_list *what)
{
    struct object *obj;
    int kludge;
    int print_message = 0;
    if (what == ((void *)0))
    {
        print_message = 1;
        while ((what = get_item("identify", 0)) == ((void *)0))
            ;
    }
    obj = ((*what).data.obj);
    obj->o_flags |= 0x00000002UL;
    switch (obj->o_type)
    {
        case '?': kludge = 1; break;
        case '!': kludge = 0; break;
        case '/': kludge = 3; break;
        case '=': kludge = 2; break;
        case ')':
        case ']':
        default: kludge = -1; break;
    }
    if (kludge != -1)
    {
        know_items[kludge][obj->o_which] = 1;
        if (guess_items[kludge][obj->o_which])
        {
            ur_free(guess_items[kludge][obj->o_which]);
            guess_items[kludge][obj->o_which] = ((void *)0);
        }
    }
    if (print_message)
        msg(inv_name(obj, 0));
}

variable_types: kludge int


teleport

decompiled_code:
__int64 teleport()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rcx
chtype v3; // rsi
int v4; // esi
int v5; // edx
__int64 v6; // rcx
int v7; // eax
__int64 v8; // rdi
char *v9; // rbp
int v10; // ebp
__int64 v11; // rax
_QWORD *v12; // rcx
__int64 result; // rax
__int64 v14; // rax
__int64 v15; // rdx
int v16[2]; // [rsp+8h] [rbp-20h] BYREF

v0 = roomin(*((_QWORD *)&player + 24));
*(_QWORD *)v16 = *((_QWORD *)&player + 24);
if ( wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
{
v3 = 0xFFFFFFFFLL;
if ( wmove(stdscr, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
v3 = (unsigned int)winch(stdscr);
waddch(cw, v3);
}
if ( (unsigned int)is_wearing(30LL) )
{
msg("Where do you wish to teleport to? (* for help)");
wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48));
wrefresh(cw);
v1 = readchar() & 0x7F;
if ( (unsigned __int8)v1 > 0x1Bu || (v2 = 134226944LL, !_bittest64(&v2, (unsigned __int8)v1)) )
{
while ( 1 )
{
if ( v1 == 42 )
msg("Use h,j,k,l,y,u,b,n to position cursor, then hitreturn.");
v4 = 1;
if ( v16[1] > 0 )
v4 = v16[1];
if ( v4 > LINES - 3 )
v4 = LINES - 3;
v16[1] = v4;
v5 = 1;
if ( v16[0] > 0 )
v5 = v16[0];
if ( v5 > COLS - 1 )
v5 = COLS - 1;
v16[0] = v5;
wmove(cw, v4, v5);
wrefresh(cw);
v1 = readchar() & 0x7F;
if ( (unsigned __int8)v1 <= 0x1Bu )
{
v6 = 134226944LL;
if ( _bittest64(&v6, (unsigned __int8)v1) )
break;
}
}
}
if ( wmove(mw, v16[1], v16[0]) != -1 && (unsigned int)winch(mw) == 32 )
{
if ( wmove(stdscr, v16[1], v16[0]) == -1 )
goto LABEL_26;
v7 = (char)winch(stdscr);
}
else
{
v7 = (char)winch(mw);
}
if ( ((v7 & 0xFFFFFFF7) == 35 || v7 == 46)
&& (!(unsigned int)ring_value(30LL) && (int)rnd(10LL) <= 5 || (int)ring_value(30LL) > 0 && (int)rnd(10LL) <= 8) )
{
msg("You attempt succeeds.");
v8 = *(_QWORD *)v16;
*((_QWORD *)&player + 24) = *(_QWORD *)v16;
v9 = (char *)roomin(v8);
goto LABEL_39;
}
LABEL_26:
msg("Your attempt fails.");
goto LABEL_35;
}
do
{
LABEL_35:
while ( 1 )
{
v9 = (char *)&rooms + 60 * (int)rnd_room();
rnd_pos(v9, (unsigned int)((_DWORD)&player + 192));
if ( wmove(mw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 && (unsigned int)winch(mw) == 32 )
break;
if ( (unsigned __int8)winch(mw) == 46 )
goto LABEL_39;
}
}
while ( wmove(stdscr, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) == -1
|| (unsigned __int8)winch(stdscr) != 46 );
LABEL_39:
if ( v0 )
{
if ( v9 != (char *)v0 )
{
v10 = *(_DWORD *)(v0 + 48);
*(_DWORD *)(v0 + 48) = v10 | 1;
light(v16);
if ( (v10 & 1) == 0 )
*(_DWORD *)(v0 + 48) &= 0xFFFFFFFE;
}
}
light((unsigned int)((_DWORD)&player + 192));
if ( wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
waddch(cw, (unsigned int)(char)PLAYER);
v11 = *((_QWORD *)&player + 27);
if ( (v11 & 0x100) != 0 )
{
BYTE1(v11) &= 0xFEu;
*((_QWORD *)&player + 27) = v11;
hold_count = 0;
v12 = (_QWORD *)mlist;
if ( mlist )
{
do
{
v14 = v12[2];
v12 = (_QWORD *)*v12;
v15 = *(_QWORD *)(v14 + 232);
if ( (v15 & 0x4000000) != 0 )
*(_QWORD *)(v14 + 232) = v15 & 0xFFFFFFFFFBFFFFFFLL | 0x2000000;
*(_QWORD *)(v14 + 224) &= 0xFFFFFFFFFFFFFFEFLL;
}
while ( v12 );
}
}
result = extinguish_fuse(15LL);
*((_DWORD *)&player + 92) = 0;
count = 0;
running = 0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rcx
chtype v3; // rsi
int v4; // esi
int v5; // edx
__int64 v6; // rcx
int v7; // eax
__int64 v8; // rdi
char *v9; // rbp
int v10; // ebp
__int64 v11; // rax
_QWORD *v12; // rcx
__int64 result; // rax
__int64 v14; // rax
__int64 v15; // rdx
int v16[2]; // [rsp+8h] [rbp-20h] BYREF

v0 = roomin(*((_QWORD *)&player + 24));
*(_QWORD *)v16 = *((_QWORD *)&player + 24);
if ( wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
{
v3 = 0xFFFFFFFFLL;
if ( wmove(stdscr, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
v3 = (unsigned int)winch(stdscr);
waddch(cw, v3);
}
if ( (unsigned int)is_wearing(30LL) )
{
msg("Where do you wish to teleport to? (* for help)");
wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48));
wrefresh(cw);
v1 = readchar() & 0x7F;
if ( (unsigned __int8)v1 > 0x1Bu || (v2 = 134226944LL, !_bittest64(&v2, (unsigned __int8)v1)) )
{
while ( 1 )
{
if ( v1 == 42 )
msg("Use h,j,k,l,y,u,b,n to position cursor, then hitreturn.");
v4 = 1;
if ( v16[1] > 0 )
v4 = v16[1];
if ( v4 > LINES - 3 )
v4 = LINES - 3;
v16[1] = v4;
v5 = 1;
if ( v16[0] > 0 )
v5 = v16[0];
if ( v5 > COLS - 1 )
v5 = COLS - 1;
v16[0] = v5;
wmove(cw, v4, v5);
wrefresh(cw);
v1 = readchar() & 0x7F;
if ( (unsigned __int8)v1 <= 0x1Bu )
{
v6 = 134226944LL;
if ( _bittest64(&v6, (unsigned __int8)v1) )
break;
}
}
}
if ( wmove(mw, v16[1], v16[0]) != -1 && (unsigned int)winch(mw) == 32 )
{
if ( wmove(stdscr, v16[1], v16[0]) == -1 )
goto LABEL_26;
v7 = (char)winch(stdscr);
}
else
{
v7 = (char)winch(mw);
}
if ( ((v7 & 0xFFFFFFF7) == 35 || v7 == 46)
&& (!(unsigned int)ring_value(30LL) && (int)rnd(10LL) <= 5 || (int)ring_value(30LL) > 0 && (int)rnd(10LL) <= 8) )
{
msg("You attempt succeeds.");
v8 = *(_QWORD *)v16;
*((_QWORD *)&player + 24) = *(_QWORD *)v16;
v9 = (char *)roomin(v8);
goto LABEL_39;
}
LABEL_26:
msg("Your attempt fails.");
goto LABEL_35;
}
do
{
LABEL_35:
while ( 1 )
{
v9 = (char *)&rooms + 60 * (int)rnd_room();
rnd_pos(v9, (unsigned int)((_DWORD)&player + 192));
if ( wmove(mw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 && (unsigned int)winch(mw) == 32 )
break;
if ( (unsigned __int8)winch(mw) == 46 )
goto LABEL_39;
}
}
while ( wmove(stdscr, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) == -1
|| (unsigned __int8)winch(stdscr) != 46 );
LABEL_39:
if ( v0 )
{
if ( v9 != (char *)v0 )
{
v10 = *(_DWORD *)(v0 + 48);
*(_DWORD *)(v0 + 48) = v10 | 1;
light(v16);
if ( (v10 & 1) == 0 )
*(_DWORD *)(v0 + 48) &= 0xFFFFFFFE;
}
}
light((unsigned int)((_DWORD)&player + 192));
if ( wmove(cw, *((_DWORD *)&player + 49), *((_DWORD *)&player + 48)) != -1 )
waddch(cw, (unsigned int)(char)PLAYER);
v11 = *((_QWORD *)&player + 27);
if ( (v11 & 0x100) != 0 )
{
BYTE1(v11) &= 0xFEu;
*((_QWORD *)&player + 27) = v11;
hold_count = 0;
v12 = (_QWORD *)mlist;
if ( mlist )
{
do
{
v14 = v12[2];
v12 = (_QWORD *)*v12;
v15 = *(_QWORD *)(v14 + 232);
if ( (v15 & 0x4000000) != 0 )
*(_QWORD *)(v14 + 232) = v15 & 0xFFFFFFFFFBFFFFFFLL | 0x2000000;
*(_QWORD *)(v14 + 224) &= 0xFFFFFFFFFFFFFFEFLL;
}
while ( v12 );
}
}
result = extinguish_fuse(15LL);
*((_DWORD *)&player + 92) = 0;
count = 0;
running = 0;
return result;
}

original_code:
void
teleport(void)
{
    struct room *new_rp = ((void *)0), *old_rp = roomin(player.t_pos);
    int rm, which;
    coord c;
    int is_lit = 0;
    int rand_position = 1;
    c = player.t_pos;
    (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),((wmove((stdscr),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)))));
    if (is_wearing(30))
    {
        msg("Where do you wish to teleport to? (* for help)");
        wmove(cw, player.t_pos.y, player.t_pos.x);
        wrefresh(cw);
        which = (short) (readchar() & 0177);
        while (which != (short) 27 && which != (short) 10
            && which != (short) 13)
        {
            switch(which)
            {
                case 'h': c.x--; break;
                case 'j': c.y++; break;
                case 'k': c.y--; break;
                case 'l': c.x++; break;
                case 'y': c.x--;
                            c.y--; break;
                case 'u': c.x++;
                            c.y--; break;
                case 'b': c.x--;
                            c.y++; break;
                case 'n': c.x++;
                            c.y++; break;
                case '*':
                    msg("Use h,j,k,l,y,u,b,n to position cursor, then hit"
                        "return.");
            }
            c.y = ((c.y) > (1) ? (c.y) : (1));
            c.y = ((c.y) < (LINES - 3) ? (c.y) : (LINES - 3));
            c.x = ((c.x) > (1) ? (c.x) : (1));
            c.x = ((c.x) < (COLS - 1) ? (c.x) : (COLS - 1));
            wmove(cw, c.y, c.x);
            wrefresh(cw);
            which = (short) (readchar() & 0177);
        }
        which = ( (char) (((wmove((mw),(c.y),(c.x)) == (-1) ? (chtype)((-1)) : winch(mw)) == ' ') ? (wmove((stdscr),(c.y),(c.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) : winch(mw)) );
        if ((which == '.' || which == '#' || which == '+') &&
            ((ring_value(30) == 0 && rnd(10) < 6)
             || (ring_value(30) > 0 && rnd(10) < 9)))
        {
            rand_position = 0;
            msg("You attempt succeeds.");
            player.t_pos = c;
            new_rp = roomin(player.t_pos);
        }
        else
            msg("Your attempt fails.");
    }
    if (rand_position)
    {
        do
        {
            rm = rnd_room();
            rnd_pos(&rooms[rm], &player.t_pos);
        }
        while (( (char) (((wmove((mw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (chtype)((-1)) : winch(mw)) == ' ') ? (wmove((stdscr),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) : winch(mw)) ) != '.');
        new_rp = &rooms[rm];
    }
    if (old_rp && old_rp != new_rp)
    {
        if (!(old_rp->r_flags & 0x00000001UL))
            is_lit = 1;
        old_rp->r_flags |= 0x00000001UL;
        light(&c);
        if (is_lit)
            old_rp->r_flags &= ~0x00000001UL;
    }
    light(&player.t_pos);
    (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
    if (((player).t_flags[(0x00000100UL >> 28UL) & 0x0000000fL] & (0x00000100UL & 0x0fffffffL)))
    {
        struct linked_list *ip, *nip;
        struct thing *mp;
        ( (player).t_flags[(0x00000100UL >> 28UL) & 0x0000000fL] &= ~(0x00000100UL & 0x0fffffffL));
        hold_count = 0;
        for (ip = mlist; ip; ip = nip)
        {
            mp = ((*ip).data.th);
            nip = ((ip)?(ip->l_next):((void *)0));
            if (((*mp).t_flags[(0x24000000UL >> 28UL) & 0x0000000fL] & (0x24000000UL & 0x0fffffffL)))
            {
                ( (*mp).t_flags[(0x24000000UL >> 28UL) & 0x0000000fL] &= ~(0x24000000UL & 0x0fffffffL));
                ( (*mp).t_flags[(0x22000000UL >> 28UL) & 0x0000000fL] |= (0x22000000UL & 0x0fffffffL));
            }
            ( (*mp).t_flags[(0x10000010UL >> 28UL) & 0x0000000fL] &= ~(0x10000010UL & 0x0fffffffL));
        }
    }
    extinguish_fuse(15);
    player.t_no_move = 0;
    count = 0;
    running = 0;
    return;
}

canonical_original_code:
void teleport()
{
    struct room *new_rp = ((void *)0); struct room *old_rp = roomin(player.t_pos);
    int rm; int which;
    struct coord c;
    int is_lit = 0;
    int rand_position = 1;
    c = player.t_pos;
    (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),((wmove((stdscr),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)))));
    if (is_wearing(30))
    {
        msg("Where do you wish to teleport to? (* for help)");
        wmove(cw, player.t_pos.y, player.t_pos.x);
        wrefresh(cw);
        which = (short) (readchar() & 0177);
        while (which != (short) 27 && which != (short) 10
            && which != (short) 13)
        {
            switch(which)
            {
                case 'h': c.x--; break;
                case 'j': c.y++; break;
                case 'k': c.y--; break;
                case 'l': c.x++; break;
                case 'y': c.x--;
                            c.y--; break;
                case 'u': c.x++;
                            c.y--; break;
                case 'b': c.x--;
                            c.y++; break;
                case 'n': c.x++;
                            c.y++; break;
                case '*':
                    msg("Use h,j,k,l,y,u,b,n to position cursor, then hit"
                        "return.");
            }
            c.y = ((c.y) > (1) ? (c.y) : (1));
            c.y = ((c.y) < (LINES - 3) ? (c.y) : (LINES - 3));
            c.x = ((c.x) > (1) ? (c.x) : (1));
            c.x = ((c.x) < (COLS - 1) ? (c.x) : (COLS - 1));
            wmove(cw, c.y, c.x);
            wrefresh(cw);
            which = (short) (readchar() & 0177);
        }
        which = ( (char) (((wmove((mw),(c.y),(c.x)) == (-1) ? (chtype)((-1)) : winch(mw)) == ' ') ? (wmove((stdscr),(c.y),(c.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) : winch(mw)) );
        if ((which == '.' || which == '#' || which == '+') &&
            ((ring_value(30) == 0 && rnd(10) < 6)
             || (ring_value(30) > 0 && rnd(10) < 9)))
        {
            rand_position = 0;
            msg("You attempt succeeds.");
            player.t_pos = c;
            new_rp = roomin(player.t_pos);
        }
        else
            msg("Your attempt fails.");
    }
    if (rand_position)
    {
        do
        {
            rm = rnd_room();
            rnd_pos(&rooms[rm], &player.t_pos);
        }
        while (( (char) (((wmove((mw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (chtype)((-1)) : winch(mw)) == ' ') ? (wmove((stdscr),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) : winch(mw)) ) != '.');
        new_rp = &rooms[rm];
    }
    if (old_rp && old_rp != new_rp)
    {
        if (!(old_rp->r_flags & 0x00000001UL))
            is_lit = 1;
        old_rp->r_flags |= 0x00000001UL;
        light(&c);
        if (is_lit)
            old_rp->r_flags &= ~0x00000001UL;
    }
    light(&player.t_pos);
    (wmove((cw),(player.t_pos.y),(player.t_pos.x)) == (-1) ? (-1) : waddch((cw),(PLAYER)));
    if (((player).t_flags[(0x00000100UL >> 28UL) & 0x0000000fL] & (0x00000100UL & 0x0fffffffL)))
    {
        struct linked_list *ip; struct linked_list *nip;
        struct thing *mp;
        ( (player).t_flags[(0x00000100UL >> 28UL) & 0x0000000fL] &= ~(0x00000100UL & 0x0fffffffL));
        hold_count = 0;
        for (ip = mlist; ip; ip = nip)
        {
            mp = ((*ip).data.th);
            nip = ((ip)?(ip->l_next):((void *)0));
            if (((*mp).t_flags[(0x24000000UL >> 28UL) & 0x0000000fL] & (0x24000000UL & 0x0fffffffL)))
            {
                ( (*mp).t_flags[(0x24000000UL >> 28UL) & 0x0000000fL] &= ~(0x24000000UL & 0x0fffffffL));
                ( (*mp).t_flags[(0x22000000UL >> 28UL) & 0x0000000fL] |= (0x22000000UL & 0x0fffffffL));
            }
            ( (*mp).t_flags[(0x10000010UL >> 28UL) & 0x0000000fL] &= ~(0x10000010UL & 0x0fffffffL));
        }
    }
    extinguish_fuse(15);
    player.t_no_move = 0;
    count = 0;
    running = 0;
    return;
}

variable_types: rm int

variable_types: which int

variable_types:
c
struct coord { int x; int y; }

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


passwd

decompiled_code:
_BOOL8 passwd()
{
_BYTE *v0; // rbx
__int64 v1; // rbp
__int64 v2; // rax
_BYTE v4[1048]; // [rsp+0h] [rbp-418h] BYREF

msg("Wizard's Password:");
mpos = 0;
v0 = v4;
v1 = 134226944LL;
while ( 1 )
{
v2 = readchar() & 0x7F;
if ( (unsigned __int8)v2 <= 0x1Bu )
{
if ( _bittest64(&v1, v2) )
break;
}
if ( (_BYTE)v2 )
{
if ( v0 > v4 && (_BYTE)v2 == 8 )
--v0;
else
*v0++ = v2;
}
else
{
v0 = v4;
}
}
return v0 != v4;
}

canonical_decompiled_code:
_BOOL8 func2()
{
_BYTE *v0; // rbx
__int64 v1; // rbp
__int64 v2; // rax
_BYTE v4[1048]; // [rsp+0h] [rbp-418h] BYREF

msg("Wizard's Password:");
mpos = 0;
v0 = v4;
v1 = 134226944LL;
while ( 1 )
{
v2 = readchar() & 0x7F;
if ( (unsigned __int8)v2 <= 0x1Bu )
{
if ( _bittest64(&v1, v2) )
break;
}
if ( (_BYTE)v2 )
{
if ( v0 > v4 && (_BYTE)v2 == 8 )
--v0;
else
*v0++ = v2;
}
else
{
v0 = v4;
}
}
return v0 != v4;
}

original_code:
int
passwd(void)
{
    char *sp, c;
    char buf[2 * 512];
    msg("Wizard's Password:");
    mpos = 0;
    sp = buf;
    while ((c = (readchar() & 0177)) != '\n' && c != '\r' && c != '\033')
    {
        if (c == '\0')
            sp = buf;
        else if (c == '\b' && sp > buf)
            sp--;
        else
            *sp++ = c;
    }
    if (sp == buf)
        return(0);
    *sp = '\0';
    return(1);
}

canonical_original_code:
int passwd()
{
    char *sp; char c;
    char buf[-1];
    msg("Wizard's Password:");
    mpos = 0;
    sp = buf;
    while ((c = (readchar() & 0177)) != '\n' && c != '\r' && c != '\033')
    {
        if (c == '\0')
            sp = buf;
        else if (c == '\b' && sp > buf)
            sp--;
        else
            *sp++ = c;
    }
    if (sp == buf)
        return(0);
    *sp = '\0';
    return(1);
}

variable_types:
sp
char *

variable_types: c char

variable_types:
buf
char [-1]