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

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

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

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

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

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


repo: kyuba/curie

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

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

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

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

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

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

variable_types:
path
char *

variable_types: mode int

variable_types: fd int

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

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


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

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

variable_types:
data
char *

variable_types:
length
unsigned int

variable_types:
i
unsigned int

variable_types:
pos
unsigned int

variable_types:
newsize
unsigned int

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

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 }


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

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

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

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

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

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

return_type: void

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


decompiled_code:
__int64 __fastcall io_read(unsigned int *a1)
{
__int64 result; // rax
unsigned int v3; // edx
unsigned int v4; // er8
__int64 v5; // rdi
__int64 v6; // rsi
int v7; // eax
unsigned int v8; // ecx
__int64 v9; // rsi
unsigned int v10; // ebx
__int64 v11; // rdx
__int64 v12; // rax
__int64 v13; // rsi

result = a1[5];
if ( (_DWORD)result != 7 && (_DWORD)result != 1 && (_DWORD)result != 3 )
{
v3 = a1[4];
if ( v3 == 4 )
{
v8 = a1[7];
a1[4] = 3;
if ( v8 )
{
relocate_buffer_contents((__int64)a1);
result = a1[5];
}
if ( (_DWORD)result == 2 )
{
a1[5] = 4;
return result;
}
return 4LL;
}
if ( v3 == 3 )
{
if ( a1[7] )
relocate_buffer_contents((__int64)a1);
return 4LL;
}
v4 = *a1;
if ( *a1 == -1 )
a1[5] = 3;
if ( v3 == 1 )
{
if ( a1[7] )
relocate_buffer_contents((__int64)a1);
v9 = a1[6];
v5 = a1[8];
v10 = v9 + 4096;
if ( (int)v9 + 4096 <= (unsigned int)v5 )
{
v4 = *a1;
v6 = *((_QWORD *)a1 + 1) + v9;
goto LABEL_11;
}
if ( (v10 & 0xFFF) != 0 )
{
v11 = (v10 & 0xFFFFF000) + 4096;
v10 = (v10 & 0xFFFFF000) + 4096;
}
else
{
v11 = v10;
}
}
else
{
v5 = a1[8];
*((_QWORD *)a1 + 2) = 1LL;
*((_QWORD *)a1 + 3) = 0LL;
if ( (unsigned int)v5 > 0xFFF )
{
v6 = *((_QWORD *)a1 + 1);
LABEL_11:
v7 = a_read(v4, v6, 4096LL);
if ( v7 >= 0 )
{
if ( v7 )
{
a1[6] += v7;
result = 2LL;
}
else
{
a1[5] = 1;
a_close(*a1);
*a1 = -1;
result = 1LL;
}
return result;
}
if ( last_error_recoverable_p != 1 )
{
a1[5] = 3;
a_close(*a1);
*a1 = -1;
return 3LL;
}
return 4LL;
}
v11 = 4096LL;
v10 = 4096;
}
v12 = resize_mem(v5, *((_QWORD *)a1 + 1), v11);
v13 = a1[6];
v4 = *a1;
a1[8] = v10;
*((_QWORD *)a1 + 1) = v12;
v6 = v12 + v13;
goto LABEL_11;
}
return result;
}

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

variable_types: readrv int


decompiled_code:
__int64 __fastcall io_commit(unsigned int *a1)
{
unsigned int v1; // er12
int v2; // eax
__int64 v3; // rdx
__int64 v4; // rsi
unsigned int v5; // eax
bool v6; // zf
unsigned int v7; // eax
__int64 v8; // rax

v1 = a1[4];
switch ( v1 )
{
case 0u:
return v1;
case 1u:
case 3u:
return io_read(a1);
case 2u:
v1 = 5;
if ( !a1[6] )
return v1;
if ( !*((_QWORD *)a1 + 1) || (v2 = a_write(*a1), v3 = *((_QWORD *)a1 + 1), v4 = v2, !v3) )
{
LABEL_20:
a1[6] = 0;
return 3;
}
if ( v2 < 0 )
{
LABEL_18:
v1 = 4;
if ( last_error_recoverable_p != 1 )
{
a1[5] = 3;
v1 = 3;
a_close(*a1);
*a1 = -1;
}
return v1;
}
if ( v2 )
{
v5 = a1[6];
if ( v5 == (_DWORD)v4 )
{
a1[6] = 0;
}
else
{
v7 = v5 - v4;
v6 = v7 == 0;
a1[6] = v7;
v8 = 0LL;
if ( !v6 )
{
while ( 1 )
{
*(_BYTE *)(v3 + v8) = *(_BYTE *)(v3 + v8 + v4);
if ( a1[6] <= (unsigned int)++v8 )
break;
v3 = *((_QWORD *)a1 + 1);
}
}
LABEL_12:
v1 = 6;
}
return v1;
}
a1[5] = 1;
a_close(*a1);
*a1 = -1;
return 1LL;
case 4u:
goto LABEL_12;
case 5u:
return 1LL;
default:
if ( *((_QWORD *)a1 + 1) )
goto LABEL_18;
goto LABEL_20;
}
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
unsigned int v1; // er12
int v2; // eax
__int64 v3; // rdx
__int64 v4; // rsi
unsigned int v5; // eax
bool v6; // zf
unsigned int v7; // eax
__int64 v8; // rax

v1 = a1[4];
switch ( v1 )
{
case 0u:
return v1;
case 1u:
case 3u:
return func8(a1);
case 2u:
v1 = 5;
if ( !a1[6] )
return v1;
if ( !*((_QWORD *)a1 + 1) || (v2 = a_write(*a1), v3 = *((_QWORD *)a1 + 1), v4 = v2, !v3) )
{
LABEL_20:
a1[6] = 0;
return 3;
}
if ( v2 < 0 )
{
LABEL_18:
v1 = 4;
if ( last_error_recoverable_p != 1 )
{
a1[5] = 3;
v1 = 3;
a_close(*a1);
*a1 = -1;
}
return v1;
}
if ( v2 )
{
v5 = a1[6];
if ( v5 == (_DWORD)v4 )
{
a1[6] = 0;
}
else
{
v7 = v5 - v4;
v6 = v7 == 0;
a1[6] = v7;
v8 = 0LL;
if ( !v6 )
{
while ( 1 )
{
*(_BYTE *)(v3 + v8) = *(_BYTE *)(v3 + v8 + v4);
if ( a1[6] <= (unsigned int)++v8 )
break;
v3 = *((_QWORD *)a1 + 1);
}
}
LABEL_12:
v1 = 6;
}
return v1;
}
a1[5] = 1;
a_close(*a1);
*a1 = -1;
return 1LL;
case 4u:
goto LABEL_12;
case 5u:
return 1LL;
default:
if ( *((_QWORD *)a1 + 1) )
goto LABEL_18;
goto LABEL_20;
}
}

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

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

variable_types: rv int

variable_types: pos int


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

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

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

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

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

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

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


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

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

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

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


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

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


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

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

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

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

variable_types:
list
unsigned long

variable_types:
f
void (*)(unsigned long)

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

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


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

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

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

variable_types:
seed
unsigned long

return_type: unsigned long


variable_types: i long

variable_types:
num
char [33]

variable_types: neg int

variable_types:
j
unsigned int

variable_types: s char


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

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

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

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

variable_types:
p
char *

variable_types:
r
unsigned long

variable_types:
l
unsigned int

variable_types:
s
unsigned int

variable_types:
mapd
char *

variable_types:
map
char **


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

if ( (a1 & 1) != 0 )
return 45LL;
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 947 )
return read_directory_rx(&unk_418, a1);
if ( v1 != 4 && v1 != 5 )
return 45LL;
return read_directory((char *)(a1 + 4));
}

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

if ( (a1 & 1) != 0 )
return 45LL;
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 947 )
return read_directory_rx(&unk_418, a1);
if ( v1 != 4 && v1 != 5 )
return 45LL;
return func1((char *)(a1 + 4));
}

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

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

variable_types:
rx
unsigned long

user_defined_types: struct sexpr_partial { unsigned int type; }

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


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

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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

variable_types: installed char

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


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

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

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

v6 = get_pool_mem(&pool_0);
*(_QWORD *)(v6 + 40) = 0LL;
v7 = v6;
*(_QWORD *)v6 = a1;
*(_QWORD *)(v6 + 8) = a2;
*(_QWORD *)(v6 + 16) = a3;
*(_DWORD *)(v6 + 32) = 0;
*(_QWORD *)(v6 + 24) = a4;
result = list;
if ( list )
{
do
{
v9 = result;
result = *(_QWORD *)(result + 40);
}
while ( result );
*(_QWORD *)(v9 + 40) = v7;
}
else
{
list = v7;
}
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 memory_pool { enum memory_pool_frame_type type; unsigned int entitysize; }

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


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


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

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

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

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

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 }


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

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:
_DWORD *graph_create()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
__int64 v2; // rax
_DWORD *result; // rax

if ( !initialised )
graph_initialise();
v0 = (_DWORD *)get_pool_mem(&pool_2);
*v0 = 947;
v1 = v0;
v0[6] = 0;
v2 = aalloc(128LL);
++gc_base_items;
*((_QWORD *)v1 + 4) = v2;
result = v1;
*((_QWORD *)v1 + 1) = 0LL;
return result;
}

canonical_decompiled_code:
_DWORD *func3()
{
_DWORD *v0; // rax
_DWORD *v1; // r12
__int64 v2; // rax
_DWORD *result; // rax

if ( !initialised )
func2();
v0 = (_DWORD *)get_pool_mem(&pool_2);
*v0 = 947;
v1 = v0;
v0[6] = 0;
v2 = aalloc(128LL);
++gc_base_items;
*((_QWORD *)v1 + 4) = v2;
result = v1;
*((_QWORD *)v1 + 1) = 0LL;
return result;
}

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 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;
do
{
if ( equalp(**(_QWORD **)(*(_QWORD *)(a1 + 16) + 8 * v2), a2) == 29 )
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v2);
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (unsigned int)v2 );
return 0LL;
}

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 func0(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; // eax
signed __int64 result; // rax

v1 = get_multiple_of_pagesize(a1);
result = sys_mmap_constprop_0(v1);
if ( result <= 0 )
result = get_mem_recovery(a1);
return result;
}

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

v1 = func0(a1);
result = func2(v1);
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, __int64 a3)
{
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rax
signed __int64 result; // rax
__int64 v9; // r9

v5 = get_multiple_of_pagesize(a1);
v7 = get_multiple_of_pagesize(v6);
result = sys_mremap_constprop_0(a2, v5, v7);
if ( result == -1 )
result = resize_mem_recovery(v9, a2, a3);
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func6(unsigned __int64 a1, unsigned __int64 a2, __int64 a3)
{
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rax
signed __int64 result; // rax
__int64 v9; // r9

v5 = func0(a1);
v7 = func0(v6);
result = func1(a2, v5, v7);
if ( result == -1 )
result = resize_mem_recovery(v9, 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_isra_0(a2, v2);
}

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

v2 = func0(a1);
return func3(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_isra_0(a2, v2, 1);
}

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

v2 = func0(a1);
return func4(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_isra_0(a2, v2, 3);
}

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

v2 = func0(a1);
return func4(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_isra_0(a2, v2, 5);
}

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

v2 = func0(a1);
return func4(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 *v6; // rdx

result = a1;
v6 = *result;
*a2 = a3;
a2[1] = 0LL;
a2[2] = 0LL;
if ( v6 )
{
while ( 1 )
{
result = (unsigned __int64 **)v6[2];
if ( *v6 >= a3 )
result = (unsigned __int64 **)v6[1];
if ( !result )
break;
v6 = (unsigned __int64 *)result;
}
if ( *v6 >= a3 )
v6[1] = (unsigned __int64)a2;
else
v6[2] = (unsigned __int64)a2;
}
else
{
*result = 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 *v6; // rdx

result = a1;
v6 = *result;
*a2 = a3;
a2[1] = 0LL;
a2[2] = 0LL;
if ( v6 )
{
while ( 1 )
{
result = (unsigned __int64 **)v6[2];
if ( *v6 >= a3 )
result = (unsigned __int64 **)v6[1];
if ( !result )
break;
v6 = (unsigned __int64 *)result;
}
if ( *v6 >= a3 )
v6[1] = (unsigned __int64)a2;
else
v6[2] = (unsigned __int64)a2;
}
else
{
*result = 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
unsigned __int64 *v3; // rdx

result = *a1;
if ( *a1 )
{
do
{
if ( *result == a2 )
break;
v3 = (unsigned __int64 *)result[1];
if ( *result < a2 )
v3 = (unsigned __int64 *)result[2];
result = v3;
}
while ( v3 );
}
return result;
}

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

result = *a1;
if ( *a1 )
{
do
{
if ( *result == a2 )
break;
v3 = (unsigned __int64 *)result[1];
if ( *result < a2 )
v3 = (unsigned __int64 *)result[2];
result = v3;
}
while ( v3 );
}
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; // r8
unsigned __int64 *v6; // rax
unsigned __int64 *v7; // rdx
__int64 v8; // rdx
unsigned __int64 **v9; // rdi
unsigned __int64 *v10; // rdx

v3 = *a1;
if ( !*a1 )
return;
v6 = 0LL;
while ( *v3 != a2 )
{
if ( *v3 < a2 )
{
v7 = (unsigned __int64 *)v3[2];
v6 = v3;
if ( !v7 )
return;
goto LABEL_5;
}
LABEL_9:
v7 = (unsigned __int64 *)v3[1];
v6 = v3;
if ( !v7 )
return;
LABEL_5:
v3 = v7;
}
if ( a3 && v3 != a3 )
goto LABEL_9;
v8 = v3[1];
if ( v8 || v3[2] )
{
do
{
v9 = a1;
if ( v6 )
{
v9 = (unsigned __int64 **)(v6 + 2);
if ( (unsigned __int64 *)v6[1] == v3 )
v9 = (unsigned __int64 **)(v6 + 1);
}
if ( !v8 )
v8 = v3[2];
node_rotate(v9, (__int64)v3, v8);
v6 = v10;
v8 = v3[1];
}
while ( v8 || v3[2] );
if ( v6 )
{
if ( v3 == (unsigned __int64 *)v6[1] )
v6[1] = 0LL;
else
v6[2] = 0LL;
}
else
{
*a1 = 0LL;
}
}
else if ( v6 )
{
if ( v3 == (unsigned __int64 *)v6[1] )
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; // r8
unsigned __int64 *v6; // rax
unsigned __int64 *v7; // rdx
__int64 v8; // rdx
unsigned __int64 **v9; // rdi
unsigned __int64 *v10; // rdx

v3 = *a1;
if ( !*a1 )
return;
v6 = 0LL;
while ( *v3 != a2 )
{
if ( *v3 < a2 )
{
v7 = (unsigned __int64 *)v3[2];
v6 = v3;
if ( !v7 )
return;
goto LABEL_5;
}
LABEL_9:
v7 = (unsigned __int64 *)v3[1];
v6 = v3;
if ( !v7 )
return;
LABEL_5:
v3 = v7;
}
if ( a3 && v3 != a3 )
goto LABEL_9;
v8 = v3[1];
if ( v8 || v3[2] )
{
do
{
v9 = a1;
if ( v6 )
{
v9 = (unsigned __int64 **)(v6 + 2);
if ( (unsigned __int64 *)v6[1] == v3 )
v9 = (unsigned __int64 **)(v6 + 1);
}
if ( !v8 )
v8 = v3[2];
func2(v9, (__int64)v3, v8);
v6 = v10;
v8 = v3[1];
}
while ( v8 || v3[2] );
if ( v6 )
{
if ( v3 == (unsigned __int64 *)v6[1] )
v6[1] = 0LL;
else
v6[2] = 0LL;
}
else
{
*a1 = 0LL;
}
}
else if ( v6 )
{
if ( v3 == (unsigned __int64 *)v6[1] )
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; } *

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

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 }