decompiled_code:
__int64 __fastcall buf_hex_dump(void (__fastcall **a1)(void *), __int64 a2, unsigned int a3)
{
unsigned int v3; // er15
__int64 v4; // r14
int v6; // ebp
__int64 i; // rbx
__int64 v8; // rsi
__int64 result; // rax

if ( a3 )
{
v3 = a3 - 1;
v4 = a3;
v6 = 0;
for ( i = 0LL; i != v4; ++i )
{
while ( 1 )
{
(*a1)(&unk_160);
v8 = *(unsigned __int8 *)(a2 + i);
if ( (unsigned __int8)v8 <= 0xFu )
{
(*a1)(&unk_162);
v8 = *(unsigned __int8 *)(a2 + i);
}
++v6;
result = ((__int64 (__fastcall *)(void *, __int64))*a1)(&unk_164, v8);
if ( v6 == 16 || v3 == (_DWORD)i )
break;
if ( ++i == v4 )
return result;
}
v6 = 0;
result = ((__int64 (__fastcall *)(void *))*a1)(&unk_167);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void (__fastcall **a1)(void *), __int64 a2, unsigned int a3)
{
unsigned int v3; // er15
__int64 v4; // r14
int v6; // ebp
__int64 i; // rbx
__int64 v8; // rsi
__int64 result; // rax

if ( a3 )
{
v3 = a3 - 1;
v4 = a3;
v6 = 0;
for ( i = 0LL; i != v4; ++i )
{
while ( 1 )
{
(*a1)(&unk_160);
v8 = *(unsigned __int8 *)(a2 + i);
if ( (unsigned __int8)v8 <= 0xFu )
{
(*a1)(&unk_162);
v8 = *(unsigned __int8 *)(a2 + i);
}
++v6;
result = ((__int64 (__fastcall *)(void *, __int64))*a1)(&unk_164, v8);
if ( v6 == 16 || v3 == (_DWORD)i )
break;
if ( ++i == v4 )
return result;
}
v6 = 0;
result = ((__int64 (__fastcall *)(void *))*a1)(&unk_167);
}
}
return result;
}

original_code:
void buf_hex_dump(struct buffer_dumper *dumper, void *given_buf, uint len)
{
 unsigned int bytes_perline = 16, n = 0;
 uint8_t *buf = given_buf;
 for (uint i = 0; i < len; i++) {
  dumper->pr(" ");
  if (buf[i] < 0x10)
   dumper->pr("0");
  dumper->pr("%x", buf[i]);
  n++;
  if (n == bytes_perline || i == len - 1) {
   dumper->pr("\n");
   n = 0;
  }
 }
}

canonical_original_code:
void buf_hex_dump(struct buffer_dumper *dumper, void *given_buf, unsigned int len)
{
 unsigned int bytes_perline = 16; unsigned int n = 0;
 unsigned char *buf = given_buf;
 for (unsigned int i = 0; i < len; i++) {
  dumper->pr(" ");
  if (buf[i] < 0x10)
   dumper->pr("0");
  dumper->pr("%x", buf[i]);
  n++;
  if (n == bytes_perline || i == len - 1) {
   dumper->pr("\n");
   n = 0;
  }
 }
}

variable_types: struct buffer_dumper { void (*pr)(char *fmt, ...); void (*formatter)(struct buffer_dumper *dumper, void *buf, unsigned int len); } *

variable_types:
len
unsigned int

variable_types:
buf
unsigned char *

variable_types:
i
unsigned int


repo: a-darwish/cuteOS

decompiled_code:
__int64 __fastcall buf_char_dump(__int64 (__fastcall **a1)(void *, __int64), char *a2, int a3)
{
char *v3; // rbp
char *v4; // rbx
__int64 v5; // rsi
__int64 result; // rax

if ( a3 )
{
v3 = &a2[a3];
v4 = a2;
do
{
v5 = (unsigned int)*v4++;
result = (*a1)(&unk_169, v5);
}
while ( v4 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 (__fastcall **a1)(void *, __int64), char *a2, int a3)
{
char *v3; // rbp
char *v4; // rbx
__int64 v5; // rsi
__int64 result; // rax

if ( a3 )
{
v3 = &a2[a3];
v4 = a2;
do
{
v5 = (unsigned int)*v4++;
result = (*a1)(&unk_169, v5);
}
while ( v4 != v3 );
}
return result;
}

original_code:
void buf_char_dump(struct buffer_dumper *dumper, void *given_buf, uint len)
{
 char *buf = given_buf;
 for (uint i = 0; i < len; i++)
  dumper->pr("%c", buf[i]);
}

canonical_original_code:
void buf_char_dump(struct buffer_dumper *dumper, void *given_buf, unsigned int len)
{
 char *buf = given_buf;
 for (unsigned int i = 0; i < len; i++)
  dumper->pr("%c", buf[i]);
}

variable_types:
buf
char *

return_type: void

user_defined_types: struct buffer_dumper { void (*pr)(char *fmt, ...); void (*formatter)(struct buffer_dumper *dumper, void *buf, unsigned int len); }


decompiled_code:
void buf_null_dump()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void buf_null_dump(__attribute__((__unused__)) struct buffer_dumper *dumper,
     __attribute__((__unused__)) void __attribute__((__unused__)) *given_buf, __attribute__((__unused__)) uint len)
{
}

canonical_original_code:
void buf_null_dump(struct buffer_dumper *dumper, void *given_buf, unsigned int len)
{
}


printbuf

decompiled_code:
__int64 __fastcall printbuf(__int64 a1)
{
if ( !a1 )
{
panic("%s:%d - !(dumper != NULL)\n", "lib/buffer_dumper.c", 80LL);
JUMPOUT(0x15ELL);
}
return (*(__int64 (**)(void))(a1 + 8))();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( !a1 )
{
panic("%s:%d - !(dumper != NULL)\n", "lib/buffer_dumper.c", 80LL);
JUMPOUT(0x15ELL);
}
return (*(__int64 (**)(void))(a1 + 8))();
}

original_code:
void printbuf(struct buffer_dumper* dumper, void *buf, uint len)
{
 do { if (__builtin_expect((!(dumper != ((void *)0))), 0)) panic("%s:%d - !(" "dumper != NULL" ")\n", "lib/buffer_dumper.c", 80); } while (0);;
 dumper->formatter(dumper, buf, len);
}

canonical_original_code:
void printbuf(struct buffer_dumper *dumper, void *buf, unsigned int len)
{
 do { if (__builtin_expect((!(dumper != ((void *)0))), 0)) panic("%s:%d - !(" "dumper != NULL" ")\n", "lib/buffer_dumper.c", 80); } while (0);;
 dumper->formatter(dumper, buf, len);
}

variable_types:
buf
void *


decompiled_code:
__int64 default_rflags()
{
return 514LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 514LL;
}

original_code:
static inline union x86_rflags default_rflags(void)
{
 union x86_rflags flags;
 flags.raw = 0;
 flags.__reserved1_0 = 1;
 flags.irqs_enabled = 1;
 return flags;
}

canonical_original_code:
static inline union x86_rflags default_rflags()
{
 union x86_rflags flags;
 flags.raw = 0;
 flags.__reserved1_0 = 1;
 flags.irqs_enabled = 1;
 return flags;
}

variable_types: union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; }


decompiled_code:
__int64 __fastcall pcb_init(__int64 a1)
{
return memset64(a1, 0xDEADFEEDDEADFEEDLL, 56LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return memset64(a1, 0xDEADFEEDDEADFEEDLL, 56LL);
}

original_code:
static inline void pcb_init(struct pcb *pcb)
{
 memset64(pcb, 0xdeadfeeddeadfeed, sizeof(*pcb));
}

variable_types: struct pcb { unsigned long rbp; unsigned long rbx; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rsp; } *


decompiled_code:
__int64 __fastcall irq_ctx_init(__int64 a1)
{
return memset64(a1, 0xDEADFEEDDEADFEEDLL, 112LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return memset64(a1, 0xDEADFEEDDEADFEEDLL, 112LL);
}

original_code:
static inline void irq_ctx_init(struct irq_ctx *ctx)
{
 memset64(ctx, 0xdeadfeeddeadfeed, sizeof(*ctx));
}

variable_types: struct irq_ctx { unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long rsi; unsigned long rdi; unsigned long rdx; unsigned long rcx; unsigned long rax; unsigned long rip; unsigned long cs; unsigned long rflags; unsigned long rsp; unsigned long ss; } *


decompiled_code:
__int64 kthread_alloc_pid()
{
return atomic_inc(&pids_0);
}

canonical_decompiled_code:
__int64 func5()
{
return atomic_inc(&pids_0);
}

original_code:
uint64_t kthread_alloc_pid(void)
{
 static uint64_t pids;
 return atomic_inc(&pids);
}

canonical_original_code:
unsigned long kthread_alloc_pid()
{
 static unsigned long pids;
 return atomic_inc(&pids);
}

variable_types:
pids
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall proc_init(_QWORD *a1)
{
memset(a1, 0, 0x140uLL);
*a1 = kthread_alloc_pid();
pcb_init((__int64)(a1 + 1));
*((_DWORD *)a1 + 16) = 2;
list_init(a1 + 9);
a1[13] = 2LL;
return unrolled_init(a1 + 14, 32LL);
}

original_code:
static inline void proc_init(struct proc *proc)
{
 memset(proc, 0, sizeof(struct proc));
 proc->pid = kthread_alloc_pid();
 pcb_init(&proc->pcb);
 proc->state = TD_INVALID;
 list_init(&proc->pnode);
 proc->working_dir = EXT2_ROOT_INODE;
 unrolled_init(&proc->fdtable, 32);
}

variable_types: struct proc { unsigned long pid; struct pcb { unsigned long rbp; unsigned long rbx; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rsp; } pcb; int state; struct list_node { struct list_node *next; struct list_node *prev; } pnode; unsigned long runtime; unsigned long enter_runqueue_ts; unsigned long working_dir; struct unrolled_head { struct __node { void **array; unsigned int array_len; unsigned int array_nrfree; unsigned int num; struct __node *next; } *node; unsigned int array_len; } fdtable; struct { unsigned long runtime_overall; unsigned int dispatch_count; unsigned long rqwait_overall; unsigned long prio_map[-1]; unsigned int preempt_high_prio; unsigned int preempt_slice_end; } stats; } *

user_defined_types: struct proc { unsigned long pid; struct pcb pcb; int state; struct list_node pnode; unsigned long runtime; unsigned long enter_runqueue_ts; unsigned long working_dir; struct unrolled_head fdtable; struct { unsigned long runtime_overall; unsigned int dispatch_count; unsigned long rqwait_overall; unsigned long prio_map[-1]; unsigned int preempt_high_prio; unsigned int preempt_slice_end; } stats; }

user_defined_types: struct unrolled_head { struct __node *node; unsigned int array_len; }


original_code:
void kthread_create(void (* func)(void))
{
 struct proc *proc;
 struct irq_ctx *irq_ctx;
 char *stack;
 proc = kmalloc(sizeof(*proc));
 proc_init(proc);
 stack = kmalloc((1 << 12));
 stack = stack + (1 << 12);
 irq_ctx = (struct irq_ctx *)(stack - sizeof(*irq_ctx));
 irq_ctx_init(irq_ctx);
 irq_ctx->cs = 0x08;
 irq_ctx->rip = (uintptr_t)func;
 irq_ctx->ss = 0;
 irq_ctx->rsp = (uintptr_t)stack;
 irq_ctx->rflags = default_rflags().raw;
 proc->pcb.rsp = (uintptr_t)irq_ctx;
 sched_enqueue(proc);
}

canonical_original_code:
void kthread_create(void (*func)())
{
 struct proc *proc;
 struct irq_ctx *irq_ctx;
 char *stack;
 proc = kmalloc(sizeof(*proc));
 proc_init(proc);
 stack = kmalloc((1 << 12));
 stack = stack + (1 << 12);
 irq_ctx = (struct irq_ctx *)(stack - sizeof(*irq_ctx));
 irq_ctx_init(irq_ctx);
 irq_ctx->cs = 0x08;
 irq_ctx->rip = (unsigned long)func;
 irq_ctx->ss = 0;
 irq_ctx->rsp = (unsigned long)stack;
 irq_ctx->rflags = default_rflags().raw;
 proc->pcb.rsp = (unsigned long)irq_ctx;
 sched_enqueue(proc);
}

variable_types:
func
void (*)()

variable_types:
stack
char *

user_defined_types: struct irq_ctx { unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long rsi; unsigned long rdi; unsigned long rdx; unsigned long rcx; unsigned long rax; unsigned long rip; unsigned long cs; unsigned long rflags; unsigned long rsp; unsigned long ss; }

user_defined_types: struct pcb { unsigned long rbp; unsigned long rbx; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rsp; }

user_defined_types: struct list_node { struct list_node *next; struct list_node *prev; }

user_defined_types: struct __node { void **array; unsigned int array_len; unsigned int array_nrfree; unsigned int num; struct __node *next; }


decompiled_code:
__int64 __fastcall vga_scrollup(__int16 a1)
{
int *v1; // rax
__int64 result; // rax

memcpy_forward_nocheck(&vga_buffer, &unk_11E0, 3840LL);
v1 = (int *)&unk_2040;
do
{
v1 = (int *)((char *)v1 + 2);
*((_WORD *)v1 - 1) = (a1 << 8) + 32;
}
while ( v1 != &vga_ypos );
result = memcpy_nocheck(0xFFFF8000000B8000LL, &vga_buffer, 4000LL);
--vga_ypos;
vga_xpos = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
int *v1; // rax
__int64 result; // rax

memcpy_forward_nocheck(&vga_buffer, &unk_11E0, 3840LL);
v1 = (int *)&unk_2040;
do
{
v1 = (int *)((char *)v1 + 2);
*((_WORD *)v1 - 1) = (a1 << 8) + 32;
}
while ( v1 != &vga_ypos );
result = memcpy_nocheck(0xFFFF8000000B8000LL, &vga_buffer, 4000LL);
--vga_ypos;
vga_xpos = 0;
return result;
}

original_code:
static void vga_scrollup(int color) {
 char *src, *dst;
 int rows_24;
 uint16_t *vgap;
 src = vga_buffer + 2 * 80;
 dst = vga_buffer;
 rows_24 = 2 * ((25 - 1) * 80);
 memcpy_forward_nocheck(dst, src, rows_24);
 vgap = (uint16_t *)(vga_buffer + rows_24);
 for (int i = 0; i < 80; i++)
  *vgap++ = (color << 8) + ' ';
 memcpy_nocheck(((char *)({ do { if (__builtin_expect((!((uintptr_t)(0xb8000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0xb8000) >= KERN_PHYS_OFFSET" ")\n", "lib/printf.c", 331); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0xb8000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0xb8000) < KERN_PHYS_END_MAX" ")\n", "lib/printf.c", 331); } while (0);; (void *)((char *)(0xb8000) + 0xffff800000000000ULL); })), vga_buffer, (25 * 80 * 2));
 vga_xpos = 0;
 vga_ypos--;
}

canonical_original_code:
static void vga_scrollup(int color) {
 char *src; char *dst;
 int rows_24;
 unsigned short *vgap;
 src = vga_buffer + 2 * 80;
 dst = vga_buffer;
 rows_24 = 2 * ((25 - 1) * 80);
 memcpy_forward_nocheck(dst, src, rows_24);
 vgap = (unsigned short *)(vga_buffer + rows_24);
 for (int i = 0; i < 80; i++)
  *vgap++ = (color << 8) + ' ';
 memcpy_nocheck(((char *)({ do { if (__builtin_expect((!((unsigned long)(0xb8000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0xb8000) >= KERN_PHYS_OFFSET" ")\n", "lib/printf.c", 331); } while (0);; do { if (__builtin_expect((!((unsigned long)(0xb8000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0xb8000) < KERN_PHYS_END_MAX" ")\n", "lib/printf.c", 331); } while (0);; (void *)((char *)(0xb8000) + 0xffff800000000000ULL); })), vga_buffer, (25 * 80 * 2));
 vga_xpos = 0;
 vga_ypos--;
}

variable_types: color int

variable_types:
src
char *

variable_types:
dst
char *

variable_types:
vgap
unsigned short *

variable_types: i int


decompiled_code:
__int64 __fastcall putc_colored(char a1, __int16 a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a1;
return vga_write(v3, 1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, __int16 a2)
{
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a1;
return func2(v3, 1, a2);
}

original_code:
void putc_colored(char c, int color)
{
 vga_write(&c, 1, color);
}

variable_types: c char


putc

decompiled_code:
__int64 __fastcall putc(char a1)
{
return putc_colored(a1, 15);
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1)
{
return func3(a1, 15);
}

original_code:
void putc(char c)
{
 putc_colored(c, (((0x0) << 4) | (0xf)));
}


decompiled_code:
void __fastcall __noreturn printk_panic(char *a1)
{
char v2; // di
char *v3; // rbp
char i; // di

v2 = panic_prefix;
if ( !panic_prefix )
goto LABEL_6;
v3 = &panic_prefix;
do
{
putc(v2);
v2 = *++v3;
}
while ( v2 );
for ( i = *a1; *a1; i = *a1 )
{
++a1;
putc(i);
LABEL_6:
;
}
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func5(char *a1)
{
char v2; // di
char *v3; // rbp
char i; // di

v2 = panic_prefix;
if ( !panic_prefix )
goto LABEL_6;
v3 = &panic_prefix;
do
{
func4(v2);
v2 = *++v3;
}
while ( v2 );
for ( i = *a1; *a1; i = *a1 )
{
++a1;
func4(i);
LABEL_6:
;
}
__halt();
}

original_code:
static __attribute__((noreturn)) void printk_panic(const char *str)
{
 const char *prefix;
 prefix = panic_prefix;
 while (*prefix != 0)
  putc(*prefix++);
 while (*str != 0)
  putc(*str++);
 do { while (((_Bool)1)) asm volatile ("hlt":::"memory"); } while (0);;
}

canonical_original_code:
static void printk_panic(char *str)
{
 char *prefix;
 prefix = panic_prefix;
 while (*prefix != 0)
  putc(*prefix++);
 while (*str != 0)
  putc(*str++);
 do { while (((_Bool)1)) asm volatile ("hlt":::"memory"); } while (0);;
}

variable_types:
str
char *

variable_types:
prefix
char *


ltoa

decompiled_code:
__int64 __fastcall ltoa(signed __int64 a1, _BYTE *a2, int a3, unsigned int a4)
{
if ( a4 - 3 > 0xD )
printk_panic("!(radix > 2 && radix <= PRINTK_MAX_RADIX)");
if ( a1 >= 0 )
return ultoa(a1, a2, a3, a4);
if ( a3 <= 1 )
printk_panic("!(size >= 2)");
*a2 = 45;
return (unsigned int)ultoa(-a1, a2 + 1, a3 - 1, a4) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func8(signed __int64 a1, _BYTE *a2, int a3, unsigned int a4)
{
if ( a4 - 3 > 0xD )
func5("!(radix > 2 && radix <= PRINTK_MAX_RADIX)");
if ( a1 >= 0 )
return func7(a1, a2, a3, a4);
if ( a3 <= 1 )
func5("!(size >= 2)");
*a2 = 45;
return (unsigned int)func7(-a1, a2 + 1, a3 - 1, a4) + 1;
}

original_code:
static int ltoa(signed long num, char *buf, int size, int radix)
{
 do { if (__builtin_expect((!(radix > 2 && radix <= 16)), 0)) printk_panic("!(" "radix > 2 && radix <= PRINTK_MAX_RADIX" ")"); } while (0);;
 if (num < 0) {
  do { if (__builtin_expect((!(size >= 2)), 0)) printk_panic("!(" "size >= 2" ")"); } while (0);;
  num *= -1;
  buf[0] = '-';
  return ultoa(num, buf+1, size-1, radix) + 1;
 }
 return ultoa(num, buf, size, radix);
}

canonical_original_code:
static int ltoa(long num, char *buf, int size, int radix)
{
 do { if (__builtin_expect((!(radix > 2 && radix <= 16)), 0)) printk_panic("!(" "radix > 2 && radix <= PRINTK_MAX_RADIX" ")"); } while (0);;
 if (num < 0) {
  do { if (__builtin_expect((!(size >= 2)), 0)) printk_panic("!(" "size >= 2" ")"); } while (0);;
  num *= -1;
  buf[0] = '-';
  return ultoa(num, buf+1, size-1, radix) + 1;
 }
 return ultoa(num, buf, size, radix);
}

variable_types: num long

variable_types:
buf
char *

variable_types: size int

variable_types: radix int

return_type: int


vsnprintf

decompiled_code:
__int64 __fastcall vsnprintf(char *dest, int a2, char *a3, __int64 a4)
{
char v4; // al
int v5; // ebx
char *v6; // rbp
char *v8; // r12
bool v9; // cl
int v11; // eax
__int64 v12; // rdx
__int64 v13; // [rsp+4h] [rbp-34h] BYREF
int v14; // [rsp+Ch] [rbp-2Ch]

v13 = 0LL;
v14 = 0;
if ( a2 <= 0 )
return 0LL;
v4 = *a3;
v5 = a2;
v6 = a3;
v8 = dest;
if ( !*a3 )
return 0LL;
while ( 1 )
{
v9 = v4 != 37;
if ( v4 != 37 )
break;
LABEL_10:
if ( v5 && v4 )
{
if ( v9 )
printk_panic("!(*fmt == '%')");
v6 = parse_arg(v6, (__int64)&v13);
v11 = print_arg(v8, v5, (unsigned int *)&v13, a4);
v12 = v11;
v5 -= v11;
v4 = *v6;
v8 += v12;
if ( *v6 )
continue;
}
goto LABEL_8;
}
while ( v5 )
{
++v6;
*v8++ = v4;
--v5;
v4 = *v6;
v9 = *v6 != 37;
if ( !*v6 || v4 == 37 )
goto LABEL_10;
}
LABEL_8:
if ( v8 < dest )
printk_panic("!(str >= buf)");
return (unsigned int)((_DWORD)v8 - (_DWORD)dest);
}

original_code:
int vsnprintf(char *buf, int size, const char *fmt, va_list args)
{
 struct printf_argdesc desc = { 0 };
 char *str;
 int len;
 if (size < 1)
  return 0;
 str = buf;
 while (*fmt) {
  while (*fmt != 0 && *fmt != '%' && size != 0) {
   *str++ = *fmt++;
   --size;
  }
  if (*fmt == 0 || size == 0)
   break;
  do { if (__builtin_expect((!(*fmt == '%')), 0)) printk_panic("!(" "*fmt == '%'" ")"); } while (0);;
  fmt = parse_arg(fmt, &desc);
  len = print_arg(str, size, &desc, args);
  str += len;
  size -= len;
 }
 do { if (__builtin_expect((!(str >= buf)), 0)) printk_panic("!(" "str >= buf" ")"); } while (0);;
 return str - buf;
}

canonical_original_code:
int vsnprintf(char *buf, int size, char *fmt, __builtin_va_list args)
{
 struct printf_argdesc desc = { 0 };
 char *str;
 int len;
 if (size < 1)
  return 0;
 str = buf;
 while (*fmt) {
  while (*fmt != 0 && *fmt != '%' && size != 0) {
   *str++ = *fmt++;
   --size;
  }
  if (*fmt == 0 || size == 0)
   break;
  do { if (__builtin_expect((!(*fmt == '%')), 0)) printk_panic("!(" "*fmt == '%'" ")"); } while (0);;
  fmt = parse_arg(fmt, &desc);
  len = print_arg(str, size, &desc, args);
  str += len;
  size -= len;
 }
 do { if (__builtin_expect((!(str >= buf)), 0)) printk_panic("!(" "str >= buf" ")"); } while (0);;
 return str - buf;
}

variable_types:
fmt
char *

variable_types: struct printf_argdesc { int radix; enum printf_arglen { INT=0, LONG=1 } len; enum printf_argtype { NONE=0, SIGNED=1, UNSIGNED=2, STRING=3, CHAR=4, PERCENT=5 } type; }

variable_types: len int

user_defined_types: struct printf_argdesc { int radix; enum printf_arglen len; enum printf_argtype type; }


printk

decompiled_code:
__int64 printk(char *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
int v9; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
spin_lock(&kbuf_lock);
v9 = vsnprintf(kbuf, 1024, a1, (__int64)va);
vga_write(kbuf, v9, 15);
return spin_unlock(&kbuf_lock);
}

canonical_decompiled_code:
__int64 func11(char *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
int v9; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
spin_lock(&kbuf_lock);
v9 = func10(kbuf, 1024, a1, (__int64)va);
func2(kbuf, v9, 15);
return spin_unlock(&kbuf_lock);
}

original_code:
void printk(const char *fmt, ...)
{
 va_list args;
 int n;
 spin_lock(&kbuf_lock);
 __builtin_va_start(args,fmt);
 n = vsnprintf(kbuf, sizeof(kbuf), fmt, args);
 __builtin_va_end(args);
 vga_write(kbuf, n, (((0x0) << 4) | (0xf)));
 spin_unlock(&kbuf_lock);
}

canonical_original_code:
void printk(char *fmt, ...)
{
 __builtin_va_list args;
 int n;
 spin_lock(&kbuf_lock);
 __builtin_va_start(args,fmt);
 n = vsnprintf(kbuf, sizeof(kbuf), fmt, args);
 __builtin_va_end(args);
 vga_write(kbuf, n, (((0x0) << 4) | (0xf)));
 spin_unlock(&kbuf_lock);
}

variable_types: n int


prints

decompiled_code:
__int64 prints(char *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
unsigned int v9; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
spin_lock(&sbuf_lock);
v9 = vsnprintf(sbuf, 1024, a1, (__int64)va);
serial_write(sbuf, v9);
return spin_unlock(&sbuf_lock);
}

canonical_decompiled_code:
__int64 func12(char *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, ...)
{
unsigned int v9; // eax
gcc_va_list va; // [rsp+8h] [rbp-50h] BYREF

va_start(va, a9);
spin_lock(&sbuf_lock);
v9 = func10(sbuf, 1024, a1, (__int64)va);
serial_write(sbuf, v9);
return spin_unlock(&sbuf_lock);
}

original_code:
void prints(const char *fmt, ...)
{
 va_list args;
 int n;
 spin_lock(&sbuf_lock);
 __builtin_va_start(args,fmt);
 n = vsnprintf(sbuf, sizeof(sbuf), fmt, args);
 __builtin_va_end(args);
 serial_write(sbuf, n);
 spin_unlock(&sbuf_lock);
}

canonical_original_code:
void prints(char *fmt, ...)
{
 __builtin_va_list args;
 int n;
 spin_lock(&sbuf_lock);
 __builtin_va_start(args,fmt);
 n = vsnprintf(sbuf, sizeof(sbuf), fmt, args);
 __builtin_va_end(args);
 serial_write(sbuf, n);
 spin_unlock(&sbuf_lock);
}


decompiled_code:
__int64 printk_bust_all_locks()
{
spin_lock(&vga_lock);
return spin_lock(&kbuf_lock);
}

canonical_decompiled_code:
__int64 func13()
{
spin_lock(&vga_lock);
return spin_lock(&kbuf_lock);
}

original_code:
void printk_bust_all_locks(void)
{
 spin_lock(&vga_lock);
 spin_lock(&kbuf_lock);
}

canonical_original_code:
void printk_bust_all_locks()
{
 spin_lock(&vga_lock);
 spin_lock(&kbuf_lock);
}


readl

decompiled_code:
__int64 __fastcall readl(unsigned int *a1)
{
return *a1;
}

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

original_code:
static inline uint32_t readl(const volatile void *addr) {
 return ({ uint32_t val; asm volatile ("mov %[addr], %[val];" : [val] "=r"(val) : [addr] "m"(*(const volatile uint32_t *)addr) : "memory"); val; });
}

canonical_original_code:
static inline unsigned int readl(void *addr) {
 return ({ unsigned int val; asm volatile ("mov %[addr], %[val];" : [val] "=r"(val) : [addr] "m"(*(unsigned int *)addr) : "memory"); val; });
}

variable_types:
addr
void *

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
unsigned __int64 __fastcall ioapic_isa_pin(int a1, int a2)
{
__int64 v3; // rax
__int64 v4; // rdi
char v5; // si
int *v6; // rdx
__int64 v7; // rax
unsigned __int64 result; // rax

if ( mp_isa_busid == -1 )
{
panic("%s:%d - !(mp_isa_busid != -1)\n", "dev/ioapic.c", 71LL);
result = ioapic_base();
}
else
{
v3 = 0LL;
if ( nr_mpcirqs <= 0 )
goto LABEL_12;
while ( 1 )
{
v4 = (int)v3;
if ( mp_isa_busid == *((unsigned __int8 *)&mp_irqs + 8 * v3 + 4)
&& *((unsigned __int8 *)&mp_irqs + 8 * v3 + 5) == a1
&& *((unsigned __int8 *)&mp_irqs + 8 * v3 + 1) == a2 )
{
break;
}
if ( nr_mpcirqs == ++v3 )
goto LABEL_12;
}
if ( nr_ioapics <= 0 )
{
LABEL_12:
result = -1LL;
}
else
{
v5 = *((_BYTE *)&mp_irqs + 8 * (int)v3 + 6);
v6 = &ioapic_descs;
v7 = 0LL;
while ( v5 != *(_BYTE *)v6 )
{
v7 = (unsigned int)(v7 + 1);
v6 += 3;
if ( nr_ioapics == (_DWORD)v7 )
goto LABEL_12;
}
result = ((unsigned __int64)*((unsigned __int8 *)&mp_irqs + 8 * v4 + 7) << 32) | v7;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(int a1, int a2)
{
__int64 v3; // rax
__int64 v4; // rdi
char v5; // si
int *v6; // rdx
__int64 v7; // rax
unsigned __int64 result; // rax

if ( mp_isa_busid == -1 )
{
panic("%s:%d - !(mp_isa_busid != -1)\n", "dev/ioapic.c", 71LL);
result = func3();
}
else
{
v3 = 0LL;
if ( nr_mpcirqs <= 0 )
goto LABEL_12;
while ( 1 )
{
v4 = (int)v3;
if ( mp_isa_busid == *((unsigned __int8 *)&mp_irqs + 8 * v3 + 4)
&& *((unsigned __int8 *)&mp_irqs + 8 * v3 + 5) == a1
&& *((unsigned __int8 *)&mp_irqs + 8 * v3 + 1) == a2 )
{
break;
}
if ( nr_mpcirqs == ++v3 )
goto LABEL_12;
}
if ( nr_ioapics <= 0 )
{
LABEL_12:
result = -1LL;
}
else
{
v5 = *((_BYTE *)&mp_irqs + 8 * (int)v3 + 6);
v6 = &ioapic_descs;
v7 = 0LL;
while ( v5 != *(_BYTE *)v6 )
{
v7 = (unsigned int)(v7 + 1);
v6 += 3;
if ( nr_ioapics == (_DWORD)v7 )
goto LABEL_12;
}
result = ((unsigned __int64)*((unsigned __int8 *)&mp_irqs + 8 * v4 + 7) << 32) | v7;
}
}
return result;
}

original_code:
static struct ioapic_pin ioapic_isa_pin(int isa_irq, enum mp_irqtype type)
{
 struct ioapic_pin pin = { .apic = -1, .pin = -1 };
 int irq;
 do { if (__builtin_expect((!(mp_isa_busid != -1)), 0)) panic("%s:%d - !(" "mp_isa_busid != -1" ")\n", "dev/ioapic.c", 71); } while (0);;
 for (irq = 0; irq < nr_mpcirqs; irq++) {
  if ((mp_irqs[irq].src_busid == mp_isa_busid) &&
      (mp_irqs[irq].src_busirq == isa_irq) &&
      (mp_irqs[irq].type == type))
   break;
 }
 if (irq >= nr_mpcirqs)
  return pin;
 for (int apic = 0; apic < nr_ioapics; apic++) {
  if(mp_irqs[irq].dst_ioapicid == ioapic_descs[apic].id) {
   pin.apic = apic;
   pin.pin = mp_irqs[irq].dst_ioapicpin;
   return pin;
  }
 }
 return pin;
}

variable_types: enum mp_irqtype { MP_INT=0, MP_NMI=1, MP_SMI=2, MP_ExtINT=3 }

variable_types: struct ioapic_pin { int apic; int pin; }

variable_types: irq int

variable_types: apic int


decompiled_code:
__int64 __fastcall ioapic_base(int a1)
{
if ( nr_ioapics > a1 )
return vm_kmap((unsigned int)ioapic_descs[3 * a1 + 1], 32LL);
panic("%s:%d - !(apic < nr_ioapics)\n", "include/ioapic.h", 83LL);
return ioapic_write();
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( nr_ioapics > a1 )
return vm_kmap((unsigned int)ioapic_descs[3 * a1 + 1], 32LL);
panic("%s:%d - !(apic < nr_ioapics)\n", "include/ioapic.h", 83LL);
return func4();
}

original_code:
static inline uintptr_t ioapic_base(int apic)
{
 void *vbase;
 do { if (__builtin_expect((!(apic < nr_ioapics)), 0)) panic("%s:%d - !(" "apic < nr_ioapics" ")\n", "include/ioapic.h", 83); } while (0);;
 vbase = vm_kmap(ioapic_descs[apic].base, 0x20);
 return (uintptr_t)vbase;
}

canonical_original_code:
static inline unsigned long ioapic_base(int apic)
{
 void *vbase;
 do { if (__builtin_expect((!(apic < nr_ioapics)), 0)) panic("%s:%d - !(" "apic < nr_ioapics" ")\n", "include/ioapic.h", 83); } while (0);;
 vbase = vm_kmap(ioapic_descs[apic].base, 0x20);
 return (unsigned long)vbase;
}

variable_types:
vbase
void *


decompiled_code:
__int64 __fastcall ioapic_read(int a1, unsigned __int8 a2)
{
_DWORD *v2; // r12
__int64 v3; // rax

v2 = (_DWORD *)ioapic_base(a1);
ioapic_base(a1);
writel(a2, v2);
return readl((unsigned int *)(v3 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1, unsigned __int8 a2)
{
_DWORD *v2; // r12
__int64 v3; // rax

v2 = (_DWORD *)func3(a1);
func3(a1);
func1(a2, v2);
return func0((unsigned int *)(v3 + 16));
}

original_code:
static inline uint32_t ioapic_read(int apic, uint8_t reg)
{
 uint32_t *ioregsel = (uint32_t *)ioapic_base(apic);
 uint32_t *iowin = (uint32_t *)(ioapic_base(apic) + 0x10);
 writel(reg, ioregsel);
 return readl(iowin);
}

canonical_original_code:
static inline unsigned int ioapic_read(int apic, unsigned char reg)
{
 unsigned int *ioregsel = (uint32_t *)ioapic_base(apic);
 unsigned int *iowin = (uint32_t *)(ioapic_base(apic) + 0x10);
 writel(reg, ioregsel);
 return readl(iowin);
}

variable_types:
reg
unsigned char

variable_types:
ioregsel
unsigned int *

variable_types:
iowin
unsigned int *


decompiled_code:
__int64 __fastcall ioapic_read_irqentry(int a1, char a2)
{
unsigned int v2; // ebp

v2 = ioapic_read(a1, 2 * a2 + 16);
return (ioapic_read(a1, 2 * a2 + 17) << 32) | v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char a2)
{
unsigned int v2; // ebp

v2 = func6(a1, 2 * a2 + 16);
return (func6(a1, 2 * a2 + 17) << 32) | v2;
}

original_code:
static inline union ioapic_irqentry ioapic_read_irqentry(int apic, uint8_t irq)
{
 union ioapic_irqentry entry = { .value = 0 };
 entry.value_low = ioapic_read(apic, 0x10 + 2*irq);
 entry.value_high = ioapic_read(apic, 0x10 + 2*irq + 1);
 return entry;
}

canonical_original_code:
static inline union ioapic_irqentry ioapic_read_irqentry(int apic, unsigned char irq)
{
 union ioapic_irqentry entry = { .value = 0 };
 entry.value_low = ioapic_read(apic, 0x10 + 2*irq);
 entry.value_high = ioapic_read(apic, 0x10 + 2*irq + 1);
 return entry;
}

variable_types:
irq
unsigned char

variable_types: union ioapic_irqentry { struct { unsigned int vector; unsigned int reserved1; }; struct { unsigned int value_low; unsigned int value_high; }; unsigned long value; }


decompiled_code:
__int64 ioapic_get_8259A_pin()
{
int *v0; // r13
int v1; // ebp
__int64 v2; // rbx
int v3; // er12
int v4; // eax

if ( nr_ioapics <= 0 )
return -1LL;
v0 = &ioapic_descs[2];
v1 = 0;
do
{
v2 = 0LL;
v3 = *(unsigned __int8 *)v0 + 1;
do
{
v4 = ioapic_read_irqentry(v1, v2);
if ( ((BYTE1(v4) ^ 7) & 7) == 0 && (v4 & 0x10000) == 0 )
return (v2 << 32) | (unsigned int)v1;
v2 = (unsigned int)(v2 + 1);
}
while ( (_DWORD)v2 != v3 );
++v1;
v0 += 3;
}
while ( nr_ioapics > v1 );
return -1LL;
}

canonical_decompiled_code:
__int64 func8()
{
int *v0; // r13
int v1; // ebp
__int64 v2; // rbx
int v3; // er12
int v4; // eax

if ( nr_ioapics <= 0 )
return -1LL;
v0 = &ioapic_descs[2];
v1 = 0;
do
{
v2 = 0LL;
v3 = *(unsigned __int8 *)v0 + 1;
do
{
v4 = func7(v1, v2);
if ( ((BYTE1(v4) ^ 7) & 7) == 0 && (v4 & 0x10000) == 0 )
return (v2 << 32) | (unsigned int)v1;
v2 = (unsigned int)(v2 + 1);
}
while ( (_DWORD)v2 != v3 );
++v1;
v0 += 3;
}
while ( nr_ioapics > v1 );
return -1LL;
}

original_code:
static struct ioapic_pin ioapic_get_8259A_pin(void)
{
 union ioapic_irqentry entry;
 struct ioapic_pin pic = { .apic = -1, .pin = -1 };
 int max_irq;
 for (int apic = 0; apic < nr_ioapics; apic++) {
  max_irq = ioapic_descs[apic].max_irq;
  for (int irq = 0; irq <= max_irq; irq++) {
   entry = ioapic_read_irqentry(apic, irq);
   if (entry.delivery_mode != IOAPIC_DELMOD_EXTINT)
    continue;
   if (entry.mask != IOAPIC_UNMASK)
    continue;
   pic.apic = apic;
   pic.pin = irq;
   return pic;
  }
 }
 return pic;
}

canonical_original_code:
static struct ioapic_pin ioapic_get_8259A_pin()
{
 union ioapic_irqentry entry;
 struct ioapic_pin pic = { .apic = -1, .pin = -1 };
 int max_irq;
 for (int apic = 0; apic < nr_ioapics; apic++) {
  max_irq = ioapic_descs[apic].max_irq;
  for (int irq = 0; irq <= max_irq; irq++) {
   entry = ioapic_read_irqentry(apic, irq);
   if (entry.delivery_mode != IOAPIC_DELMOD_EXTINT)
    continue;
   if (entry.mask != IOAPIC_UNMASK)
    continue;
   pic.apic = apic;
   pic.pin = irq;
   return pic;
  }
 }
 return pic;
}

return_type: struct ioapic_pin { int apic; int pin; }

user_defined_types: union ioapic_irqentry { struct { unsigned int vector; unsigned int reserved1; }; struct { unsigned int value_low; unsigned int value_high; }; unsigned long value; }


decompiled_code:
__int64 ioapic_init()
{
int *v0; // rbp
unsigned int v1; // ebx
unsigned int v2; // eax
__int64 v3; // rdx
unsigned int v4; // er12
unsigned int v5; // er13
int v6; // eax
__int64 v7; // r9
__int64 v8; // rsi
__int64 v9; // rbx
signed __int64 v10; // rax
unsigned int v11; // ebp
__int64 result; // rax
int *v13; // r12
int v14; // ebp
int v15; // ebx
char v16; // si

v0 = ioapic_descs;
v1 = 0;
printk("APIC: %d I/O APIC(s) found\n", (unsigned int)nr_ioapics);
if ( nr_ioapics > 0 )
{
do
{
v2 = ioapic_read(v1, 0);
v3 = *(unsigned __int8 *)v0;
v4 = v2;
v5 = HIBYTE(v2);
if ( (_BYTE)v3 != HIBYTE(v2) )
{
printk("IOAPIC[%d]: BIOS tables apic_id=0x%x, chip's apic_id=0x%x\n", v1, v3, HIBYTE(v2));
printk("IOAPIC[%d]: Writing BIOS value to chip\n", v1);
v5 = *(unsigned __int8 *)v0;
ioapic_write(v1, 0, v4 & 0xFFFFFF | (v5 << 24));
}
v0 += 3;
v6 = ioapic_read(v1, 1u);
v7 = (unsigned int)*(v0 - 2);
v8 = v1;
*((_BYTE *)v0 - 11) = v6;
++v1;
*((_BYTE *)v0 - 4) = BYTE2(v6);
printk(
"IOAPIC[%d]: apic_id 0x%x, version 0x%x, maxirq %d, address 0x%x\n",
v8,
v5,
(unsigned __int8)v6,
BYTE2(v6),
v7);
}
while ( nr_ioapics > (int)v1 );
}
v9 = ioapic_get_8259A_pin();
v10 = ioapic_isa_pin(0, 3);
v11 = v10;
if ( (_DWORD)v9 == -1 )
{
if ( (_DWORD)v10 != -1 )
{
printk("IOAPIC[%d]: MP - i8259 INT connected to pin %d\n", (unsigned int)v10, v10 >> 32);
printk("IOAPIC[%d]: MP tables and routing entries differ\n", v11);
}
}
else
{
printk("IOAPIC[%d]: ExtINT - i8259 INT connected to pin %d\n", (unsigned int)v9, v9 >> 32);
}
result = (unsigned int)nr_ioapics;
if ( nr_ioapics > 0 )
{
v13 = &ioapic_descs[2];
v14 = 0;
do
{
v15 = 0;
if ( *(_BYTE *)v13 )
{
do
{
v16 = v15++;
ioapic_mask_irq(v14, v16);
result = *(unsigned __int8 *)v13;
}
while ( (int)result > v15 );
}
++v14;
v13 += 3;
}
while ( nr_ioapics > v14 );
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int *v0; // rbp
unsigned int v1; // ebx
unsigned int v2; // eax
__int64 v3; // rdx
unsigned int v4; // er12
unsigned int v5; // er13
int v6; // eax
__int64 v7; // r9
__int64 v8; // rsi
__int64 v9; // rbx
signed __int64 v10; // rax
unsigned int v11; // ebp
__int64 result; // rax
int *v13; // r12
int v14; // ebp
int v15; // ebx
char v16; // si

v0 = ioapic_descs;
v1 = 0;
printk("APIC: %d I/O APIC(s) found\n", (unsigned int)nr_ioapics);
if ( nr_ioapics > 0 )
{
do
{
v2 = func6(v1, 0);
v3 = *(unsigned __int8 *)v0;
v4 = v2;
v5 = HIBYTE(v2);
if ( (_BYTE)v3 != HIBYTE(v2) )
{
printk("IOAPIC[%d]: BIOS tables apic_id=0x%x, chip's apic_id=0x%x\n", v1, v3, HIBYTE(v2));
printk("IOAPIC[%d]: Writing BIOS value to chip\n", v1);
v5 = *(unsigned __int8 *)v0;
func4(v1, 0, v4 & 0xFFFFFF | (v5 << 24));
}
v0 += 3;
v6 = func6(v1, 1u);
v7 = (unsigned int)*(v0 - 2);
v8 = v1;
*((_BYTE *)v0 - 11) = v6;
++v1;
*((_BYTE *)v0 - 4) = BYTE2(v6);
printk(
"IOAPIC[%d]: apic_id 0x%x, version 0x%x, maxirq %d, address 0x%x\n",
v8,
v5,
(unsigned __int8)v6,
BYTE2(v6),
v7);
}
while ( nr_ioapics > (int)v1 );
}
v9 = func8();
v10 = func2(0, 3);
v11 = v10;
if ( (_DWORD)v9 == -1 )
{
if ( (_DWORD)v10 != -1 )
{
printk("IOAPIC[%d]: MP - i8259 INT connected to pin %d\n", (unsigned int)v10, v10 >> 32);
printk("IOAPIC[%d]: MP tables and routing entries differ\n", v11);
}
}
else
{
printk("IOAPIC[%d]: ExtINT - i8259 INT connected to pin %d\n", (unsigned int)v9, v9 >> 32);
}
result = (unsigned int)nr_ioapics;
if ( nr_ioapics > 0 )
{
v13 = &ioapic_descs[2];
v14 = 0;
do
{
v15 = 0;
if ( *(_BYTE *)v13 )
{
do
{
v16 = v15++;
func9(v14, v16);
result = *(unsigned __int8 *)v13;
}
while ( (int)result > v15 );
}
++v14;
v13 += 3;
}
while ( nr_ioapics > v14 );
}
return result;
}

original_code:
void ioapic_init(void)
{
 union ioapic_id id = { .value = 0 };
 union ioapic_ver version = { .value = 0 };
 struct ioapic_pin pin1, pin2;
 printk("APIC: %d I/O APIC(s) found\n", nr_ioapics);
 for (int apic = 0; apic < nr_ioapics; apic++) {
  id.value = ioapic_read(apic, 0x00);
  if (id.id != ioapic_descs[apic].id) {
   printk("IOAPIC[%d]: BIOS tables apic_id=0x%x, "
          "chip's apic_id=0x%x\n", apic,
          ioapic_descs[apic].id, id.id);
   printk("IOAPIC[%d]: Writing BIOS value to chip\n",
          apic);
   id.id = ioapic_descs[apic].id;
   ioapic_write(apic, 0x00, id.value);
  }
  version.value = ioapic_read(apic, 0x01);
  ioapic_descs[apic].version = version.version;
  ioapic_descs[apic].max_irq = version.max_irq;
  printk("IOAPIC[%d]: apic_id 0x%x, version 0x%x, maxirq %d, "
         "address 0x%x\n", apic, id.id, version.version,
         ioapic_descs[apic].max_irq, ioapic_descs[apic].base);
 }
 pin1 = ioapic_get_8259A_pin();
 pin2 = ioapic_isa_pin(0, MP_ExtINT);
 if (pin1.apic != -1) {
  i8259_pin = pin1;
  printk("IOAPIC[%d]: ExtINT - i8259 INT connected to pin %d\n",
         pin1.apic, pin1.pin);
 } else if (pin2.apic != -1) {
  i8259_pin = pin2;
  printk("IOAPIC[%d]: MP - i8259 INT connected to pin %d\n",
         pin2.apic, pin2.pin);
  printk("IOAPIC[%d]: MP tables and routing entries differ\n",
         pin2.apic);
 }
 for (int apic = 0; apic < nr_ioapics; apic++)
  for (int irq = 0; irq < ioapic_descs[apic].max_irq; irq++)
   ioapic_mask_irq(apic, irq);
}

canonical_original_code:
void ioapic_init()
{
 union ioapic_id id = { .value = 0 };
 union ioapic_ver version = { .value = 0 };
 struct ioapic_pin pin1; struct ioapic_pin pin2;
 printk("APIC: %d I/O APIC(s) found\n", nr_ioapics);
 for (int apic = 0; apic < nr_ioapics; apic++) {
  id.value = ioapic_read(apic, 0x00);
  if (id.id != ioapic_descs[apic].id) {
   printk("IOAPIC[%d]: BIOS tables apic_id=0x%x, "
          "chip's apic_id=0x%x\n", apic,
          ioapic_descs[apic].id, id.id);
   printk("IOAPIC[%d]: Writing BIOS value to chip\n",
          apic);
   id.id = ioapic_descs[apic].id;
   ioapic_write(apic, 0x00, id.value);
  }
  version.value = ioapic_read(apic, 0x01);
  ioapic_descs[apic].version = version.version;
  ioapic_descs[apic].max_irq = version.max_irq;
  printk("IOAPIC[%d]: apic_id 0x%x, version 0x%x, maxirq %d, "
         "address 0x%x\n", apic, id.id, version.version,
         ioapic_descs[apic].max_irq, ioapic_descs[apic].base);
 }
 pin1 = ioapic_get_8259A_pin();
 pin2 = ioapic_isa_pin(0, MP_ExtINT);
 if (pin1.apic != -1) {
  i8259_pin = pin1;
  printk("IOAPIC[%d]: ExtINT - i8259 INT connected to pin %d\n",
         pin1.apic, pin1.pin);
 } else if (pin2.apic != -1) {
  i8259_pin = pin2;
  printk("IOAPIC[%d]: MP - i8259 INT connected to pin %d\n",
         pin2.apic, pin2.pin);
  printk("IOAPIC[%d]: MP tables and routing entries differ\n",
         pin2.apic);
 }
 for (int apic = 0; apic < nr_ioapics; apic++)
  for (int irq = 0; irq < ioapic_descs[apic].max_irq; irq++)
   ioapic_mask_irq(apic, irq);
}

variable_types: union ioapic_id { unsigned int value; struct { unsigned int reserved0; }; }

variable_types: union ioapic_ver { unsigned int value; struct { unsigned int version; }; }

user_defined_types: struct ioapic_pin { int apic; int pin; }


decompiled_code:
char __fastcall mpf_checksum(_BYTE *a1, int a2)
{
char result; // al
_BYTE *v3; // rdx

if ( !a2 )
return 0;
result = 0;
v3 = &a1[a2];
do
result += *a1++;
while ( a1 != v3 );
return result;
}

canonical_decompiled_code:
char __fastcall func0(_BYTE *a1, int a2)
{
char result; // al
_BYTE *v3; // rdx

if ( !a2 )
return 0;
result = 0;
v3 = &a1[a2];
do
result += *a1++;
while ( a1 != v3 );
return result;
}

original_code:
static uint8_t mpf_checksum(void *mp, uint32_t len)
{
 uint8_t sum = 0;
 uint8_t *buf = mp;
 while (len--)
  sum += *buf++;
 return sum;
}

canonical_original_code:
static unsigned char mpf_checksum(void *mp, unsigned int len)
{
 unsigned char sum = 0;
 unsigned char *buf = mp;
 while (len--)
  sum += *buf++;
 return sum;
}

variable_types:
mp
void *

variable_types:
len
unsigned int

variable_types:
sum
unsigned char

variable_types:
buf
unsigned char *

return_type: unsigned char


decompiled_code:
__int64 __fastcall parse_cpu(__int64 a1)
{
__int64 result; // rax
int v2; // esi
int v3; // edx

result = *(unsigned __int8 *)(a1 + 3);
if ( (result & 1) != 0 )
{
if ( (result & 2) != 0 )
{
if ( !bsc_entry_filled_0 )
{
result = *(unsigned __int8 *)(a1 + 1);
bsc_entry_filled_0 = 1;
*((_DWORD *)&cpus + 2) = result;
return result;
}
}
else
{
v2 = nr_cpus;
if ( nr_cpus <= 63 )
{
v3 = *(unsigned __int8 *)(a1 + 1);
++nr_cpus;
result = 768LL * v2;
*(_DWORD *)((char *)&cpus + result + 8) = v3;
return result;
}
panic("Only %d logical CPU cores supported\n", (unsigned int)nr_cpus);
}
panic("Two `bootstrap' cores in the MP tables! Either the BIOS or our parser is buggy.");
result = parse_ioapic();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
int v2; // esi
int v3; // edx

result = *(unsigned __int8 *)(a1 + 3);
if ( (result & 1) != 0 )
{
if ( (result & 2) != 0 )
{
if ( !bsc_entry_filled_0 )
{
result = *(unsigned __int8 *)(a1 + 1);
bsc_entry_filled_0 = 1;
*((_DWORD *)&cpus + 2) = result;
return result;
}
}
else
{
v2 = nr_cpus;
if ( nr_cpus <= 63 )
{
v3 = *(unsigned __int8 *)(a1 + 1);
++nr_cpus;
result = 768LL * v2;
*(_DWORD *)((char *)&cpus + result + 8) = v3;
return result;
}
panic("Only %d logical CPU cores supported\n", (unsigned int)nr_cpus);
}
panic("Two `bootstrap' cores in the MP tables! Either the BIOS or our parser is buggy.");
result = func2();
}
return result;
}

original_code:
static void parse_cpu(void *addr)
{
 struct mpc_cpu *cpu = addr;
 static _Bool bsc_entry_filled;
 if (!cpu->enabled)
  return;
 if (cpu->bsc) {
  if (bsc_entry_filled)
   panic("Two `bootstrap' cores in the MP tables! "
         "Either the BIOS or our parser is buggy.");
  cpus[0].apic_id = cpu->lapic_id;
  bsc_entry_filled = 1;
  return;
 }
 if (nr_cpus >= 64)
  panic("Only %d logical CPU cores supported\n", nr_cpus);
 cpus[nr_cpus].apic_id = cpu->lapic_id;
 ++nr_cpus;
}

variable_types:
addr
void *

variable_types: struct mpc_cpu { unsigned char entry; unsigned char lapic_id; unsigned char lapic_ver; unsigned char enabled; unsigned int signature; unsigned int flags; unsigned long reserved; } *


decompiled_code:
void __fastcall parse_ioapic(__int64 a1)
{
int v1; // eax
char v2; // cl
__int64 v3; // rdx

if ( (*(_BYTE *)(a1 + 3) & 1) != 0 )
{
v1 = nr_ioapics;
if ( nr_ioapics > 7 )
{
panic("Only %d IO APICs supported", 8LL);
parse_irq();
}
else
{
v2 = *(_BYTE *)(a1 + 1);
++nr_ioapics;
v3 = 12LL * v1;
*((_BYTE *)&ioapic_descs + v3) = v2;
*(_DWORD *)((char *)&ioapic_descs + v3 + 4) = *(_DWORD *)(a1 + 4);
}
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
int v1; // eax
char v2; // cl
__int64 v3; // rdx

if ( (*(_BYTE *)(a1 + 3) & 1) != 0 )
{
v1 = nr_ioapics;
if ( nr_ioapics > 7 )
{
panic("Only %d IO APICs supported", 8LL);
func3();
}
else
{
v2 = *(_BYTE *)(a1 + 1);
++nr_ioapics;
v3 = 12LL * v1;
*((_BYTE *)&ioapic_descs + v3) = v2;
*(_DWORD *)((char *)&ioapic_descs + v3 + 4) = *(_DWORD *)(a1 + 4);
}
}
}

original_code:
static void parse_ioapic(void *addr)
{
 struct mpc_ioapic *ioapic = addr;
 if (!ioapic->enabled)
  return;
 if (nr_ioapics >= 8)
  panic("Only %d IO APICs supported", 8);
 ioapic_descs[nr_ioapics].id = ioapic->id;
 ioapic_descs[nr_ioapics].base = ioapic->base;
 ++nr_ioapics;
}

variable_types: struct mpc_ioapic { unsigned char entry; unsigned char id; unsigned char version; unsigned char enabled; unsigned int base; } *


decompiled_code:
__int64 __fastcall parse_irq(__int64 *a1)
{
__int64 v1; // rcx
__int64 v2; // rdx
__int64 result; // rax

if ( nr_mpcirqs > 223 )
{
panic("Only %d IRQ sources supported", 224LL);
result = search_for_mpf();
}
else
{
v1 = *a1;
v2 = nr_mpcirqs;
result = (unsigned int)++nr_mpcirqs;
mp_irqs[v2] = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 v1; // rcx
__int64 v2; // rdx
__int64 result; // rax

if ( nr_mpcirqs > 223 )
{
panic("Only %d IRQ sources supported", 224LL);
result = search_for_mpf();
}
else
{
v1 = *a1;
v2 = nr_mpcirqs;
result = (unsigned int)++nr_mpcirqs;
mp_irqs[v2] = v1;
}
return result;
}

original_code:
static void parse_irq(void *addr)
{
 struct mpc_irq *irq = addr;
 if (nr_mpcirqs >= (0xff - 0x1f))
  panic("Only %d IRQ sources supported", (0xff - 0x1f));
 mp_irqs[nr_mpcirqs] = *irq;
 ++nr_mpcirqs;
}

variable_types: struct mpc_irq { unsigned char entry; unsigned char type; unsigned short polarity; unsigned char src_busid; unsigned char src_busirq; unsigned char dst_ioapicid; unsigned char dst_ioapicpin; } *


decompiled_code:
_BYTE *get_mpf()
{
_BYTE *result; // rax

result = search_for_mpf((_BYTE *)(16 * MEMORY[0xFFFF80000000040E] - 0x800000000000LL), 0x400u);
if ( !result )
{
result = search_for_mpf((_BYTE *)0xFFFF80000009FC00LL, 0x400u);
if ( !result )
result = search_for_mpf((_BYTE *)0xFFFF8000000F0000LL, 0x10000u);
}
return result;
}

canonical_decompiled_code:
_BYTE *func4()
{
_BYTE *result; // rax

result = search_for_mpf((_BYTE *)(16 * MEMORY[0xFFFF80000000040E] - 0x800000000000LL), 0x400u);
if ( !result )
{
result = search_for_mpf((_BYTE *)0xFFFF80000009FC00LL, 0x400u);
if ( !result )
result = search_for_mpf((_BYTE *)0xFFFF8000000F0000LL, 0x10000u);
}
return result;
}

original_code:
static struct mpf_struct *get_mpf(void)
{
 uintptr_t ebda;
 struct mpf_struct *mpf;
 ebda = (*(uint16_t *)({ do { if (__builtin_expect((!((uintptr_t)(0x40e) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x40e) >= KERN_PHYS_OFFSET" ")\n", "kern/mptables.c", 121); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0x40e) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x40e) < KERN_PHYS_END_MAX" ")\n", "kern/mptables.c", 121); } while (0);; (void *)((char *)(0x40e) + 0xffff800000000000ULL); })) << 4;
 mpf = search_for_mpf(({ do { if (__builtin_expect((!((uintptr_t)(ebda) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(ebda) >= KERN_PHYS_OFFSET" ")\n", "kern/mptables.c", 122); } while (0);; do { if (__builtin_expect((!((uintptr_t)(ebda) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(ebda) < KERN_PHYS_END_MAX" ")\n", "kern/mptables.c", 122); } while (0);; (void *)((char *)(ebda) + 0xffff800000000000ULL); }), 0x400);
 if (mpf != ((void *)0))
  return mpf;
 mpf = search_for_mpf(({ do { if (__builtin_expect((!((uintptr_t)(639 * 0x400) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(639 * 0x400) >= KERN_PHYS_OFFSET" ")\n", "kern/mptables.c", 126); } while (0);; do { if (__builtin_expect((!((uintptr_t)(639 * 0x400) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(639 * 0x400) < KERN_PHYS_END_MAX" ")\n", "kern/mptables.c", 126); } while (0);; (void *)((char *)(639 * 0x400) + 0xffff800000000000ULL); }), 0x400);
 if (mpf != ((void *)0))
  return mpf;
 mpf = search_for_mpf(({ do { if (__builtin_expect((!((uintptr_t)(0xF0000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0xF0000) >= KERN_PHYS_OFFSET" ")\n", "kern/mptables.c", 130); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0xF0000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0xF0000) < KERN_PHYS_END_MAX" ")\n", "kern/mptables.c", 130); } while (0);; (void *)((char *)(0xF0000) + 0xffff800000000000ULL); }), 0x10000);
 if (mpf != ((void *)0))
  return mpf;
 return ((void *)0);
}

canonical_original_code:
static struct mpf_struct *get_mpf()
{
 unsigned long ebda;
 struct mpf_struct *mpf;
 ebda = (*(unsigned short *)({ do { if (__builtin_expect((!((unsigned long)(0x40e) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x40e) >= KERN_PHYS_OFFSET" ")\n", "kern/mptables.c", 121); } while (0);; do { if (__builtin_expect((!((unsigned long)(0x40e) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x40e) < KERN_PHYS_END_MAX" ")\n", "kern/mptables.c", 121); } while (0);; (void *)((char *)(0x40e) + 0xffff800000000000ULL); })) << 4;
 mpf = search_for_mpf(({ do { if (__builtin_expect((!((unsigned long)(ebda) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(ebda) >= KERN_PHYS_OFFSET" ")\n", "kern/mptables.c", 122); } while (0);; do { if (__builtin_expect((!((unsigned long)(ebda) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(ebda) < KERN_PHYS_END_MAX" ")\n", "kern/mptables.c", 122); } while (0);; (void *)((char *)(ebda) + 0xffff800000000000ULL); }), 0x400);
 if (mpf != ((void *)0))
  return mpf;
 mpf = search_for_mpf(({ do { if (__builtin_expect((!((unsigned long)(639 * 0x400) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(639 * 0x400) >= KERN_PHYS_OFFSET" ")\n", "kern/mptables.c", 126); } while (0);; do { if (__builtin_expect((!((unsigned long)(639 * 0x400) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(639 * 0x400) < KERN_PHYS_END_MAX" ")\n", "kern/mptables.c", 126); } while (0);; (void *)((char *)(639 * 0x400) + 0xffff800000000000ULL); }), 0x400);
 if (mpf != ((void *)0))
  return mpf;
 mpf = search_for_mpf(({ do { if (__builtin_expect((!((unsigned long)(0xF0000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0xF0000) >= KERN_PHYS_OFFSET" ")\n", "kern/mptables.c", 130); } while (0);; do { if (__builtin_expect((!((unsigned long)(0xF0000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0xF0000) < KERN_PHYS_END_MAX" ")\n", "kern/mptables.c", 130); } while (0);; (void *)((char *)(0xF0000) + 0xffff800000000000ULL); }), 0x10000);
 if (mpf != ((void *)0))
  return mpf;
 return ((void *)0);
}

variable_types:
ebda
unsigned long

variable_types: struct mpf_struct { unsigned int signature; unsigned int conf_physaddr; unsigned char length; unsigned char version; unsigned char checksum; unsigned char feature1; unsigned char feature2_reserved; unsigned char feature3; unsigned char feature4; unsigned char feature5; } *


decompiled_code:
__int64 __fastcall mpc_check(unsigned int *a1)
{
__int64 v1; // rsi
__int64 v2; // rsi
unsigned __int8 v3; // al
unsigned int v4; // er8
__int64 result; // rax

v1 = *a1;
if ( (_DWORD)v1 == 1347240784 )
{
v2 = *((unsigned __int8 *)a1 + 6);
if ( (_BYTE)v2 == 1 || (_BYTE)v2 == 4 )
{
v3 = mpf_checksum(a1, *((unsigned __int16 *)a1 + 2));
if ( v3 )
{
printk("MP: buggy configuration table checksum = 0x%x\n", v3);
result = 0LL;
}
else
{
result = v4;
}
}
else
{
printk("MP: Wrong configuration table version = 0x%x\n", v2);
result = 0LL;
}
}
else
{
printk("MP: Wrong configuration table signature = 0x%x\n", v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
__int64 v1; // rsi
__int64 v2; // rsi
unsigned __int8 v3; // al
unsigned int v4; // er8
__int64 result; // rax

v1 = *a1;
if ( (_DWORD)v1 == 1347240784 )
{
v2 = *((unsigned __int8 *)a1 + 6);
if ( (_BYTE)v2 == 1 || (_BYTE)v2 == 4 )
{
v3 = func0(a1, *((unsigned __int16 *)a1 + 2));
if ( v3 )
{
printk("MP: buggy configuration table checksum = 0x%x\n", v3);
result = 0LL;
}
else
{
result = v4;
}
}
else
{
printk("MP: Wrong configuration table version = 0x%x\n", v2);
result = 0LL;
}
}
else
{
printk("MP: Wrong configuration table signature = 0x%x\n", v1);
result = 0LL;
}
return result;
}

original_code:
static int mpc_check(struct mpc_table *mpc)
{
 uint8_t checksum;
 if (mpc->signature != ('P'<<(3 * 8) | 'M'<<(2 * 8) | 'C'<<(1 * 8) | 'P')) {
  printk("MP: Wrong configuration table signature = 0x%x\n",
         mpc->signature);
  return 0;
 }
 if (mpc->version != 0x01 && mpc->version != 0x04) {
  printk("MP: Wrong configuration table version = 0x%x\n",
         mpc->version);
  return 0;
 }
 checksum = mpf_checksum(mpc, mpc->length);
 if (checksum != 0) {
  printk("MP: buggy configuration table checksum = 0x%x\n",
         checksum);
  return 0;
 }
 return 1;
}

canonical_original_code:
static int mpc_check(struct mpc_table *mpc)
{
 unsigned char checksum;
 if (mpc->signature != ('P'<<(3 * 8) | 'M'<<(2 * 8) | 'C'<<(1 * 8) | 'P')) {
  printk("MP: Wrong configuration table signature = 0x%x\n",
         mpc->signature);
  return 0;
 }
 if (mpc->version != 0x01 && mpc->version != 0x04) {
  printk("MP: Wrong configuration table version = 0x%x\n",
         mpc->version);
  return 0;
 }
 checksum = mpf_checksum(mpc, mpc->length);
 if (checksum != 0) {
  printk("MP: buggy configuration table checksum = 0x%x\n",
         checksum);
  return 0;
 }
 return 1;
}

variable_types: struct mpc_table { unsigned int signature; unsigned short length; unsigned char version; unsigned char checksum; char oem[8]; char product[12]; unsigned int oem_physaddr; unsigned short oem_size; unsigned short entries; unsigned int lapic_base; unsigned short ext_length; unsigned char ext_checksum; unsigned char reserved; } *

variable_types:
checksum
unsigned char


decompiled_code:
int __fastcall parse_bus(__int64 a1)
{
int result; // eax

result = memcmp("ISA", (const void *)(a1 + 2), 3uLL);
if ( !result )
{
result = *(unsigned __int8 *)(a1 + 1);
mp_isa_busid = result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax

result = memcmp("ISA", (const void *)(a1 + 2), 3uLL);
if ( !result )
{
result = *(unsigned __int8 *)(a1 + 1);
mp_isa_busid = result;
}
return result;
}

original_code:
static void parse_bus(void *addr)
{
 struct mpc_bus *bus = addr;
 if (memcmp("ISA", bus->type, sizeof("ISA") - 1) == 0)
  mp_isa_busid = bus->id;
 return;
}

variable_types: struct mpc_bus { unsigned char entry; unsigned char id; char type[6]; } *


decompiled_code:
__int64 __fastcall parse_mpc(__int64 a1)
{
int v1; // ebp
__int64 v2; // r14
__int64 *v3; // r15
unsigned __int64 v5; // rdi
__int64 *v6; // rax
__int64 v7; // rsi
__int64 result; // rax

if ( !*(_WORD *)(a1 + 34) )
return 1LL;
v5 = a1 + 44;
if ( v5 <= 0xFFFF7FFFFFFFFFFFLL )
{
LABEL_16:
panic("%s:%d - !((uintptr_t)(entry) >= KERN_PAGE_OFFSET)\n", "kern/mptables.c", 284LL);
return 1LL;
}
if ( v5 > 0xFFFFBFFFFFFFFFFFLL )
{
while ( 1 )
{
v6 = (__int64 *)panic("%s:%d - !((uintptr_t)(entry) < KERN_PAGE_END_MAX)\n", "kern/mptables.c", 284LL);
LABEL_11:
parse_ioapic((__int64)v6);
v5 = (unsigned __int64)(v3 + 1);
LABEL_7:
if ( *(unsigned __int16 *)(a1 + 34) <= ++v1 )
return 1LL;
if ( v5 <= 0xFFFF7FFFFFFFFFFFLL )
goto LABEL_16;
if ( v5 <= 0xFFFFBFFFFFFFFFFFLL )
goto LABEL_5;
}
}
v2 = 0x800000000000LL;
v1 = 0;
LABEL_5:
v6 = (__int64 *)vm_kmap(v2 + v5, 20LL);
v7 = *(unsigned __int8 *)v6;
v3 = v6;
switch ( (char)v7 )
{
case 0:
parse_cpu((__int64)v6);
v5 = (unsigned __int64)v3 + 20;
goto LABEL_7;
case 1:
parse_bus((__int64)v6);
v5 = (unsigned __int64)(v3 + 1);
goto LABEL_7;
case 2:
goto LABEL_11;
case 3:
parse_irq(v6);
v5 = (unsigned __int64)(v3 + 1);
goto LABEL_7;
case 4:
v5 = (unsigned __int64)(v6 + 1);
goto LABEL_7;
default:
printk("MP: Unknown conf table entry type = %d\n", v7);
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ebp
__int64 v2; // r14
__int64 *v3; // r15
unsigned __int64 v5; // rdi
__int64 *v6; // rax
__int64 v7; // rsi
__int64 result; // rax

if ( !*(_WORD *)(a1 + 34) )
return 1LL;
v5 = a1 + 44;
if ( v5 <= 0xFFFF7FFFFFFFFFFFLL )
{
LABEL_16:
panic("%s:%d - !((uintptr_t)(entry) >= KERN_PAGE_OFFSET)\n", "kern/mptables.c", 284LL);
return 1LL;
}
if ( v5 > 0xFFFFBFFFFFFFFFFFLL )
{
while ( 1 )
{
v6 = (__int64 *)panic("%s:%d - !((uintptr_t)(entry) < KERN_PAGE_END_MAX)\n", "kern/mptables.c", 284LL);
LABEL_11:
func2((__int64)v6);
v5 = (unsigned __int64)(v3 + 1);
LABEL_7:
if ( *(unsigned __int16 *)(a1 + 34) <= ++v1 )
return 1LL;
if ( v5 <= 0xFFFF7FFFFFFFFFFFLL )
goto LABEL_16;
if ( v5 <= 0xFFFFBFFFFFFFFFFFLL )
goto LABEL_5;
}
}
v2 = 0x800000000000LL;
v1 = 0;
LABEL_5:
v6 = (__int64 *)vm_kmap(v2 + v5, 20LL);
v7 = *(unsigned __int8 *)v6;
v3 = v6;
switch ( (char)v7 )
{
case 0:
func1((__int64)v6);
v5 = (unsigned __int64)v3 + 20;
goto LABEL_7;
case 1:
func6((__int64)v6);
v5 = (unsigned __int64)(v3 + 1);
goto LABEL_7;
case 2:
goto LABEL_11;
case 3:
func3(v6);
v5 = (unsigned __int64)(v3 + 1);
goto LABEL_7;
case 4:
v5 = (unsigned __int64)(v6 + 1);
goto LABEL_7;
default:
printk("MP: Unknown conf table entry type = %d\n", v7);
result = 0LL;
break;
}
return result;
}

original_code:
static int parse_mpc(struct mpc_table *mpc)
{
 uint8_t *entry;
 entry = (uint8_t *)(mpc + 1);
 for (int i = 0; i < mpc->entries; i++) {
  entry = vm_kmap(({ do { if (__builtin_expect((!((uintptr_t)(entry) >= 0xffff800000000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(entry) >= KERN_PAGE_OFFSET" ")\n", "kern/mptables.c", 284); } while (0);; do { if (__builtin_expect((!((uintptr_t)(entry) < 0xffffc00000000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(entry) < KERN_PAGE_END_MAX" ")\n", "kern/mptables.c", 284); } while (0);; (uintptr_t)((char *)(entry) - 0xffff800000000000ULL); }), (sizeof(struct mpc_cpu)));
  switch (*entry) {
  case MP_PROCESSOR:
   parse_cpu(entry);
   entry += sizeof(struct mpc_cpu);
   break;
  case MP_BUS:
   parse_bus(entry);
   entry += sizeof(struct mpc_bus);
   break;
  case MP_IOAPIC:
   parse_ioapic(entry);
   entry += sizeof(struct mpc_ioapic);
   break;
  case MP_IOINTERRUPT:
   parse_irq(entry);
   entry += sizeof(struct mpc_irq);
   break;
  case MP_LINTERRUPT:
   entry += sizeof(struct mpc_linterrupt);
   break;
  default:
   printk("MP: Unknown conf table entry type = %d\n",
         *entry);
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
static int parse_mpc(struct mpc_table *mpc)
{
 unsigned char *entry;
 entry = (unsigned char *)(mpc + 1);
 for (int i = 0; i < mpc->entries; i++) {
  entry = vm_kmap(({ do { if (__builtin_expect((!((unsigned long)(entry) >= 0xffff800000000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(entry) >= KERN_PAGE_OFFSET" ")\n", "kern/mptables.c", 284); } while (0);; do { if (__builtin_expect((!((unsigned long)(entry) < 0xffffc00000000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(entry) < KERN_PAGE_END_MAX" ")\n", "kern/mptables.c", 284); } while (0);; (unsigned long)((char *)(entry) - 0xffff800000000000ULL); }), (sizeof(struct mpc_cpu)));
  switch (*entry) {
  case MP_PROCESSOR:
   parse_cpu(entry);
   entry += sizeof(struct mpc_cpu);
   break;
  case MP_BUS:
   parse_bus(entry);
   entry += sizeof(struct mpc_bus);
   break;
  case MP_IOAPIC:
   parse_ioapic(entry);
   entry += sizeof(struct mpc_ioapic);
   break;
  case MP_IOINTERRUPT:
   parse_irq(entry);
   entry += sizeof(struct mpc_irq);
   break;
  case MP_LINTERRUPT:
   entry += sizeof(struct mpc_linterrupt);
   break;
  default:
   printk("MP: Unknown conf table entry type = %d\n",
         *entry);
   return 0;
  }
 }
 return 1;
}

variable_types:
entry
unsigned char *

variable_types: i int

user_defined_types: struct mpc_cpu { unsigned char entry; unsigned char lapic_id; unsigned char lapic_ver; unsigned char enabled; unsigned int signature; unsigned int flags; unsigned long reserved; }

user_defined_types: struct mpc_bus { unsigned char entry; unsigned char id; char type[6]; }

user_defined_types: struct mpc_ioapic { unsigned char entry; unsigned char id; unsigned char version; unsigned char enabled; unsigned int base; }

user_defined_types: struct mpc_irq { unsigned char entry; unsigned char type; unsigned short polarity; unsigned char src_busid; unsigned char src_busirq; unsigned char dst_ioapicid; unsigned char dst_ioapicpin; }

user_defined_types: struct mpc_linterrupt { unsigned char entry; unsigned char type; unsigned short polarity; unsigned char src_busid; unsigned char src_busirq; unsigned char dst_lapic; unsigned char dst_lapicpin; }

user_defined_types: struct mpc_table { unsigned int signature; unsigned short length; unsigned char version; unsigned char checksum; char oem[8]; char product[12]; unsigned int oem_physaddr; unsigned short oem_size; unsigned short entries; unsigned int lapic_base; unsigned short ext_length; unsigned char ext_checksum; unsigned char reserved; }


decompiled_code:
__int64 __fastcall mpc_dump(void *src)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // al
char dest[13]; // [rsp+Bh] [rbp-Dh] BYREF

dest[4] = 0;
printk("MP: conf table base = %lx\n", src);
memcpy(dest, src, 4uLL);
printk(".. signature = %s\n", dest);
printk(".. length = %d\n", *((unsigned __int16 *)src + 2));
printk(".. version = 0x%x\n", *((unsigned __int8 *)src + 6));
printk(".. checksum = 0x%x\n", *((unsigned __int8 *)src + 7));
printk(".. oem pointer = 0x%x\n", *((unsigned int *)src + 7));
printk(".. oem size = 0x%x\n", *((unsigned __int16 *)src + 16));
printk(".. entries count = %d\n", *((unsigned __int16 *)src + 17));
printk(".. lapic base = 0x%x\n", *((unsigned int *)src + 9));
printk(".. ext length = %d\n", *((unsigned __int16 *)src + 20));
printk(".. ext checksum = 0x%x\n", *((unsigned __int8 *)src + 42));
printk(".. reserved = 0x%x\n", *((unsigned __int8 *)src + 43));
v2 = mpf_checksum(src, *((unsigned __int16 *)src + 2));
printk(".. calculated table checksum = 0x%x\n", v2);
v3 = mpf_checksum((_BYTE *)src + 44, *((unsigned __int16 *)src + 20));
return printk(".. calculated extended entries checksum = 0x%x\n", v3);
}

canonical_decompiled_code:
__int64 __fastcall func8(void *src)
{
unsigned __int8 v2; // al
unsigned __int8 v3; // al
char dest[13]; // [rsp+Bh] [rbp-Dh] BYREF

dest[4] = 0;
printk("MP: conf table base = %lx\n", src);
memcpy(dest, src, 4uLL);
printk(".. signature = %s\n", dest);
printk(".. length = %d\n", *((unsigned __int16 *)src + 2));
printk(".. version = 0x%x\n", *((unsigned __int8 *)src + 6));
printk(".. checksum = 0x%x\n", *((unsigned __int8 *)src + 7));
printk(".. oem pointer = 0x%x\n", *((unsigned int *)src + 7));
printk(".. oem size = 0x%x\n", *((unsigned __int16 *)src + 16));
printk(".. entries count = %d\n", *((unsigned __int16 *)src + 17));
printk(".. lapic base = 0x%x\n", *((unsigned int *)src + 9));
printk(".. ext length = %d\n", *((unsigned __int16 *)src + 20));
printk(".. ext checksum = 0x%x\n", *((unsigned __int8 *)src + 42));
printk(".. reserved = 0x%x\n", *((unsigned __int8 *)src + 43));
v2 = func0(src, *((unsigned __int16 *)src + 2));
printk(".. calculated table checksum = 0x%x\n", v2);
v3 = func0((_BYTE *)src + 44, *((unsigned __int16 *)src + 20));
return printk(".. calculated extended entries checksum = 0x%x\n", v3);
}

original_code:
static void mpc_dump(struct mpc_table *mpc)
{
 char signature[5];
 signature[4] = 0;
 printk("MP: conf table base = %lx\n", mpc);
 memcpy(signature, &(mpc->signature), 4);
 printk(".. signature = %s\n", signature);
 printk(".. length = %d\n", mpc->length);
 printk(".. version = 0x%x\n", mpc->version);
 printk(".. checksum = 0x%x\n", mpc->checksum);
 printk(".. oem pointer = 0x%x\n", mpc->oem_physaddr);
 printk(".. oem size = 0x%x\n", mpc->oem_size);
 printk(".. entries count = %d\n", mpc->entries);
 printk(".. lapic base = 0x%x\n", mpc->lapic_base);
 printk(".. ext length = %d\n", mpc->ext_length);
 printk(".. ext checksum = 0x%x\n", mpc->ext_checksum);
 printk(".. reserved = 0x%x\n", mpc->reserved);
 printk(".. calculated table checksum = 0x%x\n",
        mpf_checksum(mpc, mpc->length));
 printk(".. calculated extended entries checksum = 0x%x\n",
        mpf_checksum(mpc + 1, mpc->ext_length));
}

variable_types:
signature
char [5]


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

result = (unsigned int)nr_cpus;
if ( nr_cpus <= 0 )
{
panic("%s:%d - !(nr_cpus > 0)\n", "kern/mptables.c", 317LL);
result = mptables_init();
}
return result;
}

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

result = (unsigned int)nr_cpus;
if ( nr_cpus <= 0 )
{
panic("%s:%d - !(nr_cpus > 0)\n", "kern/mptables.c", 317LL);
result = func10();
}
return result;
}

original_code:
int __attribute__((const)) mptables_get_nr_cpus(void)
{
 do { if (__builtin_expect((!(nr_cpus > 0)), 0)) panic("%s:%d - !(" "nr_cpus > 0" ")\n", "kern/mptables.c", 317); } while (0);;
 return nr_cpus;
}

canonical_original_code:
int mptables_get_nr_cpus()
{
 do { if (__builtin_expect((!(nr_cpus > 0)), 0)) panic("%s:%d - !(" "nr_cpus > 0" ")\n", "kern/mptables.c", 317); } while (0);;
 return nr_cpus;
}


decompiled_code:
__int64 __fastcall mptables_init()
{
unsigned int *v0; // rbp
_BYTE *v1; // rax
__int64 v2; // rdi
char *v3; // rdi
__int64 result; // rax

v1 = get_mpf();
if ( !v1 )
{
panic("No compliant MP pointer found");
goto LABEL_8;
}
if ( v1[11] )
{
LABEL_11:
panic("MP: Spec `default configuration' is not supported");
JUMPOUT(0x6C0LL);
}
v2 = *((unsigned int *)v1 + 1);
if ( !(_DWORD)v2 )
{
LABEL_10:
panic("MP: Spec configuration table does not exist");
goto LABEL_11;
}
v0 = (unsigned int *)vm_kmap(v2, 44LL);
v3 = (char *)v0;
if ( !(unsigned int)mpc_check(v0) )
{
LABEL_9:
mpc_dump(v3);
panic("Buggy MP conf table header");
goto LABEL_10;
}
result = parse_mpc((__int64)v0);
if ( !(_DWORD)result )
{
LABEL_8:
mpc_dump(v0);
v3 = "Can not parse MP conf table";
panic("Can not parse MP conf table");
goto LABEL_9;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10()
{
unsigned int *v0; // rbp
_BYTE *v1; // rax
__int64 v2; // rdi
char *v3; // rdi
__int64 result; // rax

v1 = func4();
if ( !v1 )
{
panic("No compliant MP pointer found");
goto LABEL_8;
}
if ( v1[11] )
{
LABEL_11:
panic("MP: Spec `default configuration' is not supported");
JUMPOUT(0x6C0LL);
}
v2 = *((unsigned int *)v1 + 1);
if ( !(_DWORD)v2 )
{
LABEL_10:
panic("MP: Spec configuration table does not exist");
goto LABEL_11;
}
v0 = (unsigned int *)vm_kmap(v2, 44LL);
v3 = (char *)v0;
if ( !(unsigned int)func5(v0) )
{
LABEL_9:
func8(v3);
panic("Buggy MP conf table header");
goto LABEL_10;
}
result = func7((__int64)v0);
if ( !(_DWORD)result )
{
LABEL_8:
func8(v0);
v3 = "Can not parse MP conf table";
panic("Can not parse MP conf table");
goto LABEL_9;
}
return result;
}

original_code:
void mptables_init(void)
{
 struct mpf_struct *mpf;
 struct mpc_table *mpc;
 mptables_check();
 mpf = get_mpf();
 if (!mpf)
  panic("No compliant MP pointer found");
 if (mpf->feature1)
  panic("MP: Spec `default configuration' is not supported");
 if (mpf->conf_physaddr == 0)
  panic("MP: Spec configuration table does not exist");
 mpc = vm_kmap(mpf->conf_physaddr, sizeof(*mpc));
 if (!mpc_check(mpc)) {
  mpc_dump(mpc);
  panic("Buggy MP conf table header");
 }
 if (!parse_mpc(mpc)) {
  mpc_dump(mpc);
  panic("Can not parse MP conf table");
 }
}

canonical_original_code:
void mptables_init()
{
 struct mpf_struct *mpf;
 struct mpc_table *mpc;
 mptables_check();
 mpf = get_mpf();
 if (!mpf)
  panic("No compliant MP pointer found");
 if (mpf->feature1)
  panic("MP: Spec `default configuration' is not supported");
 if (mpf->conf_physaddr == 0)
  panic("MP: Spec configuration table does not exist");
 mpc = vm_kmap(mpf->conf_physaddr, sizeof(*mpc));
 if (!mpc_check(mpc)) {
  mpc_dump(mpc);
  panic("Buggy MP conf table header");
 }
 if (!parse_mpc(mpc)) {
  mpc_dump(mpc);
  panic("Can not parse MP conf table");
 }
}

user_defined_types: struct mpf_struct { unsigned int signature; unsigned int conf_physaddr; unsigned char length; unsigned char version; unsigned char checksum; unsigned char feature1; unsigned char feature2_reserved; unsigned char feature3; unsigned char feature4; unsigned char feature5; }


decompiled_code:
__int64 __fastcall get_gdt(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+6h] [rbp-Ah] BYREF
__int16 v3; // [rsp+Eh] [rbp-2h]

result = a1;
__sgdt(&v2);
*(_QWORD *)a1 = v2;
*(_WORD *)(a1 + 8) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+6h] [rbp-Ah] BYREF
__int16 v3; // [rsp+Eh] [rbp-2h]

result = a1;
__sgdt(&v2);
*(_QWORD *)a1 = v2;
*(_WORD *)(a1 + 8) = v3;
return result;
}

original_code:
static inline struct gdt_descriptor get_gdt(void)
{
 struct gdt_descriptor gdt_desc;
 asm volatile("sgdt %0"
       :"=m"(gdt_desc)
       :);
 return gdt_desc;
}

canonical_original_code:
static inline struct gdt_descriptor get_gdt()
{
 struct gdt_descriptor gdt_desc;
 asm volatile("sgdt %0"
       :"=m"(gdt_desc)
       :);
 return gdt_desc;
}

variable_types: struct gdt_descriptor { unsigned short limit; unsigned long base; }


decompiled_code:
unsigned __int64 get_cr3()
{
return __readcr3();
}

canonical_decompiled_code:
unsigned __int64 func1()
{
return __readcr3();
}

original_code:
static inline uint64_t get_cr3(void)
{
 uint64_t cr3;
 asm volatile("mov %%cr3, %0"
       :"=r"(cr3)
       :
       :"cc", "memory");
 return cr3;
}

canonical_original_code:
static inline unsigned long get_cr3()
{
 unsigned long cr3;
 asm volatile("mov %%cr3, %0"
       :"=r"(cr3)
       :
       :"cc", "memory");
 return cr3;
}


decompiled_code:
__int64 __fastcall get_idt(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+6h] [rbp-Ah] BYREF
__int16 v3; // [rsp+Eh] [rbp-2h]

result = a1;
__sidt(&v2);
*(_QWORD *)a1 = v2;
*(_WORD *)(a1 + 8) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
__int64 v2; // [rsp+6h] [rbp-Ah] BYREF
__int16 v3; // [rsp+Eh] [rbp-2h]

result = a1;
__sidt(&v2);
*(_QWORD *)a1 = v2;
*(_WORD *)(a1 + 8) = v3;
return result;
}

original_code:
static inline struct idt_descriptor get_idt(void)
{
 struct idt_descriptor idt_desc;
 asm volatile("sidt %0"
       :"=m"(idt_desc)
       :);
 return idt_desc;
}

canonical_original_code:
static inline struct idt_descriptor get_idt()
{
 struct idt_descriptor idt_desc;
 asm volatile("sidt %0"
       :"=m"(idt_desc)
       :);
 return idt_desc;
}

variable_types: struct idt_descriptor { unsigned short limit; unsigned long base; }


decompiled_code:
void local_irq_enable()
{
_enable();
}

canonical_decompiled_code:
void func3()
{
_enable();
}

original_code:
static inline void local_irq_enable(void)
{
 asm volatile ("sti"
        ::
        :"cc", "memory");
}

canonical_original_code:
static inline void local_irq_enable()
{
 asm volatile ("sti"
        ::
        :"cc", "memory");
}


decompiled_code:
__int64 __fastcall readl(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
return *a1;
}

original_code:
static inline uint32_t readl(const volatile void *addr) {
 return ({ uint32_t val; asm volatile ("mov %[addr], %[val];" : [val] "=r"(val) : [addr] "m"(*(const volatile uint32_t *)addr) : "memory"); val; });
}

variable_types:
val
unsigned int


decompiled_code:
__int64 __fastcall send_init_ipi(__int64 a1)
{
return apic_send_ipi(a1, 5LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return apic_send_ipi(a1, 5LL, 0LL);
}

original_code:
static inline void send_init_ipi(int apic_id)
{
 apic_send_ipi(apic_id, APIC_DELMOD_INIT, 0);
}


decompiled_code:
__int64 __fastcall start_secondary_cpu(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
int v3; // er14
__int64 v4; // rax
unsigned int v5; // er12
int v7; // er12

v2 = *(_DWORD *)(a1 + 8);
v3 = nr_alive_cpus;
*(_QWORD *)a1 = kmalloc(320);
v4 = kmalloc(4096);
*(_QWORD *)(a2 + 36) = a1;
*(_QWORD *)(a2 + 28) = v4 + 4096;
memcpy((void *)0xFFFF800000020000LL, (const void *)a2, 0x2CuLL);
send_init_ipi(v2);
if ( (unsigned __int8)apic_ipi_acked() )
{
v5 = 1;
pit_mdelay(10LL);
while ( 1 )
{
send_startup_ipi_constprop_0(v2);
if ( (unsigned __int8)apic_ipi_acked() )
break;
printk("SMP: Failed to deliver SIPI#%d to CPU#%d\n", v5, v2);
if ( v5 == 3 )
{
printk("SMP: Giving-up SIPI delivery\n");
goto LABEL_7;
}
++v5;
printk("SMP: Retrying SIPI delivery\n");
}
v7 = 1000;
do
{
if ( nr_alive_cpus != v3 )
return 0LL;
pit_mdelay(1LL);
--v7;
}
while ( v7 );
printk("SMP: Timeout waiting for CPU#%d to start\n", v2);
}
else
{
printk("SMP: Failed to deliver INIT to CPU#%d\n", v2);
}
LABEL_7:
kfree(*(_QWORD *)a1);
kfree(*(_QWORD *)(a2 + 28) - 4096LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
unsigned int v2; // er13
int v3; // er14
__int64 v4; // rax
unsigned int v5; // er12
int v7; // er12

v2 = *(_DWORD *)(a1 + 8);
v3 = nr_alive_cpus;
*(_QWORD *)a1 = func5(320);
v4 = func5(4096);
*(_QWORD *)(a2 + 36) = a1;
*(_QWORD *)(a2 + 28) = v4 + 4096;
memcpy((void *)0xFFFF800000020000LL, (const void *)a2, 0x2CuLL);
func6(v2);
if ( (unsigned __int8)apic_ipi_acked() )
{
v5 = 1;
pit_mdelay(10LL);
while ( 1 )
{
func7(v2);
if ( (unsigned __int8)apic_ipi_acked() )
break;
printk("SMP: Failed to deliver SIPI#%d to CPU#%d\n", v5, v2);
if ( v5 == 3 )
{
printk("SMP: Giving-up SIPI delivery\n");
goto LABEL_7;
}
++v5;
printk("SMP: Retrying SIPI delivery\n");
}
v7 = 1000;
do
{
if ( nr_alive_cpus != v3 )
return 0LL;
pit_mdelay(1LL);
--v7;
}
while ( v7 );
printk("SMP: Timeout waiting for CPU#%d to start\n", v2);
}
else
{
printk("SMP: Failed to deliver INIT to CPU#%d\n", v2);
}
LABEL_7:
kfree(*(_QWORD *)a1);
kfree(*(_QWORD *)(a2 + 28) - 4096LL);
return 1LL;
}

original_code:
static int start_secondary_cpu(struct percpu *cpu, struct smpboot_params *params)
{
 int count, acked, timeout, apic_id;
 asm volatile ("":::"memory");;
 count = nr_alive_cpus;
 apic_id = cpu->apic_id;
 cpu->__current = kmalloc(sizeof(struct proc));
 params->stack_ptr = kmalloc((1 << 12));
 params->stack_ptr += (1 << 12);
 params->percpu_area_ptr = cpu;
 memcpy(({ do { if (__builtin_expect((!((uintptr_t)(0x20000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x20000) >= KERN_PHYS_OFFSET" ")\n", "kern/smpboot.c", 155); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0x20000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x20000) < KERN_PHYS_END_MAX" ")\n", "kern/smpboot.c", 155); } while (0);; (void *)((char *)(0x20000) + 0xffff800000000000ULL); }), params, sizeof(*params));
 send_init_ipi(apic_id);
 acked = apic_ipi_acked();
 if (!acked) {
  printk("SMP: Failed to deliver INIT to CPU#%d\n", apic_id);
  goto fail;
 }
 pit_mdelay(10);
 for (int j = 1; j <= 3; j++) {
  send_startup_ipi(apic_id, 0x10000);
  acked = apic_ipi_acked();
  if (acked)
   break;
  printk("SMP: Failed to deliver SIPI#%d to CPU#%d\n",
         j, apic_id);
  if (j == 3) {
   printk("SMP: Giving-up SIPI delivery\n");
   goto fail;
  }
  printk("SMP: Retrying SIPI delivery\n");
 }
 timeout = 1000;
 while (timeout-- && count == nr_alive_cpus) {
  asm volatile ("":::"memory");;
  pit_mdelay(1);
 }
 if (timeout == -1) {
  printk("SMP: Timeout waiting for CPU#%d to start\n",
         apic_id);
  goto fail;
 }
 return 0;
fail:
 kfree(cpu->__current);
 kfree(params->stack_ptr - (1 << 12));
 return 1;
}

canonical_original_code:
static int start_secondary_cpu(struct percpu *cpu, struct smpboot_params *params)
{
 int count; int acked; int timeout; int apic_id;
 asm volatile ("":::"memory");;
 count = nr_alive_cpus;
 apic_id = cpu->apic_id;
 cpu->__current = kmalloc(sizeof(struct proc));
 params->stack_ptr = kmalloc((1 << 12));
 params->stack_ptr += (1 << 12);
 params->percpu_area_ptr = cpu;
 memcpy(({ do { if (__builtin_expect((!((unsigned long)(0x20000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x20000) >= KERN_PHYS_OFFSET" ")\n", "kern/smpboot.c", 155); } while (0);; do { if (__builtin_expect((!((unsigned long)(0x20000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x20000) < KERN_PHYS_END_MAX" ")\n", "kern/smpboot.c", 155); } while (0);; (void *)((char *)(0x20000) + 0xffff800000000000ULL); }), params, sizeof(*params));
 send_init_ipi(apic_id);
 acked = apic_ipi_acked();
 if (!acked) {
  printk("SMP: Failed to deliver INIT to CPU#%d\n", apic_id);
  goto fail;
 }
 pit_mdelay(10);
 for (int j = 1; j <= 3; j++) {
  send_startup_ipi(apic_id, 0x10000);
  acked = apic_ipi_acked();
  if (acked)
   break;
  printk("SMP: Failed to deliver SIPI#%d to CPU#%d\n",
         j, apic_id);
  if (j == 3) {
   printk("SMP: Giving-up SIPI delivery\n");
   goto fail;
  }
  printk("SMP: Retrying SIPI delivery\n");
 }
 timeout = 1000;
 while (timeout-- && count == nr_alive_cpus) {
  asm volatile ("":::"memory");;
  pit_mdelay(1);
 }
 if (timeout == -1) {
  printk("SMP: Timeout waiting for CPU#%d to start\n",
         apic_id);
  goto fail;
 }
 return 0;
fail:
 kfree(cpu->__current);
 kfree(params->stack_ptr - (1 << 12));
 return 1;
}

variable_types: struct percpu { struct proc { unsigned long pid; struct pcb { unsigned long rbp; unsigned long rbx; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rsp; } pcb; int state; struct list_node { struct list_node *next; struct list_node *prev; } pnode; unsigned long runtime; unsigned long enter_runqueue_ts; unsigned long working_dir; struct unrolled_head { struct __node { void **array; unsigned int array_len; unsigned int array_nrfree; unsigned int num; struct __node *next; } *node; unsigned int array_len; } fdtable; struct { unsigned long runtime_overall; unsigned int dispatch_count; unsigned long rqwait_overall; unsigned long prio_map[-1]; unsigned int preempt_high_prio; unsigned int preempt_slice_end; } stats; } *__current; int apic_id; unsigned long self; struct percpu_sched { unsigned long sys_ticks; struct runqueue { struct list_node head[-1]; } rrq[2]; struct runqueue *rq_active; struct runqueue *rq_expired; struct list_node just_queued; int current_prio; int just_queued_turn; } sched; unsigned long dumper; } *

variable_types: struct smpboot_params { unsigned long cr3; struct idt_descriptor { unsigned short limit; unsigned long base; } idtr; struct gdt_descriptor { unsigned short limit; unsigned long base; } gdtr; char *stack_ptr; void *percpu_area_ptr; } *

variable_types: count int

variable_types: acked int

variable_types: timeout int

variable_types: j int

user_defined_types: struct percpu { struct proc *__current; int apic_id; unsigned long self; struct percpu_sched sched; unsigned long dumper; }

user_defined_types: struct smpboot_params { unsigned long cr3; struct idt_descriptor idtr; struct gdt_descriptor gdtr; char *stack_ptr; void *percpu_area_ptr; }

user_defined_types: struct percpu_sched { unsigned long sys_ticks; struct runqueue rrq[2]; struct runqueue *rq_active; struct runqueue *rq_expired; struct list_node just_queued; int current_prio; int just_queued_turn; }


decompiled_code:
void smpboot_trigger_secondary_cores_testcases()
{
start_running_testcases = 1;
}

canonical_decompiled_code:
void func10()
{
start_running_testcases = 1;
}

original_code:
void smpboot_trigger_secondary_cores_testcases(void)
{
 start_running_testcases = ((_Bool)1);
}

canonical_original_code:
void smpboot_trigger_secondary_cores_testcases()
{
 start_running_testcases = ((_Bool)1);
}


decompiled_code:
__int64 smpboot_get_nr_alive_cpus()
{
return (unsigned int)nr_alive_cpus;
}

canonical_decompiled_code:
__int64 func12()
{
return (unsigned int)nr_alive_cpus;
}

original_code:
int smpboot_get_nr_alive_cpus(void)
{
 asm volatile ("":::"memory");;
 return nr_alive_cpus;
}

canonical_original_code:
int smpboot_get_nr_alive_cpus()
{
 asm volatile ("":::"memory");;
 return nr_alive_cpus;
}


decompiled_code:
__int64 smpboot_init()
{
__int64 v0; // rbp
__int64 v1; // r13
__int64 v2; // rax
char *v3; // r12
char *v4; // rbx
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-48h] BYREF
__int16 v7; // [rsp+8h] [rbp-40h]
__int64 v8; // [rsp+10h] [rbp-38h] BYREF
__int16 v9; // [rsp+18h] [rbp-30h]

v0 = kmalloc(44);
*(_QWORD *)v0 = get_cr3();
get_idt((__int64)&v8);
*(_QWORD *)(v0 + 8) = v8;
*(_WORD *)(v0 + 16) = v9;
get_gdt((__int64)&v6);
*(_QWORD *)(v0 + 18) = v6;
*(_WORD *)(v0 + 26) = v7;
v1 = (unsigned int)mptables_get_nr_cpus();
printk("SMP: %d usable CPU(s) found\n", v1);
memcpy((void *)0xFFFF800000010000LL, &trampoline, &trampoline_end - &trampoline);
v2 = 768LL * (int)v1;
if ( v2 != 768 )
{
v3 = (char *)&cpus + v2;
v4 = (char *)&cpus + 768;
while ( !(unsigned int)start_secondary_cpu((__int64)v4, v0) )
{
v4 += 768;
if ( v3 == v4 )
goto LABEL_5;
}
LABEL_7:
panic("SMP: Could not start-up all AP cores\n");
JUMPOUT(0x487LL);
}
LABEL_5:
result = kfree(v0);
if ( nr_alive_cpus != (_DWORD)v1 )
{
panic("%s:%d - !(nr_alive_cpus == nr_cpus)\n", "kern/smpboot.c", 293LL);
goto LABEL_7;
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rbp
__int64 v1; // r13
__int64 v2; // rax
char *v3; // r12
char *v4; // rbx
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-48h] BYREF
__int16 v7; // [rsp+8h] [rbp-40h]
__int64 v8; // [rsp+10h] [rbp-38h] BYREF
__int16 v9; // [rsp+18h] [rbp-30h]

v0 = func5(44);
*(_QWORD *)v0 = func1();
func2((__int64)&v8);
*(_QWORD *)(v0 + 8) = v8;
*(_WORD *)(v0 + 16) = v9;
func0((__int64)&v6);
*(_QWORD *)(v0 + 18) = v6;
*(_WORD *)(v0 + 26) = v7;
v1 = (unsigned int)mptables_get_nr_cpus();
printk("SMP: %d usable CPU(s) found\n", v1);
memcpy((void *)0xFFFF800000010000LL, &trampoline, &trampoline_end - &trampoline);
v2 = 768LL * (int)v1;
if ( v2 != 768 )
{
v3 = (char *)&cpus + v2;
v4 = (char *)&cpus + 768;
while ( !(unsigned int)func8((__int64)v4, v0) )
{
v4 += 768;
if ( v3 == v4 )
goto LABEL_5;
}
LABEL_7:
panic("SMP: Could not start-up all AP cores\n");
JUMPOUT(0x487LL);
}
LABEL_5:
result = kfree(v0);
if ( nr_alive_cpus != (_DWORD)v1 )
{
panic("%s:%d - !(nr_alive_cpus == nr_cpus)\n", "kern/smpboot.c", 293LL);
goto LABEL_7;
}
return result;
}

original_code:
void smpboot_init(void)
{
 int nr_cpus;
 struct smpboot_params *params;
 struct percpu *cpu;
 smpboot_params_validate_offsets();
 params = kmalloc(sizeof(*params));
 params->cr3 = get_cr3();
 params->idtr = get_idt();
 params->gdtr = get_gdt();
 nr_cpus = mptables_get_nr_cpus();
 printk("SMP: %d usable CPU(s) found\n", nr_cpus);
 memcpy(({ do { if (__builtin_expect((!((uintptr_t)(0x10000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x10000) >= KERN_PHYS_OFFSET" ")\n", "kern/smpboot.c", 283); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0x10000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x10000) < KERN_PHYS_END_MAX" ")\n", "kern/smpboot.c", 283); } while (0);; (void *)((char *)(0x10000) + 0xffff800000000000ULL); }), trampoline, trampoline_end - trampoline);
 for (cpu = &cpus[1]; cpu != &cpus[mptables_get_nr_cpus()]; cpu++) {
  if (start_secondary_cpu(cpu, params))
   panic("SMP: Could not start-up all AP cores\n");
 }
 kfree(params);
 asm volatile ("":::"memory");;
 do { if (__builtin_expect((!(nr_alive_cpus == nr_cpus)), 0)) panic("%s:%d - !(" "nr_alive_cpus == nr_cpus" ")\n", "kern/smpboot.c", 293); } while (0);;
}

canonical_original_code:
void smpboot_init()
{
 int nr_cpus;
 struct smpboot_params *params;
 struct percpu *cpu;
 smpboot_params_validate_offsets();
 params = kmalloc(sizeof(*params));
 params->cr3 = get_cr3();
 params->idtr = get_idt();
 params->gdtr = get_gdt();
 nr_cpus = mptables_get_nr_cpus();
 printk("SMP: %d usable CPU(s) found\n", nr_cpus);
 memcpy(({ do { if (__builtin_expect((!((unsigned long)(0x10000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x10000) >= KERN_PHYS_OFFSET" ")\n", "kern/smpboot.c", 283); } while (0);; do { if (__builtin_expect((!((unsigned long)(0x10000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x10000) < KERN_PHYS_END_MAX" ")\n", "kern/smpboot.c", 283); } while (0);; (void *)((char *)(0x10000) + 0xffff800000000000ULL); }), trampoline, trampoline_end - trampoline);
 for (cpu = &cpus[1]; cpu != &cpus[mptables_get_nr_cpus()]; cpu++) {
  if (start_secondary_cpu(cpu, params))
   panic("SMP: Could not start-up all AP cores\n");
 }
 kfree(params);
 asm volatile ("":::"memory");;
 do { if (__builtin_expect((!(nr_alive_cpus == nr_cpus)), 0)) panic("%s:%d - !(" "nr_alive_cpus == nr_cpus" ")\n", "kern/smpboot.c", 293); } while (0);;
}

user_defined_types: struct idt_descriptor { unsigned short limit; unsigned long base; }

user_defined_types: struct gdt_descriptor { unsigned short limit; unsigned long base; }

user_defined_types: struct proc { unsigned long pid; struct pcb pcb; int state; struct list_node pnode; unsigned long runtime; unsigned long enter_runqueue_ts; unsigned long working_dir; struct unrolled_head fdtable; struct { unsigned long runtime_overall; unsigned int dispatch_count; unsigned long rqwait_overall; unsigned long prio_map[-1]; unsigned int preempt_high_prio; unsigned int preempt_slice_end; } stats; }

user_defined_types: struct unrolled_head { struct __node *node; unsigned int array_len; }

user_defined_types: struct runqueue { struct list_node head[-1]; }


decompiled_code:
unsigned __int64 get_rflags()
{
return __getcallerseflags();
}

canonical_decompiled_code:
unsigned __int64 func0()
{
return __getcallerseflags();
}

original_code:
static inline union x86_rflags get_rflags(void)
{
 union x86_rflags flags;
 asm volatile ("pushfq;"
        "popq %0;"
        :"=rm"(flags.raw)
        :);
 return flags;
}

canonical_original_code:
static inline union x86_rflags get_rflags()
{
 union x86_rflags flags;
 asm volatile ("pushfq;"
        "popq %0;"
        :"=rm"(flags.raw)
        :);
 return flags;
}

variable_types: union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; }


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

__writeeflags(v0);
}

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

__writeeflags(v0);
}

original_code:
static inline void set_rflags(union x86_rflags flags)
{
 asm volatile ("pushq %0;"
        "popfq;"
        :
        :"g"(flags.raw)
        :"cc", "memory");
}

user_defined_types: union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; }


decompiled_code:
void local_irq_disable()
{
_disable();
}

canonical_decompiled_code:
void func2()
{
_disable();
}

original_code:
static inline void local_irq_disable(void)
{
 asm volatile ("cli"
        ::
        :"cc", "memory");
}

canonical_original_code:
static inline void local_irq_disable()
{
 asm volatile ("cli"
        ::
        :"cc", "memory");
}


decompiled_code:
void local_irq_disable_save()
{
if ( (get_rflags() & 0x200) != 0 )
local_irq_disable();
}

original_code:
static inline union x86_rflags local_irq_disable_save(void)
{
 union x86_rflags flags;
 flags = get_rflags();
 if (flags.irqs_enabled)
  local_irq_disable();
 return flags;
}

canonical_original_code:
static inline union x86_rflags local_irq_disable_save()
{
 union x86_rflags flags;
 flags = get_rflags();
 if (flags.irqs_enabled)
  local_irq_disable();
 return flags;
}

return_type: union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; }


decompiled_code:
void __fastcall local_irq_restore(__int16 a1)
{
if ( (a1 & 0x200) != 0 )
set_rflags();
}

original_code:
static inline void local_irq_restore(union x86_rflags flags)
{
 if (flags.irqs_enabled)
  set_rflags(flags);
}


decompiled_code:
__int64 __fastcall spin_lock(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 result; // rax

local_irq_disable_save();
v2 = v1;
for ( result = ((__int64 (*)(void))atomic_bit_test_and_set)(); (_BYTE)result == 1; result = atomic_bit_test_and_set(a1) )
{
local_irq_restore(v2);
while ( *(_DWORD *)a1 == 1 )
_mm_pause();
local_irq_disable();
}
*(_QWORD *)(a1 + 8) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 result; // rax

func3();
v2 = v1;
for ( result = ((__int64 (*)(void))atomic_bit_test_and_set)(); (_BYTE)result == 1; result = atomic_bit_test_and_set(a1) )
{
func4(v2);
while ( *(_DWORD *)a1 == 1 )
_mm_pause();
func2();
}
*(_QWORD *)(a1 + 8) = v2;
return result;
}

original_code:
void spin_lock(struct lock_spin *lock)
{
 union x86_rflags rflags;
 rflags = local_irq_disable_save();
 while (atomic_bit_test_and_set(&lock->val) == 1) {
  local_irq_restore(rflags);
  while (lock->val == 1)
   asm volatile ("pause":::"memory");;
  local_irq_disable();
 }
 lock->rflags = rflags;
}

variable_types: struct lock_spin { unsigned int val; union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; } rflags; } *

user_defined_types: struct lock_spin { unsigned int val; union x86_rflags rflags; }


decompiled_code:
void __fastcall spin_trylock(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

local_irq_disable_save();
v2 = v1;
if ( (unsigned __int8)atomic_bit_test_and_set(a1) == 1 )
local_irq_restore(v2);
else
*(_QWORD *)(a1 + 8) = v2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp

func3();
v2 = v1;
if ( (unsigned __int8)atomic_bit_test_and_set(a1) == 1 )
func4(v2);
else
*(_QWORD *)(a1 + 8) = v2;
}

original_code:
_Bool spin_trylock(struct lock_spin *lock)
{
 union x86_rflags rflags;
 rflags = local_irq_disable_save();
 if (atomic_bit_test_and_set(&lock->val) == 1) {
  local_irq_restore(rflags);
  return ((_Bool)0);
 }
 lock->rflags = rflags;
 return ((_Bool)1);
}


decompiled_code:
void __fastcall spin_unlock(__int64 a1)
{
__int64 v1; // r8

v1 = *(_QWORD *)(a1 + 8);
*(_DWORD *)a1 = 0;
local_irq_restore(v1);
}

original_code:
void spin_unlock(struct lock_spin *lock)
{
 union x86_rflags rflags;
 rflags = lock->rflags;
 asm volatile ("":::"memory");;
 lock->val = 0;
 local_irq_restore(rflags);
}


decompiled_code:
signed __int8 __fastcall atomic_bit_test_and_set(volatile signed __int32 *a1)
{
return _interlockedbittestandset(a1, 0);
}

canonical_decompiled_code:
signed __int8 __fastcall func0(volatile signed __int32 *a1)
{
return _interlockedbittestandset(a1, 0);
}

original_code:
uint8_t atomic_bit_test_and_set(uint32_t *val)
{
 uint8_t ret;
 asm volatile (
  "LOCK bts $0, %0;"
  "     setc    %1;"
  : "+m" (*val), "=qm" (ret)
  :
  : "cc", "memory");
 return ret;
}

canonical_original_code:
unsigned char atomic_bit_test_and_set(unsigned int *val)
{
 unsigned char ret;
 asm volatile (
  "LOCK bts $0, %0;"
  "     setc    %1;"
  : "+m" (*val), "=qm" (ret)
  :
  : "cc", "memory");
 return ret;
}

variable_types:
val
unsigned int *

variable_types:
ret
unsigned char


decompiled_code:
signed __int64 __fastcall atomic_inc(volatile signed __int64 *a1)
{
return _InterlockedExchangeAdd64(a1, 1uLL);
}

canonical_decompiled_code:
signed __int64 __fastcall func1(volatile signed __int64 *a1)
{
return _InterlockedExchangeAdd64(a1, 1uLL);
}

original_code:
uint64_t atomic_inc(uint64_t *val)
{
 uint64_t i = 1;
 asm volatile (
  "LOCK xaddq %0, %1"
  : "+r"(i), "+m" (*val)
  :
  : "cc");
 return i;
}

canonical_original_code:
unsigned long atomic_inc(unsigned long *val)
{
 unsigned long i = 1;
 asm volatile (
  "LOCK xaddq %0, %1"
  : "+r"(i), "+m" (*val)
  :
  : "cc");
 return i;
}

variable_types:
val
unsigned long *

variable_types:
i
unsigned long


outb

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

result = a1;
__outbyte(a2, a1);
return result;
}

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

result = a1;
__outbyte(a2, a1);
return result;
}

original_code:
static inline void outb(uint8_t val, uint16_t port)
{
 asm volatile (
  "outb %[val], %[port]"
  :
  : [val] "a" (val), [port] "Nd" (port));
}

canonical_original_code:
static inline void outb(unsigned char val, unsigned short port)
{
 asm volatile (
  "outb %[val], %[port]"
  :
  : [val] "a" (val), [port] "Nd" (port));
}

variable_types:
val
unsigned char

variable_types:
port
unsigned short


decompiled_code:
__int64 __fastcall io_delay()
{
__int64 result; // rax

__outbyte(0xEDu, result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1()
{
__int64 result; // rax

__outbyte(0xEDu, result);
return result;
}

original_code:
static inline void io_delay(void)
{
 asm volatile ("outb %al, $0xed");
}

canonical_original_code:
static inline void io_delay()
{
 asm volatile ("outb %al, $0xed");
}


decompiled_code:
__int64 __fastcall outb_pic(unsigned __int8 a1, unsigned __int16 a2)
{
outb(a1, a2);
return io_delay();
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, unsigned __int16 a2)
{
func0(a1, a2);
return func1();
}

original_code:
static inline void outb_pic(uint8_t val, uint16_t port)
{
 outb(val, port);
 io_delay();
}

canonical_original_code:
static inline void outb_pic(unsigned char val, unsigned short port)
{
 outb(val, port);
 io_delay();
}


decompiled_code:
__int64 i8259_mask()
{
outb_pic(0xFFu, 0x21u);
return outb_pic(0xFFu, 0xA1u);
}

canonical_decompiled_code:
__int64 func3()
{
func2(0xFFu, 0x21u);
return func2(0xFFu, 0xA1u);
}

original_code:
static inline void i8259_mask(void)
{
 outb_pic(0xff, 0x21);
 outb_pic(0xff, 0xa1);
}

canonical_original_code:
static inline void i8259_mask()
{
 outb_pic(0xff, 0x21);
 outb_pic(0xff, 0xa1);
}


decompiled_code:
__int64 pic_init()
{
unsigned int v0; // ecx
__int64 result; // rax

outb_pic(0x11u, 0x20u);
outb_pic(0x11u, 0xA0u);
outb_pic(0x20u, 0x21u);
outb_pic(0x28u, 0xA1u);
outb_pic(4u, 0x21u);
outb_pic(2u, 0xA1u);
outb_pic(3u, 0x21u);
outb_pic(3u, 0xA1u);
i8259_mask();
do
set_intr_gate_constprop_0(v0);
while ( v0 != 40 );
do
result = set_intr_gate_constprop_0(v0);
while ( v0 != 48 );
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // ecx
__int64 result; // rax

func2(0x11u, 0x20u);
func2(0x11u, 0xA0u);
func2(0x20u, 0x21u);
func2(0x28u, 0xA1u);
func2(4u, 0x21u);
func2(2u, 0xA1u);
func2(3u, 0x21u);
func2(3u, 0xA1u);
func3();
do
func6(v0);
while ( v0 != 40 );
do
result = func6(v0);
while ( v0 != 48 );
return result;
}

original_code:
void pic_init(void)
{
 outb_pic(0x11, 0x20);
 outb_pic(0x11, 0xa0);
 outb_pic(0x20, 0x21);
 outb_pic(0x28, 0xa1);
 outb_pic(1 << 2, 0x21);
 outb_pic(2, 0xa1);
 outb_pic(0x3, 0x21);
 outb_pic(0x3, 0xa1);
 i8259_mask();
 for (int i = 0x20; i <= (0x20 + 7); i++)
  set_intr_gate(i, PIC_handler);
 for (int i = 0x28; i <= (0x28 + 7); i++)
  set_intr_gate(i, PIC_handler);
}

canonical_original_code:
void pic_init()
{
 outb_pic(0x11, 0x20);
 outb_pic(0x11, 0xa0);
 outb_pic(0x20, 0x21);
 outb_pic(0x28, 0xa1);
 outb_pic(1 << 2, 0x21);
 outb_pic(2, 0xa1);
 outb_pic(0x3, 0x21);
 outb_pic(0x3, 0xa1);
 i8259_mask();
 for (int i = 0x20; i <= (0x20 + 7); i++)
  set_intr_gate(i, PIC_handler);
 for (int i = 0x28; i <= (0x28 + 7); i++)
  set_intr_gate(i, PIC_handler);
}

variable_types: i int


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

result = "unknown e820.S-reported error";
if ( a1 <= 5 )
result = e820_errors[a1];
return result;
}

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

result = "unknown e820.S-reported error";
if ( a1 <= 5 )
result = e820_errors[a1];
return result;
}

original_code:
static inline const char *e820_errstr(uint32_t error)
{
 if (error > 0x5)
  return "unknown e820.S-reported error";
 do { if (__builtin_expect((!(error < ({ do { if (!((sizeof(e820_errors) / sizeof((e820_errors)[0])) <= (uint64_t)(0x7fffffff))) __undefined_method(); } while (0);; (int32_t)(sizeof(e820_errors) / sizeof((e820_errors)[0])); }))), 0)) panic("%s:%d - !(" "error < ARRAY_SIZE(e820_errors)" ")\n", "include/e820.h", 113); } while (0);;
 return e820_errors[error];
}

canonical_original_code:
static inline char *e820_errstr(unsigned int error)
{
 if (error > 0x5)
  return "unknown e820.S-reported error";
 do { if (__builtin_expect((!(error < ({ do { if (!((sizeof(e820_errors) / sizeof((e820_errors)[0])) <= (unsigned long)(0x7fffffff))) __undefined_method(); } while (0);; (int)(sizeof(e820_errors) / sizeof((e820_errors)[0])); }))), 0)) panic("%s:%d - !(" "error < ARRAY_SIZE(e820_errors)" ")\n", "include/e820.h", 113); } while (0);;
 return e820_errors[error];
}

variable_types:
error
unsigned int

return_type: char *


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

result = "unknown type - reserved";
if ( (unsigned int)(a1 - 1) <= 5 )
result = (const char *)e820_types[a1];
return result;
}

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

result = "unknown type - reserved";
if ( (unsigned int)(a1 - 1) <= 5 )
result = (const char *)e820_types[a1];
return result;
}

original_code:
static inline const char *e820_typestr(uint32_t type)
{
 if (type < E820_AVAIL || type > E820_DISABLED)
  return "unknown type - reserved";
 do { if (__builtin_expect((!(type < ({ do { if (!((sizeof(e820_types) / sizeof((e820_types)[0])) <= (uint64_t)(0x7fffffff))) __undefined_method(); } while (0);; (int32_t)(sizeof(e820_types) / sizeof((e820_types)[0])); }))), 0)) panic("%s:%d - !(" "type < ARRAY_SIZE(e820_types)" ")\n", "include/e820.h", 182); } while (0);;
 return e820_types[type];
}

canonical_original_code:
static inline char *e820_typestr(unsigned int type)
{
 if (type < E820_AVAIL || type > E820_DISABLED)
  return "unknown type - reserved";
 do { if (__builtin_expect((!(type < ({ do { if (!((sizeof(e820_types) / sizeof((e820_types)[0])) <= (unsigned long)(0x7fffffff))) __undefined_method(); } while (0);; (int)(sizeof(e820_types) / sizeof((e820_types)[0])); }))), 0)) panic("%s:%d - !(" "type < ARRAY_SIZE(e820_types)" ")\n", "include/e820.h", 182); } while (0);;
 return e820_types[type];
}

variable_types:
type
unsigned int