decompiled_code:
int __fastcall clear_hashtable(void *ptr)
{
void *v1; // r14
char *v2; // r13
char *v3; // r12
int v4; // ebp
_QWORD *v5; // rbx
void *v6; // rdi

v1 = ptr;
v2 = (char *)ptr + 1048;
v3 = (char *)ptr;
v4 = 0;
do
{
v5 = *(_QWORD **)v3;
if ( *(_QWORD *)v3 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[1];
++v4;
release(v6);
}
while ( v5 );
}
v3 += 8;
}
while ( v3 != v2 );
free(v1);
return printf("%d items released.\n", (unsigned int)(v4 + 1));
}

canonical_decompiled_code:
int __fastcall func4(void *ptr)
{
void *v1; // r14
char *v2; // r13
char *v3; // r12
int v4; // ebp
_QWORD *v5; // rbx
void *v6; // rdi

v1 = ptr;
v2 = (char *)ptr + 1048;
v3 = (char *)ptr;
v4 = 0;
do
{
v5 = *(_QWORD **)v3;
if ( *(_QWORD *)v3 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[1];
++v4;
func1(v6);
}
while ( v5 );
}
v3 += 8;
}
while ( v3 != v2 );
free(v1);
return printf("%d items released.\n", (unsigned int)(v4 + 1));
}

original_code:
void clear_hashtable(hashtable ht){
 int i,count = 0;
 for(i=0;i<131;i++){
  if(ht[i]){
   entry e = ht[i];
   while(e){
    entry te = e;
    e = e->next;
    release(te);
    count++;
   }
  }
 }
 free(ht);
 count++;
 printf("%d items released.\n",count);
}

canonical_original_code:
void clear_hashtable(struct _entry **ht){
 int i; int count = 0;
 for(i=0;i<131;i++){
  if(ht[i]){
   struct _entry *e = ht[i];
   while(e){
    struct _entry *te = e;
    e = e->next;
    release(te);
    count++;
   }
  }
 }
 free(ht);
 count++;
 printf("%d items released.\n",count);
}

variable_types: count int

user_defined_types: struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; }


main

canonical_name: main

repo: phrack-lp/miniComplier

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init_system(argc, argv, envp);
program();
return 0;
}

original_code:
int main(){
 init_system();
 program();
 return 0;
}

return_type: int


decompiled_code:
__int64 init_system()
{
symbol = init_hashtable();
TYPE_INT = Type(&unk_248, 257LL, 4LL);
TYPE_CHAR = Type("char", 257LL, 1LL);
TYPE_FLOAT = Type("float", 257LL, 8LL);
and = Word("&&", 256LL);
or = Word("||", 271LL);
eq = Word("==", 261LL);
ne = Word("!=", 269LL);
le = Word("<=", 267LL);
ge = Word(">=", 263LL);
qword_1D0 = Word("if", 265LL);
While = Word("while", 275LL);
Else = Word("else", 260LL);
minus = Word("-", 268LL);
True = Word("true", 274LL);
False = Word("false", 262LL);
tmp = Word("t", 273LL);
put_in_hashtable(symbol, qword_1D0);
put_in_hashtable(symbol, Else);
return put_in_hashtable(symbol, While);
}

canonical_decompiled_code:
__int64 func0()
{
symbol = init_hashtable();
TYPE_INT = Type(&unk_248, 257LL, 4LL);
TYPE_CHAR = Type("char", 257LL, 1LL);
TYPE_FLOAT = Type("float", 257LL, 8LL);
and = Word("&&", 256LL);
or = Word("||", 271LL);
eq = Word("==", 261LL);
ne = Word("!=", 269LL);
le = Word("<=", 267LL);
ge = Word(">=", 263LL);
qword_1D0 = Word("if", 265LL);
While = Word("while", 275LL);
Else = Word("else", 260LL);
minus = Word("-", 268LL);
True = Word("true", 274LL);
False = Word("false", 262LL);
tmp = Word("t", 273LL);
put_in_hashtable(symbol, qword_1D0);
put_in_hashtable(symbol, Else);
return put_in_hashtable(symbol, While);
}

original_code:
void init_system(){
 symbol = init_hashtable();
 TYPE_INT = Type("int",257,4);
 TYPE_CHAR = Type("char",257,1);
 TYPE_FLOAT = Type("float",257,8);
 and = Word("&&",256);
 or = Word("||",271);
 eq = Word("==",261);
 ne = Word("!=",269);
 le = Word("<=",267);
 ge = Word(">=",263);
 If = Word("if",265);
 While = Word("while",275);
 Else = Word("else",260);
 minus = Word("-",268);
 True = Word("true",274);
 False = Word("false",262);
 tmp = Word("t",273);
 put_in_hashtable(symbol,If);
 put_in_hashtable(symbol,Else);
 put_in_hashtable(symbol,While);
}

return_type: void


move

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

result = get_token();
look = result;
return result;
}

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

result = get_token();
look = result;
return result;
}

original_code:
static inline void move()
{
 look = get_token();
}


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
printf("near line %d : %s\n", line, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
printf("near line %d : %s\n", line, a1);
exit(1);
}

original_code:
static inline void error(char* s){
 printf("near line %d : %s\n",line,s);
 exit(1);
}

canonical_original_code:
static inline void error(char *s){
 printf("near line %d : %s\n",line,s);
 exit(1);
}

variable_types:
s
char *


match

decompiled_code:
__int64 __fastcall match(int a1)
{
if ( *(_DWORD *)look != a1 )
error("syntax error");
return move();
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
if ( *(_DWORD *)look != a1 )
func1("syntax error");
return func0();
}

original_code:
static inline void match(int t){
 if(look->tag == t)
  move();
 else
  error("syntax error");
}

variable_types: t int


dims

decompiled_code:
__int64 dims()
{
__int64 v0; // rbx
__int64 result; // rax

do
{
match(91);
v0 = look;
match(270);
printf("[%d]", *(unsigned int *)(v0 + 8));
match(93);
result = look;
}
while ( *(_DWORD *)look == 91 );
return result;
}

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

do
{
func2(91);
v0 = look;
func2(270);
printf("[%d]", *(unsigned int *)(v0 + 8));
func2(93);
result = look;
}
while ( *(_DWORD *)look == 91 );
return result;
}

original_code:
void dims(){
 match('[');
 token tok = look;
 match(270);
 printf("[%d]",tok->detail.num);
 match(']');
 if(look->tag == '[')
  dims();
}

canonical_original_code:
void dims(){
 match('[');
 struct _token *tok = look;
 match(270);
 printf("[%d]",tok->detail.num);
 match(']');
 if(look->tag == '[')
  dims();
}

variable_types: struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *


type

decompiled_code:
__int64 type()
{
__int64 v0; // r12

v0 = look;
match(257);
printf("%s", *(const char **)(v0 + 8));
if ( *(_DWORD *)look == 91 )
dims();
return v0;
}

original_code:
var_type type(){
 var_type p = look;
 match(257);
 printf("%s",p->detail.type.name);
 if(look->tag == '[')
  dims();
 return p;
}

canonical_original_code:
struct _token *type(){
 struct _token *p = look;
 match(257);
 printf("%s",p->detail.type.name);
 if(look->tag == '[')
  dims();
 return p;
}

return_type: struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *


decls

decompiled_code:
__int64 decls()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rax

for ( result = look; *(_DWORD *)look == 257; result = look )
{
v1 = type();
v2 = look;
v3 = v1;
match(264);
match(59);
printf(" %s\n", *(const char **)(v2 + 8));
v4 = Id(v2, v3, (unsigned int)used);
put_in_env(top, v2, v4);
used += *(_DWORD *)(v3 + 16);
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rbx
__int64 v4; // rax

for ( result = look; *(_DWORD *)look == 257; result = look )
{
v1 = func4();
v2 = look;
v3 = v1;
func2(264);
func2(59);
printf(" %s\n", *(const char **)(v2 + 8));
v4 = Id(v2, v3, (unsigned int)used);
put_in_env(top, v2, v4);
used += *(_DWORD *)(v3 + 16);
}
return result;
}

original_code:
void decls(){
 while(look->tag == 257){
  var_type p = type();
  token tok = look;
  match(264);
  match(';');
  printf(" %s\n",tok->detail.word);
  id var_id = Id(tok,p,used);
  put_in_env(top,tok,var_id);
  used = used + p->detail.type.width;
 }
}

canonical_original_code:
void decls(){
 while(look->tag == 257){
  struct _token *p = type();
  struct _token *tok = look;
  match(264);
  match(';');
  printf(" %s\n",tok->detail.word);
  struct _id *var_id = Id(tok,p,used);
  put_in_env(top,tok,var_id);
  used = used + p->detail.type.width;
 }
}

variable_types: struct _id { struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *p; int used; char *name; } *

user_defined_types: struct _id { struct _token *p; int used; char *name; }


offset

decompiled_code:
__int64 __fastcall offset(__int64 *a1)
{
__int64 v1; // rbx
unsigned int v2; // er14
const char *v3; // rdx
__int64 v4; // r8
unsigned int v5; // er12
__int64 v6; // rsi
unsigned int v7; // er13
unsigned int v8; // er14
__int64 v9; // rdx
__int64 v10; // rsi

v1 = *a1;
match(91);
v2 = boolean();
match(93);
v3 = (const char *)a1[2];
v4 = *(unsigned int *)(v1 + 16);
v5 = temp;
v6 = (unsigned int)temp++;
printf("t%d = |%s + t%d * %d|\n", v6, v3, v2, v4);
while ( *(_DWORD *)look == 91 )
{
v7 = temp++;
match(91);
v8 = boolean();
match(93);
printf("t%d = t%d * %d\n", v7, v8, *(unsigned int *)(v1 + 16));
v9 = v5;
v5 = temp;
v10 = (unsigned int)temp++;
printf("t%d = t%d + t%d\n", v10, v9, v7);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1)
{
__int64 v1; // rbx
unsigned int v2; // er14
const char *v3; // rdx
__int64 v4; // r8
unsigned int v5; // er12
__int64 v6; // rsi
unsigned int v7; // er13
unsigned int v8; // er14
__int64 v9; // rdx
__int64 v10; // rsi

v1 = *a1;
func2(91);
v2 = func14();
func2(93);
v3 = (const char *)a1[2];
v4 = *(unsigned int *)(v1 + 16);
v5 = temp;
v6 = (unsigned int)temp++;
printf("t%d = |%s + t%d * %d|\n", v6, v3, v2, v4);
while ( *(_DWORD *)look == 91 )
{
v7 = temp++;
func2(91);
v8 = func14();
func2(93);
printf("t%d = t%d * %d\n", v7, v8, *(unsigned int *)(v1 + 16));
v9 = v5;
v5 = temp;
v10 = (unsigned int)temp++;
printf("t%d = t%d + t%d\n", v10, v9, v7);
}
return v5;
}

original_code:
int offset(id a){
 int t,b,w,loc,t1;
 var_type type = a->p;
 match('[');
 b = boolean();
 match(']');
 w = type->detail.type.width;
 t = temp++;
 printf("t%d = |%s + t%d * %d|\n",t,a->name,b,w);
 loc = t;
 while(look->tag == '['){
  t = temp++;
  match('[');
  b = boolean();
  match(']');
  w = type->detail.type.width;
  printf("t%d = t%d * %d\n",t,b,w);
  t1 = t;
  t = temp++;
  printf("t%d = t%d + t%d\n",t,loc,t1);
  loc = t;
 }
 return t;
}

canonical_original_code:
int offset(struct _id *a){
 int t; int b; int w; int loc; int t1;
 struct _token *type = a->p;
 match('[');
 b = boolean();
 match(']');
 w = type->detail.type.width;
 t = temp++;
 printf("t%d = |%s + t%d * %d|\n",t,a->name,b,w);
 loc = t;
 while(look->tag == '['){
  t = temp++;
  match('[');
  b = boolean();
  match(']');
  w = type->detail.type.width;
  printf("t%d = t%d * %d\n",t,b,w);
  t1 = t;
  t = temp++;
  printf("t%d = t%d + t%d\n",t,loc,t1);
  loc = t;
 }
 return t;
}

variable_types: b int

variable_types: w int

variable_types: loc int


factor

decompiled_code:
__int64 factor()
{
unsigned int v0; // er12
__int64 result; // rax
__int64 v2; // rbx
unsigned int v3; // er13
unsigned int v4; // eax

v0 = temp++;
if ( *(_DWORD *)look == 40 )
{
move();
v3 = boolean();
match(41);
printf("t%d = t%d\n", v0, v3);
result = v0;
}
else
{
switch ( *(_DWORD *)look )
{
case 0x106:
printf("t%d = false\n", v0);
move();
goto LABEL_4;
case 0x108:
v2 = get_from_env(top);
if ( !v2 )
error("undeclared var in factor");
move();
if ( *(_DWORD *)look == 91 )
{
v4 = offset((__int64 *)v2);
printf("t%d = %s", v4, *(const char **)(v2 + 16));
LABEL_4:
result = v0;
}
else
{
printf("t%d = %s\n", v0, *(const char **)(v2 + 16));
result = v0;
}
break;
case 0x10E:
printf("t%d = %d\n", v0, *(unsigned int *)(look + 8));
move();
return v0;
case 0x110:
printf("t%d = %f\n", v0, *(float *)(look + 8));
move();
return v0;
case 0x112:
printf("t%d = true\n", v0);
move();
return v0;
default:
error("syntax error");
}
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er12
__int64 result; // rax
__int64 v2; // rbx
unsigned int v3; // er13
unsigned int v4; // eax

v0 = temp++;
if ( *(_DWORD *)look == 40 )
{
func0();
v3 = func14();
func2(41);
printf("t%d = t%d\n", v0, v3);
result = v0;
}
else
{
switch ( *(_DWORD *)look )
{
case 0x106:
printf("t%d = false\n", v0);
func0();
goto LABEL_4;
case 0x108:
v2 = get_from_env(top);
if ( !v2 )
func1("undeclared var in factor");
func0();
if ( *(_DWORD *)look == 91 )
{
v4 = func6((__int64 *)v2);
printf("t%d = %s", v4, *(const char **)(v2 + 16));
LABEL_4:
result = v0;
}
else
{
printf("t%d = %s\n", v0, *(const char **)(v2 + 16));
result = v0;
}
break;
case 0x10E:
printf("t%d = %d\n", v0, *(unsigned int *)(look + 8));
func0();
return v0;
case 0x110:
printf("t%d = %f\n", v0, *(float *)(look + 8));
func0();
return v0;
case 0x112:
printf("t%d = true\n", v0);
func0();
return v0;
default:
func1("syntax error");
}
}
return result;
}

original_code:
int factor(){
 int t,t1,off;
 float r;
 id var;
 t = temp++;
 switch(look->tag){
  case '(':
   move();
   t1 = boolean();
   match(')');
   printf("t%d = t%d\n",t,t1);
   return t;
  case 270:
   t1 = look->detail.num;
   printf("t%d = %d\n",t,t1);
   move();
   return t;
  case 272:
   r = look->detail.real;
   printf("t%d = %f\n",t,r);
   move();
   return t;
  case 274:
   printf("t%d = true\n",t);
   move();
   return t;
  case 262:
   printf("t%d = false\n",t);
   move();
   return t;
  case 264:
   var = get_from_env(top,look);
   if(var == ((void *)0))
    error("undeclared var in factor");
   move();
   if(look->tag != '['){
    printf("t%d = %s\n",t,var->name);
   }
   else{
    off = offset(var);
    printf("t%d = %s",off,var->name);
   }
   return t;
  default:
   error("syntax error");
 }
}

canonical_original_code:
int factor(){
 int t; int t1; int off;
 float r;
 struct _id *var;
 t = temp++;
 switch(look->tag){
  case '(':
   move();
   t1 = boolean();
   match(')');
   printf("t%d = t%d\n",t,t1);
   return t;
  case 270:
   t1 = look->detail.num;
   printf("t%d = %d\n",t,t1);
   move();
   return t;
  case 272:
   r = look->detail.real;
   printf("t%d = %f\n",t,r);
   move();
   return t;
  case 274:
   printf("t%d = true\n",t);
   move();
   return t;
  case 262:
   printf("t%d = false\n",t);
   move();
   return t;
  case 264:
   var = get_from_env(top,look);
   if(var == ((void *)0))
    error("undeclared var in factor");
   move();
   if(look->tag != '['){
    printf("t%d = %s\n",t,var->name);
   }
   else{
    off = offset(var);
    printf("t%d = %s",off,var->name);
   }
   return t;
  default:
   error("syntax error");
 }
}

variable_types: off int

variable_types: r float


unary

decompiled_code:
__int64 unary()
{
__int64 result; // rax
unsigned int v1; // er12
unsigned int v2; // eax
unsigned int v3; // er12
unsigned int v4; // eax

if ( *(_DWORD *)look == 45 )
{
move();
v3 = temp++;
v4 = unary();
printf("t%d = -t%d\n", v3, v4);
result = v3;
}
else if ( *(_DWORD *)look == 33 )
{
move();
v1 = temp++;
v2 = unary();
printf("t%d = !t%d\n", v1, v2);
result = v1;
}
else
{
result = factor();
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
unsigned int v1; // er12
unsigned int v2; // eax
unsigned int v3; // er12
unsigned int v4; // eax

if ( *(_DWORD *)look == 45 )
{
func0();
v3 = temp++;
v4 = func8();
printf("t%d = -t%d\n", v3, v4);
result = v3;
}
else if ( *(_DWORD *)look == 33 )
{
func0();
v1 = temp++;
v2 = func8();
printf("t%d = !t%d\n", v1, v2);
result = v1;
}
else
{
result = func7();
}
return result;
}

original_code:
int unary(){
 int t,t1;
 if(look->tag == '-'){
  move();
  t = temp++;
  t1 = unary();
  printf("t%d = -t%d\n",t,t1);
  return t;
 }else if(look->tag == '!'){
  move();
  t = temp++;
  t1 = unary();
  printf("t%d = !t%d\n",t,t1);
  return t;
 }
 else return factor();
}

canonical_original_code:
int unary(){
 int t; int t1;
 if(look->tag == '-'){
  move();
  t = temp++;
  t1 = unary();
  printf("t%d = -t%d\n",t,t1);
  return t;
 }else if(look->tag == '!'){
  move();
  t = temp++;
  t1 = unary();
  printf("t%d = !t%d\n",t,t1);
  return t;
 }
 else return factor();
}


term

decompiled_code:
__int64 term()
{
unsigned int v0; // er12
int *v1; // rbx
unsigned int v2; // er14
unsigned int v3; // er13
int v4; // eax

v0 = unary();
while ( 1 )
{
v1 = (int *)look;
if ( *(_DWORD *)look != 42 && *(_DWORD *)look != 47 )
break;
v2 = v0;
v0 = temp++;
move();
v3 = unary();
v4 = *v1;
if ( *v1 == 42 )
{
printf("t%d = t%d * t%d\n", v0, v2, v3);
v4 = *v1;
}
if ( v4 == 47 )
printf("t%d = t%d / t%d\n", v0, v2, v3);
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // er12
int *v1; // rbx
unsigned int v2; // er14
unsigned int v3; // er13
int v4; // eax

v0 = func8();
while ( 1 )
{
v1 = (int *)look;
if ( *(_DWORD *)look != 42 && *(_DWORD *)look != 47 )
break;
v2 = v0;
v0 = temp++;
func0();
v3 = func8();
v4 = *v1;
if ( *v1 == 42 )
{
printf("t%d = t%d * t%d\n", v0, v2, v3);
v4 = *v1;
}
if ( v4 == 47 )
printf("t%d = t%d / t%d\n", v0, v2, v3);
}
return v0;
}

original_code:
int term(){
 int t,t1,t2;
 token tok;
 t1 = unary();
 t = t1;
 while(look->tag == '*' || look->tag == '/'){
  tok = look;
  t = temp++;
  move();
  t2 = unary();
  if(tok->tag == '*')
   printf("t%d = t%d * t%d\n",t,t1,t2);
  if(tok->tag == '/')
   printf("t%d = t%d / t%d\n",t,t1,t2);
  t1 = t;
 }
 return t;
}

canonical_original_code:
int term(){
 int t; int t1; int t2;
 struct _token *tok;
 t1 = unary();
 t = t1;
 while(look->tag == '*' || look->tag == '/'){
  tok = look;
  t = temp++;
  move();
  t2 = unary();
  if(tok->tag == '*')
   printf("t%d = t%d * t%d\n",t,t1,t2);
  if(tok->tag == '/')
   printf("t%d = t%d / t%d\n",t,t1,t2);
  t1 = t;
 }
 return t;
}


rel

decompiled_code:
__int64 rel()
{
unsigned int v0; // er12
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax
__int64 v4; // rdx
__int64 result; // rax
unsigned int v6; // ebx
unsigned int v7; // eax
unsigned int v8; // ebx
unsigned int v9; // eax
unsigned int v10; // ebx
unsigned int v11; // eax

v0 = expr();
v1 = *(_DWORD *)look;
if ( *(_DWORD *)look == 263 )
{
v8 = temp++;
move();
v9 = expr();
printf("t%d = t%d >= t%d\n", v8, v0, v9);
result = v8;
}
else if ( v1 > 263 )
{
if ( v1 != 267 )
return v0;
v6 = temp++;
move();
v7 = expr();
printf("t%d = t%d <= t%d\n", v6, v0, v7);
result = v6;
}
else
{
if ( v1 != 60 )
{
if ( v1 == 62 )
{
v2 = temp++;
move();
v3 = expr();
v4 = v0;
v0 = v2;
printf("t%d = t%d > t%d\n", v2, v4, v3);
}
return v0;
}
v10 = temp++;
move();
v11 = expr();
printf("t%d = t%d < t%d\n", v10, v0, v11);
result = v10;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // er12
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax
__int64 v4; // rdx
__int64 result; // rax
unsigned int v6; // ebx
unsigned int v7; // eax
unsigned int v8; // ebx
unsigned int v9; // eax
unsigned int v10; // ebx
unsigned int v11; // eax

v0 = func10();
v1 = *(_DWORD *)look;
if ( *(_DWORD *)look == 263 )
{
v8 = temp++;
func0();
v9 = func10();
printf("t%d = t%d >= t%d\n", v8, v0, v9);
result = v8;
}
else if ( v1 > 263 )
{
if ( v1 != 267 )
return v0;
v6 = temp++;
func0();
v7 = func10();
printf("t%d = t%d <= t%d\n", v6, v0, v7);
result = v6;
}
else
{
if ( v1 != 60 )
{
if ( v1 == 62 )
{
v2 = temp++;
func0();
v3 = func10();
v4 = v0;
v0 = v2;
printf("t%d = t%d > t%d\n", v2, v4, v3);
}
return v0;
}
v10 = temp++;
func0();
v11 = func10();
printf("t%d = t%d < t%d\n", v10, v0, v11);
result = v10;
}
return result;
}

original_code:
int rel(){
 int t,t1,t2;
 t1 = _expr();
 switch(look->tag){
  case '<':
   t = temp++;
   move();
   t2 = _expr();
   printf("t%d = t%d < t%d\n",t,t1,t2);
   return t;
  case 267:
   t = temp++;
   move();
   t2 = _expr();
   printf("t%d = t%d <= t%d\n",t,t1,t2);
   return t;
  case 263:
   t = temp++;
   move();
   t2 = _expr();
   printf("t%d = t%d >= t%d\n",t,t1,t2);
   return t;
  case '>':
   t = temp++;
   move();
   t2 = _expr();
   printf("t%d = t%d > t%d\n",t,t1,t2);
   return t;
  default:
   return t1;
 }
}

canonical_original_code:
int rel(){
 int t; int t1; int t2;
 t1 = _expr();
 switch(look->tag){
  case '<':
   t = temp++;
   move();
   t2 = _expr();
   printf("t%d = t%d < t%d\n",t,t1,t2);
   return t;
  case 267:
   t = temp++;
   move();
   t2 = _expr();
   printf("t%d = t%d <= t%d\n",t,t1,t2);
   return t;
  case 263:
   t = temp++;
   move();
   t2 = _expr();
   printf("t%d = t%d >= t%d\n",t,t1,t2);
   return t;
  case '>':
   t = temp++;
   move();
   t2 = _expr();
   printf("t%d = t%d > t%d\n",t,t1,t2);
   return t;
  default:
   return t1;
 }
}


equality

decompiled_code:
__int64 equality()
{
unsigned int v0; // er12
int *v1; // rbx
unsigned int v2; // er14
unsigned int v3; // er13
int v4; // eax

v0 = rel();
while ( 1 )
{
v1 = (int *)look;
if ( (*(_DWORD *)look & 0xFFFFFFF7) != 261 )
break;
v2 = v0;
v0 = temp++;
move();
v3 = rel();
v4 = *v1;
if ( *v1 == 261 )
{
printf("t%d = t%d == t%d\n", v0, v2, v3);
v4 = *v1;
}
if ( v4 == 269 )
printf("t%d = t%d != t%d\n", v0, v2, v3);
}
return v0;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // er12
int *v1; // rbx
unsigned int v2; // er14
unsigned int v3; // er13
int v4; // eax

v0 = func11();
while ( 1 )
{
v1 = (int *)look;
if ( (*(_DWORD *)look & 0xFFFFFFF7) != 261 )
break;
v2 = v0;
v0 = temp++;
func0();
v3 = func11();
v4 = *v1;
if ( *v1 == 261 )
{
printf("t%d = t%d == t%d\n", v0, v2, v3);
v4 = *v1;
}
if ( v4 == 269 )
printf("t%d = t%d != t%d\n", v0, v2, v3);
}
return v0;
}

original_code:
int equality(){
 int t,t1,t2;
 token tok;
 t1 = rel();
 t = t1;
 while(look->tag == 261 || look->tag == 269){
  tok = look;
  t = temp++;
  move();
  t2 = rel();
  if(tok->tag == 261)
   printf("t%d = t%d == t%d\n",t,t1,t2);
  if(tok->tag == 269)
   printf("t%d = t%d != t%d\n",t,t1,t2);
  t1 = t;
 }
 return t;
}

canonical_original_code:
int equality(){
 int t; int t1; int t2;
 struct _token *tok;
 t1 = rel();
 t = t1;
 while(look->tag == 261 || look->tag == 269){
  tok = look;
  t = temp++;
  move();
  t2 = rel();
  if(tok->tag == 261)
   printf("t%d = t%d == t%d\n",t,t1,t2);
  if(tok->tag == 269)
   printf("t%d = t%d != t%d\n",t,t1,t2);
  t1 = t;
 }
 return t;
}


join

decompiled_code:
__int64 join()
{
unsigned int v0; // er12
unsigned int v1; // er13
unsigned int v2; // eax

v0 = equality();
while ( *(_DWORD *)look == 256 )
{
v1 = v0;
v0 = temp++;
move();
v2 = equality();
printf("t%d = t%d && t%d\n", v0, v1, v2);
}
return v0;
}

canonical_decompiled_code:
__int64 func13()
{
unsigned int v0; // er12
unsigned int v1; // er13
unsigned int v2; // eax

v0 = func12();
while ( *(_DWORD *)look == 256 )
{
v1 = v0;
v0 = temp++;
func0();
v2 = func12();
printf("t%d = t%d && t%d\n", v0, v1, v2);
}
return v0;
}

original_code:
int join(){
 int t,t1,t2;
 t1 = equality();
 t = t1;
 while(look->tag == 256){
  t = temp++;
  move();
  t2 = equality();
  printf("t%d = t%d && t%d\n",t,t1,t2);
  t1 = t;
 }
 return t;
}

canonical_original_code:
int join(){
 int t; int t1; int t2;
 t1 = equality();
 t = t1;
 while(look->tag == 256){
  t = temp++;
  move();
  t2 = equality();
  printf("t%d = t%d && t%d\n",t,t1,t2);
  t1 = t;
 }
 return t;
}


boolean

decompiled_code:
__int64 boolean()
{
unsigned int v0; // er12
unsigned int v1; // er13
unsigned int v2; // eax

v0 = join();
while ( *(_DWORD *)look == 271 )
{
v1 = v0;
v0 = temp++;
move();
v2 = join();
printf("t%d = t%d || t%d\n", v0, v1, v2);
}
return v0;
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // er12
unsigned int v1; // er13
unsigned int v2; // eax

v0 = func13();
while ( *(_DWORD *)look == 271 )
{
v1 = v0;
v0 = temp++;
func0();
v2 = func13();
printf("t%d = t%d || t%d\n", v0, v1, v2);
}
return v0;
}

original_code:
int boolean(){
 int t,t1,t2;
 t1 = join();
 t = t1;
 while(look->tag == 271){
  t = temp++;
  move();
  t2 = join();
  printf("t%d = t%d || t%d\n",t,t1,t2);
  t1 = t;
 }
 return t;
}

canonical_original_code:
int boolean(){
 int t; int t1; int t2;
 t1 = join();
 t = t1;
 while(look->tag == 271){
  t = temp++;
  move();
  t2 = join();
  printf("t%d = t%d || t%d\n",t,t1,t2);
  t1 = t;
 }
 return t;
}


assign

decompiled_code:
__int64 assign()
{
__int64 v0; // rbp
__int64 *v1; // rax
unsigned int v2; // ebp
unsigned int v3; // eax
unsigned int v5; // eax

v0 = look;
match(264);
v1 = (__int64 *)get_from_env(top);
if ( !v1 )
error("undeclared variable in assign");
if ( *(_DWORD *)look == 61 )
{
move(v1, v0);
v5 = boolean();
printf("%s = t%d\n", *(const char **)(v0 + 8), v5);
}
else
{
v2 = offset(v1);
match(61);
v3 = boolean();
printf("t%d = t%d\n", v2, v3);
}
return match(59);
}

canonical_decompiled_code:
__int64 func15()
{
__int64 v0; // rbp
__int64 *v1; // rax
unsigned int v2; // ebp
unsigned int v3; // eax
unsigned int v5; // eax

v0 = look;
func2(264);
v1 = (__int64 *)get_from_env(top);
if ( !v1 )
func1("undeclared variable in assign");
if ( *(_DWORD *)look == 61 )
{
func0(v1, v0);
v5 = func14();
printf("%s = t%d\n", *(const char **)(v0 + 8), v5);
}
else
{
v2 = func6(v1);
func2(61);
v3 = func14();
printf("t%d = t%d\n", v2, v3);
}
return func2(59);
}

original_code:
void assign(){
 int tmp,off;
 token t = look;
 match(264);
 id i = get_from_env(top,t);
 if(i == ((void *)0))
  error("undeclared variable in assign");
 if(look->tag == '='){
  move();
  tmp = boolean();
  printf("%s = t%d\n",t->detail.word,tmp);
 }else{
  off = offset(i);
  match('=');
  tmp = boolean();
  printf("t%d = t%d\n",off,tmp);
 }
 match(';');
}

canonical_original_code:
void assign(){
 int tmp; int off;
 struct _token *t = look;
 match(264);
 struct _id *i = get_from_env(top,t);
 if(i == ((void *)0))
  error("undeclared variable in assign");
 if(look->tag == '='){
  move();
  tmp = boolean();
  printf("%s = t%d\n",t->detail.word,tmp);
 }else{
  off = offset(i);
  match('=');
  tmp = boolean();
  printf("t%d = t%d\n",off,tmp);
 }
 match(';');
}

variable_types: tmp int


stmt

decompiled_code:
int __fastcall stmt(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
int v3; // eax
int result; // eax
unsigned int v5; // ebp
__int64 v6; // rsi
__int64 v7; // rsi
__int64 v8; // rsi
unsigned int v9; // ebp
unsigned int v10; // ebp

while ( 1 )
{
v2 = label;
v3 = *(_DWORD *)look;
if ( *(_DWORD *)look == 259 )
{
match(259);
v8 = (unsigned int)label++;
printf("L%d:\n", v8);
stmt();
match(275);
match(40);
v9 = boolean();
match(41);
match(59);
return printf("if true t%d goto L%d\n", v9, v2);
}
if ( v3 <= 259 )
{
if ( v3 != 123 )
{
if ( v3 != 258 )
{
if ( v3 != 59 )
return assign();
return move(a1, a2);
}
match(258);
printf("goto L%d\n", 0LL);
match(59);
}
return block();
}
if ( v3 != 265 )
break;
match(265);
match(40);
v10 = boolean();
match(41);
printf("if false t%d goto L%d\n", v10, v2);
stmt();
a2 = (unsigned int)label++;
printf("L%d:\n", a2);
result = look;
if ( *(_DWORD *)look != 260 )
return result;
a1 = 260LL;
match(260);
}
if ( v3 == 275 )
{
match(275);
match(40);
v5 = boolean();
match(41);
v6 = (unsigned int)label++;
printf("L%d:\n", v6);
stmt();
printf("if true t%d goto L%d\n", v5, v2);
v7 = (unsigned int)label++;
return printf("L%d:\n", v7);
}
return assign();
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
int v3; // eax
int result; // eax
unsigned int v5; // ebp
__int64 v6; // rsi
__int64 v7; // rsi
__int64 v8; // rsi
unsigned int v9; // ebp
unsigned int v10; // ebp

while ( 1 )
{
v2 = label;
v3 = *(_DWORD *)look;
if ( *(_DWORD *)look == 259 )
{
func2(259);
v8 = (unsigned int)label++;
printf("L%d:\n", v8);
func16();
func2(275);
func2(40);
v9 = func14();
func2(41);
func2(59);
return printf("if true t%d goto L%d\n", v9, v2);
}
if ( v3 <= 259 )
{
if ( v3 != 123 )
{
if ( v3 != 258 )
{
if ( v3 != 59 )
return func15();
return func0(a1, a2);
}
func2(258);
printf("goto L%d\n", 0LL);
func2(59);
}
return func18();
}
if ( v3 != 265 )
break;
func2(265);
func2(40);
v10 = func14();
func2(41);
printf("if false t%d goto L%d\n", v10, v2);
func16();
a2 = (unsigned int)label++;
printf("L%d:\n", a2);
result = look;
if ( *(_DWORD *)look != 260 )
return result;
a1 = 260LL;
func2(260);
}
if ( v3 == 275 )
{
func2(275);
func2(40);
v5 = func14();
func2(41);
v6 = (unsigned int)label++;
printf("L%d:\n", v6);
func16();
printf("if true t%d goto L%d\n", v5, v2);
v7 = (unsigned int)label++;
return printf("L%d:\n", v7);
}
return func15();
}

original_code:
void stmt(){
 int l = label;
 int t;
 int br;
 switch(look->tag){
  case ';':
   move();
   break;
  case 265:
   match(265);
   match('(');
   t = boolean();
   match(')');
   printf("if false t%d goto L%d\n",t,l);
   stmt();
   printf("L%d:\n",label++);
   if(look->tag != 260)
    break;
   match(260);
   stmt();
   break;
  case 275:
   match(275);
   match('(');
   t = boolean();
   match(')');
   printf("L%d:\n",label++);
   stmt();
   printf("if true t%d goto L%d\n",t,l);
   printf("L%d:\n",label++);
   br = label;
   break;
  case 259:
   match(259);
   printf("L%d:\n",label++);
   stmt();
   match(275);
   match('(');
   t = boolean();
   match(')');
   match(';');
   printf("if true t%d goto L%d\n",t,l);
   break;
  case 258:
   match(258);
   printf("goto L%d\n",br);
   match(';');
  case '{':
   block();
   break;
  default:
   assign();
   break;
 }
}

variable_types: l int

variable_types: br int


stmts

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

for ( result = look; *(_DWORD *)look != 125; result = look )
stmt(a1, a2);
return result;
}

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

for ( result = look; *(_DWORD *)look != 125; result = look )
func16(a1, a2);
return result;
}

original_code:
void stmts(){
 while(look->tag != '}'){
  stmt();
 }
}


block

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

match(123);
v2 = top;
v3 = top;
top = Enviroment(top);
decls();
stmts(v3, a2);
result = match(125);
top = v2;
return result;
}

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

func2(123);
v2 = top;
v3 = top;
top = Enviroment(top);
func5();
func17(v3, a2);
result = func2(125);
top = v2;
return result;
}

original_code:
void block(){
 match('{');
 enviroment saved_env = top;
 top = Enviroment(top);
 decls();
 stmts();
 match('}');
 top = saved_env;
}

canonical_original_code:
void block(){
 match('{');
 struct _enviroment *saved_env = top;
 top = Enviroment(top);
 decls();
 stmts();
 match('}');
 top = saved_env;
}

variable_types: struct _enviroment { struct _env_entry { struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *t; struct _id { struct _token *p; int used; char *name; } *i; struct _env_entry *next; } **tab; struct _enviroment *next; } *

user_defined_types: struct _enviroment { struct _env_entry **tab; struct _enviroment *next; }

user_defined_types: struct _env_entry { struct _token *t; struct _id *i; struct _env_entry *next; }


program

decompiled_code:
__int64 __fastcall program(__int64 a1, __int64 a2)
{
move(a1, a2);
return block(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2)
{
func0(a1, a2);
return func18(a1, a2);
}

original_code:
void program(){
 move();
 block();
}

canonical_original_code:
void program(){
 move();
 block();
}


decompiled_code:
__int64 __fastcall env_loc(_BYTE *a1)
{
char *v1; // rcx
int v2; // eax

v1 = a1 + 1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
v2 = 31 * v2 + *v1++;
while ( *(v1 - 1) );
return (unsigned int)(v2 % 131);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
char *v1; // rcx
int v2; // eax

v1 = a1 + 1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
v2 = 31 * v2 + *v1++;
while ( *(v1 - 1) );
return (unsigned int)(v2 % 131);
}

original_code:
static int env_loc(char* s){
 int h = 0;
 while(*s++)
  h = h * 31 + *s;
 return h % 131;
}

canonical_original_code:
static int env_loc(char *s){
 int h = 0;
 while(*s++)
  h = h * 31 + *s;
 return h % 131;
}

variable_types: h int


decompiled_code:
__int64 __fastcall get_from_env(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // r12
_QWORD *v3; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
while ( 1 )
{
v3 = *(_QWORD **)(*v2 + 8LL * (int)env_loc(*(_BYTE **)(a2 + 8)));
if ( v3 )
break;
LABEL_8:
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
while ( !(unsigned int)token_equal(a2, *v3) )
{
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_8;
}
return v3[1];
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // r12
_QWORD *v3; // rbx

if ( !a1 )
return 0LL;
v2 = a1;
while ( 1 )
{
v3 = *(_QWORD **)(*v2 + 8LL * (int)func0(*(_BYTE **)(a2 + 8)));
if ( v3 )
break;
LABEL_8:
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
while ( !(unsigned int)token_equal(a2, *v3) )
{
v3 = (_QWORD *)v3[2];
if ( !v3 )
goto LABEL_8;
}
return v3[1];
}

original_code:
id get_from_env(enviroment e,token t){
 if(e == ((void *)0))
  return ((void *)0);
 int h = env_loc(t->detail.word);
 env_entry head ;
 for(head = e->tab[h];head != ((void *)0);head=head->next){
  if(token_equal(t,head->t)){
   return head->i;
  }
 }
 return get_from_env(e->next,t);
}

canonical_original_code:
struct _id *get_from_env(struct _enviroment *e, struct _token *t){
 if(e == ((void *)0))
  return ((void *)0);
 int h = env_loc(t->detail.word);
 struct _env_entry *head;
 for(head = e->tab[h];head != ((void *)0);head=head->next){
  if(token_equal(t,head->t)){
   return head->i;
  }
 }
 return get_from_env(e->next,t);
}

variable_types: struct _enviroment { struct _env_entry { struct _token *t; struct _id *i; struct _env_entry *next; } **tab; struct _enviroment *next; } *

variable_types:
t
struct _token *

variable_types: struct _env_entry { struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *t; struct _id { struct _token *p; int used; char *name; } *i; struct _env_entry *next; } *

return_type: struct _id { struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *p; int used; char *name; } *


decompiled_code:
int __fastcall print_token(const char **a1)
{
int result; // eax

result = printf("TAG:%d\n", *(unsigned int *)a1);
if ( *(_DWORD *)a1 == 264 )
result = printf("lexme:%s\n", a1[1]);
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char **a1)
{
int result; // eax

result = printf("TAG:%d\n", *(unsigned int *)a1);
if ( *(_DWORD *)a1 == 264 )
result = printf("lexme:%s\n", a1[1]);
return result;
}

original_code:
void print_token(token t){
 printf("TAG:%d\n",t->tag);
 if(t->tag == 264){
  printf("lexme:%s\n",t->detail.word);
 }
}

canonical_original_code:
void print_token(struct _token *t){
 printf("TAG:%d\n",t->tag);
 if(t->tag == 264){
  printf("lexme:%s\n",t->detail.word);
 }
}


decompiled_code:
__int64 __fastcall token_equal(int *a1, __int64 a2)
{
float v2; // eax
unsigned int v3; // er8

v2 = *(float *)a1;
v3 = 0;
if ( *a1 != *(_DWORD *)a2 )
return v3;
if ( LODWORD(v2) == 270 )
return a1[2] == *(_DWORD *)(a2 + 8);
if ( LODWORD(v2) == 272 )
{
if ( *((float *)a1 + 2) == *(float *)(a2 + 8) )
v3 = 1;
return v3;
}
if ( LODWORD(v2) != 264 )
return *((_BYTE *)a1 + 8) == *(_BYTE *)(a2 + 8);
return strcmp(*((const char **)a1 + 1), *(const char **)(a2 + 8)) == 0;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, __int64 a2)
{
float v2; // eax
unsigned int v3; // er8

v2 = *(float *)a1;
v3 = 0;
if ( *a1 != *(_DWORD *)a2 )
return v3;
if ( LODWORD(v2) == 270 )
return a1[2] == *(_DWORD *)(a2 + 8);
if ( LODWORD(v2) == 272 )
{
if ( *((float *)a1 + 2) == *(float *)(a2 + 8) )
v3 = 1;
return v3;
}
if ( LODWORD(v2) != 264 )
return *((_BYTE *)a1 + 8) == *(_BYTE *)(a2 + 8);
return strcmp(*((const char **)a1 + 1), *(const char **)(a2 + 8)) == 0;
}

original_code:
int token_equal(token t1,token t2){
 if(t1->tag != t2->tag)
  return 0;
 if(t1->tag == 270)
  return t1->detail.num == t2->detail.num;
 if(t1->tag == 272)
  return t1->detail.real == t2->detail.real;
 if(t1->tag == 264)
  return !strcmp(t1->detail.word,t2->detail.word);
 return t1->detail.dummy == t2->detail.dummy;
}

canonical_original_code:
int token_equal(struct _token *t1, struct _token *t2){
 if(t1->tag != t2->tag)
  return 0;
 if(t1->tag == 270)
  return t1->detail.num == t2->detail.num;
 if(t1->tag == 272)
  return t1->detail.real == t2->detail.real;
 if(t1->tag == 264)
  return !strcmp(t1->detail.word,t2->detail.word);
 return t1->detail.dummy == t2->detail.dummy;
}


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

result = fgetc(stdin);
peek = result;
if ( (_BYTE)result == 0xFF )
exit(2);
return result;
}

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

result = fgetc(stdin);
peek = result;
if ( (_BYTE)result == 0xFF )
exit(2);
return result;
}

original_code:
void next_char(){
 peek = fgetc(stdin);
 if(peek == (-1))
  exit(2);
}


decompiled_code:
_BOOL8 __fastcall next_c(char a1)
{
next_char();
return peek == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char a1)
{
func0();
return peek == a1;
}

original_code:
int next_c(char c){
 next_char();
 if(peek != c)
  return 0;
 return 1;
}

variable_types: c char


decompiled_code:
__int64 get_token()
{
int v0; // ebx
__int64 result; // rax
const unsigned __int16 **v2; // r12
unsigned __int16 v3; // ax
int v4; // ebp
float v5; // xmm1_4
__int128 *v6; // rbp
float i; // [rsp+0h] [rbp-28h]
__int64 v8; // [rsp+0h] [rbp-28h]
float v9; // [rsp+Ch] [rbp-1Ch]

while ( 1 )
{
v0 = peek;
if ( peek != 32 && peek != 9 )
break;
LABEL_3:
next_char();
}
if ( peek == 10 )
{
++line;
goto LABEL_3;
}
if ( peek > 62 )
{
if ( peek == 124 )
{
if ( next_c(124) )
result = or;
else
result = Token(124LL);
return result;
}
goto LABEL_14;
}
if ( peek <= 32 )
{
LABEL_14:
v2 = _ctype_b_loc();
v3 = (*v2)[(char)v0];
if ( (v3 & 0x800) != 0 )
{
v4 = 0;
do
{
v4 = v0 + 10 * v4 - 48;
next_char();
v0 = peek;
}
while ( ((*v2)[peek] & 0x800) != 0 );
if ( peek == 46 )
{
v5 = *(float *)&LC0;
for ( i = (float)v4; ; i = (float)((float)(peek - 48) / v9) + i )
{
v9 = v5;
next_char();
if ( ((*v2)[peek] & 0x800) == 0 )
break;
v5 = v5 * 10.0;
}
result = Real(i);
}
else
{
result = Num((unsigned int)v4);
}
}
else if ( (v3 & 0x400) != 0 )
{
v6 = &lexme;
word_3D0 = 0;
lexme = 0LL;
xmmword_3B0 = 0LL;
xmmword_3C0 = 0LL;
do
{
*(_BYTE *)v6 = v0;
v6 = (__int128 *)((char *)v6 + 1);
next_char();
LOBYTE(v0) = peek;
}
while ( ((*v2)[peek] & 0xC00) != 0 );
result = get_from_hashtable(symbol, &lexme);
if ( !result )
{
result = TYPE_INT;
if ( (_DWORD)lexme != 7630441 )
{
if ( (_DWORD)lexme != 1634692198 || (result = TYPE_FLOAT, WORD2(lexme) != 116) )
{
if ( (_DWORD)lexme != 1918986339 || (result = TYPE_CHAR, BYTE4(lexme)) )
{
v8 = Word(&lexme, 264LL);
put_in_hashtable(symbol, v8);
result = v8;
}
}
}
}
}
else
{
result = Token((unsigned int)(char)v0);
peek = 32;
}
return result;
}
switch ( peek )
{
case '!':
if ( next_c(61) )
result = ne;
else
result = Token(33LL);
break;
case '&':
if ( next_c(38) )
result = and;
else
result = Token(38LL);
break;
case '<':
if ( next_c(61) )
result = le;
else
result = Token(60LL);
break;
case '=':
if ( next_c(61) )
result = eq;
else
result = Token(61LL);
break;
case '>':
if ( next_c(61) )
result = ge;
else
result = Token(62LL);
break;
default:
goto LABEL_14;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // ebx
__int64 result; // rax
const unsigned __int16 **v2; // r12
unsigned __int16 v3; // ax
int v4; // ebp
float v5; // xmm1_4
__int128 *v6; // rbp
float i; // [rsp+0h] [rbp-28h]
__int64 v8; // [rsp+0h] [rbp-28h]
float v9; // [rsp+Ch] [rbp-1Ch]

while ( 1 )
{
v0 = peek;
if ( peek != 32 && peek != 9 )
break;
LABEL_3:
func0();
}
if ( peek == 10 )
{
++line;
goto LABEL_3;
}
if ( peek > 62 )
{
if ( peek == 124 )
{
if ( func1(124) )
result = or;
else
result = Token(124LL);
return result;
}
goto LABEL_14;
}
if ( peek <= 32 )
{
LABEL_14:
v2 = _ctype_b_loc();
v3 = (*v2)[(char)v0];
if ( (v3 & 0x800) != 0 )
{
v4 = 0;
do
{
v4 = v0 + 10 * v4 - 48;
func0();
v0 = peek;
}
while ( ((*v2)[peek] & 0x800) != 0 );
if ( peek == 46 )
{
v5 = *(float *)&LC0;
for ( i = (float)v4; ; i = (float)((float)(peek - 48) / v9) + i )
{
v9 = v5;
func0();
if ( ((*v2)[peek] & 0x800) == 0 )
break;
v5 = v5 * 10.0;
}
result = Real(i);
}
else
{
result = Num((unsigned int)v4);
}
}
else if ( (v3 & 0x400) != 0 )
{
v6 = &lexme;
word_3D0 = 0;
lexme = 0LL;
xmmword_3B0 = 0LL;
xmmword_3C0 = 0LL;
do
{
*(_BYTE *)v6 = v0;
v6 = (__int128 *)((char *)v6 + 1);
func0();
LOBYTE(v0) = peek;
}
while ( ((*v2)[peek] & 0xC00) != 0 );
result = get_from_hashtable(symbol, &lexme);
if ( !result )
{
result = TYPE_INT;
if ( (_DWORD)lexme != 7630441 )
{
if ( (_DWORD)lexme != 1634692198 || (result = TYPE_FLOAT, WORD2(lexme) != 116) )
{
if ( (_DWORD)lexme != 1918986339 || (result = TYPE_CHAR, BYTE4(lexme)) )
{
v8 = Word(&lexme, 264LL);
put_in_hashtable(symbol, v8);
result = v8;
}
}
}
}
}
else
{
result = Token((unsigned int)(char)v0);
peek = 32;
}
return result;
}
switch ( peek )
{
case '!':
if ( func1(61) )
result = ne;
else
result = Token(33LL);
break;
case '&':
if ( func1(38) )
result = and;
else
result = Token(38LL);
break;
case '<':
if ( func1(61) )
result = le;
else
result = Token(60LL);
break;
case '=':
if ( func1(61) )
result = eq;
else
result = Token(61LL);
break;
case '>':
if ( func1(61) )
result = ge;
else
result = Token(62LL);
break;
default:
goto LABEL_14;
}
return result;
}

original_code:
token get_token(){
 int index = 0;
 for(;;next_char()){
  if(peek == ' ' || peek == '\t')
   continue;
  else if(peek == '\n')
   line = line + 1;
  else break;
 }
 switch(peek){
  case '&':
   if(next_c('&')) return and; else return Token('&');
  case '|':
   if(next_c('|')) return or; else return Token('|');
  case '=':
   if(next_c('=')) return eq; else return Token('=');
  case '!':
   if(next_c('=')) return ne; else return Token('!');
  case '<':
   if(next_c('=')) return le; else return Token('<');
  case '>':
   if(next_c('=')) return ge; else return Token('>');
 }
 if(((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short int) _ISdigit)){
  int v = 0;
  do{
   v = v*10 + (peek-'0');
   next_char();
  }while(((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short int) _ISdigit));
  if(peek != '.') return Num(v);
  float x = v; float d = 10;
  for(;;){
   next_char();
   if(!((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short int) _ISdigit)) break;
   x = x + (peek-'0')/d;
   d = d * 10;
  }
  return Real(x);
 }
 if(((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short int) _ISalpha)){
  index = 0;
  memset(lexme,0,50);
  do{
   lexme[index++] = peek;
   next_char();
  }while(((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short int) _ISdigit));
  token t = get_from_hashtable(symbol,lexme);
  if(t != ((void *)0))
   return t;
  if(!strcmp(lexme,"int")){
   return TYPE_INT;
  }
  if(!strcmp(lexme,"float"))
   return TYPE_FLOAT;
  if(!strcmp(lexme,"char"))
   return TYPE_CHAR;
  t = Word(lexme,264);
  put_in_hashtable(symbol,t);
  return t;
 }
 token tok = Token(peek);
 peek = ' ' ;
 return tok;
}

canonical_original_code:
struct _token *get_token(){
 int index = 0;
 for(;;next_char()){
  if(peek == ' ' || peek == '\t')
   continue;
  else if(peek == '\n')
   line = line + 1;
  else break;
 }
 switch(peek){
  case '&':
   if(next_c('&')) return and; else return Token('&');
  case '|':
   if(next_c('|')) return or; else return Token('|');
  case '=':
   if(next_c('=')) return eq; else return Token('=');
  case '!':
   if(next_c('=')) return ne; else return Token('!');
  case '<':
   if(next_c('=')) return le; else return Token('<');
  case '>':
   if(next_c('=')) return ge; else return Token('>');
 }
 if(((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short) _ISdigit)){
  int v = 0;
  do{
   v = v*10 + (peek-'0');
   next_char();
  }while(((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short) _ISdigit));
  if(peek != '.') return Num(v);
  float x = v; float d = 10;
  for(;;){
   next_char();
   if(!((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short) _ISdigit)) break;
   x = x + (peek-'0')/d;
   d = d * 10;
  }
  return Real(x);
 }
 if(((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short) _ISalpha)){
  index = 0;
  memset(lexme,0,50);
  do{
   lexme[index++] = peek;
   next_char();
  }while(((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) ((peek))] & (unsigned short) _ISdigit));
  struct _token *t = get_from_hashtable(symbol,lexme);
  if(t != ((void *)0))
   return t;
  if(!strcmp(lexme,"int")){
   return TYPE_INT;
  }
  if(!strcmp(lexme,"float"))
   return TYPE_FLOAT;
  if(!strcmp(lexme,"char"))
   return TYPE_CHAR;
  t = Word(lexme,264);
  put_in_hashtable(symbol,t);
  return t;
 }
 struct _token *tok = Token(peek);
 peek = ' ' ;
 return tok;
}

variable_types: index int

variable_types: v int

variable_types: x float

variable_types: d float


isnumeric

decompiled_code:
_BOOL8 __fastcall isnumeric(const char **a1)
{
int v1; // ebp
_BOOL8 result; // rax
int v3; // er8
int v4; // er8

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 != *TYPE_CHAR
|| *((_DWORD *)a1 + 4) != *(_DWORD *)(TYPE_CHAR + 16LL)
|| (v3 = strcmp(a1[1], *(const char **)(TYPE_CHAR + 8LL)), result = 1LL, v3) )
{
if ( v1 != *TYPE_INT
|| *((_DWORD *)a1 + 4) != *(_DWORD *)(TYPE_INT + 16LL)
|| (v4 = strcmp(a1[1], *(const char **)(TYPE_INT + 8LL)), result = 1LL, v4) )
{
result = 0LL;
if ( v1 == *TYPE_FLOAT && *((_DWORD *)a1 + 4) == *(_DWORD *)(TYPE_FLOAT + 16LL) )
result = strcmp(a1[1], *(const char **)(TYPE_FLOAT + 8LL)) == 0;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char **a1)
{
int v1; // ebp
_BOOL8 result; // rax
int v3; // er8
int v4; // er8

v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 != *TYPE_CHAR
|| *((_DWORD *)a1 + 4) != *(_DWORD *)(TYPE_CHAR + 16LL)
|| (v3 = strcmp(a1[1], *(const char **)(TYPE_CHAR + 8LL)), result = 1LL, v3) )
{
if ( v1 != *TYPE_INT
|| *((_DWORD *)a1 + 4) != *(_DWORD *)(TYPE_INT + 16LL)
|| (v4 = strcmp(a1[1], *(const char **)(TYPE_INT + 8LL)), result = 1LL, v4) )
{
result = 0LL;
if ( v1 == *TYPE_FLOAT && *((_DWORD *)a1 + 4) == *(_DWORD *)(TYPE_FLOAT + 16LL) )
result = strcmp(a1[1], *(const char **)(TYPE_FLOAT + 8LL)) == 0;
}
}
return result;
}

original_code:
static int isnumeric(var_type p){
 return ((p->tag == TYPE_CHAR->tag) && (p->detail.type.width == TYPE_CHAR->detail.type.width) && !strcmp(p->detail.type.name,TYPE_CHAR->detail.type.name)) || ((p->tag == TYPE_INT->tag) && (p->detail.type.width == TYPE_INT->detail.type.width) && !strcmp(p->detail.type.name,TYPE_INT->detail.type.name)) || ((p->tag == TYPE_FLOAT->tag) && (p->detail.type.width == TYPE_FLOAT->detail.type.width) && !strcmp(p->detail.type.name,TYPE_FLOAT->detail.type.name));
}

canonical_original_code:
static int isnumeric(struct _token *p){
 return ((p->tag == TYPE_CHAR->tag) && (p->detail.type.width == TYPE_CHAR->detail.type.width) && !strcmp(p->detail.type.name,TYPE_CHAR->detail.type.name)) || ((p->tag == TYPE_INT->tag) && (p->detail.type.width == TYPE_INT->detail.type.width) && !strcmp(p->detail.type.name,TYPE_INT->detail.type.name)) || ((p->tag == TYPE_FLOAT->tag) && (p->detail.type.width == TYPE_FLOAT->detail.type.width) && !strcmp(p->detail.type.name,TYPE_FLOAT->detail.type.name));
}

variable_types: struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *


max

decompiled_code:
__int64 __fastcall max(const char **a1, const char **a2)
{
__int64 v2; // r12
int v3; // er14
int v4; // ebp
int v5; // er15
int v6; // ebp

if ( !isnumeric(a1) || !isnumeric(a2) )
return 0LL;
v2 = TYPE_FLOAT;
v3 = *(_DWORD *)a1;
v4 = *TYPE_FLOAT;
if ( *(_DWORD *)a1 != *TYPE_FLOAT
|| *((_DWORD *)a1 + 4) != *(_DWORD *)(TYPE_FLOAT + 16LL)
|| strcmp(a1[1], *(const char **)(TYPE_FLOAT + 8LL)) )
{
v5 = *(_DWORD *)a2;
if ( v4 != *(_DWORD *)a2 || *((_DWORD *)a2 + 4) != *(_DWORD *)(v2 + 16) || strcmp(a2[1], *(const char **)(v2 + 8)) )
{
v2 = TYPE_INT;
v6 = *TYPE_INT;
if ( (v3 != *TYPE_INT
|| *((_DWORD *)a1 + 4) != *(_DWORD *)(TYPE_INT + 16LL)
|| strcmp(a1[1], *(const char **)(TYPE_INT + 8LL)))
&& (v5 != v6 || *((_DWORD *)a2 + 4) != *(_DWORD *)(v2 + 16) || strcmp(a2[1], *(const char **)(v2 + 8))) )
{
v2 = TYPE_CHAR;
}
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1, const char **a2)
{
__int64 v2; // r12
int v3; // er14
int v4; // ebp
int v5; // er15
int v6; // ebp

if ( !func0(a1) || !func0(a2) )
return 0LL;
v2 = TYPE_FLOAT;
v3 = *(_DWORD *)a1;
v4 = *TYPE_FLOAT;
if ( *(_DWORD *)a1 != *TYPE_FLOAT
|| *((_DWORD *)a1 + 4) != *(_DWORD *)(TYPE_FLOAT + 16LL)
|| strcmp(a1[1], *(const char **)(TYPE_FLOAT + 8LL)) )
{
v5 = *(_DWORD *)a2;
if ( v4 != *(_DWORD *)a2 || *((_DWORD *)a2 + 4) != *(_DWORD *)(v2 + 16) || strcmp(a2[1], *(const char **)(v2 + 8)) )
{
v2 = TYPE_INT;
v6 = *TYPE_INT;
if ( (v3 != *TYPE_INT
|| *((_DWORD *)a1 + 4) != *(_DWORD *)(TYPE_INT + 16LL)
|| strcmp(a1[1], *(const char **)(TYPE_INT + 8LL)))
&& (v5 != v6 || *((_DWORD *)a2 + 4) != *(_DWORD *)(v2 + 16) || strcmp(a2[1], *(const char **)(v2 + 8))) )
{
v2 = TYPE_CHAR;
}
}
}
return v2;
}

original_code:
var_type max(var_type p1,var_type p2){
 if(!isnumeric(p1) || !isnumeric(p2))
  return ((void *)0);
 else if(((p1->tag == TYPE_FLOAT->tag) && (p1->detail.type.width == TYPE_FLOAT->detail.type.width) && !strcmp(p1->detail.type.name,TYPE_FLOAT->detail.type.name)) || ((p2->tag == TYPE_FLOAT->tag) && (p2->detail.type.width == TYPE_FLOAT->detail.type.width) && !strcmp(p2->detail.type.name,TYPE_FLOAT->detail.type.name)))
  return TYPE_FLOAT;
 else if(((p1->tag == TYPE_INT->tag) && (p1->detail.type.width == TYPE_INT->detail.type.width) && !strcmp(p1->detail.type.name,TYPE_INT->detail.type.name)) || ((p2->tag == TYPE_INT->tag) && (p2->detail.type.width == TYPE_INT->detail.type.width) && !strcmp(p2->detail.type.name,TYPE_INT->detail.type.name)))
  return TYPE_INT;
 else
  return TYPE_CHAR;
}

canonical_original_code:
struct _token *max(struct _token *p1, struct _token *p2){
 if(!isnumeric(p1) || !isnumeric(p2))
  return ((void *)0);
 else if(((p1->tag == TYPE_FLOAT->tag) && (p1->detail.type.width == TYPE_FLOAT->detail.type.width) && !strcmp(p1->detail.type.name,TYPE_FLOAT->detail.type.name)) || ((p2->tag == TYPE_FLOAT->tag) && (p2->detail.type.width == TYPE_FLOAT->detail.type.width) && !strcmp(p2->detail.type.name,TYPE_FLOAT->detail.type.name)))
  return TYPE_FLOAT;
 else if(((p1->tag == TYPE_INT->tag) && (p1->detail.type.width == TYPE_INT->detail.type.width) && !strcmp(p1->detail.type.name,TYPE_INT->detail.type.name)) || ((p2->tag == TYPE_INT->tag) && (p2->detail.type.width == TYPE_INT->detail.type.width) && !strcmp(p2->detail.type.name,TYPE_INT->detail.type.name)))
  return TYPE_INT;
 else
  return TYPE_CHAR;
}


strstrip

repo: pimms/scrap

decompiled_code:
int __fastcall strstrip(void *dest)
{
const char *v1; // r13
char *v2; // rbx
int result; // eax
char i; // dl
char *v5; // r12
const char *v6; // rbp
char v7; // al
char *v8; // rdi
int v9; // edx

v1 = (const char *)dest;
v2 = (char *)dest;
puts("--- strstrip");
result = printf(" '%s'\n", (const char *)dest);
for ( i = *(_BYTE *)dest; i; v2 = v5 + 1 )
{
if ( i == 9 || (v5 = v2, i == 32) )
{
v6 = v2;
do
{
do
v7 = *++v6;
while ( v7 == 32 );
}
while ( v7 == 9 );
v5 = v2;
result = (_DWORD)v6 - (_DWORD)v2;
if ( v6 - v2 > 0 )
{
v5 = v2 + 1;
printf("hd: '%s'\n", v6);
v8 = (char *)v1;
v9 = strlen(v6) + 1;
if ( v1 != v2 )
{
v8 = v2 + 1;
if ( !*v6 )
v8 = v2;
}
memmove(v8, v6, v9);
*v2 = 32;
result = printf("ln: '%s'\n", v1);
i = v2[1];
}
if ( i == 9 )
*v5 = 32;
}
i = v5[1];
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(void *dest)
{
const char *v1; // r13
char *v2; // rbx
int result; // eax
char i; // dl
char *v5; // r12
const char *v6; // rbp
char v7; // al
char *v8; // rdi
int v9; // edx

v1 = (const char *)dest;
v2 = (char *)dest;
puts("--- strstrip");
result = printf(" '%s'\n", (const char *)dest);
for ( i = *(_BYTE *)dest; i; v2 = v5 + 1 )
{
if ( i == 9 || (v5 = v2, i == 32) )
{
v6 = v2;
do
{
do
v7 = *++v6;
while ( v7 == 32 );
}
while ( v7 == 9 );
v5 = v2;
result = (_DWORD)v6 - (_DWORD)v2;
if ( v6 - v2 > 0 )
{
v5 = v2 + 1;
printf("hd: '%s'\n", v6);
v8 = (char *)v1;
v9 = strlen(v6) + 1;
if ( v1 != v2 )
{
v8 = v2 + 1;
if ( !*v6 )
v8 = v2;
}
memmove(v8, v6, v9);
*v2 = 32;
result = printf("ln: '%s'\n", v1);
i = v2[1];
}
if ( i == 9 )
*v5 = 32;
}
i = v5[1];
}
return result;
}

original_code:
void
strstrip(char *line)
{
    char *base = line;
    char *head = line;
 printf("--- strstrip\n");
 printf("    '%s'\n", line);
    while (*base) {
        while (*head == ' ' || *head == '\t')
            head++;
        if (head - base > 0) {
   printf("hd: '%s'\n", head);
            int head_len = strlen(head) + 1;
   int offset = (base==line || !*head ? 0 : 1);
            memmove(base + offset, head, head_len);
   *base = ' ';
            base++;
   printf("ln: '%s'\n", line);
        }
  if (*base == '\t')
   *base = ' ';
        base++;
        head = base;
    }
}

variable_types:
line
char *

variable_types:
base
char *

variable_types:
head
char *

variable_types: offset int


openDisk

decompiled_code:
__int64 __fastcall openDisk(char *file, int a2)
{
int v2; // er12
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

if ( lstat(file, &v4) >= 0 )
{
v2 = open(file, 2);
if ( v2 >= 0 )
goto LABEL_3;
LABEL_6:
perror("open");
exit(1);
}
v2 = open(file, 64, 438LL);
if ( v2 < 0 )
goto LABEL_6;
LABEL_3:
if ( lseek(v2, a2, 0) < 0 )
{
perror("lseek");
exit(1);
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *file, int a2)
{
int v2; // er12
struct stat v4; // [rsp+0h] [rbp-A8h] BYREF

if ( lstat(file, &v4) >= 0 )
{
v2 = open(file, 2);
if ( v2 >= 0 )
goto LABEL_3;
LABEL_6:
perror("open");
exit(1);
}
v2 = open(file, 64, 438LL);
if ( v2 < 0 )
goto LABEL_6;
LABEL_3:
if ( lseek(v2, a2, 0) < 0 )
{
perror("lseek");
exit(1);
}
return (unsigned int)v2;
}

original_code:
int openDisk(char *filename, int nBytes) {
   int disk;
   struct stat checker;
   if(lstat(filename, &checker) < 0) {
      { if((disk = (open(filename, 0100, 0400 | 0200 | (0400 >> 3) | (0200 >> 3) | ((0400 >> 3) >> 3) | ((0200 >> 3) >> 3)))) < 0) { perror("open"); exit(1); } };
   }
   else {
      if(nBytes == 0) {
         { if((disk = (open(filename, 02))) < 0) { perror("open"); exit(1); } };
      }
      else {
         { if((disk = (open(filename, 02))) < 0) { perror("open"); exit(1); } };
      }
   }
   { if(lseek(disk, nBytes, 0) < 0) { perror("lseek"); exit(1); } };
   return disk;
}

variable_types:
filename
char *

variable_types: nBytes int

variable_types: disk int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


readBlock

decompiled_code:
ssize_t __fastcall readBlock(int fd, int a2, void *a3)
{
ssize_t result; // rax

if ( (int)lseek(fd, a2 << 8, 0) < 0 )
{
perror("lseek");
exit(1);
}
result = read(fd, a3, 0x100uLL);
if ( (int)result < 0 )
{
perror("read");
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, int a2, void *a3)
{
ssize_t result; // rax

if ( (int)lseek(fd, a2 << 8, 0) < 0 )
{
perror("lseek");
exit(1);
}
result = read(fd, a3, 0x100uLL);
if ( (int)result < 0 )
{
perror("read");
exit(1);
}
return result;
}

original_code:
int readBlock(int disk, int bNum, void *block) {
   int offset = bNum*256, status = 0;
   { if((status = lseek(disk, offset, 0)) < 0) { perror("lseek"); exit(1); } };
   { if((status = read(disk, block, 256)) < 0) { perror("read"); exit(1); } };
   return status;
}

canonical_original_code:
int readBlock(int disk, int bNum, void *block) {
   int offset = bNum*256; int status = 0;
   { if((status = lseek(disk, offset, 0)) < 0) { perror("lseek"); exit(1); } };
   { if((status = read(disk, block, 256)) < 0) { perror("read"); exit(1); } };
   return status;
}

variable_types: bNum int

variable_types:
block
void *

variable_types: status int


writeBlock

decompiled_code:
ssize_t __fastcall writeBlock(int fd, int a2, const void *a3)
{
ssize_t result; // rax

if ( (int)lseek(fd, a2 << 8, 0) < 0 )
{
perror("lseek");
exit(1);
}
result = write(fd, a3, 0x100uLL);
if ( (int)result < 0 )
{
perror("write");
exit(1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, int a2, const void *a3)
{
ssize_t result; // rax

if ( (int)lseek(fd, a2 << 8, 0) < 0 )
{
perror("lseek");
exit(1);
}
result = write(fd, a3, 0x100uLL);
if ( (int)result < 0 )
{
perror("write");
exit(1);
}
return result;
}

original_code:
int writeBlock(int disk, int bNum, void *block) {
   int offset = bNum*256, status = 0;
   { if((status = lseek(disk, offset, 0)) < 0) { perror("lseek"); exit(1); } };
   { if((status = write(disk, block, 256)) < 0) { perror("write"); exit(1); } };
   return status;
}

canonical_original_code:
int writeBlock(int disk, int bNum, void *block) {
   int offset = bNum*256; int status = 0;
   { if((status = lseek(disk, offset, 0)) < 0) { perror("lseek"); exit(1); } };
   { if((status = write(disk, block, 256)) < 0) { perror("write"); exit(1); } };
   return status;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
__int64 v4; // rsi

v3 = 4;
puts("hello world!");
printf("x = %d\n", 5LL);
do
{
v4 = v3++;
printf("%d\n", v4);
}
while ( v3 != 9 );
printf("*z = (should be 4): %d\n", 4LL);
return 0;
}

original_code:
int main() {
 printf ("hello world!\n");
 int x=5;
 printf ("x = %d\n", x);
 for (int y = 4; y < 9; ++y)
  printf ("%d\n", y);
 int* z = (int*) malloc (4);
 *z = 4;
 printf ("*z = (should be 4): %d\n", *z);
 free (z);
 return 0;
}

canonical_original_code:
int main() {
 printf ("hello world!\n");
 int x = 5;
 printf ("x = %d\n", x);
 for (int y = 4; y < 9; ++y)
  printf ("%d\n", y);
 int *z = (int*) malloc (4);
 *z = 4;
 printf ("*z = (should be 4): %d\n", *z);
 free (z);
 return 0;
}

variable_types: x int

variable_types: y int

variable_types:
z
int *


decompiled_code:
__int64 __fastcall err_and_ret(const char *a1)
{
perror(a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
perror(a1);
return 1LL;
}

original_code:
int err_and_ret (const char *msg)
{
 perror (msg);
 return (1);
}

canonical_original_code:
int err_and_ret(char *msg)
{
 perror (msg);
 return (1);
}

variable_types:
msg
char *


repo: rufuscoder/Shakespeer

decompiled_code:
void __fastcall nc_observer_free(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
static void nc_observer_free(nc_observer_t *ob)
{
    if(ob)
    {
        free(ob->channel);
        free(ob);
    }
}

canonical_original_code:
static void nc_observer_free(struct nc_observer *ob)
{
    if(ob)
    {
        free(ob->channel);
        free(ob);
    }
}

variable_types: struct nc_observer { char *channel; void (*callback)(struct notification_center { struct { struct nc_observer *lh_first; } observers; } *nc, char *channel, void *data, void *user_data); void *user_data; struct { struct nc_observer *le_next; struct nc_observer **le_prev; } next; } *

user_defined_types: struct nc_observer { char *channel; void (*callback)(struct notification_center *nc, char *channel, void *data, void *user_data); void *user_data; struct { struct nc_observer *le_next; struct nc_observer **le_prev; } next; }


decompiled_code:
void *nc_new()
{
return calloc(1uLL, 8uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(1uLL, 8uLL);
}

original_code:
nc_t *nc_new(void)
{
    nc_t *nc = calloc(1, sizeof(nc_t));
    return nc;
}

canonical_original_code:
struct notification_center *nc_new()
{
    struct notification_center *nc = calloc(1, sizeof(nc_t));
    return nc;
}

variable_types: struct notification_center { struct { struct nc_observer { char *channel; void (*callback)(struct notification_center *nc, char *channel, void *data, void *user_data); void *user_data; struct { struct nc_observer *le_next; struct nc_observer **le_prev; } next; } *lh_first; } observers; } *

user_defined_types: struct notification_center { struct { struct nc_observer *lh_first; } observers; }


decompiled_code:
void *nc_default()
{
void *result; // rax

result = (void *)default_nc_3;
if ( !default_nc_3 )
{
result = nc_new();
default_nc_3 = (__int64)result;
}
return result;
}

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

result = (void *)default_nc_3;
if ( !default_nc_3 )
{
result = func1();
default_nc_3 = (__int64)result;
}
return result;
}

original_code:
nc_t *nc_default(void)
{
    static nc_t *default_nc = ((void *)0);
    if(default_nc == ((void *)0))
    {
        default_nc = nc_new();
    }
    return default_nc;
}

canonical_original_code:
struct notification_center *nc_default()
{
    static struct notification_center *default_nc = ((void *)0);
    if(default_nc == ((void *)0))
    {
        default_nc = nc_new();
    }
    return default_nc;
}

return_type: struct notification_center { struct { struct nc_observer { char *channel; void (*callback)(struct notification_center *nc, char *channel, void *data, void *user_data); void *user_data; struct { struct nc_observer *le_next; struct nc_observer **le_prev; } next; } *lh_first; } observers; } *


decompiled_code:
void __fastcall nc_remove_observer(__int64 *a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v5; // rax

if ( !a1 )
_assert_fail("nc", "notification_center.c", 0x48u, "nc_remove_observer");
if ( !a2 )
_assert_fail("channel", "notification_center.c", 0x49u, "nc_remove_observer");
if ( !a3 )
_assert_fail("callback", "notification_center.c", 0x4Au, "nc_remove_observer");
v4 = *a1;
if ( *a1 )
{
while ( *(_QWORD *)(v4 + 8) != a3 || strcmp(*(const char **)v4, a2) )
{
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
return;
}
v5 = *(_QWORD *)(v4 + 24);
if ( v5 )
*(_QWORD *)(v5 + 32) = *(_QWORD *)(v4 + 32);
**(_QWORD **)(v4 + 32) = v5;
nc_observer_free((void *)v4);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 *a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
__int64 v5; // rax

if ( !a1 )
_assert_fail("nc", "notification_center.c", 0x48u, "nc_remove_observer");
if ( !a2 )
_assert_fail("channel", "notification_center.c", 0x49u, "nc_remove_observer");
if ( !a3 )
_assert_fail("callback", "notification_center.c", 0x4Au, "nc_remove_observer");
v4 = *a1;
if ( *a1 )
{
while ( *(_QWORD *)(v4 + 8) != a3 || strcmp(*(const char **)v4, a2) )
{
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
return;
}
v5 = *(_QWORD *)(v4 + 24);
if ( v5 )
*(_QWORD *)(v5 + 32) = *(_QWORD *)(v4 + 32);
**(_QWORD **)(v4 + 32) = v5;
func0((void *)v4);
}
}

original_code:
void nc_remove_observer(nc_t *nc, const char *channel, nc_callback_t callback)
{
    ((void) sizeof ((nc) ? 1 : 0), __extension__ ({ if (nc) ; else __assert_fail ("nc", "notification_center.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((channel) ? 1 : 0), __extension__ ({ if (channel) ; else __assert_fail ("channel", "notification_center.c", 73, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((callback) ? 1 : 0), __extension__ ({ if (callback) ; else __assert_fail ("callback", "notification_center.c", 74, __extension__ __PRETTY_FUNCTION__); }));
    nc_observer_t *ob;
    for((ob) = ((&nc->observers)->lh_first); (ob)!= ((void *)0); (ob) = ((ob)->next.le_next))
    {
        if(ob->callback == callback && strcmp(ob->channel, channel) == 0)
        {
            do { if ((ob)->next.le_next != ((void *)0)) (ob)->next.le_next->next.le_prev = (ob)->next.le_prev; *(ob)->next.le_prev = (ob)->next.le_next; } while (0);
            nc_observer_free(ob);
            break;
        }
    }
}

canonical_original_code:
void nc_remove_observer(struct notification_center *nc, char *channel, void (*callback)(struct notification_center *nc, char *channel, void *data, void *user_data))
{
    ((void) sizeof ((nc) ? 1 : 0), __extension__ ({ if (nc) ; else __assert_fail ("nc", "notification_center.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((channel) ? 1 : 0), __extension__ ({ if (channel) ; else __assert_fail ("channel", "notification_center.c", 73, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((callback) ? 1 : 0), __extension__ ({ if (callback) ; else __assert_fail ("callback", "notification_center.c", 74, __extension__ __PRETTY_FUNCTION__); }));
    struct nc_observer *ob;
    for((ob) = ((&nc->observers)->lh_first); (ob)!= ((void *)0); (ob) = ((ob)->next.le_next))
    {
        if(ob->callback == callback && strcmp(ob->channel, channel) == 0)
        {
            do { if ((ob)->next.le_next != ((void *)0)) (ob)->next.le_next->next.le_prev = (ob)->next.le_prev; *(ob)->next.le_prev = (ob)->next.le_next; } while (0);
            nc_observer_free(ob);
            break;
        }
    }
}

variable_types:
channel
char *

variable_types: void (*)(struct notification_center *nc, char *channel, void *data, void *user_data)


decompiled_code:
void __fastcall nc_send_notification(__int64 *a1, const char *a2, __int64 a3)
{
__int64 i; // rbx

if ( !a1 )
_assert_fail("nc", "notification_center.c", 0x5Au, "nc_send_notification");
if ( !a2 )
_assert_fail("channel", "notification_center.c", 0x5Bu, "nc_send_notification");
for ( i = *a1; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(a2, *(const char **)i) )
(*(void (__fastcall **)(__int64 *, const char *, __int64, _QWORD))(i + 8))(a1, a2, a3, *(_QWORD *)(i + 16));
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 *a1, const char *a2, __int64 a3)
{
__int64 i; // rbx

if ( !a1 )
_assert_fail("nc", "notification_center.c", 0x5Au, "nc_send_notification");
if ( !a2 )
_assert_fail("channel", "notification_center.c", 0x5Bu, "nc_send_notification");
for ( i = *a1; i; i = *(_QWORD *)(i + 24) )
{
if ( !strcmp(a2, *(const char **)i) )
(*(void (__fastcall **)(__int64 *, const char *, __int64, _QWORD))(i + 8))(a1, a2, a3, *(_QWORD *)(i + 16));
}
}

original_code:
void nc_send_notification(nc_t *nc, const char *channel, void *data)
{
    ((void) sizeof ((nc) ? 1 : 0), __extension__ ({ if (nc) ; else __assert_fail ("nc", "notification_center.c", 90, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((channel) ? 1 : 0), __extension__ ({ if (channel) ; else __assert_fail ("channel", "notification_center.c", 91, __extension__ __PRETTY_FUNCTION__); }));
    nc_observer_t *ob;
    for((ob) = ((&nc->observers)->lh_first); (ob)!= ((void *)0); (ob) = ((ob)->next.le_next))
    {
        if(strcmp(channel, ob->channel) == 0)
        {
            ob->callback(nc, channel, data, ob->user_data);
        }
    }
}

canonical_original_code:
void nc_send_notification(struct notification_center *nc, char *channel, void *data)
{
    ((void) sizeof ((nc) ? 1 : 0), __extension__ ({ if (nc) ; else __assert_fail ("nc", "notification_center.c", 90, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((channel) ? 1 : 0), __extension__ ({ if (channel) ; else __assert_fail ("channel", "notification_center.c", 91, __extension__ __PRETTY_FUNCTION__); }));
    struct nc_observer *ob;
    for((ob) = ((&nc->observers)->lh_first); (ob)!= ((void *)0); (ob) = ((ob)->next.le_next))
    {
        if(strcmp(channel, ob->channel) == 0)
        {
            ob->callback(nc, channel, data, ob->user_data);
        }
    }
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall xdigit_value(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

if ( (unsigned __int8)(a1 - 65) <= 5u )
return (unsigned int)(char)(a1 - 55);
if ( (unsigned __int8)(a1 - 97) <= 5u )
return (unsigned int)(char)(a1 - 87);
v1 = a1 - 48;
result = (unsigned int)(char)v1;
if ( v1 >= 0xAu )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
unsigned __int8 v1; // di
__int64 result; // rax

if ( (unsigned __int8)(a1 - 65) <= 5u )
return (unsigned int)(char)(a1 - 55);
if ( (unsigned __int8)(a1 - 97) <= 5u )
return (unsigned int)(char)(a1 - 87);
v1 = a1 - 48;
result = (unsigned int)(char)v1;
if ( v1 >= 0xAu )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int xdigit_value(char c)
{
    if(c >= 'A' && c <= 'F')
        return c - 'A' + 10;
    if(c >= 'a' && c <= 'f')
        return c - 'a' + 10;
    if(c >= '0' && c <= '9')
        return c - '0';
    return -1;
}

variable_types: c char


decompiled_code:
_BOOL8 __fastcall is_hex_string(char *a1, int a2)
{
__int64 v2; // rbx
char *v3; // rbp
const unsigned __int16 *v4; // rdx
int v5; // eax
_BOOL8 result; // rax

v2 = *a1;
if ( (_BYTE)v2 )
{
v3 = a1;
v4 = *_ctype_b_loc();
v5 = 0;
while ( (v4[v2] & 0x1000) != 0 )
{
++v5;
v2 = *++v3;
if ( a2 <= v5 || !(_BYTE)v2 )
goto LABEL_8;
}
result = 0LL;
}
else
{
v5 = 0;
LABEL_8:
result = a2 == v5;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *a1, int a2)
{
__int64 v2; // rbx
char *v3; // rbp
const unsigned __int16 *v4; // rdx
int v5; // eax
_BOOL8 result; // rax

v2 = *a1;
if ( (_BYTE)v2 )
{
v3 = a1;
v4 = *_ctype_b_loc();
v5 = 0;
while ( (v4[v2] & 0x1000) != 0 )
{
++v5;
v2 = *++v3;
if ( a2 <= v5 || !(_BYTE)v2 )
goto LABEL_8;
}
result = 0LL;
}
else
{
v5 = 0;
LABEL_8:
result = a2 == v5;
}
return result;
}

original_code:
static int is_hex_string(const char *p, int len)
{
    if(p == 0)
        return 0;
    int i;
    for(i = 0; p && *p && (len == -1 || i < len); p++, i++)
    {
        if(!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISxdigit))
        {
            return 0;
        }
    }
    return ((len == -1) || (i == len)) ? 1 : 0;
}

canonical_original_code:
static int is_hex_string(char *p, int len)
{
    if(p == 0)
        return 0;
    int i;
    for(i = 0; p && *p && (len == -1 || i < len); p++, i++)
    {
        if(!((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISxdigit))
        {
            return 0;
        }
    }
    return ((len == -1) || (i == len)) ? 1 : 0;
}

variable_types:
p
char *

variable_types: len int

variable_types: i int


decompiled_code:
char *__fastcall str_legacy_to_utf8_internal(char *s, __int64 a2, unsigned int a3)
{
__int64 v3; // rbx
char *result; // rax

if ( !s )
return 0LL;
if ( !a2 )
return 0LL;
v3 = a3;
if ( (unsigned int)g_utf8_validate(s, -1LL, 0LL) )
result = strdup(s);
else
result = (char *)iconv_string_full(s, -1LL, a2, "UTF-8", 0LL, 0LL, v3);
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *s, __int64 a2, unsigned int a3)
{
__int64 v3; // rbx
char *result; // rax

if ( !s )
return 0LL;
if ( !a2 )
return 0LL;
v3 = a3;
if ( (unsigned int)g_utf8_validate(s, -1LL, 0LL) )
result = strdup(s);
else
result = (char *)iconv_string_full(s, -1LL, a2, "UTF-8", 0LL, 0LL, v3);
return result;
}

original_code:
static char *str_legacy_to_utf8_internal(const char *string,
        const char *legacy_encoding, int replacement_char)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
    {
        return ((void *)0);
    }
    if(g_utf8_validate(string, -1, ((void *)0)))
    {
        return strdup(string);
    }
    char *utf8_string = iconv_string_full(string, -1,
            legacy_encoding, "UTF-8", ((void *)0), ((void *)0), replacement_char);
    return utf8_string;
}

canonical_original_code:
static char *str_legacy_to_utf8_internal(char *string, char *legacy_encoding, int replacement_char)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
    {
        return ((void *)0);
    }
    if(g_utf8_validate(string, -1, ((void *)0)))
    {
        return strdup(string);
    }
    char *utf8_string = iconv_string_full(string, -1,
            legacy_encoding, "UTF-8", ((void *)0), ((void *)0), replacement_char);
    return utf8_string;
}

variable_types:
string
char *

return_type: char *


decompiled_code:
__int64 __fastcall str_need_unescape_unicode(const char *a1)
{
char *v1; // rax

if ( !a1 )
return 0LL;
while ( 1 )
{
v1 = strchr(a1, 92);
if ( !v1 )
return 0LL;
if ( (v1[1] & 0xDF) == 85 )
break;
a1 = v1 + 1;
if ( !v1[1] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
char *v1; // rax

if ( !a1 )
return 0LL;
while ( 1 )
{
v1 = strchr(a1, 92);
if ( !v1 )
return 0LL;
if ( (v1[1] & 0xDF) == 85 )
break;
a1 = v1 + 1;
if ( !v1[1] )
return 0LL;
}
return 1LL;
}

original_code:
int str_need_unescape_unicode(const char *utf8_string)
{
    if(utf8_string == ((void *)0))
        return 0;
    const char *bs = utf8_string;
    do
    {
        bs = strchr(bs, '\\');
        if(bs && (bs[1] == 'u' || bs[1] == 'U'))
        {
            return 1;
        }
    } while(bs++ && *bs);
    return 0;
}

canonical_original_code:
int str_need_unescape_unicode(char *utf8_string)
{
    if(utf8_string == ((void *)0))
        return 0;
    char *bs = utf8_string;
    do
    {
        bs = strchr(bs, '\\');
        if(bs && (bs[1] == 'u' || bs[1] == 'U'))
        {
            return 1;
        }
    } while(bs++ && *bs);
    return 0;
}

variable_types:
bs
char *


decompiled_code:
__int64 __fastcall str_unescape_unicode(char *a1)
{
char *v1; // rbx
__int64 v2; // rax
__int64 v3; // r13
__int64 v4; // r12
unsigned int v5; // ebp
int v6; // eax
__int64 v7; // r13
char v9; // di
__int16 v10; // ax
__int16 v11; // dx
__int16 v12; // cx
__int16 v13; // ax
char v14; // di
int v15; // eax
int v16; // edx
unsigned int v17; // eax
char v18[46]; // [rsp+Ah] [rbp-2Eh] BYREF

if ( !a1 )
return 0LL;
v1 = a1;
v2 = dstring_new(0LL);
v3 = g_utf8_skip;
v4 = v2;
while ( *v1 )
{
while ( 1 )
{
v5 = g_utf8_get_char(v1);
v1 += *(char *)(v3 + (unsigned __int8)*v1);
if ( v5 == 92 )
{
if ( *v1 == 117 )
{
if ( is_hex_string(v1 + 1, 4) )
{
v9 = v1[1];
v1 += 5;
xdigit_value(v9);
xdigit_value(*(v1 - 3));
xdigit_value(*(v1 - 2));
v10 = xdigit_value(*(v1 - 1));
v13 = _bswap_16(v12 + v10 + 16 * v11);
v5 = (unsigned __int16)_bswap_16(v13);
}
}
else if ( *v1 == 85 && is_hex_string(v1 + 1, 8) )
{
v14 = v1[1];
v1 += 9;
xdigit_value(v14);
xdigit_value(*(v1 - 7));
xdigit_value(*(v1 - 6));
xdigit_value(*(v1 - 5));
xdigit_value(*(v1 - 4));
xdigit_value(*(v1 - 3));
xdigit_value(*(v1 - 2));
v15 = xdigit_value(*(v1 - 1));
v17 = _bswap_32(v16 + v15);
v5 = _bswap_32(v17);
}
if ( !(unsigned int)g_unichar_validate(v5) )
break;
}
v6 = g_unichar_to_utf8(v5, v18);
dstring_append_len(v4, v18, v6);
if ( !*v1 )
goto LABEL_9;
}
}
LABEL_9:
v7 = *(_QWORD *)(v4 + 8);
dstring_free(v4, 0LL);
return v7;
}

original_code:
char *str_unescape_unicode(const char *utf8_string)
{
    if(utf8_string == ((void *)0))
        return ((void *)0);
    dstring_t *unescaped = dstring_new(((void *)0));
    const char *p = utf8_string;
    while(p && *p)
    {
        uint32_t uc = g_utf8_get_char(p);
        p = (char *)((p) + g_utf8_skip[*(unsigned char *)(p)]);
        if(uc == '\\')
        {
            if(*p == 'u' && is_hex_string(p+1, 4))
            {
                p++;
                uc = htons(ntohs( (xdigit_value(p[0]) << 12) + (xdigit_value(p[1]) << 8) + (xdigit_value(p[2]) << 4) + (xdigit_value(p[3]))));
                p += 4;
            }
            else if(*p == 'U' && is_hex_string(p+1, 8))
            {
                p++;
                uc = htonl(ntohl( (xdigit_value(p[0]) << 28) + (xdigit_value(p[1]) << 24) + (xdigit_value(p[2]) << 20) + (xdigit_value(p[3]) << 16) + (xdigit_value(p[4]) << 12) + (xdigit_value(p[5]) << 8) + (xdigit_value(p[6]) << 4) + (xdigit_value(p[7]))));
                p += 8;
            }
            if(!g_unichar_validate(uc))
            {
                continue;
            }
        }
        char utf8_buf[6];
        int utf8_len = g_unichar_to_utf8(uc, utf8_buf);
        dstring_append_len(unescaped, utf8_buf, utf8_len);
    }
    char *result = unescaped->string;
    dstring_free(unescaped, 0);
    return result;
}

canonical_original_code:
char *str_unescape_unicode(char *utf8_string)
{
    if(utf8_string == ((void *)0))
        return ((void *)0);
    struct dstring *unescaped = dstring_new(((void *)0));
    char *p = utf8_string;
    while(p && *p)
    {
        unsigned int uc = g_utf8_get_char(p);
        p = (char *)((p) + g_utf8_skip[*(unsigned char *)(p)]);
        if(uc == '\\')
        {
            if(*p == 'u' && is_hex_string(p+1, 4))
            {
                p++;
                uc = htons(ntohs( (xdigit_value(p[0]) << 12) + (xdigit_value(p[1]) << 8) + (xdigit_value(p[2]) << 4) + (xdigit_value(p[3]))));
                p += 4;
            }
            else if(*p == 'U' && is_hex_string(p+1, 8))
            {
                p++;
                uc = htonl(ntohl( (xdigit_value(p[0]) << 28) + (xdigit_value(p[1]) << 24) + (xdigit_value(p[2]) << 20) + (xdigit_value(p[3]) << 16) + (xdigit_value(p[4]) << 12) + (xdigit_value(p[5]) << 8) + (xdigit_value(p[6]) << 4) + (xdigit_value(p[7]))));
                p += 8;
            }
            if(!g_unichar_validate(uc))
            {
                continue;
            }
        }
        char utf8_buf[6];
        int utf8_len = g_unichar_to_utf8(uc, utf8_buf);
        dstring_append_len(unescaped, utf8_buf, utf8_len);
    }
    char *result = unescaped->string;
    dstring_free(unescaped, 0);
    return result;
}

variable_types: struct dstring { unsigned int length; unsigned int allocated; char *string; } *

variable_types:
uc
unsigned int

variable_types:
result
char *


decompiled_code:
char *__fastcall str_legacy_to_utf8(char *a1, __int64 a2)
{
return str_legacy_to_utf8_internal(a1, a2, 0xFFFFFFFF);
}

canonical_decompiled_code:
char *__fastcall func7(char *a1, __int64 a2)
{
return func4(a1, a2, 0xFFFFFFFF);
}

original_code:
char *str_legacy_to_utf8(const char *string, const char *legacy_encoding)
{
    return str_legacy_to_utf8_internal(string, legacy_encoding, -1);
}

canonical_original_code:
char *str_legacy_to_utf8(char *string, char *legacy_encoding)
{
    return str_legacy_to_utf8_internal(string, legacy_encoding, -1);
}


decompiled_code:
char *__fastcall str_legacy_to_utf8_lossy(char *a1, __int64 a2)
{
return str_legacy_to_utf8_internal(a1, a2, 0x3Fu);
}

canonical_decompiled_code:
char *__fastcall func8(char *a1, __int64 a2)
{
return func4(a1, a2, 0x3Fu);
}

original_code:
char *str_legacy_to_utf8_lossy(const char *string, const char *legacy_encoding)
{
    return str_legacy_to_utf8_internal(string, legacy_encoding, '?');
}

canonical_original_code:
char *str_legacy_to_utf8_lossy(char *string, char *legacy_encoding)
{
    return str_legacy_to_utf8_internal(string, legacy_encoding, '?');
}


decompiled_code:
char *__fastcall str_convert_to_unescaped_utf8(char *a1, __int64 a2)
{
char *v2; // rax
char *v3; // r12
__int64 v5; // rbx

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = str_legacy_to_utf8(a1, a2);
v3 = v2;
if ( !v2 )
return 0LL;
if ( !(unsigned int)str_need_unescape_unicode(v2) )
return v3;
v5 = str_unescape_unicode(v3);
free(v3);
return (char *)v5;
}

canonical_decompiled_code:
char *__fastcall func9(char *a1, __int64 a2)
{
char *v2; // rax
char *v3; // r12
__int64 v5; // rbx

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = func7(a1, a2);
v3 = v2;
if ( !v2 )
return 0LL;
if ( !(unsigned int)func5(v2) )
return v3;
v5 = func6(v3);
free(v3);
return (char *)v5;
}

original_code:
char *str_convert_to_unescaped_utf8(const char *string, const char *legacy_encoding)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
        return ((void *)0);
    char *utf8_string = str_legacy_to_utf8(string, legacy_encoding);
    if(utf8_string)
    {
        if(str_need_unescape_unicode(utf8_string))
        {
            char *unescaped_utf8 = str_unescape_unicode(utf8_string);
            free(utf8_string);
            return unescaped_utf8;
        }
        else
            return utf8_string;
    }
    return ((void *)0);
}

canonical_original_code:
char *str_convert_to_unescaped_utf8(char *string, char *legacy_encoding)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
        return ((void *)0);
    char *utf8_string = str_legacy_to_utf8(string, legacy_encoding);
    if(utf8_string)
    {
        if(str_need_unescape_unicode(utf8_string))
        {
            char *unescaped_utf8 = str_unescape_unicode(utf8_string);
            free(utf8_string);
            return unescaped_utf8;
        }
        else
            return utf8_string;
    }
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall str_utf8_to_legacy(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4; // r12

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = g_utf8_normalize(a1, -1LL, 1LL);
v3 = (void *)v2;
if ( !v2 )
return 0LL;
v4 = iconv_string(v2, -1LL, "UTF-8", a2);
free(v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4; // r12

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = g_utf8_normalize(a1, -1LL, 1LL);
v3 = (void *)v2;
if ( !v2 )
return 0LL;
v4 = iconv_string(v2, -1LL, "UTF-8", a2);
free(v3);
return v4;
}

original_code:
char *str_utf8_to_legacy(const char *string, const char *legacy_encoding)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
        return ((void *)0);
    char *utf8_composed_string = g_utf8_normalize(string, -1, G_NORMALIZE_DEFAULT_COMPOSE);
    if(utf8_composed_string == ((void *)0))
    {
        return ((void *)0);
    }
    char *legacy_string = iconv_string(utf8_composed_string, -1,
            "UTF-8", legacy_encoding);
    free(utf8_composed_string);
    return legacy_string;
}

canonical_original_code:
char *str_utf8_to_legacy(char *string, char *legacy_encoding)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
        return ((void *)0);
    char *utf8_composed_string = g_utf8_normalize(string, -1, G_NORMALIZE_DEFAULT_COMPOSE);
    if(utf8_composed_string == ((void *)0))
    {
        return ((void *)0);
    }
    char *legacy_string = iconv_string(utf8_composed_string, -1,
            "UTF-8", legacy_encoding);
    free(utf8_composed_string);
    return legacy_string;
}


decompiled_code:
__int64 __fastcall str_utf8_to_escaped_legacy(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4; // r12
unsigned int v6; // eax

if ( !a1 || !a2 )
return 0LL;
v2 = g_utf8_normalize(a1, -1LL, 1LL);
v3 = (void *)v2;
if ( v2 )
{
v4 = iconv_string_escaped(v2, -1LL, "UTF-8", a2);
free(v3);
}
else
{
v6 = getpid();
v4 = 0LL;
sp_log(16LL, "[%d] (%s:%i) input string not valid UTF-8", v6, "str_utf8_to_escaped_legacy", 267LL);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rax
void *v3; // rbp
__int64 v4; // r12
unsigned int v6; // eax

if ( !a1 || !a2 )
return 0LL;
v2 = g_utf8_normalize(a1, -1LL, 1LL);
v3 = (void *)v2;
if ( v2 )
{
v4 = iconv_string_escaped(v2, -1LL, "UTF-8", a2);
free(v3);
}
else
{
v6 = getpid();
v4 = 0LL;
sp_log(16LL, "[%d] (%s:%i) input string not valid UTF-8", v6, "str_utf8_to_escaped_legacy", 267LL);
}
return v4;
}

original_code:
char *str_utf8_to_escaped_legacy(const char *string,
        const char *legacy_encoding)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
    {
        return ((void *)0);
    }
    char *utf8_composed_string = g_utf8_normalize(string, -1, G_NORMALIZE_DEFAULT_COMPOSE);
    if(utf8_composed_string == ((void *)0))
    {
        sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "input string not valid UTF-8", getpid(), __func__, 267);
        return ((void *)0);
    }
    char *legacy_string = iconv_string_escaped(utf8_composed_string, -1,
            "UTF-8", legacy_encoding);
    free(utf8_composed_string);
    return legacy_string;
}

canonical_original_code:
char *str_utf8_to_escaped_legacy(char *string, char *legacy_encoding)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
    {
        return ((void *)0);
    }
    char *utf8_composed_string = g_utf8_normalize(string, -1, G_NORMALIZE_DEFAULT_COMPOSE);
    if(utf8_composed_string == ((void *)0))
    {
        sp_log(LOG_LEVEL_WARNING, "[%d] (%s:%i) " "input string not valid UTF-8", getpid(), __func__, 267);
        return ((void *)0);
    }
    char *legacy_string = iconv_string_escaped(utf8_composed_string, -1,
            "UTF-8", legacy_encoding);
    free(utf8_composed_string);
    return legacy_string;
}


decompiled_code:
char *__fastcall str_convert_to_escaped_utf8(char *a1, __int64 a2)
{
char *v2; // rax
char *v3; // r12
char *v4; // r13
char *v5; // r12

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = str_legacy_to_utf8(a1, a2);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = (char *)str_utf8_to_escaped_legacy((__int64)v2, a2);
free(v3);
if ( !v4 )
return 0LL;
v5 = str_legacy_to_utf8(v4, a2);
free(v4);
return v5;
}

canonical_decompiled_code:
char *__fastcall func12(char *a1, __int64 a2)
{
char *v2; // rax
char *v3; // r12
char *v4; // r13
char *v5; // r12

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = func7(a1, a2);
v3 = v2;
if ( !v2 )
return 0LL;
v4 = (char *)func11((__int64)v2, a2);
free(v3);
if ( !v4 )
return 0LL;
v5 = func7(v4, a2);
free(v4);
return v5;
}

original_code:
char *str_convert_to_escaped_utf8(const char *string, const char *legacy_encoding)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
        return ((void *)0);
    char *utf8_string = str_legacy_to_utf8(string, legacy_encoding);
    if(utf8_string == ((void *)0))
        return ((void *)0);
    char *legacy_fallback = str_utf8_to_escaped_legacy(utf8_string,
            legacy_encoding);
    free(utf8_string);
    if(legacy_fallback == ((void *)0))
        return ((void *)0);
    utf8_string = str_legacy_to_utf8(legacy_fallback, legacy_encoding);
    free(legacy_fallback);
    return utf8_string;
}

canonical_original_code:
char *str_convert_to_escaped_utf8(char *string, char *legacy_encoding)
{
    if(string == ((void *)0) || legacy_encoding == ((void *)0))
        return ((void *)0);
    char *utf8_string = str_legacy_to_utf8(string, legacy_encoding);
    if(utf8_string == ((void *)0))
        return ((void *)0);
    char *legacy_fallback = str_utf8_to_escaped_legacy(utf8_string,
            legacy_encoding);
    free(utf8_string);
    if(legacy_fallback == ((void *)0))
        return ((void *)0);
    utf8_string = str_legacy_to_utf8(legacy_fallback, legacy_encoding);
    free(legacy_fallback);
    return utf8_string;
}


decompiled_code:
void __fastcall hl_hub_free(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 7));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 7));
free(ptr);
}
}

original_code:
static void hl_hub_free(hublist_hub_t *h)
{
    if(h)
    {
        free(h->name);
        free(h->address);
        free(h->description);
        free(h->country);
        free(h);
    }
}

canonical_original_code:
static void hl_hub_free(struct hublist_hub *h)
{
    if(h)
    {
        free(h->name);
        free(h->address);
        free(h->description);
        free(h->country);
        free(h);
    }
}

variable_types: struct hublist_hub { struct { struct hublist_hub *le_next; struct hublist_hub **le_prev; } link; char *name; char *address; char *description; unsigned int max_users; unsigned int current_users; unsigned int reliability; char *country; int min_slots; int max_hubs; unsigned long min_share; } *


decompiled_code:
void __fastcall hl_xml_parse_start_element(__int64 *a1, const char *a2, const char **a3)
{
_QWORD *v5; // rbp
const char **v6; // r13
unsigned int v7; // er14
const char *i; // rax
bool v9; // dl
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi
char v15; // dl
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
const char *v20; // rsi
__int64 v21; // rax

if ( !strcasecmp(a2, "Hub") )
{
v5 = calloc(1uLL, 0x50uLL);
if ( a3 )
{
v6 = a3;
v7 = 1;
for ( i = *a3; i; v7 += 2 )
{
v9 = strcmp(i, "Address") != 0;
v10 = 0;
v11 = !v9;
if ( v9 )
{
v12 = "Name";
v13 = 5LL;
v14 = i;
do
{
if ( !v13 )
break;
v10 = *v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
v15 = (!v10 && !v11) - v10;
v16 = 0;
v17 = v15 == 0;
if ( v15 )
{
v18 = "Description";
v19 = 12LL;
v20 = i;
do
{
if ( !v19 )
break;
v16 = *v20 < (unsigned int)*v18;
v17 = *v20++ == *v18++;
--v19;
}
while ( v17 );
if ( (!v16 && !v17) == v16 )
{
v5[4] = nmdc_unescape(a3[v7], v20);
}
else if ( !strcmp(i, "Country") )
{
v5[7] = strdup(a3[v7]);
}
else if ( !strcmp(i, "Minshare") )
{
v5[9] = strtoull(a3[v7], 0LL, 10);
}
else if ( !strcmp(i, "Maxhubs") )
{
*((_DWORD *)v5 + 17) = strtoul(a3[v7], 0LL, 10);
}
else if ( !strcmp(i, "Maxusers") )
{
*((_DWORD *)v5 + 10) = strtoul(a3[v7], 0LL, 10);
}
else if ( !strcmp(i, "Reliability") )
{
*((_DWORD *)v5 + 12) = strtoul(a3[v7], 0LL, 10);
}
else if ( !strcmp(i, "Users") )
{
*((_DWORD *)v5 + 11) = strtoul(a3[v7], 0LL, 10);
}
else if ( !strcmp(i, "Minslots") )
{
*((_DWORD *)v5 + 16) = strtoul(a3[v7], 0LL, 10);
}
}
else
{
v5[2] = nmdc_unescape(a3[v7], v14);
}
}
else
{
v5[3] = strdup(a3[v7]);
}
i = v6[2];
v6 += 2;
}
}
if ( v5[3] )
{
v21 = *a1;
*v5 = *a1;
if ( v21 )
*(_QWORD *)(v21 + 8) = v5;
*a1 = (__int64)v5;
v5[1] = a1;
}
else
{
hl_hub_free(v5);
}
}
}

original_code:
static void hl_xml_parse_start_element(void *data,
        const char *el, const char **attr)
{
    hublist_t *hlist = data;
    if(strcasecmp(el, "Hub") != 0)
    {
        return;
    }
    hublist_hub_t *h = calloc(1, sizeof(hublist_hub_t));
    int i;
    for(i = 0; attr && attr[i]; i += 2)
    {
        if(strcmp(attr[i], "Address") == 0)
        {
            h->address = strdup(attr[i+1]);
        }
        else if(strcmp(attr[i], "Name") == 0)
        {
            h->name = nmdc_unescape(attr[i+1]);
        }
        else if(strcmp(attr[i], "Description") == 0)
        {
            h->description = nmdc_unescape(attr[i+1]);
        }
        else if(strcmp(attr[i], "Country") == 0)
        {
            h->country = strdup(attr[i+1]);
        }
        else if(strcmp(attr[i], "Minshare") == 0)
        {
            h->min_share = strtoull(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Maxhubs") == 0)
        {
            h->max_hubs = strtoul(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Maxusers") == 0)
        {
            h->max_users = strtoul(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Reliability") == 0)
        {
            h->reliability = strtoul(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Users") == 0)
        {
            h->current_users = strtoul(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Minslots") == 0)
        {
            h->min_slots = strtoul(attr[i+1], ((void *)0), 10);
        }
    }
    if(h->address == ((void *)0))
    {
        hl_hub_free(h);
    }
    else
    {
        do { if (((h)->link.le_next = (hlist)->lh_first) != ((void *)0)) (hlist)->lh_first->link.le_prev = &(h)->link.le_next; (hlist)->lh_first = (h); (h)->link.le_prev = &(hlist)->lh_first; } while (0);
    }
}

canonical_original_code:
static void hl_xml_parse_start_element(void *data, char *el, char **attr)
{
    struct hublist *hlist = data;
    if(strcasecmp(el, "Hub") != 0)
    {
        return;
    }
    struct hublist_hub *h = calloc(1, sizeof(hublist_hub_t));
    int i;
    for(i = 0; attr && attr[i]; i += 2)
    {
        if(strcmp(attr[i], "Address") == 0)
        {
            h->address = strdup(attr[i+1]);
        }
        else if(strcmp(attr[i], "Name") == 0)
        {
            h->name = nmdc_unescape(attr[i+1]);
        }
        else if(strcmp(attr[i], "Description") == 0)
        {
            h->description = nmdc_unescape(attr[i+1]);
        }
        else if(strcmp(attr[i], "Country") == 0)
        {
            h->country = strdup(attr[i+1]);
        }
        else if(strcmp(attr[i], "Minshare") == 0)
        {
            h->min_share = strtoull(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Maxhubs") == 0)
        {
            h->max_hubs = strtoul(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Maxusers") == 0)
        {
            h->max_users = strtoul(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Reliability") == 0)
        {
            h->reliability = strtoul(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Users") == 0)
        {
            h->current_users = strtoul(attr[i+1], ((void *)0), 10);
        }
        else if(strcmp(attr[i], "Minslots") == 0)
        {
            h->min_slots = strtoul(attr[i+1], ((void *)0), 10);
        }
    }
    if(h->address == ((void *)0))
    {
        hl_hub_free(h);
    }
    else
    {
        do { if (((h)->link.le_next = (hlist)->lh_first) != ((void *)0)) (hlist)->lh_first->link.le_prev = &(h)->link.le_next; (hlist)->lh_first = (h); (h)->link.le_prev = &(hlist)->lh_first; } while (0);
    }
}

variable_types:
el
char *

variable_types:
attr
char **

variable_types: struct hublist { struct hublist_hub { struct { struct hublist_hub *le_next; struct hublist_hub **le_prev; } link; char *name; char *address; char *description; unsigned int max_users; unsigned int current_users; unsigned int reliability; char *country; int min_slots; int max_hubs; unsigned long min_share; } *lh_first; } *

user_defined_types: struct hublist { struct hublist_hub *lh_first; }


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

result = country_map_lookup();
if ( !result )
result = a1;
return result;
}

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

result = country_map_lookup();
if ( !result )
result = a1;
return result;
}

original_code:
const char *hl_lookup_country(const char *country_code)
{
    const char *longname = country_map_lookup(country_code);
    if(longname == ((void *)0))
        return country_code;
    return longname;
}

canonical_original_code:
char *hl_lookup_country(char *country_code)
{
    char *longname = country_map_lookup(country_code);
    if(longname == ((void *)0))
        return country_code;
    return longname;
}

variable_types:
longname
char *


original_code:
static hublist_hub_t *hl_parse_entry(arg_t *args)
{
    ((void) sizeof ((args) ? 1 : 0), __extension__ ({ if (args) ; else __assert_fail ("args", "hublist.c", 53, __extension__ __PRETTY_FUNCTION__); }));
    if(args->argc < 4)
        return ((void *)0);
    hublist_hub_t *h = calloc(1, sizeof(hublist_hub_t));
    h->name = strdup(args->argv[0]);
    if(h->name == ((void *)0))
    {
        free(h);
        return ((void *)0);
    }
    rx_subs_t *subs = rx_search(args->argv[2],
            "<R: *([0-9]+)%,S:[^,]+,C:([a-zA-Z0-9-]+)> (.*)");
    if(subs && subs->nsubs == 3)
    {
        h->reliability = strtoul(subs->subs[0], ((void *)0), 10);
        h->country = strdup(hl_lookup_country(subs->subs[1]));
        h->description = strdup(subs->subs[2]);
        rx_free_subs(subs);
    }
    else
    {
        h->description = strdup(args->argv[2]);
    }
    if(h->description == ((void *)0))
    {
        free(h->name);
        free(h->country);
        free(h);
        return ((void *)0);
    }
    h->address = strdup(args->argv[1]);
    h->current_users = strtoul(args->argv[3], ((void *)0), 10);
    return h;
}

canonical_original_code:
static struct hublist_hub *hl_parse_entry(struct arg_t *args)
{
    ((void) sizeof ((args) ? 1 : 0), __extension__ ({ if (args) ; else __assert_fail ("args", "hublist.c", 53, __extension__ __PRETTY_FUNCTION__); }));
    if(args->argc < 4)
        return ((void *)0);
    struct hublist_hub *h = calloc(1, sizeof(hublist_hub_t));
    h->name = strdup(args->argv[0]);
    if(h->name == ((void *)0))
    {
        free(h);
        return ((void *)0);
    }
    struct rx_subs *subs = rx_search(args->argv[2],
            "<R: *([0-9]+)%,S:[^,]+,C:([a-zA-Z0-9-]+)> (.*)");
    if(subs && subs->nsubs == 3)
    {
        h->reliability = strtoul(subs->subs[0], ((void *)0), 10);
        h->country = strdup(hl_lookup_country(subs->subs[1]));
        h->description = strdup(subs->subs[2]);
        rx_free_subs(subs);
    }
    else
    {
        h->description = strdup(args->argv[2]);
    }
    if(h->description == ((void *)0))
    {
        free(h->name);
        free(h->country);
        free(h);
        return ((void *)0);
    }
    h->address = strdup(args->argv[1]);
    h->current_users = strtoul(args->argv[3], ((void *)0), 10);
    return h;
}

variable_types: struct arg_t { int argc; char **argv; } *

variable_types: struct rx_subs { int nsubs; char **subs; } *

return_type: struct hublist_hub { struct { struct hublist_hub *le_next; struct hublist_hub **le_prev; } link; char *name; char *address; char *description; unsigned int max_users; unsigned int current_users; unsigned int reliability; char *country; int min_slots; int max_hubs; unsigned long min_share; } *


decompiled_code:
void __fastcall hl_free(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
_QWORD *v4; // rax

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( v2 )
{
v3 = (_QWORD *)*v2;
v4 = (_QWORD *)v2[1];
if ( *v2 )
{
do
{
v3[1] = v4;
*v4 = v3;
hl_hub_free(v2);
v2 = v3;
v3 = (_QWORD *)*v3;
v4 = (_QWORD *)v2[1];
}
while ( v3 );
}
*v4 = 0LL;
hl_hub_free(v2);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *v3; // rbx
_QWORD *v4; // rax

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( v2 )
{
v3 = (_QWORD *)*v2;
v4 = (_QWORD *)v2[1];
if ( *v2 )
{
do
{
v3[1] = v4;
*v4 = v3;
func0(v2);
v2 = v3;
v3 = (_QWORD *)*v3;
v4 = (_QWORD *)v2[1];
}
while ( v3 );
}
*v4 = 0LL;
func0(v2);
}
free(ptr);
}
}

original_code:
void hl_free(hublist_t *hlist)
{
    if(hlist)
    {
        hublist_hub_t *h, *next;
        for(h = ((hlist)->lh_first); h; h = next)
        {
            next = ((h)->link.le_next);
            do { if ((h)->link.le_next != ((void *)0)) (h)->link.le_next->link.le_prev = (h)->link.le_prev; *(h)->link.le_prev = (h)->link.le_next; } while (0);
            hl_hub_free(h);
        }
        free(hlist);
    }
}

canonical_original_code:
void hl_free(struct hublist *hlist)
{
    if(hlist)
    {
        struct hublist_hub *h; struct hublist_hub *next;
        for(h = ((hlist)->lh_first); h; h = next)
        {
            next = ((h)->link.le_next);
            do { if ((h)->link.le_next != ((void *)0)) (h)->link.le_next->link.le_prev = (h)->link.le_prev; *(h)->link.le_prev = (h)->link.le_next; } while (0);
            hl_hub_free(h);
        }
        free(hlist);
    }
}

user_defined_types: struct hublist_hub { struct { struct hublist_hub *le_next; struct hublist_hub **le_prev; } link; char *name; char *address; char *description; unsigned int max_users; unsigned int current_users; unsigned int reliability; char *country; int min_slots; int max_hubs; unsigned long min_share; }