decompiled_code:
__int64 __fastcall network_iface_iget(int a1, char **a2)
{
char *v2; // rax
int i; // edx

v2 = network_ifaces;
*a2 = 0LL;
if ( !v2 )
return 1LL;
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v2 = (char *)*((_QWORD *)v2 + 11);
if ( !v2 )
return 1LL;
}
}
*a2 = v2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char **a2)
{
char *v2; // rax
int i; // edx

v2 = network_ifaces;
*a2 = 0LL;
if ( !v2 )
return 1LL;
if ( a1 )
{
for ( i = 0; i != a1; ++i )
{
v2 = (char *)*((_QWORD *)v2 + 11);
if ( !v2 )
return 1LL;
}
}
*a2 = v2;
return 0LL;
}

original_code:
uint32_t network_iface_iget(uint32_t x, network_iface_t **iface)
{
 network_iface_t *cf = network_ifaces;
 uint32_t i = 0;
 *iface = 0;
 while(cf != 0)
 {
  if(i == x)
  {
   *iface = cf;
   return 0;
  }
  i++;
  cf = cf->next;
 }
 return 1;
}

canonical_original_code:
unsigned int network_iface_iget(unsigned int x, struct network_iface_p **iface)
{
 struct network_iface_p *cf = network_ifaces;
 unsigned int i = 0;
 *iface = 0;
 while(cf != 0)
 {
  if(i == x)
  {
   *iface = cf;
   return 0;
  }
  i++;
  cf = cf->next;
 }
 return 1;
}

variable_types:
x
unsigned int

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } **

variable_types:
i
unsigned int


repo: dakk/spiderpig-os

decompiled_code:
int __fastcall network_iface_get(char *s1, char **a2)
{
char *v2; // rbx
int result; // eax

v2 = network_ifaces;
*a2 = 0LL;
if ( !v2 )
return 1;
while ( 1 )
{
result = strcmp(s1, v2);
if ( !result )
break;
v2 = (char *)*((_QWORD *)v2 + 11);
if ( !v2 )
return 1;
}
*a2 = v2;
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1, char **a2)
{
char *v2; // rbx
int result; // eax

v2 = network_ifaces;
*a2 = 0LL;
if ( !v2 )
return 1;
while ( 1 )
{
result = strcmp(s1, v2);
if ( !result )
break;
v2 = (char *)*((_QWORD *)v2 + 11);
if ( !v2 )
return 1;
}
*a2 = v2;
return result;
}

original_code:
uint32_t network_iface_get(char *name, network_iface_t **iface)
{
 network_iface_t *cf = network_ifaces;
 *iface = 0;
 while(cf != 0)
 {
  if(strcmp(name, cf->name) == 0)
  {
   *iface = cf;
   return 0;
  }
  cf = cf->next;
 }
 return 1;
}

canonical_original_code:
unsigned int network_iface_get(char *name, struct network_iface_p **iface)
{
 struct network_iface_p *cf = network_ifaces;
 *iface = 0;
 while(cf != 0)
 {
  if(strcmp(name, cf->name) == 0)
  {
   *iface = cf;
   return 0;
  }
  cf = cf->next;
 }
 return 1;
}

variable_types:
name
char *

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *

return_type: unsigned int

user_defined_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; }

user_defined_types: struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t fs; struct driver_video_t video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; }

user_defined_types: struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; }


decompiled_code:
__int64 __fastcall network_iface_down(char *s1)
{
__int64 result; // rax
char *v2; // [rsp+8h] [rbp-10h] BYREF

debug_puts("network_iface_down()\n");
network_iface_get(s1, &v2);
result = 1LL;
if ( v2 )
{
v2[50] = 0;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
__int64 result; // rax
char *v2; // [rsp+8h] [rbp-10h] BYREF

debug_puts("network_iface_down()\n");
func2(s1, &v2);
result = 1LL;
if ( v2 )
{
v2[50] = 0;
result = 0LL;
}
return result;
}

original_code:
uint32_t network_iface_down(char *ifname)
{
 debug_puts("network_iface_down()\n");
 network_iface_t *ci;
 network_iface_get(ifname, &ci);
 if(ci != 0)
 {
  ci->if_up = 0;
  return 0;
 }
 return 1;
}

canonical_original_code:
unsigned int network_iface_down(char *ifname)
{
 debug_puts("network_iface_down()\n");
 struct network_iface_p *ci;
 network_iface_get(ifname, &ci);
 if(ci != 0)
 {
  ci->if_up = 0;
  return 0;
 }
 return 1;
}

variable_types:
ifname
char *

user_defined_types: struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); }

user_defined_types: struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; }

user_defined_types: struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; }

user_defined_types: struct dirent { char name[255]; unsigned int inode; }

user_defined_types: struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; }


decompiled_code:
__int64 __fastcall network_iface_up(char *s1)
{
__int64 v1; // rdx
__int64 v2; // rcx
char *v3; // rax
unsigned int v4; // er8
__int64 v5; // rdi
char *v7[2]; // [rsp+8h] [rbp-10h] BYREF

debug_puts("network_iface_up()\n");
network_iface_get(s1, v7);
v3 = v7[0];
v4 = 1;
if ( v7[0] )
{
*((_QWORD *)v7[0] + 7) = 0LL;
v5 = *((_QWORD *)v3 + 8);
v3[50] = 1;
driver_initd(v5, v7, v1, v2, 1LL);
v4 = 0;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s1)
{
__int64 v1; // rdx
__int64 v2; // rcx
char *v3; // rax
unsigned int v4; // er8
__int64 v5; // rdi
char *v7[2]; // [rsp+8h] [rbp-10h] BYREF

debug_puts("network_iface_up()\n");
func2(s1, v7);
v3 = v7[0];
v4 = 1;
if ( v7[0] )
{
*((_QWORD *)v7[0] + 7) = 0LL;
v5 = *((_QWORD *)v3 + 8);
v3[50] = 1;
driver_initd(v5, v7, v1, v2, 1LL);
v4 = 0;
}
return v4;
}

original_code:
uint32_t network_iface_up(char *ifname)
{
 debug_puts("network_iface_up()\n");
 network_iface_t *ci;
 network_iface_get(ifname, &ci);
 if(ci != 0)
 {
  ci->tx_bytes = 0;
  ci->rx_bytes = 0;
  ci->if_up = 1;
  driver_initd((ci->drv)->name);
  return 0;
 }
 return 1;
}

canonical_original_code:
unsigned int network_iface_up(char *ifname)
{
 debug_puts("network_iface_up()\n");
 struct network_iface_p *ci;
 network_iface_get(ifname, &ci);
 if(ci != 0)
 {
  ci->tx_bytes = 0;
  ci->rx_bytes = 0;
  ci->if_up = 1;
  driver_initd((ci->drv)->name);
  return 0;
 }
 return 1;
}


decompiled_code:
char *__fastcall network_addrtoa(unsigned __int8 *a1, char *a2)
{
const char *v2; // rax
const char *v3; // rax
const char *v4; // rax
const char *v5; // rax

v2 = (const char *)itoa(*a1);
strcpy(a2, v2);
strcat(a2, src);
v3 = (const char *)itoa(a1[1]);
strcat(a2, v3);
strcat(a2, src);
v4 = (const char *)itoa(a1[2]);
strcat(a2, v4);
strcat(a2, src);
v5 = (const char *)itoa(a1[3]);
strcat(a2, v5);
strcat(a2, byte_1016E70);
return a2;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned __int8 *a1, char *a2)
{
const char *v2; // rax
const char *v3; // rax
const char *v4; // rax
const char *v5; // rax

v2 = (const char *)itoa(*a1);
strcpy(a2, v2);
strcat(a2, src);
v3 = (const char *)itoa(a1[1]);
strcat(a2, v3);
strcat(a2, src);
v4 = (const char *)itoa(a1[2]);
strcat(a2, v4);
strcat(a2, src);
v5 = (const char *)itoa(a1[3]);
strcat(a2, v5);
strcat(a2, byte_1016E70);
return a2;
}

original_code:
char *network_addrtoa(ip_t addr, char *str)
{
 strcpy(str, itoa((uint8_t) addr[0]));
 strcat(str, ".");
 strcat(str, itoa((uint8_t) addr[1]));
 strcat(str, ".");
 strcat(str, itoa((uint8_t) addr[2]));
 strcat(str, ".");
 strcat(str, itoa((uint8_t) addr[3]));
 strcat(str, "\0");
 return str;
}

canonical_original_code:
char *network_addrtoa(char addr[4], char *str)
{
 strcpy(str, itoa((unsigned char) addr[0]));
 strcat(str, ".");
 strcat(str, itoa((unsigned char) addr[1]));
 strcat(str, ".");
 strcat(str, itoa((unsigned char) addr[2]));
 strcat(str, ".");
 strcat(str, itoa((unsigned char) addr[3]));
 strcat(str, "\0");
 return str;
}

variable_types:
addr
char [4]

variable_types:
str
char *

return_type: char *


decompiled_code:
char *__fastcall network_macrtoa(unsigned __int8 *a1, char *a2)
{
const char *v2; // rax
const char *v3; // rax
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

v2 = (const char *)itox(*a1);
strcpy(a2, v2);
strcat(a2, &src[2]);
v3 = (const char *)itox(a1[1]);
strcat(a2, v3);
strcat(a2, &src[2]);
v4 = (const char *)itox(a1[2]);
strcat(a2, v4);
strcat(a2, &src[2]);
v5 = (const char *)itox(a1[3]);
strcat(a2, v5);
strcat(a2, &src[2]);
v6 = (const char *)itox(a1[4]);
strcat(a2, v6);
strcat(a2, &src[2]);
v7 = (const char *)itox(a1[5]);
strcat(a2, v7);
strcat(a2, byte_1016E70);
return a2;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned __int8 *a1, char *a2)
{
const char *v2; // rax
const char *v3; // rax
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax

v2 = (const char *)itox(*a1);
strcpy(a2, v2);
strcat(a2, &src[2]);
v3 = (const char *)itox(a1[1]);
strcat(a2, v3);
strcat(a2, &src[2]);
v4 = (const char *)itox(a1[2]);
strcat(a2, v4);
strcat(a2, &src[2]);
v5 = (const char *)itox(a1[3]);
strcat(a2, v5);
strcat(a2, &src[2]);
v6 = (const char *)itox(a1[4]);
strcat(a2, v6);
strcat(a2, &src[2]);
v7 = (const char *)itox(a1[5]);
strcat(a2, v7);
strcat(a2, byte_1016E70);
return a2;
}

original_code:
char *network_macrtoa(mac_t addr, char *str)
{
 strcpy(str, itox((uint8_t) addr[0]));
 strcat(str, ":");
 strcat(str, itox((uint8_t) addr[1]));
 strcat(str, ":");
 strcat(str, itox((uint8_t) addr[2]));
 strcat(str, ":");
 strcat(str, itox((uint8_t) addr[3]));
 strcat(str, ":");
 strcat(str, itox((uint8_t) addr[4]));
 strcat(str, ":");
 strcat(str, itox((uint8_t) addr[5]));
 strcat(str, "\0");
 return str;
}

canonical_original_code:
char *network_macrtoa(char addr[6], char *str)
{
 strcpy(str, itox((unsigned char) addr[0]));
 strcat(str, ":");
 strcat(str, itox((unsigned char) addr[1]));
 strcat(str, ":");
 strcat(str, itox((unsigned char) addr[2]));
 strcat(str, ":");
 strcat(str, itox((unsigned char) addr[3]));
 strcat(str, ":");
 strcat(str, itox((unsigned char) addr[4]));
 strcat(str, ":");
 strcat(str, itox((unsigned char) addr[5]));
 strcat(str, "\0");
 return str;
}

variable_types:
addr
char [6]


decompiled_code:
void __fastcall network_toaddr(_BYTE *a1, char a2, char a3, char a4, char a5)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
a1[3] = a5;
}

canonical_decompiled_code:
void __fastcall func7(_BYTE *a1, char a2, char a3, char a4, char a5)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
a1[3] = a5;
}

original_code:
void network_toaddr(ip_t buf, uint8_t a, uint8_t b, uint8_t c, uint8_t d)
{
 buf[0] = a;
 buf[1] = b;
 buf[2] = c;
 buf[3] = d;
}

canonical_original_code:
void network_toaddr(char buf[4], unsigned char a, unsigned char b, unsigned char c, unsigned char d)
{
 buf[0] = a;
 buf[1] = b;
 buf[2] = c;
 buf[3] = d;
}

variable_types:
buf
char [4]

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
c
unsigned char

variable_types:
d
unsigned char

return_type: void


decompiled_code:
__int64 __fastcall network_iface_create(int a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
char v5; // dl
char v6; // cl
char v7; // dl
char v8; // cl
char v9; // r8
__int64 result; // rax
signed int v11; // eax

if ( a2 && a3 )
{
v11 = (unsigned int)malloc(0x60uLL);
v4 = v11;
*(_QWORD *)((char *)&loc_38 + v11) = 0LL;
*(_QWORD *)((char *)network_iface_iget + v11) = a2;
*(_QWORD *)((char *)&loc_47 + v11 + 1) = a3;
*((_BYTE *)&loc_32 + v11 + 3) = a1;
*((_BYTE *)&loc_32 + v11) = 0;
switch ( a1 )
{
case 1:
goto LABEL_5;
case 2:
strcpy((char *)v11, off_1016E4B);
result = v4;
*(_QWORD *)(v4 + 80) = &eth_linkproto;
break;
case 3:
strcpy((char *)v11, off_1016E52);
result = v4;
*(_QWORD *)(v4 + 80) = &ppp_linkproto;
break;
case 6:
strcpy((char *)v11, "wifi");
result = v4;
*(_QWORD *)(v4 + 80) = &wifi_linkproto;
break;
case 7:
strcpy((char *)v11, "bt");
result = v4;
*(_QWORD *)(v4 + 80) = &bt_linkproto;
break;
default:
free((void *)v11);
result = 0LL;
break;
}
}
else
{
v4 = 0LL;
if ( a1 == 1 )
{
v4 = (int)malloc(0x60uLL);
*(_QWORD *)((char *)&loc_38 + v4) = 0LL;
*(_QWORD *)((char *)network_iface_iget + v4) = a2;
*(_QWORD *)((char *)&loc_47 + v4 + 1) = a3;
*((_BYTE *)&loc_32 + v4 + 3) = 1;
*((_BYTE *)&loc_32 + v4) = 0;
LABEL_5:
strcpy((char *)v4, "lo");
network_toaddr((_BYTE *)(v4 + 32), 127, 0, 0, 1);
network_toaddr((_BYTE *)(v4 + 36), 255, v5, v6, 0);
network_toaddr((_BYTE *)(v4 + 40), 0, v7, v8, v9);
*(_BYTE *)(v4 + 51) = 0;
*(_QWORD *)(v4 + 80) = &lo_linkproto;
}
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2, __int64 a3)
{
__int64 v4; // r12
char v5; // dl
char v6; // cl
char v7; // dl
char v8; // cl
char v9; // r8
__int64 result; // rax
signed int v11; // eax

if ( a2 && a3 )
{
v11 = (unsigned int)malloc(0x60uLL);
v4 = v11;
*(_QWORD *)((char *)&loc_38 + v11) = 0LL;
*(_QWORD *)((char *)network_iface_iget + v11) = a2;
*(_QWORD *)((char *)&loc_47 + v11 + 1) = a3;
*((_BYTE *)&loc_32 + v11 + 3) = a1;
*((_BYTE *)&loc_32 + v11) = 0;
switch ( a1 )
{
case 1:
goto LABEL_5;
case 2:
strcpy((char *)v11, off_1016E4B);
result = v4;
*(_QWORD *)(v4 + 80) = &eth_linkproto;
break;
case 3:
strcpy((char *)v11, off_1016E52);
result = v4;
*(_QWORD *)(v4 + 80) = &ppp_linkproto;
break;
case 6:
strcpy((char *)v11, "wifi");
result = v4;
*(_QWORD *)(v4 + 80) = &wifi_linkproto;
break;
case 7:
strcpy((char *)v11, "bt");
result = v4;
*(_QWORD *)(v4 + 80) = &bt_linkproto;
break;
default:
free((void *)v11);
result = 0LL;
break;
}
}
else
{
v4 = 0LL;
if ( a1 == 1 )
{
v4 = (int)malloc(0x60uLL);
*(_QWORD *)((char *)&loc_38 + v4) = 0LL;
*(_QWORD *)((char *)network_iface_iget + v4) = a2;
*(_QWORD *)((char *)&loc_47 + v4 + 1) = a3;
*((_BYTE *)&loc_32 + v4 + 3) = 1;
*((_BYTE *)&loc_32 + v4) = 0;
LABEL_5:
strcpy((char *)v4, "lo");
func7((_BYTE *)(v4 + 32), 127, 0, 0, 1);
func7((_BYTE *)(v4 + 36), 255, v5, v6, 0);
func7((_BYTE *)(v4 + 40), 0, v7, v8, v9);
*(_BYTE *)(v4 + 51) = 0;
*(_QWORD *)(v4 + 80) = &lo_linkproto;
}
result = v4;
}
return result;
}

original_code:
network_iface_t *network_iface_create(uint32_t type, driver_t *driver, device_t *device)
{
 if(((driver == 0) || (device == 0)) && type != 1)
  return 0;
 network_iface_t *iface = (network_iface_t *) malloc(sizeof(network_iface_t));
 iface->tx_bytes = 0;
 iface->rx_bytes = 0;
 iface->drv = driver;
 iface->dev = device;
 iface->type = type;
 iface->if_up = 0;
 switch(type)
 {
  case 2:
   strcpy(iface->name, "eth");
   iface->link_protocol = (void *) &eth_linkproto;
   break;
  case 1:
   strcpy(iface->name, "lo");
   network_toaddr(iface->addr, 127, 0, 0, 1);
   network_toaddr(iface->mask, 255, 0, 0, 0);
   network_toaddr(iface->bcast, 0, 0, 0, 0);
   iface->if_mac = 0;
   iface->link_protocol = (void *) &lo_linkproto;
   break;
  case 3:
   strcpy(iface->name, "ppp");
   iface->link_protocol = (void *) &ppp_linkproto;
   break;
  case 7:
   strcpy(iface->name, "bt");
   iface->link_protocol = (void *) &bt_linkproto;
   break;
  case 6:
   strcpy(iface->name, "wifi");
   iface->link_protocol = (void *) &wifi_linkproto;
   break;
  default:
   free(iface);
   return 0;
 }
 return iface;
}

canonical_original_code:
struct network_iface_p *network_iface_create(unsigned int type, struct driver_p *driver, struct device_p *device)
{
 if(((driver == 0) || (device == 0)) && type != 1)
  return 0;
 struct network_iface_p *iface = (network_iface_t *) malloc(sizeof(network_iface_t));
 iface->tx_bytes = 0;
 iface->rx_bytes = 0;
 iface->drv = driver;
 iface->dev = device;
 iface->type = type;
 iface->if_up = 0;
 switch(type)
 {
  case 2:
   strcpy(iface->name, "eth");
   iface->link_protocol = (void *) &eth_linkproto;
   break;
  case 1:
   strcpy(iface->name, "lo");
   network_toaddr(iface->addr, 127, 0, 0, 1);
   network_toaddr(iface->mask, 255, 0, 0, 0);
   network_toaddr(iface->bcast, 0, 0, 0, 0);
   iface->if_mac = 0;
   iface->link_protocol = (void *) &lo_linkproto;
   break;
  case 3:
   strcpy(iface->name, "ppp");
   iface->link_protocol = (void *) &ppp_linkproto;
   break;
  case 7:
   strcpy(iface->name, "bt");
   iface->link_protocol = (void *) &bt_linkproto;
   break;
  case 6:
   strcpy(iface->name, "wifi");
   iface->link_protocol = (void *) &wifi_linkproto;
   break;
  default:
   free(iface);
   return 0;
 }
 return iface;
}

variable_types:
type
unsigned int

variable_types:
driver
struct driver_p *

variable_types:
device
struct device_p *

return_type: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *


decompiled_code:
__int64 __fastcall network_iface_add2(char *s1, __int64 a2, __int64 a3, const void *a4, const void *a5)
{
__int64 v7; // rax
__int64 v8; // rbx

if ( strcmp(s1, "lo") )
{
if ( strcmp(s1, off_1016E4B) )
{
if ( strcmp(s1, off_1016E52) )
strcmp(s1, "wifi");
}
return 0LL;
}
v7 = network_iface_create(1, 0LL, 0LL);
v8 = v7;
if ( !v7 )
return 0LL;
network_iface_add(v7);
network_iface_up(s1);
memcpy((void *)(v8 + 32), a4, 4uLL);
memcpy((void *)(v8 + 36), a5, 4uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s1, __int64 a2, __int64 a3, const void *a4, const void *a5)
{
__int64 v7; // rax
__int64 v8; // rbx

if ( strcmp(s1, "lo") )
{
if ( strcmp(s1, off_1016E4B) )
{
if ( strcmp(s1, off_1016E52) )
strcmp(s1, "wifi");
}
return 0LL;
}
v7 = func8(1, 0LL, 0LL);
v8 = v7;
if ( !v7 )
return 0LL;
func0(v7);
func4(s1);
memcpy((void *)(v8 + 32), a4, 4uLL);
memcpy((void *)(v8 + 36), a5, 4uLL);
return 1LL;
}

original_code:
uint32_t network_iface_add2(char *type, char *driver, char *device, char *adr, char *mask)
{
 network_iface_t *nt = 0;
 if(strcmp(type, "lo") == 0)
  nt = network_iface_create(1, 0, 0);
 else if(strcmp(type, "eth") == 0)
  nt = 0;
 else if(strcmp(type, "ppp") == 0)
  nt = 0;
 else if(strcmp(type, "wifi") == 0)
  nt = 0;
 if(nt != 0)
 {
  network_iface_add(nt);
  network_iface_up(type);
  memcpy(nt->addr, adr, 4);
  memcpy(nt->mask, mask, 4);
  return 1;
 }
 return 0;
}

canonical_original_code:
unsigned int network_iface_add2(char *type, char *driver, char *device, char *adr, char *mask)
{
 struct network_iface_p *nt = 0;
 if(strcmp(type, "lo") == 0)
  nt = network_iface_create(1, 0, 0);
 else if(strcmp(type, "eth") == 0)
  nt = 0;
 else if(strcmp(type, "ppp") == 0)
  nt = 0;
 else if(strcmp(type, "wifi") == 0)
  nt = 0;
 if(nt != 0)
 {
  network_iface_add(nt);
  network_iface_up(type);
  memcpy(nt->addr, adr, 4);
  memcpy(nt->mask, mask, 4);
  return 1;
 }
 return 0;
}

variable_types:
type
char *

variable_types:
driver
char *

variable_types:
device
char *

variable_types:
adr
char *

variable_types:
mask
char *


decompiled_code:
__int64 network_init()
{
__int64 v0; // rax
__int64 v1; // rbp
char v2; // dl
char v3; // cl
char v4; // r8
char v5; // dl
char v6; // cl
__int64 v7; // rax
_BYTE *v8; // rbx
char v9; // dl
char v10; // cl
__int64 v11; // rax
_BYTE *v12; // rbx
char v13; // dl
char v14; // cl
char v15; // r8
char v17[4]; // [rsp+8h] [rbp-90h] BYREF
char v18[4]; // [rsp+Ch] [rbp-8Ch] BYREF
__int128 v19[4]; // [rsp+10h] [rbp-88h] BYREF
__m128i v20; // [rsp+50h] [rbp-48h]
__m128i v21; // [rsp+60h] [rbp-38h]
int v22[10]; // [rsp+70h] [rbp-28h] BYREF

debug_puts("network_init()\n");
network_ifaces = 0LL;
route_table = 0LL;
sock_first_free = 0;
v0 = network_iface_create(1, 0LL, 0LL);
if ( v0 )
{
v1 = v0;
network_iface_add(v0);
network_iface_up("lo");
network_toaddr(v17, 127, 0, 0, 1);
network_toaddr(v18, 127, v2, v3, v4);
network_toaddr(v19, 255, v5, v6, 0);
route_add(v1, v17, v18, v19);
}
v7 = network_iface_create(3, (__int64)&driver_modem, (__int64)&rs232_com1);
v8 = (_BYTE *)v7;
if ( v7 )
{
network_iface_add(v7);
network_toaddr(v8 + 32, 80, 60, 4, 2);
network_toaddr(v8 + 36, 255, 255, 255, 0);
network_toaddr(v8 + 40, 255, v9, v10, 255);
v8[51] = 0;
}
v11 = network_iface_create(2, (__int64)&driver_ne2k, (__int64)&device_ne2k_qemu);
v12 = (_BYTE *)v11;
if ( v11 )
{
network_iface_add(v11);
network_toaddr(v12 + 32, 192, 168, 254, 16);
network_toaddr(v12 + 36, 255, 255, 255, 0);
network_toaddr(v12 + 40, 255, v13, v14, v15);
v12[51] = 0;
}
qmemcpy(v22, "aaaaa", 5);
v19[0] = 0LL;
v19[1] = 0LL;
v19[2] = (__int128)_mm_load_si128((const __m128i *)&LC12);
v19[3] = (__int128)_mm_load_si128((const __m128i *)&LC13);
v20 = _mm_load_si128((const __m128i *)&LC14);
v21 = v20;
packet_create(v19, 101LL);
return sock_test();
}

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *

variable_types:
dest
char [4]

variable_types:
gw
char [4]

variable_types:
genmask
char [4]

variable_types: i int

variable_types: struct packet_t { unsigned int size; char *data; } *


decompiled_code:
__int64 timer_callback()
{
__int64 result; // rax
unsigned __int8 v1; // dl
char v2; // al
char v3; // al
char v4; // dl

task_switch();
++pit_tick;
result = (unsigned int)__ROR4__(-1030792151 * pit_tick, 2);
if ( (unsigned int)result <= 0x28F5C28 )
{
v1 = *(&clock_data + 1);
v2 = *(&clock_data + 2) + 1;
*(&clock_data + 2) = v2;
if ( (unsigned __int8)v2 > 0x3Bu )
*(_WORD *)(&clock_data + 1) = ++v1;
v3 = clock_data;
if ( v1 > 0x3Bu )
{
v3 = clock_data + 1;
*(&clock_data + 1) = 0;
clock_data = v3;
}
v4 = *(&clock_data + 4);
if ( (unsigned __int8)v3 > 0x16u )
{
++v4;
clock_data = 0;
*(&clock_data + 4) = v4;
}
result = (unsigned __int8)*(&clock_data + 3);
if ( (unsigned __int8)v4 > 0x1Du )
{
result = (unsigned int)(result + 1);
*(_WORD *)(&clock_data + 3) = (unsigned __int8)result;
}
if ( (unsigned __int8)result > 0xBu )
{
++*(&clock_data + 5);
*(&clock_data + 3) = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
unsigned __int8 v1; // dl
char v2; // al
char v3; // al
char v4; // dl

task_switch();
++pit_tick;
result = (unsigned int)__ROR4__(-1030792151 * pit_tick, 2);
if ( (unsigned int)result <= 0x28F5C28 )
{
v1 = *(&clock_data + 1);
v2 = *(&clock_data + 2) + 1;
*(&clock_data + 2) = v2;
if ( (unsigned __int8)v2 > 0x3Bu )
*(_WORD *)(&clock_data + 1) = ++v1;
v3 = clock_data;
if ( v1 > 0x3Bu )
{
v3 = clock_data + 1;
*(&clock_data + 1) = 0;
clock_data = v3;
}
v4 = *(&clock_data + 4);
if ( (unsigned __int8)v3 > 0x16u )
{
++v4;
clock_data = 0;
*(&clock_data + 4) = v4;
}
result = (unsigned __int8)*(&clock_data + 3);
if ( (unsigned __int8)v4 > 0x1Du )
{
result = (unsigned int)(result + 1);
*(_WORD *)(&clock_data + 3) = (unsigned __int8)result;
}
if ( (unsigned __int8)result > 0xBu )
{
++*(&clock_data + 5);
*(&clock_data + 3) = 0;
}
}
return result;
}

original_code:
static void timer_callback(regs_t *regs)
{
 task_switch(regs);
 pit_tick++;
 if(pit_tick%100 == 0)
 {
  clock_data.seconds++;
  if(clock_data.seconds >= 60)
  {
   clock_data.seconds = 0;
   clock_data.minutes++;
  }
  if(clock_data.minutes >= 60)
  {
   clock_data.minutes = 0;
   clock_data.hours++;
  }
  if(clock_data.hours >= 23)
  {
   clock_data.hours = 0;
   clock_data.day++;
  }
  if(clock_data.day >= 30)
  {
   clock_data.day = 0;
   clock_data.month++;
  }
  if(clock_data.month >= 12)
  {
   clock_data.month = 0;
   clock_data.year++;
  }
 }
}

canonical_original_code:
static void timer_callback(struct regs_t *regs)
{
 task_switch(regs);
 pit_tick++;
 if(pit_tick%100 == 0)
 {
  clock_data.seconds++;
  if(clock_data.seconds >= 60)
  {
   clock_data.seconds = 0;
   clock_data.minutes++;
  }
  if(clock_data.minutes >= 60)
  {
   clock_data.minutes = 0;
   clock_data.hours++;
  }
  if(clock_data.hours >= 23)
  {
   clock_data.hours = 0;
   clock_data.day++;
  }
  if(clock_data.day >= 30)
  {
   clock_data.day = 0;
   clock_data.month++;
  }
  if(clock_data.month >= 12)
  {
   clock_data.month = 0;
   clock_data.year++;
  }
 }
}

variable_types: struct regs_t { unsigned int edi; unsigned int ds; unsigned int which_int; unsigned int eip; } *


decompiled_code:
void arch_sleep()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void arch_sleep(uint32_t ms)
{
 uint32_t i;
 for(i = 0; i < ms; i++)
 {
  uint32_t end = pit_tick + (1 / 10);
  for(pit_tick;pit_tick < end;);
 }
}

canonical_original_code:
void arch_sleep(unsigned int ms)
{
 unsigned int i;
 for(i = 0; i < ms; i++)
 {
  unsigned int end = pit_tick + (1 / 10);
  for(pit_tick;pit_tick < end;);
 }
}

variable_types:
ms
unsigned int

variable_types:
i
unsigned int

variable_types:
end
unsigned int


decompiled_code:
__int64 timer_init()
{
handler_reg(0LL, timer_callback);
io_outb(67LL, 54LL);
io_outb(64LL, 155LL);
return io_outb(64LL, 46LL);
}

canonical_decompiled_code:
__int64 func2()
{
handler_reg(0LL, timer_callback);
io_outb(67LL, 54LL);
io_outb(64LL, 155LL);
return io_outb(64LL, 46LL);
}

original_code:
void timer_init()
{
 uint32_t divisor;
 uint8_t l;
 uint8_t h;
 uint32_t freq = 100;
 handler_reg(0, &timer_callback);
 divisor = 1193180 / freq;
 io_outb(0x43, 0x36);
 l = (uint8_t)(divisor & 0xFF);
 h = (uint8_t)((divisor>>8) & 0xFF );
 io_outb(0x40, l);
 io_outb(0x40, h);
}

canonical_original_code:
void timer_init()
{
 unsigned int divisor;
 unsigned char l;
 unsigned char h;
 unsigned int freq = 100;
 handler_reg(0, &timer_callback);
 divisor = 1193180 / freq;
 io_outb(0x43, 0x36);
 l = (unsigned char)(divisor & 0xFF);
 h = (unsigned char)((divisor>>8) & 0xFF );
 io_outb(0x40, l);
 io_outb(0x40, h);
}

variable_types:
divisor
unsigned int

variable_types:
l
unsigned char

variable_types:
h
unsigned char

variable_types:
freq
unsigned int


decompiled_code:
__int64 arch_get_tick()
{
return (unsigned int)pit_tick;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)pit_tick;
}

original_code:
uint32_t arch_get_tick()
{
 return pit_tick;
}

canonical_original_code:
unsigned int arch_get_tick()
{
 return pit_tick;
}


decompiled_code:
__int64 __fastcall fs_get_mount_point(char *s2, char *dest)
{
unsigned int v3; // er12
char *v4; // rbx
unsigned int v5; // eax
const char *v6; // rsi

v3 = 0;
v4 = fs_mountpoints;
do
{
while ( 1 )
{
v5 = strlen(v4);
if ( !strncmp(v4, s2, v5) && v4[1560] == 1 )
break;
v4 += 1568;
if ( v4 == &fs_mountpoints[25088] )
return v3;
}
v6 = v4;
v4 += 1568;
strcpy(dest, v6);
v3 = strlen(dest);
}
while ( v4 != &fs_mountpoints[25088] );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2, char *dest)
{
unsigned int v3; // er12
char *v4; // rbx
unsigned int v5; // eax
const char *v6; // rsi

v3 = 0;
v4 = fs_mountpoints;
do
{
while ( 1 )
{
v5 = strlen(v4);
if ( !strncmp(v4, s2, v5) && v4[1560] == 1 )
break;
v4 += 1568;
if ( v4 == &fs_mountpoints[25088] )
return v3;
}
v6 = v4;
v4 += 1568;
strcpy(dest, v6);
v3 = strlen(dest);
}
while ( v4 != &fs_mountpoints[25088] );
return v3;
}

original_code:
uint32_t fs_get_mount_point(char *path, char *mpstr)
{
 unsigned i;
 unsigned t = 0;
 for(i = 0; i < 16; i++)
 {
  if((strncmp(fs_mountpoints[i].path, path, strlen(fs_mountpoints[i].path)) == 0) && (fs_mountpoints[i].used == 1))
  {
   strcpy(mpstr, fs_mountpoints[i].path);
   t = strlen(mpstr);
  }
 }
 return t;
}

canonical_original_code:
unsigned int fs_get_mount_point(char *path, char *mpstr)
{
 unsigned int i;
 unsigned int t = 0;
 for(i = 0; i < 16; i++)
 {
  if((strncmp(fs_mountpoints[i].path, path, strlen(fs_mountpoints[i].path)) == 0) && (fs_mountpoints[i].used == 1))
  {
   strcpy(mpstr, fs_mountpoints[i].path);
   t = strlen(mpstr);
  }
 }
 return t;
}

variable_types:
path
char *

variable_types:
mpstr
char *

variable_types:
t
unsigned int


decompiled_code:
size_t __fastcall fs_get_mount_point_fs(char *s2, char *dest)
{
__int64 v2; // rbx

v2 = 0LL;
while ( strcmp(&fs_mountpoints[v2], s2) )
{
v2 += 1568LL;
if ( v2 == 25088 )
return 0LL;
}
strcpy(dest, &fs_mountpoints[v2 + 1024]);
return strlen(&fs_mountpoints[v2 + 1024]);
}

canonical_decompiled_code:
size_t __fastcall func1(char *s2, char *dest)
{
__int64 v2; // rbx

v2 = 0LL;
while ( strcmp(&fs_mountpoints[v2], s2) )
{
v2 += 1568LL;
if ( v2 == 25088 )
return 0LL;
}
strcpy(dest, &fs_mountpoints[v2 + 1024]);
return strlen(&fs_mountpoints[v2 + 1024]);
}

original_code:
uint32_t fs_get_mount_point_fs(char *path, char *mpstr)
{
 unsigned i;
 for(i = 0; i < 16; i++)
 {
  if(strcmp(fs_mountpoints[i].path, path) == 0)
  {
   strcpy(mpstr, fs_mountpoints[i].fs);
   return strlen(fs_mountpoints[i].fs);
  }
 }
 return 0;
}

canonical_original_code:
unsigned int fs_get_mount_point_fs(char *path, char *mpstr)
{
 unsigned int i;
 for(i = 0; i < 16; i++)
 {
  if(strcmp(fs_mountpoints[i].path, path) == 0)
  {
   strcpy(mpstr, fs_mountpoints[i].fs);
   return strlen(fs_mountpoints[i].fs);
  }
 }
 return 0;
}


decompiled_code:
__int64 __fastcall fs_iget_mount_point(unsigned int a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdi

*a2 = 0LL;
result = 1LL;
if ( a1 <= 0xF )
{
v3 = 1568LL * a1;
if ( *(_QWORD *)&fs_mountpoints[v3 + 1544] )
{
*a2 = &fs_mountpoints[v3];
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdi

*a2 = 0LL;
result = 1LL;
if ( a1 <= 0xF )
{
v3 = 1568LL * a1;
if ( *(_QWORD *)&fs_mountpoints[v3 + 1544] )
{
*a2 = &fs_mountpoints[v3];
result = 0LL;
}
}
return result;
}

original_code:
uint32_t fs_iget_mount_point(uint32_t x, mount_point_t **fs)
{
 *fs = 0;
 if((x < 16) && (fs_mountpoints[x].root != 0))
 {
  *fs = &fs_mountpoints[x];
  return 0;
 }
 return 1;
}

canonical_original_code:
unsigned int fs_iget_mount_point(unsigned int x, struct mount_point_p **fs)
{
 *fs = 0;
 if((x < 16) && (fs_mountpoints[x].root != 0))
 {
  *fs = &fs_mountpoints[x];
  return 0;
 }
 return 1;
}

variable_types:
x
unsigned int

variable_types: struct mount_point_p { char path[512]; char dev[512]; char fs[512]; void *fs_struct; struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *root; struct inode_p *childs; unsigned char used; } **

user_defined_types: struct mount_point_p { char path[512]; char dev[512]; char fs[512]; void *fs_struct; struct inode_p *root; struct inode_p *childs; unsigned char used; }


decompiled_code:
const char *__fastcall fs_get_mount_point_struct(char *a1)
{
const char *v1; // rbx
const char *v2; // r12
char v4[152]; // [rsp+0h] [rbp-98h] BYREF

v1 = fs_mountpoints;
fs_get_mount_point(a1, v4);
do
{
v2 = v1;
if ( !strcmp(v1, v4) )
break;
v1 += 1568;
}
while ( v1 != &fs_mountpoints[25088] );
return v2;
}

canonical_decompiled_code:
const char *__fastcall func3(char *a1)
{
const char *v1; // rbx
const char *v2; // r12
char v4[152]; // [rsp+0h] [rbp-98h] BYREF

v1 = fs_mountpoints;
func0(a1, v4);
do
{
v2 = v1;
if ( !strcmp(v1, v4) )
break;
v1 += 1568;
}
while ( v1 != &fs_mountpoints[25088] );
return v2;
}

original_code:
mount_point_t *fs_get_mount_point_struct(char *path)
{
 uint32_t i;
 char mpname[128];
 fs_get_mount_point(path, mpname);
 for(i = 0; i < 16; i++)
 {
  if(strcmp(fs_mountpoints[i].path, mpname) == 0)
   return &fs_mountpoints[i];
 }
}

canonical_original_code:
struct mount_point_p *fs_get_mount_point_struct(char *path)
{
 unsigned int i;
 char mpname[128];
 fs_get_mount_point(path, mpname);
 for(i = 0; i < 16; i++)
 {
  if(strcmp(fs_mountpoints[i].path, mpname) == 0)
   return &fs_mountpoints[i];
 }
}

variable_types:
mpname
char [128]

return_type: struct mount_point_p { char path[512]; char dev[512]; char fs[512]; void *fs_struct; struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *root; struct inode_p *childs; unsigned char used; } *


decompiled_code:
__int64 __fastcall fs_mount(char *src, char *s1, char *a3)
{
const char *v4; // rbx
char *v5; // rbp
unsigned int v6; // er15
bool v8; // zf
unsigned __int64 v9; // rdx
__int64 v10; // rax
__int64 v11; // rbx
char *v12; // rbp
__int64 v13[8]; // [rsp+8h] [rbp-40h] BYREF

v4 = fs_mountpoints;
debug_puts("fs_mount()\n");
v5 = driver_list;
do
{
if ( !strcmp(s1, v4) )
return 6;
v4 += 1568;
}
while ( v4 != &fs_mountpoints[25088] );
while ( 1 )
{
if ( !v5 )
return 4;
if ( !strcmp(a3, v5) )
break;
v5 = (char *)*((_QWORD *)v5 + 64);
}
v8 = v5[416] == 1;
v5[288] = 5;
if ( v8 && (!*src || *src == 45) )
return 3;
fs_get_node(s1, v13);
if ( !v13[0] )
return 2;
v6 = (*((__int64 (__fastcall **)(_QWORD, _QWORD))v5 + 37))(0LL, 0LL);
if ( v6 != 1 )
return 5;
v9 = (unsigned int)((_DWORD)fs_mountpoints + 1560);
v10 = 0LL;
while ( *(_BYTE *)v9 )
{
v10 = (unsigned int)(v10 + 1);
v9 += 1568LL;
if ( (_DWORD)v10 == 16 )
return 5;
}
v11 = 1568 * v10;
v12 = &fs_mountpoints[1568 * v10];
*(_QWORD *)&fs_mountpoints[v11 + 1544] = v13[0];
fs_mountpoints[v11 + 1560] = 1;
strcpy(v12, s1);
strcat(v12, ::src);
strcpy(&fs_mountpoints[v11 + 512], src);
strcat(&fs_mountpoints[v11 + 512], ::src);
strcpy(&fs_mountpoints[v11 + 1024], a3);
strcat(&fs_mountpoints[v11 + 1024], ::src);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, char *s1, char *a3)
{
const char *v4; // rbx
char *v5; // rbp
unsigned int v6; // er15
bool v8; // zf
unsigned __int64 v9; // rdx
__int64 v10; // rax
__int64 v11; // rbx
char *v12; // rbp
__int64 v13[8]; // [rsp+8h] [rbp-40h] BYREF

v4 = fs_mountpoints;
debug_puts("fs_mount()\n");
v5 = driver_list;
do
{
if ( !strcmp(s1, v4) )
return 6;
v4 += 1568;
}
while ( v4 != &fs_mountpoints[25088] );
while ( 1 )
{
if ( !v5 )
return 4;
if ( !strcmp(a3, v5) )
break;
v5 = (char *)*((_QWORD *)v5 + 64);
}
v8 = v5[416] == 1;
v5[288] = 5;
if ( v8 && (!*src || *src == 45) )
return 3;
fs_get_node(s1, v13);
if ( !v13[0] )
return 2;
v6 = (*((__int64 (__fastcall **)(_QWORD, _QWORD))v5 + 37))(0LL, 0LL);
if ( v6 != 1 )
return 5;
v9 = (unsigned int)((_DWORD)fs_mountpoints + 1560);
v10 = 0LL;
while ( *(_BYTE *)v9 )
{
v10 = (unsigned int)(v10 + 1);
v9 += 1568LL;
if ( (_DWORD)v10 == 16 )
return 5;
}
v11 = 1568 * v10;
v12 = &fs_mountpoints[1568 * v10];
*(_QWORD *)&fs_mountpoints[v11 + 1544] = v13[0];
fs_mountpoints[v11 + 1560] = 1;
strcpy(v12, s1);
strcat(v12, ::src);
strcpy(&fs_mountpoints[v11 + 512], src);
strcat(&fs_mountpoints[v11 + 512], ::src);
strcpy(&fs_mountpoints[v11 + 1024], a3);
strcat(&fs_mountpoints[v11 + 1024], ::src);
return v6;
}

original_code:
uint32_t fs_mount(char *device, char *path, char *fs, uint32_t flags)
{
 debug_puts("fs_mount()\n");
 driver_t *cf = driver_list;
 inode_t *node;
 unsigned i;
 for(i = 0; i < 16; i++)
 {
  if((strcmp(path, fs_mountpoints[i].path) == 0))
   return 6;
 }
 while(cf != 0)
 {
  if((strcmp(fs, cf->name) == 0) && (cf->type = 5))
   break;
  cf = cf->next;
 }
 if(cf != 0)
 {
  if((cf->fs).ifdev == 1 && (device[0] == '\0' || device[0] == '-'))
   return 3;
  fs_get_node(path, &node);
  if(node == 0)
   return 2;
  if((cf->fs).mount(0, 0, node) != 1)
   return 5;
  mount_point_t *mp = 0;
  for(i = 0; i < 16; i++)
  {
   if(fs_mountpoints[i].used == 0)
   {
    mp = &fs_mountpoints[i];
    break;
   }
  }
  if(mp == 0)
   return 5;
  mp->used = 1;
  mp->root = node;
  strcpy(mp->path, path);
  strcat(mp->path, "\0");
  strcpy(mp->dev, device);
  strcat(mp->dev, "\0");
  strcpy(mp->fs, fs);
  strcat(mp->fs, "\0");
  return 1;
 }
 return 4;
}

canonical_original_code:
unsigned int fs_mount(char *device, char *path, char *fs, unsigned int flags)
{
 debug_puts("fs_mount()\n");
 struct driver_p *cf = driver_list;
 struct inode_p *node;
 unsigned int i;
 for(i = 0; i < 16; i++)
 {
  if((strcmp(path, fs_mountpoints[i].path) == 0))
   return 6;
 }
 while(cf != 0)
 {
  if((strcmp(fs, cf->name) == 0) && (cf->type = 5))
   break;
  cf = cf->next;
 }
 if(cf != 0)
 {
  if((cf->fs).ifdev == 1 && (device[0] == '\0' || device[0] == '-'))
   return 3;
  fs_get_node(path, &node);
  if(node == 0)
   return 2;
  if((cf->fs).mount(0, 0, node) != 1)
   return 5;
  struct mount_point_p *mp = 0;
  for(i = 0; i < 16; i++)
  {
   if(fs_mountpoints[i].used == 0)
   {
    mp = &fs_mountpoints[i];
    break;
   }
  }
  if(mp == 0)
   return 5;
  mp->used = 1;
  mp->root = node;
  strcpy(mp->path, path);
  strcat(mp->path, "\0");
  strcpy(mp->dev, device);
  strcat(mp->dev, "\0");
  strcpy(mp->fs, fs);
  strcat(mp->fs, "\0");
  return 1;
 }
 return 4;
}

variable_types:
device
char *

variable_types:
fs
char *

variable_types:
flags
unsigned int

variable_types: struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *

variable_types: struct mount_point_p { char path[512]; char dev[512]; char fs[512]; void *fs_struct; struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *root; struct inode_p *childs; unsigned char used; } *


decompiled_code:
__int64 fs_umount()
{
debug_puts("fs_umount()\n");
return 2LL;
}

canonical_decompiled_code:
__int64 func5()
{
debug_puts("fs_umount()\n");
return 2LL;
}

original_code:
uint32_t fs_umount(char *path)
{
 debug_puts("fs_umount()\n");
 return 2;
}

canonical_original_code:
unsigned int fs_umount(char *path)
{
 debug_puts("fs_umount()\n");
 return 2;
}


decompiled_code:
void ppp_up()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
uint32_t ppp_up(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int ppp_up(struct network_iface_p *iface)
{
}

variable_types: struct network_iface_p { char name[32]; char addr[4]; char mask[4]; char bcast[4]; char mac[6]; unsigned char if_up; unsigned char if_mac; unsigned char if_bcast; unsigned char type; unsigned int tx_bytes; unsigned int rx_bytes; struct driver_p { char name[32]; char desc[128]; char author[128]; unsigned char type; struct driver_fs_t { unsigned int (*mount)(char *, unsigned int, struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *); unsigned int (*umount)(struct inode_p *); unsigned int (*mkdir)(struct inode_p *, char *); unsigned int (*readdir)(struct inode_p *, unsigned int, struct dirent { char name[255]; unsigned int inode; } *); unsigned int (*get_node)(struct inode_p *, unsigned int, struct inode_p **); unsigned int (*delete_node)(struct inode_p *, char *); unsigned int (*create_node)(struct inode_p *, char *, unsigned int); unsigned int (*write_stat)(struct inode_p *, struct stat { unsigned int st_dev; unsigned int st_ino; int st_uid; int st_gid; unsigned long long st_blksize; unsigned long long st_blocks; } *, unsigned int); unsigned int (*read_stat)(struct inode_p *, struct stat *); unsigned int (*open)(struct inode_p *, char *); unsigned int (*close)(struct inode_p *); unsigned int (*read)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct inode_p *, char *, unsigned int, unsigned long long); unsigned int (*link)(struct inode_p *, char *, struct inode_p *, char *); unsigned int (*unlink)(struct inode_p *, char *); unsigned char ifdev; } fs; struct driver_video_t { char *buffer; void (*put_pixel)(unsigned int, unsigned int, unsigned int); unsigned int (*get_pixel)(unsigned int, unsigned int); unsigned int (*set_mode)(unsigned int, unsigned int, unsigned int); } video; unsigned char loaded; unsigned int (*init)(); unsigned int (*free)(); unsigned int (*probe)(struct device_p { unsigned int io_base; char vendor[32]; char vendor_full[32]; char device[32]; char device_desc[32]; char class[32]; char class_desc[32]; char class_prog_desc[32]; unsigned char bus_type; void *pci_dev; unsigned char interrupt; unsigned int base_addresses[6]; char file[32]; struct device_p *next; } *); unsigned int (*read)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*write)(struct device_p *, char *, unsigned int, unsigned long long); unsigned int (*ioctl)(struct device_p *, unsigned int, unsigned int, unsigned int); struct driver_p *next; } *drv; struct device_p *dev; void *link_protocol; struct network_iface_p *next; } *


decompiled_code:
// attributes: thunk
void ppp_down()
{
ppp_up();
}

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

original_code:
uint32_t ppp_down(network_iface_t *iface)
{
}

canonical_original_code:
unsigned int ppp_down(struct network_iface_p *iface)
{
}


decompiled_code:
__int64 __fastcall ppp_handle_frame(__int64 a1, unsigned int *a2)
{
unsigned __int16 v2; // bx

v2 = *(_WORD *)(*((_QWORD *)a2 + 1) + 4LL);
packet_del_header(a2, 6LL);
if ( (unsigned int)video_getx() )
printf("\n");
printf("ppp: received packet (sizeof %d) of protocol %x\n", *a2, v2);
if ( v2 == 33 )
ip_handle_packet(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned __int16 v2; // bx

v2 = *(_WORD *)(*((_QWORD *)a2 + 1) + 4LL);
packet_del_header(a2, 6LL);
if ( (unsigned int)video_getx() )
printf("\n");
printf("ppp: received packet (sizeof %d) of protocol %x\n", *a2, v2);
if ( v2 == 33 )
ip_handle_packet(a1, a2);
return 0LL;
}

original_code:
uint32_t ppp_handle_frame(network_iface_t *iface, packet_t *p)
{
 uint16_t protocol;
 ppp_header_t *ppphead = (ppp_header_t *) p->data;
 protocol = ppphead->protocol;
 packet_del_header(p, sizeof(ppp_header_t));
 if(video_getx() != 0)
  printf("\n");
 printf("ppp: received packet (sizeof %d) of protocol %x\n", p->size, protocol);
 switch(protocol)
 {
  case 0x0021:
   ip_handle_packet(iface, p);
   break;
 }
 return 0;
}

canonical_original_code:
unsigned int ppp_handle_frame(struct network_iface_p *iface, struct packet_t *p)
{
 unsigned short protocol;
 struct ppp_header_t *ppphead = (ppp_header_t *) p->data;
 protocol = ppphead->protocol;
 packet_del_header(p, sizeof(ppp_header_t));
 if(video_getx() != 0)
  printf("\n");
 printf("ppp: received packet (sizeof %d) of protocol %x\n", p->size, protocol);
 switch(protocol)
 {
  case 0x0021:
   ip_handle_packet(iface, p);
   break;
 }
 return 0;
}

variable_types: struct packet_t { unsigned int size; char *data; } *

variable_types:
protocol
unsigned short

variable_types: struct ppp_header_t { unsigned char flag; unsigned char address; unsigned char control; unsigned short protocol; } *


decompiled_code:
__int64 __fastcall ppp_send_frame(__int64 a1, unsigned int *a2)
{
__int64 v3; // rsi
__int64 v4; // rax
__int64 (__fastcall *v5)(_QWORD, __int64, _QWORD, _QWORD); // rax
__int64 result; // rax

packet_add_header(a2, 6LL);
v3 = *((_QWORD *)a2 + 1);
*(_WORD *)v3 = -130;
*(_BYTE *)(v3 + 2) = 3;
v4 = *(_QWORD *)(a1 + 64);
*(_WORD *)(v3 + 4) = 33;
v5 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, _QWORD))(v4 + 496);
if ( !v5 )
return 0LL;
result = v5(*(_QWORD *)(a1 + 72), v3, *a2, 0LL);
*(_DWORD *)(a1 + 56) += result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int *a2)
{
__int64 v3; // rsi
__int64 v4; // rax
__int64 (__fastcall *v5)(_QWORD, __int64, _QWORD, _QWORD); // rax
__int64 result; // rax

packet_add_header(a2, 6LL);
v3 = *((_QWORD *)a2 + 1);
*(_WORD *)v3 = -130;
*(_BYTE *)(v3 + 2) = 3;
v4 = *(_QWORD *)(a1 + 64);
*(_WORD *)(v3 + 4) = 33;
v5 = *(__int64 (__fastcall **)(_QWORD, __int64, _QWORD, _QWORD))(v4 + 496);
if ( !v5 )
return 0LL;
result = v5(*(_QWORD *)(a1 + 72), v3, *a2, 0LL);
*(_DWORD *)(a1 + 56) += result;
return result;
}

original_code:
uint32_t ppp_send_frame(network_iface_t *iface, packet_t *p)
{
 packet_add_header(p, sizeof(ppp_header_t));
 ppp_header_t *ppphead = (ppp_header_t *) p->data;
 ppphead->flag = 0x7E;
 ppphead->address = 0xFF;
 ppphead->control = 0x03;
 ppphead->protocol = 0x0021;
 uint32_t sended_b;
 if((iface->drv)->write != 0)
  sended_b = (iface->drv)->write(iface->dev, p->data, p->size, 0);
 else
  return 0;
 iface->tx_bytes = iface->tx_bytes + sended_b;
 return sended_b;
}

canonical_original_code:
unsigned int ppp_send_frame(struct network_iface_p *iface, struct packet_t *p)
{
 packet_add_header(p, sizeof(ppp_header_t));
 struct ppp_header_t *ppphead = (ppp_header_t *) p->data;
 ppphead->flag = 0x7E;
 ppphead->address = 0xFF;
 ppphead->control = 0x03;
 ppphead->protocol = 0x0021;
 unsigned int sended_b;
 if((iface->drv)->write != 0)
  sended_b = (iface->drv)->write(iface->dev, p->data, p->size, 0);
 else
  return 0;
 iface->tx_bytes = iface->tx_bytes + sended_b;
 return sended_b;
}

user_defined_types: struct packet_t { unsigned int size; char *data; }

user_defined_types: struct ppp_header_t { unsigned char flag; unsigned char address; unsigned char control; unsigned short protocol; }


decompiled_code:
__int64 __fastcall load_raw_bitmap(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v6; // rbp
__int64 result; // rax

v6 = fs_open(a1, &unk_1DCF98);
result = 0LL;
if ( v6 )
{
fs_read(v6, a2, (unsigned int)(4 * a4 * a3));
fs_close(v6);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v6; // rbp
__int64 result; // rax

v6 = fs_open(a1, &unk_1DCF98);
result = 0LL;
if ( v6 )
{
fs_read(v6, a2, (unsigned int)(4 * a4 * a3));
fs_close(v6);
result = 1LL;
}
return result;
}

original_code:
uint32_t load_raw_bitmap(char *path, char *data, uint32_t x, uint32_t y)
{
 file_t *f = fs_open(path, "r");
 char *pixel_data = data;
 if(f != 0)
  fs_read(f, pixel_data, x * y * 4);
 else
  return 0;
 fs_close(f);
 return 1;
}

canonical_original_code:
unsigned int load_raw_bitmap(char *path, char *data, unsigned int x, unsigned int y)
{
 struct file_p *f = fs_open(path, "r");
 char *pixel_data = data;
 if(f != 0)
  fs_read(f, pixel_data, x * y * 4);
 else
  return 0;
 fs_close(f);
 return 1;
}

variable_types:
data
char *

variable_types:
y
unsigned int

variable_types: struct file_p { unsigned int id; unsigned long long seek_p; unsigned long long size; struct inode_p { char name[255]; unsigned int inode_n; unsigned char type; unsigned char ow; void *fs_node; void *fs_driver; struct inode_p *link; struct inode_p *next; struct inode_p *prev; struct inode_p *parent; struct inode_p *childs; } *node; void *drv; struct file_p *next; } *

user_defined_types: struct file_p { unsigned int id; unsigned long long seek_p; unsigned long long size; struct inode_p *node; void *drv; struct file_p *next; }


decompiled_code:
__int64 __fastcall render_get_pixel(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int v3; // ebx
__int64 v4; // rcx

result = *(unsigned __int16 *)(vesa_get_mode_info() + 18);
if ( (unsigned int)result >= a1 )
{
result = *(unsigned __int16 *)(vesa_get_mode_info() + 20);
if ( (unsigned int)result >= a2 )
{
v3 = (*(_BYTE *)(vesa_get_mode_info() + 25) >> 3) * a1;
v4 = a2 * *(unsigned __int16 *)(vesa_get_mode_info() + 16) + v3;
result = (unsigned int)((render_buffer[v4 + 1] << 8) + render_buffer[v4] + (render_buffer[v4 + 2] << 16));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 result; // rax
int v3; // ebx
__int64 v4; // rcx

result = *(unsigned __int16 *)(vesa_get_mode_info() + 18);
if ( (unsigned int)result >= a1 )
{
result = *(unsigned __int16 *)(vesa_get_mode_info() + 20);
if ( (unsigned int)result >= a2 )
{
v3 = (*(_BYTE *)(vesa_get_mode_info() + 25) >> 3) * a1;
v4 = a2 * *(unsigned __int16 *)(vesa_get_mode_info() + 16) + v3;
result = (unsigned int)((render_buffer[v4 + 1] << 8) + render_buffer[v4] + (render_buffer[v4 + 2] << 16));
}
}
return result;
}

original_code:
uint32_t render_get_pixel(uint32_t x, uint32_t y)
{
 if (x<0 || x > vesa_get_mode_info()->width || y<0 || y>vesa_get_mode_info()->height) return;
 x = (x*(vesa_get_mode_info()->bits_per_pixel>>3));
 y = (y*vesa_get_mode_info()->bytes_per_scan_line);
 register char * cTemp;
 cTemp = &render_buffer[x+y];
 return (cTemp[0] + (cTemp[1]<<8) + (cTemp[2]<<16));
}

canonical_original_code:
unsigned int render_get_pixel(unsigned int x, unsigned int y)
{
 if (x<0 || x > vesa_get_mode_info()->width || y<0 || y>vesa_get_mode_info()->height) return;
 x = (x*(vesa_get_mode_info()->bits_per_pixel>>3));
 y = (y*vesa_get_mode_info()->bytes_per_scan_line);
 register char *cTemp;
 cTemp = &render_buffer[x+y];
 return (cTemp[0] + (cTemp[1]<<8) + (cTemp[2]<<16));
}

variable_types:
cTemp
char *


decompiled_code:
__int64 __fastcall render_draw_pixel(unsigned int a1, unsigned int a2, int a3)
{
__int64 result; // rax
int v5; // ebx

result = *(unsigned __int16 *)(vesa_get_mode_info() + 18);
if ( (unsigned int)result >= a1 )
{
result = *(unsigned __int16 *)(vesa_get_mode_info() + 20);
if ( (unsigned int)result >= a2 )
{
v5 = (*(_BYTE *)(vesa_get_mode_info() + 25) >> 3) * a1;
result = a2 * *(unsigned __int16 *)(vesa_get_mode_info() + 16) + v5;
*(_WORD *)&render_buffer[result] = a3;
render_buffer[result + 2] = BYTE2(a3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2, int a3)
{
__int64 result; // rax
int v5; // ebx

result = *(unsigned __int16 *)(vesa_get_mode_info() + 18);
if ( (unsigned int)result >= a1 )
{
result = *(unsigned __int16 *)(vesa_get_mode_info() + 20);
if ( (unsigned int)result >= a2 )
{
v5 = (*(_BYTE *)(vesa_get_mode_info() + 25) >> 3) * a1;
result = a2 * *(unsigned __int16 *)(vesa_get_mode_info() + 16) + v5;
*(_WORD *)&render_buffer[result] = a3;
render_buffer[result + 2] = BYTE2(a3);
}
}
return result;
}

original_code:
void render_draw_pixel(uint32_t x, uint32_t y, uint32_t cl)
{
 if (x<0 || x > vesa_get_mode_info()->width || y<0 || y>vesa_get_mode_info()->height) return;
 x = (x*(vesa_get_mode_info()->bits_per_pixel>>3));
 y = (y*vesa_get_mode_info()->bytes_per_scan_line);
 register char * cTemp;
 cTemp = &render_buffer[x+y];
 cTemp[0] = cl & 0xff;
 cTemp[1] = (cl>>8) & 0xff;
 cTemp[2] = (cl>>16) & 0xff;
}

canonical_original_code:
void render_draw_pixel(unsigned int x, unsigned int y, unsigned int cl)
{
 if (x<0 || x > vesa_get_mode_info()->width || y<0 || y>vesa_get_mode_info()->height) return;
 x = (x*(vesa_get_mode_info()->bits_per_pixel>>3));
 y = (y*vesa_get_mode_info()->bytes_per_scan_line);
 register char *cTemp;
 cTemp = &render_buffer[x+y];
 cTemp[0] = cl & 0xff;
 cTemp[1] = (cl>>8) & 0xff;
 cTemp[2] = (cl>>16) & 0xff;
}

variable_types:
cl
unsigned int


decompiled_code:
__int64 __fastcall render_write_letter(unsigned __int8 a1, char a2, int a3, int a4, int a5)
{
char *v5; // r15
__int64 result; // rax
unsigned int v9; // er14
int i; // ebx
unsigned int v11; // edi
int v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+Ch] [rbp-3Ch]

v12 = a1;
if ( a1 == 16 )
{
v5 = (char *)&default_font_8x16 + 16 * a2;
}
else if ( a1 == 8 )
{
v5 = (char *)&default_font_8x8 + 8 * a2;
}
else
{
result = a1;
if ( !a1 )
return result;
}
v9 = a5 - 4;
v13 = 4 - a5;
do
{
for ( i = 0; i != 8; ++i )
{
while ( ((1 << i) & *v5) == 0 )
{
if ( ++i == 8 )
goto LABEL_9;
}
v11 = i + a4;
render_draw_pixel(v11, v9, a3);
}
LABEL_9:
++v9;
++v5;
result = v9 + v13;
}
while ( (int)result < v12 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, char a2, int a3, int a4, int a5)
{
char *v5; // r15
__int64 result; // rax
unsigned int v9; // er14
int i; // ebx
unsigned int v11; // edi
int v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+Ch] [rbp-3Ch]

v12 = a1;
if ( a1 == 16 )
{
v5 = (char *)&default_font_8x16 + 16 * a2;
}
else if ( a1 == 8 )
{
v5 = (char *)&default_font_8x8 + 8 * a2;
}
else
{
result = a1;
if ( !a1 )
return result;
}
v9 = a5 - 4;
v13 = 4 - a5;
do
{
for ( i = 0; i != 8; ++i )
{
while ( ((1 << i) & *v5) == 0 )
{
if ( ++i == 8 )
goto LABEL_9;
}
v11 = i + a4;
func2(v11, v9, a3);
}
LABEL_9:
++v9;
++v5;
result = v9 + v13;
}
while ( (int)result < v12 );
return result;
}

original_code:
void render_write_letter(uint8_t size, char letter, uint32_t col, uint32_t x, uint32_t y)
{
 char *let_data;
 if(size == 16) let_data = default_font_8x16[letter];
 else if (size == 8) let_data = default_font_8x8[letter];
 int i;
 int j;
 for(i = 0; i < size; i++)
 {
  for(j = 0; j < 8; j++)
  {
   if((let_data[i] & (1 << j)) > 0)
    render_draw_pixel(x+j, y+i-4, (uint32_t) col);
  }
 }
}

canonical_original_code:
void render_write_letter(unsigned char size, char letter, unsigned int col, unsigned int x, unsigned int y)
{
 char *let_data;
 if(size == 16) let_data = default_font_8x16[letter];
 else if (size == 8) let_data = default_font_8x8[letter];
 int i;
 int j;
 for(i = 0; i < size; i++)
 {
  for(j = 0; j < 8; j++)
  {
   if((let_data[i] & (1 << j)) > 0)
    render_draw_pixel(x+j, y+i-4, (unsigned int) col);
  }
 }
}

variable_types:
size
unsigned char

variable_types: letter char

variable_types:
col
unsigned int

variable_types:
x
unsigned int

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall render_write_text(unsigned __int8 a1, char *a2, int a3, int a4, int a5)
{
char *v5; // rbx
char i; // si
__int64 result; // rax

v5 = a2;
for ( i = *a2; i; a4 += 8 )
{
result = render_write_letter(a1, i, a3, a4, a5);
i = *++v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, char *a2, int a3, int a4, int a5)
{
char *v5; // rbx
char i; // si
__int64 result; // rax

v5 = a2;
for ( i = *a2; i; a4 += 8 )
{
result = func3(a1, i, a3, a4, a5);
i = *++v5;
}
return result;
}

original_code:
void render_write_text(uint8_t size, char *text, uint32_t col, uint32_t x, uint32_t y)
{
 char *str = text;
 uint32_t cx = x;
 while(*str != '\0')
 {
  render_write_letter(size, *str, col, cx, y);
  cx = cx + 8;
  str++;
 }
}

canonical_original_code:
void render_write_text(unsigned char size, char *text, unsigned int col, unsigned int x, unsigned int y)
{
 char *str = text;
 unsigned int cx = x;
 while(*str != '\0')
 {
  render_write_letter(size, *str, col, cx, y);
  cx = cx + 8;
  str++;
 }
}

variable_types:
text
char *

variable_types:
str
char *

variable_types:
cx
unsigned int


decompiled_code:
__int64 __fastcall render_draw_line(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
unsigned int v7; // ebx
unsigned int v8; // er12
__int64 result; // rax

if ( a1 < a3 || a2 < a4 )
{
v7 = a2;
v8 = a1;
do
{
vesa_get_pixel(a1, a2);
result = render_draw_pixel(v8, v7, a5);
if ( a3 <= v8 )
{
if ( a4 <= v7 )
return result;
}
else
{
++v8;
if ( a4 <= v7 )
continue;
}
++v7;
}
while ( a3 > v8 || v7 < a4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
unsigned int v7; // ebx
unsigned int v8; // er12
__int64 result; // rax

if ( a1 < a3 || a2 < a4 )
{
v7 = a2;
v8 = a1;
do
{
vesa_get_pixel(a1, a2);
result = func2(v8, v7, a5);
if ( a3 <= v8 )
{
if ( a4 <= v7 )
return result;
}
else
{
++v8;
if ( a4 <= v7 )
continue;
}
++v7;
}
while ( a3 > v8 || v7 < a4 );
}
return result;
}

original_code:
void render_draw_line(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t col)
{
 uint32_t x = x0;
 uint32_t y = y0;
 while(x < x1 || y < y1)
 {
  uint32_t c = (vesa_get_pixel(x0, y0) + col) / 2;
  render_draw_pixel(x, y, col);
  if(x < x1) x++;
  if(y < y1) y++;
 }
}

canonical_original_code:
void render_draw_line(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int col)
{
 unsigned int x = x0;
 unsigned int y = y0;
 while(x < x1 || y < y1)
 {
  unsigned int c = (vesa_get_pixel(x0, y0) + col) / 2;
  render_draw_pixel(x, y, col);
  if(x < x1) x++;
  if(y < y1) y++;
 }
}

variable_types:
c
unsigned int


decompiled_code:
__int64 __fastcall render_draw_rect(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
render_draw_line(a1, a2, a1, a4, a5);
render_draw_line(a1, a2, a3, a2, a5);
render_draw_line(a3, a2, a3, a4, a5);
return render_draw_line(a1, a4, a3, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
func5(a1, a2, a1, a4, a5);
func5(a1, a2, a3, a2, a5);
func5(a3, a2, a3, a4, a5);
return func5(a1, a4, a3, a4, a5);
}

original_code:
void render_draw_rect(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t col)
{
 render_draw_line(x0, y0, x0, y1, col);
 render_draw_line(x0, y0, x1, y0, col);
 render_draw_line(x1, y0, x1, y1, col);
 render_draw_line(x0, y1, x1, y1, col);
}

canonical_original_code:
void render_draw_rect(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int col)
{
 render_draw_line(x0, y0, x0, y1, col);
 render_draw_line(x0, y0, x1, y0, col);
 render_draw_line(x1, y0, x1, y1, col);
 render_draw_line(x0, y1, x1, y1, col);
}


decompiled_code:
__int64 __fastcall render_draw_rect_fill(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
unsigned int v8; // ebx
unsigned int v9; // ecx
unsigned int v10; // esi
__int64 result; // rax

if ( a2 <= a4 )
{
v8 = a2;
do
{
v9 = v8;
v10 = v8++;
result = render_draw_line(a1, v10, a3, v9, a5);
}
while ( a4 >= v8 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5)
{
unsigned int v8; // ebx
unsigned int v9; // ecx
unsigned int v10; // esi
__int64 result; // rax

if ( a2 <= a4 )
{
v8 = a2;
do
{
v9 = v8;
v10 = v8++;
result = func5(a1, v10, a3, v9, a5);
}
while ( a4 >= v8 );
}
return result;
}

original_code:
void render_draw_rect_fill(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t fill)
{
 while(y0 <= y1)
 {
  render_draw_line(x0, y0, x1, y0, fill);
  y0++;
 }
}

canonical_original_code:
void render_draw_rect_fill(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int fill)
{
 while(y0 <= y1)
 {
  render_draw_line(x0, y0, x1, y0, fill);
  y0++;
 }
}

variable_types:
fill
unsigned int


decompiled_code:
__int64 __fastcall render_draw_rect_bordered(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, __int64 a5, int a6, int a7)
{
render_draw_rect_fill(a1, a2, a3, a4, a7);
return render_draw_rect(a1, a2, a3, a4, a6);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, __int64 a5, int a6, int a7)
{
func7(a1, a2, a3, a4, a7);
return func6(a1, a2, a3, a4, a6);
}

original_code:
void render_draw_rect_bordered(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
        uint8_t border_pix, uint32_t border, uint32_t fill)
{
 render_draw_rect_fill(x0, y0, x1, y1, fill);
 render_draw_rect(x0, y0, x1, y1, border);
}

canonical_original_code:
void render_draw_rect_bordered(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned char border_pix, unsigned int border, unsigned int fill)
{
 render_draw_rect_fill(x0, y0, x1, y1, fill);
 render_draw_rect(x0, y0, x1, y1, border);
}

variable_types:
border
unsigned int


decompiled_code:
__int64 __fastcall render_draw_rect_fill_gradient(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5, int a6)
{
__int64 result; // rax
unsigned int v9; // ebx
int v10; // ebp
unsigned int v11; // er12
int v12; // er8
unsigned int v13; // ecx
unsigned int v14; // esi

result = (a6 - a5) / (a4 - a2);
if ( a4 >= a2 )
{
v9 = a2;
v10 = a5;
v11 = (a6 - a5) / (a4 - a2);
do
{
v12 = v10;
v13 = v9;
v14 = v9++;
v10 += v11;
result = render_draw_line(a1, v14, a3, v13, v12);
}
while ( a4 >= v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, int a5, int a6)
{
__int64 result; // rax
unsigned int v9; // ebx
int v10; // ebp
unsigned int v11; // er12
int v12; // er8
unsigned int v13; // ecx
unsigned int v14; // esi

result = (a6 - a5) / (a4 - a2);
if ( a4 >= a2 )
{
v9 = a2;
v10 = a5;
v11 = (a6 - a5) / (a4 - a2);
do
{
v12 = v10;
v13 = v9;
v14 = v9++;
v10 += v11;
result = func5(a1, v14, a3, v13, v12);
}
while ( a4 >= v9 );
}
return result;
}

original_code:
void render_draw_rect_fill_gradient(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint32_t c1, uint32_t c2)
{
 uint32_t gr = (c2 - c1) / (y1 - y0);
 uint32_t cur = c1;
 while(y0 <= y1)
 {
  render_draw_line(x0, y0, x1, y0, (uint32_t) cur);
  cur = cur + gr;
  y0++;
 }
}

canonical_original_code:
void render_draw_rect_fill_gradient(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int c1, unsigned int c2)
{
 unsigned int gr = (c2 - c1) / (y1 - y0);
 unsigned int cur = c1;
 while(y0 <= y1)
 {
  render_draw_line(x0, y0, x1, y0, (unsigned int) cur);
  cur = cur + gr;
  y0++;
 }
}

variable_types:
gr
unsigned int

variable_types:
cur
unsigned int


decompiled_code:
__int64 __fastcall render_draw_rect_bordered_gradient(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, __int64 a5, int a6, int a7, int a8)
{
render_draw_rect_fill_gradient(a1, a2, a3, a4, a7, a8);
return render_draw_rect(a1, a2, a3, a4, a6);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4, __int64 a5, int a6, int a7, int a8)
{
func9(a1, a2, a3, a4, a7, a8);
return func6(a1, a2, a3, a4, a6);
}

original_code:
void render_draw_rect_bordered_gradient(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
        uint8_t border_pix, uint32_t border, uint32_t col1, uint32_t col2)
{
 render_draw_rect_fill_gradient(x0, y0, x1, y1, col1, col2);
 render_draw_rect(x0, y0, x1, y1, border);
}

canonical_original_code:
void render_draw_rect_bordered_gradient(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned char border_pix, unsigned int border, unsigned int col1, unsigned int col2)
{
 render_draw_rect_fill_gradient(x0, y0, x1, y1, col1, col2);
 render_draw_rect(x0, y0, x1, y1, border);
}


decompiled_code:
__int64 __fastcall render_gimp_image(unsigned int *a1, int a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v5; // er13
unsigned int v7; // er8
unsigned int v8; // ebp
unsigned int v9; // edx
unsigned int v10; // edi

result = a1[1];
if ( (_DWORD)result )
{
v5 = 0;
v7 = *a1;
do
{
v8 = 0;
if ( v7 )
{
do
{
while ( 1 )
{
result = 4 * (v8 + v5 * v7);
v9 = (*(unsigned __int8 *)(*((_QWORD *)a1 + 2) + (unsigned int)(result + 3)) << 24)
+ (*(unsigned __int8 *)(*((_QWORD *)a1 + 2) + (unsigned int)(result + 1)) << 8)
+ *(unsigned __int8 *)(*((_QWORD *)a1 + 2) + (unsigned int)(result + 2))
+ (*(unsigned __int8 *)(*((_QWORD *)a1 + 2) + result) << 16);
if ( v9 > 0x22222222 )
break;
if ( v7 <= ++v8 )
goto LABEL_8;
}
v10 = a2 + v8++;
result = render_draw_pixel(v10, a3, v9);
v7 = *a1;
}
while ( *a1 > v8 );
}
LABEL_8:
++v5;
++a3;
}
while ( a1[1] > v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int *a1, int a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v5; // er13
unsigned int v7; // er8
unsigned int v8; // ebp
unsigned int v9; // edx
unsigned int v10; // edi

result = a1[1];
if ( (_DWORD)result )
{
v5 = 0;
v7 = *a1;
do
{
v8 = 0;
if ( v7 )
{
do
{
while ( 1 )
{
result = 4 * (v8 + v5 * v7);
v9 = (*(unsigned __int8 *)(*((_QWORD *)a1 + 2) + (unsigned int)(result + 3)) << 24)
+ (*(unsigned __int8 *)(*((_QWORD *)a1 + 2) + (unsigned int)(result + 1)) << 8)
+ *(unsigned __int8 *)(*((_QWORD *)a1 + 2) + (unsigned int)(result + 2))
+ (*(unsigned __int8 *)(*((_QWORD *)a1 + 2) + result) << 16);
if ( v9 > 0x22222222 )
break;
if ( v7 <= ++v8 )
goto LABEL_8;
}
v10 = a2 + v8++;
result = func2(v10, a3, v9);
v7 = *a1;
}
while ( *a1 > v8 );
}
LABEL_8:
++v5;
++a3;
}
while ( a1[1] > v5 );
}
return result;
}

original_code:
void render_gimp_image(gimp_image *gi, uint32_t x, uint32_t y)
{
 uint32_t i,j;
 for(i = 0; i < gi->height; i++)
  for(j = 0; j < gi->width; j++)
  {
   uint32_t col =
    (gi->pixel_data[((i*4*gi->width)+j*4)+3] << 24) +
    (gi->pixel_data[((i*4*gi->width)+j*4)+1] << 8) +
    (gi->pixel_data[((i*4*gi->width)+j*4)+2] << 0) +
    (gi->pixel_data[(i*4*gi->width)+j*4] << 16);
   if(col > 0x22222222)
    render_draw_pixel(x + j, y + i, col);
  }
}

canonical_original_code:
void render_gimp_image(struct gimp_image *gi, unsigned int x, unsigned int y)
{
 unsigned int i; unsigned int j;
 for(i = 0; i < gi->height; i++)
  for(j = 0; j < gi->width; j++)
  {
   unsigned int col = (gi->pixel_data[((i*4*gi->width)+j*4)+3] << 24) +
    (gi->pixel_data[((i*4*gi->width)+j*4)+1] << 8) +
    (gi->pixel_data[((i*4*gi->width)+j*4)+2] << 0) +
    (gi->pixel_data[(i*4*gi->width)+j*4] << 16);
   if(col > 0x22222222)
    render_draw_pixel(x + j, y + i, col);
  }
}

variable_types: struct gimp_image { unsigned int width; unsigned int height; unsigned int bytes_per_pixel; unsigned char *pixel_data; } *

variable_types:
y
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int


decompiled_code:
__int64 __fastcall render_bit_map(__int64 a1, int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
unsigned int v6[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+10h] [rbp-18h]

v7 = a1;
v6[0] = a4;
v6[1] = a5;
v6[2] = 4;
return render_gimp_image(v6, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
unsigned int v6[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v7; // [rsp+10h] [rbp-18h]

v7 = a1;
v6[0] = a4;
v6[1] = a5;
v6[2] = 4;
return func11(v6, a2, a3);
}

original_code:
void render_bit_map(uint32_t *data, uint32_t x, uint32_t y, uint32_t sx, uint32_t sy)
{
 gimp_image g;
 g.width = sx;
 g.height = sy;
 g.pixel_data = (char *) data;
 g.bytes_per_pixel = 4;
 render_gimp_image(&g, x, y);
}

canonical_original_code:
void render_bit_map(unsigned int *data, unsigned int x, unsigned int y, unsigned int sx, unsigned int sy)
{
 struct gimp_image g;
 g.width = sx;
 g.height = sy;
 g.pixel_data = (char *) data;
 g.bytes_per_pixel = 4;
 render_gimp_image(&g, x, y);
}

variable_types:
data
unsigned int *

variable_types:
sx
unsigned int

variable_types:
sy
unsigned int

variable_types: struct gimp_image { unsigned int width; unsigned int height; unsigned int bytes_per_pixel; unsigned char *pixel_data; }


decompiled_code:
__int64 __fastcall render_draw_cursor(int a1, unsigned int a2)
{
return render_bit_map((__int64)&cursor, a1, a2, 0xDu, 0xFu);
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, unsigned int a2)
{
return func12((__int64)&cursor, a1, a2, 0xDu, 0xFu);
}

original_code:
void render_draw_cursor(uint32_t x, uint32_t y)
{
  render_bit_map((uint32_t *) cursor, x, y, 13, 15);
 if(1==0)
 {
  render_draw_line(x - 5, y - 1, x + 5, y - 1, 0x0);
  render_draw_line(x - 5, y, x + 5, y, 0xFFFFFF);
  render_draw_line(x - 5, y + 1, x + 5, y + 1, 0x0);
  render_draw_line(x - 1, y - 5, x - 1, y + 5, 0x0);
  render_draw_line(x + 1, y - 5, x + 1, y + 5, 0x0);
  render_draw_line(x - 5, y, x + 5, y, 0xFFFFFF);
  render_draw_line(x, y - 5, x, y + 5, 0xFFFFFF);
 }
}

canonical_original_code:
void render_draw_cursor(unsigned int x, unsigned int y)
{
  render_bit_map((unsigned int *) cursor, x, y, 13, 15);
 if(1==0)
 {
  render_draw_line(x - 5, y - 1, x + 5, y - 1, 0x0);
  render_draw_line(x - 5, y, x + 5, y, 0xFFFFFF);
  render_draw_line(x - 5, y + 1, x + 5, y + 1, 0x0);
  render_draw_line(x - 1, y - 5, x - 1, y + 5, 0x0);
  render_draw_line(x + 1, y - 5, x + 1, y + 5, 0x0);
  render_draw_line(x - 5, y, x + 5, y, 0xFFFFFF);
  render_draw_line(x, y - 5, x, y + 5, 0xFFFFFF);
 }
}

variable_types:
x
unsigned int


decompiled_code:
void *__fastcall render_swap_buffer(void *a1, const void *a2, size_t a3)
{
void *result; // rax

result = memcpy(a1, a2, a3);
render_y1 = 0;
render_y0 = 0;
render_x1 = 0;
render_x0 = 0;
return result;
}

canonical_decompiled_code:
void *__fastcall func14(void *a1, const void *a2, size_t a3)
{
void *result; // rax

result = memcpy(a1, a2, a3);
render_y1 = 0;
render_y0 = 0;
render_x1 = 0;
render_x0 = 0;
return result;
}

original_code:
void render_swap_buffer(char *phys, char *ram, uint32_t size)
{
 memcpy(phys, ram, size);
 render_x0 = render_x1 = render_y0 = render_y1 = 0;
}

canonical_original_code:
void render_swap_buffer(char *phys, char *ram, unsigned int size)
{
 memcpy(phys, ram, size);
 render_x0 = render_x1 = render_y0 = render_y1 = 0;
}

variable_types:
phys
char *

variable_types:
ram
char *

variable_types:
size
unsigned int


decompiled_code:
void __fastcall idt_set_gate(unsigned __int8 a1, int a2, __int16 a3, char a4)
{
idt[4 * a1] = a2;
idt[4 * a1 + 3] = HIWORD(a2);
idt[4 * a1 + 1] = a3;
LOBYTE(idt[4 * a1 + 2]) = 0;
HIBYTE(idt[4 * a1 + 2]) = a4;
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int8 a1, int a2, __int16 a3, char a4)
{
idt[4 * a1] = a2;
idt[4 * a1 + 3] = HIWORD(a2);
idt[4 * a1 + 1] = a3;
LOBYTE(idt[4 * a1 + 2]) = 0;
HIBYTE(idt[4 * a1 + 2]) = a4;
}

original_code:
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
{
    idt[num].base_lo = (base & 0xFFFF);
    idt[num].base_hi = (base >> 16) & 0xFFFF;
    idt[num].sel = sel;
    idt[num].always0 = 0;
    idt[num].flags = flags;
}

variable_types:
num
unsigned char

variable_types:
base
unsigned long

variable_types:
sel
unsigned short

variable_types:
flags
unsigned char


decompiled_code:
__int64 idt_install()
{
idtp = 2047;
*(_DWORD *)(&idtp + 1) = (unsigned int)idt;
memset(idt, 0, 0x800uLL);
return idt_load();
}

canonical_decompiled_code:
__int64 func1()
{
idtp = 2047;
*(_DWORD *)(&idtp + 1) = (unsigned int)idt;
memset(idt, 0, 0x800uLL);
return idt_load();
}

original_code:
void idt_install()
{
    idtp.limit = (sizeof (struct idt_entry) * 256) - 1;
    idtp.base = (unsigned int) &idt;
    memset(&idt, 0, sizeof(struct idt_entry) * 256);
    idt_load();
}

user_defined_types: struct idt_entry { unsigned short base_lo; unsigned short sel; unsigned char always0; unsigned char flags; unsigned short base_hi; }


decompiled_code:
void isrs_install()
{
int v0; // eax
__int16 v1; // dx
char v2; // cl
int v3; // eax
__int16 v4; // dx
char v5; // cl
int v6; // eax
__int16 v7; // dx
char v8; // cl
int v9; // eax
__int16 v10; // dx
char v11; // cl
int v12; // eax
__int16 v13; // dx
char v14; // cl
int v15; // eax
__int16 v16; // dx
char v17; // cl
int v18; // eax
__int16 v19; // dx
char v20; // cl
int v21; // eax
__int16 v22; // dx
char v23; // cl
int v24; // eax
__int16 v25; // dx
char v26; // cl
int v27; // eax
__int16 v28; // dx
char v29; // cl
int v30; // eax
__int16 v31; // dx
char v32; // cl
int v33; // eax
__int16 v34; // dx
char v35; // cl
int v36; // eax
__int16 v37; // dx
char v38; // cl
int v39; // eax
__int16 v40; // dx
char v41; // cl
int v42; // eax
__int16 v43; // dx
char v44; // cl
int v45; // eax
__int16 v46; // dx
char v47; // cl
int v48; // eax
__int16 v49; // dx
char v50; // cl
int v51; // eax
__int16 v52; // dx
char v53; // cl
int v54; // eax
__int16 v55; // dx
char v56; // cl
int v57; // eax
__int16 v58; // dx
char v59; // cl
int v60; // eax
__int16 v61; // dx
char v62; // cl
int v63; // eax
__int16 v64; // dx
char v65; // cl
int v66; // eax
__int16 v67; // dx
char v68; // cl
int v69; // eax
__int16 v70; // dx
char v71; // cl
int v72; // eax
__int16 v73; // dx
char v74; // cl
int v75; // eax
__int16 v76; // dx
char v77; // cl
int v78; // eax
__int16 v79; // dx
char v80; // cl
int v81; // eax
__int16 v82; // dx
char v83; // cl
int v84; // eax
__int16 v85; // dx
char v86; // cl
int v87; // eax
__int16 v88; // dx
char v89; // cl
int v90; // eax
__int16 v91; // dx
char v92; // cl

idt_set_gate(0, (int)&isr0, 8, 142);
idt_set_gate(1u, v0, v1, v2);
idt_set_gate(2u, v3, v4, v5);
idt_set_gate(3u, v6, v7, v8);
idt_set_gate(4u, v9, v10, v11);
idt_set_gate(5u, v12, v13, v14);
idt_set_gate(6u, v15, v16, v17);
idt_set_gate(7u, v18, v19, v20);
idt_set_gate(8u, v21, v22, v23);
idt_set_gate(9u, v24, v25, v26);
idt_set_gate(0xAu, v27, v28, v29);
idt_set_gate(0xBu, v30, v31, v32);
idt_set_gate(0xCu, v33, v34, v35);
idt_set_gate(0xDu, v36, v37, v38);
idt_set_gate(0xEu, v39, v40, v41);
idt_set_gate(0xFu, v42, v43, v44);
idt_set_gate(0x10u, v45, v46, v47);
idt_set_gate(0x11u, v48, v49, v50);
idt_set_gate(0x12u, v51, v52, v53);
idt_set_gate(0x13u, v54, v55, v56);
idt_set_gate(0x14u, v57, v58, v59);
idt_set_gate(0x15u, v60, v61, v62);
idt_set_gate(0x16u, v63, v64, v65);
idt_set_gate(0x17u, v66, v67, v68);
idt_set_gate(0x18u, v69, v70, v71);
idt_set_gate(0x19u, v72, v73, v74);
idt_set_gate(0x1Au, v75, v76, v77);
idt_set_gate(0x1Bu, v78, v79, v80);
idt_set_gate(0x1Cu, v81, v82, v83);
idt_set_gate(0x1Du, v84, v85, v86);
idt_set_gate(0x1Eu, v87, v88, v89);
idt_set_gate(0x1Fu, v90, v91, v92);
}

original_code:
void isrs_install()
{
    idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
    idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E);
    idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E);
    idt_set_gate(3, (unsigned)isr3, 0x08, 0x8E);
    idt_set_gate(4, (unsigned)isr4, 0x08, 0x8E);
    idt_set_gate(5, (unsigned)isr5, 0x08, 0x8E);
    idt_set_gate(6, (unsigned)isr6, 0x08, 0x8E);
    idt_set_gate(7, (unsigned)isr7, 0x08, 0x8E);
    idt_set_gate(8, (unsigned)isr8, 0x08, 0x8E);
    idt_set_gate(9, (unsigned)isr9, 0x08, 0x8E);
    idt_set_gate(10, (unsigned)isr10, 0x08, 0x8E);
    idt_set_gate(11, (unsigned)isr11, 0x08, 0x8E);
    idt_set_gate(12, (unsigned)isr12, 0x08, 0x8E);
    idt_set_gate(13, (unsigned)isr13, 0x08, 0x8E);
    idt_set_gate(14, (unsigned)isr14, 0x08, 0x8E);
    idt_set_gate(15, (unsigned)isr15, 0x08, 0x8E);
    idt_set_gate(16, (unsigned)isr16, 0x08, 0x8E);
    idt_set_gate(17, (unsigned)isr17, 0x08, 0x8E);
    idt_set_gate(18, (unsigned)isr18, 0x08, 0x8E);
    idt_set_gate(19, (unsigned)isr19, 0x08, 0x8E);
    idt_set_gate(20, (unsigned)isr20, 0x08, 0x8E);
    idt_set_gate(21, (unsigned)isr21, 0x08, 0x8E);
    idt_set_gate(22, (unsigned)isr22, 0x08, 0x8E);
    idt_set_gate(23, (unsigned)isr23, 0x08, 0x8E);
    idt_set_gate(24, (unsigned)isr24, 0x08, 0x8E);
    idt_set_gate(25, (unsigned)isr25, 0x08, 0x8E);
    idt_set_gate(26, (unsigned)isr26, 0x08, 0x8E);
    idt_set_gate(27, (unsigned)isr27, 0x08, 0x8E);
    idt_set_gate(28, (unsigned)isr28, 0x08, 0x8E);
    idt_set_gate(29, (unsigned)isr29, 0x08, 0x8E);
    idt_set_gate(30, (unsigned)isr30, 0x08, 0x8E);
    idt_set_gate(31, (unsigned)isr31, 0x08, 0x8E);
}

canonical_original_code:
void isrs_install()
{
    idt_set_gate(0, (unsigned int)isr0, 0x08, 0x8E);
    idt_set_gate(1, (unsigned int)isr1, 0x08, 0x8E);
    idt_set_gate(2, (unsigned int)isr2, 0x08, 0x8E);
    idt_set_gate(3, (unsigned int)isr3, 0x08, 0x8E);
    idt_set_gate(4, (unsigned int)isr4, 0x08, 0x8E);
    idt_set_gate(5, (unsigned int)isr5, 0x08, 0x8E);
    idt_set_gate(6, (unsigned int)isr6, 0x08, 0x8E);
    idt_set_gate(7, (unsigned int)isr7, 0x08, 0x8E);
    idt_set_gate(8, (unsigned int)isr8, 0x08, 0x8E);
    idt_set_gate(9, (unsigned int)isr9, 0x08, 0x8E);
    idt_set_gate(10, (unsigned int)isr10, 0x08, 0x8E);
    idt_set_gate(11, (unsigned int)isr11, 0x08, 0x8E);
    idt_set_gate(12, (unsigned int)isr12, 0x08, 0x8E);
    idt_set_gate(13, (unsigned int)isr13, 0x08, 0x8E);
    idt_set_gate(14, (unsigned int)isr14, 0x08, 0x8E);
    idt_set_gate(15, (unsigned int)isr15, 0x08, 0x8E);
    idt_set_gate(16, (unsigned int)isr16, 0x08, 0x8E);
    idt_set_gate(17, (unsigned int)isr17, 0x08, 0x8E);
    idt_set_gate(18, (unsigned int)isr18, 0x08, 0x8E);
    idt_set_gate(19, (unsigned int)isr19, 0x08, 0x8E);
    idt_set_gate(20, (unsigned int)isr20, 0x08, 0x8E);
    idt_set_gate(21, (unsigned int)isr21, 0x08, 0x8E);
    idt_set_gate(22, (unsigned int)isr22, 0x08, 0x8E);
    idt_set_gate(23, (unsigned int)isr23, 0x08, 0x8E);
    idt_set_gate(24, (unsigned int)isr24, 0x08, 0x8E);
    idt_set_gate(25, (unsigned int)isr25, 0x08, 0x8E);
    idt_set_gate(26, (unsigned int)isr26, 0x08, 0x8E);
    idt_set_gate(27, (unsigned int)isr27, 0x08, 0x8E);
    idt_set_gate(28, (unsigned int)isr28, 0x08, 0x8E);
    idt_set_gate(29, (unsigned int)isr29, 0x08, 0x8E);
    idt_set_gate(30, (unsigned int)isr30, 0x08, 0x8E);
    idt_set_gate(31, (unsigned int)isr31, 0x08, 0x8E);
}


decompiled_code:
void __fastcall fault_handler(__int64 a1)
{
if ( *(_DWORD *)(a1 + 48) <= 0x1Fu )
{
video_puts("Error! '");
video_puts((&exception_messages)[*(unsigned int *)(a1 + 48)]);
video_puts("' System Halted!\n");
while ( 1 )
;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
if ( *(_DWORD *)(a1 + 48) <= 0x1Fu )
{
video_puts("Error! '");
video_puts((&exception_messages)[*(unsigned int *)(a1 + 48)]);
video_puts("' System Halted!\n");
while ( 1 )
;
}
}

original_code:
void fault_handler(regs_t *r)
{
    if (r->which_int < 32)
    {
        video_puts("Error! '");
        video_puts(exception_messages[r->which_int]);
        video_puts("' System Halted!\n");
        for (;;);
    }
}

canonical_original_code:
void fault_handler(struct regs_t *r)
{
    if (r->which_int < 32)
    {
        video_puts("Error! '");
        video_puts(exception_messages[r->which_int]);
        video_puts("' System Halted!\n");
        for (;;);
    }
}

variable_types: struct regs_t { unsigned int edi; unsigned int ds; unsigned int which_int; unsigned int eip; } *


decompiled_code:
unsigned __int64 __fastcall gdt_set_gate(int a1, unsigned __int64 a2, int a3, char a4, char a5)
{
unsigned __int64 result; // rax

gdt[4 * a1] = a3;
result = a2 >> 16;
gdt[4 * a1 + 1] = a2;
LOBYTE(gdt[4 * a1 + 2]) = BYTE2(a2);
HIBYTE(gdt[4 * a1 + 3]) = BYTE3(a2);
LOBYTE(gdt[4 * a1 + 3]) = a5 & 0xF0 | BYTE2(a3) & 0xF;
HIBYTE(gdt[4 * a1 + 2]) = a4;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(int a1, unsigned __int64 a2, int a3, char a4, char a5)
{
unsigned __int64 result; // rax

gdt[4 * a1] = a3;
result = a2 >> 16;
gdt[4 * a1 + 1] = a2;
LOBYTE(gdt[4 * a1 + 2]) = BYTE2(a2);
HIBYTE(gdt[4 * a1 + 3]) = BYTE3(a2);
LOBYTE(gdt[4 * a1 + 3]) = a5 & 0xF0 | BYTE2(a3) & 0xF;
HIBYTE(gdt[4 * a1 + 2]) = a4;
return result;
}

original_code:
void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran)
{
 gdt[num].base_low = (base & 0xFFFF);
 gdt[num].base_middle = (base >> 16) & 0xFF;
 gdt[num].base_high = (base >> 24) & 0xFF;
 gdt[num].limit_low = (limit & 0xFFFF);
 gdt[num].granularity = ((limit >> 16) & 0x0F);
 gdt[num].granularity |= (gran & 0xF0);
 gdt[num].access = access;
}

variable_types: num int

variable_types:
limit
unsigned long

variable_types:
access
unsigned char

variable_types:
gran
unsigned char


original_code:
void gdt_install()
{
    gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
    gp.base = (unsigned int) &gdt;
    gdt_set_gate(0, 0, 0, 0, 0);
    gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
    gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
 gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);
 gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);
 gdt_flush((uint32_t)&gp);
}

canonical_original_code:
void gdt_install()
{
    gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
    gp.base = (unsigned int) &gdt;
    gdt_set_gate(0, 0, 0, 0, 0);
    gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
    gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
 gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);
 gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);
 gdt_flush((unsigned int)&gp);
}

user_defined_types: struct gdt_entry { unsigned short limit_low; unsigned short base_low; unsigned char base_middle; unsigned char access; unsigned char granularity; unsigned char base_high; }


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

result = (unsigned int)(a1 - 1);
if ( (unsigned __int8)(a1 - 1) <= 0xEu )
irq_routines[(unsigned __int8)a1] = a2;
return result;
}

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

result = (unsigned int)(a1 - 1);
if ( (unsigned __int8)(a1 - 1) <= 0xEu )
irq_routines[(unsigned __int8)a1] = a2;
return result;
}

original_code:
void handler_reg(uint8_t irq, void (*handler)(regs_t *r))
{
    if(irq > 0 && irq < 16) irq_routines[irq] = handler;
}

canonical_original_code:
void handler_reg(unsigned char irq, void (*handler)(struct regs_t *r))
{
    if(irq > 0 && irq < 16) irq_routines[irq] = handler;
}

variable_types:
irq
unsigned char

variable_types: void (*)(struct regs_t { unsigned int edi; unsigned int ds; unsigned int which_int; unsigned int eip; } *r)


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

result = (unsigned int)(a1 - 1);
if ( (unsigned __int8)(a1 - 1) <= 0xEu )
irq_routines[(unsigned __int8)a1] = 0LL;
return result;
}

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

result = (unsigned int)(a1 - 1);
if ( (unsigned __int8)(a1 - 1) <= 0xEu )
irq_routines[(unsigned __int8)a1] = 0LL;
return result;
}

original_code:
void handler_unreg(uint8_t irq)
{
    if(irq > 0 && irq < 16) irq_routines[irq] = 0;
}

canonical_original_code:
void handler_unreg(unsigned char irq)
{
    if(irq > 0 && irq < 16) irq_routines[irq] = 0;
}


decompiled_code:
__int64 irq_remap()
{
io_outb(32LL, 17LL);
io_outb(160LL, 17LL);
io_outb(33LL, 32LL);
io_outb(161LL, 40LL);
io_outb(33LL, 4LL);
io_outb(161LL, 2LL);
io_outb(33LL, 1LL);
io_outb(161LL, 1LL);
io_outb(33LL, 0LL);
return io_outb(161LL, 0LL);
}

canonical_decompiled_code:
__int64 func8()
{
io_outb(32LL, 17LL);
io_outb(160LL, 17LL);
io_outb(33LL, 32LL);
io_outb(161LL, 40LL);
io_outb(33LL, 4LL);
io_outb(161LL, 2LL);
io_outb(33LL, 1LL);
io_outb(161LL, 1LL);
io_outb(33LL, 0LL);
return io_outb(161LL, 0LL);
}


decompiled_code:
void irq_install()
{
int v0; // eax
__int16 v1; // dx
char v2; // cl
int v3; // eax
__int16 v4; // dx
char v5; // cl
int v6; // eax
__int16 v7; // dx
char v8; // cl
int v9; // eax
__int16 v10; // dx
char v11; // cl
int v12; // eax
__int16 v13; // dx
char v14; // cl
int v15; // eax
__int16 v16; // dx
char v17; // cl
int v18; // eax
__int16 v19; // dx
char v20; // cl
int v21; // eax
__int16 v22; // dx
char v23; // cl
int v24; // eax
__int16 v25; // dx
char v26; // cl
int v27; // eax
__int16 v28; // dx
char v29; // cl
int v30; // eax
__int16 v31; // dx
char v32; // cl
int v33; // eax
__int16 v34; // dx
char v35; // cl
int v36; // eax
__int16 v37; // dx
char v38; // cl
int v39; // eax
__int16 v40; // dx
char v41; // cl
int v42; // eax
__int16 v43; // dx
char v44; // cl

irq_remap();
idt_set_gate(0x20u, (int)&irq0, 8, 142);
idt_set_gate(0x21u, v0, v1, v2);
idt_set_gate(0x22u, v3, v4, v5);
idt_set_gate(0x23u, v6, v7, v8);
idt_set_gate(0x24u, v9, v10, v11);
idt_set_gate(0x25u, v12, v13, v14);
idt_set_gate(0x26u, v15, v16, v17);
idt_set_gate(0x27u, v18, v19, v20);
idt_set_gate(0x28u, v21, v22, v23);
idt_set_gate(0x29u, v24, v25, v26);
idt_set_gate(0x2Au, v27, v28, v29);
idt_set_gate(0x2Bu, v30, v31, v32);
idt_set_gate(0x2Cu, v33, v34, v35);
idt_set_gate(0x2Du, v36, v37, v38);
idt_set_gate(0x2Eu, v39, v40, v41);
idt_set_gate(0x2Fu, v42, v43, v44);
}

original_code:
void irq_install()
{
    irq_remap();
    idt_set_gate(32, (unsigned)irq0, 0x08, 0x8E);
    idt_set_gate(33, (unsigned)irq1, 0x08, 0x8E);
    idt_set_gate(34, (unsigned)irq2, 0x08, 0x8E);
    idt_set_gate(35, (unsigned)irq3, 0x08, 0x8E);
    idt_set_gate(36, (unsigned)irq4, 0x08, 0x8E);
    idt_set_gate(37, (unsigned)irq5, 0x08, 0x8E);
    idt_set_gate(38, (unsigned)irq6, 0x08, 0x8E);
    idt_set_gate(39, (unsigned)irq7, 0x08, 0x8E);
    idt_set_gate(40, (unsigned)irq8, 0x08, 0x8E);
    idt_set_gate(41, (unsigned)irq9, 0x08, 0x8E);
    idt_set_gate(42, (unsigned)irq10, 0x08, 0x8E);
    idt_set_gate(43, (unsigned)irq11, 0x08, 0x8E);
    idt_set_gate(44, (unsigned)irq12, 0x08, 0x8E);
    idt_set_gate(45, (unsigned)irq13, 0x08, 0x8E);
    idt_set_gate(46, (unsigned)irq14, 0x08, 0x8E);
    idt_set_gate(47, (unsigned)irq15, 0x08, 0x8E);
}

canonical_original_code:
void irq_install()
{
    irq_remap();
    idt_set_gate(32, (unsigned int)irq0, 0x08, 0x8E);
    idt_set_gate(33, (unsigned int)irq1, 0x08, 0x8E);
    idt_set_gate(34, (unsigned int)irq2, 0x08, 0x8E);
    idt_set_gate(35, (unsigned int)irq3, 0x08, 0x8E);
    idt_set_gate(36, (unsigned int)irq4, 0x08, 0x8E);
    idt_set_gate(37, (unsigned int)irq5, 0x08, 0x8E);
    idt_set_gate(38, (unsigned int)irq6, 0x08, 0x8E);
    idt_set_gate(39, (unsigned int)irq7, 0x08, 0x8E);
    idt_set_gate(40, (unsigned int)irq8, 0x08, 0x8E);
    idt_set_gate(41, (unsigned int)irq9, 0x08, 0x8E);
    idt_set_gate(42, (unsigned int)irq10, 0x08, 0x8E);
    idt_set_gate(43, (unsigned int)irq11, 0x08, 0x8E);
    idt_set_gate(44, (unsigned int)irq12, 0x08, 0x8E);
    idt_set_gate(45, (unsigned int)irq13, 0x08, 0x8E);
    idt_set_gate(46, (unsigned int)irq14, 0x08, 0x8E);
    idt_set_gate(47, (unsigned int)irq15, 0x08, 0x8E);
}