kfree

decompiled_code:
__int64 __fastcall kfree(__int64 a1)
{
__int64 v1; // r13
unsigned __int8 v2; // bl
int v3; // er12
char *v4; // rbx
__int64 v5; // rax

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // r13
unsigned __int8 v2; // bl
int v3; // er12
char *v4; // rbx
__int64 v5; // rax

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


repo: a-darwish/cuteOS

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

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

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

v0 = (char *)&kmembuckets;
do
{
result = spin_init(v0);
v0 += 32;
}
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

return_type: void


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 func1(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 timer2_start()
{
unsigned __int8 v0; // al

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

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

v0 = func0(0x61u);
return func1(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:
__int64 timer2_stop()
{
unsigned __int8 v0; // al

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

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

v0 = func0(0x61u);
return func1(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 __fastcall pit_set_counter(int a1, unsigned __int16 a2)
{
unsigned __int64 v2; // rax
unsigned int v3; // ebx

if ( a1 <= 0 )
{
panic("%s:%d - !(ms > 0)\n", "dev/pit.c", 142LL);
goto LABEL_6;
}
if ( 1000 / a1 <= 0 )
{
LABEL_6:
panic("%s:%d - !((1000 / ms) > 0)\n", "dev/pit.c", 143LL);
goto LABEL_7;
}
v2 = 0x1234DEuLL / (1000 / a1);
v3 = v2;
if ( (unsigned int)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 pit_mdelay();
}

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

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

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:
unsigned __int8 __fastcall pit_mdelay(int a1)
{
unsigned __int8 result; // al

timer2_stop();
outb(0xB0u, 0x43u);
pit_set_counter(a1, 0x42u);
timer2_start();
while ( 1 )
{
result = inb(0x61u);
if ( (result & 0x20) != 0 )
break;
_mm_pause();
}
return result;
}

canonical_decompiled_code:
unsigned __int8 __fastcall func5(int a1)
{
unsigned __int8 result; // al

func3();
func1(0xB0u, 0x43u);
func4(a1, 0x42u);
func2();
while ( 1 )
{
result = func0(0x61u);
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 __fastcall pit_oneshot(int a1)
{
__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(a1, 0x40u);
}
return result;
}

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

if ( timer0_monotonic )
{
panic("PIT: Programming timer0 as one-shot will stop currently setup monotonic mode");
result = func7();
}
else
{
func1(0x30u, 0x43u);
result = func4(a1, 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 __fastcall pit_monotonic(int a1)
{
timer0_monotonic = 1;
outb(0x34u, 0x43u);
return pit_set_counter(a1, 0x40u);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
timer0_monotonic = 1;
func1(0x34u, 0x43u);
return func4(a1, 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_218;
panic("%s:%d - !(rdheader != NULL)\n", "kern/ramdisk.c", 51LL);
return ramdisk_init();
}

canonical_decompiled_code:
__int64 func0()
{
if ( rdheader )
return ramdisk + dword_218;
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;
}

return_type: void *


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

if ( (unsigned __int64)&_kernel_end <= 0xFFFFFFFF7FFFFFFFLL )
{
panic("%s:%d - !((uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET)\n", "kern/ramdisk.c", 58LL);
goto LABEL_9;
}
if ( (unsigned __int64)&_kernel_end > 0xFFFFFFFF9FFFFFFFLL )
{
LABEL_9:
panic("%s:%d - !((uintptr_t)(__kernel_end) < KTEXT_PAGE_END)\n", "kern/ramdisk.c", 58LL);
goto LABEL_10;
}
if ( (unsigned __int64)&_kernel_end + 0x80000000 > 0x3FFFFFFFFFFFLL )
{
LABEL_10:
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);
goto LABEL_11;
}
rdheader = (__int64)&_kernel_end - 0x7FFF80000000LL;
if ( memcmp((char *)&_kernel_end - 0x7FFF80000000LL, "CUTE-STA", 8uLL) )
{
LABEL_11:
panic("Ramdisk: Invalid header start signature");
goto LABEL_12;
}
if ( memcmp((const void *)(rdheader + 16), "CUTE-END", 8uLL) )
{
LABEL_12:
panic("Ramdisk: Invalid header end signature");
return printk("Ramdisk: No disk image loaded\n");
}
ramdisk = rdheader + 24;
v6 = *(_DWORD *)(rdheader + 12);
dword_218 = v6;
if ( v6 )
return printk("Ramdisk: start address = 0x%lx, length = %d KB\n", rdheader + 24, (unsigned int)(v6 / 1024));
return printk("Ramdisk: No disk image loaded\n");
}

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

if ( (unsigned __int64)&_kernel_end <= 0xFFFFFFFF7FFFFFFFLL )
{
panic("%s:%d - !((uintptr_t)(__kernel_end) >= KTEXT_PAGE_OFFSET)\n", "kern/ramdisk.c", 58LL);
goto LABEL_9;
}
if ( (unsigned __int64)&_kernel_end > 0xFFFFFFFF9FFFFFFFLL )
{
LABEL_9:
panic("%s:%d - !((uintptr_t)(__kernel_end) < KTEXT_PAGE_END)\n", "kern/ramdisk.c", 58LL);
goto LABEL_10;
}
if ( (unsigned __int64)&_kernel_end + 0x80000000 > 0x3FFFFFFFFFFFLL )
{
LABEL_10:
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);
goto LABEL_11;
}
rdheader = (__int64)&_kernel_end - 0x7FFF80000000LL;
if ( memcmp((char *)&_kernel_end - 0x7FFF80000000LL, "CUTE-STA", 8uLL) )
{
LABEL_11:
panic("Ramdisk: Invalid header start signature");
goto LABEL_12;
}
if ( memcmp((const void *)(rdheader + 16), "CUTE-END", 8uLL) )
{
LABEL_12:
panic("Ramdisk: Invalid header end signature");
return printk("Ramdisk: No disk image loaded\n");
}
ramdisk = rdheader + 24;
v6 = *(_DWORD *)(rdheader + 12);
dword_218 = v6;
if ( v6 )
return printk("Ramdisk: start address = 0x%lx, length = %d KB\n", rdheader + 24, (unsigned int)(v6 / 1024));
return printk("Ramdisk: No disk image loaded\n");
}

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

return_type: int


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

canonical_decompiled_code:
__int64 func3()
{
if ( !rdheader )
{
panic("%s:%d - !(rdheader != NULL)\n", "kern/ramdisk.c", 85LL);
JUMPOUT(0x20BLL);
}
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


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; // bx
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; // bx
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; // bx
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; // bx
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; // bx
unsigned __int16 v1; // bp

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();
v0 = port_base;
v1 = port_base + 1;
outb(0, port_base + 1);
enable_DLAB();
outb(1u, v0);
outb(0, v1);
disable_DLAB();
outb(0, v0 + 2);
return outb(3u, v0 + 4);
}

canonical_decompiled_code:
__int64 func8()
{
unsigned __int16 v0; // bx
unsigned __int16 v1; // bp

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();
v0 = port_base;
v1 = port_base + 1;
func1(0, port_base + 1);
func3();
func1(1u, v0);
func1(0, v1);
func4();
func1(0, v0 + 2);
return func1(3u, v0 + 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
unsigned __int8 v4; // di
unsigned __int8 *v5; // rbx
int v6; // eax

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

canonical_decompiled_code:
void __fastcall func9(unsigned __int8 *a1, __int64 a2)
{
__int64 v3; // rdx
unsigned __int8 v4; // di
unsigned __int8 *v5; // rbx
int v6; // eax

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

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:
buf
char *

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 func2(unsigned int *a1)
{
return *a1;
}

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

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

variable_types:
addr
void *

variable_types:
val
unsigned int

return_type: unsigned int


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

v0 = read_msr(0x1Bu);
BYTE1(v0) |= 8u;
return write_msr(0x1Bu, v0);
}

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

v0 = func1(0x1Bu);
BYTE1(v0) |= 8u;
return func0(0x1Bu, 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:
unsigned __int64 read_tsc()
{
unsigned __int64 v0; // rax

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

canonical_decompiled_code:
unsigned __int64 func6()
{
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

return_type: unsigned long


decompiled_code:
__int64 apic_bootstrap_id()
{
if ( bootstrap_apic_id_saved )
return (unsigned __int8)byte_587;
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_587;
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(4276092928LL);
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 func2((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; // eax
int v1; // ebp
unsigned int v2; // ebx
int v3; // eax
unsigned int v4; // eax

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

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

v0 = func17(0x320u);
func10(0x320u, v0 & 0xFFFDFFFF | 0x10000);
func10(0x3E0u, 11);
v1 = 5;
v2 = -1;
while ( 1 )
{
func10(0x380u, -1);
pit_mdelay(5LL);
v3 = func17(0x390u);
if ( v3 == -1 )
break;
v4 = ~v3;
if ( v2 > v4 )
v2 = v4;
if ( !--v1 )
return 200 * v2;
}
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

msr_apicbase_setaddr(4276092928LL);
apic_virt_base = vm_kmap(4276092928LL, 4096LL);
v0 = pit_calibrate_cpu(10);
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();
bootstrap_apic_id = apic_read(0x20u);
bootstrap_apic_id_saved = 1;
return printk("APIC: bootstrap core lapic enabled, apic_id=0x%x\n", HIBYTE(bootstrap_apic_id));
}

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

func4(4276092928LL);
apic_virt_base = vm_kmap(4276092928LL, 4096LL);
v0 = func7(10);
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();
bootstrap_apic_id = func17(0x20u);
bootstrap_apic_id_saved = 1;
return printk("APIC: bootstrap core lapic enabled, apic_id=0x%x\n", HIBYTE(bootstrap_apic_id));
}

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;
while ( (apic_read(0x300u) & 0x1000) != 0 )
{
pit_mdelay(1LL);
if ( !--v0 )
return 0LL;
}
return 1LL;
}

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:
unsigned __int64 __fastcall set_gs(unsigned __int64 a1)
{
return write_msr(0xC0000101, a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(unsigned __int64 a1)
{
return func0(0xC0000101, 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


decompiled_code:
unsigned __int64 get_gs()
{
return read_msr(0xC0000101);
}

canonical_decompiled_code:
unsigned __int64 func3()
{
return func1(0xC0000101);
}

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


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 v0; // dl
unsigned __int8 result; // al

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

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

v0 = func0(0x64u);
result = -1;
if ( (v0 & 1) != 0 )
result = func0(0x60u);
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 func5()
{
int v0; // ebx
unsigned __int8 result; // al

v0 = 128;
do
{
result = func2();
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 keyboard_init()
{
set_intr_gate(0x30u, (unsigned __int64)&kb_handler);
ioapic_setup_isairq(1LL, 48LL, 1LL);
return kbd_flush_buffer();
}

canonical_decompiled_code:
unsigned __int8 func7()
{
func4(0x30u, (unsigned __int64)&kb_handler);
ioapic_setup_isairq(1LL, 48LL, 1LL);
return func5();
}

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(4LL);
}
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 func3(int a1)
{
if ( a1 <= 0 )
{
panic("%s:%d - !(size > 0)\n", "include/kmalloc.h", 102LL);
return _kmalloc(4LL);
}
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();
}

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 = func2(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(char *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // r12
unsigned int v7; // er12

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

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // r12
unsigned int v7; // er12

v2 = *(_QWORD *)a1;
if ( !*(_QWORD *)a1 )
goto LABEL_4;
if ( a2 )
goto LABEL_8;
do
{
a1 = "%s:%d - !(val != NULL)\n";
panic("%s:%d - !(val != NULL)\n", "lib/unrolled_list.c", 169LL);
LABEL_4:
v3 = func4(0, *((_DWORD *)a1 + 2));
v2 = v3;
*(_QWORD *)a1 = v3;
}
while ( !a2 );
if ( v3 )
goto LABEL_8;
v4 = panic("%s:%d - !(head->node != NULL)\n", "lib/unrolled_list.c", 170LL);
while ( 1 )
{
v2 = v4;
LABEL_8:
if ( *(_DWORD *)(v2 + 12) )
break;
v4 = *(_QWORD *)(v2 + 24);
if ( !v4 )
{
v5 = func4(*(_DWORD *)(v2 + 16) + 1, *(_DWORD *)(v2 + 8));
_unode_store_val_in_array(v5, 0, a2);
*(_QWORD *)(v2 + 24) = v5;
return (unsigned int)(*(_DWORD *)(v5 + 8) * *(_DWORD *)(v5 + 16));
}
}
v7 = func1(v2);
_unode_store_val_in_array(v2, v7, a2);
return v7 + *(_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)
{
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__int64 result; // rax

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

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(4LL);
}
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 func4(int a1)
{
if ( a1 <= 0 )
{
panic("%s:%d - !(size > 0)\n", "include/kmalloc.h", 102LL);
return _kmalloc(4LL);
}
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 func5();
}

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


decompiled_code:
__int64 __fastcall hash_new(unsigned int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx

v1 = kmalloc(16);
*(_QWORD *)(v1 + 8) = kmalloc(16 * a1);
if ( a1 )
{
v2 = 0LL;
do
{
list_init((_QWORD *)(*(_QWORD *)(v1 + 8) + v2));
v2 += 16LL;
}
while ( v2 != 16LL * a1 );
}
*(_DWORD *)v1 = a1;
return v1;
}

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 func6(__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 = func7();
}
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 <= 0 )
{
panic("%s:%d - !(size > 0)\n", "include/kmalloc.h", 102LL);
return _kmalloc(4LL);
}
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 ext2_debug_init();
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( a1 <= 0 )
{
panic("%s:%d - !(size > 0)\n", "include/kmalloc.h", 102LL);
return _kmalloc(4LL);
}
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 func1();
}


emitVarDecl

repo: a-krebs/YACC

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

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Make room on the stack for new var %s", *(const char **)a1);
result = emitStmt(128LL, "ADJUST %d", *(unsigned int *)(a1 + 36));
}
}
else
{
doNotEmit = 1;
}
return result;
}

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

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Make room on the stack for new var %s", *(const char **)a1);
result = emitStmt(128LL, "ADJUST %d", *(unsigned int *)(a1 + 36));
}
}
else
{
doNotEmit = 1;
}
return result;
}

original_code:
void emitVarDecl(Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Make room on the stack for new var %s", s->name);
 emitStmt(128, "ADJUST %d", s->size);
}

canonical_original_code:
void emitVarDecl(struct Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Make room on the stack for new var %s", s->name);
 emitStmt(128, "ADJUST %d", s->size);
}

variable_types: struct Symbol { char *name; enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 } kind; union kind_union { struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value { struct Boolean { int value; } Boolean; struct Char { unsigned char value; } Char; struct Integer { int value; } Integer; struct Real { double value; } Real; struct String { char *str; unsigned int strlen; } String; } value; } *ConstKind; struct FunctionKind { struct Symbol *typeSym; struct ElementArray { void **data; unsigned int len; unsigned int nElements; } *params; char *label; int invocationInstance; } *FuncKind; struct ParamKind { struct Symbol *typeSym; int byRef; } *ParamKind; struct ProcedureKind { struct ElementArray *params; char *label; } *ProcKind; struct TypeKind { union type_union { struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; } *Array; struct Function { struct ParamArray { struct Param { char *name; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; struct Symbol *typeSym; } **data; unsigned int len; unsigned int nElements; } *params; struct Symbol *returnTypeSym; char *label; } *Function; struct Procedure { struct ParamArray *params; char *label; } *Procedure; struct Record { struct hash { struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; } *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; } *hash; } *Record; struct Scalar { struct ElementArray *consts; } *Scalar; struct StringType { unsigned int strlen; } *String; struct Subrange { int high; int low; struct Symbol *baseTypeSym; } *Subrange; } typePtr; enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 } type; } *TypeKind; struct VariableKind { struct Symbol *typeSym; int byRef; } *VarKind; } kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; } *

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


emitIntConstDecl

decompiled_code:
__int64 __fastcall emitIntConstDecl(__int64 a1, __int64 a2)
{
emitComment("Push const val = %d on stack, pop it into place.", a2);
emitStmt(128LL, "CONSTI %d", (unsigned int)a2);
return emitStmt(128LL, "POP %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
emitComment("Push const val = %d on stack, pop it into place.", a2);
emitStmt(128LL, "CONSTI %d", (unsigned int)a2);
return emitStmt(128LL, "POP %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}

original_code:
void emitIntConstDecl(Symbol *s, int value)
{
 emitComment("Push const val = %d on stack, pop it into place.", value);
 emitStmt(128, "CONSTI %d", value);
 emitStmt(128, "POP %d[%d]", s->offset, s->lvl);
}

canonical_original_code:
void emitIntConstDecl(struct Symbol *s, int value)
{
 emitComment("Push const val = %d on stack, pop it into place.", value);
 emitStmt(128, "CONSTI %d", value);
 emitStmt(128, "POP %d[%d]", s->offset, s->lvl);
}

variable_types: value int

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


emitRealConstDecl

decompiled_code:
__int64 __fastcall emitRealConstDecl(__int64 a1, float a2)
{
emitComment("Push const val = %f on stack, pop it into place.", a2);
emitStmt(128LL, "CONSTR %f", a2);
return emitStmt(128LL, "POP %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, float a2)
{
emitComment("Push const val = %f on stack, pop it into place.", a2);
emitStmt(128LL, "CONSTR %f", a2);
return emitStmt(128LL, "POP %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}

original_code:
void emitRealConstDecl(Symbol *s, float value)
{
 emitComment("Push const val = %f on stack, pop it into place.", value);
 emitStmt(128, "CONSTR %f", value);
 emitStmt(128, "POP %d[%d]", s->offset, s->lvl);
}

canonical_original_code:
void emitRealConstDecl(struct Symbol *s, float value)
{
 emitComment("Push const val = %f on stack, pop it into place.", value);
 emitStmt(128, "CONSTR %f", value);
 emitStmt(128, "POP %d[%d]", s->offset, s->lvl);
}

variable_types: value float

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


emitStringConstDecl

decompiled_code:
__int64 __fastcall emitStringConstDecl(__int64 a1)
{
emitComment("Creating named string const decl %s", *(const char **)a1);
emitPushAnonConstValue(a1);
return emitStmt(128LL, "POP %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
emitComment("Creating named string const decl %s", *(const char **)a1);
emitPushAnonConstValue(a1);
return emitStmt(128LL, "POP %d[%d]", *(unsigned int *)(a1 + 32), *(unsigned int *)(a1 + 24));
}

original_code:
void emitStringConstDecl(Symbol *s)
{
 emitComment("Creating named string const decl %s", s->name);
 emitPushAnonConstValue(s);
 emitStmt(128, "POP %d[%d]", s->offset, s->lvl);
}

canonical_original_code:
void emitStringConstDecl(struct Symbol *s)
{
 emitComment("Creating named string const decl %s", s->name);
 emitPushAnonConstValue(s);
 emitStmt(128, "POP %d[%d]", s->offset, s->lvl);
}

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


emitConstDecl

decompiled_code:
void __fastcall emitConstDecl(__int64 a1)
{
unsigned int *v1; // rax
unsigned __int8 *v2; // rax
float v3; // xmm0_4

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Make room on the stack for new const %s.", *(const char **)a1);
emitStmt(128LL, "ADJUST %d", *(unsigned int *)(a1 + 36));
switch ( (unsigned int)getType(a1) )
{
case 2u:
case 4u:
v1 = (unsigned int *)getConstVal(a1);
emitIntConstDecl(a1, *v1);
break;
case 3u:
v2 = (unsigned __int8 *)getConstVal(a1);
emitIntConstDecl(a1, *v2);
break;
case 5u:
v3 = *(double *)getConstVal(a1);
emitRealConstDecl(a1, v3);
break;
case 9u:
emitStringConstDecl(a1);
break;
default:
return;
}
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
unsigned int *v1; // rax
unsigned __int8 *v2; // rax
float v3; // xmm0_4

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Make room on the stack for new const %s.", *(const char **)a1);
emitStmt(128LL, "ADJUST %d", *(unsigned int *)(a1 + 36));
switch ( (unsigned int)getType(a1) )
{
case 2u:
case 4u:
v1 = (unsigned int *)getConstVal(a1);
func1(a1, *v1);
break;
case 3u:
v2 = (unsigned __int8 *)getConstVal(a1);
func1(a1, *v2);
break;
case 5u:
v3 = *(double *)getConstVal(a1);
func2(a1, v3);
break;
case 9u:
func3(a1);
break;
default:
return;
}
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitConstDecl(Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Make room on the stack for new const %s.", s->name);
 emitStmt(128, "ADJUST %d", s->size);
 switch (getType(s)) {
 case BOOLEAN_T:
  emitIntConstDecl(s, getConstVal(s)->Boolean.value);
  break;
 case CHAR_T:
  emitIntConstDecl(s, getConstVal(s)->Char.value);
  break;
 case INTEGER_T:
  emitIntConstDecl(s, getConstVal(s)->Integer.value);
  break;
 case REAL_T:
  emitRealConstDecl(s, getConstVal(s)->Real.value);
  break;
 case STRING_T:
  emitStringConstDecl(s);
  break;
 default:
  break;
 }
}

canonical_original_code:
void emitConstDecl(struct Symbol *s)
{
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Make room on the stack for new const %s.", s->name);
 emitStmt(128, "ADJUST %d", s->size);
 switch (getType(s)) {
 case BOOLEAN_T:
  emitIntConstDecl(s, getConstVal(s)->Boolean.value);
  break;
 case CHAR_T:
  emitIntConstDecl(s, getConstVal(s)->Char.value);
  break;
 case INTEGER_T:
  emitIntConstDecl(s, getConstVal(s)->Integer.value);
  break;
 case REAL_T:
  emitRealConstDecl(s, getConstVal(s)->Real.value);
  break;
 case STRING_T:
  emitStringConstDecl(s);
  break;
 default:
  break;
 }
}

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


continueLoop

decompiled_code:
__int64 continueLoop()
{
__int64 v1; // rax

if ( !whileLoopDepth )
{
v1 = customErrorString("A continue statement is only allowed inside a while loop.");
recordError(v1, yylineno, colno, 2LL);
}
return emitGotoLoopTop();
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v1; // rax

if ( !whileLoopDepth )
{
v1 = customErrorString("A continue statement is only allowed inside a while loop.");
recordError(v1, yylineno, colno, 2LL);
}
return emitGotoLoopTop();
}

original_code:
void continueLoop(void) {
 if (whileLoopDepth <= 0) {
  errMsg = customErrorString("A continue statement is only "
      "allowed inside a while loop.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 emitGotoLoopTop();
}

canonical_original_code:
void continueLoop() {
 if (whileLoopDepth <= 0) {
  errMsg = customErrorString("A continue statement is only "
      "allowed inside a while loop.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 emitGotoLoopTop();
}


exitLoop

decompiled_code:
__int64 exitLoop()
{
__int64 v1; // rdi

if ( !whileLoopDepth )
{
v1 = customErrorString("An exit statement is only allowed inside a while loop.");
recordError(v1, yylineno, colno, 2LL);
}
return emitGotoLoopEnd();
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v1; // rdi

if ( !whileLoopDepth )
{
v1 = customErrorString("An exit statement is only allowed inside a while loop.");
recordError(v1, yylineno, colno, 2LL);
}
return emitGotoLoopEnd();
}

original_code:
void exitLoop(void) {
 if (whileLoopDepth <= 0) {
  errMsg = customErrorString("An exit statement is only "
      "allowed inside a while loop.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 emitGotoLoopEnd();
}

canonical_original_code:
void exitLoop() {
 if (whileLoopDepth <= 0) {
  errMsg = customErrorString("An exit statement is only "
      "allowed inside a while loop.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 emitGotoLoopEnd();
}


beginWhileLoop

decompiled_code:
__int64 beginWhileLoop()
{
++whileLoopDepth;
return emitBeginWhile();
}

canonical_decompiled_code:
__int64 func2()
{
++whileLoopDepth;
return emitBeginWhile();
}

original_code:
void beginWhileLoop(void) {
 whileLoopDepth++;
 emitBeginWhile();
}

canonical_original_code:
void beginWhileLoop() {
 whileLoopDepth++;
 emitBeginWhile();
}


whileLoopCondCheck

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

if ( !a1 || (unsigned int)getType() != 2 )
{
v1 = customErrorString("Loop conditions must be ");
recordError(v1, yylineno, colno, 2LL);
}
return emitWhileLoopCondCheck(a1);
}

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

if ( !a1 || (unsigned int)getType() != 2 )
{
v1 = customErrorString("Loop conditions must be ");
recordError(v1, yylineno, colno, 2LL);
}
return emitWhileLoopCondCheck(a1);
}

original_code:
void whileLoopCondCheck(ProxySymbol *expr) {
 if ((expr == ((void *)0)) || (getType(expr) != BOOLEAN_T)) {
  errMsg = customErrorString("Loop conditions must be ",
      "boolean type.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 emitWhileLoopCondCheck(expr);
}

canonical_original_code:
void whileLoopCondCheck(struct Symbol *expr) {
 if ((expr == ((void *)0)) || (getType(expr) != BOOLEAN_T)) {
  errMsg = customErrorString("Loop conditions must be ",
      "boolean type.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 emitWhileLoopCondCheck(expr);
}

user_defined_types: struct Symbol { char *name; enum kind_t kind; union kind_union kindPtr; int lvl; int typeOriginator; int offset; int size; int isAddress; int isRecordHead; struct Symbol *next; }

user_defined_types: union kind_union { struct ConstantKind *ConstKind; struct FunctionKind *FuncKind; struct ParamKind *ParamKind; struct ProcedureKind *ProcKind; struct TypeKind *TypeKind; struct VariableKind *VarKind; }

user_defined_types: struct ConstantKind { int constResultFlag; struct Symbol *typeSym; union anonymous_constant_value value; }

user_defined_types: struct FunctionKind { struct Symbol *typeSym; struct ElementArray *params; char *label; int invocationInstance; }

user_defined_types: struct TypeKind { union type_union typePtr; enum type_t type; }

user_defined_types: union anonymous_constant_value { struct Boolean Boolean; struct Char Char; struct Integer Integer; struct Real Real; struct String String; }

user_defined_types: union type_union { struct Array *Array; struct Function *Function; struct Procedure *Procedure; struct Record *Record; struct Scalar *Scalar; struct StringType *String; struct Subrange *Subrange; }

user_defined_types: struct Function { struct ParamArray *params; struct Symbol *returnTypeSym; char *label; }


gotoLoopTop

decompiled_code:
__int64 gotoLoopTop()
{
return emitGotoLoopTop();
}

canonical_decompiled_code:
__int64 func4()
{
return emitGotoLoopTop();
}

original_code:
void gotoLoopTop() {
 emitGotoLoopTop();
}


endWhileLoop

decompiled_code:
__int64 endWhileLoop()
{
--whileLoopDepth;
return emitEndWhile();
}

canonical_decompiled_code:
__int64 func5()
{
--whileLoopDepth;
return emitEndWhile();
}

original_code:
void endWhileLoop(void) {
 whileLoopDepth--;
 emitEndWhile();
}

canonical_original_code:
void endWhileLoop() {
 whileLoopDepth--;
 emitEndWhile();
}


ifPart

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

if ( !a1 || (unsigned int)getType() != 2 )
{
v1 = customErrorString("If statement must be given ");
recordError(v1, yylineno, colno, 2LL);
}
return emitIfStat(a1);
}

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

if ( !a1 || (unsigned int)getType() != 2 )
{
v1 = customErrorString("If statement must be given ");
recordError(v1, yylineno, colno, 2LL);
}
return emitIfStat(a1);
}

original_code:
void ifPart(ProxySymbol *expr) {
 if ((expr == ((void *)0)) || (getType(expr) != BOOLEAN_T)) {
  errMsg = customErrorString("If statement must be given ",
      "boolean type expression.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 emitIfStat(expr);
}

canonical_original_code:
void ifPart(struct Symbol *expr) {
 if ((expr == ((void *)0)) || (getType(expr) != BOOLEAN_T)) {
  errMsg = customErrorString("If statement must be given ",
      "boolean type expression.");
  recordError(errMsg, yylineno, colno, SEMANTIC);
 }
 emitIfStat(expr);
}

user_defined_types: enum kind_t { CONST_KIND=0, FUNC_KIND=1, PARAM_KIND=2, PROC_KIND=3, TYPE_KIND=4, VAR_KIND=5 }

user_defined_types: struct ParamKind { struct Symbol *typeSym; int byRef; }

user_defined_types: struct ProcedureKind { struct ElementArray *params; char *label; }

user_defined_types: struct VariableKind { struct Symbol *typeSym; int byRef; }

user_defined_types: enum type_t { VOID_T=0, ARRAY_T=1, BOOLEAN_T=2, CHAR_T=3, INTEGER_T=4, REAL_T=5, RECORD_T=6, SCALARINT_T=7, SCALAR_T=8, STRING_T=9, SUBRANGE_T=10 }

user_defined_types: struct ParamArray { struct Param **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct hash { struct hashElement *elements[1000]; int offset[1024]; unsigned int (*hashFunction)(); int lexLevel; }

user_defined_types: struct Param { char *name; enum type_t type; struct Symbol *typeSym; }


thenStatPart

decompiled_code:
__int64 thenStatPart()
{
return emitThenStat();
}

canonical_decompiled_code:
__int64 func7()
{
return emitThenStat();
}

original_code:
void thenStatPart() {
 emitThenStat();
}

canonical_original_code:
void thenStatPart() {
 emitThenStat();
}


thenMatchedStatPart

decompiled_code:
__int64 thenMatchedStatPart()
{
return emitThenMatchedStat();
}

canonical_decompiled_code:
__int64 func8()
{
return emitThenMatchedStat();
}

original_code:
void thenMatchedStatPart() {
 emitThenMatchedStat();
}


elseStatPart

decompiled_code:
__int64 elseStatPart()
{
return emitElseStat();
}

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

original_code:
void elseStatPart() {
 emitElseStat();
}

canonical_original_code:
void elseStatPart() {
 emitElseStat();
}


emitIfStat

decompiled_code:
void __fastcall emitIfStat(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
reserveLabels(labelStack, 2LL);
if ( *(_DWORD *)(a1 + 8) || !(unsigned int)isConstResultSym(a1) )
emitPushSymbolValue(a1);
v1 = peekLabelStackTop(labelStack);
emitComment("IF expr THEN. If 'expr' is false skip to %s%d", "LABEL", v1);
v2 = peekLabelStackTop(labelStack);
emitStmt(128LL, "IFZ %s%d", "LABEL", v2);
}
}
else
{
doNotEmit = 1;
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

if ( a1 )
{
if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
reserveLabels(labelStack, 2LL);
if ( *(_DWORD *)(a1 + 8) || !(unsigned int)isConstResultSym(a1) )
emitPushSymbolValue(a1);
v1 = peekLabelStackTop(labelStack);
emitComment("IF expr THEN. If 'expr' is false skip to %s%d", "LABEL", v1);
v2 = peekLabelStackTop(labelStack);
emitStmt(128LL, "IFZ %s%d", "LABEL", v2);
}
}
else
{
doNotEmit = 1;
}
}

original_code:
void emitIfStat(Symbol *s) {
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 reserveLabels(labelStack, 2);
 if (! (s->kind == CONST_KIND && isConstResultSym(s))) {
  emitPushSymbolValue(s);
 }
 emitComment("IF expr THEN. If 'expr' is false skip to %s%d",
     "LABEL", peekLabelStackTop(labelStack));
 emitStmt(128, "IFZ %s%d",
     "LABEL", peekLabelStackTop(labelStack));
}

canonical_original_code:
void emitIfStat(struct Symbol *s) {
 do { if(!(s) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 reserveLabels(labelStack, 2);
 if (! (s->kind == CONST_KIND && isConstResultSym(s))) {
  emitPushSymbolValue(s);
 }
 emitComment("IF expr THEN. If 'expr' is false skip to %s%d",
     "LABEL", peekLabelStackTop(labelStack));
 emitStmt(128, "IFZ %s%d",
     "LABEL", peekLabelStackTop(labelStack));
}

user_defined_types: struct String { char *str; unsigned int strlen; }

user_defined_types: struct ElementArray { void **data; unsigned int len; unsigned int nElements; }

user_defined_types: struct Array { struct Symbol *baseTypeSym; struct Symbol *indexTypeSym; }

user_defined_types: struct Procedure { struct ParamArray *params; char *label; }

user_defined_types: struct Scalar { struct ElementArray *consts; }

user_defined_types: struct StringType { unsigned int strlen; }

user_defined_types: struct Subrange { int high; int low; struct Symbol *baseTypeSym; }

user_defined_types: struct hashElement { char *key; struct Symbol *symbol; struct hashElement *prev; struct hashElement *next; }


emitThenMatchedStat

decompiled_code:
void emitThenMatchedStat()
{
unsigned int v0; // eax
int v1; // eax
unsigned int v2; // eax

if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Bottom of an IF-THEN.");
emitComment("Either THEN was executed, so GOTO,");
v0 = peekLabelStackTop(labelStack);
emitComment("or land at %s%d if 'expr' was false", "LABEL", v0);
v1 = peekLabelStackTop(labelStack);
emitStmt(128LL, "GOTO %s%d", "LABEL", (unsigned int)(v1 + 1));
v2 = peekLabelStackTop(labelStack);
emitLabel(128LL, "%s%d", "LABEL", v2);
}
}

canonical_decompiled_code:
void func1()
{
unsigned int v0; // eax
int v1; // eax
unsigned int v2; // eax

if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Bottom of an IF-THEN.");
emitComment("Either THEN was executed, so GOTO,");
v0 = peekLabelStackTop(labelStack);
emitComment("or land at %s%d if 'expr' was false", "LABEL", v0);
v1 = peekLabelStackTop(labelStack);
emitStmt(128LL, "GOTO %s%d", "LABEL", (unsigned int)(v1 + 1));
v2 = peekLabelStackTop(labelStack);
emitLabel(128LL, "%s%d", "LABEL", v2);
}
}

original_code:
void emitThenMatchedStat() {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Bottom of an IF-THEN.");
 emitComment("Either THEN was executed, so GOTO,");
 emitComment("or land at %s%d if 'expr' was false",
     "LABEL", peekLabelStackTop(labelStack));
 emitStmt(128, "GOTO %s%d",
     "LABEL", peekLabelStackTop(labelStack) + 1);
 emitLabel(128, "%s%d",
     "LABEL", peekLabelStackTop(labelStack));
}


emitElseStat

decompiled_code:
void emitElseStat()
{
int v0; // eax

if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Bottom of ELSE stat");
v0 = peekLabelStackTop(labelStack);
emitLabel(128LL, "%s%d", "LABEL", (unsigned int)(v0 + 1));
popLabels(labelStack);
}
}

canonical_decompiled_code:
void func2()
{
int v0; // eax

if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Bottom of ELSE stat");
v0 = peekLabelStackTop(labelStack);
emitLabel(128LL, "%s%d", "LABEL", (unsigned int)(v0 + 1));
popLabels(labelStack);
}
}

original_code:
void emitElseStat() {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Bottom of ELSE stat");
 emitLabel(128, "%s%d",
     "LABEL", peekLabelStackTop(labelStack) + 1);
 popLabels(labelStack);
}


emitThenStat

decompiled_code:
void emitThenStat()
{
unsigned int v0; // eax

if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Bottom of IF-THEN as part of IF-THEN");
v0 = peekLabelStackTop(labelStack);
emitLabel(128LL, "%s%d", "LABEL", v0);
popLabels(labelStack);
}
}

canonical_decompiled_code:
void func3()
{
unsigned int v0; // eax

if ( doNotEmit )
{
doNotEmit = 1;
}
else
{
emitComment("Bottom of IF-THEN as part of IF-THEN");
v0 = peekLabelStackTop(labelStack);
emitLabel(128LL, "%s%d", "LABEL", v0);
popLabels(labelStack);
}
}

original_code:
void emitThenStat() {
 do { if(!(1) || (doNotEmit)) { doNotEmit = 1; return; }} while (0);
 emitComment("Bottom of IF-THEN as part of IF-THEN");
 emitLabel(128, "%s%d",
     "LABEL", peekLabelStackTop(labelStack));
 popLabels(labelStack);
}