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

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


repo: RoguelikeRestorationProject/urogue

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

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

variable_types: cnt int

return_type: int

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

return_type: void

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


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

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

variable_types: id int


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

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


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

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

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

v3 = a3;
if ( **a2 )
{
v6 = (const char *)inv_name(a1, 1LL);
sprintf(v7, "%c) %s", (unsigned int)*((char *)&print_letters + v3), v6);
}
else
{
v4 = (const char *)inv_name(a1, 1LL);
sprintf(v7, "%c%c) %s", (unsigned int)*(char *)(a1 + 64), (unsigned int)*((char *)&print_letters + v3), 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);
}


decompiled_code:
unsigned __int64 __fastcall bff_callable(__int64 a1)
{
unsigned __int8 v1; // cl
unsigned __int64 result; // rax

v1 = *(_BYTE *)(a1 + 64);
result = 0LL;
if ( v1 <= 0x3Fu )
result = (0xA000800200000000LL >> v1) & 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1)
{
unsigned __int8 v1; // cl
unsigned __int64 result; // rax

v1 = *(_BYTE *)(a1 + 64);
result = 0LL;
if ( v1 <= 0x3Fu )
result = (0xA000800200000000LL >> v1) & 1;
return result;
}

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; // rbp
__int64 result; // rax
const char *v2; // r12
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; // rbp
__int64 result; // rax
const char *v2; // r12
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)
{
unsigned int v3; // er12
int v4; // ecx
__int64 v5; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
unsigned int v3; // er12
int v4; // ecx
__int64 v5; // rsi

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

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; // rbp
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();
*(_QWORD *)(v1 + 48) |= 2uLL;
cur_armor = v1;
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; // rbp
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();
*(_QWORD *)(v1 + 48) |= 2uLL;
cur_armor = v1;
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)
{
chtype v3; // rsi
__int64 result; // rax

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

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

wmove(stdscr, a2[1], *a2);
if ( (int)rnd(10LL) >= level - 1 || (int)rnd(100LL) > 19 )
v3 = 43LL;
else
v3 = 38LL;
waddch(stdscr, v3);
result = *(int *)(a1 + 52);
*(_DWORD *)(a1 + 52) = result + 1;
*(_QWORD *)(a1 + 8 * 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; // ebp
int v2; // er12
__int64 v3; // r14
int v4; // eax
__int64 v5; // r15
int v6; // er13
int v7; // eax
int result; // eax
const char *v9; // [rsp+8h] [rbp-40h]

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;
v5 = *((_QWORD *)&player + 4);
v6 = *((_DWORD *)&player + 15);
if ( (int)v3 <= 15 )
v4 = *((_DWORD *)&player + 14);
if ( cur_armor )
v6 = v6 + *(_DWORD *)(cur_armor + 88LL) - 10;
v9 = (const char *)cnames[15 * *((int *)&player + 90) - 1 + v4];
v7 = 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)(v6 - v7),
v3,
v5,
v9);
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; // ebp
int v2; // er12
__int64 v3; // r14
int v4; // eax
__int64 v5; // r15
int v6; // er13
int v7; // eax
int result; // eax
const char *v9; // [rsp+8h] [rbp-40h]

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;
v5 = *((_QWORD *)&player + 4);
v6 = *((_DWORD *)&player + 15);
if ( (int)v3 <= 15 )
v4 = *((_DWORD *)&player + 14);
if ( cur_armor )
v6 = v6 + *(_DWORD *)(cur_armor + 88LL) - 10;
v9 = (const char *)cnames[15 * *((int *)&player + 90) - 1 + v4];
v7 = 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)(v6 - v7),
v3,
v5,
v9);
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
int v1; // eax

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);
v1 = newpos;
newpos = 0;
mpos = v1;
return wrefresh(cw);
}

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

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);
v1 = newpos;
newpos = 0;
mpos = v1;
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

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

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

result = inv_type;
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);
if ( (player[56] & 0x2000000) != 0 )
{
result = wizard;
if ( !wizard )
return result;
msg("Couldn't hear: ");
}
return vmsg(a1, va);
}

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

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

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);
if ( (player[54] & 1) != 0 )
{
result = wizard;
if ( !wizard )
return result;
msg("Couldn't see: ");
}
return vmsg(a1, va);
}

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

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

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)
{
char *result; // rax
int v3; // ecx

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

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

result = func0();
if ( result )
{
*(_DWORD *)result = 1;
++demoncnt;
*((_DWORD *)result + 1) = v3;
*((_DWORD *)result + 2) = a1;
*((_QWORD *)result + 2) = a2;
*((_DWORD *)result + 6) = 1;
}
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)
{
unsigned int *v1; // rbx
__int64 v2; // rsi
void (__fastcall *v3)(__int64 *); // rax
__int64 v4; // rdx
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (unsigned int *)&d_list;
do
{
while ( 1 )
{
if ( v1[1] != a1 || *v1 != 1 )
goto LABEL_2;
v2 = v1[2];
if ( (unsigned int)(v2 - 1) <= 3 )
break;
printf("Bad daemon id %d\n", v2);
LABEL_2:
v1 += 8;
if ( v1 == (unsigned int *)((char *)&d_list + 1920) )
return;
}
v3 = (void (__fastcall *)(__int64 *))daemons[2 * (int)v2 + 1];
if ( !v3 )
{
printf("No action for daemon %d!!!\n", v2);
goto LABEL_2;
}
v4 = *((_QWORD *)v1 + 2);
v1 += 8;
v5[0] = v4;
v3(v5);
}
while ( v1 != (unsigned int *)((char *)&d_list + 1920) );
}

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

v1 = (unsigned int *)&d_list;
do
{
while ( 1 )
{
if ( v1[1] != a1 || *v1 != 1 )
goto LABEL_2;
v2 = v1[2];
if ( (unsigned int)(v2 - 1) <= 3 )
break;
printf("Bad daemon id %d\n", v2);
LABEL_2:
v1 += 8;
if ( v1 == (unsigned int *)((char *)&d_list + 1920) )
return;
}
v3 = (void (__fastcall *)(__int64 *))daemons[2 * (int)v2 + 1];
if ( !v3 )
{
printf("No action for daemon %d!!!\n", v2);
goto LABEL_2;
}
v4 = *((_QWORD *)v1 + 2);
v1 += 8;
v5[0] = v4;
v3(v5);
}
while ( v1 != (unsigned int *)((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(__int64 a1, __int64 a2, int a3)
{
char *result; // rax
int v6; // ecx
int v7; // er8

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

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, __int64 a2, int a3)
{
char *result; // rax
int v6; // ecx
int v7; // er8

result = func0();
if ( result )
{
*(_DWORD *)result = 2;
++demoncnt;
*((_DWORD *)result + 1) = v6;
*((_DWORD *)result + 2) = v7;
*((_QWORD *)result + 2) = a2;
*((_DWORD *)result + 6) = a3;
}
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


decompiled_code:
__int64 __fastcall do_fuses(int a1)
{
char *v1; // rbx
__int64 result; // rax
__int64 v3; // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (char *)&d_list;
do
{
while ( 1 )
{
if ( *(_DWORD *)v1 == 2 && *((_DWORD *)v1 + 1) == a1 )
{
result = (unsigned int)(*((_DWORD *)v1 + 6) - 1);
*((_DWORD *)v1 + 6) = result;
if ( (int)result <= 0 )
break;
}
v1 += 32;
if ( v1 == (char *)&d_list + 1920 )
return result;
}
v3 = *((_QWORD *)v1 + 2);
*(_DWORD *)v1 = 0;
v1 += 32;
v4[0] = v3;
result = ((__int64 (__fastcall *)(__int64 *))fuses[2 * *((int *)v1 - 6) + 1])(v4);
--demoncnt;
}
while ( v1 != (char *)&d_list + 1920 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
char *v1; // rbx
__int64 result; // rax
__int64 v3; // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (char *)&d_list;
do
{
while ( 1 )
{
if ( *(_DWORD *)v1 == 2 && *((_DWORD *)v1 + 1) == a1 )
{
result = (unsigned int)(*((_DWORD *)v1 + 6) - 1);
*((_DWORD *)v1 + 6) = result;
if ( (int)result <= 0 )
break;
}
v1 += 32;
if ( v1 == (char *)&d_list + 1920 )
return result;
}
v3 = *((_QWORD *)v1 + 2);
*(_DWORD *)v1 = 0;
v1 += 32;
v4[0] = v3;
result = ((__int64 (__fastcall *)(__int64 *))fuses[2 * *((int *)v1 - 6) + 1])(v4);
--demoncnt;
}
while ( v1 != (char *)&d_list + 1920 );
return result;
}

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


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

result = inwhgt;
if ( !inwhgt )
{
do_daemons(1);
do_fuses(1);
do_daemons(2);
result = do_fuses(2);
}
return result;
}

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

result = inwhgt;
if ( !inwhgt )
{
func2(1);
func4(1);
func2(2);
result = func4(2);
}
return result;
}

original_code:
void
waste_time(void)
{
    if (inwhgt)
        return;
    do_daemons(1);
    do_fuses(1);
    do_daemons(2);
    do_fuses(2);
}

canonical_original_code:
void waste_time()
{
    if (inwhgt)
        return;
    do_daemons(1);
    do_fuses(1);
    do_daemons(2);
    do_fuses(2);
}


moffset

decompiled_code:
__int64 __fastcall moffset(int a1, int a2)
{
return bits + a2 + (__int64)(a1 * (COLS - 1));
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
return bits + a2 + (__int64)(a1 * (COLS - 1));
}

original_code:
char *
moffset(int y, int x)
{
    return (bits + (y * (COLS - 1)) + x);
}

canonical_original_code:
char *moffset(int y, int x)
{
    return (bits + (y * (COLS - 1)) + x);
}

variable_types: y int

variable_types: x int

return_type: char *


foffset

decompiled_code:
__int64 __fastcall foffset(int a1, int a2)
{
return frontier + urcols * a1 + (__int64)a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return frontier + urcols * a1 + (__int64)a2;
}

original_code:
char *
foffset(int y, int x)
{
    return (frontier + (y * urcols) + x);
}

canonical_original_code:
char *foffset(int y, int x)
{
    return (frontier + (y * urcols) + x);
}


rmwall

decompiled_code:
__int64 __fastcall rmwall(int a1, int a2, int a3, int a4)
{
unsigned int v4; // er9
unsigned int v5; // er8

*(_BYTE *)moffset(a1 + a3 + 1, a2 + a4 + 1) = 0;
return findcells(v5, v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2, int a3, int a4)
{
unsigned int v4; // er9
unsigned int v5; // er8

*(_BYTE *)func0(a1 + a3 + 1, a2 + a4 + 1) = 0;
return func3(v5, v4);
}

original_code:
void
rmwall(int newy, int newx, int oldy, int oldx)
{
    int xdif, ydif;
    xdif = newx - oldx;
    ydif = newy - oldy;
    *moffset((oldy * 2) + ydif + 1, (oldx * 2) + xdif + 1) = 0;
    findcells(newy, newx);
}

canonical_original_code:
void rmwall(int newy, int newx, int oldy, int oldx)
{
    int xdif; int ydif;
    xdif = newx - oldx;
    ydif = newy - oldy;
    *moffset((oldy * 2) + ydif + 1, (oldx * 2) + xdif + 1) = 0;
    findcells(newy, newx);
}

variable_types: newy int

variable_types: newx int

variable_types: oldy int

variable_types: oldx int

variable_types: xdif int

variable_types: ydif int


findcells

original_code:
int
findcells(int y, int x)
{
    int rtpos, i;
    struct
    {
       int num_pos;
       struct
       {
           int y_pos;
           int x_pos;
       } conn[4];
    } mborder;
    *foffset(y, x) = 0;
    mborder.num_pos = 0;
    if (y < urlines - 1) {
        if (*foffset(y + 1, x))
        {
            mborder.conn[mborder.num_pos].y_pos = y + 1;
            mborder.conn[mborder.num_pos].x_pos = x;
            mborder.num_pos += 1;
        }
    }
    if (y > 0)
    {
        if (*foffset(y - 1, x))
        {
            mborder.conn[mborder.num_pos].y_pos = y - 1;
            mborder.conn[mborder.num_pos].x_pos = x;
            mborder.num_pos += 1;
        }
    }
    if (x < urcols - 1)
    {
        if (*foffset(y, x + 1))
        {
            mborder.conn[mborder.num_pos].y_pos = y;
            mborder.conn[mborder.num_pos].x_pos = x + 1;
            mborder.num_pos += 1;
        }
    }
    if (x > 0)
    {
        if (*foffset(y, x - 1))
        {
            mborder.conn[mborder.num_pos].y_pos = y;
            mborder.conn[mborder.num_pos].x_pos = x - 1;
            mborder.num_pos += 1;
        }
    }
    if (mborder.num_pos == 0)
        return(0);
    else
    {
        i = rnd(mborder.num_pos);
        rtpos = mborder.num_pos - 1;
        rmwall(mborder.conn[i].y_pos, mborder.conn[i].x_pos, y, x);
        return(rtpos);
    }
}

canonical_original_code:
int findcells(int y, int x)
{
    int rtpos; int i;
    struct { int num_pos; struct { int y_pos; int x_pos; } conn[4]; } mborder;
    *foffset(y, x) = 0;
    mborder.num_pos = 0;
    if (y < urlines - 1) {
        if (*foffset(y + 1, x))
        {
            mborder.conn[mborder.num_pos].y_pos = y + 1;
            mborder.conn[mborder.num_pos].x_pos = x;
            mborder.num_pos += 1;
        }
    }
    if (y > 0)
    {
        if (*foffset(y - 1, x))
        {
            mborder.conn[mborder.num_pos].y_pos = y - 1;
            mborder.conn[mborder.num_pos].x_pos = x;
            mborder.num_pos += 1;
        }
    }
    if (x < urcols - 1)
    {
        if (*foffset(y, x + 1))
        {
            mborder.conn[mborder.num_pos].y_pos = y;
            mborder.conn[mborder.num_pos].x_pos = x + 1;
            mborder.num_pos += 1;
        }
    }
    if (x > 0)
    {
        if (*foffset(y, x - 1))
        {
            mborder.conn[mborder.num_pos].y_pos = y;
            mborder.conn[mborder.num_pos].x_pos = x - 1;
            mborder.num_pos += 1;
        }
    }
    if (mborder.num_pos == 0)
        return(0);
    else
    {
        i = rnd(mborder.num_pos);
        rtpos = mborder.num_pos - 1;
        rmwall(mborder.conn[i].y_pos, mborder.conn[i].x_pos, y, x);
        return(rtpos);
    }
}

variable_types: rtpos int

variable_types: i int


crankout

decompiled_code:
void crankout()
{
int v0; // er13
int v1; // ebp
int v2; // er12
int v3; // ebx
WINDOW *v4; // r8
int v5; // edx

if ( LINES > 3 )
{
v0 = 0;
while ( 1 )
{
v1 = v0;
v2 = v0++;
v3 = 0;
wmove(stdscr, v0, 0);
if ( COLS > 1 )
break;
LABEL_17:
if ( LINES - 3 <= v0 )
return;
}
while ( 1 )
{
while ( !*(_BYTE *)moffset(v1, v3) )
{
++v3;
waddch(stdscr, 0x2EuLL);
if ( COLS - 1 <= v3 )
goto LABEL_17;
}
if ( !v2 || LINES - 4 == v1 )
goto LABEL_19;
if ( !v3 || v5 - 2 == v3 || (v1 & 1) != 0 )
{
++v3;
waddch(stdscr, 0x7CuLL);
goto LABEL_14;
}
if ( (v3 & 1) != 0 )
{
LABEL_19:
++v3;
waddch(stdscr, 0x2DuLL);
}
else
{
if ( *(_BYTE *)moffset(v1, v3 - 1) )
{
++v3;
}
else if ( !*(_BYTE *)moffset(v1, ++v3) )
{
waddch(v4, 0x7CuLL);
goto LABEL_14;
}
waddch(v4, 0x2DuLL);
}
LABEL_14:
if ( COLS - 1 <= v3 )
goto LABEL_17;
}
}
}

canonical_decompiled_code:
void func4()
{
int v0; // er13
int v1; // ebp
int v2; // er12
int v3; // ebx
WINDOW *v4; // r8
int v5; // edx

if ( LINES > 3 )
{
v0 = 0;
while ( 1 )
{
v1 = v0;
v2 = v0++;
v3 = 0;
wmove(stdscr, v0, 0);
if ( COLS > 1 )
break;
LABEL_17:
if ( LINES - 3 <= v0 )
return;
}
while ( 1 )
{
while ( !*(_BYTE *)func0(v1, v3) )
{
++v3;
waddch(stdscr, 0x2EuLL);
if ( COLS - 1 <= v3 )
goto LABEL_17;
}
if ( !v2 || LINES - 4 == v1 )
goto LABEL_19;
if ( !v3 || v5 - 2 == v3 || (v1 & 1) != 0 )
{
++v3;
waddch(stdscr, 0x7CuLL);
goto LABEL_14;
}
if ( (v3 & 1) != 0 )
{
LABEL_19:
++v3;
waddch(stdscr, 0x2DuLL);
}
else
{
if ( *(_BYTE *)func0(v1, v3 - 1) )
{
++v3;
}
else if ( !*(_BYTE *)func0(v1, ++v3) )
{
waddch(v4, 0x7CuLL);
goto LABEL_14;
}
waddch(v4, 0x2DuLL);
}
LABEL_14:
if ( COLS - 1 <= v3 )
goto LABEL_17;
}
}
}

original_code:
void
crankout(void)
{
    int x, y;
    for (y = 0; y < LINES - 3; y++)
    {
        wmove(stdscr,(y + 1),(0));
        for (x = 0; x < COLS - 1; x++)
        {
            if (*moffset(y, x))
            {
                if (y == 0 || y == LINES - 4)
                    waddch(stdscr,('-'));
                else if (x == 0 || x == COLS - 2)
                    waddch(stdscr,('|'));
                else if (y % 2 == 0 && x % 2 == 0)
                {
                    if (*moffset(y, x - 1) || *moffset(y, x + 1))
                        waddch(stdscr,('-'));
                    else
                        waddch(stdscr,('|'));
                }
                else if (y % 2 == 0)
                    waddch(stdscr,('-'));
                else
                    waddch(stdscr,('|'));
            }
            else
                waddch(stdscr,('.'));
        }
    }
}

canonical_original_code:
void crankout()
{
    int x; int y;
    for (y = 0; y < LINES - 3; y++)
    {
        wmove(stdscr,(y + 1),(0));
        for (x = 0; x < COLS - 1; x++)
        {
            if (*moffset(y, x))
            {
                if (y == 0 || y == LINES - 4)
                    waddch(stdscr,('-'));
                else if (x == 0 || x == COLS - 2)
                    waddch(stdscr,('|'));
                else if (y % 2 == 0 && x % 2 == 0)
                {
                    if (*moffset(y, x - 1) || *moffset(y, x + 1))
                        waddch(stdscr,('-'));
                    else
                        waddch(stdscr,('|'));
                }
                else if (y % 2 == 0)
                    waddch(stdscr,('-'));
                else
                    waddch(stdscr,('|'));
            }
            else
                waddch(stdscr,('.'));
        }
    }
}


decompiled_code:
__int64 draw_maze()
{
char *v0; // rax
int v1; // ebx
int v2; // er12
size_t v3; // rdx
int v4; // ecx
int v5; // edx
_BYTE *v6; // rax
int v7; // edx
int v8; // er8
int v9; // ebp
int v10; // ebx

urlines = (LINES - 3) / 2;
urcols = (COLS - 1) / 2;
bits = ur_alloc((unsigned int)((LINES - 3) * (COLS - 1)));
v0 = (char *)ur_alloc((unsigned int)(urcols * urlines));
v1 = urlines;
v2 = urcols;
frontier = (__int64)v0;
v3 = urcols * urlines;
if ( v0 < &v0[v3] )
memset(v0, 1, v3);
v4 = 0;
if ( LINES > 3 )
{
do
{
v5 = 0;
if ( COLS > 1 )
{
do
{
while ( 1 )
{
v6 = (_BYTE *)moffset(v4, v5);
if ( !v8 || (v7 & 1) == 0 )
break;
*v6 = 0;
v5 = v7 + 1;
if ( COLS - 1 <= v5 )
goto LABEL_10;
}
*v6 = 1;
v5 = v7 + 1;
}
while ( COLS - 1 > v5 );
}
LABEL_10:
++v4;
}
while ( LINES - 3 > v4 );
}
v9 = 0;
if ( v1 > 0 )
{
while ( 1 )
{
v10 = 0;
if ( v2 > 0 )
{
do
{
while ( (unsigned int)findcells(v9, v10) )
;
++v10;
}
while ( urcols > v10 );
}
if ( urlines <= ++v9 )
break;
v2 = urcols;
}
}
crankout();
ur_free(frontier);
return ur_free(bits);
}

canonical_decompiled_code:
__int64 func5()
{
char *v0; // rax
int v1; // ebx
int v2; // er12
size_t v3; // rdx
int v4; // ecx
int v5; // edx
_BYTE *v6; // rax
int v7; // edx
int v8; // er8
int v9; // ebp
int v10; // ebx

urlines = (LINES - 3) / 2;
urcols = (COLS - 1) / 2;
bits = ur_alloc((unsigned int)((LINES - 3) * (COLS - 1)));
v0 = (char *)ur_alloc((unsigned int)(urcols * urlines));
v1 = urlines;
v2 = urcols;
frontier = (__int64)v0;
v3 = urcols * urlines;
if ( v0 < &v0[v3] )
memset(v0, 1, v3);
v4 = 0;
if ( LINES > 3 )
{
do
{
v5 = 0;
if ( COLS > 1 )
{
do
{
while ( 1 )
{
v6 = (_BYTE *)func0(v4, v5);
if ( !v8 || (v7 & 1) == 0 )
break;
*v6 = 0;
v5 = v7 + 1;
if ( COLS - 1 <= v5 )
goto LABEL_10;
}
*v6 = 1;
v5 = v7 + 1;
}
while ( COLS - 1 > v5 );
}
LABEL_10:
++v4;
}
while ( LINES - 3 > v4 );
}
v9 = 0;
if ( v1 > 0 )
{
while ( 1 )
{
v10 = 0;
if ( v2 > 0 )
{
do
{
while ( (unsigned int)func3(v9, v10) )
;
++v10;
}
while ( urcols > v10 );
}
if ( urlines <= ++v9 )
break;
v2 = urcols;
}
}
func4();
ur_free(frontier);
return ur_free(bits);
}

original_code:
void
draw_maze(void)
{
    int i, j, more;
    char *ptr;
    urlines = (LINES - 3) / 2;
    urcols = (COLS - 1) / 2;
    bits = ur_alloc((unsigned int) ((LINES - 3) * (COLS - 1)));
    frontier = ur_alloc((unsigned int) (urlines * urcols));
    ptr = frontier;
    while (ptr < (frontier + (urlines * urcols)))
        *ptr++ = 1;
    for (i = 0; i < LINES - 3; i++)
    {
        for (j = 0; j < COLS - 1; j++)
        {
            if (i % 2 == 1 && j % 2 == 1)
                *moffset(i, j) = 0;
            else
                *moffset(i, j) = 1;
        }
    }
    for (i = 0; i < urlines; i++)
    {
        for (j = 0; j < urcols; j++)
        {
            do
                more = findcells(i, j);
            while (more != 0);
        }
    }
    crankout();
    ur_free(frontier);
    ur_free(bits);
}

canonical_original_code:
void draw_maze()
{
    int i; int j; int more;
    char *ptr;
    urlines = (LINES - 3) / 2;
    urcols = (COLS - 1) / 2;
    bits = ur_alloc((unsigned int) ((LINES - 3) * (COLS - 1)));
    frontier = ur_alloc((unsigned int) (urlines * urcols));
    ptr = frontier;
    while (ptr < (frontier + (urlines * urcols)))
        *ptr++ = 1;
    for (i = 0; i < LINES - 3; i++)
    {
        for (j = 0; j < COLS - 1; j++)
        {
            if (i % 2 == 1 && j % 2 == 1)
                *moffset(i, j) = 0;
            else
                *moffset(i, j) = 1;
        }
    }
    for (i = 0; i < urlines; i++)
    {
        for (j = 0; j < urcols; j++)
        {
            do
                more = findcells(i, j);
            while (more != 0);
        }
    }
    crankout();
    ur_free(frontier);
    ur_free(bits);
}

variable_types: j int

variable_types: more int

variable_types:
ptr
char *


decompiled_code:
__int64 do_maze()
{
char *v0; // rax
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp
__int64 v4; // rdx
__int64 v5; // rsi
__int64 v6; // rax
char **v7; // rbx
__int64 v8; // rbp
__int64 v9; // rdx
__int64 v10; // rsi
int v11; // er14
int v12; // er13
__int64 result; // rax
int v14; // ebx
ITEM *v15; // rax
const char *v16; // r12
ITEM *v17; // rbp
__int64 v18; // rbp
int v19; // er15
int v20; // er15
__int64 v21; // [rsp+8h] [rbp-50h]
char *v22[8]; // [rsp+18h] [rbp-40h] BYREF

v0 = (char *)&rooms;
do
{
*((_DWORD *)v0 + 13) = 0;
v0 += 60;
*((_DWORD *)v0 - 3) = 2;
*((_WORD *)v0 - 2) = 0;
}
while ( v0 != (char *)&rooms + 540 );
*((_DWORD *)&rooms + 12) = 1;
rooms = 0x100000000LL;
*((_DWORD *)&rooms + 2) = COLS - 1;
*((_DWORD *)&rooms + 3) = LINES - 3;
draw_maze();
v1 = spec_item(42LL, 0LL, 0LL, 0LL);
v2 = *(_QWORD *)(v1 + 16);
v3 = v1;
*(_DWORD *)(v2 + 72) *= (unsigned int)rnd(10LL) + 5;
do
{
do
rnd_pos(&rooms, v22);
while ( wmove(stdscr, SHIDWORD(v22[0]), (int)v22[0]) == -1 );
}
while ( (unsigned int)winch(stdscr) != 46 );
v4 = LODWORD(v22[0]);
v5 = HIDWORD(v22[0]);
*(char **)v2 = v22[0];
add_obj(v3, v5, v4);
v6 = spec_item(58LL, 0LL, 0LL, 0LL);
v7 = *(char ***)(v6 + 16);
v8 = v6;
do
{
do
rnd_pos(&rooms, v22);
while ( wmove(stdscr, SHIDWORD(v22[0]), (int)v22[0]) == -1 );
}
while ( (unsigned int)winch(stdscr) != 46 );
v9 = LODWORD(v22[0]);
v10 = HIDWORD(v22[0]);
*v7 = v22[0];
add_obj(v8, v10, v9);
if ( (int)rnd(100LL) > 4 )
{
v11 = 0;
v12 = 1;
}
else
{
v11 = 1;
v12 = 20;
if ( wizard && wiz_verbose )
msg("Treasure maze.");
}
result = (unsigned int)(v12 + level);
if ( (int)result > 0 )
{
v14 = 0;
do
{
while ( 1 )
{
if ( v11 || (int)rnd(100LL) > 49 )
{
v15 = new_item(&byte_188, (const char *)v10);
v16 = v15->description.str;
v17 = v15;
do
{
do
rnd_pos(&rooms, v22);
while ( wmove(stdscr, SHIDWORD(v22[0]), (int)v22[0]) == -1 );
}
while ( (unsigned int)winch(stdscr) != 46 );
v10 = (unsigned int)randmonster(0LL, 0LL);
new_monster(v17, v10, v22, 0LL);
if ( (int)rnd(100LL) < monsters[108 * *((int *)v16 + 91) + 4] )
{
v10 = new_thing();
attach(v16 + 16, v10);
}
if ( (v16[225] & 0x10) != 0 )
break;
}
++v14;
result = (unsigned int)(v12 + level);
if ( (int)result <= v14 )
return result;
}
++v14;
v18 = spec_item(42LL, 0LL, 0LL, 0LL);
v21 = *(_QWORD *)(v18 + 16);
v19 = rnd((unsigned int)(30 * level + 50));
v20 = v19 + rnd((unsigned int)(30 * level + 50)) + 4;
v10 = v18;
*(_DWORD *)(v21 + 72) = v20 + rnd((unsigned int)(30 * level + 50)) + 2;
*(_QWORD *)v21 = *((_QWORD *)v16 + 24);
attach(v16 + 16, v18);
result = (unsigned int)(v12 + level);
}
while ( (int)result > v14 );
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
char *v0; // rax
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp
__int64 v4; // rdx
__int64 v5; // rsi
__int64 v6; // rax
char **v7; // rbx
__int64 v8; // rbp
__int64 v9; // rdx
__int64 v10; // rsi
int v11; // er14
int v12; // er13
__int64 result; // rax
int v14; // ebx
ITEM *v15; // rax
const char *v16; // r12
ITEM *v17; // rbp
__int64 v18; // rbp
int v19; // er15
int v20; // er15
__int64 v21; // [rsp+8h] [rbp-50h]
char *v22[8]; // [rsp+18h] [rbp-40h] BYREF

v0 = (char *)&rooms;
do
{
*((_DWORD *)v0 + 13) = 0;
v0 += 60;
*((_DWORD *)v0 - 3) = 2;
*((_WORD *)v0 - 2) = 0;
}
while ( v0 != (char *)&rooms + 540 );
*((_DWORD *)&rooms + 12) = 1;
rooms = 0x100000000LL;
*((_DWORD *)&rooms + 2) = COLS - 1;
*((_DWORD *)&rooms + 3) = LINES - 3;
func5();
v1 = spec_item(42LL, 0LL, 0LL, 0LL);
v2 = *(_QWORD *)(v1 + 16);
v3 = v1;
*(_DWORD *)(v2 + 72) *= (unsigned int)rnd(10LL) + 5;
do
{
do
rnd_pos(&rooms, v22);
while ( wmove(stdscr, SHIDWORD(v22[0]), (int)v22[0]) == -1 );
}
while ( (unsigned int)winch(stdscr) != 46 );
v4 = LODWORD(v22[0]);
v5 = HIDWORD(v22[0]);
*(char **)v2 = v22[0];
add_obj(v3, v5, v4);
v6 = spec_item(58LL, 0LL, 0LL, 0LL);
v7 = *(char ***)(v6 + 16);
v8 = v6;
do
{
do
rnd_pos(&rooms, v22);
while ( wmove(stdscr, SHIDWORD(v22[0]), (int)v22[0]) == -1 );
}
while ( (unsigned int)winch(stdscr) != 46 );
v9 = LODWORD(v22[0]);
v10 = HIDWORD(v22[0]);
*v7 = v22[0];
add_obj(v8, v10, v9);
if ( (int)rnd(100LL) > 4 )
{
v11 = 0;
v12 = 1;
}
else
{
v11 = 1;
v12 = 20;
if ( wizard && wiz_verbose )
msg("Treasure maze.");
}
result = (unsigned int)(v12 + level);
if ( (int)result > 0 )
{
v14 = 0;
do
{
while ( 1 )
{
if ( v11 || (int)rnd(100LL) > 49 )
{
v15 = new_item(&byte_188, (const char *)v10);
v16 = v15->description.str;
v17 = v15;
do
{
do
rnd_pos(&rooms, v22);
while ( wmove(stdscr, SHIDWORD(v22[0]), (int)v22[0]) == -1 );
}
while ( (unsigned int)winch(stdscr) != 46 );
v10 = (unsigned int)randmonster(0LL, 0LL);
new_monster(v17, v10, v22, 0LL);
if ( (int)rnd(100LL) < monsters[108 * *((int *)v16 + 91) + 4] )
{
v10 = new_thing();
attach(v16 + 16, v10);
}
if ( (v16[225] & 0x10) != 0 )
break;
}
++v14;
result = (unsigned int)(v12 + level);
if ( (int)result <= v14 )
return result;
}
++v14;
v18 = spec_item(42LL, 0LL, 0LL, 0LL);
v21 = *(_QWORD *)(v18 + 16);
v19 = rnd((unsigned int)(30 * level + 50));
v20 = v19 + rnd((unsigned int)(30 * level + 50)) + 4;
v10 = v18;
*(_DWORD *)(v21 + 72) = v20 + rnd((unsigned int)(30 * level + 50)) + 2;
*(_QWORD *)v21 = *((_QWORD *)v16 + 24);
attach(v16 + 16, v18);
result = (unsigned int)(v12 + level);
}
while ( (int)result > v14 );
}
return result;
}

original_code:
void
do_maze(void)
{
    int i, least;
    struct room *rp;
    struct linked_list *item;
    struct object *obj;
    struct thing *mp;
    int treas;
    coord tp;
    for (rp = rooms; rp < &rooms[9]; rp++)
    {
        rp->r_nexits = 0;
        rp->r_flags = 0x00000002UL;
        rp->r_fires = 0;
    }
    rp = &rooms[0];
    rp->r_flags = 0x00000001UL;
    rp->r_pos.x = 0;
    rp->r_pos.y = 1;
    rp->r_max.x = COLS - 1;
    rp->r_max.y = LINES - 3;
    draw_maze();
    item = spec_item('*', 0, 0, 0);
    obj = ((*item).data.obj);
    obj->o_count *= (rnd(10) + 5);
 do
 {
     rnd_pos(rp, &tp);
 }
 while( (wmove((stdscr),(tp.y),(tp.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) != '.');
    obj->o_pos = tp;
    add_obj(item, tp.y, tp.x);
    item = spec_item(':', 0, 0, 0);
    obj = ((*item).data.obj);
 do
 {
     rnd_pos(rp, &tp);
 }
 while( (wmove((stdscr),(tp.y),(tp.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) != '.');
    obj->o_pos = tp;
    add_obj(item, tp.y, tp.x);
    if (rnd(100) < 5)
    {
        treas = 1;
        least = 20;
        if (wizard && wiz_verbose) msg("Treasure maze.");
    }
    else
    {
        least = 1;
        treas = 0;
    }
    for (i = 0; i < level + least; i++)
    {
        if (!treas && rnd(100) < 50)
            continue;
        item = new_item(sizeof *mp);
        mp = ((*item).data.th);
        do
        {
            rnd_pos(rp, &tp);
        }
        while((wmove((stdscr),(tp.y),(tp.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) != '.');
        new_monster(item, randmonster(0, 0), &tp, 0);
        if (rnd(100) < monsters[mp->t_index].m_carry)
            _attach(&mp->t_pack, new_thing());
        if (((*mp).t_flags[(0x10001000UL >> 28UL) & 0x0000000fL] & (0x10001000UL & 0x0fffffffL)))
        {
            item = spec_item('*', 0, 0, 0);
            obj = ((*item).data.obj);
            obj->o_count = (rnd(50 + 30 * level) + 2) + (rnd(50 + 30 * level) + 2) + (rnd(50 + 30 * level) + 2);
            obj->o_pos = mp->t_pos;
            _attach(&mp->t_pack, item);
        }
    }
}

canonical_original_code:
void do_maze()
{
    int i; int least;
    struct room *rp;
    struct linked_list *item;
    struct object *obj;
    struct thing *mp;
    int treas;
    struct coord tp;
    for (rp = rooms; rp < &rooms[9]; rp++)
    {
        rp->r_nexits = 0;
        rp->r_flags = 0x00000002UL;
        rp->r_fires = 0;
    }
    rp = &rooms[0];
    rp->r_flags = 0x00000001UL;
    rp->r_pos.x = 0;
    rp->r_pos.y = 1;
    rp->r_max.x = COLS - 1;
    rp->r_max.y = LINES - 3;
    draw_maze();
    item = spec_item('*', 0, 0, 0);
    obj = ((*item).data.obj);
    obj->o_count *= (rnd(10) + 5);
 do
 {
     rnd_pos(rp, &tp);
 }
 while( (wmove((stdscr),(tp.y),(tp.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) != '.');
    obj->o_pos = tp;
    add_obj(item, tp.y, tp.x);
    item = spec_item(':', 0, 0, 0);
    obj = ((*item).data.obj);
 do
 {
     rnd_pos(rp, &tp);
 }
 while( (wmove((stdscr),(tp.y),(tp.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) != '.');
    obj->o_pos = tp;
    add_obj(item, tp.y, tp.x);
    if (rnd(100) < 5)
    {
        treas = 1;
        least = 20;
        if (wizard && wiz_verbose) msg("Treasure maze.");
    }
    else
    {
        least = 1;
        treas = 0;
    }
    for (i = 0; i < level + least; i++)
    {
        if (!treas && rnd(100) < 50)
            continue;
        item = new_item(sizeof *mp);
        mp = ((*item).data.th);
        do
        {
            rnd_pos(rp, &tp);
        }
        while((wmove((stdscr),(tp.y),(tp.x)) == (-1) ? (chtype)((-1)) : winch(stdscr)) != '.');
        new_monster(item, randmonster(0, 0), &tp, 0);
        if (rnd(100) < monsters[mp->t_index].m_carry)
            _attach(&mp->t_pack, new_thing());
        if (((*mp).t_flags[(0x10001000UL >> 28UL) & 0x0000000fL] & (0x10001000UL & 0x0fffffffL)))
        {
            item = spec_item('*', 0, 0, 0);
            obj = ((*item).data.obj);
            obj->o_count = (rnd(50 + 30 * level) + 2) + (rnd(50 + 30 * level) + 2) + (rnd(50 + 30 * level) + 2);
            obj->o_pos = mp->t_pos;
            _attach(&mp->t_pack, item);
        }
    }
}

variable_types: least int

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

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

variable_types: 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 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: treas int

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


decompiled_code:
const char *__fastcall which_class(unsigned int a1)
{
const char *result; // rax

result = "Monster";
if ( a1 <= 9 )
result = (&CSWTCH_129)[a1];
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(unsigned int a1)
{
const char *result; // rax

result = "Monster";
if ( a1 <= 9 )
result = (&CSWTCH_129)[a1];
return result;
}

original_code:
char *
which_class(int c_class)
{
    char *class;
    switch (c_class)
    {
        case 0:
      class = "Fighter";
   break;
        case 5:
      class = "Magician";
   break;
        case 3:
      class = "Cleric";
   break;
        case 7:
      class = "Thief";
   break;
        case 1:
      class = "Paladin";
   break;
        case 2:
      class = "Ranger";
   break;
        case 4:
      class = "Druid";
   break;
        case 6:
      class = "Illusionist";
   break;
        case 8:
      class = "Assasin";
   break;
        case 9:
      class = "Ninja";
   break;
        default:
      class = "Monster";
   break;
    }
    return (class);
}

canonical_original_code:
char *which_class(int c_class)
{
    char *class;
    switch (c_class)
    {
        case 0:
      class = "Fighter";
   break;
        case 5:
      class = "Magician";
   break;
        case 3:
      class = "Cleric";
   break;
        case 7:
      class = "Thief";
   break;
        case 1:
      class = "Paladin";
   break;
        case 2:
      class = "Ranger";
   break;
        case 4:
      class = "Druid";
   break;
        case 6:
      class = "Illusionist";
   break;
        case 8:
      class = "Assasin";
   break;
        case 9:
      class = "Ninja";
   break;
        default:
      class = "Monster";
   break;
    }
    return (class);
}

variable_types:
class
char *