decompiled_code:
__int64 __fastcall unregist_port(__int64 a1)
{
int v1; // eax
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = unregist_database(a1 + 24, v3, *(unsigned int *)(a1 + 68));
if ( v1 )
result = recv_port_manager(*(unsigned int *)(a1 + 16), v1, v3[0]);
else
result = recv_port_manager(*(unsigned int *)(a1 + 16), 0, 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // eax
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = unregist_database(a1 + 24, v3, *(unsigned int *)(a1 + 68));
if ( v1 )
result = func0(*(unsigned int *)(a1 + 16), v1, v3[0]);
else
result = func0(*(unsigned int *)(a1 + 16), 0, 0);
return result;
}

original_code:
void
unregist_port (struct port_manager_msg_t *msgp)
{
  PORT_MANAGER_ERROR errno;
  ID port;
  errno = unregist_database (msgp->body.unregist.name,
        &port,
        msgp->body.unregist.task);
  if (errno != E_PORT_OK)
    {
      recv_port_manager (msgp->hdr.rport,
    errno,
    port);
    }
  else
    {
      recv_port_manager (msgp->hdr.rport, errno, 0);
    }
}

canonical_original_code:
void unregist_port(struct port_manager_msg_t *msgp)
{
  enum port_manager_error_t errno;
  int port;
  errno = unregist_database (msgp->body.unregist.name,
        &port,
        msgp->body.unregist.task);
  if (errno != E_PORT_OK)
    {
      recv_port_manager (msgp->hdr.rport,
    errno,
    port);
    }
  else
    {
      recv_port_manager (msgp->hdr.rport, errno, 0);
    }
}

user_defined_types: struct port_message_header_t { long type; long size; int rport; }

user_defined_types: struct regist_port_t { char name[-1]; int port; int task; }

user_defined_types: struct unregist_port_t { char name[-1]; int task; }


repo: monaka/B-Free

decompiled_code:
__int64 __fastcall find_port(__int64 a1)
{
int v1; // eax
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = find_database(a1 + 24, v3);
if ( v1 )
result = recv_port_manager(*(unsigned int *)(a1 + 16), v1, 0);
else
result = recv_port_manager(*(unsigned int *)(a1 + 16), 0, v3[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
__int64 result; // rax
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = find_database(a1 + 24, v3);
if ( v1 )
result = func0(*(unsigned int *)(a1 + 16), v1, 0);
else
result = func0(*(unsigned int *)(a1 + 16), 0, v3[0]);
return result;
}

original_code:
void
find_port (struct port_manager_msg_t *msgp)
{
  PORT_MANAGER_ERROR errno;
  ID port;
  errno = find_database (msgp->body.find.name, &port);
  if (errno == E_PORT_OK)
    {
      recv_port_manager (msgp->hdr.rport,
    errno,
    port);
    }
  else
    {
      recv_port_manager (msgp->hdr.rport, errno, 0);
    }
}

canonical_original_code:
void find_port(struct port_manager_msg_t *msgp)
{
  enum port_manager_error_t errno;
  int port;
  errno = find_database (msgp->body.find.name, &port);
  if (errno == E_PORT_OK)
    {
      recv_port_manager (msgp->hdr.rport,
    errno,
    port);
    }
  else
    {
      recv_port_manager (msgp->hdr.rport, errno, 0);
    }
}

variable_types: struct port_manager_msg_t { struct port_message_header_t { long type; long size; int rport; } hdr; union port_message_body_t { struct regist_port_t { char name[-1]; int port; int task; } regist; struct unregist_port_t { char name[-1]; int task; } unregist; struct find_port_t { char name[-1]; } find; } body; } *

variable_types: enum port_manager_error_t { E_PORT_OK=0, E_PORT_DUPLICATION=1, E_PORT_NOTFOUND=2, E_PORT_FULL=3, E_PORT_INVALID=4, E_PORT_SYSTEM=5 }

variable_types: port int

return_type: void

user_defined_types: struct port_manager_msg_t { struct port_message_header_t hdr; union port_message_body_t body; }

user_defined_types: union port_message_body_t { struct regist_port_t regist; struct unregist_port_t unregist; struct find_port_t find; }


waitpid

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

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

original_code:
int
waitpid (pid_t pid, int *status, int option)
{
  return (call_lowlib (38, pid, status, option));
}

canonical_original_code:
int waitpid(unsigned int pid, int *status, int option)
{
  return (call_lowlib (38, pid, status, option));
}

variable_types:
pid
unsigned int

variable_types:
status
int *

variable_types: option int

return_type: int


link

decompiled_code:
__int64 __fastcall link(char *s, char *a2)
{
unsigned int v2; // er12
unsigned int v3; // eax

v2 = strlen(a2);
v3 = strlen(s);
return call_lowlib(20LL, v3, s, v2, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s, char *a2)
{
unsigned int v2; // er12
unsigned int v3; // eax

v2 = strlen(a2);
v3 = strlen(s);
return call_lowlib(20LL, v3, s, v2, a2);
}

original_code:
int
link (char *src, char *dst)
{
  return (call_lowlib (20, strlen (src), src, strlen (dst), dst));
}

canonical_original_code:
int link(char *src, char *dst)
{
  return (call_lowlib (20, strlen (src), src, strlen (dst), dst));
}

variable_types:
src
char *

variable_types:
dst
char *


mkdir

decompiled_code:
void mkdir()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
mkdir (char *path, int mode)
{
  return (call_lowlib (22, strlen (path), path, mode));
}

canonical_original_code:
int mkdir(char *path, int mode)
{
  return (call_lowlib (22, strlen (path), path, mode));
}

variable_types:
path
char *

variable_types: mode int


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

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

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

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

variable_types:
argp
void *

variable_types:
args
struct a {  } *


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

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

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


getgroups

decompiled_code:
__int64 __fastcall getgroups(const char *a1)
{
unsigned int v1; // eax

v1 = strlen(a1);
return call_lowlib(72LL, v1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
unsigned int v1; // eax

v1 = strlen(a1);
return call_lowlib(72LL, v1, a1);
}

original_code:
int
getgroups (char *group)
{
  return (call_lowlib (72, strlen (group), group));
}

canonical_original_code:
int getgroups(char *group)
{
  return (call_lowlib (72, strlen (group), group));
}

variable_types:
group
char *


siglongjmp

decompiled_code:
void __noreturn siglongjmp()
{
call_lowlib(63LL);
}

canonical_decompiled_code:
void __noreturn func0()
{
call_lowlib(63LL);
}

original_code:
int
siglongjmp (void)
{
  return (call_lowlib (63));
}

canonical_original_code:
int siglongjmp()
{
  return (call_lowlib (63));
}


decompiled_code:
__int64 __fastcall psys_write(__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(39LL, 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(39LL, v5, &v2) || !v3 )
return v4;
MEMORY[0x7FFF0028] = v3;
return 0xFFFFFFFFLL;
}

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

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

return_type: unsigned int


getgrgid

decompiled_code:
void getgrgid()
{
;
}

original_code:
int
getgrgid (void)
{
  return (call_lowlib (70));
}

canonical_original_code:
int getgrgid()
{
  return (call_lowlib (70));
}


pipe

decompiled_code:
void pipe()
{
;
}

original_code:
int
pipe (int fds[2])
{
  return (call_lowlib (24, fds));
}

canonical_original_code:
int pipe(int fds[2])
{
  return (call_lowlib (24, fds));
}

variable_types:
fds
int [2]


decompiled_code:
void __fastcall set_palette(__int64 a1)
{
__int64 i; // rbx

for ( i = 0LL; i != 16; ++i )
{
outb(0xC8u, i);
outb(0xC9u, *(unsigned __int8 *)(a1 + i));
outb(0xC9u, *(unsigned __int8 *)(a1 + i + 16));
outb(0xC9u, *(unsigned __int8 *)(a1 + i + 32));
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
__int64 i; // rbx

for ( i = 0LL; i != 16; ++i )
{
outb(0xC8u, i);
outb(0xC9u, *(unsigned __int8 *)(a1 + i));
outb(0xC9u, *(unsigned __int8 *)(a1 + i + 16));
outb(0xC9u, *(unsigned __int8 *)(a1 + i + 32));
}
}

original_code:
void
set_palette (struct palette *pal)
{
  int i;
  for (i = 0; i < 16; i++)
    {
      outb (0x3C8, i);
      outb (0x3C9, pal->red[i]);
      outb (0x3C9, pal->green[i]);
      outb (0x3C9, pal->blue[i]);
    }
}

canonical_original_code:
void set_palette(struct palette *pal)
{
  int i;
  for (i = 0; i < 16; i++)
    {
      outb (0x3C8, i);
      outb (0x3C9, pal->red[i]);
      outb (0x3C9, pal->green[i]);
      outb (0x3C9, pal->blue[i]);
    }
}

variable_types: struct palette { unsigned char red[16]; unsigned char green[16]; unsigned char blue[16]; } *

variable_types: i int


sleep

decompiled_code:
__int64 __fastcall sleep(unsigned int a1)
{
return call_lowlib(77LL, a1);
}

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

original_code:
int
sleep (int second)
{
  return (call_lowlib (77, second));
}

canonical_original_code:
int sleep(int second)
{
  return (call_lowlib (77, second));
}

variable_types: second int


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

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

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


time

decompiled_code:
void time()
{
;
}

original_code:
int
time (time_t *tm)
{
  return (call_lowlib (33, tm));
}

canonical_original_code:
int time(unsigned long *tm)
{
  return (call_lowlib (33, tm));
}

variable_types:
tm
unsigned long *


decompiled_code:
__int64 __fastcall posix_entry(int a1, __int64 a2, _DWORD *a3)
{
__int64 result; // rax

if ( a1 < 0 || nsyscall < a1 )
{
*a3 = 13;
result = 0LL;
}
else
{
result = syscalls[2 * a1](a2);
*a3 = errno;
}
return result;
}

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

if ( a1 < 0 || nsyscall < a1 )
{
*a3 = 13;
result = 0LL;
}
else
{
result = syscalls[2 * a1](a2);
*a3 = errno;
}
return result;
}

original_code:
int
posix_entry (int sysno, void *uargp, int *errnop)
{
  int result;
  if ((sysno < 0) || (sysno > nsyscall))
    {
      *errnop = 13;
      return (0);
    }
  result = (int)(syscalls[sysno].func)(uargp);
  *errnop = errno;
  return (result);
}

canonical_original_code:
int posix_entry(int sysno, void *uargp, int *errnop)
{
  int result;
  if ((sysno < 0) || (sysno > nsyscall))
    {
      *errnop = 13;
      return (0);
    }
  result = (int)(syscalls[sysno].func)(uargp);
  *errnop = errno;
  return (result);
}

variable_types: sysno int

variable_types:
uargp
void *

variable_types:
errnop
int *

variable_types: result int


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

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

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


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

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

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

return_type: unsigned short


lseek

decompiled_code:
void lseek()
{
;
}

original_code:
int
lseek (int fd, int offset, int mode)
{
  return (call_lowlib (21, fd, offset, mode));
}

canonical_original_code:
int lseek(int fd, int offset, int mode)
{
  return (call_lowlib (21, fd, offset, mode));
}

variable_types: fd int

variable_types: offset int


decompiled_code:
__int64 __fastcall def_int(__int64 a1, __int64 a2)
{
return call_syscall(67LL, a1, a2);
}

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

original_code:
ER
def_int (W intno, T_DINT *pk_dint)
{
  return (call_syscall ((67), intno, pk_dint));
}

canonical_original_code:
int def_int(long intno, struct t_dint *pk_dint)
{
  return (call_syscall ((67), intno, pk_dint));
}

variable_types: intno long

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


decompiled_code:
__int64 __fastcall psys_setpgid(__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]

v6 = *a1;
if ( (unsigned int)make_connection(29LL, 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]

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

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

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


sigdelset

decompiled_code:
__int64 __fastcall sigdelset(__int64 a1, unsigned int a2)
{
return call_lowlib(59LL, a1, a2);
}

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

original_code:
int
sigdelset (sigset_t *set, int signo)
{
  return (call_lowlib (59, set, signo));
}

canonical_original_code:
int sigdelset(int *set, int signo)
{
  return (call_lowlib (59, set, signo));
}

variable_types:
set
int *

variable_types: signo int


decompiled_code:
__int64 __fastcall psys_link(__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]
__int64 v9; // [rsp+78h] [rbp-50h]

v6 = *a1;
v7 = a1[1];
v8 = a1[2];
v9 = a1[3];
if ( (unsigned int)make_connection(20LL, 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]
__int64 v9; // [rsp+78h] [rbp-50h]

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

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

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

variable_types:
argp
void *

variable_types:
args
struct a {  } *


rename

decompiled_code:
void rename()
{
;
}

original_code:
int
rename (char *src, char *dst)
{
  return (call_lowlib (26, strlen (src), src, strlen (dst), dst));
}

canonical_original_code:
int rename(char *src, char *dst)
{
  return (call_lowlib (26, strlen (src), src, strlen (dst), dst));
}

variable_types:
src
char *

variable_types:
dst
char *


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

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

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


decompiled_code:
__int64 psys_geteuid()
{
__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(14LL, 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(14LL, v4, &v1) || !v2 )
return v3;
MEMORY[0x7FFF0028] = v2;
return 0xFFFFFFFFLL;
}

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

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


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

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

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

return_type: char *


sigpending

decompiled_code:
__int64 sigpending()
{
return call_lowlib(56LL);
}

canonical_decompiled_code:
__int64 func0()
{
return call_lowlib(56LL);
}

original_code:
int
sigpending (void)
{
  return (call_lowlib (56));
}

canonical_original_code:
int sigpending()
{
  return (call_lowlib (56));
}


decompiled_code:
__int64 __fastcall psys_unlink(__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]

v6 = *a1;
v7 = a1[1];
if ( (unsigned int)make_connection(36LL, 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]

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

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

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


getppid

decompiled_code:
__int64 getppid()
{
return call_lowlib(18LL);
}

canonical_decompiled_code:
__int64 func0()
{
return call_lowlib(18LL);
}

original_code:
int
getppid (void)
{
  return (call_lowlib (18));
}

canonical_original_code:
int getppid()
{
  return (call_lowlib (18));
}


decompiled_code:
__int64 __fastcall dly_tsk(__int64 a1)
{
return call_syscall(60LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return call_syscall(60LL, a1);
}

original_code:
ER dly_tsk(DLYTIME dlytim)
{
  return call_syscall ((60), dlytim);
}

canonical_original_code:
int dly_tsk(unsigned long dlytim)
{
  return call_syscall ((60), dlytim);
}

variable_types:
dlytim
unsigned long


decompiled_code:
__int64 __fastcall act_cyc(unsigned int a1)
{
return call_syscall(62LL, a1);
}

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

original_code:
ER act_cyc(HNO cycno, UINT cycact)
{
  return call_syscall ((62), cycno, cycact);
}

canonical_original_code:
int act_cyc(int cycno, unsigned int cycact)
{
  return call_syscall ((62), cycno, cycact);
}

variable_types: cycno int

variable_types:
cycact
unsigned int


decompiled_code:
__int64 init_file_manager()
{
recvport = get_port(296LL, 296LL);
if ( recvport <= 0 )
{
dbg_printf("FM: cannot make receive porrt.\n");
slp_tsk();
}
return regist_port("posix.server.file", (unsigned int)recvport);
}

canonical_decompiled_code:
__int64 func0()
{
recvport = get_port(296LL, 296LL);
if ( recvport <= 0 )
{
dbg_printf("FM: cannot make receive porrt.\n");
slp_tsk();
}
return regist_port("posix.server.file", (unsigned int)recvport);
}

original_code:
static void
init_file_manager (void)
{
  int i;
  ID root_dev;
  ER error;
  recvport = get_port (sizeof (struct fm_msg), sizeof (struct fm_msg));
  if (recvport <= 0)
    {
      dbg_printf ("FM: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("posix.server.file", recvport);
  if (error != 0)
    {
    }
}

canonical_original_code:
static void init_file_manager()
{
  int i;
  int root_dev;
  int error;
  recvport = get_port (sizeof (struct fm_msg), sizeof (struct fm_msg));
  if (recvport <= 0)
    {
      dbg_printf ("FM: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("posix.server.file", recvport);
  if (error != 0)
    {
    }
}

variable_types: i int

variable_types: error int

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

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

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

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


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

v4[3] = a1;
v4[4] = a2 * a1;
v4[2] = 0;
v2 = 100;
while ( (unsigned int)cre_mbf(v2, v4) )
{
if ( ++v2 == 257 )
return 0;
}
return v2;
}

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

v4[3] = a1;
v4[4] = a2 * a1;
v4[2] = 0;
v2 = 100;
while ( (unsigned int)cre_mbf(v2, v4) )
{
if ( ++v2 == 257 )
return 0;
}
return v2;
}

original_code:
ID
alloc_port (W size, W max_entry)
{
  ID msg_port;
  T_CMBF create_argument;
  create_argument.bufsz = size;
  create_argument.maxmsz = size * max_entry;
  create_argument.mbfatr = (0x00000000);
  for (msg_port = (100);
       msg_port <= (256);
       msg_port++)
    {
      if (cre_mbf (msg_port, &create_argument) == (0))
 {
   return (msg_port);
 }
    }
  return (0);
}

canonical_original_code:
int alloc_port(long size, long max_entry)
{
  int msg_port;
  struct t_cmbf create_argument;
  create_argument.bufsz = size;
  create_argument.maxmsz = size * max_entry;
  create_argument.mbfatr = (0x00000000);
  for (msg_port = (100);
       msg_port <= (256);
       msg_port++)
    {
      if (cre_mbf (msg_port, &create_argument) == (0))
 {
   return (msg_port);
 }
    }
  return (0);
}

variable_types: size long

variable_types: struct t_cmbf { void *exinf; unsigned int mbfatr; int bufsz; int maxmsz; }


decompiled_code:
__int64 __fastcall regist_port(char *src, int a2)
{
unsigned int v2; // ebx
__int64 result; // rax
char v4[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v5[2]; // [rsp+10h] [rbp-78h] BYREF
unsigned int v6; // [rsp+20h] [rbp-68h]
char dest[44]; // [rsp+28h] [rbp-60h] BYREF
int v8; // [rsp+54h] [rbp-34h]
unsigned int v9[8]; // [rsp+68h] [rbp-20h] BYREF

v2 = get_port(8LL, 8LL);
result = 5LL;
if ( v2 )
{
v5[0] = 1LL;
v5[1] = 80LL;
v6 = v2;
strcpy(dest, src);
v8 = a2;
if ( (unsigned int)snd_mbf(11LL, 80LL, v5) )
{
del_mbf(v2);
result = 5LL;
}
else if ( (unsigned int)rcv_mbf(v9, v4, v2) )
{
del_mbf(v2);
result = 5LL;
}
else
{
del_mbf(v2);
result = v9[0];
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src, int a2)
{
unsigned int v2; // ebx
__int64 result; // rax
char v4[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v5[2]; // [rsp+10h] [rbp-78h] BYREF
unsigned int v6; // [rsp+20h] [rbp-68h]
char dest[44]; // [rsp+28h] [rbp-60h] BYREF
int v8; // [rsp+54h] [rbp-34h]
unsigned int v9[8]; // [rsp+68h] [rbp-20h] BYREF

v2 = get_port(8LL, 8LL);
result = 5LL;
if ( v2 )
{
v5[0] = 1LL;
v5[1] = 80LL;
v6 = v2;
strcpy(dest, src);
v8 = a2;
if ( (unsigned int)snd_mbf(11LL, 80LL, v5) )
{
del_mbf(v2);
result = 5LL;
}
else if ( (unsigned int)rcv_mbf(v9, v4, v2) )
{
del_mbf(v2);
result = 5LL;
}
else
{
del_mbf(v2);
result = v9[0];
}
}
return result;
}

original_code:
PORT_MANAGER_ERROR
regist_port (PORT_NAME *name, ID port)
{
  struct recv_port_message_t recv_msg;
  struct port_manager_msg_t send_msg;
  ID recv_port;
  W rsize;
  recv_port = get_port (sizeof (recv_msg), sizeof (recv_msg));
  if (recv_port == 0)
    {
      return (E_PORT_SYSTEM);
    }
  send_msg.hdr.type = 1;
  send_msg.hdr.size = sizeof (send_msg);
  send_msg.hdr.rport = recv_port;
  strcpy (&(send_msg.body.regist.name), name);
  send_msg.body.regist.port = port;
  if (snd_mbf ((11), sizeof (send_msg), &send_msg) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  if (rcv_mbf (&recv_msg, (VP)&rsize, recv_port) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  del_mbf (recv_port);
  return (recv_msg.error);
}

canonical_original_code:
enum port_manager_error_t regist_port(char (*name)[-1], int port)
{
  struct recv_port_message_t recv_msg;
  struct port_manager_msg_t send_msg;
  int recv_port;
  long rsize;
  recv_port = get_port (sizeof (recv_msg), sizeof (recv_msg));
  if (recv_port == 0)
    {
      return (E_PORT_SYSTEM);
    }
  send_msg.hdr.type = 1;
  send_msg.hdr.size = sizeof (send_msg);
  send_msg.hdr.rport = recv_port;
  strcpy (&(send_msg.body.regist.name), name);
  send_msg.body.regist.port = port;
  if (snd_mbf ((11), sizeof (send_msg), &send_msg) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  if (rcv_mbf (&recv_msg, (VP)&rsize, recv_port) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  del_mbf (recv_port);
  return (recv_msg.error);
}

variable_types:
name
char (*)[-1]

variable_types: port int

variable_types: struct recv_port_message_t { enum port_manager_error_t { E_PORT_OK=0, E_PORT_DUPLICATION=1, E_PORT_NOTFOUND=2, E_PORT_FULL=3, E_PORT_INVALID=4, E_PORT_SYSTEM=5 } error; int port; }

variable_types: struct port_manager_msg_t { struct port_message_header_t { long type; long size; int rport; } hdr; union port_message_body_t { struct regist_port_t { char name[-1]; int port; int task; } regist; struct unregist_port_t { char name[-1]; int task; } unregist; struct find_port_t { char name[-1]; } find; } body; }

variable_types: rsize long

user_defined_types: struct recv_port_message_t { enum port_manager_error_t error; int port; }


decompiled_code:
__int64 __fastcall unregist_port(char *src)
{
unsigned int v1; // ebx
__int64 result; // rax
char v3[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v4[2]; // [rsp+10h] [rbp-78h] BYREF
unsigned int v5; // [rsp+20h] [rbp-68h]
char dest[64]; // [rsp+28h] [rbp-60h] BYREF
unsigned int v7[8]; // [rsp+68h] [rbp-20h] BYREF

v1 = get_port(8LL, 8LL);
result = 5LL;
if ( v1 )
{
v4[0] = 2LL;
v4[1] = 80LL;
v5 = v1;
strcpy(dest, src);
if ( (unsigned int)snd_mbf(11LL, 80LL, v4) )
{
del_mbf(v1);
result = 5LL;
}
else if ( (unsigned int)rcv_mbf(v7, v3, v1) )
{
del_mbf(v1);
result = 5LL;
}
else
{
del_mbf(v1);
result = v7[0];
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src)
{
unsigned int v1; // ebx
__int64 result; // rax
char v3[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v4[2]; // [rsp+10h] [rbp-78h] BYREF
unsigned int v5; // [rsp+20h] [rbp-68h]
char dest[64]; // [rsp+28h] [rbp-60h] BYREF
unsigned int v7[8]; // [rsp+68h] [rbp-20h] BYREF

v1 = get_port(8LL, 8LL);
result = 5LL;
if ( v1 )
{
v4[0] = 2LL;
v4[1] = 80LL;
v5 = v1;
strcpy(dest, src);
if ( (unsigned int)snd_mbf(11LL, 80LL, v4) )
{
del_mbf(v1);
result = 5LL;
}
else if ( (unsigned int)rcv_mbf(v7, v3, v1) )
{
del_mbf(v1);
result = 5LL;
}
else
{
del_mbf(v1);
result = v7[0];
}
}
return result;
}

original_code:
PORT_MANAGER_ERROR
unregist_port (PORT_NAME *name)
{
  struct recv_port_message_t recv_msg;
  struct port_manager_msg_t send_msg;
  ID recv_port;
  W rsize;
  recv_port = get_port (sizeof (recv_msg), sizeof (recv_msg));
  if (recv_port == 0)
    {
      return (E_PORT_SYSTEM);
    }
  send_msg.hdr.type = 2;
  send_msg.hdr.size = sizeof (send_msg);
  send_msg.hdr.rport = recv_port;
  strcpy (&(send_msg.body.regist.name), name);
  if (snd_mbf ((11), sizeof (send_msg), &send_msg) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  if (rcv_mbf (&recv_msg, (VP)&rsize, recv_port) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  del_mbf (recv_port);
  return (recv_msg.error);
}

canonical_original_code:
enum port_manager_error_t unregist_port(char (*name)[-1])
{
  struct recv_port_message_t recv_msg;
  struct port_manager_msg_t send_msg;
  int recv_port;
  long rsize;
  recv_port = get_port (sizeof (recv_msg), sizeof (recv_msg));
  if (recv_port == 0)
    {
      return (E_PORT_SYSTEM);
    }
  send_msg.hdr.type = 2;
  send_msg.hdr.size = sizeof (send_msg);
  send_msg.hdr.rport = recv_port;
  strcpy (&(send_msg.body.regist.name), name);
  if (snd_mbf ((11), sizeof (send_msg), &send_msg) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  if (rcv_mbf (&recv_msg, (VP)&rsize, recv_port) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  del_mbf (recv_port);
  return (recv_msg.error);
}

return_type: enum port_manager_error_t { E_PORT_OK=0, E_PORT_DUPLICATION=1, E_PORT_NOTFOUND=2, E_PORT_FULL=3, E_PORT_INVALID=4, E_PORT_SYSTEM=5 }


decompiled_code:
__int64 __fastcall find_port(char *src, _DWORD *a2)
{
unsigned int v2; // ebx
__int64 result; // rax
char v4[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v5[2]; // [rsp+10h] [rbp-78h] BYREF
unsigned int v6; // [rsp+20h] [rbp-68h]
char dest[64]; // [rsp+28h] [rbp-60h] BYREF
int v8[8]; // [rsp+68h] [rbp-20h] BYREF

v2 = get_port(8LL, 8LL);
result = 5LL;
if ( v2 )
{
v5[0] = 3LL;
v5[1] = 80LL;
v6 = v2;
strcpy(dest, src);
if ( (unsigned int)snd_mbf(11LL, 80LL, v5) )
{
del_mbf(v2);
result = 5LL;
}
else if ( (unsigned int)rcv_mbf(v8, v4, v2) )
{
del_mbf(v2);
result = 5LL;
}
else
{
*a2 = v8[1];
del_mbf(v2);
result = (unsigned int)v8[0];
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, _DWORD *a2)
{
unsigned int v2; // ebx
__int64 result; // rax
char v4[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v5[2]; // [rsp+10h] [rbp-78h] BYREF
unsigned int v6; // [rsp+20h] [rbp-68h]
char dest[64]; // [rsp+28h] [rbp-60h] BYREF
int v8[8]; // [rsp+68h] [rbp-20h] BYREF

v2 = get_port(8LL, 8LL);
result = 5LL;
if ( v2 )
{
v5[0] = 3LL;
v5[1] = 80LL;
v6 = v2;
strcpy(dest, src);
if ( (unsigned int)snd_mbf(11LL, 80LL, v5) )
{
del_mbf(v2);
result = 5LL;
}
else if ( (unsigned int)rcv_mbf(v8, v4, v2) )
{
del_mbf(v2);
result = 5LL;
}
else
{
*a2 = v8[1];
del_mbf(v2);
result = (unsigned int)v8[0];
}
}
return result;
}

original_code:
PORT_MANAGER_ERROR
find_port (B *name, ID *rport)
{
  struct recv_port_message_t recv_msg;
  struct port_manager_msg_t send_msg;
  ID recv_port;
  W rsize;
  recv_port = get_port (sizeof (recv_msg), sizeof (recv_msg));
  if (recv_port == 0)
    {
      return (E_PORT_SYSTEM);
    }
  send_msg.hdr.type = 3;
  send_msg.hdr.size = sizeof (send_msg);
  send_msg.hdr.rport = recv_port;
  strcpy (send_msg.body.find.name, name);
  if (snd_mbf ((11), sizeof (send_msg), &send_msg) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  if (rcv_mbf (&recv_msg, (INT *)&rsize, recv_port) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  *rport = recv_msg.port;
  del_mbf (recv_port);
  return (recv_msg.error);
}

canonical_original_code:
enum port_manager_error_t find_port(char *name, int *rport)
{
  struct recv_port_message_t recv_msg;
  struct port_manager_msg_t send_msg;
  int recv_port;
  long rsize;
  recv_port = get_port (sizeof (recv_msg), sizeof (recv_msg));
  if (recv_port == 0)
    {
      return (E_PORT_SYSTEM);
    }
  send_msg.hdr.type = 3;
  send_msg.hdr.size = sizeof (send_msg);
  send_msg.hdr.rport = recv_port;
  strcpy (send_msg.body.find.name, name);
  if (snd_mbf ((11), sizeof (send_msg), &send_msg) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  if (rcv_mbf (&recv_msg, (int *)&rsize, recv_port) != (0))
    {
      del_mbf (recv_port);
      return (E_PORT_SYSTEM);
    }
  *rport = recv_msg.port;
  del_mbf (recv_port);
  return (recv_msg.error);
}

variable_types:
name
char *

variable_types:
rport
int *

user_defined_types: enum port_manager_error_t { E_PORT_OK=0, E_PORT_DUPLICATION=1, E_PORT_NOTFOUND=2, E_PORT_FULL=3, E_PORT_INVALID=4, E_PORT_SYSTEM=5 }


pause

decompiled_code:
__int64 pause()
{
return call_lowlib(52LL);
}

canonical_decompiled_code:
__int64 func0()
{
return call_lowlib(52LL);
}

original_code:
int
pause (void)
{
  return (call_lowlib (52));
}

canonical_original_code:
int pause()
{
  return (call_lowlib (52));
}


sigismember

decompiled_code:
__int64 __fastcall sigismember(__int64 a1, unsigned int a2)
{
return call_lowlib(62LL, a1, a2);
}

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

original_code:
int
sigismember (sigset_t *set, int signo)
{
  return (call_lowlib (62, set, signo));
}

canonical_original_code:
int sigismember(int *set, int signo)
{
  return (call_lowlib (62, set, signo));
}

variable_types:
set
int *

variable_types: signo int


mkfifo

decompiled_code:
__int64 __fastcall mkfifo(const char *a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = strlen(a1);
return call_lowlib(74LL, v2, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = strlen(a1);
return call_lowlib(74LL, v2, a1, a2);
}

original_code:
int
mkfifo (char *path, int mode)
{
  return (call_lowlib (74, strlen (path), path, mode));
}

canonical_original_code:
int mkfifo(char *path, int mode)
{
  return (call_lowlib (74, strlen (path), path, mode));
}

variable_types:
path
char *

variable_types: mode int


fcntl

decompiled_code:
void fcntl()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
fcntl (int fileid, int cmd, void *arg)
{
  return (call_lowlib (10, fileid, cmd, arg));
}

canonical_original_code:
int fcntl(int fileid, int cmd, void *arg)
{
  return (call_lowlib (10, fileid, cmd, arg));
}

variable_types: fileid int

variable_types: cmd int

variable_types:
arg
void *


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

v0 = inb(0x61u);
outb(0x61u, (char)(v0 | 3));
return 0LL;
}

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

v0 = inb(0x61u);
outb(0x61u, (char)(v0 | 3));
return 0LL;
}

original_code:
ER
open_beep (ID caller, DDEV_OPN_REQ *packet)
{
  B bPortData;
  bPortData = inb(0x61);
  bPortData |= 3;
  outb(0x61, bPortData);
  return ((0));
}

canonical_original_code:
int open_beep(int caller, struct DDEV_OPN_REQ *packet)
{
  char bPortData;
  bPortData = inb(0x61);
  bPortData |= 3;
  outb(0x61, bPortData);
  return ((0));
}

variable_types: caller int

variable_types:
packet
struct DDEV_OPN_REQ { long dd; } *

variable_types: bPortData char


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

v0 = inb(0x61u);
outb(0x61u, (char)(v0 & 0xFC));
return 0LL;
}

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

v0 = inb(0x61u);
outb(0x61u, (char)(v0 & 0xFC));
return 0LL;
}

original_code:
ER
close_beep (ID caller, DDEV_CLS_REQ *packet)
{
  B bPortData;
  bPortData = inb(0x61);
  bPortData &= 0xFC;
  outb(0x61, bPortData);
  return ((0));
}

canonical_original_code:
int close_beep(int caller, struct DDEV_CLS_REQ *packet)
{
  char bPortData;
  bPortData = inb(0x61);
  bPortData &= 0xFC;
  outb(0x61, bPortData);
  return ((0));
}

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


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

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

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

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

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

canonical_original_code:
int control_beep(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("beep: cannot make receive porrt.\n");
slp_tsk();
}
return regist_port("driver.beep", (unsigned int)recvport);
}

canonical_decompiled_code:
__int64 func0()
{
init_log();
recvport = get_port(1096LL, 1096LL);
if ( recvport <= 0 )
{
dbg_printf("beep: cannot make receive porrt.\n");
slp_tsk();
}
return regist_port("driver.beep", (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 ("beep: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.beep", 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 ("beep: cannot make receive porrt.\n");
      slp_tsk ();
    }
  error = regist_port ("driver.beep", recvport);
  if (error != (0))
    {
    }
}

variable_types: i int

variable_types: error int


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

result = *((_QWORD *)a1 + 1);
if ( !result )
return open_beep(*a1, a1 + 8);
if ( result == 1 )
result = close_beep(*a1, a1 + 8);
return result;
}

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

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

original_code:
ER
process_request (DDEV_REQ *req)
{
  switch (req->header.msgtyp)
    {
    case DEV_OPN:
      open_beep (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_beep (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_beep (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_beep (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_beep (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_beep (req->header.mbfid, &(req->body.opn_req));
      break;
    case DEV_CLS:
      close_beep (req->header.mbfid, &(req->body.cls_req));
      break;
    case DEV_REA:
      read_beep (req->header.mbfid, &(req->body.rea_req));
      break;
    case DEV_WRI:
      write_beep (req->header.mbfid, &(req->body.wri_req));
      break;
    case DEV_CTL:
      control_beep (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; } *

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


decompiled_code:
void __noreturn main_loop()
{
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 func4()
{
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
func3(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()
{
init_driver();
printf("beep driver started.\n");
main_loop();
}

canonical_decompiled_code:
void __noreturn func5()
{
func0();
printf("beep driver started.\n");
func4();
}

original_code:
void
start ()
{
  init_driver ();
  printf ("beep driver started.\n");
  main_loop ();
}

canonical_original_code:
void start()
{
  init_driver ();
  printf ("beep driver started.\n");
  main_loop ();
}


noaction

decompiled_code:
__int64 noaction()
{
return call_lowlib(0LL);
}

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

original_code:
int
noaction ()
{
  return (call_lowlib (0));
}

canonical_original_code:
int noaction()
{
  return (call_lowlib (0));
}


decompiled_code:
__int64 __fastcall psys_getlogin(__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]

v6 = *a1;
v7 = a1[1];
if ( (unsigned int)make_connection(73LL, 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]

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

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

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

variable_types:
argp
void *

variable_types:
args
struct a {  } *


decompiled_code:
__int64 __fastcall read_line(FILE *stream, __int64 a2, __int64 a3)
{
__int64 i; // rbp
__int64 v5; // rax
char v6; // bl

if ( a3 <= 0 )
{
i = 0LL;
}
else
{
for ( i = 0LL; i != a3; ++i )
{
LODWORD(v5) = getc(stream);
v6 = v5;
if ( v5 == 13 || v5 == 10 )
break;
if ( isprint(v5) )
*(_BYTE *)(a2 + i) = v6;
}
}
*(_BYTE *)(a2 + i) = 0;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(FILE *stream, __int64 a2, __int64 a3)
{
__int64 i; // rbp
__int64 v5; // rax
char v6; // bl

if ( a3 <= 0 )
{
i = 0LL;
}
else
{
for ( i = 0LL; i != a3; ++i )
{
LODWORD(v5) = getc(stream);
v6 = v5;
if ( v5 == 13 || v5 == 10 )
break;
if ( isprint(v5) )
*(_BYTE *)(a2 + i) = v6;
}
}
*(_BYTE *)(a2 + i) = 0;
return i;
}

original_code:
W
read_line (FILE *port, B *line, W length)
{
  W i;
  W ch;
  for (i = 0; i < length; i++)
    {
      ch = getc (port);
      if ((ch == ('m' & 0x1f)) || (ch == ('j' & 0x1f)))
 break;
      if (isprint (ch))
 {
   line[i] = ch;
 }
    }
  line[i] = '\0';
  return (i);
}

canonical_original_code:
long read_line(struct file *port, char *line, long length)
{
  long i;
  long ch;
  for (i = 0; i < length; i++)
    {
      ch = getc (port);
      if ((ch == ('m' & 0x1f)) || (ch == ('j' & 0x1f)))
 break;
      if (isprint (ch))
 {
   line[i] = ch;
 }
    }
  line[i] = '\0';
  return (i);
}

variable_types: struct file { int device; long count; long length; long bufsize; unsigned char buf[1024]; } *

variable_types:
line
char *

variable_types: length long

variable_types: i long

variable_types: ch long

return_type: long


banner

decompiled_code:
int banner()
{
printf("BTRON OS Initialize program (powered by Mitten Scripting Language).\n");
return printf("Version %d.%d\n", 0LL, 2LL);
}

canonical_decompiled_code:
int func0()
{
printf("BTRON OS Initialize program (powered by Mitten Scripting Language).\n");
return printf("Version %d.%d\n", 0LL, 2LL);
}

original_code:
void
banner (void)
{
  printf ("BTRON OS Initialize program (powered by Mitten Scripting Language).\n");
  printf ("Version %d.%d\n", 0, 2);
}

canonical_original_code:
void banner()
{
  printf ("BTRON OS Initialize program (powered by Mitten Scripting Language).\n");
  printf ("Version %d.%d\n", 0, 2);
}


original_code:
W read_line_edit(B *line, W length)
{
  W i;
  W ch;
  for (i = 0; i < length-1;) {
    ch = getc((&__file_table__[0]));
    if ((ch == ('m' & 0x1f)) || (ch == ('j' & 0x1f))) break;
    else if (ch == 0x0b) {
      if (i > 0) {
        --i; line[i] = 0;
        printf("\b");
      }
    }
    else if (isprint (ch)) {
        line[i++] = ch;
    }
  }
  line[i] = '\0';
  return (i);
}

canonical_original_code:
long read_line_edit(char *line, long length)
{
  long i;
  long ch;
  for (i = 0; i < length-1;) {
    ch = getc((&__file_table__[0]));
    if ((ch == ('m' & 0x1f)) || (ch == ('j' & 0x1f))) break;
    else if (ch == 0x0b) {
      if (i > 0) {
        --i; line[i] = 0;
        printf("\b");
      }
    }
    else if (isprint (ch)) {
        line[i++] = ch;
    }
  }
  line[i] = '\0';
  return (i);
}


decompiled_code:
void __noreturn main_loop()
{
eval("(lowlib.posix) load");
while ( 1 )
{
do
{
eval("(init>) ==");
read_line_edit((__int64)&line_0, 100LL);
}
while ( !line_0 );
eval(&line_0);
MitnStack_GarbageCollect();
}
}

canonical_decompiled_code:
void __noreturn func3()
{
eval("(lowlib.posix) load");
while ( 1 )
{
do
{
eval("(init>) ==");
func2((__int64)&line_0, 100LL);
}
while ( !line_0 );
eval(&line_0);
MitnStack_GarbageCollect();
}
}

original_code:
void main_loop ()
{
  static B line[100];
  eval ("(lowlib.posix) load");
  for (;;)
    {
      eval ("(init>) ==");
      read_line_edit (line, sizeof (line));
      if (*line != '\0')
 {
   eval (line);
   MitnStack_GarbageCollect ();
 }
    }
}

canonical_original_code:
void main_loop()
{
  static char line[100];
  eval ("(lowlib.posix) load");
  for (;;)
    {
      eval ("(init>) ==");
      read_line_edit (line, sizeof (line));
      if (*line != '\0')
 {
   eval (line);
   MitnStack_GarbageCollect ();
 }
    }
}

variable_types:
line
char [100]


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

init_device(argc, argv, envp);
MitnStack_Init();
InitMittenHook();
banner();
if ( !(unsigned int)vsys_inf(1LL, 0LL, &v3) && v3 != 0xFFFFFFFFLL )
{
posix_init(v3);
LABEL_4:
main_loop();
}
while ( 1 )
{
printf("Root file system is... [fd]/hd: ");
read_line_edit((__int64)&line_1, 100LL);
if ( line_1 )
{
if ( !strcmp(&line_1, "fd") )
{
if ( !(unsigned int)posix_init(0x80000000LL) )
goto LABEL_4;
}
else if ( !strcmp(&line_1, "hd") && !(unsigned int)posix_init(2147549186LL) )
{
goto LABEL_4;
}
}
else if ( !(unsigned int)posix_init(0x80000000LL) )
{
goto LABEL_4;
}
printf("Error on boot. retry...\n");
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

init_device(argc, argv, envp);
MitnStack_Init();
InitMittenHook();
func0();
if ( !(unsigned int)vsys_inf(1LL, 0LL, &v3) && v3 != 0xFFFFFFFFLL )
{
posix_init(v3);
LABEL_4:
func3();
}
while ( 1 )
{
printf("Root file system is... [fd]/hd: ");
func2((__int64)&line_1, 100LL);
if ( line_1 )
{
if ( !strcmp(&line_1, "fd") )
{
if ( !(unsigned int)posix_init(0x80000000LL) )
goto LABEL_4;
}
else if ( !strcmp(&line_1, "hd") && !(unsigned int)posix_init(2147549186LL) )
{
goto LABEL_4;
}
}
else if ( !(unsigned int)posix_init(0x80000000LL) )
{
goto LABEL_4;
}
printf("Error on boot. retry...\n");
}
}

original_code:
W main (W ac, B **av)
{
  static B line[100];
  UW rootfs;
  ER errno;
  init_device ();
  MitnStack_Init ();
  InitMittenHook ();
  banner ();
  errno = vsys_inf (1, 0, &rootfs);
  if ((errno == (0)) && (rootfs != 0xffffffff))
    {
      errno = posix_init (rootfs);
    }
  else
    {
      for (;;)
 {
   printf ("Root file system is... [fd]/hd: ");
   read_line_edit (line, sizeof (line));
   if (*line == '\0')
     {
       if (posix_init (0x80000000) == (0))
  break;
     }
   else if (strcmp (line, "fd") == 0)
     {
       if (posix_init (0x80000000) == (0))
  break;
     }
   else if (strcmp (line, "hd") == 0)
     {
       if (posix_init (0x80010002) == (0))
  break;
     }
   printf ("Error on boot. retry...\n");
 }
    }
  main_loop ();
}

canonical_original_code:
long main(long ac, char **av)
{
  static char line[100];
  unsigned long rootfs;
  int errno;
  init_device ();
  MitnStack_Init ();
  InitMittenHook ();
  banner ();
  errno = vsys_inf (1, 0, &rootfs);
  if ((errno == (0)) && (rootfs != 0xffffffff))
    {
      errno = posix_init (rootfs);
    }
  else
    {
      for (;;)
 {
   printf ("Root file system is... [fd]/hd: ");
   read_line_edit (line, sizeof (line));
   if (*line == '\0')
     {
       if (posix_init (0x80000000) == (0))
  break;
     }
   else if (strcmp (line, "fd") == 0)
     {
       if (posix_init (0x80000000) == (0))
  break;
     }
   else if (strcmp (line, "hd") == 0)
     {
       if (posix_init (0x80010002) == (0))
  break;
     }
   printf ("Error on boot. retry...\n");
 }
    }
  main_loop ();
}

variable_types: ac long

variable_types:
av
char **

variable_types:
rootfs
unsigned long

variable_types: errno int


decompiled_code:
__int64 __fastcall psys_sigaction(__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
int v6; // [rsp+60h] [rbp-68h]
__int64 v7; // [rsp+68h] [rbp-60h]
__int64 v8; // [rsp+70h] [rbp-58h]

v6 = *(_DWORD *)a1;
v7 = *(_QWORD *)(a1 + 8);
v8 = *(_QWORD *)(a1 + 16);
if ( (unsigned int)make_connection(53LL, 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
int v6; // [rsp+60h] [rbp-68h]
__int64 v7; // [rsp+68h] [rbp-60h]
__int64 v8; // [rsp+70h] [rbp-58h]

v6 = *(_DWORD *)a1;
v7 = *(_QWORD *)(a1 + 8);
v8 = *(_QWORD *)(a1 + 16);
if ( (unsigned int)make_connection(53LL, v5, &v2) || !v3 )
return v4;
MEMORY[0x7FFF0028] = v3;
return 0xFFFFFFFFLL;
}

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

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


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

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

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

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


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

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

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


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

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

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


decompiled_code:
void *__fastcall read_minix_efile(const char *a1, _DWORD *a2)
{
int v2; // eax
int v3; // ebx
void *v4; // rbp
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
perror("open");
exit(1);
}
v3 = v2;
if ( (int)fstat(v2, &v6) < 0 )
{
perror("fstat");
exit(1);
}
v4 = malloc(v6.st_size);
if ( !v4 )
{
perror("malloc");
exit(1);
}
if ( lseek(v3, 32LL, 0) < 0 )
{
perror("lseek");
exit(1);
}
if ( read(v3, v4, v6.st_size - 32) < 0 )
{
perror("read");
exit(1);
}
*a2 = LODWORD(v6.st_size) - 32;
return v4;
}

canonical_decompiled_code:
void *__fastcall func7(const char *a1, _DWORD *a2)
{
int v2; // eax
int v3; // ebx
void *v4; // rbp
struct stat v6; // [rsp+0h] [rbp-A8h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
perror("open");
exit(1);
}
v3 = v2;
if ( (int)func14(v2, &v6) < 0 )
{
perror("fstat");
exit(1);
}
v4 = malloc(v6.st_size);
if ( !v4 )
{
perror("malloc");
exit(1);
}
if ( lseek(v3, 32LL, 0) < 0 )
{
perror("lseek");
exit(1);
}
if ( read(v3, v4, v6.st_size - 32) < 0 )
{
perror("read");
exit(1);
}
*a2 = LODWORD(v6.st_size) - 32;
return v4;
}

original_code:
void *
read_minix_efile (char *fname, int *size)
{
  int fd;
  void *buf;
  struct stat st;
  fd = open (fname, 00);
  if (fd < 0)
    {
      perror ("open");
      exit (1);
    }
  if (fstat (fd, &st) < 0)
    {
      perror ("fstat");
      exit (1);
    }
  buf = malloc (st.st_size);
  if (buf == ((void *)0))
    {
      perror ("malloc");
      exit (1);
    }
  if (lseek (fd, 32, 0) < 0)
    {
      perror ("lseek");
      exit (1);
    }
  if (read (fd, buf, st.st_size - 32) < 0)
    {
      perror ("read");
      exit (1);
    }
  *size = st.st_size - 32;
  return (buf);
}

canonical_original_code:
void *read_minix_efile(char *fname, int *size)
{
  int fd;
  void *buf;
  struct stat st;
  fd = open (fname, 00);
  if (fd < 0)
    {
      perror ("open");
      exit (1);
    }
  if (fstat (fd, &st) < 0)
    {
      perror ("fstat");
      exit (1);
    }
  buf = malloc (st.st_size);
  if (buf == ((void *)0))
    {
      perror ("malloc");
      exit (1);
    }
  if (lseek (fd, 32, 0) < 0)
    {
      perror ("lseek");
      exit (1);
    }
  if (read (fd, buf, st.st_size - 32) < 0)
    {
      perror ("read");
      exit (1);
    }
  *size = st.st_size - 32;
  return (buf);
}

variable_types:
fname
char *

variable_types:
size
int *

variable_types: fd int

variable_types:
buf
void *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

return_type: void *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void *__fastcall read_elf_pheader(int fd, __int64 a2, _DWORD *a3)
{
void *v4; // rbp

v4 = malloc(*(unsigned __int16 *)(a2 + 68) * *(unsigned __int16 *)(a2 + 66));
lseek(fd, *(_QWORD *)(a2 + 40), 0);
if ( read(fd, v4, *(unsigned __int16 *)(a2 + 68) * *(unsigned __int16 *)(a2 + 66)) < 0 )
{
perror("read");
free(v4);
exit(0);
}
*a3 = *(unsigned __int16 *)(a2 + 68);
return v4;
}

canonical_decompiled_code:
void *__fastcall func9(int fd, __int64 a2, _DWORD *a3)
{
void *v4; // rbp

v4 = malloc(*(unsigned __int16 *)(a2 + 68) * *(unsigned __int16 *)(a2 + 66));
lseek(fd, *(_QWORD *)(a2 + 40), 0);
if ( read(fd, v4, *(unsigned __int16 *)(a2 + 68) * *(unsigned __int16 *)(a2 + 66)) < 0 )
{
perror("read");
free(v4);
exit(0);
}
*a3 = *(unsigned __int16 *)(a2 + 68);
return v4;
}

original_code:
struct Pheader *
read_elf_pheader (int fd, struct ELFheader *elfh, int *ent)
{
  struct Pheader *phbuf;
  phbuf = (struct Pheader *)malloc (elfh->e_phentsize * elfh->e_phnum);
  lseek (fd, elfh->e_phoff, 0);
  if (read (fd, phbuf, elfh->e_phentsize * elfh->e_phnum) < 0)
    {
      perror ("read");
      free (phbuf);
      exit (0);
    }
  *ent = elfh->e_phnum;
  return (phbuf);
}

canonical_original_code:
struct Pheader *read_elf_pheader(int fd, struct ELFheader *elfh, int *ent)
{
  struct Pheader *phbuf;
  phbuf = (struct Pheader *)malloc (elfh->e_phentsize * elfh->e_phnum);
  lseek (fd, elfh->e_phoff, 0);
  if (read (fd, phbuf, elfh->e_phentsize * elfh->e_phnum) < 0)
    {
      perror ("read");
      free (phbuf);
      exit (0);
    }
  *ent = elfh->e_phnum;
  return (phbuf);
}

variable_types: struct ELFheader { unsigned char e_ident[16]; unsigned short e_type; unsigned short e_machine; unsigned long e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned long e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *

variable_types:
ent
int *

variable_types: struct Pheader { unsigned long p_type; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_flags; unsigned long p_align; } *


decompiled_code:
void *__fastcall read_elf_efile(const char *a1, _DWORD *a2, __int64 a3, __int64 a4, _QWORD *a5)
{
int v7; // eax
int v8; // er13
char *v9; // rax
char *v10; // r15
char *v11; // rbp
int v12; // ebx
char *v13; // rbx
void *v14; // rbp
void *ptr; // [rsp+8h] [rbp-60h]
int v18[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v7 = open(a1, 0);
if ( v7 < 0 )
{
perror("open");
exit(1);
}
v8 = v7;
ptr = read_elf_header(v7);
if ( !ptr )
{
close(v8);
fwrite("Cannot read elf file.\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
v9 = (char *)read_elf_pheader(v8, (__int64)ptr, v18);
v10 = v9;
if ( !v9 )
{
free(ptr);
close(v8);
fwrite("Cannot read exec header.\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v11 = v9;
v12 = 0;
if ( v18[0] <= 0 )
goto LABEL_5;
while ( 1 )
{
fprintf(
stderr,
"ph[%d].p_type = 0x%x, ph[%d].p_flags = 0x%x\n",
(unsigned int)v12,
*(_QWORD *)v11,
(unsigned int)v12,
*((_QWORD *)v11 + 6));
if ( *(_QWORD *)v11 == a3 && (*((_QWORD *)v11 + 6) & a4) != 0 )
break;
++v12;
v11 += 64;
if ( v18[0] <= v12 )
goto LABEL_5;
}
if ( v18[0] <= v12 )
{
LABEL_5:
free(v10);
free(ptr);
fwrite("Not found program header\n", 1uLL, 0x19uLL, stderr);
close(v8);
exit(1);
}
v13 = &v10[64 * (__int64)v12];
fprintf(
stderr,
"ELF: type = 0x%x, flag = 0x%x, vaddr = 0x%x, mem size = %d, file size = %d\n",
*(_QWORD *)v13,
*((_QWORD *)v13 + 6),
*((_QWORD *)v13 + 2),
*((_QWORD *)v13 + 5),
*((_QWORD *)v13 + 4));
*a2 = *((_QWORD *)v13 + 5);
*a5 = *((_QWORD *)v13 + 2);
v14 = calloc(*((_QWORD *)v13 + 5), 1uLL);
if ( !v14 )
{
free(v10);
free(ptr);
close(v8);
perror("malloc");
exit(1);
}
if ( lseek(v8, *((_QWORD *)v13 + 1), 0) < 0 )
{
free(v10);
free(ptr);
close(v8);
perror("lseek");
exit(1);
}
if ( read(v8, v14, *((_QWORD *)v13 + 4)) < 0 )
{
free(v10);
free(ptr);
close(v8);
perror("read");
exit(1);
}
free(v10);
free(ptr);
close(v8);
return v14;
}

canonical_decompiled_code:
void *__fastcall func10(const char *a1, _DWORD *a2, __int64 a3, __int64 a4, _QWORD *a5)
{
int v7; // eax
int v8; // er13
char *v9; // rax
char *v10; // r15
char *v11; // rbp
int v12; // ebx
char *v13; // rbx
void *v14; // rbp
void *ptr; // [rsp+8h] [rbp-60h]
int v18[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v7 = open(a1, 0);
if ( v7 < 0 )
{
perror("open");
exit(1);
}
v8 = v7;
ptr = func8(v7);
if ( !ptr )
{
close(v8);
fwrite("Cannot read elf file.\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
v9 = (char *)func9(v8, (__int64)ptr, v18);
v10 = v9;
if ( !v9 )
{
free(ptr);
close(v8);
fwrite("Cannot read exec header.\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v11 = v9;
v12 = 0;
if ( v18[0] <= 0 )
goto LABEL_5;
while ( 1 )
{
fprintf(
stderr,
"ph[%d].p_type = 0x%x, ph[%d].p_flags = 0x%x\n",
(unsigned int)v12,
*(_QWORD *)v11,
(unsigned int)v12,
*((_QWORD *)v11 + 6));
if ( *(_QWORD *)v11 == a3 && (*((_QWORD *)v11 + 6) & a4) != 0 )
break;
++v12;
v11 += 64;
if ( v18[0] <= v12 )
goto LABEL_5;
}
if ( v18[0] <= v12 )
{
LABEL_5:
free(v10);
free(ptr);
fwrite("Not found program header\n", 1uLL, 0x19uLL, stderr);
close(v8);
exit(1);
}
v13 = &v10[64 * (__int64)v12];
fprintf(
stderr,
"ELF: type = 0x%x, flag = 0x%x, vaddr = 0x%x, mem size = %d, file size = %d\n",
*(_QWORD *)v13,
*((_QWORD *)v13 + 6),
*((_QWORD *)v13 + 2),
*((_QWORD *)v13 + 5),
*((_QWORD *)v13 + 4));
*a2 = *((_QWORD *)v13 + 5);
*a5 = *((_QWORD *)v13 + 2);
v14 = calloc(*((_QWORD *)v13 + 5), 1uLL);
if ( !v14 )
{
free(v10);
free(ptr);
close(v8);
perror("malloc");
exit(1);
}
if ( lseek(v8, *((_QWORD *)v13 + 1), 0) < 0 )
{
free(v10);
free(ptr);
close(v8);
perror("lseek");
exit(1);
}
if ( read(v8, v14, *((_QWORD *)v13 + 4)) < 0 )
{
free(v10);
free(ptr);
close(v8);
perror("read");
exit(1);
}
free(v10);
free(ptr);
close(v8);
return v14;
}

original_code:
void *
read_elf_efile (char *fname, int *size, ELF32_Word type, ELF32_Word flag, ELF32_Addr *vaddr)
{
  struct ELFheader *elfhp;
  struct Pheader *ph;
  int ent;
  int i;
  int section_size;
  void *buf;
  int fd;
  fd = open (fname, 00);
  if (fd < 0)
    {
      perror ("open");
      exit (1);
    }
  elfhp = read_elf_header (fd);
  if (elfhp == ((void *)0))
    {
      close (fd);
      fprintf (stderr, "Cannot read elf file.\n");
      exit (1);
    }
  ph = read_elf_pheader (fd, elfhp, &ent);
  if (ph == ((void *)0))
    {
      free (elfhp);
      close (fd);
      fprintf (stderr, "Cannot read exec header.\n");
      exit (1);
    }
  for (i = 0; i < ent; i++)
    {
      fprintf (stderr, "ph[%d].p_type = 0x%x, ph[%d].p_flags = 0x%x\n",
        i, ph[i].p_type,
        i, ph[i].p_flags);
      if ((ph[i].p_type == type) && (ph[i].p_flags & flag))
 {
   break;
 }
    }
  if (i >= ent)
    {
      free (ph);
      free (elfhp);
      fprintf (stderr, "Not found program header\n");
      close (fd);
      exit (1);
    }
  fprintf (stderr, "ELF: type = 0x%x, flag = 0x%x, vaddr = 0x%x, mem size = %d, file size = %d\n",
    ph[i].p_type,
    ph[i].p_flags,
    ph[i].p_vaddr,
    ph[i].p_memsz,
    ph[i].p_filesz);
  *size = ph[i].p_memsz;
  *vaddr = ph[i].p_vaddr;
  buf = calloc (ph[i].p_memsz, 1);
  if (buf == ((void *)0))
    {
      free (ph);
      free (elfhp);
      close (fd);
      perror ("malloc");
      exit (1);
    }
  if (lseek (fd, ph[i].p_offset, 0) < 0)
    {
      free (ph);
      free (elfhp);
      close (fd);
      perror ("lseek");
      exit (1);
    }
  if (read (fd, buf, ph[i].p_filesz) < 0)
    {
      free (ph);
      free (elfhp);
      close (fd);
      perror ("read");
      exit (1);
    }
  free (ph);
  free (elfhp);
  close (fd);
  return (buf);
}

canonical_original_code:
void *read_elf_efile(char *fname, int *size, unsigned long type, unsigned long flag, unsigned long *vaddr)
{
  struct ELFheader *elfhp;
  struct Pheader *ph;
  int ent;
  int i;
  int section_size;
  void *buf;
  int fd;
  fd = open (fname, 00);
  if (fd < 0)
    {
      perror ("open");
      exit (1);
    }
  elfhp = read_elf_header (fd);
  if (elfhp == ((void *)0))
    {
      close (fd);
      fprintf (stderr, "Cannot read elf file.\n");
      exit (1);
    }
  ph = read_elf_pheader (fd, elfhp, &ent);
  if (ph == ((void *)0))
    {
      free (elfhp);
      close (fd);
      fprintf (stderr, "Cannot read exec header.\n");
      exit (1);
    }
  for (i = 0; i < ent; i++)
    {
      fprintf (stderr, "ph[%d].p_type = 0x%x, ph[%d].p_flags = 0x%x\n",
        i, ph[i].p_type,
        i, ph[i].p_flags);
      if ((ph[i].p_type == type) && (ph[i].p_flags & flag))
 {
   break;
 }
    }
  if (i >= ent)
    {
      free (ph);
      free (elfhp);
      fprintf (stderr, "Not found program header\n");
      close (fd);
      exit (1);
    }
  fprintf (stderr, "ELF: type = 0x%x, flag = 0x%x, vaddr = 0x%x, mem size = %d, file size = %d\n",
    ph[i].p_type,
    ph[i].p_flags,
    ph[i].p_vaddr,
    ph[i].p_memsz,
    ph[i].p_filesz);
  *size = ph[i].p_memsz;
  *vaddr = ph[i].p_vaddr;
  buf = calloc (ph[i].p_memsz, 1);
  if (buf == ((void *)0))
    {
      free (ph);
      free (elfhp);
      close (fd);
      perror ("malloc");
      exit (1);
    }
  if (lseek (fd, ph[i].p_offset, 0) < 0)
    {
      free (ph);
      free (elfhp);
      close (fd);
      perror ("lseek");
      exit (1);
    }
  if (read (fd, buf, ph[i].p_filesz) < 0)
    {
      free (ph);
      free (elfhp);
      close (fd);
      perror ("read");
      exit (1);
    }
  free (ph);
  free (elfhp);
  close (fd);
  return (buf);
}

variable_types:
type
unsigned long

variable_types:
flag
unsigned long

variable_types:
vaddr
unsigned long *

variable_types: ent int

variable_types: i int

user_defined_types: struct ELFheader { unsigned char e_ident[16]; unsigned short e_type; unsigned short e_machine; unsigned long e_version; unsigned long e_entry; unsigned long e_phoff; unsigned long e_shoff; unsigned long e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

user_defined_types: struct Pheader { unsigned long p_type; unsigned long p_offset; unsigned long p_vaddr; unsigned long p_paddr; unsigned long p_filesz; unsigned long p_memsz; unsigned long p_flags; unsigned long p_align; }


decompiled_code:
void __fastcall pad_write(int fd, unsigned int a2)
{
void *v2; // rax
void *v3; // rbp

fprintf(stderr, "pad_write: size = %d\n", a2);
v2 = calloc((int)a2, 1uLL);
if ( !v2 )
{
perror("malloc");
exit(1);
}
v3 = v2;
if ( write(fd, v2, (int)a2) < 0 )
{
perror("write");
exit(1);
}
free(v3);
}

canonical_decompiled_code:
void __fastcall func11(int fd, unsigned int a2)
{
void *v2; // rax
void *v3; // rbp

fprintf(stderr, "pad_write: size = %d\n", a2);
v2 = calloc((int)a2, 1uLL);
if ( !v2 )
{
perror("malloc");
exit(1);
}
v3 = v2;
if ( write(fd, v2, (int)a2) < 0 )
{
perror("write");
exit(1);
}
free(v3);
}

original_code:
void
pad_write (int outfd, int size)
{
  void *buf;
  fprintf (stderr, "pad_write: size = %d\n", size);
  buf = calloc (size, 1);
  if (buf == ((void *)0))
    {
      perror ("malloc");
      exit (1);
    }
  if (write (outfd, buf, size) < 0)
    {
      perror ("write");
      exit (1);
    }
  free (buf);
}

canonical_original_code:
void pad_write(int outfd, int size)
{
  void *buf;
  fprintf (stderr, "pad_write: size = %d\n", size);
  buf = calloc (size, 1);
  if (buf == ((void *)0))
    {
      perror ("malloc");
      exit (1);
    }
  if (write (outfd, buf, size) < 0)
    {
      perror ("write");
      exit (1);
    }
  free (buf);
}

variable_types: outfd int

variable_types: size int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
void *v4; // rbp
void *v5; // rax
void *v6; // rbp
void *v7; // rbp
int v8; // [rsp+4h] [rbp-34h] BYREF
unsigned int v9; // [rsp+8h] [rbp-30h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v11; // [rsp+10h] [rbp-28h] BYREF
__int64 v12[4]; // [rsp+18h] [rbp-20h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "usage: %s 16bit-boot 32bit-boot\n", *argv);
exit(0);
}
v3 = read_minix_efile(argv[1], &v8);
v4 = v3;
if ( v3 )
{
if ( write(1, v3, v8) >= 0 )
{
free(v4);
if ( (v8 & 0xFFF) != 0 )
pad_write(1, 4096 - v8 % 4096);
v5 = read_elf_efile(argv[2], &v10, 1LL, 5LL, v12);
v6 = v5;
if ( v5 )
{
if ( write(1, v5, (int)v10) >= 0 )
{
fprintf(stderr, "text section write vaddr = 0x%x, size = %d bytes\n", v12[0], v10);
free(v6);
v7 = read_elf_efile(argv[2], &v9, 1LL, 6LL, &v11);
if ( v7 )
{
pad_write(1, v11 - v10 - LODWORD(v12[0]));
fprintf(stderr, "pad write %d\n", v11 - v12[0] - (int)v10);
if ( write(1, v7, (int)v9) >= 0 )
{
fprintf(stderr, "data section write vaddr = 0x%x, size = %d bytes\n", v11, v9);
free(v7);
exit(0);
}
perror("write");
exit(0);
}
fprintf(stderr, "can't open %s for 32bit-mode boot\n", argv[2]);
exit(1);
}
perror("write");
exit(0);
}
fprintf(stderr, "can't open %s for 32bit-mode boot\n", argv[2]);
exit(1);
}
perror("write");
exit(0);
}
fprintf(stderr, "can't open %s for 16bit-mode boot\n", argv[1]);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
void *v4; // rbp
void *v5; // rax
void *v6; // rbp
void *v7; // rbp
int v8; // [rsp+4h] [rbp-34h] BYREF
unsigned int v9; // [rsp+8h] [rbp-30h] BYREF
unsigned int v10; // [rsp+Ch] [rbp-2Ch] BYREF
__int64 v11; // [rsp+10h] [rbp-28h] BYREF
__int64 v12[4]; // [rsp+18h] [rbp-20h] BYREF

if ( argc <= 2 )
{
fprintf(stderr, "usage: %s 16bit-boot 32bit-boot\n", *argv);
exit(0);
}
v3 = func7(argv[1], &v8);
v4 = v3;
if ( v3 )
{
if ( write(1, v3, v8) >= 0 )
{
free(v4);
if ( (v8 & 0xFFF) != 0 )
func11(1, 4096 - v8 % 4096);
v5 = func10(argv[2], &v10, 1LL, 5LL, v12);
v6 = v5;
if ( v5 )
{
if ( write(1, v5, (int)v10) >= 0 )
{
fprintf(stderr, "text section write vaddr = 0x%x, size = %d bytes\n", v12[0], v10);
free(v6);
v7 = func10(argv[2], &v9, 1LL, 6LL, &v11);
if ( v7 )
{
func11(1, v11 - v10 - LODWORD(v12[0]));
fprintf(stderr, "pad write %d\n", v11 - v12[0] - (int)v10);
if ( write(1, v7, (int)v9) >= 0 )
{
fprintf(stderr, "data section write vaddr = 0x%x, size = %d bytes\n", v11, v9);
free(v7);
exit(0);
}
perror("write");
exit(0);
}
fprintf(stderr, "can't open %s for 32bit-mode boot\n", argv[2]);
exit(1);
}
perror("write");
exit(0);
}
fprintf(stderr, "can't open %s for 32bit-mode boot\n", argv[2]);
exit(1);
}
perror("write");
exit(0);
}
fprintf(stderr, "can't open %s for 16bit-mode boot\n", argv[1]);
exit(1);
}

original_code:
int
main (int ac, char **av)
{
  int fd;
  void *buf;
  ELF32_Addr text_vaddr, data_vaddr;
  int text_size, data_size;
  int size;
  if (ac < 3)
    {
      fprintf (stderr, "usage: %s 16bit-boot 32bit-boot\n", av[0]);
      exit (0);
    }
  buf = read_minix_efile (av[1], &size);
  if (buf == ((void *)0))
    {
      fprintf (stderr, "can't open %s for 16bit-mode boot\n", av[1]);
      exit (1);
    }
  if (write (1, buf, size) < 0)
    {
      perror ("write");
      exit (0);
    }
  free (buf);
  if (size % 4096)
    {
      pad_write (1, 4096 - (size % 4096));
    }
  buf = read_elf_efile (av[2], &text_size, 1, 0x4 | 0x1, &text_vaddr);
  if (buf == ((void *)0))
    {
      fprintf (stderr, "can't open %s for 32bit-mode boot\n", av[2]);
      exit (1);
    }
  if (write (1, buf, text_size) < 0)
    {
      perror ("write");
      exit (0);
    }
  fprintf (stderr, "text section write vaddr = 0x%x, size = %d bytes\n",
    text_vaddr, text_size);
  free (buf);
  buf = read_elf_efile (av[2], &data_size, 1, 0x4 | 0x2, &data_vaddr);
  if (buf == ((void *)0))
    {
      fprintf (stderr, "can't open %s for 32bit-mode boot\n", av[2]);
      exit (1);
    }
  pad_write (1, (data_vaddr - text_vaddr) - text_size);
  fprintf (stderr, "pad write %d\n", (data_vaddr - text_vaddr) - text_size);
  if (write (1, buf, data_size) < 0)
    {
      perror ("write");
      exit (0);
    }
  fprintf (stderr, "data section write vaddr = 0x%x, size = %d bytes\n",
    data_vaddr, data_size);
  free (buf);
  exit (0);
}

canonical_original_code:
int main(int ac, char **av)
{
  int fd;
  void *buf;
  unsigned long text_vaddr; unsigned long data_vaddr;
  int text_size; int data_size;
  int size;
  if (ac < 3)
    {
      fprintf (stderr, "usage: %s 16bit-boot 32bit-boot\n", av[0]);
      exit (0);
    }
  buf = read_minix_efile (av[1], &size);
  if (buf == ((void *)0))
    {
      fprintf (stderr, "can't open %s for 16bit-mode boot\n", av[1]);
      exit (1);
    }
  if (write (1, buf, size) < 0)
    {
      perror ("write");
      exit (0);
    }
  free (buf);
  if (size % 4096)
    {
      pad_write (1, 4096 - (size % 4096));
    }
  buf = read_elf_efile (av[2], &text_size, 1, 0x4 | 0x1, &text_vaddr);
  if (buf == ((void *)0))
    {
      fprintf (stderr, "can't open %s for 32bit-mode boot\n", av[2]);
      exit (1);
    }
  if (write (1, buf, text_size) < 0)
    {
      perror ("write");
      exit (0);
    }
  fprintf (stderr, "text section write vaddr = 0x%x, size = %d bytes\n",
    text_vaddr, text_size);
  free (buf);
  buf = read_elf_efile (av[2], &data_size, 1, 0x4 | 0x2, &data_vaddr);
  if (buf == ((void *)0))
    {
      fprintf (stderr, "can't open %s for 32bit-mode boot\n", av[2]);
      exit (1);
    }
  pad_write (1, (data_vaddr - text_vaddr) - text_size);
  fprintf (stderr, "pad write %d\n", (data_vaddr - text_vaddr) - text_size);
  if (write (1, buf, data_size) < 0)
    {
      perror ("write");
      exit (0);
    }
  fprintf (stderr, "data section write vaddr = 0x%x, size = %d bytes\n",
    data_vaddr, data_size);
  free (buf);
  exit (0);
}

variable_types: ac int

variable_types:
av
char **


open

decompiled_code:
void open()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
open (char *path, int oflag, int mode)
{
  int pathLen;
  pathLen = strlen (path);
  return (call_lowlib (23, pathLen, path, oflag, mode));
}

canonical_original_code:
int open(char *path, int oflag, int mode)
{
  int pathLen;
  pathLen = strlen (path);
  return (call_lowlib (23, pathLen, path, oflag, mode));
}

variable_types:
path
char *

variable_types: oflag int

variable_types: mode int

variable_types: pathLen int


decompiled_code:
void init_ip()
{
;
}

original_code:
ER
init_ip ()
{
}

canonical_original_code:
int init_ip()
{
}


decompiled_code:
char **__fastcall get_fdspec(char *s1)
{
const char **v1; // rbx
__int64 v2; // r12
char **result; // rax

if ( fd_spec )
{
v1 = (const char **)&fd_spec;
v2 = 0LL;
while ( 1 )
{
dbg_printf("compare: <%s>, <%s>\n", s1);
if ( !strcmp(s1, *v1) )
break;
++v2;
v1 += 15;
if ( !*v1 )
goto LABEL_5;
}
result = &(&fd_spec)[15 * v2];
}
else
{
LABEL_5:
dbg_printf("fd: get_fdspec error.(name = %s)\n", s1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
char **__fastcall func0(char *s1)
{
const char **v1; // rbx
__int64 v2; // r12
char **result; // rax

if ( fd_spec )
{
v1 = (const char **)&fd_spec;
v2 = 0LL;
while ( 1 )
{
dbg_printf("compare: <%s>, <%s>\n", s1);
if ( !strcmp(s1, *v1) )
break;
++v2;
v1 += 15;
if ( !*v1 )
goto LABEL_5;
}
result = &(&fd_spec)[15 * v2];
}
else
{
LABEL_5:
dbg_printf("fd: get_fdspec error.(name = %s)\n", s1);
result = 0LL;
}
return result;
}

original_code:
struct spec *
get_fdspec (B *name)
{
  W i;
  for (i = 0; fd_spec[i].typename != (0); i++)
    {
      dbg_printf ("compare: <%s>, <%s>\n", name, fd_spec[i].typename);
      if (strcmp (name, (B *)(fd_spec[i].typename)) == 0)
 {
   return (&(fd_spec[i]));
 }
    }
  dbg_printf ("fd: get_fdspec error.(name = %s)\n", name);
  return ((0));
}

canonical_original_code:
struct spec *get_fdspec(char *name)
{
  long i;
  for (i = 0; fd_spec[i].typename != (0); i++)
    {
      dbg_printf ("compare: <%s>, <%s>\n", name, fd_spec[i].typename);
      if (strcmp (name, (char *)(fd_spec[i].typename)) == 0)
 {
   return (&(fd_spec[i]));
 }
    }
  dbg_printf ("fd: get_fdspec error.(name = %s)\n", name);
  return ((0));
}

variable_types:
name
char *

variable_types: i long

return_type: struct spec { char *typename; unsigned long head; unsigned long sector; unsigned long length; unsigned long dtl; unsigned long lencode; unsigned long gap3; unsigned long gapskip; unsigned long srt; unsigned long hut; unsigned long hlt; unsigned long nd; unsigned long dmachan; unsigned long retry; unsigned long motor; } *


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

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

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

variable_types:
argp
void *

variable_types:
args
struct a {  } *

return_type: unsigned long


sigprocmask

decompiled_code:
void sigprocmask()
{
;
}

original_code:
int
sigprocmask (int how, sigset_t *new, sigset_t *old)
{
  return (call_lowlib (55, how, new, old));
}

canonical_original_code:
int sigprocmask(int how, int *new, int *old)
{
  return (call_lowlib (55, how, new, old));
}

variable_types: how int

variable_types:
new
int *

variable_types:
old
int *


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

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

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


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

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

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


getcwd

decompiled_code:
__int64 __fastcall getcwd(const char *a1)
{
unsigned int v1; // eax

v1 = strlen(a1);
return call_lowlib(68LL, v1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
unsigned int v1; // eax

v1 = strlen(a1);
return call_lowlib(68LL, v1, a1);
}

original_code:
int
getcwd (char *pwd)
{
  return (call_lowlib (68, strlen (pwd), pwd));
}

canonical_original_code:
int getcwd(char *pwd)
{
  return (call_lowlib (68, strlen (pwd), pwd));
}

variable_types:
pwd
char *


decompiled_code:
__int64 __fastcall psys_dup(__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]

v6 = *a1;
if ( (unsigned int)make_connection(7LL, 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]

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

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

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


chown

decompiled_code:
__int64 __fastcall chown(const char *a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = strlen(a1);
return call_lowlib(4LL, v2, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = strlen(a1);
return call_lowlib(4LL, v2, a1, a2);
}

original_code:
int
chown (char *path, int owner)
{
  return (call_lowlib (4, strlen (path), path, owner));
}

canonical_original_code:
int chown(char *path, int owner)
{
  return (call_lowlib (4, strlen (path), path, owner));
}

variable_types: owner int


getenv

decompiled_code:
void getenv()
{
;
}

original_code:
int
getenv (void)
{
  return (call_lowlib (69));
}

canonical_original_code:
int getenv()
{
  return (call_lowlib (69));
}


decompiled_code:
__int64 __fastcall vget_csl(__int64 a1, __int64 a2)
{
return call_syscall(120LL, a1, a2);
}

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

original_code:
ER
vget_csl (W *x, W *y)
{
  return (call_syscall ((120), x, y));
}

canonical_original_code:
int vget_csl(long *x, long *y)
{
  return (call_syscall ((120), x, y));
}

variable_types:
x
long *

variable_types:
y
long *


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

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

original_code:
ER
vset_cns (ID driver)
{
  return (call_syscall ((121), driver));
}

canonical_original_code:
int vset_cns(int driver)
{
  return (call_syscall ((121), driver));
}

variable_types: driver int


decompiled_code:
__int64 __fastcall vsys_msc(__int64 a1, __int64 a2)
{
return call_syscall(122LL, a1, a2);
}

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

original_code:
ER
vsys_msc (W cmd, VP argp)
{
  return (call_syscall ((122), cmd, argp));
}

canonical_original_code:
int vsys_msc(long cmd, void *argp)
{
  return (call_syscall ((122), cmd, argp));
}

variable_types: cmd long


decompiled_code:
__int64 __fastcall vsys_inf(__int64 a1, __int64 a2)
{
return call_syscall(99LL, a1, a2);
}

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

original_code:
ER
vsys_inf (W func, W sub, VP argp)
{
  return (call_syscall ((99), func, sub, argp));
}

canonical_original_code:
int vsys_inf(long func, long sub, void *argp)
{
  return (call_syscall ((99), func, sub, argp));
}

variable_types: func long

variable_types: sub long


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

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

original_code:
ER
vcpy_stk (ID src, W esp, W ebp, ID dst)
{
  return (call_syscall ((123), src, esp, ebp, dst));
}

canonical_original_code:
int vcpy_stk(int src, long esp, long ebp, int dst)
{
  return (call_syscall ((123), src, esp, ebp, dst));
}

variable_types: src int

variable_types: esp long

variable_types: ebp long

variable_types: dst int


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

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

original_code:
ER
vset_ctx (ID tid, W eip)
{
  return (call_syscall ((124), tid, eip));
}

canonical_original_code:
int vset_ctx(int tid, long eip)
{
  return (call_syscall ((124), tid, eip));
}

variable_types: tid int

variable_types: eip long


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

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

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

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

variable_types:
argp
void *

variable_types:
args
struct a {  } *


setpgid

decompiled_code:
void setpgid()
{
;
}

original_code:
int
setpgid (int gid)
{
  return (call_lowlib (29, gid));
}

canonical_original_code:
int setpgid(int gid)
{
  return (call_lowlib (29, gid));
}

variable_types: gid int


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

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

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


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

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

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


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

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

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