decompiled_code:
void __fastcall __noreturn compiler_fail(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v4; // ebp
__int64 v6; // rax
int v7; // edx
char *v8; // rbx
char *v9; // r12
char v10; // [rsp+1h] [rbp-429h]
char v11[1064]; // [rsp+2h] [rbp-428h] BYREF

v4 = a3;
if ( !a3 )
{
v4 = *(_DWORD *)(a2 + 20);
a4 = *(_DWORD *)(a2 + 24);
}
fflush(stdout);
fflush(stderr);
strncpy(v11, *((const char **)&code_lines + (int)v4), 0x400uLL);
v11[1023] = 0;
v6 = 0LL;
do
v7 = v6++;
while ( *(&v10 + v6) != 10 );
v11[v7] = 0;
fprintf(stderr, "%s\n", v11);
if ( a4 > 1 )
{
v8 = v11;
v9 = &v11[a4 - 2 + 1];
do
{
if ( *v8 == 9 )
fputc(9, stderr);
else
fputc(32, stderr);
++v8;
}
while ( v8 != v9 );
}
fputc(94, stderr);
fputc(10, stderr);
fprintf(stderr, "line %d: %s\n", v4, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1, __int64 a2, unsigned int a3, int a4)
{
unsigned int v4; // ebp
__int64 v6; // rax
int v7; // edx
char *v8; // rbx
char *v9; // r12
char v10; // [rsp+1h] [rbp-429h]
char v11[1064]; // [rsp+2h] [rbp-428h] BYREF

v4 = a3;
if ( !a3 )
{
v4 = *(_DWORD *)(a2 + 20);
a4 = *(_DWORD *)(a2 + 24);
}
fflush(stdout);
fflush(stderr);
strncpy(v11, *((const char **)&code_lines + (int)v4), 0x400uLL);
v11[1023] = 0;
v6 = 0LL;
do
v7 = v6++;
while ( *(&v10 + v6) != 10 );
v11[v7] = 0;
fprintf(stderr, "%s\n", v11);
if ( a4 > 1 )
{
v8 = v11;
v9 = &v11[a4 - 2 + 1];
do
{
if ( *v8 == 9 )
fputc(9, stderr);
else
fputc(32, stderr);
++v8;
}
while ( v8 != v9 );
}
fputc(94, stderr);
fputc(10, stderr);
fprintf(stderr, "line %d: %s\n", v4, a1);
exit(1);
}

original_code:
void compiler_fail(char *message, token_t *token,
        int in_line, int in_chr)
{
 char buf[1024];
 int line;
 int chr;
 int i;
 line = in_line ? in_line : token->from_line;
 chr = in_line ? in_chr : token->from_char;
 fflush(stdout);
 fflush(stderr);
 strncpy(buf, code_lines[line], 1024);
 buf[1023] = 0;
 for (i = 0; code_lines[line]; ++i)
  if (buf[i] == '\n') {
   buf[i] = 0;
   break;
  }
 fprintf(stderr, "%s\n", buf);
 for (i = 1; i < chr; ++i)
  if (buf[i - 1] == '\t')
   fputc(buf[i - 1], stderr);
  else
   fputc(' ', stderr);
 fputc('^', stderr);
 fputc('\n', stderr);
 fprintf(stderr, "line %d: %s\n",
  line,
  message);
 exit(1);
}

canonical_original_code:
void compiler_fail(char *message, struct token *token, int in_line, int in_chr)
{
 char buf[1024];
 int line;
 int chr;
 int i;
 line = in_line ? in_line : token->from_line;
 chr = in_line ? in_chr : token->from_char;
 fflush(stdout);
 fflush(stderr);
 strncpy(buf, code_lines[line], 1024);
 buf[1023] = 0;
 for (i = 0; code_lines[line]; ++i)
  if (buf[i] == '\n') {
   buf[i] = 0;
   break;
  }
 fprintf(stderr, "%s\n", buf);
 for (i = 1; i < chr; ++i)
  if (buf[i - 1] == '\t')
   fputc(buf[i - 1], stderr);
  else
   fputc(' ', stderr);
 fputc('^', stderr);
 fputc('\n', stderr);
 fprintf(stderr, "line %d: %s\n",
  line,
  message);
 exit(1);
}

variable_types:
message
char *

variable_types: struct token { char type; char *start; int len; int from_line; int from_char; } *

variable_types:
buf
char [1024]

variable_types: line int

variable_types: chr int


fail

decompiled_code:
void __fastcall __noreturn fail(const char *a1)
{
fprintf(stderr, "error: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "error: %s\n", a1);
exit(1);
}

original_code:
void fail(char* mesg)
{
 fprintf(stderr, "error: %s\n", mesg);
 exit(1);
}

canonical_original_code:
void fail(char *mesg)
{
 fprintf(stderr, "error: %s\n", mesg);
 exit(1);
}

variable_types:
mesg
char *

return_type: void


decompiled_code:
void __fastcall sanity_requires(int a1)
{
if ( !a1 )
fail("that doesn't make any sense");
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( !a1 )
func0("that doesn't make any sense");
}

original_code:
void sanity_requires(int exp)
{
 if(!exp)
  fail("that doesn't make any sense");
}

variable_types: exp int


decompiled_code:
char *__fastcall get_tok_str(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *src, int a9)
{
strncpy(buf, src, a9);
buf[a9] = 0;
return buf;
}

canonical_decompiled_code:
char *__fastcall func2(int a1, int a2, int a3, int a4, int a5, int a6, int a7, char *src, int a9)
{
strncpy(buf, src, a9);
buf[a9] = 0;
return buf;
}

original_code:
char* get_tok_str(token_t t)
{
        strncpy(buf, t.start, t.len);
        buf[t.len] = 0;
        return buf;
}

canonical_original_code:
char *get_tok_str(struct token t)
{
        strncpy(buf, t.start, t.len);
        buf[t.len] = 0;
        return buf;
}

variable_types: struct token { char type; char *start; int len; int from_line; int from_char; }

return_type: char *


decompiled_code:
__int64 __fastcall apply_rules_and_optimize(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int i; // ebp

for ( i = 0; ; i = 1 )
{
if ( (unsigned int)matchloop(a1, a2, a3) )
i = 1;
if ( !(unsigned int)optimize(a3) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int i; // ebp

for ( i = 0; ; i = 1 )
{
if ( (unsigned int)matchloop(a1, a2, a3) )
i = 1;
if ( !(unsigned int)optimize(a3) )
break;
}
return i;
}

original_code:
int apply_rules_and_optimize(exp_tree_t** rules, int rc, exp_tree_t *tree)
{
 int success = 0;
 while (1) {
  if (matchloop(rules, rc, tree)) {
   success = 1;
  }
  if (optimize(tree)) {
   success = 1;
   continue;
  }
  break;
 }
 return success;
}

canonical_original_code:
int apply_rules_and_optimize(struct exp_tree **rules, int rc, struct exp_tree *tree)
{
 int success = 0;
 while (1) {
  if (matchloop(rules, rc, tree)) {
   success = 1;
  }
  if (optimize(tree)) {
   success = 1;
   continue;
  }
  break;
 }
 return success;
}

variable_types: struct exp_tree { char head_type; struct token { char type; char *start; int len; int from_line; int from_char; } *tok; unsigned int child_count; unsigned int child_alloc; struct exp_tree **child; } **

variable_types: rc int

variable_types:
tree
struct exp_tree *

variable_types: success int

return_type: int

user_defined_types: struct exp_tree { char head_type; struct token *tok; unsigned int child_count; unsigned int child_alloc; struct exp_tree **child; }


rule

decompiled_code:
__int64 __fastcall rule(__int64 a1, __int64 a2, int *a3)
{
__int64 v5; // rsi
_BYTE *v6; // rdi
__int64 v7; // rcx
const __m128i *v8; // rax
int v9; // eax
__int64 v10; // rdx
__int64 *v11; // rbx
__int64 result; // rax
__int64 v13; // rdx
__int64 v14; // rcx
_BYTE v15[24]; // [rsp+0h] [rbp-58h] BYREF
const __m128i **v16; // [rsp+18h] [rbp-40h]
__m128i v17; // [rsp+20h] [rbp-38h]
__m128i v18; // [rsp+30h] [rbp-28h]

v5 = tokenize();
v6 = v15;
parse(v15, v5);
v8 = *v16;
v17 = _mm_loadu_si128(*v16);
v18 = _mm_loadu_si128(v8 + 1);
if ( v8->m128i_i8[0] != 14 )
{
putchar(10);
fail("you asked me to store, as a rule, a non-rule expression :(");
printout_tree("you asked me to store, as a rule, a non-rule expression :(", v5, v13, v14);
v6 = (_BYTE *)(&loc_9 + 1);
putchar(10);
}
v9 = *a3;
v10 = (unsigned int)(*a3 + 1);
*a3 = v10;
v11 = (__int64 *)(a2 + 8LL * v9);
result = alloc_exptree(v6, v5, v10, v7);
*v11 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int *a3)
{
__int64 v5; // rsi
_BYTE *v6; // rdi
__int64 v7; // rcx
const __m128i *v8; // rax
int v9; // eax
__int64 v10; // rdx
__int64 *v11; // rbx
__int64 result; // rax
__int64 v13; // rdx
__int64 v14; // rcx
_BYTE v15[24]; // [rsp+0h] [rbp-58h] BYREF
const __m128i **v16; // [rsp+18h] [rbp-40h]
__m128i v17; // [rsp+20h] [rbp-38h]
__m128i v18; // [rsp+30h] [rbp-28h]

v5 = tokenize();
v6 = v15;
parse(v15, v5);
v8 = *v16;
v17 = _mm_loadu_si128(*v16);
v18 = _mm_loadu_si128(v8 + 1);
if ( v8->m128i_i8[0] != 14 )
{
putchar(10);
fail("you asked me to store, as a rule, a non-rule expression :(");
printout_tree("you asked me to store, as a rule, a non-rule expression :(", v5, v13, v14);
v6 = (_BYTE *)(&loc_9 + 1);
putchar(10);
}
v9 = *a3;
v10 = (unsigned int)(*a3 + 1);
*a3 = v10;
v11 = (__int64 *)(a2 + 8LL * v9);
result = alloc_exptree(v6, v5, v10, v7);
*v11 = result;
return result;
}

original_code:
void rule(char *r, exp_tree_t **rules, int* rc)
{
 token_t* tokens;
 exp_tree_t tree;
 extern void fail(char*);
 tokens = tokenize(r);
 tree = *((parse(tokens)).child[0]);
 if (tree.head_type != EQL) {
  printf("\n");
  fail("you asked me to store, as a rule, a non-rule expression :(");
  printout_tree(tree);
  printf("\n");
 }
 rules[(*rc)++] = alloc_exptree(tree);
}

canonical_original_code:
void rule(char *r, struct exp_tree **rules, int *rc)
{
 struct token *tokens;
 struct exp_tree tree;
 extern void fail(char *);
 tokens = tokenize(r);
 tree = *((parse(tokens)).child[0]);
 if (tree.head_type != EQL) {
  printf("\n");
  fail("you asked me to store, as a rule, a non-rule expression :(");
  printout_tree(tree);
  printf("\n");
 }
 rules[(*rc)++] = alloc_exptree(tree);
}

variable_types:
r
char *

variable_types:
rc
int *

variable_types: struct exp_tree { char head_type; struct token { char type; char *start; int len; int from_line; int from_char; } *tok; unsigned int child_count; unsigned int child_alloc; struct exp_tree **child; }

variable_types:
fail
void (char *)


evlist

original_code:
void evlist(list_t* l, env_t *env)
{
 int i = 0;
 for (i = 0; i < l->cc; ++i)
  l->c[i] = eval_apply_tco(0, l->c[i], env, ((void *)0), ((void *)0));
}

canonical_original_code:
void evlist(struct list *l, struct env *env)
{
 int i = 0;
 for (i = 0; i < l->cc; ++i)
  l->c[i] = eval_apply_tco(0, l->c[i], env, ((void *)0), ((void *)0));
}

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

variable_types:
env
struct env *

variable_types: i int

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


decompiled_code:
int __fastcall error_msg(const char *a1)
{
return printf("Error: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("Error: %s\n", a1);
}

original_code:
void error_msg(char *s)
{
  printf("Error: %s\n", s);
}

variable_types:
s
char *


decompiled_code:
int __fastcall fatal_error_msg(const char *a1)
{
return printf("Fatal error: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return printf("Fatal error: %s\n", a1);
}

original_code:
void fatal_error_msg(char *s)
{
  printf("Fatal error: %s\n", s);
}


decompiled_code:
_BOOL8 __fastcall check_comment(char *a1)
{
char i; // al

for ( i = *a1; *a1; i = *++a1 )
{
if ( (unsigned __int8)(i - 9) > 1u && i != 32 )
break;
}
return i == 59;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *a1)
{
char i; // al

for ( i = *a1; *a1; i = *++a1 )
{
if ( (unsigned __int8)(i - 9) > 1u && i != 32 )
break;
}
return i == 59;
}


decompiled_code:
void __noreturn code_error()
{
stacktracer_prebarf();
if ( interactive )
longjmp(repl_jmp, 1);
puts("Shutting down.");
exit(1);
}

canonical_decompiled_code:
void __noreturn func4()
{
stacktracer_prebarf();
if ( interactive )
longjmp(repl_jmp, 1);
puts("Shutting down.");
exit(1);
}

original_code:
int code_error()
{
 stacktracer_prebarf();
 if (interactive)
  longjmp(repl_jmp, 1);
 else {
  printf("Shutting down.\n");
  exit(1);
 }
}


decompiled_code:
__int64 __fastcall strip_nl(_BYTE *a1)
{
__int64 result; // rax

result = (unsigned __int8)*a1;
if ( (_BYTE)result )
{
while ( (_BYTE)result != 10 )
{
result = (unsigned __int8)*++a1;
if ( !(_BYTE)result )
return result;
}
*a1 = 0;
}
return result;
}

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

result = (unsigned __int8)*a1;
if ( (_BYTE)result )
{
while ( (_BYTE)result != 10 )
{
result = (unsigned __int8)*++a1;
if ( !(_BYTE)result )
return result;
}
*a1 = 0;
}
return result;
}

original_code:
void strip_nl(char *s)
{
 while (*s) {
  if (*s == '\n') {
   *s = 0;
   break;
  }
  ++s;
 }
}


decompiled_code:
void *__fastcall c_malloc(size_t a1)
{
void *v1; // rax
void *v2; // rbx

v1 = malloc(a1);
if ( !v1 )
{
fatal_error_msg("malloc() has failed");
exit(1);
}
v2 = v1;
add_ptr(v1);
return v2;
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
void *v1; // rax
void *v2; // rbx

v1 = malloc(a1);
if ( !v1 )
{
func2("malloc() has failed");
exit(1);
}
v2 = v1;
add_ptr(v1);
return v2;
}

original_code:
void *c_malloc(long size)
{
 void *ptr = malloc(size);
 if (!ptr) {
  fatal_error_msg("malloc() has failed");
  exit(1);
 }
 add_ptr(ptr);
 return ptr;
}

variable_types: size long

variable_types:
ptr
void *

return_type: void *


original_code:
list_t *cons2list(list_t *c)
{
 list_t *curr = c;
 list_t *nw;
 nw = new_list();
 nw->type = LIST;
 if (curr->cc == 2) {
  do {
   add_child(nw, copy_list(curr->c[0]));
   curr = curr->c[1];
  } while (curr->cc == 2);
 }
 return nw;
}

canonical_original_code:
struct list *cons2list(struct list *c)
{
 struct list *curr = c;
 struct list *nw;
 nw = new_list();
 nw->type = LIST;
 if (curr->cc == 2) {
  do {
   add_child(nw, copy_list(curr->c[0]));
   curr = curr->c[1];
  } while (curr->cc == 2);
 }
 return nw;
}

variable_types:
c
struct list *

return_type: 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; } *


mksym

decompiled_code:
__int64 __fastcall mksym(char *src)
{
__int64 v1; // rbx

v1 = new_list();
strcpy(*(char **)v1, src);
*(_DWORD *)(v1 + 8) = 0;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *src)
{
__int64 v1; // rbx

v1 = new_list();
strcpy(*(char **)v1, src);
*(_DWORD *)(v1 + 8) = 0;
return v1;
}

original_code:
list_t* mksym(char *s)
{
 list_t *sl = new_list();
 strcpy(sl->head, s);
 sl->type = SYMBOL;
 return sl;
}

canonical_original_code:
struct list *mksym(char *s)
{
 struct list *sl = new_list();
 strcpy(sl->head, s);
 sl->type = SYMBOL;
 return sl;
}

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


makelist

original_code:
list_t* makelist(list_t* argl)
{
 list_t *nw, *nw2, *nw3;
 list_t *cons;
 int i;
 nw3 = nw = new_list();
 nw->type = CONS;
 for (i = 0; i < argl->cc; ++i) {
  if (argl->c[i]->type == LIST) {
   cons = makelist(argl->c[i]);
   add_child(nw, cons);
  } else
   add_child(nw, argl->c[i]);
  if ((i + 1) < argl->cc) {
   nw2 = new_list();
   nw2->type = CONS;
   add_child(nw, nw2);
   nw = nw2;
  } else {
   add_child(nw, mksym("NIL"));
  }
 }
 return nw3;
}

canonical_original_code:
struct list *makelist(struct list *argl)
{
 struct list *nw; struct list *nw2; struct list *nw3;
 struct list *cons;
 int i;
 nw3 = nw = new_list();
 nw->type = CONS;
 for (i = 0; i < argl->cc; ++i) {
  if (argl->c[i]->type == LIST) {
   cons = makelist(argl->c[i]);
   add_child(nw, cons);
  } else
   add_child(nw, argl->c[i]);
  if ((i + 1) < argl->cc) {
   nw2 = new_list();
   nw2->type = CONS;
   add_child(nw, nw2);
   nw = nw2;
  } else {
   add_child(nw, mksym("NIL"));
  }
 }
 return nw3;
}

variable_types:
argl
struct list *


makebool

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

result = new_list();
*(_DWORD *)(result + 8) = 5;
*(_DWORD *)(result + 12) = a1;
return result;
}

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

result = new_list();
*(_DWORD *)(result + 8) = 5;
*(_DWORD *)(result + 12) = a1;
return result;
}

original_code:
list_t* makebool(int cbool)
{
 list_t *b = new_list();
 b->type = BOOL;
 b->val = cbool;
 return b;
}

canonical_original_code:
struct list *makebool(int cbool)
{
 struct list *b = new_list();
 b->type = BOOL;
 b->val = cbool;
 return b;
}

variable_types: cbool int


isnum

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

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

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

variable_types: c char


decompiled_code:
void *__fastcall better_realloc(void *ptr, size_t a2)
{
void *v2; // rbx

v2 = realloc(ptr, a2);
if ( !v2 )
free(ptr);
return v2;
}

canonical_decompiled_code:
void *__fastcall func13(void *ptr, size_t a2)
{
void *v2; // rbx

v2 = realloc(ptr, a2);
if ( !v2 )
free(ptr);
return v2;
}

original_code:
void* better_realloc(void *ptr, long size)
{
 void *tmp;
 if (!(tmp = realloc(ptr, size)))
  free(ptr);
 return tmp;
}

canonical_original_code:
void *better_realloc(void *ptr, long size)
{
 void *tmp;
 if (!(tmp = realloc(ptr, size)))
  free(ptr);
 return tmp;
}

variable_types:
tmp
void *


decompiled_code:
__int64 final_clean_up()
{
gc();
return gc_selfdestroy();
}

canonical_decompiled_code:
__int64 func0()
{
gc();
return gc_selfdestroy();
}

original_code:
void final_clean_up()
{
 gc();
 gc_selfdestroy();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BOOL4 v3; // eax
__int64 v4; // rbx
__int64 v5; // rax
_BYTE *ptr; // [rsp+8h] [rbp-420h]
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

ptr = malloc(0x80000uLL);
if ( !ptr )
{
puts("could not allocate a buffer");
exit(1);
}
stacktracer_init();
*ptr = 0;
global = new_env();
install_primitives(global);
load_code_from_file("prefix.txt");
v3 = 0;
if ( argc == 2 )
v3 = strcmp(argv[1], "-i") == 0;
interactive = v3;
if ( setjmp(repl_jmp) )
*ptr = 0;
stacktracer_reset();
while ( 1 )
{
*ptr = 0;
v4 = new_list();
if ( save_mode )
fputc(10, save_file);
if ( !(unsigned int)do_read_file(ptr, stdin, (unsigned int)interactive) )
break;
if ( !*ptr )
break;
build(v4, ptr);
if ( feof(stdin) )
break;
if ( interactive )
{
s[0] = 0;
v5 = eval_apply_tco(0LL, v4, global, 0LL, 0LL);
printout(v5, s);
puts(s);
if ( save_mode )
{
fwrite(";; ", 1uLL, 3uLL, save_file);
fflush(save_file);
fputs(s, save_file);
fputc(10, save_file);
}
}
else
{
eval_apply_tco(0LL, v4, global, 0LL, 0LL);
}
gc();
stacktracer_reset();
}
if ( save_mode )
fclose(save_file);
final_clean_up();
free(ptr);
stacktracer_destroy();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BOOL4 v3; // eax
__int64 v4; // rbx
__int64 v5; // rax
_BYTE *ptr; // [rsp+8h] [rbp-420h]
char s[1048]; // [rsp+10h] [rbp-418h] BYREF

ptr = malloc(0x80000uLL);
if ( !ptr )
{
puts("could not allocate a buffer");
exit(1);
}
stacktracer_init();
*ptr = 0;
global = new_env();
install_primitives(global);
load_code_from_file("prefix.txt");
v3 = 0;
if ( argc == 2 )
v3 = strcmp(argv[1], "-i") == 0;
interactive = v3;
if ( setjmp(repl_jmp) )
*ptr = 0;
stacktracer_reset();
while ( 1 )
{
*ptr = 0;
v4 = new_list();
if ( save_mode )
fputc(10, save_file);
if ( !(unsigned int)do_read_file(ptr, stdin, (unsigned int)interactive) )
break;
if ( !*ptr )
break;
build(v4, ptr);
if ( feof(stdin) )
break;
if ( interactive )
{
s[0] = 0;
v5 = eval_apply_tco(0LL, v4, global, 0LL, 0LL);
printout(v5, s);
puts(s);
if ( save_mode )
{
fwrite(";; ", 1uLL, 3uLL, save_file);
fflush(save_file);
fputs(s, save_file);
fputc(10, save_file);
}
}
else
{
eval_apply_tco(0LL, v4, global, 0LL, 0LL);
}
gc();
stacktracer_reset();
}
if ( save_mode )
fclose(save_file);
func0();
free(ptr);
stacktracer_destroy();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 char *buf = malloc(1024 * 512);
 char out[1024];
 list_t *expr;
 if (!buf) {
  printf("could not allocate a buffer\n");
  exit(1);
 }
 stacktracer_init();
 *buf = 0;
 global = new_env();
 install_primitives(global);
 load_code_from_file("prefix.txt");
 interactive = argc == 2 && !strcmp(argv[1], "-i");
 if (_setjmp (repl_jmp))
  *buf = 0;
 stacktracer_reset();
 while (1) {
  *buf = 0;
  expr = new_list();
   if (save_mode)
    fprintf(save_file, "\n");
   if (!do_read_file(buf, stdin, interactive))
    break;
  if (!*buf)
   break;
  build(expr, buf);
  if (feof(stdin))
   break;
  if (interactive) {
   *out = 0;
   printout(eval_apply_tco(0, expr, global, ((void *)0), ((void *)0)), out);
   puts(out);
   if (save_mode) {
    fprintf(save_file, ";; ");
    fflush(save_file);
    fputs(out, save_file);
    fprintf(save_file, "\n");
   }
  } else {
   eval_apply_tco(0, expr, global, ((void *)0), ((void *)0));
  }
  gc();
  stacktracer_reset();
 }
 if (save_mode)
  fclose(save_file);
 final_clean_up();
 free(buf);
 stacktracer_destroy();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 char *buf = malloc(1024 * 512);
 char out[1024];
 struct list *expr;
 if (!buf) {
  printf("could not allocate a buffer\n");
  exit(1);
 }
 stacktracer_init();
 *buf = 0;
 global = new_env();
 install_primitives(global);
 load_code_from_file("prefix.txt");
 interactive = argc == 2 && !strcmp(argv[1], "-i");
 if (_setjmp (repl_jmp))
  *buf = 0;
 stacktracer_reset();
 while (1) {
  *buf = 0;
  expr = new_list();
   if (save_mode)
    fprintf(save_file, "\n");
   if (!do_read_file(buf, stdin, interactive))
    break;
  if (!*buf)
   break;
  build(expr, buf);
  if (feof(stdin))
   break;
  if (interactive) {
   *out = 0;
   printout(eval_apply_tco(0, expr, global, ((void *)0), ((void *)0)), out);
   puts(out);
   if (save_mode) {
    fprintf(save_file, ";; ");
    fflush(save_file);
    fputs(out, save_file);
    fprintf(save_file, "\n");
   }
  } else {
   eval_apply_tco(0, expr, global, ((void *)0), ((void *)0));
  }
  gc();
  stacktracer_reset();
 }
 if (save_mode)
  fclose(save_file);
 final_clean_up();
 free(buf);
 stacktracer_destroy();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
buf
char *

variable_types:
out
char [1024]


original_code:
list_t *new_list(void)
{
 list_t* nl = c_malloc(sizeof(list_t));
 nl->type = SYMBOL;
 nl->val = 0;
 nl->head = c_malloc(32);
 nl->head[0] = 0;
 nl->c = ((void *)0);
 nl->ca = 0;
 nl->cc = 0;
 return nl;
}

canonical_original_code:
struct list *new_list()
{
 struct list *nl = c_malloc(sizeof(list_t));
 nl->type = SYMBOL;
 nl->val = 0;
 nl->head = c_malloc(32);
 nl->head[0] = 0;
 nl->c = ((void *)0);
 nl->ca = 0;
 nl->cc = 0;
 return nl;
}


original_code:
void add_child(list_t *parent, list_t* child)
{
 list_t **new;
 int i;
 if (++(parent->cc) >= parent->ca) {
  parent->ca += 16;
  new = c_malloc(parent->ca * sizeof(list_t *));
  for (i = 0; i < parent->ca - 16; ++i)
   new[i] = parent->c[i];
  parent->c = new;
 }
 parent->c[parent->cc - 1] = child;
}

canonical_original_code:
void add_child(struct list *parent, struct list *child)
{
 struct list **new;
 int i;
 if (++(parent->cc) >= parent->ca) {
  parent->ca += 16;
  new = c_malloc(parent->ca * sizeof(struct list *));
  for (i = 0; i < parent->ca - 16; ++i)
   new[i] = parent->c[i];
  parent->c = new;
 }
 parent->c[parent->cc - 1] = child;
}

variable_types:
child
struct list *

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


original_code:
env_t* new_env(void)
{
 env_t *e = c_malloc(sizeof(env_t));
 e->count = 0;
 e->father = ((void *)0);
 e->alloc = 8;
 e->sym = c_malloc(e->alloc * sizeof(char *));
 e->ptr = c_malloc(e->alloc * sizeof(void *));
 return e;
}

canonical_original_code:
struct env *new_env()
{
 struct env *e = c_malloc(sizeof(env_t));
 e->count = 0;
 e->father = ((void *)0);
 e->alloc = 8;
 e->sym = c_malloc(e->alloc * sizeof(char *));
 e->ptr = c_malloc(e->alloc * sizeof(void *));
 return e;
}

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


lookup

decompiled_code:
__int64 __fastcall lookup(__int64 a1, const char *a2)
{
int v2; // ebp
__int64 v3; // r14
__int64 v4; // rbx
__int64 result; // rax

v2 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
{
LABEL_5:
result = *(_QWORD *)(a1 + 24);
if ( result )
result = lookup(result, a2, 0LL);
}
else
{
v3 = *(_QWORD *)(a1 + 8);
v4 = 0LL;
while ( strcmp(*(const char **)(v3 + 8 * v4), a2) )
{
if ( v2 == ++v4 )
goto LABEL_5;
}
result = a1;
}
return result;
}

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

v2 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
{
LABEL_5:
result = *(_QWORD *)(a1 + 24);
if ( result )
result = func1(result, a2, 0LL);
}
else
{
v3 = *(_QWORD *)(a1 + 8);
v4 = 0LL;
while ( strcmp(*(const char **)(v3 + 8 * v4), a2) )
{
if ( v2 == ++v4 )
goto LABEL_5;
}
result = a1;
}
return result;
}

original_code:
env_ref_t lookup(env_t *e, char *sym)
{
 int i;
 env_ref_t ret;
 for (i = 0; i < e->count; ++i) {
  if (!strcmp(e->sym[i], sym)) {
   ret.i = i;
   ret.e = e;
   return ret;
  }
 }
 ret.i = 0;
 ret.e = ((void *)0);
 if (e->father)
  ret = lookup(e->father, sym);
 return ret;
}

canonical_original_code:
struct env_ref lookup(struct env *e, char *sym)
{
 int i;
 struct env_ref ret;
 for (i = 0; i < e->count; ++i) {
  if (!strcmp(e->sym[i], sym)) {
   ret.i = i;
   ret.e = e;
   return ret;
  }
 }
 ret.i = 0;
 ret.e = ((void *)0);
 if (e->father)
  ret = lookup(e->father, sym);
 return ret;
}

variable_types:
e
struct env *

variable_types:
sym
char *

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

user_defined_types: struct env_ref { struct env *e; int i; }


decompiled_code:
__int64 __fastcall env_set(__int64 a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // edx
int v6; // ebx
size_t v7; // rax
_QWORD *v8; // r14
__int64 result; // rax
char *v10; // r14

v4 = lookup(a1, a2);
v6 = v5;
if ( !v4 )
{
v10 = (char *)malloc(0x20uLL);
if ( !v10 )
{
error_msg("malloc failed");
code_error();
}
sprintf(v10, "unbound variable `%s'", a2);
error_msg(v10);
free(v10);
code_error();
}
v7 = strlen(a2);
v8 = (_QWORD *)(*(_QWORD *)(v4 + 8) + 8LL * v6);
*v8 = c_malloc(v7 + 1);
strcpy(*(char **)(*(_QWORD *)(v4 + 8) + 8LL * v6), a2);
result = *(_QWORD *)(v4 + 16);
*(_QWORD *)(result + 8LL * v6) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, __int64 a3)
{
__int64 v4; // rbp
int v5; // edx
int v6; // ebx
size_t v7; // rax
_QWORD *v8; // r14
__int64 result; // rax
char *v10; // r14

v4 = func1(a1, a2);
v6 = v5;
if ( !v4 )
{
v10 = (char *)malloc(0x20uLL);
if ( !v10 )
{
error_msg("malloc failed");
code_error();
}
sprintf(v10, "unbound variable `%s'", a2);
error_msg(v10);
free(v10);
code_error();
}
v7 = strlen(a2);
v8 = (_QWORD *)(*(_QWORD *)(v4 + 8) + 8LL * v6);
*v8 = c_malloc(v7 + 1);
strcpy(*(char **)(*(_QWORD *)(v4 + 8) + 8LL * v6), a2);
result = *(_QWORD *)(v4 + 16);
*(_QWORD *)(result + 8LL * v6) = a3;
return result;
}

original_code:
void env_set(env_t *e, char *sym, void *p)
{
 env_ref_t ref = lookup(e, sym);
 char *tmp;
 if (ref.e == ((void *)0)) {
  tmp = malloc(32);
  if (!tmp) {
   error_msg("malloc failed");
   code_error();
  }
  sprintf(tmp, "unbound variable `%s'", sym);
  error_msg(tmp);
  free(tmp);
  code_error();
 }
 (ref.e)->sym[ref.i] = c_malloc(strlen(sym) + 1);
 strcpy((ref.e)->sym[ref.i], sym);
 (ref.e)->ptr[ref.i] = p;
}

canonical_original_code:
void env_set(struct env *e, char *sym, void *p)
{
 struct env_ref ref = lookup(e, sym);
 char *tmp;
 if (ref.e == ((void *)0)) {
  tmp = malloc(32);
  if (!tmp) {
   error_msg("malloc failed");
   code_error();
  }
  sprintf(tmp, "unbound variable `%s'", sym);
  error_msg(tmp);
  free(tmp);
  code_error();
 }
 (ref.e)->sym[ref.i] = c_malloc(strlen(sym) + 1);
 strcpy((ref.e)->sym[ref.i], sym);
 (ref.e)->ptr[ref.i] = p;
}

variable_types:
p
void *

variable_types:
tmp
char *


original_code:
void env_add(env_t *e, char *sym, void *p)
{
 int c = e->count;
 char **nsym;
 void **nptr;
 int i;
 if ((lookup(e, sym)).e == e) {
  env_set(e, sym, p);
  return;
 }
 if (++(e->count) >= e->alloc) {
  e->alloc += 16;
  nsym = c_malloc(e->alloc * sizeof(char *));
  nptr = c_malloc(e->alloc * sizeof(void *));
  for (i = 0; i < e->alloc - 16; ++i) {
   nsym[i] = e->sym[i];
   nptr[i] = e->ptr[i];
  }
  e->sym = nsym;
  e->ptr = nptr;
 }
 e->sym[c] = c_malloc(strlen(sym) + 1);
 strcpy(e->sym[c], sym);
 e->ptr[c] = p;
}

canonical_original_code:
void env_add(struct env *e, char *sym, void *p)
{
 int c = e->count;
 char **nsym;
 void **nptr;
 int i;
 if ((lookup(e, sym)).e == e) {
  env_set(e, sym, p);
  return;
 }
 if (++(e->count) >= e->alloc) {
  e->alloc += 16;
  nsym = c_malloc(e->alloc * sizeof(char *));
  nptr = c_malloc(e->alloc * sizeof(void *));
  for (i = 0; i < e->alloc - 16; ++i) {
   nsym[i] = e->sym[i];
   nptr[i] = e->ptr[i];
  }
  e->sym = nsym;
  e->ptr = nptr;
 }
 e->sym[c] = c_malloc(strlen(sym) + 1);
 strcpy(e->sym[c], sym);
 e->ptr[c] = p;
}

variable_types: c int

variable_types:
nsym
char **

variable_types:
nptr
void **

variable_types: i int


decompiled_code:
__int64 __fastcall add_primop(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax

v2 = new_list();
*(_DWORD *)(v2 + 8) = 2;
v3 = mksym("PRIM-OP");
add_child(v2, v3);
v4 = mksym(a2);
add_child(v2, v4);
return env_add(a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax

v2 = new_list();
*(_DWORD *)(v2 + 8) = 2;
v3 = mksym("PRIM-OP");
add_child(v2, v3);
v4 = mksym(a2);
add_child(v2, v4);
return env_add(a1, a2, v2);
}

original_code:
void add_primop(env_t *e, char *sym)
{
 list_t *l = new_list();
 l->type = LIST;
 add_child(l, mksym("PRIM-OP"));
 add_child(l, mksym(sym));
 env_add(e, sym, l);
}

canonical_original_code:
void add_primop(struct env *e, char *sym)
{
 struct list *l = new_list();
 l->type = LIST;
 add_child(l, mksym("PRIM-OP"));
 add_child(l, mksym(sym));
 env_add(e, sym, l);
}

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


decompiled_code:
__int64 __fastcall install_primitives(__int64 a1)
{
add_primop(a1, (__int64)"+");
add_primop(a1, (__int64)"-");
add_primop(a1, (__int64)"*");
add_primop(a1, (__int64)"remainder");
add_primop(a1, (__int64)"=");
add_primop(a1, (__int64)">");
add_primop(a1, (__int64)"<");
add_primop(a1, (__int64)">=");
add_primop(a1, (__int64)"<=");
add_primop(a1, (__int64)"not");
add_primop(a1, (__int64)"car");
add_primop(a1, (__int64)"cdr");
add_primop(a1, (__int64)"cons");
add_primop(a1, (__int64)"null?");
add_primop(a1, (__int64)"display");
add_primop(a1, (__int64)"newline");
add_primop(a1, (__int64)"pair?");
add_primop(a1, (__int64)"symbol?");
add_primop(a1, (__int64)"eq?");
add_primop(a1, (__int64)"number?");
add_primop(a1, (__int64)"newline");
add_primop(a1, (__int64)"save-to");
add_primop(a1, (__int64)"load");
add_primop(a1, (__int64)"cons2list");
add_primop(a1, (__int64)"debuglog");
return add_primop(a1, (__int64)"reverse");
}

original_code:
void install_primitives(env_t *env)
{
 add_primop(env, "+");
 add_primop(env, "-");
 add_primop(env, "*");
 add_primop(env, "remainder");
 add_primop(env, "=");
 add_primop(env, ">");
 add_primop(env, "<");
 add_primop(env, ">=");
 add_primop(env, "<=");
 add_primop(env, "not");
 add_primop(env, "car");
 add_primop(env, "cdr");
 add_primop(env, "cons");
 add_primop(env, "null?");
 add_primop(env, "display");
 add_primop(env, "newline");
 add_primop(env, "pair?");
 add_primop(env, "symbol?");
 add_primop(env, "eq?");
 add_primop(env, "number?");
 add_primop(env, "newline");
 add_primop(env, "save-to");
 add_primop(env, "load");
 add_primop(env, "cons2list");
 add_primop(env, "debuglog");
 add_primop(env, "reverse");
}

canonical_original_code:
void install_primitives(struct env *env)
{
 add_primop(env, "+");
 add_primop(env, "-");
 add_primop(env, "*");
 add_primop(env, "remainder");
 add_primop(env, "=");
 add_primop(env, ">");
 add_primop(env, "<");
 add_primop(env, ">=");
 add_primop(env, "<=");
 add_primop(env, "not");
 add_primop(env, "car");
 add_primop(env, "cdr");
 add_primop(env, "cons");
 add_primop(env, "null?");
 add_primop(env, "display");
 add_primop(env, "newline");
 add_primop(env, "pair?");
 add_primop(env, "symbol?");
 add_primop(env, "eq?");
 add_primop(env, "number?");
 add_primop(env, "newline");
 add_primop(env, "save-to");
 add_primop(env, "load");
 add_primop(env, "cons2list");
 add_primop(env, "debuglog");
 add_primop(env, "reverse");
}


decompiled_code:
void stacktracer_reset()
{
ptr = 0;
full = 0;
sym = 0;
sym_ptr = 0;
}

canonical_decompiled_code:
void func0()
{
ptr = 0;
full = 0;
sym = 0;
sym_ptr = 0;
}


decompiled_code:
void stacktracer_init()
{
char *v0; // rax
char *v1; // r13
char *v2; // rbp
char *v3; // r12
_QWORD *v4; // rbx
_QWORD *v5; // r13
void *v6; // rax
__int64 i; // rbx
void *v8; // rax
void *v9; // rax

debug_buff_written = 0;
v0 = (char *)malloc(0x800uLL);
debug_buff = v0;
if ( !v0
|| (*v0 = 0, v1 = (char *)malloc(0x28uLL), (stacktraces = v1) == 0LL)
|| (v2 = (char *)malloc(0x40uLL), (sym_name = v2) == 0LL)
|| (v3 = (char *)malloc(0x40uLL), (sym_print = v3) == 0LL) )
{
LABEL_13:
error_msg("stacktracer_init() has failed");
exit(1);
}
v4 = v1;
v5 = v1 + 40;
do
{
v6 = malloc(0x800uLL);
*v4 = v6;
if ( !v6 )
goto LABEL_13;
++v4;
}
while ( v4 != v5 );
for ( i = 0LL; i != 64; i += 8LL )
{
v8 = malloc(0x20uLL);
*(_QWORD *)&v2[i] = v8;
if ( !v8 )
goto LABEL_13;
v9 = malloc(0x400uLL);
*(_QWORD *)&v3[i] = v9;
if ( !v9 )
goto LABEL_13;
}
stacktracer_reset();
}

canonical_decompiled_code:
void func1()
{
char *v0; // rax
char *v1; // r13
char *v2; // rbp
char *v3; // r12
_QWORD *v4; // rbx
_QWORD *v5; // r13
void *v6; // rax
__int64 i; // rbx
void *v8; // rax
void *v9; // rax

debug_buff_written = 0;
v0 = (char *)malloc(0x800uLL);
debug_buff = v0;
if ( !v0
|| (*v0 = 0, v1 = (char *)malloc(0x28uLL), (stacktraces = v1) == 0LL)
|| (v2 = (char *)malloc(0x40uLL), (sym_name = v2) == 0LL)
|| (v3 = (char *)malloc(0x40uLL), (sym_print = v3) == 0LL) )
{
LABEL_13:
error_msg("stacktracer_init() has failed");
exit(1);
}
v4 = v1;
v5 = v1 + 40;
do
{
v6 = malloc(0x800uLL);
*v4 = v6;
if ( !v6 )
goto LABEL_13;
++v4;
}
while ( v4 != v5 );
for ( i = 0LL; i != 64; i += 8LL )
{
v8 = malloc(0x20uLL);
*(_QWORD *)&v2[i] = v8;
if ( !v8 )
goto LABEL_13;
v9 = malloc(0x400uLL);
*(_QWORD *)&v3[i] = v9;
if ( !v9 )
goto LABEL_13;
}
func0();
}

original_code:
void stacktracer_init()
{
 int i;
 debug_buff_written = 0;
 debug_buff = malloc(1024 * 2);
 if (!debug_buff)
  goto fail;
 *debug_buff = 0;
 stacktraces = malloc(5 * sizeof(char *));
 if (!stacktraces)
  goto fail;
 sym_name = malloc(8 * sizeof(char *));
 if (!sym_name)
  goto fail;
 sym_print = malloc(8 * sizeof(char *));
 if (!sym_print)
  goto fail;
 for (i = 0; i < 5; ++i) {
  stacktraces[i] = malloc(1024 * 2);
  if (!(stacktraces[i]))
   goto fail;
 }
 for (i = 0; i < 8; ++i) {
  sym_name[i] = malloc(32);
  if (!(sym_name[i]))
   goto fail;
  sym_print[i] = malloc(1024);
  if (!(sym_print[i]))
   goto fail;
 }
 stacktracer_reset();
 return;
fail:
 error_msg("stacktracer_init() has failed");
 exit(1);
}


decompiled_code:
void stacktracer_destroy()
{
__int64 i; // rbx
void *v1; // r13
__int64 j; // rbx
void *v3; // r12
void *v4; // rbp

for ( i = 0LL; i != 40; i += 8LL )
{
v1 = stacktraces;
free(*(void **)((char *)stacktraces + i));
}
for ( j = 0LL; j != 64; j += 8LL )
{
v3 = sym_name;
free(*(void **)((char *)sym_name + j));
v4 = sym_print;
free(*(void **)((char *)sym_print + j));
}
free(v1);
free(v3);
free(v4);
free(debug_buff);
}

canonical_decompiled_code:
void func2()
{
__int64 i; // rbx
void *v1; // r13
__int64 j; // rbx
void *v3; // r12
void *v4; // rbp

for ( i = 0LL; i != 40; i += 8LL )
{
v1 = stacktraces;
free(*(void **)((char *)stacktraces + i));
}
for ( j = 0LL; j != 64; j += 8LL )
{
v3 = sym_name;
free(*(void **)((char *)sym_name + j));
v4 = sym_print;
free(*(void **)((char *)sym_print + j));
}
free(v1);
free(v3);
free(v4);
free(debug_buff);
}

original_code:
void stacktracer_destroy()
{
 int i;
 for (i = 0; i < 5; ++i) {
  free(stacktraces[i]);
 }
 for (i = 0; i < 8; ++i) {
  free(sym_name[i]);
  free(sym_print[i]);
 }
 free(stacktraces);
 free(sym_name);
 free(sym_print);
 free(debug_buff);
}


decompiled_code:
unsigned __int64 __fastcall stacktracer_push(char *src)
{
unsigned __int64 result; // rax
int v2; // ebp
int v3; // ebp

result = strlen(src);
if ( result <= 0x800 )
{
v2 = ptr;
result = (unsigned __int64)strcpy(*((char **)stacktraces + ptr), src);
v3 = v2 + 1;
if ( v3 > 4 )
{
ptr = 0;
full = 1;
}
else
{
ptr = v3;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(char *src)
{
unsigned __int64 result; // rax
int v2; // ebp
int v3; // ebp

result = strlen(src);
if ( result <= 0x800 )
{
v2 = ptr;
result = (unsigned __int64)strcpy(*((char **)stacktraces + ptr), src);
v3 = v2 + 1;
if ( v3 > 4 )
{
ptr = 0;
full = 1;
}
else
{
ptr = v3;
}
}
return result;
}

original_code:
void stacktracer_push(char *s)
{
 if (strlen(s) > 1024 * 2)
  return;
 strcpy(stacktraces[ptr], s);
 if (++ptr >= 5) {
  ptr = 0;
  full = 1;
 }
}

variable_types:
s
char *


decompiled_code:
unsigned __int64 __fastcall stacktracer_push_sym(char *s2, char *s)
{
unsigned __int64 result; // rax
unsigned int v3; // er15
char *v4; // r14
__int64 v5; // rbx
char *v6; // r12
int v7; // ebx
__int64 v8; // r12
int v9; // er15

result = strlen(s2);
if ( result <= 0x20 )
{
result = strlen(s);
if ( result <= 0x800 )
{
v3 = sym;
if ( sym <= 0 )
{
LABEL_7:
if ( sym_ptr > 7 )
sym_ptr = 0;
v7 = sym_ptr;
v8 = sym_ptr;
strcpy(*((char **)sym_name + sym_ptr), s2);
strcpy(*((char **)sym_print + v8), s);
v9 = v3 + 1;
result = 7LL;
if ( v9 > 7 )
v9 = 7;
sym = v9;
sym_ptr = v7 + 1;
}
else
{
v4 = (char *)sym_name;
v5 = 0LL;
while ( 1 )
{
v6 = *(char **)&v4[v5];
if ( !strcmp(v6, s2) )
break;
v5 += 8LL;
if ( v5 == 8LL * v3 )
goto LABEL_7;
}
strcpy(v6, s2);
result = (unsigned __int64)strcpy(*(char **)((char *)sym_print + v5), s);
}
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(char *s2, char *s)
{
unsigned __int64 result; // rax
unsigned int v3; // er15
char *v4; // r14
__int64 v5; // rbx
char *v6; // r12
int v7; // ebx
__int64 v8; // r12
int v9; // er15

result = strlen(s2);
if ( result <= 0x20 )
{
result = strlen(s);
if ( result <= 0x800 )
{
v3 = sym;
if ( sym <= 0 )
{
LABEL_7:
if ( sym_ptr > 7 )
sym_ptr = 0;
v7 = sym_ptr;
v8 = sym_ptr;
strcpy(*((char **)sym_name + sym_ptr), s2);
strcpy(*((char **)sym_print + v8), s);
v9 = v3 + 1;
result = 7LL;
if ( v9 > 7 )
v9 = 7;
sym = v9;
sym_ptr = v7 + 1;
}
else
{
v4 = (char *)sym_name;
v5 = 0LL;
while ( 1 )
{
v6 = *(char **)&v4[v5];
if ( !strcmp(v6, s2) )
break;
v5 += 8LL;
if ( v5 == 8LL * v3 )
goto LABEL_7;
}
strcpy(v6, s2);
result = (unsigned __int64)strcpy(*(char **)((char *)sym_print + v5), s);
}
}
}
return result;
}

original_code:
void stacktracer_push_sym(char *symb, char *prnt)
{
 int i;
 if (strlen(symb) > 32
  || strlen(prnt) > 1024 * 2)
  return;
 for (i = 0; i < sym; ++i) {
  if (!strcmp(sym_name[i], symb)) {
   strcpy(sym_name[i], symb);
   strcpy(sym_print[i], prnt);
   return;
  }
 }
 if (sym_ptr >= 8)
  sym_ptr = 0;
 strcpy(sym_name[sym_ptr], symb);
 strcpy(sym_print[sym_ptr], prnt);
 if (++sym >= 8)
  sym = 8 - 1;
 ++sym_ptr;
}

variable_types:
symb
char *

variable_types:
prnt
char *


decompiled_code:
int __fastcall stacktracer_print(const char *a1)
{
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1)
{
return puts(a1);
}

original_code:
void stacktracer_print(char *s)
{
  printf("%s\n", s);
}


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

if ( debug_buff_written )
result = stacktracer_print(debug_buff);
else
result = stacktracer_print("no debug log available");
return result;
}

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

if ( debug_buff_written )
result = func5(debug_buff);
else
result = func5("no debug log available");
return result;
}

original_code:
void stacktracer_barf()
{
 if (debug_buff_written)
  stacktracer_print(debug_buff);
 else
  stacktracer_print("no debug log available");
}


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()
{
__int64 v0; // rbp
__int64 v1; // rbx
char *v2; // rbp
__int64 v3; // rbx
int v4; // ebp
__int64 v5; // rbx
unsigned __int64 v6; // r12
__int64 v7; // rbp
__int64 v8; // rbx

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

canonical_decompiled_code:
void func8()
{
__int64 v0; // rbp
__int64 v1; // rbx
char *v2; // rbp
__int64 v3; // rbx
int v4; // ebp
__int64 v5; // rbx
unsigned __int64 v6; // r12
__int64 v7; // rbp
__int64 v8; // rbx

*debug_buff = 0;
debug_buff_written = 1;
func7("===== DEBUGGING INFO =====");
func7("Evaluation trace:");
if ( full )
{
v4 = ptr;
if ( ptr <= 4 )
{
v5 = 8LL * ptr;
v6 = 8 * (ptr + (unsigned __int64)(unsigned int)(4 - ptr) + 1);
do
{
func7(*(char **)((char *)stacktraces + v5));
v5 += 8LL;
}
while ( v5 != v6 );
}
if ( v4 > 0 )
{
v7 = 8LL * (unsigned int)v4;
v8 = 0LL;
do
{
func7(*(char **)((char *)stacktraces + v8));
v8 += 8LL;
}
while ( v7 != v8 );
}
}
else if ( ptr > 0 )
{
v0 = 8LL * (unsigned int)ptr;
v1 = 0LL;
do
{
func7(*(char **)((char *)stacktraces + v1));
v1 += 8LL;
}
while ( v0 != v1 );
}
func7((char *)&byte_5BB);
func7("Symbols: ");
v2 = (char *)malloc(0x1000uLL);
if ( !v2 )
{
error_msg("malloc failed");
code_error();
}
if ( sym > 0 )
{
v3 = 0LL;
do
{
sprintf(v2, "%s: %s", *((const char **)sym_name + v3), *((const char **)sym_print + v3));
func7(v2);
++v3;
}
while ( sym > (int)v3 );
}
func7("===========================");
func7(" ");
free(v2);
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:
buff
char *


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

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

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

result = (unsigned int)(frames + 1);
frames = result;
if ( (int)result > frames_usage_max )
frames_usage_max = result;
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

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

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

if ( len > 0 )
{
v0 = 0LL;
do
free(*((void **)ptrs + v0++));
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
void *result; // rax
void *v3; // rax

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

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // esi
void *result; // rax
void *v3; // rax

++len;
v1 = alloc;
if ( len >= alloc )
{
alloc += 16;
ptrs = (void *)better_realloc(ptrs, 8LL * (v1 + 16));
v3 = (void *)better_realloc(mark, alloc);
mark = v3;
if ( !ptrs || !v3 )
{
fatal_error_msg("marksweep: realloc has failed");
exit(1);
}
}
*((char *)mark + len - 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;
}


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

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


gc

decompiled_code:
void gc()
{
__int64 v0; // rbx
int v1; // ebp
void *v2; // rdi
_QWORD *v3; // rax
_QWORD *v4; // r13
void *v5; // r12
__int64 v6; // rbp
__int64 i; // rbx
size_t v8; // rbx

marksweep(global);
if ( len <= 0 )
{
v8 = len;
v4 = malloc(8LL * len);
if ( v4 )
{
v5 = malloc(v8);
len = 0;
goto LABEL_17;
}
LABEL_10:
fatal_error_msg("marksweep: malloc failed");
exit(1);
}
v0 = 0LL;
do
{
v2 = (void *)*((_QWORD *)ptrs + v0);
if ( v2 && !*((_BYTE *)mark + v0) )
free(v2);
v1 = len;
++v0;
}
while ( len > (int)v0 );
v3 = malloc(8LL * len);
v4 = v3;
if ( !v3 )
goto LABEL_10;
memcpy(v3, ptrs, 8LL * v1);
v5 = malloc(v1);
memcpy(v5, mark, v1);
len = 0;
if ( v1 > 0 )
{
v6 = (unsigned int)(v1 - 1);
for ( i = 0LL; ; ++i )
{
if ( *((_BYTE *)v5 + i) )
add_ptr(v4[i]);
if ( i == v6 )
break;
}
}
LABEL_17:
free(v4);
free(v5);
}

canonical_decompiled_code:
void func4()
{
__int64 v0; // rbx
int v1; // ebp
void *v2; // rdi
_QWORD *v3; // rax
_QWORD *v4; // r13
void *v5; // r12
__int64 v6; // rbp
__int64 i; // rbx
size_t v8; // rbx

func3(global);
if ( len <= 0 )
{
v8 = len;
v4 = malloc(8LL * len);
if ( v4 )
{
v5 = malloc(v8);
len = 0;
goto LABEL_17;
}
LABEL_10:
fatal_error_msg("marksweep: malloc failed");
exit(1);
}
v0 = 0LL;
do
{
v2 = (void *)*((_QWORD *)ptrs + v0);
if ( v2 && !*((_BYTE *)mark + v0) )
free(v2);
v1 = len;
++v0;
}
while ( len > (int)v0 );
v3 = malloc(8LL * len);
v4 = v3;
if ( !v3 )
goto LABEL_10;
memcpy(v3, ptrs, 8LL * v1);
v5 = malloc(v1);
memcpy(v5, mark, v1);
len = 0;
if ( v1 > 0 )
{
v6 = (unsigned int)(v1 - 1);
for ( i = 0LL; ; ++i )
{
if ( *((_BYTE *)v5 + i) )
func1(v4[i]);
if ( i == v6 )
break;
}
}
LABEL_17:
free(v4);
free(v5);
}

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


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


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

LOBYTE(result) = 1;
if ( a1 <= 0x29u )
LOBYTE(result) = ((0x30100000600uLL >> a1) ^ 1) & 1;
return (unsigned __int8)result;
}

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

LOBYTE(result) = 1;
if ( a1 <= 0x29u )
LOBYTE(result) = ((0x30100000600uLL >> a1) ^ 1) & 1;
return (unsigned __int8)result;
}

variable_types: c char


build

decompiled_code:
unsigned __int8 *__fastcall build(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v3; // r12
char *v4; // r14
const char *v5; // rbx
__int64 v6; // rbp
size_t v7; // rax
char *v8; // rbx
char v9; // al
__int64 v10; // rbx
size_t v11; // rax
__int64 v12; // rax
char *v14; // rbp
__int64 v15; // r12
int v16; // ebp
unsigned __int8 v17; // al
unsigned __int8 v18; // bl
unsigned __int8 *v19; // r15
int v20; // ebp
signed __int8 v21; // di
char *v22; // rbx
int i; // er15

v3 = a2;
v4 = (char *)malloc(0x20uLL);
if ( !v4 )
{
error_msg("malloc failed");
code_error();
}
v5 = abbrev;
if ( !abbrev )
{
LABEL_7:
if ( *a2 == 40 )
{
v8 = (char *)(a2 + 1);
*(_DWORD *)(a1 + 8) = 2;
*(_DWORD *)(a1 + 24) = 0;
v9 = a2[1];
if ( v9 != 41 && v9 )
{
while ( 1 )
{
if ( v9 == 32 || v9 == 9 )
{
v14 = v8 + 1;
v9 = v8[1];
if ( !v9 )
{
v3 = (unsigned __int8 *)(v8 + 2);
goto LABEL_47;
}
}
else
{
v15 = new_list();
v14 = (char *)build(v15, v8);
if ( v14 == v8 )
break;
add_child(a1, v15);
v9 = *v14;
if ( *v14 == 41 || !v9 )
{
v8 = v14;
break;
}
}
v8 = v14;
}
}
v3 = (unsigned __int8 *)(v8 + 1);
if ( *v8 != 41 )
{
LABEL_47:
error_msg("Error: ) expected");
code_error();
}
goto LABEL_12;
}
v16 = isnum((unsigned int)(char)*a2);
if ( v16 )
{
v20 = 1;
if ( *a2 != 45 )
{
LABEL_34:
v21 = *v3;
v22 = v4;
for ( i = 0; *v3; v21 = *v3 )
{
if ( !(unsigned int)isnum((unsigned int)v21) )
break;
*v22++ = *v3++;
if ( ++i > 31 )
{
error_msg("numeral too long");
code_error();
}
}
*v22 = 0;
*(_DWORD *)(a1 + 8) = 1;
_isoc99_sscanf(v4, "%d", a1 + 12);
*(_DWORD *)(a1 + 12) *= v20;
goto LABEL_12;
}
}
else
{
v17 = *a2;
if ( *a2 != 45 )
{
if ( v17 == 32 || v17 == 9 )
{
do
{
do
++v3;
while ( *v3 == 32 );
}
while ( *v3 == 9 );
}
v18 = *v3;
v19 = (unsigned __int8 *)v4;
if ( !*v3 )
goto LABEL_45;
goto LABEL_30;
}
if ( ((*_ctype_b_loc())[(char)a2[1]] & 8) == 0 )
{
v18 = *a2;
LABEL_30:
v19 = (unsigned __int8 *)v4;
do
{
if ( !(unsigned int)symbol_name_char(v18) )
break;
++v3;
*v19++ = v18;
if ( ++v16 > 31 )
{
error_msg("symbol name too long");
code_error();
}
v18 = *v3;
}
while ( *v3 );
LABEL_45:
*v19 = 0;
*(_DWORD *)(a1 + 8) = 0;
strcpy(*(char **)a1, v4);
goto LABEL_12;
}
}
v3 = a2 + 1;
v20 = -1;
goto LABEL_34;
}
v6 = 0LL;
while ( 1 )
{
v7 = strlen(v5);
if ( !strncmp(v5, (const char *)a2, v7) )
break;
++v6;
v5 = (&abbrev)[2 * v6];
if ( !v5 )
goto LABEL_7;
}
v10 = new_list();
v11 = strlen((&abbrev)[2 * (int)v6]);
v3 = (unsigned __int8 *)build(v10, &a2[v11]);
v12 = mksym((&abbrev)[2 * (int)v6 + 1]);
add_child(a1, v12);
add_child(a1, v10);
*(_DWORD *)(a1 + 8) = 2;
LABEL_12:
free(v4);
return v3;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func1(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v3; // r12
char *v4; // r14
const char *v5; // rbx
__int64 v6; // rbp
size_t v7; // rax
char *v8; // rbx
char v9; // al
__int64 v10; // rbx
size_t v11; // rax
__int64 v12; // rax
char *v14; // rbp
__int64 v15; // r12
int v16; // ebp
unsigned __int8 v17; // al
unsigned __int8 v18; // bl
unsigned __int8 *v19; // r15
int v20; // ebp
signed __int8 v21; // di
char *v22; // rbx
int i; // er15

v3 = a2;
v4 = (char *)malloc(0x20uLL);
if ( !v4 )
{
error_msg("malloc failed");
code_error();
}
v5 = abbrev;
if ( !abbrev )
{
LABEL_7:
if ( *a2 == 40 )
{
v8 = (char *)(a2 + 1);
*(_DWORD *)(a1 + 8) = 2;
*(_DWORD *)(a1 + 24) = 0;
v9 = a2[1];
if ( v9 != 41 && v9 )
{
while ( 1 )
{
if ( v9 == 32 || v9 == 9 )
{
v14 = v8 + 1;
v9 = v8[1];
if ( !v9 )
{
v3 = (unsigned __int8 *)(v8 + 2);
goto LABEL_47;
}
}
else
{
v15 = new_list();
v14 = (char *)func1(v15, v8);
if ( v14 == v8 )
break;
add_child(a1, v15);
v9 = *v14;
if ( *v14 == 41 || !v9 )
{
v8 = v14;
break;
}
}
v8 = v14;
}
}
v3 = (unsigned __int8 *)(v8 + 1);
if ( *v8 != 41 )
{
LABEL_47:
error_msg("Error: ) expected");
code_error();
}
goto LABEL_12;
}
v16 = isnum((unsigned int)(char)*a2);
if ( v16 )
{
v20 = 1;
if ( *a2 != 45 )
{
LABEL_34:
v21 = *v3;
v22 = v4;
for ( i = 0; *v3; v21 = *v3 )
{
if ( !(unsigned int)isnum((unsigned int)v21) )
break;
*v22++ = *v3++;
if ( ++i > 31 )
{
error_msg("numeral too long");
code_error();
}
}
*v22 = 0;
*(_DWORD *)(a1 + 8) = 1;
_isoc99_sscanf(v4, "%d", a1 + 12);
*(_DWORD *)(a1 + 12) *= v20;
goto LABEL_12;
}
}
else
{
v17 = *a2;
if ( *a2 != 45 )
{
if ( v17 == 32 || v17 == 9 )
{
do
{
do
++v3;
while ( *v3 == 32 );
}
while ( *v3 == 9 );
}
v18 = *v3;
v19 = (unsigned __int8 *)v4;
if ( !*v3 )
goto LABEL_45;
goto LABEL_30;
}
if ( ((*_ctype_b_loc())[(char)a2[1]] & 8) == 0 )
{
v18 = *a2;
LABEL_30:
v19 = (unsigned __int8 *)v4;
do
{
if ( !(unsigned int)func0(v18) )
break;
++v3;
*v19++ = v18;
if ( ++v16 > 31 )
{
error_msg("symbol name too long");
code_error();
}
v18 = *v3;
}
while ( *v3 );
LABEL_45:
*v19 = 0;
*(_DWORD *)(a1 + 8) = 0;
strcpy(*(char **)a1, v4);
goto LABEL_12;
}
}
v3 = a2 + 1;
v20 = -1;
goto LABEL_34;
}
v6 = 0LL;
while ( 1 )
{
v7 = strlen(v5);
if ( !strncmp(v5, (const char *)a2, v7) )
break;
++v6;
v5 = (&abbrev)[2 * v6];
if ( !v5 )
goto LABEL_7;
}
v10 = new_list();
v11 = strlen((&abbrev)[2 * (int)v6]);
v3 = (unsigned __int8 *)func1(v10, &a2[v11]);
v12 = mksym((&abbrev)[2 * (int)v6 + 1]);
add_child(a1, v12);
add_child(a1, v10);
*(_DWORD *)(a1 + 8) = 2;
LABEL_12:
free(v4);
return v3;
}

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


decompiled_code:
char *__fastcall printout_iter(const char **a1, int a2, char *a3)
{
const char **v3; // rbx
char *result; // rax
int v6; // eax
char *v7; // rax
__int64 v8; // r14
int v9; // er13
char *v10; // rax
__int64 v11; // rax
int v12; // edx
__int64 v13; // rax
const char *v14; // rax
__int64 v15; // rdx
int v16; // ecx

v3 = a1;
result = (char *)*((unsigned int *)a1 + 2);
if ( (_DWORD)result == 1 )
{
sprintf(buf, "%d", *((unsigned int *)a1 + 3));
return strcat(a3, buf);
}
if ( (_DWORD)result )
{
switch ( (_DWORD)result )
{
case 2:
sprintf(buf, "(%s", *a1);
strcat(a3, buf);
v8 = 0LL;
v9 = 0;
if ( *((int *)a1 + 6) > 0 )
{
while ( 1 )
{
printout_iter(*(_QWORD *)&a1[4][v8], (unsigned int)(a2 + 1), a3);
if ( *((_DWORD *)a1 + 6) <= ++v9 )
break;
if ( v9 > 0 )
{
*(_WORD *)buf = 32;
strcat(a3, buf);
}
v8 += 8LL;
}
}
goto LABEL_39;
case 4:
sprintf(buf, "#<CLOSURE:%p>", a1[2]);
return strcat(a3, buf);
case 5:
v10 = buf;
if ( *((_DWORD *)a1 + 3) )
*(_WORD *)buf = 29731;
else
*(_WORD *)buf = 26147;
v10[2] = 0;
result = strcat(a3, buf);
break;
case 3:
v6 = *((_DWORD *)a1 + 6);
if ( v6 != 2 )
{
if ( !v6 )
{
v7 = buf;
*(_WORD *)buf = 10536;
v7[2] = 0;
return strcat(a3, buf);
}
goto LABEL_35;
}
v11 = *((_QWORD *)a1[4] + 1);
v12 = *(_DWORD *)(v11 + 8);
if ( v12 )
{
if ( v12 != 3 || *(_DWORD *)(v11 + 24) )
{
LABEL_26:
if ( *(_DWORD *)(v11 + 24) != 2 || v12 != 3 )
{
*(_WORD *)buf = 40;
strcat(a3, buf);
printout_iter(*(_QWORD *)a1[4], (unsigned int)(a2 + 1), a3);
v13 = *((_QWORD *)a1[4] + 1);
if ( *(_DWORD *)(v13 + 8) != 3 || *(_DWORD *)(v13 + 24) )
{
*(_DWORD *)buf = 2108960;
strcat(a3, buf);
printout_iter(*((_QWORD *)a1[4] + 1), (unsigned int)(a2 + 1), a3);
}
goto LABEL_39;
}
LABEL_35:
*(_WORD *)buf = 40;
strcat(a3, buf);
if ( *((_DWORD *)a1 + 6) == 2 )
{
while ( 1 )
{
v14 = v3[4];
v15 = *((_QWORD *)v14 + 1);
if ( !*(_DWORD *)(v15 + 24) )
break;
printout_iter(*(_QWORD *)v14, (unsigned int)(a2 + 1), a3);
*(_WORD *)buf = 32;
strcat(a3, buf);
v3 = (const char **)*((_QWORD *)v3[4] + 1);
if ( *((_DWORD *)v3 + 6) != 2 )
goto LABEL_38;
}
v16 = *(_DWORD *)(v15 + 8);
if ( !v16 )
{
if ( strcmp(*(const char **)v15, "NIL") )
goto LABEL_38;
LABEL_44:
printout_iter(*(_QWORD *)v14, (unsigned int)(a2 + 1), a3);
goto LABEL_39;
}
if ( v16 == 3 )
goto LABEL_44;
}
LABEL_38:
printout_iter(v3, (unsigned int)(a2 + 1), a3);
LABEL_39:
*(_WORD *)buf = 41;
return strcat(a3, buf);
}
}
else if ( strcmp(*(const char **)v11, "NIL") )
{
goto LABEL_26;
}
*(_WORD *)buf = 40;
strcat(a3, buf);
printout_iter(*(_QWORD *)a1[4], (unsigned int)(a2 + 1), a3);
*(_WORD *)buf = 41;
return strcat(a3, buf);
}
}
else
{
strcpy(buf, *a1);
result = strcat(a3, buf);
}
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: 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
unsigned int v1; // ebx
__int16 v3[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]
__int64 v5; // [rsp+10h] [rbp-18h]

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

canonical_decompiled_code:
__int64 func7()
{
int v0; // eax
unsigned int v1; // ebx
__int16 v3[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]
__int64 v5; // [rsp+10h] [rbp-18h]

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

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()
{
unsigned int v0; // ebx
__int16 v2[4]; // [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!");
v0 = 1;
}
else
{
v2[0] = 2;
v2[1] = 0;
v4 = 0LL;
v3 = 0LL;
v0 = fcntl(fd, 6, v2);
close(fd);
fd = -1;
if ( v0 )
{
puts("Strange error while releasing lock");
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
unsigned int v0; // ebx
__int16 v2[4]; // [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!");
v0 = 1;
}
else
{
v2[0] = 2;
v2[1] = 0;
v4 = 0LL;
v3 = 0LL;
v0 = fcntl(fd, 6, v2);
close(fd);
fd = -1;
if ( v0 )
{
puts("Strange error while releasing lock");
v0 = 1;
}
}
return v0;
}

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

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

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; // ebx

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; // ebx
__uid_t v1; // ebp
__gid_t v2; // er12
__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; // ebx
__uid_t v1; // ebp
__gid_t v2; // er12
__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; // ebp
__uid_t v1; // ebx
__gid_t v2; // er12
__uid_t v3; // eax
__uid_t v4; // ebx
__gid_t v5; // ebx
__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; // ebp
__uid_t v1; // ebx
__gid_t v2; // er12
__uid_t v3; // eax
__uid_t v4; // ebx
__gid_t v5; // ebx
__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; // ebx
__uid_t v1; // eax
__uid_t v2; // ebx
__gid_t v3; // ebx
__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; // ebx
__uid_t v1; // eax
__uid_t v2; // ebx
__gid_t v3; // ebx
__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();
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();
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; // eax
_DWORD *v8; // rbp

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

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

if ( argc <= 2 )
{
printf("Usage: %s <user for auth> <correct code>\n", *argv);
v4 = 1;
}
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 )
{
printf("*** Correct auth testcase failed (%d)\n", v3);
v4 = 1;
}
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
{
printf("*** Should-fail auth testcase failed (because we got authenticated) (%d)\n", 0LL);
++v4;
}
}
return v4;
}

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

if ( argc <= 2 )
{
printf("Usage: %s <user for auth> <correct code>\n", *argv);
v4 = 1;
}
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 )
{
printf("*** Correct auth testcase failed (%d)\n", v3);
v4 = 1;
}
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
{
printf("*** Should-fail auth testcase failed (because we got authenticated) (%d)\n", 0LL);
++v4;
}
}
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 v1; // rbx
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rax
__int64 v6; // rax

v1 = a1;
if ( !lessp(a1, my_two) )
{
v3 = difference(a1, my_two);
v4 = cfib(v3);
v5 = difference(a1, my_one);
v6 = cfib(v5);
v1 = plus(v6, v4);
}
return v1;
}

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

v1 = a1;
if ( !lessp(a1, my_two) )
{
v3 = difference(a1, my_two);
v4 = func0(v3);
v5 = difference(a1, my_one);
v6 = func0(v5);
v1 = plus(v6, v4);
}
return v1;
}

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)
{
int v2; // ecx
__int64 v3; // rcx
double *v4; // rdx
int v5; // eax
double result; // xmm0_8

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

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

v2 = *(_DWORD *)(a1 + 4);
if ( v2 <= a2 )
_assert_fail("col < m->cols", "mat.c", 0x2Eu, "mat_sum_col");
if ( *(int *)a1 <= 0 )
return 0.0;
v3 = 8LL * v2;
v4 = (double *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
v5 = 0;
result = 0.0;
do
{
result = result + *v4;
++v5;
v4 = (double *)((char *)v4 + v3);
}
while ( v5 != *(_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
__int64 v3; // rcx
__int64 v4; // rsi
double *v5; // rax
__int64 v6; // rdx
double result; // xmm0_8

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 = *(_QWORD *)(a1 + 8);
v4 = v2 * a2;
v5 = (double *)(v3 + 8 * v4);
v6 = v3 + 8 * ((unsigned int)(v2 - 1) + v4) + 8;
result = 0.0;
do
result = result + *v5++;
while ( v5 != (double *)v6 );
return result;
}

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

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 = *(_QWORD *)(a1 + 8);
v4 = v2 * a2;
v5 = (double *)(v3 + 8 * v4);
v6 = v3 + 8 * ((unsigned int)(v2 - 1) + v4) + 8;
result = 0.0;
do
result = result + *v5++;
while ( v5 != (double *)v6 );
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 i; // rax
char v3; // dl

if ( *(_BYTE *)(a1 + 6) != *(_BYTE *)(a2 + 6) )
return 0xFFFFFFFFLL;
for ( i = 0LL; i != 6; ++i )
{
v3 = *(_BYTE *)(a1 + i);
if ( v3 && v3 != *(_BYTE *)(a2 + i) )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 i; // rax
char v3; // dl

if ( *(_BYTE *)(a1 + 6) != *(_BYTE *)(a2 + 6) )
return 0xFFFFFFFFLL;
for ( i = 0LL; i != 6; ++i )
{
v3 = *(_BYTE *)(a1 + i);
if ( v3 && v3 != *(_BYTE *)(a2 + i) )
return 0xFFFFFFFFLL;
}
return 0LL;
}

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:
void *__fastcall vpack_cpdouble(void **a1, const void **a2, int a3, int a4)
{
char *v5; // r14
char *v6; // r15
size_t v7; // rbx
void *result; // rax

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

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

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

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:
dst
void **

variable_types:
src
void **

variable_types: n int

variable_types: icrwho int

variable_types:
pd
double *

variable_types:
ps
double *