decompiled_code:
__int64 __fastcall array_base_type(__int64 a1)
{
__int64 v1; // rdx

v1 = 0LL;
if ( (unsigned int)(*(_DWORD *)(a1 + 24) - 5) <= 1 )
v1 = first_node(a1 + 192);
return v1;
}

original_code:
static node_t *
array_base_type(node_t *type)
{
 return (type->t.category == type_pointer ||
  type->t.category == type_array)
  ? first_node(&type->child[cht_type])
  : ((void *)0);
}

canonical_original_code:
static struct node *array_base_type(struct node *type)
{
 return (type->t.category == type_pointer ||
  type->t.category == type_array)
  ? first_node(&type->child[cht_type])
  : ((void *)0);
}

user_defined_types: struct pos_t { struct parsed_file *pf; int line; unsigned short column; struct dynstr *text; }


repo: ptesarik/xcrash-scripts

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

result = 0LL;
if ( *(_DWORD *)(a1 + 24) == 7 )
result = first_node(a1 + 192);
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 24) == 7 )
result = func0(a1 + 192);
return result;
}

original_code:
static node_t *
func_return_type(node_t *type)
{
 return (type->t.category == type_func)
  ? first_node(&type->child[cht_type])
  : ((void *)0);
}

canonical_original_code:
static struct node *func_return_type(struct node *type)
{
 return (type->t.category == type_func)
  ? first_node(&type->child[cht_type])
  : ((void *)0);
}

variable_types:
type
struct node *

return_type: struct node { struct list_head_xcrash { struct list_head_xcrash *next; } list; enum node_type { nt_type=0, nt_expr=1, nt_var=2, nt_decl=3 } type; union { struct type { enum type_category { type_basic=0, type_typedef=1, type_struct=2, type_union=3, type_enum=4, type_pointer=5, type_array=6, type_func=7, type_typeof=8 } category; unsigned int flags; unsigned long btype; } t; struct expr { int op; union { long num; double f; }; } e; }; struct dynstr { struct list_head_xcrash list; struct list_head_xcrash node_first; struct list_head_xcrash dup_list; struct node *cpp_cond; struct macro_exp { int refcount; struct hashed_macro { struct hashed_macro *next; char *name; struct list_head_xcrash params; int nparams; struct node *cpp_cond; struct loc { struct pos_t { struct parsed_file { char *name; struct list_head_xcrash parsed; struct list_head_xcrash raw; struct loc loc; int clean; } *pf; int line; unsigned short column; struct dynstr *text; } first; struct loc *parent; } loc; int undef; int hidden; int hasparam; int isparam; int noexpand; int variadic; } *hm; struct dynstr *first; struct dynstr *exp_first; struct { struct dynstr *first; } params[]; } *exp; int token; int refcount; union dynstr_flags_t { struct { int fake; int macro; }; unsigned int val; } flags; unsigned long len; char text[]; } *str; struct node *parent; struct list_head_xcrash dup_list; struct loc loc; struct list_head_xcrash first_list; struct list_head_xcrash user_list; void *user_data; int nchild; struct list_head_xcrash child[]; } *

user_defined_types: struct node { struct list_head_xcrash list; enum node_type type; union { struct type t; struct expr e; }; struct dynstr *str; struct node *parent; struct list_head_xcrash dup_list; struct loc loc; struct list_head_xcrash first_list; struct list_head_xcrash user_list; void *user_data; int nchild; struct list_head_xcrash child[]; }

user_defined_types: struct type { enum type_category category; unsigned int flags; unsigned long btype; }

user_defined_types: struct dynstr { struct list_head_xcrash list; struct list_head_xcrash node_first; struct list_head_xcrash dup_list; struct node *cpp_cond; struct macro_exp *exp; int token; int refcount; union dynstr_flags_t flags; unsigned long len; char text[]; }

user_defined_types: struct macro_exp { int refcount; struct hashed_macro *hm; struct dynstr *first; struct dynstr *exp_first; struct { struct dynstr *first; } params[]; }

user_defined_types: struct hashed_macro { struct hashed_macro *next; char *name; struct list_head_xcrash params; int nparams; struct node *cpp_cond; struct loc loc; int undef; int hidden; int hasparam; int isparam; int noexpand; int variadic; }

user_defined_types: struct loc { struct pos_t first; struct loc *parent; }


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

result = *(_QWORD *)(a1 + 48);
if ( result )
{
result = *(_QWORD *)(result + 48);
if ( result )
{
result = varscope_find(result + 240, 2LL, a2);
if ( result )
result = nth_node(result + 192, 1LL);
}
}
return result;
}

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

result = *(_QWORD *)(a1 + 48);
if ( result )
{
result = *(_QWORD *)(result + 48);
if ( result )
{
result = varscope_find(result + 240, 2LL, a2);
if ( result )
result = nth_node(result + 192, 1LL);
}
}
return result;
}

original_code:
static node_t *
kr_param_type(node_t *fntype, const char *name)
{
 node_t *fnvar, *fndecl;
 if (! (fnvar = fntype->parent) )
  return ((void *)0);
 if (! (fndecl = fnvar->parent) )
  return ((void *)0);
 node_t *var = varscope_find(&fndecl->child[chd_body], nt_var, name);
 if (!var)
  return ((void *)0);
 return nth_node(&var->child[chv_type], 1);
}

canonical_original_code:
static struct node *kr_param_type(struct node *fntype, char *name)
{
 struct node *fnvar; struct node *fndecl;
 if (! (fnvar = fntype->parent) )
  return ((void *)0);
 if (! (fndecl = fnvar->parent) )
  return ((void *)0);
 struct node *var = varscope_find(&fndecl->child[chd_body], nt_var, name);
 if (!var)
  return ((void *)0);
 return nth_node(&var->child[chv_type], 1);
}

variable_types:
fntype
struct node *

variable_types:
name
char *

variable_types: struct node { struct list_head_xcrash { struct list_head_xcrash *next; } list; enum node_type { nt_type=0, nt_expr=1, nt_var=2, nt_decl=3 } type; union { struct type { enum type_category { type_basic=0, type_typedef=1, type_struct=2, type_union=3, type_enum=4, type_pointer=5, type_array=6, type_func=7, type_typeof=8 } category; unsigned int flags; unsigned long btype; } t; struct expr { int op; union { long num; double f; }; } e; }; struct dynstr { struct list_head_xcrash list; struct list_head_xcrash node_first; struct list_head_xcrash dup_list; struct node *cpp_cond; struct macro_exp { int refcount; struct hashed_macro { struct hashed_macro *next; char *name; struct list_head_xcrash params; int nparams; struct node *cpp_cond; struct loc { struct pos_t { struct parsed_file { char *name; struct list_head_xcrash parsed; struct list_head_xcrash raw; struct loc loc; int clean; } *pf; int line; unsigned short column; struct dynstr *text; } first; struct loc *parent; } loc; int undef; int hidden; int hasparam; int isparam; int noexpand; int variadic; } *hm; struct dynstr *first; struct dynstr *exp_first; struct { struct dynstr *first; } params[]; } *exp; int token; int refcount; union dynstr_flags_t { struct { int fake; int macro; }; unsigned int val; } flags; unsigned long len; char text[]; } *str; struct node *parent; struct list_head_xcrash dup_list; struct loc loc; struct list_head_xcrash first_list; struct list_head_xcrash user_list; void *user_data; int nchild; struct list_head_xcrash child[]; } *


decompiled_code:
__int64 __fastcall func_arg_type(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // r12

result = nth_node(a1 + 208, a2);
v3 = result;
if ( result )
{
if ( *(_DWORD *)(result + 16) != 3 )
_assert_fail("decl->type == nt_decl", "indirect.c", 0x48u, "func_arg_type");
v4 = result + 192;
result = first_node(result + 192);
if ( v4 == result )
{
v5 = first_node(v3 + 208);
v6 = v5;
if ( v3 + 208 == v5 )
_assert_fail("&var->list != &decl->child[chd_var]", "indirect.c", 0x4Fu, "func_arg_type");
v7 = v5 + 192;
result = first_node(v5 + 192);
if ( v7 == result )
result = kr_param_type(*(_QWORD *)(v3 + 48), *(_QWORD *)(v6 + 40) + 112LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // r12

result = nth_node(a1 + 208, a2);
v3 = result;
if ( result )
{
if ( *(_DWORD *)(result + 16) != 3 )
_assert_fail("decl->type == nt_decl", "indirect.c", 0x48u, "func_arg_type");
v4 = result + 192;
result = func0(result + 192);
if ( v4 == result )
{
v5 = func0(v3 + 208);
v6 = v5;
if ( v3 + 208 == v5 )
_assert_fail("&var->list != &decl->child[chd_var]", "indirect.c", 0x4Fu, "func_arg_type");
v7 = v5 + 192;
result = func0(v5 + 192);
if ( v7 == result )
result = func4(*(_QWORD *)(v3 + 48), *(_QWORD *)(v6 + 40) + 112LL);
}
}
return result;
}

original_code:
static node_t *
func_arg_type(node_t *type, int pos)
{
 node_t *decl = nth_node(&type->child[cht_param], pos);
 if (!decl)
  return ((void *)0);
 ((void) sizeof ((decl->type == nt_decl) ? 1 : 0), __extension__ ({ if (decl->type == nt_decl) ; else __assert_fail ("decl->type == nt_decl", "indirect.c", 72, __extension__ __PRETTY_FUNCTION__); }));
 type = first_node(&decl->child[chd_type]);
 if (&type->list != &decl->child[chd_type])
  return type;
 node_t *var = first_node(&decl->child[chd_var]);
 ((void) sizeof ((&var->list != &decl->child[chd_var]) ? 1 : 0), __extension__ ({ if (&var->list != &decl->child[chd_var]) ; else __assert_fail ("&var->list != &decl->child[chd_var]", "indirect.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 type = first_node(&var->child[chv_type]);
 if (&type->list != &var->child[chv_type])
  return type;
 if ( (type = kr_param_type(decl->parent, var->str->text)) )
  return type;
 return ((void *)0);
}

canonical_original_code:
static struct node *func_arg_type(struct node *type, int pos)
{
 struct node *decl = nth_node(&type->child[cht_param], pos);
 if (!decl)
  return ((void *)0);
 ((void) sizeof ((decl->type == nt_decl) ? 1 : 0), __extension__ ({ if (decl->type == nt_decl) ; else __assert_fail ("decl->type == nt_decl", "indirect.c", 72, __extension__ __PRETTY_FUNCTION__); }));
 type = first_node(&decl->child[chd_type]);
 if (&type->list != &decl->child[chd_type])
  return type;
 struct node *var = first_node(&decl->child[chd_var]);
 ((void) sizeof ((&var->list != &decl->child[chd_var]) ? 1 : 0), __extension__ ({ if (&var->list != &decl->child[chd_var]) ; else __assert_fail ("&var->list != &decl->child[chd_var]", "indirect.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 type = first_node(&var->child[chv_type]);
 if (&type->list != &var->child[chv_type])
  return type;
 if ( (type = kr_param_type(decl->parent, var->str->text)) )
  return type;
 return ((void *)0);
}

variable_types: pos int

user_defined_types: struct list_head_xcrash { struct list_head_xcrash *next; }

user_defined_types: enum node_type { nt_type=0, nt_expr=1, nt_var=2, nt_decl=3 }

user_defined_types: struct expr { int op; union { long num; double f; }; }

user_defined_types: enum type_category { type_basic=0, type_typedef=1, type_struct=2, type_union=3, type_enum=4, type_pointer=5, type_array=6, type_func=7, type_typeof=8 }

user_defined_types: union dynstr_flags_t { struct { int fake; int macro; }; unsigned int val; }

user_defined_types: struct parsed_file { char *name; struct list_head_xcrash parsed; struct list_head_xcrash raw; struct loc loc; int clean; }


decompiled_code:
__int64 __fastcall build_ind(__int64 a1, char **a2)
{
__int64 result; // rax
char v3; // cl
char *v4; // rdi
int v5; // edx

if ( *(_DWORD *)(a1 + 16) )
_assert_fail("type->type == nt_type", "indirect.c", 0xEu, "build_ind");
for ( result = *(_QWORD *)(a1 + 48); !*(_DWORD *)(result + 16); result = *(_QWORD *)(result + 48) )
{
v5 = *(_DWORD *)(result + 24);
if ( (unsigned int)(v5 - 5) <= 1 )
{
v3 = -1;
}
else
{
if ( v5 != 7 )
_assert_fail("0", "indirect.c", 0x19u, "build_ind");
v3 = -2;
}
if ( a2 )
{
v4 = *a2 - 1;
*a2 = v4;
*v4 = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char **a2)
{
__int64 result; // rax
char v3; // cl
char *v4; // rdi
int v5; // edx

if ( *(_DWORD *)(a1 + 16) )
_assert_fail("type->type == nt_type", "indirect.c", 0xEu, "build_ind");
for ( result = *(_QWORD *)(a1 + 48); !*(_DWORD *)(result + 16); result = *(_QWORD *)(result + 48) )
{
v5 = *(_DWORD *)(result + 24);
if ( (unsigned int)(v5 - 5) <= 1 )
{
v3 = -1;
}
else
{
if ( v5 != 7 )
_assert_fail("0", "indirect.c", 0x19u, "build_ind");
v3 = -2;
}
if ( a2 )
{
v4 = *a2 - 1;
*a2 = v4;
*v4 = v3;
}
}
return result;
}

original_code:
node_t *
build_ind(node_t *type, ind_t **indp)
{
 ((void) sizeof ((type->type == nt_type) ? 1 : 0), __extension__ ({ if (type->type == nt_type) ; else __assert_fail ("type->type == nt_type", "indirect.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 node_t *parent;
 while ((parent = type->parent)->type == nt_type) {
  ind_t ind;
  if (parent->t.category == type_pointer ||
      parent->t.category == type_array)
   ind = ind_pointer;
  else if (parent->t.category == type_func)
   ind = ind_return;
  else
   ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "indirect.c", 25, __extension__ __PRETTY_FUNCTION__); }));
  if (indp)
   *(--*indp) = ind;
  type = parent;
 }
 return parent;
}

canonical_original_code:
struct node *build_ind(struct node *type, char **indp)
{
 ((void) sizeof ((type->type == nt_type) ? 1 : 0), __extension__ ({ if (type->type == nt_type) ; else __assert_fail ("type->type == nt_type", "indirect.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 struct node *parent;
 while ((parent = type->parent)->type == nt_type) {
  char ind;
  if (parent->t.category == type_pointer ||
      parent->t.category == type_array)
   ind = ind_pointer;
  else if (parent->t.category == type_func)
   ind = ind_return;
  else
   ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "indirect.c", 25, __extension__ __PRETTY_FUNCTION__); }));
  if (indp)
   *(--*indp) = ind;
  type = parent;
 }
 return parent;
}

variable_types:
indp
char **

variable_types: ind char


decompiled_code:
__int64 __fastcall ind_base_type(__int64 a1, char *a2)
{
char *v3; // r12
char i; // bp

v3 = a2;
for ( i = *a2; *v3; i = *++v3 )
{
if ( ind_is_pointer(i) )
{
a1 = array_base_type(a1);
}
else if ( i == -2 )
{
a1 = func_return_type(a1);
}
else
{
if ( !v3 )
_assert_fail("ind > 0", "indirect.c", 0x64u, "ind_base_type");
a1 = func_arg_type(a1, (unsigned int)i);
}
if ( !a1 )
break;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2)
{
char *v3; // r12
char i; // bp

v3 = a2;
for ( i = *a2; *v3; i = *++v3 )
{
if ( func1(i) )
{
a1 = func2(a1);
}
else if ( i == -2 )
{
a1 = func3(a1);
}
else
{
if ( !v3 )
_assert_fail("ind > 0", "indirect.c", 0x64u, "ind_base_type");
a1 = func5(a1, (unsigned int)i);
}
if ( !a1 )
break;
}
return a1;
}

original_code:
node_t *
ind_base_type(node_t *type, const ind_t *ind)
{
 while (*ind != ind_stop) {
  if (ind_is_pointer(*ind))
   type = array_base_type(type);
  else if (*ind == ind_return)
   type = func_return_type(type);
  else {
   ((void) sizeof ((ind > 0) ? 1 : 0), __extension__ ({ if (ind > 0) ; else __assert_fail ("ind > 0", "indirect.c", 100, __extension__ __PRETTY_FUNCTION__); }));
   type = func_arg_type(type, *ind);
  }
  if (!type)
   break;
  ++ind;
 }
 return type;
}

canonical_original_code:
struct node *ind_base_type(struct node *type, char *ind)
{
 while (*ind != ind_stop) {
  if (ind_is_pointer(*ind))
   type = array_base_type(type);
  else if (*ind == ind_return)
   type = func_return_type(type);
  else {
   ((void) sizeof ((ind > 0) ? 1 : 0), __extension__ ({ if (ind > 0) ; else __assert_fail ("ind > 0", "indirect.c", 100, __extension__ __PRETTY_FUNCTION__); }));
   type = func_arg_type(type, *ind);
  }
  if (!type)
   break;
  ++ind;
 }
 return type;
}

variable_types:
ind
char *


decompiled_code:
__int64 __fastcall is_host_type(__int64 a1, char *a2)
{
__int64 v3; // rcx
__int64 result; // rax
_BOOL4 v5; // edx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdi
int v10; // edx
__int64 v11; // rdi
__int64 v12; // rdi
int v13; // edx
__int64 v14; // rax
__int64 v15; // rdi
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax

v3 = *(unsigned int *)(a1 + 24);
if ( (int)v3 > 126 )
{
if ( (unsigned int)(v3 - 269) <= 0x49 )
{
switch ( (int)v3 )
{
case 269:
case 270:
goto LABEL_11;
case 273:
case 321:
goto LABEL_20;
case 280:
v5 = ind_is_pointer(*a2);
result = 1LL;
if ( v5 )
{
v6 = first_node(a1 + 192);
result = is_host_type(v6, a2 + 1);
}
return result;
case 281:
case 335:
v7 = first_node(a1 + 192);
*(a2 - 1) = -1;
return is_host_type(v7, a2 - 1);
case 299:
case 317:
case 318:
case 319:
case 341:
return 0LL;
case 320:
return 1LL;
case 338:
v17 = first_node(a1 + 192);
v18 = varscope_find_expr(v17);
if ( !v18 )
return 1LL;
v19 = first_node(v18 + 192);
if ( *(_DWORD *)(v19 + 24) != 7 )
_assert_fail("type->t.category == type_func", "indirect.c", 0xC9u, "is_host_type");
v15 = nth_node(v19 + 192, 1LL);
if ( !v15 )
return 1LL;
break;
case 342:
v11 = nth_node(a1 + 208, 1LL);
result = 0LL;
if ( v11 )
goto LABEL_25;
return result;
default:
goto LABEL_5;
}
LABEL_22:
v16 = ind_base_type(v15, a2);
if ( v16 )
result = (unsigned int)(*(_DWORD *)(v16 + 24) - 5) <= 1;
else
result = 1LL;
return result;
}
LABEL_5:
fprintf(stderr, "%s: Operator %d not yet handled\n", "is_host_type", v3);
return 1LL;
}
if ( (int)v3 <= 32 )
goto LABEL_5;
switch ( (int)v3 )
{
case '!':
return 1LL;
case '%':
case '/':
case '~':
LABEL_11:
v8 = first_node(a1 + 192);
return is_host_type(v8, a2);
case '&':
case '*':
case '+':
case '-':
case '^':
case '|':
v9 = nth_node(a1 + 192, 1LL);
if ( !v9 || (v10 = is_host_type(v9, a2), result = 1LL, !v10) )
{
v11 = nth_node(a1 + 208, 1LL);
result = 0LL;
if ( v11 )
goto LABEL_25;
}
return result;
case '.':
LABEL_20:
v14 = varscope_find_expr(a1);
if ( v14 )
{
v15 = first_node(v14 + 192);
goto LABEL_22;
}
result = 1LL;
break;
case '?':
v12 = nth_node(a1 + 224, 1LL);
if ( !v12 || (v13 = is_host_type(v12, a2), result = 1LL, !v13) )
{
v11 = nth_node(a1 + 208, 1LL);
result = 0LL;
if ( v11 )
LABEL_25:
result = (unsigned int)is_host_type(v11, a2) != 0;
}
return result;
default:
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2)
{
__int64 v3; // rcx
__int64 result; // rax
_BOOL4 v5; // edx
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdi
int v10; // edx
__int64 v11; // rdi
__int64 v12; // rdi
int v13; // edx
__int64 v14; // rax
__int64 v15; // rdi
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
__int64 v19; // rax

v3 = *(unsigned int *)(a1 + 24);
if ( (int)v3 > 126 )
{
if ( (unsigned int)(v3 - 269) <= 0x49 )
{
switch ( (int)v3 )
{
case 269:
case 270:
goto LABEL_11;
case 273:
case 321:
goto LABEL_20;
case 280:
v5 = func1(*a2);
result = 1LL;
if ( v5 )
{
v6 = func0(a1 + 192);
result = func8(v6, a2 + 1);
}
return result;
case 281:
case 335:
v7 = func0(a1 + 192);
*(a2 - 1) = -1;
return func8(v7, a2 - 1);
case 299:
case 317:
case 318:
case 319:
case 341:
return 0LL;
case 320:
return 1LL;
case 338:
v17 = func0(a1 + 192);
v18 = varscope_find_expr(v17);
if ( !v18 )
return 1LL;
v19 = func0(v18 + 192);
if ( *(_DWORD *)(v19 + 24) != 7 )
_assert_fail("type->t.category == type_func", "indirect.c", 0xC9u, "is_host_type");
v15 = nth_node(v19 + 192, 1LL);
if ( !v15 )
return 1LL;
break;
case 342:
v11 = nth_node(a1 + 208, 1LL);
result = 0LL;
if ( v11 )
goto LABEL_25;
return result;
default:
goto LABEL_5;
}
LABEL_22:
v16 = func7(v15, a2);
if ( v16 )
result = (unsigned int)(*(_DWORD *)(v16 + 24) - 5) <= 1;
else
result = 1LL;
return result;
}
LABEL_5:
fprintf(stderr, "%s: Operator %d not yet handled\n", "is_host_type", v3);
return 1LL;
}
if ( (int)v3 <= 32 )
goto LABEL_5;
switch ( (int)v3 )
{
case '!':
return 1LL;
case '%':
case '/':
case '~':
LABEL_11:
v8 = func0(a1 + 192);
return func8(v8, a2);
case '&':
case '*':
case '+':
case '-':
case '^':
case '|':
v9 = nth_node(a1 + 192, 1LL);
if ( !v9 || (v10 = func8(v9, a2), result = 1LL, !v10) )
{
v11 = nth_node(a1 + 208, 1LL);
result = 0LL;
if ( v11 )
goto LABEL_25;
}
return result;
case '.':
LABEL_20:
v14 = varscope_find_expr(a1);
if ( v14 )
{
v15 = func0(v14 + 192);
goto LABEL_22;
}
result = 1LL;
break;
case '?':
v12 = nth_node(a1 + 224, 1LL);
if ( !v12 || (v13 = func8(v12, a2), result = 1LL, !v13) )
{
v11 = nth_node(a1 + 208, 1LL);
result = 0LL;
if ( v11 )
LABEL_25:
result = (unsigned int)func8(v11, a2) != 0;
}
return result;
default:
goto LABEL_5;
}
return result;
}

original_code:
int
is_host_type(node_t *expr, ind_t *ind)
{
 node_t *child, *var, *type;
 switch (expr->e.op) {
 case INT_CONST:
 case FLOAT_CONST:
 case CHAR_CONST:
  return 0;
 case '!':
 case STRING_CONST:
  return 1;
 case ADDR_OF:
  child = first_node(&expr->child[che_arg1]);
  if (!ind_is_pointer(*ind))
   return 1;
  ++ind;
  return is_host_type(child, ind);
 case DEREF_OP:
 case ARRAY:
  child = first_node(&expr->child[che_arg1]);
  *--ind = ind_pointer;
  return is_host_type(child, ind);
 case '~':
 case '/':
 case '%':
 case SHL_OP:
 case SHR_OP:
  child = first_node(&expr->child[che_arg1]);
  return is_host_type(child, ind);
 case '&':
 case '|':
 case '^':
 case '*':
 case '+':
 case '-':
  child = nth_node(&expr->child[che_arg1], 1);
  if (child && is_host_type(child, ind))
   return 1;
  child = nth_node(&expr->child[che_arg2], 1);
  if (child && is_host_type(child, ind))
   return 1;
  return 0;
 case '?':
  child = nth_node(&expr->child[che_arg3], 1);
  if (child && is_host_type(child, ind))
   return 1;
  child = nth_node(&expr->child[che_arg2], 1);
  if (child && is_host_type(child, ind))
   return 1;
  return 0;
 case SIZEOF_TYPE:
 case SIZEOF:
  return 0;
 case ID:
 case '.':
 case PTR_OP:
  if (! (var = varscope_find_expr(expr)) )
   return 1;
  type = first_node(&var->child[chv_type]);
  break;
 case TYPECAST:
  child = nth_node(&expr->child[che_arg2], 1);
  if (child && is_host_type(child, ind))
   return 1;
  return 0;
 case FUNC:
  child = first_node(&expr->child[che_arg1]);
  if (! (var = varscope_find_expr(child)) )
   return 1;
  type = first_node(&var->child[chv_type]);
  ((void) sizeof ((type->t.category == type_func) ? 1 : 0), __extension__ ({ if (type->t.category == type_func) ; else __assert_fail ("type->t.category == type_func", "indirect.c", 201, __extension__ __PRETTY_FUNCTION__); }));
  if (! (type = nth_node(&type->child[cht_type], 1)) )
   return 1;
  break;
 default:
  fprintf(stderr, "%s: Operator %d not yet handled\n",
   __FUNCTION__, expr->e.op);
  return 1;
 }
 if (! (type = ind_base_type(type, ind)) )
  return 1;
 if (type->t.category == type_pointer ||
     type->t.category == type_array)
  return 1;
 return 0;
}

canonical_original_code:
int is_host_type(struct node *expr, char *ind)
{
 struct node *child; struct node *var; struct node *type;
 switch (expr->e.op) {
 case INT_CONST:
 case FLOAT_CONST:
 case CHAR_CONST:
  return 0;
 case '!':
 case STRING_CONST:
  return 1;
 case ADDR_OF:
  child = first_node(&expr->child[che_arg1]);
  if (!ind_is_pointer(*ind))
   return 1;
  ++ind;
  return is_host_type(child, ind);
 case DEREF_OP:
 case ARRAY:
  child = first_node(&expr->child[che_arg1]);
  *--ind = ind_pointer;
  return is_host_type(child, ind);
 case '~':
 case '/':
 case '%':
 case SHL_OP:
 case SHR_OP:
  child = first_node(&expr->child[che_arg1]);
  return is_host_type(child, ind);
 case '&':
 case '|':
 case '^':
 case '*':
 case '+':
 case '-':
  child = nth_node(&expr->child[che_arg1], 1);
  if (child && is_host_type(child, ind))
   return 1;
  child = nth_node(&expr->child[che_arg2], 1);
  if (child && is_host_type(child, ind))
   return 1;
  return 0;
 case '?':
  child = nth_node(&expr->child[che_arg3], 1);
  if (child && is_host_type(child, ind))
   return 1;
  child = nth_node(&expr->child[che_arg2], 1);
  if (child && is_host_type(child, ind))
   return 1;
  return 0;
 case SIZEOF_TYPE:
 case SIZEOF:
  return 0;
 case ID:
 case '.':
 case PTR_OP:
  if (! (var = varscope_find_expr(expr)) )
   return 1;
  type = first_node(&var->child[chv_type]);
  break;
 case TYPECAST:
  child = nth_node(&expr->child[che_arg2], 1);
  if (child && is_host_type(child, ind))
   return 1;
  return 0;
 case FUNC:
  child = first_node(&expr->child[che_arg1]);
  if (! (var = varscope_find_expr(child)) )
   return 1;
  type = first_node(&var->child[chv_type]);
  ((void) sizeof ((type->t.category == type_func) ? 1 : 0), __extension__ ({ if (type->t.category == type_func) ; else __assert_fail ("type->t.category == type_func", "indirect.c", 201, __extension__ __PRETTY_FUNCTION__); }));
  if (! (type = nth_node(&type->child[cht_type], 1)) )
   return 1;
  break;
 default:
  fprintf(stderr, "%s: Operator %d not yet handled\n",
   __FUNCTION__, expr->e.op);
  return 1;
 }
 if (! (type = ind_base_type(type, ind)) )
  return 1;
 if (type->t.category == type_pointer ||
     type->t.category == type_array)
  return 1;
 return 0;
}

return_type: int


socketHandler

repo: pthrasher/fido

decompiled_code:
void *__fastcall socketHandler(void *a1)
{
int *v1; // rbx
__int64 v2; // rbp
int v4; // [rsp+0h] [rbp-28h] BYREF
char v5; // [rsp+4h] [rbp-24h]
int buf; // [rsp+8h] [rbp-20h] BYREF
char v7; // [rsp+Ch] [rbp-1Ch]

v1 = *(int **)a1;
v2 = *((_QWORD *)a1 + 1);
while ( (int)recv(*v1, &buf, 5uLL, 0) > 0 )
{
v4 = buf;
v5 = 101;
switch ( v7 )
{
case 'r':
v5 = (unsigned __int8)bit_array_test(v2) == 0 ? 117 : 115;
break;
case 's':
bit_array_set_true(v2);
v5 = 115;
break;
case 'u':
bit_array_set_false(v2);
v5 = 117;
break;
}
send(*v1, &v4, 5uLL, 0);
}
shutdown(*v1, 1);
close(*v1);
free(v1);
puts("Lost a connection.");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
int *v1; // rbx
__int64 v2; // rbp
int v4; // [rsp+0h] [rbp-28h] BYREF
char v5; // [rsp+4h] [rbp-24h]
int buf; // [rsp+8h] [rbp-20h] BYREF
char v7; // [rsp+Ch] [rbp-1Ch]

v1 = *(int **)a1;
v2 = *((_QWORD *)a1 + 1);
while ( (int)recv(*v1, &buf, 5uLL, 0) > 0 )
{
v4 = buf;
v5 = 101;
switch ( v7 )
{
case 'r':
v5 = (unsigned __int8)bit_array_test(v2) == 0 ? 117 : 115;
break;
case 's':
bit_array_set_true(v2);
v5 = 115;
break;
case 'u':
bit_array_set_false(v2);
v5 = 117;
break;
}
send(*v1, &v4, 5uLL, 0);
}
shutdown(*v1, 1);
close(*v1);
free(v1);
puts("Lost a connection.");
return 0LL;
}

original_code:
void* socketHandler(struct SHArgs *shargs) {
  int *clientSocket = shargs->clientSocket;
  bit_array_t *bits = shargs->bits;
  int packetLen = 5;
  int byteCount;
  struct message msg;
  struct message rsp;
  char read_char = 'r';
  char set_char = 's';
  char unset_char = 'u';
  char error_char = 'e';
  while ((byteCount = recv(*clientSocket, &msg, 5, 0)) > 0) {
    rsp.offset = msg.offset;
    rsp.val = error_char;
    if (msg.val == read_char) {
      if(bit_array_test(bits, msg.offset)) {
        rsp.val = set_char;
      } else {
        rsp.val = unset_char;
      }
    } else if (msg.val == set_char){
      bit_array_set_true(bits, msg.offset);
      rsp.val = set_char;
    } else if (msg.val == unset_char) {
      bit_array_set_false(bits, msg.offset);
      rsp.val = unset_char;
    } else {
    }
    send(*clientSocket, &rsp, packetLen, 0);
  }
  shutdown(*clientSocket, SHUT_WR);
  close(*clientSocket);
  free(clientSocket);
  printf("Lost a connection.\n");
  return ((void *)0);
}

canonical_original_code:
void *socketHandler(struct SHArgs *shargs) {
  int *clientSocket = shargs->clientSocket;
  struct bit_array_t *bits = shargs->bits;
  int packetLen = 5;
  int byteCount;
  struct message msg;
  struct message rsp;
  char read_char = 'r';
  char set_char = 's';
  char unset_char = 'u';
  char error_char = 'e';
  while ((byteCount = recv(*clientSocket, &msg, 5, 0)) > 0) {
    rsp.offset = msg.offset;
    rsp.val = error_char;
    if (msg.val == read_char) {
      if(bit_array_test(bits, msg.offset)) {
        rsp.val = set_char;
      } else {
        rsp.val = unset_char;
      }
    } else if (msg.val == set_char){
      bit_array_set_true(bits, msg.offset);
      rsp.val = set_char;
    } else if (msg.val == unset_char) {
      bit_array_set_false(bits, msg.offset);
      rsp.val = unset_char;
    } else {
    }
    send(*clientSocket, &rsp, packetLen, 0);
  }
  shutdown(*clientSocket, SHUT_WR);
  close(*clientSocket);
  free(clientSocket);
  printf("Lost a connection.\n");
  return ((void *)0);
}

variable_types: struct SHArgs { int *clientSocket; struct bit_array_t { unsigned long *slots; unsigned int num_bits; unsigned int num_slots; } *bits; } *

variable_types:
clientSocket
int *

variable_types: packetLen int

variable_types: byteCount int

variable_types: struct message { unsigned int offset; char val; }

return_type: void *

user_defined_types: struct SHArgs { int *clientSocket; struct bit_array_t *bits; }


hostSocketInitAndBind

decompiled_code:
int __fastcall hostSocketInitAndBind(int *a1, __int64 a2, __int16 a3)
{
int v4; // eax
int v6; // [rsp+8h] [rbp-20h] BYREF
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = socket(2, 1, 0);
*a1 = v4;
optval[0] = 1;
v6 = 1;
setsockopt(v4, 1, 2, optval, 4u);
setsockopt(*a1, 1, 9, &v6, 4u);
*(_WORD *)a2 = 2;
*(_WORD *)(a2 + 2) = _bswap_16(a3);
*(_QWORD *)(a2 + 8) = 0LL;
*(_DWORD *)(a2 + 4) = 0;
bind(*a1, (const struct sockaddr *)a2, 0x10u);
return listen(*a1, 10);
}

canonical_decompiled_code:
int __fastcall func2(int *a1, __int64 a2, __int16 a3)
{
int v4; // eax
int v6; // [rsp+8h] [rbp-20h] BYREF
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4 = socket(2, 1, 0);
*a1 = v4;
optval[0] = 1;
v6 = 1;
setsockopt(v4, 1, 2, optval, 4u);
setsockopt(*a1, 1, 9, &v6, 4u);
*(_WORD *)a2 = 2;
*(_WORD *)(a2 + 2) = func0(a3);
*(_QWORD *)(a2 + 8) = 0LL;
*(_DWORD *)(a2 + 4) = 0;
bind(*a1, (const struct sockaddr *)a2, 0x10u);
return listen(*a1, 10);
}

original_code:
void hostSocketInitAndBind(int *hostSocket, struct sockaddr_in *hostAddr, int port) {
  *hostSocket = socket(2, SOCK_STREAM, 0);
  int so_reuseaddr_optval = 1;
  int so_keepalive_optval = 1;
  setsockopt(*hostSocket, 1, 2, &so_reuseaddr_optval, sizeof(int));
  setsockopt(*hostSocket, 1, 9, &so_keepalive_optval, sizeof(int));
  hostAddr->sin_family = 2;
  hostAddr->sin_port = htons(port);
  memset(&(hostAddr->sin_zero), 0, 8);
  hostAddr->sin_addr.s_addr = ((in_addr_t) 0x00000000);
  bind(*hostSocket, (struct sockaddr*)&*hostAddr, sizeof(*hostAddr));
  listen(*hostSocket, 10);
}

canonical_original_code:
void hostSocketInitAndBind(int *hostSocket, struct sockaddr_in *hostAddr, int port) {
  *hostSocket = socket(2, SOCK_STREAM, 0);
  int so_reuseaddr_optval = 1;
  int so_keepalive_optval = 1;
  setsockopt(*hostSocket, 1, 2, &so_reuseaddr_optval, sizeof(int));
  setsockopt(*hostSocket, 1, 9, &so_keepalive_optval, sizeof(int));
  hostAddr->sin_family = 2;
  hostAddr->sin_port = htons(port);
  memset(&(hostAddr->sin_zero), 0, 8);
  hostAddr->sin_addr.s_addr = ((unsigned int) 0x00000000);
  bind(*hostSocket, (struct sockaddr *)&*hostAddr, sizeof(*hostAddr));
  listen(*hostSocket, 10);
}

variable_types:
hostSocket
int *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: port int

return_type: void

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
int v4; // eax
int *v5; // rax
__int64 v6[3]; // [rsp+0h] [rbp-68h] BYREF
pthread_t newthread; // [rsp+18h] [rbp-50h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-48h] BYREF
char v9[24]; // [rsp+30h] [rbp-38h] BYREF
socklen_t addr_len; // [rsp+48h] [rbp-20h] BYREF
int fd; // [rsp+4Ch] [rbp-1Ch] BYREF
char v12[24]; // [rsp+50h] [rbp-18h] BYREF

bit_array_init(v12, argv, envp);
bit_array_set_num_bits(v12, 0xFFFFFFFFLL);
bit_array_set_all_false(v12);
newthread = 0LL;
addr_len = 16;
hostSocketInitAndBind(&fd, (__int64)v9, 8030);
puts("Awaiting connections.");
sigset(13, (__sighandler_t)((char *)_bswap_16 + 1));
while ( 1 )
{
v3 = malloc(4uLL);
v4 = accept(fd, &addr, &addr_len);
*v3 = v4;
if ( v4 == -1 )
{
v5 = _errno_location();
fprintf(stderr, "Error accepting %d\n", (unsigned int)*v5);
}
else
{
puts("Client connection established.");
v6[0] = (__int64)v3;
v6[1] = (__int64)v12;
pthread_create(&newthread, 0LL, socketHandler, v6);
pthread_detach(newthread);
}
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
int v4; // eax
int *v5; // rax
__int64 v6[3]; // [rsp+0h] [rbp-68h] BYREF
pthread_t newthread; // [rsp+18h] [rbp-50h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-48h] BYREF
char v9[24]; // [rsp+30h] [rbp-38h] BYREF
socklen_t addr_len; // [rsp+48h] [rbp-20h] BYREF
int fd; // [rsp+4Ch] [rbp-1Ch] BYREF
char v12[24]; // [rsp+50h] [rbp-18h] BYREF

bit_array_init(v12, argv, envp);
bit_array_set_num_bits(v12, 0xFFFFFFFFLL);
bit_array_set_all_false(v12);
newthread = 0LL;
addr_len = 16;
func2(&fd, (__int64)v9, 8030);
puts("Awaiting connections.");
sigset(13, (__sighandler_t)((char *)_bswap_16 + 1));
while ( 1 )
{
v3 = malloc(4uLL);
v4 = accept(fd, &addr, &addr_len);
*v3 = v4;
if ( v4 == -1 )
{
v5 = _errno_location();
fprintf(stderr, "Error accepting %d\n", (unsigned int)*v5);
}
else
{
puts("Client connection established.");
v6[0] = (__int64)v3;
v6[1] = (__int64)v12;
pthread_create(&newthread, 0LL, socketHandler, v6);
pthread_detach(newthread);
}
}
}

original_code:
int main(int argc, char *argv[]) {
  int port = 8030;
  bit_array_num_t NUM_BITS = 4294967295;
  bit_array_t bits;
  bit_array_init(&bits);
  bit_array_set_num_bits(&bits, NUM_BITS);
  bit_array_set_all_false(&bits);
  int hostSocket;
  int *clientSocket;
  socklen_t addrSize;
  struct sockaddr_in myAddr;
  struct sockaddr_in sourceAddr;
  pthread_t thread_id=0;
  addrSize = sizeof(struct sockaddr_in);
  hostSocketInitAndBind(&hostSocket, &myAddr, port);
  printf("Awaiting connections.\n");
  sigset(13, ((__sighandler_t) 1));
  while (1)
  {
    clientSocket = (int*)malloc(sizeof(int));
    if ((*clientSocket = accept(hostSocket, (struct sockaddr*)&sourceAddr, &addrSize)) != -1 )
    {
      printf("Client connection established.\n");
      struct SHArgs shargs;
      shargs.clientSocket = clientSocket;
      shargs.bits = &bits;
      pthread_create(&thread_id, 0, (void *)&socketHandler, &shargs);
      pthread_detach(thread_id);
    } else {
      fprintf(stderr, "Error accepting %d\n", (*__errno_location ()));
    }
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  int port = 8030;
  unsigned int NUM_BITS = 4294967295;
  struct bit_array_t bits;
  bit_array_init(&bits);
  bit_array_set_num_bits(&bits, NUM_BITS);
  bit_array_set_all_false(&bits);
  int hostSocket;
  int *clientSocket;
  unsigned int addrSize;
  struct sockaddr_in myAddr;
  struct sockaddr_in sourceAddr;
  unsigned long thread_id = 0;
  addrSize = sizeof(struct sockaddr_in);
  hostSocketInitAndBind(&hostSocket, &myAddr, port);
  printf("Awaiting connections.\n");
  sigset(13, ((void (*)(int)) 1));
  while (1)
  {
    clientSocket = (int *)malloc(sizeof(int));
    if ((*clientSocket = accept(hostSocket, (struct sockaddr *)&sourceAddr, &addrSize)) != -1 )
    {
      printf("Client connection established.\n");
      struct SHArgs shargs;
      shargs.clientSocket = clientSocket;
      shargs.bits = &bits;
      pthread_create(&thread_id, 0, (void *)&socketHandler, &shargs);
      pthread_detach(thread_id);
    } else {
      fprintf(stderr, "Error accepting %d\n", (*__errno_location ()));
    }
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: hostSocket int

variable_types:
addrSize
unsigned int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct SHArgs { int *clientSocket; struct bit_array_t { unsigned long *slots; unsigned int num_bits; unsigned int num_slots; } *bits; }


decompiled_code:
__int64 __fastcall num_slots_for(unsigned int a1)
{
return a1 >> 3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return a1 >> 3;
}

original_code:
static inline bit_array_num_t num_slots_for(const bit_array_num_t num_bits) {
  return num_bits / sizeof(bit_array_slot_t);
}

canonical_original_code:
static inline unsigned int num_slots_for(unsigned int num_bits) {
  return num_bits / sizeof(bit_array_slot_t);
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall slot_for(unsigned int a1)
{
return a1 >> 6;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
return a1 >> 6;
}

original_code:
static inline bit_array_idx_t slot_for(const bit_array_idx_t nth_bit) {
  return nth_bit / BITS_PER_SLOT;
}

canonical_original_code:
static inline unsigned int slot_for(unsigned int nth_bit) {
  return nth_bit / BITS_PER_SLOT;
}


decompiled_code:
__int64 initial_bit()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
static inline bit_array_slot_t initial_bit(void) {
  return 1;
}

canonical_original_code:
static inline unsigned long initial_bit() {
  return 1;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall bit_mask_for(char a1)
{
return initial_bit() << a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
return func2() << a1;
}

original_code:
static inline bit_array_slot_t bit_mask_for(const bit_array_idx_t nth_bit) {
  return initial_bit() << (nth_bit % BITS_PER_SLOT);
}

canonical_original_code:
static inline unsigned long bit_mask_for(unsigned int nth_bit) {
  return initial_bit() << (nth_bit % BITS_PER_SLOT);
}


min

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

result = a1;
if ( a2 <= a1 )
result = a2;
return result;
}

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

result = a1;
if ( a2 <= a1 )
result = a2;
return result;
}

original_code:
static inline bit_array_num_t min(const bit_array_num_t a,
                                  const bit_array_num_t b)
{
  return a < b ? a : b;
}

canonical_original_code:
static inline unsigned int min(unsigned int a, unsigned int b)
{
  return a < b ? a : b;
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int


original_code:
void bit_array_init(bit_array_t *array) {
  array->num_bits = 0;
  array->num_slots = 0;
  array->slots = ((void *)0);
}

canonical_original_code:
void bit_array_init(struct bit_array_t *array) {
  array->num_bits = 0;
  array->num_slots = 0;
  array->slots = ((void *)0);
}

variable_types: struct bit_array_t { unsigned long *slots; unsigned int num_bits; unsigned int num_slots; } *


decompiled_code:
void __fastcall bit_array_destroy(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func7(void **a1)
{
free(*a1);
}

original_code:
void bit_array_destroy(bit_array_t *array) {
  free(array->slots);
}

canonical_original_code:
void bit_array_destroy(struct bit_array_t *array) {
  free(array->slots);
}

user_defined_types: struct bit_array_t { unsigned long *slots; unsigned int num_bits; unsigned int num_slots; }


decompiled_code:
bool __fastcall bit_array_set_num_bits(__int64 a1, unsigned int a2)
{
void *v2; // rax

*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = num_slots_for(a2);
v2 = allocate_slots_for(a1);
*(_QWORD *)a1 = v2;
return v2 != 0LL;
}

canonical_decompiled_code:
bool __fastcall func8(__int64 a1, unsigned int a2)
{
void *v2; // rax

*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)(a1 + 12) = func0(a2);
v2 = func5(a1);
*(_QWORD *)a1 = v2;
return v2 != 0LL;
}

original_code:
_Bool bit_array_set_num_bits(bit_array_t *array, const bit_array_num_t num_bits)
{
  array->num_bits = num_bits;
  array->num_slots = num_slots_for(num_bits);
  array->slots = allocate_slots_for(array);
  return array->slots != ((void *)0);
}

canonical_original_code:
_Bool bit_array_set_num_bits(struct bit_array_t *array, unsigned int num_bits)
{
  array->num_bits = num_bits;
  array->num_slots = num_slots_for(num_bits);
  array->slots = allocate_slots_for(array);
  return array->slots != ((void *)0);
}


decompiled_code:
void *__fastcall bit_array_set_all_true(__int64 a1)
{
return memset(*(void **)a1, -1, *(unsigned int *)(a1 + 12));
}

canonical_decompiled_code:
void *__fastcall func10(__int64 a1)
{
return memset(*(void **)a1, -1, *(unsigned int *)(a1 + 12));
}

original_code:
void bit_array_set_all_true(bit_array_t *array) {
  memset(array->slots, ALL_TRUE_BIT_MASK, array->num_slots);
}

canonical_original_code:
void bit_array_set_all_true(struct bit_array_t *array) {
  memset(array->slots, ALL_TRUE_BIT_MASK, array->num_slots);
}


decompiled_code:
void *__fastcall bit_array_set_all_false(__int64 a1)
{
return memset(*(void **)a1, 0, *(unsigned int *)(a1 + 12));
}

canonical_decompiled_code:
void *__fastcall func12(__int64 a1)
{
return memset(*(void **)a1, 0, *(unsigned int *)(a1 + 12));
}

original_code:
void bit_array_set_all_false(bit_array_t *array) {
  memset(array->slots, ALL_FALSE_BIT_MASK, array->num_slots);
}

canonical_original_code:
void bit_array_set_all_false(struct bit_array_t *array) {
  memset(array->slots, ALL_FALSE_BIT_MASK, array->num_slots);
}


decompiled_code:
void __fastcall bit_array_toggle_all(__int64 a1)
{
unsigned int v1; // eax

if ( *(_DWORD *)(a1 + 12) )
{
v1 = 0;
do
{
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v1) = ~*(_QWORD *)(*(_QWORD *)a1 + 8LL * v1);
++v1;
}
while ( *(_DWORD *)(a1 + 12) > v1 );
}
}

original_code:
void bit_array_toggle_all(bit_array_t *array) {
  bit_array_idx_t i;
  for (i = 0; i < array->num_slots; i += 1)
    array->slots[i] ^= ALL_TRUE_BIT_MASK;
}

canonical_original_code:
void bit_array_toggle_all(struct bit_array_t *array) {
  unsigned int i;
  for (i = 0; i < array->num_slots; i += 1)
    array->slots[i] ^= ALL_TRUE_BIT_MASK;
}

variable_types:
i
unsigned int


decompiled_code:
bool __fastcall bit_array_test(_QWORD *a1, unsigned int a2)
{
unsigned int v2; // ebx

v2 = slot_for(a2);
return (*(_QWORD *)(*a1 + 8LL * v2) & bit_mask_for(a2)) != 0;
}

canonical_decompiled_code:
bool __fastcall func15(_QWORD *a1, unsigned int a2)
{
unsigned int v2; // ebx

v2 = func1(a2);
return (*(_QWORD *)(*a1 + 8LL * v2) & func3(a2)) != 0;
}

original_code:
_Bool bit_array_test(const bit_array_t *array, const bit_array_idx_t nth_bit) {
  return array->slots[slot_for(nth_bit)] & bit_mask_for(nth_bit);
}

canonical_original_code:
_Bool bit_array_test(struct bit_array_t *array, unsigned int nth_bit) {
  return array->slots[slot_for(nth_bit)] & bit_mask_for(nth_bit);
}


decompiled_code:
__int64 __fastcall bit_array_test_all_true(__int64 a1)
{
int v1; // edx
_QWORD *v2; // rax
__int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 12);
if ( !v1 )
return 1LL;
v2 = *(_QWORD **)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
while ( *v2 == -1LL )
{
if ( ++v2 == (_QWORD *)v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
int v1; // edx
_QWORD *v2; // rax
__int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 12);
if ( !v1 )
return 1LL;
v2 = *(_QWORD **)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
while ( *v2 == -1LL )
{
if ( ++v2 == (_QWORD *)v3 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool bit_array_test_all_true(const bit_array_t *array) {
  bit_array_idx_t i;
  for (i = 0; i < array->num_slots; i += 1)
    if (array->slots[i] != ALL_TRUE_BIT_MASK)
      return 0;
  return 1;
}

canonical_original_code:
_Bool bit_array_test_all_true(struct bit_array_t *array) {
  unsigned int i;
  for (i = 0; i < array->num_slots; i += 1)
    if (array->slots[i] != ALL_TRUE_BIT_MASK)
      return 0;
  return 1;
}


decompiled_code:
__int64 __fastcall bit_array_test_all_false(__int64 a1)
{
int v1; // edx
_QWORD *v2; // rax
__int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 12);
if ( !v1 )
return 1LL;
v2 = *(_QWORD **)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
while ( !*v2 )
{
if ( ++v2 == (_QWORD *)v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
int v1; // edx
_QWORD *v2; // rax
__int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 12);
if ( !v1 )
return 1LL;
v2 = *(_QWORD **)a1;
v3 = *(_QWORD *)a1 + 8LL * (unsigned int)(v1 - 1) + 8;
while ( !*v2 )
{
if ( ++v2 == (_QWORD *)v3 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool bit_array_test_all_false(const bit_array_t *array) {
  bit_array_idx_t i;
  for (i = 0; i < array->num_slots; i += 1)
    if (array->slots[i] != ALL_FALSE_BIT_MASK)
      return 0;
  return 1;
}

canonical_original_code:
_Bool bit_array_test_all_false(struct bit_array_t *array) {
  unsigned int i;
  for (i = 0; i < array->num_slots; i += 1)
    if (array->slots[i] != ALL_FALSE_BIT_MASK)
      return 0;
  return 1;
}


decompiled_code:
__int64 __fastcall bit_array_test_any_true(__int64 a1)
{
return (unsigned int)bit_array_test_all_false(a1) ^ 1;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return (unsigned int)func17(a1) ^ 1;
}

original_code:
_Bool bit_array_test_any_true(const bit_array_t *array) {
  return !bit_array_test_all_false(array);
}

canonical_original_code:
_Bool bit_array_test_any_true(struct bit_array_t *array) {
  return !bit_array_test_all_false(array);
}


decompiled_code:
__int64 __fastcall bit_array_test_any_false(__int64 a1)
{
return (unsigned int)bit_array_test_all_true(a1) ^ 1;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
return (unsigned int)func16(a1) ^ 1;
}

original_code:
_Bool bit_array_test_any_false(const bit_array_t *array) {
  return !bit_array_test_all_true(array);
}

canonical_original_code:
_Bool bit_array_test_any_false(struct bit_array_t *array) {
  return !bit_array_test_all_true(array);
}


original_code:
size_t bit_array_to_string(const bit_array_t *array, char *buffer,
                           const size_t buffer_size)
{
  static const char TRUE_BIT = '1';
  static const char FALSE_BIT = '0';
  const bit_array_idx_t end_bit = min(buffer_size - 1, array->num_bits);
  bit_array_idx_t bit = 0;
  while (bit < end_bit) {
    if (bit_array_test(array, bit))
      buffer[bit] = TRUE_BIT;
    else
      buffer[bit] = FALSE_BIT;
    bit += 1;
  }
  buffer[bit] = '\0';
  return array->num_bits - end_bit;
}

canonical_original_code:
unsigned long bit_array_to_string(struct bit_array_t *array, char *buffer, unsigned long buffer_size)
{
  static char TRUE_BIT = '1';
  static char FALSE_BIT = '0';
  unsigned int end_bit = min(buffer_size - 1, array->num_bits);
  unsigned int bit = 0;
  while (bit < end_bit) {
    if (bit_array_test(array, bit))
      buffer[bit] = TRUE_BIT;
    else
      buffer[bit] = FALSE_BIT;
    bit += 1;
  }
  buffer[bit] = '\0';
  return array->num_bits - end_bit;
}

variable_types:
buffer
char *

variable_types:
bit
unsigned int


help

repo: ptigas/ciscal

decompiled_code:
int help()
{
char v1[312]; // [rsp+0h] [rbp-138h] BYREF

strcpy(
v1,
"Ciscal compiler.\n"
"\t Usage: ciscal [options] ...\n"
"\t Options:\n"
" -f filename \t\t \t Compiles filename. \n"
" -i \t\t\t \t Output icode to icode.txt \n"
" \t -a [x86 or metasim] \t \t Output assembly to assembly.s. \t Default metasim.");
return fprintf(stdout, "%s\n", v1);
}

canonical_decompiled_code:
int func0()
{
char v1[312]; // [rsp+0h] [rbp-138h] BYREF

strcpy(
v1,
"Ciscal compiler.\n"
"\t Usage: ciscal [options] ...\n"
"\t Options:\n"
" -f filename \t\t \t Compiles filename. \n"
" -i \t\t\t \t Output icode to icode.txt \n"
" \t -a [x86 or metasim] \t \t Output assembly to assembly.s. \t Default metasim.");
return fprintf(stdout, "%s\n", v1);
}

original_code:
void help() {
 char str[] = "Ciscal compiler.\n	              Usage: ciscal [options] ...\n	              Options:\n -f filename \t\t 	              Compiles filename. \n -i \t\t\t 	              Output icode to icode.txt \n 	              -a [x86 or metasim] \t 	              Output assembly to assembly.s. 	              Default metasim.";
 fprintf(stdout, "%s\n", str);
}

variable_types:
str
char []


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
int v5; // eax

opterr = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "f:ia::h");
if ( v5 == -1 )
break;
if ( v5 == 102 )
{
in = fopen(optarg, "r");
}
else if ( v5 <= 102 )
{
if ( v5 == 63 )
{
if ( optopt != 97 )
return 1;
fprintf(stderr, "Option -%c requires an argument.\n", 97LL);
fwrite("Setting to default assembly [metasym].\n", 1uLL, 0x27uLL, stderr);
assembly = strdup("metasim");
v4 = 1;
}
else
{
if ( v5 != 97 )
goto LABEL_16;
assembly = optarg;
v4 = 1;
}
}
else
{
if ( v5 == 104 )
{
help();
return 0;
}
v3 = 1;
if ( v5 != 105 )
LABEL_16:
abort();
}
}
if ( argc <= optind )
{
parse();
if ( v3 )
printquads();
if ( v4 )
{
v4 = strcmp(assembly, "x86");
if ( v4 )
{
generate_final();
print_machine_code();
v4 = 0;
}
else
{
generate_final_x86();
print_machine_code_x86();
}
}
}
else
{
printf("Non-option argument %s\n", argv[optind]);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er14
int v4; // er13
int v5; // eax

opterr = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "f:ia::h");
if ( v5 == -1 )
break;
if ( v5 == 102 )
{
in = fopen(optarg, "r");
}
else if ( v5 <= 102 )
{
if ( v5 == 63 )
{
if ( optopt != 97 )
return 1;
fprintf(stderr, "Option -%c requires an argument.\n", 97LL);
fwrite("Setting to default assembly [metasym].\n", 1uLL, 0x27uLL, stderr);
assembly = strdup("metasim");
v4 = 1;
}
else
{
if ( v5 != 97 )
goto LABEL_16;
assembly = optarg;
v4 = 1;
}
}
else
{
if ( v5 == 104 )
{
func0();
return 0;
}
v3 = 1;
if ( v5 != 105 )
LABEL_16:
abort();
}
}
if ( argc <= optind )
{
parse();
if ( v3 )
printquads();
if ( v4 )
{
v4 = strcmp(assembly, "x86");
if ( v4 )
{
generate_final();
print_machine_code();
v4 = 0;
}
else
{
generate_final_x86();
print_machine_code_x86();
}
}
}
else
{
printf("Non-option argument %s\n", argv[optind]);
v4 = 0;
}
return v4;
}

original_code:
int main(int argc, char *argv[]) {
 int index;
 int final = 0;
 int icode = 0;
 char *filename = ((void *)0);
 int c;
 opterr = 0;
 while ((c = getopt(argc, argv, "f:ia::h")) != -1) {
  switch (c) {
   case 'h':
    help();
    return 0;
   case 'f':
    filename = optarg;
    in = fopen(filename, "r");
    continue;
   case 'i':
    icode = 1;
    continue;
   case 'a':
    final = 1;
    assembly = optarg;
    continue;
   case '?':
    if (optopt == 'a') {
     fprintf (stderr, "Option -%c requires an argument.\n", optopt);
     fprintf (stderr, "Setting to default assembly [metasym].\n");
     assembly = strdup("metasim");
     final = 1;
     continue;
    }
    return 1;
   default:
    abort();
  }
 }
 for (index = optind; index < argc; index++){
  printf ("Non-option argument %s\n", argv[index]);
  return 0;
 }
    parse();
 if (icode) {
  printquads();
 }
 if (final) {
  if (!strcmp(assembly, "x86")) {
   generate_final_x86();
   print_machine_code_x86();
  } else {
   generate_final();
   print_machine_code();
  }
 }
    return 0;
}

variable_types: index int

variable_types: final int

variable_types: icode int

variable_types:
filename
char *

variable_types: c int


isAlpha

decompiled_code:
__int64 __fastcall isAlpha(char a1)
{
return (a1 == 95) | (unsigned __int8)((unsigned __int8)((a1 & 0xDF) - 65) <= 0x19u);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (a1 == 95) | (unsigned __int8)((unsigned __int8)((a1 & 0xDF) - 65) <= 0x19u);
}

variable_types: i char


isNum

decompiled_code:
_BOOL8 __fastcall isNum(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

original_code:
int isNum(char i){
 return (i >= '0')&&(i <= '9');
}


isAlplhanum

decompiled_code:
_BOOL8 __fastcall isAlplhanum(char a1)
{
int v1; // edx
_BOOL8 result; // rax

v1 = isAlpha(a1);
result = 1LL;
if ( !v1 )
result = isNum(a1);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char a1)
{
int v1; // edx
_BOOL8 result; // rax

v1 = func0(a1);
result = 1LL;
if ( !v1 )
result = func1(a1);
return result;
}

original_code:
int isAlplhanum(char i){
 return isAlpha(i)||isNum(i);
}


isWhite

decompiled_code:
__int64 __fastcall isWhite(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 1u);
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 1u);
}


isOperator

decompiled_code:
_BOOL8 __fastcall isOperator(char a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (a1 & 0xFD) != 45 )
result = (unsigned __int8)(a1 - 42) <= 1u;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (a1 & 0xFD) != 45 )
result = (unsigned __int8)(a1 - 42) <= 1u;
return result;
}


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

result = fgetc(in);
if ( (_BYTE)result == 10 )
++line;
return result;
}

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

result = fgetc(in);
if ( (_BYTE)result == 10 )
++line;
return result;
}

original_code:
char get_char() {
 char c;
 c = fgetc(in);
 if(c == '\n') {
        line++;
    }
 return c;
}

variable_types: c char

return_type: char


decompiled_code:
int __fastcall put_char(char a1)
{
int result; // eax

result = ungetc(a1, in);
if ( a1 == 10 )
--line;
return result;
}

canonical_decompiled_code:
int __fastcall func6(char a1)
{
int result; // eax

result = ungetc(a1, in);
if ( a1 == 10 )
--line;
return result;
}

original_code:
void put_char(char c) {
 ungetc(c, in);
 if(c == '\n') {
  line--;
    }
}


lex

decompiled_code:
int lex()
{
int v0; // er13
int v1; // ebx
int v2; // er12
int v3; // er12
char v4; // bp
int result; // eax
const char *v6; // rbp
int v7; // ebx

if ( !in )
in = stdin;
v0 = 0;
v1 = 0;
do
{
while ( 1 )
{
do
{
v4 = get_char();
if ( (unsigned int)isAlpha(v4) )
{
v2 = 1;
goto LABEL_20;
}
if ( isNum(v4) )
{
v2 = 0;
goto LABEL_20;
}
if ( (unsigned int)isWhite(v4) )
{
v2 = 2;
LABEL_20:
if ( v1 != 5 )
{
LABEL_21:
if ( v4 != 47 )
goto LABEL_22;
LOBYTE(result) = get_char();
if ( (_BYTE)result == 42 )
{
v4 = 42;
v1 = 5;
goto LABEL_22;
}
LABEL_53:
put_char(result);
goto LABEL_22;
}
LABEL_51:
v1 = 5;
if ( v4 != 42 )
goto LABEL_22;
result = get_char();
if ( (_BYTE)result == 47 )
{
token = 48;
return result;
}
goto LABEL_53;
}
if ( isOperator(v4) )
{
v2 = (((v4 - 43) & 0xFD) != 0) + 3;
goto LABEL_20;
}
switch ( v4 )
{
case '[':
v2 = 12;
break;
case ']':
v2 = 13;
break;
case '{':
v2 = 10;
break;
case '}':
v2 = 11;
break;
default:
switch ( v4 )
{
case '(':
v2 = 14;
break;
case ')':
v2 = 15;
break;
case '<':
v2 = 5;
break;
case '>':
v2 = 6;
break;
case '=':
v2 = 7;
break;
case ',':
v2 = 16;
break;
case ';':
v2 = 17;
break;
case ':':
v2 = 18;
break;
default:
v2 = 20;
if ( v4 != -1 )
goto LABEL_20;
v2 = 19;
break;
}
if ( v1 != 5 )
goto LABEL_22;
goto LABEL_51;
}
if ( v1 != 5 )
goto LABEL_21;
LABEL_22:
v1 = state[21 * v1 + v2];
}
while ( v1 == 5 );
if ( v1 != 9 )
break;
v0 = 0;
v1 = 0;
}
if ( v0 <= 29 )
*(&id_string + v0++) = v4;
v3 = v1;
}
while ( (unsigned int)(v1 - 6) > 0x2B );
if ( v1 == 6 )
{
put_char(v4);
*(&id_string + --v0) = 0;
v6 = reserved;
v7 = 0;
while ( 1 )
{
result = strcmp(v6, &id_string);
if ( !result )
break;
++v7;
v6 += 31;
if ( v7 == 18 )
goto LABEL_42;
}
token = v7 + 29;
}
else
{
if ( v1 == 7 )
{
put_char(v4);
*(&id_string + --v0) = 0;
result = atoi(&id_string);
id_value = result;
}
else
{
result = v1 - 13;
if ( (unsigned int)(v1 - 13) <= 1 )
{
result = put_char(v4);
--v0;
}
}
LABEL_42:
*(&id_string + v0) = 0;
token = v3;
}
return result;
}

canonical_decompiled_code:
int func7()
{
int v0; // er13
int v1; // ebx
int v2; // er12
int v3; // er12
char v4; // bp
int result; // eax
const char *v6; // rbp
int v7; // ebx

if ( !in )
in = stdin;
v0 = 0;
v1 = 0;
do
{
while ( 1 )
{
do
{
v4 = func5();
if ( (unsigned int)func0(v4) )
{
v2 = 1;
goto LABEL_20;
}
if ( func1(v4) )
{
v2 = 0;
goto LABEL_20;
}
if ( (unsigned int)func3(v4) )
{
v2 = 2;
LABEL_20:
if ( v1 != 5 )
{
LABEL_21:
if ( v4 != 47 )
goto LABEL_22;
LOBYTE(result) = func5();
if ( (_BYTE)result == 42 )
{
v4 = 42;
v1 = 5;
goto LABEL_22;
}
LABEL_53:
func6(result);
goto LABEL_22;
}
LABEL_51:
v1 = 5;
if ( v4 != 42 )
goto LABEL_22;
result = func5();
if ( (_BYTE)result == 47 )
{
token = 48;
return result;
}
goto LABEL_53;
}
if ( func4(v4) )
{
v2 = (((v4 - 43) & 0xFD) != 0) + 3;
goto LABEL_20;
}
switch ( v4 )
{
case '[':
v2 = 12;
break;
case ']':
v2 = 13;
break;
case '{':
v2 = 10;
break;
case '}':
v2 = 11;
break;
default:
switch ( v4 )
{
case '(':
v2 = 14;
break;
case ')':
v2 = 15;
break;
case '<':
v2 = 5;
break;
case '>':
v2 = 6;
break;
case '=':
v2 = 7;
break;
case ',':
v2 = 16;
break;
case ';':
v2 = 17;
break;
case ':':
v2 = 18;
break;
default:
v2 = 20;
if ( v4 != -1 )
goto LABEL_20;
v2 = 19;
break;
}
if ( v1 != 5 )
goto LABEL_22;
goto LABEL_51;
}
if ( v1 != 5 )
goto LABEL_21;
LABEL_22:
v1 = state[21 * v1 + v2];
}
while ( v1 == 5 );
if ( v1 != 9 )
break;
v0 = 0;
v1 = 0;
}
if ( v0 <= 29 )
*(&id_string + v0++) = v4;
v3 = v1;
}
while ( (unsigned int)(v1 - 6) > 0x2B );
if ( v1 == 6 )
{
func6(v4);
*(&id_string + --v0) = 0;
v6 = reserved;
v7 = 0;
while ( 1 )
{
result = strcmp(v6, &id_string);
if ( !result )
break;
++v7;
v6 += 31;
if ( v7 == 18 )
goto LABEL_42;
}
token = v7 + 29;
}
else
{
if ( v1 == 7 )
{
func6(v4);
*(&id_string + --v0) = 0;
result = atoi(&id_string);
id_value = result;
}
else
{
result = v1 - 13;
if ( (unsigned int)(v1 - 13) <= 1 )
{
result = func6(v4);
--v0;
}
}
LABEL_42:
*(&id_string + v0) = 0;
token = v3;
}
return result;
}

original_code:
void lex() {
    char c, cold;
    int S;
    int i;
    enum chartype ic;
    int j;
    if (in == ((void *)0)) {
        in = stdin;
    }
    i = 0;
    S = NF_START;
    while (1) {
  cold = c;
  c = get_char();
        if (isAlpha(c)) {
            ic = alpha;
        } else if (isNum(c)) {
            ic = digit;
        } else if (isWhite(c)) {
            ic = white;
        } else if (isOperator(c)) {
            if(c == '+' || c == '-') {
                ic = addop;
            } else {
                ic = mulop;
            }
        } else {
            if (c == '[') {
                ic = lbbrac;
   } else if (c == ']') {
                ic = rbbrac;
   } else if (c == '{') {
                ic = lbrac;
   } else if (c == '}') {
                ic = rbrac;
   } else if (c == '(') {
                ic = lpar;
   } else if (c == ')') {
                ic = rpar;
   } else if (c == '<') {
                ic = lt;
   } else if (c == '>') {
                ic = gt;
   } else if (c == '=') {
                ic = eq;
   } else if (c == ',') {
                ic = comma;
   } else if (c == ';') {
                ic = scol;
   } else if (c == ':') {
                ic = col;
   } else if (c == -1) {
                ic = eof;
   } else {
                ic = other;
            }
        }
        if (S != NF_COMMENT) {
            if (c == '/') {
                c = get_char();
                if (c == '*') {
                    S = NF_COMMENT;
                } else {
                    put_char(c);
     c = '/';
                }
            }
        } else {
            if (c == '*') {
                c = get_char();
                if (c == '/') {
                    S = COMMENT;
                    token = S;
                    return;
                } else {
                    put_char(c);
     c = '*';
                }
            }
        }
  S = state[S][ic];
        if (S != NF_COMMENT) {
            if (S != WHITE){
                if (i < 30){
                    id_string[i++] = c;
                }
            } else {
                i = 0;
                S = NF_START;
                continue;
            }
            if (((S>=ID)&&(S<=ERROR)) && S != WHITE) {
                if (S == ID) {
                    put_char(c);
     c = cold;
     i--;
     id_string[i] = '\0';
                    for(j=0; j < 18; j++) {
                        if (strcmp(reserved[j], id_string) == 0) {
                            S = TK_AND + j;
                            token = S;
                            return;
                        }
                    }
                }
                if (S == INTEGER) {
                    put_char(c);
     c = cold;
     i--;
     id_string[i] = '\0';
                    id_value = atoi(id_string);
                }
                if (S == TK_GT || S == TK_LT ) {
                    put_char(c);
     c = cold;
     i--;
                }
    id_string[i] = '\0';
                i = 0;
                token = S;
                return;
            }
        }
    }
    token = -1;
    return;
}

canonical_original_code:
void lex() {
    char c; char cold;
    int S;
    int i;
    enum chartype ic;
    int j;
    if (in == ((void *)0)) {
        in = stdin;
    }
    i = 0;
    S = NF_START;
    while (1) {
  cold = c;
  c = get_char();
        if (isAlpha(c)) {
            ic = alpha;
        } else if (isNum(c)) {
            ic = digit;
        } else if (isWhite(c)) {
            ic = white;
        } else if (isOperator(c)) {
            if(c == '+' || c == '-') {
                ic = addop;
            } else {
                ic = mulop;
            }
        } else {
            if (c == '[') {
                ic = lbbrac;
   } else if (c == ']') {
                ic = rbbrac;
   } else if (c == '{') {
                ic = lbrac;
   } else if (c == '}') {
                ic = rbrac;
   } else if (c == '(') {
                ic = lpar;
   } else if (c == ')') {
                ic = rpar;
   } else if (c == '<') {
                ic = lt;
   } else if (c == '>') {
                ic = gt;
   } else if (c == '=') {
                ic = eq;
   } else if (c == ',') {
                ic = comma;
   } else if (c == ';') {
                ic = scol;
   } else if (c == ':') {
                ic = col;
   } else if (c == -1) {
                ic = eof;
   } else {
                ic = other;
            }
        }
        if (S != NF_COMMENT) {
            if (c == '/') {
                c = get_char();
                if (c == '*') {
                    S = NF_COMMENT;
                } else {
                    put_char(c);
     c = '/';
                }
            }
        } else {
            if (c == '*') {
                c = get_char();
                if (c == '/') {
                    S = COMMENT;
                    token = S;
                    return;
                } else {
                    put_char(c);
     c = '*';
                }
            }
        }
  S = state[S][ic];
        if (S != NF_COMMENT) {
            if (S != WHITE){
                if (i < 30){
                    id_string[i++] = c;
                }
            } else {
                i = 0;
                S = NF_START;
                continue;
            }
            if (((S>=ID)&&(S<=ERROR)) && S != WHITE) {
                if (S == ID) {
                    put_char(c);
     c = cold;
     i--;
     id_string[i] = '\0';
                    for(j=0; j < 18; j++) {
                        if (strcmp(reserved[j], id_string) == 0) {
                            S = TK_AND + j;
                            token = S;
                            return;
                        }
                    }
                }
                if (S == INTEGER) {
                    put_char(c);
     c = cold;
     i--;
     id_string[i] = '\0';
                    id_value = atoi(id_string);
                }
                if (S == TK_GT || S == TK_LT ) {
                    put_char(c);
     c = cold;
     i--;
                }
    id_string[i] = '\0';
                i = 0;
                token = S;
                return;
            }
        }
    }
    token = -1;
    return;
}

variable_types: cold char

variable_types: S int

variable_types: i int

variable_types: enum chartype { digit=0, alpha=1, white=2, addop=3, mulop=4, lt=5, gt=6, eq=7, slash=8, star=9, lbrac=10, rbrac=11, lbbrac=12, rbbrac=13, lpar=14, rpar=15, comma=16, scol=17, col=18, eof=19, other=20 }

variable_types: j int


decompiled_code:
char *__fastcall label_x86(const char *a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

sprintf(v2, ".L%s", a1);
return strdup(v2);
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1)
{
char v2[56]; // [rsp+0h] [rbp-38h] BYREF

sprintf(v2, ".L%s", a1);
return strdup(v2);
}

original_code:
char * label_x86( char *l ){
    char s[35];
    sprintf(s, ".L%s", l);
    return strdup(s);
}

canonical_original_code:
char *label_x86(char *l){
    char s[35];
    sprintf(s, ".L%s", l);
    return strdup(s);
}

variable_types:
l
char *

variable_types:
s
char [35]

return_type: char *


decompiled_code:
__int64 __fastcall add_machine_code_x86(char *src)
{
char *v1; // rbx
__int64 result; // rax

v1 = (char *)malloc(0x110uLL);
strcpy(v1, src);
result = mc;
if ( mc )
{
*(_QWORD *)(mc + 264) = v1;
*((_QWORD *)v1 + 32) = result;
mc = (__int64)v1;
}
else
{
*((_QWORD *)v1 + 32) = 0LL;
*((_QWORD *)v1 + 33) = 0LL;
mc = (__int64)v1;
mc_tail = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src)
{
char *v1; // rbx
__int64 result; // rax

v1 = (char *)malloc(0x110uLL);
strcpy(v1, src);
result = mc;
if ( mc )
{
*(_QWORD *)(mc + 264) = v1;
*((_QWORD *)v1 + 32) = result;
mc = (__int64)v1;
}
else
{
*((_QWORD *)v1 + 32) = 0LL;
*((_QWORD *)v1 + 33) = 0LL;
mc = (__int64)v1;
mc_tail = v1;
}
return result;
}

original_code:
void add_machine_code_x86( char *s ){
    struct code *tmp;
    tmp = (struct code*)malloc(sizeof(struct code));
    sprintf(tmp->cmd, "%s", s);
    if ( mc == ((void *)0) ){
        tmp->next = ((void *)0);
        tmp->prev = ((void *)0);
        mc = tmp;
        mc_tail = tmp;
    }else{
        mc->prev = tmp;
        tmp->next = mc;
        mc = tmp;
    }
}

canonical_original_code:
void add_machine_code_x86(char *s){
    struct code *tmp;
    tmp = (struct code *)malloc(sizeof(struct code));
    sprintf(tmp->cmd, "%s", s);
    if ( mc == ((void *)0) ){
        tmp->next = ((void *)0);
        tmp->prev = ((void *)0);
        mc = tmp;
        mc_tail = tmp;
    }else{
        mc->prev = tmp;
        tmp->next = mc;
        mc = tmp;
    }
}

variable_types:
s
char *

variable_types: struct code { char cmd[255]; struct code *next; struct code *prev; } *


decompiled_code:
__int64 gnlvcode_x86()
{
__int64 v0; // rbp
int i; // ebx
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

v0 = lookup();
sprintf(v3, "\tmovl -4(%%ebp), %%ebx\n");
add_machine_code_x86(v3);
for ( i = *(_DWORD *)(v0 + 12); ncur - 1 > i; ++i )
{
sprintf(v3, "\tmovl -4(%%ebx), %%ebx\n");
add_machine_code_x86(v3);
}
sprintf(v3, "\tsubl $%d, %%ebx\n", *(unsigned int *)(v0 + 8));
return add_machine_code_x86(v3);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbp
int i; // ebx
char v3[280]; // [rsp+0h] [rbp-118h] BYREF

v0 = lookup();
sprintf(v3, "\tmovl -4(%%ebp), %%ebx\n");
func2(v3);
for ( i = *(_DWORD *)(v0 + 12); ncur - 1 > i; ++i )
{
sprintf(v3, "\tmovl -4(%%ebx), %%ebx\n");
func2(v3);
}
sprintf(v3, "\tsubl $%d, %%ebx\n", *(unsigned int *)(v0 + 8));
return func2(v3);
}

original_code:
void gnlvcode_x86(char *name) {
 char s_tmp[255];
 int i;
 SYMBOL *p = lookup(name);
 sprintf(s_tmp, "\tmovl -4(%%ebp), %%ebx\n");
 add_machine_code_x86( s_tmp );
 for(i=p->level; i<ncur-1; i++) {
  sprintf(s_tmp, "\tmovl -4(%%ebx), %%ebx\n");
  add_machine_code_x86( s_tmp );
 }
 sprintf(s_tmp, "\tsubl $%d, %%ebx\n", p->offset);
 add_machine_code_x86( s_tmp );
}

canonical_original_code:
void gnlvcode_x86(char *name) {
 char s_tmp[255];
 int i;
 struct symbol *p = lookup(name);
 sprintf(s_tmp, "\tmovl -4(%%ebp), %%ebx\n");
 add_machine_code_x86( s_tmp );
 for(i=p->level; i<ncur-1; i++) {
  sprintf(s_tmp, "\tmovl -4(%%ebx), %%ebx\n");
  add_machine_code_x86( s_tmp );
 }
 sprintf(s_tmp, "\tsubl $%d, %%ebx\n", p->offset);
 add_machine_code_x86( s_tmp );
}

variable_types:
name
char *

variable_types: struct symbol { char *name; int offset; int level; struct function { enum FTYPE { FUNC=0, PROC=1, PROG=2 } type; int size; int genquad; struct symbol *args; struct symbol *first_arg; int num_arg; int has_return; } func; struct argument { enum PARTYPE { IN=0, INOUT=1 } type; struct symbol *next_arg; struct symbol *func; int offset; int num; } arg; struct variable { int offset; } var; enum T { TYPE_FUNC=0, TYPE_VAR=1, TYPE_CONST=2, TYPE_TMP=3, TYPE_ARG=4 } type; struct symbol *next; } *

user_defined_types: struct symbol { char *name; int offset; int level; struct function func; struct argument arg; struct variable var; enum T type; struct symbol *next; }

user_defined_types: struct function { enum FTYPE type; int size; int genquad; struct symbol *args; struct symbol *first_arg; int num_arg; int has_return; }

user_defined_types: struct argument { enum PARTYPE type; struct symbol *next_arg; struct symbol *func; int offset; int num; }


decompiled_code:
__int64 __fastcall load_x86(const char *a1, const char *a2)
{
__int64 v2; // rbx
int v3; // edx
__int64 result; // rax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

if ( ((*_ctype_b_loc())[*a2] & 0x400) != 0 || *a2 == 36 )
{
v2 = lookup(a2);
v3 = *(_DWORD *)(v2 + 12);
result = ncur;
if ( v3 == ncur )
{
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v5, "\tmovl -%d(%%ebp), %%edx\n", *(unsigned int *)(v2 + 8));
add_machine_code_x86(v5);
sprintf(v5, "\tmovl (%%edx), %%%s\n", a1);
result = add_machine_code_x86(v5);
}
else
{
sprintf(v5, "\tmovl -%d(%%ebp), %%%s\n", *(unsigned int *)(v2 + 8), a1);
result = add_machine_code_x86(v5);
}
}
else if ( v3 < ncur )
{
gnlvcode_x86(*(_QWORD *)v2);
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v5, "\tmovl (%%ebx), %%ebx\n");
add_machine_code_x86(v5);
sprintf(v5, "\tmovl (%%ebx), %%%s\n", a1);
result = add_machine_code_x86(v5);
}
else
{
sprintf(v5, "\tmovl (%%ebx), %%%s\n", a1);
result = add_machine_code_x86(v5);
}
}
}
else
{
sprintf(v5, "\tmovl $%s, %%%s\n", a2, a1);
result = add_machine_code_x86(v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, const char *a2)
{
__int64 v2; // rbx
int v3; // edx
__int64 result; // rax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

if ( ((*_ctype_b_loc())[*a2] & 0x400) != 0 || *a2 == 36 )
{
v2 = lookup(a2);
v3 = *(_DWORD *)(v2 + 12);
result = ncur;
if ( v3 == ncur )
{
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v5, "\tmovl -%d(%%ebp), %%edx\n", *(unsigned int *)(v2 + 8));
func2(v5);
sprintf(v5, "\tmovl (%%edx), %%%s\n", a1);
result = func2(v5);
}
else
{
sprintf(v5, "\tmovl -%d(%%ebp), %%%s\n", *(unsigned int *)(v2 + 8), a1);
result = func2(v5);
}
}
else if ( v3 < ncur )
{
func3(*(_QWORD *)v2);
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v5, "\tmovl (%%ebx), %%ebx\n");
func2(v5);
sprintf(v5, "\tmovl (%%ebx), %%%s\n", a1);
result = func2(v5);
}
else
{
sprintf(v5, "\tmovl (%%ebx), %%%s\n", a1);
result = func2(v5);
}
}
}
else
{
sprintf(v5, "\tmovl $%s, %%%s\n", a2, a1);
result = func2(v5);
}
return result;
}

original_code:
void load_x86( char *R, char *a ){
 char s_tmp[255];
    if ( !((*__ctype_b_loc ())[(int) ((*a))] & (unsigned short int) _ISalpha) && *a != '$' ){
        sprintf(s_tmp, "\tmovl $%s, %%%s\n", a, R);
        add_machine_code_x86( s_tmp );
    }else{
        SYMBOL *p = lookup(a);
  if (p->level == ncur) {
   if (p->type == TYPE_ARG && p->arg.type == INOUT) {
    sprintf(s_tmp, "\tmovl -%d(%%ebp), %%edx\n", p->offset);
          add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl (%%edx), %%%s\n", R);
          add_machine_code_x86( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovl  -%d(%%ebp), %%%s\n", p->offset, R);
          add_machine_code_x86( s_tmp );
   }
   return;
  }else if (p->level < ncur) {
   gnlvcode_x86(p->name);
   if (p->type == TYPE_ARG && p->arg.type == INOUT) {
    sprintf(s_tmp, "\tmovl (%%ebx), %%ebx\n");
          add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl (%%ebx), %%%s\n", R);
          add_machine_code_x86( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovl (%%ebx), %%%s\n", R);
          add_machine_code_x86( s_tmp );
   }
   return;
  }
    }
}

canonical_original_code:
void load_x86(char *R, char *a){
 char s_tmp[255];
    if ( !((*__ctype_b_loc ())[(int) ((*a))] & (unsigned short) _ISalpha) && *a != '$' ){
        sprintf(s_tmp, "\tmovl $%s, %%%s\n", a, R);
        add_machine_code_x86( s_tmp );
    }else{
        struct symbol *p = lookup(a);
  if (p->level == ncur) {
   if (p->type == TYPE_ARG && p->arg.type == INOUT) {
    sprintf(s_tmp, "\tmovl -%d(%%ebp), %%edx\n", p->offset);
          add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl (%%edx), %%%s\n", R);
          add_machine_code_x86( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovl  -%d(%%ebp), %%%s\n", p->offset, R);
          add_machine_code_x86( s_tmp );
   }
   return;
  }else if (p->level < ncur) {
   gnlvcode_x86(p->name);
   if (p->type == TYPE_ARG && p->arg.type == INOUT) {
    sprintf(s_tmp, "\tmovl (%%ebx), %%ebx\n");
          add_machine_code_x86( s_tmp );
    sprintf(s_tmp, "\tmovl (%%ebx), %%%s\n", R);
          add_machine_code_x86( s_tmp );
   } else {
    sprintf(s_tmp, "\tmovl (%%ebx), %%%s\n", R);
          add_machine_code_x86( s_tmp );
   }
   return;
  }
    }
}

variable_types:
R
char *

variable_types:
a
char *

user_defined_types: enum T { TYPE_FUNC=0, TYPE_VAR=1, TYPE_CONST=2, TYPE_TMP=3, TYPE_ARG=4 }


decompiled_code:
__int64 __fastcall store_x86(const char *a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // edx
__int64 result; // rax
int v5; // eax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = lookup(a2);
v3 = *(_DWORD *)(v2 + 12);
result = ncur;
if ( v3 == ncur )
{
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v6, "\tmovl -%d(%%ebp), %%edx\n", *(unsigned int *)(v2 + 8));
add_machine_code_x86(v6);
sprintf(v6, "\tmovl %%%s, (%%edx)\n", a1);
result = add_machine_code_x86(v6);
}
else
{
sprintf(v6, "\tmovl %%%s, -%d(%%ebp)\n", a1, *(unsigned int *)(v2 + 8));
result = add_machine_code_x86(v6);
}
}
else if ( v3 < ncur || *(_DWORD *)(v2 + 92) == 3 )
{
gnlvcode_x86(*(_QWORD *)v2);
v5 = *(_DWORD *)(v2 + 92);
if ( v5 == 3 || v5 == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v6, "\tmovl (%%ebx), %%ebx\n");
add_machine_code_x86(v6);
sprintf(v6, "\tmovl (%%ebx), %%%s\n", a1);
result = add_machine_code_x86(v6);
}
else
{
sprintf(v6, "\tmovl %%%s, (%%ebx)\n", a1);
result = add_machine_code_x86(v6);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // edx
__int64 result; // rax
int v5; // eax
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = lookup(a2);
v3 = *(_DWORD *)(v2 + 12);
result = ncur;
if ( v3 == ncur )
{
if ( *(_DWORD *)(v2 + 92) == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v6, "\tmovl -%d(%%ebp), %%edx\n", *(unsigned int *)(v2 + 8));
func2(v6);
sprintf(v6, "\tmovl %%%s, (%%edx)\n", a1);
result = func2(v6);
}
else
{
sprintf(v6, "\tmovl %%%s, -%d(%%ebp)\n", a1, *(unsigned int *)(v2 + 8));
result = func2(v6);
}
}
else if ( v3 < ncur || *(_DWORD *)(v2 + 92) == 3 )
{
func3(*(_QWORD *)v2);
v5 = *(_DWORD *)(v2 + 92);
if ( v5 == 3 || v5 == 4 && *(_DWORD *)(v2 + 56) == 1 )
{
sprintf(v6, "\tmovl (%%ebx), %%ebx\n");
func2(v6);
sprintf(v6, "\tmovl (%%ebx), %%%s\n", a1);
result = func2(v6);
}
else
{
sprintf(v6, "\tmovl %%%s, (%%ebx)\n", a1);
result = func2(v6);
}
}
return result;
}

original_code:
void store_x86( char *R, char *a ){
 char s_tmp[255];
 SYMBOL *p = lookup(a);
 if (p->level == ncur) {
  if (p->type == TYPE_ARG && p->arg.type == INOUT) {
   sprintf(s_tmp, "\tmovl -%d(%%ebp), %%edx\n", p->offset);
         add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl %%%s, (%%edx)\n", R);
         add_machine_code_x86( s_tmp );
  } else {
   sprintf(s_tmp, "\tmovl %%%s, -%d(%%ebp)\n", R, p->offset);
         add_machine_code_x86( s_tmp );
  }
  return;
 }else if (p->level < ncur || p->type == TYPE_TMP) {
  gnlvcode_x86(p->name);
  if ( p->type == TYPE_TMP || (p->type == TYPE_ARG && p->arg.type == INOUT)) {
   sprintf(s_tmp, "\tmovl (%%ebx), %%ebx\n");
         add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl (%%ebx), %%%s\n", R);
         add_machine_code_x86( s_tmp );
  } else {
   sprintf(s_tmp, "\tmovl %%%s, (%%ebx)\n", R);
         add_machine_code_x86( s_tmp );
  }
  return;
 }
}

canonical_original_code:
void store_x86(char *R, char *a){
 char s_tmp[255];
 struct symbol *p = lookup(a);
 if (p->level == ncur) {
  if (p->type == TYPE_ARG && p->arg.type == INOUT) {
   sprintf(s_tmp, "\tmovl -%d(%%ebp), %%edx\n", p->offset);
         add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl %%%s, (%%edx)\n", R);
         add_machine_code_x86( s_tmp );
  } else {
   sprintf(s_tmp, "\tmovl %%%s, -%d(%%ebp)\n", R, p->offset);
         add_machine_code_x86( s_tmp );
  }
  return;
 }else if (p->level < ncur || p->type == TYPE_TMP) {
  gnlvcode_x86(p->name);
  if ( p->type == TYPE_TMP || (p->type == TYPE_ARG && p->arg.type == INOUT)) {
   sprintf(s_tmp, "\tmovl (%%ebx), %%ebx\n");
         add_machine_code_x86( s_tmp );
   sprintf(s_tmp, "\tmovl (%%ebx), %%%s\n", R);
         add_machine_code_x86( s_tmp );
  } else {
   sprintf(s_tmp, "\tmovl %%%s, (%%ebx)\n", R);
         add_machine_code_x86( s_tmp );
  }
  return;
 }
}