original_code:
static struct event *get_event ()
{
    struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct event)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct event)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct event))) ? ((unsigned short)8) : 0)) };
    struct event *ev = get_pool_mem (&pool);
    ev->queue_time = dt_get ();
    ev->repeat = 1;
    ev->model = em_seconds;
    ev->model_data.seconds = 5;
    ev->output = sx_list1 (sym_tick);
    ev->then = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    ev->next = events;
    events = ev;
    return ev;
}

canonical_original_code:
static struct event *get_event()
{
    struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct event)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct event)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct event))) ? ((unsigned short)8) : 0)) };
    struct event *ev = get_pool_mem (&pool);
    ev->queue_time = dt_get ();
    ev->repeat = 1;
    ev->model = em_seconds;
    ev->model_data.seconds = 5;
    ev->output = sx_list1 (sym_tick);
    ev->then = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    ev->next = events;
    events = ev;
    return ev;
}

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

return_type: struct event { struct datetime { unsigned long long date; unsigned int time; } queue_time; long long repeat; enum event_model { em_seconds=0 } model; union { unsigned long long seconds; } model_data; unsigned long output; unsigned long then; struct event *next; } *

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


repo: kyuba/curie

decompiled_code:
void __fastcall event_add(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
char v3; // r13
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // r12

if ( (a1 & 1) == 0 && *(_DWORD *)a1 == 6 )
{
v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 16);
if ( equalp(v1, &sexpr_payload_sym_quit) == 29 )
{
cexit(0LL);
}
else
{
v3 = 0;
v4 = 1LL;
if ( equalp(v1, &sexpr_payload_sym_repeat) != 29 )
goto LABEL_6;
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
{
if ( equalp(69LL, &sexpr_payload_sym_indefinitely) != 29 )
{
v3 = 3;
v4 = -1LL;
if ( equalp(69LL, &sexpr_payload_sym_every) != 29 )
{
v2 = 69LL;
v1 = 69LL;
LABEL_7:
if ( equalp(v1, &sexpr_payload_sym_in) != 29 )
return;
if ( (v3 & 2) == 0 )
{
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
return;
v1 = *(_QWORD *)(v2 + 8);
v2 = *(_QWORD *)(v2 + 16);
}
LABEL_12:
if ( (v1 & 7) != 3 )
return;
v5 = get_event();
*(_QWORD *)(v5 + 16) = v4;
v6 = v5;
*(_QWORD *)(v5 + 32) = v1 >> 3;
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
{
if ( equalp(69LL, &sexpr_payload_sym_seconds) != 29 && equalp(69LL, &sexpr_payload_sym_second) != 29 )
{
v7 = 69LL;
v8 = 69LL;
equalp(69LL, &sexpr_payload_sym_s);
goto LABEL_18;
}
goto LABEL_33;
}
v8 = *(_QWORD *)(v2 + 8);
v7 = *(_QWORD *)(v2 + 16);
if ( equalp(v8, &sexpr_payload_sym_seconds) == 29
|| equalp(v8, &sexpr_payload_sym_second) == 29
|| equalp(v8, &sexpr_payload_sym_s) == 29 )
{
if ( (v7 & 1) != 0 || *(_DWORD *)v7 != 6 )
goto LABEL_33;
v8 = *(_QWORD *)(v7 + 8);
v7 = *(_QWORD *)(v7 + 16);
}
if ( v8 == 69 || equalp(v8, &sexpr_payload_sym_then) != 21 )
goto LABEL_18;
*(_QWORD *)(v6 + 40) = v8;
if ( (v7 & 1) == 0 && *(_DWORD *)v7 == 6 )
{
v8 = *(_QWORD *)(v7 + 8);
v7 = *(_QWORD *)(v7 + 16);
LABEL_18:
if ( equalp(v8, &sexpr_payload_sym_then) == 29 )
*(_QWORD *)(v6 + 48) = v7;
return;
}
LABEL_33:
v7 = 69LL;
v8 = 69LL;
goto LABEL_18;
}
goto LABEL_23;
}
LABEL_32:
equalp(69LL, &sexpr_payload_sym_every);
equalp(69LL, &sexpr_payload_sym_in);
return;
}
v1 = *(_QWORD *)(v2 + 8);
v2 = *(_QWORD *)(v2 + 16);
if ( (v1 & 7) == 3 )
{
v4 = (int)(v1 >> 3);
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
goto LABEL_32;
v1 = *(_QWORD *)(v2 + 8);
v3 = 1;
v2 = *(_QWORD *)(v2 + 16);
LABEL_6:
if ( equalp(v1, &sexpr_payload_sym_every) != 29 )
goto LABEL_7;
if ( (v2 & 1) == 0 && *(_DWORD *)v2 == 6 )
{
v1 = *(_QWORD *)(v2 + 8);
v2 = *(_QWORD *)(v2 + 16);
goto LABEL_24;
}
LABEL_23:
v1 = 69LL;
v2 = 69LL;
LABEL_24:
if ( (v3 & 1) == 0 )
v4 = -1LL;
equalp(v1, &sexpr_payload_sym_in);
goto LABEL_12;
}
}
if ( equalp(v1, &sexpr_payload_sym_indefinitely) == 29 )
{
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
goto LABEL_32;
v1 = *(_QWORD *)(v2 + 8);
v3 = 1;
v2 = *(_QWORD *)(v2 + 16);
v4 = -1LL;
}
else
{
v3 = 3;
v4 = -1LL;
}
goto LABEL_6;
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
char v3; // r13
__int64 v4; // r12
__int64 v5; // rax
__int64 v6; // r13
__int64 v7; // rbx
__int64 v8; // r12

if ( (a1 & 1) == 0 && *(_DWORD *)a1 == 6 )
{
v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 16);
if ( equalp(v1, &sexpr_payload_sym_quit) == 29 )
{
cexit(0LL);
}
else
{
v3 = 0;
v4 = 1LL;
if ( equalp(v1, &sexpr_payload_sym_repeat) != 29 )
goto LABEL_6;
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
{
if ( equalp(69LL, &sexpr_payload_sym_indefinitely) != 29 )
{
v3 = 3;
v4 = -1LL;
if ( equalp(69LL, &sexpr_payload_sym_every) != 29 )
{
v2 = 69LL;
v1 = 69LL;
LABEL_7:
if ( equalp(v1, &sexpr_payload_sym_in) != 29 )
return;
if ( (v3 & 2) == 0 )
{
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
return;
v1 = *(_QWORD *)(v2 + 8);
v2 = *(_QWORD *)(v2 + 16);
}
LABEL_12:
if ( (v1 & 7) != 3 )
return;
v5 = func3();
*(_QWORD *)(v5 + 16) = v4;
v6 = v5;
*(_QWORD *)(v5 + 32) = v1 >> 3;
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
{
if ( equalp(69LL, &sexpr_payload_sym_seconds) != 29 && equalp(69LL, &sexpr_payload_sym_second) != 29 )
{
v7 = 69LL;
v8 = 69LL;
equalp(69LL, &sexpr_payload_sym_s);
goto LABEL_18;
}
goto LABEL_33;
}
v8 = *(_QWORD *)(v2 + 8);
v7 = *(_QWORD *)(v2 + 16);
if ( equalp(v8, &sexpr_payload_sym_seconds) == 29
|| equalp(v8, &sexpr_payload_sym_second) == 29
|| equalp(v8, &sexpr_payload_sym_s) == 29 )
{
if ( (v7 & 1) != 0 || *(_DWORD *)v7 != 6 )
goto LABEL_33;
v8 = *(_QWORD *)(v7 + 8);
v7 = *(_QWORD *)(v7 + 16);
}
if ( v8 == 69 || equalp(v8, &sexpr_payload_sym_then) != 21 )
goto LABEL_18;
*(_QWORD *)(v6 + 40) = v8;
if ( (v7 & 1) == 0 && *(_DWORD *)v7 == 6 )
{
v8 = *(_QWORD *)(v7 + 8);
v7 = *(_QWORD *)(v7 + 16);
LABEL_18:
if ( equalp(v8, &sexpr_payload_sym_then) == 29 )
*(_QWORD *)(v6 + 48) = v7;
return;
}
LABEL_33:
v7 = 69LL;
v8 = 69LL;
goto LABEL_18;
}
goto LABEL_23;
}
LABEL_32:
equalp(69LL, &sexpr_payload_sym_every);
equalp(69LL, &sexpr_payload_sym_in);
return;
}
v1 = *(_QWORD *)(v2 + 8);
v2 = *(_QWORD *)(v2 + 16);
if ( (v1 & 7) == 3 )
{
v4 = (int)(v1 >> 3);
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
goto LABEL_32;
v1 = *(_QWORD *)(v2 + 8);
v3 = 1;
v2 = *(_QWORD *)(v2 + 16);
LABEL_6:
if ( equalp(v1, &sexpr_payload_sym_every) != 29 )
goto LABEL_7;
if ( (v2 & 1) == 0 && *(_DWORD *)v2 == 6 )
{
v1 = *(_QWORD *)(v2 + 8);
v2 = *(_QWORD *)(v2 + 16);
goto LABEL_24;
}
LABEL_23:
v1 = 69LL;
v2 = 69LL;
LABEL_24:
if ( (v3 & 1) == 0 )
v4 = -1LL;
equalp(v1, &sexpr_payload_sym_in);
goto LABEL_12;
}
}
if ( equalp(v1, &sexpr_payload_sym_indefinitely) == 29 )
{
if ( (v2 & 1) != 0 || *(_DWORD *)v2 != 6 )
goto LABEL_32;
v1 = *(_QWORD *)(v2 + 8);
v3 = 1;
v2 = *(_QWORD *)(v2 + 16);
v4 = -1LL;
}
else
{
v3 = 3;
v4 = -1LL;
}
goto LABEL_6;
}
}

original_code:
static void event_add (sexpr sx)
{
    struct event *ev;
    if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)sx))->type == sxt_cons)))
    {
        sexpr a = ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)sx))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)sx))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        sexpr c = ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)sx))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)sx))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        int repeat = 1;
        int stat = 0;
        if (((sexpr)(equalp (a, sym_quit)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            cexit (0);
        }
        if (((sexpr)(equalp (a, sym_repeat)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            repeat = -1;
            stat |= (1 << 0);
            if (((((int_pointer)(a)) & 0x7) == 0x3))
            {
                repeat = ((int_pointer_s)(a & (~0x7)) >> 3);
                a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            }
            else if (((sexpr)(equalp (a, sym_indefinitely)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                repeat = -1;
                a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            }
            else
            {
                stat |= (1 << 1);
            }
        }
        if (((sexpr)(equalp (a, sym_every)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            if (!(stat & (1 << 0)))
            {
                repeat = -1;
            }
            stat |= (1 << 2);
            stat |= (1 << 1);
        }
        if (((sexpr)(equalp (a, sym_in)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))) || (stat & (1 << 2)))
        {
            if (!(stat & (1 << 1)))
            {
                a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            }
            if (((((int_pointer)(a)) & 0x7) == 0x3))
            {
                ev = get_event ();
                ev->repeat = repeat;
                ev->model_data.seconds = ((int_pointer_s)(a & (~0x7)) >> 3);
                a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                if (((sexpr)(equalp (a, sym_seconds)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))) ||
                    ((sexpr)(equalp (a, sym_second)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))) ||
                    ((sexpr)(equalp (a, sym_s)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
                {
                    a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                    c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                }
                if (!((sexpr)(a) == ((sexpr)((((int_pointer)(8)) << 3) | 0x5))) && ((sexpr)(equalp (a, sym_then)) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
                {
                    ev->output = a;
                    a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                    c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                }
                if (((sexpr)(equalp (a, sym_then)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
                {
                    ev->then = c;
                }
            }
        }
    }
}

canonical_original_code:
static void event_add(unsigned long sx)
{
    struct event *ev;
    if ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)sx))->type == sxt_cons)))
    {
        unsigned long a = ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)sx))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)sx))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        unsigned long c = ((((((int_pointer)(sx)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)sx))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)sx))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        int repeat = 1;
        int stat = 0;
        if (((sexpr)(equalp (a, sym_quit)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            cexit (0);
        }
        if (((sexpr)(equalp (a, sym_repeat)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            repeat = -1;
            stat |= (1 << 0);
            if (((((int_pointer)(a)) & 0x7) == 0x3))
            {
                repeat = ((int_pointer_s)(a & (~0x7)) >> 3);
                a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            }
            else if (((sexpr)(equalp (a, sym_indefinitely)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                repeat = -1;
                a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            }
            else
            {
                stat |= (1 << 1);
            }
        }
        if (((sexpr)(equalp (a, sym_every)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            if (!(stat & (1 << 0)))
            {
                repeat = -1;
            }
            stat |= (1 << 2);
            stat |= (1 << 1);
        }
        if (((sexpr)(equalp (a, sym_in)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))) || (stat & (1 << 2)))
        {
            if (!(stat & (1 << 1)))
            {
                a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
            }
            if (((((int_pointer)(a)) & 0x7) == 0x3))
            {
                ev = get_event ();
                ev->repeat = repeat;
                ev->model_data.seconds = ((int_pointer_s)(a & (~0x7)) >> 3);
                a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                if (((sexpr)(equalp (a, sym_seconds)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))) ||
                    ((sexpr)(equalp (a, sym_second)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))) ||
                    ((sexpr)(equalp (a, sym_s)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
                {
                    a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                    c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                }
                if (!((sexpr)(a) == ((sexpr)((((int_pointer)(8)) << 3) | 0x5))) && ((sexpr)(equalp (a, sym_then)) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
                {
                    ev->output = a;
                    a = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                    c = ((((((int_pointer)(c)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)c))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)c))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
                }
                if (((sexpr)(equalp (a, sym_then)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
                {
                    ev->then = c;
                }
            }
        }
    }
}

variable_types:
sx
unsigned long

variable_types: struct event { struct datetime { unsigned long long date; unsigned int time; } queue_time; long long repeat; enum event_model { em_seconds=0 } model; union { unsigned long long seconds; } model_data; unsigned long output; unsigned long then; struct event *next; } *

variable_types:
a
unsigned long

variable_types:
c
unsigned long

variable_types: repeat int

variable_types: stat int

return_type: void

user_defined_types: struct event { struct datetime queue_time; long long repeat; enum event_model model; union { unsigned long long seconds; } model_data; unsigned long output; unsigned long then; struct event *next; }

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 }


decompiled_code:
__int64 event_queue()
{
unsigned __int64 v0; // r12
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rdx
unsigned __int64 v4; // r14
__int64 *v5; // r13
__int64 v6; // rax
unsigned __int64 v7; // rax

v0 = -1LL;
v1 = events;
v2 = dt_get();
v4 = dt_to_unix(v2, v3);
if ( !v1 )
return event_set_signal(v4, v0);
v5 = &events;
while ( 1 )
{
v6 = dt_to_unix(*(_QWORD *)v1, *(_QWORD *)(v1 + 8));
if ( !*(_DWORD *)(v1 + 24) )
break;
LABEL_7:
v5 = (__int64 *)(v1 + 56);
v1 = *(_QWORD *)(v1 + 56);
if ( !v1 )
return event_set_signal(v4, v0);
}
v7 = *(_QWORD *)(v1 + 32) + v6;
if ( v4 < v7 )
{
if ( v0 > v7 )
v0 = v7;
goto LABEL_7;
}
return event_dispatch(v1, v5, v7);
}

original_code:
static void event_queue ()
{
    struct event *e = events;
    struct event **p = &events;
    unsigned long long cts = dt_to_unix (dt_get ());
    unsigned long long nts = 0 - 1;
    while (e != (struct event *)0)
    {
        unsigned long long ts = dt_to_unix (e->queue_time);
        if (e->model == em_seconds)
        {
            ts += e->model_data.seconds;
            if (ts <= cts)
            {
                event_dispatch (e, p, ts);
                return;
            }
            else if (ts < nts)
            {
                nts = ts;
            }
        }
        p = &(e->next);
        e = e->next;
    }
    event_set_signal (cts, nts);
}

canonical_original_code:
static void event_queue()
{
    struct event *e = events;
    struct event **p = &events;
    unsigned long long cts = dt_to_unix (dt_get ());
    unsigned long long nts = 0 - 1;
    while (e != (struct event *)0)
    {
        unsigned long long ts = dt_to_unix (e->queue_time);
        if (e->model == em_seconds)
        {
            ts += e->model_data.seconds;
            if (ts <= cts)
            {
                event_dispatch (e, p, ts);
                return;
            }
            else if (ts < nts)
            {
                nts = ts;
            }
        }
        p = &(e->next);
        e = e->next;
    }
    event_set_signal (cts, nts);
}

variable_types: struct event { struct datetime { unsigned long long date; unsigned int time; } queue_time; long long repeat; enum event_model { em_seconds=0 } model; union { unsigned long long seconds; } model_data; unsigned long output; unsigned long then; struct event *next; } **

variable_types:
cts
unsigned long long

variable_types:
nts
unsigned long long

variable_types:
ts
unsigned long long


decompiled_code:
__int64 __fastcall event_dispatch(__int64 *a1, _QWORD *a2, __int64 a3)
{
__int64 v4; // r13
__int64 v5; // rax
__int64 v6; // rdi
__int64 v7; // rdx

v4 = a1[6];
v5 = dt_from_unix(a3);
v6 = a1[5];
*a1 = v5;
a1[1] = v7;
output(v6);
event_repeat((__int64)a1, a2);
if ( v4 != 45 )
event_add(v4);
return event_queue();
}

original_code:
static void event_dispatch
    (struct event *e, struct event **p, unsigned long long ts)
{
    sexpr t = e->then;
    e->queue_time = dt_from_unix (ts);
    output (e->output);
    event_repeat (e, p);
    if (!((sexpr)(t) == ((sexpr)((((int_pointer)(5)) << 3) | 0x5))))
    {
        event_add (t);
    }
    event_queue ();
}

canonical_original_code:
static void event_dispatch(struct event *e, struct event **p, unsigned long long ts)
{
    unsigned long t = e->then;
    e->queue_time = dt_from_unix (ts);
    output (e->output);
    event_repeat (e, p);
    if (!((sexpr)(t) == ((sexpr)((((int_pointer)(5)) << 3) | 0x5))))
    {
        event_add (t);
    }
    event_queue ();
}

variable_types:
p
struct event **

variable_types:
t
unsigned long

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


decompiled_code:
__int64 timer_signal()
{
event_queue();
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
func8();
return 0LL;
}

original_code:
static enum signal_callback_result timer_signal (enum signal signal, void *aux)
{
    event_queue ();
    return scr_keep;
}

canonical_original_code:
static enum signal_callback_result timer_signal(enum signal signal, void *aux)
{
    event_queue ();
    return scr_keep;
}

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

variable_types:
aux
void *

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


decompiled_code:
__int64 __fastcall event_set_signal(int a1, int a2)
{
return sys_alarm_isra_0(a2 - a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2)
{
return func6(a2 - a1);
}

original_code:
static void event_set_signal (unsigned long long cts, unsigned long long nts)
{
    sys_alarm (nts - cts);
}

canonical_original_code:
static void event_set_signal(unsigned long long cts, unsigned long long nts)
{
    sys_alarm (nts - cts);
}


decompiled_code:
__int64 __fastcall str_set_rx_memberp(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a1;
if ( !a1 )
return 0LL;
v3 = rx_compile(a2);
if ( !*a1 )
return 0LL;
while ( rx_match(v3) != 29 )
{
v4 = v2[1];
++v2;
if ( !v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v2 = a1;
if ( !a1 )
return 0LL;
v3 = rx_compile(a2);
if ( !*a1 )
return 0LL;
while ( rx_match(v3) != 29 )
{
v4 = v2[1];
++v2;
if ( !v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int str_set_rx_memberp (char **set, const char *regex)
{
    if (set != (char **)0)
    {
        sexpr rx = rx_compile (regex);
        while (*set != (char *)0)
        {
            if (((sexpr)(rx_match (rx, *set)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                return ~0;
            }
            set++;
        }
    }
    return 0;
}

canonical_original_code:
int str_set_rx_memberp(char **set, char *regex)
{
    if (set != (char **)0)
    {
        unsigned long rx = rx_compile (regex);
        while (*set != (char *)0)
        {
            if (((sexpr)(rx_match (rx, *set)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
            {
                return ~0;
            }
            set++;
        }
    }
    return 0;
}

variable_types:
set
char **

variable_types:
regex
char *

variable_types:
rx
unsigned long

return_type: int


fdset

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

result = a2 >> 5;
*(_DWORD *)(a1 + 4 * result) |= 1 << a2;
return result;
}

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

result = a2 >> 5;
*(_DWORD *)(a1 + 4 * result) |= 1 << a2;
return result;
}

original_code:
static void fdset(fdcell *c, int fd) {
    unsigned int cell = ((unsigned int)fd) / CELLSIZE,
                 cellbit = ((unsigned int)fd) % CELLSIZE;

    (*c)[cell] |= 1 << cellbit;
}

canonical_original_code:
static void fdset(unsigned int (*c)[-1], int fd) {
    unsigned int cell = ((unsigned int)fd) / CELLSIZE; unsigned int cellbit = ((unsigned int)fd) % CELLSIZE;

    (*c)[cell] |= 1 << cellbit;
}

variable_types:
c
unsigned int (*)[-1]

variable_types: fd int

variable_types:
cell
unsigned int

variable_types:
cellbit
unsigned int


fdisset

decompiled_code:
bool __fastcall fdisset(__int64 a1, unsigned int a2)
{
return (*(_DWORD *)(a1 + 4LL * (a2 >> 5)) & (1 << a2)) != 0;
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1, unsigned int a2)
{
return (*(_DWORD *)(a1 + 4LL * (a2 >> 5)) & (1 << a2)) != 0;
}

original_code:
static char fdisset(fdcell *c, int fd) {
    unsigned int cell = ((unsigned int)fd) / CELLSIZE,
                 cellbit = ((unsigned int)fd) % CELLSIZE;

    return (((*c)[cell]) & (1 << cellbit)) == 0 ? (char)0 : (char)1;
}

canonical_original_code:
static char fdisset(unsigned int (*c)[-1], int fd) {
    unsigned int cell = ((unsigned int)fd) / CELLSIZE; unsigned int cellbit = ((unsigned int)fd) % CELLSIZE;

    return (((*c)[cell]) & (1 << cellbit)) == 0 ? (char)0 : (char)1;
}

return_type: char


decompiled_code:
char __fastcall a_select_with_fds(__int64 a1, int a2, unsigned int *a3, int a4)
{
unsigned int *v6; // r9
unsigned int *v7; // r10
unsigned int *v8; // r11
int v9; // er8
unsigned int *v10; // r10
unsigned int *v11; // r11
int v12; // eax
_DWORD *v13; // r9
_DWORD *v14; // r8
_DWORD *v15; // r9
unsigned int *v16; // r8
fd_set v18; // [rsp+0h] [rbp-A8h] BYREF

fdzero(&v18);
if ( a2 > 0 )
{
v7 = v6;
do
fdset((__int64)&v18, *v7);
while ( v8 != v7 );
}
fdzero(&v18.fds_bits[8]);
if ( a4 > 0 )
{
v10 = a3;
do
fdset((__int64)&v18.fds_bits[8], *v10);
while ( v10 != v11 );
}
v12 = sys_select_constprop_0(v9 + 1, &v18, (fd_set *)&v18.fds_bits[8]);
if ( v12 <= 0 )
{
if ( a2 > 0 )
LOBYTE(v12) = (unsigned __int8)memset(v13, 255, 4LL * a2);
if ( a4 > 0 )
LOBYTE(v12) = (unsigned __int8)memset(a3, 255, 4LL * a4);
}
else
{
if ( a2 > 0 )
{
do
{
LOBYTE(v12) = fdisset((__int64)&v18, *v13);
if ( !(_BYTE)v12 )
*v15 = -1;
v13 = v15 + 1;
}
while ( v14 != v13 );
}
if ( a4 > 0 )
{
do
{
LOBYTE(v12) = fdisset((__int64)&v18.fds_bits[8], *a3);
if ( !(_BYTE)v12 )
*a3 = -1;
++a3;
}
while ( v16 != a3 );
}
}
return v12;
}

original_code:
void a_select_with_fds (int *rfds, int rnum, int *wfds, int wnum) {
    fdcell rset, wset;
    int highest = 0, r;
    int i;

    fdzero(&rset);

    for (i = 0; i < rnum; i++) {
        if (rfds[i] > highest) highest = rfds[i];
        fdset(&rset, rfds[i]);
    }

    fdzero(&wset);

    for (i = 0; i < wnum; i++) {
        if (wfds[i] > highest) highest = wfds[i];
        fdset(&wset, wfds[i]);
    }

#if defined(have_sys_newselect)
    r = sys_newselect(highest + 1, (void *)&rset, (void *)&wset, 0, 0);
#else
    /* actually, this probably wont work on most arches... */
    r = sys_select(highest + 1, (void *)&rset, (void *)&wset, 0, 0);
#endif

    if (r <= 0) {
        for (i = 0; i < rnum; i++) {
            rfds[i] = -1;
        }
        for (i = 0; i < wnum; i++) {
            wfds[i] = -1;
        }
    } else {
        for (i = 0; i < rnum; i++) {
            if (fdisset(&rset, rfds[i]) == (char)0) {
                rfds[i] = -1;
            }
        }
        for (i = 0; i < wnum; i++) {
            if (fdisset(&wset, wfds[i]) == (char)0) {
                wfds[i] = -1;
            }
        }
    }
}

canonical_original_code:
void a_select_with_fds(int *rfds, int rnum, int *wfds, int wnum) {
    unsigned int rset[-1]; unsigned int wset[-1];
    int highest = 0; int r;
    int i;

    fdzero(&rset);

    for (i = 0; i < rnum; i++) {
        if (rfds[i] > highest) highest = rfds[i];
        fdset(&rset, rfds[i]);
    }

    fdzero(&wset);

    for (i = 0; i < wnum; i++) {
        if (wfds[i] > highest) highest = wfds[i];
        fdset(&wset, wfds[i]);
    }

#if defined(have_sys_newselect)
    r = sys_newselect(highest + 1, (void *)&rset, (void *)&wset, 0, 0);
#else
    /* actually, this probably wont work on most arches... */
    r = sys_select(highest + 1, (void *)&rset, (void *)&wset, 0, 0);
#endif

    if (r <= 0) {
        for (i = 0; i < rnum; i++) {
            rfds[i] = -1;
        }
        for (i = 0; i < wnum; i++) {
            wfds[i] = -1;
        }
    } else {
        for (i = 0; i < rnum; i++) {
            if (fdisset(&rset, rfds[i]) == (char)0) {
                rfds[i] = -1;
            }
        }
        for (i = 0; i < wnum; i++) {
            if (fdisset(&wset, wfds[i]) == (char)0) {
                wfds[i] = -1;
            }
        }
    }
}

variable_types:
rfds
int *

variable_types: rnum int

variable_types:
wfds
int *

variable_types: wnum int

variable_types:
rset
unsigned int [-1]

variable_types:
wset
unsigned int [-1]

variable_types: highest int

variable_types: r int

variable_types: i int


ewhich

original_code:
sexpr ewhich (char **environment, sexpr programme)
{
    __extension__ static const struct sexpr_string_or_symbol sexpr_payload_str_slash = { sxt_string, "/" }; static const sexpr str_slash = ((const sexpr)&(sexpr_payload_str_slash));
    char *x = (char *)0, *y, buffer[4096];
    for (int i = 0; environment[i]; i++)
    {
        y = environment[i];
        if ((y[0] == 'P') && (y[1] == 'A') && (y[2] == 'T') && (y[3] == 'H') &&
            (y[4] == '='))
        {
            x = y + 5;
            break;
        }
    }
    if (x == (char *)0)
    {
        x = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
    }
    y = buffer;
    while (y < (buffer + 4096 - 1))
    {
        if ((*x == ':') || ((*x) == 0))
        {
            if (y != buffer)
            {
                *y = 0;
                y = buffer;
                sexpr b = make_string (buffer);
                sexpr f = sx_join (b, str_slash, programme);
                if (((sexpr)(filep (f)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
                {
                    return f;
                }
            }
            if ((*x) == 0)
            {
                return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
            }
        }
        else
        {
            *y = *x;
            y++;
        }
        x++;
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
unsigned long ewhich(char **environment, unsigned long programme)
{
    static struct sexpr_string_or_symbol sexpr_payload_str_slash = { sxt_string, "/" }; static unsigned long str_slash = ((const sexpr)&(sexpr_payload_str_slash));
    char *x = (char *)0; char *y; char buffer[4096];
    for (int i = 0; environment[i]; i++)
    {
        y = environment[i];
        if ((y[0] == 'P') && (y[1] == 'A') && (y[2] == 'T') && (y[3] == 'H') &&
            (y[4] == '='))
        {
            x = y + 5;
            break;
        }
    }
    if (x == (char *)0)
    {
        x = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
    }
    y = buffer;
    while (y < (buffer + 4096 - 1))
    {
        if ((*x == ':') || ((*x) == 0))
        {
            if (y != buffer)
            {
                *y = 0;
                y = buffer;
                unsigned long b = make_string (buffer);
                unsigned long f = sx_join (b, str_slash, programme);
                if (((sexpr)(filep (f)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
                {
                    return f;
                }
            }
            if ((*x) == 0)
            {
                return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
            }
        }
        else
        {
            *y = *x;
            y++;
        }
        x++;
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

variable_types:
environment
char **

variable_types:
programme
unsigned long

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

variable_types:
x
char *

variable_types:
y
char *

variable_types:
buffer
char [4096]

variable_types:
b
unsigned long

variable_types:
f
unsigned long

return_type: unsigned long

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


gcd

decompiled_code:
unsigned __int64 __fastcall gcd(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // r8

v2 = a1;
v3 = a2;
if ( !a2 )
return a1;
do
{
v4 = v3;
v3 = v2 % v3;
v2 = v4;
}
while ( v3 );
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(unsigned __int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // r8

v2 = a1;
v3 = a2;
if ( !a2 )
return a1;
do
{
v4 = v3;
v3 = v2 % v3;
v2 = v4;
}
while ( v3 );
return v4;
}

original_code:
int_64 gcd (int_64 a, int_64 b)
{
    int_64 t;
    while (b > 0)
    {
        t = b;
        b = a % b;
        a = t;
    }
    return a;
}

canonical_original_code:
unsigned long long gcd(unsigned long long a, unsigned long long b)
{
    unsigned long long t;
    while (b > 0)
    {
        t = b;
        b = a % b;
        a = t;
    }
    return a;
}

variable_types:
a
unsigned long long

variable_types:
b
unsigned long long

variable_types:
t
unsigned long long

return_type: unsigned long long


filep

decompiled_code:
__int64 __fastcall filep(_DWORD *a1)
{
const char *v1; // r8
__int64 v3; // [rsp+0h] [rbp-108h] BYREF

v1 = "#nonexistent";
if ( ((unsigned __int8)a1 & 1) == 0 && *a1 == 4 )
v1 = (const char *)(a1 + 1);
return (unsigned int)a_stat(v1, &v3) == 0 ? 29LL : 21LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
const char *v1; // r8
__int64 v3; // [rsp+0h] [rbp-108h] BYREF

v1 = "#nonexistent";
if ( ((unsigned __int8)a1 & 1) == 0 && *a1 == 4 )
v1 = (const char *)(a1 + 1);
return (unsigned int)a_stat(v1, &v3) == 0 ? 29LL : 21LL;
}

original_code:
sexpr filep(sexpr path)
{
    char stat_buffer[256];
    const char *p = (const char *)((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)path))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)path))->character_data) : "#nonexistent");
    return (a_stat(p, (void *)stat_buffer) == 0) ? ((sexpr)((((int_pointer)(3)) << 3) | 0x5)) : ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
unsigned long filep(unsigned long path)
{
    char stat_buffer[256];
    char *p = (const char *)((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)path))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)path))->character_data) : "#nonexistent");
    return (a_stat(p, (void *)stat_buffer) == 0) ? ((sexpr)((((int_pointer)(3)) << 3) | 0x5)) : ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

variable_types:
path
unsigned long

variable_types:
p
char *


linkp

decompiled_code:
__int64 __fastcall linkp(_DWORD *a1)
{
const char *v1; // r8
__int64 v3; // [rsp+0h] [rbp-108h] BYREF

v1 = "#nonexistent";
if ( ((unsigned __int8)a1 & 1) == 0 && *a1 == 4 )
v1 = (const char *)(a1 + 1);
return (unsigned int)a_lstat(v1, &v3) == 0 ? 29LL : 21LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
const char *v1; // r8
__int64 v3; // [rsp+0h] [rbp-108h] BYREF

v1 = "#nonexistent";
if ( ((unsigned __int8)a1 & 1) == 0 && *a1 == 4 )
v1 = (const char *)(a1 + 1);
return (unsigned int)a_lstat(v1, &v3) == 0 ? 29LL : 21LL;
}

original_code:
sexpr linkp(sexpr path)
{
    char stat_buffer[256];
    const char *p = (const char *)((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)path))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)path))->character_data) : "#nonexistent");
    return (a_lstat(p, (void *)stat_buffer) == 0) ? ((sexpr)((((int_pointer)(3)) << 3) | 0x5)) : ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
unsigned long linkp(unsigned long path)
{
    char stat_buffer[256];
    char *p = (const char *)((((((int_pointer)(path)) & 0x1) == 0x0) && (((struct sexpr_string_or_symbol *)((void *)path))->type == sxt_string)) ? (((struct sexpr_string_or_symbol *)((void *)path))->character_data) : "#nonexistent");
    return (a_lstat(p, (void *)stat_buffer) == 0) ? ((sexpr)((((int_pointer)(3)) << 3) | 0x5)) : ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}


decompiled_code:
void *__fastcall examine_error(int a1)
{
void *result; // rax

result = &last_error_recoverable_p;
last_error_recoverable_p = a1 == -11 || a1 == -4;
return result;
}

canonical_decompiled_code:
void *__fastcall func9(int a1)
{
void *result; // rax

result = &last_error_recoverable_p;
last_error_recoverable_p = a1 == -11 || a1 == -4;
return result;
}

original_code:
static void examine_error( int errno ) {
  switch (errno)
  {
    case -4 /*EINTR*/:
    case -11 /*EAGAIN*/:
      last_error_recoverable_p = (char)1;
      break;
    default:
      last_error_recoverable_p = (char)0;
  }
}

canonical_original_code:
static void examine_error(int errno) {
  switch (errno)
  {
    case -4 /*EINTR*/:
    case -11 /*EAGAIN*/:
      last_error_recoverable_p = (char)1;
      break;
    default:
      last_error_recoverable_p = (char)0;
  }
}

variable_types: errno int


decompiled_code:
__int64 __fastcall a_read(unsigned int a1, char *a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // [rsp+4h] [rbp-4h]

result = sys_read(a1, a2, a3);
if ( (int)result < 0 )
{
v4 = result;
examine_error(result);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, char *a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // [rsp+4h] [rbp-4h]

result = func0(a1, a2, a3);
if ( (int)result < 0 )
{
v4 = result;
func9(result);
result = v4;
}
return result;
}

original_code:
int    a_read (int fd, void *buf, unsigned int count)
{
    int rv = (int)sys_read(fd, buf, (signed long)count);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_read(int fd, void *buf, unsigned int count)
{
    int rv = (int)sys_read(fd, buf, (signed long)count);
    if (rv < 0) examine_error(rv);
    return rv;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
count
unsigned int

variable_types: rv int


decompiled_code:
__int64 __fastcall a_write(unsigned int a1, const char *a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // [rsp+4h] [rbp-4h]

result = sys_write(a1, a2, a3);
if ( (int)result < 0 )
{
v4 = result;
examine_error(result);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, const char *a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v4; // [rsp+4h] [rbp-4h]

result = func1(a1, a2, a3);
if ( (int)result < 0 )
{
v4 = result;
func9(result);
result = v4;
}
return result;
}

original_code:
int    a_write (int fd, const void *buf, unsigned int count)
{
    int rv = (int)sys_write(fd, (void *)buf, (signed long)count);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_write(int fd, void *buf, unsigned int count)
{
    int rv = (int)sys_write(fd, (void *)buf, (signed long)count);
    if (rv < 0) examine_error(rv);
    return rv;
}


decompiled_code:
signed __int64 __fastcall a_open_read(const char *a1)
{
signed __int64 result; // rax
signed __int64 v2; // [rsp+0h] [rbp-8h]

result = sys_open(a1, 2048, 365);
if ( (int)result < 0 )
{
v2 = result;
examine_error(result);
result = v2;
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func13(const char *a1)
{
signed __int64 result; // rax
signed __int64 v2; // [rsp+0h] [rbp-8h]

result = func2(a1, 2048, 365);
if ( (int)result < 0 )
{
v2 = result;
func9(result);
result = v2;
}
return result;
}

original_code:
int    a_open_read (const char *path)
{
    int rv = sys_open(path, 0x800 /*O_RDONLY | O_NONBLOCK*/, 0555);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_open_read(char *path)
{
    int rv = sys_open(path, 0x800 /*O_RDONLY | O_NONBLOCK*/, 0555);
    if (rv < 0) examine_error(rv);
    return rv;
}

variable_types:
path
char *


decompiled_code:
signed __int64 __fastcall a_open_write(const char *a1)
{
signed __int64 result; // rax
signed __int64 v2; // [rsp+0h] [rbp-8h]

result = sys_open(a1, 2113, 438);
if ( (int)result < 0 )
{
v2 = result;
examine_error(result);
result = v2;
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func14(const char *a1)
{
signed __int64 result; // rax
signed __int64 v2; // [rsp+0h] [rbp-8h]

result = func2(a1, 2113, 438);
if ( (int)result < 0 )
{
v2 = result;
func9(result);
result = v2;
}
return result;
}

original_code:
int    a_open_write (const char *path)
{
    int rv = sys_open(path, 0x841 /*O_WRONLY | O_NONBLOCK | O_CREAT*/, 0666);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_open_write(char *path)
{
    int rv = sys_open(path, 0x841 /*O_WRONLY | O_NONBLOCK | O_CREAT*/, 0666);
    if (rv < 0) examine_error(rv);
    return rv;
}


decompiled_code:
signed __int64 __fastcall a_create(const char *a1, int a2)
{
signed __int64 result; // rax
signed __int64 v3; // [rsp+0h] [rbp-8h]

result = sys_open(a1, 2113, a2);
if ( (int)result < 0 )
{
v3 = result;
examine_error(result);
result = v3;
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func15(const char *a1, int a2)
{
signed __int64 result; // rax
signed __int64 v3; // [rsp+0h] [rbp-8h]

result = func2(a1, 2113, a2);
if ( (int)result < 0 )
{
v3 = result;
func9(result);
result = v3;
}
return result;
}

original_code:
int    a_create (const char *path, int mode)
{
    int rv = sys_open(path, 0x841 /*O_WRONLY | O_NONBLOCK | O_CREAT*/, mode);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_create(char *path, int mode)
{
    int rv = sys_open(path, 0x841 /*O_WRONLY | O_NONBLOCK | O_CREAT*/, mode);
    if (rv < 0) examine_error(rv);
    return rv;
}

variable_types: mode int


decompiled_code:
__int64 __fastcall a_close(unsigned int fd)
{
unsigned int v2; // er8
int v3; // eax

do
{
v3 = sys_close(fd);
v2 = v3;
if ( v3 >= 0 )
break;
examine_error(v3);
}
while ( last_error_recoverable_p == 1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int fd)
{
unsigned int v2; // er8
int v3; // eax

do
{
v3 = func3(fd);
v2 = v3;
if ( v3 >= 0 )
break;
func9(v3);
}
while ( last_error_recoverable_p == 1 );
return v2;
}

original_code:
int    a_close (int fd)
{
    int rv = sys_close (fd);
    if (rv < 0) {
        examine_error(rv);

        if (last_error_recoverable_p == (char)1) return a_close (fd);
    }
    return rv;
}

canonical_original_code:
int a_close(int fd)
{
    int rv = sys_close (fd);
    if (rv < 0) {
        examine_error(rv);

        if (last_error_recoverable_p == (char)1) return a_close (fd);
    }
    return rv;
}


decompiled_code:
__int64 __fastcall a_dup(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // [rsp+0h] [rbp-8h]

result = sys_dup2(a1, a2);
if ( (int)result < 0 )
{
v3 = result;
examine_error(result);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // [rsp+0h] [rbp-8h]

result = func7(a1, a2);
if ( (int)result < 0 )
{
v3 = result;
func9(result);
result = v3;
}
return result;
}

original_code:
int    a_dup (int ofd, int nfd)
{
    int rv = sys_dup2 (ofd, nfd);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_dup(int ofd, int nfd)
{
    int rv = sys_dup2 (ofd, nfd);
    if (rv < 0) examine_error(rv);
    return rv;
}

variable_types: ofd int

variable_types: nfd int


decompiled_code:
__int64 __fastcall a_dup_n(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-8h]

result = sys_dup(a1);
if ( (int)result < 0 )
{
v2 = result;
examine_error(result);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-8h]

result = func6(a1);
if ( (int)result < 0 )
{
v2 = result;
func9(result);
result = v2;
}
return result;
}

original_code:
int    a_dup_n (int fd)
{
    int rv = sys_dup (fd);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_dup_n(int fd)
{
    int rv = sys_dup (fd);
    if (rv < 0) examine_error(rv);
    return rv;
}


decompiled_code:
__int64 __fastcall a_make_nonblocking(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-8h]

result = sys_fcntl_constprop_0(a1);
if ( (int)result < 0 )
{
v2 = result;
examine_error(result);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-8h]

result = func10(a1);
if ( (int)result < 0 )
{
v2 = result;
func9(result);
result = v2;
}
return result;
}

original_code:
int    a_make_nonblocking (int fd) {
    int rv = sys_fcntl(fd, 0x4 /*F_SETFL*/, 0x800 /*O_NONBLOCK*/);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_make_nonblocking(int fd) {
    int rv = sys_fcntl(fd, 0x4 /*F_SETFL*/, 0x800 /*O_NONBLOCK*/);
    if (rv < 0) examine_error(rv);
    return rv;
}


decompiled_code:
signed __int64 __fastcall a_unlink(const char *a1)
{
signed __int64 result; // rax
signed __int64 v2; // [rsp+0h] [rbp-8h]

result = sys_unlink(a1);
if ( (int)result < 0 )
{
v2 = result;
examine_error(result);
result = v2;
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func20(const char *a1)
{
signed __int64 result; // rax
signed __int64 v2; // [rsp+0h] [rbp-8h]

result = func8(a1);
if ( (int)result < 0 )
{
v2 = result;
func9(result);
result = v2;
}
return result;
}

original_code:
int    a_unlink (const char *path) {
    int rv = sys_unlink(path);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_unlink(char *path) {
    int rv = sys_unlink(path);
    if (rv < 0) examine_error(rv);
    return rv;
}


decompiled_code:
signed __int64 __fastcall a_stat(const char *a1, struct stat *a2)
{
signed __int64 result; // rax
signed __int64 v3; // [rsp+0h] [rbp-8h]

result = sys_stat(a1, a2);
if ( (int)result < 0 )
{
v3 = result;
examine_error(result);
result = v3;
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func21(const char *a1, struct stat *a2)
{
signed __int64 result; // rax
signed __int64 v3; // [rsp+0h] [rbp-8h]

result = func4(a1, a2);
if ( (int)result < 0 )
{
v3 = result;
func9(result);
result = v3;
}
return result;
}

original_code:
int a_stat(const char *path, void *buffer)
{
    int rv = sys_stat((char *)path, buffer);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_stat(char *path, void *buffer)
{
    int rv = sys_stat((char *)path, buffer);
    if (rv < 0) examine_error(rv);
    return rv;
}

variable_types:
buffer
void *


decompiled_code:
__int64 a_lstat()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-8h]

result = sys_lstat();
if ( (int)result < 0 )
{
v1 = result;
examine_error(result);
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func22()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-8h]

result = func5();
if ( (int)result < 0 )
{
v1 = result;
func9(result);
result = v1;
}
return result;
}

original_code:
int a_lstat(const char *path, void *buffer)
{
    int rv = sys_lstat((void *)path, buffer);
    if (rv < 0) examine_error(rv);
    return rv;
}

canonical_original_code:
int a_lstat(char *path, void *buffer)
{
    int rv = sys_lstat((void *)path, buffer);
    if (rv < 0) examine_error(rv);
    return rv;
}


decompiled_code:
__int64 __fastcall multiplex_add_sexpr(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v5; // rax
_DWORD *v6; // rdi
__int64 result; // rax

v5 = (_QWORD *)get_pool_mem(&pool_0);
v6 = *(_DWORD **)a1;
*v5 = a1;
v5[1] = a2;
v5[2] = a3;
if ( !v6 )
return multiplex_add_io(*(_QWORD *)(a1 + 8), 0LL, mx_on_close_out, v5);
if ( !*(_QWORD *)(a1 + 8) )
return multiplex_add_io(v6, mx_on_read, mx_on_close, v5);
if ( *v6 == -1 && (unsigned int)(v6[4] - 3) > 1 )
return multiplex_add_io(*(_QWORD *)(a1 + 8), 0LL, mx_on_close_out, v5);
result = multiplex_add_io(v6, mx_on_read, mx_on_close, v5);
if ( *(_QWORD *)a1 != *(_QWORD *)(a1 + 8) )
result = multiplex_add_io_no_callback();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v5; // rax
_DWORD *v6; // rdi
__int64 result; // rax

v5 = (_QWORD *)get_pool_mem(&pool_0);
v6 = *(_DWORD **)a1;
*v5 = a1;
v5[1] = a2;
v5[2] = a3;
if ( !v6 )
return multiplex_add_io(*(_QWORD *)(a1 + 8), 0LL, mx_on_close_out, v5);
if ( !*(_QWORD *)(a1 + 8) )
return multiplex_add_io(v6, mx_on_read, mx_on_close, v5);
if ( *v6 == -1 && (unsigned int)(v6[4] - 3) > 1 )
return multiplex_add_io(*(_QWORD *)(a1 + 8), 0LL, mx_on_close_out, v5);
result = multiplex_add_io(v6, mx_on_read, mx_on_close, v5);
if ( *(_QWORD *)a1 != *(_QWORD *)(a1 + 8) )
result = multiplex_add_io_no_callback();
return result;
}

original_code:
void multiplex_add_sexpr
        (struct sexpr_io *io, void (*on_read)(sexpr, struct sexpr_io *, void *),
         void *data)
{
    static struct memory_pool pool
            = { mpft_static_header, ((((unsigned long)sizeof (struct io_element)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct io_element)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct io_element))) ? ((unsigned short)8) : 0)) };
    struct io_element *element = get_pool_mem (&pool);
    element->io = io;
    element->on_read = on_read;
    element->data = data;
    if (io->in == (struct io *)0)
    {
        multiplex_add_io (io->out, (void *)0, mx_on_close_out, (void *)element);
    }
    else if (io->out == (struct io *)0)
    {
        multiplex_add_io (io->in, mx_on_read, mx_on_close, (void *)element);
    }
    else if (
        (io->in->fd == -1)
        && (io->in->type != iot_special_read)
        && (io->in->type != iot_special_write))
    {
        multiplex_add_io (io->out, (void *)0, mx_on_close_out, (void *)element);
    }
    else
    {
        multiplex_add_io (io->in, mx_on_read, mx_on_close, (void *)element);
        if (io->in != io->out)
        {
            multiplex_add_io_no_callback(io->out);
        }
    }
}

canonical_original_code:
void multiplex_add_sexpr(struct sexpr_io *io, void (*on_read)(unsigned long, struct sexpr_io *, void *), void *data)
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct io_element)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct io_element)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct io_element))) ? ((unsigned short)8) : 0)) };
    struct io_element *element = get_pool_mem (&pool);
    element->io = io;
    element->on_read = on_read;
    element->data = data;
    if (io->in == (struct io *)0)
    {
        multiplex_add_io (io->out, (void *)0, mx_on_close_out, (void *)element);
    }
    else if (io->out == (struct io *)0)
    {
        multiplex_add_io (io->in, mx_on_read, mx_on_close, (void *)element);
    }
    else if (
        (io->in->fd == -1)
        && (io->in->type != iot_special_read)
        && (io->in->type != iot_special_write))
    {
        multiplex_add_io (io->out, (void *)0, mx_on_close_out, (void *)element);
    }
    else
    {
        multiplex_add_io (io->in, mx_on_read, mx_on_close, (void *)element);
        if (io->in != io->out)
        {
            multiplex_add_io_no_callback(io->out);
        }
    }
}

variable_types: void (*)(unsigned long, struct sexpr_io *, void *)

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_element { 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; } *io; void (*on_read)(unsigned long, struct sexpr_io *, void *); void *data; } *

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

user_defined_types: struct io_element { struct sexpr_io *io; void (*on_read)(unsigned long, struct sexpr_io *, void *); void *data; }

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


decompiled_code:
__int64 __fastcall multiplex_del_sexpr(_QWORD *a1)
{
__int64 result; // rax

if ( *a1 )
*(_DWORD *)(*a1 + 20LL) = 1;
result = a1[1];
if ( result )
*(_DWORD *)(result + 20) = 1;
return result;
}

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

if ( *a1 )
*(_DWORD *)(*a1 + 20LL) = 1;
result = a1[1];
if ( result )
*(_DWORD *)(result + 20) = 1;
return result;
}

original_code:
void multiplex_del_sexpr (struct sexpr_io *io)
{
    if (io->in != (struct io *)0)
    {
        io->in->status = io_end_of_file;
    }
    if (io->out != (struct io *)0)
    {
        io->out->status = io_end_of_file;
    }
}

canonical_original_code:
void multiplex_del_sexpr(struct sexpr_io *io)
{
    if (io->in != (struct io *)0)
    {
        io->in->status = io_end_of_file;
    }
    if (io->out != (struct io *)0)
    {
        io->out->status = io_end_of_file;
    }
}

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


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

if ( !installed_1 )
{
result = multiplex_io();
installed_1 = 1;
}
return result;
}

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

if ( !installed_1 )
{
result = multiplex_io();
installed_1 = 1;
}
return result;
}

original_code:
void multiplex_sexpr ()
{
    static char installed = (char)0;
    if (installed == (char)0) {
        multiplex_io();
        installed = (char)1;
    }
}

canonical_original_code:
void multiplex_sexpr()
{
    static char installed = (char)0;
    if (installed == (char)0) {
        multiplex_io();
        installed = (char)1;
    }
}

variable_types: installed char


aalloc

decompiled_code:
__int64 __fastcall aalloc(unsigned __int64 a1)
{
unsigned __int64 v2; // rdi
__int64 result; // rax
int v4[4]; // [rsp+0h] [rbp-10h] BYREF

v2 = a1 & 0xFFFFFFFFFFFFFFF8LL;
if ( a1 <= 0x3FF )
{
if ( a1 != v2 )
LODWORD(v2) = v2 + 8;
v4[0] = 0;
v4[1] = v2;
result = get_pool_mem(v4);
}
else
{
if ( a1 != v2 )
v2 += 8LL;
result = get_mem(v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1)
{
unsigned __int64 v2; // rdi
__int64 result; // rax
int v4[4]; // [rsp+0h] [rbp-10h] BYREF

v2 = a1 & 0xFFFFFFFFFFFFFFF8LL;
if ( a1 <= 0x3FF )
{
if ( a1 != v2 )
LODWORD(v2) = v2 + 8;
v4[0] = 0;
v4[1] = v2;
result = get_pool_mem(v4);
}
else
{
if ( a1 != v2 )
v2 += 8LL;
result = get_mem(v2);
}
return result;
}

original_code:
void *aalloc (unsigned long size) {
    if (size < 0x400) {
        struct memory_pool pool = { mpft_static_header, ((((unsigned long)0) & ~(((unsigned short)8) - 1)) + (((((unsigned long)0) & ~(((unsigned short)8) - 1)) != ((unsigned long)0)) ? ((unsigned short)8) : 0)) };
        pool.entitysize = ((((unsigned long)size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)size) & ~(((unsigned short)8) - 1)) != ((unsigned long)size)) ? ((unsigned short)8) : 0));
        return get_pool_mem (&pool);
    } else {
        return get_mem (((((unsigned long)size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)size) & ~(((unsigned short)8) - 1)) != ((unsigned long)size)) ? ((unsigned short)8) : 0)));
    }
}

canonical_original_code:
void *aalloc(unsigned long size) {
    if (size < 0x400) {
        struct memory_pool pool = { mpft_static_header, ((((unsigned long)0) & ~(((unsigned short)8) - 1)) + (((((unsigned long)0) & ~(((unsigned short)8) - 1)) != ((unsigned long)0)) ? ((unsigned short)8) : 0)) };
        pool.entitysize = ((((unsigned long)size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)size) & ~(((unsigned short)8) - 1)) != ((unsigned long)size)) ? ((unsigned short)8) : 0));
        return get_pool_mem (&pool);
    } else {
        return get_mem (((((unsigned long)size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)size) & ~(((unsigned short)8) - 1)) != ((unsigned long)size)) ? ((unsigned short)8) : 0)));
    }
}

variable_types:
size
unsigned long

return_type: void *

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


afree

decompiled_code:
__int64 __fastcall afree(unsigned __int64 a1, __int64 a2)
{
if ( a1 <= 0x3FF )
return free_pool_mem(a2);
if ( (a1 & 0xFFFFFFFFFFFFFFF8LL) != a1 )
a1 = (a1 & 0xFFFFFFFFFFFFFFF8LL) + 8;
return free_mem(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, __int64 a2)
{
if ( a1 <= 0x3FF )
return free_pool_mem(a2);
if ( (a1 & 0xFFFFFFFFFFFFFFF8LL) != a1 )
a1 = (a1 & 0xFFFFFFFFFFFFFFF8LL) + 8;
return free_mem(a1);
}

original_code:
void afree (unsigned long size, void *p) {
    if (size < 0x400) {
        free_pool_mem (p);
    } else {
        free_mem (((((unsigned long)size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)size) & ~(((unsigned short)8) - 1)) != ((unsigned long)size)) ? ((unsigned short)8) : 0)), p);
    }
}

canonical_original_code:
void afree(unsigned long size, void *p) {
    if (size < 0x400) {
        free_pool_mem (p);
    } else {
        free_mem (((((unsigned long)size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)size) & ~(((unsigned short)8) - 1)) != ((unsigned long)size)) ? ((unsigned short)8) : 0)), p);
    }
}

variable_types:
p
void *


arealloc

decompiled_code:
__int64 __fastcall arealloc(unsigned __int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r12
unsigned __int64 v4; // rbp
__int64 v6; // r14
__int64 v7; // rax
unsigned __int64 v8; // r12
__int64 v9; // rdx

v3 = a3;
v4 = a1;
if ( (a1 & 0xFFFFFFFFFFFFFFF8LL) != a1 )
v4 = (a1 & 0xFFFFFFFFFFFFFFF8LL) + 8;
if ( (a3 & 0xFFFFFFFFFFFFFFF8LL) != a3 )
v3 = (a3 & 0xFFFFFFFFFFFFFFF8LL) + 8;
if ( v3 == v4 )
return a2;
if ( v4 > 0x3FF && v3 > 0x3FF )
return resize_mem(v4, a2, v3);
v6 = aalloc(v3);
if ( v6 )
{
if ( v3 > v4 )
LODWORD(v3) = v4;
v7 = 0LL;
v8 = (unsigned __int64)(int)v3 >> 2;
if ( (int)v8 > 0 )
{
do
{
*(_DWORD *)(v6 + 4 * v7) = *(_DWORD *)(a2 + 4 * v7);
v9 = v7++;
}
while ( v9 != (_DWORD)v8 - 1 );
}
}
afree(v4, a2);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // r12
unsigned __int64 v4; // rbp
__int64 v6; // r14
__int64 v7; // rax
unsigned __int64 v8; // r12
__int64 v9; // rdx

v3 = a3;
v4 = a1;
if ( (a1 & 0xFFFFFFFFFFFFFFF8LL) != a1 )
v4 = (a1 & 0xFFFFFFFFFFFFFFF8LL) + 8;
if ( (a3 & 0xFFFFFFFFFFFFFFF8LL) != a3 )
v3 = (a3 & 0xFFFFFFFFFFFFFFF8LL) + 8;
if ( v3 == v4 )
return a2;
if ( v4 > 0x3FF && v3 > 0x3FF )
return resize_mem(v4, a2, v3);
v6 = func0(v3);
if ( v6 )
{
if ( v3 > v4 )
LODWORD(v3) = v4;
v7 = 0LL;
v8 = (unsigned __int64)(int)v3 >> 2;
if ( (int)v8 > 0 )
{
do
{
*(_DWORD *)(v6 + 4 * v7) = *(_DWORD *)(a2 + 4 * v7);
v9 = v7++;
}
while ( v9 != (_DWORD)v8 - 1 );
}
}
func1(v4, a2);
return v6;
}

original_code:
void *arealloc (unsigned long size, void *p, unsigned long new_size) {
    unsigned long msize = ((((unsigned long)size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)size) & ~(((unsigned short)8) - 1)) != ((unsigned long)size)) ? ((unsigned short)8) : 0));
    unsigned long mnew_size = ((((unsigned long)new_size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)new_size) & ~(((unsigned short)8) - 1)) != ((unsigned long)new_size)) ? ((unsigned short)8) : 0));
    if (msize != mnew_size) {
        if ((msize >= 0x400) &&
            (mnew_size >= 0x400)) {
            return resize_mem (msize, p, mnew_size);
        } else {
            unsigned int *new_location = (unsigned int *)aalloc(mnew_size);
            if (new_location == (unsigned int *)0)
            {
                afree (msize, p);
                return (void *)0;
            }
            else
            {
                unsigned int *old_location = (unsigned int *)p;
                int copysize = (int)((msize < mnew_size) ? msize : mnew_size);
                int i = 0;
                copysize = (int)((copysize / sizeof(int))
                        + (((copysize % sizeof(int)) == 0) ? 0 : 1));
                for(i = 0; i < copysize; i++) {
                    new_location[i] = old_location[i];
                }
                afree (msize, p);
                return (void*)new_location;
            }
        }
    }
    return p;
}

canonical_original_code:
void *arealloc(unsigned long size, void *p, unsigned long new_size) {
    unsigned long msize = ((((unsigned long)size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)size) & ~(((unsigned short)8) - 1)) != ((unsigned long)size)) ? ((unsigned short)8) : 0));
    unsigned long mnew_size = ((((unsigned long)new_size) & ~(((unsigned short)8) - 1)) + (((((unsigned long)new_size) & ~(((unsigned short)8) - 1)) != ((unsigned long)new_size)) ? ((unsigned short)8) : 0));
    if (msize != mnew_size) {
        if ((msize >= 0x400) &&
            (mnew_size >= 0x400)) {
            return resize_mem (msize, p, mnew_size);
        } else {
            unsigned int *new_location = (unsigned int *)aalloc(mnew_size);
            if (new_location == (unsigned int *)0)
            {
                afree (msize, p);
                return (void *)0;
            }
            else
            {
                unsigned int *old_location = (unsigned int *)p;
                int copysize = (int)((msize < mnew_size) ? msize : mnew_size);
                int i = 0;
                copysize = (int)((copysize / sizeof(int))
                        + (((copysize % sizeof(int)) == 0) ? 0 : 1));
                for(i = 0; i < copysize; i++) {
                    new_location[i] = old_location[i];
                }
                afree (msize, p);
                return (void *)new_location;
            }
        }
    }
    return p;
}

variable_types:
msize
unsigned long

variable_types: copysize int

variable_types: i int


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

result = (_QWORD *)get_pool_mem(&pool_0);
*result = 0LL;
return result;
}

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

result = (_QWORD *)get_pool_mem(&pool_0);
*result = 0LL;
return result;
}

original_code:
struct tree * tree_create ()
{
    static struct memory_pool pool
            = { mpft_static_header, ((((unsigned long)sizeof (struct tree)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct tree)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct tree))) ? ((unsigned short)8) : 0)) };
    struct tree *tree = (struct tree *)get_pool_mem(&pool);
    tree->root = (struct tree_node *)0;
    return tree;
}

canonical_original_code:
struct tree *tree_create()
{
    static struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof (struct tree)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof (struct tree)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof (struct tree))) ? ((unsigned short)8) : 0)) };
    struct tree *tree = (struct tree *)get_pool_mem(&pool);
    tree->root = (struct tree_node *)0;
    return tree;
}

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


decompiled_code:
void mx_read()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void mx_read (struct io *io, void *aux)
{
}

canonical_original_code:
static void mx_read(struct io *io, void *aux)
{
}

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

variable_types:
aux
void *


original_code:
static void mx_close (struct io *io, void *aux)
{
    struct io_get_file_data *d = (struct io_get_file_data *)aux;
    void *buffer = io->buffer;
    buffer = resize_mem (io->buffersize, buffer, io->length);
    io->buffersize = 0;
    io->buffer = (void *)0;
    d->on_file_read (buffer, io->length, d->aux);
    free_pool_mem (aux);
}

canonical_original_code:
static void mx_close(struct io *io, void *aux)
{
    struct io_get_file_data *d = (struct io_get_file_data *)aux;
    void *buffer = io->buffer;
    buffer = resize_mem (io->buffersize, buffer, io->length);
    io->buffersize = 0;
    io->buffer = (void *)0;
    d->on_file_read (buffer, io->length, d->aux);
    free_pool_mem (aux);
}

variable_types: struct io_get_file_data { void (*on_file_read)(void *, unsigned int, void *); void *aux; } *

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

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


decompiled_code:
__int64 __fastcall io_get_file_contents(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
_QWORD *v5; // rax
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = io_open_read();
v7[0] = 0x1000000000LL;
v5 = (_QWORD *)get_pool_mem(v7);
*v5 = a2;
v5[1] = a3;
return multiplex_add_io(v4, mx_read, mx_close, v5);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbp
_QWORD *v5; // rax
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = io_open_read();
v7[0] = 0x1000000000LL;
v5 = (_QWORD *)get_pool_mem(v7);
*v5 = a2;
v5[1] = a3;
return multiplex_add_io(v4, mx_read, mx_close, v5);
}

original_code:
void io_get_file_contents
    (const char *path, void (*on_file_read)(void *, unsigned int, void *),
     void *aux)
{
    struct io *io = io_open_read (path);
    struct memory_pool pool =
        { mpft_static_header, ((((unsigned long)sizeof(struct io_get_file_data)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof(struct io_get_file_data)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof(struct io_get_file_data))) ? ((unsigned short)8) : 0)) };
    struct io_get_file_data *d = get_pool_mem (&pool);
    d->on_file_read = on_file_read;
    d->aux = aux;
    multiplex_add_io (io, mx_read, mx_close, (void *)d);
}

canonical_original_code:
void io_get_file_contents(char *path, void (*on_file_read)(void *, unsigned int, void *), void *aux)
{
    struct io *io = io_open_read (path);
    struct memory_pool pool = { mpft_static_header, ((((unsigned long)sizeof(struct io_get_file_data)) & ~(((unsigned short)8) - 1)) + (((((unsigned long)sizeof(struct io_get_file_data)) & ~(((unsigned short)8) - 1)) != ((unsigned long)sizeof(struct io_get_file_data))) ? ((unsigned short)8) : 0)) };
    struct io_get_file_data *d = get_pool_mem (&pool);
    d->on_file_read = on_file_read;
    d->aux = aux;
    multiplex_add_io (io, mx_read, mx_close, (void *)d);
}

variable_types:
path
char *

user_defined_types: struct io_get_file_data { void (*on_file_read)(void *, unsigned int, void *); void *aux; }


decompiled_code:
__int64 __fastcall sx_set_rx_memberp(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 i; // rbp
__int64 result; // rax

v2 = a1;
for ( i = rx_compile_sx(a2); (v2 & 1) == 0; v2 = *(_QWORD *)(v2 + 16) )
{
if ( *(_DWORD *)v2 != 6 )
break;
result = rx_match_sx(i, *(_QWORD *)(v2 + 8));
if ( result == 29 )
return result;
if ( *(_DWORD *)v2 != 6 )
break;
}
return 21LL;
}

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

v2 = a1;
for ( i = rx_compile_sx(a2); (v2 & 1) == 0; v2 = *(_QWORD *)(v2 + 16) )
{
if ( *(_DWORD *)v2 != 6 )
break;
result = rx_match_sx(i, *(_QWORD *)(v2 + 8));
if ( result == 29 )
return result;
if ( *(_DWORD *)v2 != 6 )
break;
}
return 21LL;
}

original_code:
sexpr sx_set_rx_memberp (sexpr set, sexpr regex)
{
    regex = rx_compile_sx (regex);
    while ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)))
    {
        if (((sexpr)(rx_match_sx (regex, ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)set))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))))) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
        }
        set = ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)set))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

canonical_original_code:
unsigned long sx_set_rx_memberp(unsigned long set, unsigned long regex)
{
    regex = rx_compile_sx (regex);
    while ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)))
    {
        if (((sexpr)(rx_match_sx (regex, ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)set))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))))) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return ((sexpr)((((int_pointer)(3)) << 3) | 0x5));
        }
        set = ((((((int_pointer)(set)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)set))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)set))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return ((sexpr)((((int_pointer)(2)) << 3) | 0x5));
}

variable_types:
set
unsigned long

variable_types:
regex
unsigned long


decompiled_code:
__int64 __fastcall create_memory_pool(int a1)
{
__int64 result; // rax
unsigned int v2; // ecx
unsigned int v3; // ecx

result = get_mem_chunk();
v2 = a1 & 0xFFFFFFF8;
if ( (a1 & 7) != 0 )
{
v3 = v2 + 8;
*(_DWORD *)(result + 4) = v3;
*(_DWORD *)(result + 88) = -1;
*(_OWORD *)(result + 24) = -1LL;
*(_OWORD *)(result + 40) = -1LL;
*(_OWORD *)(result + 56) = -1LL;
*(_OWORD *)(result + 72) = -1LL;
*(_WORD *)(result + 8) = 0xFA0 / v3;
}
else
{
*(_DWORD *)(result + 4) = v2;
*(_DWORD *)(result + 88) = -1;
*(_OWORD *)(result + 24) = -1LL;
*(_OWORD *)(result + 40) = -1LL;
*(_OWORD *)(result + 56) = -1LL;
*(_OWORD *)(result + 72) = -1LL;
*(_WORD *)(result + 8) = 0xFA0 / v2;
if ( 0xFA0 / v2 > 0x200 )
*(_WORD *)(result + 8) = 512;
}
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)result = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
unsigned int v2; // ecx
unsigned int v3; // ecx

result = get_mem_chunk();
v2 = a1 & 0xFFFFFFF8;
if ( (a1 & 7) != 0 )
{
v3 = v2 + 8;
*(_DWORD *)(result + 4) = v3;
*(_DWORD *)(result + 88) = -1;
*(_OWORD *)(result + 24) = -1LL;
*(_OWORD *)(result + 40) = -1LL;
*(_OWORD *)(result + 56) = -1LL;
*(_OWORD *)(result + 72) = -1LL;
*(_WORD *)(result + 8) = 0xFA0 / v3;
}
else
{
*(_DWORD *)(result + 4) = v2;
*(_DWORD *)(result + 88) = -1;
*(_OWORD *)(result + 24) = -1LL;
*(_OWORD *)(result + 40) = -1LL;
*(_OWORD *)(result + 56) = -1LL;
*(_OWORD *)(result + 72) = -1LL;
*(_WORD *)(result + 8) = 0xFA0 / v2;
if ( 0xFA0 / v2 > 0x200 )
*(_WORD *)(result + 8) = 512;
}
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)result = 1;
return result;
}

original_code:
struct memory_pool *create_memory_pool (unsigned long int entitysize)
{
    struct memory_pool_frame_header *pool = get_mem_chunk();
    unsigned int i;
    pool->entitysize = ((((unsigned long)entitysize) & ~(((unsigned short)8) - 1)) + (((((unsigned long)entitysize) & ~(((unsigned short)8) - 1)) != ((unsigned long)entitysize)) ? ((unsigned short)8) : 0));
    pool->maxentities = (unsigned short)((0x1000 - sizeof(struct memory_pool_frame_header)) / pool->entitysize);
    for (i = 0; i <= (unsigned short)16; i++) {
        pool->map[i] = (int_32)~0;
    }
    if (pool->maxentities > (unsigned short)((unsigned short)16 * (unsigned short)(32))) pool->maxentities = (unsigned short)((unsigned short)16 * (unsigned short)(32));
    pool->next = (struct memory_pool_frame_header *)0;
    pool->type = mpft_frame;
    return (struct memory_pool *)pool;
}

canonical_original_code:
struct memory_pool *create_memory_pool(unsigned long entitysize)
{
    struct memory_pool_frame_header *pool = get_mem_chunk();
    unsigned int i;
    pool->entitysize = ((((unsigned long)entitysize) & ~(((unsigned short)8) - 1)) + (((((unsigned long)entitysize) & ~(((unsigned short)8) - 1)) != ((unsigned long)entitysize)) ? ((unsigned short)8) : 0));
    pool->maxentities = (unsigned short)((0x1000 - sizeof(struct memory_pool_frame_header)) / pool->entitysize);
    for (i = 0; i <= (unsigned short)16; i++) {
        pool->map[i] = (unsigned int)~0;
    }
    if (pool->maxentities > (unsigned short)((unsigned short)16 * (unsigned short)(32))) pool->maxentities = (unsigned short)((unsigned short)16 * (unsigned short)(32));
    pool->next = (struct memory_pool_frame_header *)0;
    pool->type = mpft_frame;
    return (struct memory_pool *)pool;
}

variable_types:
entitysize
unsigned long

variable_types: struct memory_pool_frame_header { enum memory_pool_frame_type { mpft_static_header=0, mpft_frame=1 } type; unsigned int entitysize; unsigned short maxentities; struct memory_pool_frame_header *next; unsigned int map[-1]; } *

variable_types:
i
unsigned int

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

user_defined_types: struct memory_pool_frame_header { enum memory_pool_frame_type type; unsigned int entitysize; unsigned short maxentities; struct memory_pool_frame_header *next; unsigned int map[-1]; }


variable_types:
frame
struct memory_pool_frame_header *

variable_types:
x
unsigned int

variable_types:
cell
unsigned int

variable_types:
index
unsigned int


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

if ( *(_DWORD *)a1 == 1 )
{
if ( *(_QWORD *)(a1 + 16) )
free_memory_pool();
result = free_mem(4096LL, a1);
}
return result;
}

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

if ( *(_DWORD *)a1 == 1 )
{
if ( *(_QWORD *)(a1 + 16) )
func2();
result = free_mem(4096LL, a1);
}
return result;
}

original_code:
void free_memory_pool (struct memory_pool *pool)
{
    if (pool->type == mpft_frame)
    {
        struct memory_pool_frame_header *h
            = (struct memory_pool_frame_header *)pool;
        if (h->next != ((void *)0))
            free_memory_pool ((struct memory_pool *)h->next);
        free_mem(0x1000, (struct memory_pool *)pool);
    }
}

canonical_original_code:
void free_memory_pool(struct memory_pool *pool)
{
    if (pool->type == mpft_frame)
    {
        struct memory_pool_frame_header *h = (struct memory_pool_frame_header *)pool;
        if (h->next != ((void *)0))
            free_memory_pool ((struct memory_pool *)h->next);
        free_mem(0x1000, (struct memory_pool *)pool);
    }
}

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


decompiled_code:
__int64 __fastcall get_pool_mem(_DWORD *a1)
{
__int64 result; // rax
unsigned int v2; // eax
__int64 v3; // rbx
__int64 v4; // rdi
__int64 v5; // rax

if ( *a1 )
{
if ( *a1 == 1 )
result = get_pool_mem_inner((__int64)a1, (__int64)a1);
else
result = 0LL;
}
else
{
v2 = a1[1];
v3 = (unsigned __int16)((v2 >> 3) - 1);
v4 = static_pools[v3];
if ( v4 )
{
result = get_pool_mem_inner(v4, v4);
}
else
{
v5 = create_memory_pool(v2);
static_pools[v3] = v5;
result = get_pool_mem_inner(v5, v5);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
__int64 result; // rax
unsigned int v2; // eax
__int64 v3; // rbx
__int64 v4; // rdi
__int64 v5; // rax

if ( *a1 )
{
if ( *a1 == 1 )
result = func1((__int64)a1, (__int64)a1);
else
result = 0LL;
}
else
{
v2 = a1[1];
v3 = (unsigned __int16)((v2 >> 3) - 1);
v4 = static_pools[v3];
if ( v4 )
{
result = func1(v4, v4);
}
else
{
v5 = func0(v2);
static_pools[v3] = v5;
result = func1(v5, v5);
}
}
return result;
}

original_code:
void *get_pool_mem(struct memory_pool *pool)
{
    switch (pool->type)
    {
        case mpft_static_header:
        {
            unsigned short r = (pool->entitysize / ((unsigned short)8)) - 1;
            if (static_pools[r] == (struct memory_pool *)0)
            {
                static_pools[r] = create_memory_pool(pool->entitysize);
            }
            return get_pool_mem_inner
                    ((struct memory_pool_frame_header *)static_pools[r],
                     (struct memory_pool_frame_header *)static_pools[r]);
        }
        case mpft_frame:
            return get_pool_mem_inner((struct memory_pool_frame_header *)pool,
                                      (struct memory_pool_frame_header *)pool);
    }
    return (void *)0;
}

variable_types:
r
unsigned short


decompiled_code:
__int64 __fastcall free_pool_mem(__int64 a1)
{
unsigned __int64 v1; // rsi
__int64 result; // rax

v1 = a1 & 0xFFFFFFFFFFFFF000LL;
result = (__int64)(a1 - ((a1 & 0xFFFFFFFFFFFFF000LL) + 96)) / *(unsigned int *)((a1 & 0xFFFFFFFFFFFFF000LL) + 4);
*(_DWORD *)(v1 + 4LL * ((unsigned int)result >> 5) + 24) |= 1 << result;
*(_DWORD *)(v1 + 88) |= 1 << ((unsigned int)result >> 5);
return result;
}

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

v1 = a1 & 0xFFFFFFFFFFFFF000LL;
result = (__int64)(a1 - ((a1 & 0xFFFFFFFFFFFFF000LL) + 96)) / *(unsigned int *)((a1 & 0xFFFFFFFFFFFFF000LL) + 4);
*(_DWORD *)(v1 + 4LL * ((unsigned int)result >> 5) + 24) |= 1 << result;
*(_DWORD *)(v1 + 88) |= 1 << ((unsigned int)result >> 5);
return result;
}

original_code:
void free_pool_mem(void *mem)
{
    struct memory_pool_frame_header *pool = (struct memory_pool_frame_header *)((((int_pointer)(((int_pointer)mem)) / 0x1000)) * 0x1000);
    char *pool_mem_start = (char *)pool + sizeof(struct memory_pool_frame_header);
    unsigned int index = (unsigned int)(((char*)mem - pool_mem_start) / pool->entitysize);
    unsigned int cell = ((unsigned int)((index) / (unsigned short)(32)));
    pool->map[cell] |= (1 << (index%(unsigned short)(32)));
    pool->map[(unsigned short)16] |= ((int_32)(1 << cell));
}

variable_types:
mem
void *


original_code:
void optimise_memory_pool(struct memory_pool *pool)
{
    struct memory_pool_frame_header
        *cursor = (struct memory_pool_frame_header *)pool,
        *last = (struct memory_pool_frame_header *)0;
    unsigned int i;
    if (cursor->type != mpft_frame) return;
    while ((cursor != (struct memory_pool_frame_header *)0) &&
           (cursor->next != (struct memory_pool_frame_header *)0))
    {
        last = cursor;
        cursor = cursor->next;
        for (i = 0; i < (unsigned short)16; i++)
        {
            if (cursor->map[i] != ((int_32)~0)) break;
        }
        if (i == (unsigned short)16)
        {
            last->next = cursor->next;
            free_mem(0x1000, (void *)cursor);
            cursor = last;
        }
    }
}

canonical_original_code:
void optimise_memory_pool(struct memory_pool *pool)
{
    struct memory_pool_frame_header *cursor = (struct memory_pool_frame_header *)pool; struct memory_pool_frame_header *last = (struct memory_pool_frame_header *)0;
    unsigned int i;
    if (cursor->type != mpft_frame) return;
    while ((cursor != (struct memory_pool_frame_header *)0) &&
           (cursor->next != (struct memory_pool_frame_header *)0))
    {
        last = cursor;
        cursor = cursor->next;
        for (i = 0; i < (unsigned short)16; i++)
        {
            if (cursor->map[i] != ((unsigned int)~0)) break;
        }
        if (i == (unsigned short)16)
        {
            last->next = cursor->next;
            free_mem(0x1000, (void *)cursor);
            cursor = last;
        }
    }
}


decompiled_code:
void optimise_static_memory_pools()
{
__int64 *v0; // rbx
__int64 v1; // rsi
_DWORD *v2; // rax

v0 = static_pools;
do
{
LABEL_3:
if ( *v0 )
{
optimise_memory_pool((_DWORD *)*v0);
v1 = *v0;
if ( *v0 )
{
LABEL_5:
v2 = (_DWORD *)(v1 + 24);
while ( *v2 == -1 )
{
if ( ++v2 == (_DWORD *)(v1 + 88) )
{
*v0 = *(_QWORD *)(v1 + 16);
free_mem(4096LL, v1);
v1 = *v0;
if ( *v0 )
goto LABEL_5;
if ( ++v0 != (__int64 *)&unk_13A0 )
goto LABEL_3;
return;
}
}
}
}
++v0;
}
while ( v0 != (__int64 *)&unk_13A0 );
}

original_code:
void optimise_static_memory_pools()
{
    unsigned int i;
    for (i = 0; i < (0x1000 / ((unsigned short)8)); i++)
    {
        if (static_pools[i] != (struct memory_pool *)0)
        {
            struct memory_pool_frame_header *h;
            optimise_memory_pool (static_pools[i]);
            for (h = (struct memory_pool_frame_header *)(static_pools[i]);
                 h != (struct memory_pool_frame_header *)0;)
            {
                unsigned int j;
                for (j = 0; j < (unsigned short)16; j++)
                {
                    if (h->map[j] != ((int_32)~0)) break;
                }
                if (j == (unsigned short)16)
                {
                    static_pools[i] = (struct memory_pool *)h->next;
                    free_mem(0x1000, (void *)h);
                    h = (struct memory_pool_frame_header *)(static_pools[i]);
                }
                else
                {
                    h = (struct memory_pool_frame_header *)0;
                }
            }
        }
    }
}

canonical_original_code:
void optimise_static_memory_pools()
{
    unsigned int i;
    for (i = 0; i < (0x1000 / ((unsigned short)8)); i++)
    {
        if (static_pools[i] != (struct memory_pool *)0)
        {
            struct memory_pool_frame_header *h;
            optimise_memory_pool (static_pools[i]);
            for (h = (struct memory_pool_frame_header *)(static_pools[i]);
                 h != (struct memory_pool_frame_header *)0;)
            {
                unsigned int j;
                for (j = 0; j < (unsigned short)16; j++)
                {
                    if (h->map[j] != ((unsigned int)~0)) break;
                }
                if (j == (unsigned short)16)
                {
                    static_pools[i] = (struct memory_pool *)h->next;
                    free_mem(0x1000, (void *)h);
                    h = (struct memory_pool_frame_header *)(static_pools[i]);
                }
                else
                {
                    h = (struct memory_pool_frame_header *)0;
                }
            }
        }
    }
}

variable_types:
j
unsigned int


original_code:
sexpr sx_alist_get (sexpr alist, sexpr key)
{
    while ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)))
    {
        sexpr a = ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        if (((sexpr)(equalp (((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), key)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
        alist = ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return ((sexpr)((((int_pointer)(8)) << 3) | 0x5));
}

canonical_original_code:
unsigned long sx_alist_get(unsigned long alist, unsigned long key)
{
    while ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)))
    {
        unsigned long a = ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        if (((sexpr)(equalp (((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), key)) == ((sexpr)((((int_pointer)(3)) << 3) | 0x5))))
        {
            return ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        }
        alist = ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return ((sexpr)((((int_pointer)(8)) << 3) | 0x5));
}

variable_types:
alist
unsigned long

variable_types:
key
unsigned long

variable_types:
a
unsigned long


decompiled_code:
__int64 __fastcall sx_alist_add(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rax

v3 = cons(a2, a3);
return cons(v3, a1);
}

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

v3 = cons(a2, a3);
return cons(v3, a1);
}

original_code:
sexpr sx_alist_add (sexpr alist, sexpr key, sexpr value)
{
    return cons (cons (key, value), alist);
}

canonical_original_code:
unsigned long sx_alist_add(unsigned long alist, unsigned long key, unsigned long value)
{
    return cons (cons (key, value), alist);
}

variable_types:
value
unsigned long


original_code:
sexpr sx_alist_remove (sexpr alist, sexpr key)
{
    sexpr r = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    while ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)))
    {
        sexpr a = ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        if (((sexpr)(equalp (((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), key)) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
        {
            r = cons (a, r);
        }
        alist = ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return r;
}

canonical_original_code:
unsigned long sx_alist_remove(unsigned long alist, unsigned long key)
{
    unsigned long r = ((sexpr)((((int_pointer)(5)) << 3) | 0x5));
    while ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)))
    {
        unsigned long a = ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        if (((sexpr)(equalp (((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))), key)) == ((sexpr)((((int_pointer)(2)) << 3) | 0x5))))
        {
            r = cons (a, r);
        }
        alist = ((((((int_pointer)(alist)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return r;
}

variable_types:
r
unsigned long


original_code:
sexpr sx_alist_merge (sexpr alist1, sexpr alist2)
{
    sexpr r = alist1;
    while ((((((int_pointer)(alist2)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist2))->type == sxt_cons)))
    {
        sexpr a = ((((((int_pointer)(alist2)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist2))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist2))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        r = sx_alist_remove (r, ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))));
        r = cons (a, r);
        alist2 = ((((((int_pointer)(alist2)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist2))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist2))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return r;
}

canonical_original_code:
unsigned long sx_alist_merge(unsigned long alist1, unsigned long alist2)
{
    unsigned long r = alist1;
    while ((((((int_pointer)(alist2)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist2))->type == sxt_cons)))
    {
        unsigned long a = ((((((int_pointer)(alist2)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist2))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist2))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
        r = sx_alist_remove (r, ((((((int_pointer)(a)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)a))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)a))->car) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5))));
        r = cons (a, r);
        alist2 = ((((((int_pointer)(alist2)) & 0x1) == 0x0) && (((struct sexpr_cons *)((void *)alist2))->type == sxt_cons)) ? (((struct sexpr_cons *)((void *)alist2))->cdr) : ((sexpr)((((int_pointer)(8)) << 3) | 0x5)));
    }
    return r;
}