decompiled_code:
void term_release(void)
{
if ( claimed )
{
if ( !cleared_0 )
{
term_clear();
fflush(stdout);
cleared_0 = 1;
}
term_show_cursor(1);
tcsetattr(0, 0, &initial_tios);
print_flushed("\x1B[?1000;1002;1006;1015l");
}
}

canonical_decompiled_code:
void func9(void)
{
if ( claimed )
{
if ( !cleared_0 )
{
func2();
fflush(stdout);
cleared_0 = 1;
}
func8(1);
tcsetattr(0, 0, &initial_tios);
func1("\x1B[?1000;1002;1006;1015l");
}
}

original_code:
void term_release(void)
{
    static _Bool cleared = 0;
    if (!claimed)
        return;
    if (!cleared)
    {
        term_clear();
        fflush(stdout);
        cleared = 1;
    }
    term_show_cursor(1);
    tcsetattr(0, 0, &initial_tios);
    print_flushed("\033[?1000;1002;1006;1015l");
}

canonical_original_code:
void term_release()
{
    static _Bool cleared = 0;
    if (!claimed)
        return;
    if (!cleared)
    {
        term_clear();
        fflush(stdout);
        cleared = 1;
    }
    term_show_cursor(1);
    tcsetattr(0, 0, &initial_tios);
    print_flushed("\033[?1000;1002;1006;1015l");
}


repo: XanClic/standard

decompiled_code:
int term_init()
{
struct termios v1; // [rsp+0h] [rbp-58h] BYREF
__int16 v2[8]; // [rsp+48h] [rbp-10h] BYREF

terminfo_load();
ioctl(1, 0x5413uLL, v2);
term_width = (unsigned __int16)v2[1];
term_height = (unsigned __int16)v2[0];
tcgetattr(0, &initial_tios);
claimed = 1;
atexit(term_release);
*(__m128i *)&v1.c_iflag = _mm_load_si128((const __m128i *)&initial_tios);
*(__m128i *)&v1.c_line = _mm_load_si128((const __m128i *)&initial_tios.c_line);
*(__m128i *)&v1.c_cc[15] = _mm_load_si128((const __m128i *)&initial_tios.c_cc[15]);
*(_QWORD *)&v1.c_cc[31] = *(_QWORD *)&initial_tios.c_cc[31];
v1.c_ospeed = initial_tios.c_ospeed;
v1.c_lflag &= 0xFFFFFF85;
*(_WORD *)&v1.c_cc[5] = 257;
tcsetattr(0, 0, &v1);
setbuf(stdin, 0LL);
setvbuf(stdout, 0LL, 0, 0LL);
print_flushed("\x1B[?1000;1002;1006;1015h");
init_mouse_input_regex();
term_show_cursor(0);
return fflush(stdout);
}

canonical_decompiled_code:
int func10()
{
struct termios v1; // [rsp+0h] [rbp-58h] BYREF
__int16 v2[8]; // [rsp+48h] [rbp-10h] BYREF

terminfo_load();
ioctl(1, 0x5413uLL, v2);
term_width = (unsigned __int16)v2[1];
term_height = (unsigned __int16)v2[0];
tcgetattr(0, &initial_tios);
claimed = 1;
atexit(term_release);
*(__m128i *)&v1.c_iflag = _mm_load_si128((const __m128i *)&initial_tios);
*(__m128i *)&v1.c_line = _mm_load_si128((const __m128i *)&initial_tios.c_line);
*(__m128i *)&v1.c_cc[15] = _mm_load_si128((const __m128i *)&initial_tios.c_cc[15]);
*(_QWORD *)&v1.c_cc[31] = *(_QWORD *)&initial_tios.c_cc[31];
v1.c_ospeed = initial_tios.c_ospeed;
v1.c_lflag &= 0xFFFFFF85;
*(_WORD *)&v1.c_cc[5] = 257;
tcsetattr(0, 0, &v1);
setbuf(stdin, 0LL);
setvbuf(stdout, 0LL, 0, 0LL);
func1("\x1B[?1000;1002;1006;1015h");
init_mouse_input_regex();
func8(0);
return fflush(stdout);
}

original_code:
void term_init(void)
{
    terminfo_load();
    struct winsize ws;
    ioctl(1, 0x5413, &ws);
    term_width = ws.ws_col;
    term_height = ws.ws_row;
    tcgetattr(0, &initial_tios);
    claimed = 1;
    atexit(term_release);
    struct termios tios;
    memcpy(&tios, &initial_tios, sizeof(tios));
    tios.c_lflag &= ~(0000010 | 0000020 | 0000040 | 0000100 | 0000002);
    tios.c_cc[5] = 1;
    tios.c_cc[6] = 1;
    tcsetattr(0, 0, &tios);
    setbuf(stdin, ((void *)0));
    setvbuf(stdout, ((void *)0), 0, 0);
    print_flushed("\033[?1000;1002;1006;1015h");
    init_mouse_input_regex();
    term_show_cursor(0);
    fflush(stdout);
}

canonical_original_code:
void term_init()
{
    terminfo_load();
    struct winsize ws;
    ioctl(1, 0x5413, &ws);
    term_width = ws.ws_col;
    term_height = ws.ws_row;
    tcgetattr(0, &initial_tios);
    claimed = 1;
    atexit(term_release);
    struct termios tios;
    memcpy(&tios, &initial_tios, sizeof(tios));
    tios.c_lflag &= ~(0000010 | 0000020 | 0000040 | 0000100 | 0000002);
    tios.c_cc[5] = 1;
    tios.c_cc[6] = 1;
    tcsetattr(0, 0, &tios);
    setbuf(stdin, ((void *)0));
    setvbuf(stdout, ((void *)0), 0, 0);
    print_flushed("\033[?1000;1002;1006;1015h");
    init_mouse_input_regex();
    term_show_cursor(0);
    fflush(stdout);
}

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: void


decompiled_code:
void __fastcall buf_edit(__int64 a1, __int64 a2, const char *a3)
{
__int64 v3; // rsi
const char *v4; // rdx

v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
if ( *(_QWORD *)(a1 + 16) )
{
error((int)"Only one file path allowed.", v3, a3);
}
else if ( *(_BYTE *)(active_buffer + 60LL) )
{
error((int)"%s has been modified.", *active_buffer, a3);
}
else if ( (unsigned __int8)buffer_load() )
{
update_active_buffer();
}
else
{
error((int)&unk_4D9, *(_QWORD *)(a1 + 8), v4);
}
}
else
{
error((int)"Expected a file path.", 0, a3);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2, const char *a3)
{
__int64 v3; // rsi
const char *v4; // rdx

v3 = *(_QWORD *)(a1 + 8);
if ( v3 )
{
if ( *(_QWORD *)(a1 + 16) )
{
error((int)"Only one file path allowed.", v3, a3);
}
else if ( *(_BYTE *)(active_buffer + 60LL) )
{
error((int)"%s has been modified.", *active_buffer, a3);
}
else if ( (unsigned __int8)buffer_load() )
{
update_active_buffer();
}
else
{
error((int)&unk_4D9, *(_QWORD *)(a1 + 8), v4);
}
}
else
{
error((int)"Expected a file path.", 0, a3);
}
}

original_code:
static void buf_edit(char **cmd_line)
{
    if (!(cmd_line[1])) { error("Expected a file path."); return; };
    if (!(!cmd_line[2])) { error("Only one file path allowed."); return; };
    if (!(!active_buffer->modified)) { error("%s has been modified.", active_buffer->name); return; };
    if (!(buffer_load(active_buffer, cmd_line[1]))) { error("Could not load “%s”.", cmd_line[1]); return; };
    update_active_buffer();
}


decompiled_code:
__int64 __fastcall raw_write(_QWORD *a1, __int64 a2, const char *a3)
{
_QWORD *v3; // rax
int v4; // er12
_QWORD *v5; // rbx
__int64 v6; // r13
unsigned int v7; // ebp
const char *v8; // rdx

if ( !*a1 )
{
LABEL_9:
if ( *(_QWORD *)(active_buffer + 8LL) )
{
v7 = buffer_write(active_buffer, 0LL);
if ( !(_BYTE)v7 )
error((int)&unk_4F2, *(_QWORD *)(active_buffer + 8LL), v8);
}
else
{
error((int)"No file associated with %s.", *active_buffer, a3);
v7 = 0;
}
return v7;
}
v3 = a1 + 1;
v4 = 0;
do
{
a3 = (const char *)(unsigned int)v4++;
++v3;
}
while ( *(v3 - 1) );
if ( (int)a3 <= 0 )
{
LABEL_8:
v7 = 1;
if ( v4 > 1 )
return v7;
goto LABEL_9;
}
v5 = &a1[(int)a3];
v6 = (__int64)&v5[-((_DWORD)a3 - 1) - 1];
while ( 1 )
{
v7 = buffer_write(active_buffer, *v5);
if ( !(_BYTE)v7 )
break;
if ( --v5 == (_QWORD *)v6 )
goto LABEL_8;
}
error((int)&unk_4F2, *v5, a3);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2, const char *a3)
{
_QWORD *v3; // rax
int v4; // er12
_QWORD *v5; // rbx
__int64 v6; // r13
unsigned int v7; // ebp
const char *v8; // rdx

if ( !*a1 )
{
LABEL_9:
if ( *(_QWORD *)(active_buffer + 8LL) )
{
v7 = buffer_write(active_buffer, 0LL);
if ( !(_BYTE)v7 )
error((int)&unk_4F2, *(_QWORD *)(active_buffer + 8LL), v8);
}
else
{
error((int)"No file associated with %s.", *active_buffer, a3);
v7 = 0;
}
return v7;
}
v3 = a1 + 1;
v4 = 0;
do
{
a3 = (const char *)(unsigned int)v4++;
++v3;
}
while ( *(v3 - 1) );
if ( (int)a3 <= 0 )
{
LABEL_8:
v7 = 1;
if ( v4 > 1 )
return v7;
goto LABEL_9;
}
v5 = &a1[(int)a3];
v6 = (__int64)&v5[-((_DWORD)a3 - 1) - 1];
while ( 1 )
{
v7 = buffer_write(active_buffer, *v5);
if ( !(_BYTE)v7 )
break;
if ( --v5 == (_QWORD *)v6 )
goto LABEL_8;
}
error((int)&unk_4F2, *v5, a3);
return v7;
}

original_code:
static _Bool raw_write(char **cmd_line)
{
    int parcount;
    for (parcount = 0; cmd_line[parcount]; parcount++);
    for (int i = parcount - 1; i > 0; i--)
    {
        if (!buffer_write(active_buffer, cmd_line[i]))
        {
            error("Could not write to “%s”.", cmd_line[i]);
            return 0;
        }
    }
    if (parcount <= 1)
    {
        if (!active_buffer->location)
        {
            error("No file associated with %s.", active_buffer->name);
            return 0;
        }
        else if (!buffer_write(active_buffer, ((void *)0)))
        {
            error("Could not write to “%s”.", active_buffer->location);
            return 0;
        }
    }
    return 1;
}

variable_types: parcount int

variable_types: i int


decompiled_code:
__int64 __fastcall buf_write(_QWORD *a1, __int64 a2, const char *a3)
{
return raw_write(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 a2, const char *a3)
{
return func1(a1, a2, a3);
}

original_code:
static void buf_write(char **cmd_line)
{
    raw_write(cmd_line);
}


decompiled_code:
void __fastcall write_and_quit_all(__int64 a1, int a2, const char *a3)
{
_QWORD *v3; // rbx
__int64 v4; // rdi

if ( *(_QWORD *)(a1 + 8) )
{
error((int)"Unexpected parameter.", a2, a3);
}
else
{
v3 = (_QWORD *)buffer_list;
if ( !buffer_list )
LABEL_3:
exit(0);
while ( 1 )
{
v4 = v3[1];
if ( *(_BYTE *)(v4 + 60) )
{
if ( !*(_QWORD *)(v4 + 8) )
{
error((int)"No file associated with %s.", *(_QWORD *)v4, a3);
return;
}
if ( !(unsigned __int8)buffer_write(v4, 0LL) )
break;
}
v3 = (_QWORD *)*v3;
if ( !v3 )
goto LABEL_3;
}
error((int)&unk_4F2, *(_QWORD *)(v3[1] + 8LL), a3);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2, const char *a3)
{
_QWORD *v3; // rbx
__int64 v4; // rdi

if ( *(_QWORD *)(a1 + 8) )
{
error((int)"Unexpected parameter.", a2, a3);
}
else
{
v3 = (_QWORD *)buffer_list;
if ( !buffer_list )
LABEL_3:
exit(0);
while ( 1 )
{
v4 = v3[1];
if ( *(_BYTE *)(v4 + 60) )
{
if ( !*(_QWORD *)(v4 + 8) )
{
error((int)"No file associated with %s.", *(_QWORD *)v4, a3);
return;
}
if ( !(unsigned __int8)buffer_write(v4, 0LL) )
break;
}
v3 = (_QWORD *)*v3;
if ( !v3 )
goto LABEL_3;
}
error((int)&unk_4F2, *(_QWORD *)(v3[1] + 8LL), a3);
}
}

original_code:
static void write_and_quit_all(char **cmd_line)
{
    if (cmd_line[1])
    {
        error("Unexpected parameter.");
        return;
    }
    for (buffer_list_t *bl = buffer_list; bl != ((void *)0); bl = bl->next)
    {
        if (bl->buffer->modified)
        {
            if (!bl->buffer->location)
            {
                error("No file associated with %s.", bl->buffer->name);
                return;
            }
            else if (!buffer_write(bl->buffer, ((void *)0)))
            {
                error("Could not write to “%s”.", bl->buffer->location);
                return;
            }
        }
    }
    exit(0);
}

canonical_original_code:
static void write_and_quit_all(char **cmd_line)
{
    if (cmd_line[1])
    {
        error("Unexpected parameter.");
        return;
    }
    for (struct buffer_list *bl = buffer_list; bl != ((void *)0); bl = bl->next)
    {
        if (bl->buffer->modified)
        {
            if (!bl->buffer->location)
            {
                error("No file associated with %s.", bl->buffer->name);
                return;
            }
            else if (!buffer_write(bl->buffer, ((void *)0)))
            {
                error("Could not write to “%s”.", bl->buffer->location);
                return;
            }
        }
    }
    exit(0);
}

variable_types: struct buffer_list { struct buffer_list *next; struct buffer { char *name; char *location; int line_count; char **lines; int *line_screen_pos; int x; int ys; int linenr_width; _Bool modified; int oll_unused_lines; } *buffer; } *

user_defined_types: struct buffer_list { struct buffer_list *next; struct buffer *buffer; }


decompiled_code:
void __fastcall force_quit_all(__int64 a1, int a2, const char *a3)
{
if ( !*(_QWORD *)(a1 + 8) )
exit(0);
error((int)"Unexpected parameter.", a2, a3);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2, const char *a3)
{
if ( !*(_QWORD *)(a1 + 8) )
exit(0);
error((int)"Unexpected parameter.", a2, a3);
}

original_code:
static void force_quit_all(char **cmd_line)
{
    if (!(!cmd_line[1])) { error("Unexpected parameter."); return; };
    exit(0);
}


decompiled_code:
void __fastcall quit_all(__int64 a1, int a2, const char *a3)
{
_QWORD *v3; // rax
__int64 v4; // rdx

if ( *(_QWORD *)(a1 + 8) )
{
error((int)"Unexpected parameter.", a2, a3);
}
else
{
v3 = (_QWORD *)buffer_list;
if ( !buffer_list )
LABEL_5:
exit(0);
while ( 1 )
{
v4 = v3[1];
if ( *(_BYTE *)(v4 + 60) )
break;
v3 = (_QWORD *)*v3;
if ( !v3 )
goto LABEL_5;
}
error((int)"%s has been modified.", *(_QWORD *)v4, (const char *)v4);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2, const char *a3)
{
_QWORD *v3; // rax
__int64 v4; // rdx

if ( *(_QWORD *)(a1 + 8) )
{
error((int)"Unexpected parameter.", a2, a3);
}
else
{
v3 = (_QWORD *)buffer_list;
if ( !buffer_list )
LABEL_5:
exit(0);
while ( 1 )
{
v4 = v3[1];
if ( *(_BYTE *)(v4 + 60) )
break;
v3 = (_QWORD *)*v3;
if ( !v3 )
goto LABEL_5;
}
error((int)"%s has been modified.", *(_QWORD *)v4, (const char *)v4);
}
}

original_code:
static void quit_all(char **cmd_line)
{
    if (!(!cmd_line[1])) { error("Unexpected parameter."); return; };
    for (buffer_list_t *bl = buffer_list; bl != ((void *)0); bl = bl->next)
        if (!(!bl->buffer->modified)) { error("%s has been modified.", bl->buffer->name); return; };
    exit(0);
}

canonical_original_code:
static void quit_all(char **cmd_line)
{
    if (!(!cmd_line[1])) { error("Unexpected parameter."); return; };
    for (struct buffer_list *bl = buffer_list; bl != ((void *)0); bl = bl->next)
        if (!(!bl->buffer->modified)) { error("%s has been modified.", bl->buffer->name); return; };
    exit(0);
}

user_defined_types: struct buffer { char *name; char *location; int line_count; char **lines; int *line_screen_pos; int x; int ys; int linenr_width; _Bool modified; int oll_unused_lines; }


decompiled_code:
__int64 __fastcall write_and_quit(_QWORD *a1, __int64 a2, const char *a3)
{
__int64 result; // rax

if ( !a1[1] && !*(_BYTE *)(active_buffer + 60LL) || (result = raw_write(a1, a2, a3), (_BYTE)result) )
result = buffer_destroy(active_buffer);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2, const char *a3)
{
__int64 result; // rax

if ( !a1[1] && !*(_BYTE *)(active_buffer + 60LL) || (result = func1(a1, a2, a3), (_BYTE)result) )
result = buffer_destroy(active_buffer);
return result;
}

original_code:
static void write_and_quit(char **cmd_line)
{
    if ((!cmd_line[1] && !active_buffer->modified) || raw_write(cmd_line))
        buffer_destroy(active_buffer);
}


decompiled_code:
void __fastcall force_quit(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
error((int)"Unexpected parameter.", a2, a3);
else
buffer_destroy(active_buffer);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
error((int)"Unexpected parameter.", a2, a3);
else
buffer_destroy(active_buffer);
}

original_code:
static void force_quit(char **cmd_line)
{
    if (!(!cmd_line[1])) { error("Unexpected parameter."); return; };
    buffer_destroy(active_buffer);
}


quit

decompiled_code:
void __fastcall quit(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
{
error((int)"Unexpected parameter.", a2, a3);
}
else if ( *(_BYTE *)(active_buffer + 60LL) )
{
error((int)"%s has been modified.", *active_buffer, a3);
}
else
{
buffer_destroy(active_buffer);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
{
error((int)"Unexpected parameter.", a2, a3);
}
else if ( *(_BYTE *)(active_buffer + 60LL) )
{
error((int)"%s has been modified.", *active_buffer, a3);
}
else
{
buffer_destroy(active_buffer);
}
}

original_code:
static void quit(char **cmd_line)
{
    if (!(!cmd_line[1])) { error("Unexpected parameter."); return; };
    if (!(!active_buffer->modified)) { error("%s has been modified.", active_buffer->name); return; };
    buffer_destroy(active_buffer);
}


tabnew

decompiled_code:
void __fastcall tabnew(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
{
error((int)"Unexpected parameter.", a2, a3);
}
else
{
new_buffer();
buffer_activate_next();
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
{
error((int)"Unexpected parameter.", a2, a3);
}
else
{
new_buffer();
buffer_activate_next();
}
}

original_code:
static void tabnew(char **cmd_line)
{
    if (!(!cmd_line[1])) { error("Unexpected parameter."); return; };
    new_buffer();
    buffer_activate_next();
}


tabnext

decompiled_code:
void __fastcall tabnext(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
error((int)"Unexpected parameter.", a2, a3);
else
buffer_activate_next();
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
error((int)"Unexpected parameter.", a2, a3);
else
buffer_activate_next();
}

original_code:
static void tabnext(char **cmd_line)
{
    if (!(!cmd_line[1])) { error("Unexpected parameter."); return; };
    buffer_activate_next();
}


tabprevious

decompiled_code:
void __fastcall tabprevious(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
error((int)"Unexpected parameter.", a2, a3);
else
buffer_activate_prev();
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, int a2, const char *a3)
{
if ( *(_QWORD *)(a1 + 8) )
error((int)"Unexpected parameter.", a2, a3);
else
buffer_activate_prev();
}

original_code:
static void tabprevious(char **cmd_line)
{
    if (!(!cmd_line[1])) { error("Unexpected parameter."); return; };
    buffer_activate_prev();
}


decompiled_code:
__int64 __fastcall hash_eseq(char *a1)
{
char *v1; // rcx
char v2; // dl
__int64 result; // rax

v1 = a1 + 1;
v2 = *a1;
if ( *a1 )
{
LOBYTE(result) = 5;
do
{
LOBYTE(result) = v2 ^ (33 * result);
v2 = *v1++;
}
while ( v2 );
}
else
{
LOBYTE(result) = 5;
}
return (unsigned __int8)result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char *v1; // rcx
char v2; // dl
__int64 result; // rax

v1 = a1 + 1;
v2 = *a1;
if ( *a1 )
{
LOBYTE(result) = 5;
do
{
LOBYTE(result) = v2 ^ (33 * result);
v2 = *v1++;
}
while ( v2 );
}
else
{
LOBYTE(result) = 5;
}
return (unsigned __int8)result;
}

original_code:
static int hash_eseq(const char *sequence)
{
    uint32_t hash = 5381;
    uint8_t c;
    while ((c = *(sequence++)))
        hash = ((hash << 5) + hash) ^ c;
    return hash & ((1 << 8) - 1);
}

canonical_original_code:
static int hash_eseq(char *sequence)
{
    unsigned int hash = 5381;
    unsigned char c;
    while ((c = *(sequence++)))
        hash = ((hash << 5) + hash) ^ c;
    return hash & ((1 << 8) - 1);
}

variable_types:
sequence
char *

variable_types:
hash
unsigned int

variable_types:
c
unsigned char

return_type: int


decompiled_code:
__int64 read_escape_sequence()
{
int v0; // ebx
__int64 result; // rax
__int64 v2; // rbx
int v3; // ebp
int v4; // ebx
const char *v5; // rdi
int v6; // eax
__int64 v7; // rdx
int v8; // ebp
regmatch_t v9; // [rsp+0h] [rbp-88h] BYREF
int v10; // [rsp+8h] [rbp-80h]
int v11; // [rsp+10h] [rbp-78h]
int v12; // [rsp+18h] [rbp-70h]
int v13; // [rsp+20h] [rbp-68h]
__int64 ptr[6]; // [rsp+30h] [rbp-58h] BYREF
__int64 v15; // [rsp+60h] [rbp-28h]

fcntl(0, 4, 2048LL);
ptr[0] = 27LL;
ptr[1] = 0LL;
ptr[2] = 0LL;
ptr[3] = 0LL;
v0 = fread((char *)ptr + 1, 1uLL, 0x1EuLL, stdin);
fcntl(0, 4, 0LL);
result = 27LL;
if ( v0 > 0 )
{
v2 = eseq_trans_list[(int)hash_eseq((char *)ptr)];
if ( !v2 )
{
LABEL_5:
if ( regexec(&mouse_input_regex_1006, (const char *)ptr, 5uLL, &v9, 0) )
{
v5 = (const char *)&mouse_input_regex_1015;
if ( regexec(&mouse_input_regex_1015, (const char *)ptr, 4uLL, &v9, 0) )
{
result = 0LL;
if ( *(_WORD *)((char *)ptr + 1) != 19803 )
return result;
v3 = BYTE3(ptr[0]) - 32;
v4 = BYTE4(ptr[0]) - 32;
v6 = BYTE5(ptr[0]) - 32;
}
else
{
v8 = atoi((const char *)ptr + v10);
v4 = atoi((const char *)ptr + v11);
v5 = (char *)ptr + v12;
v6 = atoi(v5);
v3 = v8 - 32;
}
if ( v3 > 2 )
{
v7 = 2LL;
if ( v3 == 3 )
{
v7 = 3LL;
v3 = last_down_0;
}
}
else
{
last_down_0 = v3;
v7 = 2LL;
}
}
else
{
v3 = atoi((const char *)ptr + v10);
v4 = atoi((const char *)ptr + v11);
v5 = (char *)ptr + v12;
v6 = atoi(v5);
v7 = (unsigned int)(*((_BYTE *)ptr + v13) != 77) + 2;
}
ptr[4] = (unsigned int)v7;
ptr[5] = (unsigned int)v3;
LODWORD(v15) = v4 - 1;
HIDWORD(v15) = v6 - 1;
trigger_event(v5, ptr, v7);
return 0LL;
}
while ( strcmp(*(const char **)(v2 + 8), (const char *)ptr) )
{
v2 = *(_QWORD *)v2;
if ( !v2 )
goto LABEL_5;
}
result = *(unsigned int *)(v2 + 16);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx
__int64 result; // rax
__int64 v2; // rbx
int v3; // ebp
int v4; // ebx
const char *v5; // rdi
int v6; // eax
__int64 v7; // rdx
int v8; // ebp
regmatch_t v9; // [rsp+0h] [rbp-88h] BYREF
int v10; // [rsp+8h] [rbp-80h]
int v11; // [rsp+10h] [rbp-78h]
int v12; // [rsp+18h] [rbp-70h]
int v13; // [rsp+20h] [rbp-68h]
__int64 ptr[6]; // [rsp+30h] [rbp-58h] BYREF
__int64 v15; // [rsp+60h] [rbp-28h]

fcntl(0, 4, 2048LL);
ptr[0] = 27LL;
ptr[1] = 0LL;
ptr[2] = 0LL;
ptr[3] = 0LL;
v0 = fread((char *)ptr + 1, 1uLL, 0x1EuLL, stdin);
fcntl(0, 4, 0LL);
result = 27LL;
if ( v0 > 0 )
{
v2 = eseq_trans_list[(int)func0((char *)ptr)];
if ( !v2 )
{
LABEL_5:
if ( regexec(&mouse_input_regex_1006, (const char *)ptr, 5uLL, &v9, 0) )
{
v5 = (const char *)&mouse_input_regex_1015;
if ( regexec(&mouse_input_regex_1015, (const char *)ptr, 4uLL, &v9, 0) )
{
result = 0LL;
if ( *(_WORD *)((char *)ptr + 1) != 19803 )
return result;
v3 = BYTE3(ptr[0]) - 32;
v4 = BYTE4(ptr[0]) - 32;
v6 = BYTE5(ptr[0]) - 32;
}
else
{
v8 = atoi((const char *)ptr + v10);
v4 = atoi((const char *)ptr + v11);
v5 = (char *)ptr + v12;
v6 = atoi(v5);
v3 = v8 - 32;
}
if ( v3 > 2 )
{
v7 = 2LL;
if ( v3 == 3 )
{
v7 = 3LL;
v3 = last_down_0;
}
}
else
{
last_down_0 = v3;
v7 = 2LL;
}
}
else
{
v3 = atoi((const char *)ptr + v10);
v4 = atoi((const char *)ptr + v11);
v5 = (char *)ptr + v12;
v6 = atoi(v5);
v7 = (unsigned int)(*((_BYTE *)ptr + v13) != 77) + 2;
}
ptr[4] = (unsigned int)v7;
ptr[5] = (unsigned int)v3;
LODWORD(v15) = v4 - 1;
HIDWORD(v15) = v6 - 1;
trigger_event(v5, ptr, v7);
return 0LL;
}
while ( strcmp(*(const char **)(v2 + 8), (const char *)ptr) )
{
v2 = *(_QWORD *)v2;
if ( !v2 )
goto LABEL_5;
}
result = *(unsigned int *)(v2 + 16);
}
return result;
}

original_code:
static int read_escape_sequence(void)
{
    fcntl(0, 4, 04000);
    char escape_sequence[32] = { '\033' };
    int eseq_len = fread(&escape_sequence[1], 1, 30, stdin);
    fcntl(0, 4, 0);
    if (eseq_len <= 0)
        return '\033';
    int hash = hash_eseq(escape_sequence);
    for (struct eseq_trans_list *etl = eseq_trans_list[hash]; etl != ((void *)0); etl = etl->next)
        if (!strcmp(etl->sequence, escape_sequence))
            return etl->keycode;
    int match_type;
    regmatch_t matches[5];
    if (!regexec(&mouse_input_regex_1006, escape_sequence, 5, matches, 0))
        match_type = 1006;
    else if (!regexec(&mouse_input_regex_1015, escape_sequence, 4, matches, 0))
        match_type = 1015;
    else if ((escape_sequence[1] == '[') && (escape_sequence[2] == 'M'))
        match_type = 1000;
    else
        return 0;
    int button = (match_type == 1000) ? escape_sequence[3] : atoi(&escape_sequence[matches[1].rm_so]);
    int x = (match_type == 1000) ? escape_sequence[4] : atoi(&escape_sequence[matches[2].rm_so]);
    int y = (match_type == 1000) ? escape_sequence[5] : atoi(&escape_sequence[matches[3].rm_so]);
    int event_type = EVENT_MBUTTON_DOWN;
    if (match_type == 1006)
        event_type = (escape_sequence[matches[4].rm_so] == 'M') ? EVENT_MBUTTON_DOWN : EVENT_MBUTTON_UP;
    else if ((match_type == 1015) || (match_type == 1000))
    {
        button -= ' ';
        if (match_type == 1000)
        {
            x -= ' ';
            y -= ' ';
        }
        static int last_down = 0;
        if (button < 3)
            last_down = button;
        else if (button == 3)
        {
            button = last_down;
            event_type = EVENT_MBUTTON_UP;
        }
    }
    trigger_event((event_t){ event_type, .code = button, .mbutton = { x - 1, y - 1 } });
    return 0;
}

canonical_original_code:
static int read_escape_sequence()
{
    fcntl(0, 4, 04000);
    char escape_sequence[32] = { '\033' };
    int eseq_len = fread(&escape_sequence[1], 1, 30, stdin);
    fcntl(0, 4, 0);
    if (eseq_len <= 0)
        return '\033';
    int hash = hash_eseq(escape_sequence);
    for (struct eseq_trans_list *etl = eseq_trans_list[hash]; etl != ((void *)0); etl = etl->next)
        if (!strcmp(etl->sequence, escape_sequence))
            return etl->keycode;
    int match_type;
    struct regmatch_t matches[5];
    if (!regexec(&mouse_input_regex_1006, escape_sequence, 5, matches, 0))
        match_type = 1006;
    else if (!regexec(&mouse_input_regex_1015, escape_sequence, 4, matches, 0))
        match_type = 1015;
    else if ((escape_sequence[1] == '[') && (escape_sequence[2] == 'M'))
        match_type = 1000;
    else
        return 0;
    int button = (match_type == 1000) ? escape_sequence[3] : atoi(&escape_sequence[matches[1].rm_so]);
    int x = (match_type == 1000) ? escape_sequence[4] : atoi(&escape_sequence[matches[2].rm_so]);
    int y = (match_type == 1000) ? escape_sequence[5] : atoi(&escape_sequence[matches[3].rm_so]);
    int event_type = EVENT_MBUTTON_DOWN;
    if (match_type == 1006)
        event_type = (escape_sequence[matches[4].rm_so] == 'M') ? EVENT_MBUTTON_DOWN : EVENT_MBUTTON_UP;
    else if ((match_type == 1015) || (match_type == 1000))
    {
        button -= ' ';
        if (match_type == 1000)
        {
            x -= ' ';
            y -= ' ';
        }
        static int last_down = 0;
        if (button < 3)
            last_down = button;
        else if (button == 3)
        {
            button = last_down;
            event_type = EVENT_MBUTTON_UP;
        }
    }
    trigger_event((struct event){ event_type, .code = button, .mbutton = { x - 1, y - 1 } });
    return 0;
}

variable_types: hash int

variable_types: struct eseq_trans_list { struct eseq_trans_list *next; char *sequence; int keycode; } *

variable_types: struct regmatch_t { int rm_so; int rm_eo; } [5]

variable_types: button int

variable_types: x int

variable_types: y int

user_defined_types: struct event { enum event_type type; union { int *key_seq; int code; }; struct { int x; } mbutton; }

user_defined_types: enum event_type { EVENT_NORMAL_KEY_SEQ=0, EVENT_INSERT_KEY=1, EVENT_MBUTTON_DOWN=2, EVENT_MBUTTON_UP=3 }


decompiled_code:
__int64 input_read()
{
unsigned int v0; // ebx
__int64 v1; // rdx
int v3; // eax
int v4; // eax

if ( fifo_content )
{
v0 = *(_DWORD *)fifo;
v1 = fifo_content - 1;
fifo_content = v1;
if ( v1 )
memmove(fifo, (char *)fifo + 4, 4 * v1);
}
else
{
v3 = getchar();
v0 = v3;
if ( v3 == 27 )
{
v0 = read_escape_sequence();
}
else if ( (unsigned int)(v3 - 1) <= 0x19 )
{
v4 = v3 + 96;
if ( v0 != 10 )
{
BYTE1(v4) = ((unsigned __int16)(v0 + 96) >> 8) | 8;
v0 = v4;
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
__int64 v1; // rdx
int v3; // eax
int v4; // eax

if ( fifo_content )
{
v0 = *(_DWORD *)fifo;
v1 = fifo_content - 1;
fifo_content = v1;
if ( v1 )
memmove(fifo, (char *)fifo + 4, 4 * v1);
}
else
{
v3 = getchar();
v0 = v3;
if ( v3 == 27 )
{
v0 = func1();
}
else if ( (unsigned int)(v3 - 1) <= 0x19 )
{
v4 = v3 + 96;
if ( v0 != 10 )
{
BYTE1(v4) = ((unsigned __int16)(v0 + 96) >> 8) | 8;
v0 = v4;
}
}
}
return v0;
}

original_code:
int input_read(void)
{
    if (fifo_content)
    {
        int v = fifo[0];
        if (--fifo_content)
            memmove(&fifo[0], &fifo[1], fifo_content * sizeof(fifo[0]));
        return v;
    }
    int inp = getchar();
    if (inp == '\e')
        inp = read_escape_sequence();
    else if ((inp >= 1) && (inp <= 26) && (inp != '\n'))
        inp = (inp + 96) | 0x0800;
    return inp;
}

canonical_original_code:
int input_read()
{
    if (fifo_content)
    {
        int v = fifo[0];
        if (--fifo_content)
            memmove(&fifo[0], &fifo[1], fifo_content * sizeof(fifo[0]));
        return v;
    }
    int inp = getchar();
    if (inp == '\e')
        inp = read_escape_sequence();
    else if ((inp >= 1) && (inp <= 26) && (inp != '\n'))
        inp = (inp + 96) | 0x0800;
    return inp;
}

variable_types: v int

variable_types: inp int


decompiled_code:
void *__fastcall sim_input(int a1)
{
__int64 v1; // rbx
__int64 v2; // r12
void *result; // rax

v1 = fifo_content;
v2 = fifo_content + 1;
if ( fifo_content != -1 )
fifo = realloc(fifo, 0x40uLL);
fifo_content = v2;
result = fifo;
*((_DWORD *)fifo + v1) = a1;
return result;
}

canonical_decompiled_code:
void *__fastcall func4(int a1)
{
__int64 v1; // rbx
__int64 v2; // r12
void *result; // rax

v1 = fifo_content;
v2 = fifo_content + 1;
if ( fifo_content != -1 )
fifo = realloc(fifo, 0x40uLL);
fifo_content = v2;
result = fifo;
*((_DWORD *)fifo + v1) = a1;
return result;
}

original_code:
void sim_input(int val)
{
    if (fifo_content + 1 > fifo_size)
        fifo = realloc(fifo, fifo_size + 16 * sizeof(fifo[0]));
    fifo[fifo_content++] = val;
}

variable_types: val int


decompiled_code:
__int64 __fastcall update_buffer_name(__int64 a1)
{
const char *v2; // r13
size_t v3; // rdi
char v4; // r12
int v5; // ebp
char *v7; // rax
int v8; // ecx
char *v9; // rax

free(*(void **)a1);
v2 = *(const char **)(a1 + 8);
v3 = strlen(v2) + 1;
*(_QWORD *)a1 = malloc(v3);
v4 = *v2;
if ( *v2 )
{
v5 = 0;
while ( 1 )
{
v7 = strchr(v2, 47);
if ( !v7 )
break;
v8 = v5 + 1;
*(_BYTE *)(*(_QWORD *)a1 + v5) = v4;
v9 = &v7[-*(_QWORD *)(a1 + 8)];
if ( (_DWORD)v9 )
{
v5 += 2;
*(_BYTE *)(*(_QWORD *)a1 + v8) = 47;
}
else
{
++v5;
}
v2 = (const char *)(*(_QWORD *)(a1 + 8) + (int)v9 + 1);
v4 = *v2;
if ( !*v2 )
return full_redraw();
}
strcpy((char *)(*(_QWORD *)a1 + v5), v2);
}
return full_redraw();
}

original_code:
static void update_buffer_name(buffer_t *buf)
{
    free(buf->name);
    buf->name = malloc(strlen(buf->location) + 1);
    for (int i = 0, oi = 0; buf->location[i]; i++)
    {
        char *slash = strchr(&buf->location[i], '/');
        if (slash)
        {
            buf->name[oi++] = buf->location[i];
            if ((i = slash - buf->location))
                buf->name[oi++] = '/';
        }
        else
        {
            strcpy(&buf->name[oi], &buf->location[i]);
            break;
        }
    }
    full_redraw();
}

canonical_original_code:
static void update_buffer_name(struct buffer *buf)
{
    free(buf->name);
    buf->name = malloc(strlen(buf->location) + 1);
    for (int i = 0; int oi = 0; buf->location[i]; i++)
    {
        char *slash = strchr(&buf->location[i], '/');
        if (slash)
        {
            buf->name[oi++] = buf->location[i];
            if ((i = slash - buf->location))
                buf->name[oi++] = '/';
        }
        else
        {
            strcpy(&buf->name[oi], &buf->location[i]);
            break;
        }
    }
    full_redraw();
}

variable_types: struct buffer { char *name; char *location; int line_count; char **lines; int *line_screen_pos; int x; int ys; int linenr_width; _Bool modified; int oll_unused_lines; } *

variable_types: oi int

variable_types:
slash
char *


decompiled_code:
void *__fastcall ensure_line_size(void **a1, __int64 a2)
{
void *result; // rax

result = realloc(*a1, a2 + 1);
*a1 = result;
return result;
}

canonical_decompiled_code:
void *__fastcall func1(void **a1, __int64 a2)
{
void *result; // rax

result = realloc(*a1, a2 + 1);
*a1 = result;
return result;
}

original_code:
static void ensure_line_size(char **lineptr, size_t len)
{
    *lineptr = realloc(*lineptr, len + 1);
}

canonical_original_code:
static void ensure_line_size(char **lineptr, unsigned long len)
{
    *lineptr = realloc(*lineptr, len + 1);
}

variable_types:
lineptr
char **

variable_types:
len
unsigned long


decompiled_code:
void __fastcall buffer_destroy(void *ptr)
{
void **v2; // rdi
void **v3; // rbp
char v4; // r12
_QWORD *v5; // r12
__int64 v6; // rbp

v2 = (void **)buffer_list;
v3 = &buffer_list;
v4 = 0;
if ( buffer_list )
{
while ( v2[1] != ptr )
{
v3 = v2;
v2 = (void **)*v2;
if ( !v2 )
{
v4 = 0;
goto LABEL_12;
}
}
v5 = *v2;
free(v2);
*v3 = v5;
if ( (void *)active_buffer == ptr )
{
if ( v5 )
{
active_buffer = v5[1];
v4 = 1;
}
else
{
if ( v3 == &buffer_list )
exit(0);
active_buffer = (__int64)v3[1];
v4 = 1;
}
}
else
{
v4 = 0;
}
}
LABEL_12:
free(*((void **)ptr + 1));
free(*(void **)ptr);
if ( *((int *)ptr + 4) > 0 )
{
v6 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 3) + 8 * v6++));
while ( *((_DWORD *)ptr + 4) > (int)v6 );
}
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
if ( v4 )
update_active_buffer();
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void **v2; // rdi
void **v3; // rbp
char v4; // r12
_QWORD *v5; // r12
__int64 v6; // rbp

v2 = (void **)buffer_list;
v3 = &buffer_list;
v4 = 0;
if ( buffer_list )
{
while ( v2[1] != ptr )
{
v3 = v2;
v2 = (void **)*v2;
if ( !v2 )
{
v4 = 0;
goto LABEL_12;
}
}
v5 = *v2;
free(v2);
*v3 = v5;
if ( (void *)active_buffer == ptr )
{
if ( v5 )
{
active_buffer = v5[1];
v4 = 1;
}
else
{
if ( v3 == &buffer_list )
exit(0);
active_buffer = (__int64)v3[1];
v4 = 1;
}
}
else
{
v4 = 0;
}
}
LABEL_12:
free(*((void **)ptr + 1));
free(*(void **)ptr);
if ( *((int *)ptr + 4) > 0 )
{
v6 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 3) + 8 * v6++));
while ( *((_DWORD *)ptr + 4) > (int)v6 );
}
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
if ( v4 )
update_active_buffer();
}

original_code:
void buffer_destroy(buffer_t *buf)
{
    _Bool active_buffer_changed = 0;
    buffer_list_t **blp;
    for (blp = &buffer_list; (*blp != ((void *)0)) && ((*blp)->buffer != buf); blp = &(*blp)->next);
    if (*blp != ((void *)0))
    {
        buffer_list_t *blp_next = (*blp)->next;
        free(*blp);
        *blp = blp_next;
        if (active_buffer == buf)
        {
            if (blp_next != ((void *)0))
                active_buffer = blp_next->buffer;
            else
            {
                if (blp == &buffer_list)
                    exit(0);
                else
                {
                    active_buffer = *(buffer_t **)((uintptr_t)blp - __builtin_offsetof (buffer_list_t, next) + __builtin_offsetof (buffer_list_t, buffer));
                }
            }
            active_buffer_changed = 1;
        }
    }
    free(buf->location);
    free(buf->name);
    for (int i = 0; i < buf->line_count; i++)
        free(buf->lines[i]);
    free(buf->lines);
    free(buf->line_screen_pos);
    free(buf);
    if (active_buffer_changed)
        update_active_buffer();
}

canonical_original_code:
void buffer_destroy(struct buffer *buf)
{
    _Bool active_buffer_changed = 0;
    struct buffer_list **blp;
    for (blp = &buffer_list; (*blp != ((void *)0)) && ((*blp)->buffer != buf); blp = &(*blp)->next);
    if (*blp != ((void *)0))
    {
        struct buffer_list *blp_next = (*blp)->next;
        free(*blp);
        *blp = blp_next;
        if (active_buffer == buf)
        {
            if (blp_next != ((void *)0))
                active_buffer = blp_next->buffer;
            else
            {
                if (blp == &buffer_list)
                    exit(0);
                else
                {
                    active_buffer = *(struct buffer **)((unsigned long)blp - __builtin_offsetof (buffer_list_t, next) + __builtin_offsetof (buffer_list_t, buffer));
                }
            }
            active_buffer_changed = 1;
        }
    }
    free(buf->location);
    free(buf->name);
    for (int i = 0; i < buf->line_count; i++)
        free(buf->lines[i]);
    free(buf->lines);
    free(buf->line_screen_pos);
    free(buf);
    if (active_buffer_changed)
        update_active_buffer();
}

variable_types: struct buffer_list { struct buffer_list *next; struct buffer { char *name; char *location; int line_count; char **lines; int *line_screen_pos; int x; int ys; int linenr_width; _Bool modified; int oll_unused_lines; } *buffer; } **

variable_types: i int


original_code:
void buffer_insert(buffer_t *buf, const char *string)
{
    buf->modified = 1;
    int ofs = utf8_byte_offset(buf->lines[buf->y], buf->x);
    size_t line_len = strlen(buf->lines[buf->y]);
    const char *nl = strchr(string, '\n');
    if (!nl)
    {
        size_t str_len = strlen(string);
        ensure_line_size(&buf->lines[buf->y], line_len + str_len);
        memmove(&buf->lines[buf->y][ofs + str_len], &buf->lines[buf->y][ofs], line_len - ofs + 1);
        memcpy(&buf->lines[buf->y][ofs], string, str_len);
        buf->x += utf8_strlen(string);
        return;
    }
    size_t str_len = nl - string;
    buf->lines = realloc(buf->lines, ++buf->line_count * sizeof(*buf->lines));
    buf->line_screen_pos = realloc(buf->line_screen_pos, buf->line_count * sizeof(*buf->line_screen_pos));
    buf->linenr_width = get_decimal_length(buf->line_count);
    memmove(&buf->lines[buf->y + 2], &buf->lines[buf->y + 1], (buf->line_count - buf->y - 2) * sizeof(*buf->lines));
    buf->lines[buf->y + 1] = malloc(line_len - ofs + 1);
    strcpy(buf->lines[buf->y + 1], &buf->lines[buf->y][ofs]);
    ensure_line_size(&buf->lines[buf->y], ofs + str_len);
    memcpy(&buf->lines[buf->y][ofs], string, str_len);
    buf->lines[buf->y][ofs + str_len] = 0;
    buf->x = 0;
    buf->y++;
    if (nl[1])
        buffer_insert(buf, nl + 1);
}

canonical_original_code:
void buffer_insert(struct buffer *buf, char *string)
{
    buf->modified = 1;
    int ofs = utf8_byte_offset(buf->lines[buf->y], buf->x);
    unsigned long line_len = strlen(buf->lines[buf->y]);
    char *nl = strchr(string, '\n');
    if (!nl)
    {
        unsigned long str_len = strlen(string);
        ensure_line_size(&buf->lines[buf->y], line_len + str_len);
        memmove(&buf->lines[buf->y][ofs + str_len], &buf->lines[buf->y][ofs], line_len - ofs + 1);
        memcpy(&buf->lines[buf->y][ofs], string, str_len);
        buf->x += utf8_strlen(string);
        return;
    }
    unsigned long str_len = nl - string;
    buf->lines = realloc(buf->lines, ++buf->line_count * sizeof(*buf->lines));
    buf->line_screen_pos = realloc(buf->line_screen_pos, buf->line_count * sizeof(*buf->line_screen_pos));
    buf->linenr_width = get_decimal_length(buf->line_count);
    memmove(&buf->lines[buf->y + 2], &buf->lines[buf->y + 1], (buf->line_count - buf->y - 2) * sizeof(*buf->lines));
    buf->lines[buf->y + 1] = malloc(line_len - ofs + 1);
    strcpy(buf->lines[buf->y + 1], &buf->lines[buf->y][ofs]);
    ensure_line_size(&buf->lines[buf->y], ofs + str_len);
    memcpy(&buf->lines[buf->y][ofs], string, str_len);
    buf->lines[buf->y][ofs + str_len] = 0;
    buf->x = 0;
    buf->y++;
    if (nl[1])
        buffer_insert(buf, nl + 1);
}

variable_types:
string
char *

variable_types: ofs int

variable_types:
nl
char *


original_code:
void buffer_delete(buffer_t *buf, int char_count)
{
    while (char_count > 0)
    {
        int remaining = utf8_strlen(buf->lines[buf->y]) - buf->x;
        int x_offset = utf8_byte_offset(buf->lines[buf->y], buf->x);
        if (remaining == char_count)
            buf->lines[buf->y][x_offset] = 0;
        else if (remaining > char_count)
        {
            int bytes = utf8_byte_offset(&buf->lines[buf->y][x_offset], char_count);
            memmove(&buf->lines[buf->y][x_offset], &buf->lines[buf->y][x_offset + bytes], strlen(&buf->lines[buf->y][x_offset + bytes]) + 1);
        }
        else
        {
            if (buf->line_count <= buf->y + 1)
            {
                buf->lines[buf->y][x_offset] = 0;
                break;
            }
            size_t next_line_length = strlen(buf->lines[buf->y + 1]);
            buf->lines[buf->y] = realloc(buf->lines[buf->y], x_offset + next_line_length + 1);
            memmove(&buf->lines[buf->y][x_offset], buf->lines[buf->y + 1], next_line_length + 1);
            free(buf->lines[buf->y + 1]);
            memmove(&buf->lines[buf->y + 1], &buf->lines[buf->y + 2], (--buf->line_count - buf->y - 1) * sizeof(buf->lines[0]));
            buf->linenr_width = get_decimal_length(buf->line_count);
            remaining++;
        }
        char_count -= remaining;
        buf->modified = 1;
    }
    int current_line_length = utf8_strlen(buf->lines[buf->y]);
    if (buf->x >= current_line_length)
        buf->x = (input_mode == MODE_INSERT) ? current_line_length : (current_line_length ? (current_line_length - 1) : 0);
}

canonical_original_code:
void buffer_delete(struct buffer *buf, int char_count)
{
    while (char_count > 0)
    {
        int remaining = utf8_strlen(buf->lines[buf->y]) - buf->x;
        int x_offset = utf8_byte_offset(buf->lines[buf->y], buf->x);
        if (remaining == char_count)
            buf->lines[buf->y][x_offset] = 0;
        else if (remaining > char_count)
        {
            int bytes = utf8_byte_offset(&buf->lines[buf->y][x_offset], char_count);
            memmove(&buf->lines[buf->y][x_offset], &buf->lines[buf->y][x_offset + bytes], strlen(&buf->lines[buf->y][x_offset + bytes]) + 1);
        }
        else
        {
            if (buf->line_count <= buf->y + 1)
            {
                buf->lines[buf->y][x_offset] = 0;
                break;
            }
            unsigned long next_line_length = strlen(buf->lines[buf->y + 1]);
            buf->lines[buf->y] = realloc(buf->lines[buf->y], x_offset + next_line_length + 1);
            memmove(&buf->lines[buf->y][x_offset], buf->lines[buf->y + 1], next_line_length + 1);
            free(buf->lines[buf->y + 1]);
            memmove(&buf->lines[buf->y + 1], &buf->lines[buf->y + 2], (--buf->line_count - buf->y - 1) * sizeof(buf->lines[0]));
            buf->linenr_width = get_decimal_length(buf->line_count);
            remaining++;
        }
        char_count -= remaining;
        buf->modified = 1;
    }
    int current_line_length = utf8_strlen(buf->lines[buf->y]);
    if (buf->x >= current_line_length)
        buf->x = (input_mode == MODE_INSERT) ? current_line_length : (current_line_length ? (current_line_length - 1) : 0);
}

variable_types: remaining int

variable_types: bytes int


original_code:
buffer_t *new_buffer(void)
{
    buffer_t *buf = malloc(sizeof(*buf));
    buf->location = ((void *)0);
    buf->x = buf->y = buf->ys = 0;
    buf->modified = 0;
    buf->line_count = 1;
    buf->linenr_width = 1;
    buf->lines = malloc(sizeof(*buf->lines));
    buf->line_screen_pos = malloc(sizeof(*buf->line_screen_pos));
    buf->lines[0] = malloc(1);
    buf->lines[0][0] = 0;
    buf->name = strdup("[unnamed]");
    buffer_list_append(buf);
    return buf;
}

canonical_original_code:
struct buffer *new_buffer()
{
    struct buffer *buf = malloc(sizeof(*buf));
    buf->location = ((void *)0);
    buf->x = buf->y = buf->ys = 0;
    buf->modified = 0;
    buf->line_count = 1;
    buf->linenr_width = 1;
    buf->lines = malloc(sizeof(*buf->lines));
    buf->line_screen_pos = malloc(sizeof(*buf->line_screen_pos));
    buf->lines[0] = malloc(1);
    buf->lines[0][0] = 0;
    buf->name = strdup("[unnamed]");
    buffer_list_append(buf);
    return buf;
}

return_type: struct buffer { char *name; char *location; int line_count; char **lines; int *line_screen_pos; int x; int ys; int linenr_width; _Bool modified; int oll_unused_lines; } *


decompiled_code:
__int64 buffer_activate_next()
{
_QWORD *v0; // rax
__int64 v1; // rax
_QWORD *v3; // rax

if ( !buffer_list )
goto LABEL_5;
v0 = buffer_list;
while ( v0[1] != active_buffer )
{
v0 = (_QWORD *)*v0;
if ( !v0 )
goto LABEL_5;
}
v3 = (_QWORD *)*v0;
if ( v3 )
v1 = v3[1];
else
LABEL_5:
v1 = *((_QWORD *)buffer_list + 1);
active_buffer = v1;
return update_active_buffer();
}

canonical_decompiled_code:
__int64 func8()
{
_QWORD *v0; // rax
__int64 v1; // rax
_QWORD *v3; // rax

if ( !buffer_list )
goto LABEL_5;
v0 = buffer_list;
while ( v0[1] != active_buffer )
{
v0 = (_QWORD *)*v0;
if ( !v0 )
goto LABEL_5;
}
v3 = (_QWORD *)*v0;
if ( v3 )
v1 = v3[1];
else
LABEL_5:
v1 = *((_QWORD *)buffer_list + 1);
active_buffer = v1;
return update_active_buffer();
}

original_code:
void buffer_activate_next(void)
{
    buffer_list_t *bl;
    for (bl = buffer_list; (bl != ((void *)0)) && (bl->buffer != active_buffer); bl = bl->next);
    if ((bl != ((void *)0)) && (bl->next != ((void *)0)))
        active_buffer = bl->next->buffer;
    else
        active_buffer = buffer_list->buffer;
    update_active_buffer();
}

canonical_original_code:
void buffer_activate_next()
{
    struct buffer_list *bl;
    for (bl = buffer_list; (bl != ((void *)0)) && (bl->buffer != active_buffer); bl = bl->next);
    if ((bl != ((void *)0)) && (bl->next != ((void *)0)))
        active_buffer = bl->next->buffer;
    else
        active_buffer = buffer_list->buffer;
    update_active_buffer();
}

variable_types: struct buffer_list { struct buffer_list *next; struct buffer { char *name; char *location; int line_count; char **lines; int *line_screen_pos; int x; int ys; int linenr_width; _Bool modified; int oll_unused_lines; } *buffer; } *


decompiled_code:
__int64 __fastcall buffer_activate_prev(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rcx
_QWORD *v4; // rdx

v2 = buffer_list;
v3 = active_buffer;
do
{
v4 = v2;
v2 = (_QWORD *)*v2;
}
while ( v2 && v2[1] != active_buffer );
active_buffer = v4[1];
return update_active_buffer(a1, a2, v4, v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rcx
_QWORD *v4; // rdx

v2 = buffer_list;
v3 = active_buffer;
do
{
v4 = v2;
v2 = (_QWORD *)*v2;
}
while ( v2 && v2[1] != active_buffer );
active_buffer = v4[1];
return update_active_buffer(a1, a2, v4, v3);
}

original_code:
void buffer_activate_prev(void)
{
    buffer_list_t *bl;
    for (bl = buffer_list; (bl->next != ((void *)0)) && (bl->next->buffer != active_buffer); bl = bl->next);
    active_buffer = bl->buffer;
    update_active_buffer();
}

canonical_original_code:
void buffer_activate_prev()
{
    struct buffer_list *bl;
    for (bl = buffer_list; (bl->next != ((void *)0)) && (bl->next->buffer != active_buffer); bl = bl->next);
    active_buffer = bl->buffer;
    update_active_buffer();
}


decompiled_code:
__int64 __fastcall hash_event(__int64 a1)
{
__int64 result; // rax
int *v2; // rdx
int v3; // ecx
_DWORD *v4; // rdx

if ( *(_DWORD *)a1 )
return (unsigned __int8)(*(_BYTE *)(a1 + 8) + *(_DWORD *)a1);
v2 = *(int **)(a1 + 8);
v3 = *v2;
if ( *v2 )
{
v4 = v2 + 1;
LOBYTE(result) = 0;
do
{
LOBYTE(result) = v3 + result;
v3 = *v4++;
}
while ( v3 );
}
else
{
LOBYTE(result) = 0;
}
return (unsigned __int8)result;
}

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

if ( *(_DWORD *)a1 )
return (unsigned __int8)(*(_BYTE *)(a1 + 8) + *(_DWORD *)a1);
v2 = *(int **)(a1 + 8);
v3 = *v2;
if ( *v2 )
{
v4 = v2 + 1;
LOBYTE(result) = 0;
do
{
LOBYTE(result) = v3 + result;
v3 = *v4++;
}
while ( v3 );
}
else
{
LOBYTE(result) = 0;
}
return (unsigned __int8)result;
}

original_code:
static int hash_event(const event_t *event)
{
    if (event->type != EVENT_NORMAL_KEY_SEQ)
        return (event->type + event->code) & ((1 << 8) - 1);
    else
    {
        int sum = event->type;
        for (int i = 0; event->key_seq[i]; i++)
            sum += event->key_seq[i];
        return sum & ((1 << 8) - 1);
    }
}

canonical_original_code:
static int hash_event(struct event *event)
{
    if (event->type != EVENT_NORMAL_KEY_SEQ)
        return (event->type + event->code) & ((1 << 8) - 1);
    else
    {
        int sum = event->type;
        for (int i = 0; event->key_seq[i]; i++)
            sum += event->key_seq[i];
        return sum & ((1 << 8) - 1);
    }
}

variable_types: struct event { enum event_type { EVENT_NORMAL_KEY_SEQ=0, EVENT_INSERT_KEY=1, EVENT_MBUTTON_DOWN=2, EVENT_MBUTTON_UP=3 } type; union { int *key_seq; int code; }; struct { int x; } mbutton; } *

variable_types: sum int


decompiled_code:
bool __fastcall key_seq_cmp(__int64 a1, __int64 a2)
{
__int64 v2; // rax
int v3; // edx

v2 = 0LL;
do
{
v3 = *(_DWORD *)(a1 + v2);
if ( !v3 )
return *(_DWORD *)(a2 + v2) == 0;
v2 += 4LL;
}
while ( *(_DWORD *)(a2 + v2 - 4) == v3 );
return 0;
}

original_code:
static _Bool key_seq_cmp(const int *ks1, const int *ks2)
{
    for (int i = 0; ks1[i] || ks2[i]; i++)
        if (ks1[i] != ks2[i])
            return 0;
    return 1;
}

canonical_original_code:
static _Bool key_seq_cmp(int *ks1, int *ks2)
{
    for (int i = 0; ks1[i] || ks2[i]; i++)
        if (ks1[i] != ks2[i])
            return 0;
    return 1;
}


decompiled_code:
__int64 __fastcall trigger_event(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8)
{
int v8; // eax
__int64 v9; // rbx
__int64 v10; // rbp
__int64 result; // rax

v8 = hash_event((__int64)&a7);
if ( a7 )
{
result = event_handlers[v8];
if ( result )
{
while ( *(_DWORD *)(result + 16) != (_DWORD)a8 || a7 != *(_DWORD *)(result + 8) )
{
result = *(_QWORD *)result;
if ( !result )
return result;
}
result = (*(__int64 (__fastcall **)(int *, _QWORD))(result + 32))(&a7, *(_QWORD *)(result + 40));
}
else
{
result = 0LL;
}
}
else
{
v9 = event_handlers[v8];
if ( v9 )
{
v10 = a8;
do
{
if ( !*(_DWORD *)(v9 + 8) && key_seq_cmp(*(_QWORD *)(v9 + 16), v10) )
return (*(__int64 (__fastcall **)(int *, _QWORD))(v9 + 32))(&a7, *(_QWORD *)(v9 + 40));
v9 = *(_QWORD *)v9;
}
while ( v9 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, __int64 a8)
{
int v8; // eax
__int64 v9; // rbx
__int64 v10; // rbp
__int64 result; // rax

v8 = func0((__int64)&a7);
if ( a7 )
{
result = event_handlers[v8];
if ( result )
{
while ( *(_DWORD *)(result + 16) != (_DWORD)a8 || a7 != *(_DWORD *)(result + 8) )
{
result = *(_QWORD *)result;
if ( !result )
return result;
}
result = (*(__int64 (__fastcall **)(int *, _QWORD))(result + 32))(&a7, *(_QWORD *)(result + 40));
}
else
{
result = 0LL;
}
}
else
{
v9 = event_handlers[v8];
if ( v9 )
{
v10 = a8;
do
{
if ( !*(_DWORD *)(v9 + 8) && func1(*(_QWORD *)(v9 + 16), v10) )
return (*(__int64 (__fastcall **)(int *, _QWORD))(v9 + 32))(&a7, *(_QWORD *)(v9 + 40));
v9 = *(_QWORD *)v9;
}
while ( v9 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
_Bool trigger_event(event_t event)
{
    int hash = hash_event(&event);
    if (event.type == EVENT_NORMAL_KEY_SEQ)
    {
        for (struct event_handler_list *ehl = event_handlers[hash]; ehl != ((void *)0); ehl = ehl->next)
            if ((ehl->handler.event.type == EVENT_NORMAL_KEY_SEQ) && key_seq_cmp(ehl->handler.event.key_seq, event.key_seq))
                return ehl->handler.handler(&event, ehl->handler.info);
    }
    else
    {
        for (struct event_handler_list *ehl = event_handlers[hash]; ehl != ((void *)0); ehl = ehl->next)
            if ((ehl->handler.event.code == event.code) && (ehl->handler.event.type == event.type))
                return ehl->handler.handler(&event, ehl->handler.info);
    }
    return 0;
}

canonical_original_code:
_Bool trigger_event(struct event event)
{
    int hash = hash_event(&event);
    if (event.type == EVENT_NORMAL_KEY_SEQ)
    {
        for (struct event_handler_list *ehl = event_handlers[hash]; ehl != ((void *)0); ehl = ehl->next)
            if ((ehl->handler.event.type == EVENT_NORMAL_KEY_SEQ) && key_seq_cmp(ehl->handler.event.key_seq, event.key_seq))
                return ehl->handler.handler(&event, ehl->handler.info);
    }
    else
    {
        for (struct event_handler_list *ehl = event_handlers[hash]; ehl != ((void *)0); ehl = ehl->next)
            if ((ehl->handler.event.code == event.code) && (ehl->handler.event.type == event.type))
                return ehl->handler.handler(&event, ehl->handler.info);
    }
    return 0;
}

variable_types: hash int

variable_types: struct event_handler_list { struct event_handler_list *next; struct event_handler { struct event { enum event_type { EVENT_NORMAL_KEY_SEQ=0, EVENT_INSERT_KEY=1, EVENT_MBUTTON_DOWN=2, EVENT_MBUTTON_UP=3 } type; union { int *key_seq; int code; }; struct { int x; } mbutton; } event; _Bool (*handler)(struct event *event, void *info); void *info; } handler; } *

user_defined_types: struct event_handler_list { struct event_handler_list *next; struct event_handler handler; }

user_defined_types: struct event_handler { struct event event; _Bool (*handler)(struct event *event, void *info); void *info; }


decompiled_code:
char *__fastcall register_event_handler(__int64 a1, char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, __int64 a8)
{
int v8; // eax
int v9; // er12
__int64 v10; // r15
int v11; // ebp
int v12; // er14
void *v13; // r13
__int64 v14; // rbx
char *result; // rax

v8 = hash_event((__int64)&a7);
v9 = v8;
v10 = event_handlers[v8];
if ( !v10 )
{
LABEL_10:
result = (char *)malloc(0x30uLL);
*(__m128i *)(result + 8) = _mm_loadu_si128((const __m128i *)&a7);
*((_QWORD *)result + 3) = a8;
*((_QWORD *)result + 4) = a1;
*((_QWORD *)result + 5) = a2;
*(_QWORD *)result = v10;
event_handlers[v9] = (__int64)result;
return result;
}
v11 = a7;
v12 = DWORD2(a7);
v13 = (void *)*((_QWORD *)&a7 + 1);
v14 = event_handlers[v8];
while ( 1 )
{
if ( *(_DWORD *)(v14 + 8) != v11 )
goto LABEL_4;
if ( !v11 )
break;
if ( *(_DWORD *)(v14 + 16) == v12 )
goto LABEL_9;
LABEL_4:
v14 = *(_QWORD *)v14;
if ( !v14 )
goto LABEL_10;
}
if ( !key_seq_cmp(*(_QWORD *)(v14 + 16), (__int64)v13) )
goto LABEL_4;
free(v13);
LABEL_9:
*(_QWORD *)(v14 + 32) = a1;
result = a2;
*(_QWORD *)(v14 + 40) = a2;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int128 a7, __int64 a8)
{
int v8; // eax
int v9; // er12
__int64 v10; // r15
int v11; // ebp
int v12; // er14
void *v13; // r13
__int64 v14; // rbx
char *result; // rax

v8 = func0((__int64)&a7);
v9 = v8;
v10 = event_handlers[v8];
if ( !v10 )
{
LABEL_10:
result = (char *)malloc(0x30uLL);
*(__m128i *)(result + 8) = _mm_loadu_si128((const __m128i *)&a7);
*((_QWORD *)result + 3) = a8;
*((_QWORD *)result + 4) = a1;
*((_QWORD *)result + 5) = a2;
*(_QWORD *)result = v10;
event_handlers[v9] = (__int64)result;
return result;
}
v11 = a7;
v12 = DWORD2(a7);
v13 = (void *)*((_QWORD *)&a7 + 1);
v14 = event_handlers[v8];
while ( 1 )
{
if ( *(_DWORD *)(v14 + 8) != v11 )
goto LABEL_4;
if ( !v11 )
break;
if ( *(_DWORD *)(v14 + 16) == v12 )
goto LABEL_9;
LABEL_4:
v14 = *(_QWORD *)v14;
if ( !v14 )
goto LABEL_10;
}
if ( !func1(*(_QWORD *)(v14 + 16), (__int64)v13) )
goto LABEL_4;
free(v13);
LABEL_9:
*(_QWORD *)(v14 + 32) = a1;
result = a2;
*(_QWORD *)(v14 + 40) = a2;
return result;
}

original_code:
void register_event_handler(event_t event, _Bool (*handler)(const event_t *event, void *info), void *info)
{
    int hash = hash_event(&event);
    for (struct event_handler_list *ehl = event_handlers[hash]; ehl != ((void *)0); ehl = ehl->next)
    {
        if ((ehl->handler.event.type == event.type) &&
           (((event.type == EVENT_NORMAL_KEY_SEQ) && key_seq_cmp(ehl->handler.event.key_seq, event.key_seq)) ||
            ((event.type != EVENT_NORMAL_KEY_SEQ) && (ehl->handler.event.code == event.code))))
        {
            if (event.type == EVENT_NORMAL_KEY_SEQ)
                free((void *)event.key_seq);
            ehl->handler.handler = handler;
            ehl->handler.info = info;
            return;
        }
    }
    struct event_handler_list *ehl = malloc(sizeof(*ehl));
    memcpy(&ehl->handler.event, &event, sizeof(event));
    ehl->handler.handler = handler;
    ehl->handler.info = info;
    ehl->next = event_handlers[hash];
    event_handlers[hash] = ehl;
}

canonical_original_code:
void register_event_handler(struct event event, _Bool (*handler)(struct event *event, void *info), void *info)
{
    int hash = hash_event(&event);
    for (struct event_handler_list *ehl = event_handlers[hash]; ehl != ((void *)0); ehl = ehl->next)
    {
        if ((ehl->handler.event.type == event.type) &&
           (((event.type == EVENT_NORMAL_KEY_SEQ) && key_seq_cmp(ehl->handler.event.key_seq, event.key_seq)) ||
            ((event.type != EVENT_NORMAL_KEY_SEQ) && (ehl->handler.event.code == event.code))))
        {
            if (event.type == EVENT_NORMAL_KEY_SEQ)
                free((void *)event.key_seq);
            ehl->handler.handler = handler;
            ehl->handler.info = info;
            return;
        }
    }
    struct event_handler_list *ehl = malloc(sizeof(*ehl));
    memcpy(&ehl->handler.event, &event, sizeof(event));
    ehl->handler.handler = handler;
    ehl->handler.info = info;
    ehl->next = event_handlers[hash];
    event_handlers[hash] = ehl;
}

variable_types: struct event { enum event_type { EVENT_NORMAL_KEY_SEQ=0, EVENT_INSERT_KEY=1, EVENT_MBUTTON_DOWN=2, EVENT_MBUTTON_UP=3 } type; union { int *key_seq; int code; }; struct { int x; } mbutton; }

variable_types: _Bool (*)(struct event *event, void *info)

variable_types:
info
void *


decompiled_code:
__int64 __fastcall syntax_region(int a1)
{
term_set_color(syntax_fg[a1], syntax_bg[a1]);
term_underline((unsigned __int8)syntax_underline[a1]);
return term_bold((unsigned __int8)syntax_bold[a1]);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
term_set_color(syntax_fg[a1], syntax_bg[a1]);
term_underline((unsigned __int8)syntax_underline[a1]);
return term_bold((unsigned __int8)syntax_bold[a1]);
}

original_code:
void syntax_region(enum syntax_region region)
{
    term_set_color(syntax_fg[region], syntax_bg[region]);
    term_underline(syntax_underline[region]);
    term_bold(syntax_bold[region]);
}

variable_types: enum syntax_region { SYNREG_DEFAULT=0, SYNREG_ERROR=1, SYNREG_TABBAR=2, SYNREG_TAB_ACTIVE_INNER=3, SYNREG_TAB_ACTIVE_OUTER=4, SYNREG_TAB_INACTIVE_INNER=5, SYNREG_TAB_INACTIVE_OUTER=6, SYNREG_LINENR=7, SYNREG_PLACEHOLDER_EMPTY=8, SYNREG_PLACEHOLDER_LINE=9, SYNREG_STATUSBAR=10, SYNREG_MODEBAR=11, SYNREG_NORMAL_COMMAND_COMPLETED=12, SYNREG_NORMAL_COMMAND_TYPING=13, SYNREG_COUNT=14 }


main

canonical_name: main

repo: XanClic/transalign-killer

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // r15
__int64 v8; // rax
__int64 v9; // r14
char *v10; // rbx
unsigned int v11; // er13
int v12; // ebx
unsigned int v13; // eax
__int64 v14; // r12
__int64 v15; // r14
__int64 v16; // rdx
__int64 v17; // r8
__int64 v18; // rdx
int v19; // ebp
__int64 i; // r9
int v21; // ebp
__int64 v23; // rdi
int v24; // ebp
__int64 v25; // rsi
_BYTE *v26; // rcx
int v27; // eax
unsigned int v28; // ebp
_BOOL4 v29; // eax
__int64 v30; // r13
_BYTE *v31; // [rsp+0h] [rbp-C8h]
__int64 v32; // [rsp+8h] [rbp-C0h]
signed __int64 v33; // [rsp+10h] [rbp-B8h]
__int64 v34; // [rsp+10h] [rbp-B8h]
__int64 v35; // [rsp+18h] [rbp-B0h]
char *v36; // [rsp+18h] [rbp-B0h]
__int64 v37; // [rsp+20h] [rbp-A8h]
__int64 v38; // [rsp+28h] [rbp-A0h]
__int64 v39; // [rsp+30h] [rbp-98h]
__int64 v40; // [rsp+38h] [rbp-90h]
__int64 v41; // [rsp+48h] [rbp-80h] BYREF
__int64 v42; // [rsp+50h] [rbp-78h] BYREF
void *ptr; // [rsp+58h] [rbp-70h] BYREF
__int64 v44; // [rsp+60h] [rbp-68h] BYREF
__int64 v45; // [rsp+68h] [rbp-60h] BYREF
int v46; // [rsp+74h] [rbp-54h] BYREF
__int64 v47; // [rsp+78h] [rbp-50h] BYREF
int v48; // [rsp+80h] [rbp-48h] BYREF
int v49; // [rsp+84h] [rbp-44h] BYREF
__int64 v50[8]; // [rsp+88h] [rbp-40h] BYREF

if ( argc <= 1 )
{
fwrite("Usage: transalign_killer [--cldev=x.y] <input file>\n", 1uLL, 0x34uLL, stderr);
fwrite(" --cldev=x.y: x specifies the platform index, y the device index.\n", 1uLL, 0x43uLL, stderr);
v21 = 1;
}
else
{
v31 = load_text(argv[argc - 1], (size_t *)&v45);
if ( v31 )
{
v33 = --v45;
v35 = round_up_to_power_of_two(v45, 4);
v3 = v35 / 16;
v4 = v35 / 16;
if ( v35 / 16 )
{
v5 = 0LL;
do
{
v5 += v3;
v3 /= 16LL;
}
while ( (v35 % 16) >> 4 );
}
else
{
v5 = 0LL;
}
v44 = select_device((unsigned int)(argc - 1), argv);
if ( v44 )
{
v6 = clCreateContext(0LL, 1LL, &v44, 0LL, 0LL, 0LL);
v32 = v6;
v7 = clCreateCommandQueue(v6, v44, 0LL, 0LL);
ptr = load_text("trans.cl", 0LL);
if ( ptr )
{
v40 = clCreateProgramWithSource(v6, 1LL, &ptr, 0LL, 0LL);
free(ptr);
clBuildProgram(v40, 0LL, 0LL, 0LL, 0LL, 0LL);
v37 = clCreateKernel(v40, "k_iadd", 0LL);
v8 = clCreateKernel(v40, "k_cadd", 0LL);
v9 = v8;
if ( !v37 )
_assert_fail("k_iadd", "main.c", 0x8Du, "main");
if ( !v8 )
_assert_fail("k_cadd", "main.c", 0x8Eu, "main");
v39 = 4 * v5;
v10 = (char *)malloc(4 * v5);
v42 = clCreateBuffer(v32, 9LL, 4 * v5, v10, 0LL);
clock_start();
v41 = clCreateBuffer(v32, 9LL, v45, v31, 0LL);
v38 = ((__int64 (*)(void))clock_delta)();
clSetKernelArg(v37, 0LL, 8LL, &v42);
clSetKernelArg(v37, 1LL, 8LL, &v41);
v46 = v45;
clSetKernelArg(v37, 2LL, 4LL, &v46);
v47 = v35 / 16;
clEnqueueNDRangeKernel(v7, v37, 1LL, 0LL, &v47, 0LL, 0LL, 0LL, 0LL);
v11 = v35 / 256;
if ( v11 )
{
v36 = v10;
v12 = 0;
do
{
clSetKernelArg(v9, 0LL, 8LL, &v42);
v48 = v4;
clSetKernelArg(v9, 1LL, 4LL, &v48);
v49 = v12;
clSetKernelArg(v9, 2LL, 4LL, &v49);
clFinish(v7);
v50[0] = v11;
clEnqueueNDRangeKernel(v7, v9, 1LL, 0LL, v50, 0LL, 0LL, 0LL, 0LL);
v12 = v4;
LODWORD(v4) = v11 + v4;
v13 = v11;
v11 >>= 4;
}
while ( v13 > 0xF );
v10 = v36;
}
v14 = v33 / 2;
clFinish(v7);
v15 = ((__int64 (*)(void))clock_delta)();
clEnqueueReadBuffer(v7, v42, 1LL, 0LL, v39, v10, 0LL, 0LL, 0LL);
v34 = ((__int64 (*)(void))clock_delta)();
v16 = *(unsigned int *)&v10[v39 - 4];
if ( (unsigned int)v16 < (unsigned int)v14 )
{
fprintf(stderr, "Logical index out of bounds (last index: %u).\n", v16);
v21 = 1;
}
else if ( (_DWORD)v14 )
{
v17 = (unsigned int)(v5 - 17);
v18 = (unsigned int)(v14 - 1);
v19 = 0;
for ( i = 16LL; ; v17 = (unsigned int)(v17 - i) )
{
v24 = 16 * v19;
v25 = (unsigned int)(v24 + v17);
v26 = (_BYTE *)*(unsigned int *)&v10[4 * v25];
if ( (unsigned int)v18 < (unsigned int)v26 )
{
v23 = 0LL;
}
else
{
v27 = 0;
do
{
v18 = (unsigned int)(v18 - (_DWORD)v26);
v23 = (unsigned int)++v27;
v26 = (_BYTE *)*(unsigned int *)&v10[4 * (unsigned int)(v27 + v25)];
}
while ( (unsigned int)v26 <= (unsigned int)v18 );
if ( v27 > 15 )
_assert_fail("subtree < BASE", "main.c", 0x133u, "main");
}
v19 = v23 + v24;
if ( !(_DWORD)v17 )
break;
i = (unsigned int)(16 * i);
}
v28 = 16 * v19;
if ( (_DWORD)v18 )
{
v26 = v31;
do
{
v29 = v31[v28++] != 45;
v18 = (unsigned int)(v18 - v29);
}
while ( (_DWORD)v18 );
}
v30 = clock_delta(v23, v25, v18, v26, v17, i);
printf("%li us elapsed total\n", v30);
printf(" - %li us on bandwidth forth\n", v38);
printf(" - %li us on GPU\n", v15 - v38);
printf(" - %li us on bandwidth back\n", v34 - v15);
printf(" - %li us on CPU\n", v30 - v34);
printf("Index for %u: %u\n", (unsigned int)v14, v28);
printf("cnt = %u (index + 1)\n", v28 + 1);
v21 = 0;
}
else
{
fwrite("Please used 1-based indexing (for whatever reason).\n", 1uLL, 0x34uLL, stderr);
v21 = 1;
}
free(v31);
free(v10);
clReleaseMemObject(v42);
clReleaseMemObject(v41);
clReleaseKernel(v37);
clReleaseProgram(v40);
clReleaseCommandQueue(v7);
clReleaseContext(v32);
}
else
{
v21 = 1;
}
}
else
{
v21 = 1;
}
}
else
{
v21 = 1;
}
}
return v21;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r12
__int64 v5; // rbp
__int64 v6; // rbx
__int64 v7; // r15
__int64 v8; // rax
__int64 v9; // r14
char *v10; // rbx
unsigned int v11; // er13
int v12; // ebx
unsigned int v13; // eax
__int64 v14; // r12
__int64 v15; // r14
__int64 v16; // rdx
__int64 v17; // r8
__int64 v18; // rdx
int v19; // ebp
__int64 i; // r9
int v21; // ebp
__int64 v23; // rdi
int v24; // ebp
__int64 v25; // rsi
_BYTE *v26; // rcx
int v27; // eax
unsigned int v28; // ebp
_BOOL4 v29; // eax
__int64 v30; // r13
_BYTE *v31; // [rsp+0h] [rbp-C8h]
__int64 v32; // [rsp+8h] [rbp-C0h]
signed __int64 v33; // [rsp+10h] [rbp-B8h]
__int64 v34; // [rsp+10h] [rbp-B8h]
__int64 v35; // [rsp+18h] [rbp-B0h]
char *v36; // [rsp+18h] [rbp-B0h]
__int64 v37; // [rsp+20h] [rbp-A8h]
__int64 v38; // [rsp+28h] [rbp-A0h]
__int64 v39; // [rsp+30h] [rbp-98h]
__int64 v40; // [rsp+38h] [rbp-90h]
__int64 v41; // [rsp+48h] [rbp-80h] BYREF
__int64 v42; // [rsp+50h] [rbp-78h] BYREF
void *ptr; // [rsp+58h] [rbp-70h] BYREF
__int64 v44; // [rsp+60h] [rbp-68h] BYREF
__int64 v45; // [rsp+68h] [rbp-60h] BYREF
int v46; // [rsp+74h] [rbp-54h] BYREF
__int64 v47; // [rsp+78h] [rbp-50h] BYREF
int v48; // [rsp+80h] [rbp-48h] BYREF
int v49; // [rsp+84h] [rbp-44h] BYREF
__int64 v50[8]; // [rsp+88h] [rbp-40h] BYREF

if ( argc <= 1 )
{
fwrite("Usage: transalign_killer [--cldev=x.y] <input file>\n", 1uLL, 0x34uLL, stderr);
fwrite(" --cldev=x.y: x specifies the platform index, y the device index.\n", 1uLL, 0x43uLL, stderr);
v21 = 1;
}
else
{
v31 = func1(argv[argc - 1], (size_t *)&v45);
if ( v31 )
{
v33 = --v45;
v35 = func0(v45, 4);
v3 = v35 / 16;
v4 = v35 / 16;
if ( v35 / 16 )
{
v5 = 0LL;
do
{
v5 += v3;
v3 /= 16LL;
}
while ( (v35 % 16) >> 4 );
}
else
{
v5 = 0LL;
}
v44 = select_device((unsigned int)(argc - 1), argv);
if ( v44 )
{
v6 = clCreateContext(0LL, 1LL, &v44, 0LL, 0LL, 0LL);
v32 = v6;
v7 = clCreateCommandQueue(v6, v44, 0LL, 0LL);
ptr = func1("trans.cl", 0LL);
if ( ptr )
{
v40 = clCreateProgramWithSource(v6, 1LL, &ptr, 0LL, 0LL);
free(ptr);
clBuildProgram(v40, 0LL, 0LL, 0LL, 0LL, 0LL);
v37 = clCreateKernel(v40, "k_iadd", 0LL);
v8 = clCreateKernel(v40, "k_cadd", 0LL);
v9 = v8;
if ( !v37 )
_assert_fail("k_iadd", "main.c", 0x8Du, "main");
if ( !v8 )
_assert_fail("k_cadd", "main.c", 0x8Eu, "main");
v39 = 4 * v5;
v10 = (char *)malloc(4 * v5);
v42 = clCreateBuffer(v32, 9LL, 4 * v5, v10, 0LL);
clock_start();
v41 = clCreateBuffer(v32, 9LL, v45, v31, 0LL);
v38 = ((__int64 (*)(void))clock_delta)();
clSetKernelArg(v37, 0LL, 8LL, &v42);
clSetKernelArg(v37, 1LL, 8LL, &v41);
v46 = v45;
clSetKernelArg(v37, 2LL, 4LL, &v46);
v47 = v35 / 16;
clEnqueueNDRangeKernel(v7, v37, 1LL, 0LL, &v47, 0LL, 0LL, 0LL, 0LL);
v11 = v35 / 256;
if ( v11 )
{
v36 = v10;
v12 = 0;
do
{
clSetKernelArg(v9, 0LL, 8LL, &v42);
v48 = v4;
clSetKernelArg(v9, 1LL, 4LL, &v48);
v49 = v12;
clSetKernelArg(v9, 2LL, 4LL, &v49);
clFinish(v7);
v50[0] = v11;
clEnqueueNDRangeKernel(v7, v9, 1LL, 0LL, v50, 0LL, 0LL, 0LL, 0LL);
v12 = v4;
LODWORD(v4) = v11 + v4;
v13 = v11;
v11 >>= 4;
}
while ( v13 > 0xF );
v10 = v36;
}
v14 = v33 / 2;
clFinish(v7);
v15 = ((__int64 (*)(void))clock_delta)();
clEnqueueReadBuffer(v7, v42, 1LL, 0LL, v39, v10, 0LL, 0LL, 0LL);
v34 = ((__int64 (*)(void))clock_delta)();
v16 = *(unsigned int *)&v10[v39 - 4];
if ( (unsigned int)v16 < (unsigned int)v14 )
{
fprintf(stderr, "Logical index out of bounds (last index: %u).\n", v16);
v21 = 1;
}
else if ( (_DWORD)v14 )
{
v17 = (unsigned int)(v5 - 17);
v18 = (unsigned int)(v14 - 1);
v19 = 0;
for ( i = 16LL; ; v17 = (unsigned int)(v17 - i) )
{
v24 = 16 * v19;
v25 = (unsigned int)(v24 + v17);
v26 = (_BYTE *)*(unsigned int *)&v10[4 * v25];
if ( (unsigned int)v18 < (unsigned int)v26 )
{
v23 = 0LL;
}
else
{
v27 = 0;
do
{
v18 = (unsigned int)(v18 - (_DWORD)v26);
v23 = (unsigned int)++v27;
v26 = (_BYTE *)*(unsigned int *)&v10[4 * (unsigned int)(v27 + v25)];
}
while ( (unsigned int)v26 <= (unsigned int)v18 );
if ( v27 > 15 )
_assert_fail("subtree < BASE", "main.c", 0x133u, "main");
}
v19 = v23 + v24;
if ( !(_DWORD)v17 )
break;
i = (unsigned int)(16 * i);
}
v28 = 16 * v19;
if ( (_DWORD)v18 )
{
v26 = v31;
do
{
v29 = v31[v28++] != 45;
v18 = (unsigned int)(v18 - v29);
}
while ( (_DWORD)v18 );
}
v30 = clock_delta(v23, v25, v18, v26, v17, i);
printf("%li us elapsed total\n", v30);
printf(" - %li us on bandwidth forth\n", v38);
printf(" - %li us on GPU\n", v15 - v38);
printf(" - %li us on bandwidth back\n", v34 - v15);
printf(" - %li us on CPU\n", v30 - v34);
printf("Index for %u: %u\n", (unsigned int)v14, v28);
printf("cnt = %u (index + 1)\n", v28 + 1);
v21 = 0;
}
else
{
fwrite("Please used 1-based indexing (for whatever reason).\n", 1uLL, 0x34uLL, stderr);
v21 = 1;
}
free(v31);
free(v10);
clReleaseMemObject(v42);
clReleaseMemObject(v41);
clReleaseKernel(v37);
clReleaseProgram(v40);
clReleaseCommandQueue(v7);
clReleaseContext(v32);
}
else
{
v21 = 1;
}
}
else
{
v21 = 1;
}
}
else
{
v21 = 1;
}
}
return v21;
}

original_code:
int main(int argc, char *argv[])
{
    int ret = 0;
    if (argc < 2)
    {
        fprintf(stderr, "Usage: transalign_killer <input file>\n");
        return 1;
    }
    long seq_length;
    char *sequence = load_text(argv[argc - 1], &seq_length);
    if (!sequence)
        return 1;
    seq_length--;
    unsigned long letter_index = seq_length / 2;
    clock_start();
    unsigned long index = find_index(sequence, letter_index - 1);
    long delta_time = clock_delta();
    printf("%li us elapsed total\n\n", delta_time);
    printf("Index for %lu: %lu\n", letter_index, index);
    printf("cnt = %lu (index + 1)\n", index + 1);
    free(sequence);
    return ret;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: ret int

variable_types:
sequence
char *

variable_types:
index
unsigned long


repo: Xangis/ModernMUDConverter

decompiled_code:
__int64 __fastcall is_name(__int64 a1, __int64 a2)
{
char v4[1224]; // [rsp+0h] [rbp-4C8h] BYREF

while ( 1 )
{
a2 = one_argument(a2, v4);
if ( !v4[0] )
break;
if ( !(unsigned __int8)str_cmp(a1, v4) )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
char v4[1224]; // [rsp+0h] [rbp-4C8h] BYREF

while ( 1 )
{
a2 = one_argument(a2, v4);
if ( !v4[0] )
break;
if ( !(unsigned __int8)str_cmp(a1, v4) )
return 1LL;
}
return 0LL;
}

original_code:
bool is_name( const char *str, char *namelist )
{
    char name [299 * 4];
    for ( ; ; )
    {
 namelist = one_argument( namelist, name );
 if ( name[0] == '\0' )
     return 0;
 if ( !str_cmp( str, name ) )
     return 1;
    }
}

canonical_original_code:
unsigned char is_name(char *str, char *namelist)
{
    char name[-1];
    for ( ; ; )
    {
 namelist = one_argument( namelist, name );
 if ( name[0] == '\0' )
     return 0;
 if ( !str_cmp( str, name ) )
     return 1;
    }
}

variable_types:
str
char *

variable_types:
namelist
char *

variable_types:
name
char [-1]

return_type: unsigned char


decompiled_code:
__int64 __fastcall get_obj_weight(__int64 a1)
{
unsigned int v1; // ebp
__int64 i; // rbx

v1 = *(_DWORD *)(a1 + 176);
for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 8) )
{
if ( !*(_BYTE *)(i + 228) )
v1 += get_obj_weight(i);
}
return v1;
}

original_code:
int get_obj_weight( OBJ_DATA *obj )
{
    int weight;
    weight = obj->weight;
    for ( obj = obj->contains; obj; obj = obj->next_content )
    {
 if ( obj->deleted )
     continue;
 weight += get_obj_weight( obj );
    }
    return weight;
}

canonical_original_code:
int get_obj_weight(struct obj_data *obj)
{
    int weight;
    weight = obj->weight;
    for ( obj = obj->contains; obj; obj = obj->next_content )
    {
 if ( obj->deleted )
     continue;
 weight += get_obj_weight( obj );
    }
    return weight;
}

variable_types: struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *group_leader; struct char_data *fighting; struct char_data *reply; struct char_data *riding; struct char_data *rider; struct char_data *next_in_group; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); unsigned char (*death_fun)(struct char_data *ch, int cmd); struct shop_data { struct shop_data *next; struct area_data { struct area_data *next; struct reset_data { struct reset_data *next; char command; int arg0; int arg1; int arg2; int arg3; int arg4; int arg5; int arg6; int arg7; } *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; } *area; int keeper; int buy_type[10]; int sell_item[20]; int profit_buy; int profit_sell; int open_hour; int close_hour; } *pShop; struct area_data *area; char *player_name; char *short_descr; char *long_descr; char *description; int vnum; int count; int killed; int sex; int c_class; int level; int act; int affected_by[5]; int alignment; int race; int position; int progtypes; int resistant; int immune; int susceptible; } *pIndexData; struct affect_data { struct affect_data *next; int skill; int spell; int song; int duration; int location; int modifier; int bitvector[5]; int level; unsigned char deleted; } *affected; struct obj_data *carrying; struct room_index_data { struct room_index_data *next; struct char_data *people; struct obj_data *contents; struct extra_descr_data { struct extra_descr_data *next; char *keyword; char *description; unsigned char deleted; } *extra_descr; struct area_data *area; struct exit_data { struct room_index_data *to_room; int vnum; int exit_info; int key; char *keyword; char *description; struct exit_data *next; } *exit[10]; char *name; char *description; int vnum; int room_flags[2]; int orig_room_flags; int light; int current; int current_dir; int fall_chance; int sector_type; int extra_sector_info; struct reset_data *reset_first; struct reset_data *reset_last; } *in_room; struct room_index_data *was_in_room; char *name; char *short_descr; char *long_descr; char *description; int sex; int c_class; int race; int level; int trust; int size; int played; int cast_spl; int cast_time; int perm_str; int perm_int; int perm_wis; int perm_dex; int perm_con; int perm_agi; int perm_cha; int perm_pow; int perm_luk; int mod_str; int mod_int; int mod_wis; int mod_dex; int mod_con; int mod_agi; int mod_cha; int mod_pow; int mod_luk; long logon; long save_time; long last_note; int timer; int wait; int hit; int max_hit; int mana; int max_mana; int move; int max_move; struct coin_data { int copper; int silver; int gold; int platinum; } money; int exp; int act; int affected_by[5]; int position; int carry_weight; int carry_number; int saving_throw[5]; int alignment; int hitroll; int damroll; int armor; int wimpy; int deaf; unsigned char deleted; int mpactnum; int resistant; int immune; int susceptible; int fly_level; int load_room_vnum; } *keeper, unsigned char hit); struct char_data *carried_by; struct extra_descr_data *extra_descr; struct affect_data *affected; struct obj_index_data { struct obj_index_data *next; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct extra_descr_data *extra_descr; struct affect_data *affected; struct trap_data { int trigger; int damage; int charges; int level; int percent; } *trap; char *name; char *short_descr; char *description; int vnum; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int count; int weight; int cost; int level; int progtypes; int condition; int value[8]; struct area_data *area; } *pIndexData; struct room_index_data *in_room; struct trap_data *trap; char *name; char *short_descr; char *description; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int wear_loc; int weight; int cost; int level; int timer; int value[8]; int condition; unsigned char deleted; int fly_level; } *

variable_types: weight int

user_defined_types: struct obj_data { struct obj_data *next; struct obj_data *next_content; struct obj_data *contains; struct obj_data *in_obj; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct char_data *carried_by; struct extra_descr_data *extra_descr; struct affect_data *affected; struct obj_index_data *pIndexData; struct room_index_data *in_room; struct trap_data *trap; char *name; char *short_descr; char *description; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int wear_loc; int weight; int cost; int level; int timer; int value[8]; int condition; unsigned char deleted; int fly_level; }

user_defined_types: struct obj_index_data { struct obj_index_data *next; unsigned char (*spec_fun)(struct obj_data *obj, struct char_data *keeper, unsigned char hit); struct extra_descr_data *extra_descr; struct affect_data *affected; struct trap_data *trap; char *name; char *short_descr; char *description; int vnum; int item_type; int extra_flags[2]; int affected_by[5]; int wear_flags; int anti_flags; int anti_flags2; int material; int size; int volume; int craftsmanship; int count; int weight; int cost; int level; int progtypes; int condition; int value[8]; struct area_data *area; }

user_defined_types: struct char_data { struct char_data *next; struct char_data *next_in_room; struct char_data *master; struct char_data *group_leader; struct char_data *fighting; struct char_data *reply; struct char_data *riding; struct char_data *rider; struct char_data *next_in_group; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); struct mob_index_data *pIndexData; struct affect_data *affected; struct obj_data *carrying; struct room_index_data *in_room; struct room_index_data *was_in_room; char *name; char *short_descr; char *long_descr; char *description; int sex; int c_class; int race; int level; int trust; int size; int played; int cast_spl; int cast_time; int perm_str; int perm_int; int perm_wis; int perm_dex; int perm_con; int perm_agi; int perm_cha; int perm_pow; int perm_luk; int mod_str; int mod_int; int mod_wis; int mod_dex; int mod_con; int mod_agi; int mod_cha; int mod_pow; int mod_luk; long logon; long save_time; long last_note; int timer; int wait; int hit; int max_hit; int mana; int max_mana; int move; int max_move; struct coin_data money; int exp; int act; int affected_by[5]; int position; int carry_weight; int carry_number; int saving_throw[5]; int alignment; int hitroll; int damroll; int armor; int wimpy; int deaf; unsigned char deleted; int mpactnum; int resistant; int immune; int susceptible; int fly_level; int load_room_vnum; }

user_defined_types: struct mob_index_data { struct mob_index_data *next; unsigned char (*spec_fun)(struct char_data *ch, int cmd); unsigned char (*spec_fun2)(struct char_data *ch, int cmd); unsigned char (*death_fun)(struct char_data *ch, int cmd); struct shop_data *pShop; struct area_data *area; char *player_name; char *short_descr; char *long_descr; char *description; int vnum; int count; int killed; int sex; int c_class; int level; int act; int affected_by[5]; int alignment; int race; int position; int progtypes; int resistant; int immune; int susceptible; }

user_defined_types: struct room_index_data { struct room_index_data *next; struct char_data *people; struct obj_data *contents; struct extra_descr_data *extra_descr; struct area_data *area; struct exit_data *exit[10]; char *name; char *description; int vnum; int room_flags[2]; int orig_room_flags; int light; int current; int current_dir; int fall_chance; int sector_type; int extra_sector_info; struct reset_data *reset_first; struct reset_data *reset_last; }

user_defined_types: struct shop_data { struct shop_data *next; struct area_data *area; int keeper; int buy_type[10]; int sell_item[20]; int profit_buy; int profit_sell; int open_hour; int close_hour; }

user_defined_types: struct area_data { struct area_data *next; struct reset_data *reset_first; struct reset_data *reset_last; char *name; int defender; int defender_num; int barracks; int judge; int jail; int squads; int dispatched; int recall; int version; int age; int nplayer; int justice; char *filename; char *builders; int security; int lvnum; int uvnum; int vnum; int area_flags; int low_r_vnum; int hi_r_vnum; int low_o_vnum; int hi_o_vnum; int low_m_vnum; int hi_m_vnum; int llv; int ulv; char *author; char *resetmsg; int times_reset; int resetmode; int llifespan; int ulifespan; }


decompiled_code:
void end_of_game()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void end_of_game( void )
{
    return;
}

canonical_original_code:
void end_of_game()
{
    return;
}


decompiled_code:
__int64 __fastcall race_lookup(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !(unsigned __int8)str_prefix(a1, race_table[21 * v1]) )
break;
if ( ++v1 == 78 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !(unsigned __int8)str_prefix(a1, race_table[21 * v1]) )
break;
if ( ++v1 == 78 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int race_lookup( const char *race )
{
    int index;
    for ( index = 0; index < 78; index++ )
        if ( !str_prefix( race, race_table[index].name ) )
     return index;
    return -1;
}

canonical_original_code:
int race_lookup(char *race)
{
    int index;
    for ( index = 0; index < 78; index++ )
        if ( !str_prefix( race, race_table[index].name ) )
     return index;
    return -1;
}

variable_types:
race
char *

variable_types: index int


decompiled_code:
__int64 __fastcall size_lookup(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rsi

v1 = 0;
while ( 1 )
{
v2 = size_string(v1);
if ( !(unsigned __int8)str_prefix(a1, v2) )
break;
if ( ++v1 == 11 )
return (unsigned int)-1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // ebx
__int64 v2; // rsi

v1 = 0;
while ( 1 )
{
v2 = size_string(v1);
if ( !(unsigned __int8)str_prefix(a1, v2) )
break;
if ( ++v1 == 11 )
return (unsigned int)-1;
}
return v1;
}

original_code:
int size_lookup( const char *size )
{
    int index;
    for ( index = 0; index < 11; index++ )
        if ( !str_prefix( size, size_string(index) ) )
     return index;
    return -1;
}

canonical_original_code:
int size_lookup(char *size)
{
    int index;
    for ( index = 0; index < 11; index++ )
        if ( !str_prefix( size, size_string(index) ) )
     return index;
    return -1;
}

variable_types:
size
char *


decompiled_code:
__int64 __fastcall race_key_lookup(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !(unsigned __int8)str_cmp(a1, race_table[21 * v1 + 2]) )
break;
if ( ++v1 == 78 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !(unsigned __int8)str_cmp(a1, race_table[21 * v1 + 2]) )
break;
if ( ++v1 == 78 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int race_key_lookup( const char *race )
{
    int index;
    for ( index = 0; index < 78; index++ )
        if ( !str_cmp( race, race_table[index].key ) )
     return index;
    return -1;
}

canonical_original_code:
int race_key_lookup(char *race)
{
    int index;
    for ( index = 0; index < 78; index++ )
        if ( !str_cmp( race, race_table[index].key ) )
     return index;
    return -1;
}