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

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

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

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

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

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

variable_types: ring int

variable_types:
buf
char [-1]


repo: RoguelikeRestorationProject/urogue

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

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

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

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

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

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

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

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 ring_eat(int a1)
{
__int64 v1; // rax
int v2; // ebx
int v4; // eax
__int64 v5; // rdi
int v6; // ebp

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

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rax
int v2; // ebx
int v4; // eax
__int64 v5; // rdi
int v6; // ebp

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

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

variable_types: hand int

variable_types: ac int

return_type: int


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

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

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

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

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

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

variable_types:
buf
char *

variable_types:
buffer
char [1024]

return_type: char *

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


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

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

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

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

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

variable_types: type int

variable_types: result int


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

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

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

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

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

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

variable_types:
file
char *

variable_types: line int

variable_types:
s
char [80]


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

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

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

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

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

variable_types: id int


original_code:
struct object *
apply_to_bag(struct linked_list *bag_p,
             int type,
             int (*bff_p)(struct object *obj, bag_arg *user_arg),
             int (*baf_p)(struct object *obj, bag_arg *user_arg, int id),
             void *user_arg)
{
    struct object *bag_obj_p = ((void *)0);
    struct object *cur_obj_p;
    bag_arg arg;
    arg.varg = user_arg;
    if (bag_p == ((void *)0))
        return (((void *)0));
    for (; bag_p != ((void *)0); bag_p = ((bag_p)?(bag_p->l_next):((void *)0)))
    {
        cur_obj_p = ((*bag_p).data.obj);
        if (type != 0 && type != cur_obj_p->o_type)
            continue;
        if (bff_p != ((void *)0) && !(*bff_p)(cur_obj_p, &arg))
            continue;
        bag_obj_p = cur_obj_p;
        if (baf_p != ((void *)0) && (*baf_p)(cur_obj_p, &arg, (bag_obj_p->o_ident)))
            continue;
        break;
    }
    if (bag_p == ((void *)0))
        return (((void *)0));
    return (bag_obj_p);
}

canonical_original_code:
struct object *apply_to_bag(struct linked_list *bag_p, int type, int (*bff_p)(struct object *obj, union bag_arg *user_arg), int (*baf_p)(struct object *obj, union bag_arg *user_arg, int id), void *user_arg)
{
    struct object *bag_obj_p = ((void *)0);
    struct object *cur_obj_p;
    union bag_arg arg;
    arg.varg = user_arg;
    if (bag_p == ((void *)0))
        return (((void *)0));
    for (; bag_p != ((void *)0); bag_p = ((bag_p)?(bag_p->l_next):((void *)0)))
    {
        cur_obj_p = ((*bag_p).data.obj);
        if (type != 0 && type != cur_obj_p->o_type)
            continue;
        if (bff_p != ((void *)0) && !(*bff_p)(cur_obj_p, &arg))
            continue;
        bag_obj_p = cur_obj_p;
        if (baf_p != ((void *)0) && (*baf_p)(cur_obj_p, &arg, (bag_obj_p->o_ident)))
            continue;
        break;
    }
    if (bag_p == ((void *)0))
        return (((void *)0));
    return (bag_obj_p);
}

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

variable_types: int (*)(struct object *obj, union bag_arg *user_arg, int id)

variable_types: union bag_arg { void *varg; int *iarg; 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; } *obj; }


decompiled_code:
__int64 __fastcall count_bag(_QWORD *a1, int a2, unsigned int (__fastcall *a3)(_QWORD, __int64 *))
{
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
apply_to_bag(a1, a2, a3, (unsigned int (__fastcall *)(__int64, __int64 *, _QWORD))baf_increment, (__int64)v4);
return v4[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int a2, unsigned int (__fastcall *a3)(_QWORD, __int64 *))
{
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

v4[0] = 0;
func1(a1, a2, a3, (unsigned int (__fastcall *)(__int64, __int64 *, _QWORD))baf_increment, (__int64)v4);
return v4[0];
}

original_code:
int
count_bag(linked_list *bag_p,
          int type,
          int (*bff_p)(struct object *obj, bag_arg *junk))
{
    int cnt = 0;
    apply_to_bag(bag_p, type, bff_p, baf_increment, &cnt);
    return(cnt);
}

canonical_original_code:
int count_bag(struct linked_list *bag_p, int type, int (*bff_p)(struct object *obj, union bag_arg *junk))
{
    int cnt = 0;
    apply_to_bag(bag_p, type, bff_p, baf_increment, &cnt);
    return(cnt);
}

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

variable_types: cnt int


decompiled_code:
__int64 __fastcall del_bag(__int64 a1, _QWORD *a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a1;
pop_bag(&v3, a2);
return ur_free(a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a1;
pop_bag(&v3, a2);
return ur_free(a2);
}

original_code:
void
del_bag(linked_list *bag_p, object *obj_p)
{
    pop_bag(&bag_p, obj_p);
    ur_free(obj_p);
}

canonical_original_code:
void del_bag(struct linked_list *bag_p, struct object *obj_p)
{
    pop_bag(&bag_p, obj_p);
    ur_free(obj_p);
}

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:
void
push_bag(linked_list **bag_pp, object *obj_p)
{
    struct linked_list *item_p = ((void *)0);
    struct linked_list *new_p = ((void *)0);
    struct linked_list *best_p = ((void *)0);
    new_p = new_list();
    new_p->data.obj = obj_p;
    (obj_p->o_ident) = get_ident(obj_p);
    for (item_p = *bag_pp; item_p != ((void *)0); item_p = ((item_p)?(item_p->l_next):((void *)0)))
    {
        if ((((*item_p).data.obj))->o_type == obj_p->o_type)
        {
            if (best_p == ((void *)0))
                best_p = item_p;
            else if (((((*item_p).data.obj))->o_ident) >
                     ((((*best_p).data.obj))->o_ident) &&
                     ((((*item_p).data.obj))->o_ident) <
                     (obj_p->o_ident))
                best_p = item_p;
        }
    }
    _attach_after(bag_pp, best_p, new_p);
    return;
}

canonical_original_code:
void push_bag(struct linked_list **bag_pp, struct object *obj_p)
{
    struct linked_list *item_p = ((void *)0);
    struct linked_list *new_p = ((void *)0);
    struct linked_list *best_p = ((void *)0);
    new_p = new_list();
    new_p->data.obj = obj_p;
    (obj_p->o_ident) = get_ident(obj_p);
    for (item_p = *bag_pp; item_p != ((void *)0); item_p = ((item_p)?(item_p->l_next):((void *)0)))
    {
        if ((((*item_p).data.obj))->o_type == obj_p->o_type)
        {
            if (best_p == ((void *)0))
                best_p = item_p;
            else if (((((*item_p).data.obj))->o_ident) >
                     ((((*best_p).data.obj))->o_ident) &&
                     ((((*item_p).data.obj))->o_ident) <
                     (obj_p->o_ident))
                best_p = item_p;
        }
    }
    _attach_after(bag_pp, best_p, new_p);
    return;
}

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


decompiled_code:
_BOOL8 __fastcall baf_decrement_test(__int64 a1, _DWORD **a2)
{
return **a2 > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, _DWORD **a2)
{
return **a2 > 0;
}

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

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

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

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


decompiled_code:
__int64 __fastcall baf_identify(__int64 a1)
{
_QWORD v2[5]; // [rsp+0h] [rbp-28h] BYREF

v2[2] = a1;
whatis(v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
_QWORD v2[5]; // [rsp+0h] [rbp-28h] BYREF

v2[2] = a1;
whatis(v2);
return 1LL;
}

original_code:
int
baf_identify(struct object *obj_p, bag_arg *junk, int id)
{
    linked_list l;
    linked_list *lp = &l;
    (junk += 0);
    (id += 0);
    lp->data.obj = obj_p;
    whatis(lp);
    return(1);
}

canonical_original_code:
int baf_identify(struct object *obj_p, union bag_arg *junk, int id)
{
    struct linked_list l;
    struct linked_list *lp = &l;
    (junk += 0);
    (id += 0);
    lp->data.obj = obj_p;
    whatis(lp);
    return(1);
}

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


decompiled_code:
__int64 __fastcall baf_print_item(__int64 a1, _DWORD **a2, int a3)
{
const char *v4; // rax
const char *v6; // rax
char v7[1560]; // [rsp+0h] [rbp-618h] BYREF

if ( **a2 )
{
v6 = (const char *)inv_name(a1, 1LL);
sprintf(v7, "%c) %s", (unsigned int)*((char *)&print_letters + a3), v6);
}
else
{
v4 = (const char *)inv_name(a1, 1LL);
sprintf(v7, "%c%c) %s", (unsigned int)*(char *)(a1 + 64), (unsigned int)*((char *)&print_letters + a3), v4);
}
add_line(v7);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _DWORD **a2, int a3)
{
const char *v4; // rax
const char *v6; // rax
char v7[1560]; // [rsp+0h] [rbp-618h] BYREF

if ( **a2 )
{
v6 = (const char *)inv_name(a1, 1LL);
sprintf(v7, "%c) %s", (unsigned int)*((char *)&print_letters + a3), v6);
}
else
{
v4 = (const char *)inv_name(a1, 1LL);
sprintf(v7, "%c%c) %s", (unsigned int)*(char *)(a1 + 64), (unsigned int)*((char *)&print_letters + a3), v4);
}
add_line(v7);
return 1LL;
}

original_code:
int
baf_print_item(struct object *obj_p, bag_arg *type, int id)
{
    char inv_temp[3 * 512];
    if (*type->iarg == 0)
        sprintf(inv_temp, "%c%c) %s", obj_p->o_type,
              print_letters[id], inv_name(obj_p, 1), 0);
    else
        sprintf(inv_temp, "%c) %s", print_letters[id],
            inv_name(obj_p, 1), 0);
    add_line(inv_temp);
    return(1);
}

canonical_original_code:
int baf_print_item(struct object *obj_p, union bag_arg *type, int id)
{
    char inv_temp[-1];
    if (*type->iarg == 0)
        sprintf(inv_temp, "%c%c) %s", obj_p->o_type,
              print_letters[id], inv_name(obj_p, 1), 0);
    else
        sprintf(inv_temp, "%c) %s", print_letters[id],
            inv_name(obj_p, 1), 0);
    add_line(inv_temp);
    return(1);
}


original_code:
int
bff_group(struct object *obj_p, bag_arg *arg)
{
    struct object *new_obj_p = arg->obj;
    if (new_obj_p->o_group > 0 && new_obj_p->o_group == obj_p->o_group)
        return(1);
    if (new_obj_p->o_type == ':' &&
        obj_p->o_type == new_obj_p->o_type &&
        obj_p->o_which == new_obj_p->o_which)
        return(1);
    return(0);
}

canonical_original_code:
int bff_group(struct object *obj_p, union bag_arg *arg)
{
    struct object *new_obj_p = arg->obj;
    if (new_obj_p->o_group > 0 && new_obj_p->o_group == obj_p->o_group)
        return(1);
    if (new_obj_p->o_type == ':' &&
        obj_p->o_type == new_obj_p->o_type &&
        obj_p->o_which == new_obj_p->o_which)
        return(1);
    return(0);
}


original_code:
int
bff_callable(struct object *obj_p, bag_arg *junk)
{
    (junk += 0);
    if (obj_p->o_type == '!' || obj_p->o_type == '=' ||
        obj_p->o_type == '/' || obj_p->o_type == '?')
        return(1);
    return(0);
}

canonical_original_code:
int bff_callable(struct object *obj_p, union bag_arg *junk)
{
    (junk += 0);
    if (obj_p->o_type == '!' || obj_p->o_type == '=' ||
        obj_p->o_type == '/' || obj_p->o_type == '?')
        return(1);
    return(0);
}


decompiled_code:
_BOOL8 __fastcall bff_markable(__int64 a1)
{
return *(_BYTE *)(a1 + 64) != 42;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1)
{
return *(_BYTE *)(a1 + 64) != 42;
}

original_code:
int
bff_markable(struct object *obj_p, bag_arg *junk)
{
    (junk += 0);
    if (obj_p->o_type == '*')
        return(0);
    return(1);
}

canonical_original_code:
int bff_markable(struct object *obj_p, union bag_arg *junk)
{
    (junk += 0);
    if (obj_p->o_type == '*')
        return(0);
    return(1);
}


bffron

decompiled_code:
_BOOL8 __fastcall bffron(__int64 a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( cur_ring[0] != a1
&& cur_ring[1] != a1
&& cur_ring[2] != a1
&& cur_ring[3] != a1
&& !cur_ring[4]
&& cur_ring[5] != a1
&& cur_ring[6] != a1
&& cur_ring[7] != a1
&& cur_ring[8] != a1 )
{
result = cur_ring[9] != 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( cur_ring[0] != a1
&& cur_ring[1] != a1
&& cur_ring[2] != a1
&& cur_ring[3] != a1
&& !cur_ring[4]
&& cur_ring[5] != a1
&& cur_ring[6] != a1
&& cur_ring[7] != a1
&& cur_ring[8] != a1 )
{
result = cur_ring[9] != 0LL;
}
return result;
}

original_code:
int
bffron(object *obj_p, bag_arg *junk)
{
    (junk += 0);
    return(cur_ring[0] == obj_p || cur_ring[1] == obj_p ||
        cur_ring[2] == obj_p || cur_ring[3] == obj_p ||
        cur_ring[4] ||
        cur_ring[5] == obj_p || cur_ring[6] == obj_p ||
        cur_ring[7] == obj_p || cur_ring[8] == obj_p ||
        cur_ring[9]);
}

canonical_original_code:
int bffron(struct object *obj_p, union bag_arg *junk)
{
    (junk += 0);
    return(cur_ring[0] == obj_p || cur_ring[1] == obj_p ||
        cur_ring[2] == obj_p || cur_ring[3] == obj_p ||
        cur_ring[4] ||
        cur_ring[5] == obj_p || cur_ring[6] == obj_p ||
        cur_ring[7] == obj_p || cur_ring[8] == obj_p ||
        cur_ring[9]);
}


decompiled_code:
__int64 __fastcall bff_zappable(__int64 a1)
{
char v1; // dl
__int64 result; // rax

v1 = *(_BYTE *)(a1 + 64);
result = 1LL;
if ( v1 != 47 )
{
result = 0LL;
if ( v1 == 41 )
result = (*(_QWORD *)(a1 + 48) >> 6) & 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
char v1; // dl
__int64 result; // rax

v1 = *(_BYTE *)(a1 + 64);
result = 1LL;
if ( v1 != 47 )
{
result = 0LL;
if ( v1 == 41 )
result = (*(_QWORD *)(a1 + 48) >> 6) & 1LL;
}
return result;
}

original_code:
int
bff_zappable(struct object *obj_p, bag_arg *junk)
{
    (junk += 0);
    if (obj_p->o_type == '/')
        return(1);
    if (obj_p->o_type == ')' && obj_p->o_flags & 0x00000040UL)
        return(1);
    return (0);
}

canonical_original_code:
int bff_zappable(struct object *obj_p, union bag_arg *junk)
{
    (junk += 0);
    if (obj_p->o_type == '/')
        return(1);
    if (obj_p->o_type == ')' && obj_p->o_flags & 0x00000040UL)
        return(1);
    return (0);
}


decompiled_code:
__int64 __fastcall baf_curse(__int64 a1)
{
if ( *(_BYTE *)(a1 + 64) == 44 )
return 1LL;
if ( !(unsigned int)rnd(8LL) )
*(_QWORD *)(a1 + 48) = (*(_QWORD *)(a1 + 48) | 1LL) & 0xFFFFFFFFFFFFFFDFLL;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
if ( *(_BYTE *)(a1 + 64) == 44 )
return 1LL;
if ( !(unsigned int)rnd(8LL) )
*(_QWORD *)(a1 + 48) = (*(_QWORD *)(a1 + 48) | 1LL) & 0xFFFFFFFFFFFFFFDFLL;
return 1LL;
}

original_code:
int
baf_curse(struct object *obj_p, bag_arg *junk, int id)
{
    (junk += 0);
    (id += 0);
    if (obj_p->o_type != ',' && rnd(8) == 0)
    {
        obj_p->o_flags |= 0x00000001UL;
        obj_p->o_flags &= ~0x00000020UL;
    }
    return(1);
}

canonical_original_code:
int baf_curse(struct object *obj_p, union bag_arg *junk, int id)
{
    (junk += 0);
    (id += 0);
    if (obj_p->o_type != ',' && rnd(8) == 0)
    {
        obj_p->o_flags |= 0x00000001UL;
        obj_p->o_flags &= ~0x00000020UL;
    }
    return(1);
}


bafcweapon

decompiled_code:
_BOOL8 __fastcall bafcweapon(__int64 a1)
{
return cur_weapon != a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(__int64 a1)
{
return cur_weapon != a1;
}

original_code:
int
bafcweapon(struct object *obj_p, bag_arg *junk, int id)
{
    (junk += 0);
    (id += 0);
    if (obj_p == cur_weapon)
        return(0);
    return(1);
}

canonical_original_code:
int bafcweapon(struct object *obj_p, union bag_arg *junk, int id)
{
    (junk += 0);
    (id += 0);
    if (obj_p == cur_weapon)
        return(0);
    return(1);
}


bafcarmor

decompiled_code:
_BOOL8 __fastcall bafcarmor(__int64 a1)
{
return cur_armor != a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(__int64 a1)
{
return cur_armor != a1;
}

original_code:
int
bafcarmor(struct object *obj_p, bag_arg *junk, int id)
{
    (junk += 0);
    (id += 0);
    if (obj_p == cur_armor)
        return(0);
    return(1);
}

canonical_original_code:
int bafcarmor(struct object *obj_p, union bag_arg *junk, int id)
{
    (junk += 0);
    (id += 0);
    if (obj_p == cur_armor)
        return(0);
    return(1);
}


decompiled_code:
__int64 take_off()
{
__int64 v0; // rbx
__int64 result; // rax
const char *v2; // rbp
int v3; // eax

v0 = cur_armor;
if ( !cur_armor )
return msg("You aren't wearing armor!");
result = dropcheck(cur_armor);
if ( (_DWORD)result )
{
v2 = (const char *)inv_name(v0, 1LL);
v3 = get_ident(v0);
result = msg("You were wearing %c%c) %s.", 93LL, (unsigned int)*((char *)&print_letters + v3), v2);
cur_armor = 0LL;
if ( (*((_BYTE *)&player + 242) & 1) != 0 )
{
result = msg("Your foot feels a lot better now.");
*((_QWORD *)&player + 30) &= 0xFFFFFFFFFFFEFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
__int64 result; // rax
const char *v2; // rbp
int v3; // eax

v0 = cur_armor;
if ( !cur_armor )
return msg("You aren't wearing armor!");
result = dropcheck(cur_armor);
if ( (_DWORD)result )
{
v2 = (const char *)inv_name(v0, 1LL);
v3 = get_ident(v0);
result = msg("You were wearing %c%c) %s.", 93LL, (unsigned int)*((char *)&print_letters + v3), v2);
cur_armor = 0LL;
if ( (*((_BYTE *)&player + 242) & 1) != 0 )
{
result = msg("Your foot feels a lot better now.");
*((_QWORD *)&player + 30) &= 0xFFFFFFFFFFFEFFFFLL;
}
}
return result;
}

original_code:
void
take_off(void)
{
    struct object *obj;
    if ((obj = cur_armor) == ((void *)0))
    {
        msg("You aren't wearing armor!");
        return;
    }
    if (!dropcheck(cur_armor))
        return;
    msg("You were wearing %c%c) %s.", ']', print_letters[get_ident(obj)],
        inv_name(obj, 1));
    cur_armor = ((void *)0);
    if (((player).t_flags[(0x30010000UL >> 28UL) & 0x0000000fL] & (0x30010000UL & 0x0fffffffL)))
    {
        msg("Your foot feels a lot better now.");
        ( (player).t_flags[(0x30010000UL >> 28UL) & 0x0000000fL] &= ~(0x30010000UL & 0x0fffffffL));
    }
}

canonical_original_code:
void take_off()
{
    struct object *obj;
    if ((obj = cur_armor) == ((void *)0))
    {
        msg("You aren't wearing armor!");
        return;
    }
    if (!dropcheck(cur_armor))
        return;
    msg("You were wearing %c%c) %s.", ']', print_letters[get_ident(obj)],
        inv_name(obj, 1));
    cur_armor = ((void *)0);
    if (((player).t_flags[(0x30010000UL >> 28UL) & 0x0000000fL] & (0x30010000UL & 0x0fffffffL)))
    {
        msg("Your foot feels a lot better now.");
        ( (player).t_flags[(0x30010000UL >> 28UL) & 0x0000000fL] &= ~(0x30010000UL & 0x0fffffffL));
    }
}


decompiled_code:
__int64 __fastcall wear_ok(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
int v4; // ecx
__int64 v5; // rsi

result = 0LL;
if ( *(_BYTE *)(a2 + 64) == 93 )
{
v4 = *(_DWORD *)(a2 + 76);
v5 = *(unsigned int *)(a1 + 360);
switch ( (int)v5 )
{
case 0:
case 2:
case 10:
result = 1LL;
goto LABEL_9;
case 1:
if ( (unsigned int)v4 > 8 )
{
result = (unsigned int)v5;
}
else if ( ((1LL << v4) & 0x157) != 0 )
{
if ( a3 == 1 )
goto LABEL_26;
result = 0LL;
}
else
{
result = (unsigned int)v5;
}
break;
case 3:
case 4:
result = 1LL;
goto LABEL_19;
case 5:
case 6:
if ( (unsigned int)v4 > 0xD )
result = 1LL;
else
result = ((1LL << v4) & 0x3BE8) == 0;
goto LABEL_6;
case 7:
case 8:
case 9:
result = 1LL;
LABEL_6:
if ( v4 > 9 )
{
if ( (unsigned int)(v4 - 11) <= 2 )
result = 0LL;
LABEL_19:
if ( (unsigned int)(v4 - 12) <= 2 )
result = 0LL;
}
else if ( v4 >= 7 )
{
result = 0LL;
}
LABEL_9:
if ( (_DWORD)result || a3 != 1 )
return result;
if ( (int)v5 > 6 )
{
result = 0LL;
if ( (unsigned int)(v5 - 7) <= 2 )
{
msg("Don't expect to be stealthy while wearing that!");
result = 0LL;
}
}
else if ( (int)v5 > 4 )
{
msg("You cannot regenerate spell points while wearing that!");
result = 0LL;
}
else if ( (_DWORD)v5 == 1 || (unsigned int)(v5 - 3) <= 1 )
{
LABEL_26:
msg("Your god strongly disapproves of your wearing that!");
result = 0LL;
}
break;
default:
if ( wizard && wiz_verbose )
msg("Unknown class %d.", v5);
return 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
__int64 result; // rax
int v4; // ecx
__int64 v5; // rsi

result = 0LL;
if ( *(_BYTE *)(a2 + 64) == 93 )
{
v4 = *(_DWORD *)(a2 + 76);
v5 = *(unsigned int *)(a1 + 360);
switch ( (int)v5 )
{
case 0:
case 2:
case 10:
result = 1LL;
goto LABEL_9;
case 1:
if ( (unsigned int)v4 > 8 )
{
result = (unsigned int)v5;
}
else if ( ((1LL << v4) & 0x157) != 0 )
{
if ( a3 == 1 )
goto LABEL_26;
result = 0LL;
}
else
{
result = (unsigned int)v5;
}
break;
case 3:
case 4:
result = 1LL;
goto LABEL_19;
case 5:
case 6:
if ( (unsigned int)v4 > 0xD )
result = 1LL;
else
result = ((1LL << v4) & 0x3BE8) == 0;
goto LABEL_6;
case 7:
case 8:
case 9:
result = 1LL;
LABEL_6:
if ( v4 > 9 )
{
if ( (unsigned int)(v4 - 11) <= 2 )
result = 0LL;
LABEL_19:
if ( (unsigned int)(v4 - 12) <= 2 )
result = 0LL;
}
else if ( v4 >= 7 )
{
result = 0LL;
}
LABEL_9:
if ( (_DWORD)result || a3 != 1 )
return result;
if ( (int)v5 > 6 )
{
result = 0LL;
if ( (unsigned int)(v5 - 7) <= 2 )
{
msg("Don't expect to be stealthy while wearing that!");
result = 0LL;
}
}
else if ( (int)v5 > 4 )
{
msg("You cannot regenerate spell points while wearing that!");
result = 0LL;
}
else if ( (_DWORD)v5 == 1 || (unsigned int)(v5 - 3) <= 1 )
{
LABEL_26:
msg("Your god strongly disapproves of your wearing that!");
result = 0LL;
}
break;
default:
if ( wizard && wiz_verbose )
msg("Unknown class %d.", v5);
return 1LL;
}
}
return result;
}

original_code:
int
wear_ok(struct thing *wearee, struct object *obj, int print_message)
{
    int which = obj->o_which;
    int ret_val = 1;
    int class_type = wearee->t_ctype;
    if (obj->o_type != ']')
        return(0);
    else
        switch (class_type)
        {
            case 5:
            case 6:
                switch (which)
                {
                    case 3:
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    case 9:
                    case 11:
                    case 12:
                    case 13:
                        ret_val = 0;
                        break;
                    default:
                        break;
                }
            case 7:
            case 8:
            case 9:
                switch (which)
                {
                    case 7:
                    case 8:
                    case 9:
                    case 11:
                    case 12:
                    case 13:
                        ret_val = 0;
                        break;
                    default:
                        break;
                }
            case 3:
            case 4:
                switch (which)
                {
                    case 12:
                    case 13:
                    case 14:
                        ret_val = 0;
                        break;
                    default:
                        break;
                }
            case 0:
            case 2:
                break;
            case 1:
                switch (which)
                {
                    case 0:
                    case 1:
                    case 2:
                    case 4:
                    case 6:
                    case 8:
                        ret_val = 0;
                        break;
                    default:
                        break;
                }
            case 10:
                break;
            default:
                if (wizard && wiz_verbose) msg("Unknown class %d.", class_type);
                break;
        }
    if (ret_val == 0 && print_message == 1)
        switch (class_type)
        {
            case 5:
            case 6:
                msg("You cannot regenerate spell points while wearing that!");
                break;
            case 7:
            case 8:
            case 9:
                msg("Don't expect to be stealthy while wearing that!");
                break;
            case 3:
            case 4:
            case 1:
                msg("Your god strongly disapproves of your wearing that!");
                break;
            case 0:
            case 2:
            case 10:
                break;
        }
    return(ret_val);
}

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:
obj
struct object *

variable_types: which int


wear

decompiled_code:
__int64 wear()
{
__int64 result; // rax
__int64 v1; // rbx
const char *v2; // rax

if ( cur_armor )
{
result = msg("You are already wearing some.");
after = 0;
}
else
{
result = get_object(player[2], "wear", 93LL, 0LL);
v1 = result;
if ( result )
{
wear_ok((__int64)player, result, 1);
waste_time();
cur_armor = v1;
*(_QWORD *)(v1 + 48) |= 2uLL;
v2 = (const char *)inv_name(v1, 1LL);
result = msg("You are now wearing %s.", v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
__int64 v1; // rbx
const char *v2; // rax

if ( cur_armor )
{
result = msg("You are already wearing some.");
after = 0;
}
else
{
result = get_object(player[2], "wear", 93LL, 0LL);
v1 = result;
if ( result )
{
func1((__int64)player, result, 1);
waste_time();
cur_armor = v1;
*(_QWORD *)(v1 + 48) |= 2uLL;
v2 = (const char *)inv_name(v1, 1LL);
result = msg("You are now wearing %s.", v2);
}
}
return result;
}

original_code:
void
wear(void)
{
    struct object *obj;
    if (cur_armor != ((void *)0))
    {
        msg("You are already wearing some.");
        after = 0;
        return;
    }
    if ((obj = get_object(player.t_pack, "wear", ']', ((void *)0))) == ((void *)0))
        return;
    wear_ok(&player, obj, 1);
    waste_time();
    cur_armor = obj;
    obj->o_flags |= 0x00000002UL;
    msg("You are now wearing %s.", inv_name(obj, 1));
    return;
}

canonical_original_code:
void wear()
{
    struct object *obj;
    if (cur_armor != ((void *)0))
    {
        msg("You are already wearing some.");
        after = 0;
        return;
    }
    if ((obj = get_object(player.t_pack, "wear", ']', ((void *)0))) == ((void *)0))
        return;
    wear_ok(&player, obj, 1);
    waste_time();
    cur_armor = obj;
    obj->o_flags |= 0x00000002UL;
    msg("You are now wearing %s.", inv_name(obj, 1));
    return;
}


door

decompiled_code:
__int64 __fastcall door(__int64 a1, int *a2)
{
char v3; // si
__int64 result; // rax

wmove(stdscr, a2[1], *a2);
v3 = 43;
if ( (int)rnd(10LL) < level - 1 )
v3 = 5 * ((int)rnd(100LL) > 19) + 38;
waddch(stdscr, (unsigned int)v3);
LODWORD(result) = *(_DWORD *)(a1 + 52);
*(_DWORD *)(a1 + 52) = result + 1;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result + 16) = *(_QWORD *)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2)
{
char v3; // si
__int64 result; // rax

wmove(stdscr, a2[1], *a2);
v3 = 43;
if ( (int)rnd(10LL) < level - 1 )
v3 = 5 * ((int)rnd(100LL) > 19) + 38;
waddch(stdscr, (unsigned int)v3);
LODWORD(result) = *(_DWORD *)(a1 + 52);
*(_DWORD *)(a1 + 52) = result + 1;
result = (int)result;
*(_QWORD *)(a1 + 8LL * (int)result + 16) = *(_QWORD *)a2;
return result;
}

original_code:
void
door(struct room *rm, coord *cp)
{
    char a_door;
    wmove(stdscr,((*cp).y),((*cp).x));
    a_door = (rnd(10)<level - 1 && rnd(100) < 20) ? '&' : '+';
    waddch(stdscr,(a_door));
    rm->r_exit[rm->r_nexits++] = *cp;
}

canonical_original_code:
void door(struct room *rm, struct coord *cp)
{
    char a_door;
    wmove(stdscr,((*cp).y),((*cp).x));
    a_door = (rnd(10)<level - 1 && rnd(100) < 20) ? '&' : '+';
    waddch(stdscr,(a_door));
    rm->r_exit[rm->r_nexits++] = *cp;
}

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:
cp
struct coord *

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


conn

original_code:
void
conn(int r1, int r2)
{
    struct room *rpf, *rpt = ((void *)0);
    int rmt;
    int distance = 0, turn_spot = 0, turn_distance = 0;
    int rm;
    char direc;
    coord delt = {0,0}, curr, turn_delta = {0,0}, spos = {0,0}, epos = {0,0};
    if (r1 < r2)
    {
        rm = r1;
        if (r1 + 1 == r2)
            direc = 'r';
        else
            direc = 'd';
    }
    else
    {
        rm = r2;
        if (r2 + 1 == r1)
            direc = 'r';
        else
            direc = 'd';
    }
    rpf = &rooms[rm];
    if (direc == 'd')
    {
        rmt = rm + 3;
        rpt = &rooms[rmt];
        delt.x = 0;
        delt.y = 1;
        spos.x = rpf->r_pos.x;
        spos.y = rpf->r_pos.y;
        epos.x = rpt->r_pos.x;
        epos.y = rpt->r_pos.y;
        if (!(rpf->r_flags & 0x00000002UL))
        {
            spos.x += rnd(rpf->r_max.x - 2) + 1;
            spos.y += rpf->r_max.y - 1;
        }
        if (!(rpt->r_flags & 0x00000002UL))
            epos.x += rnd(rpt->r_max.x - 2) + 1;
        distance = abs(spos.y - epos.y) - 1;
        turn_delta.y = 0;
        turn_delta.x = (spos.x < epos.x ? 1 : -1);
        turn_distance = abs(spos.x - epos.x);
        turn_spot = rnd(distance - 1) + 1;
    }
    else if (direc == 'r')
    {
        rmt = rm + 1;
        rpt = &rooms[rmt];
        delt.x = 1;
        delt.y = 0;
        spos.x = rpf->r_pos.x;
        spos.y = rpf->r_pos.y;
        epos.x = rpt->r_pos.x;
        epos.y = rpt->r_pos.y;
        if (!(rpf->r_flags & 0x00000002UL))
        {
            spos.x += rpf->r_max.x - 1;
            spos.y += rnd(rpf->r_max.y - 2) + 1;
        }
        if (!(rpt->r_flags & 0x00000002UL))
            epos.y += rnd(rpt->r_max.y - 2) + 1;
        distance = abs(spos.x - epos.x) - 1;
        turn_delta.y = (spos.y < epos.y ? 1 : -1);
        turn_delta.x = 0;
        turn_distance = abs(spos.y - epos.y);
        turn_spot = rnd(distance - 1) + 1;
    }
    else
        if (wizard && wiz_verbose) msg("Error in connection tables.");
    if (!(rpf->r_flags & 0x00000002UL))
        door(rpf, &spos);
    else
    {
        wmove(stdscr,((spos).y),((spos).x));
        waddch(stdscr,('#'));
    }
    if (!(rpt->r_flags & 0x00000002UL))
        door(rpt, &epos);
    else
    {
        wmove(stdscr,((epos).y),((epos).x));
        waddch(stdscr,('#'));
    }
    curr.x = spos.x;
    curr.y = spos.y;
    while (distance)
    {
        curr.x += delt.x;
        curr.y += delt.y;
        if (distance == turn_spot && turn_distance > 0)
            while (turn_distance--)
            {
                wmove(stdscr,((curr).y),((curr).x));
                waddch(stdscr,('#'));
                curr.x += turn_delta.x;
                curr.y += turn_delta.y;
            }
        wmove(stdscr,((curr).y),((curr).x));
        waddch(stdscr,('#'));
        distance--;
    }
    curr.x += delt.x;
    curr.y += delt.y;
    if (!((curr).x == (epos).x && (curr).y == (epos).y))
        msg("Warning, connectivity problem on this level.");
}

canonical_original_code:
void conn(int r1, int r2)
{
    struct room *rpf; struct room *rpt = ((void *)0);
    int rmt;
    int distance = 0; int turn_spot = 0; int turn_distance = 0;
    int rm;
    char direc;
    struct coord delt = {0,0}; struct coord curr; struct coord turn_delta = {0,0}; struct coord spos = {0,0}; struct coord epos = {0,0};
    if (r1 < r2)
    {
        rm = r1;
        if (r1 + 1 == r2)
            direc = 'r';
        else
            direc = 'd';
    }
    else
    {
        rm = r2;
        if (r2 + 1 == r1)
            direc = 'r';
        else
            direc = 'd';
    }
    rpf = &rooms[rm];
    if (direc == 'd')
    {
        rmt = rm + 3;
        rpt = &rooms[rmt];
        delt.x = 0;
        delt.y = 1;
        spos.x = rpf->r_pos.x;
        spos.y = rpf->r_pos.y;
        epos.x = rpt->r_pos.x;
        epos.y = rpt->r_pos.y;
        if (!(rpf->r_flags & 0x00000002UL))
        {
            spos.x += rnd(rpf->r_max.x - 2) + 1;
            spos.y += rpf->r_max.y - 1;
        }
        if (!(rpt->r_flags & 0x00000002UL))
            epos.x += rnd(rpt->r_max.x - 2) + 1;
        distance = abs(spos.y - epos.y) - 1;
        turn_delta.y = 0;
        turn_delta.x = (spos.x < epos.x ? 1 : -1);
        turn_distance = abs(spos.x - epos.x);
        turn_spot = rnd(distance - 1) + 1;
    }
    else if (direc == 'r')
    {
        rmt = rm + 1;
        rpt = &rooms[rmt];
        delt.x = 1;
        delt.y = 0;
        spos.x = rpf->r_pos.x;
        spos.y = rpf->r_pos.y;
        epos.x = rpt->r_pos.x;
        epos.y = rpt->r_pos.y;
        if (!(rpf->r_flags & 0x00000002UL))
        {
            spos.x += rpf->r_max.x - 1;
            spos.y += rnd(rpf->r_max.y - 2) + 1;
        }
        if (!(rpt->r_flags & 0x00000002UL))
            epos.y += rnd(rpt->r_max.y - 2) + 1;
        distance = abs(spos.x - epos.x) - 1;
        turn_delta.y = (spos.y < epos.y ? 1 : -1);
        turn_delta.x = 0;
        turn_distance = abs(spos.y - epos.y);
        turn_spot = rnd(distance - 1) + 1;
    }
    else
        if (wizard && wiz_verbose) msg("Error in connection tables.");
    if (!(rpf->r_flags & 0x00000002UL))
        door(rpf, &spos);
    else
    {
        wmove(stdscr,((spos).y),((spos).x));
        waddch(stdscr,('#'));
    }
    if (!(rpt->r_flags & 0x00000002UL))
        door(rpt, &epos);
    else
    {
        wmove(stdscr,((epos).y),((epos).x));
        waddch(stdscr,('#'));
    }
    curr.x = spos.x;
    curr.y = spos.y;
    while (distance)
    {
        curr.x += delt.x;
        curr.y += delt.y;
        if (distance == turn_spot && turn_distance > 0)
            while (turn_distance--)
            {
                wmove(stdscr,((curr).y),((curr).x));
                waddch(stdscr,('#'));
                curr.x += turn_delta.x;
                curr.y += turn_delta.y;
            }
        wmove(stdscr,((curr).y),((curr).x));
        waddch(stdscr,('#'));
        distance--;
    }
    curr.x += delt.x;
    curr.y += delt.y;
    if (!((curr).x == (epos).x && (curr).y == (epos).y))
        msg("Warning, connectivity problem on this level.");
}

variable_types: rmt int

variable_types: distance int

variable_types: rm int

variable_types: direc char

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

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

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

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


variable_types: struct rdes { int conn[9]; int isconn[9]; int ingraph; } *

variable_types: i int

variable_types: j int

variable_types: roomcount int

variable_types: struct rdes { int conn[9]; int isconn[9]; int ingraph; } [9]


doadd

decompiled_code:
size_t __fastcall doadd(char *format, __gnuc_va_list arg)
{
size_t result; // rax

vsprintf(&mbuf[newpos], format, arg);
result = strlen(mbuf);
newpos = result;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *format, __gnuc_va_list arg)
{
size_t result; // rax

vsprintf(&mbuf[newpos], format, arg);
result = strlen(mbuf);
newpos = result;
return result;
}

original_code:
void
doadd(const char *fmt, va_list ap)
{
    vsprintf(&mbuf[newpos], fmt, ap);
    newpos = (int) strlen(mbuf);
}

canonical_original_code:
void doadd(char *fmt, __builtin_va_list ap)
{
    vsprintf(&mbuf[newpos], fmt, ap);
    newpos = (int) strlen(mbuf);
}

variable_types:
fmt
char *


addmsg

decompiled_code:
size_t addmsg(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return doadd(a1, arg);
}

canonical_decompiled_code:
size_t func1(char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
return func0(a1, arg);
}

original_code:
void
addmsg(const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    doadd(fmt,ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void addmsg(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    doadd(fmt,ap);
    __builtin_va_end(ap);
}


status

decompiled_code:
int __fastcall status(int a1)
{
int v1; // er12
int v2; // er13
__int64 v3; // rbp
int v4; // eax
const char *v5; // r15
__int64 v6; // r14
int v7; // ebx
int v8; // eax
int result; // eax

if ( cw )
{
v1 = cw->_cury;
v2 = cw->_curx;
}
else
{
v1 = -1;
v2 = -1;
}
sprintf(
buf_1,
"Int:%d(%d) Str:%d(%d) Wis:%d(%d) Dex:%d(%d) Con:%d(%d) Carry:%d(%d) %d",
*((unsigned int *)&player + 19),
*((unsigned int *)&player + 37),
*((unsigned int *)&player + 18),
*((unsigned int *)&player + 36),
*((unsigned int *)&player + 20),
*((unsigned int *)&player + 38),
*((unsigned int *)&player + 21),
*((unsigned int *)&player + 39),
*((unsigned int *)&player + 22),
*((unsigned int *)&player + 40),
(unsigned int)(*((_DWORD *)&player + 12) / 10),
(unsigned int)(*((_DWORD *)&player + 13) / 10),
foodlev);
if ( wmove(cw, LINES - 2, 0) != -1 )
waddnstr(cw, buf_1, -1);
wclrtoeol(cw);
v3 = *((unsigned int *)&player + 14);
v4 = 15;
if ( (int)v3 <= 15 )
v4 = *((_DWORD *)&player + 14);
v5 = (const char *)cnames[15 * *((int *)&player + 90) - 1 + v4];
v6 = *((_QWORD *)&player + 4);
v7 = *((_DWORD *)&player + 15);
if ( cur_armor )
v7 = *(_DWORD *)(cur_armor + 88LL) + v7 - 10;
v8 = ring_value(0LL);
sprintf(
buf_1,
"Lvl:%d Au:%d Hpt:%3d(%3d) Pow:%d(%d) Ac:%d Exp:%d+%ld %s",
level,
purse,
*((_QWORD *)&player + 5),
*((_QWORD *)&player + 14),
*((unsigned int *)&player + 17),
*((unsigned int *)&player + 35),
(unsigned int)(v7 - v8),
v3,
v6,
v5);
if ( wmove(cw, LINES - 1, 0) != -1 )
waddnstr(cw, buf_1, -1);
switch ( hungry_state )
{
case 2:
waddnstr(cw, " Weak", -1);
break;
case 3:
waddnstr(cw, " Fainting", -1);
break;
case 1:
waddnstr(cw, " Hungry", -1);
break;
}
wclrtoeol(cw);
result = wmove(cw, v1, v2);
if ( a1 )
result = wrefresh(cw);
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
int v1; // er12
int v2; // er13
__int64 v3; // rbp
int v4; // eax
const char *v5; // r15
__int64 v6; // r14
int v7; // ebx
int v8; // eax
int result; // eax

if ( cw )
{
v1 = cw->_cury;
v2 = cw->_curx;
}
else
{
v1 = -1;
v2 = -1;
}
sprintf(
buf_1,
"Int:%d(%d) Str:%d(%d) Wis:%d(%d) Dex:%d(%d) Con:%d(%d) Carry:%d(%d) %d",
*((unsigned int *)&player + 19),
*((unsigned int *)&player + 37),
*((unsigned int *)&player + 18),
*((unsigned int *)&player + 36),
*((unsigned int *)&player + 20),
*((unsigned int *)&player + 38),
*((unsigned int *)&player + 21),
*((unsigned int *)&player + 39),
*((unsigned int *)&player + 22),
*((unsigned int *)&player + 40),
(unsigned int)(*((_DWORD *)&player + 12) / 10),
(unsigned int)(*((_DWORD *)&player + 13) / 10),
foodlev);
if ( wmove(cw, LINES - 2, 0) != -1 )
waddnstr(cw, buf_1, -1);
wclrtoeol(cw);
v3 = *((unsigned int *)&player + 14);
v4 = 15;
if ( (int)v3 <= 15 )
v4 = *((_DWORD *)&player + 14);
v5 = (const char *)cnames[15 * *((int *)&player + 90) - 1 + v4];
v6 = *((_QWORD *)&player + 4);
v7 = *((_DWORD *)&player + 15);
if ( cur_armor )
v7 = *(_DWORD *)(cur_armor + 88LL) + v7 - 10;
v8 = ring_value(0LL);
sprintf(
buf_1,
"Lvl:%d Au:%d Hpt:%3d(%3d) Pow:%d(%d) Ac:%d Exp:%d+%ld %s",
level,
purse,
*((_QWORD *)&player + 5),
*((_QWORD *)&player + 14),
*((unsigned int *)&player + 17),
*((unsigned int *)&player + 35),
(unsigned int)(v7 - v8),
v3,
v6,
v5);
if ( wmove(cw, LINES - 1, 0) != -1 )
waddnstr(cw, buf_1, -1);
switch ( hungry_state )
{
case 2:
waddnstr(cw, " Weak", -1);
break;
case 3:
waddnstr(cw, " Fainting", -1);
break;
case 1:
waddnstr(cw, " Hungry", -1);
break;
}
wclrtoeol(cw);
result = wmove(cw, v1, v2);
if ( a1 )
result = wrefresh(cw);
return result;
}

original_code:
void
status(int display)
{
    static char buf[1024];
    struct stats *stat_ptr, *max_ptr;
    int oy, ox;
    stat_ptr = &player.t_stats;
    max_ptr = &player.maxstats;
    (oy = ((0 != (const void *)((cw))) ? (cw)->_cury : (-1)), ox = ((0 != (const void *)((cw))) ? (cw)->_curx : (-1)));
    sprintf(buf,
    "Int:%d(%d) Str:%d(%d) Wis:%d(%d) Dex:%d(%d) Con:%d(%d) Carry:%d(%d) %d",
        stat_ptr->s_intel, max_ptr->s_intel,
        stat_ptr->s_str, max_ptr->s_str,
        stat_ptr->s_wisdom, max_ptr->s_wisdom,
        stat_ptr->s_dext, max_ptr->s_dext,
        stat_ptr->s_const, max_ptr->s_const,
        stat_ptr->s_pack / 10, stat_ptr->s_carry / 10, foodlev );
    (wmove((cw),(LINES - 2),(0)) == (-1) ? (-1) : waddnstr((cw),(buf),-1));
    wclrtoeol(cw);
    sprintf(buf, "Lvl:%d Au:%d Hpt:%3d(%3d) Pow:%d(%d) Ac:%d  Exp:%d+%ld  %s",
        level,
        purse,
        stat_ptr->s_hpt, max_ptr->s_hpt,
        stat_ptr->s_power, max_ptr->s_power,
        (cur_armor != ((void *)0) ? (cur_armor->o_ac - 10 + stat_ptr->s_arm)
         : stat_ptr->s_arm) - ring_value(0),
        stat_ptr->s_lvl,
        stat_ptr->s_exp,
        cnames[player.t_ctype][((stat_ptr->s_lvl - 1) < (14) ? (stat_ptr->s_lvl - 1) : (14))]);
    (wmove((cw),(LINES - 1),(0)) == (-1) ? (-1) : waddnstr((cw),(buf),-1));
    switch(hungry_state)
    {
        case 0: break;
        case 1: waddnstr(cw," Hungry",-1);
                       break;
        case 2: waddnstr(cw," Weak",-1);
                       break;
        case 3: waddnstr(cw," Fainting",-1);
                       break;
    }
    wclrtoeol(cw);
    wmove(cw, oy, ox);
    if (display)
        wrefresh(cw);
}

canonical_original_code:
void status(int display)
{
    static char buf[1024];
    struct stats *stat_ptr; struct stats *max_ptr;
    int oy; int ox;
    stat_ptr = &player.t_stats;
    max_ptr = &player.maxstats;
    (oy = ((0 != (void *)((cw))) ? (cw)->_cury : (-1)), ox = ((0 != (void *)((cw))) ? (cw)->_curx : (-1)));
    sprintf(buf,
    "Int:%d(%d) Str:%d(%d) Wis:%d(%d) Dex:%d(%d) Con:%d(%d) Carry:%d(%d) %d",
        stat_ptr->s_intel, max_ptr->s_intel,
        stat_ptr->s_str, max_ptr->s_str,
        stat_ptr->s_wisdom, max_ptr->s_wisdom,
        stat_ptr->s_dext, max_ptr->s_dext,
        stat_ptr->s_const, max_ptr->s_const,
        stat_ptr->s_pack / 10, stat_ptr->s_carry / 10, foodlev );
    (wmove((cw),(LINES - 2),(0)) == (-1) ? (-1) : waddnstr((cw),(buf),-1));
    wclrtoeol(cw);
    sprintf(buf, "Lvl:%d Au:%d Hpt:%3d(%3d) Pow:%d(%d) Ac:%d  Exp:%d+%ld  %s",
        level,
        purse,
        stat_ptr->s_hpt, max_ptr->s_hpt,
        stat_ptr->s_power, max_ptr->s_power,
        (cur_armor != ((void *)0) ? (cur_armor->o_ac - 10 + stat_ptr->s_arm)
         : stat_ptr->s_arm) - ring_value(0),
        stat_ptr->s_lvl,
        stat_ptr->s_exp,
        cnames[player.t_ctype][((stat_ptr->s_lvl - 1) < (14) ? (stat_ptr->s_lvl - 1) : (14))]);
    (wmove((cw),(LINES - 1),(0)) == (-1) ? (-1) : waddnstr((cw),(buf),-1));
    switch(hungry_state)
    {
        case 0: break;
        case 1: waddnstr(cw," Hungry",-1);
                       break;
        case 2: waddnstr(cw," Weak",-1);
                       break;
        case 3: waddnstr(cw," Fainting",-1);
                       break;
    }
    wclrtoeol(cw);
    wmove(cw, oy, ox);
    if (display)
        wrefresh(cw);
}

variable_types: display int

variable_types:
buf
char [1024]

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

variable_types: oy int

variable_types: ox int


readchar

decompiled_code:
__int64 __fastcall readchar(__int64 a1, __int64 a2)
{
return readcharw((__int64)cw, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return func3((__int64)cw, a2);
}

original_code:
char
readchar()
{
    return( readcharw(cw) );
}

return_type: char


decompiled_code:
__int64 __fastcall wait_for(unsigned int a1)
{
return w_wait_for((__int64)cw, a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
return func5((__int64)cw, a1);
}

original_code:
void
wait_for(int ch)
{
    w_wait_for(cw, ch);
}

variable_types: ch int


endmsg

decompiled_code:
int endmsg()
{
int v0; // ebx

v0 = msg_index;
strcpy(&msgbuf[1024 * (__int64)msg_index], mbuf);
msg_index = (v0 + 1) % 10;
if ( mpos )
{
wmove(cw, 0, mpos);
wprintw(cw, morestr);
wrefresh(cw);
wait_for(0x20u);
}
mvwprintw(cw, 0, 0, mbuf);
wclrtoeol(cw);
mpos = newpos;
newpos = 0;
return wrefresh(cw);
}

canonical_decompiled_code:
int func7()
{
int v0; // ebx

v0 = msg_index;
strcpy(&msgbuf[1024 * (__int64)msg_index], mbuf);
msg_index = (v0 + 1) % 10;
if ( mpos )
{
wmove(cw, 0, mpos);
wprintw(cw, morestr);
wrefresh(cw);
func6(0x20u);
}
mvwprintw(cw, 0, 0, mbuf);
wclrtoeol(cw);
mpos = newpos;
newpos = 0;
return wrefresh(cw);
}

original_code:
void
endmsg(void)
{
    strcpy(msgbuf[msg_index], mbuf);
    msg_index = ++msg_index % 10;
    if (mpos)
    {
        wmove(cw, 0, mpos);
        wprintw(cw, (char *) morestr);
        wrefresh(cw);
        wait_for(' ');
    }
    mvwprintw(cw, 0, 0, mbuf);
    wclrtoeol(cw);
    mpos = newpos;
    newpos = 0;
    wrefresh(cw);
}

canonical_original_code:
void endmsg()
{
    strcpy(msgbuf[msg_index], mbuf);
    msg_index = ++msg_index % 10;
    if (mpos)
    {
        wmove(cw, 0, mpos);
        wprintw(cw, (char *) morestr);
        wrefresh(cw);
        wait_for(' ');
    }
    mvwprintw(cw, 0, 0, mbuf);
    wclrtoeol(cw);
    mpos = newpos;
    newpos = 0;
    wrefresh(cw);
}


msg

decompiled_code:
int msg(char *a1, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( *a1 )
{
va_start(arg, a1);
doadd(a1, arg);
result = endmsg();
}
else
{
wmove(cw, 0, 0);
result = wclrtoeol(cw);
mpos = 0;
}
return result;
}

canonical_decompiled_code:
int func8(char *a1, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( *a1 )
{
va_start(arg, a1);
func0(a1, arg);
result = func7();
}
else
{
wmove(cw, 0, 0);
result = wclrtoeol(cw);
mpos = 0;
}
return result;
}

original_code:
void
msg(const char *fmt, ...)
{
    va_list ap;
    if (*fmt == '\0')
    {
        wmove(cw, 0, 0);
        wclrtoeol(cw);
        mpos = 0;
        return;
    }
    __builtin_va_start(ap,fmt);
    doadd(fmt, ap);
    __builtin_va_end(ap);
    endmsg();
}

canonical_original_code:
void msg(char *fmt, ...)
{
    __builtin_va_list ap;
    if (*fmt == '\0')
    {
        wmove(cw, 0, 0);
        wclrtoeol(cw);
        mpos = 0;
        return;
    }
    __builtin_va_start(ap,fmt);
    doadd(fmt, ap);
    __builtin_va_end(ap);
    endmsg();
}


vmsg

decompiled_code:
int __fastcall vmsg(char *a1, void *a2)
{
int result; // eax

if ( *a1 )
{
doadd(a1, a2);
result = endmsg();
}
else
{
wmove(cw, 0, 0);
result = wclrtoeol(cw);
mpos = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *a1, void *a2)
{
int result; // eax

if ( *a1 )
{
func0(a1, a2);
result = func7();
}
else
{
wmove(cw, 0, 0);
result = wclrtoeol(cw);
mpos = 0;
}
return result;
}

original_code:
void
vmsg(const char *fmt, va_list ap)
{
    if (*fmt == '\0')
    {
        wmove(cw, 0, 0);
        wclrtoeol(cw);
        mpos = 0;
        return;
    }
    doadd(fmt, ap);
    endmsg();
}

canonical_original_code:
void vmsg(char *fmt, __builtin_va_list ap)
{
    if (*fmt == '\0')
    {
        wmove(cw, 0, 0);
        wclrtoeol(cw);
        mpos = 0;
        return;
    }
    doadd(fmt, ap);
    endmsg();
}


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

if ( inv_type )
result = add_line(0LL);
line_cnt = 0;
newpage = 0;
return result;
}

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

if ( inv_type )
result = func12(0LL);
line_cnt = 0;
newpage = 0;
return result;
}

original_code:
void
end_line(void)
{
    if (inv_type != 0)
        add_line(((void *)0));
    line_cnt = 0;
    newpage = 0;
}

canonical_original_code:
void end_line()
{
    if (inv_type != 0)
        add_line(((void *)0));
    line_cnt = 0;
    newpage = 0;
}


hearmsg

decompiled_code:
int hearmsg(char *a1, ...)
{
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
result = (int)va[0].reg_save_area;
if ( (player[56] & 0x2000000) == 0 )
return vmsg(a1, va);
if ( wizard )
{
msg("Couldn't hear: ");
result = vmsg(a1, va);
}
return result;
}

canonical_decompiled_code:
int func14(char *a1, ...)
{
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
result = (int)va[0].reg_save_area;
if ( (player[56] & 0x2000000) == 0 )
return func9(a1, va);
if ( wizard )
{
func8("Couldn't hear: ");
result = func9(a1, va);
}
return result;
}

original_code:
void
hearmsg(const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    if ((!((player).t_flags[(0x12000000UL >> 28UL) & 0x0000000fL] & (0x12000000UL & 0x0fffffffL))))
        vmsg(fmt, ap);
    else if (wizard)
    {
        msg("Couldn't hear: ");
        vmsg(fmt, ap);
    }
    __builtin_va_end(ap);
}

canonical_original_code:
void hearmsg(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    if ((!((player).t_flags[(0x12000000UL >> 28UL) & 0x0000000fL] & (0x12000000UL & 0x0fffffffL))))
        vmsg(fmt, ap);
    else if (wizard)
    {
        msg("Couldn't hear: ");
        vmsg(fmt, ap);
    }
    __builtin_va_end(ap);
}


seemsg

decompiled_code:
int seemsg(char *a1, ...)
{
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
result = (int)va[0].reg_save_area;
if ( (player[54] & 1) == 0 )
return vmsg(a1, va);
if ( wizard )
{
msg("Couldn't see: ");
result = vmsg(a1, va);
}
return result;
}

canonical_decompiled_code:
int func15(char *a1, ...)
{
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
result = (int)va[0].reg_save_area;
if ( (player[54] & 1) == 0 )
return func9(a1, va);
if ( wizard )
{
func8("Couldn't see: ");
result = func9(a1, va);
}
return result;
}

original_code:
void
seemsg(const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    if ((!((player).t_flags[(0x00000001UL >> 28UL) & 0x0000000fL] & (0x00000001UL & 0x0fffffffL))))
        vmsg(fmt, ap);
    else if (wizard)
    {
        msg("Couldn't see: ");
        vmsg(fmt, ap);
    }
    __builtin_va_end(ap);
}

canonical_original_code:
void seemsg(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    if ((!((player).t_flags[(0x00000001UL >> 28UL) & 0x0000000fL] & (0x00000001UL & 0x0fffffffL))))
        vmsg(fmt, ap);
    else if (wizard)
    {
        msg("Couldn't see: ");
        vmsg(fmt, ap);
    }
    __builtin_va_end(ap);
}


decompiled_code:
char *d_slot()
{
char *result; // rax

result = (char *)&d_list;
while ( *(_DWORD *)result )
{
result += 32;
if ( result == (char *)&d_list + 1920 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
char *func0()
{
char *result; // rax

result = (char *)&d_list;
while ( *(_DWORD *)result )
{
result += 32;
if ( result == (char *)&d_list + 1920 )
return 0LL;
}
return result;
}

original_code:
struct delayed_action *
d_slot(void)
{
    int i;
    struct delayed_action *dev;
    for (i = 0, dev = d_list; i < 60; i++, dev++)
        if (dev->d_type == 0)
            return(dev);
    return(((void *)0));
}

canonical_original_code:
struct delayed_action *d_slot()
{
    int i;
    struct delayed_action *dev;
    for (i = 0, dev = d_list; i < 60; i++, dev++)
        if (dev->d_type == 0)
            return(dev);
    return(((void *)0));
}

variable_types: struct delayed_action { int d_type; int d_when; int d_id; void *d_arg; int d_time; } *


decompiled_code:
char *__fastcall start_daemon(int a1, __int64 a2, int a3)
{
char *result; // rax

result = d_slot();
if ( result )
{
*(_DWORD *)result = 1;
*((_DWORD *)result + 1) = a3;
*((_DWORD *)result + 2) = a1;
*((_QWORD *)result + 2) = a2;
*((_DWORD *)result + 6) = 1;
++demoncnt;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(int a1, __int64 a2, int a3)
{
char *result; // rax

result = func0();
if ( result )
{
*(_DWORD *)result = 1;
*((_DWORD *)result + 1) = a3;
*((_DWORD *)result + 2) = a1;
*((_QWORD *)result + 2) = a2;
*((_DWORD *)result + 6) = 1;
++demoncnt;
}
return result;
}

original_code:
void
start_daemon(int id, void *arg, int whendo)
{
    struct delayed_action *dev;
    dev = d_slot();
    if (dev != ((void *)0))
    {
        dev->d_type = 1;
        dev->d_when = whendo;
        dev->d_id = id;
        dev->d_arg = arg;
        dev->d_time = 1;
        demoncnt += 1;
    }
}

variable_types: id int

variable_types:
arg
void *

variable_types: whendo int

user_defined_types: struct delayed_action { int d_type; int d_when; int d_id; void *d_arg; int d_time; }


decompiled_code:
void __fastcall do_daemons(int a1)
{
_QWORD *v1; // rbx
__int64 v2; // rsi
void (__fastcall *v3)(__int64 *); // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = &d_list;
do
{
if ( *((_DWORD *)v1 + 1) == a1 && *(_DWORD *)v1 == 1 )
{
v2 = *((unsigned int *)v1 + 2);
if ( (unsigned int)(v2 - 1) > 3 )
{
printf("Bad daemon id %d\n", v2);
}
else
{
v3 = (void (__fastcall *)(__int64 *))daemons[2 * (int)v2 + 1];
if ( v3 )
{
v4[0] = v1[2];
v3(v4);
}
else
{
printf("No action for daemon %d!!!\n", v2);
}
}
}
v1 += 4;
}
while ( v1 != (_QWORD *)((char *)&d_list + 1920) );
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
_QWORD *v1; // rbx
__int64 v2; // rsi
void (__fastcall *v3)(__int64 *); // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = &d_list;
do
{
if ( *((_DWORD *)v1 + 1) == a1 && *(_DWORD *)v1 == 1 )
{
v2 = *((unsigned int *)v1 + 2);
if ( (unsigned int)(v2 - 1) > 3 )
{
printf("Bad daemon id %d\n", v2);
}
else
{
v3 = (void (__fastcall *)(__int64 *))daemons[2 * (int)v2 + 1];
if ( v3 )
{
v4[0] = v1[2];
v3(v4);
}
else
{
printf("No action for daemon %d!!!\n", v2);
}
}
}
v1 += 4;
}
while ( v1 != (_QWORD *)((char *)&d_list + 1920) );
}

original_code:
void
do_daemons(int now)
{
    struct delayed_action *dev;
    for (dev = d_list; dev < &d_list[60]; dev++)
        if ( (dev->d_when == now) && (dev->d_type == 1))
        {
            if ((dev->d_id < 1) || (dev->d_id >= 5))
                printf("Bad daemon id %d\n", dev->d_id);
            else if (daemons[dev->d_id].func == ((void *)0))
                printf("No action for daemon %d!!!\n", dev->d_id);
            else
            {
                daemon_arg arg;
                arg.varg = dev->d_arg;
                daemons[dev->d_id].func(&arg);
            }
        }
}

canonical_original_code:
void do_daemons(int now)
{
    struct delayed_action *dev;
    for (dev = d_list; dev < &d_list[60]; dev++)
        if ( (dev->d_when == now) && (dev->d_type == 1))
        {
            if ((dev->d_id < 1) || (dev->d_id >= 5))
                printf("Bad daemon id %d\n", dev->d_id);
            else if (daemons[dev->d_id].func == ((void *)0))
                printf("No action for daemon %d!!!\n", dev->d_id);
            else
            {
                union daemon_arg arg;
                arg.varg = dev->d_arg;
                daemons[dev->d_id].func(&arg);
            }
        }
}

variable_types: now int

variable_types: union daemon_arg { void *varg; int *iarg; 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; } *thingptr; }

user_defined_types: union daemon_arg { void *varg; int *iarg; struct thing *thingptr; }


decompiled_code:
char *__fastcall light_fuse(int a1, __int64 a2, int a3, int a4)
{
char *result; // rax

result = d_slot();
if ( result )
{
*(_DWORD *)result = 2;
*((_DWORD *)result + 1) = a4;
*((_DWORD *)result + 2) = a1;
*((_QWORD *)result + 2) = a2;
*((_DWORD *)result + 6) = a3;
++demoncnt;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(int a1, __int64 a2, int a3, int a4)
{
char *result; // rax

result = func0();
if ( result )
{
*(_DWORD *)result = 2;
*((_DWORD *)result + 1) = a4;
*((_DWORD *)result + 2) = a1;
*((_QWORD *)result + 2) = a2;
*((_DWORD *)result + 6) = a3;
++demoncnt;
}
return result;
}

original_code:
void
light_fuse(int id, void *arg, int time, int whendo)
{
    struct delayed_action *wire;
    wire = d_slot();
    if (wire != ((void *)0))
    {
        wire->d_type = 2;
        wire->d_when = whendo;
        wire->d_id = id;
        wire->d_arg = arg;
        wire->d_time = time;
        demoncnt += 1;
    }
}

variable_types: time int


original_code:
void
do_fuses(int now)
{
    struct delayed_action *wire;
    for (wire = d_list; wire < &d_list[60]; wire++)
    {
        if( (wire->d_type == 2) && (wire->d_when == now) )
        {
            if (--wire->d_time <= 0)
            {
                fuse_arg arg;
                arg.varg = wire->d_arg;
                wire->d_type = 0;
                fuses[wire->d_id].func(&arg);
                demoncnt -= 1;
            }
        }
    }
    return;
}

canonical_original_code:
void do_fuses(int now)
{
    struct delayed_action *wire;
    for (wire = d_list; wire < &d_list[60]; wire++)
    {
        if( (wire->d_type == 2) && (wire->d_when == now) )
        {
            if (--wire->d_time <= 0)
            {
                union fuse_arg arg;
                arg.varg = wire->d_arg;
                wire->d_type = 0;
                fuses[wire->d_id].func(&arg);
                demoncnt -= 1;
            }
        }
    }
    return;
}

variable_types: union fuse_arg { void *varg; int *iarg; 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; } *ll; }

user_defined_types: union fuse_arg { void *varg; int *iarg; struct linked_list *ll; }


activity

decompiled_code:
__int64 activity()
{
return msg("Daemons = %d : Memory Items = %d ", (unsigned int)demoncnt, total);
}

canonical_decompiled_code:
__int64 func5()
{
return msg("Daemons = %d : Memory Items = %d ", (unsigned int)demoncnt, total);
}

original_code:
void
activity(void)
{
    msg("Daemons = %d : Memory Items = %d ", demoncnt, total);
    return;
}

canonical_original_code:
void activity()
{
    msg("Daemons = %d : Memory Items = %d ", demoncnt, total);
    return;
}