decompiled_code:
void *__fastcall TXT_DrawHorizScrollbar(unsigned int a1, signed int a2, int a3, int a4, int a5)
{
void *result; // rax
int v8; // ebx
int v9; // er15
int v10; // er12
char v12[64]; // [rsp+18h] [rbp-40h] BYREF

result = cliparea;
if ( *((_DWORD *)cliparea + 2) <= a2 && *((_DWORD *)cliparea + 3) > a2 )
{
TXT_SaveColors(v12);
v8 = a1 + 1;
TXT_FGColor(0LL);
v9 = a1 + 1;
TXT_BGColor(7LL, 0LL);
TXT_GotoXY(a1, (unsigned int)a2);
TXT_PutChar(27LL);
if ( a5 > 0 )
v9 = a4 * (a3 - 3) / a5 + v8;
v10 = a3 + a1 - 1;
if ( v10 <= v9 )
v9 = a3 + a1 - 2;
if ( v10 > v8 )
{
do
{
if ( *(_DWORD *)cliparea <= v8 && *((_DWORD *)cliparea + 1) > v8 )
{
if ( v9 == v8 )
TXT_PutChar(4294967259LL);
else
TXT_PutChar(4294967217LL);
}
++v8;
}
while ( v10 != v8 );
}
TXT_PutChar(26LL);
result = (void *)TXT_RestoreColors(v12);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(unsigned int a1, signed int a2, int a3, int a4, int a5)
{
void *result; // rax
int v8; // ebx
int v9; // er15
int v10; // er12
char v12[64]; // [rsp+18h] [rbp-40h] BYREF

result = cliparea;
if ( *((_DWORD *)cliparea + 2) <= a2 && *((_DWORD *)cliparea + 3) > a2 )
{
TXT_SaveColors(v12);
v8 = a1 + 1;
TXT_FGColor(0LL);
v9 = a1 + 1;
TXT_BGColor(7LL, 0LL);
TXT_GotoXY(a1, (unsigned int)a2);
TXT_PutChar(27LL);
if ( a5 > 0 )
v9 = a4 * (a3 - 3) / a5 + v8;
v10 = a3 + a1 - 1;
if ( v10 <= v9 )
v9 = a3 + a1 - 2;
if ( v10 > v8 )
{
do
{
if ( *(_DWORD *)cliparea <= v8 && *((_DWORD *)cliparea + 1) > v8 )
{
if ( v9 == v8 )
TXT_PutChar(4294967259LL);
else
TXT_PutChar(4294967217LL);
}
++v8;
}
while ( v10 != v8 );
}
TXT_PutChar(26LL);
result = (void *)TXT_RestoreColors(v12);
}
return result;
}

original_code:
void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range)
{
    txt_saved_colors_t colors;
    int x1;
    int cursor_x;
    if (!((y) >= cliparea->y1 && (y) < cliparea->y2))
    {
        return;
    }
    TXT_SaveColors(&colors);
    TXT_FGColor(TXT_COLOR_BLACK);
    TXT_BGColor(TXT_COLOR_GREY, 0);
    TXT_GotoXY(x, y);
    TXT_PutChar('\x1b');
    cursor_x = x + 1;
    if (range > 0)
    {
        cursor_x += (cursor * (w - 3)) / range;
    }
    if (cursor_x > x + w - 2)
    {
        cursor_x = x + w - 2;
    }
    for (x1=x+1; x1<x+w-1; ++x1)
    {
        if (((x1) >= cliparea->x1 && (x1) < cliparea->x2))
        {
            if (x1 == cursor_x)
            {
                TXT_PutChar('\xdb');
            }
            else
            {
                TXT_PutChar('\xb1');
            }
        }
    }
    TXT_PutChar('\x1a');
    TXT_RestoreColors(&colors);
}

canonical_original_code:
void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range)
{
    struct txt_saved_colors_t colors;
    int x1;
    int cursor_x;
    if (!((y) >= cliparea->y1 && (y) < cliparea->y2))
    {
        return;
    }
    TXT_SaveColors(&colors);
    TXT_FGColor(TXT_COLOR_BLACK);
    TXT_BGColor(TXT_COLOR_GREY, 0);
    TXT_GotoXY(x, y);
    TXT_PutChar('\x1b');
    cursor_x = x + 1;
    if (range > 0)
    {
        cursor_x += (cursor * (w - 3)) / range;
    }
    if (cursor_x > x + w - 2)
    {
        cursor_x = x + w - 2;
    }
    for (x1=x+1; x1<x+w-1; ++x1)
    {
        if (((x1) >= cliparea->x1 && (x1) < cliparea->x2))
        {
            if (x1 == cursor_x)
            {
                TXT_PutChar('\xdb');
            }
            else
            {
                TXT_PutChar('\xb1');
            }
        }
    }
    TXT_PutChar('\x1a');
    TXT_RestoreColors(&colors);
}

variable_types: cursor int

variable_types: range int


repo: JohnnyonFlame/textlauncher

decompiled_code:
void *__fastcall TXT_DrawVertScrollbar(unsigned int a1, unsigned int a2, int a3, int a4, int a5)
{
void *result; // rax
signed int v8; // ebx
int v9; // er12
int v10; // er14
char v12[64]; // [rsp+18h] [rbp-40h] BYREF

result = cliparea;
if ( *(_DWORD *)cliparea <= (signed int)a1 && *((_DWORD *)cliparea + 1) > (signed int)a1 )
{
TXT_SaveColors(v12);
v8 = a2 + 1;
TXT_FGColor(0LL);
TXT_BGColor(7LL, 0LL);
v9 = a2 + a3 - 1;
TXT_GotoXY(a1, a2);
TXT_PutChar(24LL);
if ( v9 <= (int)(a2 + 1) )
{
LABEL_12:
TXT_GotoXY(a1, (unsigned int)v9);
TXT_PutChar(25LL);
return (void *)TXT_RestoreColors(v12);
}
v10 = a2 + 1;
if ( a5 > 0 )
v10 = a4 * (a3 - 3) / a5 + v8;
while ( 1 )
{
if ( *((_DWORD *)cliparea + 2) > v8 || *((_DWORD *)cliparea + 3) <= v8 )
goto LABEL_7;
TXT_GotoXY(a1, (unsigned int)v8);
if ( v10 == v8 )
{
TXT_PutChar(4294967259LL);
LABEL_7:
if ( v9 <= ++v8 )
goto LABEL_12;
}
else
{
++v8;
TXT_PutChar(4294967217LL);
if ( v9 <= v8 )
goto LABEL_12;
}
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(unsigned int a1, unsigned int a2, int a3, int a4, int a5)
{
void *result; // rax
signed int v8; // ebx
int v9; // er12
int v10; // er14
char v12[64]; // [rsp+18h] [rbp-40h] BYREF

result = cliparea;
if ( *(_DWORD *)cliparea <= (signed int)a1 && *((_DWORD *)cliparea + 1) > (signed int)a1 )
{
TXT_SaveColors(v12);
v8 = a2 + 1;
TXT_FGColor(0LL);
TXT_BGColor(7LL, 0LL);
v9 = a2 + a3 - 1;
TXT_GotoXY(a1, a2);
TXT_PutChar(24LL);
if ( v9 <= (int)(a2 + 1) )
{
LABEL_12:
TXT_GotoXY(a1, (unsigned int)v9);
TXT_PutChar(25LL);
return (void *)TXT_RestoreColors(v12);
}
v10 = a2 + 1;
if ( a5 > 0 )
v10 = a4 * (a3 - 3) / a5 + v8;
while ( 1 )
{
if ( *((_DWORD *)cliparea + 2) > v8 || *((_DWORD *)cliparea + 3) <= v8 )
goto LABEL_7;
TXT_GotoXY(a1, (unsigned int)v8);
if ( v10 == v8 )
{
TXT_PutChar(4294967259LL);
LABEL_7:
if ( v9 <= ++v8 )
goto LABEL_12;
}
else
{
++v8;
TXT_PutChar(4294967217LL);
if ( v9 <= v8 )
goto LABEL_12;
}
}
}
return result;
}

original_code:
void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range)
{
    txt_saved_colors_t colors;
    int y1;
    int cursor_y;
    if (!((x) >= cliparea->x1 && (x) < cliparea->x2))
    {
        return;
    }
    TXT_SaveColors(&colors);
    TXT_FGColor(TXT_COLOR_BLACK);
    TXT_BGColor(TXT_COLOR_GREY, 0);
    TXT_GotoXY(x, y);
    TXT_PutChar('\x18');
    cursor_y = y + 1;
    if (cursor_y > y + h - 2)
    {
        cursor_y = y + h - 2;
    }
    if (range > 0)
    {
        cursor_y += (cursor * (h - 3)) / range;
    }
    for (y1=y+1; y1<y+h-1; ++y1)
    {
        if (((y1) >= cliparea->y1 && (y1) < cliparea->y2))
        {
            TXT_GotoXY(x, y1);
            if (y1 == cursor_y)
            {
                TXT_PutChar('\xdb');
            }
            else
            {
                TXT_PutChar('\xb1');
            }
        }
    }
    TXT_GotoXY(x, y + h - 1);
    TXT_PutChar('\x19');
    TXT_RestoreColors(&colors);
}

canonical_original_code:
void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range)
{
    struct txt_saved_colors_t colors;
    int y1;
    int cursor_y;
    if (!((x) >= cliparea->x1 && (x) < cliparea->x2))
    {
        return;
    }
    TXT_SaveColors(&colors);
    TXT_FGColor(TXT_COLOR_BLACK);
    TXT_BGColor(TXT_COLOR_GREY, 0);
    TXT_GotoXY(x, y);
    TXT_PutChar('\x18');
    cursor_y = y + 1;
    if (cursor_y > y + h - 2)
    {
        cursor_y = y + h - 2;
    }
    if (range > 0)
    {
        cursor_y += (cursor * (h - 3)) / range;
    }
    for (y1=y+1; y1<y+h-1; ++y1)
    {
        if (((y1) >= cliparea->y1 && (y1) < cliparea->y2))
        {
            TXT_GotoXY(x, y1);
            if (y1 == cursor_y)
            {
                TXT_PutChar('\xdb');
            }
            else
            {
                TXT_PutChar('\xb1');
            }
        }
    }
    TXT_GotoXY(x, y + h - 1);
    TXT_PutChar('\x19');
    TXT_RestoreColors(&colors);
}

variable_types: x int

variable_types: y int

variable_types: h int

variable_types: struct txt_saved_colors_t { int bgcolor; int fgcolor; }

return_type: void


decompiled_code:
void TXT_InitClipArea()
{
_QWORD *v0; // rax

if ( !cliparea )
{
v0 = malloc(0x18uLL);
cliparea = v0;
*v0 = 0x5000000000LL;
v0[1] = 0x1800000001LL;
v0[2] = 0LL;
}
}

original_code:
void TXT_InitClipArea(void)
{
    if (cliparea == ((void *)0))
    {
        cliparea = malloc(sizeof(txt_cliparea_t));
        cliparea->x1 = 0;
        cliparea->x2 = 80;
        cliparea->y1 = 1;
        cliparea->y2 = 25 - 1;
        cliparea->next = ((void *)0);
    }
}

canonical_original_code:
void TXT_InitClipArea()
{
    if (cliparea == ((void *)0))
    {
        cliparea = malloc(sizeof(txt_cliparea_t));
        cliparea->x1 = 0;
        cliparea->x2 = 80;
        cliparea->y1 = 1;
        cliparea->y2 = 25 - 1;
        cliparea->next = ((void *)0);
    }
}


decompiled_code:
void TXT_PopClipArea()
{
void *v0; // rbx

v0 = (void *)*((_QWORD *)cliparea + 2);
if ( v0 )
{
free(cliparea);
cliparea = v0;
}
}

canonical_decompiled_code:
void func10()
{
void *v0; // rbx

v0 = (void *)*((_QWORD *)cliparea + 2);
if ( v0 )
{
free(cliparea);
cliparea = v0;
}
}

original_code:
void TXT_PopClipArea(void)
{
    txt_cliparea_t *next_cliparea;
    if (cliparea->next == ((void *)0))
        return;
    next_cliparea = cliparea->next;
    free(cliparea);
    cliparea = next_cliparea;
}

canonical_original_code:
void TXT_PopClipArea()
{
    struct txt_cliparea_s *next_cliparea;
    if (cliparea->next == ((void *)0))
        return;
    next_cliparea = cliparea->next;
    free(cliparea);
    cliparea = next_cliparea;
}

variable_types: struct txt_cliparea_s { int x1; int y1; struct txt_cliparea_s *next; } *


DrawDesktopBackground

original_code:
static void DrawDesktopBackground(const char *title)
{
    int i;
    unsigned char *screendata;
    unsigned char *p;
    screendata = TXT_GetScreenData();
    p = screendata;
    for (i=0; i<80 * 25; ++i)
    {
        *p++ = 0xb1;
        *p++ = TXT_COLOR_GREY | (TXT_COLOR_BLUE << 4);
    }
    p = screendata;
    for (i=0; i<80; ++i)
    {
        *p++ = ' ';
        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
    }
    p = screendata + (25 - 1) * 80 * 2;
    for (i=0; i<80; ++i)
    {
        *p++ = ' ';
        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
    }
    TXT_GotoXY(0, 0);
    TXT_FGColor(TXT_COLOR_BLACK);
    TXT_BGColor(TXT_COLOR_GREY, 0);
    TXT_PutChar(' ');
    TXT_Puts(title);
}

canonical_original_code:
static void DrawDesktopBackground(char *title)
{
    int i;
    unsigned char *screendata;
    unsigned char *p;
    screendata = TXT_GetScreenData();
    p = screendata;
    for (i=0; i<80 * 25; ++i)
    {
        *p++ = 0xb1;
        *p++ = TXT_COLOR_GREY | (TXT_COLOR_BLUE << 4);
    }
    p = screendata;
    for (i=0; i<80; ++i)
    {
        *p++ = ' ';
        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
    }
    p = screendata + (25 - 1) * 80 * 2;
    for (i=0; i<80; ++i)
    {
        *p++ = ' ';
        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
    }
    TXT_GotoXY(0, 0);
    TXT_FGColor(TXT_COLOR_BLACK);
    TXT_BGColor(TXT_COLOR_GREY, 0);
    TXT_PutChar(' ');
    TXT_Puts(title);
}

variable_types:
title
char *

variable_types: i int

variable_types:
screendata
unsigned char *

variable_types:
p
unsigned char *


decompiled_code:
__int64 __fastcall TXT_SetDesktopTitle(char *s)
{
free(desktop_title);
desktop_title = strdup(s);
return TXT_SetWindowTitle(s);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s)
{
free(desktop_title);
desktop_title = strdup(s);
return TXT_SetWindowTitle(s);
}

original_code:
void TXT_SetDesktopTitle(char *title)
{
    free(desktop_title);
    desktop_title = strdup(title);
    TXT_SetWindowTitle(title);
}


decompiled_code:
__int64 TXT_DrawDesktop()
{
void *v0; // rdi
__int64 v1; // rbx
__int64 v2; // rdi

TXT_InitClipArea();
v0 = desktop_title;
if ( !desktop_title )
v0 = &unk_788;
DrawDesktopBackground((__int64)v0);
if ( num_windows > 0 )
{
v1 = 0LL;
do
{
v2 = all_windows[v1++];
TXT_DrawWindow(v2);
}
while ( num_windows > (int)v1 );
}
return TXT_UpdateScreen();
}

canonical_decompiled_code:
__int64 func5()
{
void *v0; // rdi
__int64 v1; // rbx
__int64 v2; // rdi

TXT_InitClipArea();
v0 = desktop_title;
if ( !desktop_title )
v0 = &unk_788;
func0((__int64)v0);
if ( num_windows > 0 )
{
v1 = 0LL;
do
{
v2 = all_windows[v1++];
TXT_DrawWindow(v2);
}
while ( num_windows > (int)v1 );
}
return TXT_UpdateScreen();
}

original_code:
void TXT_DrawDesktop(void)
{
    int i;
    const char *title;
    TXT_InitClipArea();
    if (desktop_title == ((void *)0))
        title = "";
    else
        title = desktop_title;
    DrawDesktopBackground(title);
    for (i=0; i<num_windows; ++i)
    {
        TXT_DrawWindow(all_windows[i]);
    }
    TXT_UpdateScreen();
}

canonical_original_code:
void TXT_DrawDesktop()
{
    int i;
    char *title;
    TXT_InitClipArea();
    if (desktop_title == ((void *)0))
        title = "";
    else
        title = desktop_title;
    DrawDesktopBackground(title);
    for (i=0; i<num_windows; ++i)
    {
        TXT_DrawWindow(all_windows[i]);
    }
    TXT_UpdateScreen();
}


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

while ( 1 )
{
result = TXT_GetChar();
if ( (int)result <= 0 )
break;
if ( num_windows > 0 )
TXT_WindowKeyPress(all_windows[num_windows - 1], (unsigned int)result);
}
return result;
}

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

while ( 1 )
{
result = TXT_GetChar();
if ( (int)result <= 0 )
break;
if ( num_windows > 0 )
TXT_WindowKeyPress(all_windows[num_windows - 1], (unsigned int)result);
}
return result;
}

original_code:
void TXT_DispatchEvents(void)
{
    int c;
    while ((c = TXT_GetChar()) > 0)
    {
        if (num_windows > 0)
        {
            TXT_WindowKeyPress(all_windows[num_windows - 1], c);
        }
    }
}

canonical_original_code:
void TXT_DispatchEvents()
{
    int c;
    while ((c = TXT_GetChar()) > 0)
    {
        if (num_windows > 0)
        {
            TXT_WindowKeyPress(all_windows[num_windows - 1], c);
        }
    }
}

variable_types: c int


decompiled_code:
void TXT_ExitMainLoop()
{
main_loop_running = 0;
}

canonical_decompiled_code:
void func7()
{
main_loop_running = 0;
}

original_code:
void TXT_ExitMainLoop(void)
{
    main_loop_running = 0;
}


decompiled_code:
__int64 TXT_DrawASCIITable()
{
unsigned int v0; // er13
__int64 v1; // r14
__int64 v2; // r14
__int64 v3; // r12
unsigned int v4; // ebx
unsigned int v5; // ebp
__int64 v6; // rdi
char s[50]; // [rsp+6h] [rbp-32h] BYREF

v0 = 0;
v1 = TXT_GetScreenData();
TXT_FGColor(15LL);
v2 = v1 + 6;
TXT_BGColor(0LL, 0LL);
do
{
v3 = v2;
v4 = 0;
v5 = 16 * v0;
do
{
v6 = v4;
v4 += 5;
v3 += 10LL;
TXT_GotoXY(v6, v0);
sprintf(s, "%02x ", v5);
TXT_Puts(s);
*(_BYTE *)(v3 - 10) = v5++;
}
while ( v4 != 80 );
++v0;
v2 += 160LL;
}
while ( v0 != 16 );
return TXT_UpdateScreen();
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // er13
__int64 v1; // r14
__int64 v2; // r14
__int64 v3; // r12
unsigned int v4; // ebx
unsigned int v5; // ebp
__int64 v6; // rdi
char s[50]; // [rsp+6h] [rbp-32h] BYREF

v0 = 0;
v1 = TXT_GetScreenData();
TXT_FGColor(15LL);
v2 = v1 + 6;
TXT_BGColor(0LL, 0LL);
do
{
v3 = v2;
v4 = 0;
v5 = 16 * v0;
do
{
v6 = v4;
v4 += 5;
v3 += 10LL;
TXT_GotoXY(v6, v0);
sprintf(s, "%02x ", v5);
TXT_Puts(s);
*(_BYTE *)(v3 - 10) = v5++;
}
while ( v4 != 80 );
++v0;
v2 += 160LL;
}
while ( v0 != 16 );
return TXT_UpdateScreen();
}

original_code:
void TXT_DrawASCIITable(void)
{
    unsigned char *screendata;
    char buf[10];
    int x, y;
    int n;
    screendata = TXT_GetScreenData();
    TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
    TXT_BGColor(TXT_COLOR_BLACK, 0);
    for (y=0; y<16; ++y)
    {
        for (x=0; x<16; ++x)
        {
            n = y * 16 + x;
            TXT_GotoXY(x * 5, y);
            sprintf(buf, "%02x   ", n);
            TXT_Puts(buf);
            screendata[(y * 80 + x * 5 + 3) * 2] = n;
        }
    }
    TXT_UpdateScreen();
}

canonical_original_code:
void TXT_DrawASCIITable()
{
    unsigned char *screendata;
    char buf[10];
    int x; int y;
    int n;
    screendata = TXT_GetScreenData();
    TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
    TXT_BGColor(TXT_COLOR_BLACK, 0);
    for (y=0; y<16; ++y)
    {
        for (x=0; x<16; ++x)
        {
            n = y * 16 + x;
            TXT_GotoXY(x * 5, y);
            sprintf(buf, "%02x   ", n);
            TXT_Puts(buf);
            screendata[(y * 80 + x * 5 + 3) * 2] = n;
        }
    }
    TXT_UpdateScreen();
}

variable_types:
buf
char [10]

variable_types: n int


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

main_loop_running = 1;
do
{
TXT_DispatchEvents();
if ( num_windows <= 0 )
TXT_ExitMainLoop();
TXT_DrawDesktop();
TXT_Sleep(66LL);
result = (unsigned int)main_loop_running;
}
while ( main_loop_running );
return result;
}

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

main_loop_running = 1;
do
{
func6();
if ( num_windows <= 0 )
func7();
func5();
TXT_Sleep(66LL);
result = (unsigned int)main_loop_running;
}
while ( main_loop_running );
return result;
}

original_code:
void TXT_GUIMainLoop(void)
{
    main_loop_running = 1;
    while (main_loop_running)
    {
        TXT_DispatchEvents();
        if (num_windows <= 0)
        {
            TXT_ExitMainLoop();
        }
        TXT_DrawDesktop();
        TXT_Sleep(66);
    }
}

canonical_original_code:
void TXT_GUIMainLoop()
{
    main_loop_running = 1;
    while (main_loop_running)
    {
        TXT_DispatchEvents();
        if (num_windows <= 0)
        {
            TXT_ExitMainLoop();
        }
        TXT_DrawDesktop();
        TXT_Sleep(66);
    }
}


SDLButtonToTXTButton

decompiled_code:
__int64 __fastcall SDLButtonToTXTButton(int a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = (unsigned int)(a1 - 1);
result = (unsigned int)(a1 + 255);
if ( (unsigned int)v1 <= 2 )
result = (unsigned int)CSWTCH_50[v1];
return result;
}

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

v1 = (unsigned int)(a1 - 1);
result = (unsigned int)(a1 + 255);
if ( (unsigned int)v1 <= 2 )
result = (unsigned int)CSWTCH_50[v1];
return result;
}

original_code:
static int SDLButtonToTXTButton(int button)
{
    switch (button)
    {
        case 1:
            return (256 + 0);
        case 3:
            return (256 + 1);
        case 2:
            return (256 + 2);
        default:
            return 256 + button - 1;
    }
}

variable_types: button int

return_type: int


SpecialKeyName

decompiled_code:
const char *__fastcall SpecialKeyName(int a1)
{
const char *result; // rax

if ( a1 <= 61 )
{
if ( a1 > 7 )
{
switch ( a1 )
{
case 8:
result = "BKSP";
break;
case 9:
result = "TAB";
break;
case 13:
result = "ENTER";
break;
case 20:
result = "PAUSE";
break;
case 27:
result = "ESC";
break;
case 32:
result = "SPACE";
break;
case 45:
result = "MINUS";
break;
case 61:
result = "EQUALS";
break;
default:
goto LABEL_4;
}
}
else
{
LABEL_4:
result = 0LL;
}
}
else
{
switch ( a1 )
{
case 127:
result = "DEL";
break;
case 186:
result = "CAPS";
break;
case 198:
result = "SCRLCK";
break;
case 273:
result = "UP";
break;
case 274:
result = "DOWN";
break;
case 275:
result = "RIGHT";
break;
case 276:
result = "LEFT";
break;
case 277:
result = "INS";
break;
case 278:
result = "HOME";
break;
case 279:
result = "END";
break;
case 280:
result = "PGUP";
break;
case 281:
result = "PGDN";
break;
case 282:
result = "F1";
break;
case 283:
result = "F2";
break;
case 284:
result = "F3";
break;
case 285:
result = "F4";
break;
case 286:
result = "F5";
break;
case 287:
result = "F6";
break;
case 288:
result = "F7";
break;
case 289:
result = "F8";
break;
case 290:
result = "F9";
break;
case 291:
result = "F10";
break;
case 292:
result = "F11";
break;
case 293:
result = "F12";
break;
case 303:
result = "SHIFT";
break;
case 305:
result = "CTRL";
break;
case 307:
result = "ALT";
break;
default:
goto LABEL_4;
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
const char *result; // rax

if ( a1 <= 61 )
{
if ( a1 > 7 )
{
switch ( a1 )
{
case 8:
result = "BKSP";
break;
case 9:
result = "TAB";
break;
case 13:
result = "ENTER";
break;
case 20:
result = "PAUSE";
break;
case 27:
result = "ESC";
break;
case 32:
result = "SPACE";
break;
case 45:
result = "MINUS";
break;
case 61:
result = "EQUALS";
break;
default:
goto LABEL_4;
}
}
else
{
LABEL_4:
result = 0LL;
}
}
else
{
switch ( a1 )
{
case 127:
result = "DEL";
break;
case 186:
result = "CAPS";
break;
case 198:
result = "SCRLCK";
break;
case 273:
result = "UP";
break;
case 274:
result = "DOWN";
break;
case 275:
result = "RIGHT";
break;
case 276:
result = "LEFT";
break;
case 277:
result = "INS";
break;
case 278:
result = "HOME";
break;
case 279:
result = "END";
break;
case 280:
result = "PGUP";
break;
case 281:
result = "PGDN";
break;
case 282:
result = "F1";
break;
case 283:
result = "F2";
break;
case 284:
result = "F3";
break;
case 285:
result = "F4";
break;
case 286:
result = "F5";
break;
case 287:
result = "F6";
break;
case 288:
result = "F7";
break;
case 289:
result = "F8";
break;
case 290:
result = "F9";
break;
case 291:
result = "F10";
break;
case 292:
result = "F11";
break;
case 293:
result = "F12";
break;
case 303:
result = "SHIFT";
break;
case 305:
result = "CTRL";
break;
case 307:
result = "ALT";
break;
default:
goto LABEL_4;
}
}
return result;
}

original_code:
static const char *SpecialKeyName(int key)
{
    switch (key)
    {
        case ' ': return "SPACE";
        case 0x113: return "RIGHT";
        case 0x114: return "LEFT";
        case 0x111: return "UP";
        case 0x112: return "DOWN";
        case 0x1B: return "ESC";
        case 0x0D: return "ENTER";
        case 0x09: return "TAB";
        case 0x11A: return "F1";
        case 0x11B: return "F2";
        case 0x11C: return "F3";
        case 0x11D: return "F4";
        case 0x11E: return "F5";
        case 0x11F: return "F6";
        case 0x120: return "F7";
        case 0x121: return "F8";
        case 0x122: return "F9";
        case 0x123: return "F10";
        case 0x124: return "F11";
        case 0x125: return "F12";
        case 0x08: return "BKSP";
        case 0x14: return "PAUSE";
        case 0x3D: return "EQUALS";
        case 0x2D: return "MINUS";
        case 0x12F: return "SHIFT";
        case 0x131: return "CTRL";
        case 0x133: return "ALT";
        case (0x80+0x3a): return "CAPS";
        case (0x80+0x46): return "SCRLCK";
        case 0x116: return "HOME";
        case 0x117: return "END";
        case 0x118: return "PGUP";
        case 0x119: return "PGDN";
        case 0x115: return "INS";
        case 0x7F: return "DEL";
        default: return ((void *)0);
    }
}

canonical_original_code:
static char *SpecialKeyName(int key)
{
    switch (key)
    {
        case ' ': return "SPACE";
        case 0x113: return "RIGHT";
        case 0x114: return "LEFT";
        case 0x111: return "UP";
        case 0x112: return "DOWN";
        case 0x1B: return "ESC";
        case 0x0D: return "ENTER";
        case 0x09: return "TAB";
        case 0x11A: return "F1";
        case 0x11B: return "F2";
        case 0x11C: return "F3";
        case 0x11D: return "F4";
        case 0x11E: return "F5";
        case 0x11F: return "F6";
        case 0x120: return "F7";
        case 0x121: return "F8";
        case 0x122: return "F9";
        case 0x123: return "F10";
        case 0x124: return "F11";
        case 0x125: return "F12";
        case 0x08: return "BKSP";
        case 0x14: return "PAUSE";
        case 0x3D: return "EQUALS";
        case 0x2D: return "MINUS";
        case 0x12F: return "SHIFT";
        case 0x131: return "CTRL";
        case 0x133: return "ALT";
        case (0x80+0x3a): return "CAPS";
        case (0x80+0x46): return "SCRLCK";
        case 0x116: return "HOME";
        case 0x117: return "END";
        case 0x118: return "PGUP";
        case 0x119: return "PGDN";
        case 0x115: return "INS";
        case 0x7F: return "DEL";
        default: return ((void *)0);
    }
}

variable_types: key int

return_type: char *


FontForName

decompiled_code:
void **__fastcall FontForName(const char *a1)
{
void **v1; // r8

v1 = &small_font;
if ( strcmp(a1, "small") )
{
v1 = &main_font;
if ( strcmp(a1, "normal") )
{
v1 = &large_font;
if ( strcmp(a1, "large") )
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
void **__fastcall func2(const char *a1)
{
void **v1; // r8

v1 = &small_font;
if ( strcmp(a1, "small") )
{
v1 = &main_font;
if ( strcmp(a1, "normal") )
{
v1 = &large_font;
if ( strcmp(a1, "large") )
v1 = 0LL;
}
}
return v1;
}

original_code:
static txt_font_t *FontForName(char *name)
{
    if (!strcmp(name, "small"))
    {
        return &small_font;
    }
    else if (!strcmp(name, "normal"))
    {
        return &main_font;
    }
    else if (!strcmp(name, "large"))
    {
        return &large_font;
    }
    else
    {
        return ((void *)0);
    }
}

canonical_original_code:
static struct txt_font_t *FontForName(char *name)
{
    if (!strcmp(name, "small"))
    {
        return &small_font;
    }
    else if (!strcmp(name, "normal"))
    {
        return &main_font;
    }
    else if (!strcmp(name, "large"))
    {
        return &large_font;
    }
    else
    {
        return ((void *)0);
    }
}

variable_types:
name
char *

return_type: struct txt_font_t { unsigned char *data; unsigned int w; unsigned int h; } *


ChooseFont

decompiled_code:
void **ChooseFont()
{
char *v0; // rax
void **result; // rax
_WORD *v2; // rdx
char v3; // si
void **v4; // rdi
unsigned __int16 v5; // dx
unsigned __int16 v6; // cx

v0 = getenv("TEXTSCREEN_FONT");
if ( !v0 || (result = FontForName(v0), (font = (__int64)result) == 0) )
{
result = (void **)SDL_ListModes(0LL, 0x80000000LL);
if ( (unsigned __int64)result - 1 > 0xFFFFFFFFFFFFFFFDLL || (v2 = *result) == 0LL )
{
font = (__int64)&main_font;
return result;
}
++result;
v3 = 0;
v4 = &small_font;
font = (__int64)&small_font;
while ( 1 )
{
v6 = v2[2];
if ( v6 > 0x77Fu )
break;
if ( v6 > 0x27Fu )
{
v5 = v2[3];
LABEL_8:
if ( v5 >= 0x1E0u )
v3 = 1;
if ( v5 >= 0x1E0u )
v4 = &main_font;
}
v2 = *result++;
if ( !v2 )
{
if ( v3 )
font = (__int64)v4;
return result;
}
}
v5 = v2[3];
if ( v5 > 0x437u )
{
font = (__int64)&large_font;
return result;
}
goto LABEL_8;
}
return result;
}

canonical_decompiled_code:
void **func3()
{
char *v0; // rax
void **result; // rax
_WORD *v2; // rdx
char v3; // si
void **v4; // rdi
unsigned __int16 v5; // dx
unsigned __int16 v6; // cx

v0 = getenv("TEXTSCREEN_FONT");
if ( !v0 || (result = func2(v0), (font = (__int64)result) == 0) )
{
result = (void **)SDL_ListModes(0LL, 0x80000000LL);
if ( (unsigned __int64)result - 1 > 0xFFFFFFFFFFFFFFFDLL || (v2 = *result) == 0LL )
{
font = (__int64)&main_font;
return result;
}
++result;
v3 = 0;
v4 = &small_font;
font = (__int64)&small_font;
while ( 1 )
{
v6 = v2[2];
if ( v6 > 0x77Fu )
break;
if ( v6 > 0x27Fu )
{
v5 = v2[3];
LABEL_8:
if ( v5 >= 0x1E0u )
v3 = 1;
if ( v5 >= 0x1E0u )
v4 = &main_font;
}
v2 = *result++;
if ( !v2 )
{
if ( v3 )
font = (__int64)v4;
return result;
}
}
v5 = v2[3];
if ( v5 > 0x437u )
{
font = (__int64)&large_font;
return result;
}
goto LABEL_8;
}
return result;
}

original_code:
static void ChooseFont(void)
{
    SDL_Rect **modes;
    char *env;
    int i;
    env = getenv("TEXTSCREEN_FONT");
    if (env != ((void *)0))
    {
        font = FontForName(env);
        if (font != ((void *)0))
        {
            return;
        }
    }
    modes = SDL_ListModes(((void *)0), 0x80000000);
    if (modes == ((void *)0) || modes == (SDL_Rect **) -1 || *modes == ((void *)0))
    {
        font = &main_font;
        return;
    }
    font = &small_font;
    for (i=0; modes[i] != ((void *)0); ++i)
    {
        if (modes[i]->w >= 1920 && modes[i]->h >= 1080)
        {
            font = &large_font;
            break;
        }
        else if (modes[i]->w >= 640 && modes[i]->h >= 480)
        {
            font = &main_font;
        }
    }
}

canonical_original_code:
static void ChooseFont()
{
    struct SDL_Rect **modes;
    char *env;
    int i;
    env = getenv("TEXTSCREEN_FONT");
    if (env != ((void *)0))
    {
        font = FontForName(env);
        if (font != ((void *)0))
        {
            return;
        }
    }
    modes = SDL_ListModes(((void *)0), 0x80000000);
    if (modes == ((void *)0) || modes == (struct SDL_Rect **) -1 || *modes == ((void *)0))
    {
        font = &main_font;
        return;
    }
    font = &small_font;
    for (i=0; modes[i] != ((void *)0); ++i)
    {
        if (modes[i]->w >= 1920 && modes[i]->h >= 1080)
        {
            font = &large_font;
            break;
        }
        else if (modes[i]->w >= 640 && modes[i]->h >= 480)
        {
            font = &main_font;
        }
    }
}

variable_types: struct SDL_Rect { short x; unsigned short w; } **

variable_types:
env
char *


UpdateCharacter

decompiled_code:
__int64 __fastcall UpdateCharacter(int a1, int a2)
{
unsigned __int8 *v3; // rax
int v4; // er12
unsigned __int8 v5; // bp
char v6; // al
char v7; // bp
char v8; // bl
__int64 v9; // r9
unsigned int v10; // er11
int v11; // ecx
__int64 result; // rax
__int64 v13; // rdi
__int64 v14; // r12
unsigned __int8 *v15; // rdi
unsigned __int64 v16; // r8
__int64 v17; // rdx
int v18; // eax
char v19; // cl

v3 = (unsigned __int8 *)screendata + 160 * a2 + 2 * a1;
v4 = *v3;
v5 = v3[1];
v6 = v5 >> 4;
v7 = v5 & 0xF;
v8 = v6;
if ( (v6 & 8) != 0 )
{
v8 = v6 & 0xF7;
if ( (((unsigned int)SDL_GetTicks() / 0xFA) & 1) == 0 )
v7 = v8;
}
v9 = font;
v10 = 0;
v11 = *(_DWORD *)(font + 8);
result = *(unsigned int *)(font + 12);
v13 = v4 * (unsigned int)result * ((unsigned int)(v11 + 7) >> 3);
v14 = screen;
v15 = (unsigned __int8 *)(*(_QWORD *)font + v13);
v16 = *(_QWORD *)(screen + 32)
+ (unsigned int)result * *(unsigned __int16 *)(screen + 24) * a2
+ (unsigned __int64)(unsigned int)(v11 * a1);
if ( (_DWORD)result )
{
while ( 1 )
{
v17 = 0LL;
v18 = 0;
if ( v11 )
{
do
{
v19 = v7;
if ( (((int)*v15 >> (7 - v18)) & 1) == 0 )
v19 = v8;
++v18;
*(_BYTE *)(v16 + v17) = v19;
if ( v18 == 8 )
{
++v15;
v18 = 0;
}
++v17;
}
while ( *(_DWORD *)(v9 + 8) > (unsigned int)v17 );
v15 += -(v18 == 0) + 1;
}
result = *(unsigned __int16 *)(v14 + 24);
++v10;
v16 += result;
if ( *(_DWORD *)(v9 + 12) <= v10 )
break;
v11 = *(_DWORD *)(v9 + 8);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
unsigned __int8 *v3; // rax
int v4; // er12
unsigned __int8 v5; // bp
char v6; // al
char v7; // bp
char v8; // bl
__int64 v9; // r9
unsigned int v10; // er11
int v11; // ecx
__int64 result; // rax
__int64 v13; // rdi
__int64 v14; // r12
unsigned __int8 *v15; // rdi
unsigned __int64 v16; // r8
__int64 v17; // rdx
int v18; // eax
char v19; // cl

v3 = (unsigned __int8 *)screendata + 160 * a2 + 2 * a1;
v4 = *v3;
v5 = v3[1];
v6 = v5 >> 4;
v7 = v5 & 0xF;
v8 = v6;
if ( (v6 & 8) != 0 )
{
v8 = v6 & 0xF7;
if ( (((unsigned int)SDL_GetTicks() / 0xFA) & 1) == 0 )
v7 = v8;
}
v9 = font;
v10 = 0;
v11 = *(_DWORD *)(font + 8);
result = *(unsigned int *)(font + 12);
v13 = v4 * (unsigned int)result * ((unsigned int)(v11 + 7) >> 3);
v14 = screen;
v15 = (unsigned __int8 *)(*(_QWORD *)font + v13);
v16 = *(_QWORD *)(screen + 32)
+ (unsigned int)result * *(unsigned __int16 *)(screen + 24) * a2
+ (unsigned __int64)(unsigned int)(v11 * a1);
if ( (_DWORD)result )
{
while ( 1 )
{
v17 = 0LL;
v18 = 0;
if ( v11 )
{
do
{
v19 = v7;
if ( (((int)*v15 >> (7 - v18)) & 1) == 0 )
v19 = v8;
++v18;
*(_BYTE *)(v16 + v17) = v19;
if ( v18 == 8 )
{
++v15;
v18 = 0;
}
++v17;
}
while ( *(_DWORD *)(v9 + 8) > (unsigned int)v17 );
v15 += -(v18 == 0) + 1;
}
result = *(unsigned __int16 *)(v14 + 24);
++v10;
v16 += result;
if ( *(_DWORD *)(v9 + 12) <= v10 )
break;
v11 = *(_DWORD *)(v9 + 8);
}
}
return result;
}

original_code:
static inline void UpdateCharacter(int x, int y)
{
    unsigned char character;
    unsigned char *p;
    unsigned char *s, *s1;
    unsigned int bit, bytes;
    int bg, fg;
    unsigned int x1, y1;
    p = &screendata[(y * 80 + x) * 2];
    character = p[0];
    fg = p[1] & 0xf;
    bg = (p[1] >> 4) & 0xf;
    if (bg & 0x8)
    {
        bg &= ~0x8;
        if (((SDL_GetTicks() / 250) % 2) == 0)
        {
            fg = bg;
        }
    }
    bytes = (font->w + 7) / 8;
    p = &font->data[character * font->h * bytes];
    s = ((unsigned char *) screen->pixels)
      + (y * font->h * screen->pitch)
      + (x * font->w);
    for (y1=0; y1<font->h; ++y1)
    {
        s1 = s;
        bit = 0;
        for (x1=0; x1<font->w; ++x1)
        {
            if (*p & (1 << (7-bit)))
            {
                *s1++ = fg;
            }
            else
            {
                *s1++ = bg;
            }
            ++bit;
            if (bit == 8)
            {
                ++p;
                bit = 0;
            }
        }
        if (bit != 0)
        {
            ++p;
        }
        s += screen->pitch;
    }
}

canonical_original_code:
static inline void UpdateCharacter(int x, int y)
{
    unsigned char character;
    unsigned char *p;
    unsigned char *s; unsigned char *s1;
    unsigned int bit; unsigned int bytes;
    int bg; int fg;
    unsigned int x1; unsigned int y1;
    p = &screendata[(y * 80 + x) * 2];
    character = p[0];
    fg = p[1] & 0xf;
    bg = (p[1] >> 4) & 0xf;
    if (bg & 0x8)
    {
        bg &= ~0x8;
        if (((SDL_GetTicks() / 250) % 2) == 0)
        {
            fg = bg;
        }
    }
    bytes = (font->w + 7) / 8;
    p = &font->data[character * font->h * bytes];
    s = ((unsigned char *) screen->pixels)
      + (y * font->h * screen->pitch)
      + (x * font->w);
    for (y1=0; y1<font->h; ++y1)
    {
        s1 = s;
        bit = 0;
        for (x1=0; x1<font->w; ++x1)
        {
            if (*p & (1 << (7-bit)))
            {
                *s1++ = fg;
            }
            else
            {
                *s1++ = bg;
            }
            ++bit;
            if (bit == 8)
            {
                ++p;
                bit = 0;
            }
        }
        if (bit != 0)
        {
            ++p;
        }
        s += screen->pitch;
    }
}

variable_types: x int

variable_types:
character
unsigned char

variable_types:
s
unsigned char *

variable_types:
bit
unsigned int

variable_types:
bytes
unsigned int

variable_types: bg int

variable_types: fg int


TranslateKey

decompiled_code:
int __fastcall TranslateKey(__int64 a1)
{
unsigned int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 4);
if ( v2 <= 0x1B )
{
if ( v2 > 7 )
{
switch ( v2 )
{
case 8u:
result = 8;
break;
case 9u:
result = 9;
break;
case 0xDu:
result = 13;
break;
case 0x13u:
result = 20;
break;
case 0x1Bu:
result = 27;
break;
default:
LABEL_10:
if ( key_mapping )
goto LABEL_5;
result = v2;
if ( v2 - 256 > 0x10 )
goto LABEL_44;
break;
}
}
else if ( key_mapping )
{
LABEL_5:
result = *(unsigned __int16 *)(a1 + 12);
if ( (unsigned __int16)result > 0x7Fu )
result += 384;
}
else
{
LABEL_44:
result = tolower(v2);
}
}
else
{
switch ( v2 )
{
case 0x7Fu:
result = 127;
break;
case 0x111u:
result = 273;
break;
case 0x112u:
result = 274;
break;
case 0x113u:
result = 275;
break;
case 0x114u:
result = 276;
break;
case 0x115u:
result = 277;
break;
case 0x116u:
result = 278;
break;
case 0x117u:
result = 279;
break;
case 0x118u:
result = 280;
break;
case 0x119u:
result = 281;
break;
case 0x11Au:
result = 282;
break;
case 0x11Bu:
result = 283;
break;
case 0x11Cu:
result = 284;
break;
case 0x11Du:
result = 285;
break;
case 0x11Eu:
result = 286;
break;
case 0x11Fu:
result = 287;
break;
case 0x120u:
result = 288;
break;
case 0x121u:
result = 289;
break;
case 0x122u:
result = 290;
break;
case 0x123u:
result = 291;
break;
case 0x124u:
result = 292;
break;
case 0x125u:
result = 293;
break;
case 0x12Du:
result = 186;
break;
case 0x12Eu:
result = 198;
break;
case 0x12Fu:
case 0x130u:
result = 303;
break;
case 0x131u:
case 0x132u:
result = 305;
break;
case 0x133u:
case 0x134u:
case 0x135u:
case 0x136u:
result = 307;
break;
default:
goto LABEL_10;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
unsigned int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 4);
if ( v2 <= 0x1B )
{
if ( v2 > 7 )
{
switch ( v2 )
{
case 8u:
result = 8;
break;
case 9u:
result = 9;
break;
case 0xDu:
result = 13;
break;
case 0x13u:
result = 20;
break;
case 0x1Bu:
result = 27;
break;
default:
LABEL_10:
if ( key_mapping )
goto LABEL_5;
result = v2;
if ( v2 - 256 > 0x10 )
goto LABEL_44;
break;
}
}
else if ( key_mapping )
{
LABEL_5:
result = *(unsigned __int16 *)(a1 + 12);
if ( (unsigned __int16)result > 0x7Fu )
result += 384;
}
else
{
LABEL_44:
result = tolower(v2);
}
}
else
{
switch ( v2 )
{
case 0x7Fu:
result = 127;
break;
case 0x111u:
result = 273;
break;
case 0x112u:
result = 274;
break;
case 0x113u:
result = 275;
break;
case 0x114u:
result = 276;
break;
case 0x115u:
result = 277;
break;
case 0x116u:
result = 278;
break;
case 0x117u:
result = 279;
break;
case 0x118u:
result = 280;
break;
case 0x119u:
result = 281;
break;
case 0x11Au:
result = 282;
break;
case 0x11Bu:
result = 283;
break;
case 0x11Cu:
result = 284;
break;
case 0x11Du:
result = 285;
break;
case 0x11Eu:
result = 286;
break;
case 0x11Fu:
result = 287;
break;
case 0x120u:
result = 288;
break;
case 0x121u:
result = 289;
break;
case 0x122u:
result = 290;
break;
case 0x123u:
result = 291;
break;
case 0x124u:
result = 292;
break;
case 0x125u:
result = 293;
break;
case 0x12Du:
result = 186;
break;
case 0x12Eu:
result = 198;
break;
case 0x12Fu:
case 0x130u:
result = 303;
break;
case 0x131u:
case 0x132u:
result = 305;
break;
case 0x133u:
case 0x134u:
case 0x135u:
case 0x136u:
result = 307;
break;
default:
goto LABEL_10;
}
}
return result;
}

original_code:
static int TranslateKey(SDL_keysym *sym)
{
    switch(sym->sym)
    {
        case SDLK_LEFT: return 0x114;
        case SDLK_RIGHT: return 0x113;
        case SDLK_DOWN: return 0x112;
        case SDLK_UP: return 0x111;
        case SDLK_ESCAPE: return 0x1B;
        case SDLK_RETURN: return 0x0D;
        case SDLK_TAB: return 0x09;
        case SDLK_F1: return 0x11A;
        case SDLK_F2: return 0x11B;
        case SDLK_F3: return 0x11C;
        case SDLK_F4: return 0x11D;
        case SDLK_F5: return 0x11E;
        case SDLK_F6: return 0x11F;
        case SDLK_F7: return 0x120;
        case SDLK_F8: return 0x121;
        case SDLK_F9: return 0x122;
        case SDLK_F10: return 0x123;
        case SDLK_F11: return 0x124;
        case SDLK_F12: return 0x125;
        case SDLK_BACKSPACE: return 0x08;
        case SDLK_DELETE: return 0x7F;
        case SDLK_PAUSE: return 0x14;
        case SDLK_LSHIFT:
        case SDLK_RSHIFT:
                               return 0x12F;
        case SDLK_LCTRL:
        case SDLK_RCTRL:
                               return 0x131;
        case SDLK_LALT:
        case SDLK_RALT:
        case SDLK_LMETA:
        case SDLK_RMETA:
                               return 0x133;
        case SDLK_CAPSLOCK: return (0x80+0x3a);
        case SDLK_SCROLLOCK: return (0x80+0x46);
        case SDLK_HOME: return 0x116;
        case SDLK_INSERT: return 0x115;
        case SDLK_END: return 0x117;
        case SDLK_PAGEUP: return 0x118;
        case SDLK_PAGEDOWN: return 0x119;
        default: break;
    }
    if (key_mapping)
    {
        if (sym->unicode < 128)
        {
            return sym->unicode;
        }
        else
        {
            return sym->unicode - 128 + 512;
        }
    }
    else
    {
        switch (sym->sym)
        {
            case SDLK_KP0: return 0x100;
            case SDLK_KP1: return 0x101;
            case SDLK_KP2: return 0x102;
            case SDLK_KP3: return 0x103;
            case SDLK_KP4: return 0x104;
            case SDLK_KP5: return 0x105;
            case SDLK_KP6: return 0x106;
            case SDLK_KP7: return 0x107;
            case SDLK_KP8: return 0x108;
            case SDLK_KP9: return 0x109;
            case SDLK_KP_PERIOD: return 0x10A;
            case SDLK_KP_MULTIPLY: return 0x10C;
            case SDLK_KP_PLUS: return 0x10E;
            case SDLK_KP_MINUS: return 0x10D;
            case SDLK_KP_DIVIDE: return 0x10B;
            case SDLK_KP_EQUALS: return 0x110;
            case SDLK_KP_ENTER: return 0x10F;
            default:
                return tolower(sym->sym);
        }
    }
}

canonical_original_code:
static int TranslateKey(struct SDL_keysym *sym)
{
    switch(sym->sym)
    {
        case SDLK_LEFT: return 0x114;
        case SDLK_RIGHT: return 0x113;
        case SDLK_DOWN: return 0x112;
        case SDLK_UP: return 0x111;
        case SDLK_ESCAPE: return 0x1B;
        case SDLK_RETURN: return 0x0D;
        case SDLK_TAB: return 0x09;
        case SDLK_F1: return 0x11A;
        case SDLK_F2: return 0x11B;
        case SDLK_F3: return 0x11C;
        case SDLK_F4: return 0x11D;
        case SDLK_F5: return 0x11E;
        case SDLK_F6: return 0x11F;
        case SDLK_F7: return 0x120;
        case SDLK_F8: return 0x121;
        case SDLK_F9: return 0x122;
        case SDLK_F10: return 0x123;
        case SDLK_F11: return 0x124;
        case SDLK_F12: return 0x125;
        case SDLK_BACKSPACE: return 0x08;
        case SDLK_DELETE: return 0x7F;
        case SDLK_PAUSE: return 0x14;
        case SDLK_LSHIFT:
        case SDLK_RSHIFT:
                               return 0x12F;
        case SDLK_LCTRL:
        case SDLK_RCTRL:
                               return 0x131;
        case SDLK_LALT:
        case SDLK_RALT:
        case SDLK_LMETA:
        case SDLK_RMETA:
                               return 0x133;
        case SDLK_CAPSLOCK: return (0x80+0x3a);
        case SDLK_SCROLLOCK: return (0x80+0x46);
        case SDLK_HOME: return 0x116;
        case SDLK_INSERT: return 0x115;
        case SDLK_END: return 0x117;
        case SDLK_PAGEUP: return 0x118;
        case SDLK_PAGEDOWN: return 0x119;
        default: break;
    }
    if (key_mapping)
    {
        if (sym->unicode < 128)
        {
            return sym->unicode;
        }
        else
        {
            return sym->unicode - 128 + 512;
        }
    }
    else
    {
        switch (sym->sym)
        {
            case SDLK_KP0: return 0x100;
            case SDLK_KP1: return 0x101;
            case SDLK_KP2: return 0x102;
            case SDLK_KP3: return 0x103;
            case SDLK_KP4: return 0x104;
            case SDLK_KP5: return 0x105;
            case SDLK_KP6: return 0x106;
            case SDLK_KP7: return 0x107;
            case SDLK_KP8: return 0x108;
            case SDLK_KP9: return 0x109;
            case SDLK_KP_PERIOD: return 0x10A;
            case SDLK_KP_MULTIPLY: return 0x10C;
            case SDLK_KP_PLUS: return 0x10E;
            case SDLK_KP_MINUS: return 0x10D;
            case SDLK_KP_DIVIDE: return 0x10B;
            case SDLK_KP_EQUALS: return 0x110;
            case SDLK_KP_ENTER: return 0x10F;
            default:
                return tolower(sym->sym);
        }
    }
}

variable_types: struct SDL_keysym { unsigned char scancode; enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 } sym; enum SDLMod { KMOD_NONE=0, KMOD_LSHIFT=1, KMOD_RSHIFT=2, KMOD_LCTRL=64, KMOD_RCTRL=128, KMOD_LALT=256, KMOD_RALT=512, KMOD_LMETA=1024, KMOD_RMETA=2048, KMOD_NUM=4096, KMOD_CAPS=8192, KMOD_MODE=16384, KMOD_RESERVED=32768 } mod; unsigned short unicode; } *

user_defined_types: struct SDL_keysym { unsigned char scancode; enum SDLKey sym; enum SDLMod mod; unsigned short unicode; }


decompiled_code:
__int64 TXT_Init()
{
if ( (int)SDL_InitSubSystem(32LL) < 0 )
return 0LL;
ChooseFont();
screen = SDL_SetVideoMode(
(unsigned int)(80 * *(_DWORD *)(font + 8)),
(unsigned int)(25 * *(_DWORD *)(font + 12)),
8LL,
0LL);
if ( !screen )
return 0LL;
SDL_SetColors(screen, &ega_colors, 0LL, 16LL);
SDL_EnableUNICODE(1LL);
screendata = calloc(0xFA0uLL, 1uLL);
SDL_EnableKeyRepeat(500LL, 30LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
if ( (int)SDL_InitSubSystem(32LL) < 0 )
return 0LL;
func3();
screen = SDL_SetVideoMode(
(unsigned int)(80 * *(_DWORD *)(font + 8)),
(unsigned int)(25 * *(_DWORD *)(font + 12)),
8LL,
0LL);
if ( !screen )
return 0LL;
SDL_SetColors(screen, &ega_colors, 0LL, 16LL);
SDL_EnableUNICODE(1LL);
screendata = calloc(0xFA0uLL, 1uLL);
SDL_EnableKeyRepeat(500LL, 30LL);
return 1LL;
}

original_code:
int TXT_Init(void)
{
    if (SDL_InitSubSystem(0x00000020) < 0)
    {
        return 0;
    }
    ChooseFont();
    screen = SDL_SetVideoMode(80 * font->w,
                              25 * font->h, 8, 0);
    if (screen == ((void *)0))
        return 0;
    SDL_SetColors(screen, ega_colors, 0, 16);
    SDL_EnableUNICODE(1);
    screendata = malloc(80 * 25 * 2);
    memset(screendata, 0, 80 * 25 * 2);
    SDL_EnableKeyRepeat(500, 30);
    return 1;
}

canonical_original_code:
int TXT_Init()
{
    if (SDL_InitSubSystem(0x00000020) < 0)
    {
        return 0;
    }
    ChooseFont();
    screen = SDL_SetVideoMode(80 * font->w,
                              25 * font->h, 8, 0);
    if (screen == ((void *)0))
        return 0;
    SDL_SetColors(screen, ega_colors, 0, 16);
    SDL_EnableUNICODE(1);
    screendata = malloc(80 * 25 * 2);
    memset(screendata, 0, 80 * 25 * 2);
    SDL_EnableKeyRepeat(500, 30);
    return 1;
}


decompiled_code:
__int64 TXT_Shutdown()
{
free(screendata);
return SDL_QuitSubSystem(32LL);
}

canonical_decompiled_code:
__int64 func9()
{
free(screendata);
return SDL_QuitSubSystem(32LL);
}

original_code:
void TXT_Shutdown(void)
{
    free(screendata);
    SDL_QuitSubSystem(0x00000020);
}

canonical_original_code:
void TXT_Shutdown()
{
    free(screendata);
    SDL_QuitSubSystem(0x00000020);
}


decompiled_code:
void *TXT_GetScreenData()
{
return screendata;
}

canonical_decompiled_code:
void *func10()
{
return screendata;
}

original_code:
unsigned char *TXT_GetScreenData(void)
{
    return screendata;
}

canonical_original_code:
unsigned char *TXT_GetScreenData()
{
    return screendata;
}

return_type: unsigned char *


decompiled_code:
__int64 __fastcall TXT_UpdateScreenArea(int a1, __int64 a2, int a3)
{
int v3; // ecx
int v4; // er9
int v5; // er12
int v6; // er15
int v7; // er10
int v8; // er13
int v9; // er9
int v10; // er14
int v11; // ebp
int v12; // ebx
int v13; // edi

v5 = LimitToRange_constprop_0(a3 + a1, 80);
v6 = LimitToRange_constprop_0(v4 + v3, 25);
v8 = LimitToRange_constprop_0(v7, 80);
v10 = LimitToRange_constprop_0(v9, 25);
v11 = v10;
if ( v6 > v10 )
{
do
{
v12 = v8;
if ( v5 > v8 )
{
do
{
v13 = v12++;
UpdateCharacter(v13, v11);
}
while ( v5 != v12 );
}
++v11;
}
while ( v6 != v11 );
}
return SDL_UpdateRect(
screen,
(unsigned int)(v8 * *(_DWORD *)(font + 8)),
(unsigned int)(*(_DWORD *)(font + 12) * v10),
(unsigned int)(*(_DWORD *)(font + 8) * (v5 - v8)),
(unsigned int)((v6 - v10) * *(_DWORD *)(font + 12)));
}

original_code:
void TXT_UpdateScreenArea(int x, int y, int w, int h)
{
    int x1, y1;
    int x_end;
    int y_end;
    x_end = LimitToRange(x + w, 0, 80);
    y_end = LimitToRange(y + h, 0, 25);
    x = LimitToRange(x, 0, 80);
    y = LimitToRange(y, 0, 25);
    for (y1=y; y1<y_end; ++y1)
    {
        for (x1=x; x1<x_end; ++x1)
        {
            UpdateCharacter(x1, y1);
        }
    }
    SDL_UpdateRect(screen,
                   x * font->w, y * font->h,
                   (x_end - x) * font->w, (y_end - y) * font->h);
}

canonical_original_code:
void TXT_UpdateScreenArea(int x, int y, int w, int h)
{
    int x1; int y1;
    int x_end;
    int y_end;
    x_end = LimitToRange(x + w, 0, 80);
    y_end = LimitToRange(y + h, 0, 25);
    x = LimitToRange(x, 0, 80);
    y = LimitToRange(y, 0, 25);
    for (y1=y; y1<y_end; ++y1)
    {
        for (x1=x; x1<x_end; ++x1)
        {
            UpdateCharacter(x1, y1);
        }
    }
    SDL_UpdateRect(screen,
                   x * font->w, y * font->h,
                   (x_end - x) * font->w, (y_end - y) * font->h);
}

variable_types: y int

variable_types: w int

variable_types: h int


decompiled_code:
__int64 TXT_UpdateScreen()
{
return TXT_UpdateScreenArea(0, 0LL, 80);
}

original_code:
void TXT_UpdateScreen(void)
{
    TXT_UpdateScreenArea(0, 0, 80, 25);
}

canonical_original_code:
void TXT_UpdateScreen()
{
    TXT_UpdateScreenArea(0, 0, 80, 25);
}


MouseHasMoved

decompiled_code:
__int64 MouseHasMoved()
{
unsigned int v0; // er8
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

TXT_GetMousePosition(&v2, v3);
if ( v2 != last_x_1 || (v0 = 0, v3[0] != last_y_0) )
{
last_x_1 = v2;
v0 = 1;
last_y_0 = v3[0];
}
return v0;
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // er8
int v2; // [rsp+8h] [rbp-10h] BYREF
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

func13(&v2, v3);
if ( v2 != last_x_1 || (v0 = 0, v3[0] != last_y_0) )
{
last_x_1 = v2;
v0 = 1;
last_y_0 = v3[0];
}
return v0;
}

original_code:
static int MouseHasMoved(void)
{
    static int last_x = 0, last_y = 0;
    int x, y;
    TXT_GetMousePosition(&x, &y);
    if (x != last_x || y != last_y)
    {
        last_x = x; last_y = y;
        return 1;
    }
    else
    {
        return 0;
    }
}

canonical_original_code:
static int MouseHasMoved()
{
    static int last_x = 0; static int last_y = 0;
    int x; int y;
    TXT_GetMousePosition(&x, &y);
    if (x != last_x || y != last_y)
    {
        last_x = x; last_y = y;
        return 1;
    }
    else
    {
        return 0;
    }
}


decompiled_code:
_BOOL8 __fastcall TXT_GetModifierState(unsigned int a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 <= 2 )
result = modifier_state[a1] > 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(unsigned int a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 <= 2 )
result = modifier_state[a1] > 0;
return result;
}

original_code:
int TXT_GetModifierState(txt_modifier_t mod)
{
    if (mod < TXT_NUM_MODIFIERS)
    {
        return modifier_state[mod] > 0;
    }
    return 0;
}

canonical_original_code:
int TXT_GetModifierState(enum txt_modifier_t mod)
{
    if (mod < TXT_NUM_MODIFIERS)
    {
        return modifier_state[mod] > 0;
    }
    return 0;
}

variable_types: enum txt_modifier_t { TXT_MOD_SHIFT=0, TXT_MOD_CTRL=1, TXT_MOD_ALT=2, TXT_NUM_MODIFIERS=3 }


decompiled_code:
unsigned int __fastcall TXT_GetKeyDescription(int c, char *s)
{
const char *v2; // rax
__int64 v4; // rdx

v2 = SpecialKeyName(c);
if ( v2 )
return (unsigned int)strcpy(s, v2);
if ( ((*_ctype_b_loc())[c] & 0x4000) == 0 )
return sprintf(s, "??%i", (unsigned int)c);
v4 = (unsigned int)toupper(c);
return sprintf(s, "%c", v4);
}

canonical_decompiled_code:
unsigned int __fastcall func17(int c, char *s)
{
const char *v2; // rax
__int64 v4; // rdx

v2 = func1(c);
if ( v2 )
return (unsigned int)strcpy(s, v2);
if ( ((*_ctype_b_loc())[c] & 0x4000) == 0 )
return sprintf(s, "??%i", (unsigned int)c);
v4 = (unsigned int)toupper(c);
return sprintf(s, "%c", v4);
}

original_code:
void TXT_GetKeyDescription(int key, char *buf)
{
    const char *keyname;
    keyname = SpecialKeyName(key);
    if (keyname != ((void *)0))
    {
        strcpy(buf, keyname);
    }
    else if (((*__ctype_b_loc ())[(int) ((key))] & (unsigned short int) _ISprint))
    {
        sprintf(buf, "%c", toupper(key));
    }
    else
    {
        sprintf(buf, "??%i", key);
    }
}

canonical_original_code:
void TXT_GetKeyDescription(int key, char *buf)
{
    char *keyname;
    keyname = SpecialKeyName(key);
    if (keyname != ((void *)0))
    {
        strcpy(buf, keyname);
    }
    else if (((*__ctype_b_loc ())[(int) ((key))] & (unsigned short) _ISprint))
    {
        sprintf(buf, "%c", toupper(key));
    }
    else
    {
        sprintf(buf, "??%i", key);
    }
}

variable_types:
buf
char *

variable_types:
keyname
char *


decompiled_code:
__int64 TXT_ScreenHasBlinkingChars()
{
char *v0; // rdx
char *v1; // rax

v0 = (char *)screendata + 160;
do
{
v1 = v0 - 160;
do
{
if ( v1[1] < 0 )
return 1LL;
v1 += 2;
}
while ( v1 != v0 );
v0 = v1 + 160;
}
while ( v1 + 160 != (char *)screendata + 4160 );
return 0LL;
}

canonical_decompiled_code:
__int64 func18()
{
char *v0; // rdx
char *v1; // rax

v0 = (char *)screendata + 160;
do
{
v1 = v0 - 160;
do
{
if ( v1[1] < 0 )
return 1LL;
v1 += 2;
}
while ( v1 != v0 );
v0 = v1 + 160;
}
while ( v1 + 160 != (char *)screendata + 4160 );
return 0LL;
}

original_code:
int TXT_ScreenHasBlinkingChars(void)
{
    int x, y;
    unsigned char *p;
    for (y=0; y<25; ++y)
    {
        for (x=0; x<80; ++x)
        {
            p = &screendata[(y * 80 + x) * 2];
            if (p[1] & 0x80)
            {
                return 1;
            }
        }
    }
    return 0;
}

canonical_original_code:
int TXT_ScreenHasBlinkingChars()
{
    int x; int y;
    unsigned char *p;
    for (y=0; y<25; ++y)
    {
        for (x=0; x<80; ++x)
        {
            p = &screendata[(y * 80 + x) * 2];
            if (p[1] & 0x80)
            {
                return 1;
            }
        }
    }
    return 0;
}

variable_types:
p
unsigned char *


decompiled_code:
__int64 __fastcall TXT_Sleep(signed int a1)
{
unsigned int v1; // ebx
__int64 result; // rax
unsigned int v3; // eax
unsigned int v4; // ebx

v1 = a1;
if ( (unsigned int)TXT_ScreenHasBlinkingChars() )
{
v3 = (unsigned int)SDL_GetTicks() % 0xFA;
if ( a1 > (int)(250 - v3) || !a1 )
v1 = 251 - v3;
}
else if ( !a1 )
{
return SDL_WaitEvent(0LL);
}
v4 = SDL_GetTicks() + v1;
while ( 1 )
{
result = SDL_GetTicks();
if ( (unsigned int)result >= v4 )
break;
result = SDL_PollEvent(0LL);
if ( (_DWORD)result )
break;
SDL_Delay(1LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(signed int a1)
{
unsigned int v1; // ebx
__int64 result; // rax
unsigned int v3; // eax
unsigned int v4; // ebx

v1 = a1;
if ( (unsigned int)func18() )
{
v3 = (unsigned int)SDL_GetTicks() % 0xFA;
if ( a1 > (int)(250 - v3) || !a1 )
v1 = 251 - v3;
}
else if ( !a1 )
{
return SDL_WaitEvent(0LL);
}
v4 = SDL_GetTicks() + v1;
while ( 1 )
{
result = SDL_GetTicks();
if ( (unsigned int)result >= v4 )
break;
result = SDL_PollEvent(0LL);
if ( (_DWORD)result )
break;
SDL_Delay(1LL);
}
return result;
}

original_code:
void TXT_Sleep(int timeout)
{
    unsigned int start_time;
    if (TXT_ScreenHasBlinkingChars())
    {
        int time_to_next_blink;
        time_to_next_blink = 250 - (SDL_GetTicks() % 250);
        if (timeout == 0 || timeout > time_to_next_blink)
        {
            timeout = time_to_next_blink + 1;
        }
    }
    if (timeout == 0)
    {
        SDL_WaitEvent(((void *)0));
    }
    else
    {
        start_time = SDL_GetTicks();
        while (SDL_GetTicks() < start_time + timeout)
        {
            if (SDL_PollEvent(((void *)0)) != 0)
            {
                break;
            }
            SDL_Delay(1);
        }
    }
}

variable_types: timeout int


decompiled_code:
void __fastcall TXT_EnableKeyMapping(int a1)
{
key_mapping = a1;
}

canonical_decompiled_code:
void __fastcall func20(int a1)
{
key_mapping = a1;
}

original_code:
void TXT_EnableKeyMapping(int enable)
{
    key_mapping = enable;
}

variable_types: enable int


decompiled_code:
__int64 __fastcall TXT_SetWindowTitle(__int64 a1)
{
return SDL_WM_SetCaption(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
return SDL_WM_SetCaption(a1, 0LL);
}

original_code:
void TXT_SetWindowTitle(char *title)
{
    SDL_WM_SetCaption(title, ((void *)0));
}

variable_types:
title
char *


variable_types:
ptr
char **

variable_types:
p
char *

variable_types:
c
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall TXT_UTF8_Strlen(char *a1)
{
unsigned int v1; // er11
bool v2; // zf
char *v4; // [rsp+8h] [rbp-8h] BYREF

v1 = 0;
v2 = *a1 == 0;
v4 = a1;
if ( !v2 )
{
do
{
if ( !(unsigned int)TXT_DecodeUTF8(&v4) )
break;
++v1;
}
while ( *v4 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
unsigned int v1; // er11
bool v2; // zf
char *v4; // [rsp+8h] [rbp-8h] BYREF

v1 = 0;
v2 = *a1 == 0;
v4 = a1;
if ( !v2 )
{
do
{
if ( !(unsigned int)func0(&v4) )
break;
++v1;
}
while ( *v4 );
}
return v1;
}

original_code:
unsigned int TXT_UTF8_Strlen(const char *s)
{
    const char *p;
    unsigned int result = 0;
    unsigned int c;
    for (p = s; *p != '\0';)
    {
        c = TXT_DecodeUTF8(&p);
        if (c == 0)
        {
            break;
        }
        ++result;
    }
    return result;
}

canonical_original_code:
unsigned int TXT_UTF8_Strlen(char *s)
{
    char *p;
    unsigned int result = 0;
    unsigned int c;
    for (p = s; *p != '\0';)
    {
        c = TXT_DecodeUTF8(&p);
        if (c == 0)
        {
            break;
        }
        ++result;
    }
    return result;
}

variable_types:
s
char *

variable_types:
result
unsigned int


decompiled_code:
char *__fastcall TXT_UTF8_SkipChars(char *a1, int a2)
{
int v2; // er11
char *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a1;
if ( !a2 )
return a1;
while ( (unsigned int)TXT_DecodeUTF8(&v4) && a2 != v2 + 1 )
;
return v4;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1, int a2)
{
int v2; // er11
char *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a1;
if ( !a2 )
return a1;
while ( (unsigned int)func0(&v4) && a2 != v2 + 1 )
;
return v4;
}

original_code:
char *TXT_UTF8_SkipChars(const char *s, unsigned int n)
{
    unsigned int i;
    const char *p;
    p = s;
    for (i = 0; i < n; ++i)
    {
        if (TXT_DecodeUTF8(&p) == 0)
        {
            break;
        }
    }
    return (char *) p;
}

canonical_original_code:
char *TXT_UTF8_SkipChars(char *s, unsigned int n)
{
    unsigned int i;
    char *p;
    p = s;
    for (i = 0; i < n; ++i)
    {
        if (TXT_DecodeUTF8(&p) == 0)
        {
            break;
        }
    }
    return (char *) p;
}

variable_types:
n
unsigned int

variable_types:
i
unsigned int


IntWidth

decompiled_code:
size_t __fastcall IntWidth(unsigned int a1)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

sprintf(v2, "%i", a1);
return strlen(v2);
}

canonical_decompiled_code:
size_t __fastcall func4(unsigned int a1)
{
char v2[40]; // [rsp+0h] [rbp-28h] BYREF

sprintf(v2, "%i", a1);
return strlen(v2);
}

original_code:
static unsigned int IntWidth(int val)
{
    char buf[25];
    sprintf(buf, "%i", val);
    return strlen(buf);
}

variable_types: val int

variable_types:
buf
char [25]


FloatWidth

decompiled_code:
__int64 __fastcall FloatWidth(float a1, float a2)
{
unsigned int v2; // er12
double v3; // xmm0_8
__m128d v4; // xmm3
__m128d v5; // xmm1

v2 = IntWidth((int)a1);
v3 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(a2)) ^ LC1) / 2.302585092994046;
if ( COERCE_DOUBLE(*(_QWORD *)&v3 & LC4) < 4.503599627370496e15 )
{
v4.m128d_f64[0] = v3;
v5.m128d_f64[0] = (double)(int)v3;
*(_QWORD *)&v3 = COERCE_UNSIGNED_INT64(v5.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v4, v5) & LC5)) | ~LC4 & *(_QWORD *)&v3;
}
if ( (int)v3 )
v2 += (int)v3 + 1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(float a1, float a2)
{
unsigned int v2; // er12
double v3; // xmm0_8
__m128d v4; // xmm3
__m128d v5; // xmm1

v2 = func4((int)a1);
v3 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(a2)) ^ LC1) / 2.302585092994046;
if ( COERCE_DOUBLE(*(_QWORD *)&v3 & LC4) < 4.503599627370496e15 )
{
v4.m128d_f64[0] = v3;
v5.m128d_f64[0] = (double)(int)v3;
*(_QWORD *)&v3 = COERCE_UNSIGNED_INT64(v5.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v4, v5) & LC5)) | ~LC4 & *(_QWORD *)&v3;
}
if ( (int)v3 )
v2 += (int)v3 + 1;
return v2;
}

original_code:
static unsigned int FloatWidth(float val, float step)
{
    unsigned int precision;
    unsigned int result;
    result = IntWidth((int) val);
    precision = (unsigned int) ceil(-log(step) / log(10));
    if (precision > 0)
    {
        result += precision + 1;
    }
    return result;
}

variable_types: val float

variable_types: step float

variable_types:
precision
unsigned int


FloatFormatString

decompiled_code:
void __fastcall FloatFormatString(char *s, float a2)
{
double v2; // xmm0_8
__m128d v3; // xmm3
__m128d v4; // xmm1
__int64 v5; // rdx

v2 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(a2)) ^ LC1) / 2.302585092994046;
if ( COERCE_DOUBLE(*(_QWORD *)&v2 & LC4) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = v2;
v4.m128d_f64[0] = (double)(int)v2;
*(_QWORD *)&v2 = COERCE_UNSIGNED_INT64(v4.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v3, v4) & LC5)) | ~LC4 & *(_QWORD *)&v2;
}
v5 = (unsigned int)(int)v2;
if ( (int)v5 <= 0 )
strcpy(s, "%.1f");
else
sprintf(s, "%%.%if", v5);
}

canonical_decompiled_code:
void __fastcall func9(char *s, float a2)
{
double v2; // xmm0_8
__m128d v3; // xmm3
__m128d v4; // xmm1
__int64 v5; // rdx

v2 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(a2)) ^ LC1) / 2.302585092994046;
if ( COERCE_DOUBLE(*(_QWORD *)&v2 & LC4) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = v2;
v4.m128d_f64[0] = (double)(int)v2;
*(_QWORD *)&v2 = COERCE_UNSIGNED_INT64(v4.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v3, v4) & LC5)) | ~LC4 & *(_QWORD *)&v2;
}
v5 = (unsigned int)(int)v2;
if ( (int)v5 <= 0 )
strcpy(s, "%.1f");
else
sprintf(s, "%%.%if", v5);
}

original_code:
static void FloatFormatString(float step, char *buf)
{
    int precision;
    precision = (int) ceil(-log(step) / log(10));
    if (precision > 0)
    {
        sprintf(buf, "%%.%if", precision);
    }
    else
    {
        strcpy(buf, "%.1f");
    }
}

variable_types:
buf
char *

variable_types: precision int


decompiled_code:
void TXT_StrutDrawer()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static void TXT_StrutDrawer(void * uncast_strut)
{
}

canonical_original_code:
static void TXT_StrutDrawer(void *uncast_strut)
{
}


decompiled_code:
void TXT_StrutDestructor()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void TXT_StrutDestructor(void * uncast_strut)
{
}

canonical_original_code:
static void TXT_StrutDestructor(void *uncast_strut)
{
}


decompiled_code:
__int64 TXT_StrutKeyPress()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0LL;
}

original_code:
static int TXT_StrutKeyPress(void * uncast_strut, int key)
{
    return 0;
}

canonical_original_code:
static int TXT_StrutKeyPress(void *uncast_strut, int key)
{
    return 0;
}

variable_types: key int


decompiled_code:
void TXT_DropdownListDestructor()
{
;
}

original_code:
static void TXT_DropdownListDestructor(void * uncast_list)
{
}

canonical_original_code:
static void TXT_DropdownListDestructor(void *uncast_list)
{
}


decompiled_code:
void __fastcall dict_create(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
_QWORD *v3; // rax
__int64 v4; // rdx

v1 = jmalloc(64LL);
table_reset(v1 + 8);
table_reset(v2 + 32);
*v3 = a1;
v3[7] = v4;
}

original_code:
dict *dict_create(dict_opts *opts) {
 dict *d = jmalloc(sizeof(struct dict));
 _table_reset(&d->dt[0]);
 _table_reset(&d->dt[1]);
 d->rehashidx = -1;
 d->opts = opts;
 d->iterators = 0;
 return d;
}

canonical_original_code:
struct dict *dict_create(struct dict_opts *opts) {
 struct dict *d = jmalloc(sizeof(struct dict));
 _table_reset(&d->dt[0]);
 _table_reset(&d->dt[1]);
 d->rehashidx = -1;
 d->opts = opts;
 d->iterators = 0;
 return d;
}

variable_types:
opts
struct dict_opts *

variable_types: struct dict { struct dict_opts { unsigned int (*hash)(void *key); void *(*key_dup)(void *key); void *(*value_dup)(void *key); int (*key_compare)(void *k1, void *k2); void (*key_destroy)(void *key); void (*value_destroy)(void *v); } *opts; struct dict_table { struct dict_entry { void *key; void *value; int ref; struct dict_entry *next; } **entries; unsigned int size; unsigned int mask; unsigned int used; } dt[2]; int rehashidx; int iterators; } *

user_defined_types: struct dict { struct dict_opts *opts; struct dict_table dt[2]; int rehashidx; int iterators; }

user_defined_types: struct dict_table { struct dict_entry **entries; unsigned int size; unsigned int mask; unsigned int used; }


decompiled_code:
__int64 __fastcall dict_destroy(__int64 a1)
{
*(_DWORD *)(a1 + 56) = -1;
table_clear((__int64 *)a1, a1 + 8);
table_clear((__int64 *)a1, a1 + 32);
return jfree(a1);
}

original_code:
void dict_destroy(dict *d) {
 d->rehashidx = -1;
 _table_clear(d, &d->dt[0]);
 _table_clear(d, &d->dt[1]);
 jfree(d);
}

canonical_original_code:
void dict_destroy(struct dict *d) {
 d->rehashidx = -1;
 _table_clear(d, &d->dt[0]);
 _table_clear(d, &d->dt[1]);
 jfree(d);
}

user_defined_types: struct dict_opts { unsigned int (*hash)(void *key); void *(*key_dup)(void *key); void *(*value_dup)(void *key); int (*key_compare)(void *k1, void *k2); void (*key_destroy)(void *key); void (*value_destroy)(void *v); }

user_defined_types: struct dict_entry { void *key; void *value; int ref; struct dict_entry *next; }


decompiled_code:
void __fastcall dict_clear(__int64 a1)
{
*(_DWORD *)(a1 + 56) = -1;
table_clear((__int64 *)a1, a1 + 8);
table_clear((__int64 *)a1, a1 + 32);
}

original_code:
void dict_clear(dict *d) {
 d->rehashidx = -1;
 _table_clear(d, &d->dt[0]);
 _table_clear(d, &d->dt[1]);
}

canonical_original_code:
void dict_clear(struct dict *d) {
 d->rehashidx = -1;
 _table_clear(d, &d->dt[0]);
 _table_clear(d, &d->dt[1]);
}


original_code:
int dict_rehash(dict *d, int n) {
 dict_entry *entry, *next;
 if(!(d->rehashidx != -1)) return 0;
 while(n--) {
  if(d->dt[0].used == 0) {
   jfree(d->dt[0].entries);
   d->dt[0] = d->dt[1];
   _table_reset(&d->dt[1]);
   d->rehashidx = -1;
   return 0;
  }
  while(d->dt[0].entries[d->rehashidx] == ((void *)0)) d->rehashidx++;
  entry = d->dt[0].entries[d->rehashidx];
  while(entry) {
   unsigned int idx;
   next = entry->next;
   idx = d->opts->hash(entry->key)&d->dt[1].mask;
   entry->next = d->dt[1].entries[idx];
   d->dt[1].entries[idx] = entry;
   d->dt[1].used++;
   d->dt[0].used--;
   entry = next;
  }
  d->dt[0].entries[d->rehashidx++] = ((void *)0);
 }
 return 1;
}

canonical_original_code:
int dict_rehash(struct dict *d, int n) {
 struct dict_entry *entry; struct dict_entry *next;
 if(!(d->rehashidx != -1)) return 0;
 while(n--) {
  if(d->dt[0].used == 0) {
   jfree(d->dt[0].entries);
   d->dt[0] = d->dt[1];
   _table_reset(&d->dt[1]);
   d->rehashidx = -1;
   return 0;
  }
  while(d->dt[0].entries[d->rehashidx] == ((void *)0)) d->rehashidx++;
  entry = d->dt[0].entries[d->rehashidx];
  while(entry) {
   unsigned int idx;
   next = entry->next;
   idx = d->opts->hash(entry->key)&d->dt[1].mask;
   entry->next = d->dt[1].entries[idx];
   d->dt[1].entries[idx] = entry;
   d->dt[1].used++;
   d->dt[0].used--;
   entry = next;
  }
  d->dt[0].entries[d->rehashidx++] = ((void *)0);
 }
 return 1;
}

variable_types: n int

variable_types: struct dict_entry { void *key; void *value; int ref; struct dict_entry *next; } *

variable_types:
idx
unsigned int


original_code:
static int dict_del_internal(dict *d, void *key, int flag) {
 int i, idx;
 dict_entry *entry, *prev;
 unsigned int hash;
 if(d->dt[0].size == 0) return 0;
 if((d->rehashidx != -1) && d->iterators == 0) dict_rehash(d, 1);
 hash = d->opts->hash(key);
 for(i = 0; i <= 1; i++) {
  idx = hash&d->dt[i].mask;
  entry = d->dt[i].entries[idx];
  prev = ((void *)0);
  while(entry) {
   if(d->opts->key_compare?d->opts->key_compare(entry->key, key):entry->key == key) {
    if(flag) {
     if(d->opts->key_destroy) d->opts->key_destroy(entry->key);
     if(d->opts->value_destroy) d->opts->value_destroy(entry->value);
    }
    if(prev)
     prev->next = entry->next;
    else
     d->dt[i].entries[idx] = entry->next;
    if(--entry->ref == 0) jfree(entry);
    d->dt[i].used--;
    return 1;
   }
   prev = entry;
   entry = entry->next;
  }
  if(!(d->rehashidx != -1)) break;
 }
 return 0;
}

canonical_original_code:
static int dict_del_internal(struct dict *d, void *key, int flag) {
 int i; int idx;
 struct dict_entry *entry; struct dict_entry *prev;
 unsigned int hash;
 if(d->dt[0].size == 0) return 0;
 if((d->rehashidx != -1) && d->iterators == 0) dict_rehash(d, 1);
 hash = d->opts->hash(key);
 for(i = 0; i <= 1; i++) {
  idx = hash&d->dt[i].mask;
  entry = d->dt[i].entries[idx];
  prev = ((void *)0);
  while(entry) {
   if(d->opts->key_compare?d->opts->key_compare(entry->key, key):entry->key == key) {
    if(flag) {
     if(d->opts->key_destroy) d->opts->key_destroy(entry->key);
     if(d->opts->value_destroy) d->opts->value_destroy(entry->value);
    }
    if(prev)
     prev->next = entry->next;
    else
     d->dt[i].entries[idx] = entry->next;
    if(--entry->ref == 0) jfree(entry);
    d->dt[i].used--;
    return 1;
   }
   prev = entry;
   entry = entry->next;
  }
  if(!(d->rehashidx != -1)) break;
 }
 return 0;
}

variable_types:
key
void *

variable_types: flag int

variable_types: i int

variable_types: idx int

variable_types:
hash
unsigned int


decompiled_code:
__int64 __fastcall dict_expand(__int64 a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // ebp
unsigned int v4; // er13
void *v5; // rax
void *v6; // rax

result = *(unsigned int *)(a1 + 56);
if ( (_DWORD)result != -1 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 16) <= a2 )
{
v3 = pow_size(a2);
v4 = v3 - 1;
v5 = (void *)jmalloc(8LL * v3);
v6 = memset(v5, 0, 8LL * v3);
if ( *(_QWORD *)(a1 + 8) )
{
*(_DWORD *)(a1 + 40) = v3;
*(_DWORD *)(a1 + 44) = v4;
*(_DWORD *)(a1 + 48) = 0;
*(_DWORD *)(a1 + 56) = 0;
*(_QWORD *)(a1 + 32) = v6;
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) = v6;
result = 0LL;
*(_DWORD *)(a1 + 16) = v3;
*(_DWORD *)(a1 + 20) = v4;
*(_DWORD *)(a1 + 24) = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // ebp
unsigned int v4; // er13
void *v5; // rax
void *v6; // rax

result = *(unsigned int *)(a1 + 56);
if ( (_DWORD)result != -1 )
return 0xFFFFFFFFLL;
if ( *(_DWORD *)(a1 + 16) <= a2 )
{
v3 = func0(a2);
v4 = v3 - 1;
v5 = (void *)jmalloc(8LL * v3);
v6 = memset(v5, 0, 8LL * v3);
if ( *(_QWORD *)(a1 + 8) )
{
*(_DWORD *)(a1 + 40) = v3;
*(_DWORD *)(a1 + 44) = v4;
*(_DWORD *)(a1 + 48) = 0;
*(_DWORD *)(a1 + 56) = 0;
*(_QWORD *)(a1 + 32) = v6;
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) = v6;
result = 0LL;
*(_DWORD *)(a1 + 16) = v3;
*(_DWORD *)(a1 + 20) = v4;
*(_DWORD *)(a1 + 24) = 0;
}
}
return result;
}

original_code:
int dict_expand(dict *d, unsigned int size) {
 unsigned int realsize;
 size_t msize;
 dict_table dt;
 if((d->rehashidx != -1) || d->dt[0].size > size)
  return -1;
 realsize = _pow_size(size);
 dt.size = realsize;
 dt.mask = realsize - 1;
 dt.used = 0;
 msize = realsize*sizeof(struct dict_entry *);
 dt.entries = jmalloc(msize);
 memset(dt.entries, 0, msize);
 if(d->dt[0].entries == ((void *)0)) {
  d->dt[0] = dt;
  return 0;
 }
 d->dt[1] = dt;
 d->rehashidx = 0;
 return 0;
}

canonical_original_code:
int dict_expand(struct dict *d, unsigned int size) {
 unsigned int realsize;
 unsigned long msize;
 struct dict_table dt;
 if((d->rehashidx != -1) || d->dt[0].size > size)
  return -1;
 realsize = _pow_size(size);
 dt.size = realsize;
 dt.mask = realsize - 1;
 dt.used = 0;
 msize = realsize*sizeof(struct dict_entry *);
 dt.entries = jmalloc(msize);
 memset(dt.entries, 0, msize);
 if(d->dt[0].entries == ((void *)0)) {
  d->dt[0] = dt;
  return 0;
 }
 d->dt[1] = dt;
 d->rehashidx = 0;
 return 0;
}

variable_types:
size
unsigned int

variable_types:
realsize
unsigned int

variable_types:
msize
unsigned long

variable_types: struct dict_table { struct dict_entry { void *key; void *value; int ref; struct dict_entry *next; } **entries; unsigned int size; unsigned int mask; unsigned int used; }


decompiled_code:
__int64 __fastcall dict_try_expand(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // esi

if ( a1[14] != -1 )
return 0LL;
v1 = a1[4];
if ( !v1 )
return dict_expand((__int64)a1, 8u);
v2 = a1[6];
if ( v1 > v2 )
return 0LL;
return dict_expand((__int64)a1, 2 * v2);
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
unsigned int v1; // eax
unsigned int v2; // esi

if ( a1[14] != -1 )
return 0LL;
v1 = a1[4];
if ( !v1 )
return func8((__int64)a1, 8u);
v2 = a1[6];
if ( v1 > v2 )
return 0LL;
return func8((__int64)a1, 2 * v2);
}

original_code:
static int dict_try_expand(dict *d) {
 if((d->rehashidx != -1)) return 0;
 if(d->dt[0].size == 0) return dict_expand(d, 1<<3);
 if(d->dt[0].used >= d->dt[0].size)
  return dict_expand(d, d->dt[0].used*2);
 return 0;
}

canonical_original_code:
static int dict_try_expand(struct dict *d) {
 if((d->rehashidx != -1)) return 0;
 if(d->dt[0].size == 0) return dict_expand(d, 1<<3);
 if(d->dt[0].used >= d->dt[0].size)
  return dict_expand(d, d->dt[0].used*2);
 return 0;
}


original_code:
int dict_add(dict *d, void *key, void *val) {
 int htidx;
 int idx;
 dict_entry *entry;
 if((d->rehashidx != -1) && d->iterators == 0) dict_rehash(d, 1);
 if((idx = _dict_key_index(d, key)) < 0) return -1;
 htidx = (d->rehashidx != -1)?1:0;
 entry = jmalloc(sizeof(struct dict_entry));
 entry->ref = 1;
 if(d->opts->key_dup) entry->key = d->opts->key_dup(key); else entry->key = (key);
 if(d->opts->value_dup) entry->value = d->opts->value_dup(val); else entry->value = (val);
 entry->next = d->dt[htidx].entries[idx];
 d->dt[htidx].used++;
 d->dt[htidx].entries[idx] = entry;
 return 1;
}

canonical_original_code:
int dict_add(struct dict *d, void *key, void *val) {
 int htidx;
 int idx;
 struct dict_entry *entry;
 if((d->rehashidx != -1) && d->iterators == 0) dict_rehash(d, 1);
 if((idx = _dict_key_index(d, key)) < 0) return -1;
 htidx = (d->rehashidx != -1)?1:0;
 entry = jmalloc(sizeof(struct dict_entry));
 entry->ref = 1;
 if(d->opts->key_dup) entry->key = d->opts->key_dup(key); else entry->key = (key);
 if(d->opts->value_dup) entry->value = d->opts->value_dup(val); else entry->value = (val);
 entry->next = d->dt[htidx].entries[idx];
 d->dt[htidx].used++;
 d->dt[htidx].entries[idx] = entry;
 return 1;
}

variable_types:
val
void *

variable_types: htidx int


original_code:
int dict_replace(dict *d, void *key, void *val) {
 dict_entry *entry;
 if((entry = dict_find(d, key)) != ((void *)0)) {
  if(d->opts->value_destroy) d->opts->value_destroy(entry->value);
  if(d->opts->value_dup) entry->value = d->opts->value_dup(val); else entry->value = (val);
  return 0;
 } else
  return dict_add(d, key, val);
}

canonical_original_code:
int dict_replace(struct dict *d, void *key, void *val) {
 struct dict_entry *entry;
 if((entry = dict_find(d, key)) != ((void *)0)) {
  if(d->opts->value_destroy) d->opts->value_destroy(entry->value);
  if(d->opts->value_dup) entry->value = d->opts->value_dup(val); else entry->value = (val);
  return 0;
 } else
  return dict_add(d, key, val);
}


decompiled_code:
__int64 __fastcall dict_del(_DWORD *a1, __int64 a2)
{
return dict_del_internal(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1, __int64 a2)
{
return func7(a1, a2, 1);
}

original_code:
int dict_del(dict *d, void *key) {
 return dict_del_internal(d, key, 1);
}

canonical_original_code:
int dict_del(struct dict *d, void *key) {
 return dict_del_internal(d, key, 1);
}


decompiled_code:
__int64 __fastcall dict_del_no_free(_DWORD *a1, __int64 a2)
{
return dict_del_internal(a1, a2, 0);
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, __int64 a2)
{
return func7(a1, a2, 0);
}

original_code:
int dict_del_no_free(dict *d, void *key) {
 return dict_del_internal(d, key, 0);
}

canonical_original_code:
int dict_del_no_free(struct dict *d, void *key) {
 return dict_del_internal(d, key, 0);
}


decompiled_code:
__int64 __fastcall dict_generic_hash(char *a1, __int64 a2)
{
char *v2; // rsi
unsigned int v3; // er8
int v4; // edx

if ( !a2 )
return 5381LL;
v2 = &a1[a2];
v3 = 5381;
do
{
v4 = *a1++;
v3 += v4 + 32 * v3;
}
while ( a1 != v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1, __int64 a2)
{
char *v2; // rsi
unsigned int v3; // er8
int v4; // edx

if ( !a2 )
return 5381LL;
v2 = &a1[a2];
v3 = 5381;
do
{
v4 = *a1++;
v3 += v4 + 32 * v3;
}
while ( a1 != v2 );
return v3;
}

original_code:
unsigned int dict_generic_hash(const char *buf, size_t len) {
 unsigned int hash = 5381;
 while (len--)
  hash = ((hash << 5) + hash) + (*buf++);
 return hash;
}

canonical_original_code:
unsigned int dict_generic_hash(char *buf, unsigned long len) {
 unsigned int hash = 5381;
 while (len--)
  hash = ((hash << 5) + hash) + (*buf++);
 return hash;
}

variable_types:
buf
char *

variable_types:
len
unsigned long


original_code:
dict_entry *dict_iterator_next(dict_iterator *iter) {
 dict *d = iter->d;
 while(1) {
  if(iter->entry == ((void *)0)) {
   if(iter->dt_idx == 0 && iter->idx == -1)
    d->iterators++;
   iter->idx++;
   if(iter->idx >= d->dt[iter->dt_idx].size) {
    if(iter->dt_idx == 0 && (d->rehashidx != -1)) {
     iter->dt_idx++;
     iter->idx = 0;
    } else
     break;
   }
   iter->entry = d->dt[iter->dt_idx].entries[iter->idx];
  } else {
   if(--iter->entry->ref == 0) jfree(iter->entry);
   iter->entry = iter->entry->next;
  }
  if(iter->entry) {
   iter->entry->ref++;
   return iter->entry;
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct dict_entry *dict_iterator_next(struct dict_iterator *iter) {
 struct dict *d = iter->d;
 while(1) {
  if(iter->entry == ((void *)0)) {
   if(iter->dt_idx == 0 && iter->idx == -1)
    d->iterators++;
   iter->idx++;
   if(iter->idx >= d->dt[iter->dt_idx].size) {
    if(iter->dt_idx == 0 && (d->rehashidx != -1)) {
     iter->dt_idx++;
     iter->idx = 0;
    } else
     break;
   }
   iter->entry = d->dt[iter->dt_idx].entries[iter->idx];
  } else {
   if(--iter->entry->ref == 0) jfree(iter->entry);
   iter->entry = iter->entry->next;
  }
  if(iter->entry) {
   iter->entry->ref++;
   return iter->entry;
  }
 }
 return ((void *)0);
}

variable_types: struct dict_iterator { struct dict { struct dict_opts { unsigned int (*hash)(void *key); void *(*key_dup)(void *key); void *(*value_dup)(void *key); int (*key_compare)(void *k1, void *k2); void (*key_destroy)(void *key); void (*value_destroy)(void *v); } *opts; struct dict_table { struct dict_entry **entries; unsigned int size; unsigned int mask; unsigned int used; } dt[2]; int rehashidx; int iterators; } *d; int dt_idx; int idx; struct dict_entry *entry; } *

variable_types: struct dict { struct dict_opts { unsigned int (*hash)(void *key); void *(*key_dup)(void *key); void *(*value_dup)(void *key); int (*key_compare)(void *k1, void *k2); void (*key_destroy)(void *key); void (*value_destroy)(void *v); } *opts; struct dict_table { struct dict_entry { void *key; void *value; int ref; struct dict_entry *next; } **entries; unsigned int size; unsigned int mask; unsigned int used; } dt[2]; int rehashidx; int iterators; } *

user_defined_types: struct dict_iterator { struct dict *d; int dt_idx; int idx; struct dict_entry *entry; }


decompiled_code:
__int64 __fastcall dict_iterator_destroy(_QWORD *a1)
{
__int64 v2; // rdi

if ( a1[1] != 0xFFFFFFFF00000000LL )
--*(_DWORD *)(*a1 + 60LL);
v2 = a1[2];
if ( !v2 )
return jfree(a1);
if ( (*(_DWORD *)(v2 + 16))-- != 1 )
return jfree(a1);
jfree(v2);
return jfree(a1);
}

canonical_decompiled_code:
__int64 __fastcall func17(_QWORD *a1)
{
__int64 v2; // rdi

if ( a1[1] != 0xFFFFFFFF00000000LL )
--*(_DWORD *)(*a1 + 60LL);
v2 = a1[2];
if ( !v2 )
return jfree(a1);
if ( (*(_DWORD *)(v2 + 16))-- != 1 )
return jfree(a1);
jfree(v2);
return jfree(a1);
}

original_code:
void dict_iterator_destroy(dict_iterator *iter) {
 if(!(iter->idx == -1 && iter->dt_idx == 0))
  iter->d->iterators--;
 if(iter->entry)
  if(--iter->entry->ref == 0) jfree(iter->entry);
 jfree(iter);
}

canonical_original_code:
void dict_iterator_destroy(struct dict_iterator *iter) {
 if(!(iter->idx == -1 && iter->dt_idx == 0))
  iter->d->iterators--;
 if(iter->entry)
  if(--iter->entry->ref == 0) jfree(iter->entry);
 jfree(iter);
}

variable_types: struct dict_iterator { struct dict { struct dict_opts { unsigned int (*hash)(void *key); void *(*key_dup)(void *key); void *(*value_dup)(void *key); int (*key_compare)(void *k1, void *k2); void (*key_destroy)(void *key); void (*value_destroy)(void *v); } *opts; struct dict_table { struct dict_entry { void *key; void *value; int ref; struct dict_entry *next; } **entries; unsigned int size; unsigned int mask; unsigned int used; } dt[2]; int rehashidx; int iterators; } *d; int dt_idx; int idx; struct dict_entry *entry; } *


decompiled_code:
__int64 __fastcall log_write(int fd, void *buf, unsigned __int64 a3)
{
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // rdx
int v8; // eax

if ( !a3 )
return 0;
v5 = 0;
v6 = 0LL;
do
{
v8 = write(fd, buf, a3 - v6);
if ( !v8 )
break;
if ( v8 == -1 )
return 0xFFFFFFFFLL;
v5 += v8;
v7 = v8;
v6 = (int)v5;
buf = (char *)buf + v7;
}
while ( (int)v5 < a3 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, unsigned __int64 a3)
{
unsigned int v5; // er12
__int64 v6; // rax
__int64 v7; // rdx
int v8; // eax

if ( !a3 )
return 0;
v5 = 0;
v6 = 0LL;
do
{
v8 = write(fd, buf, a3 - v6);
if ( !v8 )
break;
if ( v8 == -1 )
return 0xFFFFFFFFLL;
v5 += v8;
v7 = v8;
v6 = (int)v5;
buf = (char *)buf + v7;
}
while ( (int)v5 < a3 );
return v5;
}

original_code:
static int log_write(int fd, char *ptr, size_t len) {
 int count = 0;
 int wn = 0;
 while(count < len ) {
  wn = write(fd, ptr, len - count);
  if(wn == 0) return count;
  if(wn == -1) return -1;
  ptr += wn;
  count += wn;
 }
 return count;
}

canonical_original_code:
static int log_write(int fd, char *ptr, unsigned long len) {
 int count = 0;
 int wn = 0;
 while(count < len ) {
  wn = write(fd, ptr, len - count);
  if(wn == 0) return count;
  if(wn == -1) return -1;
  ptr += wn;
  count += wn;
 }
 return count;
}

variable_types: fd int

variable_types:
ptr
char *

variable_types: count int

variable_types: wn int


decompiled_code:
void __fastcall log_init(int a1)
{
logfd = a1;
lock = 0;
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
logfd = a1;
lock = 0;
}

original_code:
void log_init(int fd) {
 logfd = fd;
 (*&lock)=0;
}


decompiled_code:
void __fastcall set_top_level(int a1)
{
top_level = a1;
}

canonical_decompiled_code:
void __fastcall func5(int a1)
{
top_level = a1;
}

original_code:
void set_top_level(int level) {
 top_level = level;
}

variable_types: level int


decompiled_code:
void log_print(int a1, const char *a2, ...)
{
unsigned __int64 v2; // rax
gcc_va_list va; // [rsp+8h] [rbp-100E0h] BYREF
char s[65536]; // [rsp+20h] [rbp-100C8h] BYREF

if ( top_level <= a1 )
{
memset(s, 0, 0xFFFFuLL);
va_start(va, a2);
log_fmt_constprop_0(s, a1, a2, va);
spinlock_lock(&lock);
v2 = strlen(s);
log_write(logfd, s, v2);
spinlock_unlock_constprop_0();
}
}

canonical_decompiled_code:
void func6(int a1, const char *a2, ...)
{
unsigned __int64 v2; // rax
gcc_va_list va; // [rsp+8h] [rbp-100E0h] BYREF
char s[65536]; // [rsp+20h] [rbp-100C8h] BYREF

if ( top_level <= a1 )
{
memset(s, 0, 0xFFFFuLL);
va_start(va, a2);
func2(s, a1, a2, va);
spinlock_lock(&lock);
v2 = strlen(s);
func0(logfd, s, v2);
func3();
}
}

original_code:
void log_print(int level, const char *fmt, ...) {
 char buf[65535];
 if(level < top_level)
  return;
 memset(buf, 0, sizeof(buf));
 va_list arg_list;
 __builtin_va_start(arg_list,fmt);
 log_fmt(buf, sizeof(buf), level, fmt, arg_list);
 __builtin_va_end(arg_list);
 spinlock_lock(&lock);;
 log_write(logfd, buf, strlen(buf));
 spinlock_unlock(&lock);;
}

canonical_original_code:
void log_print(int level, char *fmt, ...) {
 char buf[65535];
 if(level < top_level)
  return;
 memset(buf, 0, sizeof(buf));
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,fmt);
 log_fmt(buf, sizeof(buf), level, fmt, arg_list);
 __builtin_va_end(arg_list);
 spinlock_lock(&lock);;
 log_write(logfd, buf, strlen(buf));
 spinlock_unlock(&lock);;
}

variable_types:
fmt
char *

variable_types:
buf
char [65535]


decompiled_code:
// attributes: thunk
__int64 command_key_destroy()
{
return cstr_destroy();
}

canonical_decompiled_code:
__int64 func0()
{
return cstr_destroy();
}

original_code:
void command_key_destroy(void *c) {
 char * s = (char *)c;
 cstr_destroy(s);
}

canonical_original_code:
void command_key_destroy(void *c) {
 char *s = (char *)c;
 cstr_destroy(s);
}

variable_types:
c
void *

variable_types:
s
char *


decompiled_code:
_BOOL8 __fastcall command_key_compare(_DWORD *a1, const void *a2)
{
size_t v2; // rdx
_BOOL8 result; // rax

v2 = (unsigned int)(*(a1 - 2) - *(a1 - 1));
if ( (_DWORD)v2 == *((_DWORD *)a2 - 2) - *((_DWORD *)a2 - 1) )
result = memcmp(a1, a2, v2) == 0;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1, const void *a2)
{
size_t v2; // rdx
_BOOL8 result; // rax

v2 = (unsigned int)(*(a1 - 2) - *(a1 - 1));
if ( (_DWORD)v2 == *((_DWORD *)a2 - 2) - *((_DWORD *)a2 - 1) )
result = memcmp(a1, a2, v2) == 0;
else
result = 0LL;
return result;
}

original_code:
int command_key_compare(const void *k1, const void *k2) {
 size_t len;
 char * s1 = (char *)k1;
 char * s2 = (char *)k2;
 len = ((((cstrhdr*)(s1 - sizeof(cstrhdr)))->len - ((cstrhdr*)(s1 - sizeof(cstrhdr)))->free));
 if(len != ((((cstrhdr*)(s2 - sizeof(cstrhdr)))->len - ((cstrhdr*)(s2 - sizeof(cstrhdr)))->free)))
  return 0;
 return memcmp(k1, k2, len) == 0;
}

canonical_original_code:
int command_key_compare(void *k1, void *k2) {
 unsigned long len;
 char *s1 = (char *)k1;
 char *s2 = (char *)k2;
 len = ((((struct cstrhdr *)(s1 - sizeof(cstrhdr)))->len - ((struct cstrhdr *)(s1 - sizeof(cstrhdr)))->free));
 if(len != ((((struct cstrhdr *)(s2 - sizeof(cstrhdr)))->len - ((struct cstrhdr *)(s2 - sizeof(cstrhdr)))->free)))
  return 0;
 return memcmp(k1, k2, len) == 0;
}

user_defined_types: struct cstrhdr { unsigned int len; unsigned int free; char buf[]; }


hash

decompiled_code:
__int64 __fastcall hash(__int64 a1)
{
return dict_generic_hash(a1, (unsigned int)(*(_DWORD *)(a1 - 8) - *(_DWORD *)(a1 - 4)));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return dict_generic_hash(a1, (unsigned int)(*(_DWORD *)(a1 - 8) - *(_DWORD *)(a1 - 4)));
}

original_code:
static unsigned int hash(const void *key) {
 char * cs = (char *)key;
 return dict_generic_hash(cs, ((((cstrhdr*)(cs - sizeof(cstrhdr)))->len - ((cstrhdr*)(cs - sizeof(cstrhdr)))->free)));
}

canonical_original_code:
static unsigned int hash(void *key) {
 char *cs = (char *)key;
 return dict_generic_hash(cs, ((((struct cstrhdr *)(cs - sizeof(cstrhdr)))->len - ((struct cstrhdr *)(cs - sizeof(cstrhdr)))->free)));
}

variable_types:
key
void *

variable_types:
cs
char *


decompiled_code:
__int64 __fastcall regist_commands(__int64 a1)
{
const char **v1; // rbx
const char *v2; // r13
size_t v3; // rax
__int64 v4; // rax
const char **v5; // rdx
__int64 result; // rax

v1 = (const char **)&commands;
do
{
v2 = *v1;
v3 = strlen(*v1);
v4 = cstr_new(v2, v3);
v5 = v1;
v1 += 3;
result = dict_add(*(_QWORD *)(a1 + 40), v4, v5);
}
while ( v1 != (const char **)(&commands + 9) );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
const char **v1; // rbx
const char *v2; // r13
size_t v3; // rax
__int64 v4; // rax
const char **v5; // rdx
__int64 result; // rax

v1 = (const char **)&commands;
do
{
v2 = *v1;
v3 = strlen(*v1);
v4 = cstr_new(v2, v3);
v5 = v1;
v1 += 3;
result = dict_add(*(_QWORD *)(a1 + 40), v4, v5);
}
while ( v1 != (const char **)(&commands + 9) );
return result;
}

original_code:
static void regist_commands(thr_socket_svr *svr) {
 size_t i;
 struct command *cmd;
 for(i = 0; i < sizeof(commands)/sizeof(struct command); i++) {
  cmd = &commands[i];
  dict_add(svr->commands, cstr_new(cmd->name, strlen(cmd->name)), cmd);
 }
}

canonical_original_code:
static void regist_commands(struct thr_socket_svr *svr) {
 unsigned long i;
 struct command *cmd;
 for(i = 0; i < sizeof(commands)/sizeof(struct command); i++) {
  cmd = &commands[i];
  dict_add(svr->commands, cstr_new(cmd->name, strlen(cmd->name)), cmd);
 }
}

variable_types: struct thr_socket_svr { int in_fd; int un_fd; int logfd; int pid; unsigned int connections; long last_info_time; struct cevents { int maxfd; struct cevent { int mask; int (*read_proc)(struct cevents *evts, int fd, void *priv, int mask); int (*write_proc)(struct cevents *evts, int fd, void *priv, int mask); void *priv; } *events; struct cevent_fired { int mask; int fd; } *fired; struct clist { struct clist_item { struct clist_item *prev; struct clist_item *next; void *data; } *head; unsigned long count; } *fired_queue; unsigned int qlock; unsigned int lock; long poll_sec; int poll_ms; char impl_name[64]; void *priv_data; } *evts; struct dict { struct dict_opts { unsigned int (*hash)(void *key); void *(*key_dup)(void *key); void *(*value_dup)(void *key); int (*key_compare)(void *k1, void *k2); void (*key_destroy)(void *key); void (*value_destroy)(void *v); } *opts; struct dict_table { struct dict_entry { void *key; void *value; int ref; struct dict_entry *next; } **entries; unsigned int size; unsigned int mask; unsigned int used; } dt[2]; int rehashidx; int iterators; } *commands; int running; struct _thr_pool { struct cthread { unsigned long thrid; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } cond; int state; void *(*proc)(void *); void *proc_data; struct _thr_pool *pool; } *thrs; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; int state; unsigned long size; void *(*thr_init_cb)(void *); void *(*thr_uninit_cb)(void *); } *thr_pool; } *

variable_types:
i
unsigned long

variable_types: struct command { char *name; void (*call)(struct cio { int fd; int type; int mask; char *rbuf; char *wbuf; int wcount; char ip[128]; int nbulk; int bulk_len; int reqtype; int port; int flag; struct obj { int ref; int type; void *priv; unsigned int lock; } **argv; unsigned long argc; int tabidx; void *priv; void *thr_priv; } *io); int symbolic; int argc; } *

user_defined_types: struct command { char *name; void (*call)(struct cio *io); int symbolic; int argc; }

user_defined_types: struct thr_socket_svr { int in_fd; int un_fd; int logfd; int pid; unsigned int connections; long last_info_time; struct cevents *evts; struct dict *commands; int running; struct _thr_pool *thr_pool; }

user_defined_types: struct cevents { int maxfd; struct cevent *events; struct cevent_fired *fired; struct clist *fired_queue; unsigned int qlock; unsigned int lock; long poll_sec; int poll_ms; char impl_name[64]; void *priv_data; }

user_defined_types: struct _thr_pool { struct cthread *thrs; union pthread_mutex_t mutex; int state; unsigned long size; void *(*thr_init_cb)(void *); void *(*thr_uninit_cb)(void *); }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct cio { int fd; int type; int mask; char *rbuf; char *wbuf; int wcount; char ip[128]; int nbulk; int bulk_len; int reqtype; int port; int flag; struct obj **argv; unsigned long argc; int tabidx; void *priv; void *thr_priv; }

user_defined_types: struct clist { struct clist_item *head; unsigned long count; }

user_defined_types: struct cthread { unsigned long thrid; union pthread_cond_t cond; int state; void *(*proc)(void *); void *proc_data; struct _thr_pool *pool; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }


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

shared[0] = cstr_obj_create("-ERR\r\n");
shared[1] = cstr_obj_create("+PONG\r\n");
shared[2] = cstr_obj_create("+OK\r\n");
result = cstr_obj_create("$-1\r\n");
shared[4] = result;
return result;
}

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

shared[0] = cstr_obj_create("-ERR\r\n");
shared[1] = cstr_obj_create("+PONG\r\n");
shared[2] = cstr_obj_create("+OK\r\n");
result = cstr_obj_create("$-1\r\n");
shared[4] = result;
return result;
}

original_code:
void shared_obj_create() {
 shared.err = cstr_obj_create("-ERR\r\n");
 shared.pong = cstr_obj_create("+PONG\r\n");
 shared.ok = cstr_obj_create("+OK\r\n");
 shared.nullbulk = cstr_obj_create("$-1\r\n");
}