decompiled_code:
__int64 __fastcall vir_to_phys(unsigned __int64 a1)
{
_BYTE *v1; // r12
_DWORD *v2; // rbp
__int64 result; // rax

v1 = (_BYTE *)(int)get_cr3();
boot_printf("vir_to_phys: %d:%d:%d\n", 0LL, (a1 >> 12) & 0x3FF, a1 & 0xFFF);
if ( (*v1 & 1) != 0
&& (v2 = (_DWORD *)((int)(*(_DWORD *)v1 & 0xFFFFF000) + 4 * ((a1 >> 12) & 0x3FF)), (*(_BYTE *)v2 & 1) != 0) )
{
boot_printf("vir_to_phys: virtual = 0x%x, physical = 0x%x\n", a1, (a1 & 0xFFF) + (int)(*v2 & 0xFFFFF000));
result = *v2 & 0xFFFFF000;
}
else
{
boot_printf("vir_to_phys: 0x%x, address not mapped.\n", a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1)
{
_BYTE *v1; // r12
_DWORD *v2; // rbp
__int64 result; // rax

v1 = (_BYTE *)(int)get_cr3();
boot_printf("vir_to_phys: %d:%d:%d\n", 0LL, (a1 >> 12) & 0x3FF, a1 & 0xFFF);
if ( (*v1 & 1) != 0
&& (v2 = (_DWORD *)((int)(*(_DWORD *)v1 & 0xFFFFF000) + 4 * ((a1 >> 12) & 0x3FF)), (*(_BYTE *)v2 & 1) != 0) )
{
boot_printf("vir_to_phys: virtual = 0x%x, physical = 0x%x\n", a1, (a1 & 0xFFF) + (int)(*v2 & 0xFFFFF000));
result = *v2 & 0xFFFFF000;
}
else
{
boot_printf("vir_to_phys: 0x%x, address not mapped.\n", a1);
result = 0LL;
}
return result;
}

original_code:
int
vir_to_phys (void *virtual)
{
  ULONG v;
  ULONG dirent;
  ULONG pageent;
  ULONG offset;
  struct page_directory_entry *cr3;
  struct page_table_entry *pageptr;
  v = (ULONG) virtual;
  dirent = (v & 0xffc0) >> 22;
  pageent = (v >> 12) & 0x3ff;
  offset = (v & 0xfff);
  cr3 = (struct page_directory_entry *)get_cr3 ();
  boot_printf ("vir_to_phys: %d:%d:%d\n", dirent, pageent, offset);
  if (cr3[dirent].present == 0)
    {
      boot_printf ("vir_to_phys: 0x%x, address not mapped.\n", virtual);
      return (0);
    }
  pageptr = (struct page_table_entry *)((cr3[dirent].frame_addr) << 12);
  if (pageptr[pageent].present == 0)
    {
      boot_printf ("vir_to_phys: 0x%x, address not mapped.\n", virtual);
      return (0);
    }
  boot_printf ("vir_to_phys: virtual = 0x%x, physical = 0x%x\n", virtual, (pageptr[pageent].frame_addr << 12) + offset);
  return (pageptr[pageent].frame_addr << 12);
}

canonical_original_code:
int vir_to_phys(void *virtual)
{
  unsigned long v;
  unsigned long dirent;
  unsigned long pageent;
  unsigned long offset;
  struct page_directory_entry *cr3;
  struct page_table_entry *pageptr;
  v = (unsigned long) virtual;
  dirent = (v & 0xffc0) >> 22;
  pageent = (v >> 12) & 0x3ff;
  offset = (v & 0xfff);
  cr3 = (struct page_directory_entry *)get_cr3 ();
  boot_printf ("vir_to_phys: %d:%d:%d\n", dirent, pageent, offset);
  if (cr3[dirent].present == 0)
    {
      boot_printf ("vir_to_phys: 0x%x, address not mapped.\n", virtual);
      return (0);
    }
  pageptr = (struct page_table_entry *)((cr3[dirent].frame_addr) << 12);
  if (pageptr[pageent].present == 0)
    {
      boot_printf ("vir_to_phys: 0x%x, address not mapped.\n", virtual);
      return (0);
    }
  boot_printf ("vir_to_phys: virtual = 0x%x, physical = 0x%x\n", virtual, (pageptr[pageent].frame_addr << 12) + offset);
  return (pageptr[pageent].frame_addr << 12);
}

variable_types:
virtual
void *

variable_types:
v
unsigned long

variable_types:
dirent
unsigned long

variable_types:
pageent
unsigned long

variable_types:
offset
unsigned long

variable_types: struct page_directory_entry { unsigned int present; unsigned int read_write; unsigned int u_and_s; unsigned int zero2; unsigned int access; unsigned int dirty; unsigned int zero1; unsigned int user; unsigned int frame_addr; } *


repo: monaka/B-Free

decompiled_code:
void psys_siglongjmp()
{
errno = 26;
}

canonical_decompiled_code:
void func0()
{
errno = 26;
}

original_code:
void
psys_siglongjmp (void *argp)
{
  struct a
    {
    } *args = (struct a *)argp;
  errno = 26;
}

canonical_original_code:
void psys_siglongjmp(void *argp)
{
  struct a *args = (struct a *)argp;
  errno = 26;
}

variable_types:
argp
void *

variable_types:
args
struct a {  } *

return_type: void


decompiled_code:
__int64 __fastcall close_console(__int64 a1, _QWORD *a2)
{
_QWORD v3[139]; // [rsp+0h] [rbp-458h] BYREF

v3[4] = *a2;
v3[5] = 0LL;
v3[6] = 0LL;
snd_mbf(a1, 1096LL, v3);
return 0LL;
}

original_code:
W
close_console (ID caller, DDEV_CLS_REQ *packet)
{
  DDEV_RES res;
  res.body.cls_res.dd = packet->dd;
  res.body.cls_res.errcd = (0);
  res.body.cls_res.errinfo = (0);
  snd_mbf (caller, sizeof (res), &res);
  return ((0));
}

canonical_original_code:
long close_console(int caller, struct DDEV_CLS_REQ *packet)
{
  struct DDEV_RES res;
  res.body.cls_res.dd = packet->dd;
  res.body.cls_res.errcd = (0);
  res.body.cls_res.errinfo = (0);
  snd_mbf (caller, sizeof (res), &res);
  return ((0));
}

variable_types: caller int

variable_types: struct DDEV_CLS_REQ { long dd; long eject; } *

variable_types: struct DDEV_RES { struct SVC_REQ { int mbfid; long msgtyp; int tskid; long len; unsigned long arg[]; } header; union { struct DDEV_OPN_RES { long dd; long errcd; long errinfo; } opn_res; struct DDEV_CLS_RES { long dd; long errcd; long errinfo; } cls_res; struct DDEV_REA_RES { long dd; long errcd; long errinfo; long split; long a_size; unsigned char dt[1024]; } rea_res; struct DDEV_WRI_RES { long dd; long errcd; long errinfo; long a_size; } wri_res; struct DDEV_CTL_RES { long dd; long errcd; long errinfo; long res[]; } ctl_res; } body; }

return_type: long

user_defined_types: struct DDEV_RES { struct SVC_REQ header; union { struct DDEV_OPN_RES opn_res; struct DDEV_CLS_RES cls_res; struct DDEV_REA_RES rea_res; struct DDEV_WRI_RES wri_res; struct DDEV_CTL_RES ctl_res; } body; }


original_code:
W
read_console (ID caller, DDEV_REA_REQ *packet)
{
  DDEV_RES res;
  res.body.rea_res.dd = packet->dd;
  res.body.rea_res.errcd = (-17);
  res.body.rea_res.errinfo = (-17);
  snd_mbf (caller, sizeof (res), &res);
  return ((-17));
}

canonical_original_code:
long read_console(int caller, struct DDEV_REA_REQ *packet)
{
  struct DDEV_RES res;
  res.body.rea_res.dd = packet->dd;
  res.body.rea_res.errcd = (-17);
  res.body.rea_res.errinfo = (-17);
  snd_mbf (caller, sizeof (res), &res);
  return ((-17));
}

variable_types: struct DDEV_REA_REQ { long dd; long start; long size; } *

user_defined_types: struct SVC_REQ { int mbfid; long msgtyp; int tskid; long len; unsigned long arg[]; }

user_defined_types: struct DDEV_OPN_RES { long dd; long errcd; long errinfo; }

user_defined_types: struct DDEV_CLS_RES { long dd; long errcd; long errinfo; }

user_defined_types: struct DDEV_REA_RES { long dd; long errcd; long errinfo; long split; long a_size; unsigned char dt[1024]; }

user_defined_types: struct DDEV_WRI_RES { long dd; long errcd; long errinfo; long a_size; }

user_defined_types: struct DDEV_CTL_RES { long dd; long errcd; long errinfo; long res[]; }


decompiled_code:
__int64 __fastcall control_console(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rax
int v3; // eax
__int64 v4; // rbp
_BYTE v6[32]; // [rsp+0h] [rbp-468h] BYREF
__int64 v7; // [rsp+20h] [rbp-448h]
__int64 v8; // [rsp+28h] [rbp-440h]
__int64 v9; // [rsp+30h] [rbp-438h]

v2 = *(_QWORD *)(a2 + 8);
if ( (v2 & 0x8000) == 0 )
{
if ( v2 == 3 )
{
v4 = video_mode;
if ( !video_mode )
{
vga_graph();
v7 = *(_QWORD *)a2;
v8 = 0LL;
v9 = 0LL;
video_mode = 1LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return v4;
}
goto LABEL_19;
}
if ( v2 > 3 )
{
if ( v2 == 4 )
{
if ( video_mode == 1 )
{
vga_text();
v7 = *(_QWORD *)a2;
v8 = 0LL;
v9 = 0LL;
video_mode = 0LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return 0LL;
}
goto LABEL_19;
}
}
else
{
if ( v2 == 1 )
{
clear_console();
v7 = *(_QWORD *)a2;
v8 = 0LL;
v9 = 0LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return 0LL;
}
if ( v2 == 2 )
{
if ( *(_QWORD *)(a2 + 16) == 2LL )
{
set_curpos(*(unsigned __int8 *)(a2 + 24), *(unsigned __int8 *)(a2 + 25));
v7 = *(_QWORD *)a2;
v8 = 0LL;
v9 = 0LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return 0LL;
}
LABEL_19:
v7 = *(_QWORD *)a2;
v8 = -33LL;
v9 = -33LL;
snd_mbf(a1, 1096LL, v6);
return -33LL;
}
}
v7 = *(_QWORD *)a2;
v8 = -17LL;
v9 = -17LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return -17LL;
}
if ( video_mode != 1 )
goto LABEL_19;
v3 = graphic_command();
v7 = *(_QWORD *)a2;
v4 = v3;
v8 = v3;
v9 = v3;
snd_mbf((unsigned int)a1, 1096LL, v6);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
unsigned __int64 v2; // rax
int v3; // eax
__int64 v4; // rbp
_BYTE v6[32]; // [rsp+0h] [rbp-468h] BYREF
__int64 v7; // [rsp+20h] [rbp-448h]
__int64 v8; // [rsp+28h] [rbp-440h]
__int64 v9; // [rsp+30h] [rbp-438h]

v2 = *(_QWORD *)(a2 + 8);
if ( (v2 & 0x8000) == 0 )
{
if ( v2 == 3 )
{
v4 = video_mode;
if ( !video_mode )
{
vga_graph();
v7 = *(_QWORD *)a2;
v8 = 0LL;
v9 = 0LL;
video_mode = 1LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return v4;
}
goto LABEL_19;
}
if ( v2 > 3 )
{
if ( v2 == 4 )
{
if ( video_mode == 1 )
{
vga_text();
v7 = *(_QWORD *)a2;
v8 = 0LL;
v9 = 0LL;
video_mode = 0LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return 0LL;
}
goto LABEL_19;
}
}
else
{
if ( v2 == 1 )
{
clear_console();
v7 = *(_QWORD *)a2;
v8 = 0LL;
v9 = 0LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return 0LL;
}
if ( v2 == 2 )
{
if ( *(_QWORD *)(a2 + 16) == 2LL )
{
set_curpos(*(unsigned __int8 *)(a2 + 24), *(unsigned __int8 *)(a2 + 25));
v7 = *(_QWORD *)a2;
v8 = 0LL;
v9 = 0LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return 0LL;
}
LABEL_19:
v7 = *(_QWORD *)a2;
v8 = -33LL;
v9 = -33LL;
snd_mbf(a1, 1096LL, v6);
return -33LL;
}
}
v7 = *(_QWORD *)a2;
v8 = -17LL;
v9 = -17LL;
snd_mbf((unsigned int)a1, 1096LL, v6);
return -17LL;
}
if ( video_mode != 1 )
goto LABEL_19;
v3 = graphic_command();
v7 = *(_QWORD *)a2;
v4 = v3;
v8 = v3;
v9 = v3;
snd_mbf((unsigned int)a1, 1096LL, v6);
return v4;
}

original_code:
W
control_console (ID caller, DDEV_CTL_REQ *packet)
{
  DDEV_RES res;
  ER errno;
  if ((packet->cmd & 0x00008000) != 0)
    {
      if (video_mode != 1)
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (-33);
   res.body.ctl_res.errinfo = (-33);
   snd_mbf (caller, sizeof (res), &res);
   return ((-33));
 }
      errno = graphic_command (caller, packet);
      res.body.ctl_res.dd = packet->dd;
      res.body.ctl_res.errcd = errno;
      res.body.ctl_res.errinfo = errno;
      snd_mbf (caller, sizeof (res), &res);
      return (errno);
    }
  else
    {
      switch (packet->cmd)
 {
 case 0x00000001:
   clear_console ();
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (0);
   res.body.ctl_res.errinfo = (0);
   snd_mbf (caller, sizeof (res), &res);
   return ((0));
 case 0x00000002:
   if (packet->len != 2)
     {
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (-33);
       res.body.ctl_res.errinfo = (-33);
       snd_mbf (caller, sizeof (res), &res);
       return ((-33));
     }
   set_curpos (packet->param[0], packet->param[1]);
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (0);
   res.body.ctl_res.errinfo = (0);
   snd_mbf (caller, sizeof (res), &res);
   return ((0));
 case 0x00000003:
   if (video_mode == 0)
     {
       vga_graph ();
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (0);
       res.body.ctl_res.errinfo = (0);
       video_mode = 1;
       snd_mbf (caller, sizeof (res), &res);
       return ((0));
     }
   else
     {
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (-33);
       res.body.ctl_res.errinfo = (-33);
       snd_mbf (caller, sizeof (res), &res);
       return ((-33));
     }
 case 0x00000004:
   if (video_mode == 1)
     {
       vga_text ();
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (0);
       res.body.ctl_res.errinfo = (0);
       video_mode = 0;
       snd_mbf (caller, sizeof (res), &res);
       return ((0));
     }
   else
     {
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (-33);
       res.body.ctl_res.errinfo = (-33);
       snd_mbf (caller, sizeof (res), &res);
       return ((-33));
     }
 default:
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (-17);
   res.body.ctl_res.errinfo = (-17);
   snd_mbf (caller, sizeof (res), &res);
   return ((-17));
 }
    }
}

canonical_original_code:
long control_console(int caller, struct DDEV_CTL_REQ *packet)
{
  struct DDEV_RES res;
  int errno;
  if ((packet->cmd & 0x00008000) != 0)
    {
      if (video_mode != 1)
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (-33);
   res.body.ctl_res.errinfo = (-33);
   snd_mbf (caller, sizeof (res), &res);
   return ((-33));
 }
      errno = graphic_command (caller, packet);
      res.body.ctl_res.dd = packet->dd;
      res.body.ctl_res.errcd = errno;
      res.body.ctl_res.errinfo = errno;
      snd_mbf (caller, sizeof (res), &res);
      return (errno);
    }
  else
    {
      switch (packet->cmd)
 {
 case 0x00000001:
   clear_console ();
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (0);
   res.body.ctl_res.errinfo = (0);
   snd_mbf (caller, sizeof (res), &res);
   return ((0));
 case 0x00000002:
   if (packet->len != 2)
     {
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (-33);
       res.body.ctl_res.errinfo = (-33);
       snd_mbf (caller, sizeof (res), &res);
       return ((-33));
     }
   set_curpos (packet->param[0], packet->param[1]);
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (0);
   res.body.ctl_res.errinfo = (0);
   snd_mbf (caller, sizeof (res), &res);
   return ((0));
 case 0x00000003:
   if (video_mode == 0)
     {
       vga_graph ();
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (0);
       res.body.ctl_res.errinfo = (0);
       video_mode = 1;
       snd_mbf (caller, sizeof (res), &res);
       return ((0));
     }
   else
     {
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (-33);
       res.body.ctl_res.errinfo = (-33);
       snd_mbf (caller, sizeof (res), &res);
       return ((-33));
     }
 case 0x00000004:
   if (video_mode == 1)
     {
       vga_text ();
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (0);
       res.body.ctl_res.errinfo = (0);
       video_mode = 0;
       snd_mbf (caller, sizeof (res), &res);
       return ((0));
     }
   else
     {
       res.body.ctl_res.dd = packet->dd;
       res.body.ctl_res.errcd = (-33);
       res.body.ctl_res.errinfo = (-33);
       snd_mbf (caller, sizeof (res), &res);
       return ((-33));
     }
 default:
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (-17);
   res.body.ctl_res.errinfo = (-17);
   snd_mbf (caller, sizeof (res), &res);
   return ((-17));
 }
    }
}

variable_types: struct DDEV_CTL_REQ { long dd; unsigned long cmd; long len; unsigned char param[]; } *

variable_types: errno int


decompiled_code:
__int64 init_console()
{
unsigned int v0; // eax
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

recvport = get_port(1080LL, 1080LL);
if ( recvport <= 0 )
{
dbg_printf("CONSOLE: cannot make receive port.\n");
slp_tsk();
}
v0 = regist_port("driver.console", (unsigned int)recvport);
if ( v0 )
{
dbg_printf("console: cannot regist port (error = %d)\n", v0);
result = -5LL;
}
else
{
initialized = 1LL;
dbg_printf("console: regist port %d\n", (unsigned int)recvport);
if ( (unsigned int)vget_csl(&v3, &v2) )
clear_console();
else
set_curpos(v3, v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // eax
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

recvport = get_port(1080LL, 1080LL);
if ( recvport <= 0 )
{
dbg_printf("CONSOLE: cannot make receive port.\n");
slp_tsk();
}
v0 = regist_port("driver.console", (unsigned int)recvport);
if ( v0 )
{
dbg_printf("console: cannot regist port (error = %d)\n", v0);
result = -5LL;
}
else
{
initialized = 1LL;
dbg_printf("console: regist port %d\n", (unsigned int)recvport);
if ( (unsigned int)vget_csl(&v3, &v2) )
clear_console();
else
set_curpos(v3, v2);
result = 0LL;
}
return result;
}

original_code:
W
init_console (void)
{
  int i;
  ER error;
  W x, y;
  recvport = get_port (sizeof (DDEV_REQ), sizeof (DDEV_REQ));
  if (recvport <= 0)
    {
      dbg_printf ("CONSOLE: cannot make receive port.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.console", recvport);
  if (error != (0))
    {
      dbg_printf ("console: cannot regist port (error = %d)\n", error);
      return (-5);
    }
  initialized = 1;
  dbg_printf ("console: regist port %d\n", recvport);
  if (vget_csl (&x, &y) == (0))
    {
      set_curpos (x, y);
    }
  else
    {
      clear_console ();
    }
  return (0);
}

canonical_original_code:
long init_console()
{
  int i;
  int error;
  long x; long y;
  recvport = get_port (sizeof (DDEV_REQ), sizeof (DDEV_REQ));
  if (recvport <= 0)
    {
      dbg_printf ("CONSOLE: cannot make receive port.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.console", recvport);
  if (error != (0))
    {
      dbg_printf ("console: cannot regist port (error = %d)\n", error);
      return (-5);
    }
  initialized = 1;
  dbg_printf ("console: regist port %d\n", recvport);
  if (vget_csl (&x, &y) == (0))
    {
      set_curpos (x, y);
    }
  else
    {
      clear_console ();
    }
  return (0);
}

variable_types: i int

variable_types: error int

variable_types: x long

variable_types: y long


decompiled_code:
__int64 __fastcall open_console(__int64 a1, _QWORD *a2)
{
_QWORD v3[139]; // [rsp+0h] [rbp-458h] BYREF

v3[4] = *a2;
v3[5] = 0LL;
v3[6] = 0LL;
snd_mbf(a1, 1096LL, v3);
return 0LL;
}

original_code:
W
open_console (ID caller, DDEV_OPN_REQ *packet)
{
  DDEV_RES res;
  res.body.opn_res.dd = packet->dd;
  res.body.opn_res.errcd = (0);
  res.body.opn_res.errinfo = (0);
  snd_mbf (caller, sizeof (res), &res);
  return ((0));
}

canonical_original_code:
long open_console(int caller, struct DDEV_OPN_REQ *packet)
{
  struct DDEV_RES res;
  res.body.opn_res.dd = packet->dd;
  res.body.opn_res.errcd = (0);
  res.body.opn_res.errinfo = (0);
  snd_mbf (caller, sizeof (res), &res);
  return ((0));
}

variable_types:
packet
struct DDEV_OPN_REQ { long dd; } *


decompiled_code:
__int64 __fastcall write_console(unsigned int a1, __int64 *a2)
{
__int64 v3; // rbx
int v4; // eax
int v5; // edx
__int64 v6; // rax
__int64 v7; // r12
unsigned __int8 v8; // di
__int64 v9; // rbp
__int64 v11; // [rsp+0h] [rbp-488h]
__int64 v12; // [rsp+8h] [rbp-480h]
char v13[32]; // [rsp+10h] [rbp-478h] BYREF
__int64 v14; // [rsp+30h] [rbp-458h]
__int64 v15; // [rsp+38h] [rbp-450h]
__int64 v16; // [rsp+40h] [rbp-448h]
__int64 v17; // [rsp+48h] [rbp-440h]

if ( a2[2] <= 0 )
{
v3 = 0LL;
v4 = 0;
goto LABEL_35;
}
v3 = 0LL;
do
{
v7 = v3;
v8 = *((_BYTE *)a2 + v3 + 24);
if ( esc_flag_1 == 1 )
{
if ( v8 == 91 )
{
esc_flag_1 = 2;
goto LABEL_29;
}
v4 = write_char(v8);
esc_flag_1 = 0;
}
else
{
if ( esc_flag_1 == 2 )
{
if ( (unsigned __int8)(v8 - 48) > 9u )
{
v5 = cnum_0;
if ( !*(&v11 + cnum_0) )
*(&v11 + cnum_0) = 1LL;
switch ( v8 )
{
case ';':
cnum_0 = v5 + 1;
if ( v5 == 1 )
esc_flag_1 = 0;
goto LABEL_29;
case 'A':
move_curpos(0LL, -v11);
esc_flag_1 = 0;
goto LABEL_29;
case 'B':
move_curpos(0LL, v11);
esc_flag_1 = 0;
goto LABEL_29;
case 'C':
move_curpos(v11, 0LL);
esc_flag_1 = 0;
goto LABEL_29;
case 'D':
move_curpos(-v11, 0LL);
esc_flag_1 = 0;
goto LABEL_29;
case 'H':
v6 = v12;
if ( !v12 )
v6 = 1LL;
v12 = v6;
set_curpos(v6 - 1, v11 - 1);
esc_flag_1 = 0;
goto LABEL_29;
case 'J':
if ( v11 == 2 )
{
set_curpos(0LL, 0LL);
clear_console();
}
else if ( v11 == 1 )
{
clear_rest_screen();
}
esc_flag_1 = 0;
goto LABEL_29;
case 'K':
clear_rest_line();
esc_flag_1 = 0;
goto LABEL_29;
default:
esc_flag_1 = 0;
v4 = write_char(v8);
goto LABEL_28;
}
}
*(&v11 + cnum_0) = v8 - 48 + 10 * *(&v11 + cnum_0);
goto LABEL_29;
}
if ( v8 == 27 )
{
esc_flag_1 = 1;
v11 = 0LL;
v12 = 0LL;
cnum_0 = 0;
goto LABEL_29;
}
v4 = write_char(v8);
}
LABEL_28:
if ( v4 )
goto LABEL_35;
LABEL_29:
++v3;
}
while ( a2[2] > v7 + 1 );
v4 = 0;
LABEL_35:
v14 = *a2;
v9 = v4;
v15 = v4;
v16 = v4;
v17 = v3;
snd_mbf(a1, 1096LL, v13);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 *a2)
{
__int64 v3; // rbx
int v4; // eax
int v5; // edx
__int64 v6; // rax
__int64 v7; // r12
unsigned __int8 v8; // di
__int64 v9; // rbp
__int64 v11; // [rsp+0h] [rbp-488h]
__int64 v12; // [rsp+8h] [rbp-480h]
char v13[32]; // [rsp+10h] [rbp-478h] BYREF
__int64 v14; // [rsp+30h] [rbp-458h]
__int64 v15; // [rsp+38h] [rbp-450h]
__int64 v16; // [rsp+40h] [rbp-448h]
__int64 v17; // [rsp+48h] [rbp-440h]

if ( a2[2] <= 0 )
{
v3 = 0LL;
v4 = 0;
goto LABEL_35;
}
v3 = 0LL;
do
{
v7 = v3;
v8 = *((_BYTE *)a2 + v3 + 24);
if ( esc_flag_1 == 1 )
{
if ( v8 == 91 )
{
esc_flag_1 = 2;
goto LABEL_29;
}
v4 = write_char(v8);
esc_flag_1 = 0;
}
else
{
if ( esc_flag_1 == 2 )
{
if ( (unsigned __int8)(v8 - 48) > 9u )
{
v5 = cnum_0;
if ( !*(&v11 + cnum_0) )
*(&v11 + cnum_0) = 1LL;
switch ( v8 )
{
case ';':
cnum_0 = v5 + 1;
if ( v5 == 1 )
esc_flag_1 = 0;
goto LABEL_29;
case 'A':
move_curpos(0LL, -v11);
esc_flag_1 = 0;
goto LABEL_29;
case 'B':
move_curpos(0LL, v11);
esc_flag_1 = 0;
goto LABEL_29;
case 'C':
move_curpos(v11, 0LL);
esc_flag_1 = 0;
goto LABEL_29;
case 'D':
move_curpos(-v11, 0LL);
esc_flag_1 = 0;
goto LABEL_29;
case 'H':
v6 = v12;
if ( !v12 )
v6 = 1LL;
v12 = v6;
set_curpos(v6 - 1, v11 - 1);
esc_flag_1 = 0;
goto LABEL_29;
case 'J':
if ( v11 == 2 )
{
set_curpos(0LL, 0LL);
clear_console();
}
else if ( v11 == 1 )
{
clear_rest_screen();
}
esc_flag_1 = 0;
goto LABEL_29;
case 'K':
clear_rest_line();
esc_flag_1 = 0;
goto LABEL_29;
default:
esc_flag_1 = 0;
v4 = write_char(v8);
goto LABEL_28;
}
}
*(&v11 + cnum_0) = v8 - 48 + 10 * *(&v11 + cnum_0);
goto LABEL_29;
}
if ( v8 == 27 )
{
esc_flag_1 = 1;
v11 = 0LL;
v12 = 0LL;
cnum_0 = 0;
goto LABEL_29;
}
v4 = write_char(v8);
}
LABEL_28:
if ( v4 )
goto LABEL_35;
LABEL_29:
++v3;
}
while ( a2[2] > v7 + 1 );
v4 = 0;
LABEL_35:
v14 = *a2;
v9 = v4;
v15 = v4;
v16 = v4;
v17 = v3;
snd_mbf(a1, 1096LL, v13);
return v9;
}

original_code:
W
write_console(ID caller, DDEV_WRI_REQ *packet)
{
  DDEV_RES res;
  int i;
  ER error;
  static int esc_flag = 0, cnum = 0;
  W cpos[2];
  UB ch;
  error = (0);
  for (i = 0; i < (packet->size); i++)
    {
      ch = packet->dt[i];
      if (esc_flag == 1) {
 if (ch == '[') {
   esc_flag = 2;
 }
 else {
   error = write_char (ch);
   esc_flag = 0;
 }
      }
      else if (esc_flag == 2) {
 if (((ch >= '0') && (ch <= '9'))) {
   cpos[cnum] *= 10;
   cpos[cnum] += ch-'0';
 }
 else {
   if (cpos[cnum] == 0) cpos[cnum] = 1;
   switch(ch) {
   case ';':
     cnum++;
     if (cnum == 2) esc_flag = 0;
     break;
   case 'H':
     if (cpos[1] == 0) cpos[1] = 1;
     set_curpos(cpos[1]-1, cpos[0]-1);
     esc_flag = 0;
     break;
   case 'A':
     move_curpos(0, -cpos[0]);
     esc_flag = 0;
     break;
   case 'B':
     move_curpos(0, cpos[0]);
     esc_flag = 0;
     break;
   case 'C':
     move_curpos(cpos[0], 0);
     esc_flag = 0;
     break;
   case 'D':
     move_curpos(-cpos[0], 0);
     esc_flag = 0;
     break;
   case 'J':
     if (cpos[0] == 2) {
       set_curpos(0, 0);
       clear_console();
     }
     else if (cpos[0] == 1) {
       clear_rest_screen();
     }
     esc_flag = 0;
     break;
   case 'K':
     clear_rest_line();
     esc_flag = 0;
     break;
   default:
     esc_flag = 0;
     error = write_char(ch);
   }
 }
      }
      else {
 if (ch == 0x1B) {
   esc_flag = 1;
   cpos[0] = 0; cpos[1] = 0;
   cnum = 0;
 }
 else {
   error = write_char (ch);
 }
      }
      if (error != (0))
 break;
    }
  res.body.wri_res.dd = packet->dd;
  res.body.wri_res.errcd = error;
  res.body.wri_res.errinfo = error;
  res.body.wri_res.a_size = i;
  snd_mbf (caller, sizeof (res), &res);
  return (error);
}

canonical_original_code:
long write_console(int caller, struct DDEV_WRI_REQ *packet)
{
  struct DDEV_RES res;
  int i;
  int error;
  static int esc_flag = 0; static int cnum = 0;
  long cpos[2];
  unsigned char ch;
  error = (0);
  for (i = 0; i < (packet->size); i++)
    {
      ch = packet->dt[i];
      if (esc_flag == 1) {
 if (ch == '[') {
   esc_flag = 2;
 }
 else {
   error = write_char (ch);
   esc_flag = 0;
 }
      }
      else if (esc_flag == 2) {
 if (((ch >= '0') && (ch <= '9'))) {
   cpos[cnum] *= 10;
   cpos[cnum] += ch-'0';
 }
 else {
   if (cpos[cnum] == 0) cpos[cnum] = 1;
   switch(ch) {
   case ';':
     cnum++;
     if (cnum == 2) esc_flag = 0;
     break;
   case 'H':
     if (cpos[1] == 0) cpos[1] = 1;
     set_curpos(cpos[1]-1, cpos[0]-1);
     esc_flag = 0;
     break;
   case 'A':
     move_curpos(0, -cpos[0]);
     esc_flag = 0;
     break;
   case 'B':
     move_curpos(0, cpos[0]);
     esc_flag = 0;
     break;
   case 'C':
     move_curpos(cpos[0], 0);
     esc_flag = 0;
     break;
   case 'D':
     move_curpos(-cpos[0], 0);
     esc_flag = 0;
     break;
   case 'J':
     if (cpos[0] == 2) {
       set_curpos(0, 0);
       clear_console();
     }
     else if (cpos[0] == 1) {
       clear_rest_screen();
     }
     esc_flag = 0;
     break;
   case 'K':
     clear_rest_line();
     esc_flag = 0;
     break;
   default:
     esc_flag = 0;
     error = write_char(ch);
   }
 }
      }
      else {
 if (ch == 0x1B) {
   esc_flag = 1;
   cpos[0] = 0; cpos[1] = 0;
   cnum = 0;
 }
 else {
   error = write_char (ch);
 }
      }
      if (error != (0))
 break;
    }
  res.body.wri_res.dd = packet->dd;
  res.body.wri_res.errcd = error;
  res.body.wri_res.errinfo = error;
  res.body.wri_res.a_size = i;
  snd_mbf (caller, sizeof (res), &res);
  return (error);
}

variable_types: struct DDEV_WRI_REQ { long dd; long start; long size; unsigned char dt[1024]; } *

variable_types: cnum int

variable_types:
cpos
long [2]

variable_types:
ch
unsigned char


doit

decompiled_code:
__int64 __fastcall doit(unsigned int *a1)
{
__int64 result; // rax

result = *((_QWORD *)a1 + 1);
switch ( result )
{
case 0LL:
if ( !initialized )
init_console();
result = open_console(*a1, (_QWORD *)a1 + 4);
break;
case 1LL:
result = close_console(*a1, (_QWORD *)a1 + 4);
break;
case 2LL:
result = read_console(*a1, (_QWORD *)a1 + 4);
break;
case 3LL:
result = write_console(*a1, (__int64 *)a1 + 4);
break;
case 4LL:
result = control_console(*a1, (__int64)(a1 + 8));
break;
default:
return result;
}
return result;
}

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

result = *((_QWORD *)a1 + 1);
switch ( result )
{
case 0LL:
if ( !initialized )
func1();
result = func2(*a1, (_QWORD *)a1 + 4);
break;
case 1LL:
result = func3(*a1, (_QWORD *)a1 + 4);
break;
case 2LL:
result = func4(*a1, (_QWORD *)a1 + 4);
break;
case 3LL:
result = func5(*a1, (__int64 *)a1 + 4);
break;
case 4LL:
result = func6(*a1, (__int64)(a1 + 8));
break;
default:
return result;
}
return result;
}

original_code:
static void
doit (DDEV_REQ *packet)
{
  switch (packet->header.msgtyp)
    {
    case DEV_OPN:
      if (!initialized)
 {
   init_console ();
 }
      open_console (packet->header.mbfid, &(packet->body.opn_req));
      break;
    case DEV_CLS:
      close_console (packet->header.mbfid, &(packet->body.cls_req));
      break;
    case DEV_REA:
      read_console (packet->header.mbfid, &(packet->body.rea_req));
      break;
    case DEV_WRI:
      write_console (packet->header.mbfid, &(packet->body.wri_req));
      break;
    case DEV_CTL:
      control_console (packet->header.mbfid, &(packet->body.ctl_req));
      break;
    }
}

canonical_original_code:
static void doit(struct DDEV_REQ *packet)
{
  switch (packet->header.msgtyp)
    {
    case DEV_OPN:
      if (!initialized)
 {
   init_console ();
 }
      open_console (packet->header.mbfid, &(packet->body.opn_req));
      break;
    case DEV_CLS:
      close_console (packet->header.mbfid, &(packet->body.cls_req));
      break;
    case DEV_REA:
      read_console (packet->header.mbfid, &(packet->body.rea_req));
      break;
    case DEV_WRI:
      write_console (packet->header.mbfid, &(packet->body.wri_req));
      break;
    case DEV_CTL:
      control_console (packet->header.mbfid, &(packet->body.ctl_req));
      break;
    }
}

variable_types: struct DDEV_REQ { struct SVC_REQ { int mbfid; long msgtyp; int tskid; long len; unsigned long arg[]; } header; union { struct DDEV_OPN_REQ { long dd; } opn_req; struct DDEV_CLS_REQ { long dd; long eject; } cls_req; struct DDEV_REA_REQ { long dd; long start; long size; } rea_req; struct DDEV_WRI_REQ { long dd; long start; long size; unsigned char dt[1024]; } wri_req; struct DDEV_CTL_REQ { long dd; unsigned long cmd; long len; unsigned char param[]; } ctl_req; struct DDEV_PRD_REQ { long dd; char *buf; long start; long length; } prd_req; struct DDEV_RLY_REQ { long dd; long start; long size; unsigned char dt[1024]; } rly_req; } body; } *

user_defined_types: struct DDEV_REQ { struct SVC_REQ header; union { struct DDEV_OPN_REQ opn_req; struct DDEV_CLS_REQ cls_req; struct DDEV_REA_REQ rea_req; struct DDEV_WRI_REQ wri_req; struct DDEV_CTL_REQ ctl_req; struct DDEV_PRD_REQ prd_req; struct DDEV_RLY_REQ rly_req; } body; }


decompiled_code:
void __noreturn main_loop()
{
__int64 v0; // [rsp+8h] [rbp-450h] BYREF
unsigned int v1[274]; // [rsp+10h] [rbp-448h] BYREF

while ( 1 )
{
do
{
v0 = 1080LL;
get_req((unsigned int)recvport, v1, &v0);
}
while ( sys_errno );
doit(v1);
}
}

canonical_decompiled_code:
void __noreturn func8()
{
__int64 v0; // [rsp+8h] [rbp-450h] BYREF
unsigned int v1[274]; // [rsp+10h] [rbp-448h] BYREF

while ( 1 )
{
do
{
v0 = 1080LL;
get_req((unsigned int)recvport, v1, &v0);
}
while ( sys_errno );
func7(v1);
}
}

original_code:
static void
main_loop (void)
{
  DDEV_REQ req;
  ER err;
  extern ER sys_errno;
  for (;;)
    {
      W rsize;
      rsize = sizeof (req);
      get_req (recvport, &req, &rsize);
      switch (sys_errno)
 {
 case (0):
   doit (&req);
   break;
 default:
   break;
 }
    }
}

canonical_original_code:
static void main_loop()
{
  struct DDEV_REQ req;
  int err;
  extern int sys_errno;
  for (;;)
    {
      long rsize;
      rsize = sizeof (req);
      get_req (recvport, &req, &rsize);
      switch (sys_errno)
 {
 case (0):
   doit (&req);
   break;
 default:
   break;
 }
    }
}

variable_types: struct DDEV_REQ { struct SVC_REQ { int mbfid; long msgtyp; int tskid; long len; unsigned long arg[]; } header; union { struct DDEV_OPN_REQ { long dd; } opn_req; struct DDEV_CLS_REQ { long dd; long eject; } cls_req; struct DDEV_REA_REQ { long dd; long start; long size; } rea_req; struct DDEV_WRI_REQ { long dd; long start; long size; unsigned char dt[1024]; } wri_req; struct DDEV_CTL_REQ { long dd; unsigned long cmd; long len; unsigned char param[]; } ctl_req; struct DDEV_PRD_REQ { long dd; char *buf; long start; long length; } prd_req; struct DDEV_RLY_REQ { long dd; long start; long size; unsigned char dt[1024]; } rly_req; } body; }

variable_types: err int

variable_types: rsize long


start

decompiled_code:
void __noreturn start()
{
init_console();
writes("console driver start\n");
main_loop();
}

canonical_decompiled_code:
void __noreturn func9()
{
func1();
func0("console driver start\n");
func8();
}

original_code:
void start (void)
{
  char *p;
  init_console ();
  writes ("console driver start\n");
  p = rcsid;
  p = revision;
  main_loop ();
}

canonical_original_code:
void start()
{
  char *p;
  init_console ();
  writes ("console driver start\n");
  p = rcsid;
  p = revision;
  main_loop ();
}

variable_types:
p
char *


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

if ( keyboard_select == 1 )
result = key_table_101[255 * a1 + a2];
else
result = key_table_106[255 * a1 + a2];
return result;
}

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

if ( keyboard_select == 1 )
result = key_table_101[255 * a1 + a2];
else
result = key_table_106[255 * a1 + a2];
return result;
}

original_code:
static W
get_keycode(int cont,int num)
{
  if(keyboard_select == 1){
    return key_table_101[cont][num];
  }else{
    return key_table_106[cont][num];
  }
}

canonical_original_code:
static long get_keycode(int cont, int num)
{
  if(keyboard_select == 1){
    return key_table_101[cont][num];
  }else{
    return key_table_106[cont][num];
  }
}

variable_types: cont int

variable_types: num int


decompiled_code:
char keyboard_interrupt()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v2; // rbp

LOBYTE(v0) = inb(0x60u);
v1 = (int)v0;
if ( (driver_mode & 4) != 0 )
{
put_entry((int)v0);
LOBYTE(v0) = set_flg(waitflag, 1LL);
return v0;
}
if ( (_DWORD)v0 == 157 )
{
shiftkey_code &= 0xFFFFFFFFFFFFFFFDLL;
return v0;
}
if ( (int)v0 <= 157 )
goto LABEL_16;
if ( (_DWORD)v0 == 184 )
{
shiftkey_code &= 0xFFFFFFFFFFFFFFFBLL;
return v0;
}
if ( (int)v0 > 184 )
{
if ( (_DWORD)v0 == 241 )
{
capskey = 0LL;
return v0;
}
LABEL_16:
if ( (v0 & 0x80u) != 0LL )
return v0;
if ( (shiftkey_code & 2) != 0 )
{
v0 = get_keycode(2, v0);
v2 = v0;
LABEL_19:
if ( v1 == 59 )
{
send_switch = 1LL;
LOBYTE(v0) = rel_wai(my_tskid);
}
if ( v2 )
{
put_entry(v2);
LOBYTE(v0) = set_flg(waitflag, 1LL);
}
return v0;
}
if ( capskey )
{
if ( (shiftkey_code & 1) != 0 )
{
LABEL_25:
v0 = get_keycode(0, v0);
v2 = v0;
goto LABEL_19;
}
}
else if ( (shiftkey_code & 1) == 0 )
{
goto LABEL_25;
}
v0 = get_keycode(1, v0);
v2 = v0;
goto LABEL_19;
}
if ( (_DWORD)v0 == 170 || (_DWORD)v0 == 182 )
shiftkey_code &= 0xFFFFFFFFFFFFFFFELL;
return v0;
}

canonical_decompiled_code:
char func1()
{
__int64 v0; // rax
__int64 v1; // rbx
__int64 v2; // rbp

LOBYTE(v0) = inb(0x60u);
v1 = (int)v0;
if ( (driver_mode & 4) != 0 )
{
put_entry((int)v0);
LOBYTE(v0) = set_flg(waitflag, 1LL);
return v0;
}
if ( (_DWORD)v0 == 157 )
{
shiftkey_code &= 0xFFFFFFFFFFFFFFFDLL;
return v0;
}
if ( (int)v0 <= 157 )
goto LABEL_16;
if ( (_DWORD)v0 == 184 )
{
shiftkey_code &= 0xFFFFFFFFFFFFFFFBLL;
return v0;
}
if ( (int)v0 > 184 )
{
if ( (_DWORD)v0 == 241 )
{
capskey = 0LL;
return v0;
}
LABEL_16:
if ( (v0 & 0x80u) != 0LL )
return v0;
if ( (shiftkey_code & 2) != 0 )
{
v0 = func0(2, v0);
v2 = v0;
LABEL_19:
if ( v1 == 59 )
{
send_switch = 1LL;
LOBYTE(v0) = rel_wai(my_tskid);
}
if ( v2 )
{
put_entry(v2);
LOBYTE(v0) = set_flg(waitflag, 1LL);
}
return v0;
}
if ( capskey )
{
if ( (shiftkey_code & 1) != 0 )
{
LABEL_25:
v0 = func0(0, v0);
v2 = v0;
goto LABEL_19;
}
}
else if ( (shiftkey_code & 1) == 0 )
{
goto LABEL_25;
}
v0 = func0(1, v0);
v2 = v0;
goto LABEL_19;
}
if ( (_DWORD)v0 == 170 || (_DWORD)v0 == 182 )
shiftkey_code &= 0xFFFFFFFFFFFFFFFELL;
return v0;
}

original_code:
static void
keyboard_interrupt ()
{
  W key_code;
  W ch;
  key_code = inb (0x60);
  if (driver_mode & 0x0004)
    {
      put_entry (key_code);
      set_flg (waitflag, 1);
      return;
    }
  switch (key_code)
    {
    case 0xf1:
      capskey = 0x0000;
      return;
    case 0x2a:
    case 0x36:
      shiftkey_code |= 0x0001;
      return;
    case 0x3a:
      if (capskey == 1) capskey = 0x0000;
      else capskey = 1;
      return;
    case 0x38:
      shiftkey_code |= 0x0004;
      return;
    case 0x1d:
      shiftkey_code |= 0x0002;
      return;
    case 0xb8:
      shiftkey_code &= ~0x0004;
      return;
    case 0x9d:
      shiftkey_code &= ~0x0002;
      return;
    case 0xaa:
    case 0xb6:
      shiftkey_code &= ~0x0001;
      return;
    }
  if ((key_code & 0x80))
    return;
  if (shiftkey_code & 0x0002)
    ch = get_keycode(2,key_code);
  else if (capskey)
    {
      if (shiftkey_code & 0x0001)
 ch = get_keycode(0,key_code);
      else
 ch = get_keycode(1,key_code);
    }
  else if (shiftkey_code & 0x0001)
    ch = get_keycode(0x0001,key_code);
  else
    ch = get_keycode(0,key_code);
  if (key_code == 0x3B) {
    send_switch = 1;
    rel_wai(my_tskid);
  }
  if (ch == (0))
    return;
  put_entry (ch);
  set_flg (waitflag, 1);
}

canonical_original_code:
static void keyboard_interrupt()
{
  long key_code;
  long ch;
  key_code = inb (0x60);
  if (driver_mode & 0x0004)
    {
      put_entry (key_code);
      set_flg (waitflag, 1);
      return;
    }
  switch (key_code)
    {
    case 0xf1:
      capskey = 0x0000;
      return;
    case 0x2a:
    case 0x36:
      shiftkey_code |= 0x0001;
      return;
    case 0x3a:
      if (capskey == 1) capskey = 0x0000;
      else capskey = 1;
      return;
    case 0x38:
      shiftkey_code |= 0x0004;
      return;
    case 0x1d:
      shiftkey_code |= 0x0002;
      return;
    case 0xb8:
      shiftkey_code &= ~0x0004;
      return;
    case 0x9d:
      shiftkey_code &= ~0x0002;
      return;
    case 0xaa:
    case 0xb6:
      shiftkey_code &= ~0x0001;
      return;
    }
  if ((key_code & 0x80))
    return;
  if (shiftkey_code & 0x0002)
    ch = get_keycode(2,key_code);
  else if (capskey)
    {
      if (shiftkey_code & 0x0001)
 ch = get_keycode(0,key_code);
      else
 ch = get_keycode(1,key_code);
    }
  else if (shiftkey_code & 0x0001)
    ch = get_keycode(0x0001,key_code);
  else
    ch = get_keycode(0,key_code);
  if (key_code == 0x3B) {
    send_switch = 1;
    rel_wai(my_tskid);
  }
  if (ch == (0))
    return;
  put_entry (ch);
  set_flg (waitflag, 1);
}

variable_types: ch long


beep

decompiled_code:
__int64 beep()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
int
beep ()
{
  return (0);
}

canonical_original_code:
int beep()
{
  return (0);
}

return_type: int


decompiled_code:
__int64 status_memory()
{
boot_printf("Extended Memory = %d K bytes\n", ext_mem >> 10);
boot_printf("USE Memory = %d bytes\n", last_addr);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
boot_printf("Extended Memory = %d K bytes\n", ext_mem >> 10);
boot_printf("USE Memory = %d bytes\n", last_addr);
return 0LL;
}

original_code:
int
status_memory ()
{
  extern void *last_addr;
  boot_printf ("Extended Memory = %d K bytes\n", ext_mem / 1024);
  boot_printf ("USE Memory      = %d bytes\n", last_addr);
  return (0);
}

canonical_original_code:
int status_memory()
{
  extern void *last_addr;
  boot_printf ("Extended Memory = %d K bytes\n", ext_mem / 1024);
  boot_printf ("USE Memory      = %d bytes\n", last_addr);
  return (0);
}


decompiled_code:
__int64 __fastcall print_binary(int a1)
{
int v1; // ebp
unsigned __int64 v2; // rbx
__int64 result; // rax

v1 = 8;
v2 = 128LL;
do
{
if ( (v2 & a1) != 0 )
result = boot_printf("1");
else
result = boot_printf("0");
v2 >>= 1;
--v1;
}
while ( v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // ebp
unsigned __int64 v2; // rbx
__int64 result; // rax

v1 = 8;
v2 = 128LL;
do
{
if ( (v2 & a1) != 0 )
result = boot_printf("1");
else
result = boot_printf("0");
v2 >>= 1;
--v1;
}
while ( v1 );
return result;
}

original_code:
void
print_binary (int n)
{
  ULONG mask = 0x00000080;
  int i;
  for (i = 0; i < 8; i++)
    {
      if (mask & n)
 boot_printf ("1");
      else
 boot_printf ("0");
      mask = mask >> 1;
    }
}

canonical_original_code:
void print_binary(int n)
{
  unsigned long mask = 0x00000080;
  int i;
  for (i = 0; i < 8; i++)
    {
      if (mask & n)
 boot_printf ("1");
      else
 boot_printf ("0");
      mask = mask >> 1;
    }
}

variable_types: n int

variable_types:
mask
unsigned long

variable_types: i int


panic

decompiled_code:
void __fastcall __noreturn panic(const char *a1)
{
boot_printf("panic: %s\n", a1);
while ( 1 )
;
}

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
boot_printf("panic: %s\n", a1);
while ( 1 )
;
}

original_code:
void
panic (char *s)
{
  boot_printf ("panic: %s\n", s);
  for (;;)
    ;
}

canonical_original_code:
void panic(char *s)
{
  boot_printf ("panic: %s\n", s);
  for (;;)
    ;
}

variable_types:
s
char *


cat

decompiled_code:
__int64 __fastcall cat(__int64 a1, int a2)
{
__int64 v2; // rbx

if ( a2 <= 0 )
return 0LL;
v2 = a1;
do
{
boot_printf("%c", v2);
v2 += 2LL;
}
while ( v2 != a1 + 2LL * ((unsigned int)(a2 - 1) >> 1) + 2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
__int64 v2; // rbx

if ( a2 <= 0 )
return 0LL;
v2 = a1;
do
{
boot_printf("%c", v2);
v2 += 2LL;
}
while ( v2 != a1 + 2LL * ((unsigned int)(a2 - 1) >> 1) + 2 );
return 0LL;
}

original_code:
int
cat (char *buf, int size)
{
  int i;
  for (i = 0; i < size; i += 2)
    {
      boot_printf ("%c", &buf[i]);
    }
  return (0);
}

canonical_original_code:
int cat(char *buf, int size)
{
  int i;
  for (i = 0; i < size; i += 2)
    {
      boot_printf ("%c", &buf[i]);
    }
  return (0);
}

variable_types:
buf
char *

variable_types: size int


decompiled_code:
__int64 __fastcall load_module(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6)
{
int v7; // ebx
unsigned __int64 v10; // rdx
unsigned __int64 v11; // rcx
__int64 result; // rax
__int64 v13; // [rsp+0h] [rbp-438h] BYREF
__int64 v14; // [rsp+8h] [rbp-430h]

v7 = a4;
sfs_read_file(a1, a2, a3, a4, 40LL, &v13);
v10 = (unsigned __int16)v13 - 204LL;
if ( v10 <= 0x3F && (v11 = 0x9800000000000001LL, _bittest64((const __int64 *)&v11, v10)) )
{
if ( a6 )
{
if ( (unsigned __int16)v13 != 267LL && (unsigned __int16)v13 != 264LL )
return 4294967286LL;
}
else
{
boot_printf("[%s]\n", (const char *)(a5 + 24));
boot_printf(
"Module: exec type = 0x%x, Text size = %d, Data size = %d\n",
(unsigned __int16)v13,
(unsigned int)v14,
HIDWORD(v14));
if ( (unsigned __int16)v13 != 267LL && (unsigned __int16)v13 != 264LL )
{
boot_printf("I don't know how to read a.out image.(0x%x)\n", (unsigned __int16)v13);
return 4294967286LL;
}
}
result = sfs_read_file(
(unsigned int)a1,
a2,
a3,
(unsigned int)(v7 + 1024),
(unsigned int)(HIDWORD(v14) + v14),
*(unsigned int *)(a5 + 12));
if ( (_DWORD)result )
result = 4294967249LL;
}
else
{
result = 4294967286LL;
if ( !a6 )
{
boot_printf("This object is not exec format (%d).\n", a2);
result = 4294967286LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6)
{
int v7; // ebx
unsigned __int64 v10; // rdx
unsigned __int64 v11; // rcx
__int64 result; // rax
__int64 v13; // [rsp+0h] [rbp-438h] BYREF
__int64 v14; // [rsp+8h] [rbp-430h]

v7 = a4;
sfs_read_file(a1, a2, a3, a4, 40LL, &v13);
v10 = (unsigned __int16)v13 - 204LL;
if ( v10 <= 0x3F && (v11 = 0x9800000000000001LL, _bittest64((const __int64 *)&v11, v10)) )
{
if ( a6 )
{
if ( (unsigned __int16)v13 != 267LL && (unsigned __int16)v13 != 264LL )
return 4294967286LL;
}
else
{
boot_printf("[%s]\n", (const char *)(a5 + 24));
boot_printf(
"Module: exec type = 0x%x, Text size = %d, Data size = %d\n",
(unsigned __int16)v13,
(unsigned int)v14,
HIDWORD(v14));
if ( (unsigned __int16)v13 != 267LL && (unsigned __int16)v13 != 264LL )
{
boot_printf("I don't know how to read a.out image.(0x%x)\n", (unsigned __int16)v13);
return 4294967286LL;
}
}
result = sfs_read_file(
(unsigned int)a1,
a2,
a3,
(unsigned int)(v7 + 1024),
(unsigned int)(HIDWORD(v14) + v14),
*(unsigned int *)(a5 + 12));
if ( (_DWORD)result )
result = 4294967249LL;
}
else
{
result = 4294967286LL;
if ( !a6 )
{
boot_printf("This object is not exec format (%d).\n", a2);
result = 4294967286LL;
}
}
return result;
}

original_code:
int
load_module (int fd,
      struct sfs_superblock *sb,
      struct sfs_inode *ip,
      int offset,
      struct module_info *info,
      int silent)
{
  char tmp[1024];
  struct exec *exec_info;
  sfs_read_file (fd, sb, ip, offset, sizeof (struct exec), tmp);
  exec_info = (struct exec *)tmp;
  if ((((*exec_info).a_info & 0xffff) != 0407 && ((*exec_info).a_info & 0xffff) != 0410 && ((*exec_info).a_info & 0xffff) != 0413 && ((*exec_info).a_info & 0xffff) != 0314))
    {
      if (!silent) {
 boot_printf ("This object is not exec format (%d).\n", *exec_info);
      }
      return ((-10));
    }
  if (!silent)
    {
      boot_printf ("[%s]\n",info->name);
      boot_printf ("Module: exec type = 0x%x, Text size = %d, Data size = %d\n",
       ((*exec_info).a_info & 0xffff),
       exec_info->a_text,
       exec_info->a_data);
    }
  if ((((*exec_info).a_info & 0xffff) == 0413) || (((*exec_info).a_info & 0xffff) == 0410))
    {
      if (sfs_read_file (fd, sb, ip, offset + 1024, exec_info->a_text + exec_info->a_data, (char *)info->paddr))
 {
   return (-47);
 }
    }
  else
    {
      if (!silent)
 {
   boot_printf ("I don't know how to read a.out image.(0x%x)\n", ((*exec_info).a_info & 0xffff));
 }
      return (-10);
    }
  return (0);
}

canonical_original_code:
int load_module(int fd, struct sfs_superblock *sb, struct sfs_inode *ip, int offset, struct module_info *info, int silent)
{
  char tmp[1024];
  struct exec *exec_info;
  sfs_read_file (fd, sb, ip, offset, sizeof (struct exec), tmp);
  exec_info = (struct exec *)tmp;
  if ((((*exec_info).a_info & 0xffff) != 0407 && ((*exec_info).a_info & 0xffff) != 0410 && ((*exec_info).a_info & 0xffff) != 0413 && ((*exec_info).a_info & 0xffff) != 0314))
    {
      if (!silent) {
 boot_printf ("This object is not exec format (%d).\n", *exec_info);
      }
      return ((-10));
    }
  if (!silent)
    {
      boot_printf ("[%s]\n",info->name);
      boot_printf ("Module: exec type = 0x%x, Text size = %d, Data size = %d\n",
       ((*exec_info).a_info & 0xffff),
       exec_info->a_text,
       exec_info->a_data);
    }
  if ((((*exec_info).a_info & 0xffff) == 0413) || (((*exec_info).a_info & 0xffff) == 0410))
    {
      if (sfs_read_file (fd, sb, ip, offset + 1024, exec_info->a_text + exec_info->a_data, (char *)info->paddr))
 {
   return (-47);
 }
    }
  else
    {
      if (!silent)
 {
   boot_printf ("I don't know how to read a.out image.(0x%x)\n", ((*exec_info).a_info & 0xffff));
 }
      return (-10);
    }
  return (0);
}

variable_types: fd int

variable_types: struct sfs_superblock { unsigned long sfs_magic; short sfs_version_hi; short sfs_version_lo; unsigned long sfs_mountcount; short sfs_blocksize; unsigned long sfs_nblock; unsigned long sfs_freeblock; unsigned long sfs_bitmapsize; unsigned long sfs_ninode; unsigned long sfs_freeinode; unsigned long sfs_isearch; unsigned long sfs_bsearch; unsigned long sfs_datablock; } *

variable_types: struct sfs_inode { unsigned long sfs_i_index; unsigned long sfs_i_nlink; unsigned long sfs_i_size; unsigned long sfs_i_size_blk; unsigned long sfs_i_perm; unsigned long sfs_i_uid; unsigned long sfs_i_gid; unsigned long sfs_i_dev; unsigned long sfs_i_atime; unsigned long sfs_i_ctime; unsigned long sfs_i_mtime; unsigned long sfs_i_direct[70]; unsigned long sfs_i_indirect[20]; unsigned long sfs_i_dindirect[26]; unsigned long sfs_i_tindirect[1]; } *

variable_types: offset int

variable_types: struct module_info { int length; int mem_length; unsigned int vaddr; unsigned int paddr; unsigned int entry; enum module_type { kernel=0, user=1, lowlib=2, server=3, driver=4 } type; char name[-1]; } *

variable_types: silent int

variable_types:
tmp
char [1024]

variable_types: struct exec { unsigned long a_info; unsigned int a_text; unsigned int a_data; unsigned int a_bss; unsigned int a_syms; unsigned int a_entry; unsigned int a_trsize; unsigned int a_drsize; } *

user_defined_types: struct module_info { int length; int mem_length; unsigned int vaddr; unsigned int paddr; unsigned int entry; enum module_type type; char name[-1]; }


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 __fastcall multi_boot(__int64 a1, __int64 a2, __int64 a3, int a4)
{
unsigned int v5; // eax
__int64 v6; // rbp
unsigned int v7; // er12
unsigned __int64 v9; // rbx
unsigned int v11; // [rsp+1Ch] [rbp-3Ch]

if ( a4 )
{
if ( !(unsigned int)sfs_read_file(a1, a2, a3, 0LL, 1024LL, 2048LL) )
goto LABEL_3;
LABEL_10:
vga_text();
return 4294967286LL;
}
boot_printf("Multiple module boot.\n");
if ( (unsigned int)sfs_read_file((unsigned int)a1, a2, a3, 0LL, 1024LL, 2048LL) )
{
boot_printf("Couldn't read OS file.\n");
goto LABEL_10;
}
LABEL_3:
*(_DWORD *)((char *)&loc_80F + 1) = base_mem;
loc_808 = ext_mem;
*(_DWORD *)((char *)&loc_80A + 2) = real_mem;
if ( (a1 & 0x10000) != 0 )
v5 = ((unsigned __int8)a1 + 1) | 0x80010000;
else
v5 = (unsigned __int8)a1 | 0x80000000;
*(_DWORD *)((char *)&loc_80F + 5) = v5;
if ( a4 )
{
v11 = loc_828;
if ( *(int *)((char *)&loc_801 + 3) > 0 )
goto LABEL_7;
v9 = loc_828;
}
else
{
boot_printf("Module %d\n", *(unsigned int *)((char *)&loc_801 + 3));
v11 = loc_828;
if ( *(int *)((char *)&loc_801 + 3) > 0 )
{
LABEL_7:
v6 = 0LL;
v7 = 1024;
while ( 1 )
{
if ( !a4 )
boot_printf("[%d] ", (unsigned int)v6);
if ( (unsigned int)load_module((unsigned int)a1, a2, a3, v7, (v6 << 6) + 2072, a4) )
break;
v7 += *(_DWORD *)((char *)&loc_816 + 64 * (__int64)(int)v6++ + 2) + 1024;
if ( *(int *)((char *)&loc_801 + 3) <= (int)v6 )
goto LABEL_13;
}
if ( !a4 )
boot_printf("Can't load module(s)...abort.\n");
goto LABEL_10;
}
LABEL_13:
v9 = v11;
if ( !a4 )
{
boot_printf("exec_info->a_entry = 0x%x\n", v11);
goto LABEL_23;
}
}
vga_text();
LABEL_23:
((void (*)(void))v9)();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3, int a4)
{
unsigned int v5; // eax
__int64 v6; // rbp
unsigned int v7; // er12
unsigned __int64 v9; // rbx
unsigned int v11; // [rsp+1Ch] [rbp-3Ch]

if ( a4 )
{
if ( !(unsigned int)sfs_read_file(a1, a2, a3, 0LL, 1024LL, 2048LL) )
goto LABEL_3;
LABEL_10:
vga_text();
return 4294967286LL;
}
boot_printf("Multiple module boot.\n");
if ( (unsigned int)sfs_read_file((unsigned int)a1, a2, a3, 0LL, 1024LL, 2048LL) )
{
boot_printf("Couldn't read OS file.\n");
goto LABEL_10;
}
LABEL_3:
*(_DWORD *)((char *)&loc_80F + 1) = base_mem;
loc_808 = ext_mem;
*(_DWORD *)((char *)&loc_80A + 2) = real_mem;
if ( (a1 & 0x10000) != 0 )
v5 = ((unsigned __int8)a1 + 1) | 0x80010000;
else
v5 = (unsigned __int8)a1 | 0x80000000;
*(_DWORD *)((char *)&loc_80F + 5) = v5;
if ( a4 )
{
v11 = loc_828;
if ( *(int *)((char *)&loc_801 + 3) > 0 )
goto LABEL_7;
v9 = loc_828;
}
else
{
boot_printf("Module %d\n", *(unsigned int *)((char *)&loc_801 + 3));
v11 = loc_828;
if ( *(int *)((char *)&loc_801 + 3) > 0 )
{
LABEL_7:
v6 = 0LL;
v7 = 1024;
while ( 1 )
{
if ( !a4 )
boot_printf("[%d] ", (unsigned int)v6);
if ( (unsigned int)func7((unsigned int)a1, a2, a3, v7, (v6 << 6) + 2072, a4) )
break;
v7 += *(_DWORD *)((char *)&loc_816 + 64 * (__int64)(int)v6++ + 2) + 1024;
if ( *(int *)((char *)&loc_801 + 3) <= (int)v6 )
goto LABEL_13;
}
if ( !a4 )
boot_printf("Can't load module(s)...abort.\n");
goto LABEL_10;
}
LABEL_13:
v9 = v11;
if ( !a4 )
{
boot_printf("exec_info->a_entry = 0x%x\n", v11);
goto LABEL_23;
}
}
vga_text();
LABEL_23:
((void (*)(void))v9)();
return 0LL;
}

original_code:
int
multi_boot (int fd, struct sfs_superblock *sb, struct sfs_inode *ip, int silent)
{
  int i;
  int offset;
  struct boot_header *info;
  void (*entry)();
  int errno;
  if (!silent)
    boot_printf ("Multiple module boot.\n");
  info = (struct boot_header *)(0x00000800);
  errno = sfs_read_file (fd, sb, ip, 0, 1024, (char *)info);
  if (errno)
    {
      if (!silent)
 boot_printf ("Couldn't read OS file.\n");
      vga_text ();
      return ((-10));
    }
  info->machine.base_mem = base_mem;
  info->machine.ext_mem = ext_mem;
  info->machine.real_mem = real_mem;
  if (fd & 0x010000)
    {
      info->machine.rootfs = 0x80010000 | ((fd & 0xff) + 1);
    }
  else
    {
      info->machine.rootfs = 0x80000000 | (fd & 0xff);
    }
  if (!silent)
    boot_printf ("Module %d\n", info->count);
  offset = 1024;
  entry = (void (*)())(info->modules[0].entry);
  for (i = 0; i < info->count; i++)
    {
      if (!silent)
 {
   boot_printf ("[%d] ", i);
 }
      if (load_module (fd, sb, ip, offset, &(info->modules[i]), silent) != (0))
 {
   if (!silent)
     {
       boot_printf ("Can't load module(s)...abort.\n");
     }
   vga_text ();
   return ((-10));
 }
      offset += info->modules[i].length + 1024;
    }
  if (!silent) {
    boot_printf ("exec_info->a_entry = 0x%x\n", entry);
  }
  if (silent)
    {
      vga_text ();
    }
  (*entry)();
  return (0);
}

canonical_original_code:
int multi_boot(int fd, struct sfs_superblock *sb, struct sfs_inode *ip, int silent)
{
  int i;
  int offset;
  struct boot_header *info;
  void (*entry)();
  int errno;
  if (!silent)
    boot_printf ("Multiple module boot.\n");
  info = (struct boot_header *)(0x00000800);
  errno = sfs_read_file (fd, sb, ip, 0, 1024, (char *)info);
  if (errno)
    {
      if (!silent)
 boot_printf ("Couldn't read OS file.\n");
      vga_text ();
      return ((-10));
    }
  info->machine.base_mem = base_mem;
  info->machine.ext_mem = ext_mem;
  info->machine.real_mem = real_mem;
  if (fd & 0x010000)
    {
      info->machine.rootfs = 0x80010000 | ((fd & 0xff) + 1);
    }
  else
    {
      info->machine.rootfs = 0x80000000 | (fd & 0xff);
    }
  if (!silent)
    boot_printf ("Module %d\n", info->count);
  offset = 1024;
  entry = (void (*)())(info->modules[0].entry);
  for (i = 0; i < info->count; i++)
    {
      if (!silent)
 {
   boot_printf ("[%d] ", i);
 }
      if (load_module (fd, sb, ip, offset, &(info->modules[i]), silent) != (0))
 {
   if (!silent)
     {
       boot_printf ("Can't load module(s)...abort.\n");
     }
   vga_text ();
   return ((-10));
 }
      offset += info->modules[i].length + 1024;
    }
  if (!silent) {
    boot_printf ("exec_info->a_entry = 0x%x\n", entry);
  }
  if (silent)
    {
      vga_text ();
    }
  (*entry)();
  return (0);
}

variable_types: struct boot_header { unsigned char cookie; int count; struct machine_info { unsigned int ext_mem; unsigned int real_mem; unsigned int base_mem; unsigned int rootfs; } machine; struct module_info { int length; int mem_length; unsigned int vaddr; unsigned int paddr; unsigned int entry; enum module_type { kernel=0, user=1, lowlib=2, server=3, driver=4 } type; char name[-1]; } modules[]; } *

variable_types:
entry
void (*)()

variable_types: errno int

user_defined_types: struct sfs_superblock { unsigned long sfs_magic; short sfs_version_hi; short sfs_version_lo; unsigned long sfs_mountcount; short sfs_blocksize; unsigned long sfs_nblock; unsigned long sfs_freeblock; unsigned long sfs_bitmapsize; unsigned long sfs_ninode; unsigned long sfs_freeinode; unsigned long sfs_isearch; unsigned long sfs_bsearch; unsigned long sfs_datablock; }

user_defined_types: struct sfs_inode { unsigned long sfs_i_index; unsigned long sfs_i_nlink; unsigned long sfs_i_size; unsigned long sfs_i_size_blk; unsigned long sfs_i_perm; unsigned long sfs_i_uid; unsigned long sfs_i_gid; unsigned long sfs_i_dev; unsigned long sfs_i_atime; unsigned long sfs_i_ctime; unsigned long sfs_i_mtime; unsigned long sfs_i_direct[70]; unsigned long sfs_i_indirect[20]; unsigned long sfs_i_dindirect[26]; unsigned long sfs_i_tindirect[1]; }

user_defined_types: struct boot_header { unsigned char cookie; int count; struct machine_info machine; struct module_info modules[]; }


decompiled_code:
__int64 __fastcall read_single_module(unsigned int a1, char *a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rdx
unsigned int v4; // ebx
char *v5; // rbp
__int64 v6; // rbp
__int64 v8; // [rsp+0h] [rbp-828h] BYREF
__int64 v9; // [rsp+8h] [rbp-820h]
char src[1064]; // [rsp+400h] [rbp-428h] BYREF

fd_read(0LL, a1, &v8);
v2 = (unsigned __int16)v8 - 204LL;
if ( v2 > 0x3F || (v3 = 0x9800000000000001LL, !_bittest64((const __int64 *)&v3, v2)) )
{
boot_printf("This object is not exec format (%d).\n", (unsigned __int16)v8);
boot_printf("block number: %d\n", a1);
while ( 1 )
;
}
if ( (unsigned __int16)v8 != 267LL && (unsigned __int16)v8 != 264LL )
{
boot_printf("I don't know how to read a.out image.(0x%x)\n", (unsigned __int16)v8);
while ( 1 )
;
}
v4 = a1 + 1;
boot_printf(
"blocks: text: %d, data: %d, paddr: 0x%x\n",
(((_DWORD)v9 + 4095) & 0xFFFFF000) >> 10,
((HIDWORD(v9) + 4095) & 0xFFFFF000) >> 10,
a2);
if ( (((_DWORD)v9 + 4095) & 0xFFFFF000) > 0x3FF )
{
v5 = a2;
do
{
boot_printf(".");
fd_read(0LL, v4, src);
bcopy(src, v5, 0x400uLL);
++v4;
v5 += 1024;
}
while ( (((_DWORD)v9 + 4095) & 0xFFFFF000) >> 10 > v4 + ~a1 );
}
if ( HIDWORD(v9) )
{
v6 = 0LL;
do
{
boot_printf(",");
fd_read(0LL, v4 + (unsigned int)v6, src);
bcopy(src, &a2[1024 * v6++ + (((_DWORD)v9 + 4095) & 0xFFFFF000)], 0x400uLL);
}
while ( ((HIDWORD(v9) + 4095) & 0xFFFFF000) >> 10 >= (unsigned int)v6 );
}
boot_printf("\n");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, char *a2)
{
unsigned __int64 v2; // rax
unsigned __int64 v3; // rdx
unsigned int v4; // ebx
char *v5; // rbp
__int64 v6; // rbp
__int64 v8; // [rsp+0h] [rbp-828h] BYREF
__int64 v9; // [rsp+8h] [rbp-820h]
char src[1064]; // [rsp+400h] [rbp-428h] BYREF

fd_read(0LL, a1, &v8);
v2 = (unsigned __int16)v8 - 204LL;
if ( v2 > 0x3F || (v3 = 0x9800000000000001LL, !_bittest64((const __int64 *)&v3, v2)) )
{
boot_printf("This object is not exec format (%d).\n", (unsigned __int16)v8);
boot_printf("block number: %d\n", a1);
while ( 1 )
;
}
if ( (unsigned __int16)v8 != 267LL && (unsigned __int16)v8 != 264LL )
{
boot_printf("I don't know how to read a.out image.(0x%x)\n", (unsigned __int16)v8);
while ( 1 )
;
}
v4 = a1 + 1;
boot_printf(
"blocks: text: %d, data: %d, paddr: 0x%x\n",
(((_DWORD)v9 + 4095) & 0xFFFFF000) >> 10,
((HIDWORD(v9) + 4095) & 0xFFFFF000) >> 10,
a2);
if ( (((_DWORD)v9 + 4095) & 0xFFFFF000) > 0x3FF )
{
v5 = a2;
do
{
boot_printf(".");
fd_read(0LL, v4, src);
bcopy(src, v5, 0x400uLL);
++v4;
v5 += 1024;
}
while ( (((_DWORD)v9 + 4095) & 0xFFFFF000) >> 10 > v4 + ~a1 );
}
if ( HIDWORD(v9) )
{
v6 = 0LL;
do
{
boot_printf(",");
fd_read(0LL, v4 + (unsigned int)v6, src);
bcopy(src, &a2[1024 * v6++ + (((_DWORD)v9 + 4095) & 0xFFFFF000)], 0x400uLL);
}
while ( ((HIDWORD(v9) + 4095) & 0xFFFFF000) >> 10 >= (unsigned int)v6 );
}
boot_printf("\n");
return 0LL;
}

original_code:
int
read_single_module (int start_block, void *paddr, struct module_info *info)
{
  char buf[1024];
  char tmp[1024];
  int i, j;
  int bn;
  struct exec *exec_info;
  bn = start_block;
  fd_read (0, bn, (BYTE *)tmp);
  exec_info = (struct exec *)tmp;
  if ((((*exec_info).a_info & 0xffff) != 0407 && ((*exec_info).a_info & 0xffff) != 0410 && ((*exec_info).a_info & 0xffff) != 0413 && ((*exec_info).a_info & 0xffff) != 0314))
    {
      boot_printf ("This object is not exec format (%d).\n", *exec_info);
      boot_printf ("block number: %d\n", bn);
      for (;;)
 ;
    }
  if ((((*exec_info).a_info & 0xffff) == 0413) || (((*exec_info).a_info & 0xffff) == 0410))
    {
      bn += 1;
      boot_printf ("blocks: text: %d, data: %d, paddr: 0x%x\n",
       (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096)) / 1024),
       (((((exec_info->a_data) + ((4096) - 1)) / (4096)) * (4096)) / 1024),
       paddr);
      for (i = 0;
    i < (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096))
   / 1024);
    i++, bn++)
 {
   boot_printf (".");
   fd_read (0, bn, (BYTE*)buf);
   bcopy (buf,
   (char *)(paddr + i * 1024),
   1024);
 }
      if (exec_info->a_data > 0)
 {
   for (j = 0;
        j <= (((((exec_info->a_data) + ((4096) - 1)) / (4096)) * (4096))
       / 1024);
        j++ , bn++)
     {
       boot_printf (",");
       fd_read (0, bn, buf);
       bcopy (buf,
       (char *)(paddr
         + (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096)))
         + j * 1024),
       1024);
     }
 }
    }
  else
    {
      boot_printf ("I don't know how to read a.out image.(0x%x)\n", ((*exec_info).a_info & 0xffff));
      for (;;)
 ;
    }
  boot_printf ("\n");
  return (0);
}

canonical_original_code:
int read_single_module(int start_block, void *paddr, struct module_info *info)
{
  char buf[1024];
  char tmp[1024];
  int i; int j;
  int bn;
  struct exec *exec_info;
  bn = start_block;
  fd_read (0, bn, (unsigned char *)tmp);
  exec_info = (struct exec *)tmp;
  if ((((*exec_info).a_info & 0xffff) != 0407 && ((*exec_info).a_info & 0xffff) != 0410 && ((*exec_info).a_info & 0xffff) != 0413 && ((*exec_info).a_info & 0xffff) != 0314))
    {
      boot_printf ("This object is not exec format (%d).\n", *exec_info);
      boot_printf ("block number: %d\n", bn);
      for (;;)
 ;
    }
  if ((((*exec_info).a_info & 0xffff) == 0413) || (((*exec_info).a_info & 0xffff) == 0410))
    {
      bn += 1;
      boot_printf ("blocks: text: %d, data: %d, paddr: 0x%x\n",
       (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096)) / 1024),
       (((((exec_info->a_data) + ((4096) - 1)) / (4096)) * (4096)) / 1024),
       paddr);
      for (i = 0;
    i < (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096))
   / 1024);
    i++, bn++)
 {
   boot_printf (".");
   fd_read (0, bn, (unsigned char *)buf);
   bcopy (buf,
   (char *)(paddr + i * 1024),
   1024);
 }
      if (exec_info->a_data > 0)
 {
   for (j = 0;
        j <= (((((exec_info->a_data) + ((4096) - 1)) / (4096)) * (4096))
       / 1024);
        j++ , bn++)
     {
       boot_printf (",");
       fd_read (0, bn, buf);
       bcopy (buf,
       (char *)(paddr
         + (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096)))
         + j * 1024),
       1024);
     }
 }
    }
  else
    {
      boot_printf ("I don't know how to read a.out image.(0x%x)\n", ((*exec_info).a_info & 0xffff));
      for (;;)
 ;
    }
  boot_printf ("\n");
  return (0);
}

variable_types:
paddr
void *

variable_types:
buf
char [1024]

variable_types: j int

variable_types: bn int

user_defined_types: struct exec { unsigned long a_info; unsigned int a_text; unsigned int a_data; unsigned int a_bss; unsigned int a_syms; unsigned int a_entry; unsigned int a_trsize; unsigned int a_drsize; }

user_defined_types: enum module_type { kernel=0, user=1, lowlib=2, server=3, driver=4 }


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 read_multi_module()
{
__int64 v0; // rbx
unsigned int v1; // ebp

boot_printf("Multiple module boot.\n");
fd_read(0LL, 0LL, 2048LL);
*(_DWORD *)((char *)&loc_80F + 1) = base_mem;
loc_808 = ext_mem;
*(_DWORD *)((char *)&loc_80A + 2) = real_mem;
*(_DWORD *)((char *)&loc_80F + 5) = -1;
boot_printf("Module %d\n", *(unsigned int *)((char *)&loc_801 + 3));
if ( *(int *)((char *)&loc_801 + 3) > 0 )
{
v0 = 0LL;
v1 = 1;
do
{
boot_printf("[%d][%s]\n", (unsigned int)v0, (const char *)((v0 << 6) + 2096));
read_single_module(v1, (char *)*((unsigned int *)&loc_824 + 16 * (__int64)(int)v0));
v1 += *(_DWORD *)((char *)&loc_816 + 64 * (__int64)(int)v0++ + 2) / 1024 + 1;
}
while ( *(int *)((char *)&loc_801 + 3) > (int)v0 );
}
boot_printf("load done.\n");
boot_printf("exec_info->a_entry = 0x%x\n", loc_828);
stop_motor(0LL);
((void (*)(void))loc_828)();
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rbx
unsigned int v1; // ebp

boot_printf("Multiple module boot.\n");
fd_read(0LL, 0LL, 2048LL);
*(_DWORD *)((char *)&loc_80F + 1) = base_mem;
loc_808 = ext_mem;
*(_DWORD *)((char *)&loc_80A + 2) = real_mem;
*(_DWORD *)((char *)&loc_80F + 5) = -1;
boot_printf("Module %d\n", *(unsigned int *)((char *)&loc_801 + 3));
if ( *(int *)((char *)&loc_801 + 3) > 0 )
{
v0 = 0LL;
v1 = 1;
do
{
boot_printf("[%d][%s]\n", (unsigned int)v0, (const char *)((v0 << 6) + 2096));
func9(v1, (char *)*((unsigned int *)&loc_824 + 16 * (__int64)(int)v0));
v1 += *(_DWORD *)((char *)&loc_816 + 64 * (__int64)(int)v0++ + 2) / 1024 + 1;
}
while ( *(int *)((char *)&loc_801 + 3) > (int)v0 );
}
boot_printf("load done.\n");
boot_printf("exec_info->a_entry = 0x%x\n", loc_828);
stop_motor(0LL);
((void (*)(void))loc_828)();
return 0LL;
}

original_code:
int
read_multi_module ()
{
  int i;
  int bn;
  struct boot_header *info;
  void (*entry)();
  boot_printf ("Multiple module boot.\n");
  info = (struct boot_header *)(0x00000800);
  fd_read (0, 0, (BYTE *)info);
  info->machine.base_mem = base_mem;
  info->machine.ext_mem = ext_mem;
  info->machine.real_mem = real_mem;
  info->machine.rootfs = 0xffffffff;
  boot_printf ("Module %d\n", info->count);
  bn = 1;
  entry = (void (*)())(info->modules[0].entry);
  for (i = 0; i < info->count; i++)
    {
      boot_printf ("[%d][%s]\n", i, info->modules[i].name);
      read_single_module (bn, (void *)info->modules[i].paddr, &(info->modules[i]));
      bn += (info->modules[i].length / 1024 + 1);
    }
  boot_printf ("load done.\n");
  boot_printf ("exec_info->a_entry = 0x%x\n", entry);
  stop_motor(0);
  (*entry)();
  return (0);
}

canonical_original_code:
int read_multi_module()
{
  int i;
  int bn;
  struct boot_header *info;
  void (*entry)();
  boot_printf ("Multiple module boot.\n");
  info = (struct boot_header *)(0x00000800);
  fd_read (0, 0, (unsigned char *)info);
  info->machine.base_mem = base_mem;
  info->machine.ext_mem = ext_mem;
  info->machine.real_mem = real_mem;
  info->machine.rootfs = 0xffffffff;
  boot_printf ("Module %d\n", info->count);
  bn = 1;
  entry = (void (*)())(info->modules[0].entry);
  for (i = 0; i < info->count; i++)
    {
      boot_printf ("[%d][%s]\n", i, info->modules[i].name);
      read_single_module (bn, (void *)info->modules[i].paddr, &(info->modules[i]));
      bn += (info->modules[i].length / 1024 + 1);
    }
  boot_printf ("load done.\n");
  boot_printf ("exec_info->a_entry = 0x%x\n", entry);
  stop_motor(0);
  (*entry)();
  return (0);
}

variable_types: i int

user_defined_types: struct machine_info { unsigned int ext_mem; unsigned int real_mem; unsigned int base_mem; unsigned int rootfs; }


decompiled_code:
// write access to const memory has been detected, the output may be wrong!
__int64 read_a_out()
{
unsigned __int64 v0; // rax
unsigned __int64 v1; // rdx
__int64 v2; // rsi
unsigned __int64 v3; // rbx
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // edx
unsigned int v7; // ebp
__int64 v8; // rbx
__int64 v10; // rax
unsigned __int16 v11; // [rsp+0h] [rbp-828h] BYREF
unsigned int v12; // [rsp+8h] [rbp-820h]
unsigned int v13; // [rsp+Ch] [rbp-81Ch]
unsigned int v14; // [rsp+10h] [rbp-818h]
unsigned int v15; // [rsp+18h] [rbp-810h]
char src[1064]; // [rsp+400h] [rbp-428h] BYREF

fd_read(0LL, 0LL, &v11);
v0 = v11 - 204LL;
if ( v0 <= 0x3F && (v1 = 0x9800000000000001LL, _bittest64((const __int64 *)&v1, v0)) )
{
boot_printf("*** Single Module boot. ***\n");
boot_printf("text size = %d\n", v12);
boot_printf("data size = %d\n", v13);
boot_printf(" bss size = %d\n", v14);
*(_DWORD *)((char *)&loc_80F + 1) = base_mem;
loc_808 = ext_mem;
*(_DWORD *)((char *)&loc_80A + 2) = real_mem;
*(_DWORD *)((char *)&loc_80F + 5) = -1;
if ( v11 == 267LL )
{
boot_printf("demand loading object. (page size alignemnt)\n");
boot_printf("load address = 0x%x\n", 2147614720LL);
v4 = -2147352576;
v5 = 1;
do
{
putchar(46);
fd_read(0LL, v5, src);
bcopy(src, (void *)v4, 0x400uLL);
v6 = v5++;
v4 += 1024;
}
while ( ((v12 + 4095) & 0xFFFFF000) >> 10 >= v6 );
boot_printf("\nText region is read.\n");
v7 = 0;
do
{
putchar(46);
fd_read(0LL, v5, src);
bcopy(src, (void *)((v5 << 10) - 2147353600), 0x400uLL);
++v7;
++v5;
}
while ( v7 <= ((v13 + 4095) & 0xFFFFF000) >> 10 );
}
else
{
v2 = 2147614720LL;
if ( v11 != 204LL )
v2 = 2147614680LL;
boot_printf("load address = 0x%x\n", v2);
v3 = 0LL;
do
{
putchar(46);
while ( (unsigned int)fd_read(0LL, (unsigned int)v3, src) )
;
v10 = 2147613696LL;
if ( v11 != 267LL )
{
v10 = 2147614680LL;
if ( v11 == 204LL )
v10 = 2147614720LL;
}
bcopy(src, (void *)(v10 + (v3++ << 10)), 0x400uLL);
}
while ( (((unsigned __int64)(((v12 + 1023) & 0xFFFFFC00) + ((v13 + 1023) & 0xFFFFFC00)) + 1024) >> 10) + 10 >= v3 );
}
v8 = v15;
boot_printf("load done.\n");
boot_printf("exec_info->a_entry = 0x%x\n", v8);
((void (*)(void))v15)();
}
else
{
boot_printf("This object is not exec format.\n");
}
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned __int64 v0; // rax
unsigned __int64 v1; // rdx
__int64 v2; // rsi
unsigned __int64 v3; // rbx
unsigned int v4; // ebp
unsigned int v5; // ebx
unsigned int v6; // edx
unsigned int v7; // ebp
__int64 v8; // rbx
__int64 v10; // rax
unsigned __int16 v11; // [rsp+0h] [rbp-828h] BYREF
unsigned int v12; // [rsp+8h] [rbp-820h]
unsigned int v13; // [rsp+Ch] [rbp-81Ch]
unsigned int v14; // [rsp+10h] [rbp-818h]
unsigned int v15; // [rsp+18h] [rbp-810h]
char src[1064]; // [rsp+400h] [rbp-428h] BYREF

fd_read(0LL, 0LL, &v11);
v0 = v11 - 204LL;
if ( v0 <= 0x3F && (v1 = 0x9800000000000001LL, _bittest64((const __int64 *)&v1, v0)) )
{
boot_printf("*** Single Module boot. ***\n");
boot_printf("text size = %d\n", v12);
boot_printf("data size = %d\n", v13);
boot_printf(" bss size = %d\n", v14);
*(_DWORD *)((char *)&loc_80F + 1) = base_mem;
loc_808 = ext_mem;
*(_DWORD *)((char *)&loc_80A + 2) = real_mem;
*(_DWORD *)((char *)&loc_80F + 5) = -1;
if ( v11 == 267LL )
{
boot_printf("demand loading object. (page size alignemnt)\n");
boot_printf("load address = 0x%x\n", 2147614720LL);
v4 = -2147352576;
v5 = 1;
do
{
putchar(46);
fd_read(0LL, v5, src);
bcopy(src, (void *)v4, 0x400uLL);
v6 = v5++;
v4 += 1024;
}
while ( ((v12 + 4095) & 0xFFFFF000) >> 10 >= v6 );
boot_printf("\nText region is read.\n");
v7 = 0;
do
{
putchar(46);
fd_read(0LL, v5, src);
bcopy(src, (void *)((v5 << 10) - 2147353600), 0x400uLL);
++v7;
++v5;
}
while ( v7 <= ((v13 + 4095) & 0xFFFFF000) >> 10 );
}
else
{
v2 = 2147614720LL;
if ( v11 != 204LL )
v2 = 2147614680LL;
boot_printf("load address = 0x%x\n", v2);
v3 = 0LL;
do
{
putchar(46);
while ( (unsigned int)fd_read(0LL, (unsigned int)v3, src) )
;
v10 = 2147613696LL;
if ( v11 != 267LL )
{
v10 = 2147614680LL;
if ( v11 == 204LL )
v10 = 2147614720LL;
}
bcopy(src, (void *)(v10 + (v3++ << 10)), 0x400uLL);
}
while ( (((unsigned __int64)(((v12 + 1023) & 0xFFFFFC00) + ((v13 + 1023) & 0xFFFFFC00)) + 1024) >> 10) + 10 >= v3 );
}
v8 = v15;
boot_printf("load done.\n");
boot_printf("exec_info->a_entry = 0x%x\n", v8);
((void (*)(void))v15)();
}
else
{
boot_printf("This object is not exec format.\n");
}
return 0LL;
}

original_code:
int
read_a_out ()
{
  char buf[1024];
  char tmp[1024];
  int *p;
  int i;
  int bn;
  void (*func)();
  struct exec *exec_info;
  int errno;
  struct boot_header *info;
  fd_read (0, 0, tmp);
  exec_info = (struct exec *)tmp;
  if ((((*exec_info).a_info & 0xffff) != 0407 && ((*exec_info).a_info & 0xffff) != 0410 && ((*exec_info).a_info & 0xffff) != 0413 && ((*exec_info).a_info & 0xffff) != 0314))
    {
      boot_printf ("This object is not exec format.\n");
      return (0);
    }
  boot_printf ("*** Single Module boot. ***\n");
  boot_printf ("text size = %d\n", exec_info->a_text);
  boot_printf ("data size = %d\n", exec_info->a_data);
  boot_printf (" bss size = %d\n", exec_info->a_bss);
  info = (struct boot_header *)(0x00000800);
  info->machine.base_mem = base_mem;
  info->machine.ext_mem = ext_mem;
  info->machine.real_mem = real_mem;
  info->machine.rootfs = 0xffffffff;
  if (((*exec_info).a_info & 0xffff) == 0413)
    {
      boot_printf ("demand loading object. (page size alignemnt)\n");
      boot_printf ("load address = 0x%x\n", 0x80020000);
      bn = 1;
      for (i = 0;
    i <= (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096))
   / 1024);
    i++, bn++)
 {
   putchar ('.');
   fd_read (0, bn, buf);
   bcopy (buf,
   (char *)(0x80020000 + ((bn - 1) * 1024)),
    1024);
 }
      boot_printf ("\nText region is read.\n");
      for (i = 0;
    i <= (((((exec_info->a_data) + ((4096) - 1)) / (4096)) * (4096))
   / 1024);
    i++, bn++)
 {
   putchar ('.');
   fd_read (0, bn, buf);
   bcopy (buf,
   (char *)(0x80020000 + ((bn - 1) * 1024)),
   1024);
 }
    }
  else
    {
      boot_printf ("load address = 0x%x\n", (0x80020000 - (((*exec_info).a_info & 0xffff) == 0413 ? (1024 - sizeof (struct exec)) + sizeof (struct exec) : (((*exec_info).a_info & 0xffff) == 0314 ? 0 : sizeof (struct exec)))));
      for (i = 0;
    i <= ((((((exec_info->a_text) + ((1024) - 1)) / (1024)) * (1024))
       + ((((exec_info->a_data) + ((1024) - 1)) / (1024)) * (1024))
       + ((((sizeof (struct exec)) + ((1024) - 1)) / (1024)) * (1024))) / 1024 + 10);
    i++)
 {
   putchar ('.');
retry:
   errno = fd_read (0, i, buf);
   if (errno != (0))
     {
       goto retry;
     }
   bcopy (buf,
   (char *)((0x80020000 - (((*exec_info).a_info & 0xffff) == 0413 ? (1024 - sizeof (struct exec)) + sizeof (struct exec) : (((*exec_info).a_info & 0xffff) == 0314 ? 0 : sizeof (struct exec))))
     + (i * 1024)),
   1024);
 }
    }
  p = (int *)(exec_info->a_entry);
  boot_printf ("load done.\n");
  boot_printf ("exec_info->a_entry = 0x%x\n", p);
  func = (void (*)())(exec_info->a_entry);
  (*func)();
  return (0);
}

canonical_original_code:
int read_a_out()
{
  char buf[1024];
  char tmp[1024];
  int *p;
  int i;
  int bn;
  void (*func)();
  struct exec *exec_info;
  int errno;
  struct boot_header *info;
  fd_read (0, 0, tmp);
  exec_info = (struct exec *)tmp;
  if ((((*exec_info).a_info & 0xffff) != 0407 && ((*exec_info).a_info & 0xffff) != 0410 && ((*exec_info).a_info & 0xffff) != 0413 && ((*exec_info).a_info & 0xffff) != 0314))
    {
      boot_printf ("This object is not exec format.\n");
      return (0);
    }
  boot_printf ("*** Single Module boot. ***\n");
  boot_printf ("text size = %d\n", exec_info->a_text);
  boot_printf ("data size = %d\n", exec_info->a_data);
  boot_printf (" bss size = %d\n", exec_info->a_bss);
  info = (struct boot_header *)(0x00000800);
  info->machine.base_mem = base_mem;
  info->machine.ext_mem = ext_mem;
  info->machine.real_mem = real_mem;
  info->machine.rootfs = 0xffffffff;
  if (((*exec_info).a_info & 0xffff) == 0413)
    {
      boot_printf ("demand loading object. (page size alignemnt)\n");
      boot_printf ("load address = 0x%x\n", 0x80020000);
      bn = 1;
      for (i = 0;
    i <= (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096))
   / 1024);
    i++, bn++)
 {
   putchar ('.');
   fd_read (0, bn, buf);
   bcopy (buf,
   (char *)(0x80020000 + ((bn - 1) * 1024)),
    1024);
 }
      boot_printf ("\nText region is read.\n");
      for (i = 0;
    i <= (((((exec_info->a_data) + ((4096) - 1)) / (4096)) * (4096))
   / 1024);
    i++, bn++)
 {
   putchar ('.');
   fd_read (0, bn, buf);
   bcopy (buf,
   (char *)(0x80020000 + ((bn - 1) * 1024)),
   1024);
 }
    }
  else
    {
      boot_printf ("load address = 0x%x\n", (0x80020000 - (((*exec_info).a_info & 0xffff) == 0413 ? (1024 - sizeof (struct exec)) + sizeof (struct exec) : (((*exec_info).a_info & 0xffff) == 0314 ? 0 : sizeof (struct exec)))));
      for (i = 0;
    i <= ((((((exec_info->a_text) + ((1024) - 1)) / (1024)) * (1024))
       + ((((exec_info->a_data) + ((1024) - 1)) / (1024)) * (1024))
       + ((((sizeof (struct exec)) + ((1024) - 1)) / (1024)) * (1024))) / 1024 + 10);
    i++)
 {
   putchar ('.');
retry:
   errno = fd_read (0, i, buf);
   if (errno != (0))
     {
       goto retry;
     }
   bcopy (buf,
   (char *)((0x80020000 - (((*exec_info).a_info & 0xffff) == 0413 ? (1024 - sizeof (struct exec)) + sizeof (struct exec) : (((*exec_info).a_info & 0xffff) == 0314 ? 0 : sizeof (struct exec))))
     + (i * 1024)),
   1024);
 }
    }
  p = (int *)(exec_info->a_entry);
  boot_printf ("load done.\n");
  boot_printf ("exec_info->a_entry = 0x%x\n", p);
  func = (void (*)())(exec_info->a_entry);
  (*func)();
  return (0);
}

variable_types:
p
int *

variable_types:
func
void (*)()


banner

decompiled_code:
__int64 banner()
{
boot_printf("BTRON/386 2nd BOOT Version %d.%d\n\n", 0LL, 2LL);
boot_printf("RCS Version : %s\n", rcsid);
boot_printf("START AS 32 BIT MODE.\n");
return boot_printf("Welcome BTRON/386.\n");
}

canonical_decompiled_code:
__int64 func3()
{
boot_printf("BTRON/386 2nd BOOT Version %d.%d\n\n", 0LL, 2LL);
boot_printf("RCS Version : %s\n", rcsid);
boot_printf("START AS 32 BIT MODE.\n");
return boot_printf("Welcome BTRON/386.\n");
}

original_code:
void
banner (void)
{
  boot_printf ("BTRON/386 2nd BOOT Version %d.%d\n\n", 0, 2);
  boot_printf ("RCS Version : %s\n", rcsid);
  boot_printf ("START AS 32 BIT MODE.\n");
  boot_printf ("Welcome BTRON/386.\n");
}

canonical_original_code:
void banner()
{
  boot_printf ("BTRON/386 2nd BOOT Version %d.%d\n\n", 0, 2);
  boot_printf ("RCS Version : %s\n", rcsid);
  boot_printf ("START AS 32 BIT MODE.\n");
  boot_printf ("Welcome BTRON/386.\n");
}


decompiled_code:
__int64 __fastcall set_interrupt_handler(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v4; // [rsp+0h] [rbp-18h] BYREF
__int64 v5; // [rsp+8h] [rbp-10h]

v4 = 3;
v5 = a3;
result = def_int(a2, &v4);
if ( (_DWORD)result )
return 4294967195LL;
device = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
int v4; // [rsp+0h] [rbp-18h] BYREF
__int64 v5; // [rsp+8h] [rbp-10h]

v4 = 3;
v5 = a3;
result = def_int(a2, &v4);
if ( (_DWORD)result )
return 4294967195LL;
device = a1;
return result;
}

original_code:
ER
set_interrupt_handler (struct ne2000_device *dev, W intno, FP handler)
{
  T_DINT pk_dint;
  ER errno;
  pk_dint.intatr = (3);
  pk_dint.inthdr = handler;
  errno = def_int (intno, &pk_dint);
  if (errno != (0))
    {
      return ((-101));
    }
  device = dev;
  return ((0));
}

canonical_original_code:
int set_interrupt_handler(struct ne2000_device *dev, long intno, void (*handler)())
{
  struct t_dint pk_dint;
  int errno;
  pk_dint.intatr = (3);
  pk_dint.inthdr = handler;
  errno = def_int (intno, &pk_dint);
  if (errno != (0))
    {
      return ((-101));
    }
  device = dev;
  return ((0));
}

variable_types: struct ne2000_device { unsigned long io_base; unsigned char sa_prom[32]; char tx_busy; char tx_use; char tx_new; char tx_next; char tx_len[2]; char rx_next; char word_access; unsigned long tx_count; unsigned long tx_error; unsigned long collision; unsigned long rx_count; unsigned long rx_error; unsigned char intr_number; void (*intr_handler)(); } *

variable_types: intno long

variable_types:
handler
void (*)()

variable_types: struct t_dint { unsigned int intatr; void (*inthdr)(); }


decompiled_code:
unsigned __int8 ne2000_interrupt_handler()
{
unsigned __int8 result; // al
unsigned __int8 v1; // bl
unsigned __int8 v2; // bp
int v3; // eax
int v4; // edx
__int64 v5; // rax

dbg_printf("NE2000: catch interrupt\n");
select_page0(device);
result = inb(*(_WORD *)device + 7);
if ( result )
{
v1 = result;
v2 = result;
outb(*(_BYTE *)device + 7, result);
if ( (v2 & 0xA) != 0 )
{
LOBYTE(v3) = inb(*(_WORD *)device + 5);
v4 = v3;
v5 = device;
*(_QWORD *)(device + 64) = v4;
if ( (v1 & 2) != 0 )
{
++*(_QWORD *)(v5 + 48);
}
else if ( (v1 & 8) != 0 )
{
++*(_QWORD *)(v5 + 56);
}
*(_BYTE *)(v5 + 40) = 0;
--*(_BYTE *)(v5 + 41);
}
if ( (v2 & 5) != 0 )
{
if ( (v1 & 5) != 0 || (v1 & 0x10) == 0 )
goto LABEL_14;
}
else if ( (v1 & 0x10) == 0 || (v1 & 5) != 0 )
{
goto LABEL_14;
}
select_page0(device);
init_device(device);
LABEL_14:
result = select_page0(device);
if ( (v1 & 0x20) != 0 )
{
inb(*(_WORD *)device + 13);
inb(*(_WORD *)device + 14);
result = inb(*(_WORD *)device + 15);
}
}
return result;
}

canonical_decompiled_code:
unsigned __int8 func1()
{
unsigned __int8 result; // al
unsigned __int8 v1; // bl
unsigned __int8 v2; // bp
int v3; // eax
int v4; // edx
__int64 v5; // rax

dbg_printf("NE2000: catch interrupt\n");
select_page0(device);
result = inb(*(_WORD *)device + 7);
if ( result )
{
v1 = result;
v2 = result;
outb(*(_BYTE *)device + 7, result);
if ( (v2 & 0xA) != 0 )
{
LOBYTE(v3) = inb(*(_WORD *)device + 5);
v4 = v3;
v5 = device;
*(_QWORD *)(device + 64) = v4;
if ( (v1 & 2) != 0 )
{
++*(_QWORD *)(v5 + 48);
}
else if ( (v1 & 8) != 0 )
{
++*(_QWORD *)(v5 + 56);
}
*(_BYTE *)(v5 + 40) = 0;
--*(_BYTE *)(v5 + 41);
}
if ( (v2 & 5) != 0 )
{
if ( (v1 & 5) != 0 || (v1 & 0x10) == 0 )
goto LABEL_14;
}
else if ( (v1 & 0x10) == 0 || (v1 & 5) != 0 )
{
goto LABEL_14;
}
select_page0(device);
init_device(device);
LABEL_14:
result = select_page0(device);
if ( (v1 & 0x20) != 0 )
{
inb(*(_WORD *)device + 13);
inb(*(_WORD *)device + 14);
result = inb(*(_WORD *)device + 15);
}
}
return result;
}

original_code:
void
ne2000_interrupt_handler (void)
{
  UB reason;
  dbg_printf ("NE2000: catch interrupt\n");
  select_page0 (device);
  reason = inb ((device->io_base + 0x07));
  if (reason == 0)
    {
      return;
    }
  outb ((device->io_base + 0x07), reason);
  if ((reason & 0x02) || (reason & 0x08))
    {
      device->collision = inb ((device->io_base) + 0x05);
      if (reason & 0x02)
 {
   device->tx_count++;
 }
      else if (reason & 0x08)
 {
   device->tx_error++;
 }
      device->tx_busy = 0;
      device->tx_use--;
    }
  if ((reason & 0x01) || (reason & 0x04) || (reason & 0x10))
    {
      if (reason & 0x01)
 {
 }
      else if (reason & 0x04)
 {
 }
      else if (reason & 0x10)
 {
   select_page0 (device);
   init_device (device);
 }
    }
  select_page0 (device);
  if (reason & 0x20)
    {
      UB tmp;
      tmp = inb ((device->io_base) + 0x0d);
      tmp = inb ((device->io_base) + 0x0e);
      tmp = inb ((device->io_base) + 0x0f);
    }
}

canonical_original_code:
void ne2000_interrupt_handler()
{
  unsigned char reason;
  dbg_printf ("NE2000: catch interrupt\n");
  select_page0 (device);
  reason = inb ((device->io_base + 0x07));
  if (reason == 0)
    {
      return;
    }
  outb ((device->io_base + 0x07), reason);
  if ((reason & 0x02) || (reason & 0x08))
    {
      device->collision = inb ((device->io_base) + 0x05);
      if (reason & 0x02)
 {
   device->tx_count++;
 }
      else if (reason & 0x08)
 {
   device->tx_error++;
 }
      device->tx_busy = 0;
      device->tx_use--;
    }
  if ((reason & 0x01) || (reason & 0x04) || (reason & 0x10))
    {
      if (reason & 0x01)
 {
 }
      else if (reason & 0x04)
 {
 }
      else if (reason & 0x10)
 {
   select_page0 (device);
   init_device (device);
 }
    }
  select_page0 (device);
  if (reason & 0x20)
    {
      unsigned char tmp;
      tmp = inb ((device->io_base) + 0x0d);
      tmp = inb ((device->io_base) + 0x0e);
      tmp = inb ((device->io_base) + 0x0f);
    }
}

variable_types:
reason
unsigned char

variable_types:
tmp
unsigned char


decompiled_code:
__int64 ide_chk_drq()
{
return inb(0x1F7u) & 8;
}

canonical_decompiled_code:
__int64 func4()
{
return inb(0x1F7u) & 8;
}

original_code:
static int
ide_chk_drq ()
{
  return (inb (0x1f7) & 0x08);
}

canonical_original_code:
static int ide_chk_drq()
{
  return (inb (0x1f7) & 0x08);
}


decompiled_code:
__int64 __fastcall get_ide_parameter(unsigned __int16 *a1)
{
unsigned __int16 *v1; // rbx

v1 = a1;
lock();
outb(0xF6u, 0xA0u);
busywait(1000LL);
ide_send_command(0xECu);
if ( (unsigned int)ide_chk_drq() )
{
do
*v1++ = inw(0x1F0u);
while ( a1 + 59 != v1 );
}
else
{
boot_printf("drive busy. (%d)\n", 322LL);
}
unlock();
boot_printf("\n");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 *a1)
{
unsigned __int16 *v1; // rbx

v1 = a1;
lock();
outb(0xF6u, 0xA0u);
busywait(1000LL);
func3(0xECu);
if ( (unsigned int)func4() )
{
do
*v1++ = inw(0x1F0u);
while ( a1 + 59 != v1 );
}
else
{
boot_printf("drive busy. (%d)\n", 322LL);
}
unlock();
boot_printf("\n");
return 0LL;
}

original_code:
int get_ide_parameter (struct ide_id *id)
{
  int i;
  UWORD16 *p;
  lock ();
  outb (0x1f6, 0xA0);
  busywait (1000);
  ide_send_command (0xec);
  p = (UWORD16 *)id;
  if (ide_chk_drq ())
    {
      for (i = 0; i < sizeof (struct ide_id) / 2; i++)
 {
   *p = inw (0x1f0);
   p++;
 }
    }
  else
    {
      boot_printf ("drive busy. (%d)\n", 322);
    }
  unlock ();
  boot_printf ("\n");
  return (0);
}

canonical_original_code:
int get_ide_parameter(struct ide_id *id)
{
  int i;
  unsigned short *p;
  lock ();
  outb (0x1f6, 0xA0);
  busywait (1000);
  ide_send_command (0xec);
  p = (unsigned short *)id;
  if (ide_chk_drq ())
    {
      for (i = 0; i < sizeof (struct ide_id) / 2; i++)
 {
   *p = inw (0x1f0);
   p++;
 }
    }
  else
    {
      boot_printf ("drive busy. (%d)\n", 322);
    }
  unlock ();
  boot_printf ("\n");
  return (0);
}

variable_types: struct ide_id { unsigned short config; unsigned short n_cylinder; unsigned short pad0; unsigned short n_head; unsigned short track_byte_unformat; unsigned short sector_byte_unformat; unsigned short n_sector; unsigned short pad1[3]; unsigned char number[20]; unsigned short buffer_type; unsigned short buffer_size; unsigned short ecc_bytes; unsigned char firm_ware[8]; unsigned char model[40]; unsigned short pad2; unsigned short double_word_io; unsigned short dma_support; unsigned short pad3; unsigned short pio_config; unsigned short dma_config; unsigned short trans_mode; unsigned short now_cylinder; unsigned short now_head; unsigned short now_sector_track; unsigned short now_sector[2]; } *

variable_types:
p
unsigned short *


decompiled_code:
__int64 ide_id()
{
unsigned __int8 *v0; // rbx
__int64 *v1; // rbx
unsigned int i; // ebp
__int64 result; // rax

get_ide_parameter(ide_parameter);
v0 = (unsigned __int8 *)(unsigned int)((_DWORD)ide_parameter + 54);
do
{
boot_printf("%c", v0[1]);
boot_printf("%c", *v0);
v0 += 2;
}
while ( v0 != (unsigned __int8 *)(unsigned int)((_DWORD)ide_parameter + 94) );
boot_printf("\n");
boot_printf("C/H/S: %d/%d/%d\n", ide_parameter[1], ide_parameter[3], ide_parameter[6]);
v1 = &partition_table;
for ( i = 0; i != 4; ++i )
{
result = boot_printf(
"partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
i,
*((unsigned __int8 *)v1 + 4),
*((unsigned int *)v1 + 2),
*((unsigned int *)v1 + 4),
*(unsigned __int8 *)v1);
v1 += 3;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int8 *v0; // rbx
__int64 *v1; // rbx
unsigned int i; // ebp
__int64 result; // rax

func6(ide_parameter);
v0 = (unsigned __int8 *)(unsigned int)((_DWORD)ide_parameter + 54);
do
{
boot_printf("%c", v0[1]);
boot_printf("%c", *v0);
v0 += 2;
}
while ( v0 != (unsigned __int8 *)(unsigned int)((_DWORD)ide_parameter + 94) );
boot_printf("\n");
boot_printf("C/H/S: %d/%d/%d\n", ide_parameter[1], ide_parameter[3], ide_parameter[6]);
v1 = &partition_table;
for ( i = 0; i != 4; ++i )
{
result = boot_printf(
"partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
i,
*((unsigned __int8 *)v1 + 4),
*((unsigned int *)v1 + 2),
*((unsigned int *)v1 + 4),
*(unsigned __int8 *)v1);
v1 += 3;
}
return result;
}

original_code:
void
ide_id (void)
{
  int i;
  get_ide_parameter (&ide_parameter);
  for (i = 0; i < 20; i++)
    {
      boot_printf ("%c", ide_parameter.model[i * 2 + 1]);
      boot_printf ("%c", ide_parameter.model[i * 2]);
    }
  boot_printf ("\n");
  boot_printf ("C/H/S: %d/%d/%d\n",
   ide_parameter.n_cylinder,
   ide_parameter.n_head,
   ide_parameter.n_sector);
  for (i = 0; i < 4; i++)
    {
      boot_printf ("partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
       i,
       partition_table[i].type,
       (int)partition_table[i].start,
       (int)partition_table[i].length,
       (int)partition_table[i].boot_flag);
    }
}

canonical_original_code:
void ide_id()
{
  int i;
  get_ide_parameter (&ide_parameter);
  for (i = 0; i < 20; i++)
    {
      boot_printf ("%c", ide_parameter.model[i * 2 + 1]);
      boot_printf ("%c", ide_parameter.model[i * 2]);
    }
  boot_printf ("\n");
  boot_printf ("C/H/S: %d/%d/%d\n",
   ide_parameter.n_cylinder,
   ide_parameter.n_head,
   ide_parameter.n_sector);
  for (i = 0; i < 4; i++)
    {
      boot_printf ("partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
       i,
       partition_table[i].type,
       (int)partition_table[i].start,
       (int)partition_table[i].length,
       (int)partition_table[i].boot_flag);
    }
}


decompiled_code:
__int64 __fastcall ide_read_low(unsigned int a1, __int16 a2, char a3, unsigned __int8 a4, __int64 a5, int a6)
{
int v9; // er12
signed __int8 v10; // al
__int64 v11; // rbx

v9 = a6 << 9;
ide_intr_flag = 0;
while ( (inb(0x1F7u) & 0x80u) != 0 )
;
lock();
outb(0xF6u, (unsigned __int8)((16 * a1) | a3) | 0xA0);
outb(0xF2u, 1u);
outb(0xF4u, (unsigned __int8)a2);
outb(0xF5u, HIBYTE(a2));
outb(0xF3u, a4);
ide_send_command(0x20u);
unlock();
if ( (inb(0x1F7u) & 8) == 0 )
busywait(1LL);
do
v10 = inb(0x1F7u);
while ( v10 < 0 );
if ( (v10 & 1) != 0 )
{
boot_printf("IDE read error.\n");
v9 = 0;
}
else
{
v11 = 0LL;
if ( v9 > 1 )
{
do
*(_WORD *)(a5 + 2 * v11++) = inw(0x1F0u);
while ( v9 >> 1 > (int)v11 );
}
ide_enable_int(a1);
}
return (unsigned int)v9;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int16 a2, char a3, unsigned __int8 a4, __int64 a5, int a6)
{
int v9; // er12
signed __int8 v10; // al
__int64 v11; // rbx

v9 = a6 << 9;
ide_intr_flag = 0;
while ( (inb(0x1F7u) & 0x80u) != 0 )
;
lock();
outb(0xF6u, (unsigned __int8)((16 * a1) | a3) | 0xA0);
outb(0xF2u, 1u);
outb(0xF4u, (unsigned __int8)a2);
outb(0xF5u, HIBYTE(a2));
outb(0xF3u, a4);
func3(0x20u);
unlock();
if ( (inb(0x1F7u) & 8) == 0 )
busywait(1LL);
do
v10 = inb(0x1F7u);
while ( v10 < 0 );
if ( (v10 & 1) != 0 )
{
boot_printf("IDE read error.\n");
v9 = 0;
}
else
{
v11 = 0LL;
if ( v9 > 1 )
{
do
*(_WORD *)(a5 + 2 * v11++) = inw(0x1F0u);
while ( v9 >> 1 > (int)v11 );
}
func0(a1);
}
return (unsigned int)v9;
}

original_code:
int
ide_read_low (int drive, int cyl_b, int head_b, int sec_b, char *buf, int length)
{
  int stat;
  int i;
  UWORD16 *tmpbuf;
  int cyl, head, sec;
  cyl = cyl_b;
  head = head_b;
  sec = sec_b;
  length *= 512;
  ide_intr_flag = FALSE;
  while (inb (0x1f7) & 0x80)
    ;
  lock ();
  outb (0x1f6, 0xA0 | ((drive << 4) | head));
  outb (0x1f2, 1);
  outb (0x1f4, cyl & 0xff);
  outb (0x1f5, (cyl >> 8) & 0xff);
  outb (0x1f3, sec & 0xff);
  ide_send_command (0x20);
  unlock ();
  if (!(inb (0x1f7) & 0x08))
    {
      busywait (1);
    }
  while ((stat = inb (0x1f7)) & 0x80)
    ;
  if (stat & 0x01)
    {
      boot_printf ("IDE read error.\n");
      return (0);
    }
  tmpbuf = (UWORD16 *)buf;
  for (i = 0; i < length / 2; i++)
    {
      tmpbuf[i] = inw (0x1f0);
    }
  ide_enable_int (drive);
  return (length);
}

canonical_original_code:
int ide_read_low(int drive, int cyl_b, int head_b, int sec_b, char *buf, int length)
{
  int stat;
  int i;
  unsigned short *tmpbuf;
  int cyl; int head; int sec;
  cyl = cyl_b;
  head = head_b;
  sec = sec_b;
  length *= 512;
  ide_intr_flag = FALSE;
  while (inb (0x1f7) & 0x80)
    ;
  lock ();
  outb (0x1f6, 0xA0 | ((drive << 4) | head));
  outb (0x1f2, 1);
  outb (0x1f4, cyl & 0xff);
  outb (0x1f5, (cyl >> 8) & 0xff);
  outb (0x1f3, sec & 0xff);
  ide_send_command (0x20);
  unlock ();
  if (!(inb (0x1f7) & 0x08))
    {
      busywait (1);
    }
  while ((stat = inb (0x1f7)) & 0x80)
    ;
  if (stat & 0x01)
    {
      boot_printf ("IDE read error.\n");
      return (0);
    }
  tmpbuf = (unsigned short *)buf;
  for (i = 0; i < length / 2; i++)
    {
      tmpbuf[i] = inw (0x1f0);
    }
  ide_enable_int (drive);
  return (length);
}

variable_types: drive int

variable_types:
buf
char *

variable_types: length int

variable_types: stat int

variable_types:
tmpbuf
unsigned short *

variable_types: cyl int

variable_types: head int

variable_types: sec int


decompiled_code:
__int64 __fastcall ide_read_dump(const char **a1)
{
unsigned int v1; // ebp
unsigned int v2; // er12
__int64 v3; // rbx
char *v4; // rbp
int i; // er12
char *v6; // rbx
unsigned __int8 v7; // si
__int64 result; // rax
__int64 v9; // [rsp+0h] [rbp-218h] BYREF
char v10; // [rsp+8h] [rbp-210h] BYREF

v1 = atoi(a1[1]);
v2 = atoi(a1[2]);
v3 = (unsigned int)atoi(a1[3]);
boot_printf("read: c/h/s = %d/%d/%d\n", v1, v2, v3);
ide_read_low(0, v1, v2, v3, (__int64)&v9, 1);
v4 = &v10;
for ( i = 0; i != 128; i += 8 )
{
v6 = v4 - 8;
do
{
v7 = *v6;
if ( (unsigned __int8)*v6 > 0xFu )
boot_printf("0x%x ", v7);
else
boot_printf("0x0%x ", v7);
++v6;
}
while ( v6 != v4 );
result = boot_printf("\n");
v4 += 8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char **a1)
{
unsigned int v1; // ebp
unsigned int v2; // er12
__int64 v3; // rbx
char *v4; // rbp
int i; // er12
char *v6; // rbx
unsigned __int8 v7; // si
__int64 result; // rax
__int64 v9; // [rsp+0h] [rbp-218h] BYREF
char v10; // [rsp+8h] [rbp-210h] BYREF

v1 = atoi(a1[1]);
v2 = atoi(a1[2]);
v3 = (unsigned int)atoi(a1[3]);
boot_printf("read: c/h/s = %d/%d/%d\n", v1, v2, v3);
func8(0, v1, v2, v3, (__int64)&v9, 1);
v4 = &v10;
for ( i = 0; i != 128; i += 8 )
{
v6 = v4 - 8;
do
{
v7 = *v6;
if ( (unsigned __int8)*v6 > 0xFu )
boot_printf("0x%x ", v7);
else
boot_printf("0x0%x ", v7);
++v6;
}
while ( v6 != v4 );
result = boot_printf("\n");
v4 += 8;
}
return result;
}

original_code:
void
ide_read_dump (char **av)
{
  int cylinder, sector, head;
  BYTE buf[512];
  int i, j;
  cylinder = atoi (av[1]);
  head = atoi (av[2]);
  sector = atoi (av[3]);
  boot_printf ("read: c/h/s = %d/%d/%d\n", cylinder, head, sector);
  ide_read_low (0, cylinder, head, sector, buf, 1);
  for (i = 0; i < 128; )
    {
      for (j = 0; j < 8; j++, i++)
 {
   if (buf[i] < 0x10)
     {
       boot_printf("0x0%x ", buf[i]);
     }
   else
     {
       boot_printf("0x%x ", buf[i]);
     }
 }
      boot_printf ("\n");
    }
}

canonical_original_code:
void ide_read_dump(char **av)
{
  int cylinder; int sector; int head;
  unsigned char buf[512];
  int i; int j;
  cylinder = atoi (av[1]);
  head = atoi (av[2]);
  sector = atoi (av[3]);
  boot_printf ("read: c/h/s = %d/%d/%d\n", cylinder, head, sector);
  ide_read_low (0, cylinder, head, sector, buf, 1);
  for (i = 0; i < 128; )
    {
      for (j = 0; j < 8; j++, i++)
 {
   if (buf[i] < 0x10)
     {
       boot_printf("0x0%x ", buf[i]);
     }
   else
     {
       boot_printf("0x%x ", buf[i]);
     }
 }
      boot_printf ("\n");
    }
}

variable_types:
av
char **

variable_types: cylinder int

variable_types: sector int

variable_types:
buf
unsigned char [512]

variable_types: i int

variable_types: j int


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

outb(0xF6u, 0xA0u);
outb(0xF6u, 8u);
busywait(1000LL);
outb(0xF6u, 0xAu);
busywait(1000LL);
v0 = inb(0x1F7u);
boot_printf("IDE init status = 0x%x\n", v0);
get_ide_parameter(ide_parameter);
return read_partition_table(0LL, (unsigned __int8 *)partition_table);
}

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

outb(0xF6u, 0xA0u);
outb(0xF6u, 8u);
busywait(1000LL);
outb(0xF6u, 0xAu);
busywait(1000LL);
v0 = inb(0x1F7u);
boot_printf("IDE init status = 0x%x\n", v0);
func6(ide_parameter);
return func10(0LL, (unsigned __int8 *)partition_table);
}

original_code:
void
ide_init (void)
{
  int status;
  outb (0x1f6, 0xA0);
  outb (0x3f6, 0x08);
  busywait (1000);
  outb (0x3f6, 0x0a);
  busywait (1000);
  status = inb (0x1f7);
  boot_printf ("IDE init status = 0x%x\n", status);
  get_ide_parameter (&ide_parameter);
  read_partition_table (0, partition_table);
}

canonical_original_code:
void ide_init()
{
  int status;
  outb (0x1f6, 0xA0);
  outb (0x3f6, 0x08);
  busywait (1000);
  outb (0x3f6, 0x0a);
  busywait (1000);
  status = inb (0x1f7);
  boot_printf ("IDE init status = 0x%x\n", status);
  get_ide_parameter (&ide_parameter);
  read_partition_table (0, partition_table);
}

variable_types: status int


decompiled_code:
__int64 __fastcall ide_read_block_1k(unsigned int a1, int a2, int a3, __int64 a4, int a5)
{
return ide_read(a1, a2, (unsigned int)(2 * a3), a4, 2 * a5);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, int a2, int a3, __int64 a4, int a5)
{
return func12(a1, a2, (unsigned int)(2 * a3), a4, 2 * a5);
}

original_code:
int
ide_read_block_1k (int drive, int partition, unsigned int block, BYTE *buf, int length)
{
  int err;
  err = ide_read (drive, partition, block * (1024 / 512), buf, length * (1024 / 512));
  return (err);
}

canonical_original_code:
int ide_read_block_1k(int drive, int partition, unsigned int block, unsigned char *buf, int length)
{
  int err;
  err = ide_read (drive, partition, block * (1024 / 512), buf, length * (1024 / 512));
  return (err);
}

variable_types: partition int

variable_types:
block
unsigned int

variable_types:
buf
unsigned char *

variable_types: err int


decompiled_code:
__int64 __fastcall disp_string(__int64 a1, int a2)
{
__int64 v3; // rbx
char v4; // di
char v5; // di

if ( a2 > 1 )
{
v3 = 0LL;
do
{
v4 = *(_BYTE *)(a1 + v3 + 1);
if ( v4 )
putchar(v4);
else
putchar(32);
v5 = *(_BYTE *)(a1 + v3);
if ( v5 )
putchar(v5);
else
putchar(32);
v3 += 2LL;
}
while ( a2 / 2 > (int)v3 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2)
{
__int64 v3; // rbx
char v4; // di
char v5; // di

if ( a2 > 1 )
{
v3 = 0LL;
do
{
v4 = *(_BYTE *)(a1 + v3 + 1);
if ( v4 )
putchar(v4);
else
putchar(32);
v5 = *(_BYTE *)(a1 + v3);
if ( v5 )
putchar(v5);
else
putchar(32);
v3 += 2LL;
}
while ( a2 / 2 > (int)v3 );
}
return 0LL;
}

original_code:
int
disp_string (char *s, int length)
{
  int i;
  for (i = 0; i < (length / 2); i += 2)
    {
      if ((s[i + 1]) == 0)
 putchar (' ');
      else
 putchar (s[i + 1]);
      if ((s[i]) == 0)
 putchar (' ');
      else
 putchar (s[i]);
    }
  return (0);
}

canonical_original_code:
int disp_string(char *s, int length)
{
  int i;
  for (i = 0; i < (length / 2); i += 2)
    {
      if ((s[i + 1]) == 0)
 putchar (' ');
      else
 putchar (s[i + 1]);
      if ((s[i]) == 0)
 putchar (' ');
      else
 putchar (s[i]);
    }
  return (0);
}

variable_types:
s
char *

variable_types: length int