decompiled_code:
__int64 __fastcall set_cost(_DWORD *a1)
{
__int64 v2; // rsi
__int64 v3; // rdi
int v4; // eax
int v5; // ebp
__int64 result; // rax
int v7; // edx
int v8; // eax
__int64 v9; // rdx

v2 = (unsigned int)a1[28];
switch ( (int)v2 )
{
case 0:
case 1:
case 15:
case 22:
case 40:
case 48:
v3 = 100LL;
break;
case 2:
case 41:
v3 = 30LL;
break;
case 3:
v3 = 60LL;
break;
case 4:
v3 = 20LL;
break;
case 5:
v3 = 50LL;
break;
case 6:
v3 = 70LL;
break;
case 7:
v3 = 130LL;
break;
case 8:
v3 = 140LL;
break;
case 9:
v3 = 65LL;
break;
case 10:
v3 = 35LL;
break;
case 11:
v3 = 80LL;
break;
case 12:
v3 = 60LL;
break;
case 13:
v3 = 80LL;
break;
case 14:
v3 = 85LL;
break;
case 16:
v3 = 110LL;
break;
case 17:
v3 = 95LL;
break;
case 18:
v3 = 150LL;
break;
case 19:
v3 = 200LL;
break;
case 20:
v3 = 90LL;
break;
case 21:
v3 = 50LL;
break;
case 23:
v3 = 150LL;
break;
case 24:
v3 = 250LL;
break;
case 25:
v3 = 500LL;
break;
case 26:
v3 = 750LL;
break;
case 27:
v3 = 1000LL;
break;
case 28:
v3 = 35LL;
break;
case 29:
v3 = 25LL;
break;
case 30:
v3 = 20LL;
break;
case 31:
v3 = 800LL;
break;
case 32:
v3 = 900LL;
break;
case 33:
v3 = 950LL;
break;
case 34:
v3 = 300LL;
break;
case 35:
v3 = 220LL;
break;
case 36:
v3 = 130LL;
break;
case 37:
v3 = 88LL;
break;
case 38:
v3 = 83LL;
break;
case 39:
v3 = 68LL;
break;
case 42:
v3 = 28LL;
break;
case 43:
v3 = 42LL;
break;
case 44:
v3 = 125LL;
break;
case 45:
v3 = 15LL;
break;
case 46:
v3 = 22LL;
break;
case 47:
v3 = 82LL;
break;
case 49:
v3 = 80LL;
break;
case 50:
v3 = 38LL;
break;
case 51:
v3 = 45LL;
break;
case 52:
v3 = 550LL;
break;
case 53:
v3 = 205LL;
break;
case 54:
v3 = 235LL;
break;
case 55:
v3 = 920LL;
break;
case 56:
v3 = 60LL;
break;
default:
bug("Unrecognized material type %d. Setting to default.", v2);
v3 = 100LL;
break;
}
v4 = a1[31];
if ( v4 )
v3 = (unsigned int)((int)v3 * v4 / 7);
v5 = a1[17];
switch ( v5 )
{
case 2:
case 3:
case 4:
case 10:
v5 = 10000;
break;
case 5:
v5 = 100 * a1[40] * a1[39];
break;
case 8:
v5 = 100;
break;
case 9:
v5 = 6 * a1[38] * a1[38] + 10;
break;
case 11:
break;
case 13:
v5 = 1;
break;
case 15:
v5 = 50;
break;
case 17:
v5 = 18;
break;
case 19:
v5 = 20;
break;
case 21:
v5 = 80;
break;
case 22:
v5 = 100;
break;
case 28:
v5 = 1000;
break;
case 32:
v5 = 100;
break;
case 33:
v5 = 3 * a1[40] + 10;
break;
case 34:
v5 = 90;
break;
case 36:
v5 = 40;
break;
default:
v5 = 10;
break;
}
result = (unsigned int)((int)(number_fuzzy(v3) * v5) / 100);
a1[34] = result;
v7 = a1[37];
if ( v7 )
{
v8 = v7 * result;
v9 = (1374389535LL * v8) >> 37;
result = (unsigned int)(v8 >> 31);
a1[34] = v9 - result;
}
if ( !a1[34] )
a1[34] = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1)
{
__int64 v2; // rsi
__int64 v3; // rdi
int v4; // eax
int v5; // ebp
__int64 result; // rax
int v7; // edx
int v8; // eax
__int64 v9; // rdx

v2 = (unsigned int)a1[28];
switch ( (int)v2 )
{
case 0:
case 1:
case 15:
case 22:
case 40:
case 48:
v3 = 100LL;
break;
case 2:
case 41:
v3 = 30LL;
break;
case 3:
v3 = 60LL;
break;
case 4:
v3 = 20LL;
break;
case 5:
v3 = 50LL;
break;
case 6:
v3 = 70LL;
break;
case 7:
v3 = 130LL;
break;
case 8:
v3 = 140LL;
break;
case 9:
v3 = 65LL;
break;
case 10:
v3 = 35LL;
break;
case 11:
v3 = 80LL;
break;
case 12:
v3 = 60LL;
break;
case 13:
v3 = 80LL;
break;
case 14:
v3 = 85LL;
break;
case 16:
v3 = 110LL;
break;
case 17:
v3 = 95LL;
break;
case 18:
v3 = 150LL;
break;
case 19:
v3 = 200LL;
break;
case 20:
v3 = 90LL;
break;
case 21:
v3 = 50LL;
break;
case 23:
v3 = 150LL;
break;
case 24:
v3 = 250LL;
break;
case 25:
v3 = 500LL;
break;
case 26:
v3 = 750LL;
break;
case 27:
v3 = 1000LL;
break;
case 28:
v3 = 35LL;
break;
case 29:
v3 = 25LL;
break;
case 30:
v3 = 20LL;
break;
case 31:
v3 = 800LL;
break;
case 32:
v3 = 900LL;
break;
case 33:
v3 = 950LL;
break;
case 34:
v3 = 300LL;
break;
case 35:
v3 = 220LL;
break;
case 36:
v3 = 130LL;
break;
case 37:
v3 = 88LL;
break;
case 38:
v3 = 83LL;
break;
case 39:
v3 = 68LL;
break;
case 42:
v3 = 28LL;
break;
case 43:
v3 = 42LL;
break;
case 44:
v3 = 125LL;
break;
case 45:
v3 = 15LL;
break;
case 46:
v3 = 22LL;
break;
case 47:
v3 = 82LL;
break;
case 49:
v3 = 80LL;
break;
case 50:
v3 = 38LL;
break;
case 51:
v3 = 45LL;
break;
case 52:
v3 = 550LL;
break;
case 53:
v3 = 205LL;
break;
case 54:
v3 = 235LL;
break;
case 55:
v3 = 920LL;
break;
case 56:
v3 = 60LL;
break;
default:
bug("Unrecognized material type %d. Setting to default.", v2);
v3 = 100LL;
break;
}
v4 = a1[31];
if ( v4 )
v3 = (unsigned int)((int)v3 * v4 / 7);
v5 = a1[17];
switch ( v5 )
{
case 2:
case 3:
case 4:
case 10:
v5 = 10000;
break;
case 5:
v5 = 100 * a1[40] * a1[39];
break;
case 8:
v5 = 100;
break;
case 9:
v5 = 6 * a1[38] * a1[38] + 10;
break;
case 11:
break;
case 13:
v5 = 1;
break;
case 15:
v5 = 50;
break;
case 17:
v5 = 18;
break;
case 19:
v5 = 20;
break;
case 21:
v5 = 80;
break;
case 22:
v5 = 100;
break;
case 28:
v5 = 1000;
break;
case 32:
v5 = 100;
break;
case 33:
v5 = 3 * a1[40] + 10;
break;
case 34:
v5 = 90;
break;
case 36:
v5 = 40;
break;
default:
v5 = 10;
break;
}
result = (unsigned int)((int)(number_fuzzy(v3) * v5) / 100);
a1[34] = result;
v7 = a1[37];
if ( v7 )
{
v8 = v7 * result;
v9 = (1374389535LL * v8) >> 37;
result = (unsigned int)(v8 >> 31);
a1[34] = v9 - result;
}
if ( !a1[34] )
a1[34] = 1;
return result;
}

original_code:
void set_cost( OBJ_INDEX_DATA *obj )
{
        int multiplier;
        int value;
        switch( obj->material )
        {
           default:
              bug( "Unrecognized material type %d.  Setting to default.", obj->material );
              multiplier = 100;
              break;
           case 0:
              multiplier = 100;
              break;
           case 1:
              multiplier = 100;
              break;
           case 2:
              multiplier = 30;
              break;
           case 3:
              multiplier = 60;
              break;
           case 4:
              multiplier = 20;
              break;
           case 5:
              multiplier = 50;
              break;
           case 6:
              multiplier = 70;
              break;
           case 7:
              multiplier = 130;
              break;
           case 8:
              multiplier = 140;
              break;
           case 9:
              multiplier = 65;
              break;
           case 10:
              multiplier = 35;
              break;
           case 11:
              multiplier = 80;
              break;
           case 12:
              multiplier = 60;
              break;
           case 13:
              multiplier = 80;
              break;
           case 14:
              multiplier = 85;
              break;
           case 15:
              multiplier = 100;
              break;
           case 16:
              multiplier = 110;
              break;
           case 17:
              multiplier = 95;
              break;
           case 18:
              multiplier = 150;
              break;
           case 19:
              multiplier = 200;
              break;
           case 20:
              multiplier = 90;
              break;
           case 21:
              multiplier = 50;
              break;
           case 22:
              multiplier = 100;
              break;
           case 23:
              multiplier = 150;
              break;
           case 24:
              multiplier = 250;
              break;
           case 25:
              multiplier = 500;
              break;
           case 26:
              multiplier = 750;
              break;
           case 27:
              multiplier = 1000;
              break;
           case 28:
              multiplier = 35;
              break;
           case 29:
              multiplier = 25;
              break;
           case 30:
              multiplier = 20;
              break;
           case 31:
              multiplier = 800;
              break;
           case 32:
              multiplier = 900;
              break;
           case 33:
              multiplier = 950;
              break;
           case 34:
              multiplier = 300;
              break;
           case 35:
              multiplier = 220;
              break;
           case 36:
              multiplier = 130;
              break;
           case 37:
              multiplier = 88;
              break;
           case 38:
              multiplier = 83;
              break;
           case 39:
              multiplier = 68;
              break;
           case 40:
              multiplier = 100;
              break;
           case 41:
              multiplier = 30;
              break;
           case 42:
              multiplier = 28;
              break;
           case 43:
              multiplier = 42;
              break;
           case 44:
              multiplier = 125;
              break;
           case 45:
              multiplier = 15;
              break;
           case 46:
              multiplier = 22;
              break;
           case 47:
              multiplier = 82;
              break;
           case 48:
              multiplier = 100;
              break;
           case 49:
              multiplier = 80;
              break;
           case 51:
              multiplier = 45;
              break;
           case 50:
              multiplier = 38;
              break;
           case 52:
              multiplier = 550;
              break;
           case 53:
              multiplier = 205;
              break;
           case 54:
              multiplier = 235;
              break;
           case 55:
              multiplier = 920;
              break;
           case 56:
              multiplier = 60;
        }
       if( obj->craftsmanship != 0 )
       {
           multiplier = (obj->craftsmanship * multiplier) / 7;
       }
       switch( obj->item_type )
       {
           default:
             value = 10;
             break;
           case 9:
             value = obj->value[0] * obj->value[0] * 6 + 10;
             break;
           case 5:
             value = (obj->value[1] * obj->value[2] * 2) * 50;
             break;
           case 4:
           case 2:
           case 3:
           case 10:
             value = 10000;
             break;
           case 19:
             value = 20;
             break;
           case 1:
             value = 10;
             break;
           case 17:
             value = 18;
             break;
           case 21:
             value = 80;
             break;
           case 15:
             value = 50;
             break;
           case 36:
             value = 40;
             break;
           case 34:
             value = 90;
             break;
           case 33:
             value = (3 * obj->value[2]) + 10;
             break;
           case 8:
             value = 100;
             break;
           case 11:
             value = 11;
             break;
           case 13:
             value = 1;
             break;
           case 22:
             value = 100;
             break;
           case 28:
             value = 1000;
             break;
           case 32:
             value = 100;
             break;
       }
       multiplier = number_fuzzy( multiplier );
       obj->cost = (( value * multiplier ) / 100);
       if( obj->condition != 0 )
          obj->cost = ( obj->cost * obj->condition ) / 100;
       if( obj->cost == 0 )
         obj->cost = 1;
}

canonical_original_code:
void set_cost(struct obj_index_data *obj)
{
        int multiplier;
        int value;
        switch( obj->material )
        {
           default:
              bug( "Unrecognized material type %d.  Setting to default.", obj->material );
              multiplier = 100;
              break;
           case 0:
              multiplier = 100;
              break;
           case 1:
              multiplier = 100;
              break;
           case 2:
              multiplier = 30;
              break;
           case 3:
              multiplier = 60;
              break;
           case 4:
              multiplier = 20;
              break;
           case 5:
              multiplier = 50;
              break;
           case 6:
              multiplier = 70;
              break;
           case 7:
              multiplier = 130;
              break;
           case 8:
              multiplier = 140;
              break;
           case 9:
              multiplier = 65;
              break;
           case 10:
              multiplier = 35;
              break;
           case 11:
              multiplier = 80;
              break;
           case 12:
              multiplier = 60;
              break;
           case 13:
              multiplier = 80;
              break;
           case 14:
              multiplier = 85;
              break;
           case 15:
              multiplier = 100;
              break;
           case 16:
              multiplier = 110;
              break;
           case 17:
              multiplier = 95;
              break;
           case 18:
              multiplier = 150;
              break;
           case 19:
              multiplier = 200;
              break;
           case 20:
              multiplier = 90;
              break;
           case 21:
              multiplier = 50;
              break;
           case 22:
              multiplier = 100;
              break;
           case 23:
              multiplier = 150;
              break;
           case 24:
              multiplier = 250;
              break;
           case 25:
              multiplier = 500;
              break;
           case 26:
              multiplier = 750;
              break;
           case 27:
              multiplier = 1000;
              break;
           case 28:
              multiplier = 35;
              break;
           case 29:
              multiplier = 25;
              break;
           case 30:
              multiplier = 20;
              break;
           case 31:
              multiplier = 800;
              break;
           case 32:
              multiplier = 900;
              break;
           case 33:
              multiplier = 950;
              break;
           case 34:
              multiplier = 300;
              break;
           case 35:
              multiplier = 220;
              break;
           case 36:
              multiplier = 130;
              break;
           case 37:
              multiplier = 88;
              break;
           case 38:
              multiplier = 83;
              break;
           case 39:
              multiplier = 68;
              break;
           case 40:
              multiplier = 100;
              break;
           case 41:
              multiplier = 30;
              break;
           case 42:
              multiplier = 28;
              break;
           case 43:
              multiplier = 42;
              break;
           case 44:
              multiplier = 125;
              break;
           case 45:
              multiplier = 15;
              break;
           case 46:
              multiplier = 22;
              break;
           case 47:
              multiplier = 82;
              break;
           case 48:
              multiplier = 100;
              break;
           case 49:
              multiplier = 80;
              break;
           case 51:
              multiplier = 45;
              break;
           case 50:
              multiplier = 38;
              break;
           case 52:
              multiplier = 550;
              break;
           case 53:
              multiplier = 205;
              break;
           case 54:
              multiplier = 235;
              break;
           case 55:
              multiplier = 920;
              break;
           case 56:
              multiplier = 60;
        }
       if( obj->craftsmanship != 0 )
       {
           multiplier = (obj->craftsmanship * multiplier) / 7;
       }
       switch( obj->item_type )
       {
           default:
             value = 10;
             break;
           case 9:
             value = obj->value[0] * obj->value[0] * 6 + 10;
             break;
           case 5:
             value = (obj->value[1] * obj->value[2] * 2) * 50;
             break;
           case 4:
           case 2:
           case 3:
           case 10:
             value = 10000;
             break;
           case 19:
             value = 20;
             break;
           case 1:
             value = 10;
             break;
           case 17:
             value = 18;
             break;
           case 21:
             value = 80;
             break;
           case 15:
             value = 50;
             break;
           case 36:
             value = 40;
             break;
           case 34:
             value = 90;
             break;
           case 33:
             value = (3 * obj->value[2]) + 10;
             break;
           case 8:
             value = 100;
             break;
           case 11:
             value = 11;
             break;
           case 13:
             value = 1;
             break;
           case 22:
             value = 100;
             break;
           case 28:
             value = 1000;
             break;
           case 32:
             value = 100;
             break;
       }
       multiplier = number_fuzzy( multiplier );
       obj->cost = (( value * multiplier ) / 100);
       if( obj->condition != 0 )
          obj->cost = ( obj->cost * obj->condition ) / 100;
       if( obj->cost == 0 )
         obj->cost = 1;
}

variable_types: struct obj_index_data { struct obj_index_data *next; unsigned char (*spec_fun)(struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *group_leader; struct char_data *fighting; struct char_data *reply; struct char_data *riding; struct char_data *rider; struct char_data *next_in_group; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); unsigned char (*death_fun)(struct char_data *ch, int cmd); struct shop_data { struct shop_data *next; struct area_data { struct area_data *next; struct reset_data { struct reset_data *next; char command; int arg0; int arg1; int arg2; int arg3; int arg4; int arg5; int arg6; int arg7; } *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; } *area; int keeper; int buy_type[10]; int sell_item[20]; int profit_buy; int profit_sell; int open_hour; int close_hour; } *pShop; struct area_data *area; char *player_name; char *short_descr; char *long_descr; char *description; int vnum; int count; int killed; int sex; int c_class; int level; int act; int affected_by[5]; int alignment; int race; int position; int progtypes; int resistant; int immune; int susceptible; } *pIndexData; struct affect_data { struct affect_data *next; int skill; int spell; int song; int duration; int location; int modifier; int bitvector[5]; int level; unsigned char deleted; } *affected; struct obj_data *carrying; struct room_index_data { struct room_index_data *next; struct char_data *people; struct obj_data *contents; struct extra_descr_data { struct extra_descr_data *next; char *keyword; char *description; unsigned char deleted; } *extra_descr; struct area_data *area; struct exit_data { struct room_index_data *to_room; int vnum; int exit_info; int key; char *keyword; char *description; struct exit_data *next; } *exit[10]; char *name; char *description; int vnum; int room_flags[2]; int orig_room_flags; int light; int current; int current_dir; int fall_chance; int sector_type; int extra_sector_info; struct reset_data *reset_first; struct reset_data *reset_last; } *in_room; struct room_index_data *was_in_room; char *name; char *short_descr; char *long_descr; char *description; int sex; int c_class; int race; int level; int trust; int size; int played; int cast_spl; int cast_time; int perm_str; int perm_int; int perm_wis; int perm_dex; int perm_con; int perm_agi; int perm_cha; int perm_pow; int perm_luk; int mod_str; int mod_int; int mod_wis; int mod_dex; int mod_con; int mod_agi; int mod_cha; int mod_pow; int mod_luk; long logon; long save_time; long last_note; int timer; int wait; int hit; int max_hit; int mana; int max_mana; int move; int max_move; struct coin_data { int copper; int silver; int gold; int platinum; } money; int exp; int act; int affected_by[5]; int position; int carry_weight; int carry_number; int saving_throw[5]; int alignment; int hitroll; int damroll; int armor; int wimpy; int deaf; unsigned char deleted; int mpactnum; int resistant; int immune; int susceptible; int fly_level; int load_room_vnum; } *keeper, unsigned char hit); struct char_data *carried_by; struct extra_descr_data *extra_descr; struct affect_data *affected; struct obj_index_data *pIndexData; struct room_index_data *in_room; struct trap_data { int trigger; int damage; int charges; int level; int percent; } *trap; char *name; char *short_descr; char *description; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int wear_loc; int weight; int cost; int level; int timer; int value[8]; int condition; unsigned char deleted; int fly_level; } *obj, struct char_data *keeper, unsigned char hit); struct extra_descr_data *extra_descr; struct affect_data *affected; struct trap_data *trap; char *name; char *short_descr; char *description; int vnum; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int count; int weight; int cost; int level; int progtypes; int condition; int value[8]; struct area_data *area; } *

variable_types: multiplier int

variable_types: value int


repo: Xangis/ModernMUDConverter

original_code:
static unsigned get_string_hash( register const char *key, int len )
{
    register int i = ( ( len ) < ( 32 ) ? ( len ) : ( 32 ) );
    register unsigned hash = 0;
    while( i-- )
 hash = hash * 33U + *key++;
    return hash % 32771;
}

canonical_original_code:
static unsigned int get_string_hash(char *key, int len)
{
    register int i = ( ( len ) < ( 32 ) ? ( len ) : ( 32 ) );
    register unsigned int hash = 0;
    while( i-- )
 hash = hash * 33U + *key++;
    return hash % 32771;
}

variable_types:
key
char *

variable_types: len int

variable_types: i int

variable_types:
hash
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall is_number(_BYTE *a1)
{
char v1; // bl
__int64 result; // rax
_BYTE *v3; // rbp
const unsigned __int16 *v4; // rax

v1 = *a1;
result = 0LL;
if ( *a1 )
{
v3 = a1;
if ( ((v1 - 43) & 0xFD) == 0 )
{
v1 = a1[1];
if ( !v1 )
return 1LL;
v3 = a1 + 1;
}
v4 = *_ctype_b_loc();
while ( (v4[v1] & 0x800) != 0 )
{
v1 = *++v3;
if ( !*v3 )
return 1LL;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
char v1; // bl
__int64 result; // rax
_BYTE *v3; // rbp
const unsigned __int16 *v4; // rax

v1 = *a1;
result = 0LL;
if ( *a1 )
{
v3 = a1;
if ( ((v1 - 43) & 0xFD) == 0 )
{
v1 = a1[1];
if ( !v1 )
return 1LL;
v3 = a1 + 1;
}
v4 = *_ctype_b_loc();
while ( (v4[v1] & 0x800) != 0 )
{
v1 = *++v3;
if ( !*v3 )
return 1LL;
}
result = 0LL;
}
return result;
}

original_code:
bool is_number( char *arg )
{
    if ( *arg == '\0' )
 return 0;
    if ( *arg == '+' || *arg == '-' )
        arg++;
    for ( ; *arg != '\0'; arg++ )
    {
 if ( !((*__ctype_b_loc ())[(int) ((*arg))] & (unsigned short int) _ISdigit) )
     return 0;
    }
    return 1;
}

canonical_original_code:
unsigned char is_number(char *arg)
{
    if ( *arg == '\0' )
 return 0;
    if ( *arg == '+' || *arg == '-' )
        arg++;
    for ( ; *arg != '\0'; arg++ )
    {
 if ( !((*__ctype_b_loc ())[(int) ((*arg))] & (unsigned short) _ISdigit) )
     return 0;
    }
    return 1;
}

variable_types:
arg
char *

return_type: unsigned char


decompiled_code:
bool __fastcall char_is_number(char a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

canonical_decompiled_code:
bool __fastcall func2(char a1)
{
return (unsigned int)(a1 - 48) <= 9;
}

original_code:
bool char_is_number( char arg )
{
    switch( arg )
    {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
        return 1;
    default:
        return 0;
    }
}

canonical_original_code:
unsigned char char_is_number(char arg)
{
    switch( arg )
    {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
        return 1;
    default:
        return 0;
    }
}

variable_types: arg char


decompiled_code:
char *__fastcall one_argument(char *a1, char *a2)
{
const unsigned __int16 **v4; // rdi
char v5; // dl
char v6; // al
char *result; // rax

v4 = _ctype_b_loc();
while ( 1 )
{
v5 = *a1;
if ( ((*v4)[*a1] & 0x2000) == 0 )
break;
++a1;
}
if ( v5 == 39 || v5 == 34 )
++a1;
else
v5 = 32;
v6 = *a1;
if ( *a1 )
{
while ( v5 != v6 )
{
if ( (unsigned __int8)(v6 - 65) < 0x1Au )
v6 += 32;
*a2++ = v6;
v6 = *++a1;
if ( !*a1 )
{
result = a1;
goto LABEL_15;
}
}
result = a1 + 1;
}
else
{
result = a1;
}
LABEL_15:
for ( *a2 = 0; ((*v4)[*result] & 0x2000) != 0; ++result )
;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1, char *a2)
{
const unsigned __int16 **v4; // rdi
char v5; // dl
char v6; // al
char *result; // rax

v4 = _ctype_b_loc();
while ( 1 )
{
v5 = *a1;
if ( ((*v4)[*a1] & 0x2000) == 0 )
break;
++a1;
}
if ( v5 == 39 || v5 == 34 )
++a1;
else
v5 = 32;
v6 = *a1;
if ( *a1 )
{
while ( v5 != v6 )
{
if ( (unsigned __int8)(v6 - 65) < 0x1Au )
v6 += 32;
*a2++ = v6;
v6 = *++a1;
if ( !*a1 )
{
result = a1;
goto LABEL_15;
}
}
result = a1 + 1;
}
else
{
result = a1;
}
LABEL_15:
for ( *a2 = 0; ((*v4)[*result] & 0x2000) != 0; ++result )
;
return result;
}

original_code:
char *one_argument( char *argument, char *arg_first )
{
    char cEnd;
    while ( ((*__ctype_b_loc ())[(int) ((*argument))] & (unsigned short int) _ISspace) )
 argument++;
    cEnd = ' ';
    if ( *argument == '\'' || *argument == '"' )
 cEnd = *argument++;
    while ( *argument != '\0' )
    {
 if ( *argument == cEnd )
 {
     argument++;
     break;
 }
 *arg_first = ( ( *argument ) >= 'A' && ( *argument ) <= 'Z' ? ( *argument ) + 'a' - 'A' : ( *argument ) );
 arg_first++;
 argument++;
    }
    *arg_first = '\0';
    while ( ((*__ctype_b_loc ())[(int) ((*argument))] & (unsigned short int) _ISspace) )
 argument++;
    return argument;
}

canonical_original_code:
char *one_argument(char *argument, char *arg_first)
{
    char cEnd;
    while ( ((*__ctype_b_loc ())[(int) ((*argument))] & (unsigned short) _ISspace) )
 argument++;
    cEnd = ' ';
    if ( *argument == '\'' || *argument == '"' )
 cEnd = *argument++;
    while ( *argument != '\0' )
    {
 if ( *argument == cEnd )
 {
     argument++;
     break;
 }
 *arg_first = ( ( *argument ) >= 'A' && ( *argument ) <= 'Z' ? ( *argument ) + 'a' - 'A' : ( *argument ) );
 arg_first++;
 argument++;
    }
    *arg_first = '\0';
    while ( ((*__ctype_b_loc ())[(int) ((*argument))] & (unsigned short) _ISspace) )
 argument++;
    return argument;
}

variable_types:
argument
char *

variable_types: cEnd char

return_type: char *


decompiled_code:
void *init_string_space()
{
size_t v0; // rbx
char *v1; // rax
__int64 v2; // rcx
char *v3; // rdx
void *result; // rax

v0 = MAX_STRING;
v1 = (char *)malloc(MAX_STRING);
string_space = (__int64)v1;
if ( !v1 )
{
bug("init_string_space: Cant allocate shared string space.", 0LL);
getchar();
exit(1);
}
v2 = (__int64)v1;
top_string = (__int64)&v1[v0 - 1];
ssm_buf_head = (__int64)v1;
HEADER_SIZE = 12;
*((_WORD *)v1 + 5) = 0;
*((_WORD *)v1 + 4) = -28;
v3 = v1 + 67026960;
do
{
v1 += 65520;
*((_QWORD *)v1 - 8190) = v1;
*((_WORD *)v1 + 5) = 0;
*((_WORD *)v1 + 4) = -28;
}
while ( v1 != v3 );
*(_QWORD *)(v2 + 67026960) = 0LL;
ssm_buf_free = v2;
result = calloc(8uLL, 0x8003uLL);
temp_string_hash = result;
return result;
}

canonical_decompiled_code:
void *func4()
{
size_t v0; // rbx
char *v1; // rax
__int64 v2; // rcx
char *v3; // rdx
void *result; // rax

v0 = MAX_STRING;
v1 = (char *)malloc(MAX_STRING);
string_space = (__int64)v1;
if ( !v1 )
{
bug("init_string_space: Cant allocate shared string space.", 0LL);
getchar();
exit(1);
}
v2 = (__int64)v1;
top_string = (__int64)&v1[v0 - 1];
ssm_buf_head = (__int64)v1;
HEADER_SIZE = 12;
*((_WORD *)v1 + 5) = 0;
*((_WORD *)v1 + 4) = -28;
v3 = v1 + 67026960;
do
{
v1 += 65520;
*((_QWORD *)v1 - 8190) = v1;
*((_WORD *)v1 + 5) = 0;
*((_WORD *)v1 + 4) = -28;
}
while ( v1 != v3 );
*(_QWORD *)(v2 + 67026960) = 0LL;
ssm_buf_free = v2;
result = calloc(8uLL, 0x8003uLL);
temp_string_hash = result;
return result;
}

original_code:
void init_string_space()
{
    BufEntry *walk;
    int i;
    string_space = (char *)malloc( MAX_STRING );
    if( !string_space )
    {
  bug( "init_string_space: Cant allocate shared string space.", 0 );
  getchar();
        exit(1);
    }
    top_string = string_space + MAX_STRING-1;
    ssm_buf_head = (BufEntry *)string_space;
    HEADER_SIZE = (int)( (char*)&ssm_buf_head->buf[0] - (char*)ssm_buf_head );
    walk = ssm_buf_head;
    for( i = 0; ;i++ )
    {
 walk->usage = 0;
 walk->size = 0xfff0 - HEADER_SIZE;
 if( i < 1024 - 1 )
 {
     walk->next = (BufEntry *)( (char*)walk + 0xfff0 );
     walk = walk->next;
     continue;
 }
 walk->next = 0;
 break;
    }
    ssm_buf_free = ssm_buf_head;
    temp_string_hash = (TempHash **)calloc( sizeof(TempHash *),
           32771 );
}

canonical_original_code:
void init_string_space()
{
    struct BE *walk;
    int i;
    string_space = (char *)malloc( MAX_STRING );
    if( !string_space )
    {
  bug( "init_string_space: Cant allocate shared string space.", 0 );
  getchar();
        exit(1);
    }
    top_string = string_space + MAX_STRING-1;
    ssm_buf_head = (struct BE *)string_space;
    HEADER_SIZE = (int)( (char *)&ssm_buf_head->buf[0] - (char *)ssm_buf_head );
    walk = ssm_buf_head;
    for( i = 0; ;i++ )
    {
 walk->usage = 0;
 walk->size = 0xfff0 - HEADER_SIZE;
 if( i < 1024 - 1 )
 {
     walk->next = (struct BE *)( (char *)walk + 0xfff0 );
     walk = walk->next;
     continue;
 }
 walk->next = 0;
 break;
    }
    ssm_buf_free = ssm_buf_head;
    temp_string_hash = (struct TH **)calloc( sizeof(struct TH *),
           32771 );
}

variable_types: struct BE { struct BE *next; unsigned short size; short usage; char buf[1]; } *

return_type: void

user_defined_types: struct TH { struct TH *next; char *str; }


decompiled_code:
__int64 __fastcall defrag_heap(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rax
unsigned int v5; // ebx
unsigned __int16 v6; // si
unsigned __int16 v7; // r8

ssm_buf_free = 0LL;
v4 = (_QWORD *)ssm_buf_head;
if ( !ssm_buf_head )
{
v5 = 0;
LABEL_16:
bug("[SSM] defrag_heap : resulted in 0 merges.", 0LL, a3, a4);
goto LABEL_14;
}
v5 = 0;
a4 = 0LL;
do
{
a3 = (__int64)v4;
v4 = (_QWORD *)*v4;
if ( *(__int16 *)(a3 + 10) > 0 )
{
a4 = 0LL;
}
else if ( a4 )
{
v6 = *(_WORD *)(a4 + 8);
v7 = *(_WORD *)(a3 + 8);
if ( (__int64)(v7 + (unsigned __int64)v6) > 65520 )
{
a4 = a3;
}
else
{
++v5;
*(_WORD *)(a4 + 8) = HEADER_SIZE + v7 + v6;
a3 = *(_QWORD *)a3;
*(_QWORD *)a4 = a3;
*(_WORD *)(a4 + 10) = 0;
}
}
else
{
a4 = a3;
if ( !ssm_buf_free )
ssm_buf_free = a3;
}
}
while ( v4 );
if ( !v5 )
goto LABEL_16;
bug("[SSM] defrag_heap : made %d block merges.", v5);
LABEL_14:
numFree = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_QWORD *v4; // rax
unsigned int v5; // ebx
unsigned __int16 v6; // si
unsigned __int16 v7; // r8

ssm_buf_free = 0LL;
v4 = (_QWORD *)ssm_buf_head;
if ( !ssm_buf_head )
{
v5 = 0;
LABEL_16:
bug("[SSM] defrag_heap : resulted in 0 merges.", 0LL, a3, a4);
goto LABEL_14;
}
v5 = 0;
a4 = 0LL;
do
{
a3 = (__int64)v4;
v4 = (_QWORD *)*v4;
if ( *(__int16 *)(a3 + 10) > 0 )
{
a4 = 0LL;
}
else if ( a4 )
{
v6 = *(_WORD *)(a4 + 8);
v7 = *(_WORD *)(a3 + 8);
if ( (__int64)(v7 + (unsigned __int64)v6) > 65520 )
{
a4 = a3;
}
else
{
++v5;
*(_WORD *)(a4 + 8) = HEADER_SIZE + v7 + v6;
a3 = *(_QWORD *)a3;
*(_QWORD *)a4 = a3;
*(_WORD *)(a4 + 10) = 0;
}
}
else
{
a4 = a3;
if ( !ssm_buf_free )
ssm_buf_free = a3;
}
}
while ( v4 );
if ( !v5 )
goto LABEL_16;
bug("[SSM] defrag_heap : made %d block merges.", v5);
LABEL_14:
numFree = 0;
return v5;
}

original_code:
int defrag_heap()
{
    BufEntry *walk, *last_free, *next;
    int merges = 0;
    ssm_buf_free = 0;
    for( walk=ssm_buf_head,last_free=0; walk; walk = next )
      {
 next = walk->next;
 if( walk->usage > 0 )
 {
     last_free = 0;
     continue;
 }
 else if( !last_free )
 {
     last_free = walk;
     if( !ssm_buf_free )
         ssm_buf_free = walk;
     continue;
 }
 else
 {
     if( (long)last_free->size + (long)walk->size <= 0xfff0 )
     {
  merges++;
  last_free->size += walk->size + HEADER_SIZE;
  last_free->next = walk->next;
  last_free->usage = 0;
     }
     else
         last_free = walk;
 }
    }
    if( merges )
        bug( "[SSM] defrag_heap : made %d block merges.", merges );
    else
        bug( "[SSM] defrag_heap : resulted in 0 merges.", 0 );
    numFree = 0;
    return merges;
}

canonical_original_code:
int defrag_heap()
{
    struct BE *walk; struct BE *last_free; struct BE *next;
    int merges = 0;
    ssm_buf_free = 0;
    for( walk=ssm_buf_head,last_free=0; walk; walk = next )
      {
 next = walk->next;
 if( walk->usage > 0 )
 {
     last_free = 0;
     continue;
 }
 else if( !last_free )
 {
     last_free = walk;
     if( !ssm_buf_free )
         ssm_buf_free = walk;
     continue;
 }
 else
 {
     if( (long)last_free->size + (long)walk->size <= 0xfff0 )
     {
  merges++;
  last_free->size += walk->size + HEADER_SIZE;
  last_free->next = walk->next;
  last_free->usage = 0;
     }
     else
         last_free = walk;
 }
    }
    if( merges )
        bug( "[SSM] defrag_heap : made %d block merges.", merges );
    else
        bug( "[SSM] defrag_heap : resulted in 0 merges.", 0 );
    numFree = 0;
    return merges;
}

variable_types: merges int

return_type: int

user_defined_types: struct BE { struct BE *next; unsigned short size; short usage; char buf[1]; }


decompiled_code:
char *__fastcall str_dup(char *src)
{
char *v1; // rbp
int v2; // eax
int v3; // er13
int v4; // ebp
char *v5; // rbx
__int64 v6; // rbx
unsigned __int16 v7; // dx
int v8; // esi
__int64 v9; // rax
__int64 v11; // rax
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rcx

if ( !src )
return (char *)&str_empty;
v1 = (char *)&str_empty;
if ( *src )
{
if ( string_space < (unsigned __int64)src && top_string > (unsigned __int64)src )
{
v5 = &src[-HEADER_SIZE];
if ( *((__int16 *)v5 + 5) <= 0 )
{
bug("str_dup : invalid str", 0LL);
bug(src, 0LL);
}
++*((_WORD *)v5 + 5);
v1 = src;
}
else
{
v2 = strlen(src);
v3 = v2 + 1;
v4 = v2 + 1;
if ( (((_BYTE)HEADER_SIZE + (_BYTE)v2 + 1) & 7) != 0 )
v4 = v2 + 9 - (((_BYTE)HEADER_SIZE + (_BYTE)v2 + 1) & 7);
if ( ssm_buf_free )
{
while ( 1 )
{
v14 = ssm_buf_free;
if ( ssm_buf_free )
break;
LABEL_29:
if ( numFree > 999 )
{
bug("[SSM] Attempting to optimize shared string heap.", 0LL);
if ( (unsigned int)defrag_heap((__int64)"[SSM] Attempting to optimize shared string heap.", 0LL, v12, v13) )
continue;
}
goto LABEL_24;
}
v6 = ssm_buf_free;
while ( 1 )
{
if ( !*(_WORD *)(v6 + 10) )
{
v7 = *(_WORD *)(v6 + 8);
if ( v7 >= v4 )
break;
}
v6 = *(_QWORD *)v6;
if ( !v6 )
goto LABEL_29;
}
v8 = HEADER_SIZE;
if ( v7 - v4 >= HEADER_SIZE )
{
v11 = v6 + v4 + (__int64)HEADER_SIZE;
*(_WORD *)(v11 + 8) = v7 - (v4 + HEADER_SIZE);
*(_QWORD *)v11 = *(_QWORD *)v6;
*(_WORD *)(v11 + 10) = 0;
*(_WORD *)(v6 + 8) = v4;
*(_QWORD *)v6 = v11;
*(_WORD *)(v6 + 10) = 1;
ssm_buf_free = v6 + v4 + (__int64)v8;
}
else
{
*(_WORD *)(v6 + 10) = 1;
if ( v14 != v6 )
--*(_WORD *)(v14 + 10);
v9 = ssm_buf_head;
for ( ssm_buf_free = ssm_buf_head; v9; ssm_buf_free = v9 )
{
if ( !*(_WORD *)(v9 + 10) )
break;
v9 = *(_QWORD *)v9;
}
}
v1 = (char *)(v6 + 12);
strcpy((char *)(v6 + 12), src);
++nAllocString;
sAllocString += HEADER_SIZE + *(unsigned __int16 *)(v6 + 8);
}
else
{
if ( !Full )
{
bug("[SSM] The shared string heap is full!", 0LL);
Full = 1;
}
LABEL_24:
v1 = (char *)malloc(v3);
strcpy(v1, src);
sOverFlowString += v3;
++nOverFlowString;
}
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func6(char *src)
{
char *v1; // rbp
int v2; // eax
int v3; // er13
int v4; // ebp
char *v5; // rbx
__int64 v6; // rbx
unsigned __int16 v7; // dx
int v8; // esi
__int64 v9; // rax
__int64 v11; // rax
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rcx

if ( !src )
return (char *)&str_empty;
v1 = (char *)&str_empty;
if ( *src )
{
if ( string_space < (unsigned __int64)src && top_string > (unsigned __int64)src )
{
v5 = &src[-HEADER_SIZE];
if ( *((__int16 *)v5 + 5) <= 0 )
{
bug("str_dup : invalid str", 0LL);
bug(src, 0LL);
}
++*((_WORD *)v5 + 5);
v1 = src;
}
else
{
v2 = strlen(src);
v3 = v2 + 1;
v4 = v2 + 1;
if ( (((_BYTE)HEADER_SIZE + (_BYTE)v2 + 1) & 7) != 0 )
v4 = v2 + 9 - (((_BYTE)HEADER_SIZE + (_BYTE)v2 + 1) & 7);
if ( ssm_buf_free )
{
while ( 1 )
{
v14 = ssm_buf_free;
if ( ssm_buf_free )
break;
LABEL_29:
if ( numFree > 999 )
{
bug("[SSM] Attempting to optimize shared string heap.", 0LL);
if ( (unsigned int)func5((__int64)"[SSM] Attempting to optimize shared string heap.", 0LL, v12, v13) )
continue;
}
goto LABEL_24;
}
v6 = ssm_buf_free;
while ( 1 )
{
if ( !*(_WORD *)(v6 + 10) )
{
v7 = *(_WORD *)(v6 + 8);
if ( v7 >= v4 )
break;
}
v6 = *(_QWORD *)v6;
if ( !v6 )
goto LABEL_29;
}
v8 = HEADER_SIZE;
if ( v7 - v4 >= HEADER_SIZE )
{
v11 = v6 + v4 + (__int64)HEADER_SIZE;
*(_WORD *)(v11 + 8) = v7 - (v4 + HEADER_SIZE);
*(_QWORD *)v11 = *(_QWORD *)v6;
*(_WORD *)(v11 + 10) = 0;
*(_WORD *)(v6 + 8) = v4;
*(_QWORD *)v6 = v11;
*(_WORD *)(v6 + 10) = 1;
ssm_buf_free = v6 + v4 + (__int64)v8;
}
else
{
*(_WORD *)(v6 + 10) = 1;
if ( v14 != v6 )
--*(_WORD *)(v14 + 10);
v9 = ssm_buf_head;
for ( ssm_buf_free = ssm_buf_head; v9; ssm_buf_free = v9 )
{
if ( !*(_WORD *)(v9 + 10) )
break;
v9 = *(_QWORD *)v9;
}
}
v1 = (char *)(v6 + 12);
strcpy((char *)(v6 + 12), src);
++nAllocString;
sAllocString += HEADER_SIZE + *(unsigned __int16 *)(v6 + 8);
}
else
{
if ( !Full )
{
bug("[SSM] The shared string heap is full!", 0LL);
Full = 1;
}
LABEL_24:
v1 = (char *)malloc(v3);
strcpy(v1, src);
sOverFlowString += v3;
++nOverFlowString;
}
}
}
return v1;
}

original_code:
char *str_dup( const char *str )
{
    BufEntry *ptr;
    char *str_new;
    int len;
    int rlen;
    if( !str || !*str )
        return &str_empty[0];
    if( str > string_space && str < top_string )
    {
 ptr = (BufEntry *)( str - HEADER_SIZE );
 if( ptr->usage <= 0 )
 {
     bug( "str_dup : invalid str", 0 );
     bug( str, 0 );
 }
 ptr->usage++;
 return (char *)str;
    }
    rlen = len = (int)strlen( str ) + 1;
    if( ( len + HEADER_SIZE ) & ( sizeof( void * ) - 1 ) )
        len += ( sizeof( void * ) ) - ( ( len + HEADER_SIZE ) & ( sizeof( void * ) - 1 ) );
    if( ssm_buf_free )
    {
        RETRY:
 for( ptr = ssm_buf_free; ptr; ptr = ptr->next )
     if( ptr->usage == 0 && ptr->size >= len )
         break;
 if( !ptr )
 {
     if( numFree >= 1000 )
     {
  int merges;
  bug( "[SSM] Attempting to optimize shared string heap.", 0 );
  merges = defrag_heap();
  if( merges )
      goto RETRY;
     }
     str_new = (char *)malloc( rlen );
     strcpy( str_new, str );
     sOverFlowString += rlen;
     nOverFlowString++;
     return str_new;
 }
 else if( ptr->size - len >= HEADER_SIZE )
 {
     BufEntry *temp;
     temp = (BufEntry*)( (char *)ptr + HEADER_SIZE + len );
     temp->size = ptr->size - ( len + HEADER_SIZE );
     temp->next = ptr->next;
     temp->usage = 0;
     ptr->size = len;
     ptr->next = temp;
     ptr->usage = 1;
     ssm_buf_free = temp;
 }
 else
 {
     ptr->usage = 1;
     if( ptr != ssm_buf_free )
         ssm_buf_free->usage--;
     for( ssm_buf_free = ssm_buf_head; ssm_buf_free;
  ssm_buf_free = ssm_buf_free->next )
         if( ssm_buf_free->usage == 0 )
      break;
 }
 str_new = (char *)&ptr->buf[0];
 strcpy( str_new, str );
 nAllocString++;
 sAllocString += ptr->size + HEADER_SIZE;
    }
    else
    {
 if( !Full )
 {
     bug( "[SSM] The shared string heap is full!", 0 );
     Full = 1;
 }
 str_new = (char *)malloc( rlen );
 strcpy( str_new, str );
 sOverFlowString += rlen;
 nOverFlowString++;
    }
    return str_new;
}

canonical_original_code:
char *str_dup(char *str)
{
    struct BE *ptr;
    char *str_new;
    int len;
    int rlen;
    if( !str || !*str )
        return &str_empty[0];
    if( str > string_space && str < top_string )
    {
 ptr = (struct BE *)( str - HEADER_SIZE );
 if( ptr->usage <= 0 )
 {
     bug( "str_dup : invalid str", 0 );
     bug( str, 0 );
 }
 ptr->usage++;
 return (char *)str;
    }
    rlen = len = (int)strlen( str ) + 1;
    if( ( len + HEADER_SIZE ) & ( sizeof( void * ) - 1 ) )
        len += ( sizeof( void * ) ) - ( ( len + HEADER_SIZE ) & ( sizeof( void * ) - 1 ) );
    if( ssm_buf_free )
    {
        RETRY:
 for( ptr = ssm_buf_free; ptr; ptr = ptr->next )
     if( ptr->usage == 0 && ptr->size >= len )
         break;
 if( !ptr )
 {
     if( numFree >= 1000 )
     {
  int merges;
  bug( "[SSM] Attempting to optimize shared string heap.", 0 );
  merges = defrag_heap();
  if( merges )
      goto RETRY;
     }
     str_new = (char *)malloc( rlen );
     strcpy( str_new, str );
     sOverFlowString += rlen;
     nOverFlowString++;
     return str_new;
 }
 else if( ptr->size - len >= HEADER_SIZE )
 {
     struct BE *temp;
     temp = (struct BE *)( (char *)ptr + HEADER_SIZE + len );
     temp->size = ptr->size - ( len + HEADER_SIZE );
     temp->next = ptr->next;
     temp->usage = 0;
     ptr->size = len;
     ptr->next = temp;
     ptr->usage = 1;
     ssm_buf_free = temp;
 }
 else
 {
     ptr->usage = 1;
     if( ptr != ssm_buf_free )
         ssm_buf_free->usage--;
     for( ssm_buf_free = ssm_buf_head; ssm_buf_free;
  ssm_buf_free = ssm_buf_free->next )
         if( ssm_buf_free->usage == 0 )
      break;
 }
 str_new = (char *)&ptr->buf[0];
 strcpy( str_new, str );
 nAllocString++;
 sAllocString += ptr->size + HEADER_SIZE;
    }
    else
    {
 if( !Full )
 {
     bug( "[SSM] The shared string heap is full!", 0 );
     Full = 1;
 }
 str_new = (char *)malloc( rlen );
 strcpy( str_new, str );
 sOverFlowString += rlen;
 nOverFlowString++;
    }
    return str_new;
}

variable_types:
str
char *

variable_types: rlen int


decompiled_code:
void __fastcall temp_hash_add(char *a1, int a2)
{
int v2; // ebp
_QWORD *v3; // rax
_QWORD *v4; // rdx

if ( fBootDb && *a1 && (string_space < (unsigned __int64)a1 || top_string > (unsigned __int64)a1) )
{
v2 = get_string_hash(a1, a2);
v3 = malloc(0x10uLL);
v4 = (char *)temp_string_hash + 8 * v2;
*v3 = *v4;
*v4 = v3;
v3[1] = a1;
}
}

canonical_decompiled_code:
void __fastcall func9(char *a1, int a2)
{
int v2; // ebp
_QWORD *v3; // rax
_QWORD *v4; // rdx

if ( fBootDb && *a1 && (string_space < (unsigned __int64)a1 || top_string > (unsigned __int64)a1) )
{
v2 = func0(a1, a2);
v3 = malloc(0x10uLL);
v4 = (char *)temp_string_hash + 8 * v2;
*v3 = *v4;
*v4 = v3;
v3[1] = a1;
}
}

original_code:
void temp_hash_add( char *str, int len )
{
    TempHash *add;
    int ihash;
    if( !fBootDb || !*str || ( str <= string_space && str >= top_string ))
 return;
    ihash = get_string_hash( str, len );
    add = (TempHash *)malloc( sizeof( TempHash ) );
    add->next = temp_string_hash[ ihash ];
    temp_string_hash[ ihash ] = add;
    add->str = str;
}

canonical_original_code:
void temp_hash_add(char *str, int len)
{
    struct TH *add;
    int ihash;
    if( !fBootDb || !*str || ( str <= string_space && str >= top_string ))
 return;
    ihash = get_string_hash( str, len );
    add = (struct TH *)malloc( sizeof( TempHash ) );
    add->next = temp_string_hash[ ihash ];
    temp_string_hash[ ihash ] = add;
    add->str = str;
}

variable_types: struct TH { struct TH *next; char *str; } *

variable_types: ihash int


decompiled_code:
void boot_done()
{
__int64 i; // rbp
_QWORD *v1; // rbx
void *v2; // rdi

for ( i = 0LL; i != 262168; i += 8LL )
{
v1 = *(_QWORD **)((char *)temp_string_hash + i);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
}
free(temp_string_hash);
temp_string_hash = 0LL;
}

canonical_decompiled_code:
void func11()
{
__int64 i; // rbp
_QWORD *v1; // rbx
void *v2; // rdi

for ( i = 0LL; i != 262168; i += 8LL )
{
v1 = *(_QWORD **)((char *)temp_string_hash + i);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
}
free(temp_string_hash);
temp_string_hash = 0LL;
}

original_code:
void boot_done( void )
{
    TempHash *ptr, *next;
    int ihash;
    for( ihash = 0; ihash < 32771; ihash++ )
    {
 for( ptr = temp_string_hash[ ihash ]; ptr; ptr = next )
 {
     next = ptr->next;
     free( ptr );
 }
    }
    free( temp_string_hash );
    temp_string_hash = 0;
}

canonical_original_code:
void boot_done()
{
    struct TH *ptr; struct TH *next;
    int ihash;
    for( ihash = 0; ihash < 32771; ihash++ )
    {
 for( ptr = temp_string_hash[ ihash ]; ptr; ptr = next )
 {
     next = ptr->next;
     free( ptr );
 }
    }
    free( temp_string_hash );
    temp_string_hash = 0;
}


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

result = alloc_perm(48LL);
++top_reset;
*(_QWORD *)result = 0LL;
*(_BYTE *)(result + 8) = 88;
*(_DWORD *)(result + 16) = 0;
*(_DWORD *)(result + 20) = 0;
*(_DWORD *)(result + 24) = 0;
return result;
}

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

result = alloc_perm(48LL);
++top_reset;
*(_QWORD *)result = 0LL;
*(_BYTE *)(result + 8) = 88;
*(_DWORD *)(result + 16) = 0;
*(_DWORD *)(result + 20) = 0;
*(_DWORD *)(result + 24) = 0;
return result;
}

original_code:
RESET_DATA *new_reset_data( void )
{
    RESET_DATA *pReset;
 pReset = alloc_perm( sizeof( *pReset ) );
 top_reset++;
    pReset->next = ((void *)0);
    pReset->command = 'X';
    pReset->arg1 = 0;
    pReset->arg2 = 0;
    pReset->arg3 = 0;
    return pReset;
}

canonical_original_code:
struct reset_data *new_reset_data()
{
    struct reset_data *pReset;
 pReset = alloc_perm( sizeof( *pReset ) );
 top_reset++;
    pReset->next = ((void *)0);
    pReset->command = 'X';
    pReset->arg1 = 0;
    pReset->arg2 = 0;
    pReset->arg3 = 0;
    return pReset;
}

variable_types: struct reset_data { struct reset_data *next; char command; int arg0; int arg1; int arg2; int arg3; int arg4; int arg5; int arg6; int arg7; } *


original_code:
AREA_DATA *new_area( void )
{
    AREA_DATA *pArea;
    char buf[ 299 ];
 pArea = alloc_perm( sizeof( *pArea ) );
 top_area++;
    pArea->next = ((void *)0);
    pArea->name = str_dup( "New area" );
    pArea->recall = 200;
    pArea->area_flags = (1 << 1);
    pArea->security = 1;
    pArea->builders = str_dup( "None" );
    pArea->lvnum = 0;
    pArea->uvnum = 0;
    pArea->age = 0;
    pArea->nplayer = 0;
    pArea->vnum = top_area - 1;
    sprintf( buf, "area%d.are", pArea->vnum );
    pArea->filename = str_dup( buf );
    return pArea;
}

canonical_original_code:
struct area_data *new_area()
{
    struct area_data *pArea;
    char buf[299];
 pArea = alloc_perm( sizeof( *pArea ) );
 top_area++;
    pArea->next = ((void *)0);
    pArea->name = str_dup( "New area" );
    pArea->recall = 200;
    pArea->area_flags = (1 << 1);
    pArea->security = 1;
    pArea->builders = str_dup( "None" );
    pArea->lvnum = 0;
    pArea->uvnum = 0;
    pArea->age = 0;
    pArea->nplayer = 0;
    pArea->vnum = top_area - 1;
    sprintf( buf, "area%d.are", pArea->vnum );
    pArea->filename = str_dup( buf );
    return pArea;
}

variable_types: struct area_data { struct area_data *next; struct reset_data { struct reset_data *next; char command; int arg0; int arg1; int arg2; int arg3; int arg4; int arg5; int arg6; int arg7; } *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; } *

variable_types:
buf
char [299]

user_defined_types: struct area_data { struct area_data *next; struct reset_data *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; }


original_code:
ROOM_INDEX_DATA *new_room_index( void )
{
    ROOM_INDEX_DATA *pRoom;
    int door;
 pRoom = alloc_perm( sizeof( *pRoom ) );
 top_room++;
    pRoom->next = ((void *)0);
    pRoom->people = ((void *)0);
    pRoom->contents = ((void *)0);
    pRoom->extra_descr = ((void *)0);
    pRoom->area = ((void *)0);
    for ( door = 0; door < 10; door++ )
 pRoom->exit[door] = ((void *)0);
    pRoom->name = &str_empty[0];
    pRoom->description = &str_empty[0];
    pRoom->vnum = 0;
    pRoom->room_flags[0]= 0;
    pRoom->room_flags[1]= 0;
    pRoom->light = 0;
    pRoom->sector_type = 0;
    return pRoom;
}

canonical_original_code:
struct room_index_data *new_room_index()
{
    struct room_index_data *pRoom;
    int door;
 pRoom = alloc_perm( sizeof( *pRoom ) );
 top_room++;
    pRoom->next = ((void *)0);
    pRoom->people = ((void *)0);
    pRoom->contents = ((void *)0);
    pRoom->extra_descr = ((void *)0);
    pRoom->area = ((void *)0);
    for ( door = 0; door < 10; door++ )
 pRoom->exit[door] = ((void *)0);
    pRoom->name = &str_empty[0];
    pRoom->description = &str_empty[0];
    pRoom->vnum = 0;
    pRoom->room_flags[0]= 0;
    pRoom->room_flags[1]= 0;
    pRoom->light = 0;
    pRoom->sector_type = 0;
    return pRoom;
}

variable_types: struct room_index_data { struct room_index_data *next; struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *group_leader; struct char_data *fighting; struct char_data *reply; struct char_data *riding; struct char_data *rider; struct char_data *next_in_group; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); unsigned char (*death_fun)(struct char_data *ch, int cmd); struct shop_data { struct shop_data *next; struct area_data { struct area_data *next; struct reset_data { struct reset_data *next; char command; int arg0; int arg1; int arg2; int arg3; int arg4; int arg5; int arg6; int arg7; } *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; } *area; int keeper; int buy_type[10]; int sell_item[20]; int profit_buy; int profit_sell; int open_hour; int close_hour; } *pShop; struct area_data *area; char *player_name; char *short_descr; char *long_descr; char *description; int vnum; int count; int killed; int sex; int c_class; int level; int act; int affected_by[5]; int alignment; int race; int position; int progtypes; int resistant; int immune; int susceptible; } *pIndexData; struct affect_data { struct affect_data *next; int skill; int spell; int song; int duration; int location; int modifier; int bitvector[5]; int level; unsigned char deleted; } *affected; struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct char_data *carried_by; struct extra_descr_data { struct extra_descr_data *next; char *keyword; char *description; unsigned char deleted; } *extra_descr; struct affect_data *affected; struct obj_index_data { struct obj_index_data *next; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct extra_descr_data *extra_descr; struct affect_data *affected; struct trap_data { int trigger; int damage; int charges; int level; int percent; } *trap; char *name; char *short_descr; char *description; int vnum; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int count; int weight; int cost; int level; int progtypes; int condition; int value[8]; struct area_data *area; } *pIndexData; struct room_index_data *in_room; struct trap_data *trap; char *name; char *short_descr; char *description; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int wear_loc; int weight; int cost; int level; int timer; int value[8]; int condition; unsigned char deleted; int fly_level; } *carrying; struct room_index_data *in_room; struct room_index_data *was_in_room; char *name; char *short_descr; char *long_descr; char *description; int sex; int c_class; int race; int level; int trust; int size; int played; int cast_spl; int cast_time; int perm_str; int perm_int; int perm_wis; int perm_dex; int perm_con; int perm_agi; int perm_cha; int perm_pow; int perm_luk; int mod_str; int mod_int; int mod_wis; int mod_dex; int mod_con; int mod_agi; int mod_cha; int mod_pow; int mod_luk; long logon; long save_time; long last_note; int timer; int wait; int hit; int max_hit; int mana; int max_mana; int move; int max_move; struct coin_data { int copper; int silver; int gold; int platinum; } money; int exp; int act; int affected_by[5]; int position; int carry_weight; int carry_number; int saving_throw[5]; int alignment; int hitroll; int damroll; int armor; int wimpy; int deaf; unsigned char deleted; int mpactnum; int resistant; int immune; int susceptible; int fly_level; int load_room_vnum; } *people; struct obj_data *contents; struct extra_descr_data *extra_descr; struct area_data *area; struct exit_data { struct room_index_data *to_room; int vnum; int exit_info; int key; char *keyword; char *description; struct exit_data *next; } *exit[10]; char *name; char *description; int vnum; int room_flags[2]; int orig_room_flags; int light; int current; int current_dir; int fall_chance; int sector_type; int extra_sector_info; struct reset_data *reset_first; struct reset_data *reset_last; } *

variable_types: door int

user_defined_types: struct room_index_data { struct room_index_data *next; struct char_data *people; struct obj_data *contents; struct extra_descr_data *extra_descr; struct area_data *area; struct exit_data *exit[10]; char *name; char *description; int vnum; int room_flags[2]; int orig_room_flags; int light; int current; int current_dir; int fall_chance; int sector_type; int extra_sector_info; struct reset_data *reset_first; struct reset_data *reset_last; }

user_defined_types: struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *group_leader; struct char_data *fighting; struct char_data *reply; struct char_data *riding; struct char_data *rider; struct char_data *next_in_group; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); struct mob_index_data *pIndexData; struct affect_data *affected; struct obj_data *carrying; struct room_index_data *in_room; struct room_index_data *was_in_room; char *name; char *short_descr; char *long_descr; char *description; int sex; int c_class; int race; int level; int trust; int size; int played; int cast_spl; int cast_time; int perm_str; int perm_int; int perm_wis; int perm_dex; int perm_con; int perm_agi; int perm_cha; int perm_pow; int perm_luk; int mod_str; int mod_int; int mod_wis; int mod_dex; int mod_con; int mod_agi; int mod_cha; int mod_pow; int mod_luk; long logon; long save_time; long last_note; int timer; int wait; int hit; int max_hit; int mana; int max_mana; int move; int max_move; struct coin_data money; int exp; int act; int affected_by[5]; int position; int carry_weight; int carry_number; int saving_throw[5]; int alignment; int hitroll; int damroll; int armor; int wimpy; int deaf; unsigned char deleted; int mpactnum; int resistant; int immune; int susceptible; int fly_level; int load_room_vnum; }

user_defined_types: struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); unsigned char (*death_fun)(struct char_data *ch, int cmd); struct shop_data *pShop; struct area_data *area; char *player_name; char *short_descr; char *long_descr; char *description; int vnum; int count; int killed; int sex; int c_class; int level; int act; int affected_by[5]; int alignment; int race; int position; int progtypes; int resistant; int immune; int susceptible; }

user_defined_types: struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct char_data *carried_by; struct extra_descr_data *extra_descr; struct affect_data *affected; struct obj_index_data *pIndexData; struct room_index_data *in_room; struct trap_data *trap; char *name; char *short_descr; char *description; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int wear_loc; int weight; int cost; int level; int timer; int value[8]; int condition; unsigned char deleted; int fly_level; }

user_defined_types: struct shop_data { struct shop_data *next; struct area_data *area; int keeper; int buy_type[10]; int sell_item[20]; int profit_buy; int profit_sell; int open_hour; int close_hour; }

user_defined_types: struct obj_index_data { struct obj_index_data *next; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct extra_descr_data *extra_descr; struct affect_data *affected; struct trap_data *trap; char *name; char *short_descr; char *description; int vnum; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int count; int weight; int cost; int level; int progtypes; int condition; int value[8]; struct area_data *area; }


original_code:
SHOP_DATA *new_shop( void )
{
    SHOP_DATA *pShop;
    int buy;
 pShop = alloc_perm( sizeof( *pShop ) );
 top_shop++;
    pShop->next = ((void *)0);
    pShop->keeper = 0;
    for ( buy = 0; buy < 10; buy++ )
 pShop->buy_type[buy] = 0;
    for ( buy = 0; buy < 20; buy++ )
 pShop->sell_item[buy] = 0;
    pShop->profit_buy = 100;
    pShop->profit_sell = 100;
    pShop->open_hour = 0;
    pShop->close_hour = 23;
    return pShop;
}

canonical_original_code:
struct shop_data *new_shop()
{
    struct shop_data *pShop;
    int buy;
 pShop = alloc_perm( sizeof( *pShop ) );
 top_shop++;
    pShop->next = ((void *)0);
    pShop->keeper = 0;
    for ( buy = 0; buy < 10; buy++ )
 pShop->buy_type[buy] = 0;
    for ( buy = 0; buy < 20; buy++ )
 pShop->sell_item[buy] = 0;
    pShop->profit_buy = 100;
    pShop->profit_sell = 100;
    pShop->open_hour = 0;
    pShop->close_hour = 23;
    return pShop;
}

variable_types: struct shop_data { struct shop_data *next; struct area_data { struct area_data *next; struct reset_data { struct reset_data *next; char command; int arg0; int arg1; int arg2; int arg3; int arg4; int arg5; int arg6; int arg7; } *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; } *area; int keeper; int buy_type[10]; int sell_item[20]; int profit_buy; int profit_sell; int open_hour; int close_hour; } *

variable_types: buy int


original_code:
OBJ_INDEX_DATA *new_obj_index( void )
{
    OBJ_INDEX_DATA *pObj;
    int value;
    int count;
 pObj = alloc_perm( sizeof( *pObj ) );
 top_obj_index++;
    pObj->next = ((void *)0);
    pObj->extra_descr = ((void *)0);
    pObj->affected = ((void *)0);
    pObj->area = ((void *)0);
    pObj->name = str_dup( "no name" );
    pObj->short_descr = str_dup( "(no short description)" );
    pObj->description = str_dup( "(no description)" );
    pObj->vnum = 0;
    pObj->item_type = 13;
    for( count = 0; count < 2; count++)
      pObj->extra_flags[count] = 0;
    pObj->wear_flags = 0;
    pObj->count = 0;
    pObj->weight = 0;
    pObj->cost = 0;
    for ( value = 0; value < 5; value++ )
 pObj->value[value] = 0;
    return pObj;
}

canonical_original_code:
struct obj_index_data *new_obj_index()
{
    struct obj_index_data *pObj;
    int value;
    int count;
 pObj = alloc_perm( sizeof( *pObj ) );
 top_obj_index++;
    pObj->next = ((void *)0);
    pObj->extra_descr = ((void *)0);
    pObj->affected = ((void *)0);
    pObj->area = ((void *)0);
    pObj->name = str_dup( "no name" );
    pObj->short_descr = str_dup( "(no short description)" );
    pObj->description = str_dup( "(no description)" );
    pObj->vnum = 0;
    pObj->item_type = 13;
    for( count = 0; count < 2; count++)
      pObj->extra_flags[count] = 0;
    pObj->wear_flags = 0;
    pObj->count = 0;
    pObj->weight = 0;
    pObj->cost = 0;
    for ( value = 0; value < 5; value++ )
 pObj->value[value] = 0;
    return pObj;
}

variable_types: struct obj_index_data { struct obj_index_data *next; unsigned char (*spec_fun)(struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *group_leader; struct char_data *fighting; struct char_data *reply; struct char_data *riding; struct char_data *rider; struct char_data *next_in_group; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); unsigned char (*death_fun)(struct char_data *ch, int cmd); struct shop_data { struct shop_data *next; struct area_data { struct area_data *next; struct reset_data { struct reset_data *next; char command; int arg0; int arg1; int arg2; int arg3; int arg4; int arg5; int arg6; int arg7; } *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; } *area; int keeper; int buy_type[10]; int sell_item[20]; int profit_buy; int profit_sell; int open_hour; int close_hour; } *pShop; struct area_data *area; char *player_name; char *short_descr; char *long_descr; char *description; int vnum; int count; int killed; int sex; int c_class; int level; int act; int affected_by[5]; int alignment; int race; int position; int progtypes; int resistant; int immune; int susceptible; } *pIndexData; struct affect_data { struct affect_data *next; int skill; int spell; int song; int duration; int location; int modifier; int bitvector[5]; int level; unsigned char deleted; } *affected; struct obj_data *carrying; struct room_index_data { struct room_index_data *next; struct char_data *people; struct obj_data *contents; struct extra_descr_data { struct extra_descr_data *next; char *keyword; char *description; unsigned char deleted; } *extra_descr; struct area_data *area; struct exit_data { struct room_index_data *to_room; int vnum; int exit_info; int key; char *keyword; char *description; struct exit_data *next; } *exit[10]; char *name; char *description; int vnum; int room_flags[2]; int orig_room_flags; int light; int current; int current_dir; int fall_chance; int sector_type; int extra_sector_info; struct reset_data *reset_first; struct reset_data *reset_last; } *in_room; struct room_index_data *was_in_room; char *name; char *short_descr; char *long_descr; char *description; int sex; int c_class; int race; int level; int trust; int size; int played; int cast_spl; int cast_time; int perm_str; int perm_int; int perm_wis; int perm_dex; int perm_con; int perm_agi; int perm_cha; int perm_pow; int perm_luk; int mod_str; int mod_int; int mod_wis; int mod_dex; int mod_con; int mod_agi; int mod_cha; int mod_pow; int mod_luk; long logon; long save_time; long last_note; int timer; int wait; int hit; int max_hit; int mana; int max_mana; int move; int max_move; struct coin_data { int copper; int silver; int gold; int platinum; } money; int exp; int act; int affected_by[5]; int position; int carry_weight; int carry_number; int saving_throw[5]; int alignment; int hitroll; int damroll; int armor; int wimpy; int deaf; unsigned char deleted; int mpactnum; int resistant; int immune; int susceptible; int fly_level; int load_room_vnum; } *keeper, unsigned char hit); struct char_data *carried_by; struct extra_descr_data *extra_descr; struct affect_data *affected; struct obj_index_data *pIndexData; struct room_index_data *in_room; struct trap_data { int trigger; int damage; int charges; int level; int percent; } *trap; char *name; char *short_descr; char *description; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int wear_loc; int weight; int cost; int level; int timer; int value[8]; int condition; unsigned char deleted; int fly_level; } *obj, struct char_data *keeper, unsigned char hit); struct extra_descr_data *extra_descr; struct affect_data *affected; struct trap_data *trap; char *name; char *short_descr; char *description; int vnum; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int count; int weight; int cost; int level; int progtypes; int condition; int value[8]; struct area_data *area; } *

variable_types: value int

variable_types: count int


original_code:
MOB_INDEX_DATA *new_mob_index( void )
{
    MOB_INDEX_DATA *pMob;
    int count;
 pMob = alloc_perm( sizeof( *pMob ) );
 top_mob_index++;
    pMob->next = ((void *)0);
    pMob->spec_fun = ((void *)0);
    pMob->pShop = ((void *)0);
    pMob->area = ((void *)0);
    pMob->player_name = str_dup( "no name" );
    pMob->short_descr = str_dup( "(no short description)" );
    pMob->long_descr = str_dup( "(no long description)\r\n" );
    pMob->description = &str_empty[0];
    pMob->vnum = 0;
    pMob->count = 0;
    pMob->killed = 0;
    pMob->sex = 0;
    pMob->level = 0;
    pMob->act = (1 << 3);
    for( count = 0; count < 5; count++ )
    {
       pMob->affected_by[count] = 0;
    }
    pMob->alignment = 0;
    return pMob;
}

canonical_original_code:
struct mob_index_data *new_mob_index()
{
    struct mob_index_data *pMob;
    int count;
 pMob = alloc_perm( sizeof( *pMob ) );
 top_mob_index++;
    pMob->next = ((void *)0);
    pMob->spec_fun = ((void *)0);
    pMob->pShop = ((void *)0);
    pMob->area = ((void *)0);
    pMob->player_name = str_dup( "no name" );
    pMob->short_descr = str_dup( "(no short description)" );
    pMob->long_descr = str_dup( "(no long description)\r\n" );
    pMob->description = &str_empty[0];
    pMob->vnum = 0;
    pMob->count = 0;
    pMob->killed = 0;
    pMob->sex = 0;
    pMob->level = 0;
    pMob->act = (1 << 3);
    for( count = 0; count < 5; count++ )
    {
       pMob->affected_by[count] = 0;
    }
    pMob->alignment = 0;
    return pMob;
}

variable_types: struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *group_leader; struct char_data *fighting; struct char_data *reply; struct char_data *riding; struct char_data *rider; struct char_data *next_in_group; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); struct mob_index_data *pIndexData; struct affect_data { struct affect_data *next; int skill; int spell; int song; int duration; int location; int modifier; int bitvector[5]; int level; unsigned char deleted; } *affected; struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct char_data *carried_by; struct extra_descr_data { struct extra_descr_data *next; char *keyword; char *description; unsigned char deleted; } *extra_descr; struct affect_data *affected; struct obj_index_data { struct obj_index_data *next; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct extra_descr_data *extra_descr; struct affect_data *affected; struct trap_data { int trigger; int damage; int charges; int level; int percent; } *trap; char *name; char *short_descr; char *description; int vnum; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int count; int weight; int cost; int level; int progtypes; int condition; int value[8]; struct area_data { struct area_data *next; struct reset_data { struct reset_data *next; char command; int arg0; int arg1; int arg2; int arg3; int arg4; int arg5; int arg6; int arg7; } *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; } *area; } *pIndexData; struct room_index_data { struct room_index_data *next; struct char_data *people; struct obj_data *contents; struct extra_descr_data *extra_descr; struct area_data *area; struct exit_data { struct room_index_data *to_room; int vnum; int exit_info; int key; char *keyword; char *description; struct exit_data *next; } *exit[10]; char *name; char *description; int vnum; int room_flags[2]; int orig_room_flags; int light; int current; int current_dir; int fall_chance; int sector_type; int extra_sector_info; struct reset_data *reset_first; struct reset_data *reset_last; } *in_room; struct trap_data *trap; char *name; char *short_descr; char *description; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int wear_loc; int weight; int cost; int level; int timer; int value[8]; int condition; unsigned char deleted; int fly_level; } *carrying; struct room_index_data *in_room; struct room_index_data *was_in_room; char *name; char *short_descr; char *long_descr; char *description; int sex; int c_class; int race; int level; int trust; int size; int played; int cast_spl; int cast_time; int perm_str; int perm_int; int perm_wis; int perm_dex; int perm_con; int perm_agi; int perm_cha; int perm_pow; int perm_luk; int mod_str; int mod_int; int mod_wis; int mod_dex; int mod_con; int mod_agi; int mod_cha; int mod_pow; int mod_luk; long logon; long save_time; long last_note; int timer; int wait; int hit; int max_hit; int mana; int max_mana; int move; int max_move; struct coin_data { int copper; int silver; int gold; int platinum; } money; int exp; int act; int affected_by[5]; int position; int carry_weight; int carry_number; int saving_throw[5]; int alignment; int hitroll; int damroll; int armor; int wimpy; int deaf; unsigned char deleted; int mpactnum; int resistant; int immune; int susceptible; int fly_level; int load_room_vnum; } *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); unsigned char (*death_fun)(struct char_data *ch, int cmd); struct shop_data { struct shop_data *next; struct area_data *area; int keeper; int buy_type[10]; int sell_item[20]; int profit_buy; int profit_sell; int open_hour; int close_hour; } *pShop; struct area_data *area; char *player_name; char *short_descr; char *long_descr; char *description; int vnum; int count; int killed; int sex; int c_class; int level; int act; int affected_by[5]; int alignment; int race; int position; int progtypes; int resistant; int immune; int susceptible; } *


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

switch ( a1 )
{
case 0:
result = "any";
break;
case 1:
result = "tiny";
break;
case 2:
result = "small";
break;
case 3:
result = "small";
break;
case 4:
result = "medium";
break;
case 5:
result = "medium";
break;
case 6:
result = "large";
break;
case 7:
result = "huge";
break;
case 8:
result = "giant";
break;
case 9:
result = "titanic";
break;
case 10:
result = "gargantuan";
break;
case 11:
result = "none";
break;
default:
result = "unknown-invalid";
break;
}
return result;
}

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

switch ( a1 )
{
case 0:
result = "any";
break;
case 1:
result = "tiny";
break;
case 2:
result = "small";
break;
case 3:
result = "small";
break;
case 4:
result = "medium";
break;
case 5:
result = "medium";
break;
case 6:
result = "large";
break;
case 7:
result = "huge";
break;
case 8:
result = "giant";
break;
case 9:
result = "titanic";
break;
case 10:
result = "gargantuan";
break;
case 11:
result = "none";
break;
default:
result = "unknown-invalid";
break;
}
return result;
}

original_code:
const char * size_string( int size )
{
    switch( size )
    {
      default:
        return "unknown-invalid";
        break;
      case 0:
        return "any";
        break;
      case 1:
        return "tiny";
        break;
      case 2:
        return "small";
        break;
      case 3:
        return "small";
        break;
      case 5:
        return "medium";
        break;
      case 4:
        return "medium";
        break;
      case 6:
        return "large";
        break;
      case 7:
        return "huge";
        break;
      case 8:
        return "giant";
        break;
      case 9:
        return "titanic";
        break;
      case 10:
        return "gargantuan";
        break;
      case 11:
        return "none";
        break;
     }
}

canonical_original_code:
char *size_string(int size)
{
    switch( size )
    {
      default:
        return "unknown-invalid";
        break;
      case 0:
        return "any";
        break;
      case 1:
        return "tiny";
        break;
      case 2:
        return "small";
        break;
      case 3:
        return "small";
        break;
      case 5:
        return "medium";
        break;
      case 4:
        return "medium";
        break;
      case 6:
        return "large";
        break;
      case 7:
        return "huge";
        break;
      case 8:
        return "giant";
        break;
      case 9:
        return "titanic";
        break;
      case 10:
        return "gargantuan";
        break;
      case 11:
        return "none";
        break;
     }
}

variable_types: size int


UpdateState

repo: XenoKrelian/RpiJtag

decompiled_code:
void __fastcall UpdateState(int a1)
{
int v1; // eax

if ( a1 )
{
if ( a1 == 1 )
{
*(_DWORD *)(gpio + 28) = 512;
i = 0;
do
{
nop_sleep(125LL);
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
*(_DWORD *)(gpio + 28) = 16;
nop_sleep(125LL);
++i;
}
while ( i <= 4 );
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
jtag_state = 1;
}
}
else if ( (jtag_state & 0xFFEu) > 0xE )
{
if ( (jtag_state & 0xFFFFFEE9) == 0 )
jtag_state = 3;
}
else
{
v1 = jtag_state + 1;
if ( jtag_state + 1 > 5 )
v1 = 1;
jtag_state = v1;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int v1; // eax

if ( a1 )
{
if ( a1 == 1 )
{
*(_DWORD *)(gpio + 28) = 512;
i = 0;
do
{
nop_sleep(125LL);
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
*(_DWORD *)(gpio + 28) = 16;
nop_sleep(125LL);
++i;
}
while ( i <= 4 );
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
jtag_state = 1;
}
}
else if ( (jtag_state & 0xFFEu) > 0xE )
{
if ( (jtag_state & 0xFFFFFEE9) == 0 )
jtag_state = 3;
}
else
{
v1 = jtag_state + 1;
if ( jtag_state + 1 > 5 )
v1 = 1;
jtag_state = v1;
}
}

original_code:
void UpdateState(int j_state, int iTMS)
{
 switch(j_state)
 {
  case 0x001:
   *(gpio+7) = 1<<(9);
   for(i=0;i<5;i++)
   {
    nop_sleep(125);
    *(gpio+10) = 1<<(4);
    nop_sleep(125);
    *(gpio+7) = 1<<(4);
    nop_sleep(125);
   }
   *(gpio+10) = 1<<(4);
   nop_sleep(125);
   jtag_state=0x001;
   break;
  case 0x000:
   if((jtag_state & 0xFFE) < 15)
   {
    jtag_state++;
    if(jtag_state > 5)
     jtag_state = 0x001;
   }
   else if((jtag_state | 0x116) == 0x116)
    jtag_state = 0x003;
   break;
 }
}

variable_types: iTMS int


syncJTAGs

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

*(_DWORD *)(gpio + 28) = 512;
i = 0;
do
{
nop_sleep(125LL);
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
*(_DWORD *)(gpio + 28) = 16;
nop_sleep(125LL);
++i;
}
while ( i <= 4 );
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
send_cmd(0LL, 0LL);
result = send_cmd(0LL, 1LL);
jtag_state = 3;
return result;
}

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

*(_DWORD *)(gpio + 28) = 512;
i = 0;
do
{
nop_sleep(125LL);
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
*(_DWORD *)(gpio + 28) = 16;
nop_sleep(125LL);
++i;
}
while ( i <= 4 );
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
send_cmd(0LL, 0LL);
result = send_cmd(0LL, 1LL);
jtag_state = 3;
return result;
}


SelectShiftDR

decompiled_code:
__int64 SelectShiftDR()
{
jtag_state = 18;
send_cmd(0LL, 0LL);
return send_cmd(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
jtag_state = 18;
send_cmd(0LL, 0LL);
return send_cmd(0LL, 0LL);
}

original_code:
void SelectShiftDR()
{
 jtag_state = 0x012;
 send_cmd(0,0);
 send_cmd(0,0);
}


SelectShiftIR

decompiled_code:
__int64 SelectShiftIR()
{
jtag_state = 258;
send_cmd(0LL, 1LL);
send_cmd(0LL, 0LL);
return send_cmd(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
jtag_state = 258;
send_cmd(0LL, 1LL);
send_cmd(0LL, 0LL);
return send_cmd(0LL, 0LL);
}

original_code:
void SelectShiftIR()
{
 jtag_state = 0x102;
 send_cmd(0,1);
 send_cmd(0,0);
 send_cmd(0,0);
}


ExitShift

decompiled_code:
__int64 ExitShift()
{
jtag_state = 3;
send_cmd(0LL, 1LL);
send_cmd(0LL, 1LL);
return send_cmd(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func4()
{
jtag_state = 3;
send_cmd(0LL, 1LL);
send_cmd(0LL, 1LL);
return send_cmd(0LL, 1LL);
}

original_code:
void ExitShift()
{
 jtag_state = 0x003;
 send_cmd(0,1);
 send_cmd(0,1);
 send_cmd(0,1);
}


decompiled_code:
__int64 read_jtag_tdo()
{
return (*(_DWORD *)(gpio + 52) >> 8) & 1;
}


decompiled_code:
void __fastcall nop_sleep(__int64 a1)
{
for ( ; a1; --a1 )
;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
for ( ; a1; --a1 )
;
}

original_code:
void nop_sleep(long x)
{
 while (x--) {
  asm("nop");
 }
}

variable_types: x long


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

v2 = read_jtag_tdo();
if ( a1 == 1 )
*(_DWORD *)(gpio + 28) = 128;
else
*(_DWORD *)(gpio + 40) = 128;
if ( a2 == 1 )
*(_DWORD *)(gpio + 28) = 512;
else
*(_DWORD *)(gpio + 40) = 512;
UpdateState(0LL, a2);
nop_sleep(125LL);
*(_DWORD *)(gpio + 28) = 16;
nop_sleep(125LL);
*(_DWORD *)(gpio + 40) = 16;
nop_sleep(125LL);
return v2;
}

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

v2 = func0();
if ( a1 == 1 )
*(_DWORD *)(gpio + 28) = 128;
else
*(_DWORD *)(gpio + 40) = 128;
if ( a2 == 1 )
*(_DWORD *)(gpio + 28) = 512;
else
*(_DWORD *)(gpio + 40) = 512;
UpdateState(0LL, a2);
func1(125LL);
*(_DWORD *)(gpio + 28) = 16;
func1(125LL);
*(_DWORD *)(gpio + 40) = 16;
func1(125LL);
return v2;
}

variable_types: iTDI int

variable_types: tdo int


decompiled_code:
__int64 __fastcall send_cmdWord_msb_first(unsigned int a1, int a2, int a3)
{
unsigned int v3; // ebx
__int64 result; // rax

v3 = a3 - 1;
if ( a3 )
{
do
{
send_cmd((a1 >> v3) & 1, a2 == 1 && v3 == 0);
result = v3--;
}
while ( (_DWORD)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2, int a3)
{
unsigned int v3; // ebx
__int64 result; // rax

v3 = a3 - 1;
if ( a3 )
{
do
{
func2((a1 >> v3) & 1, a2 == 1 && v3 == 0);
result = v3--;
}
while ( (_DWORD)result );
}
return result;
}

original_code:
void send_cmdWord_msb_first(unsigned int cmd, int lastBit, int bitoffset)
{
 while(bitoffset--)
 {
  int x = ( cmd >> bitoffset) & 0x01;
  send_cmd(x,(lastBit==1 && bitoffset==0));
 }
}

variable_types:
cmd
unsigned int

variable_types: lastBit int

variable_types: bitoffset int

variable_types: x int


decompiled_code:
__int64 __fastcall send_cmdWord_msb_last(unsigned int a1, int a2, int a3)
{
int v5; // ebx
__int64 result; // rax
int v7; // edi

if ( a3 > 0 )
{
v5 = 0;
while ( 1 )
{
v7 = (a1 >> v5) & 1;
if ( a2 == 1 && a3 == v5 + 1 )
break;
result = send_cmd(v7, 0);
if ( a3 == ++v5 )
return result;
}
result = send_cmd(v7, 1u);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, int a2, int a3)
{
int v5; // ebx
__int64 result; // rax
int v7; // edi

if ( a3 > 0 )
{
v5 = 0;
while ( 1 )
{
v7 = (a1 >> v5) & 1;
if ( a2 == 1 && a3 == v5 + 1 )
break;
result = func2(v7, 0);
if ( a3 == ++v5 )
return result;
}
result = func2(v7, 1u);
}
return result;
}

original_code:
void send_cmdWord_msb_last(unsigned int cmd, int lastBit, int bitoffset)
{
 int i;
 for(i=0;i<bitoffset;i++)
 {
  int x = ( cmd >> i ) & 0x01;
  send_cmd(x,(lastBit==1 && bitoffset==i+1));
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall send_byte(unsigned __int8 a1, int a2)
{
int i; // ebx
__int64 result; // rax

for ( i = 7; i != -1; --i )
result = send_cmd(((int)a1 >> i) & 1, (a2 == 1) & (unsigned __int8)(i == 0));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 a1, int a2)
{
int i; // ebx
__int64 result; // rax

for ( i = 7; i != -1; --i )
result = func2(((int)a1 >> i) & 1, (a2 == 1) & (unsigned __int8)(i == 0));
return result;
}

original_code:
void send_byte(unsigned char byte, int lastByte)
{
 int x;
 for(x=7;x>=0;x--)
 {
  send_cmd(byte>>x&0x01,(lastByte==1 && x==0));
 }
}

variable_types:
byte
unsigned char

variable_types: lastByte int


original_code:
void jtag_read_data(char* data,int iSize)
{
 if(iSize==0) return;
 int bitOffset = 0;
 memset(data,0,(iSize+7)/8);
 iSize--;
 while(iSize--)
 {
  temp = send_cmd(0,0);
  data[bitOffset/8] |= (temp << (bitOffset & 7));
  bitOffset++;
 }
 temp = send_cmd(0,1);
 data[bitOffset/8] |= (temp << (bitOffset & 7));
 send_cmd(0,1);
 send_cmd(0,1);
}

canonical_original_code:
void jtag_read_data(char *data, int iSize)
{
 if(iSize==0) return;
 int bitOffset = 0;
 memset(data,0,(iSize+7)/8);
 iSize--;
 while(iSize--)
 {
  temp = send_cmd(0,0);
  data[bitOffset/8] |= (temp << (bitOffset & 7));
  bitOffset++;
 }
 temp = send_cmd(0,1);
 data[bitOffset/8] |= (temp << (bitOffset & 7));
 send_cmd(0,1);
 send_cmd(0,1);
}

variable_types:
data
char *

variable_types: iSize int

variable_types: bitOffset int


readIDCODES

decompiled_code:
size_t readIDCODES()
{
int v0; // edx
size_t result; // rax
__int64 v2; // rcx

if ( !(nDevices | parms & 1) )
return fwrite("No devices found\n", 1uLL, 0x11uLL, stderr);
syncJTAGs();
send_cmd(0, 0);
send_cmd(0, 0);
jtag_read_data(idcode, 32 * nDevices);
x = 0;
i = 0;
if ( nDevices <= 0 )
goto LABEL_11;
v0 = 0;
do
{
if ( (idcode[v0] & 1) != 0 )
{
v2 = idcode[v0] | 0xF0000000;
if ( LODWORD(device_data[4 * deviceDataNr + 1]) != (_DWORD)v2 || x )
{
fprintf(
stderr,
"\nDevice %d, %08X (Manuf %03X, Part size %03X, Family code %02X) bitfile+bdsl match: %d",
(unsigned int)(v0 + 1),
v2,
(unsigned int)((__int16)(16 * LOWORD(idcode[v0])) >> 5),
(unsigned int)(idcode[v0] << 11 >> 23),
(unsigned int)((char)(HIWORD(idcode[v0]) >> 4) >> 1),
0LL);
}
else
{
x = 1;
deviceChainNr = v0;
fprintf(
stderr,
"\nDevice %d, %08X (Manuf %03X, Part size %03X, Family code %02X) bitfile+bdsl match: %d",
(unsigned int)(v0 + 1),
v2,
(unsigned int)((__int16)(16 * LOWORD(idcode[v0])) >> 5),
(unsigned int)(idcode[v0] << 11 >> 23),
(unsigned int)((char)(HIWORD(idcode[v0]) >> 4) >> 1),
1LL);
}
}
result = (unsigned int)i;
v0 = i + 1;
i = v0;
}
while ( v0 < nDevices );
if ( !x )
{
LABEL_11:
fwrite("ERROR NO DEVICE IDCODE MATCH BITFILE/BDSL FILE", 1uLL, 0x2EuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
size_t func7()
{
int v0; // edx
size_t result; // rax
__int64 v2; // rcx

if ( !(nDevices | parms & 1) )
return fwrite("No devices found\n", 1uLL, 0x11uLL, stderr);
syncJTAGs();
func2(0, 0);
func2(0, 0);
func6(idcode, 32 * nDevices);
x = 0;
i = 0;
if ( nDevices <= 0 )
goto LABEL_11;
v0 = 0;
do
{
if ( (idcode[v0] & 1) != 0 )
{
v2 = idcode[v0] | 0xF0000000;
if ( LODWORD(device_data[4 * deviceDataNr + 1]) != (_DWORD)v2 || x )
{
fprintf(
stderr,
"\nDevice %d, %08X (Manuf %03X, Part size %03X, Family code %02X) bitfile+bdsl match: %d",
(unsigned int)(v0 + 1),
v2,
(unsigned int)((__int16)(16 * LOWORD(idcode[v0])) >> 5),
(unsigned int)(idcode[v0] << 11 >> 23),
(unsigned int)((char)(HIWORD(idcode[v0]) >> 4) >> 1),
0LL);
}
else
{
x = 1;
deviceChainNr = v0;
fprintf(
stderr,
"\nDevice %d, %08X (Manuf %03X, Part size %03X, Family code %02X) bitfile+bdsl match: %d",
(unsigned int)(v0 + 1),
v2,
(unsigned int)((__int16)(16 * LOWORD(idcode[v0])) >> 5),
(unsigned int)(idcode[v0] << 11 >> 23),
(unsigned int)((char)(HIWORD(idcode[v0]) >> 4) >> 1),
1LL);
}
}
result = (unsigned int)i;
v0 = i + 1;
i = v0;
}
while ( v0 < nDevices );
if ( !x )
{
LABEL_11:
fwrite("ERROR NO DEVICE IDCODE MATCH BITFILE/BDSL FILE", 1uLL, 0x2EuLL, stderr);
exit(1);
}
return result;
}

original_code:
void readIDCODES()
{
 if(nDevices != 0 || ((parms & 0x01) == 0x01))
 {
  syncJTAGs();
  send_cmd(0,0);
  send_cmd(0,0);
  jtag_read_data((char*)idcode,32*nDevices);
  x = 0;
  for(i=0;i<nDevices;i++)
  {
   if(idcode[i].onebit == 1 || idcode[i].onebit == -1)
   {
    int iIdcode = (*(int*)&idcode[i]|0xF0000000);
    if(iIdcode == device_data[deviceDataNr].idcode && x == 0)
    {
     x=1;
     deviceChainNr = i;
     fprintf(stderr,"\nDevice %d, %08X (Manuf %03X, Part size %03X, Family code %02X) bitfile+bdsl match: %d",i+1,iIdcode,idcode[i].manuf,idcode[i].size,idcode[i].family,x);
    }else{
     fprintf(stderr,"\nDevice %d, %08X (Manuf %03X, Part size %03X, Family code %02X) bitfile+bdsl match: %d",i+1,iIdcode,idcode[i].manuf,idcode[i].size,idcode[i].family,0);
    }
   }
  }
  if(x==0){fprintf(stderr,"ERROR NO DEVICE IDCODE MATCH BITFILE/BDSL FILE"); exit(1);}
 }else{
  fprintf(stderr,"No devices found\n");
 }
}

canonical_original_code:
void readIDCODES()
{
 if(nDevices != 0 || ((parms & 0x01) == 0x01))
 {
  syncJTAGs();
  send_cmd(0,0);
  send_cmd(0,0);
  jtag_read_data((char *)idcode,32*nDevices);
  x = 0;
  for(i=0;i<nDevices;i++)
  {
   if(idcode[i].onebit == 1 || idcode[i].onebit == -1)
   {
    int iIdcode = (*(int*)&idcode[i]|0xF0000000);
    if(iIdcode == device_data[deviceDataNr].idcode && x == 0)
    {
     x=1;
     deviceChainNr = i;
     fprintf(stderr,"\nDevice %d, %08X (Manuf %03X, Part size %03X, Family code %02X) bitfile+bdsl match: %d",i+1,iIdcode,idcode[i].manuf,idcode[i].size,idcode[i].family,x);
    }else{
     fprintf(stderr,"\nDevice %d, %08X (Manuf %03X, Part size %03X, Family code %02X) bitfile+bdsl match: %d",i+1,iIdcode,idcode[i].manuf,idcode[i].size,idcode[i].family,0);
    }
   }
  }
  if(x==0){fprintf(stderr,"ERROR NO DEVICE IDCODE MATCH BITFILE/BDSL FILE"); exit(1);}
 }else{
  fprintf(stderr,"No devices found\n");
 }
}

variable_types: iIdcode int


CountDevices

decompiled_code:
__int64 CountDevices()
{
int v0; // ebx

if ( (parms & 1) != 0 )
fwrite("Counting devices\n", 1uLL, 0x11uLL, stderr);
syncJTAGs();
SelectShiftIR();
x = 0;
do
{
send_cmd(1, 0);
++x;
}
while ( x <= 198 );
i = 0;
v0 = 0;
do
{
x = send_cmd(0, 0);
if ( !x )
break;
++v0;
++i;
}
while ( i <= 198 );
if ( IRTotalRegSize != v0 )
fwrite("\nERROR IR SIZE FROM BSDL MISMATCH FROM JTAG\n", 1uLL, 0x2CuLL, stderr);
x = 0;
do
{
send_cmd(1, 0);
++x;
}
while ( x <= 198 );
ExitShift();
SelectShiftDR();
x = 0;
do
{
send_cmd(0, 0);
++x;
}
while ( x <= 198 );
if ( (parms & 1) != 0 )
fwrite("FLUSH DR\n", 1uLL, 9uLL, stderr);
for ( x = 0; x < v0; ++x )
{
i = send_cmd(1, 0);
if ( i )
break;
}
if ( x == v0 )
x = 0;
if ( (parms & 1) != 0 )
fprintf(stderr, "(IR REG SIZE:(0's) %d vs (1's) %d)\n", (unsigned int)i, (unsigned int)v0);
fprintf(stderr, "Devices found: %d\n", (unsigned int)x);
ExitShift();
return (unsigned int)x;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx

if ( (parms & 1) != 0 )
fwrite("Counting devices\n", 1uLL, 0x11uLL, stderr);
syncJTAGs();
SelectShiftIR();
x = 0;
do
{
func2(1, 0);
++x;
}
while ( x <= 198 );
i = 0;
v0 = 0;
do
{
x = func2(0, 0);
if ( !x )
break;
++v0;
++i;
}
while ( i <= 198 );
if ( IRTotalRegSize != v0 )
fwrite("\nERROR IR SIZE FROM BSDL MISMATCH FROM JTAG\n", 1uLL, 0x2CuLL, stderr);
x = 0;
do
{
func2(1, 0);
++x;
}
while ( x <= 198 );
ExitShift();
SelectShiftDR();
x = 0;
do
{
func2(0, 0);
++x;
}
while ( x <= 198 );
if ( (parms & 1) != 0 )
fwrite("FLUSH DR\n", 1uLL, 9uLL, stderr);
for ( x = 0; x < v0; ++x )
{
i = func2(1, 0);
if ( i )
break;
}
if ( x == v0 )
x = 0;
if ( (parms & 1) != 0 )
fprintf(stderr, "(IR REG SIZE:(0's) %d vs (1's) %d)\n", (unsigned int)i, (unsigned int)v0);
fprintf(stderr, "Devices found: %d\n", (unsigned int)x);
ExitShift();
return (unsigned int)x;
}

original_code:
int CountDevices()
{
 if((parms & 0x01) == 0x01)
  fprintf(stderr,"Counting devices\n");
 int tIRLen = 0;
 syncJTAGs();
 SelectShiftIR();
 for(x=0;x<199;x++) send_cmd(1,0);
 for(i=0;i<199;i++)
  {
  x = send_cmd(0,0);
  if(!x) break;
  tIRLen++;
 }
 if(tIRLen != IRTotalRegSize)
  fprintf(stderr,"\nERROR IR SIZE FROM BSDL MISMATCH FROM JTAG\n");
 for(x=0;x<199;x++) send_cmd(1,0);
 ExitShift();
 SelectShiftDR();
 for(x=0;x<199;x++) send_cmd(0,0);
 if((parms & 0x01) == 0x01)
  fprintf(stderr,"FLUSH DR\n");
 for(x=0;x<tIRLen;x++)
 {
  i = send_cmd(1,0);
  if(i) break;
 }
 if(x==tIRLen) x = 0;
 if((parms & 0x01) == 0x01)
  fprintf(stderr,"(IR REG SIZE:(0's) %d vs (1's) %d)\n",i,tIRLen);
 fprintf(stderr,"Devices found: %d\n",x);
 ExitShift();
 return x;
}

variable_types: tIRLen int


help

decompiled_code:
size_t help()
{
return fwrite(
"Usage: rpjtag [options]\n"
" -h Print help\n"
"\t-D\t Debug info\n"
"\t-b\t\tuse BDSL file(s) use , as between multiple files\n"
"\t\t\tonly needed if program doesn't know IDCODE->BDSL file\n"
"\n",
1uLL,
0xB1uLL,
stderr);
}

canonical_decompiled_code:
size_t func9()
{
return fwrite(
"Usage: rpjtag [options]\n"
" -h Print help\n"
"\t-D\t Debug info\n"
"\t-b\t\tuse BDSL file(s) use , as between multiple files\n"
"\t\t\tonly needed if program doesn't know IDCODE->BDSL file\n"
"\n",
1uLL,
0xB1uLL,
stderr);
}

original_code:
void help()
{
 fprintf(stderr,
 "Usage: rpjtag [options]\n"
 "   -h      Print help\n"
 "	-D	    Debug info\n"
 "	-b		use BDSL file(s) use , as between multiple files\n"
 "			only needed if program doesn't know IDCODE->BDSL file\n"
 "\n");
}


decompiled_code:
void setup_io()
{
int v0; // eax
int v1; // edx
int v2; // eax

v0 = open("/dev/mem", 1052674);
mem_fd = v0;
if ( v0 < 0 )
{
puts("can't open /dev/mem ");
exit(-1);
}
gpio_map = mmap(0LL, 0x1000uLL, 3, 1, v0, 538968064LL);
close(mem_fd);
if ( gpio_map == (void *)-1LL )
{
printf(aMmapError, 0xFFFFFFFFLL);
exit(-1);
}
gpio = (__int64)gpio_map;
v1 = *(_DWORD *)gpio_map;
BYTE1(v1) = BYTE1(*(_DWORD *)gpio_map) & 0x8F;
*(_DWORD *)gpio_map = v1;
*(_DWORD *)gpio &= 0xC7FFFFFF;
*(_DWORD *)gpio &= 0xFF1FFFFF;
*(_DWORD *)gpio &= 0xF8FFFFFF;
nop_sleep(125LL);
if ( (parms & 1) != 0 )
fprintf(
stderr,
"INITIAL PORT STATUS TMS %d, TCK %d, TDI %d, TDO %d\n",
(*(_DWORD *)(gpio + 52) >> 9) & 1,
(*(_DWORD *)(gpio + 52) >> 4) & 1,
(*(_DWORD *)(gpio + 52) >> 7) & 1,
(*(_DWORD *)(gpio + 52) >> 8) & 1);
*(_DWORD *)gpio |= 0x200000u;
*(_DWORD *)gpio |= 0x8000000u;
v2 = *(_DWORD *)gpio;
BYTE1(v2) = BYTE1(*(_DWORD *)gpio) | 0x10;
*(_DWORD *)gpio = v2;
if ( (parms & 1) != 0 )
fprintf(
stderr,
"READY PORT STATUS TMS %d, TCK %d, TDI %d, TDO %d\n",
(*(_DWORD *)(gpio + 52) >> 9) & 1,
(*(_DWORD *)(gpio + 52) >> 4) & 1,
(*(_DWORD *)(gpio + 52) >> 7) & 1,
(*(_DWORD *)(gpio + 52) >> 8) & 1);
nop_sleep(125LL);
}

canonical_decompiled_code:
void func10()
{
int v0; // eax
int v1; // edx
int v2; // eax

v0 = open("/dev/mem", 1052674);
mem_fd = v0;
if ( v0 < 0 )
{
puts("can't open /dev/mem ");
exit(-1);
}
gpio_map = mmap(0LL, 0x1000uLL, 3, 1, v0, 538968064LL);
close(mem_fd);
if ( gpio_map == (void *)-1LL )
{
printf(aMmapError, 0xFFFFFFFFLL);
exit(-1);
}
gpio = (__int64)gpio_map;
v1 = *(_DWORD *)gpio_map;
BYTE1(v1) = BYTE1(*(_DWORD *)gpio_map) & 0x8F;
*(_DWORD *)gpio_map = v1;
*(_DWORD *)gpio &= 0xC7FFFFFF;
*(_DWORD *)gpio &= 0xFF1FFFFF;
*(_DWORD *)gpio &= 0xF8FFFFFF;
func1(125LL);
if ( (parms & 1) != 0 )
fprintf(
stderr,
"INITIAL PORT STATUS TMS %d, TCK %d, TDI %d, TDO %d\n",
(*(_DWORD *)(gpio + 52) >> 9) & 1,
(*(_DWORD *)(gpio + 52) >> 4) & 1,
(*(_DWORD *)(gpio + 52) >> 7) & 1,
(*(_DWORD *)(gpio + 52) >> 8) & 1);
*(_DWORD *)gpio |= 0x200000u;
*(_DWORD *)gpio |= 0x8000000u;
v2 = *(_DWORD *)gpio;
BYTE1(v2) = BYTE1(*(_DWORD *)gpio) | 0x10;
*(_DWORD *)gpio = v2;
if ( (parms & 1) != 0 )
fprintf(
stderr,
"READY PORT STATUS TMS %d, TCK %d, TDI %d, TDO %d\n",
(*(_DWORD *)(gpio + 52) >> 9) & 1,
(*(_DWORD *)(gpio + 52) >> 4) & 1,
(*(_DWORD *)(gpio + 52) >> 7) & 1,
(*(_DWORD *)(gpio + 52) >> 8) & 1);
func1(125LL);
}


decompiled_code:
void __fastcall load_bdsl_files(const char *a1)
{
int v1; // eax
int v2; // er15
int v3; // ebx
char *v4; // r12
int i; // eax
char v6; // bp
char *v7; // rax

v1 = strlen(a1);
x = 0;
if ( v1 <= 0 )
{
v4 = 0LL;
}
else
{
v2 = v1;
v3 = 0;
v4 = 0LL;
for ( i = 0; i < v2; x = i )
{
v6 = a1[i];
if ( v6 == 44 )
{
read_bdsl_file(v4, fileCounter);
++fileCounter;
v3 = 0;
v4 = 0LL;
}
else
{
v7 = (char *)realloc(v4, v3 + 1);
if ( v7 )
{
v7[v3++] = v6;
v4 = v7;
}
else
{
free(v4);
fwrite("Error (re)allocating memory", 1uLL, 0x1BuLL, stderr);
++v3;
}
}
i = x + 1;
}
}
read_bdsl_file(v4, fileCounter);
free(v4);
x = 0;
::i = 0;
n = 0;
}

canonical_decompiled_code:
void __fastcall func1(const char *a1)
{
int v1; // eax
int v2; // er15
int v3; // ebx
char *v4; // r12
int i; // eax
char v6; // bp
char *v7; // rax

v1 = strlen(a1);
x = 0;
if ( v1 <= 0 )
{
v4 = 0LL;
}
else
{
v2 = v1;
v3 = 0;
v4 = 0LL;
for ( i = 0; i < v2; x = i )
{
v6 = a1[i];
if ( v6 == 44 )
{
func0(v4, fileCounter);
++fileCounter;
v3 = 0;
v4 = 0LL;
}
else
{
v7 = (char *)realloc(v4, v3 + 1);
if ( v7 )
{
v7[v3++] = v6;
v4 = v7;
}
else
{
free(v4);
fwrite("Error (re)allocating memory", 1uLL, 0x1BuLL, stderr);
++v3;
}
}
i = x + 1;
}
}
func0(v4, fileCounter);
free(v4);
x = 0;
::i = 0;
n = 0;
}

original_code:
void load_bdsl_files(char *bdslfiles)
{
 int strlength = strlen(bdslfiles);
 char *temp = ((void *)0);
 char *temp2 = ((void *)0);
 int wordCounter = 0;
    for(x=0;x<strlength;x++)
 {
  if(bdslfiles[x] == ',' || x==strlength)
  {
   read_bdsl_file(temp,fileCounter);
   fileCounter++;
   wordCounter = 0;
   temp=((void *)0);
  }else{
   temp2 = (char*)realloc(temp,(wordCounter+1)*sizeof(char));
   if(temp2!=((void *)0))
   {
    temp=temp2;
    temp[wordCounter] = bdslfiles[x];
   }else{
    free(temp);
    fprintf(stderr,"Error (re)allocating memory");
   }
   wordCounter++;
  }
 }
 read_bdsl_file(temp,fileCounter);
 free(temp);
 x=0;
 i=0;
 n=0;
}

canonical_original_code:
void load_bdsl_files(char *bdslfiles)
{
 int strlength = strlen(bdslfiles);
 char *temp = ((void *)0);
 char *temp2 = ((void *)0);
 int wordCounter = 0;
    for(x=0;x<strlength;x++)
 {
  if(bdslfiles[x] == ',' || x==strlength)
  {
   read_bdsl_file(temp,fileCounter);
   fileCounter++;
   wordCounter = 0;
   temp=((void *)0);
  }else{
   temp2 = (char *)realloc(temp,(wordCounter+1)*sizeof(char));
   if(temp2!=((void *)0))
   {
    temp=temp2;
    temp[wordCounter] = bdslfiles[x];
   }else{
    free(temp);
    fprintf(stderr,"Error (re)allocating memory");
   }
   wordCounter++;
  }
 }
 read_bdsl_file(temp,fileCounter);
 free(temp);
 x=0;
 i=0;
 n=0;
}

variable_types:
bdslfiles
char *

variable_types: strlength int

variable_types:
temp
char *

variable_types: wordCounter int