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


repo: blanciq/bq-killer

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 *)

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

return_type: 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
__int64 v15[2]; // [rsp+18h] [rbp-18h] BYREF

v13 = (_QWORD *)gl_empty();
v0 = v13;
v14 = 0x200000001LL;
v15[0] = 0x400000003LL;
gl_push_front((__int64 *)&v13, (__int64)&v14);
gl_push_front((__int64 *)&v13, (__int64)&v14 + 4);
gl_push_front((__int64 *)&v13, (__int64)v15);
gl_push_front((__int64 *)&v13, (__int64)v15 + 4);
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
__int64 v15[2]; // [rsp+18h] [rbp-18h] BYREF

v13 = (_QWORD *)func5();
v0 = v13;
v14 = 0x200000001LL;
v15[0] = 0x400000003LL;
gl_push_front((__int64 *)&v13, (__int64)&v14);
gl_push_front((__int64 *)&v13, (__int64)&v14 + 4);
gl_push_front((__int64 *)&v13, (__int64)v15);
gl_push_front((__int64 *)&v13, (__int64)v15 + 4);
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 *


decompiled_code:
__int64 __fastcall gl_filter(__int64 *a1, __int64 (__fastcall *a2)(__int64))
{
__int64 *v2; // rbx
__int64 result; // rax
int v4; // eax
__int64 v5[3]; // [rsp+8h] [rbp-18h] BYREF

v2 = a1;
result = gl_empty();
v5[0] = result;
if ( a1 )
{
do
{
v4 = a2(*v2);
if ( v4 != 2 )
{
if ( !v4 )
break;
gl_push_front(v5, *v2);
}
v2 = (__int64 *)v2[1];
}
while ( v2 );
result = v5[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1, __int64 (__fastcall *a2)(__int64))
{
__int64 *v2; // rbx
__int64 result; // rax
int v4; // eax
__int64 v5[3]; // [rsp+8h] [rbp-18h] BYREF

v2 = a1;
result = func5();
v5[0] = result;
if ( a1 )
{
do
{
v4 = a2(*v2);
if ( v4 != 2 )
{
if ( !v4 )
break;
gl_push_front(v5, *v2);
}
v2 = (__int64 *)v2[1];
}
while ( v2 );
result = v5[0];
}
return result;
}

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 != &str_empty && ptr )
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 != &str_empty && ptr )
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]

return_type: char *


decompiled_code:
__int64 __fastcall is_stat(void *a1)
{
__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;
v2 = *(void **)(v1 + 8);
v1 += 16LL;
}
while ( v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
__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;
v2 = *(void **)(v1 + 8);
v1 += 16LL;
}
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

return_type: unsigned char


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

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

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

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

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

return_type: int

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


decompiled_code:
const char *__fastcall flag_string(_QWORD *a1, int a2)
{
int v2; // er14
_QWORD *v3; // rbx
__int64 v4; // rax
const char *v5; // r13
char v6; // r15
int v7; // eax
size_t v8; // rax
const char *result; // rax
size_t v10; // rax

v2 = cnt_7 + 1;
v3 = a1;
if ( cnt_7 + 1 <= 1 )
{
++cnt_7;
}
else
{
cnt_7 = 0;
v2 = 0;
}
v4 = (__int64)v2 << 9;
buf_6[v4] = 0;
v5 = &buf_6[v4];
if ( !*a1 )
goto LABEL_12;
v6 = is_stat(a1);
while ( 1 )
{
while ( 1 )
{
v7 = *((_DWORD *)v3 + 2);
if ( v6 || (v7 & a2) <= 0 )
break;
v3 += 2;
v8 = strlen(v5);
*(_WORD *)&v5[v8] = 32;
strcpy((char *)&v5[v8 + 1], (const char *)*(v3 - 2));
if ( !*v3 )
goto LABEL_10;
}
if ( a2 == v7 )
break;
v3 += 2;
if ( !*v3 )
goto LABEL_10;
}
v10 = strlen(v5);
*(_WORD *)&v5[v10] = 32;
strcpy((char *)&v5[v10 + 1], (const char *)*v3);
LABEL_10:
if ( buf_6[512 * (__int64)v2] )
result = v5 + 1;
else
LABEL_12:
result = "none";
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(_QWORD *a1, int a2)
{
int v2; // er14
_QWORD *v3; // rbx
__int64 v4; // rax
const char *v5; // r13
char v6; // r15
int v7; // eax
size_t v8; // rax
const char *result; // rax
size_t v10; // rax

v2 = cnt_7 + 1;
v3 = a1;
if ( cnt_7 + 1 <= 1 )
{
++cnt_7;
}
else
{
cnt_7 = 0;
v2 = 0;
}
v4 = (__int64)v2 << 9;
buf_6[v4] = 0;
v5 = &buf_6[v4];
if ( !*a1 )
goto LABEL_12;
v6 = func0(a1);
while ( 1 )
{
while ( 1 )
{
v7 = *((_DWORD *)v3 + 2);
if ( v6 || (v7 & a2) <= 0 )
break;
v3 += 2;
v8 = strlen(v5);
*(_WORD *)&v5[v8] = 32;
strcpy((char *)&v5[v8 + 1], (const char *)*(v3 - 2));
if ( !*v3 )
goto LABEL_10;
}
if ( a2 == v7 )
break;
v3 += 2;
if ( !*v3 )
goto LABEL_10;
}
v10 = strlen(v5);
*(_WORD *)&v5[v10] = 32;
strcpy((char *)&v5[v10 + 1], (const char *)*v3);
LABEL_10:
if ( buf_6[512 * (__int64)v2] )
result = v5 + 1;
else
LABEL_12:
result = "none";
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 )
{
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

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

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
_QWORD *v1; // rax

if ( !a1 )
return 1LL;
v1 = a1 + 5;
while ( !*a1 )
{
if ( ++a1 == v1 )
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)
{
int v2; // er12
const char **v3; // rbx
__int64 v4; // rax
const char *v5; // r13
size_t v6; // rax
const char *result; // rax

v2 = cnt_1 + 1;
v3 = a1;
if ( cnt_1 + 1 <= 1 )
{
++cnt_1;
}
else
{
cnt_1 = 0;
v2 = 0;
}
v4 = (__int64)v2 << 9;
buf_0[v4] = 0;
v5 = &buf_0[v4];
if ( !*a1 )
goto LABEL_9;
do
{
if ( (__int64)(*(_QWORD *)(a2 + 8LL * *(int *)v3[1]) & *((int *)v3[1] + 1)) > 0 )
{
v6 = strlen(v5);
*(_WORD *)&v5[v6] = 32;
strcpy((char *)&v5[v6 + 1], *v3);
}
v3 += 3;
}
while ( *v3 );
if ( buf_0[512 * (__int64)v2] )
result = v5 + 1;
else
LABEL_9:
result = "none";
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
__int64 *v3; // rdi

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

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

result = *a1;
if ( *a1 )
{
v3 = a1 + 3;
do
{
if ( *(v3 - 2) == a2 )
break;
result = *v3;
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_1FE8, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) |= 1 << a2;
result = 1LL;
}
return result;
}

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

if ( a2 > 319 )
{
save_debug_info("bit.c => set_bigflag", 0LL, &unk_1FE8, 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_1FE8, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) &= ~(1 << a2);
result = 1LL;
}
return result;
}

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

if ( a2 > 319 )
{
save_debug_info("bit.c => rmv_bigflag", 0LL, &unk_1FE8, 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_1FE8, 1LL, 0LL, 1LL);
result = 0LL;
}
else
{
*(_DWORD *)(a1 + 4 * ((__int64)a2 >> 5)) ^= 1 << a2;
result = 1LL;
}
return result;
}

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

if ( a2 > 319 )
{
save_debug_info("bit.c => tgl_bigflag", 0LL, &unk_1FE8, 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
__m128i v3; // xmm0
__m128i v4; // xmm0

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_1FE8, 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");
v3 = _mm_load_si128((const __m128i *)&LC13);
*((_WORD *)&log_buf + 34) = 33;
log_buf = v3;
v4 = _mm_load_si128((const __m128i *)&LC14);
*((_DWORD *)&log_buf + 16) = 1701732727;
*((__m128i *)&log_buf + 1) = v4;
*((__m128i *)&log_buf + 2) = _mm_load_si128((const __m128i *)&LC15);
*((__m128i *)&log_buf + 3) = _mm_load_si128((const __m128i *)&LC16);
log_string(&log_buf);
result = 0;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func15(__int64 a1, int a2)
{
bool result; // al
__m128i v3; // xmm0
__m128i v4; // xmm0

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_1FE8, 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");
v3 = _mm_load_si128((const __m128i *)&LC13);
*((_WORD *)&log_buf + 34) = 33;
log_buf = v3;
v4 = _mm_load_si128((const __m128i *)&LC14);
*((_DWORD *)&log_buf + 16) = 1701732727;
*((__m128i *)&log_buf + 1) = v4;
*((__m128i *)&log_buf + 2) = _mm_load_si128((const __m128i *)&LC15);
*((__m128i *)&log_buf + 3) = _mm_load_si128((const __m128i *)&LC16);
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 v4; // ax
__int64 v5; // r13
char dest[8224]; // [rsp+0h] [rbp-2020h] BYREF

v2 = (const char *)capitalize_first();
strcpy(dest, v2);
v3 = ban_list;
for ( dest[0] = *((_BYTE *)&lower_pol + (unsigned __int8)dest[0]); v3; v3 = *(_QWORD *)v3 )
{
LOBYTE(v4) = *(_WORD *)(v3 + 10);
if ( (a2 & *(__int16 *)(v3 + 10)) > 0 )
{
if ( (v4 & 2) != 0 )
{
v5 = *(_QWORD *)(v3 + 16);
if ( (v4 & 1) != 0 && strstr(*(const char **)(v3 + 16), dest) || !(unsigned __int8)str_suffix(v5, dest) )
return 1LL;
v4 = *(_WORD *)(v3 + 10);
}
if ( (v4 & 1) != 0 && !(unsigned __int8)str_prefix(*(_QWORD *)(v3 + 16), dest) )
return 1LL;
}
}
return 0LL;
}

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

v2 = (const char *)capitalize_first();
strcpy(dest, v2);
v3 = ban_list;
for ( dest[0] = *((_BYTE *)&lower_pol + (unsigned __int8)dest[0]); v3; v3 = *(_QWORD *)v3 )
{
LOBYTE(v4) = *(_WORD *)(v3 + 10);
if ( (a2 & *(__int16 *)(v3 + 10)) > 0 )
{
if ( (v4 & 2) != 0 )
{
v5 = *(_QWORD *)(v3 + 16);
if ( (v4 & 1) != 0 && strstr(*(const char **)(v3 + 16), dest) || !(unsigned __int8)str_suffix(v5, dest) )
return 1LL;
v4 = *(_WORD *)(v3 + 10);
}
if ( (v4 & 1) != 0 && !(unsigned __int8)str_prefix(*(_QWORD *)(v3 + 16), dest) )
return 1LL;
}
}
return 0LL;
}

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(_BYTE *a1)
{
int v1; // eax
_BYTE *v2; // rdi
int v3; // edx

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

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

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = a1 + 1;
v3 = 0;
do
{
++v2;
v3 += v1;
v1 = (char)*(v2 - 1);
}
while ( *(v2 - 1) );
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(_BYTE *a1)
{
__int64 v1; // rbx
unsigned __int8 *v2; // r12

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

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 v1; // rbx
unsigned __int8 *v2; // r12

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

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(_BYTE *a1)
{
unsigned __int8 *v1; // r12

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

canonical_decompiled_code:
unsigned __int8 *__fastcall func2(_BYTE *a1)
{
unsigned __int8 *v1; // r12

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

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
char **v3; // rax
char **v4; // r13
char *v5; // rax
__int64 v6; // rdx
int v7; // eax
__int64 v8; // rdx
unsigned __int8 *v9; // rax

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

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()
{
memset(name_table, 0, sizeof(name_table));
return load_files();
}

canonical_decompiled_code:
int func7()
{
memset(name_table, 0, sizeof(name_table));
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 != &str_empty && v2 )
{
free(v2);
*(_QWORD *)ptr = 0LL;
}
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 != &str_empty && v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 != &str_empty && v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 3);
if ( v5 != &str_empty )
{
if ( v5 )
free(v5);
}
free(ptr);
}
}

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 != &str_empty && v2 )
{
free(v2);
*(_QWORD *)ptr = 0LL;
}
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 != &str_empty && v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 != &str_empty && v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 3);
if ( v5 != &str_empty )
{
if ( v5 )
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_1208;
result[1] = &unk_1208;
result[2] = &unk_1208;
result[3] = &unk_1208;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
result[8] = 0LL;
return result;
}

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

result = malloc(0x50uLL);
*result = &unk_1208;
result[1] = &unk_1208;
result[2] = &unk_1208;
result[3] = &unk_1208;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
result[7] = 0LL;
result[8] = 0LL;
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)
{
__int64 v1; // rax
int v2; // edx
const char *v3; // r8

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

canonical_decompiled_code:
const char *__fastcall func0(int a1)
{
__int64 v1; // rax
int v2; // edx
const char *v3; // r8

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

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 func1(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; // er12
int pipedes[2]; // [rsp+0h] [rbp-30h] BYREF
int v8[2]; // [rsp+8h] [rbp-28h] BYREF

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

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

if ( pipe(pipedes) || pipe(v8) )
return (unsigned int)-1;
v4 = fork();
v5 = v4;
if ( v4 < 0 )
return v5;
if ( v4 )
{
if ( a2 )
*a2 = pipedes[1];
else
close(pipedes[1]);
if ( a3 )
*a3 = v8[0];
else
close(v8[0]);
close(pipedes[0]);
close(v8[1]);
return v5;
}
close(pipedes[1]);
dup2(pipedes[0], 0);
close(v8[0]);
dup2(v8[1], 1);
execl("/bin/sh", "sh", &unk_FD, 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

decompiled_code:
double __fastcall norm(__int64 a1, int a2, int a3)
{
void *v3; // rsp
double *v4; // rcx
double *v5; // r9
int v6; // esi
double v7; // xmm1_8
double v8; // xmm0_8
double *v9; // rax
double v10; // xmm0_8
double result; // xmm0_8
__int64 savedregs; // [rsp+0h] [rbp+0h] BYREF

v3 = alloca(8LL * a2);
if ( a2 <= 0 )
return 0.0;
v4 = (double *)&savedregs;
v5 = (double *)(&savedregs + (unsigned int)a2);
v6 = 0;
v7 = 0.0;
do
{
if ( a3 <= 0 )
{
v10 = 0.0;
}
else
{
v8 = 0.0;
v9 = (double *)(a1 + 8LL * v6);
do
v8 = v8 + *v9++;
while ( v9 != (double *)(a1 + 8 + 8 * ((unsigned int)(a3 - 1) + (__int64)v6)) );
*v4 = v8;
v10 = fabs(v8);
}
result = fmax(v10, v7);
++v4;
v6 += a3;
v7 = result;
}
while ( v4 != v5 );
return result;
}

canonical_decompiled_code:
double __fastcall func9(__int64 a1, int a2, int a3)
{
void *v3; // rsp
double *v4; // rcx
double *v5; // r9
int v6; // esi
double v7; // xmm1_8
double v8; // xmm0_8
double *v9; // rax
double v10; // xmm0_8
double result; // xmm0_8
__int64 savedregs; // [rsp+0h] [rbp+0h] BYREF

v3 = alloca(8LL * a2);
if ( a2 <= 0 )
return 0.0;
v4 = (double *)&savedregs;
v5 = (double *)(&savedregs + (unsigned int)a2);
v6 = 0;
v7 = 0.0;
do
{
if ( a3 <= 0 )
{
v10 = 0.0;
}
else
{
v8 = 0.0;
v9 = (double *)(a1 + 8LL * v6);
do
v8 = v8 + *v9++;
while ( v9 != (double *)(a1 + 8 + 8 * ((unsigned int)(a3 - 1) + (__int64)v6)) );
*v4 = v8;
v10 = fabs(v8);
}
result = fmax(v10, v7);
++v4;
v6 += a3;
v7 = result;
}
while ( v4 != v5 );
return result;
}

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

return_type: double


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rax
unsigned int v6; // eax
unsigned int v7; // eax
__int64 v8; // rax
__int64 v10; // [rsp+8h] [rbp-10h]
__int64 v11; // [rsp+8h] [rbp-10h]

puts(" ................");
printf("Enter 16 hexadeximal digits: ");
__isoc99_scanf();
printf("Enter hexadeximal digits for new exponent: ");
__isoc99_scanf();
putchar(10);
printf("entered number (hex) %016llx\n", v10);
v3 = exp_bits();
printf("number of exp bits are (dec) %16u\n", v3);
v4 = exp_bits();
printf("value of exponent is (hex) %16x\n", v4);
v5 = get_mantissa();
printf("value of mantissa is (hex) %16llx\n", v5);
v11 = set_exponent(v10);
putchar(10);
printf("modified number (hex) %016llx\n", v11);
v6 = exp_bits();
printf("number of exp bits are (dec) %16u\n", v6);
v7 = exp_bits();
printf("value of exponent is (hex) %16x\n", v7);
v8 = get_mantissa();
printf("value of mantissa is (hex) %16llx\n", v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rax
unsigned int v6; // eax
unsigned int v7; // eax
__int64 v8; // rax
__int64 v10; // [rsp+8h] [rbp-10h]
__int64 v11; // [rsp+8h] [rbp-10h]

puts(" ................");
printf("Enter 16 hexadeximal digits: ");
__isoc99_scanf();
printf("Enter hexadeximal digits for new exponent: ");
__isoc99_scanf();
putchar(10);
printf("entered number (hex) %016llx\n", v10);
v3 = func7();
printf("number of exp bits are (dec) %16u\n", v3);
v4 = func7();
printf("value of exponent is (hex) %16x\n", v4);
v5 = func10();
printf("value of mantissa is (hex) %16llx\n", v5);
v11 = func9(v10);
putchar(10);
printf("modified number (hex) %016llx\n", v11);
v6 = func7();
printf("number of exp bits are (dec) %16u\n", v6);
v7 = func7();
printf("value of exponent is (hex) %16x\n", v7);
v8 = func10();
printf("value of mantissa is (hex) %16llx\n", v8);
return 0;
}

original_code:
int main()
{
  ulli number;
  uint new_exponent;
  printf("                             ................\n");
  printf("Enter 16 hexadeximal digits: ");
  scanf("%llx", &number);
  printf("Enter hexadeximal digits for new exponent: ");
  scanf("%x", &new_exponent);
  printf("\n");
  printf("entered number         (hex) %016llx\n", number);
  printf("number of exp bits are (dec) %16u\n", exp_bits(number));
  printf("value of exponent is   (hex) %16x\n", get_exponent(number));
  printf("value of mantissa is   (hex) %16llx\n", get_mantissa(number));
  number = set_exponent(number, new_exponent);
  printf("\n");
  printf("modified number        (hex) %016llx\n", number);
  printf("number of exp bits are (dec) %16u\n", exp_bits(number));
  printf("value of exponent is   (hex) %16x\n", get_exponent(number));
  printf("value of mantissa is   (hex) %16llx\n", get_mantissa(number));
  return 0;
}

canonical_original_code:
int main()
{
  unsigned long long number;
  unsigned int new_exponent;
  printf("                             ................\n");
  printf("Enter 16 hexadeximal digits: ");
  scanf("%llx", &number);
  printf("Enter hexadeximal digits for new exponent: ");
  scanf("%x", &new_exponent);
  printf("\n");
  printf("entered number         (hex) %016llx\n", number);
  printf("number of exp bits are (dec) %16u\n", exp_bits(number));
  printf("value of exponent is   (hex) %16x\n", get_exponent(number));
  printf("value of mantissa is   (hex) %16llx\n", get_mantissa(number));
  number = set_exponent(number, new_exponent);
  printf("\n");
  printf("modified number        (hex) %016llx\n", number);
  printf("number of exp bits are (dec) %16u\n", exp_bits(number));
  printf("value of exponent is   (hex) %16x\n", get_exponent(number));
  printf("value of mantissa is   (hex) %16llx\n", get_mantissa(number));
  return 0;
}

variable_types:
number
unsigned long long


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:
// attributes: thunk
__int64 __fastcall get_exponent(__int64 a1)
{
return exp_bits(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return func7(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;
}


decompiled_code:
void set_display()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void set_display(int value)
{
}

canonical_original_code:
void set_display(int value)
{
}

variable_types: value int


decompiled_code:
void seconds_to_display()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void seconds_to_display(int seconds)
{
  set_display( 0 );
}

variable_types: seconds int


Heat

decompiled_code:
void Heat()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void Heat()
{
}

canonical_original_code:
void Heat()
{
}


decompiled_code:
__int64 Set_Time()
{
__int64 result; // rax
int v1; // edx
int v2; // edx

result = (unsigned int)state_1;
if ( state_1 == 2 )
{
result = (unsigned int)clock;
if ( (A & 1) != 0 )
{
result = (unsigned int)(clock + 20);
clock += 20;
v2 = ++press_count_0;
}
else
{
if ( (A & 2) != 0 )
goto LABEL_12;
v2 = press_count_0;
}
if ( v2 > 5 )
{
press_count_0 = 0;
state_1 = 3;
}
goto LABEL_14;
}
if ( (unsigned int)state_1 > 2 )
{
if ( state_1 != 3 )
{
result = (unsigned int)clock;
goto LABEL_14;
}
result = (unsigned int)clock;
if ( (A & 1) != 0 )
{
result = (unsigned int)(clock + 60);
clock += 60;
goto LABEL_14;
}
if ( (A & 2) == 0 )
goto LABEL_14;
LABEL_12:
press_count_0 = 0;
state_1 = 1;
result = (unsigned int)((int)result / 2);
clock = result;
goto LABEL_14;
}
if ( !state_1 )
{
press_count_0 = 0;
state_1 = 1;
clock = 0;
return result;
}
result = (unsigned int)clock;
if ( (A & 1) != 0 )
{
result = (unsigned int)(clock + 10);
clock += 10;
v1 = ++press_count_0;
}
else
{
if ( (A & 2) != 0 )
{
press_count_0 = 0;
result = (unsigned int)(clock / 2);
clock /= 2;
goto LABEL_14;
}
v1 = press_count_0;
}
if ( v1 > 5 )
{
press_count_0 = 0;
state_1 = 2;
if ( (int)result <= 5999 )
return result;
LABEL_15:
clock = 5999;
return result;
}
LABEL_14:
if ( (int)result > 5999 )
goto LABEL_15;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
int v1; // edx
int v2; // edx

result = (unsigned int)state_1;
if ( state_1 == 2 )
{
result = (unsigned int)clock;
if ( (A & 1) != 0 )
{
result = (unsigned int)(clock + 20);
clock += 20;
v2 = ++press_count_0;
}
else
{
if ( (A & 2) != 0 )
goto LABEL_12;
v2 = press_count_0;
}
if ( v2 > 5 )
{
press_count_0 = 0;
state_1 = 3;
}
goto LABEL_14;
}
if ( (unsigned int)state_1 > 2 )
{
if ( state_1 != 3 )
{
result = (unsigned int)clock;
goto LABEL_14;
}
result = (unsigned int)clock;
if ( (A & 1) != 0 )
{
result = (unsigned int)(clock + 60);
clock += 60;
goto LABEL_14;
}
if ( (A & 2) == 0 )
goto LABEL_14;
LABEL_12:
press_count_0 = 0;
state_1 = 1;
result = (unsigned int)((int)result / 2);
clock = result;
goto LABEL_14;
}
if ( !state_1 )
{
press_count_0 = 0;
state_1 = 1;
clock = 0;
return result;
}
result = (unsigned int)clock;
if ( (A & 1) != 0 )
{
result = (unsigned int)(clock + 10);
clock += 10;
v1 = ++press_count_0;
}
else
{
if ( (A & 2) != 0 )
{
press_count_0 = 0;
result = (unsigned int)(clock / 2);
clock /= 2;
goto LABEL_14;
}
v1 = press_count_0;
}
if ( v1 > 5 )
{
press_count_0 = 0;
state_1 = 2;
if ( (int)result <= 5999 )
return result;
LABEL_15:
clock = 5999;
return result;
}
LABEL_14:
if ( (int)result > 5999 )
goto LABEL_15;
return result;
}

original_code:
void Set_Time()
{
  static enum {INIT,INC_10S, INC_20S, INC_1M} state = INIT;
  static int press_count;
  switch (state)
  {
    case INIT:
      press_count = 0;
      state = INC_10S;
      clock = 0;
      break;
    case INC_10S:
      if ( (A & 0x01) )
      {
        clock += 10;
        ++press_count;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
      }
      if (press_count >= 6)
      {
        press_count = 0;
        state = INC_20S;
      }
      break;
    case INC_20S:
      if ( (A & 0x01) )
      {
        clock += 20;
        ++press_count;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
        state = INC_10S;
      }
      if (press_count >= 6)
      {
        press_count = 0;
        state = INC_1M;
      }
      break;
    case INC_1M:
      if ( (A & 0x01) )
      {
        clock += 60;
        state = INC_1M;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
        state = INC_10S;
      }
      break;
  }
  switch (state)
  {
    case INIT:
      break;
    case INC_10S:
      time_set = (clock != 0);
      break;
    case INC_20S:
      time_set = (clock != 0);
      break;
    case INC_1M:
      time_set = (clock != 0);
      break;
  }
  if (clock > 99*60+59)
    clock = 99*60+59;
}

canonical_original_code:
void Set_Time()
{
  static enum { INIT=0, INC_10S=1, INC_20S=2, INC_1M=3 } state = INIT;
  static int press_count;
  switch (state)
  {
    case INIT:
      press_count = 0;
      state = INC_10S;
      clock = 0;
      break;
    case INC_10S:
      if ( (A & 0x01) )
      {
        clock += 10;
        ++press_count;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
      }
      if (press_count >= 6)
      {
        press_count = 0;
        state = INC_20S;
      }
      break;
    case INC_20S:
      if ( (A & 0x01) )
      {
        clock += 20;
        ++press_count;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
        state = INC_10S;
      }
      if (press_count >= 6)
      {
        press_count = 0;
        state = INC_1M;
      }
      break;
    case INC_1M:
      if ( (A & 0x01) )
      {
        clock += 60;
        state = INC_1M;
      }
      else if ( (A & 0x02) )
      {
        clock /= 2;
        press_count = 0;
        state = INC_10S;
      }
      break;
  }
  switch (state)
  {
    case INIT:
      break;
    case INC_10S:
      time_set = (clock != 0);
      break;
    case INC_20S:
      time_set = (clock != 0);
      break;
    case INC_1M:
      time_set = (clock != 0);
      break;
  }
  if (clock > 99*60+59)
    clock = 99*60+59;
}


TimerISR

decompiled_code:
void TimerISR()
{
timer_period_elapsed = 1;
}

canonical_decompiled_code:
void func0()
{
timer_period_elapsed = 1;
}


decompiled_code:
__int64 app_main()
{
int v0; // ebx
__int64 result; // rax

v0 = 0;
TimerSet(200LL);
TimerOn();
for ( B = 0; ; B = v0++ )
{
result = true_test(1LL, "1");
if ( !(_DWORD)result )
break;
while ( (unsigned int)true_test(timer_period_elapsed == 0, "! timer_period_elapsed") )
;
timer_period_elapsed = 0;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // ebx
__int64 result; // rax

v0 = 0;
TimerSet(200LL);
TimerOn();
for ( B = 0; ; B = v0++ )
{
result = true_test(1LL, "1");
if ( !(_DWORD)result )
break;
while ( (unsigned int)true_test(timer_period_elapsed == 0, "! timer_period_elapsed") )
;
timer_period_elapsed = 0;
}
return result;
}

original_code:
int app_main(void)
{
   TimerSet(200);
   TimerOn();
   B = 0;
   byte count = 0;
   while ( true_test(1, "1") )
   {
     while ( true_test(! timer_period_elapsed, "! timer_period_elapsed") )
       ;
     timer_period_elapsed = 0;
     B = count;
     count = (count + 1);
   }
   return 0;
}

canonical_original_code:
int app_main()
{
   TimerSet(200);
   TimerOn();
   B = 0;
   unsigned char count = 0;
   while ( true_test(1, "1") )
   {
     while ( true_test(! timer_period_elapsed, "! timer_period_elapsed") )
       ;
     timer_period_elapsed = 0;
     B = count;
     count = (count + 1);
   }
   return 0;
}

variable_types:
count
unsigned char


HotelSafe

decompiled_code:
void HotelSafe()
{
;
}

original_code:
void HotelSafe()
{
}

canonical_original_code:
void HotelSafe()
{
}


Safe

decompiled_code:
int Safe()
{
char v0; // al
const char *v1; // rsi
int result; // eax
char v3; // al
char v4; // al
char v5; // al
__int64 v6[9]; // [rsp+0h] [rbp-48h]

v6[0] = (__int64)"LOCK";
v6[1] = (__int64)"PIN1";
v6[2] = (__int64)"PIN2";
v6[3] = (__int64)"PIN3";
v6[4] = (__int64)"PINX";
v6[5] = (__int64)"OPEN";
v6[6] = 0LL;
printf("Entry State = %s, A = %d\n", (const char *)v6[state_5], A);
switch ( state_5 )
{
case 0:
if ( A != pin1_4 )
goto LABEL_8;
state_5 = 1;
v3 = pin2_3;
goto LABEL_10;
case 1:
v3 = pin2_3;
if ( A == pin2_3 )
{
state_5 = 2;
v4 = pin3_2;
LABEL_12:
B = 0;
pin3_2 = v4 + 2;
result = printf("Exit State = %s\n", "PIN2");
}
else
{
LABEL_10:
B = 0;
pin2_3 = v3 + 1;
result = printf("Exit State = %s\n", "PIN1");
}
break;
case 2:
v4 = pin3_2;
if ( A != pin3_2 )
goto LABEL_12;
state_5 = 3;
v5 = pin4_1;
LABEL_14:
B = 0;
pin4_1 = v5 + 3;
count_0 = 0;
result = printf("Exit State = %s\n", "PIN3");
break;
case 3:
v5 = pin4_1;
if ( A != pin4_1 )
goto LABEL_14;
state_5 = 4;
v0 = count_0;
LABEL_3:
B = 0;
v1 = "PINX";
count_0 = v0 + 1;
LABEL_4:
result = printf("Exit State = %s\n", v1);
break;
case 4:
v0 = count_0;
if ( count_0 != 4 )
goto LABEL_3;
state_5 = 5;
LABEL_6:
B = 2;
result = printf("Exit State = %s\n", "OPEN");
break;
case 5:
if ( A != 11 )
goto LABEL_6;
state_5 = 0;
LABEL_8:
B = 1;
pin1_4 = 1;
pin2_3 = 1;
pin3_2 = 1;
pin4_1 = 1;
result = printf("Exit State = %s\n", "LOCK");
break;
default:
v1 = (const char *)v6[state_5];
goto LABEL_4;
}
return result;
}

canonical_decompiled_code:
int func3()
{
char v0; // al
const char *v1; // rsi
int result; // eax
char v3; // al
char v4; // al
char v5; // al
__int64 v6[9]; // [rsp+0h] [rbp-48h]

v6[0] = (__int64)"LOCK";
v6[1] = (__int64)"PIN1";
v6[2] = (__int64)"PIN2";
v6[3] = (__int64)"PIN3";
v6[4] = (__int64)"PINX";
v6[5] = (__int64)"OPEN";
v6[6] = 0LL;
printf("Entry State = %s, A = %d\n", (const char *)v6[state_5], A);
switch ( state_5 )
{
case 0:
if ( A != pin1_4 )
goto LABEL_8;
state_5 = 1;
v3 = pin2_3;
goto LABEL_10;
case 1:
v3 = pin2_3;
if ( A == pin2_3 )
{
state_5 = 2;
v4 = pin3_2;
LABEL_12:
B = 0;
pin3_2 = v4 + 2;
result = printf("Exit State = %s\n", "PIN2");
}
else
{
LABEL_10:
B = 0;
pin2_3 = v3 + 1;
result = printf("Exit State = %s\n", "PIN1");
}
break;
case 2:
v4 = pin3_2;
if ( A != pin3_2 )
goto LABEL_12;
state_5 = 3;
v5 = pin4_1;
LABEL_14:
B = 0;
pin4_1 = v5 + 3;
count_0 = 0;
result = printf("Exit State = %s\n", "PIN3");
break;
case 3:
v5 = pin4_1;
if ( A != pin4_1 )
goto LABEL_14;
state_5 = 4;
v0 = count_0;
LABEL_3:
B = 0;
v1 = "PINX";
count_0 = v0 + 1;
LABEL_4:
result = printf("Exit State = %s\n", v1);
break;
case 4:
v0 = count_0;
if ( count_0 != 4 )
goto LABEL_3;
state_5 = 5;
LABEL_6:
B = 2;
result = printf("Exit State = %s\n", "OPEN");
break;
case 5:
if ( A != 11 )
goto LABEL_6;
state_5 = 0;
LABEL_8:
B = 1;
pin1_4 = 1;
pin2_3 = 1;
pin3_2 = 1;
pin4_1 = 1;
result = printf("Exit State = %s\n", "LOCK");
break;
default:
v1 = (const char *)v6[state_5];
goto LABEL_4;
}
return result;
}

original_code:
void Safe()
{
  static enum { LOCK, PIN1, PIN2, PIN3, PINX, OPEN } state = LOCK;
  const char* debug[] = {
    "LOCK", "PIN1", "PIN2", "PIN3", "PINX", "OPEN", 0
  };
  static byte pin1 = 1, pin2 = 1, pin3 = 1, pin4 = 1;
  static byte count = 0;
  printf("Entry State = %s, A = %d\n", debug[state], A);
  switch( state )
  {
    case LOCK: if ( A == pin1 ) state = PIN1; break;
    case PIN1: if ( A == pin2 ) state = PIN2; break;
    case PIN2: if ( A == pin3 ) state = PIN3; break;
    case PIN3: if ( A == pin4 ) state = PINX; break;
    case PINX: if ( count == 4 ) state = OPEN; break;
    case OPEN: if ( A == 11 ) state = LOCK; break;
  }
  switch( state )
  {
    case LOCK: B = 1; pin1 = 1, pin2 = 1, pin3 = 1, pin4 = 1; break;
    case PIN1: B = 0; pin2 += 1; break;
    case PIN2: B = 0; pin3 += 2; break;
    case PIN3: B = 0; pin4 += 3; count = 0; break;
    case PINX: B = 0; ++count; break;
    case OPEN: B = 2; break;
  }
  printf("Exit State = %s\n", debug[state]);
}

canonical_original_code:
void Safe()
{
  static enum { LOCK=0, PIN1=1, PIN2=2, PIN3=3, PINX=4, OPEN=5 } state = LOCK;
  char *debug[] = {
    "LOCK", "PIN1", "PIN2", "PIN3", "PINX", "OPEN", 0
  };
  static unsigned char pin1 = 1; static unsigned char pin2 = 1; static unsigned char pin3 = 1; static unsigned char pin4 = 1;
  static unsigned char count = 0;
  printf("Entry State = %s, A = %d\n", debug[state], A);
  switch( state )
  {
    case LOCK: if ( A == pin1 ) state = PIN1; break;
    case PIN1: if ( A == pin2 ) state = PIN2; break;
    case PIN2: if ( A == pin3 ) state = PIN3; break;
    case PIN3: if ( A == pin4 ) state = PINX; break;
    case PINX: if ( count == 4 ) state = OPEN; break;
    case OPEN: if ( A == 11 ) state = LOCK; break;
  }
  switch( state )
  {
    case LOCK: B = 1; pin1 = 1, pin2 = 1, pin3 = 1, pin4 = 1; break;
    case PIN1: B = 0; pin2 += 1; break;
    case PIN2: B = 0; pin3 += 2; break;
    case PIN3: B = 0; pin4 += 3; count = 0; break;
    case PINX: B = 0; ++count; break;
    case OPEN: B = 2; break;
  }
  printf("Exit State = %s\n", debug[state]);
}

variable_types:
debug
char *[]


KeyboardISR

decompiled_code:
int KeyboardISR()
{
return Safe();
}

canonical_decompiled_code:
int func4()
{
return func3();
}

original_code:
void KeyboardISR()
{
  Safe();
}

canonical_original_code:
void KeyboardISR()
{
  Safe();
}


TimerISR

decompiled_code:
void TimerISR()
{
;
}

original_code:
void TimerISR()
{
}

canonical_original_code:
void TimerISR()
{
}


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

B = 1;
do
result = true_test(1LL, &unk_310);
while ( (_DWORD)result );
return result;
}

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

B = 1;
do
result = true_test(1LL, &unk_310);
while ( (_DWORD)result );
return result;
}

original_code:
int app_main(void)
{
   B = 1;
   while ( true_test(1, "1") )
   {
   }
   return 0;
}

canonical_original_code:
int app_main()
{
   B = 1;
   while ( true_test(1, "1") )
   {
   }
   return 0;
}


decompiled_code:
char BLINK_Tick()
{
char result; // al

result = BLINK_State;
if ( BLINK_State )
{
if ( BLINK_State != 1 || (result = A, A <= 5u) )
{
BLINK_State = 0;
LABEL_5:
B = 0;
return result;
}
}
else
{
result = A;
if ( A <= 5u )
goto LABEL_5;
BLINK_State = 1;
}
result = B == 0;
B = B == 0;
return result;
}

canonical_decompiled_code:
char func1()
{
char result; // al

result = BLINK_State;
if ( BLINK_State )
{
if ( BLINK_State != 1 || (result = A, A <= 5u) )
{
BLINK_State = 0;
LABEL_5:
B = 0;
return result;
}
}
else
{
result = A;
if ( A <= 5u )
goto LABEL_5;
BLINK_State = 1;
}
result = B == 0;
B = B == 0;
return result;
}

original_code:
void BLINK_Tick() {
   switch(BLINK_State) {
         case BLINK_OFF:
         if (A > 5) {
            BLINK_State = BLINK_BLINK;
         }
         break;
      case BLINK_BLINK:
         if (A <= 5) {
            BLINK_State = BLINK_OFF;
         }
         break;
      default:
         BLINK_State = BLINK_OFF;
   }
   switch(BLINK_State) {
      case BLINK_OFF:
         B = 0;
         break;
      case BLINK_BLINK:
         B = !B;
         break;
      default:
      break;
   }
}


decompiled_code:
void TimerISR()
{
BLINK_Clk = 1;
}

canonical_decompiled_code:
void func0()
{
BLINK_Clk = 1;
}

original_code:
void TimerISR() {
   BLINK_Clk = 1;
}

canonical_original_code:
void TimerISR() {
   BLINK_Clk = 1;
}


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

TimerSet(300LL);
TimerOn();
B = 0;
BLINK_State = -1;
while ( 1 )
{
result = true_test(1LL, "1");
if ( !(_DWORD)result )
break;
BLINK_Tick();
while ( (unsigned int)true_test(BLINK_Clk == 0, "!BLINK_Clk") )
;
BLINK_Clk = 0;
}
return result;
}

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

TimerSet(300LL);
TimerOn();
B = 0;
BLINK_State = -1;
while ( 1 )
{
result = true_test(1LL, "1");
if ( !(_DWORD)result )
break;
func1();
while ( (unsigned int)true_test(BLINK_Clk == 0, "!BLINK_Clk") )
;
BLINK_Clk = 0;
}
return result;
}

original_code:
int app_main(void)
{
  const unsigned int BLINK_Period = 300;
  TimerSet(BLINK_Period);
  TimerOn();
  BLINK_State = -1;
  B = 0;
  while ( true_test(1, "1") )
  {
    BLINK_Tick();
    while ( true_test(!BLINK_Clk, "!BLINK_Clk") )
      ;
    BLINK_Clk = 0;
  }
  return 0;
}

canonical_original_code:
int app_main()
{
  unsigned int BLINK_Period = 300;
  TimerSet(BLINK_Period);
  TimerOn();
  BLINK_State = -1;
  B = 0;
  while ( true_test(1, "1") )
  {
    BLINK_Tick();
    while ( true_test(!BLINK_Clk, "!BLINK_Clk") )
      ;
    BLINK_Clk = 0;
  }
  return 0;
}


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

result = A;
if ( A < 0 )
{
result = 0LL;
if ( blink_state != 2 )
result = (unsigned int)(blink_state + 1);
blink_state = result;
}
return result;
}

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

result = A;
if ( A < 0 )
{
result = 0LL;
if ( blink_state != 2 )
result = (unsigned int)(blink_state + 1);
blink_state = result;
}
return result;
}

original_code:
void button_press()
{
  byte A_READ = A & 128;
  if (A_READ)
    blink_state == ON ? blink_state = OFF : blink_state++;
}

canonical_original_code:
void button_press()
{
  unsigned char A_READ = A & 128;
  if (A_READ)
    blink_state == ON ? blink_state = OFF : blink_state++;
}


enable

decompiled_code:
__int64 enable()
{
__int64 result; // rax
int v1; // eax

result = (unsigned int)motion_state;
if ( motion_state == 2 )
{
v1 = lamp_state;
LOBYTE(v1) = lamp_state != 0;
result = (unsigned int)-v1;
B = result;
if ( (A & 0x7C) != 0 )
{
counter = 100;
return result;
}
}
else
{
if ( (unsigned int)motion_state <= 2 )
{
if ( motion_state )
{
if ( (A & 0x7C) != 0 )
{
motion_state = 2;
return result;
}
goto LABEL_8;
}
B = 0;
if ( (A & 0x7C) != 0 )
motion_state = 1;
return result;
}
if ( motion_state != 3 )
return result;
}
if ( !--counter )
LABEL_8:
motion_state = 0;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
int v1; // eax

result = (unsigned int)motion_state;
if ( motion_state == 2 )
{
v1 = lamp_state;
LOBYTE(v1) = lamp_state != 0;
result = (unsigned int)-v1;
B = result;
if ( (A & 0x7C) != 0 )
{
counter = 100;
return result;
}
}
else
{
if ( (unsigned int)motion_state <= 2 )
{
if ( motion_state )
{
if ( (A & 0x7C) != 0 )
{
motion_state = 2;
return result;
}
goto LABEL_8;
}
B = 0;
if ( (A & 0x7C) != 0 )
motion_state = 1;
return result;
}
if ( motion_state != 3 )
return result;
}
if ( !--counter )
LABEL_8:
motion_state = 0;
return result;
}

original_code:
void enable()
{
  byte A_READ = A & 127;
  switch(motion_state)
    {
    case SLEEP:
      B = 0;
      if (A_READ > 3)
 ++motion_state;
      break;
    case DATA:
      if (A_READ > 3)
 ++motion_state;
      else
 motion_state = SLEEP;
      break;
    case ROAD:
      B = (lamp_state) ? 255 : 0;
      if (A_READ > 3) {
 counter = 100;
 break;
      }
    case COUNTER:
      if (--counter == 0) {
 motion_state = SLEEP;
      }
      break;
    }
}

canonical_original_code:
void enable()
{
  unsigned char A_READ = A & 127;
  switch(motion_state)
    {
    case SLEEP:
      B = 0;
      if (A_READ > 3)
 ++motion_state;
      break;
    case DATA:
      if (A_READ > 3)
 ++motion_state;
      else
 motion_state = SLEEP;
      break;
    case ROAD:
      B = (lamp_state) ? 255 : 0;
      if (A_READ > 3) {
 counter = 100;
 break;
      }
    case COUNTER:
      if (--counter == 0) {
 motion_state = SLEEP;
      }
      break;
    }
}


toggle

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

if ( blink_state == 1 )
{
button_press();
lamp_state = lamp_state == 0;
result = enable();
}
else if ( blink_state == 2 )
{
button_press();
lamp_state = 1;
result = enable();
}
else
{
if ( blink_state )
{
blink_state = 0;
}
else
{
button_press();
lamp_state = 0;
}
counter = 0;
result = enable();
}
return result;
}

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

if ( blink_state == 1 )
{
func1();
lamp_state = lamp_state == 0;
result = func2();
}
else if ( blink_state == 2 )
{
func1();
lamp_state = 1;
result = func2();
}
else
{
if ( blink_state )
{
blink_state = 0;
}
else
{
func1();
lamp_state = 0;
}
counter = 0;
result = func2();
}
return result;
}

original_code:
void toggle()
{
  switch (blink_state) {
    case OFF:
      button_press();
      lamp_state = false;
      counter = 0;
      break;
    case BLINK:
      button_press();
      lamp_state = !lamp_state;
      break;
    case ON:
      button_press();
      lamp_state = true;
      break;
    default:
      blink_state = OFF;
      counter = 0;
      break;
  }
  enable();
}


TimerISR

decompiled_code:
void TimerISR()
{
T_FLAG = 1;
}

canonical_decompiled_code:
void func0()
{
T_FLAG = 1;
}

original_code:
void TimerISR() {
  T_FLAG = 1;
}

canonical_original_code:
void TimerISR() {
  T_FLAG = 1;
}


decompiled_code:
void __noreturn app_main()
{
TimerSet(100LL);
TimerOn();
B = 0;
blink_state = 0;
motion_state = 0;
counter = 0;
while ( 1 )
{
T_FLAG = 0;
toggle();
while ( (unsigned int)true_test(T_FLAG == 0, "!T_FLAG") )
;
}
}

canonical_decompiled_code:
void __noreturn func4()
{
TimerSet(100LL);
TimerOn();
B = 0;
blink_state = 0;
motion_state = 0;
counter = 0;
while ( 1 )
{
T_FLAG = 0;
func3();
while ( (unsigned int)true_test(T_FLAG == 0, "!T_FLAG") )
;
}
}

original_code:
int app_main(void)
{
  TimerSet(100);
  TimerOn();
  B = 0;
  blink_state = OFF;
  motion_state = SLEEP;
  counter = 0;
  T_FLAG = 0;
  for (;;)
  {
    toggle();
    while ( true_test(!T_FLAG, "!T_FLAG") )
      ;
    T_FLAG = 0;
  }
  return 0;
}

canonical_original_code:
int app_main()
{
  TimerSet(100);
  TimerOn();
  B = 0;
  blink_state = OFF;
  motion_state = SLEEP;
  counter = 0;
  T_FLAG = 0;
  for (;;)
  {
    toggle();
    while ( true_test(!T_FLAG, "!T_FLAG") )
      ;
    T_FLAG = 0;
  }
  return 0;
}


decompiled_code:
__int64 __fastcall find_router(_DWORD *a1, int a2)
{
__int64 result; // rax

for ( result = *(_QWORD *)routers; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)result == *a1
&& *(_DWORD *)(result + 4) == a1[1]
&& *(_DWORD *)(result + 8) == a1[2]
&& *(_DWORD *)(result + 12) == a1[3]
&& *(_DWORD *)(result + 24) == a2 )
{
break;
}
}
return result;
}

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

for ( result = *(_QWORD *)routers; result; result = *(_QWORD *)(result + 32) )
{
if ( *(_DWORD *)result == *a1
&& *(_DWORD *)(result + 4) == a1[1]
&& *(_DWORD *)(result + 8) == a1[2]
&& *(_DWORD *)(result + 12) == a1[3]
&& *(_DWORD *)(result + 24) == a2 )
{
break;
}
}
return result;
}

original_code:
static struct Router *
find_router(const struct in6_addr *addr, int if_index) {
    struct Router *iter;
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        if ((__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (&iter->addr); const struct in6_addr *__b = (const struct in6_addr *) (addr); __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; })) && iter->if_index == if_index)
            return iter;
    }
    return ((void *)0);
}

canonical_original_code:
static struct Router *find_router(struct in6_addr *addr, int if_index) {
    struct Router *iter;
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        if ((__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (&iter->addr); struct in6_addr *__b = (const struct in6_addr *) (addr); __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; })) && iter->if_index == if_index)
            return iter;
    }
    return ((void *)0);
}

variable_types:
addr
struct in6_addr *

variable_types: struct Router { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } addr; long valid_until; int if_index; struct { struct Router *sle_next; } entries; } *

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } *

user_defined_types: struct Router { struct in6_addr addr; long valid_until; int if_index; struct { struct Router *sle_next; } entries; }


decompiled_code:
void print_routers()
{
__int64 v0; // rbx
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
char v5[16]; // [rsp+0h] [rbp-48h] BYREF
char buf[56]; // [rsp+10h] [rbp-38h] BYREF

puts("Routers:");
v0 = *(_QWORD *)routers;
if ( *(_QWORD *)routers )
{
while ( 1 )
{
if ( !inet_ntop(10, (const void *)v0, buf, 0x2Eu) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "inet_ntop: %s", v2);
return;
}
if ( !if_indextoname(*(_DWORD *)(v0 + 24), v5) )
break;
printf("\t%s\t%ld\t%s\n", buf, *(_QWORD *)(v0 + 16), v5);
v0 = *(_QWORD *)(v0 + 32);
if ( !v0 )
return;
}
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "if_indextoname: %s", v4);
}
}

canonical_decompiled_code:
void func1()
{
__int64 v0; // rbx
int *v1; // rax
char *v2; // rax
int *v3; // rax
char *v4; // rax
char v5[16]; // [rsp+0h] [rbp-48h] BYREF
char buf[56]; // [rsp+10h] [rbp-38h] BYREF

puts("Routers:");
v0 = *(_QWORD *)routers;
if ( *(_QWORD *)routers )
{
while ( 1 )
{
if ( !inet_ntop(10, (const void *)v0, buf, 0x2Eu) )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "inet_ntop: %s", v2);
return;
}
if ( !if_indextoname(*(_DWORD *)(v0 + 24), v5) )
break;
printf("\t%s\t%ld\t%s\n", buf, *(_QWORD *)(v0 + 16), v5);
v0 = *(_QWORD *)(v0 + 32);
if ( !v0 )
return;
}
v3 = _errno_location();
v4 = strerror(*v3);
syslog(2, "if_indextoname: %s", v4);
}
}

original_code:
static void print_routers() {
    struct Router *iter;
    char addr_str[46];
    char if_name[16];
    printf("Routers:\n");
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        if (inet_ntop(10, &iter->addr, addr_str, sizeof(addr_str)) == ((void *)0)) {
            syslog(2, "inet_ntop: %s", strerror((*__errno_location ())));
            return;
        }
        if (if_indextoname(iter->if_index, if_name) == ((void *)0)) {
            syslog(2, "if_indextoname: %s", strerror((*__errno_location ())));
            return;
        }
        printf("\t%s\t%ld\t%s\n", addr_str, iter->valid_until, if_name);
    }
}

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
void __fastcall remove_router(void *ptr)
{
__int64 v1; // rcx
_QWORD *v2; // rax
_QWORD *v3; // rdx

v1 = *((_QWORD *)ptr + 4);
v2 = *(_QWORD **)routers;
if ( *(void **)routers == ptr )
{
*(_QWORD *)routers = v1;
}
else
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[4];
}
while ( v2 != ptr );
v3[4] = v1;
}
remove_gateway(ptr, *((unsigned int *)ptr + 6));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v1; // rcx
_QWORD *v2; // rax
_QWORD *v3; // rdx

v1 = *((_QWORD *)ptr + 4);
v2 = *(_QWORD **)routers;
if ( *(void **)routers == ptr )
{
*(_QWORD *)routers = v1;
}
else
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[4];
}
while ( v2 != ptr );
v3[4] = v1;
}
remove_gateway(ptr, *((unsigned int *)ptr + 6));
free(ptr);
}

original_code:
static void
remove_router(struct Router *router) {
    do { if ((routers)->slh_first == (router)) { do { ((routers))->slh_first = ((routers))->slh_first->entries.sle_next; } while ( 0); } else { struct Router *curelm = (routers)->slh_first; while(curelm->entries.sle_next != (router)) curelm = curelm->entries.sle_next; curelm->entries.sle_next = curelm->entries.sle_next->entries.sle_next; } } while ( 0);
    remove_gateway(&router->addr, router->if_index);
    free(router);
}


decompiled_code:
_QWORD *init_routers()
{
_QWORD *result; // rax
int *v1; // rax
char *v2; // rax

result = calloc(1uLL, 8uLL);
routers = (__int64)result;
if ( !result )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "calloc(): %s", v2);
exit(1);
}
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *result; // rax
int *v1; // rax
char *v2; // rax

result = calloc(1uLL, 8uLL);
routers = (__int64)result;
if ( !result )
{
v1 = _errno_location();
v2 = strerror(*v1);
syslog(2, "calloc(): %s", v2);
exit(1);
}
*result = 0LL;
return result;
}

original_code:
void
init_routers() {
    routers = calloc(1, sizeof(*routers));
    if (routers == ((void *)0)) {
        syslog(2, "calloc(): %s", strerror((*__errno_location ())));
        exit(1);
    }
    do { (routers)->slh_first = ((void *)0); } while ( 0);
}


decompiled_code:
__int64 __fastcall update_router(__m128i *a1, unsigned __int32 a2, __int64 a3)
{
__int64 result; // rax

result = find_router(a1, a2);
if ( !result )
result = (__int64)add_router(a1, a2);
*(_QWORD *)(result + 16) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__m128i *a1, unsigned __int32 a2, __int64 a3)
{
__int64 result; // rax

result = func0(a1, a2);
if ( !result )
result = (__int64)add_router(a1, a2);
*(_QWORD *)(result + 16) = a3;
return result;
}

original_code:
void
update_router(const struct in6_addr *addr, int if_index, time_t valid_until) {
    struct Router *r;
    r = find_router(addr, if_index);
    if (r == ((void *)0))
        r = add_router(addr, if_index);
    r->valid_until = valid_until;
}

canonical_original_code:
void update_router(struct in6_addr *addr, int if_index, long valid_until) {
    struct Router *r;
    r = find_router(addr, if_index);
    if (r == ((void *)0))
        r = add_router(addr, if_index);
    r->valid_until = valid_until;
}


decompiled_code:
void handle_routers()
{
_QWORD *v0; // rbx
_QWORD *v1; // rdi
time_t timer; // [rsp+8h] [rbp-10h] BYREF

print_routers();
time(&timer);
v0 = *(_QWORD **)routers;
if ( *(_QWORD *)routers )
{
do
{
while ( 1 )
{
v1 = v0;
v0 = (_QWORD *)v0[4];
if ( v1[2] < timer )
break;
if ( !v0 )
return;
}
remove_router(v1);
}
while ( v0 );
}
}

canonical_decompiled_code:
void func5()
{
_QWORD *v0; // rbx
_QWORD *v1; // rdi
time_t timer; // [rsp+8h] [rbp-10h] BYREF

func1();
time(&timer);
v0 = *(_QWORD **)routers;
if ( *(_QWORD *)routers )
{
do
{
while ( 1 )
{
v1 = v0;
v0 = (_QWORD *)v0[4];
if ( v1[2] < timer )
break;
if ( !v0 )
return;
}
func2(v1);
}
while ( v0 );
}
}

original_code:
void
handle_routers() {
    struct Router *iter, *temp;
    time_t now;
    print_routers();
    time(&now);
    for ((iter) = (((routers))->slh_first); (iter) && ((temp) = (((iter))->entries.sle_next), 1); (iter) = (temp)) {
        if (iter->valid_until < now)
            remove_router(iter);
    }
}

canonical_original_code:
void handle_routers() {
    struct Router *iter; struct Router *temp;
    long now;
    print_routers();
    time(&now);
    for ((iter) = (((routers))->slh_first); (iter) && ((temp) = (((iter))->entries.sle_next), 1); (iter) = (temp)) {
        if (iter->valid_until < now)
            remove_router(iter);
    }
}

variable_types: now long


decompiled_code:
time_t next_timeout()
{
time_t v0; // rdx
__int64 v1; // rax
time_t v2; // rcx
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v0 = time(&timer) + 3600;
v1 = *(_QWORD *)routers;
while ( v1 )
{
v2 = *(_QWORD *)(v1 + 16);
v1 = *(_QWORD *)(v1 + 32);
if ( v0 > v2 )
v0 = v2;
}
return v0 - timer;
}

canonical_decompiled_code:
time_t func6()
{
time_t v0; // rdx
__int64 v1; // rax
time_t v2; // rcx
time_t timer; // [rsp+8h] [rbp-10h] BYREF

v0 = time(&timer) + 3600;
v1 = *(_QWORD *)routers;
while ( v1 )
{
v2 = *(_QWORD *)(v1 + 16);
v1 = *(_QWORD *)(v1 + 32);
if ( v0 > v2 )
v0 = v2;
}
return v0 - timer;
}

original_code:
time_t
next_timeout() {
    struct Router *iter;
    time_t now, min_valid_until;
    min_valid_until = time(&now) + 3600;
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        min_valid_until = ((min_valid_until) > (iter->valid_until) ? (iter->valid_until) : (min_valid_until));
    }
    return min_valid_until - now;
}

canonical_original_code:
long next_timeout() {
    struct Router *iter;
    long now; long min_valid_until;
    min_valid_until = time(&now) + 3600;
    for((iter) = (routers)->slh_first; (iter); (iter) = (iter)->entries.sle_next) {
        min_valid_until = ((min_valid_until) > (iter->valid_until) ? (iter->valid_until) : (min_valid_until));
    }
    return min_valid_until - now;
}

return_type: long


usage

decompiled_code:
size_t usage()
{
return fwrite(
"Usage: routeradv_listend [-f] [-i <interface>]\n"
" -f run in foreground\n"
" -i specify an interface to listen on\n",
1uLL,
0x73uLL,
stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"Usage: routeradv_listend [-f] [-i <interface>]\n"
" -f run in foreground\n"
" -i specify an interface to listen on\n",
1uLL,
0x73uLL,
stderr);
}

original_code:
static void
usage() {
    fprintf(stderr, "Usage: routeradv_listend [-f] [-i <interface>]\n"
                    "    -f  run in foreground\n"
                    "    -i  specify an interface to listen on\n");
}