decompiled_code:
__int64 __fastcall console_put(char a1)
{
__int64 v1; // r8
__int64 v2; // rsi
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbp

switch ( a1 )
{
case 8:
v1 = console_cursor_x;
if ( !console_cursor_x )
goto LABEL_5;
--console_cursor_x;
result = console_put(32LL);
--console_cursor_x;
break;
case 9:
v4 = 0LL;
result = console_cursor_x & 7;
v5 = result;
if ( (console_cursor_x & 7) != 0 )
{
do
{
++v4;
result = console_put(32LL);
}
while ( v5 != v4 );
}
break;
case 10:
++console_cursor_y;
console_cursor_x = 0LL;
LABEL_7:
console_scroll();
return console_update_cursor();
default:
v1 = console_cursor_x;
LABEL_5:
v2 = console_cursor_y;
*(_WORD *)(console_videomem + 2 * (80 * console_cursor_y + v1)) = ((console_color_fg & 0xF | (unsigned __int16)(16 * (unsigned __int8)console_color_bg)) << 8) | a1;
if ( (unsigned __int64)(v1 + 1) > 0x4F )
{
console_cursor_x = 0LL;
console_cursor_y = v2 + 1;
}
else
{
console_cursor_x = v1 + 1;
}
goto LABEL_7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
__int64 v1; // r8
__int64 v2; // rsi
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rbp

switch ( a1 )
{
case 8:
v1 = console_cursor_x;
if ( !console_cursor_x )
goto LABEL_5;
--console_cursor_x;
result = func2(32LL);
--console_cursor_x;
break;
case 9:
v4 = 0LL;
result = console_cursor_x & 7;
v5 = result;
if ( (console_cursor_x & 7) != 0 )
{
do
{
++v4;
result = func2(32LL);
}
while ( v5 != v4 );
}
break;
case 10:
++console_cursor_y;
console_cursor_x = 0LL;
LABEL_7:
func0();
return func1();
default:
v1 = console_cursor_x;
LABEL_5:
v2 = console_cursor_y;
*(_WORD *)(console_videomem + 2 * (80 * console_cursor_y + v1)) = ((console_color_fg & 0xF | (unsigned __int16)(16 * (unsigned __int8)console_color_bg)) << 8) | a1;
if ( (unsigned __int64)(v1 + 1) > 0x4F )
{
console_cursor_x = 0LL;
console_cursor_y = v2 + 1;
}
else
{
console_cursor_x = v1 + 1;
}
goto LABEL_7;
}
return result;
}

original_code:
void console_put(char c)
{
    if (__builtin_expect(!!(c == 0x08 && console_cursor_x > 0), 0))
    {
        --console_cursor_x;
        console_put(' ');
        --console_cursor_x;
        return;
    }
    else if (__builtin_expect(!!(c == '\t'), 0))
    {
        size_t chars = console_cursor_x % 8;
        size_t i;
        for (i = 0; i < chars; ++i)
            console_put(' ');
        return;
    }
    else if (__builtin_expect(!!(c == '\n'), 0))
    {
        console_cursor_x = 0;
        ++console_cursor_y;
    }
    else
    {
        console_videomem[(console_cursor_y * 80 + console_cursor_x)] =
            (c | (((console_color_bg << 4) | (console_color_fg & 0x0F)) << 8));
        ++console_cursor_x;
        if (console_cursor_x >= 80)
        {
            console_cursor_x = 0;
            ++console_cursor_y;
        }
    }
    _console_scroll();
    _console_update_cursor();
}

canonical_original_code:
void console_put(char c)
{
    if (__builtin_expect(!!(c == 0x08 && console_cursor_x > 0), 0))
    {
        --console_cursor_x;
        console_put(' ');
        --console_cursor_x;
        return;
    }
    else if (__builtin_expect(!!(c == '\t'), 0))
    {
        unsigned long long chars = console_cursor_x % 8;
        unsigned long long i;
        for (i = 0; i < chars; ++i)
            console_put(' ');
        return;
    }
    else if (__builtin_expect(!!(c == '\n'), 0))
    {
        console_cursor_x = 0;
        ++console_cursor_y;
    }
    else
    {
        console_videomem[(console_cursor_y * 80 + console_cursor_x)] =
            (c | (((console_color_bg << 4) | (console_color_fg & 0x0F)) << 8));
        ++console_cursor_x;
        if (console_cursor_x >= 80)
        {
            console_cursor_x = 0;
            ++console_cursor_y;
        }
    }
    _console_scroll();
    _console_update_cursor();
}

variable_types: c char

variable_types:
chars
unsigned long long


repo: zrho/Carbon

decompiled_code:
__int64 console_clear()
{
_WORD *v0; // rax
__int16 v1; // dx
__int64 v2; // rcx

v0 = (_WORD *)console_videomem;
v1 = ((console_color_fg & 0xF | (unsigned __int16)(16 * (unsigned __int8)console_color_bg)) << 8) | 0x20;
v2 = console_videomem + 4000;
do
*v0++ = v1;
while ( v0 != (_WORD *)v2 );
console_cursor_y = 0LL;
console_cursor_x = 0LL;
return console_update_cursor();
}

canonical_decompiled_code:
__int64 func3()
{
_WORD *v0; // rax
__int16 v1; // dx
__int64 v2; // rcx

v0 = (_WORD *)console_videomem;
v1 = ((console_color_fg & 0xF | (unsigned __int16)(16 * (unsigned __int8)console_color_bg)) << 8) | 0x20;
v2 = console_videomem + 4000;
do
*v0++ = v1;
while ( v0 != (_WORD *)v2 );
console_cursor_y = 0LL;
console_cursor_x = 0LL;
return func1();
}

original_code:
void console_clear()
{
    uint16_t cell = (' ' | (((console_color_bg << 4) | (console_color_fg & 0x0F)) << 8));
    size_t i;
    for (i = 0; i < 80 * 25; ++i)
        console_videomem[i] = cell;
    console_cursor_x = console_cursor_y = 0;
    _console_update_cursor();
}

canonical_original_code:
void console_clear()
{
    unsigned short cell = (' ' | (((console_color_bg << 4) | (console_color_fg & 0x0F)) << 8));
    unsigned long long i;
    for (i = 0; i < 80 * 25; ++i)
        console_videomem[i] = cell;
    console_cursor_x = console_cursor_y = 0;
    _console_update_cursor();
}

variable_types:
cell
unsigned short

variable_types:
i
unsigned long long

return_type: void


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

result = a1;
console_color_fg = a1;
return result;
}

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

result = a1;
console_color_fg = a1;
return result;
}

original_code:
void console_set_foreground(uint8_t color)
{
    console_color_fg = color;
}

canonical_original_code:
void console_set_foreground(unsigned char color)
{
    console_color_fg = color;
}

variable_types:
color
unsigned char


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

result = a1;
console_color_bg = a1;
return result;
}

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

result = a1;
console_color_bg = a1;
return result;
}

original_code:
void console_set_background(uint8_t color)
{
    console_color_bg = color;
}

canonical_original_code:
void console_set_background(unsigned char color)
{
    console_color_bg = color;
}


canonical_decompiled_code:
char func6()
{
return console_color_fg;
}

original_code:
uint8_t console_get_foreground()
{
    return console_color_fg;
}

canonical_original_code:
unsigned char console_get_foreground()
{
    return console_color_fg;
}

return_type: unsigned char


canonical_decompiled_code:
char func7()
{
return console_color_bg;
}

original_code:
uint8_t console_get_background()
{
    return console_color_bg;
}

canonical_original_code:
unsigned char console_get_background()
{
    return console_color_bg;
}


decompiled_code:
__int64 console_get_x()
{
return console_cursor_x;
}

canonical_decompiled_code:
__int64 func8()
{
return console_cursor_x;
}

original_code:
size_t console_get_x()
{
    return console_cursor_x;
}

canonical_original_code:
unsigned long long console_get_x()
{
    return console_cursor_x;
}

return_type: unsigned long long


decompiled_code:
__int64 console_get_y()
{
return console_cursor_y;
}

canonical_decompiled_code:
__int64 func9()
{
return console_cursor_y;
}

original_code:
size_t console_get_y()
{
    return console_cursor_y;
}

canonical_original_code:
unsigned long long console_get_y()
{
    return console_cursor_y;
}


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

result = a1;
console_cursor_x = a1;
return result;
}

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

result = a1;
console_cursor_x = a1;
return result;
}

original_code:
void console_set_x(size_t x)
{
    console_cursor_x = x;
}

canonical_original_code:
void console_set_x(unsigned long long x)
{
    console_cursor_x = x;
}

variable_types:
x
unsigned long long


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

result = a1;
console_cursor_y = a1;
return result;
}

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

result = a1;
console_cursor_y = a1;
return result;
}

original_code:
void console_set_y(size_t y)
{
    console_cursor_y = y;
}

canonical_original_code:
void console_set_y(unsigned long long y)
{
    console_cursor_y = y;
}

variable_types:
y
unsigned long long


decompiled_code:
__int64 console_get_width()
{
return 80LL;
}

canonical_decompiled_code:
__int64 func12()
{
return 80LL;
}

original_code:
size_t console_get_width()
{
    return 80;
}

canonical_original_code:
unsigned long long console_get_width()
{
    return 80;
}


decompiled_code:
__int64 console_get_height()
{
return 25LL;
}

canonical_decompiled_code:
__int64 func13()
{
return 25LL;
}

original_code:
size_t console_get_height()
{
    return 25;
}

canonical_original_code:
unsigned long long console_get_height()
{
    return 25;
}


decompiled_code:
__int64 __fastcall console_print(char *a1)
{
char *v1; // rbx
char i; // di
__int64 result; // rax

v1 = a1;
for ( i = *a1; i; ++v1 )
{
result = console_put(i);
i = v1[1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1)
{
char *v1; // rbx
char i; // di
__int64 result; // rax

v1 = a1;
for ( i = *a1; i; ++v1 )
{
result = func2(i);
i = v1[1];
}
return result;
}

original_code:
void console_print(const char *str)
{
    char *ptr;
    for (ptr = (char *) str; *ptr; ++ptr)
        console_put(*ptr);
}

canonical_original_code:
void console_print(char *str)
{
    char *ptr;
    for (ptr = (char *) str; *ptr; ++ptr)
        console_put(*ptr);
}

variable_types:
str
char *

variable_types:
ptr
char *


decompiled_code:
__int64 __fastcall console_print_hex(unsigned __int64 a1)
{
unsigned __int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rbx
unsigned int v4; // edx
char v5; // di
__int64 v6; // rbx
__int64 result; // rax
char v8; // di
char v9[40]; // [rsp+0h] [rbp-28h]

v1 = a1;
console_put(48);
console_put(120);
v2 = 15LL;
if ( !a1 )
return console_put(48);
do
{
v3 = (int)v2;
v4 = v1 & 0xF;
v5 = v4 + 48;
if ( v4 >= 0xA )
v5 = v4 + 55;
v9[v2--] = v5;
v1 >>= 4;
}
while ( v1 );
v6 = v3 + 1;
for ( result = console_put(v5); (_DWORD)v6 != 16; result = console_put(v8) )
v8 = v9[v6++];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int64 a1)
{
unsigned __int64 v1; // r12
__int64 v2; // rax
__int64 v3; // rbx
unsigned int v4; // edx
char v5; // di
__int64 v6; // rbx
__int64 result; // rax
char v8; // di
char v9[40]; // [rsp+0h] [rbp-28h]

v1 = a1;
func2(48);
func2(120);
v2 = 15LL;
if ( !a1 )
return func2(48);
do
{
v3 = (int)v2;
v4 = v1 & 0xF;
v5 = v4 + 48;
if ( v4 >= 0xA )
v5 = v4 + 55;
v9[v2--] = v5;
v1 >>= 4;
}
while ( v1 );
v6 = v3 + 1;
for ( result = func2(v5); (_DWORD)v6 != 16; result = func2(v8) )
v8 = v9[v6++];
return result;
}

original_code:
void console_print_hex(uintptr_t number)
{
    console_put('0');
    console_put('x');
    if (__builtin_expect(!!(0 == number), 0)) {
        console_put('0');
        return;
    }
    int32_t i = 0;
    int8_t out[16];
    for (i = 15; number != 0; --i) {
        uint32_t digit = number & 0xF;
        number = number >> 4;
        if (digit > 9) {
            out[i] = (int8_t) ('A' + digit - 0xA);
        } else
            out[i] = (int8_t) ('0' + digit);
    }
    for (++i; i < 16; ++i)
        console_put(out[i]);
}

canonical_original_code:
void console_print_hex(unsigned long long number)
{
    console_put('0');
    console_put('x');
    if (__builtin_expect(!!(0 == number), 0)) {
        console_put('0');
        return;
    }
    int i = 0;
    char out[16];
    for (i = 15; number != 0; --i) {
        unsigned int digit = number & 0xF;
        number = number >> 4;
        if (digit > 9) {
            out[i] = (char) ('A' + digit - 0xA);
        } else
            out[i] = (char) ('0' + digit);
    }
    for (++i; i < 16; ++i)
        console_put(out[i]);
}

variable_types:
number
unsigned long long

variable_types: i int

variable_types:
out
char [16]

variable_types:
digit
unsigned int


decompiled_code:
__int64 __fastcall console_print_dec(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned int v2; // esi
char v3; // dl
__int64 result; // rax
__int64 v5; // rcx
char *v6; // rbx
char *v7; // rbp
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

if ( !a1 )
return console_put(48);
v1 = a1;
if ( a1 < 0 )
{
v1 = -a1;
console_put(45);
}
v2 = 15;
do
{
v3 = v1 / 0xA + 48;
v8[v2] = v3;
result = v2--;
v1 %= 0xAuLL;
}
while ( v1 );
if ( (unsigned int)result <= 0xF )
{
v5 = (unsigned int)(result + 1);
v6 = &v8[v5];
v7 = &v8[v5 + (unsigned int)(15 - result)];
while ( 1 )
{
result = console_put(v3);
if ( v7 == v6 )
break;
v3 = *v6++;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned int v2; // esi
char v3; // dl
__int64 result; // rax
__int64 v5; // rcx
char *v6; // rbx
char *v7; // rbp
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

if ( !a1 )
return func2(48);
v1 = a1;
if ( a1 < 0 )
{
v1 = -a1;
func2(45);
}
v2 = 15;
do
{
v3 = v1 / 0xA + 48;
v8[v2] = v3;
result = v2--;
v1 %= 0xAuLL;
}
while ( v1 );
if ( (unsigned int)result <= 0xF )
{
v5 = (unsigned int)(result + 1);
v6 = &v8[v5];
v7 = &v8[v5 + (unsigned int)(15 - result)];
while ( 1 )
{
result = func2(v3);
if ( v7 == v6 )
break;
v3 = *v6++;
}
}
return result;
}

original_code:
void console_print_dec(intptr_t number)
{
    if (__builtin_expect(!!(0 == number), 0)) {
        console_put('0');
        return;
    }
    if (__builtin_expect(!!(number < 0), 0)) {
        console_put('-');
        number = -number;
    }
    uint32_t i = 0;
    uint8_t out[16];
    for (i = 15; number != 0; --i) {
        uint32_t digit = number / 10;
        number = number % 10;
        out[i] = (int8_t) ('0' + digit);
    }
    for (++i; i < 16; ++i)
        console_put(out[i]);
}

canonical_original_code:
void console_print_dec(long long number)
{
    if (__builtin_expect(!!(0 == number), 0)) {
        console_put('0');
        return;
    }
    if (__builtin_expect(!!(number < 0), 0)) {
        console_put('-');
        number = -number;
    }
    unsigned int i = 0;
    unsigned char out[16];
    for (i = 15; number != 0; --i) {
        unsigned int digit = number / 10;
        number = number % 10;
        out[i] = (char) ('0' + digit);
    }
    for (++i; i < 16; ++i)
        console_put(out[i]);
}

variable_types:
number
long long

variable_types:
i
unsigned int

variable_types:
out
unsigned char [16]


decompiled_code:
unsigned __int64 __fastcall stack_create(_QWORD *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rbp
unsigned __int64 result; // rax

v2 = *(_QWORD *)(a2 + 56);
*a1 = v2 - 0x17FFFE01000LL;
*(_QWORD *)(a2 + 56) = v2 + 2093056;
a1[1] = 0LL;
if ( (unsigned __int64)(v2 - 0x17FFFE01000LL) > 0xFFFFFEFFFFFFFFFFLL )
{
console_print("PANIC: ");
console_print("Exceeded maximum number of stacks per process.");
console_print("\n");
while ( 1 )
;
}
v3 = memory_space_get();
if ( *(_QWORD *)(a2 + 48) != v3 )
((void (*)(void))memory_space_switch)();
result = stack_resize(a1, 0x1000uLL, a2);
if ( *(_QWORD *)(a2 + 48) != v3 )
result = memory_space_switch(v3);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rbp
unsigned __int64 result; // rax

v2 = *(_QWORD *)(a2 + 56);
*a1 = v2 - 0x17FFFE01000LL;
*(_QWORD *)(a2 + 56) = v2 + 2093056;
a1[1] = 0LL;
if ( (unsigned __int64)(v2 - 0x17FFFE01000LL) > 0xFFFFFEFFFFFFFFFFLL )
{
console_print("PANIC: ");
console_print("Exceeded maximum number of stacks per process.");
console_print("\n");
while ( 1 )
;
}
v3 = memory_space_get();
if ( *(_QWORD *)(a2 + 48) != v3 )
((void (*)(void))memory_space_switch)();
result = func0(a1, 0x1000uLL, a2);
if ( *(_QWORD *)(a2 + 48) != v3 )
result = memory_space_switch(v3);
return result;
}

original_code:
void stack_create(stack_t *stack, process_t *process) {
    stack->address = 0xFFFFFE8000000000 + process->stack_offset + (0x200000 - 0x1000);
    process->stack_offset += (0x200000 - 0x1000);
    stack->length = 0;
    if (__builtin_expect(!!(stack->address >= 0xFFFFFE8000000000 + 0x8000000000), 0))
        { console_print("PANIC: "); console_print("Exceeded maximum number of stacks per process."); console_print("\n"); while (1); };
    uintptr_t old_addr_space = memory_space_get();
    if (old_addr_space != process->addr_space)
        memory_space_switch(process->addr_space);
    stack_resize(stack, 0x1000, process);
    if (old_addr_space != process->addr_space)
        memory_space_switch(old_addr_space);
}

canonical_original_code:
void stack_create(struct stack_t *stack, struct process_t *process) {
    stack->address = 0xFFFFFE8000000000 + process->stack_offset + (0x200000 - 0x1000);
    process->stack_offset += (0x200000 - 0x1000);
    stack->length = 0;
    if (__builtin_expect(!!(stack->address >= 0xFFFFFE8000000000 + 0x8000000000), 0))
        { console_print("PANIC: "); console_print("Exceeded maximum number of stacks per process."); console_print("\n"); while (1); };
    unsigned long long old_addr_space = memory_space_get();
    if (old_addr_space != process->addr_space)
        memory_space_switch(process->addr_space);
    stack_resize(stack, 0x1000, process);
    if (old_addr_space != process->addr_space)
        memory_space_switch(old_addr_space);
}

variable_types: struct stack_t { unsigned long long address; unsigned long long length; } *

variable_types: struct process_t { unsigned int pid; struct process_t *parent; unsigned short order; unsigned long long message_handler; unsigned char term_implicit; struct thread_t { unsigned int tid; unsigned int pid; unsigned char frozen; unsigned char ttl; unsigned char role; void *role_ctx; unsigned char sleep_mode; void *sleep_ctx; void *result_ptr; unsigned int ipc_buffer_sz[3]; unsigned char flags; unsigned long long entry_point; void *fx_data; struct cpu_int_state_t { unsigned long long ds; struct cpu_state_t { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rsi; unsigned long long rdi; unsigned long long rbp; unsigned long long rdx; unsigned long long rcx; unsigned long long rbx; unsigned long long rax; } state; unsigned long long vector; unsigned long long error_code; unsigned long long rip; unsigned long long cs; unsigned long long flags; unsigned long long rsp; unsigned long long ss; } state; struct stack_t stack; struct thread_t *next_sched; struct thread_t *next; } *threads; unsigned long long addr_space; unsigned long long stack_offset; struct process_t *next; } *

user_defined_types: struct process_t { unsigned int pid; struct process_t *parent; unsigned short order; unsigned long long message_handler; unsigned char term_implicit; struct thread_t *threads; unsigned long long addr_space; unsigned long long stack_offset; struct process_t *next; }

user_defined_types: struct thread_t { unsigned int tid; unsigned int pid; unsigned char frozen; unsigned char ttl; unsigned char role; void *role_ctx; unsigned char sleep_mode; void *sleep_ctx; void *result_ptr; unsigned int ipc_buffer_sz[3]; unsigned char flags; unsigned long long entry_point; void *fx_data; struct cpu_int_state_t state; struct stack_t stack; struct thread_t *next_sched; struct thread_t *next; }

user_defined_types: struct cpu_int_state_t { unsigned long long ds; struct cpu_state_t state; unsigned long long vector; unsigned long long error_code; unsigned long long rip; unsigned long long cs; unsigned long long flags; unsigned long long rsp; unsigned long long ss; }


decompiled_code:
unsigned __int64 __fastcall stack_dispose(_QWORD *a1, __int64 a2)
{
return stack_resize(a1, 0LL, a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_QWORD *a1, __int64 a2)
{
return func0(a1, 0LL, a2);
}

original_code:
void stack_dispose(stack_t *stack, process_t *process) {
    stack_resize(stack, 0, process);
}

canonical_original_code:
void stack_dispose(struct stack_t *stack, struct process_t *process) {
    stack_resize(stack, 0, process);
}

user_defined_types: struct stack_t { unsigned long long address; unsigned long long length; }

user_defined_types: struct cpu_state_t { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rsi; unsigned long long rdi; unsigned long long rbp; unsigned long long rdx; unsigned long long rcx; unsigned long long rbx; unsigned long long rax; }


fread

decompiled_code:
unsigned __int64 __fastcall fread(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // r14
unsigned __int64 v8; // rsi
unsigned __int64 v9; // rax
unsigned __int64 v10; // rdx
unsigned __int64 v11; // r12

v4 = a4 + 8;
mutex_lock(a4 + 8);
v8 = a2 * a3;
v9 = _stdio_read(a4, v8, a1);
v10 = v9 % a2;
v11 = v9 / a2;
if ( v8 > v9 )
*(_BYTE *)(a4 + 24) |= 1u;
mutex_unlock(v4, v8, v10);
return v11;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // r14
unsigned __int64 v8; // rsi
unsigned __int64 v9; // rax
unsigned __int64 v10; // rdx
unsigned __int64 v11; // r12

v4 = a4 + 8;
mutex_lock(a4 + 8);
v8 = a2 * a3;
v9 = _stdio_read(a4, v8, a1);
v10 = v9 % a2;
v11 = v9 / a2;
if ( v8 > v9 )
*(_BYTE *)(a4 + 24) |= 1u;
mutex_unlock(v4, v8, v10);
return v11;
}

original_code:
size_t fread(void *ptr, size_t size, size_t count, FILE *stream) {
    mutex_lock(&stream->lock);
    size_t length = size * count;
    size_t bytes_read = __stdio_read(stream, length, ptr);
    size_t blocks_read = bytes_read / size;
    if (bytes_read < length)
        stream->flags |= (1 << 0);
    mutex_unlock(&stream->lock);
    return blocks_read;
}

canonical_original_code:
unsigned long long fread(void *ptr, unsigned long long size, unsigned long long count, struct __file *stream) {
    mutex_lock(&stream->lock);
    unsigned long long length = size * count;
    unsigned long long bytes_read = __stdio_read(stream, length, ptr);
    unsigned long long blocks_read = bytes_read / size;
    if (bytes_read < length)
        stream->flags |= (1 << 0);
    mutex_unlock(&stream->lock);
    return blocks_read;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long long

variable_types:
count
unsigned long long

variable_types: struct __file { unsigned long long descriptor; unsigned int lock; unsigned long long position; unsigned char flags; void *buffer; unsigned long long buffer_len; unsigned long long buffer_size; unsigned char buffer_mode; void (*callback_write)(struct __file *, unsigned long long pos, unsigned long long size, void *data); unsigned long long (*callback_read)(struct __file *, unsigned long long pos, unsigned long long size, void *data); unsigned long long (*callback_length)(struct __file *); struct __file *next; } *

variable_types:
length
unsigned long long


memcmp

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

if ( !a3 )
return 0LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( a3 == ++v3 )
return 0LL;
}
return 1LL;
}

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

if ( !a3 )
return 0LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( a3 == ++v3 )
return 0LL;
}
return 1LL;
}

original_code:
int memcmp(const void *p1, const void *p2, size_t n) {
 uint8_t *v1 = (void*) p1;
 uint8_t *v2 = (void*) p2;
 size_t i;
 for (i = 0; i < n; i++) {
  if (v1[i] != v2[i]) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
int memcmp(void *p1, void *p2, unsigned long long n) {
 unsigned char *v1 = (void*) p1;
 unsigned char *v2 = (void*) p2;
 unsigned long long i;
 for (i = 0; i < n; i++) {
  if (v1[i] != v2[i]) {
   return 1;
  }
 }
 return 0;
}

variable_types:
n
unsigned long long

variable_types:
i
unsigned long long

return_type: int


strdup

decompiled_code:
char *__fastcall strdup(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // r12

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // rax
char *v2; // rax
char *v3; // r12

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

original_code:
char *strdup(const char *s) {
 char *d;
 d = malloc(sizeof(char) * (strlen(s) + 1));
 if (!d) return 0;
 strcpy(d, s);
 return d;
}

canonical_original_code:
char *strdup(char *s) {
 char *d;
 d = malloc(sizeof(char) * (strlen(s) + 1));
 if (!d) return 0;
 strcpy(d, s);
 return d;
}

variable_types:
s
char *

variable_types:
d
char *

return_type: char *


strtok

decompiled_code:
char *__fastcall strtok(char *a1, const char *a2)
{
char *result; // rax

result = strtok_r(a1, a2, &saveptr_0);
if ( !result )
saveptr_0 = 0LL;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1, const char *a2)
{
char *result; // rax

result = strtok_r(a1, a2, &saveptr_0);
if ( !result )
saveptr_0 = 0LL;
return result;
}

original_code:
char *strtok(char *str, const char *delim) {
 static char *saveptr = 0;
 char *token;
 token = strtok_r(str, delim, &saveptr);
 if (!token) {
  saveptr = 0;
 }
 return token;
}

canonical_original_code:
char *strtok(char *str, char *delim) {
 static char *saveptr = 0;
 char *token;
 token = strtok_r(str, delim, &saveptr);
 if (!token) {
  saveptr = 0;
 }
 return token;
}

variable_types:
str
char *

variable_types:
delim
char *

variable_types:
saveptr
char *

variable_types:
token
char *


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

result = *(unsigned int *)process_current;
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 120) = 1LL;
}
else
{
result = frame_alloc();
*(_QWORD *)(a1 + 120) = 0LL;
*(_QWORD *)(a1 + 112) = result;
}
return result;
}

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

result = *(unsigned int *)process_current;
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 120) = 1LL;
}
else
{
result = frame_alloc();
*(_QWORD *)(a1 + 120) = 0LL;
*(_QWORD *)(a1 + 112) = result;
}
return result;
}

original_code:
void syscall_memory_alloc(cpu_int_state_t *state) {
 if (!(0 == process_current->pid))
  { state->state.rax = 1; return; };
    state->state.rbx = frame_alloc();
    { state->state.rax = 0; return; };
}

canonical_original_code:
void syscall_memory_alloc(struct cpu_int_state_t *state) {
 if (!(0 == process_current->pid))
  { state->state.rax = 1; return; };
    state->state.rbx = frame_alloc();
    { state->state.rax = 0; return; };
}

variable_types: struct cpu_int_state_t { unsigned long long ds; struct cpu_state_t { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rsi; unsigned long long rdi; unsigned long long rbp; unsigned long long rdx; unsigned long long rcx; unsigned long long rbx; unsigned long long rax; } state; unsigned long long vector; unsigned long long error_code; unsigned long long rip; unsigned long long cs; unsigned long long flags; unsigned long long rsp; unsigned long long ss; } *


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

result = *(unsigned int *)process_current;
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 120) = 1LL;
}
else
{
result = frame_free(*(_QWORD *)(a1 + 112));
*(_QWORD *)(a1 + 120) = 0LL;
}
return result;
}

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

result = *(unsigned int *)process_current;
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 120) = 1LL;
}
else
{
result = frame_free(*(_QWORD *)(a1 + 112));
*(_QWORD *)(a1 + 120) = 0LL;
}
return result;
}

original_code:
void syscall_memory_free(cpu_int_state_t *state) {
 if (!(0 == process_current->pid))
  { state->state.rax = 1; return; };
    frame_free(state->state.rbx);
    { state->state.rax = 0; return; };
}

canonical_original_code:
void syscall_memory_free(struct cpu_int_state_t *state) {
 if (!(0 == process_current->pid))
  { state->state.rax = 1; return; };
    frame_free(state->state.rbx);
    { state->state.rax = 0; return; };
}


decompiled_code:
__int64 __fastcall syscall_memory_map(__int64 a1)
{
__int64 result; // rax
void *v2; // rbp
void *v3; // rax
__int64 v4; // r12
void *v5; // r13
__int64 v6; // r14

result = *(unsigned int *)process_current;
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 120) = 1LL;
}
else
{
v2 = memalign(*(_QWORD *)(a1 + 80), 0x1000uLL);
v3 = memalign(*(_QWORD *)(a1 + 72), 0x1000uLL);
v4 = *(_QWORD *)(a1 + 112);
v5 = v3;
result = process_get(*(unsigned int *)(a1 + 104));
if ( result )
{
v6 = memory_space_switch(*(_QWORD *)(result + 48));
memory_map(v2, v5, (v4 & 1) == 0 ? 4 : 6);
result = memory_space_switch(v6);
*(_QWORD *)(a1 + 120) = 0LL;
}
else
{
*(_QWORD *)(a1 + 120) = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
void *v2; // rbp
void *v3; // rax
__int64 v4; // r12
void *v5; // r13
__int64 v6; // r14

result = *(unsigned int *)process_current;
if ( (_DWORD)result )
{
*(_QWORD *)(a1 + 120) = 1LL;
}
else
{
v2 = memalign(*(_QWORD *)(a1 + 80), 0x1000uLL);
v3 = memalign(*(_QWORD *)(a1 + 72), 0x1000uLL);
v4 = *(_QWORD *)(a1 + 112);
v5 = v3;
result = process_get(*(unsigned int *)(a1 + 104));
if ( result )
{
v6 = memory_space_switch(*(_QWORD *)(result + 48));
memory_map(v2, v5, (v4 & 1) == 0 ? 4 : 6);
result = memory_space_switch(v6);
*(_QWORD *)(a1 + 120) = 0LL;
}
else
{
*(_QWORD *)(a1 + 120) = 2LL;
}
}
return result;
}

original_code:
void syscall_memory_map(cpu_int_state_t *state) {
 if (!(0 == process_current->pid))
  { state->state.rax = 1; return; };
    uintptr_t virt = memalign(state->state.rdi, 0x1000);
    uintptr_t phys = memalign(state->state.rsi, 0x1000);
    uint16_t flags = (uint16_t) state->state.rbx;
    uint32_t pid = (uint32_t) state->state.rcx;
    process_t *proc = process_get(pid);
    if (0 == proc)
        { state->state.rax = 2; return; };
    uint16_t pflags = (1 << 2);
    if (0 != (flags & (1 << 0)))
        pflags |= (1 << 1);
    uintptr_t old_space = memory_space_switch(proc->addr_space);
    memory_map(virt, phys, pflags);
    memory_space_switch(old_space);
    { state->state.rax = 0; return; };
}

canonical_original_code:
void syscall_memory_map(struct cpu_int_state_t *state) {
 if (!(0 == process_current->pid))
  { state->state.rax = 1; return; };
    unsigned long long virt = memalign(state->state.rdi, 0x1000);
    unsigned long long phys = memalign(state->state.rsi, 0x1000);
    unsigned short flags = (uint16_t) state->state.rbx;
    unsigned int pid = (uint32_t) state->state.rcx;
    struct process_t *proc = process_get(pid);
    if (0 == proc)
        { state->state.rax = 2; return; };
    unsigned short pflags = (1 << 2);
    if (0 != (flags & (1 << 0)))
        pflags |= (1 << 1);
    unsigned long long old_space = memory_space_switch(proc->addr_space);
    memory_map(virt, phys, pflags);
    memory_space_switch(old_space);
    { state->state.rax = 0; return; };
}

variable_types:
virt
unsigned long long

variable_types:
phys
unsigned long long

variable_types:
flags
unsigned short

variable_types:
pid
unsigned int

variable_types: struct process_t { unsigned int pid; struct process_t *parent; unsigned short order; unsigned long long message_handler; unsigned char term_implicit; struct thread_t { unsigned int tid; unsigned int pid; unsigned char frozen; unsigned char ttl; unsigned char role; void *role_ctx; unsigned char sleep_mode; void *sleep_ctx; void *result_ptr; unsigned int ipc_buffer_sz[3]; unsigned char flags; unsigned long long entry_point; void *fx_data; struct cpu_int_state_t { unsigned long long ds; struct cpu_state_t { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rsi; unsigned long long rdi; unsigned long long rbp; unsigned long long rdx; unsigned long long rcx; unsigned long long rbx; unsigned long long rax; } state; unsigned long long vector; unsigned long long error_code; unsigned long long rip; unsigned long long cs; unsigned long long flags; unsigned long long rsp; unsigned long long ss; } state; struct stack_t { unsigned long long address; unsigned long long length; } stack; struct thread_t *next_sched; struct thread_t *next; } *threads; unsigned long long addr_space; unsigned long long stack_offset; struct process_t *next; } *

variable_types:
pflags
unsigned short


free

decompiled_code:
void free()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void free(void *ptr) {
}

canonical_original_code:
void free(void *ptr) {
}

variable_types:
ptr
void *


fprintf

decompiled_code:
int fprintf(FILE *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
return vfprintf(a1, a2, arg);
}

canonical_decompiled_code:
int func0(FILE *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
return vfprintf(a1, a2, arg);
}

original_code:
int fprintf(FILE *stream, const char *format, ...) {
    va_list ap;
    __builtin_va_start(ap, format);
    int ret = vfprintf(stream, format, ap);
    __builtin_va_end(ap);
    return ret;
}

canonical_original_code:
int fprintf(struct __file *stream, char *format, ...) {
    __builtin_va_list ap;
    __builtin_va_start(ap, format);
    int ret = vfprintf(stream, format, ap);
    __builtin_va_end(ap);
    return ret;
}

variable_types: struct __file { unsigned long long descriptor; unsigned int lock; unsigned long long position; unsigned char flags; void *buffer; unsigned long long buffer_len; unsigned long long buffer_size; unsigned char buffer_mode; void (*callback_write)(struct __file *, unsigned long long pos, unsigned long long size, void *data); unsigned long long (*callback_read)(struct __file *, unsigned long long pos, unsigned long long size, void *data); unsigned long long (*callback_length)(struct __file *); struct __file *next; } *

variable_types:
format
char *

variable_types: ret int


tolower

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

result = a1;
if ( a1 - 65 < 0x1A )
result = a1 + 32;
return result;
}

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

result = a1;
if ( a1 - 65 < 0x1A )
result = a1 + 32;
return result;
}

variable_types: c int


strlen

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

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

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

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

original_code:
size_t strlen(const char *s) {
 size_t i;
 for (i = 0; s[i]; i++);
 return i;
}

canonical_original_code:
unsigned long long strlen(char *s) {
 unsigned long long i;
 for (i = 0; s[i]; i++);
 return i;
}

variable_types:
s
char *

variable_types:
i
unsigned long long


labs

decompiled_code:
unsigned __int64 __fastcall labs(__int64 a1)
{
return abs64(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1)
{
return abs64(a1);
}

original_code:
long int labs(long int number) {
 if (number >= 0)
  return number;
 else
  return -number;
}

canonical_original_code:
long labs(long number) {
 if (number >= 0)
  return number;
 else
  return -number;
}

variable_types: number long

return_type: long


strtof

decompiled_code:
float __fastcall strtof(const char *a1, char **a2)
{
return strtold(a1, a2);
}

canonical_decompiled_code:
float __fastcall func0(const char *a1, char **a2)
{
return strtold(a1, a2);
}

original_code:
float strtof(const char *str, char **endptr) {
 return strtold(str, endptr);
}

canonical_original_code:
float strtof(char *str, char **endptr) {
 return strtold(str, endptr);
}

variable_types:
str
char *

variable_types:
endptr
char **

return_type: float


strtol

decompiled_code:
__int64 __fastcall strtol(const char *nptr, char **endptr, int base)
{
return strtoll(nptr, endptr, base);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *nptr, char **endptr, int base)
{
return strtoll(nptr, endptr, base);
}

original_code:
long int strtol(const char *ptr, char **endptr, int base) {
 return strtoll(ptr, endptr, base);
}

canonical_original_code:
long strtol(char *ptr, char **endptr, int base) {
 return strtoll(ptr, endptr, base);
}

variable_types:
ptr
char *

variable_types: base int


atof

decompiled_code:
void __fastcall atof(const char *a1)
{
strtod(a1, 0LL);
}

canonical_decompiled_code:
void __fastcall func0(const char *a1)
{
strtod(a1, 0LL);
}

original_code:
inline double atof(const char *str) {
 return strtod(str, 0);
}

canonical_original_code:
inline double atof(char *str) {
 return strtod(str, 0);
}

return_type: double


strtold

decompiled_code:
void __fastcall strtold(char *a1, _QWORD *a2)
{
char *v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
_scan_float_constprop_0(&v2);
if ( a2 )
*a2 = v2;
}

canonical_decompiled_code:
void __fastcall func3(char *a1, _QWORD *a2)
{
char *v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
func2(&v2);
if ( a2 )
*a2 = v2;
}

original_code:
long double strtold(const char *nptr, char **endptr) {
 long double value;
 value = __scan_float(&nptr, 0);
 if (endptr) {
  *endptr = (char*) nptr;
 }
 return value;
}

canonical_original_code:
long double strtold(char *nptr, char **endptr) {
 long double value;
 value = __scan_float(&nptr, 0);
 if (endptr) {
  *endptr = (char *) nptr;
 }
 return value;
}

variable_types:
nptr
char *

variable_types:
value
long double

return_type: long double


toupper

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

result = a1;
if ( a1 - 97 < 0x1A )
result = a1 - 32;
return result;
}

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

result = a1;
if ( a1 - 97 < 0x1A )
result = a1 - 32;
return result;
}


decompiled_code:
__int64 __fastcall is_accepted(char a1, _BYTE *a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rsi

LOBYTE(result) = *a2;
if ( !*a2 )
return 0LL;
v3 = a2 + 1;
while ( a1 != (_BYTE)result )
{
result = *v3++;
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, _BYTE *a2)
{
__int64 result; // rax
unsigned __int8 *v3; // rsi

LOBYTE(result) = *a2;
if ( !*a2 )
return 0LL;
v3 = a2 + 1;
while ( a1 != (_BYTE)result )
{
result = *v3++;
if ( !(_BYTE)result )
return result;
}
return 1LL;
}

original_code:
static bool is_accepted(char c, const char *accept) {
 size_t i;
 for (i = 0; accept[i]; i++) {
  if (c == accept[i]) {
   return 1;
  }
 }
 return 0;
}

canonical_original_code:
static unsigned char is_accepted(char c, char *accept) {
 unsigned long long i;
 for (i = 0; accept[i]; i++) {
  if (c == accept[i]) {
   return 1;
  }
 }
 return 0;
}

variable_types: c char

variable_types:
accept
char *


strpbrk

decompiled_code:
__int64 __fastcall strpbrk(char *a1, _BYTE *a2)
{
char v2; // di
char i; // al
__int64 v4; // rdx
_BYTE *v5; // rcx
__int64 (__fastcall *v6)(char, _BYTE *); // r8
char v7; // di

v2 = *a1;
if ( !v2 )
return 0LL;
for ( i = is_accepted(v2, a2); !i; i = v6(v7, v5) )
{
v7 = *(_BYTE *)(v4 + 1);
if ( !v7 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, _BYTE *a2)
{
char v2; // di
char i; // al
__int64 v4; // rdx
_BYTE *v5; // rcx
__int64 (__fastcall *v6)(char, _BYTE *); // r8
char v7; // di

v2 = *a1;
if ( !v2 )
return 0LL;
for ( i = func0(v2, a2); !i; i = v6(v7, v5) )
{
v7 = *(_BYTE *)(v4 + 1);
if ( !v7 )
return 0LL;
}
return v4;
}

original_code:
char *strpbrk(const char *s, const char *accept) {
 size_t i;
 for (i = 0; s[i]; i++) {
  if (is_accepted(s[i], accept)) {
   return (char*) &s[i];
  }
 }
 return 0;
}

canonical_original_code:
char *strpbrk(char *s, char *accept) {
 unsigned long long i;
 for (i = 0; s[i]; i++) {
  if (is_accepted(s[i], accept)) {
   return (char *) &s[i];
  }
 }
 return 0;
}


atol

decompiled_code:
__int64 __fastcall atol(const char *a1)
{
return strtol(a1, 0LL, 10);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
return strtol(a1, 0LL, 10);
}

original_code:
inline long int atol(const char *str) {
 return strtol(str, 0, 10);
}

canonical_original_code:
inline long atol(char *str) {
 return strtol(str, 0, 10);
}


decompiled_code:
__int64 __fastcall syscall_ipc_respond(_QWORD *a1)
{
__int64 result; // rax
__int64 v3; // r13
unsigned int *v4; // r14
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // r15
__int64 v8; // rax
unsigned int *v9; // r12
__int64 v10; // rsi
__int64 v11; // rdi
__int64 v12; // rdi
__int64 v13; // [rsp+8h] [rbp-40h]

result = thread_current;
if ( *(_BYTE *)(thread_current + 10) == 1 )
{
v3 = a1[13];
if ( *(_DWORD *)(thread_current + 48) >= (unsigned int)v3 )
{
v4 = *(unsigned int **)(thread_current + 16);
v5 = v4[1];
v13 = a1[14];
v6 = process_get(*v4);
v7 = v6;
if ( v6 && (v8 = thread_get(v6, v5), (v9 = (unsigned int *)v8) != 0LL) )
{
if ( (v4[2] & 2) != 0 )
{
v10 = thread_current;
v11 = process_current;
}
else
{
if ( (_DWORD)v3 )
ipc_buffer_move(thread_current, 0LL, v8, 1LL, v7);
ipc_message_header(
1LL,
(unsigned int)v3,
(unsigned __int16)v13,
*(unsigned int *)process_current,
*v9,
v9 + 20);
thread_thaw(v9, 0LL);
v10 = thread_current;
v11 = process_current;
}
thread_stop(v11, v10);
result = thread_switch(v9, a1);
}
else
{
thread_stop(process_current, thread_current);
v12 = scheduler_next();
result = thread_switch(v12, a1);
}
}
else
{
a1[15] = 2LL;
}
}
else
{
a1[15] = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 result; // rax
__int64 v3; // r13
unsigned int *v4; // r14
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // r15
__int64 v8; // rax
unsigned int *v9; // r12
__int64 v10; // rsi
__int64 v11; // rdi
__int64 v12; // rdi
__int64 v13; // [rsp+8h] [rbp-40h]

result = thread_current;
if ( *(_BYTE *)(thread_current + 10) == 1 )
{
v3 = a1[13];
if ( *(_DWORD *)(thread_current + 48) >= (unsigned int)v3 )
{
v4 = *(unsigned int **)(thread_current + 16);
v5 = v4[1];
v13 = a1[14];
v6 = process_get(*v4);
v7 = v6;
if ( v6 && (v8 = thread_get(v6, v5), (v9 = (unsigned int *)v8) != 0LL) )
{
if ( (v4[2] & 2) != 0 )
{
v10 = thread_current;
v11 = process_current;
}
else
{
if ( (_DWORD)v3 )
ipc_buffer_move(thread_current, 0LL, v8, 1LL, v7);
ipc_message_header(
1LL,
(unsigned int)v3,
(unsigned __int16)v13,
*(unsigned int *)process_current,
*v9,
v9 + 20);
thread_thaw(v9, 0LL);
v10 = thread_current;
v11 = process_current;
}
thread_stop(v11, v10);
result = thread_switch(v9, a1);
}
else
{
thread_stop(process_current, thread_current);
v12 = scheduler_next();
result = thread_switch(v12, a1);
}
}
else
{
a1[15] = 2LL;
}
}
else
{
a1[15] = 1LL;
}
return result;
}

original_code:
void syscall_ipc_respond(cpu_int_state_t *state) {
 if (1 != thread_current->role)
  { state->state.rax = 1; return; };
 uint16_t flags = (uint16_t) state->state.rbx;
 uint32_t length = (uint32_t) state->state.rcx;
 if (length > thread_current->ipc_buffer_sz[0])
  { state->state.rax = 2; return; };
 ipc_role_ctx_t *role_ctx = (ipc_role_ctx_t *) thread_current->role_ctx;
 uint32_t sender_pid = role_ctx->sender_process;
 uint32_t sender_tid = role_ctx->sender_thread;
 process_t *sender_process = process_get(sender_pid);
 if (0 == sender_process) {
  thread_stop(process_current, thread_current);
  thread_switch(scheduler_next(), state);
  return;
 }
 thread_t *sender_thread = thread_get(sender_process, sender_tid);
 if (0 == sender_thread) {
  thread_stop(process_current, thread_current);
  thread_switch(scheduler_next(), state);
  return;
 }
 if (0 != (role_ctx->flags & (1 << 1))) {
  thread_stop(process_current, thread_current);
  thread_switch(sender_thread, state);
  return;
 }
 if (length > 0)
  ipc_buffer_move(
    thread_current,
    0,
    sender_thread,
    1,
    sender_process);
 ipc_message_header(
   1,
   length,
   flags,
   process_current->pid,
   sender_thread->tid,
   &sender_thread->state);
 thread_thaw(sender_thread, 0);
 thread_stop(process_current, thread_current);
 thread_switch(sender_thread, state);
}

canonical_original_code:
void syscall_ipc_respond(struct cpu_int_state_t *state) {
 if (1 != thread_current->role)
  { state->state.rax = 1; return; };
 unsigned short flags = (uint16_t) state->state.rbx;
 unsigned int length = (uint32_t) state->state.rcx;
 if (length > thread_current->ipc_buffer_sz[0])
  { state->state.rax = 2; return; };
 struct ipc_role_ctx_t *role_ctx = (ipc_role_ctx_t *) thread_current->role_ctx;
 unsigned int sender_pid = role_ctx->sender_process;
 unsigned int sender_tid = role_ctx->sender_thread;
 struct process_t *sender_process = process_get(sender_pid);
 if (0 == sender_process) {
  thread_stop(process_current, thread_current);
  thread_switch(scheduler_next(), state);
  return;
 }
 struct thread_t *sender_thread = thread_get(sender_process, sender_tid);
 if (0 == sender_thread) {
  thread_stop(process_current, thread_current);
  thread_switch(scheduler_next(), state);
  return;
 }
 if (0 != (role_ctx->flags & (1 << 1))) {
  thread_stop(process_current, thread_current);
  thread_switch(sender_thread, state);
  return;
 }
 if (length > 0)
  ipc_buffer_move(
    thread_current,
    0,
    sender_thread,
    1,
    sender_process);
 ipc_message_header(
   1,
   length,
   flags,
   process_current->pid,
   sender_thread->tid,
   &sender_thread->state);
 thread_thaw(sender_thread, 0);
 thread_stop(process_current, thread_current);
 thread_switch(sender_thread, state);
}

variable_types: struct cpu_int_state_t { unsigned long long ds; struct cpu_state_t { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rsi; unsigned long long rdi; unsigned long long rbp; unsigned long long rdx; unsigned long long rcx; unsigned long long rbx; unsigned long long rax; } state; unsigned long long vector; unsigned long long error_code; unsigned long long rip; unsigned long long cs; unsigned long long flags; unsigned long long rsp; unsigned long long ss; } *

variable_types:
flags
unsigned short

variable_types:
length
unsigned int

variable_types: struct ipc_role_ctx_t { unsigned int sender_process; unsigned int sender_thread; unsigned short flags; } *

variable_types: struct process_t { unsigned int pid; struct process_t *parent; unsigned short order; unsigned long long message_handler; unsigned char term_implicit; struct thread_t { unsigned int tid; unsigned int pid; unsigned char frozen; unsigned char ttl; unsigned char role; void *role_ctx; unsigned char sleep_mode; void *sleep_ctx; void *result_ptr; unsigned int ipc_buffer_sz[3]; unsigned char flags; unsigned long long entry_point; void *fx_data; struct cpu_int_state_t { unsigned long long ds; struct cpu_state_t { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rsi; unsigned long long rdi; unsigned long long rbp; unsigned long long rdx; unsigned long long rcx; unsigned long long rbx; unsigned long long rax; } state; unsigned long long vector; unsigned long long error_code; unsigned long long rip; unsigned long long cs; unsigned long long flags; unsigned long long rsp; unsigned long long ss; } state; struct stack_t { unsigned long long address; unsigned long long length; } stack; struct thread_t *next_sched; struct thread_t *next; } *threads; unsigned long long addr_space; unsigned long long stack_offset; struct process_t *next; } *


decompiled_code:
unsigned __int64 __fastcall syscall_ipc_buffer_get(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rdx
int v3; // eax

result = *(_QWORD *)(a1 + 112);
if ( (unsigned __int8)result > 2u )
{
*(_QWORD *)(a1 + 120) = 1LL;
}
else
{
v2 = 0xFFFFFD8000000000LL;
if ( !(_BYTE)result )
v2 = 0xFFFFFE0000000000LL;
v3 = *(_DWORD *)thread_current;
*(_QWORD *)(a1 + 120) = 0LL;
result = v2 + (unsigned int)(v3 << 21);
*(_QWORD *)(a1 + 112) = result;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rdx
int v3; // eax

result = *(_QWORD *)(a1 + 112);
if ( (unsigned __int8)result > 2u )
{
*(_QWORD *)(a1 + 120) = 1LL;
}
else
{
v2 = 0xFFFFFD8000000000LL;
if ( !(_BYTE)result )
v2 = 0xFFFFFE0000000000LL;
v3 = *(_DWORD *)thread_current;
*(_QWORD *)(a1 + 120) = 0LL;
result = v2 + (unsigned int)(v3 << 21);
*(_QWORD *)(a1 + 112) = result;
}
return result;
}

original_code:
void syscall_ipc_buffer_get(cpu_int_state_t *state) {
 uint8_t buffer = state->state.rbx;
 if (buffer > 2)
  { state->state.rax = 1; return; };
 state->state.rbx = ((buffer == 0) ? 0xFFFFFE0000000000 : 0xFFFFFD8000000000) +
   0x200000 * thread_current->tid;
 { state->state.rax = 0; return; };
}

canonical_original_code:
void syscall_ipc_buffer_get(struct cpu_int_state_t *state) {
 unsigned char buffer = state->state.rbx;
 if (buffer > 2)
  { state->state.rax = 1; return; };
 state->state.rbx = ((buffer == 0) ? 0xFFFFFE0000000000 : 0xFFFFFD8000000000) +
   0x200000 * thread_current->tid;
 { state->state.rax = 0; return; };
}

variable_types:
buffer
unsigned char


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

result = process_current;
*(_QWORD *)(process_current + 24) = *(_QWORD *)(a1 + 112);
*(_QWORD *)(a1 + 120) = 0LL;
return result;
}

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

result = process_current;
*(_QWORD *)(process_current + 24) = *(_QWORD *)(a1 + 112);
*(_QWORD *)(a1 + 120) = 0LL;
return result;
}

original_code:
void syscall_ipc_handler(cpu_int_state_t *state) {
 uintptr_t handler = state->state.rbx;
 process_current->message_handler = handler;
 { state->state.rax = 0; return; };
}

canonical_original_code:
void syscall_ipc_handler(struct cpu_int_state_t *state) {
 unsigned long long handler = state->state.rbx;
 process_current->message_handler = handler;
 { state->state.rax = 0; return; };
}

variable_types:
handler
unsigned long long


fwrite

original_code:
size_t fwrite(const void *array, size_t size, size_t count, FILE *stream) {
    mutex_lock(&stream->lock);
    if (0 == stream->callback_write) {
        mutex_unlock(&stream->lock);
        return 0;
    }
    size_t length = size * count;
    if (0 == stream->buffer_mode) {
        void *buffer = (void *) ((uintptr_t) stream->buffer + stream->buffer_len);
        size_t buffer_remaining = stream->buffer_size - stream->buffer_len;
        while (length > 0) {
            size_t to_copy = (length > buffer_remaining)
                    ? buffer_remaining : length;
            memcpy(buffer, array, to_copy);
            length -= to_copy;
            stream->buffer_len += to_copy;
            if (stream->buffer_len >= stream->buffer_size && length > 0) {
                __stdio_write(stream, stream->buffer_size, stream->buffer);
                buffer = stream->buffer;
                buffer_remaining = stream->buffer_size;
                stream->buffer_len = 0;
            }
        }
    } else if (2 == stream->buffer_mode) {
        __stdio_write(stream, length, array);
    } else if (1 == stream->buffer_mode) {
        size_t last_nl_offset = 0;
        const char *chars = (const char *) array;
        for (last_nl_offset = length - 1; last_nl_offset > 0; --last_nl_offset) {
            if ('\n' == chars[last_nl_offset])
                break;
        }
        if (-1 != last_nl_offset) {
            __stdio_write(stream, stream->buffer_len, stream->buffer);
            stream->buffer_len = 0;
            __stdio_write(stream, last_nl_offset + 1, array);
            length -= last_nl_offset + 1;
            array = (void *) ((uintptr_t) array + last_nl_offset + 1);
        }
        if (length <= stream->buffer_size) {
            memcpy(stream->buffer, array, length);
            stream->buffer_len = length;
        } else {
            __stdio_write(stream, length, array);
        }
    }
    mutex_unlock(&stream->lock);
    return size;
}

canonical_original_code:
unsigned long long fwrite(void *array, unsigned long long size, unsigned long long count, struct __file *stream) {
    mutex_lock(&stream->lock);
    if (0 == stream->callback_write) {
        mutex_unlock(&stream->lock);
        return 0;
    }
    unsigned long long length = size * count;
    if (0 == stream->buffer_mode) {
        void *buffer = (void *) ((uintptr_t) stream->buffer + stream->buffer_len);
        unsigned long long buffer_remaining = stream->buffer_size - stream->buffer_len;
        while (length > 0) {
            unsigned long long to_copy = (length > buffer_remaining)
                    ? buffer_remaining : length;
            memcpy(buffer, array, to_copy);
            length -= to_copy;
            stream->buffer_len += to_copy;
            if (stream->buffer_len >= stream->buffer_size && length > 0) {
                __stdio_write(stream, stream->buffer_size, stream->buffer);
                buffer = stream->buffer;
                buffer_remaining = stream->buffer_size;
                stream->buffer_len = 0;
            }
        }
    } else if (2 == stream->buffer_mode) {
        __stdio_write(stream, length, array);
    } else if (1 == stream->buffer_mode) {
        unsigned long long last_nl_offset = 0;
        char *chars = (const char *) array;
        for (last_nl_offset = length - 1; last_nl_offset > 0; --last_nl_offset) {
            if ('\n' == chars[last_nl_offset])
                break;
        }
        if (-1 != last_nl_offset) {
            __stdio_write(stream, stream->buffer_len, stream->buffer);
            stream->buffer_len = 0;
            __stdio_write(stream, last_nl_offset + 1, array);
            length -= last_nl_offset + 1;
            array = (void *) ((unsigned long long) array + last_nl_offset + 1);
        }
        if (length <= stream->buffer_size) {
            memcpy(stream->buffer, array, length);
            stream->buffer_len = length;
        } else {
            __stdio_write(stream, length, array);
        }
    }
    mutex_unlock(&stream->lock);
    return size;
}

variable_types:
array
void *

variable_types:
size
unsigned long long

variable_types:
count
unsigned long long

variable_types: struct __file { unsigned long long descriptor; unsigned int lock; unsigned long long position; unsigned char flags; void *buffer; unsigned long long buffer_len; unsigned long long buffer_size; unsigned char buffer_mode; void (*callback_write)(struct __file *, unsigned long long pos, unsigned long long size, void *data); unsigned long long (*callback_read)(struct __file *, unsigned long long pos, unsigned long long size, void *data); unsigned long long (*callback_length)(struct __file *); struct __file *next; } *

variable_types:
length
unsigned long long

variable_types:
buffer
void *

variable_types:
chars
char *


strtod

decompiled_code:
double __fastcall strtod(const char *a1, char **a2)
{
return strtold(a1, a2);
}

canonical_decompiled_code:
double __fastcall func0(const char *a1, char **a2)
{
return strtold(a1, a2);
}

original_code:
double strtod(const char *str, char **endptr) {
 return strtold(str, endptr);
}

canonical_original_code:
double strtod(char *str, char **endptr) {
 return strtold(str, endptr);
}

variable_types:
str
char *

variable_types:
endptr
char **


printf

decompiled_code:
int printf(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stdout, format, arg);
}

canonical_decompiled_code:
int func0(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
return vfprintf(stdout, format, arg);
}

original_code:
int printf(const char *format, ...) {
    va_list args;
    __builtin_va_start(args, format);
    int ret = vfprintf(stdout, format, args);
    __builtin_va_end(args);
    return ret;
}

canonical_original_code:
int printf(char *format, ...) {
    __builtin_va_list args;
    __builtin_va_start(args, format);
    int ret = vfprintf(stdout, format, args);
    __builtin_va_end(args);
    return ret;
}

variable_types:
format
char *

variable_types: ret int


strncpy

decompiled_code:
__int64 __fastcall strncpy(__int64 a1, char *a2, unsigned __int64 a3)
{
char v4; // dl
unsigned __int64 v5; // rax
_BYTE *v6; // rdx

v4 = *a2;
if ( *a2 )
{
if ( !a3 )
return a1;
v5 = 0LL;
while ( 1 )
{
*(_BYTE *)(a1 + v5++) = v4;
v4 = a2[v5];
if ( !v4 )
break;
if ( a3 == v5 )
return a1;
}
}
else
{
v5 = 0LL;
}
v6 = (_BYTE *)(a1 + v5);
if ( a3 > v5 )
{
do
*v6++ = 0;
while ( (_BYTE *)(a1 + a3) != v6 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, unsigned __int64 a3)
{
char v4; // dl
unsigned __int64 v5; // rax
_BYTE *v6; // rdx

v4 = *a2;
if ( *a2 )
{
if ( !a3 )
return a1;
v5 = 0LL;
while ( 1 )
{
*(_BYTE *)(a1 + v5++) = v4;
v4 = a2[v5];
if ( !v4 )
break;
if ( a3 == v5 )
return a1;
}
}
else
{
v5 = 0LL;
}
v6 = (_BYTE *)(a1 + v5);
if ( a3 > v5 )
{
do
*v6++ = 0;
while ( (_BYTE *)(a1 + a3) != v6 );
}
return a1;
}

original_code:
char *strncpy(char *d, const char *s, size_t n) {
 size_t i;
 for (i = 0; s[i] != '\0' && i < n; i++) {
  d[i] = s[i];
 }
 for (; i < n; i++) {
  d[i] = '\0';
 }
 return d;
}

canonical_original_code:
char *strncpy(char *d, char *s, unsigned long long n) {
 unsigned long long i;
 for (i = 0; s[i] != '\0' && i < n; i++) {
  d[i] = s[i];
 }
 for (; i < n; i++) {
  d[i] = '\0';
 }
 return d;
}

variable_types:
d
char *

variable_types:
s
char *

variable_types:
n
unsigned long long

variable_types:
i
unsigned long long


llabs

decompiled_code:
unsigned __int64 __fastcall llabs(__int64 a1)
{
return abs64(a1);
}

original_code:
long long int llabs(long long int number) {
 if (number >= 0)
  return number;
 else
  return -number;
}

canonical_original_code:
long long llabs(long long number) {
 if (number >= 0)
  return number;
 else
  return -number;
}

variable_types:
number
long long

return_type: long long


strncmp

decompiled_code:
__int64 __fastcall strncmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
char v5; // dl
char v6; // r8
__int64 result; // rax

if ( !a3 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
v6 = *(_BYTE *)(a2 + v4);
if ( v5 != v6 )
break;
if ( v5 )
{
if ( a3 != ++v4 )
continue;
}
return 0LL;
}
result = 0xFFFFFFFFLL;
if ( v5 && (v5 >= v6 || !v6) )
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
char v5; // dl
char v6; // r8
__int64 result; // rax

if ( !a3 )
return 0LL;
v4 = 0LL;
while ( 1 )
{
v5 = *(_BYTE *)(a1 + v4);
v6 = *(_BYTE *)(a2 + v4);
if ( v5 != v6 )
break;
if ( v5 )
{
if ( a3 != ++v4 )
continue;
}
return 0LL;
}
result = 0xFFFFFFFFLL;
if ( v5 && (v5 >= v6 || !v6) )
result = 1LL;
return result;
}

original_code:
int strncmp(const char *s1, const char *s2, size_t n) {
 size_t i;
 for (i = 0; i < n; i++) {
  if (s1[i] == s2[i]) {
   if (s1[i] == '\0') return 0;
   continue;
  }
  if (s1[i] == '\0') return -1;
  if (s2[i] == '\0') return 1;
  if (s1[i] < s2[i]) return -1;
  else return 1;
 }
 return 0;
}

canonical_original_code:
int strncmp(char *s1, char *s2, unsigned long long n) {
 unsigned long long i;
 for (i = 0; i < n; i++) {
  if (s1[i] == s2[i]) {
   if (s1[i] == '\0') return 0;
   continue;
  }
  if (s1[i] == '\0') return -1;
  if (s2[i] == '\0') return 1;
  if (s1[i] < s2[i]) return -1;
  else return 1;
 }
 return 0;
}


div

decompiled_code:
__int64 __fastcall div(int a1, int a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(a1 >> 31);
LODWORD(v2) = a1 % a2;
return (v2 << 32) | (unsigned int)(a1 / a2);
}

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

v2 = (unsigned int)(a1 >> 31);
LODWORD(v2) = a1 % a2;
return (v2 << 32) | (unsigned int)(a1 / a2);
}

original_code:
div_t div(int numerator, int denominator) {
 div_t result;
 result.quot = numerator / denominator;
 result.rem = numerator % denominator;
 return result;
}

canonical_original_code:
struct div_t div(int numerator, int denominator) {
 struct div_t result;
 result.quot = numerator / denominator;
 result.rem = numerator % denominator;
 return result;
}

variable_types: numerator int

variable_types: denominator int

variable_types:
result
struct div_t { int quot; int rem; }

return_type: struct div_t { int quot; int rem; }


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

v0 = heap_alloc(104LL);
memset((void *)v0, 0, 0x68uLL);
*(_QWORD *)(v0 + 4) = &stack_runtime_top;
memset((void *)0xFFFFFF7FFFFFD032LL, 0, 0x10uLL);
MEMORY[0xFFFFFF7FFFFFD034] = v0;
MEMORY[0xFFFFFF7FFFFFD036] = BYTE2(v0);
MEMORY[0xFFFFFF7FFFFFD037] |= 0xE9u;
MEMORY[0xFFFFFF7FFFFFD039] = BYTE3(v0);
MEMORY[0xFFFFFF7FFFFFD03A] = HIDWORD(v0);
MEMORY[0xFFFFFF7FFFFFD032] = 104;
return cpu_tss_load();
}

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

v0 = heap_alloc(104LL);
memset((void *)v0, 0, 0x68uLL);
*(_QWORD *)(v0 + 4) = &stack_runtime_top;
memset((void *)0xFFFFFF7FFFFFD032LL, 0, 0x10uLL);
MEMORY[0xFFFFFF7FFFFFD034] = v0;
MEMORY[0xFFFFFF7FFFFFD036] = BYTE2(v0);
MEMORY[0xFFFFFF7FFFFFD037] |= 0xE9u;
MEMORY[0xFFFFFF7FFFFFD039] = BYTE3(v0);
MEMORY[0xFFFFFF7FFFFFD03A] = HIDWORD(v0);
MEMORY[0xFFFFFF7FFFFFD032] = 104;
return cpu_tss_load();
}

original_code:
void cpu_tss_create(void) {
    cpu_tss_t *tss = (cpu_tss_t *) heap_alloc(sizeof(cpu_tss_t));
    memset((void *) tss, 0, sizeof(cpu_tss_t));
    tss->rsp0 = (uintptr_t) &stack_runtime_top;
    uintptr_t tss_addr = (uintptr_t) tss;
    cpu_tss_ptr_t *ptr = (cpu_tss_ptr_t *) ((0xFFFFFF8000000000 - 0x003000) + 0xA + 0x28);
    memset((void *) ptr, 0, sizeof(cpu_tss_ptr_t));
    ptr->baseLow = tss_addr & 0xFFFF;
    ptr->baseMiddleLow = (tss_addr >> 16) & 0xFF;
    ptr->baseMiddleHigh = (tss_addr >> 24) & 0xFF;
    ptr->baseHigh = (tss_addr >> 32) & 0xFFFFFFFF;
    ptr->limitLow = sizeof(cpu_tss_t);
    ptr->flags |=
        0x09 |
        (1 << 7) |
        (3 << 5);
    cpu_tss_load();
}

canonical_original_code:
void cpu_tss_create() {
    struct cpu_tss_t *tss = (cpu_tss_t *) heap_alloc(sizeof(cpu_tss_t));
    memset((void *) tss, 0, sizeof(cpu_tss_t));
    tss->rsp0 = (unsigned long long) &stack_runtime_top;
    unsigned long long tss_addr = (uintptr_t) tss;
    struct cpu_tss_ptr_t *ptr = (cpu_tss_ptr_t *) ((0xFFFFFF8000000000 - 0x003000) + 0xA + 0x28);
    memset((void *) ptr, 0, sizeof(cpu_tss_ptr_t));
    ptr->baseLow = tss_addr & 0xFFFF;
    ptr->baseMiddleLow = (tss_addr >> 16) & 0xFF;
    ptr->baseMiddleHigh = (tss_addr >> 24) & 0xFF;
    ptr->baseHigh = (tss_addr >> 32) & 0xFFFFFFFF;
    ptr->limitLow = sizeof(cpu_tss_t);
    ptr->flags |=
        0x09 |
        (1 << 7) |
        (3 << 5);
    cpu_tss_load();
}

variable_types: struct cpu_tss_t { unsigned int reserved0; unsigned long long rsp0; unsigned long long rsp1; unsigned long long rsp2; unsigned long long reserved1; unsigned long long ist1; unsigned long long ist2; unsigned long long ist3; unsigned long long ist4; unsigned long long ist5; unsigned long long ist6; unsigned long long ist7; unsigned long long reserved2; unsigned short reserved3; unsigned short io_map_base; } *

variable_types: struct cpu_tss_ptr_t { unsigned short limitLow; unsigned short baseLow; unsigned char baseMiddleLow; unsigned char flags; unsigned char flags_limitHigh; unsigned char baseMiddleHigh; unsigned int baseHigh; unsigned int reserved; } *


vsprintf

decompiled_code:
__int64 __fastcall vsprintf(char *dest, char *a2, __int64 a3)
{
char v3; // al
__int64 v4; // rdx
__int64 v5; // rbx
const char *v6; // rax
char *v7; // r15
__int64 v9; // [rsp+8h] [rbp-50h] BYREF
char src[2]; // [rsp+16h] [rbp-42h] BYREF
__int64 v11[8]; // [rsp+18h] [rbp-40h] BYREF

v9 = a3;
strcpy(dest, &::src);
v3 = *a2;
src[1] = 0;
if ( v3 )
{
v4 = (__int64)a2;
v5 = 0LL;
while ( 1 )
{
while ( v3 != 37 )
{
src[0] = v3;
strcat(dest, src);
LABEL_4:
v4 = (__int64)&a2[++v5];
v3 = a2[v5];
if ( !v3 )
return (unsigned int)v5;
}
v11[0] = v4;
v6 = (const char *)_format(v11, &v9);
v7 = (char *)v6;
v5 = v11[0] - (_QWORD)a2;
if ( !v6 )
goto LABEL_4;
++v5;
strcat(dest, v6);
free(v7);
v4 = (__int64)&a2[v5];
v3 = a2[v5];
if ( !v3 )
return (unsigned int)v5;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *dest, char *a2, __int64 a3)
{
char v3; // al
__int64 v4; // rdx
__int64 v5; // rbx
const char *v6; // rax
char *v7; // r15
__int64 v9; // [rsp+8h] [rbp-50h] BYREF
char src[2]; // [rsp+16h] [rbp-42h] BYREF
__int64 v11[8]; // [rsp+18h] [rbp-40h] BYREF

v9 = a3;
strcpy(dest, &::src);
v3 = *a2;
src[1] = 0;
if ( v3 )
{
v4 = (__int64)a2;
v5 = 0LL;
while ( 1 )
{
while ( v3 != 37 )
{
src[0] = v3;
strcat(dest, src);
LABEL_4:
v4 = (__int64)&a2[++v5];
v3 = a2[v5];
if ( !v3 )
return (unsigned int)v5;
}
v11[0] = v4;
v6 = (const char *)_format(v11, &v9);
v7 = (char *)v6;
v5 = v11[0] - (_QWORD)a2;
if ( !v6 )
goto LABEL_4;
++v5;
strcat(dest, v6);
free(v7);
v4 = (__int64)&a2[v5];
v3 = a2[v5];
if ( !v3 )
return (unsigned int)v5;
}
}
return 0LL;
}

original_code:
int vsprintf(char *str, const char *format, va_list ap) {
    size_t i;
    const char *format_tmp;
    char m[2];
    char *string;
    strcpy(str, "");
    m[1] = '\0';
    for (i = 0; format[i]; i++) {
        if (format[i] == '%') {
            format_tmp = &format[i];
            string = __format(&format_tmp, &ap);
            i = (uintptr_t) format_tmp - (uintptr_t) format;
            if (!string) continue;
            strcat(str, string);
            free(string);
        }
        else {
            m[0] = format[i];
            strcat(str, m);
        }
    }
    return i;
}

canonical_original_code:
int vsprintf(char *str, char *format, __builtin_va_list ap) {
    unsigned long long i;
    char *format_tmp;
    char m[2];
    char *string;
    strcpy(str, "");
    m[1] = '\0';
    for (i = 0; format[i]; i++) {
        if (format[i] == '%') {
            format_tmp = &format[i];
            string = __format(&format_tmp, &ap);
            i = (unsigned long long) format_tmp - (unsigned long long) format;
            if (!string) continue;
            strcat(str, string);
            free(string);
        }
        else {
            m[0] = format[i];
            strcat(str, m);
        }
    }
    return i;
}

variable_types:
m
char [2]

variable_types:
string
char *


strcspn

original_code:
size_t strcspn(const char *s, const char *reject) {
 uint16_t mask[16];
 size_t i;
 memclr(mask, sizeof(uint16_t) * 16);
 for (i = 0; reject[i]; i++) {
  mask[(size_t) reject[i] >> 4] |= (1 << ((size_t) reject[i] & 0xF));
 }
 for (i = 0; s[i]; i++) {
  if (mask[(size_t) s[i] >> 4] & (1 << ((size_t) s[i] & 0xF))) {
   break;
  }
 }
 return i;
}

canonical_original_code:
unsigned long long strcspn(char *s, char *reject) {
 unsigned short mask[16];
 unsigned long long i;
 memclr(mask, sizeof(unsigned short) * 16);
 for (i = 0; reject[i]; i++) {
  mask[(unsigned long long) reject[i] >> 4] |= (1 << ((unsigned long long) reject[i] & 0xF));
 }
 for (i = 0; s[i]; i++) {
  if (mask[(unsigned long long) s[i] >> 4] & (1 << ((unsigned long long) s[i] & 0xF))) {
   break;
  }
 }
 return i;
}

variable_types:
reject
char *

variable_types:
mask
unsigned short [16]


decompiled_code:
__int64 __fastcall syscall_futex_wait(_QWORD *a1)
{
unsigned __int64 v2; // rbx
__int64 v3; // r12
__int64 result; // rax
__int64 v5; // rdi
__int64 v6; // rax

v2 = a1[9];
v3 = a1[14];
result = memory_user_accessible(v2 & 0xFFFFFFFFFFFFF000LL);
if ( (_BYTE)result && *(_DWORD *)v2 == (_DWORD)v3 )
{
v5 = thread_current;
*(_QWORD *)(thread_current + 32LL) = v2;
*(_BYTE *)(v5 + 24) = 3;
thread_freeze();
a1[15] = 1LL;
v6 = scheduler_next();
result = thread_switch(v6, a1);
}
else
{
a1[15] = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
unsigned __int64 v2; // rbx
__int64 v3; // r12
__int64 result; // rax
__int64 v5; // rdi
__int64 v6; // rax

v2 = a1[9];
v3 = a1[14];
result = memory_user_accessible(v2 & 0xFFFFFFFFFFFFF000LL);
if ( (_BYTE)result && *(_DWORD *)v2 == (_DWORD)v3 )
{
v5 = thread_current;
*(_QWORD *)(thread_current + 32LL) = v2;
*(_BYTE *)(v5 + 24) = 3;
thread_freeze();
a1[15] = 1LL;
v6 = scheduler_next();
result = thread_switch(v6, a1);
}
else
{
a1[15] = 0LL;
}
return result;
}

original_code:
void syscall_futex_wait(cpu_int_state_t *state) {
    uintptr_t futex_vaddr = state->state.rsi;
    uint32_t value_cmp = (uint32_t) state->state.rbx;
    if (!memory_user_accessible(futex_vaddr & ~0xFFF)) {
        state->state.rax = 0;
        return;
    }
    uint32_t *futex = (uint32_t *) futex_vaddr;
    if (value_cmp != *futex) {
        state->state.rax = 0;
        return;
    }
    thread_current->sleep_mode = 3;
    thread_current->sleep_ctx = (void *) futex_vaddr;
    thread_freeze(thread_current);
    state->state.rax = 1;
    thread_switch(scheduler_next(), state);
}

canonical_original_code:
void syscall_futex_wait(struct cpu_int_state_t *state) {
    unsigned long long futex_vaddr = state->state.rsi;
    unsigned int value_cmp = (uint32_t) state->state.rbx;
    if (!memory_user_accessible(futex_vaddr & ~0xFFF)) {
        state->state.rax = 0;
        return;
    }
    unsigned int *futex = (uint32_t *) futex_vaddr;
    if (value_cmp != *futex) {
        state->state.rax = 0;
        return;
    }
    thread_current->sleep_mode = 3;
    thread_current->sleep_ctx = (void *) futex_vaddr;
    thread_freeze(thread_current);
    state->state.rax = 1;
    thread_switch(scheduler_next(), state);
}

variable_types: struct cpu_int_state_t { unsigned long long ds; struct cpu_state_t { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rsi; unsigned long long rdi; unsigned long long rbp; unsigned long long rdx; unsigned long long rcx; unsigned long long rbx; unsigned long long rax; } state; unsigned long long vector; unsigned long long error_code; unsigned long long rip; unsigned long long cs; unsigned long long flags; unsigned long long rsp; unsigned long long ss; } *

variable_types:
futex
unsigned int *


rand

decompiled_code:
unsigned __int64 rand()
{
unsigned __int64 v0; // rax

v0 = (0x5DEECE66DLL * rand_seed + 11) & 0xFFFFFFFFFFFFLL;
rand_seed = -554899859 * rand_seed + 11;
return v0 >> 16;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
unsigned __int64 v0; // rax

v0 = (0x5DEECE66DLL * rand_seed + 11) & 0xFFFFFFFFFFFFLL;
rand_seed = -554899859 * rand_seed + 11;
return v0 >> 16;
}

original_code:
int rand(void) {
    uint64_t next;
    rand_seed = next = (25214903917 * rand_seed + 11) % 0x1000000000000;
    return (int) ((next >> 16) & 0xFFFFFFFF);
}

canonical_original_code:
int rand() {
    unsigned long long next;
    rand_seed = next = (25214903917 * rand_seed + 11) % 0x1000000000000;
    return (int) ((next >> 16) & 0xFFFFFFFF);
}

variable_types:
next
unsigned long long


init

decompiled_code:
void init()
{
const char **v0; // rdx

stdout = (struct _IO_FILE *)(_stdout_write + 1);
stdout = (__int64)&stdout;
stdout->_IO_write_base = (char *)&stdout_buf;
stdout->_IO_buf_end = (char *)_stdout_write;
LODWORD(stdout->_IO_read_ptr) = 0;
stdout->_IO_read_end = 0LL;
LOBYTE(stdout->_IO_read_base) = 0;
stdout->_IO_write_ptr = 0LL;
stdout->_IO_write_end = (char *)512;
LOBYTE(stdout->_IO_buf_base) = 2;
stdout->_IO_backup_base = 0LL;
stdout->_IO_save_base = 0LL;
stdout->_IO_save_end = 0LL;
stderr = &stderr;
memcpy(&stderr, &stdout, 0x60uLL);
stderr->_IO_buf_end = (char *)_stderr_write;
stderr = (struct _IO_FILE *)(_stdout_write + 2);
stderr->_IO_write_base = (char *)&stderr_buf;
main(0, 0LL, v0);
process_exit();
JUMPOUT(0x106LL);
}

canonical_decompiled_code:
void func2()
{
const char **v0; // rdx

stdout = (struct _IO_FILE *)(_stdout_write + 1);
stdout = (__int64)&stdout;
stdout->_IO_write_base = (char *)&stdout_buf;
stdout->_IO_buf_end = (char *)_stdout_write;
LODWORD(stdout->_IO_read_ptr) = 0;
stdout->_IO_read_end = 0LL;
LOBYTE(stdout->_IO_read_base) = 0;
stdout->_IO_write_ptr = 0LL;
stdout->_IO_write_end = (char *)512;
LOBYTE(stdout->_IO_buf_base) = 2;
stdout->_IO_backup_base = 0LL;
stdout->_IO_save_base = 0LL;
stdout->_IO_save_end = 0LL;
stderr = &stderr;
memcpy(&stderr, &stdout, 0x60uLL);
stderr->_IO_buf_end = (char *)_stderr_write;
stderr = (struct _IO_FILE *)(_stdout_write + 2);
stderr->_IO_write_base = (char *)&stderr_buf;
main(0, 0LL, v0);
process_exit();
JUMPOUT(0x106LL);
}

original_code:
int init(uint32_t mboot_magic, multiboot_info_t *mboot_info) {
    {};;
    {};;
    {};;
    {};;
    {};;
    if (mboot_magic != 0x2BADB002)
        {};;
    boot_info_t *info = boot_info_parse(mboot_info);
    frame_placement = memalign(boot_modules_relocate(info, (uintptr_t) &end), 0x1000);
    boot_modules_map(info);
    {};;
    {};;
    {};;
    {};;
    {};;
    boot_info_mod_t *kernel_mod = _boot_find_kernel(info);
    if (0 == kernel_mod)
        {};;
    memory_map_system(info);
    uint16_t pflags = (1 << 8);
    info->entry_point = binary_load_elf64((void *) (uintptr_t) kernel_mod->address, pflags);
    {};;
    {};;
    {};;
    info->free_mem_begin = memalign(frame_placement, 0x1000);
    boot_trampoline_callback = info->entry_point;
    boot_info_relocate(info, (0xFFFFFF8000000000 - 0x001000));
    return 0;
}

canonical_original_code:
int init(unsigned int mboot_magic, struct multiboot_info *mboot_info) {
    {};;
    {};;
    {};;
    {};;
    {};;
    if (mboot_magic != 0x2BADB002)
        {};;
    struct boot_info_t *info = boot_info_parse(mboot_info);
    frame_placement = memalign(boot_modules_relocate(info, (unsigned int) &end), 0x1000);
    boot_modules_map(info);
    {};;
    {};;
    {};;
    {};;
    {};;
    struct boot_info_mod_t *kernel_mod = _boot_find_kernel(info);
    if (0 == kernel_mod)
        {};;
    memory_map_system(info);
    unsigned short pflags = (1 << 8);
    info->entry_point = binary_load_elf64((void *) (unsigned int) kernel_mod->address, pflags);
    {};;
    {};;
    {};;
    info->free_mem_begin = memalign(frame_placement, 0x1000);
    boot_trampoline_callback = info->entry_point;
    boot_info_relocate(info, (0xFFFFFF8000000000 - 0x001000));
    return 0;
}

variable_types: struct multiboot_info { unsigned int flags; unsigned int mem_lower; unsigned int mem_upper; unsigned int boot_device; unsigned int cmdline; unsigned int mods_count; unsigned int mods_addr; union { struct multiboot_aout_symbol_table { unsigned int tabsize; unsigned int strsize; unsigned int addr; unsigned int reserved; } aout_sym; struct multiboot_elf_section_header_table { unsigned int num; unsigned int size; unsigned int addr; unsigned int shndx; } elf_sec; } u; unsigned int mmap_length; unsigned int mmap_addr; unsigned int drives_length; unsigned int drives_addr; unsigned int config_table; unsigned int boot_loader_name; unsigned int apm_table; unsigned int vbe_control_info; unsigned int vbe_mode_info; unsigned short vbe_mode; unsigned short vbe_interface_seg; unsigned short vbe_interface_off; unsigned short vbe_interface_len; } *

variable_types: struct boot_info_t { unsigned long long loader_name; unsigned long long args; unsigned long long entry_point; unsigned long long free_mem_begin; unsigned long long mmap; unsigned long long mods; } *

variable_types: struct boot_info_mod_t { unsigned long long address; unsigned long long mapping; unsigned long long length; unsigned long long name; unsigned long long next; } *

variable_types:
pflags
unsigned short

user_defined_types: struct multiboot_info { unsigned int flags; unsigned int mem_lower; unsigned int mem_upper; unsigned int boot_device; unsigned int cmdline; unsigned int mods_count; unsigned int mods_addr; union { struct multiboot_aout_symbol_table aout_sym; struct multiboot_elf_section_header_table elf_sec; } u; unsigned int mmap_length; unsigned int mmap_addr; unsigned int drives_length; unsigned int drives_addr; unsigned int config_table; unsigned int boot_loader_name; unsigned int apm_table; unsigned int vbe_control_info; unsigned int vbe_mode_info; unsigned short vbe_mode; unsigned short vbe_interface_seg; unsigned short vbe_interface_off; unsigned short vbe_interface_len; }


decompiled_code:
void *__fastcall frame_init(__int64 a1)
{
void *result; // rax
__int64 v2; // rbx
unsigned __int64 v3; // r13
unsigned __int64 v4; // rbp
unsigned __int64 v5; // r12
__int64 v6; // rdi

result = memalign(*(_QWORD *)(a1 + 24), 0x1000uLL);
v2 = *(_QWORD *)(a1 + 32);
if ( v2 )
{
v3 = (unsigned __int64)result;
do
{
while ( 1 )
{
if ( *(_BYTE *)(v2 + 16) == 1 )
{
v4 = *(_QWORD *)v2;
v5 = (*(_QWORD *)v2 + *(_QWORD *)(v2 + 8)) & 0xFFFFFFFFFFFFF000LL;
if ( v3 <= v5 )
{
if ( v3 >= v4 )
v4 = v3;
if ( v4 < v5 )
break;
}
}
v2 = *(_QWORD *)(v2 + 17);
if ( !v2 )
return result;
}
do
{
v6 = v4;
v4 += 4096LL;
result = frame_free(v6);
}
while ( v5 > v4 );
v2 = *(_QWORD *)(v2 + 17);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
void *result; // rax
__int64 v2; // rbx
unsigned __int64 v3; // r13
unsigned __int64 v4; // rbp
unsigned __int64 v5; // r12
__int64 v6; // rdi

result = memalign(*(_QWORD *)(a1 + 24), 0x1000uLL);
v2 = *(_QWORD *)(a1 + 32);
if ( v2 )
{
v3 = (unsigned __int64)result;
do
{
while ( 1 )
{
if ( *(_BYTE *)(v2 + 16) == 1 )
{
v4 = *(_QWORD *)v2;
v5 = (*(_QWORD *)v2 + *(_QWORD *)(v2 + 8)) & 0xFFFFFFFFFFFFF000LL;
if ( v3 <= v5 )
{
if ( v3 >= v4 )
v4 = v3;
if ( v4 < v5 )
break;
}
}
v2 = *(_QWORD *)(v2 + 17);
if ( !v2 )
return result;
}
do
{
v6 = v4;
v4 += 4096LL;
result = frame_free(v6);
}
while ( v5 > v4 );
v2 = *(_QWORD *)(v2 + 17);
}
while ( v2 );
}
return result;
}

original_code:
void frame_init(boot_info_t *info) {
 uintptr_t mem_begin = memalign(info->free_mem_begin, 0x1000);
 boot_info_mmap_t *mmap = info->mmap;
 while (0 != mmap) {
  if (1 == mmap->available) {
   uintptr_t addr_begin = mmap->address;
   if (addr_begin < mem_begin) addr_begin = mem_begin;
   uintptr_t addr_end = (mmap->address + mmap->length) & ~0xFFF;
   if (addr_end >= mem_begin) {
                uintptr_t addr;
                for (addr = addr_begin; addr < addr_end; addr += 0x1000) {
                    frame_free(addr);
                }
   }
  }
  mmap = mmap->next;
 }
}

canonical_original_code:
void frame_init(struct boot_info_t *info) {
 unsigned long long mem_begin = memalign(info->free_mem_begin, 0x1000);
 struct boot_info_mmap_t *mmap = info->mmap;
 while (0 != mmap) {
  if (1 == mmap->available) {
   unsigned long long addr_begin = mmap->address;
   if (addr_begin < mem_begin) addr_begin = mem_begin;
   unsigned long long addr_end = (mmap->address + mmap->length) & ~0xFFF;
   if (addr_end >= mem_begin) {
                unsigned long long addr;
                for (addr = addr_begin; addr < addr_end; addr += 0x1000) {
                    frame_free(addr);
                }
   }
  }
  mmap = mmap->next;
 }
}

variable_types: struct boot_info_t { char *loader_name; char *args; unsigned long long entry_point; unsigned long long free_mem_begin; struct boot_info_mmap_t { unsigned long long address; unsigned long long length; unsigned char available; struct boot_info_mmap_t *next; } *mmap; struct boot_info_mod_t { unsigned long long address; unsigned long long mapping; unsigned long long length; unsigned long long name; struct boot_info_mod_t *next; } *mods; } *

variable_types:
addr
unsigned long long

user_defined_types: struct boot_info_t { char *loader_name; char *args; unsigned long long entry_point; unsigned long long free_mem_begin; struct boot_info_mmap_t *mmap; struct boot_info_mod_t *mods; }


decompiled_code:
__int64 frame_alloc()
{
_QWORD *v0; // rdi
__int64 v1; // r12

v0 = frame_stack_free;
if ( !frame_stack_free )
{
console_print("PANIC: ");
console_print("Out of memory!");
console_print("\n");
while ( 1 )
;
}
v1 = *frame_stack_free;
frame_stack_free = (_QWORD *)frame_stack_free[1];
if ( v0 < frame_alloc_init || v0 > &frame_alloc_init[512] )
heap_free();
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
_QWORD *v0; // rdi
__int64 v1; // r12

v0 = frame_stack_free;
if ( !frame_stack_free )
{
console_print("PANIC: ");
console_print("Out of memory!");
console_print("\n");
while ( 1 )
;
}
v1 = *frame_stack_free;
frame_stack_free = (_QWORD *)frame_stack_free[1];
if ( v0 < frame_alloc_init || v0 > &frame_alloc_init[512] )
heap_free();
return v1;
}

original_code:
uintptr_t frame_alloc(void) {
 if (0 == frame_stack_free)
  { console_print("PANIC: "); console_print("Out of memory!"); console_print("\n"); while (1); };
 frame_stack_t *frame = frame_stack_free;
 frame_stack_free = frame->next;
 uintptr_t address = frame->address;
 if ((uintptr_t) frame < (uintptr_t) &frame_alloc_init ||
  (uintptr_t) frame > (uintptr_t) &frame_alloc_init + 0x1000)
  heap_free(frame);
    return address;
}

canonical_original_code:
unsigned long long frame_alloc() {
 if (0 == frame_stack_free)
  { console_print("PANIC: "); console_print("Out of memory!"); console_print("\n"); while (1); };
 struct frame_stack_t *frame = frame_stack_free;
 frame_stack_free = frame->next;
 unsigned long long address = frame->address;
 if ((unsigned long long) frame < (unsigned long long) &frame_alloc_init ||
  (unsigned long long) frame > (unsigned long long) &frame_alloc_init + 0x1000)
  heap_free(frame);
    return address;
}

variable_types: struct frame_stack_t { unsigned long long address; struct frame_stack_t *next; } *

variable_types:
address
unsigned long long


decompiled_code:
void *process_init()
{
__int64 v0; // rsi
__int64 v1; // rax

v0 = frame_alloc();
memory_map(0xFFFFFF7FFFFF9000LL, v0, 258LL);
v1 = frame_alloc();
memory_map(0xFFFFFF7FFFFFA000LL, v1, 258LL);
return memset((void *)0xFFFFFF7FFFFF9000LL, 0, 0x2000uLL);
}

canonical_decompiled_code:
void *func3()
{
__int64 v0; // rsi
__int64 v1; // rax

v0 = frame_alloc();
memory_map(0xFFFFFF7FFFFF9000LL, v0, 258LL);
v1 = frame_alloc();
memory_map(0xFFFFFF7FFFFFA000LL, v1, 258LL);
return memset((void *)0xFFFFFF7FFFFF9000LL, 0, 0x2000uLL);
}

original_code:
void process_init(void) {
    uintptr_t vaddr = (0xFFFFFF8000000000 - 0x007000);
    uint16_t pflags = (1 << 8) | (1 << 1);
    uintptr_t offset;
    for (offset = 0; offset < (1024 * sizeof(uintptr_t)); offset += 0x1000)
        memory_map(vaddr + offset, frame_alloc(), pflags);
    memset((void *) vaddr, 0, (1024 * sizeof(uintptr_t)));
}

canonical_original_code:
void process_init() {
    unsigned long long vaddr = (0xFFFFFF8000000000 - 0x007000);
    unsigned short pflags = (1 << 8) | (1 << 1);
    unsigned long long offset;
    for (offset = 0; offset < (1024 * sizeof(unsigned long long)); offset += 0x1000)
        memory_map(vaddr + offset, frame_alloc(), pflags);
    memset((void *) vaddr, 0, (1024 * sizeof(unsigned long long)));
}

variable_types:
vaddr
unsigned long long

variable_types:
offset
unsigned long long


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

if ( a1 > 0x3FF )
result = 0LL;
else
result = *(_QWORD *)(8LL * a1 - 0x8000007000LL);
return result;
}

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

if ( a1 > 0x3FF )
result = 0LL;
else
result = *(_QWORD *)(8LL * a1 - 0x8000007000LL);
return result;
}

original_code:
process_t *process_get(uint32_t pid) {
    if (pid >= 1024)
        return 0;
    return process_map[pid];
}

canonical_original_code:
struct process_t *process_get(unsigned int pid) {
    if (pid >= 1024)
        return 0;
    return process_map[pid];
}

variable_types:
pid
unsigned int

return_type: struct process_t { unsigned int pid; struct process_t *parent; unsigned short order; unsigned long long message_handler; unsigned char term_implicit; struct thread_t { unsigned int tid; unsigned int pid; unsigned char frozen; unsigned char ttl; unsigned char role; void *role_ctx; unsigned char sleep_mode; void *sleep_ctx; void *result_ptr; unsigned int ipc_buffer_sz[3]; unsigned char flags; unsigned long long entry_point; void *fx_data; struct cpu_int_state_t { unsigned long long ds; struct cpu_state_t { unsigned long long r15; unsigned long long r14; unsigned long long r13; unsigned long long r12; unsigned long long r11; unsigned long long r10; unsigned long long r9; unsigned long long r8; unsigned long long rsi; unsigned long long rdi; unsigned long long rbp; unsigned long long rdx; unsigned long long rcx; unsigned long long rbx; unsigned long long rax; } state; unsigned long long vector; unsigned long long error_code; unsigned long long rip; unsigned long long cs; unsigned long long flags; unsigned long long rsp; unsigned long long ss; } state; struct stack_t { unsigned long long address; unsigned long long length; } stack; struct thread_t *next_sched; struct thread_t *next; } *threads; unsigned long long addr_space; unsigned long long stack_offset; struct process_t *next; } *


srand

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

result = a1;
rand_seed = a1;
return result;
}

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

result = a1;
rand_seed = a1;
return result;
}

original_code:
void srand(unsigned int seed) {
 rand_seed = seed;
}

variable_types:
seed
unsigned int


memcpy

original_code:
void *memcpy(void *d, const void *s, size_t n) {
 size_t i;
 uint8_t *dst = (uint8_t*) d;
 uint8_t *src = (uint8_t*) s;
 for (i = 0; i < n; i++) {
  dst[i] = src[i];
 }
 return dst;
}

canonical_original_code:
void *memcpy(void *d, void *s, unsigned long long n) {
 unsigned long long i;
 unsigned char *dst = (uint8_t*) d;
 unsigned char *src = (uint8_t*) s;
 for (i = 0; i < n; i++) {
  dst[i] = src[i];
 }
 return dst;
}

variable_types:
d
void *

variable_types:
s
void *

variable_types:
n
unsigned long long

variable_types:
i
unsigned long long

variable_types:
dst
unsigned char *

variable_types:
src
unsigned char *

return_type: void *


bsearch

original_code:
const void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
  int (*cmp)(const void *keyval, const void *datum)) {
 size_t lower, upper;
 const uint8_t *array;
 int result;
 lower = 0;
 upper = nmemb;
 array = base;
 while (1) {
  result = cmp(key, &array[((lower + upper) / 2) * size]);
  if (result < 0) {
   upper = (lower + upper) / 2;
  }
  else if (result > 0) {
   lower = 1 + (lower + upper) / 2;
  }
  else {
   return &array[((lower + upper) / 2) * size];
  }
 }
}

canonical_original_code:
void *bsearch(void *key, void *base, unsigned long long nmemb, unsigned long long size, int (*cmp)(void *keyval, void *datum)) {
 unsigned long long lower; unsigned long long upper;
 unsigned char *array;
 int result;
 lower = 0;
 upper = nmemb;
 array = base;
 while (1) {
  result = cmp(key, &array[((lower + upper) / 2) * size]);
  if (result < 0) {
   upper = (lower + upper) / 2;
  }
  else if (result > 0) {
   lower = 1 + (lower + upper) / 2;
  }
  else {
   return &array[((lower + upper) / 2) * size];
  }
 }
}

variable_types:
key
void *

variable_types:
base
void *

variable_types:
nmemb
unsigned long long

variable_types:
size
unsigned long long

variable_types:
cmp
int (*)(void *keyval, void *datum)

variable_types:
lower
unsigned long long

variable_types:
upper
unsigned long long

variable_types:
array
unsigned char *

variable_types: result int


strspn

original_code:
size_t strspn(const char *s, const char *accept) {
 uint16_t mask[16];
 size_t i;
 memclr(mask, sizeof(uint16_t) * 16);
 for (i = 0; accept[i]; i++) {
  mask[(size_t) accept[i] >> 4] |= (1 << ((size_t) accept[i] & 0xF));
 }
 for (i = 0; s[i]; i++) {
  if (~mask[(size_t) s[i] >> 4] & (1 << ((size_t) s[i] & 0xF))) {
   break;
  }
 }
 return i;
}

canonical_original_code:
unsigned long long strspn(char *s, char *accept) {
 unsigned short mask[16];
 unsigned long long i;
 memclr(mask, sizeof(unsigned short) * 16);
 for (i = 0; accept[i]; i++) {
  mask[(unsigned long long) accept[i] >> 4] |= (1 << ((unsigned long long) accept[i] & 0xF));
 }
 for (i = 0; s[i]; i++) {
  if (~mask[(unsigned long long) s[i] >> 4] & (1 << ((unsigned long long) s[i] & 0xF))) {
   break;
  }
 }
 return i;
}

variable_types:
s
char *

variable_types:
accept
char *

variable_types:
mask
unsigned short [16]


decompiled_code:
__int64 __fastcall heap_free(unsigned __int64 a1)
{
__int64 result; // rax
__int64 v2; // rcx

result = *(unsigned __int16 *)((char *)heap_alloc_region + (a1 & 0xFFFFFFFFFFF00000LL | (a1 >> 8) & 0xFF0) + 2);
v2 = heap_slots[result];
heap_slots[result] = a1;
*(_QWORD *)a1 = v2;
return result;
}

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

result = *(unsigned __int16 *)((char *)heap_alloc_region + (a1 & 0xFFFFFFFFFFF00000LL | (a1 >> 8) & 0xFF0) + 2);
v2 = heap_slots[result];
heap_slots[result] = a1;
*(_QWORD *)a1 = v2;
return result;
}

original_code:
void heap_free(void *ptr) {
 uintptr_t region_addr = ((uintptr_t) ptr & ~0xfffff);
 uintptr_t slab_offset = ((uintptr_t) ptr & 0xfffff);
 heap_slab_t *slab = (heap_slab_t *) (region_addr + ((slab_offset & ~0xFFF) >> 8));
 heap_slot_t *slot = (heap_slot_t *) ptr;
 slot->next = heap_slots[slab->size_index];
 heap_slots[slab->size_index] = slot;
}

canonical_original_code:
void heap_free(void *ptr) {
 unsigned long long region_addr = ((uintptr_t) ptr & ~0xfffff);
 unsigned long long slab_offset = ((uintptr_t) ptr & 0xfffff);
 struct heap_slab_t *slab = (heap_slab_t *) (region_addr + ((slab_offset & ~0xFFF) >> 8));
 struct heap_slot_t *slot = (heap_slot_t *) ptr;
 slot->next = heap_slots[slab->size_index];
 heap_slots[slab->size_index] = slot;
}

variable_types:
ptr
void *

variable_types: struct heap_slab_t { unsigned short size; unsigned short size_index; unsigned int usecount; struct heap_slab_t *next; } *

variable_types: struct heap_slot_t { struct heap_slot_t *next; } *


fputs

decompiled_code:
__int64 __fastcall fputs(void *ptr, FILE *s)
{
size_t v2; // rax

v2 = strlen((const char *)ptr);
fwrite(ptr, v2, 1uLL, s);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr, FILE *s)
{
size_t v2; // rax

v2 = strlen((const char *)ptr);
fwrite(ptr, v2, 1uLL, s);
return 0LL;
}

original_code:
int fputs(const char *str, FILE *stream) {
    fwrite(str, strlen(str), sizeof(char), stream);
    return 0;
}

canonical_original_code:
int fputs(char *str, struct __file *stream) {
    fwrite(str, strlen(str), sizeof(char), stream);
    return 0;
}

variable_types:
str
char *

variable_types: struct __file { unsigned long long descriptor; unsigned int lock; unsigned long long position; unsigned char flags; void *buffer; unsigned long long buffer_len; unsigned long long buffer_size; unsigned char buffer_mode; void (*callback_write)(struct __file *, unsigned long long pos, unsigned long long size, void *data); unsigned long long (*callback_read)(struct __file *, unsigned long long pos, unsigned long long size, void *data); unsigned long long (*callback_length)(struct __file *); struct __file *next; } *


strtoull

decompiled_code:
__int64 __fastcall strtoull(_BYTE *a1, _QWORD *a2, unsigned int a3)
{
unsigned int v3; // er14
__int64 v5; // rbx
__int64 v6; // rax
_BYTE *v7; // r13
char *v8; // r15
__int64 v9; // rdi
__int64 v10; // rbp
__int64 v11; // rbx
__int64 v12; // rdi
int v13; // eax
__int64 result; // rax
char v15; // [rsp+Fh] [rbp-39h]

v3 = a3;
if ( (ctype_tbl[2 * (unsigned __int8)*a1 + 1] & 2) != 0 )
{
v5 = 0LL;
do
v6 = (unsigned __int8)a1[++v5];
while ( (ctype_tbl[2 * v6 + 1] & 2) != 0 );
}
else
{
LOBYTE(v6) = *a1;
v5 = 0LL;
}
if ( (_BYTE)v6 == 43 )
{
v15 = 0;
++v5;
}
else if ( (_BYTE)v6 == 45 )
{
v15 = 1;
++v5;
}
v7 = &a1[v5];
v8 = &a1[v5];
if ( a3 )
goto LABEL_12;
if ( *v7 != 48 )
{
if ( !(unsigned __int8)_isbdigit((unsigned int)(char)*v7, 10LL) )
goto LABEL_23;
v3 = 10;
LABEL_12:
v9 = (unsigned int)(char)*v7;
if ( !*v7 )
{
v11 = 0LL;
goto LABEL_16;
}
LABEL_13:
v10 = (__int64)&a1[v5 + 1];
v11 = 0LL;
do
{
if ( !(unsigned __int8)_isbdigit(v9, v3) )
break;
v12 = (unsigned int)*v8;
v8 = (char *)v10++;
v13 = _digit(v12, v3);
v9 = (unsigned int)*(char *)(v10 - 1);
v11 = v13 + (int)v3 * v11;
}
while ( *(_BYTE *)(v10 - 1) );
LABEL_16:
if ( a2 )
*a2 = v8;
result = -v11;
if ( !v15 )
result = v11;
return result;
}
++v5;
v3 = 16;
v7 = &a1[v5];
v9 = (unsigned int)(char)a1[v5];
v8 = &a1[v5];
if ( a1[v5] == 120 )
goto LABEL_13;
if ( (unsigned __int8)_isbdigit(v9, 8LL) )
{
v3 = 8;
goto LABEL_12;
}
LABEL_23:
if ( a2 )
*a2 = v7;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _QWORD *a2, unsigned int a3)
{
unsigned int v3; // er14
__int64 v5; // rbx
__int64 v6; // rax
_BYTE *v7; // r13
char *v8; // r15
__int64 v9; // rdi
__int64 v10; // rbp
__int64 v11; // rbx
__int64 v12; // rdi
int v13; // eax
__int64 result; // rax
char v15; // [rsp+Fh] [rbp-39h]

v3 = a3;
if ( (ctype_tbl[2 * (unsigned __int8)*a1 + 1] & 2) != 0 )
{
v5 = 0LL;
do
v6 = (unsigned __int8)a1[++v5];
while ( (ctype_tbl[2 * v6 + 1] & 2) != 0 );
}
else
{
LOBYTE(v6) = *a1;
v5 = 0LL;
}
if ( (_BYTE)v6 == 43 )
{
v15 = 0;
++v5;
}
else if ( (_BYTE)v6 == 45 )
{
v15 = 1;
++v5;
}
v7 = &a1[v5];
v8 = &a1[v5];
if ( a3 )
goto LABEL_12;
if ( *v7 != 48 )
{
if ( !(unsigned __int8)_isbdigit((unsigned int)(char)*v7, 10LL) )
goto LABEL_23;
v3 = 10;
LABEL_12:
v9 = (unsigned int)(char)*v7;
if ( !*v7 )
{
v11 = 0LL;
goto LABEL_16;
}
LABEL_13:
v10 = (__int64)&a1[v5 + 1];
v11 = 0LL;
do
{
if ( !(unsigned __int8)_isbdigit(v9, v3) )
break;
v12 = (unsigned int)*v8;
v8 = (char *)v10++;
v13 = _digit(v12, v3);
v9 = (unsigned int)*(char *)(v10 - 1);
v11 = v13 + (int)v3 * v11;
}
while ( *(_BYTE *)(v10 - 1) );
LABEL_16:
if ( a2 )
*a2 = v8;
result = -v11;
if ( !v15 )
result = v11;
return result;
}
++v5;
v3 = 16;
v7 = &a1[v5];
v9 = (unsigned int)(char)a1[v5];
v8 = &a1[v5];
if ( a1[v5] == 120 )
goto LABEL_13;
if ( (unsigned __int8)_isbdigit(v9, 8LL) )
{
v3 = 8;
goto LABEL_12;
}
LABEL_23:
if ( a2 )
*a2 = v7;
return 0LL;
}

original_code:
unsigned long long int strtoull(const char *nptr, char **endptr, int base) {
 size_t i;
 int64_t sum;
 bool neg;
 i = 0;
 sum = 0;
 while ((_ctype_tbl[(unsigned char) (nptr[i])] & 0x200)) {
  i++;
 }
 if (nptr[i] == '+') {
  neg = 0;
  i++;
 }
 else if (nptr[i] == '-') {
  neg = 1;
  i++;
 }
 if (base == 0) {
  if (nptr[i] == '0') {
   i++;
   if (nptr[i] == 'x') {
    base = 16;
   }
   else if (__isbdigit(nptr[i], 8)) {
    base = 8;
   }
  }
  else if (__isbdigit(nptr[i], 10)) {
   base = 10;
  }
 }
 if (base == 0) {
  if (endptr) {
   *endptr = (char*) &nptr[i];
  }
  return 0;
 }
 while (nptr[i] && __isbdigit(nptr[i], base)) {
  sum *= base;
  sum += __digit(nptr[i], base);
  i++;
 }
 if (endptr) {
  *endptr = (char*) &nptr[i];
 }
 return (neg) ? -sum : sum;
}

canonical_original_code:
unsigned long long strtoull(char *nptr, char **endptr, int base) {
 unsigned long long i;
 long long sum;
 unsigned char neg;
 i = 0;
 sum = 0;
 while ((_ctype_tbl[(unsigned char) (nptr[i])] & 0x200)) {
  i++;
 }
 if (nptr[i] == '+') {
  neg = 0;
  i++;
 }
 else if (nptr[i] == '-') {
  neg = 1;
  i++;
 }
 if (base == 0) {
  if (nptr[i] == '0') {
   i++;
   if (nptr[i] == 'x') {
    base = 16;
   }
   else if (__isbdigit(nptr[i], 8)) {
    base = 8;
   }
  }
  else if (__isbdigit(nptr[i], 10)) {
   base = 10;
  }
 }
 if (base == 0) {
  if (endptr) {
   *endptr = (char *) &nptr[i];
  }
  return 0;
 }
 while (nptr[i] && __isbdigit(nptr[i], base)) {
  sum *= base;
  sum += __digit(nptr[i], base);
  i++;
 }
 if (endptr) {
  *endptr = (char *) &nptr[i];
 }
 return (neg) ? -sum : sum;
}

variable_types:
nptr
char *

variable_types:
endptr
char **

variable_types: base int

variable_types:
i
unsigned long long

variable_types:
sum
long long

variable_types:
neg
unsigned char


ldiv

decompiled_code:
__int64 __fastcall ldiv(__int64 a1, __int64 a2)
{
return a1 / a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return a1 / a2;
}

original_code:
ldiv_t ldiv(long int numerator, long int denominator) {
 ldiv_t result;
 result.quot = numerator / denominator;
 result.rem = numerator % denominator;
 return result;
}

canonical_original_code:
struct ldiv_t ldiv(long numerator, long denominator) {
 struct ldiv_t result;
 result.quot = numerator / denominator;
 result.rem = numerator % denominator;
 return result;
}

variable_types: numerator long

variable_types: denominator long

variable_types:
result
struct ldiv_t { long quot; long rem; }

return_type: struct ldiv_t { long quot; long rem; }


sprintf

decompiled_code:
int sprintf(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
return vsprintf(a1, a2, arg);
}

canonical_decompiled_code:
int func0(char *a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
return vsprintf(a1, a2, arg);
}

original_code:
int sprintf(char *str, const char *format, ...) {
    va_list args;
    __builtin_va_start(args, format);
    int ret = vsprintf(str, format, args);
    __builtin_va_end(args);
    return ret;
}

canonical_original_code:
int sprintf(char *str, char *format, ...) {
    __builtin_va_list args;
    __builtin_va_start(args, format);
    int ret = vsprintf(str, format, args);
    __builtin_va_end(args);
    return ret;
}

variable_types:
format
char *

variable_types: ret int