original_code:
static void mx_f_callback(int *rs, int r, int *ws, int w)
{
    struct net_socket_listener *l = list, *p = (struct net_socket_listener *)0;
    while (l != (struct net_socket_listener *)0)
    {
        next:
        if (l->socket >= 0)
        {
            int i;
            for (i = 0; i < r; i++)
            {
                if (rs[i] == l->socket)
                {
                    int fdr, fdw;
                    enum io_result res;
                    if ((res = a_accept_socket (&fdr, l->socket))== io_complete)
                    {
                        fdw = a_dup_n (fdr);
                        if (fdw >= 0)
                        {
                            struct io *in, *out;
                            in = io_open (fdr);
                            out = io_open (fdw);
                            in->type = iot_read;
                            out->type = iot_write;
                            l->on_connect(in, out, l->data);
                        }
                        else
                        {
                            (void)a_close (fdr);
                        }
                    }
                    else if (res == io_unrecoverable_error)
                    {
                        (void)a_close (rs[i]);
                        if (p == (struct net_socket_listener *)0)
                        {
                            list = l->next;
                            free_pool_mem (l);
                            l = list->next;
                        }
                        else
                        {
                            p->next = l->next;
                            free_pool_mem (l);
                            l = p->next;
                        }
                        if (l != (struct net_socket_listener *)0)
                        {
                            goto next;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }
        p = l;
        l = l->next;
    }
}

canonical_original_code:
static void mx_f_callback(int *rs, int r, int *ws, int w)
{
    struct net_socket_listener *l = list; struct net_socket_listener *p = (struct net_socket_listener *)0;
    while (l != (struct net_socket_listener *)0)
    {
        next:
        if (l->socket >= 0)
        {
            int i;
            for (i = 0; i < r; i++)
            {
                if (rs[i] == l->socket)
                {
                    int fdr; int fdw;
                    enum io_result res;
                    if ((res = a_accept_socket (&fdr, l->socket))== io_complete)
                    {
                        fdw = a_dup_n (fdr);
                        if (fdw >= 0)
                        {
                            struct io *in; struct io *out;
                            in = io_open (fdr);
                            out = io_open (fdw);
                            in->type = iot_read;
                            out->type = iot_write;
                            l->on_connect(in, out, l->data);
                        }
                        else
                        {
                            (void)a_close (fdr);
                        }
                    }
                    else if (res == io_unrecoverable_error)
                    {
                        (void)a_close (rs[i]);
                        if (p == (struct net_socket_listener *)0)
                        {
                            list = l->next;
                            free_pool_mem (l);
                            l = list->next;
                        }
                        else
                        {
                            p->next = l->next;
                            free_pool_mem (l);
                            l = p->next;
                        }
                        if (l != (struct net_socket_listener *)0)
                        {
                            goto next;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }
        p = l;
        l = l->next;
    }
}

variable_types: r int

variable_types: w int

variable_types: fdr int

variable_types: fdw int

variable_types: struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *


multiplex

repo: kyuba/curie

decompiled_code:
__int64 multiplex()
{
__int64 v0; // rbx
__int64 i; // rbx
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // r15
signed __int64 v5; // rax
void *v6; // rsp
void *v7; // rsp
__int64 j; // r12
_QWORD v9[3]; // [rsp+0h] [rbp-50h] BYREF
_QWORD v10[7]; // [rsp+18h] [rbp-38h] BYREF

v0 = mx_func_list;
v10[0] = 0LL;
if ( !mx_func_list )
return 1LL;
do
{
if ( (*(unsigned int (__fastcall **)(_QWORD *, char *))v0)(v10, (char *)v10 + 4) == 2 )
{
for ( i = mx_func_list; i; i = *(_QWORD *)(i + 24) )
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(i + 16))(0LL, 0LL, 0LL, 0LL);
return 0LL;
}
v0 = *(_QWORD *)(v0 + 24);
}
while ( v0 );
v3 = SHIDWORD(v10[0]);
if ( !v10[0] )
return 1LL;
v9[1] = v9;
v4 = mx_func_list;
v5 = (4LL * SLODWORD(v10[0]) + 15) & 0xFFFFFFFFFFFFFFF0LL;
v10[0] = 0LL;
v6 = alloca(v5);
v7 = alloca(4 * v3);
if ( !mx_func_list )
return 1LL;
do
{
(*(void (__fastcall **)(_QWORD *, _QWORD *, _QWORD *, char *))(v4 + 8))(v9, v10, v9, (char *)v10 + 4);
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
if ( LODWORD(v10[0]) || (result = 1LL, HIDWORD(v10[0])) )
{
a_select_with_fds(v9, LODWORD(v10[0]), v9, HIDWORD(v10[0]));
for ( j = mx_func_list; j; j = *(_QWORD *)(j + 24) )
(*(void (__fastcall **)(_QWORD *, _QWORD, _QWORD *, _QWORD))(j + 16))(v9, LODWORD(v10[0]), v9, HIDWORD(v10[0]));
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
__int64 i; // rbx
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // r15
signed __int64 v5; // rax
void *v6; // rsp
void *v7; // rsp
__int64 j; // r12
_QWORD v9[3]; // [rsp+0h] [rbp-50h] BYREF
_QWORD v10[7]; // [rsp+18h] [rbp-38h] BYREF

v0 = mx_func_list;
v10[0] = 0LL;
if ( !mx_func_list )
return 1LL;
do
{
if ( (*(unsigned int (__fastcall **)(_QWORD *, char *))v0)(v10, (char *)v10 + 4) == 2 )
{
for ( i = mx_func_list; i; i = *(_QWORD *)(i + 24) )
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(i + 16))(0LL, 0LL, 0LL, 0LL);
return 0LL;
}
v0 = *(_QWORD *)(v0 + 24);
}
while ( v0 );
v3 = SHIDWORD(v10[0]);
if ( !v10[0] )
return 1LL;
v9[1] = v9;
v4 = mx_func_list;
v5 = (4LL * SLODWORD(v10[0]) + 15) & 0xFFFFFFFFFFFFFFF0LL;
v10[0] = 0LL;
v6 = alloca(v5);
v7 = alloca(4 * v3);
if ( !mx_func_list )
return 1LL;
do
{
(*(void (__fastcall **)(_QWORD *, _QWORD *, _QWORD *, char *))(v4 + 8))(v9, v10, v9, (char *)v10 + 4);
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
if ( LODWORD(v10[0]) || (result = 1LL, HIDWORD(v10[0])) )
{
a_select_with_fds(v9, LODWORD(v10[0]), v9, HIDWORD(v10[0]));
for ( j = mx_func_list; j; j = *(_QWORD *)(j + 24) )
(*(void (__fastcall **)(_QWORD *, _QWORD, _QWORD *, _QWORD))(j + 16))(v9, LODWORD(v10[0]), v9, HIDWORD(v10[0]));
result = 0LL;
}
return result;
}

original_code:
enum multiplex_result multiplex () {
    struct multiplex_functions *cur = mx_func_list;
    int rnum = 0, wnum = 0;
    for (cur = mx_func_list;
         cur != (struct multiplex_functions *)0;
         cur = cur->next)
    {
        if (cur->count (&rnum, &wnum) == mx_immediate_action)
        {
            for (cur = mx_func_list;
                 cur != (struct multiplex_functions *)0;
                 cur = cur->next)
            {
                cur->callback ((int *)0, 0, (int *)0, 0);
            }
            return mx_ok;
        }
    }
    if ((rnum == 0) && (wnum == 0)) {
        return mx_nothing_to_do;
    } else {
        int rfds[rnum], wfds[wnum];
        rnum = 0;
        wnum = 0;
        for (cur = mx_func_list;
             cur != (struct multiplex_functions *)0;
             cur = cur->next) {
            cur->augment (rfds, &rnum, wfds, &wnum);
        }
        if ((rnum == 0) && (wnum == 0)) {
            return mx_nothing_to_do;
        }
        a_select_with_fds (rfds, rnum, wfds, wnum);
        for (cur = mx_func_list;
             cur != (struct multiplex_functions *)0;
             cur = cur->next) {
            cur->callback (rfds, rnum, wfds, wnum);
        }
        return mx_ok;
    }
}

canonical_original_code:
enum multiplex_result multiplex() {
    struct multiplex_functions *cur = mx_func_list;
    int rnum = 0; int wnum = 0;
    for (cur = mx_func_list;
         cur != (struct multiplex_functions *)0;
         cur = cur->next)
    {
        if (cur->count (&rnum, &wnum) == mx_immediate_action)
        {
            for (cur = mx_func_list;
                 cur != (struct multiplex_functions *)0;
                 cur = cur->next)
            {
                cur->callback ((int *)0, 0, (int *)0, 0);
            }
            return mx_ok;
        }
    }
    if ((rnum == 0) && (wnum == 0)) {
        return mx_nothing_to_do;
    } else {
        int rfds[-1]; int wfds[-1];
        rnum = 0;
        wnum = 0;
        for (cur = mx_func_list;
             cur != (struct multiplex_functions *)0;
             cur = cur->next) {
            cur->augment (rfds, &rnum, wfds, &wnum);
        }
        if ((rnum == 0) && (wnum == 0)) {
            return mx_nothing_to_do;
        }
        a_select_with_fds (rfds, rnum, wfds, wnum);
        for (cur = mx_func_list;
             cur != (struct multiplex_functions *)0;
             cur = cur->next) {
            cur->callback (rfds, rnum, wfds, wnum);
        }
        return mx_ok;
    }
}

variable_types: struct multiplex_functions { enum multiplex_result { mx_ok=0, mx_nothing_to_do=1, mx_immediate_action=2 } (*count)(int *, int *); void (*augment)(int *, int *, int *, int *); void (*callback)(int *, int, int *, int); struct multiplex_functions *next; } *

variable_types: rnum int

variable_types: wnum int

variable_types:
rfds
int [-1]

variable_types:
wfds
int [-1]

user_defined_types: struct multiplex_functions { enum multiplex_result (*count)(int *, int *); void (*augment)(int *, int *, int *, int *); void (*callback)(int *, int, int *, int); struct multiplex_functions *next; }


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

result = mx_func_list;
mx_func_list = a1;
*(_QWORD *)(a1 + 24) = result;
return result;
}

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

result = mx_func_list;
mx_func_list = a1;
*(_QWORD *)(a1 + 24) = result;
return result;
}

original_code:
void multiplex_add (struct multiplex_functions *mx) {
    mx->next = mx_func_list;
    mx_func_list = mx;
}

canonical_original_code:
void multiplex_add(struct multiplex_functions *mx) {
    mx->next = mx_func_list;
    mx_func_list = mx;
}

return_type: void

user_defined_types: enum multiplex_result { mx_ok=0, mx_nothing_to_do=1, mx_immediate_action=2 }


decompiled_code:
__int64 __fastcall sx_register_type(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax
__int64 v12; // rdx

result = get_pool_mem(&pool_0);
if ( result )
{
*(_DWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(result + 48) = a7;
v12 = sxcd;
*(_QWORD *)(result + 16) = a3;
*(_QWORD *)(result + 24) = a4;
*(_QWORD *)(result + 32) = a5;
*(_QWORD *)(result + 40) = a6;
*(_QWORD *)(result + 56) = v12;
sxcd = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax
__int64 v12; // rdx

result = get_pool_mem(&pool_0);
if ( result )
{
*(_DWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(result + 48) = a7;
v12 = sxcd;
*(_QWORD *)(result + 16) = a3;
*(_QWORD *)(result + 24) = a4;
*(_QWORD *)(result + 32) = a5;
*(_QWORD *)(result + 40) = a6;
*(_QWORD *)(result + 56) = v12;
sxcd = result;
}
return result;
}

original_code:
void sx_register_type
        (unsigned int type,
         sexpr (*serialise) (sexpr), sexpr (*unserialise) (sexpr),
         void (*tag) (sexpr), void (*destroy) (sexpr), void (*call) (),
         sexpr (*equalp) (sexpr, sexpr))
{
    static struct memory_pool pool =
            { mpft_static_header, ((((unsigned long)sizeof (struct sexpr_type_descriptor)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct sexpr_type_descriptor)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct sexpr_type_descriptor))) ? ((unsigned short)8) : 0)) };
    struct sexpr_type_descriptor *d = get_pool_mem (&pool);
    if (d == (struct sexpr_type_descriptor *)0)
    {
        return;
    }
    d->type = type;
    d->serialise = serialise;
    d->unserialise = unserialise;
    d->tag = tag;
    d->destroy = destroy;
    d->call = call;
    d->equalp = equalp;
    d->next = sxcd;
    sxcd = d;
}

canonical_original_code:
void sx_register_type(unsigned int type, unsigned long (*serialise)(unsigned long), unsigned long (*unserialise)(unsigned long), void (*tag)(unsigned long), void (*destroy)(unsigned long), void (*call)(), unsigned long (*equalp)(unsigned long, unsigned long))
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct sexpr_type_descriptor)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct sexpr_type_descriptor)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct sexpr_type_descriptor))) ? ((unsigned short)8) : 0)) };
    struct sexpr_type_descriptor *d = get_pool_mem (&pool);
    if (d == (struct sexpr_type_descriptor *)0)
    {
        return;
    }
    d->type = type;
    d->serialise = serialise;
    d->unserialise = unserialise;
    d->tag = tag;
    d->destroy = destroy;
    d->call = call;
    d->equalp = equalp;
    d->next = sxcd;
    sxcd = d;
}

variable_types:
type
unsigned int

variable_types:
unserialise
unsigned long (*)(unsigned long)

variable_types:
tag
void (*)(unsigned long)

variable_types:
destroy
void (*)(unsigned long)

variable_types:
call
void (*)()

variable_types: unsigned long (*)(unsigned long, unsigned long)

variable_types: struct memory_pool { enum memory_pool_frame_type { mpft_static_header=0, mpft_frame=1 } type; unsigned int entitysize; }

variable_types: struct sexpr_type_descriptor { unsigned int type; unsigned long (*serialise)(unsigned long); unsigned long (*unserialise)(unsigned long); void (*tag)(unsigned long); void (*destroy)(unsigned long); void (*call)(); unsigned long (*equalp)(unsigned long, unsigned long); struct sexpr_type_descriptor *next; } *

user_defined_types: struct memory_pool { enum memory_pool_frame_type type; unsigned int entitysize; }


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

for ( result = sxcd; result; result = *(_QWORD *)(result + 56) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = sxcd; result; result = *(_QWORD *)(result + 56) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
struct sexpr_type_descriptor *sx_get_descriptor (unsigned int type)
{
    struct sexpr_type_descriptor *d = sxcd;
    while (d != (struct sexpr_type_descriptor *)0)
    {
        if (d->type == type)
        {
            return d;
        }
        d = d->next;
    }
    return (struct sexpr_type_descriptor *)0;
}

canonical_original_code:
struct sexpr_type_descriptor *sx_get_descriptor(unsigned int type)
{
    struct sexpr_type_descriptor *d = sxcd;
    while (d != (struct sexpr_type_descriptor *)0)
    {
        if (d->type == type)
        {
            return d;
        }
        d = d->next;
    }
    return (struct sexpr_type_descriptor *)0;
}

return_type: struct sexpr_type_descriptor { unsigned int type; unsigned long (*serialise)(unsigned long); unsigned long (*unserialise)(unsigned long); void (*tag)(unsigned long); void (*destroy)(unsigned long); void (*call)(); unsigned long (*equalp)(unsigned long, unsigned long); struct sexpr_type_descriptor *next; } *


decompiled_code:
__int64 sx_call_custom()
{
__int64 i; // rbx
__int64 (*v1)(void); // rdx
__int64 result; // rax

for ( i = sxcd; i; i = *(_QWORD *)(i + 56) )
{
v1 = *(__int64 (**)(void))(i + 40);
if ( v1 )
result = v1();
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 i; // rbx
__int64 (*v1)(void); // rdx
__int64 result; // rax

for ( i = sxcd; i; i = *(_QWORD *)(i + 56) )
{
v1 = *(__int64 (**)(void))(i + 40);
if ( v1 )
result = v1();
}
return result;
}

original_code:
void sx_call_custom ( void )
{
    struct sexpr_type_descriptor *d = sxcd;
    while (d != (struct sexpr_type_descriptor *)0)
    {
        if (d->call != (void *)0)
        {
            d->call ();
        }
        d = d->next;
    }
}

canonical_original_code:
void sx_call_custom()
{
    struct sexpr_type_descriptor *d = sxcd;
    while (d != (struct sexpr_type_descriptor *)0)
    {
        if (d->call != (void *)0)
        {
            d->call ();
        }
        d = d->next;
    }
}

user_defined_types: struct sexpr_type_descriptor { unsigned int type; unsigned long (*serialise)(unsigned long); unsigned long (*unserialise)(unsigned long); void (*tag)(unsigned long); void (*destroy)(unsigned long); void (*call)(); unsigned long (*equalp)(unsigned long, unsigned long); struct sexpr_type_descriptor *next; }


partition

decompiled_code:
__int64 __fastcall partition(unsigned int a1, int a2, int a3)
{
__int64 v4; // rdi
unsigned __int64 *v6; // rax
unsigned __int64 *v7; // r11
unsigned __int64 v8; // rsi
unsigned __int64 *v9; // rax
unsigned __int64 v10; // r9
unsigned __int64 v11; // rdx
__int64 v12; // rcx
unsigned __int64 *v13; // rcx
unsigned __int64 *v14; // rax
unsigned __int64 v15; // rdx
__int64 result; // rax

v4 = gc_calls;
v6 = (unsigned __int64 *)(gc_calls + 8LL * a3);
v7 = (unsigned __int64 *)(gc_calls + 8LL * a2);
v8 = *v6;
*v6 = *v7;
*v7 = v8;
if ( a2 > (int)a1 )
{
v9 = (unsigned __int64 *)(v4 + 8LL * (int)a1);
v10 = v4 + 8 * ((int)a1 + (unsigned __int64)(a2 - a1 - 1)) + 8;
do
{
v11 = *v9;
if ( *v9 <= v8 )
{
v12 = (int)a1++;
v13 = (unsigned __int64 *)(v4 + 8 * v12);
*v9 = *v13;
*v13 = v11;
}
++v9;
}
while ( v9 != (unsigned __int64 *)v10 );
v8 = *v7;
}
v14 = (unsigned __int64 *)(v4 + 8LL * (int)a1);
v15 = *v14;
*v14 = v8;
result = a1;
*v7 = v15;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, int a3)
{
__int64 v4; // rdi
unsigned __int64 *v6; // rax
unsigned __int64 *v7; // r11
unsigned __int64 v8; // rsi
unsigned __int64 *v9; // rax
unsigned __int64 v10; // r9
unsigned __int64 v11; // rdx
__int64 v12; // rcx
unsigned __int64 *v13; // rcx
unsigned __int64 *v14; // rax
unsigned __int64 v15; // rdx
__int64 result; // rax

v4 = gc_calls;
v6 = (unsigned __int64 *)(gc_calls + 8LL * a3);
v7 = (unsigned __int64 *)(gc_calls + 8LL * a2);
v8 = *v6;
*v6 = *v7;
*v7 = v8;
if ( a2 > (int)a1 )
{
v9 = (unsigned __int64 *)(v4 + 8LL * (int)a1);
v10 = v4 + 8 * ((int)a1 + (unsigned __int64)(a2 - a1 - 1)) + 8;
do
{
v11 = *v9;
if ( *v9 <= v8 )
{
v12 = (int)a1++;
v13 = (unsigned __int64 *)(v4 + 8 * v12);
*v9 = *v13;
*v13 = v11;
}
++v9;
}
while ( v9 != (unsigned __int64 *)v10 );
v8 = *v7;
}
v14 = (unsigned __int64 *)(v4 + 8LL * (int)a1);
v15 = *v14;
*v14 = v8;
result = a1;
*v7 = v15;
return result;
}

original_code:
static int partition (int left, int right, int pivot)
{
    int index, i;
    sexpr value = gc_calls[pivot], t;
    gc_calls[pivot] = gc_calls[right];
    gc_calls[right] = value;
    index = left;
    for (i = left; i < right; i++)
    {
        if (gc_calls[i] <= value)
        {
            t = gc_calls[i];
            gc_calls[i] = gc_calls[index];
            gc_calls[index] = t;
            index++;
        }
    }
    t = gc_calls[index];
    gc_calls[index] = gc_calls[right];
    gc_calls[right] = t;
    return index;
}

canonical_original_code:
static int partition(int left, int right, int pivot)
{
    int index; int i;
    unsigned long value = gc_calls[pivot]; unsigned long t;
    gc_calls[pivot] = gc_calls[right];
    gc_calls[right] = value;
    index = left;
    for (i = left; i < right; i++)
    {
        if (gc_calls[i] <= value)
        {
            t = gc_calls[i];
            gc_calls[i] = gc_calls[index];
            gc_calls[index] = t;
            index++;
        }
    }
    t = gc_calls[index];
    gc_calls[index] = gc_calls[right];
    gc_calls[right] = t;
    return index;
}

variable_types: left int

variable_types: right int

variable_types: pivot int

variable_types: index int

variable_types: i int

variable_types:
value
unsigned long

variable_types:
t
unsigned long

return_type: int


decompiled_code:
__int64 __fastcall gc_tag(__int64 a1)
{
return gc_tag_sub(a1, gc_calls, gc_pointer);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return func3(a1, gc_calls, gc_pointer);
}

original_code:
void gc_tag (sexpr sx)
{
    gc_tag_sub (sx, gc_calls, gc_pointer);
}

canonical_original_code:
void gc_tag(unsigned long sx)
{
    gc_tag_sub (sx, gc_calls, gc_pointer);
}

variable_types:
sx
unsigned long


decompiled_code:
__int64 __fastcall gc_initialise_memory(__int64 a1, __int64 a2)
{
__int64 **v2; // rbx
unsigned __int64 v3; // rbp
__int64 result; // rax

gc_call_size = (gc_base_items & 0xFFFFFFFFFFFFF000LL) + 4096;
gc_calls = get_mem((gc_base_items & 0xFFFFFFFFFFFFF000LL) + 4096, a2);
gc_pointer = gc_calls;
sx_call_all();
sx_call_custom();
if ( cancel )
{
free_mem(gc_call_size, gc_calls);
result = 0LL;
}
else
{
sort_calls(0, ((gc_pointer - gc_calls) >> 3) - 1);
if ( gc_roots_size )
{
v2 = (__int64 **)gc_roots;
v3 = gc_roots + gc_roots_size;
if ( gc_roots < (unsigned __int64)(gc_roots + gc_roots_size) )
{
do
{
if ( *v2 )
gc_tag(**v2);
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}
cancel = 0;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 **v2; // rbx
unsigned __int64 v3; // rbp
__int64 result; // rax

gc_call_size = (gc_base_items & 0xFFFFFFFFFFFFF000LL) + 4096;
gc_calls = get_mem((gc_base_items & 0xFFFFFFFFFFFFF000LL) + 4096, a2);
gc_pointer = gc_calls;
sx_call_all();
sx_call_custom();
if ( cancel )
{
free_mem(gc_call_size, gc_calls);
result = 0LL;
}
else
{
func1(0, ((gc_pointer - gc_calls) >> 3) - 1);
if ( gc_roots_size )
{
v2 = (__int64 **)gc_roots;
v3 = gc_roots + gc_roots_size;
if ( gc_roots < (unsigned __int64)(gc_roots + gc_roots_size) )
{
do
{
if ( *v2 )
func2(**v2);
++v2;
}
while ( v3 > (unsigned __int64)v2 );
}
}
cancel = 0;
result = 1LL;
}
return result;
}

original_code:
static int gc_initialise_memory ()
{
    gc_call_size = (gc_base_items & (~(0x1000 - 1)))
                  + 0x1000;
    gc_calls = get_mem (gc_call_size);
    gc_pointer = gc_calls;
    sx_call_all();
    sx_call_custom();
    if (cancel)
    {
        free_mem (gc_call_size, gc_calls);
        return 0;
    }
    sort_calls (0, gc_pointer - gc_calls - 1);
    if (gc_roots_size != 0)
    {
        sexpr **rootp, **roote;
        for (rootp = gc_roots,
             roote = (sexpr**)((int_pointer)rootp + gc_roots_size);
             rootp < roote; rootp++)
        {
            if ((*rootp) != (sexpr *)0)
            {
                gc_tag (**rootp);
            }
        }
    }
    cancel = 0;
    return 1;
}

canonical_original_code:
static int gc_initialise_memory()
{
    gc_call_size = (gc_base_items & (~(0x1000 - 1)))
                  + 0x1000;
    gc_calls = get_mem (gc_call_size);
    gc_pointer = gc_calls;
    sx_call_all();
    sx_call_custom();
    if (cancel)
    {
        free_mem (gc_call_size, gc_calls);
        return 0;
    }
    sort_calls (0, gc_pointer - gc_calls - 1);
    if (gc_roots_size != 0)
    {
        unsigned long **rootp; unsigned long **roote;
        for (rootp = gc_roots,
             roote = (unsigned long **)((unsigned long)rootp + gc_roots_size);
             rootp < roote; rootp++)
        {
            if ((*rootp) != (unsigned long *)0)
            {
                gc_tag (**rootp);
            }
        }
    }
    cancel = 0;
    return 1;
}

variable_types:
rootp
unsigned long **

variable_types:
roote
unsigned long **


decompiled_code:
void __fastcall gc_call(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rax
__int64 v3; // rdx

if ( !cancel )
{
v1 = (_QWORD *)gc_pointer;
if ( gc_pointer >= (unsigned __int64)(gc_calls + gc_call_size) )
{
v2 = resize_mem(gc_call_size, gc_calls, gc_call_size + 4096);
gc_call_size += 4096LL;
v3 = v2;
v1 = (_QWORD *)(v2 + gc_pointer - gc_calls);
gc_calls = v3;
*v1 = a1;
}
else
{
*(_QWORD *)gc_pointer = a1;
}
gc_pointer = (__int64)(v1 + 1);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rax
__int64 v3; // rdx

if ( !cancel )
{
v1 = (_QWORD *)gc_pointer;
if ( gc_pointer >= (unsigned __int64)(gc_calls + gc_call_size) )
{
v2 = resize_mem(gc_call_size, gc_calls, gc_call_size + 4096);
gc_call_size += 4096LL;
v3 = v2;
v1 = (_QWORD *)(v2 + gc_pointer - gc_calls);
gc_calls = v3;
*v1 = a1;
}
else
{
*(_QWORD *)gc_pointer = a1;
}
gc_pointer = (__int64)(v1 + 1);
}
}

original_code:
void gc_call (sexpr sx)
{
    sexpr *map;
    if (cancel) return;
    if (gc_pointer < (sexpr*)((int_pointer)gc_calls + gc_call_size))
    {
      add:
        *gc_pointer = sx;
        gc_pointer++;
        return;
    }
    map = resize_mem (gc_call_size, gc_calls, gc_call_size + 0x1000);
    gc_pointer = (sexpr *)((int_pointer)map +
                   ((int_pointer)gc_pointer - (int_pointer)gc_calls));
    gc_calls = map;
    gc_call_size += 0x1000;
    goto add;
}

canonical_original_code:
void gc_call(unsigned long sx)
{
    unsigned long *map;
    if (cancel) return;
    if (gc_pointer < (unsigned long *)((unsigned long)gc_calls + gc_call_size))
    {
      add:
        *gc_pointer = sx;
        gc_pointer++;
        return;
    }
    map = resize_mem (gc_call_size, gc_calls, gc_call_size + 0x1000);
    gc_pointer = (unsigned long *)((unsigned long)map +
                   ((unsigned long)gc_pointer - (unsigned long)gc_calls));
    gc_calls = map;
    gc_call_size += 0x1000;
    goto add;
}

variable_types:
map
unsigned long *


decompiled_code:
__int64 __fastcall gc_invoke(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 *v3; // rbx
__int64 i; // rbp
__int64 v5; // rdi
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

if ( stack_growth )
{
v7[0] = 45LL;
if ( stack_growth != 1 || stack_start_address <= (unsigned __int64)v7 )
{
v2 = 1LL;
if ( (unsigned int)gc_initialise_memory(a1, a2) )
goto LABEL_4;
}
}
else
{
v7[0] = 45LL;
v2 = -1LL;
if ( stack_start_address >= (unsigned __int64)v7 && (unsigned int)gc_initialise_memory(a1, a2) )
{
LABEL_4:
v3 = (__int64 *)stack_start_address;
for ( i = 8 * v2; ; v3 = (__int64 *)((char *)v3 + i) )
{
v5 = *v3;
if ( *v3 )
{
if ( (v5 & 1) == 0 )
gc_tag(v5);
}
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 *v3; // rbx
__int64 i; // rbp
__int64 v5; // rdi
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

if ( stack_growth )
{
v7[0] = 45LL;
if ( stack_growth != 1 || stack_start_address <= (unsigned __int64)v7 )
{
v2 = 1LL;
if ( (unsigned int)func4(a1, a2) )
goto LABEL_4;
}
}
else
{
v7[0] = 45LL;
v2 = -1LL;
if ( stack_start_address >= (unsigned __int64)v7 && (unsigned int)func4(a1, a2) )
{
LABEL_4:
v3 = (__int64 *)stack_start_address;
for ( i = 8 * v2; ; v3 = (__int64 *)((char *)v3 + i) )
{
v5 = *v3;
if ( *v3 )
{
if ( (v5 & 1) == 0 )
func2(v5);
}
}
}
}
return 0LL;
}

original_code:
unsigned long gc_invoke ()
{
    int step = (stack_growth == sg_down) ? -1 : 1;
    sexpr end = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    sexpr *t, *l = &end;
    unsigned int i, k;
    unsigned long rv = 0;
    if (((stack_growth == sg_down) && (stack_start_address < (void *)l)) ||
        ((stack_growth == sg_up) && (stack_start_address > (void *)l)))
    {
        return 0;
    }
    if (((int_pointer)l & (~ (sizeof(sexpr) - 1))) != (int_pointer)l) return 0;
    if (!gc_initialise_memory ()) return 0;
    for (t = stack_start_address; t != l; t += step)
    {
        sexpr e = *t;
        if (((((int_pointer)(e)) & 0x1) == 0x0) && (e != (sexpr)0))
        {
            gc_tag (e);
        }
    }
    for (i = 0, k = (gc_pointer - gc_calls); i < k; i++)
    {
        sexpr sx = gc_calls[i];
        if (sx != (sexpr)0)
        {
            sx_destroy (sx);
            rv++;
        }
    }
    gc_deinitialise_memory ();
    optimise_static_memory_pools ();
    return rv;
}

canonical_original_code:
unsigned long gc_invoke()
{
    int step = (stack_growth == sg_down) ? -1 : 1;
    unsigned long end = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    unsigned long *t; unsigned long *l = &end;
    unsigned int i; unsigned int k;
    unsigned long rv = 0;
    if (((stack_growth == sg_down) && (stack_start_address < (void *)l)) ||
        ((stack_growth == sg_up) && (stack_start_address > (void *)l)))
    {
        return 0;
    }
    if (((unsigned long)l & (~ (sizeof(sexpr) - 1))) != (unsigned long)l) return 0;
    if (!gc_initialise_memory ()) return 0;
    for (t = stack_start_address; t != l; t += step)
    {
        unsigned long e = *t;
        if (((((int_pointer)(e)) & 0x1) == 0x0) && (e != (unsigned long)0))
        {
            gc_tag (e);
        }
    }
    for (i = 0, k = (gc_pointer - gc_calls); i < k; i++)
    {
        unsigned long sx = gc_calls[i];
        if (sx != (unsigned long)0)
        {
            sx_destroy (sx);
            rv++;
        }
    }
    gc_deinitialise_memory ();
    optimise_static_memory_pools ();
    return rv;
}

variable_types: step int

variable_types:
end
unsigned long

variable_types:
t
unsigned long *

variable_types:
l
unsigned long *

variable_types:
i
unsigned int

variable_types:
k
unsigned int

variable_types:
rv
unsigned long

variable_types:
e
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall sort_calls(int a1, int a2)
{
unsigned int v2; // ebp
int v3; // ebx

if ( a1 < a2 )
{
v2 = a1;
do
{
v3 = partition(v2, a2, v2);
sort_calls(v2, (unsigned int)(v3 - 1));
v2 = v3 + 1;
}
while ( a2 > v3 + 1 );
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2)
{
unsigned int v2; // ebp
int v3; // ebx

if ( a1 < a2 )
{
v2 = a1;
do
{
v3 = func0(v2, a2, v2);
func1(v2, (unsigned int)(v3 - 1));
v2 = v3 + 1;
}
while ( a2 > v3 + 1 );
}
}

original_code:
static void sort_calls (int left, int right)
{
    int pivot;
    while (right > left)
    {
        pivot = partition (left, right, left);
        sort_calls (left, pivot - 1);
        left = pivot + 1;
    }
}

canonical_original_code:
static void sort_calls(int left, int right)
{
    int pivot;
    while (right > left)
    {
        pivot = partition (left, right, left);
        sort_calls (left, pivot - 1);
        left = pivot + 1;
    }
}

variable_types: left int

variable_types: right int

variable_types: pivot int


original_code:
static enum signal_callback_result sig_chld_combined_handler
        (enum signal signal, void *e)
{
    int pid, q = 0;
    while ((pid = a_wait_all(&q)) > 0)
    {
        struct exec_cx *cx = elements;
        struct exec_cx **prev = &elements;
        while (cx != (struct exec_cx *)0)
        {
            if ((cx->context != (struct exec_context *)0) &&
                (cx->context->pid == pid) &&
                (cx->context->status == ps_running))
            {
                cx->context->exitstatus = q;
                cx->context->status = ps_terminated;
                cx->on_death (cx->context, cx->data);
                *prev = cx->next;
                free_pool_mem((void *)cx);
                break;
            }
            prev = &(cx->next);
            cx = cx->next;
        }
        cx = elements;
        while (cx != (struct exec_cx *)0)
        {
            if (cx->context == (struct exec_context *)0)
            {
                struct exec_context tcx;
                tcx.pid = pid;
                tcx.exitstatus = q;
                tcx.status = ps_terminated;
                cx->on_death (&tcx, cx->data);
            }
            cx = cx->next;
        }
    }
    return scr_keep;
}

canonical_original_code:
static enum signal_callback_result sig_chld_combined_handler(enum signal signal, void *e)
{
    int pid; int q = 0;
    while ((pid = a_wait_all(&q)) > 0)
    {
        struct exec_cx *cx = elements;
        struct exec_cx **prev = &elements;
        while (cx != (struct exec_cx *)0)
        {
            if ((cx->context != (struct exec_context *)0) &&
                (cx->context->pid == pid) &&
                (cx->context->status == ps_running))
            {
                cx->context->exitstatus = q;
                cx->context->status = ps_terminated;
                cx->on_death (cx->context, cx->data);
                *prev = cx->next;
                free_pool_mem((void *)cx);
                break;
            }
            prev = &(cx->next);
            cx = cx->next;
        }
        cx = elements;
        while (cx != (struct exec_cx *)0)
        {
            if (cx->context == (struct exec_context *)0)
            {
                struct exec_context tcx;
                tcx.pid = pid;
                tcx.exitstatus = q;
                tcx.status = ps_terminated;
                cx->on_death (&tcx, cx->data);
            }
            cx = cx->next;
        }
    }
    return scr_keep;
}

variable_types: enum signal { sig_unused=0, sig_hup=1, sig_int=2, sig_quit=3, sig_ill=4, sig_abrt=5, sig_fpe=6, sig_kill=7, sig_segv=8, sig_pipe=9, sig_alrm=10, sig_term=11, sig_chld=12, sig_cont=13, sig_stop=14, sig_tstp=15, sig_ttin=16, sig_ttou=17, sig_usr1=18, sig_usr2=19, sig_bus=20, sig_poll=21, sig_prof=22, sig_sys=23, sig_trap=24, sig_urg=25, sig_vtalrm=26, sig_xcpu=27, sig_xfsz=28, sig_iot=29, sig_emt=30, sig_stkflt=31, sig_io=32, sig_pwr=33, sig_info=34, sig_lost=35, sig_winch=36 }

variable_types:
e
void *

variable_types: pid int

variable_types: q int

variable_types: struct exec_cx { struct exec_context { int pid; int exitstatus; enum process_status { ps_running=0, ps_terminated=1 } status; struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *in; struct io *out; } *context; void (*on_death)(struct exec_context *, void *); void *data; struct exec_cx *next; } **

return_type: enum signal_callback_result { scr_keep=0, scr_ditch=1 }

user_defined_types: struct exec_context { int pid; int exitstatus; enum process_status status; struct io *in; struct io *out; }

user_defined_types: struct exec_cx { struct exec_context *context; void (*on_death)(struct exec_context *, void *); void *data; struct exec_cx *next; }

user_defined_types: struct io { int fd; char *buffer; enum io_type type; enum io_result status; unsigned int length; unsigned int position; unsigned int buffersize; }


decompiled_code:
__int64 __fastcall sig_chld_signal_handler(__int64 a1, _QWORD *a2)
{
if ( *(_DWORD *)(*a2 + 8LL) )
return 0LL;
check_exec_context();
if ( *(_DWORD *)(*a2 + 8LL) != 1 )
return 0LL;
((void (__fastcall *)(_QWORD, _QWORD))a2[1])(*a2, a2[2]);
free_pool_mem(a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
if ( *(_DWORD *)(*a2 + 8LL) )
return 0LL;
check_exec_context();
if ( *(_DWORD *)(*a2 + 8LL) != 1 )
return 0LL;
((void (__fastcall *)(_QWORD, _QWORD))a2[1])(*a2, a2[2]);
free_pool_mem(a2);
return 1LL;
}

original_code:
static enum signal_callback_result sig_chld_signal_handler
        (enum signal signal, void *e)
{
    struct exec_cx *cx = (struct exec_cx *)e;
    if (cx->context->status == ps_running) {
        check_exec_context (cx->context);
        if (cx->context->status == ps_terminated) {
            cx->on_death (cx->context, cx->data);
            free_pool_mem((void *)cx);
            return scr_ditch;
        }
    }
    return scr_keep;
}

canonical_original_code:
static enum signal_callback_result sig_chld_signal_handler(enum signal signal, void *e)
{
    struct exec_cx *cx = (struct exec_cx *)e;
    if (cx->context->status == ps_running) {
        check_exec_context (cx->context);
        if (cx->context->status == ps_terminated) {
            cx->on_death (cx->context, cx->data);
            free_pool_mem((void *)cx);
            return scr_ditch;
        }
    }
    return scr_keep;
}

variable_types: struct exec_cx { struct exec_context { int pid; int exitstatus; enum process_status { ps_running=0, ps_terminated=1 } status; struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *in; struct io *out; } *context; void (*on_death)(struct exec_context *, void *); void *data; struct exec_cx *next; } *

user_defined_types: enum signal { sig_unused=0, sig_hup=1, sig_int=2, sig_quit=3, sig_ill=4, sig_abrt=5, sig_fpe=6, sig_kill=7, sig_segv=8, sig_pipe=9, sig_alrm=10, sig_term=11, sig_chld=12, sig_cont=13, sig_stop=14, sig_tstp=15, sig_ttin=16, sig_ttou=17, sig_usr1=18, sig_usr2=19, sig_bus=20, sig_poll=21, sig_prof=22, sig_sys=23, sig_trap=24, sig_urg=25, sig_vtalrm=26, sig_xcpu=27, sig_xfsz=28, sig_iot=29, sig_emt=30, sig_stkflt=31, sig_io=32, sig_pwr=33, sig_info=34, sig_lost=35, sig_winch=36 }

user_defined_types: enum signal_callback_result { scr_keep=0, scr_ditch=1 }


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

if ( !multiplexer_installed )
{
result = multiplex_signal();
multiplexer_installed = 1;
}
return result;
}

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

if ( !multiplexer_installed )
{
result = multiplex_signal();
multiplexer_installed = 1;
}
return result;
}

original_code:
void multiplex_process () {
    if (multiplexer_installed == (char)0) {
        multiplex_signal();
        multiplexer_installed = (char)1;
    }
}

canonical_original_code:
void multiplex_process() {
    if (multiplexer_installed == (char)0) {
        multiplex_signal();
        multiplexer_installed = (char)1;
    }
}


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

if ( !multiplexer_installed )
{
multiplex_signal();
result = multiplex_add_signal(12LL, sig_chld_combined_handler, 0LL);
multiplexer_installed = 2;
}
return result;
}

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

if ( !multiplexer_installed )
{
multiplex_signal();
result = multiplex_add_signal(12LL, sig_chld_combined_handler, 0LL);
multiplexer_installed = 2;
}
return result;
}

original_code:
void multiplex_all_processes () {
    if (multiplexer_installed == (char)0) {
        multiplex_signal();
        multiplex_add_signal (sig_chld, sig_chld_combined_handler, (void *)0);
        multiplexer_installed = (char)2;
    }
}

canonical_original_code:
void multiplex_all_processes() {
    if (multiplexer_installed == (char)0) {
        multiplex_signal();
        multiplex_add_signal (sig_chld, sig_chld_combined_handler, (void *)0);
        multiplexer_installed = (char)2;
    }
}


decompiled_code:
__int64 __fastcall multiplex_add_process(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
bool v5; // zf
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rcx

v4 = (_QWORD *)get_pool_mem(&pool_0);
v5 = multiplexer_installed == 1;
*v4 = a1;
v6 = (__int64)v4;
v4[1] = a2;
v4[2] = a3;
v4[3] = 0LL;
if ( v5 )
return multiplex_add_signal(12LL, sig_chld_signal_handler, v4);
result = elements;
if ( elements )
{
do
{
v8 = result;
result = *(_QWORD *)(result + 24);
}
while ( result );
*(_QWORD *)(v8 + 24) = v6;
}
else
{
elements = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rax
bool v5; // zf
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rcx

v4 = (_QWORD *)get_pool_mem(&pool_0);
v5 = multiplexer_installed == 1;
*v4 = a1;
v6 = (__int64)v4;
v4[1] = a2;
v4[2] = a3;
v4[3] = 0LL;
if ( v5 )
return multiplex_add_signal(12LL, sig_chld_signal_handler, v4);
result = elements;
if ( elements )
{
do
{
v8 = result;
result = *(_QWORD *)(result + 24);
}
while ( result );
*(_QWORD *)(v8 + 24) = v6;
}
else
{
elements = v6;
}
return result;
}

original_code:
void multiplex_add_process (struct exec_context *context, void (*on_death)(struct exec_context *, void *), void *data) {
    static struct memory_pool pool
            = { mpft_static_header, ((((unsigned long)sizeof (struct exec_cx)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct exec_cx)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct exec_cx))) ? ((unsigned short)8) : 0)) };
    struct exec_cx *element = get_pool_mem (&pool);
    element->context = context;
    element->on_death = on_death;
    element->data = data;
    element->next = (struct exec_cx *)0;
    if (multiplexer_installed == (char)1)
    {
        multiplex_add_signal (sig_chld, sig_chld_signal_handler, (void *)element);
    }
    else
    {
        if (elements == (struct exec_cx *)0)
        {
            elements = element;
        }
        else
        {
            struct exec_cx *cx = elements;
            while ((cx->next) != (struct exec_cx *)0)
            {
                cx = cx->next;
            }
            cx->next = element;
        }
    }
}

canonical_original_code:
void multiplex_add_process(struct exec_context *context, void (*on_death)(struct exec_context *, void *), void *data) {
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct exec_cx)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct exec_cx)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct exec_cx))) ? ((unsigned short)8) : 0)) };
    struct exec_cx *element = get_pool_mem (&pool);
    element->context = context;
    element->on_death = on_death;
    element->data = data;
    element->next = (struct exec_cx *)0;
    if (multiplexer_installed == (char)1)
    {
        multiplex_add_signal (sig_chld, sig_chld_signal_handler, (void *)element);
    }
    else
    {
        if (elements == (struct exec_cx *)0)
        {
            elements = element;
        }
        else
        {
            struct exec_cx *cx = elements;
            while ((cx->next) != (struct exec_cx *)0)
            {
                cx = cx->next;
            }
            cx->next = element;
        }
    }
}

variable_types: struct exec_context { int pid; int exitstatus; enum process_status { ps_running=0, ps_terminated=1 } status; struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *in; struct io *out; } *

variable_types:
data
void *

variable_types: struct memory_pool { enum memory_pool_frame_type { mpft_static_header=0, mpft_frame=1 } type; unsigned int entitysize; }


decompiled_code:
unsigned __int64 __fastcall dt_from_unix(unsigned __int64 a1)
{
return a1 / 0x15180 + 1856305;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1)
{
return a1 / 0x15180 + 1856305;
}

original_code:
struct datetime dt_from_unix (unsigned long long timestamp)
{
    struct datetime date =
        { (12*144000 + 17*7200 + 16*360 + 7*20 + 5) + (timestamp / (24 * 60 * 60)),
          timestamp % (24 * 60 * 60) };
    return date;
}

canonical_original_code:
struct datetime dt_from_unix(unsigned long long timestamp)
{
    struct datetime date = { (12*144000 + 17*7200 + 16*360 + 7*20 + 5) + (timestamp / (24 * 60 * 60)),
          timestamp % (24 * 60 * 60) };
    return date;
}

variable_types:
timestamp
unsigned long long

variable_types: struct datetime { unsigned long long date; unsigned int time; }


decompiled_code:
__int64 __fastcall dt_to_unix(__int64 a1, unsigned int a2)
{
return a2 + 86400 * a1 - 0x2557AD1980LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
return a2 + 86400 * a1 - 0x2557AD1980LL;
}

original_code:
unsigned long long dt_to_unix (struct datetime date)
{
    return ((date.date - (12*144000 + 17*7200 + 16*360 + 7*20 + 5)) * (24 * 60 * 60)) + date.time;
}

canonical_original_code:
unsigned long long dt_to_unix(struct datetime date)
{
    return ((date.date - (12*144000 + 17*7200 + 16*360 + 7*20 + 5)) * (24 * 60 * 60)) + date.time;
}

return_type: unsigned long long

user_defined_types: struct datetime { unsigned long long date; unsigned int time; }


decompiled_code:
__int64 __fastcall on_regex_graph_free(__int64 a1)
{
return tree_remove_node_specific(&regex_cache, *(_QWORD *)(a1 + 16), 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return tree_remove_node_specific(&regex_cache, *(_QWORD *)(a1 + 16), 0LL);
}

original_code:
static void on_regex_graph_free (struct graph *g)
{
    tree_remove_node_specific(&regex_cache, (int_pointer)(g->aux), (struct tree_node *)0);
}

canonical_original_code:
static void on_regex_graph_free(struct graph *g)
{
    tree_remove_node_specific(&regex_cache, (int_pointer)(g->aux), (struct tree_node *)0);
}

variable_types: struct graph { unsigned int type; void (*on_free)(struct graph *); void *aux; unsigned int node_count; struct graph_node { unsigned long label; unsigned int edge_count; struct graph_edge { unsigned long label; struct graph_node *target; } **edges; } **nodes; } *

user_defined_types: struct graph { unsigned int type; void (*on_free)(struct graph *); void *aux; unsigned int node_count; struct graph_node **nodes; }

user_defined_types: struct graph_node { unsigned long label; unsigned int edge_count; struct graph_edge **edges; }


decompiled_code:
__int64 __fastcall rx_compile_add_nodes(__int64 a1, __int64 a2)
{
unsigned int v2; // er15
bool v3; // r13
char v4; // bl
unsigned int v5; // er14
__int64 result; // rax
unsigned int v7[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = utf8_get_character(a2, v2, v7);
result = v7[0];
if ( !v7[0] )
return result;
if ( v4 )
goto LABEL_10;
if ( v3 )
{
v3 = v7[0] != 93;
}
else
{
if ( v7[0] == 91 )
{
v3 = 1;
LABEL_10:
v4 = 0;
graph_add_node(a1, 8LL * v2 + 3);
goto LABEL_7;
}
if ( v7[0] <= 0x5B )
{
if ( v7[0] > 0x2B )
{
if ( v7[0] != 63 )
goto LABEL_10;
}
else if ( v7[0] <= 0x27 )
{
goto LABEL_10;
}
}
else
{
if ( v7[0] == 92 )
{
v4 = 1;
goto LABEL_7;
}
if ( v7[0] != 124 )
goto LABEL_10;
}
}
LABEL_7:
v2 = v5;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v2; // er15
bool v3; // r13
char v4; // bl
unsigned int v5; // er14
__int64 result; // rax
unsigned int v7[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v2 = 0;
v3 = 0;
v4 = 0;
while ( 1 )
{
v5 = utf8_get_character(a2, v2, v7);
result = v7[0];
if ( !v7[0] )
return result;
if ( v4 )
goto LABEL_10;
if ( v3 )
{
v3 = v7[0] != 93;
}
else
{
if ( v7[0] == 91 )
{
v3 = 1;
LABEL_10:
v4 = 0;
graph_add_node(a1, 8LL * v2 + 3);
goto LABEL_7;
}
if ( v7[0] <= 0x5B )
{
if ( v7[0] > 0x2B )
{
if ( v7[0] != 63 )
goto LABEL_10;
}
else if ( v7[0] <= 0x27 )
{
goto LABEL_10;
}
}
else
{
if ( v7[0] == 92 )
{
v4 = 1;
goto LABEL_7;
}
if ( v7[0] != 124 )
goto LABEL_10;
}
}
LABEL_7:
v2 = v5;
}
}

original_code:
static void rx_compile_add_nodes (sexpr g, const unsigned char *s)
{
    unsigned int p = 0, np;
    char quote = 0, cclass = 0;
    int_32 ra;
    while ((np = utf8_get_character (s, p, &ra)), (ra != 0))
    {
        if (quote)
        {
            quote = 0;
            goto add;
        }
        if (cclass)
        {
            if (ra == ']')
            {
                cclass = 0;
            }
            p = np;
            continue;
        }
        switch (ra)
        {
            case '\\':
                quote = 1;
                break;
            case '?':
            case '*':
            case '+':
            case '(':
            case ')':
            case '|':
                break;
            case '[':
                cclass = 1;
            default:
                add:
                graph_add_node (g, ((sexpr)((((int_pointer_s)(p)) << 3) | 0x3)));
                break;
        }
        p = np;
    }
}

canonical_original_code:
static void rx_compile_add_nodes(unsigned long g, unsigned char *s)
{
    unsigned int p = 0; unsigned int np;
    char quote = 0; char cclass = 0;
    unsigned int ra;
    while ((np = utf8_get_character (s, p, &ra)), (ra != 0))
    {
        if (quote)
        {
            quote = 0;
            goto add;
        }
        if (cclass)
        {
            if (ra == ']')
            {
                cclass = 0;
            }
            p = np;
            continue;
        }
        switch (ra)
        {
            case '\\':
                quote = 1;
                break;
            case '?':
            case '*':
            case '+':
            case '(':
            case ')':
            case '|':
                break;
            case '[':
                cclass = 1;
            default:
                add:
                graph_add_node (g, ((sexpr)((((int_pointer_s)(p)) << 3) | 0x3)));
                break;
        }
        p = np;
    }
}

variable_types:
g
unsigned long

variable_types:
s
unsigned char *

variable_types:
p
unsigned int

variable_types:
np
unsigned int

variable_types: quote char

variable_types: cclass char

variable_types:
ra
unsigned int


original_code:
static sexpr rx_match_nfa_state_progress
    (struct nfa_state *ns, struct nfa_state **r, const unsigned char *s)
{
    unsigned int p = ns->p, np;
    struct graph_node *n = ns->n;
    char haveedge = 0;
    int_32 ra;
    sexpr sx;
    unsigned int i;
    if (((sexpr)(n->label) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5)))) {
        return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
    }
    np = utf8_get_character (s, p, &ra);
    sx = ((sexpr)((((int_pointer_s)(ra)) << 3) | 0x3));
    for (i = 0; i < n->edge_count; i++)
    {
        struct graph_edge *e = n->edges[i];
        sexpr l = e->label;
        if (haveedge)
        {
            if (((sexpr)(l) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
            {
                rx_match_add_nfa_state (r, e->target, p);
            }
            else if (((ra != 0) && ((sexpr)(l) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5)))) || ((sexpr)(equalp(l, sx)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                struct graph_node *nt = e->target;
                rx_match_add_nfa_state (r, nt, p + ((ra == 0) ? 0 : 1));
            }
        }
        else
        {
            if (((sexpr)(l) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
            {
                ns->n = e->target;
                haveedge = 1;
            }
            else if (((ra != 0) && ((sexpr)(l) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5)))) || ((sexpr)(equalp(l, sx)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                ns->n = e->target;
                if (ra != 0) ns->p = np;
                haveedge = 1;
            }
        }
    }
    if (!haveedge)
    {
        return ((sexpr)((((int_pointer)(8)) << 3) | 0x5));
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
static unsigned long rx_match_nfa_state_progress(struct nfa_state *ns, struct nfa_state **r, unsigned char *s)
{
    unsigned int p = ns->p; unsigned int np;
    struct graph_node *n = ns->n;
    char haveedge = 0;
    unsigned int ra;
    unsigned long sx;
    unsigned int i;
    if (((sexpr)(n->label) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5)))) {
        return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
    }
    np = utf8_get_character (s, p, &ra);
    sx = ((sexpr)((((int_pointer_s)(ra)) << 3) | 0x3));
    for (i = 0; i < n->edge_count; i++)
    {
        struct graph_edge *e = n->edges[i];
        unsigned long l = e->label;
        if (haveedge)
        {
            if (((sexpr)(l) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
            {
                rx_match_add_nfa_state (r, e->target, p);
            }
            else if (((ra != 0) && ((sexpr)(l) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5)))) || ((sexpr)(equalp(l, sx)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                struct graph_node *nt = e->target;
                rx_match_add_nfa_state (r, nt, p + ((ra == 0) ? 0 : 1));
            }
        }
        else
        {
            if (((sexpr)(l) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
            {
                ns->n = e->target;
                haveedge = 1;
            }
            else if (((ra != 0) && ((sexpr)(l) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5)))) || ((sexpr)(equalp(l, sx)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                ns->n = e->target;
                if (ra != 0) ns->p = np;
                haveedge = 1;
            }
        }
    }
    if (!haveedge)
    {
        return ((sexpr)((((int_pointer)(8)) << 3) | 0x5));
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

variable_types: struct nfa_state { struct graph_node { unsigned long label; unsigned int edge_count; struct graph_edge { unsigned long label; struct graph_node *target; } **edges; } *n; unsigned int p; struct nfa_state *next; } *

variable_types:
r
struct nfa_state **

variable_types: haveedge char

variable_types:
sx
unsigned long

variable_types:
i
unsigned int

variable_types: struct graph_edge { unsigned long label; struct graph_node { unsigned long label; unsigned int edge_count; struct graph_edge **edges; } *target; } *

variable_types:
l
unsigned long

user_defined_types: struct nfa_state { struct graph_node *n; unsigned int p; struct nfa_state *next; }


decompiled_code:
__int64 __fastcall rx_match_recurse(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rbx
char v3; // dl
__int64 result; // rax

v2 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = 0;
do
{
if ( *v2 )
{
result = rx_match_nfa_state_progress((__int64)v2, a1, a2);
if ( result == 29 )
return result;
v3 = 1;
if ( result == 69 )
*v2 = 0LL;
}
v2 = (_QWORD *)v2[2];
}
while ( v2 );
v2 = (_QWORD *)*a1;
}
while ( *a1 && v3 );
}
return 21LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rbx
char v3; // dl
__int64 result; // rax

v2 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = 0;
do
{
if ( *v2 )
{
result = func4((__int64)v2, a1, a2);
if ( result == 29 )
return result;
v3 = 1;
if ( result == 69 )
*v2 = 0LL;
}
v2 = (_QWORD *)v2[2];
}
while ( v2 );
v2 = (_QWORD *)*a1;
}
while ( *a1 && v3 );
}
return 21LL;
}

original_code:
static sexpr rx_match_recurse
    (struct nfa_state **ns, const unsigned char *s)
{
    char had_nodes = (char)1;
    while (((*ns) != (struct nfa_state *)0) && (had_nodes == (char)1))
    {
        struct nfa_state *c = (*ns);
        had_nodes = (char)0;
        while (c != (struct nfa_state *)0)
        {
            if (c->n != (struct graph_node *)0)
            {
                sexpr sx = rx_match_nfa_state_progress (c, ns, s);
                had_nodes = (char)1;
                if (((sexpr)(sx) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
                {
                    return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
                }
                else if (((sexpr)(sx) == ((sexpr)((((int_pointer)(8)) << 3) | 0x5))))
                {
                    c->n = (struct graph_node *)0;
                }
            }
            c = c->next;
        }
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
static unsigned long rx_match_recurse(struct nfa_state **ns, unsigned char *s)
{
    char had_nodes = (char)1;
    while (((*ns) != (struct nfa_state *)0) && (had_nodes == (char)1))
    {
        struct nfa_state *c = (*ns);
        had_nodes = (char)0;
        while (c != (struct nfa_state *)0)
        {
            if (c->n != (struct graph_node *)0)
            {
                unsigned long sx = rx_match_nfa_state_progress (c, ns, s);
                had_nodes = (char)1;
                if (((sexpr)(sx) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
                {
                    return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
                }
                else if (((sexpr)(sx) == ((sexpr)((((int_pointer)(8)) << 3) | 0x5))))
                {
                    c->n = (struct graph_node *)0;
                }
            }
            c = c->next;
        }
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

variable_types: struct nfa_state { struct graph_node { unsigned long label; unsigned int edge_count; struct graph_edge { unsigned long label; struct graph_node *target; } **edges; } *n; unsigned int p; struct nfa_state *next; } **


decompiled_code:
__int64 __fastcall rx_compile_sx(int *a1)
{
int v1; // eax

if ( ((unsigned __int8)a1 & 1) != 0 )
return 69LL;
v1 = *a1;
if ( *a1 != 947 )
{
if ( v1 == 4 || v1 == 5 )
return rx_compile((__int64)(a1 + 1));
return 69LL;
}
return (__int64)a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
int v1; // eax

if ( ((unsigned __int8)a1 & 1) != 0 )
return 69LL;
v1 = *a1;
if ( *a1 != 947 )
{
if ( v1 == 4 || v1 == 5 )
return func6((__int64)(a1 + 1));
return 69LL;
}
return (__int64)a1;
}

original_code:
sexpr rx_compile_sx (sexpr sx)
{
    if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_partial *)((void *)sx))->type == 0x03b3)))
    {
        return sx;
    }
    else if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_string)))
    {
        return rx_compile ((const char *)((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)sx))->character_data) : "#nonexistent"));
    }
    else if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_symbol)))
    {
        return rx_compile ((const char *)((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_symbol)) ? (((struct sexpr_string_or_symbol *)((void *)sx))->character_data) : "#nonexistent"));
    }
    return ((sexpr)((((int_pointer)(8)) << 3) | 0x5));
}

canonical_original_code:
unsigned long rx_compile_sx(unsigned long sx)
{
    if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_partial *)((void *)sx))->type == 0x03b3)))
    {
        return sx;
    }
    else if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_string)))
    {
        return rx_compile ((char *)((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)sx))->character_data) : "#nonexistent"));
    }
    else if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_symbol)))
    {
        return rx_compile ((char *)((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_symbol)) ? (((struct sexpr_string_or_symbol *)((void *)sx))->character_data) : "#nonexistent"));
    }
    return ((sexpr)((((int_pointer)(8)) << 3) | 0x5));
}

user_defined_types: struct sexpr_partial { unsigned int type; }

user_defined_types: struct sexpr_string_or_symbol { enum sx_type type; char character_data[]; }

user_defined_types: enum sx_type { sxt_string=4, sxt_symbol=5, sxt_cons=6, sxt_rational=20 }


original_code:
sexpr rx_match (sexpr g, const char *s)
{
    if ((((((int_pointer)(g)) & 0x1) == 0x0) && (((struct sexpr_partial *)((void *)g))->type == 0x03b3)))
    {
        static struct memory_pool pool =
                { mpft_static_header, ((((unsigned long)sizeof(struct nfa_state)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof(struct nfa_state)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof(struct nfa_state))) ? ((unsigned short)8) : 0)) };
        sexpr rv = ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
        struct graph_node *n = graph_search_node (g, ((sexpr)((((int_pointer)(1)) << 3) | 0x5)));
        struct nfa_state *ns = get_pool_mem (&pool);
        if (n == (struct graph_node *)0)
        {
            return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
        }
        if (((sexpr)(n->label) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
        }
        ns->next = (struct nfa_state *)0;
        ns->n = n;
        ns->p = 0;
        rv = rx_match_recurse (&ns, (const unsigned char *)s);
        while (ns != (struct nfa_state *)0)
        {
            struct nfa_state *f = ns;
            ns = ns->next;
            free_pool_mem (f);
        }
        return rv;
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
unsigned long rx_match(unsigned long g, char *s)
{
    if ((((((int_pointer)(g)) & 0x1) == 0x0) && (((struct sexpr_partial *)((void *)g))->type == 0x03b3)))
    {
        static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof(struct nfa_state)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof(struct nfa_state)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof(struct nfa_state))) ? ((unsigned short)8) : 0)) };
        unsigned long rv = ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
        struct graph_node *n = graph_search_node (g, ((sexpr)((((int_pointer)(1)) << 3) | 0x5)));
        struct nfa_state *ns = get_pool_mem (&pool);
        if (n == (struct graph_node *)0)
        {
            return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
        }
        if (((sexpr)(n->label) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
        }
        ns->next = (struct nfa_state *)0;
        ns->n = n;
        ns->p = 0;
        rv = rx_match_recurse (&ns, (unsigned char *)s);
        while (ns != (struct nfa_state *)0)
        {
            struct nfa_state *f = ns;
            ns = ns->next;
            free_pool_mem (f);
        }
        return rv;
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

variable_types:
s
char *

variable_types: struct memory_pool { enum memory_pool_frame_type { mpft_static_header=0, mpft_frame=1 } type; unsigned int entitysize; }

variable_types:
rv
unsigned long

variable_types: struct graph_node { unsigned long label; unsigned int edge_count; struct graph_edge { unsigned long label; struct graph_node *target; } **edges; } *


decompiled_code:
__int64 __fastcall rx_match_sx(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

if ( ((unsigned __int8)a2 & 1) == 0 && (*a2 == 4 || *a2 == 5) )
result = rx_match(a1, (__int64)(a2 + 1));
else
result = 21LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

if ( ((unsigned __int8)a2 & 1) == 0 && (*a2 == 4 || *a2 == 5) )
result = func8(a1, (__int64)(a2 + 1));
else
result = 21LL;
return result;
}

original_code:
sexpr rx_match_sx (sexpr g, sexpr sx)
{
    if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_string)))
    {
        return rx_match (g, (const char *)((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)sx))->character_data) : "#nonexistent"));
    }
    else if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_symbol)))
    {
        return rx_match (g, (const char *)((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_symbol)) ? (((struct sexpr_string_or_symbol *)((void *)sx))->character_data) : "#nonexistent"));
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
unsigned long rx_match_sx(unsigned long g, unsigned long sx)
{
    if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_string)))
    {
        return rx_match (g, (char *)((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)sx))->character_data) : "#nonexistent"));
    }
    else if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_symbol)))
    {
        return rx_match (g, (char *)((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)sx))->type == sxt_symbol)) ? (((struct sexpr_string_or_symbol *)((void *)sx))->character_data) : "#nonexistent"));
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

variable_types:
g
unsigned long


cexit

decompiled_code:
// attributes: thunk
void __fastcall __noreturn cexit(int a1)
{
sys_exit_isra_0(a1);
JUMPOUT(0x25LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int a1)
{
func0(a1);
JUMPOUT(0x25LL);
}

original_code:
void cexit (int status)
{
    sys_exit (status);
    UNREACHABLE
}

canonical_original_code:
void cexit(int status)
{
    sys_exit (status);
    UNREACHABLE
}

variable_types: status int


decompiled_code:
// attributes: thunk
__int64 jump_cmain()
{
return cmain();
}

canonical_decompiled_code:
__int64 func2()
{
return cmain();
}

original_code:
int jump_cmain ( void )
{
    return cmain ();
}

canonical_original_code:
int jump_cmain()
{
    return cmain ();
}


immutable

decompiled_code:
__int64 __fastcall immutable(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
__int64 v4; // r13
__int64 v5; // rax
__int64 v6; // r12
_BYTE *v7; // rcx
__int64 v8; // r14
__int64 i; // rax
__int64 v10; // rax
__int64 v11; // rcx
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // [rsp+8h] [rbp-40h] BYREF
__int64 v15[6]; // [rsp+18h] [rbp-30h] BYREF

v14 = a1;
v2 = hash_murmur2_pt(&v14, 8LL, 0LL);
if ( tree_get_node(&immutable_data_tree, v2) )
return v14;
v4 = hash_murmur2_pt(v14, (unsigned int)a2, 0LL);
v5 = tree_get_node(&immutable_hashes, v4);
if ( v5 )
return node_get_value(v5);
v6 = immutable_data_space_left;
if ( a2 + 1 > immutable_data_space_left )
{
lock_immutable_pages();
if ( a2 > 0x2000 )
{
v6 = ((a2 >> 13) + ((a2 & 0x1FFF) != 0)) << 13;
v8 = v6 - 1;
}
else
{
v8 = 0x1FFFLL;
v6 = 0x2000LL;
}
if ( immutable_data )
lock_immutable_pages();
v13 = get_mem(v6);
immutable_data_space_left = v6;
immutable_data = v13;
v7 = (_BYTE *)v13;
immutable_cursor = v13;
immutable_data_size = v6;
}
else
{
v7 = (_BYTE *)immutable_cursor;
v8 = immutable_data_space_left - 1;
}
v15[0] = (__int64)v7;
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
v7[i] = *(_BYTE *)(a1 + i);
v7 += a2;
v8 = v6 - a2 - 1;
}
v10 = (__int64)(v7 + 1);
*v7 = 0;
immutable_cursor = (__int64)(v7 + 1);
immutable_data_space_left = v8;
if ( (((_BYTE)v7 + 1) & 7) != 0 )
{
v11 = (__int64)&v7[v8 + 1];
do
*(_BYTE *)v10++ = 0;
while ( (v10 & 7) != 0 );
immutable_cursor = v10;
immutable_data_space_left = v11 - v10;
}
tree_add_node_value(&immutable_hashes, v4, v15[0]);
v12 = hash_murmur2_pt(v15, 8LL, 0LL);
tree_add_node(&immutable_data_tree, v12);
return v15[0];
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // rax
__int64 v4; // r13
__int64 v5; // rax
__int64 v6; // r12
_BYTE *v7; // rcx
__int64 v8; // r14
__int64 i; // rax
__int64 v10; // rax
__int64 v11; // rcx
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // [rsp+8h] [rbp-40h] BYREF
__int64 v15[6]; // [rsp+18h] [rbp-30h] BYREF

v14 = a1;
v2 = hash_murmur2_pt(&v14, 8LL, 0LL);
if ( tree_get_node(&immutable_data_tree, v2) )
return v14;
v4 = hash_murmur2_pt(v14, (unsigned int)a2, 0LL);
v5 = tree_get_node(&immutable_hashes, v4);
if ( v5 )
return node_get_value(v5);
v6 = immutable_data_space_left;
if ( a2 + 1 > immutable_data_space_left )
{
func0();
if ( a2 > 0x2000 )
{
v6 = ((a2 >> 13) + ((a2 & 0x1FFF) != 0)) << 13;
v8 = v6 - 1;
}
else
{
v8 = 0x1FFFLL;
v6 = 0x2000LL;
}
if ( immutable_data )
func0();
v13 = get_mem(v6);
immutable_data_space_left = v6;
immutable_data = v13;
v7 = (_BYTE *)v13;
immutable_cursor = v13;
immutable_data_size = v6;
}
else
{
v7 = (_BYTE *)immutable_cursor;
v8 = immutable_data_space_left - 1;
}
v15[0] = (__int64)v7;
if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
v7[i] = *(_BYTE *)(a1 + i);
v7 += a2;
v8 = v6 - a2 - 1;
}
v10 = (__int64)(v7 + 1);
*v7 = 0;
immutable_cursor = (__int64)(v7 + 1);
immutable_data_space_left = v8;
if ( (((_BYTE)v7 + 1) & 7) != 0 )
{
v11 = (__int64)&v7[v8 + 1];
do
*(_BYTE *)v10++ = 0;
while ( (v10 & 7) != 0 );
immutable_cursor = v10;
immutable_data_space_left = v11 - v10;
}
tree_add_node_value(&immutable_hashes, v4, v15[0]);
v12 = hash_murmur2_pt(v15, 8LL, 0LL);
tree_add_node(&immutable_data_tree, v12);
return v15[0];
}

original_code:
const void *immutable (const void * data, unsigned long length)
{
    const char *rv;
    const char *data_char = (const char *)data;
    struct tree_node *n;
    int_pointer hash = hash_murmur2_pt (&data, sizeof (const void *), 0);
    if (tree_get_node (&immutable_data_tree, hash)
        != (struct tree_node *)0)
    {
        return data;
    }
    hash = hash_murmur2_pt (data, length, 0);
    if ((n = tree_get_node (&immutable_hashes, hash))
        != (struct tree_node *)0)
    {
        return (const void *)node_get_value (n);
    }
    if ((length + 1) > immutable_data_space_left) {
        unsigned long new_size = (4096*2);
        lock_immutable_pages();
        if (length > (4096*2)) {
            new_size = ((length / (4096*2)) +
                         (((length % (4096*2)) != 0) ? 1 : 0))
                       * (4096*2);
        }
        if (immutable_data != (void *)0)
        {
            lock_immutable_pages();
        }
        immutable_data = get_mem(new_size);
        immutable_data_space_left = new_size;
        immutable_cursor = immutable_data;
        immutable_data_size = new_size;
    }
    for (rv = immutable_cursor; length != 0;
         immutable_cursor++,
         data_char++,
         length--,
         immutable_data_space_left--)
    {
         *immutable_cursor = *data_char;
    }
    *immutable_cursor = 0;
    immutable_cursor++;
    immutable_data_space_left--;
    while ((((unsigned long)immutable_cursor) % sizeof(void *)) != 0)
    {
        *immutable_cursor = 0;
        immutable_cursor++;
        immutable_data_space_left--;
    }
    tree_add_node_value (&immutable_hashes, hash, (void *)rv);
    hash = hash_murmur2_pt (&rv, sizeof (const void *), 0);
    tree_add_node (&immutable_data_tree, hash);
    return rv;
}

canonical_original_code:
void *immutable(void *data, unsigned long length)
{
    char *rv;
    char *data_char = (const char *)data;
    struct tree_node *n;
    unsigned long hash = hash_murmur2_pt (&data, sizeof (const void *), 0);
    if (tree_get_node (&immutable_data_tree, hash)
        != (struct tree_node *)0)
    {
        return data;
    }
    hash = hash_murmur2_pt (data, length, 0);
    if ((n = tree_get_node (&immutable_hashes, hash))
        != (struct tree_node *)0)
    {
        return (void *)node_get_value (n);
    }
    if ((length + 1) > immutable_data_space_left) {
        unsigned long new_size = (4096*2);
        lock_immutable_pages();
        if (length > (4096*2)) {
            new_size = ((length / (4096*2)) +
                         (((length % (4096*2)) != 0) ? 1 : 0))
                       * (4096*2);
        }
        if (immutable_data != (void *)0)
        {
            lock_immutable_pages();
        }
        immutable_data = get_mem(new_size);
        immutable_data_space_left = new_size;
        immutable_cursor = immutable_data;
        immutable_data_size = new_size;
    }
    for (rv = immutable_cursor; length != 0;
         immutable_cursor++,
         data_char++,
         length--,
         immutable_data_space_left--)
    {
         *immutable_cursor = *data_char;
    }
    *immutable_cursor = 0;
    immutable_cursor++;
    immutable_data_space_left--;
    while ((((unsigned long)immutable_cursor) % sizeof(void *)) != 0)
    {
        *immutable_cursor = 0;
        immutable_cursor++;
        immutable_data_space_left--;
    }
    tree_add_node_value (&immutable_hashes, hash, (void *)rv);
    hash = hash_murmur2_pt (&rv, sizeof (void *), 0);
    tree_add_node (&immutable_data_tree, hash);
    return rv;
}

variable_types:
data
void *

variable_types:
length
unsigned long

variable_types:
rv
char *

variable_types: struct tree_node { unsigned long key; } *

variable_types:
hash
unsigned long

return_type: void *


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

if ( immutable_data_size )
result = mark_mem_ro(immutable_data_size, immutable_data);
immutable_data_size = 0LL;
immutable_data_space_left = 0LL;
return result;
}

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

if ( immutable_data_size )
result = mark_mem_ro(immutable_data_size, immutable_data);
immutable_data_size = 0LL;
immutable_data_space_left = 0LL;
return result;
}

original_code:
void lock_immutable_pages ( void )
{
    if (immutable_data_size != 0) {
        mark_mem_ro (immutable_data_size, immutable_data);
    }
    immutable_data_size = 0;
    immutable_data_space_left = 0;
}

canonical_original_code:
void lock_immutable_pages()
{
    if (immutable_data_size != 0) {
        mark_mem_ro (immutable_data_size, immutable_data);
    }
    immutable_data_size = 0;
    immutable_data_space_left = 0;
}


decompiled_code:
void *__fastcall str_immutable(_BYTE *a1)
{
unsigned __int64 v1; // rsi

if ( !*a1 )
return &LC0;
v1 = 0LL;
do
++v1;
while ( a1[v1] );
return (void *)immutable((__int64)a1, v1);
}

canonical_decompiled_code:
void *__fastcall func2(_BYTE *a1)
{
unsigned __int64 v1; // rsi

if ( !*a1 )
return &LC0;
v1 = 0LL;
do
++v1;
while ( a1[v1] );
return (void *)func1((__int64)a1, v1);
}

original_code:
const char *str_immutable (const char * string)
{
    unsigned long stringlength = 0;
    if (string[0] == (char)0) return (const char *)"";
    while (string[stringlength] != 0)
    {
        stringlength++;
    }
    return (const char *)immutable (string, stringlength);
}

canonical_original_code:
char *str_immutable(char *string)
{
    unsigned long stringlength = 0;
    if (string[0] == (char)0) return (char *)"";
    while (string[stringlength] != 0)
    {
        stringlength++;
    }
    return (char *)immutable (string, stringlength);
}

variable_types:
string
char *

variable_types:
stringlength
unsigned long

return_type: char *


decompiled_code:
__int64 __fastcall make_string_or_symbol_lh(__int64 a1, char a2, __int64 a3, unsigned __int64 a4)
{
void *v5; // r14
__int64 v7; // rax
_DWORD *v9; // r12
unsigned int v10; // edx
__int64 v11; // rcx
__int64 v12; // rax

v5 = &sx_symbol_tree;
if ( a2 != 1 )
v5 = &sx_string_tree;
v7 = tree_get_node(v5, a3);
if ( v7 )
return node_get_value(v7);
v9 = (_DWORD *)aalloc(a4 + 5);
tree_add_node_value(v5, a3, v9);
if ( a4 )
{
v10 = 0;
v11 = 0LL;
v12 = 0LL;
do
{
*((_BYTE *)v9 + v12 + 4) = *(_BYTE *)(a1 + v11);
v12 = ++v10;
v11 = v10;
}
while ( v10 < a4 );
}
else
{
v12 = 0LL;
}
*((_BYTE *)v9 + v12 + 4) = 0;
*v9 = (a2 == 1) + 4;
++gc_base_items;
return (__int64)v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, __int64 a3, unsigned __int64 a4)
{
void *v5; // r14
__int64 v7; // rax
_DWORD *v9; // r12
unsigned int v10; // edx
__int64 v11; // rcx
__int64 v12; // rax

v5 = &sx_symbol_tree;
if ( a2 != 1 )
v5 = &sx_string_tree;
v7 = tree_get_node(v5, a3);
if ( v7 )
return node_get_value(v7);
v9 = (_DWORD *)aalloc(a4 + 5);
tree_add_node_value(v5, a3, v9);
if ( a4 )
{
v10 = 0;
v11 = 0LL;
v12 = 0LL;
do
{
*((_BYTE *)v9 + v12 + 4) = *(_BYTE *)(a1 + v11);
v12 = ++v10;
v11 = v10;
}
while ( v10 < a4 );
}
else
{
v12 = 0LL;
}
*((_BYTE *)v9 + v12 + 4) = 0;
*v9 = (a2 == 1) + 4;
++gc_base_items;
return (__int64)v9;
}

original_code:
static sexpr make_string_or_symbol_lh
    (const char *string, char symbol, int_pointer hash, unsigned long len)
{
    struct sexpr_string_or_symbol *s;
    unsigned int i;
    struct tree_node *n;
    if ((n = tree_get_node ((symbol == (char)1) ? &sx_symbol_tree
                                                : &sx_string_tree,
                            (int_pointer)hash)))
    {
        return (sexpr)node_get_value (n);
    }
    s = aalloc (sizeof (struct sexpr_string_or_symbol) + len + 1);
    tree_add_node_value ((symbol == (char)1) ? &sx_symbol_tree
                                             : &sx_string_tree,
                         (int_pointer)hash, s);
    for (i = 0; i < len; i++)
    {
        s->character_data[i] = string[i];
    }
    s->character_data[i] = (char)0;
    s->type = (symbol == (char)1) ? sxt_symbol : sxt_string;
    gc_base_items++;
    return (sexpr)s;
}

canonical_original_code:
static unsigned long make_string_or_symbol_lh(char *string, char symbol, unsigned long hash, unsigned long len)
{
    struct sexpr_string_or_symbol *s;
    unsigned int i;
    struct tree_node *n;
    if ((n = tree_get_node ((symbol == (char)1) ? &sx_symbol_tree
                                                : &sx_string_tree,
                            (unsigned long)hash)))
    {
        return (unsigned long)node_get_value (n);
    }
    s = aalloc (sizeof (struct sexpr_string_or_symbol) + len + 1);
    tree_add_node_value ((symbol == (char)1) ? &sx_symbol_tree
                                             : &sx_string_tree,
                         (unsigned long)hash, s);
    for (i = 0; i < len; i++)
    {
        s->character_data[i] = string[i];
    }
    s->character_data[i] = (char)0;
    s->type = (symbol == (char)1) ? sxt_symbol : sxt_string;
    gc_base_items++;
    return (unsigned long)s;
}

variable_types: symbol char

variable_types:
len
unsigned long

variable_types: struct sexpr_string_or_symbol { enum sx_type { sxt_string=4, sxt_symbol=5, sxt_cons=6, sxt_rational=20 } type; char character_data[]; } *

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall make_string_or_symbol(__int64 a1, char a2)
{
__int64 v2; // rax
unsigned __int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = str_hash(a1, v4);
return make_string_or_symbol_lh(a1, a2, v2, v4[0]);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char a2)
{
__int64 v2; // rax
unsigned __int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = str_hash(a1, v4);
return func0(a1, a2, v2, v4[0]);
}

original_code:
static sexpr make_string_or_symbol
    (const char *string, char symbol)
{
    unsigned long len;
    int_pointer hash = str_hash (string, &len);
    return make_string_or_symbol_lh (string, symbol, hash, len);
}

canonical_original_code:
static unsigned long make_string_or_symbol(char *string, char symbol)
{
    unsigned long len;
    unsigned long hash = str_hash (string, &len);
    return make_string_or_symbol_lh (string, symbol, hash, len);
}


decompiled_code:
__int64 __fastcall make_string_or_symbol_l(__int64 a1, char a2, unsigned __int64 a3)
{
__int64 v4; // rax

v4 = hash_murmur2_pt(a1, (unsigned int)a3, 0LL);
return make_string_or_symbol_lh(a1, a2, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2, unsigned __int64 a3)
{
__int64 v4; // rax

v4 = hash_murmur2_pt(a1, (unsigned int)a3, 0LL);
return func0(a1, a2, v4, a3);
}

original_code:
static sexpr make_string_or_symbol_l
    (const char *string, char symbol, unsigned long len)
{
    int_pointer hash = hash_murmur2_pt (string, len, 0);
    return make_string_or_symbol_lh (string, symbol, hash, len);
}

canonical_original_code:
static unsigned long make_string_or_symbol_l(char *string, char symbol, unsigned long len)
{
    unsigned long hash = hash_murmur2_pt (string, len, 0);
    return make_string_or_symbol_lh (string, symbol, hash, len);
}


decompiled_code:
__int64 __fastcall sx_map_call(__int64 a1)
{
__int64 v1; // rax

v1 = node_get_value(a1);
return gc_call(v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rax

v1 = node_get_value(a1);
return gc_call(v1);
}

original_code:
static void sx_map_call (struct tree_node *node, void *u)
{
    sexpr sx = (sexpr)node_get_value(node);
    gc_call (sx);
}

canonical_original_code:
static void sx_map_call(struct tree_node *node, void *u)
{
    unsigned long sx = (sexpr)node_get_value(node);
    gc_call (sx);
}

variable_types:
u
void *

variable_types:
sx
unsigned long


cons

decompiled_code:
__int64 __fastcall cons(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rax
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7[7]; // [rsp+0h] [rbp-38h] BYREF

v7[0] = a1;
v7[1] = a2;
v2 = hash_murmur2_pt(v7, 16LL, 0LL);
v3 = tree_get_node(&sx_cons_tree, v2);
if ( v3 )
return node_get_value(v3);
v5 = get_pool_mem(&pool_1);
*(_QWORD *)(v5 + 8) = a1;
v6 = v5;
*(_QWORD *)(v5 + 16) = a2;
*(_DWORD *)v5 = 6;
tree_add_node_value(&sx_cons_tree, v2, v5);
++gc_base_items;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rax
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7[7]; // [rsp+0h] [rbp-38h] BYREF

v7[0] = a1;
v7[1] = a2;
v2 = hash_murmur2_pt(v7, 16LL, 0LL);
v3 = tree_get_node(&sx_cons_tree, v2);
if ( v3 )
return node_get_value(v3);
v5 = get_pool_mem(&pool_1);
*(_QWORD *)(v5 + 8) = a1;
v6 = v5;
*(_QWORD *)(v5 + 16) = a2;
*(_DWORD *)v5 = 6;
tree_add_node_value(&sx_cons_tree, v2, v5);
++gc_base_items;
return v6;
}

original_code:
sexpr cons(sexpr sx_car, sexpr sx_cdr)
{
    static struct memory_pool pool =
            { mpft_static_header, ((((unsigned long)sizeof (struct sexpr_cons)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct sexpr_cons)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct sexpr_cons))) ? ((unsigned short)8) : 0)) };
    struct sexpr_cons *rv;
    struct tree_node *n;
    sexpr t[2];
    int_pointer hash;
    t[0] = sx_car;
    t[1] = sx_cdr;
    hash = hash_murmur2_pt (t, sizeof(t), 0);
    if ((n = tree_get_node (&sx_cons_tree, (int_pointer)hash)))
    {
        return (sexpr)node_get_value (n);
    }
    rv = get_pool_mem (&pool);
    rv->type = sxt_cons;
    rv->car = sx_car;
    rv->cdr = sx_cdr;
    tree_add_node_value (&sx_cons_tree, hash, (void *)rv);
    gc_base_items++;
    return (sexpr)rv;
}

canonical_original_code:
unsigned long cons(unsigned long sx_car, unsigned long sx_cdr)
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct sexpr_cons)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct sexpr_cons)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct sexpr_cons))) ? ((unsigned short)8) : 0)) };
    struct sexpr_cons *rv;
    struct tree_node *n;
    unsigned long t[2];
    unsigned long hash;
    t[0] = sx_car;
    t[1] = sx_cdr;
    hash = hash_murmur2_pt (t, sizeof(t), 0);
    if ((n = tree_get_node (&sx_cons_tree, (unsigned long)hash)))
    {
        return (unsigned long)node_get_value (n);
    }
    rv = get_pool_mem (&pool);
    rv->type = sxt_cons;
    rv->car = sx_car;
    rv->cdr = sx_cdr;
    tree_add_node_value (&sx_cons_tree, hash, (void *)rv);
    gc_base_items++;
    return (unsigned long)rv;
}

variable_types: struct memory_pool { enum memory_pool_frame_type { mpft_static_header=0, mpft_frame=1 } type; unsigned int entitysize; }

variable_types: struct sexpr_cons { enum sx_type { sxt_string=4, sxt_symbol=5, sxt_cons=6, sxt_rational=20 } type; unsigned long car; unsigned long cdr; } *

variable_types:
t
unsigned long [2]

user_defined_types: struct sexpr_cons { enum sx_type type; unsigned long car; unsigned long cdr; }


decompiled_code:
__int64 __fastcall make_rational(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // r13
__int64 v7; // rdi
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = gcd(a1, abs64(a2));
v3 = a1 / v2;
v4 = a2 / v2;
if ( v4 == 1 )
return 8 * v3 + 3;
v5 = v4;
if ( v4 == -1 )
{
v3 = -v3;
return 8 * v3 + 3;
}
v11[0] = v3;
v11[1] = v4;
v6 = hash_murmur2_pt(v11, 16LL, 0LL);
v7 = tree_get_node(&sx_rational_tree, v6);
if ( v7 )
return node_get_value(v7);
v9 = get_pool_mem(&pool_0);
*(_QWORD *)(v9 + 8) = v3;
v10 = v9;
*(_QWORD *)(v9 + 16) = v5;
*(_DWORD *)v9 = 20;
tree_add_node_value(&sx_rational_tree, v6, v9);
++gc_base_items;
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // r13
__int64 v7; // rdi
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = gcd(a1, abs64(a2));
v3 = a1 / v2;
v4 = a2 / v2;
if ( v4 == 1 )
return 8 * v3 + 3;
v5 = v4;
if ( v4 == -1 )
{
v3 = -v3;
return 8 * v3 + 3;
}
v11[0] = v3;
v11[1] = v4;
v6 = hash_murmur2_pt(v11, 16LL, 0LL);
v7 = tree_get_node(&sx_rational_tree, v6);
if ( v7 )
return node_get_value(v7);
v9 = get_pool_mem(&pool_0);
*(_QWORD *)(v9 + 8) = v3;
v10 = v9;
*(_QWORD *)(v9 + 16) = v5;
*(_DWORD *)v9 = 20;
tree_add_node_value(&sx_rational_tree, v6, v9);
++gc_base_items;
return v10;
}

original_code:
sexpr make_rational(int_pointer p, int_pointer_s q)
{
    static struct memory_pool pool =
            { mpft_static_header, ((((unsigned long)sizeof (struct sexpr_rational)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct sexpr_rational)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct sexpr_rational))) ? ((unsigned short)8) : 0)) };
    struct sexpr_rational *rv;
    struct tree_node *n;
    int_64 g = gcd (p, q >= 0 ? q : (q * -1));
    int_pointer t[2], hash;
    p /= g;
    q /= g;
    if (q == 1)
    {
        return ((sexpr)((((int_pointer_s)(p)) << 3) | 0x3));
    }
    else if (q == -1)
    {
        return ((sexpr)((((int_pointer_s)(p * -1)) << 3) | 0x3));
    }
    t[0] = p;
    t[1] = q;
    hash = hash_murmur2_pt (t, sizeof(t), 0);
    if ((n = tree_get_node (&sx_rational_tree, (int_pointer)hash)))
    {
        return (sexpr)node_get_value (n);
    }
    rv = get_pool_mem (&pool);
    rv->type = sxt_rational;
    rv->numerator = p;
    rv->denominator = q;
    tree_add_node_value (&sx_rational_tree, hash, (void *)rv);
    gc_base_items++;
    return (sexpr)rv;
}

canonical_original_code:
unsigned long make_rational(unsigned long p, long q)
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct sexpr_rational)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct sexpr_rational)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct sexpr_rational))) ? ((unsigned short)8) : 0)) };
    struct sexpr_rational *rv;
    struct tree_node *n;
    unsigned long long g = gcd (p, q >= 0 ? q : (q * -1));
    unsigned long t[2]; unsigned long hash;
    p /= g;
    q /= g;
    if (q == 1)
    {
        return ((sexpr)((((int_pointer_s)(p)) << 3) | 0x3));
    }
    else if (q == -1)
    {
        return ((sexpr)((((int_pointer_s)(p * -1)) << 3) | 0x3));
    }
    t[0] = p;
    t[1] = q;
    hash = hash_murmur2_pt (t, sizeof(t), 0);
    if ((n = tree_get_node (&sx_rational_tree, (unsigned long)hash)))
    {
        return (unsigned long)node_get_value (n);
    }
    rv = get_pool_mem (&pool);
    rv->type = sxt_rational;
    rv->numerator = p;
    rv->denominator = q;
    tree_add_node_value (&sx_rational_tree, hash, (void *)rv);
    gc_base_items++;
    return (unsigned long)rv;
}

variable_types:
p
unsigned long

variable_types: q long

variable_types: struct sexpr_rational { enum sx_type { sxt_string=4, sxt_symbol=5, sxt_cons=6, sxt_rational=20 } type; unsigned long numerator; long denominator; } *

variable_types:
g
unsigned long long

user_defined_types: enum memory_pool_frame_type { mpft_static_header=0, mpft_frame=1 }

user_defined_types: struct sexpr_rational { enum sx_type type; unsigned long numerator; long denominator; }


decompiled_code:
__int64 __fastcall make_string(__int64 a1)
{
return make_string_or_symbol(a1, 0);
}

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

original_code:
sexpr make_string
    (const char *string)
{
    return make_string_or_symbol (string, (char)0);
}

canonical_original_code:
unsigned long make_string(char *string)
{
    return make_string_or_symbol (string, (char)0);
}


variable_types: i long

variable_types:
num
char [33]

variable_types: neg int

variable_types:
j
unsigned int

variable_types: s char


decompiled_code:
__int64 __fastcall make_symbol(__int64 a1)
{
return make_string_or_symbol(a1, 1);
}

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

original_code:
sexpr make_symbol
    (const char *symbol)
{
    return make_string_or_symbol (symbol, (char)1);
}

canonical_original_code:
unsigned long make_symbol(char *symbol)
{
    return make_string_or_symbol (symbol, (char)1);
}

variable_types:
symbol
char *


decompiled_code:
__int64 __fastcall make_string_l(__int64 a1, unsigned __int64 a2)
{
return make_string_or_symbol_l(a1, 0, a2);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int64 a2)
{
return func2(a1, 0, a2);
}

original_code:
sexpr make_string_l
        (const char *string, unsigned long length)
{
    return make_string_or_symbol_l (string, (char)0, length);
}

canonical_original_code:
unsigned long make_string_l(char *string, unsigned long length)
{
    return make_string_or_symbol_l (string, (char)0, length);
}

variable_types:
string
char *

variable_types:
length
unsigned long


decompiled_code:
__int64 __fastcall make_symbol_l(__int64 a1, unsigned __int64 a2)
{
return make_string_or_symbol_l(a1, 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int64 a2)
{
return func2(a1, 1, a2);
}

original_code:
sexpr make_symbol_l
        (const char *symbol, unsigned long length)
{
    return make_string_or_symbol_l (symbol, (char)1, length);
}

canonical_original_code:
unsigned long make_symbol_l(char *symbol, unsigned long length)
{
    return make_string_or_symbol_l (symbol, (char)1, length);
}


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

result = a1;
if ( (a1 & 7) == 3 )
result = sx_integer_to_string(a1 >> 3);
return result;
}

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

result = a1;
if ( (a1 & 7) == 3 )
result = func7(a1 >> 3);
return result;
}

original_code:
sexpr sx_to_string (sexpr a)
{
    if (((((int_pointer)(a)) & 0x7) == 0x3))
    {
        return sx_integer_to_string (((int_pointer_s)(a & (~0x7)) >> 3));
    }
    return a;
}

canonical_original_code:
unsigned long sx_to_string(unsigned long a)
{
    if (((((int_pointer)(a)) & 0x7) == 0x3))
    {
        return sx_integer_to_string (((int_pointer_s)(a & (~0x7)) >> 3));
    }
    return a;
}

variable_types:
a
unsigned long


decompiled_code:
__int64 sx_call_all()
{
tree_map(&sx_cons_tree, sx_map_call, 0LL);
tree_map(&sx_string_tree, sx_map_call, 0LL);
tree_map(&sx_symbol_tree, sx_map_call, 0LL);
return tree_map(&sx_rational_tree, sx_map_call, 0LL);
}

canonical_decompiled_code:
__int64 func12()
{
tree_map(&sx_cons_tree, sx_map_call, 0LL);
tree_map(&sx_string_tree, sx_map_call, 0LL);
tree_map(&sx_symbol_tree, sx_map_call, 0LL);
return tree_map(&sx_rational_tree, sx_map_call, 0LL);
}

original_code:
void sx_call_all ( void )
{
    tree_map (&sx_cons_tree, sx_map_call, (void *)0);
    tree_map (&sx_string_tree, sx_map_call, (void *)0);
    tree_map (&sx_symbol_tree, sx_map_call, (void *)0);
    tree_map (&sx_rational_tree, sx_map_call, (void *)0);
}

canonical_original_code:
void sx_call_all()
{
    tree_map (&sx_cons_tree, sx_map_call, (void *)0);
    tree_map (&sx_string_tree, sx_map_call, (void *)0);
    tree_map (&sx_symbol_tree, sx_map_call, (void *)0);
    tree_map (&sx_rational_tree, sx_map_call, (void *)0);
}


decompiled_code:
__int64 __fastcall relocate_buffer_contents(__int64 a1)
{
unsigned int v1; // ecx
__int64 result; // rax
__int64 v3; // rdx
char v4; // si
__int64 v5; // rcx

v1 = *(_DWORD *)(a1 + 28);
result = *(unsigned int *)(a1 + 24);
if ( v1 < (unsigned int)result )
{
*(_DWORD *)(a1 + 24) = result - v1;
LODWORD(result) = 0;
while ( 1 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = *(_BYTE *)(v3 + (unsigned int)result + v1);
v5 = (unsigned int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(v3 + v5) = v4;
if ( *(_DWORD *)(a1 + 24) <= (unsigned int)result )
break;
v1 = *(_DWORD *)(a1 + 28);
}
*(_DWORD *)(a1 + 28) = 0;
}
else
{
*(_QWORD *)(a1 + 24) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ecx
__int64 result; // rax
__int64 v3; // rdx
char v4; // si
__int64 v5; // rcx

v1 = *(_DWORD *)(a1 + 28);
result = *(unsigned int *)(a1 + 24);
if ( v1 < (unsigned int)result )
{
*(_DWORD *)(a1 + 24) = result - v1;
LODWORD(result) = 0;
while ( 1 )
{
v3 = *(_QWORD *)(a1 + 8);
v4 = *(_BYTE *)(v3 + (unsigned int)result + v1);
v5 = (unsigned int)result;
result = (unsigned int)(result + 1);
*(_BYTE *)(v3 + v5) = v4;
if ( *(_DWORD *)(a1 + 24) <= (unsigned int)result )
break;
v1 = *(_DWORD *)(a1 + 28);
}
*(_DWORD *)(a1 + 28) = 0;
}
else
{
*(_QWORD *)(a1 + 24) = 0LL;
}
return result;
}

original_code:
static void relocate_buffer_contents (struct io *io)
{
    if (io->position >= io->length) {
        io->length = 0;
        io->position = 0;
    } else {
        unsigned int i;
        io->length -= io->position;
        for (i = 0; i < io->length; i++) {
            io->buffer[i] = io->buffer[(io->position + i)];
        }
        io->position = 0;
    }
}

canonical_original_code:
static void relocate_buffer_contents(struct io *io)
{
    if (io->position >= io->length) {
        io->length = 0;
        io->position = 0;
    } else {
        unsigned int i;
        io->length -= io->position;
        for (i = 0; i < io->length; i++) {
            io->buffer[i] = io->buffer[(io->position + i)];
        }
        io->position = 0;
    }
}

variable_types: struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *

variable_types:
i
unsigned int


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

result = io_create();
*(_DWORD *)result = -1;
*(_QWORD *)(result + 16) = 4LL;
*(_QWORD *)(result + 24) = 0LL;
return result;
}

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

result = io_create();
*(_DWORD *)result = -1;
*(_QWORD *)(result + 16) = 4LL;
*(_QWORD *)(result + 24) = 0LL;
return result;
}

original_code:
struct io *io_open_special ()
{
    struct io *io = io_create();
    io->fd = -1;
    io->status = io_undefined;
    io->length = 0;
    io->position = 0;
    io->type = iot_special_write;
    return io;
}

canonical_original_code:
struct io *io_open_special()
{
    struct io *io = io_create();
    io->fd = -1;
    io->status = io_undefined;
    io->length = 0;
    io->position = 0;
    io->type = iot_special_write;
    return io;
}

return_type: struct io { int fd; char *buffer; enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 } type; enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 } status; unsigned int length; unsigned int position; unsigned int buffersize; } *


decompiled_code:
unsigned int *__fastcall io_open(unsigned int a1)
{
unsigned int *v1; // r12
unsigned int *result; // rax

v1 = (unsigned int *)io_create();
a_make_nonblocking(a1);
*v1 = a1;
result = v1;
v1[4] = 0;
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func2(unsigned int a1)
{
unsigned int *v1; // r12
unsigned int *result; // rax

v1 = (unsigned int *)io_create();
a_make_nonblocking(a1);
*v1 = a1;
result = v1;
v1[4] = 0;
return result;
}

original_code:
struct io *io_open (int fd)
{
    struct io *io = io_create();
    (void)a_make_nonblocking (fd);
    io->fd = fd;
    io->type = iot_undefined;
    return io;
}

canonical_original_code:
struct io *io_open(int fd)
{
    struct io *io = io_create();
    (void)a_make_nonblocking (fd);
    io->fd = fd;
    io->type = iot_undefined;
    return io;
}

variable_types: fd int

user_defined_types: enum io_type { iot_undefined=0, iot_read=1, iot_write=2, iot_special_read=3, iot_special_write=4, iot_buffer=5 }

user_defined_types: enum io_result { io_undefined=0, io_end_of_file=1, io_changes=2, io_unrecoverable_error=3, io_no_change=4, io_complete=5, io_incomplete=6, io_finalising=7 }


decompiled_code:
unsigned int *io_open_read()
{
unsigned int v0; // eax
unsigned int *result; // rax

v0 = a_open_read();
result = io_open(v0);
result[4] = 1;
return result;
}

canonical_decompiled_code:
unsigned int *func3()
{
unsigned int v0; // eax
unsigned int *result; // rax

v0 = a_open_read();
result = func2(v0);
result[4] = 1;
return result;
}

original_code:
struct io *io_open_read (const char *path)
{
    int fd = a_open_read (path);
    struct io *io = io_open(fd);
    io->type = iot_read;
    return io;
}

canonical_original_code:
struct io *io_open_read(char *path)
{
    int fd = a_open_read (path);
    struct io *io = io_open(fd);
    io->type = iot_read;
    return io;
}

variable_types:
path
char *