decompiled_code:
void __fastcall handle_device_event(__int64 a1)
{
char *v2; // rax
char *v3; // r12
const void *v4; // r13
bool v5; // zf
int v6; // ebp
const char *v7; // rcx
char v8[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 )
{
if ( !memcmp(*(const void **)(a1 + 16), "block", 5uLL) )
{
mkdir("/dev/block/", 0x1EDu);
v6 = 1;
v7 = "/dev/block/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "graphics", 8uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/graphics/", 0x1EDu);
v7 = "/dev/graphics/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "oncrpc", 6uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/oncrpc/", 0x1EDu);
v7 = "/dev/oncrpc/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "adsp", 4uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/adsp/", 0x1EDu);
v7 = "/dev/adsp/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "msm_camera", 0xAuLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/msm_camera/", 0x1EDu);
v7 = "/dev/msm_camera/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "input", 5uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/input/", 0x1EDu);
v7 = "/dev/input/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "mtd", 3uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/mtd/", 0x1EDu);
v7 = "/dev/mtd/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "sound", 5uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/snd/", 0x1EDu);
v7 = "/dev/snd/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "misc", 4uLL) == 0;
v6 = !v5;
if ( v5 )
{
v5 = memcmp(v4, "log_", 4uLL) == 0;
v7 = "/dev/";
if ( v5 )
{
mkdir("/dev/log/", 0x1EDu);
v4 = v3 + 5;
v6 = 0;
v7 = "/dev/log/";
}
}
else
{
v6 = 0;
v7 = "/dev/";
}
}
}
}
}
}
}
}
}
snprintf(v8, 0x60uLL, "%s%s", v7, (const char *)v4);
if ( !strcmp(*(const char **)a1, "add") )
{
make_device(v8, v6, *(_DWORD *)(a1 + 32), *(_DWORD *)(a1 + 36));
}
else if ( !strcmp(*(const char **)a1, "remove") )
{
unlink(v8);
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
char *v2; // rax
char *v3; // r12
const void *v4; // r13
bool v5; // zf
int v6; // ebp
const char *v7; // rcx
char v8[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 )
{
if ( !memcmp(*(const void **)(a1 + 16), "block", 5uLL) )
{
mkdir("/dev/block/", 0x1EDu);
v6 = 1;
v7 = "/dev/block/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "graphics", 8uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/graphics/", 0x1EDu);
v7 = "/dev/graphics/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "oncrpc", 6uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/oncrpc/", 0x1EDu);
v7 = "/dev/oncrpc/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "adsp", 4uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/adsp/", 0x1EDu);
v7 = "/dev/adsp/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "msm_camera", 0xAuLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/msm_camera/", 0x1EDu);
v7 = "/dev/msm_camera/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "input", 5uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/input/", 0x1EDu);
v7 = "/dev/input/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "mtd", 3uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/mtd/", 0x1EDu);
v7 = "/dev/mtd/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "sound", 5uLL) == 0;
v6 = !v5;
if ( v5 )
{
mkdir("/dev/snd/", 0x1EDu);
v7 = "/dev/snd/";
}
else
{
v5 = memcmp(*(const void **)(a1 + 16), "misc", 4uLL) == 0;
v6 = !v5;
if ( v5 )
{
v5 = memcmp(v4, "log_", 4uLL) == 0;
v7 = "/dev/";
if ( v5 )
{
mkdir("/dev/log/", 0x1EDu);
v4 = v3 + 5;
v6 = 0;
v7 = "/dev/log/";
}
}
else
{
v6 = 0;
v7 = "/dev/";
}
}
}
}
}
}
}
}
}
snprintf(v8, 0x60uLL, "%s%s", v7, (const char *)v4);
if ( !strcmp(*(const char **)a1, "add") )
{
func3(v8, v6, *(_DWORD *)(a1 + 32), *(_DWORD *)(a1 + 36));
}
else if ( !strcmp(*(const char **)a1, "remove") )
{
unlink(v8);
}
}
}
}
}

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; }


repo: absabs/init

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

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

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

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

return_type: int

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; // ebx
int v2; // ebp
int v3; // eax
int v4; // er12
char *v5; // [rsp+0h] [rbp-38h] BYREF
char *v6; // [rsp+8h] [rbp-30h] BYREF
char *file; // [rsp+10h] [rbp-28h] BYREF
char *ptr; // [rsp+18h] [rbp-20h] BYREF

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

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

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

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: struct uevent { char *action; char *path; char *subsystem; char *firmware; int major; int minor; } *

variable_types:
root
char *

variable_types:
loading
char *

variable_types:
data
char *

variable_types:
file
char *

variable_types: l int

return_type: void


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: pid int


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

v3 = 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, &v3, 4u);
if ( bind(v1, &addr, 0xCu) < 0 )
{
close(v1);
v1 = -1;
}
return v1;
}

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

v3 = 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, &v3, 4u);
if ( bind(v1, &addr, 0xCu) < 0 )
{
close(v1);
v1 = -1;
}
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 *v8; // rax
_DWORD *v9; // rbx
size_t v10; // rbp
void *v11; // rdi

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

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

v8 = malloc(0x28uLL);
if ( !v8 )
return 4294967284LL;
v9 = v8;
v10 = (int)(strlen((const char *)src) + 1);
v11 = malloc(v10);
*(_QWORD *)v9 = v11;
if ( !v11 )
return 4294967284LL;
memcpy(v11, src, v10);
v9[2] = a2;
v9[3] = a3;
v9[4] = a4;
*((_WORD *)v9 + 10) = a5;
list_add_tail(&devperms_partners, v9 + 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; // ebx
__suseconds_t v2; // rbp
__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; // ebx
__suseconds_t v2; // rbp
__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

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)
{
unsigned __int64 result; // rax
char v2; // bp
int *v3; // rbp

if ( !nptr )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
if ( *nptr )
{
v2 = *nptr;
if ( ((*_ctype_b_loc())[v2] & 0x400) != 0 )
{
result = android_name_to_id(nptr);
}
else
{
v3 = _errno_location();
*v3 = 0;
result = strtoul(nptr, 0LL, 0);
if ( *v3 )
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(char *nptr)
{
unsigned __int64 result; // rax
char v2; // bp
int *v3; // rbp

if ( !nptr )
return 0xFFFFFFFFLL;
result = 0xFFFFFFFFLL;
if ( *nptr )
{
v2 = *nptr;
if ( ((*_ctype_b_loc())[v2] & 0x400) != 0 )
{
result = func0(nptr);
}
else
{
v3 = _errno_location();
*v3 = 0;
result = strtoul(nptr, 0LL, 0);
if ( *v3 )
result = 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; // ebx
int v11; // edi
int *v13; // rax
char *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
_BYTE v18[104]; // [rsp+0h] [rbp-98h] BYREF
int v19; // [rsp+68h] [rbp-30h]
__int16 v20; // [rsp+6Ch] [rbp-2Ch]

v9 = socket(1, a2, 0);
if ( v9 < 0 )
{
v13 = _errno_location();
v14 = strerror(*v13);
log_write(3, "<3>init: Failed to open socket '%s': %s\n", a1, v14);
return (unsigned int)-1;
}
v10 = v9;
memset(v18, 0, sizeof(v18));
v19 = 0;
v20 = 0;
*(_WORD *)v18 = 1;
snprintf(&v18[2], 0x6CuLL, "/dev/socket/%s", a1);
if ( unlink(&v18[2]) )
{
v11 = *_errno_location();
if ( v11 != 2 )
{
v15 = strerror(v11);
log_write(3, "<3>init: Failed to unlink old socket '%s': %s\n", a1, v15);
LABEL_10:
close(v10);
return (unsigned int)-1;
}
}
if ( bind(v10, (const struct sockaddr *)v18, 0x6Eu) )
{
v16 = _errno_location();
v17 = strerror(*v16);
log_write(3, "<3>init: Failed to bind socket '%s': %s\n", a1, v17);
unlink(&v18[2]);
goto LABEL_10;
}
chown(&v18[2], a4, a5);
chmod(&v18[2], a3);
log_write(6, "<6>init: Created socket '%s' with mode '%o', user '%d', group '%d'\n", &v18[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; // ebx
int v11; // edi
int *v13; // rax
char *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
_BYTE v18[104]; // [rsp+0h] [rbp-98h] BYREF
int v19; // [rsp+68h] [rbp-30h]
__int16 v20; // [rsp+6Ch] [rbp-2Ch]

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


repo: absabs/objdl

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

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

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

v4 = (const char **)(a1 + 8LL * a2 - 8);
if ( a1 > (unsigned __int64)v4 )
return 0LL;
while ( strcmp(*v4, a3) )
{
if ( a1 > (unsigned __int64)--v4 )
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; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rax
FILE *v4; // rbp
FILE *v5; // r12
_QWORD *v6; // r14
int v7; // er13
int v8; // er15
char *v9; // rax
char v10; // bl
const unsigned __int16 *v11; // rdx
char *v12; // rax
int result; // eax
int v14; // eax
const char **v15; // rbx
__int64 v16; // r13
const char *v17; // rbp
char v18[72]; // [rsp+0h] [rbp-88h] BYREF
char *v19[8]; // [rsp+48h] [rbp-40h] BYREF

v3 = fopen(argv[1], "r");
if ( v3 )
{
v4 = v3;
v5 = fopen(argv[2], "w");
if ( v5 )
{
v6 = malloc(0x2000uLL);
if ( v6 )
{
fwrite("#include \"sym.h\"\n\n", 1uLL, 0x12uLL, v5);
v7 = 0;
v8 = 1024;
while ( fgets(v18, 64, v4) )
{
if ( !v18[63] )
{
fwrite("Scanner buffer overrun\n", 1uLL, 0x17uLL, _bss_start);
return -1;
}
v9 = strchr(v18, 47);
v19[0] = v9;
if ( v9 && v9[1] == 42 )
{
*v9 = 0;
v19[0] = v9 + 2;
do
{
while ( mygc(v19, v4) != 42 )
;
do
v14 = mygc(v19, v4);
while ( v14 == 42 );
}
while ( v14 != 47 );
}
v19[0] = v18;
v10 = v18[0];
if ( v18[0] )
{
v11 = *__ctype_b_loc();
v12 = v18;
do
{
if ( (v11[v10] & 0x2000) != 0 )
break;
v19[0] = ++v12;
v10 = *v12;
}
while ( *v12 );
}
else
{
v12 = v18;
}
*v12 = 0;
if ( (int)strlen(v18) > 0 && !(unsigned int)find_duplicate((unsigned __int64)v6, v7, v18) )
{
fprintf(v5, "extern int %s;\n", v18);
v6[v7++] = strdup(v18);
if ( v8 < v7 )
{
v8 += 1024;
v6 = realloc(v6, 8LL * v8);
}
}
}
fwrite("\nstatic struct dl_symbol system_symbols[] = {\n", 1uLL, 0x2EuLL, v5);
if ( v7 > 0 )
{
v15 = (const char **)v6;
v16 = (__int64)&v6[(unsigned int)(v7 - 1) + 1];
do
{
fwrite("\t{\n", 1uLL, 3uLL, v5);
v17 = *v15;
fprintf(v5, "\t\t.name = \"%s\",\n", *v15);
fprintf(v5, "\t\t.value = (unsigned long)&%s,\n", v17);
fwrite("\t},\n", 1uLL, 4uLL, v5);
++v15;
}
while ( v15 != (const char **)v16 );
}
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; // r12
_QWORD *v6; // r14
int v7; // er13
int v8; // er15
char *v9; // rax
char v10; // bl
const unsigned __int16 *v11; // rdx
char *v12; // rax
int result; // eax
int v14; // eax
const char **v15; // rbx
__int64 v16; // r13
const char *v17; // rbp
char v18[72]; // [rsp+0h] [rbp-88h] BYREF
char *v19[8]; // [rsp+48h] [rbp-40h] BYREF

v3 = fopen(argv[1], "r");
if ( v3 )
{
v4 = v3;
v5 = fopen(argv[2], "w");
if ( v5 )
{
v6 = malloc(0x2000uLL);
if ( v6 )
{
fwrite("#include \"sym.h\"\n\n", 1uLL, 0x12uLL, v5);
v7 = 0;
v8 = 1024;
while ( fgets(v18, 64, v4) )
{
if ( !v18[63] )
{
fwrite("Scanner buffer overrun\n", 1uLL, 0x17uLL, _bss_start);
return -1;
}
v9 = strchr(v18, 47);
v19[0] = v9;
if ( v9 && v9[1] == 42 )
{
*v9 = 0;
v19[0] = v9 + 2;
do
{
while ( func7(v19, v4) != 42 )
;
do
v14 = func7(v19, v4);
while ( v14 == 42 );
}
while ( v14 != 47 );
}
v19[0] = v18;
v10 = v18[0];
if ( v18[0] )
{
v11 = *__ctype_b_loc();
v12 = v18;
do
{
if ( (v11[v10] & 0x2000) != 0 )
break;
v19[0] = ++v12;
v10 = *v12;
}
while ( *v12 );
}
else
{
v12 = v18;
}
*v12 = 0;
if ( (int)strlen(v18) > 0 && !(unsigned int)func8((unsigned __int64)v6, v7, v18) )
{
fprintf(v5, "extern int %s;\n", v18);
v6[v7++] = strdup(v18);
if ( v8 < v7 )
{
v8 += 1024;
v6 = realloc(v6, 8LL * v8);
}
}
}
fwrite("\nstatic struct dl_symbol system_symbols[] = {\n", 1uLL, 0x2EuLL, v5);
if ( v7 > 0 )
{
v15 = (const char **)v6;
v16 = (__int64)&v6[(unsigned int)(v7 - 1) + 1];
do
{
fwrite("\t{\n", 1uLL, 3uLL, v5);
v17 = *v15;
fprintf(v5, "\t\t.name = \"%s\",\n", *v15);
fprintf(v5, "\t\t.value = (unsigned long)&%s,\n", v17);
fwrite("\t},\n", 1uLL, 4uLL, v5);
++v15;
}
while ( v15 != (const char **)v16 );
}
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:
int __fastcall print_help(const char *a1)
{
int result; // eax
const char *v2; // rcx
unsigned __int64 v3; // rbx
const char *v4; // r8

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_2CD;
if ( *(&long_options.has_arg + v3) )
v4 = " (argument)";
result = fprintf(
stdout,
"\t-%c/--%s%s: %s\n",
*((unsigned int *)&long_options.val + v3),
v2,
v4,
descriptions[v3 / 8]);
v3 += 8LL;
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

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_2CD;
if ( *(&long_options.has_arg + v3) )
v4 = " (argument)";
result = fprintf(
stdout,
"\t-%c/--%s%s: %s\n",
*((unsigned int *)&long_options.val + v3),
v2,
v4,
descriptions[v3 / 8]);
v3 += 8LL;
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_11:
fprintf(stderr, "Unknown option");
exit(1);
}
}
else
{
if ( v6 != 115 )
goto LABEL_11;
*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_11:
fprintf(stderr, "Unknown option");
exit(1);
}
}
else
{
if ( v6 != 115 )
goto LABEL_11;
*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; // rbx
void *v5; // [rsp+0h] [rbp-18h] BYREF
void *ptr; // [rsp+8h] [rbp-10h] BYREF

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

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

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


dlerror

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

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

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

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

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:
__int64 lapic_eoi()
{
return lapic_write(0xB0u, 0);
}

canonical_decompiled_code:
__int64 func1()
{
return func0(0xB0u, 0);
}

original_code:
static inline void lapic_eoi(void)
{
 lapic_write(0xb0, 0);
}

canonical_original_code:
static inline void lapic_eoi()
{
 lapic_write(0xb0, 0);
}


decompiled_code:
void isr_generic_handler()
{
lapic_eoi();
__asm { iretq }
}

canonical_decompiled_code:
void func3()
{
func1();
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void isr_generic_handler(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" );
 lapic_eoi();
 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_30_security()
{
kprintf("Security exception!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func5()
{
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" );
}

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_19_simd()
{
kprintf("SIMD exception!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func6()
{
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" );
}


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

canonical_decompiled_code:
void func7()
{
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 func8()
{
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 func9()
{
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 func10()
{
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 func11()
{
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 func12()
{
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 func13()
{
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" );
}


decompiled_code:
void exc_10_tss_inval()
{
kprintf("Invalid TSS!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func14()
{
kprintf("Invalid TSS!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_10_tss_inval(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("Invalid TSS!\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_generic_handler()
{
kprintf("Exception!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func15()
{
kprintf("Exception!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_generic_handler(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("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" );
}


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

kprintf("Double fault! (%llp)\n", v0);
__asm { iretq }
}

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

kprintf("Double fault! (%llp)\n", v0);
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_8_doublefault(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("Double fault! (%llp)\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_7_nomathco()
{
kprintf("No math coprocessor!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func17()
{
kprintf("No math coprocessor!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_7_nomathco(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("No math coprocessor!\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_6_iopcode()
{
kprintf("Invalid opcode!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func18()
{
kprintf("Invalid opcode!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_6_iopcode(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("Invalid opcode!\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_5_bound()
{
kprintf("Bound!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func19()
{
kprintf("Bound!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_5_bound(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("Bound!\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_4_overflow()
{
kprintf("Overflow!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func20()
{
kprintf("Overflow!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_4_overflow(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("Overflow!\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_3_breakpoint()
{
kprintf("Breakpoint!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func21()
{
kprintf("Breakpoint!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_3_breakpoint(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("Breakpoint!\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_2_nmi()
{
kprintf("NMI!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func22()
{
kprintf("NMI!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_2_nmi(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("NMI!\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_1_debug()
{
kprintf("Debug!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func23()
{
kprintf("Debug!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_1_debug(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("Debug!\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_0_divideby0()
{
kprintf("Divide by 0!\n");
__asm { iretq }
}

canonical_decompiled_code:
void func24()
{
kprintf("Divide by 0!\n");
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void exc_0_divideby0(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("Divide by 0!\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 init_exceptions()
{
int i; // ebx
int j; // ebx

idt_set_gate(0, (__int64)exc_0_divideby0, 32, 142);
idt_set_gate(1u, (__int64)exc_1_debug, 32, 142);
idt_set_gate(2u, (__int64)exc_2_nmi, 32, 142);
idt_set_gate(3u, (__int64)exc_3_breakpoint, 32, 142);
idt_set_gate(4u, (__int64)exc_4_overflow, 32, 142);
idt_set_gate(5u, (__int64)exc_5_bound, 32, 142);
idt_set_gate(6u, (__int64)exc_6_iopcode, 32, 142);
idt_set_gate(7u, (__int64)exc_7_nomathco, 32, 142);
idt_set_gate(8u, (__int64)exc_8_doublefault, 32, 142);
idt_set_gate(9u, (__int64)exc_generic_handler, 32, 142);
idt_set_gate(0xAu, (__int64)exc_10_tss_inval, 32, 142);
idt_set_gate(0xCu, (__int64)exc_11_nosuchsegment, 32, 142);
idt_set_gate(0xDu, (__int64)exc_12_stack, 32, 142);
idt_set_gate(0xEu, (__int64)exc_13_gp, 32, 142);
idt_set_gate(0xFu, (__int64)exc_14_pf, 32, 142);
idt_set_gate(0x10u, (__int64)exc_generic_handler, 32, 142);
idt_set_gate(0x11u, (__int64)exc_16_math_pending, 32, 142);
idt_set_gate(0x12u, (__int64)exc_17_misalignment, 32, 142);
idt_set_gate(0x13u, (__int64)exc_18_machinecheck, 32, 142);
idt_set_gate(0xAu, (__int64)exc_19_simd, 32, 142);
for ( i = 20; i != 30; ++i )
idt_set_gate(i, (__int64)exc_generic_handler, 32, 142);
idt_set_gate(0x1Eu, (__int64)exc_30_security, 32, 142);
idt_set_gate(0x1Fu, (__int64)exc_generic_handler, 32, 142);
for ( j = 32; j != 255; ++j )
idt_set_gate(j, (__int64)isr_generic_handler, 32, 142);
set_idt_reg((__int64)&idtentry, 4095);
}

original_code:
void init_exceptions(void)
{
 u8 n;
 idt_set_gate(0, exc_0_divideby0, 0x20, 0x8e);
 idt_set_gate(1, exc_1_debug, 0x20, 0x8e);
 idt_set_gate(2, exc_2_nmi, 0x20, 0x8e);
 idt_set_gate(3, exc_3_breakpoint, 0x20, 0x8e);
 idt_set_gate(4, exc_4_overflow, 0x20, 0x8e);
 idt_set_gate(5, exc_5_bound, 0x20, 0x8e);
 idt_set_gate(6, exc_6_iopcode, 0x20, 0x8e);
 idt_set_gate(7, exc_7_nomathco, 0x20, 0x8e);
 idt_set_gate(8, exc_8_doublefault, 0x20, 0x8e);
 idt_set_gate(9, exc_generic_handler, 0x20, 0x8e);
 idt_set_gate(10, exc_10_tss_inval, 0x20, 0x8e);
 idt_set_gate(12, exc_11_nosuchsegment, 0x20, 0x8e);
 idt_set_gate(13, exc_12_stack, 0x20, 0x8e);
 idt_set_gate(14, exc_13_gp, 0x20, 0x8e);
 idt_set_gate(15, exc_14_pf, 0x20, 0x8e);
 idt_set_gate(16, exc_generic_handler, 0x20, 0x8e);
 idt_set_gate(17, exc_16_math_pending, 0x20, 0x8e);
 idt_set_gate(18, exc_17_misalignment, 0x20, 0x8e);
 idt_set_gate(19, exc_18_machinecheck, 0x20, 0x8e);
 idt_set_gate(10, exc_19_simd, 0x20, 0x8e);
 for (n = 20; n <= 29; n++)
  idt_set_gate(n, exc_generic_handler, 0x20, 0x8e);
 idt_set_gate(30, exc_30_security, 0x20, 0x8e);
 idt_set_gate(31, exc_generic_handler, 0x20, 0x8e);
 for (n = 32; n <= 254; n++)
  idt_set_gate(n, isr_generic_handler, 0x20, 0x8e);
 set_idt_reg(idtentry, sizeof(idtentry) - 1);
}

canonical_original_code:
void init_exceptions()
{
 unsigned char n;
 idt_set_gate(0, exc_0_divideby0, 0x20, 0x8e);
 idt_set_gate(1, exc_1_debug, 0x20, 0x8e);
 idt_set_gate(2, exc_2_nmi, 0x20, 0x8e);
 idt_set_gate(3, exc_3_breakpoint, 0x20, 0x8e);
 idt_set_gate(4, exc_4_overflow, 0x20, 0x8e);
 idt_set_gate(5, exc_5_bound, 0x20, 0x8e);
 idt_set_gate(6, exc_6_iopcode, 0x20, 0x8e);
 idt_set_gate(7, exc_7_nomathco, 0x20, 0x8e);
 idt_set_gate(8, exc_8_doublefault, 0x20, 0x8e);
 idt_set_gate(9, exc_generic_handler, 0x20, 0x8e);
 idt_set_gate(10, exc_10_tss_inval, 0x20, 0x8e);
 idt_set_gate(12, exc_11_nosuchsegment, 0x20, 0x8e);
 idt_set_gate(13, exc_12_stack, 0x20, 0x8e);
 idt_set_gate(14, exc_13_gp, 0x20, 0x8e);
 idt_set_gate(15, exc_14_pf, 0x20, 0x8e);
 idt_set_gate(16, exc_generic_handler, 0x20, 0x8e);
 idt_set_gate(17, exc_16_math_pending, 0x20, 0x8e);
 idt_set_gate(18, exc_17_misalignment, 0x20, 0x8e);
 idt_set_gate(19, exc_18_machinecheck, 0x20, 0x8e);
 idt_set_gate(10, exc_19_simd, 0x20, 0x8e);
 for (n = 20; n <= 29; n++)
  idt_set_gate(n, exc_generic_handler, 0x20, 0x8e);
 idt_set_gate(30, exc_30_security, 0x20, 0x8e);
 idt_set_gate(31, exc_generic_handler, 0x20, 0x8e);
 for (n = 32; n <= 254; n++)
  idt_set_gate(n, isr_generic_handler, 0x20, 0x8e);
 set_idt_reg(idtentry, sizeof(idtentry) - 1);
}

variable_types:
n
unsigned char


iowait

decompiled_code:
void iowait()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static inline void iowait(void)
{
 asm volatile(
  "jmp 1f\n\t"
  "1:\n\t"
  "jmp 1f\n\t"
  "1:\n\t"
  );
}

canonical_original_code:
static inline void iowait()
{
 asm volatile(
  "jmp 1f\n\t"
  "1:\n\t"
  "jmp 1f\n\t"
  "1:\n\t"
  );
}


decompiled_code:
__int64 __fastcall lapic_read(unsigned int a1)
{
return *(unsigned int *)(lapic + a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return *(unsigned int *)(lapic + a1);
}

original_code:
static inline u32 lapic_read(u32 reg)
{
 return *(volatile u32 *)(lapic[0].base + reg);
}

canonical_original_code:
static inline unsigned int lapic_read(unsigned int reg)
{
 return *(unsigned int *)(lapic[0].base + reg);
}

variable_types:
reg
unsigned int


decompiled_code:
__int64 lapic_eoi()
{
return lapic_write(0xB0u, 0);
}

canonical_decompiled_code:
__int64 func5()
{
return func4(0xB0u, 0);
}

original_code:
static inline void lapic_eoi(void)
{
 lapic_write(0xb0, 0);
}


decompiled_code:
__int64 __fastcall ioapic_regsel(unsigned __int8 a1)
{
__int64 result; // rax

result = ioapic;
*(_DWORD *)ioapic = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int8 a1)
{
__int64 result; // rax

result = ioapic;
*(_DWORD *)ioapic = a1;
return result;
}

original_code:
static inline void ioapic_regsel(u8 reg)
{
 *(volatile u32 *)(ioapic[0].base + 0x0) = reg;
}

canonical_original_code:
static inline void ioapic_regsel(unsigned char reg)
{
 *(unsigned int *)(ioapic[0].base + 0x0) = reg;
}

variable_types:
reg
unsigned char


decompiled_code:
__int64 __fastcall ioapic_read(unsigned __int8 a1)
{
ioapic_regsel(a1);
return *(unsigned int *)(ioapic + 16);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 a1)
{
func6(a1);
return *(unsigned int *)(ioapic + 16);
}

original_code:
static u32 ioapic_read(u8 reg)
{
 ioapic_regsel(reg);
 return *(volatile u32 *)(ioapic[0].base + 0x10);
}

canonical_original_code:
static unsigned int ioapic_read(unsigned char reg)
{
 ioapic_regsel(reg);
 return *(unsigned int *)(ioapic[0].base + 0x10);
}


decompiled_code:
__int64 __fastcall ioapic_redir_nint_to_reg(int a1)
{
return (unsigned int)(2 * a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
return (unsigned int)(2 * a1 + 16);
}

original_code:
static inline u8 ioapic_redir_nint_to_reg(u8 n)
{
 return n * 2 + 0x10;
}

canonical_original_code:
static inline unsigned char ioapic_redir_nint_to_reg(unsigned char n)
{
 return n * 2 + 0x10;
}

return_type: unsigned char


decompiled_code:
__int64 __fastcall ioapic_redir_read(unsigned __int8 a1)
{
unsigned __int8 v1; // bl
__int64 v2; // rbp

v1 = ioapic_redir_nint_to_reg(*((unsigned __int8 *)&ioapic + 3 * a1 + 10));
v2 = ioapic_read(v1 + 1) << 32;
return v2 | (unsigned int)ioapic_read(v1);
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 a1)
{
unsigned __int8 v1; // bl
__int64 v2; // rbp

v1 = func8(*((unsigned __int8 *)&ioapic + 3 * a1 + 10));
v2 = func7(v1 + 1) << 32;
return v2 | (unsigned int)func7(v1);
}

original_code:
static u64 ioapic_redir_read(u8 n)
{
 u64 v;
 u8 reg;
 reg = ioapic_redir_nint_to_reg(ioapic[0].pic[n].dest);
 v = ioapic_read(reg + 1);
 v <<= 32;
 v |= ioapic_read(reg);
 return v;
}

canonical_original_code:
static unsigned long ioapic_redir_read(unsigned char n)
{
 unsigned long v;
 unsigned char reg;
 reg = ioapic_redir_nint_to_reg(ioapic[0].pic[n].dest);
 v = ioapic_read(reg + 1);
 v <<= 32;
 v |= ioapic_read(reg);
 return v;
}

variable_types:
v
unsigned long


decompiled_code:
void pic_disable()
{
outb(0xA1u, 0xFFu);
outb(0x21u, 0xFFu);
}

canonical_decompiled_code:
void func10()
{
func2(0xA1u, 0xFFu);
func2(0x21u, 0xFFu);
}

original_code:
static void pic_disable(void)
{
 outb(0xa1, 0xff);
 outb(0x21, 0xff);
}

canonical_original_code:
static void pic_disable()
{
 outb(0xa1, 0xff);
 outb(0x21, 0xff);
}


decompiled_code:
void do_lapic_err()
{
kprintf("Lapic internal error.\n");
lapic_eoi();
__asm { iretq }
}

canonical_decompiled_code:
void func11()
{
kprintf("Lapic internal error.\n");
func5();
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void do_lapic_err(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("Lapic internal error.\n");
 lapic_eoi();
 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 do_spurious()
{
kprintf("Spurious int!\n");
lapic_eoi();
__asm { iretq }
}

canonical_decompiled_code:
void func12()
{
kprintf("Spurious int!\n");
func5();
__asm { iretq }
}

original_code:
__attribute__((aligned(16))) static void do_spurious(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("Spurious int!\n");
 lapic_eoi();
 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:
__int64 lapic_init()
{
if ( !lapic )
kpanic("Local apic not found");
msr_write(0x1Bu, lapic | 0x900);
*((_BYTE *)&lapic + 8) = ((unsigned int)lapic_read(0x20u) >> 24) & 0xF;
*((_BYTE *)&lapic + 9) = lapic_read(0x30u);
intr_install_handler(64LL, do_spurious);
lapic_write(0xF0u, 320);
lapic_write(0xE0u, -268435456);
lapic_write(0xD0u, 0x1000000);
lapic_write(0x80u, 0);
intr_install_handler(65LL, do_lapic_err);
lapic_write(0x370u, 65);
lapic_write(0x350u, 34560);
return lapic_write(0x360u, 1024);
}

canonical_decompiled_code:
__int64 func13()
{
if ( !lapic )
kpanic("Local apic not found");
func0(0x1Bu, lapic | 0x900);
*((_BYTE *)&lapic + 8) = ((unsigned int)func3(0x20u) >> 24) & 0xF;
*((_BYTE *)&lapic + 9) = func3(0x30u);
intr_install_handler(64LL, do_spurious);
func4(0xF0u, 320);
func4(0xE0u, -268435456);
func4(0xD0u, 0x1000000);
func4(0x80u, 0);
intr_install_handler(65LL, do_lapic_err);
func4(0x370u, 65);
func4(0x350u, 34560);
return func4(0x360u, 1024);
}

original_code:
static void lapic_init(void)
{
 if (lapic[0].base == 0)
  kpanic("Local apic not found");
 msr_write(0x1b,
  0x800 | 0x100 | (u64)((void *)(((u64)lapic[0].base) - 0xffff800000000000)));
 lapic[0].id = (u8)((lapic_read(0x20) >> 24) & 0xf);
 lapic[0].version = (u8)(lapic_read(0x30) & 0xff);
 intr_install_handler(64, do_spurious);
 lapic_write(0xf0, (1 << 8) | 64);
 lapic_write(0xe0, (0xf << 28));
 lapic_write(0xd0, 1 << 24);
 lapic_write(0x80, 0);
 intr_install_handler(65, do_lapic_err);
 lapic_write(0x370, 65);
 lapic_write(0x350, 0x8700);
 lapic_write(0x360, 0x400);
 return;
}

canonical_original_code:
static void lapic_init()
{
 if (lapic[0].base == 0)
  kpanic("Local apic not found");
 msr_write(0x1b,
  0x800 | 0x100 | (u64)((void *)(((unsigned long)lapic[0].base) - 0xffff800000000000)));
 lapic[0].id = (u8)((lapic_read(0x20) >> 24) & 0xf);
 lapic[0].version = (u8)(lapic_read(0x30) & 0xff);
 intr_install_handler(64, do_spurious);
 lapic_write(0xf0, (1 << 8) | 64);
 lapic_write(0xe0, (0xf << 28));
 lapic_write(0xd0, 1 << 24);
 lapic_write(0x80, 0);
 intr_install_handler(65, do_lapic_err);
 lapic_write(0x370, 65);
 lapic_write(0x350, 0x8700);
 lapic_write(0x360, 0x400);
 return;
}


decompiled_code:
__int64 __fastcall ioapic_write(unsigned __int8 a1, int a2)
{
__int64 result; // rax

ioapic_regsel(a1);
result = ioapic;
*(_DWORD *)(ioapic + 16) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned __int8 a1, int a2)
{
__int64 result; // rax

func6(a1);
result = ioapic;
*(_DWORD *)(ioapic + 16) = a2;
return result;
}

original_code:
void ioapic_write(u8 reg, u32 val)
{
 ioapic_regsel(reg);
 *(volatile u32 *)(ioapic[0].base + 0x10) = val;
}

canonical_original_code:
void ioapic_write(unsigned char reg, unsigned int val)
{
 ioapic_regsel(reg);
 *(unsigned int *)(ioapic[0].base + 0x10) = val;
}

variable_types:
val
unsigned int


decompiled_code:
__int64 __fastcall ioapic_redir_write(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int8 v3; // di
unsigned __int8 v4; // bp

result = 3LL * a1;
v3 = *((_BYTE *)&ioapic + result + 10);
if ( v3 <= 0x10u )
{
v4 = ioapic_redir_nint_to_reg(v3);
ioapic_write(v4, a2);
result = ioapic_write(v4 + 1, SHIDWORD(a2));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax
unsigned __int8 v3; // di
unsigned __int8 v4; // bp

result = 3LL * a1;
v3 = *((_BYTE *)&ioapic + result + 10);
if ( v3 <= 0x10u )
{
v4 = func8(v3);
func14(v4, a2);
result = func14(v4 + 1, SHIDWORD(a2));
}
return result;
}

original_code:
static void ioapic_redir_write(u8 n, u64 val)
{
 if (ioapic[0].pic[n].dest > 16)
  return;
 n = ioapic_redir_nint_to_reg(ioapic[0].pic[n].dest);
 ioapic_write(n, val & 0xffffffff);
 ioapic_write(n + 1, val >> 32);
}

canonical_original_code:
static void ioapic_redir_write(unsigned char n, unsigned long val)
{
 if (ioapic[0].pic[n].dest > 16)
  return;
 n = ioapic_redir_nint_to_reg(ioapic[0].pic[n].dest);
 ioapic_write(n, val & 0xffffffff);
 ioapic_write(n + 1, val >> 32);
}

variable_types:
val
unsigned long


original_code:
static void ioapic_redir(u8 n, u64 val)
{
 val |= (1 << 16);
 val |= 0x800;
 val |= 0xff00000000000000;
 if (ioapic[0].pic[n].edge == 0)
  val |= (1 << 15);
 if (ioapic[0].pic[n].active_high == 0)
  val |= (1 << 13);
 ioapic_redir_write(n, val);
}

canonical_original_code:
static void ioapic_redir(unsigned char n, unsigned long val)
{
 val |= (1 << 16);
 val |= 0x800;
 val |= 0xff00000000000000;
 if (ioapic[0].pic[n].edge == 0)
  val |= (1 << 15);
 if (ioapic[0].pic[n].active_high == 0)
  val |= (1 << 13);
 ioapic_redir_write(n, val);
}


decompiled_code:
__int64 ioapic_init()
{
__int64 i; // rbx

ioapic_write(0, *((unsigned __int8 *)&ioapic + 8));
*((_BYTE *)&ioapic + 9) = ioapic_read(1u);
for ( i = 32LL; i != 48; ++i )
ioapic_redir(i - 32, i);
lapic_eoi();
return kprintf(
"IOAPIC id=%p ver=%p enabled (%llp)\n",
*((unsigned __int8 *)&ioapic + 8),
*((unsigned __int8 *)&ioapic + 9),
ioapic + 0x800000000000LL);
}

canonical_decompiled_code:
__int64 func17()
{
__int64 i; // rbx

func14(0, *((unsigned __int8 *)&ioapic + 8));
*((_BYTE *)&ioapic + 9) = func7(1u);
for ( i = 32LL; i != 48; ++i )
func16(i - 32, i);
func5();
return kprintf(
"IOAPIC id=%p ver=%p enabled (%llp)\n",
*((unsigned __int8 *)&ioapic + 8),
*((unsigned __int8 *)&ioapic + 9),
ioapic + 0x800000000000LL);
}

original_code:
static void ioapic_init(void)
{
 u8 i;
 ioapic_write(0x0, ioapic[0].id);
 ioapic[0].version = (u8)(ioapic_read(0x1) & 0xff);
 for (i = 0; i < 16; i++)
  ioapic_redir(i, i + 32);
 lapic_eoi();
 kprintf("IOAPIC id=%p ver=%p enabled (%llp)\n",
  ioapic[0].id, ioapic[0].version, ((void *)(((u64)ioapic[0].base) - 0xffff800000000000)));
}

canonical_original_code:
static void ioapic_init()
{
 unsigned char i;
 ioapic_write(0x0, ioapic[0].id);
 ioapic[0].version = (u8)(ioapic_read(0x1) & 0xff);
 for (i = 0; i < 16; i++)
  ioapic_redir(i, i + 32);
 lapic_eoi();
 kprintf("IOAPIC id=%p ver=%p enabled (%llp)\n",
  ioapic[0].id, ioapic[0].version, ((void *)(((unsigned long)ioapic[0].base) - 0xffff800000000000)));
}

variable_types:
i
unsigned char


decompiled_code:
__int64 __fastcall ioapic_redir_unmask(unsigned __int8 a1)
{
unsigned __int8 v1; // bl
__int64 v2; // rax

v1 = *((_BYTE *)&ioapic + 3 * a1 + 10);
v2 = ioapic_redir_read(v1);
return ioapic_redir_write(v1, v2 & 0xFFFFFFFFFFFEFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned __int8 a1)
{
unsigned __int8 v1; // bl
__int64 v2; // rax

v1 = *((_BYTE *)&ioapic + 3 * a1 + 10);
v2 = func9(v1);
return func15(v1, v2 & 0xFFFFFFFFFFFEFFFFLL);
}

original_code:
void ioapic_redir_unmask(u8 n)
{
 n = ioapic[0].pic[n].dest;
 ioapic_redir_write(n, ioapic_redir_read(n) & ~(1 << 16));
}

canonical_original_code:
void ioapic_redir_unmask(unsigned char n)
{
 n = ioapic[0].pic[n].dest;
 ioapic_redir_write(n, ioapic_redir_read(n) & ~(1 << 16));
}


decompiled_code:
__int64 init_interrupts()
{
pic_disable();
lapic_init();
ioapic_init();
return kprintf(
"LAPIC id=%p ver=%p enabled (%llp)\n",
*((unsigned __int8 *)&lapic + 8),
*((unsigned __int8 *)&lapic + 9),
lapic + 0x800000000000LL);
}

canonical_decompiled_code:
__int64 func19()
{
func10();
func13();
func17();
return kprintf(
"LAPIC id=%p ver=%p enabled (%llp)\n",
*((unsigned __int8 *)&lapic + 8),
*((unsigned __int8 *)&lapic + 9),
lapic + 0x800000000000LL);
}

original_code:
void init_interrupts(void)
{
 pic_disable();
 lapic_init();
 ioapic_init();
 kprintf("LAPIC id=%p ver=%p enabled (%llp)\n",
  lapic[0].id, lapic[0].version, ((void *)(((u64)lapic[0].base) - 0xffff800000000000)));
}

canonical_original_code:
void init_interrupts()
{
 pic_disable();
 lapic_init();
 ioapic_init();
 kprintf("LAPIC id=%p ver=%p enabled (%llp)\n",
  lapic[0].id, lapic[0].version, ((void *)(((unsigned long)lapic[0].base) - 0xffff800000000000)));
}


decompiled_code:
char *file_get()
{
_WORD *v0; // rax
unsigned __int8 i; // bl
char *result; // rax

v0 = &unk_A8;
for ( i = 0; i != 0x80; ++i )
{
if ( !*v0 )
break;
v0 += 12;
}
result = (char *)namei();
*((_QWORD *)&file_table + 3 * i) = result;
if ( result )
{
*((_WORD *)&file_table + 12 * i + 4) = 1;
result = (char *)&file_table + 24 * i;
}
return result;
}

canonical_decompiled_code:
char *func0()
{
_WORD *v0; // rax
unsigned __int8 i; // bl
char *result; // rax

v0 = &unk_A8;
for ( i = 0; i != 0x80; ++i )
{
if ( !*v0 )
break;
v0 += 12;
}
result = (char *)namei();
*((_QWORD *)&file_table + 3 * i) = result;
if ( result )
{
*((_WORD *)&file_table + 12 * i + 4) = 1;
result = (char *)&file_table + 24 * i;
}
return result;
}

original_code:
struct file *file_get(const char *path)
{
 u8 i = 0;
 for (; i < 128; i++) {
  if (file_table[i].count == 0)
   break;
 }
 file_table[i].inode = namei(path);
 if (file_table[i].inode == ((void *)0))
  return ((void *)0);
 file_table[i].count = 1;
 return &file_table[i];
}

canonical_original_code:
struct file *file_get(char *path)
{
 unsigned char i = 0;
 for (; i < 128; i++) {
  if (file_table[i].count == 0)
   break;
 }
 file_table[i].inode = namei(path);
 if (file_table[i].inode == ((void *)0))
  return ((void *)0);
 file_table[i].count = 1;
 return &file_table[i];
}

variable_types:
path
char *

return_type: struct file { struct inode { struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head { struct list_head *prev; } bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead { struct list_head l; unsigned long bnum; void *data; unsigned char count; } *(*block_read)(struct inode *, long); } *ops; void *priv; } *inode; unsigned short count; unsigned short mode; unsigned short flags; long pos; } *

user_defined_types: struct file { struct inode *inode; unsigned short count; unsigned short mode; unsigned short flags; long pos; }

user_defined_types: struct inode { struct super *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops *ops; void *priv; }

user_defined_types: struct super { struct dev_t dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head bcache; struct list_head icache; struct super_ops *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; }

user_defined_types: struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead *(*block_read)(struct inode *, long); }


decompiled_code:
char *init_files()
{
char *result; // rax

result = (char *)&unk_A8;
do
{
*(_WORD *)result = 0;
result += 24;
}
while ( result != (char *)&unk_A8 + 3072 );
return result;
}

canonical_decompiled_code:
char *func1()
{
char *result; // rax

result = (char *)&unk_A8;
do
{
*(_WORD *)result = 0;
result += 24;
}
while ( result != (char *)&unk_A8 + 3072 );
return result;
}

original_code:
void init_files(void)
{
 u8 i;
 for (i = 0; i < 128; i++)
  file_table[i].count = 0;
 return;
}

canonical_original_code:
void init_files()
{
 unsigned char i;
 for (i = 0; i < 128; i++)
  file_table[i].count = 0;
 return;
}


lseek

decompiled_code:
__int64 __fastcall lseek(int a1, __int64 a2, char a3)
{
__int64 result; // rax
__int64 v4; // rax
__int64 v5; // rax

if ( a3 == 1 )
{
v4 = *(_QWORD *)(current + 8LL * a1 + 8);
*(_QWORD *)(v4 + 16) += a2;
}
else if ( a3 == 2 )
{
v5 = **(_QWORD **)(current + 8LL * a1 + 8);
*(_QWORD *)(v5 + 32) += a2;
}
else
{
result = -1LL;
if ( a3 )
return result;
*(_QWORD *)(*(_QWORD *)(current + 8LL * a1 + 8) + 16LL) = a2;
}
return *(_QWORD *)(*(_QWORD *)(current + 8LL * a1 + 8) + 16LL);
}

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

if ( a3 == 1 )
{
v4 = *(_QWORD *)(current + 8LL * a1 + 8);
*(_QWORD *)(v4 + 16) += a2;
}
else if ( a3 == 2 )
{
v5 = **(_QWORD **)(current + 8LL * a1 + 8);
*(_QWORD *)(v5 + 32) += a2;
}
else
{
result = -1LL;
if ( a3 )
return result;
*(_QWORD *)(*(_QWORD *)(current + 8LL * a1 + 8) + 16LL) = a2;
}
return *(_QWORD *)(*(_QWORD *)(current + 8LL * a1 + 8) + 16LL);
}

original_code:
off_t lseek(s32 fd, off_t offset, u8 origin)
{
 switch (origin) {
 case 0:
  current->fds[fd]->pos = offset;
  break;
 case 1:
  current->fds[fd]->pos += offset;
  break;
 case 2:
  current->fds[fd]->inode->filesize += offset;
  break;
 default:
  return (off_t) - 1;
 }
 return current->fds[fd]->pos;
}

canonical_original_code:
long lseek(int fd, long offset, unsigned char origin)
{
 switch (origin) {
 case 0:
  current->fds[fd]->pos = offset;
  break;
 case 1:
  current->fds[fd]->pos += offset;
  break;
 case 2:
  current->fds[fd]->inode->filesize += offset;
  break;
 default:
  return (off_t) - 1;
 }
 return current->fds[fd]->pos;
}

variable_types: fd int

variable_types: offset long

variable_types:
origin
unsigned char