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

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

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


repo: acceso/jOS

decompiled_code:
void exc_generic_handler()
{
kprintf("Exception!\n");
__asm { iretq }
}

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

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

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

return_type: void


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

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

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

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

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

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


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

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

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


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

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

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


decompiled_code:
void exc_5_bound()
{
kprintf("Bound!\n");
__asm { iretq }
}

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

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


decompiled_code:
void exc_4_overflow()
{
kprintf("Overflow!\n");
__asm { iretq }
}

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

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


decompiled_code:
void exc_3_breakpoint()
{
kprintf("Breakpoint!\n");
__asm { iretq }
}

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

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


decompiled_code:
void exc_2_nmi()
{
kprintf("NMI!\n");
__asm { iretq }
}

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

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


decompiled_code:
void exc_1_debug()
{
kprintf("Debug!\n");
__asm { iretq }
}

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

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


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

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

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


decompiled_code:
__int64 lapic_eoi()
{
return lapic_write_constprop_0();
}

canonical_decompiled_code:
__int64 func23()
{
return func22();
}

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

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


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

canonical_decompiled_code:
void func24()
{
func23();
__asm { iretq }
}

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


decompiled_code:
__int64 init_exceptions()
{
void (__fastcall *v0)(unsigned __int8, __int64); // rcx
void (__fastcall *v1)(unsigned __int8, __int64); // rcx
void (__fastcall *v2)(unsigned __int8, __int64); // rcx
void (__fastcall *v3)(unsigned __int8, __int64); // rcx
void (__fastcall *v4)(unsigned __int8, __int64); // rcx
void (__fastcall *v5)(unsigned __int8, __int64); // rcx
void (__fastcall *v6)(unsigned __int8, __int64); // rcx
void (__fastcall *v7)(unsigned __int8, __int64); // rcx
void (__fastcall *v8)(unsigned __int8, __int64); // rcx
void (__fastcall *v9)(unsigned __int8, __int64); // rcx
void (__fastcall *v10)(unsigned __int8, __int64); // rcx
void (__fastcall *v11)(unsigned __int8, __int64); // rcx
void (__fastcall *v12)(unsigned __int8, __int64); // rcx
void (__fastcall *v13)(unsigned __int8, __int64); // rcx
void (__fastcall *v14)(unsigned __int8, __int64); // rcx
void (__fastcall *v15)(unsigned __int8, __int64); // rcx
void (__fastcall *v16)(unsigned __int8, __int64); // rcx
void (__fastcall *v17)(unsigned __int8, __int64); // rcx
void (__fastcall *v18)(unsigned __int8, __int64); // rcx
int v19; // edx
void (__fastcall *v20)(unsigned __int8, __int64); // rcx
__int64 v21; // r8
void (__fastcall *v22)(unsigned __int8, __int64); // rcx
int v23; // edx
void (__fastcall *v24)(unsigned __int8, __int64); // rcx
__int64 v25; // r8

idt_set_gate_constprop_0(0, (__int64)exc_0_divideby0);
v0(1u, (__int64)exc_1_debug);
v1(2u, (__int64)exc_2_nmi);
v2(3u, (__int64)exc_3_breakpoint);
v3(4u, (__int64)exc_4_overflow);
v4(5u, (__int64)exc_5_bound);
v5(6u, (__int64)exc_6_iopcode);
v6(7u, (__int64)exc_7_nomathco);
v7(8u, (__int64)exc_8_doublefault);
v8(9u, (__int64)exc_generic_handler);
v9(0xAu, (__int64)exc_10_tss_inval);
v10(0xCu, (__int64)exc_11_nosuchsegment);
v11(0xDu, (__int64)exc_12_stack);
v12(0xEu, (__int64)exc_13_gp);
v13(0xFu, (__int64)exc_14_pf);
v14(0x10u, (__int64)exc_generic_handler);
v15(0x11u, (__int64)exc_16_math_pending);
v16(0x12u, (__int64)exc_17_misalignment);
v17(0x13u, (__int64)exc_18_machinecheck);
v18(0xAu, (__int64)exc_19_simd);
do
v20(v19, v21);
while ( v19 != 30 );
v20(0x1Eu, (__int64)exc_30_security);
v22(0x1Fu, (__int64)exc_generic_handler);
do
v24(v23, v25);
while ( v23 != 255 );
return set_idt_reg_constprop_0();
}

canonical_decompiled_code:
__int64 func26()
{
void (__fastcall *v0)(unsigned __int8, __int64); // rcx
void (__fastcall *v1)(unsigned __int8, __int64); // rcx
void (__fastcall *v2)(unsigned __int8, __int64); // rcx
void (__fastcall *v3)(unsigned __int8, __int64); // rcx
void (__fastcall *v4)(unsigned __int8, __int64); // rcx
void (__fastcall *v5)(unsigned __int8, __int64); // rcx
void (__fastcall *v6)(unsigned __int8, __int64); // rcx
void (__fastcall *v7)(unsigned __int8, __int64); // rcx
void (__fastcall *v8)(unsigned __int8, __int64); // rcx
void (__fastcall *v9)(unsigned __int8, __int64); // rcx
void (__fastcall *v10)(unsigned __int8, __int64); // rcx
void (__fastcall *v11)(unsigned __int8, __int64); // rcx
void (__fastcall *v12)(unsigned __int8, __int64); // rcx
void (__fastcall *v13)(unsigned __int8, __int64); // rcx
void (__fastcall *v14)(unsigned __int8, __int64); // rcx
void (__fastcall *v15)(unsigned __int8, __int64); // rcx
void (__fastcall *v16)(unsigned __int8, __int64); // rcx
void (__fastcall *v17)(unsigned __int8, __int64); // rcx
void (__fastcall *v18)(unsigned __int8, __int64); // rcx
int v19; // edx
void (__fastcall *v20)(unsigned __int8, __int64); // rcx
__int64 v21; // r8
void (__fastcall *v22)(unsigned __int8, __int64); // rcx
int v23; // edx
void (__fastcall *v24)(unsigned __int8, __int64); // rcx
__int64 v25; // r8

func20(0, (__int64)exc_0_divideby0);
v0(1u, (__int64)exc_1_debug);
v1(2u, (__int64)exc_2_nmi);
v2(3u, (__int64)exc_3_breakpoint);
v3(4u, (__int64)exc_4_overflow);
v4(5u, (__int64)exc_5_bound);
v5(6u, (__int64)exc_6_iopcode);
v6(7u, (__int64)exc_7_nomathco);
v7(8u, (__int64)exc_8_doublefault);
v8(9u, (__int64)exc_generic_handler);
v9(0xAu, (__int64)exc_10_tss_inval);
v10(0xCu, (__int64)exc_11_nosuchsegment);
v11(0xDu, (__int64)exc_12_stack);
v12(0xEu, (__int64)exc_13_gp);
v13(0xFu, (__int64)exc_14_pf);
v14(0x10u, (__int64)exc_generic_handler);
v15(0x11u, (__int64)exc_16_math_pending);
v16(0x12u, (__int64)exc_17_misalignment);
v17(0x13u, (__int64)exc_18_machinecheck);
v18(0xAu, (__int64)exc_19_simd);
do
v20(v19, v21);
while ( v19 != 30 );
v20(0x1Eu, (__int64)exc_30_security);
v22(0x1Fu, (__int64)exc_generic_handler);
do
v24(v23, v25);
while ( v23 != 255 );
return func21();
}

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

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

variable_types:
n
unsigned char


iowait

decompiled_code:
void iowait()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

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

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


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

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

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

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

variable_types:
reg
unsigned int

return_type: unsigned int


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

canonical_decompiled_code:
__int64 func3()
{
return func2(0xB0u, 0);
}


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

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

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

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

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

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

variable_types:
reg
unsigned char


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

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

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

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


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

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

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

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

return_type: unsigned char


decompiled_code:
__int64 __fastcall ioapic_redir_read(unsigned __int8 a1)
{
char v1; // al
unsigned __int8 v2; // dl
unsigned int v3; // eax
__int64 v4; // rcx

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

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 a1)
{
char v1; // al
unsigned __int8 v2; // dl
unsigned int v3; // eax
__int64 v4; // rcx

v1 = func6(*((unsigned __int8 *)&ioapic + 3 * a1 + 10));
func5(v1 + 1);
v3 = func5(v2);
return (v4 << 32) | v3;
}

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

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

variable_types:
v
unsigned long

return_type: unsigned long


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

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

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


decompiled_code:
void do_spurious()
{
kprintf("Spurious int!\n");
lapic_eoi();
__asm { iretq }
}

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

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


decompiled_code:
__int64 pic_disable()
{
__int64 (__fastcall *v0)(__int64); // rcx

outb_constprop_0(0xA1u);
return v0(33LL);
}

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

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


decompiled_code:
__int64 lapic_init()
{
int v0; // edi
__int64 (__fastcall *v1)(unsigned int); // rdx

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

canonical_decompiled_code:
__int64 func13()
{
int v0; // edi
__int64 (__fastcall *v1)(unsigned int); // rdx

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

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

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


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

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

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

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

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

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

variable_types:
val
unsigned int


decompiled_code:
__int64 __fastcall ioapic_redir_write(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edi
unsigned __int8 v4; // al
__int64 v5; // rdx
void (__fastcall *v6)(_QWORD, __int64, __int64, _QWORD); // r8
char v7; // cl
__int64 v8; // rdx
__int64 (__fastcall *v9)(_QWORD, __int64); // r8

result = 3LL * a1;
v3 = *((unsigned __int8 *)&ioapic + result + 10);
if ( (unsigned __int8)v3 <= 0x10u )
{
v4 = ioapic_redir_nint_to_reg(v3);
v6(v4, a2, v5, v4);
result = v9((unsigned __int8)(v7 + 1), v8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned __int8 a1, __int64 a2)
{
__int64 result; // rax
int v3; // edi
unsigned __int8 v4; // al
__int64 v5; // rdx
void (__fastcall *v6)(_QWORD, __int64, __int64, _QWORD); // r8
char v7; // cl
__int64 v8; // rdx
__int64 (__fastcall *v9)(_QWORD, __int64); // r8

result = 3LL * a1;
v3 = *((unsigned __int8 *)&ioapic + result + 10);
if ( (unsigned __int8)v3 <= 0x10u )
{
v4 = func6(v3);
v6(v4, a2, v5, v4);
result = v9((unsigned __int8)(v7 + 1), v8);
}
return result;
}

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

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

variable_types:
val
unsigned long


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

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


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

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

variable_types:
i
unsigned char


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

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

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

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

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

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


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

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

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

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


decompiled_code:
char *file_get()
{
_WORD *v0; // rax
int v1; // edx
__int64 v2; // rbx
char *result; // rax
char *v4; // rdx

v0 = &unk_A8;
v1 = 0;
while ( 1 )
{
v2 = v1;
if ( !*v0 )
break;
++v1;
v0 += 12;
if ( (_DWORD)v2 == 127 )
{
v2 = 128LL;
break;
}
}
result = (char *)namei();
v4 = (char *)&file_table + 24 * v2;
*(_QWORD *)v4 = result;
if ( result )
{
*((_WORD *)v4 + 4) = 1;
result = (char *)&file_table + 24 * v2;
}
return result;
}

canonical_decompiled_code:
char *func0()
{
_WORD *v0; // rax
int v1; // edx
__int64 v2; // rbx
char *result; // rax
char *v4; // rdx

v0 = &unk_A8;
v1 = 0;
while ( 1 )
{
v2 = v1;
if ( !*v0 )
break;
++v1;
v0 += 12;
if ( (_DWORD)v2 == 127 )
{
v2 = 128LL;
break;
}
}
result = (char *)namei();
v4 = (char *)&file_table + 24 * v2;
*(_QWORD *)v4 = result;
if ( result )
{
*((_WORD *)v4 + 4) = 1;
result = (char *)&file_table + 24 * v2;
}
return result;
}

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

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

variable_types:
path
char *

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

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

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

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

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


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

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

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

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

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

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


lseek

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

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

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

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

variable_types: fd int

variable_types: offset long

variable_types:
origin
unsigned char

return_type: long


read

original_code:
size_t read(s32 fd, void *buf, size_t count)
{
 struct inode *inode;
 struct bhead *block;
 size_t rbytes;
 off_t offset;
 u16 len;
 if (current->fds[fd]->pos > current->fds[fd]->inode->filesize)
  return 0;
 inode = current->fds[fd]->inode;
 rbytes = current->fds[fd]->pos;
 while (count) {
  block = inode->ops->block_read(inode, current->fds[fd]->pos);
  if (block == ((void *)0))
   break;
  offset = current->fds[fd]->pos % inode->sb->blocksize;
  len = ((inode->sb->blocksize - offset) < (count) ? (inode->sb->blocksize - offset) : (count));
  memcpy(buf, block->data + offset, len);
  current->fds[fd]->pos += len;
  count -= len;
  buf += len;
 }
 return current->fds[fd]->pos - rbytes;
}

canonical_original_code:
unsigned long read(int fd, void *buf, unsigned long count)
{
 struct inode *inode;
 struct bhead *block;
 unsigned long rbytes;
 long offset;
 unsigned short len;
 if (current->fds[fd]->pos > current->fds[fd]->inode->filesize)
  return 0;
 inode = current->fds[fd]->inode;
 rbytes = current->fds[fd]->pos;
 while (count) {
  block = inode->ops->block_read(inode, current->fds[fd]->pos);
  if (block == ((void *)0))
   break;
  offset = current->fds[fd]->pos % inode->sb->blocksize;
  len = ((inode->sb->blocksize - offset) < (count) ? (inode->sb->blocksize - offset) : (count));
  memcpy(buf, block->data + offset, len);
  current->fds[fd]->pos += len;
  count -= len;
  buf += len;
 }
 return current->fds[fd]->pos - rbytes;
}

variable_types:
buf
void *

variable_types:
count
unsigned long

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

variable_types: struct bhead { struct list_head { struct list_head *prev; } l; unsigned long bnum; void *data; unsigned char count; } *

variable_types:
rbytes
unsigned long

variable_types:
len
unsigned short


open

decompiled_code:
__int64 __fastcall open(__int64 a1, __int16 a2, __int16 a3)
{
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // rax

v4 = 0LL;
v5 = current;
while ( *(_QWORD *)(current + 8 * v4 + 8) )
{
if ( ++v4 == 32 )
return 0xFFFFFFFFLL;
}
if ( (_DWORD)v4 != 31 )
{
*(_QWORD *)(v5 + 8LL * (unsigned int)v4 + 8) = file_get();
v6 = *(_QWORD *)(current + 8LL * (unsigned int)v4 + 8);
if ( v6 )
{
*(_WORD *)(v6 + 10) = a3;
*(_WORD *)(v6 + 12) = a2;
*(_QWORD *)(v6 + 16) = 0LL;
return (unsigned int)v4;
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int16 a2, __int16 a3)
{
__int64 v4; // rbx
__int64 v5; // r12
__int64 v6; // rax

v4 = 0LL;
v5 = current;
while ( *(_QWORD *)(current + 8 * v4 + 8) )
{
if ( ++v4 == 32 )
return 0xFFFFFFFFLL;
}
if ( (_DWORD)v4 != 31 )
{
*(_QWORD *)(v5 + 8LL * (unsigned int)v4 + 8) = file_get();
v6 = *(_QWORD *)(current + 8LL * (unsigned int)v4 + 8);
if ( v6 )
{
*(_WORD *)(v6 + 10) = a3;
*(_WORD *)(v6 + 12) = a2;
*(_QWORD *)(v6 + 16) = 0LL;
return (unsigned int)v4;
}
}
return 0xFFFFFFFFLL;
}

original_code:
s8 open(const char *path, u16 flags, u16 mode)
{
 u32 fd;
 for (fd = 0; fd < 32; fd++)
  if (current->fds[fd] == ((void *)0))
   break;
 if (fd >= 32 - 1)
  return -1;
 current->fds[fd] = file_get(path);
 if (current->fds[fd] == ((void *)0))
  return -1;
 current->fds[fd]->mode = mode;
 current->fds[fd]->flags = flags;
 current->fds[fd]->pos = 0;
 return fd;
}

canonical_original_code:
char open(char *path, unsigned short flags, unsigned short mode)
{
 unsigned int fd;
 for (fd = 0; fd < 32; fd++)
  if (current->fds[fd] == ((void *)0))
   break;
 if (fd >= 32 - 1)
  return -1;
 current->fds[fd] = file_get(path);
 if (current->fds[fd] == ((void *)0))
  return -1;
 current->fds[fd]->mode = mode;
 current->fds[fd]->flags = flags;
 current->fds[fd]->pos = 0;
 return fd;
}

variable_types:
flags
unsigned short

variable_types:
mode
unsigned short

variable_types:
fd
unsigned int

return_type: char


bitset

decompiled_code:
void __fastcall bitset(signed __int64 *a1, unsigned __int64 a2)
{
_bittestandset64(a1, a2);
}

canonical_decompiled_code:
void __fastcall func0(signed __int64 *a1, unsigned __int64 a2)
{
_bittestandset64(a1, a2);
}

original_code:
inline static void bitset(u64 *word, u64 pos)
{
 asm volatile(
  "bts %[bit], %[reg]\n"
  : [reg] "+m"(*word)
  : [bit] "ir" (pos)
  : "cc" );
}

canonical_original_code:
inline static void bitset(unsigned long *word, unsigned long pos)
{
 asm volatile(
  "bts %[bit], %[reg]\n"
  : [reg] "+m"(*word)
  : [bit] "ir" (pos)
  : "cc" );
}

variable_types:
word
unsigned long *

variable_types:
pos
unsigned long


bitclear

decompiled_code:
void __fastcall bitclear(signed __int64 *a1, unsigned __int64 a2)
{
_bittestandreset64(a1, a2);
}

canonical_decompiled_code:
void __fastcall func1(signed __int64 *a1, unsigned __int64 a2)
{
_bittestandreset64(a1, a2);
}

original_code:
inline static void bitclear(u64 *word, u64 pos)
{
 asm volatile(
  "btr %[bit], %[reg]\n"
  : [reg] "+m"(*word)
  : [bit] "ir" (pos)
  : "cc" );
}

canonical_original_code:
inline static void bitclear(unsigned long *word, unsigned long pos)
{
 asm volatile(
  "btr %[bit], %[reg]\n"
  : [reg] "+m"(*word)
  : [bit] "ir" (pos)
  : "cc" );
}


decompiled_code:
__int64 __fastcall pfn_to_addr(__int64 a1)
{
return a1 << 21;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return a1 << 21;
}

original_code:
static void *pfn_to_addr(u64 pfn)
{
 return (void *)(pfn * 0x200000);
}

canonical_original_code:
static void *pfn_to_addr(unsigned long pfn)
{
 return (void *)(pfn * 0x200000);
}

variable_types:
pfn
unsigned long

return_type: void *


decompiled_code:
unsigned __int64 __fastcall addr_to_pfn(unsigned __int64 a1)
{
return a1 >> 21;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(unsigned __int64 a1)
{
return a1 >> 21;
}

original_code:
static inline u64 addr_to_pfn(void *addr)
{
 return (u64)addr >> 21;
}

canonical_original_code:
static inline unsigned long addr_to_pfn(void *addr)
{
 return (unsigned long)addr >> 21;
}

variable_types:
addr
void *


decompiled_code:
void __fastcall pf_mark_free_addr(unsigned __int64 a1)
{
unsigned __int64 v1; // rax

v1 = addr_to_pfn(a1);
if ( v1 <= 0x83F )
bitclear(&zone[v1 >> 6], v1 & 0x3F);
}

canonical_decompiled_code:
void __fastcall func4(unsigned __int64 a1)
{
unsigned __int64 v1; // rax

v1 = func3(a1);
if ( v1 <= 0x83F )
func1(&zone[v1 >> 6], v1 & 0x3F);
}

original_code:
static void pf_mark_free_addr(void *addr)
{
 u64 idx = addr_to_pfn(addr) >> 6;
 if (idx > 32)
  return;
 bitclear(&zone.memmap[idx], (u64)addr_to_pfn(addr) & 0b111111);
}

canonical_original_code:
static void pf_mark_free_addr(void *addr)
{
 unsigned long idx = addr_to_pfn(addr) >> 6;
 if (idx > 32)
  return;
 bitclear(&zone.memmap[idx], (unsigned long)addr_to_pfn(addr) & 0b111111);
}

variable_types:
idx
unsigned long


decompiled_code:
__int64 __fastcall mem_usable(unsigned __int64 a1)
{
unsigned __int64 v1; // rdx
__int64 result; // rax
int v3; // eax
bool v4; // cf
bool v5; // zf
int v6; // edx

v1 = a1 + 0x200000;
if ( a1 + 0x200000 < (unsigned __int64)&sok || (result = 0LL, a1 >= (unsigned __int64)&eok + 0x800000000000LL) )
{
v3 = -20971521;
v4 = v1 < 0xFEBFFFFF;
v5 = v1 == 4273995775;
v6 = -2;
LOBYTE(v3) = !v4 && !v5;
LOBYTE(v6) = a1 <= 0xFFFFFFFE;
result = v6 & v3 ^ 1u;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1)
{
unsigned __int64 v1; // rdx
__int64 result; // rax
int v3; // eax
bool v4; // cf
bool v5; // zf
int v6; // edx

v1 = a1 + 0x200000;
if ( a1 + 0x200000 < (unsigned __int64)&sok || (result = 0LL, a1 >= (unsigned __int64)&eok + 0x800000000000LL) )
{
v3 = -20971521;
v4 = v1 < 0xFEBFFFFF;
v5 = v1 == 4273995775;
v6 = -2;
LOBYTE(v3) = !v4 && !v5;
LOBYTE(v6) = a1 <= 0xFFFFFFFE;
result = v6 & v3 ^ 1u;
}
return result;
}

original_code:
static s8 mem_usable(void *addr)
{
 if (addr + 0x200000 >= (void *)&sok &&
  addr < (void *)((void *)(((u64)(void *)&eok) - 0xffff800000000000)))
   return 0;
 if (addr + 0x200000 >= (void *)0xfec00000 &&
  addr < (void *)0xffffffff)
   return 0;
 return 1;
}

canonical_original_code:
static char mem_usable(void *addr)
{
 if (addr + 0x200000 >= (void *)&sok &&
  addr < (void *)((void *)(((unsigned long)(void *)&eok) - 0xffff800000000000)))
   return 0;
 if (addr + 0x200000 >= (void *)0xfec00000 &&
  addr < (void *)0xffffffff)
   return 0;
 return 1;
}


decompiled_code:
__int64 __fastcall mm_make_range_usable(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r12
__int64 v4; // r8
__int64 (__fastcall *v5)(unsigned __int64); // r11
unsigned __int64 v6; // rdi
__int64 v7; // r8
__int64 v8; // r9

v2 = 0LL;
if ( a2 > 0x1FFFFF )
{
v4 = align_to(a1, 0x200000LL);
if ( a1 + a2 >= v4 + 0x200000 )
{
v2 = 0LL;
v5 = mem_usable;
do
{
v6 = v4;
if ( (unsigned __int8)v5(v4) )
{
pf_mark_free_addr(v6);
++v2;
}
v4 = v7 + 0x200000;
}
while ( v4 != v8 );
}
}
return v2;
}

original_code:
static s64 mm_make_range_usable(void *addr, u64 len)
{
 void *p;
 u64 npages = 0;
 if (len < 0x200000)
  return 0;
 p = align_to(addr, 0x200000);
 do {
  if (p + 0x200000 > addr + len)
   return npages;
  if (mem_usable(p)) {
   pf_mark_free_addr(p);
   npages++;
  }
  p += 0x200000;
 } while (p <= addr + len);
 return npages;
}

canonical_original_code:
static long mm_make_range_usable(void *addr, unsigned long len)
{
 void *p;
 unsigned long npages = 0;
 if (len < 0x200000)
  return 0;
 p = align_to(addr, 0x200000);
 do {
  if (p + 0x200000 > addr + len)
   return npages;
  if (mem_usable(p)) {
   pf_mark_free_addr(p);
   npages++;
  }
  p += 0x200000;
 } while (p <= addr + len);
 return npages;
}

variable_types:
len
unsigned long

variable_types:
p
void *

variable_types:
npages
unsigned long


decompiled_code:
__int64 build_page_frames()
{
signed __int64 *v0; // rax
char v1; // si
__int64 v2; // rax
char v3; // bl
unsigned __int64 v4; // rsi
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = zone;
v6[0] = 0LL;
do
*v0++ = -1LL;
while ( v0 != &zone[32] );
v1 = 0;
while ( 1 )
{
v3 = v1 + 1;
v4 = get_mm_range(v6);
if ( !v4 )
break;
v2 = mm_make_range_usable(v6[0], v4);
v1 = v3;
qword_460 += v2;
}
return kprintf(" %d free page frames\n", qword_460);
}

canonical_decompiled_code:
__int64 func8()
{
signed __int64 *v0; // rax
char v1; // si
__int64 v2; // rax
char v3; // bl
unsigned __int64 v4; // rsi
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v0 = zone;
v6[0] = 0LL;
do
*v0++ = -1LL;
while ( v0 != &zone[32] );
v1 = 0;
while ( 1 )
{
v3 = v1 + 1;
v4 = get_mm_range(v6);
if ( !v4 )
break;
v2 = func6(v6[0], v4);
v1 = v3;
qword_460 += v2;
}
return kprintf(" %d free page frames\n", qword_460);
}

original_code:
void build_page_frames(void)
{
 u8 i;
 void *addr = 0;
 u64 len;
 for (i = 0; i < 32; i++)
  zone.memmap[i] = ~0L;
 i = 0;
 do {
  len = get_mm_range(&addr, i++);
  if (len == 0)
   break;
  zone.npages += mm_make_range_usable(addr, len);
 } while (1);
 kprintf("  %d free page frames\n", zone.npages);
}

canonical_original_code:
void build_page_frames()
{
 unsigned char i;
 void *addr = 0;
 unsigned long len;
 for (i = 0; i < 32; i++)
  zone.memmap[i] = ~0L;
 i = 0;
 do {
  len = get_mm_range(&addr, i++);
  if (len == 0)
   break;
  zone.npages += mm_make_range_usable(addr, len);
 } while (1);
 kprintf("  %d free page frames\n", zone.npages);
}

variable_types:
i
unsigned char


decompiled_code:
__int64 __fastcall get_pages(int a1)
{
int v1; // ebx
__int64 v2; // rax
__int64 v3; // rdx

if ( a1 )
kpanic("Not yet implemented!\n");
v1 = find_free_pages_constprop_0();
if ( v1 < 0 )
oom("get_pages");
v2 = pfn_to_addr(v1);
return v3 + v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // ebx
__int64 v2; // rax
__int64 v3; // rdx

if ( a1 )
kpanic("Not yet implemented!\n");
v1 = func7();
if ( v1 < 0 )
oom("get_pages");
v2 = func2(v1);
return v3 + v2;
}

original_code:
void *get_pages(u32 order)
{
 s32 pfn;
 if (order > 0)
  kpanic("Not yet implemented!\n");
 pfn = find_free_pages(order);
 if (pfn < 0)
  oom(__func__);
 return (void *)((void *)(((u64)pfn_to_addr(pfn)) + 0xffff800000000000));
}

canonical_original_code:
void *get_pages(unsigned int order)
{
 int pfn;
 if (order > 0)
  kpanic("Not yet implemented!\n");
 pfn = find_free_pages(order);
 if (pfn < 0)
  oom(__func__);
 return (void *)((void *)(((unsigned long)pfn_to_addr(pfn)) + 0xffff800000000000));
}

variable_types:
order
unsigned int

variable_types: pfn int


decompiled_code:
__int64 get_one_page()
{
return get_pages(0);
}

canonical_decompiled_code:
__int64 func10()
{
return func9(0);
}

original_code:
void *get_one_page(void)
{
 return get_pages(0);
}

canonical_original_code:
void *get_one_page()
{
 return get_pages(0);
}


decompiled_code:
void __fastcall free_page(unsigned __int64 a1)
{
pf_mark_free_addr(a1);
}

canonical_decompiled_code:
void __fastcall func11(unsigned __int64 a1)
{
func4(a1);
}

original_code:
void free_page(u64 *addr)
{
 pf_mark_free_addr(addr);
}

canonical_original_code:
void free_page(unsigned long *addr)
{
 pf_mark_free_addr(addr);
}

variable_types:
addr
unsigned long *


decompiled_code:
void __fastcall free_page_pfn(__int64 a1)
{
__int64 v1; // rax

v1 = pfn_to_addr(a1);
pf_mark_free_addr(v1);
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
__int64 v1; // rax

v1 = func2(a1);
func4(v1);
}

original_code:
void free_page_pfn(u64 pfn)
{
 pf_mark_free_addr((u64 *)pfn_to_addr(pfn));
}

canonical_original_code:
void free_page_pfn(unsigned long pfn)
{
 pf_mark_free_addr((unsigned long *)pfn_to_addr(pfn));
}


decompiled_code:
void __fastcall cr3_write(unsigned __int64 a1)
{
__writecr3(a1);
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int64 a1)
{
__writecr3(a1);
}

original_code:
static inline void
cr3_write(u64 val)
{
 asm volatile(
  "mov %0,%%cr3"
  : : "r" (val));
}

canonical_original_code:
static inline void cr3_write(unsigned long val)
{
 asm volatile(
  "mov %0,%%cr3"
  : : "r" (val));
}

variable_types:
val
unsigned long


original_code:
static void *pte_set(void *src, void *dst, u8 user_readable, u8 last)
{
 *(u64 *)src = (u64)((void *)(((u64)dst) - 0xffff800000000000))
  | (last << 7)
  | (user_readable << 2)
  | 0b10
  | 0b1;
 return dst;
}

canonical_original_code:
static void *pte_set(void *src, void *dst, unsigned char user_readable, unsigned char last)
{
 *(unsigned long *)src = (u64)((void *)(((unsigned long)dst) - 0xffff800000000000))
  | (last << 7)
  | (user_readable << 2)
  | 0b10
  | 0b1;
 return dst;
}

variable_types:
src
void *

variable_types:
dst
void *

variable_types:
last
unsigned char


decompiled_code:
__int64 __fastcall pml4_walk(unsigned __int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(current + 264LL) + 16LL) + 8 * ((a1 >> 39) & 0x1FF)) & 0xFFFFFFFFFF000LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(*(_QWORD *)(current + 264LL) + 16LL) + 8 * ((a1 >> 39) & 0x1FF)) & 0xFFFFFFFFFF000LL;
}

original_code:
static void *pml4_walk(const void *addr)
{
 return ((void *)((*(u64 *)(current->mm->pgd + ((u64)(addr) >> 39 & 0x1ff))) & 0xffffffffff000L));
}

canonical_original_code:
static void *pml4_walk(void *addr)
{
 return ((void *)((*(unsigned long *)(current->mm->pgd + ((u64)(addr) >> 39 & 0x1ff))) & 0xffffffffff000L));
}


decompiled_code:
__int64 __fastcall pdpe_walk(__int64 a1, unsigned __int64 a2)
{
return *(_QWORD *)(a1 + 8 * ((a2 >> 30) & 0x1FF)) & 0xFFFFFFFFFF000LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int64 a2)
{
return *(_QWORD *)(a1 + 8 * ((a2 >> 30) & 0x1FF)) & 0xFFFFFFFFFF000LL;
}

original_code:
static void *pdpe_walk(const u64 *pdpe, const void *addr)
{
 return ((void *)((*(u64 *)(pdpe + ((u64)(addr) >> 30 & 0x1ff))) & 0xffffffffff000L));
}

canonical_original_code:
static void *pdpe_walk(unsigned long *pdpe, void *addr)
{
 return ((void *)((*(unsigned long *)(pdpe + ((u64)(addr) >> 30 & 0x1ff))) & 0xffffffffff000L));
}

variable_types:
pdpe
unsigned long *


decompiled_code:
__int64 __fastcall pde_walk(__int64 a1, unsigned __int64 a2)
{
return (a2 & 0xFFFFF) + (*(_QWORD *)(a1 + 8 * ((a2 >> 21) & 0x1FF)) & 0xFFFFFFFFFF000LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int64 a2)
{
return (a2 & 0xFFFFF) + (*(_QWORD *)(a1 + 8 * ((a2 >> 21) & 0x1FF)) & 0xFFFFFFFFFF000LL);
}

original_code:
static void *pde_walk(const u64 *pde, const void *addr)
{
 return ((void *)((*(u64 *)(pde + ((u64)(addr) >> 21 & 0x1ff))) & 0xffffffffff000L)) + ((u64)addr & 0xfffff);
}

canonical_original_code:
static void *pde_walk(unsigned long *pde, void *addr)
{
 return ((void *)((*(unsigned long *)(pde + ((u64)(addr) >> 21 & 0x1ff))) & 0xffffffffff000L)) + ((unsigned long)addr & 0xfffff);
}

variable_types:
pde
unsigned long *


decompiled_code:
__int64 __fastcall is_canonical(unsigned __int64 a1, __int64 a2, int a3)
{
unsigned int v3; // eax
unsigned __int64 v4; // rdi

v4 = a1 >> 47;
LOBYTE(v3) = v4 == 0;
LOBYTE(a3) = v4 == 0x1FFFF;
return a3 | v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1, __int64 a2, int a3)
{
unsigned int v3; // eax
unsigned __int64 v4; // rdi

v4 = a1 >> 47;
LOBYTE(v3) = v4 == 0;
LOBYTE(a3) = v4 == 0x1FFFF;
return a3 | v3;
}

original_code:
static u8 is_canonical(const void *addr)
{
 if ((u64)addr >> 47 == 0 || (u64)addr >> 47 == 0x1ffff)
  return 1;
 return 0;
}

canonical_original_code:
static unsigned char is_canonical(void *addr)
{
 if ((unsigned long)addr >> 47 == 0 || (unsigned long)addr >> 47 == 0x1ffff)
  return 1;
 return 0;
}


decompiled_code:
__int64 pte_get_empty()
{
return xkmallocf0(4096LL, "pte_get_empty");
}

canonical_decompiled_code:
__int64 func6()
{
return xkmallocf0(4096LL, "pte_get_empty");
}

original_code:
static void *pte_get_empty(void)
{
 return xkmallocf0(4096, __func__);
}

canonical_original_code:
static void *pte_get_empty()
{
 return xkmallocf0(4096, __func__);
}


decompiled_code:
void __fastcall cr3_load(unsigned __int64 a1)
{
if ( (a1 & 0x7FF8000000000FFFLL) != 0 )
kpanic("Invalid cr3 location!\n");
cr3_write(a1);
}

canonical_decompiled_code:
void __fastcall func7(unsigned __int64 a1)
{
if ( (a1 & 0x7FF8000000000FFFLL) != 0 )
kpanic("Invalid cr3 location!\n");
func0(a1);
}

original_code:
static void cr3_load(void *pml4)
{
 if (((u64)pml4 & 0x7ff8000000000fffL) != 0)
  kpanic("Invalid cr3 location!\n");
 cr3_write((u64)pml4);
}

canonical_original_code:
static void cr3_load(void *pml4)
{
 if (((unsigned long)pml4 & 0x7ff8000000000fffL) != 0)
  kpanic("Invalid cr3 location!\n");
 cr3_write((unsigned long)pml4);
}


decompiled_code:
__int64 __fastcall virt2phys(unsigned __int64 a1, __int64 a2, int a3)
{
unsigned __int64 v3; // r8
__int64 v4; // rax
unsigned __int64 v5; // r8
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // r8
__int64 result; // rax

if ( (unsigned __int8)is_canonical(a1, a2, a3)
&& (v4 = pml4_walk(v3)) != 0
&& (v6 = pdpe_walk(v4 - 0x800000000000LL, v5)) != 0 )
{
result = pde_walk(v6 + v7, v8);
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1, __int64 a2, int a3)
{
unsigned __int64 v3; // r8
__int64 v4; // rax
unsigned __int64 v5; // r8
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // r8
__int64 result; // rax

if ( (unsigned __int8)func5(a1, a2, a3)
&& (v4 = func2(v3)) != 0
&& (v6 = func3(v4 - 0x800000000000LL, v5)) != 0 )
{
result = func4(v6 + v7, v8);
}
else
{
result = 0LL;
}
return result;
}

original_code:
void *virt2phys(const void *vaddr)
{
 u64 *pdpe;
 u64 *pde;
 if (!is_canonical(vaddr))
  return ((void *)0);
 pdpe = pml4_walk(vaddr);
 if (pdpe == ((void *)0))
  return ((void *)0);
 pde = pdpe_walk(((void *)(((u64)pdpe) + 0xffff800000000000)), vaddr);
 if (pde == ((void *)0))
  return ((void *)0);
 return pde_walk(((void *)(((u64)pde) + 0xffff800000000000)), vaddr);
}

canonical_original_code:
void *virt2phys(void *vaddr)
{
 unsigned long *pdpe;
 unsigned long *pde;
 if (!is_canonical(vaddr))
  return ((void *)0);
 pdpe = pml4_walk(vaddr);
 if (pdpe == ((void *)0))
  return ((void *)0);
 pde = pdpe_walk(((void *)(((unsigned long)pdpe) + 0xffff800000000000)), vaddr);
 if (pde == ((void *)0))
  return ((void *)0);
 return pde_walk(((void *)(((unsigned long)pde) + 0xffff800000000000)), vaddr);
}

variable_types:
vaddr
void *


decompiled_code:
__int64 __fastcall map_one_page(unsigned __int64 a1, unsigned __int64 a2, int a3)
{
__int64 result; // rax
int v4; // edx
__int64 (__fastcall *v5)(unsigned __int64, __int64, int); // rcx
__int64 v6; // r13
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax

result = is_canonical(a2, a2, a3);
if ( (_BYTE)result )
{
result = v5(a1, a2, v4);
if ( (_BYTE)result )
{
v6 = pml4_walk(a2);
if ( !v6 )
{
v8 = pte_get_empty();
v6 = pte_set(
(unsigned __int64 *)(*(_QWORD *)(*(_QWORD *)(current + 264LL) + 16LL) + ((a2 >> 36) & 0xFF8)),
v8,
1,
0);
}
v7 = pdpe_walk(v6, a2);
if ( !v7 )
{
v9 = pte_get_empty();
v7 = pte_set((unsigned __int64 *)(v6 + ((a2 >> 27) & 0xFF8)), v9, 1, 0);
}
pte_set((unsigned __int64 *)(v7 + ((a2 >> 18) & 0xFF8)), (a1 & 0xFFFFFFFFFFE00000LL) - 0x800000000000LL, 1, 1);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int64 a1, unsigned __int64 a2, int a3)
{
__int64 result; // rax
int v4; // edx
__int64 (__fastcall *v5)(unsigned __int64, __int64, int); // rcx
__int64 v6; // r13
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax

result = func5(a2, a2, a3);
if ( (_BYTE)result )
{
result = v5(a1, a2, v4);
if ( (_BYTE)result )
{
v6 = func2(a2);
if ( !v6 )
{
v8 = func6();
v6 = func1(
(unsigned __int64 *)(*(_QWORD *)(*(_QWORD *)(current + 264LL) + 16LL) + ((a2 >> 36) & 0xFF8)),
v8,
1,
0);
}
v7 = func3(v6, a2);
if ( !v7 )
{
v9 = func6();
v7 = func1((unsigned __int64 *)(v6 + ((a2 >> 27) & 0xFF8)), v9, 1, 0);
}
func1((unsigned __int64 *)(v7 + ((a2 >> 18) & 0xFF8)), (a1 & 0xFFFFFFFFFFE00000LL) - 0x800000000000LL, 1, 1);
result = 1LL;
}
}
return result;
}

original_code:
u8 map_one_page(void *phys, void *vaddr)
{
 u64 *pdpe;
 u64 *pde;
 if (!is_canonical(vaddr) || !is_canonical(phys))
  return 0;
 pdpe = pml4_walk(vaddr);
 if (pdpe == ((void *)0))
  pdpe = pte_set(current->mm->pgd + ((u64)(vaddr) >> 39 & 0x1ff), pte_get_empty(), 1, 0);
 pde = pdpe_walk(pdpe, vaddr);
 if (pde == ((void *)0))
  pde = pte_set(pdpe + ((u64)(vaddr) >> 30 & 0x1ff), pte_get_empty(), 1, 0);
 pte_set(pde + ((u64)(vaddr) >> 21 & 0x1ff), ((void *)(((u64)phys & ~(0x200000 - 1)) + 0xffff800000000000)), 1, 1);
 return 1;
}

canonical_original_code:
unsigned char map_one_page(void *phys, void *vaddr)
{
 unsigned long *pdpe;
 unsigned long *pde;
 if (!is_canonical(vaddr) || !is_canonical(phys))
  return 0;
 pdpe = pml4_walk(vaddr);
 if (pdpe == ((void *)0))
  pdpe = pte_set(current->mm->pgd + ((u64)(vaddr) >> 39 & 0x1ff), pte_get_empty(), 1, 0);
 pde = pdpe_walk(pdpe, vaddr);
 if (pde == ((void *)0))
  pde = pte_set(pdpe + ((u64)(vaddr) >> 30 & 0x1ff), pte_get_empty(), 1, 0);
 pte_set(pde + ((u64)(vaddr) >> 21 & 0x1ff), ((void *)(((unsigned long)phys & ~(0x200000 - 1)) + 0xffff800000000000)), 1, 1);
 return 1;
}

variable_types:
phys
void *


original_code:
void load_init_page_tables(struct task *task)
{
 u16 i;
 u64 *p;
 u64 *pa;
 u64 *pd;
 task->mm = xkmallocf0(sizeof(struct mm), __func__);
 init_mm(task->mm, pte_get_empty());
 p = pte_set(task->mm->pgd + 256, pte_get_empty(), 0, 0);
 pa = pte_set(p + 0, pte_get_empty(), 0, 0);
 pd = pte_set(p + 3, pte_get_empty(), 0, 0);
 for (i = 0; i < 512; i++) {
  *(pa + i) = 0x87 + i * 0x200000;
  *(pd + i) = 0xc0000087 + i * 0x200000;
 }
 cr3_load(((void *)(((u64)task->mm->pgd) - 0xffff800000000000)));
}

canonical_original_code:
void load_init_page_tables(struct task *task)
{
 unsigned short i;
 unsigned long *p;
 unsigned long *pa;
 unsigned long *pd;
 task->mm = xkmallocf0(sizeof(struct mm), __func__);
 init_mm(task->mm, pte_get_empty());
 p = pte_set(task->mm->pgd + 256, pte_get_empty(), 0, 0);
 pa = pte_set(p + 0, pte_get_empty(), 0, 0);
 pd = pte_set(p + 3, pte_get_empty(), 0, 0);
 for (i = 0; i < 512; i++) {
  *(pa + i) = 0x87 + i * 0x200000;
  *(pd + i) = 0xc0000087 + i * 0x200000;
 }
 cr3_load(((void *)(((unsigned long)task->mm->pgd) - 0xffff800000000000)));
}

variable_types: struct task { unsigned char state; struct file { struct inode { struct super { struct dev_t { unsigned int major; unsigned int minor; } dev; unsigned long blocksize; unsigned long blocksizephys; struct list_head { struct list_head *prev; } bcache; struct list_head icache; struct super_ops { struct super *(*super_read)(struct dev_t *dev); struct inode *(*inode_read)(struct super *sb, unsigned long inum); } *ops; unsigned long magic; unsigned long time; struct inode *mounted; unsigned int flags; void *priv; } *sb; unsigned long num; unsigned short mode; unsigned char nlinks; unsigned int uid; unsigned int gid; unsigned long filesize; unsigned long nblocks; unsigned long atime; unsigned long mtime; unsigned long ctime; unsigned int flags; unsigned int count; struct list_head l; struct super *covered; struct inode_ops { struct inode *(*lookup)(struct inode *, char *, unsigned char); unsigned long (*bmap)(struct inode *, long); struct bhead { struct list_head l; unsigned long bnum; void *data; unsigned char count; } *(*block_read)(struct inode *, long); } *ops; void *priv; } *inode; unsigned short count; unsigned short mode; unsigned short flags; long pos; } *fds[32]; struct mm { struct list_head l; unsigned long *pgd; unsigned char count; void *code_start; void *code_end; void *data_start; void *data_end; void *heap_start; void *heap_end; void *stack_start; unsigned short used_pages; } *mm; } *

variable_types:
i
unsigned short

variable_types:
p
unsigned long *

variable_types:
pa
unsigned long *

variable_types:
pd
unsigned long *

user_defined_types: struct task { unsigned char state; struct file *fds[32]; struct mm *mm; }


decompiled_code:
void __fastcall syscall_dispatch_real()
{
unsigned __int64 v0; // rax

if ( v0 < 0x3D )
syscall_table[v0]();
__asm { sysret }
}

canonical_decompiled_code:
void __fastcall func0()
{
unsigned __int64 v0; // rax

if ( v0 < 0x3D )
syscall_table[v0]();
__asm { sysret }
}

original_code:
void syscall_dispatch_real(void)
{
 asm volatile(
  "nop; nop; nop; nop;"
  "nop; nop; nop; nop;"
  "nop; nop; nop; nop;"
  "nop; nop; nop; nop;\n\t"
  "cmpq $" "61" ", %rax\n\t"
  "jae 1f\n\t"
  "cmpq $" "60" ", %rax\n\t"
  "je 2f\n\t"
  "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t"
  "2:\n\t"
 );
 asm volatile(
  "shl $3, %%rax\n\t"
  "addq %0, %%rax\n\t"
  "call *(%%rax)\n\t"
  : : "c"(syscall_table)
 );
 asm volatile(
  "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t"
  "1:\n\t"
  "sysretq\n\t"
 );
 kernel_idle();
}

canonical_original_code:
void syscall_dispatch_real()
{
 asm volatile(
  "nop; nop; nop; nop;"
  "nop; nop; nop; nop;"
  "nop; nop; nop; nop;"
  "nop; nop; nop; nop;\n\t"
  "cmpq $" "61" ", %rax\n\t"
  "jae 1f\n\t"
  "cmpq $" "60" ", %rax\n\t"
  "je 2f\n\t"
  "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t"
  "2:\n\t"
 );
 asm volatile(
  "shl $3, %%rax\n\t"
  "addq %0, %%rax\n\t"
  "call *(%%rax)\n\t"
  : : "c"(syscall_table)
 );
 asm volatile(
  "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t"
  "1:\n\t"
  "sysretq\n\t"
 );
 kernel_idle();
}


decompiled_code:
__int64 __fastcall syscall_register(unsigned __int16 a1, void (*a2)(void))
{
if ( a1 > 0x3Cu )
return 0xFFFFFFFFLL;
syscall_table[a1] = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 a1, void (*a2)(void))
{
if ( a1 > 0x3Cu )
return 0xFFFFFFFFLL;
syscall_table[a1] = a2;
return 0LL;
}

original_code:
s8 syscall_register(u16 num, void *handler)
{
 if (num >= 61)
  return -1;
 syscall_table[num] = handler;
 return 0;
}

canonical_original_code:
char syscall_register(unsigned short num, void *handler)
{
 if (num >= 61)
  return -1;
 syscall_table[num] = handler;
 return 0;
}

variable_types:
num
unsigned short

variable_types:
handler
void *


decompiled_code:
void *init_syscall()
{
void *result; // rax

result = &loc_10;
syscall_dispatch = (__int64)&loc_10;
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

result = &loc_10;
syscall_dispatch = (__int64)&loc_10;
return result;
}

original_code:
void init_syscall(void)
{
 syscall_dispatch = syscall_dispatch_real + 16;
}

canonical_original_code:
void init_syscall()
{
 syscall_dispatch = syscall_dispatch_real + 16;
}


decompiled_code:
__int64 elf_get_machine()
{
return 62LL;
}

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

original_code:
static u16 elf_get_machine(void)
{
 return 0x3e;
}

canonical_original_code:
static unsigned short elf_get_machine()
{
 return 0x3e;
}

return_type: unsigned short


decompiled_code:
__int64 __fastcall elf_load_section(int fd, __int64 a2)
{
if ( *(_QWORD *)(a2 + 16) % *(_QWORD *)(a2 + 48) )
return 0xFFFFFFFFLL;
mmap(*(void **)(a2 + 16), *(_QWORD *)(a2 + 40), 4, 17, fd, *(_QWORD *)(a2 + 8));
return 0LL;
}

original_code:
static s8 elf_load_section(s32 fd, struct elf_ph_entry *ph)
{
 if (ph->ph_vaddr % ph->ph_align > 0)
  return -1;
 mmap((void *)ph->ph_vaddr, ph->ph_memsz, 0x4,
  0x01 | 0x10, fd, ph->ph_offset);
 return 0;
}

canonical_original_code:
static char elf_load_section(int fd, struct elf_ph_entry *ph)
{
 if (ph->ph_vaddr % ph->ph_align > 0)
  return -1;
 mmap((void *)ph->ph_vaddr, ph->ph_memsz, 0x4,
  0x01 | 0x10, fd, ph->ph_offset);
 return 0;
}

variable_types: fd int

variable_types: struct elf_ph_entry { unsigned int ph_type; unsigned int ph_flags; unsigned long ph_offset; unsigned long ph_vaddr; unsigned long ph_paddr; unsigned long ph_filesz; unsigned long ph_memsz; unsigned long ph_align; } *


decompiled_code:
__int64 tsc_calibration()
{
char v0; // bl
unsigned __int64 v1; // rax
unsigned __int64 v2; // r12
unsigned __int64 v4[6]; // [rsp+8h] [rbp-30h] BYREF

v0 = 4;
sys[2] = -1LL;
loops_per_jiffy = -1LL;
do
{
v1 = tsc_calibration_withpit(v4);
if ( sys[2] > v1 )
sys[2] = v1;
if ( v4[0] < loops_per_jiffy )
loops_per_jiffy = v4[0];
--v0;
}
while ( v0 );
v2 = sys[2] / 0xF4240uLL;
if ( sys[2] <= 0xF423FuLL )
kpanic("Can't calibrate the cpu!!");
return kprintf("Cpu speed calibrated to: %ldMhz, %ld BogoMIPS\n", v2, loops_per_jiffy);
}

canonical_decompiled_code:
__int64 func0()
{
char v0; // bl
unsigned __int64 v1; // rax
unsigned __int64 v2; // r12
unsigned __int64 v4[6]; // [rsp+8h] [rbp-30h] BYREF

v0 = 4;
sys[2] = -1LL;
loops_per_jiffy = -1LL;
do
{
v1 = tsc_calibration_withpit(v4);
if ( sys[2] > v1 )
sys[2] = v1;
if ( v4[0] < loops_per_jiffy )
loops_per_jiffy = v4[0];
--v0;
}
while ( v0 );
v2 = sys[2] / 0xF4240uLL;
if ( sys[2] <= 0xF423FuLL )
kpanic("Can't calibrate the cpu!!");
return kprintf("Cpu speed calibrated to: %ldMhz, %ld BogoMIPS\n", v2, loops_per_jiffy);
}

original_code:
static void tsc_calibration(void)
{
 u64 hz, mhz, loops;
 u8 i;
 sys.cpu[0].hz = (u64)-1;
 loops_per_jiffy = (u64)-1;
 i = 4;
 while (i--) {
  hz = tsc_calibration_withpit(&loops);
  if (hz < sys.cpu[0].hz)
   sys.cpu[0].hz = hz;
  if (loops < loops_per_jiffy)
   loops_per_jiffy = loops;
 }
 mhz = sys.cpu[0].hz / 1000000;
 if (mhz == 0)
  kpanic("Can't calibrate the cpu!!");
 kprintf("Cpu speed calibrated to: %ldMhz, %ld BogoMIPS\n",
  mhz, loops_per_jiffy);
}

canonical_original_code:
static void tsc_calibration()
{
 unsigned long hz; unsigned long mhz; unsigned long loops;
 unsigned char i;
 sys.cpu[0].hz = (u64)-1;
 loops_per_jiffy = (u64)-1;
 i = 4;
 while (i--) {
  hz = tsc_calibration_withpit(&loops);
  if (hz < sys.cpu[0].hz)
   sys.cpu[0].hz = hz;
  if (loops < loops_per_jiffy)
   loops_per_jiffy = loops;
 }
 mhz = sys.cpu[0].hz / 1000000;
 if (mhz == 0)
  kpanic("Can't calibrate the cpu!!");
 kprintf("Cpu speed calibrated to: %ldMhz, %ld BogoMIPS\n",
  mhz, loops_per_jiffy);
}

variable_types:
hz
unsigned long

variable_types:
mhz
unsigned long

variable_types:
loops
unsigned long

variable_types:
i
unsigned char


decompiled_code:
__int64 lapic_eoi()
{
return lapic_write_constprop_0();
}

canonical_decompiled_code:
__int64 func2()
{
return func1();
}

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

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


decompiled_code:
void do_pit()
{
++jiffies;
lapic_eoi();
__asm { iretq }
}

canonical_decompiled_code:
void func3()
{
++jiffies;
func2();
__asm { iretq }
}

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

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


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

canonical_decompiled_code:
void func4()
{
func2();
__asm { iretq }
}

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


decompiled_code:
__int64 init_timers()
{
tsc_calibration();
init_pit(do_pit, 100LL);
init_lapic_timer(do_lapictim, 100LL);
return init_rtc();
}

canonical_decompiled_code:
__int64 func5()
{
func0();
init_pit(do_pit, 100LL);
init_lapic_timer(do_lapictim, 100LL);
return init_rtc();
}

original_code:
void init_timers(void)
{
 tsc_calibration();
 init_pit(do_pit, 100);
 init_lapic_timer(do_lapictim, 100);
 init_rtc();
 return;
}

canonical_original_code:
void init_timers()
{
 tsc_calibration();
 init_pit(do_pit, 100);
 init_lapic_timer(do_lapictim, 100);
 init_rtc();
 return;
}


decompiled_code:
char __fastcall acpi_csum(_BYTE *a1, unsigned __int8 a2)
{
char result; // al
_BYTE *v3; // rsi

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

canonical_decompiled_code:
char __fastcall func0(_BYTE *a1, unsigned __int8 a2)
{
char result; // al
_BYTE *v3; // rsi

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

original_code:
static inline u8 acpi_csum(void *p, u8 bytes)
{
 u8 csum = 0;
 u8 *pp = (u8 *)p;
 while ((u64)pp < (u64)p + bytes)
  csum += *pp++;
 return csum;
}

canonical_original_code:
static inline unsigned char acpi_csum(void *p, unsigned char bytes)
{
 unsigned char csum = 0;
 unsigned char *pp = (u8 *)p;
 while ((unsigned long)pp < (unsigned long)p + bytes)
  csum += *pp++;
 return csum;
}

variable_types:
p
void *

variable_types:
bytes
unsigned char

variable_types:
csum
unsigned char

variable_types:
pp
unsigned char *


decompiled_code:
unsigned __int64 __fastcall acpi_walk_madt(unsigned int *a1, int a2)
{
_BYTE *v2; // rax
int v3; // edx
__int64 v4; // rdx
unsigned __int64 result; // rax
int v6; // ebp
unsigned int *v7; // rbx
__int64 v8; // rdx
char v9; // al
__int64 v10; // rsi
unsigned int v11; // er8
__int64 v12; // rdx
__int64 v13; // rdx

v2 = (char *)&ioapic + 10;
v3 = 0;
do
{
*v2 = v3++;
v2 += 3;
*(v2 - 2) = 1;
*(v2 - 1) = 1;
}
while ( (_BYTE)v3 != 16 );
v4 = *a1;
result = (unsigned __int64)&lapic;
*((_QWORD *)&sys + 1) = &lapic;
lapic = v4 - 0x800000000000LL;
if ( (a1[1] & 1) != 0 )
*((_BYTE *)&sys + 32) = 1;
v6 = a2 - 8;
v7 = a1 + 2;
if ( a2 - 8 > 0 )
{
while ( 1 )
{
v8 = *((unsigned __int8 *)v7 + 1);
if ( !(_BYTE)v8 )
return result;
v9 = *(_BYTE *)v7;
if ( *(_BYTE *)v7 == 1 )
break;
if ( v9 != 2 )
{
if ( !v9 )
{
*((_BYTE *)&lapic + 8) = *((_BYTE *)v7 + 3);
sys = *((_BYTE *)v7 + 2);
}
goto LABEL_9;
}
v10 = *((unsigned __int8 *)v7 + 3);
if ( (unsigned __int8)v10 > 0x10u || (v11 = v7[1], v11 > 0x10) )
{
LABEL_9:
result = (unsigned __int8)v8;
v7 = (unsigned int *)((char *)v7 + v8);
v6 -= (unsigned __int8)v8;
if ( v6 <= 0 )
return result;
}
else
{
kprintf(" PIC Redirect %d -> %d", v10, v11);
v12 = v7[1];
*((_BYTE *)&ioapic + 3 * *((unsigned __int8 *)v7 + 3) + 10) = v12;
if ( (((unsigned __int8)*((_WORD *)v7 + 4) ^ 0xC) & 0xC) == 0 )
{
*((_BYTE *)&ioapic + 3 * v12 + 11) = 0;
kprintf(" (level, ");
if ( (v7[2] & 3) != 1 )
goto LABEL_17;
LABEL_21:
kprintf("high)\n");
v8 = *((unsigned __int8 *)v7 + 1);
goto LABEL_9;
}
kprintf(" (edge, ");
if ( (v7[2] & 3) == 1 )
goto LABEL_21;
LABEL_17:
*((_BYTE *)&ioapic + 3 * v7[1] + 12) = 0;
kprintf("low)\n");
v13 = *((unsigned __int8 *)v7 + 1);
result = (unsigned __int8)v13;
v7 = (unsigned int *)((char *)v7 + v13);
v6 -= (unsigned __int8)v13;
if ( v6 <= 0 )
return result;
}
}
*((_BYTE *)&ioapic + 8) = *((_BYTE *)v7 + 2);
ioapic = v7[1] - 0x800000000000LL;
goto LABEL_9;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned int *a1, int a2)
{
_BYTE *v2; // rax
int v3; // edx
__int64 v4; // rdx
unsigned __int64 result; // rax
int v6; // ebp
unsigned int *v7; // rbx
__int64 v8; // rdx
char v9; // al
__int64 v10; // rsi
unsigned int v11; // er8
__int64 v12; // rdx
__int64 v13; // rdx

v2 = (char *)&ioapic + 10;
v3 = 0;
do
{
*v2 = v3++;
v2 += 3;
*(v2 - 2) = 1;
*(v2 - 1) = 1;
}
while ( (_BYTE)v3 != 16 );
v4 = *a1;
result = (unsigned __int64)&lapic;
*((_QWORD *)&sys + 1) = &lapic;
lapic = v4 - 0x800000000000LL;
if ( (a1[1] & 1) != 0 )
*((_BYTE *)&sys + 32) = 1;
v6 = a2 - 8;
v7 = a1 + 2;
if ( a2 - 8 > 0 )
{
while ( 1 )
{
v8 = *((unsigned __int8 *)v7 + 1);
if ( !(_BYTE)v8 )
return result;
v9 = *(_BYTE *)v7;
if ( *(_BYTE *)v7 == 1 )
break;
if ( v9 != 2 )
{
if ( !v9 )
{
*((_BYTE *)&lapic + 8) = *((_BYTE *)v7 + 3);
sys = *((_BYTE *)v7 + 2);
}
goto LABEL_9;
}
v10 = *((unsigned __int8 *)v7 + 3);
if ( (unsigned __int8)v10 > 0x10u || (v11 = v7[1], v11 > 0x10) )
{
LABEL_9:
result = (unsigned __int8)v8;
v7 = (unsigned int *)((char *)v7 + v8);
v6 -= (unsigned __int8)v8;
if ( v6 <= 0 )
return result;
}
else
{
kprintf(" PIC Redirect %d -> %d", v10, v11);
v12 = v7[1];
*((_BYTE *)&ioapic + 3 * *((unsigned __int8 *)v7 + 3) + 10) = v12;
if ( (((unsigned __int8)*((_WORD *)v7 + 4) ^ 0xC) & 0xC) == 0 )
{
*((_BYTE *)&ioapic + 3 * v12 + 11) = 0;
kprintf(" (level, ");
if ( (v7[2] & 3) != 1 )
goto LABEL_17;
LABEL_21:
kprintf("high)\n");
v8 = *((unsigned __int8 *)v7 + 1);
goto LABEL_9;
}
kprintf(" (edge, ");
if ( (v7[2] & 3) == 1 )
goto LABEL_21;
LABEL_17:
*((_BYTE *)&ioapic + 3 * v7[1] + 12) = 0;
kprintf("low)\n");
v13 = *((unsigned __int8 *)v7 + 1);
result = (unsigned __int8)v13;
v7 = (unsigned int *)((char *)v7 + v13);
v6 -= (unsigned __int8)v13;
if ( v6 <= 0 )
return result;
}
}
*((_BYTE *)&ioapic + 8) = *((_BYTE *)v7 + 2);
ioapic = v7[1] - 0x800000000000LL;
goto LABEL_9;
}
return result;
}

original_code:
static void acpi_walk_madt(void *t, s32 l)
{
 struct acpi_apic *a;
 u8 i;
 for (i = 0; i < 16; i++) {
  ioapic[0].pic[i].dest = i;
  ioapic[0].pic[i].edge = 1;
  ioapic[0].pic[i].active_high = 1;
 }
 sys.cpu[0].lapic = &lapic[0];
 lapic[0].base = (void *)((void *)(((u64)*(u32 *)(void *)(t + 0)) + 0xffff800000000000));
 if (*(u32 *)(t + 4) & 0x1)
  sys.has8259 = 1;
 l = l - 8;
 a = (struct acpi_apic *)(t + 8);
 while (l > 0) {
  if (a->l == 0)
   break;
  switch (a->type) {
  case 0:
   lapic[0].id = a->lapicid;
   sys.cpu[0].id = a->cpuid;
   break;
  case 1:
   ioapic[0].id = a->ioapicid;
   ioapic[0].base = (void *)((void *)(((u64)a->ioapicaddr) + 0xffff800000000000));
   break;
  case 2:
   if (a->source > 16 || a->gsi > 16)
    break;
   kprintf("  PIC Redirect %d -> %d",
    a->source, a->gsi);
   ioapic[0].pic[a->source].dest = a->gsi;
   if (((a->flags2 >> 2) & 0x3) == 0x3) {
    ioapic[0].pic[a->gsi].edge = 0;
    kprintf(" (level, ");
   } else
    kprintf(" (edge, ");
   if ((a->flags2 & 0x3) != 0x1) {
    ioapic[0].pic[a->gsi].active_high = 0;
    kprintf("low)\n");
   } else
    kprintf("high)\n");
   break;
  default:
   break;
  }
  l -= a->l;
  a = (struct acpi_apic *)((u64)a + a->l);
 }
 return;
}

canonical_original_code:
static void acpi_walk_madt(void *t, int l)
{
 struct acpi_apic *a;
 unsigned char i;
 for (i = 0; i < 16; i++) {
  ioapic[0].pic[i].dest = i;
  ioapic[0].pic[i].edge = 1;
  ioapic[0].pic[i].active_high = 1;
 }
 sys.cpu[0].lapic = &lapic[0];
 lapic[0].base = (void *)((void *)(((u64)*(unsigned int *)(void *)(t + 0)) + 0xffff800000000000));
 if (*(unsigned int *)(t + 4) & 0x1)
  sys.has8259 = 1;
 l = l - 8;
 a = (struct acpi_apic *)(t + 8);
 while (l > 0) {
  if (a->l == 0)
   break;
  switch (a->type) {
  case 0:
   lapic[0].id = a->lapicid;
   sys.cpu[0].id = a->cpuid;
   break;
  case 1:
   ioapic[0].id = a->ioapicid;
   ioapic[0].base = (void *)((void *)(((unsigned long)a->ioapicaddr) + 0xffff800000000000));
   break;
  case 2:
   if (a->source > 16 || a->gsi > 16)
    break;
   kprintf("  PIC Redirect %d -> %d",
    a->source, a->gsi);
   ioapic[0].pic[a->source].dest = a->gsi;
   if (((a->flags2 >> 2) & 0x3) == 0x3) {
    ioapic[0].pic[a->gsi].edge = 0;
    kprintf(" (level, ");
   } else
    kprintf(" (edge, ");
   if ((a->flags2 & 0x3) != 0x1) {
    ioapic[0].pic[a->gsi].active_high = 0;
    kprintf("low)\n");
   } else
    kprintf("high)\n");
   break;
  default:
   break;
  }
  l -= a->l;
  a = (struct acpi_apic *)((unsigned long)a + a->l);
 }
 return;
}

variable_types:
t
void *

variable_types: l int

variable_types: struct acpi_apic { unsigned char type; unsigned char l; union { struct { unsigned char cpuid; unsigned char lapicid; unsigned int flags0; }; struct { unsigned char ioapicid; unsigned char reserved1; unsigned int ioapicaddr; unsigned int gsib; }; struct { unsigned char bus; unsigned char source; unsigned int gsi; unsigned short flags2; }; }; } *


decompiled_code:
char init_acpi()
{
char *v0; // rax
char *v1; // rbx
__int64 v2; // rsi
__int64 v3; // rbx
unsigned __int64 v4; // rax
__int64 v5; // rdx
unsigned int *v6; // r14
_DWORD *v7; // rdx
int v8; // ecx
char dest[47]; // [rsp+9h] [rbp-2Fh] BYREF

kprintf("Parsing ACPI tables:\n");
v0 = (char *)acpi_search_table(0x2052545020445352LL);
v1 = v0;
if ( !v0 || !*((_DWORD *)v0 + 4) )
kpanic("No valid ACPI tables.");
if ( acpi_csum(v1, 0x14u) )
kpanic("Wrong checksum in rsdp\n");
strncpy(dest, v1 + 9, 6uLL);
v2 = (unsigned __int8)v1[15];
dest[6] = 0;
kprintf(" ACPI table v%d by %s\n", v2, dest);
v3 = *((unsigned int *)v1 + 4) - 0x800000000000LL;
if ( *(_DWORD *)v3 != 1413763922 )
kpanic("Invalid RSDT in ACPI table\n");
LOBYTE(v4) = acpi_csum((_BYTE *)v3, *(_DWORD *)(v3 + 4));
if ( (_BYTE)v4 )
{
LOBYTE(v4) = kpanic("Wrong checksum in rsdt\n");
v5 = *(unsigned int *)(v3 + 4);
}
v6 = (unsigned int *)(v3 + 36);
if ( v3 + 36 < (unsigned __int64)(v3 + v5) )
{
do
{
while ( acpi_csum((_BYTE *)(*v6 - 0x800000000000LL), *(_DWORD *)(*v6 - 0x800000000000LL + 4)) || *v7 != 1128878145 )
{
++v6;
v4 = v3 + *(unsigned int *)(v3 + 4);
if ( (unsigned __int64)v6 >= v4 )
return v4;
}
++v6;
acpi_walk_madt(v7 + 9, v8 - 44);
v4 = v3 + *(unsigned int *)(v3 + 4);
}
while ( (unsigned __int64)v6 < v4 );
}
return v4;
}

canonical_decompiled_code:
char func2()
{
char *v0; // rax
char *v1; // rbx
__int64 v2; // rsi
__int64 v3; // rbx
unsigned __int64 v4; // rax
__int64 v5; // rdx
unsigned int *v6; // r14
_DWORD *v7; // rdx
int v8; // ecx
char dest[47]; // [rsp+9h] [rbp-2Fh] BYREF

kprintf("Parsing ACPI tables:\n");
v0 = (char *)acpi_search_table(0x2052545020445352LL);
v1 = v0;
if ( !v0 || !*((_DWORD *)v0 + 4) )
kpanic("No valid ACPI tables.");
if ( func0(v1, 0x14u) )
kpanic("Wrong checksum in rsdp\n");
strncpy(dest, v1 + 9, 6uLL);
v2 = (unsigned __int8)v1[15];
dest[6] = 0;
kprintf(" ACPI table v%d by %s\n", v2, dest);
v3 = *((unsigned int *)v1 + 4) - 0x800000000000LL;
if ( *(_DWORD *)v3 != 1413763922 )
kpanic("Invalid RSDT in ACPI table\n");
LOBYTE(v4) = func0((_BYTE *)v3, *(_DWORD *)(v3 + 4));
if ( (_BYTE)v4 )
{
LOBYTE(v4) = kpanic("Wrong checksum in rsdt\n");
v5 = *(unsigned int *)(v3 + 4);
}
v6 = (unsigned int *)(v3 + 36);
if ( v3 + 36 < (unsigned __int64)(v3 + v5) )
{
do
{
while ( func0((_BYTE *)(*v6 - 0x800000000000LL), *(_DWORD *)(*v6 - 0x800000000000LL + 4)) || *v7 != 1128878145 )
{
++v6;
v4 = v3 + *(unsigned int *)(v3 + 4);
if ( (unsigned __int64)v6 >= v4 )
return v4;
}
++v6;
func1(v7 + 9, v8 - 44);
v4 = v3 + *(unsigned int *)(v3 + 4);
}
while ( (unsigned __int64)v6 < v4 );
}
return v4;
}

original_code:
void init_acpi(void)
{
 struct rsdp *rsdpp = ((void *)0);
 struct acpi_header *h;
 char oem[7];
 u32 *p;
 kprintf("Parsing ACPI tables:\n");
 rsdpp = (struct rsdp *)acpi_search_table(0x2052545020445352);
 if (rsdpp == ((void *)0) || rsdpp->rsdt == 0)
  kpanic("No valid ACPI tables.");
 if (acpi_csum(rsdpp, 20) != 0)
  kpanic("Wrong checksum in rsdp\n");
 strncpy(oem, rsdpp->oemid, 6);
 oem[6] = '\0';
 kprintf("  ACPI table v%d by %s\n", rsdpp->rev, oem);
 h = (struct acpi_header *)((void *)(((u64)rsdpp->rsdt) + 0xffff800000000000));
 if (h == ((void *)0) || h->sig != 0x54445352)
  kpanic("Invalid RSDT in ACPI table\n");
 if (acpi_csum(h, h->l) != 0)
  kpanic("Wrong checksum in rsdt\n");
 for (p = (u32 *)&h->entry; p < (u32 *)((u64)h + h->l); p++) {
  struct acpi_header *h2 = (struct acpi_header *)((void *)(((u64)*p) + 0xffff800000000000));
  if (acpi_csum(h2, h2->l) != 0)
   continue;
  switch (h2->sig) {
  case 0x43495041:
   acpi_walk_madt(&h2->entry,
    h2->l - sizeof(struct acpi_header) + 4
    );
   break;
  case 0x50434146:
   acpi_walk_fadt(&h2->entry);
   break;
  case 0x54445353:
   acpi_walk_ssdt(&h2->entry);
   break;
  case 0x54455048:
   break;
  default:
   break;
  }
 }
}

canonical_original_code:
void init_acpi()
{
 struct rsdp *rsdpp = ((void *)0);
 struct acpi_header *h;
 char oem[7];
 unsigned int *p;
 kprintf("Parsing ACPI tables:\n");
 rsdpp = (struct rsdp *)acpi_search_table(0x2052545020445352);
 if (rsdpp == ((void *)0) || rsdpp->rsdt == 0)
  kpanic("No valid ACPI tables.");
 if (acpi_csum(rsdpp, 20) != 0)
  kpanic("Wrong checksum in rsdp\n");
 strncpy(oem, rsdpp->oemid, 6);
 oem[6] = '\0';
 kprintf("  ACPI table v%d by %s\n", rsdpp->rev, oem);
 h = (struct acpi_header *)((void *)(((unsigned long)rsdpp->rsdt) + 0xffff800000000000));
 if (h == ((void *)0) || h->sig != 0x54445352)
  kpanic("Invalid RSDT in ACPI table\n");
 if (acpi_csum(h, h->l) != 0)
  kpanic("Wrong checksum in rsdt\n");
 for (p = (unsigned int *)&h->entry; p < (unsigned int *)((unsigned long)h + h->l); p++) {
  struct acpi_header *h2 = (struct acpi_header *)((void *)(((u64)*p) + 0xffff800000000000));
  if (acpi_csum(h2, h2->l) != 0)
   continue;
  switch (h2->sig) {
  case 0x43495041:
   acpi_walk_madt(&h2->entry,
    h2->l - sizeof(struct acpi_header) + 4
    );
   break;
  case 0x50434146:
   acpi_walk_fadt(&h2->entry);
   break;
  case 0x54445353:
   acpi_walk_ssdt(&h2->entry);
   break;
  case 0x54455048:
   break;
  default:
   break;
  }
 }
}

variable_types: struct rsdp { unsigned long sig; unsigned char csum; char oemid[6]; unsigned char rev; unsigned int rsdt; } *

variable_types: struct acpi_header { unsigned int sig; unsigned int l; unsigned char rev; unsigned char csum; char oemid[6]; char oemtableid[8]; unsigned int oemrev; char creatorid[4]; unsigned int creatorrev; unsigned int entry; } *

variable_types:
oem
char [7]

variable_types:
p
unsigned int *


iowait

decompiled_code:
void iowait()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

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

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


yield

decompiled_code:
void yield()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static inline void yield(void)
{
 asm volatile("nop\n\t");
}

canonical_original_code:
static inline void yield()
{
 asm volatile("nop\n\t");
}


outb

decompiled_code:
void __fastcall outb(unsigned __int16 a1, unsigned __int8 a2)
{
__outbyte(a1, a2);
iowait();
}

canonical_decompiled_code:
void __fastcall func2(unsigned __int16 a1, unsigned __int8 a2)
{
__outbyte(a1, a2);
func0();
}

original_code:
static inline void outb(u16 port, u8 val)
{
 asm volatile("outb %1, %0" : : "dN"(port), "a"(val));
 iowait();
}

canonical_original_code:
static inline void outb(unsigned short port, unsigned char val)
{
 asm volatile("outb %1, %0" : : "dN"(port), "a"(val));
 iowait();
}

variable_types:
port
unsigned short

variable_types:
val
unsigned char


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

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

original_code:
static inline void interrupts_disable(void)
{
 asm volatile("cli\n\t");
}

canonical_original_code:
static inline void interrupts_disable()
{
 asm volatile("cli\n\t");
}


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

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

original_code:
static inline void interrupts_enable(void)
{
 asm volatile("sti\n\t");
}

canonical_original_code:
static inline void interrupts_enable()
{
 asm volatile("sti\n\t");
}


ticks

decompiled_code:
unsigned __int64 ticks()
{
return __rdtsc();
}

canonical_decompiled_code:
unsigned __int64 func5()
{
return __rdtsc();
}

original_code:
static inline u64 ticks(void)
{
 u32 a;
 u32 d;
 asm volatile(
  "rdtsc\n\t"
  : "=a"(a), "=d"(d));
 return ((u64)d << 32) | a;
}

canonical_original_code:
static inline unsigned long ticks()
{
 unsigned int a;
 unsigned int d;
 asm volatile(
  "rdtsc\n\t"
  : "=a"(a), "=d"(d));
 return ((unsigned long)d << 32) | a;
}

variable_types:
a
unsigned int

variable_types:
d
unsigned int


canonical_decompiled_code:
__int64 func10()
{
return func9();
}


decompiled_code:
void __fastcall rtc_read(char a1)
{
outb(0x70u, a1 | 0x80);
inb_constprop_0();
}

canonical_decompiled_code:
void __fastcall func12(char a1)
{
func2(0x70u, a1 | 0x80);
func11();
}

original_code:
static inline u8 rtc_read(u8 port)
{
 outb(0x70, port | (1 << 7));
 return inb(0x71);
}

canonical_original_code:
static inline unsigned char rtc_read(unsigned char port)
{
 outb(0x70, port | (1 << 7));
 return inb(0x71);
}

variable_types:
port
unsigned char


decompiled_code:
// positive sp value has been detected, the output may be wrong!
void __fastcall do_rtc(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // r10
__int64 v9; // r11
struct tm v10; // [rsp-90h] [rbp-B8h] BYREF
__int64 v11; // [rsp-58h] [rbp-80h]
__int64 v12; // [rsp-50h] [rbp-78h]
__int64 v13; // [rsp-48h] [rbp-70h]
__int64 v14; // [rsp-40h] [rbp-68h]
__int64 v15; // [rsp-38h] [rbp-60h]
__int64 v16; // [rsp-30h] [rbp-58h]

v16 = 0LL;
v15 = v6;
v14 = a4;
v13 = a3;
v12 = v7;
v11 = a2;
v10.tm_zone = a1;
v10.tm_gmtoff = a5;
*(_QWORD *)&v10.tm_isdst = a6;
*(_QWORD *)&v10.tm_wday = v8;
*(_QWORD *)&v10.tm_mon = v9;
rtc_read(12);
if ( ++hznum == 1024 )
{
hznum = 0;
++unixtime;
if ( __ROR8__(0xFEDCBA987654321LL * unixtime, 4) > 0x123456789ABCDFuLL )
{
rtc_get_tm();
unixtime = mktime(&v10);
}
}
lapic_eoi();
__asm { iretq }
JUMPOUT(0x2DBLL);
}

original_code:
__attribute__((aligned(16))) static void do_rtc(struct intr_frame r)
{
 asm volatile( "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "nop; nop; nop; nop;" "pushq $0\n\t" "pushq %rax\n\t" "pushq %rcx\n\t" "pushq %rdx\n\t" "pushq %rbx\n\t" "pushq %rsi\n\t" "pushq %rdi\n\t" "pushq %r8\n\t" "pushq %r9\n\t" "pushq %r10\n\t" "pushq %r11\n\t" "subq $16, %rsp\n\t" "cld\n\t" );
 struct tm tim;
 rtc_read(0xc);
 hznum++;
 if (hznum == 1024) {
  hznum = 0;
  unixtime++;
  if (unixtime % 3600) {
   rtc_get_tm(&tim);
   unixtime = mktime(&tim);
  }
 }
 lapic_eoi();
 asm volatile( "addq $16, %rsp\n\t" "popq %r11\n\t" "popq %r10\n\t" "popq %r9\n\t" "popq %r8\n\t" "popq %rdi\n\t" "popq %rsi\n\t" "popq %rbx\n\t" "popq %rdx\n\t" "popq %rcx\n\t" "popq %rax\n\t" "addq $8, %rsp\n\t" "iretq\n\t" );
}

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

variable_types: struct tm { short tm_sec; short tm_min; short tm_hour; short tm_mday; short tm_mon; short tm_year; short tm_wday; short tm_yday; short tm_isdst; }


decompiled_code:
__int64 init_rtc()
{
unsigned __int8 v0; // al
__int16 v2[20]; // [rsp+0h] [rbp-28h] BYREF

intr_install_handler(8LL, do_rtc);
interrupts_disable();
rtc_read(11);
rtc_write_constprop_0(v0 | 0x46u);
interrupts_enable();
msleep_constprop_0();
rtc_get_tm();
unixtime = mktime((struct tm *)v2);
return kprintf(
"System clock set to: %d-%d-%d %d:%d:%d (unix: %lld)\n",
(unsigned int)v2[5],
(unsigned int)v2[4],
(unsigned int)v2[3],
(unsigned int)v2[2],
(unsigned int)v2[1],
(unsigned int)v2[0],
unixtime);
}

canonical_decompiled_code:
__int64 func15()
{
unsigned __int8 v0; // al
__int16 v2[20]; // [rsp+0h] [rbp-28h] BYREF

intr_install_handler(8LL, do_rtc);
func3();
func12(11);
func6(v0 | 0x46u);
func4();
func8();
func13();
unixtime = mktime((struct tm *)v2);
return kprintf(
"System clock set to: %d-%d-%d %d:%d:%d (unix: %lld)\n",
(unsigned int)v2[5],
(unsigned int)v2[4],
(unsigned int)v2[3],
(unsigned int)v2[2],
(unsigned int)v2[1],
(unsigned int)v2[0],
unixtime);
}

original_code:
void init_rtc(void)
{
 struct tm tim;
 intr_install_handler(8, do_rtc);
 interrupts_disable();
 rtc_write(0xb, rtc_read(0xb) | 0b1000110);
 interrupts_enable();
 msleep(500);
 rtc_get_tm(&tim);
 unixtime = mktime(&tim);
 kprintf("System clock set to: %d-%d-%d %d:%d:%d (unix: %lld)\n",
  tim.tm_year, tim.tm_mon, tim.tm_mday, tim.tm_hour, tim.tm_min,
  tim.tm_sec, unixtime);
 return;
}

canonical_original_code:
void init_rtc()
{
 struct tm tim;
 intr_install_handler(8, do_rtc);
 interrupts_disable();
 rtc_write(0xb, rtc_read(0xb) | 0b1000110);
 interrupts_enable();
 msleep(500);
 rtc_get_tm(&tim);
 unixtime = mktime(&tim);
 kprintf("System clock set to: %d-%d-%d %d:%d:%d (unix: %lld)\n",
  tim.tm_year, tim.tm_mon, tim.tm_mday, tim.tm_hour, tim.tm_min,
  tim.tm_sec, unixtime);
 return;
}

user_defined_types: struct tm { short tm_sec; short tm_min; short tm_hour; short tm_mday; short tm_mon; short tm_year; short tm_wday; short tm_yday; short tm_isdst; }


decompiled_code:
bool __fastcall list_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8) == a1;
}

original_code:
static inline u8 list_empty(const struct list_head *head)
{
 return head->next == head;
}

canonical_original_code:
static inline unsigned char list_empty(struct list_head *head)
{
 return head->next == head;
}

variable_types: struct list_head { struct list_head *prev; } *


decompiled_code:
__int64 __fastcall num2power(unsigned __int64 a1)
{
__int64 result; // rax
unsigned __int64 v2; // rdi

result = 0LL;
if ( a1 > 1 )
{
v2 = (a1 - 1) >> 1;
if ( v2 )
{
LODWORD(result) = 1;
do
{
result = (unsigned int)(result + 1);
v2 >>= 1;
}
while ( v2 );
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
__int64 result; // rax
unsigned __int64 v2; // rdi

result = 0LL;
if ( a1 > 1 )
{
v2 = (a1 - 1) >> 1;
if ( v2 )
{
LODWORD(result) = 1;
do
{
result = (unsigned int)(result + 1);
v2 >>= 1;
}
while ( v2 );
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
static inline u64 num2power(u64 x)
{
 unsigned power = 1;
 if (x == 0 || x == 1)
  return 0;
 x--;
 while (x >>= 1)
  power++;
 return power;
}

canonical_original_code:
static inline unsigned long num2power(unsigned long x)
{
 unsigned int power = 1;
 if (x == 0 || x == 1)
  return 0;
 x--;
 while (x >>= 1)
  power++;
 return power;
}

variable_types:
x
unsigned long

variable_types:
power
unsigned int


decompiled_code:
__int64 __fastcall kma_blocksizes_idx(char a1)
{
unsigned int v1; // er8
unsigned int i; // eax
char v3; // dl

if ( 0x4000u >> a1 )
return 0LL;
v1 = 1;
for ( i = 0x8000; ; i = blocksizes[v3] )
{
v3 = v1 + 1;
if ( i >> a1 )
break;
++v1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
unsigned int v1; // er8
unsigned int i; // eax
char v3; // dl

if ( 0x4000u >> a1 )
return 0LL;
v1 = 1;
for ( i = 0x8000; ; i = blocksizes[v3] )
{
v3 = v1 + 1;
if ( i >> a1 )
break;
++v1;
}
return v1;
}

original_code:
static u8 kma_blocksizes_idx(u8 power)
{
 s8 i = 0;
 while (blocksizes[i] < (1 << power))
  i++;
 return i;
}

canonical_original_code:
static unsigned char kma_blocksizes_idx(unsigned char power)
{
 char i = 0;
 while (blocksizes[i] < (1 << power))
  i++;
 return i;
}

variable_types:
power
unsigned char

variable_types: i char


decompiled_code:
__int64 kma_free_page()
{
--*((_WORD *)&kma + 8);
return free_page();
}

canonical_decompiled_code:
__int64 func5()
{
--*((_WORD *)&kma + 8);
return free_page();
}

original_code:
static inline void kma_free_page(void *addr)
{
 kma.npages--;
 free_page(addr);
}

variable_types:
addr
void *


decompiled_code:
__int64 __fastcall bitscan_right(__int64 _RDI)
{
__int64 result; // rax

if ( !_RDI )
return 0xFFFFFFFFLL;
__asm { tzcnt rax, rdi }
return result;
}

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

if ( !_RDI )
return 0xFFFFFFFFLL;
__asm { tzcnt rax, rdi }
return result;
}

original_code:
inline static s8 bitscan_right(u64 word)
{
 if (word == 0)
  return -1;
 return __builtin_ctzl(word);
}

canonical_original_code:
inline static char bitscan_right(unsigned long word)
{
 if (word == 0)
  return -1;
 return __builtin_ctzl(word);
}

variable_types:
word
unsigned long


decompiled_code:
char *kma_early_alloc_next_busy()
{
char v0; // al
unsigned __int64 v1; // rbx
__int64 v2; // rdx

if ( kma_early_init_done )
return (char *)kcache_alloc(busy_block_cache);
v0 = bitscan_right(~bblock_bmask);
v1 = v0;
if ( v0 == -1 )
kpanic("Oops! kma memory exhausted :(\n");
bitset_constprop_0(v1);
return (char *)&bblock + 8 * v2;
}

canonical_decompiled_code:
char *func7()
{
char v0; // al
unsigned __int64 v1; // rbx
__int64 v2; // rdx

if ( kma_early_init_done )
return (char *)kcache_alloc(busy_block_cache);
v0 = func6(~bblock_bmask);
v1 = v0;
if ( v0 == -1 )
kpanic("Oops! kma memory exhausted :(\n");
bitset_constprop_0(v1);
return (char *)&bblock + 8 * v2;
}

original_code:
static void *kma_early_alloc_next_busy(void)
{
 s8 bit;
 if (kma_early_init_done)
  return kcache_alloc(busy_block_cache);
 bit = bitscan_right(~bblock_bmask);
 if (bit == -1)
  kpanic("Oops! kma memory exhausted :(\n");
 bitset(&bblock_bmask, bit);
 return &bblock[bit];
}

canonical_original_code:
static void *kma_early_alloc_next_busy()
{
 char bit;
 if (kma_early_init_done)
  return kcache_alloc(busy_block_cache);
 bit = bitscan_right(~bblock_bmask);
 if (bit == -1)
  kpanic("Oops! kma memory exhausted :(\n");
 bitset(&bblock_bmask, bit);
 return &bblock[bit];
}

variable_types: bit char