decompiled_code:
__int64 draw_window()
{
eval("gsave 4 copy 4 2 roll translate");
eval("2 copy 2 setcolor fillbox");
eval("2 copy 1 setcolor box");
eval("2 setmode 1 setcolor 0 18 moveto");
eval("2 copy pop 0 rlineto");
eval("3 setcolor 20 2 moveto");
eval("2 copy pop 25 sub 14 box");
eval("1 1 moveto");
eval("2 sub exch 2 sub");
eval("2 copy");
eval("7 setcolor 0 rlineto 1 setcolor 0 exch rlineto");
eval("neg 0 rlineto 7 setcolor neg 0 exch rlineto");
eval("5 20 moveto");
eval("2 copy");
eval("45 sub exch 30 sub exch 2 copy");
eval("3 setcolor fillbox exch");
eval("2 copy");
eval("1 setcolor 0 rlineto 7 setcolor 0 exch rlineto");
eval("neg 0 rlineto 1 setcolor neg 0 exch rlineto");
eval("2 copy");
eval("5 setcolor exch 20 sub 20 moveto 45 sub 15 exch box");
eval("2 copy");
eval("5 setcolor 20 sub 5 exch moveto 30 sub 15 box");
eval("2 copy");
eval("5 setcolor 20 sub exch 20 sub exch moveto 15 15 box");
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
eval("gsave 4 copy 4 2 roll translate");
eval("2 copy 2 setcolor fillbox");
eval("2 copy 1 setcolor box");
eval("2 setmode 1 setcolor 0 18 moveto");
eval("2 copy pop 0 rlineto");
eval("3 setcolor 20 2 moveto");
eval("2 copy pop 25 sub 14 box");
eval("1 1 moveto");
eval("2 sub exch 2 sub");
eval("2 copy");
eval("7 setcolor 0 rlineto 1 setcolor 0 exch rlineto");
eval("neg 0 rlineto 7 setcolor neg 0 exch rlineto");
eval("5 20 moveto");
eval("2 copy");
eval("45 sub exch 30 sub exch 2 copy");
eval("3 setcolor fillbox exch");
eval("2 copy");
eval("1 setcolor 0 rlineto 7 setcolor 0 exch rlineto");
eval("neg 0 rlineto 1 setcolor neg 0 exch rlineto");
eval("2 copy");
eval("5 setcolor exch 20 sub 20 moveto 45 sub 15 exch box");
eval("2 copy");
eval("5 setcolor 20 sub 5 exch moveto 30 sub 15 box");
eval("2 copy");
eval("5 setcolor 20 sub exch 20 sub exch moveto 15 15 box");
return 0LL;
}

original_code:
ER
draw_window(void)
{
  int x;
  int y;
  int width;
  int height;
  Cell *c;
  ER result;
  eval ("gsave 4 copy 4 2 roll translate");
  eval ("2 copy 2 setcolor fillbox");
  eval ("2 copy 1 setcolor box");
  eval ("2 setmode 1 setcolor 0 18 moveto");
  eval ("2 copy pop 0 rlineto");
  eval ("3 setcolor 20 2 moveto");
  eval ("2 copy pop 25 sub 14 box");
  eval ("1 1 moveto");
  eval ("2 sub exch 2 sub");
  eval ("2 copy");
  eval ("7 setcolor 0 rlineto 1 setcolor 0 exch rlineto");
  eval ("neg 0 rlineto 7 setcolor neg 0 exch rlineto");
  eval ("5 20 moveto");
  eval ("2 copy");
  eval ("45 sub exch 30 sub exch 2 copy");
  eval ("3 setcolor fillbox exch");
  eval ("2 copy");
  eval ("1 setcolor 0 rlineto 7 setcolor 0 exch rlineto");
  eval ("neg 0 rlineto 1 setcolor neg 0 exch rlineto");
  eval ("2 copy");
  eval ("5 setcolor exch 20 sub 20 moveto 45 sub 15 exch box");
  eval ("2 copy");
  eval ("5 setcolor 20 sub 5 exch moveto 30 sub 15 box");
  eval ("2 copy");
  eval ("5 setcolor 20 sub exch 20 sub exch moveto 15 15 box");
  return (0);
}

canonical_original_code:
int draw_window()
{
  int x;
  int y;
  int width;
  int height;
  struct _cell *c;
  int result;
  eval ("gsave 4 copy 4 2 roll translate");
  eval ("2 copy 2 setcolor fillbox");
  eval ("2 copy 1 setcolor box");
  eval ("2 setmode 1 setcolor 0 18 moveto");
  eval ("2 copy pop 0 rlineto");
  eval ("3 setcolor 20 2 moveto");
  eval ("2 copy pop 25 sub 14 box");
  eval ("1 1 moveto");
  eval ("2 sub exch 2 sub");
  eval ("2 copy");
  eval ("7 setcolor 0 rlineto 1 setcolor 0 exch rlineto");
  eval ("neg 0 rlineto 7 setcolor neg 0 exch rlineto");
  eval ("5 20 moveto");
  eval ("2 copy");
  eval ("45 sub exch 30 sub exch 2 copy");
  eval ("3 setcolor fillbox exch");
  eval ("2 copy");
  eval ("1 setcolor 0 rlineto 7 setcolor 0 exch rlineto");
  eval ("neg 0 rlineto 1 setcolor neg 0 exch rlineto");
  eval ("2 copy");
  eval ("5 setcolor exch 20 sub 20 moveto 45 sub 15 exch box");
  eval ("2 copy");
  eval ("5 setcolor 20 sub 5 exch moveto 30 sub 15 box");
  eval ("2 copy");
  eval ("5 setcolor 20 sub exch 20 sub exch moveto 15 15 box");
  return (0);
}

variable_types: width int

variable_types: height int


repo: monaka/B-Free

decompiled_code:
__int64 get_one_char()
{
wait_int(&input_flag);
return (unsigned int)cbuf;
}

canonical_decompiled_code:
__int64 func0()
{
wait_int(&input_flag);
return (unsigned int)cbuf;
}

original_code:
static int
get_one_char (void)
{
  int ch;
  wait_int (&input_flag);
  ch = cbuf;
  return (ch);
}

canonical_original_code:
static int get_one_char()
{
  int ch;
  wait_int (&input_flag);
  ch = cbuf;
  return (ch);
}

variable_types: ch int

return_type: int


decompiled_code:
__int64 __fastcall get_mode(__int16 a1)
{
__int64 result; // rax

result = 3LL;
if ( (a1 & 0x100) == 0 )
{
result = 1LL;
if ( (a1 & 0x200) == 0 )
{
result = a1 & 0x400;
if ( (a1 & 0x400) != 0 )
result = 2LL;
}
}
return result;
}

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

result = 3LL;
if ( (a1 & 0x100) == 0 )
{
result = 1LL;
if ( (a1 & 0x200) == 0 )
{
result = a1 & 0x400;
if ( (a1 & 0x400) != 0 )
result = 2LL;
}
}
return result;
}

original_code:
int
get_mode (int ch)
{
  if (ch & (0x0100))
    {
      return (3);
    }
  else if (ch & (0x0200))
    {
      return (1);
    }
  else if (ch & (0x0400))
    {
      return (2);
    }
  else if (ch & (0x0800))
    {
      return (0);
    }
  return (0);
}

canonical_original_code:
int get_mode(int ch)
{
  if (ch & (0x0100))
    {
      return (3);
    }
  else if (ch & (0x0200))
    {
      return (1);
    }
  else if (ch & (0x0400))
    {
      return (2);
    }
  else if (ch & (0x0800))
    {
      return (0);
    }
  return (0);
}


decompiled_code:
unsigned __int8 init_keyboard()
{
keyboard_type = 1;
set_idt(33LL, 8LL, (unsigned int)&int33_handler, 14LL, 0LL);
reset_intr_mask(1LL);
return inb(0x64u);
}

canonical_decompiled_code:
unsigned __int8 func2()
{
keyboard_type = 1;
set_idt(33LL, 8LL, (unsigned int)&int33_handler, 14LL, 0LL);
reset_intr_mask(1LL);
return inb(0x64u);
}

original_code:
void
init_keyboard (void)
{
  BYTE status;
  keyboard_type = 1;
  set_idt (33, 0x08, (int)int33_handler, 0xe, 0);
  reset_intr_mask (1);
  status = inb (0x64);
}

canonical_original_code:
void init_keyboard()
{
  unsigned char status;
  keyboard_type = 1;
  set_idt (33, 0x08, (int)int33_handler, 0xe, 0);
  reset_intr_mask (1);
  status = inb (0x64);
}

variable_types:
status
unsigned char

return_type: void


decompiled_code:
__int64 read_keyboard()
{
__int16 v0; // ax
char v1; // cl
__int64 v2; // rdx
__int64 result; // rax
__int16 v4; // ax
char v5; // cl
__int64 v6; // rdx

if ( keyboard_type == 1 )
{
do
{
v4 = get_one_char();
v6 = (int)get_mode(v4);
result = key_table_101[255 * v6 + (v5 & 0x7F)];
}
while ( !result );
}
else
{
do
{
v0 = get_one_char();
v2 = (int)get_mode(v0);
result = key_table_106[255 * v2 + (v1 & 0x7F)];
}
while ( !result );
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int16 v0; // ax
char v1; // cl
__int64 v2; // rdx
__int64 result; // rax
__int16 v4; // ax
char v5; // cl
__int64 v6; // rdx

if ( keyboard_type == 1 )
{
do
{
v4 = func0();
v6 = (int)func1(v4);
result = key_table_101[255 * v6 + (v5 & 0x7F)];
}
while ( !result );
}
else
{
do
{
v0 = func0();
v2 = (int)func1(v0);
result = key_table_106[255 * v2 + (v1 & 0x7F)];
}
while ( !result );
}
return result;
}

original_code:
int
read_keyboard (void)
{
  int ch;
  int mode;
  if(keyboard_type == 1){
    do{
      ch = get_one_char ();
      mode = get_mode (ch);
    }while(key_table_101[mode][(ch & 0x7f)] == 0);
    return key_table_101[mode][(ch & 0x7f)];
  }else{
    do{
      ch = get_one_char ();
      mode = get_mode (ch);
    }while(key_table_106[mode][(ch & 0x7f)] == 0);
    return key_table_106[mode][(ch & 0x7f)];
  }
}

canonical_original_code:
int read_keyboard()
{
  int ch;
  int mode;
  if(keyboard_type == 1){
    do{
      ch = get_one_char ();
      mode = get_mode (ch);
    }while(key_table_101[mode][(ch & 0x7f)] == 0);
    return key_table_101[mode][(ch & 0x7f)];
  }else{
    do{
      ch = get_one_char ();
      mode = get_mode (ch);
    }while(key_table_106[mode][(ch & 0x7f)] == 0);
    return key_table_106[mode][(ch & 0x7f)];
  }
}

variable_types: mode int


decompiled_code:
__int64 read_keyboard_no_hung()
{
__int16 v0; // ax
int v1; // eax
char v2; // cl
__int64 v3; // rcx
__int64 result; // rax

v0 = get_one_char();
v1 = get_mode(v0);
v3 = 255LL * v1 + (v2 & 0x7F);
if ( keyboard_type == 1 )
result = LODWORD(key_table_101[v3]);
else
result = LODWORD(key_table_106[v3]);
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int16 v0; // ax
int v1; // eax
char v2; // cl
__int64 v3; // rcx
__int64 result; // rax

v0 = func0();
v1 = func1(v0);
v3 = 255LL * v1 + (v2 & 0x7F);
if ( keyboard_type == 1 )
result = LODWORD(key_table_101[v3]);
else
result = LODWORD(key_table_106[v3]);
return result;
}

original_code:
int
read_keyboard_no_hung (void)
{
  int ch;
  int mode;
  ch = get_one_char ();
  mode = get_mode (ch);
  if(keyboard_type == 1){
    return key_table_101[mode][(ch & 0x7f)];
  }else{
    return key_table_106[mode][(ch & 0x7f)];
  }
}

canonical_original_code:
int read_keyboard_no_hung()
{
  int ch;
  int mode;
  ch = get_one_char ();
  mode = get_mode (ch);
  if(keyboard_type == 1){
    return key_table_101[mode][(ch & 0x7f)];
  }else{
    return key_table_106[mode][(ch & 0x7f)];
  }
}


decompiled_code:
void intr_keyboard()
{
int v0; // ebx
int v1; // ebp
int v2; // edx
unsigned __int8 v3; // al
int v4; // er12

v0 = 100;
v1 = inb(0x60u);
while ( (inb(0x64u) & 2) != 0 )
{
if ( !--v0 )
{
boot_printf("keyboard wait overrun\n");
break;
}
}
outb(0x64u, 0xADu);
outb(0x64u, 0xAEu);
switch ( v1 )
{
case 224:
v3 = inb(0x60u);
v2 = mode_0;
v1 = v3 | 0x800;
if ( v3 == 83 )
{
v1 = 2131;
if ( (mode_0 & 0x300) != 0 )
{
boot_printf("reset\n");
v2 = mode_0;
}
}
LABEL_10:
input_flag = 1;
cbuf = v2 | v1;
return;
case 42:
case 54:
mode_0 |= 0x200u;
return;
case 29:
mode_0 |= 0x100u;
return;
case 56:
mode_0 |= 0x400u;
return;
}
v2 = mode_0;
if ( (v1 & 0x80u) == 0 )
goto LABEL_10;
v4 = v1 & 0x7F;
switch ( v4 )
{
case 42:
case 54:
mode_0 &= 0xFFFFFDFF;
break;
case 29:
mode_0 &= 0xFFFFFEFF;
break;
case 56:
mode_0 &= 0xFFFFFBFF;
break;
}
}

canonical_decompiled_code:
void func5()
{
int v0; // ebx
int v1; // ebp
int v2; // edx
unsigned __int8 v3; // al
int v4; // er12

v0 = 100;
v1 = inb(0x60u);
while ( (inb(0x64u) & 2) != 0 )
{
if ( !--v0 )
{
boot_printf("keyboard wait overrun\n");
break;
}
}
outb(0x64u, 0xADu);
outb(0x64u, 0xAEu);
switch ( v1 )
{
case 224:
v3 = inb(0x60u);
v2 = mode_0;
v1 = v3 | 0x800;
if ( v3 == 83 )
{
v1 = 2131;
if ( (mode_0 & 0x300) != 0 )
{
boot_printf("reset\n");
v2 = mode_0;
}
}
LABEL_10:
input_flag = 1;
cbuf = v2 | v1;
return;
case 42:
case 54:
mode_0 |= 0x200u;
return;
case 29:
mode_0 |= 0x100u;
return;
case 56:
mode_0 |= 0x400u;
return;
}
v2 = mode_0;
if ( (v1 & 0x80u) == 0 )
goto LABEL_10;
v4 = v1 & 0x7F;
switch ( v4 )
{
case 42:
case 54:
mode_0 &= 0xFFFFFDFF;
break;
case 29:
mode_0 &= 0xFFFFFEFF;
break;
case 56:
mode_0 &= 0xFFFFFBFF;
break;
}
}

original_code:
void
intr_keyboard ()
{
  int ch;
  int i;
  static int mode = 0;
  ch = inb (0x60);
  for (i = 0; i < 100; i++)
    {
      if ((inb (0x64) & 0x02) == 0)
        break;
    }
  if (i == 100)
    {
      boot_printf ("keyboard wait overrun\n");
    }
  outb (0x64, 0xad);
  outb (0x64, 0xae);
  if (ch == 0xE0)
    {
      ch = inb (0x60);
      ch = ch | (0x0800);
      if ((ch & 0xff) == 0x53)
 {
   if (mode & ((0x0200) | (0x0100)))
     {
       boot_printf ("reset\n");
     }
 }
    }
  else if ((ch == 0x2a) || (ch == 0x36))
    {
      mode |= (0x0200);
      return;
    }
  else if (ch == 0x1d)
    {
      mode |= (0x0100);
      return;
    }
  else if (ch == 0x38)
    {
      mode |= (0x0400);
      return ;
    }
  else if ((ch & 0x80))
    {
      ch = ch & 0x7f;
      if ((ch == 0x2a) || (ch == 0x36))
 {
   mode &= ~(0x0200);
 }
      else if (ch == 0x1d)
 {
   mode &= ~(0x0100);
 }
      else if (ch == 0x38)
 {
   mode &= ~(0x0400);
 }
      return;
    }
  cbuf = ch | mode;
  input_flag = 1;
  return ;
}

canonical_original_code:
void intr_keyboard()
{
  int ch;
  int i;
  static int mode = 0;
  ch = inb (0x60);
  for (i = 0; i < 100; i++)
    {
      if ((inb (0x64) & 0x02) == 0)
        break;
    }
  if (i == 100)
    {
      boot_printf ("keyboard wait overrun\n");
    }
  outb (0x64, 0xad);
  outb (0x64, 0xae);
  if (ch == 0xE0)
    {
      ch = inb (0x60);
      ch = ch | (0x0800);
      if ((ch & 0xff) == 0x53)
 {
   if (mode & ((0x0200) | (0x0100)))
     {
       boot_printf ("reset\n");
     }
 }
    }
  else if ((ch == 0x2a) || (ch == 0x36))
    {
      mode |= (0x0200);
      return;
    }
  else if (ch == 0x1d)
    {
      mode |= (0x0100);
      return;
    }
  else if (ch == 0x38)
    {
      mode |= (0x0400);
      return ;
    }
  else if ((ch & 0x80))
    {
      ch = ch & 0x7f;
      if ((ch == 0x2a) || (ch == 0x36))
 {
   mode &= ~(0x0200);
 }
      else if (ch == 0x1d)
 {
   mode &= ~(0x0100);
 }
      else if (ch == 0x38)
 {
   mode &= ~(0x0400);
 }
      return;
    }
  cbuf = ch | mode;
  input_flag = 1;
  return ;
}

variable_types: i int


decompiled_code:
void k101us()
{
keyboard_type = 1;
}

canonical_decompiled_code:
void func6()
{
keyboard_type = 1;
}

original_code:
void k101us(char *argv[])
{
  keyboard_type = 1;
}

variable_types:
argv
char *[]


decompiled_code:
void k106jp()
{
keyboard_type = 2;
}

canonical_decompiled_code:
void func7()
{
keyboard_type = 2;
}

original_code:
void k106jp(char *argv[])
{
  keyboard_type = 2;
}


decompiled_code:
__int64 run_func()
{
MEMORY[0x80010000]();
return 0LL;
}

original_code:
static int
run_func (char* argv[])
{
  void (*func)();
  func = (void (*)())0x80010000;
  (*func)();
  return (0);
}

canonical_original_code:
static int run_func(char *argv[])
{
  void (*func)();
  func = (void (*)())0x80010000;
  (*func)();
  return (0);
}

variable_types:
func
void (*)()


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

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

original_code:
static int
fd_status_func (char **args)
{
  return (0);
}

canonical_original_code:
static int fd_status_func(char **args)
{
  return (0);
}

variable_types:
args
char **


decompiled_code:
__int64 __fastcall debug_func(__int64 a1)
{
const char *v1; // rdi

v1 = *(const char **)(a1 + 8);
if ( v1 )
debug_flag = atoi(v1);
else
debug_flag = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
const char *v1; // rdi

v1 = *(const char **)(a1 + 8);
if ( v1 )
debug_flag = atoi(v1);
else
debug_flag = 0;
return 0LL;
}

original_code:
static int
debug_func (char **argv)
{
  int level;
  if (argv[1] == 0)
    level = 0;
  else
    level = atoi (argv[1]);
  debug_flag = level;
  return (0);
}

canonical_original_code:
static int debug_func(char **argv)
{
  int level;
  if (argv[1] == 0)
    level = 0;
  else
    level = atoi (argv[1]);
  debug_flag = level;
  return (0);
}

variable_types:
argv
char **

variable_types: level int


decompiled_code:
__int64 __fastcall print_map_func(__int64 a1)
{
__int64 v1; // rbp
const char *v2; // rdi
_DWORD *v3; // rbx

v1 = 0LL;
v2 = *(const char **)(a1 + 8);
if ( v2 )
v1 = (__int64)atoi(v2) << 12;
v3 = (_DWORD *)get_page_entry(v1);
boot_printf("virtual address: 0x%x\n", v1);
boot_printf("physical address: 0x%x\n", *v3 & 0xFFFFF000);
boot_printf("user/supervisor: 0x%x\n", (*(_BYTE *)v3 & 4) != 0);
boot_printf("read_write: 0x%x\n", (*(_BYTE *)v3 & 2) != 0);
boot_printf("present bit: 0x%x\n", *(_BYTE *)v3 & 1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbp
const char *v2; // rdi
_DWORD *v3; // rbx

v1 = 0LL;
v2 = *(const char **)(a1 + 8);
if ( v2 )
v1 = (__int64)atoi(v2) << 12;
v3 = (_DWORD *)get_page_entry(v1);
boot_printf("virtual address: 0x%x\n", v1);
boot_printf("physical address: 0x%x\n", *v3 & 0xFFFFF000);
boot_printf("user/supervisor: 0x%x\n", (*(_BYTE *)v3 & 4) != 0);
boot_printf("read_write: 0x%x\n", (*(_BYTE *)v3 & 2) != 0);
boot_printf("present bit: 0x%x\n", *(_BYTE *)v3 & 1);
return 0LL;
}

original_code:
static int
print_map_func (char **av)
{
  ULONG vaddr = av[1] ? atoi (av[1]) : 0;
  struct page_table_entry *page;
  page = get_page_entry (vaddr * 4096);
  boot_printf ("virtual  address: 0x%x\n", vaddr * 4096);
  boot_printf ("physical address: 0x%x\n", page->frame_addr * 4096);
  boot_printf ("user/supervisor:  0x%x\n", page->u_and_s);
  boot_printf ("read_write:       0x%x\n", page->read_write);
  boot_printf ("present bit:      0x%x\n", page->present);
  return (0);
}

canonical_original_code:
static int print_map_func(char **av)
{
  unsigned long vaddr = av[1] ? atoi (av[1]) : 0;
  struct page_table_entry *page;
  page = get_page_entry (vaddr * 4096);
  boot_printf ("virtual  address: 0x%x\n", vaddr * 4096);
  boot_printf ("physical address: 0x%x\n", page->frame_addr * 4096);
  boot_printf ("user/supervisor:  0x%x\n", page->u_and_s);
  boot_printf ("read_write:       0x%x\n", page->read_write);
  boot_printf ("present bit:      0x%x\n", page->present);
  return (0);
}

variable_types:
av
char **

variable_types:
vaddr
unsigned long

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


decompiled_code:
__int64 help_func()
{
const char *v0; // rbx
int v1; // eax
int v2; // er12
int v3; // eax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = (const char *)(unsigned int)((_DWORD)func_table + 24);
boot_printf("help:\n");
boot_printf("COMMAND:\n");
strcpy(v5, " ");
v1 = strlen(func_table);
if ( v1 > 15 )
v1 = 15;
v2 = 0;
strncpy(v5, func_table, v1);
boot_printf("%s", v5);
while ( ++v2 != 25 )
{
strcpy(v5, " ");
v3 = strlen(v0);
if ( v3 > 15 )
v3 = 15;
strncpy(v5, v0, v3);
boot_printf("%s", v5);
if ( (unsigned int)(-1431655765 * v2 - 1431655766) <= 0x55555554 )
boot_printf("\n");
v0 += 24;
}
boot_printf("\n");
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
const char *v0; // rbx
int v1; // eax
int v2; // er12
int v3; // eax
char v5[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = (const char *)(unsigned int)((_DWORD)func_table + 24);
boot_printf("help:\n");
boot_printf("COMMAND:\n");
strcpy(v5, " ");
v1 = strlen(func_table);
if ( v1 > 15 )
v1 = 15;
v2 = 0;
strncpy(v5, func_table, v1);
boot_printf("%s", v5);
while ( ++v2 != 25 )
{
strcpy(v5, " ");
v3 = strlen(v0);
if ( v3 > 15 )
v3 = 15;
strncpy(v5, v0, v3);
boot_printf("%s", v5);
if ( (unsigned int)(-1431655765 * v2 - 1431655766) <= 0x55555554 )
boot_printf("\n");
v0 += 24;
}
boot_printf("\n");
return 0LL;
}

original_code:
static int
help_func (char *argv[])
{
  int i;
  boot_printf ("help:\n");
  boot_printf ("COMMAND:\n");
  for (i = 0; i < (sizeof(func_table) / sizeof(func_table[0])); i++)
    {
      char disp[21];
      int funcname_len;
      strcpy(disp, "                    ");
      funcname_len = strlen(func_table[i].name);
      if (funcname_len > 15)
 {
   funcname_len = 15;
 }
      strncpy(disp, func_table[i].name, funcname_len);
      boot_printf ("%s", disp);
      if (i % 3 == 2)
 {
   boot_printf("\n");
 }
    }
  if (i % 3 != 0)
    {
      boot_printf("\n");
    }
  return (0);
}

canonical_original_code:
static int help_func(char *argv[])
{
  int i;
  boot_printf ("help:\n");
  boot_printf ("COMMAND:\n");
  for (i = 0; i < (sizeof(func_table) / sizeof(func_table[0])); i++)
    {
      char disp[21];
      int funcname_len;
      strcpy(disp, "                    ");
      funcname_len = strlen(func_table[i].name);
      if (funcname_len > 15)
 {
   funcname_len = 15;
 }
      strncpy(disp, func_table[i].name, funcname_len);
      boot_printf ("%s", disp);
      if (i % 3 == 2)
 {
   boot_printf("\n");
 }
    }
  if (i % 3 != 0)
    {
      boot_printf("\n");
    }
  return (0);
}

variable_types:
disp
char [21]


decompiled_code:
__int64 __fastcall seek_func(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
unsigned int v3; // eax

v1 = atoi(*(const char **)(a1 + 8));
v2 = (unsigned int)atoi(*(const char **)(a1 + 16));
boot_printf("seek drive = %d, cylinder = %d\n", v1, v2);
v3 = fd_seek(0LL, v1, (unsigned int)v2, 1LL);
boot_printf("seek status = 0x%x\n", v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
unsigned int v1; // ebp
__int64 v2; // r12
unsigned int v3; // eax

v1 = atoi(*(const char **)(a1 + 8));
v2 = (unsigned int)atoi(*(const char **)(a1 + 16));
boot_printf("seek drive = %d, cylinder = %d\n", v1, v2);
v3 = fd_seek(0LL, v1, (unsigned int)v2, 1LL);
boot_printf("seek status = 0x%x\n", v3);
return 0LL;
}

original_code:
static int
seek_func (char **args)
{
  int drive;
  int cylinder;
  drive = atoi (args[1]);
  cylinder = atoi (args[2]);
  boot_printf ("seek drive = %d, cylinder = %d\n",
   drive, cylinder);
  boot_printf ("seek status = 0x%x\n", fd_seek (0, drive, cylinder, 1));
  return (0);
}

canonical_original_code:
static int seek_func(char **args)
{
  int drive;
  int cylinder;
  drive = atoi (args[1]);
  cylinder = atoi (args[2]);
  boot_printf ("seek drive = %d, cylinder = %d\n",
   drive, cylinder);
  boot_printf ("seek status = 0x%x\n", fd_seek (0, drive, cylinder, 1));
  return (0);
}

variable_types: drive int

variable_types: cylinder int


decompiled_code:
__int64 fd_recalibrate_func()
{
unsigned int v0; // eax

v0 = fd_recalibrate(0LL);
boot_printf("recalibrate status = 0x%x\n", v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax

v0 = fd_recalibrate(0LL);
boot_printf("recalibrate status = 0x%x\n", v0);
return 0LL;
}

original_code:
static int
fd_recalibrate_func (char* argv[])
{
  boot_printf ("recalibrate status = 0x%x\n", fd_recalibrate (0));
  return (0);
}

canonical_original_code:
static int fd_recalibrate_func(char *argv[])
{
  boot_printf ("recalibrate status = 0x%x\n", fd_recalibrate (0));
  return (0);
}


decompiled_code:
__int64 init_fd_func()
{
init_fd();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
init_fd();
return 0LL;
}

original_code: static int init_fd_func (char *argv[]) { init_fd (); return (0); }

canonical_original_code: static int init_fd_func(char *argv[]) { init_fd (); return (0); }


decompiled_code:
__int64 fd_reset_func()
{
fd_reset();
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
fd_reset();
return 0LL;
}

original_code: static int fd_reset_func (char *argv[]) { fd_reset (); return (0); }

canonical_original_code: static int fd_reset_func(char *argv[]) { fd_reset (); return (0); }


decompiled_code:
__int64 boot_func()
{
char v1[1032]; // [rsp+0h] [rbp-408h] BYREF

boot_printf("booting kernel...\n");
init_fd();
fd_reset();
on_motor(0LL);
fd_recalibrate(0LL);
fd_read(0LL, 0LL, v1);
boot_printf("exec data read...\n");
boot_printf("magic number %d\n", (unsigned int)v1[0]);
if ( v1[0] == 1 )
{
boot_printf("read multiple module.\n");
read_multi_module();
boot_printf("boot end\n");
}
else
{
read_a_out();
}
stop_motor(0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
char v1[1032]; // [rsp+0h] [rbp-408h] BYREF

boot_printf("booting kernel...\n");
init_fd();
fd_reset();
on_motor(0LL);
fd_recalibrate(0LL);
fd_read(0LL, 0LL, v1);
boot_printf("exec data read...\n");
boot_printf("magic number %d\n", (unsigned int)v1[0]);
if ( v1[0] == 1 )
{
boot_printf("read multiple module.\n");
read_multi_module();
boot_printf("boot end\n");
}
else
{
read_a_out();
}
stop_motor(0LL);
return 0LL;
}

original_code:
static int
boot_func (char *argv[])
{
  char tmp[1024];
  extern int read_multi_module ();
  extern int read_a_out ();
  boot_printf ("booting kernel...\n");
  init_fd ();
  fd_reset ();
  on_motor (0);
  fd_recalibrate(0);
  fd_read (0, 0, tmp);
  boot_printf ("exec data read...\n");
  boot_printf ("magic number %d\n", tmp[0]);
  if (tmp[0] == 0x0001)
    {
      boot_printf ("read multiple module.\n");
      read_multi_module ();
      boot_printf ("boot end\n");
    }
  else
    {
      read_a_out ();
    }
  stop_motor (0);
  return (0);
}

canonical_original_code:
static int boot_func(char *argv[])
{
  char tmp[1024];
  extern int read_multi_module();
  extern int read_a_out();
  boot_printf ("booting kernel...\n");
  init_fd ();
  fd_reset ();
  on_motor (0);
  fd_recalibrate(0);
  fd_read (0, 0, tmp);
  boot_printf ("exec data read...\n");
  boot_printf ("magic number %d\n", tmp[0]);
  if (tmp[0] == 0x0001)
    {
      boot_printf ("read multiple module.\n");
      read_multi_module ();
      boot_printf ("boot end\n");
    }
  else
    {
      read_a_out ();
    }
  stop_motor (0);
  return (0);
}

variable_types:
tmp
char [1024]


decompiled_code:
__int64 cpu_reset_func()
{
while ( (inb(0x64u) & 2) != 0 )
;
outb(0x64u, 0xF0u);
return 0LL;
}

original_code:
static int
cpu_reset_func (char *argv[])
{
  while ((inb (0x64) & 0x02) == 0x02)
    ;
  outb (0x64, 0xf0);
  return (0);
}

canonical_original_code:
static int cpu_reset_func(char *argv[])
{
  while ((inb (0x64) & 0x02) == 0x02)
    ;
  outb (0x64, 0xf0);
  return (0);
}


decompiled_code:
__int64 status_memory_func()
{
status_memory();
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
status_memory();
return 0LL;
}

original_code: static int status_memory_func (char *argv[]) { status_memory (); return (0); }

canonical_original_code: static int status_memory_func(char *argv[]) { status_memory (); return (0); }


decompiled_code:
__int64 ide_init_func()
{
ide_init();
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
ide_init();
return 0LL;
}

original_code: static int ide_init_func (char *argv[]) { ide_init (); return (0); }

canonical_original_code: static int ide_init_func(char *argv[]) { ide_init (); return (0); }


decompiled_code:
__int64 ide_id_func()
{
ide_id();
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
ide_id();
return 0LL;
}

original_code: static int ide_id_func (char *argv[]) { ide_id (); return (0); }

canonical_original_code: static int ide_id_func(char *argv[]) { ide_id (); return (0); }


decompiled_code:
__int64 __fastcall dump_func(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp

v1 = atoi(*(const char **)(a1 + 8));
v2 = (unsigned int)atoi(*(const char **)(a1 + 16));
boot_printf("dump_func: base = 0x%x, length = %d\n", (unsigned int)v1, v2);
dump_isra_0(v1, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp

v1 = atoi(*(const char **)(a1 + 8));
v2 = (unsigned int)atoi(*(const char **)(a1 + 16));
boot_printf("dump_func: base = 0x%x, length = %d\n", (unsigned int)v1, v2);
func15(v1, v2);
return 0LL;
}

original_code:
static int
dump_func (char **args)
{
  int base;
  int length;
  base = atoi (args[1]);
  length = atoi (args[2]);
  boot_printf ("dump_func: base = 0x%x, length = %d\n", base, length);
  dump ((BYTE *)base, length);
  return (0);
}

canonical_original_code:
static int dump_func(char **args)
{
  int base;
  int length;
  base = atoi (args[1]);
  length = atoi (args[2]);
  boot_printf ("dump_func: base = 0x%x, length = %d\n", base, length);
  dump ((unsigned char *)base, length);
  return (0);
}

variable_types: base int

variable_types: length int


decompiled_code:
__int64 __fastcall fd_read_func(__int64 a1)
{
unsigned int v1; // ebx
unsigned int v2; // er12
unsigned int v3; // eax
unsigned int v4; // er12

v1 = atoi(*(const char **)(a1 + 8));
v2 = atoi(*(const char **)(a1 + 16));
boot_printf("fd_read_func: drive = %d, blockno = %d\n", v1, v2);
v3 = fd_read((unsigned __int8)v1, v2, 196608LL);
v4 = v3;
if ( v3 )
{
boot_printf("can't read device. errno = %d\n", v3);
}
else
{
boot_printf("read ok.\n");
dump_isra_0(196608LL, 512);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
unsigned int v1; // ebx
unsigned int v2; // er12
unsigned int v3; // eax
unsigned int v4; // er12

v1 = atoi(*(const char **)(a1 + 8));
v2 = atoi(*(const char **)(a1 + 16));
boot_printf("fd_read_func: drive = %d, blockno = %d\n", v1, v2);
v3 = fd_read((unsigned __int8)v1, v2, 196608LL);
v4 = v3;
if ( v3 )
{
boot_printf("can't read device. errno = %d\n", v3);
}
else
{
boot_printf("read ok.\n");
func15(196608LL, 512);
}
return v4;
}

original_code:
static int
fd_read_func (char **args)
{
  int drive;
  int blockno;
  int stat;
  drive = atoi (args[1]);
  blockno = atoi (args[2]);
  boot_printf ("fd_read_func: drive = %d, blockno = %d\n", drive, blockno);
  stat = fd_read (drive, blockno, (char *)0x30000);
  if (stat != (0))
    {
      boot_printf ("can't read device. errno = %d\n", stat);
      return (stat);
    }
  boot_printf ("read ok.\n");
  dump ((BYTE *)0x30000, 512);
  return (0);
}

canonical_original_code:
static int fd_read_func(char **args)
{
  int drive;
  int blockno;
  int stat;
  drive = atoi (args[1]);
  blockno = atoi (args[2]);
  boot_printf ("fd_read_func: drive = %d, blockno = %d\n", drive, blockno);
  stat = fd_read (drive, blockno, (char *)0x30000);
  if (stat != (0))
    {
      boot_printf ("can't read device. errno = %d\n", stat);
      return (stat);
    }
  boot_printf ("read ok.\n");
  dump ((unsigned char *)0x30000, 512);
  return (0);
}

variable_types: blockno int

variable_types: stat int


evaluate

decompiled_code:
__int64 __fastcall evaluate(_BYTE *a1)
{
int v1; // ebx
const char *v2; // rbp
__int64 v3; // rax
char *s1[13]; // [rsp+0h] [rbp-68h] BYREF

v1 = 0;
bzero(s1, 0x50uLL);
v2 = func_table;
setargs_isra_0(a1, s1);
do
{
LODWORD(v3) = strncmp(s1[0], v2, 0xFuLL);
if ( !v3 )
{
(*(void (__fastcall **)(char **))&func_table[24 * v1 + 16])(s1);
return 0LL;
}
++v1;
v2 += 24;
}
while ( v1 != 25 );
boot_printf("boot: %s: command not found\n", s1[0]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(_BYTE *a1)
{
int v1; // ebx
const char *v2; // rbp
__int64 v3; // rax
char *s1[13]; // [rsp+0h] [rbp-68h] BYREF

v1 = 0;
bzero(s1, 0x50uLL);
v2 = func_table;
func18(a1, s1);
do
{
LODWORD(v3) = strncmp(s1[0], v2, 0xFuLL);
if ( !v3 )
{
(*(void (__fastcall **)(char **))&func_table[24 * v1 + 16])(s1);
return 0LL;
}
++v1;
v2 += 24;
}
while ( v1 != 25 );
boot_printf("boot: %s: command not found\n", s1[0]);
return 0LL;
}

original_code:
int
evaluate (char *line)
{
  int i;
  char *args[10];
  bzero ((void *)args, sizeof (char *) * 10);
  setargs(line, args);
  for (i = 0; i < (sizeof(func_table) / sizeof(func_table[0])); i++)
    {
      if (strncmp (args[0], func_table[i].name, 15) == 0)
 {
   func_table[i].func (args);
   break;
 }
    }
  if (i >= (sizeof(func_table) / sizeof(func_table[0])))
    {
      boot_printf ("boot: %s: command not found\n", args[0]);
    }
  return (0);
}

canonical_original_code:
int evaluate(char *line)
{
  int i;
  char *args[10];
  bzero ((void *)args, sizeof (char *) * 10);
  setargs(line, args);
  for (i = 0; i < (sizeof(func_table) / sizeof(func_table[0])); i++)
    {
      if (strncmp (args[0], func_table[i].name, 15) == 0)
 {
   func_table[i].func (args);
   break;
 }
    }
  if (i >= (sizeof(func_table) / sizeof(func_table[0])))
    {
      boot_printf ("boot: %s: command not found\n", args[0]);
    }
  return (0);
}

variable_types:
line
char *

variable_types: i int

variable_types:
args
char *[10]


getgrnam

decompiled_code:
void getgrnam()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
getgrnam (char *group)
{
  return (call_lowlib (71, strlen (group), group));
}

canonical_original_code:
int getgrnam(char *group)
{
  return (call_lowlib (71, strlen (group), group));
}

variable_types:
group
char *


decompiled_code:
void open_rs232c()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
ER
open_rs232c (ID caller, DDEV_OPN_REQ *packet)
{
}

canonical_original_code:
int open_rs232c(int caller, struct DDEV_OPN_REQ *packet)
{
}

variable_types: caller int

variable_types:
packet
struct DDEV_OPN_REQ { long dd; } *


decompiled_code:
// attributes: thunk
void close_rs232c()
{
open_rs232c_constprop_0();
}

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

original_code:
ER
close_rs232c (ID caller, DDEV_CLS_REQ *packet)
{
}

canonical_original_code:
int close_rs232c(int caller, struct DDEV_CLS_REQ *packet)
{
}

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


decompiled_code:
// attributes: thunk
void read_rs232c()
{
open_rs232c_constprop_0();
}

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

original_code:
ER
read_rs232c (ID caller, DDEV_REA_REQ *packet)
{
}

canonical_original_code:
int read_rs232c(int caller, struct DDEV_REA_REQ *packet)
{
}

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


decompiled_code:
// attributes: thunk
void write_rs232c()
{
open_rs232c_constprop_0();
}

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

original_code:
ER
write_rs232c (ID caller, DDEV_WRI_REQ *packet)
{
}

canonical_original_code:
int write_rs232c(int caller, struct DDEV_WRI_REQ *packet)
{
}

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


decompiled_code:
// attributes: thunk
void control_rs232c()
{
open_rs232c_constprop_0();
}

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

original_code:
ER
control_rs232c (ID caller, DDEV_CTL_REQ *packet)
{
}

canonical_original_code:
int control_rs232c(int caller, struct DDEV_CTL_REQ *packet)
{
}

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


decompiled_code:
__int64 probe_rs232c()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func10()
{
return 1LL;
}

original_code:
W
probe_rs232c (W number)
{
  return ((1));
}

canonical_original_code:
long probe_rs232c(long number)
{
  return ((1));
}

variable_types: number long

return_type: long


original_code:
ER
setup_rs232c (W port,
       W speed,
       W parity,
       W start_stop_bit,
       W data_length)
{
  return ((-17));
}

canonical_original_code:
int setup_rs232c(long port, long speed, long parity, long start_stop_bit, long data_length)
{
  return ((-17));
}

variable_types: port long

variable_types: speed long

variable_types: parity long


original_code:
ER
write_byte_rs232c (W port, UB data)
{
  return ((-17));
}

canonical_original_code:
int write_byte_rs232c(long port, unsigned char data)
{
  return ((-17));
}

variable_types:
data
unsigned char


original_code:
ER
read_byte_rs232c (W port, UB *data)
{
  return ((-17));
}

canonical_original_code:
int read_byte_rs232c(long port, unsigned char *data)
{
  return ((-17));
}

variable_types:
data
unsigned char *


decompiled_code:
__int64 init_driver()
{
__int64 v0; // rsi

init_log();
recvport = get_port(1096LL, 1096LL);
v0 = (unsigned int)recvport;
if ( recvport <= 0 )
{
dbg_printf("rs232c: cannot make receive porrt.\n", (unsigned int)recvport);
slp_tsk();
v0 = (unsigned int)recvport;
}
return regist_port("driver.rs232c", v0);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rsi

init_log();
recvport = get_port(1096LL, 1096LL);
v0 = (unsigned int)recvport;
if ( recvport <= 0 )
{
dbg_printf("rs232c: cannot make receive porrt.\n", (unsigned int)recvport);
slp_tsk();
v0 = (unsigned int)recvport;
}
return regist_port("driver.rs232c", v0);
}

original_code:
static void
init_driver (void)
{
  int i;
  ER error;
  init_log ();
  recvport = get_port (sizeof (DDEV_RES), sizeof (DDEV_RES));
  if (recvport <= 0)
    {
      dbg_printf ("rs232c: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.rs232c", recvport);
  if (error != (0))
    {
    }
}

canonical_original_code:
static void init_driver()
{
  int i;
  int error;
  init_log ();
  recvport = get_port (sizeof (DDEV_RES), sizeof (DDEV_RES));
  if (recvport <= 0)
    {
      dbg_printf ("rs232c: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.rs232c", recvport);
  if (error != (0))
    {
    }
}

variable_types: error int


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

while ( 1 )
{
do
get_req((unsigned int)recvport, v1, v0);
while ( !sys_errno );
slp_tsk();
}
}

canonical_decompiled_code:
void __noreturn func1()
{
char v0[8]; // [rsp+8h] [rbp-450h] BYREF
char v1[1096]; // [rsp+10h] [rbp-448h] BYREF

while ( 1 )
{
do
get_req((unsigned int)recvport, v1, v0);
while ( !sys_errno );
slp_tsk();
}
}

original_code:
static void
main_loop (void)
{
  DDEV_REQ req;
  extern ER sys_errno;
  UW rsize;
  for (;;)
    {
      get_req (recvport, &req, &rsize);
      switch (sys_errno)
 {
 case (0):
   process_request (&req);
   break;
 default:
   slp_tsk ();
   break;
 }
    }
}

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

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

variable_types:
rsize
unsigned long

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


start

decompiled_code:
void __noreturn start()
{
init_driver();
printf("registed rs232c driver\n");
main_loop();
}

canonical_decompiled_code:
void __noreturn func3()
{
func0();
printf("registed rs232c driver\n");
func1();
}

original_code:
void
start (void)
{
  init_driver ();
  printf ("registed rs232c driver\n");
  main_loop ();
}

canonical_original_code:
void start()
{
  init_driver ();
  printf ("registed rs232c driver\n");
  main_loop ();
}


decompiled_code:
void process_request()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
ER
process_request (DDEV_REQ *req)
{
  switch (req->header.msgtyp)
    {
    case DEV_OPN:
      open_rs232c (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_rs232c (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_rs232c (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_rs232c (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_rs232c (req->header.mbfid, &(req->body.ctl_req));
      break;
    }
}

canonical_original_code:
int process_request(struct DDEV_REQ *req)
{
  switch (req->header.msgtyp)
    {
    case DEV_OPN:
      open_rs232c (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_rs232c (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_rs232c (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_rs232c (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_rs232c (req->header.mbfid, &(req->body.ctl_req));
      break;
    }
}

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


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

eval(": move1 (Move disk ) echo . swap ( from ) echo . ( to ) echo . cr ;");
result = error_no;
if ( !error_no )
{
eval(": hanoi dup 1 = if move1 else");
result = error_no;
if ( !error_no )
{
eval(" 3 ndup 3 ndup + 6 - minus 4 ndup swap 3 ndup 1- hanoi");
result = error_no;
if ( !error_no )
{
result = eval(" 3 ndup 3 ndup 3 ndup move1");
if ( !error_no )
{
result = eval(" 1- rotr swap over + 6 - minus swap rot hanoi");
if ( !error_no )
{
result = eval(" endif ;");
if ( !error_no )
{
result = eval(": N 2 * 3 + ;");
if ( !error_no )
{
result = eval(": disp dup N ndup 0 for ");
if ( !error_no )
{
result = eval(" dup N ndup 0 for over I = ");
if ( !error_no )
{
result = eval(" if (Q ) echo else (. ) echo endif ");
if ( !error_no )
{
result = eval(" loop cr drop drop ");
if ( !error_no )
{
result = eval(" loop drop ;");
if ( !error_no )
{
result = eval(": check over 0 for ");
if ( !error_no )
{
result = eval(" 3 ndup 6 ndup = if drop 0 else ");
if ( !error_no )
{
result = eval(" 3 ndup 6 ndup - abs 3 ndup 6 ndup - = if drop 0 else 1 = endif ");
if ( !error_no )
{
result = eval(" endif");
if ( !error_no )
{
result = eval(" 5 nrot 5 nrot drop drop ");
if ( !error_no )
{
result = eval(" loop rotr drop drop ;");
if ( !error_no )
{
result = eval(": nq dup N ndup 0 for ");
if ( !error_no )
{
result = eval(" I over 1+ dup N 1- copy 1 check if ");
if ( !error_no )
{
result = eval(" dup N ndup over 1+ = if dup N copy disp cr else nq endif ");
if ( !error_no )
{
result = eval(" endif");
if ( !error_no )
{
result = eval(" drop drop loop ;");
if ( !error_no )
result = eval(": queens dup 0 for I 0 nq drop drop loop drop ;");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

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

eval(": move1 (Move disk ) echo . swap ( from ) echo . ( to ) echo . cr ;");
result = error_no;
if ( !error_no )
{
eval(": hanoi dup 1 = if move1 else");
result = error_no;
if ( !error_no )
{
eval(" 3 ndup 3 ndup + 6 - minus 4 ndup swap 3 ndup 1- hanoi");
result = error_no;
if ( !error_no )
{
result = eval(" 3 ndup 3 ndup 3 ndup move1");
if ( !error_no )
{
result = eval(" 1- rotr swap over + 6 - minus swap rot hanoi");
if ( !error_no )
{
result = eval(" endif ;");
if ( !error_no )
{
result = eval(": N 2 * 3 + ;");
if ( !error_no )
{
result = eval(": disp dup N ndup 0 for ");
if ( !error_no )
{
result = eval(" dup N ndup 0 for over I = ");
if ( !error_no )
{
result = eval(" if (Q ) echo else (. ) echo endif ");
if ( !error_no )
{
result = eval(" loop cr drop drop ");
if ( !error_no )
{
result = eval(" loop drop ;");
if ( !error_no )
{
result = eval(": check over 0 for ");
if ( !error_no )
{
result = eval(" 3 ndup 6 ndup = if drop 0 else ");
if ( !error_no )
{
result = eval(" 3 ndup 6 ndup - abs 3 ndup 6 ndup - = if drop 0 else 1 = endif ");
if ( !error_no )
{
result = eval(" endif");
if ( !error_no )
{
result = eval(" 5 nrot 5 nrot drop drop ");
if ( !error_no )
{
result = eval(" loop rotr drop drop ;");
if ( !error_no )
{
result = eval(": nq dup N ndup 0 for ");
if ( !error_no )
{
result = eval(" I over 1+ dup N 1- copy 1 check if ");
if ( !error_no )
{
result = eval(" dup N ndup over 1+ = if dup N copy disp cr else nq endif ");
if ( !error_no )
{
result = eval(" endif");
if ( !error_no )
{
result = eval(" drop drop loop ;");
if ( !error_no )
result = eval(": queens dup 0 for I 0 nq drop drop loop drop ;");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
void f_puzzle()
{
  eval(": move1 (Move disk ) echo . swap  ( from ) echo . ( to ) echo . cr ;"); if (error_no != 0) return;;
  eval(": hanoi dup 1 = if move1 else"); if (error_no != 0) return;;
  eval("    3 ndup 3 ndup + 6 - minus 4 ndup swap 3 ndup 1- hanoi"); if (error_no != 0) return;;
  eval("    3 ndup 3 ndup 3 ndup move1"); if (error_no != 0) return;;
  eval("    1- rotr swap over + 6 - minus swap rot hanoi"); if (error_no != 0) return;;
  eval("  endif ;"); if (error_no != 0) return;;
  eval(": N 2 * 3 + ;"); if (error_no != 0) return;;
  eval(": disp dup N ndup 0 for "); if (error_no != 0) return;;
  eval("    dup N ndup 0 for over I = "); if (error_no != 0) return;;
  eval("      if (Q ) echo else (. ) echo endif "); if (error_no != 0) return;;
  eval("    loop cr drop drop "); if (error_no != 0) return;;
  eval("  loop drop ;"); if (error_no != 0) return;;
  eval(": check over 0 for "); if (error_no != 0) return;;
  eval("    3 ndup 6 ndup = if drop 0 else "); if (error_no != 0) return;;
  eval("        3 ndup 6 ndup - abs 3 ndup 6 ndup - = if drop 0 else 1 = endif "); if (error_no != 0) return;;
  eval("    endif"); if (error_no != 0) return;;
  eval("    5 nrot 5 nrot drop drop "); if (error_no != 0) return;;
  eval("  loop rotr drop drop ;"); if (error_no != 0) return;;
  eval(": nq dup N ndup 0 for "); if (error_no != 0) return;;
  eval("    I over 1+ dup N 1- copy 1 check if "); if (error_no != 0) return;;
  eval("      dup N ndup over 1+ = if dup N copy disp cr else nq endif "); if (error_no != 0) return;;
  eval("    endif"); if (error_no != 0) return;;
  eval("  drop drop loop ;"); if (error_no != 0) return;;
  eval(": queens dup 0 for I 0 nq drop drop loop drop ;"); if (error_no != 0) return;;
}


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

eval(": boxes 16 0 for I setcolor 10 20 I * + dup 100 100 rectf loop ;");
result = error_no;
if ( !error_no )
{
eval(": pre 5 copy drop ;");
result = error_no;
if ( !error_no )
{
eval(": genx 3 ndup 6 ndup - * minus 100 / swap 4 ndup 7 ndup - * 100 / + 5 ndup +");
result = error_no;
if ( !error_no )
{
result = eval(" 5 nrotr 4 ndrop ;");
if ( !error_no )
{
result = eval(": geny swap 3 ndup 6 ndup - * 100 / swap 4 ndup 7 ndup - * 100 / + 4 ndup +");
if ( !error_no )
{
result = eval(" 5 nrotr 4 ndrop ;");
if ( !error_no )
{
result = eval(": gen 6 copy genx 7 nrotr geny ;");
if ( !error_no )
{
result = eval(": keep 7 nrotr 7 nrotr pre ;");
if ( !error_no )
{
result = eval(": post 9 nrot 9 nrot 4 nrot 4 nrot 5 ndup 1- ;");
if ( !error_no )
{
result = eval(": line moveto lineto ;");
if ( !error_no )
{
result = eval(": koch dup 0= if drop line else ");
if ( !error_no )
{
result = eval(" pre 0 0 gen keep 33 0 gen post koch");
if ( !error_no )
{
result = eval(" pre 33 0 gen keep 50 -28 gen post koch");
if ( !error_no )
{
result = eval(" pre 50 -28 gen keep 66 0 gen post koch");
if ( !error_no )
{
result = eval(" pre 66 0 gen keep 100 0 gen post koch");
if ( !error_no )
{
result = eval(" 5 ndrop");
if ( !error_no )
{
result = eval(" endif ;");
if ( !error_no )
{
result = eval(": kochs 10 setcolor 89 440 551 440 4 koch");
if ( !error_no )
{
result = eval(" 11 setcolor 551 440 320 40 4 koch");
if ( !error_no )
result = eval(" 12 setcolor 320 40 89 440 4 koch ;");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

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

eval(": boxes 16 0 for I setcolor 10 20 I * + dup 100 100 rectf loop ;");
result = error_no;
if ( !error_no )
{
eval(": pre 5 copy drop ;");
result = error_no;
if ( !error_no )
{
eval(": genx 3 ndup 6 ndup - * minus 100 / swap 4 ndup 7 ndup - * 100 / + 5 ndup +");
result = error_no;
if ( !error_no )
{
result = eval(" 5 nrotr 4 ndrop ;");
if ( !error_no )
{
result = eval(": geny swap 3 ndup 6 ndup - * 100 / swap 4 ndup 7 ndup - * 100 / + 4 ndup +");
if ( !error_no )
{
result = eval(" 5 nrotr 4 ndrop ;");
if ( !error_no )
{
result = eval(": gen 6 copy genx 7 nrotr geny ;");
if ( !error_no )
{
result = eval(": keep 7 nrotr 7 nrotr pre ;");
if ( !error_no )
{
result = eval(": post 9 nrot 9 nrot 4 nrot 4 nrot 5 ndup 1- ;");
if ( !error_no )
{
result = eval(": line moveto lineto ;");
if ( !error_no )
{
result = eval(": koch dup 0= if drop line else ");
if ( !error_no )
{
result = eval(" pre 0 0 gen keep 33 0 gen post koch");
if ( !error_no )
{
result = eval(" pre 33 0 gen keep 50 -28 gen post koch");
if ( !error_no )
{
result = eval(" pre 50 -28 gen keep 66 0 gen post koch");
if ( !error_no )
{
result = eval(" pre 66 0 gen keep 100 0 gen post koch");
if ( !error_no )
{
result = eval(" 5 ndrop");
if ( !error_no )
{
result = eval(" endif ;");
if ( !error_no )
{
result = eval(": kochs 10 setcolor 89 440 551 440 4 koch");
if ( !error_no )
{
result = eval(" 11 setcolor 551 440 320 40 4 koch");
if ( !error_no )
result = eval(" 12 setcolor 320 40 89 440 4 koch ;");
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
void f_graphics()
{
  eval(": boxes 16 0 for I setcolor 10 20 I * + dup 100 100 rectf loop ;"); if (error_no != 0) return;;
  eval(": pre 5 copy drop ;"); if (error_no != 0) return;;
  eval(": genx 3 ndup 6 ndup - * minus 100 / swap 4 ndup 7 ndup - * 100 / + 5 ndup +"); if (error_no != 0) return;;
  eval("  5 nrotr 4 ndrop ;"); if (error_no != 0) return;;
  eval(": geny swap 3 ndup 6 ndup - * 100 / swap 4 ndup 7 ndup - * 100 / + 4 ndup +"); if (error_no != 0) return;;
  eval("  5 nrotr 4 ndrop ;"); if (error_no != 0) return;;
  eval(": gen 6 copy genx 7 nrotr geny ;"); if (error_no != 0) return;;
  eval(": keep 7 nrotr 7 nrotr pre ;"); if (error_no != 0) return;;
  eval(": post 9 nrot 9 nrot 4 nrot 4 nrot 5 ndup 1- ;"); if (error_no != 0) return;;
  eval(": line moveto lineto ;"); if (error_no != 0) return;;
  eval(": koch dup 0= if drop line else "); if (error_no != 0) return;;
  eval("    pre 0 0 gen keep 33 0 gen post koch"); if (error_no != 0) return;;
  eval("    pre 33 0 gen keep 50 -28 gen post koch"); if (error_no != 0) return;;
  eval("    pre 50 -28 gen keep 66 0 gen post koch"); if (error_no != 0) return;;
  eval("    pre 66 0 gen keep 100 0 gen post koch"); if (error_no != 0) return;;
  eval("    5 ndrop"); if (error_no != 0) return;;
  eval("  endif ;"); if (error_no != 0) return;;
  eval(": kochs 10 setcolor  89 440 551 440 4 koch"); if (error_no != 0) return;;
  eval("        11 setcolor 551 440 320  40 4 koch"); if (error_no != 0) return;;
  eval("        12 setcolor 320  40  89 440 4 koch ;"); if (error_no != 0) return;;
}


decompiled_code:
void __fastcall write_digit2(unsigned __int64 a1, __int64 a2, int a3)
{
unsigned __int64 v3; // rbx
int v4; // edi

if ( a1 && a3 - 1 >= 0 )
{
v3 = a1 % (int)a2;
write_digit2(a1 / (int)a2, a2, (unsigned int)(a3 - 1));
v4 = v3 + 87;
if ( v3 <= 9 )
v4 = v3 + 48;
putchar(v4);
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned __int64 a1, __int64 a2, int a3)
{
unsigned __int64 v3; // rbx
int v4; // edi

if ( a1 && a3 - 1 >= 0 )
{
v3 = a1 % (int)a2;
func0(a1 / (int)a2, a2, (unsigned int)(a3 - 1));
v4 = v3 + 87;
if ( v3 <= 9 )
v4 = v3 + 48;
putchar(v4);
}
}

original_code:
static void
write_digit2 (ULONG n, int base, int width)
{
  int ch;
  if (--width < 0) return;
  if (n > 0)
    {
      write_digit2 (n / base, base, width);
      ch = n % base;
      if ((ch >= 0) && (ch <= 9))
 ch += '0';
      else
 ch = (ch - 10) + 'a';
      putchar (ch);
    }
}

canonical_original_code:
static void write_digit2(unsigned long n, int base, int width)
{
  int ch;
  if (--width < 0) return;
  if (n > 0)
    {
      write_digit2 (n / base, base, width);
      ch = n % base;
      if ((ch >= 0) && (ch <= 9))
 ch += '0';
      else
 ch = (ch - 10) + 'a';
      putchar (ch);
    }
}

variable_types:
n
unsigned long

variable_types: base int

variable_types: width int

variable_types: ch int


decompiled_code:
void __fastcall write_digit(int a1, __int64 a2, int a3)
{
if ( a1 )
{
if ( a1 < 0 && (_DWORD)a2 == 10 )
{
putchar(45);
write_digit2((unsigned int)-a1, 10LL, a3);
}
else
{
write_digit2((unsigned int)a1, a2, a3);
}
}
else
{
putchar(48);
}
}

canonical_decompiled_code:
void __fastcall func1(int a1, __int64 a2, int a3)
{
if ( a1 )
{
if ( a1 < 0 && (_DWORD)a2 == 10 )
{
putchar(45);
func0((unsigned int)-a1, 10LL, a3);
}
else
{
func0((unsigned int)a1, a2, a3);
}
}
else
{
putchar(48);
}
}

original_code:
static void
write_digit (int n, int base, int width)
{
  if (n == 0)
    {
      putchar ('0');
    }
  else if ((n < 0) && (base == 10))
    {
      putchar ('-');
      write_digit2 (-n, base, width);
    }
  else
    {
      write_digit2 (n, base, width);
    }
}

canonical_original_code:
static void write_digit(int n, int base, int width)
{
  if (n == 0)
    {
      putchar ('0');
    }
  else if ((n < 0) && (base == 10))
    {
      putchar ('-');
      write_digit2 (-n, base, width);
    }
  else
    {
      write_digit2 (n, base, width);
    }
}

variable_types: n int


decompiled_code:
int __fastcall write_string(char *a1, int a2)
{
char *v2; // rbx
int v3; // edi
int v4; // ebp
int result; // eax

v2 = a1;
v3 = *a1;
if ( a2 > 0 && (_BYTE)v3 )
{
v4 = 0;
while ( (_BYTE)v3 != 9 )
{
if ( (_BYTE)v3 != 10 )
{
result = putchar(v3);
goto LABEL_5;
}
result = write_cr();
++v4;
v3 = *++v2;
if ( a2 <= v4 )
return result;
LABEL_6:
if ( !(_BYTE)v3 )
return result;
}
result = write_tab();
LABEL_5:
++v4;
v3 = *++v2;
if ( a2 <= v4 )
return result;
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *a1, int a2)
{
char *v2; // rbx
int v3; // edi
int v4; // ebp
int result; // eax

v2 = a1;
v3 = *a1;
if ( a2 > 0 && (_BYTE)v3 )
{
v4 = 0;
while ( (_BYTE)v3 != 9 )
{
if ( (_BYTE)v3 != 10 )
{
result = putchar(v3);
goto LABEL_5;
}
result = write_cr();
++v4;
v3 = *++v2;
if ( a2 <= v4 )
return result;
LABEL_6:
if ( !(_BYTE)v3 )
return result;
}
result = write_tab();
LABEL_5:
++v4;
v3 = *++v2;
if ( a2 <= v4 )
return result;
goto LABEL_6;
}
return result;
}

original_code:
static void
write_string (char *s, int width)
{
  int i;
  for (i = 0; (*s != '\0') && (i < width); i++)
    {
      switch (*s)
 {
 default:
   putchar (*s);
   break;
 case '\n':
   write_cr ();
   break;
 case '\t':
   write_tab ();
   break;
 }
      s++;
    }
}

canonical_original_code:
static void write_string(char *s, int width)
{
  int i;
  for (i = 0; (*s != '\0') && (i < width); i++)
    {
      switch (*s)
 {
 default:
   putchar (*s);
   break;
 case '\n':
   write_cr ();
   break;
 case '\t':
   write_tab ();
   break;
 }
      s++;
    }
}

variable_types:
s
char *

variable_types: i int


variable_types:
fmt
char *

variable_types:
sp
void **


original_code:
void
write_vram (int x, int y, int ch, int attr)
{
  short *addr;
  addr = (short *)0x0B8000;
  ch = ch | (addr [(x + y * 80)] & 0xff00);
  addr [(x + y * 80)] = ch;
}

canonical_original_code:
void write_vram(int x, int y, int ch, int attr)
{
  short *addr;
  addr = (short *)0x0B8000;
  ch = ch | (addr [(x + y * 80)] & 0xff00);
  addr [(x + y * 80)] = ch;
}

variable_types: x int

variable_types: y int

variable_types: attr int

variable_types:
addr
short *


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

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

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

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

original_code:
void
set_cursor_pos (int x, int y)
{
  int addr;
  lock ();
  addr = (x + y * 80);
  outb (0x03d4, 0x0e);
  outb (0x03d5, (addr >> 8) & 0xff);
  outb (0x03d4, 0x0f);
  outb (0x03d5, addr & 0xff);
  unlock ();
}

canonical_original_code:
void set_cursor_pos(int x, int y)
{
  int addr;
  lock ();
  addr = (x + y * 80);
  outb (0x03d4, 0x0e);
  outb (0x03d5, (addr >> 8) & 0xff);
  outb (0x03d4, 0x0f);
  outb (0x03d5, addr & 0xff);
  unlock ();
}

variable_types: addr int


decompiled_code:
__int64 __fastcall string_to_number(char *a1, int a2)
{
char v2; // al
unsigned int v3; // er8
unsigned __int8 v4; // al

v2 = *a1;
v3 = 0;
if ( *a1 )
{
while ( 1 )
{
v4 = v2 - 48;
if ( v4 > 9u )
break;
++a1;
v3 = (char)v4 + a2 * v3;
v2 = *a1;
if ( !*a1 )
return v3;
}
v3 = 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1, int a2)
{
char v2; // al
unsigned int v3; // er8
unsigned __int8 v4; // al

v2 = *a1;
v3 = 0;
if ( *a1 )
{
while ( 1 )
{
v4 = v2 - 48;
if ( v4 > 9u )
break;
++a1;
v3 = (char)v4 + a2 * v3;
v2 = *a1;
if ( !*a1 )
return v3;
}
v3 = 0;
}
return v3;
}

original_code:
int
string_to_number (char *s, int base)
{
  int total = 0;
  while (*s != '\0')
    {
      if (!((*s >= '0') && (*s <= '9')))
 return (0);
      total = (total * base) + (*s - '0');
      s++;
    }
  return (total);
}

canonical_original_code:
int string_to_number(char *s, int base)
{
  int total = 0;
  while (*s != '\0')
    {
      if (!((*s >= '0') && (*s <= '9')))
 return (0);
      total = (total * base) + (*s - '0');
      s++;
    }
  return (total);
}

variable_types: total int


bcopy

original_code:
void
bcopy (const char *src, char *dest, int length)
{
  while (length-- > 0)
    {
      *dest++ = *src++;
    }
}

canonical_original_code:
void bcopy(char *src, char *dest, int length)
{
  while (length-- > 0)
    {
      *dest++ = *src++;
    }
}

variable_types:
src
char *

variable_types:
dest
char *

variable_types: length int


bzero

decompiled_code:
void __fastcall bzero(_BYTE *a1, int a2)
{
_BYTE *v2; // rax

if ( a2 > 0 )
{
v2 = &a1[a2];
do
*a1++ = 0;
while ( a1 != v2 );
}
}

canonical_decompiled_code:
void __fastcall func19(_BYTE *a1, int a2)
{
_BYTE *v2; // rax

if ( a2 > 0 )
{
v2 = &a1[a2];
do
*a1++ = 0;
while ( a1 != v2 );
}
}

original_code:
void
bzero (char *src, int length)
{
  while (length-- > 0)
    {
      *src++ = 0;
    }
}

canonical_original_code:
void bzero(char *src, int length)
{
  while (length-- > 0)
    {
      *src++ = 0;
    }
}


strlen

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

if ( !*a1 )
return 0LL;
v1 = 1 - (_DWORD)a1;
do
LODWORD(result) = v1 + (_DWORD)a1++;
while ( *a1 );
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
int v1; // edx
__int64 result; // rax

if ( !*a1 )
return 0LL;
v1 = 1 - (_DWORD)a1;
do
LODWORD(result) = v1 + (_DWORD)a1++;
while ( *a1 );
return (int)result;
}

original_code:
WORD
strlen (BPTR s)
{
  int i;
  for (i = 0; *s != '\0'; i++, s++)
    ;
  return (i);
}

canonical_original_code:
long strlen(unsigned char *s)
{
  int i;
  for (i = 0; *s != '\0'; i++, s++)
    ;
  return (i);
}

variable_types:
s
unsigned char *


strnlen

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

result = 0LL;
if ( *a1 && a2 > 0 )
{
do
++result;
while ( a1[result] && a2 > result );
}
return result;
}

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

result = 0LL;
if ( *a1 && a2 > 0 )
{
do
++result;
while ( a1[result] && a2 > result );
}
return result;
}

original_code:
WORD
strnlen (BPTR s, WORD len)
{
  WORD i;
  for (i = 0; (*s != '\0') && (i < len); i++, s++)
    ;
  return (i);
}

canonical_original_code:
long strnlen(unsigned char *s, long len)
{
  long i;
  for (i = 0; (*s != '\0') && (i < len); i++, s++)
    ;
  return (i);
}

variable_types: len long

variable_types: i long


strcpy

original_code:
WORD
strcpy (BPTR s1, BPTR s2)
{
  WORD i;
  for (i = 0; *s2; i++)
    {
      *s1++ = *s2++;
    }
  *s1 = *s2;
  return (i);
}

canonical_original_code:
long strcpy(unsigned char *s1, unsigned char *s2)
{
  long i;
  for (i = 0; *s2; i++)
    {
      *s1++ = *s2++;
    }
  *s1 = *s2;
  return (i);
}


strncpy

decompiled_code:
__int64 __fastcall strncpy(__int64 a1, char *a2, __int64 a3)
{
__int64 result; // rax
char v5; // dl

result = 0LL;
v5 = *a2;
if ( a3 >= 0 && v5 )
{
do
{
*(_BYTE *)(a1 + result++) = v5;
v5 = a2[result];
}
while ( a3 >= result && v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2, __int64 a3)
{
__int64 result; // rax
char v5; // dl

result = 0LL;
v5 = *a2;
if ( a3 >= 0 && v5 )
{
do
{
*(_BYTE *)(a1 + result++) = v5;
v5 = a2[result];
}
while ( a3 >= result && v5 );
}
return result;
}

original_code:
WORD
strncpy (BPTR s1, BPTR s2, WORD n)
{
  WORD i;
  for (i = 0; *s2; i++)
    {
      if (i > n)
 {
   return (i);
 }
      *s1++ = *s2++;
    }
  return (i);
}

canonical_original_code:
long strncpy(unsigned char *s1, unsigned char *s2, long n)
{
  long i;
  for (i = 0; *s2; i++)
    {
      if (i > n)
 {
   return (i);
 }
      *s1++ = *s2++;
    }
  return (i);
}

variable_types: n long


decompiled_code:
__int64 __fastcall strncpy_with_key(unsigned __int8 *a1, unsigned __int8 *a2, __int64 a3, int a4)
{
unsigned __int8 v4; // al
__int64 v5; // r8

v4 = *a2;
v5 = 0LL;
if ( *a2 && a3 > 0 )
{
do
{
if ( v4 == a4 )
break;
++v5;
*a1++ = v4;
v4 = a2[v5];
if ( !v4 )
break;
}
while ( a3 != v5 );
}
*a1 = 0;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1, unsigned __int8 *a2, __int64 a3, int a4)
{
unsigned __int8 v4; // al
__int64 v5; // r8

v4 = *a2;
v5 = 0LL;
if ( *a2 && a3 > 0 )
{
do
{
if ( v4 == a4 )
break;
++v5;
*a1++ = v4;
v4 = a2[v5];
if ( !v4 )
break;
}
while ( a3 != v5 );
}
*a1 = 0;
return v5;
}

original_code:
WORD
strncpy_with_key (BPTR s1, BPTR s2, WORD n, int key)
{
  WORD i;
  for (i = 0; *s2; i++)
    {
      if ((i >= n) || (*s2 == key))
 {
   *s1 = '\0';
   return (i);
 }
      *s1++ = *s2++;
    }
  *s1 = *s2;
  return (i);
}

canonical_original_code:
long strncpy_with_key(unsigned char *s1, unsigned char *s2, long n, int key)
{
  long i;
  for (i = 0; *s2; i++)
    {
      if ((i >= n) || (*s2 == key))
 {
   *s1 = '\0';
   return (i);
 }
      *s1++ = *s2++;
    }
  *s1 = *s2;
  return (i);
}

variable_types: key int


strcmp

decompiled_code:
__int64 __fastcall strcmp(unsigned __int8 *a1, unsigned __int8 *a2)
{
int v2; // eax
int v3; // edx
int v4; // edx

v2 = *a1;
v3 = *a2;
if ( !(_BYTE)v2 )
return -v3;
while ( 1 )
{
v4 = *a2;
if ( !(_BYTE)v4 )
return v2 - v4;
if ( (_BYTE)v4 != (_BYTE)v2 )
break;
v2 = *++a1;
if ( !(_BYTE)v2 )
{
v3 = a2[1];
return -v3;
}
++a2;
}
return (unsigned __int8)v4 - (unsigned __int8)v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1, unsigned __int8 *a2)
{
int v2; // eax
int v3; // edx
int v4; // edx

v2 = *a1;
v3 = *a2;
if ( !(_BYTE)v2 )
return -v3;
while ( 1 )
{
v4 = *a2;
if ( !(_BYTE)v4 )
return v2 - v4;
if ( (_BYTE)v4 != (_BYTE)v2 )
break;
v2 = *++a1;
if ( !(_BYTE)v2 )
{
v3 = a2[1];
return -v3;
}
++a2;
}
return (unsigned __int8)v4 - (unsigned __int8)v2;
}

canonical_original_code:
unsigned long strcmp(unsigned char *s1, unsigned char *s2)
{
  while (*s1 && *s2)
    {
      if (*s1 != *s2)
        {
          return (*s2 - *s1);
        }
      s1++;
      s2++;
    }
  return (*s1 - *s2);
}

return_type: unsigned long


strncmp

decompiled_code:
__int64 __fastcall strncmp(unsigned __int8 *a1, unsigned __int8 *a2, __int64 a3)
{
__int64 v4; // rcx
int v5; // eax
int v6; // edx
__int64 result; // rax

v4 = 0LL;
if ( a3 > 0 )
{
while ( 1 )
{
v5 = *a1;
v6 = *a2;
if ( !(_BYTE)v5 || !(_BYTE)v6 )
return v5 - v6;
if ( (_BYTE)v5 != (_BYTE)v6 )
break;
++v4;
++a1;
++a2;
if ( a3 == v4 )
goto LABEL_9;
}
result = (unsigned __int8)v6 - (unsigned __int8)v5;
}
else if ( a3 )
{
result = *a1 - *a2;
}
else
{
LABEL_9:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1, unsigned __int8 *a2, __int64 a3)
{
__int64 v4; // rcx
int v5; // eax
int v6; // edx
__int64 result; // rax

v4 = 0LL;
if ( a3 > 0 )
{
while ( 1 )
{
v5 = *a1;
v6 = *a2;
if ( !(_BYTE)v5 || !(_BYTE)v6 )
return v5 - v6;
if ( (_BYTE)v5 != (_BYTE)v6 )
break;
++v4;
++a1;
++a2;
if ( a3 == v4 )
goto LABEL_9;
}
result = (unsigned __int8)v6 - (unsigned __int8)v5;
}
else if ( a3 )
{
result = *a1 - *a2;
}
else
{
LABEL_9:
result = 0LL;
}
return result;
}

original_code:
ULONG
strncmp (BPTR s1, BPTR s2, WORD n)
{
  WORD i;
  for (i = 0; (i < n) && *s1 && *s2; i++)
    {
      if (*s1 != *s2)
        return (*s2 - *s1);
      s1++;
      s2++;
    }
  if (i == n)
    return 0;
  return (*s1 - *s2);
}

canonical_original_code:
unsigned long strncmp(unsigned char *s1, unsigned char *s2, long n)
{
  long i;
  for (i = 0; (i < n) && *s1 && *s2; i++)
    {
      if (*s1 != *s2)
        return (*s2 - *s1);
      s1++;
      s2++;
    }
  if (i == n)
    return 0;
  return (*s1 - *s2);
}


toupper

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

result = a1;
if ( a1 - 97 < 0x1A )
result = a1 - 32;
return result;
}

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

result = a1;
if ( a1 - 97 < 0x1A )
result = a1 - 32;
return result;
}

original_code:
int
toupper (int ch)
{
  if ((ch >= 'a') && (ch <= 'z'))
    {
      ch = ch + ('A' - 'a');
    }
  return (ch);
}

canonical_original_code:
int toupper(int ch)
{
  if ((ch >= 'a') && (ch <= 'z'))
    {
      ch = ch + ('A' - 'a');
    }
  return (ch);
}

variable_types: ch int


canonical_original_code:
void scroll_up()
{
  unsigned short *addr;
  int i;
  addr = (unsigned short *)0x0B8000;
  for (i = 0; i < 2000 - 80; i++)
    {
      addr[i] = addr[i + 80];
    }
  for (i = 0; i <= 80; i++)
    {
      write_vram (i, 24, ' ', 0xe1);
    }
}

variable_types:
addr
unsigned short *

variable_types: i int


atoi

decompiled_code:
__int64 __fastcall atoi(char *a1)
{
return string_to_number(a1, 10);
}

canonical_decompiled_code:
__int64 __fastcall func17(char *a1)
{
return func16(a1, 10);
}

original_code:
int
atoi (char *s)
{
  int result;
  result = string_to_number (s, 10);
  return result;
}

canonical_original_code:
int atoi(char *s)
{
  int result;
  result = string_to_number (s, 10);
  return result;
}

variable_types:
s
char *

variable_types: result int


decompiled_code:
void clear_stack()
{
dword_3C0 = 0;
}

canonical_decompiled_code:
void func2()
{
dword_3C0 = 0;
}

original_code:
void clear_stack()
{
  sp = 0;
}

canonical_original_code:
void clear_stack()
{
  sp = 0;
}


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

result = pop(a1);
if ( !error_no )
{
if ( (int)result <= 0 || dword_3C0 < (int)result )
error_no = 19;
else
result = push(stack[dword_3C0 - (int)result]);
}
return result;
}

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

result = func1(a1);
if ( !error_no )
{
if ( (int)result <= 0 || dword_3C0 < (int)result )
error_no = 19;
else
result = func0(stack[dword_3C0 - (int)result]);
}
return result;
}

original_code:
void f_ndup()
{
  int v1, v2;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  v2 = stack[sp - v1];
  push(v2); if (error_no != 0) return;;
}

canonical_original_code:
void f_ndup()
{
  int v1; int v2;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  v2 = stack[sp - v1];
  push(v2); if (error_no != 0) return;;
}


decompiled_code:
void *__fastcall f_nrot(__int64 a1)
{
void *result; // rax
int v2; // ebx
int v3; // ebp

result = (void *)pop(a1);
if ( !error_no )
{
if ( (int)result <= 0 || (v2 = dword_3C0, dword_3C0 < (int)result) )
{
error_no = 19;
}
else if ( (_DWORD)result != 1 )
{
v3 = stack[dword_3C0 - (int)result];
result = memmove(
&stack[dword_3C0 - (__int64)(int)result],
(char *)&unk_3E4 + 4 * (dword_3C0 - (__int64)(int)result),
4LL * (unsigned int)((_DWORD)result - 1));
stack[v2 - 1] = v3;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1)
{
void *result; // rax
int v2; // ebx
int v3; // ebp

result = (void *)func1(a1);
if ( !error_no )
{
if ( (int)result <= 0 || (v2 = dword_3C0, dword_3C0 < (int)result) )
{
error_no = 19;
}
else if ( (_DWORD)result != 1 )
{
v3 = stack[dword_3C0 - (int)result];
result = memmove(
&stack[dword_3C0 - (__int64)(int)result],
(char *)&unk_3E4 + 4 * (dword_3C0 - (__int64)(int)result),
4LL * (unsigned int)((_DWORD)result - 1));
stack[v2 - 1] = v3;
}
}
return result;
}

original_code:
void f_nrot()
{
  int v1, v2, i;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  if (v1 == 1) return;
  v2 = stack[sp - v1];
  for(i = v1; i > 1; --i) {
    stack[sp - i] = stack[sp -i + 1];
  }
  stack[sp - 1] = v2;
}

canonical_original_code:
void f_nrot()
{
  int v1; int v2; int i;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  if (v1 == 1) return;
  v2 = stack[sp - v1];
  for(i = v1; i > 1; --i) {
    stack[sp - i] = stack[sp -i + 1];
  }
  stack[sp - 1] = v2;
}


decompiled_code:
void *__fastcall f_nrotr(__int64 a1)
{
void *result; // rax
int v2; // ebx
int v3; // ebp
int v4; // er12
__int64 v5; // rax
size_t v6; // rdx

result = (void *)pop(a1);
if ( !error_no )
{
v2 = (int)result;
if ( (int)result <= 0 || (v3 = dword_3C0, dword_3C0 < (int)result) )
{
error_no = 19;
}
else if ( (_DWORD)result != 1 )
{
v4 = stack[dword_3C0 - 1];
v5 = 0x3FFFFFFFFFFFFFFFLL * (unsigned int)((_DWORD)result - 2);
if ( v2 <= 1 )
v5 = 0LL;
v6 = 4LL * (unsigned int)(v2 - 1);
if ( v2 <= 1 )
v6 = 4LL;
result = memmove(&stack[dword_3C0 - 1 + v5], (char *)&unk_3DC + 4 * dword_3C0 + v5 * 4 - 4, v6);
stack[v3 - v2] = v4;
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1)
{
void *result; // rax
int v2; // ebx
int v3; // ebp
int v4; // er12
__int64 v5; // rax
size_t v6; // rdx

result = (void *)func1(a1);
if ( !error_no )
{
v2 = (int)result;
if ( (int)result <= 0 || (v3 = dword_3C0, dword_3C0 < (int)result) )
{
error_no = 19;
}
else if ( (_DWORD)result != 1 )
{
v4 = stack[dword_3C0 - 1];
v5 = 0x3FFFFFFFFFFFFFFFLL * (unsigned int)((_DWORD)result - 2);
if ( v2 <= 1 )
v5 = 0LL;
v6 = 4LL * (unsigned int)(v2 - 1);
if ( v2 <= 1 )
v6 = 4LL;
result = memmove(&stack[dword_3C0 - 1 + v5], (char *)&unk_3DC + 4 * dword_3C0 + v5 * 4 - 4, v6);
stack[v3 - v2] = v4;
}
}
return result;
}

original_code:
void f_nrotr()
{
  int v1, v2, i;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  if (v1 == 1) return;
  v2 = stack[sp - 1];
  for(i = 1; i < v1; ++i) {
    stack[sp - i] = stack[sp -i - 1];
  }
  stack[sp - v1] = v2;
}

canonical_original_code:
void f_nrotr()
{
  int v1; int v2; int i;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  if (v1 == 1) return;
  v2 = stack[sp - 1];
  for(i = 1; i < v1; ++i) {
    stack[sp - i] = stack[sp -i - 1];
  }
  stack[sp - v1] = v2;
}


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

result = pop(a1);
if ( !error_no )
{
if ( (int)result <= 0 || dword_3C0 < (int)result )
error_no = 19;
else
dword_3C0 -= result;
}
return result;
}

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

result = func1(a1);
if ( !error_no )
{
if ( (int)result <= 0 || dword_3C0 < (int)result )
error_no = 19;
else
dword_3C0 -= result;
}
return result;
}

original_code:
void f_ndrop()
{
  int v1, v2, i;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  sp -= v1;
}

canonical_original_code:
void f_ndrop()
{
  int v1; int v2; int i;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  sp -= v1;
}


decompiled_code:
__int64 f_SP()
{
return push(dword_3C0);
}

canonical_decompiled_code:
__int64 func9()
{
return func0(dword_3C0);
}

original_code:
void f_SP()
{
  push(sp); if (error_no != 0) return;;
}


decompiled_code:
__int64 __fastcall f_copy(__int64 a1)
{
__int64 result; // rax
int v2; // esi
int v3; // ecx

result = pop(a1);
v2 = result;
if ( !error_no )
{
if ( (int)result > 0 && (result = (unsigned int)dword_3C0, dword_3C0 >= v2) )
{
while ( 1 )
{
push(stack[(int)result - v2]);
result = error_no;
if ( error_no || v2 == v3 + 1 )
break;
LODWORD(result) = dword_3C0;
}
}
else
{
error_no = 19;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
int v2; // esi
int v3; // ecx

result = func1(a1);
v2 = result;
if ( !error_no )
{
if ( (int)result > 0 && (result = (unsigned int)dword_3C0, dword_3C0 >= v2) )
{
while ( 1 )
{
func0(stack[(int)result - v2]);
result = error_no;
if ( error_no || v2 == v3 + 1 )
break;
LODWORD(result) = dword_3C0;
}
}
else
{
error_no = 19;
}
}
return result;
}

original_code:
void f_copy()
{
  int v1, v2, i;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  for(i = 0; i < v1; ++i) {
    push(stack[sp-v1]); if (error_no != 0) return;;
  }
}

canonical_original_code:
void f_copy()
{
  int v1; int v2; int i;
  v1 = pop(); if (error_no != 0) return;;
  if ((v1 <= 0) || (v1 > sp)) {
    error_no = 19;
    return;
  }
  for(i = 0; i < v1; ++i) {
    push(stack[sp-v1]); if (error_no != 0) return;;
  }
}


pop

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

result = (unsigned int)dword_3C0;
if ( dword_3C0 )
{
--dword_3C0;
result = (unsigned int)stack[(int)result - 1];
}
else
{
error_no = 2;
}
return result;
}

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

result = (unsigned int)dword_3C0;
if ( dword_3C0 )
{
--dword_3C0;
result = (unsigned int)stack[(int)result - 1];
}
else
{
error_no = 2;
}
return result;
}

original_code:
int pop()
{
  if (sp == 0) {
    error_no = 2;
    return;
  }
  return stack[--sp];
}


decompiled_code:
__int64 open_pcmcia()
{
wreg(2LL, 0LL);
wreg(47LL, 0LL);
wreg(6LL, 32LL);
wreg(3LL, 64LL);
wreg(5LL, 0LL);
wreg(4LL, 255LL);
wreg(2LL, 144LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
wreg(2LL, 0LL);
wreg(47LL, 0LL);
wreg(6LL, 32LL);
wreg(3LL, 64LL);
wreg(5LL, 0LL);
wreg(4LL, 255LL);
wreg(2LL, 144LL);
return 0LL;
}

original_code:
ER
open_pcmcia (ID caller, DDEV_OPN_REQ *packet)
{
  wreg(0x02,0x00);
  wreg(0x2f,0x00);
  wreg(0x06,0x20);
  wreg(0x03,0x40);
  wreg(0x05,0x00);
  wreg(0x04,0xff);
  wreg(0x02,0x90);
  return ((0));
}

canonical_original_code:
int open_pcmcia(int caller, struct DDEV_OPN_REQ *packet)
{
  wreg(0x02,0x00);
  wreg(0x2f,0x00);
  wreg(0x06,0x20);
  wreg(0x03,0x40);
  wreg(0x05,0x00);
  wreg(0x04,0xff);
  wreg(0x02,0x90);
  return ((0));
}

variable_types: caller int

variable_types:
packet
struct DDEV_OPN_REQ { long dd; } *


decompiled_code:
__int64 close_pcmcia()
{
return 4294967279LL;
}

original_code:
ER
close_pcmcia (ID caller, DDEV_CLS_REQ *packet)
{
  return ((-17));
}

canonical_original_code:
int close_pcmcia(int caller, struct DDEV_CLS_REQ *packet)
{
  return ((-17));
}

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


decompiled_code:
// attributes: thunk
__int64 read_pcmcia()
{
return close_pcmcia_constprop_0();
}

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

original_code:
ER
read_pcmcia (ID caller, DDEV_REA_REQ *packet)
{
  return ((-17));
}

canonical_original_code:
int read_pcmcia(int caller, struct DDEV_REA_REQ *packet)
{
  return ((-17));
}

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


decompiled_code:
// attributes: thunk
__int64 write_pcmcia()
{
return close_pcmcia_constprop_0();
}

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

original_code:
ER
write_pcmcia (ID caller, DDEV_WRI_REQ *packet)
{
  return ((-17));
}

canonical_original_code:
int write_pcmcia(int caller, struct DDEV_WRI_REQ *packet)
{
  return ((-17));
}

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


decompiled_code:
__int64 __fastcall control_pcmcia(__int64 a1, __int64 a2)
{
if ( !*(_QWORD *)(a2 + 8) )
{
dbg_printf("pcmcia: read memory\n");
dump_cis();
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
if ( !*(_QWORD *)(a2 + 8) )
{
dbg_printf("pcmcia: read memory\n");
dump_cis();
}
return 0LL;
}

original_code:
ER
control_pcmcia (ID caller, DDEV_CTL_REQ *packet)
{
int i;
  switch (packet->cmd)
    {
    case 0:
      dbg_printf("pcmcia: read memory\n");
      dump_cis();
      break;
    default:
      break;
    }
  return ((0));
}

canonical_original_code:
int control_pcmcia(int caller, struct DDEV_CTL_REQ *packet)
{
int i;
  switch (packet->cmd)
    {
    case 0:
      dbg_printf("pcmcia: read memory\n");
      dump_cis();
      break;
    default:
      break;
    }
  return ((0));
}

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


decompiled_code:
__int64 init_driver()
{
__int64 v0; // rsi
__int64 result; // rax

dbg_printf("pcmcia: init_log\n");
init_log();
dbg_printf("pcmcia: get_port\n");
recvport = get_port(1096LL, 1096LL);
v0 = (unsigned int)recvport;
if ( recvport <= 0 )
{
dbg_printf("pcmcia: cannot make receive port.\n");
slp_tsk("pcmcia: cannot make receive port.\n", v0);
v0 = (unsigned int)recvport;
}
result = regist_port("driver.pcmcia", v0);
if ( (_DWORD)result )
{
dbg_printf("pcmcia: cannot regist receive port.\n");
result = slp_tsk("pcmcia: cannot regist receive port.\n", v0);
}
return result;
}

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

dbg_printf("pcmcia: init_log\n");
init_log();
dbg_printf("pcmcia: get_port\n");
recvport = get_port(1096LL, 1096LL);
v0 = (unsigned int)recvport;
if ( recvport <= 0 )
{
dbg_printf("pcmcia: cannot make receive port.\n");
slp_tsk("pcmcia: cannot make receive port.\n", v0);
v0 = (unsigned int)recvport;
}
result = regist_port("driver.pcmcia", v0);
if ( (_DWORD)result )
{
dbg_printf("pcmcia: cannot regist receive port.\n");
result = slp_tsk("pcmcia: cannot regist receive port.\n", v0);
}
return result;
}

original_code:
static void
init_driver (void)
{
  int i;
  ER error;
  dbg_printf("pcmcia: init_log\n");
  init_log ();
  dbg_printf("pcmcia: get_port\n");
  recvport = get_port (sizeof (DDEV_RES), sizeof (DDEV_RES));
  if (recvport <= 0)
    {
      dbg_printf ("pcmcia: cannot make receive port.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.pcmcia", recvport);
  if (error != (0))
    {
      dbg_printf ("pcmcia: cannot regist receive port.\n");
      slp_tsk();
    }
}

canonical_original_code:
static void init_driver()
{
  int i;
  int error;
  dbg_printf("pcmcia: init_log\n");
  init_log ();
  dbg_printf("pcmcia: get_port\n");
  recvport = get_port (sizeof (DDEV_RES), sizeof (DDEV_RES));
  if (recvport <= 0)
    {
      dbg_printf ("pcmcia: cannot make receive port.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.pcmcia", recvport);
  if (error != (0))
    {
      dbg_printf ("pcmcia: cannot regist receive port.\n");
      slp_tsk();
    }
}

variable_types: error int


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

result = *((_QWORD *)a1 + 1);
if ( !result )
return open_pcmcia(*a1, a1 + 8);
if ( result == 4 )
result = control_pcmcia(*a1, (__int64)(a1 + 8));
return result;
}

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

result = *((_QWORD *)a1 + 1);
if ( !result )
return func2(*a1, a1 + 8);
if ( result == 4 )
result = func6(*a1, (__int64)(a1 + 8));
return result;
}

original_code:
ER
process_request (DDEV_REQ *req)
{
  switch (req->header.msgtyp)
    {
    case DEV_OPN:
      open_pcmcia (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_pcmcia (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_pcmcia (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_pcmcia (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_pcmcia (req->header.mbfid, &(req->body.ctl_req));
      break;
    }
}

canonical_original_code:
int process_request(struct DDEV_REQ *req)
{
  switch (req->header.msgtyp)
    {
    case DEV_OPN:
      open_pcmcia (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_pcmcia (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_pcmcia (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_pcmcia (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_pcmcia (req->header.mbfid, &(req->body.ctl_req));
      break;
    }
}

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


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

dbg_printf("main loop\n");
while ( 1 )
{
get_req((unsigned int)recvport, v1, v0);
if ( sys_errno )
{
dbg_printf("pcmcia: main loop Unknown error.\n");
slp_tsk("pcmcia: main loop Unknown error.\n", v1);
}
else
{
process_request(v1);
}
}
}

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

dbg_printf("main loop\n");
while ( 1 )
{
get_req((unsigned int)recvport, v1, v0);
if ( sys_errno )
{
dbg_printf("pcmcia: main loop Unknown error.\n");
slp_tsk("pcmcia: main loop Unknown error.\n", v1);
}
else
{
func7(v1);
}
}
}

original_code:
static void
main_loop (void)
{
  DDEV_REQ req;
  extern ER sys_errno;
  UW rsize;
  dbg_printf("main loop\n");
  for (;;)
    {
      get_req (recvport, &req, &rsize);
      switch (sys_errno)
 {
 case (0):
   process_request (&req);
   break;
 default:
          dbg_printf ("pcmcia: main loop Unknown error.\n");
   slp_tsk ();
   break;
 }
    }
}

canonical_original_code:
static void main_loop()
{
  struct DDEV_REQ req;
  extern int sys_errno;
  unsigned long rsize;
  dbg_printf("main loop\n");
  for (;;)
    {
      get_req (recvport, &req, &rsize);
      switch (sys_errno)
 {
 case (0):
   process_request (&req);
   break;
 default:
          dbg_printf ("pcmcia: main loop Unknown error.\n");
   slp_tsk ();
   break;
 }
    }
}

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

variable_types:
rsize
unsigned long


start

decompiled_code:
void __noreturn start()
{
probe(&dev_table);
init_driver();
printf("registed pcmcia driver.\n");
main_loop();
}

canonical_decompiled_code:
void __noreturn func9()
{
probe(&dev_table);
func0();
printf("registed pcmcia driver.\n");
func8();
}

original_code:
void
start (void)
{
  probe (&dev_table[0]);
  init_driver ();
  printf ("registed pcmcia driver.\n");
  main_loop ();
}

canonical_original_code:
void start()
{
  probe (&dev_table[0]);
  init_driver ();
  printf ("registed pcmcia driver.\n");
  main_loop ();
}


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

result = (unsigned int)dp;
if ( dp )
return (unsigned int)--dp;
error_no = 8;
return result;
}

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

result = (unsigned int)dp;
if ( dp )
return (unsigned int)--dp;
error_no = 8;
return result;
}

original_code:
void drop_dict()
{
  if (dp == 0) {
    error_no = 8;
    return;
  }
  --dp;
}


decompiled_code:
__int64 query_dp()
{
return (unsigned int)dp;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)dp;
}

original_code:
int query_dp()
{
  return dp;
}

canonical_original_code:
int query_dp()
{
  return dp;
}


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

result = (unsigned int)csp;
old_csp = csp;
return result;
}

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

result = (unsigned int)csp;
old_csp = csp;
return result;
}

original_code:
void keep_old_csp()
{
  old_csp = csp;
}

canonical_original_code:
void keep_old_csp()
{
  old_csp = csp;
}


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

result = (unsigned int)old_csp;
csp = old_csp;
return result;
}

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

result = (unsigned int)old_csp;
csp = old_csp;
return result;
}

original_code:
void reload_old_csp()
{
  csp = old_csp;
}


rpop

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

result = (unsigned int)dword_1440;
if ( dword_1440 )
{
--dword_1440;
result = (unsigned int)rstack[(int)result - 1];
}
else
{
error_no = 11;
}
return result;
}

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

result = (unsigned int)dword_1440;
if ( dword_1440 )
{
--dword_1440;
result = (unsigned int)rstack[(int)result - 1];
}
else
{
error_no = 11;
}
return result;
}

original_code:
int rpop()
{
  if (rsp == 0) {
    error_no = 11;
    return;
  }
  return rstack[--rsp];
}


rpeek

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

result = (unsigned int)dword_1440;
if ( dword_1440 )
return (unsigned int)rstack[dword_1440 - 1];
error_no = 11;
return result;
}

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

result = (unsigned int)dword_1440;
if ( dword_1440 )
return (unsigned int)rstack[dword_1440 - 1];
error_no = 11;
return result;
}

original_code:
int rpeek()
{
  if (rsp == 0) {
    error_no = 11;
    return;
  }
  return rstack[rsp-1];
}


decompiled_code:
void clear_rstack()
{
dword_1440 = 0;
}

original_code:
void clear_rstack()
{
  rsp = 0;
}

canonical_original_code:
void clear_rstack()
{
  rsp = 0;
}


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

if ( eval_mode )
{
if ( eval_mode != 1 )
{
error_no = 15;
return spush(6);
}
spush(1);
result = error_no;
if ( !error_no )
return spush(6);
}
else
{
result = spush(0);
if ( !error_no )
{
result = pop();
if ( !error_no )
{
if ( !(_DWORD)result )
eval_mode = 1;
return spush(6);
}
}
}
return result;
}

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

if ( eval_mode )
{
if ( eval_mode != 1 )
{
error_no = 15;
return func15(6);
}
func15(1);
result = error_no;
if ( !error_no )
return func15(6);
}
else
{
result = func15(0);
if ( !error_no )
{
result = pop();
if ( !error_no )
{
if ( !(_DWORD)result )
eval_mode = 1;
return func15(6);
}
}
}
return result;
}

original_code:
void f_if()
{
  int val;
  switch(eval_mode) {
  case RUN:
    spush(eval_mode); if (error_no != 0) return;;
    val = pop(); if (error_no != 0) return;;
    if (! val) eval_mode = SKIP;
    break;
  case SKIP:
    spush(SKIP); if (error_no != 0) return;;
    break;
  default:
    error_no = 15;
  }
  spush(IF); if (error_no != 0) return;;
}

variable_types: val int


spop

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

result = (unsigned int)ssp;
if ( ssp )
{
--ssp;
result = (unsigned int)sstack[(int)result - 1];
}
else
{
error_no = 14;
}
return result;
}

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

result = (unsigned int)ssp;
if ( ssp )
{
--ssp;
result = (unsigned int)sstack[(int)result - 1];
}
else
{
error_no = 14;
}
return result;
}

canonical_original_code:
enum MODE spop()
{
  if (ssp == 0) {
    error_no = 14;
    return;
  }
  return sstack[--ssp];
}

return_type: enum MODE { RUN=0, SKIP=1, DIC1=2, DIC2=3, FGT=4, DEF=5, IF=6, DO=7, FOR=8, ON=9, OFF=10 }


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

result = spop();
if ( !error_no )
{
if ( (_DWORD)result != 6 )
{
error_no = 16;
return result;
}
result = spop();
if ( !error_no )
{
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
goto LABEL_9;
goto LABEL_8;
}
if ( eval_mode )
{
if ( eval_mode != 1 )
{
LABEL_8:
error_no = 15;
goto LABEL_9;
}
eval_mode = 0;
}
else
{
eval_mode = 1;
}
LABEL_9:
spush(result);
result = error_no;
if ( !error_no )
result = spush(6);
return result;
}
}
return result;
}

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

result = func19();
if ( !error_no )
{
if ( (_DWORD)result != 6 )
{
error_no = 16;
return result;
}
result = func19();
if ( !error_no )
{
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
goto LABEL_9;
goto LABEL_8;
}
if ( eval_mode )
{
if ( eval_mode != 1 )
{
LABEL_8:
error_no = 15;
goto LABEL_9;
}
eval_mode = 0;
}
else
{
eval_mode = 1;
}
LABEL_9:
func15(result);
result = error_no;
if ( !error_no )
result = func15(6);
return result;
}
}
return result;
}

original_code:
void f_else()
{
  MODE str, mode;
  str = spop(); if (error_no != 0) return;;
  if (str != IF) {
    error_no = 16;
    return;
  }
  mode = spop(); if (error_no != 0) return;;
  switch(mode) {
  case RUN:
    switch(eval_mode) {
    case RUN:
      eval_mode = SKIP;
      break;
    case SKIP:
      eval_mode = mode;
      break;
    default:
      error_no = 15;
    }
    break;
  case SKIP:
    break;
  default:
    error_no = 15;
  }
  spush(mode); if (error_no != 0) return;;
  spush(IF); if (error_no != 0) return;;
}

canonical_original_code:
void f_else()
{
  enum MODE str; enum MODE mode;
  str = spop(); if (error_no != 0) return;;
  if (str != IF) {
    error_no = 16;
    return;
  }
  mode = spop(); if (error_no != 0) return;;
  switch(mode) {
  case RUN:
    switch(eval_mode) {
    case RUN:
      eval_mode = SKIP;
      break;
    case SKIP:
      eval_mode = mode;
      break;
    default:
      error_no = 15;
    }
    break;
  case SKIP:
    break;
  default:
    error_no = 15;
  }
  spush(mode); if (error_no != 0) return;;
  spush(IF); if (error_no != 0) return;;
}

variable_types: enum MODE { RUN=0, SKIP=1, DIC1=2, DIC2=3, FGT=4, DEF=5, IF=6, DO=7, FOR=8, ON=9, OFF=10 }


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

result = spop();
if ( !error_no )
{
if ( (_DWORD)result == 6 )
{
result = spop();
if ( !error_no )
eval_mode = result;
}
else
{
error_no = 16;
}
}
return result;
}

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

result = func19();
if ( !error_no )
{
if ( (_DWORD)result == 6 )
{
result = func19();
if ( !error_no )
eval_mode = result;
}
else
{
error_no = 16;
}
}
return result;
}

original_code:
void f_endif()
{
  MODE str, mode;
  str = spop(); if (error_no != 0) return;;
  if (str != IF) {
    error_no = 16;
    return;
  }
  mode = spop(); if (error_no != 0) return;;
  eval_mode = mode;
}

canonical_original_code:
void f_endif()
{
  enum MODE str; enum MODE mode;
  str = spop(); if (error_no != 0) return;;
  if (str != IF) {
    error_no = 16;
    return;
  }
  mode = spop(); if (error_no != 0) return;;
  eval_mode = mode;
}

user_defined_types: enum MODE { RUN=0, SKIP=1, DIC1=2, DIC2=3, FGT=4, DEF=5, IF=6, DO=7, FOR=8, ON=9, OFF=10 }


decompiled_code:
void clear_sstack()
{
ssp = 0;
}

canonical_decompiled_code:
void func22()
{
ssp = 0;
}

original_code:
void clear_sstack()
{
  ssp = 0;
}

canonical_original_code:
void clear_sstack()
{
  ssp = 0;
}


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

result = (unsigned int)dword_1440;
if ( dword_1440 > 1 )
return push((unsigned int)rstack[dword_1440 - 2]);
error_no = 11;
return result;
}

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

result = (unsigned int)dword_1440;
if ( dword_1440 > 1 )
return push((unsigned int)rstack[dword_1440 - 2]);
error_no = 11;
return result;
}

original_code:
void f_count()
{
  int num;
  if (rsp - 2 < 0) {
    error_no = 11;
    return;
  }
  num = rstack[rsp-2];
  push(num); if (error_no != 0) return;;
}

variable_types: num int


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

result = eval_mode;
if ( eval_mode || memory == 9 )
error_no = 12;
else
eval_mode = 2;
return result;
}

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

result = eval_mode;
if ( eval_mode || memory == 9 )
error_no = 12;
else
eval_mode = 2;
return result;
}

original_code:
void f_dict_start()
{
  if (eval_mode != RUN || memory == ON) {
    error_no = 12;
    return;
  }
  eval_mode = DIC1;
}


decompiled_code:
int __fastcall f_dict_end(__int64 a1, const char *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
int result; // eax

if ( eval_mode == 3 )
{
cpush_csp(-1);
result = error_no;
if ( !error_no )
{
keep_old_csp("Memory %s [%d-%d]\n", a2, v2, v3);
eval_mode = 0;
result = printf(
"Memory %s [%d-%d]\n",
&dict_name[12 * dp - 12],
*(unsigned int *)&dict_name[12 * dp - 4],
(unsigned int)(csp - 1));
}
}
else
{
error_no = 12;
}
return result;
}

canonical_decompiled_code:
int __fastcall func25(__int64 a1, const char *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
int result; // eax

if ( eval_mode == 3 )
{
func9(-1);
result = error_no;
if ( !error_no )
{
func5("Memory %s [%d-%d]\n", a2, v2, v3);
eval_mode = 0;
result = printf(
"Memory %s [%d-%d]\n",
&dict_name[12 * dp - 12],
*(unsigned int *)&dict_name[12 * dp - 4],
(unsigned int)(csp - 1));
}
}
else
{
error_no = 12;
}
return result;
}

original_code:
void f_dict_end()
{
  if (eval_mode != DIC2) {
    error_no = 12;
    return;
  }
  cpush_csp(-1); if (error_no != 0) return;;
  keep_old_csp();
  eval_mode = RUN;
  printf("Memory %s [%d-%d]\n",
  dict_name[dp-1].name, dict_name[dp-1].point, csp-1);
}


decompiled_code:
__int64 __fastcall f_while(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rsi
int v3; // ebx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // rdx
int v8; // er8
__int64 v9; // rdx
__int64 v10; // r8
__int64 v11; // r9

result = spop();
v2 = error_no;
if ( !error_no )
{
if ( (_DWORD)result != 7 )
{
error_no = 16;
return result;
}
result = spop();
v3 = result;
if ( !error_no )
{
result = pop();
v7 = error_no;
if ( !error_no )
{
if ( !(_DWORD)result )
goto LABEL_15;
if ( memory == 9 )
{
result = cpush_func((__int64)f_while);
if ( error_no )
return result;
cpush_csp(-1);
}
memory = 10;
result = rpeek();
if ( !error_no )
{
result = rpush(-1);
if ( !error_no )
{
result = rpush(v8);
if ( !error_no )
{
result = spush(v3);
v2 = error_no;
if ( !error_no )
{
result = spush(7);
if ( !error_no )
{
a1 = (unsigned int)v10;
exec_user_com((unsigned int)v10, v2, v9, error_no, v10, v11);
LABEL_15:
memory = v3;
result = rpop(a1, v2, v7, v4, v5, v6);
if ( !error_no )
{
if ( memory == 10 )
csp = result;
else
--csp;
}
return result;
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rsi
int v3; // ebx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // rdx
int v8; // er8
__int64 v9; // rdx
__int64 v10; // r8
__int64 v11; // r9

result = func19();
v2 = error_no;
if ( !error_no )
{
if ( (_DWORD)result != 7 )
{
error_no = 16;
return result;
}
result = func19();
v3 = result;
if ( !error_no )
{
result = pop();
v7 = error_no;
if ( !error_no )
{
if ( !(_DWORD)result )
goto LABEL_15;
if ( memory == 9 )
{
result = func8((__int64)f_while);
if ( error_no )
return result;
func9(-1);
}
memory = 10;
result = func13();
if ( !error_no )
{
result = func11(-1);
if ( !error_no )
{
result = func11(v8);
if ( !error_no )
{
result = func15(v3);
v2 = error_no;
if ( !error_no )
{
result = func15(7);
if ( !error_no )
{
a1 = (unsigned int)v10;
func29((unsigned int)v10, v2, v9, error_no, v10, v11);
LABEL_15:
memory = v3;
result = func12(a1, v2, v7, v4, v5, v6);
if ( !error_no )
{
if ( memory == 10 )
csp = result;
else
--csp;
}
return result;
}
}
}
}
}
}
}
}
return result;
}

original_code:
void f_while()
{
  MODE str, keep;
  int val;
  str = spop(); if (error_no != 0) return;;
  if (str != DO) {
    error_no = 16;
    return;
  }
  keep = spop(); if (error_no != 0) return;;
  val = pop(); if (error_no != 0) return;;
  if (val) {
    if (memory == ON) {
      cpush_func(f_while); if (error_no != 0) return;;
      cpush_csp(-1);
    }
    memory = OFF;
    val = rpeek(); if (error_no != 0) return;;
    rpush(-1); if (error_no != 0) return;;
    rpush(val); if (error_no != 0) return;;
    spush(keep); if (error_no != 0) return;;
    spush(str); if (error_no != 0) return;;
    exec_user_com(val);
  }
  memory = keep;
  val = rpop(); if (error_no != 0) return;;
  if (memory == OFF) csp = val;
  else {
    --csp;
  }
}

canonical_original_code:
void f_while()
{
  enum MODE str; enum MODE keep;
  int val;
  str = spop(); if (error_no != 0) return;;
  if (str != DO) {
    error_no = 16;
    return;
  }
  keep = spop(); if (error_no != 0) return;;
  val = pop(); if (error_no != 0) return;;
  if (val) {
    if (memory == ON) {
      cpush_func(f_while); if (error_no != 0) return;;
      cpush_csp(-1);
    }
    memory = OFF;
    val = rpeek(); if (error_no != 0) return;;
    rpush(-1); if (error_no != 0) return;;
    rpush(val); if (error_no != 0) return;;
    spush(keep); if (error_no != 0) return;;
    spush(str); if (error_no != 0) return;;
    exec_user_com(val);
  }
  memory = keep;
  val = rpop(); if (error_no != 0) return;;
  if (memory == OFF) csp = val;
  else {
    --csp;
  }
}