decompiled_code:
__int64 validate_e820h_struct()
{
unsigned int *v0; // rbx
__int64 v1; // rbp
const char *v2; // rax
__int64 v3; // rsi
__int64 v4; // rdx
const char *v5; // rdi
unsigned int v6; // eax
unsigned int v7; // er9
__int64 result; // rax
const char *v9; // rax

if ( MEMORY[0xFFFF800000001000] == 1129665605 )
{
v0 = (unsigned int *)0xFFFF800000001004LL;
v1 = MEMORY[0xFFFF800000001004];
if ( MEMORY[0xFFFF800000001004] != -1 )
{
while ( 1 )
{
v2 = e820_typestr(v0[5]);
v3 = *(_QWORD *)(v0 + 1);
v4 = *(_QWORD *)(v0 + 3);
v0 = (unsigned int *)((char *)v0 + v1 + 4);
printk("Memory: E820 range: 0x%lx - 0x%lx (%s)\n", v3, v3 + v4, v2);
v1 = *v0;
if ( (_DWORD)v1 == -1 )
break;
if ( (unsigned __int64)v0 > 0xFFFF800000001FFFLL )
goto LABEL_11;
}
}
LODWORD(v5) = v0[1];
if ( !(_DWORD)v5 )
{
v6 = e820_checksum_constprop_0((int)v0 - 4088);
if ( v7 == v6 )
{
if ( (unsigned __int64)(v0 + 3) <= 0xFFFF800000002000LL )
{
result = 0xFFFF800000001000LL;
MEMORY[0xFFFF800000001000] = 1447119940;
return result;
}
panic("%s:%d - !(entry <= (uint32_t *)E820_MAX)\n", "mm/e820.c", 82LL);
LABEL_11:
v6 = panic("E820h - Unterminated buffer structure");
}
v5 = "E820h error - calculated checksum = 0x%lx, found checksum = 0x%lx\n";
panic("E820h error - calculated checksum = 0x%lx, found checksum = 0x%lx\n", v6, v7);
}
v9 = e820_errstr((unsigned int)v5);
panic("E820h error - %s", v9);
}
panic("E820h - Invalid buffer start signature");
return e820_sanitize_range();
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int *v0; // rbx
__int64 v1; // rbp
const char *v2; // rax
__int64 v3; // rsi
__int64 v4; // rdx
const char *v5; // rdi
unsigned int v6; // eax
unsigned int v7; // er9
__int64 result; // rax
const char *v9; // rax

if ( MEMORY[0xFFFF800000001000] == 1129665605 )
{
v0 = (unsigned int *)0xFFFF800000001004LL;
v1 = MEMORY[0xFFFF800000001004];
if ( MEMORY[0xFFFF800000001004] != -1 )
{
while ( 1 )
{
v2 = func1(v0[5]);
v3 = *(_QWORD *)(v0 + 1);
v4 = *(_QWORD *)(v0 + 3);
v0 = (unsigned int *)((char *)v0 + v1 + 4);
printk("Memory: E820 range: 0x%lx - 0x%lx (%s)\n", v3, v3 + v4, v2);
v1 = *v0;
if ( (_DWORD)v1 == -1 )
break;
if ( (unsigned __int64)v0 > 0xFFFF800000001FFFLL )
goto LABEL_11;
}
}
LODWORD(v5) = v0[1];
if ( !(_DWORD)v5 )
{
v6 = func3((int)v0 - 4088);
if ( v7 == v6 )
{
if ( (unsigned __int64)(v0 + 3) <= 0xFFFF800000002000LL )
{
result = 0xFFFF800000001000LL;
MEMORY[0xFFFF800000001000] = 1447119940;
return result;
}
panic("%s:%d - !(entry <= (uint32_t *)E820_MAX)\n", "mm/e820.c", 82LL);
LABEL_11:
v6 = panic("E820h - Unterminated buffer structure");
}
v5 = "E820h error - calculated checksum = 0x%lx, found checksum = 0x%lx\n";
panic("E820h error - calculated checksum = 0x%lx, found checksum = 0x%lx\n", v6, v7);
}
v9 = func0((unsigned int)v5);
panic("E820h error - %s", v9);
}
panic("E820h - Invalid buffer start signature");
return func5();
}

original_code:
static void validate_e820h_struct(void)
{
 uint32_t *entry, entry_len, err, chksum1, chksum2;
 struct e820_range *range;
 entry = ({ do { if (__builtin_expect((!((uintptr_t)(0x1000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 52); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0x1000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 52); } while (0);; (void *)((char *)(0x1000) + 0xffff800000000000ULL); });
 if (*entry != ('C'<<(3*8) | 'U'<<(2*8) | 'T'<<(1*8) | 'E'))
  panic("E820h - Invalid buffer start signature");
 entry++;
 while (*entry != 0xffffffff) {
  if (entry >= (uint32_t *)({ do { if (__builtin_expect((!((uintptr_t)((0x1000 + 0x1000)) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)((0x1000 + 0x1000)) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)((0x1000 + 0x1000)) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)((0x1000 + 0x1000)) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 58); } while (0);; (void *)((char *)((0x1000 + 0x1000)) + 0xffff800000000000ULL); }))
   panic("E820h - Unterminated buffer structure");
  entry_len = *entry++;
  range = (struct e820_range *)entry;
  printk("Memory: E820 range: 0x%lx - 0x%lx (%s)\n", range->base,
         range->base + range->len, e820_typestr(range->type));
  entry = (uint32_t *)((char *)entry + entry_len);
 }
 entry++;
 err = *entry;
 if (err != 0x0)
  panic("E820h error - %s", e820_errstr(err));
 entry++;
 chksum2 = *entry;
 chksum1 = e820_checksum(({ do { if (__builtin_expect((!((uintptr_t)(0x1000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 76); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0x1000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 76); } while (0);; (void *)((char *)(0x1000) + 0xffff800000000000ULL); }), (char *)entry - (char *)({ do { if (__builtin_expect((!((uintptr_t)(0x1000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 76); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0x1000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 76); } while (0);; (void *)((char *)(0x1000) + 0xffff800000000000ULL); }));
 if (chksum1 != chksum2)
  panic("E820h error - calculated checksum = 0x%lx, "
        "found checksum = 0x%lx\n", chksum1, chksum2);
 entry++;
 do { if (__builtin_expect((!(entry <= (uint32_t *)({ do { if (__builtin_expect((!((uintptr_t)((0x1000 + 0x1000)) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)((0x1000 + 0x1000)) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 82); } while (0);; do { if (__builtin_expect((!((uintptr_t)((0x1000 + 0x1000)) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)((0x1000 + 0x1000)) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 82); } while (0);; (void *)((char *)((0x1000 + 0x1000)) + 0xffff800000000000ULL); }))), 0)) panic("%s:%d - !(" "entry <= (uint32_t *)E820_MAX" ")\n", "mm/e820.c", 82); } while (0);;
 entry = ({ do { if (__builtin_expect((!((uintptr_t)(0x1000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 85); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0x1000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 85); } while (0);; (void *)((char *)(0x1000) + 0xffff800000000000ULL); });
 *entry = ('V'<<(3*8) | 'A'<<(2*8) | 'L'<<(1*8) | 'D');
}

canonical_original_code:
static void validate_e820h_struct()
{
 unsigned int *entry; unsigned int entry_len; unsigned int err; unsigned int chksum1; unsigned int chksum2;
 struct e820_range *range;
 entry = ({ do { if (__builtin_expect((!((unsigned long)(0x1000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 52); } while (0);; do { if (__builtin_expect((!((unsigned long)(0x1000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 52); } while (0);; (void *)((char *)(0x1000) + 0xffff800000000000ULL); });
 if (*entry != ('C'<<(3*8) | 'U'<<(2*8) | 'T'<<(1*8) | 'E'))
  panic("E820h - Invalid buffer start signature");
 entry++;
 while (*entry != 0xffffffff) {
  if (entry >= (unsigned int *)({ do { if (__builtin_expect((!((unsigned long)((0x1000 + 0x1000)) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)((0x1000 + 0x1000)) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 58); } while (0);; do { if (__builtin_expect((!((unsigned long)((0x1000 + 0x1000)) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)((0x1000 + 0x1000)) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 58); } while (0);; (void *)((char *)((0x1000 + 0x1000)) + 0xffff800000000000ULL); }))
   panic("E820h - Unterminated buffer structure");
  entry_len = *entry++;
  range = (struct e820_range *)entry;
  printk("Memory: E820 range: 0x%lx - 0x%lx (%s)\n", range->base,
         range->base + range->len, e820_typestr(range->type));
  entry = (unsigned int *)((char *)entry + entry_len);
 }
 entry++;
 err = *entry;
 if (err != 0x0)
  panic("E820h error - %s", e820_errstr(err));
 entry++;
 chksum2 = *entry;
 chksum1 = e820_checksum(({ do { if (__builtin_expect((!((unsigned long)(0x1000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 76); } while (0);; do { if (__builtin_expect((!((unsigned long)(0x1000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 76); } while (0);; (void *)((char *)(0x1000) + 0xffff800000000000ULL); }), (char *)entry - (char *)({ do { if (__builtin_expect((!((unsigned long)(0x1000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 76); } while (0);; do { if (__builtin_expect((!((unsigned long)(0x1000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 76); } while (0);; (void *)((char *)(0x1000) + 0xffff800000000000ULL); }));
 if (chksum1 != chksum2)
  panic("E820h error - calculated checksum = 0x%lx, "
        "found checksum = 0x%lx\n", chksum1, chksum2);
 entry++;
 do { if (__builtin_expect((!(entry <= (unsigned int *)({ do { if (__builtin_expect((!((unsigned long)((0x1000 + 0x1000)) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)((0x1000 + 0x1000)) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 82); } while (0);; do { if (__builtin_expect((!((unsigned long)((0x1000 + 0x1000)) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)((0x1000 + 0x1000)) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 82); } while (0);; (void *)((char *)((0x1000 + 0x1000)) + 0xffff800000000000ULL); }))), 0)) panic("%s:%d - !(" "entry <= (uint32_t *)E820_MAX" ")\n", "mm/e820.c", 82); } while (0);;
 entry = ({ do { if (__builtin_expect((!((unsigned long)(0x1000) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) >= KERN_PHYS_OFFSET" ")\n", "mm/e820.c", 85); } while (0);; do { if (__builtin_expect((!((unsigned long)(0x1000) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x1000) < KERN_PHYS_END_MAX" ")\n", "mm/e820.c", 85); } while (0);; (void *)((char *)(0x1000) + 0xffff800000000000ULL); });
 *entry = ('V'<<(3*8) | 'A'<<(2*8) | 'L'<<(1*8) | 'D');
}

variable_types:
entry
unsigned int *

variable_types:
err
unsigned int

variable_types: struct e820_range { unsigned long base; unsigned long len; unsigned int type; } *


repo: a-darwish/cuteOS

decompiled_code:
int *e820_get_memory_setup()
{
if ( memory_setup == 1 )
return &memory_setup;
panic("%s:%d - !(memory_setup.valid == 1)\n", "mm/e820.c", 159LL);
return (int *)e820_get_phys_addr_end();
}

canonical_decompiled_code:
int *func6()
{
if ( memory_setup == 1 )
return &memory_setup;
panic("%s:%d - !(memory_setup.valid == 1)\n", "mm/e820.c", 159LL);
return (int *)func7();
}

original_code:
struct e820_setup *e820_get_memory_setup(void)
{
 do { if (__builtin_expect((!(memory_setup.valid == 1)), 0)) panic("%s:%d - !(" "memory_setup.valid == 1" ")\n", "mm/e820.c", 159); } while (0);;
 return &memory_setup;
}

canonical_original_code:
struct e820_setup *e820_get_memory_setup()
{
 do { if (__builtin_expect((!(memory_setup.valid == 1)), 0)) panic("%s:%d - !(" "memory_setup.valid == 1" ")\n", "mm/e820.c", 159); } while (0);;
 return &memory_setup;
}

return_type: struct e820_setup { int valid; unsigned long avail_pages; unsigned long avail_ranges; unsigned long phys_addr_end; } *


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

if ( memory_setup != 1 )
{
panic("%s:%d - !(memory_setup.valid == 1)\n", "mm/e820.c", 166LL);
goto LABEL_5;
}
result = qword_478;
if ( !qword_478 )
{
LABEL_5:
panic("%s:%d - !(memory_setup.phys_addr_end)\n", "mm/e820.c", 167LL);
result = e820_init();
}
return result;
}

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

if ( memory_setup != 1 )
{
panic("%s:%d - !(memory_setup.valid == 1)\n", "mm/e820.c", 166LL);
goto LABEL_5;
}
result = qword_478;
if ( !qword_478 )
{
LABEL_5:
panic("%s:%d - !(memory_setup.phys_addr_end)\n", "mm/e820.c", 167LL);
result = func8();
}
return result;
}

original_code:
uint64_t e820_get_phys_addr_end(void)
{
 do { if (__builtin_expect((!(memory_setup.valid == 1)), 0)) panic("%s:%d - !(" "memory_setup.valid == 1" ")\n", "mm/e820.c", 166); } while (0);;
 do { if (__builtin_expect((!(memory_setup.phys_addr_end)), 0)) panic("%s:%d - !(" "memory_setup.phys_addr_end" ")\n", "mm/e820.c", 167); } while (0);;
 return memory_setup.phys_addr_end;
}

canonical_original_code:
unsigned long e820_get_phys_addr_end()
{
 do { if (__builtin_expect((!(memory_setup.valid == 1)), 0)) panic("%s:%d - !(" "memory_setup.valid == 1" ")\n", "mm/e820.c", 166); } while (0);;
 do { if (__builtin_expect((!(memory_setup.phys_addr_end)), 0)) panic("%s:%d - !(" "memory_setup.phys_addr_end" ")\n", "mm/e820.c", 167); } while (0);;
 return memory_setup.phys_addr_end;
}

return_type: unsigned long


decompiled_code:
__int64 e820_init()
{
validate_e820h_struct();
return build_memory_setup();
}

canonical_decompiled_code:
__int64 func8()
{
func4();
return func2();
}

original_code:
void e820_init(void)
{
 validate_e820h_struct();
 build_memory_setup();
}

canonical_original_code:
void e820_init()
{
 validate_e820h_struct();
 build_memory_setup();
}

return_type: void


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

a1[1] = 0LL;
result = *a1 & 0xFF00000000000000LL;
*a1 = result | (a2 >> 12) | 0x90000000000000LL;
return result;
}

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

a1[1] = 0LL;
result = *a1 & 0xFF00000000000000LL;
*a1 = result | (a2 >> 12) | 0x90000000000000LL;
return result;
}

original_code:
static inline void page_init(struct page *page, uintptr_t phys_addr)
{
 page->pfn = phys_addr >> 12;
 page->free = 1;
 page->in_bucket = 0;
 page->zone_id = ZONE_UNASSIGNED;
 page->next = ((void *)0);
}

canonical_original_code:
static inline void page_init(struct page *page, unsigned long phys_addr)
{
 page->pfn = phys_addr >> 12;
 page->free = 1;
 page->in_bucket = 0;
 page->zone_id = ZONE_UNASSIGNED;
 page->next = ((void *)0);
}

variable_types: struct page { unsigned long pfn; union { struct page *next; unsigned char bucket_idx; }; } *


decompiled_code:
__int64 __fastcall page_phys_addr(_QWORD *a1)
{
return *a1 << 12;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
return *a1 << 12;
}

original_code:
static inline uintptr_t page_phys_addr(struct page *page)
{
 return (uintptr_t)page->pfn << 12;
}

canonical_original_code:
static inline unsigned long page_phys_addr(struct page *page)
{
 return (unsigned long)page->pfn << 12;
}

user_defined_types: struct page { unsigned long pfn; union { struct page *next; unsigned char bucket_idx; }; }


decompiled_code:
int *__fastcall get_zone(unsigned int a1)
{
if ( a1 <= 1 )
return &zones[18 * a1];
panic("Memory - invalid zone id = %d", a1);
return (int *)page_address();
}

canonical_decompiled_code:
int *__fastcall func2(unsigned int a1)
{
if ( a1 <= 1 )
return &zones[18 * a1];
panic("Memory - invalid zone id = %d", a1);
return (int *)func3();
}

original_code:
static inline struct zone *get_zone(enum zone_id zid)
{
 if (zid != ZONE_1GB && zid != ZONE_ANY)
  panic("Memory - invalid zone id = %d", zid);
 return &zones[zid];
}

return_type: struct zone { enum zone_id { ZONE_1GB=0, ZONE_ANY=1, ZONE_UNASSIGNED=2 } id; unsigned long start; unsigned long end; char *description; struct page { unsigned long pfn; union { struct page *next; unsigned char bucket_idx; }; } *freelist; struct lock_spin { unsigned int val; union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; } rflags; } freelist_lock; unsigned long freepages_count; unsigned long boot_freepages; } *

user_defined_types: struct zone { enum zone_id id; unsigned long start; unsigned long end; char *description; struct page *freelist; struct lock_spin freelist_lock; unsigned long freepages_count; unsigned long boot_freepages; }

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


decompiled_code:
__int64 __fastcall page_address(_QWORD *a1)
{
unsigned __int64 v1; // rax

v1 = *a1 << 12;
if ( v1 <= 0x3FFFFFFFFFFFLL )
return v1 - 0x800000000000LL;
panic("%s:%d - !((uintptr_t)((uintptr_t)page->pfn << 12) < KERN_PHYS_END_MAX)\n", "include/mm.h", 139LL);
return rmap_add_range();
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
unsigned __int64 v1; // rax

v1 = *a1 << 12;
if ( v1 <= 0x3FFFFFFFFFFFLL )
return v1 - 0x800000000000LL;
panic("%s:%d - !((uintptr_t)((uintptr_t)page->pfn << 12) < KERN_PHYS_END_MAX)\n", "include/mm.h", 139LL);
return func4();
}

original_code:
static inline void *page_address(struct page *page)
{
 return ({ do { if (__builtin_expect((!((uintptr_t)((uintptr_t)page->pfn << 12) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)((uintptr_t)page->pfn << 12) >= KERN_PHYS_OFFSET" ")\n", "include/mm.h", 139); } while (0);; do { if (__builtin_expect((!((uintptr_t)((uintptr_t)page->pfn << 12) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)((uintptr_t)page->pfn << 12) < KERN_PHYS_END_MAX" ")\n", "include/mm.h", 139); } while (0);; (void *)((char *)((uintptr_t)page->pfn << 12) + 0xffff800000000000ULL); });
}

canonical_original_code:
static inline void *page_address(struct page *page)
{
 return ({ do { if (__builtin_expect((!((unsigned long)((unsigned long)page->pfn << 12) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)((uintptr_t)page->pfn << 12) >= KERN_PHYS_OFFSET" ")\n", "include/mm.h", 139); } while (0);; do { if (__builtin_expect((!((unsigned long)((unsigned long)page->pfn << 12) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)((uintptr_t)page->pfn << 12) < KERN_PHYS_END_MAX" ")\n", "include/mm.h", 139); } while (0);; (void *)((char *)((unsigned long)page->pfn << 12) + 0xffff800000000000ULL); });
}

return_type: void *


decompiled_code:
__int64 __fastcall rmap_add_range(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx

result = pfdrmap_top;
if ( pfdrmap_top + 32 > (unsigned __int64)pfdrmap_end )
{
panic("%s:%d - !(rmap + 1 <= pfdrmap_end)\n", "mm/page_alloc.c", 288LL);
result = page_assign_zone();
}
else
{
v3 = *a1;
pfdrmap_top += 32LL;
*(_QWORD *)result = v3;
*(_QWORD *)(result + 8) = a1[1];
LODWORD(v3) = *((_DWORD *)a1 + 4);
*(_QWORD *)(result + 24) = a2;
*(_DWORD *)(result + 16) = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx

result = pfdrmap_top;
if ( pfdrmap_top + 32 > (unsigned __int64)pfdrmap_end )
{
panic("%s:%d - !(rmap + 1 <= pfdrmap_end)\n", "mm/page_alloc.c", 288LL);
result = page_assign_zone();
}
else
{
v3 = *a1;
pfdrmap_top += 32LL;
*(_QWORD *)result = v3;
*(_QWORD *)(result + 8) = a1[1];
LODWORD(v3) = *((_DWORD *)a1 + 4);
*(_QWORD *)(result + 24) = a2;
*(_DWORD *)(result + 16) = v3;
}
return result;
}

original_code:
static void rmap_add_range(struct e820_range *range,
      struct page *start)
{
 struct rmap *rmap;
 rmap = pfdrmap_top;
 do { if (__builtin_expect((!(rmap + 1 <= pfdrmap_end)), 0)) panic("%s:%d - !(" "rmap + 1 <= pfdrmap_end" ")\n", "mm/page_alloc.c", 288); } while (0);;
 rmap->range = *range;
 rmap->pfd_start = start;
 pfdrmap_top = rmap + 1;
}

variable_types: struct rmap { struct e820_range { unsigned long base; unsigned long len; unsigned int type; } range; struct page { unsigned long pfn; union { struct page *next; unsigned char bucket_idx; }; } *pfd_start; } *

user_defined_types: struct rmap { struct e820_range range; struct page *pfd_start; }


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

qword_940 = 0LL;
spin_init(&unk_948);
qword_958 = 0LL;
qword_960 = 0LL;
qword_988 = 0LL;
result = spin_init(&unk_990);
qword_9A0 = 0LL;
qword_9A8 = 0LL;
return result;
}

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

qword_940 = 0LL;
spin_init(&unk_948);
qword_958 = 0LL;
qword_960 = 0LL;
qword_988 = 0LL;
result = spin_init(&unk_990);
qword_9A0 = 0LL;
qword_9A8 = 0LL;
return result;
}

original_code:
static inline void zones_init(void)
{
 struct zone *zone;
 for (zone = &zones[0]; zone <= &zones[ZONE_ANY]; zone++) {
  zone->freelist = ((void *)0);
  spin_init(&zone->freelist_lock);
  zone->freepages_count = 0;
  zone->boot_freepages = 0;
 }
}

canonical_original_code:
static inline void zones_init()
{
 struct zone *zone;
 for (zone = &zones[0]; zone <= &zones[ZONE_ANY]; zone++) {
  zone->freelist = ((void *)0);
  spin_init(&zone->freelist_lock);
  zone->freepages_count = 0;
  zone->boot_freepages = 0;
 }
}

variable_types: struct zone { enum zone_id { ZONE_1GB=0, ZONE_ANY=1, ZONE_UNASSIGNED=2 } id; unsigned long start; unsigned long end; char *description; struct page { unsigned long pfn; union { struct page *next; unsigned char bucket_idx; }; } *freelist; struct lock_spin { unsigned int val; union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; } rflags; } freelist_lock; unsigned long freepages_count; unsigned long boot_freepages; } *


decompiled_code:
__int64 __fastcall free_page(__int64 a1)
{
int *v1; // rax
int *v2; // r12
int *v3; // rbx
char v4; // al
__int64 result; // rax
__int64 v6; // rax

v1 = get_zone(*(_BYTE *)(a1 + 6) >> 6);
v2 = v1 + 10;
v3 = v1;
spin_lock(v1 + 10);
*(_QWORD *)(a1 + 8) = *((_QWORD *)v3 + 4);
v4 = *(_BYTE *)(a1 + 6);
++*((_QWORD *)v3 + 7);
*((_QWORD *)v3 + 4) = a1;
if ( (v4 & 0x10) != 0 )
{
v6 = page_address((_QWORD *)a1);
panic("Memory - Freeing already free page at 0x%lx\n", v6);
result = addr_to_page();
}
else
{
*(_BYTE *)(a1 + 6) = v4 | 0x10;
result = spin_unlock(v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int *v1; // rax
int *v2; // r12
int *v3; // rbx
char v4; // al
__int64 result; // rax
__int64 v6; // rax

v1 = func2(*(_BYTE *)(a1 + 6) >> 6);
v2 = v1 + 10;
v3 = v1;
spin_lock(v1 + 10);
*(_QWORD *)(a1 + 8) = *((_QWORD *)v3 + 4);
v4 = *(_BYTE *)(a1 + 6);
++*((_QWORD *)v3 + 7);
*((_QWORD *)v3 + 4) = a1;
if ( (v4 & 0x10) != 0 )
{
v6 = func3((_QWORD *)a1);
panic("Memory - Freeing already free page at 0x%lx\n", v6);
result = func9();
}
else
{
*(_BYTE *)(a1 + 6) = v4 | 0x10;
result = spin_unlock(v2);
}
return result;
}

original_code:
void free_page(struct page *page)
{
 struct zone *zone;
 zone = get_zone(page->zone_id);
 spin_lock(&zone->freelist_lock);
 page->next = zone->freelist;
 zone->freelist = page;
 zone->freepages_count++;
 if (page->free != 0)
  panic("Memory - Freeing already free page at 0x%lx\n",
        page_address(page));
 page->free = 1;
 spin_unlock(&zone->freelist_lock);
}

user_defined_types: enum zone_id { ZONE_1GB=0, ZONE_ANY=1, ZONE_UNASSIGNED=2 }

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


decompiled_code:
_BOOL8 __fastcall page_is_free(__int64 a1)
{
return (*(_BYTE *)(a1 + 6) & 0x10) != 0;
}

original_code:
static inline int page_is_free(struct page *page)
{
 return page->free;
}

return_type: int


decompiled_code:
void __fastcall sign_buf(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 8) = a2;
}

original_code:
static inline void sign_buf(void *buf, uint32_t signature)
{
 buf = (char *)buf + sizeof(void *);
 *(uint32_t *)buf = signature;
}

canonical_original_code:
static inline void sign_buf(void *buf, unsigned int signature)
{
 buf = (char *)buf + sizeof(void *);
 *(unsigned int *)buf = signature;
}

variable_types:
buf
void *

variable_types:
signature
unsigned int


original_code:
static inline int is_free_buf(void *buf)
{
 buf = (char *)buf + sizeof(void *);
 if (*(uint32_t *)buf == 0xcafebabe)
  return 1;
 return 0;
}

canonical_original_code:
static inline int is_free_buf(void *buf)
{
 buf = (char *)buf + sizeof(void *);
 if (*(unsigned int *)buf == 0xcafebabe)
  return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall page_address(_QWORD *a1)
{
unsigned __int64 v1; // rax

v1 = *a1 << 12;
if ( v1 <= 0x3FFFFFFFFFFFLL )
return v1 - 0x800000000000LL;
panic("%s:%d - !((uintptr_t)((uintptr_t)page->pfn << 12) < KERN_PHYS_END_MAX)\n", "include/mm.h", 139LL);
return get_tokenized_page();
}


original_code:
static void *get_tokenized_page(int bucket_idx)
{
 struct page *page;
 char *buf, *start, *end;
 int buf_len;
 page = get_free_page(ZONE_ANY);
 page->in_bucket = 1;
 page->bucket_idx = bucket_idx;
 start = page_address(page);
 end = start + (1 << 12);
 buf = start;
 buf_len = 1 << bucket_idx;
 while (buf < (end - buf_len)) {
  *(void **)buf = buf + buf_len;
  sign_buf(buf, 0xcafebabe);
  buf += buf_len;
 }
 *(void **)buf = ((void *)0);
 sign_buf(buf, 0xcafebabe);
 return start;
}

canonical_original_code:
static void *get_tokenized_page(int bucket_idx)
{
 struct page *page;
 char *buf; char *start; char *end;
 int buf_len;
 page = get_free_page(ZONE_ANY);
 page->in_bucket = 1;
 page->bucket_idx = bucket_idx;
 start = page_address(page);
 end = start + (1 << 12);
 buf = start;
 buf_len = 1 << bucket_idx;
 while (buf < (end - buf_len)) {
  *(void **)buf = buf + buf_len;
  sign_buf(buf, 0xcafebabe);
  buf += buf_len;
 }
 *(void **)buf = ((void *)0);
 sign_buf(buf, 0xcafebabe);
 return start;
}

variable_types:
buf
char *

variable_types:
start
char *

variable_types:
end
char *


kfree

decompiled_code:
__int64 __fastcall kfree(__int64 a1)
{
__int64 v1; // rax
int v2; // ebx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rcx
char *v7; // rbp
__int64 v8; // rbx

v1 = addr_to_page();
v2 = *(unsigned __int8 *)(v1 + 8);
if ( page_is_free(v1) )
{
panic("Bucket: Freeing address 0x%lx which resides in an unallocated page frame", a1);
goto LABEL_7;
}
if ( (*(_BYTE *)(v3 + 6) & 0x20) != 0 )
{
v4 = (unsigned int)(1 << v2);
if ( (((int)v4 - 1) & (unsigned __int64)a1) != 0 )
{
LABEL_8:
panic("Bucket: Freeing invalidly-aligned 0x%lx address; bucket buffer size = 0x%lx\n", a1, v4);
goto LABEL_9;
}
if ( !is_free_buf(a1) )
{
sign_buf(a1, -889275714);
v7 = (char *)&kmembuckets + v6;
v8 = 4LL * v2;
spin_lock((char *)&kmembuckets + v6);
*(_QWORD *)a1 = qword_330[v8];
++*(_DWORD *)((char *)&kmembuckets + v8 * 8 + 28);
qword_330[v8] = a1;
return spin_unlock(v7);
}
LABEL_7:
panic("Bucket: Freeing already free buffer at 0x%lx, with size = 0x%lx bytes", a1, v5);
goto LABEL_8;
}
LABEL_9:
panic("Bucket: Freeing address 0x%lx which resides in a foreign page frame (not allocated by us)", a1);
return kmalloc_init();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rax
int v2; // ebx
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rcx
char *v7; // rbp
__int64 v8; // rbx

v1 = addr_to_page();
v2 = *(unsigned __int8 *)(v1 + 8);
if ( func0(v1) )
{
panic("Bucket: Freeing address 0x%lx which resides in an unallocated page frame", a1);
goto LABEL_7;
}
if ( (*(_BYTE *)(v3 + 6) & 0x20) != 0 )
{
v4 = (unsigned int)(1 << v2);
if ( (((int)v4 - 1) & (unsigned __int64)a1) != 0 )
{
LABEL_8:
panic("Bucket: Freeing invalidly-aligned 0x%lx address; bucket buffer size = 0x%lx\n", a1, v4);
goto LABEL_9;
}
if ( !func2(a1) )
{
func1(a1, -889275714);
v7 = (char *)&kmembuckets + v6;
v8 = 4LL * v2;
spin_lock((char *)&kmembuckets + v6);
*(_QWORD *)a1 = qword_330[v8];
++*(_DWORD *)((char *)&kmembuckets + v8 * 8 + 28);
qword_330[v8] = a1;
return spin_unlock(v7);
}
LABEL_7:
panic("Bucket: Freeing already free buffer at 0x%lx, with size = 0x%lx bytes", a1, v5);
goto LABEL_8;
}
LABEL_9:
panic("Bucket: Freeing address 0x%lx which resides in a foreign page frame (not allocated by us)", a1);
return func7();
}

original_code:
void kfree(void *addr)
{
 struct page *page;
 struct bucket *bucket;
 int buf_size;
 char *buf;
 buf = addr;
 page = addr_to_page(buf);
 bucket = &kmembuckets[page->bucket_idx];
 if (page_is_free(page))
  panic("Bucket: Freeing address 0x%lx which resides in "
        "an unallocated page frame", buf);
 if (!page->in_bucket)
  panic("Bucket: Freeing address 0x%lx which resides in "
        "a foreign page frame (not allocated by us)", buf);
 buf_size = 1 << page->bucket_idx;
 if (!((((uintptr_t)buf) & ((typeof((uintptr_t)buf))((buf_size) - 1))) == 0))
  panic("Bucket: Freeing invalidly-aligned 0x%lx address; "
        "bucket buffer size = 0x%lx\n", buf, buf_size);
 if (is_free_buf(buf))
  panic("Bucket: Freeing already free buffer at 0x%lx, "
        "with size = 0x%lx bytes", buf, buf_size);
 sign_buf(buf, 0xcafebabe);
 spin_lock(&bucket->lock);
 *(void **)buf = bucket->head;
 bucket->head = buf;
 bucket->totalfree++;
 spin_unlock(&bucket->lock);
}

canonical_original_code:
void kfree(void *addr)
{
 struct page *page;
 struct bucket *bucket;
 int buf_size;
 char *buf;
 buf = addr;
 page = addr_to_page(buf);
 bucket = &kmembuckets[page->bucket_idx];
 if (page_is_free(page))
  panic("Bucket: Freeing address 0x%lx which resides in "
        "an unallocated page frame", buf);
 if (!page->in_bucket)
  panic("Bucket: Freeing address 0x%lx which resides in "
        "a foreign page frame (not allocated by us)", buf);
 buf_size = 1 << page->bucket_idx;
 if (!((((unsigned long)buf) & ((typeof((unsigned long)buf))((buf_size) - 1))) == 0))
  panic("Bucket: Freeing invalidly-aligned 0x%lx address; "
        "bucket buffer size = 0x%lx\n", buf, buf_size);
 if (is_free_buf(buf))
  panic("Bucket: Freeing already free buffer at 0x%lx, "
        "with size = 0x%lx bytes", buf, buf_size);
 sign_buf(buf, 0xcafebabe);
 spin_lock(&bucket->lock);
 *(void **)buf = bucket->head;
 bucket->head = buf;
 bucket->totalfree++;
 spin_unlock(&bucket->lock);
}

variable_types:
addr
void *

variable_types: struct bucket { struct lock_spin { unsigned int val; union x86_rflags { unsigned long raw; struct { unsigned int carry_flag; unsigned int __reserved0_4; }; } rflags; } lock; void *head; int totalpages; int totalfree; } *

user_defined_types: struct bucket { struct lock_spin lock; void *head; int totalpages; int totalfree; }


decompiled_code:
__int64 kmalloc_init()
{
char *v0; // rbx
char *v1; // rdi
__int64 result; // rax

v0 = (char *)&kmembuckets;
do
{
v1 = v0;
v0 += 32;
result = spin_init(v1);
}
while ( v0 != "include/mm.h" );
return result;
}

canonical_decompiled_code:
__int64 func7()
{
char *v0; // rbx
char *v1; // rdi
__int64 result; // rax

v0 = (char *)&kmembuckets;
do
{
v1 = v0;
v0 += 32;
result = spin_init(v1);
}
while ( v0 != "include/mm.h" );
return result;
}

original_code:
void kmalloc_init(void)
{
 for (int i = 0; i <= 12; i++)
  spin_init(&kmembuckets[i].lock);
}

canonical_original_code:
void kmalloc_init()
{
 for (int i = 0; i <= 12; i++)
  spin_init(&kmembuckets[i].lock);
}

variable_types: i int


outb

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

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

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

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

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

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

variable_types:
val
unsigned char

variable_types:
port
unsigned short


decompiled_code:
__int64 __fastcall pit_set_counter(int a1, unsigned __int16 a2)
{
unsigned __int64 v2; // rax
unsigned int v3; // ecx

if ( a1 <= 0 )
{
panic("%s:%d - !(ms > 0)\n", "dev/pit.c", 142LL);
goto LABEL_6;
}
if ( !(1000 / a1) )
{
LABEL_6:
panic("%s:%d - !((1000 / ms) > 0)\n", "dev/pit.c", 143LL);
goto LABEL_7;
}
v2 = 0x1234DEuLL / (1000 / a1);
if ( v2 <= 0xFFFF )
{
outb((unsigned __int8)v2, a2);
return outb(v3 >> 8, a2);
}
LABEL_7:
panic("%s:%d - !(counter <= UINT16_MAX)\n", "dev/pit.c", 146LL);
return inb_constprop_0();
}

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

if ( a1 <= 0 )
{
panic("%s:%d - !(ms > 0)\n", "dev/pit.c", 142LL);
goto LABEL_6;
}
if ( !(1000 / a1) )
{
LABEL_6:
panic("%s:%d - !((1000 / ms) > 0)\n", "dev/pit.c", 143LL);
goto LABEL_7;
}
v2 = 0x1234DEuLL / (1000 / a1);
if ( v2 <= 0xFFFF )
{
func0((unsigned __int8)v2, a2);
return func0(v3 >> 8, a2);
}
LABEL_7:
panic("%s:%d - !(counter <= UINT16_MAX)\n", "dev/pit.c", 146LL);
return func2();
}

original_code:
static void pit_set_counter(int ms, int counter_reg)
{
 uint32_t counter;
 uint8_t counter_low, counter_high;
 do { if (__builtin_expect((!(ms > 0)), 0)) panic("%s:%d - !(" "ms > 0" ")\n", "dev/pit.c", 142); } while (0);;
 do { if (__builtin_expect((!((1000 / ms) > 0)), 0)) panic("%s:%d - !(" "(1000 / ms) > 0" ")\n", "dev/pit.c", 143); } while (0);;
 counter = 1193182ul / (1000 / ms);
 do { if (__builtin_expect((!(counter <= (0xffff))), 0)) panic("%s:%d - !(" "counter <= UINT16_MAX" ")\n", "dev/pit.c", 146); } while (0);;
 counter_low = counter & 0xff;
 counter_high = counter >> 8;
 outb(counter_low, counter_reg);
 outb(counter_high, counter_reg);
}

canonical_original_code:
static void pit_set_counter(int ms, int counter_reg)
{
 unsigned int counter;
 unsigned char counter_low; unsigned char counter_high;
 do { if (__builtin_expect((!(ms > 0)), 0)) panic("%s:%d - !(" "ms > 0" ")\n", "dev/pit.c", 142); } while (0);;
 do { if (__builtin_expect((!((1000 / ms) > 0)), 0)) panic("%s:%d - !(" "(1000 / ms) > 0" ")\n", "dev/pit.c", 143); } while (0);;
 counter = 1193182ul / (1000 / ms);
 do { if (__builtin_expect((!(counter <= (0xffff))), 0)) panic("%s:%d - !(" "counter <= UINT16_MAX" ")\n", "dev/pit.c", 146); } while (0);;
 counter_low = counter & 0xff;
 counter_high = counter >> 8;
 outb(counter_low, counter_reg);
 outb(counter_high, counter_reg);
}

variable_types: ms int

variable_types:
counter
unsigned int


decompiled_code:
__int64 timer2_stop()
{
unsigned __int8 v0; // al

v0 = inb_constprop_0();
return outb(v0 & 0xFE, 0x61u);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned __int8 v0; // al

v0 = func2();
return func0(v0 & 0xFE, 0x61u);
}

original_code:
static inline void timer2_stop(void)
{
 uint8_t val;
 val = inb(0x61) & ~PIT_GATE2;
 outb(val, 0x61);
}

canonical_original_code:
static inline void timer2_stop()
{
 unsigned char val;
 val = inb(0x61) & ~PIT_GATE2;
 outb(val, 0x61);
}


decompiled_code:
__int64 timer2_start()
{
unsigned __int8 v0; // al

v0 = inb_constprop_0();
return outb(v0 & 0xFD | 1u, 0x61u);
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int8 v0; // al

v0 = func2();
return func0(v0 & 0xFD | 1u, 0x61u);
}

original_code:
static inline void timer2_start(void)
{
 uint8_t val;
 val = (inb(0x61) | PIT_GATE2) & ~PIT_SPEAKER;
 outb(val, 0x61);
}

canonical_original_code:
static inline void timer2_start()
{
 unsigned char val;
 val = (inb(0x61) | PIT_GATE2) & ~PIT_SPEAKER;
 outb(val, 0x61);
}


decompiled_code:
unsigned __int8 __fastcall pit_mdelay(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er8
unsigned __int8 result; // al

timer2_stop(a1, a2, a3, a4, (unsigned int)a1);
outb(0xB0u, 0x43u);
pit_set_counter(v4, 0x42u);
timer2_start();
while ( 1 )
{
result = inb_constprop_0();
if ( (result & 0x20) != 0 )
break;
_mm_pause();
}
return result;
}

canonical_decompiled_code:
unsigned __int8 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er8
unsigned __int8 result; // al

func3(a1, a2, a3, a4, (unsigned int)a1);
func0(0xB0u, 0x43u);
func1(v4, 0x42u);
func4();
while ( 1 )
{
result = func2();
if ( (result & 0x20) != 0 )
break;
_mm_pause();
}
return result;
}

original_code:
void pit_mdelay(int ms)
{
 union pit_cmd cmd = { .raw = 0 };
 timer2_stop();
 cmd.bcd = 0;
 cmd.mode = MODE_0;
 cmd.rw = RW_16bit;
 cmd.timer = 2;
 outb(cmd.raw, PIT_CONTROL);
 pit_set_counter(ms, PIT_COUNTER2);
 timer2_start();
 while ((inb(0x61) & PIT_OUT2) == 0)
  asm volatile ("pause":::"memory");;
}

variable_types: union pit_cmd { unsigned char raw; struct { unsigned char bcd; }; }


decompiled_code:
__int64 pit_oneshot()
{
int v0; // er8
__int64 result; // rax

if ( timer0_monotonic )
{
panic("PIT: Programming timer0 as one-shot will stop currently setup monotonic mode");
result = pit_monotonic();
}
else
{
outb(0x30u, 0x43u);
result = pit_set_counter(v0, 0x40u);
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // er8
__int64 result; // rax

if ( timer0_monotonic )
{
panic("PIT: Programming timer0 as one-shot will stop currently setup monotonic mode");
result = func7();
}
else
{
func0(0x30u, 0x43u);
result = func1(v0, 0x40u);
}
return result;
}

original_code:
void pit_oneshot(int ms)
{
 union pit_cmd cmd = { .raw = 0 };
 if (timer0_monotonic == ((_Bool)1))
  panic("PIT: Programming timer0 as one-shot will "
        "stop currently setup monotonic mode");
 cmd.bcd = 0;
 cmd.mode = MODE_0;
 cmd.rw = RW_16bit;
 cmd.timer = 0;
 outb(cmd.raw, PIT_CONTROL);
 pit_set_counter(ms, PIT_COUNTER0);
}

user_defined_types: union pit_cmd { unsigned char raw; struct { unsigned char bcd; }; }


decompiled_code:
__int64 pit_monotonic()
{
int v0; // er8

timer0_monotonic = 1;
outb(0x34u, 0x43u);
return pit_set_counter(v0, 0x40u);
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // er8

timer0_monotonic = 1;
func0(0x34u, 0x43u);
return func1(v0, 0x40u);
}

original_code:
void pit_monotonic(int ms)
{
 union pit_cmd cmd = { .raw = 0 };
 timer0_monotonic = ((_Bool)1);
 cmd.bcd = 0;
 cmd.mode = MODE_2;
 cmd.rw = RW_16bit;
 cmd.timer = 0;
 outb(cmd.raw, PIT_CONTROL);
 pit_set_counter(ms, PIT_COUNTER0);
}


decompiled_code:
__int64 ramdisk_memory_area_end()
{
if ( rdheader )
return ramdisk + dword_228;
panic("%s:%d - !(rdheader != NULL)\n", "kern/ramdisk.c", 51LL);
return ramdisk_init();
}

canonical_decompiled_code:
__int64 func0()
{
if ( rdheader )
return ramdisk + dword_228;
panic("%s:%d - !(rdheader != NULL)\n", "kern/ramdisk.c", 51LL);
return func1();
}

original_code:
void *ramdisk_memory_area_end(void)
{
 do { if (__builtin_expect((!(rdheader != ((void *)0))), 0)) panic("%s:%d - !(" "rdheader != NULL" ")\n", "kern/ramdisk.c", 51); } while (0);;
 return (char *)ramdisk.buf + ramdisk.len;
}

canonical_original_code:
void *ramdisk_memory_area_end()
{
 do { if (__builtin_expect((!(rdheader != ((void *)0))), 0)) panic("%s:%d - !(" "rdheader != NULL" ")\n", "kern/ramdisk.c", 51); } while (0);;
 return (char *)ramdisk.buf + ramdisk.len;
}


decompiled_code:
__int64 __fastcall ramdisk_init(__int64 a1, __int64 a2, __int64 a3, const char *a4, __int64 a5, const char *a6)
{
int v6; // edx
__int64 result; // rax
__int64 v8; // [rsp+0h] [rbp-8h]

if ( (unsigned __int64)&_kernel_end <= 0xFFFFFFFF7FFFFFFFLL )
goto LABEL_10;
if ( (unsigned __int64)&_kernel_end > 0xFFFFFFFF9FFFFFFFLL )
{
LABEL_13:
panic("%s:%d - !((uintptr_t)(__kernel_end) < KTEXT_PAGE_END)\n", "kern/ramdisk.c", 58LL);
return ramdisk_get_len();
}
if ( (unsigned __int64)&_kernel_end + 0x80000000 > 0x3FFFFFFFFFFFLL )
{
panic(
"%s:%d - !((uintptr_t)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) pa"
"nic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET\" \")\\n\", \"kern/ramdisk.c\", 58); } while ("
"0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic(\"%s:%d - !(\" \""
"(uintptr_t)(__kernel_end) < KTEXT_PAGE_END\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; (uintptr_t)((char *)"
"(__kernel_end) - 0xffffffff80000000ULL);})) < KERN_PHYS_END_MAX)\n",
"kern/ramdisk.c",
58LL,
a4,
a5,
a6,
v8);
LABEL_10:
panic("%s:%d - !((uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET)\n", "kern/ramdisk.c", 58LL);
goto LABEL_11;
}
rdheader = (__int64)&_kernel_end - 0x7FFF80000000LL;
if ( memcmp((char *)&_kernel_end - 0x7FFF80000000LL, "CUTE-STA", 8uLL) )
{
LABEL_12:
panic("Ramdisk: Invalid header start signature");
goto LABEL_13;
}
if ( memcmp((const void *)(rdheader + 16), "CUTE-END", 8uLL) )
{
LABEL_11:
panic("Ramdisk: Invalid header end signature");
goto LABEL_12;
}
v6 = *(_DWORD *)(rdheader + 12);
ramdisk = rdheader + 24;
dword_228 = v6;
if ( v6 )
result = printk("Ramdisk: start address = 0x%lx, length = %d KB\n");
else
result = printk("Ramdisk: No disk image loaded\n");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, const char *a4, __int64 a5, const char *a6)
{
int v6; // edx
__int64 result; // rax
__int64 v8; // [rsp+0h] [rbp-8h]

if ( (unsigned __int64)&_kernel_end <= 0xFFFFFFFF7FFFFFFFLL )
goto LABEL_10;
if ( (unsigned __int64)&_kernel_end > 0xFFFFFFFF9FFFFFFFLL )
{
LABEL_13:
panic("%s:%d - !((uintptr_t)(__kernel_end) < KTEXT_PAGE_END)\n", "kern/ramdisk.c", 58LL);
return func2();
}
if ( (unsigned __int64)&_kernel_end + 0x80000000 > 0x3FFFFFFFFFFFLL )
{
panic(
"%s:%d - !((uintptr_t)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) pa"
"nic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET\" \")\\n\", \"kern/ramdisk.c\", 58); } while ("
"0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic(\"%s:%d - !(\" \""
"(uintptr_t)(__kernel_end) < KTEXT_PAGE_END\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; (uintptr_t)((char *)"
"(__kernel_end) - 0xffffffff80000000ULL);})) < KERN_PHYS_END_MAX)\n",
"kern/ramdisk.c",
58LL,
a4,
a5,
a6,
v8);
LABEL_10:
panic("%s:%d - !((uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET)\n", "kern/ramdisk.c", 58LL);
goto LABEL_11;
}
rdheader = (__int64)&_kernel_end - 0x7FFF80000000LL;
if ( memcmp((char *)&_kernel_end - 0x7FFF80000000LL, "CUTE-STA", 8uLL) )
{
LABEL_12:
panic("Ramdisk: Invalid header start signature");
goto LABEL_13;
}
if ( memcmp((const void *)(rdheader + 16), "CUTE-END", 8uLL) )
{
LABEL_11:
panic("Ramdisk: Invalid header end signature");
goto LABEL_12;
}
v6 = *(_DWORD *)(rdheader + 12);
ramdisk = rdheader + 24;
dword_228 = v6;
if ( v6 )
result = printk("Ramdisk: start address = 0x%lx, length = %d KB\n");
else
result = printk("Ramdisk: No disk image loaded\n");
return result;
}

original_code:
void ramdisk_init(void)
{
 rdheader = ({ do { if (__builtin_expect((!((uintptr_t)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET" ")\n", "kern/ramdisk.c", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) < KTEXT_PAGE_END" ")\n", "kern/ramdisk.c", 58); } while (0);; (uintptr_t)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) < KTEXT_PAGE_END\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; (uintptr_t)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) >= KERN_PHYS_OFFSET" ")\n", "kern/ramdisk.c", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET" ")\n", "kern/ramdisk.c", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) < KTEXT_PAGE_END" ")\n", "kern/ramdisk.c", 58); } while (0);; (uintptr_t)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) < KTEXT_PAGE_END\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; (uintptr_t)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) < KERN_PHYS_END_MAX" ")\n", "kern/ramdisk.c", 58); } while (0);; (void *)((char *)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET" ")\n", "kern/ramdisk.c", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) < KTEXT_PAGE_END" ")\n", "kern/ramdisk.c", 58); } while (0);; (uintptr_t)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) + 0xffff800000000000ULL); });
 if (memcmp(rdheader->start_signature, "CUTE-STA", 8))
  panic("Ramdisk: Invalid header start signature");
 if (memcmp(rdheader->end_signature, "CUTE-END", 8))
  panic("Ramdisk: Invalid header end signature");
 ramdisk.buf = (char *)(rdheader + 1);
 ramdisk.len = rdheader->length;
 if (ramdisk.len != 0)
  printk("Ramdisk: start address = 0x%lx, length = %d KB\n",
         ramdisk.buf, ramdisk.len / 1024);
 else
  printk("Ramdisk: No disk image loaded\n");
}

canonical_original_code:
void ramdisk_init()
{
 rdheader = ({ do { if (__builtin_expect((!((unsigned long)(({ do { if (__builtin_expect((!((unsigned long)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET" ")\n", "kern/ramdisk.c", 58); } while (0);; do { if (__builtin_expect((!((unsigned long)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) < KTEXT_PAGE_END" ")\n", "kern/ramdisk.c", 58); } while (0);; (unsigned long)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) < KTEXT_PAGE_END\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; (uintptr_t)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) >= KERN_PHYS_OFFSET" ")\n", "kern/ramdisk.c", 58); } while (0);; do { if (__builtin_expect((!((unsigned long)(({ do { if (__builtin_expect((!((unsigned long)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET" ")\n", "kern/ramdisk.c", 58); } while (0);; do { if (__builtin_expect((!((unsigned long)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) < KTEXT_PAGE_END" ")\n", "kern/ramdisk.c", 58); } while (0);; (unsigned long)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(({ do { if (__builtin_expect((!((uintptr_t)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; do { if (__builtin_expect((!((uintptr_t)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic(\"%s:%d - !(\" \"(uintptr_t)(__kernel_end) < KTEXT_PAGE_END\" \")\\n\", \"kern/ramdisk.c\", 58); } while (0);; (uintptr_t)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) < KERN_PHYS_END_MAX" ")\n", "kern/ramdisk.c", 58); } while (0);; (void *)((char *)(({ do { if (__builtin_expect((!((unsigned long)(__kernel_end) >= 0xffffffff80000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET" ")\n", "kern/ramdisk.c", 58); } while (0);; do { if (__builtin_expect((!((unsigned long)(__kernel_end) < 0xffffffffa0000000ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(__kernel_end) < KTEXT_PAGE_END" ")\n", "kern/ramdisk.c", 58); } while (0);; (unsigned long)((char *)(__kernel_end) - 0xffffffff80000000ULL);})) + 0xffff800000000000ULL); });
 if (memcmp(rdheader->start_signature, "CUTE-STA", 8))
  panic("Ramdisk: Invalid header start signature");
 if (memcmp(rdheader->end_signature, "CUTE-END", 8))
  panic("Ramdisk: Invalid header end signature");
 ramdisk.buf = (char *)(rdheader + 1);
 ramdisk.len = rdheader->length;
 if (ramdisk.len != 0)
  printk("Ramdisk: start address = 0x%lx, length = %d KB\n",
         ramdisk.buf, ramdisk.len / 1024);
 else
  printk("Ramdisk: No disk image loaded\n");
}


decompiled_code:
__int64 ramdisk_get_len()
{
if ( rdheader )
return (unsigned int)dword_228;
panic("%s:%d - !(rdheader != NULL)\n", "kern/ramdisk.c", 79LL);
return ramdisk_get_buf();
}

canonical_decompiled_code:
__int64 func2()
{
if ( rdheader )
return (unsigned int)dword_228;
panic("%s:%d - !(rdheader != NULL)\n", "kern/ramdisk.c", 79LL);
return func3();
}

original_code:
int ramdisk_get_len(void)
{
 do { if (__builtin_expect((!(rdheader != ((void *)0))), 0)) panic("%s:%d - !(" "rdheader != NULL" ")\n", "kern/ramdisk.c", 79); } while (0);;
 return ramdisk.len;
}

canonical_original_code:
int ramdisk_get_len()
{
 do { if (__builtin_expect((!(rdheader != ((void *)0))), 0)) panic("%s:%d - !(" "rdheader != NULL" ")\n", "kern/ramdisk.c", 79); } while (0);;
 return ramdisk.len;
}


decompiled_code:
__int64 ramdisk_get_buf()
{
if ( !rdheader )
{
panic("%s:%d - !(rdheader != NULL)\n", "kern/ramdisk.c", 85LL);
JUMPOUT(0x216LL);
}
return ramdisk;
}

canonical_decompiled_code:
__int64 func3()
{
if ( !rdheader )
{
panic("%s:%d - !(rdheader != NULL)\n", "kern/ramdisk.c", 85LL);
JUMPOUT(0x216LL);
}
return ramdisk;
}

original_code:
char *ramdisk_get_buf(void)
{
 do { if (__builtin_expect((!(rdheader != ((void *)0))), 0)) panic("%s:%d - !(" "rdheader != NULL" ")\n", "kern/ramdisk.c", 85); } while (0);;
 return ramdisk.buf;
}

canonical_original_code:
char *ramdisk_get_buf()
{
 do { if (__builtin_expect((!(rdheader != ((void *)0))), 0)) panic("%s:%d - !(" "rdheader != NULL" ")\n", "kern/ramdisk.c", 85); } while (0);;
 return ramdisk.buf;
}

return_type: char *


inb

decompiled_code:
unsigned __int8 __fastcall inb(unsigned __int16 a1)
{
return __inbyte(a1);
}

canonical_decompiled_code:
unsigned __int8 __fastcall func0(unsigned __int16 a1)
{
return __inbyte(a1);
}

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

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

return_type: unsigned char


outb

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

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


decompiled_code:
__int64 reset_port_set_8n1_mode()
{
return outb(3u, port_base + 3);
}

canonical_decompiled_code:
__int64 func2()
{
return func1(3u, port_base + 3);
}

original_code:
static void reset_port_set_8n1_mode(void)
{
 union line_control_reg reg;
 reg.raw = 0;
 reg.stop_bit = STOP_BIT_1;
 reg.data_len = DATA_LEN_8;
 outb(reg.raw, port_base + 3);
}

canonical_original_code:
static void reset_port_set_8n1_mode()
{
 union line_control_reg reg;
 reg.raw = 0;
 reg.stop_bit = STOP_BIT_1;
 reg.data_len = DATA_LEN_8;
 outb(reg.raw, port_base + 3);
}

variable_types: union line_control_reg { unsigned char raw; struct { unsigned char data_len; }; }


decompiled_code:
__int64 enable_DLAB()
{
unsigned __int16 v0; // si
unsigned __int8 v1; // al

v0 = port_base + 3;
v1 = inb(port_base + 3);
return outb(v1 | 0x80u, v0);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned __int16 v0; // si
unsigned __int8 v1; // al

v0 = port_base + 3;
v1 = func0(port_base + 3);
return func1(v1 | 0x80u, v0);
}

original_code:
static void enable_DLAB(void)
{
 union line_control_reg reg;
 reg.raw = inb(port_base + 3);
 reg.DLAB = 1;
 outb(reg.raw, port_base + 3);
}

canonical_original_code:
static void enable_DLAB()
{
 union line_control_reg reg;
 reg.raw = inb(port_base + 3);
 reg.DLAB = 1;
 outb(reg.raw, port_base + 3);
}

user_defined_types: union line_control_reg { unsigned char raw; struct { unsigned char data_len; }; }


decompiled_code:
__int64 disable_DLAB()
{
unsigned __int16 v0; // si
unsigned __int8 v1; // al

v0 = port_base + 3;
v1 = inb(port_base + 3);
return outb(v1 & 0x7F, v0);
}

canonical_decompiled_code:
__int64 func4()
{
unsigned __int16 v0; // si
unsigned __int8 v1; // al

v0 = port_base + 3;
v1 = func0(port_base + 3);
return func1(v1 & 0x7F, v0);
}

original_code:
static void disable_DLAB(void)
{
 union line_control_reg reg;
 reg.raw = inb(port_base + 3);
 reg.DLAB = 0;
 outb(reg.raw, port_base + 3);
}

canonical_original_code:
static void disable_DLAB()
{
 union line_control_reg reg;
 reg.raw = inb(port_base + 3);
 reg.DLAB = 0;
 outb(reg.raw, port_base + 3);
}


decompiled_code:
_BOOL8 tx_buffer_empty()
{
return (inb(port_base + 5) & 0x20) != 0;
}

canonical_decompiled_code:
_BOOL8 func5()
{
return (func0(port_base + 5) & 0x20) != 0;
}

original_code:
static _Bool tx_buffer_empty(void)
{
 union line_status_reg reg;
 reg.raw = inb(port_base + 5);
 return reg.tx_empty;
}

canonical_original_code:
static _Bool tx_buffer_empty()
{
 union line_status_reg reg;
 reg.raw = inb(port_base + 5);
 return reg.tx_empty;
}

variable_types: union line_status_reg { unsigned char raw; struct { unsigned char rx_avail; }; }


decompiled_code:
bool remote_ready()
{
return (inb(port_base + 6) & 0x30) == 48;
}

canonical_decompiled_code:
bool func6()
{
return (func0(port_base + 6) & 0x30) == 48;
}

original_code:
static _Bool remote_ready(void)
{
 union modem_status_reg reg;
 reg.raw = inb(port_base + 6);
 return reg.remote_ready && reg.clr_to_send;
}

canonical_original_code:
static _Bool remote_ready()
{
 union modem_status_reg reg;
 reg.raw = inb(port_base + 6);
 return reg.remote_ready && reg.clr_to_send;
}

variable_types: union modem_status_reg { unsigned char raw; struct { unsigned char unused0; }; }


decompiled_code:
__int64 serial_init()
{
unsigned __int16 v0; // cx
unsigned __int16 v1; // r8
__int16 v2; // cx
__int16 v3; // cx

port_base = MEMORY[0xFFFF800000000400];
if ( !MEMORY[0xFFFF800000000400] )
return printk("COM1: BIOS-reported I/O address = 0; no serial port attached\n");
printk("COM1: BIOS-reported I/O address = 0x%x\n", MEMORY[0xFFFF800000000400]);
reset_port_set_8n1_mode();
outb(0, port_base + 1);
enable_DLAB();
outb(1u, v0);
outb(0, v1);
disable_DLAB();
outb(0, v2 + 2);
return outb(3u, v3 + 4);
}

canonical_decompiled_code:
__int64 func8()
{
unsigned __int16 v0; // cx
unsigned __int16 v1; // r8
__int16 v2; // cx
__int16 v3; // cx

port_base = MEMORY[0xFFFF800000000400];
if ( !MEMORY[0xFFFF800000000400] )
return printk("COM1: BIOS-reported I/O address = 0; no serial port attached\n");
printk("COM1: BIOS-reported I/O address = 0x%x\n", MEMORY[0xFFFF800000000400]);
func2();
func1(0, port_base + 1);
func3();
func1(1u, v0);
func1(0, v1);
func4();
func1(0, v2 + 2);
return func1(3u, v3 + 4);
}

original_code:
void serial_init(void)
{
 union modem_control_reg reg;
 uint16_t divisor;
 divisor = 115200 / 115200;
 do { if (__builtin_expect((!(divisor <= (0xffff))), 0)) panic("%s:%d - !(" "divisor <= UINT16_MAX" ")\n", "dev/serial.c", 208); } while (0);;
 port_base = *(uint16_t *)({ do { if (__builtin_expect((!((uintptr_t)(0x400) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x400) >= KERN_PHYS_OFFSET" ")\n", "dev/serial.c", 210); } while (0);; do { if (__builtin_expect((!((uintptr_t)(0x400) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x400) < KERN_PHYS_END_MAX" ")\n", "dev/serial.c", 210); } while (0);; (void *)((char *)(0x400) + 0xffff800000000000ULL); });
 if (port_base == 0) {
  printk("COM1: BIOS-reported I/O address = 0; "
         "no serial port attached\n");
  return;
 }
 printk("COM1: BIOS-reported I/O address = 0x%x\n", port_base);
 reset_port_set_8n1_mode();
 outb(0x00, port_base + 1);
 enable_DLAB();
 outb(divisor & 0xff, port_base + 0);
 outb(divisor >> 8, port_base + 1);
 disable_DLAB();
 outb(0x00, port_base + 2);
 reg.raw = 0, reg.dt_ready = 1, reg.req_send = 1;
 outb(reg.raw, port_base + 4);
}

canonical_original_code:
void serial_init()
{
 union modem_control_reg reg;
 unsigned short divisor;
 divisor = 115200 / 115200;
 do { if (__builtin_expect((!(divisor <= (0xffff))), 0)) panic("%s:%d - !(" "divisor <= UINT16_MAX" ")\n", "dev/serial.c", 208); } while (0);;
 port_base = *(unsigned short *)({ do { if (__builtin_expect((!((unsigned long)(0x400) >= 0x0ULL)), 0)) panic("%s:%d - !(" "(uintptr_t)(0x400) >= KERN_PHYS_OFFSET" ")\n", "dev/serial.c", 210); } while (0);; do { if (__builtin_expect((!((unsigned long)(0x400) < (0x0ULL + (0xffffc00000000000ULL - 0xffff800000000000ULL)))), 0)) panic("%s:%d - !(" "(uintptr_t)(0x400) < KERN_PHYS_END_MAX" ")\n", "dev/serial.c", 210); } while (0);; (void *)((char *)(0x400) + 0xffff800000000000ULL); });
 if (port_base == 0) {
  printk("COM1: BIOS-reported I/O address = 0; "
         "no serial port attached\n");
  return;
 }
 printk("COM1: BIOS-reported I/O address = 0x%x\n", port_base);
 reset_port_set_8n1_mode();
 outb(0x00, port_base + 1);
 enable_DLAB();
 outb(divisor & 0xff, port_base + 0);
 outb(divisor >> 8, port_base + 1);
 disable_DLAB();
 outb(0x00, port_base + 2);
 reg.raw = 0, reg.dt_ready = 1, reg.req_send = 1;
 outb(reg.raw, port_base + 4);
}

variable_types: union modem_control_reg { unsigned char raw; struct { unsigned char dt_ready; }; }

variable_types:
divisor
unsigned short


decompiled_code:
void __fastcall serial_write(unsigned __int8 *a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
unsigned __int8 v7; // di
int v8; // eax
__int64 v9; // r9

if ( port_base )
{
spin_lock(&port_lock);
if ( !port_is_broken )
{
v7 = *a1;
if ( *a1 )
{
if ( (_DWORD)a2 )
{
do
{
v8 = _putc(v7);
v7 = *(_BYTE *)(v9 + 1);
v6 = v9 + 1;
if ( !v7 )
break;
v3 = (unsigned int)((_DWORD)a1 + a2 - v6);
if ( !((_DWORD)a1 + (_DWORD)a2 - (_DWORD)v6) )
break;
}
while ( !v8 );
}
}
}
spin_unlock(&port_lock, a2, v3, v4, v5, v6);
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned __int8 *a1, __int64 a2)
{
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
unsigned __int8 v7; // di
int v8; // eax
__int64 v9; // r9

if ( port_base )
{
spin_lock(&port_lock);
if ( !port_is_broken )
{
v7 = *a1;
if ( *a1 )
{
if ( (_DWORD)a2 )
{
do
{
v8 = func7(v7);
v7 = *(_BYTE *)(v9 + 1);
v6 = v9 + 1;
if ( !v7 )
break;
v3 = (unsigned int)((_DWORD)a1 + a2 - v6);
if ( !((_DWORD)a1 + (_DWORD)a2 - (_DWORD)v6) )
break;
}
while ( !v8 );
}
}
}
spin_unlock(&port_lock, a2, v3, v4, v5, v6);
}
}

original_code:
void serial_write(const char *buf, int len)
{
 int ret;
 if (port_base == 0)
  return;
 spin_lock(&port_lock);
 if (port_is_broken)
  goto out;
 ret = 0;
 while (*buf && len-- && ret == 0)
  ret = __putc(*buf++);
out: spin_unlock(&port_lock);
}

canonical_original_code:
void serial_write(char *buf, int len)
{
 int ret;
 if (port_base == 0)
  return;
 spin_lock(&port_lock);
 if (port_is_broken)
  goto out;
 ret = 0;
 while (*buf && len-- && ret == 0)
  ret = __putc(*buf++);
out: spin_unlock(&port_lock);
}

variable_types: len int

variable_types: ret int


decompiled_code:
void __fastcall serial_putc(unsigned __int8 a1)
{
unsigned __int8 v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = a1;
serial_write(v1, 1LL);
}

canonical_decompiled_code:
void __fastcall func10(unsigned __int8 a1)
{
unsigned __int8 v1[12]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = a1;
func9(v1, 1LL);
}

original_code:
void serial_putc(char ch)
{
 serial_write(&ch, 1);
}

variable_types: ch char


readl

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

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

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

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

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
unsigned __int64 read_tsc()
{
unsigned __int64 v0; // rax

v0 = __rdtsc();
return ((unsigned __int64)HIDWORD(v0) << 32) + (unsigned int)v0;
}

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

v0 = __rdtsc();
return ((unsigned __int64)HIDWORD(v0) << 32) + (unsigned int)v0;
}

original_code:
static inline uint64_t read_tsc(void)
{
 uint32_t low, high;
 asm volatile (
  "rdtsc;"
  : "=a" (low), "=d" (high));
 return ((uint64_t)high << 32) + low;
}

canonical_original_code:
static inline unsigned long read_tsc()
{
 unsigned int low; unsigned int high;
 asm volatile (
  "rdtsc;"
  : "=a" (low), "=d" (high));
 return ((unsigned long)high << 32) + low;
}

variable_types:
low
unsigned int

variable_types:
high
unsigned int


decompiled_code:
unsigned __int64 msr_apicbase_enable()
{
unsigned __int64 v0; // rax

v0 = read_msr_constprop_0();
BYTE1(v0) |= 8u;
return write_msr_constprop_0(v0);
}

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

v0 = func4();
BYTE1(v0) |= 8u;
return func5(v0);
}

original_code:
static inline void msr_apicbase_enable(void)
{
 uint64_t tmp;
 tmp = read_msr(0x0000001b);
 tmp |= (1UL << 11);
 write_msr(0x0000001b, tmp);
}

canonical_original_code:
static inline void msr_apicbase_enable()
{
 unsigned long tmp;
 tmp = read_msr(0x0000001b);
 tmp |= (1UL << 11);
 write_msr(0x0000001b, tmp);
}

variable_types:
tmp
unsigned long


decompiled_code:
__int64 apic_bootstrap_id()
{
if ( bootstrap_apic_id_saved )
return (unsigned __int8)byte_5E7;
panic("%s:%d - !(bootstrap_apic_id_saved == true)\n", "dev/apic.c", 388LL);
return apic_vrbase();
}

canonical_decompiled_code:
__int64 func8()
{
if ( bootstrap_apic_id_saved )
return (unsigned __int8)byte_5E7;
panic("%s:%d - !(bootstrap_apic_id_saved == true)\n", "dev/apic.c", 388LL);
return func9();
}

original_code:
uint8_t apic_bootstrap_id(void)
{
 do { if (__builtin_expect((!(bootstrap_apic_id_saved == ((_Bool)1))), 0)) panic("%s:%d - !(" "bootstrap_apic_id_saved == true" ")\n", "dev/apic.c", 388); } while (0);;
 return bootstrap_apic_id.id;
}

canonical_original_code:
unsigned char apic_bootstrap_id()
{
 do { if (__builtin_expect((!(bootstrap_apic_id_saved == ((_Bool)1))), 0)) panic("%s:%d - !(" "bootstrap_apic_id_saved == true" ")\n", "dev/apic.c", 388); } while (0);;
 return bootstrap_apic_id.id;
}


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

result = apic_virt_base;
if ( !apic_virt_base )
{
panic("%s:%d - !(apic_virt_base != NULL)\n", "dev/apic.c", 395LL);
result = apic_write();
}
return result;
}

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

result = apic_virt_base;
if ( !apic_virt_base )
{
panic("%s:%d - !(apic_virt_base != NULL)\n", "dev/apic.c", 395LL);
result = func10();
}
return result;
}

original_code:
void *apic_vrbase(void)
{
 do { if (__builtin_expect((!(apic_virt_base != ((void *)0))), 0)) panic("%s:%d - !(" "apic_virt_base != NULL" ")\n", "dev/apic.c", 395); } while (0);;
 return apic_virt_base;
}

canonical_original_code:
void *apic_vrbase()
{
 do { if (__builtin_expect((!(apic_virt_base != ((void *)0))), 0)) panic("%s:%d - !(" "apic_virt_base != NULL" ")\n", "dev/apic.c", 395); } while (0);;
 return apic_virt_base;
}


decompiled_code:
unsigned __int64 apic_local_regs_init()
{
msr_apicbase_setaddr_constprop_0();
apic_write(0x80u, 0);
apic_write(0xD0u, -16777216);
apic_write(0xE0u, -1);
apic_write(0x320u, 65600);
apic_write(0x330u, 65601);
apic_write(0x340u, 65602);
apic_write(0x350u, 65603);
apic_write(0x360u, 65604);
apic_write(0xF0u, 511);
return msr_apicbase_enable();
}

original_code:
void apic_local_regs_init(void)
{
 union apic_tpr tpr = { .value = APIC_TPR_RESET };
 union apic_ldr ldr = { .value = APIC_LDR_RESET };
 union apic_dfr dfr = { .value = APIC_DFR_RESET };
 union apic_spiv spiv = { .value = APIC_SPIV_RESET };
 union apic_lvt_timer timer = { .value = APIC_LVT_RESET };
 union apic_lvt_thermal thermal = { .value = APIC_LVT_RESET };
 union apic_lvt_perfc perfc = { .value = APIC_LVT_RESET };
 union apic_lvt_lint lint0 = { .value = APIC_LVT_RESET };
 union apic_lvt_lint lint1 = { .value = APIC_LVT_RESET };
 msr_apicbase_setaddr(0xfee00000);
 tpr.subclass = APIC_TPR_DISABLE_IRQ_BALANCE;
 tpr.priority = APIC_TPR_DISABLE_IRQ_BALANCE;
 apic_write(0x80, tpr.value);
 ldr.logical_id = 0xff;
 apic_write(0xd0, ldr.value);
 dfr.apic_model = APIC_MODEL_FLAT;
 apic_write(0xe0, dfr.value);
 timer.vector = 0x40;
 timer.mask = APIC_MASK;
 apic_write(0x320, timer.value);
 thermal.vector = 0x41;
 thermal.mask = APIC_MASK;
 apic_write(0x330, thermal.value);
 perfc.vector = 0x42;
 perfc.mask = APIC_MASK;
 apic_write(0x340, perfc.value);
 lint0.vector = 0x43;
 lint0.mask = APIC_MASK;
 apic_write(0x350, lint0.value);
 lint1.vector = 0x44;
 lint1.mask = APIC_MASK;
 apic_write(0x360, lint1.value);
 spiv.vector = 0xff;
 spiv.apic_enable = 1;
 apic_write(0xf0, spiv.value);
 msr_apicbase_enable();
}

canonical_original_code:
void apic_local_regs_init()
{
 union apic_tpr tpr = { .value = APIC_TPR_RESET };
 union apic_ldr ldr = { .value = APIC_LDR_RESET };
 union apic_dfr dfr = { .value = APIC_DFR_RESET };
 union apic_spiv spiv = { .value = APIC_SPIV_RESET };
 union apic_lvt_timer timer = { .value = APIC_LVT_RESET };
 union apic_lvt_thermal thermal = { .value = APIC_LVT_RESET };
 union apic_lvt_perfc perfc = { .value = APIC_LVT_RESET };
 union apic_lvt_lint lint0 = { .value = APIC_LVT_RESET };
 union apic_lvt_lint lint1 = { .value = APIC_LVT_RESET };
 msr_apicbase_setaddr(0xfee00000);
 tpr.subclass = APIC_TPR_DISABLE_IRQ_BALANCE;
 tpr.priority = APIC_TPR_DISABLE_IRQ_BALANCE;
 apic_write(0x80, tpr.value);
 ldr.logical_id = 0xff;
 apic_write(0xd0, ldr.value);
 dfr.apic_model = APIC_MODEL_FLAT;
 apic_write(0xe0, dfr.value);
 timer.vector = 0x40;
 timer.mask = APIC_MASK;
 apic_write(0x320, timer.value);
 thermal.vector = 0x41;
 thermal.mask = APIC_MASK;
 apic_write(0x330, thermal.value);
 perfc.vector = 0x42;
 perfc.mask = APIC_MASK;
 apic_write(0x340, perfc.value);
 lint0.vector = 0x43;
 lint0.mask = APIC_MASK;
 apic_write(0x350, lint0.value);
 lint1.vector = 0x44;
 lint1.mask = APIC_MASK;
 apic_write(0x360, lint1.value);
 spiv.vector = 0xff;
 spiv.apic_enable = 1;
 apic_write(0xf0, spiv.value);
 msr_apicbase_enable();
}

variable_types: union apic_tpr { struct { unsigned int subclass; }; unsigned int value; }

variable_types: union apic_ldr { struct { unsigned int reserved; }; unsigned int value; }

variable_types: union apic_dfr { struct { unsigned int reserved; }; unsigned int value; }

variable_types: union apic_spiv { struct { unsigned int vector; }; unsigned int value; }

variable_types: union apic_lvt_timer { struct { unsigned int vector; }; unsigned int value; }

variable_types: union apic_lvt_thermal { struct { unsigned int vector; }; unsigned int value; }

variable_types: union apic_lvt_perfc { struct { unsigned int vector; }; unsigned int value; }

variable_types: union apic_lvt_lint { struct { unsigned int vector; }; unsigned int value; }


decompiled_code:
__int64 __fastcall apic_read(unsigned int a1)
{
__int64 v1; // rax

v1 = apic_vrbase();
return readl((unsigned int *)(v1 + a1));
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1)
{
__int64 v1; // rax

v1 = func9();
return func0((unsigned int *)(v1 + a1));
}

original_code:
static inline uint32_t apic_read(uint32_t reg)
{
 void *vaddr;
 vaddr = apic_vrbase();
 vaddr = (char *)vaddr + reg;
 return readl(vaddr);
}

canonical_original_code:
static inline unsigned int apic_read(unsigned int reg)
{
 void *vaddr;
 vaddr = apic_vrbase();
 vaddr = (char *)vaddr + reg;
 return readl(vaddr);
}

variable_types:
reg
unsigned int

variable_types:
vaddr
void *


decompiled_code:
__int64 pit_calibrate_apic_timer()
{
int v0; // ebp
unsigned int v1; // ebx
int v2; // eax
int v3; // eax
unsigned int v4; // eax

v0 = 5;
v1 = -1;
v2 = apic_read(0x320u);
apic_write(0x320u, v2 & 0xFFFCFFFF | 0x10000);
apic_write(0x3E0u, 11);
while ( 1 )
{
apic_write(0x380u, -1);
pit_mdelay(5LL);
v3 = apic_read(0x390u);
if ( v3 == -1 )
break;
v4 = ~v3;
if ( v1 > v4 )
v1 = v4;
if ( !--v0 )
return 200 * v1;
}
panic("%s:%d - !(counter1 > counter2)\n", "dev/apic.c", 105LL);
return apic_init();
}

canonical_decompiled_code:
__int64 func18()
{
int v0; // ebp
unsigned int v1; // ebx
int v2; // eax
int v3; // eax
unsigned int v4; // eax

v0 = 5;
v1 = -1;
v2 = func17(0x320u);
func10(0x320u, v2 & 0xFFFCFFFF | 0x10000);
func10(0x3E0u, 11);
while ( 1 )
{
func10(0x380u, -1);
pit_mdelay(5LL);
v3 = func17(0x390u);
if ( v3 == -1 )
break;
v4 = ~v3;
if ( v1 > v4 )
v1 = v4;
if ( !--v0 )
return 200 * v1;
}
panic("%s:%d - !(counter1 > counter2)\n", "dev/apic.c", 105LL);
return func19();
}

original_code:
static uint64_t pit_calibrate_apic_timer(void)
{
 int ms_delay;
 uint32_t counter1, counter2, ticks, ticks_min;
 uint64_t apic_clock;
 union apic_lvt_timer lvt_timer;
 lvt_timer.value = apic_read(0x320);
 lvt_timer.timer_mode = APIC_TIMER_ONESHOT;
 lvt_timer.mask = APIC_MASK;
 apic_write(0x320, lvt_timer.value);
 apic_write(0x3e0, APIC_DCR_1);
 counter1 = ticks_min = (0xffffffff);
 ms_delay = 5;
 for (int i = 0; i < 5; i++) {
  apic_write(0x380, counter1);
  pit_mdelay(ms_delay);
  counter2 = apic_read(0x390);
  do { if (__builtin_expect((!(counter1 > counter2)), 0)) panic("%s:%d - !(" "counter1 > counter2" ")\n", "dev/apic.c", 105); } while (0);;
  ticks = counter1 - counter2;
  if (ticks < ticks_min)
   ticks_min = ticks;
 }
 apic_clock = ticks_min * (1000 / ms_delay);
 return apic_clock;
}

canonical_original_code:
static unsigned long pit_calibrate_apic_timer()
{
 int ms_delay;
 unsigned int counter1; unsigned int counter2; unsigned int ticks; unsigned int ticks_min;
 unsigned long apic_clock;
 union apic_lvt_timer lvt_timer;
 lvt_timer.value = apic_read(0x320);
 lvt_timer.timer_mode = APIC_TIMER_ONESHOT;
 lvt_timer.mask = APIC_MASK;
 apic_write(0x320, lvt_timer.value);
 apic_write(0x3e0, APIC_DCR_1);
 counter1 = ticks_min = (0xffffffff);
 ms_delay = 5;
 for (int i = 0; i < 5; i++) {
  apic_write(0x380, counter1);
  pit_mdelay(ms_delay);
  counter2 = apic_read(0x390);
  do { if (__builtin_expect((!(counter1 > counter2)), 0)) panic("%s:%d - !(" "counter1 > counter2" ")\n", "dev/apic.c", 105); } while (0);;
  ticks = counter1 - counter2;
  if (ticks < ticks_min)
   ticks_min = ticks;
 }
 apic_clock = ticks_min * (1000 / ms_delay);
 return apic_clock;
}

variable_types:
ticks
unsigned int

variable_types: i int

user_defined_types: union apic_lvt_timer { struct { unsigned int vector; }; unsigned int value; }


decompiled_code:
__int64 apic_init()
{
unsigned __int64 v0; // rax
unsigned int v1; // eax

msr_apicbase_setaddr_constprop_0();
apic_virt_base = vm_kmap(4276092928LL, 4096LL);
v0 = pit_calibrate_cpu_constprop_0();
printk("APIC: Detected %d.%d MHz processor\n", v0 / 0xF4240, (unsigned __int8)(v0 % 0xF4240));
apic_clock = pit_calibrate_apic_timer();
printk("APIC: Detected %d.%d MHz bus clock\n", apic_clock / 0xF4240uLL, (unsigned __int8)(apic_clock % 0xF4240uLL));
apic_local_regs_init();
v1 = apic_read(0x20u);
bootstrap_apic_id_saved = 1;
bootstrap_apic_id = v1;
return printk("APIC: bootstrap core lapic enabled, apic_id=0x%x\n", HIBYTE(v1));
}

canonical_decompiled_code:
__int64 func19()
{
unsigned __int64 v0; // rax
unsigned int v1; // eax

func6();
apic_virt_base = vm_kmap(4276092928LL, 4096LL);
v0 = func3();
printk("APIC: Detected %d.%d MHz processor\n", v0 / 0xF4240, (unsigned __int8)(v0 % 0xF4240));
apic_clock = func18();
printk("APIC: Detected %d.%d MHz bus clock\n", apic_clock / 0xF4240uLL, (unsigned __int8)(apic_clock % 0xF4240uLL));
func11();
v1 = func17(0x20u);
bootstrap_apic_id_saved = 1;
bootstrap_apic_id = v1;
return printk("APIC: bootstrap core lapic enabled, apic_id=0x%x\n", HIBYTE(v1));
}

original_code:
void apic_init(void)
{
 msr_apicbase_setaddr(0xfee00000);
 apic_virt_base = vm_kmap(0xfee00000, (1 << 12));
 cpu_clock = pit_calibrate_cpu(10);
 printk("APIC: Detected %d.%d MHz processor\n",
        cpu_clock / 1000000, (uint8_t)(cpu_clock % 1000000));
 apic_clock = pit_calibrate_apic_timer();
 printk("APIC: Detected %d.%d MHz bus clock\n",
        apic_clock / 1000000, (uint8_t)(apic_clock % 1000000));
 apic_local_regs_init();
 bootstrap_apic_id.raw = apic_read(0x20);
 bootstrap_apic_id_saved = ((_Bool)1);
 printk("APIC: bootstrap core lapic enabled, apic_id=0x%x\n",
        bootstrap_apic_id.id);
}

canonical_original_code:
void apic_init()
{
 msr_apicbase_setaddr(0xfee00000);
 apic_virt_base = vm_kmap(0xfee00000, (1 << 12));
 cpu_clock = pit_calibrate_cpu(10);
 printk("APIC: Detected %d.%d MHz processor\n",
        cpu_clock / 1000000, (unsigned char)(cpu_clock % 1000000));
 apic_clock = pit_calibrate_apic_timer();
 printk("APIC: Detected %d.%d MHz bus clock\n",
        apic_clock / 1000000, (unsigned char)(apic_clock % 1000000));
 apic_local_regs_init();
 bootstrap_apic_id.raw = apic_read(0x20);
 bootstrap_apic_id_saved = ((_Bool)1);
 printk("APIC: bootstrap core lapic enabled, apic_id=0x%x\n",
        bootstrap_apic_id.id);
}


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

apic_write(0x320u, 0x10000);
apic_set_counter_us(a1);
while ( 1 )
{
result = apic_read(0x390u);
if ( !(_DWORD)result )
break;
_mm_pause();
}
return result;
}

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

func10(0x320u, 0x10000);
func12(a1);
while ( 1 )
{
result = func17(0x390u);
if ( !(_DWORD)result )
break;
_mm_pause();
}
return result;
}

original_code:
void apic_udelay(uint64_t us)
{
 union apic_lvt_timer lvt_timer;
 lvt_timer.value = 0;
 lvt_timer.timer_mode = APIC_TIMER_ONESHOT;
 lvt_timer.mask = APIC_MASK;
 apic_write(0x320, lvt_timer.value);
 apic_set_counter_us(us);
 while (apic_read(0x390) != 0)
  asm volatile ("pause":::"memory");;
}

canonical_original_code:
void apic_udelay(unsigned long us)
{
 union apic_lvt_timer lvt_timer;
 lvt_timer.value = 0;
 lvt_timer.timer_mode = APIC_TIMER_ONESHOT;
 lvt_timer.mask = APIC_MASK;
 apic_write(0x320, lvt_timer.value);
 apic_set_counter_us(us);
 while (apic_read(0x390) != 0)
  asm volatile ("pause":::"memory");;
}

variable_types:
us
unsigned long


decompiled_code:
__int64 __fastcall apic_mdelay(int a1)
{
return apic_udelay(1000 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1)
{
return func20(1000 * a1);
}

original_code:
void apic_mdelay(int ms)
{
 apic_udelay(ms * 1000);
}

variable_types: ms int


decompiled_code:
__int64 apic_ipi_acked()
{
int v0; // ebx

v0 = 100;
do
{
if ( (apic_read(0x300u) & 0x1000) == 0 )
return 1LL;
pit_mdelay(1LL);
--v0;
}
while ( v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func22()
{
int v0; // ebx

v0 = 100;
do
{
if ( (func17(0x300u) & 0x1000) == 0 )
return 1LL;
pit_mdelay(1LL);
--v0;
}
while ( v0 );
return 0LL;
}

original_code:
_Bool apic_ipi_acked(void)
{
 union apic_icr icr = { .value = 0 };
 int timeout = 100;
 while (timeout--) {
  icr.value_low = apic_read(0x300);
  if (icr.delivery_status == APIC_DELSTATE_IDLE)
   return ((_Bool)1);
  pit_mdelay(1);
 }
 return ((_Bool)0);
}

canonical_original_code:
_Bool apic_ipi_acked()
{
 union apic_icr icr = { .value = 0 };
 int timeout = 100;
 while (timeout--) {
  icr.value_low = apic_read(0x300);
  if (icr.delivery_status == APIC_DELSTATE_IDLE)
   return ((_Bool)1);
  pit_mdelay(1);
 }
 return ((_Bool)0);
}

variable_types: union apic_icr { struct { unsigned int vector; unsigned int reserved3; }; struct { unsigned int value_low; unsigned int value_high; }; unsigned long value; }

variable_types: timeout int


decompiled_code:
// attributes: thunk
unsigned __int64 get_gs()
{
return read_msr_constprop_0();
}

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

original_code:
static inline uint64_t get_gs(void)
{
 return read_msr(0xC0000101);
}

canonical_original_code:
static inline unsigned long get_gs()
{
 return read_msr(0xC0000101);
}


decompiled_code:
// attributes: thunk
unsigned __int64 __fastcall set_gs(unsigned __int64 a1)
{
return write_msr_constprop_0(a1);
}

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

original_code:
static inline void set_gs(uint64_t val)
{
 write_msr(0xC0000101, val);
}

canonical_original_code:
static inline void set_gs(unsigned long val)
{
 write_msr(0xC0000101, val);
}

variable_types:
val
unsigned long


inb

decompiled_code:
unsigned __int8 __fastcall inb(unsigned __int16 a1)
{
return __inbyte(a1);
}

canonical_decompiled_code:
unsigned __int8 __fastcall func0(unsigned __int16 a1)
{
return __inbyte(a1);
}

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

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

variable_types:
port
unsigned short

variable_types:
val
unsigned char


decompiled_code:
unsigned __int8 kbd_read_input()
{
unsigned __int8 result; // al

if ( (inb(0x64u) & 1) != 0 )
result = inb(0x60u);
else
result = -1;
return result;
}

canonical_decompiled_code:
unsigned __int8 func1()
{
unsigned __int8 result; // al

if ( (func0(0x64u) & 1) != 0 )
result = func0(0x60u);
else
result = -1;
return result;
}

original_code:
static uint8_t kbd_read_input(void)
{
 union i8042_status status;
 status.raw = inb(KBD_STATUS_REG);
 if (status.output_ready)
  return inb(KBD_DATA_REG);
 return KEY_NONE;
}

canonical_original_code:
static unsigned char kbd_read_input()
{
 union i8042_status status;
 status.raw = inb(KBD_STATUS_REG);
 if (status.output_ready)
  return inb(KBD_DATA_REG);
 return KEY_NONE;
}

variable_types: union i8042_status { unsigned char raw; struct { unsigned char output_ready; }; }


decompiled_code:
unsigned __int8 kbd_flush_buffer()
{
int v0; // ebx
unsigned __int8 result; // al

v0 = 128;
do
{
result = kbd_read_input();
if ( result == 0xFF )
break;
result = apic_udelay(50LL);
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
unsigned __int8 func2()
{
int v0; // ebx
unsigned __int8 result; // al

v0 = 128;
do
{
result = func1();
if ( result == 0xFF )
break;
result = apic_udelay(50LL);
--v0;
}
while ( v0 );
return result;
}

original_code:
static void kbd_flush_buffer(void)
{
 int trials = 128;
 while (trials--) {
  if (kbd_read_input() == KEY_NONE)
   break;
  apic_udelay(50);
 }
}

canonical_original_code:
static void kbd_flush_buffer()
{
 int trials = 128;
 while (trials--) {
  if (kbd_read_input() == KEY_NONE)
   break;
  apic_udelay(50);
 }
}

variable_types: trials int


decompiled_code:
unsigned __int8 __fastcall keyboard_init(__int64 a1)
{
set_intr_gate_constprop_0(a1, 48LL);
ioapic_setup_isairq(1LL, 48LL, 1LL);
return kbd_flush_buffer();
}

canonical_decompiled_code:
unsigned __int8 __fastcall func7(__int64 a1)
{
func5(a1, 48LL);
ioapic_setup_isairq(1LL, 48LL, 1LL);
return func2();
}

original_code:
void keyboard_init(void) {
 extern void kb_handler(void);
 uint8_t vector;
 vector = 0x30;
 set_intr_gate(vector, kb_handler);
 ioapic_setup_isairq(1, vector, IRQ_BOOTSTRAP);
 kbd_flush_buffer();
}

canonical_original_code:
void keyboard_init() {
 extern void kb_handler();
 unsigned char vector;
 vector = 0x30;
 set_intr_gate(vector, kb_handler);
 ioapic_setup_isairq(1, vector, IRQ_BOOTSTRAP);
 kbd_flush_buffer();
}

variable_types:
vector
unsigned char


kmalloc

decompiled_code:
__int64 __fastcall kmalloc(int a1)
{
if ( a1 <= 0 )
{
panic("%s:%d - !(size > 0)\n", "include/kmalloc.h", 102LL);
return _kmalloc(7LL);
}
if ( a1 <= 16 )
return _kmalloc(4LL);
if ( a1 <= 32 )
return _kmalloc(5LL);
if ( a1 <= 64 )
return _kmalloc(6LL);
if ( a1 <= 128 )
return _kmalloc(7LL);
if ( a1 <= 256 )
return _kmalloc(8LL);
if ( a1 <= 512 )
return _kmalloc(9LL);
if ( a1 <= 1024 )
return _kmalloc(10LL);
if ( a1 <= 2048 )
return _kmalloc(11LL);
if ( a1 <= 4096 )
return _kmalloc(12LL);
panic("Malloc: %d bytes requested; can't support > %d bytes", (unsigned int)a1, 4096LL);
return _unode_new();
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
if ( a1 <= 0 )
{
panic("%s:%d - !(size > 0)\n", "include/kmalloc.h", 102LL);
return _kmalloc(7LL);
}
if ( a1 <= 16 )
return _kmalloc(4LL);
if ( a1 <= 32 )
return _kmalloc(5LL);
if ( a1 <= 64 )
return _kmalloc(6LL);
if ( a1 <= 128 )
return _kmalloc(7LL);
if ( a1 <= 256 )
return _kmalloc(8LL);
if ( a1 <= 512 )
return _kmalloc(9LL);
if ( a1 <= 1024 )
return _kmalloc(10LL);
if ( a1 <= 2048 )
return _kmalloc(11LL);
if ( a1 <= 4096 )
return _kmalloc(12LL);
panic("Malloc: %d bytes requested; can't support > %d bytes", (unsigned int)a1, 4096LL);
return func2();
}

original_code:
static inline void *kmalloc(int size)
{
 do { if (__builtin_expect((!(size > 0)), 0)) panic("%s:%d - !(" "size > 0" ")\n", "include/kmalloc.h", 102); } while (0);;
 do { if (!(((1 << 4) * 256) == (1 << 12))) __undefined_method(); } while (0);;
 do { if (!((4 + 8) == 12)) __undefined_method(); } while (0);;
 if (size <= (1 << 4)) return __kmalloc(4);
 if (size <= (1 << 4) * 2) return __kmalloc(4 + 1);
 if (size <= (1 << 4) * 4) return __kmalloc(4 + 2);
 if (size <= (1 << 4) * 8) return __kmalloc(4 + 3);
 if (size <= (1 << 4) * 16) return __kmalloc(4 + 4);
 if (size <= (1 << 4) * 32) return __kmalloc(4 + 5);
 if (size <= (1 << 4) * 64) return __kmalloc(4 + 6);
 if (size <= (1 << 4) * 128) return __kmalloc(4 + 7);
 if (size <= (1 << 4) * 256) return __kmalloc(4 + 8);
 panic("Malloc: %d bytes requested; can't support > %d "
       "bytes", size, (1 << 12));
 return ((void *)0);
}

variable_types: size int


decompiled_code:
__int64 __fastcall unrolled_init(__int64 a1, int a2)
{
__int64 result; // rax

*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = a2;
if ( !a2 )
{
panic("%s:%d - !(head->array_len > 0)\n", "lib/unrolled_list.c", 132LL);
result = unrolled_free();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 result; // rax

*(_QWORD *)a1 = 0LL;
*(_DWORD *)(a1 + 8) = a2;
if ( !a2 )
{
panic("%s:%d - !(head->array_len > 0)\n", "lib/unrolled_list.c", 132LL);
result = func6();
}
return result;
}

original_code:
void unrolled_init(struct unrolled_head *head, uint array_len)
{
 head->node = ((void *)0);
 head->array_len = array_len;
 do { if (__builtin_expect((!(head->array_len > 0)), 0)) panic("%s:%d - !(" "head->array_len > 0" ")\n", "lib/unrolled_list.c", 132); } while (0);;
}

canonical_original_code:
void unrolled_init(struct unrolled_head *head, unsigned int array_len)
{
 head->node = ((void *)0);
 head->array_len = array_len;
 do { if (__builtin_expect((!(head->array_len > 0)), 0)) panic("%s:%d - !(" "head->array_len > 0" ")\n", "lib/unrolled_list.c", 132); } while (0);;
}

variable_types: struct unrolled_head { struct __node { void **array; unsigned int array_len; unsigned int array_nrfree; unsigned int num; struct __node *next; } *node; unsigned int array_len; } *

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


decompiled_code:
__int64 __fastcall unrolled_free(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rdi
__int64 result; // rax

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
result = _unode_free(v2);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rdi
__int64 result; // rax

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
result = func0(v2);
}
while ( v1 );
}
return result;
}

original_code:
void unrolled_free(struct unrolled_head *head)
{
 struct __node *node, *prev;
 node = head->node;
 while (node != ((void *)0)) {
  prev = node;
  node = node->next;
  __unode_free(prev);
 }
}

canonical_original_code:
void unrolled_free(struct unrolled_head *head)
{
 struct __node *node; struct __node *prev;
 node = head->node;
 while (node != ((void *)0)) {
  prev = node;
  node = node->next;
  __unode_free(prev);
 }
}

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


decompiled_code:
__int64 __fastcall unrolled_insert(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // edx
__int64 v4; // rbp
unsigned int v6; // ebp
__int64 v7; // rax

v2 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 )
{
if ( a2 )
goto LABEL_5;
goto LABEL_12;
}
v7 = _unode_new(0, *(_DWORD *)(a1 + 8));
*(_QWORD *)a1 = v7;
v2 = v7;
if ( !a2 )
{
LABEL_12:
panic("%s:%d - !(val != NULL)\n", "lib/unrolled_list.c", 169LL);
return unrolled_lookup();
}
if ( !v7 )
{
panic("%s:%d - !(head->node != NULL)\n", "lib/unrolled_list.c", 170LL);
goto LABEL_12;
}
LABEL_5:
while ( 1 )
{
v3 = *(_DWORD *)(v2 + 12);
if ( v3 )
break;
if ( !*(_QWORD *)(v2 + 24) )
{
v4 = _unode_new(*(_DWORD *)(v2 + 16) + 1, *(_DWORD *)(v2 + 8));
_unode_store_val_in_array(v4, 0, a2);
*(_QWORD *)(v2 + 24) = v4;
return (unsigned int)(*(_DWORD *)(v4 + 8) * *(_DWORD *)(v4 + 16));
}
v2 = *(_QWORD *)(v2 + 24);
}
v6 = _unode_array_find_free_idx_isra_0(*(_QWORD *)v2, *(_DWORD *)(v2 + 8), v3);
_unode_store_val_in_array(v2, v6, a2);
return v6 + *(_DWORD *)(v2 + 8) * *(_DWORD *)(v2 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // edx
__int64 v4; // rbp
unsigned int v6; // ebp
__int64 v7; // rax

v2 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 )
{
if ( a2 )
goto LABEL_5;
goto LABEL_12;
}
v7 = func2(0, *(_DWORD *)(a1 + 8));
*(_QWORD *)a1 = v7;
v2 = v7;
if ( !a2 )
{
LABEL_12:
panic("%s:%d - !(val != NULL)\n", "lib/unrolled_list.c", 169LL);
return unrolled_lookup();
}
if ( !v7 )
{
panic("%s:%d - !(head->node != NULL)\n", "lib/unrolled_list.c", 170LL);
goto LABEL_12;
}
LABEL_5:
while ( 1 )
{
v3 = *(_DWORD *)(v2 + 12);
if ( v3 )
break;
if ( !*(_QWORD *)(v2 + 24) )
{
v4 = func2(*(_DWORD *)(v2 + 16) + 1, *(_DWORD *)(v2 + 8));
_unode_store_val_in_array(v4, 0, a2);
*(_QWORD *)(v2 + 24) = v4;
return (unsigned int)(*(_DWORD *)(v4 + 8) * *(_DWORD *)(v4 + 16));
}
v2 = *(_QWORD *)(v2 + 24);
}
v6 = func4(*(_QWORD *)v2, *(_DWORD *)(v2 + 8), v3);
_unode_store_val_in_array(v2, v6, a2);
return v6 + *(_DWORD *)(v2 + 8) * *(_DWORD *)(v2 + 16);
}

original_code:
uint unrolled_insert(struct unrolled_head *head, void *val)
{
 struct __node *node, *prev;
 uint idx;
 if (head->node == ((void *)0))
  head->node = __unode_new(0, head->array_len);
 do { if (__builtin_expect((!(val != ((void *)0))), 0)) panic("%s:%d - !(" "val != NULL" ")\n", "lib/unrolled_list.c", 169); } while (0);;
 do { if (__builtin_expect((!(head->node != ((void *)0))), 0)) panic("%s:%d - !(" "head->node != NULL" ")\n", "lib/unrolled_list.c", 170); } while (0);;
 for (node = head->node; node != ((void *)0); node = node->next) {
  if (node->array_nrfree > 0) {
   idx = __unode_array_find_free_idx(node);
   __unode_store_val_in_array(node, idx, val);
   return (node->num * node->array_len) + idx;
  }
  prev = node;
 }
 node = __unode_new(prev->num + 1, prev->array_len);
 __unode_store_val_in_array(node, 0, val);
 prev->next = node;
 return node->num * node->array_len;
}

canonical_original_code:
unsigned int unrolled_insert(struct unrolled_head *head, void *val)
{
 struct __node *node; struct __node *prev;
 unsigned int idx;
 if (head->node == ((void *)0))
  head->node = __unode_new(0, head->array_len);
 do { if (__builtin_expect((!(val != ((void *)0))), 0)) panic("%s:%d - !(" "val != NULL" ")\n", "lib/unrolled_list.c", 169); } while (0);;
 do { if (__builtin_expect((!(head->node != ((void *)0))), 0)) panic("%s:%d - !(" "head->node != NULL" ")\n", "lib/unrolled_list.c", 170); } while (0);;
 for (node = head->node; node != ((void *)0); node = node->next) {
  if (node->array_nrfree > 0) {
   idx = __unode_array_find_free_idx(node);
   __unode_store_val_in_array(node, idx, val);
   return (node->num * node->array_len) + idx;
  }
  prev = node;
 }
 node = __unode_new(prev->num + 1, prev->array_len);
 __unode_store_val_in_array(node, 0, val);
 prev->next = node;
 return node->num * node->array_len;
}

variable_types:
val
void *

variable_types:
idx
unsigned int

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


decompiled_code:
__int64 __fastcall list_empty(_QWORD *a1)
{
_QWORD *v1; // rax
unsigned int v2; // er8

v1 = (_QWORD *)a1[1];
if ( (_QWORD *)*a1 == a1 )
{
v2 = 1;
if ( v1 == a1 )
return v2;
panic("%s:%d - !(node->prev == node)\n", "include/list.h", 92LL);
}
else
{
v2 = 0;
if ( v1 != a1 )
return v2;
}
panic("%s:%d - !(node->prev != node)\n", "include/list.h", 96LL);
return list_del();
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
_QWORD *v1; // rax
unsigned int v2; // er8

v1 = (_QWORD *)a1[1];
if ( (_QWORD *)*a1 == a1 )
{
v2 = 1;
if ( v1 == a1 )
return v2;
panic("%s:%d - !(node->prev == node)\n", "include/list.h", 92LL);
}
else
{
v2 = 0;
if ( v1 != a1 )
return v2;
}
panic("%s:%d - !(node->prev != node)\n", "include/list.h", 96LL);
return list_del();
}

original_code:
static inline _Bool list_empty(const struct list_node *node)
{
 if (node->next == node) {
  do { if (__builtin_expect((!(node->prev == node)), 0)) panic("%s:%d - !(" "node->prev == node" ")\n", "include/list.h", 92); } while (0);;
  return ((_Bool)1);
 }
 do { if (__builtin_expect((!(node->prev != node)), 0)) panic("%s:%d - !(" "node->prev != node" ")\n", "include/list.h", 96); } while (0);;
 return ((_Bool)0);
}

canonical_original_code:
static inline _Bool list_empty(struct list_node *node)
{
 if (node->next == node) {
  do { if (__builtin_expect((!(node->prev == node)), 0)) panic("%s:%d - !(" "node->prev == node" ")\n", "include/list.h", 92); } while (0);;
  return ((_Bool)1);
 }
 do { if (__builtin_expect((!(node->prev != node)), 0)) panic("%s:%d - !(" "node->prev != node" ")\n", "include/list.h", 96); } while (0);;
 return ((_Bool)0);
}

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


decompiled_code:
__int64 __fastcall kmalloc(int a1)
{
if ( a1 <= 0 )
{
panic("%s:%d - !(size > 0)\n", "include/kmalloc.h", 102LL);
return _kmalloc(7LL);
}
if ( a1 <= 16 )
return _kmalloc(4LL);
if ( a1 <= 32 )
return _kmalloc(5LL);
if ( a1 <= 64 )
return _kmalloc(6LL);
if ( a1 <= 128 )
return _kmalloc(7LL);
if ( a1 <= 256 )
return _kmalloc(8LL);
if ( a1 <= 512 )
return _kmalloc(9LL);
if ( a1 <= 1024 )
return _kmalloc(10LL);
if ( a1 <= 2048 )
return _kmalloc(11LL);
if ( a1 <= 4096 )
return _kmalloc(12LL);
panic("Malloc: %d bytes requested; can't support > %d bytes", (unsigned int)a1, 4096LL);
return hash_new();
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
if ( a1 <= 0 )
{
panic("%s:%d - !(size > 0)\n", "include/kmalloc.h", 102LL);
return _kmalloc(7LL);
}
if ( a1 <= 16 )
return _kmalloc(4LL);
if ( a1 <= 32 )
return _kmalloc(5LL);
if ( a1 <= 64 )
return _kmalloc(6LL);
if ( a1 <= 128 )
return _kmalloc(7LL);
if ( a1 <= 256 )
return _kmalloc(8LL);
if ( a1 <= 512 )
return _kmalloc(9LL);
if ( a1 <= 1024 )
return _kmalloc(10LL);
if ( a1 <= 2048 )
return _kmalloc(11LL);
if ( a1 <= 4096 )
return _kmalloc(12LL);
panic("Malloc: %d bytes requested; can't support > %d bytes", (unsigned int)a1, 4096LL);
return func4();
}

canonical_original_code:
static inline void *kmalloc(int size)
{
 do { if (__builtin_expect((!(size > 0)), 0)) panic("%s:%d - !(" "size > 0" ")\n", "include/kmalloc.h", 102); } while (0);;
 do { if (!(((1 << 4) * 256) == (1 << 12))) __undefined_method(); } while (0);;
 do { if (!((4 + 8) == 12)) __undefined_method(); } while (0);;
 if (size <= (1 << 4)) return __kmalloc(4);
 if (size <= (1 << 4) * 2) return __kmalloc(4 + 1);
 if (size <= (1 << 4) * 4) return __kmalloc(4 + 2);
 if (size <= (1 << 4) * 8) return __kmalloc(4 + 3);
 if (size <= (1 << 4) * 16) return __kmalloc(4 + 4);
 if (size <= (1 << 4) * 32) return __kmalloc(4 + 5);
 if (size <= (1 << 4) * 64) return __kmalloc(4 + 6);
 if (size <= (1 << 4) * 128) return __kmalloc(4 + 7);
 if (size <= (1 << 4) * 256) return __kmalloc(4 + 8);
 panic("Malloc: %d bytes requested; can't support > %d "
       "bytes", size, (1 << 12));
 return ((void *)0);
}


original_code:
struct hash *hash_new(uint len)
{
 struct hash *hash;
 hash = kmalloc(sizeof(*hash));
 hash->nodes_array = kmalloc(len * sizeof(*hash->nodes_array));
 for (uint i = 0; i < len; i++)
  list_init(&hash->nodes_array[i]);
 hash->len = len;
 return hash;
}

canonical_original_code:
struct hash *hash_new(unsigned int len)
{
 struct hash *hash;
 hash = kmalloc(sizeof(*hash));
 hash->nodes_array = kmalloc(len * sizeof(*hash->nodes_array));
 for (unsigned int i = 0; i < len; i++)
  list_init(&hash->nodes_array[i]);
 hash->len = len;
 return hash;
}

variable_types:
len
unsigned int

variable_types: struct hash { int len; struct list_node { struct list_node *next; struct list_node *prev; } *nodes_array; } *

variable_types:
i
unsigned int

user_defined_types: struct hash { int len; struct list_node *nodes_array; }


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

if ( a1 )
{
kfree(*(_QWORD *)(a1 + 8));
result = kfree(a1);
}
else
{
panic("%s:%d - !(hash != NULL)\n", "lib/hash.c", 51LL);
result = hash_insert();
}
return result;
}

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

if ( a1 )
{
kfree(*(_QWORD *)(a1 + 8));
result = kfree(a1);
}
else
{
panic("%s:%d - !(hash != NULL)\n", "lib/hash.c", 51LL);
result = func6();
}
return result;
}

original_code:
void hash_free(struct hash *hash)
{
 do { if (__builtin_expect((!(hash != ((void *)0))), 0)) panic("%s:%d - !(" "hash != NULL" ")\n", "lib/hash.c", 51); } while (0);;
 kfree(hash->nodes_array);
 kfree(hash);
}

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


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

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

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

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


decompiled_code:
__int64 __fastcall kmalloc(int a1)
{
if ( a1 <= 16 )
return _kmalloc(4LL);
if ( a1 <= 32 )
return _kmalloc(5LL);
if ( a1 <= 64 )
return _kmalloc(6LL);
if ( a1 <= 128 )
return _kmalloc(7LL);
return _kmalloc(8LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( a1 <= 16 )
return _kmalloc(4LL);
if ( a1 <= 32 )
return _kmalloc(5LL);
if ( a1 <= 64 )
return _kmalloc(6LL);
if ( a1 <= 128 )
return _kmalloc(7LL);
return _kmalloc(8LL);
}