decompiled_code:
_QWORD *list_add_last_test()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *result; // rax

v0 = (_QWORD *)linked_list_int_create();
linked_list_int_add_last(v0, 1LL);
v1 = (_QWORD *)v0[1];
if ( v1 != (_QWORD *)v0[2] )
__assert_fail("list -> node_first == list -> node_last", "test.c", 0x3Du, "list_add_last_test");
if ( !v1 )
__assert_fail("list -> node_first != NULL", "test.c", 0x3Eu, "list_add_last_test");
if ( *v0 != 1LL )
__assert_fail("list -> count == 1", "test.c", 0x3Fu, "list_add_last_test");
if ( *v1 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x41u, "list_add_last_test");
if ( v1[1] )
__assert_fail("list -> node_first -> next == NULL", "test.c", 0x42u, "list_add_last_test");
linked_list_int_add_last(v0, 2LL);
v2 = (_QWORD *)v0[1];
if ( !v2 )
__assert_fail("list -> node_first != NULL", "test.c", 0x46u, "list_add_last_test");
result = (_QWORD *)v0[2];
if ( !result )
__assert_fail("list -> node_last != NULL", "test.c", 0x47u, "list_add_last_test");
if ( *v0 != 2LL )
__assert_fail("list -> count == 2", "test.c", 0x48u, "list_add_last_test");
if ( v2 == result )
__assert_fail("list -> node_first != list -> node_last", "test.c", 0x4Au, "list_add_last_test");
if ( *v2 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x4Cu, "list_add_last_test");
if ( result != (_QWORD *)v2[1] )
__assert_fail("list -> node_first -> next == list -> node_last", "test.c", 0x4Du, "list_add_last_test");
if ( *result != 2LL )
__assert_fail("list -> node_last -> value == value2", "test.c", 0x4Eu, "list_add_last_test");
if ( result[1] )
__assert_fail("list -> node_last -> next == NULL", "test.c", 0x4Fu, "list_add_last_test");
return result;
}

canonical_decompiled_code:
_QWORD *func9()
{
_QWORD *v0; // rbx
_QWORD *v1; // rax
_QWORD *v2; // rdx
_QWORD *result; // rax

v0 = (_QWORD *)func10();
func12(v0, 1LL);
v1 = (_QWORD *)v0[1];
if ( v1 != (_QWORD *)v0[2] )
__assert_fail("list -> node_first == list -> node_last", "test.c", 0x3Du, "list_add_last_test");
if ( !v1 )
__assert_fail("list -> node_first != NULL", "test.c", 0x3Eu, "list_add_last_test");
if ( *v0 != 1LL )
__assert_fail("list -> count == 1", "test.c", 0x3Fu, "list_add_last_test");
if ( *v1 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x41u, "list_add_last_test");
if ( v1[1] )
__assert_fail("list -> node_first -> next == NULL", "test.c", 0x42u, "list_add_last_test");
func12(v0, 2LL);
v2 = (_QWORD *)v0[1];
if ( !v2 )
__assert_fail("list -> node_first != NULL", "test.c", 0x46u, "list_add_last_test");
result = (_QWORD *)v0[2];
if ( !result )
__assert_fail("list -> node_last != NULL", "test.c", 0x47u, "list_add_last_test");
if ( *v0 != 2LL )
__assert_fail("list -> count == 2", "test.c", 0x48u, "list_add_last_test");
if ( v2 == result )
__assert_fail("list -> node_first != list -> node_last", "test.c", 0x4Au, "list_add_last_test");
if ( *v2 != 1LL )
__assert_fail("list -> node_first -> value == value1", "test.c", 0x4Cu, "list_add_last_test");
if ( result != (_QWORD *)v2[1] )
__assert_fail("list -> node_first -> next == list -> node_last", "test.c", 0x4Du, "list_add_last_test");
if ( *result != 2LL )
__assert_fail("list -> node_last -> value == value2", "test.c", 0x4Eu, "list_add_last_test");
if ( result[1] )
__assert_fail("list -> node_last -> next == NULL", "test.c", 0x4Fu, "list_add_last_test");
return result;
}

original_code:
void list_add_last_test()
{
    linked_list_int_t *list;
    int64_t value1 = 1;
    int64_t value2 = 2;
    list = linked_list_int_create();
    linked_list_int_add_last(list, value1);
    ((void) sizeof ((list -> node_first == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first == list -> node_last) ; else __assert_fail ("list -> node_first == list -> node_last", "test.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 1) ? 1 : 0), __extension__ ({ if (list -> count == 1) ; else __assert_fail ("list -> count == 1", "test.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == ((void *)0)) ; else __assert_fail ("list -> node_first -> next == NULL", "test.c", 66, __extension__ __PRETTY_FUNCTION__); }));
    linked_list_int_add_last(list, value2);
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 70, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last != ((void *)0)) ; else __assert_fail ("list -> node_last != NULL", "test.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 2) ? 1 : 0), __extension__ ({ if (list -> count == 2) ; else __assert_fail ("list -> count == 2", "test.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first != list -> node_last) ; else __assert_fail ("list -> node_first != list -> node_last", "test.c", 74, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == list -> node_last) ; else __assert_fail ("list -> node_first -> next == list -> node_last", "test.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> value == value2) ? 1 : 0), __extension__ ({ if (list -> node_last -> value == value2) ; else __assert_fail ("list -> node_last -> value == value2", "test.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last -> next == ((void *)0)) ; else __assert_fail ("list -> node_last -> next == NULL", "test.c", 79, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
void list_add_last_test()
{
    struct linked_list_int_head *list;
    long value1 = 1;
    long value2 = 2;
    list = linked_list_int_create();
    linked_list_int_add_last(list, value1);
    ((void) sizeof ((list -> node_first == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first == list -> node_last) ; else __assert_fail ("list -> node_first == list -> node_last", "test.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 1) ? 1 : 0), __extension__ ({ if (list -> count == 1) ; else __assert_fail ("list -> count == 1", "test.c", 63, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 65, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == ((void *)0)) ; else __assert_fail ("list -> node_first -> next == NULL", "test.c", 66, __extension__ __PRETTY_FUNCTION__); }));
    linked_list_int_add_last(list, value2);
    ((void) sizeof ((list -> node_first != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_first != ((void *)0)) ; else __assert_fail ("list -> node_first != NULL", "test.c", 70, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last != ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last != ((void *)0)) ; else __assert_fail ("list -> node_last != NULL", "test.c", 71, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> count == 2) ? 1 : 0), __extension__ ({ if (list -> count == 2) ; else __assert_fail ("list -> count == 2", "test.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first != list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first != list -> node_last) ; else __assert_fail ("list -> node_first != list -> node_last", "test.c", 74, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> value == value1) ? 1 : 0), __extension__ ({ if (list -> node_first -> value == value1) ; else __assert_fail ("list -> node_first -> value == value1", "test.c", 76, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_first -> next == list -> node_last) ? 1 : 0), __extension__ ({ if (list -> node_first -> next == list -> node_last) ; else __assert_fail ("list -> node_first -> next == list -> node_last", "test.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> value == value2) ? 1 : 0), __extension__ ({ if (list -> node_last -> value == value2) ; else __assert_fail ("list -> node_last -> value == value2", "test.c", 78, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((list -> node_last -> next == ((void *)0)) ? 1 : 0), __extension__ ({ if (list -> node_last -> next == ((void *)0)) ; else __assert_fail ("list -> node_last -> next == NULL", "test.c", 79, __extension__ __PRETTY_FUNCTION__); }));
}


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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

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

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
}
return result;
}

original_code:
linked_list_int_t * linked_list_int_create()
{
    linked_list_int_t *list = malloc(sizeof(struct linked_list_int_head));
    if (list != ((void *)0))
    {
        list -> count = 0;
        list -> node_first = ((void *)0);
        list -> node_last = ((void *)0);
    }
    return list;
}

canonical_original_code:
struct linked_list_int_head *linked_list_int_create()
{
    struct linked_list_int_head *list = malloc(sizeof(struct linked_list_int_head));
    if (list != ((void *)0))
    {
        list -> count = 0;
        list -> node_first = ((void *)0);
        list -> node_last = ((void *)0);
    }
    return list;
}

variable_types: struct linked_list_int_head { long count; struct linked_list_int_node { long value; struct linked_list_int_node *next; } *node_first; struct linked_list_int_node *node_last; } *

user_defined_types: struct linked_list_int_head { long count; struct linked_list_int_node *node_first; struct linked_list_int_node *node_last; }


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

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = a1[1];
*v2 = a2;
if ( v3 )
{
v2[1] = v3;
a1[1] = v2;
}
else
{
v2[1] = 0LL;
a1[1] = v2;
a1[2] = v2;
}
++*a1;
return 0LL;
}

original_code:
int32_t linked_list_int_add_first(linked_list_int_t *list, int64_t value)
{
    linked_list_int_node_t *new_node = malloc(sizeof(linked_list_int_node_t));
    int32_t result;
    if (new_node != ((void *)0))
    {
        new_node -> value = value;
        if (list -> node_first == ((void *)0))
        {
            new_node -> next = ((void *)0);
            list -> node_first = new_node;
            list -> node_last = new_node;
        }
        else
        {
            new_node -> next = list -> node_first;
            list -> node_first = new_node;
        }
        list -> count += 1;
        result = 0;
    }
    else
    {
        result = -1;
    }
    return result;
}

canonical_original_code:
int linked_list_int_add_first(struct linked_list_int_head *list, long value)
{
    struct linked_list_int_node *new_node = malloc(sizeof(linked_list_int_node_t));
    int result;
    if (new_node != ((void *)0))
    {
        new_node -> value = value;
        if (list -> node_first == ((void *)0))
        {
            new_node -> next = ((void *)0);
            list -> node_first = new_node;
            list -> node_last = new_node;
        }
        else
        {
            new_node -> next = list -> node_first;
            list -> node_first = new_node;
        }
        list -> count += 1;
        result = 0;
    }
    else
    {
        result = -1;
    }
    return result;
}

variable_types: value long

variable_types: struct linked_list_int_node { long value; struct linked_list_int_node *next; } *

variable_types: result int

return_type: int


decompiled_code:
__int64 __fastcall linked_list_int_add_last(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = a1[1] == 0LL;
*v2 = a2;
v2[1] = 0LL;
if ( v3 )
a1[1] = v2;
else
*(_QWORD *)(a1[2] + 8LL) = v2;
a1[2] = v2;
++*a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
bool v3; // zf

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = a1[1] == 0LL;
*v2 = a2;
v2[1] = 0LL;
if ( v3 )
a1[1] = v2;
else
*(_QWORD *)(a1[2] + 8LL) = v2;
a1[2] = v2;
++*a1;
return 0LL;
}

original_code:
int32_t linked_list_int_add_last(linked_list_int_t *list, int64_t value)
{
    linked_list_int_node_t *new_node = malloc(sizeof(linked_list_int_node_t));
    int32_t result;
    if (new_node != ((void *)0))
    {
        new_node -> value = value;
        new_node -> next = ((void *)0);
        if (list -> node_first == ((void *)0))
        {
            list -> node_first = new_node;
            list -> node_last = new_node;
        }
        else
        {
            list -> node_last -> next = new_node;
            list -> node_last = new_node;
        }
        list -> count += 1;
        result = 0;
    }
    else
    {
        result = -1;
    }
    return result;
}

canonical_original_code:
int linked_list_int_add_last(struct linked_list_int_head *list, long value)
{
    struct linked_list_int_node *new_node = malloc(sizeof(linked_list_int_node_t));
    int result;
    if (new_node != ((void *)0))
    {
        new_node -> value = value;
        new_node -> next = ((void *)0);
        if (list -> node_first == ((void *)0))
        {
            list -> node_first = new_node;
            list -> node_last = new_node;
        }
        else
        {
            list -> node_last -> next = new_node;
            list -> node_last = new_node;
        }
        list -> count += 1;
        result = 0;
    }
    else
    {
        result = -1;
    }
    return result;
}

user_defined_types: struct linked_list_int_node { long value; struct linked_list_int_node *next; }


decompiled_code:
int __fastcall linked_list_int_print(__int64 a1)
{
_QWORD *v1; // rbx
int result; // eax

v1 = *(_QWORD **)(a1 + 8);
for ( result = putchar(76); v1; v1 = (_QWORD *)v1[1] )
{
printf("-|");
printf("%ld", *v1);
result = putchar(124);
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
_QWORD *v1; // rbx
int result; // eax

v1 = *(_QWORD **)(a1 + 8);
for ( result = putchar(76); v1; v1 = (_QWORD *)v1[1] )
{
printf("-|");
printf("%ld", *v1);
result = putchar(124);
}
return result;
}

original_code:
void linked_list_int_print(linked_list_int_t *list)
{
    linked_list_int_node_t *list_node = list -> node_first;
    printf("L");
    while (list_node != ((void *)0))
    {
        printf("-|");
        printf("%ld", list_node -> value);
        printf("|");
        list_node = list_node -> next;
    }
}

canonical_original_code:
void linked_list_int_print(struct linked_list_int_head *list)
{
    struct linked_list_int_node *list_node = list -> node_first;
    printf("L");
    while (list_node != ((void *)0))
    {
        printf("-|");
        printf("%ld", list_node -> value);
        printf("|");
        list_node = list_node -> next;
    }
}

return_type: void


repo: aboreak/KISS-Engine

decompiled_code:
int __fastcall output_error(int a1, int a2, int a3, const char *a4, void *a5)
{
char *v6; // rax
const char *v7; // rcx
char v9[512]; // [rsp+0h] [rbp-618h] BYREF
char s[512]; // [rsp+200h] [rbp-418h] BYREF
char v11[536]; // [rsp+400h] [rbp-218h] BYREF

vsnprintf(s, 0x1F4uLL, a4, a5);
if ( a1 )
{
v6 = strerror(a2);
v7 = "?UNKNOWN?";
if ( (unsigned int)(a2 - 1) <= 0x84 )
v7 = (const char *)*(&ename + a2);
snprintf(v11, 0x1F4uLL, " [%s %s]", v7, v6);
}
else
{
strcpy(v11, ":");
}
snprintf(v9, 0x1F4uLL, "ERROR%s %s\n", v11, s);
if ( a3 )
fflush(stdout);
fputs(v9, stderr);
return fflush(stderr);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, int a3, const char *a4, void *a5)
{
char *v6; // rax
const char *v7; // rcx
char v9[512]; // [rsp+0h] [rbp-618h] BYREF
char s[512]; // [rsp+200h] [rbp-418h] BYREF
char v11[536]; // [rsp+400h] [rbp-218h] BYREF

vsnprintf(s, 0x1F4uLL, a4, a5);
if ( a1 )
{
v6 = strerror(a2);
v7 = "?UNKNOWN?";
if ( (unsigned int)(a2 - 1) <= 0x84 )
v7 = (const char *)*(&ename + a2);
snprintf(v11, 0x1F4uLL, " [%s %s]", v7, v6);
}
else
{
strcpy(v11, ":");
}
snprintf(v9, 0x1F4uLL, "ERROR%s %s\n", v11, s);
if ( a3 )
fflush(stdout);
fputs(v9, stderr);
return fflush(stderr);
}

original_code:
static void output_error(int use_err, int err, int flush_stdout,
    const char *format, va_list ap)
{
 char buf[500];
 char user_msg[500];
 char err_text[500];
 vsnprintf(user_msg, 500, format, ap);
 if (use_err)
  snprintf(err_text, 500, " [%s %s]",
    (err > 0 && err <= 133) ?
    ename[err] : "?UNKNOWN?", strerror(err));
 else
  snprintf(err_text, 500, ":");
 snprintf(buf, 500, "ERROR%s %s\n", err_text, user_msg);
 if (flush_stdout)
  fflush(stdout);
 fputs(buf, stderr);
 fflush(stderr);
}

canonical_original_code:
static void output_error(int use_err, int err, int flush_stdout, char *format, __builtin_va_list ap)
{
 char buf[500];
 char user_msg[500];
 char err_text[500];
 vsnprintf(user_msg, 500, format, ap);
 if (use_err)
  snprintf(err_text, 500, " [%s %s]",
    (err > 0 && err <= 133) ?
    ename[err] : "?UNKNOWN?", strerror(err));
 else
  snprintf(err_text, 500, ":");
 snprintf(buf, 500, "ERROR%s %s\n", err_text, user_msg);
 if (flush_stdout)
  fflush(stdout);
 fputs(buf, stderr);
 fflush(stderr);
}

variable_types: err int

variable_types:
format
char *

variable_types:
buf
char [500]


terminate

decompiled_code:
void __fastcall __noreturn terminate(int a1)
{
char *v1; // rax

v1 = getenv("EF_DUMPCORE");
if ( !v1 || !*v1 )
{
if ( a1 )
exit(1);
exit(1);
}
terminate_cold();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(int a1)
{
char *v1; // rax

v1 = getenv("EF_DUMPCORE");
if ( !v1 || !*v1 )
{
if ( a1 )
exit(1);
exit(1);
}
func9();
}

original_code:
__attribute__ ((__noreturn__))
static void terminate(int use_exit3)
{
 char *s = getenv("EF_DUMPCORE");
 if (s != ((void *)0) && *s != '\0')
  abort();
 else if (use_exit3)
  exit(1);
 else
  _exit(1);
}

variable_types:
s
char *


decompiled_code:
int err_msg(const char *a1, ...)
{
int *v1; // rax
int v2; // ebp
int *v3; // rbx
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = _errno_location();
v2 = *v1;
v3 = v1;
result = output_error(1, *v1, 1, a1, va);
*v3 = v2;
return result;
}

canonical_decompiled_code:
int func2(const char *a1, ...)
{
int *v1; // rax
int v2; // ebp
int *v3; // rbx
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = _errno_location();
v2 = *v1;
v3 = v1;
result = func0(1, *v1, 1, a1, va);
*v3 = v2;
return result;
}

original_code:
void err_msg(const char *format, ...)
{
 va_list arg_list;
 int saved_errno = (*__errno_location ());
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (1), format, arg_list);
 __builtin_va_end(arg_list);
 (*__errno_location ()) = saved_errno;
}

canonical_original_code:
void err_msg(char *format, ...)
{
 __builtin_va_list arg_list;
 int saved_errno = (*__errno_location ());
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (1), format, arg_list);
 __builtin_va_end(arg_list);
 (*__errno_location ()) = saved_errno;
}


decompiled_code:
void __noreturn err_exit(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
output_error(1, *v1, 1, a1, va);
terminate(1);
}

canonical_decompiled_code:
void __noreturn func3(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
func0(1, *v1, 1, a1, va);
func1(1);
}

original_code:
void err_exit(const char *format, ...)
{
 va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((1));
}

canonical_original_code:
void err_exit(char *format, ...)
{
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((1));
}


decompiled_code:
void __noreturn err_exit2(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
output_error(1, *v1, 0, a1, va);
terminate(0);
}

canonical_decompiled_code:
void __noreturn func4(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
func0(1, *v1, 0, a1, va);
func1(0);
}

original_code:
void err_exit2(const char *format, ...)
{
 va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (!(1)), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}

canonical_original_code:
void err_exit2(char *format, ...)
{
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), (*__errno_location ()), (!(1)), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}


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

va_start(va, a2);
output_error(1, a1, 1, a2, va);
terminate(0);
}

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

va_start(va, a2);
func0(1, a1, 1, a2, va);
func1(0);
}

original_code:
void err_exit_en(int errnum, const char *format, ...)
{
 va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), errnum, (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}

canonical_original_code:
void err_exit_en(int errnum, char *format, ...)
{
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((1), errnum, (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}

variable_types: errnum int


fatal

decompiled_code:
void __noreturn fatal(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
output_error(0, 0, 1, a1, va);
terminate(0);
}

canonical_decompiled_code:
void __noreturn func6(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(0, 0, 1, a1, va);
func1(0);
}

original_code:
void fatal(const char *format, ...)
{
 va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((!(1)), 0, (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}

canonical_original_code:
void fatal(char *format, ...)
{
 __builtin_va_list arg_list;
 __builtin_va_start(arg_list,format);
 output_error((!(1)), 0, (1), format, arg_list);
 __builtin_va_end(arg_list);
 terminate((!(1)));
}


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

va_start(arg, format);
fflush(stdout);
fwrite("Usage: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

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

va_start(arg, format);
fflush(stdout);
fwrite("Usage: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

original_code:
void err_usage(const char *format, ...)
{
 va_list arg_list;
 fflush(stdout);
 fprintf(stderr, "Usage: ");
 __builtin_va_start(arg_list,format);
 vfprintf(stderr, format, arg_list);
 __builtin_va_end(arg_list);
 fflush(stderr);
 exit(1);
}

canonical_original_code:
void err_usage(char *format, ...)
{
 __builtin_va_list arg_list;
 fflush(stdout);
 fprintf(stderr, "Usage: ");
 __builtin_va_start(arg_list,format);
 vfprintf(stderr, format, arg_list);
 __builtin_va_end(arg_list);
 fflush(stderr);
 exit(1);
}


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

va_start(arg, format);
fflush(stdout);
fwrite("Command-line usage error: ", 1uLL, 0x1AuLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

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

va_start(arg, format);
fflush(stdout);
fwrite("Command-line usage error: ", 1uLL, 0x1AuLL, stderr);
vfprintf(stderr, format, arg);
fflush(stderr);
exit(1);
}

original_code:
void err_cmdline(const char *format, ...)
{
 va_list arg_list;
 fflush(stdout);
 fprintf(stderr, "Command-line usage error: ");
 __builtin_va_start(arg_list,format);
 vfprintf(stderr, format, arg_list);
 __builtin_va_end(arg_list);
 fflush(stderr);
 exit(1);
}

canonical_original_code:
void err_cmdline(char *format, ...)
{
 __builtin_va_list arg_list;
 fflush(stdout);
 fprintf(stderr, "Command-line usage error: ");
 __builtin_va_start(arg_list,format);
 vfprintf(stderr, format, arg_list);
 __builtin_va_end(arg_list);
 fflush(stderr);
 exit(1);
}


repo: absabs/init

decompiled_code:
__int64 __fastcall get_device_perm_inner(const char **a1, const char *a2, _DWORD *a3, _DWORD *a4, _DWORD *a5)
{
const char *v5; // rbp
const char **v6; // rbx
size_t v10; // rax

v5 = *a1;
if ( *a1 )
{
v6 = a1;
do
{
if ( *((_WORD *)v6 + 10) )
{
v10 = strlen(v5);
if ( !strncmp(a2, v5, v10) )
goto LABEL_5;
}
else if ( !strcmp(a2, v5) )
{
LABEL_5:
*a3 = *((_DWORD *)v6 + 3);
*a4 = *((_DWORD *)v6 + 4);
*a5 = *((_DWORD *)v6 + 2);
return 0LL;
}
v5 = v6[3];
v6 += 3;
}
while ( v5 );
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1, const char *a2, _DWORD *a3, _DWORD *a4, _DWORD *a5)
{
const char *v5; // rbp
const char **v6; // rbx
size_t v10; // rax

v5 = *a1;
if ( *a1 )
{
v6 = a1;
do
{
if ( *((_WORD *)v6 + 10) )
{
v10 = strlen(v5);
if ( !strncmp(a2, v5, v10) )
goto LABEL_5;
}
else if ( !strcmp(a2, v5) )
{
LABEL_5:
*a3 = *((_DWORD *)v6 + 3);
*a4 = *((_DWORD *)v6 + 4);
*a5 = *((_DWORD *)v6 + 2);
return 0LL;
}
v5 = v6[3];
v6 += 3;
}
while ( v5 );
}
return 0xFFFFFFFFLL;
}

original_code:
static int get_device_perm_inner(struct perms_ *perms, const char *path,
                                    unsigned *uid, unsigned *gid, mode_t *perm)
{
    int i;
    for(i = 0; perms[i].name; i++) {
        if(perms[i].prefix) {
            if(strncmp(path, perms[i].name, strlen(perms[i].name)))
                continue;
        } else {
            if(strcmp(path, perms[i].name))
                continue;
        }
        *uid = perms[i].uid;
        *gid = perms[i].gid;
        *perm = perms[i].perm;
        return 0;
    }
    return -1;
}

canonical_original_code:
static int get_device_perm_inner(struct perms_ *perms, char *path, unsigned int *uid, unsigned int *gid, unsigned int *perm)
{
    int i;
    for(i = 0; perms[i].name; i++) {
        if(perms[i].prefix) {
            if(strncmp(path, perms[i].name, strlen(perms[i].name)))
                continue;
        } else {
            if(strcmp(path, perms[i].name))
                continue;
        }
        *uid = perms[i].uid;
        *gid = perms[i].gid;
        *perm = perms[i].perm;
        return 0;
    }
    return -1;
}

variable_types: struct perms_ { char *name; unsigned int perm; unsigned int uid; unsigned int gid; unsigned short prefix; } *

variable_types:
path
char *

variable_types:
uid
unsigned int *

variable_types:
gid
unsigned int *

variable_types:
perm
unsigned int *

variable_types: i int


original_code:
static void parse_event(const char *msg, struct uevent *uevent)
{
    uevent->action = "";
    uevent->path = "";
    uevent->subsystem = "";
    uevent->firmware = "";
    uevent->major = -1;
    uevent->minor = -1;
    while(*msg) {
        if(!strncmp(msg, "ACTION=", 7)) {
            msg += 7;
            uevent->action = msg;
        } else if(!strncmp(msg, "DEVPATH=", 8)) {
            msg += 8;
            uevent->path = msg;
        } else if(!strncmp(msg, "SUBSYSTEM=", 10)) {
            msg += 10;
            uevent->subsystem = msg;
        } else if(!strncmp(msg, "FIRMWARE=", 9)) {
            msg += 9;
            uevent->firmware = msg;
        } else if(!strncmp(msg, "MAJOR=", 6)) {
            msg += 6;
            uevent->major = atoi(msg);
        } else if(!strncmp(msg, "MINOR=", 6)) {
            msg += 6;
            uevent->minor = atoi(msg);
        }
        while(*msg++)
            ;
    }
    log_write(6, "<6>init: " "event { '%s', '%s', '%s', '%s', %d, %d }\n", uevent->action, uevent->path, uevent->subsystem, uevent->firmware, uevent->major, uevent->minor);
}

canonical_original_code:
static void parse_event(char *msg, struct uevent *uevent)
{
    uevent->action = "";
    uevent->path = "";
    uevent->subsystem = "";
    uevent->firmware = "";
    uevent->major = -1;
    uevent->minor = -1;
    while(*msg) {
        if(!strncmp(msg, "ACTION=", 7)) {
            msg += 7;
            uevent->action = msg;
        } else if(!strncmp(msg, "DEVPATH=", 8)) {
            msg += 8;
            uevent->path = msg;
        } else if(!strncmp(msg, "SUBSYSTEM=", 10)) {
            msg += 10;
            uevent->subsystem = msg;
        } else if(!strncmp(msg, "FIRMWARE=", 9)) {
            msg += 9;
            uevent->firmware = msg;
        } else if(!strncmp(msg, "MAJOR=", 6)) {
            msg += 6;
            uevent->major = atoi(msg);
        } else if(!strncmp(msg, "MINOR=", 6)) {
            msg += 6;
            uevent->minor = atoi(msg);
        }
        while(*msg++)
            ;
    }
    log_write(6, "<6>init: " "event { '%s', '%s', '%s', '%s', %d, %d }\n", uevent->action, uevent->path, uevent->subsystem, uevent->firmware, uevent->major, uevent->minor);
}

variable_types:
msg
char *

variable_types: struct uevent { char *action; char *path; char *subsystem; char *firmware; int major; int minor; } *


decompiled_code:
void __fastcall make_device(char *file, int a2, int a3, int a4)
{
int v6; // eax
__uid_t owner; // [rsp+0h] [rbp-30h] BYREF
__gid_t group[11]; // [rsp+4h] [rbp-2Ch] BYREF

if ( a3 <= 255 && a4 <= 255 )
{
v6 = get_device_perm(file, &owner, group);
mknod(file, v6 | (a2 == 0 ? 0x2000 : 24576), a4 | (a3 << 8));
chown(file, owner, group[0]);
}
}

canonical_decompiled_code:
void __fastcall func3(char *file, int a2, int a3, int a4)
{
int v6; // eax
__uid_t owner; // [rsp+0h] [rbp-30h] BYREF
__gid_t group[11]; // [rsp+4h] [rbp-2Ch] BYREF

if ( a3 <= 255 && a4 <= 255 )
{
v6 = func1(file, &owner, group);
mknod(file, v6 | (a2 == 0 ? 0x2000 : 24576), a4 | (a3 << 8));
chown(file, owner, group[0]);
}
}

original_code:
static void make_device(const char *path, int block, int major, int minor)
{
    unsigned uid;
    unsigned gid;
    mode_t mode;
    dev_t dev;
    if(major > 255 || minor > 255)
        return;
    mode = get_device_perm(path, &uid, &gid) | (block ? 0060000 : 0020000);
    dev = (major << 8) | minor;
    mknod(path, mode, dev);
    chown(path, uid, gid);
}

canonical_original_code:
static void make_device(char *path, int block, int major, int minor)
{
    unsigned int uid;
    unsigned int gid;
    unsigned int mode;
    unsigned long dev;
    if(major > 255 || minor > 255)
        return;
    mode = get_device_perm(path, &uid, &gid) | (block ? 0060000 : 0020000);
    dev = (major << 8) | minor;
    mknod(path, mode, dev);
    chown(path, uid, gid);
}

variable_types: block int

variable_types: major int

variable_types: minor int

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int

variable_types:
mode
unsigned int

variable_types:
dev
unsigned long


decompiled_code:
void __fastcall handle_device_event(__int64 a1)
{
char *v2; // rax
char *v3; // r12
const void *v4; // r13
_BYTE *v5; // rax
bool v6; // zf
int v7; // ebp
const char *v8; // rcx
char v9[136]; // [rsp-88h] [rbp-88h] BYREF

if ( *(int *)(a1 + 32) >= 0 && *(int *)(a1 + 36) >= 0 )
{
v2 = strrchr(*(const char **)(a1 + 8), 47);
v3 = v2;
if ( v2 )
{
v4 = v2 + 1;
if ( strlen(v2 + 1) <= 0x40 )
{
v5 = *(_BYTE **)(a1 + 16);
if ( !memcmp(v5, "block", 5uLL) )
{
v7 = 1;
mkdir("/dev/block/", 0x1EDu);
v8 = "/dev/block/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "graphics", 8uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/graphics/", 0x1EDu);
v8 = "/dev/graphics/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "oncrpc", 6uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/oncrpc/", 0x1EDu);
v8 = "/dev/oncrpc/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "adsp", 4uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/adsp/", 0x1EDu);
v8 = "/dev/adsp/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "msm_camera", 0xAuLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/msm_camera/", 0x1EDu);
v8 = "/dev/msm_camera/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "input", 5uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/input/", 0x1EDu);
v8 = "/dev/input/";
}
else if ( *v5 == 109 && v5[1] == 116 && (v7 = (unsigned __int8)v5[2] - 100, v5[2] == 100) )
{
mkdir("/dev/mtd/", 0x1EDu);
v8 = "/dev/mtd/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "sound", 5uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/snd/", 0x1EDu);
v8 = "/dev/snd/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "misc", 4uLL) == 0;
v7 = !v6;
if ( v6 )
{
v6 = memcmp(v4, "log_", 4uLL) == 0;
v8 = "/dev/";
if ( v6 )
{
v4 = v3 + 5;
mkdir("/dev/log/", 0x1EDu);
v8 = "/dev/log/";
}
}
else
{
v7 = 0;
v8 = "/dev/";
}
}
}
}
}
}
}
}
snprintf(v9, 0x60uLL, "%s%s", v8, (const char *)v4);
if ( !strcmp(*(const char **)a1, "add") )
{
make_device(v9, v7, *(_DWORD *)(a1 + 32), *(_DWORD *)(a1 + 36));
}
else if ( !strcmp(*(const char **)a1, "remove") )
{
unlink(v9);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
char *v2; // rax
char *v3; // r12
const void *v4; // r13
_BYTE *v5; // rax
bool v6; // zf
int v7; // ebp
const char *v8; // rcx
char v9[136]; // [rsp-88h] [rbp-88h] BYREF

if ( *(int *)(a1 + 32) >= 0 && *(int *)(a1 + 36) >= 0 )
{
v2 = strrchr(*(const char **)(a1 + 8), 47);
v3 = v2;
if ( v2 )
{
v4 = v2 + 1;
if ( strlen(v2 + 1) <= 0x40 )
{
v5 = *(_BYTE **)(a1 + 16);
if ( !memcmp(v5, "block", 5uLL) )
{
v7 = 1;
mkdir("/dev/block/", 0x1EDu);
v8 = "/dev/block/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "graphics", 8uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/graphics/", 0x1EDu);
v8 = "/dev/graphics/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "oncrpc", 6uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/oncrpc/", 0x1EDu);
v8 = "/dev/oncrpc/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "adsp", 4uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/adsp/", 0x1EDu);
v8 = "/dev/adsp/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "msm_camera", 0xAuLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/msm_camera/", 0x1EDu);
v8 = "/dev/msm_camera/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "input", 5uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/input/", 0x1EDu);
v8 = "/dev/input/";
}
else if ( *v5 == 109 && v5[1] == 116 && (v7 = (unsigned __int8)v5[2] - 100, v5[2] == 100) )
{
mkdir("/dev/mtd/", 0x1EDu);
v8 = "/dev/mtd/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "sound", 5uLL) == 0;
v7 = !v6;
if ( v6 )
{
mkdir("/dev/snd/", 0x1EDu);
v8 = "/dev/snd/";
}
else
{
v6 = memcmp(*(const void **)(a1 + 16), "misc", 4uLL) == 0;
v7 = !v6;
if ( v6 )
{
v6 = memcmp(v4, "log_", 4uLL) == 0;
v8 = "/dev/";
if ( v6 )
{
v4 = v3 + 5;
mkdir("/dev/log/", 0x1EDu);
v8 = "/dev/log/";
}
}
else
{
v7 = 0;
v8 = "/dev/";
}
}
}
}
}
}
}
}
snprintf(v9, 0x60uLL, "%s%s", v8, (const char *)v4);
if ( !strcmp(*(const char **)a1, "add") )
{
func3(v9, v7, *(_DWORD *)(a1 + 32), *(_DWORD *)(a1 + 36));
}
else if ( !strcmp(*(const char **)a1, "remove") )
{
unlink(v9);
}
}
}
}
}

original_code:
static void handle_device_event(struct uevent *uevent)
{
    char devpath[96];
    char *base, *name;
    int block;
    if((uevent->major < 0) || (uevent->minor < 0))
        return;
    name = strrchr(uevent->path, '/');
    if(!name)
        return;
    name++;
    if(strlen(name) > 64)
        return;
    if(!strncmp(uevent->subsystem, "block", 5)) {
        block = 1;
        base = "/dev/block/";
        mkdir(base, 0755);
    } else {
        block = 0;
        if(!strncmp(uevent->subsystem, "graphics", 8)) {
            base = "/dev/graphics/";
            mkdir(base, 0755);
        } else if (!strncmp(uevent->subsystem, "oncrpc", 6)) {
            base = "/dev/oncrpc/";
            mkdir(base, 0755);
        } else if (!strncmp(uevent->subsystem, "adsp", 4)) {
            base = "/dev/adsp/";
            mkdir(base, 0755);
        } else if (!strncmp(uevent->subsystem, "msm_camera", 10)) {
            base = "/dev/msm_camera/";
            mkdir(base, 0755);
        } else if(!strncmp(uevent->subsystem, "input", 5)) {
            base = "/dev/input/";
            mkdir(base, 0755);
        } else if(!strncmp(uevent->subsystem, "mtd", 3)) {
            base = "/dev/mtd/";
            mkdir(base, 0755);
        } else if(!strncmp(uevent->subsystem, "sound", 5)) {
            base = "/dev/snd/";
            mkdir(base, 0755);
        } else if(!strncmp(uevent->subsystem, "misc", 4) &&
                    !strncmp(name, "log_", 4)) {
            base = "/dev/log/";
            mkdir(base, 0755);
            name += 4;
        } else
            base = "/dev/";
    }
    snprintf(devpath, sizeof(devpath), "%s%s", base, name);
    if(!strcmp(uevent->action, "add")) {
        make_device(devpath, block, uevent->major, uevent->minor);
        return;
    }
    if(!strcmp(uevent->action, "remove")) {
        unlink(devpath);
        return;
    }
}

canonical_original_code:
static void handle_device_event(struct uevent *uevent)
{
    char devpath[96];
    char *base; char *name;
    int block;
    if((uevent->major < 0) || (uevent->minor < 0))
        return;
    name = strrchr(uevent->path, '/');
    if(!name)
        return;
    name++;
    if(strlen(name) > 64)
        return;
    if(!strncmp(uevent->subsystem, "block", 5)) {
        block = 1;
        base = "/dev/block/";
        mkdir(base, 0755);
    } else {
        block = 0;
        if(!strncmp(uevent->subsystem, "graphics", 8)) {
            base = "/dev/graphics/";
            mkdir(base, 0755);
        } else if (!strncmp(uevent->subsystem, "oncrpc", 6)) {
            base = "/dev/oncrpc/";
            mkdir(base, 0755);
        } else if (!strncmp(uevent->subsystem, "adsp", 4)) {
            base = "/dev/adsp/";
            mkdir(base, 0755);
        } else if (!strncmp(uevent->subsystem, "msm_camera", 10)) {
            base = "/dev/msm_camera/";
            mkdir(base, 0755);
        } else if(!strncmp(uevent->subsystem, "input", 5)) {
            base = "/dev/input/";
            mkdir(base, 0755);
        } else if(!strncmp(uevent->subsystem, "mtd", 3)) {
            base = "/dev/mtd/";
            mkdir(base, 0755);
        } else if(!strncmp(uevent->subsystem, "sound", 5)) {
            base = "/dev/snd/";
            mkdir(base, 0755);
        } else if(!strncmp(uevent->subsystem, "misc", 4) &&
                    !strncmp(name, "log_", 4)) {
            base = "/dev/log/";
            mkdir(base, 0755);
            name += 4;
        } else
            base = "/dev/";
    }
    snprintf(devpath, sizeof(devpath), "%s%s", base, name);
    if(!strcmp(uevent->action, "add")) {
        make_device(devpath, block, uevent->major, uevent->minor);
        return;
    }
    if(!strcmp(uevent->action, "remove")) {
        unlink(devpath);
        return;
    }
}

variable_types:
devpath
char [96]

variable_types:
base
char *

variable_types:
name
char *

user_defined_types: struct uevent { char *action; char *path; char *subsystem; char *firmware; int major; int minor; }


decompiled_code:
__int64 __fastcall load_firmware(int fd, int a2, int a3)
{
__off_t v4; // r14
ssize_t v5; // rax
ssize_t v6; // rbp
signed __int64 v7; // r15
ssize_t v8; // rax
struct stat v10; // [rsp+0h] [rbp-10C8h] BYREF
char buf[4152]; // [rsp+90h] [rbp-1038h] BYREF

if ( fstat(fd, &v10) < 0 )
return 0xFFFFFFFFLL;
v4 = v10.st_size;
write(a2, "1", 1uLL);
if ( v4 <= 0 )
{
LABEL_10:
write(a2, "0", 1uLL);
return 0LL;
}
LABEL_3:
v5 = read(fd, buf, 0x1000uLL);
v6 = v5;
if ( !v5 )
goto LABEL_10;
if ( v5 >= 0 )
{
v7 = v5;
while ( 1 )
{
v8 = write(a3, buf, v7);
if ( v8 <= 0 )
break;
v7 -= v8;
if ( v7 <= 0 )
{
v4 -= v6;
if ( v4 > 0 )
goto LABEL_3;
goto LABEL_10;
}
}
}
write(a2, "-1", 2uLL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, int a2, int a3)
{
__off_t v4; // r14
ssize_t v5; // rax
ssize_t v6; // rbp
signed __int64 v7; // r15
ssize_t v8; // rax
struct stat v10; // [rsp+0h] [rbp-10C8h] BYREF
char buf[4152]; // [rsp+90h] [rbp-1038h] BYREF

if ( fstat(fd, &v10) < 0 )
return 0xFFFFFFFFLL;
v4 = v10.st_size;
write(a2, "1", 1uLL);
if ( v4 <= 0 )
{
LABEL_10:
write(a2, "0", 1uLL);
return 0LL;
}
LABEL_3:
v5 = read(fd, buf, 0x1000uLL);
v6 = v5;
if ( !v5 )
goto LABEL_10;
if ( v5 >= 0 )
{
v7 = v5;
while ( 1 )
{
v8 = write(a3, buf, v7);
if ( v8 <= 0 )
break;
v7 -= v8;
if ( v7 <= 0 )
{
v4 -= v6;
if ( v4 > 0 )
goto LABEL_3;
goto LABEL_10;
}
}
}
write(a2, "-1", 2uLL);
return 0xFFFFFFFFLL;
}

original_code:
static int load_firmware(int fw_fd, int loading_fd, int data_fd)
{
    struct stat st;
    long len_to_copy;
    int ret = 0;
    if(fstat(fw_fd, &st) < 0)
        return -1;
    len_to_copy = st.st_size;
    write(loading_fd, "1", 1);
    while (len_to_copy > 0) {
        char buf[4096];
        ssize_t nr;
        nr = read(fw_fd, buf, sizeof(buf));
        if(!nr)
            break;
        if(nr < 0) {
            ret = -1;
            break;
        }
        len_to_copy -= nr;
        while (nr > 0) {
            ssize_t nw = 0;
            nw = write(data_fd, buf + nw, nr);
            if(nw <= 0) {
                ret = -1;
                goto out;
            }
            nr -= nw;
        }
    }
out:
    if(!ret)
        write(loading_fd, "0", 1);
    else
        write(loading_fd, "-1", 2);
    return ret;
}

canonical_original_code:
static int load_firmware(int fw_fd, int loading_fd, int data_fd)
{
    struct stat st;
    long len_to_copy;
    int ret = 0;
    if(fstat(fw_fd, &st) < 0)
        return -1;
    len_to_copy = st.st_size;
    write(loading_fd, "1", 1);
    while (len_to_copy > 0) {
        char buf[4096];
        long nr;
        nr = read(fw_fd, buf, sizeof(buf));
        if(!nr)
            break;
        if(nr < 0) {
            ret = -1;
            break;
        }
        len_to_copy -= nr;
        while (nr > 0) {
            long nw = 0;
            nw = write(data_fd, buf + nw, nr);
            if(nw <= 0) {
                ret = -1;
                goto out;
            }
            nr -= nw;
        }
    }
out:
    if(!ret)
        write(loading_fd, "0", 1);
    else
        write(loading_fd, "-1", 2);
    return ret;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: ret int

variable_types:
buf
char [4096]

variable_types: nr long

variable_types: nw long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void __fastcall process_firmware_event(__int64 a1)
{
int v1; // ebp
int v2; // er12
int v3; // eax
int v4; // er13
void *v5; // [rsp+0h] [rbp-48h] BYREF
char *ptr; // [rsp+8h] [rbp-40h] BYREF
char *file; // [rsp+10h] [rbp-38h] BYREF
char *v8; // [rsp+18h] [rbp-30h] BYREF

log_write(6LL, "<6>init: firmware event { '%s', '%s' }\n", *(const char **)(a1 + 8), *(const char **)(a1 + 24));
if ( asprintf((char **)&v5, "/sys%s/", *(const char **)(a1 + 8)) != -1 )
{
if ( asprintf(&ptr, "%sloading", (const char *)v5) != -1 )
{
if ( asprintf(&file, "%sdata", (const char *)v5) != -1 )
{
if ( asprintf(&v8, "/etc/firmware/%s", *(const char **)(a1 + 24)) != -1 )
{
v1 = open(ptr, 1);
if ( v1 >= 0 )
{
v2 = open(file, 1);
if ( v2 >= 0 )
{
v3 = open(v8, 0);
v4 = v3;
if ( v3 >= 0 )
{
if ( (unsigned int)load_firmware(v3, v1, v2) )
log_write(6LL, "<6>init: firmware copy failure { '%s', '%s' }\n", (const char *)v5, v8);
else
log_write(6LL, "<6>init: firmware copy success { '%s', '%s' }\n", (const char *)v5, v8);
close(v4);
}
close(v2);
}
close(v1);
}
free(v8);
}
free(file);
}
free(ptr);
}
free(v5);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
int v1; // ebp
int v2; // er12
int v3; // eax
int v4; // er13
void *v5; // [rsp+0h] [rbp-48h] BYREF
char *ptr; // [rsp+8h] [rbp-40h] BYREF
char *file; // [rsp+10h] [rbp-38h] BYREF
char *v8; // [rsp+18h] [rbp-30h] BYREF

log_write(6LL, "<6>init: firmware event { '%s', '%s' }\n", *(const char **)(a1 + 8), *(const char **)(a1 + 24));
if ( asprintf((char **)&v5, "/sys%s/", *(const char **)(a1 + 8)) != -1 )
{
if ( asprintf(&ptr, "%sloading", (const char *)v5) != -1 )
{
if ( asprintf(&file, "%sdata", (const char *)v5) != -1 )
{
if ( asprintf(&v8, "/etc/firmware/%s", *(const char **)(a1 + 24)) != -1 )
{
v1 = open(ptr, 1);
if ( v1 >= 0 )
{
v2 = open(file, 1);
if ( v2 >= 0 )
{
v3 = open(v8, 0);
v4 = v3;
if ( v3 >= 0 )
{
if ( (unsigned int)func5(v3, v1, v2) )
log_write(6LL, "<6>init: firmware copy failure { '%s', '%s' }\n", (const char *)v5, v8);
else
log_write(6LL, "<6>init: firmware copy success { '%s', '%s' }\n", (const char *)v5, v8);
close(v4);
}
close(v2);
}
close(v1);
}
free(v8);
}
free(file);
}
free(ptr);
}
free(v5);
}
}

original_code:
static void process_firmware_event(struct uevent *uevent)
{
    char *root, *loading, *data, *file;
    int l, loading_fd, data_fd, fw_fd;
    log_write(6, "<6>init: " "firmware event { '%s', '%s' }\n", uevent->path, uevent->firmware);
    l = asprintf(&root, "/sys""%s/", uevent->path);
    if (l == -1)
        return;
    l = asprintf(&loading, "%sloading", root);
    if (l == -1)
        goto root_free_out;
    l = asprintf(&data, "%sdata", root);
    if (l == -1)
        goto loading_free_out;
    l = asprintf(&file, "/etc/firmware""/%s", uevent->firmware);
    if (l == -1)
        goto data_free_out;
    loading_fd = open(loading, 01);
    if(loading_fd < 0)
        goto file_free_out;
    data_fd = open(data, 01);
    if(data_fd < 0)
        goto loading_close_out;
    fw_fd = open(file, 00);
    if(fw_fd < 0)
        goto data_close_out;
    if(!load_firmware(fw_fd, loading_fd, data_fd))
        log_write(6, "<6>init: " "firmware copy success { '%s', '%s' }\n", root, file);
    else
        log_write(6, "<6>init: " "firmware copy failure { '%s', '%s' }\n", root, file);
    close(fw_fd);
data_close_out:
    close(data_fd);
loading_close_out:
    close(loading_fd);
file_free_out:
    free(file);
data_free_out:
    free(data);
loading_free_out:
    free(loading);
root_free_out:
    free(root);
}

canonical_original_code:
static void process_firmware_event(struct uevent *uevent)
{
    char *root; char *loading; char *data; char *file;
    int l; int loading_fd; int data_fd; int fw_fd;
    log_write(6, "<6>init: " "firmware event { '%s', '%s' }\n", uevent->path, uevent->firmware);
    l = asprintf(&root, "/sys""%s/", uevent->path);
    if (l == -1)
        return;
    l = asprintf(&loading, "%sloading", root);
    if (l == -1)
        goto root_free_out;
    l = asprintf(&data, "%sdata", root);
    if (l == -1)
        goto loading_free_out;
    l = asprintf(&file, "/etc/firmware""/%s", uevent->firmware);
    if (l == -1)
        goto data_free_out;
    loading_fd = open(loading, 01);
    if(loading_fd < 0)
        goto file_free_out;
    data_fd = open(data, 01);
    if(data_fd < 0)
        goto loading_close_out;
    fw_fd = open(file, 00);
    if(fw_fd < 0)
        goto data_close_out;
    if(!load_firmware(fw_fd, loading_fd, data_fd))
        log_write(6, "<6>init: " "firmware copy success { '%s', '%s' }\n", root, file);
    else
        log_write(6, "<6>init: " "firmware copy failure { '%s', '%s' }\n", root, file);
    close(fw_fd);
data_close_out:
    close(data_fd);
loading_close_out:
    close(loading_fd);
file_free_out:
    free(file);
data_free_out:
    free(data);
loading_free_out:
    free(loading);
root_free_out:
    free(root);
}

variable_types:
root
char *

variable_types:
loading
char *

variable_types:
data
char *

variable_types:
file
char *

variable_types: l int


decompiled_code:
char __fastcall handle_firmware_event(const char **a1)
{
bool v1; // zf
__pid_t v2; // eax

v1 = strcmp(a1[2], "firmware") == 0;
LOBYTE(v2) = !v1;
if ( v1 )
{
v1 = strcmp(*a1, "add") == 0;
LOBYTE(v2) = !v1;
if ( v1 )
{
v2 = fork();
if ( !v2 )
{
process_firmware_event((__int64)a1);
exit(0);
}
}
}
return v2;
}

canonical_decompiled_code:
char __fastcall func7(const char **a1)
{
bool v1; // zf
__pid_t v2; // eax

v1 = strcmp(a1[2], "firmware") == 0;
LOBYTE(v2) = !v1;
if ( v1 )
{
v1 = strcmp(*a1, "add") == 0;
LOBYTE(v2) = !v1;
if ( v1 )
{
v2 = fork();
if ( !v2 )
{
func6((__int64)a1);
exit(0);
}
}
}
return v2;
}

original_code:
static void handle_firmware_event(struct uevent *uevent)
{
    pid_t pid;
    if(strcmp(uevent->subsystem, "firmware"))
        return;
    if(strcmp(uevent->action, "add"))
        return;
    pid = fork();
    if (!pid) {
        process_firmware_event(uevent);
        exit(0);
    }
}

canonical_original_code:
static void handle_firmware_event(struct uevent *uevent)
{
    int pid;
    if(strcmp(uevent->subsystem, "firmware"))
        return;
    if(strcmp(uevent->action, "add"))
        return;
    pid = fork();
    if (!pid) {
        process_firmware_event(uevent);
        exit(0);
    }
}

variable_types: struct uevent { char *action; char *path; char *subsystem; char *firmware; int major; int minor; } *

variable_types: pid int


decompiled_code:
__int64 open_uevent_socket()
{
int v0; // eax
unsigned int v1; // er12
int v3; // edi
int v4; // [rsp+0h] [rbp-18h] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-14h] BYREF

v4 = 0x10000;
*(_DWORD *)&addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[2] = getpid();
*(_DWORD *)&addr.sa_data[6] = -1;
v0 = socket(16, 2, 15);
if ( v0 < 0 )
return (unsigned int)-1;
v1 = v0;
setsockopt(v0, 1, 33, &v4, 4u);
if ( bind(v1, &addr, 0xCu) < 0 )
{
v3 = v1;
v1 = -1;
close(v3);
}
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // eax
unsigned int v1; // er12
int v3; // edi
int v4; // [rsp+0h] [rbp-18h] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-14h] BYREF

v4 = 0x10000;
*(_DWORD *)&addr.sa_family = 16;
*(_DWORD *)&addr.sa_data[2] = getpid();
*(_DWORD *)&addr.sa_data[6] = -1;
v0 = socket(16, 2, 15);
if ( v0 < 0 )
return (unsigned int)-1;
v1 = v0;
setsockopt(v0, 1, 33, &v4, 4u);
if ( bind(v1, &addr, 0xCu) < 0 )
{
v3 = v1;
v1 = -1;
close(v3);
}
return v1;
}

original_code:
static int open_uevent_socket(void)
{
    struct sockaddr_nl addr;
    int sz = 64*1024;
    int s;
    memset(&addr, 0, sizeof(addr));
    addr.nl_family = 16;
    addr.nl_pid = getpid();
    addr.nl_groups = 0xffffffff;
    s = socket(16, SOCK_DGRAM, 15);
    if(s < 0)
        return -1;
    setsockopt(s, 1, 33, &sz, sizeof(sz));
    if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
        close(s);
        return -1;
    }
    return s;
}

canonical_original_code:
static int open_uevent_socket()
{
    struct sockaddr_nl addr;
    int sz = 64*1024;
    int s;
    memset(&addr, 0, sizeof(addr));
    addr.nl_family = 16;
    addr.nl_pid = getpid();
    addr.nl_groups = 0xffffffff;
    s = socket(16, SOCK_DGRAM, 15);
    if(s < 0)
        return -1;
    setsockopt(s, 1, 33, &sz, sizeof(sz));
    if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
        close(s);
        return -1;
    }
    return s;
}

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }

variable_types: sz int

variable_types: s int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__suseconds_t get_usecs()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func9()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static inline suseconds_t get_usecs(void)
{
    struct timeval tv;
    gettimeofday(&tv, 0);
    return tv.tv_sec * (suseconds_t) 1000000 + tv.tv_usec;
}

canonical_original_code:
static inline long get_usecs()
{
    struct timeval tv;
    gettimeofday(&tv, 0);
    return tv.tv_sec * (long) 1000000 + tv.tv_usec;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: long


decompiled_code:
__int64 __fastcall add_devperms_partners(void *src, int a2, int a3, int a4, __int16 a5)
{
_DWORD *v7; // rax
_DWORD *v8; // rbx
size_t v9; // r15
void *v10; // rax

v7 = malloc(0x28uLL);
if ( !v7 )
return 4294967284LL;
v8 = v7;
v9 = (int)(strlen((const char *)src) + 1);
v10 = malloc(v9);
*(_QWORD *)v8 = v10;
if ( !v10 )
return 4294967284LL;
memcpy(v10, src, v9);
v8[2] = a2;
v8[3] = a3;
*((_WORD *)v8 + 10) = a5;
v8[4] = a4;
list_add_tail(&devperms_partners, v8 + 6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(void *src, int a2, int a3, int a4, __int16 a5)
{
_DWORD *v7; // rax
_DWORD *v8; // rbx
size_t v9; // r15
void *v10; // rax

v7 = malloc(0x28uLL);
if ( !v7 )
return 4294967284LL;
v8 = v7;
v9 = (int)(strlen((const char *)src) + 1);
v10 = malloc(v9);
*(_QWORD *)v8 = v10;
if ( !v10 )
return 4294967284LL;
memcpy(v10, src, v9);
v8[2] = a2;
v8[3] = a3;
*((_WORD *)v8 + 10) = a5;
v8[4] = a4;
list_add_tail(&devperms_partners, v8 + 6);
return 0LL;
}

original_code:
int add_devperms_partners(const char *name, mode_t perm, unsigned int uid,
                        unsigned int gid, unsigned short prefix) {
    int size;
    struct perm_node *node = malloc(sizeof (struct perm_node));
    if (!node)
        return -12;
    size = strlen(name) + 1;
    if ((node->dp.name = malloc(size)) == ((void *)0))
        return -12;
    memcpy(node->dp.name, name, size);
    node->dp.perm = perm;
    node->dp.uid = uid;
    node->dp.gid = gid;
    node->dp.prefix = prefix;
    list_add_tail(&devperms_partners, &node->plist);
    return 0;
}

canonical_original_code:
int add_devperms_partners(char *name, unsigned int perm, unsigned int uid, unsigned int gid, unsigned short prefix) {
    int size;
    struct perm_node *node = malloc(sizeof (struct perm_node));
    if (!node)
        return -12;
    size = strlen(name) + 1;
    if ((node->dp.name = malloc(size)) == ((void *)0))
        return -12;
    memcpy(node->dp.name, name, size);
    node->dp.perm = perm;
    node->dp.uid = uid;
    node->dp.gid = gid;
    node->dp.prefix = prefix;
    list_add_tail(&devperms_partners, &node->plist);
    return 0;
}

variable_types:
name
char *

variable_types:
perm
unsigned int

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int

variable_types:
prefix
unsigned short

variable_types: size int

variable_types: struct perm_node { struct perms_ { char *name; unsigned int perm; unsigned int uid; unsigned int gid; unsigned short prefix; } dp; struct listnode { struct listnode *next; struct listnode *prev; } plist; } *

user_defined_types: struct perm_node { struct perms_ dp; struct listnode plist; }


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

result = 0LL;
memset(&qemu_perms, 0, 0xA8uLL);
return result;
}

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

result = 0LL;
memset(&qemu_perms, 0, 0xA8uLL);
return result;
}

original_code:
void qemu_init(void) {
    qemu_perm_count = 0;
    memset(&qemu_perms, 0, sizeof(qemu_perms));
}

canonical_original_code:
void qemu_init() {
    qemu_perm_count = 0;
    memset(&qemu_perms, 0, sizeof(qemu_perms));
}


decompiled_code:
char __fastcall qemu_cmdline(const char *a1, const char *a2)
{
bool v2; // zf
int v3; // eax
char *ptr; // [rsp+0h] [rbp-10h] BYREF

v2 = strcmp(a1, "android.ril") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
v3 = asprintf(&ptr, "/dev/%s", a2);
if ( v3 != -1 )
LOBYTE(v3) = log_write(6LL, "<6>init: nani- buf:: %s\n", ptr);
}
return v3;
}

canonical_decompiled_code:
char __fastcall func12(const char *a1, const char *a2)
{
bool v2; // zf
int v3; // eax
char *ptr; // [rsp+0h] [rbp-10h] BYREF

v2 = strcmp(a1, "android.ril") == 0;
LOBYTE(v3) = !v2;
if ( v2 )
{
v3 = asprintf(&ptr, "/dev/%s", a2);
if ( v3 != -1 )
LOBYTE(v3) = log_write(6LL, "<6>init: nani- buf:: %s\n", ptr);
}
return v3;
}

original_code:
void qemu_cmdline(const char* name, const char *value)
{
    char *buf;
    if (!strcmp(name, "android.ril")) {
        if (asprintf(&buf, "/dev""/%s", value) == -1) {
            return;
        }
        log_write(6, "<6>init: " "nani- buf:: %s\n", buf);
    }
}

canonical_original_code:
void qemu_cmdline(char *name, char *value)
{
    char *buf;
    if (!strcmp(name, "android.ril")) {
        if (asprintf(&buf, "/dev""/%s", value) == -1) {
            return;
        }
        log_write(6, "<6>init: " "nani- buf:: %s\n", buf);
    }
}

variable_types:
value
char *

variable_types:
buf
char *


decompiled_code:
ssize_t __fastcall handle_device_fd(int fd)
{
ssize_t result; // rax
const char *v2[6]; // [rsp+0h] [rbp-448h] BYREF
char buf[1048]; // [rsp+30h] [rbp-418h] BYREF

while ( 1 )
{
result = recv(fd, buf, 0x400uLL, 0);
if ( (int)result <= 0 )
break;
if ( (_DWORD)result != 1024 )
{
buf[(int)result] = 0;
buf[(int)result + 1] = 0;
parse_event(buf, (__int64)v2);
handle_device_event((__int64)v2);
handle_firmware_event(v2);
}
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func13(int fd)
{
ssize_t result; // rax
const char *v2[6]; // [rsp+0h] [rbp-448h] BYREF
char buf[1048]; // [rsp+30h] [rbp-418h] BYREF

while ( 1 )
{
result = recv(fd, buf, 0x400uLL, 0);
if ( (int)result <= 0 )
break;
if ( (_DWORD)result != 1024 )
{
buf[(int)result] = 0;
buf[(int)result + 1] = 0;
func2(buf, (__int64)v2);
func4((__int64)v2);
func7(v2);
}
}
return result;
}

original_code:
void handle_device_fd(int fd)
{
    char msg[1024 +2];
    int n;
    while((n = recv(fd, msg, 1024, 0)) > 0) {
        struct uevent uevent;
        if(n == 1024)
            continue;
        msg[n] = '\0';
        msg[n+1] = '\0';
        parse_event(msg, &uevent);
        handle_device_event(&uevent);
        handle_firmware_event(&uevent);
    }
}

canonical_original_code:
void handle_device_fd(int fd)
{
    char msg[-1];
    int n;
    while((n = recv(fd, msg, 1024, 0)) > 0) {
        struct uevent uevent;
        if(n == 1024)
            continue;
        msg[n] = '\0';
        msg[n+1] = '\0';
        parse_event(msg, &uevent);
        handle_device_event(&uevent);
        handle_firmware_event(&uevent);
    }
}

variable_types: fd int

variable_types:
msg
char [-1]

variable_types: n int

variable_types: struct uevent { char *action; char *path; char *subsystem; char *firmware; int major; int minor; }


decompiled_code:
__int64 device_init()
{
int v0; // eax
unsigned int v1; // er12
__suseconds_t v2; // rbx
__suseconds_t v3; // rax

v0 = open_uevent_socket();
if ( v0 < 0 )
return (unsigned int)-1;
v1 = v0;
fcntl(v0, 2, 1LL);
fcntl(v1, 4, 2048LL);
v2 = get_usecs();
coldboot(v1, "/sys/class");
coldboot(v1, "/sys/block");
coldboot(v1, "/sys/devices");
v3 = get_usecs();
log_write(6LL, "<6>init: coldboot %ld uS\n", v3 - v2);
return v1;
}

canonical_decompiled_code:
__int64 func16()
{
int v0; // eax
unsigned int v1; // er12
__suseconds_t v2; // rbx
__suseconds_t v3; // rax

v0 = func8();
if ( v0 < 0 )
return (unsigned int)-1;
v1 = v0;
fcntl(v0, 2, 1LL);
fcntl(v1, 4, 2048LL);
v2 = func9();
func15(v1, "/sys/class");
func15(v1, "/sys/block");
func15(v1, "/sys/devices");
v3 = func9();
log_write(6LL, "<6>init: coldboot %ld uS\n", v3 - v2);
return v1;
}

original_code:
int device_init(void)
{
    suseconds_t t0, t1;
    int fd;
    fd = open_uevent_socket();
    if(fd < 0)
        return -1;
    fcntl(fd, 2, 1);
    fcntl(fd, 4, 04000);
    t0 = get_usecs();
    coldboot(fd, "/sys/class");
    coldboot(fd, "/sys/block");
    coldboot(fd, "/sys/devices");
    t1 = get_usecs();
    log_write(6, "<6>init: " "coldboot %ld uS\n", ((long) (t1 - t0)));
    return fd;
}

canonical_original_code:
int device_init()
{
    long t0; long t1;
    int fd;
    fd = open_uevent_socket();
    if(fd < 0)
        return -1;
    fcntl(fd, 2, 1);
    fcntl(fd, 4, 04000);
    t0 = get_usecs();
    coldboot(fd, "/sys/class");
    coldboot(fd, "/sys/block");
    coldboot(fd, "/sys/devices");
    t1 = get_usecs();
    log_write(6, "<6>init: " "coldboot %ld uS\n", ((long) (t1 - t0)));
    return fd;
}


strlcpy

decompiled_code:
__int64 __fastcall strlcpy(_BYTE *a1, _BYTE *a2, __int64 a3)
{
__int64 v3; // rcx
_BYTE *v4; // rax
char v5; // dl
_BYTE *v6; // rdx
__int64 result; // rax

if ( a3 )
{
v3 = (__int64)&a1[a3 - 1];
v4 = a2;
while ( 1 )
{
v6 = v4++;
if ( a1 == (_BYTE *)v3 )
break;
v5 = *(v4 - 1);
*a1++ = v5;
if ( !v5 )
goto LABEL_6;
}
*a1 = 0;
v4 = v6 + 1;
if ( *v6 )
goto LABEL_8;
LABEL_6:
result = v4 - a2 - 1;
}
else
{
v4 = a2;
do
LABEL_8:
++v4;
while ( *(v4 - 1) );
result = v4 - a2 - 1;
}
return result;
}

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

if ( a3 )
{
v3 = (__int64)&a1[a3 - 1];
v4 = a2;
while ( 1 )
{
v6 = v4++;
if ( a1 == (_BYTE *)v3 )
break;
v5 = *(v4 - 1);
*a1++ = v5;
if ( !v5 )
goto LABEL_6;
}
*a1 = 0;
v4 = v6 + 1;
if ( *v6 )
goto LABEL_8;
LABEL_6:
result = v4 - a2 - 1;
}
else
{
v4 = a2;
do
LABEL_8:
++v4;
while ( *(v4 - 1) );
result = v4 - a2 - 1;
}
return result;
}

original_code:
size_t
strlcpy(char *dst, const char *src, size_t siz)
{
 char *d = dst;
 const char *s = src;
 size_t n = siz;
 if (n != 0) {
  while (--n != 0) {
   if ((*d++ = *s++) == '\0')
    break;
  }
  }
 if (n == 0) {
  if (siz != 0)
   *d = '\0';
  while (*s++)
   ;
 }
 return(s - src - 1);
}

canonical_original_code:
unsigned long strlcpy(char *dst, char *src, unsigned long siz)
{
 char *d = dst;
 char *s = src;
 unsigned long n = siz;
 if (n != 0) {
  while (--n != 0) {
   if ((*d++ = *s++) == '\0')
    break;
  }
  }
 if (n == 0) {
  if (siz != 0)
   *d = '\0';
  while (*s++)
   ;
 }
 return(s - src - 1);
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
siz
unsigned long

variable_types:
d
char *

variable_types:
s
char *

variable_types:
n
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall log_set_level(int a1)
{
log_level = a1;
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
log_level = a1;
}

original_code:
void log_set_level(int level) {
    log_level = level;
}

variable_types: level int


decompiled_code:
int log_init()
{
int result; // eax

result = mknod("/dev/__kmsg__", 0x2180u, 0x10BuLL);
if ( !result )
{
log_fd = open("/dev/__kmsg__", 1);
fcntl(log_fd, 2, 1LL);
result = unlink("/dev/__kmsg__");
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

result = mknod("/dev/__kmsg__", 0x2180u, 0x10BuLL);
if ( !result )
{
log_fd = open("/dev/__kmsg__", 1);
fcntl(log_fd, 2, 1LL);
result = unlink("/dev/__kmsg__");
}
return result;
}

original_code:
void log_init(void)
{
    static const char *name = "/dev/__kmsg__";
    if (mknod(name, 0020000 | 0600, (1 << 8) | 11) == 0) {
        log_fd = open(name, 01);
        fcntl(log_fd, 2, 1);
        unlink(name);
    }
}

canonical_original_code:
void log_init()
{
    static char *name = "/dev/__kmsg__";
    if (mknod(name, 0020000 | 0600, (1 << 8) | 11) == 0) {
        log_fd = open(name, 01);
        fcntl(log_fd, 2, 1);
        unlink(name);
    }
}

variable_types:
name
char *


decompiled_code:
void log_write(int a1, const char *a2, ...)
{
size_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

if ( log_level >= a1 && log_fd >= 0 )
{
va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
s[511] = 0;
v2 = strlen(s);
write(log_fd, s, v2);
}
}

canonical_decompiled_code:
void func3(int a1, const char *a2, ...)
{
size_t v2; // rax
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

if ( log_level >= a1 && log_fd >= 0 )
{
va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
s[511] = 0;
v2 = strlen(s);
write(log_fd, s, v2);
}
}

original_code:
void log_write(int level, const char *fmt, ...)
{
    char buf[512];
    va_list ap;
    if (level > log_level) return;
    if (log_fd < 0) return;
    __builtin_va_start(ap,fmt);
    vsnprintf(buf, 512, fmt, ap);
    buf[512 - 1] = 0;
    __builtin_va_end(ap);
    write(log_fd, buf, strlen(buf));
}

canonical_original_code:
void log_write(int level, char *fmt, ...)
{
    char buf[512];
    __builtin_va_list ap;
    if (level > log_level) return;
    if (log_fd < 0) return;
    __builtin_va_start(ap,fmt);
    vsnprintf(buf, 512, fmt, ap);
    buf[512 - 1] = 0;
    __builtin_va_end(ap);
    write(log_fd, buf, strlen(buf));
}

variable_types:
fmt
char *

variable_types:
buf
char [512]


decompiled_code:
unsigned __int64 __fastcall decode_uid(char *nptr)
{
__int64 v1; // rbx
unsigned __int64 result; // rax
int *v3; // rax
int *v4; // rbx

if ( !nptr )
return 0xFFFFFFFFLL;
v1 = *nptr;
if ( !(_BYTE)v1 )
return 0xFFFFFFFFLL;
if ( ((*_ctype_b_loc())[v1] & 0x400) != 0 )
return android_name_to_id_constprop_0();
v3 = _errno_location();
*v3 = 0;
v4 = v3;
result = strtoul(nptr, 0LL, 0);
if ( *v4 )
return 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(char *nptr)
{
__int64 v1; // rbx
unsigned __int64 result; // rax
int *v3; // rax
int *v4; // rbx

if ( !nptr )
return 0xFFFFFFFFLL;
v1 = *nptr;
if ( !(_BYTE)v1 )
return 0xFFFFFFFFLL;
if ( ((*_ctype_b_loc())[v1] & 0x400) != 0 )
return func0();
v3 = _errno_location();
*v3 = 0;
v4 = v3;
result = strtoul(nptr, 0LL, 0);
if ( *v4 )
return 0xFFFFFFFFLL;
return result;
}

original_code:
unsigned int decode_uid(const char *s)
{
    unsigned int v;
    if (!s || *s == '\0')
        return -1U;
    if (((*__ctype_b_loc ())[(int) ((s[0]))] & (unsigned short int) _ISalpha))
        return android_name_to_id(s);
    (*__errno_location ()) = 0;
    v = (unsigned int) strtoul(s, 0, 0);
    if ((*__errno_location ()))
        return -1U;
    return v;
}

canonical_original_code:
unsigned int decode_uid(char *s)
{
    unsigned int v;
    if (!s || *s == '\0')
        return -1U;
    if (((*__ctype_b_loc ())[(int) ((s[0]))] & (unsigned short) _ISalpha))
        return android_name_to_id(s);
    (*__errno_location ()) = 0;
    v = (unsigned int) strtoul(s, 0, 0);
    if ((*__errno_location ()))
        return -1U;
    return v;
}

variable_types:
v
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall create_socket(const char *a1, int a2, __mode_t a3, __uid_t a4, __gid_t a5)
{
int v9; // eax
unsigned int v10; // er12
int v11; // edi
int *v13; // rax
char *v14; // rax
int v15; // edi
int *v16; // rax
char *v17; // rax
char *v18; // rax
_BYTE v19[104]; // [rsp+0h] [rbp-A8h] BYREF
int v20; // [rsp+68h] [rbp-40h]
__int16 v21; // [rsp+6Ch] [rbp-3Ch]

v9 = socket(1, a2, 0);
if ( v9 < 0 )
{
v16 = _errno_location();
v10 = -1;
v17 = strerror(*v16);
log_write(3, "<3>init: Failed to open socket '%s': %s\n", a1, v17);
return v10;
}
v10 = v9;
memset(v19, 0, sizeof(v19));
*(_WORD *)v19 = 1;
v21 = 0;
v20 = 0;
snprintf(&v19[2], 0x6CuLL, "/dev/socket/%s", a1);
if ( unlink(&v19[2]) )
{
v11 = *_errno_location();
if ( v11 != 2 )
{
v18 = strerror(v11);
log_write(3, "<3>init: Failed to unlink old socket '%s': %s\n", a1, v18);
goto LABEL_8;
}
}
if ( bind(v10, (const struct sockaddr *)v19, 0x6Eu) )
{
v13 = _errno_location();
v14 = strerror(*v13);
log_write(3, "<3>init: Failed to bind socket '%s': %s\n", a1, v14);
unlink(&v19[2]);
LABEL_8:
v15 = v10;
v10 = -1;
close(v15);
return v10;
}
chown(&v19[2], a4, a5);
chmod(&v19[2], a3);
log_write(6, "<6>init: Created socket '%s' with mode '%o', user '%d', group '%d'\n", &v19[2], a3, a4, a5);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, int a2, __mode_t a3, __uid_t a4, __gid_t a5)
{
int v9; // eax
unsigned int v10; // er12
int v11; // edi
int *v13; // rax
char *v14; // rax
int v15; // edi
int *v16; // rax
char *v17; // rax
char *v18; // rax
_BYTE v19[104]; // [rsp+0h] [rbp-A8h] BYREF
int v20; // [rsp+68h] [rbp-40h]
__int16 v21; // [rsp+6Ch] [rbp-3Ch]

v9 = socket(1, a2, 0);
if ( v9 < 0 )
{
v16 = _errno_location();
v10 = -1;
v17 = strerror(*v16);
func3(3, "<3>init: Failed to open socket '%s': %s\n", a1, v17);
return v10;
}
v10 = v9;
memset(v19, 0, sizeof(v19));
*(_WORD *)v19 = 1;
v21 = 0;
v20 = 0;
snprintf(&v19[2], 0x6CuLL, "/dev/socket/%s", a1);
if ( unlink(&v19[2]) )
{
v11 = *_errno_location();
if ( v11 != 2 )
{
v18 = strerror(v11);
func3(3, "<3>init: Failed to unlink old socket '%s': %s\n", a1, v18);
goto LABEL_8;
}
}
if ( bind(v10, (const struct sockaddr *)v19, 0x6Eu) )
{
v13 = _errno_location();
v14 = strerror(*v13);
func3(3, "<3>init: Failed to bind socket '%s': %s\n", a1, v14);
unlink(&v19[2]);
LABEL_8:
v15 = v10;
v10 = -1;
close(v15);
return v10;
}
chown(&v19[2], a4, a5);
chmod(&v19[2], a3);
func3(6, "<6>init: Created socket '%s' with mode '%o', user '%d', group '%d'\n", &v19[2], a3, a4, a5);
return v10;
}

original_code:
int create_socket(const char *name, int type, mode_t perm, uid_t uid, gid_t gid)
{
    struct sockaddr_un addr;
    int fd, ret;
    fd = socket(1, type, 0);
    if (fd < 0) {
        log_write(3, "<3>init: " "Failed to open socket '%s': %s\n", name, strerror((*__errno_location ())));
        return -1;
    }
    memset(&addr, 0 , sizeof(addr));
    addr.sun_family = 1;
    snprintf(addr.sun_path, sizeof(addr.sun_path), "/dev/socket""/%s",
             name);
    ret = unlink(addr.sun_path);
    if (ret != 0 && (*__errno_location ()) != 2) {
        log_write(3, "<3>init: " "Failed to unlink old socket '%s': %s\n", name, strerror((*__errno_location ())));
        goto out_close;
    }
    ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr));
    if (ret) {
        log_write(3, "<3>init: " "Failed to bind socket '%s': %s\n", name, strerror((*__errno_location ())));
        goto out_unlink;
    }
    chown(addr.sun_path, uid, gid);
    chmod(addr.sun_path, perm);
    log_write(6, "<6>init: " "Created socket '%s' with mode '%o', user '%d', group '%d'\n", addr.sun_path, perm, uid, gid);
    return fd;
out_unlink:
    unlink(addr.sun_path);
out_close:
    close(fd);
    return -1;
}

canonical_original_code:
int create_socket(char *name, int type, unsigned int perm, unsigned int uid, unsigned int gid)
{
    struct sockaddr_un addr;
    int fd; int ret;
    fd = socket(1, type, 0);
    if (fd < 0) {
        log_write(3, "<3>init: " "Failed to open socket '%s': %s\n", name, strerror((*__errno_location ())));
        return -1;
    }
    memset(&addr, 0 , sizeof(addr));
    addr.sun_family = 1;
    snprintf(addr.sun_path, sizeof(addr.sun_path), "/dev/socket""/%s",
             name);
    ret = unlink(addr.sun_path);
    if (ret != 0 && (*__errno_location ()) != 2) {
        log_write(3, "<3>init: " "Failed to unlink old socket '%s': %s\n", name, strerror((*__errno_location ())));
        goto out_close;
    }
    ret = bind(fd, (struct sockaddr *) &addr, sizeof (addr));
    if (ret) {
        log_write(3, "<3>init: " "Failed to bind socket '%s': %s\n", name, strerror((*__errno_location ())));
        goto out_unlink;
    }
    chown(addr.sun_path, uid, gid);
    chmod(addr.sun_path, perm);
    log_write(6, "<6>init: " "Created socket '%s' with mode '%o', user '%d', group '%d'\n", addr.sun_path, perm, uid, gid);
    return fd;
out_unlink:
    unlink(addr.sun_path);
out_close:
    close(fd);
    return -1;
}

variable_types: type int

variable_types:
perm
unsigned int

variable_types:
uid
unsigned int

variable_types:
gid
unsigned int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types: ret int


main

canonical_name: main

repo: absabs/objdl

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbp
FILE *v5; // r13
const char **v6; // r12
__int64 v7; // r14
int v8; // er15
char *v9; // rax
__int64 v10; // rbx
const unsigned __int16 **v11; // rax
char *v12; // rsi
char v13; // dl
const unsigned __int16 *v14; // rcx
char *v15; // rax
int v16; // ebx
int v17; // eax
__int64 v18; // rbx
const char *v19; // r14
int result; // eax
char *v21; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

v3 = fopen(argv[1], "r");
if ( v3 )
{
v4 = v3;
v5 = fopen(argv[2], "w");
if ( v5 )
{
v6 = (const char **)malloc(0x2000uLL);
if ( v6 )
{
v7 = 0LL;
v8 = 1024;
fwrite("#include \"sym.h\"\n\n", 1uLL, 0x12uLL, v5);
while ( fgets(s, 64, v4) )
{
if ( !s[63] )
{
fwrite("Scanner buffer overrun\n", 1uLL, 0x17uLL, _bss_start);
return -1;
}
v9 = strchr(s, 47);
v21 = v9;
if ( v9 && v9[1] == 42 )
{
*v9 = 0;
v21 = v9 + 2;
do
{
while ( (unsigned int)mygc(&v21, v4) != 42 )
;
do
v17 = mygc(&v21, v4);
while ( v17 == 42 );
}
while ( v17 != 47 );
}
v10 = s[0];
v21 = s;
if ( s[0] )
{
v11 = __ctype_b_loc();
v12 = s;
v13 = 0;
v14 = *v11;
v15 = s;
while ( (v14[v10] & 0x2000) == 0 )
{
v10 = *++v15;
v13 = 1;
if ( !(_BYTE)v10 )
{
v21 = v15;
goto LABEL_16;
}
v12 = v15;
}
if ( v13 )
v21 = v12;
}
else
{
v15 = s;
}
LABEL_16:
*v15 = 0;
if ( strlen(s) && !(unsigned int)find_duplicate(v6, (unsigned int)v7, s) )
{
v16 = v7 + 1;
fprintf(v5, "extern int %s;\n", s);
v6[v7] = strdup(s);
v7 = (int)v7 + 1;
if ( v8 < v16 )
{
v8 += 1024;
v6 = (const char **)realloc(v6, 8LL * v8);
}
}
}
fwrite("\nstatic struct dl_symbol system_symbols[] = {\n", 1uLL, 0x2EuLL, v5);
if ( (_DWORD)v7 )
{
v18 = (__int64)&v6[(unsigned int)(v7 - 1) + 1];
do
{
fwrite("\t{\n", 1uLL, 3uLL, v5);
v19 = *v6++;
fprintf(v5, "\t\t.name = \"%s\",\n", v19);
fprintf(v5, "\t\t.value = (unsigned long)&%s,\n", v19);
fwrite("\t},\n", 1uLL, 4uLL, v5);
}
while ( v6 != (const char **)v18 );
}
fwrite("\t{\n", 1uLL, 3uLL, v5);
fwrite("\t0, /* terminating record */\n", 1uLL, 0x1DuLL, v5);
fwrite("\t},\n", 1uLL, 4uLL, v5);
fwrite("};\n", 1uLL, 3uLL, v5);
fwrite("struct dl_symbl *cexpSystemSymbols = system_symbols;\n", 1uLL, 0x35uLL, v5);
result = 0;
}
else
{
puts("no memory");
fclose(v4);
fclose(v5);
result = -1;
}
}
else
{
perror("opening source file");
result = -1;
}
}
else
{
perror("opening config file");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbp
FILE *v5; // r13
const char **v6; // r12
__int64 v7; // r14
int v8; // er15
char *v9; // rax
__int64 v10; // rbx
const unsigned __int16 **v11; // rax
char *v12; // rsi
char v13; // dl
const unsigned __int16 *v14; // rcx
char *v15; // rax
int v16; // ebx
int v17; // eax
__int64 v18; // rbx
const char *v19; // r14
int result; // eax
char *v21; // [rsp+8h] [rbp-80h] BYREF
char s[120]; // [rsp+10h] [rbp-78h] BYREF

v3 = fopen(argv[1], "r");
if ( v3 )
{
v4 = v3;
v5 = fopen(argv[2], "w");
if ( v5 )
{
v6 = (const char **)malloc(0x2000uLL);
if ( v6 )
{
v7 = 0LL;
v8 = 1024;
fwrite("#include \"sym.h\"\n\n", 1uLL, 0x12uLL, v5);
while ( fgets(s, 64, v4) )
{
if ( !s[63] )
{
fwrite("Scanner buffer overrun\n", 1uLL, 0x17uLL, _bss_start);
return -1;
}
v9 = strchr(s, 47);
v21 = v9;
if ( v9 && v9[1] == 42 )
{
*v9 = 0;
v21 = v9 + 2;
do
{
while ( (unsigned int)func7(&v21, v4) != 42 )
;
do
v17 = func7(&v21, v4);
while ( v17 == 42 );
}
while ( v17 != 47 );
}
v10 = s[0];
v21 = s;
if ( s[0] )
{
v11 = __ctype_b_loc();
v12 = s;
v13 = 0;
v14 = *v11;
v15 = s;
while ( (v14[v10] & 0x2000) == 0 )
{
v10 = *++v15;
v13 = 1;
if ( !(_BYTE)v10 )
{
v21 = v15;
goto LABEL_16;
}
v12 = v15;
}
if ( v13 )
v21 = v12;
}
else
{
v15 = s;
}
LABEL_16:
*v15 = 0;
if ( strlen(s) && !(unsigned int)func8(v6, (unsigned int)v7, s) )
{
v16 = v7 + 1;
fprintf(v5, "extern int %s;\n", s);
v6[v7] = strdup(s);
v7 = (int)v7 + 1;
if ( v8 < v16 )
{
v8 += 1024;
v6 = (const char **)realloc(v6, 8LL * v8);
}
}
}
fwrite("\nstatic struct dl_symbol system_symbols[] = {\n", 1uLL, 0x2EuLL, v5);
if ( (_DWORD)v7 )
{
v18 = (__int64)&v6[(unsigned int)(v7 - 1) + 1];
do
{
fwrite("\t{\n", 1uLL, 3uLL, v5);
v19 = *v6++;
fprintf(v5, "\t\t.name = \"%s\",\n", v19);
fprintf(v5, "\t\t.value = (unsigned long)&%s,\n", v19);
fwrite("\t},\n", 1uLL, 4uLL, v5);
}
while ( v6 != (const char **)v18 );
}
fwrite("\t{\n", 1uLL, 3uLL, v5);
fwrite("\t0, /* terminating record */\n", 1uLL, 0x1DuLL, v5);
fwrite("\t},\n", 1uLL, 4uLL, v5);
fwrite("};\n", 1uLL, 3uLL, v5);
fwrite("struct dl_symbl *cexpSystemSymbols = system_symbols;\n", 1uLL, 0x35uLL, v5);
result = 0;
}
else
{
puts("no memory");
fclose(v4);
fclose(v5);
result = -1;
}
}
else
{
perror("opening source file");
result = -1;
}
}
else
{
perror("opening config file");
result = -1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
    char *libname, *symname, *prog = *argv;
    get_options(argc, argv, &libname, &symname);
    if (symname == ((void *)0)) {
        fprintf(stderr, "You must specify a symbol!\n");
        print_help(prog);
        exit(1);
    }
    if (libname == ((void *)0)) {
        fprintf(stderr, "You must specify a lib!\n");
        print_help(prog);
        exit(1);
    }
    demo(libname, symname);
    if (libname != ((void *)0)) free(libname);
    if (symname != ((void *)0)) free(symname);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *libname; char *symname; char *prog = *argv;
    get_options(argc, argv, &libname, &symname);
    if (symname == ((void *)0)) {
        fprintf(stderr, "You must specify a symbol!\n");
        print_help(prog);
        exit(1);
    }
    if (libname == ((void *)0)) {
        fprintf(stderr, "You must specify a lib!\n");
        print_help(prog);
        exit(1);
    }
    demo(libname, symname);
    if (libname != ((void *)0)) free(libname);
    if (symname != ((void *)0)) free(symname);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
libname
char *

variable_types:
symname
char *

variable_types:
prog
char *


decompiled_code:
__int64 __fastcall find_duplicate(unsigned __int64 a1, int a2, const char *a3)
{
const char **v3; // rbx

v3 = (const char **)(a1 + 8LL * a2 - 8);
if ( a1 > (unsigned __int64)v3 )
return 0LL;
while ( strcmp(*v3, a3) )
{
if ( a1 > (unsigned __int64)--v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1, int a2, const char *a3)
{
const char **v3; // rbx

v3 = (const char **)(a1 + 8LL * a2 - 8);
if ( a1 > (unsigned __int64)v3 )
return 0LL;
while ( strcmp(*v3, a3) )
{
if ( a1 > (unsigned __int64)--v3 )
return 0LL;
}
return 1LL;
}

original_code:
static int
find_duplicate(struct namerec *rec, int count, char *name)
{
 struct namerec *p;
 for (p = rec + count - 1; p >= rec; --p) {
  if (!strcmp(p->name, name))
   return 1;
 }
 return 0;
}

variable_types:
rec
struct namerec { char *name; } *

variable_types: count int

variable_types:
p
struct namerec { char *name; } *


decompiled_code:
int __fastcall print_help(const char *a1)
{
int result; // eax
const char *v2; // rcx
unsigned __int64 v3; // rbx
const char *v4; // r8
char *v5; // r9
__int64 v6; // rdx

fprintf(stdout, "invokation:\n\t%s [-l <libname>] -s <symbol name>\n\t%s -h\n\n", a1, a1);
result = fprintf(stdout, "options:\n");
v2 = long_options.name;
if ( long_options.name )
{
v3 = 0LL;
do
{
v4 = (const char *)&unk_22D;
v5 = descriptions[v3 / 8];
v6 = *((unsigned int *)&long_options.val + v3);
if ( *(&long_options.has_arg + v3) )
v4 = " (argument)";
v3 += 8LL;
result = fprintf(stdout, "\t-%c/--%s%s: %s\n", v6, v2, v4, v5);
v2 = *(const char **)((char *)&long_options.name + 4 * v3);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax
const char *v2; // rcx
unsigned __int64 v3; // rbx
const char *v4; // r8
char *v5; // r9
__int64 v6; // rdx

fprintf(stdout, "invokation:\n\t%s [-l <libname>] -s <symbol name>\n\t%s -h\n\n", a1, a1);
result = fprintf(stdout, "options:\n");
v2 = long_options.name;
if ( long_options.name )
{
v3 = 0LL;
do
{
v4 = (const char *)&unk_22D;
v5 = descriptions[v3 / 8];
v6 = *((unsigned int *)&long_options.val + v3);
if ( *(&long_options.has_arg + v3) )
v4 = " (argument)";
v3 += 8LL;
result = fprintf(stdout, "\t-%c/--%s%s: %s\n", v6, v2, v4, v5);
v2 = *(const char **)((char *)&long_options.name + 4 * v3);
}
while ( v2 );
}
return result;
}

original_code:
void print_help(const char *name) {
    fprintf(stdout,
            "invokation:\n"
            "\t%s [-l <libname>] -s <symbol name>\n"
            "\t%s -h\n\n", name, name);
    fprintf(stdout, "options:\n");
    struct option *opt = long_options;
    const char **desc = descriptions;
    while (opt->name) {
        fprintf(stdout, "\t-%c/--%s%s: %s\n",
                opt->val,
                opt->name,
                (opt->has_arg ? " (argument)" : ""),
                *desc);
        opt++;
        desc++;
    }
}

canonical_original_code:
void print_help(char *name) {
    fprintf(stdout,
            "invokation:\n"
            "\t%s [-l <libname>] -s <symbol name>\n"
            "\t%s -h\n\n", name, name);
    fprintf(stdout, "options:\n");
    struct option *opt = long_options;
    char **desc = descriptions;
    while (opt->name) {
        fprintf(stdout, "\t-%c/--%s%s: %s\n",
                opt->val,
                opt->name,
                (opt->has_arg ? " (argument)" : ""),
                *desc);
        opt++;
        desc++;
    }
}

variable_types:
name
char *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } *

variable_types:
desc
char **


decompiled_code:
__int64 __fastcall get_options(int argc, char **argv, char **a3, char **a4)
{
int v6; // eax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

*a3 = 0LL;
*a4 = 0LL;
while ( 1 )
{
longind[0] = 0;
v6 = getopt_long(argc, argv, "l:s:h", &long_options, longind);
if ( v6 == -1 )
return (unsigned int)optind;
if ( v6 == 108 )
{
*a3 = strdup(optarg);
}
else if ( v6 <= 108 )
{
if ( v6 != 63 )
{
if ( v6 == 104 )
{
print_help(*argv);
exit(1);
}
LABEL_12:
fprintf(stderr, "Unknown option");
exit(1);
}
}
else
{
if ( v6 != 115 )
goto LABEL_12;
*a4 = strdup(optarg);
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char **argv, char **a3, char **a4)
{
int v6; // eax
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

*a3 = 0LL;
*a4 = 0LL;
while ( 1 )
{
longind[0] = 0;
v6 = getopt_long(argc, argv, "l:s:h", &long_options, longind);
if ( v6 == -1 )
return (unsigned int)optind;
if ( v6 == 108 )
{
*a3 = strdup(optarg);
}
else if ( v6 <= 108 )
{
if ( v6 != 63 )
{
if ( v6 == 104 )
{
func0(*argv);
exit(1);
}
LABEL_12:
fprintf(stderr, "Unknown option");
exit(1);
}
}
else
{
if ( v6 != 115 )
goto LABEL_12;
*a4 = strdup(optarg);
}
}
}

original_code:
int get_options(int argc, char **argv, char **lib, char **sym)
{
    int c;
    *lib = 0;
    *sym = 0;
    while (1) {
        int option_index = 0;
        c = getopt_long (argc, argv,
                         "l:s:h",
                         long_options,
                         &option_index);
        if (c == -1) break;
        switch (c) {
  case 'l':
            *lib = strdup(optarg);
   break;
        case 's':
            *sym = strdup(optarg);
            break;
        case 'h': print_help(argv[0]); exit(1); break;
        case '?':
            break;
        default:
            fprintf(stderr, "Unknown option");
            exit(1);
        }
    }
    return optind;
}

variable_types:
lib
char **

variable_types:
sym
char **

variable_types: c int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
void *ptr; // [rsp+0h] [rbp-18h] BYREF
void *v6; // [rsp+8h] [rbp-10h] BYREF

v3 = *argv;
get_options(argc, (char **)argv, (char **)&ptr, (char **)&v6);
if ( !v6 )
{
fprintf(stderr, "You must specify a symbol!\n");
goto LABEL_9;
}
if ( !ptr )
{
fprintf(stderr, "You must specify a lib!\n");
LABEL_9:
print_help(v3);
exit(1);
}
demo();
if ( ptr )
free(ptr);
if ( v6 )
free(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
void *ptr; // [rsp+0h] [rbp-18h] BYREF
void *v6; // [rsp+8h] [rbp-10h] BYREF

v3 = *argv;
func1(argc, (char **)argv, (char **)&ptr, (char **)&v6);
if ( !v6 )
{
fprintf(stderr, "You must specify a symbol!\n");
goto LABEL_9;
}
if ( !ptr )
{
fprintf(stderr, "You must specify a lib!\n");
LABEL_9:
func0(v3);
exit(1);
}
demo();
if ( ptr )
free(ptr);
if ( v6 )
free(v6);
return 0;
}


dlerror

decompiled_code:
__int64 dlerror()
{
__int64 v0; // rax

v0 = dl_last_err;
dl_last_err = 0;
return dl_errors[v0];
}

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

v0 = dl_last_err;
dl_last_err = 0;
return dl_errors[v0];
}

original_code:
const char *dlerror(void)
{
    const char *err = dl_errors[dl_last_err];
    dl_last_err = 0;
    return err;
}

canonical_original_code:
char *dlerror()
{
    char *err = dl_errors[dl_last_err];
    dl_last_err = 0;
    return err;
}

variable_types:
err
char *

return_type: char *


kkget

decompiled_code:
__int64 kkget()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 2LL;
}

original_code:
int kkget()
{
 return 2;
}

canonical_original_code:
int kkget()
{
 return 2;
}


usage

repo: absmall/wordsearch

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "Usage: %s [options] wordlist\n", a1);
fputc(10, stderr);
fwrite("-d dim\tSpecify the number of dimensions in the puzzle\n", 1uLL, 0x36uLL, stderr);
fwrite("-g\tFill the unused space with garbage letters\n", 1uLL, 0x2EuLL, stderr);
fwrite("-h\tHelp\n", 1uLL, 8uLL, stderr);
fwrite("-m message\tMessage to hide in the unused letters\n", 1uLL, 0x31uLL, stderr);
fwrite(
"-s size\tSpecify the size of each dimension. This can either be a single integer the size\n",
1uLL,
0x59uLL,
stderr);
fwrite(
" \tof each dimension, or a set of integers separated by a single letter x for each\n",
1uLL,
0x58uLL,
stderr);
fwrite(
" \tdimension. In this case, the number of parameters must match the dimension.\n",
1uLL,
0x54uLL,
stderr);
fwrite("-n\tDon't fit words, just fill the grid using a message (useful for import)\n", 1uLL, 0x4BuLL, stderr);
fwrite("-v\tEnable additional prints\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
fprintf(stderr, "Usage: %s [options] wordlist\n", a1);
fputc(10, stderr);
fwrite("-d dim\tSpecify the number of dimensions in the puzzle\n", 1uLL, 0x36uLL, stderr);
fwrite("-g\tFill the unused space with garbage letters\n", 1uLL, 0x2EuLL, stderr);
fwrite("-h\tHelp\n", 1uLL, 8uLL, stderr);
fwrite("-m message\tMessage to hide in the unused letters\n", 1uLL, 0x31uLL, stderr);
fwrite(
"-s size\tSpecify the size of each dimension. This can either be a single integer the size\n",
1uLL,
0x59uLL,
stderr);
fwrite(
" \tof each dimension, or a set of integers separated by a single letter x for each\n",
1uLL,
0x58uLL,
stderr);
fwrite(
" \tdimension. In this case, the number of parameters must match the dimension.\n",
1uLL,
0x54uLL,
stderr);
fwrite("-n\tDon't fit words, just fill the grid using a message (useful for import)\n", 1uLL, 0x4BuLL, stderr);
fwrite("-v\tEnable additional prints\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}

original_code:
void usage(char *progname)
{
 fprintf(stderr, "Usage: %s [options] wordlist\n", progname);
 fprintf(stderr, "\n");
 fprintf(stderr, "-d dim\tSpecify the number of dimensions in the puzzle\n");
 fprintf(stderr, "-g\tFill the unused space with garbage letters\n");
 fprintf(stderr, "-h\tHelp\n");
 fprintf(stderr, "-m message\tMessage to hide in the unused letters\n");
 fprintf(stderr, "-s size\tSpecify the size of each dimension. This can either be a single integer the size\n");
  fprintf(stderr, "       \tof each dimension, or a set of integers separated by a single letter x for each\n");
  fprintf(stderr, "       \tdimension. In this case, the number of parameters must match the dimension.\n");
 fprintf(stderr, "-n\tDon't fit words, just fill the grid using a message (useful for import)\n");
 fprintf(stderr, "-v\tEnable additional prints\n");
 exit(1);
}

variable_types:
progname
char *


repo: acceso/jOS

decompiled_code:
void exc_30_security()
{
kprintf("Security exception!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func0()
{
kprintf("Security exception!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_30_security(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq $0\n\t" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("Security exception!\n");
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "addq $8, %rsp\n\t" "iretq\n\t" );
}

variable_types: struct intr_frame { unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long rdi; unsigned long rsi; unsigned long rbx; unsigned long rdx; unsigned long rcx; unsigned long rax; unsigned int ecode; unsigned int pad4; unsigned long rip; unsigned char cs; unsigned char pad0; unsigned int pad1; unsigned long rflags; unsigned long rsp; unsigned char ss; unsigned char pad2; unsigned int pad3; }


decompiled_code:
void exc_19_simd()
{
kprintf("SIMD exception!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func1()
{
kprintf("SIMD exception!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_19_simd(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq $0\n\t" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("SIMD exception!\n");
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "addq $8, %rsp\n\t" "iretq\n\t" );
}

user_defined_types: struct intr_frame { unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long rdi; unsigned long rsi; unsigned long rbx; unsigned long rdx; unsigned long rcx; unsigned long rax; unsigned int ecode; unsigned int pad4; unsigned long rip; unsigned char cs; unsigned char pad0; unsigned int pad1; unsigned long rflags; unsigned long rsp; unsigned char ss; unsigned char pad2; unsigned int pad3; }


decompiled_code:
void exc_18_machinecheck()
{
kprintf("Machine check!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func2()
{
kprintf("Machine check!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_18_machinecheck(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq $0\n\t" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("Machine check!\n");
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "addq $8, %rsp\n\t" "iretq\n\t" );
}


decompiled_code:
void exc_17_misalignment()
{
kprintf("Misaligned memory access!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func3()
{
kprintf("Misaligned memory access!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_17_misalignment(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("Misaligned memory access!\n");
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "iretq\n\t" );
}


decompiled_code:
void exc_16_math_pending()
{
kprintf("x87 floating-point exception pending!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func4()
{
kprintf("x87 floating-point exception pending!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_16_math_pending(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq $0\n\t" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("x87 floating-point exception pending!\n");
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "addq $8, %rsp\n\t" "iretq\n\t" );
}


decompiled_code:
void exc_14_pf()
{
kprintf("Page fault!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func5()
{
kprintf("Page fault!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_14_pf(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("Page fault!\n");
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "iretq\n\t" );
}


decompiled_code:
void exc_13_gp()
{
kprintf("General protection fault!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func6()
{
kprintf("General protection fault!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_13_gp(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("General protection fault!\n");
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "iretq\n\t" );
}


decompiled_code:
void exc_12_stack()
{
unsigned int v0; // [rsp+0h] [rbp-8h]

kprintf("Stack exception, segment selector: 0x%lx\n", v0);
__asm { iretq }
}

canonical_decompiled_code:
void func7()
{
unsigned int v0; // [rsp+0h] [rbp-8h]

kprintf("Stack exception, segment selector: 0x%lx\n", v0);
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_12_stack(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("Stack exception, segment selector: 0x%lx\n", r.ecode);
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "iretq\n\t" );
}


decompiled_code:
void exc_11_nosuchsegment()
{
kprintf("Segment not present!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func8()
{
kprintf("Segment not present!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_11_nosuchsegment(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 kprintf("Segment not present!\n");
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "iretq\n\t" );
}