lookup

repo: orodley/ali

decompiled_code:
__int64 __fastcall lookup(__int64 a1, _QWORD *a2)
{
if ( !a2 )
return 0LL;
if ( (unsigned int)eq(a1, *a2) )
return a2[1];
return lookup(a1, a2[2]);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2)
{
if ( !a2 )
return 0LL;
if ( (unsigned int)eq(a1, *a2) )
return a2[1];
return func0(a1, a2[2]);
}

original_code:
LispObj *lookup(LispObj *symbol, Env *env)
{
 if (env == ((void *)0))
  return ((void *)0);
 else if (eq(symbol, env->key))
  return env->value;
 else
  return lookup(symbol, env->next);
}

canonical_original_code:
struct LispObj *lookup(struct LispObj *symbol, struct Env *env)
{
 if (env == ((void *)0))
  return ((void *)0);
 else if (eq(symbol, env->key))
  return env->value;
 else
  return lookup(symbol, env->next);
}

variable_types:
symbol
struct LispObj *

variable_types:
env
struct Env *

return_type: struct LispObj { union { int l_int; int l_bool; char l_char; char *l_string; char *l_symbol; struct Cons { struct LispObj *car; struct LispObj *cdr; } *l_cons; struct LispObj *(*l_function)(int argc, struct LispObj *argv[], struct Env { struct LispObj *key; struct LispObj *value; struct Env *next; } *env); enum ErrorCode { UNMATCHED_CLOSE_PAREN=0, UNBOUND_VAR=1, NOT_A_FUNCTION=2, WRONG_ARGC=3, NAME_NOT_A_SYMBOL=4, WRONG_TYPE=5, REDEFINITION=6 } l_err; } value; enum LispType { INT=0, BOOL=1, CHAR=2, STRING=3, SYMBOL=4, CONS=5, NIL=6, FUNCTION=7, ERROR=8 } type; int refc; } *

user_defined_types: struct LispObj { union { int l_int; int l_bool; char l_char; char *l_string; char *l_symbol; struct Cons *l_cons; struct LispObj *(*l_function)(int argc, struct LispObj *argv[], struct Env *env); enum ErrorCode l_err; } value; enum LispType type; int refc; }


decompiled_code:
__int64 __fastcall free_env(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax

if ( a1 )
{
free_lisp_obj(*a1);
free_lisp_obj(a1[1]);
v1 = a1[2];
free(a1);
result = free_env(v1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 v1; // rbp
__int64 result; // rax

if ( a1 )
{
free_lisp_obj(*a1);
free_lisp_obj(a1[1]);
v1 = a1[2];
free(a1);
result = func1(v1);
}
return result;
}

original_code:
void free_env(Env *env)
{
 if (env == ((void *)0))
  return;
 free_lisp_obj(env->key);
 free_lisp_obj(env->value);
 Env *next = env->next;
 free(env);
 free_env(next);
}

canonical_original_code:
void free_env(struct Env *env)
{
 if (env == ((void *)0))
  return;
 free_lisp_obj(env->key);
 free_lisp_obj(env->value);
 struct Env *next = env->next;
 free(env);
 free_env(next);
}

variable_types: struct Env { struct LispObj { union { int l_int; int l_bool; char l_char; char *l_string; char *l_symbol; struct Cons { struct LispObj *car; struct LispObj *cdr; } *l_cons; struct LispObj *(*l_function)(int argc, struct LispObj *argv[], struct Env *env); enum ErrorCode { UNMATCHED_CLOSE_PAREN=0, UNBOUND_VAR=1, NOT_A_FUNCTION=2, WRONG_ARGC=3, NAME_NOT_A_SYMBOL=4, WRONG_TYPE=5, REDEFINITION=6 } l_err; } value; enum LispType { INT=0, BOOL=1, CHAR=2, STRING=3, SYMBOL=4, CONS=5, NIL=6, FUNCTION=7, ERROR=8 } type; int refc; } *key; struct LispObj *value; struct Env *next; } *

return_type: void

user_defined_types: struct Env { struct LispObj *key; struct LispObj *value; struct Env *next; }


set

original_code:
void set(Env *env, LispObj *key, LispObj *value)
{
 if (env == ((void *)0))
  return;
 if (eq(key, env->key)) {
  free_lisp_obj(env->value);
  env->value = value;
  value->refc++;
 } else {
  set(env->next, key, value);
 }
}

canonical_original_code:
void set(struct Env *env, struct LispObj *key, struct LispObj *value)
{
 if (env == ((void *)0))
  return;
 if (eq(key, env->key)) {
  free_lisp_obj(env->value);
  env->value = value;
  value->refc++;
 } else {
  set(env->next, key, value);
 }
}

variable_types:
key
struct LispObj *

variable_types:
value
struct LispObj *

user_defined_types: enum LispType { INT=0, BOOL=1, CHAR=2, STRING=3, SYMBOL=4, CONS=5, NIL=6, FUNCTION=7, ERROR=8 }

user_defined_types: enum ErrorCode { UNMATCHED_CLOSE_PAREN=0, UNBOUND_VAR=1, NOT_A_FUNCTION=2, WRONG_ARGC=3, NAME_NOT_A_SYMBOL=4, WRONG_TYPE=5, REDEFINITION=6 }

user_defined_types: struct Cons { struct LispObj *car; struct LispObj *cdr; }


decompiled_code:
__int64 __fastcall print_env(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
prin1(*a1);
fwrite(" => ", 1uLL, 4uLL, stdout);
prin1(a1[1]);
putchar(10);
result = print_env(a1[2]);
}
return result;
}

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

if ( a1 )
{
prin1(*a1);
fwrite(" => ", 1uLL, 4uLL, stdout);
prin1(a1[1]);
putchar(10);
result = func3(a1[2]);
}
return result;
}

original_code:
void print_env(Env *env)
{
 if (env == ((void *)0))
  return;
 prin1(env->key);
 fputs(" => ", stdout);
 prin1(env->value);
 putchar('\n');
 print_env(env->next);
}

canonical_original_code:
void print_env(struct Env *env)
{
 if (env == ((void *)0))
  return;
 prin1(env->key);
 fputs(" => ", stdout);
 prin1(env->value);
 putchar('\n');
 print_env(env->next);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rbx

v3 = get_init_env(argc, argv, envp);
yyout = fopen("/dev/null", "r");
while ( 1 )
{
fwrite("> ", 1uLL, 2uLL, stdout);
v5 = read_from_stream(stdin);
v6 = v5;
if ( !v5 )
break;
add_ref(v5);
v4 = eval(v6, v3);
add_ref(v4);
free_lisp_obj(v6);
fputc(58, stdout);
print(v4);
free_lisp_obj(v4);
}
putchar(10);
yylex_destroy();
free_env(v3);
free_nil();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 LispObj *obj, *value;
 Env *init_env = get_init_env();
 yyout = fopen("/dev/null", "r");
 for (;;) {
  fputs(PROMPT, stdout);
  obj = read_from_stream(stdin);
  if (obj == ((void *)0))
   break;
  add_ref(obj);
  value = eval(obj, init_env);
  add_ref(value);
  free_lisp_obj(obj);
  fputs(RESULT, stdout);
  print(value);
  free_lisp_obj(value);
 }
 putchar('\n');
 yylex_destroy();
 free_env(init_env);
 free_nil();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct LispObj *obj; struct LispObj *value;
 struct Env *init_env = get_init_env();
 yyout = fopen("/dev/null", "r");
 for (;;) {
  fputs(PROMPT, stdout);
  obj = read_from_stream(stdin);
  if (obj == ((void *)0))
   break;
  add_ref(obj);
  value = eval(obj, init_env);
  add_ref(value);
  free_lisp_obj(obj);
  fputs(RESULT, stdout);
  print(value);
  free_lisp_obj(value);
 }
 putchar('\n');
 yylex_destroy();
 free_env(init_env);
 free_nil();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct LispObj { union { int l_int; int l_bool; char l_char; char *l_string; char *l_symbol; struct Cons { struct LispObj *car; struct LispObj *cdr; } *l_cons; struct LispObj *(*l_function)(int argc, struct LispObj *argv[], struct Env { struct LispObj *key; struct LispObj *value; struct Env *next; } *env); enum ErrorCode { UNMATCHED_CLOSE_PAREN=0, UNBOUND_VAR=1, NOT_A_FUNCTION=2, WRONG_ARGC=3, NAME_NOT_A_SYMBOL=4, WRONG_TYPE=5, REDEFINITION=6 } l_err; } value; enum LispType { INT=0, BOOL=1, CHAR=2, STRING=3, SYMBOL=4, CONS=5, NIL=6, FUNCTION=7, ERROR=8 } type; int refc; } *

return_type: int


decompiled_code:
__int64 __fastcall b_plus(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // rdi
_DWORD *v5; // rdx
__int64 result; // rax

if ( a1 <= 0 )
{
v4 = 0LL;
LABEL_5:
result = make_int(v4);
}
else
{
v2 = a2;
v3 = a2 + 8LL * (unsigned int)(a1 - 1) + 8;
LODWORD(v4) = 0;
while ( 1 )
{
v5 = *(_DWORD **)v2;
if ( *(_DWORD *)(*(_QWORD *)v2 + 8LL) )
break;
v4 = (unsigned int)(*v5 + v4);
v2 += 8LL;
if ( v2 == v3 )
goto LABEL_5;
}
result = make_error(5LL, a2, v5, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // rdi
_DWORD *v5; // rdx
__int64 result; // rax

if ( a1 <= 0 )
{
v4 = 0LL;
LABEL_5:
result = make_int(v4);
}
else
{
v2 = a2;
v3 = a2 + 8LL * (unsigned int)(a1 - 1) + 8;
LODWORD(v4) = 0;
while ( 1 )
{
v5 = *(_DWORD **)v2;
if ( *(_DWORD *)(*(_QWORD *)v2 + 8LL) )
break;
v4 = (unsigned int)(*v5 + v4);
v2 += 8LL;
if ( v2 == v3 )
goto LABEL_5;
}
result = make_error(5LL, a2, v5, v3);
}
return result;
}

original_code:
struct LispObj *b_plus(int argc, struct LispObj *argv[], struct Env *env)
{
 int result = 0;
 for (int i = 0; i < argc; i++) {
  if (argv[i]->type != INT)
   return make_error(WRONG_TYPE);
  result += argv[i]->value.l_int;
 }
 return make_int(result);
}

variable_types:
argv
struct LispObj *[]

variable_types: result int

variable_types: i int


decompiled_code:
__int64 __fastcall b_minus(int a1, unsigned __int64 *a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // rdx
_DWORD *v5; // rax
bool v6; // cc
__int64 v7; // rdi
unsigned __int64 *v8; // rax

if ( !a1 )
return make_error(3LL, a2, a3, a4);
v4 = (unsigned int)a1;
v5 = (_DWORD *)*a2;
if ( !*(_DWORD *)(*a2 + 8) )
{
v6 = a1 <= 1;
if ( a1 == 1 )
return make_int((unsigned int)-*v5);
v7 = (unsigned int)*v5;
if ( v6 )
return make_int(v7);
v8 = a2 + 1;
a4 = (__int64)&a2[(unsigned int)(v4 - 2) + 2];
while ( 1 )
{
v4 = *v8;
if ( *(_DWORD *)(*v8 + 8) )
break;
v7 = (unsigned int)(v7 - *(_DWORD *)v4);
if ( ++v8 == (unsigned __int64 *)a4 )
return make_int(v7);
}
}
return make_error(5LL, a2, v4, a4);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned __int64 *a2, __int64 a3, __int64 a4)
{
unsigned __int64 v4; // rdx
_DWORD *v5; // rax
bool v6; // cc
__int64 v7; // rdi
unsigned __int64 *v8; // rax

if ( !a1 )
return make_error(3LL, a2, a3, a4);
v4 = (unsigned int)a1;
v5 = (_DWORD *)*a2;
if ( !*(_DWORD *)(*a2 + 8) )
{
v6 = a1 <= 1;
if ( a1 == 1 )
return make_int((unsigned int)-*v5);
v7 = (unsigned int)*v5;
if ( v6 )
return make_int(v7);
v8 = a2 + 1;
a4 = (__int64)&a2[(unsigned int)(v4 - 2) + 2];
while ( 1 )
{
v4 = *v8;
if ( *(_DWORD *)(*v8 + 8) )
break;
v7 = (unsigned int)(v7 - *(_DWORD *)v4);
if ( ++v8 == (unsigned __int64 *)a4 )
return make_int(v7);
}
}
return make_error(5LL, a2, v4, a4);
}

original_code:
struct LispObj *b_minus(int argc, struct LispObj *argv[], struct Env *env)
{
 if (argc == 0)
  return make_error(WRONG_ARGC);
 if (argv[0]->type != INT)
  return make_error(WRONG_TYPE);
 if (argc == 1)
  return make_int(-argv[0]->value.l_int);
 int result = argv[0]->value.l_int;
 for (int i = 1; i < argc; i++) {
  if (argv[i]->type != INT)
   return make_error(WRONG_TYPE);
  result -= argv[i]->value.l_int;
 }
 return make_int(result);
}


decompiled_code:
__int64 __fastcall b_multiply(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // rdi
_DWORD *v5; // rdx
__int64 result; // rax

if ( a1 <= 0 )
{
v4 = 1LL;
LABEL_5:
result = make_int(v4);
}
else
{
v2 = a2;
v3 = a2 + 8LL * (unsigned int)(a1 - 1) + 8;
LODWORD(v4) = 1;
while ( 1 )
{
v5 = *(_DWORD **)v2;
if ( *(_DWORD *)(*(_QWORD *)v2 + 8LL) )
break;
v4 = (unsigned int)(*v5 * v4);
v2 += 8LL;
if ( v2 == v3 )
goto LABEL_5;
}
result = make_error(5LL, a2, v5, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // rdi
_DWORD *v5; // rdx
__int64 result; // rax

if ( a1 <= 0 )
{
v4 = 1LL;
LABEL_5:
result = make_int(v4);
}
else
{
v2 = a2;
v3 = a2 + 8LL * (unsigned int)(a1 - 1) + 8;
LODWORD(v4) = 1;
while ( 1 )
{
v5 = *(_DWORD **)v2;
if ( *(_DWORD *)(*(_QWORD *)v2 + 8LL) )
break;
v4 = (unsigned int)(*v5 * v4);
v2 += 8LL;
if ( v2 == v3 )
goto LABEL_5;
}
result = make_error(5LL, a2, v5, v3);
}
return result;
}

original_code:
struct LispObj *b_multiply(int argc, struct LispObj *argv[], struct Env *env)
{
 int result = 1;
 for (int i = 0; i < argc; i++) {
  if (argv[i]->type != INT)
   return make_error(WRONG_TYPE);
  result *= argv[i]->value.l_int;
 }
 return make_int(result);
}


decompiled_code:
__int64 __fastcall b_cons(int a1, _QWORD *a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax

if ( a1 != 2 )
return make_error(3LL, a2, a3, a4);
v5 = cons(*a2, a2[1]);
return make_cons(v5);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, _QWORD *a2, __int64 a3, __int64 a4)
{
__int64 v5; // rax

if ( a1 != 2 )
return make_error(3LL, a2, a3, a4);
v5 = cons(*a2, a2[1]);
return make_cons(v5);
}

original_code:
struct LispObj *b_cons(int argc, struct LispObj *argv[], struct Env *env)
{
 if (argc != 2)
  return make_error(WRONG_ARGC);
 return make_cons(cons(argv[0], argv[1]));
}


decompiled_code:
__int64 __fastcall b_car(int a1, __int64 a2, __int64 a3, __int64 a4)
{
if ( a1 != 1 )
return make_error(3LL, a2, a3, a4);
if ( *(_DWORD *)(*(_QWORD *)a2 + 8LL) == 5 )
return car();
return make_error(5LL, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, __int64 a2, __int64 a3, __int64 a4)
{
if ( a1 != 1 )
return make_error(3LL, a2, a3, a4);
if ( *(_DWORD *)(*(_QWORD *)a2 + 8LL) == 5 )
return car();
return make_error(5LL, a2, a3, a4);
}

original_code:
struct LispObj *b_car(int argc, struct LispObj *argv[], struct Env *env)
{
 if (argc != 1)
  return make_error(WRONG_ARGC);
 if (argv[0]->type != CONS)
  return make_error(WRONG_TYPE);
 return car(argv[0]);
}


decompiled_code:
__int64 __fastcall b_cdr(int a1, __int64 a2, __int64 a3, __int64 a4)
{
if ( a1 != 1 )
return make_error(3LL, a2, a3, a4);
if ( *(_DWORD *)(*(_QWORD *)a2 + 8LL) == 5 )
return cdr();
return make_error(5LL, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, __int64 a2, __int64 a3, __int64 a4)
{
if ( a1 != 1 )
return make_error(3LL, a2, a3, a4);
if ( *(_DWORD *)(*(_QWORD *)a2 + 8LL) == 5 )
return cdr();
return make_error(5LL, a2, a3, a4);
}

original_code:
struct LispObj *b_cdr(int argc, struct LispObj *argv[], struct Env *env)
{
 if (argc != 1)
  return make_error(WRONG_ARGC);
 if (argv[0]->type != CONS)
  return make_error(WRONG_TYPE);
 return cdr(argv[0]);
}


decompiled_code:
__int64 __fastcall b_set(int a1, __int64 *a2, __int64 a3, __int64 a4)
{
__int64 v5; // rsi

if ( a1 != 2 )
return make_error(3LL, a2, a3, a4);
v5 = *a2;
if ( *(_DWORD *)(v5 + 8) != 4 )
return make_error(4LL, v5, a3, a4);
set(a3, v5, a2[1]);
return a2[1];
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, __int64 *a2, __int64 a3, __int64 a4)
{
__int64 v5; // rsi

if ( a1 != 2 )
return make_error(3LL, a2, a3, a4);
v5 = *a2;
if ( *(_DWORD *)(v5 + 8) != 4 )
return make_error(4LL, v5, a3, a4);
set(a3, v5, a2[1]);
return a2[1];
}

original_code:
struct LispObj *b_set(int argc, struct LispObj *argv[], struct Env *env)
{
 if (argc != 2)
  return make_error(WRONG_ARGC);
 if (argv[0]->type != SYMBOL)
  return make_error(NAME_NOT_A_SYMBOL);
 set(env, argv[0], argv[1]);
 return argv[1];
}


decompiled_code:
__int64 __fastcall b_def(int a1, _QWORD *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v7; // r12
__int64 v9; // rdx
__int64 v10; // rcx

if ( a1 != 2 )
return make_error(3LL, a2, a3, a4);
v4 = a3;
v5 = *a2;
if ( *(_DWORD *)(*a2 + 8LL) != 4 )
return make_error(4LL, a2, a3, a4);
v7 = a2[1];
if ( lookup(v5, a3) )
return make_error(6LL, a3, v9, v10);
extend_in_place(v4, v5, v7);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, _QWORD *a2, __int64 a3, __int64 a4)
{
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v7; // r12
__int64 v9; // rdx
__int64 v10; // rcx

if ( a1 != 2 )
return make_error(3LL, a2, a3, a4);
v4 = a3;
v5 = *a2;
if ( *(_DWORD *)(*a2 + 8LL) != 4 )
return make_error(4LL, a2, a3, a4);
v7 = a2[1];
if ( lookup(v5, a3) )
return make_error(6LL, a3, v9, v10);
extend_in_place(v4, v5, v7);
return v5;
}

original_code:
struct LispObj *b_def(int argc, struct LispObj *argv[], struct Env *env)
{
 if (argc != 2)
  return make_error(WRONG_ARGC);
 if (argv[0]->type != SYMBOL)
  return make_error(NAME_NOT_A_SYMBOL);
 LispObj *name_sym = argv[0];
 LispObj *value = argv[1];
 if (lookup(name_sym, env) != ((void *)0))
  return make_error(REDEFINITION);
 extend_in_place(env, name_sym, value);
 return name_sym;
}

canonical_original_code:
struct LispObj *b_def(int argc, struct LispObj *argv[], struct Env *env)
{
 if (argc != 2)
  return make_error(WRONG_ARGC);
 if (argv[0]->type != SYMBOL)
  return make_error(NAME_NOT_A_SYMBOL);
 struct LispObj *name_sym = argv[0];
 struct LispObj *value = argv[1];
 if (lookup(name_sym, env) != ((void *)0))
  return make_error(REDEFINITION);
 extend_in_place(env, name_sym, value);
 return name_sym;
}


decompiled_code:
__int64 get_init_env()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // rbx
__int64 v11; // rbp
__int64 v12; // rax

v0 = extend_func(0LL, &unk_33A, b_plus);
v1 = extend_func(v0, &unk_33C, b_minus);
v2 = extend_func(v1, &unk_33E, b_multiply);
v3 = extend_func(v2, "cons", b_cons);
v4 = extend_func(v3, "car", b_car);
v5 = extend_func(v4, "cdr", b_cdr);
v6 = extend_func(v5, "set", b_set);
v7 = extend_func(v6, "def", b_def);
v8 = make_bool(1LL);
v9 = make_symbol_cpy("t");
v10 = extend(v7, v9, v8);
v11 = make_bool(0LL);
v12 = make_symbol_cpy("f");
return extend(v10, v12, v11);
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // rbx
__int64 v11; // rbp
__int64 v12; // rax

v0 = extend_func(0LL, &unk_33A, b_plus);
v1 = extend_func(v0, &unk_33C, b_minus);
v2 = extend_func(v1, &unk_33E, b_multiply);
v3 = extend_func(v2, "cons", b_cons);
v4 = extend_func(v3, "car", b_car);
v5 = extend_func(v4, "cdr", b_cdr);
v6 = extend_func(v5, "set", b_set);
v7 = extend_func(v6, "def", b_def);
v8 = make_bool(1LL);
v9 = make_symbol_cpy("t");
v10 = extend(v7, v9, v8);
v11 = make_bool(0LL);
v12 = make_symbol_cpy("f");
return extend(v10, v12, v11);
}

original_code:
Env *get_init_env()
{
 Env *env = ((void *)0);
 env = extend_func(env, "+", b_plus);
 env = extend_func(env, "-", b_minus);
 env = extend_func(env, "*", b_multiply);
 env = extend_func(env, "cons", b_cons);
 env = extend_func(env, "car", b_car);
 env = extend_func(env, "cdr", b_cdr);
 env = extend_func(env, "set", b_set);
 env = extend_func(env, "def", b_def);
 env = extend(env, make_symbol_cpy("t"), make_bool(1));
 env = extend(env, make_symbol_cpy("f"), make_bool(0));
 return env;
}

canonical_original_code:
struct Env *get_init_env()
{
 struct Env *env = ((void *)0);
 env = extend_func(env, "+", b_plus);
 env = extend_func(env, "-", b_minus);
 env = extend_func(env, "*", b_multiply);
 env = extend_func(env, "cons", b_cons);
 env = extend_func(env, "car", b_car);
 env = extend_func(env, "cdr", b_cdr);
 env = extend_func(env, "set", b_set);
 env = extend_func(env, "def", b_def);
 env = extend(env, make_symbol_cpy("t"), make_bool(1));
 env = extend(env, make_symbol_cpy("f"), make_bool(0));
 return env;
}

return_type: struct Env { struct LispObj { union { int l_int; int l_bool; char l_char; char *l_string; char *l_symbol; struct Cons { struct LispObj *car; struct LispObj *cdr; } *l_cons; struct LispObj *(*l_function)(int argc, struct LispObj *argv[], struct Env *env); enum ErrorCode { UNMATCHED_CLOSE_PAREN=0, UNBOUND_VAR=1, NOT_A_FUNCTION=2, WRONG_ARGC=3, NAME_NOT_A_SYMBOL=4, WRONG_TYPE=5, REDEFINITION=6 } l_err; } value; enum LispType { INT=0, BOOL=1, CHAR=2, STRING=3, SYMBOL=4, CONS=5, NIL=6, FUNCTION=7, ERROR=8 } type; int refc; } *key; struct LispObj *value; struct Env *next; } *


original_code:
LispObj *eval_special_form(LispObj *sexpr, Env *env)
{
 if (car(sexpr)->type != SYMBOL)
  return ((void *)0);
 char *name = car(sexpr)->value.l_symbol;
 if (strcmp(name, "quote") == 0) {
  return cadr(sexpr);
 } else if (strcmp(name, "if") == 0) {
  LispObj *f = make_bool(0);
  LispObj *condition = eval(cadr(sexpr), env);
  LispObj *result_form;
  if (eq(f, condition))
   result_form = cadr(cddr(sexpr));
  else
   result_form = cadr(cdr(sexpr));
  free_lisp_obj(f);
  free_lisp_obj(condition);
  return eval(result_form, env);
 } else if (strcmp(name, "define") == 0) {
  if (cadr(sexpr)->type != SYMBOL)
   return make_error(NAME_NOT_A_SYMBOL);
  extend_in_place(env, cadr(sexpr), eval(car(cddr(sexpr)), env));
  return cadr(sexpr);
 }
 return ((void *)0);
}

canonical_original_code:
struct LispObj *eval_special_form(struct LispObj *sexpr, struct Env *env)
{
 if (car(sexpr)->type != SYMBOL)
  return ((void *)0);
 char *name = car(sexpr)->value.l_symbol;
 if (strcmp(name, "quote") == 0) {
  return cadr(sexpr);
 } else if (strcmp(name, "if") == 0) {
  struct LispObj *f = make_bool(0);
  struct LispObj *condition = eval(cadr(sexpr), env);
  struct LispObj *result_form;
  if (eq(f, condition))
   result_form = cadr(cddr(sexpr));
  else
   result_form = cadr(cdr(sexpr));
  free_lisp_obj(f);
  free_lisp_obj(condition);
  return eval(result_form, env);
 } else if (strcmp(name, "define") == 0) {
  if (cadr(sexpr)->type != SYMBOL)
   return make_error(NAME_NOT_A_SYMBOL);
  extend_in_place(env, cadr(sexpr), eval(car(cddr(sexpr)), env));
  return cadr(sexpr);
 }
 return ((void *)0);
}

variable_types:
sexpr
struct LispObj *

variable_types:
name
char *


eval

original_code:
LispObj *eval(LispObj *sexpr, Env *env)
{
 switch (sexpr->type) {
 case INT:
 case BOOL:
 case CHAR:
 case STRING:
 case FUNCTION:
 case NIL:
 case ERROR:
  return sexpr;
 case SYMBOL: {
  LispObj *value = lookup(sexpr, env);
  if (value == ((void *)0))
   return make_error(UNBOUND_VAR);
  else
   return value;
 }
 case CONS: {
  LispObj *result = eval_special_form(sexpr, env);
  if (result != ((void *)0))
   return result;
  LispObj *func = eval(car(sexpr), env);
  if (func->type == ERROR)
   return func;
  if (func->type != FUNCTION)
   return make_error(NOT_A_FUNCTION);
  int argc = 0;
  LispObj *s = sexpr;
  for (; cdr(s)->type != NIL; argc++)
   s = cdr(s);
  LispObj **args = malloc(sizeof(LispObj*) * argc);
  for (int i = 0; i < argc; i++) {
   sexpr = cdr(sexpr);
   LispObj *arg = eval(car(sexpr), env);
   if (arg->type == ERROR) {
    result = arg;
    argc = i - 1;
    goto cleanup;
   }
   args[i] = arg;
  }
  result = func->value.l_function(argc, args, env);
cleanup:
  add_ref(result);
  for (int i = 0; i < argc; i++)
   free_lisp_obj(args[i]);
  result->refc--;
  free(args);
  return result;
 }
 }
 return ((void *)0);
}

canonical_original_code:
struct LispObj *eval(struct LispObj *sexpr, struct Env *env)
{
 switch (sexpr->type) {
 case INT:
 case BOOL:
 case CHAR:
 case STRING:
 case FUNCTION:
 case NIL:
 case ERROR:
  return sexpr;
 case SYMBOL: {
  struct LispObj *value = lookup(sexpr, env);
  if (value == ((void *)0))
   return make_error(UNBOUND_VAR);
  else
   return value;
 }
 case CONS: {
  struct LispObj *result = eval_special_form(sexpr, env);
  if (result != ((void *)0))
   return result;
  struct LispObj *func = eval(car(sexpr), env);
  if (func->type == ERROR)
   return func;
  if (func->type != FUNCTION)
   return make_error(NOT_A_FUNCTION);
  int argc = 0;
  struct LispObj *s = sexpr;
  for (; cdr(s)->type != NIL; argc++)
   s = cdr(s);
  struct LispObj **args = malloc(sizeof(LispObj*) * argc);
  for (int i = 0; i < argc; i++) {
   sexpr = cdr(sexpr);
   struct LispObj *arg = eval(car(sexpr), env);
   if (arg->type == ERROR) {
    result = arg;
    argc = i - 1;
    goto cleanup;
   }
   args[i] = arg;
  }
  result = func->value.l_function(argc, args, env);
cleanup:
  add_ref(result);
  for (int i = 0; i < argc; i++)
   free_lisp_obj(args[i]);
  result->refc--;
  free(args);
  return result;
 }
 }
 return ((void *)0);
}

variable_types: struct LispObj { union { int l_int; int l_bool; char l_char; char *l_string; char *l_symbol; struct Cons { struct LispObj *car; struct LispObj *cdr; } *l_cons; struct LispObj *(*l_function)(int argc, struct LispObj *argv[], struct Env { struct LispObj *key; struct LispObj *value; struct Env *next; } *env); enum ErrorCode { UNMATCHED_CLOSE_PAREN=0, UNBOUND_VAR=1, NOT_A_FUNCTION=2, WRONG_ARGC=3, NAME_NOT_A_SYMBOL=4, WRONG_TYPE=5, REDEFINITION=6 } l_err; } value; enum LispType { INT=0, BOOL=1, CHAR=2, STRING=3, SYMBOL=4, CONS=5, NIL=6, FUNCTION=7, ERROR=8 } type; int refc; } **


decompiled_code:
void free_nil()
{
free(nil);
}

canonical_decompiled_code:
void func1()
{
free(nil);
}

original_code:
void free_nil()
{
 free(nil);
}

canonical_original_code:
void free_nil()
{
 free(nil);
}


decompiled_code:
char *get_token()
{
char *v0; // rbp
const char *v2; // r12
size_t v3; // rax

v0 = 0LL;
if ( (unsigned int)yylex() )
{
v2 = yytext;
v3 = strlen(yytext);
v0 = (char *)malloc(v3 + 1);
strcpy(v0, v2);
}
return v0;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rbp
const char *v2; // r12
size_t v3; // rax

v0 = 0LL;
if ( (unsigned int)yylex() )
{
v2 = yytext;
v3 = strlen(yytext);
v0 = (char *)malloc(v3 + 1);
strcpy(v0, v2);
}
return v0;
}

original_code:
Token get_token()
{
 char *str = ((void *)0);
 TokenType type = yylex();
 if (type != 0) {
  str = malloc(sizeof(char) * strlen(yytext) + 1);
  strcpy(str, yytext);
 }
 return (Token) {
  .str = str,
  .type = type
 };
}

canonical_original_code:
struct Token get_token()
{
 char *str = ((void *)0);
 enum TokenType type = yylex();
 if (type != 0) {
  str = malloc(sizeof(char) * strlen(yytext) + 1);
  strcpy(str, yytext);
 }
 return (struct Token) {
  .str = str,
  .type = type
 };
}

variable_types:
str
char *

return_type: struct Token { char *str; enum TokenType { T_OPEN_PAREN=1, T_CLOSE_PAREN=2, T_STRING=3, T_SYMBOL=4, T_INTEGER=5, T_CHAR=6 } type; }

user_defined_types: struct Token { char *str; enum TokenType type; }


decompiled_code:
size_t __fastcall print_error(int a1)
{
size_t result; // rax

result = fwrite("ERROR: ", 1uLL, 7uLL, stdout);
switch ( a1 )
{
case 0:
result = fwrite("Unmatched close parenthesis.", 1uLL, 0x1CuLL, stdout);
break;
case 1:
result = fwrite("Unbound variable.", 1uLL, 0x11uLL, stdout);
break;
case 2:
result = fwrite("Non-function found where a function was expected", 1uLL, 0x30uLL, stdout);
break;
case 3:
result = fwrite("Wrong number of arguments", 1uLL, 0x19uLL, stdout);
break;
case 4:
result = fwrite("Identifiers must be symbols", 1uLL, 0x1BuLL, stdout);
break;
case 5:
result = fwrite("Wrong type supplied to function", 1uLL, 0x1FuLL, stdout);
break;
case 6:
result = fwrite("Attempting to redefine name", 1uLL, 0x1BuLL, stdout);
break;
default:
return result;
}
return result;
}

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

result = fwrite("ERROR: ", 1uLL, 7uLL, stdout);
switch ( a1 )
{
case 0:
result = fwrite("Unmatched close parenthesis.", 1uLL, 0x1CuLL, stdout);
break;
case 1:
result = fwrite("Unbound variable.", 1uLL, 0x11uLL, stdout);
break;
case 2:
result = fwrite("Non-function found where a function was expected", 1uLL, 0x30uLL, stdout);
break;
case 3:
result = fwrite("Wrong number of arguments", 1uLL, 0x19uLL, stdout);
break;
case 4:
result = fwrite("Identifiers must be symbols", 1uLL, 0x1BuLL, stdout);
break;
case 5:
result = fwrite("Wrong type supplied to function", 1uLL, 0x1FuLL, stdout);
break;
case 6:
result = fwrite("Attempting to redefine name", 1uLL, 0x1BuLL, stdout);
break;
default:
return result;
}
return result;
}

original_code:
void print_error(ErrorCode err)
{
 fputs("ERROR: ", stdout);
 switch (err) {
 case UNMATCHED_CLOSE_PAREN:
  fputs("Unmatched close parenthesis.", stdout);
  break;
 case UNBOUND_VAR:
  fputs("Unbound variable.", stdout);
  break;
 case NOT_A_FUNCTION:
  fputs("Non-function found where a function was expected", stdout);
  break;
 case WRONG_ARGC:
  fputs("Wrong number of arguments", stdout);
  break;
 case NAME_NOT_A_SYMBOL:
  fputs("Identifiers must be symbols", stdout);
  break;
 case WRONG_TYPE:
  fputs("Wrong type supplied to function", stdout);
  break;
 case REDEFINITION:
  fputs("Attempting to redefine name", stdout);
  break;
 }
}

canonical_original_code:
void print_error(enum ErrorCode err)
{
 fputs("ERROR: ", stdout);
 switch (err) {
 case UNMATCHED_CLOSE_PAREN:
  fputs("Unmatched close parenthesis.", stdout);
  break;
 case UNBOUND_VAR:
  fputs("Unbound variable.", stdout);
  break;
 case NOT_A_FUNCTION:
  fputs("Non-function found where a function was expected", stdout);
  break;
 case WRONG_ARGC:
  fputs("Wrong number of arguments", stdout);
  break;
 case NAME_NOT_A_SYMBOL:
  fputs("Identifiers must be symbols", stdout);
  break;
 case WRONG_TYPE:
  fputs("Wrong type supplied to function", stdout);
  break;
 case REDEFINITION:
  fputs("Attempting to redefine name", stdout);
  break;
 }
}

variable_types: enum ErrorCode { UNMATCHED_CLOSE_PAREN=0, UNBOUND_VAR=1, NOT_A_FUNCTION=2, WRONG_ARGC=3, NAME_NOT_A_SYMBOL=4, WRONG_TYPE=5, REDEFINITION=6 }


repo: orodley/imgprint

decompiled_code:
__int64 __fastcall print_bmp(int fd)
{
unsigned __int16 v1; // r13
unsigned __int8 *v2; // rbp
__int64 v3; // r13
int v4; // er12
unsigned __int64 v5; // r14
__int64 v6; // rbx
__int64 result; // rax
unsigned int v8; // eax
char buf[10]; // [rsp+10h] [rbp-68h] BYREF
__off_t offset; // [rsp+1Ah] [rbp-5Eh]
unsigned int v11; // [rsp+22h] [rbp-56h]
int v12; // [rsp+26h] [rbp-52h]
unsigned __int16 v13; // [rsp+2Ch] [rbp-4Ch]
int v14; // [rsp+2Eh] [rbp-4Ah]
size_t size; // [rsp+32h] [rbp-46h]
int v16; // [rsp+3Eh] [rbp-3Ah]

if ( read(fd, buf, 0x36uLL) == -1 )
{
perror("error reading file");
result = 1LL;
}
else if ( v16 || (v1 = v13, v13 <= 7u) )
{
puts("Error: BMPs with color tables are currently unsupported");
result = 1LL;
}
else if ( (v13 & 7) != 0 )
{
puts("Error: BMPs with bpp indivisible by 8 are currently unsupported");
result = 1LL;
}
else if ( v14 )
{
puts("Error: compressed BMPs are currently unsupported");
result = 1LL;
}
else
{
v2 = (unsigned __int8 *)malloc((unsigned int)size);
lseek(fd, (unsigned int)offset, 0);
if ( read(fd, v2, (unsigned int)size) == -1 )
{
perror("error reading file");
free(v2);
result = 1LL;
}
else
{
v3 = v1 >> 3;
v4 = v12 - 1;
v5 = v3 * v11;
if ( (v5 & 3) != 0 )
v5 = ((v3 * v11) & 0xFFFFFFFFFFFFFFFCLL) + 4;
v6 = 0LL;
while ( v4 > 0 )
{
v8 = closest_color(((unsigned __int64)v2[v6 * v3 + 1 + v5 * v4] << 8) | v2[v6 * v3 + 2 + v5 * v4] | ((unsigned __int64)v2[v6 * v3 + v5 * v4] << 16));
print_pixel(v8);
if ( v11 == ++v6 )
{
putchar(10);
--v4;
v6 = 0LL;
}
}
free(v2);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd)
{
unsigned __int16 v1; // r13
unsigned __int8 *v2; // rbp
__int64 v3; // r13
int v4; // er12
unsigned __int64 v5; // r14
__int64 v6; // rbx
__int64 result; // rax
unsigned int v8; // eax
char buf[10]; // [rsp+10h] [rbp-68h] BYREF
__off_t offset; // [rsp+1Ah] [rbp-5Eh]
unsigned int v11; // [rsp+22h] [rbp-56h]
int v12; // [rsp+26h] [rbp-52h]
unsigned __int16 v13; // [rsp+2Ch] [rbp-4Ch]
int v14; // [rsp+2Eh] [rbp-4Ah]
size_t size; // [rsp+32h] [rbp-46h]
int v16; // [rsp+3Eh] [rbp-3Ah]

if ( read(fd, buf, 0x36uLL) == -1 )
{
perror("error reading file");
result = 1LL;
}
else if ( v16 || (v1 = v13, v13 <= 7u) )
{
puts("Error: BMPs with color tables are currently unsupported");
result = 1LL;
}
else if ( (v13 & 7) != 0 )
{
puts("Error: BMPs with bpp indivisible by 8 are currently unsupported");
result = 1LL;
}
else if ( v14 )
{
puts("Error: compressed BMPs are currently unsupported");
result = 1LL;
}
else
{
v2 = (unsigned __int8 *)malloc((unsigned int)size);
lseek(fd, (unsigned int)offset, 0);
if ( read(fd, v2, (unsigned int)size) == -1 )
{
perror("error reading file");
free(v2);
result = 1LL;
}
else
{
v3 = v1 >> 3;
v4 = v12 - 1;
v5 = v3 * v11;
if ( (v5 & 3) != 0 )
v5 = ((v3 * v11) & 0xFFFFFFFFFFFFFFFCLL) + 4;
v6 = 0LL;
while ( v4 > 0 )
{
v8 = func9(((unsigned __int64)v2[v6 * v3 + 1 + v5 * v4] << 8) | v2[v6 * v3 + 2 + v5 * v4] | ((unsigned __int64)v2[v6 * v3 + v5 * v4] << 16));
func8(v8);
if ( v11 == ++v6 )
{
putchar(10);
--v4;
v6 = 0LL;
}
}
free(v2);
result = 0LL;
}
}
return result;
}

original_code:
int print_bmp(int fd)
{
 char buf[sizeof(BMP_header)];
 ssize_t bytes = read(fd, buf, sizeof(BMP_header));
 if (bytes == -1) {
  perror("error reading file");
  return 1;
 }
 BMP_header *header = (BMP_header*)buf;
 if (header->num_colors != 0 || header->bits_per_pixel < 8) {
  puts("Error: BMPs with color tables are currently unsupported");
  return 1;
 }
 if (header->bits_per_pixel % 8 != 0) {
  puts("Error: BMPs with bpp indivisible by 8 are currently unsupported");
  return 1;
 }
 size_t bytes_per_pixel = header->bits_per_pixel / 8;
 if (header->compression_method != 0) {
  puts("Error: compressed BMPs are currently unsupported");
  return 1;
 }
 char *pixels = malloc(header->pixel_array_size);
 lseek(fd, header->pixels_offset, 0);
 bytes = read(fd, pixels, header->pixel_array_size);
 if (bytes == -1) {
  perror("error reading file");
  free(pixels);
  return 1;
 }
 size_t column = 0;
 int row = header->height - 1;
 size_t row_width = bytes_per_pixel * header->width;
 if (row_width % 4 != 0)
  row_width += 4 - (row_width % 4);
 while (row > 0) {
  size_t i = row * row_width + (column * bytes_per_pixel);
  uint8_t b = pixels[i];
  uint8_t g = pixels[i + 1];
  uint8_t r = pixels[i + 2];
  Color c = { r, g, b };
  print_pixel(closest_color(c));
  column++;
  if (column == header->width) {
   putchar('\n');
   row--;
   column = 0;
  }
 }
 free(pixels);
 return 0;
}

canonical_original_code:
int print_bmp(int fd)
{
 char buf[-1];
 long bytes = read(fd, buf, sizeof(BMP_header));
 if (bytes == -1) {
  perror("error reading file");
  return 1;
 }
 struct BMP_Header *header = (BMP_header*)buf;
 if (header->num_colors != 0 || header->bits_per_pixel < 8) {
  puts("Error: BMPs with color tables are currently unsupported");
  return 1;
 }
 if (header->bits_per_pixel % 8 != 0) {
  puts("Error: BMPs with bpp indivisible by 8 are currently unsupported");
  return 1;
 }
 unsigned long bytes_per_pixel = header->bits_per_pixel / 8;
 if (header->compression_method != 0) {
  puts("Error: compressed BMPs are currently unsupported");
  return 1;
 }
 char *pixels = malloc(header->pixel_array_size);
 lseek(fd, header->pixels_offset, 0);
 bytes = read(fd, pixels, header->pixel_array_size);
 if (bytes == -1) {
  perror("error reading file");
  free(pixels);
  return 1;
 }
 unsigned long column = 0;
 int row = header->height - 1;
 unsigned long row_width = bytes_per_pixel * header->width;
 if (row_width % 4 != 0)
  row_width += 4 - (row_width % 4);
 while (row > 0) {
  unsigned long i = row * row_width + (column * bytes_per_pixel);
  unsigned char b = pixels[i];
  unsigned char g = pixels[i + 1];
  unsigned char r = pixels[i + 2];
  struct Color c = { r, g, b };
  print_pixel(closest_color(c));
  column++;
  if (column == header->width) {
   putchar('\n');
   row--;
   column = 0;
  }
 }
 free(pixels);
 return 0;
}

variable_types: fd int

variable_types:
buf
char [-1]

variable_types: bytes long

variable_types: struct BMP_Header { unsigned short signature; unsigned int file_size; unsigned short reserved1; unsigned short reserved2; unsigned int pixels_offset; unsigned int header_size; unsigned int width; unsigned int height; unsigned short planes; unsigned short bits_per_pixel; unsigned int compression_method; unsigned int pixel_array_size; unsigned int horizontal_resolution; unsigned int vertical_resolution; unsigned int num_colors; unsigned int num_important_colors; } *

variable_types:
pixels
char *

variable_types:
column
unsigned long

variable_types: row int

variable_types:
i
unsigned long

variable_types:
b
unsigned char

variable_types:
g
unsigned char

variable_types:
r
unsigned char

variable_types: struct Color { unsigned char r; unsigned char g; unsigned char b; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // eax
int v5; // ebx
char buf[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( argc == 2 )
{
v4 = open(argv[1], 0, envp);
v5 = v4;
if ( v4 == -1 )
{
perror("error opening file");
result = 1;
}
else if ( read(v4, buf, 2uLL) == -1 )
{
perror("error reading file");
result = 1;
}
else
{
lseek(v5, 0LL, 0);
if ( (buf[1] | (buf[0] << 8)) == 16973 )
{
result = print_bmp(v5);
}
else
{
puts("Error: unrecognized file format");
result = 1;
}
}
}
else
{
printf("Usage: %s <filenname>\n", *argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // eax
int v5; // ebx
char buf[10]; // [rsp+Eh] [rbp-Ah] BYREF

if ( argc == 2 )
{
v4 = open(argv[1], 0, envp);
v5 = v4;
if ( v4 == -1 )
{
perror("error opening file");
result = 1;
}
else if ( read(v4, buf, 2uLL) == -1 )
{
perror("error reading file");
result = 1;
}
else
{
lseek(v5, 0LL, 0);
if ( (buf[1] | (buf[0] << 8)) == 16973 )
{
result = func7(v5);
}
else
{
puts("Error: unrecognized file format");
result = 1;
}
}
}
else
{
printf("Usage: %s <filenname>\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc != 2) {
  printf(usage, argv[0]);
  return 1;
 }
 int fd = open(argv[1], 00);
 if (fd == -1) {
  perror("error opening file");
  return 1;
 }
 char buf[2];
 ssize_t bytes = read(fd, buf, 2);
 if (bytes == -1) {
  perror("error reading file");
  return 1;
 }
 lseek(fd, 0, 0);
 switch (buf[0] << 8 | buf[1]) {
 case 0x424D:
  return print_bmp(fd);
 default:
  puts("Error: unrecognized file format");
  return 1;
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if (argc != 2) {
  printf(usage, argv[0]);
  return 1;
 }
 int fd = open(argv[1], 00);
 if (fd == -1) {
  perror("error opening file");
  return 1;
 }
 char buf[2];
 long bytes = read(fd, buf, 2);
 if (bytes == -1) {
  perror("error reading file");
  return 1;
 }
 lseek(fd, 0, 0);
 switch (buf[0] << 8 | buf[1]) {
 case 0x424D:
  return print_bmp(fd);
 default:
  puts("Error: unrecognized file format");
  return 1;
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buf
char [2]


decompiled_code:
size_t __fastcall print_pixel(int a1)
{
char v1; // di

switch ( a1 )
{
case 0:
v1 = 32;
break;
case 1:
fwrite("\x1B[31m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 2:
fwrite("\x1B[32m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 3:
fwrite("\x1B[33m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 4:
fwrite("\x1B[34m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 5:
fwrite("\x1B[35m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 6:
fwrite("\x1B[36m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 7:
fwrite("\x1B[37m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
default:
v1 = 35;
break;
}
putchar(v1);
return fwrite("\x1B[0m", 1uLL, 4uLL, _bss_start);
}

canonical_decompiled_code:
size_t __fastcall func8(int a1)
{
char v1; // di

switch ( a1 )
{
case 0:
v1 = 32;
break;
case 1:
fwrite("\x1B[31m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 2:
fwrite("\x1B[32m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 3:
fwrite("\x1B[33m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 4:
fwrite("\x1B[34m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 5:
fwrite("\x1B[35m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 6:
fwrite("\x1B[36m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
case 7:
fwrite("\x1B[37m", 1uLL, 5uLL, _bss_start);
v1 = 35;
break;
default:
v1 = 35;
break;
}
putchar(v1);
return fwrite("\x1B[0m", 1uLL, 4uLL, _bss_start);
}

original_code:
void print_pixel(Term_color col)
{
 char ch = '#';
 switch (col) {
 case BLACK: ch = ' '; break;
 case RED: fputs("\x1B[31m", stdout); break;
 case GREEN: fputs("\x1B[32m", stdout); break;
 case YELLOW: fputs("\x1B[33m", stdout); break;
 case BLUE: fputs("\x1B[34m", stdout); break;
 case MAGENTA: fputs("\x1B[35m", stdout); break;
 case CYAN: fputs("\x1B[36m", stdout); break;
 case WHITE: fputs("\x1B[37m", stdout); break;
 }
 putchar(ch);
 fputs("\x1B[0m", stdout);
}

canonical_original_code:
void print_pixel(enum Term_color col)
{
 char ch = '#';
 switch (col) {
 case BLACK: ch = ' '; break;
 case RED: fputs("\x1B[31m", stdout); break;
 case GREEN: fputs("\x1B[32m", stdout); break;
 case YELLOW: fputs("\x1B[33m", stdout); break;
 case BLUE: fputs("\x1B[34m", stdout); break;
 case MAGENTA: fputs("\x1B[35m", stdout); break;
 case CYAN: fputs("\x1B[36m", stdout); break;
 case WHITE: fputs("\x1B[37m", stdout); break;
 }
 putchar(ch);
 fputs("\x1B[0m", stdout);
}

variable_types: enum Term_color { BLACK=0, RED=1, GREEN=2, YELLOW=3, BLUE=4, MAGENTA=5, CYAN=6, WHITE=7 }

variable_types: ch char


decompiled_code:
__int64 __fastcall closest_color(int a1)
{
unsigned int v1; // er10
int v2; // er11
int v3; // ebx
int v4; // er9
unsigned __int8 *v5; // rdx
__int64 v6; // rdi
unsigned __int64 v7; // r8
int v8; // esi
int v9; // ecx

v2 = (unsigned __int8)a1;
v3 = BYTE1(a1);
v4 = BYTE2(a1);
v5 = (unsigned __int8 *)&colors;
v6 = 0LL;
v7 = -1LL;
do
{
v8 = (v3 - v5[1]) * (v3 - v5[1]);
v9 = (v4 - v5[2]) * (v4 - v5[2]);
if ( v9 + v8 + (v2 - *v5) * (v2 - (unsigned int)*v5) < v7 )
{
v1 = v6;
v7 = v9 + v8 + (v2 - *v5) * (v2 - (unsigned int)*v5);
}
++v6;
v5 += 3;
}
while ( v6 != 8 );
return v1;
}

original_code:
Term_color closest_color(Color c)
{
 Term_color closest;
 size_t min_diff = (size_t)-1;
 for (size_t i = 0; i < 8; i++) {
  Color c2 = colors[i];
  int dr = (int)(c.r - c2.r);
  int dg = (int)(c.g - c2.g);
  int db = (int)(c.b - c2.b);
  unsigned int diff = (dr * dr) + (dg * dg) + (db * db);
  if (diff < min_diff) {
   closest = (Term_color)i;
   min_diff = diff;
  }
 }
 return closest;
}

canonical_original_code:
enum Term_color closest_color(struct Color c)
{
 enum Term_color closest;
 unsigned long min_diff = (size_t)-1;
 for (unsigned long i = 0; i < 8; i++) {
  struct Color c2 = colors[i];
  int dr = (int)(c.r - c2.r);
  int dg = (int)(c.g - c2.g);
  int db = (int)(c.b - c2.b);
  unsigned int diff = (dr * dr) + (dg * dg) + (db * db);
  if (diff < min_diff) {
   closest = (enum Term_color)i;
   min_diff = diff;
  }
 }
 return closest;
}

variable_types: dr int

variable_types: dg int

variable_types: db int

variable_types:
diff
unsigned int

return_type: enum Term_color { BLACK=0, RED=1, GREEN=2, YELLOW=3, BLUE=4, MAGENTA=5, CYAN=6, WHITE=7 }

user_defined_types: struct Color { unsigned char r; unsigned char g; unsigned char b; }


repo: osandov/osh

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
size_t n; // [rsp+8h] [rbp-20h] BYREF
void *ptr; // [rsp+10h] [rbp-18h] BYREF
char *lineptr; // [rsp+18h] [rbp-10h] BYREF

lineptr = 0LL;
ptr = 0LL;
n = 0LL;
v7 = 0LL;
printf("%s", "$ ");
while ( getline(&lineptr, &n, stdin) != -1 )
{
v3 = tokenize(&ptr, &v7, lineptr);
if ( v3 != -1 )
{
v4 = parse(v3, ptr);
v5 = v4;
if ( v4 )
{
exec_cmdline(v4);
free_tree(v5);
}
}
printf("%s", "$ ");
}
putchar(10);
free(lineptr);
free(ptr);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    char *line = ((void *)0);
    struct Token *tokens = ((void *)0);
    size_t line_len = 0, tokens_len = 0;
    ssize_t line_read, tokens_read;
    printf("%s", "$ ");
    while ((line_read = getline(&line, &line_len, stdin)) != -1) {
        if ((tokens_read = tokenize(&tokens, &tokens_len, line)) != -1) {
            struct SyntaxTree *tree = ((void *)0);
            tree = parse(tokens_read, tokens);
            if (tree) {
                exec_cmdline(tree);
                free_tree(tree);
            }
        }
        printf("%s", "$ ");
    }
    printf("\n");
    free(line);
    free(tokens);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *line = ((void *)0);
    struct Token *tokens = ((void *)0);
    unsigned long line_len = 0; unsigned long tokens_len = 0;
    long line_read; long tokens_read;
    printf("%s", "$ ");
    while ((line_read = getline(&line, &line_len, stdin)) != -1) {
        if ((tokens_read = tokenize(&tokens, &tokens_len, line)) != -1) {
            struct SyntaxTree *tree = ((void *)0);
            tree = parse(tokens_read, tokens);
            if (tree) {
                exec_cmdline(tree);
                free_tree(tree);
            }
        }
        printf("%s", "$ ");
    }
    printf("\n");
    free(line);
    free(tokens);
    return 0;
}

variable_types:
argv
char **

variable_types:
line
char *

variable_types: struct SyntaxTree { enum NodeType { NODE_CMD=0, NODE_REDIR_IN=1, NODE_REDIR_OUT=2, NODE_REDIR_APPEND=3, NODE_PIPE=4, NODE_ERR_PIPE=5, NODE_AND=6, NODE_OR=7, NODE_SEMICOLON=8, NODE_BACKGROUND=9, NODE_DISOWN=10 } type; struct Token { _Bool special; union { char *token; long offset; }; } *tokens; unsigned long num_tokens; struct SyntaxTree *left; } *

user_defined_types: struct SyntaxTree { enum NodeType type; struct Token *tokens; unsigned long num_tokens; struct SyntaxTree *left; }


decompiled_code:
__int64 __fastcall exec_cmdline(_DWORD *a1)
{
__int64 result; // rax

switch ( *a1 )
{
case 0:
result = exec_cmd((__int64)a1);
break;
case 1:
result = exec_redir_in();
break;
case 2:
result = exec_redir_out(a1, 0LL);
break;
case 3:
result = exec_redir_out(a1, 1LL);
break;
case 4:
result = exec_pipe(a1, 0LL);
break;
case 5:
result = exec_pipe(a1, 1LL);
break;
case 6:
result = exec_and();
break;
case 7:
result = exec_or();
break;
case 8:
result = exec_semicolon();
break;
case 9:
result = exec_background();
break;
case 0xA:
_assert_fail("0", "cmdline.c", 0x5Du, "exec_cmdline");
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
__int64 result; // rax

switch ( *a1 )
{
case 0:
result = func0((__int64)a1);
break;
case 1:
result = func2();
break;
case 2:
result = func3(a1, 0LL);
break;
case 3:
result = func3(a1, 1LL);
break;
case 4:
result = func4(a1, 0LL);
break;
case 5:
result = func4(a1, 1LL);
break;
case 6:
result = func5();
break;
case 7:
result = func6();
break;
case 8:
result = func7();
break;
case 9:
result = func8();
break;
case 0xA:
_assert_fail("0", "cmdline.c", 0x5Du, "exec_cmdline");
default:
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
int exec_cmdline(struct SyntaxTree *root)
{
    switch (root->type) {
        case NODE_CMD:
            return exec_cmd(root);
        case NODE_REDIR_IN:
            return exec_redir_in(root);
        case NODE_REDIR_OUT:
            return exec_redir_out(root, 0);
        case NODE_REDIR_APPEND:
            return exec_redir_out(root, 1);
        case NODE_PIPE:
            return exec_pipe(root, 0);
        case NODE_ERR_PIPE:
            return exec_pipe(root, 1);
        case NODE_AND:
            return exec_and(root);
        case NODE_OR:
            return exec_or(root);
        case NODE_SEMICOLON:
            return exec_semicolon(root);
        case NODE_BACKGROUND:
            return exec_background(root);
        case NODE_DISOWN:
            ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "cmdline.c", 93, __extension__ __PRETTY_FUNCTION__); }));
    }
    return -1;
}

user_defined_types: enum NodeType { NODE_CMD=0, NODE_REDIR_IN=1, NODE_REDIR_OUT=2, NODE_REDIR_APPEND=3, NODE_PIPE=4, NODE_ERR_PIPE=5, NODE_AND=6, NODE_OR=7, NODE_SEMICOLON=8, NODE_BACKGROUND=9, NODE_DISOWN=10 }

user_defined_types: struct Token { _Bool special; union { char *token; long offset; }; }


decompiled_code:
__int64 __fastcall exec_redir_in(__int64 a1)
{
int v1; // eax
int v2; // er12
__pid_t v3; // eax
__pid_t v4; // ebx
__int64 result; // rax
int *v6; // rbx
int *v7; // rax
int *v8; // rax
int v9; // eax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = open(*(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL) + 8LL), 0);
if ( v1 == -1 )
{
v6 = _errno_location();
error(0, *v6, "error");
result = (unsigned int)*v6;
}
else
{
v2 = v1;
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
v7 = _errno_location();
error(*v7, *v7, "error");
}
else if ( !v3 )
{
dup2(v2, 0);
v9 = exec_cmdline(*(_DWORD **)(a1 + 24));
exit(v9);
}
if ( waitpid(v4, &stat_loc, 0) == -1 )
{
v8 = _errno_location();
error(*v8, *v8, "error");
}
result = BYTE1(stat_loc);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // eax
int v2; // er12
__pid_t v3; // eax
__pid_t v4; // ebx
__int64 result; // rax
int *v6; // rbx
int *v7; // rax
int *v8; // rax
int v9; // eax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = open(*(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL) + 8LL), 0);
if ( v1 == -1 )
{
v6 = _errno_location();
error(0, *v6, "error");
result = (unsigned int)*v6;
}
else
{
v2 = v1;
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
v7 = _errno_location();
error(*v7, *v7, "error");
}
else if ( !v3 )
{
dup2(v2, 0);
v9 = func1(*(_DWORD **)(a1 + 24));
exit(v9);
}
if ( waitpid(v4, &stat_loc, 0) == -1 )
{
v8 = _errno_location();
error(*v8, *v8, "error");
}
result = BYTE1(stat_loc);
}
return result;
}

original_code:
static int exec_redir_in(struct SyntaxTree *root)
{
    int fd;
    pid_t pid;
    if ((fd = open(root->right->tokens[0].token, 00)) == -1) {
        error(0, (*__errno_location ()), "error");
        return (*__errno_location ());
    }
    if ((pid = fork()) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if (pid) {
        int status;
        if (waitpid(pid, &status, 0) == -1)
            error((*__errno_location ()), (*__errno_location ()), "error");
        return (((status) & 0xff00) >> 8);
    } else {
        dup2(fd, 0);
        exit(exec_cmdline(root->left));
    }
}

canonical_original_code:
static int exec_redir_in(struct SyntaxTree *root)
{
    int fd;
    int pid;
    if ((fd = open(root->right->tokens[0].token, 00)) == -1) {
        error(0, (*__errno_location ()), "error");
        return (*__errno_location ());
    }
    if ((pid = fork()) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if (pid) {
        int status;
        if (waitpid(pid, &status, 0) == -1)
            error((*__errno_location ()), (*__errno_location ()), "error");
        return (((status) & 0xff00) >> 8);
    } else {
        dup2(fd, 0);
        exit(exec_cmdline(root->left));
    }
}

variable_types: fd int

variable_types: pid int

variable_types: status int


decompiled_code:
__int64 __fastcall exec_redir_out(__int64 a1, char a2)
{
int v2; // eax
int v3; // er12
__pid_t v4; // eax
__pid_t v5; // ebx
__int64 result; // rax
int *v7; // rbx
int *v8; // rax
int *v9; // rax
int v10; // eax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = open(*(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL) + 8LL), a2 == 0 ? 577 : 1089, 436LL);
if ( v2 == -1 )
{
v7 = _errno_location();
error(0, *v7, "error");
result = (unsigned int)*v7;
}
else
{
v3 = v2;
v4 = fork();
v5 = v4;
if ( v4 == -1 )
{
v8 = _errno_location();
error(*v8, *v8, "error");
}
else if ( !v4 )
{
dup2(v3, 1);
v10 = exec_cmdline(*(_DWORD **)(a1 + 24));
exit(v10);
}
if ( waitpid(v5, &stat_loc, 0) == -1 )
{
v9 = _errno_location();
error(*v9, *v9, "error");
}
result = BYTE1(stat_loc);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char a2)
{
int v2; // eax
int v3; // er12
__pid_t v4; // eax
__pid_t v5; // ebx
__int64 result; // rax
int *v7; // rbx
int *v8; // rax
int *v9; // rax
int v10; // eax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = open(*(const char **)(*(_QWORD *)(*(_QWORD *)(a1 + 32) + 8LL) + 8LL), a2 == 0 ? 577 : 1089, 436LL);
if ( v2 == -1 )
{
v7 = _errno_location();
error(0, *v7, "error");
result = (unsigned int)*v7;
}
else
{
v3 = v2;
v4 = fork();
v5 = v4;
if ( v4 == -1 )
{
v8 = _errno_location();
error(*v8, *v8, "error");
}
else if ( !v4 )
{
dup2(v3, 1);
v10 = func1(*(_DWORD **)(a1 + 24));
exit(v10);
}
if ( waitpid(v5, &stat_loc, 0) == -1 )
{
v9 = _errno_location();
error(*v9, *v9, "error");
}
result = BYTE1(stat_loc);
}
return result;
}

original_code:
static int exec_redir_out(struct SyntaxTree *root, _Bool append)
{
    int fd, flags = 01 | 0100 | (append ? 02000 : 01000);
    int mode = 0400 | 0200 | (0400 >> 3) | (0200 >> 3) | ((0400 >> 3) >> 3);
    pid_t pid;
    if ((fd = open(root->right->tokens[0].token, flags, mode)) == -1) {
        error(0, (*__errno_location ()), "error");
        return (*__errno_location ());
    }
    if ((pid = fork()) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if (pid) {
        int status;
        if (waitpid(pid, &status, 0) == -1)
            error((*__errno_location ()), (*__errno_location ()), "error");
        return (((status) & 0xff00) >> 8);
    } else {
        dup2(fd, 1);
        exit(exec_cmdline(root->left));
    }
}

canonical_original_code:
static int exec_redir_out(struct SyntaxTree *root, _Bool append)
{
    int fd; int flags = 01 | 0100 | (append ? 02000 : 01000);
    int mode = 0400 | 0200 | (0400 >> 3) | (0200 >> 3) | ((0400 >> 3) >> 3);
    int pid;
    if ((fd = open(root->right->tokens[0].token, flags, mode)) == -1) {
        error(0, (*__errno_location ()), "error");
        return (*__errno_location ());
    }
    if ((pid = fork()) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if (pid) {
        int status;
        if (waitpid(pid, &status, 0) == -1)
            error((*__errno_location ()), (*__errno_location ()), "error");
        return (((status) & 0xff00) >> 8);
    } else {
        dup2(fd, 1);
        exit(exec_cmdline(root->left));
    }
}

variable_types: flags int

variable_types: mode int


decompiled_code:
__int64 __fastcall exec_pipe(__int64 a1, char a2)
{
unsigned int v2; // er14
__pid_t v3; // eax
__pid_t v4; // ebx
__pid_t v5; // eax
__pid_t v6; // er12
char v7; // r13
char v8; // bp
int *v9; // rax
int *v10; // rax
int *v11; // rax
int v12; // eax
int v13; // eax
__pid_t v14; // eax
__WAIT_STATUS stat_loc; // [rsp+4h] [rbp-34h] BYREF
int v17; // [rsp+Ch] [rbp-2Ch]

if ( pipe((int *)&stat_loc.__iptr + 1) == -1 )
{
v9 = _errno_location();
error(*v9, *v9, "error");
}
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
v10 = _errno_location();
error(*v10, *v10, "error");
}
else if ( !v3 )
{
if ( a2 )
dup2(v17, 2);
else
dup2(v17, 1);
close(SHIDWORD(stat_loc.__iptr));
v13 = exec_cmdline(*(_DWORD **)(a1 + 24));
exit(v13);
}
v5 = fork();
v6 = v5;
if ( v5 == -1 )
{
v11 = _errno_location();
error(*v11, *v11, "error");
}
else if ( !v5 )
{
dup2(SHIDWORD(stat_loc.__iptr), 0);
close(v17);
v12 = exec_cmdline(*(_DWORD **)(a1 + 32));
exit(v12);
}
close(SHIDWORD(stat_loc.__iptr));
close(v17);
v7 = 0;
v8 = 0;
do
{
do
{
while ( 1 )
{
v14 = wait((__WAIT_STATUS)&stat_loc);
if ( v4 == v14 )
{
v8 = 1;
goto LABEL_18;
}
if ( v6 != v14 )
break;
v2 = BYTE1(stat_loc.__uptr);
if ( v8 )
return v2;
v7 = 1;
}
}
while ( !v8 );
LABEL_18:
;
}
while ( !v7 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
unsigned int v2; // er14
__pid_t v3; // eax
__pid_t v4; // ebx
__pid_t v5; // eax
__pid_t v6; // er12
char v7; // r13
char v8; // bp
int *v9; // rax
int *v10; // rax
int *v11; // rax
int v12; // eax
int v13; // eax
__pid_t v14; // eax
__WAIT_STATUS stat_loc; // [rsp+4h] [rbp-34h] BYREF
int v17; // [rsp+Ch] [rbp-2Ch]

if ( pipe((int *)&stat_loc.__iptr + 1) == -1 )
{
v9 = _errno_location();
error(*v9, *v9, "error");
}
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
v10 = _errno_location();
error(*v10, *v10, "error");
}
else if ( !v3 )
{
if ( a2 )
dup2(v17, 2);
else
dup2(v17, 1);
close(SHIDWORD(stat_loc.__iptr));
v13 = func1(*(_DWORD **)(a1 + 24));
exit(v13);
}
v5 = fork();
v6 = v5;
if ( v5 == -1 )
{
v11 = _errno_location();
error(*v11, *v11, "error");
}
else if ( !v5 )
{
dup2(SHIDWORD(stat_loc.__iptr), 0);
close(v17);
v12 = func1(*(_DWORD **)(a1 + 32));
exit(v12);
}
close(SHIDWORD(stat_loc.__iptr));
close(v17);
v7 = 0;
v8 = 0;
do
{
do
{
while ( 1 )
{
v14 = wait((__WAIT_STATUS)&stat_loc);
if ( v4 == v14 )
{
v8 = 1;
goto LABEL_18;
}
if ( v6 != v14 )
break;
v2 = BYTE1(stat_loc.__uptr);
if ( v8 )
return v2;
v7 = 1;
}
}
while ( !v8 );
LABEL_18:
;
}
while ( !v7 );
return v2;
}

original_code:
static int exec_pipe(struct SyntaxTree *root, _Bool err_pipe)
{
    int pipefd[2];
    pid_t pid1, pid2;
    if (pipe(pipefd) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if ((pid1 = fork()) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if (pid1) {
        if ((pid2 = fork()) == -1)
            error((*__errno_location ()), (*__errno_location ()), "error");
        if (pid2) {
            close(pipefd[0]);
            close(pipefd[1]);
        } else {
            dup2(pipefd[0], 0);
            close(pipefd[1]);
            exit(exec_cmdline(root->right));
        }
    } else {
        if (err_pipe)
            dup2(pipefd[1], 2);
        else
            dup2(pipefd[1], 1);
        close(pipefd[0]);
        exit(exec_cmdline(root->left));
    }
    _Bool done[2] = {0, 0};
    int retval;
    while (!done[0] || !done[1]) {
        int status;
        pid_t pid = wait(&status);
        if (pid == pid1)
            done[0] = 1;
        else if (pid == pid2) {
            done[1] = 1;
            retval = (((status) & 0xff00) >> 8);
        }
    }
    return retval;
}

canonical_original_code:
static int exec_pipe(struct SyntaxTree *root, _Bool err_pipe)
{
    int pipefd[2];
    int pid1; int pid2;
    if (pipe(pipefd) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if ((pid1 = fork()) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if (pid1) {
        if ((pid2 = fork()) == -1)
            error((*__errno_location ()), (*__errno_location ()), "error");
        if (pid2) {
            close(pipefd[0]);
            close(pipefd[1]);
        } else {
            dup2(pipefd[0], 0);
            close(pipefd[1]);
            exit(exec_cmdline(root->right));
        }
    } else {
        if (err_pipe)
            dup2(pipefd[1], 2);
        else
            dup2(pipefd[1], 1);
        close(pipefd[0]);
        exit(exec_cmdline(root->left));
    }
    _Bool done[2] = {0, 0};
    int retval;
    while (!done[0] || !done[1]) {
        int status;
        int pid = wait(&status);
        if (pid == pid1)
            done[0] = 1;
        else if (pid == pid2) {
            done[1] = 1;
            retval = (((status) & 0xff00) >> 8);
        }
    }
    return retval;
}

variable_types:
pipefd
int [2]

variable_types:
done
_Bool [2]

variable_types: retval int


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

result = exec_cmdline(*(_DWORD **)(a1 + 24));
if ( !(_DWORD)result )
result = exec_cmdline(*(_DWORD **)(a1 + 32));
return result;
}

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

result = func1(*(_DWORD **)(a1 + 24));
if ( !(_DWORD)result )
result = func1(*(_DWORD **)(a1 + 32));
return result;
}

original_code:
static int exec_and(struct SyntaxTree *root)
{
    int retval = exec_cmdline(root->left);
    if (retval == 0)
        retval = exec_cmdline(root->right);
    return retval;
}


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

result = exec_cmdline(*(_DWORD **)(a1 + 24));
if ( (_DWORD)result )
result = exec_cmdline(*(_DWORD **)(a1 + 32));
return result;
}

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

result = func1(*(_DWORD **)(a1 + 24));
if ( (_DWORD)result )
result = func1(*(_DWORD **)(a1 + 32));
return result;
}

original_code:
static int exec_or(struct SyntaxTree *root)
{
    int retval = exec_cmdline(root->left);
    if (retval != 0)
        retval = exec_cmdline(root->right);
    return retval;
}


decompiled_code:
__int64 __fastcall exec_semicolon(__int64 a1)
{
_DWORD *v2; // rdi
__int64 result; // rax
_DWORD *v4; // rdi

v2 = *(_DWORD **)(a1 + 24);
result = 0LL;
if ( v2 )
result = exec_cmdline(v2);
v4 = *(_DWORD **)(a1 + 32);
if ( v4 )
result = exec_cmdline(v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
_DWORD *v2; // rdi
__int64 result; // rax
_DWORD *v4; // rdi

v2 = *(_DWORD **)(a1 + 24);
result = 0LL;
if ( v2 )
result = func1(v2);
v4 = *(_DWORD **)(a1 + 32);
if ( v4 )
result = func1(v4);
return result;
}

original_code:
static int exec_semicolon(struct SyntaxTree *root)
{
    int retval = 0;
    if (root->left)
        retval = exec_cmdline(root->left);
    if (root->right)
        retval = exec_cmdline(root->right);
    return retval;
}


decompiled_code:
__int64 __fastcall exec_background(__int64 a1)
{
__pid_t v1; // eax
_DWORD *v2; // rdi
__int64 result; // rax
int *v4; // rax
int v5; // eax

v1 = fork();
if ( v1 == -1 )
{
v4 = _errno_location();
error(*v4, *v4, "error");
}
else if ( !v1 )
{
v5 = exec_cmdline(*(_DWORD **)(a1 + 24));
exit(v5);
}
v2 = *(_DWORD **)(a1 + 32);
result = 0LL;
if ( v2 )
result = exec_cmdline(v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
__pid_t v1; // eax
_DWORD *v2; // rdi
__int64 result; // rax
int *v4; // rax
int v5; // eax

v1 = fork();
if ( v1 == -1 )
{
v4 = _errno_location();
error(*v4, *v4, "error");
}
else if ( !v1 )
{
v5 = func1(*(_DWORD **)(a1 + 24));
exit(v5);
}
v2 = *(_DWORD **)(a1 + 32);
result = 0LL;
if ( v2 )
result = func1(v2);
return result;
}

original_code:
static int exec_background(struct SyntaxTree *root)
{
    int retval = 0;
    pid_t pid;
    if ((pid = fork()) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if (pid) {
        if (root->right)
            retval = exec_cmdline(root->right);
    } else
        exit(exec_cmdline(root->left));
    return retval;
}

canonical_original_code:
static int exec_background(struct SyntaxTree *root)
{
    int retval = 0;
    int pid;
    if ((pid = fork()) == -1)
        error((*__errno_location ()), (*__errno_location ()), "error");
    if (pid) {
        if (root->right)
            retval = exec_cmdline(root->right);
    } else
        exit(exec_cmdline(root->left));
    return retval;
}


decompiled_code:
__int64 __fastcall need_split(char a1, char a2)
{
const unsigned __int16 *v2; // rdx
__int64 result; // rax
char **v4; // rax

v2 = *_ctype_b_loc();
result = 0LL;
if ( (v2[a2] & 0x2000) == 0 )
{
v4 = special_strings;
do
{
if ( **v4 == a2 && (*v4)[1] == a1 )
return 0LL;
++v4;
}
while ( v4 != (char **)&unk_638 );
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, char a2)
{
const unsigned __int16 *v2; // rdx
__int64 result; // rax
char **v4; // rax

v2 = *_ctype_b_loc();
result = 0LL;
if ( (v2[a2] & 0x2000) == 0 )
{
v4 = special_strings;
do
{
if ( **v4 == a2 && (*v4)[1] == a1 )
return 0LL;
++v4;
}
while ( v4 != (char **)&unk_638 );
result = 1LL;
}
return result;
}

original_code:
static inline _Bool need_split(char curr, char prev)
{
    if (((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short int) _ISspace))
        return 0;
    else {
        for (int i = 0; i < sizeof(special_strings) / sizeof(*special_strings);
                ++i) {
            if (prev == special_strings[i][0] && curr == special_strings[i][1])
                return 0;
        }
    }
    return 1;
}

canonical_original_code:
static inline _Bool need_split(char curr, char prev)
{
    if (((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short) _ISspace))
        return 0;
    else {
        for (int i = 0; i < sizeof(special_strings) / sizeof(*special_strings);
                ++i) {
            if (prev == special_strings[i][0] && curr == special_strings[i][1])
                return 0;
        }
    }
    return 1;
}

variable_types: curr char

variable_types: prev char

variable_types: i int


decompiled_code:
void *__fastcall add_token(void **a1, __int64 *a2, unsigned __int64 a3, __int64 a4, char a5)
{
__int64 v8; // rbx
void *result; // rax
__int64 v10; // rax
void *v11; // rax
int *v12; // rax

if ( *a2 > a3 )
goto LABEL_2;
v10 = 2 * *a2 + 1;
*a2 = v10;
v11 = realloc(*a1, 16 * v10);
if ( v11 )
{
*a1 = v11;
LABEL_2:
v8 = 16 * a3;
*(_QWORD *)((char *)*a1 + v8 + 8) = a4;
result = *a1;
*((_BYTE *)*a1 + v8) = a5;
return result;
}
v12 = _errno_location();
error(1, *v12, "fatal error");
return (void *)write_char();
}

canonical_decompiled_code:
void *__fastcall func2(void **a1, __int64 *a2, unsigned __int64 a3, __int64 a4, char a5)
{
__int64 v8; // rbx
void *result; // rax
__int64 v10; // rax
void *v11; // rax
int *v12; // rax

if ( *a2 > a3 )
goto LABEL_2;
v10 = 2 * *a2 + 1;
*a2 = v10;
v11 = realloc(*a1, 16 * v10);
if ( v11 )
{
*a1 = v11;
LABEL_2:
v8 = 16 * a3;
*(_QWORD *)((char *)*a1 + v8 + 8) = a4;
result = *a1;
*((_BYTE *)*a1 + v8) = a5;
return result;
}
v12 = _errno_location();
error(1, *v12, "fatal error");
return (void *)write_char();
}

original_code:
static void add_token(struct Token **tokens, size_t *n, size_t i,
                      ptrdiff_t offset, _Bool special)
{
    if (i >= *n) {
        struct Token *new_tokens;
        *n = 2 * *n + 1;
        if (!(new_tokens = realloc(*tokens, *n * sizeof((*tokens)[0]))))
            error(1, (*__errno_location ()), "fatal error");
        *tokens = new_tokens;
    }
    (*tokens)[i].offset = offset;
    (*tokens)[i].special = special;
}

canonical_original_code:
static void add_token(struct Token **tokens, unsigned long *n, unsigned long i, long offset, _Bool special)
{
    if (i >= *n) {
        struct Token *new_tokens;
        *n = 2 * *n + 1;
        if (!(new_tokens = realloc(*tokens, *n * sizeof((*tokens)[0]))))
            error(1, (*__errno_location ()), "fatal error");
        *tokens = new_tokens;
    }
    (*tokens)[i].offset = offset;
    (*tokens)[i].special = special;
}

variable_types: struct Token { _Bool special; union { char *token; long offset; }; } **

variable_types:
n
unsigned long *

variable_types:
i
unsigned long

variable_types: offset long


tokenize

decompiled_code:
__int64 __fastcall tokenize(void **a1, __int64 *a2, char *a3)
{
char v3; // bl
__int64 v4; // r12
char v5; // r14
bool v7; // r13
char v8; // r15
int *v9; // rax
const unsigned __int16 *v10; // rax
__int64 v11; // rcx
__int64 i; // rdx
bool v14; // [rsp+1Dh] [rbp-4Bh]
unsigned __int8 v15; // [rsp+1Eh] [rbp-4Ah]
__int64 v16[8]; // [rsp+28h] [rbp-40h] BYREF

if ( !buffer_1 )
{
buffer_1 = (__int64)malloc(0x100uLL);
if ( !buffer_1 )
{
v9 = _errno_location();
error(1, *v9, "fatal error");
LABEL_6:
add_token(a1, a2, v4++, v16[0] - buffer_1, 0);
LABEL_16:
if ( v3 == v5 )
{
v7 = 1;
v5 = 0;
}
else
{
write_char((void **)&buffer_1, &buffer_len_0, v16, v3);
v7 = 1;
}
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
++a3;
v8 = v3;
if ( !*a3 )
{
if ( v5 )
{
error(0, 0, "error: Unclosed quote");
v4 = -1LL;
}
else if ( v4 > 0 )
{
v11 = buffer_1;
for ( i = 0LL; i != v4; ++i )
*((_QWORD *)*a1 + 2 * i + 1) += v11;
}
return v4;
}
v3 = *a3;
LABEL_14:
if ( v5 )
{
if ( !v7 )
goto LABEL_6;
goto LABEL_16;
}
if ( !v14 )
break;
if ( !v7 )
add_token(a1, a2, v4++, v16[0] - buffer_1, 0);
write_char((void **)&buffer_1, &buffer_len_0, v16, v3);
v7 = v14;
v14 = 0;
}
v15 = isspecial(v8);
if ( v15 && !(unsigned __int8)isspecial(v3) )
{
write_char((void **)&buffer_1, &buffer_len_0, v16, 0);
v7 = 0;
}
v10 = *_ctype_b_loc();
if ( (v10[v3] & 0x2000) == 0 )
break;
if ( !(v15 | ((v10[v8] & 0x2000) != 0)) )
{
write_char((void **)&buffer_1, &buffer_len_0, v16, 0);
v14 = 0;
v7 = 0;
}
}
if ( (unsigned __int8)isspecial(v3) )
break;
if ( v3 == 39 || v3 == 34 )
{
v14 = 0;
v5 = v3;
}
else
{
if ( !v7 )
add_token(a1, a2, v4++, v16[0] - buffer_1, 0);
LABEL_29:
v7 = 1;
v14 = v3 == 92;
if ( v3 != 92 )
write_char((void **)&buffer_1, &buffer_len_0, v16, v3);
}
}
if ( (unsigned __int8)need_split(v3, v8) )
{
write_char((void **)&buffer_1, &buffer_len_0, v16, 0);
}
else if ( v7 )
{
goto LABEL_28;
}
add_token(a1, a2, v4++, v16[0] - buffer_1, 1);
LABEL_28:
v7 = v3 == 39 || v3 == 34;
if ( !v7 )
goto LABEL_29;
v5 = v3;
}
}
}
v16[0] = buffer_1;
v3 = *a3;
if ( *a3 )
{
v14 = 0;
v7 = 0;
v4 = 0LL;
v5 = 0;
v8 = 32;
goto LABEL_14;
}
return 0LL;
}

original_code:
ssize_t tokenize(struct Token **tokens, size_t *n, char *line)
{
    static char *buffer = ((void *)0);
    static size_t buffer_len = 256;
    if (!buffer) {
        buffer = malloc(256 * sizeof(char));
        if (!buffer)
            error(1, (*__errno_location ()), "fatal error");
    }
    char *head = buffer;
    char prev = ' ', quote = '\0';
    ssize_t i = 0;
    _Bool in_token = 0, escape = 0;
    for (char *p = line; *p; ++p) {
        char c = *p;
        if (quote) {
            if (!in_token)
                do { add_token(tokens, n, i++, head - buffer, (0)); in_token = 1; } while(0);
            if (c == quote)
                quote = '\0';
            else
                write_char(&buffer, &buffer_len, &head, (c));
        } else if (escape) {
            if (!in_token)
                do { add_token(tokens, n, i++, head - buffer, (0)); in_token = 1; } while(0);
            write_char(&buffer, &buffer_len, &head, (c));
            escape = 0;
        } else {
            if (isspecial(prev) && !isspecial(c))
                do { write_char(&buffer, &buffer_len, &head, '\0'); in_token = 0; } while(0);
            if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISspace)) {
                if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short int) _ISspace) && !isspecial(prev))
                    do { write_char(&buffer, &buffer_len, &head, '\0'); in_token = 0; } while(0);
            } else {
                if (isspecial(c)) {
                    if (need_split(c, prev))
                        do { write_char(&buffer, &buffer_len, &head, '\0'); in_token = 0; } while(0);
                    if (!in_token)
                        do { add_token(tokens, n, i++, head - buffer, (1)); in_token = 1; } while(0);
                }
                if (c == '\'' || c == '"')
                    quote = c;
                else {
                    if (!in_token)
                        do { add_token(tokens, n, i++, head - buffer, (0)); in_token = 1; } while(0);
                    escape = c == '\\';
                    if (!escape)
                        write_char(&buffer, &buffer_len, &head, (c));
                }
            }
        }
        prev = c;
    }
    if (quote) {
        error(0, 0, "error: Unclosed quote");
        return -1;
    }
    for (ssize_t j = 0; j < i; ++j)
        (*tokens)[j].token = buffer + (*tokens)[j].offset;
    return i;
}

canonical_original_code:
long tokenize(struct Token **tokens, unsigned long *n, char *line)
{
    static char *buffer = ((void *)0);
    static unsigned long buffer_len = 256;
    if (!buffer) {
        buffer = malloc(256 * sizeof(char));
        if (!buffer)
            error(1, (*__errno_location ()), "fatal error");
    }
    char *head = buffer;
    char prev = ' '; char quote = '\0';
    long i = 0;
    _Bool in_token = 0; _Bool escape = 0;
    for (char *p = line; *p; ++p) {
        char c = *p;
        if (quote) {
            if (!in_token)
                do { add_token(tokens, n, i++, head - buffer, (0)); in_token = 1; } while(0);
            if (c == quote)
                quote = '\0';
            else
                write_char(&buffer, &buffer_len, &head, (c));
        } else if (escape) {
            if (!in_token)
                do { add_token(tokens, n, i++, head - buffer, (0)); in_token = 1; } while(0);
            write_char(&buffer, &buffer_len, &head, (c));
            escape = 0;
        } else {
            if (isspecial(prev) && !isspecial(c))
                do { write_char(&buffer, &buffer_len, &head, '\0'); in_token = 0; } while(0);
            if (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISspace)) {
                if (!((*__ctype_b_loc ())[(int) ((prev))] & (unsigned short) _ISspace) && !isspecial(prev))
                    do { write_char(&buffer, &buffer_len, &head, '\0'); in_token = 0; } while(0);
            } else {
                if (isspecial(c)) {
                    if (need_split(c, prev))
                        do { write_char(&buffer, &buffer_len, &head, '\0'); in_token = 0; } while(0);
                    if (!in_token)
                        do { add_token(tokens, n, i++, head - buffer, (1)); in_token = 1; } while(0);
                }
                if (c == '\'' || c == '"')
                    quote = c;
                else {
                    if (!in_token)
                        do { add_token(tokens, n, i++, head - buffer, (0)); in_token = 1; } while(0);
                    escape = c == '\\';
                    if (!escape)
                        write_char(&buffer, &buffer_len, &head, (c));
                }
            }
        }
        prev = c;
    }
    if (quote) {
        error(0, 0, "error: Unclosed quote");
        return -1;
    }
    for (long j = 0; j < i; ++j)
        (*tokens)[j].token = buffer + (*tokens)[j].offset;
    return i;
}

variable_types:
line
char *

variable_types:
buffer
char *

variable_types:
head
char *

variable_types: quote char

variable_types: i long

variable_types:
p
char *

variable_types: c char

variable_types: j long

return_type: long


decompiled_code:
int __fastcall print_tokens(unsigned __int64 a1, __int64 a2)
{
__int64 v3; // rbx
__int64 i; // rbp

putchar(91);
if ( a1 )
{
printf("`%s'", *(const char **)(a2 + 8));
if ( *(_BYTE *)a2 )
putchar(42);
if ( a1 > 1 )
{
v3 = a2 + 16;
for ( i = 1LL; i != a1; ++i )
{
printf(", `%s'", *(const char **)(v3 + 8));
if ( *(_BYTE *)v3 )
putchar(42);
v3 += 16LL;
}
}
}
return puts("]");
}

original_code:
void print_tokens(size_t num_tokens, struct Token *tokens)
{
    printf("[");
    if (num_tokens) {
        printf("`%s'", tokens[0].token);
        if (tokens[0].special)
            printf("*");
        for (int i = 1; i < num_tokens; ++i) {
            printf(", `%s'", tokens[i].token);
            if (tokens[i].special)
                printf("*");
        }
    }
    printf("]\n");
}

canonical_original_code:
void print_tokens(unsigned long num_tokens, struct Token *tokens)
{
    printf("[");
    if (num_tokens) {
        printf("`%s'", tokens[0].token);
        if (tokens[0].special)
            printf("*");
        for (int i = 1; i < num_tokens; ++i) {
            printf(", `%s'", tokens[i].token);
            if (tokens[i].special)
                printf("*");
        }
    }
    printf("]\n");
}

variable_types: struct Token { _Bool special; union { char *token; long offset; }; } *


decompiled_code:
__int64 __fastcall valid_operator(char *s1)
{
char **v1; // r12
const char *v2; // rsi
char **v3; // rbx

v1 = binary_tokens;
while ( 1 )
{
v2 = *v1;
if ( *v1 )
break;
LABEL_6:
if ( !strcmp(s1, "(") )
return 1LL;
if ( !strcmp(s1, ")") )
return 1LL;
v1 += 4;
if ( v1 == (char **)&unk_8C0 )
return 0LL;
}
v3 = v1 + 1;
while ( strcmp(s1, v2) )
{
v2 = *v3++;
if ( !v2 )
goto LABEL_6;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
char **v1; // r12
const char *v2; // rsi
char **v3; // rbx

v1 = binary_tokens;
while ( 1 )
{
v2 = *v1;
if ( *v1 )
break;
LABEL_6:
if ( !strcmp(s1, "(") )
return 1LL;
if ( !strcmp(s1, ")") )
return 1LL;
v1 += 4;
if ( v1 == (char **)&unk_8C0 )
return 0LL;
}
v3 = v1 + 1;
while ( strcmp(s1, v2) )
{
v2 = *v3++;
if ( !v2 )
goto LABEL_6;
}
return 1LL;
}

original_code:
static _Bool valid_operator(char *token)
{
    for (size_t i = 0; i < (sizeof(binary_tokens) / sizeof(*binary_tokens)); ++i) {
        const char **operators = binary_tokens[i];
        for (size_t j = 0; operators[j]; ++j) {
            if (strcmp(token, operators[j]) == 0)
                return 1;
        }
        if (strcmp(token, "(") == 0 || strcmp(token, ")") == 0)
            return 1;
    }
    return 0;
}

canonical_original_code:
static _Bool valid_operator(char *token)
{
    for (unsigned long i = 0; i < (sizeof(binary_tokens) / sizeof(*binary_tokens)); ++i) {
        char **operators = binary_tokens[i];
        for (unsigned long j = 0; operators[j]; ++j) {
            if (strcmp(token, operators[j]) == 0)
                return 1;
        }
        if (strcmp(token, "(") == 0 || strcmp(token, ")") == 0)
            return 1;
    }
    return 0;
}

variable_types:
token
char *

variable_types:
operators
char **

variable_types:
j
unsigned long


decompiled_code:
__int64 __fastcall is_full(int *a1)
{
int v1; // eax
char v3; // dl
char v4; // al

v1 = *a1;
if ( (unsigned int)*a1 > 7 )
{
if ( (unsigned int)(v1 - 9) <= 1 && !*(_QWORD *)(*((_QWORD *)a1 + 3) + 16LL) )
{
LABEL_11:
error(0, 0, "parse error near `%s'", *(const char **)(*((_QWORD *)a1 + 1) + 8LL));
return 0LL;
}
}
else
{
if ( !v1 )
return 1LL;
if ( !*(_QWORD *)(*((_QWORD *)a1 + 3) + 16LL) || !*(_QWORD *)(*((_QWORD *)a1 + 4) + 16LL) )
goto LABEL_11;
}
v3 = is_full(*((_QWORD *)a1 + 3));
v4 = 0;
if ( v3 )
v4 = is_full(*((_QWORD *)a1 + 4));
return v4 & 1;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
int v1; // eax
char v3; // dl
char v4; // al

v1 = *a1;
if ( (unsigned int)*a1 > 7 )
{
if ( (unsigned int)(v1 - 9) <= 1 && !*(_QWORD *)(*((_QWORD *)a1 + 3) + 16LL) )
{
LABEL_11:
error(0, 0, "parse error near `%s'", *(const char **)(*((_QWORD *)a1 + 1) + 8LL));
return 0LL;
}
}
else
{
if ( !v1 )
return 1LL;
if ( !*(_QWORD *)(*((_QWORD *)a1 + 3) + 16LL) || !*(_QWORD *)(*((_QWORD *)a1 + 4) + 16LL) )
goto LABEL_11;
}
v3 = func1(*((_QWORD *)a1 + 3));
v4 = 0;
if ( v3 )
v4 = func1(*((_QWORD *)a1 + 4));
return v4 & 1;
}

original_code:
static _Bool is_full(struct SyntaxTree *root)
{
    switch (root->type) {
        case NODE_CMD:
            return 1;
        case NODE_REDIR_IN:
        case NODE_REDIR_OUT:
        case NODE_REDIR_APPEND:
        case NODE_PIPE:
        case NODE_ERR_PIPE:
        case NODE_AND:
        case NODE_OR:
            if (root->left->num_tokens == 0 || root->right->num_tokens == 0) {
                error(0, 0, "parse error near `%s'", root->tokens[0].token);
                return 0;
            }
            break;
        case NODE_SEMICOLON:
            break;
        case NODE_BACKGROUND:
        case NODE_DISOWN:
            if (root->left->num_tokens == 0) {
                error(0, 0, "parse error near `%s'", root->tokens[0].token);
                return 0;
            }
            break;
    }
    return is_full(root->left) && is_full(root->right);
}

variable_types: struct SyntaxTree { enum NodeType { NODE_CMD=0, NODE_REDIR_IN=1, NODE_REDIR_OUT=2, NODE_REDIR_APPEND=3, NODE_PIPE=4, NODE_ERR_PIPE=5, NODE_AND=6, NODE_OR=7, NODE_SEMICOLON=8, NODE_BACKGROUND=9, NODE_DISOWN=10 } type; struct Token { _Bool special; union { char *token; long offset; }; } *tokens; unsigned long num_tokens; struct SyntaxTree *left; } *


original_code:
static int strip_parens(struct SyntaxTree *root)
{
    if (root->num_tokens == 0)
        return 0;
    ssize_t parens = 0;
    _Bool strip = root->tokens[0].special &&
                 strcmp(root->tokens[0].token, "(") == 0 &&
                 root->tokens[root->num_tokens - 1].special &&
                 strcmp(root->tokens[root->num_tokens - 1].token, ")") == 0;
    for (size_t i = 0; i < root->num_tokens; ++i) {
        if (root->tokens[i].special) {
            char *token = root->tokens[i].token;
            if (strcmp(token, "(") == 0)
                ++parens;
            else if (strcmp(token, ")") == 0) {
                --parens;
                if (parens == 0 && i != root->num_tokens - 1)
                    strip = 0;
                else if (parens < 0)
                    return -1;
            }
        }
    }
    if (strip) {
        root->num_tokens -= 2;
        memmove(root->tokens, root->tokens + 1,
                root->num_tokens * sizeof(struct Token));
        return strip_parens(root);
    } else
        return parens == 0 ? 0 : -1;
}

canonical_original_code:
static int strip_parens(struct SyntaxTree *root)
{
    if (root->num_tokens == 0)
        return 0;
    long parens = 0;
    _Bool strip = root->tokens[0].special &&
                 strcmp(root->tokens[0].token, "(") == 0 &&
                 root->tokens[root->num_tokens - 1].special &&
                 strcmp(root->tokens[root->num_tokens - 1].token, ")") == 0;
    for (unsigned long i = 0; i < root->num_tokens; ++i) {
        if (root->tokens[i].special) {
            char *token = root->tokens[i].token;
            if (strcmp(token, "(") == 0)
                ++parens;
            else if (strcmp(token, ")") == 0) {
                --parens;
                if (parens == 0 && i != root->num_tokens - 1)
                    strip = 0;
                else if (parens < 0)
                    return -1;
            }
        }
    }
    if (strip) {
        root->num_tokens -= 2;
        memmove(root->tokens, root->tokens + 1,
                root->num_tokens * sizeof(struct Token));
        return strip_parens(root);
    } else
        return parens == 0 ? 0 : -1;
}

variable_types: parens long


decompiled_code:
__int64 __fastcall get_node_type(const char *a1)
{
if ( !strcmp(a1, "<") )
return 1LL;
if ( !strcmp(a1, ">") )
return 2LL;
if ( !strcmp(a1, ">>") )
return 3LL;
if ( !strcmp(a1, "|") )
return 4LL;
if ( !strcmp(a1, "|&") )
return 5LL;
if ( !strcmp(a1, "&&") )
return 6LL;
if ( !strcmp(a1, "||") )
return 7LL;
if ( !strcmp(a1, ";") )
return 8LL;
if ( !strcmp(a1, "&") )
return 9LL;
if ( strcmp(a1, "&!") )
_assert_fail("0", "parser.c", 0xE5u, "get_node_type");
return 10LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
if ( !strcmp(a1, "<") )
return 1LL;
if ( !strcmp(a1, ">") )
return 2LL;
if ( !strcmp(a1, ">>") )
return 3LL;
if ( !strcmp(a1, "|") )
return 4LL;
if ( !strcmp(a1, "|&") )
return 5LL;
if ( !strcmp(a1, "&&") )
return 6LL;
if ( !strcmp(a1, "||") )
return 7LL;
if ( !strcmp(a1, ";") )
return 8LL;
if ( !strcmp(a1, "&") )
return 9LL;
if ( strcmp(a1, "&!") )
_assert_fail("0", "parser.c", 0xE5u, "get_node_type");
return 10LL;
}

original_code:
static inline enum NodeType get_node_type(char *token) {
    if (strcmp(token, "<") == 0)
        return NODE_REDIR_IN;
    else if (strcmp(token, ">") == 0)
        return NODE_REDIR_OUT;
    else if (strcmp(token, ">>") == 0)
        return NODE_REDIR_APPEND;
    else if (strcmp(token, "|") == 0)
        return NODE_PIPE;
    else if (strcmp(token, "|&") == 0)
        return NODE_ERR_PIPE;
    else if (strcmp(token, "&&") == 0)
        return NODE_AND;
    else if (strcmp(token, "||") == 0)
        return NODE_OR;
    else if (strcmp(token, ";") == 0)
        return NODE_SEMICOLON;
    else if (strcmp(token, "&") == 0)
        return NODE_BACKGROUND;
    else if (strcmp(token, "&!") == 0)
        return NODE_DISOWN;
    else
        ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("0", "parser.c", 229, __extension__ __PRETTY_FUNCTION__); }));
}

return_type: enum NodeType { NODE_CMD=0, NODE_REDIR_IN=1, NODE_REDIR_OUT=2, NODE_REDIR_APPEND=3, NODE_PIPE=4, NODE_ERR_PIPE=5, NODE_AND=6, NODE_OR=7, NODE_SEMICOLON=8, NODE_BACKGROUND=9, NODE_DISOWN=10 }


original_code:
static void split_node(struct SyntaxTree *root, size_t i)
{
    root->left = syntax_node(i);
    memcpy(root->left->tokens, root->tokens,
            root->left->num_tokens * sizeof(struct Token));
    split_tree(root->left);
    root->right = syntax_node(root->num_tokens - (i + 1));
    memcpy(root->right->tokens, root->tokens + (i + 1),
            root->right->num_tokens * sizeof(struct Token));
    split_tree(root->right);
    root->tokens[0] = root->tokens[i];
    root->num_tokens = 1;
    root->type = get_node_type(root->tokens[0].token);
}

canonical_original_code:
static void split_node(struct SyntaxTree *root, unsigned long i)
{
    root->left = syntax_node(i);
    memcpy(root->left->tokens, root->tokens,
            root->left->num_tokens * sizeof(struct Token));
    split_tree(root->left);
    root->right = syntax_node(root->num_tokens - (i + 1));
    memcpy(root->right->tokens, root->tokens + (i + 1),
            root->right->num_tokens * sizeof(struct Token));
    split_tree(root->right);
    root->tokens[0] = root->tokens[i];
    root->num_tokens = 1;
    root->type = get_node_type(root->tokens[0].token);
}


original_code:
static int split_tree(struct SyntaxTree *root)
{
    ssize_t parens = 0;
    if (strip_parens(root) == -1) {
        error(0, 0, "parsing error: unmatched parentheses");
        return -1;
    }
    for (size_t level = 0; level < (sizeof(binary_tokens) / sizeof(*binary_tokens)); ++level) {
        for (ssize_t i = root->num_tokens - 1; i >= 0; --i) {
            const char **operators = binary_tokens[level];
            for (size_t j = 0; operators[j]; ++j) {
                if (root->tokens[i].special) {
                    char *token = root->tokens[i].token;
                    if (strcmp(token, ")") == 0)
                        ++parens;
                    else if (strcmp(token, "(") == 0)
                        --parens;
                    else if (!parens && strcmp(token, operators[j]) == 0) {
                        split_node(root, i);
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}

canonical_original_code:
static int split_tree(struct SyntaxTree *root)
{
    long parens = 0;
    if (strip_parens(root) == -1) {
        error(0, 0, "parsing error: unmatched parentheses");
        return -1;
    }
    for (unsigned long level = 0; level < (sizeof(binary_tokens) / sizeof(*binary_tokens)); ++level) {
        for (long i = root->num_tokens - 1; i >= 0; --i) {
            char **operators = binary_tokens[level];
            for (unsigned long j = 0; operators[j]; ++j) {
                if (root->tokens[i].special) {
                    char *token = root->tokens[i].token;
                    if (strcmp(token, ")") == 0)
                        ++parens;
                    else if (strcmp(token, "(") == 0)
                        --parens;
                    else if (!parens && strcmp(token, operators[j]) == 0) {
                        split_node(root, i);
                        return 0;
                    }
                }
            }
        }
    }
    return 0;
}

variable_types:
level
unsigned long


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

if ( !*(_QWORD *)(a1 + 24) && !*(_QWORD *)(a1 + 32) )
return (unsigned int)-((unsigned int)split_tree(a1) == -1);
result = ((__int64 (*)(void))parse_helper)();
if ( (_DWORD)result != -1 )
result = (unsigned int)-((unsigned int)parse_helper(*(_QWORD *)(a1 + 32)) == -1);
return result;
}

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

if ( !*(_QWORD *)(a1 + 24) && !*(_QWORD *)(a1 + 32) )
return (unsigned int)-((unsigned int)func6(a1) == -1);
result = ((__int64 (*)(void))parse_helper)();
if ( (_DWORD)result != -1 )
result = (unsigned int)-((unsigned int)func7(*(_QWORD *)(a1 + 32)) == -1);
return result;
}

original_code:
static int parse_helper(struct SyntaxTree *root)
{
    if (!root->left && !root->right) {
        if (split_tree(root) == -1)
            return -1;
    } else {
        if (parse_helper(root->left) == -1 ||
            parse_helper(root->right) == -1)
            return -1;
    }
    return 0;
}


decompiled_code:
void __fastcall free_tree(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free_tree(*((void **)ptr + 3));
free_tree(*((void **)ptr + 4));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
func8(*((void **)ptr + 3));
func8(*((void **)ptr + 4));
free(ptr);
}
}

original_code:
void free_tree(struct SyntaxTree *root)
{
    if (root) {
        free(root->tokens);
        free_tree(root->left);
        free_tree(root->right);
        free(root);
    }
}


decompiled_code:
__int64 __fastcall print_tree(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
{
print_tokens(a1[2], a1[1]);
print_tree(a1[3]);
result = print_tree(a1[4]);
}
return result;
}

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

if ( a1 )
{
print_tokens(a1[2], a1[1]);
func9(a1[3]);
result = func9(a1[4]);
}
return result;
}

original_code:
void print_tree(struct SyntaxTree *root)
{
    if (root) {
        print_tokens(root->num_tokens, root->tokens);
        print_tree(root->left);
        print_tree(root->right);
    }
}


decompiled_code:
void __fastcall __noreturn builtin_exit(int a1, __int64 a2)
{
int v3; // edi

v3 = 0;
if ( a1 > 1 )
v3 = atoi(*(const char **)(a2 + 8)) % 256;
exit(v3);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1, __int64 a2)
{
int v3; // edi

v3 = 0;
if ( a1 > 1 )
v3 = atoi(*(const char **)(a2 + 8)) % 256;
exit(v3);
}

original_code:
static int builtin_exit(int argc, char **argv)
{
    int status = 0;
    if (argc > 1)
        status = atoi(argv[1]) % 256;
    exit(status);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: status int


decompiled_code:
__int64 __fastcall builtin_cd(__int64 a1, __int64 a2)
{
char *v2; // rbx
char *v3; // rax
__int64 result; // rax
int *v5; // rax

v2 = getcwd(0LL, 0LL);
v3 = *(char **)(a2 + 8);
if ( !v2 )
goto LABEL_11;
if ( !prev_path_0 )
prev_path_0 = v2;
if ( v3 )
{
if ( !strcmp(v3, "-") )
v3 = prev_path_0;
}
else
{
v3 = getenv("HOME");
}
if ( chdir(v3) == -1 )
{
LABEL_11:
v5 = _errno_location();
error(0, *v5, "error");
result = 1LL;
}
else
{
prev_path_0 = v2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char *v2; // rbx
char *v3; // rax
__int64 result; // rax
int *v5; // rax

v2 = getcwd(0LL, 0LL);
v3 = *(char **)(a2 + 8);
if ( !v2 )
goto LABEL_11;
if ( !prev_path_0 )
prev_path_0 = v2;
if ( v3 )
{
if ( !strcmp(v3, "-") )
v3 = prev_path_0;
}
else
{
v3 = getenv("HOME");
}
if ( chdir(v3) == -1 )
{
LABEL_11:
v5 = _errno_location();
error(0, *v5, "error");
result = 1LL;
}
else
{
prev_path_0 = v2;
result = 0LL;
}
return result;
}

original_code:
static int builtin_cd(int argc, char **argv)
{
    static char *prev_path = ((void *)0);
    char *cwd = getcwd(((void *)0), 0), *path = argv[1];
    if (!cwd) {
        error(0, (*__errno_location ()), "error");
        return 1;
    }
    if (!prev_path)
        prev_path = cwd;
    if (!argv[1])
        path = getenv("HOME");
    else if (strcmp(argv[1], "-") == 0)
        path = prev_path;
    if (chdir(path) == -1) {
        error(0, (*__errno_location ()), "error");
        return 1;
    }
    prev_path = cwd;
    return 0;
}

canonical_original_code:
static int builtin_cd(int argc, char **argv)
{
    static char *prev_path = ((void *)0);
    char *cwd = getcwd(((void *)0), 0); char *path = argv[1];
    if (!cwd) {
        error(0, (*__errno_location ()), "error");
        return 1;
    }
    if (!prev_path)
        prev_path = cwd;
    if (!argv[1])
        path = getenv("HOME");
    else if (strcmp(argv[1], "-") == 0)
        path = prev_path;
    if (chdir(path) == -1) {
        error(0, (*__errno_location ()), "error");
        return 1;
    }
    prev_path = cwd;
    return 0;
}

variable_types:
cwd
char *

variable_types:
path
char *


decompiled_code:
__int64 __fastcall exec_builtin(unsigned int a1, const char **a2)
{
bool v2; // zf
_BOOL4 v3; // eax

v2 = strcmp("cd", *a2) == 0;
v3 = !v2;
if ( !v2 )
{
if ( strcmp("exit", *a2) )
return 0xFFFFFFFFLL;
v3 = 1;
}
return ((__int64 (__fastcall *)(__int64, __int64))*(&off_188 + 2 * v3))(a1, (__int64)a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, const char **a2)
{
bool v2; // zf
_BOOL4 v3; // eax

v2 = strcmp("cd", *a2) == 0;
v3 = !v2;
if ( !v2 )
{
if ( strcmp("exit", *a2) )
return 0xFFFFFFFFLL;
v3 = 1;
}
return ((__int64 (__fastcall *)(__int64, __int64))*(&off_188 + 2 * v3))(a1, (__int64)a2);
}

original_code:
int exec_builtin(int argc, char **argv)
{
    for (int i = 0; i < sizeof(builtins) / sizeof(*builtins); ++i) {
        if (strcmp(builtins[i].name, argv[0]) == 0)
            return builtins[i].func(argc, argv);
    }
    return -1;
}

variable_types: i int


repo: oshogbo/warnock

variable_types: struct surface_t { struct coord_t { float x; float y; float z; float xp; float yp; } coords[4]; float r; float g; float b; } *

variable_types: f float

user_defined_types: struct surface_t { struct coord_t coords[4]; float r; float g; float b; }


decompiled_code:
__int64 __fastcall init_box_tb(__int64 a1, char a2)
{
__int64 v2; // xmm0_8
__m128i v3; // xmm3
float v4; // er14

v2 = LC0;
if ( !a2 )
v2 = LC1;
v3 = 0LL;
*(float *)v3.m128i_i32 = *(double *)&v2 * 240.0;
v4 = COERCE_FLOAT(_mm_cvtsi128_si32(v3));
coord_set(a1, 300.0, *(float *)v3.m128i_i32, COERCE_DOUBLE((unsigned __int64)LC4));
coord_set(a1 + 20, 300.0, v4, COERCE_DOUBLE((unsigned __int64)LC6));
coord_set(a1 + 40, 600.0, v4, COERCE_DOUBLE((unsigned __int64)LC6));
return coord_set(a1 + 60, 600.0, v4, COERCE_DOUBLE((unsigned __int64)LC4));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
__int64 v2; // xmm0_8
__m128i v3; // xmm3
float v4; // er14

v2 = LC0;
if ( !a2 )
v2 = LC1;
v3 = 0LL;
*(float *)v3.m128i_i32 = *(double *)&v2 * 240.0;
v4 = COERCE_FLOAT(_mm_cvtsi128_si32(v3));
coord_set(a1, 300.0, *(float *)v3.m128i_i32, COERCE_DOUBLE((unsigned __int64)LC4));
coord_set(a1 + 20, 300.0, v4, COERCE_DOUBLE((unsigned __int64)LC6));
coord_set(a1 + 40, 600.0, v4, COERCE_DOUBLE((unsigned __int64)LC6));
return coord_set(a1 + 60, 600.0, v4, COERCE_DOUBLE((unsigned __int64)LC4));
}

user_defined_types: struct coord_t { float x; float y; float z; float xp; float yp; }


decompiled_code:
__int64 __fastcall init_box_lr(__int64 a1, char a2)
{
__int64 v2; // xmm0_8
__m128i v3; // xmm3
float v4; // er14

v2 = LC0;
if ( !a2 )
v2 = LC1;
v3 = 0LL;
*(float *)v3.m128i_i32 = *(double *)&v2 * 300.0;
v4 = COERCE_FLOAT(_mm_cvtsi128_si32(v3));
coord_set(a1, *(float *)v3.m128i_i32, 240.0, COERCE_DOUBLE((unsigned __int64)LC4));
coord_set(a1 + 20, v4, 240.0, COERCE_DOUBLE((unsigned __int64)LC6));
coord_set(a1 + 40, v4, 480.0, COERCE_DOUBLE((unsigned __int64)LC6));
return coord_set(a1 + 60, v4, 480.0, COERCE_DOUBLE((unsigned __int64)LC4));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2)
{
__int64 v2; // xmm0_8
__m128i v3; // xmm3
float v4; // er14

v2 = LC0;
if ( !a2 )
v2 = LC1;
v3 = 0LL;
*(float *)v3.m128i_i32 = *(double *)&v2 * 300.0;
v4 = COERCE_FLOAT(_mm_cvtsi128_si32(v3));
coord_set(a1, *(float *)v3.m128i_i32, 240.0, COERCE_DOUBLE((unsigned __int64)LC4));
coord_set(a1 + 20, v4, 240.0, COERCE_DOUBLE((unsigned __int64)LC6));
coord_set(a1 + 40, v4, 480.0, COERCE_DOUBLE((unsigned __int64)LC6));
return coord_set(a1 + 60, v4, 480.0, COERCE_DOUBLE((unsigned __int64)LC4));
}


decompiled_code:
__int64 __fastcall init_box(__int64 a1)
{
init_box_fb(a1, 0);
init_box_fb(a1 + 92, 1);
init_box_tb(a1 + 184, 0);
init_box_tb(a1 + 276, 1);
init_box_lr(a1 + 368, 0);
return init_box_lr(a1 + 460, 1);
}

original_code:
void
init_box(box_t *b)
{
 int i;
 i = 0;
 init_box_fb(&b->surfaces[i++], 0);
 init_box_fb(&b->surfaces[i++], 1);
 init_box_tb(&b->surfaces[i++], 0);
 init_box_tb(&b->surfaces[i++], 1);
 init_box_lr(&b->surfaces[i++], 0);
 init_box_lr(&b->surfaces[i++], 1);
}

canonical_original_code:
void init_box(struct box_t *b)
{
 int i;
 i = 0;
 init_box_fb(&b->surfaces[i++], 0);
 init_box_fb(&b->surfaces[i++], 1);
 init_box_tb(&b->surfaces[i++], 0);
 init_box_tb(&b->surfaces[i++], 1);
 init_box_lr(&b->surfaces[i++], 0);
 init_box_lr(&b->surfaces[i++], 1);
}

variable_types: struct box_t { struct surface_t { struct coord_t { float x; float y; float z; float xp; float yp; } coords[4]; float r; float g; float b; } surfaces[6]; int color_schame; } *

user_defined_types: struct box_t { struct surface_t surfaces[6]; int color_schame; }


decompiled_code:
__int64 __fastcall box_rotate_x(__int64 a1, float a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
do
{
result = surface_rotate_x(v2, a2);
v2 += 92LL;
}
while ( v2 != a1 + 552 );
return result;
}

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

v2 = a1;
do
{
result = surface_rotate_x(v2, a2);
v2 += 92LL;
}
while ( v2 != a1 + 552 );
return result;
}

original_code:
void
box_rotate_x(box_t *b, float alphax)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_rotate_x(&b->surfaces[i], alphax);
}

canonical_original_code:
void box_rotate_x(struct box_t *b, float alphax)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_rotate_x(&b->surfaces[i], alphax);
}

variable_types: alphax float


decompiled_code:
__int64 __fastcall box_rotate_y(__int64 a1, float a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
do
{
result = surface_rotate_y(v2, a2);
v2 += 92LL;
}
while ( v2 != a1 + 552 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, float a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
do
{
result = surface_rotate_y(v2, a2);
v2 += 92LL;
}
while ( v2 != a1 + 552 );
return result;
}

original_code:
void
box_rotate_y(box_t *b, float alphax)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_rotate_y(&b->surfaces[i], alphax);
}

canonical_original_code:
void box_rotate_y(struct box_t *b, float alphax)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_rotate_y(&b->surfaces[i], alphax);
}


decompiled_code:
__int64 __fastcall box_rotate_z(__int64 a1, float a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
do
{
result = surface_rotate_z(v2, a2);
v2 += 92LL;
}
while ( v2 != a1 + 552 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, float a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
do
{
result = surface_rotate_z(v2, a2);
v2 += 92LL;
}
while ( v2 != a1 + 552 );
return result;
}

original_code:
void
box_rotate_z(box_t *b, float alphax)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_rotate_z(&b->surfaces[i], alphax);
}

canonical_original_code:
void box_rotate_z(struct box_t *b, float alphax)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_rotate_z(&b->surfaces[i], alphax);
}


decompiled_code:
__int64 __fastcall box_translation(__int64 a1, float a2, float a3, float a4)
{
__int64 v4; // rbx
__int64 result; // rax

v4 = a1;
do
{
result = surface_translation(v4, a2, a3, a4);
v4 += 92LL;
}
while ( v4 != a1 + 552 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, float a2, float a3, float a4)
{
__int64 v4; // rbx
__int64 result; // rax

v4 = a1;
do
{
result = surface_translation(v4, a2, a3, a4);
v4 += 92LL;
}
while ( v4 != a1 + 552 );
return result;
}

original_code:
void
box_translation(box_t *b, float x, float y, float z)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_translation(&b->surfaces[i], x, y, z);
}

canonical_original_code:
void box_translation(struct box_t *b, float x, float y, float z)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_translation(&b->surfaces[i], x, y, z);
}

variable_types: x float

variable_types: y float

variable_types: z float


decompiled_code:
__int64 __fastcall box_project(__int64 a1, float a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
do
{
result = surface_project(v2, a2);
v2 += 92LL;
}
while ( v2 != a1 + 552 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, float a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = a1;
do
{
result = surface_project(v2, a2);
v2 += 92LL;
}
while ( v2 != a1 + 552 );
return result;
}

original_code:
void
box_project(box_t *b, float d)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_project(&b->surfaces[i], d);
}

canonical_original_code:
void box_project(struct box_t *b, float d)
{
 int i;
 for (i = 0; i < 6; i++)
  surface_project(&b->surfaces[i], d);
}

variable_types: d float