decompiled_code:
size_t __fastcall stacktracer_pushbuf(char *src)
{
char *v1; // rbx
size_t result; // rax

strcat(debug_buff, src);
v1 = debug_buff;
result = strlen(debug_buff);
*(_WORD *)&v1[result] = 10;
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(char *src)
{
char *v1; // rbx
size_t result; // rax

strcat(debug_buff, src);
v1 = debug_buff;
result = strlen(debug_buff);
*(_WORD *)&v1[result] = 10;
return result;
}

original_code:
void stacktracer_pushbuf(char *s)
{
  strcat(debug_buff, s);
  strcat(debug_buff, "\n");
}


decompiled_code:
void stacktracer_prebarf()
{
int v0; // er12
char **v1; // rax
char **v2; // rbx
char **v3; // rbp
char *v4; // rbp
__int64 i; // rbx
const char *v6; // rcx
const char *v7; // rdx
char **v8; // rbx
char **v9; // rbp
char *v10; // rdi
char **v11; // rax
char **v12; // rbx
char **v13; // rbp

*debug_buff = 0;
debug_buff_written = 1;
stacktracer_pushbuf("===== DEBUGGING INFO =====");
stacktracer_pushbuf("Evaluation trace:");
v0 = ptr;
if ( full )
{
if ( ptr > 4 )
goto LABEL_15;
v8 = (char **)((char *)stacktraces + 8 * ptr);
v9 = (char **)((char *)stacktraces + 8 * ptr + 8 * (unsigned __int64)(unsigned int)(4 - ptr) + 8);
do
{
v10 = *v8++;
stacktracer_pushbuf(v10);
}
while ( v9 != v8 );
if ( v0 > 0 )
{
LABEL_15:
v11 = (char **)stacktraces;
v12 = (char **)((char *)stacktraces + 8);
v13 = (char **)((char *)stacktraces + 8 * (unsigned int)(v0 - 1) + 8);
while ( 1 )
{
stacktracer_pushbuf(*v11);
v11 = v12;
if ( v12 == v13 )
break;
++v12;
}
}
}
else if ( ptr > 0 )
{
v1 = (char **)stacktraces;
v2 = (char **)((char *)stacktraces + 8);
v3 = (char **)((char *)stacktraces + 8 * (unsigned int)(ptr - 1) + 8);
while ( 1 )
{
stacktracer_pushbuf(*v1);
v1 = v2;
if ( v3 == v2 )
break;
++v2;
}
}
stacktracer_pushbuf((char *)&byte_7AB);
stacktracer_pushbuf("Symbols: ");
v4 = (char *)malloc(0x1000uLL);
if ( !v4 )
{
error_msg("malloc failed");
code_error();
}
for ( i = 0LL; sym > (int)i; ++i )
{
v6 = (const char *)*((_QWORD *)sym_print + i);
v7 = (const char *)*((_QWORD *)sym_name + i);
sprintf(v4, "%s: %s", v7, v6);
stacktracer_pushbuf(v4);
}
stacktracer_pushbuf("===========================");
stacktracer_pushbuf(" ");
free(v4);
stacktracer_print("A debug log has been prepared. Type (debuglog) to see it.");
stacktracer_reset();
}

canonical_decompiled_code:
void func8()
{
int v0; // er12
char **v1; // rax
char **v2; // rbx
char **v3; // rbp
char *v4; // rbp
__int64 i; // rbx
const char *v6; // rcx
const char *v7; // rdx
char **v8; // rbx
char **v9; // rbp
char *v10; // rdi
char **v11; // rax
char **v12; // rbx
char **v13; // rbp

*debug_buff = 0;
debug_buff_written = 1;
func7("===== DEBUGGING INFO =====");
func7("Evaluation trace:");
v0 = ptr;
if ( full )
{
if ( ptr > 4 )
goto LABEL_15;
v8 = (char **)((char *)stacktraces + 8 * ptr);
v9 = (char **)((char *)stacktraces + 8 * ptr + 8 * (unsigned __int64)(unsigned int)(4 - ptr) + 8);
do
{
v10 = *v8++;
func7(v10);
}
while ( v9 != v8 );
if ( v0 > 0 )
{
LABEL_15:
v11 = (char **)stacktraces;
v12 = (char **)((char *)stacktraces + 8);
v13 = (char **)((char *)stacktraces + 8 * (unsigned int)(v0 - 1) + 8);
while ( 1 )
{
func7(*v11);
v11 = v12;
if ( v12 == v13 )
break;
++v12;
}
}
}
else if ( ptr > 0 )
{
v1 = (char **)stacktraces;
v2 = (char **)((char *)stacktraces + 8);
v3 = (char **)((char *)stacktraces + 8 * (unsigned int)(ptr - 1) + 8);
while ( 1 )
{
func7(*v1);
v1 = v2;
if ( v3 == v2 )
break;
++v2;
}
}
func7((char *)&byte_7AB);
func7("Symbols: ");
v4 = (char *)malloc(0x1000uLL);
if ( !v4 )
{
error_msg("malloc failed");
code_error();
}
for ( i = 0LL; sym > (int)i; ++i )
{
v6 = (const char *)*((_QWORD *)sym_print + i);
v7 = (const char *)*((_QWORD *)sym_name + i);
sprintf(v4, "%s: %s", v7, v6);
func7(v4);
}
func7("===========================");
func7(" ");
free(v4);
func5("A debug log has been prepared. Type (debuglog) to see it.");
func0();
}

original_code:
void stacktracer_prebarf()
{
 int i;
 char *buff;
 *debug_buff = 0;
 debug_buff_written = 1;
 stacktracer_pushbuf("===== DEBUGGING INFO  =====");
 stacktracer_pushbuf("Evaluation trace:");
 if (!full) {
  for (i = 0; i < ptr; ++i)
   stacktracer_pushbuf(stacktraces[i]);
 } else {
  for (i = ptr; i < 5; ++i)
   stacktracer_pushbuf(stacktraces[i]);
  for (i = 0; i < ptr; ++i)
   stacktracer_pushbuf(stacktraces[i]);
 }
 stacktracer_pushbuf("");
 stacktracer_pushbuf("Symbols: ");
 buff = malloc(4096);
 if (!buff) {
  error_msg("malloc failed");
  code_error();
 }
 for (i = 0; i < sym; ++i) {
  sprintf(buff, "%s: %s", sym_name[i], sym_print[i]);
  stacktracer_pushbuf(buff);
 }
 stacktracer_pushbuf("===========================");
 stacktracer_pushbuf("  ");
 free(buff);
  stacktracer_print("A debug log has been prepared. Type (debuglog) to see it.");
 stacktracer_reset();
}

variable_types: i int

variable_types:
buff
char *

return_type: void


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

result = (unsigned int)++frames;
if ( frames > frames_usage_max )
frames_usage_max = frames;
return result;
}

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

result = (unsigned int)++frames;
if ( frames > frames_usage_max )
frames_usage_max = frames;
return result;
}

original_code:
void new_frame()
{
 ++frames;
 if (frames > frames_usage_max) {
  frames_usage_max = frames;
 }
}


decompiled_code:
void close_frame()
{
--frames;
}

canonical_decompiled_code:
void func1()
{
--frames;
}

original_code:
void close_frame()
{
 --frames;
}

canonical_original_code:
void close_frame()
{
 --frames;
}


decompiled_code:
void gc_selfdestroy()
{
__int64 v0; // rbx
void *v1; // rdi

if ( len > 0 )
{
v0 = 0LL;
do
{
v1 = (void *)*((_QWORD *)ptrs + v0++);
free(v1);
}
while ( len > (int)v0 );
}
free(mark);
free(ptrs);
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rbx
void *v1; // rdi

if ( len > 0 )
{
v0 = 0LL;
do
{
v1 = (void *)*((_QWORD *)ptrs + v0++);
free(v1);
}
while ( len > (int)v0 );
}
free(mark);
free(ptrs);
}

original_code:
void gc_selfdestroy()
{
 int i = 0;
 for (i = 0; i < len; ++i)
  free(ptrs[i]);
 free(mark);
 free(ptrs);
}


decompiled_code:
void *__fastcall add_ptr(__int64 a1)
{
int v1; // esi
char *v2; // rdx
int v3; // eax
void *result; // rax
void *v5; // rax
__int64 v6; // rsi
__int64 v7; // rdx
char *v8; // rax

v1 = alloc;
v2 = (char *)mark;
v3 = len + 1;
len = v3;
if ( v3 >= alloc )
{
alloc += 16;
v5 = (void *)better_realloc(ptrs, 8LL * (v1 + 16), mark);
v6 = alloc;
ptrs = v5;
v8 = (char *)better_realloc(mark, alloc, v7);
mark = v8;
v2 = v8;
if ( !ptrs || !v8 )
{
fatal_error_msg("marksweep: realloc has failed", v6, v8);
exit(1);
}
v3 = len;
}
v2[v3 - 1] = 0;
result = ptrs;
*((_QWORD *)ptrs + len - 1) = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // esi
char *v2; // rdx
int v3; // eax
void *result; // rax
void *v5; // rax
__int64 v6; // rsi
__int64 v7; // rdx
char *v8; // rax

v1 = alloc;
v2 = (char *)mark;
v3 = len + 1;
len = v3;
if ( v3 >= alloc )
{
alloc += 16;
v5 = (void *)better_realloc(ptrs, 8LL * (v1 + 16), mark);
v6 = alloc;
ptrs = v5;
v8 = (char *)better_realloc(mark, alloc, v7);
mark = v8;
v2 = v8;
if ( !ptrs || !v8 )
{
fatal_error_msg("marksweep: realloc has failed", v6, v8);
exit(1);
}
v3 = len;
}
v2[v3 - 1] = 0;
result = ptrs;
*((_QWORD *)ptrs + len - 1) = a1;
return result;
}

original_code:
void add_ptr(void *p)
{
 if (++len >= alloc) {
  alloc += 16;
  ptrs = better_realloc(ptrs, alloc * sizeof(void *));
  mark = better_realloc(mark, alloc);
  if (!ptrs || !mark) {
   fatal_error_msg("marksweep: realloc has failed");
   exit(1);
  }
 }
 mark[len - 1] = 0;
 ptrs[len - 1] = p;
}

variable_types:
p
void *


decompiled_code:
void __fastcall do_mark(__int64 a1, char a2)
{
__int64 v2; // rax

if ( a1 && len > 0 )
{
v2 = 0LL;
while ( *((_QWORD *)ptrs + v2) != a1 )
{
if ( ++v2 == len )
return;
}
*((_BYTE *)mark + v2) = a2;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, char a2)
{
__int64 v2; // rax

if ( a1 && len > 0 )
{
v2 = 0LL;
while ( *((_QWORD *)ptrs + v2) != a1 )
{
if ( ++v2 == len )
return;
}
*((_BYTE *)mark + v2) = a2;
}
}

original_code:
void do_mark(void* p, int m)
{
 int i;
 if (!p)
  return;
 for (i = 0; i < len; ++i) {
  if (ptrs[i] == p) {
   mark[i] = m;
   return;
  }
 }
}

canonical_original_code:
void do_mark(void *p, int m)
{
 int i;
 if (!p)
  return;
 for (i = 0; i < len; ++i) {
  if (ptrs[i] == p) {
   mark[i] = m;
   return;
  }
 }
}

variable_types: m int


marksweep

decompiled_code:
__int64 __fastcall marksweep(unsigned int *a1)
{
__int64 v2; // r8
__int64 result; // rax
__int64 v4; // rbp
__int64 v5; // rdi

do
{
do_mark((__int64)a1, 1);
do_mark(*((_QWORD *)a1 + 1), 1);
do_mark(*((_QWORD *)a1 + 2), 1);
result = *a1;
if ( (int)result > 0 )
{
do
{
do_mark(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v2), 1);
result = *a1;
}
while ( (int)result > (int)v2 );
if ( (int)result > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)a1 + 2) + 8 * v4++);
result = marksweep_list(v5);
}
while ( (int)*a1 > (int)v4 );
}
}
a1 = (unsigned int *)*((_QWORD *)a1 + 3);
}
while ( a1 && a1 != (unsigned int *)global );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
__int64 v2; // r8
__int64 result; // rax
__int64 v4; // rbp
__int64 v5; // rdi

do
{
func2((__int64)a1, 1);
func2(*((_QWORD *)a1 + 1), 1);
func2(*((_QWORD *)a1 + 2), 1);
result = *a1;
if ( (int)result > 0 )
{
do
{
func2(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v2), 1);
result = *a1;
}
while ( (int)result > (int)v2 );
if ( (int)result > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)a1 + 2) + 8 * v4++);
result = func5(v5);
}
while ( (int)*a1 > (int)v4 );
}
}
a1 = (unsigned int *)*((_QWORD *)a1 + 3);
}
while ( a1 && a1 != (unsigned int *)global );
return result;
}

original_code:
void marksweep(env_t *e)
{
 int i;
 do_mark(e, 1);
 do_mark(e->sym, 1);
 do_mark(e->ptr, 1);
 for (i = 0; i < e->count; ++i)
  do_mark(e->sym[i], 1);
 for (i = 0; i < e->count; ++i)
  marksweep_list(e->ptr[i]);
 if (e->father && e->father != global)
  marksweep(e->father);
}

canonical_original_code:
void marksweep(struct env *e)
{
 int i;
 do_mark(e, 1);
 do_mark(e->sym, 1);
 do_mark(e->ptr, 1);
 for (i = 0; i < e->count; ++i)
  do_mark(e->sym[i], 1);
 for (i = 0; i < e->count; ++i)
  marksweep_list(e->ptr[i]);
 if (e->father && e->father != global)
  marksweep(e->father);
}

variable_types: struct env { int count; int alloc; char **sym; void **ptr; struct env *father; } *


gc

decompiled_code:
void __fastcall gc(__int64 a1, __int64 a2)
{
size_t v2; // rbp
__int64 v3; // rbx
void *v4; // rdi
_QWORD *v5; // rax
__int64 v6; // rdx
_QWORD *v7; // r14
void *v8; // r12
__int64 v9; // rbx
__int64 v10; // rdi
void *v11; // rax

marksweep(global);
v2 = len;
if ( len <= 0 )
{
v7 = malloc(8LL * len);
if ( v7 )
{
v11 = malloc(v2);
len = 0;
v8 = v11;
goto LABEL_13;
}
LABEL_16:
fatal_error_msg("marksweep: malloc failed", a2, v6);
exit(1);
}
v3 = 0LL;
do
{
while ( 1 )
{
v4 = (void *)*((_QWORD *)ptrs + v3);
if ( v4 )
{
if ( !*((_BYTE *)mark + v3) )
break;
}
if ( (int)v2 <= (int)++v3 )
goto LABEL_7;
}
free(v4);
LODWORD(v2) = len;
++v3;
}
while ( len > (int)v3 );
LABEL_7:
v5 = malloc(8LL * (int)v2);
v7 = v5;
if ( !v5 )
goto LABEL_16;
memcpy(v5, ptrs, 8LL * (int)v2);
v8 = malloc((int)v2);
memcpy(v8, mark, (int)v2);
len = 0;
if ( (int)v2 > 0 )
{
v9 = 0LL;
do
{
while ( !*((_BYTE *)v8 + v9) )
{
if ( (int)v2 == ++v9 )
goto LABEL_13;
}
v10 = v7[v9++];
add_ptr(v10);
}
while ( (int)v2 != v9 );
}
LABEL_13:
free(v7);
free(v8);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
size_t v2; // rbp
__int64 v3; // rbx
void *v4; // rdi
_QWORD *v5; // rax
__int64 v6; // rdx
_QWORD *v7; // r14
void *v8; // r12
__int64 v9; // rbx
__int64 v10; // rdi
void *v11; // rax

func3(global);
v2 = len;
if ( len <= 0 )
{
v7 = malloc(8LL * len);
if ( v7 )
{
v11 = malloc(v2);
len = 0;
v8 = v11;
goto LABEL_13;
}
LABEL_16:
fatal_error_msg("marksweep: malloc failed", a2, v6);
exit(1);
}
v3 = 0LL;
do
{
while ( 1 )
{
v4 = (void *)*((_QWORD *)ptrs + v3);
if ( v4 )
{
if ( !*((_BYTE *)mark + v3) )
break;
}
if ( (int)v2 <= (int)++v3 )
goto LABEL_7;
}
free(v4);
LODWORD(v2) = len;
++v3;
}
while ( len > (int)v3 );
LABEL_7:
v5 = malloc(8LL * (int)v2);
v7 = v5;
if ( !v5 )
goto LABEL_16;
memcpy(v5, ptrs, 8LL * (int)v2);
v8 = malloc((int)v2);
memcpy(v8, mark, (int)v2);
len = 0;
if ( (int)v2 > 0 )
{
v9 = 0LL;
do
{
while ( !*((_BYTE *)v8 + v9) )
{
if ( (int)v2 == ++v9 )
goto LABEL_13;
}
v10 = v7[v9++];
func1(v10);
}
while ( (int)v2 != v9 );
}
LABEL_13:
free(v7);
free(v8);
}

original_code:
void gc()
{
 int i;
 int orig;
 void **copy_ptr;
 char *copy_mark;
 marksweep(global);
 for (i = 0; i < len; ++i)
  if (ptrs[i] != ((void *)0))
   if (mark[i] == 0)
    free(ptrs[i]);
 copy_ptr = malloc(len * sizeof(void *));
 if (!copy_ptr) {
  fatal_error_msg("marksweep: malloc failed");
  exit(1);
 }
 memcpy(copy_ptr, ptrs, len * sizeof(void *));
 copy_mark = malloc(len);
 memcpy(copy_mark, mark, len);
 orig = len;
 len = 0;
 for (i = 0; i < orig; ++i)
  if (copy_mark[i] != 0)
   add_ptr(copy_ptr[i]);
 free(copy_ptr);
 free(copy_mark);
}

variable_types: orig int


decompiled_code:
__int64 __fastcall marksweep_list(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rdi
unsigned int *v5; // rdi

do_mark(a1, 1);
do_mark(*(_QWORD *)(a1 + 32), 1);
do_mark(*(_QWORD *)a1, 1);
result = *(unsigned int *)(a1 + 8);
if ( (unsigned int)(result - 2) <= 2 )
{
if ( *(int *)(a1 + 24) > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v3++);
marksweep_list(v4);
}
while ( *(_DWORD *)(a1 + 24) > (int)v3 );
result = *(unsigned int *)(a1 + 8);
}
if ( (_DWORD)result == 4 )
{
v5 = *(unsigned int **)(a1 + 16);
if ( v5 != (unsigned int *)global )
result = marksweep(v5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rdi
unsigned int *v5; // rdi

func2(a1, 1);
func2(*(_QWORD *)(a1 + 32), 1);
func2(*(_QWORD *)a1, 1);
result = *(unsigned int *)(a1 + 8);
if ( (unsigned int)(result - 2) <= 2 )
{
if ( *(int *)(a1 + 24) > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8 * v3++);
func5(v4);
}
while ( *(_DWORD *)(a1 + 24) > (int)v3 );
result = *(unsigned int *)(a1 + 8);
}
if ( (_DWORD)result == 4 )
{
v5 = *(unsigned int **)(a1 + 16);
if ( v5 != (unsigned int *)global )
result = func3(v5);
}
}
return result;
}

original_code:
void marksweep_list(list_t *l)
{
 int i;
 do_mark(l, 1);
 do_mark(l->c, 1);
 do_mark(l->head, 1);
 if (l->type == LIST || l->type == CLOSURE || l->type == CONS)
  for (i = 0; i < l->cc; ++i)
   marksweep_list(l->c[i]);
 if (l->type == CLOSURE && l->closure != global)
  marksweep(l->closure);
}

canonical_original_code:
void marksweep_list(struct list *l)
{
 int i;
 do_mark(l, 1);
 do_mark(l->c, 1);
 do_mark(l->head, 1);
 if (l->type == LIST || l->type == CLOSURE || l->type == CONS)
  for (i = 0; i < l->cc; ++i)
   marksweep_list(l->c[i]);
 if (l->type == CLOSURE && l->closure != global)
  marksweep(l->closure);
}

variable_types: struct list { char *head; int type; int val; struct env { int count; int alloc; char **sym; void **ptr; struct env *father; } *closure; int cc; int ca; struct list **c; } *

user_defined_types: struct list { char *head; int type; int val; struct env *closure; int cc; int ca; struct list **c; }


decompiled_code:
_BOOL8 __fastcall symbol_name_char(unsigned __int8 a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1 <= 0x29u )
result = ((0x30100000600uLL >> a1) & 1) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int8 a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( a1 <= 0x29u )
result = ((0x30100000600uLL >> a1) & 1) == 0;
return result;
}

variable_types: c char

return_type: int


build

original_code:
char* build(list_t* l, char *expr)
{
 char *p, *q;
 char *old;
 char* tok;
 int sgn;
 list_t* child;
 int len;
 int i;
 tok = malloc(32);
 if (!tok) {
  error_msg("malloc failed");
  code_error();
 }
 p = expr;
 for (i = 0; abbrev[i].shorthand; ++i) {
  if (!strncmp(abbrev[i].shorthand, p, strlen(abbrev[i].shorthand))) {
   child = new_list();
   p = build(child, p + strlen(abbrev[i].shorthand));
   add_child(l, mksym(abbrev[i].internal));
   add_child(l, child);
   l->type = LIST;
   goto final;
  }
 }
 if (*p == '(') {
  ++p;
  l->type = LIST;
  l->cc = 0;
  while (*p != ')' && *p) {
   while (*p && (*p == ' ' || *p == '\t'))
    ++p;
   if (!*p)
    break;
   child = new_list();
   old = p;
   p = build(child, p);
   if (p == old)
    break;
   add_child(l, child);
  }
  if (*p++ != ')') {
   error_msg("Error: ) expected");
   code_error();
  }
 }
 else if (isnum(*p) || (*p == '-' && ((*__ctype_b_loc ())[(int) ((*(p+1)))] & (unsigned short int) _ISalnum))) {
  if (*p == '-') {
   sgn = -1;
   ++p;
  } else {
   sgn = 1;
  }
  q = tok;
  len = 0;
  while (*p && isnum(*p)) {
   *q++ = *p++;
   if (++len >= 32) {
    error_msg("numeral too long");
    code_error();
   }
  }
  *q = 0;
  l->type = NUMBER;
  sscanf(tok, "%d", &(l->val));
  l->val *= sgn;
 } else {
  while (*p == ' ' || *p == '\t')
   ++p;
  q = tok;
  len = 0;
  while (*p && symbol_name_char(*p)) {
   *q++ = *p++;
   if (++len >= 32) {
    error_msg("symbol name too long");
    code_error();
   }
  }
  *q = 0;
  l->type = SYMBOL;
  strcpy(l->head, tok);
 }
final:
 free(tok);
 return p;
}

canonical_original_code:
char *build(struct list *l, char *expr)
{
 char *p; char *q;
 char *old;
 char *tok;
 int sgn;
 struct list *child;
 int len;
 int i;
 tok = malloc(32);
 if (!tok) {
  error_msg("malloc failed");
  code_error();
 }
 p = expr;
 for (i = 0; abbrev[i].shorthand; ++i) {
  if (!strncmp(abbrev[i].shorthand, p, strlen(abbrev[i].shorthand))) {
   child = new_list();
   p = build(child, p + strlen(abbrev[i].shorthand));
   add_child(l, mksym(abbrev[i].internal));
   add_child(l, child);
   l->type = LIST;
   goto final;
  }
 }
 if (*p == '(') {
  ++p;
  l->type = LIST;
  l->cc = 0;
  while (*p != ')' && *p) {
   while (*p && (*p == ' ' || *p == '\t'))
    ++p;
   if (!*p)
    break;
   child = new_list();
   old = p;
   p = build(child, p);
   if (p == old)
    break;
   add_child(l, child);
  }
  if (*p++ != ')') {
   error_msg("Error: ) expected");
   code_error();
  }
 }
 else if (isnum(*p) || (*p == '-' && ((*__ctype_b_loc ())[(int) ((*(p+1)))] & (unsigned short) _ISalnum))) {
  if (*p == '-') {
   sgn = -1;
   ++p;
  } else {
   sgn = 1;
  }
  q = tok;
  len = 0;
  while (*p && isnum(*p)) {
   *q++ = *p++;
   if (++len >= 32) {
    error_msg("numeral too long");
    code_error();
   }
  }
  *q = 0;
  l->type = NUMBER;
  sscanf(tok, "%d", &(l->val));
  l->val *= sgn;
 } else {
  while (*p == ' ' || *p == '\t')
   ++p;
  q = tok;
  len = 0;
  while (*p && symbol_name_char(*p)) {
   *q++ = *p++;
   if (++len >= 32) {
    error_msg("symbol name too long");
    code_error();
   }
  }
  *q = 0;
  l->type = SYMBOL;
  strcpy(l->head, tok);
 }
final:
 free(tok);
 return p;
}

variable_types:
expr
char *

variable_types:
p
char *

variable_types:
q
char *

variable_types:
old
char *

variable_types:
tok
char *

variable_types: sgn int

variable_types: len int

return_type: char *

user_defined_types: struct env { int count; int alloc; char **sym; void **ptr; struct env *father; }


decompiled_code:
char *__fastcall printout_iter(const char **a1, int a2, char *a3)
{
const char **v4; // rbp
char *result; // rax
__int64 v6; // r13
__int64 v7; // rdi
int v8; // eax
char *v9; // rdx
int v10; // eax
unsigned int v11; // er13
const char *v12; // rax
__int64 v13; // rdx
char *v14; // rax
__int64 v15; // rax
int v16; // ecx
__int64 v17; // rax
int v18; // ecx

v4 = a1;
result = (char *)*((unsigned int *)a1 + 2);
switch ( (_DWORD)result )
{
case 1:
sprintf(buf, "%d", *((unsigned int *)a1 + 3));
return strcat(a3, buf);
case 0:
strcpy(buf, *a1);
return strcat(a3, buf);
case 2:
v6 = 0LL;
sprintf(buf, "(%s", *a1);
strcat(a3, buf);
if ( *((int *)a1 + 6) > 0 )
{
while ( 1 )
{
v7 = *(_QWORD *)&v4[4][8 * v6++];
printout_iter(v7, (unsigned int)(a2 + 1), a3);
if ( *((_DWORD *)v4 + 6) <= (int)v6 )
break;
*(_WORD *)buf = 32;
strcat(a3, buf);
}
}
goto LABEL_24;
case 4:
sprintf(buf, "#<CLOSURE:%p>", a1[2]);
return strcat(a3, buf);
case 5:
v14 = buf;
if ( *((_DWORD *)a1 + 3) )
{
buf[2] = 0;
*(_WORD *)v14 = 29731;
}
else
{
buf[2] = 0;
*(_WORD *)v14 = 26147;
}
return strcat(a3, buf);
case 3:
v8 = *((_DWORD *)a1 + 6);
v9 = buf;
if ( v8 != 2 )
{
if ( !v8 )
{
buf[2] = 0;
*(_WORD *)v9 = 10536;
return strcat(a3, buf);
}
LABEL_20:
v11 = a2 + 1;
*(_WORD *)buf = 40;
strcat(a3, buf);
if ( *((_DWORD *)a1 + 6) == 2 )
{
while ( 1 )
{
v12 = v4[4];
v13 = *((_QWORD *)v12 + 1);
if ( !*(_DWORD *)(v13 + 24) )
break;
printout_iter(*(_QWORD *)v12, v11, a3);
*(_WORD *)buf = 32;
strcat(a3, buf);
v4 = (const char **)*((_QWORD *)v4[4] + 1);
if ( *((_DWORD *)v4 + 6) != 2 )
goto LABEL_23;
}
v18 = *(_DWORD *)(v13 + 8);
if ( v18 )
{
if ( v18 == 3 )
goto LABEL_37;
}
else if ( !strcmp(*(const char **)v13, "NIL") )
{
LABEL_37:
printout_iter(*(_QWORD *)v12, v11, a3);
goto LABEL_24;
}
}
LABEL_23:
printout_iter(v4, v11, a3);
LABEL_24:
*(_WORD *)buf = 41;
return strcat(a3, buf);
}
v15 = *((_QWORD *)a1[4] + 1);
v16 = *(_DWORD *)(v15 + 8);
if ( v16 )
{
v10 = *(_DWORD *)(v15 + 24);
if ( v16 == 3 )
{
if ( !v10 )
{
LABEL_31:
*(_WORD *)buf = 40;
strcat(a3, buf);
printout_iter(*(_QWORD *)a1[4], (unsigned int)(a2 + 1), a3);
*(_WORD *)buf = 41;
return strcat(a3, buf);
}
if ( v10 == 2 )
goto LABEL_20;
}
}
else if ( !strcmp(*(const char **)v15, "NIL") )
{
goto LABEL_31;
}
*(_WORD *)buf = 40;
strcat(a3, buf);
printout_iter(*(_QWORD *)a1[4], (unsigned int)(a2 + 1), a3);
v17 = *((_QWORD *)a1[4] + 1);
if ( *(_DWORD *)(v17 + 8) != 3 || *(_DWORD *)(v17 + 24) )
{
*(_DWORD *)buf = 2108960;
strcat(a3, buf);
printout_iter(*((_QWORD *)a1[4] + 1), (unsigned int)(a2 + 1), a3);
}
goto LABEL_24;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char **a1, int a2, char *a3)
{
const char **v4; // rbp
char *result; // rax
__int64 v6; // r13
__int64 v7; // rdi
int v8; // eax
char *v9; // rdx
int v10; // eax
unsigned int v11; // er13
const char *v12; // rax
__int64 v13; // rdx
char *v14; // rax
__int64 v15; // rax
int v16; // ecx
__int64 v17; // rax
int v18; // ecx

v4 = a1;
result = (char *)*((unsigned int *)a1 + 2);
switch ( (_DWORD)result )
{
case 1:
sprintf(buf, "%d", *((unsigned int *)a1 + 3));
return strcat(a3, buf);
case 0:
strcpy(buf, *a1);
return strcat(a3, buf);
case 2:
v6 = 0LL;
sprintf(buf, "(%s", *a1);
strcat(a3, buf);
if ( *((int *)a1 + 6) > 0 )
{
while ( 1 )
{
v7 = *(_QWORD *)&v4[4][8 * v6++];
func0(v7, (unsigned int)(a2 + 1), a3);
if ( *((_DWORD *)v4 + 6) <= (int)v6 )
break;
*(_WORD *)buf = 32;
strcat(a3, buf);
}
}
goto LABEL_24;
case 4:
sprintf(buf, "#<CLOSURE:%p>", a1[2]);
return strcat(a3, buf);
case 5:
v14 = buf;
if ( *((_DWORD *)a1 + 3) )
{
buf[2] = 0;
*(_WORD *)v14 = 29731;
}
else
{
buf[2] = 0;
*(_WORD *)v14 = 26147;
}
return strcat(a3, buf);
case 3:
v8 = *((_DWORD *)a1 + 6);
v9 = buf;
if ( v8 != 2 )
{
if ( !v8 )
{
buf[2] = 0;
*(_WORD *)v9 = 10536;
return strcat(a3, buf);
}
LABEL_20:
v11 = a2 + 1;
*(_WORD *)buf = 40;
strcat(a3, buf);
if ( *((_DWORD *)a1 + 6) == 2 )
{
while ( 1 )
{
v12 = v4[4];
v13 = *((_QWORD *)v12 + 1);
if ( !*(_DWORD *)(v13 + 24) )
break;
func0(*(_QWORD *)v12, v11, a3);
*(_WORD *)buf = 32;
strcat(a3, buf);
v4 = (const char **)*((_QWORD *)v4[4] + 1);
if ( *((_DWORD *)v4 + 6) != 2 )
goto LABEL_23;
}
v18 = *(_DWORD *)(v13 + 8);
if ( v18 )
{
if ( v18 == 3 )
goto LABEL_37;
}
else if ( !strcmp(*(const char **)v13, "NIL") )
{
LABEL_37:
func0(*(_QWORD *)v12, v11, a3);
goto LABEL_24;
}
}
LABEL_23:
func0(v4, v11, a3);
LABEL_24:
*(_WORD *)buf = 41;
return strcat(a3, buf);
}
v15 = *((_QWORD *)a1[4] + 1);
v16 = *(_DWORD *)(v15 + 8);
if ( v16 )
{
v10 = *(_DWORD *)(v15 + 24);
if ( v16 == 3 )
{
if ( !v10 )
{
LABEL_31:
*(_WORD *)buf = 40;
strcat(a3, buf);
func0(*(_QWORD *)a1[4], (unsigned int)(a2 + 1), a3);
*(_WORD *)buf = 41;
return strcat(a3, buf);
}
if ( v10 == 2 )
goto LABEL_20;
}
}
else if ( !strcmp(*(const char **)v15, "NIL") )
{
goto LABEL_31;
}
*(_WORD *)buf = 40;
strcat(a3, buf);
func0(*(_QWORD *)a1[4], (unsigned int)(a2 + 1), a3);
v17 = *((_QWORD *)a1[4] + 1);
if ( *(_DWORD *)(v17 + 8) != 3 || *(_DWORD *)(v17 + 24) )
{
*(_DWORD *)buf = 2108960;
strcat(a3, buf);
func0(*((_QWORD *)a1[4] + 1), (unsigned int)(a2 + 1), a3);
}
goto LABEL_24;
}
return result;
}

original_code:
void printout_iter(list_t* l, int d, char *out)
{
 int i;
 if (l->type == NUMBER) {
  sprintf(buf, "%d", l->val);
  strcat(out, buf);
 } else if(l->type == SYMBOL) {
  sprintf(buf, "%s", l->head);
  strcat(out, buf);
 } else if (l->type == LIST) {
  sprintf(buf, "(%s", l->head);
  strcat(out, buf);
  for (i = 0; i < l->cc; ++i) {
   if (i > 0) {
    sprintf(buf, " ");
    strcat(out, buf);
   }
   printout_iter(l->c[i], d + 1, out);
  }
  sprintf(buf, ")");
  strcat(out, buf);
 } else if (l->type == CLOSURE) {
  sprintf(buf, "#<CLOSURE:%p>", (void *)l->closure);
  strcat(out, buf);
 } else if (l->type == BOOL) {
  if (l->val)
   sprintf(buf, "#t");
  else
   sprintf(buf, "#f");
  strcat(out, buf);
 } else if (l->type == CONS) {
  if (l->cc == 2
   && ((l->c[1]->type == SYMBOL && !strcmp(l->c[1]->head, "NIL"))
    || (l->c[1]->type == CONS && l->c[1]->cc == 0))) {
   sprintf(buf, "(");
   strcat(out, buf);
   printout_iter(l->c[0], d + 1, out);
   sprintf(buf, ")");
   strcat(out, buf);
  }
  else
  if (l->cc == 2 && (l->c[1]->cc != 2 || l->c[1]->type != CONS)) {
   sprintf(buf, "(");
   strcat(out, buf);
   printout_iter(l->c[0], d + 1, out);
   if (!(l->c[1]->type == CONS && l->c[1]->cc == 0)) {
    sprintf(buf, " . ");
    strcat(out, buf);
    printout_iter(l->c[1], d + 1, out);
   }
   sprintf(buf, ")");
   strcat(out, buf);
  } else if (l->cc) {
   sprintf(buf, "(");
   strcat(out, buf);
   while (1) {
    if (l->cc == 2 && l->c[1]->cc) {
     printout_iter(l->c[0], d + 1, out);
     sprintf(buf, " ");
     strcat(out, buf);
     l = l->c[1];
    } else {
     if (l->cc == 2
      && ((l->c[1]->type == SYMBOL && !strcmp(l->c[1]->head, "NIL"))
      || (l->c[1]->type == CONS && l->c[1]->cc == 0))) {
      printout_iter(l->c[0], d + 1, out);
     } else {
      printout_iter(l, d + 1, out);
     }
     break;
    }
   }
   sprintf(buf, ")");
   strcat(out, buf);
  } else {
   sprintf(buf, "()");
   strcat(out, buf);
  }
 }
}

canonical_original_code:
void printout_iter(struct list *l, int d, char *out)
{
 int i;
 if (l->type == NUMBER) {
  sprintf(buf, "%d", l->val);
  strcat(out, buf);
 } else if(l->type == SYMBOL) {
  sprintf(buf, "%s", l->head);
  strcat(out, buf);
 } else if (l->type == LIST) {
  sprintf(buf, "(%s", l->head);
  strcat(out, buf);
  for (i = 0; i < l->cc; ++i) {
   if (i > 0) {
    sprintf(buf, " ");
    strcat(out, buf);
   }
   printout_iter(l->c[i], d + 1, out);
  }
  sprintf(buf, ")");
  strcat(out, buf);
 } else if (l->type == CLOSURE) {
  sprintf(buf, "#<CLOSURE:%p>", (void *)l->closure);
  strcat(out, buf);
 } else if (l->type == BOOL) {
  if (l->val)
   sprintf(buf, "#t");
  else
   sprintf(buf, "#f");
  strcat(out, buf);
 } else if (l->type == CONS) {
  if (l->cc == 2
   && ((l->c[1]->type == SYMBOL && !strcmp(l->c[1]->head, "NIL"))
    || (l->c[1]->type == CONS && l->c[1]->cc == 0))) {
   sprintf(buf, "(");
   strcat(out, buf);
   printout_iter(l->c[0], d + 1, out);
   sprintf(buf, ")");
   strcat(out, buf);
  }
  else
  if (l->cc == 2 && (l->c[1]->cc != 2 || l->c[1]->type != CONS)) {
   sprintf(buf, "(");
   strcat(out, buf);
   printout_iter(l->c[0], d + 1, out);
   if (!(l->c[1]->type == CONS && l->c[1]->cc == 0)) {
    sprintf(buf, " . ");
    strcat(out, buf);
    printout_iter(l->c[1], d + 1, out);
   }
   sprintf(buf, ")");
   strcat(out, buf);
  } else if (l->cc) {
   sprintf(buf, "(");
   strcat(out, buf);
   while (1) {
    if (l->cc == 2 && l->c[1]->cc) {
     printout_iter(l->c[0], d + 1, out);
     sprintf(buf, " ");
     strcat(out, buf);
     l = l->c[1];
    } else {
     if (l->cc == 2
      && ((l->c[1]->type == SYMBOL && !strcmp(l->c[1]->head, "NIL"))
      || (l->c[1]->type == CONS && l->c[1]->cc == 0))) {
      printout_iter(l->c[0], d + 1, out);
     } else {
      printout_iter(l, d + 1, out);
     }
     break;
    }
   }
   sprintf(buf, ")");
   strcat(out, buf);
  } else {
   sprintf(buf, "()");
   strcat(out, buf);
  }
 }
}

variable_types: d int

variable_types:
out
char *


printout

decompiled_code:
void __fastcall printout(const char **a1, char *a2)
{
buf = (char *)malloc(0x400uLL);
if ( !buf )
{
error_msg("malloc failed");
code_error();
}
printout_iter(a1, 0, a2);
free(buf);
}

canonical_decompiled_code:
void __fastcall func1(const char **a1, char *a2)
{
buf = (char *)malloc(0x400uLL);
if ( !buf )
{
error_msg("malloc failed");
code_error();
}
func0(a1, 0, a2);
free(buf);
}

original_code:
void printout(list_t *l, char *s)
{
 extern void printout_iter(list_t* l, int d, char* s);
 buf = malloc(1024);
 if (!buf) {
  error_msg("malloc failed");
  code_error();
 }
 printout_iter(l, 0, s);
 free(buf);
}

canonical_original_code:
void printout(struct list *l, char *s)
{
 extern void printout_iter(struct list *l, int d, char *s);
 buf = malloc(1024);
 if (!buf) {
  error_msg("malloc failed");
  code_error();
 }
 printout_iter(l, 0, s);
 free(buf);
}

variable_types:
s
char *

variable_types: void (struct list { char *head; int type; int val; struct env { int count; int alloc; char **sym; void **ptr; struct env *father; } *closure; int cc; int ca; struct list **c; } *l, int d, char *s)


lock

repo: blaa/OTPasswd

decompiled_code:
__int64 lock()
{
int v0; // eax
__int64 result; // rax
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]

v2 = 1;
v4 = 0LL;
v3 = 0LL;
v0 = open(".otpasswd.lck", 65, 384LL);
fd = v0;
if ( v0 == -1 )
{
perror("open");
puts("Unable to open a state file");
result = 1LL;
}
else if ( fcntl(v0, 6, &v2) )
{
close(fd);
puts("Unable to lock");
result = 1LL;
}
else
{
puts("Locked");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
__int64 result; // rax
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]

v2 = 1;
v4 = 0LL;
v3 = 0LL;
v0 = open(".otpasswd.lck", 65, 384LL);
fd = v0;
if ( v0 == -1 )
{
perror("open");
puts("Unable to open a state file");
result = 1LL;
}
else if ( fcntl(v0, 6, &v2) )
{
close(fd);
puts("Unable to lock");
result = 1LL;
}
else
{
puts("Locked");
result = 0LL;
}
return result;
}

original_code:
int lock()
{
 struct flock fl;
 fl.l_type = 1;
 fl.l_whence = 0;
 fl.l_start = fl.l_len = 0;
 fd = open(".otpasswd.lck", 01|0100, 0400|0200);
 if (fd == -1) {
  perror("open");
  printf("Unable to open a state file\n");
  return 1;
 }
 if (fcntl(fd, 6, &fl) == 0) {
  printf("Locked\n");
  return 0;
 }
 close(fd);
 printf("Unable to lock\n");
 return 1;
}

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


unlock

decompiled_code:
__int64 unlock()
{
int v0; // er12
__int64 result; // rax
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]

if ( fd < 0 )
{
puts("No lock to release!");
result = 1LL;
}
else
{
v2 = 2;
v4 = 0LL;
v3 = 0LL;
v0 = fcntl(fd, 6, &v2);
close(fd);
fd = -1;
if ( v0 )
{
puts("Strange error while releasing lock");
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // er12
__int64 result; // rax
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]

if ( fd < 0 )
{
puts("No lock to release!");
result = 1LL;
}
else
{
v2 = 2;
v4 = 0LL;
v3 = 0LL;
v0 = fcntl(fd, 6, &v2);
close(fd);
fd = -1;
if ( v0 )
{
puts("Strange error while releasing lock");
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int unlock()
{
 struct flock fl;
 if (fd < 0) {
  printf("No lock to release!\n");
  return 1;
 }
 fl.l_type = 2;
 fl.l_whence = 0;
 fl.l_start = fl.l_len = 0;
 int ret = fcntl(fd, 6, &fl);
 close(fd);
 fd = -1;
 if (ret != 0) {
  printf("Strange error while releasing lock\n");
  return 1;
 }
 return 0;
}

variable_types: ret int

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12

v3 = 1;
if ( !(unsigned int)lock(argc, argv, envp) )
{
v3 = 0;
puts("Waiting for keypress");
getchar();
unlock();
}
return v3;
}

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

v3 = 1;
if ( !(unsigned int)func7(argc, argv, envp) )
{
v3 = 0;
puts("Waiting for keypress");
getchar();
func9();
}
return v3;
}

original_code:
int main(int argc, char **argv)
{
 if (lock() != 0) {
  return 1;
 }
 printf("Waiting for keypress\n"); getchar();
 unlock();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


init

decompiled_code:
__gid_t init()
{
__gid_t result; // eax

real_uid = getuid();
set_uid = geteuid();
real_gid = getgid();
result = getegid();
set_gid = result;
return result;
}

canonical_decompiled_code:
__gid_t func7()
{
__gid_t result; // eax

real_uid = getuid();
set_uid = geteuid();
real_gid = getgid();
result = getegid();
set_gid = result;
return result;
}

original_code:
void init()
{
 real_uid = getuid();
 set_uid = geteuid();
 real_gid = getgid();
 set_gid = getegid();
}


print

decompiled_code:
int print()
{
__uid_t v0; // ebp
__uid_t v1; // er12
__gid_t v2; // er13
__gid_t v3; // eax

v0 = getuid();
v1 = geteuid();
v2 = getgid();
v3 = getegid();
return printf("UID/eUID: %d/%d GID/eGID: %d/%d\n", v0, v1, v2, v3);
}

canonical_decompiled_code:
int func8()
{
__uid_t v0; // ebp
__uid_t v1; // er12
__gid_t v2; // er13
__gid_t v3; // eax

v0 = getuid();
v1 = geteuid();
v2 = getgid();
v3 = getegid();
return printf("UID/eUID: %d/%d GID/eGID: %d/%d\n", v0, v1, v2, v3);
}

original_code:
void print(void)
{
 int uid, euid;
 int gid, egid;
 uid = getuid();
 euid = geteuid();
 gid = getgid();
 egid = getegid();
 printf("UID/eUID: %d/%d GID/eGID: %d/%d\n", uid, euid, gid, egid);
}

canonical_original_code:
void print()
{
 int uid; int euid;
 int gid; int egid;
 uid = getuid();
 euid = geteuid();
 gid = getgid();
 egid = getegid();
 printf("UID/eUID: %d/%d GID/eGID: %d/%d\n", uid, euid, gid, egid);
}

variable_types: uid int

variable_types: euid int

variable_types: gid int

variable_types: egid int


decompiled_code:
__gid_t drop_temporarily()
{
__gid_t v0; // er12
__uid_t v1; // ebp
__gid_t v2; // er13
__uid_t v3; // eax
__uid_t v4; // ebp
__gid_t v5; // ebp
__gid_t result; // eax

v0 = getgid();
v1 = getuid();
v2 = getegid();
v3 = geteuid();
if ( setresuid(v1, v1, v3) || setresgid(v0, v0, v2) )
{
LABEL_6:
puts("d_t: failure");
exit(1);
}
v4 = geteuid();
if ( v4 != getuid() || (v5 = getegid(), result = getgid(), v5 != result) )
{
puts("d_t: fun");
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
__gid_t func10()
{
__gid_t v0; // er12
__uid_t v1; // ebp
__gid_t v2; // er13
__uid_t v3; // eax
__uid_t v4; // ebp
__gid_t v5; // ebp
__gid_t result; // eax

v0 = getgid();
v1 = getuid();
v2 = getegid();
v3 = geteuid();
if ( setresuid(v1, v1, v3) || setresgid(v0, v0, v2) )
{
LABEL_6:
puts("d_t: failure");
exit(1);
}
v4 = geteuid();
if ( v4 != getuid() || (v5 = getegid(), result = getgid(), v5 != result) )
{
puts("d_t: fun");
goto LABEL_6;
}
return result;
}

original_code:
void drop_temporarily(void)
{
 const int gid = getgid(), uid = getuid();
 const int egid = getegid(), euid = geteuid();
 if (setresuid(uid, uid, euid) != 0)
  goto error;
 if (setresgid(gid, gid, egid) != 0)
  goto error;
 if (geteuid() != getuid() || getegid() != getgid()) {
  printf("d_t: fun\n");
  goto error;
 }
 return;
error:
 printf("d_t: failure\n");
 exit(1);
}

canonical_original_code:
void drop_temporarily()
{
 int gid = getgid(); int uid = getuid();
 int egid = getegid(); int euid = geteuid();
 if (setresuid(uid, uid, euid) != 0)
  goto error;
 if (setresgid(gid, gid, egid) != 0)
  goto error;
 if (geteuid() != getuid() || getegid() != getgid()) {
  printf("d_t: fun\n");
  goto error;
 }
 return;
error:
 printf("d_t: failure\n");
 exit(1);
}


decompiled_code:
__gid_t drop_pernamently()
{
__gid_t v0; // ebp
__uid_t v1; // eax
__uid_t v2; // ebp
__gid_t v3; // ebp
__gid_t result; // eax

v0 = getgid();
v1 = getuid();
if ( setresuid(v1, v1, v1) || setresgid(v0, v0, v0) )
{
LABEL_6:
puts("d_p: failure");
exit(1);
}
v2 = geteuid();
if ( v2 != getuid() || (v3 = getegid(), result = getgid(), v3 != result) )
{
puts("d_t: fun");
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
__gid_t func11()
{
__gid_t v0; // ebp
__uid_t v1; // eax
__uid_t v2; // ebp
__gid_t v3; // ebp
__gid_t result; // eax

v0 = getgid();
v1 = getuid();
if ( setresuid(v1, v1, v1) || setresgid(v0, v0, v0) )
{
LABEL_6:
puts("d_p: failure");
exit(1);
}
v2 = geteuid();
if ( v2 != getuid() || (v3 = getegid(), result = getgid(), v3 != result) )
{
puts("d_t: fun");
goto LABEL_6;
}
return result;
}

original_code:
void drop_pernamently(void)
{
 const int gid = getgid(), uid = getuid();
 if (setresuid(uid, uid, uid) != 0)
  goto error;
 if (setresgid(gid, gid, gid) != 0)
  goto error;
 if (geteuid() != getuid() || getegid() != getgid()) {
  printf("d_t: fun\n");
  goto error;
 }
 return;
error:
 printf("d_p: failure\n");
 exit(1);
}

canonical_original_code:
void drop_pernamently()
{
 int gid = getgid(); int uid = getuid();
 if (setresuid(uid, uid, uid) != 0)
  goto error;
 if (setresgid(gid, gid, gid) != 0)
  goto error;
 if (geteuid() != getuid() || getegid() != getgid()) {
  printf("d_t: fun\n");
  goto error;
 }
 return;
error:
 printf("d_p: failure\n");
 exit(1);
}


restore

decompiled_code:
__gid_t restore()
{
__uid_t v0; // ebx
__gid_t v1; // ebp
__gid_t result; // eax

v0 = set_uid;
if ( setresuid(real_uid, set_uid, set_uid) || (v1 = set_gid, setresgid(real_gid, set_gid, set_gid)) )
{
LABEL_6:
puts("d_p: failure");
exit(1);
}
if ( v0 != geteuid() || (result = getegid(), v1 != result) )
{
puts("d_t: fun");
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
__gid_t func12()
{
__uid_t v0; // ebx
__gid_t v1; // ebp
__gid_t result; // eax

v0 = set_uid;
if ( setresuid(real_uid, set_uid, set_uid) || (v1 = set_gid, setresgid(real_gid, set_gid, set_gid)) )
{
LABEL_6:
puts("d_p: failure");
exit(1);
}
if ( v0 != geteuid() || (result = getegid(), v1 != result) )
{
puts("d_t: fun");
goto LABEL_6;
}
return result;
}

original_code:
void restore(void)
{
 if (setresuid(real_uid, set_uid, set_uid) != 0)
  goto error;
 if (setresgid(real_gid, set_gid, set_gid) != 0)
  goto error;
 if (geteuid() != set_uid || getegid() != set_gid) {
  printf("d_t: fun\n");
  goto error;
 }
 return;
error:
 printf("d_p: failure\n");
 exit(1);
}

canonical_original_code:
void restore()
{
 if (setresuid(real_uid, set_uid, set_uid) != 0)
  goto error;
 if (setresgid(real_gid, set_gid, set_gid) != 0)
  goto error;
 if (geteuid() != set_uid || getegid() != set_gid) {
  printf("d_t: fun\n");
  goto error;
 }
 return;
error:
 printf("d_p: failure\n");
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
clearenv();
init(argc, argv);
printf("Initial: ");
print();
check_perms();
puts("* TEMPORARY DROP ");
drop_temporarily();
check_perms();
puts("* RESTORE ");
restore();
check_perms();
puts("* PERNAMENT DROP ");
drop_pernamently();
check_perms();
puts("* RESTORE (we should fail now) ");
restore();
check_perms();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
clearenv();
func7(argc, argv);
printf("Initial: ");
func8();
func9();
puts("* TEMPORARY DROP ");
func10();
func9();
puts("* RESTORE ");
func12();
func9();
puts("* PERNAMENT DROP ");
func11();
func9();
puts("* RESTORE (we should fail now) ");
func12();
func9();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 clearenv();
 init();
 printf("Initial: ");
 print();
 check_perms();
 printf("* TEMPORARY DROP \n");
 drop_temporarily();
 check_perms();
 printf("* RESTORE \n");
 restore();
 check_perms();
 printf("* PERNAMENT DROP \n");
 drop_pernamently();
 check_perms();
 printf("* RESTORE (we should fail now) \n");
 restore();
 check_perms();
 return 0;
}


conversation

decompiled_code:
__int64 __fastcall conversation(int a1, int **a2, _QWORD *a3, const char *a4)
{
int *v7; // rdx
int v8; // eax
_DWORD *v9; // rax
_DWORD *v10; // rbx
char *v11; // rax

if ( a1 != 1 )
{
puts("Num_msg should always be one in this test!");
return 1LL;
}
puts("Conversation:");
v7 = *a2;
v8 = **a2;
if ( v8 == 3 )
{
printf("\terror msg: ");
v7 = *a2;
}
else if ( v8 > 3 )
{
if ( v8 == 4 )
{
printf("\ttext info: ");
v7 = *a2;
}
}
else if ( v8 == 1 )
{
printf("\tprompt noecho: ");
v7 = *a2;
}
else if ( v8 == 2 )
{
printf("\tprompt echo: ");
v7 = *a2;
}
puts(*((const char **)v7 + 1));
if ( (unsigned int)(**a2 - 1) > 1 )
goto LABEL_13;
if ( *a3 )
puts("**** STRANGE ****");
v9 = malloc(0x10uLL);
*a3 = v9;
v10 = v9;
if ( v9 )
{
printf("\tResponding with: %s\n", a4);
v11 = strdup(a4);
v10[2] = 0;
*(_QWORD *)v10 = v11;
LABEL_13:
puts("\tConversation finished");
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int **a2, _QWORD *a3, const char *a4)
{
int *v7; // rdx
int v8; // eax
_DWORD *v9; // rax
_DWORD *v10; // rbx
char *v11; // rax

if ( a1 != 1 )
{
puts("Num_msg should always be one in this test!");
return 1LL;
}
puts("Conversation:");
v7 = *a2;
v8 = **a2;
if ( v8 == 3 )
{
printf("\terror msg: ");
v7 = *a2;
}
else if ( v8 > 3 )
{
if ( v8 == 4 )
{
printf("\ttext info: ");
v7 = *a2;
}
}
else if ( v8 == 1 )
{
printf("\tprompt noecho: ");
v7 = *a2;
}
else if ( v8 == 2 )
{
printf("\tprompt echo: ");
v7 = *a2;
}
puts(*((const char **)v7 + 1));
if ( (unsigned int)(**a2 - 1) > 1 )
goto LABEL_13;
if ( *a3 )
puts("**** STRANGE ****");
v9 = malloc(0x10uLL);
*a3 = v9;
v10 = v9;
if ( v9 )
{
printf("\tResponding with: %s\n", a4);
v11 = strdup(a4);
v10[2] = 0;
*(_QWORD *)v10 = v11;
LABEL_13:
puts("\tConversation finished");
return 0LL;
}
return 1LL;
}

original_code:
int conversation(int num_msg, const struct pam_message **msg,
   struct pam_response **resp, void *appdata_ptr)
{
 if (num_msg != 1) {
  printf("Num_msg should always be one in this test!\n");
  return 1;
 }
 printf("Conversation:\n");
 switch (msg[0]->msg_style) {
 case 2:
  printf("\tprompt echo: ");
  break;
 case 1:
  printf("\tprompt noecho: ");
  break;
 case 3:
  printf("\terror msg: ");
  break;
 case 4:
  printf("\ttext info: ");
  break;
 }
 printf("%s\n", msg[0]->msg);
 if (msg[0]->msg_style == 2 ||
     msg[0]->msg_style == 1) {
      const char *reply = (const char *)appdata_ptr;
      struct pam_response *r;
      if (*resp) {
       printf("**** STRANGE ****\n");
      }
      r = *resp = malloc(sizeof(*r));
      if (!r)
       return 1;
      printf("\tResponding with: %s\n", reply);
      r->resp = strdup(reply);
      r->resp_retcode = 0;
     }
 printf("\tConversation finished\n");
 return 0;
}

canonical_original_code:
int conversation(int num_msg, struct pam_message **msg, struct pam_response **resp, void *appdata_ptr)
{
 if (num_msg != 1) {
  printf("Num_msg should always be one in this test!\n");
  return 1;
 }
 printf("Conversation:\n");
 switch (msg[0]->msg_style) {
 case 2:
  printf("\tprompt echo: ");
  break;
 case 1:
  printf("\tprompt noecho: ");
  break;
 case 3:
  printf("\terror msg: ");
  break;
 case 4:
  printf("\ttext info: ");
  break;
 }
 printf("%s\n", msg[0]->msg);
 if (msg[0]->msg_style == 2 ||
     msg[0]->msg_style == 1) {
      char *reply = (const char *)appdata_ptr;
      struct pam_response *r;
      if (*resp) {
       printf("**** STRANGE ****\n");
      }
      r = *resp = malloc(sizeof(*r));
      if (!r)
       return 1;
      printf("\tResponding with: %s\n", reply);
      r->resp = strdup(reply);
      r->resp_retcode = 0;
     }
 printf("\tConversation finished\n");
 return 0;
}

variable_types: struct pam_message { int msg_style; char *msg; } **

variable_types: struct pam_response { char *resp; int resp_retcode; } **

variable_types:
reply
char *


main

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

if ( argc <= 2 )
{
v4 = 1;
printf("Usage: %s <user for auth> <correct code>\n", *argv);
}
else
{
puts("Two authentication will be done. First should succeed,\nsecond should fail. You'd better run it as root.\n");
puts("Should succeed:");
v3 = authenticate(argv[1], argv[2]);
v4 = v3;
if ( v3 )
{
v4 = 1;
printf("*** Correct auth testcase failed (%d)\n", v3);
}
else
{
puts("*** CORRECT AUTH SUCCEDDED");
}
puts("\n\nShould fail:");
if ( (unsigned int)authenticate(argv[1], "failedfailedfailed") )
{
puts("*** SHOULD-FAIL AUTH SUCCEDDED (that is - we got rejected)");
}
else
{
++v4;
printf("*** Should-fail auth testcase failed (because we got authenticated) (%d)\n", 0LL);
}
}
return v4;
}

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

if ( argc <= 2 )
{
v4 = 1;
printf("Usage: %s <user for auth> <correct code>\n", *argv);
}
else
{
puts("Two authentication will be done. First should succeed,\nsecond should fail. You'd better run it as root.\n");
puts("Should succeed:");
v3 = func8(argv[1], argv[2]);
v4 = v3;
if ( v3 )
{
v4 = 1;
printf("*** Correct auth testcase failed (%d)\n", v3);
}
else
{
puts("*** CORRECT AUTH SUCCEDDED");
}
puts("\n\nShould fail:");
if ( (unsigned int)func8(argv[1], "failedfailedfailed") )
{
puts("*** SHOULD-FAIL AUTH SUCCEDDED (that is - we got rejected)");
}
else
{
++v4;
printf("*** Should-fail auth testcase failed (because we got authenticated) (%d)\n", 0LL);
}
}
return v4;
}

original_code:
int main(int argc, char **argv)
{
 int ret, retval;
 if (argc < 3) {
  printf("Usage: %s <user for auth> <correct code>\n", argv[0]);
  return 1;
 }
 ret = 0;
 printf( "Two authentication will be done. First should succeed,\n"
  "second should fail. You'd better run it as root.\n\n");
 printf("Should succeed:\n");
 retval = authenticate(argv[1], argv[2]);
 if (retval != 0) {
  printf("*** Correct auth testcase failed (%d)\n", retval);
  ret++;
 } else {
  printf("*** CORRECT AUTH SUCCEDDED\n");
 }
 printf("\n\nShould fail:\n");
 retval = authenticate(argv[1], "failedfailedfailed");
 if (retval == 0) {
  printf("*** Should-fail auth testcase failed (because we got authenticated) (%d)\n", retval);
  ret++;
 } else {
  printf("*** SHOULD-FAIL AUTH SUCCEDDED (that is - we got rejected)\n");
 }
 return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int ret; int retval;
 if (argc < 3) {
  printf("Usage: %s <user for auth> <correct code>\n", argv[0]);
  return 1;
 }
 ret = 0;
 printf( "Two authentication will be done. First should succeed,\n"
  "second should fail. You'd better run it as root.\n\n");
 printf("Should succeed:\n");
 retval = authenticate(argv[1], argv[2]);
 if (retval != 0) {
  printf("*** Correct auth testcase failed (%d)\n", retval);
  ret++;
 } else {
  printf("*** CORRECT AUTH SUCCEDDED\n");
 }
 printf("\n\nShould fail:\n");
 retval = authenticate(argv[1], "failedfailedfailed");
 if (retval == 0) {
  printf("*** Should-fail auth testcase failed (because we got authenticated) (%d)\n", retval);
  ret++;
 } else {
  printf("*** SHOULD-FAIL AUTH SUCCEDDED (that is - we got rejected)\n");
 }
 return ret;
}

variable_types: retval int


cfib

decompiled_code:
__int64 __fastcall cfib(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax

if ( lessp(a1, my_two) )
return a1;
v2 = difference(a1, my_two);
v3 = cfib(v2);
v4 = difference(a1, my_one);
v5 = cfib(v4);
return plus(v5, v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax

if ( lessp(a1, my_two) )
return a1;
v2 = difference(a1, my_two);
v3 = func0(v2);
v4 = difference(a1, my_one);
v5 = func0(v4);
return plus(v5, v3);
}

original_code:
LISP cfib(LISP x)
{
    if ((lessp(x,my_two)) != (((struct obj *) 0)))
        return(x);
    else
        return(plus(cfib(difference(x,my_one)),
                    cfib(difference(x,my_two))));
}

canonical_original_code:
struct obj *cfib(struct obj *x)
{
    if ((lessp(x,my_two)) != (((struct obj *) 0)))
        return(x);
    else
        return(plus(cfib(difference(x,my_one)),
                    cfib(difference(x,my_two))));
}

variable_types:
x
struct obj *

return_type: struct obj { short gc_mark; short type; union { struct { struct obj *car; struct obj *cdr; } cons; struct { double data; } flonum; struct { char *pname; struct obj *vcell; } symbol; struct { char *name; struct obj *(*f)(); } subr; struct { struct obj *env; struct obj *code; } closure; } storage_as; } *


decompiled_code:
__int64 our_subrs()
{
my_one = flocons(1.0);
my_two = flocons(2.0);
gc_protect(&my_one);
gc_protect(&my_two);
return init_subr("cfib", 5LL, cfib);
}

canonical_decompiled_code:
__int64 func1()
{
my_one = flocons(1.0);
my_two = flocons(2.0);
gc_protect(&my_one);
gc_protect(&my_two);
return init_subr("cfib", 5LL, cfib);
}

original_code:
void our_subrs(void)
{
    my_one = flocons((double) 1.0);
    my_two = flocons((double) 2.0);
    gc_protect(&my_one);
    gc_protect(&my_two);
    init_subr("cfib",5,cfib);
}

canonical_original_code:
void our_subrs()
{
    my_one = flocons((double) 1.0);
    my_two = flocons((double) 2.0);
    gc_protect(&my_one);
    gc_protect(&my_two);
    init_subr("cfib",5,cfib);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
print_welcome(argc, argv, envp);
process_cla((unsigned int)argc, argv);
print_hs_1();
init_storage();
init_subrs();
our_subrs();
repl_driver();
puts("EXIT");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
print_welcome(argc, argv, envp);
process_cla((unsigned int)argc, argv);
print_hs_1();
init_storage();
init_subrs();
func1();
repl_driver();
puts("EXIT");
return 0;
}

original_code:
int main(int argc,char **argv)
{
    print_welcome();
    process_cla(argc,argv);
    print_hs_1();
    init_storage();
    init_subrs();
    our_subrs();
    repl_driver();
    printf("EXIT\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    print_welcome();
    process_cla(argc,argv);
    print_hs_1();
    init_storage();
    init_subrs();
    our_subrs();
    repl_driver();
    printf("EXIT\n");
 return 0;
}


usage

decompiled_code:
size_t usage()
{
return fwrite(
"USAGE: ./brutehttp Host [Dict]\n"
" Host : The website hostname. ex: www.google.com\n"
" Dict : The dictionary. ex: dict.txt\n",
1uLL,
0x7DuLL,
stderr);
}

canonical_decompiled_code:
size_t func7()
{
return fwrite(
"USAGE: ./brutehttp Host [Dict]\n"
" Host : The website hostname. ex: www.google.com\n"
" Dict : The dictionary. ex: dict.txt\n",
1uLL,
0x7DuLL,
stderr);
}

original_code:
static void usage(void)
{
  fprintf(stderr, "USAGE: ./brutehttp Host [Dict]\n  Host : The website hostname. ex: www.google.com\n  Dict : The dictionary.       ex: dict.txt\n");
}

canonical_original_code:
static void usage()
{
  fprintf(stderr, "USAGE: ./brutehttp Host [Dict]\n  Host : The website hostname. ex: www.google.com\n  Dict : The dictionary.       ex: dict.txt\n");
}


gethost

decompiled_code:
char *__fastcall gethost(char *s)
{
char *v1; // rax

if ( !strchr(s, 58) )
return strtok(s, "/");
strtok(s, ":");
v1 = strtok(0LL, ":");
return strtok(v1, "/");
}

canonical_decompiled_code:
char *__fastcall func9(char *s)
{
char *v1; // rax

if ( !strchr(s, 58) )
return strtok(s, "/");
strtok(s, ":");
v1 = strtok(0LL, ":");
return strtok(v1, "/");
}

original_code:
char* gethost(char* url)
{
  if (strstr(url, ":"))
  {
    char *host = strtok(url, ":");
    host = strtok(((void *)0), ":");
    return strtok(host, "/");
  }
  else
  {
    return strtok(url, "/");
  }
}

canonical_original_code:
char *gethost(char *url)
{
  if (strstr(url, ":"))
  {
    char *host = strtok(url, ":");
    host = strtok(((void *)0), ":");
    return strtok(host, "/");
  }
  else
  {
    return strtok(url, "/");
  }
}

variable_types:
url
char *

variable_types:
host
char *


repo: blackball/cgdl

decompiled_code:
void __fastcall mat_free(void **a1)
{
if ( a1 )
{
if ( *a1 )
{
free(*((void **)*a1 + 1));
free(*a1);
*a1 = 0LL;
}
}
}

original_code:
void
mat_free(struct mat_t **m) {
        if (m && (*m)) {
                free( (*m)->data );
                free( *m );
                *m = ((void *)0);
        }
}

variable_types: struct mat_t { int rows; double *data; } **


original_code:
void
mat_set(struct mat_t *m, double v) {
        if (m) {
                int i,j;
                for (i = 0; i < m->rows; ++i) {
                        for (j = 0; j < m->cols; ++j) {
                                m->data[i * m->cols + j] = v;
                        }
                }
        }
}

canonical_original_code:
void mat_set(struct mat_t *m, double v) {
        if (m) {
                int i; int j;
                for (i = 0; i < m->rows; ++i) {
                        for (j = 0; j < m->cols; ++j) {
                                m->data[i * m->cols + j] = v;
                        }
                }
        }
}

variable_types: struct mat_t { int rows; double *data; } *

variable_types: v double

variable_types: i int

variable_types: j int


decompiled_code:
double __fastcall mat_sum_col(__int64 a1, int a2)
{
__int64 v2; // rcx
__int64 v3; // rcx
double result; // xmm0_8
double *v5; // rdx
int v6; // eax

v2 = *(int *)(a1 + 4);
if ( (int)v2 <= a2 )
_assert_fail("col < m->cols", "mat.c", 0x2Eu, "mat_sum_col");
if ( *(int *)a1 <= 0 )
return 0.0;
v3 = 8 * v2;
result = 0.0;
v5 = (double *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
v6 = 0;
do
{
++v6;
result = result + *v5;
v5 = (double *)((char *)v5 + v3);
}
while ( v6 != *(_DWORD *)a1 );
return result;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rcx
__int64 v3; // rcx
double result; // xmm0_8
double *v5; // rdx
int v6; // eax

v2 = *(int *)(a1 + 4);
if ( (int)v2 <= a2 )
_assert_fail("col < m->cols", "mat.c", 0x2Eu, "mat_sum_col");
if ( *(int *)a1 <= 0 )
return 0.0;
v3 = 8 * v2;
result = 0.0;
v5 = (double *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
v6 = 0;
do
{
++v6;
result = result + *v5;
v5 = (double *)((char *)v5 + v3);
}
while ( v6 != *(_DWORD *)a1 );
return result;
}

original_code:
double
mat_sum_col(const struct mat_t *m, int col) {
        double sum = .0;
        int i = 0;
        ((void) sizeof ((col < m->cols) ? 1 : 0), __extension__ ({ if (col < m->cols) ; else __assert_fail ("col < m->cols", "mat.c", 46, __extension__ __PRETTY_FUNCTION__); }));
        for (; i < m->rows; ++i) {
                sum += m->data[i * m->cols + col];
        }
        return sum;
}

canonical_original_code:
double mat_sum_col(struct mat_t *m, int col) {
        double sum = .0;
        int i = 0;
        ((void) sizeof ((col < m->cols) ? 1 : 0), __extension__ ({ if (col < m->cols) ; else __assert_fail ("col < m->cols", "mat.c", 46, __extension__ __PRETTY_FUNCTION__); }));
        for (; i < m->rows; ++i) {
                sum += m->data[i * m->cols + col];
        }
        return sum;
}

variable_types: col int

variable_types: sum double

return_type: double

user_defined_types: struct mat_t { int rows; double *data; }


decompiled_code:
double __fastcall mat_sum_row(__int64 a1, int a2)
{
int v2; // edx
int v3; // esi
__int64 v4; // rcx
double result; // xmm0_8
double *v6; // rax
__int64 v7; // rdx

if ( *(_DWORD *)a1 <= a2 )
_assert_fail("row < m->rows", "mat.c", 0x3Au, "mat_sum_row");
v2 = *(_DWORD *)(a1 + 4);
if ( v2 <= 0 )
return 0.0;
v3 = v2 * a2;
v4 = *(_QWORD *)(a1 + 8);
result = 0.0;
v6 = (double *)(v4 + 8LL * v3);
v7 = v4 + 8 * ((unsigned int)(v2 - 1) + (__int64)v3) + 8;
do
result = result + *v6++;
while ( v6 != (double *)v7 );
return result;
}

canonical_decompiled_code:
double __fastcall func3(__int64 a1, int a2)
{
int v2; // edx
int v3; // esi
__int64 v4; // rcx
double result; // xmm0_8
double *v6; // rax
__int64 v7; // rdx

if ( *(_DWORD *)a1 <= a2 )
_assert_fail("row < m->rows", "mat.c", 0x3Au, "mat_sum_row");
v2 = *(_DWORD *)(a1 + 4);
if ( v2 <= 0 )
return 0.0;
v3 = v2 * a2;
v4 = *(_QWORD *)(a1 + 8);
result = 0.0;
v6 = (double *)(v4 + 8LL * v3);
v7 = v4 + 8 * ((unsigned int)(v2 - 1) + (__int64)v3) + 8;
do
result = result + *v6++;
while ( v6 != (double *)v7 );
return result;
}

original_code:
double
mat_sum_row(const struct mat_t *m, int row) {
        double sum = .0;
        int i = 0;
        ((void) sizeof ((row < m->rows) ? 1 : 0), __extension__ ({ if (row < m->rows) ; else __assert_fail ("row < m->rows", "mat.c", 58, __extension__ __PRETTY_FUNCTION__); }));
        for (; i < m->cols; ++i) {
                sum += m->data[ row * m->cols + i];
        }
        return sum;
}

canonical_original_code:
double mat_sum_row(struct mat_t *m, int row) {
        double sum = .0;
        int i = 0;
        ((void) sizeof ((row < m->rows) ? 1 : 0), __extension__ ({ if (row < m->rows) ; else __assert_fail ("row < m->rows", "mat.c", 58, __extension__ __PRETTY_FUNCTION__); }));
        for (; i < m->cols; ++i) {
                sum += m->data[ row * m->cols + i];
        }
        return sum;
}

variable_types: row int


original_code:
void
mat_print(const struct mat_t *m) {
        int i, j;
        if (!m) {
                return ;
        }
        for (i = 0; i < m->rows; ++i) {
                for (j = 0; j < m->cols; ++j) {
                        printf("%lf ", ((m)->data[(i) * (m)->cols + (j)]));
                }
                printf("\n");
        }
}

canonical_original_code:
void mat_print(struct mat_t *m) {
        int i; int j;
        if (!m) {
                return ;
        }
        for (i = 0; i < m->rows; ++i) {
                for (j = 0; j < m->cols; ++j) {
                        printf("%lf ", ((m)->data[(i) * (m)->cols + (j)]));
                }
                printf("\n");
        }
}


repo: blackball/vpack

decompiled_code:
__int64 vpack_getendian()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0LL;
}

original_code:
static char
vpack_getendian() {
        int i = 1;
        return ( (*(char*)&i) == 0 ) ? 0xff : 0x00;
}

canonical_original_code:
static char vpack_getendian() {
        int i = 1;
        return ( (*(char *)&i) == 0 ) ? 0xff : 0x00;
}

return_type: char


decompiled_code:
__int64 __fastcall vpack_checkguard(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl

if ( *(_BYTE *)(a1 + 6) == *(_BYTE *)(a2 + 6) )
{
v2 = 0LL;
while ( 1 )
{
v3 = *(_BYTE *)(a1 + v2);
if ( v3 )
{
if ( v3 != *(_BYTE *)(a2 + v2) )
break;
}
if ( ++v2 == 6 )
return 0LL;
}
}
return 0xFFFFFFFFLL;
}

original_code:
static int
vpack_checkguard(struct _vguard *file, struct _vguard *local) {
        int i;
        if (file->flags[6] != local->flags[6])
                return -1;
        for (i = 0; i < 6; ++i)
                if (file->flags[i] != 0 &&
                    file->flags[i] != local->flags[i])
                        return -1;
        return 0;
}

variable_types:
file
struct _vguard { char flags[8]; } *

variable_types:
local
struct _vguard *


decompiled_code:
char *__fastcall vpack_cplong(void **a1, const void **a2, int a3, int a4)
{
size_t v5; // rbx
char *v6; // r14
char *result; // rax

v5 = 8LL * a3;
v6 = (char *)*a2;
result = (char *)memcpy(*a1, *a2, v5);
if ( a4 )
*a2 = &v6[v5];
else
*a1 = &result[v5];
return result;
}

canonical_decompiled_code:
char *__fastcall func9(void **a1, const void **a2, int a3, int a4)
{
size_t v5; // rbx
char *v6; // r14
char *result; // rax

v5 = 8LL * a3;
v6 = (char *)*a2;
result = (char *)memcpy(*a1, *a2, v5);
if ( a4 )
*a2 = &v6[v5];
else
*a1 = &result[v5];
return result;
}

original_code: static void vpack_cplong(void **dst, void **src, int n, int icrwho) { long *pd = (long*)(*dst); long *ps = (long*)(*src); memcpy(*dst, *src, sizeof(long)*n); if (icrwho) *src = (void*)(ps + n); else *dst = (void*)(pd + n); }

canonical_original_code: static void vpack_cplong(void **dst, void **src, int n, int icrwho) { long *pd = (long*)(*dst); long *ps = (long*)(*src); memcpy(*dst, *src, sizeof(long)*n); if (icrwho) *src = (void *)(ps + n); else *dst = (void *)(pd + n); }

variable_types:
dst
void **

variable_types:
src
void **

variable_types: n int

variable_types: icrwho int

variable_types:
pd
long *

variable_types:
ps
long *


decompiled_code:
// attributes: thunk
char *__fastcall vpack_cpdouble(void **a1, const void **a2, int a3, int a4)
{
return vpack_cplong(a1, a2, a3, a4);
}

canonical_decompiled_code:
char *__fastcall func10(void **a1, const void **a2, int a3, int a4)
{
return func9(a1, a2, a3, a4);
}

original_code: static void vpack_cpdouble(void **dst, void **src, int n, int icrwho) { double *pd = (double*)(*dst); double *ps = (double*)(*src); memcpy(*dst, *src, sizeof(double)*n); if (icrwho) *src = (void*)(ps + n); else *dst = (void*)(pd + n); }

canonical_original_code: static void vpack_cpdouble(void **dst, void **src, int n, int icrwho) { double *pd = (double*)(*dst); double *ps = (double*)(*src); memcpy(*dst, *src, sizeof(double)*n); if (icrwho) *src = (void *)(ps + n); else *dst = (void *)(pd + n); }

variable_types:
pd
double *

variable_types:
ps
double *


decompiled_code:
char *__fastcall vpack_cpint(void **a1, const void **a2, int a3, int a4)
{
size_t v5; // rbx
char *v6; // r14
char *result; // rax

v5 = 4LL * a3;
v6 = (char *)*a2;
result = (char *)memcpy(*a1, *a2, v5);
if ( a4 )
*a2 = &v6[v5];
else
*a1 = &result[v5];
return result;
}

canonical_decompiled_code:
char *__fastcall func11(void **a1, const void **a2, int a3, int a4)
{
size_t v5; // rbx
char *v6; // r14
char *result; // rax

v5 = 4LL * a3;
v6 = (char *)*a2;
result = (char *)memcpy(*a1, *a2, v5);
if ( a4 )
*a2 = &v6[v5];
else
*a1 = &result[v5];
return result;
}

original_code: static void vpack_cpint(void **dst, void **src, int n, int icrwho) { int *pd = (int*)(*dst); int *ps = (int*)(*src); memcpy(*dst, *src, sizeof(int)*n); if (icrwho) *src = (void*)(ps + n); else *dst = (void*)(pd + n); }

canonical_original_code: static void vpack_cpint(void **dst, void **src, int n, int icrwho) { int *pd = (int*)(*dst); int *ps = (int*)(*src); memcpy(*dst, *src, sizeof(int)*n); if (icrwho) *src = (void *)(ps + n); else *dst = (void *)(pd + n); }

variable_types:
pd
int *

variable_types:
ps
int *


decompiled_code:
// attributes: thunk
char *__fastcall vpack_cpfloat(void **a1, const void **a2, int a3, int a4)
{
return vpack_cpint(a1, a2, a3, a4);
}

canonical_decompiled_code:
char *__fastcall func12(void **a1, const void **a2, int a3, int a4)
{
return func11(a1, a2, a3, a4);
}

original_code: static void vpack_cpfloat(void **dst, void **src, int n, int icrwho) { float *pd = (float*)(*dst); float *ps = (float*)(*src); memcpy(*dst, *src, sizeof(float)*n); if (icrwho) *src = (void*)(ps + n); else *dst = (void*)(pd + n); }

canonical_original_code: static void vpack_cpfloat(void **dst, void **src, int n, int icrwho) { float *pd = (float*)(*dst); float *ps = (float*)(*src); memcpy(*dst, *src, sizeof(float)*n); if (icrwho) *src = (void *)(ps + n); else *dst = (void *)(pd + n); }

variable_types:
pd
float *

variable_types:
ps
float *


decompiled_code:
char *__fastcall vpack_cpshort(void **a1, const void **a2, int a3, int a4)
{
size_t v5; // rbx
char *v6; // r14
char *result; // rax

v5 = 2LL * a3;
v6 = (char *)*a2;
result = (char *)memcpy(*a1, *a2, v5);
if ( a4 )
*a2 = &v6[v5];
else
*a1 = &result[v5];
return result;
}

canonical_decompiled_code:
char *__fastcall func13(void **a1, const void **a2, int a3, int a4)
{
size_t v5; // rbx
char *v6; // r14
char *result; // rax

v5 = 2LL * a3;
v6 = (char *)*a2;
result = (char *)memcpy(*a1, *a2, v5);
if ( a4 )
*a2 = &v6[v5];
else
*a1 = &result[v5];
return result;
}

original_code: static void vpack_cpshort(void **dst, void **src, int n, int icrwho) { short *pd = (short*)(*dst); short *ps = (short*)(*src); memcpy(*dst, *src, sizeof(short)*n); if (icrwho) *src = (void*)(ps + n); else *dst = (void*)(pd + n); }

canonical_original_code: static void vpack_cpshort(void **dst, void **src, int n, int icrwho) { short *pd = (short*)(*dst); short *ps = (short*)(*src); memcpy(*dst, *src, sizeof(short)*n); if (icrwho) *src = (void *)(ps + n); else *dst = (void *)(pd + n); }

variable_types:
pd
short *

variable_types:
ps
short *


decompiled_code:
char *__fastcall vpack_cpchar(void **a1, const void **a2, int a3, int a4)
{
__int64 v5; // rbx
char *v6; // r14
char *result; // rax

v5 = a3;
v6 = (char *)*a2;
result = (char *)memcpy(*a1, *a2, a3);
if ( a4 )
*a2 = &v6[v5];
else
*a1 = &result[v5];
return result;
}

canonical_decompiled_code:
char *__fastcall func14(void **a1, const void **a2, int a3, int a4)
{
__int64 v5; // rbx
char *v6; // r14
char *result; // rax

v5 = a3;
v6 = (char *)*a2;
result = (char *)memcpy(*a1, *a2, a3);
if ( a4 )
*a2 = &v6[v5];
else
*a1 = &result[v5];
return result;
}

original_code: static void vpack_cpchar(void **dst, void **src, int n, int icrwho) { char *pd = (char*)(*dst); char *ps = (char*)(*src); memcpy(*dst, *src, sizeof(char)*n); if (icrwho) *src = (void*)(ps + n); else *dst = (void*)(pd + n); }

canonical_original_code: static void vpack_cpchar(void **dst, void **src, int n, int icrwho) { char *pd = (char*)(*dst); char *ps = (char*)(*src); memcpy(*dst, *src, sizeof(char)*n); if (icrwho) *src = (void *)(ps + n); else *dst = (void *)(pd + n); }

variable_types:
pd
char *

variable_types:
ps
char *


original_code:
int world_border_detection(SDL_Rect *offset) {
 int detected = 0;
 if((offset->x + 640) > world->landscape->w) {
  offset->x = (world->landscape->w / 2) - (get_screen()->w / 2);
  world->player->x -= 30;
  detected = 1;
 }
 if((offset->y + 480) > world->landscape->h) {
  offset->y = (world->landscape->h/ 2) - (get_screen()->h / 2);
  world->player->y -= 30;
  detected = 1;
 }
 if(offset->x < 0) {
  offset->x = 0;
  world->player->x += 30;
  detected = 1;
 }
 if(offset->y < 0) {
  offset->y = 0;
  world->player->y += 30;
  detected = 1;
 }
 return detected;
}

canonical_original_code:
int world_border_detection(struct SDL_Rect *offset) {
 int detected = 0;
 if((offset->x + 640) > world->landscape->w) {
  offset->x = (world->landscape->w / 2) - (get_screen()->w / 2);
  world->player->x -= 30;
  detected = 1;
 }
 if((offset->y + 480) > world->landscape->h) {
  offset->y = (world->landscape->h/ 2) - (get_screen()->h / 2);
  world->player->y -= 30;
  detected = 1;
 }
 if(offset->x < 0) {
  offset->x = 0;
  world->player->x += 30;
  detected = 1;
 }
 if(offset->y < 0) {
  offset->y = 0;
  world->player->y += 30;
  detected = 1;
 }
 return detected;
}

variable_types: struct SDL_Rect { short x; unsigned short w; } *

variable_types: detected int


original_code:
void paint_world() {
 SDL_FillRect(get_screen(), &get_screen()->clip_rect, SDL_MapRGB( get_screen()->format, 0xFF, 0xFF, 0xFF ) );
 SDL_Rect offset;
 offset.x = (world->landscape->w / 2) - (get_screen()->w / 2) + world->player->x;
 offset.y = (world->landscape->h / 2) - (get_screen()->h / 2) + world->player->y;
 int border_detected = world_border_detection(&offset);
 offset.w = 640;
 offset.h = 480;
 apply_surface(&offset, ((void *)0), world->landscape, get_screen());
 if(border_detected) {
  offset.x = (get_screen()->w / 2) - (world->player->surface->w / 2);
  offset.y = (get_screen()->h / 2) - (world->player->surface->h / 2);
 } else {
  offset.x = (get_screen()->w / 2) - (world->player->surface->w / 2);
  offset.y = (get_screen()->h / 2) - (world->player->surface->h / 2);
 }
 apply_surface(((void *)0), &offset, world->player->surface, get_screen());
 SDL_Flip(get_screen());
}

canonical_original_code:
void paint_world() {
 SDL_FillRect(get_screen(), &get_screen()->clip_rect, SDL_MapRGB( get_screen()->format, 0xFF, 0xFF, 0xFF ) );
 struct SDL_Rect offset;
 offset.x = (world->landscape->w / 2) - (get_screen()->w / 2) + world->player->x;
 offset.y = (world->landscape->h / 2) - (get_screen()->h / 2) + world->player->y;
 int border_detected = world_border_detection(&offset);
 offset.w = 640;
 offset.h = 480;
 apply_surface(&offset, ((void *)0), world->landscape, get_screen());
 if(border_detected) {
  offset.x = (get_screen()->w / 2) - (world->player->surface->w / 2);
  offset.y = (get_screen()->h / 2) - (world->player->surface->h / 2);
 } else {
  offset.x = (get_screen()->w / 2) - (world->player->surface->w / 2);
  offset.y = (get_screen()->h / 2) - (world->player->surface->h / 2);
 }
 apply_surface(((void *)0), &offset, world->player->surface, get_screen());
 SDL_Flip(get_screen());
}

variable_types: struct SDL_Rect { short x; unsigned short w; }


decompiled_code:
__int64 init_world()
{
_QWORD *v0; // rax
__int64 result; // rax

v0 = malloc(0x18uLL);
world = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
world = (void *)load_world("../world/world_description.wd");
result = 0LL;
}
else
{
fwrite("THE UNIVERSE HAS COLLAPSED :O", 1uLL, 0x1DuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

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

v0 = malloc(0x18uLL);
world = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
world = (void *)load_world("../world/world_description.wd");
result = 0LL;
}
else
{
fwrite("THE UNIVERSE HAS COLLAPSED :O", 1uLL, 0x1DuLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int init_world() {
 world = malloc(sizeof(*world));
 if(world == ((void *)0)) {
  fprintf(stderr, "THE UNIVERSE HAS COLLAPSED :O");
  return -1;
 }
 world->landscape = ((void *)0);
 world->player = ((void *)0);
 world = load_world("../world" "/world_description.wd");
 return 0;
}


decompiled_code:
void destroy_world()
{
SDL_FreeSurface(*(_QWORD *)world);
SDL_FreeSurface(**((_QWORD **)world + 1));
free(world);
}

canonical_decompiled_code:
void func3()
{
SDL_FreeSurface(*(_QWORD *)world);
SDL_FreeSurface(**((_QWORD **)world + 1));
free(world);
}

original_code:
void destroy_world() {
 SDL_FreeSurface(world->landscape);
 SDL_FreeSurface(world->player->surface);
 free(world);
}


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

result = *((_QWORD *)world + 1);
*(_DWORD *)(result + 8) += a1;
*(_DWORD *)(result + 12) += a2;
return result;
}

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

result = *((_QWORD *)world + 1);
*(_DWORD *)(result + 8) += a1;
*(_DWORD *)(result + 12) += a2;
return result;
}

original_code:
void move_player(int x, int y) {
 world->player->x += x;
 world->player->y += y;
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 init_opengl()
{
int v0; // edi
__int64 result; // rax
const char *v2; // rax

glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, 640.0, 480.0, 0.0, 1.0, -1.0);
glMatrixMode(5888LL);
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
v0 = glGetError();
result = 1LL;
if ( v0 )
{
v2 = (const char *)gluErrorString();
printf("Error initializing OpenGL! %s\n", v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // edi
__int64 result; // rax
const char *v2; // rax

glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(0.0, 640.0, 480.0, 0.0, 1.0, -1.0);
glMatrixMode(5888LL);
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
v0 = glGetError();
result = 1LL;
if ( v0 )
{
v2 = (const char *)gluErrorString();
printf("Error initializing OpenGL! %s\n", v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int init_opengl() {
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(0.0, 640, 480, 0.0, 1.0, -1.0);
 glMatrixMode(0x1700);
 glLoadIdentity();
 glClearColor(0.f, 0.f, 0.f, 1.f);
 GLenum error = glGetError();
 if(error != 0) {
  printf( "Error initializing OpenGL! %s\n", gluErrorString(error));
  return -1;
 }
 return 1;
}

canonical_original_code:
int init_opengl() {
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(0.0, 640, 480, 0.0, 1.0, -1.0);
 glMatrixMode(0x1700);
 glLoadIdentity();
 glClearColor(0.f, 0.f, 0.f, 1.f);
 unsigned int error = glGetError();
 if(error != 0) {
  printf( "Error initializing OpenGL! %s\n", gluErrorString(error));
  return -1;
 }
 return 1;
}

variable_types:
error
unsigned int


decompiled_code:
__int64 init_screen()
{
unsigned int v0; // er12
const char *v2; // rax
const char *v3; // rax

if ( (unsigned int)SDL_Init(0xFFFFLL) == -1 )
{
v0 = -1;
v2 = (const char *)SDL_GetError();
fprintf(stderr, "SDL failed to initialize: %s\n", v2);
}
else
{
screen = SDL_SetVideoMode(640LL, 480LL, 32LL, 1LL);
if ( screen )
{
v0 = 0;
SDL_WM_SetCaption("Hello world!", 0LL);
SDL_EnableKeyRepeat(200LL, 30LL);
}
else
{
v3 = (const char *)SDL_GetError();
v0 = -1;
fprintf(stderr, "failed to initialize the screen: %s\n", v3);
}
}
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
const char *v2; // rax
const char *v3; // rax

if ( (unsigned int)SDL_Init(0xFFFFLL) == -1 )
{
v0 = -1;
v2 = (const char *)SDL_GetError();
fprintf(stderr, "SDL failed to initialize: %s\n", v2);
}
else
{
screen = SDL_SetVideoMode(640LL, 480LL, 32LL, 1LL);
if ( screen )
{
v0 = 0;
SDL_WM_SetCaption("Hello world!", 0LL);
SDL_EnableKeyRepeat(200LL, 30LL);
}
else
{
v3 = (const char *)SDL_GetError();
v0 = -1;
fprintf(stderr, "failed to initialize the screen: %s\n", v3);
}
}
return v0;
}

original_code:
int init_screen() {
 if(SDL_Init(0x0000FFFF) == -1) {
  fprintf(stderr, "SDL failed to initialize: %s\n", SDL_GetError());
  return -1;
 }
 screen = SDL_SetVideoMode(640, 480, 32, 0x00000001);
 if(screen == ((void *)0)) {
  fprintf(stderr, "failed to initialize the screen: %s\n", SDL_GetError());
  return -1;
 }
 SDL_WM_SetCaption("Hello world!", ((void *)0));
 SDL_EnableKeyRepeat(500 - 300, 30);
 return 0;
}


update

decompiled_code:
void update()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void update() {
}

canonical_original_code:
void update() {
}


render

decompiled_code:
__int64 render()
{
glClear(0x4000LL);
glMatrixMode(5888LL);
glLoadIdentity();
glTranslatef(320.0, 240.0, 0.0);
glBegin(7LL);
glColor3f(1.0, 0.0);
glVertex2f(-50.0);
glColor3f(1.0, COERCE_DOUBLE((unsigned __int64)LC5));
glVertex2f(50.0);
glColor3f(0.0, COERCE_DOUBLE((unsigned __int64)LC5));
glVertex2f(50.0);
glColor3f(0.0, 0.0);
glVertex2f(-50.0);
glEnd(-50.0, 50.0, 1.0);
return SDL_GL_SwapBuffers();
}

canonical_decompiled_code:
__int64 func6()
{
glClear(0x4000LL);
glMatrixMode(5888LL);
glLoadIdentity();
glTranslatef(320.0, 240.0, 0.0);
glBegin(7LL);
glColor3f(1.0, 0.0);
glVertex2f(-50.0);
glColor3f(1.0, COERCE_DOUBLE((unsigned __int64)LC5));
glVertex2f(50.0);
glColor3f(0.0, COERCE_DOUBLE((unsigned __int64)LC5));
glVertex2f(50.0);
glColor3f(0.0, 0.0);
glVertex2f(-50.0);
glEnd(-50.0, 50.0, 1.0);
return SDL_GL_SwapBuffers();
}

original_code:
void render() {
 glClear(0x00004000);
 glMatrixMode(0x1700);
 glLoadIdentity();
 glTranslatef(640 / 2.f, 480 / 2.f, 0.f);
 glBegin( 0x0007 );
 glColor3f(1.f, 0.f, 0.f); glVertex2f(-50.f, -50.f);
 glColor3f(1.f, 1.f, 0.f); glVertex2f(50.f, -50.f);
 glColor3f(0.f, 1.f, 0.f); glVertex2f(50.f, 50.f);
 glColor3f(0.f, 0.f, 1.f); glVertex2f(-50.f, 50.f);
 glEnd();
 SDL_GL_SwapBuffers();
}


decompiled_code:
void *__fastcall get_character_path(__int64 a1, const char *a2)
{
__int64 v2; // rax
const char *v3; // rbp
size_t v5; // r12
size_t v6; // rbx
void *v7; // r12

v2 = a1;
while ( 1 )
{
if ( !*(_QWORD *)(v2 + 8) )
return 0LL;
v3 = *(const char **)v2;
if ( !**(_BYTE **)v2 )
return 0LL;
if ( !strcmp(*(const char **)v2, "characters") )
break;
v2 += 4104LL;
if ( a1 + 0x202008000LL == v2 )
return 0LL;
}
v5 = strlen(*(const char **)v2);
strcpy((char *)&v3[v5], "/player0.png");
v6 = strlen(a2);
v7 = malloc(v5 + v6 + 12);
memcpy(v7, a2, v6);
strcpy((char *)v7 + v6, v3);
return v7;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, const char *a2)
{
__int64 v2; // rax
const char *v3; // rbp
size_t v5; // r12
size_t v6; // rbx
void *v7; // r12

v2 = a1;
while ( 1 )
{
if ( !*(_QWORD *)(v2 + 8) )
return 0LL;
v3 = *(const char **)v2;
if ( !**(_BYTE **)v2 )
return 0LL;
if ( !strcmp(*(const char **)v2, "characters") )
break;
v2 += 4104LL;
if ( a1 + 0x202008000LL == v2 )
return 0LL;
}
v5 = strlen(*(const char **)v2);
strcpy((char *)&v3[v5], "/player0.png");
v6 = strlen(a2);
v7 = malloc(v5 + v6 + 12);
memcpy(v7, a2, v6);
strcpy((char *)v7 + v6, v3);
return v7;
}

original_code:
char *get_character_path(struct parser_data *data, char *path) {
 int i;
 int size = sizeof(data->nodes);
   for(i = 0; i < size; i++) {
  if((data->nodes[i].data[0] == ((void *)0)) || (strcmp(data->nodes[i].name, "") == 0)) {
   break;
  }
  if((data->nodes[i].data[0] != ((void *)0))) {
   if(strcmp(data->nodes[i].name, "characters") == 0) {
    char *name = data->nodes[i].name;
    strcat(name, "/player0.png");
    char *pathdup = malloc(strlen(path) + strlen(name));
    strcpy(pathdup, path);
    strcat(pathdup, name);
    return pathdup;
   }
  }
 }
 return ((void *)0);
}

variable_types: struct parser_data { struct node { char *name; char *data[512]; } nodes[512]; } *

variable_types:
path
char *

variable_types: i int

variable_types: size int

variable_types:
name
char *

variable_types:
pathdup
char *

user_defined_types: struct parser_data { struct node nodes[512]; }


BufCRC

repo: blakemcbride/Dynace

decompiled_code:
__int64 __fastcall BufCRC(__int64 a1, char *a2, int a3)
{
__int64 result; // rax
__int64 v4; // rcx
char v5; // dl

result = a1;
if ( a3 > 0 )
{
v4 = (__int64)&a2[a3 - 1 + 1];
do
{
v5 = *a2++;
result = crctab[(unsigned __int8)(result ^ v5)] ^ ((unsigned int)result >> 8);
}
while ( (char *)v4 != a2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, int a3)
{
__int64 result; // rax
__int64 v4; // rcx
char v5; // dl

result = a1;
if ( a3 > 0 )
{
v4 = (__int64)&a2[a3 - 1 + 1];
do
{
v5 = *a2++;
result = crctab[(unsigned __int8)(result ^ v5)] ^ ((unsigned int)result >> 8);
}
while ( (char *)v4 != a2 );
}
return result;
}

original_code:
tcrc BufCRC(tcrc crccode, char *buf, int size)
{
 int i;
 for (i = 0 ; i < size ; i ++)
  crccode = crctab[(int) (crccode ^ buf[i]) & 0xff] ^ ((crccode >> 8) & 0x00FFFFFFL);
 return crccode;
}

canonical_original_code:
unsigned long BufCRC(unsigned long crccode, char *buf, int size)
{
 int i;
 for (i = 0 ; i < size ; i ++)
  crccode = crctab[(int) (crccode ^ buf[i]) & 0xff] ^ ((crccode >> 8) & 0x00FFFFFFL);
 return crccode;
}

variable_types:
crccode
unsigned long

variable_types:
buf
char *

return_type: unsigned long


InitCRC

decompiled_code:
__int64 InitCRC()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0xFFFFFFFFLL;
}

original_code:
tcrc InitCRC()
{
 return 0xFFFFFFFFL;
}

canonical_original_code:
unsigned long InitCRC()
{
 return 0xFFFFFFFFL;
}


findbucket

decompiled_code:
__int64 __fastcall findbucket(_QWORD *a1, int a2)
{
__int64 i; // rcx
_QWORD *v3; // rax
unsigned int v4; // er8
int v5; // edx

for ( i = 0LL; i != 30; ++i )
{
v3 = (_QWORD *)nextf[i];
v4 = i;
if ( v3 && a2 )
{
if ( v3 == a1 )
return v4;
v5 = 0;
while ( 1 )
{
v3 = (_QWORD *)*v3;
++v5;
if ( !v3 || a2 == v5 )
break;
if ( a1 == v3 )
return v4;
}
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2)
{
__int64 i; // rcx
_QWORD *v3; // rax
unsigned int v4; // er8
int v5; // edx

for ( i = 0LL; i != 30; ++i )
{
v3 = (_QWORD *)nextf[i];
v4 = i;
if ( v3 && a2 )
{
if ( v3 == a1 )
return v4;
v5 = 0;
while ( 1 )
{
v3 = (_QWORD *)*v3;
++v5;
if ( !v3 || a2 == v5 )
break;
if ( a1 == v3 )
return v4;
}
}
}
return (unsigned int)-1;
}

original_code:
static int findbucket( union overhead *freep, int srchlen )
{
 union overhead *p;
 int i, j;
 for (i = 0; i < 30; i++) {
  j = 0;
  for (p = nextf[i]; p && j != srchlen; p = p->ov_next) {
   if (p == freep)
    return (i);
   j++;
  }
 }
 return (-1);
}

canonical_original_code:
static int findbucket(union overhead *freep, int srchlen)
{
 union overhead *p;
 int i; int j;
 for (i = 0; i < 30; i++) {
  j = 0;
  for (p = nextf[i]; p && j != srchlen; p = p->ov_next) {
   if (p == freep)
    return (i);
   j++;
  }
 }
 return (-1);
}

variable_types: union overhead { union overhead *ov_next; struct { unsigned char ovu_magic; unsigned char ovu_index; } ovu; } *

variable_types: srchlen int

variable_types: j int


getBlock

decompiled_code:
__int64 __fastcall getBlock(__int64 a1)
{
__int64 v1; // rbp
_QWORD *v2; // rbx
__int64 v3; // rax
__int64 v4; // r8
__int64 v6; // rax
__int64 v7; // rdx

v1 = s_pagesz_0;
v2 = (_QWORD *)availList;
if ( !s_pagesz_0 )
{
v1 = Dynace_GetInitialPageSize();
s_pagesz_0 = Dynace_GetPageSize();
}
if ( v2 )
{
while ( 1 )
{
v3 = v2[1];
if ( v3 >= a1 )
break;
v2 = (_QWORD *)*v2;
if ( !v2 )
goto LABEL_10;
}
v4 = v2[2];
}
else
{
LABEL_10:
if ( a1 + 16 >= v1 )
v1 = a1 + 16;
v6 = Dynace_getpage(v1);
v2 = (_QWORD *)v6;
if ( !v6 )
return 0LL;
v7 = availList;
v4 = v6 + 24;
v3 = v1 - 24;
availList = (__int64)v2;
v2[2] = v2 + 3;
v2[1] = v1 - 24;
*v2 = v7;
}
v2[2] = v4 + a1;
v2[1] = v3 - a1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
_QWORD *v2; // rbx
__int64 v3; // rax
__int64 v4; // r8
__int64 v6; // rax
__int64 v7; // rdx

v1 = s_pagesz_0;
v2 = (_QWORD *)availList;
if ( !s_pagesz_0 )
{
v1 = Dynace_GetInitialPageSize();
s_pagesz_0 = Dynace_GetPageSize();
}
if ( v2 )
{
while ( 1 )
{
v3 = v2[1];
if ( v3 >= a1 )
break;
v2 = (_QWORD *)*v2;
if ( !v2 )
goto LABEL_10;
}
v4 = v2[2];
}
else
{
LABEL_10:
if ( a1 + 16 >= v1 )
v1 = a1 + 16;
v6 = Dynace_getpage(v1);
v2 = (_QWORD *)v6;
if ( !v6 )
return 0LL;
v7 = availList;
v4 = v6 + 24;
v3 = v1 - 24;
availList = (__int64)v2;
v2[2] = v2 + 3;
v2[1] = v1 - 24;
*v2 = v7;
}
v2[2] = v4 + a1;
v2[1] = v3 - a1;
return v4;
}

original_code:
static void *getBlock( long blockSize )
{
 char *returnBlock;
 al *tempList = availList;
 static long s_pagesz = 0;
 long curr_pagesz = s_pagesz;
 if ( !s_pagesz ) {
  curr_pagesz = Dynace_GetInitialPageSize();
  s_pagesz = Dynace_GetPageSize();
 }
 while( tempList )
 {
  if ( tempList->availAmt >= blockSize )
   break;
  tempList = tempList->next;
 }
 if ( !tempList )
 {
  returnBlock = _Dynace_getpage( ((curr_pagesz)>(blockSize + 16)?(curr_pagesz):(blockSize + 16)) );
  if ( !returnBlock )
   return( ((void *)0) );
  tempList = ( al * )returnBlock;
  returnBlock += sizeof( al );
  tempList->memBlock = returnBlock;
  tempList->availAmt = ((curr_pagesz)>(blockSize + 16)?(curr_pagesz):(blockSize + 16)) - sizeof( al );
  tempList->next = availList;
  availList = tempList;
 }
 returnBlock = tempList->memBlock;
 tempList->memBlock += blockSize;
 tempList->availAmt -= blockSize;
 return( returnBlock );
}

canonical_original_code:
static void *getBlock(long blockSize)
{
 char *returnBlock;
 struct _availList *tempList = availList;
 static long s_pagesz = 0;
 long curr_pagesz = s_pagesz;
 if ( !s_pagesz ) {
  curr_pagesz = Dynace_GetInitialPageSize();
  s_pagesz = Dynace_GetPageSize();
 }
 while( tempList )
 {
  if ( tempList->availAmt >= blockSize )
   break;
  tempList = tempList->next;
 }
 if ( !tempList )
 {
  returnBlock = _Dynace_getpage( ((curr_pagesz)>(blockSize + 16)?(curr_pagesz):(blockSize + 16)) );
  if ( !returnBlock )
   return( ((void *)0) );
  tempList = ( struct _availList * )returnBlock;
  returnBlock += sizeof( al );
  tempList->memBlock = returnBlock;
  tempList->availAmt = ((curr_pagesz)>(blockSize + 16)?(curr_pagesz):(blockSize + 16)) - sizeof( al );
  tempList->next = availList;
  availList = tempList;
 }
 returnBlock = tempList->memBlock;
 tempList->memBlock += blockSize;
 tempList->availAmt -= blockSize;
 return( returnBlock );
}

variable_types: blockSize long

variable_types:
returnBlock
char *

variable_types: struct _availList { struct _availList *next; long availAmt; char *memBlock; } *

return_type: void *


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

result = cErrorFunction;
cErrorFunction = a2;
return result;
}

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

result = cErrorFunction;
cErrorFunction = a2;
return result;
}

original_code:
static ifun Object_cm_gSetErrorFunction(object self, ifun fun)
{
 ifun ret = cErrorFunction;
 cErrorFunction = fun;
 return ret;
}

canonical_original_code:
static int (*Object_cm_gSetErrorFunction(struct _Object_iv_t *self, int (*fun)()))()
{
 int (*ret)() = cErrorFunction;
 cErrorFunction = fun;
 return ret;
}

variable_types: struct _Object_iv_t { struct _Object_iv_t *cls; unsigned short tag; unsigned short siz; unsigned long sn; } *

variable_types:
fun
int (*)()

variable_types:
ret
int (*)()


decompiled_code:
__int64 __fastcall Object_im_gInit(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1;
}

original_code:
static objrtn Object_im_gInit(object self)
{
 return self;
}

canonical_original_code:
static struct _Object_iv_t *Object_im_gInit(struct _Object_iv_t *self)
{
 return self;
}

variable_types:
self
struct _Object_iv_t *

return_type: struct _Object_iv_t { struct _Object_iv_t *cls; unsigned short tag; unsigned short siz; unsigned long sn; } *


decompiled_code:
__int64 __fastcall Object_im_gPrintValue(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

if ( CheckObjects_ && !(unsigned int)IsObj(a2) )
gInvalidObject(LastGeneric_, 2LL, a1);
v2 = gStringRepValue(a1);
gPuts(a2, v2);
gDispose(v2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

if ( CheckObjects_ && !(unsigned int)IsObj(a2) )
gInvalidObject(LastGeneric_, 2LL, a1);
v2 = gStringRepValue(a1);
gPuts(a2, v2);
gDispose(v2);
return a1;
}

original_code:
static objrtn Object_im_gPrintValue(object self, object stream)
{
 object t;
 if (_CheckObjects_ && !IsObj(stream)) gInvalidObject(_LastGeneric_, 2, self);
 t = gStringRepValue(self);
 gPuts(stream, (char *) t);
 gDispose(t);
 return self;
}

canonical_original_code:
static struct _Object_iv_t *Object_im_gPrintValue(struct _Object_iv_t *self, struct _Object_iv_t *stream)
{
 struct _Object_iv_t *t;
 if (_CheckObjects_ && !IsObj(stream)) gInvalidObject(_LastGeneric_, 2, self);
 t = gStringRepValue(self);
 gPuts(stream, (char *) t);
 gDispose(t);
 return self;
}

variable_types:
stream
struct _Object_iv_t *

user_defined_types: struct _Object_iv_t { struct _Object_iv_t *cls; unsigned short tag; unsigned short siz; unsigned long sn; }


decompiled_code:
__int64 __fastcall Object_im_gPrint(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

if ( CheckObjects_ && !(unsigned int)IsObj(a2) )
gInvalidObject(LastGeneric_, 2LL, a1);
v2 = gStringRep(a1);
gPuts(a2, v2);
gDispose(v2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

if ( CheckObjects_ && !(unsigned int)IsObj(a2) )
gInvalidObject(LastGeneric_, 2LL, a1);
v2 = gStringRep(a1);
gPuts(a2, v2);
gDispose(v2);
return a1;
}

original_code:
static objrtn Object_im_gPrint(object self, object stream)
{
 object t;
 if (_CheckObjects_ && !IsObj(stream)) gInvalidObject(_LastGeneric_, 2, self);
 t = gStringRep(self);
 gPuts(stream, (char *) t);
 gDispose(t);
 return self;
}

canonical_original_code:
static struct _Object_iv_t *Object_im_gPrint(struct _Object_iv_t *self, struct _Object_iv_t *stream)
{
 struct _Object_iv_t *t;
 if (_CheckObjects_ && !IsObj(stream)) gInvalidObject(_LastGeneric_, 2, self);
 t = gStringRep(self);
 gPuts(stream, (char *) t);
 gDispose(t);
 return self;
}


decompiled_code:
__int64 __fastcall Object_im_gCompare(unsigned __int64 a1, unsigned __int64 a2)
{
if ( a1 == a2 )
return 0LL;
if ( !CheckObjects_ || (unsigned int)IsObj(a2) )
return a1 < a2 ? -1 : 1;
gInvalidObject(LastGeneric_, 2LL, a1);
return a1 < a2 ? -1 : 1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, unsigned __int64 a2)
{
if ( a1 == a2 )
return 0LL;
if ( !CheckObjects_ || (unsigned int)IsObj(a2) )
return a1 < a2 ? -1 : 1;
gInvalidObject(LastGeneric_, 2LL, a1);
return a1 < a2 ? -1 : 1;
}

original_code:
static int Object_im_gCompare(object self, object obj2)
{
 if (((self) == (obj2)))
  return 0;
 if (_CheckObjects_ && !IsObj(obj2)) gInvalidObject(_LastGeneric_, 2, self);
 if ((INT_PTR) self < (INT_PTR) obj2)
  return -1;
 else
  return 1;
}

canonical_original_code:
static int Object_im_gCompare(struct _Object_iv_t *self, struct _Object_iv_t *obj2)
{
 if (((self) == (obj2)))
  return 0;
 if (_CheckObjects_ && !IsObj(obj2)) gInvalidObject(_LastGeneric_, 2, self);
 if ((unsigned long) self < (unsigned long) obj2)
  return -1;
 else
  return 1;
}


decompiled_code:
__int64 __fastcall Object_im_gStringRepValue(_QWORD *a1, __int64 a2)
{
__int64 (*v3)(__int64, const char *, ...); // rbx
__int64 v4; // rax
__int64 v5; // rdi
const char *v6; // rdx
__int64 v8; // rax
const char *v9; // [rsp+8h] [rbp-20h]

v3 = (__int64 (*)(__int64, const char *, ...))vSprintf;
v4 = gName(*a1);
v5 = String_c;
v6 = (const char *)v4;
if ( !String_c )
{
v9 = (const char *)v4;
v8 = String_initialize(String_c, a2, v4);
v6 = v9;
v5 = v8;
}
return v3(v5, "%s:<%8.8lx>", v6, a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2)
{
__int64 (*v3)(__int64, const char *, ...); // rbx
__int64 v4; // rax
__int64 v5; // rdi
const char *v6; // rdx
__int64 v8; // rax
const char *v9; // [rsp+8h] [rbp-20h]

v3 = (__int64 (*)(__int64, const char *, ...))vSprintf;
v4 = gName(*a1);
v5 = String_c;
v6 = (const char *)v4;
if ( !String_c )
{
v9 = (const char *)v4;
v8 = String_initialize(String_c, a2, v4);
v6 = v9;
v5 = v8;
}
return v3(v5, "%s:<%8.8lx>", v6, a1);
}

original_code:
static objrtn Object_im_gStringRepValue(object self)
{
 return vSprintf((String_c ? String_c : String_initialize()), "%s:<%8.8lx>", gName((object) *((object *) (self))), self);
}

canonical_original_code:
static struct _Object_iv_t *Object_im_gStringRepValue(struct _Object_iv_t *self)
{
 return vSprintf((String_c ? String_c : String_initialize()), "%s:<%8.8lx>", gName((object) *((struct _Object_iv_t **) (self))), self);
}


decompiled_code:
__int64 __fastcall Object_im_gStringRep(_QWORD *a1, __int64 a2)
{
__int64 (*v3)(__int64, const char *, ...); // r12
__int64 v4; // rax
__int64 v5; // rdi
const char *v6; // rdx
__int64 v7; // r12
__int64 v8; // rbp
__int64 v10; // rax
const char *v11; // [rsp+8h] [rbp-20h]

v3 = vSprintf;
v4 = gName(*a1);
v5 = String_c;
v6 = (const char *)v4;
if ( !String_c )
{
v11 = (const char *)v4;
v10 = String_initialize(String_c, a2, v4);
v6 = v11;
v5 = v10;
}
v7 = v3(v5, "%s:<%8.8lx> [ ", v6, a1);
v8 = gStringRepValue(a1);
vBuild(v7, 0LL, v8, " ]\n", 0LL);
gDispose(v8);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
__int64 (*v3)(__int64, const char *, ...); // r12
__int64 v4; // rax
__int64 v5; // rdi
const char *v6; // rdx
__int64 v7; // r12
__int64 v8; // rbp
__int64 v10; // rax
const char *v11; // [rsp+8h] [rbp-20h]

v3 = vSprintf;
v4 = gName(*a1);
v5 = String_c;
v6 = (const char *)v4;
if ( !String_c )
{
v11 = (const char *)v4;
v10 = String_initialize(String_c, a2, v4);
v6 = v11;
v5 = v10;
}
v7 = v3(v5, "%s:<%8.8lx> [ ", v6, a1);
v8 = gStringRepValue(a1);
vBuild(v7, 0LL, v8, " ]\n", 0LL);
gDispose(v8);
return v7;
}

original_code:
static objrtn Object_im_gStringRep(object self)
{
 object s, t;
 s = vSprintf((String_c ? String_c : String_initialize()), "%s:<%8.8lx> [ ", gName((object) *((object *) (self))), self);
 t = gStringRepValue(self);
 vBuild(s, ((void *)0), t, " ]\n", ((void *)0));
 gDispose(t);
 return s;
}

canonical_original_code:
static struct _Object_iv_t *Object_im_gStringRep(struct _Object_iv_t *self)
{
 struct _Object_iv_t *s; struct _Object_iv_t *t;
 s = vSprintf((String_c ? String_c : String_initialize()), "%s:<%8.8lx> [ ", gName((object) *((struct _Object_iv_t **) (self))), self);
 t = gStringRepValue(self);
 vBuild(s, ((void *)0), t, " ]\n", ((void *)0));
 gDispose(t);
 return s;
}


decompiled_code:
__int64 __fastcall Object_im_gObjectSerialNumber(__int64 a1)
{
return *(_QWORD *)(GetIVptr(a1, Object_c) + 16);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_QWORD *)(GetIVptr(a1, Object_c) + 16);
}

original_code:
static unsigned long Object_im_gObjectSerialNumber(object self)
{ Object_iv_t *iv = ((Object_iv_t *) GetIVptr((self), Object_c));
 return iv->sn;
}

canonical_original_code:
static unsigned long Object_im_gObjectSerialNumber(struct _Object_iv_t *self)
{ struct _Object_iv_t *iv = ((Object_iv_t *) GetIVptr((self), Object_c));
 return iv->sn;
}


decompiled_code:
__int64 __fastcall Object_im_gIsKindOf(_QWORD *a1, __int64 a2)
{
__int64 v5; // rdi
__int64 (__fastcall *v6)(__int64, __int64, __int64); // r12
__int64 v7; // rsi
__int64 (__fastcall *v8)(_QWORD, _QWORD); // rax
__int64 v9; // rdi

if ( class_IsKindOf_0 )
return class_IsKindOf_0(*a1, a2);
v5 = Behavior_c;
v6 = gFindMethod;
v7 = gIsKindOf_g;
if ( !Behavior_c )
{
v7 = gIsKindOf_g;
v5 = Behavior_initialize();
}
v8 = (__int64 (__fastcall *)(_QWORD, _QWORD))v6(v5, v7, 1LL);
v9 = *a1;
class_IsKindOf_0 = v8;
return v8(v9, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, __int64 a2)
{
__int64 v5; // rdi
__int64 (__fastcall *v6)(__int64, __int64, __int64); // r12
__int64 v7; // rsi
__int64 (__fastcall *v8)(_QWORD, _QWORD); // rax
__int64 v9; // rdi

if ( class_IsKindOf_0 )
return class_IsKindOf_0(*a1, a2);
v5 = Behavior_c;
v6 = gFindMethod;
v7 = gIsKindOf_g;
if ( !Behavior_c )
{
v7 = gIsKindOf_g;
v5 = Behavior_initialize();
}
v8 = (__int64 (__fastcall *)(_QWORD, _QWORD))v6(v5, v7, 1LL);
v9 = *a1;
class_IsKindOf_0 = v8;
return v8(v9, a2);
}

original_code:
static int Object_im_gIsKindOf(object self, object aCls)
{
 static gIsKindOf_t class_IsKindOf = ((void *)0);
 if (!class_IsKindOf)
  class_IsKindOf = (gIsKindOf_t) gFindMethod((Behavior_c ? Behavior_c : Behavior_initialize()), gIsKindOf_g, 1);
 return class_IsKindOf((object) *((object *) (self)), aCls);
}

canonical_original_code:
static int Object_im_gIsKindOf(struct _Object_iv_t *self, struct _Object_iv_t *aCls)
{
 static int (*class_IsKindOf)(struct _Object_iv_t *self, struct _Object_iv_t *aCls) = ((void *)0);
 if (!class_IsKindOf)
  class_IsKindOf = (int (*)(struct _Object_iv_t *self, struct _Object_iv_t *aCls)) gFindMethod((Behavior_c ? Behavior_c : Behavior_initialize()), gIsKindOf_g, 1);
 return class_IsKindOf((object) *((struct _Object_iv_t **) (self)), aCls);
}

variable_types:
aCls
struct _Object_iv_t *

variable_types: int (*)(struct _Object_iv_t { struct _Object_iv_t *cls; unsigned short tag; unsigned short siz; unsigned long sn; } *self, struct _Object_iv_t *aCls)


decompiled_code:
__int64 __fastcall Object_im_gShouldNotImplement(_QWORD **a1, const char *a2)
{
_QWORD *v3; // rdi
const char *v4; // rax
const char *v5; // rax
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = *a1;
if ( *v3 == MetaClass_c || v3 == (_QWORD *)MetaClass_c )
{
v5 = (const char *)gName(a1);
sprintf(v7, "Method %s is not appropriate for the %s class\n", a2, v5);
}
else
{
v4 = (const char *)gName(v3);
sprintf(v7, "Method %s is not appropriate for instances of %s\n", a2, v4);
}
return gError(a1, v7);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD **a1, const char *a2)
{
_QWORD *v3; // rdi
const char *v4; // rax
const char *v5; // rax
char v7[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = *a1;
if ( *v3 == MetaClass_c || v3 == (_QWORD *)MetaClass_c )
{
v5 = (const char *)gName(a1);
sprintf(v7, "Method %s is not appropriate for the %s class\n", a2, v5);
}
else
{
v4 = (const char *)gName(v3);
sprintf(v7, "Method %s is not appropriate for instances of %s\n", a2, v4);
}
return gError(a1, v7);
}

original_code:
static objrtn Object_im_gShouldNotImplement(object self, char *meth)
{
 char buf[100];
 if ((((object) *((object *) ((object) *((object *) (self)))) == MetaClass_c) || ((object) *((object *) (self)) == MetaClass_c)))
  sprintf(buf, "Method %s is not appropriate for the %s class\n",
  meth, gName(self));
 else
  sprintf(buf, "Method %s is not appropriate for instances of %s\n",
  meth, gName((object) *((object *) (self))));
 return gError(self, buf);
}

canonical_original_code:
static struct _Object_iv_t *Object_im_gShouldNotImplement(struct _Object_iv_t *self, char *meth)
{
 char buf[100];
 if ((((object) *((struct _Object_iv_t **) ((object) *((struct _Object_iv_t **) (self)))) == MetaClass_c) || ((object) *((struct _Object_iv_t **) (self)) == MetaClass_c)))
  sprintf(buf, "Method %s is not appropriate for the %s class\n",
  meth, gName(self));
 else
  sprintf(buf, "Method %s is not appropriate for instances of %s\n",
  meth, gName((object) *((struct _Object_iv_t **) (self))));
 return gError(self, buf);
}

variable_types:
meth
char *

variable_types:
buf
char [100]


decompiled_code:
__int64 __fastcall Object_im_gSubclassResponsibility(_QWORD **a1, const char *a2)
{
_QWORD *v3; // rdi
const char *v4; // rax
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = *a1;
if ( *v3 == MetaClass_c || v3 == (_QWORD *)MetaClass_c )
v3 = a1;
v4 = (const char *)gName(v3);
sprintf(v6, "Method %s should be implemented by a subclass of %s\n", a2, v4);
return gError(a1, v6);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD **a1, const char *a2)
{
_QWORD *v3; // rdi
const char *v4; // rax
char v6[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = *a1;
if ( *v3 == MetaClass_c || v3 == (_QWORD *)MetaClass_c )
v3 = a1;
v4 = (const char *)gName(v3);
sprintf(v6, "Method %s should be implemented by a subclass of %s\n", a2, v4);
return gError(a1, v6);
}

original_code:
static objrtn Object_im_gSubclassResponsibility(object self, char *meth)
{
 char buf[100];
 object aCls;
 aCls = (((object) *((object *) ((object) *((object *) (self)))) == MetaClass_c) || ((object) *((object *) (self)) == MetaClass_c)) ? self : (object) *((object *) (self));
 sprintf(buf, "Method %s should be implemented by a subclass of %s\n",
  meth, gName(aCls));
 return gError(self, buf);
}

canonical_original_code:
static struct _Object_iv_t *Object_im_gSubclassResponsibility(struct _Object_iv_t *self, char *meth)
{
 char buf[100];
 struct _Object_iv_t *aCls;
 aCls = (((object) *((struct _Object_iv_t **) ((object) *((struct _Object_iv_t **) (self)))) == MetaClass_c) || ((object) *((struct _Object_iv_t **) (self)) == MetaClass_c)) ? self : (object) *((struct _Object_iv_t **) (self));
 sprintf(buf, "Method %s should be implemented by a subclass of %s\n",
  meth, gName(aCls));
 return gError(self, buf);
}


decompiled_code:
__int64 Object_ifm_vError(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return Object_ivm_vError(a1, (int *)va);
}

canonical_decompiled_code:
__int64 func12(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func11(a1, (int *)va);
}

original_code:
static objrtn Object_ifm_vError(object self, ...)
{
 va_list _rest_;
 __builtin_va_start(_rest_,self);
 return Object_ivm_vError(self, _rest_);
}

canonical_original_code:
static struct _Object_iv_t *Object_ifm_vError(struct _Object_iv_t *self, ...)
{
 __builtin_va_list _rest_;
 __builtin_va_start(_rest_,self);
 return Object_ivm_vError(self, _rest_);
}