main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char **v4; // rbx
FILE *v5; // rdi

if ( argc <= 1 )
return 0;
v3 = &argv[(unsigned int)(argc - 2) + 2];
v4 = argv + 1;
do
{
v5 = fopen(*v4, "r");
if ( !v5 )
{
fprintf(stderr, "File %s not found\n", *v4);
exit(1);
}
stemfile(v5);
++v4;
}
while ( v4 != v3 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char **v4; // rbx
FILE *v5; // rdi

if ( argc <= 1 )
return 0;
v3 = &argv[(unsigned int)(argc - 2) + 2];
v4 = argv + 1;
do
{
v5 = fopen(*v4, "r");
if ( !v5 )
{
fprintf(stderr, "File %s not found\n", *v4);
exit(1);
}
func15(v5);
++v4;
}
while ( v4 != v3 );
return 0;
}

original_code:
int main(void) {
    struct tnode *root = ((void *)0);
    char word[50] = "";
    char unstemmed[50] = "";
    int line = 1;
    while (getword(word, 50) != (-1))
        if (((*__ctype_b_loc ())[(int) ((word[0]))] & (unsigned short int) _ISalpha)) {
            lowerstr(word);
            if (isnotstopword(word)) {
                strncpy(unstemmed, word, 50);
                squeezechar(word, '\'');
                word[stem(word, 0, strlen(word) - 1) + 1] = '\0';
                root = treeadd(root, word, unstemmed, line);
            }
        } else if (word[0] == '\n')
            line++;
    treeprint(root);
    return 0;
}

canonical_original_code:
int main() {
    struct tnode *root = ((void *)0);
    char word[50] = "";
    char unstemmed[50] = "";
    int line = 1;
    while (getword(word, 50) != (-1))
        if (((*__ctype_b_loc ())[(int) ((word[0]))] & (unsigned short) _ISalpha)) {
            lowerstr(word);
            if (isnotstopword(word)) {
                strncpy(unstemmed, word, 50);
                squeezechar(word, '\'');
                word[stem(word, 0, strlen(word) - 1) + 1] = '\0';
                root = treeadd(root, word, unstemmed, line);
            }
        } else if (word[0] == '\n')
            line++;
    treeprint(root);
    return 0;
}

variable_types: struct tnode { char *word; int wordcount; struct linkwords { char *word; struct linkwords *next; } *words; struct linklist { int linenum; struct linklist *next; } *lines; struct tnode *left; struct tnode *right; } *

variable_types:
word
char [50]

variable_types:
unstemmed
char [50]

variable_types: line int

user_defined_types: struct tnode { char *word; int wordcount; struct linkwords *words; struct linklist *lines; struct tnode *left; struct tnode *right; }


printbits

repo: ptdecker/cbasics

decompiled_code:
int __fastcall printbits(int a1)
{
int v1; // ebx
int result; // eax

v1 = 32;
printf("0b");
do
{
while ( (a1 & (1 << --v1)) != 0 )
{
result = putchar(49);
if ( !v1 )
return result;
}
result = putchar(48);
}
while ( v1 );
return result;
}

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

v1 = 32;
printf("0b");
do
{
while ( (a1 & (1 << --v1)) != 0 )
{
result = putchar(49);
if ( !v1 )
return result;
}
result = putchar(48);
}
while ( v1 );
return result;
}

original_code:
static void printbits(unsigned x) {
    unsigned i;
    printf("0b");
    for(i = (unsigned)(8 * sizeof(int)); i > 0; i--)
        (_Bool)(x & (1 << (i - 1))) ? putchar('1') : putchar('0');
}

canonical_original_code:
static void printbits(unsigned int x) {
    unsigned int i;
    printf("0b");
    for(i = (unsigned int)(8 * sizeof(int)); i > 0; i--)
        (_Bool)(x & (1 << (i - 1))) ? putchar('1') : putchar('0');
}

variable_types:
x
unsigned int

variable_types:
i
unsigned int

return_type: void


repo: ptesarik/xcrash-scripts

decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
static inline int list_empty(const struct list_head_xcrash *head)
{
 return head->next == head;
}

canonical_original_code:
static inline int list_empty(struct list_head_xcrash *head)
{
 return head->next == head;
}

variable_types: struct list_head_xcrash { struct list_head_xcrash *next; } *

return_type: int


original_code:
static void
init_file(struct parsed_file *pf, const char *name)
{
 pf->name = name;
 INIT_LIST_HEAD(&pf->parsed);
 INIT_LIST_HEAD(&pf->raw);
 pf->loc.first.pf = pf;
 pf->loc.last.pf = pf;
 pf->clean = 1;
}

canonical_original_code:
static void init_file(struct parsed_file *pf, char *name)
{
 pf->name = name;
 INIT_LIST_HEAD(&pf->parsed);
 INIT_LIST_HEAD(&pf->raw);
 pf->loc.first.pf = pf;
 pf->loc.last.pf = pf;
 pf->clean = 1;
}

variable_types: struct parsed_file { char *name; struct list_head_xcrash { struct list_head_xcrash *next; } parsed; struct list_head_xcrash raw; struct loc { struct pos_t { struct parsed_file *pf; int line; unsigned short column; struct dynstr { struct list_head_xcrash list; struct list_head_xcrash node_first; struct list_head_xcrash dup_list; struct node { struct list_head_xcrash 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 *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[]; } *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 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[]; } *text; } first; struct loc *parent; } loc; int clean; } *

variable_types:
name
char *

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

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

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

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 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 macro_exp { int refcount; struct hashed_macro *hm; struct dynstr *first; struct dynstr *exp_first; struct { struct dynstr *first; } params[]; }

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


decompiled_code:
void *__fastcall get_basedir(void *src)
{
char *v1; // rax
void *v2; // r8
signed __int64 v3; // rbx
void *v4; // rax
_BYTE *v5; // rax

v1 = strrchr((const char *)src, 47);
v2 = &unk_C90;
if ( v1 )
{
v3 = v1 - (_BYTE *)src;
v4 = malloc(v1 - (_BYTE *)src + 2);
v5 = memcpy(v4, src, v3 + 1);
v5[v3 + 1] = 0;
v2 = v5;
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func9(void *src)
{
char *v1; // rax
void *v2; // r8
signed __int64 v3; // rbx
void *v4; // rax
_BYTE *v5; // rax

v1 = strrchr((const char *)src, 47);
v2 = &unk_C90;
if ( v1 )
{
v3 = v1 - (_BYTE *)src;
v4 = malloc(v1 - (_BYTE *)src + 2);
v5 = memcpy(v4, src, v3 + 1);
v5[v3 + 1] = 0;
v2 = v5;
}
return v2;
}

original_code:
static char *
get_basedir(const char *path)
{
 char *p, *ret;
 if ( (p = strrchr(path, '/')) ) {
  ret = malloc(p - path + 2);
  memcpy(ret, path, p - path + 1);
  ret[p - path + 1] = 0;
 } else
  ret = "./";
 return ret;
}

canonical_original_code:
static char *get_basedir(char *path)
{
 char *p; char *ret;
 if ( (p = strrchr(path, '/')) ) {
  ret = malloc(p - path + 2);
  memcpy(ret, path, p - path + 1);
  ret[p - path + 1] = 0;
 } else
  ret = "./";
 return ret;
}

variable_types:
path
char *

variable_types:
p
char *

variable_types:
ret
char *

return_type: char *


decompiled_code:
__int64 init_predef_types()
{
__int64 result; // rax
char **v1; // rbx
char *v2; // rdi

result = cleartypedefs();
if ( predef_types[0] )
{
v1 = predef_types;
do
{
result = addtypedef();
v2 = v1[1];
++v1;
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax
char **v1; // rbx
char *v2; // rdi

result = cleartypedefs();
if ( predef_types[0] )
{
v1 = predef_types;
do
{
result = addtypedef();
v2 = v1[1];
++v1;
}
while ( v2 );
}
return result;
}

original_code:
void init_predef_types(void)
{
 const char **p;
 cleartypedefs();
 for (p = predef_types; *p; ++p)
  addtypedef(*p);
}

canonical_original_code:
void init_predef_types()
{
 char **p;
 cleartypedefs();
 for (p = predef_types; *p; ++p)
  addtypedef(*p);
}

variable_types:
p
char **


decompiled_code:
__int64 __fastcall walk_tree(_QWORD **a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
_QWORD *v3; // rbx
_QWORD *v4; // rbp
__int64 v6; // r12
int i; // eax
__int64 v8; // rax
int v9; // ecx
__int64 v10; // rbx

v3 = *a1;
v4 = (_QWORD *)**a1;
if ( a1 == *a1 )
return 0LL;
v6 = (__int64)a1;
for ( i = a2(v3, a3); i != 1; i = a2(v3, a3) )
{
v8 = check_current_node_isra_0((__int64)v3, v6, v4[1]);
v10 = v8;
if ( v8 )
{
if ( v9 != 2 && (unsigned int)walk_children(v8, a2, a3) == 1 )
return 1LL;
v6 = v10;
}
v3 = v4;
if ( v4 == a1 )
return 0LL;
v4 = (_QWORD *)*v4;
}
return 1LL;
}

original_code:
enum walk_action
walk_tree(struct list_head_xcrash *tree, walkfn *fn, void *data)
{
 node_t *item, *next;
 struct list_head_xcrash *prev = tree;
 for (item = ({ const struct list_head_xcrash *__mptr = ((tree)->next); (typeof(*item) *)( (char *)__mptr - __builtin_offsetof (typeof(*item), list) );}), next = ({ const struct list_head_xcrash *__mptr = (item->list.next); (typeof(*item) *)( (char *)__mptr - __builtin_offsetof (typeof(*item), list) );}); &item->list != (tree); item = next, next = ({ const struct list_head_xcrash *__mptr = (next->list.next); (typeof(*next) *)( (char *)__mptr - __builtin_offsetof (typeof(*next), list) );})) {
  enum walk_action act = fn(item, data);
  if (act == walk_terminate)
   return walk_terminate;
  if (! (item = check_current_node(item, prev, &next->list)) )
   continue;
  if (act != walk_skip_children &&
      walk_children(item, fn, data) == walk_terminate)
   return walk_terminate;
  prev = &item->list;
 }
 return walk_continue;
}

canonical_original_code:
enum walk_action walk_tree(struct list_head_xcrash *tree, enum walk_action (*fn)(struct node *, void *), void *data)
{
 struct node *item; struct node *next;
 struct list_head_xcrash *prev = tree;
 for (item = ({ struct list_head_xcrash *__mptr = ((tree)->next); (typeof(*item) *)( (char *)__mptr - __builtin_offsetof (typeof(*item), list) );}), next = ({ struct list_head_xcrash *__mptr = (item->list.next); (typeof(*item) *)( (char *)__mptr - __builtin_offsetof (typeof(*item), list) );}); &item->list != (tree); item = next, next = ({ struct list_head_xcrash *__mptr = (next->list.next); (typeof(*next) *)( (char *)__mptr - __builtin_offsetof (typeof(*next), list) );})) {
  enum walk_action act = fn(item, data);
  if (act == walk_terminate)
   return walk_terminate;
  if (! (item = check_current_node(item, prev, &next->list)) )
   continue;
  if (act != walk_skip_children &&
      walk_children(item, fn, data) == walk_terminate)
   return walk_terminate;
  prev = &item->list;
 }
 return walk_continue;
}

variable_types: enum walk_action { walk_continue=0, walk_terminate=1, walk_skip_children=2 } (*)(struct node { struct list_head_xcrash 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[]; } *, void *)

variable_types:
data
void *

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

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


decompiled_code:
__int64 __fastcall walk_children(__int64 a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
int v3; // er14
_QWORD **i; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 184) <= 0 )
return 0LL;
v3 = 0;
for ( i = (_QWORD **)(a1 + 192); ; i += 2 )
{
result = walk_tree(i, a2, a3);
if ( (_DWORD)result == 1 )
break;
if ( *(_DWORD *)(a1 + 184) <= ++v3 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
int v3; // er14
_QWORD **i; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 184) <= 0 )
return 0LL;
v3 = 0;
for ( i = (_QWORD **)(a1 + 192); ; i += 2 )
{
result = func16(i, a2, a3);
if ( (_DWORD)result == 1 )
break;
if ( *(_DWORD *)(a1 + 184) <= ++v3 )
return 0LL;
}
return result;
}

original_code:
static inline enum walk_action
walk_children(node_t *node, walkfn *fn, void *data)
{
 int i;
 for (i = 0; i < node->nchild; ++i)
  if (walk_tree(&node->child[i], fn, data) == walk_terminate)
   return walk_terminate;
 return walk_continue;
}

canonical_original_code:
static inline enum walk_action walk_children(struct node *node, enum walk_action (*fn)(struct node *, void *), void *data)
{
 int i;
 for (i = 0; i < node->nchild; ++i)
  if (walk_tree(&node->child[i], fn, data) == walk_terminate)
   return walk_terminate;
 return walk_continue;
}

variable_types: enum walk_action { walk_continue=0, walk_terminate=1, walk_skip_children=2 } (*)(struct node *, void *)

variable_types: i 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; }


decompiled_code:
__int64 __fastcall walk_tree_single(__int64 *a1, __int64 (__fastcall *a2)(__int64 *, __int64), __int64 a3)
{
__int64 v4; // r13
__int64 v5; // rbx
__int64 result; // rax
__int64 v7; // rdi

v4 = a1[1];
v5 = *a1;
result = a2(a1, a3);
if ( (_DWORD)result != 1 )
{
if ( (_DWORD)result == 2 || (v7 = check_current_node_isra_0((__int64)a1, v4, *(_QWORD *)(v5 + 8))) == 0 )
result = 0LL;
else
result = walk_children(v7, a2, a3);
}
return result;
}

original_code:
enum walk_action
walk_tree_single(node_t *tree, walkfn *fn, void *data)
{
 struct list_head_xcrash *prev = tree->list.prev,
  *next = tree->list.next;
 switch (fn(tree, data)) {
 case walk_terminate: return walk_terminate;
 case walk_skip_children: return walk_continue;
 case walk_continue: break;
 }
 if (! (tree = check_current_node(tree, prev, next)) )
  return walk_continue;
 return walk_children(tree, fn, data);
}

canonical_original_code:
enum walk_action walk_tree_single(struct node *tree, enum walk_action (*fn)(struct node *, void *), void *data)
{
 struct list_head_xcrash *prev = tree->list.prev; struct list_head_xcrash *next = tree->list.next;
 switch (fn(tree, data)) {
 case walk_terminate: return walk_terminate;
 case walk_skip_children: return walk_continue;
 case walk_continue: break;
 }
 if (! (tree = check_current_node(tree, prev, next)) )
  return walk_continue;
 return walk_children(tree, fn, data);
}

return_type: enum walk_action { walk_continue=0, walk_terminate=1, walk_skip_children=2 }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
__int64 v4; // rcx
__int64 v5; // rax
int v6; // edx
int result; // eax
int v8; // [rsp+Ch] [rbp-3Ch] BYREF
void *input; // [rsp+10h] [rbp-38h] BYREF
__int64 v10[6]; // [rsp+18h] [rbp-30h] BYREF

INIT_LIST_HEAD(v10);
input = get_basedir((void *)*argv);
argp_parse(&argp, argc, (char **)argv, 0, &v8, &input);
files = argc - v8 + 1;
v3 = calloc(files, 0x68uLL);
qword_C88 = (__int64)v3;
if ( v3 )
{
init_builtin_file(v3);
if ( files > 1 )
{
v4 = 104LL;
do
{
v5 = v8++;
init_file((_QWORD *)(v4 + qword_C88), (__int64)argv[v5]);
}
while ( files > v6 );
}
result = xform_files(&input, &files);
}
else
{
perror("Cannot allocate file array");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rax
__int64 v4; // rcx
__int64 v5; // rax
int v6; // edx
int result; // eax
int v8; // [rsp+Ch] [rbp-3Ch] BYREF
void *input; // [rsp+10h] [rbp-38h] BYREF
__int64 v10[6]; // [rsp+18h] [rbp-30h] BYREF

func0(v10);
input = func9((void *)*argv);
argp_parse(&argp, argc, (char **)argv, 0, &v8, &input);
files = argc - v8 + 1;
v3 = calloc(files, 0x68uLL);
qword_C88 = (__int64)v3;
if ( v3 )
{
func10(v3);
if ( files > 1 )
{
v4 = 104LL;
do
{
v5 = v8++;
func7((_QWORD *)(v4 + qword_C88), (__int64)argv[v5]);
}
while ( files > v6 );
}
result = xform_files(&input, &files);
}
else
{
perror("Cannot allocate file array");
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 struct arguments arguments;
 int argf, i;
 INIT_LIST_HEAD(&arguments.xform_names);
 arguments.basedir = get_basedir(argv[0]);
 argp_parse(&argp, argc, argv, 0, &argf, &arguments);
 files.n = argc - argf + 1;
 if (! (files.array = calloc(files.n, sizeof(struct parsed_file))) ) {
  perror("Cannot allocate file array");
  return 1;
 }
 i = 0;
 init_builtin_file(&files.array[i++]);
 while(i < files.n)
  init_file(&files.array[i++], argv[argf++]);
 return xform_files(&arguments, &files);
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct arguments arguments;
 int argf; int i;
 INIT_LIST_HEAD(&arguments.xform_names);
 arguments.basedir = get_basedir(argv[0]);
 argp_parse(&argp, argc, argv, 0, &argf, &arguments);
 files.n = argc - argf + 1;
 if (! (files.array = calloc(files.n, sizeof(struct parsed_file))) ) {
  perror("Cannot allocate file array");
  return 1;
 }
 i = 0;
 init_builtin_file(&files.array[i++]);
 while(i < files.n)
  init_file(&files.array[i++], argv[argf++]);
 return xform_files(&arguments, &files);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct arguments { char *basedir; struct list_head_xcrash { struct list_head_xcrash *next; } xform_names; }

variable_types: argf int

user_defined_types: struct arguments { char *basedir; struct list_head_xcrash xform_names; }


canonical_decompiled_code:
_BOOL8 __fastcall func0(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}


decompiled_code:
__int64 __fastcall find_var_scope(__int64 a1)
{
const char **v1; // rbx
__int64 v2; // r12

v1 = *(const char ***)(a1 + 72);
v2 = find_scope(a1, 0LL);
if ( (const char **)v2 != v1 + 1 )
return v2;
if ( is_header_file_isra_0(*v1) )
v2 = 0LL;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
const char **v1; // rbx
__int64 v2; // r12

v1 = *(const char ***)(a1 + 72);
v2 = find_scope(a1, 0LL);
if ( (const char **)v2 != v1 + 1 )
return v2;
if ( func3(*v1) )
v2 = 0LL;
return v2;
}

original_code:
struct list_head_xcrash *
find_var_scope(node_t *node)
{
 struct parsed_file *pf = node->loc.first.pf;
 struct list_head_xcrash *tree = &pf->parsed;
 struct list_head_xcrash *scope = find_scope(node, ((void *)0));
 if (scope == tree && is_header_file(pf))
  return ((void *)0);
 return scope;
}

canonical_original_code:
struct list_head_xcrash *find_var_scope(struct node *node)
{
 struct parsed_file *pf = node->loc.first.pf;
 struct list_head_xcrash *tree = &pf->parsed;
 struct list_head_xcrash *scope = find_scope(node, ((void *)0));
 if (scope == tree && is_header_file(pf))
  return ((void *)0);
 return scope;
}

variable_types: struct node { struct list_head_xcrash 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[]; } *

return_type: struct list_head_xcrash { struct list_head_xcrash *next; } *


decompiled_code:
__int64 __fastcall varscope_add(__int64 a1)
{
__int64 v1; // rbp
__int64 *v2; // rcx
__int64 result; // rax
__int64 v4; // rdx

v1 = find_var_scope(a1);
malloc(0x18uLL);
LODWORD(result) = mkhash((_BYTE *)(*(_QWORD *)(a1 + 40) + 112LL), v1);
v2[1] = a1;
result = (unsigned int)result;
v2[2] = v1;
v4 = vshash[(unsigned int)result];
vshash[(unsigned int)result] = (__int64)v2;
*v2 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbp
__int64 *v2; // rcx
__int64 result; // rax
__int64 v4; // rdx

v1 = func5(a1);
malloc(0x18uLL);
LODWORD(result) = func1((_BYTE *)(*(_QWORD *)(a1 + 40) + 112LL), v1);
v2[1] = a1;
result = (unsigned int)result;
v2[2] = v1;
v4 = vshash[(unsigned int)result];
vshash[(unsigned int)result] = (__int64)v2;
*v2 = v4;
return result;
}

original_code:
static void
varscope_add(node_t *node)
{
 struct list_head_xcrash *scope = find_var_scope(node);
 struct varscope *vs = malloc(sizeof(struct varscope));
 unsigned idx = mkhash(node->str->text, scope);
 vs->next = vshash[idx];
 vs->node = node;
 vs->scope = scope;
 vshash[idx] = vs;
}

canonical_original_code:
static void varscope_add(struct node *node)
{
 struct list_head_xcrash *scope = find_var_scope(node);
 struct varscope *vs = malloc(sizeof(struct varscope));
 unsigned int idx = mkhash(node->str->text, scope);
 vs->next = vshash[idx];
 vs->node = node;
 vs->scope = scope;
 vshash[idx] = vs;
}

variable_types: struct list_head_xcrash { struct list_head_xcrash *next; } *

variable_types: struct varscope { struct varscope *next; 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[]; } *node; struct list_head_xcrash *scope; } *

variable_types:
idx
unsigned int

user_defined_types: struct varscope { struct varscope *next; struct node *node; struct list_head_xcrash *scope; }


decompiled_code:
__int64 __fastcall fill_varscope(__int64 a1)
{
int v1; // eax

v1 = *(_DWORD *)(a1 + 16);
if ( v1 == 2 )
{
if ( !*(_QWORD *)(a1 + 40) )
return 0LL;
}
else if ( v1
|| !*(_QWORD *)(a1 + 40)
|| (unsigned int)(*(_DWORD *)(a1 + 24) - 2) > 2
|| list_empty((_QWORD *)(a1 + 192)) )
{
return 0LL;
}
varscope_add(a1);
return 0LL;
}

original_code:
static enum walk_action
fill_varscope(node_t *node, void *data)
{
 if (node->type == nt_var && node->str)
  varscope_add(node);
 else if (node->type == nt_type && node->str &&
   (node->t.category == type_struct ||
    node->t.category == type_union ||
    node->t.category == type_enum) &&
   !list_empty(&node->child[cht_body]))
  varscope_add(node);
 return walk_continue;
}

canonical_original_code:
static enum walk_action fill_varscope(struct node *node, void *data)
{
 if (node->type == nt_var && node->str)
  varscope_add(node);
 else if (node->type == nt_type && node->str &&
   (node->t.category == type_struct ||
    node->t.category == type_union ||
    node->t.category == type_enum) &&
   !list_empty(&node->child[cht_body]))
  varscope_add(node);
 return walk_continue;
}

user_defined_types: enum walk_action { walk_continue=0, walk_terminate=1, walk_skip_children=2 }


decompiled_code:
void free_varscope()
{
char *v0; // rbp
_QWORD *v1; // rbx
void *v2; // rdi

v0 = (char *)vshash;
do
{
v1 = *(_QWORD **)v0;
if ( *(_QWORD *)v0 )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
}
*(_QWORD *)v0 = 0LL;
v0 += 8;
}
while ( v0 != "var " );
}

canonical_decompiled_code:
void func8()
{
char *v0; // rbp
_QWORD *v1; // rbx
void *v2; // rdi

v0 = (char *)vshash;
do
{
v1 = *(_QWORD **)v0;
if ( *(_QWORD *)v0 )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
free(v2);
}
while ( v1 );
}
*(_QWORD *)v0 = 0LL;
v0 += 8;
}
while ( v0 != "var " );
}

original_code:
void
free_varscope(void)
{
 unsigned idx;
 for (idx = 0; idx < 8192; ++idx) {
  struct varscope *vs, *vsnext;
  for (vs = vshash[idx]; vs; vs = vsnext) {
   vsnext = vs->next;
   free(vs);
  }
  vshash[idx] = ((void *)0);
 }
}

canonical_original_code:
void free_varscope()
{
 unsigned int idx;
 for (idx = 0; idx < 8192; ++idx) {
  struct varscope *vs; struct varscope *vsnext;
  for (vs = vshash[idx]; vs; vs = vsnext) {
   vsnext = vs->next;
   free(vs);
  }
  vshash[idx] = ((void *)0);
 }
}


decompiled_code:
__int64 __fastcall init_varscope(int *a1)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rdi

free_varscope();
v2 = *((_QWORD *)a1 + 1);
result = 104LL * *a1;
if ( result )
{
do
{
v4 = v2 + 8;
v2 += 104LL;
walk_tree(v4, fill_varscope, 0LL);
result = *((_QWORD *)a1 + 1) + 104LL * *a1;
}
while ( v2 != result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rdi

func8();
v2 = *((_QWORD *)a1 + 1);
result = 104LL * *a1;
if ( result )
{
do
{
v4 = v2 + 8;
v2 += 104LL;
walk_tree(v4, fill_varscope, 0LL);
result = *((_QWORD *)a1 + 1) + 104LL * *a1;
}
while ( v2 != result );
}
return result;
}

original_code:
void
init_varscope(const struct file_array *files)
{
 struct parsed_file *pf;
 free_varscope();
 for ((pf) = (files)->array; (pf) != &(files)->array[(files)->n]; ++(pf))
  walk_tree(&pf->parsed, fill_varscope, ((void *)0));
}

canonical_original_code:
void init_varscope(struct file_array *files)
{
 struct parsed_file *pf;
 free_varscope();
 for ((pf) = (files)->array; (pf) != &(files)->array[(files)->n]; ++(pf))
  walk_tree(&pf->parsed, fill_varscope, ((void *)0));
}

variable_types: struct file_array { int n; struct parsed_file { char *name; struct list_head_xcrash { struct list_head_xcrash *next; } parsed; struct list_head_xcrash raw; struct loc { struct pos_t { struct parsed_file *pf; int line; unsigned short column; struct dynstr { struct list_head_xcrash list; struct list_head_xcrash node_first; struct list_head_xcrash dup_list; struct node { struct list_head_xcrash 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 *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[]; } *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 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[]; } *text; } first; struct loc *parent; } loc; int clean; } *array; } *

user_defined_types: struct file_array { int n; struct parsed_file *array; }


decompiled_code:
__int64 __fastcall resolve_typedef(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

do
{
if ( *(_DWORD *)(a2 + 16) )
return a2;
if ( *(_DWORD *)(a2 + 24) != 1 )
return a2;
v2 = varscope_traverse(a1, a2, 2, (char *)(*(_QWORD *)(a2 + 40) + 112LL));
a2 = (__int64)v2;
if ( !v2 )
return a2;
a2 = first_node_isra_0(v2[24]);
}
while ( (*(_BYTE *)(a2 + 28) & 0x20) != 0 );
return 0LL;
}

original_code:
node_t *
resolve_typedef(struct list_head_xcrash *tree, node_t *type)
{
 while (type->type == nt_type && type->t.category == type_typedef) {
  node_t *var = varscope_traverse(tree, type,
      nt_var, type->str->text);
  if (!var)
   return ((void *)0);
  type = first_node(&var->child[chv_type]);
  if (! (type->t.flags & (1U << 5)))
   return ((void *)0);
 }
 return type;
}

canonical_original_code:
struct node *resolve_typedef(struct list_head_xcrash *tree, struct node *type)
{
 while (type->type == nt_type && type->t.category == type_typedef) {
  struct node *var = varscope_traverse(tree, type,
      nt_var, type->str->text);
  if (!var)
   return ((void *)0);
  type = first_node(&var->child[chv_type]);
  if (! (type->t.flags & (1U << 5)))
   return ((void *)0);
 }
 return type;
}

variable_types:
tree
struct list_head_xcrash *

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


decompiled_code:
__int64 __fastcall expr_type(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v5; // rax
_QWORD *v6; // rax
__int64 v7; // rdx

if ( *(_DWORD *)(a1 + 16) != 1 )
_assert_fail("expr->type == nt_expr", "varscope.c", 0xDFu, "expr_type");
if ( *(_DWORD *)(a1 + 24) == 335 )
{
v5 = first_node_isra_0(*(_QWORD *)(a1 + 192));
v6 = varscope_find_expr(v5);
if ( !v6 )
return 0LL;
if ( *((_DWORD *)v6 + 4) != 2 )
_assert_fail("var->type == nt_var", "varscope.c", 0xE5u, "expr_type");
if ( list_empty(v6 + 24) )
return 0LL;
v2 = first_node_isra_0(*(_QWORD *)(v7 + 192));
if ( *(_DWORD *)(v2 + 16) )
_assert_fail("type->type == nt_type", "varscope.c", 0xEBu, "expr_type");
if ( (unsigned int)(*(_DWORD *)(v2 + 24) - 5) > 1 )
_assert_fail(
"type->t.category == type_array || type->t.category == type_pointer",
"varscope.c",
0xEEu,
"expr_type");
}
else
{
v1 = varscope_find_expr(a1);
v2 = (__int64)v1;
if ( !v1 )
return 0LL;
if ( *((_DWORD *)v1 + 4) != 2 )
_assert_fail("var->type == nt_var", "varscope.c", 0xF7u, "expr_type");
}
if ( !list_empty((_QWORD *)(v2 + 192)) )
return first_node_isra_0(*(_QWORD *)(v3 + 192));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v5; // rax
_QWORD *v6; // rax
__int64 v7; // rdx

if ( *(_DWORD *)(a1 + 16) != 1 )
_assert_fail("expr->type == nt_expr", "varscope.c", 0xDFu, "expr_type");
if ( *(_DWORD *)(a1 + 24) == 335 )
{
v5 = func4(*(_QWORD *)(a1 + 192));
v6 = varscope_find_expr(v5);
if ( !v6 )
return 0LL;
if ( *((_DWORD *)v6 + 4) != 2 )
_assert_fail("var->type == nt_var", "varscope.c", 0xE5u, "expr_type");
if ( func0(v6 + 24) )
return 0LL;
v2 = func4(*(_QWORD *)(v7 + 192));
if ( *(_DWORD *)(v2 + 16) )
_assert_fail("type->type == nt_type", "varscope.c", 0xEBu, "expr_type");
if ( (unsigned int)(*(_DWORD *)(v2 + 24) - 5) > 1 )
_assert_fail(
"type->t.category == type_array || type->t.category == type_pointer",
"varscope.c",
0xEEu,
"expr_type");
}
else
{
v1 = varscope_find_expr(a1);
v2 = (__int64)v1;
if ( !v1 )
return 0LL;
if ( *((_DWORD *)v1 + 4) != 2 )
_assert_fail("var->type == nt_var", "varscope.c", 0xF7u, "expr_type");
}
if ( !func0((_QWORD *)(v2 + 192)) )
return func4(*(_QWORD *)(v3 + 192));
return 0LL;
}

original_code:
static node_t *
expr_type(node_t *expr)
{
 node_t *var, *type;
 ((void) sizeof ((expr->type == nt_expr) ? 1 : 0), __extension__ ({ if (expr->type == nt_expr) ; else __assert_fail ("expr->type == nt_expr", "varscope.c", 223, __extension__ __PRETTY_FUNCTION__); }));
 if (expr->e.op == ARRAY) {
  var = first_node(&expr->child[che_arg1]);
  if (! (var = varscope_find_expr(var)) )
   return ((void *)0);
  ((void) sizeof ((var->type == nt_var) ? 1 : 0), __extension__ ({ if (var->type == nt_var) ; else __assert_fail ("var->type == nt_var", "varscope.c", 229, __extension__ __PRETTY_FUNCTION__); }));
  if (list_empty(&var->child[chv_type]))
   return ((void *)0);
  type = first_node(&var->child[chv_type]);
  ((void) sizeof ((type->type == nt_type) ? 1 : 0), __extension__ ({ if (type->type == nt_type) ; else __assert_fail ("type->type == nt_type", "varscope.c", 235, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((type->t.category == type_array || type->t.category == type_pointer) ? 1 : 0), __extension__ ({ if (type->t.category == type_array || type->t.category == type_pointer) ; else __assert_fail ("type->t.category == type_array || type->t.category == type_pointer", "varscope.c", 238, __extension__ __PRETTY_FUNCTION__); }));
  return !list_empty(&type->child[cht_type])
   ? first_node(&type->child[cht_type])
   : ((void *)0);
 } else {
  if (! (var = varscope_find_expr(expr)) )
   return ((void *)0);
  ((void) sizeof ((var->type == nt_var) ? 1 : 0), __extension__ ({ if (var->type == nt_var) ; else __assert_fail ("var->type == nt_var", "varscope.c", 247, __extension__ __PRETTY_FUNCTION__); }));
  return !list_empty(&var->child[chv_type])
   ? first_node(&var->child[chv_type])
   : ((void *)0);
 }
}

canonical_original_code:
static struct node *expr_type(struct node *expr)
{
 struct node *var; struct node *type;
 ((void) sizeof ((expr->type == nt_expr) ? 1 : 0), __extension__ ({ if (expr->type == nt_expr) ; else __assert_fail ("expr->type == nt_expr", "varscope.c", 223, __extension__ __PRETTY_FUNCTION__); }));
 if (expr->e.op == ARRAY) {
  var = first_node(&expr->child[che_arg1]);
  if (! (var = varscope_find_expr(var)) )
   return ((void *)0);
  ((void) sizeof ((var->type == nt_var) ? 1 : 0), __extension__ ({ if (var->type == nt_var) ; else __assert_fail ("var->type == nt_var", "varscope.c", 229, __extension__ __PRETTY_FUNCTION__); }));
  if (list_empty(&var->child[chv_type]))
   return ((void *)0);
  type = first_node(&var->child[chv_type]);
  ((void) sizeof ((type->type == nt_type) ? 1 : 0), __extension__ ({ if (type->type == nt_type) ; else __assert_fail ("type->type == nt_type", "varscope.c", 235, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((type->t.category == type_array || type->t.category == type_pointer) ? 1 : 0), __extension__ ({ if (type->t.category == type_array || type->t.category == type_pointer) ; else __assert_fail ("type->t.category == type_array || type->t.category == type_pointer", "varscope.c", 238, __extension__ __PRETTY_FUNCTION__); }));
  return !list_empty(&type->child[cht_type])
   ? first_node(&type->child[cht_type])
   : ((void *)0);
 } else {
  if (! (var = varscope_find_expr(expr)) )
   return ((void *)0);
  ((void) sizeof ((var->type == nt_var) ? 1 : 0), __extension__ ({ if (var->type == nt_var) ; else __assert_fail ("var->type == nt_var", "varscope.c", 247, __extension__ __PRETTY_FUNCTION__); }));
  return !list_empty(&var->child[chv_type])
   ? first_node(&var->child[chv_type])
   : ((void *)0);
 }
}

variable_types:
expr
struct node *

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 varscope_symbol(int *a1, const char *a2)
{
size_t v2; // rdx
void *v3; // rsp
char *v4; // rax
char *v5; // rbx
__int64 v6; // rax
__int64 v7; // r13
__int64 v8; // r12
char *v9; // r14
char *v10; // rax
_QWORD *v11; // rsi
char v13; // [rsp+1h] [rbp-41h] BYREF
char v14[8]; // [rsp+2h] [rbp-40h] BYREF
__int64 v15; // [rsp+Ah] [rbp-38h]

v2 = strlen(a2) + 1;
v3 = alloca(v2);
memcpy(v14, a2, v2);
v4 = strchr(v14, 58);
if ( v4 )
{
*v4 = 0;
v5 = v4;
v6 = find_file(a1, v14);
if ( !v6 )
return 0LL;
v15 = v6 + 8;
}
else
{
v15 = 0LL;
v5 = &v13;
}
v7 = v15;
v8 = 0LL;
while ( 1 )
{
v9 = v5 + 1;
v10 = strchr(v5 + 1, 46);
v5 = v10;
if ( v10 )
*v10 = 0;
if ( v8 )
v7 = node_scope(v8);
v11 = find_symbol(a1, v7, v9);
if ( !v11 )
break;
v8 = resolve_typedef(v15, (__int64)v11);
if ( !v8 )
break;
if ( !v5 || !v5[1] )
return v8;
}
return 0LL;
}

original_code:
node_t *
varscope_symbol(const struct file_array *files, const char *name)
{
 struct list_head_xcrash *tree;
 char localname[strlen(name) + 1];
 char *spec, *sep;
 spec = localname;
 strcpy(spec, name);
 if ( (sep = strchr(spec, ':')) ) {
  struct parsed_file *pf;
  *sep = 0;
  if (! (pf = find_file(files, spec)) )
   return ((void *)0);
  tree = &pf->parsed;
 } else {
  sep = spec - 1;
  tree = ((void *)0);
 }
 struct list_head_xcrash *scope = tree;
 node_t *node = ((void *)0);
 do {
  spec = sep + 1;
  if ( (sep = strchr(spec, '.')) )
   *sep = 0;
  if (node)
   scope = node_scope(node);
  if (! (node = find_symbol(files, scope, spec)) )
   return ((void *)0);
  if (! (node = resolve_typedef(tree, node)) )
   return ((void *)0);
 } while (sep && sep[1]);
 return node;
}

canonical_original_code:
struct node *varscope_symbol(struct file_array *files, char *name)
{
 struct list_head_xcrash *tree;
 char localname[-1];
 char *spec; char *sep;
 spec = localname;
 strcpy(spec, name);
 if ( (sep = strchr(spec, ':')) ) {
  struct parsed_file *pf;
  *sep = 0;
  if (! (pf = find_file(files, spec)) )
   return ((void *)0);
  tree = &pf->parsed;
 } else {
  sep = spec - 1;
  tree = ((void *)0);
 }
 struct list_head_xcrash *scope = tree;
 struct node *node = ((void *)0);
 do {
  spec = sep + 1;
  if ( (sep = strchr(spec, '.')) )
   *sep = 0;
  if (node)
   scope = node_scope(node);
  if (! (node = find_symbol(files, scope, spec)) )
   return ((void *)0);
  if (! (node = resolve_typedef(tree, node)) )
   return ((void *)0);
 } while (sep && sep[1]);
 return node;
}

variable_types: struct file_array { int n; struct parsed_file *array; } *

variable_types:
name
char *

variable_types:
localname
char [-1]

variable_types:
spec
char *

variable_types:
sep
char *

variable_types: struct parsed_file { char *name; struct list_head_xcrash { struct list_head_xcrash *next; } parsed; struct list_head_xcrash raw; struct loc { struct pos_t { struct parsed_file *pf; int line; unsigned short column; struct dynstr { struct list_head_xcrash list; struct list_head_xcrash node_first; struct list_head_xcrash dup_list; struct node { struct list_head_xcrash 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 *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[]; } *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 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[]; } *text; } first; struct loc *parent; } loc; int clean; } *

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


decompiled_code:
_BOOL8 __fastcall ind_is_pointer(char a1)
{
return (a1 & 0xFD) == 0xFD;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char a1)
{
return (a1 & 0xFD) == 0xFD;
}

original_code:
static inline int
ind_is_pointer(ind_t ind)
{
 return (ind == ind_pointer || ind == ind_implicit);
}

canonical_original_code:
static inline int ind_is_pointer(char ind)
{
 return (ind == ind_pointer || ind == ind_implicit);
}

variable_types: ind char


decompiled_code:
__int64 __fastcall kr_param_type(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 v4; // rax
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 48);
if ( !v2 )
return 0LL;
v3 = *(_QWORD *)(v2 + 48);
if ( !v3 )
return 0LL;
v4 = varscope_find(v3 + 240, 2LL, a2);
if ( v4 )
result = nth_node(v4 + 192, 1LL);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 v4; // rax
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 48);
if ( !v2 )
return 0LL;
v3 = *(_QWORD *)(v2 + 48);
if ( !v3 )
return 0LL;
v4 = varscope_find(v3 + 240, 2LL, a2);
if ( v4 )
result = nth_node(v4 + 192, 1LL);
else
result = 0LL;
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: 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 pos_t { struct parsed_file *pf; int line; unsigned short column; struct dynstr *text; }


decompiled_code:
__int64 __fastcall func_arg_type(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // rcx
__int64 v7; // rdx
__int64 v8; // rsi
__int64 v9; // rdx
__int64 v10; // rcx

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // rcx
__int64 v7; // rdx
__int64 v8; // rsi
__int64 v9; // rdx
__int64 v10; // rcx

v2 = nth_node(a1 + 208, a2);
if ( !v2 )
return 0LL;
if ( *(_DWORD *)(v2 + 16) != 3 )
_assert_fail("decl->type == nt_decl", "indirect.c", 0x48u, "func_arg_type");
result = func2(*(_QWORD *)(v2 + 192));
if ( result == v5 )
{
v6 = func2(*(_QWORD *)(v4 + 208));
if ( v6 == v7 + 208 )
_assert_fail("&var->list != &decl->child[chd_var]", "indirect.c", 0x4Fu, "func_arg_type");
v8 = v6 + 192;
result = func2(*(_QWORD *)(v6 + 192));
if ( result == v8 )
result = func1(*(_QWORD *)(v9 + 48), *(_QWORD *)(v10 + 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 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[]; }


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

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

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

if ( *(_DWORD *)(a1 + 24) == 7 )
result = func2(*(_QWORD *)(a1 + 192));
else
result = 0LL;
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);
}

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


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

if ( (unsigned int)(*(_DWORD *)(a1 + 24) - 5) > 1 )
result = 0LL;
else
result = first_node_isra_0(*(_QWORD *)(a1 + 192));
return result;
}

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

if ( (unsigned int)(*(_DWORD *)(a1 + 24) - 5) > 1 )
result = 0LL;
else
result = func2(*(_QWORD *)(a1 + 192));
return result;
}

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 macro_exp { int refcount; struct hashed_macro *hm; struct dynstr *first; struct dynstr *exp_first; struct { struct dynstr *first; } params[]; }


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 )
{
if ( v5 != 7 )
_assert_fail("0", "indirect.c", 0x19u, "build_ind");
v3 = -2;
}
else
{
v3 = -1;
}
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 )
{
if ( v5 != 7 )
_assert_fail("0", "indirect.c", 0x19u, "build_ind");
v3 = -2;
}
else
{
v3 = -1;
}
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 **

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


decompiled_code:
__int64 __fastcall ind_base_type(__int64 a1, char *a2)
{
char v2; // dl
char *v3; // rbx
__int64 v4; // r8
__int64 v5; // rsi
char v6; // dl
__int64 v7; // r8

v2 = *a2;
if ( *a2 )
{
v3 = a2;
while ( 1 )
{
v5 = (unsigned int)v2;
if ( ind_is_pointer(v2) )
break;
if ( v6 != -2 )
{
v4 = func_arg_type(v7, v5);
LABEL_4:
if ( !v4 )
return v4;
goto LABEL_5;
}
v4 = func_return_type(v7);
if ( !v4 )
return v4;
LABEL_5:
v2 = *++v3;
if ( !v2 )
return v4;
}
v4 = array_base_type(v7);
goto LABEL_4;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2)
{
char v2; // dl
char *v3; // rbx
__int64 v4; // r8
__int64 v5; // rsi
char v6; // dl
__int64 v7; // r8

v2 = *a2;
if ( *a2 )
{
v3 = a2;
while ( 1 )
{
v5 = (unsigned int)v2;
if ( func0(v2) )
break;
if ( v6 != -2 )
{
v4 = func3(v7, v5);
LABEL_4:
if ( !v4 )
return v4;
goto LABEL_5;
}
v4 = func4(v7);
if ( !v4 )
return v4;
LABEL_5:
v2 = *++v3;
if ( !v2 )
return v4;
}
v4 = func5(v7);
goto LABEL_4;
}
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 *

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


decompiled_code:
_BOOL8 __fastcall is_host_type(__int64 a1, char *a2)
{
__int64 v4; // rcx
_BOOL8 result; // rax
__int64 v6; // rdi
__int64 v7; // rdi
__int64 v8; // rdi
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rdi
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax

while ( 2 )
{
while ( 1 )
{
v4 = *(unsigned int *)(a1 + 24);
if ( (int)v4 <= 126 )
break;
switch ( (int)v4 )
{
case 269:
case 270:
goto LABEL_21;
case 273:
case 321:
goto LABEL_16;
case 280:
a1 = first_node_isra_0(*(_QWORD *)(a1 + 192));
if ( !ind_is_pointer(*a2) )
goto LABEL_14;
++a2;
break;
case 281:
case 335:
--a2;
v15 = first_node_isra_0(*(_QWORD *)(a1 + 192));
*a2 = -1;
a1 = v15;
continue;
case 299:
case 317:
case 318:
case 319:
case 341:
goto LABEL_10;
case 320:
goto LABEL_14;
case 338:
v9 = first_node_isra_0(*(_QWORD *)(a1 + 192));
v10 = varscope_find_expr(v9);
if ( !v10 )
goto LABEL_14;
v11 = first_node_isra_0(*(_QWORD *)(v10 + 192));
if ( *(_DWORD *)(v11 + 24) != 7 )
_assert_fail("type->t.category == type_func", "indirect.c", 0xC9u, "is_host_type");
v12 = nth_node(v11 + 192, 1LL);
if ( !v12 )
goto LABEL_14;
goto LABEL_18;
case 342:
goto LABEL_9;
default:
goto LABEL_4;
}
}
if ( (int)v4 > 32 )
{
switch ( (int)v4 )
{
case '!':
goto LABEL_14;
case '%':
case '/':
case '~':
LABEL_21:
a1 = first_node_isra_0(*(_QWORD *)(a1 + 192));
continue;
case '&':
case '*':
case '+':
case '-':
case '^':
case '|':
v6 = a1 + 192;
goto LABEL_7;
case '.':
LABEL_16:
v13 = varscope_find_expr(a1);
if ( !v13 )
goto LABEL_14;
v12 = first_node_isra_0(*(_QWORD *)(v13 + 192));
LABEL_18:
v14 = ind_base_type(v12, a2);
if ( !v14 )
goto LABEL_14;
result = (unsigned int)(*(_DWORD *)(v14 + 24) - 5) <= 1;
break;
case '?':
v6 = a1 + 224;
LABEL_7:
v7 = nth_node(v6, 1LL);
if ( v7 && (unsigned int)is_host_type(v7, a2) )
{
LABEL_14:
result = 1LL;
}
else
{
LABEL_9:
v8 = nth_node(a1 + 208, 1LL);
if ( v8 )
result = (unsigned int)is_host_type(v8, a2) != 0;
else
LABEL_10:
result = 0LL;
}
break;
default:
goto LABEL_4;
}
}
else
{
LABEL_4:
fprintf(stderr, "%s: Operator %d not yet handled\n", "is_host_type", v4);
result = 1LL;
}
return result;
}
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(__int64 a1, char *a2)
{
__int64 v4; // rcx
_BOOL8 result; // rax
__int64 v6; // rdi
__int64 v7; // rdi
__int64 v8; // rdi
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rdi
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax

while ( 2 )
{
while ( 1 )
{
v4 = *(unsigned int *)(a1 + 24);
if ( (int)v4 <= 126 )
break;
switch ( (int)v4 )
{
case 269:
case 270:
goto LABEL_21;
case 273:
case 321:
goto LABEL_16;
case 280:
a1 = func2(*(_QWORD *)(a1 + 192));
if ( !func0(*a2) )
goto LABEL_14;
++a2;
break;
case 281:
case 335:
--a2;
v15 = func2(*(_QWORD *)(a1 + 192));
*a2 = -1;
a1 = v15;
continue;
case 299:
case 317:
case 318:
case 319:
case 341:
goto LABEL_10;
case 320:
goto LABEL_14;
case 338:
v9 = func2(*(_QWORD *)(a1 + 192));
v10 = varscope_find_expr(v9);
if ( !v10 )
goto LABEL_14;
v11 = func2(*(_QWORD *)(v10 + 192));
if ( *(_DWORD *)(v11 + 24) != 7 )
_assert_fail("type->t.category == type_func", "indirect.c", 0xC9u, "is_host_type");
v12 = nth_node(v11 + 192, 1LL);
if ( !v12 )
goto LABEL_14;
goto LABEL_18;
case 342:
goto LABEL_9;
default:
goto LABEL_4;
}
}
if ( (int)v4 > 32 )
{
switch ( (int)v4 )
{
case '!':
goto LABEL_14;
case '%':
case '/':
case '~':
LABEL_21:
a1 = func2(*(_QWORD *)(a1 + 192));
continue;
case '&':
case '*':
case '+':
case '-':
case '^':
case '|':
v6 = a1 + 192;
goto LABEL_7;
case '.':
LABEL_16:
v13 = varscope_find_expr(a1);
if ( !v13 )
goto LABEL_14;
v12 = func2(*(_QWORD *)(v13 + 192));
LABEL_18:
v14 = func7(v12, a2);
if ( !v14 )
goto LABEL_14;
result = (unsigned int)(*(_DWORD *)(v14 + 24) - 5) <= 1;
break;
case '?':
v6 = a1 + 224;
LABEL_7:
v7 = nth_node(v6, 1LL);
if ( v7 && (unsigned int)func8(v7, a2) )
{
LABEL_14:
result = 1LL;
}
else
{
LABEL_9:
v8 = nth_node(a1 + 208, 1LL);
if ( v8 )
result = (unsigned int)func8(v8, a2) != 0;
else
LABEL_10:
result = 0LL;
}
break;
default:
goto LABEL_4;
}
}
else
{
LABEL_4:
fprintf(stderr, "%s: Operator %d not yet handled\n", "is_host_type", v4);
result = 1LL;
}
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;
}

user_defined_types: struct list_head_xcrash { struct list_head_xcrash *next; }


socketHandler

repo: pthrasher/fido

decompiled_code:
void *__fastcall socketHandler(void *a1)
{
int *v1; // rbp
__int64 v2; // rbx
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, &v4, 5uLL, 0) > 0 )
{
v7 = 101;
buf = v4;
switch ( v5 )
{
case 'r':
v7 = (unsigned __int8)bit_array_test(v2) == 0 ? 117 : 115;
break;
case 's':
bit_array_set_true(v2);
v7 = 115;
break;
case 'u':
bit_array_set_false(v2);
v7 = 117;
break;
}
send(*v1, &buf, 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; // rbp
__int64 v2; // rbx
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, &v4, 5uLL, 0) > 0 )
{
v7 = 101;
buf = v4;
switch ( v5 )
{
case 'r':
v7 = (unsigned __int8)bit_array_test(v2) == 0 ? 117 : 115;
break;
case 's':
bit_array_set_true(v2);
v7 = 115;
break;
case 'u':
bit_array_set_false(v2);
v7 = 117;
break;
}
send(*v1, &buf, 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 v5; // eax
__int16 v6; // ax
int v7; // edi
socklen_t v8; // edx
int optval; // [rsp+8h] [rbp-20h] BYREF
int v11[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
int __fastcall func2(int *a1, __int64 a2, __int16 a3)
{
int v5; // eax
__int16 v6; // ax
int v7; // edi
socklen_t v8; // edx
int optval; // [rsp+8h] [rbp-20h] BYREF
int v11[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5 = socket(2, 1, 0);
*a1 = v5;
optval = 1;
v11[0] = 1;
setsockopt(v5, 1, 2, &optval, 4u);
setsockopt(*a1, 1, 9, v11, 4u);
*(_WORD *)a2 = 2;
v6 = func0(a3);
*(_QWORD *)(a2 + 8) = 0LL;
*(_DWORD *)(a2 + 4) = 0;
v7 = *a1;
*(_WORD *)(a2 + 2) = v6;
bind(v7, (const struct sockaddr *)a2, v8);
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

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

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_DWORD *v3; // rbx
int v4; // eax
int *v5; // rax
int fd; // [rsp+0h] [rbp-68h] BYREF
socklen_t addr_len; // [rsp+4h] [rbp-64h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
char v9[16]; // [rsp+10h] [rbp-58h] BYREF
char v10[16]; // [rsp+20h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-38h] BYREF
__int64 arg[5]; // [rsp+40h] [rbp-28h] BYREF

bit_array_init(v9, argv, envp);
bit_array_set_num_bits(v9, 0xFFFFFFFFLL);
bit_array_set_all_false(v9);
newthread = 0LL;
addr_len = 16;
hostSocketInitAndBind(&fd, (__int64)v10, 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.");
arg[0] = (__int64)v3;
arg[1] = (__int64)v9;
pthread_create(&newthread, 0LL, socketHandler, arg);
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
int fd; // [rsp+0h] [rbp-68h] BYREF
socklen_t addr_len; // [rsp+4h] [rbp-64h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-60h] BYREF
char v9[16]; // [rsp+10h] [rbp-58h] BYREF
char v10[16]; // [rsp+20h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-38h] BYREF
__int64 arg[5]; // [rsp+40h] [rbp-28h] BYREF

bit_array_init(v9, argv, envp);
bit_array_set_num_bits(v9, 0xFFFFFFFFLL);
bit_array_set_all_false(v9);
newthread = 0LL;
addr_len = 16;
func2(&fd, (__int64)v10, 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.");
arg[0] = (__int64)v3;
arg[1] = (__int64)v9;
pthread_create(&newthread, 0LL, socketHandler, arg);
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


decompiled_code:
void __fastcall bit_array_init(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func6(_QWORD *a1)
{
*a1 = 0LL;
a1[1] = 0LL;
}

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)
{
unsigned int v3; // eax
void *v4; // rdi
void *v5; // rax

*(_DWORD *)(a1 + 8) = a2;
v3 = num_slots_for(a2);
v4 = *(void **)a1;
*(_DWORD *)(a1 + 12) = v3;
v5 = allocate_slots_for_isra_0(v4, v3);
*(_QWORD *)a1 = v5;
return v5 != 0LL;
}

canonical_decompiled_code:
bool __fastcall func8(__int64 a1, unsigned int a2)
{
unsigned int v3; // eax
void *v4; // rdi
void *v5; // rax

*(_DWORD *)(a1 + 8) = a2;
v3 = func0(a2);
v4 = *(void **)a1;
*(_DWORD *)(a1 + 12) = v3;
v5 = func5(v4, v3);
*(_QWORD *)a1 = v5;
return v5 != 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:
__int64 __fastcall bit_array_toggle_all(__int64 a1)
{
__int64 result; // rax
_QWORD *v2; // rdx
__int64 v3; // rcx
__int64 v4; // rcx

result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result )
{
v2 = *(_QWORD **)a1;
v3 = (unsigned int)(result - 1);
result = *(_QWORD *)a1 + 8LL;
v4 = result + 8 * v3;
while ( 1 )
{
*v2 = ~*v2;
v2 = (_QWORD *)result;
if ( result == v4 )
break;
result += 8LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 result; // rax
_QWORD *v2; // rdx
__int64 v3; // rcx
__int64 v4; // rcx

result = *(unsigned int *)(a1 + 12);
if ( (_DWORD)result )
{
v2 = *(_QWORD **)a1;
v3 = (unsigned int)(result - 1);
result = *(_QWORD *)a1 + 8LL;
v4 = result + 8 * v3;
while ( 1 )
{
*v2 = ~*v2;
v2 = (_QWORD *)result;
if ( result == v4 )
break;
result += 8LL;
}
}
return result;
}

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(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
_QWORD *v3; // r8
__int64 v4; // rdx

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

canonical_decompiled_code:
bool __fastcall func15(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
_QWORD *v3; // r8
__int64 v4; // rdx

func1(a2);
v2 = func3(a2);
return (*(_QWORD *)(*v3 + 8 * v4) & v2) != 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; // er13
int v4; // er12
int v5; // eax

v3 = 0;
v4 = 0;
opterr = 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 == 104 )
{
v4 = 0;
help();
return v4;
}
v3 = 1;
if ( v5 != 105 )
goto LABEL_12;
}
else if ( v5 == 63 )
{
if ( optopt != 97 )
return 1;
v4 = 1;
fprintf(stderr, "Option -%c requires an argument.\n", 97LL);
fwrite("Setting to default assembly [metasym].\n", 1uLL, 0x27uLL, stderr);
assembly = strdup("metasim");
}
else
{
if ( v5 != 97 )
LABEL_12:
abort();
v4 = 1;
assembly = optarg;
}
}
if ( argc > optind )
{
v4 = 0;
printf("Non-option argument %s\n", argv[optind]);
}
else
{
parse();
if ( v3 )
printquads();
if ( v4 )
{
v4 = strcmp(assembly, "x86");
if ( v4 )
{
generate_final();
v4 = 0;
print_machine_code();
}
else
{
generate_final_x86();
print_machine_code_x86();
}
}
}
return v4;
}

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

v3 = 0;
v4 = 0;
opterr = 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 == 104 )
{
v4 = 0;
func0();
return v4;
}
v3 = 1;
if ( v5 != 105 )
goto LABEL_12;
}
else if ( v5 == 63 )
{
if ( optopt != 97 )
return 1;
v4 = 1;
fprintf(stderr, "Option -%c requires an argument.\n", 97LL);
fwrite("Setting to default assembly [metasym].\n", 1uLL, 0x27uLL, stderr);
assembly = strdup("metasim");
}
else
{
if ( v5 != 97 )
LABEL_12:
abort();
v4 = 1;
assembly = optarg;
}
}
if ( argc > optind )
{
v4 = 0;
printf("Non-option argument %s\n", argv[optind]);
}
else
{
parse();
if ( v3 )
printquads();
if ( v4 )
{
v4 = strcmp(assembly, "x86");
if ( v4 )
{
generate_final();
v4 = 0;
print_machine_code();
}
else
{
generate_final_x86();
print_machine_code_x86();
}
}
}
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; // er8
_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; // er8
_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