decompiled_code:
char *__fastcall modifiermask2name(int a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( (dword_A48[4 * v1] & a1) == 0 )
{
if ( ++v1 == 10 )
return 0LL;
}
return (&g_modifier_names)[2 * (int)v1];
}

canonical_decompiled_code:
char *__fastcall func6(int a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( (dword_A48[4 * v1] & a1) == 0 )
{
if ( ++v1 == 10 )
return 0LL;
}
return (&g_modifier_names)[2 * (int)v1];
}

original_code:
char* modifiermask2name(unsigned int mask) {
    for (int i = 0; i < (sizeof(g_modifier_names)/sizeof(*g_modifier_names)); i++) {
        if (g_modifier_names[i].mask & mask) {
            return g_modifier_names[i].name;
        }
    }
    return ((void *)0);
}

canonical_original_code:
char *modifiermask2name(unsigned int mask) {
    for (int i = 0; i < (sizeof(g_modifier_names)/sizeof(*g_modifier_names)); i++) {
        if (g_modifier_names[i].mask & mask) {
            return g_modifier_names[i].name;
        }
    }
    return ((void *)0);
}

variable_types:
mask
unsigned int

return_type: char *


repo: xiaq/hlwm

decompiled_code:
__int64 __fastcall string2modifiers(__int64 a1, _DWORD *a2)
{
__int64 *v2; // rax
__int64 v3; // rdi
__int64 *v4; // rbp
bool v5; // zf
__int64 i; // rbx
int v7; // eax
__int64 result; // rax

v2 = (__int64 *)g_strsplit_set(a1, &unk_B14, 0LL);
v3 = *v2;
v4 = v2;
if ( *v2 )
{
v5 = v2[1] == 0;
*a2 = 0;
if ( v5 )
{
LABEL_8:
g_strfreev(v4);
result = 1LL;
}
else
{
for ( i = 0LL; ; v3 = v4[i] )
{
v7 = modifiername2mask(v3);
if ( !v7 )
break;
++i;
*a2 |= v7;
if ( !v4[i + 1] )
goto LABEL_8;
}
fprintf(stderr, "warning: unknown Modifier \"%s\"\n", (const char *)v4[i]);
g_strfreev(v4);
result = 0LL;
}
}
else
{
fwrite("warning: empty keysym\n", 1uLL, 0x16uLL, stderr);
g_strfreev(v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _DWORD *a2)
{
__int64 *v2; // rax
__int64 v3; // rdi
__int64 *v4; // rbp
bool v5; // zf
__int64 i; // rbx
int v7; // eax
__int64 result; // rax

v2 = (__int64 *)g_strsplit_set(a1, &unk_B14, 0LL);
v3 = *v2;
v4 = v2;
if ( *v2 )
{
v5 = v2[1] == 0;
*a2 = 0;
if ( v5 )
{
LABEL_8:
g_strfreev(v4);
result = 1LL;
}
else
{
for ( i = 0LL; ; v3 = v4[i] )
{
v7 = func5(v3);
if ( !v7 )
break;
++i;
*a2 |= v7;
if ( !v4[i + 1] )
goto LABEL_8;
}
fprintf(stderr, "warning: unknown Modifier \"%s\"\n", (const char *)v4[i]);
g_strfreev(v4);
result = 0LL;
}
}
else
{
fwrite("warning: empty keysym\n", 1uLL, 0x16uLL, stderr);
g_strfreev(v4);
result = 0LL;
}
return result;
}

original_code:
_Bool string2modifiers(char* string, unsigned int* modmask) {
    char** splitted = g_strsplit_set(string, "+-", 0);
    if (((void *)0) == splitted[0]) {
        fprintf(stderr, "warning: empty keysym\n");
        g_strfreev(splitted);
        return 0;
    }
    int i;
    *modmask = 0;
    for (i = 0; splitted[i+1] != ((void *)0); i++) {
        unsigned int cur_mask = modifiername2mask(splitted[i]);
        if (cur_mask == 0) {
            fprintf(stderr, "warning: unknown Modifier \"%s\"\n", splitted[i]);
            g_strfreev(splitted);
            return 0;
        }
        *modmask |= cur_mask;
    }
    g_strfreev(splitted);
    return 1;
}

canonical_original_code:
_Bool string2modifiers(char *string, unsigned int *modmask) {
    char **splitted = g_strsplit_set(string, "+-", 0);
    if (((void *)0) == splitted[0]) {
        fprintf(stderr, "warning: empty keysym\n");
        g_strfreev(splitted);
        return 0;
    }
    int i;
    *modmask = 0;
    for (i = 0; splitted[i+1] != ((void *)0); i++) {
        unsigned int cur_mask = modifiername2mask(splitted[i]);
        if (cur_mask == 0) {
            fprintf(stderr, "warning: unknown Modifier \"%s\"\n", splitted[i]);
            g_strfreev(splitted);
            return 0;
        }
        *modmask |= cur_mask;
    }
    g_strfreev(splitted);
    return 1;
}

variable_types:
string
char *

variable_types:
modmask
unsigned int *

variable_types:
splitted
char **

variable_types: i int


decompiled_code:
__int64 __fastcall string2key(__int64 a1, _DWORD *a2, KeySym *a3)
{
unsigned int v4; // er12
const char *v6; // r13
KeySym v7; // rax

v4 = string2modifiers(a1, a2);
if ( (_BYTE)v4 )
{
v6 = (const char *)strlasttoken(a1, &unk_B14);
v7 = XStringToKeysym(v6);
*a3 = v7;
if ( !v7 )
{
v4 = 0;
fprintf(stderr, "warning: unknown KeySym \"%s\"\n", v6);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _DWORD *a2, KeySym *a3)
{
unsigned int v4; // er12
const char *v6; // r13
KeySym v7; // rax

v4 = func7(a1, a2);
if ( (_BYTE)v4 )
{
v6 = (const char *)strlasttoken(a1, &unk_B14);
v7 = XStringToKeysym(v6);
*a3 = v7;
if ( !v7 )
{
v4 = 0;
fprintf(stderr, "warning: unknown KeySym \"%s\"\n", v6);
}
}
return v4;
}

original_code:
_Bool string2key(char* string, unsigned int* modmask, KeySym* keysym) {
    if (!string2modifiers(string, modmask)) {
        return 0;
    }
    char* last_token = strlasttoken(string, "+-");
    *keysym = XStringToKeysym(last_token);
    if (*keysym == 0L) {
        fprintf(stderr, "warning: unknown KeySym \"%s\"\n", last_token);
        return 0;
    }
    return 1;
}

canonical_original_code:
_Bool string2key(char *string, unsigned int *modmask, unsigned long *keysym) {
    if (!string2modifiers(string, modmask)) {
        return 0;
    }
    char *last_token = strlasttoken(string, "+-");
    *keysym = XStringToKeysym(last_token);
    if (*keysym == 0L) {
        fprintf(stderr, "warning: unknown KeySym \"%s\"\n", last_token);
        return 0;
    }
    return 1;
}

variable_types:
keysym
unsigned long *


decompiled_code:
__int64 __fastcall key_remove_bind_with_keysym(int a1, __int64 a2)
{
__int64 *v2; // rbp
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+8h] [rbp-20h]

v5 = a1;
v4 = a2;
v2 = (__int64 *)g_list_find_custom(g_key_binds, &v4, keysym_equals);
result = 0LL;
if ( v2 )
{
keybinding_free(*v2);
g_key_binds = g_list_remove_link(g_key_binds, v2);
g_list_free_1(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, __int64 a2)
{
__int64 *v2; // rbp
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+8h] [rbp-20h]

v5 = a1;
v4 = a2;
v2 = (__int64 *)g_list_find_custom(g_key_binds, &v4, keysym_equals);
result = 0LL;
if ( v2 )
{
func1(*v2);
g_key_binds = g_list_remove_link(g_key_binds, v2);
g_list_free_1(v2);
result = 1LL;
}
return result;
}

original_code:
_Bool key_remove_bind_with_keysym(unsigned int modifiers, KeySym keysym){
    KeyBinding bind;
    bind.modifiers = modifiers;
    bind.keysym = keysym;
    GList* element = g_list_find_custom(g_key_binds, &bind, (GCompareFunc)keysym_equals);
    if (!element) {
        return 0;
    }
    KeyBinding* data = element->data;
    keybinding_free(data);
    g_key_binds = g_list_remove_link(g_key_binds, element);
    g_list_free_1(element);
    return 1;
}

canonical_original_code:
_Bool key_remove_bind_with_keysym(unsigned int modifiers, unsigned long keysym){
    struct KeyBinding bind;
    bind.modifiers = modifiers;
    bind.keysym = keysym;
    struct _GList *element = g_list_find_custom(g_key_binds, &bind, (GCompareFunc)keysym_equals);
    if (!element) {
        return 0;
    }
    struct KeyBinding *data = element->data;
    keybinding_free(data);
    g_key_binds = g_list_remove_link(g_key_binds, element);
    g_list_free_1(element);
    return 1;
}

variable_types:
modifiers
unsigned int

variable_types:
keysym
unsigned long

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *

variable_types: struct KeyBinding { unsigned long keysym; unsigned int modifiers; int cmd_argc; char **cmd_argv; } *


keybind

decompiled_code:
__int64 __fastcall keybind(int a1, const char **a2, __int64 a3)
{
__int64 result; // rax
__m128i *v5; // rax
__int64 v6; // rdi
__int64 v7; // rbp
char *v8; // rax
KeySym v9[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v10; // [rsp+10h] [rbp-28h]

result = 9LL;
if ( a1 > 2 )
{
if ( (unsigned __int8)string2key((__int64)a2[1], &v9[1], v9) )
{
if ( XKeysymToKeycode(g_display, v9[0]) )
{
key_remove_bind_with_keysym(v9[1], v9[0]);
HIDWORD(v9[1]) = a1 - 2;
v10 = argv_duplicate((unsigned int)(a1 - 2), a2 + 2);
v5 = (__m128i *)g_malloc(24LL);
v6 = g_key_binds;
v7 = (__int64)v5;
*v5 = _mm_loadu_si128((const __m128i *)v9);
v5[1].m128i_i64[0] = v10;
g_key_binds = g_list_append(v6, v5);
grab_keybind(v7);
result = 0LL;
}
else
{
v8 = XKeysymToString(v9[0]);
g_string_append_printf(a3, "%s: No keycode for symbol %s\n", *a2, v8);
result = 3LL;
}
}
else
{
g_string_append_printf(a3, "%s: No such KeySym/modifier\n", *a2);
result = 3LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, const char **a2, __int64 a3)
{
__int64 result; // rax
__m128i *v5; // rax
__int64 v6; // rdi
__int64 v7; // rbp
char *v8; // rax
KeySym v9[2]; // [rsp+0h] [rbp-38h] BYREF
__int64 v10; // [rsp+10h] [rbp-28h]

result = 9LL;
if ( a1 > 2 )
{
if ( (unsigned __int8)func8((__int64)a2[1], &v9[1], v9) )
{
if ( XKeysymToKeycode(g_display, v9[0]) )
{
func9(v9[1], v9[0]);
HIDWORD(v9[1]) = a1 - 2;
v10 = argv_duplicate((unsigned int)(a1 - 2), a2 + 2);
v5 = (__m128i *)g_malloc(24LL);
v6 = g_key_binds;
v7 = (__int64)v5;
*v5 = _mm_loadu_si128((const __m128i *)v9);
v5[1].m128i_i64[0] = v10;
g_key_binds = g_list_append(v6, v5);
func2(v7);
result = 0LL;
}
else
{
v8 = XKeysymToString(v9[0]);
g_string_append_printf(a3, "%s: No keycode for symbol %s\n", *a2, v8);
result = 3LL;
}
}
else
{
g_string_append_printf(a3, "%s: No such KeySym/modifier\n", *a2);
result = 3LL;
}
}
return result;
}

original_code:
int keybind(int argc, char** argv, GString* output) {
    if (argc <= 2) {
        return HERBST_NEED_MORE_ARGS;
    }
    KeyBinding new_bind;
    if (!string2key(argv[1], &(new_bind.modifiers), &(new_bind.keysym))) {
        g_string_append_printf(output,
            "%s: No such KeySym/modifier\n", argv[0]);
        return HERBST_INVALID_ARGUMENT;
    }
    KeyCode keycode = XKeysymToKeycode(g_display, new_bind.keysym);
    if (!keycode) {
        g_string_append_printf(output,
            "%s: No keycode for symbol %s\n",
            argv[0], XKeysymToString(new_bind.keysym));
        return HERBST_INVALID_ARGUMENT;
    }
    key_remove_bind_with_keysym(new_bind.modifiers, new_bind.keysym);
    new_bind.cmd_argc = argc - 2;
    new_bind.cmd_argv = argv_duplicate(new_bind.cmd_argc, argv+2);
    KeyBinding* data = ((KeyBinding *) g_malloc_n ((1), sizeof (KeyBinding)));
    *data = new_bind;
    g_key_binds = g_list_append(g_key_binds, data);
    grab_keybind(data, ((void *)0));
    return 0;
}

canonical_original_code:
int keybind(int argc, char **argv, struct _GString *output) {
    if (argc <= 2) {
        return HERBST_NEED_MORE_ARGS;
    }
    struct KeyBinding new_bind;
    if (!string2key(argv[1], &(new_bind.modifiers), &(new_bind.keysym))) {
        g_string_append_printf(output,
            "%s: No such KeySym/modifier\n", argv[0]);
        return HERBST_INVALID_ARGUMENT;
    }
    unsigned char keycode = XKeysymToKeycode(g_display, new_bind.keysym);
    if (!keycode) {
        g_string_append_printf(output,
            "%s: No keycode for symbol %s\n",
            argv[0], XKeysymToString(new_bind.keysym));
        return HERBST_INVALID_ARGUMENT;
    }
    key_remove_bind_with_keysym(new_bind.modifiers, new_bind.keysym);
    new_bind.cmd_argc = argc - 2;
    new_bind.cmd_argv = argv_duplicate(new_bind.cmd_argc, argv+2);
    struct KeyBinding *data = ((KeyBinding *) g_malloc_n ((1), sizeof (KeyBinding)));
    *data = new_bind;
    g_key_binds = g_list_append(g_key_binds, data);
    grab_keybind(data, ((void *)0));
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *

variable_types: struct KeyBinding { unsigned long keysym; unsigned int modifiers; int cmd_argc; char **cmd_argv; }

variable_types:
keycode
unsigned char

return_type: int


decompiled_code:
int update_numlockmask()
{
int v0; // ebp
XModifierKeymap *v1; // r14
int v2; // eax
unsigned int v3; // ebx
KeyCode v4; // r15

v0 = 0;
numlockmask = 0;
v1 = XGetModifierMapping(g_display);
v2 = v1->max_keypermod;
do
{
v3 = 0;
if ( v2 )
{
do
{
v4 = v1->modifiermap[v3 + v0 * v2];
if ( v4 == XKeysymToKeycode(g_display, 0xFF7FuLL) )
numlockmask = 1 << v0;
v2 = v1->max_keypermod;
++v3;
}
while ( v1->max_keypermod > v3 );
}
++v0;
}
while ( v0 != 8 );
return XFreeModifiermap(v1);
}

canonical_decompiled_code:
int func11()
{
int v0; // ebp
XModifierKeymap *v1; // r14
int v2; // eax
unsigned int v3; // ebx
KeyCode v4; // r15

v0 = 0;
numlockmask = 0;
v1 = XGetModifierMapping(g_display);
v2 = v1->max_keypermod;
do
{
v3 = 0;
if ( v2 )
{
do
{
v4 = v1->modifiermap[v3 + v0 * v2];
if ( v4 == XKeysymToKeycode(g_display, 0xFF7FuLL) )
numlockmask = 1 << v0;
v2 = v1->max_keypermod;
++v3;
}
while ( v1->max_keypermod > v3 );
}
++v0;
}
while ( v0 != 8 );
return XFreeModifiermap(v1);
}

original_code:
void update_numlockmask() {
    unsigned int i, j;
    XModifierKeymap *modmap;
    numlockmask = 0;
    modmap = XGetModifierMapping(g_display);
    for(i = 0; i < 8; i++)
        for(j = 0; j < modmap->max_keypermod; j++)
            if(modmap->modifiermap[i * modmap->max_keypermod + j]
               == XKeysymToKeycode(g_display, 0xff7f))
                numlockmask = (1 << i);
    XFreeModifiermap(modmap);
}

canonical_original_code:
void update_numlockmask() {
    unsigned int i; unsigned int j;
    struct XModifierKeymap *modmap;
    numlockmask = 0;
    modmap = XGetModifierMapping(g_display);
    for(i = 0; i < 8; i++)
        for(j = 0; j < modmap->max_keypermod; j++)
            if(modmap->modifiermap[i * modmap->max_keypermod + j]
               == XKeysymToKeycode(g_display, 0xff7f))
                numlockmask = (1 << i);
    XFreeModifiermap(modmap);
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types: struct XModifierKeymap { int max_keypermod; unsigned char *modifiermap; } *

return_type: void


decompiled_code:
int key_init()
{
return update_numlockmask();
}

canonical_decompiled_code:
int func12()
{
return func11();
}

original_code:
void key_init() {
    update_numlockmask();
}


decompiled_code:
__int64 regrab_keys()
{
update_numlockmask();
XUngrabKey(g_display, 0, 0x8000u, g_root);
return g_list_foreach(g_key_binds, grab_keybind, 0LL);
}

canonical_decompiled_code:
__int64 func13()
{
func11();
XUngrabKey(g_display, 0, 0x8000u, g_root);
return g_list_foreach(g_key_binds, grab_keybind, 0LL);
}

original_code:
void regrab_keys() {
    update_numlockmask();
    XUngrabKey(g_display, 0L, (1<<15), g_root);
    g_list_foreach(g_key_binds, (GFunc)grab_keybind, ((void *)0));
}

canonical_original_code:
void regrab_keys() {
    update_numlockmask();
    XUngrabKey(g_display, 0L, (1<<15), g_root);
    g_list_foreach(g_key_binds, (void (*)(void *data, void *user_data))grab_keybind, ((void *)0));
}


decompiled_code:
__int64 key_remove_all_binds()
{
g_list_free_full(g_key_binds, keybinding_free);
g_key_binds = 0LL;
return regrab_keys();
}

canonical_decompiled_code:
__int64 func14()
{
g_list_free_full(g_key_binds, keybinding_free);
g_key_binds = 0LL;
return func13();
}

original_code:
void key_remove_all_binds() {
    g_list_free_full(g_key_binds, (GDestroyNotify)keybinding_free);
    g_key_binds = ((void *)0);
    regrab_keys();
}

canonical_original_code:
void key_remove_all_binds() {
    g_list_free_full(g_key_binds, (void (*)(void *data))keybinding_free);
    g_key_binds = ((void *)0);
    regrab_keys();
}


decompiled_code:
__int64 key_destroy()
{
return key_remove_all_binds();
}

canonical_decompiled_code:
__int64 func15()
{
return func14();
}

original_code:
void key_destroy() {
    key_remove_all_binds();
}


keyunbind

decompiled_code:
__int64 __fastcall keyunbind(int a1, const char **a2, __int64 a3)
{
const char *v4; // r8
__int64 result; // rax
int v6; // [rsp+0h] [rbp-24h] BYREF
KeySym v7[4]; // [rsp+4h] [rbp-20h] BYREF

if ( a1 <= 1 )
return 9LL;
v4 = a2[1];
if ( *v4 == 45 && v4[1] == 70 && !v4[2] || !strcmp(a2[1], "--all") )
{
key_remove_all_binds();
result = 0LL;
}
else if ( (unsigned __int8)string2key((__int64)v4, &v6, v7) )
{
if ( !(unsigned __int8)key_remove_bind_with_keysym(v6, v7[0]) )
g_string_append_printf(a3, "%s: Key \"%s\" is not bound\n", *a2, a2[1]);
regrab_keys();
result = 0LL;
}
else
{
g_string_append_printf(a3, "%s: No such KeySym/modifier\n", *a2);
result = 3LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, const char **a2, __int64 a3)
{
const char *v4; // r8
__int64 result; // rax
int v6; // [rsp+0h] [rbp-24h] BYREF
KeySym v7[4]; // [rsp+4h] [rbp-20h] BYREF

if ( a1 <= 1 )
return 9LL;
v4 = a2[1];
if ( *v4 == 45 && v4[1] == 70 && !v4[2] || !strcmp(a2[1], "--all") )
{
func14();
result = 0LL;
}
else if ( (unsigned __int8)func8((__int64)v4, &v6, v7) )
{
if ( !(unsigned __int8)func9(v6, v7[0]) )
g_string_append_printf(a3, "%s: Key \"%s\" is not bound\n", *a2, a2[1]);
func13();
result = 0LL;
}
else
{
g_string_append_printf(a3, "%s: No such KeySym/modifier\n", *a2);
result = 3LL;
}
return result;
}

original_code:
int keyunbind(int argc, char** argv, GString* output) {
    if (argc <= 1) {
        return HERBST_NEED_MORE_ARGS;
    }
    if (!strcmp(argv[1], "-F") || !strcmp(argv[1], "--all")) {
        key_remove_all_binds();
        return 0;
    }
    unsigned int modifiers;
    KeySym keysym;
    if (!string2key(argv[1], &modifiers, &keysym)) {
        g_string_append_printf(output,
            "%s: No such KeySym/modifier\n", argv[0]);
        return HERBST_INVALID_ARGUMENT;
    }
    if (key_remove_bind_with_keysym(modifiers, keysym) == 0) {
        g_string_append_printf(output,
            "%s: Key \"%s\" is not bound\n", argv[0], argv[1]);
    }
    regrab_keys();
    return 0;
}

canonical_original_code:
int keyunbind(int argc, char **argv, struct _GString *output) {
    if (argc <= 1) {
        return HERBST_NEED_MORE_ARGS;
    }
    if (!strcmp(argv[1], "-F") || !strcmp(argv[1], "--all")) {
        key_remove_all_binds();
        return 0;
    }
    unsigned int modifiers;
    unsigned long keysym;
    if (!string2key(argv[1], &modifiers, &keysym)) {
        g_string_append_printf(output,
            "%s: No such KeySym/modifier\n", argv[0]);
        return HERBST_INVALID_ARGUMENT;
    }
    if (key_remove_bind_with_keysym(modifiers, keysym) == 0) {
        g_string_append_printf(output,
            "%s: Key \"%s\" is not bound\n", argv[0], argv[1]);
    }
    regrab_keys();
    return 0;
}

user_defined_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; }


decompiled_code:
__int64 __fastcall key_find_binds_helper(__int64 a1, _QWORD *a2)
{
const char **v2; // rax
const char *v3; // r12
const char **v4; // rbp

v2 = (const char **)keybinding_to_g_string(a1);
v3 = *v2;
v4 = v2;
if ( !strncmp((const char *)a2[1], *v2, a2[2]) )
{
g_string_append(*a2, v3);
g_string_append_c_inline_isra_0((__int64 *)*a2, 10);
}
return g_string_free(v4, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, _QWORD *a2)
{
const char **v2; // rax
const char *v3; // r12
const char **v4; // rbp

v2 = (const char **)keybinding_to_g_string(a1);
v3 = *v2;
v4 = v2;
if ( !strncmp((const char *)a2[1], *v2, a2[2]) )
{
g_string_append(*a2, v3);
func3((__int64 *)*a2, 10);
}
return g_string_free(v4, 1LL);
}

original_code:
static void key_find_binds_helper(KeyBinding* b, struct key_find_context* c) {
    GString* name = keybinding_to_g_string(b);
    if (!strncmp(c->needle, name->str, c->needle_len)) {
        g_string_append(c->output, name->str);
        g_string_append_c_inline (c->output, '\n');
    }
    g_string_free(name, 1);
}

canonical_original_code:
static void key_find_binds_helper(struct KeyBinding *b, struct key_find_context *c) {
    struct _GString *name = keybinding_to_g_string(b);
    if (!strncmp(c->needle, name->str, c->needle_len)) {
        g_string_append(c->output, name->str);
        g_string_append_c_inline (c->output, '\n');
    }
    g_string_free(name, 1);
}

variable_types: struct key_find_context { struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *output; char *needle; unsigned long needle_len; } *

user_defined_types: struct KeyBinding { unsigned long keysym; unsigned int modifiers; int cmd_argc; char **cmd_argv; }

user_defined_types: struct key_find_context { struct _GString *output; char *needle; unsigned long needle_len; }


decompiled_code:
__int64 __fastcall key_find_binds(const char *a1, __int64 a2)
{
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = a2;
v3[1] = (__int64)a1;
v3[2] = strlen(a1);
return g_list_foreach(g_key_binds, key_find_binds_helper, v3);
}

canonical_decompiled_code:
__int64 __fastcall func19(const char *a1, __int64 a2)
{
__int64 v3[5]; // [rsp+0h] [rbp-28h] BYREF

v3[0] = a2;
v3[1] = (__int64)a1;
v3[2] = strlen(a1);
return g_list_foreach(g_key_binds, key_find_binds_helper, v3);
}

original_code:
void key_find_binds(char* needle, GString* output) {
    struct key_find_context c = {
        output, needle, strlen(needle)
    };
    g_list_foreach(g_key_binds, (GFunc)key_find_binds_helper, &c);
}

canonical_original_code:
void key_find_binds(char *needle, struct _GString *output) {
    struct key_find_context c = {
        output, needle, strlen(needle)
    };
    g_list_foreach(g_key_binds, (void (*)(void *data, void *user_data))key_find_binds_helper, &c);
}

variable_types:
needle
char *

variable_types: struct key_find_context { struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *output; char *needle; unsigned long needle_len; }


decompiled_code:
__int64 __fastcall key_list_binds(__int64 a1, __int64 a2, __int64 a3)
{
g_list_foreach(g_key_binds, key_list_binds_helper, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, __int64 a2, __int64 a3)
{
g_list_foreach(g_key_binds, key_list_binds_helper, a3);
return 0LL;
}

original_code:
int key_list_binds(int argc, char** argv, GString* output) {
    g_list_foreach(g_key_binds, (GFunc)key_list_binds_helper, output);
    return 0;
}

canonical_original_code:
int key_list_binds(int argc, char **argv, struct _GString *output) {
    g_list_foreach(g_key_binds, (void (*)(void *data, void *user_data))key_list_binds_helper, output);
    return 0;
}


decompiled_code:
int __fastcall complete_against_keysyms(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // er15
KeySym *v6; // r14
int i; // ebx
int v8; // eax
KeySym v9; // rdi
char *v10; // rax
int v12; // [rsp+4h] [rbp-44h] BYREF
int v13; // [rsp+8h] [rbp-40h] BYREF
int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

XDisplayKeycodes(g_display, &v12, &v13);
v5 = v13 - v12;
v6 = XGetKeyboardMapping(g_display, v12, v13 - v12 + 1, v14);
if ( v5 + 1 > 0 )
{
for ( i = 0; ; i = v8 )
{
v9 = v6[i * v14[0]];
if ( v9 )
{
v10 = XKeysymToString(v9);
try_complete_prefix(a1, v10, a2, a3);
v8 = i + 1;
if ( v5 == i )
return XFree(v6);
}
else
{
v8 = i + 1;
if ( v5 == i )
return XFree(v6);
}
}
}
return XFree(v6);
}

canonical_decompiled_code:
int __fastcall func21(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // er15
KeySym *v6; // r14
int i; // ebx
int v8; // eax
KeySym v9; // rdi
char *v10; // rax
int v12; // [rsp+4h] [rbp-44h] BYREF
int v13; // [rsp+8h] [rbp-40h] BYREF
int v14[15]; // [rsp+Ch] [rbp-3Ch] BYREF

XDisplayKeycodes(g_display, &v12, &v13);
v5 = v13 - v12;
v6 = XGetKeyboardMapping(g_display, v12, v13 - v12 + 1, v14);
if ( v5 + 1 > 0 )
{
for ( i = 0; ; i = v8 )
{
v9 = v6[i * v14[0]];
if ( v9 )
{
v10 = XKeysymToString(v9);
try_complete_prefix(a1, v10, a2, a3);
v8 = i + 1;
if ( v5 == i )
return XFree(v6);
}
else
{
v8 = i + 1;
if ( v5 == i )
return XFree(v6);
}
}
}
return XFree(v6);
}

original_code:
void complete_against_keysyms(char* needle, char* prefix, GString* output) {
    int min, max;
    XDisplayKeycodes(g_display, &min, &max);
    int kc_count = max - min + 1;
    int ks_per_kc;
    KeySym* keysyms;
    keysyms = XGetKeyboardMapping(g_display, min, kc_count, &ks_per_kc);
    for (int i = 0; i < kc_count; i++) {
        if (keysyms[i * ks_per_kc] != 0L) {
            char* str = XKeysymToString(keysyms[i * ks_per_kc]);
            try_complete_prefix(needle, str, prefix, output);
        }
    }
    XFree(keysyms);
}

canonical_original_code:
void complete_against_keysyms(char *needle, char *prefix, struct _GString *output) {
    int min; int max;
    XDisplayKeycodes(g_display, &min, &max);
    int kc_count = max - min + 1;
    int ks_per_kc;
    unsigned long *keysyms;
    keysyms = XGetKeyboardMapping(g_display, min, kc_count, &ks_per_kc);
    for (int i = 0; i < kc_count; i++) {
        if (keysyms[i * ks_per_kc] != 0L) {
            char *str = XKeysymToString(keysyms[i * ks_per_kc]);
            try_complete_prefix(needle, str, prefix, output);
        }
    }
    XFree(keysyms);
}

variable_types:
prefix
char *

variable_types: min int

variable_types: max int

variable_types:
keysyms
unsigned long *

variable_types: i int

variable_types:
str
char *


decompiled_code:
__int64 __fastcall complete_against_modifiers(__int64 a1, char a2, __int64 a3, __int64 a4)
{
__int64 *v6; // rbx
_QWORD *v7; // rbp
const char *v8; // rdx

v6 = (__int64 *)&g_modifier_names;
v7 = (_QWORD *)g_string_sized_new(20LL);
do
{
v8 = (const char *)*v6;
v6 += 2;
g_string_printf(v7, "%s%c", v8, (unsigned int)a2);
try_complete_prefix_partial(a1, *v7, a3, a4);
}
while ( v6 != &g_key_binds );
return g_string_free(v7, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, char a2, __int64 a3, __int64 a4)
{
__int64 *v6; // rbx
_QWORD *v7; // rbp
const char *v8; // rdx

v6 = (__int64 *)&g_modifier_names;
v7 = (_QWORD *)g_string_sized_new(20LL);
do
{
v8 = (const char *)*v6;
v6 += 2;
g_string_printf(v7, "%s%c", v8, (unsigned int)a2);
try_complete_prefix_partial(a1, *v7, a3, a4);
}
while ( v6 != &g_key_binds );
return g_string_free(v7, 1LL);
}

original_code:
void complete_against_modifiers(char* needle, char seperator,
                                char* prefix, GString* output) {
    GString* buf = g_string_sized_new(20);
    for (int i = 0; i < (sizeof(g_modifier_names)/sizeof(*g_modifier_names)); i++) {
        g_string_printf(buf, "%s%c", g_modifier_names[i].name, seperator);
        try_complete_prefix_partial(needle, buf->str, prefix, output);
    }
    g_string_free(buf, 1);
}

canonical_original_code:
void complete_against_modifiers(char *needle, char seperator, char *prefix, struct _GString *output) {
    struct _GString *buf = g_string_sized_new(20);
    for (int i = 0; i < (sizeof(g_modifier_names)/sizeof(*g_modifier_names)); i++) {
        g_string_printf(buf, "%s%c", g_modifier_names[i].name, seperator);
        try_complete_prefix_partial(needle, buf->str, prefix, output);
    }
    g_string_free(buf, 1);
}

variable_types: seperator char


decompiled_code:
void destroy_hook_regex()
{
__int64 v0; // rbx
__int64 v1; // rdi

if ( g_hook_regex_count > 0 )
{
v0 = 0LL;
do
{
v1 = v0++;
regfree((regex_t *)g_hook_regex + v1);
}
while ( g_hook_regex_count > (int)v0 );
}
free(g_hook_regex);
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rbx
__int64 v1; // rdi

if ( g_hook_regex_count > 0 )
{
v0 = 0LL;
do
{
v1 = v0++;
regfree((regex_t *)g_hook_regex + v1);
}
while ( g_hook_regex_count > (int)v0 );
}
free(g_hook_regex);
}

original_code:
void destroy_hook_regex() {
    int i;
    for (i = 0; i < g_hook_regex_count; i++) {
        regfree(g_hook_regex + i);
    }
    free(g_hook_regex);
}


decompiled_code:
void __fastcall __noreturn quit_herbstclient(unsigned int a1)
{
fprintf(stderr, "interrupted by signal %d\n", a1);
destroy_hook_regex();
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(unsigned int a1)
{
fprintf(stderr, "interrupted by signal %d\n", a1);
func0();
exit(1);
}

original_code:
static void quit_herbstclient(int signal) {
    fprintf(stderr, "interrupted by signal %d\n", signal);
    destroy_hook_regex();
    exit(1);
}

variable_types: signal int


yyerror

repo: xinu-os/xinu

decompiled_code:
int yyerror()
{
return fprintf(stderr, "Syntax error in %s on line %d\n", doing, (unsigned int)linectr);
}

canonical_decompiled_code:
int func0()
{
return fprintf(stderr, "Syntax error in %s on line %d\n", doing, (unsigned int)linectr);
}

original_code:
void yyerror(const char *s)
{
 fprintf(stderr, "Syntax error in %s on line %d\n", doing, linectr);
}

canonical_original_code:
void yyerror(char *s)
{
 fprintf(stderr, "Syntax error in %s on line %d\n", doing, linectr);
}

variable_types:
s
char *


lookup

decompiled_code:
__int64 __fastcall lookup(char *src)
{
int v2; // eax
size_t v3; // rbx
size_t v4; // rdi
char *v5; // rbp
int v6; // er14
__int64 v7; // rbx
__int64 result; // rax
__int64 v9; // r12

v2 = strlen(src);
if ( v2 > 19 )
{
v3 = 19LL;
fprintf(stderr, "warning: name %s truncated\n", src);
v4 = 20LL;
}
else
{
v3 = v2;
v4 = v2 + 1;
}
v5 = (char *)malloc(v4);
strncpy(v5, src, v3);
v6 = nsym;
v5[v3] = 0;
v7 = 0LL;
if ( v6 > 0 )
{
while ( strncmp(v5, (const char *)symtab[2 * v7], 0x14uLL) )
{
if ( v6 == ++v7 )
goto LABEL_8;
}
result = (unsigned int)v7;
}
else
{
LABEL_8:
v9 = 2LL * v6;
symtab[v9] = (__int64)v5;
LODWORD(symtab[v9 + 1]) = 0;
nsym = v6 + 1;
result = (unsigned int)v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
int v2; // eax
size_t v3; // rbx
size_t v4; // rdi
char *v5; // rbp
int v6; // er14
__int64 v7; // rbx
__int64 result; // rax
__int64 v9; // r12

v2 = strlen(src);
if ( v2 > 19 )
{
v3 = 19LL;
fprintf(stderr, "warning: name %s truncated\n", src);
v4 = 20LL;
}
else
{
v3 = v2;
v4 = v2 + 1;
}
v5 = (char *)malloc(v4);
strncpy(v5, src, v3);
v6 = nsym;
v5[v3] = 0;
v7 = 0LL;
if ( v6 > 0 )
{
while ( strncmp(v5, (const char *)symtab[2 * v7], 0x14uLL) )
{
if ( v6 == ++v7 )
goto LABEL_8;
}
result = (unsigned int)v7;
}
else
{
LABEL_8:
v9 = 2LL * v6;
symtab[v9] = (__int64)v5;
LODWORD(symtab[v9 + 1]) = 0;
nsym = v6 + 1;
result = (unsigned int)v6;
}
return result;
}

original_code:
int lookup(const char *str)
{
 int i;
 char *s;
 int len = strlen(str);
 if (len >= 20)
 {
  len = 20 -1;
  fprintf(stderr, "warning: name %s truncated\n", str);
 }
 s = (char *)malloc(len + 1);
 strncpy(s, str, len);
 s[len] = '\0';
 for (i = 0; i < nsym; i++)
 {
  if ( strncmp(s, symtab[i].name, 20) == 0 )
  { return(i); }
 }
 symtab[nsym].name = s;
 symtab[nsym].occurs = 0;
 return nsym++;
}

canonical_original_code:
int lookup(char *str)
{
 int i;
 char *s;
 int len = strlen(str);
 if (len >= 20)
 {
  len = 20 -1;
  fprintf(stderr, "warning: name %s truncated\n", str);
 }
 s = (char *)malloc(len + 1);
 strncpy(s, str, len);
 s[len] = '\0';
 for (i = 0; i < nsym; i++)
 {
  if ( strncmp(s, symtab[i].name, 20) == 0 )
  { return(i); }
 }
 symtab[nsym].name = s;
 symtab[nsym].occurs = 0;
 return nsym++;
}

variable_types: len int


newattr

decompiled_code:
void __fastcall newattr(int a1, int a2)
{
__int64 v3; // rdi
const char *v4; // r12
char *v5; // rdi

v3 = currtype;
if ( devs )
v3 = lastdv;
if ( a2 >= 0 && nsym > a2 )
{
v4 = (const char *)symtab[2 * a2];
if ( strnlen(v4, 0x14uLL) == 20 )
{
fwrite("Internal overflow\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
}
else
{
v4 = 0LL;
}
switch ( a1 )
{
case 263:
*(_DWORD *)(v3 + 32) = a2;
return;
case 264:
*(_DWORD *)(v3 + 36) = a2;
return;
case 265:
v5 = (char *)(v3 + 40);
goto LABEL_10;
case 266:
v5 = (char *)(v3 + 60);
goto LABEL_10;
case 267:
v5 = (char *)(v3 + 80);
goto LABEL_10;
case 268:
v5 = (char *)(v3 + 100);
goto LABEL_10;
case 269:
v5 = (char *)(v3 + 120);
goto LABEL_10;
case 270:
v5 = (char *)(v3 + 140);
goto LABEL_10;
case 271:
v5 = (char *)(v3 + 180);
goto LABEL_10;
case 272:
v5 = (char *)(v3 + 160);
goto LABEL_10;
case 275:
v5 = (char *)(v3 + 200);
goto LABEL_10;
case 276:
v5 = (char *)(v3 + 220);
LABEL_10:
strncpy(v5, v4, 0x14uLL);
break;
default:
fwrite("Internal error 1\n", 1uLL, 0x11uLL, stderr);
break;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
__int64 v3; // rdi
const char *v4; // r12
char *v5; // rdi

v3 = currtype;
if ( devs )
v3 = lastdv;
if ( a2 >= 0 && nsym > a2 )
{
v4 = (const char *)symtab[2 * a2];
if ( strnlen(v4, 0x14uLL) == 20 )
{
fwrite("Internal overflow\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
}
else
{
v4 = 0LL;
}
switch ( a1 )
{
case 263:
*(_DWORD *)(v3 + 32) = a2;
return;
case 264:
*(_DWORD *)(v3 + 36) = a2;
return;
case 265:
v5 = (char *)(v3 + 40);
goto LABEL_10;
case 266:
v5 = (char *)(v3 + 60);
goto LABEL_10;
case 267:
v5 = (char *)(v3 + 80);
goto LABEL_10;
case 268:
v5 = (char *)(v3 + 100);
goto LABEL_10;
case 269:
v5 = (char *)(v3 + 120);
goto LABEL_10;
case 270:
v5 = (char *)(v3 + 140);
goto LABEL_10;
case 271:
v5 = (char *)(v3 + 180);
goto LABEL_10;
case 272:
v5 = (char *)(v3 + 160);
goto LABEL_10;
case 275:
v5 = (char *)(v3 + 200);
goto LABEL_10;
case 276:
v5 = (char *)(v3 + 220);
LABEL_10:
strncpy(v5, v4, 0x14uLL);
break;
default:
fwrite("Internal error 1\n", 1uLL, 0x11uLL, stderr);
break;
}
}

original_code:
void newattr(int tok, int val)
{
 struct dev_ent *s;
 char *c;
 if (devs == (struct dev_ent *)0x00) { s = currtype; }
 else { s = lastdv; }
 if (val>=0 && val<nsym)
 {
  c = symtab[val].name;
  if (strnlen(c, 20) == 20 )
  {
   fprintf(stderr, "Internal overflow\n");
   exit(1);
  }
 }
 else
 { c = ((void *)0); }
 switch (tok)
 {
 case 263: s->csr = val; break;
 case 264: s->irq = val; break;
 case 265: strncpy(s->intr, c, 20); break;
 case 269: strncpy(s->read, c, 20); break;
 case 270: strncpy(s->write, c, 20); break;
 case 275: strncpy(s->getc, c, 20); break;
 case 276: strncpy(s->putc, c, 20); break;
 case 267: strncpy(s->open, c, 20); break;
 case 268: strncpy(s->close, c, 20); break;
 case 266: strncpy(s->init, c, 20); break;
 case 271: strncpy(s->seek, c, 20); break;
 case 272: strncpy(s->control, c, 20); break;
 default: fprintf(stderr, "Internal error 1\n");
 }
}

variable_types: tok int

variable_types: val int

variable_types: struct dev_ent { char *name; char *tname; int tnum; char *device; int csr; int irq; char intr[20]; char init[20]; char open[20]; char close[20]; char read[20]; char write[20]; char control[20]; char seek[20]; char getc[20]; char putc[20]; int minor; struct dev_ent *next; } *

variable_types:
c
char *


cktname

decompiled_code:
__int64 __fastcall cktname(unsigned int a1)
{
const char *v1; // rdx
__int64 i; // rax

v1 = (const char *)symtab[2 * (int)a1];
for ( i = ftypes; i; i = *(_QWORD *)(i + 248) )
{
if ( *(const char **)(i + 8) == v1 )
{
fprintf(stderr, "Duplicate type name %s on line %d\n", v1, (unsigned int)linectr);
exit(1);
}
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
const char *v1; // rdx
__int64 i; // rax

v1 = (const char *)symtab[2 * (int)a1];
for ( i = ftypes; i; i = *(_QWORD *)(i + 248) )
{
if ( *(const char **)(i + 8) == v1 )
{
fprintf(stderr, "Duplicate type name %s on line %d\n", v1, (unsigned int)linectr);
exit(1);
}
}
return a1;
}

original_code:
int cktname(int symid)
{
 struct dev_ent *s;
 char *name;
 name = symtab[symid].name;
 for (s = ftypes; s != (struct dev_ent *)0x00; s = s->next)
 {
  if (s->tname == name)
  {
   fprintf(stderr, "Duplicate type name %s on line %d\n",
           name, linectr);
   exit(1);
  }
 }
 return symid;
}

variable_types: symid int

variable_types:
name
char *

user_defined_types: struct dev_ent { char *name; char *tname; int tnum; char *device; int csr; int irq; char intr[20]; char init[20]; char open[20]; char close[20]; char read[20]; char write[20]; char control[20]; char seek[20]; char getc[20]; char putc[20]; int minor; struct dev_ent *next; }


initattr

original_code:
void initattr(struct dev_ent *fstr, int tnum, int deviceid)
{
 fstr->name = ((void *)0);
 fstr->tname = symtab[tnum].name;
 fstr->tnum = tnum;
 fstr->device = symtab[deviceid].name;
 fstr->csr = 0;
 fstr->irq = 0;
 strncpy(fstr->intr, "ioerr", 5);
 strncpy(fstr->init, "ioerr", 5);
 strncpy(fstr->open, "ioerr", 5);
 strncpy(fstr->close, "ioerr", 5);
 strncpy(fstr->read, "ioerr", 5);
 strncpy(fstr->write, "ioerr", 5);
 strncpy(fstr->control, "ioerr", 5);
 strncpy(fstr->seek, "ioerr", 5);
 strncpy(fstr->getc, "ioerr", 5);
 strncpy(fstr->putc, "ioerr", 5);
 fstr->minor = 0;
}

variable_types: tnum int

variable_types: deviceid int


mktype

decompiled_code:
__int64 __fastcall mktype(int a1)
{
int v1; // ebp
_QWORD *v2; // rbx
const char *v3; // rcx
const char *v4; // rdx
void *v5; // rax
__int64 result; // rax

v1 = currtname;
v2 = (_QWORD *)ftypes;
v3 = (const char *)symtab[2 * currtname];
v4 = (const char *)symtab[2 * a1];
if ( ftypes )
{
while ( 1 )
{
if ( (const char *)v2[1] == v3 && (const char *)v2[3] == v4 )
{
fprintf(stderr, "Duplicate device %s for type %s on line %d\n", v4, v3, (unsigned int)linectr);
exit(1);
}
if ( !v2[31] )
break;
v2 = (_QWORD *)v2[31];
}
v5 = malloc(0x100uLL);
v2[31] = v5;
currtype = (__int64)v5;
result = initattr((__int64)v5, v1, a1);
}
else
{
currtype = (__int64)malloc(0x100uLL);
ftypes = currtype;
result = initattr(currtype, v1, a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // ebp
_QWORD *v2; // rbx
const char *v3; // rcx
const char *v4; // rdx
void *v5; // rax
__int64 result; // rax

v1 = currtname;
v2 = (_QWORD *)ftypes;
v3 = (const char *)symtab[2 * currtname];
v4 = (const char *)symtab[2 * a1];
if ( ftypes )
{
while ( 1 )
{
if ( (const char *)v2[1] == v3 && (const char *)v2[3] == v4 )
{
fprintf(stderr, "Duplicate device %s for type %s on line %d\n", v4, v3, (unsigned int)linectr);
exit(1);
}
if ( !v2[31] )
break;
v2 = (_QWORD *)v2[31];
}
v5 = malloc(0x100uLL);
v2[31] = v5;
currtype = (__int64)v5;
result = func4((__int64)v5, v1, a1);
}
else
{
currtype = (__int64)malloc(0x100uLL);
ftypes = currtype;
result = func4(currtype, v1, a1);
}
return result;
}

original_code:
void mktype(int deviceid)
{
 struct dev_ent *s, *p;
 char *tn, *dn;
 p = (struct dev_ent *)0x00;
 tn = symtab[currtname].name;
 dn = symtab[deviceid].name;
 for (s = ftypes; s != (struct dev_ent *)0x00 ; s = s->next)
 {
  if (s->tname == tn && s->device==dn)
  {
   fprintf(stderr, "Duplicate device %s for type %s on line %d\n",
           dn, tn, linectr);
   exit(1);
  }
  p = s;
 }
 currtype = s = (struct dev_ent *)malloc(sizeof(struct dev_ent));
 if (ftypes != (struct dev_ent *)0x00) { p->next = s; }
 else { ftypes = s; }
 initattr(s, currtname, deviceid);
}

canonical_original_code:
void mktype(int deviceid)
{
 struct dev_ent *s; struct dev_ent *p;
 char *tn; char *dn;
 p = (struct dev_ent *)0x00;
 tn = symtab[currtname].name;
 dn = symtab[deviceid].name;
 for (s = ftypes; s != (struct dev_ent *)0x00 ; s = s->next)
 {
  if (s->tname == tn && s->device==dn)
  {
   fprintf(stderr, "Duplicate device %s for type %s on line %d\n",
           dn, tn, linectr);
   exit(1);
  }
  p = s;
 }
 currtype = s = (struct dev_ent *)malloc(sizeof(struct dev_ent));
 if (ftypes != (struct dev_ent *)0x00) { p->next = s; }
 else { ftypes = s; }
 initattr(s, currtname, deviceid);
}

variable_types:
tn
char *

variable_types:
dn
char *


ckdname

decompiled_code:
__int64 __fastcall ckdname(unsigned int a1)
{
const char *v1; // rdx
const char **v2; // rax

v1 = (const char *)symtab[2 * (int)a1];
v2 = (const char **)devs;
if ( devs )
{
do
{
if ( *v2 == v1 )
{
fprintf(stderr, "Duplicate device name %s on line %d\n", v1, (unsigned int)linectr);
exit(1);
}
v2 = (const char **)v2[31];
}
while ( v2 );
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
const char *v1; // rdx
const char **v2; // rax

v1 = (const char *)symtab[2 * (int)a1];
v2 = (const char **)devs;
if ( devs )
{
do
{
if ( *v2 == v1 )
{
fprintf(stderr, "Duplicate device name %s on line %d\n", v1, (unsigned int)linectr);
exit(1);
}
v2 = (const char **)v2[31];
}
while ( v2 );
}
return a1;
}

original_code:
int ckdname(int devid)
{
 struct dev_ent *s;
 char *name;
 name = symtab[devid].name;
 for (s = devs; s != (struct dev_ent *)0x00; s = s->next)
 {
  if (s->name == name)
  {
   fprintf(stderr, "Duplicate device name %s on line %d\n",
           name, linectr);
   exit(1);
  }
 }
 return devid;
}

variable_types: devid int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
const char **v4; // rbp
__int64 v5; // rbx
const char *i; // rdx
unsigned int v7; // ebp
__int64 j; // rbx
__int64 v9; // rcx
__int64 v10; // rax
int v11; // edx
__int64 *v12; // rbp
int v13; // er12
int v14; // er13
char *v15; // rbx
char v16; // r14
int v17; // eax
int v18; // ebp
__int64 *v19; // rbx
const char **v20; // rbx
unsigned int v21; // ebp
const char *v23; // rdx
__int64 k; // rbx
int status; // [rsp+Ch] [rbp-5Ch]
char dest[20]; // [rsp+10h] [rbp-58h] BYREF
char v27; // [rsp+24h] [rbp-44h] BYREF

if ( argc <= 1 )
{
if ( freopen("xinu.config", "r", stdin) )
{
LABEL_5:
status = yyparse();
if ( !status )
goto LABEL_6;
LABEL_57:
exit(status);
}
goto LABEL_48;
}
v3 = argv[1];
v4 = argv;
if ( strncmp("-v", v3, 2uLL) )
{
if ( argc == 2 )
{
if ( freopen(v3, "r", stdin) )
goto LABEL_5;
goto LABEL_55;
}
LABEL_56:
fwrite("use: config [-v] [file]\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
if ( argc - 1 > 2 )
goto LABEL_56;
puts("Opening input file...");
if ( argc != 3 )
{
if ( freopen("xinu.config", "r", stdin) )
goto LABEL_25;
LABEL_48:
v23 = "xinu.config";
LABEL_49:
fprintf(stderr, "Can't open %s\n", v23);
goto LABEL_50;
}
v4 = argv + 1;
if ( !freopen(argv[2], "r", stdin) )
{
LABEL_55:
v23 = v4[1];
goto LABEL_49;
}
LABEL_25:
puts("Parsing configuration specs...");
status = yyparse();
if ( status )
goto LABEL_57;
puts("Opening output files...");
status = 1;
LABEL_6:
confc = fopen("../system/conf.c", "w");
if ( !confc )
{
fprintf(stderr, "Can't write on %s\n", "../system/conf.c");
exit(1);
}
confh = fopen("../include/conf.h", "w");
if ( !confh )
{
fprintf(stderr, "Can't write on %s\n", "../include/conf.h");
LABEL_50:
exit(1);
}
fwrite("/* conf.h (GENERATED FILE; DO NOT EDIT) */\n\n", 1uLL, 0x2CuLL, confh);
fwrite("#ifndef _CONF_H_\n", 1uLL, 0x11uLL, confh);
fwrite("#define _CONF_H_\n\n", 1uLL, 0x12uLL, confh);
fwrite("#include <stddef.h>\n\n", 1uLL, 0x15uLL, confh);
if ( status )
puts("Writing output...");
v5 = (unsigned int)((_DWORD)devstab + 8);
fwrite("/* Device table declarations */\n\n", 1uLL, 0x21uLL, confh);
for ( i = devstab[0]; i; i = *(const char **)(v5 - 8) )
{
v5 += 8LL;
fprintf(confh, "%s\n", i);
}
v7 = 0;
fputc(10, confh);
fwrite("/* Device name definitions */\n\n", 1uLL, 0x1FuLL, confh);
for ( j = devs; j; j = *(_QWORD *)(j + 248) )
{
v9 = v7++;
fprintf(confh, "#define %-12s%d /* type %-8s */\n", *(const char **)j, v9, *(const char **)(j + 8));
v10 = 2LL * *(int *)(j + 16);
v11 = symtab[v10 + 1];
LODWORD(symtab[v10 + 1]) = v11 + 1;
*(_DWORD *)(j + 240) = v11;
}
v12 = symtab;
v13 = 0;
fputc(10, confh);
fwrite("/* Control block sizes */\n\n", 1uLL, 0x1BuLL, confh);
if ( nsym > 0 )
{
do
{
v14 = *((_DWORD *)v12 + 2);
if ( v14 > 0 )
{
v15 = dest;
strncpy(dest, (const char *)*v12, 0x14uLL);
do
{
v16 = *v15;
if ( !*v15 )
break;
*v15++ = (*_ctype_toupper_loc())[v16];
}
while ( &v27 != v15 );
dest[19] = 0;
fprintf(confh, "#define N%s %d\n", dest, (unsigned int)v14);
}
++v13;
v12 += 2;
}
while ( nsym > v13 );
}
fputc(10, confh);
fprintf(confh, "#define DEVMAXNAME %d\n", 20LL);
if ( ndevs > 0 )
fprintf(confh, "#define NDEVS %d\n", (unsigned int)ndevs);
v17 = brkcount;
if ( brkcount == 2 )
{
if ( (status & 1) != 0 )
{
printf("Copying definitions to %s...\n", "../include/conf.h");
v17 = brkcount;
}
if ( v17 == 2 )
fputs(literal_string, confh);
}
v18 = 0;
v19 = symtab;
fwrite("\n#endif /* _CONF_H_ */\n", 1uLL, 0x17uLL, confh);
fclose(confh);
fwrite("/* conf.c (GENERATED FILE; DO NOT EDIT) */\n\n", 1uLL, 0x2CuLL, confc);
fprintf(confc, "#include %s\n", "<conf.h>");
fwrite("#include <device.h>\n\n", 1uLL, 0x15uLL, confc);
if ( nsym > 0 )
{
do
{
if ( *((int *)v19 + 2) > 0 )
fprintf(confc, "#include <%s.h>\n", (const char *)*v19);
++v18;
v19 += 2;
}
while ( nsym > v18 );
}
fputc(10, confc);
fwrite("extern devcall ioerr(void);\n", 1uLL, 0x1CuLL, confc);
fwrite("extern devcall ionull(void);\n\n", 1uLL, 0x1EuLL, confc);
fwrite("/* device independent I/O switch */\n\n", 1uLL, 0x25uLL, confc);
if ( ndevs > 0 )
{
fwrite("const device devtab[NDEVS] =\n{\n", 1uLL, 0x1FuLL, confc);
fprintf(
confc,
"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n",
"/**",
" * Format of entries is:",
" * dev-number, minor-number, dev-name,",
" * init, open, close,",
" * read, write, seek,",
" * getc, putc, control,",
" * dev-csr-address, intr-handler, irq",
" */");
}
v20 = (const char **)devs;
v21 = 0;
if ( devs )
{
do
{
while ( 1 )
{
fprintf(confc, "/* %s is %s */\n", *v20, v20[1]);
fprintf(confc, "\t{ %d, %d, \"%s\",\n", v21, *((unsigned int *)v20 + 60), *v20);
fprintf(
confc,
"\t (void *)%s, (void *)%s, (void *)%s,\n",
(const char *)v20 + 60,
(const char *)v20 + 80,
(const char *)v20 + 100);
fprintf(
confc,
"\t (void *)%s, (void *)%s, (void *)%s,\n",
(const char *)v20 + 120,
(const char *)v20 + 140,
(const char *)v20 + 180);
fprintf(
confc,
"\t (void *)%s, (void *)%s, (void *)%s,\n",
(const char *)v20 + 200,
(const char *)v20 + 220,
(const char *)v20 + 160);
fprintf(
confc,
"\t (void *)0x%x, (void *)%s, %d }",
*((unsigned int *)v20 + 8),
(const char *)v20 + 40,
*((unsigned int *)v20 + 9));
if ( !v20[31] )
break;
++v21;
fwrite(",\n\n", 1uLL, 3uLL, confc);
v20 = (const char **)v20[31];
if ( !v20 )
goto LABEL_45;
}
++v21;
fwrite("\n};", 1uLL, 3uLL, confc);
v20 = (const char **)v20[31];
}
while ( v20 );
}
LABEL_45:
fputc(10, confc);
fclose(confc);
if ( status )
{
printf("Configuration complete. Number of devs=%d:\n", (unsigned int)ndevs);
for ( k = devs; k; k = *(_QWORD *)(k + 248) )
{
printf("Device %s (on %s)\n", *(const char **)k, *(const char **)(k + 24));
printf(
" csr=0x%04x, irq=0x%04x, minor=%d\n",
*(unsigned int *)(k + 32),
*(unsigned int *)(k + 36),
*(unsigned int *)(k + 240));
}
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int n, i, fcount;
 struct dev_ent *s;
 int verbose = 0;
 char *p;
 if ( argc > 1 && (strncmp("-v", argv[1], 2) == 0) )
 {
  argc--;
  argv++;
  verbose++;
 }
 if ( argc > 2 )
 {
  fprintf(stderr, "use: config [-v] [file]\n");
  exit(1);
 }
 if (verbose) { printf("Opening input file...\n"); }
 if (argc == 2)
 {
  if (freopen(argv[1], "r", stdin) == ((void *)0))
  {
   fprintf(stderr, "Can't open %s\n", argv[1]);
   exit(1);
  }
 }
 else
 {
  if (freopen("xinu.config", "r", stdin) == ((void *)0))
  {
   fprintf(stderr, "Can't open %s\n", "xinu.config");
   exit(1);
  }
 }
 if (verbose) { printf("Parsing configuration specs...\n"); }
 if ( (n = yyparse()) != 0 ) { exit(n); }
 if (verbose) { printf("Opening output files...\n"); }
 if ( (confc = fopen("../system/conf.c","w") ) == ((void *)0))
 {
  fprintf(stderr, "Can't write on %s\n", "../system/conf.c");
  exit(1);
 }
 if ( (confh = fopen("../include/conf.h","w") ) == ((void *)0))
 {
  fprintf(stderr, "Can't write on %s\n", "../include/conf.h");
  exit(1);
 }
 fprintf(confh, "/* conf.h (GENERATED FILE; DO NOT EDIT) */\n\n");
 fprintf(confh, "#ifndef _CONF_H_\n");
 fprintf(confh, "#define _CONF_H_\n\n");
 fprintf(confh, "#include <stddef.h>\n\n");
 if (verbose) { printf("Writing output...\n"); }
 fprintf(confh, "/* Device table declarations */\n\n");
 for (i = 0; (p = devstab[i]) != ((void *)0); i++)
 {
  fprintf(confh, "%s\n", p);
 }
 fprintf(confh, "\n");
 fprintf(confh, "/* Device name definitions */\n\n");
 for (i = 0, s = devs; s != (struct dev_ent *)0x00; i++, s = s->next)
 {
  fprintf(confh, "#define %-12s%d       /* type %-8s */\n",
          s->name, i, s->tname);
  s->minor = symtab[s->tnum].occurs++;
 }
 fprintf(confh, "\n");
 fprintf(confh, "/* Control block sizes */\n\n");
 for (i = 0; i < nsym; i++)
 {
  if (symtab[i].occurs > 0)
  {
   int j;
   char name[20];
   strncpy(name, symtab[i].name, 20);
   for (j = 0; j < 20 && name[j] != '\0'; j++)
   { name[j] = toupper( name[j] ); }
   name[19] = '\0';
   fprintf(confh, "#define N%s %d\n",
           name, symtab[i].occurs);
  }
 }
 fprintf(confh, "\n");
 fprintf(confh, "#define DEVMAXNAME %d\n", 20);
 if (ndevs > 0) { fprintf(confh, "#define NDEVS %d\n", ndevs); }
 if (brkcount == 2 && verbose)
 { printf("Copying definitions to %s...\n", "../include/conf.h"); }
 if (brkcount == 2 )
 {
  fputs(literal_string, confh);
 }
 fprintf(confh, "\n#endif /* _CONF_H_ */\n");
 fclose(confh);
 fprintf(confc, "/* conf.c (GENERATED FILE; DO NOT EDIT) */\n\n");
 fprintf(confc, "#include %s\n", "<conf.h>");
 fprintf(confc, "#include <device.h>\n\n");
 for (i = 0; i < nsym; i++)
 {
  if (symtab[i].occurs > 0)
  { fprintf(confc, "#include <%s.h>\n", symtab[i].name); }
 }
 fprintf(confc, "\n");
 fprintf(confc, "extern devcall ioerr(void);\n");
 fprintf(confc, "extern devcall ionull(void);\n\n");
 fprintf(confc, "/* device independent I/O switch */\n\n");
 if (ndevs > 0)
 {
  fprintf(confc, "const device devtab[NDEVS] =\n{\n");
  fprintf(confc, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n",
   "/**",
   " * Format of entries is:",
   " * dev-number, minor-number, dev-name,",
   " * init, open, close,",
   " * read, write, seek,",
   " * getc, putc, control,",
   " * dev-csr-address, intr-handler, irq",
   " */");
 }
 for (fcount = 0, s = devs; s != (struct dev_ent *)0x00; fcount++, s = s->next)
 {
  fprintf(confc, "/* %s is %s */\n", s->name, s->tname);
  fprintf(confc, "\t{ %d, %d, \"%s\",\n", fcount, s->minor, s->name);
  fprintf(confc, "\t  (void *)%s, (void *)%s, (void *)%s,\n",
          s->init, s->open, s->close);
  fprintf(confc, "\t  (void *)%s, (void *)%s, (void *)%s,\n",
          s->read, s->write, s->seek);
  fprintf(confc, "\t  (void *)%s, (void *)%s, (void *)%s,\n",
          s->getc, s->putc, s->control);
  fprintf(confc, "\t  (void *)0x%x, (void *)%s, %d }",
          s->csr, s->intr, s->irq);
  if ( s->next != (struct dev_ent *)0x00 ) { fprintf(confc, ",\n\n"); }
  else { fprintf(confc, "\n};"); }
 }
 fprintf(confc, "\n");
 fclose(confc);
 if (verbose)
 {
  printf("Configuration complete. Number of devs=%d:\n", ndevs);
  for (s = devs; s != (struct dev_ent *)0x00 ; s = s->next)
  {
   printf("Device %s (on %s)\n", s->name, s->device);
   printf("    csr=0x%04x, irq=0x%04x, minor=%d\n",
          s->csr, s->irq, s->minor);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int n; int i; int fcount;
 struct dev_ent *s;
 int verbose = 0;
 char *p;
 if ( argc > 1 && (strncmp("-v", argv[1], 2) == 0) )
 {
  argc--;
  argv++;
  verbose++;
 }
 if ( argc > 2 )
 {
  fprintf(stderr, "use: config [-v] [file]\n");
  exit(1);
 }
 if (verbose) { printf("Opening input file...\n"); }
 if (argc == 2)
 {
  if (freopen(argv[1], "r", stdin) == ((void *)0))
  {
   fprintf(stderr, "Can't open %s\n", argv[1]);
   exit(1);
  }
 }
 else
 {
  if (freopen("xinu.config", "r", stdin) == ((void *)0))
  {
   fprintf(stderr, "Can't open %s\n", "xinu.config");
   exit(1);
  }
 }
 if (verbose) { printf("Parsing configuration specs...\n"); }
 if ( (n = yyparse()) != 0 ) { exit(n); }
 if (verbose) { printf("Opening output files...\n"); }
 if ( (confc = fopen("../system/conf.c","w") ) == ((void *)0))
 {
  fprintf(stderr, "Can't write on %s\n", "../system/conf.c");
  exit(1);
 }
 if ( (confh = fopen("../include/conf.h","w") ) == ((void *)0))
 {
  fprintf(stderr, "Can't write on %s\n", "../include/conf.h");
  exit(1);
 }
 fprintf(confh, "/* conf.h (GENERATED FILE; DO NOT EDIT) */\n\n");
 fprintf(confh, "#ifndef _CONF_H_\n");
 fprintf(confh, "#define _CONF_H_\n\n");
 fprintf(confh, "#include <stddef.h>\n\n");
 if (verbose) { printf("Writing output...\n"); }
 fprintf(confh, "/* Device table declarations */\n\n");
 for (i = 0; (p = devstab[i]) != ((void *)0); i++)
 {
  fprintf(confh, "%s\n", p);
 }
 fprintf(confh, "\n");
 fprintf(confh, "/* Device name definitions */\n\n");
 for (i = 0, s = devs; s != (struct dev_ent *)0x00; i++, s = s->next)
 {
  fprintf(confh, "#define %-12s%d       /* type %-8s */\n",
          s->name, i, s->tname);
  s->minor = symtab[s->tnum].occurs++;
 }
 fprintf(confh, "\n");
 fprintf(confh, "/* Control block sizes */\n\n");
 for (i = 0; i < nsym; i++)
 {
  if (symtab[i].occurs > 0)
  {
   int j;
   char name[20];
   strncpy(name, symtab[i].name, 20);
   for (j = 0; j < 20 && name[j] != '\0'; j++)
   { name[j] = toupper( name[j] ); }
   name[19] = '\0';
   fprintf(confh, "#define N%s %d\n",
           name, symtab[i].occurs);
  }
 }
 fprintf(confh, "\n");
 fprintf(confh, "#define DEVMAXNAME %d\n", 20);
 if (ndevs > 0) { fprintf(confh, "#define NDEVS %d\n", ndevs); }
 if (brkcount == 2 && verbose)
 { printf("Copying definitions to %s...\n", "../include/conf.h"); }
 if (brkcount == 2 )
 {
  fputs(literal_string, confh);
 }
 fprintf(confh, "\n#endif /* _CONF_H_ */\n");
 fclose(confh);
 fprintf(confc, "/* conf.c (GENERATED FILE; DO NOT EDIT) */\n\n");
 fprintf(confc, "#include %s\n", "<conf.h>");
 fprintf(confc, "#include <device.h>\n\n");
 for (i = 0; i < nsym; i++)
 {
  if (symtab[i].occurs > 0)
  { fprintf(confc, "#include <%s.h>\n", symtab[i].name); }
 }
 fprintf(confc, "\n");
 fprintf(confc, "extern devcall ioerr(void);\n");
 fprintf(confc, "extern devcall ionull(void);\n\n");
 fprintf(confc, "/* device independent I/O switch */\n\n");
 if (ndevs > 0)
 {
  fprintf(confc, "const device devtab[NDEVS] =\n{\n");
  fprintf(confc, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n",
   "/**",
   " * Format of entries is:",
   " * dev-number, minor-number, dev-name,",
   " * init, open, close,",
   " * read, write, seek,",
   " * getc, putc, control,",
   " * dev-csr-address, intr-handler, irq",
   " */");
 }
 for (fcount = 0, s = devs; s != (struct dev_ent *)0x00; fcount++, s = s->next)
 {
  fprintf(confc, "/* %s is %s */\n", s->name, s->tname);
  fprintf(confc, "\t{ %d, %d, \"%s\",\n", fcount, s->minor, s->name);
  fprintf(confc, "\t  (void *)%s, (void *)%s, (void *)%s,\n",
          s->init, s->open, s->close);
  fprintf(confc, "\t  (void *)%s, (void *)%s, (void *)%s,\n",
          s->read, s->write, s->seek);
  fprintf(confc, "\t  (void *)%s, (void *)%s, (void *)%s,\n",
          s->getc, s->putc, s->control);
  fprintf(confc, "\t  (void *)0x%x, (void *)%s, %d }",
          s->csr, s->intr, s->irq);
  if ( s->next != (struct dev_ent *)0x00 ) { fprintf(confc, ",\n\n"); }
  else { fprintf(confc, "\n};"); }
 }
 fprintf(confc, "\n");
 fclose(confc);
 if (verbose)
 {
  printf("Configuration complete. Number of devs=%d:\n", ndevs);
  for (s = devs; s != (struct dev_ent *)0x00 ; s = s->next)
  {
   printf("Device %s (on %s)\n", s->name, s->device);
   printf("    csr=0x%04x, irq=0x%04x, minor=%d\n",
          s->csr, s->irq, s->minor);
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: n int

variable_types: i int

variable_types: fcount int

variable_types: verbose int

variable_types:
p
char *

variable_types: j int

variable_types:
name
char [20]


original_code:
static void swap_elements(void *_p1, void *_p2, size_t size)
{
    unsigned char *p1 = _p1;
    unsigned char *p2 = _p2;
    size_t i;
    unsigned char tmp;
    for (i = 0; i < size; i++)
    {
        tmp = p1[i];
        p1[i] = p2[i];
        p2[i] = tmp;
    }
}

canonical_original_code:
static void swap_elements(void *_p1, void *_p2, unsigned long size)
{
    unsigned char *p1 = _p1;
    unsigned char *p2 = _p2;
    unsigned long i;
    unsigned char tmp;
    for (i = 0; i < size; i++)
    {
        tmp = p1[i];
        p1[i] = p2[i];
        p2[i] = tmp;
    }
}

variable_types:
size
unsigned long

variable_types:
i
unsigned long

variable_types:
tmp
unsigned char


partition

original_code:
static size_t partition(void *base, size_t nmemb, size_t size,
                        int (*compar)(const void *, const void*))
{
    void *p1, *p2;
    size_t p1_index = 1;
    p1 = base + size;
    p2 = base + (nmemb * size);
    do
    {
        if ((*compar)(p1, base) <= 0)
        {
            p1 += size;
            p1_index++;
        }
        else
        {
            p2 -= size;
            swap_elements(p1, p2, size);
        }
    } while (p1 != p2);
    p1 -= size;
    p1_index--;
    swap_elements(p1, base, size);
    return p1_index;
}

canonical_original_code:
static unsigned long partition(void *base, unsigned long nmemb, unsigned long size, int (*compar)(void *, void *))
{
    void *p1; void *p2;
    unsigned long p1_index = 1;
    p1 = base + size;
    p2 = base + (nmemb * size);
    do
    {
        if ((*compar)(p1, base) <= 0)
        {
            p1 += size;
            p1_index++;
        }
        else
        {
            p2 -= size;
            swap_elements(p1, p2, size);
        }
    } while (p1 != p2);
    p1 -= size;
    p1_index--;
    swap_elements(p1, base, size);
    return p1_index;
}

variable_types:
base
void *

variable_types:
nmemb
unsigned long

variable_types:
compar
int (*)(void *, void *)

return_type: unsigned long


qsort

original_code:
void qsort(void *base, size_t nmemb, size_t size,
           int (*compar)(const void *, const void *))
{
    if (nmemb > 1)
    {
        size_t pivot_index = partition(base, nmemb, size, compar);
        qsort(base, pivot_index, size, compar);
        qsort(base + (pivot_index + 1) * size, nmemb - (pivot_index + 1),
              size, compar);
    }
}

canonical_original_code:
void qsort(void *base, unsigned long nmemb, unsigned long size, int (*compar)(void *, void *))
{
    if (nmemb > 1)
    {
        unsigned long pivot_index = partition(base, nmemb, size, compar);
        qsort(base, pivot_index, size, compar);
        qsort(base + (pivot_index + 1) * size, nmemb - (pivot_index + 1),
              size, compar);
    }
}


strlen

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

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

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

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

original_code:
size_t strlen(const char *s)
{
    size_t n = 0;
    while (s[n] != '\0')
    {
        n++;
    }
    return n;
}

canonical_original_code:
unsigned long strlen(char *s)
{
    unsigned long n = 0;
    while (s[n] != '\0')
    {
        n++;
    }
    return n;
}

variable_types:
s
char *

variable_types:
n
unsigned long


strlcpy

decompiled_code:
size_t __fastcall strlcpy(void *dest, void *src, __int64 a3)
{
size_t result; // rax
size_t v5; // r12
size_t v6; // rbx

result = strlen((const char *)src);
v5 = result;
if ( a3 )
{
v6 = a3 - 1;
if ( v6 > result )
v6 = result;
memcpy(dest, src, v6);
*((_BYTE *)dest + v6) = 0;
result = v5;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(void *dest, void *src, __int64 a3)
{
size_t result; // rax
size_t v5; // r12
size_t v6; // rbx

result = strlen((const char *)src);
v5 = result;
if ( a3 )
{
v6 = a3 - 1;
if ( v6 > result )
v6 = result;
memcpy(dest, src, v6);
*((_BYTE *)dest + v6) = 0;
result = v5;
}
return result;
}

original_code:
size_t strlcpy(char *dest, const char *src, size_t destsize)
{
    size_t srclen;
    size_t copylen;
    srclen = strlen(src);
    if (destsize != 0)
    {
        if (destsize - 1 < srclen)
        {
            copylen = destsize - 1;
        }
        else
        {
            copylen = srclen;
        }
        memcpy(dest, src, copylen);
        dest[copylen] = '\0';
    }
    return srclen;
}

canonical_original_code:
unsigned long strlcpy(char *dest, char *src, unsigned long destsize)
{
    unsigned long srclen;
    unsigned long copylen;
    srclen = strlen(src);
    if (destsize != 0)
    {
        if (destsize - 1 < srclen)
        {
            copylen = destsize - 1;
        }
        else
        {
            copylen = srclen;
        }
        memcpy(dest, src, copylen);
        dest[copylen] = '\0';
    }
    return srclen;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
destsize
unsigned long

variable_types:
srclen
unsigned long

variable_types:
copylen
unsigned long


labs

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

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

original_code:
long labs(long j)
{
    if (j < 0)
    {
        j = -j;
    }
    return j;
}

variable_types: j long

return_type: long


strnlen

decompiled_code:
unsigned __int64 __fastcall strnlen(_BYTE *a1, unsigned __int64 a2)
{
unsigned __int64 result; // rax

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

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

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

original_code:
size_t strnlen(const char *s, size_t maxlen)
{
    size_t n = 0;
    while (s[n] != '\0' && n < maxlen)
    {
        n++;
    }
    return n;
}

canonical_original_code:
unsigned long strnlen(char *s, unsigned long maxlen)
{
    unsigned long n = 0;
    while (s[n] != '\0' && n < maxlen)
    {
        n++;
    }
    return n;
}

variable_types:
maxlen
unsigned long


srand

decompiled_code:
void __fastcall srand(int a1)
{
seed = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
seed = a1;
}

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

variable_types:
x
unsigned int


rand

decompiled_code:
__int64 rand()
{
seed = 1103515245 * seed + 12345;
return HIWORD(seed);
}

canonical_decompiled_code:
__int64 func1()
{
seed = 1103515245 * seed + 12345;
return HIWORD(seed);
}


memcpy

original_code:
void *memcpy(void *dest, const void *src, size_t n)
{
    unsigned char *dest_p = dest;
    const unsigned char *src_p = src;
    size_t i;
    for (i = 0; i < n; i++)
    {
        dest_p[i] = src_p[i];
    }
    return dest;
}

canonical_original_code:
void *memcpy(void *dest, void *src, unsigned long n)
{
    unsigned char *dest_p = dest;
    unsigned char *src_p = src;
    unsigned long i;
    for (i = 0; i < n; i++)
    {
        dest_p[i] = src_p[i];
    }
    return dest;
}

variable_types:
dest
void *

variable_types:
src
void *

return_type: void *


yyparse

original_code:
int
yyparse (void)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    YYSTYPE yyvsa[200];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 4)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-17))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 276 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 46 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 3:
    { doing = "device definitions"; }
    break;
  case 9:
    { mktype((yyvsp[0].intval)); }
    break;
  case 10:
    {(yyval.intval) = currtname = cktname((yyvsp[-1].intval)); }
    break;
  case 11:
    { (yyval.intval) = currname = lookup((yyvsp[0].strval)); }
    break;
  case 14:
    { newattr(263, (yyvsp[0].intval)); }
    break;
  case 15:
    { newattr(264, (yyvsp[0].intval)); }
    break;
  case 16:
    { newattr(265, (yyvsp[0].intval)); }
    break;
  case 17:
    { newattr(267, (yyvsp[0].intval)); }
    break;
  case 18:
    { newattr(268, (yyvsp[0].intval)); }
    break;
  case 19:
    { newattr(266, (yyvsp[0].intval)); }
    break;
  case 20:
    { newattr(275, (yyvsp[0].intval)); }
    break;
  case 21:
    { newattr(276, (yyvsp[0].intval)); }
    break;
  case 22:
    { newattr(269, (yyvsp[0].intval)); }
    break;
  case 23:
    { newattr(270, (yyvsp[0].intval)); }
    break;
  case 24:
    { newattr(271, (yyvsp[0].intval)); }
    break;
  case 25:
    { newattr(272, (yyvsp[0].intval)); }
    break;
  case 29:
    { mkdev((yyvsp[-3].intval), (yyvsp[-1].intval), (yyvsp[0].intval)); }
    break;
  case 30:
    { (yyval.intval) = currdname = ckdname((yyvsp[0].intval)); }
    break;
  case 31:
    { (yyval.intval) = 0; }
    break;
  case 32:
    { (yyval.intval) = (yyvsp[0].intval); }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 22;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 46 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 276 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-17))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 46 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 276 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

canonical_original_code:
int yyparse()
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    union YYSTYPE yyvsa[200];
    union YYSTYPE *yyvs;
    union YYSTYPE *yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  union YYSTYPE yyval;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 4)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-17))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 276 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 46 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 3:
    { doing = "device definitions"; }
    break;
  case 9:
    { mktype((yyvsp[0].intval)); }
    break;
  case 10:
    {(yyval.intval) = currtname = cktname((yyvsp[-1].intval)); }
    break;
  case 11:
    { (yyval.intval) = currname = lookup((yyvsp[0].strval)); }
    break;
  case 14:
    { newattr(263, (yyvsp[0].intval)); }
    break;
  case 15:
    { newattr(264, (yyvsp[0].intval)); }
    break;
  case 16:
    { newattr(265, (yyvsp[0].intval)); }
    break;
  case 17:
    { newattr(267, (yyvsp[0].intval)); }
    break;
  case 18:
    { newattr(268, (yyvsp[0].intval)); }
    break;
  case 19:
    { newattr(266, (yyvsp[0].intval)); }
    break;
  case 20:
    { newattr(275, (yyvsp[0].intval)); }
    break;
  case 21:
    { newattr(276, (yyvsp[0].intval)); }
    break;
  case 22:
    { newattr(269, (yyvsp[0].intval)); }
    break;
  case 23:
    { newattr(270, (yyvsp[0].intval)); }
    break;
  case 24:
    { newattr(271, (yyvsp[0].intval)); }
    break;
  case 25:
    { newattr(272, (yyvsp[0].intval)); }
    break;
  case 29:
    { mkdev((yyvsp[-3].intval), (yyvsp[-1].intval), (yyvsp[0].intval)); }
    break;
  case 30:
    { (yyval.intval) = currdname = ckdname((yyvsp[0].intval)); }
    break;
  case 31:
    { (yyval.intval) = 0; }
    break;
  case 32:
    { (yyval.intval) = (yyvsp[0].intval); }
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 22;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 46 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 276 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror ("syntax error");
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-17))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 46 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror ("memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 276 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyssp
short *

variable_types: union YYSTYPE { int intval; char *strval; } [200]

variable_types: union YYSTYPE { int intval; char *strval; } *

variable_types:
yystacksize
unsigned long

variable_types: yyn int

variable_types: yyresult int

variable_types: yytoken int

variable_types: yylen int

variable_types:
yysize
unsigned long

variable_types: union yyalloc { short yyss_alloc; union YYSTYPE { int intval; char *strval; } yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: yylhs int

variable_types: yyi int

user_defined_types: union yyalloc { short yyss_alloc; union YYSTYPE yyvs_alloc; }


sgetch

decompiled_code:
__int64 __fastcall sgetch(__int64 a1, int a2)
{
unsigned __int8 *v2; // rdx
__int64 result; // rax

v2 = *(unsigned __int8 **)a2;
result = *v2;
if ( !(_BYTE)result )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = v2 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
unsigned __int8 *v2; // rdx
__int64 result; // rax

v2 = *(unsigned __int8 **)a2;
result = *v2;
if ( !(_BYTE)result )
return 0xFFFFFFFFLL;
*(_QWORD *)a2 = v2 + 1;
return result;
}

original_code:
static int sgetch(int _ignored, int _str_p)
{
    const char **str_p = (const char **)_str_p;
    const char *str = *str_p;
    int c;
    if (*str == '\0')
    {
        c = (-1);
    }
    else
    {
        c = (unsigned char)(*str);
        *str_p = ++str;
    }
    return c;
}

canonical_original_code:
static int sgetch(int _ignored, int _str_p)
{
    char **str_p = (const char **)_str_p;
    char *str = *str_p;
    int c;
    if (*str == '\0')
    {
        c = (-1);
    }
    else
    {
        c = (unsigned char)(*str);
        *str_p = ++str;
    }
    return c;
}

variable_types:
str
char *

variable_types: c int


sungetch

decompiled_code:
__int64 __fastcall sungetch(__int64 a1, int a2)
{
__int64 v2; // rax
unsigned int v3; // er8

v2 = *(_QWORD *)a2;
v3 = *(unsigned __int8 *)(v2 - 1);
*(_QWORD *)a2 = v2 - 1;
return v3;
}

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

v2 = *(_QWORD *)a2;
v3 = *(unsigned __int8 *)(v2 - 1);
*(_QWORD *)a2 = v2 - 1;
return v3;
}

original_code:
static int sungetch(int _ignored, int _str_p)
{
    const char **str_p = (const char**)_str_p;
    const char *str = *str_p;
    int c;
    str--;
    c = (unsigned char)(*str);
    *str_p = str;
    return c;
}

canonical_original_code:
static int sungetch(int _ignored, int _str_p)
{
    char **str_p = (const char**)_str_p;
    char *str = *str_p;
    int c;
    str--;
    c = (unsigned char)(*str);
    *str_p = str;
    return c;
}


abs

decompiled_code:
__int64 __fastcall abs(int a1)
{
return abs32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return abs32(a1);
}

original_code:
int abs(int j)
{
    if (j < 0)
    {
        j = -j;
    }
    return j;
}

variable_types: j int


strcmp

decompiled_code:
__int64 __fastcall strcmp(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // dl
int v3; // ecx
__int64 v4; // rax

v2 = *a1;
v3 = *a2;
v4 = 1LL;
if ( (_BYTE)v3 != *a1 )
return (unsigned int)v2 - v3;
while ( v2 )
{
v2 = a1[v4++];
v3 = a2[v4 - 1];
if ( v2 != (_BYTE)v3 )
return (unsigned int)v2 - v3;
}
return (unsigned int)-v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // dl
int v3; // ecx
__int64 v4; // rax

v2 = *a1;
v3 = *a2;
v4 = 1LL;
if ( (_BYTE)v3 != *a1 )
return (unsigned int)v2 - v3;
while ( v2 )
{
v2 = a1[v4++];
v3 = a2[v4 - 1];
if ( v2 != (_BYTE)v3 )
return (unsigned int)v2 - v3;
}
return (unsigned int)-v3;
}

original_code:
int strcmp(const char *s1, const char *s2)
{
    while (*s1 == *s2 && *s1 != '\0')
    {
        s1++;
        s2++;
    }
    return (int)(unsigned char)*s1 - (int)(unsigned char)*s2;
}

canonical_original_code:
int strcmp(char *s1, char *s2)
{
    while (*s1 == *s2 && *s1 != '\0')
    {
        s1++;
        s2++;
    }
    return (int)(unsigned char)*s1 - (int)(unsigned char)*s2;
}


bzero

decompiled_code:
void *__fastcall bzero(void *a1, size_t a2)
{
return memset(a1, 0, a2);
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, size_t a2)
{
return memset(a1, 0, a2);
}

original_code:
void bzero(void *s, size_t n)
{
    memset(s, 0, n);
}

canonical_original_code:
void bzero(void *s, unsigned long n)
{
    memset(s, 0, n);
}

variable_types:
s
void *

variable_types:
n
unsigned long


strstr

decompiled_code:
char *__fastcall strstr(char *s1, char *s2)
{
char *v2; // rbx
size_t v3; // rax
size_t v4; // r12

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
v4 = v3;
while ( strncmp(v2, s2, v4) )
{
if ( !*++v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *s1, char *s2)
{
char *v2; // rbx
size_t v3; // rax
size_t v4; // r12

v2 = s1;
v3 = strlen(s2);
if ( !*s1 )
return 0LL;
v4 = v3;
while ( strncmp(v2, s2, v4) )
{
if ( !*++v2 )
return 0LL;
}
return v2;
}

original_code:
char *strstr(const char *haystack, const char *needle)
{
    size_t needle_len = strlen(needle);
    for (; *haystack != '\0'; haystack++)
    {
        if (strncmp(haystack, needle, needle_len) == 0)
        {
            return (char*)haystack;
        }
    }
    return ((void *)0);
}

canonical_original_code:
char *strstr(char *haystack, char *needle)
{
    unsigned long needle_len = strlen(needle);
    for (; *haystack != '\0'; haystack++)
    {
        if (strncmp(haystack, needle, needle_len) == 0)
        {
            return (char *)haystack;
        }
    }
    return ((void *)0);
}

variable_types:
haystack
char *

variable_types:
needle
char *


sprntf

decompiled_code:
__int64 __fastcall sprntf(unsigned __int8 a1, int a2)
{
unsigned __int8 *v2; // rax

v2 = *(unsigned __int8 **)a2;
*v2 = a1;
*(_QWORD *)a2 = v2 + 1;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, int a2)
{
unsigned __int8 *v2; // rax

v2 = *(unsigned __int8 **)a2;
*v2 = a1;
*(_QWORD *)a2 = v2 + 1;
return a1;
}

original_code:
static int sprntf(int c, int _sptr)
{
    char **sptr = (char **)_sptr;
    char *s = *sptr;
    *s++ = c;
    *sptr = s;
    return (unsigned char)c;
}

variable_types:
sptr
char **

variable_types:
s
char *


sprintf

decompiled_code:
__int64 sprintf(_BYTE *a1, __int64 a2, ...)
{
_BYTE *v3; // [rsp+0h] [rbp-D8h] BYREF
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
v3 = a1;
doprnt(a2, va, sprntf, &v3);
*v3 = 0;
return v3 - a1;
}

canonical_decompiled_code:
__int64 func1(_BYTE *a1, __int64 a2, ...)
{
_BYTE *v3; // [rsp+0h] [rbp-D8h] BYREF
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
v3 = a1;
doprnt(a2, va, sprntf, &v3);
*v3 = 0;
return v3 - a1;
}

original_code:
int sprintf(char *str, const char *format, ...)
{
    va_list ap;
    char *s;
    s = str;
    __builtin_va_start(ap,format);
    _doprnt(format, ap, sprntf, (int)&s);
    __builtin_va_end(ap);
    *s = '\0';
    return s - str;
}

canonical_original_code:
int sprintf(char *str, char *format, ...)
{
    __builtin_va_list ap;
    char *s;
    s = str;
    __builtin_va_start(ap,format);
    _doprnt(format, ap, sprntf, (int)&s);
    __builtin_va_end(ap);
    *s = '\0';
    return s - str;
}

variable_types:
format
char *


atol

decompiled_code:
__int64 __fastcall atol(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
_isoc99_sscanf(a1, &unk_2A, &v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
_isoc99_sscanf(a1, &unk_2A, &v2);
return v2;
}

original_code:
long atol(const char *nptr)
{
    long n = 0;
    sscanf(nptr, "%ld", &n);
    return n;
}

canonical_original_code:
long atol(char *nptr)
{
    long n = 0;
    sscanf(nptr, "%ld", &n);
    return n;
}

variable_types:
nptr
char *

variable_types: n long


atoi

decompiled_code:
__int64 __fastcall atoi(const char *a1)
{
return atol(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
return atol(a1);
}

original_code:
int atoi(const char *nptr)
{
    return atol(nptr);
}

canonical_original_code:
int atoi(char *nptr)
{
    return atol(nptr);
}


printf

decompiled_code:
__int64 printf(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return doprnt(a1, va, &fputc, stdout);
}

canonical_decompiled_code:
__int64 func0(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return doprnt(a1, va, &fputc, stdout);
}

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

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

variable_types: ret int


strncpy

decompiled_code:
__int64 __fastcall strncpy(__int64 a1, char *a2, unsigned __int64 a3)
{
char v3; // al
unsigned __int64 v5; // rdi

v3 = *a2;
if ( *a2 )
{
if ( !a3 )
return a1;
v5 = 0LL;
while ( 1 )
{
*(_BYTE *)(a1 + v5++) = v3;
v3 = a2[v5];
if ( !v3 )
break;
if ( a3 == v5 )
return a1;
}
}
else
{
v5 = 0LL;
}
if ( a3 > v5 )
memset((void *)(a1 + v5), 0, a3 - v5);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2, unsigned __int64 a3)
{
char v3; // al
unsigned __int64 v5; // rdi

v3 = *a2;
if ( *a2 )
{
if ( !a3 )
return a1;
v5 = 0LL;
while ( 1 )
{
*(_BYTE *)(a1 + v5++) = v3;
v3 = a2[v5];
if ( !v3 )
break;
if ( a3 == v5 )
return a1;
}
}
else
{
v5 = 0LL;
}
if ( a3 > v5 )
memset((void *)(a1 + v5), 0, a3 - v5);
return a1;
}

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

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

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
i
unsigned long


memcmp

decompiled_code:
__int64 __fastcall memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
unsigned __int8 v6; // dl
int v7; // ecx

if ( !a3 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_BYTE *)(a1 + v5);
v7 = *(unsigned __int8 *)(a2 + v5);
if ( v6 != (_BYTE)v7 )
break;
if ( a3 == ++v5 )
return 0LL;
}
return (unsigned int)v6 - v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
unsigned __int8 v6; // dl
int v7; // ecx

if ( !a3 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_BYTE *)(a1 + v5);
v7 = *(unsigned __int8 *)(a2 + v5);
if ( v6 != (_BYTE)v7 )
break;
if ( a3 == ++v5 )
return 0LL;
}
return (unsigned int)v6 - v7;
}

original_code:
int memcmp(const void *s1, const void *s2, size_t n)
{
    const unsigned char *p1 = s1, *p2 = s2;
    size_t i;
    for (i = 0; i < n; i++)
    {
        if (p1[i] != p2[i])
        {
            return (int)p1[i] - (int)p2[i];
        }
    }
    return 0;
}

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


strncmp

decompiled_code:
__int64 __fastcall strncmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
unsigned __int8 v6; // dl
int v7; // ecx

if ( !a3 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_BYTE *)(a1 + v5);
v7 = *(unsigned __int8 *)(a2 + v5);
if ( !v6 )
return (unsigned int)-v7;
if ( v6 != (_BYTE)v7 )
break;
if ( a3 == ++v5 )
return 0LL;
}
return (unsigned int)v6 - v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rax
unsigned __int8 v6; // dl
int v7; // ecx

if ( !a3 )
return 0LL;
v5 = 0LL;
while ( 1 )
{
v6 = *(_BYTE *)(a1 + v5);
v7 = *(unsigned __int8 *)(a2 + v5);
if ( !v6 )
return (unsigned int)-v7;
if ( v6 != (_BYTE)v7 )
break;
if ( a3 == ++v5 )
return 0LL;
}
return (unsigned int)v6 - v7;
}

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

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


strncat

decompiled_code:
const char *__fastcall strncat(const char *a1, __int64 a2, __int64 a3)
{
const char *v5; // rcx
const char *v6; // rsi
__int64 v7; // rax
char v8; // dl
const char *result; // rax

v5 = &a1[strlen(a1)];
v6 = v5;
if ( a3 )
{
v7 = 0LL;
while ( 1 )
{
v8 = *(_BYTE *)(a2 + v7);
v6 = &v5[v7];
if ( !v8 )
break;
v5[v7++] = v8;
if ( a3 == v7 )
{
result = a1;
v5[a3] = 0;
return result;
}
}
}
*v6 = 0;
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1, __int64 a2, __int64 a3)
{
const char *v5; // rcx
const char *v6; // rsi
__int64 v7; // rax
char v8; // dl
const char *result; // rax

v5 = &a1[strlen(a1)];
v6 = v5;
if ( a3 )
{
v7 = 0LL;
while ( 1 )
{
v8 = *(_BYTE *)(a2 + v7);
v6 = &v5[v7];
if ( !v8 )
break;
v5[v7++] = v8;
if ( a3 == v7 )
{
result = a1;
v5[a3] = 0;
return result;
}
}
}
*v6 = 0;
return a1;
}

original_code:
char *strncat(char *dest, const char *src, size_t n)
{
    char *dest_save = dest;
    size_t i;
    dest = strchr(dest, '\0');
    for (i = 0; i < n && src[i] != '\0'; i++)
    {
        dest[i] = src[i];
    }
    dest[i] = '\0';
    return dest_save;
}

canonical_original_code:
char *strncat(char *dest, char *src, unsigned long n)
{
    char *dest_save = dest;
    unsigned long i;
    dest = strchr(dest, '\0');
    for (i = 0; i < n && src[i] != '\0'; i++)
    {
        dest[i] = src[i];
    }
    dest[i] = '\0';
    return dest_save;
}


clamp

repo: xjowest/linuxWebCam

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

result = 255LL;
if ( a1 <= 255 )
result = (unsigned int)a1;
if ( (int)result < 0 )
result = 0LL;
return result;
}

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

result = 255LL;
if ( a1 <= 255 )
result = (unsigned int)a1;
if ( (int)result < 0 )
result = 0LL;
return result;
}

original_code:
u8 clamp(int val)
{
  if(val < 0) val = 0;
  if(val > 255) val = 255;
  return (u8)val;
}

canonical_original_code:
unsigned char clamp(int val)
{
  if(val < 0) val = 0;
  if(val > 255) val = 255;
  return (unsigned char)val;
}

variable_types: val int

return_type: unsigned char


decompiled_code:
unsigned __int64 __fastcall YUV444toRGB(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3)
{
int v3; // esi
int v4; // edx
int v5; // ecx
int v6; // edx
char v7; // al
char v8; // cl
unsigned __int8 v9; // r8
unsigned __int16 v11; // [rsp+Dh] [rbp-3h]

v3 = a2 - 128;
clamp((298 * (a1 - 16) + 409 * (a3 - 128) + 128) >> 8);
clamp((v4 - 100 * v3 + v5 + 128) >> 8);
v7 = clamp((v6 + 516 * v3 + 128) >> 8);
HIBYTE(v11) = v8;
LOBYTE(v11) = v7;
return v11 | ((unsigned __int64)v9 << 16);
}

canonical_original_code:
struct RGB YUV444toRGB(unsigned char y, unsigned char u, unsigned char v)
{
  int a; int b; int c;
  struct RGB rgb;
  a = y - 16;
  b = u - 128;
  c = v - 128;
  rgb.B = clamp((298*a + 409*c + 128) >> 8);
  rgb.G = clamp((298*a - 100*b - 208*c + 128) >> 8);
  rgb.R = clamp((298*a + 516*b + 128) >> 8);
  return rgb;
}

variable_types:
y
unsigned char

variable_types:
u
unsigned char

variable_types:
v
unsigned char

variable_types: a int

variable_types: b int

variable_types: struct RGB { unsigned char R; unsigned char G; unsigned char B; }


original_code:
void convertFrame2RGB(u8 * rgb_buf)
{
  int i;
  static struct RGB rgb1;
  static struct RGB rgb2;
  int indexYuv;
  int indexRgb;
  u8 * pixel_p = (u8*)buffers[0].start;
  for(i=0;i<buffers[0].length / 4 - 4;i++){
    indexYuv = i*4;
    indexRgb = i*6;
    rgb1 = YUV444toRGB(pixel_p[indexYuv + 0],
         pixel_p[indexYuv + 1],
         pixel_p[indexYuv + 3]);
    rgb2 = YUV444toRGB(pixel_p[indexYuv + 2],
         pixel_p[indexYuv + 1],
         pixel_p[indexYuv + 3]);
    rgb_buf[indexRgb+0] = rgb1.R;
    rgb_buf[indexRgb+1] = rgb1.G;
    rgb_buf[indexRgb+2] = rgb1.B;
    rgb_buf[indexRgb+3] = rgb2.R;
    rgb_buf[indexRgb+4] = rgb2.G;
    rgb_buf[indexRgb+5] = rgb2.B;
  }
}

canonical_original_code:
void convertFrame2RGB(unsigned char *rgb_buf)
{
  int i;
  static struct RGB rgb1;
  static struct RGB rgb2;
  int indexYuv;
  int indexRgb;
  unsigned char *pixel_p = (u8*)buffers[0].start;
  for(i=0;i<buffers[0].length / 4 - 4;i++){
    indexYuv = i*4;
    indexRgb = i*6;
    rgb1 = YUV444toRGB(pixel_p[indexYuv + 0],
         pixel_p[indexYuv + 1],
         pixel_p[indexYuv + 3]);
    rgb2 = YUV444toRGB(pixel_p[indexYuv + 2],
         pixel_p[indexYuv + 1],
         pixel_p[indexYuv + 3]);
    rgb_buf[indexRgb+0] = rgb1.R;
    rgb_buf[indexRgb+1] = rgb1.G;
    rgb_buf[indexRgb+2] = rgb1.B;
    rgb_buf[indexRgb+3] = rgb2.R;
    rgb_buf[indexRgb+4] = rgb2.G;
    rgb_buf[indexRgb+5] = rgb2.B;
  }
}

variable_types: i int

variable_types: indexYuv int

variable_types: indexRgb int

user_defined_types: struct RGB { unsigned char R; unsigned char G; unsigned char B; }


gethostbyname

decompiled_code:
__int64 __fastcall gethostbyname(const char *a1)
{
unsigned int v1; // er12
FILE *v2; // rax

if ( !lib_gethostbyname_2 )
lib_gethostbyname_2 = (__int64 (__fastcall *)(_QWORD))_my_loadfun("gethostbyname");
v1 = getpid();
v2 = _my_getlog();
fprintf(v2, "Process %d is resolving (gethostbyname): %s\n", v1, a1);
return lib_gethostbyname_2(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
unsigned int v1; // er12
FILE *v2; // rax

if ( !lib_gethostbyname_2 )
lib_gethostbyname_2 = (__int64 (__fastcall *)(_QWORD))func7("gethostbyname");
v1 = getpid();
v2 = func6();
fprintf(v2, "Process %d is resolving (gethostbyname): %s\n", v1, a1);
return lib_gethostbyname_2(a1);
}

original_code:
__attribute__((visibility("default")))
struct hostent *gethostbyname(const char *name)
{
 static struct hostent *(*lib_gethostbyname)
  (const char *name) = ((void *)0);
 if (!lib_gethostbyname) {
  lib_gethostbyname = __my_loadfun("gethostbyname");
 }
 fprintf(__my_getlog(), "Process %d is resolving (gethostbyname): %s\n",
  getpid(), name);
 return lib_gethostbyname(name);
}

canonical_original_code:
struct hostent *gethostbyname(char *name)
{
 static struct hostent *(*lib_gethostbyname)(char *name) = ((void *)0);
 if (!lib_gethostbyname) {
  lib_gethostbyname = __my_loadfun("gethostbyname");
 }
 fprintf(__my_getlog(), "Process %d is resolving (gethostbyname): %s\n",
  getpid(), name);
 return lib_gethostbyname(name);
}

variable_types:
name
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *(*)(char *name)


random

decompiled_code:
__int64 random()
{
return _my_random();
}

canonical_decompiled_code:
__int64 func7()
{
return func6();
}

original_code:
__attribute__((visibility("default")))
long int random(void)
{
 return __my_random();
}

canonical_original_code:
long random()
{
 return __my_random();
}


srandom

decompiled_code:
int __fastcall srandom(unsigned int a1)
{
return fprintf(stderr, "Ignoring random seed: %u\n", a1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1)
{
return fprintf(stderr, "Ignoring random seed: %u\n", a1);
}

original_code:
__attribute__((visibility("default")))
void srandom(unsigned int seed)
{
 fprintf(stderr, "Ignoring random seed: %u\n", seed);
}

variable_types:
seed
unsigned int


decompiled_code:
__int64 SDL_WM_GrabInput()
{
if ( !lib_SDL_WM_GrabInput_0 )
lib_SDL_WM_GrabInput_0 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "SDL_WM_GrabInput");
return lib_SDL_WM_GrabInput_0(0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 func6()
{
if ( !lib_SDL_WM_GrabInput_0 )
lib_SDL_WM_GrabInput_0 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "SDL_WM_GrabInput");
return lib_SDL_WM_GrabInput_0(0xFFFFFFFFLL);
}

original_code:
__attribute__((visibility("default")))
SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode __attribute__((unused)))
{
        static SDL_GrabMode (*lib_SDL_WM_GrabInput) (SDL_GrabMode mode) = ((void *)0);
        if (!lib_SDL_WM_GrabInput) {
                lib_SDL_WM_GrabInput = dlsym(((void *) -1l), "SDL_WM_GrabInput");
        }
        return lib_SDL_WM_GrabInput(SDL_GRAB_QUERY);
}

canonical_original_code:
enum SDL_GrabMode SDL_WM_GrabInput(enum SDL_GrabMode mode)
{
        static enum SDL_GrabMode (*lib_SDL_WM_GrabInput)(enum SDL_GrabMode mode) = ((void *)0);
        if (!lib_SDL_WM_GrabInput) {
                lib_SDL_WM_GrabInput = dlsym(((void *) -1l), "SDL_WM_GrabInput");
        }
        return lib_SDL_WM_GrabInput(SDL_GRAB_QUERY);
}

variable_types: enum SDL_GrabMode { SDL_GRAB_QUERY=-1, SDL_GRAB_OFF=0, SDL_GRAB_ON=1, SDL_GRAB_FULLSCREEN=2 } (*)(enum SDL_GrabMode { SDL_GRAB_QUERY=-1, SDL_GRAB_OFF=0, SDL_GRAB_ON=1, SDL_GRAB_FULLSCREEN=2 } mode)


decompiled_code:
__int64 SDL_ShowCursor()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 1LL;
}

original_code:
__attribute__((visibility("default")))
int SDL_ShowCursor(int i __attribute__((unused)))
{
     return 1;
}

canonical_original_code:
int SDL_ShowCursor(int i)
{
     return 1;
}