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


repo: kyuba/curie

decompiled_code:
__int64 __fastcall sig_chld_signal_handler(__int64 a1, _QWORD *a2)
{
unsigned int v2; // ebp

v2 = *(_DWORD *)(*a2 + 8LL);
if ( v2 )
return 0;
check_exec_context();
if ( *(_DWORD *)(*a2 + 8LL) == 1 )
{
((void (__fastcall *)(_QWORD, _QWORD))a2[1])(*a2, a2[2]);
free_pool_mem(a2);
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
unsigned int v2; // ebp

v2 = *(_DWORD *)(*a2 + 8LL);
if ( v2 )
return 0;
check_exec_context();
if ( *(_DWORD *)(*a2 + 8LL) == 1 )
{
((void (__fastcall *)(_QWORD, _QWORD))a2[1])(*a2, a2[2]);
free_pool_mem(a2);
v2 = 1;
}
return v2;
}

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 }

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

return_type: void


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; // rdx
__int64 result; // rax
__int64 v6; // rcx

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

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

v4 = (_QWORD *)get_pool_mem(&pool_0);
*v4 = a1;
v4[1] = a2;
v4[2] = a3;
v4[3] = 0LL;
if ( multiplexer_installed == 1 )
return multiplex_add_signal(12LL, sig_chld_signal_handler, v4);
result = elements;
if ( elements )
{
do
{
v6 = result;
result = *(_QWORD *)(result + 24);
}
while ( result );
*(_QWORD *)(v6 + 24) = v4;
}
else
{
elements = (__int64)v4;
}
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; }

user_defined_types: struct memory_pool { enum memory_pool_frame_type 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)
{
bool v2; // r13
char v3; // r12
unsigned int i; // ebx
unsigned int v5; // ebp
__int64 result; // rax
unsigned int v7[15]; // [rsp+Ch] [rbp-3Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
bool v2; // r13
char v3; // r12
unsigned int i; // ebx
unsigned int v5; // ebp
__int64 result; // rax
unsigned int v7[15]; // [rsp+Ch] [rbp-3Ch] BYREF

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

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

return_type: 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;
v3 = 0;
result = 21LL;
if ( *a1 )
{
while ( 1 )
{
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;
if ( !v3 || !v2 )
break;
v3 = 0;
}
result = 21LL;
}
return result;
}

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

v2 = (_QWORD *)*a1;
v3 = 0;
result = 21LL;
if ( *a1 )
{
while ( 1 )
{
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;
if ( !v3 || !v2 )
break;
v3 = 0;
}
result = 21LL;
}
return result;
}

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)
{
__int64 result; // rax
int v2; // edx

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

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
__int64 result; // rax
int v2; // edx

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

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

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

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

result = 21LL;
if ( ((unsigned __int8)a2 & 1) == 0 )
{
if ( *a2 == 4 || (result = 21LL, *a2 == 5) )
result = func8(a1, (__int64)(a2 + 1));
}
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
__int64 __fastcall cexit(int a1)
{
sys_exit(a1);
return jump_cmain();
}

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

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:
__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 ();
}

return_type: int


immutable

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

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

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

v15 = a1;
v2 = hash_murmur2_pt(&v15, 8LL, 0LL);
if ( tree_get_node(&immutable_data_tree, v2) )
return v15;
v4 = hash_murmur2_pt(v15, (unsigned int)a2, 0LL);
v5 = tree_get_node(&immutable_hashes, v4);
if ( v5 )
return node_get_value(v5);
if ( a2 + 1 > immutable_data_space_left )
{
func0();
v14 = 0x2000LL;
if ( a2 > 0x2000 )
v14 = ((a2 >> 13) + ((a2 & 0x1FFF) != 0)) << 13;
if ( immutable_data )
func0();
immutable_data = get_mem(v14);
immutable_data_space_left = v14;
immutable_cursor = immutable_data;
immutable_data_size = v14;
}
v6 = (_BYTE *)immutable_cursor;
v16[0] = immutable_cursor;
if ( a2 )
{
v7 = (_BYTE *)a1;
v8 = immutable_data_space_left + a1;
do
*v6++ = *v7++;
while ( (_BYTE *)(a1 + a2) != v7 );
immutable_cursor = (__int64)v6;
immutable_data_space_left = v8 - (_QWORD)v7;
}
v9 = immutable_cursor;
*(_BYTE *)immutable_cursor = 0;
v10 = v9 + 1;
immutable_cursor = v9 + 1;
v11 = immutable_data_space_left--;
if ( (((_BYTE)v9 + 1) & 7) != 0 )
{
v12 = v11 + v9;
do
*(_BYTE *)v10++ = 0;
while ( (v10 & 7) != 0 );
immutable_cursor = v10;
immutable_data_space_left = v12 - v10;
}
tree_add_node_value(&immutable_hashes, v4, v16[0]);
v13 = hash_murmur2_pt(v16, 8LL, 0LL);
tree_add_node(&immutable_data_tree, v13);
return v16[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)
{
void *result; // rax
unsigned __int64 v2; // rsi

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

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

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

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 *v6; // r14
__int64 v7; // rax
_DWORD *v9; // rbx
unsigned int v10; // eax
__int64 v11; // rdx

v6 = &sx_symbol_tree;
if ( a2 != 1 )
v6 = &sx_string_tree;
v7 = tree_get_node(v6, a3);
if ( v7 )
return node_get_value(v7);
v9 = (_DWORD *)aalloc(a4 + 5);
tree_add_node_value(v6, a3, v9);
if ( a4 )
{
v10 = 0;
v11 = 0LL;
do
{
*((_BYTE *)v9 + v10++ + 4) = *(_BYTE *)(a1 + v11);
v11 = v10;
}
while ( v10 < a4 );
}
else
{
v10 = 0;
}
*((_BYTE *)v9 + v10 + 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 *v6; // r14
__int64 v7; // rax
_DWORD *v9; // rbx
unsigned int v10; // eax
__int64 v11; // rdx

v6 = &sx_symbol_tree;
if ( a2 != 1 )
v6 = &sx_string_tree;
v7 = tree_get_node(v6, a3);
if ( v7 )
return node_get_value(v7);
v9 = (_DWORD *)aalloc(a4 + 5);
tree_add_node_value(v6, a3, v9);
if ( a4 )
{
v10 = 0;
v11 = 0LL;
do
{
*((_BYTE *)v9 + v10++ + 4) = *(_BYTE *)(a1 + v11);
v11 = v10;
}
while ( v10 < a4 );
}
else
{
v10 = 0;
}
*((_BYTE *)v9 + v10 + 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; // rbp
__int64 v3; // rax
__int64 v5; // rbx
__int64 v6[7]; // [rsp+0h] [rbp-38h] BYREF

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

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

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

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; // rax
__int64 v9; // rbp
__int64 v10[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 )
return -8 * v3 + 3;
v10[0] = v3;
v10[1] = v4;
v6 = hash_murmur2_pt(v10, 16LL, 0LL);
v7 = tree_get_node(&sx_rational_tree, v6);
if ( v7 )
return node_get_value(v7);
v9 = get_pool_mem(&pool_0);
*(_DWORD *)v9 = 20;
*(_QWORD *)(v9 + 8) = v3;
*(_QWORD *)(v9 + 16) = v5;
tree_add_node_value(&sx_rational_tree, v6, v9);
++gc_base_items;
return v9;
}

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; // rax
__int64 v9; // rbp
__int64 v10[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 )
return -8 * v3 + 3;
v10[0] = v3;
v10[1] = v4;
v6 = hash_murmur2_pt(v10, 16LL, 0LL);
v7 = tree_get_node(&sx_rational_tree, v6);
if ( v7 )
return node_get_value(v7);
v9 = get_pool_mem(&pool_0);
*(_DWORD *)v9 = 20;
*(_QWORD *)(v9 + 8) = v3;
*(_QWORD *)(v9 + 16) = v5;
tree_add_node_value(&sx_rational_tree, v6, v9);
++gc_base_items;
return v9;
}

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; // edx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // edx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 28);
result = *(unsigned int *)(a1 + 24);
if ( v1 < (unsigned int)result )
{
*(_DWORD *)(a1 + 24) = result - v1;
LODWORD(result) = 0;
do
{
*(_BYTE *)(*(_QWORD *)(a1 + 8) + (unsigned int)result) = *(_BYTE *)(*(_QWORD *)(a1 + 8)
+ (unsigned int)(*(_DWORD *)(a1 + 28) + result));
result = (unsigned int)(result + 1);
}
while ( *(_DWORD *)(a1 + 24) > (unsigned int)result );
*(_DWORD *)(a1 + 28) = 0;
}
else
{
*(_DWORD *)(a1 + 24) = 0;
*(_DWORD *)(a1 + 28) = 0;
}
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:
_DWORD *io_open_special()
{
_DWORD *result; // rax

result = (_DWORD *)io_create();
*result = -1;
result[5] = 0;
result[6] = 0;
result[7] = 0;
result[4] = 4;
return result;
}

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

result = (_DWORD *)io_create();
*result = -1;
result[5] = 0;
result[6] = 0;
result[7] = 0;
result[4] = 4;
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; // rbx

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

canonical_decompiled_code:
unsigned int *__fastcall func2(unsigned int a1)
{
unsigned int *v1; // rbx

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

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 *


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

v0 = a_open_write();
result = io_open(v0);
result[4] = 2;
return result;
}

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

v0 = a_open_write();
result = func2(v0);
result[4] = 2;
return result;
}

original_code:
struct io *io_open_write (const char *path)
{
    int fd = a_open_write (path);
    struct io *io = io_open(fd);
    io->type = iot_write;
    return io;
}

canonical_original_code:
struct io *io_open_write(char *path)
{
    int fd = a_open_write (path);
    struct io *io = io_open(fd);
    io->type = iot_write;
    return io;
}


decompiled_code:
unsigned int *__fastcall io_open_create(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int *result; // rax

a_unlink();
v2 = a_create(a1, a2);
result = io_open(v2);
result[4] = 2;
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func5(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
unsigned int *result; // rax

a_unlink();
v2 = a_create(a1, a2);
result = func2(v2);
result[4] = 2;
return result;
}

original_code:
struct io *io_open_create (const char *path, int mode)
{
    int fd = 0;
    struct io *io = (struct io *)0;
    a_unlink (path);
    fd = a_create (path, mode);
    io = io_open(fd);
    io->type = iot_write;
    return io;
}

canonical_original_code:
struct io *io_open_create(char *path, int mode)
{
    int fd = 0;
    struct io *io = (struct io *)0;
    a_unlink (path);
    fd = a_create (path, mode);
    io = io_open(fd);
    io->type = iot_write;
    return io;
}

variable_types: mode int


original_code:
enum io_result io_collect(struct io *io, const char *data, unsigned int length)
{
    unsigned int i, pos;
    if ((io->status == io_finalising) ||
        (io->status == io_end_of_file) ||
        (io->status == io_unrecoverable_error))
        return io->status;
    if (io->type == iot_special_read)
    {
        io->type = iot_special_write;
    }
    else if ((io->type != iot_special_write) && (io->fd == -1))
    {
        io->status = io_unrecoverable_error;
    }
    if ((io->type == iot_write) || (io->type == iot_special_write)) {
        if (io->position != 0) relocate_buffer_contents(io);
    } else {
        io->length = 0;
        io->position = 0;
        io->type = iot_write;
        io->status = io_undefined;
    }
    if ((io->length + length) > io->buffersize) {
        unsigned int newsize = (io->length + length);
        if ((newsize % 0x1000) != 0) {
            newsize = ((newsize / 0x1000) + 1) * 0x1000;
        }
        io->buffer = resize_mem (io->buffersize, io->buffer, newsize);
        io->buffersize = newsize;
    }
    for (i = 0, pos = io->length; i < length; i++, pos++) {
        io->buffer[pos] = data[i];
    }
    io->length += length;
    if (io->type == iot_special_write)
    {
        io->status = io_changes;
    }
    return io_incomplete;
}

canonical_original_code:
enum io_result io_collect(struct io *io, char *data, unsigned int length)
{
    unsigned int i; unsigned int pos;
    if ((io->status == io_finalising) ||
        (io->status == io_end_of_file) ||
        (io->status == io_unrecoverable_error))
        return io->status;
    if (io->type == iot_special_read)
    {
        io->type = iot_special_write;
    }
    else if ((io->type != iot_special_write) && (io->fd == -1))
    {
        io->status = io_unrecoverable_error;
    }
    if ((io->type == iot_write) || (io->type == iot_special_write)) {
        if (io->position != 0) relocate_buffer_contents(io);
    } else {
        io->length = 0;
        io->position = 0;
        io->type = iot_write;
        io->status = io_undefined;
    }
    if ((io->length + length) > io->buffersize) {
        unsigned int newsize = (io->length + length);
        if ((newsize % 0x1000) != 0) {
            newsize = ((newsize / 0x1000) + 1) * 0x1000;
        }
        io->buffer = resize_mem (io->buffersize, io->buffer, newsize);
        io->buffersize = newsize;
    }
    for (i = 0, pos = io->length; i < length; i++, pos++) {
        io->buffer[pos] = data[i];
    }
    io->length += length;
    if (io->type == iot_special_write)
    {
        io->status = io_changes;
    }
    return io_incomplete;
}

variable_types:
data
char *

variable_types:
length
unsigned int

variable_types:
pos
unsigned int

variable_types:
newsize
unsigned int

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


decompiled_code:
__int64 __fastcall io_flush(__int64 a1)
{
__int64 result; // rax
unsigned int v3; // ebp
unsigned int v4; // edi

result = *(unsigned int *)(a1 + 20);
if ( (*(_DWORD *)(a1 + 20) & 0xFFFFFFFD) != 1 && (_DWORD)result != 7 )
{
if ( *(_DWORD *)(a1 + 28) )
relocate_buffer_contents(a1);
result = *(unsigned int *)(a1 + 24);
v3 = result + 4096;
if ( (result & 0xFFF) != 0 )
v3 = (v3 & 0xFFFFF000) + 4096;
v4 = *(_DWORD *)(a1 + 32);
if ( v4 != v3 )
{
result = resize_mem(v4, *(_QWORD *)(a1 + 8), v3);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 32) = v3;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
unsigned int v3; // ebp
unsigned int v4; // edi

result = *(unsigned int *)(a1 + 20);
if ( (*(_DWORD *)(a1 + 20) & 0xFFFFFFFD) != 1 && (_DWORD)result != 7 )
{
if ( *(_DWORD *)(a1 + 28) )
func0(a1);
result = *(unsigned int *)(a1 + 24);
v3 = result + 4096;
if ( (result & 0xFFF) != 0 )
v3 = (v3 & 0xFFFFF000) + 4096;
v4 = *(_DWORD *)(a1 + 32);
if ( v4 != v3 )
{
result = resize_mem(v4, *(_QWORD *)(a1 + 8), v3);
*(_QWORD *)(a1 + 8) = result;
*(_DWORD *)(a1 + 32) = v3;
}
}
return result;
}

original_code:
void io_flush (struct io *io)
{
    if ((io->status == io_finalising) ||
        (io->status == io_end_of_file) ||
        (io->status == io_unrecoverable_error))
        return;
    if (io->position != 0) relocate_buffer_contents(io);
    unsigned int newsize = (io->length + 0x1000);
    if ((newsize % 0x1000) != 0) {
        newsize = ((newsize / 0x1000) + 1) * 0x1000;
    }
    if (newsize != io->buffersize) {
        io->buffer = resize_mem (io->buffersize, io->buffer, newsize);
        io->buffersize = newsize;
    }
    return;
}

canonical_original_code:
void io_flush(struct io *io)
{
    if ((io->status == io_finalising) ||
        (io->status == io_end_of_file) ||
        (io->status == io_unrecoverable_error))
        return;
    if (io->position != 0) relocate_buffer_contents(io);
    unsigned int newsize = (io->length + 0x1000);
    if ((newsize % 0x1000) != 0) {
        newsize = ((newsize / 0x1000) + 1) * 0x1000;
    }
    if (newsize != io->buffersize) {
        io->buffer = resize_mem (io->buffersize, io->buffer, newsize);
        io->buffersize = newsize;
    }
    return;
}


original_code:
enum io_result io_read(struct io *io)
{
    int readrv;
    if ((io->status == io_finalising) ||
        (io->status == io_end_of_file) ||
        (io->status == io_unrecoverable_error))
        return io->status;
    if (io->type == iot_special_write)
    {
        io->type = iot_special_read;
        if (io->position != 0) relocate_buffer_contents(io);
        if (io->status == io_changes)
        {
          io->status = io_no_change;
          return io_changes;
        }
        return io_no_change;
    }
    else if ((io->type != iot_special_read) && (io->fd == -1))
    {
        io->status = io_unrecoverable_error;
    }
    if (io->type == iot_special_read)
    {
        if (io->position != 0) relocate_buffer_contents(io);
        return io_no_change;
    }
    if (io->type == iot_read) {
        if (io->position != 0) relocate_buffer_contents(io);
    } else {
        io->length = 0;
        io->position = 0;
        io->type = iot_read;
        io->status = io_undefined;
    }
    if ((io->length + 0x1000) > io->buffersize) {
        unsigned int newsize = (io->length + 0x1000);
        if ((newsize % 0x1000) != 0) {
            newsize = ((newsize / 0x1000) + 1) * 0x1000;
        }
        io->buffer = resize_mem (io->buffersize, io->buffer, newsize);
        io->buffersize = newsize;
    }
    readrv = a_read(io->fd, (io->buffer + io->length), 0x1000);
    if (readrv < 0)
    {
        if (last_error_recoverable_p == (char)1) {
            return io_no_change;
        } else {
            io->status = io_unrecoverable_error;
            (void)a_close (io->fd);
            io->fd = -1;
            return io_unrecoverable_error;
        }
    }
    if (readrv == 0)
    {
        io->status = io_end_of_file;
        (void)a_close (io->fd);
        io->fd = -1;
        return io_end_of_file;
    }
    io->length += readrv;
    return io_changes;
}

variable_types: readrv int


decompiled_code:
__int64 __fastcall io_commit(unsigned int *a1)
{
__int64 result; // rax
int v2; // ecx
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rax

result = a1[4];
switch ( (int)result )
{
case 0:
return result;
case 1:
case 3:
result = io_read(a1);
break;
case 2:
result = 5LL;
if ( a1[6] )
{
if ( !*((_QWORD *)a1 + 1) )
goto LABEL_17;
v2 = a_write(*a1);
goto LABEL_8;
}
break;
case 4:
result = 6LL;
break;
case 5:
result = 1LL;
break;
default:
v2 = -1;
LABEL_8:
if ( *((_QWORD *)a1 + 1) )
{
if ( v2 < 0 )
{
result = 4LL;
if ( last_error_recoverable_p != 1 )
{
a1[5] = 3;
a_close(*a1);
*a1 = -1;
result = 3LL;
}
}
else if ( v2 )
{
v3 = a1[6];
if ( v3 == v2 )
{
a1[6] = 0;
result = 5LL;
}
else
{
v4 = v3 - v2;
a1[6] = v4;
if ( v4 )
{
v5 = 0LL;
do
{
*(_BYTE *)(*((_QWORD *)a1 + 1) + v5) = *(_BYTE *)(*((_QWORD *)a1 + 1) + v5 + v2);
++v5;
}
while ( a1[6] > (unsigned int)v5 );
result = 6LL;
}
else
{
result = 6LL;
}
}
}
else
{
a1[5] = 1;
a_close(*a1);
*a1 = -1;
result = 1LL;
}
}
else
{
LABEL_17:
a1[6] = 0;
result = 3LL;
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
__int64 result; // rax
int v2; // ecx
unsigned int v3; // eax
unsigned int v4; // eax
__int64 v5; // rax

result = a1[4];
switch ( (int)result )
{
case 0:
return result;
case 1:
case 3:
result = func8(a1);
break;
case 2:
result = 5LL;
if ( a1[6] )
{
if ( !*((_QWORD *)a1 + 1) )
goto LABEL_17;
v2 = a_write(*a1);
goto LABEL_8;
}
break;
case 4:
result = 6LL;
break;
case 5:
result = 1LL;
break;
default:
v2 = -1;
LABEL_8:
if ( *((_QWORD *)a1 + 1) )
{
if ( v2 < 0 )
{
result = 4LL;
if ( last_error_recoverable_p != 1 )
{
a1[5] = 3;
a_close(*a1);
*a1 = -1;
result = 3LL;
}
}
else if ( v2 )
{
v3 = a1[6];
if ( v3 == v2 )
{
a1[6] = 0;
result = 5LL;
}
else
{
v4 = v3 - v2;
a1[6] = v4;
if ( v4 )
{
v5 = 0LL;
do
{
*(_BYTE *)(*((_QWORD *)a1 + 1) + v5) = *(_BYTE *)(*((_QWORD *)a1 + 1) + v5 + v2);
++v5;
}
while ( a1[6] > (unsigned int)v5 );
result = 6LL;
}
else
{
result = 6LL;
}
}
}
else
{
a1[5] = 1;
a_close(*a1);
*a1 = -1;
result = 1LL;
}
}
else
{
LABEL_17:
a1[6] = 0;
result = 3LL;
}
break;
}
return result;
}

original_code:
enum io_result io_commit (struct io *io)
{
    int rv = -1, pos;
    unsigned int i;
    switch (io->type) {
        case iot_undefined:
            return io_undefined;
        case iot_buffer:
            return io_end_of_file;
        case iot_special_read:
        case iot_read:
            return io_read(io);
        case iot_special_write:
            return io_incomplete;
        case iot_write:
            if (io->length == 0) return io_complete;
            if (io->buffer != (char *)0)
            {
                rv = a_write(io->fd, io->buffer, io->length);
            }
    }
    if (io->buffer == (char *)0)
    {
        io->length = 0;
        return io_unrecoverable_error;
    }
    if (rv < 0)
    {
        if (last_error_recoverable_p == (char)1) {
            return io_no_change;
        } else {
            io->status = io_unrecoverable_error;
            (void)a_close (io->fd);
            io->fd = -1;
            return io_unrecoverable_error;
        }
    }
    if (rv == 0)
    {
        io->status = io_end_of_file;
        (void)a_close (io->fd);
        io->fd = -1;
        return io_end_of_file;
    }
    if (rv == (int)io->length)
    {
        io->length = 0;
        return io_complete;
    }
    io->length -= rv;
    for (i = 0, pos = rv; i < io->length; i++, pos++) {
        io->buffer[i] = io->buffer[pos];
    }
    return io_incomplete;
}

canonical_original_code:
enum io_result io_commit(struct io *io)
{
    int rv = -1; int pos;
    unsigned int i;
    switch (io->type) {
        case iot_undefined:
            return io_undefined;
        case iot_buffer:
            return io_end_of_file;
        case iot_special_read:
        case iot_read:
            return io_read(io);
        case iot_special_write:
            return io_incomplete;
        case iot_write:
            if (io->length == 0) return io_complete;
            if (io->buffer != (char *)0)
            {
                rv = a_write(io->fd, io->buffer, io->length);
            }
    }
    if (io->buffer == (char *)0)
    {
        io->length = 0;
        return io_unrecoverable_error;
    }
    if (rv < 0)
    {
        if (last_error_recoverable_p == (char)1) {
            return io_no_change;
        } else {
            io->status = io_unrecoverable_error;
            (void)a_close (io->fd);
            io->fd = -1;
            return io_unrecoverable_error;
        }
    }
    if (rv == 0)
    {
        io->status = io_end_of_file;
        (void)a_close (io->fd);
        io->fd = -1;
        return io_end_of_file;
    }
    if (rv == (int)io->length)
    {
        io->length = 0;
        return io_complete;
    }
    io->length -= rv;
    for (i = 0, pos = rv; i < io->length; i++, pos++) {
        io->buffer[i] = io->buffer[pos];
    }
    return io_incomplete;
}

variable_types: rv int

variable_types: pos int


decompiled_code:
__int64 __fastcall io_write(unsigned int *a1, _BYTE *a2, int a3)
{
__int64 result; // rax

result = io_collect((__int64)a1, a2, a3);
if ( (_DWORD)result == 6 )
result = io_commit(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, _BYTE *a2, int a3)
{
__int64 result; // rax

result = func6((__int64)a1, a2, a3);
if ( (_DWORD)result == 6 )
result = func9(a1);
return result;
}

original_code:
enum io_result io_write(struct io *io, const char *data, unsigned int length)
{
    enum io_result r = io_collect (io, data, length);
    if (r == io_incomplete) return io_commit(io);
    else return r;
}

canonical_original_code:
enum io_result io_write(struct io *io, char *data, unsigned int length)
{
    enum io_result r = io_collect (io, data, length);
    if (r == io_incomplete) return io_commit(io);
    else return r;
}

variable_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:
__int64 __fastcall io_finish(__int64 a1)
{
*(_DWORD *)(a1 + 20) = 7;
return 7LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
*(_DWORD *)(a1 + 20) = 7;
return 7LL;
}

original_code:
enum io_result io_finish (struct io *io)
{
    io->status = io_finalising;
    return io_finalising;
}

canonical_original_code:
enum io_result io_finish(struct io *io)
{
    io->status = io_finalising;
    return io_finalising;
}


decompiled_code:
__int64 __fastcall io_close(unsigned int *a1)
{
__int64 v2; // rdi
unsigned int v3; // edi

if ( a1[5] != 7 )
io_finish((__int64)a1);
if ( a1[4] == 2 )
{
while ( (io_commit(a1) & 0xFFFFFFFD) == 4 )
;
io_finish((__int64)a1);
}
v2 = *a1;
if ( (int)v2 >= 0 )
{
a_close(v2);
*a1 = -1;
}
v3 = a1[8];
if ( v3 && *((_QWORD *)a1 + 1) )
{
free_mem(v3);
*((_QWORD *)a1 + 1) = 0LL;
a1[8] = 0;
}
return io_destroy(a1);
}

original_code:
void io_close (struct io *io)
{
    if (io->status != io_finalising) (void)io_finish (io);
    if (io->type == iot_write) {
        enum io_result r;
        while (((r = io_commit (io)) == io_incomplete) || (r == io_no_change));
        (void)io_finish (io);
    }
    if (io->fd >= 0)
    {
        (void)a_close (io->fd);
        io->fd = -1;
    }
    if ((io->buffersize > 0) && (io->buffer != (char *)0)) {
        free_mem(io->buffersize, io->buffer);
        io->buffer = (char *)0;
        io->buffersize = 0;
    }
    io_destroy (io);
}

canonical_original_code:
void io_close(struct io *io)
{
    if (io->status != io_finalising) (void)io_finish (io);
    if (io->type == iot_write) {
        enum io_result r;
        while (((r = io_commit (io)) == io_incomplete) || (r == io_no_change));
        (void)io_finish (io);
    }
    if (io->fd >= 0)
    {
        (void)a_close (io->fd);
        io->fd = -1;
    }
    if ((io->buffersize > 0) && (io->buffer != (char *)0)) {
        free_mem(io->buffersize, io->buffer);
        io->buffer = (char *)0;
        io->buffersize = 0;
    }
    io_destroy (io);
}


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

for ( i = a1; (i & 1) == 0; i = *(_QWORD *)(i + 16) )
{
if ( *(_DWORD *)i != 6 )
break;
result = a2(*(_QWORD *)(i + 8));
if ( *(_DWORD *)i != 6 )
break;
}
return result;
}

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

for ( i = a1; (i & 1) == 0; i = *(_QWORD *)(i + 16) )
{
if ( *(_DWORD *)i != 6 )
break;
result = a2(*(_QWORD *)(i + 8));
if ( *(_DWORD *)i != 6 )
break;
}
return result;
}

original_code:
void sx_list_map (sexpr list, void (*f)(sexpr))
{
    while ((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)))
    {
        f(((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)list))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))));
        list = ((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)list))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
}

canonical_original_code:
void sx_list_map(unsigned long list, void (*f)(unsigned long))
{
    while ((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)))
    {
        f(((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)list))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))));
        list = ((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)list))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
}

variable_types:
list
unsigned long

variable_types:
f
void (*)(unsigned long)


original_code:
sexpr sx_list_fold (sexpr list, sexpr (*f)(sexpr, sexpr), sexpr seed)
{
    while ((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)))
    {
        seed = f(((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)list))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), seed);
        list = ((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)list))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return seed;
}

canonical_original_code:
unsigned long sx_list_fold(unsigned long list, unsigned long (*f)(unsigned long, unsigned long), unsigned long seed)
{
    while ((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)))
    {
        seed = f(((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)list))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), seed);
        list = ((((((int_pointer)(list)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)list))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)list))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return seed;
}

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

variable_types:
seed
unsigned long


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 read_directory(char *a1)
{
char v1; // al
int v2; // ecx
int i; // esi
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned __int8 *v6; // r12
__int64 v7; // rbp
__int64 v9; // r12
unsigned __int8 **v10; // rax
unsigned __int8 **v11; // r13
__int64 v12; // r14
unsigned __int8 *v13; // rbx
unsigned __int8 *v14[512]; // [rsp+0h] [rbp-2028h] BYREF
unsigned __int8 v15[4136]; // [rsp+1000h] [rbp-1028h] BYREF

v1 = *a1;
if ( !*a1 )
return read_directory_w(a1, v14, v15);
v2 = 0;
for ( i = 0; ; ++i )
{
v2 += v1 == 47;
v1 = a1[i + 1];
if ( !v1 )
break;
}
v4 = i + 2;
v5 = 8 * v2 + 8;
if ( v5 <= 0xFFF )
{
if ( v4 > 0xFFF )
{
v6 = (unsigned __int8 *)aalloc(v4);
v7 = read_directory_w(a1, v14, v6);
afree(v4, v6);
return v7;
}
return read_directory_w(a1, v14, v15);
}
v9 = v5;
v10 = (unsigned __int8 **)aalloc(v5);
v11 = v10;
if ( v4 > 0xFFF )
{
v12 = v4;
v13 = (unsigned __int8 *)aalloc(v4);
v7 = read_directory_w(a1, v11, v13);
afree(v12, v13);
}
else
{
v7 = read_directory_w(a1, v10, v15);
}
afree(v9, v11);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char v1; // al
int v2; // ecx
int i; // esi
unsigned int v4; // ebx
unsigned int v5; // eax
unsigned __int8 *v6; // r12
__int64 v7; // rbp
__int64 v9; // r12
unsigned __int8 **v10; // rax
unsigned __int8 **v11; // r13
__int64 v12; // r14
unsigned __int8 *v13; // rbx
unsigned __int8 *v14[512]; // [rsp+0h] [rbp-2028h] BYREF
unsigned __int8 v15[4136]; // [rsp+1000h] [rbp-1028h] BYREF

v1 = *a1;
if ( !*a1 )
return func0(a1, v14, v15);
v2 = 0;
for ( i = 0; ; ++i )
{
v2 += v1 == 47;
v1 = a1[i + 1];
if ( !v1 )
break;
}
v4 = i + 2;
v5 = 8 * v2 + 8;
if ( v5 <= 0xFFF )
{
if ( v4 > 0xFFF )
{
v6 = (unsigned __int8 *)aalloc(v4);
v7 = func0(a1, v14, v6);
afree(v4, v6);
return v7;
}
return func0(a1, v14, v15);
}
v9 = v5;
v10 = (unsigned __int8 **)aalloc(v5);
v11 = v10;
if ( v4 > 0xFFF )
{
v12 = v4;
v13 = (unsigned __int8 *)aalloc(v4);
v7 = func0(a1, v11, v13);
afree(v12, v13);
}
else
{
v7 = func0(a1, v10, v15);
}
afree(v9, v11);
return v7;
}

original_code:
sexpr read_directory (const char *p)
{
    sexpr r = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    unsigned int l = 0, s = 0, map_s, mapd_l;
    while (p[l]) {
        if (p[l] == '/') s++;
        l++;
    }
    s++;
    l++;
    map_s = sizeof (char *) * s;
    mapd_l = l;
    if (map_s < 0x1000)
    {
        char buf_map [0x1000];
        if (mapd_l < 0x1000)
        {
            char buf_mapd [0x1000];
            r = read_directory_w (p, (char **)buf_map, buf_mapd);
        }
        else
        {
            char *mapd = aalloc (mapd_l);
            r = read_directory_w (p, (char **)buf_map, mapd);
            afree (mapd_l, mapd);
        }
    }
    else
    {
        char **map = aalloc (map_s);
        if (mapd_l < 0x1000)
        {
            char buf_mapd [0x1000];
            r = read_directory_w (p, map, buf_mapd);
        }
        else
        {
            char *mapd = aalloc (mapd_l);
            r = read_directory_w (p, map, mapd);
            afree (mapd_l, mapd);
        }
        afree (map_s, map);
    }
    return r;
}

canonical_original_code:
unsigned long read_directory(char *p)
{
    unsigned long r = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    unsigned int l = 0; unsigned int s = 0; unsigned int map_s; unsigned int mapd_l;
    while (p[l]) {
        if (p[l] == '/') s++;
        l++;
    }
    s++;
    l++;
    map_s = sizeof (char *) * s;
    mapd_l = l;
    if (map_s < 0x1000)
    {
        char buf_map[4096];
        if (mapd_l < 0x1000)
        {
            char buf_mapd[4096];
            r = read_directory_w (p, (char **)buf_map, buf_mapd);
        }
        else
        {
            char *mapd = aalloc (mapd_l);
            r = read_directory_w (p, (char **)buf_map, mapd);
            afree (mapd_l, mapd);
        }
    }
    else
    {
        char **map = aalloc (map_s);
        if (mapd_l < 0x1000)
        {
            char buf_mapd[4096];
            r = read_directory_w (p, map, buf_mapd);
        }
        else
        {
            char *mapd = aalloc (mapd_l);
            r = read_directory_w (p, map, mapd);
            afree (mapd_l, mapd);
        }
        afree (map_s, map);
    }
    return r;
}

variable_types:
p
char *

variable_types:
r
unsigned long

variable_types:
l
unsigned int

variable_types:
s
unsigned int

variable_types:
mapd
char *

variable_types:
map
char **


decompiled_code:
__int64 __fastcall read_directory_sx(char *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = 45LL;
if ( ((unsigned __int8)a1 & 1) == 0 )
{
v2 = *(unsigned int *)a1;
if ( (_DWORD)v2 == 947 )
{
result = read_directory_rx(&LC1, a1, v2);
}
else if ( (_DWORD)v2 == 4 || (result = 45LL, (_DWORD)v2 == 5) )
{
result = read_directory(a1 + 4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = 45LL;
if ( ((unsigned __int8)a1 & 1) == 0 )
{
v2 = *(unsigned int *)a1;
if ( (_DWORD)v2 == 947 )
{
result = read_directory_rx(&LC1, a1, v2);
}
else if ( (_DWORD)v2 == 4 || (result = 45LL, (_DWORD)v2 == 5) )
{
result = func1(a1 + 4);
}
}
return result;
}

original_code:
sexpr read_directory_sx (sexpr rx)
{
    sexpr r = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    if ((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_partial *)((void *)rx))->type == 0x03b3))) {
        r = read_directory_rx (".", rx);
    } else if ((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)rx))->type == sxt_string))) {
        r = read_directory ((const char *)((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)rx))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)rx))->character_data) : "#nonexistent"));
    } else if ((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)rx))->type == sxt_symbol))) {
        r = read_directory ((const char *)((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)rx))->type == sxt_symbol)) ? (((struct sexpr_string_or_symbol *)((void *)rx))->character_data) : "#nonexistent"));
    }
    return r;
}

canonical_original_code:
unsigned long read_directory_sx(unsigned long rx)
{
    unsigned long r = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    if ((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_partial *)((void *)rx))->type == 0x03b3))) {
        r = read_directory_rx (".", rx);
    } else if ((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)rx))->type == sxt_string))) {
        r = read_directory ((char *)((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)rx))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)rx))->character_data) : "#nonexistent"));
    } else if ((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)rx))->type == sxt_symbol))) {
        r = read_directory ((char *)((((((int_pointer)(rx)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)rx))->type == sxt_symbol)) ? (((struct sexpr_string_or_symbol *)((void *)rx))->character_data) : "#nonexistent"));
    }
    return r;
}

variable_types:
rx
unsigned long


decompiled_code:
__int64 sx_open_stdio()
{
__int64 v0; // rbx
__int64 v1; // rax

v0 = io_open_stdout();
v1 = io_open_stdin();
return sx_open_io(v1, v0);
}

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

v0 = io_open_stdout();
v1 = io_open_stdin();
return sx_open_io(v1, v0);
}

original_code:
struct sexpr_io *sx_open_stdio() {
    return sx_open_io (io_open_stdin(), io_open_stdout());
}

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

user_defined_types: struct sexpr_io { struct io *in; struct io *out; }


decompiled_code:
__int64 sx_open_stdin()
{
__int64 v0; // rax

v0 = io_open_stdin();
return sx_open_io(v0, 0LL);
}

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

v0 = io_open_stdin();
return sx_open_io(v0, 0LL);
}

original_code:
struct sexpr_io *sx_open_stdin() {
    return (sx_open_io(io_open_stdin(), (struct io*)0));
}

canonical_original_code:
struct sexpr_io *sx_open_stdin() {
    return (sx_open_io(io_open_stdin(), (struct io *)0));
}


decompiled_code:
__int64 sx_open_stdout()
{
__int64 v0; // rax

v0 = io_open_stdout();
return sx_open_io(0LL, v0);
}

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

v0 = io_open_stdout();
return sx_open_io(0LL, v0);
}

original_code:
struct sexpr_io *sx_open_stdout() {
    return (sx_open_io((struct io*)0, io_open_stdout()));
}

canonical_original_code:
struct sexpr_io *sx_open_stdout() {
    return (sx_open_io((struct io *)0, io_open_stdout()));
}


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

if ( !installed_2 )
{
result = multiplex_add(mx_functions_1);
installed_2 = 1;
}
return result;
}

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

if ( !installed_2 )
{
result = multiplex_add(mx_functions_1);
installed_2 = 1;
}
return result;
}

original_code:
void multiplex_io () {
    static struct multiplex_functions mx_functions = {
        mx_f_count,
        mx_f_augment,
        mx_f_callback,
        (struct multiplex_functions *)0
    };
    static char installed = (char)0;
    if (installed == (char)0) {
        multiplex_add (&mx_functions);
        installed = (char)1;
    }
}

canonical_original_code:
void multiplex_io() {
    static struct multiplex_functions mx_functions = {
        mx_f_count,
        mx_f_augment,
        mx_f_callback,
        (struct multiplex_functions *)0
    };
    static char installed = (char)0;
    if (installed == (char)0) {
        multiplex_add (&mx_functions);
        installed = (char)1;
    }
}

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: installed char

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