original_code:
int circle_vga (int fd, int x, int y, int width, int height, int color)
{
  struct gr_box_t param;
  int error;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  error = fcntl(fd, (0x00008005 << 16 | sizeof(struct gr_box_t) & 0xFFFF), &param);
  return(error);
}

canonical_original_code:
int circle_vga(int fd, int x, int y, int width, int height, int color)
{
  struct gr_box_t param;
  int error;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  error = fcntl(fd, (0x00008005 << 16 | sizeof(struct gr_box_t) & 0xFFFF), &param);
  return(error);
}

user_defined_types: struct gr_box_t { long x; long width; long color; }


repo: monaka/B-Free

original_code:
int point_vga (int fd, int x, int y, int color, int mode)
{
  struct gr_point_t param;
  int error;
  param.x = x;
  param.y = y;
  param.color = color;
  param.mode = mode;
  error = fcntl(fd, (0x00008001 << 16 | sizeof(struct gr_point_t) & 0xFFFF), &param);
  return(error);
}

canonical_original_code:
int point_vga(int fd, int x, int y, int color, int mode)
{
  struct gr_point_t param;
  int error;
  param.x = x;
  param.y = y;
  param.color = color;
  param.mode = mode;
  error = fcntl(fd, (0x00008001 << 16 | sizeof(struct gr_point_t) & 0xFFFF), &param);
  return(error);
}

variable_types: fd int

variable_types: x int

variable_types: y int

variable_types: color int

variable_types: mode int

variable_types: struct gr_point_t { long x; long color; long mode; }

variable_types: error int

return_type: int


original_code:
int line_vga (int fd, int x1, int y1, int x2, int y2, int color, int mode)
{
  struct gr_line_t param;
  int error;
  param.x1 = x1;
  param.y1 = y1;
  param.x2 = x2;
  param.y2 = y2;
  param.color = color;
  param.mode = mode;
  error = fcntl(fd, (0x00008002 << 16 | sizeof(struct gr_line_t) & 0xFFFF), &param);
  return(error);
}

canonical_original_code:
int line_vga(int fd, int x1, int y1, int x2, int y2, int color, int mode)
{
  struct gr_line_t param;
  int error;
  param.x1 = x1;
  param.y1 = y1;
  param.x2 = x2;
  param.y2 = y2;
  param.color = color;
  param.mode = mode;
  error = fcntl(fd, (0x00008002 << 16 | sizeof(struct gr_line_t) & 0xFFFF), &param);
  return(error);
}

variable_types: struct gr_line_t { long x1; long x2; long color; long mode; }


original_code:
int ellipse_vga (int fd, int x, int y, int width, int height, int color)
{
  struct gr_ellipse_t param;
  int error;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  error = fcntl(fd, (0x00008009 << 16 | sizeof(struct gr_ellipse_t) & 0xFFFF), &param);
  return(error);
}

canonical_original_code:
int ellipse_vga(int fd, int x, int y, int width, int height, int color)
{
  struct gr_ellipse_t param;
  int error;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  error = fcntl(fd, (0x00008009 << 16 | sizeof(struct gr_ellipse_t) & 0xFFFF), &param);
  return(error);
}

variable_types: width int

variable_types: height int

variable_types: struct gr_ellipse_t { long x; long width; long color; }


original_code:
int fillellipse_vga (int fd, int x, int y, int width, int height, int color)
{
  struct gr_ellipse_t param;
  int error;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  error = fcntl(fd, (0x0000800A << 16 | sizeof(struct gr_ellipse_t) & 0xFFFF), &param);
  return(error);
}

canonical_original_code:
int fillellipse_vga(int fd, int x, int y, int width, int height, int color)
{
  struct gr_ellipse_t param;
  int error;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  error = fcntl(fd, (0x0000800A << 16 | sizeof(struct gr_ellipse_t) & 0xFFFF), &param);
  return(error);
}

user_defined_types: struct gr_ellipse_t { long x; long width; long color; }


original_code:
int set_background (int fd, int width, int height, unsigned char *bitmap)
{
  struct gr_setbg_t param;
  int error;
  param.caller = ((struct lowlib_data *)(0x7fff0000))->main_task;
  if (bitmap)
    {
      param.width = width;
      param.height = height;
      param.size = (width * height) / 8;
      param.bitmap = bitmap;
    }
  else
    {
      param.width = 16;
      param.height = 16;
      param.size = sizeof (bit_bits);
      param.bitmap = bit_bits;
    }
  param.frcolor = 1;
  param.bgcolor = 7;
  error = fcntl(fd, (0x00008006 << 16 | sizeof(struct gr_setbg_t) & 0xFFFF), &param);
  return(error);
}

canonical_original_code:
int set_background(int fd, int width, int height, unsigned char *bitmap)
{
  struct gr_setbg_t param;
  int error;
  param.caller = ((struct lowlib_data *)(0x7fff0000))->main_task;
  if (bitmap)
    {
      param.width = width;
      param.height = height;
      param.size = (width * height) / 8;
      param.bitmap = bitmap;
    }
  else
    {
      param.width = 16;
      param.height = 16;
      param.size = sizeof (bit_bits);
      param.bitmap = bit_bits;
    }
  param.frcolor = 1;
  param.bgcolor = 7;
  error = fcntl(fd, (0x00008006 << 16 | sizeof(struct gr_setbg_t) & 0xFFFF), &param);
  return(error);
}

variable_types:
bitmap
unsigned char *

variable_types: struct gr_setbg_t { int caller; long width; long size; void *bitmap; long frcolor; long bgcolor; }

user_defined_types: struct lowlib_data { int recv_port; int my_pid; int main_task; int signal_task; int fifo_task; int alarm_task; void (*start_func)(); int efile; long errno; }


original_code:
int set_bitmap (int fd, int x, int y, int width, int height, int size, unsigned char *buf, int color, int bgcolor)
{
  struct gr_setbitmap_t param;
  int error;
  param.caller = ((struct lowlib_data *)(0x7fff0000))->main_task;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.size = size;
  param.bitmap = buf;
  param.frcolor = color;
  param.bgcolor = bgcolor;
  error = fcntl(fd, (0x00008007 << 16 | sizeof(struct gr_setbitmap_t) & 0xFFFF), &param);
  return(error);
}

canonical_original_code:
int set_bitmap(int fd, int x, int y, int width, int height, int size, unsigned char *buf, int color, int bgcolor)
{
  struct gr_setbitmap_t param;
  int error;
  param.caller = ((struct lowlib_data *)(0x7fff0000))->main_task;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.size = size;
  param.bitmap = buf;
  param.frcolor = color;
  param.bgcolor = bgcolor;
  error = fcntl(fd, (0x00008007 << 16 | sizeof(struct gr_setbitmap_t) & 0xFFFF), &param);
  return(error);
}

variable_types: size int

variable_types:
buf
unsigned char *

variable_types: bgcolor int

variable_types: struct gr_setbitmap_t { int caller; long x; long width; long size; void *bitmap; long frcolor; long bgcolor; }


original_code:
int spl_bitmap (int fd, int x, int y, int width, int height, int size, unsigned char *buf, int color)
{
  struct gr_splbitmap_t param;
  int error;
  param.caller = ((struct lowlib_data *)(0x7fff0000))->main_task;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.size = size;
  param.bitmap = buf;
  param.frcolor = color;
  error = fcntl(fd, (0x00008008 << 16 | sizeof(struct gr_splbitmap_t) & 0xFFFF), &param);
  return(error);
}

canonical_original_code:
int spl_bitmap(int fd, int x, int y, int width, int height, int size, unsigned char *buf, int color)
{
  struct gr_splbitmap_t param;
  int error;
  param.caller = ((struct lowlib_data *)(0x7fff0000))->main_task;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.size = size;
  param.bitmap = buf;
  param.frcolor = color;
  error = fcntl(fd, (0x00008008 << 16 | sizeof(struct gr_splbitmap_t) & 0xFFFF), &param);
  return(error);
}

variable_types: fd int

variable_types: struct gr_splbitmap_t { int caller; long x; long width; long size; void *bitmap; long frcolor; }


original_code:
int scroll_vga(int fd, int direc, int x, int y, int width, int height, int step, int color)
{
  struct gr_scroll_t param;
  int error;
  param.direc = direc;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.step = step;
  param.color = color;
  error = fcntl(fd, (0x0000800B << 16 | sizeof(struct gr_scroll_t) & 0xFFFF), &param);
  return(error);
}

variable_types: direc int

variable_types: x int

variable_types: y int

variable_types: step int

variable_types: struct gr_scroll_t { long direc; long x; long width; long step; long color; }


original_code:
int
set_idt (int entry, int selector, int offset, int type, int dpl)
{
  struct idt_t *table;
  table = (struct idt_t *)0x2000;
  (table[entry].offset0 = offset & 0xffff); (table[entry].offset1 = offset >> 16 & 0xffff);;
  table[entry].p = 1;
  table[entry].selector = selector;
  table[entry].dpl = dpl;
  table[entry].type = type;
  table[entry].dt0 = 0;
  table[entry].zero = 0;
  return (0);
}

canonical_original_code:
int set_idt(int entry, int selector, int offset, int type, int dpl)
{
  struct idt_t *table;
  table = (struct idt_t *)0x2000;
  (table[entry].offset0 = offset & 0xffff); (table[entry].offset1 = offset >> 16 & 0xffff);;
  table[entry].p = 1;
  table[entry].selector = selector;
  table[entry].dpl = dpl;
  table[entry].type = type;
  table[entry].dt0 = 0;
  table[entry].zero = 0;
  return (0);
}

variable_types: entry int

variable_types: selector int

variable_types: offset int

variable_types: type int

variable_types: dpl int

variable_types: struct idt_t { int offset0; int selector; int zero; int type; int dt0; int dpl; int p; int offset1; } *


decompiled_code:
__int64 init_idt()
{
int v0; // er9
int v1; // er10
__int64 result; // rax

v0 = 0;
v1 = (unsigned int)&ignore_handler;
do
result = set_idt(v0, 8, v1, 15, 0);
while ( v0 != 256 );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er9
int v1; // er10
__int64 result; // rax

v0 = 0;
v1 = (unsigned int)&ignore_handler;
do
result = func0(v0, 8, v1, 15, 0);
while ( v0 != 256 );
return result;
}

original_code:
void
init_idt (void)
{
  int i;
  for (i = 0; i < 256; i++)
    {
      set_idt (i, 0x08, (int)ignore_handler, 0xf, 0);
    }
}

canonical_original_code:
void init_idt()
{
  int i;
  for (i = 0; i < 256; i++)
    {
      set_idt (i, 0x08, (int)ignore_handler, 0xf, 0);
    }
}

variable_types: i int

return_type: void


decompiled_code:
__int64 __fastcall get_idt(int a1)
{
return 8LL * a1 + 0x2000;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return 8LL * a1 + 0x2000;
}

original_code:
struct idt_t *
get_idt (int entry)
{
  struct idt_t *table;
  table = (struct idt_t *)0x2000;
  return (&table[entry]);
}

canonical_original_code:
struct idt_t *get_idt(int entry)
{
  struct idt_t *table;
  table = (struct idt_t *)0x2000;
  return (&table[entry]);
}

return_type: struct idt_t { int offset0; int selector; int zero; int type; int dt0; int dpl; int p; int offset1; } *


getchar

decompiled_code:
__int64 getchar()
{
unsigned int v0; // er12

v0 = read_keyboard();
putchar(v0);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // er12

v0 = read_keyboard();
putchar(v0);
return v0;
}

original_code:
int
getchar (void)
{
  int ch;
  ch = read_keyboard ();
  putchar (ch);
  return (ch);
}

canonical_original_code:
int getchar()
{
  int ch;
  ch = read_keyboard ();
  putchar (ch);
  return (ch);
}

variable_types: ch int


getch

decompiled_code:
// attributes: thunk
__int64 getch()
{
return read_keyboard();
}

canonical_decompiled_code:
__int64 func1()
{
return read_keyboard();
}

original_code:
int getch(void)
{
  int ch;
  ch = read_keyboard ();
  return ch;
}

canonical_original_code:
int getch()
{
  int ch;
  ch = read_keyboard ();
  return ch;
}


decompiled_code:
__int64 __fastcall mount_root(const char *a1)
{
return dbg_printf("init: mount %s at /\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
return dbg_printf("init: mount %s at /\n", a1);
}

original_code:
W
mount_root (ID device,
     W fstype,
     W option)
{
  struct fsops *fsp;
  W err;
  printk ("device = 0x%x, fstype = %d, option = %d\n",
   device, fstype, option);
  if ((fstype < 0) || (fstype > 1))
    {
      printk("ERROR: mount_root fstype error %d\n", fstype);
      return ((-13));
    }
  rootfile = alloc_inode ();
  if (rootfile == (0))
    {
      return ((-10));
    }
  rootfs = alloc_fs ();
  if (rootfs == (0))
    {
      dealloc_inode (rootfile);
      return ((-10));
    }
  fsp = fs_table[fstype].fsops;
  err = (fsp->fs_mountroot)(device, rootfs,rootfile);
  if (err)
    {
      return (err);
    }
  fs_register_inode (rootfile);
  rootfile->i_fs = rootfs;
  rootfs->rootdir = rootfile;
  rootfs->fs_device = device;
  return ((0));
}

canonical_original_code:
long mount_root(int device, long fstype, long option)
{
  struct fsops *fsp;
  long err;
  printk ("device = 0x%x, fstype = %d, option = %d\n",
   device, fstype, option);
  if ((fstype < 0) || (fstype > 1))
    {
      printk("ERROR: mount_root fstype error %d\n", fstype);
      return ((-13));
    }
  rootfile = alloc_inode ();
  if (rootfile == (0))
    {
      return ((-10));
    }
  rootfs = alloc_fs ();
  if (rootfs == (0))
    {
      dealloc_inode (rootfile);
      return ((-10));
    }
  fsp = fs_table[fstype].fsops;
  err = (fsp->fs_mountroot)(device, rootfs,rootfile);
  if (err)
    {
      return (err);
    }
  fs_register_inode (rootfile);
  rootfile->i_fs = rootfs;
  rootfs->rootdir = rootfile;
  rootfs->fs_device = device;
  return ((0));
}

variable_types: device int

variable_types: fstype long

variable_types: option long

variable_types: struct fsops { long (*fs_mount)(); long (*fs_mountroot)(); long (*fs_umount)(); long (*fs_statfs)(); long (*fs_syncfs)(); long (*fs_read_inode)(); long (*fs_write_inode)(); long (*fs_read_super)(); long (*fs_write_super)(); long (*fs_get_inode)(); long (*fs_put_inode)(); } *

variable_types: err long

return_type: long


decompiled_code:
__int64 console_clear()
{
unsigned int i; // ebp
unsigned int j; // ebx
__int64 result; // rax

for ( i = 0; i != 25; ++i )
{
for ( j = 0; j != 81; ++j )
result = write_vram(j, i, 32LL, 225LL);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int i; // ebp
unsigned int j; // ebx
__int64 result; // rax

for ( i = 0; i != 25; ++i )
{
for ( j = 0; j != 81; ++j )
result = write_vram(j, i, 32LL, 225LL);
}
return result;
}

original_code:
void
console_clear (void)
{
  int x, y;
  for (y = 0; y <= 24; y++)
    for (x = 0; x <= 80; x++)
      {
 write_vram (x, y, ' ', 0xE1);
      }
}

canonical_original_code:
void console_clear()
{
  int x; int y;
  for (y = 0; y <= 24; y++)
    for (x = 0; x <= 80; x++)
      {
 write_vram (x, y, ' ', 0xE1);
      }
}

variable_types: x int


decompiled_code:
__int64 write_cr()
{
x = 0;
if ( y <= 23 )
return set_cursor_pos(0LL, (unsigned int)++y);
scroll_up();
return set_cursor_pos((unsigned int)x, (unsigned int)y);
}

canonical_decompiled_code:
__int64 func2()
{
x = 0;
if ( y <= 23 )
return set_cursor_pos(0LL, (unsigned int)++y);
scroll_up();
return set_cursor_pos((unsigned int)x, (unsigned int)y);
}

original_code:
void
write_cr ()
{
  x = 0;
  if (y >= 24)
    {
      scroll_up ();
    }
  else
    {
      y++;
    }
  set_cursor_pos (x, y);
}

canonical_original_code:
void write_cr()
{
  x = 0;
  if (y >= 24)
    {
      scroll_up ();
    }
  else
    {
      y++;
    }
  set_cursor_pos (x, y);
}


decompiled_code:
void write_tab()
{
__int64 v0; // rdi
int v1; // ebx
signed int v2; // ebx

v0 = (unsigned int)x;
if ( x <= 79 )
{
v1 = x + 15;
if ( x + 8 >= 0 )
v1 = x + 8;
v2 = (v1 & 0xFFFFFFF8) - 1;
if ( x < v2 )
{
do
{
write_vram(v0, (unsigned int)y, 32LL, 0LL);
v0 = (unsigned int)(x + 1);
x = v0;
}
while ( (int)v0 < v2 );
}
}
}

canonical_decompiled_code:
void func3()
{
__int64 v0; // rdi
int v1; // ebx
signed int v2; // ebx

v0 = (unsigned int)x;
if ( x <= 79 )
{
v1 = x + 15;
if ( x + 8 >= 0 )
v1 = x + 8;
v2 = (v1 & 0xFFFFFFF8) - 1;
if ( x < v2 )
{
do
{
write_vram(v0, (unsigned int)y, 32LL, 0LL);
v0 = (unsigned int)(x + 1);
x = v0;
}
while ( (int)v0 < v2 );
}
}
}

variable_types: tmp int


decompiled_code:
__int64 __fastcall set_coursor(__int64 a1, __int64 a2)
{
x = a1;
y = a2;
return set_cursor_pos(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
x = a1;
y = a2;
return set_cursor_pos(a1, a2);
}

original_code:
void set_coursor(int sx, int sy)
{
  x = sx;
  y = sy;
  set_cursor_pos (x,y);
}

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 init_console()
{
int v0; // ebx

v0 = 24;
console_clear();
do
{
scroll_up();
--v0;
}
while ( v0 );
y = 0;
x = 0;
set_cursor_pos(0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx

v0 = 24;
func0();
do
{
scroll_up();
--v0;
}
while ( v0 );
y = 0;
x = 0;
set_cursor_pos(0LL, 0LL);
return 0LL;
}

original_code:
int
init_console (void)
{
  int i;
  console_clear ();
  for (i = 0; i < 24; i++)
    {
      scroll_up ();
    }
  x = y = 0;
  set_cursor_pos (x, y);
  return (0);
}

canonical_original_code:
int init_console()
{
  int i;
  console_clear ();
  for (i = 0; i < 24; i++)
    {
      scroll_up ();
    }
  x = y = 0;
  set_cursor_pos (x, y);
  return (0);
}


putchar

decompiled_code:
__int64 __fastcall putchar(unsigned __int8 a1)
{
__int64 v1; // rsi
__int64 v2; // rdi
__int64 result; // rax

if ( a1 == 10 )
{
write_cr();
result = 0LL;
}
else
{
write_vram((unsigned int)x, (unsigned int)y, a1, 225LL);
v1 = (unsigned int)y;
v2 = (unsigned int)(x + 1);
x = v2;
if ( (int)v2 > 79 )
{
v2 = 0LL;
x = 0;
v1 = (unsigned int)(y + 1);
y = v1;
if ( (int)v1 > 24 )
{
scroll_up(0LL);
v2 = (unsigned int)x;
v1 = 24LL;
y = 24;
}
}
set_cursor_pos(v2, v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1)
{
__int64 v1; // rsi
__int64 v2; // rdi
__int64 result; // rax

if ( a1 == 10 )
{
func2();
result = 0LL;
}
else
{
write_vram((unsigned int)x, (unsigned int)y, a1, 225LL);
v1 = (unsigned int)y;
v2 = (unsigned int)(x + 1);
x = v2;
if ( (int)v2 > 79 )
{
v2 = 0LL;
x = 0;
v1 = (unsigned int)(y + 1);
y = v1;
if ( (int)v1 > 24 )
{
scroll_up(0LL);
v2 = (unsigned int)x;
v1 = 24LL;
y = 24;
}
}
set_cursor_pos(v2, v1);
result = 0LL;
}
return result;
}

original_code:
int
putchar (int ch)
{
  ch = ch & 0xff;
  if (ch == '\n')
    {
      write_cr ();
      return (0);
    }
  else
    {
      write_vram (x, y, ch, 0xE1);
    }
  if (++x >= 80)
    {
      y++;
      x = 0;
      if (y > 24)
 {
   scroll_up ();
   y = 24;
 }
    }
  set_cursor_pos (x, y);
  return (0);
}

canonical_original_code:
int putchar(int ch)
{
  ch = ch & 0xff;
  if (ch == '\n')
    {
      write_cr ();
      return (0);
    }
  else
    {
      write_vram (x, y, ch, 0xE1);
    }
  if (++x >= 80)
    {
      y++;
      x = 0;
      if (y > 24)
 {
   scroll_up ();
   y = 24;
 }
    }
  set_cursor_pos (x, y);
  return (0);
}


wreg

decompiled_code:
void __fastcall wreg(unsigned __int16 port, unsigned __int8 a2)
{
outb(0xE0u, port);
outb(0xE1u, a2);
}

canonical_decompiled_code:
void __fastcall func1(unsigned __int16 port, unsigned __int8 a2)
{
outb(0xE0u, port);
outb(0xE1u, a2);
}

original_code:
void wreg(UW ind, UB data)
{
  outb(0x3e0,ind);
  outb(0x3e0 +1,data);
}

canonical_original_code:
void wreg(unsigned long ind, unsigned char data)
{
  outb(0x3e0,ind);
  outb(0x3e0 +1,data);
}

variable_types:
ind
unsigned long

variable_types:
data
unsigned char


rreg

decompiled_code:
unsigned __int8 __fastcall rreg(unsigned __int16 port)
{
outb(0xE0u, port);
return inb(0x3E1u);
}

canonical_decompiled_code:
unsigned __int8 __fastcall func2(unsigned __int16 port)
{
outb(0xE0u, port);
return inb(0x3E1u);
}

original_code:
UB rreg(UW ind, UB data)
{
  outb(0x3e0,ind);
  return inb(0x3e0 +1,data);
}

canonical_original_code:
unsigned char rreg(unsigned long ind, unsigned char data)
{
  outb(0x3e0,ind);
  return inb(0x3e0 +1,data);
}

return_type: unsigned char


decompiled_code:
__int64 itron_debug()
{
vsys_msc(9999LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
vsys_msc(9999LL, 0LL);
return 0LL;
}

original_code:
ER
itron_debug(void)
{
  vsys_msc (9999, (0));
  return (0);
}

canonical_original_code:
int itron_debug()
{
  vsys_msc (9999, (0));
  return (0);
}


decompiled_code:
__int64 dump_cis()
{
pmemdump(589824LL);
return pmemdump(655360LL);
}

original_code:
void dump_cis(void)
{
  pmemdump(0x90000);
  pmemdump(0xa0000);
}

canonical_original_code:
void dump_cis()
{
  pmemdump(0x90000);
  pmemdump(0xa0000);
}


probe

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

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

original_code:
ER
probe (struct device *dev)
{
  char *p = rcs;
  return ((0));
}

canonical_original_code:
int probe(struct device *dev)
{
  char *p = rcs;
  return ((0));
}

variable_types: struct device { unsigned long uwSlotNumbber; unsigned long uwDeviceName; unsigned short uhVendorID; unsigned short uhDeviceID; unsigned long uwRevisionID; char reg[15]; } *

variable_types:
p
char *


decompiled_code:
void vm_create()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
vm_create (ID taskid, UW vaddr, UW size, UW permission, UW mode)
{
}

canonical_original_code:
int vm_create(int taskid, unsigned long vaddr, unsigned long size, unsigned long permission, unsigned long mode)
{
}

variable_types: taskid int

variable_types:
vaddr
unsigned long

variable_types:
size
unsigned long

variable_types:
permission
unsigned long

variable_types:
mode
unsigned long


decompiled_code:
__int64 psys_sigdelset()
{
errno = 26;
return 0LL;
}

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

original_code:
int
psys_sigdelset (void *argp)
{
  struct a
    {
    } *args = (struct a *)argp;
  errno = 26;
  return ((0));
}

canonical_original_code:
int psys_sigdelset(void *argp)
{
  struct a *args = (struct a *)argp;
  errno = 26;
  return ((0));
}

variable_types:
argp
void *

variable_types:
args
struct a {  } *


decompiled_code:
void init_8259A()
{
outb(0x20u, 0x11u);
outb(0x21u, 0x20u);
outb(0x21u, 4u);
outb(0x21u, 1u);
outb(0xA0u, 0x11u);
outb(0xA1u, 0x28u);
outb(0xA1u, 2u);
outb(0xA1u, 1u);
outb(0x21u, 0xFBu);
outb(0xA1u, 0xFFu);
}

canonical_decompiled_code:
void func0()
{
outb(0x20u, 0x11u);
outb(0x21u, 0x20u);
outb(0x21u, 4u);
outb(0x21u, 1u);
outb(0xA0u, 0x11u);
outb(0xA1u, 0x28u);
outb(0xA1u, 2u);
outb(0xA1u, 1u);
outb(0x21u, 0xFBu);
outb(0xA1u, 0xFFu);
}


decompiled_code:
__int64 __fastcall reset_intr_mask(int a1)
{
unsigned __int8 v1; // al
unsigned __int8 v3; // al

lock();
if ( a1 > 7 )
{
v3 = inb(0xA1u);
outb(0xA1u, v3 & (unsigned __int8)__ROL4__(-2, a1 - 8));
}
else
{
v1 = inb(0x21u);
outb(0x21u, v1 & (unsigned __int8)__ROL4__(-2, a1));
}
return unlock();
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
unsigned __int8 v1; // al
unsigned __int8 v3; // al

lock();
if ( a1 > 7 )
{
v3 = inb(0xA1u);
outb(0xA1u, v3 & (unsigned __int8)__ROL4__(-2, a1 - 8));
}
else
{
v1 = inb(0x21u);
outb(0x21u, v1 & (unsigned __int8)__ROL4__(-2, a1));
}
return unlock();
}

original_code:
void
reset_intr_mask (int intn)
{
  lock ();
  if (intn < 8)
    outb (0x21, inb (0x21) & ~(1 << intn));
  else
    outb (0xa1, inb (0xa1) & ~(1 << (intn - 8)));
  unlock ();
}

canonical_original_code:
void reset_intr_mask(int intn)
{
  lock ();
  if (intn < 8)
    outb (0x21, inb (0x21) & ~(1 << intn));
  else
    outb (0xa1, inb (0xa1) & ~(1 << (intn - 8)));
  unlock ();
}

variable_types: intn int


interrupt

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

if ( a1 == 38 )
return intr_fd();
if ( a1 <= 38 )
{
if ( a1 == 32 )
return result;
if ( a1 == 33 )
return intr_keyboard();
}
else if ( (unsigned int)(a1 - 46) <= 1 )
{
return intr_ide();
}
return boot_printf("unknown interrupt from %d\n", (unsigned int)a1);
}

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

if ( a1 == 38 )
return intr_fd();
if ( a1 <= 38 )
{
if ( a1 == 32 )
return result;
if ( a1 == 33 )
return intr_keyboard();
}
else if ( (unsigned int)(a1 - 46) <= 1 )
{
return intr_ide();
}
return boot_printf("unknown interrupt from %d\n", (unsigned int)a1);
}

original_code:
void
interrupt (int intn)
{
  switch (intn)
    {
    default:
      boot_printf ("unknown interrupt from %d\n", intn);
      break;
    case 32:
      break;
    case 33:
      intr_keyboard ();
      break;
    case 38:
      intr_fd ();
      break;
    case 46:
      intr_ide ();
      break;
    case 47:
      intr_ide ();
      break;
    }
}

canonical_original_code:
void interrupt(int intn)
{
  switch (intn)
    {
    default:
      boot_printf ("unknown interrupt from %d\n", intn);
      break;
    case 32:
      break;
    case 33:
      intr_keyboard ();
      break;
    case 38:
      intr_fd ();
      break;
    case 46:
      intr_ide ();
      break;
    case 47:
      intr_ide ();
      break;
    }
}


trap

decompiled_code:
__int64 __fastcall trap(unsigned int a1)
{
return boot_printf("trap %d\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return boot_printf("trap %d\n", a1);
}

original_code:
void
trap (int intn)
{
  boot_printf ("trap %d\n", intn);
}

canonical_original_code:
void trap(int intn)
{
  boot_printf ("trap %d\n", intn);
}


fault

decompiled_code:
__int64 __fastcall fault(unsigned int a1)
{
return boot_printf("fault %d\n", a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return boot_printf("fault %d\n", a1);
}

original_code:
void
fault (int intn)
{
  boot_printf ("fault %d\n", intn);
}

canonical_original_code:
void fault(int intn)
{
  boot_printf ("fault %d\n", intn);
}


decompiled_code:
__int64 __fastcall wait_int(unsigned int *a1)
{
unlock();
if ( !*a1 )
{
while ( 1 )
;
}
lock();
*a1 = 0;
unlock();
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
unlock();
if ( !*a1 )
{
while ( 1 )
;
}
lock();
*a1 = 0;
unlock();
return *a1;
}

original_code:
int
wait_int (int *flag)
{
  unlock ();
  while (*flag == FALSE)
    ;
  lock ();
  *flag = FALSE;
  unlock ();
  return (*flag);
}

canonical_original_code:
int wait_int(int *flag)
{
  unlock ();
  while (*flag == FALSE)
    ;
  lock ();
  *flag = FALSE;
  unlock ();
  return (*flag);
}

variable_types:
flag
int *


decompiled_code:
void sig_core()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
static int
sig_core (void *arg)
{
}

canonical_original_code:
static int sig_core(void *arg)
{
}

variable_types:
arg
void *


decompiled_code:
// attributes: thunk
void sig_kill()
{
sig_core();
}

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

original_code:
static int
sig_kill (void *arg)
{
}

canonical_original_code:
static int sig_kill(void *arg)
{
}


decompiled_code:
// attributes: thunk
void sig_cont()
{
sig_core();
}

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

original_code:
static int
sig_cont (void *arg)
{
}

canonical_original_code:
static int sig_cont(void *arg)
{
}


decompiled_code:
void proc_set_signal_port()
{
;
}

canonical_decompiled_code:
void func6()
{
;
}

original_code:
int
proc_set_signal_port (int my_pid, ID sigport)
{
}

canonical_original_code:
int proc_set_signal_port(int my_pid, int sigport)
{
}

variable_types: sigport int


getuid

decompiled_code:
void getuid()
{
;
}

original_code:
int
getuid (void)
{
  return (call_lowlib (19));
}

canonical_original_code:
int getuid()
{
  return (call_lowlib (19));
}


decompiled_code:
__int64 __fastcall UDP_CRE_CEP(__int64 a1, __int64 a2)
{
ID_CHECK();
NUL_CHECK(a2);
return 4294967279LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
ID_CHECK();
NUL_CHECK(a2);
return 4294967279LL;
}

original_code:
ER UDP_CRE_CEP(ID cepid, T_UDP_CCEP *pk_ccep)
{
 ID_CHECK(cepid);
 NUL_CHECK(pk_ccep);
 return (-17);
}

canonical_original_code:
int UDP_CRE_CEP(int cepid, struct t_udp_ccep *pk_ccep)
{
 ID_CHECK(cepid);
 NUL_CHECK(pk_ccep);
 return (-17);
}

variable_types: cepid int

variable_types: struct t_udp_ccep { unsigned int cepatr; struct t_ipv4ep { unsigned long ipaddr; unsigned short portno; } myaddr; void (*callback)(); } *

user_defined_types: struct t_udp_ccep { unsigned int cepatr; struct t_ipv4ep myaddr; void (*callback)(); }


decompiled_code:
// attributes: thunk
__int64 __fastcall udp_cre_cep(__int64 a1, __int64 a2)
{
return UDP_CRE_CEP(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
return func0(a1, a2);
}

original_code:
ER udp_cre_cep(ID cepid, T_UDP_CCEP *pk_ccep)
{
 ID_CHECK(cepid);
 NUL_CHECK(pk_ccep);
 return (-17);
}

canonical_original_code:
int udp_cre_cep(int cepid, struct t_udp_ccep *pk_ccep)
{
 ID_CHECK(cepid);
 NUL_CHECK(pk_ccep);
 return (-17);
}

user_defined_types: struct t_ipv4ep { unsigned long ipaddr; unsigned short portno; }


decompiled_code:
__int64 udp_del_cep()
{
ID_CHECK();
return 4294967279LL;
}

original_code:
ER udp_del_cep(ID cepid)
{
 ID_CHECK(cepid);
 return (-17);
}

canonical_original_code:
int udp_del_cep(int cepid)
{
 ID_CHECK(cepid);
 return (-17);
}


decompiled_code:
__int64 __fastcall udp_snd_dat(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
ID_CHECK();
NUL_CHECK(a2);
NUL_CHECK(a3);
LEN_CHECK(a4);
TMO_CHECK(a5);
return 4294967279LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
ID_CHECK();
NUL_CHECK(a2);
NUL_CHECK(a3);
LEN_CHECK(a4);
TMO_CHECK(a5);
return 4294967279LL;
}

original_code:
ER udp_snd_dat(ID cepid, T_IPV4EP *p_dstaddr, VP data, INT len, TMO tmout)
{
 ID_CHECK(cepid);
 NUL_CHECK(p_dstaddr);
 NUL_CHECK(data);
 LEN_CHECK(len);
 TMO_CHECK(tmout);
 return (-17);
}

canonical_original_code:
int udp_snd_dat(int cepid, struct t_ipv4ep *p_dstaddr, void *data, int len, int tmout)
{
 ID_CHECK(cepid);
 NUL_CHECK(p_dstaddr);
 NUL_CHECK(data);
 LEN_CHECK(len);
 TMO_CHECK(tmout);
 return (-17);
}

variable_types: struct t_ipv4ep { unsigned long ipaddr; unsigned short portno; } *

variable_types:
data
void *

variable_types: len int

variable_types: tmout int


decompiled_code:
__int64 __fastcall udp_rcv_dat(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
ID_CHECK();
NUL_CHECK(a3);
LEN_CHECK(a4);
TMO_CHECK(a5);
return 4294967279LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
ID_CHECK();
NUL_CHECK(a3);
LEN_CHECK(a4);
TMO_CHECK(a5);
return 4294967279LL;
}

original_code:
ER udp_rcv_dat(ID cepid, T_IPV4EP *p_dstaddr, VP data, INT len, TMO tmout)
{
 ID_CHECK(cepid);
 NUL_CHECK(data);
 LEN_CHECK(len);
 TMO_CHECK(tmout);
 return (-17);
}

canonical_original_code:
int udp_rcv_dat(int cepid, struct t_ipv4ep *p_dstaddr, void *data, int len, int tmout)
{
 ID_CHECK(cepid);
 NUL_CHECK(data);
 LEN_CHECK(len);
 TMO_CHECK(tmout);
 return (-17);
}


original_code:
ER udp_can_cep(ID cepid, FN fncd)
{
 ID_CHECK(cepid);
 switch (fncd) {
  case (-0x223):
   break;
  case (-0x224):
   break;
  case (0):
   break;
  default:
   return (-63);
 }
 return (-17);
}

canonical_original_code:
int udp_can_cep(int cepid, short fncd)
{
 ID_CHECK(cepid);
 switch (fncd) {
  case (-0x223):
   break;
  case (-0x224):
   break;
  case (0):
   break;
  default:
   return (-63);
 }
 return (-17);
}

variable_types: fncd short


decompiled_code:
__int64 __fastcall udp_set_opt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
ID_CHECK();
NUL_CHECK(a3);
LEN_CHECK(a4);
return 4294967279LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
ID_CHECK();
NUL_CHECK(a3);
LEN_CHECK(a4);
return 4294967279LL;
}

original_code:
ER udp_set_opt(ID cepid, INT optname, VP optval, INT optlen)
{
 ID_CHECK(cepid);
 NUL_CHECK(optval);
 LEN_CHECK(optlen);
 return (-17);
}

canonical_original_code:
int udp_set_opt(int cepid, int optname, void *optval, int optlen)
{
 ID_CHECK(cepid);
 NUL_CHECK(optval);
 LEN_CHECK(optlen);
 return (-17);
}

variable_types: optname int

variable_types:
optval
void *

variable_types: optlen int


decompiled_code:
// attributes: thunk
__int64 __fastcall udp_get_opt(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
return udp_set_opt(a1, a2, a3, a4);
}

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

original_code:
ER udp_get_opt(ID cepid, INT optname, VP optval, INT optlen)
{
 ID_CHECK(cepid);
 NUL_CHECK(optval);
 LEN_CHECK(optlen);
 return (-17);
}

canonical_original_code:
int udp_get_opt(int cepid, int optname, void *optval, int optlen)
{
 ID_CHECK(cepid);
 NUL_CHECK(optval);
 LEN_CHECK(optlen);
 return (-17);
}


read

decompiled_code:
void read()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
read (int fd, void *buf, int size)
{
  return (call_lowlib (25, fd, buf, size));
}

canonical_original_code:
int read(int fd, void *buf, int size)
{
  return (call_lowlib (25, fd, buf, size));
}

variable_types: fd int

variable_types:
buf
void *

variable_types: size int


decompiled_code:
__int64 MitnMath_Neg()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
v2 = -v2;
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
v2 = -v2;
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
return result;
}

original_code:
ER
MitnMath_Neg(void)
{
  Cell *c;
  long n;
  ER result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n, c);
  if ((result) != (0)) { return (result); };
  n = 0 - n;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

canonical_original_code:
int MitnMath_Neg()
{
  struct _cell *c;
  long n;
  int result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n, c);
  if ((result) != (0)) { return (result); };
  n = 0 - n;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

variable_types: struct _cell { char mark; unsigned long type; struct _cell *prev; struct _cell *next; union { long inum; double dnum; struct { char str[48]; long length; } string; struct { struct _cell *link; char str[48]; } name; int (*mitn_func)(); struct { long arg_num; int (*func)(int argc, char *argv[]); } trad; struct _cell *link; } value; } *

variable_types: n long

variable_types: result int


decompiled_code:
__int64 MitnMath_Add()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
__int64 v2; // [rsp+10h] [rbp-18h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
MitnCell_GetLongFromCell(&v3, v1);
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
__int64 v2; // [rsp+10h] [rbp-18h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
MitnCell_GetLongFromCell(&v3, v1);
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
}
return result;
}

original_code:
ER
MitnMath_Add(void)
{
  Cell *c;
  long n1, n2, n;
  ER result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n1, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n2, c);
  n = n2 + n1;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

canonical_original_code:
int MitnMath_Add()
{
  struct _cell *c;
  long n1; long n2; long n;
  int result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n1, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n2, c);
  n = n2 + n1;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

user_defined_types: struct _cell { char mark; unsigned long type; struct _cell *prev; struct _cell *next; union { long inum; double dnum; struct { char str[48]; long length; } string; struct { struct _cell *link; char str[48]; } name; int (*mitn_func)(); struct { long arg_num; int (*func)(int argc, char *argv[]); } trad; struct _cell *link; } value; }


decompiled_code:
__int64 MitnMath_Sub()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
__int64 v2; // [rsp+10h] [rbp-18h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
MitnCell_GetLongFromCell(&v3, v1);
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
__int64 v2; // [rsp+10h] [rbp-18h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
MitnCell_GetLongFromCell(&v3, v1);
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
}
return result;
}

original_code:
ER
MitnMath_Sub(void)
{
  Cell *c;
  long n1, n2, n;
  ER result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n1, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n2, c);
  n = n2 - n1;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

canonical_original_code:
int MitnMath_Sub()
{
  struct _cell *c;
  long n1; long n2; long n;
  int result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n1, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n2, c);
  n = n2 - n1;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}


decompiled_code:
__int64 MitnMath_Mul()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
__int64 v2; // [rsp+10h] [rbp-18h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
MitnCell_GetLongFromCell(&v3, v1);
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
__int64 v2; // [rsp+10h] [rbp-18h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
MitnCell_GetLongFromCell(&v3, v1);
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
}
return result;
}

original_code:
ER
MitnMath_Mul(void)
{
  Cell *c;
  long n1, n2, n;
  ER result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n1, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n2, c);
  n = n2 * n1;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

canonical_original_code:
int MitnMath_Mul()
{
  struct _cell *c;
  long n1; long n2; long n;
  int result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n1, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n2, c);
  n = n2 * n1;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}


decompiled_code:
__int64 MitnMath_Div()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
__int64 v2; // [rsp+10h] [rbp-18h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
MitnCell_GetLongFromCell(&v3, v1);
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
__int64 v2; // [rsp+10h] [rbp-18h] BYREF
__int64 v3; // [rsp+18h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(&v2, v1);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, &v1);
if ( !(_DWORD)result )
{
MitnCell_GetLongFromCell(&v3, v1);
result = MitnCell_GetCellAsLong(&v1);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v1);
}
}
}
return result;
}

original_code:
ER
MitnMath_Div(void)
{
  Cell *c;
  long n1, n2, n;
  ER result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n1, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n2, c);
  n = n2 / n1;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

canonical_original_code:
int MitnMath_Div()
{
  struct _cell *c;
  long n1; long n2; long n;
  int result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n1, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&n2, c);
  n = n2 / n1;
  result = MitnCell_GetCellAsLong(&c, n);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}


decompiled_code:
__int64 __fastcall write_char(char a1)
{
__int64 v1; // rsi
__int64 v2; // rbp
__int64 result; // rax

if ( (unsigned __int8)a1 > 0x1Fu )
{
v1 = qword_488;
LOWORD(v2) = curpos;
if ( a1 >= 0 )
{
v2 = curpos + 1;
write_vram_xy_constprop_0(curpos, qword_488, (unsigned __int8)a1);
curpos = v2;
if ( v2 > 79 )
{
++v1;
LOWORD(v2) = 0;
curpos = 0LL;
qword_488 = v1;
if ( v1 > 24 )
{
qword_488 = 24LL;
scroll_up();
LOWORD(v1) = 24;
}
}
}
goto LABEL_6;
}
switch ( a1 )
{
case 9:
next_tab();
goto_cursol(curpos, qword_488);
result = 0LL;
break;
case 10:
caridge_return();
LOWORD(v1) = qword_488;
LOWORD(v2) = curpos;
goto LABEL_6;
case 8:
backspace();
goto_cursol(curpos, qword_488);
result = 0LL;
break;
default:
LOWORD(v1) = qword_488;
LOWORD(v2) = curpos;
LABEL_6:
goto_cursol(v2, v1);
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
__int64 v1; // rsi
__int64 v2; // rbp
__int64 result; // rax

if ( (unsigned __int8)a1 > 0x1Fu )
{
v1 = qword_488;
LOWORD(v2) = curpos;
if ( a1 >= 0 )
{
v2 = curpos + 1;
func0(curpos, qword_488, (unsigned __int8)a1);
curpos = v2;
if ( v2 > 79 )
{
++v1;
LOWORD(v2) = 0;
curpos = 0LL;
qword_488 = v1;
if ( v1 > 24 )
{
qword_488 = 24LL;
func1();
LOWORD(v1) = 24;
}
}
}
goto LABEL_6;
}
switch ( a1 )
{
case 9:
func3();
func4(curpos, qword_488);
result = 0LL;
break;
case 10:
func2();
LOWORD(v1) = qword_488;
LOWORD(v2) = curpos;
goto LABEL_6;
case 8:
func7();
func4(curpos, qword_488);
result = 0LL;
break;
default:
LOWORD(v1) = qword_488;
LOWORD(v2) = curpos;
LABEL_6:
func4(v2, v1);
return 0LL;
}
return result;
}

original_code:
ER
write_char (UB ch)
{
  if (ch < 0x20)
    {
      switch (ch)
 {
 case '\n':
   caridge_return ();
   break;
 case '\t':
   next_tab ();
   break;
 case '\b':
   backspace ();
   break;
 }
    }
  else if (ch <= 0x7f)
    {
      write_vram_xy (curpos.x, curpos.y, ch, 0);
      curpos.x++;
      if (curpos.x >= 80)
 {
   curpos.y++;
   curpos.x = 0;
   if (curpos.y >= 25)
     {
       curpos.y = 25 - 1;
       scroll_up ();
     }
 }
    }
  goto_cursol (curpos.x, curpos.y);
  return ((0));
}

canonical_original_code:
int write_char(unsigned char ch)
{
  if (ch < 0x20)
    {
      switch (ch)
 {
 case '\n':
   caridge_return ();
   break;
 case '\t':
   next_tab ();
   break;
 case '\b':
   backspace ();
   break;
 }
    }
  else if (ch <= 0x7f)
    {
      write_vram_xy (curpos.x, curpos.y, ch, 0);
      curpos.x++;
      if (curpos.x >= 80)
 {
   curpos.y++;
   curpos.x = 0;
   if (curpos.y >= 25)
     {
       curpos.y = 25 - 1;
       scroll_up ();
     }
 }
    }
  goto_cursol (curpos.x, curpos.y);
  return ((0));
}

variable_types:
ch
unsigned char


decompiled_code:
__int64 clear_console()
{
__int64 i; // rsi
__int64 j; // rdi

for ( i = 0LL; i != 25; ++i )
{
for ( j = 0LL; j != 80; ++j )
write_vram_xy_constprop_0(j, i, 32LL);
}
return set_curpos(0LL, 0LL);
}

original_code:
void
clear_console (void)
{
  W x, y;
  for (y = 0; y < 25; y++)
    for (x = 0; x < 80; x++)
      {
 write_vram_xy (x, y, ' ', 0xE1);
      }
  set_curpos (0, 0);
}

canonical_original_code:
void clear_console()
{
  long x; long y;
  for (y = 0; y < 25; y++)
    for (x = 0; x < 80; x++)
      {
 write_vram_xy (x, y, ' ', 0xE1);
      }
  set_curpos (0, 0);
}

variable_types: x long

variable_types: y long


decompiled_code:
__int64 scroll_up()
{
__int64 i; // rdi
__int64 result; // rax

memmove((void *)0x800B8000LL, (const void *)0x800B80A0LL, 0xF00uLL);
for ( i = 0LL; i != 81; ++i )
result = write_vram_xy_constprop_0(i, 24LL, 32LL);
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 i; // rdi
__int64 result; // rax

memmove((void *)0x800B8000LL, (const void *)0x800B80A0LL, 0xF00uLL);
for ( i = 0LL; i != 81; ++i )
result = func0(i, 24LL, 32LL);
return result;
}

original_code:
static void
scroll_up (void)
{
  UH *addr;
  W i;
  addr = (unsigned short *)0x800B8000;
  for (i = 0; i < 2000 - 80; i++)
    {
      addr[i] = addr[i + 80];
    }
  for (i = 0; i <= 80; i++)
    {
      write_vram_xy (i, 25 - 1, ' ', 0xe1);
    }
}

canonical_original_code:
static void scroll_up()
{
  unsigned short *addr;
  long i;
  addr = (unsigned short *)0x800B8000;
  for (i = 0; i < 2000 - 80; i++)
    {
      addr[i] = addr[i + 80];
    }
  for (i = 0; i <= 80; i++)
    {
      write_vram_xy (i, 25 - 1, ' ', 0xe1);
    }
}

variable_types:
addr
unsigned short *

variable_types: i long


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

curpos = 0LL;
result = qword_488 + 1;
if ( qword_488 + 1 > 24 )
{
qword_488 = 24LL;
result = scroll_up();
}
else
{
++qword_488;
}
return result;
}

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

curpos = 0LL;
result = qword_488 + 1;
if ( qword_488 + 1 > 24 )
{
qword_488 = 24LL;
result = func1();
}
else
{
++qword_488;
}
return result;
}

original_code:
static void
caridge_return (void)
{
  curpos.x = 0;
  curpos.y++;
  if (curpos.y >= 25)
    {
      curpos.x = 0;
      curpos.y = 25 - 1;
      scroll_up ();
    }
}

canonical_original_code:
static void caridge_return()
{
  curpos.x = 0;
  curpos.y++;
  if (curpos.y >= 25)
    {
      curpos.x = 0;
      curpos.y = 25 - 1;
      scroll_up ();
    }
}


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

if ( (curpos & 7) != 0 )
result = curpos
+ ((unsigned __int64)(curpos >> 63) >> 61)
- (((_BYTE)curpos + ((unsigned __int64)(curpos >> 63) >> 61)) & 7)
+ 8;
else
result = curpos + 8;
curpos = result;
if ( result > 79 )
{
result = qword_488 + 1;
qword_488 = result;
if ( result > 24 )
{
curpos = 0LL;
qword_488 = 24LL;
result = scroll_up();
}
}
return result;
}

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

if ( (curpos & 7) != 0 )
result = curpos
+ ((unsigned __int64)(curpos >> 63) >> 61)
- (((_BYTE)curpos + ((unsigned __int64)(curpos >> 63) >> 61)) & 7)
+ 8;
else
result = curpos + 8;
curpos = result;
if ( result > 79 )
{
result = qword_488 + 1;
qword_488 = result;
if ( result > 24 )
{
curpos = 0LL;
qword_488 = 24LL;
result = func1();
}
}
return result;
}

original_code:
static void
next_tab ()
{
  if ((curpos.x % 8) == 0)
    {
      curpos.x += 8;
    }
  else
    {
      curpos.x += (8 - (curpos.x % 8));
    }
  if (curpos.x >= 80)
    {
      curpos.y++;
      if (curpos.y >= 25)
 {
   curpos.x = 0;
   curpos.y = 25 - 1;
   scroll_up ();
 }
    }
}

canonical_original_code:
static void next_tab()
{
  if ((curpos.x % 8) == 0)
    {
      curpos.x += 8;
    }
  else
    {
      curpos.x += (8 - (curpos.x % 8));
    }
  if (curpos.x >= 80)
    {
      curpos.y++;
      if (curpos.y >= 25)
 {
   curpos.x = 0;
   curpos.y = 25 - 1;
   scroll_up ();
 }
    }
}


decompiled_code:
__int64 __fastcall goto_cursol(__int16 a1, __int16 a2)
{
__int16 v2; // bx

v2 = a1 + 80 * a2;
dis_int();
outb(0xD4u, 0xEu);
outb(0xD5u, HIBYTE(v2));
outb(0xD4u, 0xFu);
outb(0xD5u, (unsigned __int8)v2);
return ena_int();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1, __int16 a2)
{
__int16 v2; // bx

v2 = a1 + 80 * a2;
dis_int();
outb(0xD4u, 0xEu);
outb(0xD5u, HIBYTE(v2));
outb(0xD4u, 0xFu);
outb(0xD5u, (unsigned __int8)v2);
return ena_int();
}

original_code:
void
goto_cursol (W x, W y)
{
  W addr;
  dis_int ();
  addr = x + (y * 80);
  outb (0x03d4, 0x0e);
  outb (0x03d5, (addr >> 8) & 0xff);
  outb (0x03d4, 0x0f);
  outb (0x03d5, addr & 0xff);
  ena_int ();
}

canonical_original_code:
void goto_cursol(long x, long y)
{
  long addr;
  dis_int ();
  addr = x + (y * 80);
  outb (0x03d4, 0x0e);
  outb (0x03d5, (addr >> 8) & 0xff);
  outb (0x03d4, 0x0f);
  outb (0x03d5, addr & 0xff);
  ena_int ();
}

variable_types: addr long


decompiled_code:
__int64 __fastcall set_curpos(__int64 a1, __int64 a2)
{
curpos = a1;
qword_488 = a2;
return goto_cursol(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
curpos = a1;
qword_488 = a2;
return func4(a1, a2);
}

original_code:
void
set_curpos (W x, W y)
{
  curpos.x = x;
  curpos.y = y;
  goto_cursol (x, y);
}

canonical_original_code:
void set_curpos(long x, long y)
{
  curpos.x = x;
  curpos.y = y;
  goto_cursol (x, y);
}


decompiled_code:
__int64 __fastcall move_curpos(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 v3; // rsi
__int64 result; // rax

v2 = curpos + a1;
if ( v2 < 0 )
{
curpos = 0LL;
LOWORD(v2) = 0;
LABEL_4:
v3 = qword_488 + a2;
if ( v3 >= 0 )
goto LABEL_5;
LABEL_8:
qword_488 = 0LL;
return goto_cursol(v2, 0);
}
if ( v2 <= 79 )
{
curpos = v2;
goto LABEL_4;
}
curpos = 79LL;
LOWORD(v2) = 79;
v3 = qword_488 + a2;
if ( v3 < 0 )
goto LABEL_8;
LABEL_5:
if ( v3 > 79 )
{
qword_488 = 24LL;
result = goto_cursol(v2, 24);
}
else
{
qword_488 = v3;
result = goto_cursol(v2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 v3; // rsi
__int64 result; // rax

v2 = curpos + a1;
if ( v2 < 0 )
{
curpos = 0LL;
LOWORD(v2) = 0;
LABEL_4:
v3 = qword_488 + a2;
if ( v3 >= 0 )
goto LABEL_5;
LABEL_8:
qword_488 = 0LL;
return func4(v2, 0);
}
if ( v2 <= 79 )
{
curpos = v2;
goto LABEL_4;
}
curpos = 79LL;
LOWORD(v2) = 79;
v3 = qword_488 + a2;
if ( v3 < 0 )
goto LABEL_8;
LABEL_5:
if ( v3 > 79 )
{
qword_488 = 24LL;
result = func4(v2, 24);
}
else
{
qword_488 = v3;
result = func4(v2, v3);
}
return result;
}

original_code:
void
move_curpos (W x, W y)
{
  curpos.x += x;
  if (curpos.x < 0) curpos.x = 0;
  else if (curpos.x >= 80) curpos.x = 80 -1;
  curpos.y += y;
  if (curpos.y < 0) curpos.y = 0;
  else if (curpos.y >= 80) curpos.y = 25 -1;
  goto_cursol (curpos.x, curpos.y);
}

canonical_original_code:
void move_curpos(long x, long y)
{
  curpos.x += x;
  if (curpos.x < 0) curpos.x = 0;
  else if (curpos.x >= 80) curpos.x = 80 -1;
  curpos.y += y;
  if (curpos.y < 0) curpos.y = 0;
  else if (curpos.y >= 80) curpos.y = 25 -1;
  goto_cursol (curpos.x, curpos.y);
}


backspace

decompiled_code:
__int64 backspace()
{
__int64 v0; // rdi
__int64 v1; // rsi

v0 = curpos;
v1 = qword_488;
if ( curpos <= 0 )
{
if ( qword_488 > 0 )
{
v1 = qword_488 - 1;
v0 = 79LL;
curpos = 79LL;
--qword_488;
}
}
else
{
v0 = --curpos;
}
write_vram_xy_constprop_0(v0, v1, 32LL);
return goto_cursol(v0, v1);
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rdi
__int64 v1; // rsi

v0 = curpos;
v1 = qword_488;
if ( curpos <= 0 )
{
if ( qword_488 > 0 )
{
v1 = qword_488 - 1;
v0 = 79LL;
curpos = 79LL;
--qword_488;
}
}
else
{
v0 = --curpos;
}
func0(v0, v1, 32LL);
return func4(v0, v1);
}

original_code:
static void
backspace ()
{
  if (curpos.x <= 0)
    {
      if (curpos.y > 0)
 {
   curpos.x = 80 - 1;
   curpos.y--;
 }
    }
  else
    {
      curpos.x--;
    }
  write_vram_xy (curpos.x, curpos.y, ' ', 0);
  goto_cursol (curpos.x, curpos.y);
}

canonical_original_code:
static void backspace()
{
  if (curpos.x <= 0)
    {
      if (curpos.y > 0)
 {
   curpos.x = 80 - 1;
   curpos.y--;
 }
    }
  else
    {
      curpos.x--;
    }
  write_vram_xy (curpos.x, curpos.y, ' ', 0);
  goto_cursol (curpos.x, curpos.y);
}


decompiled_code:
__int64 clear_rest_line()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 v2; // rdi

result = curpos;
v1 = qword_488;
v2 = curpos + 1;
if ( curpos + 1 <= 79 )
{
do
result = write_vram_xy_constprop_0(v2++, v1, 32LL);
while ( v2 != 80 );
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 v2; // rdi

result = curpos;
v1 = qword_488;
v2 = curpos + 1;
if ( curpos + 1 <= 79 )
{
do
result = func0(v2++, v1, 32LL);
while ( v2 != 80 );
}
return result;
}

original_code:
void
clear_rest_line(void)
{
  W x, y;
  y = curpos.y;
  for(x = curpos.x+1; x < 80; x++) {
    write_vram_xy (x, y, ' ', 0xE1);
  }
}

canonical_original_code:
void clear_rest_line()
{
  long x; long y;
  y = curpos.y;
  for(x = curpos.x+1; x < 80; x++) {
    write_vram_xy (x, y, ' ', 0xE1);
  }
}


decompiled_code:
__int64 clear_rest_screen()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 i; // rdi

clear_rest_line();
result = qword_488;
v1 = qword_488 + 1;
if ( qword_488 + 1 <= 24 )
{
do
{
for ( i = 0LL; i != 80; ++i )
result = write_vram_xy_constprop_0(i, v1, 32LL);
++v1;
}
while ( v1 != 25 );
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax
__int64 v1; // rsi
__int64 i; // rdi

func10();
result = qword_488;
v1 = qword_488 + 1;
if ( qword_488 + 1 <= 24 )
{
do
{
for ( i = 0LL; i != 80; ++i )
result = func0(i, v1, 32LL);
++v1;
}
while ( v1 != 25 );
}
return result;
}

original_code:
void
clear_rest_screen(void)
{
  W x, y;
  clear_rest_line();
  for (y = curpos.y+1; y < 25; y++)
    for (x = 0; x < 80; x++)
      {
 write_vram_xy (x, y, ' ', 0xE1);
      }
}

canonical_original_code:
void clear_rest_screen()
{
  long x; long y;
  clear_rest_line();
  for (y = curpos.y+1; y < 25; y++)
    for (x = 0; x < 80; x++)
      {
 write_vram_xy (x, y, ' ', 0xE1);
      }
}


decompiled_code:
__int64 __fastcall do_access(__int64 a1)
{
return send_error_reply(a1, 3LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return send_error_reply(a1, 3LL);
}

original_code:
void
do_access (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_access(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

variable_types: struct fm_msg { struct SVC_REQ { int mbfid; long msgtyp; int tskid; long len; unsigned long arg[]; } header; union { struct file_access_req { char path[255]; int mode; } file_access_req; struct file_setattr_req { char path[255]; int mode; } file_setattr_req; } body; } *

user_defined_types: struct fm_msg { struct SVC_REQ header; union { struct file_access_req file_access_req; struct file_setattr_req file_setattr_req; } body; }


decompiled_code:
// attributes: thunk
__int64 __fastcall do_lookup(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_lookup (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_lookup(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

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

user_defined_types: struct file_access_req { char path[255]; int mode; }

user_defined_types: struct file_setattr_req { char path[255]; int mode; }


decompiled_code:
// attributes: thunk
__int64 __fastcall do_close(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_close (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_close(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_getattr(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_getattr (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_getattr(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_setattr(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_setattr (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_setattr(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_read(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_read (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_read(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_write(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_write (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_write(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_tranc(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_tranc (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_tranc(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_mkdir(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_mkdir (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_mkdir(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_rmdir(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_rmdir (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_rmdir(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_mknod(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_mknod (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_mknod(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_rmnod(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_rmnod (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_rmnod(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_link(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_link (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_link(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_remove(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_remove (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_remove(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_select(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_select (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_select(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_control(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_control (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_control(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_move(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_move (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_move(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_mountroot(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_mountroot (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_mountroot(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_mount(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_mount (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_mount(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall do_unmount(__int64 a1)
{
return do_access(a1);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
return func0(a1);
}

original_code:
void
do_unmount (fm_msg_t *req)
{
  send_error_reply (req, FILE_ENOSPT);
}

canonical_original_code:
void do_unmount(struct fm_msg *req)
{
  send_error_reply (req, FILE_ENOSPT);
}


misc

decompiled_code:
__int64 __fastcall misc(unsigned int a1, unsigned int a2, __int64 a3)
{
return call_lowlib(65LL, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, __int64 a3)
{
return call_lowlib(65LL, a1, a2, a3);
}

original_code:
int
misc (int cmd, int len, void *argp)
{
  return (call_lowlib (65, cmd, len, argp));
}

canonical_original_code:
int misc(int cmd, int len, void *argp)
{
  return (call_lowlib (65, cmd, len, argp));
}

variable_types: cmd int

variable_types: len int

variable_types:
argp
void *


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

motor_goal = 0;
result = (unsigned int)motor_status;
if ( motor_status )
{
outb(0xF2u, 0xCu);
result = (unsigned int)motor_goal;
motor_status = motor_goal;
}
return result;
}

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

motor_goal = 0;
result = (unsigned int)motor_status;
if ( motor_status )
{
outb(0xF2u, 0xCu);
result = (unsigned int)motor_goal;
motor_status = motor_goal;
}
return result;
}

original_code:
void sm_handler(VP drive)
{
  motor_goal = 0;
  if (motor_goal != motor_status) {
 outb (0x3f2, (motor_goal << 4) | 0x0c);
 motor_status = motor_goal;
  }
}

canonical_original_code:
void sm_handler(void *drive)
{
  motor_goal = 0;
  if (motor_goal != motor_status) {
 outb (0x3f2, (motor_goal << 4) | 0x0c);
 motor_status = motor_goal;
  }
}

variable_types:
drive
void *


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

LOBYTE(result) = inb(0x3F4u);
return (int)result;
}

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

LOBYTE(result) = inb(0x3F4u);
return (int)result;
}

original_code:
W
read_fdc (void)
{
  return (inb (0x3f4));
}

canonical_original_code:
long read_fdc()
{
  return (inb (0x3f4));
}


decompiled_code:
__int64 ready_check()
{
int v0; // ebx
__int64 result; // rax

v0 = 10;
while ( 1 )
{
result = read_fdc() & 0x10;
if ( !(_DWORD)result )
break;
if ( !--v0 )
return (int)result;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // ebx
__int64 result; // rax

v0 = 10;
while ( 1 )
{
result = func3() & 0x10;
if ( !(_DWORD)result )
break;
if ( !--v0 )
return (int)result;
}
return 0LL;
}

original_code:
W
ready_check (void)
{
  int i;
  int status;
  for (i = 0; i < 10; i++)
    {
      status = read_fdc ();
      status = status & 0x10;
      if (status == 0)
 break;
    }
  return (status);
}

canonical_original_code:
long ready_check()
{
  int i;
  int status;
  for (i = 0; i < 10; i++)
    {
      status = read_fdc ();
      status = status & 0x10;
      if (status == 0)
 break;
    }
  return (status);
}

variable_types: i int

variable_types: status int


specify

decompiled_code:
__int64 specify()
{
ready_check();
write_fdc(3u);
write_fdc(0xDFu);
write_fdc(2u);
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
func4();
func1(3u);
func1(0xDFu);
func1(2u);
return 0LL;
}

original_code:
W
specify (W drive, UW srt, UW hut, UW hlt, UW nd)
{
  ready_check ();
  write_fdc (0x03);
  write_fdc (0xdf);
  write_fdc (0x02);
  return (0);
}

canonical_original_code:
long specify(long drive, unsigned long srt, unsigned long hut, unsigned long hlt, unsigned long nd)
{
  ready_check ();
  write_fdc (0x03);
  write_fdc (0xdf);
  write_fdc (0x02);
  return (0);
}

variable_types: drive long

variable_types:
srt
unsigned long

variable_types:
hut
unsigned long

variable_types:
hlt
unsigned long

variable_types:
nd
unsigned long


decompiled_code:
__int64 __fastcall reset_fdc(__int64 a1)
{
specify(
a1,
*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 64LL),
*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 72LL),
*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 80LL),
*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 88LL));
outb(0xF7u, 0);
return 1LL;
}

original_code:
W
reset_fdc (W drive)
{
  W data;
  UW result[8];
  W count;
  W i;
  specify (drive,
    fd_data[drive]->srt,
    fd_data[drive]->hut,
    fd_data[drive]->hlt,
    fd_data[drive]->nd);
  outb (0x3f7, 0x00);
  return ((1));
}

canonical_original_code:
long reset_fdc(long drive)
{
  long data;
  unsigned long result[8];
  long count;
  long i;
  specify (drive,
    fd_data[drive]->srt,
    fd_data[drive]->hut,
    fd_data[drive]->hlt,
    fd_data[drive]->nd);
  outb (0x3f7, 0x00);
  return ((1));
}

variable_types: data long

variable_types:
result
unsigned long [8]

variable_types: count long


decompiled_code:
__int64 fdc_sense()
{
int v0; // ebx
int v1; // eax
unsigned __int8 v2; // r8
__int64 v3; // rax

v0 = 0;
LOBYTE(v1) = inb(0x3F4u);
while ( v1 != 208 )
{
LABEL_5:
v1 = inb(0x3F4u) & 0xD0;
if ( v1 == 128 )
return 1LL;
}
if ( v0 <= 7 )
{
v2 = inb(0x3F5u);
v3 = v0++;
fd_status[v3 + 1] = v2;
goto LABEL_5;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
int v0; // ebx
int v1; // eax
unsigned __int8 v2; // r8
__int64 v3; // rax

v0 = 0;
LOBYTE(v1) = inb(0x3F4u);
while ( v1 != 208 )
{
LABEL_5:
v1 = inb(0x3F4u) & 0xD0;
if ( v1 == 128 )
return 1LL;
}
if ( v0 <= 7 )
{
v2 = inb(0x3F5u);
v3 = v0++;
fd_status[v3 + 1] = v2;
goto LABEL_5;
}
return 0LL;
}

original_code:
BOOL
fdc_sense ()
{
  int result_nr = 0;
  int status;
  status = inb (0x3f4);
  for (;;)
    {
      if (status == (0x80 | 0x40 | 0x10))
 {
   if (result_nr >= 8)
     {
       break;
     }
   fd_status.status_data[result_nr++] = inb (0x3f5);
 }
      status = inb (0x3f4) & (0x80 | 0x40 | 0x10);
      if (status == 0x80)
 {
   return (TRUE);
 }
    }
  return (FALSE);
}

canonical_original_code:
enum BOOL fdc_sense()
{
  int result_nr = 0;
  int status;
  status = inb (0x3f4);
  for (;;)
    {
      if (status == (0x80 | 0x40 | 0x10))
 {
   if (result_nr >= 8)
     {
       break;
     }
   fd_status.status_data[result_nr++] = inb (0x3f5);
 }
      status = inb (0x3f4) & (0x80 | 0x40 | 0x10);
      if (status == 0x80)
 {
   return (TRUE);
 }
    }
  return (FALSE);
}

return_type: enum BOOL { FALSE=0, TRUE=1 }


decompiled_code:
__int64 __fastcall read_result(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rbx
int v6; // eax

result = read_fdc() & 0x40;
if ( (_DWORD)result )
{
v5 = 0LL;
if ( a3 > 0 )
{
do
{
LOBYTE(v6) = inb(0x3F5u);
*(_QWORD *)(a2 + 8 * v5++) = v6;
}
while ( a3 != v5 );
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rbx
int v6; // eax

result = func3() & 0x40;
if ( (_DWORD)result )
{
v5 = 0LL;
if ( a3 > 0 )
{
do
{
LOBYTE(v6) = inb(0x3F5u);
*(_QWORD *)(a2 + 8 * v5++) = v6;
}
while ( a3 != v5 );
}
result = 1LL;
}
return result;
}

original_code:
W
read_result (W drive, UW *result, W n)
{
  W i;
  W sense;
  sense = read_fdc ();
  if (sense & 0x40)
    {
      for (i = 0; i < n; i++)
 {
   result[i] = inb (0x3f5);
 }
      return ((1));
    }
  return ((0));
}

canonical_original_code:
long read_result(long drive, unsigned long *result, long n)
{
  long i;
  long sense;
  sense = read_fdc ();
  if (sense & 0x40)
    {
      for (i = 0; i < n; i++)
 {
   result[i] = inb (0x3f5);
 }
      return ((1));
    }
  return ((0));
}

variable_types:
result
unsigned long *

variable_types: n long

variable_types: i long

variable_types: sense long


decompiled_code:
__int64 __fastcall sense_interrupt(__int64 a1, _BYTE *a2)
{
__int64 result; // rax

write_fdc(8u);
result = read_result(a1, (__int64)a2, 2LL);
if ( result )
result = (*a2 & 0xC0) == 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, _BYTE *a2)
{
__int64 result; // rax

func1(8u);
result = func9(a1, (__int64)a2, 2LL);
if ( result )
result = (*a2 & 0xC0) == 0;
return result;
}

original_code:
W
sense_interrupt (W drive, UW *result)
{
  write_fdc (0x08);
  if (read_result (drive, result, 2) == (0))
    {
      return ((0));
    }
  if ((result[0] & 0xC0) == 0x00)
    {
      return ((1));
    }
  return ((0));
}

canonical_original_code:
long sense_interrupt(long drive, unsigned long *result)
{
  write_fdc (0x08);
  if (read_result (drive, result, 2) == (0))
    {
      return ((0));
    }
  if ((result[0] & 0xC0) == 0x00)
    {
      return ((1));
    }
  return ((0));
}


decompiled_code:
__int64 __fastcall sense_fdc(__int64 port)
{
__int64 result; // rax
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

ready_check();
intr_flag = 0LL;
write_fdc(4u);
write_fdc(port);
result = read_result(port, (__int64)&v2, 1LL);
if ( result )
result = (v2 & 0xA0) == 32;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 port)
{
__int64 result; // rax
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

func4();
intr_flag = 0LL;
func1(4u);
func1(port);
result = func9(port, (__int64)&v2, 1LL);
if ( result )
result = (v2 & 0xA0) == 32;
return result;
}

original_code:
W
sense_fdc (W drive)
{
  UW result [1];
  ready_check ();
  intr_flag = (0);
  write_fdc (0x04);
  write_fdc (drive);
  if (read_result (drive, result, 1) == (0))
    {
      return ((0));
    }
  if ((result[0] & 0x80) ||
      (result[0] & 0x20) == 0)
    {
      return ((0));
    }
  return ((1));
}

canonical_original_code:
long sense_fdc(long drive)
{
  unsigned long result[1];
  ready_check ();
  intr_flag = (0);
  write_fdc (0x04);
  write_fdc (drive);
  if (read_result (drive, result, 1) == (0))
    {
      return ((0));
    }
  if ((result[0] & 0x80) ||
      (result[0] & 0x20) == 0)
    {
      return ((0));
    }
  return ((1));
}

variable_types:
result
unsigned long [1]


original_code:
int
stop_motor (BYTE drive)
{
  motor_goal = 0;
  if (motor_goal != motor_status) {
 outb (0x3f2, (motor_goal << 4) | 0x0c);
 motor_status = motor_goal;
  }
  return (0);
}

canonical_original_code:
int stop_motor(unsigned char drive)
{
  motor_goal = 0;
  if (motor_goal != motor_status) {
 outb (0x3f2, (motor_goal << 4) | 0x0c);
 motor_status = motor_goal;
  }
  return (0);
}

variable_types:
drive
unsigned char


recalibrate

decompiled_code:
_BOOL8 __fastcall recalibrate(char a1)
{
ready_check();
dis_int();
intr_flag = 0LL;
write_fdc(7u);
write_fdc(a1 & 3);
ena_int();
wait_int((__int64)&intr_flag);
fdc_isense();
return fd_status[1] == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(char a1)
{
func4();
dis_int();
intr_flag = 0LL;
func1(7u);
func1(a1 & 3);
ena_int();
func14((__int64)&intr_flag);
func5();
return fd_status[1] == 0;
}

original_code:
W
recalibrate (W drive)
{
  UW result[2];
  UINT rflag;
  ready_check ();
  dis_int ();
  intr_flag = (0);
  write_fdc (0x07);
  write_fdc (drive & 0x03);
  ena_int ();
  wait_int (&intr_flag);
  fdc_isense ();
  if (fd_status.status_data[0] != 0)
    {
      return ((0));
    }
  return ((1));
}

canonical_original_code:
long recalibrate(long drive)
{
  unsigned long result[2];
  unsigned int rflag;
  ready_check ();
  dis_int ();
  intr_flag = (0);
  write_fdc (0x07);
  write_fdc (drive & 0x03);
  ena_int ();
  wait_int (&intr_flag);
  fdc_isense ();
  if (fd_status.status_data[0] != 0)
    {
      return ((0));
    }
  return ((1));
}

variable_types:
result
unsigned long [2]

variable_types:
rflag
unsigned int


seek

decompiled_code:
__int64 __fastcall seek(__int16 a1, char a2, __int64 a3)
{
__int64 v4; // r8

ready_check();
dis_int();
intr_flag = 0LL;
fd_status[1] = 0;
*(_WORD *)&fd_status[2] = 0;
write_fdc(0xFu);
write_fdc(a2 & 3 | (4 * a1));
write_fdc(a3);
ena_int();
wait_int((__int64)&intr_flag);
fdc_isense();
v4 = -101LL;
if ( (fd_status[1] & 0xF8) == 32 && (unsigned __int8)fd_status[2] == a3 )
v4 = 0LL;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int16 a1, char a2, __int64 a3)
{
__int64 v4; // r8

func4();
dis_int();
intr_flag = 0LL;
fd_status[1] = 0;
*(_WORD *)&fd_status[2] = 0;
func1(0xFu);
func1(a2 & 3 | (4 * a1));
func1(a3);
ena_int();
func14((__int64)&intr_flag);
func5();
v4 = -101LL;
if ( (fd_status[1] & 0xF8) == 32 && (unsigned __int8)fd_status[2] == a3 )
v4 = 0LL;
return v4;
}

original_code:
W
seek (W head, W drive, W cylinder)
{
  int i;
  int result;
  UINT rflag;
  ready_check ();
  dis_int ();
  intr_flag = (0);
  fd_status.status_data[0] = 0;
  fd_status.status_data[1] = 0;
  fd_status.status_data[2] = 0;
  write_fdc (0x0f);
  write_fdc ((head << 2) | (drive & 0x03));
  write_fdc (cylinder);
  ena_int ();
  wait_int (&intr_flag);
  fdc_isense ();
  if ((fd_status.status_data[0] & 0xF8) != 0x20) result = (-101);
  else if (fd_status.status_data[1] != cylinder) result = (-101);
  else result = (0);
  return (result);
}

canonical_original_code:
long seek(long head, long drive, long cylinder)
{
  int i;
  int result;
  unsigned int rflag;
  ready_check ();
  dis_int ();
  intr_flag = (0);
  fd_status.status_data[0] = 0;
  fd_status.status_data[1] = 0;
  fd_status.status_data[2] = 0;
  write_fdc (0x0f);
  write_fdc ((head << 2) | (drive & 0x03));
  write_fdc (cylinder);
  ena_int ();
  wait_int (&intr_flag);
  fdc_isense ();
  if ((fd_status.status_data[0] & 0xF8) != 0x20) result = (-101);
  else if (fd_status.status_data[1] != cylinder) result = (-101);
  else result = (0);
  return (result);
}

variable_types: head long

variable_types: cylinder long

variable_types: i int

variable_types: result int


decompiled_code:
__int64 __fastcall wait_int_with_timeout(__int64 a1)
{
if ( *(_QWORD *)a1 )
{
dis_int();
*(_QWORD *)a1 = 0LL;
ena_int();
}
else
{
dbg_printf("interrupt timeout error\n");
}
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
if ( *(_QWORD *)a1 )
{
dis_int();
*(_QWORD *)a1 = 0LL;
ena_int();
}
else
{
dbg_printf("interrupt timeout error\n");
}
return *(_QWORD *)a1;
}

original_code:
W
wait_int_with_timeout (W *flag, W timeout)
{
  W i;
  for (i = 0; i < timeout; i++)
    {
      if (*flag != (0))
 break;
    }
  if (*flag == (0))
    {
      dbg_printf ("interrupt timeout error\n");
      return (*flag);
    }
  dis_int ();
  *flag = (0);
  ena_int ();
  return (*flag);
}

canonical_original_code:
long wait_int_with_timeout(long *flag, long timeout)
{
  long i;
  for (i = 0; i < timeout; i++)
    {
      if (*flag != (0))
 break;
    }
  if (*flag == (0))
    {
      dbg_printf ("interrupt timeout error\n");
      return (*flag);
    }
  dis_int ();
  *flag = (0);
  ena_int ();
  return (*flag);
}

variable_types:
flag
long *

variable_types: timeout long


decompiled_code:
__int64 __fastcall wait_int(__int64 a1)
{
if ( !*(_QWORD *)a1 )
{
while ( 1 )
;
}
dis_int();
*(_QWORD *)a1 = 0LL;
ena_int();
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
if ( !*(_QWORD *)a1 )
{
while ( 1 )
;
}
dis_int();
*(_QWORD *)a1 = 0LL;
ena_int();
return *(_QWORD *)a1;
}

original_code:
W
wait_int (W *flag)
{
  while (*flag == (0))
    ;
  dis_int ();
  *flag = (0);
  ena_int ();
  return (*flag);
}

canonical_original_code:
long wait_int(long *flag)
{
  while (*flag == (0))
    ;
  dis_int ();
  *flag = (0);
  ena_int ();
  return (*flag);
}


decompiled_code:
__int64 __fastcall get_data(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
__int64 result; // rax
__int64 v9; // rax

on_motor(a1);
ready_check();
LODWORD(result) = seek(a2, a1, a3);
if ( (_DWORD)result )
return (int)result;
ready_check();
dis_int();
v9 = *((_QWORD *)&fd_data + a1);
intr_flag = 0LL;
setup_dma(*(_QWORD *)(v9 + 96), a5 & 0x7FFFFFFF, 68LL, *(_QWORD *)(v9 + 24), 2LL);
write_fdc(0xE6u);
write_fdc(a1 | (4 * a2));
write_fdc(a3);
write_fdc(a2);
write_fdc(a4);
write_fdc(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 40LL));
write_fdc(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 16LL));
write_fdc(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 56LL));
write_fdc(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 32LL));
ena_int();
wait_int((__int64)&intr_flag);
if ( (unsigned int)fdc_sense() == 1
&& (stop_motor(a1), !(fd_status[1] & 0xF8 | (unsigned __int8)(fd_status[3] | fd_status[2])))
&& *(_QWORD *)(*((_QWORD *)&fd_data + a1) + 24LL)
* (*(_DWORD *)(*((_QWORD *)&fd_data + a1) + 16LL)
* (((unsigned __int8)fd_status[4] - (int)a3) * *(_DWORD *)(*((_QWORD *)&fd_data + a1) + 8LL)
+ (unsigned __int8)fd_status[5]
- a2)
+ (unsigned __int8)fd_status[6]
- a4) == 512LL )
{
result = 0LL;
}
else
{
result = -101LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
__int64 result; // rax
__int64 v9; // rax

func12(a1);
func4();
LODWORD(result) = func16(a2, a1, a3);
if ( (_DWORD)result )
return (int)result;
func4();
dis_int();
v9 = *((_QWORD *)&fd_data + a1);
intr_flag = 0LL;
setup_dma(*(_QWORD *)(v9 + 96), a5 & 0x7FFFFFFF, 68LL, *(_QWORD *)(v9 + 24), 2LL);
func1(0xE6u);
func1(a1 | (4 * a2));
func1(a3);
func1(a2);
func1(a4);
func1(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 40LL));
func1(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 16LL));
func1(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 56LL));
func1(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 32LL));
ena_int();
func14((__int64)&intr_flag);
if ( (unsigned int)func8() == 1
&& (func13(a1), !(fd_status[1] & 0xF8 | (unsigned __int8)(fd_status[3] | fd_status[2])))
&& *(_QWORD *)(*((_QWORD *)&fd_data + a1) + 24LL)
* (*(_DWORD *)(*((_QWORD *)&fd_data + a1) + 16LL)
* (((unsigned __int8)fd_status[4] - (int)a3) * *(_DWORD *)(*((_QWORD *)&fd_data + a1) + 8LL)
+ (unsigned __int8)fd_status[5]
- a2)
+ (unsigned __int8)fd_status[6]
- a4) == 512LL )
{
result = 0LL;
}
else
{
result = -101LL;
}
return result;
}

original_code:
W
get_data (W drive, W head, W cylinder, W sector, B *buff)
{
  W i;
  int ret;
  int s;
  UINT rflag;
  on_motor (drive);
  ready_check ();
  ret = seek (head, drive, cylinder);
  if (ret != (0)) return (ret);
  ready_check ();
  dis_int ();
  intr_flag = (0);
  setup_dma ((fd_data[drive]->dmachan), (void *)(((W)buff) & 0x7fffffff), 0x44, (fd_data[drive]->length), 0x02 & 0x02);
  write_fdc (0xE6);
  write_fdc ((head << 2) | drive);
  write_fdc (cylinder);
  write_fdc (head);
  write_fdc (sector);
  write_fdc (fd_data[drive]->lencode);
  write_fdc (fd_data[drive]->sector);
  write_fdc (fd_data[drive]->gapskip);
  write_fdc (fd_data[drive]->dtl);
  ena_int ();
  wait_int (&intr_flag);
  ret = fdc_sense ();
  if (ret != (1)) return ((-101));
  stop_motor (drive);
  if ((fd_status.status_data[0] & 0xF8) != 0x00) {
    return ((-101));
  }
  if (fd_status.status_data[1] | fd_status.status_data[2]) return ((-101));
  s = (fd_status.status_data[3] - cylinder)
    * fd_data[drive]->head * fd_data[drive]->sector;
  s += (fd_status.status_data[4] - head) * fd_data[drive]->sector;
  s += (fd_status.status_data[5] - sector);
  if (s * (fd_data[drive]->length) != 512) return ((-101));
  else
    return ((0));
}

canonical_original_code:
long get_data(long drive, long head, long cylinder, long sector, char *buff)
{
  long i;
  int ret;
  int s;
  unsigned int rflag;
  on_motor (drive);
  ready_check ();
  ret = seek (head, drive, cylinder);
  if (ret != (0)) return (ret);
  ready_check ();
  dis_int ();
  intr_flag = (0);
  setup_dma ((fd_data[drive]->dmachan), (void *)(((long)buff) & 0x7fffffff), 0x44, (fd_data[drive]->length), 0x02 & 0x02);
  write_fdc (0xE6);
  write_fdc ((head << 2) | drive);
  write_fdc (cylinder);
  write_fdc (head);
  write_fdc (sector);
  write_fdc (fd_data[drive]->lencode);
  write_fdc (fd_data[drive]->sector);
  write_fdc (fd_data[drive]->gapskip);
  write_fdc (fd_data[drive]->dtl);
  ena_int ();
  wait_int (&intr_flag);
  ret = fdc_sense ();
  if (ret != (1)) return ((-101));
  stop_motor (drive);
  if ((fd_status.status_data[0] & 0xF8) != 0x00) {
    return ((-101));
  }
  if (fd_status.status_data[1] | fd_status.status_data[2]) return ((-101));
  s = (fd_status.status_data[3] - cylinder)
    * fd_data[drive]->head * fd_data[drive]->sector;
  s += (fd_status.status_data[4] - head) * fd_data[drive]->sector;
  s += (fd_status.status_data[5] - sector);
  if (s * (fd_data[drive]->length) != 512) return ((-101));
  else
    return ((0));
}

variable_types: drive long

variable_types: sector long

variable_types:
buff
char *

variable_types: ret int

variable_types: s int


decompiled_code:
__int64 __fastcall put_data(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
__int64 result; // rax
__int64 v9; // rax

on_motor(a1);
LODWORD(result) = seek(a2, a1, a3);
if ( (_DWORD)result )
return (int)result;
ready_check();
dis_int();
v9 = *((_QWORD *)&fd_data + a1);
intr_flag = 0LL;
setup_dma(*(_QWORD *)(v9 + 96), a5 & 0x7FFFFFFF, 72LL, *(_QWORD *)(v9 + 24), 2LL);
write_fdc(0xC5u);
write_fdc(a1 | (4 * a2));
write_fdc(a3);
write_fdc(a2);
write_fdc(a4);
write_fdc(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 40LL));
write_fdc(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 16LL));
write_fdc(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 56LL));
write_fdc(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 32LL));
ena_int();
wait_int((__int64)&intr_flag);
if ( (unsigned int)fdc_sense() == 1
&& (stop_motor(a1), !(fd_status[1] & 0xF8 | (unsigned __int8)(fd_status[3] | fd_status[2])))
&& *(_QWORD *)(*((_QWORD *)&fd_data + a1) + 24LL)
* (*(_DWORD *)(*((_QWORD *)&fd_data + a1) + 16LL)
* (((unsigned __int8)fd_status[4] - (int)a3) * *(_DWORD *)(*((_QWORD *)&fd_data + a1) + 8LL)
+ (unsigned __int8)fd_status[5]
- a2)
+ (unsigned __int8)fd_status[6]
- a4) == 512LL )
{
result = 0LL;
}
else
{
result = -101LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, int a2, __int64 a3, int a4, int a5)
{
__int64 result; // rax
__int64 v9; // rax

func12(a1);
LODWORD(result) = func16(a2, a1, a3);
if ( (_DWORD)result )
return (int)result;
func4();
dis_int();
v9 = *((_QWORD *)&fd_data + a1);
intr_flag = 0LL;
setup_dma(*(_QWORD *)(v9 + 96), a5 & 0x7FFFFFFF, 72LL, *(_QWORD *)(v9 + 24), 2LL);
func1(0xC5u);
func1(a1 | (4 * a2));
func1(a3);
func1(a2);
func1(a4);
func1(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 40LL));
func1(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 16LL));
func1(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 56LL));
func1(*(_QWORD *)(*((_QWORD *)&fd_data + a1) + 32LL));
ena_int();
func14((__int64)&intr_flag);
if ( (unsigned int)func8() == 1
&& (func13(a1), !(fd_status[1] & 0xF8 | (unsigned __int8)(fd_status[3] | fd_status[2])))
&& *(_QWORD *)(*((_QWORD *)&fd_data + a1) + 24LL)
* (*(_DWORD *)(*((_QWORD *)&fd_data + a1) + 16LL)
* (((unsigned __int8)fd_status[4] - (int)a3) * *(_DWORD *)(*((_QWORD *)&fd_data + a1) + 8LL)
+ (unsigned __int8)fd_status[5]
- a2)
+ (unsigned __int8)fd_status[6]
- a4) == 512LL )
{
result = 0LL;
}
else
{
result = -101LL;
}
return result;
}

original_code:
W
put_data (W drive, W head, W cylinder, W sector, B *buff)
{
  W i;
  int ret;
  int s;
  UINT rflag;
  on_motor (drive);
  ret = seek (head, drive, cylinder);
  if (ret != (0)) return (ret);
  ready_check ();
  dis_int ();
  intr_flag = (0);
  setup_dma ((fd_data[drive]->dmachan), (void *)(((W)buff) & 0x7fffffff), 0x48, (fd_data[drive]->length), 0x02 & 0x02);
  write_fdc (0xC5);
  write_fdc ((head << 2) | drive);
  write_fdc (cylinder);
  write_fdc (head);
  write_fdc (sector);
  write_fdc (fd_data[drive]->lencode);
  write_fdc (fd_data[drive]->sector);
  write_fdc (fd_data[drive]->gapskip);
  write_fdc (fd_data[drive]->dtl);
  ena_int ();
  wait_int (&intr_flag);
  ret = fdc_sense ();
  if (ret != (1)) return ((-101));
  stop_motor (drive);
  if ((fd_status.status_data[0] & 0xF8) != 0x00) return ((-101));
  if (fd_status.status_data[1] | fd_status.status_data[2]) return ((-101));
  s = (fd_status.status_data[3] - cylinder)
    * fd_data[drive]->head * fd_data[drive]->sector;
  s += (fd_status.status_data[4] - head) * fd_data[drive]->sector;
  s += (fd_status.status_data[5] - sector);
  if (s * (fd_data[drive]->length) != 512) return ((-101));
  else return ((0));
}

canonical_original_code:
long put_data(long drive, long head, long cylinder, long sector, char *buff)
{
  long i;
  int ret;
  int s;
  unsigned int rflag;
  on_motor (drive);
  ret = seek (head, drive, cylinder);
  if (ret != (0)) return (ret);
  ready_check ();
  dis_int ();
  intr_flag = (0);
  setup_dma ((fd_data[drive]->dmachan), (void *)(((long)buff) & 0x7fffffff), 0x48, (fd_data[drive]->length), 0x02 & 0x02);
  write_fdc (0xC5);
  write_fdc ((head << 2) | drive);
  write_fdc (cylinder);
  write_fdc (head);
  write_fdc (sector);
  write_fdc (fd_data[drive]->lencode);
  write_fdc (fd_data[drive]->sector);
  write_fdc (fd_data[drive]->gapskip);
  write_fdc (fd_data[drive]->dtl);
  ena_int ();
  wait_int (&intr_flag);
  ret = fdc_sense ();
  if (ret != (1)) return ((-101));
  stop_motor (drive);
  if ((fd_status.status_data[0] & 0xF8) != 0x00) return ((-101));
  if (fd_status.status_data[1] | fd_status.status_data[2]) return ((-101));
  s = (fd_status.status_data[3] - cylinder)
    * fd_data[drive]->head * fd_data[drive]->sector;
  s += (fd_status.status_data[4] - head) * fd_data[drive]->sector;
  s += (fd_status.status_data[5] - sector);
  if (s * (fd_data[drive]->length) != 512) return ((-101));
  else return ((0));
}

variable_types: i long


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

canonical_decompiled_code:
__int64 func0()
{
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 read_stat(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = a2;
ide_send_command_isra_0(0xECu);
if ( (unsigned int)ide_chk_drq() )
{
do
{
v2 += 2LL;
*(_WORD *)(v2 - 2) = inw(0x1F0u);
}
while ( a2 + 116 != v2 );
}
return 0LL;
}

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

v2 = a2;
func4(0xECu);
if ( (unsigned int)func0() )
{
do
{
v2 += 2LL;
*(_WORD *)(v2 - 2) = inw(0x1F0u);
}
while ( a2 + 116 != v2 );
}
return 0LL;
}

original_code:
ER
read_stat (W drive, struct ide_id *stat)
{
  UH *p;
  W i;
  W N;
  ide_send_command (0xec);
  p = (unsigned short *)stat;
  if (ide_chk_drq ())
    {
      for (i = 0; i < sizeof (struct ide_id) / 2; i++)
 {
   *p = inw (0x1f0);
   p++;
 }
    }
  return ((0));
}

canonical_original_code:
int read_stat(long drive, struct ide_id *stat)
{
  unsigned short *p;
  long i;
  long N;
  ide_send_command (0xec);
  p = (unsigned short *)stat;
  if (ide_chk_drq ())
    {
      for (i = 0; i < sizeof (struct ide_id) / 2; i++)
 {
   *p = inw (0x1f0);
   p++;
 }
    }
  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 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 *

variable_types: N long


decompiled_code:
__int64 __fastcall get_data(__int16 a1, __int16 a2, __int16 a3, unsigned __int8 a4, __int64 a5, __int64 a6)
{
__int64 v7; // r12
int v10; // eax
unsigned int v11; // er14
__int64 v12; // rbx

v7 = a6 << 9;
ide_intr_flag = 0LL;
while ( (inb(0x1F7u) & 0x80u) != 0 )
;
dis_int();
outb(0xF6u, a2 | (16 * a1));
outb(0xF2u, 1u);
outb(0xF4u, (unsigned __int8)a3);
outb(0xF5u, HIBYTE(a3));
outb(0xF3u, a4);
ide_send_command_isra_0(0x20u);
ena_int();
inb(0x1F7u);
do
{
LOBYTE(v10) = inb(0x1F7u);
v11 = v10 & 0x80;
}
while ( (v10 & 0x80) != 0 );
if ( (v10 & 1) != 0 )
{
dbg_printf("IDE read error. stat = 0x%x\n", v10);
}
else
{
v12 = 0LL;
if ( v7 > 1 )
{
do
*(_WORD *)(a5 + 2 * v12++) = inw(0x1F0u);
while ( v12 < v7 >> 1 );
}
v11 = v7;
ide_enable_int_isra_0();
}
return v11;
}

original_code:
ER
get_data (W drive, UW head, UW cyl, UW sec, B *buf, W length)
{
  W stat;
  W i;
  UH *tmpbuf;
  length *= 512;
  ide_intr_flag = (0);
  while (inb (0x1f7) & 0x80)
    ;
  dis_int ();
  outb (0x1f6, (drive << 4) | head);
  outb (0x1f2, 1);
  outb (0x1f4, cyl & 0xff);
  outb (0x1f5, (cyl >> 8) & 0xff);
  outb (0x1f3, sec & 0xff);
  ide_send_command (0x20);
  ena_int ();
  if (!(inb (0x1f7) & 0x08))
    {
    }
  while ((stat = inb (0x1f7)) & 0x80)
    ;
  if (stat & 0x01)
    {
      dbg_printf ("IDE read error. stat = 0x%x\n", stat);
      return (0);
    }
  tmpbuf = (unsigned short *)buf;
  for (i = 0; i < length / 2; i++)
    {
      tmpbuf[i] = inw (0x1f0);
    }
  ide_enable_int (drive);
  return (length);
}

canonical_original_code:
int get_data(long drive, unsigned long head, unsigned long cyl, unsigned long sec, char *buf, long length)
{
  long stat;
  long i;
  unsigned short *tmpbuf;
  length *= 512;
  ide_intr_flag = (0);
  while (inb (0x1f7) & 0x80)
    ;
  dis_int ();
  outb (0x1f6, (drive << 4) | head);
  outb (0x1f2, 1);
  outb (0x1f4, cyl & 0xff);
  outb (0x1f5, (cyl >> 8) & 0xff);
  outb (0x1f3, sec & 0xff);
  ide_send_command (0x20);
  ena_int ();
  if (!(inb (0x1f7) & 0x08))
    {
    }
  while ((stat = inb (0x1f7)) & 0x80)
    ;
  if (stat & 0x01)
    {
      dbg_printf ("IDE read error. stat = 0x%x\n", stat);
      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:
head
unsigned long

variable_types:
cyl
unsigned long

variable_types:
sec
unsigned long

variable_types:
buf
char *

variable_types: length long

variable_types: stat long

variable_types:
tmpbuf
unsigned short *


decompiled_code:
__int64 __fastcall put_data(__int16 a1, __int16 a2, unsigned __int8 a3, unsigned __int8 a4, __int64 a5, __int64 a6)
{
__int64 v7; // r12
int v10; // eax
unsigned int v11; // er14
__int64 v12; // rbx
unsigned __int16 v13; // si

v7 = a6 << 9;
ide_intr_flag = 0LL;
while ( (inb(0x1F7u) & 0x80u) != 0 )
;
dis_int();
outb(0xF6u, a2 | (16 * a1));
outb(0xF2u, 1u);
outb(0xF4u, a3);
outb(0xF5u, 0);
outb(0xF3u, a4);
ide_send_command_isra_0(0x30u);
ena_int();
inb(0x1F7u);
do
{
LOBYTE(v10) = inb(0x1F7u);
v11 = v10 & 0x80;
}
while ( (v10 & 0x80) != 0 );
if ( (v10 & 1) != 0 )
{
dbg_printf("IDE read error. stat = 0x%x\n", v10);
}
else
{
v12 = 0LL;
if ( v7 > 1 )
{
do
{
v13 = *(_WORD *)(a5 + 2 * v12++);
outw(0x1F0u, v13);
}
while ( v12 < v7 >> 1 );
}
v11 = v7;
ide_enable_int_isra_0();
}
return v11;
}

original_code:
ER
put_data (W drive, UW head, UW cyl, UW sec, B *buf, W length)
{
  W stat;
  W i;
  UH *tmpbuf;
  length *= 512;
  ide_intr_flag = (0);
  while (inb (0x1f7) & 0x80)
    ;
  dis_int ();
  outb (0x1f6, (drive << 4) | head);
  outb (0x1f2, 1);
  outb (0x1f4, cyl & 0xff);
  outb (0x1f5, (cyl << 8) & 0xff);
  outb (0x1f3, sec & 0xff);
  ide_send_command (0x30);
  ena_int ();
  if (!(inb (0x1f7) & 0x08))
    {
    }
  while ((stat = inb (0x1f7)) & 0x80)
    ;
  if (stat & 0x01)
    {
      dbg_printf ("IDE read error. stat = 0x%x\n", stat);
      return (0);
    }
  tmpbuf = (unsigned short *)buf;
  for (i = 0; i < length / 2; i++)
    {
      outw (0x1f0, tmpbuf[i]);
    }
  ide_enable_int (drive);
  return (length);
}

canonical_original_code:
int put_data(long drive, unsigned long head, unsigned long cyl, unsigned long sec, char *buf, long length)
{
  long stat;
  long i;
  unsigned short *tmpbuf;
  length *= 512;
  ide_intr_flag = (0);
  while (inb (0x1f7) & 0x80)
    ;
  dis_int ();
  outb (0x1f6, (drive << 4) | head);
  outb (0x1f2, 1);
  outb (0x1f4, cyl & 0xff);
  outb (0x1f5, (cyl << 8) & 0xff);
  outb (0x1f3, sec & 0xff);
  ide_send_command (0x30);
  ena_int ();
  if (!(inb (0x1f7) & 0x08))
    {
    }
  while ((stat = inb (0x1f7)) & 0x80)
    ;
  if (stat & 0x01)
    {
      dbg_printf ("IDE read error. stat = 0x%x\n", stat);
      return (0);
    }
  tmpbuf = (unsigned short *)buf;
  for (i = 0; i < length / 2; i++)
    {
      outw (0x1f0, tmpbuf[i]);
    }
  ide_enable_int (drive);
  return (length);
}


decompiled_code:
__int64 __fastcall wait_int(unsigned int *a1)
{
ena_int();
if ( !*a1 )
{
while ( 1 )
;
}
dis_int();
*a1 = 0;
ena_int();
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1)
{
ena_int();
if ( !*a1 )
{
while ( 1 )
;
}
dis_int();
*a1 = 0;
ena_int();
return *a1;
}

original_code:
int
wait_int (int *flag)
{
  ena_int ();
  while (*flag == (0))
    ;
  dis_int ();
  *flag = (0);
  ena_int ();
  return (*flag);
}

canonical_original_code:
int wait_int(int *flag)
{
  ena_int ();
  while (*flag == (0))
    ;
  dis_int ();
  *flag = (0);
  ena_int ();
  return (*flag);
}

variable_types:
flag
int *


decompiled_code:
__int64 __fastcall TCP_CRE_REP(__int64 a1, __int64 a2)
{
ID_CHECK();
NUL_CHECK(a2);
return 4294967279LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
ID_CHECK();
NUL_CHECK(a2);
return 4294967279LL;
}

original_code:
ER TCP_CRE_REP(ID repid, T_TCP_CREP *pk_crep)
{
 ID_CHECK(repid);
 NUL_CHECK(pk_crep);
 return (-17);
}

canonical_original_code:
int TCP_CRE_REP(int repid, struct t_tcp_ip_crep *pk_crep)
{
 ID_CHECK(repid);
 NUL_CHECK(pk_crep);
 return (-17);
}

variable_types: repid int

variable_types: struct t_tcp_ip_crep { unsigned int repatr; struct t_ipv4ep { unsigned long ipaddr; unsigned short portno; } myaddr; } *

user_defined_types: struct t_tcp_ip_crep { unsigned int repatr; struct t_ipv4ep myaddr; }