decompiled_code:
__int64 __fastcall dynarr_resize_down(__int64 a1, unsigned int a2)
{
unsigned int v3; // edi
unsigned int v4; // eax
unsigned int v5; // ecx
unsigned int v6; // ebp

v3 = *(_DWORD *)(a1 + 4);
if ( !v3 && a2 )
{
*(_DWORD *)(a1 + 4) = 1;
if ( a2 >= *(_DWORD *)a1 )
{
v6 = 1;
v5 = 1;
goto LABEL_11;
}
v5 = 1;
goto LABEL_6;
}
v4 = v3 >> 1;
if ( a2 >= v3 >> 1 )
{
if ( a2 >= *(_DWORD *)a1 )
return 0;
v5 = v3;
goto LABEL_6;
}
do
{
v5 = v4;
v4 >>= 1;
}
while ( v4 > a2 );
*(_DWORD *)(a1 + 4) = v5;
if ( *(_DWORD *)a1 > a2 )
LABEL_6:
*(_DWORD *)a1 = a2;
v6 = v5 - v3;
if ( v5 != v3 )
LABEL_11:
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
unsigned int v3; // edi
unsigned int v4; // eax
unsigned int v5; // ecx
unsigned int v6; // ebp

v3 = *(_DWORD *)(a1 + 4);
if ( !v3 && a2 )
{
*(_DWORD *)(a1 + 4) = 1;
if ( a2 >= *(_DWORD *)a1 )
{
v6 = 1;
v5 = 1;
goto LABEL_11;
}
v5 = 1;
goto LABEL_6;
}
v4 = v3 >> 1;
if ( a2 >= v3 >> 1 )
{
if ( a2 >= *(_DWORD *)a1 )
return 0;
v5 = v3;
goto LABEL_6;
}
do
{
v5 = v4;
v4 >>= 1;
}
while ( v4 > a2 );
*(_DWORD *)(a1 + 4) = v5;
if ( *(_DWORD *)a1 > a2 )
LABEL_6:
*(_DWORD *)a1 = a2;
v6 = v5 - v3;
if ( v5 != v3 )
LABEL_11:
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), v5);
return v6;
}

original_code:
int dynarr_resize_down(struct dynarr *array, unsigned int size)
{
    int old_size = array->alloc_size;
    if (size && !array->alloc_size)
        array->alloc_size = 1;
    while (size < array->alloc_size / 2)
        array->alloc_size = array->alloc_size / 2;
    if (array->size > size)
        array->size = size;
    int diff = array->alloc_size - old_size;
    if (diff)
        array->arr = (dynarr_info_t *) realloc(array->arr, array->alloc_size * sizeof(dynarr_info_t));
    return diff;
}

canonical_original_code:
int dynarr_resize_down(struct dynarr *array, unsigned int size)
{
    int old_size = array->alloc_size;
    if (size && !array->alloc_size)
        array->alloc_size = 1;
    while (size < array->alloc_size / 2)
        array->alloc_size = array->alloc_size / 2;
    if (array->size > size)
        array->size = size;
    int diff = array->alloc_size - old_size;
    if (diff)
        array->arr = (char *) realloc(array->arr, array->alloc_size * sizeof(dynarr_info_t));
    return diff;
}

variable_types:
size
unsigned int

variable_types: diff int


decompiled_code:
__int64 __fastcall dynarr_remove(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int v3; // edx
unsigned int v4; // esi

result = 0LL;
if ( *(_DWORD *)a1 > a2 )
{
v3 = ~a2 + *(_DWORD *)a1;
if ( v3 )
memmove((void *)(a2 + *(_QWORD *)(a1 + 8)), (const void *)(*(_QWORD *)(a1 + 8) + a2 + 1LL), v3);
v4 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v4;
result = dynarr_resize_down(a1, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int v3; // edx
unsigned int v4; // esi

result = 0LL;
if ( *(_DWORD *)a1 > a2 )
{
v3 = ~a2 + *(_DWORD *)a1;
if ( v3 )
memmove((void *)(a2 + *(_QWORD *)(a1 + 8)), (const void *)(*(_QWORD *)(a1 + 8) + a2 + 1LL), v3);
v4 = *(_DWORD *)a1 - 1;
*(_DWORD *)a1 = v4;
result = func2(a1, v4);
}
return result;
}

original_code:
int dynarr_remove(struct dynarr *array, unsigned int pos)
{
    if (pos >= array->size)
        return 0;
    int rest = array->size - pos - 1;
    if (rest)
        memmove(array->arr + pos, array->arr + pos + 1, rest * sizeof(dynarr_info_t));
    return dynarr_resize_down(array, --array->size);
}

variable_types: struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *

variable_types:
pos
unsigned int

variable_types: rest int

return_type: int


decompiled_code:
__int64 __fastcall dynarr_resize_up(__int64 a1, unsigned int a2)
{
unsigned int v3; // edx
unsigned int v4; // esi
unsigned int v5; // ebp

v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
v4 = *(_DWORD *)(a1 + 4);
if ( v3 >= a2 )
return 0;
}
else
{
*(_DWORD *)(a1 + 4) = 1;
if ( a2 <= 1 )
{
v4 = 1;
v5 = 1;
LABEL_8:
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), v4);
return v5;
}
v4 = 1;
}
do
v4 *= 2;
while ( v4 < a2 );
*(_DWORD *)(a1 + 4) = v4;
v5 = v4 - v3;
if ( v4 != v3 )
goto LABEL_8;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
unsigned int v3; // edx
unsigned int v4; // esi
unsigned int v5; // ebp

v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
v4 = *(_DWORD *)(a1 + 4);
if ( v3 >= a2 )
return 0;
}
else
{
*(_DWORD *)(a1 + 4) = 1;
if ( a2 <= 1 )
{
v4 = 1;
v5 = 1;
LABEL_8:
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), v4);
return v5;
}
v4 = 1;
}
do
v4 *= 2;
while ( v4 < a2 );
*(_DWORD *)(a1 + 4) = v4;
v5 = v4 - v3;
if ( v4 != v3 )
goto LABEL_8;
return v5;
}

original_code:
int dynarr_resize_up(struct dynarr *array, unsigned int size)
{
    int old_size = array->alloc_size;
    if (!array->alloc_size)
        array->alloc_size = 1;
    while (size > array->alloc_size)
        array->alloc_size = array->alloc_size * 2;
    int diff = array->alloc_size - old_size;
    if (diff)
        array->arr = (dynarr_info_t *) realloc(array->arr, array->alloc_size * sizeof(dynarr_info_t));
    return diff;
}

canonical_original_code:
int dynarr_resize_up(struct dynarr *array, unsigned int size)
{
    int old_size = array->alloc_size;
    if (!array->alloc_size)
        array->alloc_size = 1;
    while (size > array->alloc_size)
        array->alloc_size = array->alloc_size * 2;
    int diff = array->alloc_size - old_size;
    if (diff)
        array->arr = (char *) realloc(array->arr, array->alloc_size * sizeof(dynarr_info_t));
    return diff;
}

user_defined_types: struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; }


decompiled_code:
__int64 __fastcall dynarr_append(__int64 a1, char a2)
{
unsigned int v3; // esi
__int64 result; // rax

v3 = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = v3;
result = dynarr_resize_up(a1, v3);
*(_BYTE *)(*(_QWORD *)(a1 + 8) + (unsigned int)(*(_DWORD *)a1 - 1)) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, char a2)
{
unsigned int v3; // esi
__int64 result; // rax

v3 = *(_DWORD *)a1 + 1;
*(_DWORD *)a1 = v3;
result = func4(a1, v3);
*(_BYTE *)(*(_QWORD *)(a1 + 8) + (unsigned int)(*(_DWORD *)a1 - 1)) = a2;
return result;
}

original_code:
int dynarr_append(struct dynarr *array, dynarr_info_t info)
{
    int alloc = dynarr_resize_up(array, ++array->size);
    array->arr[array->size - 1] = info;
    return alloc;
}

canonical_original_code:
int dynarr_append(struct dynarr *array, char info)
{
    int alloc = dynarr_resize_up(array, ++array->size);
    array->arr[array->size - 1] = info;
    return alloc;
}

variable_types: info char

variable_types: alloc int


decompiled_code:
__int64 __fastcall dynarr_insert(__int64 a1, unsigned int a2, char a3)
{
int v4; // esi
unsigned int v5; // er12
unsigned int v7; // esi

v4 = *(_DWORD *)a1;
v5 = 0;
if ( *(_DWORD *)a1 >= a2 )
{
if ( v4 == a2 )
{
v5 = dynarr_append(a1, a3);
}
else
{
v7 = v4 + 1;
*(_DWORD *)a1 = v7;
v5 = dynarr_resize_up(a1, v7);
memmove(
(void *)(*(_QWORD *)(a1 + 8) + a2 + 1LL),
(const void *)(*(_QWORD *)(a1 + 8) + a2),
(int)(*(_DWORD *)a1 + ~a2));
*(_BYTE *)(*(_QWORD *)(a1 + 8) + a2) = a3;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, char a3)
{
int v4; // esi
unsigned int v5; // er12
unsigned int v7; // esi

v4 = *(_DWORD *)a1;
v5 = 0;
if ( *(_DWORD *)a1 >= a2 )
{
if ( v4 == a2 )
{
v5 = func5(a1, a3);
}
else
{
v7 = v4 + 1;
*(_DWORD *)a1 = v7;
v5 = func4(a1, v7);
memmove(
(void *)(*(_QWORD *)(a1 + 8) + a2 + 1LL),
(const void *)(*(_QWORD *)(a1 + 8) + a2),
(int)(*(_DWORD *)a1 + ~a2));
*(_BYTE *)(*(_QWORD *)(a1 + 8) + a2) = a3;
}
}
return v5;
}

original_code:
int dynarr_insert(struct dynarr *array, unsigned int pos, dynarr_info_t info)
{
    if (pos > array->size)
        return 0;
    else if (pos == array->size)
        return dynarr_append(array, info);
    int alloc = dynarr_resize_up(array, ++array->size);
    int move_size = array->size - pos - 1;
    memmove(array->arr + pos + 1, array->arr + pos, move_size * sizeof(dynarr_info_t));
    array->arr[pos] = info;
    return alloc;
}

canonical_original_code:
int dynarr_insert(struct dynarr *array, unsigned int pos, char info)
{
    if (pos > array->size)
        return 0;
    else if (pos == array->size)
        return dynarr_append(array, info);
    int alloc = dynarr_resize_up(array, ++array->size);
    int move_size = array->size - pos - 1;
    memmove(array->arr + pos + 1, array->arr + pos, move_size * sizeof(dynarr_info_t));
    array->arr[pos] = info;
    return alloc;
}


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

if ( *(_DWORD *)(a1 + 4) > a2 )
result = dynarr_resize_down(a1, a2);
else
result = dynarr_resize_up(a1, a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 4) > a2 )
result = func2(a1, a2);
else
result = func4(a1, a2);
return result;
}

original_code:
int dynarr_resize_auto(struct dynarr *array, unsigned int size)
{
    if (array->alloc_size > size)
        return dynarr_resize_down(array, size);
    return dynarr_resize_up(array, size);
}


decompiled_code:
__int64 __fastcall dynarr_clear(_DWORD *a1)
{
*a1 = 0;
return dynarr_resize_down((__int64)a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
*a1 = 0;
return func2((__int64)a1, 0);
}

original_code:
void dynarr_clear(struct dynarr *array)
{
    dynarr_resize_down(array, array->size = 0);
}

return_type: void


runString

decompiled_code:
__int64 __fastcall runString(__int64 a1, __int64 a2)
{
__int64 v2; // rax

ns_init();
v2 = ns_newNamespace(ns_builtinsSpace);
return ns_interpret(a1, a2, 1LL, v2);
}

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

ns_init();
v2 = ns_newNamespace(ns_builtinsSpace);
return ns_interpret(a1, a2, 1LL, v2);
}

original_code:
void runString(const char *str, const char *filename)
{
    ns_init();
    do { ns_interpret(str, filename, 1, ns_newNamespace(ns_builtinsSpace)); } while (0);
}

canonical_original_code:
void runString(char *str, char *filename)
{
    ns_init();
    do { ns_interpret(str, filename, 1, ns_newNamespace(ns_builtinsSpace)); } while (0);
}

variable_types:
str
char *

variable_types:
filename
char *


repl

decompiled_code:
int repl()
{
__int64 v0; // rbx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

ns_init();
v0 = ns_newNamespace(ns_builtinsSpace);
while ( 1 )
{
printf("> ");
if ( !fgets(v2, 1024, stdin) )
break;
putchar(10);
ns_interpret(v2, "<repl>", 1LL, v0);
puts("\n");
}
return putchar(10);
}

canonical_decompiled_code:
int func2()
{
__int64 v0; // rbx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

ns_init();
v0 = ns_newNamespace(ns_builtinsSpace);
while ( 1 )
{
printf("> ");
if ( !fgets(v2, 1024, stdin) )
break;
putchar(10);
ns_interpret(v2, "<repl>", 1LL, v0);
puts("\n");
}
return putchar(10);
}

original_code:
void repl()
{
    char buf[1024];
    ns_init();
    struct ns_namespace *replSpace = ns_newNamespace(ns_builtinsSpace);
    for (;;)
    {
        printf("> ");
        if (!fgets(buf, sizeof(buf), stdin))
            break;
        printf("\n");
        ns_interpret(buf, "<repl>", 1, replSpace);
        printf("\n\n");
    }
    printf("\n");
}

variable_types:
buf
char [1024]

variable_types: struct ns_namespace { struct trie { char initialised; struct ns_obj { short type; union { int bo; int i; double fl; struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *s; void (*f)(); struct ns_block { struct dynarr *file; int lineNo; struct dynarr *str; } b; struct dynarr *sym; } u; } info; struct trie *arr[256]; } *vars; struct ns_namespace *parent; } *

user_defined_types: struct ns_namespace { struct trie *vars; struct ns_namespace *parent; }

user_defined_types: struct trie { char initialised; struct ns_obj info; struct trie *arr[256]; }

user_defined_types: struct ns_obj { short type; union { int bo; int i; double fl; struct dynarr *s; void (*f)(); struct ns_block b; struct dynarr *sym; } u; }


showHelp

decompiled_code:
void __fastcall __noreturn showHelp(const char *a1)
{
printf("%s file\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
printf("%s file\n", a1);
exit(0);
}

original_code:
void showHelp(char *progname)
{
    printf("%s file\n", progname);
    exit(0);
}

variable_types:
progname
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
FILE *v4; // rax
int result; // eax
__int16 v6; // [rsp+0h] [rbp-38h] BYREF
int v7; // [rsp+8h] [rbp-30h]

if ( argc <= 1 )
{
repl();
}
else
{
v3 = argv[1];
if ( !strcmp(v3, "-") )
{
runFile(stdin, (__int64)"<stdin>");
}
else
{
if ( !strcmp(v3, "-h") )
showHelp(*argv);
v4 = fopen(v3, "r");
runFile(v4, (__int64)v3);
}
}
result = 0;
if ( ns_stackSize > 0 )
{
ns_pop(&v6);
result = 0;
if ( v6 == 2 )
result = v7;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
FILE *v4; // rax
int result; // eax
__int16 v6; // [rsp+0h] [rbp-38h] BYREF
int v7; // [rsp+8h] [rbp-30h]

if ( argc <= 1 )
{
func2();
}
else
{
v3 = argv[1];
if ( !strcmp(v3, "-") )
{
func1(stdin, (__int64)"<stdin>");
}
else
{
if ( !strcmp(v3, "-h") )
func3(*argv);
v4 = fopen(v3, "r");
func1(v4, (__int64)v3);
}
}
result = 0;
if ( ns_stackSize > 0 )
{
ns_pop(&v6);
result = 0;
if ( v6 == 2 )
result = v7;
}
return result;
}

original_code:
int main(int argc, char *argv[])
{
    if (argc > 1)
        if (!strcmp(argv[1], "-"))
            runFile(stdin, "<stdin>");
        else if (!strcmp(argv[1], "-h"))
            showHelp(argv[0]);
        else
            runFile(fopen(argv[1], "r"), argv[1]);
    else
        repl();
    struct ns_obj ret;
    if (ns_stackSize > 0 && (ret = ns_pop()).type == TY_INT)
        return ((ret).u.i);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct ns_obj { short type; union { int bo; int i; double fl; struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *s; void (*f)(); struct ns_block { struct dynarr *file; int lineNo; struct dynarr *str; } b; struct dynarr *sym; } u; }


decompiled_code:
__int64 __fastcall ns_addToNamespace(_QWORD *a1)
{
return trie_add(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
return trie_add(*a1);
}

original_code:
void ns_addToNamespace(struct ns_namespace *ns, const char *name, struct ns_obj obj)
{
    trie_add(ns->vars, name, obj);
}

canonical_original_code:
void ns_addToNamespace(struct ns_namespace *ns, char *name, struct ns_obj obj)
{
    trie_add(ns->vars, name, obj);
}

variable_types:
name
char *

variable_types:
obj
struct ns_obj

user_defined_types: struct ns_block { struct dynarr *file; int lineNo; struct dynarr *str; }


decompiled_code:
__int64 __fastcall ns_namemapToNamespace(_QWORD *a1, _QWORD *a2)
{
_QWORD *i; // rbx
__int64 result; // rax

for ( i = a2; *i; i += 5 )
result = ns_addToNamespace(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _QWORD *a2)
{
_QWORD *i; // rbx
__int64 result; // rax

for ( i = a2; *i; i += 5 )
result = func0(a1);
return result;
}

original_code:
void ns_namemapToNamespace(struct ns_namespace *ns, struct ns_namemap *nm)
{
    for (; nm->key; ++nm)
        ns_addToNamespace(ns, nm->key, nm->obj);
}

variable_types: struct ns_namemap { char *key; struct ns_obj obj; } *


decompiled_code:
__int64 __fastcall ns_searchNamespace(_QWORD *a1, __int64 a2)
{
return trie_get(*a1, a2, &ns_defaultObj);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
return trie_get(*a1, a2, &ns_defaultObj);
}

original_code:
struct ns_obj *ns_searchNamespace(struct ns_namespace *ns, const char *name)
{
    return trie_get(ns->vars, name, &ns_defaultObj);
}

canonical_original_code:
struct ns_obj *ns_searchNamespace(struct ns_namespace *ns, char *name)
{
    return trie_get(ns->vars, name, &ns_defaultObj);
}

variable_types: struct ns_namespace { struct trie { char initialised; struct ns_obj info; struct trie *arr[256]; } *vars; struct ns_namespace *parent; } *

return_type: struct ns_obj { short type; union { int bo; int i; double fl; struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *s; void (*f)(); struct ns_block { struct dynarr *file; int lineNo; struct dynarr *str; } b; struct dynarr *sym; } u; } *


decompiled_code:
void *__fastcall ns_searchNamespaceInherit(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbx
void *result; // rax

v2 = a1;
if ( !a1 )
return &ns_defaultObj;
do
{
result = (void *)ns_searchNamespace(v2, a2);
if ( result != &ns_defaultObj )
break;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
return result;
}

canonical_decompiled_code:
void *__fastcall func3(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbx
void *result; // rax

v2 = a1;
if ( !a1 )
return &ns_defaultObj;
do
{
result = (void *)func2(v2, a2);
if ( result != &ns_defaultObj )
break;
v2 = (_QWORD *)v2[1];
}
while ( v2 );
return result;
}

original_code:
struct ns_obj *ns_searchNamespaceInherit(struct ns_namespace *ns, const char *name)
{
    struct ns_obj *obj;
    for (; ns; ns = ns->parent)
        if ((obj = ns_searchNamespace(ns, name)) != &ns_defaultObj)
            return obj;
    return &ns_defaultObj;
}

canonical_original_code:
struct ns_obj *ns_searchNamespaceInherit(struct ns_namespace *ns, char *name)
{
    struct ns_obj *obj;
    for (; ns; ns = ns->parent)
        if ((obj = ns_searchNamespace(ns, name)) != &ns_defaultObj)
            return obj;
    return &ns_defaultObj;
}

variable_types: struct ns_obj { short type; union { int bo; int i; double fl; struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *s; void (*f)(); struct ns_block { struct dynarr *file; int lineNo; struct dynarr *str; } b; struct dynarr *sym; } u; } *


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

ns_initStack();
ns_initBuiltinsSpace();
result = ns_builtinsSpace;
ns_currNamespace = ns_builtinsSpace;
return result;
}

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

ns_initStack();
ns_initBuiltinsSpace();
result = ns_builtinsSpace;
ns_currNamespace = ns_builtinsSpace;
return result;
}

original_code:
void ns_init()
{
    ns_initStack();
    ns_initBuiltinsSpace();
    ns_currNamespace = ns_builtinsSpace;
}


decompiled_code:
_QWORD *ns_pushContext()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
result[1] = 0LL;
*((_DWORD *)result + 6) = 1;
*result = ns_currContext;
ns_currContext = result;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
result[1] = 0LL;
*((_DWORD *)result + 6) = 1;
*result = ns_currContext;
ns_currContext = result;
return result;
}

original_code:
struct ns_interpContext *ns_pushContext()
{
    struct ns_interpContext *newCon = malloc(sizeof(struct ns_interpContext));
    newCon->line = 0;
    newCon->lineNo = 1;
    newCon->parent = ns_currContext;
    return ns_currContext = newCon;
}

variable_types: struct ns_interpContext { struct ns_interpContext *parent; char *line; char *filename; int lineNo; } *


decompiled_code:
void ns_popContext()
{
void *v0; // rbx

v0 = *(void **)ns_currContext;
free(ns_currContext);
ns_currContext = v0;
}

canonical_decompiled_code:
void func2()
{
void *v0; // rbx

v0 = *(void **)ns_currContext;
free(ns_currContext);
ns_currContext = v0;
}

original_code:
void ns_popContext()
{
    struct ns_interpContext *parent = ns_currContext->parent;
    free(ns_currContext);
    ns_currContext = parent;
}

user_defined_types: struct ns_interpContext { struct ns_interpContext *parent; char *line; char *filename; int lineNo; }


decompiled_code:
void ns_printContext()
{
const char **v0; // rbp
const char *v1; // rbx
char v2; // di
const unsigned __int16 *v3; // rdx

v0 = (const char **)ns_currContext;
if ( ns_currContext )
{
do
{
fprintf(stderr, "%s:%d:\t", v0[2], *((unsigned int *)v0 + 6));
v1 = v0[1];
v3 = *_ctype_b_loc();
while ( 1 )
{
v2 = *v1;
if ( (v3[*v1] & 0x2000) == 0 )
break;
++v1;
}
if ( v2 && v2 != 10 )
{
do
{
++v1;
putc(v2, stderr);
v2 = *v1;
}
while ( *v1 && v2 != 10 );
}
putc(10, stderr);
v0 = (const char **)*v0;
}
while ( v0 );
}
}

canonical_decompiled_code:
void func3()
{
const char **v0; // rbp
const char *v1; // rbx
char v2; // di
const unsigned __int16 *v3; // rdx

v0 = (const char **)ns_currContext;
if ( ns_currContext )
{
do
{
fprintf(stderr, "%s:%d:\t", v0[2], *((unsigned int *)v0 + 6));
v1 = v0[1];
v3 = *_ctype_b_loc();
while ( 1 )
{
v2 = *v1;
if ( (v3[*v1] & 0x2000) == 0 )
break;
++v1;
}
if ( v2 && v2 != 10 )
{
do
{
++v1;
putc(v2, stderr);
v2 = *v1;
}
while ( *v1 && v2 != 10 );
}
putc(10, stderr);
v0 = (const char **)*v0;
}
while ( v0 );
}
}

original_code:
void ns_printContext()
{
    struct ns_interpContext *con;
    for (con = ns_currContext; con; con = con->parent)
    {
        fprintf(stderr, "%s:%d:\t", con->filename, con->lineNo);
        const char *c = con->line;
        while (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace))
            ++c;
        while (*c && *c != '\n')
            putc(*c++, stderr);
        putc('\n', stderr);
    }
}

canonical_original_code:
void ns_printContext()
{
    struct ns_interpContext *con;
    for (con = ns_currContext; con; con = con->parent)
    {
        fprintf(stderr, "%s:%d:\t", con->filename, con->lineNo);
        char *c = con->line;
        while (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace))
            ++c;
        while (*c && *c != '\n')
            putc(*c++, stderr);
        putc('\n', stderr);
    }
}

variable_types:
c
char *


decompiled_code:
__int64 __fastcall ns_interpret(unsigned __int8 *a1, unsigned __int64 a2, int a3, __int64 a4)
{
unsigned __int8 *v4; // rbx
unsigned int *v7; // r13
unsigned __int64 v8; // rdx
__int64 v9; // rcx
_QWORD *v10; // r12
int v11; // er15
int v12; // ebp
signed __int8 v13; // r14
const unsigned __int16 **v14; // rax
unsigned __int16 v15; // ax
unsigned __int8 *v16; // rax
__int64 v17; // rdx
__int64 v18; // rcx
signed __int8 v19; // bp
const unsigned __int16 **v20; // rax
signed __int8 v21; // bp
__int64 v22; // rdi
__int16 v23; // ax
__int64 v24; // rdx
__int64 v25; // rcx
signed __int8 v26; // r14
const unsigned __int16 **v27; // rax
char v28; // si
__int64 v29; // rdx
__int64 v30; // rcx
__int64 v31; // r14
__int64 v32; // rbp
char *v33; // rdi
__int64 v34; // rdx
__int64 v35; // rcx
signed __int8 v36; // r14
__int64 v37; // rdx
__int64 v38; // rcx
__int64 v39; // rdx
__int64 v40; // rcx
__int64 result; // rax
int v42; // [rsp+4h] [rbp-E4h]
double v43; // [rsp+8h] [rbp-E0h]
char *s; // [rsp+10h] [rbp-D8h]
__int64 v45; // [rsp+18h] [rbp-D0h]
unsigned int v46; // [rsp+20h] [rbp-C8h]
signed __int8 v47; // [rsp+2Bh] [rbp-BDh]
__int64 v48; // [rsp+50h] [rbp-98h] BYREF
__int64 v49; // [rsp+70h] [rbp-78h] BYREF
__int64 v50; // [rsp+90h] [rbp-58h] BYREF

v4 = a1;
s = (char *)a2;
v7 = (unsigned int *)dynarr_new();
v45 = ns_currNamespace;
ns_currNamespace = a4;
v10 = ns_pushContext();
v10[1] = a1;
*((_DWORD *)v10 + 6) = a3;
v10[2] = a2;
v43 = *(double *)&LC1;
v47 = 0;
v11 = 0;
v42 = 0;
v12 = 0;
while ( 2 )
{
switch ( v12 )
{
case 0:
v13 = *v4;
if ( *v4 == 35 )
{
do
{
v16 = v4++;
v8 = *v4;
}
while ( (_BYTE)v8 != 10 && (_BYTE)v8 );
goto LABEL_34;
}
v14 = _ctype_b_loc();
v8 = (unsigned __int64)*v14;
v15 = (*v14)[v13];
if ( (v15 & 0x800) != 0 )
{
a2 = 0LL;
ns_makeIntObj(&v48, 0LL);
ns_push(&v48, 0LL, v17, v18);
v16 = v4;
v12 = v11;
if ( v11 )
goto LABEL_34;
LABEL_21:
v19 = *v4;
if ( !*v4 )
{
if ( v11 )
goto LABEL_40;
v16 = v4;
v12 = 0;
goto LABEL_35;
}
v20 = _ctype_b_loc();
v8 = (unsigned __int64)*v20;
if ( ((*v20)[v19] & 0x800) != 0 )
{
v8 = (unsigned int)(v19 + 10 * *(_DWORD *)(ns_stack + 8) - 48);
*(_DWORD *)(ns_stack + 8) = v8;
v16 = v4;
v12 = 1;
goto LABEL_34;
}
if ( v19 == 46 )
{
*(_WORD *)ns_stack = 3;
*(double *)(ns_stack + 8) = (double)*(int *)(ns_stack + 8);
v16 = v4;
v12 = 2;
goto LABEL_34;
}
if ( v11 )
{
LABEL_40:
*(_DWORD *)(ns_stack + 8) = -*(_DWORD *)(ns_stack + 8);
v16 = v4;
v11 = 0;
v12 = 0;
goto LABEL_34;
}
v16 = v4;
v12 = 0;
}
else
{
v9 = v4[1];
if ( v13 == 45 && (_BYTE)v9 )
{
v9 = (char)v9;
if ( (*(_BYTE *)(v8 + 2LL * (char)v9 + 1) & 8) != 0 )
{
a2 = 0LL;
ns_makeIntObj(&v48, 0LL);
ns_push(&v48, 0LL, v39, v40);
v16 = v4;
v11 = 1;
v12 = 1;
goto LABEL_34;
}
if ( (v15 & 0x2000) != 0 )
goto LABEL_19;
}
else
{
switch ( v13 )
{
case 39:
case 34:
dynarr_clear(v7, a2, v8, v9);
v16 = v4;
v47 = v13;
v12 = 3;
goto LABEL_34;
case 123:
dynarr_clear(v7, a2, v8, v9);
v16 = v4;
v42 = 1;
v12 = 4;
goto LABEL_34;
case 38:
dynarr_clear(v7, a2, v8, v9);
v16 = v4;
v12 = 5;
goto LABEL_34;
case 0:
goto LABEL_86;
}
if ( (v15 & 0x2000) != 0 )
{
v16 = v4;
if ( v13 == 10 )
goto LABEL_13;
LABEL_19:
++v4;
continue;
}
}
dynarr_clear(v7, a2, v8, v9);
LABEL_28:
v21 = *v4;
if ( *v4 && ((*_ctype_b_loc())[v21] & 0x2000) == 0 )
{
a2 = (unsigned int)v21;
dynarr_append(v7, a2);
v16 = v4;
v12 = 6;
}
else
{
dynarr_append(v7, 0LL);
a2 = *((_QWORD *)v7 + 1);
v22 = ns_currNamespace;
v23 = *(_WORD *)ns_searchNamespaceInherit(ns_currNamespace, a2);
if ( !v23 )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "Variable '%s' not found!", *((const char **)v7 + 1));
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
if ( (unsigned __int16)(v23 - 5) > 2u )
ns_push(v22, a2, v24, v25);
else
ns_execute(v22, a2, v24, v25);
v16 = v4;
v12 = 0;
}
}
goto LABEL_34;
case 1:
goto LABEL_21;
case 2:
v26 = *v4;
if ( *v4 )
{
v27 = _ctype_b_loc();
v8 = (unsigned __int64)*v27;
if ( ((*v27)[v26] & 0x800) != 0 )
{
*(double *)(ns_stack + 8) = (double)(v26 - 48) * v43 + *(double *)(ns_stack + 8);
v43 = v43 * 0.1;
v16 = v4;
goto LABEL_34;
}
if ( v11 )
goto LABEL_45;
v16 = v4;
v12 = 0;
v43 = *(double *)&LC1;
LABEL_34:
if ( *v16 == 10 )
{
LABEL_13:
v8 = (unsigned __int64)(v16 + 1);
v10[1] = v16 + 1;
++*((_DWORD *)v10 + 6);
}
LABEL_35:
v4 = v16 + 1;
if ( !*v16 )
goto LABEL_86;
continue;
}
if ( v11 )
{
LABEL_45:
*(_QWORD *)(ns_stack + 8) ^= LC2;
v16 = v4;
v43 = *(double *)&LC1;
v11 = 0;
v12 = 0;
goto LABEL_34;
}
LABEL_86:
dynarr_free(v7, a2, v8, v9);
ns_popContext();
result = v45;
ns_currNamespace = v45;
return result;
case 3:
v28 = *v4;
if ( *v4 == v47 )
{
if ( v47 != 39 || v4[1] != 39 )
{
dynarr_append(v7, 0LL);
a2 = *((_QWORD *)v7 + 1);
ns_makeStrObjLen(&v49, a2, *v7 - 1);
ns_push(&v49, a2, v29, v30);
v16 = v4;
v12 = 0;
goto LABEL_34;
}
LABEL_55:
++v4;
v28 = 39;
goto LABEL_70;
}
if ( v47 == 39 )
{
if ( v28 == 39 && v4[1] == 39 )
goto LABEL_55;
}
else if ( v28 == 92 )
{
v28 = v4[1];
switch ( v28 )
{
case 'a':
++v4;
v28 = 7;
break;
case 'b':
++v4;
v28 = 8;
break;
case 'f':
++v4;
v28 = 12;
break;
case 'n':
++v4;
v28 = 10;
break;
case 'r':
++v4;
v28 = 13;
break;
case 't':
++v4;
v28 = 9;
break;
case 'v':
++v4;
v28 = 11;
break;
default:
++v4;
break;
}
}
LABEL_70:
a2 = (unsigned int)v28;
dynarr_append(v7, a2);
v16 = v4;
goto LABEL_34;
case 4:
v28 = *v4;
if ( *v4 == 123 )
{
if ( ++v42 <= 0 )
goto LABEL_68;
}
else
{
if ( v28 == 125 )
{
if ( --v42 > 0 )
goto LABEL_70;
LABEL_68:
dynarr_append(v7, 0LL);
v31 = dynarr_new_alloc(*v7);
*(_DWORD *)v31 = *v7;
strcpy(*(char **)(v31 + 8), *((const char **)v7 + 1));
v46 = strlen(s);
v32 = dynarr_new_alloc(v46);
*(_DWORD *)v32 = v46 + 1;
v33 = *(char **)(v32 + 8);
a2 = (unsigned __int64)s;
strcpy(v33, s);
ns_push(v33, s, v34, v35);
v16 = v4;
v12 = 0;
goto LABEL_34;
}
if ( v42 <= 0 )
goto LABEL_68;
if ( !v28 )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "ns_interpret: Unexpected end of file! Expected %d closing braces.", (unsigned int)v42);
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
}
goto LABEL_70;
case 5:
v36 = *v4;
if ( *v4 && ((*_ctype_b_loc())[v36] & 0x2000) == 0 )
{
a2 = (unsigned int)v36;
dynarr_append(v7, a2);
v16 = v4;
}
else
{
dynarr_append(v7, 0LL);
a2 = *((_QWORD *)v7 + 1);
ns_makeSymObjLen(&v50, a2, *v7 - 1);
ns_push(&v50, a2, v37, v38);
v16 = v4;
v12 = 0;
}
goto LABEL_34;
case 6:
goto LABEL_28;
default:
v16 = v4;
goto LABEL_34;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1, unsigned __int64 a2, int a3, __int64 a4)
{
unsigned __int8 *v4; // rbx
unsigned int *v7; // r13
unsigned __int64 v8; // rdx
__int64 v9; // rcx
_QWORD *v10; // r12
int v11; // er15
int v12; // ebp
signed __int8 v13; // r14
const unsigned __int16 **v14; // rax
unsigned __int16 v15; // ax
unsigned __int8 *v16; // rax
__int64 v17; // rdx
__int64 v18; // rcx
signed __int8 v19; // bp
const unsigned __int16 **v20; // rax
signed __int8 v21; // bp
__int64 v22; // rdi
__int16 v23; // ax
__int64 v24; // rdx
__int64 v25; // rcx
signed __int8 v26; // r14
const unsigned __int16 **v27; // rax
char v28; // si
__int64 v29; // rdx
__int64 v30; // rcx
__int64 v31; // r14
__int64 v32; // rbp
char *v33; // rdi
__int64 v34; // rdx
__int64 v35; // rcx
signed __int8 v36; // r14
__int64 v37; // rdx
__int64 v38; // rcx
__int64 v39; // rdx
__int64 v40; // rcx
__int64 result; // rax
int v42; // [rsp+4h] [rbp-E4h]
double v43; // [rsp+8h] [rbp-E0h]
char *s; // [rsp+10h] [rbp-D8h]
__int64 v45; // [rsp+18h] [rbp-D0h]
unsigned int v46; // [rsp+20h] [rbp-C8h]
signed __int8 v47; // [rsp+2Bh] [rbp-BDh]
__int64 v48; // [rsp+50h] [rbp-98h] BYREF
__int64 v49; // [rsp+70h] [rbp-78h] BYREF
__int64 v50; // [rsp+90h] [rbp-58h] BYREF

v4 = a1;
s = (char *)a2;
v7 = (unsigned int *)dynarr_new();
v45 = ns_currNamespace;
ns_currNamespace = a4;
v10 = func1();
v10[1] = a1;
*((_DWORD *)v10 + 6) = a3;
v10[2] = a2;
v43 = *(double *)&LC1;
v47 = 0;
v11 = 0;
v42 = 0;
v12 = 0;
while ( 2 )
{
switch ( v12 )
{
case 0:
v13 = *v4;
if ( *v4 == 35 )
{
do
{
v16 = v4++;
v8 = *v4;
}
while ( (_BYTE)v8 != 10 && (_BYTE)v8 );
goto LABEL_34;
}
v14 = _ctype_b_loc();
v8 = (unsigned __int64)*v14;
v15 = (*v14)[v13];
if ( (v15 & 0x800) != 0 )
{
a2 = 0LL;
ns_makeIntObj(&v48, 0LL);
ns_push(&v48, 0LL, v17, v18);
v16 = v4;
v12 = v11;
if ( v11 )
goto LABEL_34;
LABEL_21:
v19 = *v4;
if ( !*v4 )
{
if ( v11 )
goto LABEL_40;
v16 = v4;
v12 = 0;
goto LABEL_35;
}
v20 = _ctype_b_loc();
v8 = (unsigned __int64)*v20;
if ( ((*v20)[v19] & 0x800) != 0 )
{
v8 = (unsigned int)(v19 + 10 * *(_DWORD *)(ns_stack + 8) - 48);
*(_DWORD *)(ns_stack + 8) = v8;
v16 = v4;
v12 = 1;
goto LABEL_34;
}
if ( v19 == 46 )
{
*(_WORD *)ns_stack = 3;
*(double *)(ns_stack + 8) = (double)*(int *)(ns_stack + 8);
v16 = v4;
v12 = 2;
goto LABEL_34;
}
if ( v11 )
{
LABEL_40:
*(_DWORD *)(ns_stack + 8) = -*(_DWORD *)(ns_stack + 8);
v16 = v4;
v11 = 0;
v12 = 0;
goto LABEL_34;
}
v16 = v4;
v12 = 0;
}
else
{
v9 = v4[1];
if ( v13 == 45 && (_BYTE)v9 )
{
v9 = (char)v9;
if ( (*(_BYTE *)(v8 + 2LL * (char)v9 + 1) & 8) != 0 )
{
a2 = 0LL;
ns_makeIntObj(&v48, 0LL);
ns_push(&v48, 0LL, v39, v40);
v16 = v4;
v11 = 1;
v12 = 1;
goto LABEL_34;
}
if ( (v15 & 0x2000) != 0 )
goto LABEL_19;
}
else
{
switch ( v13 )
{
case 39:
case 34:
dynarr_clear(v7, a2, v8, v9);
v16 = v4;
v47 = v13;
v12 = 3;
goto LABEL_34;
case 123:
dynarr_clear(v7, a2, v8, v9);
v16 = v4;
v42 = 1;
v12 = 4;
goto LABEL_34;
case 38:
dynarr_clear(v7, a2, v8, v9);
v16 = v4;
v12 = 5;
goto LABEL_34;
case 0:
goto LABEL_86;
}
if ( (v15 & 0x2000) != 0 )
{
v16 = v4;
if ( v13 == 10 )
goto LABEL_13;
LABEL_19:
++v4;
continue;
}
}
dynarr_clear(v7, a2, v8, v9);
LABEL_28:
v21 = *v4;
if ( *v4 && ((*_ctype_b_loc())[v21] & 0x2000) == 0 )
{
a2 = (unsigned int)v21;
dynarr_append(v7, a2);
v16 = v4;
v12 = 6;
}
else
{
dynarr_append(v7, 0LL);
a2 = *((_QWORD *)v7 + 1);
v22 = ns_currNamespace;
v23 = *(_WORD *)ns_searchNamespaceInherit(ns_currNamespace, a2);
if ( !v23 )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "Variable '%s' not found!", *((const char **)v7 + 1));
putc(10, stderr);
putc(10, stderr);
func3();
exit(1);
}
if ( (unsigned __int16)(v23 - 5) > 2u )
ns_push(v22, a2, v24, v25);
else
ns_execute(v22, a2, v24, v25);
v16 = v4;
v12 = 0;
}
}
goto LABEL_34;
case 1:
goto LABEL_21;
case 2:
v26 = *v4;
if ( *v4 )
{
v27 = _ctype_b_loc();
v8 = (unsigned __int64)*v27;
if ( ((*v27)[v26] & 0x800) != 0 )
{
*(double *)(ns_stack + 8) = (double)(v26 - 48) * v43 + *(double *)(ns_stack + 8);
v43 = v43 * 0.1;
v16 = v4;
goto LABEL_34;
}
if ( v11 )
goto LABEL_45;
v16 = v4;
v12 = 0;
v43 = *(double *)&LC1;
LABEL_34:
if ( *v16 == 10 )
{
LABEL_13:
v8 = (unsigned __int64)(v16 + 1);
v10[1] = v16 + 1;
++*((_DWORD *)v10 + 6);
}
LABEL_35:
v4 = v16 + 1;
if ( !*v16 )
goto LABEL_86;
continue;
}
if ( v11 )
{
LABEL_45:
*(_QWORD *)(ns_stack + 8) ^= LC2;
v16 = v4;
v43 = *(double *)&LC1;
v11 = 0;
v12 = 0;
goto LABEL_34;
}
LABEL_86:
dynarr_free(v7, a2, v8, v9);
func2();
result = v45;
ns_currNamespace = v45;
return result;
case 3:
v28 = *v4;
if ( *v4 == v47 )
{
if ( v47 != 39 || v4[1] != 39 )
{
dynarr_append(v7, 0LL);
a2 = *((_QWORD *)v7 + 1);
ns_makeStrObjLen(&v49, a2, *v7 - 1);
ns_push(&v49, a2, v29, v30);
v16 = v4;
v12 = 0;
goto LABEL_34;
}
LABEL_55:
++v4;
v28 = 39;
goto LABEL_70;
}
if ( v47 == 39 )
{
if ( v28 == 39 && v4[1] == 39 )
goto LABEL_55;
}
else if ( v28 == 92 )
{
v28 = v4[1];
switch ( v28 )
{
case 'a':
++v4;
v28 = 7;
break;
case 'b':
++v4;
v28 = 8;
break;
case 'f':
++v4;
v28 = 12;
break;
case 'n':
++v4;
v28 = 10;
break;
case 'r':
++v4;
v28 = 13;
break;
case 't':
++v4;
v28 = 9;
break;
case 'v':
++v4;
v28 = 11;
break;
default:
++v4;
break;
}
}
LABEL_70:
a2 = (unsigned int)v28;
dynarr_append(v7, a2);
v16 = v4;
goto LABEL_34;
case 4:
v28 = *v4;
if ( *v4 == 123 )
{
if ( ++v42 <= 0 )
goto LABEL_68;
}
else
{
if ( v28 == 125 )
{
if ( --v42 > 0 )
goto LABEL_70;
LABEL_68:
dynarr_append(v7, 0LL);
v31 = dynarr_new_alloc(*v7);
*(_DWORD *)v31 = *v7;
strcpy(*(char **)(v31 + 8), *((const char **)v7 + 1));
v46 = strlen(s);
v32 = dynarr_new_alloc(v46);
*(_DWORD *)v32 = v46 + 1;
v33 = *(char **)(v32 + 8);
a2 = (unsigned __int64)s;
strcpy(v33, s);
ns_push(v33, s, v34, v35);
v16 = v4;
v12 = 0;
goto LABEL_34;
}
if ( v42 <= 0 )
goto LABEL_68;
if ( !v28 )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "ns_interpret: Unexpected end of file! Expected %d closing braces.", (unsigned int)v42);
putc(10, stderr);
putc(10, stderr);
func3();
exit(1);
}
}
goto LABEL_70;
case 5:
v36 = *v4;
if ( *v4 && ((*_ctype_b_loc())[v36] & 0x2000) == 0 )
{
a2 = (unsigned int)v36;
dynarr_append(v7, a2);
v16 = v4;
}
else
{
dynarr_append(v7, 0LL);
a2 = *((_QWORD *)v7 + 1);
ns_makeSymObjLen(&v50, a2, *v7 - 1);
ns_push(&v50, a2, v37, v38);
v16 = v4;
v12 = 0;
}
goto LABEL_34;
case 6:
goto LABEL_28;
default:
v16 = v4;
goto LABEL_34;
}
}
}

original_code:
void ns_interpret(const char *code, const char *filename, int lineNo, struct
        ns_namespace *ns)
{
    enum
    {
        MD_NONE,
        MD_READINT,
        MD_READFLOATPART,
        MD_READSTR,
        MD_READBLOCK,
        MD_READSYM,
        MD_READVAR,
    };
    int mode = MD_NONE;
    int blockDepth = 0;
    int negative = 0;
    int blockLine;
    char stringChar = 0;
    double floatMult = 0.1;
    const char *curr = code, p;
    struct dynarr *buf = dynarr_new();
    struct ns_namespace *oldns = ns_currNamespace;
    ns_currNamespace = ns;
    struct ns_interpContext *con = ns_pushContext();
    con->line = curr;
    con->lineNo = lineNo;
    con->filename = filename;
    do
    {
        switch (mode)
        {
            case MD_NONE:
                if (*curr == '#')
                {
                    while (*++curr && (*curr != '\n'));
                    --curr;
                }
                else if (((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISdigit) || (*(curr + 1) && (*curr == '-') &&
                            ((*__ctype_b_loc ())[(int) ((*(curr + 1)))] & (unsigned short int) _ISdigit) && (negative = 1)))
                {
                    mode = MD_READINT;
                    ns_push(ns_makeIntObj(0));
                    if (negative)
                        break;
                    goto read_int;
                }
                else if (*curr == '\'' || *curr == '"')
                {
                    stringChar = *curr;
                    mode = MD_READSTR;
                    dynarr_clear(buf);
                    break;
                }
                else if (*curr == '{')
                {
                    mode = MD_READBLOCK;
                    blockDepth = 1;
                    blockLine = con->lineNo;
                    dynarr_clear(buf);
                    break;
                }
                else if (*curr == '&')
                {
                    mode = MD_READSYM;
                    dynarr_clear(buf);
                    break;
                }
                else if (*curr && !((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISspace))
                {
                    mode = MD_READVAR;
                    dynarr_clear(buf);
                    goto get_var;
                }
                break;
            case MD_READINT:
read_int:
                if (*curr && ((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISdigit))
                    ns_stack->obj.u.i = ns_stack->obj.u.i * 10 + *curr - '0';
                else if (*curr == '.')
                {
                    do { (ns_stack->obj).type = TY_FLOAT; ((ns_stack->obj).u.fl) = ((ns_stack->obj).u.i); } while(0);
                    mode = MD_READFLOATPART;
                }
                else
                {
                    if (negative)
                        ns_stack->obj.u.i *= -1;
                    negative = 0;
                    mode = MD_NONE;
                }
                break;
            case MD_READFLOATPART:
                if (*curr && ((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISdigit))
                {
                    ns_stack->obj.u.fl += floatMult * (*curr - '0');
                    floatMult *= 0.1;
                }
                else
                {
                    if (negative)
                        ns_stack->obj.u.fl *= -1;
                    floatMult = 0.1;
                    negative = 0;
                    mode = MD_NONE;
                }
                break;
            case MD_READSTR:
                if (*curr != stringChar ||
                        (stringChar == '\'' && (*(curr + 1) == '\'')))
                {
                    char c = *curr;
                    if (stringChar == '\'')
                    {
                        if (*curr == '\'' && *(curr + 1) == '\'')
                        {
                            c = '\'';
                            ++curr;
                        }
                    }
                    else if (*curr == '\\')
                        switch (*(curr + 1))
                        {
                            case 'n':
                                c = '\n';
                                ++curr;
                                break;
                            case 't':
                                c = '\t';
                                ++curr;
                                break;
                            case 'v':
                                c = '\v';
                                ++curr;
                                break;
                            case 'b':
                                c = '\b';
                                ++curr;
                                break;
                            case 'r':
                                c = '\r';
                                ++curr;
                                break;
                            case 'f':
                                c = '\f';
                                ++curr;
                                break;
                            case 'a':
                                c = '\a';
                                ++curr;
                                break;
                            default:
                                c = *(curr + 1);
                                ++curr;
                                break;
                        }
                    dynarr_append(buf, c);
                }
                else
                {
                    dynarr_append(buf, '\0');
                    ns_push(ns_makeStrObjLen(buf->arr, buf->size - 1));
                    mode = MD_NONE;
                }
                break;
            case MD_READBLOCK:
                if (*curr == '{')
                    ++blockDepth;
                if (*curr == '}')
                    --blockDepth;
                if (blockDepth > 0)
                {
                    if (!*curr)
                        do { fprintf(stderr, "\nError: "); fprintf(stderr, "ns_interpret: Unexpected end of file! " "Expected %d closing braces.", blockDepth); putc('\n', stderr); putc('\n', stderr); ns_printContext(); exit(1); } while (0);
                    dynarr_append(buf, *curr);
                }
                else
                {
                    dynarr_append(buf, '\0');
                    struct ns_obj obj;
                    obj.type = TY_BLOCK;
                    obj.u.b.str = dynarr_new_alloc(buf->size);
                    obj.u.b.str->size = buf->size;
                    strcpy(obj.u.b.str->arr, buf->arr);
                    int len = strlen(filename);
                    obj.u.b.file = dynarr_new_alloc(len);
                    obj.u.b.file->size = len + 1;
                    strcpy(obj.u.b.file->arr, filename);
                    obj.u.b.lineNo = blockLine;
                    ns_push(obj);
                    mode = MD_NONE;
                }
                break;
            case MD_READSYM:
                if (*curr && !((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISspace))
                    dynarr_append(buf, *curr);
                else
                {
                    dynarr_append(buf, '\0');
                    ns_push(ns_makeSymObjLen(buf->arr, buf->size - 1));
                    mode = MD_NONE;
                }
                break;
            case MD_READVAR:
get_var:
                if (*curr && !((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short int) _ISspace))
                    dynarr_append(buf, *curr);
                else
                {
                    dynarr_append(buf, '\0');
                    struct ns_obj obj = *ns_searchNamespaceInherit(ns_currNamespace,
                            buf->arr);
                    if (obj.type != TY_EMPTY)
                        if (((obj).type == TY_FUNC || (obj).type == TY_BLOCK || (obj).type == TY_SYM))
                            ns_execute(obj);
                        else
                            ns_push(obj);
                    else
                        do { fprintf(stderr, "\nError: "); fprintf(stderr, "Variable '%s' not found!", buf->arr); putc('\n', stderr); putc('\n', stderr); ns_printContext(); exit(1); } while (0);
                    mode = MD_NONE;
                }
                break;
        }
        if (*curr == '\n')
        {
            con->line = curr + 1;
            ++con->lineNo;
        }
    } while (*curr++);
    dynarr_free(buf);
    ns_popContext();
    ns_currNamespace = oldns;
}

canonical_original_code:
void ns_interpret(char *code, char *filename, int lineNo, struct ns_namespace *ns)
{
    enum
    {
        MD_NONE,
        MD_READINT,
        MD_READFLOATPART,
        MD_READSTR,
        MD_READBLOCK,
        MD_READSYM,
        MD_READVAR,
    };
    int mode = MD_NONE;
    int blockDepth = 0;
    int negative = 0;
    int blockLine;
    char stringChar = 0;
    double floatMult = 0.1;
    char *curr = code; char p;
    struct dynarr *buf = dynarr_new();
    struct ns_namespace *oldns = ns_currNamespace;
    ns_currNamespace = ns;
    struct ns_interpContext *con = ns_pushContext();
    con->line = curr;
    con->lineNo = lineNo;
    con->filename = filename;
    do
    {
        switch (mode)
        {
            case MD_NONE:
                if (*curr == '#')
                {
                    while (*++curr && (*curr != '\n'));
                    --curr;
                }
                else if (((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISdigit) || (*(curr + 1) && (*curr == '-') &&
                            ((*__ctype_b_loc ())[(int) ((*(curr + 1)))] & (unsigned short) _ISdigit) && (negative = 1)))
                {
                    mode = MD_READINT;
                    ns_push(ns_makeIntObj(0));
                    if (negative)
                        break;
                    goto read_int;
                }
                else if (*curr == '\'' || *curr == '"')
                {
                    stringChar = *curr;
                    mode = MD_READSTR;
                    dynarr_clear(buf);
                    break;
                }
                else if (*curr == '{')
                {
                    mode = MD_READBLOCK;
                    blockDepth = 1;
                    blockLine = con->lineNo;
                    dynarr_clear(buf);
                    break;
                }
                else if (*curr == '&')
                {
                    mode = MD_READSYM;
                    dynarr_clear(buf);
                    break;
                }
                else if (*curr && !((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISspace))
                {
                    mode = MD_READVAR;
                    dynarr_clear(buf);
                    goto get_var;
                }
                break;
            case MD_READINT:
read_int:
                if (*curr && ((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISdigit))
                    ns_stack->obj.u.i = ns_stack->obj.u.i * 10 + *curr - '0';
                else if (*curr == '.')
                {
                    do { (ns_stack->obj).type = TY_FLOAT; ((ns_stack->obj).u.fl) = ((ns_stack->obj).u.i); } while(0);
                    mode = MD_READFLOATPART;
                }
                else
                {
                    if (negative)
                        ns_stack->obj.u.i *= -1;
                    negative = 0;
                    mode = MD_NONE;
                }
                break;
            case MD_READFLOATPART:
                if (*curr && ((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISdigit))
                {
                    ns_stack->obj.u.fl += floatMult * (*curr - '0');
                    floatMult *= 0.1;
                }
                else
                {
                    if (negative)
                        ns_stack->obj.u.fl *= -1;
                    floatMult = 0.1;
                    negative = 0;
                    mode = MD_NONE;
                }
                break;
            case MD_READSTR:
                if (*curr != stringChar ||
                        (stringChar == '\'' && (*(curr + 1) == '\'')))
                {
                    char c = *curr;
                    if (stringChar == '\'')
                    {
                        if (*curr == '\'' && *(curr + 1) == '\'')
                        {
                            c = '\'';
                            ++curr;
                        }
                    }
                    else if (*curr == '\\')
                        switch (*(curr + 1))
                        {
                            case 'n':
                                c = '\n';
                                ++curr;
                                break;
                            case 't':
                                c = '\t';
                                ++curr;
                                break;
                            case 'v':
                                c = '\v';
                                ++curr;
                                break;
                            case 'b':
                                c = '\b';
                                ++curr;
                                break;
                            case 'r':
                                c = '\r';
                                ++curr;
                                break;
                            case 'f':
                                c = '\f';
                                ++curr;
                                break;
                            case 'a':
                                c = '\a';
                                ++curr;
                                break;
                            default:
                                c = *(curr + 1);
                                ++curr;
                                break;
                        }
                    dynarr_append(buf, c);
                }
                else
                {
                    dynarr_append(buf, '\0');
                    ns_push(ns_makeStrObjLen(buf->arr, buf->size - 1));
                    mode = MD_NONE;
                }
                break;
            case MD_READBLOCK:
                if (*curr == '{')
                    ++blockDepth;
                if (*curr == '}')
                    --blockDepth;
                if (blockDepth > 0)
                {
                    if (!*curr)
                        do { fprintf(stderr, "\nError: "); fprintf(stderr, "ns_interpret: Unexpected end of file! " "Expected %d closing braces.", blockDepth); putc('\n', stderr); putc('\n', stderr); ns_printContext(); exit(1); } while (0);
                    dynarr_append(buf, *curr);
                }
                else
                {
                    dynarr_append(buf, '\0');
                    struct ns_obj obj;
                    obj.type = TY_BLOCK;
                    obj.u.b.str = dynarr_new_alloc(buf->size);
                    obj.u.b.str->size = buf->size;
                    strcpy(obj.u.b.str->arr, buf->arr);
                    int len = strlen(filename);
                    obj.u.b.file = dynarr_new_alloc(len);
                    obj.u.b.file->size = len + 1;
                    strcpy(obj.u.b.file->arr, filename);
                    obj.u.b.lineNo = blockLine;
                    ns_push(obj);
                    mode = MD_NONE;
                }
                break;
            case MD_READSYM:
                if (*curr && !((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISspace))
                    dynarr_append(buf, *curr);
                else
                {
                    dynarr_append(buf, '\0');
                    ns_push(ns_makeSymObjLen(buf->arr, buf->size - 1));
                    mode = MD_NONE;
                }
                break;
            case MD_READVAR:
get_var:
                if (*curr && !((*__ctype_b_loc ())[(int) ((*curr))] & (unsigned short) _ISspace))
                    dynarr_append(buf, *curr);
                else
                {
                    dynarr_append(buf, '\0');
                    struct ns_obj obj = *ns_searchNamespaceInherit(ns_currNamespace,
                            buf->arr);
                    if (obj.type != TY_EMPTY)
                        if (((obj).type == TY_FUNC || (obj).type == TY_BLOCK || (obj).type == TY_SYM))
                            ns_execute(obj);
                        else
                            ns_push(obj);
                    else
                        do { fprintf(stderr, "\nError: "); fprintf(stderr, "Variable '%s' not found!", buf->arr); putc('\n', stderr); putc('\n', stderr); ns_printContext(); exit(1); } while (0);
                    mode = MD_NONE;
                }
                break;
        }
        if (*curr == '\n')
        {
            con->line = curr + 1;
            ++con->lineNo;
        }
    } while (*curr++);
    dynarr_free(buf);
    ns_popContext();
    ns_currNamespace = oldns;
}

variable_types:
code
char *

variable_types: lineNo int

variable_types: mode int

variable_types: blockDepth int

variable_types: negative int

variable_types: blockLine int

variable_types: stringChar char

variable_types: floatMult double

variable_types:
curr
char *

variable_types: p char

variable_types: struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *

variable_types: c char

variable_types: len int


decompiled_code:
__m128i *ns_initStack()
{
__m128i *result; // rax

result = (__m128i *)malloc(0x28uLL);
ns_stack = result;
result[2].m128i_i64[0] = 0LL;
*result = _mm_loadu_si128(ns_defaultObj);
result[1] = _mm_loadu_si128(&ns_defaultObj[1]);
ns_stackSize = 0;
return result;
}

canonical_decompiled_code:
__m128i *func0()
{
__m128i *result; // rax

result = (__m128i *)malloc(0x28uLL);
ns_stack = result;
result[2].m128i_i64[0] = 0LL;
*result = _mm_loadu_si128(ns_defaultObj);
result[1] = _mm_loadu_si128(&ns_defaultObj[1]);
ns_stackSize = 0;
return result;
}

original_code:
void ns_initStack()
{
    ns_stack = (struct ns_stack *) malloc(sizeof(struct ns_stack));
    ns_stack->next = 0;
    ns_stack->obj = ns_defaultObj;
    ns_stackSize = 0;
}

user_defined_types: struct ns_stack { struct ns_obj obj; struct ns_stack *next; }


original_code:
struct trie *trie_new()
{
    struct trie *trie = malloc(sizeof(struct trie));
    int i;
    for (i = 0; i < 256; ++i)
        trie->arr[i] = 0;
    trie->initialised = 0;
    return trie;
}

variable_types: struct trie { char initialised; struct ns_obj { short type; union { int bo; int i; double fl; struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *s; void (*f)(); struct ns_block { struct dynarr *file; int lineNo; struct dynarr *str; } b; struct dynarr *sym; } u; } info; struct trie *arr[256]; } *

variable_types: i int


decompiled_code:
void __fastcall trie_free(_QWORD *a1)
{
_QWORD *v1; // rbx

v1 = a1 + 5;
do
{
if ( *v1 )
trie_free();
++v1;
}
while ( v1 != a1 + 261 );
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rbx

v1 = a1 + 5;
do
{
if ( *v1 )
func1();
++v1;
}
while ( v1 != a1 + 261 );
free(a1);
}

original_code:
void trie_free(struct trie *trie)
{
    int i;
    for (i = 0; i < 256; ++i)
        if (trie->arr[i])
            trie_free(trie->arr[i]);
    free(trie);
}


original_code:
void trie_add(struct trie *trie, const char *c, trie_info_t info)
{
    for (; *c; ++c)
        trie = (trie->arr[*c] ? trie->arr[*c] : (trie->arr[*c] = trie_new()));
    trie->info = info;
    trie->initialised = 1;
}

canonical_original_code:
void trie_add(struct trie *trie, char *c, struct ns_obj info)
{
    for (; *c; ++c)
        trie = (trie->arr[*c] ? trie->arr[*c] : (trie->arr[*c] = trie_new()));
    trie->info = info;
    trie->initialised = 1;
}

variable_types:
info
struct ns_obj


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

result = a1;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_WORD *)a1 = 3;
*(double *)(a1 + 8) = a2;
return result;
}

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

result = a1;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0LL;
*(_WORD *)a1 = 3;
*(double *)(a1 + 8) = a2;
return result;
}

original_code:
struct ns_obj ns_makeFloatObj(double fl)
{
    struct ns_obj obj = { TY_FLOAT, { .fl = fl } };
    return obj;
}

variable_types: fl double

variable_types: struct ns_obj { short type; union { int bo; int i; double fl; struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *s; void (*f)(); struct ns_block { struct dynarr *file; int lineNo; struct dynarr *str; } b; struct dynarr *sym; } u; }


decompiled_code:
__int64 __fastcall ns_execute(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, unsigned __int16 a7, __int64 a8, unsigned int a9, __int64 a10)
{
__int64 result; // rax
__int64 v11; // rax
__int64 v12; // rsi
int v13; // edi
unsigned __int16 *v14; // rax
int v15; // er8
int v16; // er9
int v17; // ecx

result = a7;
switch ( a7 )
{
case 6u:
v11 = ns_newNamespace(ns_currNamespace);
result = ns_interpret(*(_QWORD *)(a10 + 8), *(_QWORD *)(a8 + 8), a9, v11);
break;
case 7u:
v12 = *(_QWORD *)(a8 + 8);
v13 = ns_currNamespace;
v14 = (unsigned __int16 *)ns_searchNamespaceInherit(ns_currNamespace, v12);
if ( v14 == (unsigned __int16 *)&ns_defaultObj )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "exec: Could not find variable '%s'!", *(const char **)(a8 + 8));
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
v17 = *v14;
if ( (unsigned __int16)(v17 - 5) > 2u )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "exec: '%s' is not executable!", *(const char **)(a8 + 8));
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
result = ns_execute(
v13,
v12,
v17 - 5,
v17,
v15,
v16,
*(_QWORD *)v14,
*((_QWORD *)v14 + 1),
*((_QWORD *)v14 + 2),
*((_QWORD *)v14 + 3));
break;
case 5u:
result = ((__int64 (*)(void))a8)();
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, unsigned __int16 a7, __int64 a8, unsigned int a9, __int64 a10)
{
__int64 result; // rax
__int64 v11; // rax
__int64 v12; // rsi
int v13; // edi
unsigned __int16 *v14; // rax
int v15; // er8
int v16; // er9
int v17; // ecx

result = a7;
switch ( a7 )
{
case 6u:
v11 = ns_newNamespace(ns_currNamespace);
result = ns_interpret(*(_QWORD *)(a10 + 8), *(_QWORD *)(a8 + 8), a9, v11);
break;
case 7u:
v12 = *(_QWORD *)(a8 + 8);
v13 = ns_currNamespace;
v14 = (unsigned __int16 *)ns_searchNamespaceInherit(ns_currNamespace, v12);
if ( v14 == (unsigned __int16 *)&ns_defaultObj )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "exec: Could not find variable '%s'!", *(const char **)(a8 + 8));
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
v17 = *v14;
if ( (unsigned __int16)(v17 - 5) > 2u )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "exec: '%s' is not executable!", *(const char **)(a8 + 8));
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
result = func6(
v13,
v12,
v17 - 5,
v17,
v15,
v16,
*(_QWORD *)v14,
*((_QWORD *)v14 + 1),
*((_QWORD *)v14 + 2),
*((_QWORD *)v14 + 3));
break;
case 5u:
result = ((__int64 (*)(void))a8)();
break;
}
return result;
}

original_code:
void ns_execute(struct ns_obj obj)
{
    switch (obj.type)
    {
        case TY_FUNC:
            obj.u.f();
            break;
        case TY_BLOCK:
            do { ns_interpret(obj.u.b.str->arr, obj.u.b.file->arr, obj.u.b.lineNo, ns_newNamespace(ns_currNamespace)); } while (0);
            break;
        case TY_SYM:
            {
                struct ns_obj *e = ns_searchNamespaceInherit(ns_currNamespace,
                        obj.u.sym->arr);
                if (e == &ns_defaultObj)
                    do { fprintf(stderr, "\nError: "); fprintf(stderr, "exec: Could not find variable '%s'!", obj.u.sym->arr); putc('\n', stderr); putc('\n', stderr); ns_printContext(); exit(1); } while (0);
                if (!((*e).type == TY_FUNC || (*e).type == TY_BLOCK || (*e).type == TY_SYM))
                    do { fprintf(stderr, "\nError: "); fprintf(stderr, "exec: '%s' is not executable!", obj.u.sym->arr); putc('\n', stderr); putc('\n', stderr); ns_printContext(); exit(1); } while (0);
                ns_execute(*e);
                break;
            }
    }
}

variable_types: struct ns_obj { short type; union { int bo; int i; double fl; struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *s; void (*f)(); struct ns_block { struct dynarr *file; int lineNo; struct dynarr *str; } b; struct dynarr *sym; } u; } *


crash

repo: niksaak/the-game-of-SPACE-and-ships

decompiled_code:
void __noreturn crash()
{
fwrite("\nCrashing mindlessly...\n", 1uLL, 0x18uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("\nCrashing mindlessly...\n", 1uLL, 0x18uLL, stderr);
exit(1);
}

original_code:
void crash()
{
  fprintf(stderr, "\nCrashing mindlessly...\n");
  exit(1);
}


decompiled_code:
int errorprint_SDL()
{
const char *v0; // rax

v0 = (const char *)SDL_GetError();
return fprintf(stderr, "ERROR: %s\n", v0);
}

canonical_decompiled_code:
int func1()
{
const char *v0; // rax

v0 = (const char *)SDL_GetError();
return fprintf(stderr, "ERROR: %s\n", v0);
}

original_code:
void errorprint_SDL()
{
  fprintf(stderr, "ERROR: %s\n", SDL_GetError());
}


decompiled_code:
__int64 __fastcall check_malloc(__int64 a1, const char *a2, unsigned int a3)
{
__int64 result; // rax

result = 1LL;
if ( !a1 )
{
fprintf(stderr, a2);
if ( (_BYTE)a3 )
crash();
result = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, unsigned int a3)
{
__int64 result; // rax

result = 1LL;
if ( !a1 )
{
fprintf(stderr, a2);
if ( (_BYTE)a3 )
func0();
result = a3;
}
return result;
}

original_code:
_Bool check_malloc(const void* ptr, const char* errstr, _Bool crash_on_fail)
{
  if(ptr == ((void *)0)) {
    fprintf(stderr, errstr);
    if(crash_on_fail) {
      crash();
    } else {
      return 0;
    }
  } else {
    return 1;
  }
  return 0;
}

canonical_original_code:
_Bool check_malloc(void *ptr, char *errstr, _Bool crash_on_fail)
{
  if(ptr == ((void *)0)) {
    fprintf(stderr, errstr);
    if(crash_on_fail) {
      crash();
    } else {
      return 0;
    }
  } else {
    return 1;
  }
  return 0;
}

variable_types:
ptr
void *

variable_types:
errstr
char *


decompiled_code:
void *__fastcall malloc_or_die(size_t a1, const char *a2)
{
void *v2; // rbx

v2 = malloc(a1);
check_malloc((__int64)v2, a2, 1u);
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(size_t a1, const char *a2)
{
void *v2; // rbx

v2 = malloc(a1);
func2((__int64)v2, a2, 1u);
return v2;
}

original_code:
void* malloc_or_die(size_t size, const char* errstr)
{
  void* ptr = malloc(size);
  check_malloc(ptr, errstr, 1);
  return ptr;
}

canonical_original_code:
void *malloc_or_die(unsigned long size, char *errstr)
{
  void *ptr = malloc(size);
  check_malloc(ptr, errstr, 1);
  return ptr;
}

variable_types:
size
unsigned long

return_type: void *


dedatacons

decompiled_code:
__int64 __fastcall dedatacons(_QWORD *a1)
{
__int64 v1; // rbx

if ( !a1 )
_assert_fail("list != NULL", "state.c", 0x5Cu, "dedatacons");
v1 = a1[1];
free(a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v1; // rbx

if ( !a1 )
_assert_fail("list != NULL", "state.c", 0x5Cu, "dedatacons");
v1 = a1[1];
free(a1);
return v1;
}

original_code:
DataCons* dedatacons(DataCons* list)
{
  ((list != ((void *)0)) ? (void) (0) : __assert_fail ("list != NULL", "state.c", 92, __extension__ __PRETTY_FUNCTION__));
  DataCons* rest = list->rest;
  free(list);
  return rest;
}

canonical_original_code:
struct DataCons *dedatacons(struct DataCons *list)
{
  ((list != ((void *)0)) ? (void) (0) : __assert_fail ("list != NULL", "state.c", 92, __extension__ __PRETTY_FUNCTION__));
  struct DataCons *rest = list->rest;
  free(list);
  return rest;
}

variable_types:
list
struct DataCons *

variable_types: struct DataCons { void *first; struct DataCons *rest; } *


datapop

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

result = dedatacons((_QWORD *)*a1);
*a1 = result;
return result;
}

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

result = func3((_QWORD *)*a1);
*a1 = result;
return result;
}

original_code:
void datapop(DataCons** list)
{
  *list = dedatacons(*list);
}

canonical_original_code:
void datapop(struct DataCons **list)
{
  *list = dedatacons(*list);
}

variable_types: struct DataCons { void *first; struct DataCons *rest; } **


deinit

decompiled_code:
int deinit()
{
printf("Deinitializing SDL: ");
SDL_Quit();
return puts("OK.");
}

canonical_decompiled_code:
int func2()
{
printf("Deinitializing SDL: ");
SDL_Quit();
return puts("OK.");
}

original_code:
void deinit() {
  printf("Deinitializing SDL: ");
  SDL_Quit();
  printf("OK.\n");
}


repo: nima/python-dmidecode

decompiled_code:
_DWORD *log_init()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = calloc(1uLL, 0x22uLL);
v1 = v0;
if ( v0 )
*v0 = -1;
else
fwrite("** ERROR ** Could not allocate memory for log data\n", 1uLL, 0x34uLL, stderr);
return v1;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = calloc(1uLL, 0x22uLL);
v1 = v0;
if ( v0 )
*v0 = -1;
else
fwrite("** ERROR ** Could not allocate memory for log data\n", 1uLL, 0x34uLL, stderr);
return v1;
}

original_code:
Log_t * log_init()
{
 Log_t *ret = ((void *)0);
 ret = (Log_t *) calloc(1, sizeof(Log_t)+2);
 if( !ret ) {
  fprintf(stderr, "** ERROR **  Could not allocate memory for log data\n");
        return ret;
 }
 ret->level = -1;
 return ret;
}

canonical_original_code:
struct _Log_t *log_init()
{
 struct _Log_t *ret = ((void *)0);
 ret = (struct _Log_t *) calloc(1, sizeof(Log_t)+2);
 if( !ret ) {
  fprintf(stderr, "** ERROR **  Could not allocate memory for log data\n");
        return ret;
 }
 ret->level = -1;
 return ret;
}

variable_types: struct _Log_t { int level; char *message; unsigned int read; struct _Log_t *next; } *


decompiled_code:
__int64 log_append(__int64 a1, char a2, int a3, const char *a4, ...)
{
__int64 v4; // rbx
__int64 v6; // r12
const char *v7; // rdi
__int64 result; // rax
_DWORD *v9; // rax
__int64 v10; // rbx
char v11[4096]; // [rsp+0h] [rbp-10F8h] BYREF
__int16 v12; // [rsp+1000h] [rbp-F8h]
gcc_va_list arg; // [rsp+1008h] [rbp-F0h] BYREF

va_start(arg, a4);
v4 = a1;
memset(v11, 0, sizeof(v11));
v12 = 0;
vsnprintf(v11, 0x1000uLL, a4, arg);
if ( !a1 )
{
if ( (a2 & 4) != 0 )
return 0xFFFFFFFFLL;
goto LABEL_12;
}
while ( 1 )
{
v6 = v4;
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
break;
if ( (a2 & 2) != 0 )
{
v7 = *(const char **)(v4 + 8);
if ( v7 )
{
if ( !strcmp(v7, v11) )
return 1LL;
}
}
}
if ( (unsigned int)(a3 - 3) <= 1 )
{
v9 = log_init();
*(_QWORD *)(v6 + 24) = v9;
if ( v9 )
{
*v9 = a3;
v10 = *(_QWORD *)(v6 + 24);
*(_QWORD *)(v10 + 8) = strdup(v11);
return 1LL;
}
}
result = 0xFFFFFFFFLL;
if ( (a2 & 4) == 0 )
{
fwrite("** ERROR ** Failed to save log entry\n", 1uLL, 0x26uLL, stderr);
LABEL_12:
fprintf(stderr, "%s\n", v11);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func1(__int64 a1, char a2, int a3, const char *a4, ...)
{
__int64 v4; // rbx
__int64 v6; // r12
const char *v7; // rdi
__int64 result; // rax
_DWORD *v9; // rax
__int64 v10; // rbx
char v11[4096]; // [rsp+0h] [rbp-10F8h] BYREF
__int16 v12; // [rsp+1000h] [rbp-F8h]
gcc_va_list arg; // [rsp+1008h] [rbp-F0h] BYREF

va_start(arg, a4);
v4 = a1;
memset(v11, 0, sizeof(v11));
v12 = 0;
vsnprintf(v11, 0x1000uLL, a4, arg);
if ( !a1 )
{
if ( (a2 & 4) != 0 )
return 0xFFFFFFFFLL;
goto LABEL_12;
}
while ( 1 )
{
v6 = v4;
v4 = *(_QWORD *)(v4 + 24);
if ( !v4 )
break;
if ( (a2 & 2) != 0 )
{
v7 = *(const char **)(v4 + 8);
if ( v7 )
{
if ( !strcmp(v7, v11) )
return 1LL;
}
}
}
if ( (unsigned int)(a3 - 3) <= 1 )
{
v9 = func0();
*(_QWORD *)(v6 + 24) = v9;
if ( v9 )
{
*v9 = a3;
v10 = *(_QWORD *)(v6 + 24);
*(_QWORD *)(v10 + 8) = strdup(v11);
return 1LL;
}
}
result = 0xFFFFFFFFLL;
if ( (a2 & 4) == 0 )
{
fwrite("** ERROR ** Failed to save log entry\n", 1uLL, 0x26uLL, stderr);
LABEL_12:
fprintf(stderr, "%s\n", v11);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int log_append(Log_t *logp, Log_f flags, int level, const char *fmt, ...)
{
        Log_t *ptr = ((void *)0);
        va_list ap;
        char logmsg[4098];
        memset(&logmsg, 0, 4098);
        __builtin_va_start(ap,fmt);
        vsnprintf(logmsg, 4096, fmt, ap);
        __builtin_va_end(ap);
        ptr = logp;
        while( ptr && ptr->next ) {
                if( (flags & LOGFL_NODUPS) && ptr->next && ptr->next->message
                    && (strcmp(ptr->next->message, logmsg) == 0) ) {
                        return 1;
                }
                ptr = ptr->next;
        }
        if( ptr && ((level == 3) || (level == 4)) ) {
                ptr->next = log_init();
                if( ptr->next ) {
                        ptr->next->level = level;
                        ptr->next->message = strdup(logmsg);
                        return 1;
                }
        }
        if( !(flags & LOGFL_NOSTDERR) ) {
                if( logp ) {
                        fprintf(stderr, "** ERROR **  Failed to save log entry\n");
                }
                fprintf(stderr, "%s\n", logmsg);
        }
        return -1;
}

canonical_original_code:
int log_append(struct _Log_t *logp, enum Log_f flags, int level, char *fmt, ...)
{
        struct _Log_t *ptr = ((void *)0);
        __builtin_va_list ap;
        char logmsg[4098];
        memset(&logmsg, 0, 4098);
        __builtin_va_start(ap,fmt);
        vsnprintf(logmsg, 4096, fmt, ap);
        __builtin_va_end(ap);
        ptr = logp;
        while( ptr && ptr->next ) {
                if( (flags & LOGFL_NODUPS) && ptr->next && ptr->next->message
                    && (strcmp(ptr->next->message, logmsg) == 0) ) {
                        return 1;
                }
                ptr = ptr->next;
        }
        if( ptr && ((level == 3) || (level == 4)) ) {
                ptr->next = log_init();
                if( ptr->next ) {
                        ptr->next->level = level;
                        ptr->next->message = strdup(logmsg);
                        return 1;
                }
        }
        if( !(flags & LOGFL_NOSTDERR) ) {
                if( logp ) {
                        fprintf(stderr, "** ERROR **  Failed to save log entry\n");
                }
                fprintf(stderr, "%s\n", logmsg);
        }
        return -1;
}

variable_types: enum Log_f { LOGFL_NORMAL=1, LOGFL_NODUPS=2, LOGFL_NOSTDERR=4 }

variable_types: level int

variable_types:
fmt
char *

variable_types:
logmsg
char [4098]

user_defined_types: struct _Log_t { int level; char *message; unsigned int read; struct _Log_t *next; }


decompiled_code:
char *__fastcall log_retrieve(__int64 a1, int a2)
{
__int64 v2; // rbx
size_t v3; // r12
char *v4; // rbp
size_t v5; // rax

v2 = a1;
if ( !a1 )
return 0LL;
v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)v2 != a2 )
goto LABEL_6;
v5 = strlen(*(const char **)(v2 + 8));
v4 = (char *)(v4 ? realloc(v4, v3 + v5 + 3) : calloc(1uLL, v5 + 2));
if ( !v4 )
break;
strcat(v4, *(const char **)(v2 + 8));
*(_WORD *)&v4[strlen(v4)] = 10;
++*(_DWORD *)(v2 + 16);
v3 = strlen(v4);
LABEL_6:
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return v4;
}
fwrite("** ERROR ** Could not allocate log retrieval memory buffer\n", 1uLL, 0x3BuLL, stderr);
return v4;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rbx
size_t v3; // r12
char *v4; // rbp
size_t v5; // rax

v2 = a1;
if ( !a1 )
return 0LL;
v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
if ( *(_DWORD *)v2 != a2 )
goto LABEL_6;
v5 = strlen(*(const char **)(v2 + 8));
v4 = (char *)(v4 ? realloc(v4, v3 + v5 + 3) : calloc(1uLL, v5 + 2));
if ( !v4 )
break;
strcat(v4, *(const char **)(v2 + 8));
*(_WORD *)&v4[strlen(v4)] = 10;
++*(_DWORD *)(v2 + 16);
v3 = strlen(v4);
LABEL_6:
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return v4;
}
fwrite("** ERROR ** Could not allocate log retrieval memory buffer\n", 1uLL, 0x3BuLL, stderr);
return v4;
}

original_code:
char * log_retrieve(Log_t *logp, int level)
{
 char *ret = ((void *)0);
 size_t len = 0;
 Log_t *ptr = ((void *)0);
 if( !logp ) {
  return ((void *)0);
 }
 for( ptr = logp; ptr != ((void *)0); ptr = ptr->next ) {
  if( ptr && ptr->level == level ) {
   if( ret ) {
    ret = realloc(ret, strlen(ptr->message)+len+3);
   } else {
    ret = calloc(1, strlen(ptr->message)+2);
   }
   if( !ret ) {
    fprintf(stderr,
     "** ERROR ** Could not allocate log retrieval memory buffer\n");
    return ((void *)0);
   }
   strcat(ret, ptr->message);
   strcat(ret, "\n");
   ptr->read++;
   len = strlen(ret);
  }
 }
 return ret;
}

canonical_original_code:
char *log_retrieve(struct _Log_t *logp, int level)
{
 char *ret = ((void *)0);
 unsigned long len = 0;
 struct _Log_t *ptr = ((void *)0);
 if( !logp ) {
  return ((void *)0);
 }
 for( ptr = logp; ptr != ((void *)0); ptr = ptr->next ) {
  if( ptr && ptr->level == level ) {
   if( ret ) {
    ret = realloc(ret, strlen(ptr->message)+len+3);
   } else {
    ret = calloc(1, strlen(ptr->message)+2);
   }
   if( !ret ) {
    fprintf(stderr,
     "** ERROR ** Could not allocate log retrieval memory buffer\n");
    return ((void *)0);
   }
   strcat(ret, ptr->message);
   strcat(ret, "\n");
   ptr->read++;
   len = strlen(ret);
  }
 }
 return ret;
}

variable_types:
ret
char *

variable_types:
len
unsigned long

return_type: char *


original_code:
size_t log_clear_partial(Log_t *logp, int level, int unread)
{
 Log_t *ptr = ((void *)0), *prev = ((void *)0);
 size_t elmnt = 0;
 if( !logp ) {
  return 0;
 }
 prev = logp;
 for( ptr = logp->next; ptr != ((void *)0); ptr = ptr->next ) {
  if( !ptr ) {
   break;
  }
  if( (ptr->level == level) && ((unread == 1) || (ptr->read > 0)) ) {
   prev->next = ptr->next;
   if( ptr->message ) {
    free(ptr->message);
    ptr->message = ((void *)0);
   }
   free(ptr);
   ptr = prev;
   elmnt++;
  }
  prev = ptr;
 }
 return elmnt;
}

canonical_original_code:
unsigned long log_clear_partial(struct _Log_t *logp, int level, int unread)
{
 struct _Log_t *ptr = ((void *)0); struct _Log_t *prev = ((void *)0);
 unsigned long elmnt = 0;
 if( !logp ) {
  return 0;
 }
 prev = logp;
 for( ptr = logp->next; ptr != ((void *)0); ptr = ptr->next ) {
  if( !ptr ) {
   break;
  }
  if( (ptr->level == level) && ((unread == 1) || (ptr->read > 0)) ) {
   prev->next = ptr->next;
   if( ptr->message ) {
    free(ptr->message);
    ptr->message = ((void *)0);
   }
   free(ptr);
   ptr = prev;
   elmnt++;
  }
  prev = ptr;
 }
 return elmnt;
}

variable_types: unread int

variable_types:
elmnt
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall log_close(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
v3 = (void *)v2[1];
if ( v3 )
free(v3);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void *v3; // rdi

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
v3 = (void *)v2[1];
if ( v3 )
free(v3);
free(v2);
}
while ( v1 );
}
}

original_code:
void log_close(Log_t *logp)
{
 Log_t *ptr = ((void *)0), *next = ((void *)0);
 ptr = logp;
 while( ptr ) {
  next = ptr->next;
  ptr->next = ((void *)0);
  if( ptr->message ) {
   free(ptr->message);
   ptr->message = ((void *)0);
  }
  free(ptr);
  ptr = next;
 }
}

canonical_original_code:
void log_close(struct _Log_t *logp)
{
 struct _Log_t *ptr = ((void *)0); struct _Log_t *next = ((void *)0);
 ptr = logp;
 while( ptr ) {
  next = ptr->next;
  ptr->next = ((void *)0);
  if( ptr->message ) {
   free(ptr->message);
   ptr->message = ((void *)0);
  }
  free(ptr);
  ptr = next;
 }
}


myread

decompiled_code:
__int64 __fastcall myread(__int64 a1, int a2, __int64 a3, __int64 a4, const char *a5)
{
__int64 v8; // rbp
ssize_t v9; // rax
ssize_t v10; // rbx

if ( !a4 )
return 0LL;
v8 = 0LL;
do
{
v9 = read(a2, (void *)(a3 + v8), a4 - v8);
v10 = v9;
if ( v9 == -1 )
{
if ( *_errno_location() != 4 )
{
close(a2);
perror(a5);
return 0xFFFFFFFFLL;
}
}
else
{
v8 += v9;
}
}
while ( v8 != a4 && v10 );
if ( v8 == a4 )
return 0LL;
close(a2);
log_append(a1, 1LL, 4LL, "%s: Unexpected end of file", a5);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, __int64 a4, const char *a5)
{
__int64 v8; // rbp
ssize_t v9; // rax
ssize_t v10; // rbx

if ( !a4 )
return 0LL;
v8 = 0LL;
do
{
v9 = read(a2, (void *)(a3 + v8), a4 - v8);
v10 = v9;
if ( v9 == -1 )
{
if ( *_errno_location() != 4 )
{
close(a2);
perror(a5);
return 0xFFFFFFFFLL;
}
}
else
{
v8 += v9;
}
}
while ( v8 != a4 && v10 );
if ( v8 == a4 )
return 0LL;
close(a2);
log_append(a1, 1LL, 4LL, "%s: Unexpected end of file", a5);
return 0xFFFFFFFFLL;
}

original_code:
static int myread(Log_t *logp, int fd, u8 * buf, size_t count, const char *prefix)
{
        ssize_t r = 1;
        size_t r2 = 0;
        while(r2 != count && r != 0) {
                r = read(fd, buf + r2, count - r2);
                if(r == -1) {
                        if((*__errno_location ()) != 4) {
                                close(fd);
                                perror(prefix);
                                return -1;
                        }
                } else
                        r2 += r;
        }
        if(r2 != count) {
                close(fd);
                log_append(logp, LOGFL_NORMAL, 4, "%s: Unexpected end of file", prefix);
                return -1;
        }
        return 0;
}

canonical_original_code:
static int myread(struct _Log_t *logp, int fd, unsigned char *buf, unsigned long count, char *prefix)
{
        long r = 1;
        unsigned long r2 = 0;
        while(r2 != count && r != 0) {
                r = read(fd, buf + r2, count - r2);
                if(r == -1) {
                        if((*__errno_location ()) != 4) {
                                close(fd);
                                perror(prefix);
                                return -1;
                        }
                } else
                        r2 += r;
        }
        if(r2 != count) {
                close(fd);
                log_append(logp, LOGFL_NORMAL, 4, "%s: Unexpected end of file", prefix);
                return -1;
        }
        return 0;
}

variable_types: fd int

variable_types:
buf
unsigned char *

variable_types:
count
unsigned long

variable_types:
prefix
char *

variable_types: r long


decompiled_code:
void sigill_handler()
{
sigill_error = 1;
if ( sigill_logobj )
log_append(sigill_logobj, 2LL, 4LL, "SIGILL signal caught in mem_chunk()");
else
fwrite("** WARNING ** SIGILL signal caught in mem_chunk()\n", 1uLL, 0x32uLL, stderr);
}

canonical_decompiled_code:
void func1()
{
sigill_error = 1;
if ( sigill_logobj )
log_append(sigill_logobj, 2LL, 4LL, "SIGILL signal caught in mem_chunk()");
else
fwrite("** WARNING ** SIGILL signal caught in mem_chunk()\n", 1uLL, 0x32uLL, stderr);
}

original_code:
void sigill_handler(int ignore_this) {
        sigill_error = 1;
        if( sigill_logobj ) {
                log_append(sigill_logobj, LOGFL_NODUPS, 4,
                           "SIGILL signal caught in mem_chunk()");
        } else {
                fprintf(stderr,
                        "** WARNING ** SIGILL signal caught in mem_chunk()\n");
        }
}


decompiled_code:
void *__fastcall safe_memcpy(void *a1, const void *a2, size_t a3)
{
return memcpy(a1, a2, a3);
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, const void *a2, size_t a3)
{
return memcpy(a1, a2, a3);
}

original_code:
static void safe_memcpy(void *dest, const void *src, size_t n)
{
        memcpy(dest, src, n);
}

canonical_original_code:
static void safe_memcpy(void *dest, void *src, unsigned long n)
{
        memcpy(dest, src, n);
}

variable_types:
dest
void *

variable_types:
src
void *

variable_types:
n
unsigned long


checksum

decompiled_code:
_BOOL8 __fastcall checksum(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rax
_BYTE *v3; // rsi
char v4; // dl

if ( a2 )
{
v2 = a1;
v3 = &a1[a2];
v4 = 0;
do
v4 += *v2++;
while ( v2 != v3 );
}
else
{
v4 = 0;
}
return v4 == 0;
}

original_code:
int checksum(const u8 * buf, size_t len)
{
        u8 sum = 0;
        size_t a;
        for(a = 0; a < len; a++)
                sum += buf[a];
        return (sum == 0);
}

canonical_original_code:
int checksum(unsigned char *buf, unsigned long len)
{
        unsigned char sum = 0;
        unsigned long a;
        for(a = 0; a < len; a++)
                sum += buf[a];
        return (sum == 0);
}

variable_types:
sum
unsigned char

variable_types:
a
unsigned long


decompiled_code:
void *__fastcall read_file(__int64 a1, __off_t a2, size_t *a3, const char *a4)
{
int v6; // eax
int v7; // ebx
void *v8; // rbp
struct stat v10; // [rsp+0h] [rbp-C8h] BYREF

v6 = open(a4, 0);
if ( v6 != -1 )
{
v7 = v6;
if ( !fstat(v6, &v10) )
{
if ( v10.st_size <= a2 )
{
fprintf(stderr, "%s: Can't read data beyond EOF\n", a4);
v8 = 0LL;
goto LABEL_10;
}
if ( *a3 > v10.st_size - a2 )
*a3 = v10.st_size - a2;
}
v8 = malloc(*a3);
if ( v8 )
{
if ( lseek(v7, a2, 0) == -1 )
{
fprintf(stderr, "%s: ", a4);
perror("lseek");
}
else if ( !(unsigned int)myread(a1, v7, (__int64)v8, *a3, a4) )
{
goto LABEL_10;
}
free(v8);
v8 = 0LL;
}
else
{
perror("malloc");
}
LABEL_10:
if ( close(v7) == -1 )
perror(a4);
return v8;
}
v8 = 0LL;
if ( *_errno_location() != 2 )
perror(a4);
return v8;
}

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, __off_t a2, size_t *a3, const char *a4)
{
int v6; // eax
int v7; // ebx
void *v8; // rbp
struct stat v10; // [rsp+0h] [rbp-C8h] BYREF

v6 = open(a4, 0);
if ( v6 != -1 )
{
v7 = v6;
if ( !fstat(v6, &v10) )
{
if ( v10.st_size <= a2 )
{
fprintf(stderr, "%s: Can't read data beyond EOF\n", a4);
v8 = 0LL;
goto LABEL_10;
}
if ( *a3 > v10.st_size - a2 )
*a3 = v10.st_size - a2;
}
v8 = malloc(*a3);
if ( v8 )
{
if ( lseek(v7, a2, 0) == -1 )
{
fprintf(stderr, "%s: ", a4);
perror("lseek");
}
else if ( !(unsigned int)func0(a1, v7, (__int64)v8, *a3, a4) )
{
goto LABEL_10;
}
free(v8);
v8 = 0LL;
}
else
{
perror("malloc");
}
LABEL_10:
if ( close(v7) == -1 )
perror(a4);
return v8;
}
v8 = 0LL;
if ( *_errno_location() != 2 )
perror(a4);
return v8;
}

original_code:
void *read_file(Log_t *logp, off_t base, size_t *max_len, const char *filename)
{
        struct stat statbuf;
        int fd;
        u8 *p;
        if ((fd = open(filename, 00)) == -1)
        {
                if ((*__errno_location ()) != 2)
                        perror(filename);
                return ((void *)0);
        }
        if (fstat(fd, &statbuf) == 0)
        {
                if (base >= statbuf.st_size)
                {
                        fprintf(stderr, "%s: Can't read data beyond EOF\n",
                                filename);
                        p = ((void *)0);
                        goto out;
                }
                if (*max_len > (size_t)statbuf.st_size - base)
                        *max_len = statbuf.st_size - base;
        }
        if ((p = malloc(*max_len)) == ((void *)0))
        {
                perror("malloc");
                goto out;
        }
        if (lseek(fd, base, 0) == -1)
        {
                fprintf(stderr, "%s: ", filename);
                perror("lseek");
                goto err_free;
        }
        if (myread(logp, fd, p, *max_len, filename) == 0)
                goto out;
err_free:
        free(p);
        p = ((void *)0);
out:
        if (close(fd) == -1)
                perror(filename);
        return p;
}

canonical_original_code:
void *read_file(struct _Log_t *logp, long base, unsigned long *max_len, char *filename)
{
        struct stat statbuf;
        int fd;
        unsigned char *p;
        if ((fd = open(filename, 00)) == -1)
        {
                if ((*__errno_location ()) != 2)
                        perror(filename);
                return ((void *)0);
        }
        if (fstat(fd, &statbuf) == 0)
        {
                if (base >= statbuf.st_size)
                {
                        fprintf(stderr, "%s: Can't read data beyond EOF\n",
                                filename);
                        p = ((void *)0);
                        goto out;
                }
                if (*max_len > (unsigned long)statbuf.st_size - base)
                        *max_len = statbuf.st_size - base;
        }
        if ((p = malloc(*max_len)) == ((void *)0))
        {
                perror("malloc");
                goto out;
        }
        if (lseek(fd, base, 0) == -1)
        {
                fprintf(stderr, "%s: ", filename);
                perror("lseek");
                goto err_free;
        }
        if (myread(logp, fd, p, *max_len, filename) == 0)
                goto out;
err_free:
        free(p);
        p = ((void *)0);
out:
        if (close(fd) == -1)
                perror(filename);
        return p;
}

variable_types: struct _Log_t { int level; char *message; unsigned int read; struct _Log_t *next; } *

variable_types: base long

variable_types:
filename
char *

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

variable_types:
p
unsigned char *

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


decompiled_code:
void *__fastcall mem_chunk(__int64 a1, unsigned __int64 a2, size_t a3, const char *a4)
{
int v6; // ebx
void *v7; // r13
unsigned __int64 v8; // rax
char *v9; // rax
char *v10; // rbp
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
char *v20; // rax
int *v21; // rax
char *v22; // rax
char *v23; // rax
size_t len; // [rsp+0h] [rbp-D8h]
int *lena; // [rsp+0h] [rbp-D8h]
unsigned __int64 v26; // [rsp+8h] [rbp-D0h]
struct stat buf; // [rsp+10h] [rbp-C8h] BYREF

sigill_logobj = a1;
signal(4, (__sighandler_t)sigill_handler);
if ( sigill_error || (v6 = open(a4, 0), v6 == -1) )
{
v12 = _errno_location();
v13 = strerror(*v12);
log_append(a1, 1LL, 4LL, "Failed to open memory buffer (%s): %s", a4, v13);
v7 = 0LL;
goto LABEL_14;
}
if ( sigill_error || (v7 = malloc(a3)) == 0LL )
{
v14 = _errno_location();
v15 = strerror(*v14);
log_append(a1, 1LL, 4LL, "malloc: %s", v15);
v7 = 0LL;
}
else
{
if ( fstat(v6, &buf) == -1 )
{
v16 = _errno_location();
v17 = strerror(*v16);
log_append(a1, 1LL, 4LL, "fstat: %s", v17);
}
else if ( (buf.st_mode & 0xF000) == 0x8000 && (__int64)(a3 + a2) > buf.st_size )
{
v18 = _errno_location();
v19 = strerror(*v18);
log_append(a1, 1LL, 4LL, "mmap: Can't map beyond end of file %s: %s", a4, v19);
}
else
{
v8 = sysconf(30);
v26 = a2 % v8;
len = a3 + a2 % v8;
v9 = (char *)mmap(0LL, len, 1, 1, v6, a2 - a2 % v8);
if ( v9 != (char *)-1LL )
{
v10 = v9;
safe_memcpy(v7, &v9[v26], a3);
if ( munmap(v10, len) == -1 )
{
v21 = _errno_location();
v22 = strerror(*v21);
log_append(a1, 1LL, 4LL, "%s (munmap): %s", a4, v22);
free(v7);
v7 = 0LL;
}
goto LABEL_11;
}
lena = _errno_location();
v20 = strerror(*lena);
log_append(a1, 1LL, 4LL, "%s (mmap): %s", a4, v20);
if ( lseek(v6, a2, 0) == -1 )
{
v23 = strerror(*lena);
log_append(a1, 1LL, 4LL, "%s (lseek): %s", a4, v23);
}
else if ( !sigill_error )
{
myread(a1, v6, (__int64)v7, a3, a4);
}
}
free(v7);
v7 = 0LL;
}
LABEL_11:
if ( v6 >= 0 && close(v6) == -1 )
perror(a4);
LABEL_14:
signal(4, 0LL);
sigill_logobj = 0LL;
return v7;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, unsigned __int64 a2, size_t a3, const char *a4)
{
int v6; // ebx
void *v7; // r13
unsigned __int64 v8; // rax
char *v9; // rax
char *v10; // rbp
int *v12; // rax
char *v13; // rax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
char *v20; // rax
int *v21; // rax
char *v22; // rax
char *v23; // rax
size_t len; // [rsp+0h] [rbp-D8h]
int *lena; // [rsp+0h] [rbp-D8h]
unsigned __int64 v26; // [rsp+8h] [rbp-D0h]
struct stat buf; // [rsp+10h] [rbp-C8h] BYREF

sigill_logobj = a1;
signal(4, (__sighandler_t)sigill_handler);
if ( sigill_error || (v6 = open(a4, 0), v6 == -1) )
{
v12 = _errno_location();
v13 = strerror(*v12);
log_append(a1, 1LL, 4LL, "Failed to open memory buffer (%s): %s", a4, v13);
v7 = 0LL;
goto LABEL_14;
}
if ( sigill_error || (v7 = malloc(a3)) == 0LL )
{
v14 = _errno_location();
v15 = strerror(*v14);
log_append(a1, 1LL, 4LL, "malloc: %s", v15);
v7 = 0LL;
}
else
{
if ( fstat(v6, &buf) == -1 )
{
v16 = _errno_location();
v17 = strerror(*v16);
log_append(a1, 1LL, 4LL, "fstat: %s", v17);
}
else if ( (buf.st_mode & 0xF000) == 0x8000 && (__int64)(a3 + a2) > buf.st_size )
{
v18 = _errno_location();
v19 = strerror(*v18);
log_append(a1, 1LL, 4LL, "mmap: Can't map beyond end of file %s: %s", a4, v19);
}
else
{
v8 = sysconf(30);
v26 = a2 % v8;
len = a3 + a2 % v8;
v9 = (char *)mmap(0LL, len, 1, 1, v6, a2 - a2 % v8);
if ( v9 != (char *)-1LL )
{
v10 = v9;
func2(v7, &v9[v26], a3);
if ( munmap(v10, len) == -1 )
{
v21 = _errno_location();
v22 = strerror(*v21);
log_append(a1, 1LL, 4LL, "%s (munmap): %s", a4, v22);
free(v7);
v7 = 0LL;
}
goto LABEL_11;
}
lena = _errno_location();
v20 = strerror(*lena);
log_append(a1, 1LL, 4LL, "%s (mmap): %s", a4, v20);
if ( lseek(v6, a2, 0) == -1 )
{
v23 = strerror(*lena);
log_append(a1, 1LL, 4LL, "%s (lseek): %s", a4, v23);
}
else if ( !sigill_error )
{
func0(a1, v6, (__int64)v7, a3, a4);
}
}
free(v7);
v7 = 0LL;
}
LABEL_11:
if ( v6 >= 0 && close(v6) == -1 )
perror(a4);
LABEL_14:
signal(4, 0LL);
sigill_logobj = 0LL;
return v7;
}

original_code:
void *mem_chunk(Log_t *logp, size_t base, size_t len, const char *devmem)
{
        void *p;
        int fd = -1;
        struct stat statbuf;
 size_t mmoffset;
        void *mmp;
        sigill_logobj = logp;
        signal(4, sigill_handler);
        if(sigill_error || (fd = open(devmem, 00)) == -1) {
                log_append(logp, LOGFL_NORMAL, 4,
                           "Failed to open memory buffer (%s): %s",
                           devmem, strerror((*__errno_location ())));
                p = ((void *)0);
                goto exit;
        }
        if(sigill_error || (p = malloc(len)) == ((void *)0)) {
                log_append(logp, LOGFL_NORMAL, 4,"malloc: %s", strerror((*__errno_location ())));
                p = ((void *)0);
                goto exit;
        }
        if (sigill_error || fstat(fd, &statbuf) == -1 )
        {
                log_append(logp, LOGFL_NORMAL, 4,"fstat: %s", strerror((*__errno_location ())));
                goto err_free;
        }
        if ((sigill_error || ((((statbuf.st_mode)) & 0170000) == (0100000))) && (__off_t)(base + (off_t)len) > statbuf.st_size )
        {
                log_append(logp, LOGFL_NORMAL, 4,
                                "mmap: Can't map beyond end of file %s: %s",
                                devmem, strerror((*__errno_location ())));
                goto err_free;
        }
        mmoffset = base % sysconf(_SC_PAGESIZE);
        mmp = mmap(((void *)0), mmoffset + len, 0x1, 0x01, fd, base - mmoffset);
        if(sigill_error || (mmp == ((void *) -1))) {
                log_append(logp, LOGFL_NORMAL, 4, "%s (mmap): %s", devmem, strerror((*__errno_location ())));
   goto try_read;
        }
        safe_memcpy(p, (u8 *) mmp + mmoffset, len);
        if (sigill_error) {
                log_append(logp, LOGFL_NODUPS, 4,
                           "Failed to do memcpy() due to SIGILL signal");
                free(p);
                p = ((void *)0);
                goto exit;
        }
        if(sigill_error || (munmap(mmp, mmoffset + len) == -1)) {
                log_append(logp, LOGFL_NORMAL, 4, "%s (munmap): %s", devmem, strerror((*__errno_location ())));
                free(p);
                p = ((void *)0);
                goto exit;
        }
 goto exit;
try_read:
        if (lseek(fd, base, 0) == -1 )
        {
                log_append(logp, LOGFL_NORMAL, 4, "%s (lseek): %s", devmem, strerror((*__errno_location ())));
                goto err_free;
        }
        if(sigill_error || (myread(logp, fd, p, len, devmem) == 0)) {
                free(p);
                p = ((void *)0);
                goto exit;
        }
err_free:
        free(p);
        p = ((void *)0);
exit:
        if (fd >= 0) {
            if(close(fd) == -1)
                perror(devmem);
        }
        signal(4, ((__sighandler_t) 0));
        sigill_logobj = ((void *)0);
        return p;
}

canonical_original_code:
void *mem_chunk(struct _Log_t *logp, unsigned long base, unsigned long len, char *devmem)
{
        void *p;
        int fd = -1;
        struct stat statbuf;
 unsigned long mmoffset;
        void *mmp;
        sigill_logobj = logp;
        signal(4, sigill_handler);
        if(sigill_error || (fd = open(devmem, 00)) == -1) {
                log_append(logp, LOGFL_NORMAL, 4,
                           "Failed to open memory buffer (%s): %s",
                           devmem, strerror((*__errno_location ())));
                p = ((void *)0);
                goto exit;
        }
        if(sigill_error || (p = malloc(len)) == ((void *)0)) {
                log_append(logp, LOGFL_NORMAL, 4,"malloc: %s", strerror((*__errno_location ())));
                p = ((void *)0);
                goto exit;
        }
        if (sigill_error || fstat(fd, &statbuf) == -1 )
        {
                log_append(logp, LOGFL_NORMAL, 4,"fstat: %s", strerror((*__errno_location ())));
                goto err_free;
        }
        if ((sigill_error || ((((statbuf.st_mode)) & 0170000) == (0100000))) && (__off_t)(base + (long)len) > statbuf.st_size )
        {
                log_append(logp, LOGFL_NORMAL, 4,
                                "mmap: Can't map beyond end of file %s: %s",
                                devmem, strerror((*__errno_location ())));
                goto err_free;
        }
        mmoffset = base % sysconf(_SC_PAGESIZE);
        mmp = mmap(((void *)0), mmoffset + len, 0x1, 0x01, fd, base - mmoffset);
        if(sigill_error || (mmp == ((void *) -1))) {
                log_append(logp, LOGFL_NORMAL, 4, "%s (mmap): %s", devmem, strerror((*__errno_location ())));
   goto try_read;
        }
        safe_memcpy(p, (unsigned char *) mmp + mmoffset, len);
        if (sigill_error) {
                log_append(logp, LOGFL_NODUPS, 4,
                           "Failed to do memcpy() due to SIGILL signal");
                free(p);
                p = ((void *)0);
                goto exit;
        }
        if(sigill_error || (munmap(mmp, mmoffset + len) == -1)) {
                log_append(logp, LOGFL_NORMAL, 4, "%s (munmap): %s", devmem, strerror((*__errno_location ())));
                free(p);
                p = ((void *)0);
                goto exit;
        }
 goto exit;
try_read:
        if (lseek(fd, base, 0) == -1 )
        {
                log_append(logp, LOGFL_NORMAL, 4, "%s (lseek): %s", devmem, strerror((*__errno_location ())));
                goto err_free;
        }
        if(sigill_error || (myread(logp, fd, p, len, devmem) == 0)) {
                free(p);
                p = ((void *)0);
                goto exit;
        }
err_free:
        free(p);
        p = ((void *)0);
exit:
        if (fd >= 0) {
            if(close(fd) == -1)
                perror(devmem);
        }
        signal(4, ((void (*)(int)) 0));
        sigill_logobj = ((void *)0);
        return p;
}

variable_types:
base
unsigned long

variable_types:
len
unsigned long

variable_types:
devmem
char *

variable_types:
p
void *

variable_types:
mmoffset
unsigned long

variable_types:
mmp
void *

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
unsigned __int64 __fastcall u64_range(__int64 a1, __int64 a2)
{
return ((unsigned __int64)(unsigned int)(((_DWORD)a2 + 1 == (_DWORD)a1) + ((unsigned __int64)(a2 - a1) >> 32)) << 32) | (unsigned int)(a2 + 1 - a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1, __int64 a2)
{
return ((unsigned __int64)(unsigned int)(((_DWORD)a2 + 1 == (_DWORD)a1) + ((unsigned __int64)(a2 - a1) >> 32)) << 32) | (unsigned int)(a2 + 1 - a1);
}

original_code:
u64 u64_range(u64 start, u64 end)
{
 u64 res;
 res.h = end.h - start.h;
 res.l = end.l - start.l;
 if (end.l < start.l)
  res.h--;
 if (++res.l == 0)
  res.h++;
 return res;
}

canonical_original_code:
struct u64 u64_range(struct u64 start, struct u64 end)
{
 struct u64 res;
 res.h = end.h - start.h;
 res.l = end.l - start.l;
 if (end.l < start.l)
  res.h--;
 if (++res.l == 0)
  res.h++;
 return res;
}

variable_types:
start
struct u64

variable_types:
end
struct u64

variable_types: struct u64 { unsigned int l; unsigned int h; }


decompiled_code:
__int64 __fastcall overwrite_smbios3_address(_BYTE *a1)
{
int v1; // eax
int v2; // edx
int v3; // eax
__int64 result; // rax

v1 = (unsigned __int8)(a1[5] + a1[18]) + (unsigned __int8)a1[19] - 32;
LOBYTE(v1) = a1[23] + a1[22] + a1[21] + a1[20] + v1;
v2 = v1;
v3 = (unsigned __int8)(a1[16] + a1[17]);
*((_QWORD *)a1 + 2) = 32LL;
result = (unsigned int)(v2 + v3);
a1[5] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
int v2; // edx
int v3; // eax
__int64 result; // rax

v1 = (unsigned __int8)(a1[5] + a1[18]) + (unsigned __int8)a1[19] - 32;
LOBYTE(v1) = a1[23] + a1[22] + a1[21] + a1[20] + v1;
v2 = v1;
v3 = (unsigned __int8)(a1[16] + a1[17]);
*((_QWORD *)a1 + 2) = 32LL;
result = (unsigned int)(v2 + v3);
a1[5] = result;
return result;
}

variable_types:
buf
unsigned char *


decompiled_code:
__int64 __fastcall dmi_table_dump(__int64 a1, unsigned int a2, __int64 a3)
{
return write_dump(32LL, a2, a1, a3, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 a3)
{
return write_dump(32LL, a2, a1, a3, 0LL);
}

original_code:
void dmi_table_dump(const u8 *buf, u32 len, const char *dumpfile)
{
        write_dump(32, len, buf, dumpfile, 0);
}

canonical_original_code:
void dmi_table_dump(unsigned char *buf, unsigned int len, char *dumpfile)
{
        write_dump(32, len, buf, dumpfile, 0);
}

variable_types:
len
unsigned int

variable_types:
dumpfile
char *