decompiled_code:
void f_loopp()
{
int v0; // eax
int v1; // ebx
int v2; // ebp
int v3; // er12
int v4; // er13
int v5; // eax
int v6; // er12

v0 = spop();
if ( !error_no )
{
if ( v0 != 8 )
{
error_no = 16;
return;
}
v1 = spop();
if ( !error_no )
{
v2 = rpop();
if ( !error_no )
{
v3 = rpop();
if ( !error_no )
{
v4 = rpop();
if ( !error_no )
{
v5 = pop();
if ( !error_no )
{
v6 = v5 + v3;
if ( v4 <= v6 )
goto LABEL_19;
if ( memory == 9 )
{
cpush_func((__int64)f_loopp);
if ( error_no )
return;
cpush_csp(-1);
}
memory = 10;
rpush(-1);
if ( !error_no )
{
rpush(v4);
if ( !error_no )
{
rpush(v6);
if ( !error_no )
{
rpush(v2);
if ( !error_no )
{
spush(v1);
if ( !error_no )
{
spush(8);
if ( !error_no )
{
exec_user_com(v2);
LABEL_19:
memory = v1;
if ( v1 == 10 )
csp = v2;
else
--csp;
return;
}
}
}
}
}
}
}
}
}
}
}
}
}

canonical_decompiled_code:
void func32()
{
int v0; // eax
int v1; // ebx
int v2; // ebp
int v3; // er12
int v4; // er13
int v5; // eax
int v6; // er12

v0 = func19();
if ( !error_no )
{
if ( v0 != 8 )
{
error_no = 16;
return;
}
v1 = func19();
if ( !error_no )
{
v2 = func12();
if ( !error_no )
{
v3 = func12();
if ( !error_no )
{
v4 = func12();
if ( !error_no )
{
v5 = pop();
if ( !error_no )
{
v6 = v5 + v3;
if ( v4 <= v6 )
goto LABEL_19;
if ( memory == 9 )
{
func8((__int64)f_loopp);
if ( error_no )
return;
func9(-1);
}
memory = 10;
func11(-1);
if ( !error_no )
{
func11(v4);
if ( !error_no )
{
func11(v6);
if ( !error_no )
{
func11(v2);
if ( !error_no )
{
func15(v1);
if ( !error_no )
{
func15(8);
if ( !error_no )
{
func29(v2);
LABEL_19:
memory = v1;
if ( v1 == 10 )
csp = v2;
else
--csp;
return;
}
}
}
}
}
}
}
}
}
}
}
}
}

original_code:
void f_loopp()
{
  MODE str, keep;
  int v1, v2, val, ret;
  str = spop(); if (error_no != 0) return;;
  if (str != FOR) {
    error_no = 16;
    return;
  }
  keep = spop(); if (error_no != 0) return;;
  ret = rpop(); if (error_no != 0) return;;
  v1 = rpop(); if (error_no != 0) return;;
  v2 = rpop(); if (error_no != 0) return;;
  val = pop(); if (error_no != 0) return;;
  v1 += val;
  if (v2 > v1) {
    if (memory == ON) {
      cpush_func(f_loopp); if (error_no != 0) return;;
      cpush_csp(-1);
    }
    memory = OFF;
    rpush(-1); if (error_no != 0) return;;
    rpush(v2); if (error_no != 0) return;; rpush(v1); if (error_no != 0) return;; rpush(ret); if (error_no != 0) return;;
    spush(keep); if (error_no != 0) return;;
    spush(str); if (error_no != 0) return;;
    exec_user_com(ret);
  }
  memory = keep;
  if (memory == OFF) csp = ret;
  else {
    --csp;
  }
}

canonical_original_code:
void f_loopp()
{
  enum MODE str; enum MODE keep;
  int v1; int v2; int val; int ret;
  str = spop(); if (error_no != 0) return;;
  if (str != FOR) {
    error_no = 16;
    return;
  }
  keep = spop(); if (error_no != 0) return;;
  ret = rpop(); if (error_no != 0) return;;
  v1 = rpop(); if (error_no != 0) return;;
  v2 = rpop(); if (error_no != 0) return;;
  val = pop(); if (error_no != 0) return;;
  v1 += val;
  if (v2 > v1) {
    if (memory == ON) {
      cpush_func(f_loopp); if (error_no != 0) return;;
      cpush_csp(-1);
    }
    memory = OFF;
    rpush(-1); if (error_no != 0) return;;
    rpush(v2); if (error_no != 0) return;; rpush(v1); if (error_no != 0) return;; rpush(ret); if (error_no != 0) return;;
    spush(keep); if (error_no != 0) return;;
    spush(str); if (error_no != 0) return;;
    exec_user_com(ret);
  }
  memory = keep;
  if (memory == OFF) csp = ret;
  else {
    --csp;
  }
}


repo: monaka/B-Free

decompiled_code:
void __fastcall __noreturn posix_exec_child(const char *a1)
{
printf("posix exec: path = \"%s\"\n", a1);
printf("posix exec -- fail. (%d)\n", 0LL);
while ( 1 )
slp_tsk();
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
printf("posix exec: path = \"%s\"\n", a1);
printf("posix exec -- fail. (%d)\n", 0LL);
while ( 1 )
slp_tsk();
}

original_code:
W
posix_exec_child (B *path)
{
  W err;
  printf ("posix exec: path = \"%s\"\n", path);
  printf ("posix exec -- fail. (%d)\n", err);
  for (;;)
    {
      slp_tsk ();
    }
}

canonical_original_code:
long posix_exec_child(char *path)
{
  long err;
  printf ("posix exec: path = \"%s\"\n", path);
  printf ("posix exec -- fail. (%d)\n", err);
  for (;;)
    {
      slp_tsk ();
    }
}

variable_types:
path
char *

variable_types: err long

return_type: long


decompiled_code:
void __noreturn posix_fork_test_child()
{
printf("I am a child!\n");
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
printf("I am a child!\n");
exit(1);
}

original_code:
W
posix_fork_test_child (void)
{
  printf ("I am a child!\n");
  _exit(1);
}

canonical_original_code:
long posix_fork_test_child()
{
  printf ("I am a child!\n");
  _exit(1);
}


posix

decompiled_code:
__int64 __fastcall posix(__int64 a1, __int64 a2)
{
char *v2; // rdx
__int64 v3; // rbx
int v4; // eax
__int64 v5; // rbx
__int64 v7; // rbx

v2 = *(char **)(a2 + 8);
if ( !memcmp(v2, "/dev/ide", 8uLL) )
{
v3 = v2[8] - 48;
v4 = v2[9] - 48;
if ( v3 >= 0 && v4 > 0 )
{
v5 = (unsigned __int8)v4 | (unsigned __int64)(v3 << 8) | 0x80010000;
printf("mount device = ide/0x%x\n", v5);
return posix_init(v5);
}
LABEL_10:
printf("Cannot mount root filesystem.\n");
return 4294967291LL;
}
if ( !memcmp(v2, "/dev/fd", 7uLL) )
{
v7 = v2[7] - 48;
if ( v7 >= 0 )
{
v5 = (v7 << 8) | 0x80000000LL;
printf("mount device = fd/0x%x\n", v5);
return posix_init(v5);
}
goto LABEL_10;
}
printf("init: Cannot open device.\n");
return 4294967291LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
char *v2; // rdx
__int64 v3; // rbx
int v4; // eax
__int64 v5; // rbx
__int64 v7; // rbx

v2 = *(char **)(a2 + 8);
if ( !memcmp(v2, "/dev/ide", 8uLL) )
{
v3 = v2[8] - 48;
v4 = v2[9] - 48;
if ( v3 >= 0 && v4 > 0 )
{
v5 = (unsigned __int8)v4 | (unsigned __int64)(v3 << 8) | 0x80010000;
printf("mount device = ide/0x%x\n", v5);
return posix_init(v5);
}
LABEL_10:
printf("Cannot mount root filesystem.\n");
return 4294967291LL;
}
if ( !memcmp(v2, "/dev/fd", 7uLL) )
{
v7 = v2[7] - 48;
if ( v7 >= 0 )
{
v5 = (v7 << 8) | 0x80000000LL;
printf("mount device = fd/0x%x\n", v5);
return posix_init(v5);
}
goto LABEL_10;
}
printf("init: Cannot open device.\n");
return 4294967291LL;
}

original_code:
ER
posix (W ac, B **av)
{
  W device;
  B *device_name;
  W drive, partition;
  device_name = av[1];
  if (strncmp (device_name, "/dev/ide", strlen ("/dev/ide")) == 0)
    {
      device = 0x80010000;
      drive = device_name[strlen ("/dev/ide")] - '0';
      partition = device_name[strlen ("/dev/ide") + 1] - '0';
      if ((drive < 0) || (partition <= 0))
 {
   printf ("Cannot mount root filesystem.\n");
   return ((-5));
 }
      device = device | ((drive & 0xff) << 8) | (partition & 0xff);
      printf ("mount device = ide/0x%x\n", device);
    }
  else if (strncmp (device_name, "/dev/fd", strlen ("/dev/fd")) == 0)
    {
      device = 0x80000000;
      drive = device_name[strlen ("/dev/fd")] - '0';
      partition = 0;
      if (drive < 0)
 {
   printf ("Cannot mount root filesystem.\n");
   return ((-5));
 }
      device = device | ((drive & 0xff) << 8);
      printf ("mount device = fd/0x%x\n", device);
    }
  else
    {
      printf ("init: Cannot open device.\n");
      return ((-5));
    }
  return (posix_init (device));
}

canonical_original_code:
int posix(long ac, char **av)
{
  long device;
  char *device_name;
  long drive; long partition;
  device_name = av[1];
  if (strncmp (device_name, "/dev/ide", strlen ("/dev/ide")) == 0)
    {
      device = 0x80010000;
      drive = device_name[strlen ("/dev/ide")] - '0';
      partition = device_name[strlen ("/dev/ide") + 1] - '0';
      if ((drive < 0) || (partition <= 0))
 {
   printf ("Cannot mount root filesystem.\n");
   return ((-5));
 }
      device = device | ((drive & 0xff) << 8) | (partition & 0xff);
      printf ("mount device = ide/0x%x\n", device);
    }
  else if (strncmp (device_name, "/dev/fd", strlen ("/dev/fd")) == 0)
    {
      device = 0x80000000;
      drive = device_name[strlen ("/dev/fd")] - '0';
      partition = 0;
      if (drive < 0)
 {
   printf ("Cannot mount root filesystem.\n");
   return ((-5));
 }
      device = device | ((drive & 0xff) << 8);
      printf ("mount device = fd/0x%x\n", device);
    }
  else
    {
      printf ("init: Cannot open device.\n");
      return ((-5));
    }
  return (posix_init (device));
}

variable_types: ac long

variable_types:
av
char **

variable_types: device long

variable_types: drive long

variable_types: partition long

return_type: int


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

v0 = noaction();
printf("posix noaction: %d\n", v0);
return 0LL;
}

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

v0 = noaction();
printf("posix noaction: %d\n", v0);
return 0LL;
}

original_code:
ER
posix_noaction (void)
{
  printf ("posix noaction: %d\n", noaction ());
  return (0);
}

canonical_original_code:
int posix_noaction()
{
  printf ("posix noaction: %d\n", noaction ());
  return (0);
}


decompiled_code:
__int64 __fastcall posix_exec_test(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = posix_fork(posix_exec_child, *(_QWORD *)(a2 + 8));
printf("[posix_exec_tset] err = %d\n", v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = posix_fork(posix_exec_child, *(_QWORD *)(a2 + 8));
printf("[posix_exec_tset] err = %d\n", v2);
return 0LL;
}

original_code:
ER
posix_exec_test (W ac, B **av)
{
  W err;
  err = posix_fork (posix_exec_child, av[1]);
  printf ("[posix_exec_tset] err = %d\n", err);
  return (0);
}

canonical_original_code:
int posix_exec_test(long ac, char **av)
{
  long err;
  err = posix_fork (posix_exec_child, av[1]);
  printf ("[posix_exec_tset] err = %d\n", err);
  return (0);
}


decompiled_code:
__int64 posix_fork_test()
{
int v0; // eax

printf("child start addr %x\n", posix_fork_test_child);
v0 = posix_fork(posix_fork_test_child, 0LL);
printf("err = %d\n", v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax

printf("child start addr %x\n", posix_fork_test_child);
v0 = posix_fork(posix_fork_test_child, 0LL);
printf("err = %d\n", v0);
return 0LL;
}

original_code:
ER
posix_fork_test (void)
{
  W err;
  printf("child start addr %x\n", posix_fork_test_child);
  err = posix_fork (posix_fork_test_child, (0));
  printf ("err = %d\n", err);
  return (0);
}

canonical_original_code:
int posix_fork_test()
{
  long err;
  printf("child start addr %x\n", posix_fork_test_child);
  err = posix_fork (posix_fork_test_child, (0));
  printf ("err = %d\n", err);
  return (0);
}


cexec

decompiled_code:
__int64 cexec()
{
unsigned int v0; // ebx
unsigned int v2; // eax
unsigned int v3; // eax
char v4[256]; // [rsp+0h] [rbp-118h] BYREF
__int64 v5; // [rsp+100h] [rbp-18h] BYREF
int stat_loc[3]; // [rsp+10Ch] [rbp-Ch] BYREF

v0 = MitnStack_Pop(1LL, &v5);
if ( !v0 )
{
v0 = MitnCell_ToString(v4, v5, 255LL);
if ( !v0 )
{
v2 = fork();
stat_loc[0] = v2;
if ( !v2 )
{
execve(v4, 0LL, 0LL);
exit(1);
}
if ( v2 == -1 )
{
printf("fork error\n");
v0 = stat_loc[0];
}
else
{
printf("waiting pid=%d ...\n", v2);
v3 = waitpid(-1, stat_loc, 0);
printf("child process exited pid=%d stat=%d\n", v3, (unsigned int)stat_loc[0]);
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // ebx
unsigned int v2; // eax
unsigned int v3; // eax
char v4[256]; // [rsp+0h] [rbp-118h] BYREF
__int64 v5; // [rsp+100h] [rbp-18h] BYREF
int stat_loc[3]; // [rsp+10Ch] [rbp-Ch] BYREF

v0 = MitnStack_Pop(1LL, &v5);
if ( !v0 )
{
v0 = MitnCell_ToString(v4, v5, 255LL);
if ( !v0 )
{
v2 = fork();
stat_loc[0] = v2;
if ( !v2 )
{
execve(v4, 0LL, 0LL);
exit(1);
}
if ( v2 == -1 )
{
printf("fork error\n");
v0 = stat_loc[0];
}
else
{
printf("waiting pid=%d ...\n", v2);
v3 = waitpid(-1, stat_loc, 0);
printf("child process exited pid=%d stat=%d\n", v3, (unsigned int)stat_loc[0]);
}
}
}
return v0;
}

original_code:
ER cexec(void)
{
  int pid, res;
  Cell *c;
  B fname[255];
  ER result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_ToString(fname, c, 255);
  if ((result) != (0)) { return (result); };
  if ((res = fork()) == 0) {
    execve(fname, (0), (0));
    _exit(1);
  }
  else if (res == -1) {
    printf("fork error\n");
    return(res);
  }
  else {
    printf("waiting pid=%d ...\n", res);
    pid = waitpid(-1, &res, 0);
    printf("child process exited pid=%d stat=%d\n", pid, res);
    return((0));
  }
}

canonical_original_code:
int cexec()
{
  int pid; int res;
  struct _cell *c;
  char fname[255];
  int result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_ToString(fname, c, 255);
  if ((result) != (0)) { return (result); };
  if ((res = fork()) == 0) {
    execve(fname, (0), (0));
    _exit(1);
  }
  else if (res == -1) {
    printf("fork error\n");
    return(res);
  }
  else {
    printf("waiting pid=%d ...\n", res);
    pid = waitpid(-1, &res, 0);
    printf("child process exited pid=%d stat=%d\n", pid, res);
    return((0));
  }
}

variable_types: pid int

variable_types: res int

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

variable_types:
fname
char [255]

variable_types: result int


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

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

original_code:
ER
init_link ()
{
  return ((0));
}

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


decompiled_code:
void attach_driver()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
ER
attach_driver (B *driver_name)
{
}

canonical_original_code:
int attach_driver(char *driver_name)
{
}


decompiled_code:
void detach_driver()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
ER
detach_driver (B *driver_name)
{
}

canonical_original_code:
int detach_driver(char *driver_name)
{
}


decompiled_code:
void receive_packet()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
ER
receive_packet (W length, B *packet)
{
}

canonical_original_code:
int receive_packet(long length, char *packet)
{
}

variable_types: length long

variable_types:
packet
char *


decompiled_code:
void send_packet()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
ER
send_packet (W length, B *packet)
{
}

canonical_original_code:
int send_packet(long length, char *packet)
{
}


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

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

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

variable_types: caller int

variable_types:
packet
struct DDEV_OPN_REQ { long dd; } *


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

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

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

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


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

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

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

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


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

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

canonical_original_code:
int write_gname(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 control_gname()
{
return 4294967279LL;
}

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

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

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


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

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

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 ("gname: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.gname", 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 ("gname: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.gname", recvport);
  if (error != (0))
    {
    }
}

variable_types: i int

variable_types: error int

return_type: void


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()
{
probe(&dev_table);
init_driver();
printf("registed gname driver.\n");
main_loop();
}

canonical_decompiled_code:
void __noreturn func2()
{
probe(&dev_table);
func0();
printf("registed gname driver.\n");
func1();
}

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

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


decompiled_code:
void process_request()
{
;
}

original_code:
ER
process_request (DDEV_REQ *req)
{
  switch (req->header.msgtyp)
    {
    case DEV_OPN:
      open_gname (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_gname (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_gname (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_gname (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_gname (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_gname (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_gname (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_gname (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_gname (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_gname (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 __fastcall cre_tsk(unsigned int a1, __int64 a2)
{
return call_syscall(1LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return call_syscall(1LL, a1, a2);
}

original_code:
ER
cre_tsk (ID tskid, T_CTSK *pk_ctsk)
{
  return call_syscall ((1), tskid, pk_ctsk);
}

canonical_original_code:
int cre_tsk(int tskid, struct t_ctsk *pk_ctsk)
{
  return call_syscall ((1), tskid, pk_ctsk);
}

variable_types: tskid int

variable_types: struct t_ctsk { void *exinf; unsigned int tskatr; void (*startaddr)(); int itskpri; int stksz; struct I386_DIRECTORY_ENTRY { unsigned long present; unsigned long read_write; unsigned long u_and_s; unsigned long zero2; unsigned long access; unsigned long dirty; unsigned long zero1; unsigned long user; unsigned long frame_addr; } **addrmap; enum TSKMODE { kernel_mode=0, user_mode=1 } mode; } *

user_defined_types: struct t_ctsk { void *exinf; unsigned int tskatr; void (*startaddr)(); int itskpri; int stksz; struct I386_DIRECTORY_ENTRY **addrmap; enum TSKMODE mode; }


decompiled_code:
__int64 __fastcall vcre_tsk(__int64 a1, _DWORD *a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = 21LL;
while ( 1 )
{
result = cre_tsk(v2, a1);
if ( !(_DWORD)result )
break;
if ( ++v2 == 129 )
return 4294967286LL;
}
*a2 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2)
{
__int64 v2; // rbx
__int64 result; // rax

v2 = 21LL;
while ( 1 )
{
result = func0(v2, a1);
if ( !(_DWORD)result )
break;
if ( ++v2 == 129 )
return 4294967286LL;
}
*a2 = v2;
return result;
}

original_code:
ER
vcre_tsk (T_CTSK *pk_ctsk, ID *rid)
{
  W i;
  ER err;
  for (i = (21); i <= (128); i++)
    {
      err = cre_tsk (i, pk_ctsk);
      if (err == (0))
 {
   *rid = i;
   return ((0));
 }
    }
  return ((-10));
}

canonical_original_code:
int vcre_tsk(struct t_ctsk *pk_ctsk, int *rid)
{
  long i;
  int err;
  for (i = (21); i <= (128); i++)
    {
      err = cre_tsk (i, pk_ctsk);
      if (err == (0))
 {
   *rid = i;
   return ((0));
 }
    }
  return ((-10));
}

variable_types:
rid
int *

variable_types: i long

variable_types: err int

user_defined_types: enum TSKMODE { kernel_mode=0, user_mode=1 }

user_defined_types: struct I386_DIRECTORY_ENTRY { unsigned long present; unsigned long read_write; unsigned long u_and_s; unsigned long zero2; unsigned long access; unsigned long dirty; unsigned long zero1; unsigned long user; unsigned long frame_addr; }


decompiled_code:
__int64 __fastcall ext_tsk(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(4LL, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(4LL, a2, a3);
}

original_code:
void
ext_tsk (void)
{
  call_syscall ((4));
}

canonical_original_code:
void ext_tsk()
{
  call_syscall ((4));
}


decompiled_code:
__int64 __fastcall exd_tsk(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(5LL, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(5LL, a2, a3);
}

original_code:
void
exd_tsk (void)
{
  call_syscall ((5));
}

canonical_original_code:
void exd_tsk()
{
  call_syscall ((5));
}


decompiled_code:
__int64 __fastcall can_wup(__int64 a1, unsigned int a2)
{
return call_syscall(20LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
return call_syscall(20LL, a1, a2);
}

original_code:
ER
can_wup (INT *p_wupcnt, ID taskid)
{
  return call_syscall ((20), p_wupcnt, taskid);
}

canonical_original_code:
int can_wup(int *p_wupcnt, int taskid)
{
  return call_syscall ((20), p_wupcnt, taskid);
}

variable_types: taskid int


decompiled_code:
__int64 __fastcall chg_pri(unsigned int a1, unsigned int a2)
{
return call_syscall(9LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned int a2)
{
return call_syscall(9LL, a1, a2);
}

original_code:
ER
chg_pri (ID tskid, PRI tskpri)
{
  return call_syscall ((9), tskid, tskpri);
}

canonical_original_code:
int chg_pri(int tskid, int tskpri)
{
  return call_syscall ((9), tskid, tskpri);
}

variable_types: tskpri int


decompiled_code:
__int64 __fastcall dis_dsp(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(7LL, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(7LL, a2, a3);
}

original_code:
ER
dis_dsp (void)
{
  return call_syscall ((7));
}

canonical_original_code:
int dis_dsp()
{
  return call_syscall ((7));
}


decompiled_code:
__int64 __fastcall ena_dsp(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(8LL, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(8LL, a2, a3);
}

original_code:
ER
ena_dsp (void)
{
  return call_syscall ((8));
}

canonical_original_code:
int ena_dsp()
{
  return call_syscall ((8));
}


decompiled_code:
__int64 __fastcall frsm_tsk(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(16LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(16LL, a1, a3);
}

original_code:
ER
frsm_tsk (ID taskid)
{
  return call_syscall ((16), taskid);
}

canonical_original_code:
int frsm_tsk(int taskid)
{
  return call_syscall ((16), taskid);
}


decompiled_code:
__int64 __fastcall get_tid(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(12LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(12LL, a1, a3);
}

original_code:
ER
get_tid (ID *rid)
{
  return call_syscall ((12), rid);
}

canonical_original_code:
int get_tid(int *rid)
{
  return call_syscall ((12), rid);
}


decompiled_code:
__int64 __fastcall ref_tsk(__int64 a1, unsigned int a2)
{
return call_syscall(13LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
return call_syscall(13LL, a1, a2);
}

original_code:
ER
ref_tsk (T_RTSK *stat, ID taskid)
{
  return call_syscall ((13), stat, taskid);
}

canonical_original_code:
int ref_tsk(struct t_rtsk *stat, int taskid)
{
  return call_syscall ((13), stat, taskid);
}

variable_types: struct t_rtsk { void *exinf; int tskpri; unsigned int tskstat; long total_time; } *


decompiled_code:
__int64 __fastcall rot_rdq(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(10LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(10LL, a1, a3);
}

original_code:
ER
rot_rdq (PRI tskpri)
{
  return call_syscall ((10), tskpri);
}

canonical_original_code:
int rot_rdq(int tskpri)
{
  return call_syscall ((10), tskpri);
}


decompiled_code:
__int64 __fastcall rsm_tsk(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(15LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(15LL, a1, a3);
}

original_code:
ER
rsm_tsk (ID taskid)
{
  return call_syscall ((15), taskid);
}

canonical_original_code:
int rsm_tsk(int taskid)
{
  return call_syscall ((15), taskid);
}


decompiled_code:
__int64 __fastcall slp_tsk(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(17LL, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3)
{
return call_syscall(17LL, a2, a3);
}

original_code:
ER
slp_tsk (void)
{
  return call_syscall ((17));
}

canonical_original_code:
int slp_tsk()
{
  return call_syscall ((17));
}


decompiled_code:
__int64 __fastcall sta_tsk(unsigned int a1, unsigned int a2)
{
return call_syscall(3LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, unsigned int a2)
{
return call_syscall(3LL, a1, a2);
}

original_code:
ER
sta_tsk (ID taskid, INT stacd)
{
  return call_syscall ((3), taskid, stacd);
}

canonical_original_code:
int sta_tsk(int taskid, int stacd)
{
  return call_syscall ((3), taskid, stacd);
}

variable_types: stacd int


decompiled_code:
__int64 __fastcall sus_tsk(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(14LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(14LL, a1, a3);
}

original_code:
ER
sus_tsk (ID taskid)
{
  return call_syscall ((14), taskid);
}

canonical_original_code:
int sus_tsk(int taskid)
{
  return call_syscall ((14), taskid);
}


decompiled_code:
__int64 __fastcall ter_tsk(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(6LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(6LL, a1, a3);
}

original_code:
ER
ter_tsk (ID tskid)
{
  return call_syscall ((6), tskid);
}

canonical_original_code:
int ter_tsk(int tskid)
{
  return call_syscall ((6), tskid);
}


decompiled_code:
__int64 __fastcall wup_tsk(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(19LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func18(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(19LL, a1, a3);
}

original_code:
ER
wup_tsk (ID taskid)
{
  return call_syscall ((19), taskid);
}

canonical_original_code:
int wup_tsk(int taskid)
{
  return call_syscall ((19), taskid);
}


decompiled_code:
__int64 __fastcall del_tsk(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(2LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func19(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(2LL, a1, a3);
}

original_code:
ER
del_tsk (ID tskid)
{
  return call_syscall ((2), tskid);
}

canonical_original_code:
int del_tsk(int tskid)
{
  return call_syscall ((2), tskid);
}


decompiled_code:
void f_forget()
{
if ( eval_mode || memory == 9 )
error_no = 12;
else
eval_mode = 4;
}

canonical_decompiled_code:
void func0()
{
if ( eval_mode || memory == 9 )
error_no = 12;
else
eval_mode = 4;
}

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


decompiled_code:
void f_def()
{
if ( eval_mode || memory == 9 )
error_no = 12;
else
eval_mode = 5;
}

canonical_decompiled_code:
void func1()
{
if ( eval_mode || memory == 9 )
error_no = 12;
else
eval_mode = 5;
}

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


decompiled_code:
__int64 init_hash()
{
unsigned __int64 v0; // rax
__int64 v1; // rbp
int i; // ebx
__int64 result; // rax

v0 = (unsigned int)((_DWORD)hash_tbl + 4);
do
{
*(_DWORD *)v0 = -1;
v0 += 8LL;
}
while ( v0 != (_DWORD)hash_tbl + 92 );
v1 = (unsigned int)((_DWORD)&builtin_command + 2184);
for ( i = 91; i != -1; --i )
{
result = (int)hash(*(_BYTE **)v1);
*(_DWORD *)(v1 + 16) = hash_tbl[2 * (int)result + 1];
hash_tbl[2 * (int)result + 1] = i;
v1 -= 24LL;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned __int64 v0; // rax
__int64 v1; // rbp
int i; // ebx
__int64 result; // rax

v0 = (unsigned int)((_DWORD)hash_tbl + 4);
do
{
*(_DWORD *)v0 = -1;
v0 += 8LL;
}
while ( v0 != (_DWORD)hash_tbl + 92 );
v1 = (unsigned int)((_DWORD)&builtin_command + 2184);
for ( i = 91; i != -1; --i )
{
result = (int)func4(*(_BYTE **)v1);
*(_DWORD *)(v1 + 16) = hash_tbl[2 * (int)result + 1];
hash_tbl[2 * (int)result + 1] = i;
v1 -= 24LL;
}
return result;
}

original_code:
void init_hash()
{
  int i, cm, h;
  for(i = 0; i < 11; ++i) {
    hash_tbl[i].next = -1;
  }
  cm = sizeof(builtin_command)/sizeof(struct bc);
  for(i = cm-1; i >= 0; --i) {
    h = hash(builtin_command[i].name);
    builtin_command[i].next = hash_tbl[h].next;
    hash_tbl[h].next = i;
  }
}

canonical_original_code:
void init_hash()
{
  int i; int cm; int h;
  for(i = 0; i < 11; ++i) {
    hash_tbl[i].next = -1;
  }
  cm = sizeof(builtin_command)/sizeof(struct bc);
  for(i = cm-1; i >= 0; --i) {
    h = hash(builtin_command[i].name);
    builtin_command[i].next = hash_tbl[h].next;
    hash_tbl[h].next = i;
  }
}

variable_types: cm int

variable_types: h int

user_defined_types: struct bc { char *name; void (*func)(); int next; }


decompiled_code:
int f_help()
{
const char **v0; // rbp
int i; // ebx
int v2; // ebp
unsigned int j; // ebx
const char *v4; // rax

printf("Builtin Command:");
v0 = (const char **)&builtin_command;
for ( i = 0; i != 92; ++i )
{
if ( (i & 7) == 0 )
putchar(10);
printf("%s ", *v0);
v0 += 3;
}
putchar(10);
v2 = query_dp();
printf("User Command:");
if ( v2 > 0 )
{
for ( j = 0; j != v2; ++j )
{
if ( (j & 7) == 0 )
putchar(10);
v4 = (const char *)query_dict_name(j);
printf("%s ", v4);
}
}
return putchar(10);
}

canonical_decompiled_code:
int func2()
{
const char **v0; // rbp
int i; // ebx
int v2; // ebp
unsigned int j; // ebx
const char *v4; // rax

printf("Builtin Command:");
v0 = (const char **)&builtin_command;
for ( i = 0; i != 92; ++i )
{
if ( (i & 7) == 0 )
putchar(10);
printf("%s ", *v0);
v0 += 3;
}
putchar(10);
v2 = query_dp();
printf("User Command:");
if ( v2 > 0 )
{
for ( j = 0; j != v2; ++j )
{
if ( (j & 7) == 0 )
putchar(10);
v4 = (const char *)query_dict_name(j);
printf("%s ", v4);
}
}
return putchar(10);
}

original_code:
void f_help()
{
  int i, cm;
  cm = sizeof(builtin_command)/sizeof(struct bc);
  printf("Builtin Command:");
  for(i = 0; i < cm; ++i) {
    if (!(i%8)) printf("\n");
    printf("%s ", builtin_command[i].name);
  }
  printf("\n");
  cm = query_dp();
  printf("User Command:");
  for(i = 0; i < cm; ++i) {
    if (!(i%8)) printf("\n");
    printf("%s ", query_dict_name(i));
  }
  printf("\n");
}

canonical_original_code:
void f_help()
{
  int i; int cm;
  cm = sizeof(builtin_command)/sizeof(struct bc);
  printf("Builtin Command:");
  for(i = 0; i < cm; ++i) {
    if (!(i%8)) printf("\n");
    printf("%s ", builtin_command[i].name);
  }
  printf("\n");
  cm = query_dp();
  printf("User Command:");
  for(i = 0; i < cm; ++i) {
    if (!(i%8)) printf("\n");
    printf("%s ", query_dict_name(i));
  }
  printf("\n");
}


ttyname

decompiled_code:
void ttyname()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
ttyname (char *name)
{
  return (call_lowlib (78, strlen (name), name));
}

canonical_original_code:
int ttyname(char *name)
{
  return (call_lowlib (78, strlen (name), name));
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall get_flag(int a1, int a2)
{
unsigned int v2; // ebx
_DWORD v4[6]; // [rsp+0h] [rbp-18h] BYREF

v4[2] = a1;
v4[3] = a2;
v2 = 1;
while ( (unsigned int)cre_flg(v2, v4) )
{
if ( ++v2 == 257 )
return 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
unsigned int v2; // ebx
_DWORD v4[6]; // [rsp+0h] [rbp-18h] BYREF

v4[2] = a1;
v4[3] = a2;
v2 = 1;
while ( (unsigned int)cre_flg(v2, v4) )
{
if ( ++v2 == 257 )
return 0;
}
return v2;
}

original_code:
ID
get_flag (ATR atr, UINT pattern)
{
  ID flag;
  W errno;
  T_CFLG t_cflg;
  t_cflg.flgatr = atr;
  t_cflg.iflgptn = pattern;
  for (flag = (1);
       flag <= (256);
       flag++)
    {
      errno = cre_flg (flag, &t_cflg);
      if (errno == (0))
 {
   return (flag);
 }
    }
  return (0);
}

canonical_original_code:
int get_flag(unsigned int atr, unsigned int pattern)
{
  int flag;
  long errno;
  struct t_cflg t_cflg;
  t_cflg.flgatr = atr;
  t_cflg.iflgptn = pattern;
  for (flag = (1);
       flag <= (256);
       flag++)
    {
      errno = cre_flg (flag, &t_cflg);
      if (errno == (0))
 {
   return (flag);
 }
    }
  return (0);
}

variable_types:
atr
unsigned int

variable_types:
pattern
unsigned int

variable_types: flag int

variable_types: errno long

variable_types: struct t_cflg { void *exinf; unsigned int flgatr; unsigned int iflgptn; }


decompiled_code:
__int64 f_tasklist()
{
return misc(4294967290LL, 0LL, 0LL);
}

original_code:
void f_tasklist (void)
{
  misc (-6, 0, (0));
}

canonical_original_code:
void f_tasklist()
{
  misc (-6, 0, (0));
}


decompiled_code:
__int64 f_pmemstat()
{
return misc(4294967289LL, 0LL, 0LL);
}

original_code:
void f_pmemstat(void)
{
  misc (-7, 0, (0));
}

canonical_original_code:
void f_pmemstat()
{
  misc (-7, 0, (0));
}


decompiled_code:
__int64 f_prtflist()
{
return misc(4LL, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 func2()
{
return misc(4LL, 0LL, 0LL);
}

original_code:
void f_prtflist(void)
{
  misc (4, 0, (0));
}

canonical_original_code:
void f_prtflist()
{
  misc (4, 0, (0));
}


decompiled_code:
__int64 __fastcall bcd_to_bin(int a1)
{
return (a1 & 0xF) + 10 * (unsigned int)((unsigned __int64)a1 >> 4);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (a1 & 0xF) + 10 * (unsigned int)((unsigned __int64)a1 >> 4);
}

original_code:
static int
bcd_to_bin (int bcd)
{
  UWORD32 tmp;
  tmp = ((UWORD32)bcd) >> 4;
  return ((tmp * 10) + (bcd & 0xf));
}

canonical_original_code:
static int bcd_to_bin(int bcd)
{
  unsigned long tmp;
  tmp = ((unsigned long)bcd) >> 4;
  return ((tmp * 10) + (bcd & 0xf));
}

variable_types: bcd int

variable_types:
tmp
unsigned long


decompiled_code:
void init_clock()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void
init_clock (void)
{
}

canonical_original_code:
void init_clock()
{
}


decompiled_code:
__int64 __fastcall read_clock(_DWORD *a1)
{
char *v1; // r12
int i; // ebx
unsigned __int8 v3; // bl
unsigned __int8 v4; // r12
unsigned __int8 v5; // bp
unsigned __int8 v7; // [rsp+Ah] [rbp-2Eh] BYREF
unsigned __int8 v8; // [rsp+Bh] [rbp-2Dh]
unsigned __int8 v9; // [rsp+Ch] [rbp-2Ch]
unsigned __int8 v10; // [rsp+Dh] [rbp-2Bh]
unsigned __int8 v11; // [rsp+Fh] [rbp-29h]
char v12; // [rsp+10h] [rbp-28h] BYREF

outb(0x20u, 3u);
outb(0x20u, 0xBu);
outb(0x20u, 3u);
outb(0x20u, 1u);
outb(0x20u, 9u);
outb(0x20u, 1u);
v1 = (char *)&v7;
do
{
*v1 = 0;
for ( i = 0; i != 8; ++i )
{
*v1 |= (inb(0x33u) & 1) << i;
outb(0x20u, 0x11u);
outb(0x20u, 1u);
}
++v1;
}
while ( v1 != &v12 );
*a1 = bcd_to_bin(v11);
a1[1] = 0;
a1[2] = bcd_to_bin(v10);
a1[3] = 0;
v3 = v9;
a1[4] = bcd_to_bin(v9);
v4 = v8;
a1[5] = bcd_to_bin(v8);
v5 = v7;
a1[6] = bcd_to_bin(v7);
boot_printf("%d%d:%d%d:%d%d\n", v3 >> 4, v3 & 0xF, v4 >> 4, v4 & 0xF, v5 >> 4, v5 & 0xF);
return 1LL;
}

original_code:
int
read_clock (struct date_t *date)
{
  BYTE data[6];
  int i,j;
  int tmp;
  outb (0x20, 0x03);
  busywait (2);
  outb (0x20, 0x0b);
  busywait (4);
  outb (0x20, 0x03);
  busywait (20);
  outb (0x20, 0x01);
  busywait (2);
  outb (0x20, 0x09);
  busywait (4);
  outb (0x20, 0x01);
  busywait (40);
  for (i = 0; i < 6; i++)
    {
      data[i] = 0;
      for (j = 0; j < 8; j++)
 {
   tmp = 0;
   tmp = inb (0x33);
   data[i] |= ((tmp & 0x1) << j);
   outb (0x20, 0x11);
   busywait (2);
   outb (0x20, 0x01);
   busywait (2);
 }
    }
  date->year = bcd_to_bin (data[5]);
  date->month = 0;
  date->day = bcd_to_bin (data[3]);
  date->week = 0;
  date->hour = bcd_to_bin (data[2]);
  date->minute = bcd_to_bin (data[1]);
  date->second = bcd_to_bin (data[0]);
  boot_printf ("%d%d:%d%d:%d%d\n",
   (data[2] >> 4) & 0xf, data[2] & 0xf,
   (data[1] >> 4) & 0xf, data[1] & 0xf,
   (data[0] >> 4) & 0xf, data[0] & 0xf);
  return (1);
}

canonical_original_code:
int read_clock(struct date_t *date)
{
  unsigned char data[6];
  int i; int j;
  int tmp;
  outb (0x20, 0x03);
  busywait (2);
  outb (0x20, 0x0b);
  busywait (4);
  outb (0x20, 0x03);
  busywait (20);
  outb (0x20, 0x01);
  busywait (2);
  outb (0x20, 0x09);
  busywait (4);
  outb (0x20, 0x01);
  busywait (40);
  for (i = 0; i < 6; i++)
    {
      data[i] = 0;
      for (j = 0; j < 8; j++)
 {
   tmp = 0;
   tmp = inb (0x33);
   data[i] |= ((tmp & 0x1) << j);
   outb (0x20, 0x11);
   busywait (2);
   outb (0x20, 0x01);
   busywait (2);
 }
    }
  date->year = bcd_to_bin (data[5]);
  date->month = 0;
  date->day = bcd_to_bin (data[3]);
  date->week = 0;
  date->hour = bcd_to_bin (data[2]);
  date->minute = bcd_to_bin (data[1]);
  date->second = bcd_to_bin (data[0]);
  boot_printf ("%d%d:%d%d:%d%d\n",
   (data[2] >> 4) & 0xf, data[2] & 0xf,
   (data[1] >> 4) & 0xf, data[1] & 0xf,
   (data[0] >> 4) & 0xf, data[0] & 0xf);
  return (1);
}

variable_types: struct date_t { int year; int month; int day; int week; int hour; int minute; int second; } *

variable_types:
data
unsigned char [6]

variable_types: i int

variable_types: j int

variable_types: tmp int


busywait

decompiled_code:
void __fastcall busywait(int a1)
{
int v1; // edx
int v2; // eax

v1 = 0;
if ( a1 > 0 )
{
do
{
v2 = 100;
do
--v2;
while ( v2 );
++v1;
}
while ( a1 != v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
int v1; // edx
int v2; // eax

v1 = 0;
if ( a1 > 0 )
{
do
{
v2 = 100;
do
--v2;
while ( v2 );
++v1;
}
while ( a1 != v1 );
}
}

original_code:
void
busywait(int x)
{
  int i,j;
  int tmp;
  for (i = 0; i < x; i++)
     for (j = 0; j < 100; j++)
       tmp = j;
}

canonical_original_code:
void busywait(int x)
{
  int i; int j;
  int tmp;
  for (i = 0; i < x; i++)
     for (j = 0; j < 100; j++)
       tmp = j;
}

variable_types: x int


tolower

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

result = a1 + 32;
if ( (unsigned __int8)(a1 - 65) >= 0x1Au )
result = a1;
return result;
}

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

result = a1 + 32;
if ( (unsigned __int8)(a1 - 65) >= 0x1Au )
result = a1;
return result;
}

original_code:
char
tolower (char c)
{
  if(c>='A'){
    if(c<='Z'){
      return c-('A'-'a');
    }
  }
  return c;
}

canonical_original_code:
char tolower(char c)
{
  if(c>='A'){
    if(c<='Z'){
      return c-('A'-'a');
    }
  }
  return c;
}

variable_types: c char

return_type: char


strcmp

decompiled_code:
__int64 __fastcall strcmp(char *a1, _BYTE *a2)
{
char i; // al

for ( i = *a1; *a1; i = *a1 )
{
if ( *a2 != i )
break;
++a1;
++a2;
}
return (char)*a2 - i;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, _BYTE *a2)
{
char i; // al

for ( i = *a1; *a1; i = *a1 )
{
if ( *a2 != i )
break;
++a1;
++a2;
}
return (char)*a2 - i;
}


strncmp

original_code:
W
strncmp (B *s1, B *s2, W length)
{
  W counter;
  for (counter = 0;
       (*s1 == *s2) && (counter < length) && (*s1 != '\0');
       counter++)
    {
      s1++;
      s2++;
    }
  if (counter >= length)
    return (0);
  return (*s2 - *s1);
}

canonical_original_code:
long strncmp(char *s1, char *s2, long length)
{
  long counter;
  for (counter = 0;
       (*s1 == *s2) && (counter < length) && (*s1 != '\0');
       counter++)
    {
      s1++;
      s2++;
    }
  if (counter >= length)
    return (0);
  return (*s2 - *s1);
}

variable_types: length long

variable_types: counter long


strlen

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

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

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

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int
strlen (char *s)
{
  int count;
  for (count = 0; s[count]; count++)
    ;
  return (count);
}

canonical_original_code:
int strlen(char *s)
{
  int count;
  for (count = 0; s[count]; count++)
    ;
  return (count);
}

variable_types:
s
char *

variable_types: count int


toupper

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

result = a1 - 32;
if ( (unsigned __int8)(a1 - 97) >= 0x1Au )
result = a1;
return result;
}

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

result = a1 - 32;
if ( (unsigned __int8)(a1 - 97) >= 0x1Au )
result = a1;
return result;
}

original_code:
char
toupper(char c)
{
  if(c>='a'){
    if(c<='z'){
      return c-('a'-'A');
    }
  }
  return c;
}


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

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

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

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

variable_types:
argp
void *

variable_types:
args
struct a {  } *


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

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

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

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


decompiled_code:
void __fastcall fix_path(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
*v1++ = toupper(v2);
v2 = *v1;
}
while ( *v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
*v1++ = toupper(v2);
v2 = *v1;
}
while ( *v1 );
}
}

original_code:
void
fix_path (char *path)
{
  char *p;
  for (p = path; *p; p++)
    {
      *p = toupper (*p);
    }
}

canonical_original_code:
void fix_path(char *path)
{
  char *p;
  for (p = path; *p; p++)
    {
      *p = toupper (*p);
    }
}

variable_types:
path
char *

variable_types:
p
char *


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

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

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

return_type: struct dirent { unsigned int d_ino; unsigned long d_mode; unsigned char d_name[14]; } *


decompiled_code:
__int64 psys_getuid()
{
__int64 v1; // [rsp+0h] [rbp-C8h] BYREF
__int64 v2; // [rsp+18h] [rbp-B0h]
unsigned int v3; // [rsp+20h] [rbp-A8h]
char v4[136]; // [rsp+40h] [rbp-88h] BYREF

if ( (unsigned int)make_connection(19LL, v4, &v1) || !v2 )
return v3;
MEMORY[0x7FFF0028] = v2;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v1; // [rsp+0h] [rbp-C8h] BYREF
__int64 v2; // [rsp+18h] [rbp-B0h]
unsigned int v3; // [rsp+20h] [rbp-A8h]
char v4[136]; // [rsp+40h] [rbp-88h] BYREF

if ( (unsigned int)make_connection(19LL, v4, &v1) || !v2 )
return v3;
MEMORY[0x7FFF0028] = v2;
return 0xFFFFFFFFLL;
}

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

canonical_original_code:
unsigned short psys_getuid(void *argp)
{
  struct a *args = (struct a *)argp;
  errno = 26;
  return ((0));
}

return_type: unsigned short


decompiled_code:
__int64 lowlib_exit()
{
return exd_tsk();
}

canonical_decompiled_code:
__int64 func0()
{
return exd_tsk();
}

original_code:
ER
lowlib_exit ()
{
  exd_tsk ();
}

canonical_original_code:
int lowlib_exit()
{
  exd_tsk ();
}


decompiled_code:
__int64 __fastcall lowlib_init(_QWORD *a1)
{
dbg_printf("POSIX lowlib: now loading...\n");
a1[6] = 65LL;
a1[7] = lowlib_start;
a1[8] = lowlib_exit;
a1[9] = lowlib_syscall;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
dbg_printf("POSIX lowlib: now loading...\n");
a1[6] = 65LL;
a1[7] = lowlib_start;
a1[8] = lowlib_exit;
a1[9] = lowlib_syscall;
return 0LL;
}

original_code:
ER
lowlib_init (struct lowlib_info *lowlib)
{
  ER error;
  dbg_printf ("POSIX lowlib: now loading...\n");
  lowlib->intr = 65;
  lowlib->start = lowlib_start;
  lowlib->quit = lowlib_exit;
  lowlib->intr_func = lowlib_syscall;
  return ((0));
}

canonical_original_code:
int lowlib_init(struct lowlib_info *lowlib)
{
  int error;
  dbg_printf ("POSIX lowlib: now loading...\n");
  lowlib->intr = 65;
  lowlib->start = lowlib_start;
  lowlib->quit = lowlib_exit;
  lowlib->intr_func = lowlib_syscall;
  return ((0));
}

variable_types: struct lowlib_info { struct module_info { int length; int mem_length; unsigned int vaddr; unsigned int paddr; unsigned int entry; enum module_type { kernel=0, user=1, lowlib=2, server=3, driver=4 } type; char name[-1]; } *modp; char name[-1]; long intr; int (*start)(void *stack_top); int (*quit)(); int (*intr_func)(long signo, void *arg); } *

variable_types: error int

user_defined_types: struct lowlib_info { struct module_info *modp; char name[-1]; long intr; int (*start)(void *stack_top); int (*quit)(); int (*intr_func)(long signo, void *arg); }

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


decompiled_code:
__int64 setup_port()
{
_DWORD *v0; // rbp
unsigned int v1; // ebx

posix_name = (__int64)"manager.posix";
if ( posix_manager || (v1 = find_port("manager.posix", &posix_manager)) == 0 )
{
v0 = (_DWORD *)lowlib_data;
v1 = *lowlib_data;
if ( *lowlib_data )
{
v1 = 0;
}
else
{
*v0 = get_port(56LL, 56LL);
if ( !*lowlib_data )
v1 = -10;
}
}
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
_DWORD *v0; // rbp
unsigned int v1; // ebx

posix_name = (__int64)"manager.posix";
if ( posix_manager || (v1 = find_port("manager.posix", &posix_manager)) == 0 )
{
v0 = (_DWORD *)lowlib_data;
v1 = *lowlib_data;
if ( *lowlib_data )
{
v1 = 0;
}
else
{
*v0 = get_port(56LL, 56LL);
if ( !*lowlib_data )
v1 = -10;
}
}
return v1;
}

original_code:
ER
setup_port (void)
{
  ER error;
  posix_name = "manager.posix";
  if (posix_manager == 0) {
    error = find_port (posix_name, &posix_manager);
    if (error != (0))
      {
 return (error);
      }
  }
  if (lowlib_data->recv_port == 0) {
    lowlib_data->recv_port = get_port (sizeof (struct posix_response), sizeof (struct posix_response));
    if (lowlib_data->recv_port == 0)
      {
 return ((-10));
      }
  }
  return ((0));
}

canonical_original_code:
int setup_port()
{
  int error;
  posix_name = "manager.posix";
  if (posix_manager == 0) {
    error = find_port (posix_name, &posix_manager);
    if (error != (0))
      {
 return (error);
      }
  }
  if (lowlib_data->recv_port == 0) {
    lowlib_data->recv_port = get_port (sizeof (struct posix_response), sizeof (struct posix_response));
    if (lowlib_data->recv_port == 0)
      {
 return ((-10));
      }
  }
  return ((0));
}

user_defined_types: struct posix_response { int receive_port; long msg_length; long operation; long errno; long status; long ret1; long ret2; }


decompiled_code:
__int64 __fastcall lowlib_syscall(__int64 a1, __int64 a2)
{
__int64 (__fastcall *v2)(__int64); // rbx
__int64 result; // rax

if ( a1 < 0 )
return 4294967283LL;
if ( nsyscall <= a1 )
return 4294967283LL;
v2 = (__int64 (__fastcall *)(__int64))syscalls[2 * a1];
if ( !v2 )
return 4294967270LL;
if ( *lowlib_data || (result = setup_port(), !(_DWORD)result) )
result = v2(a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 (__fastcall *v2)(__int64); // rbx
__int64 result; // rax

if ( a1 < 0 )
return 4294967283LL;
if ( nsyscall <= a1 )
return 4294967283LL;
v2 = (__int64 (__fastcall *)(__int64))syscalls[2 * a1];
if ( !v2 )
return 4294967270LL;
if ( *lowlib_data || (result = func3(), !(_DWORD)result) )
result = v2(a2);
return result;
}

original_code:
ER
lowlib_syscall (W syscallno, VP arg)
{
  int (*func)();
  ER errno;
  if ((syscallno < 0) || (syscallno >= nsyscall))
    {
      return ((-13));
    }
  func = syscalls[syscallno].func;
  if (func == (0))
    {
      return ((-26));
    }
  if (lowlib_data->recv_port == 0)
    {
      errno = setup_port ();
      if (errno != (0)) return(errno);
    }
  return ((*func)(arg));
}

canonical_original_code:
int lowlib_syscall(long syscallno, void *arg)
{
  int (*func)();
  int errno;
  if ((syscallno < 0) || (syscallno >= nsyscall))
    {
      return ((-13));
    }
  func = syscalls[syscallno].func;
  if (func == (0))
    {
      return ((-26));
    }
  if (lowlib_data->recv_port == 0)
    {
      errno = setup_port ();
      if (errno != (0)) return(errno);
    }
  return ((*func)(arg));
}

variable_types: syscallno long

variable_types:
arg
void *

variable_types:
func
int (*)()

variable_types: errno int


nodef

decompiled_code:
__int64 nodef()
{
return 26LL;
}

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

original_code:
static int
nodef ()
{
  return (26);
}

canonical_original_code:
static int nodef()
{
  return (26);
}


decompiled_code:
__int64 __fastcall cre_flg(unsigned int a1, __int64 a2)
{
return call_syscall(28LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return call_syscall(28LL, a1, a2);
}

original_code:
ER
cre_flg (ID flgid, T_CFLG *pk_flg)
{
  return (call_syscall ((28), flgid, pk_flg));
}

canonical_original_code:
int cre_flg(int flgid, struct t_cflg *pk_flg)
{
  return (call_syscall ((28), flgid, pk_flg));
}

variable_types: flgid int

variable_types: struct t_cflg { void *exinf; unsigned int flgatr; unsigned int iflgptn; } *


decompiled_code:
__int64 __fastcall del_flg(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(29LL, a1, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, __int64 a3)
{
return call_syscall(29LL, a1, a3);
}

original_code:
ER
del_flg (ID flgid)
{
  return (call_syscall ((29), flgid));
}

canonical_original_code:
int del_flg(int flgid)
{
  return (call_syscall ((29), flgid));
}


decompiled_code:
__int64 __fastcall set_flg(unsigned int a1, unsigned int a2)
{
return call_syscall(30LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
return call_syscall(30LL, a1, a2);
}

original_code:
ER
set_flg (ID flgid, UINT setptn)
{
  return (call_syscall ((30), flgid, setptn));
}

canonical_original_code:
int set_flg(int flgid, unsigned int setptn)
{
  return (call_syscall ((30), flgid, setptn));
}

variable_types:
setptn
unsigned int


decompiled_code:
__int64 __fastcall clr_flg(unsigned int a1, unsigned int a2)
{
return call_syscall(31LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2)
{
return call_syscall(31LL, a1, a2);
}

original_code:
ER
clr_flg (ID flgid, UINT clrptn)
{
  return (call_syscall ((31), flgid, clrptn));
}

canonical_original_code:
int clr_flg(int flgid, unsigned int clrptn)
{
  return (call_syscall ((31), flgid, clrptn));
}

variable_types:
clrptn
unsigned int


decompiled_code:
__int64 __fastcall wai_flg(__int64 a1, unsigned int a2)
{
return call_syscall(32LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
return call_syscall(32LL, a1, a2);
}

original_code:
ER
wai_flg (UINT *flgptn, ID flgid, UINT waiptn, UINT wfmode)
{
  return (call_syscall ((32), flgptn, flgid, waiptn, wfmode));
}

canonical_original_code:
int wai_flg(unsigned int *flgptn, int flgid, unsigned int waiptn, unsigned int wfmode)
{
  return (call_syscall ((32), flgptn, flgid, waiptn, wfmode));
}

variable_types:
flgptn
unsigned int *

variable_types:
waiptn
unsigned int

variable_types:
wfmode
unsigned int


decompiled_code:
__int64 __fastcall pol_flg(__int64 a1, unsigned int a2)
{
return call_syscall(33LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
return call_syscall(33LL, a1, a2);
}

original_code:
ER
pol_flg (UINT *flgptn, ID flgid, UINT waiptn, UINT wfmode)
{
  return (call_syscall ((33), flgptn, flgid, waiptn, wfmode));
}

canonical_original_code:
int pol_flg(unsigned int *flgptn, int flgid, unsigned int waiptn, unsigned int wfmode)
{
  return (call_syscall ((33), flgptn, flgid, waiptn, wfmode));
}


decompiled_code:
__int64 __fastcall twai_flg(__int64 a1, unsigned int a2)
{
return call_syscall(34LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
return call_syscall(34LL, a1, a2);
}

original_code:
ER
twai_flg (UINT *flgptn, ID flgid, UINT waiptn, UINT wfmode, TMO tmout)
{
  return (call_syscall ((34), flgptn, flgid, waiptn, wfmode, tmout));
}

canonical_original_code:
int twai_flg(unsigned int *flgptn, int flgid, unsigned int waiptn, unsigned int wfmode, int tmout)
{
  return (call_syscall ((34), flgptn, flgid, waiptn, wfmode, tmout));
}

variable_types: tmout int


decompiled_code:
__int64 __fastcall ref_flg(__int64 a1, unsigned int a2)
{
return call_syscall(35LL, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
return call_syscall(35LL, a1, a2);
}

original_code:
ER
ref_flg (T_RFLG *pk_rflg, ID flgid)
{
  return (call_syscall ((35), pk_rflg, flgid));
}

canonical_original_code:
int ref_flg(struct t_rflg *pk_rflg, int flgid)
{
  return (call_syscall ((35), pk_rflg, flgid));
}

variable_types: struct t_rflg { void *exinf; int wtsk; unsigned int flgptn; } *


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

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

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

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

variable_types: caller int

variable_types:
packet
struct DDEV_OPN_REQ { long dd; } *

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

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


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

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

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

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

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

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

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

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

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

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

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


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

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

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


decompiled_code:
__int64 __fastcall write_svga_cons(unsigned int a1, __int64 *a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
int v4; // eax
__int64 v5; // rax
__int64 v6; // r13
unsigned __int8 v7; // bp
__int64 v9; // [rsp+0h] [rbp-498h]
__int64 v10; // [rsp+8h] [rbp-490h]
char v11[32]; // [rsp+10h] [rbp-488h] BYREF
__int64 v12; // [rsp+30h] [rbp-468h]
__int64 v13; // [rsp+38h] [rbp-460h]
__int64 v14; // [rsp+40h] [rbp-458h]
__int64 v15; // [rsp+48h] [rbp-450h]

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

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, __int64 *a2)
{
__int64 v2; // rbx
unsigned int v3; // ebp
int v4; // eax
__int64 v5; // rax
__int64 v6; // r13
unsigned __int8 v7; // bp
__int64 v9; // [rsp+0h] [rbp-498h]
__int64 v10; // [rsp+8h] [rbp-490h]
char v11[32]; // [rsp+10h] [rbp-488h] BYREF
__int64 v12; // [rsp+30h] [rbp-468h]
__int64 v13; // [rsp+38h] [rbp-460h]
__int64 v14; // [rsp+40h] [rbp-458h]
__int64 v15; // [rsp+48h] [rbp-450h]

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

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

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

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

variable_types: i int

variable_types: error int

variable_types: cnum int

variable_types:
cpos
long [2]

variable_types:
ch
unsigned char


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

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

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

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


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

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

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 ("svga_cons: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.svga_cons", 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 ("svga_cons: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.svga_cons", recvport);
  if (error != (0))
    {
    }
}


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

result = *((_QWORD *)a1 + 1);
if ( result == 2 )
return read_svga_cons(*a1, (_QWORD *)a1 + 4);
if ( result > 2 )
{
if ( result == 3 )
result = write_svga_cons(*a1, (__int64 *)a1 + 4);
}
else if ( result )
{
if ( result == 1 )
result = close_svga_cons(*a1, (_QWORD *)a1 + 4);
}
else
{
result = open_svga_cons(*a1, (_QWORD *)a1 + 4);
}
return result;
}

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

result = *((_QWORD *)a1 + 1);
if ( result == 2 )
return func3(*a1, (_QWORD *)a1 + 4);
if ( result > 2 )
{
if ( result == 3 )
result = func4(*a1, (__int64 *)a1 + 4);
}
else if ( result )
{
if ( result == 1 )
result = func2(*a1, (_QWORD *)a1 + 4);
}
else
{
result = func1(*a1, (_QWORD *)a1 + 4);
}
return result;
}

original_code:
ER
process_request (DDEV_REQ *req)
{
  switch (req->header.msgtyp)
    {
    case DEV_OPN:
      open_svga_cons (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_svga_cons (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_svga_cons (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_svga_cons (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_svga_cons (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_svga_cons (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_svga_cons (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_svga_cons (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_svga_cons (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_svga_cons (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

while ( 1 )
{
get_req((unsigned int)recvport, v1, v0);
if ( sys_errno )
slp_tsk();
else
process_request(v1);
}
}

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

while ( 1 )
{
get_req((unsigned int)recvport, v1, v0);
if ( sys_errno )
slp_tsk();
else
func5(v1);
}
}

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


start

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

canonical_decompiled_code:
void __noreturn func7()
{
probe(&dev_table);
func0();
printf("registed svga_cons driver.\n");
func6();
}

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

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


decompiled_code:
__int64 __fastcall psys_mkfifo(__int64 *a1)
{
__int64 v2; // [rsp+0h] [rbp-C8h] BYREF
__int64 v3; // [rsp+18h] [rbp-B0h]
unsigned int v4; // [rsp+20h] [rbp-A8h]
char v5[32]; // [rsp+40h] [rbp-88h] BYREF
__int64 v6; // [rsp+60h] [rbp-68h]
__int64 v7; // [rsp+68h] [rbp-60h]
__int64 v8; // [rsp+70h] [rbp-58h]

v6 = *a1;
v7 = a1[1];
v8 = a1[2];
if ( (unsigned int)make_connection(74LL, v5, &v2) || !v3 )
return v4;
MEMORY[0x7FFF0028] = v3;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1)
{
__int64 v2; // [rsp+0h] [rbp-C8h] BYREF
__int64 v3; // [rsp+18h] [rbp-B0h]
unsigned int v4; // [rsp+20h] [rbp-A8h]
char v5[32]; // [rsp+40h] [rbp-88h] BYREF
__int64 v6; // [rsp+60h] [rbp-68h]
__int64 v7; // [rsp+68h] [rbp-60h]
__int64 v8; // [rsp+70h] [rbp-58h]

v6 = *a1;
v7 = a1[1];
v8 = a1[2];
if ( (unsigned int)make_connection(74LL, v5, &v2) || !v3 )
return v4;
MEMORY[0x7FFF0028] = v3;
return 0xFFFFFFFFLL;
}

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

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

variable_types:
argp
void *

variable_types:
args
struct a {  } *


decompiled_code:
void open_ne2000()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

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

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

variable_types: caller int


decompiled_code:
void close_ne2000()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

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

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

user_defined_types: struct DDEV_CLS_REQ { long dd; long eject; }


decompiled_code:
__int64 __fastcall read_ne2000(__int64 a1, __int64 *a2)
{
unsigned int v2; // ebp
__int64 v3; // rdx
__int64 v5[137]; // [rsp+0h] [rbp-448h] BYREF

v5[0] = *a2;
v3 = read_buffer_length;
if ( read_buffer_length > 0 )
{
if ( a2[2] <= read_buffer_length )
v3 = a2[2];
v2 = vput_reg(a1, a2[1], v3, &read_buffer);
}
v5[1] = (int)v2;
v5[2] = 0LL;
v5[4] = read_buffer_length;
snd_mbf((unsigned int)a1, 1064LL, v5);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 *a2)
{
unsigned int v2; // ebp
__int64 v3; // rdx
__int64 v5[137]; // [rsp+0h] [rbp-448h] BYREF

v5[0] = *a2;
v3 = read_buffer_length;
if ( read_buffer_length > 0 )
{
if ( a2[2] <= read_buffer_length )
v3 = a2[2];
v2 = vput_reg(a1, a2[1], v3, &read_buffer);
}
v5[1] = (int)v2;
v5[2] = 0LL;
v5[4] = read_buffer_length;
snd_mbf((unsigned int)a1, 1064LL, v5);
return v2;
}

original_code:
ER
read_ne2000 (ID caller, DDEV_REA_REQ *packet)
{
  DDEV_REA_RES res;
  ER err;
  res.dd = packet->dd;
  if (read_buffer_length > 0)
    {
      err = vput_reg (caller,
        packet->start,
        (read_buffer_length > packet->size) ? packet->size : read_buffer_length,
        read_buffer);
    }
  res.errcd = err;
  res.errinfo = 0;
  res.a_size = read_buffer_length;
  snd_mbf (caller, sizeof (res), &res);
  return (err);
}

canonical_original_code:
int read_ne2000(int caller, struct DDEV_REA_REQ *packet)
{
  struct DDEV_REA_RES res;
  int err;
  res.dd = packet->dd;
  if (read_buffer_length > 0)
    {
      err = vput_reg (caller,
        packet->start,
        (read_buffer_length > packet->size) ? packet->size : read_buffer_length,
        read_buffer);
    }
  res.errcd = err;
  res.errinfo = 0;
  res.a_size = read_buffer_length;
  snd_mbf (caller, sizeof (res), &res);
  return (err);
}

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

variable_types: err int

user_defined_types: struct DDEV_REA_REQ { long dd; long start; long size; }


original_code:
ER
write_ne2000 (ID caller, ID tskid, DDEV_WRI_REQ *packet)
{
  DDEV_REA_RES res;
  ER err;
  UB buf[1514];
  res.dd = packet->dd;
printf ("write_ne2000: write\n");
printf ("%s: %d\n", "ne2000.c", 278);
  if (packet->size > 1514)
    {
      err = (-33);
    }
  else
    {
      int i;
      vget_reg (tskid, packet->start, packet->size, buf);
      for (i = 0; i < 64; i++)
 {
   printf ("buf[%d]: 0x%x ", i, buf[i]);
   if ((i % 4) == 0)
     {
       printf ("\n");
     }
 }
      err = write_frame (&dev_table[packet->dd & 0x0f], buf, packet->size);
    }
  res.errcd = err;
  res.errinfo = 0;
  snd_mbf (caller, sizeof (res), &res);
  return (err);
}

canonical_original_code:
int write_ne2000(int caller, int tskid, struct DDEV_WRI_REQ *packet)
{
  struct DDEV_REA_RES res;
  int err;
  unsigned char buf[1514];
  res.dd = packet->dd;
printf ("write_ne2000: write\n");
printf ("%s: %d\n", "ne2000.c", 278);
  if (packet->size > 1514)
    {
      err = (-33);
    }
  else
    {
      int i;
      vget_reg (tskid, packet->start, packet->size, buf);
      for (i = 0; i < 64; i++)
 {
   printf ("buf[%d]: 0x%x ", i, buf[i]);
   if ((i % 4) == 0)
     {
       printf ("\n");
     }
 }
      err = write_frame (&dev_table[packet->dd & 0x0f], buf, packet->size);
    }
  res.errcd = err;
  res.errinfo = 0;
  snd_mbf (caller, sizeof (res), &res);
  return (err);
}

variable_types: tskid int

variable_types:
buf
unsigned char [1514]

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


original_code:
ER
control_ne2000 (ID caller, DDEV_CTL_REQ *packet)
{
  DDEV_RES res;
  ER errno;
  UW devno;
  W i;
  devno = packet->dd;
  if ((devno < 0) || (devno >= 1))
    {
      res.body.ctl_res.dd = packet->dd;
      res.body.ctl_res.errcd = (-33);
      res.body.ctl_res.errinfo = 0;
      snd_mbf (caller, sizeof (res), &res);
    }
  switch (packet->cmd)
    {
    case 0x00000001:
      errno = reset_adaptor (&dev_table[devno]);
      if (errno)
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (-101);
   res.body.ctl_res.errinfo = errno;
   snd_mbf (caller, sizeof (res), &res);
 }
      else
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (0);
   res.body.ctl_res.errinfo = (0);
   snd_mbf (caller, sizeof (res), &res);
   return ((0));
 }
      break;
    case 0x00000002:
      if (dev_table[devno].io_base != 0)
 {
   errno = probe_1 (&dev_table[devno]);
 }
      else
 {
   errno = (-101);
 }
      if (errno)
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (-101);
   res.body.ctl_res.errinfo = errno;
   snd_mbf (caller, sizeof (res), &res);
 }
      else
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (0);
   res.body.ctl_res.errinfo = (0);
   snd_mbf (caller, sizeof (res), &res);
   return ((0));
 }
      break;
    case 0x00000003:
      for (i = 0; i < 6; i++)
 {
   res.body.ctl_res.res[i] = dev_table[devno].sa_prom[i];
 }
      res.body.ctl_res.dd = packet->dd;
      res.body.ctl_res.errcd = (0);
      res.body.ctl_res.errinfo = (0);
      snd_mbf (caller, sizeof (res), &res);
      return ((0));
    }
  res.body.ctl_res.dd = packet->dd;
  res.body.ctl_res.errcd = (-33);
  res.body.ctl_res.errinfo = errno;
  snd_mbf (caller, sizeof (res), &res);
  return ((-33));
}

canonical_original_code:
int control_ne2000(int caller, struct DDEV_CTL_REQ *packet)
{
  struct DDEV_RES res;
  int errno;
  unsigned long devno;
  long i;
  devno = packet->dd;
  if ((devno < 0) || (devno >= 1))
    {
      res.body.ctl_res.dd = packet->dd;
      res.body.ctl_res.errcd = (-33);
      res.body.ctl_res.errinfo = 0;
      snd_mbf (caller, sizeof (res), &res);
    }
  switch (packet->cmd)
    {
    case 0x00000001:
      errno = reset_adaptor (&dev_table[devno]);
      if (errno)
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (-101);
   res.body.ctl_res.errinfo = errno;
   snd_mbf (caller, sizeof (res), &res);
 }
      else
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (0);
   res.body.ctl_res.errinfo = (0);
   snd_mbf (caller, sizeof (res), &res);
   return ((0));
 }
      break;
    case 0x00000002:
      if (dev_table[devno].io_base != 0)
 {
   errno = probe_1 (&dev_table[devno]);
 }
      else
 {
   errno = (-101);
 }
      if (errno)
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (-101);
   res.body.ctl_res.errinfo = errno;
   snd_mbf (caller, sizeof (res), &res);
 }
      else
 {
   res.body.ctl_res.dd = packet->dd;
   res.body.ctl_res.errcd = (0);
   res.body.ctl_res.errinfo = (0);
   snd_mbf (caller, sizeof (res), &res);
   return ((0));
 }
      break;
    case 0x00000003:
      for (i = 0; i < 6; i++)
 {
   res.body.ctl_res.res[i] = dev_table[devno].sa_prom[i];
 }
      res.body.ctl_res.dd = packet->dd;
      res.body.ctl_res.errcd = (0);
      res.body.ctl_res.errinfo = (0);
      snd_mbf (caller, sizeof (res), &res);
      return ((0));
    }
  res.body.ctl_res.dd = packet->dd;
  res.body.ctl_res.errcd = (-33);
  res.body.ctl_res.errinfo = errno;
  snd_mbf (caller, sizeof (res), &res);
  return ((-33));
}

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

variable_types: errno int

variable_types:
devno
unsigned long

variable_types: i long

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


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

result = *((_QWORD *)a1 + 1);
switch ( result )
{
case 3LL:
return write_ne2000(*a1, a1[4], (__int64 *)a1 + 4);
case 4LL:
return control_ne2000(*a1, (__int64 *)a1 + 4);
case 2LL:
result = read_ne2000(*a1, (__int64 *)a1 + 4);
break;
}
return result;
}

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

result = *((_QWORD *)a1 + 1);
switch ( result )
{
case 3LL:
return func4(*a1, a1[4], (__int64 *)a1 + 4);
case 4LL:
return func5(*a1, (__int64 *)a1 + 4);
case 2LL:
result = func3(*a1, (__int64 *)a1 + 4);
break;
}
return result;
}

original_code:
ER
process_request (DDEV_REQ *req)
{
  switch (req->header.msgtyp)
    {
    case DEV_OPN:
      open_ne2000 (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_ne2000 (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_ne2000 (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_ne2000 (req->header.mbfid, req->header.tskid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_ne2000 (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_ne2000 (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_ne2000 (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_ne2000 (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_ne2000 (req->header.mbfid, req->header.tskid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_ne2000 (req->header.mbfid, &(req->body.ctl_req));
      break;
    }
}

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; }

user_defined_types: struct DDEV_PRD_REQ { long dd; char *buf; long start; long length; }

user_defined_types: struct DDEV_RLY_REQ { long dd; long start; long size; unsigned char dt[1024]; }


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

while ( 1 )
{
get_req((unsigned int)recvport, v1, v0);
if ( sys_errno )
slp_tsk();
else
func6(v1);
}
}


decompiled_code:
void __noreturn start()
{
if ( (unsigned int)probe(dev_table) )
{
dbg_printf("Can not probe: ne2000\n");
slp_tsk();
}
max_adaptor = 1;
init_driver(dev_table);
printf("registed ne2000 driver.\n");
main_loop();
}

canonical_decompiled_code:
void __noreturn func8()
{
if ( (unsigned int)probe(dev_table) )
{
dbg_printf("Can not probe: ne2000\n");
slp_tsk();
}
max_adaptor = 1;
func0(dev_table);
printf("registed ne2000 driver.\n");
func7();
}

original_code:
void
start ()
{
  if (probe (&dev_table[0]) != (0))
    {
      dbg_printf ("Can not probe: ne2000\n");
      slp_tsk ();
    }
  max_adaptor = 1;
  init_driver (&dev_table[0]);
  printf ("registed ne2000 driver.\n");
  main_loop ();
}

canonical_original_code:
void start()
{
  if (probe (&dev_table[0]) != (0))
    {
      dbg_printf ("Can not probe: ne2000\n");
      slp_tsk ();
    }
  max_adaptor = 1;
  init_driver (&dev_table[0]);
  printf ("registed ne2000 driver.\n");
  main_loop ();
}


winmod

decompiled_code:
int __fastcall winmod(int a1, int a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return fcntl(a1, 1073807368, &v3);
}

canonical_decompiled_code:
int __fastcall func13(int a1, int a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return fcntl(a1, 1073807368, &v3);
}

original_code:
int winmod(int fd, int mode)
{
  struct wc_winmod_t param;
  int error;
  param.mode = mode;
  error = fcntl(fd, (0x00004001 << 16 | sizeof(struct wc_winmod_t) & 0xFFFF), &param);
  return(error);
}

variable_types: fd int

variable_types: mode int

variable_types:
param
struct wc_winmod_t { long mode; }

variable_types: error int


decompiled_code:
int __fastcall graphic_mode(int a1)
{
return fcntl(a1, 196608, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
return fcntl(a1, 196608, 0LL);
}

original_code:
int graphic_mode (int fd)
{
  int errno;
  errno = fcntl(fd, (0x00000003 << 16), 0);
  return(errno);
}

canonical_original_code:
int graphic_mode(int fd)
{
  int errno;
  errno = fcntl(fd, (0x00000003 << 16), 0);
  return(errno);
}


decompiled_code:
int __fastcall text_mode(int a1)
{
return fcntl(a1, 0x40000, 0LL);
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
return fcntl(a1, 0x40000, 0LL);
}

original_code:
int text_mode (int fd)
{
  int errno;
  errno = fcntl(fd, (0x00000004 << 16), 0);
  return(errno);
}

canonical_original_code:
int text_mode(int fd)
{
  int errno;
  errno = fcntl(fd, (0x00000004 << 16), 0);
  return(errno);
}


original_code:
int box_vga (int fd, int x, int y, int width, int height, int color)
{
  struct gr_box_t param;
  int errno;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  errno = fcntl(fd, (0x00008003 << 16 | (sizeof(struct gr_box_t) & 0x0FFFF)), &param);
  return (errno);
}

canonical_original_code:
int box_vga(int fd, int x, int y, int width, int height, int color)
{
  struct gr_box_t param;
  int errno;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  errno = fcntl(fd, (0x00008003 << 16 | (sizeof(struct gr_box_t) & 0x0FFFF)), &param);
  return (errno);
}

variable_types: x int

variable_types: y int

variable_types: width int

variable_types: height int

variable_types: color int

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


original_code:
int fillbox_vga (int fd, int x, int y, int width, int height, int color)
{
  struct gr_fillbox_t param;
  int error;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  error = fcntl(fd, (0x00008004 << 16 | (sizeof(struct gr_fillbox_t) & 0x0FFFF)), &param);
  return(error);
}

canonical_original_code:
int fillbox_vga(int fd, int x, int y, int width, int height, int color)
{
  struct gr_fillbox_t param;
  int error;
  param.x = x;
  param.y = y;
  param.width = width;
  param.height = height;
  param.color = color;
  error = fcntl(fd, (0x00008004 << 16 | (sizeof(struct gr_fillbox_t) & 0x0FFFF)), &param);
  return(error);
}

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


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

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

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


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

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

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


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

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

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


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

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

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


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

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

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


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

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

variable_types:
bitmap
unsigned char *

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

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