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

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

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

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

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

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

variable_types:
reg
unsigned char

variable_types:
ioregsel
unsigned int *

variable_types:
iowin
unsigned int *


repo: a-darwish/cuteOS

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

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

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

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

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

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

variable_types: apic int

variable_types:
irq
unsigned char

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


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

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

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

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

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

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

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

variable_types: irq int

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


decompiled_code:
signed __int64 ioapic_init()
{
int *v0; // r12
unsigned int v1; // ebp
__int64 v2; // rax
unsigned int v3; // ebx
__int64 v4; // rbx
signed __int64 result; // rax
unsigned int v6; // ebp
int *v7; // r13
int v8; // ebp
int v9; // ebx

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

canonical_decompiled_code:
signed __int64 func11()
{
int *v0; // r12
unsigned int v1; // ebp
__int64 v2; // rax
unsigned int v3; // ebx
__int64 v4; // rbx
signed __int64 result; // rax
unsigned int v6; // ebp
int *v7; // r13
int v8; // ebp
int v9; // ebx

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

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

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

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

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

return_type: void

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


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

if ( !a2 )
return 0;
v2 = (__int64)&a1[a2 - 1 + 1];
result = 0;
do
result += *a1++;
while ( a1 != (_BYTE *)v2 );
return result;
}

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

if ( !a2 )
return 0;
v2 = (__int64)&a1[a2 - 1 + 1];
result = 0;
do
result += *a1++;
while ( a1 != (_BYTE *)v2 );
return result;
}

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

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

variable_types:
mp
void *

variable_types:
len
unsigned int

variable_types:
sum
unsigned char

variable_types:
buf
unsigned char *

return_type: unsigned char


decompiled_code:
__int64 __fastcall parse_cpu(const char *a1)
{
__int64 result; // rax
int v2; // esi

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

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

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

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

variable_types:
addr
void *

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


decompiled_code:
void __fastcall parse_ioapic(__int64 a1)
{
int v1; // eax

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

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
int v1; // eax

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

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

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


decompiled_code:
__int64 __fastcall parse_irq(__int64 *a1)
{
int v1; // eax
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
int v1; // eax
__int64 result; // rax

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

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

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


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

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

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

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

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

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

variable_types:
ebda
unsigned long

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


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

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

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

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

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

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

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

variable_types:
checksum
unsigned char

return_type: int


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall parse_mpc(__int64 a1)
{
int v1; // ebp
__int64 v2; // r12
unsigned __int64 v3; // r13
unsigned __int64 v4; // r14
char *v5; // r15
unsigned __int64 v7; // rdi
char *v8; // rax
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ebp
__int64 v2; // r12
unsigned __int64 v3; // r13
unsigned __int64 v4; // r14
char *v5; // r15
unsigned __int64 v7; // rdi
char *v8; // rax
__int64 result; // rax

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

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

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

variable_types:
entry
unsigned char *

variable_types: i int

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

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

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

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

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

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


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

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

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

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

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

variable_types:
signature
char [5]


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

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

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

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

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

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


decompiled_code:
__int64 __fastcall mptables_init()
{
void *v0; // rbx
_BYTE *v1; // rax
unsigned int v2; // edi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func10()
{
void *v0; // rbx
_BYTE *v1; // rax
unsigned int v2; // edi
__int64 result; // rax

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

return_type: unsigned long


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

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

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

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

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

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

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


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

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

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

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


readl

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

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

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

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

variable_types:
val
unsigned int

return_type: unsigned int


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

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

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


decompiled_code:
__int64 __fastcall start_secondary_cpu(__int64 a1, __int64 a2)
{
int v2; // er13
unsigned int v3; // er14
unsigned int i; // ebx
int v5; // ebx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // er13
unsigned int v3; // er14
unsigned int i; // ebx
int v5; // ebx
__int64 result; // rax

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

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

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

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

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

variable_types: count int

variable_types: acked int

variable_types: timeout int

variable_types: j int

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

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

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

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

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


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

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

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

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


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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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


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

__writeeflags(v0);
}

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

__writeeflags(v0);
}

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

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


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

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

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

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


decompiled_code:
unsigned __int64 local_irq_disable_save()
{
unsigned __int64 v0; // rbx

v0 = get_rflags();
if ( (v0 & 0x200) != 0 )
local_irq_disable();
return v0;
}

canonical_decompiled_code:
unsigned __int64 func3()
{
unsigned __int64 v0; // rbx

v0 = func0();
if ( (v0 & 0x200) != 0 )
func2();
return v0;
}

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

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

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


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

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


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

v1 = local_irq_disable_save();
while ( 1 )
{
result = atomic_bit_test_and_set(a1);
if ( (_BYTE)result != 1 )
break;
local_irq_restore(v1);
while ( *(_DWORD *)a1 == 1 )
_mm_pause();
local_irq_disable();
}
*(_QWORD *)(a1 + 8) = v1;
return result;
}

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

v1 = func3();
while ( 1 )
{
result = atomic_bit_test_and_set(a1);
if ( (_BYTE)result != 1 )
break;
func4(v1);
while ( *(_DWORD *)a1 == 1 )
_mm_pause();
func2();
}
*(_QWORD *)(a1 + 8) = v1;
return result;
}

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

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

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


decompiled_code:
__int64 __fastcall spin_trylock(__int64 a1)
{
unsigned __int64 v1; // rbp
__int64 result; // rax

v1 = local_irq_disable_save();
if ( (unsigned __int8)atomic_bit_test_and_set(a1) == 1 )
{
local_irq_restore(v1);
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) = v1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
unsigned __int64 v1; // rbp
__int64 result; // rax

v1 = func3();
if ( (unsigned __int8)atomic_bit_test_and_set(a1) == 1 )
{
func4(v1);
result = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) = v1;
result = 1LL;
}
return result;
}

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


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

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

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


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

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

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

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

variable_types:
val
unsigned int *

variable_types:
ret
unsigned char


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

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

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

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

variable_types:
val
unsigned long *

variable_types:
i
unsigned long


outb

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

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

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

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

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

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

variable_types:
val
unsigned char

variable_types:
port
unsigned short


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

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

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

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

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

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


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

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

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

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


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

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

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

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


decompiled_code:
__int64 pic_init()
{
int i; // ebx
__int64 result; // rax

outb_pic(0x11u, 0x20u);
outb_pic(0x11u, 0xA0u);
outb_pic(0x20u, 0x21u);
outb_pic(0x28u, 0xA1u);
outb_pic(4u, 0x21u);
outb_pic(2u, 0xA1u);
outb_pic(3u, 0x21u);
outb_pic(3u, 0xA1u);
i8259_mask();
for ( i = 32; i != 40; ++i )
set_intr_gate(i, (unsigned __int64)&PIC_handler);
do
result = set_intr_gate(i++, (unsigned __int64)&PIC_handler);
while ( i != 48 );
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int i; // ebx
__int64 result; // rax

func3(0x11u, 0x20u);
func3(0x11u, 0xA0u);
func3(0x20u, 0x21u);
func3(0x28u, 0xA1u);
func3(4u, 0x21u);
func3(2u, 0xA1u);
func3(3u, 0x21u);
func3(3u, 0xA1u);
func4();
for ( i = 32; i != 40; ++i )
func6(i, (unsigned __int64)&PIC_handler);
do
result = func6(i++, (unsigned __int64)&PIC_handler);
while ( i != 48 );
return result;
}

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

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

variable_types: i int


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

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

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

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

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

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

variable_types:
error
unsigned int

return_type: char *


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

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

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

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

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

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

variable_types:
type
unsigned int


decompiled_code:
__int64 __fastcall validate_e820h_struct()
{
unsigned __int64 v0; // rbx
unsigned int v1; // ebp
const char *v2; // rax
unsigned int v3; // edi
unsigned int v4; // eax
__int64 result; // rax
const char *v6; // rax

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

canonical_decompiled_code:
__int64 __fastcall func4()
{
unsigned __int64 v0; // rbx
unsigned int v1; // ebp
const char *v2; // rax
unsigned int v3; // edi
unsigned int v4; // eax
__int64 result; // rax
const char *v6; // rax

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

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

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

variable_types:
entry
unsigned int *

variable_types:
err
unsigned int

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


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

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

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

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

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


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

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

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

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

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

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


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

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

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

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


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

v2 = (a2 >> 12) | *(_QWORD *)a1 & 0xFFF0000000000000LL;
*(_QWORD *)a1 = v2;
result = BYTE6(v2) & 0x1F | 0xFFFFFF90;
*(_BYTE *)(a1 + 6) = BYTE6(v2) & 0x1F | 0x90;
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

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

v2 = (a2 >> 12) | *(_QWORD *)a1 & 0xFFF0000000000000LL;
*(_QWORD *)a1 = v2;
result = BYTE6(v2) & 0x1F | 0xFFFFFF90;
*(_BYTE *)(a1 + 6) = BYTE6(v2) & 0x1F | 0x90;
*(_QWORD *)(a1 + 8) = 0LL;
return result;
}

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

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

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


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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

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

return_type: void *


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

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

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

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

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

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

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


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

qword_8A0 = 0LL;
spin_init(&unk_8A8);
qword_8B8 = 0LL;
qword_8C0 = 0LL;
qword_8E8 = 0LL;
result = spin_init(&unk_8F0);
qword_900 = 0LL;
qword_908 = 0LL;
return result;
}

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

qword_8A0 = 0LL;
spin_init(&unk_8A8);
qword_8B8 = 0LL;
qword_8C0 = 0LL;
qword_8E8 = 0LL;
result = spin_init(&unk_8F0);
qword_900 = 0LL;
qword_908 = 0LL;
return result;
}

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

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

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


decompiled_code:
__int64 __fastcall free_page(__int64 a1)
{
int *v1; // rbp
__int64 result; // rax
__int64 v3; // rax

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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int *v1; // rbp
__int64 result; // rax
__int64 v3; // rax

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

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

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


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

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


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

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

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

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

variable_types:
buf
void *

variable_types:
signature
unsigned int


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

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


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

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


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

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

variable_types:
buf
char *

variable_types:
start
char *

variable_types:
end
char *