original_code:
bool rem_flag( PFLAG_DATA **list, char *argument )
{
 PFLAG_DATA * tmp, *org_list, *tmp_prev;
 bool result = 0;
 org_list = *list;
 tmp = org_list;
 if ( !tmp )
  return 0;
 if ( !str_cmp( tmp->id, argument ) )
 {
  org_list = org_list->next;
  free_pflag( tmp );
  tmp = ((void *)0);
  *list = org_list;
  result = 1;
 }
 else
 {
  tmp_prev = tmp;
  for ( ;tmp;tmp = tmp->next )
  {
   if ( !str_cmp( tmp->id, argument ) )
   {
    tmp_prev->next = tmp->next;
    tmp->next = ((void *)0);
    free_pflag( tmp );
    tmp = ((void *)0);
    result = 1;
    break;
   }
   tmp_prev = tmp;
  }
 }
 if ( *list == misc.global_flag_list )
  save_misc_data();
 return result;
}

canonical_original_code:
unsigned char rem_flag(struct pflag_data **list, char *argument)
{
 struct pflag_data *tmp; struct pflag_data *org_list; struct pflag_data *tmp_prev;
 unsigned char result = 0;
 org_list = *list;
 tmp = org_list;
 if ( !tmp )
  return 0;
 if ( !str_cmp( tmp->id, argument ) )
 {
  org_list = org_list->next;
  free_pflag( tmp );
  tmp = ((void *)0);
  *list = org_list;
  result = 1;
 }
 else
 {
  tmp_prev = tmp;
  for ( ;tmp;tmp = tmp->next )
  {
   if ( !str_cmp( tmp->id, argument ) )
   {
    tmp_prev->next = tmp->next;
    tmp->next = ((void *)0);
    free_pflag( tmp );
    tmp = ((void *)0);
    result = 1;
    break;
   }
   tmp_prev = tmp;
  }
 }
 if ( *list == misc.global_flag_list )
  save_misc_data();
 return result;
}

variable_types: struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; } **

variable_types:
argument
char *

variable_types:
result
unsigned char


repo: blanciq/bq-killer

original_code:
PFLAG_DATA * add_flag( PFLAG_DATA **list, char *id, int duration )
{
 PFLAG_DATA * tmp;
 if ( !id || id[ 0 ] == '\0' )
  return ((void *)0);
 if ( strlen( id ) > 32 )
  return ((void *)0);
 if ( *list )
 {
  for ( tmp = *list;tmp;tmp = tmp->next )
  {
   if ( !str_cmp( tmp->id, id ) )
   {
    if ( tmp->duration != -1 )
     tmp->duration = duration;
    return tmp;
   }
  }
 }
 tmp = new_pflag();
 tmp->id = str_dup( id );
 tmp->duration = duration;
 tmp->next = ((void *)0);
 tmp->next = ( *list );
 *list = tmp;
 return tmp;
}

canonical_original_code:
struct pflag_data *add_flag(struct pflag_data **list, char *id, int duration)
{
 struct pflag_data *tmp;
 if ( !id || id[ 0 ] == '\0' )
  return ((void *)0);
 if ( strlen( id ) > 32 )
  return ((void *)0);
 if ( *list )
 {
  for ( tmp = *list;tmp;tmp = tmp->next )
  {
   if ( !str_cmp( tmp->id, id ) )
   {
    if ( tmp->duration != -1 )
     tmp->duration = duration;
    return tmp;
   }
  }
 }
 tmp = new_pflag();
 tmp->id = str_dup( id );
 tmp->duration = duration;
 tmp->next = ((void *)0);
 tmp->next = ( *list );
 *list = tmp;
 return tmp;
}

variable_types:
list
struct pflag_data **

variable_types:
id
char *

variable_types: duration int

variable_types: struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; } *


setglobalflag

decompiled_code:
__int64 __fastcall setglobalflag(_BYTE *a1)
{
__int64 result; // rax
const char *v2; // rbx
int v3; // edx
__int64 v4; // rdx
char v5; // al
int v6; // eax
char v7[520]; // [rsp+0h] [rbp-210h] BYREF

result = 0LL;
if ( *a1 )
{
v2 = (const char *)one_argument(a1, v7);
result = 0LL;
if ( v7[0] )
{
v3 = 0;
if ( *v2 )
{
v5 = is_number(v2, v7, 0LL);
v3 = 0;
if ( v5 )
{
v6 = atoi(v2);
v3 = UMAX(-1LL, v6);
}
}
v4 = add_flag((__int64 *)(unsigned int)((_DWORD)misc + 40), v7, v3);
result = 0LL;
if ( v4 )
{
save_misc_data();
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_BYTE *a1)
{
__int64 result; // rax
const char *v2; // rbx
int v3; // edx
__int64 v4; // rdx
char v5; // al
int v6; // eax
char v7[520]; // [rsp+0h] [rbp-210h] BYREF

result = 0LL;
if ( *a1 )
{
v2 = (const char *)one_argument(a1, v7);
result = 0LL;
if ( v7[0] )
{
v3 = 0;
if ( *v2 )
{
v5 = is_number(v2, v7, 0LL);
v3 = 0;
if ( v5 )
{
v6 = atoi(v2);
v3 = UMAX(-1LL, v6);
}
}
v4 = func1((__int64 *)(unsigned int)((_DWORD)misc + 40), v7, v3);
result = 0LL;
if ( v4 )
{
save_misc_data();
result = 1LL;
}
}
}
return result;
}

original_code:
bool setglobalflag( char *argument )
{
 int counter;
 char arg[ 512 ];
 if ( argument[ 0 ] == '\0' )
  return 0;
 argument = one_argument( argument, arg );
 if ( arg[ 0 ] == '\0' )
  return 0;
 if ( argument[ 0 ] != '\0' && is_number( argument ) )
 {
  counter = atoi( argument );
  counter = UMAX( -1, counter );
 }
 else
  counter = 0;
 if ( !add_flag( &misc.global_flag_list, arg, counter ) )
  return 0;
 save_misc_data();
 if ( arg[ 0 ] == 'r' && arg[ 1 ] == 'e' && arg[ 2 ] == 'g' )
  return 1;
 return 1;
}

canonical_original_code:
unsigned char setglobalflag(char *argument)
{
 int counter;
 char arg[512];
 if ( argument[ 0 ] == '\0' )
  return 0;
 argument = one_argument( argument, arg );
 if ( arg[ 0 ] == '\0' )
  return 0;
 if ( argument[ 0 ] != '\0' && is_number( argument ) )
 {
  counter = atoi( argument );
  counter = UMAX( -1, counter );
 }
 else
  counter = 0;
 if ( !add_flag( &misc.global_flag_list, arg, counter ) )
  return 0;
 save_misc_data();
 if ( arg[ 0 ] == 'r' && arg[ 1 ] == 'e' && arg[ 2 ] == 'g' )
  return 1;
 return 1;
}

variable_types: counter int

variable_types:
arg
char [512]

return_type: unsigned char


removeglobalflag

decompiled_code:
__int64 __fastcall removeglobalflag(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 )
result = rem_flag((__int64 *)(unsigned int)((_DWORD)misc + 40), (__int64)a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_BYTE *a1)
{
__int64 result; // rax

result = 0LL;
if ( *a1 )
result = func0((__int64 *)(unsigned int)((_DWORD)misc + 40), (__int64)a1);
return result;
}

original_code:
bool removeglobalflag( char *argument )
{
 if ( argument[ 0 ] == '\0' )
  return 0;
 return rem_flag( &misc.global_flag_list, argument );
}

canonical_original_code:
unsigned char removeglobalflag(char *argument)
{
 if ( argument[ 0 ] == '\0' )
  return 0;
 return rem_flag( &misc.global_flag_list, argument );
}


decompiled_code:
__int64 __fastcall flag_exists(unsigned __int8 *a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
if ( !a2 )
return 0LL;
do
{
if ( *((_BYTE *)&upper_nopol + *a1) == *((_BYTE *)&upper_nopol + **(unsigned __int8 **)(v2 + 8))
&& !(unsigned __int8)str_cmp(a1) )
{
return 1LL;
}
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 *a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
if ( !a2 )
return 0LL;
do
{
if ( *((_BYTE *)&upper_nopol + *a1) == *((_BYTE *)&upper_nopol + **(unsigned __int8 **)(v2 + 8))
&& !(unsigned __int8)str_cmp(a1) )
{
return 1LL;
}
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
return 0LL;
}

original_code:
bool flag_exists( char *buf, PFLAG_DATA *plist )
{
 PFLAG_DATA * flag;
 for ( flag = plist; flag; flag = flag->next )
  if ( ( upper_nopol[(unsigned char)(buf[ 0 ])]) == ( upper_nopol[(unsigned char)(flag->id[ 0 ])]) && !str_cmp( buf, flag->id ) )
   return 1;
 return 0;
}

canonical_original_code:
unsigned char flag_exists(char *buf, struct pflag_data *plist)
{
 struct pflag_data *flag;
 for ( flag = plist; flag; flag = flag->next )
  if ( ( upper_nopol[(unsigned char)(buf[ 0 ])]) == ( upper_nopol[(unsigned char)(flag->id[ 0 ])]) && !str_cmp( buf, flag->id ) )
   return 1;
 return 0;
}

variable_types:
buf
char *

user_defined_types: struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; }


decompiled_code:
void update_global_flags()
{
__int64 v0; // rbx
__int64 v1; // rdx
unsigned __int8 *v2; // rdi
int v3; // eax
int v4; // eax

v0 = misc[5];
while ( v0 )
{
v1 = v0;
v0 = *(_QWORD *)(v0 + 24);
v2 = *(unsigned __int8 **)(v1 + 8);
if ( *((_BYTE *)&upper_nopol + *v2) != 82
|| *((_BYTE *)&upper_nopol + v2[1]) != 69
|| *((_BYTE *)&upper_nopol + v2[2]) != 71 )
{
v3 = *(_DWORD *)(v1 + 16);
if ( v3 > 0 )
{
v4 = v3 - 1;
*(_DWORD *)(v1 + 16) = v4;
if ( v4 )
save_misc_data();
else
removeglobalflag(v2);
}
}
}
}

original_code:
void update_global_flags()
{
 PFLAG_DATA * global_flag, * global_flag_next;
 for ( global_flag = misc.global_flag_list ; global_flag ; global_flag = global_flag_next )
 {
  global_flag_next = global_flag->next;
  if ( ( upper_nopol[(unsigned char)(global_flag->id[ 0 ])]) == 'R' &&
       ( upper_nopol[(unsigned char)(global_flag->id[ 1 ])]) == 'E' &&
       ( upper_nopol[(unsigned char)(global_flag->id[ 2 ])]) == 'G' )
   continue;
  if ( global_flag->duration > 0 )
  {
   global_flag->duration--;
   if ( global_flag->duration == 0 )
    removeglobalflag( global_flag->id );
   else
    save_misc_data();
  }
 }
}

canonical_original_code:
void update_global_flags()
{
 struct pflag_data *global_flag; struct pflag_data *global_flag_next;
 for ( global_flag = misc.global_flag_list ; global_flag ; global_flag = global_flag_next )
 {
  global_flag_next = global_flag->next;
  if ( ( upper_nopol[(unsigned char)(global_flag->id[ 0 ])]) == 'R' &&
       ( upper_nopol[(unsigned char)(global_flag->id[ 1 ])]) == 'E' &&
       ( upper_nopol[(unsigned char)(global_flag->id[ 2 ])]) == 'G' )
   continue;
  if ( global_flag->duration > 0 )
  {
   global_flag->duration--;
   if ( global_flag->duration == 0 )
    removeglobalflag( global_flag->id );
   else
    save_misc_data();
  }
 }
}

return_type: void


decompiled_code:
void *__fastcall zlib_alloc(__int64 a1, unsigned int a2, unsigned int a3)
{
return calloc(a2, a3);
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
return calloc(a2, a3);
}

original_code:
void *zlib_alloc(void *opaque, unsigned int items, unsigned int size)
{
    return calloc(items, size);
}

variable_types:
opaque
void *

variable_types:
items
unsigned int

variable_types:
size
unsigned int

return_type: void *


decompiled_code:
void __fastcall zlib_free(__int64 a1, void *a2)
{
if ( a2 )
free(a2);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, void *a2)
{
if ( a2 )
free(a2);
}

original_code:
void zlib_free(void *opaque, void *address)
{
    do { if((address)) { free((address)); (address) = ((void *)0); } } while(0);
}

variable_types:
address
void *


decompiled_code:
__int64 __fastcall get_langflag(__int64 a1)
{
__int64 result; // rax
__int64 i; // rbx
__int64 v3; // r12

result = *((unsigned int *)&lang_table + 2);
if ( (_DWORD)result )
{
for ( i = 0LL; ; ++i )
{
v3 = 2 * i;
if ( !(unsigned __int8)str_cmp(a1, (&lang_table)[2 * i]) )
break;
result = LODWORD((&lang_table)[v3 + 3]);
if ( !(_DWORD)result )
return result;
}
result = LODWORD((&lang_table)[2 * (int)i + 1]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
__int64 i; // rbx
__int64 v3; // r12

result = *((unsigned int *)&lang_table + 2);
if ( (_DWORD)result )
{
for ( i = 0LL; ; ++i )
{
v3 = 2 * i;
if ( !(unsigned __int8)str_cmp(a1, (&lang_table)[2 * i]) )
break;
result = LODWORD((&lang_table)[v3 + 3]);
if ( !(_DWORD)result )
return result;
}
result = LODWORD((&lang_table)[2 * (int)i + 1]);
}
return result;
}

original_code:
int get_langflag( char *flag )
{
 int x;
 for ( x = 0; lang_table[x].bit != 0; x++ )
  if ( !str_cmp( flag, lang_table[x].name ) )
   return lang_table[x].bit;
 return 0;
}

canonical_original_code:
int get_langflag(char *flag)
{
 int x;
 for ( x = 0; lang_table[x].bit != 0; x++ )
  if ( !str_cmp( flag, lang_table[x].name ) )
   return lang_table[x].bit;
 return 0;
}

variable_types:
flag
char *

variable_types: x int

return_type: int


decompiled_code:
__int64 __fastcall get_langnum(__int64 a1)
{
__int64 i; // rbx
unsigned int v2; // er14
__int64 v3; // r12

if ( !*((_DWORD *)&lang_table + 2) )
return (unsigned int)-1;
for ( i = 0LL; ; ++i )
{
v2 = i;
v3 = 2 * i;
if ( !(unsigned __int8)str_prefix(a1, (&lang_table)[2 * i]) )
break;
if ( !LODWORD((&lang_table)[v3 + 3]) )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 i; // rbx
unsigned int v2; // er14
__int64 v3; // r12

if ( !*((_DWORD *)&lang_table + 2) )
return (unsigned int)-1;
for ( i = 0LL; ; ++i )
{
v2 = i;
v3 = 2 * i;
if ( !(unsigned __int8)str_prefix(a1, (&lang_table)[2 * i]) )
break;
if ( !LODWORD((&lang_table)[v3 + 3]) )
return (unsigned int)-1;
}
return v2;
}

original_code:
int get_langnum( char *flag )
{
        int x;
        for ( x = 0; lang_table[x].bit != 0; x++ )
            if ( !str_prefix( flag, lang_table[x].name ) )
                return x;
        return -1;
}

canonical_original_code:
int get_langnum(char *flag)
{
        int x;
        for ( x = 0; lang_table[x].bit != 0; x++ )
            if ( !str_prefix( flag, lang_table[x].name ) )
                return x;
        return -1;
}


translate

original_code:
char *translate(int percent, const char *in, const char *name)
{
    LCNV_DATA *cnv;
    static char buf[2 * 512 ];
    char buf2[ 2 * 512 ];
    const char *pbuf;
    char *pbuf2 = buf2;
    LANG_DATA *lng;
    if ( percent > 99 )
 return (char *) in;
    if ( !(lng=get_lang(name)) )
 if ( !(lng = get_lang("default")) )
     return (char *) in;
    for (pbuf = in; *pbuf;)
    {
 for (cnv = lng->first_precnv; cnv; cnv = cnv->next)
 {
     if (!str_prefix(cnv->old, pbuf))
     {
  if ( (percent > 0) && ( ((number_percent() + number_percent()) /2) < percent ))
  {
      strncpy(pbuf2, pbuf, cnv->olen);
      pbuf2[cnv->olen] = '\0';
      pbuf2 += cnv->olen;
  }
  else
  {
      strcpy(pbuf2, cnv->new);
      pbuf2 += cnv->nlen;
  }
  pbuf += cnv->olen;
  break;
     }
 }
 if (!cnv)
 {
     if (((*__ctype_b_loc ())[(int) ((*pbuf))] & (unsigned short int) _ISalpha) && (!percent || ((number_percent() + number_percent())/2) > percent) )
     {
  *pbuf2 = lng->alphabet[( lower_pol[(unsigned char)(*pbuf)]) - 'a'];
  if ( ((*__ctype_b_loc ())[(int) ((*pbuf))] & (unsigned short int) _ISupper) )
      *pbuf2 = ( upper_pol[(unsigned char)(*pbuf2)]);
     }
     else
  *pbuf2 = *pbuf;
     pbuf++;
     pbuf2++;
 }
    }
    *pbuf2 = '\0';
    for (pbuf = buf2, pbuf2 = buf; *pbuf;)
    {
 for (cnv = lng->first_cnv; cnv; cnv = cnv->next)
     if (!str_prefix(cnv->old, pbuf))
     {
  strcpy(pbuf2, cnv->new);
  pbuf += cnv->olen;
  pbuf2 += cnv->nlen;
  break;
     }
 if (!cnv)
     *(pbuf2++) = *(pbuf++);
    }
    *pbuf2 = '\0';
    return buf;
}

canonical_original_code:
char *translate(int percent, char *in, char *name)
{
    struct lcnv_data *cnv;
    static char buf[-1];
    char buf2[-1];
    char *pbuf;
    char *pbuf2 = buf2;
    struct lang_data *lng;
    if ( percent > 99 )
 return (char *) in;
    if ( !(lng=get_lang(name)) )
 if ( !(lng = get_lang("default")) )
     return (char *) in;
    for (pbuf = in; *pbuf;)
    {
 for (cnv = lng->first_precnv; cnv; cnv = cnv->next)
 {
     if (!str_prefix(cnv->old, pbuf))
     {
  if ( (percent > 0) && ( ((number_percent() + number_percent()) /2) < percent ))
  {
      strncpy(pbuf2, pbuf, cnv->olen);
      pbuf2[cnv->olen] = '\0';
      pbuf2 += cnv->olen;
  }
  else
  {
      strcpy(pbuf2, cnv->new);
      pbuf2 += cnv->nlen;
  }
  pbuf += cnv->olen;
  break;
     }
 }
 if (!cnv)
 {
     if (((*__ctype_b_loc ())[(int) ((*pbuf))] & (unsigned short) _ISalpha) && (!percent || ((number_percent() + number_percent())/2) > percent) )
     {
  *pbuf2 = lng->alphabet[( lower_pol[(unsigned char)(*pbuf)]) - 'a'];
  if ( ((*__ctype_b_loc ())[(int) ((*pbuf))] & (unsigned short) _ISupper) )
      *pbuf2 = ( upper_pol[(unsigned char)(*pbuf2)]);
     }
     else
  *pbuf2 = *pbuf;
     pbuf++;
     pbuf2++;
 }
    }
    *pbuf2 = '\0';
    for (pbuf = buf2, pbuf2 = buf; *pbuf;)
    {
 for (cnv = lng->first_cnv; cnv; cnv = cnv->next)
     if (!str_prefix(cnv->old, pbuf))
     {
  strcpy(pbuf2, cnv->new);
  pbuf += cnv->olen;
  pbuf2 += cnv->nlen;
  break;
     }
 if (!cnv)
     *(pbuf2++) = *(pbuf++);
    }
    *pbuf2 = '\0';
    return buf;
}

variable_types: percent int

variable_types:
in
char *

variable_types:
name
char *

variable_types:
buf
char [-1]

variable_types:
pbuf
char *

variable_types: struct lang_data { struct lang_data *next; char *name; struct lcnv_data { struct lcnv_data *next; char *old; int olen; char *new; int nlen; } *first_precnv; char *alphabet; struct lcnv_data *first_cnv; } *

return_type: char *

user_defined_types: struct lang_data { struct lang_data *next; char *name; struct lcnv_data *first_precnv; char *alphabet; struct lcnv_data *first_cnv; }


original_code:
char *translate_gnomish( char *string )
{
    static char buf[ 8192 ];
    char *point;
    buf[0] = '\0';
    point = buf;
    while ( *string )
    {
        if ( ((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short int) _ISspace) )
        {
            if ( !((*__ctype_b_loc ())[(int) ((*( string + 1 )))] & (unsigned short int) _ISspace) )
                *point++ = ( upper_pol[(unsigned char)(*++string)]);
            string++;
        }
        else
            *point++ = *string++;
    }
    *point = '\0';
    buf[0] = ( upper_pol[(unsigned char)(buf[0])]);
    return buf;
}

canonical_original_code:
char *translate_gnomish(char *string)
{
    static char buf[8192];
    char *point;
    buf[0] = '\0';
    point = buf;
    while ( *string )
    {
        if ( ((*__ctype_b_loc ())[(int) ((*string))] & (unsigned short) _ISspace) )
        {
            if ( !((*__ctype_b_loc ())[(int) ((*( string + 1 )))] & (unsigned short) _ISspace) )
                *point++ = ( upper_pol[(unsigned char)(*++string)]);
            string++;
        }
        else
            *point++ = *string++;
    }
    *point = '\0';
    buf[0] = ( upper_pol[(unsigned char)(buf[0])]);
    return buf;
}

variable_types:
string
char *

variable_types:
buf
char [8192]

variable_types:
point
char *


decompiled_code:
__int64 __fastcall init_genrand(unsigned int a1)
{
__int64 i; // rdx
__int64 result; // rax

mt[0] = a1;
for ( i = 1LL; i != 624; ++i )
{
result = (unsigned int)i
+ 1812433253 * ((unsigned int)*(_QWORD *)(8 * i + 0x438) ^ (unsigned int)(*(_QWORD *)(8 * i + 0x438) >> 30));
mt[i] = result;
}
mti = 624;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 i; // rdx
__int64 result; // rax

mt[0] = a1;
for ( i = 1LL; i != 624; ++i )
{
result = (unsigned int)i
+ 1812433253 * ((unsigned int)*(_QWORD *)(8 * i + 0x438) ^ (unsigned int)(*(_QWORD *)(8 * i + 0x438) >> 30));
mt[i] = result;
}
mti = 624;
return result;
}

original_code:
void init_genrand(unsigned long s)
{
    mt[0]= s & 0xffffffffUL;
    for (mti=1; mti<624; mti++) {
        mt[mti] =
     (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
        mt[mti] &= 0xffffffffUL;
    }
}

variable_types:
s
unsigned long


variable_types:
y
unsigned long

variable_types: kk int

return_type: unsigned long


decompiled_code:
unsigned __int64 genrand_int31()
{
return genrand_int32() >> 1;
}

canonical_decompiled_code:
unsigned __int64 func3()
{
return func2() >> 1;
}

original_code:
long genrand_int31(void)
{
    return (long)(genrand_int32()>>1);
}

canonical_original_code:
long genrand_int31()
{
    return (long)(genrand_int32()>>1);
}

return_type: long


original_code:
double genrand_real1(void)
{
    return genrand_int32()*(1.0/4294967295.0);
}

canonical_original_code:
double genrand_real1()
{
    return genrand_int32()*(1.0/4294967295.0);
}

return_type: double


original_code:
double genrand_real2(void)
{
    return genrand_int32()*(1.0/4294967296.0);
}

canonical_original_code:
double genrand_real2()
{
    return genrand_int32()*(1.0/4294967296.0);
}


original_code:
double genrand_real3(void)
{
    return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
}


canonical_original_code:
double genrand_res53()
{
    unsigned long a = genrand_int32()>>5; unsigned long b = genrand_int32()>>6;
    return(a*67108864.0+b)*(1.0/9007199254740992.0);
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


original_code:
void init_random(long x, long y)
{
  unsigned long init[6]={0x871, 0x127, 0x003, 0x780, 0, 0}, length=6;
  init[4] = x;
  init[5] = y;
  init_by_array(init, length);
}

canonical_original_code:
void init_random(long x, long y)
{
  unsigned long init[6] = {0x871, 0x127, 0x003, 0x780, 0, 0}; unsigned long length = 6;
  init[4] = x;
  init[5] = y;
  init_by_array(init, length);
}

variable_types: x long

variable_types: y long

variable_types:
init
unsigned long [6]

variable_types:
length
unsigned long


decompiled_code:
__int64 __fastcall obj_interpret(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
__int64 v3; // rbx
char v4[544]; // [rsp+0h] [rbp-220h] BYREF

result = running_prog_env;
if ( *(_QWORD *)(running_prog_env + 32LL) )
{
v2 = one_argument(a1, v4);
result = *(unsigned __int8 *)obj_cmd_table[0];
if ( (_BYTE)result )
{
v3 = 0LL;
while ( v4[0] != (_BYTE)result || (unsigned __int8)str_prefix(v4) )
{
result = *(unsigned __int8 *)obj_cmd_table[2 * v3++ + 2];
if ( !(_BYTE)result )
return result;
}
obj_cmd_table[2 * (int)v3 + 1](v2);
result = tail_chain();
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r12
__int64 v3; // rbx
char v4[544]; // [rsp+0h] [rbp-220h] BYREF

result = running_prog_env;
if ( *(_QWORD *)(running_prog_env + 32LL) )
{
v2 = one_argument(a1, v4);
result = *(unsigned __int8 *)obj_cmd_table[0];
if ( (_BYTE)result )
{
v3 = 0LL;
while ( v4[0] != (_BYTE)result || (unsigned __int8)str_prefix(v4) )
{
result = *(unsigned __int8 *)obj_cmd_table[2 * v3++ + 2];
if ( !(_BYTE)result )
return result;
}
obj_cmd_table[2 * (int)v3 + 1](v2);
result = tail_chain();
}
}
return result;
}

original_code:
void obj_interpret( char *argument )
{
 char command[ 512 ];
 int cmd;
 if ( !running_prog_env->obj )
  return ;
 argument = one_argument( argument, command );
 for ( cmd = 0; obj_cmd_table[ cmd ].name[ 0 ] != '\0'; cmd++ )
 {
  if ( command[ 0 ] == obj_cmd_table[ cmd ].name[ 0 ]
       && !str_prefix( command, obj_cmd_table[ cmd ].name ) )
  {
   ( *obj_cmd_table[ cmd ].prog_fun ) ( argument );
   tail_chain( );
   return ;
  }
 }
 return ;
}

canonical_original_code:
void obj_interpret(char *argument)
{
 char command[512];
 int cmd;
 if ( !running_prog_env->obj )
  return ;
 argument = one_argument( argument, command );
 for ( cmd = 0; obj_cmd_table[ cmd ].name[ 0 ] != '\0'; cmd++ )
 {
  if ( command[ 0 ] == obj_cmd_table[ cmd ].name[ 0 ]
       && !str_prefix( command, obj_cmd_table[ cmd ].name ) )
  {
   ( *obj_cmd_table[ cmd ].prog_fun ) ( argument );
   tail_chain( );
   return ;
  }
 }
 return ;
}

variable_types:
argument
char *

variable_types:
command
char [512]

variable_types: cmd int


decompiled_code:
__int64 __fastcall do_osetflag(_BYTE *a1)
{
char v2[512]; // [rsp+0h] [rbp-200h] BYREF

if ( !*a1 )
return bug_prog_format("osetflag: missing argument");
expand_arg(v2, a1);
return setobjflag(*(_QWORD *)(running_prog_env + 32LL), v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
char v2[512]; // [rsp+0h] [rbp-200h] BYREF

if ( !*a1 )
return bug_prog_format("osetflag: missing argument");
expand_arg(v2, a1);
return setobjflag(*(_QWORD *)(running_prog_env + 32LL), v2);
}

original_code:
void do_osetflag( char *argument )
{
 char arg[ 512 ];
 if ( argument[ 0 ] == '\0' )
 {
  bug_prog_format( "osetflag: missing argument" );
  return ;
 }
 expand_arg( arg, argument );
 setobjflag( running_prog_env->obj, arg );
 return ;
}

canonical_original_code:
void do_osetflag(char *argument)
{
 char arg[512];
 if ( argument[ 0 ] == '\0' )
 {
  bug_prog_format( "osetflag: missing argument" );
  return ;
 }
 expand_arg( arg, argument );
 setobjflag( running_prog_env->obj, arg );
 return ;
}

variable_types:
arg
char [512]


decompiled_code:
int __fastcall do_omodflag(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rbx
unsigned __int8 *v5; // rsi
char v7[512]; // [rsp+0h] [rbp-810h] BYREF
char nptr[512]; // [rsp+200h] [rbp-610h] BYREF
char v9[512]; // [rsp+400h] [rbp-410h] BYREF
char v10[520]; // [rsp+600h] [rbp-210h] BYREF

v1 = one_argument(a1, v7);
expand_arg(v10, v7);
v2 = one_argument(v1, v7);
expand_arg(v9, v7);
expand_arg(nptr, v2);
if ( v10[0] && v9[0] )
{
v3 = *(_QWORD *)(running_prog_env + 32LL);
v4 = *(_QWORD *)(v3 + 96);
if ( v4 )
{
while ( 1 )
{
v5 = *(unsigned __int8 **)(v4 + 8);
LODWORD(v3) = *((unsigned __int8 *)&upper_nopol + *v5);
if ( *((_BYTE *)&upper_nopol + (unsigned __int8)v9[0]) == (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v9, v5);
if ( !(_BYTE)v3 )
break;
}
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
return v3;
}
LODWORD(v3) = str_cmp(v10, "set");
if ( (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v10, "mod");
if ( (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v10, "rem");
if ( !(_BYTE)v3 )
{
*(_DWORD *)(v4 + 16) = 0;
LODWORD(v3) = removeobjflag(*(_QWORD *)(running_prog_env + 32LL), *(_QWORD *)(v4 + 8));
}
}
else if ( nptr[0] )
{
LODWORD(v3) = is_number(nptr);
if ( (_BYTE)v3 )
{
LODWORD(v3) = atoi(nptr);
*(_DWORD *)(v4 + 16) += v3;
}
}
}
else if ( nptr[0] )
{
LODWORD(v3) = is_number(nptr);
if ( (_BYTE)v3 )
{
LODWORD(v3) = atoi(nptr);
*(_DWORD *)(v4 + 16) = v3;
}
}
}
}
else
{
LODWORD(v3) = bug_prog_format("omodflag: missing argument");
}
return v3;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rbx
unsigned __int8 *v5; // rsi
char v7[512]; // [rsp+0h] [rbp-810h] BYREF
char nptr[512]; // [rsp+200h] [rbp-610h] BYREF
char v9[512]; // [rsp+400h] [rbp-410h] BYREF
char v10[520]; // [rsp+600h] [rbp-210h] BYREF

v1 = one_argument(a1, v7);
expand_arg(v10, v7);
v2 = one_argument(v1, v7);
expand_arg(v9, v7);
expand_arg(nptr, v2);
if ( v10[0] && v9[0] )
{
v3 = *(_QWORD *)(running_prog_env + 32LL);
v4 = *(_QWORD *)(v3 + 96);
if ( v4 )
{
while ( 1 )
{
v5 = *(unsigned __int8 **)(v4 + 8);
LODWORD(v3) = *((unsigned __int8 *)&upper_nopol + *v5);
if ( *((_BYTE *)&upper_nopol + (unsigned __int8)v9[0]) == (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v9, v5);
if ( !(_BYTE)v3 )
break;
}
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
return v3;
}
LODWORD(v3) = str_cmp(v10, "set");
if ( (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v10, "mod");
if ( (_BYTE)v3 )
{
LODWORD(v3) = str_cmp(v10, "rem");
if ( !(_BYTE)v3 )
{
*(_DWORD *)(v4 + 16) = 0;
LODWORD(v3) = removeobjflag(*(_QWORD *)(running_prog_env + 32LL), *(_QWORD *)(v4 + 8));
}
}
else if ( nptr[0] )
{
LODWORD(v3) = is_number(nptr);
if ( (_BYTE)v3 )
{
LODWORD(v3) = atoi(nptr);
*(_DWORD *)(v4 + 16) += v3;
}
}
}
else if ( nptr[0] )
{
LODWORD(v3) = is_number(nptr);
if ( (_BYTE)v3 )
{
LODWORD(v3) = atoi(nptr);
*(_DWORD *)(v4 + 16) = v3;
}
}
}
}
else
{
LODWORD(v3) = bug_prog_format("omodflag: missing argument");
}
return v3;
}

original_code:
void do_omodflag( char *argument )
{
 PFLAG_DATA * list, *tmp = ((void *)0);
 int val;
 char arg[ 512 ];
 char arg2[ 512 ];
 char arg3[ 512 ];
 char expand[ 512 ];
 argument = one_argument( argument, expand );
 expand_arg( arg, expand );
 argument = one_argument( argument, expand );
 expand_arg( arg2, expand );
 expand_arg( arg3, argument );
 if ( arg[ 0 ] == '\0' || arg2[ 0 ] == '\0' )
 {
  bug_prog_format( "omodflag: missing argument" );
  return ;
 }
 for ( list = running_prog_env->obj->pflag_list; list; list = list->next )
  if ( ( upper_nopol[(unsigned char)(arg2[ 0 ])]) == ( upper_nopol[(unsigned char)(list->id[ 0 ])]) && !str_cmp( arg2, list->id ) )
  {
   tmp = list;
   break;
  }
 if ( !tmp )
  return ;
 if ( !str_cmp( arg, "set" ) )
 {
  if ( arg3[ 0 ] == '\0' || !is_number( arg3 ) )
   return ;
  val = atoi( arg3 );
  tmp->duration = val;
  return ;
 }
 else if ( !str_cmp( arg, "mod" ) )
 {
  if ( arg3[ 0 ] == '\0' || !is_number( arg3 ) )
   return ;
  val = atoi( arg3 );
  tmp->duration += val;
 }
 else if ( !str_cmp( arg, "rem" ) )
 {
  tmp->duration = 0;
  removeobjflag( running_prog_env->obj, tmp->id );
  return ;
 }
 return ;
}

canonical_original_code:
void do_omodflag(char *argument)
{
 struct pflag_data *list; struct pflag_data *tmp = ((void *)0);
 int val;
 char arg[512];
 char arg2[512];
 char arg3[512];
 char expand[512];
 argument = one_argument( argument, expand );
 expand_arg( arg, expand );
 argument = one_argument( argument, expand );
 expand_arg( arg2, expand );
 expand_arg( arg3, argument );
 if ( arg[ 0 ] == '\0' || arg2[ 0 ] == '\0' )
 {
  bug_prog_format( "omodflag: missing argument" );
  return ;
 }
 for ( list = running_prog_env->obj->pflag_list; list; list = list->next )
  if ( ( upper_nopol[(unsigned char)(arg2[ 0 ])]) == ( upper_nopol[(unsigned char)(list->id[ 0 ])]) && !str_cmp( arg2, list->id ) )
  {
   tmp = list;
   break;
  }
 if ( !tmp )
  return ;
 if ( !str_cmp( arg, "set" ) )
 {
  if ( arg3[ 0 ] == '\0' || !is_number( arg3 ) )
   return ;
  val = atoi( arg3 );
  tmp->duration = val;
  return ;
 }
 else if ( !str_cmp( arg, "mod" ) )
 {
  if ( arg3[ 0 ] == '\0' || !is_number( arg3 ) )
   return ;
  val = atoi( arg3 );
  tmp->duration += val;
 }
 else if ( !str_cmp( arg, "rem" ) )
 {
  tmp->duration = 0;
  removeobjflag( running_prog_env->obj, tmp->id );
  return ;
 }
 return ;
}

variable_types: struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; } *

variable_types: val int

variable_types:
expand
char [512]


decompiled_code:
__int64 __fastcall do_ostring(_BYTE *a1)
{
char v2[512]; // [rsp+0h] [rbp-200h] BYREF

if ( !*a1 )
return bug_prog_format("ostring: missing argument");
expand_arg(v2, a1);
return objstring(*(_QWORD *)(running_prog_env + 32LL), v2);
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
char v2[512]; // [rsp+0h] [rbp-200h] BYREF

if ( !*a1 )
return bug_prog_format("ostring: missing argument");
expand_arg(v2, a1);
return objstring(*(_QWORD *)(running_prog_env + 32LL), v2);
}

original_code:
void do_ostring( char *argument )
{
 char arg[ 512 ];
 if ( argument[ 0 ] == '\0' )
 {
  bug_prog_format( "ostring: missing argument" );
  return ;
 }
 expand_arg( arg, argument );
 objstring( running_prog_env->obj, arg );
}

canonical_original_code:
void do_ostring(char *argument)
{
 char arg[512];
 if ( argument[ 0 ] == '\0' )
 {
  bug_prog_format( "ostring: missing argument" );
  return ;
 }
 expand_arg( arg, argument );
 objstring( running_prog_env->obj, arg );
}


decompiled_code:
__int64 do_objwear()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 v2; // rdi

result = running_prog_env;
v1 = *(_QWORD *)(running_prog_env + 32LL);
v2 = *(_QWORD *)(v1 + 40);
if ( v2 )
{
equip_char(v2, v1, (unsigned int)*(__int16 *)(v1 + 306), 0LL);
result = *(_QWORD *)(running_prog_env + 32LL);
*(_WORD *)(result + 306) = -1;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 v2; // rdi

result = running_prog_env;
v1 = *(_QWORD *)(running_prog_env + 32LL);
v2 = *(_QWORD *)(v1 + 40);
if ( v2 )
{
equip_char(v2, v1, (unsigned int)*(__int16 *)(v1 + 306), 0LL);
result = *(_QWORD *)(running_prog_env + 32LL);
*(_WORD *)(result + 306) = -1;
}
return result;
}

original_code:
void do_objwear( char *argument )
{
 if ( !running_prog_env->obj->carried_by )
  return ;
 equip_char( running_prog_env->obj->carried_by, running_prog_env->obj, running_prog_env->obj->prewear_loc, 0 );
 running_prog_env->obj->prewear_loc = -1;
}

canonical_original_code:
void do_objwear(char *argument)
{
 if ( !running_prog_env->obj->carried_by )
  return ;
 equip_char( running_prog_env->obj->carried_by, running_prog_env->obj, running_prog_env->obj->prewear_loc, 0 );
 running_prog_env->obj->prewear_loc = -1;
}


decompiled_code:
__int64 do_objunwear()
{
__int64 result; // rax
__int64 v1; // rdi

result = running_prog_env;
v1 = *(_QWORD *)(*(_QWORD *)(running_prog_env + 32LL) + 40LL);
if ( v1 )
result = unequip_char(v1);
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
__int64 v1; // rdi

result = running_prog_env;
v1 = *(_QWORD *)(*(_QWORD *)(running_prog_env + 32LL) + 40LL);
if ( v1 )
result = unequip_char(v1);
return result;
}

original_code:
void do_objunwear( char *argument )
{
 if ( !running_prog_env->obj->carried_by )
  return ;
 unequip_char( running_prog_env->obj->carried_by, running_prog_env->obj );
}

canonical_original_code:
void do_objunwear(char *argument)
{
 if ( !running_prog_env->obj->carried_by )
  return ;
 unequip_char( running_prog_env->obj->carried_by, running_prog_env->obj );
}


decompiled_code:
__int64 __fastcall translate_buffer(iconv_t cd, void *dest, unsigned __int64 a3)
{
size_t v5; // r12
const void *v6; // rsi
int v7; // edx
__int64 result; // rax
int *v9; // rax
char *v10; // rax
char *inbuf; // [rsp+0h] [rbp-40h] BYREF
char *outbuf; // [rsp+8h] [rbp-38h] BYREF
size_t inbytesleft; // [rsp+10h] [rbp-30h] BYREF
size_t outbytesleft[5]; // [rsp+18h] [rbp-28h] BYREF

if ( !buf_2 )
{
buf_len_1 = 0x200000LL;
buf_2 = malloc(0x200000uLL);
}
v5 = buf_len_1 - 1;
if ( buf_len_1 - 1 < a3 )
{
logformat("%s, %s, %d: buffer too long, sorry.", "charset_utils.c", "translate_buffer", 48LL);
result = 0LL;
}
else
{
inbuf = (char *)dest;
outbuf = (char *)buf_2;
inbytesleft = strlen((const char *)dest);
outbytesleft[0] = v5;
if ( iconv(cd, &inbuf, &inbytesleft, &outbuf, outbytesleft) == -1LL )
{
v9 = _errno_location();
v10 = strerror(*v9);
logformat("%s, %s, %d: iconv returned -1. errno=%s.", "charset_utils.c", "translate_buffer", 66LL, v10);
result = 0LL;
}
else
{
v6 = buf_2;
v7 = (_DWORD)outbuf - (_DWORD)buf_2;
*((_BYTE *)buf_2 + (int)outbuf - (int)buf_2) = 0;
memcpy(dest, v6, v7 + 1);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(iconv_t cd, void *dest, unsigned __int64 a3)
{
size_t v5; // r12
const void *v6; // rsi
int v7; // edx
__int64 result; // rax
int *v9; // rax
char *v10; // rax
char *inbuf; // [rsp+0h] [rbp-40h] BYREF
char *outbuf; // [rsp+8h] [rbp-38h] BYREF
size_t inbytesleft; // [rsp+10h] [rbp-30h] BYREF
size_t outbytesleft[5]; // [rsp+18h] [rbp-28h] BYREF

if ( !buf_2 )
{
buf_len_1 = 0x200000LL;
buf_2 = malloc(0x200000uLL);
}
v5 = buf_len_1 - 1;
if ( buf_len_1 - 1 < a3 )
{
logformat("%s, %s, %d: buffer too long, sorry.", "charset_utils.c", "translate_buffer", 48LL);
result = 0LL;
}
else
{
inbuf = (char *)dest;
outbuf = (char *)buf_2;
inbytesleft = strlen((const char *)dest);
outbytesleft[0] = v5;
if ( iconv(cd, &inbuf, &inbytesleft, &outbuf, outbytesleft) == -1LL )
{
v9 = _errno_location();
v10 = strerror(*v9);
logformat("%s, %s, %d: iconv returned -1. errno=%s.", "charset_utils.c", "translate_buffer", 66LL, v10);
result = 0LL;
}
else
{
v6 = buf_2;
v7 = (_DWORD)outbuf - (_DWORD)buf_2;
*((_BYTE *)buf_2 + (int)outbuf - (int)buf_2) = 0;
memcpy(dest, v6, v7 + 1);
result = 1LL;
}
}
return result;
}

original_code:
int translate_buffer(iconv_t p_iconv,
                     char * p_buffer,
                     size_t p_buffer_len)
{
  static char * buf = ((void *)0);
  static size_t buf_len = 0;
  int copy_cnt;
  if (!buf)
    {
      buf_len = 2 * 1024 * 1024;
      buf = malloc(sizeof(char) * buf_len);
    }
  if ( p_buffer_len > buf_len-1 )
    {
      logformat ( "%s, %s, %d: buffer too long, sorry.", "charset_utils.c", __func__, 48 );
      return 0;
    }
  {
    char * buf_in = p_buffer;
    char * buf_out = buf;
    size_t buf_in_left = strlen(p_buffer);
    size_t buf_out_left = buf_len-1;
    if ( -1 == iconv( p_iconv,
                      &buf_in, &buf_in_left,
                      &buf_out, &buf_out_left ) )
      {
        logformat ( "%s, %s, %d: iconv returned -1. errno=%s.", "charset_utils.c", __func__, 66, strerror((*__errno_location ())) );
        return 0;
      }
    copy_cnt = buf_out - buf;
    buf[copy_cnt] = '\0';
  }
  {
    memcpy(p_buffer, buf, copy_cnt+1);
  }
  return 1;
}

canonical_original_code:
int translate_buffer(void *p_iconv, char *p_buffer, unsigned long p_buffer_len)
{
  static char *buf = ((void *)0);
  static unsigned long buf_len = 0;
  int copy_cnt;
  if (!buf)
    {
      buf_len = 2 * 1024 * 1024;
      buf = malloc(sizeof(char) * buf_len);
    }
  if ( p_buffer_len > buf_len-1 )
    {
      logformat ( "%s, %s, %d: buffer too long, sorry.", "charset_utils.c", __func__, 48 );
      return 0;
    }
  {
    char *buf_in = p_buffer;
    char *buf_out = buf;
    unsigned long buf_in_left = strlen(p_buffer);
    unsigned long buf_out_left = buf_len-1;
    if ( -1 == iconv( p_iconv,
                      &buf_in, &buf_in_left,
                      &buf_out, &buf_out_left ) )
      {
        logformat ( "%s, %s, %d: iconv returned -1. errno=%s.", "charset_utils.c", __func__, 66, strerror((*__errno_location ())) );
        return 0;
      }
    copy_cnt = buf_out - buf;
    buf[copy_cnt] = '\0';
  }
  {
    memcpy(p_buffer, buf, copy_cnt+1);
  }
  return 1;
}

variable_types:
buf
char *


decompiled_code:
iconv_t init_iconv()
{
iconv_t result; // rax

to_pol = (__int64)iconv_open("ASCII//TRANSLIT", "ISO-8859-2");
to_iso = (__int64)iconv_open("ISO-8859-2//TRANSLIT", "ISO-8859-2");
to_win = (__int64)iconv_open("CP-1250//TRANSLIT", "ISO-8859-2");
result = iconv_open("UTF-8//TRANSLIT", "ISO-8859-2");
to_utf8 = (__int64)result;
return result;
}

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

to_pol = (__int64)iconv_open("ASCII//TRANSLIT", "ISO-8859-2");
to_iso = (__int64)iconv_open("ISO-8859-2//TRANSLIT", "ISO-8859-2");
to_win = (__int64)iconv_open("CP-1250//TRANSLIT", "ISO-8859-2");
result = iconv_open("UTF-8//TRANSLIT", "ISO-8859-2");
to_utf8 = (__int64)result;
return result;
}

original_code:
void init_iconv(void)
{
  to_pol = iconv_open("ASCII//TRANSLIT",MUD_CHARSET);
  to_iso = iconv_open("ISO-8859-2//TRANSLIT",MUD_CHARSET);
  to_win = iconv_open("CP-1250//TRANSLIT",MUD_CHARSET);
  to_utf8 = iconv_open("UTF-8//TRANSLIT",MUD_CHARSET);
}

canonical_original_code:
void init_iconv()
{
  to_pol = iconv_open("ASCII//TRANSLIT",MUD_CHARSET);
  to_iso = iconv_open("ISO-8859-2//TRANSLIT",MUD_CHARSET);
  to_win = iconv_open("CP-1250//TRANSLIT",MUD_CHARSET);
  to_utf8 = iconv_open("UTF-8//TRANSLIT",MUD_CHARSET);
}


decompiled_code:
__int64 gl_empty()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 0LL;
}

original_code:
genlist * gl_empty(void)
{
  return ((void *)0);
}

canonical_original_code:
struct genlist *gl_empty()
{
  return ((void *)0);
}

return_type: struct genlist { void *payload; struct genlist *next; } *


decompiled_code:
void __fastcall gl_iterate_list(_QWORD *a1, unsigned int (__fastcall *a2)(_QWORD))
{
_QWORD *i; // rbx

for ( i = a1; i; i = (_QWORD *)i[1] )
{
if ( !a2(*i) )
break;
}
}

canonical_decompiled_code:
void __fastcall func6(_QWORD *a1, unsigned int (__fastcall *a2)(_QWORD))
{
_QWORD *i; // rbx

for ( i = a1; i; i = (_QWORD *)i[1] )
{
if ( !a2(*i) )
break;
}
}

original_code:
void gl_iterate_list(genlist * gl, FLOW_CONTROL (*iteratee)(void*))
{
  genlist * gl_ptr;
  for(gl_ptr = gl; gl_ptr; gl_ptr = gl_ptr->next)
    {
      FLOW_CONTROL fc = (*iteratee)(gl_ptr->payload);
      if (fc == STOP)
        return;
    }
}

canonical_original_code:
void gl_iterate_list(struct genlist *gl, enum FLOW_CONTROL (*iteratee)(void *))
{
  struct genlist *gl_ptr;
  for(gl_ptr = gl; gl_ptr; gl_ptr = gl_ptr->next)
    {
      enum FLOW_CONTROL fc = (*iteratee)(gl_ptr->payload);
      if (fc == STOP)
        return;
    }
}

variable_types: struct genlist { void *payload; struct genlist *next; } *

variable_types: enum FLOW_CONTROL { STOP=0, CONTINUE=1, SKIP=2 } (*)(void *)


original_code:
void * gl_find(genlist * gl, int (*pred)(void*) )
{
  void * retval = ((void *)0);
  FLOW_CONTROL fun(void * payload)
  {
    if ((*pred)(payload))
      {
        retval = payload;
        return STOP;
      }
    return CONTINUE;
  };
  gl_iterate_list(gl, fun);
  return retval;
}

canonical_original_code:
void *gl_find(struct genlist *gl, int (*pred)(void *))
{
  void *retval = ((void *)0);
  FLOW_CONTROL fun(void * payload)
  {
    if ((*pred)(payload))
      {
        retval = payload;
        return STOP;
      }
    return CONTINUE;
  };
  gl_iterate_list(gl, fun);
  return retval;
}

variable_types:
pred
int (*)(void *)

variable_types:
retval
void *

user_defined_types: struct genlist { void *payload; struct genlist *next; }


decompiled_code:
void gl_selftest()
{
_QWORD *v0; // rbx
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
__int64 v4; // r9
unsigned int *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
unsigned int *v10; // rax
char v11; // [rsp+0h] [rbp-30h]
char v12; // [rsp+0h] [rbp-30h]
_QWORD *v13; // [rsp+8h] [rbp-28h] BYREF
__int64 v14; // [rsp+10h] [rbp-20h] BYREF
int v15; // [rsp+18h] [rbp-18h] BYREF
int v16[3]; // [rsp+1Ch] [rbp-14h] BYREF

v0 = (_QWORD *)gl_empty();
v13 = v0;
v14 = 0x200000001LL;
v15 = 3;
v16[0] = 4;
gl_push_front(&v13, (__int64)&v14);
gl_push_front(&v13, (__int64)&v14 + 4);
gl_push_front(&v13, (__int64)&v15);
gl_push_front(&v13, (__int64)v16);
gl_iterate_list(v13, (unsigned int (__fastcall *)(_QWORD))iteratee_3);
v5 = (unsigned int *)gl_find(v13, (__int64)is_equal_to_two_2, v1, v2, v3, v4, v11);
if ( v5 )
printf("Found 2: %d\n", *v5);
v10 = (unsigned int *)gl_find(v13, (__int64)is_equal_to_five_1, v6, v7, v8, v9, v12);
if ( v10 )
printf("Found 5, but shouldn't! %d\n", *v10);
else
puts("NULL returned - not '5' in list - OK");
v14 = (__int64)v0;
gl_push_front(&v14, (__int64)"foo");
gl_push_front(&v14, (__int64)"bar");
gl_push_front(&v14, (__int64)"baz");
gl_push_front(&v14, (__int64)"xyz");
gl_push_front(&v14, (__int64)"var");
gl_iterate_list((_QWORD *)v14, (unsigned int (__fastcall *)(_QWORD))iteratee_0);
}

canonical_decompiled_code:
void func8()
{
_QWORD *v0; // rbx
__int64 v1; // rdx
__int64 v2; // rcx
__int64 v3; // r8
__int64 v4; // r9
unsigned int *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
unsigned int *v10; // rax
char v11; // [rsp+0h] [rbp-30h]
char v12; // [rsp+0h] [rbp-30h]
_QWORD *v13; // [rsp+8h] [rbp-28h] BYREF
__int64 v14; // [rsp+10h] [rbp-20h] BYREF
int v15; // [rsp+18h] [rbp-18h] BYREF
int v16[3]; // [rsp+1Ch] [rbp-14h] BYREF

v0 = (_QWORD *)func5();
v13 = v0;
v14 = 0x200000001LL;
v15 = 3;
v16[0] = 4;
gl_push_front(&v13, (__int64)&v14);
gl_push_front(&v13, (__int64)&v14 + 4);
gl_push_front(&v13, (__int64)&v15);
gl_push_front(&v13, (__int64)v16);
func6(v13, (unsigned int (__fastcall *)(_QWORD))iteratee_3);
v5 = (unsigned int *)func7(v13, (__int64)is_equal_to_two_2, v1, v2, v3, v4, v11);
if ( v5 )
printf("Found 2: %d\n", *v5);
v10 = (unsigned int *)func7(v13, (__int64)is_equal_to_five_1, v6, v7, v8, v9, v12);
if ( v10 )
printf("Found 5, but shouldn't! %d\n", *v10);
else
puts("NULL returned - not '5' in list - OK");
v14 = (__int64)v0;
gl_push_front(&v14, (__int64)"foo");
gl_push_front(&v14, (__int64)"bar");
gl_push_front(&v14, (__int64)"baz");
gl_push_front(&v14, (__int64)"xyz");
gl_push_front(&v14, (__int64)"var");
func6((_QWORD *)v14, (unsigned int (__fastcall *)(_QWORD))iteratee_0);
}

original_code:
void gl_selftest(void)
{
  {
    genlist * g;
    g = gl_empty();
    int arr[] = { 1, 2, 3, 4 };
    gl_push_front(&g, &arr[0]);
    gl_push_front(&g, &arr[1]);
    gl_push_front(&g, &arr[2]);
    gl_push_front(&g, &arr[3]);
    FLOW_CONTROL iteratee(void * ptr)
    {
      int * num = ptr;
      printf("%d\n", *num);
      return CONTINUE;
    }
    gl_iterate_list(g, iteratee);
    int is_equal_to_two(void * ptr)
    {
      int * num = ptr;
      return (*num == 2);
    }
    int is_equal_to_five(void * ptr)
    {
      int * num = ptr;
      return (*num == 5);
    }
    {
      int * ptr = gl_find( g, is_equal_to_two );
      if ( ptr )
        {
          printf("Found 2: %d\n", *ptr);
        }
    }
    {
      int * ptr = gl_find( g, is_equal_to_five );
      if ( ptr )
        {
          printf("Found 5, but shouldn't! %d\n", *ptr);
        }
      else
        {
          printf("NULL returned - not '5' in list - OK\n");
        }
    }
  }
  {
    genlist * g;
    g = gl_empty();
    gl_push_front(&g, "foo");
    gl_push_front(&g, "bar");
    gl_push_front(&g, "baz");
    gl_push_front(&g, "xyz");
    gl_push_front(&g, "var");
    FLOW_CONTROL iteratee(void * ptr)
    {
      char * str = ptr;
      printf("%s\n", str);
      return CONTINUE;
    }
    gl_iterate_list(g, iteratee);
  }
}

canonical_original_code:
void gl_selftest()
{
  {
    struct genlist *g;
    g = gl_empty();
    int arr[] = { 1, 2, 3, 4 };
    gl_push_front(&g, &arr[0]);
    gl_push_front(&g, &arr[1]);
    gl_push_front(&g, &arr[2]);
    gl_push_front(&g, &arr[3]);
    FLOW_CONTROL iteratee(void * ptr)
    {
      int *num = ptr;
      printf("%d\n", *num);
      return CONTINUE;
    }
    gl_iterate_list(g, iteratee);
    int is_equal_to_two(void * ptr)
    {
      int *num = ptr;
      return (*num == 2);
    }
    int is_equal_to_five(void * ptr)
    {
      int *num = ptr;
      return (*num == 5);
    }
    {
      int *ptr = gl_find( g, is_equal_to_two );
      if ( ptr )
        {
          printf("Found 2: %d\n", *ptr);
        }
    }
    {
      int *ptr = gl_find( g, is_equal_to_five );
      if ( ptr )
        {
          printf("Found 5, but shouldn't! %d\n", *ptr);
        }
      else
        {
          printf("NULL returned - not '5' in list - OK\n");
        }
    }
  }
  {
    struct genlist *g;
    g = gl_empty();
    gl_push_front(&g, "foo");
    gl_push_front(&g, "bar");
    gl_push_front(&g, "baz");
    gl_push_front(&g, "xyz");
    gl_push_front(&g, "var");
    FLOW_CONTROL iteratee(void * ptr)
    {
      char *str = ptr;
      printf("%s\n", str);
      return CONTINUE;
    }
    gl_iterate_list(g, iteratee);
  }
}

variable_types:
arr
int []

variable_types:
num
int *

variable_types:
ptr
int *

variable_types:
str
char *


original_code:
genlist * gl_filter(genlist * gl, FLOW_CONTROL (*filterfun)(void*))
{
  genlist * gl_ptr;
  genlist * retlist = gl_empty();
  for(gl_ptr = gl; gl_ptr; gl_ptr = gl_ptr->next)
    {
      FLOW_CONTROL fc = (*filterfun)(gl_ptr->payload);
      if (fc == SKIP)
        continue;
      if (fc == STOP)
        break;
      gl_push_front(&retlist,gl_ptr->payload);
    }
  gl_reverse( retlist );
  return retlist;
}

canonical_original_code:
struct genlist *gl_filter(struct genlist *gl, enum FLOW_CONTROL (*filterfun)(void *))
{
  struct genlist *gl_ptr;
  struct genlist *retlist = gl_empty();
  for(gl_ptr = gl; gl_ptr; gl_ptr = gl_ptr->next)
    {
      enum FLOW_CONTROL fc = (*filterfun)(gl_ptr->payload);
      if (fc == SKIP)
        continue;
      if (fc == STOP)
        break;
      gl_push_front(&retlist,gl_ptr->payload);
    }
  gl_reverse( retlist );
  return retlist;
}

variable_types:
gl
struct genlist *

variable_types: enum FLOW_CONTROL { STOP=0, CONTINUE=1, SKIP=2 }


decompiled_code:
void gl_reverse()
{
;
}

canonical_decompiled_code:
void func10()
{
;
}

original_code:
void * gl_reverse(genlist * gl)
{
  void swap(genlist * gl1, genlist * gl2)
  {
    genlist * saveptr = gl2->next;
    gl2->next = gl1;
    gl1->next = saveptr;
  }
}

canonical_original_code:
void *gl_reverse(struct genlist *gl)
{
  void swap(genlist * gl1, genlist * gl2)
  {
    struct genlist *saveptr = gl2->next;
    gl2->next = gl1;
    gl1->next = saveptr;
  }
}


nsprintf

decompiled_code:
__int64 nsprintf(void *ptr, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-40D8h] BYREF
char s[16384]; // [rsp+20h] [rbp-40C0h] BYREF

va_start(arg, a2);
vsprintf(s, a2, arg);
if ( ptr && ptr != &str_empty )
free(ptr);
return str_dup(s);
}

canonical_decompiled_code:
__int64 func0(void *ptr, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-40D8h] BYREF
char s[16384]; // [rsp+20h] [rbp-40C0h] BYREF

va_start(arg, a2);
vsprintf(s, a2, arg);
if ( ptr && ptr != &str_empty )
free(ptr);
return str_dup(s);
}

original_code:
char *nsprintf( char *fr, char *fmt, ... )
{
    char buf[ 2 * 8192 ];
    va_list args;
    __builtin_va_start(args,fmt);
    vsprintf( buf, fmt, args );
    __builtin_va_end(args);
    if ( (fr) != &str_empty[0] ) do { if((fr)) { free((fr)); (fr) = ((void *)0); } } while(0);
    return str_dup( buf );
}

canonical_original_code:
char *nsprintf(char *fr, char *fmt, ...)
{
    char buf[-1];
    __builtin_va_list args;
    __builtin_va_start(args,fmt);
    vsprintf( buf, fmt, args );
    __builtin_va_end(args);
    if ( (fr) != &str_empty[0] ) do { if((fr)) { free((fr)); (fr) = ((void *)0); } } while(0);
    return str_dup( buf );
}

variable_types:
fr
char *

variable_types:
fmt
char *

variable_types:
buf
char [-1]


decompiled_code:
__int64 __fastcall is_stat(void *a1)
{
unsigned __int64 v1; // rax
void *v2; // rdx

v1 = (unsigned int)((_DWORD)&flag_stat_table + 8);
v2 = &area_flags;
do
{
if ( a1 == v2 && *(_BYTE *)v1 )
return 1LL;
v1 += 16LL;
v2 = *(void **)(v1 - 8);
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
unsigned __int64 v1; // rax
void *v2; // rdx

v1 = (unsigned int)((_DWORD)&flag_stat_table + 8);
v2 = &area_flags;
do
{
if ( a1 == v2 && *(_BYTE *)v1 )
return 1LL;
v1 += 16LL;
v2 = *(void **)(v1 - 8);
}
while ( v2 );
return 0LL;
}

original_code:
bool is_stat( const struct flag_type *flag_table )
{
    int flag;
    for (flag = 0; flag_stat_table[flag].structure; flag++)
    {
 if ( flag_stat_table[flag].structure == flag_table
   && flag_stat_table[flag].stat )
     return 1;
    }
    return 0;
}

canonical_original_code:
unsigned char is_stat(struct flag_type *flag_table)
{
    int flag;
    for (flag = 0; flag_stat_table[flag].structure; flag++)
    {
 if ( flag_stat_table[flag].structure == flag_table
   && flag_stat_table[flag].stat )
     return 1;
    }
    return 0;
}

variable_types: struct flag_type { char *name; int bit; unsigned char settable; } *

variable_types: flag int


decompiled_code:
__int64 __fastcall flag_value(void *a1, __int64 a2)
{
__int64 v2; // rbx
char v3; // r14
unsigned int v4; // er12
int v5; // eax
char v7[544]; // [rsp+0h] [rbp-220h] BYREF

v2 = a2;
v3 = is_stat(a1);
v4 = 0;
if ( v3 )
return (unsigned int)flag_lookup(a2, a1);
while ( 1 )
{
v2 = one_argument(v2, v7);
if ( !v7[0] )
break;
v5 = flag_lookup(v7, a1);
if ( v5 != -99 )
{
v4 |= v5;
v3 = 1;
}
}
if ( !v3 )
v4 = -99;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1, __int64 a2)
{
__int64 v2; // rbx
char v3; // r14
unsigned int v4; // er12
int v5; // eax
char v7[544]; // [rsp+0h] [rbp-220h] BYREF

v2 = a2;
v3 = func0(a1);
v4 = 0;
if ( v3 )
return (unsigned int)flag_lookup(a2, a1);
while ( 1 )
{
v2 = one_argument(v2, v7);
if ( !v7[0] )
break;
v5 = flag_lookup(v7, a1);
if ( v5 != -99 )
{
v4 |= v5;
v3 = 1;
}
}
if ( !v3 )
v4 = -99;
return v4;
}

original_code:
int flag_value( const struct flag_type *flag_table, char *argument)
{
    char word[512];
    int bit;
    int marked = 0;
    bool found = 0;
    if ( is_stat( flag_table ) )
 return flag_lookup(argument, flag_table);
    for (; ;)
    {
        argument = one_argument( argument, word );
        if ( word[0] == '\0' )
     break;
        if ( ( bit = flag_lookup( word, flag_table ) ) != -99 )
        {
            ((marked) |= (bit));
            found = 1;
        }
    }
    if ( found )
 return marked;
    else
 return -99;
}

canonical_original_code:
int flag_value(struct flag_type *flag_table, char *argument)
{
    char word[512];
    int bit;
    int marked = 0;
    unsigned char found = 0;
    if ( is_stat( flag_table ) )
 return flag_lookup(argument, flag_table);
    for (; ;)
    {
        argument = one_argument( argument, word );
        if ( word[0] == '\0' )
     break;
        if ( ( bit = flag_lookup( word, flag_table ) ) != -99 )
        {
            ((marked) |= (bit));
            found = 1;
        }
    }
    if ( found )
 return marked;
    else
 return -99;
}

variable_types:
argument
char *

variable_types:
word
char [512]

variable_types: bit int

variable_types: marked int

variable_types:
found
unsigned char

user_defined_types: struct flag_type { char *name; int bit; unsigned char settable; }


decompiled_code:
const char *__fastcall flag_string(_QWORD *a1, int a2)
{
_QWORD *v2; // rbx
int v3; // er13
char v4; // r14
char *v5; // r15
const char *result; // rax

v2 = a1;
v3 = cnt_7 + 1;
if ( cnt_7 + 1 > 1 )
v3 = 0;
cnt_7 = v3;
buf_6[512 * (__int64)v3] = 0;
if ( !*a1 )
return "none";
v4 = is_stat(a1);
v5 = &buf_6[512 * (__int64)v3];
while ( 1 )
{
if ( !v4 && ((_DWORD)v2[1] & a2) > 0 )
{
*(_WORD *)&v5[strlen(v5)] = 32;
strcat(v5, (const char *)*v2);
goto LABEL_6;
}
if ( *((_DWORD *)v2 + 2) == a2 )
break;
LABEL_6:
v2 += 2;
if ( !*v2 )
goto LABEL_11;
}
*(_WORD *)&v5[strlen(v5)] = 32;
strcat(v5, (const char *)*v2);
LABEL_11:
result = "none";
if ( buf_6[512 * (__int64)v3] )
result = v5 + 1;
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(_QWORD *a1, int a2)
{
_QWORD *v2; // rbx
int v3; // er13
char v4; // r14
char *v5; // r15
const char *result; // rax

v2 = a1;
v3 = cnt_7 + 1;
if ( cnt_7 + 1 > 1 )
v3 = 0;
cnt_7 = v3;
buf_6[512 * (__int64)v3] = 0;
if ( !*a1 )
return "none";
v4 = func0(a1);
v5 = &buf_6[512 * (__int64)v3];
while ( 1 )
{
if ( !v4 && ((_DWORD)v2[1] & a2) > 0 )
{
*(_WORD *)&v5[strlen(v5)] = 32;
strcat(v5, (const char *)*v2);
goto LABEL_6;
}
if ( *((_DWORD *)v2 + 2) == a2 )
break;
LABEL_6:
v2 += 2;
if ( !*v2 )
goto LABEL_11;
}
*(_WORD *)&v5[strlen(v5)] = 32;
strcat(v5, (const char *)*v2);
LABEL_11:
result = "none";
if ( buf_6[512 * (__int64)v3] )
result = v5 + 1;
return result;
}

original_code:
char *flag_string( const struct flag_type *flag_table, int bits )
{
 static char buf[ 2 ][ 512 ];
 static int cnt = 0;
 int flag;
 if ( ++cnt > 1 )
  cnt = 0;
 buf[ cnt ][ 0 ] = '\0';
 for ( flag = 0; flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( !is_stat( flag_table ) && (((bits) & (flag_table[ flag ].bit)) > 0) )
  {
   strcat( buf[ cnt ], " " );
   strcat( buf[ cnt ], flag_table[ flag ].name );
  }
  else
   if ( flag_table[ flag ].bit == bits )
   {
    strcat( buf[ cnt ], " " );
    strcat( buf[ cnt ], flag_table[ flag ].name );
    break;
   }
 }
 return ( buf[ cnt ][ 0 ] != '\0' ) ? buf[ cnt ] + 1 : "none";
}

canonical_original_code:
char *flag_string(struct flag_type *flag_table, int bits)
{
 static char buf[2][512];
 static int cnt = 0;
 int flag;
 if ( ++cnt > 1 )
  cnt = 0;
 buf[ cnt ][ 0 ] = '\0';
 for ( flag = 0; flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( !is_stat( flag_table ) && (((bits) & (flag_table[ flag ].bit)) > 0) )
  {
   strcat( buf[ cnt ], " " );
   strcat( buf[ cnt ], flag_table[ flag ].name );
  }
  else
   if ( flag_table[ flag ].bit == bits )
   {
    strcat( buf[ cnt ], " " );
    strcat( buf[ cnt ], flag_table[ flag ].name );
    break;
   }
 }
 return ( buf[ cnt ][ 0 ] != '\0' ) ? buf[ cnt ] + 1 : "none";
}

variable_types: bits int

variable_types: cnt int


decompiled_code:
void __fastcall ext_flags_copy(__int64 a1, __int64 a2)
{
__int64 i; // rax

if ( a1 && a2 )
{
for ( i = 0LL; i != 40; i += 8LL )
*(_QWORD *)(a2 + i) = *(_QWORD *)(a1 + i);
}
}

original_code:
void ext_flags_copy( long * flags_from, long * flags_to )
{
 int i;
 if ( !flags_from || !flags_to )
  return;
 for( i = 0; i < 5; i++ )
  *(flags_to + i) = *(flags_from + i);
}

canonical_original_code:
void ext_flags_copy(long *flags_from, long *flags_to)
{
 int i;
 if ( !flags_from || !flags_to )
  return;
 for( i = 0; i < 5; i++ )
  *(flags_to + i) = *(flags_from + i);
}

variable_types: i int


decompiled_code:
__int64 __fastcall ext_flags_same(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = 0LL;
while ( *(_QWORD *)(a1 + v2) == *(_QWORD *)(a2 + v2) )
{
v2 += 8LL;
if ( v2 == 40 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = 0LL;
while ( *(_QWORD *)(a1 + v2) == *(_QWORD *)(a2 + v2) )
{
v2 += 8LL;
if ( v2 == 40 )
return 1LL;
}
return 0LL;
}

original_code:
bool ext_flags_same( long * flags1, long * flags2 )
{
 int i;
 bool same = 1;
 if ( !flags1 || !flags2 )
  return 0;
 for( i = 0; i < 5; i++ )
 {
  if ( *(flags1 + i) != *(flags2 + i) )
  {
   same = 0;
   break;
  }
 }
 return same;
}

canonical_original_code:
unsigned char ext_flags_same(long *flags1, long *flags2)
{
 int i;
 unsigned char same = 1;
 if ( !flags1 || !flags2 )
  return 0;
 for( i = 0; i < 5; i++ )
 {
  if ( *(flags1 + i) != *(flags2 + i) )
  {
   same = 0;
   break;
  }
 }
 return same;
}

variable_types:
same
unsigned char


decompiled_code:
__int64 __fastcall ext_flags_none(_QWORD *a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rdi

if ( !a1 )
return 1LL;
v1 = a1;
v2 = a1 + 5;
while ( !*v1 )
{
if ( ++v1 == v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rdi

if ( !a1 )
return 1LL;
v1 = a1;
v2 = a1 + 5;
while ( !*v1 )
{
if ( ++v1 == v2 )
return 1LL;
}
return 0LL;
}

original_code:
bool ext_flags_none( long * flags )
{
 int i;
 bool none = 1;
 if ( !flags )
  return 1;
 for( i = 0; i < 5; i++ )
 {
  if ( *(flags + i) != 0 )
  {
   none = 0;
   break;
  }
 }
 return none;
}

canonical_original_code:
unsigned char ext_flags_none(long *flags)
{
 int i;
 unsigned char none = 1;
 if ( !flags )
  return 1;
 for( i = 0; i < 5; i++ )
 {
  if ( *(flags + i) != 0 )
  {
   none = 0;
   break;
  }
 }
 return none;
}

variable_types:
flags
long *


decompiled_code:
const char *__fastcall ext_flag_string(const char **a1, __int64 a2)
{
const char **v2; // rbx
int v3; // er13
__int64 v4; // rax
char *v5; // r12
const char *result; // rax

v2 = a1;
v3 = cnt_1 + 1;
if ( cnt_1 + 1 > 1 )
v3 = 0;
cnt_1 = v3;
v4 = (__int64)v3 << 9;
buf_0[v4] = 0;
if ( !*a1 )
return "none";
v5 = &buf_0[v4];
do
{
if ( (__int64)(*(_QWORD *)(a2 + 8LL * *(int *)v2[1]) & *((int *)v2[1] + 1)) > 0 )
{
*(_WORD *)&v5[strlen(v5)] = 32;
strcat(v5, *v2);
}
v2 += 3;
}
while ( *v2 );
result = "none";
if ( buf_0[512 * (__int64)v3] )
result = v5 + 1;
return result;
}

original_code:
char * ext_flag_string( const struct ext_flag_type *ext_flag_table, long * ext_bits )
{
 static char buf[ 2 ][ 512 ];
 static int cnt = 0;
 int flag;
 if ( ++cnt > 1 )
  cnt = 0;
 buf[ cnt ][ 0 ] = '\0';
 for ( flag = 0; ext_flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( (((*( ext_bits + ((*ext_flag_table[ flag ].bitvect)).bank )) & (((*ext_flag_table[ flag ].bitvect)).vector)) > 0) ) )
  {
   strcat( buf[ cnt ], " " );
   strcat( buf[ cnt ], ext_flag_table[ flag ].name );
  }
 }
 return ( buf[ cnt ][ 0 ] != '\0' ) ? buf[ cnt ] + 1 : "none";
}

canonical_original_code:
char *ext_flag_string(struct ext_flag_type *ext_flag_table, long *ext_bits)
{
 static char buf[2][512];
 static int cnt = 0;
 int flag;
 if ( ++cnt > 1 )
  cnt = 0;
 buf[ cnt ][ 0 ] = '\0';
 for ( flag = 0; ext_flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ( (((*( ext_bits + ((*ext_flag_table[ flag ].bitvect)).bank )) & (((*ext_flag_table[ flag ].bitvect)).vector)) > 0) ) )
  {
   strcat( buf[ cnt ], " " );
   strcat( buf[ cnt ], ext_flag_table[ flag ].name );
  }
 }
 return ( buf[ cnt ][ 0 ] != '\0' ) ? buf[ cnt ] + 1 : "none";
}

variable_types: struct ext_flag_type { char *name; struct bitvect_data { int bank; int vector; } *bitvect; unsigned char settable; } *

user_defined_types: struct ext_flag_type { char *name; struct bitvect_data *bitvect; unsigned char settable; }


decompiled_code:
__int64 __fastcall ext_bit_name(__int64 *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rdi

result = *a1;
if ( *a1 )
{
v3 = a1 + 3;
do
{
if ( *(v3 - 2) == a2 )
break;
v3 += 3;
result = *(v3 - 3);
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, __int64 a2)
{
__int64 result; // rax
_QWORD *v3; // rdi

result = *a1;
if ( *a1 )
{
v3 = a1 + 3;
do
{
if ( *(v3 - 2) == a2 )
break;
v3 += 3;
result = *(v3 - 3);
}
while ( result );
}
return result;
}

original_code:
char * ext_bit_name( const struct ext_flag_type *ext_flag_table, BITVECT_DATA * ext_bit )
{
 int flag;
 for ( flag = 0; ext_flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ext_bit == ext_flag_table[ flag ].bitvect )
  {
   return ext_flag_table[ flag ].name;
  }
 }
 return ((void *)0);
}

canonical_original_code:
char *ext_bit_name(struct ext_flag_type *ext_flag_table, struct bitvect_data *ext_bit)
{
 int flag;
 for ( flag = 0; ext_flag_table[ flag ].name != ((void *)0); flag++ )
 {
  if ( ext_bit == ext_flag_table[ flag ].bitvect )
  {
   return ext_flag_table[ flag ].name;
  }
 }
 return ((void *)0);
}

user_defined_types: struct bitvect_data { int bank; int vector; }


decompiled_code:
__int64 __fastcall set_bigflag(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 > 319 )
{
save_debug_info("bit.c => set_bigflag", 0LL, &unk_1F48, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) |= 1 << a2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 > 319 )
{
save_debug_info("bit.c => set_bigflag", 0LL, &unk_1F48, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) |= 1 << a2;
result = 1LL;
}
return result;
}

original_code:
bool set_bigflag( BIGFLAG *flaga, int nrbitu )
{
 int bank;
 int bit;
 const char *call = "bit.c => set_bigflag";
 if ( nrbitu >= MAX_BIGFLAG )
 {
  save_debug_info( call, ((void *)0), "pr�ba operowania na fladze przekraczaj�cej pojemno�� BIGFLAG", 1, 0, 1 );
  return 0;
 }
 bank = nrbitu / ( sizeof( flaga->bank[0] ) * 8 );
 bit = nrbitu % ( sizeof( flaga->bank[0] ) * 8 );
 flaga->bank[ bank ] |= 1<<bit;
 return 1;
}

canonical_original_code:
unsigned char set_bigflag(struct bigflag *flaga, int nrbitu)
{
 int bank;
 int bit;
 char *call = "bit.c => set_bigflag";
 if ( nrbitu >= MAX_BIGFLAG )
 {
  save_debug_info( call, ((void *)0), "pr�ba operowania na fladze przekraczaj�cej pojemno�� BIGFLAG", 1, 0, 1 );
  return 0;
 }
 bank = nrbitu / ( sizeof( flaga->bank[0] ) * 8 );
 bit = nrbitu % ( sizeof( flaga->bank[0] ) * 8 );
 flaga->bank[ bank ] |= 1<<bit;
 return 1;
}

variable_types: struct bigflag { unsigned int bank[10]; } *

variable_types: nrbitu int

variable_types: bank int

variable_types:
call
char *


decompiled_code:
__int64 __fastcall rmv_bigflag(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 > 319 )
{
save_debug_info("bit.c => rmv_bigflag", 0LL, &unk_1F48, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) &= ~(1 << a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 > 319 )
{
save_debug_info("bit.c => rmv_bigflag", 0LL, &unk_1F48, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) &= ~(1 << a2);
result = 1LL;
}
return result;
}

original_code:
bool rmv_bigflag( BIGFLAG *flaga, int nrbitu )
{
 int bank;
 int bit;
 const char *call = "bit.c => rmv_bigflag";
 if ( nrbitu >= MAX_BIGFLAG )
 {
  save_debug_info( call, ((void *)0), "pr�ba operowania na fladze przekraczaj�cej pojemno�� BIGFLAG", 1, 0, 1 );
  return 0;
 }
 bank = nrbitu / ( sizeof( flaga->bank[0] ) * 8 );
 bit = nrbitu % ( sizeof( flaga->bank[0] ) * 8 );
 flaga->bank[ bank ] &= ~( 1<<bit );
 return 1;
}

canonical_original_code:
unsigned char rmv_bigflag(struct bigflag *flaga, int nrbitu)
{
 int bank;
 int bit;
 char *call = "bit.c => rmv_bigflag";
 if ( nrbitu >= MAX_BIGFLAG )
 {
  save_debug_info( call, ((void *)0), "pr�ba operowania na fladze przekraczaj�cej pojemno�� BIGFLAG", 1, 0, 1 );
  return 0;
 }
 bank = nrbitu / ( sizeof( flaga->bank[0] ) * 8 );
 bit = nrbitu % ( sizeof( flaga->bank[0] ) * 8 );
 flaga->bank[ bank ] &= ~( 1<<bit );
 return 1;
}

user_defined_types: struct bigflag { unsigned int bank[10]; }


decompiled_code:
__int64 __fastcall tgl_bigflag(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 > 319 )
{
save_debug_info("bit.c => tgl_bigflag", 0LL, &unk_1F48, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) ^= 1 << a2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, int a2)
{
__int64 result; // rax

if ( a2 > 319 )
{
save_debug_info("bit.c => tgl_bigflag", 0LL, &unk_1F48, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) ^= 1 << a2;
result = 1LL;
}
return result;
}

original_code:
bool tgl_bigflag( BIGFLAG *flaga, int nrbitu )
{
 int bank;
 int bit;
 const char *call = "bit.c => tgl_bigflag";
 if ( nrbitu >= MAX_BIGFLAG )
 {
  save_debug_info( call, ((void *)0), "pr�ba operowania na fladze przekraczaj�cej pojemno�� BIGFLAG", 1, 0, 1 );
  return 0;
 }
 bank = nrbitu / ( sizeof( flaga->bank[0] ) * 8 );
 bit = nrbitu % ( sizeof( flaga->bank[0] ) * 8 );
 flaga->bank[ bank ] ^= (1<<bit);
 return 1;
}

canonical_original_code:
unsigned char tgl_bigflag(struct bigflag *flaga, int nrbitu)
{
 int bank;
 int bit;
 char *call = "bit.c => tgl_bigflag";
 if ( nrbitu >= MAX_BIGFLAG )
 {
  save_debug_info( call, ((void *)0), "pr�ba operowania na fladze przekraczaj�cej pojemno�� BIGFLAG", 1, 0, 1 );
  return 0;
 }
 bank = nrbitu / ( sizeof( flaga->bank[0] ) * 8 );
 bit = nrbitu % ( sizeof( flaga->bank[0] ) * 8 );
 flaga->bank[ bank ] ^= (1<<bit);
 return 1;
}


decompiled_code:
bool __fastcall chk_bigflag(__int64 a1, int a2)
{
bool result; // al

DEBUG_INFO("bit.c:chk_bigflag:start");
if ( a2 > 319 )
{
DEBUG_INFO("bit.c:chk_bigflag:MAX_BIGFLAG");
save_debug_info("bit.c => chk_bigflag", 0LL, &unk_1F48, 1LL, 0LL, 1LL);
result = 0;
}
else
{
DEBUG_INFO("bit.c:chk_bigflag:2");
if ( a1 )
{
DEBUG_INFO("bit.c:chk_bigflag:3");
DEBUG_INFO("bit.c:chk_bigflag:4");
DEBUG_INFO("bit.c:chk_bigflag:bit_shift_and_and");
result = (*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) & (1 << a2)) != 0;
}
else
{
DEBUG_INFO("bit.c:chk_bigflag:flag");
log_buf = 0x69625B203A475542LL;
*((_QWORD *)&log_buf + 1) = 0x5F6B68633A632E74LL;
*((_QWORD *)&log_buf + 2) = 0x5D67616C66676962LL;
*((_QWORD *)&log_buf + 3) = 0x6C206167616C6620LL;
*((_QWORD *)&log_buf + 4) = 0x6167616C66206275LL;
*((_QWORD *)&log_buf + 5) = 0x6E206B6E61623E2DLL;
*((_QWORD *)&log_buf + 6) = 0x20BDBFEF73206569LL;
*((_QWORD *)&log_buf + 7) = 0x6F696E696665647ALL;
strcpy((char *)&log_buf + 64, "wane!");
log_string(&log_buf);
result = 0;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func12(__int64 a1, int a2)
{
bool result; // al

DEBUG_INFO("bit.c:chk_bigflag:start");
if ( a2 > 319 )
{
DEBUG_INFO("bit.c:chk_bigflag:MAX_BIGFLAG");
save_debug_info("bit.c => chk_bigflag", 0LL, &unk_1F48, 1LL, 0LL, 1LL);
result = 0;
}
else
{
DEBUG_INFO("bit.c:chk_bigflag:2");
if ( a1 )
{
DEBUG_INFO("bit.c:chk_bigflag:3");
DEBUG_INFO("bit.c:chk_bigflag:4");
DEBUG_INFO("bit.c:chk_bigflag:bit_shift_and_and");
result = (*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) & (1 << a2)) != 0;
}
else
{
DEBUG_INFO("bit.c:chk_bigflag:flag");
log_buf = 0x69625B203A475542LL;
*((_QWORD *)&log_buf + 1) = 0x5F6B68633A632E74LL;
*((_QWORD *)&log_buf + 2) = 0x5D67616C66676962LL;
*((_QWORD *)&log_buf + 3) = 0x6C206167616C6620LL;
*((_QWORD *)&log_buf + 4) = 0x6167616C66206275LL;
*((_QWORD *)&log_buf + 5) = 0x6E206B6E61623E2DLL;
*((_QWORD *)&log_buf + 6) = 0x20BDBFEF73206569LL;
*((_QWORD *)&log_buf + 7) = 0x6F696E696665647ALL;
strcpy((char *)&log_buf + 64, "wane!");
log_string(&log_buf);
result = 0;
}
}
return result;
}

original_code:
bool chk_bigflag( BIGFLAG *flaga, int nrbitu )
{
 int bank;
 int bit;
 DEBUG_INFO ( "bit.c:chk_bigflag:start" );
 const char *call = "bit.c => chk_bigflag";
 if ( nrbitu >= MAX_BIGFLAG )
 {
 DEBUG_INFO ( "bit.c:chk_bigflag:MAX_BIGFLAG" );
        save_debug_info( call, ((void *)0), "pr�ba operowania na fladze przekraczaj�cej pojemno�� BIGFLAG", 1, 0, 1 );
        return 0;
 }
 DEBUG_INFO ( "bit.c:chk_bigflag:2" );
 if ( !flaga || !flaga->bank ) {
 DEBUG_INFO ( "bit.c:chk_bigflag:flag" );
     sprintf( log_buf, "BUG: [bit.c:chk_bigflag] flaga lub flaga->bank nie s� zdefiniowane!" );
  log_string( log_buf );
  return 0;
 }
 DEBUG_INFO ( "bit.c:chk_bigflag:3" );
 bank = nrbitu / ( sizeof( flaga->bank[0] ) * 8 );
 DEBUG_INFO ( "bit.c:chk_bigflag:4" );
 bit = nrbitu % ( sizeof( flaga->bank[0] ) * 8 );
 DEBUG_INFO ( "bit.c:chk_bigflag:bit_shift_and_and" );
 return ( ( ( flaga->bank[ bank ] & ( 1<<bit ) ) != 0 )? 1: 0 );
}

canonical_original_code:
unsigned char chk_bigflag(struct bigflag *flaga, int nrbitu)
{
 int bank;
 int bit;
 DEBUG_INFO ( "bit.c:chk_bigflag:start" );
 char *call = "bit.c => chk_bigflag";
 if ( nrbitu >= MAX_BIGFLAG )
 {
 DEBUG_INFO ( "bit.c:chk_bigflag:MAX_BIGFLAG" );
        save_debug_info( call, ((void *)0), "pr�ba operowania na fladze przekraczaj�cej pojemno�� BIGFLAG", 1, 0, 1 );
        return 0;
 }
 DEBUG_INFO ( "bit.c:chk_bigflag:2" );
 if ( !flaga || !flaga->bank ) {
 DEBUG_INFO ( "bit.c:chk_bigflag:flag" );
     sprintf( log_buf, "BUG: [bit.c:chk_bigflag] flaga lub flaga->bank nie s� zdefiniowane!" );
  log_string( log_buf );
  return 0;
 }
 DEBUG_INFO ( "bit.c:chk_bigflag:3" );
 bank = nrbitu / ( sizeof( flaga->bank[0] ) * 8 );
 DEBUG_INFO ( "bit.c:chk_bigflag:4" );
 bit = nrbitu % ( sizeof( flaga->bank[0] ) * 8 );
 DEBUG_INFO ( "bit.c:chk_bigflag:bit_shift_and_and" );
 return ( ( ( flaga->bank[ bank ] & ( 1<<bit ) ) != 0 )? 1: 0 );
}


decompiled_code:
__int64 __fastcall check_ban(__int64 a1, int a2)
{
const char *v2; // rax
__int64 v3; // rbx
__int16 v5; // ax
char dest[8208]; // [rsp+0h] [rbp-2010h] BYREF

v2 = (const char *)capitalize_first();
strcpy(dest, v2);
dest[0] = *((_BYTE *)&lower_pol + (unsigned __int8)dest[0]);
v3 = ban_list;
if ( !ban_list )
return 0LL;
while ( 1 )
{
v5 = *(_WORD *)(v3 + 10);
if ( (a2 & v5) > 0 )
break;
LABEL_5:
v3 = *(_QWORD *)v3;
if ( !v3 )
return 0LL;
}
if ( (v5 & 2) == 0 )
goto LABEL_17;
if ( (v5 & 1) != 0 && strstr(*(const char **)(v3 + 16), dest) )
return 1LL;
if ( (unsigned __int8)str_suffix(*(_QWORD *)(v3 + 16), dest) )
{
LABEL_17:
if ( (*(_BYTE *)(v3 + 10) & 1) != 0 && !(unsigned __int8)str_prefix(*(_QWORD *)(v3 + 16), dest) )
return 1LL;
goto LABEL_5;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
const char *v2; // rax
__int64 v3; // rbx
__int16 v5; // ax
char dest[8208]; // [rsp+0h] [rbp-2010h] BYREF

v2 = (const char *)capitalize_first();
strcpy(dest, v2);
dest[0] = *((_BYTE *)&lower_pol + (unsigned __int8)dest[0]);
v3 = ban_list;
if ( !ban_list )
return 0LL;
while ( 1 )
{
v5 = *(_WORD *)(v3 + 10);
if ( (a2 & v5) > 0 )
break;
LABEL_5:
v3 = *(_QWORD *)v3;
if ( !v3 )
return 0LL;
}
if ( (v5 & 2) == 0 )
goto LABEL_17;
if ( (v5 & 1) != 0 && strstr(*(const char **)(v3 + 16), dest) )
return 1LL;
if ( (unsigned __int8)str_suffix(*(_QWORD *)(v3 + 16), dest) )
{
LABEL_17:
if ( (*(_BYTE *)(v3 + 10) & 1) != 0 && !(unsigned __int8)str_prefix(*(_QWORD *)(v3 + 16), dest) )
return 1LL;
goto LABEL_5;
}
return 1LL;
}

original_code:
bool check_ban( char *site, int type )
{
    BAN_DATA * pban;
    char host[ 8192 ];
    strcpy( host, capitalize_first( site ) );
    host[ 0 ] = ( lower_pol[(unsigned char)(host[ 0 ])]);
    for ( pban = ban_list; pban != ((void *)0); pban = pban->next )
    {
        if ( !(((pban->ban_flags) & (type)) > 0) )
            continue;
        if ( (((pban->ban_flags) & (2)) > 0)
             && (((pban->ban_flags) & (1)) > 0)
             && strstr( pban->site, host ) != ((void *)0) )
            return 1;
        if ( (((pban->ban_flags) & (2)) > 0)
             && !str_suffix( pban->site, host ) )
            return 1;
        if ( (((pban->ban_flags) & (1)) > 0)
             && !str_prefix( pban->site, host ) )
            return 1;
    }
    return 0;
}

canonical_original_code:
unsigned char check_ban(char *site, int type)
{
    struct ban_data *pban;
    char host[8192];
    strcpy( host, capitalize_first( site ) );
    host[ 0 ] = ( lower_pol[(unsigned char)(host[ 0 ])]);
    for ( pban = ban_list; pban != ((void *)0); pban = pban->next )
    {
        if ( !(((pban->ban_flags) & (type)) > 0) )
            continue;
        if ( (((pban->ban_flags) & (2)) > 0)
             && (((pban->ban_flags) & (1)) > 0)
             && strstr( pban->site, host ) != ((void *)0) )
            return 1;
        if ( (((pban->ban_flags) & (2)) > 0)
             && !str_suffix( pban->site, host ) )
            return 1;
        if ( (((pban->ban_flags) & (1)) > 0)
             && !str_prefix( pban->site, host ) )
            return 1;
    }
    return 0;
}

variable_types:
site
char *

variable_types: type int

variable_types: struct ban_data { struct ban_data *next; unsigned char valid; short ban_flags; short level; char *site; char *reason; char *person; long date_stamp; int period; } *

variable_types:
host
char [8192]


decompiled_code:
void update_bans()
{
__int64 v0; // rdi
_QWORD *v1; // rdx
int v2; // eax

if ( ban_list )
{
v0 = ban_list;
v1 = 0LL;
while ( 1 )
{
v2 = *(_DWORD *)(v0 + 48);
if ( v2 > 0 && *(_QWORD *)(v0 + 40) + 86400 * v2 <= current_time )
break;
v1 = (_QWORD *)v0;
if ( !*(_QWORD *)v0 )
return;
v0 = *(_QWORD *)v0;
}
if ( v1 )
*v1 = *(_QWORD *)v0;
else
ban_list = *(_QWORD *)ban_list;
free_ban(v0);
save_bans();
}
}

canonical_decompiled_code:
void func6()
{
__int64 v0; // rdi
_QWORD *v1; // rdx
int v2; // eax

if ( ban_list )
{
v0 = ban_list;
v1 = 0LL;
while ( 1 )
{
v2 = *(_DWORD *)(v0 + 48);
if ( v2 > 0 && *(_QWORD *)(v0 + 40) + 86400 * v2 <= current_time )
break;
v1 = (_QWORD *)v0;
if ( !*(_QWORD *)v0 )
return;
v0 = *(_QWORD *)v0;
}
if ( v1 )
*v1 = *(_QWORD *)v0;
else
ban_list = *(_QWORD *)ban_list;
free_ban(v0);
func0();
}
}

original_code:
void update_bans()
{
    BAN_DATA *prev;
    BAN_DATA *curr;
    prev = ((void *)0);
    for ( curr = ban_list; curr != ((void *)0); prev = curr, curr = curr->next )
    {
        if ( curr->period > 0 && curr->date_stamp + ( curr->period * 24 * 3600 ) <= current_time )
        {
            if ( prev == ((void *)0) )
                ban_list = ban_list->next;
            else
                prev->next = curr->next;
            free_ban( curr );
            save_bans();
            return ;
        }
    }
    return ;
}

canonical_original_code:
void update_bans()
{
    struct ban_data *prev;
    struct ban_data *curr;
    prev = ((void *)0);
    for ( curr = ban_list; curr != ((void *)0); prev = curr, curr = curr->next )
    {
        if ( curr->period > 0 && curr->date_stamp + ( curr->period * 24 * 3600 ) <= current_time )
        {
            if ( prev == ((void *)0) )
                ban_list = ban_list->next;
            else
                prev->next = curr->next;
            free_ban( curr );
            save_bans();
            return ;
        }
    }
    return ;
}

user_defined_types: struct ban_data { struct ban_data *next; unsigned char valid; short ban_flags; short level; char *site; char *reason; char *person; long date_stamp; int period; }


decompiled_code:
__int64 __fastcall hash_number(char *a1)
{
char v1; // al
char *v2; // rdi
int v3; // edx

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1;
v1 = *v2++;
}
while ( v1 );
}
else
{
v3 = 0;
}
return (unsigned int)(v3 % 32);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
char *v2; // rdi
int v3; // edx

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
v3 = 0;
do
{
v3 += v1;
v1 = *v2++;
}
while ( v1 );
}
else
{
v3 = 0;
}
return (unsigned int)(v3 % 32);
}

original_code:
int hash_number( char *ptr )
{
    int hash_value = 0, letter;
    for ( letter = 0; ptr[ letter ] != '\0'; letter++ )
        hash_value += ptr[ letter ];
    return ( hash_value % 32 );
}

canonical_original_code:
int hash_number(char *ptr)
{
    int hash_value = 0; int letter;
    for ( letter = 0; ptr[ letter ] != '\0'; letter++ )
        hash_value += ptr[ letter ];
    return ( hash_value % 32 );
}

variable_types:
ptr
char *

variable_types: letter int


decompiled_code:
__int64 __fastcall is_allowed(char *a1)
{
__int64 result; // rax
unsigned __int8 *v2; // rbx

if ( !a1 )
return 0LL;
result = 0LL;
if ( *a1 )
{
v2 = (unsigned __int8 *)name_table[(int)hash_number(a1)];
if ( v2 )
{
do
{
if ( *((_BYTE *)&upper_nopol + (unsigned __int8)*a1) == *((_BYTE *)&upper_nopol + **(unsigned __int8 **)v2)
&& !(unsigned __int8)str_cmp(a1) )
{
return *((unsigned int *)v2 + 4);
}
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 1);
}
while ( v2 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
__int64 result; // rax
unsigned __int8 *v2; // rbx

if ( !a1 )
return 0LL;
result = 0LL;
if ( *a1 )
{
v2 = (unsigned __int8 *)name_table[(int)func0(a1)];
if ( v2 )
{
do
{
if ( *((_BYTE *)&upper_nopol + (unsigned __int8)*a1) == *((_BYTE *)&upper_nopol + **(unsigned __int8 **)v2)
&& !(unsigned __int8)str_cmp(a1) )
{
return *((unsigned int *)v2 + 4);
}
v2 = (unsigned __int8 *)*((_QWORD *)v2 + 1);
}
while ( v2 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int is_allowed( char *name )
{
    NAME_LIST * list;
    if ( ((name) == ((void *)0) || (name)[0] == '\0') )
        return 0;
    list = name_table[ hash_number( name ) ];
    for ( ; list; list = list->next )
        if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(list->name[ 0 ])]) &&
             !str_cmp( name, list->name ) )
            return list->allowed;
    return 0;
}

canonical_original_code:
int is_allowed(char *name)
{
    struct name_list *list;
    if ( ((name) == ((void *)0) || (name)[0] == '\0') )
        return 0;
    list = name_table[ hash_number( name ) ];
    for ( ; list; list = list->next )
        if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(list->name[ 0 ])]) &&
             !str_cmp( name, list->name ) )
            return list->allowed;
    return 0;
}

variable_types:
name
char *

variable_types: struct name_list { char *name; struct name_list *next; int allowed; } *


decompiled_code:
unsigned __int8 *__fastcall get_name_list(char *a1)
{
unsigned __int8 *i; // rbx

for ( i = (unsigned __int8 *)name_table[(int)hash_number(a1)]; i; i = (unsigned __int8 *)*((_QWORD *)i + 1) )
{
if ( *((_BYTE *)&upper_nopol + (unsigned __int8)*a1) == *((_BYTE *)&upper_nopol + **(unsigned __int8 **)i)
&& !(unsigned __int8)str_cmp(a1) )
{
break;
}
}
return i;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func2(char *a1)
{
unsigned __int8 *i; // rbx

for ( i = (unsigned __int8 *)name_table[(int)func0(a1)]; i; i = (unsigned __int8 *)*((_QWORD *)i + 1) )
{
if ( *((_BYTE *)&upper_nopol + (unsigned __int8)*a1) == *((_BYTE *)&upper_nopol + **(unsigned __int8 **)i)
&& !(unsigned __int8)str_cmp(a1) )
{
break;
}
}
return i;
}

original_code:
NAME_LIST * get_name_list( char *name )
{
    NAME_LIST * list;
    list = name_table[ hash_number( name ) ];
    for ( ; list; list = list->next )
        if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(list->name[ 0 ])]) &&
             !str_cmp( name, list->name ) )
            return list;
    return ((void *)0);
}

canonical_original_code:
struct name_list *get_name_list(char *name)
{
    struct name_list *list;
    list = name_table[ hash_number( name ) ];
    for ( ; list; list = list->next )
        if ( ( upper_nopol[(unsigned char)(name[ 0 ])]) == ( upper_nopol[(unsigned char)(list->name[ 0 ])]) &&
             !str_cmp( name, list->name ) )
            return list;
    return ((void *)0);
}

return_type: struct name_list { char *name; struct name_list *next; int allowed; } *


decompiled_code:
void __fastcall add_name(char *s, int a2)
{
int v2; // eax
_DWORD *v3; // r13
char *v4; // rax
int v5; // eax
unsigned __int8 *v6; // rax
unsigned __int8 *v7; // rax
unsigned __int8 *v8; // rax

if ( s && *s && (a2 == -1 || (unsigned int)(a2 - 1) <= 1) )
{
v2 = is_allowed(s);
if ( v2 == 1 )
{
v7 = get_name_list(s);
if ( !v7 )
goto LABEL_8;
if ( a2 != 2 )
*((_DWORD *)v7 + 4) = a2;
}
else
{
if ( v2 != 2 )
{
if ( v2 == -1 )
{
v8 = get_name_list(s);
if ( v8 )
{
if ( a2 != 2 )
*((_DWORD *)v8 + 4) = a2;
return;
}
}
LABEL_8:
v3 = malloc(0x18uLL);
v3[4] = a2;
v4 = strdup(s);
*(_QWORD *)v3 = v4;
*v4 = *((_BYTE *)&lower_pol + (unsigned __int8)*v4);
v5 = hash_number(s);
*((_QWORD *)v3 + 1) = name_table[v5];
name_table[v5] = (__int64)v3;
return;
}
v6 = get_name_list(s);
if ( !v6 )
goto LABEL_8;
if ( a2 != 2 )
*((_DWORD *)v6 + 4) = a2;
}
}
}

canonical_decompiled_code:
void __fastcall func3(char *s, int a2)
{
int v2; // eax
_DWORD *v3; // r13
char *v4; // rax
int v5; // eax
unsigned __int8 *v6; // rax
unsigned __int8 *v7; // rax
unsigned __int8 *v8; // rax

if ( s && *s && (a2 == -1 || (unsigned int)(a2 - 1) <= 1) )
{
v2 = func1(s);
if ( v2 == 1 )
{
v7 = func2(s);
if ( !v7 )
goto LABEL_8;
if ( a2 != 2 )
*((_DWORD *)v7 + 4) = a2;
}
else
{
if ( v2 != 2 )
{
if ( v2 == -1 )
{
v8 = func2(s);
if ( v8 )
{
if ( a2 != 2 )
*((_DWORD *)v8 + 4) = a2;
return;
}
}
LABEL_8:
v3 = malloc(0x18uLL);
v3[4] = a2;
v4 = strdup(s);
*(_QWORD *)v3 = v4;
*v4 = *((_BYTE *)&lower_pol + (unsigned __int8)*v4);
v5 = func0(s);
*((_QWORD *)v3 + 1) = name_table[v5];
name_table[v5] = (__int64)v3;
return;
}
v6 = func2(s);
if ( !v6 )
goto LABEL_8;
if ( a2 != 2 )
*((_DWORD *)v6 + 4) = a2;
}
}
}

original_code:
void add_name( char *name, int type )
{
    NAME_LIST * new_el = ((void *)0), *ptr = ((void *)0);
    int hash;
    if ( !name || name[ 0 ] == '\0' )
        return ;
    switch ( type )
    {
        case 1:
        case -1:
        case 2: break;
        default: return ;
    }
    switch ( is_allowed( name ) )
    {
        case 2:
            if ( ( ptr = get_name_list( name ) ) == ((void *)0) )
                break;
            if ( type == 2 )
                return ;
            ptr->allowed = type;
            return ;
        case 1:
            if ( ( ptr = get_name_list( name ) ) == ((void *)0) )
                break;
            if ( type == 2 )
                return ;
            ptr->allowed = type;
            return ;
        case -1:
            if ( ( ptr = get_name_list( name ) ) == ((void *)0) )
                break;
            if ( type == 2 )
                return ;
            ptr->allowed = type;
            return ;
        case 0: break;
    }
    new_el = ( NAME_LIST * ) malloc( sizeof( NAME_LIST ) );
    new_el->allowed = type;
    new_el->name = strdup( name );
    new_el->name[ 0 ] = ( lower_pol[(unsigned char)(new_el->name[ 0 ])]);
    hash = hash_number( name );
    new_el->next = name_table[ hash ];
    name_table[ hash ] = new_el;
    return ;
}

canonical_original_code:
void add_name(char *name, int type)
{
    struct name_list *new_el = ((void *)0); struct name_list *ptr = ((void *)0);
    int hash;
    if ( !name || name[ 0 ] == '\0' )
        return ;
    switch ( type )
    {
        case 1:
        case -1:
        case 2: break;
        default: return ;
    }
    switch ( is_allowed( name ) )
    {
        case 2:
            if ( ( ptr = get_name_list( name ) ) == ((void *)0) )
                break;
            if ( type == 2 )
                return ;
            ptr->allowed = type;
            return ;
        case 1:
            if ( ( ptr = get_name_list( name ) ) == ((void *)0) )
                break;
            if ( type == 2 )
                return ;
            ptr->allowed = type;
            return ;
        case -1:
            if ( ( ptr = get_name_list( name ) ) == ((void *)0) )
                break;
            if ( type == 2 )
                return ;
            ptr->allowed = type;
            return ;
        case 0: break;
    }
    new_el = ( struct name_list * ) malloc( sizeof( NAME_LIST ) );
    new_el->allowed = type;
    new_el->name = strdup( name );
    new_el->name[ 0 ] = ( lower_pol[(unsigned char)(new_el->name[ 0 ])]);
    hash = hash_number( name );
    new_el->next = name_table[ hash ];
    name_table[ hash ] = new_el;
    return ;
}

variable_types: hash int

user_defined_types: struct name_list { char *name; struct name_list *next; int allowed; }


decompiled_code:
int initialize_name_table()
{
const char *v0; // rax

v0 = (const char *)name_table;
do
{
*(_QWORD *)v0 = 0LL;
v0 += 8;
}
while ( v0 != "../system/allowed_names.txt" );
return load_files();
}

canonical_decompiled_code:
int func7()
{
const char *v0; // rax

v0 = (const char *)name_table;
do
{
*(_QWORD *)v0 = 0LL;
v0 += 8;
}
while ( v0 != "../system/allowed_names.txt" );
return func6();
}

original_code:
void initialize_name_table()
{
    int i;
    for ( i = 0; i < 32; i++ )
        name_table[ i ] = ((void *)0);
    load_files();
    return ;
}

variable_types: i int


decompiled_code:
__int64 spell_items_table_count()
{
return 59LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 59LL;
}

original_code:
int spell_items_table_count()
{
 return ( ( sizeof( spell_items_table ) / sizeof( spell_items_table[0] ) ) - 2 );
}


decompiled_code:
void __fastcall free_monk_hit(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 && v2 != &str_empty )
{
free(v2);
*(_QWORD *)ptr = 0LL;
}
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 && v3 != &str_empty )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 && v4 != &str_empty )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 3);
if ( v5 )
{
if ( v5 != &str_empty )
free(v5);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void *v5; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 && v2 != &str_empty )
{
free(v2);
*(_QWORD *)ptr = 0LL;
}
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 && v3 != &str_empty )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 && v4 != &str_empty )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 3);
if ( v5 )
{
if ( v5 != &str_empty )
free(v5);
}
free(ptr);
}
}

original_code:
void free_monk_hit( MONK_HITS * hit )
{
    if( !hit )
 return;
    if ( (hit->hit_name) != &str_empty[0] ) do { if((hit->hit_name)) { free((hit->hit_name)); (hit->hit_name) = ((void *)0); } } while(0);
    if ( (hit->monk_text) != &str_empty[0] ) do { if((hit->monk_text)) { free((hit->monk_text)); (hit->monk_text) = ((void *)0); } } while(0);
    if ( (hit->victim_text) != &str_empty[0] ) do { if((hit->victim_text)) { free((hit->victim_text)); (hit->victim_text) = ((void *)0); } } while(0);
    if ( (hit->room_text) != &str_empty[0] ) do { if((hit->room_text)) { free((hit->room_text)); (hit->room_text) = ((void *)0); } } while(0);
    free( hit );
    return;
}

canonical_original_code:
void free_monk_hit(struct monk_hits *hit)
{
    if( !hit )
 return;
    if ( (hit->hit_name) != &str_empty[0] ) do { if((hit->hit_name)) { free((hit->hit_name)); (hit->hit_name) = ((void *)0); } } while(0);
    if ( (hit->monk_text) != &str_empty[0] ) do { if((hit->monk_text)) { free((hit->monk_text)); (hit->monk_text) = ((void *)0); } } while(0);
    if ( (hit->victim_text) != &str_empty[0] ) do { if((hit->victim_text)) { free((hit->victim_text)); (hit->victim_text) = ((void *)0); } } while(0);
    if ( (hit->room_text) != &str_empty[0] ) do { if((hit->room_text)) { free((hit->room_text)); (hit->room_text) = ((void *)0); } } while(0);
    free( hit );
    return;
}

variable_types: struct monk_hits { char *hit_name; char *monk_text; char *victim_text; char *room_text; int min_skill_req; int min_wisdom_req; int rating; int damage[2]; int dam_bonus; int hit_bonus; int victim_type; int victim_parts; int special_flag; struct monk_hits *next; } *


decompiled_code:
_QWORD *new_monk_hit()
{
_QWORD *result; // rax

result = malloc(0x50uLL);
*result = &unk_11C8;
result[1] = &unk_11C8;
result[2] = &unk_11C8;
result[3] = &unk_11C8;
*((_DWORD *)result + 8) = 0;
*((_DWORD *)result + 9) = 0;
*((_DWORD *)result + 10) = 0;
*((_DWORD *)result + 11) = 0;
*((_DWORD *)result + 12) = 0;
*((_DWORD *)result + 13) = 0;
*((_DWORD *)result + 14) = 0;
*((_DWORD *)result + 15) = 0;
*((_DWORD *)result + 16) = 0;
*((_DWORD *)result + 17) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x50uLL);
*result = &unk_11C8;
result[1] = &unk_11C8;
result[2] = &unk_11C8;
result[3] = &unk_11C8;
*((_DWORD *)result + 8) = 0;
*((_DWORD *)result + 9) = 0;
*((_DWORD *)result + 10) = 0;
*((_DWORD *)result + 11) = 0;
*((_DWORD *)result + 12) = 0;
*((_DWORD *)result + 13) = 0;
*((_DWORD *)result + 14) = 0;
*((_DWORD *)result + 15) = 0;
*((_DWORD *)result + 16) = 0;
*((_DWORD *)result + 17) = 0;
return result;
}

original_code:
MONK_HITS * new_monk_hit()
{
    MONK_HITS * hit = ((void *)0);
    hit = (MONK_HITS *)malloc(sizeof(*hit));
    hit->hit_name = "\0";
    hit->monk_text = "\0";
    hit->victim_text = "\0";
    hit->room_text = "\0";
    hit->min_skill_req = 0;
    hit->min_wisdom_req = 0;
    hit->rating = 0;
    hit->damage[0] = 0;
    hit->damage[1] = 0;
    hit->dam_bonus = 0;
    hit->hit_bonus = 0;
    hit->victim_type = 0;
    hit->victim_parts = 0;
    hit->special_flag = 0;
    return hit;
}

canonical_original_code:
struct monk_hits *new_monk_hit()
{
    struct monk_hits *hit = ((void *)0);
    hit = (struct monk_hits *)malloc(sizeof(*hit));
    hit->hit_name = "\0";
    hit->monk_text = "\0";
    hit->victim_text = "\0";
    hit->room_text = "\0";
    hit->min_skill_req = 0;
    hit->min_wisdom_req = 0;
    hit->rating = 0;
    hit->damage[0] = 0;
    hit->damage[1] = 0;
    hit->dam_bonus = 0;
    hit->hit_bonus = 0;
    hit->victim_type = 0;
    hit->victim_parts = 0;
    hit->special_flag = 0;
    return hit;
}

return_type: struct monk_hits { char *hit_name; char *monk_text; char *victim_text; char *room_text; int min_skill_req; int min_wisdom_req; int rating; int damage[2]; int dam_bonus; int hit_bonus; int victim_type; int victim_parts; int special_flag; struct monk_hits *next; } *


decompiled_code:
const char *__fastcall nazwa_projektu(int a1)
{
char *v1; // rax
const char *v2; // rdx

save_debug_info("projects.c => nazwa_projektu", 0LL, 0LL, 1LL, 3LL, 1LL);
v1 = (char *)&projects_table;
v2 = "unknown";
do
{
if ( *(_DWORD *)v1 == a1 )
break;
v1 += 32;
v2 = (const char *)*((_QWORD *)v1 + 1);
}
while ( v2 );
return v2;
}

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
char *v1; // rax
const char *v2; // rdx

save_debug_info("projects.c => nazwa_projektu", 0LL, 0LL, 1LL, 3LL, 1LL);
v1 = (char *)&projects_table;
v2 = "unknown";
do
{
if ( *(_DWORD *)v1 == a1 )
break;
v1 += 32;
v2 = (const char *)*((_QWORD *)v1 + 1);
}
while ( v2 );
return v2;
}

original_code:
char *nazwa_projektu( int nr )
{
 int i;
 const char *call = "projects.c => nazwa_projektu";
 save_debug_info( call, ((void *)0), ((void *)0), 1, 3, 1 );
 for ( i = 0; projects_table[i].name; i++ )
 {
  if ( projects_table[i].number == nr ) return projects_table[i].name;
 }
 return ((void *)0);
}

canonical_original_code:
char *nazwa_projektu(int nr)
{
 int i;
 char *call = "projects.c => nazwa_projektu";
 save_debug_info( call, ((void *)0), ((void *)0), 1, 3, 1 );
 for ( i = 0; projects_table[i].name; i++ )
 {
  if ( projects_table[i].number == nr ) return projects_table[i].name;
 }
 return ((void *)0);
}

variable_types: nr int


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

if ( a1 < 0 )
return 0LL;
for ( result = pre_waits; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)(result + 16) == a1 )
break;
}
return result;
}

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

if ( a1 < 0 )
return 0LL;
for ( result = pre_waits; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)(result + 16) == a1 )
break;
}
return result;
}

original_code:
PRE_WAIT * get_prewait( int sn )
{
    PRE_WAIT * tmp = ((void *)0);
    if ( sn < 0 )
        return ((void *)0);
    for ( tmp = pre_waits;tmp;tmp = tmp->next )
        if ( tmp->sn == sn )
            return ( tmp );
    return ((void *)0);
}

canonical_original_code:
struct pre_wait *get_prewait(int sn)
{
    struct pre_wait *tmp = ((void *)0);
    if ( sn < 0 )
        return ((void *)0);
    for ( tmp = pre_waits;tmp;tmp = tmp->next )
        if ( tmp->sn == sn )
            return ( tmp );
    return ((void *)0);
}

variable_types: sn int

variable_types: struct pre_wait { unsigned char valid; short duration; char *spell_name; int sn; struct pflag_data { unsigned char valid; char *id; int duration; int target; struct pflag_data *next; } *list; struct pre_wait *next; } *

user_defined_types: struct pre_wait { unsigned char valid; short duration; char *spell_name; int sn; struct pflag_data *list; struct pre_wait *next; }


decompiled_code:
void save_songs()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void save_songs( void )
{
}

canonical_original_code:
void save_songs()
{
}


decompiled_code:
__int64 __fastcall popen2(__int64 a1, _DWORD *a2, _DWORD *a3)
{
__pid_t v4; // eax
unsigned int v5; // er14
int v7[2]; // [rsp+0h] [rbp-30h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-28h] BYREF

if ( pipe(pipedes) )
return (unsigned int)-1;
if ( pipe(v7) )
return (unsigned int)-1;
v4 = fork();
v5 = v4;
if ( v4 >= 0 )
{
if ( v4 )
{
if ( a2 )
*a2 = pipedes[1];
else
close(pipedes[1]);
if ( a3 )
*a3 = v7[0];
else
close(v7[0]);
close(pipedes[0]);
close(v7[1]);
}
else
{
close(pipedes[1]);
dup2(pipedes[0], 0);
close(v7[0]);
dup2(v7[1], 1);
execl("/bin/sh", "sh", &unk_108, a1, 0LL);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2, _DWORD *a3)
{
__pid_t v4; // eax
unsigned int v5; // er14
int v7[2]; // [rsp+0h] [rbp-30h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-28h] BYREF

if ( pipe(pipedes) )
return (unsigned int)-1;
if ( pipe(v7) )
return (unsigned int)-1;
v4 = fork();
v5 = v4;
if ( v4 >= 0 )
{
if ( v4 )
{
if ( a2 )
*a2 = pipedes[1];
else
close(pipedes[1]);
if ( a3 )
*a3 = v7[0];
else
close(v7[0]);
close(pipedes[0]);
close(v7[1]);
}
else
{
close(pipedes[1]);
dup2(pipedes[0], 0);
close(v7[0]);
dup2(v7[1], 1);
execl("/bin/sh", "sh", &unk_108, a1, 0LL);
}
}
return v5;
}

original_code:
pid_t
popen2(const char *command, int *infp, int *outfp)
{
    int p_stdin[2], p_stdout[2];
    pid_t pid;
    if (pipe(p_stdin) != 0 || pipe(p_stdout) != 0)
        return -1;
    pid = fork();
    if (pid < 0)
        return pid;
    else if (pid == 0)
    {
        close(p_stdin[1]);
        dup2(p_stdin[0], 0);
        close(p_stdout[0]);
        dup2(p_stdout[1], 1);
        execl("/bin/sh", "sh", "-c", command, ((void *)0));
 return (pid_t)((void *)0);
    }
    if (infp == ((void *)0))
        close(p_stdin[1]);
    else
        *infp = p_stdin[1];
    if (outfp == ((void *)0))
        close(p_stdout[0]);
    else
        *outfp = p_stdout[0];
 close(p_stdin[0]);
 close(p_stdout[1]);
    return pid;
}

canonical_original_code:
int popen2(char *command, int *infp, int *outfp)
{
    int p_stdin[2]; int p_stdout[2];
    int pid;
    if (pipe(p_stdin) != 0 || pipe(p_stdout) != 0)
        return -1;
    pid = fork();
    if (pid < 0)
        return pid;
    else if (pid == 0)
    {
        close(p_stdin[1]);
        dup2(p_stdin[0], 0);
        close(p_stdout[0]);
        dup2(p_stdout[1], 1);
        execl("/bin/sh", "sh", "-c", command, ((void *)0));
 return (pid_t)((void *)0);
    }
    if (infp == ((void *)0))
        close(p_stdin[1]);
    else
        *infp = p_stdin[1];
    if (outfp == ((void *)0))
        close(p_stdout[0]);
    else
        *outfp = p_stdout[0];
 close(p_stdin[0]);
 close(p_stdout[1]);
    return pid;
}

variable_types:
command
char *

variable_types:
infp
int *

variable_types:
outfp
int *

variable_types: pid int


norm

repo: blkqi/kmeans

original_code:
double
norm (double *matrix, int n, int m)
{
    double column_sum [n];
    double max = 0, test = 0;
    int i, j;
    for (i = 0; i < n; ++i) {
        column_sum[i] = 0;
        for (j = 0; j < m; ++j)
            column_sum[i] += matrix[i*m+j];
        if ((test = fabs (column_sum [i])) > max)
            max = test;
    }
    return max;
}

canonical_original_code:
double norm(double *matrix, int n, int m)
{
    double column_sum[-1];
    double max = 0; double test = 0;
    int i; int j;
    for (i = 0; i < n; ++i) {
        column_sum[i] = 0;
        for (j = 0; j < m; ++j)
            column_sum[i] += matrix[i*m+j];
        if ((test = fabs (column_sum [i])) > max)
            max = test;
    }
    return max;
}

variable_types:
matrix
double *

variable_types: n int

variable_types: m int

variable_types: max double

variable_types: test double

variable_types: j int


decompiled_code:
__int64 __fastcall exp_bits(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return a1;
}

original_code:
uint exp_bits(ulli n)
{
  return n;
}

canonical_original_code:
unsigned int exp_bits(unsigned long long n)
{
  return n;
}

variable_types:
n
unsigned long long

return_type: unsigned int


decompiled_code:
__int64 __fastcall get_exponent(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return a1;
}

original_code:
uint get_exponent(ulli n)
{
  return n;
}

canonical_original_code:
unsigned int get_exponent(unsigned long long n)
{
  return n;
}


decompiled_code:
__int64 __fastcall set_exponent(__int64 a1, unsigned int a2)
{
return a1 + a2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
return a1 + a2;
}

original_code:
ulli set_exponent(ulli n, uint exp)
{
  return n+exp;
}

canonical_original_code:
unsigned long long set_exponent(unsigned long long n, unsigned int exp)
{
  return n+exp;
}

variable_types:
exp
unsigned int

return_type: unsigned long long


decompiled_code:
__int64 __fastcall get_mantissa(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return a1;
}

original_code:
ulli get_mantissa(ulli n)
{
  return n;
}

canonical_original_code:
unsigned long long get_mantissa(unsigned long long n)
{
  return n;
}