decompiled_code:
__int64 sys_unimp()
{
printf("sys_unimp: %ld\n", 0LL);
return -38LL;
}

canonical_decompiled_code:
__int64 func6()
{
printf("sys_unimp: %ld\n", 0LL);
return -38LL;
}

original_code:
long sys_unimp(void)
{
 uint64_t num = 0;
 __asm__ volatile ( "mov %%rax, %0" :: "m"(num) );
 printf("sys_unimp: %ld\n", num);
 return -38;
}

canonical_original_code:
long sys_unimp()
{
 unsigned long num = 0;
 __asm__ volatile ( "mov %%rax, %0" :: "m"(num) );
 printf("sys_unimp: %ld\n", num);
 return -38;
}

variable_types:
num
unsigned long


repo: juur/FailOS

decompiled_code:
__int64 __fastcall sys_ioctl(unsigned int a1, unsigned int a2, __int64 a3)
{
printf("sys_ioctl: %x, %x, %lx\n", a1, a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2, __int64 a3)
{
printf("sys_ioctl: %x, %x, %lx\n", a1, a2, a3);
return 0LL;
}

original_code:
long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
{
 printf("sys_ioctl: %x, %x, %lx\n", fd, cmd, arg);
 return 0;
}

variable_types:
fd
unsigned int

variable_types:
cmd
unsigned int

variable_types:
arg
unsigned long

return_type: long


decompiled_code:
int syscall_init()
{
__int64 *v0; // rax

printf("syscall_init: ");
v0 = sc_tbl;
do
*v0++ = (__int64)sys_unimp;
while ( v0 != &sc_tbl[232] );
sc_tbl[43] = (__int64)&sys_accept;
sc_tbl[158] = (__int64)sys_arch_prctl;
sc_tbl[49] = (__int64)&sys_bind;
sc_tbl[12] = (__int64)sys_brk;
sc_tbl[3] = (__int64)&sys_close;
sc_tbl[85] = (__int64)&sys_creat;
sc_tbl[59] = (__int64)&sys_execve;
sc_tbl[60] = (__int64)&sys_exit;
sc_tbl[231] = (__int64)&sys_exit_group;
sc_tbl[57] = (__int64)&sys_fork;
sc_tbl[108] = (__int64)&sys_getegid;
sc_tbl[107] = (__int64)&sys_geteuid;
sc_tbl[104] = (__int64)&sys_getgid;
sc_tbl[39] = (__int64)sys_getpid;
sc_tbl[110] = (__int64)sys_getppid;
sc_tbl[186] = (__int64)sys_gettid;
sc_tbl[102] = (__int64)&sys_getuid;
sc_tbl[16] = (__int64)sys_ioctl;
sc_tbl[62] = (__int64)sys_kill;
sc_tbl[100] = (__int64)sys_kludge;
sc_tbl[50] = (__int64)&sys_listen;
sc_tbl[83] = (__int64)&sys_mkdir;
sc_tbl[2] = (__int64)&sys_open;
sc_tbl[34] = (__int64)sys_pause;
sc_tbl[0] = (__int64)&sys_read;
sc_tbl[41] = (__int64)&sys_socket;
sc_tbl[201] = (__int64)&sys_time;
sc_tbl[61] = (__int64)&sys_wait4;
sc_tbl[1] = (__int64)&sys_write;
return printf("done\n");
}

canonical_decompiled_code:
int func12()
{
__int64 *v0; // rax

printf("syscall_init: ");
v0 = sc_tbl;
do
*v0++ = (__int64)sys_unimp;
while ( v0 != &sc_tbl[232] );
sc_tbl[43] = (__int64)&sys_accept;
sc_tbl[158] = (__int64)sys_arch_prctl;
sc_tbl[49] = (__int64)&sys_bind;
sc_tbl[12] = (__int64)sys_brk;
sc_tbl[3] = (__int64)&sys_close;
sc_tbl[85] = (__int64)&sys_creat;
sc_tbl[59] = (__int64)&sys_execve;
sc_tbl[60] = (__int64)&sys_exit;
sc_tbl[231] = (__int64)&sys_exit_group;
sc_tbl[57] = (__int64)&sys_fork;
sc_tbl[108] = (__int64)&sys_getegid;
sc_tbl[107] = (__int64)&sys_geteuid;
sc_tbl[104] = (__int64)&sys_getgid;
sc_tbl[39] = (__int64)sys_getpid;
sc_tbl[110] = (__int64)sys_getppid;
sc_tbl[186] = (__int64)sys_gettid;
sc_tbl[102] = (__int64)&sys_getuid;
sc_tbl[16] = (__int64)sys_ioctl;
sc_tbl[62] = (__int64)sys_kill;
sc_tbl[100] = (__int64)sys_kludge;
sc_tbl[50] = (__int64)&sys_listen;
sc_tbl[83] = (__int64)&sys_mkdir;
sc_tbl[2] = (__int64)&sys_open;
sc_tbl[34] = (__int64)sys_pause;
sc_tbl[0] = (__int64)&sys_read;
sc_tbl[41] = (__int64)&sys_socket;
sc_tbl[201] = (__int64)&sys_time;
sc_tbl[61] = (__int64)&sys_wait4;
sc_tbl[1] = (__int64)&sys_write;
return printf("done\n");
}

original_code:
void syscall_init(void)
{
 printf("syscall_init: ");
 for(int i=0; i<232; i++)
  sc_tbl[i] = (voidfunc)sys_unimp;
 sc_tbl[43] = (voidfunc)sys_accept;
 sc_tbl[158] = (voidfunc)sys_arch_prctl;
 sc_tbl[49] = (voidfunc)sys_bind;
 sc_tbl[12] = (voidfunc)sys_brk;
 sc_tbl[3] = (voidfunc)sys_close;
 sc_tbl[85] = (voidfunc)sys_creat;
 sc_tbl[59] = (voidfunc)sys_execve;
 sc_tbl[60] = (voidfunc)sys_exit;
 sc_tbl[231] = (voidfunc)sys_exit_group;
 sc_tbl[57] = (voidfunc)sys_fork;
 sc_tbl[108] = (voidfunc)sys_getegid;
 sc_tbl[107] = (voidfunc)sys_geteuid;
 sc_tbl[104] = (voidfunc)sys_getgid;
 sc_tbl[39] = (voidfunc)sys_getpid;
 sc_tbl[110] = (voidfunc)sys_getppid;
 sc_tbl[186] = (voidfunc)sys_gettid;
 sc_tbl[102] = (voidfunc)sys_getuid;
 sc_tbl[16] = (voidfunc)sys_ioctl;
 sc_tbl[62] = (voidfunc)sys_kill;
 sc_tbl[100] = (voidfunc)sys_kludge;
 sc_tbl[50] = (voidfunc)sys_listen;
    sc_tbl[83] = (voidfunc)sys_mkdir;
 sc_tbl[2] = (voidfunc)sys_open;
 sc_tbl[34] = (voidfunc)sys_pause;
 sc_tbl[0] = (voidfunc)sys_read;
 sc_tbl[41] = (voidfunc)sys_socket;
 sc_tbl[201] = (voidfunc)sys_time;
 sc_tbl[61] = (voidfunc)sys_wait4;
 sc_tbl[1] = (voidfunc)sys_write;
 printf("done\n");
}

canonical_original_code:
void syscall_init()
{
 printf("syscall_init: ");
 for(int i = 0; i<232; i++)
  sc_tbl[i] = (void (*)())sys_unimp;
 sc_tbl[43] = (void (*)())sys_accept;
 sc_tbl[158] = (void (*)())sys_arch_prctl;
 sc_tbl[49] = (void (*)())sys_bind;
 sc_tbl[12] = (void (*)())sys_brk;
 sc_tbl[3] = (void (*)())sys_close;
 sc_tbl[85] = (void (*)())sys_creat;
 sc_tbl[59] = (void (*)())sys_execve;
 sc_tbl[60] = (void (*)())sys_exit;
 sc_tbl[231] = (void (*)())sys_exit_group;
 sc_tbl[57] = (void (*)())sys_fork;
 sc_tbl[108] = (void (*)())sys_getegid;
 sc_tbl[107] = (void (*)())sys_geteuid;
 sc_tbl[104] = (void (*)())sys_getgid;
 sc_tbl[39] = (void (*)())sys_getpid;
 sc_tbl[110] = (void (*)())sys_getppid;
 sc_tbl[186] = (void (*)())sys_gettid;
 sc_tbl[102] = (void (*)())sys_getuid;
 sc_tbl[16] = (void (*)())sys_ioctl;
 sc_tbl[62] = (void (*)())sys_kill;
 sc_tbl[100] = (void (*)())sys_kludge;
 sc_tbl[50] = (void (*)())sys_listen;
    sc_tbl[83] = (void (*)())sys_mkdir;
 sc_tbl[2] = (void (*)())sys_open;
 sc_tbl[34] = (void (*)())sys_pause;
 sc_tbl[0] = (void (*)())sys_read;
 sc_tbl[41] = (void (*)())sys_socket;
 sc_tbl[201] = (void (*)())sys_time;
 sc_tbl[61] = (void (*)())sys_wait4;
 sc_tbl[1] = (void (*)())sys_write;
 printf("done\n");
}

variable_types: i int

return_type: void


decompiled_code:
int __fastcall print_mac(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
int result; // eax

v1 = a1 + 1;
printf("%x", *a1);
do
{
++v1;
printf(":");
result = printf("%x", *(v1 - 1));
}
while ( v1 != a1 + 6 );
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rbx
int result; // eax

v1 = a1 + 1;
printf("%x", *a1);
do
{
++v1;
printf(":");
result = printf("%x", *(v1 - 1));
}
while ( v1 != a1 + 6 );
return result;
}

original_code:
void print_mac(uint8_t t[6])
{
 int i,max=6;
 for(i=0;i<max;i++) {
  printf("%x", (uint32_t)(0 + (t[i] & 0xff)));
  if(i<max-1) printf(":");
 }
}

canonical_original_code:
void print_mac(unsigned char t[6])
{
 int i; int max = 6;
 for(i=0;i<max;i++) {
  printf("%x", (unsigned int)(0 + (t[i] & 0xff)));
  if(i<max-1) printf(":");
 }
}

variable_types:
t
unsigned char [6]

variable_types: max int


decompiled_code:
__int64 __fastcall send_frame(unsigned int *a1, const void *a2, const void *a3, const void *a4, unsigned __int16 a5)
{
unsigned __int16 v6; // bx
_WORD *v7; // r12
int v8; // edx
__int64 result; // rax

v6 = 1500;
v7 = (_WORD *)*a1;
if ( a5 <= 0x5DCu )
v6 = a5;
memcpy(v7 + 7, a4, v6);
v7[6] = htons(v6 + 14);
memcpy(v7 + 3, a2, 6uLL);
memcpy(v7, a3, 6uLL);
v8 = *((unsigned __int8 *)a1 + 5);
*((_BYTE *)a1 + 4) = -14 - v6;
v8 &= 0xFFFFFFF0;
result = v8 | ((unsigned __int16)(-14 - v6) >> 8) & 0xFu;
*((_BYTE *)a1 + 5) = v8 | ((unsigned __int16)(-14 - v6) >> 8) & 0xF;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, const void *a2, const void *a3, const void *a4, unsigned __int16 a5)
{
unsigned __int16 v6; // bx
_WORD *v7; // r12
int v8; // edx
__int64 result; // rax

v6 = 1500;
v7 = (_WORD *)*a1;
if ( a5 <= 0x5DCu )
v6 = a5;
memcpy(v7 + 7, a4, v6);
v7[6] = htons(v6 + 14);
memcpy(v7 + 3, a2, 6uLL);
memcpy(v7, a3, 6uLL);
v8 = *((unsigned __int8 *)a1 + 5);
*((_BYTE *)a1 + 4) = -14 - v6;
v8 &= 0xFFFFFFF0;
result = v8 | ((unsigned __int16)(-14 - v6) >> 8) & 0xFu;
*((_BYTE *)a1 + 5) = v8 | ((unsigned __int16)(-14 - v6) >> 8) & 0xF;
return result;
}

original_code:
__attribute__((nonnull)) void send_frame(struct pcnet_tx_32 *b, uint8_t src[6], uint8_t dst[6],
  const char *d, uint16_t len)
{
 struct eth_frame *f = (struct eth_frame *)(0L + b->TBADR);
 if(len>1500) len = 1500;
 memcpy(&f->data, d, len);
 f->len = htons(len + 6 + 6 + 2 );
 memcpy(f->src,src,6);
 memcpy(f->dst,dst,6);
 b->BCNT = ((~(len + 6 + 6 + 2))+1);
}

canonical_original_code:
void send_frame(struct pcnet_tx_32 *b, unsigned char src[6], unsigned char dst[6], char *d, unsigned short len)
{
 struct eth_frame *f = (struct eth_frame *)(0L + b->TBADR);
 if(len>1500) len = 1500;
 memcpy(&f->data, d, len);
 f->len = htons(len + 6 + 6 + 2 );
 memcpy(f->src,src,6);
 memcpy(f->dst,dst,6);
 b->BCNT = ((~(len + 6 + 6 + 2))+1);
}

variable_types: struct pcnet_tx_32 { unsigned int TBADR; unsigned short BCNT; unsigned int ones; unsigned int res1; unsigned int ENP; unsigned int STP; unsigned int DEF; unsigned int ONE; unsigned int MORE; unsigned int ADD_NO_FCS; unsigned int ERR; unsigned int OWN; unsigned int TRC; unsigned short RES; unsigned short TDR; unsigned int RTRY; unsigned int LCAR; unsigned int LCOL; unsigned int EXDEF; unsigned int UFLO; unsigned int BUFF; } *

variable_types:
src
unsigned char [6]

variable_types:
dst
unsigned char [6]

variable_types:
d
char *

variable_types:
len
unsigned short

variable_types: struct eth_frame { unsigned char dst[6]; unsigned char src[6]; unsigned short len; unsigned char data[1500]; } *


writeCSR

decompiled_code:
__int64 __fastcall writeCSR(__int16 a1)
{
outportl((unsigned __int16)(a1 + 20));
return outportl((unsigned __int16)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int16 a1)
{
outportl((unsigned __int16)(a1 + 20));
return outportl((unsigned __int16)(a1 + 16));
}

original_code:
void writeCSR(uint32_t base, uint32_t index, uint32_t val)
{
 outportl(base + 0x14, index);
 outportl(base + 0x10, val);
}

canonical_original_code:
void writeCSR(unsigned int base, unsigned int index, unsigned int val)
{
 outportl(base + 0x14, index);
 outportl(base + 0x10, val);
}

variable_types:
base
unsigned int

variable_types:
index
unsigned int

variable_types:
val
unsigned int


readCSR

decompiled_code:
__int64 __fastcall readCSR(__int16 a1)
{
outportl((unsigned __int16)(a1 + 20));
return inportl((unsigned __int16)(a1 + 16));
}

canonical_decompiled_code:
__int64 __fastcall func9(__int16 a1)
{
outportl((unsigned __int16)(a1 + 20));
return inportl((unsigned __int16)(a1 + 16));
}

original_code:
uint32_t readCSR(uint32_t base, uint32_t index)
{
 outportl(base + 0x14, index);
 return inportl(base + 0x10);
}

canonical_original_code:
unsigned int readCSR(unsigned int base, unsigned int index)
{
 outportl(base + 0x14, index);
 return inportl(base + 0x10);
}

return_type: unsigned int


writeBCR

decompiled_code:
__int64 __fastcall writeBCR(__int16 a1)
{
outportl((unsigned __int16)(a1 + 20));
return outportl((unsigned __int16)(a1 + 28));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int16 a1)
{
outportl((unsigned __int16)(a1 + 20));
return outportl((unsigned __int16)(a1 + 28));
}

original_code:
void writeBCR(uint32_t base, uint32_t index, uint32_t val)
{
 outportl(base + 0x14, index);
 outportl(base + 0x1C, val);
}

canonical_original_code:
void writeBCR(unsigned int base, unsigned int index, unsigned int val)
{
 outportl(base + 0x14, index);
 outportl(base + 0x1C, val);
}


readBCR

decompiled_code:
__int64 __fastcall readBCR(__int16 a1)
{
outportl((unsigned __int16)(a1 + 20));
return inportl((unsigned __int16)(a1 + 28));
}

canonical_decompiled_code:
__int64 __fastcall func11(__int16 a1)
{
outportl((unsigned __int16)(a1 + 20));
return inportl((unsigned __int16)(a1 + 28));
}

original_code:
uint32_t readBCR(uint32_t base, uint32_t index)
{
 outportl(base + 0x14, index);
 return inportl(base + 0x1C);
}

canonical_original_code:
unsigned int readBCR(unsigned int base, unsigned int index)
{
 outportl(base + 0x14, index);
 return inportl(base + 0x1C);
}


decompiled_code:
__int64 con_pending()
{
return *(int *)(*(_QWORD *)(*(_QWORD *)(con_dev + 16) + 104LL) + 20LL);
}

original_code:
ssize_t con_pending(struct char_dev *dev)
{
 struct con_private *p = (struct con_private *)con_dev->priv;
 return p->rh->data;
}

canonical_original_code:
long con_pending(struct char_dev *dev)
{
 struct con_private *p = (struct con_private *)con_dev->priv;
 return p->rh->data;
}

variable_types: struct char_dev { unsigned long devid; struct char_ops { char *name; long (*read)(struct char_dev *, char *, unsigned long); long (*write)(struct char_dev *, char *, unsigned long); int (*init)(struct char_dev *); long (*pending)(struct char_dev *); } *ops; void *priv; } *

variable_types: struct con_private { char buf[100]; struct ring_head { unsigned char *buffer; int length; int read; int write; int data; } *rh; int head; } *

user_defined_types: struct char_dev { unsigned long devid; struct char_ops *ops; void *priv; }

user_defined_types: struct con_private { char buf[100]; struct ring_head *rh; int head; }


decompiled_code:
__int64 __fastcall ser_pending(__int64 a1)
{
return *(int *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 104LL) + 20LL);
}

original_code:
__attribute__((nonnull)) static ssize_t ser_pending(struct char_dev *dev)
{
 struct ser_private *p = (struct ser_private *)dev->priv;
 return p->rh->data;
}

canonical_original_code:
static long ser_pending(struct char_dev *dev)
{
 struct ser_private *p = (struct ser_private *)dev->priv;
 return p->rh->data;
}

variable_types: struct ser_private { char buf[100]; struct ring_head { unsigned char *buffer; int length; int read; int write; int data; } *rh; int head; unsigned short port; } *

user_defined_types: struct ser_private { char buf[100]; struct ring_head *rh; int head; unsigned short port; }

user_defined_types: struct char_ops { char *name; long (*read)(struct char_dev *, char *, unsigned long); long (*write)(struct char_dev *, char *, unsigned long); int (*init)(struct char_dev *); long (*pending)(struct char_dev *); }


decompiled_code:
__int64 __fastcall con_read(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r13
__int64 result; // rax
__int64 i; // rbx

v3 = *(_QWORD *)(con_dev + 16);
result = 0LL;
if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
if ( !(unsigned __int8)ring_read(*(_QWORD *)(v3 + 104), a2 + i) )
return i;
}
result = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r13
__int64 result; // rax
__int64 i; // rbx

v3 = *(_QWORD *)(con_dev + 16);
result = 0LL;
if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
if ( !(unsigned __int8)ring_read(*(_QWORD *)(v3 + 104), a2 + i) )
return i;
}
result = a3;
}
return result;
}

original_code:
ssize_t con_read(struct char_dev *_dev, char *dest, size_t len)
{
 size_t cnt = 0;
 uint8_t *dst_ptr = (uint8_t *)dest;
 struct con_private *p = (struct con_private *)con_dev->priv;
 while(len-- && ring_read(p->rh,dst_ptr++)) cnt++;
 return cnt;
}

canonical_original_code:
long con_read(struct char_dev *_dev, char *dest, unsigned long len)
{
 unsigned long cnt = 0;
 unsigned char *dst_ptr = (uint8_t *)dest;
 struct con_private *p = (struct con_private *)con_dev->priv;
 while(len-- && ring_read(p->rh,dst_ptr++)) cnt++;
 return cnt;
}

variable_types:
dest
char *

variable_types:
len
unsigned long

variable_types:
cnt
unsigned long

user_defined_types: struct ring_head { unsigned char *buffer; int length; int read; int write; int data; }


original_code:
__attribute__((nonnull)) static ssize_t ser_read(struct char_dev *const dev, char *const dest, const size_t len)
{
 size_t cnt = 0;
 size_t rem = len;
 struct ser_private *p = (struct ser_private *)dev->priv;
 uint8_t *dst = (uint8_t *)dest;
 __asm__ volatile("sti");
 while(rem) {
  while(!p->rh->data) {
   __asm__ volatile("pause");
  }
  while(rem && ring_read(p->rh,dst++)) {
   cnt++;
   rem--;
  }
 }
 __asm__ volatile("cli");
 return cnt;
}

canonical_original_code:
static long ser_read(struct char_dev *dev, char *dest, unsigned long len)
{
 unsigned long cnt = 0;
 unsigned long rem = len;
 struct ser_private *p = (struct ser_private *)dev->priv;
 unsigned char *dst = (uint8_t *)dest;
 __asm__ volatile("sti");
 while(rem) {
  while(!p->rh->data) {
   __asm__ volatile("pause");
  }
  while(rem && ring_read(p->rh,dst++)) {
   cnt++;
   rem--;
  }
 }
 __asm__ volatile("cli");
 return cnt;
}

variable_types:
rem
unsigned long

variable_types:
dst
unsigned char *


decompiled_code:
__int64 __fastcall con_init(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // rax

if ( con_dev )
{
printf("Attempt to init two consoles\n");
result = 4294967274LL;
}
else
{
v1 = *(_QWORD *)(a1 + 16);
con_dev = a1;
if ( v1 || (v3 = kmalloc(120LL, "con_private", 0LL, 0LL), *(_QWORD *)(a1 + 16) = v3, (v1 = v3) != 0) )
{
*(_QWORD *)(v1 + 104) = ring_init(32LL, 0LL);
result = 0LL;
}
else
{
result = 4294967284LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // rax

if ( con_dev )
{
printf("Attempt to init two consoles\n");
result = 4294967274LL;
}
else
{
v1 = *(_QWORD *)(a1 + 16);
con_dev = a1;
if ( v1 || (v3 = kmalloc(120LL, "con_private", 0LL, 0LL), *(_QWORD *)(a1 + 16) = v3, (v1 = v3) != 0) )
{
*(_QWORD *)(v1 + 104) = ring_init(32LL, 0LL);
result = 0LL;
}
else
{
result = 4294967284LL;
}
}
return result;
}

original_code:
int con_init(struct char_dev *dev)
{
 struct con_private *cp;
 if(con_dev != ((void*)0)) {
  printf("Attempt to init two consoles\n");
  return -22;
 }
 con_dev = dev;
 cp = dev->priv;
 if(!cp && (cp = dev->priv = (void *)kmalloc(sizeof(struct con_private), "con_private", ((void*)0), 0)) == ((void*)0))
  return -12;
 cp->rh = ring_init(32, ((void*)0));
 return 0;
}

canonical_original_code:
int con_init(struct char_dev *dev)
{
 struct con_private *cp;
 if(con_dev != ((void *)0)) {
  printf("Attempt to init two consoles\n");
  return -22;
 }
 con_dev = dev;
 cp = dev->priv;
 if(!cp && (cp = dev->priv = (void *)kmalloc(sizeof(struct con_private), "con_private", ((void *)0), 0)) == ((void *)0))
  return -12;
 cp->rh = ring_init(32, ((void *)0));
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall ser_init(unsigned __int16 *a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rsi
__int16 v4; // ax
__int64 v6; // rax

v1 = *((_QWORD *)a1 + 2);
if ( v1 || (v6 = kmalloc(120LL, "ser_private", 0LL, 0LL), *((_QWORD *)a1 + 2) = v6, (v1 = v6) != 0) )
{
v2 = ring_init(32LL, 0LL);
*(_QWORD *)(v1 + 104) = v2;
if ( v2 )
{
v3 = *a1;
if ( (_DWORD)v3 == 64 )
{
v4 = 1016;
goto LABEL_6;
}
if ( (_DWORD)v3 == 65 )
{
v4 = 760;
LABEL_6:
*(_WORD *)(v1 + 116) = v4;
return 0LL;
}
printf("ser_init: invalid minor id %x\n", v3);
if ( *(_QWORD *)(v1 + 104) )
((void (*)(void))kfree)();
}
kfree(v1);
return 0xFFFFFFFFLL;
}
printf("ser_init: unable to allocate memory ser_private\n");
return 4294967284LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int16 *a1)
{
__int64 v1; // rbp
__int64 v2; // rax
__int64 v3; // rsi
__int16 v4; // ax
__int64 v6; // rax

v1 = *((_QWORD *)a1 + 2);
if ( v1 || (v6 = kmalloc(120LL, "ser_private", 0LL, 0LL), *((_QWORD *)a1 + 2) = v6, (v1 = v6) != 0) )
{
v2 = ring_init(32LL, 0LL);
*(_QWORD *)(v1 + 104) = v2;
if ( v2 )
{
v3 = *a1;
if ( (_DWORD)v3 == 64 )
{
v4 = 1016;
goto LABEL_6;
}
if ( (_DWORD)v3 == 65 )
{
v4 = 760;
LABEL_6:
*(_WORD *)(v1 + 116) = v4;
return 0LL;
}
printf("ser_init: invalid minor id %x\n", v3);
if ( *(_QWORD *)(v1 + 104) )
((void (*)(void))kfree)();
}
kfree(v1);
return 0xFFFFFFFFLL;
}
printf("ser_init: unable to allocate memory ser_private\n");
return 4294967284LL;
}

original_code:
__attribute__((nonnull)) static int ser_init(struct char_dev *dev)
{
 struct ser_private *cp;
 uint16_t port;
 cp = dev->priv;
 if(!cp && (cp = dev->priv = (void *)kmalloc(sizeof(struct ser_private), "ser_private", ((void*)0), 0)) == ((void*)0)) {
  printf("ser_init: unable to allocate memory ser_private\n");
  return -12;
 }
 if((cp->rh = ring_init(32, ((void*)0))) == ((void*)0))
  goto fail;
 switch((((dev_t)(dev->devid))&0xffff))
 {
  case 64:
   port = 0x3f8;
   break;
  case 65:
   port = 0x2f8;
   break;
  default:
   printf("ser_init: invalid minor id %x\n", (((dev_t)(dev->devid))&0xffff));
   goto fail;
   break;
 }
 cp->port = port;
 return 0;
fail:
 if(cp->rh) kfree(cp->rh);
 if(cp) kfree(cp);
 return -1;
}

canonical_original_code:
static int ser_init(struct char_dev *dev)
{
 struct ser_private *cp;
 unsigned short port;
 cp = dev->priv;
 if(!cp && (cp = dev->priv = (void *)kmalloc(sizeof(struct ser_private), "ser_private", ((void *)0), 0)) == ((void *)0)) {
  printf("ser_init: unable to allocate memory ser_private\n");
  return -12;
 }
 if((cp->rh = ring_init(32, ((void *)0))) == ((void *)0))
  goto fail;
 switch((((dev_t)(dev->devid))&0xffff))
 {
  case 64:
   port = 0x3f8;
   break;
  case 65:
   port = 0x2f8;
   break;
  default:
   printf("ser_init: invalid minor id %x\n", (((dev_t)(dev->devid))&0xffff));
   goto fail;
   break;
 }
 cp->port = port;
 return 0;
fail:
 if(cp->rh) kfree(cp->rh);
 if(cp) kfree(cp);
 return -1;
}

variable_types:
port
unsigned short


decompiled_code:
void setup_tsc()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
void setup_tsc(void)
{
}

canonical_original_code:
void setup_tsc()
{
}


decompiled_code:
void delay_ms()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void delay_ms(uint32_t ms)
{
}

canonical_original_code:
void delay_ms(unsigned int ms)
{
}

variable_types:
ms
unsigned int


inportb

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

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

original_code:
uint8_t inportb (unsigned short _port)
{
 uint8_t rv = 0;
 __asm__ volatile ("inb %1, %0" : "=a" (rv) : "dN" (_port));
 return rv;
}

canonical_original_code:
unsigned char inportb(unsigned short _port)
{
 unsigned char rv = 0;
 __asm__ volatile ("inb %1, %0" : "=a" (rv) : "dN" (_port));
 return rv;
}

variable_types:
rv
unsigned char

return_type: unsigned char


decompiled_code:
unsigned __int8 process_key()
{
unsigned __int8 result; // al
char v1; // cl
unsigned __int8 v2; // dl
__int64 v3; // rcx
__int64 v4; // rdi

result = inportb(0x64u);
if ( (result & 1) != 0 )
{
while ( 1 )
{
while ( 1 )
{
do
{
while ( 1 )
{
while ( 1 )
{
do
{
result = inportb(0x60u);
if ( v1 == result )
return result;
}
while ( result > 0x80u );
if ( result != 29 )
break;
ctrl = 1;
}
if ( result != 42 )
break;
shift = 1;
}
}
while ( result > 0x47u || !keymap[result] );
v4 = find_dev(327680LL, 2LL)[2];
if ( shift )
break;
if ( !ctrl || alt )
{
LABEL_16:
ring_write(*(_QWORD *)(v4 + 104), v2);
}
else if ( v2 == 107 )
{
dump_pools(v4);
}
}
if ( ctrl || alt )
goto LABEL_16;
ring_write(*(_QWORD *)(v4 + 104), (unsigned __int8)keymap_shift[v3]);
}
}
return result;
}

canonical_decompiled_code:
unsigned __int8 func11()
{
unsigned __int8 result; // al
char v1; // cl
unsigned __int8 v2; // dl
__int64 v3; // rcx
__int64 v4; // rdi

result = func10(0x64u);
if ( (result & 1) != 0 )
{
while ( 1 )
{
while ( 1 )
{
do
{
while ( 1 )
{
while ( 1 )
{
do
{
result = func10(0x60u);
if ( v1 == result )
return result;
}
while ( result > 0x80u );
if ( result != 29 )
break;
ctrl = 1;
}
if ( result != 42 )
break;
shift = 1;
}
}
while ( result > 0x47u || !keymap[result] );
v4 = find_dev(327680LL, 2LL)[2];
if ( shift )
break;
if ( !ctrl || alt )
{
LABEL_16:
ring_write(*(_QWORD *)(v4 + 104), v2);
}
else if ( v2 == 107 )
{
dump_pools(v4);
}
}
if ( ctrl || alt )
goto LABEL_16;
ring_write(*(_QWORD *)(v4 + 104), (unsigned __int8)keymap_shift[v3]);
}
}
return result;
}

original_code:
void process_key()
{
 if(!(inportb(0x64) & 0x1)) return;
 uint8_t raw=0, oldraw, running=1;
 struct char_dev *tty;
 struct con_private *ttyp;
 do {
  oldraw = raw;
  raw = inportb(0x60);
  if(raw==oldraw) {
   running=0; continue; }
  else if(raw > 0x80) {
  } else {
   switch(raw) {
    case 0x2a:
     shift = 1;
     break;
    case 0x1d:
     ctrl = 1;
     break;
    default:
     if(raw < 0x48 && keymap[raw]) {
      tty = find_dev(((((dev_t)(5))<<16)|(dev_t)(0)), 2);
      ttyp = (struct con_private *)tty->priv;
      if(shift && !ctrl && !alt) {
       ring_write(ttyp->rh, keymap_shift[raw]);
      } else if(ctrl && !shift && !alt) {
       switch(keymap[raw]) {
        case 'l':
         break;
        case 'k':
         dump_pools();
         break;
       }
      } else {
       ring_write(ttyp->rh, keymap[raw]);
      }
     } else {
     }
     break;
   }
  }
 } while(running);
}

canonical_original_code:
void process_key()
{
 if(!(inportb(0x64) & 0x1)) return;
 unsigned char raw = 0; unsigned char oldraw; unsigned char running = 1;
 struct char_dev *tty;
 struct con_private *ttyp;
 do {
  oldraw = raw;
  raw = inportb(0x60);
  if(raw==oldraw) {
   running=0; continue; }
  else if(raw > 0x80) {
  } else {
   switch(raw) {
    case 0x2a:
     shift = 1;
     break;
    case 0x1d:
     ctrl = 1;
     break;
    default:
     if(raw < 0x48 && keymap[raw]) {
      tty = find_dev(((((dev_t)(5))<<16)|(dev_t)(0)), 2);
      ttyp = (struct con_private *)tty->priv;
      if(shift && !ctrl && !alt) {
       ring_write(ttyp->rh, keymap_shift[raw]);
      } else if(ctrl && !shift && !alt) {
       switch(keymap[raw]) {
        case 'l':
         break;
        case 'k':
         dump_pools();
         break;
       }
      } else {
       ring_write(ttyp->rh, keymap[raw]);
      }
     } else {
     }
     break;
   }
  }
 } while(running);
}

variable_types:
raw
unsigned char

variable_types:
oldraw
unsigned char

variable_types:
running
unsigned char


inportw

decompiled_code:
unsigned __int16 __fastcall inportw(unsigned __int16 a1)
{
return __inword(a1);
}

canonical_decompiled_code:
unsigned __int16 __fastcall func12(unsigned __int16 a1)
{
return __inword(a1);
}

original_code:
uint16_t inportw (unsigned short _port)
{
 uint16_t rv = 0;
 __asm__ volatile ("inw %1, %0" : "=a" (rv) : "dN" (_port));
 return rv;
}

canonical_original_code:
unsigned short inportw(unsigned short _port)
{
 unsigned short rv = 0;
 __asm__ volatile ("inw %1, %0" : "=a" (rv) : "dN" (_port));
 return rv;
}

variable_types:
rv
unsigned short

return_type: unsigned short


inportl

decompiled_code:
unsigned __int32 __fastcall inportl(unsigned __int16 a1)
{
return __indword(a1);
}

canonical_decompiled_code:
unsigned __int32 __fastcall func13(unsigned __int16 a1)
{
return __indword(a1);
}

original_code:
uint32_t inportl (unsigned short _port)
{
 uint32_t rv = 0;
 __asm__ volatile ("inl %1, %0" : "=a" (rv) : "dN" (_port));
 return rv;
}

canonical_original_code:
unsigned int inportl(unsigned short _port)
{
 unsigned int rv = 0;
 __asm__ volatile ("inl %1, %0" : "=a" (rv) : "dN" (_port));
 return rv;
}

variable_types:
rv
unsigned int


outportb

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

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

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

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

original_code:
void outportb (unsigned short _port, uint8_t _data)
{
 __asm__ volatile ("outb %1, %0" :: "dN" (_port), "a" (_data):"memory");
}

canonical_original_code:
void outportb(unsigned short _port, unsigned char _data)
{
 __asm__ volatile ("outb %1, %0" :: "dN" (_port), "a" (_data):"memory");
}


outportw

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

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

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

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

original_code:
void outportw (unsigned short _port, uint16_t _data)
{
 __asm__ volatile ("outw %1, %0" :: "dN" (_port), "a" (_data):"memory");
}

canonical_original_code:
void outportw(unsigned short _port, unsigned short _data)
{
 __asm__ volatile ("outw %1, %0" :: "dN" (_port), "a" (_data):"memory");
}


outportl

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

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

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

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

original_code:
void outportl (uint16_t _port, uint32_t _data)
{
 __asm__ volatile ("outl %1, %0" :: "dN" (_port), "a" (_data):"memory");
}

canonical_original_code:
void outportl(unsigned short _port, unsigned int _data)
{
 __asm__ volatile ("outl %1, %0" :: "dN" (_port), "a" (_data):"memory");
}


scroll

decompiled_code:
__int64 scroll()
{
__int64 result; // rax
__int64 v1; // rsi
int v2; // eax
__int64 v3; // rdi
__int64 v4; // rdx
__int64 v5; // rax

result = (unsigned __int8)cur_y;
if ( (unsigned __int8)cur_y > 0x18u )
{
v1 = vga;
v2 = (unsigned __int16)((unsigned __int8)cur_y - 24);
v3 = vga + 2LL * (unsigned int)(80 * v2);
v4 = (unsigned int)(-80 * v2 + 2000);
if ( -80 * v2 != -2000 )
{
v5 = 0LL;
do
{
*(_WORD *)(v1 + 2 * v5) = *(_WORD *)(v3 + 2 * v5);
++v5;
}
while ( v5 != v4 );
}
result = memsetw(v1 + 2 * v4, 1824LL, 80LL);
cur_y = 24;
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 result; // rax
__int64 v1; // rsi
int v2; // eax
__int64 v3; // rdi
__int64 v4; // rdx
__int64 v5; // rax

result = (unsigned __int8)cur_y;
if ( (unsigned __int8)cur_y > 0x18u )
{
v1 = vga;
v2 = (unsigned __int16)((unsigned __int8)cur_y - 24);
v3 = vga + 2LL * (unsigned int)(80 * v2);
v4 = (unsigned int)(-80 * v2 + 2000);
if ( -80 * v2 != -2000 )
{
v5 = 0LL;
do
{
*(_WORD *)(v1 + 2 * v5) = *(_WORD *)(v3 + 2 * v5);
++v5;
}
while ( v5 != v4 );
}
result = memsetw(v1 + 2 * v4, 1824LL, 80LL);
cur_y = 24;
}
return result;
}

original_code:
void scroll(void)
{
 const uint16_t blank = 0x20 | (attrib << 8);
 if(cur_y >= 25U)
 {
  const uint16_t offset = cur_y - 25U + 1;
  uint16_t *dp = vga;
  const uint16_t *sp = (const uint16_t *)(vga + (offset * 80U));
  size_t count = (25U - offset) * 80U;
  for(; count; count--)
   *dp++ = *sp++;
  memsetw(vga + ((25U - offset) * 80U),
    blank,
    80U);
  cur_y = 25U - 1;
 }
}

canonical_original_code:
void scroll()
{
 unsigned short blank = 0x20 | (attrib << 8);
 if(cur_y >= 25U)
 {
  unsigned short offset = cur_y - 25U + 1;
  unsigned short *dp = vga;
  unsigned short *sp = (const uint16_t *)(vga + (offset * 80U));
  unsigned long count = (25U - offset) * 80U;
  for(; count; count--)
   *dp++ = *sp++;
  memsetw(vga + ((25U - offset) * 80U),
    blank,
    80U);
  cur_y = 25U - 1;
 }
}

variable_types:
blank
unsigned short

variable_types:
offset
unsigned short

variable_types:
dp
unsigned short *

variable_types:
sp
unsigned short *

variable_types:
count
unsigned long


decompiled_code:
__int64 move_csr()
{
unsigned __int8 v0; // ch
unsigned __int8 v1; // cl

outportb(0x3D4u, 0xEu);
outportb(0x3D5u, v0);
outportb(0x3D4u, 0xFu);
return outportb(0x3D5u, v1);
}

canonical_decompiled_code:
__int64 func18()
{
unsigned __int8 v0; // ch
unsigned __int8 v1; // cl

func14(0x3D4u, 0xEu);
func14(0x3D5u, v0);
func14(0x3D4u, 0xFu);
return func14(0x3D5u, v1);
}

original_code:
void move_csr(void)
{
 const uint16_t temp = (cur_y * 80U) + cur_x;
 outportb(0x3d4, 0x0e);
 outportb(0x3d5, (temp >> 8) & 0xff);
 outportb(0x3d4, 0x0f);
 outportb(0x3d5, temp & 0xff);
}

canonical_original_code:
void move_csr()
{
 unsigned short temp = (cur_y * 80U) + cur_x;
 outportb(0x3d4, 0x0e);
 outportb(0x3d5, (temp >> 8) & 0xff);
 outportb(0x3d4, 0x0f);
 outportb(0x3d5, temp & 0xff);
}

variable_types:
temp
unsigned short


cls

original_code:
void cls(void)
{
 uint8_t i;
 const uint16_t blank = 0x20 | (attrib << 8);
 for(i=0;i<25U;i++)
  memsetw(vga + (i*80U), blank, 80U);
 cur_x = 0;
 cur_y = 0;
 move_csr();
}

canonical_original_code:
void cls()
{
 unsigned char i;
 unsigned short blank = 0x20 | (attrib << 8);
 for(i=0;i<25U;i++)
  memsetw(vga + (i*80U), blank, 80U);
 cur_x = 0;
 cur_y = 0;
 move_csr();
}

variable_types:
i
unsigned char


decompiled_code:
__int64 __fastcall putch_s(unsigned __int16 a1)
{
unsigned __int16 v1; // cx
unsigned __int16 v2; // r8
unsigned __int8 v3; // r9
__int64 result; // rax
char v5; // r9

do
{
v1 = a1 + 5;
while ( (inportb(v1) & 0x20) == 0 )
_mm_pause();
a1 = v2;
result = outportb(v2, v3);
}
while ( v5 == 10 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned __int16 a1)
{
unsigned __int16 v1; // cx
unsigned __int16 v2; // r8
unsigned __int8 v3; // r9
__int64 result; // rax
char v5; // r9

do
{
v1 = a1 + 5;
while ( (func10(v1) & 0x20) == 0 )
_mm_pause();
a1 = v2;
result = func14(v2, v3);
}
while ( v5 == 10 );
return result;
}

original_code:
void putch_s(const uint16_t port, const unsigned char c)
{
 while( (inportb(port+0x5) & (1<<5)) == 0) {
  __asm__ volatile("pause");
 }
 outportb(port, c);
 if(c=='\n') putch_s(port, '\r');
}

canonical_original_code:
void putch_s(unsigned short port, unsigned char c)
{
 while( (inportb(port+0x5) & (1<<5)) == 0) {
  __asm__ volatile("pause");
 }
 outportb(port, c);
 if(c=='\n') putch_s(port, '\r');
}

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall con_write(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // r10
__int64 v4; // r11

if ( !a3 )
return 0LL;
v3 = 0LL;
do
{
if ( !*(_BYTE *)(a2 + v3) )
return v3;
putch_s(0x3F8u);
}
while ( v4 != v3 );
return v4;
}

original_code:
ssize_t con_write(struct char_dev *const _dev, const char *const src, const size_t len)
{
 size_t i;
 for(i=0;i<len;i++)
 {
  if(!src[i]) return i;
  putch_s(0x3f8, src[i]);
 }
 return i;
}

canonical_original_code:
long con_write(struct char_dev *_dev, char *src, unsigned long len)
{
 unsigned long i;
 for(i=0;i<len;i++)
 {
  if(!src[i]) return i;
  putch_s(0x3f8, src[i]);
 }
 return i;
}

variable_types: struct char_dev { unsigned long devid; struct char_ops { char *name; long (*read)(struct char_dev *, char *, unsigned long); long (*write)(struct char_dev *, char *, unsigned long); int (*init)(struct char_dev *); long (*pending)(struct char_dev *); } *ops; void *priv; } *

variable_types:
src
char *

variable_types:
len
unsigned long

variable_types:
i
unsigned long


original_code:
__attribute__((nonnull)) static ssize_t ser_write(struct char_dev *dev, const char *src, size_t len)
{
 size_t i;
 struct ser_private *p = (struct ser_private *)dev->priv;
 for(i=0;i<len;i++)
 {
  putch_s(p->port, src[i]);
 }
 return len;
}

canonical_original_code:
static long ser_write(struct char_dev *dev, char *src, unsigned long len)
{
 unsigned long i;
 struct ser_private *p = (struct ser_private *)dev->priv;
 for(i=0;i<len;i++)
 {
  putch_s(p->port, src[i]);
 }
 return len;
}

variable_types: struct ser_private { char buf[100]; struct ring_head { unsigned char *buffer; int length; int read; int write; int data; } *rh; int head; unsigned short port; } *


decompiled_code:
__int64 __fastcall getch_s(__int16 a1, unsigned __int8 *a2)
{
unsigned __int16 v2; // cx
unsigned __int8 v3; // r8
__int64 result; // rax

v3 = inportb(a1 + 5);
result = 0LL;
if ( (v3 & 1) != 0 )
{
*a2 = inportb(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int16 a1, unsigned __int8 *a2)
{
unsigned __int16 v2; // cx
unsigned __int8 v3; // r8
__int64 result; // rax

v3 = func10(a1 + 5);
result = 0LL;
if ( (v3 & 1) != 0 )
{
*a2 = func10(v2);
result = 1LL;
}
return result;
}

original_code:
bool getch_s(uint16_t port, unsigned char *c)
{
 if( (inportb(port + 0x5) & (1<<0)) == 0 ) return 0;
 *c = inportb(port + 0x0);
 return 1;
}

canonical_original_code:
_Bool getch_s(unsigned short port, unsigned char *c)
{
 if( (inportb(port + 0x5) & (1<<0)) == 0 ) return 0;
 *c = inportb(port + 0x0);
 return 1;
}

variable_types:
port
unsigned short

variable_types:
c
unsigned char *


decompiled_code:
unsigned __int8 __fastcall ser_status(unsigned __int16 a1)
{
_QWORD *v1; // rax
unsigned int v2; // er8
__int64 v3; // rbx
unsigned __int8 v4; // al
unsigned __int8 result; // al

v1 = find_dev((a1 + 64) | 0x40000u, 2LL);
if ( !v1 )
return printf("ser_status: can't find port for %x\n", v2);
v3 = v1[2];
if ( !v3 )
return printf("ser_status: sp is null for %x\n", v2);
inportb(*(_WORD *)(v3 + 116) + 6);
while ( 1 )
{
result = inportb(*(_WORD *)(v3 + 116) + 5);
if ( (result & 1) == 0 )
break;
v4 = inportb(*(_WORD *)(v3 + 116));
ring_write(*(_QWORD *)(v3 + 104), v4);
}
return result;
}

canonical_decompiled_code:
unsigned __int8 __fastcall func24(unsigned __int16 a1)
{
_QWORD *v1; // rax
unsigned int v2; // er8
__int64 v3; // rbx
unsigned __int8 v4; // al
unsigned __int8 result; // al

v1 = find_dev((a1 + 64) | 0x40000u, 2LL);
if ( !v1 )
return printf("ser_status: can't find port for %x\n", v2);
v3 = v1[2];
if ( !v3 )
return printf("ser_status: sp is null for %x\n", v2);
func10(*(_WORD *)(v3 + 116) + 6);
while ( 1 )
{
result = func10(*(_WORD *)(v3 + 116) + 5);
if ( (result & 1) == 0 )
break;
v4 = func10(*(_WORD *)(v3 + 116));
ring_write(*(_QWORD *)(v3 + 104), v4);
}
return result;
}

original_code:
void ser_status(uint16_t port)
{
 uint8_t ch;
 uint8_t st;
 struct char_dev *d;
 struct ser_private *sp;
 d = find_dev(((((dev_t)(4))<<16)|(dev_t)(64 + port)), 2);
 if(!d) {
  printf("ser_status: can't find port for %x\n", port);
  return;
 }
 sp = d->priv;
 if(!sp) {
  printf("ser_status: sp is null for %x\n", port);
  return;
 }
 st = inportb(sp->port + 0x6);
 st = inportb(sp->port+0x5);
 while((st & (1<<0)) == (1<<0))
 {
  ch = inportb(sp->port + 0x0);
  ring_write(sp->rh, ch);
  st = inportb(sp->port + 0x5);
 }
}

canonical_original_code:
void ser_status(unsigned short port)
{
 unsigned char ch;
 unsigned char st;
 struct char_dev *d;
 struct ser_private *sp;
 d = find_dev(((((dev_t)(4))<<16)|(dev_t)(64 + port)), 2);
 if(!d) {
  printf("ser_status: can't find port for %x\n", port);
  return;
 }
 sp = d->priv;
 if(!sp) {
  printf("ser_status: sp is null for %x\n", port);
  return;
 }
 st = inportb(sp->port + 0x6);
 st = inportb(sp->port+0x5);
 while((st & (1<<0)) == (1<<0))
 {
  ch = inportb(sp->port + 0x0);
  ring_write(sp->rh, ch);
  st = inportb(sp->port + 0x5);
 }
}

variable_types:
ch
unsigned char

variable_types:
st
unsigned char


putch

decompiled_code:
__int64 __fastcall putch(unsigned __int8 a1)
{
char v1; // al
int v2; // ecx

switch ( a1 )
{
case 8u:
if ( !cur_x )
return move_csr();
v1 = --cur_x;
break;
case 9u:
v1 = (cur_x + 8) & 0xF8;
cur_x = v1;
break;
case 0xDu:
cur_x = 0;
return move_csr();
case 0xAu:
goto LABEL_9;
default:
v1 = cur_x;
if ( a1 > 0x1Fu )
{
v2 = (unsigned __int8)cur_x;
v1 = ++cur_x;
*(_WORD *)(vga + 2LL * (v2 + 80 * (unsigned int)(unsigned __int8)cur_y)) = a1 | 0x700;
}
break;
}
if ( (unsigned __int8)v1 > 0x50u )
{
LABEL_9:
++cur_y;
cur_x = 0;
}
return move_csr();
}

canonical_decompiled_code:
__int64 __fastcall func25(unsigned __int8 a1)
{
char v1; // al
int v2; // ecx

switch ( a1 )
{
case 8u:
if ( !cur_x )
return func18();
v1 = --cur_x;
break;
case 9u:
v1 = (cur_x + 8) & 0xF8;
cur_x = v1;
break;
case 0xDu:
cur_x = 0;
return func18();
case 0xAu:
goto LABEL_9;
default:
v1 = cur_x;
if ( a1 > 0x1Fu )
{
v2 = (unsigned __int8)cur_x;
v1 = ++cur_x;
*(_WORD *)(vga + 2LL * (v2 + 80 * (unsigned int)(unsigned __int8)cur_y)) = a1 | 0x700;
}
break;
}
if ( (unsigned __int8)v1 > 0x50u )
{
LABEL_9:
++cur_y;
cur_x = 0;
}
return func18();
}

original_code:
void putch(unsigned char c)
{
 uint16_t *where;
 const short att = (attrib << 8);
 if (c == 0x08) {
  if(cur_x > 0)
   cur_x--;
 } else if (c == 0x09) {
  cur_x = (cur_x + 8) & ~(8 - 1);
 } else if (c == '\r') {
  cur_x = 0;
 } else if (c == '\n') {
  cur_x = 0;
  cur_y++;
 } else if( c >= ' ' ) {
  where = vga + ((cur_y * 80U) + cur_x);
  *where = c | att;
  cur_x++;
 }
 if( cur_x > 80U ) {
  cur_x = 0;
  cur_y++;
 }
 move_csr();
}

canonical_original_code:
void putch(unsigned char c)
{
 unsigned short *where;
 short att = (attrib << 8);
 if (c == 0x08) {
  if(cur_x > 0)
   cur_x--;
 } else if (c == 0x09) {
  cur_x = (cur_x + 8) & ~(8 - 1);
 } else if (c == '\r') {
  cur_x = 0;
 } else if (c == '\n') {
  cur_x = 0;
  cur_y++;
 } else if( c >= ' ' ) {
  where = vga + ((cur_y * 80U) + cur_x);
  *where = c | att;
  cur_x++;
 }
 if( cur_x > 80U ) {
  cur_x = 0;
  cur_y++;
 }
 move_csr();
}

variable_types:
where
unsigned short *

variable_types: att short


decompiled_code:
__int64 lock_frames()
{
return spin_lock(&frames_lock);
}

canonical_decompiled_code:
__int64 func0()
{
return spin_lock(&frames_lock);
}

original_code:
static inline void lock_frames(void)
{
 spin_lock(&frames_lock);
}

canonical_original_code:
static inline void lock_frames()
{
 spin_lock(&frames_lock);
}


decompiled_code:
__int64 unlock_frames()
{
return spin_unlock(&frames_lock);
}

canonical_decompiled_code:
__int64 func1()
{
return spin_unlock(&frames_lock);
}

original_code:
static inline void unlock_frames(void)
{
 spin_unlock(&frames_lock);
}

canonical_original_code:
static inline void unlock_frames()
{
 spin_unlock(&frames_lock);
}


decompiled_code:
int print_frame_stats()
{
_QWORD *v0; // r8
__int64 v1; // rsi
__int64 i; // rcx

if ( !free_page_size )
return printf("pagebm %lx/%lx\n", 0LL, free_page_size);
v0 = (_QWORD *)pagebm;
v1 = 0LL;
do
{
for ( i = 0LL; i != 64; ++i )
v1 -= ((*v0 & (1 << i)) == 0LL) - 1LL;
++v0;
}
while ( v0 != (_QWORD *)(pagebm + 8 * free_page_size) );
return printf("pagebm %lx/%lx\n", v1, free_page_size << 6);
}

canonical_decompiled_code:
int func3()
{
_QWORD *v0; // r8
__int64 v1; // rsi
__int64 i; // rcx

if ( !free_page_size )
return printf("pagebm %lx/%lx\n", 0LL, free_page_size);
v0 = (_QWORD *)pagebm;
v1 = 0LL;
do
{
for ( i = 0LL; i != 64; ++i )
v1 -= ((*v0 & (1 << i)) == 0LL) - 1LL;
++v0;
}
while ( v0 != (_QWORD *)(pagebm + 8 * free_page_size) );
return printf("pagebm %lx/%lx\n", v1, free_page_size << 6);
}

original_code:
void print_frame_stats(void)
{
 uint64_t idx,off;
 uint64_t cnt=0;
 for(idx=0;idx<free_page_size;idx++)
  for(off=0;off<64;off++)
   if(pagebm[idx]&(1<<off)) cnt++;
 printf("pagebm %lx/%lx\n", cnt, free_page_size<<6);
}

canonical_original_code:
void print_frame_stats()
{
 unsigned long idx; unsigned long off;
 unsigned long cnt = 0;
 for(idx=0;idx<free_page_size;idx++)
  for(off=0;off<64;off++)
   if(pagebm[idx]&(1<<off)) cnt++;
 printf("pagebm %lx/%lx\n", cnt, free_page_size<<6);
}

variable_types:
idx
unsigned long

variable_types:
off
unsigned long

variable_types:
cnt
unsigned long


decompiled_code:
void __fastcall add_to_useable_mem(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // rcx

if ( a2 )
{
if ( phys_mem_list[2] )
{
v2 = 1LL;
do
v3 = (int)v2++;
while ( phys_mem_list[4 * v2 - 2] );
if ( (_DWORD)v3 == 31 )
{
printf("add_to_useable_mem: MAX_PHYS_MEM_SLOTS reached\n");
return;
}
}
else
{
v3 = 0LL;
}
v4 = 4 * v3;
phys_mem_list[v4] = a1;
phys_mem_list[v4 + 1] = a2 + a1;
phys_mem_list[v4 + 2] = a2;
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rcx
__int64 v4; // rcx

if ( a2 )
{
if ( phys_mem_list[2] )
{
v2 = 1LL;
do
v3 = (int)v2++;
while ( phys_mem_list[4 * v2 - 2] );
if ( (_DWORD)v3 == 31 )
{
printf("add_to_useable_mem: MAX_PHYS_MEM_SLOTS reached\n");
return;
}
}
else
{
v3 = 0LL;
}
v4 = 4 * v3;
phys_mem_list[v4] = a1;
phys_mem_list[v4 + 1] = a2 + a1;
phys_mem_list[v4 + 2] = a2;
}
}

original_code:
void add_to_useable_mem(uint8_t *const from, const uint64_t len)
{
 int i = 0;
 if(!len) return;
 while( phys_mem_list[i].len != 0 && i < 32 ) i++;
 if( i >= 32 -1 ) {
  printf("add_to_useable_mem: MAX_PHYS_MEM_SLOTS reached\n");
  return;
 }
 phys_mem_list[i].from = from;
 phys_mem_list[i].to = (void *)((uint64_t)(from) + len);
 phys_mem_list[i].len = len;
}

canonical_original_code:
void add_to_useable_mem(unsigned char *from, unsigned long len)
{
 int i = 0;
 if(!len) return;
 while( phys_mem_list[i].len != 0 && i < 32 ) i++;
 if( i >= 32 -1 ) {
  printf("add_to_useable_mem: MAX_PHYS_MEM_SLOTS reached\n");
  return;
 }
 phys_mem_list[i].from = from;
 phys_mem_list[i].to = (void *)((unsigned long)(from) + len);
 phys_mem_list[i].len = len;
}

variable_types:
from
unsigned char *

variable_types: i int


decompiled_code:
__int64 __fastcall is_useable(unsigned __int64 a1, __int64 a2, unsigned int a3)
{
__int64 *v3; // rax
int v4; // ecx
bool v5; // dl
__int64 result; // rax

if ( phys_mem_list[2] )
{
v3 = phys_mem_list;
v4 = 0;
while ( *v3 > a1 || v3[1] < a1 )
{
++v4;
v5 = v3[6] != 0;
v3 += 4;
LOBYTE(a3) = v4 != 31 && v5;
if ( !(_BYTE)a3 )
goto LABEL_6;
}
result = 1LL;
}
else
{
a3 = 0;
LABEL_6:
result = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1, __int64 a2, unsigned int a3)
{
__int64 *v3; // rax
int v4; // ecx
bool v5; // dl
__int64 result; // rax

if ( phys_mem_list[2] )
{
v3 = phys_mem_list;
v4 = 0;
while ( *v3 > a1 || v3[1] < a1 )
{
++v4;
v5 = v3[6] != 0;
v3 += 4;
LOBYTE(a3) = v4 != 31 && v5;
if ( !(_BYTE)a3 )
goto LABEL_6;
}
result = 1LL;
}
else
{
a3 = 0;
LABEL_6:
result = a3;
}
return result;
}

original_code:
bool is_useable(const uint8_t *const ad)
{
 int i = 0;
 while( phys_mem_list[i].len && i < 32 - 1 )
 {
  if( ad >= phys_mem_list[i].from && ad <= phys_mem_list[i].to ) return 1;
  i++;
 }
 return 0;
}

canonical_original_code:
_Bool is_useable(unsigned char *ad)
{
 int i = 0;
 while( phys_mem_list[i].len && i < 32 - 1 )
 {
  if( ad >= phys_mem_list[i].from && ad <= phys_mem_list[i].to ) return 1;
  i++;
 }
 return 0;
}

variable_types:
ad
unsigned char *


decompiled_code:
__int64 __fastcall set_n_frames(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // r9

if ( a2 )
{
do
result = set_frame(a1 + 4096);
while ( v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // r9

if ( a2 )
{
do
result = func6(a1 + 4096);
while ( v4 );
}
return result;
}

original_code:
void set_n_frames(const uint8_t *const addr, const uint64_t number_of_frames)
{
 uint64_t nframes = number_of_frames;
 uint64_t ptr = (uint64_t)(addr);
 while(nframes--)
  set_frame((void *)(ptr+=(1024*4)));
}

canonical_original_code:
void set_n_frames(unsigned char *addr, unsigned long number_of_frames)
{
 unsigned long nframes = number_of_frames;
 unsigned long ptr = (uint64_t)(addr);
 while(nframes--)
  set_frame((void *)(ptr+=(1024*4)));
}

variable_types:
addr
unsigned char *

variable_types:
nframes
unsigned long

variable_types:
ptr
unsigned long


decompiled_code:
__int64 __fastcall clear_n_frames(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // r9

if ( a2 )
{
do
result = clear_frame(a1 + 4096);
while ( v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // r9

if ( a2 )
{
do
result = func8(a1 + 4096);
while ( v4 );
}
return result;
}

original_code:
void clear_n_frames(const uint8_t *const addr, const uint64_t number_of_frames)
{
 uint64_t nframes = number_of_frames;
 uint64_t ptr = (uint64_t)(addr);
 while(nframes--)
  clear_frame((void *)(ptr+=(1024*4)));
}

canonical_original_code:
void clear_n_frames(unsigned char *addr, unsigned long number_of_frames)
{
 unsigned long nframes = number_of_frames;
 unsigned long ptr = (uint64_t)(addr);
 while(nframes--)
  clear_frame((void *)(ptr+=(1024*4)));
}


decompiled_code:
bool __fastcall test_frame(unsigned __int64 a1)
{
unsigned __int64 v1; // rsi
char v2; // di
bool result; // al

v1 = a1 >> 18;
v2 = ~(unsigned __int8)(a1 >> 12) & 0x3F;
if ( pagebm )
result = (*(_QWORD *)(pagebm + 8 * v1) & (1 << (63 - v2))) != 0LL;
else
result = 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func10(unsigned __int64 a1)
{
unsigned __int64 v1; // rsi
char v2; // di
bool result; // al

v1 = a1 >> 18;
v2 = ~(unsigned __int8)(a1 >> 12) & 0x3F;
if ( pagebm )
result = (*(_QWORD *)(pagebm + 8 * v1) & (1 << (63 - v2))) != 0LL;
else
result = 0;
return result;
}

original_code:
bool test_frame(const uint8_t *const addr)
{
 unsigned long frame = (uint64_t)addr/(1024*4);
 unsigned long idx = ((frame)/64);
 unsigned long off = (63-((frame)%64));
 if(!pagebm) return 0;
 return (pagebm[idx] & (1 << (63-off)));
}

canonical_original_code:
_Bool test_frame(unsigned char *addr)
{
 unsigned long frame = (uint64_t)addr/(1024*4);
 unsigned long idx = ((frame)/64);
 unsigned long off = (63-((frame)%64));
 if(!pagebm) return 0;
 return (pagebm[idx] & (1 << (63-off)));
}

variable_types:
frame
unsigned long


decompiled_code:
__int64 __fastcall find_frame(unsigned __int64 a1)
{
__int64 result; // rax
unsigned __int64 v2; // rbx
unsigned __int64 *v3; // r8
__int64 v4; // rsi
unsigned __int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // rbp

result = pagebm;
if ( pagebm )
{
v2 = a1;
lock_frames();
if ( free_page_size )
{
v3 = (unsigned __int64 *)pagebm;
v4 = 0LL;
a1 = 0x8000000000000000LL;
while ( 1 )
{
v5 = *v3;
if ( *v3 != -1LL )
break;
LABEL_5:
++v4;
++v3;
if ( free_page_size == v4 )
goto LABEL_6;
}
v6 = 0LL;
while ( ((0x8000000000000000LL >> v6) & v5) != 0 )
{
if ( ++v6 == 64 )
goto LABEL_5;
}
*v3 = v5 | (0x8000000000000000LL >> v6);
v7 = (v4 << 6) - v6 + 63;
if ( taskbm )
*(_QWORD *)(taskbm + 8 * v7) = v2;
unlock_frames(0x8000000000000000LL);
result = v7 << 12;
}
else
{
LABEL_6:
unlock_frames(a1);
printf("frame: can't find free frame\n");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int64 a1)
{
__int64 result; // rax
unsigned __int64 v2; // rbx
unsigned __int64 *v3; // r8
__int64 v4; // rsi
unsigned __int64 v5; // rdx
__int64 v6; // rcx
__int64 v7; // rbp

result = pagebm;
if ( pagebm )
{
v2 = a1;
func0();
if ( free_page_size )
{
v3 = (unsigned __int64 *)pagebm;
v4 = 0LL;
a1 = 0x8000000000000000LL;
while ( 1 )
{
v5 = *v3;
if ( *v3 != -1LL )
break;
LABEL_5:
++v4;
++v3;
if ( free_page_size == v4 )
goto LABEL_6;
}
v6 = 0LL;
while ( ((0x8000000000000000LL >> v6) & v5) != 0 )
{
if ( ++v6 == 64 )
goto LABEL_5;
}
*v3 = v5 | (0x8000000000000000LL >> v6);
v7 = (v4 << 6) - v6 + 63;
if ( taskbm )
*(_QWORD *)(taskbm + 8 * v7) = v2;
func1(0x8000000000000000LL);
result = v7 << 12;
}
else
{
LABEL_6:
func1(a1);
printf("frame: can't find free frame\n");
result = 0LL;
}
}
return result;
}

original_code:
uint8_t *find_frame(const void *const owner)
{
 unsigned long idx,off,retfr;
 if(!pagebm) return 0;
 lock_frames();
 for(idx=0;idx<free_page_size;idx++) {
  if(pagebm[idx] != ~(0UL)) {
   for(off=0;off<64U;off++) {
    if(!(pagebm[idx] & (uint64_t)(1LU<<(63U-off)))) {
     retfr=((idx*64U)+(63U-off));
     pagebm[idx] |= (uint64_t)(1LU<<(63U-off));
     if(taskbm)
      taskbm[retfr] = owner;
     unlock_frames();
     return((void *)(retfr*(1024*4)));
    }
   }
  }
 }
 unlock_frames();
 printf("frame: can't find free frame\n");
 return 0;
}

canonical_original_code:
unsigned char *find_frame(void *owner)
{
 unsigned long idx; unsigned long off; unsigned long retfr;
 if(!pagebm) return 0;
 lock_frames();
 for(idx=0;idx<free_page_size;idx++) {
  if(pagebm[idx] != ~(0UL)) {
   for(off=0;off<64U;off++) {
    if(!(pagebm[idx] & (unsigned long)(1LU<<(63U-off)))) {
     retfr=((idx*64U)+(63U-off));
     pagebm[idx] |= (unsigned long)(1LU<<(63U-off));
     if(taskbm)
      taskbm[retfr] = owner;
     unlock_frames();
     return((void *)(retfr*(1024*4)));
    }
   }
  }
 }
 unlock_frames();
 printf("frame: can't find free frame\n");
 return 0;
}

variable_types:
owner
void *

variable_types:
retfr
unsigned long

return_type: unsigned char *


decompiled_code:
__int64 __fastcall find_n_frames(const char *a1, unsigned __int64 a2)
{
__int64 v2; // rbp
unsigned __int64 v3; // r14
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
__int64 v6; // r15
__int64 v7; // rbx
__int64 v8; // rcx
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11; // rdx
__int64 v13; // rdx
unsigned __int64 v14; // rcx
__int64 v15; // rcx

if ( !pagebm )
return 0LL;
v2 = (__int64)a1;
if ( !a1 )
return 0LL;
if ( a1 == (_BYTE *)lock_frames + 1 )
return find_frame(a2);
lock_frames();
v3 = (unsigned __int64)a1;
v4 = 0LL;
v5 = free_page_size;
v6 = -1LL;
while ( v3 > 0x3F )
{
if ( v4 >= v5 )
goto LABEL_35;
while ( 1 )
{
v13 = *(_QWORD *)(pagebm + 8 * v4);
v14 = v4++;
if ( !v13 )
break;
if ( v4 == v5 )
goto LABEL_35;
}
v15 = v14 << 18;
if ( v6 == -1 )
v6 = v15;
v3 -= 64LL;
if ( !v3 )
goto LABEL_12;
if ( v3 <= 0x3F )
break;
LABEL_28:
if ( v4 == -1LL || v4 >= v5 )
{
a1 = "idx wtf\n";
printf("idx wtf\n");
v5 = free_page_size;
}
}
if ( v4 >= v5 )
{
LABEL_31:
if ( v3 == v2 )
{
LABEL_35:
unlock_frames(a1);
printf("frame: can't find 0x%lx frames\n", v2);
return 0LL;
}
++v4;
v3 = v2;
goto LABEL_28;
}
while ( (-(1 << v3) & *(_QWORD *)(pagebm + 8 * v4)) != 0LL )
{
if ( ++v4 == v5 )
goto LABEL_31;
}
v7 = v4 << 18;
if ( v3 == v2 )
v6 = v7;
LABEL_12:
set_n_frames(v6, v2);
v8 = taskbm;
if ( a2 && taskbm )
{
v9 = v6;
v10 = v6 + (v2 << 12);
do
{
v11 = v9 + 4095;
if ( v9 >= 0 )
v11 = v9;
v9 += 4096LL;
*(_QWORD *)(v8 + 8 * (v11 >> 12)) = a2;
}
while ( v9 != v10 );
}
unlock_frames(v6);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, unsigned __int64 a2)
{
__int64 v2; // rbp
unsigned __int64 v3; // r14
unsigned __int64 v4; // rbx
unsigned __int64 v5; // rax
__int64 v6; // r15
__int64 v7; // rbx
__int64 v8; // rcx
__int64 v9; // rax
__int64 v10; // rbp
__int64 v11; // rdx
__int64 v13; // rdx
unsigned __int64 v14; // rcx
__int64 v15; // rcx

if ( !pagebm )
return 0LL;
v2 = (__int64)a1;
if ( !a1 )
return 0LL;
if ( a1 == (_BYTE *)lock_frames + 1 )
return func11(a2);
func0();
v3 = (unsigned __int64)a1;
v4 = 0LL;
v5 = free_page_size;
v6 = -1LL;
while ( v3 > 0x3F )
{
if ( v4 >= v5 )
goto LABEL_35;
while ( 1 )
{
v13 = *(_QWORD *)(pagebm + 8 * v4);
v14 = v4++;
if ( !v13 )
break;
if ( v4 == v5 )
goto LABEL_35;
}
v15 = v14 << 18;
if ( v6 == -1 )
v6 = v15;
v3 -= 64LL;
if ( !v3 )
goto LABEL_12;
if ( v3 <= 0x3F )
break;
LABEL_28:
if ( v4 == -1LL || v4 >= v5 )
{
a1 = "idx wtf\n";
printf("idx wtf\n");
v5 = free_page_size;
}
}
if ( v4 >= v5 )
{
LABEL_31:
if ( v3 == v2 )
{
LABEL_35:
func1(a1);
printf("frame: can't find 0x%lx frames\n", v2);
return 0LL;
}
++v4;
v3 = v2;
goto LABEL_28;
}
while ( (-(1 << v3) & *(_QWORD *)(pagebm + 8 * v4)) != 0LL )
{
if ( ++v4 == v5 )
goto LABEL_31;
}
v7 = v4 << 18;
if ( v3 == v2 )
v6 = v7;
LABEL_12:
func7(v6, v2);
v8 = taskbm;
if ( a2 && taskbm )
{
v9 = v6;
v10 = v6 + (v2 << 12);
do
{
v11 = v9 + 4095;
if ( v9 >= 0 )
v11 = v9;
v9 += 4096LL;
*(_QWORD *)(v8 + 8 * (v11 >> 12)) = a2;
}
while ( v9 != v10 );
}
func1(v6);
return v6;
}

original_code:
uint8_t *find_n_frames(const unsigned long nframes, const void *const owner)
{
 unsigned long tf = nframes;
 unsigned long idx,retfr = (uint64_t)-1;
 unsigned long mask;
 long tmp;
 if(!pagebm) return 0;
 if(nframes == 0) return 0;
 else if(nframes == 1) return find_frame(owner);
 idx=0;
 lock_frames();
 while( 1 )
 {
  if(tf>=64) {
   for(tmp=-1;idx<free_page_size;idx++) {
    if(pagebm[idx] == 0) {
     tmp = (long)idx*64*(1024*4);
                      break;
    }
   }
   if( tmp == -1 ) goto notfound;
   else if( retfr == -1UL ) retfr = (uint64_t)tmp;
   tf-=64;
   idx++;
  }
  if(tf == 0) {
   idx--;
   goto foundone;
  } else if(tf<64) {
   mask = ~((1<<tf) - 1);
   for( ; idx<free_page_size ; idx++) {
    if( (~(pagebm[idx]) & mask) == mask) {
     if(tf == nframes) {
      retfr = idx*64*(1024*4);
     }
     goto foundone;
    }
   }
   if(tf == nframes ) {
    goto notfound;
   } else {
    tf = nframes;
    idx++;
   }
  }
  if(idx == -1UL || idx >= free_page_size) { printf("idx wtf\n"); }
 }
foundone:
 tmp = (unsigned long)retfr;
 tf = nframes;
 set_n_frames((void *)tmp, nframes);
 if(taskbm && owner) while(tf--) {
  taskbm[tmp/(1024*4)] = owner;
  tmp += (1024*4);
 }
 unlock_frames();
 return (void *)retfr;
notfound:
 unlock_frames();
 printf("frame: can't find 0x%lx frames\n", nframes);
 return 0;
}

canonical_original_code:
unsigned char *find_n_frames(unsigned long nframes, void *owner)
{
 unsigned long tf = nframes;
 unsigned long idx; unsigned long retfr = (uint64_t)-1;
 unsigned long mask;
 long tmp;
 if(!pagebm) return 0;
 if(nframes == 0) return 0;
 else if(nframes == 1) return find_frame(owner);
 idx=0;
 lock_frames();
 while( 1 )
 {
  if(tf>=64) {
   for(tmp=-1;idx<free_page_size;idx++) {
    if(pagebm[idx] == 0) {
     tmp = (long)idx*64*(1024*4);
                      break;
    }
   }
   if( tmp == -1 ) goto notfound;
   else if( retfr == -1UL ) retfr = (unsigned long)tmp;
   tf-=64;
   idx++;
  }
  if(tf == 0) {
   idx--;
   goto foundone;
  } else if(tf<64) {
   mask = ~((1<<tf) - 1);
   for( ; idx<free_page_size ; idx++) {
    if( (~(pagebm[idx]) & mask) == mask) {
     if(tf == nframes) {
      retfr = idx*64*(1024*4);
     }
     goto foundone;
    }
   }
   if(tf == nframes ) {
    goto notfound;
   } else {
    tf = nframes;
    idx++;
   }
  }
  if(idx == -1UL || idx >= free_page_size) { printf("idx wtf\n"); }
 }
foundone:
 tmp = (unsigned long)retfr;
 tf = nframes;
 set_n_frames((void *)tmp, nframes);
 if(taskbm && owner) while(tf--) {
  taskbm[tmp/(1024*4)] = owner;
  tmp += (1024*4);
 }
 unlock_frames();
 return (void *)retfr;
notfound:
 unlock_frames();
 printf("frame: can't find 0x%lx frames\n", nframes);
 return 0;
}

variable_types:
tf
unsigned long

variable_types:
mask
unsigned long

variable_types: tmp long


decompiled_code:
__int64 __fastcall decode_madt(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 result; // rax
unsigned int v3; // er12
const char *v4; // r9
const char *v5; // r8
__int16 v6; // ax
__int16 v7; // dx
const char *v8; // rax
const char *v9; // r9

v1 = a1 + 11;
printf("acpi: MADT: lapic_addr=%x flags=%x loc=%p len=%lx+%x\n", a1[9], a1[10], a1, 44LL, a1[1]);
result = a1[1];
if ( a1 + 11 < (unsigned int *)((char *)a1 + result) )
{
v3 = 0;
do
{
switch ( *(_BYTE *)v1 )
{
case 0:
printf(
"acpi: MADT: LAPIC: cpu_id:%x id:%x flags:%x\n",
*((unsigned __int8 *)v1 + 2),
*((unsigned __int8 *)v1 + 3),
*(unsigned int *)((char *)v1 + 6));
result = a1[1];
break;
case 1:
printf(
"acpi: MADT: IO APIC: id:%x addr:0x%0x int base:0x%0x\n",
*((unsigned __int8 *)v1 + 2),
*(unsigned int *)((char *)v1 + 6),
*(unsigned int *)((char *)v1 + 10));
result = a1[1];
break;
case 2:
v7 = *((_WORD *)v1 + 2);
v8 = "edge ";
v9 = "low ";
if ( (v7 & 8) != 0 )
v8 = "level";
if ( (v7 & 2) == 0 )
v9 = "high";
printf(
"acpi: MADT: INT src: bus:%x irq:%x gsi:%0x flags:%x active %s, %s triggered\n",
*((unsigned __int8 *)v1 + 2),
*((unsigned __int8 *)v1 + 3),
*(unsigned int *)((char *)v1 + 6),
*((unsigned __int16 *)v1 + 5),
v9,
v8);
result = a1[1];
break;
case 4:
v4 = "edge";
v5 = "low";
v6 = *((_WORD *)v1 + 2);
if ( (v6 & 8) != 0 )
v4 = "level";
if ( (v6 & 2) == 0 )
v5 = "high";
printf(
"acpi: MADT: NMI: cpu_id:%x lint:%x flags:%x active %s, %s triggered\n",
*((unsigned __int8 *)v1 + 2),
*((unsigned __int8 *)v1 + 6),
*((unsigned __int16 *)v1 + 2),
v5,
v4);
result = a1[1];
break;
case 5:
printf("acpi: madt[%u]: LAPIC Address Override\n", v3);
result = a1[1];
break;
default:
break;
}
++v3;
v1 = (unsigned int *)((char *)v1 + *((unsigned __int8 *)v1 + 1));
}
while ( (unsigned int *)((char *)a1 + result) > v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
unsigned int *v1; // rbx
__int64 result; // rax
unsigned int v3; // er12
const char *v4; // r9
const char *v5; // r8
__int16 v6; // ax
__int16 v7; // dx
const char *v8; // rax
const char *v9; // r9

v1 = a1 + 11;
printf("acpi: MADT: lapic_addr=%x flags=%x loc=%p len=%lx+%x\n", a1[9], a1[10], a1, 44LL, a1[1]);
result = a1[1];
if ( a1 + 11 < (unsigned int *)((char *)a1 + result) )
{
v3 = 0;
do
{
switch ( *(_BYTE *)v1 )
{
case 0:
printf(
"acpi: MADT: LAPIC: cpu_id:%x id:%x flags:%x\n",
*((unsigned __int8 *)v1 + 2),
*((unsigned __int8 *)v1 + 3),
*(unsigned int *)((char *)v1 + 6));
result = a1[1];
break;
case 1:
printf(
"acpi: MADT: IO APIC: id:%x addr:0x%0x int base:0x%0x\n",
*((unsigned __int8 *)v1 + 2),
*(unsigned int *)((char *)v1 + 6),
*(unsigned int *)((char *)v1 + 10));
result = a1[1];
break;
case 2:
v7 = *((_WORD *)v1 + 2);
v8 = "edge ";
v9 = "low ";
if ( (v7 & 8) != 0 )
v8 = "level";
if ( (v7 & 2) == 0 )
v9 = "high";
printf(
"acpi: MADT: INT src: bus:%x irq:%x gsi:%0x flags:%x active %s, %s triggered\n",
*((unsigned __int8 *)v1 + 2),
*((unsigned __int8 *)v1 + 3),
*(unsigned int *)((char *)v1 + 6),
*((unsigned __int16 *)v1 + 5),
v9,
v8);
result = a1[1];
break;
case 4:
v4 = "edge";
v5 = "low";
v6 = *((_WORD *)v1 + 2);
if ( (v6 & 8) != 0 )
v4 = "level";
if ( (v6 & 2) == 0 )
v5 = "high";
printf(
"acpi: MADT: NMI: cpu_id:%x lint:%x flags:%x active %s, %s triggered\n",
*((unsigned __int8 *)v1 + 2),
*((unsigned __int8 *)v1 + 6),
*((unsigned __int16 *)v1 + 2),
v5,
v4);
result = a1[1];
break;
case 5:
printf("acpi: madt[%u]: LAPIC Address Override\n", v3);
result = a1[1];
break;
default:
break;
}
++v3;
v1 = (unsigned int *)((char *)v1 + *((unsigned __int8 *)v1 + 1));
}
while ( (unsigned int *)((char *)a1 + result) > v1 );
}
return result;
}

original_code:
__attribute__((nonnull)) static void decode_madt(struct ACPIMADT *const h)
{
 uint64_t ptr = (uint64_t)h;
 int cnt = 0;
 printf("acpi: MADT: lapic_addr=%x flags=%x loc=%p len=%lx+%x\n",
   h->lapic_addr, h->flags,
   (void *)h, sizeof(struct ACPIMADT), h->h.Length);
 ptr += sizeof(*h);
 while(ptr < (uint64_t)((uint64_t)h + h->h.Length))
 {
  struct MADTEntry *ent = (struct MADTEntry *)ptr;
  switch(ent->type)
  {
   case 0:
    {
     printf("acpi: MADT: LAPIC:   cpu_id:%x id:%x flags:%x\n",
       ent->lapic.acpi_cpu_id,
       ent->lapic.apic_id,
       ent->lapic.flags);
    }
    break;
   case 1:
    {
     printf("acpi: MADT: IO APIC: id:%x addr:0x%0x int base:0x%0x\n",
       ent->ioapic.id,
       ent->ioapic.addr,
       ent->ioapic.global);
    }
    break;
   case 2:
    {
     printf("acpi: MADT: INT src: bus:%x irq:%x gsi:%0x flags:%x active %s, %s triggered\n",
       ent->src.bus,
       ent->src.irq,
       ent->src.gsi,
       ent->src.flags,
       ent->nmi.flags & 2 ? "low " : "high",
       ent->nmi.flags & 8 ? "level" : "edge "
       );
    }
    break;
   case 4:
    {
     printf("acpi: MADT: NMI:     cpu_id:%x lint:%x flags:%x active %s, %s triggered\n",
       ent->nmi.acpi_cpu_id,
       ent->nmi.lint_num,
       ent->nmi.flags,
       ent->nmi.flags & 2 ? "low" : "high",
       ent->nmi.flags & 8 ? "level" : "edge"
       );
    }
    break;
   case 5:
    printf("acpi: madt[%u]: LAPIC Address Override\n", cnt);
    break;
  }
  ptr += ent->len;
  cnt++;
 }
}

canonical_original_code:
static void decode_madt(struct ACPIMADT *h)
{
 unsigned long ptr = (uint64_t)h;
 int cnt = 0;
 printf("acpi: MADT: lapic_addr=%x flags=%x loc=%p len=%lx+%x\n",
   h->lapic_addr, h->flags,
   (void *)h, sizeof(struct ACPIMADT), h->h.Length);
 ptr += sizeof(*h);
 while(ptr < (unsigned long)((unsigned long)h + h->h.Length))
 {
  struct MADTEntry *ent = (struct MADTEntry *)ptr;
  switch(ent->type)
  {
   case 0:
    {
     printf("acpi: MADT: LAPIC:   cpu_id:%x id:%x flags:%x\n",
       ent->lapic.acpi_cpu_id,
       ent->lapic.apic_id,
       ent->lapic.flags);
    }
    break;
   case 1:
    {
     printf("acpi: MADT: IO APIC: id:%x addr:0x%0x int base:0x%0x\n",
       ent->ioapic.id,
       ent->ioapic.addr,
       ent->ioapic.global);
    }
    break;
   case 2:
    {
     printf("acpi: MADT: INT src: bus:%x irq:%x gsi:%0x flags:%x active %s, %s triggered\n",
       ent->src.bus,
       ent->src.irq,
       ent->src.gsi,
       ent->src.flags,
       ent->nmi.flags & 2 ? "low " : "high",
       ent->nmi.flags & 8 ? "level" : "edge "
       );
    }
    break;
   case 4:
    {
     printf("acpi: MADT: NMI:     cpu_id:%x lint:%x flags:%x active %s, %s triggered\n",
       ent->nmi.acpi_cpu_id,
       ent->nmi.lint_num,
       ent->nmi.flags,
       ent->nmi.flags & 2 ? "low" : "high",
       ent->nmi.flags & 8 ? "level" : "edge"
       );
    }
    break;
   case 5:
    printf("acpi: madt[%u]: LAPIC Address Override\n", cnt);
    break;
  }
  ptr += ent->len;
  cnt++;
 }
}

variable_types: struct ACPIMADT { struct ACPISDTHeader { char Signature[4]; unsigned int Length; unsigned char Revision; unsigned char Checksum; char OEMID[6]; char OEMTableID[8]; unsigned int OEMRevision; unsigned int CreatorID; unsigned int CreatorRevision; } h; unsigned int lapic_addr; unsigned int flags; } *

variable_types: cnt int

variable_types: struct MADTEntry { unsigned char type; unsigned char len; union { struct { unsigned char acpi_cpu_id; unsigned char apic_id; unsigned int flags; } lapic; struct { unsigned char id; unsigned char res; unsigned int addr; unsigned int global; } ioapic; struct { unsigned char bus; unsigned char irq; unsigned int gsi; unsigned short flags; } src; struct { unsigned char acpi_cpu_id; unsigned short flags; unsigned char lint_num; } nmi; }; } *

user_defined_types: struct ACPIMADT { struct ACPISDTHeader h; unsigned int lapic_addr; unsigned int flags; }


decompiled_code:
int __fastcall decode_facp(__int64 a1)
{
__int64 v1; // rsi

printf(
"acpi: FADT: len=%u firmware:%0x dsdt:%0x sci_int:%x smi_cmd:%0x m_profile:",
*(unsigned int *)(a1 + 4),
*(unsigned int *)(a1 + 36),
*(unsigned int *)(a1 + 40),
*(unsigned __int16 *)(a1 + 46),
*(unsigned int *)(a1 + 48));
v1 = *(unsigned __int8 *)(a1 + 45);
if ( (_BYTE)v1 == 1 )
{
printf("desktop");
}
else if ( (_BYTE)v1 == 2 )
{
printf("mobile");
}
else if ( (_BYTE)v1 )
{
printf("unknown[%d]", v1);
}
else
{
printf("unspecified");
}
printf("\n");
printf(
"acpi: FADT: C2_latency:%x C3_latency:%x\nacpi: FADT: flags[%x]:",
*(unsigned __int16 *)(a1 + 96),
*(unsigned __int16 *)(a1 + 98),
*(unsigned int *)(a1 + 112));
print_bits(*(unsigned int *)(a1 + 112), bits_fadt_flags, 22LL, 44LL);
printf(" iapc_boot_arch[%x]:", *(unsigned __int16 *)(a1 + 109));
print_bits(*(unsigned __int16 *)(a1 + 109), bits_fadt_iapc_boot_arch, 6LL, 44LL);
return printf("\n");
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rsi

printf(
"acpi: FADT: len=%u firmware:%0x dsdt:%0x sci_int:%x smi_cmd:%0x m_profile:",
*(unsigned int *)(a1 + 4),
*(unsigned int *)(a1 + 36),
*(unsigned int *)(a1 + 40),
*(unsigned __int16 *)(a1 + 46),
*(unsigned int *)(a1 + 48));
v1 = *(unsigned __int8 *)(a1 + 45);
if ( (_BYTE)v1 == 1 )
{
printf("desktop");
}
else if ( (_BYTE)v1 == 2 )
{
printf("mobile");
}
else if ( (_BYTE)v1 )
{
printf("unknown[%d]", v1);
}
else
{
printf("unspecified");
}
printf("\n");
printf(
"acpi: FADT: C2_latency:%x C3_latency:%x\nacpi: FADT: flags[%x]:",
*(unsigned __int16 *)(a1 + 96),
*(unsigned __int16 *)(a1 + 98),
*(unsigned int *)(a1 + 112));
print_bits(*(unsigned int *)(a1 + 112), bits_fadt_flags, 22LL, 44LL);
printf(" iapc_boot_arch[%x]:", *(unsigned __int16 *)(a1 + 109));
print_bits(*(unsigned __int16 *)(a1 + 109), bits_fadt_iapc_boot_arch, 6LL, 44LL);
return printf("\n");
}

original_code:
__attribute__((nonnull)) static void decode_facp(struct ACPIFADT *h)
{
 printf("acpi: FADT: len=%u firmware:%0x dsdt:%0x sci_int:%x smi_cmd:%0x m_profile:",
   h->h.Length,
   h->firmware_ctrl,
   h->dsdt,
   h->sci_int,
   h->smi_cmd
   );
 switch(h->preferred_pm_profile)
 {
  case 0: printf("unspecified"); break;
  case 1: printf("desktop"); break;
  case 2: printf("mobile"); break;
  default: printf("unknown[%d]", h->preferred_pm_profile); break;
 }
 printf("\n");
 printf( "acpi: FADT: C2_latency:%x C3_latency:%x\n"
   "acpi: FADT: flags[%x]:",
   h->p_lvl2_lat,
   h->p_lvl3_lat,
   h->flags.a
    );
 print_bits(h->flags.a, bits_fadt_flags, max_bits_fadt_flags, ',');
 printf(" iapc_boot_arch[%x]:", h->iapc_boot_arch.a);
 print_bits(h->iapc_boot_arch.a, bits_fadt_iapc_boot_arch, max_bits_fadt_iapc_boot_arch, ',');
 printf("\n");
}

variable_types: struct ACPIFADT { struct ACPISDTHeader { char Signature[4]; unsigned int Length; unsigned char Revision; unsigned char Checksum; char OEMID[6]; char OEMTableID[8]; unsigned int OEMRevision; unsigned int CreatorID; unsigned int CreatorRevision; } h; unsigned int firmware_ctrl; unsigned int dsdt; unsigned char res0; unsigned char preferred_pm_profile; unsigned short sci_int; unsigned int smi_cmd; unsigned char acpi_enable; unsigned char acpi_disable; unsigned char s4bios_req; unsigned char pstate_cnt; unsigned int pm1a_evt_blk; unsigned int pm1b_evt_blk; unsigned int pm1a_cnt_blk; unsigned int pm1b_cnt_blk; unsigned int pm2_cnt_blk; unsigned int pm_tmr_blk; unsigned int gpe0_blk; unsigned int gpe1_blk; unsigned char pm1_evt_len; unsigned char pm1_cnt_len; unsigned char pm2_cnt_len; unsigned char pm_tmr_len; unsigned char gpe0_blk_len; unsigned char gpe1_blk_len; unsigned char gpe1_base; unsigned char cst_cnt; unsigned short p_lvl2_lat; unsigned short p_lvl3_lat; unsigned short flush_size; unsigned short flush_stride; unsigned char duty_offset; unsigned char duty_width; unsigned char day_alrm; unsigned char mon_alrm; unsigned char century; union fadt_iapc_boot_arch { struct { unsigned int legacy_devices; unsigned int i8042; unsigned int no_vga; unsigned int no_msi; unsigned int pcie_aspm; unsigned int no_cmos_rtc; unsigned int res0; }; unsigned short a; } iapc_boot_arch; unsigned char res1; union fadt_flags { struct { unsigned int wbinvd; unsigned int wbinvd_flush; unsigned int proc_c1; unsigned int p_lvl2_up; unsigned int pwr_button; unsigned int slp_button; unsigned int fix_rtc; unsigned int rtc_s4; unsigned int tmr_val_ext; unsigned int dkc_cap; unsigned int reset_reg_sup; unsigned int sealed_case; unsigned int headless; unsigned int cpu_sw_slp; unsigned int pci_exp_wak; unsigned int use_platform_clock; unsigned int s4_rtc_sts_valid; unsigned int remote_power_on_capable; unsigned int force_apic_cluster_model; unsigned int force_apic_phys_dest_mode; unsigned int hw_reduced_acpi; unsigned int low_power_s0_idle_cap; unsigned int reserved; }; unsigned int a; } flags; struct fadt_gas { unsigned char address_space; unsigned char bit_width; unsigned char bit_offset; unsigned char access_size; unsigned long address; } reset_reg; unsigned char reset_value; unsigned short arm_boot_arch; unsigned char fadt_minor_version; unsigned long x_firmware_ctrl; unsigned long x_dsdt; struct fadt_gas x_pm1a_evt_blk; struct fadt_gas x_pm1b_evt_blk; struct fadt_gas x_pm1a_cnt_blk; struct fadt_gas x_pm1b_cnt_blk; struct fadt_gas x_pm2_cnt_blk; struct fadt_gas x_pm_tmr_blk; struct fadt_gas x_gpe0_blk; struct fadt_gas x_gpe1_blk; struct fadt_gas sleep_control_reg; struct fadt_gas sleep_status_reg; unsigned long hyp_vend_id; } *

user_defined_types: struct ACPIFADT { struct ACPISDTHeader h; unsigned int firmware_ctrl; unsigned int dsdt; unsigned char res0; unsigned char preferred_pm_profile; unsigned short sci_int; unsigned int smi_cmd; unsigned char acpi_enable; unsigned char acpi_disable; unsigned char s4bios_req; unsigned char pstate_cnt; unsigned int pm1a_evt_blk; unsigned int pm1b_evt_blk; unsigned int pm1a_cnt_blk; unsigned int pm1b_cnt_blk; unsigned int pm2_cnt_blk; unsigned int pm_tmr_blk; unsigned int gpe0_blk; unsigned int gpe1_blk; unsigned char pm1_evt_len; unsigned char pm1_cnt_len; unsigned char pm2_cnt_len; unsigned char pm_tmr_len; unsigned char gpe0_blk_len; unsigned char gpe1_blk_len; unsigned char gpe1_base; unsigned char cst_cnt; unsigned short p_lvl2_lat; unsigned short p_lvl3_lat; unsigned short flush_size; unsigned short flush_stride; unsigned char duty_offset; unsigned char duty_width; unsigned char day_alrm; unsigned char mon_alrm; unsigned char century; union fadt_iapc_boot_arch iapc_boot_arch; unsigned char res1; union fadt_flags flags; struct fadt_gas reset_reg; unsigned char reset_value; unsigned short arm_boot_arch; unsigned char fadt_minor_version; unsigned long x_firmware_ctrl; unsigned long x_dsdt; struct fadt_gas x_pm1a_evt_blk; struct fadt_gas x_pm1b_evt_blk; struct fadt_gas x_pm1a_cnt_blk; struct fadt_gas x_pm1b_cnt_blk; struct fadt_gas x_pm2_cnt_blk; struct fadt_gas x_pm_tmr_blk; struct fadt_gas x_gpe0_blk; struct fadt_gas x_gpe1_blk; struct fadt_gas sleep_control_reg; struct fadt_gas sleep_status_reg; unsigned long hyp_vend_id; }


decompiled_code:
__int64 __fastcall decode_hpet(__int64 a1)
{
const char *v1; // rax
int v2; // ebp
unsigned __int8 *v3; // r13
__int64 *v4; // rbx
__int64 v5; // rdx
__int64 v6; // r8
__int64 v7; // r9
__int64 v8; // rcx
__int64 v9; // r9
__int64 v10; // r8
__int64 v11; // rdx
__int64 v12; // rcx
__int64 result; // rax

v1 = "system IO";
if ( !*(_BYTE *)(a1 + 40) )
v1 = "system memory";
v2 = 0;
printf(
"hpet%u: rev=%u comp=%u pci_vendor_id=%x addr=0x%lx[%s]\n",
*(unsigned __int8 *)(a1 + 52),
*(unsigned __int8 *)(a1 + 36),
*(_BYTE *)(a1 + 37) & 0x1F,
*(unsigned __int16 *)(a1 + 38),
*(_QWORD *)(a1 + 44),
v1);
v3 = *(unsigned __int8 **)(a1 + 44);
v4 = (__int64 *)(v3 + 32);
create_page_entry_4k(kernel_pd, v3, v3, 259LL, 0LL);
v5 = *v3;
v6 = *((unsigned int *)v3 + 1);
v7 = *((_QWORD *)v3 + 1) | 3LL;
v8 = v3[1] & 0x1F;
*((_QWORD *)v3 + 1) = v7;
printf("hpet%u: rev_id=%u num_tim_cap=%u clk=%u conf=%lx\n", *(unsigned __int8 *)(a1 + 52), v5, v8, v6, v7);
do
{
v9 = v4[2];
v10 = v4[1];
v11 = (unsigned int)v2;
v12 = *v4;
++v2;
v4 += 3;
printf("hpet%u.%u: conf:%lx comp:%lx intr:%lx\n", *(unsigned __int8 *)(a1 + 52), v11, v12, v10, v9);
result = v3[1] & 0x1F;
}
while ( (int)result >= v2 );
return result;
}

original_code:
__attribute__((nonnull)) static void decode_hpet(struct ACPIHPET *const h)
{
 printf("hpet%u: rev=%u comp=%u pci_vendor_id=%x addr=0x%lx[%s]\n",
   h->hpet_number,
   h->hardware_rev_id,
   h->comparator_count,
   h->pci_vendor_id,
   h->address.address,
   h->address.address_space_id ? "system IO" : "system memory"
   );
 struct hpet *hpet = (void *)h->address.address;
 create_page_entry_4k(kernel_pd, (uint64_t)hpet, (uint64_t)hpet, 0x001|0x002|0x100, ((void*)0));
 hpet->conf |= 0x1|0x2;
 printf("hpet%u: rev_id=%u num_tim_cap=%u clk=%u conf=%lx\n",
   h->hpet_number,
   hpet->rev_id,
   hpet->num_tim_cap,
   hpet->counter_clk,
   hpet->conf);
 for(int i = 0; i < hpet->num_tim_cap + 1; i++)
 {
  printf("hpet%u.%u: conf:%lx comp:%lx intr:%lx\n",
    h->hpet_number,
    i,
    hpet->timers[i].conf,
    hpet->timers[i].comp,
    hpet->timers[i].intr);
 }
}

canonical_original_code:
static void decode_hpet(struct ACPIHPET *h)
{
 printf("hpet%u: rev=%u comp=%u pci_vendor_id=%x addr=0x%lx[%s]\n",
   h->hpet_number,
   h->hardware_rev_id,
   h->comparator_count,
   h->pci_vendor_id,
   h->address.address,
   h->address.address_space_id ? "system IO" : "system memory"
   );
 struct hpet *hpet = (void *)h->address.address;
 create_page_entry_4k(kernel_pd, (unsigned long)hpet, (unsigned long)hpet, 0x001|0x002|0x100, ((void *)0));
 hpet->conf |= 0x1|0x2;
 printf("hpet%u: rev_id=%u num_tim_cap=%u clk=%u conf=%lx\n",
   h->hpet_number,
   hpet->rev_id,
   hpet->num_tim_cap,
   hpet->counter_clk,
   hpet->conf);
 for(int i = 0; i < hpet->num_tim_cap + 1; i++)
 {
  printf("hpet%u.%u: conf:%lx comp:%lx intr:%lx\n",
    h->hpet_number,
    i,
    hpet->timers[i].conf,
    hpet->timers[i].comp,
    hpet->timers[i].intr);
 }
}

variable_types: struct ACPIHPET { struct ACPISDTHeader { char Signature[4]; unsigned int Length; unsigned char Revision; unsigned char Checksum; char OEMID[6]; char OEMTableID[8]; unsigned int OEMRevision; unsigned int CreatorID; unsigned int CreatorRevision; } h; unsigned char hardware_rev_id; unsigned int comparator_count; unsigned int counter_size; unsigned int reserved; unsigned int legacy_replacement; unsigned short pci_vendor_id; struct address_structure { unsigned char address_space_id; unsigned char register_bit_width; unsigned char register_bit_offset; unsigned char reserved; unsigned long address; } address; unsigned char hpet_number; unsigned short minimum_tick; unsigned char page_protection; } *

variable_types: struct hpet { union { unsigned long cap_id; struct { unsigned int rev_id; unsigned int num_tim_cap; unsigned int count_size_cap; unsigned int res0; unsigned int leg_rt_cap; unsigned int vendor_id; unsigned int counter_clk; }; }; union { unsigned long conf; struct { unsigned int enable_cnf; unsigned int leg_rt_cnf; unsigned long reserved; }; }; unsigned long intr; unsigned long main; struct { union { unsigned long conf; struct { unsigned int res0; unsigned int int_type_cnf; unsigned int int_enb_cnf; unsigned int type_cnf; unsigned int per_int_cnf; unsigned int size_cap; unsigned int val_set_cnf; unsigned int res1; unsigned int int_route_cnf; unsigned int fsb_en_cnf; unsigned int fsb_int_del_cap; unsigned int res2; unsigned int int_route_cap; }; }; unsigned long comp; unsigned long intr; } timers[]; } *

user_defined_types: struct ACPIHPET { struct ACPISDTHeader h; unsigned char hardware_rev_id; unsigned int comparator_count; unsigned int counter_size; unsigned int reserved; unsigned int legacy_replacement; unsigned short pci_vendor_id; struct address_structure address; unsigned char hpet_number; unsigned short minimum_tick; unsigned char page_protection; }


decompiled_code:
int __fastcall decode_sdt(unsigned int *a1)
{
unsigned int v1; // er12

v1 = *a1;
printf(
"acpi: %c%c%c%c: 0x%0x %x ver=%x (%c%c%c%c%c%c) (%c%c%c%c%c%c%c%c) %x %x %x\n",
(unsigned int)*(char *)a1,
(unsigned int)*((char *)a1 + 1),
(unsigned int)*((char *)a1 + 2),
(unsigned int)*((char *)a1 + 3),
(unsigned int)a1,
a1[1],
*((unsigned __int8 *)a1 + 8),
(unsigned int)*((char *)a1 + 10),
(unsigned int)*((char *)a1 + 11),
(unsigned int)*((char *)a1 + 12),
(unsigned int)*((char *)a1 + 13),
(unsigned int)*((char *)a1 + 14),
(unsigned int)*((char *)a1 + 15),
(unsigned int)*((char *)a1 + 16),
(unsigned int)*((char *)a1 + 17),
(unsigned int)*((char *)a1 + 18),
(unsigned int)*((char *)a1 + 19),
(unsigned int)*((char *)a1 + 20),
(unsigned int)*((char *)a1 + 21),
(unsigned int)*((char *)a1 + 22),
(unsigned int)*((char *)a1 + 23),
a1[6],
a1[7],
a1[8]);
switch ( v1 )
{
case 0x50434146u:
return decode_facp((__int64)a1);
case 0x54455048u:
return decode_hpet((__int64)a1);
case 0x43495041u:
return decode_madt(a1);
}
return printf(
"acpi_probe: unknown sig %x '%c%c%c%c'\n",
v1,
(unsigned int)*(char *)a1,
(unsigned int)*((char *)a1 + 1),
(unsigned int)*((char *)a1 + 2),
(unsigned int)*((char *)a1 + 3));
}

canonical_decompiled_code:
int __fastcall func3(unsigned int *a1)
{
unsigned int v1; // er12

v1 = *a1;
printf(
"acpi: %c%c%c%c: 0x%0x %x ver=%x (%c%c%c%c%c%c) (%c%c%c%c%c%c%c%c) %x %x %x\n",
(unsigned int)*(char *)a1,
(unsigned int)*((char *)a1 + 1),
(unsigned int)*((char *)a1 + 2),
(unsigned int)*((char *)a1 + 3),
(unsigned int)a1,
a1[1],
*((unsigned __int8 *)a1 + 8),
(unsigned int)*((char *)a1 + 10),
(unsigned int)*((char *)a1 + 11),
(unsigned int)*((char *)a1 + 12),
(unsigned int)*((char *)a1 + 13),
(unsigned int)*((char *)a1 + 14),
(unsigned int)*((char *)a1 + 15),
(unsigned int)*((char *)a1 + 16),
(unsigned int)*((char *)a1 + 17),
(unsigned int)*((char *)a1 + 18),
(unsigned int)*((char *)a1 + 19),
(unsigned int)*((char *)a1 + 20),
(unsigned int)*((char *)a1 + 21),
(unsigned int)*((char *)a1 + 22),
(unsigned int)*((char *)a1 + 23),
a1[6],
a1[7],
a1[8]);
switch ( v1 )
{
case 0x50434146u:
return func1((__int64)a1);
case 0x54455048u:
return func2((__int64)a1);
case 0x43495041u:
return func0(a1);
}
return printf(
"acpi_probe: unknown sig %x '%c%c%c%c'\n",
v1,
(unsigned int)*(char *)a1,
(unsigned int)*((char *)a1 + 1),
(unsigned int)*((char *)a1 + 2),
(unsigned int)*((char *)a1 + 3));
}

original_code:
__attribute__((nonnull)) static void decode_sdt(const struct ACPISDTHeader *const h)
{
 uint32_t sig;
 sig = *(uint32_t*)h->Signature;
 printf("acpi: %c%c%c%c: 0x%0x %x ver=%x (%c%c%c%c%c%c) (%c%c%c%c%c%c%c%c) %x %x %x\n",
   h->Signature[0],
   h->Signature[1],
   h->Signature[2],
   h->Signature[3],
   (uint32_t)(uint64_t)h,
   h->Length,
   h->Revision,
   h->OEMID[0],
   h->OEMID[1],
   h->OEMID[2],
   h->OEMID[3],
   h->OEMID[4],
   h->OEMID[5],
   h->OEMTableID[0],
   h->OEMTableID[1],
   h->OEMTableID[2],
   h->OEMTableID[3],
   h->OEMTableID[4],
   h->OEMTableID[5],
   h->OEMTableID[6],
   h->OEMTableID[7],
   h->OEMRevision,
   h->CreatorID,
   h->CreatorRevision
   );
 switch(sig)
 {
  case 0x50434146:
   decode_facp((struct ACPIFADT *)h);
   break;
  case 0x43495041:
   decode_madt((struct ACPIMADT *)h);
   break;
  case 0x54455048:
   decode_hpet((struct ACPIHPET *)h);
   break;
  default:
   printf("acpi_probe: unknown sig %x '%c%c%c%c'\n",
     sig,
     h->Signature[0],
     h->Signature[1],
     h->Signature[2],
     h->Signature[3]
     );
 }
}

canonical_original_code:
static void decode_sdt(struct ACPISDTHeader *h)
{
 unsigned int sig;
 sig = *(unsigned int *)h->Signature;
 printf("acpi: %c%c%c%c: 0x%0x %x ver=%x (%c%c%c%c%c%c) (%c%c%c%c%c%c%c%c) %x %x %x\n",
   h->Signature[0],
   h->Signature[1],
   h->Signature[2],
   h->Signature[3],
   (unsigned int)(unsigned long)h,
   h->Length,
   h->Revision,
   h->OEMID[0],
   h->OEMID[1],
   h->OEMID[2],
   h->OEMID[3],
   h->OEMID[4],
   h->OEMID[5],
   h->OEMTableID[0],
   h->OEMTableID[1],
   h->OEMTableID[2],
   h->OEMTableID[3],
   h->OEMTableID[4],
   h->OEMTableID[5],
   h->OEMTableID[6],
   h->OEMTableID[7],
   h->OEMRevision,
   h->CreatorID,
   h->CreatorRevision
   );
 switch(sig)
 {
  case 0x50434146:
   decode_facp((struct ACPIFADT *)h);
   break;
  case 0x43495041:
   decode_madt((struct ACPIMADT *)h);
   break;
  case 0x54455048:
   decode_hpet((struct ACPIHPET *)h);
   break;
  default:
   printf("acpi_probe: unknown sig %x '%c%c%c%c'\n",
     sig,
     h->Signature[0],
     h->Signature[1],
     h->Signature[2],
     h->Signature[3]
     );
 }
}

variable_types: struct ACPISDTHeader { char Signature[4]; unsigned int Length; unsigned char Revision; unsigned char Checksum; char OEMID[6]; char OEMTableID[8]; unsigned int OEMRevision; unsigned int CreatorID; unsigned int CreatorRevision; } *

variable_types:
sig
unsigned int

user_defined_types: union fadt_iapc_boot_arch { struct { unsigned int legacy_devices; unsigned int i8042; unsigned int no_vga; unsigned int no_msi; unsigned int pcie_aspm; unsigned int no_cmos_rtc; unsigned int res0; }; unsigned short a; }

user_defined_types: union fadt_flags { struct { unsigned int wbinvd; unsigned int wbinvd_flush; unsigned int proc_c1; unsigned int p_lvl2_up; unsigned int pwr_button; unsigned int slp_button; unsigned int fix_rtc; unsigned int rtc_s4; unsigned int tmr_val_ext; unsigned int dkc_cap; unsigned int reset_reg_sup; unsigned int sealed_case; unsigned int headless; unsigned int cpu_sw_slp; unsigned int pci_exp_wak; unsigned int use_platform_clock; unsigned int s4_rtc_sts_valid; unsigned int remote_power_on_capable; unsigned int force_apic_cluster_model; unsigned int force_apic_phys_dest_mode; unsigned int hw_reduced_acpi; unsigned int low_power_s0_idle_cap; unsigned int reserved; }; unsigned int a; }

user_defined_types: struct fadt_gas { unsigned char address_space; unsigned char bit_width; unsigned char bit_offset; unsigned char access_size; unsigned long address; }

user_defined_types: struct address_structure { unsigned char address_space_id; unsigned char register_bit_width; unsigned char register_bit_offset; unsigned char reserved; unsigned long address; }


decompiled_code:
__int64 acpi_probe()
{
__int64 v0; // rsi
__int64 v1; // rbx
__int64 v2; // r11
unsigned __int64 v3; // rbx
int v4; // ebp
int v5; // ebx
__int64 v6; // rax
unsigned int v7; // er8
__int64 v8; // rax
__int64 v9; // rbx
unsigned __int64 v10; // rbx
char s[31]; // [rsp+9h] [rbp-1Fh] BYREF

RSDP = 0LL;
RSDT = 0LL;
XSDT = 0LL;
printf("acpi_probe: ");
v0 = 57344LL;
while ( *(_QWORD *)v0 != 0x2052545020445352LL )
{
v0 += 16LL;
if ( v0 == 0x100000 )
goto LABEL_5;
}
RSDP = v0;
printf("found at 0x%0x\n", v0);
LABEL_5:
if ( RSDP )
{
memset(s, 0, 7uLL);
memcpy(s, (const void *)(RSDP + 9), 6uLL);
printf("acpi: OEM='%s' rev=%u RSDT=0x%x", s, *(unsigned __int8 *)(RSDP + 15), *(unsigned int *)(RSDP + 16));
if ( *(_BYTE *)(RSDP + 15) > 1u )
printf("len=%x XSDT=0x%lx", *(unsigned int *)(RSDP + 20), *(_QWORD *)(RSDP + 24));
printf("\n");
v1 = *(unsigned int *)((char *)&loc_2 + *(unsigned int *)(RSDP + 16) + 2);
v2 = *(unsigned int *)((char *)&loc_1F + *(unsigned int *)(RSDP + 16) + 1);
RSDT = *(unsigned int *)(RSDP + 16);
v3 = (unsigned __int64)(v1 - 36) >> 2;
v4 = v3;
printf(
"acpi: %c%c%c%c: len=%x oemrev=%x cID=%x crev=%x rsdt[%u]=0x%p\n",
(unsigned int)*(char *)(unsigned int)RSDT,
(unsigned int)*(char *)(RSDT + 1),
(unsigned int)*(char *)(RSDT + 2),
(unsigned int)*(char *)(RSDT + 3),
*(unsigned int *)(RSDT + 4),
*(unsigned int *)(RSDT + 24),
*(unsigned int *)(RSDT + 28),
v2,
v3,
(const void *)RSDT);
if ( (int)v3 > 0 )
{
v5 = 0;
do
{
v6 = v5++;
decode_sdt((unsigned int *)*(unsigned int *)(RSDT + 4 * (v6 + 8) + 4));
}
while ( v4 != v5 );
}
v7 = 0;
if ( *(_BYTE *)(RSDP + 15) > 1u && *(_QWORD *)(RSDP + 24) )
{
v8 = *(_QWORD *)(RSDP + 24);
v9 = *(unsigned int *)(v8 + 4);
XSDT = v8;
v10 = (unsigned __int64)(v9 - 36) >> 3;
if ( v8 == RSDT )
printf("acpi: XSDT exists and points to RSDT ");
else
printf("acpi: XSDT differs from RSDT ");
printf("XSDT[%u]=0x%p\n", (unsigned int)v10, (const void *)XSDT);
v7 = 0;
}
}
else
{
printf("not found\n");
v7 = -1;
}
return v7;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rsi
__int64 v1; // rbx
__int64 v2; // r11
unsigned __int64 v3; // rbx
int v4; // ebp
int v5; // ebx
__int64 v6; // rax
unsigned int v7; // er8
__int64 v8; // rax
__int64 v9; // rbx
unsigned __int64 v10; // rbx
char s[31]; // [rsp+9h] [rbp-1Fh] BYREF

RSDP = 0LL;
RSDT = 0LL;
XSDT = 0LL;
printf("acpi_probe: ");
v0 = 57344LL;
while ( *(_QWORD *)v0 != 0x2052545020445352LL )
{
v0 += 16LL;
if ( v0 == 0x100000 )
goto LABEL_5;
}
RSDP = v0;
printf("found at 0x%0x\n", v0);
LABEL_5:
if ( RSDP )
{
memset(s, 0, 7uLL);
memcpy(s, (const void *)(RSDP + 9), 6uLL);
printf("acpi: OEM='%s' rev=%u RSDT=0x%x", s, *(unsigned __int8 *)(RSDP + 15), *(unsigned int *)(RSDP + 16));
if ( *(_BYTE *)(RSDP + 15) > 1u )
printf("len=%x XSDT=0x%lx", *(unsigned int *)(RSDP + 20), *(_QWORD *)(RSDP + 24));
printf("\n");
v1 = *(unsigned int *)((char *)&loc_2 + *(unsigned int *)(RSDP + 16) + 2);
v2 = *(unsigned int *)((char *)&loc_1F + *(unsigned int *)(RSDP + 16) + 1);
RSDT = *(unsigned int *)(RSDP + 16);
v3 = (unsigned __int64)(v1 - 36) >> 2;
v4 = v3;
printf(
"acpi: %c%c%c%c: len=%x oemrev=%x cID=%x crev=%x rsdt[%u]=0x%p\n",
(unsigned int)*(char *)(unsigned int)RSDT,
(unsigned int)*(char *)(RSDT + 1),
(unsigned int)*(char *)(RSDT + 2),
(unsigned int)*(char *)(RSDT + 3),
*(unsigned int *)(RSDT + 4),
*(unsigned int *)(RSDT + 24),
*(unsigned int *)(RSDT + 28),
v2,
v3,
(const void *)RSDT);
if ( (int)v3 > 0 )
{
v5 = 0;
do
{
v6 = v5++;
func3((unsigned int *)*(unsigned int *)(RSDT + 4 * (v6 + 8) + 4));
}
while ( v4 != v5 );
}
v7 = 0;
if ( *(_BYTE *)(RSDP + 15) > 1u && *(_QWORD *)(RSDP + 24) )
{
v8 = *(_QWORD *)(RSDP + 24);
v9 = *(unsigned int *)(v8 + 4);
XSDT = v8;
v10 = (unsigned __int64)(v9 - 36) >> 3;
if ( v8 == RSDT )
printf("acpi: XSDT exists and points to RSDT ");
else
printf("acpi: XSDT differs from RSDT ");
printf("XSDT[%u]=0x%p\n", (unsigned int)v10, (const void *)XSDT);
v7 = 0;
}
}
else
{
printf("not found\n");
v7 = -1;
}
return v7;
}

original_code:
int acpi_probe(void)
{
 char *tmp;
 uint64_t offset;
 RSDP = ((void*)0);
 RSDT = ((void*)0);
 XSDT = ((void*)0);
 printf("acpi_probe: ");
 for(offset = 0xe000; offset < 0xFFFFF; offset+=16)
 {
  tmp = (char *)(0 + offset);
  if(*(uint64_t *)tmp == acpi_id) {
   RSDP = (struct RSDPDescriptor20 *)tmp;
   printf("found at 0x%0x\n", (uint32_t)(uint64_t)tmp);
   break;
  }
 }
 if(RSDP == ((void*)0)) {
  printf("not found\n");
  return -1;
 }
 char acpi_OEMID[7];
 memset(acpi_OEMID, 0, 7);
 memcpy(acpi_OEMID, (char *)RSDP->OEMID, 6);
 printf("acpi: OEM='%s' rev=%u RSDT=0x%x",
   acpi_OEMID,
   RSDP->Revision,
   RSDP->RsdtAddress);
 if((uint32_t)RSDP->Revision >= 2) {
  printf("len=%x XSDT=0x%lx",
    RSDP->Length,
    RSDP->XsdtAddress);
 }
 printf("\n");
 int RSDT_ent;
 int XSDT_ent;
 RSDT = (struct ACPIRSDT *)(uint64_t)RSDP->RsdtAddress;
 RSDT_ent = (RSDT->h.Length - sizeof(RSDT->h)) / sizeof(uint32_t);
 printf("acpi: %c%c%c%c: len=%x oemrev=%x cID=%x crev=%x rsdt[%u]=0x%p\n",
   RSDT->h.Signature[0], RSDT->h.Signature[1],
   RSDT->h.Signature[2], RSDT->h.Signature[3],
   RSDT->h.Length, RSDT->h.OEMRevision, RSDT->h.CreatorID,
   RSDT->h.CreatorRevision,
   RSDT_ent,
   (void *)RSDT);
 for(int i = 0; i < RSDT_ent; i++) {
  decode_sdt((struct ACPISDTHeader *)(uint64_t)RSDT->otherSDT[i]);
 }
 if(RSDP->Revision >= 2 && RSDP->XsdtAddress) {
  XSDT = (struct ACPIXSDT *)(uint64_t)RSDP->XsdtAddress;
  XSDT_ent = (XSDT->h.Length - sizeof(XSDT->h)) / sizeof(uint64_t);
  if((void *)XSDT == (void *)RSDT)
   printf("acpi: XSDT exists and points to RSDT ");
  else
   printf("acpi: XSDT differs from RSDT ");
  printf("XSDT[%u]=0x%p\n",
    XSDT_ent,
    (void *)XSDT);
 }
 return 0;
}

canonical_original_code:
int acpi_probe()
{
 char *tmp;
 unsigned long offset;
 RSDP = ((void *)0);
 RSDT = ((void *)0);
 XSDT = ((void *)0);
 printf("acpi_probe: ");
 for(offset = 0xe000; offset < 0xFFFFF; offset+=16)
 {
  tmp = (char *)(0 + offset);
  if(*(unsigned long *)tmp == acpi_id) {
   RSDP = (struct RSDPDescriptor20 *)tmp;
   printf("found at 0x%0x\n", (unsigned int)(unsigned long)tmp);
   break;
  }
 }
 if(RSDP == ((void *)0)) {
  printf("not found\n");
  return -1;
 }
 char acpi_OEMID[7];
 memset(acpi_OEMID, 0, 7);
 memcpy(acpi_OEMID, (char *)RSDP->OEMID, 6);
 printf("acpi: OEM='%s' rev=%u RSDT=0x%x",
   acpi_OEMID,
   RSDP->Revision,
   RSDP->RsdtAddress);
 if((unsigned int)RSDP->Revision >= 2) {
  printf("len=%x XSDT=0x%lx",
    RSDP->Length,
    RSDP->XsdtAddress);
 }
 printf("\n");
 int RSDT_ent;
 int XSDT_ent;
 RSDT = (struct ACPIRSDT *)(unsigned long)RSDP->RsdtAddress;
 RSDT_ent = (RSDT->h.Length - sizeof(RSDT->h)) / sizeof(unsigned int);
 printf("acpi: %c%c%c%c: len=%x oemrev=%x cID=%x crev=%x rsdt[%u]=0x%p\n",
   RSDT->h.Signature[0], RSDT->h.Signature[1],
   RSDT->h.Signature[2], RSDT->h.Signature[3],
   RSDT->h.Length, RSDT->h.OEMRevision, RSDT->h.CreatorID,
   RSDT->h.CreatorRevision,
   RSDT_ent,
   (void *)RSDT);
 for(int i = 0; i < RSDT_ent; i++) {
  decode_sdt((struct ACPISDTHeader *)(unsigned long)RSDT->otherSDT[i]);
 }
 if(RSDP->Revision >= 2 && RSDP->XsdtAddress) {
  XSDT = (struct ACPIXSDT *)(unsigned long)RSDP->XsdtAddress;
  XSDT_ent = (XSDT->h.Length - sizeof(XSDT->h)) / sizeof(unsigned long);
  if((void *)XSDT == (void *)RSDT)
   printf("acpi: XSDT exists and points to RSDT ");
  else
   printf("acpi: XSDT differs from RSDT ");
  printf("XSDT[%u]=0x%p\n",
    XSDT_ent,
    (void *)XSDT);
 }
 return 0;
}

variable_types:
tmp
char *

variable_types:
offset
unsigned long

variable_types: i int

user_defined_types: struct RSDPDescriptor20 { char Signature[8]; unsigned char Checksum; char OEMID[6]; unsigned char Revision; unsigned int RsdtAddress; unsigned int Length; unsigned long XsdtAddress; unsigned char ExtendedChecksum; unsigned char reserved[3]; }

user_defined_types: struct ACPIRSDT { struct ACPISDTHeader h; unsigned int otherSDT[]; }

user_defined_types: struct ACPISDTHeader { char Signature[4]; unsigned int Length; unsigned char Revision; unsigned char Checksum; char OEMID[6]; char OEMTableID[8]; unsigned int OEMRevision; unsigned int CreatorID; unsigned int CreatorRevision; }

user_defined_types: struct ACPIXSDT { struct ACPISDTHeader h; unsigned long otherSDT[]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // eax
int v5; // er12
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "fb:");
if ( v3 == -1 )
break;
if ( v3 == 98 )
{
opt_blksize = atoi(optarg);
}
else
{
if ( v3 != 102 )
{
if ( ((*__ctype_b_loc())[v3] & 0x4000) == 0 )
v3 = 63;
warnx("Unknown option '%c'\n", v3);
show_usage();
}
opt_force = 1;
}
}
if ( !opt_blksize )
opt_blksize = 512;
if ( argc - optind != 1 )
{
warnx("Missing file or device\n");
show_usage();
}
if ( !opt_force )
errx(1, "please pass -f to erase file or device");
v4 = open(argv[optind], 2);
v5 = v4;
if ( v4 == -1 )
err(1, "open: %s\n", argv[optind]);
if ( (unsigned int)fstat(v4, &v7) == -1 )
err(1, "stat: %s\n", argv[optind]);
if ( (v7.st_mode & 0xF000) != 0x8000 )
err(1, "%s is not a regular file", argv[optind]);
ffs_format(v5);
close(v5);
puts("mkfs.failfs: done");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // eax
int v5; // er12
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "fb:");
if ( v3 == -1 )
break;
if ( v3 == 98 )
{
opt_blksize = atoi(optarg);
}
else
{
if ( v3 != 102 )
{
if ( ((*__ctype_b_loc())[v3] & 0x4000) == 0 )
v3 = 63;
warnx("Unknown option '%c'\n", v3);
func7();
}
opt_force = 1;
}
}
if ( !opt_blksize )
opt_blksize = 512;
if ( argc - optind != 1 )
{
warnx("Missing file or device\n");
func7();
}
if ( !opt_force )
errx(1, "please pass -f to erase file or device");
v4 = open(argv[optind], 2);
v5 = v4;
if ( v4 == -1 )
err(1, "open: %s\n", argv[optind]);
if ( (unsigned int)func11(v4, &v7) == -1 )
err(1, "stat: %s\n", argv[optind]);
if ( (v7.st_mode & 0xF000) != 0x8000 )
err(1, "%s is not a regular file", argv[optind]);
func8(v5);
close(v5);
puts("mkfs.failfs: done");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int opt;
 while( (opt = getopt(argc, argv, "fb:")) != -1 )
 {
  switch( opt ) {
   case 'f':
    opt_force = 1;
    break;
   case 'b':
    opt_blksize = atoi(optarg);
    break;
   default:
    warnx("Unknown option '%c'\n", ((*__ctype_b_loc ())[(int) ((opt))] & (unsigned short int) _ISprint) ? opt : '?');
    show_usage();
  }
 }
 if( opt_blksize == 0 )
  opt_blksize = 512;
 if( (argc - optind) != 1 ) {
  warnx("Missing file or device\n");
  show_usage();
 }
 if( !opt_force )
  errx(1, "please pass -f to erase file or device");
 int fd;
 if( (fd = open(argv[optind], 02)) == -1 )
  err(1, "open: %s\n", argv[optind]);
 struct stat sb;
 if( fstat(fd, &sb) == -1 )
  err(1, "stat: %s\n", argv[optind]);
 if( (sb.st_mode & 0170000) != 0100000 )
  err(1, "%s is not a regular file", argv[optind]);
 ffs_format(fd, sb.st_size, opt_blksize);
 close(fd);
 printf("mkfs.failfs: done\n");
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int opt;
 while( (opt = getopt(argc, argv, "fb:")) != -1 )
 {
  switch( opt ) {
   case 'f':
    opt_force = 1;
    break;
   case 'b':
    opt_blksize = atoi(optarg);
    break;
   default:
    warnx("Unknown option '%c'\n", ((*__ctype_b_loc ())[(int) ((opt))] & (unsigned short) _ISprint) ? opt : '?');
    show_usage();
  }
 }
 if( opt_blksize == 0 )
  opt_blksize = 512;
 if( (argc - optind) != 1 ) {
  warnx("Missing file or device\n");
  show_usage();
 }
 if( !opt_force )
  errx(1, "please pass -f to erase file or device");
 int fd;
 if( (fd = open(argv[optind], 02)) == -1 )
  err(1, "open: %s\n", argv[optind]);
 struct stat sb;
 if( fstat(fd, &sb) == -1 )
  err(1, "stat: %s\n", argv[optind]);
 if( (sb.st_mode & 0170000) != 0100000 )
  err(1, "%s is not a regular file", argv[optind]);
 ffs_format(fd, sb.st_size, opt_blksize);
 close(fd);
 printf("mkfs.failfs: done\n");
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void __noreturn show_usage()
{
fwrite("Usage: mkfs.ffs [-f] file|device\n", 1uLL, 0x21uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite("Usage: mkfs.ffs [-f] file|device\n", 1uLL, 0x21uLL, stderr);
exit(1);
}

original_code:
static __attribute__((noreturn)) void show_usage()
{
 fprintf(stderr, "Usage: mkfs.ffs [-f] file|device\n");
 exit(1);
}

canonical_original_code:
static void show_usage()
{
 fprintf(stderr, "Usage: mkfs.ffs [-f] file|device\n");
 exit(1);
}