decompiled_code:
__int64 __fastcall multiplex_add_io(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rcx

v6 = get_pool_mem(&pool_0);
*(_QWORD *)(v6 + 40) = 0LL;
*(_QWORD *)v6 = a1;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = a3;
*(_DWORD *)(v6 + 32) = 0;
*(_QWORD *)(v6 + 24) = a4;
result = list;
if ( list )
{
do
{
v8 = result;
result = *(_QWORD *)(result + 40);
}
while ( result );
*(_QWORD *)(v8 + 40) = v6;
}
else
{
list = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rdx
__int64 result; // rax
__int64 v8; // rcx

v6 = get_pool_mem(&pool_0);
*(_QWORD *)(v6 + 40) = 0LL;
*(_QWORD *)v6 = a1;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = a3;
*(_DWORD *)(v6 + 32) = 0;
*(_QWORD *)(v6 + 24) = a4;
result = list;
if ( list )
{
do
{
v8 = result;
result = *(_QWORD *)(result + 40);
}
while ( result );
*(_QWORD *)(v8 + 40) = v6;
}
else
{
list = v6;
}
return result;
}

original_code:
void multiplex_add_io (struct io *io, void (*on_read)(struct io *, void *), void (*on_close)(struct io *, void *), void *data) {
    static struct memory_pool pool
            = { mpft_static_header, ((((unsigned long)sizeof (struct io_list)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct io_list)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct io_list))) ? ((unsigned short)8) : 0)) };
    struct io_list *list_element = get_pool_mem (&pool);
    list_element->next = (void *)0;
    list_element->io = io;
    list_element->on_read = on_read;
    list_element->on_close = on_close;
    list_element->status = ils_nominal;
    list_element->data = data;
    if (list == (void *)0)
    {
        list = list_element;
    }
    else
    {
        struct io_list *cx = list;
        while ((cx->next) != (struct io_list *)0)
        {
            cx = cx->next;
        }
        cx->next = list_element;
    }
}

canonical_original_code:
void multiplex_add_io(struct io *io, void (*on_read)(struct io *, void *), void (*on_close)(struct io *, void *), void *data) {
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct io_list)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct io_list)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct io_list))) ? ((unsigned short)8) : 0)) };
    struct io_list *list_element = get_pool_mem (&pool);
    list_element->next = (void *)0;
    list_element->io = io;
    list_element->on_read = on_read;
    list_element->on_close = on_close;
    list_element->status = ils_nominal;
    list_element->data = data;
    if (list == (void *)0)
    {
        list = list_element;
    }
    else
    {
        struct io_list *cx = list;
        while ((cx->next) != (struct io_list *)0)
        {
            cx = cx->next;
        }
        cx->next = list_element;
    }
}

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

variable_types: struct io_list { 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; } *io; void (*on_read)(struct io *, void *); void (*on_close)(struct io *, void *); void *data; enum io_list_status { ils_nominal=0, ils_active=1, ils_kill=2 } status; struct io_list *next; } *

user_defined_types: struct io_list { struct io *io; void (*on_read)(struct io *, void *); void (*on_close)(struct io *, void *); void *data; enum io_list_status status; struct io_list *next; }


repo: kyuba/curie

decompiled_code:
__int64 __fastcall multiplex_add_io_no_callback(__int64 a1)
{
return multiplex_add_io(a1, 0LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return func3(a1, 0LL, 0LL, 0LL);
}

original_code:
void multiplex_add_io_no_callback (struct io *io)
{
    multiplex_add_io (io, (void *)0, (void *)0, (void *)0);
}

canonical_original_code:
void multiplex_add_io_no_callback(struct io *io)
{
    multiplex_add_io (io, (void *)0, (void *)0, (void *)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; } *

return_type: void

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


decompiled_code:
__int64 __fastcall mx_f_count(_DWORD *a1, _DWORD *a2)
{
_QWORD *v2; // rax
unsigned int v3; // edx
_DWORD *v4; // rdx
int v5; // ecx

v2 = (_QWORD *)list;
if ( !list )
return 0;
do
{
v4 = (_DWORD *)*v2;
if ( *(_DWORD *)*v2 == -1 )
{
if ( (unsigned int)(v4[4] - 3) <= 1 )
{
v3 = v4[5];
if ( v3 == 2 )
return v3;
}
}
else if ( (v4[5] & 0xFFFFFFFD) != 1 )
{
v5 = v4[4];
if ( v5 == 1 )
{
++*a1;
}
else if ( v5 == 2 && v4[6] )
{
++*a2;
}
}
v2 = (_QWORD *)v2[5];
}
while ( v2 );
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
_QWORD *v2; // rax
unsigned int v3; // edx
_DWORD *v4; // rdx
int v5; // ecx

v2 = (_QWORD *)list;
if ( !list )
return 0;
do
{
v4 = (_DWORD *)*v2;
if ( *(_DWORD *)*v2 == -1 )
{
if ( (unsigned int)(v4[4] - 3) <= 1 )
{
v3 = v4[5];
if ( v3 == 2 )
return v3;
}
}
else if ( (v4[5] & 0xFFFFFFFD) != 1 )
{
v5 = v4[4];
if ( v5 == 1 )
{
++*a1;
}
else if ( v5 == 2 && v4[6] )
{
++*a2;
}
}
v2 = (_QWORD *)v2[5];
}
while ( v2 );
return 0;
}

original_code:
static enum multiplex_result mx_f_count(int *r, int *w) {
    struct io_list *l = list;
    while (l != (struct io_list *)0) {
        struct io *io = l->io;
        if ((io->fd == -1))
        {
            switch (io->type) {
                case iot_special_read:
                case iot_special_write:
                    if (io->status == io_changes)
                    {
                        return mx_immediate_action;
                    }
                    break;
                default:
                    break;
            }
        } else if ((io->status != io_end_of_file) &&
                   (io->status != io_unrecoverable_error))
        {
            switch (io->type) {
                case iot_read:
                    (*r) += 1;
                    break;
                case iot_write:
                    if (io->length == 0) goto next;
                    (*w) += 1;
                    break;
                default:
                    break;
            }
        }
        next:
        l = l->next;
    }
    return mx_ok;
}

variable_types:
r
int *

variable_types:
w
int *

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

user_defined_types: enum io_list_status { ils_nominal=0, ils_active=1, ils_kill=2 }

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 }


original_code:
static void mx_f_augment(int *rs, int *r, int *ws, int *w) {
    struct io_list *l = list;
    while (l != (struct io_list *)0) {
        struct io *io = l->io;
        if ((io->fd != -1) &&
            (io->status != io_end_of_file) &&
            (io->status != io_unrecoverable_error))
        {
            int i, t, fd = io->fd;
            switch (io->type) {
                case iot_read:
                    t = *r;
                    for (i = 0; i < t; i++) {
                        if (rs[i] == fd) {
                            goto next;
                        }
                    }
                    rs[i] = fd;
                    (*r) += 1;
                    break;
                case iot_write:
                    if (io->length == 0) goto next;
                    t = *w;
                    for (i = 0; i < t; i++) {
                        if (ws[i] == fd) {
                            goto next;
                        }
                    }
                    ws[i] = fd;
                    (*w) += 1;
                    break;
                default:
                    break;
            }
        }
        next:
        l = l->next;
    }
}

canonical_original_code:
static void mx_f_augment(int *rs, int *r, int *ws, int *w) {
    struct io_list *l = list;
    while (l != (struct io_list *)0) {
        struct io *io = l->io;
        if ((io->fd != -1) &&
            (io->status != io_end_of_file) &&
            (io->status != io_unrecoverable_error))
        {
            int i; int t; int fd = io->fd;
            switch (io->type) {
                case iot_read:
                    t = *r;
                    for (i = 0; i < t; i++) {
                        if (rs[i] == fd) {
                            goto next;
                        }
                    }
                    rs[i] = fd;
                    (*r) += 1;
                    break;
                case iot_write:
                    if (io->length == 0) goto next;
                    t = *w;
                    for (i = 0; i < t; i++) {
                        if (ws[i] == fd) {
                            goto next;
                        }
                    }
                    ws[i] = fd;
                    (*w) += 1;
                    break;
                default:
                    break;
            }
        }
        next:
        l = l->next;
    }
}

variable_types:
rs
int *

variable_types:
ws
int *

variable_types: i int

variable_types: t int

variable_types: fd int


original_code:
static void mx_f_callback(int *rs, int r, int *ws, int w) {
    struct io_list *l = list, *t;
    char changes = 1;
    while (l != (struct io_list *)0) {
        struct io *io = l->io;
        if (l->status & ils_active)
        {
            goto next;
        }
        if (io->fd == -1)
        {
            switch (io->type) {
                case iot_special_read:
                case iot_special_write:
                    if (l->on_read != (void *)0)
                    {
                        if (io_read(io) == io_changes)
                        {
                            l->status |= ils_active;
                            l->on_read (io, l->data);
                            l->status &= ~ils_active;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        else if ((io->status != io_end_of_file) &&
                 (io->status != io_unrecoverable_error))
        {
            int i, fd = io->fd;
            switch (io->type) {
                case iot_read:
                    for (i = 0; i < r; i++) {
                        if (rs[i] == fd) {
                            (void)io_read (io);
                            if (l->on_read != (void *)0)
                            {
                                l->status |= ils_active;
                                l->on_read (io, l->data);
                                l->status &= ~ils_active;
                            }
                        }
                    }
                    break;
                case iot_write:
                    if (io->length == 0) goto next;
                    for (i = 0; i < w; i++) {
                        if (ws[i] == fd) {
                            (void)io_commit (io);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        next:
        t = l;
        l = l->next;
        if (t->status == ils_kill)
        {
            multiplex_del_io (io);
        }
    }
    while (changes)
    {
        changes = 0;
        l = list;
        while (l != (struct io_list *)0) {
            struct io *io = l->io;
            if (!(l->status & ils_active) &&
                (io->fd == -1))
            {
                switch (io->type) {
                    case iot_special_read:
                    case iot_special_write:
                        if (l->on_read != (void *)0)
                        {
                            if (io_read(io) == io_changes)
                            {
                                l->status |= ils_active;
                                l->on_read (io, l->data);
                                changes = 1;
                                l->status &= ~ils_active;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            t = l;
            l = l->next;
            if (t->status == ils_kill)
            {
                multiplex_del_io (io);
            }
        }
    }
    retry:
    l = list;
    while (l != (struct io_list *)0) {
        struct io *io = l->io;
        if (((io->fd == -1) &&
             (io->type != iot_special_read) &&
             (io->type != iot_special_write)) ||
            (io->status == io_end_of_file) ||
            (io->status == io_unrecoverable_error))
        {
            multiplex_del_io (io);
            goto retry;
        }
        l = l->next;
    }
}

canonical_original_code:
static void mx_f_callback(int *rs, int r, int *ws, int w) {
    struct io_list *l = list; struct io_list *t;
    char changes = 1;
    while (l != (struct io_list *)0) {
        struct io *io = l->io;
        if (l->status & ils_active)
        {
            goto next;
        }
        if (io->fd == -1)
        {
            switch (io->type) {
                case iot_special_read:
                case iot_special_write:
                    if (l->on_read != (void *)0)
                    {
                        if (io_read(io) == io_changes)
                        {
                            l->status |= ils_active;
                            l->on_read (io, l->data);
                            l->status &= ~ils_active;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        else if ((io->status != io_end_of_file) &&
                 (io->status != io_unrecoverable_error))
        {
            int i; int fd = io->fd;
            switch (io->type) {
                case iot_read:
                    for (i = 0; i < r; i++) {
                        if (rs[i] == fd) {
                            (void)io_read (io);
                            if (l->on_read != (void *)0)
                            {
                                l->status |= ils_active;
                                l->on_read (io, l->data);
                                l->status &= ~ils_active;
                            }
                        }
                    }
                    break;
                case iot_write:
                    if (io->length == 0) goto next;
                    for (i = 0; i < w; i++) {
                        if (ws[i] == fd) {
                            (void)io_commit (io);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        next:
        t = l;
        l = l->next;
        if (t->status == ils_kill)
        {
            multiplex_del_io (io);
        }
    }
    while (changes)
    {
        changes = 0;
        l = list;
        while (l != (struct io_list *)0) {
            struct io *io = l->io;
            if (!(l->status & ils_active) &&
                (io->fd == -1))
            {
                switch (io->type) {
                    case iot_special_read:
                    case iot_special_write:
                        if (l->on_read != (void *)0)
                        {
                            if (io_read(io) == io_changes)
                            {
                                l->status |= ils_active;
                                l->on_read (io, l->data);
                                changes = 1;
                                l->status &= ~ils_active;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            t = l;
            l = l->next;
            if (t->status == ils_kill)
            {
                multiplex_del_io (io);
            }
        }
    }
    retry:
    l = list;
    while (l != (struct io_list *)0) {
        struct io *io = l->io;
        if (((io->fd == -1) &&
             (io->type != iot_special_read) &&
             (io->type != iot_special_write)) ||
            (io->status == io_end_of_file) ||
            (io->status == io_unrecoverable_error))
        {
            multiplex_del_io (io);
            goto retry;
        }
        l = l->next;
    }
}

variable_types: r int

variable_types: w int

variable_types: changes char


original_code:
static sexpr graph_to_sexpr (sexpr gsx)
{
    struct graph *g = (struct graph *)((void *)gsx);
    sexpr sx = ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
    if (g != (struct graph *)0)
    {
        sexpr nodes = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
        sexpr edges = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
        unsigned int i;
        for (i = 0; i < g->node_count; i++)
        {
            struct graph_node *n = g->nodes[i];
            sexpr sxx = n->label;
            sexpr sxn = ((sexpr)((((int_pointer_s)(i)) << 3) | 0x3));
            unsigned int j;
            nodes = cons (cons (sxn, sxx), nodes);
            for (j = 0; j < n->edge_count; j++)
            {
                struct graph_edge *e = n->edges[j];
                unsigned int k;
                for (k = 0; k < g->node_count; k++)
                {
                    if (g->nodes[k] == e->target)
                    {
                        edges = cons (cons (sxn,
                                            cons (((sexpr)((((int_pointer_s)(k)) << 3) | 0x3)),
                                                  e->label)),
                                      edges);
                    }
                }
            }
        }
        sx = cons (nodes, edges);
    }
    return sx;
}

canonical_original_code:
static unsigned long graph_to_sexpr(unsigned long gsx)
{
    struct graph *g = (struct graph *)((void *)gsx);
    unsigned long sx = ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
    if (g != (struct graph *)0)
    {
        unsigned long nodes = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
        unsigned long edges = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
        unsigned int i;
        for (i = 0; i < g->node_count; i++)
        {
            struct graph_node *n = g->nodes[i];
            unsigned long sxx = n->label;
            unsigned long sxn = ((sexpr)((((int_pointer_s)(i)) << 3) | 0x3));
            unsigned int j;
            nodes = cons (cons (sxn, sxx), nodes);
            for (j = 0; j < n->edge_count; j++)
            {
                struct graph_edge *e = n->edges[j];
                unsigned int k;
                for (k = 0; k < g->node_count; k++)
                {
                    if (g->nodes[k] == e->target)
                    {
                        edges = cons (cons (sxn,
                                            cons (((sexpr)((((int_pointer_s)(k)) << 3) | 0x3)),
                                                  e->label)),
                                      edges);
                    }
                }
            }
        }
        sx = cons (nodes, edges);
    }
    return sx;
}

variable_types:
gsx
unsigned long

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

variable_types:
sx
unsigned long

variable_types:
nodes
unsigned long

variable_types:
edges
unsigned long

variable_types:
i
unsigned int

variable_types:
sxx
unsigned long

variable_types:
sxn
unsigned long

variable_types:
j
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:
k
unsigned int

return_type: unsigned long

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


decompiled_code:
__int64 graph_create()
{
__int64 v0; // rbx

if ( !initialised )
graph_initialise();
v0 = get_pool_mem(&pool_2);
*(_DWORD *)v0 = 947;
*(_DWORD *)(v0 + 24) = 0;
*(_QWORD *)(v0 + 32) = aalloc(128LL);
*(_QWORD *)(v0 + 8) = 0LL;
++gc_base_items;
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx

if ( !initialised )
func2();
v0 = get_pool_mem(&pool_2);
*(_DWORD *)v0 = 947;
*(_DWORD *)(v0 + 24) = 0;
*(_QWORD *)(v0 + 32) = aalloc(128LL);
*(_QWORD *)(v0 + 8) = 0LL;
++gc_base_items;
return v0;
}

original_code:
sexpr graph_create()
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct graph)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct graph)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct graph))) ? ((unsigned short)8) : 0)) };
    struct graph *gr;
    if (!initialised)
    {
        graph_initialise ();
    }
    gr = (struct graph *) get_pool_mem(&pool);
    gr->type = 0x03b3;
    gr->node_count = 0;
    gr->nodes = (struct graph_node **)aalloc (((((0) & ~(0x10 -1)) + 1) * 0x10 * sizeof(struct graph_node *)));
    gr->on_free = (void*)0;
    gc_base_items++;
    return (sexpr)gr;
}

canonical_original_code:
unsigned long graph_create()
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct graph)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct graph)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct graph))) ? ((unsigned short)8) : 0)) };
    struct graph *gr;
    if (!initialised)
    {
        graph_initialise ();
    }
    gr = (struct graph *) get_pool_mem(&pool);
    gr->type = 0x03b3;
    gr->node_count = 0;
    gr->nodes = (struct graph_node **)aalloc (((((0) & ~(0x10 -1)) + 1) * 0x10 * sizeof(struct graph_node *)));
    gr->on_free = (void *)0;
    gc_base_items++;
    return (unsigned long)gr;
}

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

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

user_defined_types: struct graph_edge { unsigned long label; struct graph_node *target; }


original_code:
struct graph_node *graph_add_node(sexpr sx, sexpr label)
{
    struct graph *gr = (struct graph *)((void *)sx);
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct graph_node)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct graph_node)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct graph_node))) ? ((unsigned short)8) : 0)) };
    struct graph_node *node = (struct graph_node *) get_pool_mem(&pool);
    unsigned int size_before = ((((gr->node_count) & ~(0x10 -1)) + 1) * 0x10 * sizeof(struct graph_node *)),
                 size_after = ((((gr->node_count + 1) & ~(0x10 -1)) + 1) * 0x10 * sizeof(struct graph_node *));
    if (size_before != size_after)
    {
        gr->nodes = (struct graph_node **) arealloc
                (size_before, gr->nodes, size_after);
    }
    node->edge_count = 0;
    node->edges = (struct graph_edge **)aalloc (((((0) & ~(0x8 -1)) + 1) * 0x8 * sizeof(struct graph_edge *)));
    node->label = label;
    gr->nodes[gr->node_count] = node;
    gr->node_count++;
    return node;
}

canonical_original_code:
struct graph_node *graph_add_node(unsigned long sx, unsigned long label)
{
    struct graph *gr = (struct graph *)((void *)sx);
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct graph_node)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct graph_node)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct graph_node))) ? ((unsigned short)8) : 0)) };
    struct graph_node *node = (struct graph_node *) get_pool_mem(&pool);
    unsigned int size_before = ((((gr->node_count) & ~(0x10 -1)) + 1) * 0x10 * sizeof(struct graph_node *)); unsigned int size_after = ((((gr->node_count + 1) & ~(0x10 -1)) + 1) * 0x10 * sizeof(struct graph_node *));
    if (size_before != size_after)
    {
        gr->nodes = (struct graph_node **) arealloc
                (size_before, gr->nodes, size_after);
    }
    node->edge_count = 0;
    node->edges = (struct graph_edge **)aalloc (((((0) & ~(0x8 -1)) + 1) * 0x8 * sizeof(struct graph_edge *)));
    node->label = label;
    gr->nodes[gr->node_count] = node;
    gr->node_count++;
    return node;
}

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

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


original_code:
struct graph_node *graph_search_node (sexpr sx, sexpr label)
{
    struct graph *gr = (struct graph *)((void *)sx);
    int i;
    for(i = 0; i < gr->node_count; i++) {
        if(((sexpr)(equalp(gr->nodes[i]->label, label)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
           return gr->nodes[i];
    }
    return (struct graph_node *)0;
}

canonical_original_code:
struct graph_node *graph_search_node(unsigned long sx, unsigned long label)
{
    struct graph *gr = (struct graph *)((void *)sx);
    int i;
    for(i = 0; i < gr->node_count; i++) {
        if(((sexpr)(equalp(gr->nodes[i]->label, label)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
           return gr->nodes[i];
    }
    return (struct graph_node *)0;
}

variable_types: i int

return_type: 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 graph_node_search_edge(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

if ( !*(_DWORD *)(a1 + 8) )
return 0LL;
v2 = 0LL;
while ( equalp(**(_QWORD **)(*(_QWORD *)(a1 + 16) + 8 * v2), a2) != 29 )
{
if ( *(_DWORD *)(a1 + 8) <= (unsigned int)++v2 )
return 0LL;
}
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v2);
}

original_code:
struct graph_edge *graph_node_search_edge (struct graph_node *node, sexpr label)
{
    int i;
    for(i = 0; i < node->edge_count; i++) {
        if(((sexpr)(equalp(node->edges[i]->label, label)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
           return node->edges[i];
    }
    return (struct graph_edge *)0;
}

canonical_original_code:
struct graph_edge *graph_node_search_edge(struct graph_node *node, unsigned long label)
{
    int i;
    for(i = 0; i < node->edge_count; i++) {
        if(((sexpr)(equalp(node->edges[i]->label, label)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
           return node->edges[i];
    }
    return (struct graph_edge *)0;
}

variable_types:
node
struct graph_node *

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


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

if ( !initialised )
{
result = sx_register_type(947LL, graph_to_sexpr, sexpr_to_graph, 0LL, graph_destroy, 0LL, 0LL);
initialised = 1;
}
return result;
}

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

if ( !initialised )
{
result = sx_register_type(947LL, graph_to_sexpr, sexpr_to_graph, 0LL, graph_destroy, 0LL, 0LL);
initialised = 1;
}
return result;
}

original_code:
void graph_initialise ()
{
    if (!initialised)
    {
        sx_register_type
                (0x03b3, graph_to_sexpr, sexpr_to_graph,
                 (void *)0, graph_destroy, (void *)0, (void *)0);
        initialised = 1;
    }
}

canonical_original_code:
void graph_initialise()
{
    if (!initialised)
    {
        sx_register_type
                (0x03b3, graph_to_sexpr, sexpr_to_graph,
                 (void *)0, graph_destroy, (void *)0, (void *)0);
        initialised = 1;
    }
}


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

v2 = str_immutable(a2);
return tree_add_node(a1, v2);
}

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

v2 = str_immutable(a2);
return tree_add_node(a1, v2);
}

original_code:
void tree_add_node_string (struct tree *t, char *k)
{
    tree_add_node(t, (int_pointer)str_immutable(k));
}

canonical_original_code:
void tree_add_node_string(struct tree *t, char *k)
{
    tree_add_node(t, (unsigned long)str_immutable(k));
}

variable_types: struct tree { struct tree_node { unsigned long key; } *root; } *

variable_types:
k
char *

user_defined_types:
struct tree { struct tree_node *root; }
struct tree_node { unsigned long key; }


decompiled_code:
__int64 __fastcall tree_add_node_string_value(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax

v4 = str_immutable(a2);
return tree_add_node_value(a1, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax

v4 = str_immutable(a2);
return tree_add_node_value(a1, v4, a3);
}

original_code:
void tree_add_node_string_value (struct tree *t, char *k, void *v)
{
    tree_add_node_value(t, (int_pointer)str_immutable(k), v);
}

canonical_original_code:
void tree_add_node_string_value(struct tree *t, char *k, void *v)
{
    tree_add_node_value(t, (unsigned long)str_immutable(k), v);
}

variable_types:
v
void *


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

v2 = str_immutable(a2);
return tree_get_node(a1, v2);
}

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

v2 = str_immutable(a2);
return tree_get_node(a1, v2);
}

original_code:
struct tree_node * tree_get_node_string (struct tree *t, char *k)
{
    return tree_get_node (t, (int_pointer)str_immutable(k));
}

canonical_original_code:
struct tree_node *tree_get_node_string(struct tree *t, char *k)
{
    return tree_get_node (t, (unsigned long)str_immutable(k));
}

variable_types: struct tree { struct tree_node *root; } *

return_type: struct tree_node { unsigned long key; } *


decompiled_code:
__int64 __fastcall tree_remove_node_string_specific(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax

v4 = str_immutable(a2);
return tree_remove_node_specific(a1, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax

v4 = str_immutable(a2);
return tree_remove_node_specific(a1, v4, a3);
}

original_code:
void tree_remove_node_string_specific
        (struct tree *t, char *k, struct tree_node *v)
{
    tree_remove_node_specific(t, (int_pointer)str_immutable(k), v);
}

canonical_original_code:
void tree_remove_node_string_specific(struct tree *t, char *k, struct tree_node *v)
{
    tree_remove_node_specific(t, (unsigned long)str_immutable(k), v);
}

variable_types:
v
struct tree_node *


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

result = a1;
if ( (a1 & 0xFFF) != 0 )
result = (a1 & 0xFFFFFFFFFFFFF000LL) + 4096;
return result;
}

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

result = a1;
if ( (a1 & 0xFFF) != 0 )
result = (a1 & 0xFFFFFFFFFFFFF000LL) + 4096;
return result;
}

original_code:
static unsigned long long get_multiple_of_pagesize(unsigned long int s)
{
    if ((s % LIBCURIE_PAGE_SIZE) == 0)
        return (unsigned long long)s;
    else
        return (unsigned long long)
               (((s / LIBCURIE_PAGE_SIZE) + 1) * LIBCURIE_PAGE_SIZE);
}

canonical_original_code:
static unsigned long long get_multiple_of_pagesize(unsigned long s)
{
    if ((s % LIBCURIE_PAGE_SIZE) == 0)
        return (unsigned long long)s;
    else
        return (unsigned long long)
               (((s / LIBCURIE_PAGE_SIZE) + 1) * LIBCURIE_PAGE_SIZE);
}

variable_types:
s
unsigned long

return_type: unsigned long long


decompiled_code:
signed __int64 __fastcall get_mem(unsigned __int64 a1)
{
int v1; // esi
signed __int64 result; // rax

v1 = get_multiple_of_pagesize(a1);
result = sys_mmap(0LL, v1, 3, 34, -1, 0LL);
if ( result <= 0 )
result = get_mem_recovery(a1);
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func5(unsigned __int64 a1)
{
int v1; // esi
signed __int64 result; // rax

v1 = func4(a1);
result = func0(0LL, v1, 3, 34, -1, 0LL);
if ( result <= 0 )
result = get_mem_recovery(a1);
return result;
}

original_code:
void *get_mem(unsigned long int size) {
    void *rv = (void *)-1;
    unsigned long long msize = get_multiple_of_pagesize(size);

    rv = sys_mmap((void *)0, msize,
                  0x3 /* PROT_READ | PROT_WRITE */,
                  0x22 /* MAP_ANON | MAP_PRIVATE */,
                  -1, 0);

    if ((signed long long)rv <= 0) {
        return get_mem_recovery(size);
    }

    return rv;
}

canonical_original_code:
void *get_mem(unsigned long size) {
    void *rv = (void *)-1;
    unsigned long long msize = get_multiple_of_pagesize(size);

    rv = sys_mmap((void *)0, msize,
                  0x3 /* PROT_READ | PROT_WRITE */,
                  0x22 /* MAP_ANON | MAP_PRIVATE */,
                  -1, 0);

    if ((long long)rv <= 0) {
        return get_mem_recovery(size);
    }

    return rv;
}

variable_types:
size
unsigned long

variable_types:
rv
void *

variable_types:
msize
unsigned long long

return_type: void *


decompiled_code:
signed __int64 __fastcall resize_mem(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r13
unsigned __int64 v5; // rax
signed __int64 result; // rax

v4 = get_multiple_of_pagesize(a1);
v5 = get_multiple_of_pagesize(a3);
result = sys_mremap(a2, v4, v5, 1uLL, 0LL);
if ( result == -1 )
result = resize_mem_recovery(a1, a2, a3);
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func6(unsigned __int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // r13
unsigned __int64 v5; // rax
signed __int64 result; // rax

v4 = func4(a1);
v5 = func4(a3);
result = func3(a2, v4, v5, 1uLL, 0LL);
if ( result == -1 )
result = resize_mem_recovery(a1, a2, a3);
return result;
}

original_code:
void *resize_mem
    (unsigned long int size, void *location, unsigned long int new_size)
{
    unsigned long long msize = get_multiple_of_pagesize(size);
    unsigned long long mnew_size = get_multiple_of_pagesize(new_size);

    void *rv = sys_mremap (location, msize, mnew_size,
                           0x1 /*MREMAP_MAYMOVE*/, 0);

    if (rv == (void*)-1)
    {
        return resize_mem_recovery(size, location, new_size);
    }

    return rv;
}

canonical_original_code:
void *resize_mem(unsigned long size, void *location, unsigned long new_size)
{
    unsigned long long msize = get_multiple_of_pagesize(size);
    unsigned long long mnew_size = get_multiple_of_pagesize(new_size);

    void *rv = sys_mremap (location, msize, mnew_size,
                           0x1 /*MREMAP_MAYMOVE*/, 0);

    if (rv == (void *)-1)
    {
        return resize_mem_recovery(size, location, new_size);
    }

    return rv;
}

variable_types:
location
void *


decompiled_code:
signed __int64 __fastcall free_mem(unsigned __int64 a1, unsigned __int64 a2)
{
int v2; // eax

v2 = get_multiple_of_pagesize(a1);
return sys_munmap(a2, v2);
}

canonical_decompiled_code:
signed __int64 __fastcall func7(unsigned __int64 a1, unsigned __int64 a2)
{
int v2; // eax

v2 = func4(a1);
return func2(a2, v2);
}

original_code:
void free_mem(unsigned long int size, void *location) {
    unsigned long long msize = get_multiple_of_pagesize(size);

    /* we ignore the return value, because the only way this will return in a
       bad way is whenever people pass invalid data to this function, which in
       turn would either lead to serious issues with the kernel or other parts
       of the programme. */
    (void)sys_munmap (location, msize);
}

canonical_original_code:
void free_mem(unsigned long size, void *location) {
    unsigned long long msize = get_multiple_of_pagesize(size);

    /* we ignore the return value, because the only way this will return in a
       bad way is whenever people pass invalid data to this function, which in
       turn would either lead to serious issues with the kernel or other parts
       of the programme. */
    (void)sys_munmap (location, msize);
}


decompiled_code:
signed __int64 get_mem_chunk()
{
return get_mem(0x1000uLL);
}

canonical_decompiled_code:
signed __int64 func8()
{
return func5(0x1000uLL);
}

original_code:
void *get_mem_chunk() {
    return get_mem(LIBCURIE_PAGE_SIZE);
}


decompiled_code:
signed __int64 __fastcall mark_mem_ro(unsigned __int64 a1, unsigned __int64 a2)
{
int v2; // eax

v2 = get_multiple_of_pagesize(a1);
return sys_mprotect(a2, v2, 1);
}

canonical_decompiled_code:
signed __int64 __fastcall func9(unsigned __int64 a1, unsigned __int64 a2)
{
int v2; // eax

v2 = func4(a1);
return func1(a2, v2, 1);
}

original_code:
void mark_mem_ro (unsigned long int size, void *location) {
    unsigned long long msize = get_multiple_of_pagesize(size);

    /* again we ignore the return value, because failure to mark the memory will
       only result in the memory still being writable, which is not going to be
       a critical issue */
    (void)sys_mprotect (location, msize, 0x1 /* PROT_READ*/);
}

canonical_original_code:
void mark_mem_ro(unsigned long size, void *location) {
    unsigned long long msize = get_multiple_of_pagesize(size);

    /* again we ignore the return value, because failure to mark the memory will
       only result in the memory still being writable, which is not going to be
       a critical issue */
    (void)sys_mprotect (location, msize, 0x1 /* PROT_READ*/);
}


decompiled_code:
signed __int64 __fastcall mark_mem_rw(unsigned __int64 a1, unsigned __int64 a2)
{
int v2; // eax

v2 = get_multiple_of_pagesize(a1);
return sys_mprotect(a2, v2, 3);
}

canonical_decompiled_code:
signed __int64 __fastcall func10(unsigned __int64 a1, unsigned __int64 a2)
{
int v2; // eax

v2 = func4(a1);
return func1(a2, v2, 3);
}

original_code:
void mark_mem_rw (unsigned long int size, void *location) {
    unsigned long long msize = get_multiple_of_pagesize(size);

    (void)sys_mprotect (location, msize, 0x3 /* PROT_READ | PROT_WRITE */);
}

canonical_original_code:
void mark_mem_rw(unsigned long size, void *location) {
    unsigned long long msize = get_multiple_of_pagesize(size);

    (void)sys_mprotect (location, msize, 0x3 /* PROT_READ | PROT_WRITE */);
}


decompiled_code:
signed __int64 __fastcall mark_mem_rx(unsigned __int64 a1, unsigned __int64 a2)
{
int v2; // eax

v2 = get_multiple_of_pagesize(a1);
return sys_mprotect(a2, v2, 5);
}

canonical_decompiled_code:
signed __int64 __fastcall func11(unsigned __int64 a1, unsigned __int64 a2)
{
int v2; // eax

v2 = func4(a1);
return func1(a2, v2, 5);
}

original_code:
void mark_mem_rx (unsigned long int size, void *location) {
    unsigned long long msize = get_multiple_of_pagesize(size);

    (void)sys_mprotect (location, msize, 0x5 /* PROT_READ | PROT_EXEC*/);
}

canonical_original_code:
void mark_mem_rx(unsigned long size, void *location) {
    unsigned long long msize = get_multiple_of_pagesize(size);

    (void)sys_mprotect (location, msize, 0x5 /* PROT_READ | PROT_EXEC*/);
}


original_code:
static void tree_map_worker
        (struct tree_node_basic *node,
         void (*callback)(struct tree_node *, void *),
         void *sv)
{
    struct tree_node_basic *onode;
    while (node != (struct tree_node_basic *)0) {
        onode = node;
        if (node->right != (struct tree_node_basic *)0)
        {
            if (node->left != (struct tree_node_basic *)0)
            {
                tree_map_worker (node->left, callback, sv);
            }
            node = node->right;
        }
        else
        {
            node = node->left;
        }
        callback((void *)onode, sv);
    }
}

canonical_original_code:
static void tree_map_worker(struct tree_node_basic *node, void (*callback)(struct tree_node *, void *), void *sv)
{
    struct tree_node_basic *onode;
    while (node != (struct tree_node_basic *)0) {
        onode = node;
        if (node->right != (struct tree_node_basic *)0)
        {
            if (node->left != (struct tree_node_basic *)0)
            {
                tree_map_worker (node->left, callback, sv);
            }
            node = node->right;
        }
        else
        {
            node = node->left;
        }
        callback((void *)onode, sv);
    }
}

variable_types: struct tree_node_basic { unsigned long key; struct tree_node_basic *left; struct tree_node_basic *right; } *

variable_types: void (*)(struct tree_node { unsigned long key; } *, void *)

variable_types:
sv
void *


decompiled_code:
unsigned __int64 *__fastcall tree_add_node_to_tree(unsigned __int64 **a1, unsigned __int64 *a2, unsigned __int64 a3)
{
unsigned __int64 *result; // rax
unsigned __int64 *v5; // rdx

result = *a1;
*a2 = a3;
a2[1] = 0LL;
a2[2] = 0LL;
if ( *a1 )
{
if ( result )
{
while ( 1 )
{
v5 = (unsigned __int64 *)(*result >= a3 ? result[1] : result[2]);
if ( !v5 )
break;
result = v5;
}
}
if ( *result >= a3 )
result[1] = (unsigned __int64)a2;
else
result[2] = (unsigned __int64)a2;
}
else
{
*a1 = a2;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 *__fastcall func1(unsigned __int64 **a1, unsigned __int64 *a2, unsigned __int64 a3)
{
unsigned __int64 *result; // rax
unsigned __int64 *v5; // rdx

result = *a1;
*a2 = a3;
a2[1] = 0LL;
a2[2] = 0LL;
if ( *a1 )
{
if ( result )
{
while ( 1 )
{
v5 = (unsigned __int64 *)(*result >= a3 ? result[1] : result[2]);
if ( !v5 )
break;
result = v5;
}
}
if ( *result >= a3 )
result[1] = (unsigned __int64)a2;
else
result[2] = (unsigned __int64)a2;
}
else
{
*a1 = a2;
}
return result;
}

original_code:
static void tree_add_node_to_tree
        (struct tree *tree, struct tree_node_basic *node, int_pointer key)
{
    struct tree_node_basic *cur = (struct tree_node_basic *)tree->root,
                           *last = (struct tree_node_basic *)0;
    node->key = key;
    node->left = (struct tree_node_basic *)0;
    node->right = (struct tree_node_basic *)0;
    if (tree->root == (struct tree_node *)0)
    {
        tree->root = (struct tree_node *)node;
        return;
    }
    while (cur != (struct tree_node_basic *)0)
    {
        last = cur;
        if (key > cur->key) {
            cur = cur->right;
        } else {
            cur = cur->left;
        }
    }
    if (key > last->key) {
        last->right = node;
    } else {
        last->left = node;
    }
}

canonical_original_code:
static void tree_add_node_to_tree(struct tree *tree, struct tree_node_basic *node, unsigned long key)
{
    struct tree_node_basic *cur = (struct tree_node_basic *)tree->root; struct tree_node_basic *last = (struct tree_node_basic *)0;
    node->key = key;
    node->left = (struct tree_node_basic *)0;
    node->right = (struct tree_node_basic *)0;
    if (tree->root == (struct tree_node *)0)
    {
        tree->root = (struct tree_node *)node;
        return;
    }
    while (cur != (struct tree_node_basic *)0)
    {
        last = cur;
        if (key > cur->key) {
            cur = cur->right;
        } else {
            cur = cur->left;
        }
    }
    if (key > last->key) {
        last->right = node;
    } else {
        last->left = node;
    }
}

variable_types:
key
unsigned long

user_defined_types: struct tree_node_basic { unsigned long key; struct tree_node_basic *left; struct tree_node_basic *right; }


decompiled_code:
__int64 __fastcall tree_destroy_fnd(__int64 *a1, void (__fastcall *a2)(__int64, __int64), __int64 a3)
{
node_destroy_fnd(*a1, a2, a3);
return free_pool_mem(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, void (__fastcall *a2)(__int64, __int64), __int64 a3)
{
func3(*a1, a2, a3);
return free_pool_mem(a1);
}

original_code:
void tree_destroy_fnd
        (struct tree *tree, void (*fnd)(struct tree_node *, void *), void *aux)
{
    node_destroy_fnd ((struct tree_node_basic *)tree->root, fnd, aux);
    free_pool_mem((void *)tree);
}

canonical_original_code:
void tree_destroy_fnd(struct tree *tree, void (*fnd)(struct tree_node *, void *), void *aux)
{
    node_destroy_fnd ((struct tree_node_basic *)tree->root, fnd, aux);
    free_pool_mem((void *)tree);
}

variable_types:
fnd
void (*)(struct tree_node *, void *)

variable_types:
aux
void *


decompiled_code:
__int64 __fastcall tree_destroy(__int64 *a1)
{
return tree_destroy_fnd(a1, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
return func4(a1, 0LL, 0LL);
}

original_code:
void tree_destroy (struct tree *tree)
{
    tree_destroy_fnd (tree, 0, 0);
}

canonical_original_code:
void tree_destroy(struct tree *tree)
{
    tree_destroy_fnd (tree, 0, 0);
}


decompiled_code:
__int64 __fastcall tree_map(__int64 *a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 v3; // rdi
__int64 result; // rax

v3 = *a1;
if ( v3 )
result = tree_map_worker(v3, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 v3; // rdi
__int64 result; // rax

v3 = *a1;
if ( v3 )
result = func0(v3, a2, a3);
return result;
}

original_code:
void tree_map
        (struct tree *tree, void (*callback)(struct tree_node *, void *),
         void *sv)
{
    if (tree->root != (struct tree_node *)0)
        tree_map_worker ((void *)tree->root, callback, sv);
}

canonical_original_code:
void tree_map(struct tree *tree, void (*callback)(struct tree_node *, void *), void *sv)
{
    if (tree->root != (struct tree_node *)0)
        tree_map_worker ((void *)tree->root, callback, sv);
}

variable_types:
callback
void (*)(struct tree_node *, void *)


decompiled_code:
unsigned __int64 *__fastcall tree_add_node(unsigned __int64 **a1, unsigned __int64 a2)
{
unsigned __int64 *v2; // rax

v2 = (unsigned __int64 *)get_pool_mem(&pool_1);
return tree_add_node_to_tree(a1, v2, a2);
}

canonical_decompiled_code:
unsigned __int64 *__fastcall func7(unsigned __int64 **a1, unsigned __int64 a2)
{
unsigned __int64 *v2; // rax

v2 = (unsigned __int64 *)get_pool_mem(&pool_1);
return func1(a1, v2, a2);
}

original_code:
void tree_add_node (struct tree *tree, int_pointer key)
{
    static struct memory_pool pool
            = { mpft_static_header, ((((unsigned long)sizeof (struct tree_node_basic)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct tree_node_basic)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct tree_node_basic))) ? ((unsigned short)8) : 0)) };
    struct tree_node_basic *node
            = (struct tree_node_basic *)get_pool_mem(&pool);
    tree_add_node_to_tree (tree, node, key);
}

canonical_original_code:
void tree_add_node(struct tree *tree, unsigned long key)
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct tree_node_basic)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct tree_node_basic)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct tree_node_basic))) ? ((unsigned short)8) : 0)) };
    struct tree_node_basic *node = (struct tree_node_basic *)get_pool_mem(&pool);
    tree_add_node_to_tree (tree, node, key);
}

variable_types: struct tree { struct tree_node { unsigned long key; } *root; } *

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


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

v4 = (unsigned __int64 *)get_pool_mem(&pool_0);
v4[3] = a3;
return tree_add_node_to_tree(a1, v4, a2);
}

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

v4 = (unsigned __int64 *)get_pool_mem(&pool_0);
v4[3] = a3;
return func1(a1, v4, a2);
}

original_code:
void tree_add_node_value (struct tree *tree, int_pointer key, void *value)
{
    static struct memory_pool pool
            = { mpft_static_header, ((((unsigned long)sizeof (struct tree_node_basic_pointer)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct tree_node_basic_pointer)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct tree_node_basic_pointer))) ? ((unsigned short)8) : 0)) };
    struct tree_node_basic_pointer * node
            = (struct tree_node_basic_pointer *)get_pool_mem(&pool);
    node->value = value;
    tree_add_node_to_tree (tree, (struct tree_node_basic *)node, key);
}

canonical_original_code:
void tree_add_node_value(struct tree *tree, unsigned long key, void *value)
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct tree_node_basic_pointer)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct tree_node_basic_pointer)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct tree_node_basic_pointer))) ? ((unsigned short)8) : 0)) };
    struct tree_node_basic_pointer *node = (struct tree_node_basic_pointer *)get_pool_mem(&pool);
    node->value = value;
    tree_add_node_to_tree (tree, (struct tree_node_basic *)node, key);
}

variable_types:
value
void *

variable_types: struct tree_node_basic_pointer { unsigned long key; struct tree_node_basic { unsigned long key; struct tree_node_basic *left; struct tree_node_basic *right; } *left; struct tree_node_basic *right; void *value; } *

user_defined_types: struct tree_node_basic_pointer { unsigned long key; struct tree_node_basic *left; struct tree_node_basic *right; void *value; }


decompiled_code:
unsigned __int64 *__fastcall tree_get_node(unsigned __int64 **a1, unsigned __int64 a2)
{
unsigned __int64 *result; // rax

for ( result = *a1; result; result = (unsigned __int64 *)(*result >= a2 ? result[1] : result[2]) )
{
if ( *result == a2 )
break;
}
return result;
}

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

for ( result = *a1; result; result = (unsigned __int64 *)(*result >= a2 ? result[1] : result[2]) )
{
if ( *result == a2 )
break;
}
return result;
}

original_code:
struct tree_node * tree_get_node (struct tree *tree, int_pointer key)
{
    struct tree_node_basic *cur = (struct tree_node_basic *)tree->root;
    while (cur != (struct tree_node_basic *)0) {
        if (cur->key == key)
        {
            return (struct tree_node *)cur;
        }
        if (key > cur->key) {
            cur = cur->right;
        } else {
            cur = cur->left;
        }
    }
    return (struct tree_node *)0;
}

canonical_original_code:
struct tree_node *tree_get_node(struct tree *tree, unsigned long key)
{
    struct tree_node_basic *cur = (struct tree_node_basic *)tree->root;
    while (cur != (struct tree_node_basic *)0) {
        if (cur->key == key)
        {
            return (struct tree_node *)cur;
        }
        if (key > cur->key) {
            cur = cur->right;
        } else {
            cur = cur->left;
        }
    }
    return (struct tree_node *)0;
}

variable_types: struct tree { struct tree_node *root; } *


decompiled_code:
void __fastcall tree_remove_node_specific(unsigned __int64 **a1, unsigned __int64 a2, unsigned __int64 *a3)
{
unsigned __int64 *v3; // rbx
_QWORD *v6; // rax
unsigned __int64 *v7; // rdx
unsigned __int64 **v8; // rdi
__int64 v9; // rbp

v3 = *a1;
if ( !*a1 )
return;
v6 = 0LL;
while ( *v3 != a2 )
{
if ( *v3 >= a2 )
goto LABEL_5;
v7 = (unsigned __int64 *)v3[2];
LABEL_22:
v6 = v3;
if ( !v7 )
return;
v3 = v7;
}
if ( a3 && a3 != v3 )
{
LABEL_5:
v7 = (unsigned __int64 *)v3[1];
goto LABEL_22;
}
while ( 1 )
{
v9 = v3[1];
if ( !v9 && !v3[2] )
break;
v8 = a1;
if ( v6 )
{
v8 = (unsigned __int64 **)(v6 + 2);
if ( (unsigned __int64 *)v6[1] == v3 )
v8 = (unsigned __int64 **)(v6 + 1);
}
if ( !v9 )
v9 = v3[2];
node_rotate(v8, (__int64)v3, v9);
v6 = (_QWORD *)v9;
}
if ( v6 )
{
if ( (unsigned __int64 *)v6[1] == v3 )
v6[1] = 0LL;
else
v6[2] = 0LL;
}
else
{
*a1 = 0LL;
}
free_pool_mem(v3);
}

canonical_decompiled_code:
void __fastcall func10(unsigned __int64 **a1, unsigned __int64 a2, unsigned __int64 *a3)
{
unsigned __int64 *v3; // rbx
_QWORD *v6; // rax
unsigned __int64 *v7; // rdx
unsigned __int64 **v8; // rdi
__int64 v9; // rbp

v3 = *a1;
if ( !*a1 )
return;
v6 = 0LL;
while ( *v3 != a2 )
{
if ( *v3 >= a2 )
goto LABEL_5;
v7 = (unsigned __int64 *)v3[2];
LABEL_22:
v6 = v3;
if ( !v7 )
return;
v3 = v7;
}
if ( a3 && a3 != v3 )
{
LABEL_5:
v7 = (unsigned __int64 *)v3[1];
goto LABEL_22;
}
while ( 1 )
{
v9 = v3[1];
if ( !v9 && !v3[2] )
break;
v8 = a1;
if ( v6 )
{
v8 = (unsigned __int64 **)(v6 + 2);
if ( (unsigned __int64 *)v6[1] == v3 )
v8 = (unsigned __int64 **)(v6 + 1);
}
if ( !v9 )
v9 = v3[2];
func2(v8, (__int64)v3, v9);
v6 = (_QWORD *)v9;
}
if ( v6 )
{
if ( (unsigned __int64 *)v6[1] == v3 )
v6[1] = 0LL;
else
v6[2] = 0LL;
}
else
{
*a1 = 0LL;
}
free_pool_mem(v3);
}

original_code:
void tree_remove_node_specific
        (struct tree *tree, int_pointer key, struct tree_node *node)
{
    struct tree_node_basic
            *cur = (struct tree_node_basic *)tree->root,
            *last = (struct tree_node_basic *)0;
    while (cur != (struct tree_node_basic *)0) {
        if ((cur->key == key) &&
            ((node == (struct tree_node *)0) ||
             (cur == (struct tree_node_basic *)node)))
        {
            while ((cur->left != (struct tree_node_basic *)0) ||
                   (cur->right != (struct tree_node_basic *)0))
            {
                struct tree_node_basic **update, *new_last;
                if (last == (struct tree_node_basic *)0)
                {
                    struct tree_node **update_temp = &(tree->root);
                    update = (struct tree_node_basic **)update_temp;
                }
                else
                {
                    if (last->left == cur)
                    {
                        update = &(last->left);
                    }
                    else
                    {
                        update = &(last->right);
                    }
                }
                if (cur->left != (struct tree_node_basic *)0)
                {
                    new_last = cur->left;
                }
                else
                {
                    new_last = cur->right;
                }
                node_rotate (update, cur, new_last);
                last = new_last;
            }
            if (last == (struct tree_node_basic *)0) {
                tree->root = (struct tree_node *)0;
            } else {
                if (last->left == cur) {
                    last->left = (struct tree_node_basic *)0;
                } else {
                    last->right = (struct tree_node_basic *)0;
                }
            }
            free_pool_mem((void *)cur);
            return;
        }
        last = cur;
        if (key > cur->key) {
            cur = cur->right;
        } else {
            cur = cur->left;
        }
    };
}

canonical_original_code:
void tree_remove_node_specific(struct tree *tree, unsigned long key, struct tree_node *node)
{
    struct tree_node_basic *cur = (struct tree_node_basic *)tree->root; struct tree_node_basic *last = (struct tree_node_basic *)0;
    while (cur != (struct tree_node_basic *)0) {
        if ((cur->key == key) &&
            ((node == (struct tree_node *)0) ||
             (cur == (struct tree_node_basic *)node)))
        {
            while ((cur->left != (struct tree_node_basic *)0) ||
                   (cur->right != (struct tree_node_basic *)0))
            {
                struct tree_node_basic **update; struct tree_node_basic *new_last;
                if (last == (struct tree_node_basic *)0)
                {
                    struct tree_node **update_temp = &(tree->root);
                    update = (struct tree_node_basic **)update_temp;
                }
                else
                {
                    if (last->left == cur)
                    {
                        update = &(last->left);
                    }
                    else
                    {
                        update = &(last->right);
                    }
                }
                if (cur->left != (struct tree_node_basic *)0)
                {
                    new_last = cur->left;
                }
                else
                {
                    new_last = cur->right;
                }
                node_rotate (update, cur, new_last);
                last = new_last;
            }
            if (last == (struct tree_node_basic *)0) {
                tree->root = (struct tree_node *)0;
            } else {
                if (last->left == cur) {
                    last->left = (struct tree_node_basic *)0;
                } else {
                    last->right = (struct tree_node_basic *)0;
                }
            }
            free_pool_mem((void *)cur);
            return;
        }
        last = cur;
        if (key > cur->key) {
            cur = cur->right;
        } else {
            cur = cur->left;
        }
    };
}

variable_types:
node
struct tree_node *

variable_types: struct tree_node_basic { unsigned long key; struct tree_node_basic *left; struct tree_node_basic *right; } **

variable_types: struct tree_node { unsigned long key; } **


decompiled_code:
__int64 __fastcall node_get_value(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
void *node_get_value
        (struct tree_node *node)
{
    return ((struct tree_node_basic_pointer *)node)->value;
}

canonical_original_code:
void *node_get_value(struct tree_node *node)
{
    return ((struct tree_node_basic_pointer *)node)->value;
}

variable_types: struct tree_node { unsigned long key; } *


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

result = io_open(0LL);
*(_DWORD *)(result + 16) = 1;
return result;
}

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

result = io_open(0LL);
*(_DWORD *)(result + 16) = 1;
return result;
}

original_code:
struct io *io_open_stdin ()
{
    struct io *in = io_open (0);
    in->type = iot_read;
    return in;
}

canonical_original_code:
struct io *io_open_stdin()
{
    struct io *in = io_open (0);
    in->type = iot_read;
    return in;
}

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


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

result = io_open(1LL);
*(_DWORD *)(result + 16) = 2;
return result;
}

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

result = io_open(1LL);
*(_DWORD *)(result + 16) = 2;
return result;
}

original_code:
struct io *io_open_stdout ()
{
    struct io *out = io_open (1);
    out->type = iot_write;
    return out;
}

canonical_original_code:
struct io *io_open_stdout()
{
    struct io *out = io_open (1);
    out->type = iot_write;
    return out;
}

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:
__int64 io_open_stderr()
{
__int64 result; // rax

result = io_open(2LL);
*(_DWORD *)(result + 16) = 2;
return result;
}

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

result = io_open(2LL);
*(_DWORD *)(result + 16) = 2;
return result;
}

original_code:
struct io *io_open_stderr ()
{
    struct io *out = io_open (2);
    out->type = iot_write;
    return out;
}

canonical_original_code:
struct io *io_open_stderr()
{
    struct io *out = io_open (2);
    out->type = iot_write;
    return out;
}


original_code:
sexpr path_normalise (sexpr path)
{
    sexpr rv = ((sexpr)((((int_pointer)(1)) << 3) | 0x5));
    if ((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)path))->type == sxt_cons)))
    {
        rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
        while ((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)path))->type == sxt_cons)))
        {
            rv = sx_set_add (rv, path_normalise (((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)path))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)path))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)))));
            path = ((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)path))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)path))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
    }
    else if ((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)path))->type == sxt_string)))
    {
        int l = 0, i = 0, levels = 0;
        const char *s = (const char *)((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)path))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)path))->character_data) : "#nonexistent");
        char *f;
        char is_start = (char)1;
        while (s[l] != (char)0)
        {
            l++;
        }
        l++;
        f = (char *)aalloc (l);
        l = 0;
        while (s[l] != (char)0)
        {
            switch (s[l])
            {
                case '/':
                    is_start = (char)1;
                    levels++;
                    f[i] = '/';
                    i++;
                    break;
                case '.':
                    if (is_start == (char)1)
                    {
                        if (s[(l+1)] == '/')
                        {
                            while (s[(l+1)] == '/')
                            {
                                l++;
                            }
                            break;
                        }
                    }
                default:
                    f[i] = s[l];
                    i++;
                    is_start = (char)0;
                    break;
            }
            l++;
        }
        f[i] = (char)0;
        rv = make_string_l (f, i);
        afree (l, (void *)f);
    }
    return rv;
}

canonical_original_code:
unsigned long path_normalise(unsigned long path)
{
    unsigned long rv = ((sexpr)((((int_pointer)(1)) << 3) | 0x5));
    if ((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)path))->type == sxt_cons)))
    {
        rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
        while ((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)path))->type == sxt_cons)))
        {
            rv = sx_set_add (rv, path_normalise (((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)path))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)path))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)))));
            path = ((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)path))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)path))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
    }
    else if ((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)path))->type == sxt_string)))
    {
        int l = 0; int i = 0; int levels = 0;
        char *s = (const char *)((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)path))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)path))->character_data) : "#nonexistent");
        char *f;
        char is_start = (char)1;
        while (s[l] != (char)0)
        {
            l++;
        }
        l++;
        f = (char *)aalloc (l);
        l = 0;
        while (s[l] != (char)0)
        {
            switch (s[l])
            {
                case '/':
                    is_start = (char)1;
                    levels++;
                    f[i] = '/';
                    i++;
                    break;
                case '.':
                    if (is_start == (char)1)
                    {
                        if (s[(l+1)] == '/')
                        {
                            while (s[(l+1)] == '/')
                            {
                                l++;
                            }
                            break;
                        }
                    }
                default:
                    f[i] = s[l];
                    i++;
                    is_start = (char)0;
                    break;
            }
            l++;
        }
        f[i] = (char)0;
        rv = make_string_l (f, i);
        afree (l, (void *)f);
    }
    return rv;
}

variable_types:
path
unsigned long

variable_types:
rv
unsigned long

variable_types: l int

variable_types: i int

variable_types: levels int

variable_types:
s
char *

variable_types:
f
char *

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

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 path_prefix (sexpr list)
{
    sexpr l = list, n = ((((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)l))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    const char *s;
    char buf[0x1000];
    int i = 0, li;
    for (s = (const char *)((((((int_pointer)(n)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)n))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)n))->character_data) : "#nonexistent"); (s[i] != (char)0) && (i < 0xfff); i++)
    {
        buf[i] = s[i];
    }
    buf[i] = (char)0;
    for (l = ((((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)l))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))); (((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)); l = ((((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)l))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))))
    {
        n = ((((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)l))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        s = (const char *)((((((int_pointer)(n)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)n))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)n))->character_data) : "#nonexistent");
        for (i = 0; (s[i] != (char)0) && (buf[i] != (char)0); i++)
        {
            if (buf[i] != s[i])
            {
                buf[i] = 0;
                break;
            }
        }
    }
    for (i = li = 0; (buf[i] != (char)0); i++)
    {
        if ((buf[i] == '/') || (buf[i] == '\\'))
        {
            li = i+1;
            i++;
        }
    }
    buf[li] = (char)0;
    return make_string (buf);
}

canonical_original_code:
unsigned long path_prefix(unsigned long list)
{
    unsigned long l = list; unsigned long n = ((((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)l))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    char *s;
    char buf[4096];
    int i = 0; int li;
    for (s = (char *)((((((int_pointer)(n)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)n))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)n))->character_data) : "#nonexistent"); (s[i] != (char)0) && (i < 0xfff); i++)
    {
        buf[i] = s[i];
    }
    buf[i] = (char)0;
    for (l = ((((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)l))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))); (((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)); l = ((((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)l))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))))
    {
        n = ((((((int_pointer)(l)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)l))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)l))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        s = (char *)((((((int_pointer)(n)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)n))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)n))->character_data) : "#nonexistent");
        for (i = 0; (s[i] != (char)0) && (buf[i] != (char)0); i++)
        {
            if (buf[i] != s[i])
            {
                buf[i] = 0;
                break;
            }
        }
    }
    for (i = li = 0; (buf[i] != (char)0); i++)
    {
        if ((buf[i] == '/') || (buf[i] == '\\'))
        {
            li = i+1;
            i++;
        }
    }
    buf[li] = (char)0;
    return make_string (buf);
}

variable_types:
list
unsigned long

variable_types:
l
unsigned long

variable_types:
n
unsigned long

variable_types:
buf
char [4096]

variable_types: li int


original_code:
sexpr path_normalise_prefix (sexpr path)
{
    sexpr p = path_normalise(path), rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5)), n,
          px = path_prefix (p);
    int i = 0;
    const char *s = (const char *)((((((int_pointer)(px)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)px))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)px))->character_data) : "#nonexistent");
    while (s[i] != (char)0)
    {
        i++;
    }
    while ((((((int_pointer)(p)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)p))->type == sxt_cons)))
    {
        n = ((((((int_pointer)(p)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)p))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)p))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        s = (const char *)((((((int_pointer)(n)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)n))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)n))->character_data) : "#nonexistent");
        rv = cons (cons (n, make_string (s + i)), rv);
        p = ((((((int_pointer)(p)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)p))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)p))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return rv;
}

canonical_original_code:
unsigned long path_normalise_prefix(unsigned long path)
{
    unsigned long p = path_normalise(path); unsigned long rv = ((sexpr)((((int_pointer)(5)) << 3) | 0x5)); unsigned long n; unsigned long px = path_prefix (p);
    int i = 0;
    char *s = (const char *)((((((int_pointer)(px)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)px))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)px))->character_data) : "#nonexistent");
    while (s[i] != (char)0)
    {
        i++;
    }
    while ((((((int_pointer)(p)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)p))->type == sxt_cons)))
    {
        n = ((((((int_pointer)(p)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)p))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)p))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        s = (char *)((((((int_pointer)(n)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)n))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)n))->character_data) : "#nonexistent");
        rv = cons (cons (n, make_string (s + i)), rv);
        p = ((((((int_pointer)(p)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)p))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)p))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return rv;
}

variable_types:
p
unsigned long

variable_types:
px
unsigned long


decompiled_code:
__int64 get_io_struct_real()
{
return get_pool_mem(io_struct_pool);
}

canonical_decompiled_code:
__int64 func0()
{
return get_pool_mem(io_struct_pool);
}

original_code:
static struct io *get_io_struct_real ()
{
    return get_pool_mem (io_struct_pool);
}

canonical_original_code:
static struct io *get_io_struct_real()
{
    return get_pool_mem (io_struct_pool);
}


decompiled_code:
__int64 get_io_struct_init()
{
io_struct_pool = create_memory_pool(40LL);
get_io_struct = get_io_struct_real;
return get_io_struct_real();
}

canonical_decompiled_code:
__int64 func1()
{
io_struct_pool = create_memory_pool(40LL);
get_io_struct = get_io_struct_real;
return func0();
}

original_code:
static struct io *get_io_struct_init ()
{
    io_struct_pool = create_memory_pool (sizeof (struct io));
    get_io_struct = get_io_struct_real;
    return get_io_struct_real();
}

canonical_original_code:
static struct io *get_io_struct_init()
{
    io_struct_pool = create_memory_pool (sizeof (struct io));
    get_io_struct = get_io_struct_real;
    return get_io_struct_real();
}


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

result = get_io_struct();
*(_QWORD *)(result + 8) = a1;
*(_DWORD *)(result + 16) = 5;
*(_DWORD *)(result + 20) = 1;
*(_QWORD *)(result + 24) = a2;
*(_DWORD *)(result + 32) = 0;
*(_DWORD *)result = -1;
return result;
}

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

result = get_io_struct();
*(_QWORD *)(result + 8) = a1;
*(_DWORD *)(result + 16) = 5;
*(_DWORD *)(result + 20) = 1;
*(_QWORD *)(result + 24) = a2;
*(_DWORD *)(result + 32) = 0;
*(_DWORD *)result = -1;
return result;
}

original_code:
struct io *io_open_buffer (void *buffer, unsigned int size)
{
    struct io *io = get_io_struct ();
    io->buffer = buffer;
    io->type = iot_buffer;
    io->status = io_end_of_file;
    io->length = size;
    io->position = 0;
    io->buffersize = 0;
    io->fd = -1;
    return io;
}

canonical_original_code:
struct io *io_open_buffer(void *buffer, unsigned int size)
{
    struct io *io = get_io_struct ();
    io->buffer = buffer;
    io->type = iot_buffer;
    io->status = io_end_of_file;
    io->length = size;
    io->position = 0;
    io->buffersize = 0;
    io->fd = -1;
    return io;
}

variable_types:
buffer
void *

variable_types:
size
unsigned int


original_code:
struct io *io_create ()
{
    struct io *io = get_io_struct ();
    io->buffer = get_mem (0x1000);
    io->status = io_undefined;
    io->length = 0;
    io->position = 0;
    io->buffersize = 0x1000;
    return io;
}

canonical_original_code:
struct io *io_create()
{
    struct io *io = get_io_struct ();
    io->buffer = get_mem (0x1000);
    io->status = io_undefined;
    io->length = 0;
    io->position = 0;
    io->buffersize = 0x1000;
    return io;
}

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


decompiled_code:
__int64 io_destroy()
{
return free_pool_mem();
}

canonical_decompiled_code:
__int64 func4()
{
return free_pool_mem();
}

original_code:
void io_destroy (struct io *io)
{
    free_pool_mem ((void *)(io));
}

canonical_original_code:
void io_destroy(struct io *io)
{
    free_pool_mem ((void *)(io));
}


decompiled_code:
signed __int64 dt_get_time()
{
return sys_time(0LL) % 86400;
}

canonical_decompiled_code:
signed __int64 func4()
{
return func0(0LL) % 86400;
}

original_code:
unsigned int dt_get_time (void)
{
    return sys_time(0) % SECONDS_PER_DAY;
}

canonical_original_code:
unsigned int dt_get_time()
{
    return sys_time(0) % SECONDS_PER_DAY;
}

return_type: unsigned int


decompiled_code:
signed __int64 __fastcall a_wait_all(_DWORD *a1)
{
signed __int64 result; // rax
int v2; // [rsp+Ch] [rbp-Ch] BYREF

result = sys_wait4(-1, &v2, 1, 0LL);
if ( (v2 & 0x7F) == 0 )
*a1 = BYTE1(v2);
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func2(_DWORD *a1)
{
signed __int64 result; // rax
int v2; // [rsp+Ch] [rbp-Ch] BYREF

result = func0(-1, &v2, 1, 0LL);
if ( (v2 & 0x7F) == 0 )
*a1 = BYTE1(v2);
return result;
}

original_code:
int a_wait_all(int *status) {
    int st, r;

    r = sys_wait4((signed int)-1, &st, 0x1 /*WNOHANG*/, (void *)0);

    if ((st & 0x7f) == 0) /* see above */
    {
        *status = ((st & 0xff00) >> 8);
    }

    return r;
}

canonical_original_code:
int a_wait_all(int *status) {
    int st; int r;

    r = sys_wait4((int)-1, &st, 0x1 /*WNOHANG*/, (void *)0);

    if ((st & 0x7f) == 0) /* see above */
    {
        *status = ((st & 0xff00) >> 8);
    }

    return r;
}

variable_types:
status
int *

variable_types: st int

variable_types: r int

return_type: int


decompiled_code:
__int64 __fastcall with_metadata_indirect(__int64 a1, __int64 a2)
{
return (*(__int64 (__fastcall **)(__int64, _QWORD))a2)(a1, *(_QWORD *)(a2 + 8));
}

original_code:
static void with_metadata_indirect (struct metadata *metadata, void *aux)
{
    struct metadata_indirection *i = (struct metadata_indirection *)aux;
    i->with_metadata (metadata, i->aux);
}

canonical_original_code:
static void with_metadata_indirect(struct metadata *metadata, void *aux)
{
    struct metadata_indirection *i = (struct metadata_indirection *)aux;
    i->with_metadata (metadata, i->aux);
}

variable_types:
aux
void *

variable_types: struct metadata_indirection { void (*with_metadata)(struct metadata { int datetime_count; int relation_count; int acl_count; struct metadata_datetime { enum metadata_datetime_purpose { mdp_unknown=0, mdp_creation=1, mdp_link_creation=2, mdp_last_access=3, mdp_last_modification=4, mdp_last_status_change=5, mdp_expiry=6 } purpose; struct datetime { unsigned long long date; unsigned int time; } datetime; } *datetime; struct metadata_relation { enum metadata_relation_type { mrt_unknown=0, mrt_owning_user=1, mrt_owning_group=2, mrt_creating_user=3, mrt_creating_group=4 } type; char *target; } *relation; struct metadata_acl { enum metadata_acl_target_type { mct_unknown=0, mct_creating_user=1, mct_creating_group=2, mct_owning_user=3, mct_owning_group=4, mct_user=5, mct_group=6, mct_default=7 } target_type; char *target; int access; } *acl; struct metadata_classification { enum metadata_classification_type { mdt_unknown=0, mdt_mime=1, mdt_unix=2 } type; } **classification; struct metadata_attribute { enum metadata_attribute_type { mat_unknown=0, mat_key_value=1, mat_description=2, mat_link_target=3, mat_link_device_id=4, mat_source_device_id=5, mat_inode=6, mat_link_count=7, mat_size=8, mat_user_id=9, mat_group_id=10, mat_flags=11 } type; } **attribute; struct metadata_signature { enum metadata_signature_type { mst_unknown=0, mst_hash_md4=1, mst_hash_md5=2, mst_hash_murmur=3, mst_hash_sha1=4, mst_hash_sha256=5, mst_hash_crc8=6, mst_hash_crc16=7, mst_hash_crc32=8 } type; } **signature; } *, void *); void *aux; } *

user_defined_types: struct metadata { int datetime_count; int relation_count; int acl_count; struct metadata_datetime *datetime; struct metadata_relation *relation; struct metadata_acl *acl; struct metadata_classification **classification; struct metadata_attribute **attribute; struct metadata_signature **signature; }

user_defined_types: struct metadata_indirection { void (*with_metadata)(struct metadata *, void *); void *aux; }

user_defined_types: struct metadata_datetime { enum metadata_datetime_purpose purpose; struct datetime datetime; }

user_defined_types: struct metadata_relation { enum metadata_relation_type type; char *target; }

user_defined_types: struct metadata_acl { enum metadata_acl_target_type target_type; char *target; int access; }

user_defined_types: struct metadata_classification { enum metadata_classification_type type; }

user_defined_types: struct metadata_attribute { enum metadata_attribute_type type; }

user_defined_types: struct metadata_signature { enum metadata_signature_type type; }


original_code:
void metadata_from_path
    (const char *path,
     void (*with_metadata) (struct metadata *, void *), void *aux)
{
    struct stat st;
    if (sys_stat ((char *)path, &st) != 0)
    {
        struct metadata metadata = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        with_metadata (&metadata, aux);
    }
    else
    {
        struct metadata_indirection i = { with_metadata, aux };
        enum metadata_classification_unix c;
        int attributes = 0;
             if (0xc000 & st.st_mode) { c = mcu_socket; }
        else if (0xa000 & st.st_mode) { c = mcu_symbolic_link; }
        else if (0x8000 & st.st_mode) { c = mcu_file; }
        else if (0x6000 & st.st_mode) { c = mcu_block_device; }
        else if (0x4000 & st.st_mode) { c = mcu_directory; }
        else if (0x2000 & st.st_mode) { c = mcu_character_device; }
        else if (0x1000 & st.st_mode) { c = mcu_fifo; }
        else { c = mcu_unknown; }
        if (0x0800 & st.st_mode) { attributes |= (1 << 0x0); }
        if (0x0400 & st.st_mode) { attributes |= (1 << 0x1); }
        if (0x0200 & st.st_mode) { attributes |= (1 << 0x2); }
        metadata_from_unix
            (c, st.st_uid, st.st_gid, st.st_mode, st.st_atime, st.st_mtime,
             st.st_ctime, st.st_size, st.st_dev, attributes,
             with_metadata_indirect, &i);
    }
}

canonical_original_code:
void metadata_from_path(char *path, void (*with_metadata)(struct metadata *, void *), void *aux)
{
    struct stat st;
    if (sys_stat ((char *)path, &st) != 0)
    {
        struct metadata metadata = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        with_metadata (&metadata, aux);
    }
    else
    {
        struct metadata_indirection i = { with_metadata, aux };
        enum metadata_classification_unix c;
        int attributes = 0;
             if (0xc000 & st.st_mode) { c = mcu_socket; }
        else if (0xa000 & st.st_mode) { c = mcu_symbolic_link; }
        else if (0x8000 & st.st_mode) { c = mcu_file; }
        else if (0x6000 & st.st_mode) { c = mcu_block_device; }
        else if (0x4000 & st.st_mode) { c = mcu_directory; }
        else if (0x2000 & st.st_mode) { c = mcu_character_device; }
        else if (0x1000 & st.st_mode) { c = mcu_fifo; }
        else { c = mcu_unknown; }
        if (0x0800 & st.st_mode) { attributes |= (1 << 0x0); }
        if (0x0400 & st.st_mode) { attributes |= (1 << 0x1); }
        if (0x0200 & st.st_mode) { attributes |= (1 << 0x2); }
        metadata_from_unix
            (c, st.st_uid, st.st_gid, st.st_mode, st.st_atime, st.st_mtime,
             st.st_ctime, st.st_size, st.st_dev, attributes,
             with_metadata_indirect, &i);
    }
}

variable_types:
path
char *

variable_types: void (*)(struct metadata { int datetime_count; int relation_count; int acl_count; struct metadata_datetime { enum metadata_datetime_purpose { mdp_unknown=0, mdp_creation=1, mdp_link_creation=2, mdp_last_access=3, mdp_last_modification=4, mdp_last_status_change=5, mdp_expiry=6 } purpose; struct datetime { unsigned long long date; unsigned int time; } datetime; } *datetime; struct metadata_relation { enum metadata_relation_type { mrt_unknown=0, mrt_owning_user=1, mrt_owning_group=2, mrt_creating_user=3, mrt_creating_group=4 } type; char *target; } *relation; struct metadata_acl { enum metadata_acl_target_type { mct_unknown=0, mct_creating_user=1, mct_creating_group=2, mct_owning_user=3, mct_owning_group=4, mct_user=5, mct_group=6, mct_default=7 } target_type; char *target; int access; } *acl; struct metadata_classification { enum metadata_classification_type { mdt_unknown=0, mdt_mime=1, mdt_unix=2 } type; } **classification; struct metadata_attribute { enum metadata_attribute_type { mat_unknown=0, mat_key_value=1, mat_description=2, mat_link_target=3, mat_link_device_id=4, mat_source_device_id=5, mat_inode=6, mat_link_count=7, mat_size=8, mat_user_id=9, mat_group_id=10, mat_flags=11 } type; } **attribute; struct metadata_signature { enum metadata_signature_type { mst_unknown=0, mst_hash_md4=1, mst_hash_md5=2, mst_hash_murmur=3, mst_hash_sha1=4, mst_hash_sha256=5, mst_hash_crc8=6, mst_hash_crc16=7, mst_hash_crc32=8 } type; } **signature; } *, void *)

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; unsigned int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; unsigned long st_atime; unsigned long st_atime_nsec; unsigned long st_mtime; unsigned long st_mtime_nsec; unsigned long st_ctime; unsigned long st_ctime_nsec; long __unused[3]; }

variable_types: struct metadata_indirection { void (*with_metadata)(struct metadata { int datetime_count; int relation_count; int acl_count; struct metadata_datetime { enum metadata_datetime_purpose { mdp_unknown=0, mdp_creation=1, mdp_link_creation=2, mdp_last_access=3, mdp_last_modification=4, mdp_last_status_change=5, mdp_expiry=6 } purpose; struct datetime { unsigned long long date; unsigned int time; } datetime; } *datetime; struct metadata_relation { enum metadata_relation_type { mrt_unknown=0, mrt_owning_user=1, mrt_owning_group=2, mrt_creating_user=3, mrt_creating_group=4 } type; char *target; } *relation; struct metadata_acl { enum metadata_acl_target_type { mct_unknown=0, mct_creating_user=1, mct_creating_group=2, mct_owning_user=3, mct_owning_group=4, mct_user=5, mct_group=6, mct_default=7 } target_type; char *target; int access; } *acl; struct metadata_classification { enum metadata_classification_type { mdt_unknown=0, mdt_mime=1, mdt_unix=2 } type; } **classification; struct metadata_attribute { enum metadata_attribute_type { mat_unknown=0, mat_key_value=1, mat_description=2, mat_link_target=3, mat_link_device_id=4, mat_source_device_id=5, mat_inode=6, mat_link_count=7, mat_size=8, mat_user_id=9, mat_group_id=10, mat_flags=11 } type; } **attribute; struct metadata_signature { enum metadata_signature_type { mst_unknown=0, mst_hash_md4=1, mst_hash_md5=2, mst_hash_murmur=3, mst_hash_sha1=4, mst_hash_sha256=5, mst_hash_crc8=6, mst_hash_crc16=7, mst_hash_crc32=8 } type; } **signature; } *, void *); void *aux; }

variable_types: enum metadata_classification_unix { mcu_unknown=0, mcu_file=1, mcu_directory=2, mcu_fifo=3, mcu_pipe=4, mcu_socket=5, mcu_symbolic_link=6, mcu_block_device=7, mcu_character_device=8 }

variable_types: attributes int


decompiled_code:
signed __int64 __fastcall metadata_to_path(__int64 a1, char *a2)
{
struct utimbuf v3; // [rsp+0h] [rbp-58h] BYREF
char v4[8]; // [rsp+18h] [rbp-40h] BYREF
__int64 v5; // [rsp+20h] [rbp-38h] BYREF
__time_t v6; // [rsp+28h] [rbp-30h] BYREF
__time_t v7; // [rsp+30h] [rbp-28h] BYREF
int v8; // [rsp+38h] [rbp-20h] BYREF
char v9[4]; // [rsp+3Ch] [rbp-1Ch] BYREF
mode_t v10; // [rsp+40h] [rbp-18h] BYREF
unsigned int v11; // [rsp+44h] [rbp-14h] BYREF
unsigned int v12; // [rsp+48h] [rbp-10h] BYREF
char v13[12]; // [rsp+4Ch] [rbp-Ch] BYREF

v7 = 0LL;
v6 = 0LL;
v5 = 0LL;
metadata_to_unix(a1, v13, &v12, &v11, &v10, &v7, &v6, &v5, v4, v9, &v8);
if ( (v8 & 1) != 0 )
v10 |= 0x800u;
if ( (v8 & 2) != 0 )
v10 |= 0x400u;
if ( (v8 & 4) != 0 )
v10 |= 0x200u;
sys_chmod(a2, v10);
sys_chown(a2, v12, v11);
v3.actime = v7;
v3.modtime = v6;
return sys_utime(a2, &v3);
}

canonical_decompiled_code:
signed __int64 __fastcall func6(__int64 a1, char *a2)
{
struct utimbuf v3; // [rsp+0h] [rbp-58h] BYREF
char v4[8]; // [rsp+18h] [rbp-40h] BYREF
__int64 v5; // [rsp+20h] [rbp-38h] BYREF
__time_t v6; // [rsp+28h] [rbp-30h] BYREF
__time_t v7; // [rsp+30h] [rbp-28h] BYREF
int v8; // [rsp+38h] [rbp-20h] BYREF
char v9[4]; // [rsp+3Ch] [rbp-1Ch] BYREF
mode_t v10; // [rsp+40h] [rbp-18h] BYREF
unsigned int v11; // [rsp+44h] [rbp-14h] BYREF
unsigned int v12; // [rsp+48h] [rbp-10h] BYREF
char v13[12]; // [rsp+4Ch] [rbp-Ch] BYREF

v7 = 0LL;
v6 = 0LL;
v5 = 0LL;
metadata_to_unix(a1, v13, &v12, &v11, &v10, &v7, &v6, &v5, v4, v9, &v8);
if ( (v8 & 1) != 0 )
v10 |= 0x800u;
if ( (v8 & 2) != 0 )
v10 |= 0x400u;
if ( (v8 & 4) != 0 )
v10 |= 0x200u;
func1(a2, v10);
func2(a2, v12, v11);
v3.actime = v7;
v3.modtime = v6;
return func3(a2, &v3);
}

original_code:
void metadata_to_path
    (struct metadata *metadata,
     const char *path)
{
    enum metadata_classification_unix classification;
    int uid, gid, mode, device, attributes;
    long atime = 0, mtime = 0, ctime = 0, size;
    long times[2];
    metadata_to_unix
        (metadata, &classification, &uid, &gid, &mode, &atime, &mtime, &ctime,
         &size, &device, &attributes);
    if (attributes & (1 << 0x0)) { mode |= 0x0800; }
    if (attributes & (1 << 0x1)) { mode |= 0x0400; }
    if (attributes & (1 << 0x2)) { mode |= 0x0200; }
    sys_chmod (path, mode);
    sys_chown (path, uid, gid);
    times[0] = atime;
    times[1] = mtime;
    sys_utime ((char *)path, times);
}

canonical_original_code:
void metadata_to_path(struct metadata *metadata, char *path)
{
    enum metadata_classification_unix classification;
    int uid; int gid; int mode; int device; int attributes;
    long atime = 0; long mtime = 0; long ctime = 0; long size;
    long times[2];
    metadata_to_unix
        (metadata, &classification, &uid, &gid, &mode, &atime, &mtime, &ctime,
         &size, &device, &attributes);
    if (attributes & (1 << 0x0)) { mode |= 0x0800; }
    if (attributes & (1 << 0x1)) { mode |= 0x0400; }
    if (attributes & (1 << 0x2)) { mode |= 0x0200; }
    sys_chmod (path, mode);
    sys_chown (path, uid, gid);
    times[0] = atime;
    times[1] = mtime;
    sys_utime ((char *)path, times);
}

variable_types: struct metadata { int datetime_count; int relation_count; int acl_count; struct metadata_datetime { enum metadata_datetime_purpose { mdp_unknown=0, mdp_creation=1, mdp_link_creation=2, mdp_last_access=3, mdp_last_modification=4, mdp_last_status_change=5, mdp_expiry=6 } purpose; struct datetime { unsigned long long date; unsigned int time; } datetime; } *datetime; struct metadata_relation { enum metadata_relation_type { mrt_unknown=0, mrt_owning_user=1, mrt_owning_group=2, mrt_creating_user=3, mrt_creating_group=4 } type; char *target; } *relation; struct metadata_acl { enum metadata_acl_target_type { mct_unknown=0, mct_creating_user=1, mct_creating_group=2, mct_owning_user=3, mct_owning_group=4, mct_user=5, mct_group=6, mct_default=7 } target_type; char *target; int access; } *acl; struct metadata_classification { enum metadata_classification_type { mdt_unknown=0, mdt_mime=1, mdt_unix=2 } type; } **classification; struct metadata_attribute { enum metadata_attribute_type { mat_unknown=0, mat_key_value=1, mat_description=2, mat_link_target=3, mat_link_device_id=4, mat_source_device_id=5, mat_inode=6, mat_link_count=7, mat_size=8, mat_user_id=9, mat_group_id=10, mat_flags=11 } type; } **attribute; struct metadata_signature { enum metadata_signature_type { mst_unknown=0, mst_hash_md4=1, mst_hash_md5=2, mst_hash_murmur=3, mst_hash_sha1=4, mst_hash_sha256=5, mst_hash_crc8=6, mst_hash_crc16=7, mst_hash_crc32=8 } type; } **signature; } *

variable_types: uid int

variable_types: gid int

variable_types: mode int

variable_types: device int

variable_types: atime long

variable_types: mtime long

variable_types: ctime long

variable_types: size long

variable_types:
times
long [2]

user_defined_types: enum metadata_classification_unix { mcu_unknown=0, mcu_file=1, mcu_directory=2, mcu_fifo=3, mcu_pipe=4, mcu_socket=5, mcu_symbolic_link=6, mcu_block_device=7, mcu_character_device=8 }


abort

decompiled_code:
void __noreturn abort()
{
sys_exit(-1);
memcpy();
}

canonical_decompiled_code:
void __noreturn func1()
{
func0(-1);
func2();
}

original_code:
void abort ( void )
{
    sys_exit (-1);
}

canonical_original_code:
void abort()
{
    sys_exit (-1);
}


memcpy

original_code:
void *memcpy(void *dest, const void *src, unsigned long n)
{
    const char *sc = (const char *)src;
    char *dc = (char *)dest;

    for (unsigned long i = 0; i < n; i++)
    {
        dc[i] = sc[i];
    }

    return dest;
}

canonical_original_code:
void *memcpy(void *dest, void *src, unsigned long n)
{
    char *sc = (const char *)src;
    char *dc = (char *)dest;

    for (unsigned long i = 0; i < n; i++)
    {
        dc[i] = sc[i];
    }

    return dest;
}

variable_types:
dest
void *

variable_types:
src
void *

variable_types:
n
unsigned long

variable_types:
sc
char *

variable_types:
dc
char *

variable_types:
i
unsigned long


strlen

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

if ( !*a1 )
return 0LL;
result = 0LL;
do
++result;
while ( a1[result] );
return result;
}

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

if ( !*a1 )
return 0LL;
result = 0LL;
do
++result;
while ( a1[result] );
return result;
}

original_code:
unsigned long strlen(const char *s)
{
    unsigned long i = 0;

    while (s[i] != (const char)0) i++;

    return i;
}

canonical_original_code:
unsigned long strlen(char *s)
{
    unsigned long i = 0;

    while (s[i] != (char)0) i++;

    return i;
}

variable_types:
s
char *


strcpy

decompiled_code:
__int64 __fastcall strcpy(__int64 a1, char *a2)
{
char v2; // al
int v3; // ecx
__int64 v4; // rdx

v2 = *a2;
if ( *a2 )
{
v3 = 0;
v4 = 0LL;
do
{
*(_BYTE *)(a1 + v4) = v2;
v4 = (unsigned int)++v3;
v2 = a2[v3];
}
while ( v2 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
char v2; // al
int v3; // ecx
__int64 v4; // rdx

v2 = *a2;
if ( *a2 )
{
v3 = 0;
v4 = 0LL;
do
{
*(_BYTE *)(a1 + v4) = v2;
v4 = (unsigned int)++v3;
v2 = a2[v3];
}
while ( v2 );
}
return a1;
}

original_code:
char *strcpy(char *restrict s1, const char *restrict s2)
{
    for (unsigned int i = 0; s2[i] != 0; i++)
    {
        s1[i] = s2[i];
    }

    return s1;
}

canonical_original_code:
char *strcpy(char *s1, char *s2)
{
    for (unsigned int i = 0; s2[i] != 0; i++)
    {
        s1[i] = s2[i];
    }

    return s1;
}

variable_types:
i
unsigned int

return_type: char *


memcmp

decompiled_code:
__int64 __fastcall memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // r8
unsigned __int8 v5; // dl
unsigned __int8 v6; // al

if ( !a3 )
return 0LL;
for ( i = 0LL; i != a3; ++i )
{
v5 = *(_BYTE *)(a1 + i);
v6 = *(_BYTE *)(a2 + i);
if ( v5 != v6 )
return v6 - (unsigned int)v5;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // r8
unsigned __int8 v5; // dl
unsigned __int8 v6; // al

if ( !a3 )
return 0LL;
for ( i = 0LL; i != a3; ++i )
{
v5 = *(_BYTE *)(a1 + i);
v6 = *(_BYTE *)(a2 + i);
if ( v5 != v6 )
return v6 - (unsigned int)v5;
}
return 0LL;
}

original_code:
int memcmp(const void *s1, const void *s2, unsigned long count)
{
    for (long i = 0; i < count; i++)
    {
        if (((unsigned char *)s1)[i] == ((unsigned char *)s2)[i]) continue;
        return (((unsigned char *)s2)[i] - ((unsigned char *)s1)[i]);
    }

    return 0;
}

canonical_original_code:
int memcmp(void *s1, void *s2, unsigned long count)
{
    for (long i = 0; i < count; i++)
    {
        if (((unsigned char *)s1)[i] == ((unsigned char *)s2)[i]) continue;
        return (((unsigned char *)s2)[i] - ((unsigned char *)s1)[i]);
    }

    return 0;
}

variable_types:
count
unsigned long

variable_types: i long


strncmp

decompiled_code:
__int64 __fastcall strncmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r8
unsigned __int8 v5; // dl
unsigned __int8 v6; // al

v4 = 0LL;
if ( !a3 )
return 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
if ( !v5 )
break;
v6 = *(_BYTE *)(a2 + v4);
if ( !v6 )
return 0LL;
if ( v5 != v6 )
return v6 - (unsigned int)v5;
if ( ++v4 == a3 )
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // r8
unsigned __int8 v5; // dl
unsigned __int8 v6; // al

v4 = 0LL;
if ( !a3 )
return 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
if ( !v5 )
break;
v6 = *(_BYTE *)(a2 + v4);
if ( !v6 )
return 0LL;
if ( v5 != v6 )
return v6 - (unsigned int)v5;
if ( ++v4 == a3 )
return 0LL;
}
return 0LL;
}

original_code:
int strncmp(const char *s1, const char *s2, unsigned long count)
{
    for (long i = 0; (i < count) && (s1[i] != 0) && (s2[i] != 0); i++)
    {
        if ((unsigned char)(s1[i]) == (unsigned char)(s2[i])) continue;
        return ((unsigned char)(s2[i]) - (unsigned char)(s1[i]));
    }

    return 0;
}

canonical_original_code:
int strncmp(char *s1, char *s2, unsigned long count)
{
    for (long i = 0; (i < count) && (s1[i] != 0) && (s2[i] != 0); i++)
    {
        if ((unsigned char)(s1[i]) == (unsigned char)(s2[i])) continue;
        return ((unsigned char)(s2[i]) - (unsigned char)(s1[i]));
    }

    return 0;
}


renderMap

repo: sevko/termcrate

decompiled_code:
__int64 renderMap()
{
const char *v0; // rbx

xt_par0("\x1B[33m");
v0 = &mapBuf;
do
{
printf("%s", v0);
v0 += 178;
}
while ( v0 != (const char *)(unsigned int)((_DWORD)&mapBuf + 7832) );
return xt_par0("\x1B[0m");
}

canonical_decompiled_code:
__int64 func0()
{
const char *v0; // rbx

xt_par0("\x1B[33m");
v0 = &mapBuf;
do
{
printf("%s", v0);
v0 += 178;
}
while ( v0 != (const char *)(unsigned int)((_DWORD)&mapBuf + 7832) );
return xt_par0("\x1B[0m");
}

original_code:
void renderMap(){
 int row;
 xt_par0("\033[33m");
 for(row = 0; row < 44; row++)
  printf("%s", mapBuf[row]);
 xt_par0("\033[0m");
}

variable_types: row int