decompiled_code:
__int64 __fastcall dynarr_resize_up(__int64 a1, unsigned int a2)
{
unsigned int v3; // edx
size_t v4; // rsi
unsigned int v5; // er12

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
unsigned int v3; // edx
size_t v4; // rsi
unsigned int v5; // er12

v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
LODWORD(v4) = *(_DWORD *)(a1 + 4);
if ( v3 >= a2 )
return 0;
}
else
{
*(_DWORD *)(a1 + 4) = 1;
if ( a2 <= 1 )
{
v4 = 1LL;
v5 = 1;
goto LABEL_10;
}
LODWORD(v4) = 1;
}
do
v4 = (unsigned int)(2 * v4);
while ( (unsigned int)v4 < a2 );
*(_DWORD *)(a1 + 4) = v4;
v5 = v4 - v3;
if ( (_DWORD)v4 == v3 )
return v5;
LABEL_10:
*(_QWORD *)(a1 + 8) = realloc(*(void **)(a1 + 8), v4);
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;
}


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: struct dynarr { unsigned int size; unsigned int alloc_size; char *arr; } *

variable_types: info char

variable_types: alloc int

return_type: int


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

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

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

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

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

variable_types:
pos
unsigned int

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


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

variable_types:
size
unsigned int


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 ( *(_WORD *)v3 == 45 )
{
runFile(stdin, (__int64)"<stdin>");
}
else
{
if ( !strcmp(v3, "-h") )
showHelp(*argv);
v4 = fopen(v3, "r");
runFile(v4, (__int64)v3);
}
}
if ( ns_stackSize > 0 && (ns_pop(&v6), v6 == 2) )
result = v7;
else
result = 0;
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 ( *(_WORD *)v3 == 45 )
{
func1(stdin, (__int64)"<stdin>");
}
else
{
if ( !strcmp(v3, "-h") )
func3(*argv);
v4 = fopen(v3, "r");
func1(v4, (__int64)v3);
}
}
if ( ns_stackSize > 0 && (ns_pop(&v6), v6 == 2) )
result = v7;
else
result = 0;
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; result = ns_addToNamespace(a1) )
i += 5;
return result;
}

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

for ( i = a2; *i; result = func0(a1) )
i += 5;
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

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

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

if ( !a1 )
return &ns_defaultObj;
v2 = a1;
while ( 1 )
{
result = (void *)func2(v2, a2);
if ( result != &ns_defaultObj )
break;
v2 = (_QWORD *)v2[1];
if ( !v2 )
return &ns_defaultObj;
}
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
void *v1; // rdx

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

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

result = malloc(0x20uLL);
v1 = ns_currContext;
result[1] = 0LL;
*((_DWORD *)result + 6) = 1;
*result = v1;
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 unsigned __int16 **v1; // r12
_BYTE *i; // rbx
__int64 v3; // rax
int v4; // edi

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

canonical_decompiled_code:
void func3()
{
const char *v0; // rbp
const unsigned __int16 **v1; // r12
_BYTE *i; // rbx
__int64 v3; // rax
int v4; // edi

v0 = (const char *)ns_currContext;
if ( ns_currContext )
{
v1 = _ctype_b_loc();
do
{
fprintf(stderr, "%s:%d:\t", *((const char **)v0 + 2), *((unsigned int *)v0 + 6));
for ( i = (_BYTE *)*((_QWORD *)v0 + 1); ; ++i )
{
v3 = (char)*i;
v4 = (char)*i;
if ( ((*v1)[v3] & 0x2000) == 0 )
break;
}
if ( (_BYTE)v3 )
{
do
{
if ( (_BYTE)v4 == 10 )
break;
++i;
putc(v4, stderr);
v4 = (char)*i;
}
while ( *i );
}
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(char *a1, const char *a2, int a3, __int64 a4)
{
char *v4; // r15
unsigned int *v7; // rbp
__int64 v8; // rax
_QWORD *v9; // rax
_QWORD *v10; // rbx
int v11; // er12
int v12; // eax
__int64 v13; // rsi
char *v14; // r13
char v15; // al
__int64 result; // rax
__int64 v17; // rsi
char *v18; // r14
__int64 v19; // rsi
__int64 *v20; // rdi
__int64 v21; // rdx
__int64 v22; // rcx
char v23; // r13
__int64 *v24; // rax
__int64 v25; // rdx
__int64 v26; // rcx
__int64 v27; // rsi
__int64 v28; // rdi
__int16 v29; // ax
char v30; // al
char i; // r13
const unsigned __int16 **v32; // rax
const unsigned __int16 **v33; // r15
unsigned __int16 v34; // si
char v35; // r9
char *v36; // rdx
char v37; // al
char v38; // r13
__int64 v39; // rsi
char v40; // r13
double v41; // xmm0_8
char v42; // al
char v43; // al
__int64 v44; // rax
const char *v45; // rsi
char *v46; // rdi
__int64 v47; // rax
char *v48; // rdi
__int64 v49; // rdx
__int64 v50; // rcx
__int64 v51; // rdx
__int64 v52; // rcx
double v53; // xmm0_8
int v54; // edi
__int64 v55; // rdx
__int64 v56; // rcx
char v57; // dl
const unsigned __int16 *v58; // rdi
char v59; // [rsp+Fh] [rbp-E9h]
char v60; // [rsp+10h] [rbp-E8h]
unsigned int v61; // [rsp+10h] [rbp-E8h]
double v62; // [rsp+18h] [rbp-E0h]
__int64 v64; // [rsp+30h] [rbp-C8h]
int v65; // [rsp+38h] [rbp-C0h]
__int64 v66; // [rsp+60h] [rbp-98h] BYREF
__int64 v67; // [rsp+80h] [rbp-78h] BYREF
__int64 v68; // [rsp+A0h] [rbp-58h] BYREF

v4 = a1;
v7 = (unsigned int *)dynarr_new();
v8 = ns_currNamespace;
ns_currNamespace = a4;
v64 = v8;
v9 = ns_pushContext();
v59 = 0;
*((_DWORD *)v9 + 6) = a3;
v10 = v9;
v11 = 0;
v9[1] = a1;
v9[2] = a2;
v65 = 0;
v62 = *(double *)&LC1;
v12 = 0;
LABEL_2:
switch ( v12 )
{
case 1:
v39 = ns_stack;
v14 = v4;
goto LABEL_72;
case 2:
v39 = ns_stack;
goto LABEL_63;
case 3:
goto LABEL_15;
case 4:
goto LABEL_6;
case 5:
goto LABEL_56;
case 6:
goto LABEL_28;
default:
v18 = v4;
break;
}
LABEL_35:
while ( 2 )
{
while ( 2 )
{
for ( i = *v18; ; i = v35 )
{
if ( i == 35 )
{
do
{
v36 = v18;
v37 = *++v18;
}
while ( v37 != 10 && v37 );
v30 = *v36;
if ( *v36 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v18;
if ( *v36 )
goto LABEL_35;
goto LABEL_11;
}
goto LABEL_34;
}
v32 = _ctype_b_loc();
v33 = v32;
v34 = (*v32)[i];
if ( (v34 & 0x800) != 0 )
{
ns_makeIntObj(&v66, 0LL);
ns_push(&v66, 0LL, v51, v52);
if ( v11 )
goto LABEL_90;
v54 = *v18;
if ( !*v18 )
goto LABEL_11;
if ( ((*v33)[(char)v54] & 0x800) != 0 )
{
v39 = ns_stack;
v14 = v18 + 1;
*(_DWORD *)(ns_stack + 8) = v54 + 10 * *(_DWORD *)(ns_stack + 8) - 48;
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v14;
if ( !*v18 )
goto LABEL_11;
}
else if ( !*v18 )
{
goto LABEL_11;
}
LABEL_72:
while ( 1 )
{
v4 = v14 + 1;
v18 = v14 + 1;
v60 = *v14;
if ( !*v14 )
break;
if ( ((*_ctype_b_loc())[v60] & 0x800) == 0 )
{
if ( v60 == 46 )
goto LABEL_94;
if ( !v11 )
{
LABEL_162:
v43 = *v14;
v18 = v4;
if ( *v14 != 10 )
{
LABEL_79:
v11 = 0;
if ( v43 )
goto LABEL_35;
goto LABEL_11;
}
++*((_DWORD *)v10 + 6);
v11 = 0;
v10[1] = v4;
if ( !*v14 )
goto LABEL_11;
goto LABEL_35;
}
LABEL_78:
*(_DWORD *)(v39 + 8) = -*(_DWORD *)(v39 + 8);
v43 = *v14;
if ( *v14 != 10 )
goto LABEL_79;
++*((_DWORD *)v10 + 6);
v11 = 0;
v10[1] = v4;
if ( !*v14 )
goto LABEL_11;
goto LABEL_35;
}
*(_DWORD *)(v39 + 8) = v60 + 10 * *(_DWORD *)(v39 + 8) - 48;
if ( *v14 == 10 )
{
v12 = 1;
LABEL_98:
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( !*v14 )
goto LABEL_11;
goto LABEL_2;
}
if ( !*v14 )
goto LABEL_11;
++v14;
}
if ( !v11 )
goto LABEL_11;
goto LABEL_78;
}
if ( (_BYTE)v54 != 46 )
{
v14 = v18;
v4 = v18 + 1;
goto LABEL_162;
}
v39 = ns_stack;
v14 = v18;
v4 = v18 + 1;
LABEL_94:
v53 = (double)*(int *)(v39 + 8);
*(_WORD *)v39 = 3;
*(double *)(v39 + 8) = v53;
if ( *v14 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( !*v14 )
goto LABEL_11;
}
else if ( !*v14 )
{
goto LABEL_11;
}
LABEL_63:
v40 = *v4;
v18 = v4 + 1;
if ( *v4 )
{
while ( ((*_ctype_b_loc())[v40] & 0x800) != 0 )
{
v41 = (double)(v40 - 48) * v62 + *(double *)(v39 + 8);
v62 = 0.1 * v62;
*(double *)(v39 + 8) = v41;
v42 = *(v18 - 1);
if ( v42 == 10 )
{
v14 = v4;
v12 = 2;
v4 = v18;
goto LABEL_98;
}
if ( !v42 )
goto LABEL_11;
v4 = v18;
v40 = *v18++;
if ( !v40 )
goto LABEL_68;
}
if ( !v11 )
{
v62 = *(double *)&LC1;
if ( v40 != 10 )
goto LABEL_35;
++*((_DWORD *)v10 + 6);
v10[1] = v18;
if ( *v4 )
goto LABEL_35;
goto LABEL_11;
}
}
else
{
LABEL_68:
if ( !v11 )
goto LABEL_11;
}
*(_QWORD *)(v39 + 8) ^= LC2;
v30 = *v4;
if ( *v4 != 10 )
{
v11 = 0;
v62 = *(double *)&LC1;
goto LABEL_34;
}
++*((_DWORD *)v10 + 6);
v11 = 0;
v10[1] = v18;
v62 = *(double *)&LC1;
if ( !*v4 )
goto LABEL_11;
goto LABEL_35;
}
v35 = v18[1];
if ( i != 45 || !v35 )
break;
if ( ((*v32)[v35] & 0x800) != 0 )
{
ns_makeIntObj(&v66, 0LL);
ns_push(&v66, 0LL, v55, v56);
LABEL_90:
v14 = v18 + 1;
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v14;
if ( !*v18 )
goto LABEL_11;
}
else if ( !*v18 )
{
goto LABEL_11;
}
v39 = ns_stack;
v11 = 1;
goto LABEL_72;
}
if ( (v34 & 0x2000) == 0 )
goto LABEL_136;
++v18;
LABEL_126:
;
}
switch ( i )
{
case 39:
case 34:
v4 = v18 + 1;
dynarr_clear(v7);
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( !*v18 )
goto LABEL_11;
}
else if ( !*v18 )
{
goto LABEL_11;
}
v59 = i;
LABEL_15:
v17 = (unsigned int)*v4;
v18 = v4 + 1;
if ( *v4 == v59 )
goto LABEL_22;
LABEL_16:
if ( v59 == 39 )
{
if ( (_BYTE)v17 == 39 )
{
if ( v4[1] != 39 )
{
v14 = v4;
v17 = 39LL;
goto LABEL_19;
}
while ( 1 )
{
v14 = v18;
v17 = 39LL;
LABEL_19:
v4 = v14 + 1;
dynarr_append(v7, v17);
if ( *v14 == 10 )
{
v12 = 3;
goto LABEL_98;
}
if ( !*v14 )
goto LABEL_11;
v17 = (unsigned int)*v4;
v18 = v14 + 2;
if ( *v4 != v59 )
goto LABEL_16;
LABEL_22:
if ( v59 != 39 || v4[1] != 39 )
{
dynarr_append(v7, 0LL);
v19 = *((_QWORD *)v7 + 1);
v20 = &v67;
ns_makeStrObjLen(&v67, v19, *v7 - 1);
goto LABEL_59;
}
}
}
}
else if ( (_BYTE)v17 == 92 )
{
v17 = (unsigned int)v4[1];
v14 = v18;
switch ( v4[1] )
{
case 'a':
v17 = 7LL;
break;
case 'b':
v17 = 8LL;
break;
case 'f':
v17 = 12LL;
break;
case 'n':
v17 = 10LL;
break;
case 'r':
v17 = 13LL;
break;
case 't':
v17 = 9LL;
break;
case 'v':
v17 = 11LL;
break;
default:
goto LABEL_19;
}
goto LABEL_19;
}
v14 = v4;
goto LABEL_19;
case 123:
v4 = v18 + 1;
dynarr_clear(v7);
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( !*v18 )
goto LABEL_11;
}
else if ( !*v18 )
{
goto LABEL_11;
}
v65 = 1;
LABEL_6:
while ( 2 )
{
v13 = (unsigned int)*v4;
v14 = v4;
if ( *v4 == 123 )
{
if ( ++v65 <= 0 )
goto LABEL_83;
LABEL_9:
++v4;
dynarr_append(v7, v13);
v15 = *(v4 - 1);
if ( v15 == 10 )
{
v12 = 4;
goto LABEL_98;
}
if ( !v15 )
goto LABEL_11;
continue;
}
break;
}
if ( *v4 == 125 )
{
if ( --v65 <= 0 )
goto LABEL_83;
goto LABEL_9;
}
if ( v65 > 0 )
{
if ( !*v4 )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "ns_interpret: Unexpected end of file! Expected %d closing braces.", (unsigned int)v65);
goto LABEL_168;
}
goto LABEL_9;
}
LABEL_83:
dynarr_append(v7, 0LL);
v44 = dynarr_new_alloc(*v7);
v45 = (const char *)*((_QWORD *)v7 + 1);
v46 = *(char **)(v44 + 8);
*(_DWORD *)v44 = *v7;
strcpy(v46, v45);
v61 = strlen(a2);
v47 = dynarr_new_alloc(v61);
v48 = *(char **)(v47 + 8);
*(_DWORD *)v47 = v61 + 1;
strcpy(v48, a2);
v18 = v4 + 1;
ns_push(v48, a2, v49, v50);
v30 = *v4;
if ( *v4 != 10 )
goto LABEL_34;
++*((_DWORD *)v10 + 6);
v10[1] = v18;
if ( !*v4 )
goto LABEL_11;
continue;
case 38:
v4 = v18 + 1;
dynarr_clear(v7);
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( *v18 )
goto LABEL_56;
goto LABEL_11;
}
if ( !*v18 )
goto LABEL_11;
LABEL_56:
while ( 1 )
{
v38 = *v4;
v18 = v4 + 1;
if ( !*v4 || ((*_ctype_b_loc())[v38] & 0x2000) != 0 )
break;
dynarr_append(v7, (unsigned int)v38);
if ( *v4 == 10 )
{
v14 = v4;
v12 = 5;
++v4;
goto LABEL_98;
}
if ( !*v4 )
goto LABEL_11;
++v4;
}
dynarr_append(v7, 0LL);
v19 = *((_QWORD *)v7 + 1);
v20 = &v68;
ns_makeSymObjLen(&v68, v19, *v7 - 1);
LABEL_59:
ns_push(v20, v19, v21, v22);
v30 = *v4;
if ( *v4 != 10 )
goto LABEL_34;
LABEL_60:
++*((_DWORD *)v10 + 6);
v10[1] = v18;
if ( *v4 )
continue;
goto LABEL_11;
case 0:
goto LABEL_11;
}
}
if ( (v34 & 0x2000) != 0 )
{
v4 = v18 + 1;
if ( i == 10 )
{
v14 = v18;
v12 = 0;
goto LABEL_98;
}
++v18;
goto LABEL_126;
}
LABEL_136:
dynarr_clear(v7);
v57 = *v18;
if ( !*v18 )
{
v4 = v18;
LABEL_30:
dynarr_append(v7, 0LL);
v24 = (__int64 *)ns_searchNamespaceInherit(ns_currNamespace, *((_QWORD *)v7 + 1));
v27 = *v24;
v28 = v24[1];
v29 = *(_WORD *)v24;
if ( !v29 )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "Variable '%s' not found!", *((const char **)v7 + 1));
LABEL_168:
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
if ( (unsigned __int16)(v29 - 5) > 2u )
ns_push(v28, v27, v25, v26);
else
ns_execute(v28, v27, v25, v26);
v30 = *v4;
v18 = v4 + 1;
if ( *v4 == 10 )
goto LABEL_60;
LABEL_34:
if ( v30 )
continue;
goto LABEL_11;
}
break;
}
v58 = *v33;
v4 = v18;
if ( (v58[v57] & 0x2000) != 0 )
goto LABEL_30;
v4 = v18 + 1;
dynarr_append(v7, (unsigned int)v57);
if ( *v18 != 10 )
{
if ( !*v18 )
goto LABEL_11;
while ( 1 )
{
LABEL_28:
v23 = *v4;
if ( !*v4 || ((*_ctype_b_loc())[v23] & 0x2000) != 0 )
goto LABEL_30;
dynarr_append(v7, (unsigned int)v23);
if ( *v4 == 10 )
break;
if ( !*v4 )
goto LABEL_11;
++v4;
}
v14 = v4;
v12 = 6;
++v4;
goto LABEL_98;
}
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( *v18 )
goto LABEL_28;
LABEL_11:
dynarr_free(v7);
ns_popContext();
result = v64;
ns_currNamespace = v64;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, const char *a2, int a3, __int64 a4)
{
char *v4; // r15
unsigned int *v7; // rbp
__int64 v8; // rax
_QWORD *v9; // rax
_QWORD *v10; // rbx
int v11; // er12
int v12; // eax
__int64 v13; // rsi
char *v14; // r13
char v15; // al
__int64 result; // rax
__int64 v17; // rsi
char *v18; // r14
__int64 v19; // rsi
__int64 *v20; // rdi
__int64 v21; // rdx
__int64 v22; // rcx
char v23; // r13
__int64 *v24; // rax
__int64 v25; // rdx
__int64 v26; // rcx
__int64 v27; // rsi
__int64 v28; // rdi
__int16 v29; // ax
char v30; // al
char i; // r13
const unsigned __int16 **v32; // rax
const unsigned __int16 **v33; // r15
unsigned __int16 v34; // si
char v35; // r9
char *v36; // rdx
char v37; // al
char v38; // r13
__int64 v39; // rsi
char v40; // r13
double v41; // xmm0_8
char v42; // al
char v43; // al
__int64 v44; // rax
const char *v45; // rsi
char *v46; // rdi
__int64 v47; // rax
char *v48; // rdi
__int64 v49; // rdx
__int64 v50; // rcx
__int64 v51; // rdx
__int64 v52; // rcx
double v53; // xmm0_8
int v54; // edi
__int64 v55; // rdx
__int64 v56; // rcx
char v57; // dl
const unsigned __int16 *v58; // rdi
char v59; // [rsp+Fh] [rbp-E9h]
char v60; // [rsp+10h] [rbp-E8h]
unsigned int v61; // [rsp+10h] [rbp-E8h]
double v62; // [rsp+18h] [rbp-E0h]
__int64 v64; // [rsp+30h] [rbp-C8h]
int v65; // [rsp+38h] [rbp-C0h]
__int64 v66; // [rsp+60h] [rbp-98h] BYREF
__int64 v67; // [rsp+80h] [rbp-78h] BYREF
__int64 v68; // [rsp+A0h] [rbp-58h] BYREF

v4 = a1;
v7 = (unsigned int *)dynarr_new();
v8 = ns_currNamespace;
ns_currNamespace = a4;
v64 = v8;
v9 = func1();
v59 = 0;
*((_DWORD *)v9 + 6) = a3;
v10 = v9;
v11 = 0;
v9[1] = a1;
v9[2] = a2;
v65 = 0;
v62 = *(double *)&LC1;
v12 = 0;
LABEL_2:
switch ( v12 )
{
case 1:
v39 = ns_stack;
v14 = v4;
goto LABEL_72;
case 2:
v39 = ns_stack;
goto LABEL_63;
case 3:
goto LABEL_15;
case 4:
goto LABEL_6;
case 5:
goto LABEL_56;
case 6:
goto LABEL_28;
default:
v18 = v4;
break;
}
LABEL_35:
while ( 2 )
{
while ( 2 )
{
for ( i = *v18; ; i = v35 )
{
if ( i == 35 )
{
do
{
v36 = v18;
v37 = *++v18;
}
while ( v37 != 10 && v37 );
v30 = *v36;
if ( *v36 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v18;
if ( *v36 )
goto LABEL_35;
goto LABEL_11;
}
goto LABEL_34;
}
v32 = _ctype_b_loc();
v33 = v32;
v34 = (*v32)[i];
if ( (v34 & 0x800) != 0 )
{
ns_makeIntObj(&v66, 0LL);
ns_push(&v66, 0LL, v51, v52);
if ( v11 )
goto LABEL_90;
v54 = *v18;
if ( !*v18 )
goto LABEL_11;
if ( ((*v33)[(char)v54] & 0x800) != 0 )
{
v39 = ns_stack;
v14 = v18 + 1;
*(_DWORD *)(ns_stack + 8) = v54 + 10 * *(_DWORD *)(ns_stack + 8) - 48;
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v14;
if ( !*v18 )
goto LABEL_11;
}
else if ( !*v18 )
{
goto LABEL_11;
}
LABEL_72:
while ( 1 )
{
v4 = v14 + 1;
v18 = v14 + 1;
v60 = *v14;
if ( !*v14 )
break;
if ( ((*_ctype_b_loc())[v60] & 0x800) == 0 )
{
if ( v60 == 46 )
goto LABEL_94;
if ( !v11 )
{
LABEL_162:
v43 = *v14;
v18 = v4;
if ( *v14 != 10 )
{
LABEL_79:
v11 = 0;
if ( v43 )
goto LABEL_35;
goto LABEL_11;
}
++*((_DWORD *)v10 + 6);
v11 = 0;
v10[1] = v4;
if ( !*v14 )
goto LABEL_11;
goto LABEL_35;
}
LABEL_78:
*(_DWORD *)(v39 + 8) = -*(_DWORD *)(v39 + 8);
v43 = *v14;
if ( *v14 != 10 )
goto LABEL_79;
++*((_DWORD *)v10 + 6);
v11 = 0;
v10[1] = v4;
if ( !*v14 )
goto LABEL_11;
goto LABEL_35;
}
*(_DWORD *)(v39 + 8) = v60 + 10 * *(_DWORD *)(v39 + 8) - 48;
if ( *v14 == 10 )
{
v12 = 1;
LABEL_98:
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( !*v14 )
goto LABEL_11;
goto LABEL_2;
}
if ( !*v14 )
goto LABEL_11;
++v14;
}
if ( !v11 )
goto LABEL_11;
goto LABEL_78;
}
if ( (_BYTE)v54 != 46 )
{
v14 = v18;
v4 = v18 + 1;
goto LABEL_162;
}
v39 = ns_stack;
v14 = v18;
v4 = v18 + 1;
LABEL_94:
v53 = (double)*(int *)(v39 + 8);
*(_WORD *)v39 = 3;
*(double *)(v39 + 8) = v53;
if ( *v14 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( !*v14 )
goto LABEL_11;
}
else if ( !*v14 )
{
goto LABEL_11;
}
LABEL_63:
v40 = *v4;
v18 = v4 + 1;
if ( *v4 )
{
while ( ((*_ctype_b_loc())[v40] & 0x800) != 0 )
{
v41 = (double)(v40 - 48) * v62 + *(double *)(v39 + 8);
v62 = 0.1 * v62;
*(double *)(v39 + 8) = v41;
v42 = *(v18 - 1);
if ( v42 == 10 )
{
v14 = v4;
v12 = 2;
v4 = v18;
goto LABEL_98;
}
if ( !v42 )
goto LABEL_11;
v4 = v18;
v40 = *v18++;
if ( !v40 )
goto LABEL_68;
}
if ( !v11 )
{
v62 = *(double *)&LC1;
if ( v40 != 10 )
goto LABEL_35;
++*((_DWORD *)v10 + 6);
v10[1] = v18;
if ( *v4 )
goto LABEL_35;
goto LABEL_11;
}
}
else
{
LABEL_68:
if ( !v11 )
goto LABEL_11;
}
*(_QWORD *)(v39 + 8) ^= LC2;
v30 = *v4;
if ( *v4 != 10 )
{
v11 = 0;
v62 = *(double *)&LC1;
goto LABEL_34;
}
++*((_DWORD *)v10 + 6);
v11 = 0;
v10[1] = v18;
v62 = *(double *)&LC1;
if ( !*v4 )
goto LABEL_11;
goto LABEL_35;
}
v35 = v18[1];
if ( i != 45 || !v35 )
break;
if ( ((*v32)[v35] & 0x800) != 0 )
{
ns_makeIntObj(&v66, 0LL);
ns_push(&v66, 0LL, v55, v56);
LABEL_90:
v14 = v18 + 1;
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v14;
if ( !*v18 )
goto LABEL_11;
}
else if ( !*v18 )
{
goto LABEL_11;
}
v39 = ns_stack;
v11 = 1;
goto LABEL_72;
}
if ( (v34 & 0x2000) == 0 )
goto LABEL_136;
++v18;
LABEL_126:
;
}
switch ( i )
{
case 39:
case 34:
v4 = v18 + 1;
dynarr_clear(v7);
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( !*v18 )
goto LABEL_11;
}
else if ( !*v18 )
{
goto LABEL_11;
}
v59 = i;
LABEL_15:
v17 = (unsigned int)*v4;
v18 = v4 + 1;
if ( *v4 == v59 )
goto LABEL_22;
LABEL_16:
if ( v59 == 39 )
{
if ( (_BYTE)v17 == 39 )
{
if ( v4[1] != 39 )
{
v14 = v4;
v17 = 39LL;
goto LABEL_19;
}
while ( 1 )
{
v14 = v18;
v17 = 39LL;
LABEL_19:
v4 = v14 + 1;
dynarr_append(v7, v17);
if ( *v14 == 10 )
{
v12 = 3;
goto LABEL_98;
}
if ( !*v14 )
goto LABEL_11;
v17 = (unsigned int)*v4;
v18 = v14 + 2;
if ( *v4 != v59 )
goto LABEL_16;
LABEL_22:
if ( v59 != 39 || v4[1] != 39 )
{
dynarr_append(v7, 0LL);
v19 = *((_QWORD *)v7 + 1);
v20 = &v67;
ns_makeStrObjLen(&v67, v19, *v7 - 1);
goto LABEL_59;
}
}
}
}
else if ( (_BYTE)v17 == 92 )
{
v17 = (unsigned int)v4[1];
v14 = v18;
switch ( v4[1] )
{
case 'a':
v17 = 7LL;
break;
case 'b':
v17 = 8LL;
break;
case 'f':
v17 = 12LL;
break;
case 'n':
v17 = 10LL;
break;
case 'r':
v17 = 13LL;
break;
case 't':
v17 = 9LL;
break;
case 'v':
v17 = 11LL;
break;
default:
goto LABEL_19;
}
goto LABEL_19;
}
v14 = v4;
goto LABEL_19;
case 123:
v4 = v18 + 1;
dynarr_clear(v7);
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( !*v18 )
goto LABEL_11;
}
else if ( !*v18 )
{
goto LABEL_11;
}
v65 = 1;
LABEL_6:
while ( 2 )
{
v13 = (unsigned int)*v4;
v14 = v4;
if ( *v4 == 123 )
{
if ( ++v65 <= 0 )
goto LABEL_83;
LABEL_9:
++v4;
dynarr_append(v7, v13);
v15 = *(v4 - 1);
if ( v15 == 10 )
{
v12 = 4;
goto LABEL_98;
}
if ( !v15 )
goto LABEL_11;
continue;
}
break;
}
if ( *v4 == 125 )
{
if ( --v65 <= 0 )
goto LABEL_83;
goto LABEL_9;
}
if ( v65 > 0 )
{
if ( !*v4 )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "ns_interpret: Unexpected end of file! Expected %d closing braces.", (unsigned int)v65);
goto LABEL_168;
}
goto LABEL_9;
}
LABEL_83:
dynarr_append(v7, 0LL);
v44 = dynarr_new_alloc(*v7);
v45 = (const char *)*((_QWORD *)v7 + 1);
v46 = *(char **)(v44 + 8);
*(_DWORD *)v44 = *v7;
strcpy(v46, v45);
v61 = strlen(a2);
v47 = dynarr_new_alloc(v61);
v48 = *(char **)(v47 + 8);
*(_DWORD *)v47 = v61 + 1;
strcpy(v48, a2);
v18 = v4 + 1;
ns_push(v48, a2, v49, v50);
v30 = *v4;
if ( *v4 != 10 )
goto LABEL_34;
++*((_DWORD *)v10 + 6);
v10[1] = v18;
if ( !*v4 )
goto LABEL_11;
continue;
case 38:
v4 = v18 + 1;
dynarr_clear(v7);
if ( *v18 == 10 )
{
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( *v18 )
goto LABEL_56;
goto LABEL_11;
}
if ( !*v18 )
goto LABEL_11;
LABEL_56:
while ( 1 )
{
v38 = *v4;
v18 = v4 + 1;
if ( !*v4 || ((*_ctype_b_loc())[v38] & 0x2000) != 0 )
break;
dynarr_append(v7, (unsigned int)v38);
if ( *v4 == 10 )
{
v14 = v4;
v12 = 5;
++v4;
goto LABEL_98;
}
if ( !*v4 )
goto LABEL_11;
++v4;
}
dynarr_append(v7, 0LL);
v19 = *((_QWORD *)v7 + 1);
v20 = &v68;
ns_makeSymObjLen(&v68, v19, *v7 - 1);
LABEL_59:
ns_push(v20, v19, v21, v22);
v30 = *v4;
if ( *v4 != 10 )
goto LABEL_34;
LABEL_60:
++*((_DWORD *)v10 + 6);
v10[1] = v18;
if ( *v4 )
continue;
goto LABEL_11;
case 0:
goto LABEL_11;
}
}
if ( (v34 & 0x2000) != 0 )
{
v4 = v18 + 1;
if ( i == 10 )
{
v14 = v18;
v12 = 0;
goto LABEL_98;
}
++v18;
goto LABEL_126;
}
LABEL_136:
dynarr_clear(v7);
v57 = *v18;
if ( !*v18 )
{
v4 = v18;
LABEL_30:
dynarr_append(v7, 0LL);
v24 = (__int64 *)ns_searchNamespaceInherit(ns_currNamespace, *((_QWORD *)v7 + 1));
v27 = *v24;
v28 = v24[1];
v29 = *(_WORD *)v24;
if ( !v29 )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "Variable '%s' not found!", *((const char **)v7 + 1));
LABEL_168:
putc(10, stderr);
putc(10, stderr);
func3();
exit(1);
}
if ( (unsigned __int16)(v29 - 5) > 2u )
ns_push(v28, v27, v25, v26);
else
ns_execute(v28, v27, v25, v26);
v30 = *v4;
v18 = v4 + 1;
if ( *v4 == 10 )
goto LABEL_60;
LABEL_34:
if ( v30 )
continue;
goto LABEL_11;
}
break;
}
v58 = *v33;
v4 = v18;
if ( (v58[v57] & 0x2000) != 0 )
goto LABEL_30;
v4 = v18 + 1;
dynarr_append(v7, (unsigned int)v57);
if ( *v18 != 10 )
{
if ( !*v18 )
goto LABEL_11;
while ( 1 )
{
LABEL_28:
v23 = *v4;
if ( !*v4 || ((*_ctype_b_loc())[v23] & 0x2000) != 0 )
goto LABEL_30;
dynarr_append(v7, (unsigned int)v23);
if ( *v4 == 10 )
break;
if ( !*v4 )
goto LABEL_11;
++v4;
}
v14 = v4;
v12 = 6;
++v4;
goto LABEL_98;
}
++*((_DWORD *)v10 + 6);
v10[1] = v4;
if ( *v18 )
goto LABEL_28;
LABEL_11:
dynarr_free(v7);
func2();
result = v64;
ns_currNamespace = v64;
return result;
}

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:
_OWORD *ns_initStack()
{
_OWORD *result; // rax
__m128i v1; // xmm0
__m128i v2; // xmm1

result = malloc(0x28uLL);
v1 = _mm_loadu_si128(ns_defaultObj);
v2 = _mm_loadu_si128(&ns_defaultObj[1]);
ns_stackSize = 0;
ns_stack = result;
*((_QWORD *)result + 4) = 0LL;
*result = v1;
result[1] = v2;
return result;
}

canonical_decompiled_code:
_OWORD *func0()
{
_OWORD *result; // rax
__m128i v1; // xmm0
__m128i v2; // xmm1

result = malloc(0x28uLL);
v1 = _mm_loadu_si128(ns_defaultObj);
v2 = _mm_loadu_si128(&ns_defaultObj[1]);
ns_stackSize = 0;
ns_stack = result;
*((_QWORD *)result + 4) = 0LL;
*result = v1;
result[1] = v2;
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; }


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

result = malloc(0x828uLL);
result[5] = 0LL;
result[260] = 0LL;
memset(
(void *)((unsigned __int64)(result + 6) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)result - (((_DWORD)result + 48) & 0xFFFFFFF8) + 2088) >> 3));
*(_BYTE *)result = 0;
return result;
}

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

result = malloc(0x828uLL);
result[5] = 0LL;
result[260] = 0LL;
memset(
(void *)((unsigned __int64)(result + 6) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)result - (((_DWORD)result + 48) & 0xFFFFFFF8) + 2088) >> 3));
*(_BYTE *)result = 0;
return result;
}

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;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
*(_WORD *)a1 = 3;
*(double *)(a1 + 8) = a2;
return result;
}

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

result = a1;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 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, __m128i a7, __m128i a8)
{
__int64 result; // rax
__int64 v9; // rax
const __m128i *v10; // rax

while ( 1 )
{
result = a7.m128i_u16[0];
if ( a7.m128i_i16[0] == 6 )
{
v9 = ns_newNamespace(ns_currNamespace);
return ns_interpret(*(_QWORD *)(a8.m128i_i64[1] + 8), *(_QWORD *)(a7.m128i_i64[1] + 8), a8.m128i_u32[0], v9);
}
if ( a7.m128i_i16[0] != 7 )
break;
a2 = *(_QWORD *)(a7.m128i_i64[1] + 8);
a1 = ns_currNamespace;
v10 = (const __m128i *)ns_searchNamespaceInherit(ns_currNamespace, a2);
if ( v10 == (const __m128i *)&ns_defaultObj )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "exec: Could not find variable '%s'!", *(_QWORD *)(a7.m128i_i64[1] + 8));
goto LABEL_11;
}
a4 = v10->m128i_u16[0];
a3 = (unsigned int)(a4 - 5);
if ( (unsigned __int16)(a4 - 5) > 2u )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "exec: '%s' is not executable!", *(_QWORD *)(a7.m128i_i64[1] + 8));
LABEL_11:
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
a7 = _mm_loadu_si128(v10);
a8 = _mm_loadu_si128(v10 + 1);
}
if ( a7.m128i_i16[0] == 5 )
result = ((__int64 (__fastcall *)(__int64, __int64, __int64, __int64))a7.m128i_i64[1])(a1, a2, a3, a4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __m128i a7, __m128i a8)
{
__int64 result; // rax
__int64 v9; // rax
const __m128i *v10; // rax

while ( 1 )
{
result = a7.m128i_u16[0];
if ( a7.m128i_i16[0] == 6 )
{
v9 = ns_newNamespace(ns_currNamespace);
return ns_interpret(*(_QWORD *)(a8.m128i_i64[1] + 8), *(_QWORD *)(a7.m128i_i64[1] + 8), a8.m128i_u32[0], v9);
}
if ( a7.m128i_i16[0] != 7 )
break;
a2 = *(_QWORD *)(a7.m128i_i64[1] + 8);
a1 = ns_currNamespace;
v10 = (const __m128i *)ns_searchNamespaceInherit(ns_currNamespace, a2);
if ( v10 == (const __m128i *)&ns_defaultObj )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "exec: Could not find variable '%s'!", *(_QWORD *)(a7.m128i_i64[1] + 8));
goto LABEL_11;
}
a4 = v10->m128i_u16[0];
a3 = (unsigned int)(a4 - 5);
if ( (unsigned __int16)(a4 - 5) > 2u )
{
fwrite("\nError: ", 1uLL, 8uLL, stderr);
fprintf(stderr, "exec: '%s' is not executable!", *(_QWORD *)(a7.m128i_i64[1] + 8));
LABEL_11:
putc(10, stderr);
putc(10, stderr);
ns_printContext();
exit(1);
}
a7 = _mm_loadu_si128(v10);
a8 = _mm_loadu_si128(v10 + 1);
}
if ( a7.m128i_i16[0] == 5 )
result = ((__int64 (__fastcall *)(__int64, __int64, __int64, __int64))a7.m128i_i64[1])(a1, a2, a3, a4);
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, char a3)
{
__int64 result; // rax

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

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

if ( a1 )
return 1LL;
fprintf(stderr, a2);
result = 0LL;
if ( a3 )
func0();
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; // r12

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

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

v2 = malloc(a1);
func2((__int64)v2, a2, 1);
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; // r12

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

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

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

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 v5; // rbx
__int64 v6; // r12
const char *v7; // rdi
_DWORD *v9; // rax
gcc_va_list va; // [rsp+0h] [rbp-1118h] BYREF
char s[4096]; // [rsp+20h] [rbp-10F8h] BYREF
__int16 v12; // [rsp+1020h] [rbp-F8h]
unsigned __int64 v13; // [rsp+1028h] [rbp-F0h]

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

canonical_decompiled_code:
__int64 func1(__int64 a1, char a2, int a3, const char *a4, ...)
{
__int64 v5; // rbx
__int64 v6; // r12
const char *v7; // rdi
_DWORD *v9; // rax
gcc_va_list va; // [rsp+0h] [rbp-1118h] BYREF
char s[4096]; // [rsp+20h] [rbp-10F8h] BYREF
__int16 v12; // [rsp+1020h] [rbp-F8h]
unsigned __int64 v13; // [rsp+1028h] [rbp-F0h]

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

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:
void *__fastcall log_retrieve(__int64 a1, int a2)
{
__int64 v2; // rbx
__int64 v3; // r13
void *v4; // rbp
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax

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

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

if ( !a1 )
return 0LL;
v2 = a1;
v3 = 0LL;
v4 = 0LL;
while ( 1 )
{
while ( a2 != *(_DWORD *)v2 )
{
v2 = *(_QWORD *)(v2 + 24);
if ( !v2 )
return v4;
}
v5 = strlen(*(const char **)(v2 + 8));
v4 = v4 ? realloc(v4, v3 + v5 + 3) : calloc(1uLL, v5 + 2);
if ( !v4 )
break;
v6 = strlen((const char *)v4);
*(_WORD *)stpcpy((char *)v4 + v6, *(const char **)(v2 + 8)) = 10;
++*(_DWORD *)(v2 + 16);
v7 = strlen((const char *)v4);
v2 = *(_QWORD *)(v2 + 24);
v3 = v7;
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 *


decompiled_code:
__int64 __fastcall log_clear_partial(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // rbp
_QWORD *v4; // rbx
__int64 v6; // r14
void *v7; // rdi

if ( !a1 )
return 0LL;
v3 = (_QWORD *)a1[3];
v4 = a1;
if ( !v3 )
return 0LL;
v6 = 0LL;
do
{
while ( *(_DWORD *)v3 != a2 || a3 != 1 && !*((_DWORD *)v3 + 4) )
{
v4 = v3;
v3 = (_QWORD *)v3[3];
if ( !v3 )
return v6;
}
v7 = (void *)v3[1];
v4[3] = v3[3];
if ( v7 )
free(v7);
++v6;
free(v3);
v3 = (_QWORD *)v4[3];
}
while ( v3 );
return v6;
}

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

if ( ptr )
{
v1 = 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

if ( ptr )
{
v1 = 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 v5; // r15
bool v9; // al
ssize_t v10; // rax

if ( !a4 )
return 0LL;
v5 = 0LL;
do
{
v10 = read(a2, (void *)(a3 + v5), a4 - v5);
if ( v10 == -1 )
{
if ( *_errno_location() != 4 )
{
close(a2);
perror(a5);
return 0xFFFFFFFFLL;
}
v9 = 1;
if ( v5 == a4 )
return 0LL;
}
else
{
v5 += v10;
v9 = v10 != 0;
if ( v5 == a4 )
return 0LL;
}
}
while ( v9 );
if ( v5 == 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 v5; // r15
bool v9; // al
ssize_t v10; // rax

if ( !a4 )
return 0LL;
v5 = 0LL;
do
{
v10 = read(a2, (void *)(a3 + v5), a4 - v5);
if ( v10 == -1 )
{
if ( *_errno_location() != 4 )
{
close(a2);
perror(a5);
return 0xFFFFFFFFLL;
}
v9 = 1;
if ( v5 == a4 )
return 0LL;
}
else
{
v5 += v10;
v9 = v10 != 0;
if ( v5 == a4 )
return 0LL;
}
}
while ( v9 );
if ( v5 == 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:
// attributes: thunk
void *safe_memcpy(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}

canonical_decompiled_code:
void *func2(void *dest, const void *src, size_t n)
{
return memcpy(dest, src, n);
}

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; // rsi
char v3; // al

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

canonical_decompiled_code:
_BOOL8 __fastcall func3(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // rsi
char v3; // al

if ( !a2 )
return 1LL;
v2 = &a1[a2];
v3 = 0;
do
v3 += *a1++;
while ( v2 != a1 );
return v3 == 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, __int64 *a3, const char *a4)
{
int v7; // eax
int v8; // ebp
size_t v9; // rdi
__off_t v10; // rax
void *v11; // r12
void *v12; // rdi
struct stat v14; // [rsp+0h] [rbp-C8h] BYREF

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

canonical_decompiled_code:
void *__fastcall func4(__int64 a1, __off_t a2, __int64 *a3, const char *a4)
{
int v7; // eax
int v8; // ebp
size_t v9; // rdi
__off_t v10; // rax
void *v11; // r12
void *v12; // rdi
struct stat v14; // [rsp+0h] [rbp-C8h] BYREF

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

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