decompiled_code:
__int64 __fastcall ide_read_module(unsigned int a1, int a2, int a3, __int64 a4)
{
unsigned __int64 v4; // rbp
__int64 v5; // r15
unsigned __int64 v6; // rax
unsigned __int64 v7; // rdx
int v8; // er14
__int64 v9; // rbx
__int64 v10; // rbx
__int64 v13; // [rsp+8h] [rbp-840h]
__int64 v14; // [rsp+10h] [rbp-838h] BYREF
__int64 v15; // [rsp+18h] [rbp-830h]
char src[1080]; // [rsp+410h] [rbp-438h] BYREF

LODWORD(v4) = *(_DWORD *)(a4 + 12);
v5 = a3;
ide_read(a1, a2, a3, (__int64)&v14, 1);
v6 = (unsigned __int16)v14 - 204LL;
if ( v6 > 0x3F || (v7 = 0x9800000000000001LL, !_bittest64((const __int64 *)&v7, v6)) )
{
boot_printf("This object is not exec format (%d).\n", (unsigned __int16)v14);
while ( 1 )
;
}
if ( (unsigned __int16)v14 != 267LL && (unsigned __int16)v14 != 264LL )
{
boot_printf("I am unknown a.out image.(0x%x)\n", (unsigned __int16)v14);
while ( 1 )
;
}
v13 = (unsigned int)v4;
v8 = a3 + 2;
if ( (((_DWORD)v15 + 4095) & 0xFFFFF000) > 0x1FF )
{
v4 = (unsigned int)v4;
v9 = 0LL;
do
{
boot_printf(".");
ide_read(a1, a2, v5 + v9 + 2, (__int64)src, 1);
bcopy(src, (void *)v4, 0x200uLL);
v8 = a3 + v9++ + 3;
v4 += 512LL;
}
while ( (((_DWORD)v15 + 4095) & 0xFFFFF000) >> 9 > (unsigned int)v9 );
}
v10 = 0LL;
do
{
boot_printf(".");
ide_read(a1, a2, v10 + v8, (__int64)src, 1);
bcopy(src, (void *)(v13 + (v10++ << 9) + (((_DWORD)v15 + 4095) & 0xFFFFF000)), 0x200uLL);
}
while ( ((HIDWORD(v15) + 4095) & 0xFFFFF000) >> 9 >= (unsigned int)v10 );
boot_printf("\n");
return 0LL;
}

original_code:
int
ide_read_module (int drive, int partition, int bn, struct module_info *moduleinfo)
{
  char buf[1024];
  char tmp[1024];
  int i, j;
  struct exec *exec_info;
  void *paddr;
  paddr = (void *)(moduleinfo->paddr);
  ide_read (drive, partition, bn, tmp, 1);
  exec_info = (struct exec *)tmp;
  if ((((*exec_info).a_info & 0xffff) != 0407 && ((*exec_info).a_info & 0xffff) != 0410 && ((*exec_info).a_info & 0xffff) != 0413 && ((*exec_info).a_info & 0xffff) != 0314))
    {
      boot_printf ("This object is not exec format (%d).\n", *exec_info);
      for (;;)
 ;
    }
  if ((((*exec_info).a_info & 0xffff) == 0413) || (((*exec_info).a_info & 0xffff) == 0410))
    {
      bn += (1024 / 512);
      for (i = 0;
    i < (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096))
   / 512);
    i++, bn++)
 {
   boot_printf (".");
   ide_read (drive, partition, bn, buf, 1);
   bcopy (buf,
   (char *)(paddr + i * 512),
   512);
 }
      for (j = 0;
    j <= (((((exec_info->a_data) + ((4096) - 1)) / (4096)) * (4096))
   / 512);
    j++ , bn++)
 {
   boot_printf (".");
   ide_read (drive, partition, bn, buf, 1);
   bcopy (buf,
   (char *)(paddr
     + (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096)))
     + j * 512),
   512);
 }
    }
  else
    {
      boot_printf ("I am unknown a.out image.(0x%x)\n", ((*exec_info).a_info & 0xffff));
      for (;;)
 ;
    }
  boot_printf ("\n");
  return (0);
}

canonical_original_code:
int ide_read_module(int drive, int partition, int bn, struct module_info *moduleinfo)
{
  char buf[1024];
  char tmp[1024];
  int i; int j;
  struct exec *exec_info;
  void *paddr;
  paddr = (void *)(moduleinfo->paddr);
  ide_read (drive, partition, bn, tmp, 1);
  exec_info = (struct exec *)tmp;
  if ((((*exec_info).a_info & 0xffff) != 0407 && ((*exec_info).a_info & 0xffff) != 0410 && ((*exec_info).a_info & 0xffff) != 0413 && ((*exec_info).a_info & 0xffff) != 0314))
    {
      boot_printf ("This object is not exec format (%d).\n", *exec_info);
      for (;;)
 ;
    }
  if ((((*exec_info).a_info & 0xffff) == 0413) || (((*exec_info).a_info & 0xffff) == 0410))
    {
      bn += (1024 / 512);
      for (i = 0;
    i < (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096))
   / 512);
    i++, bn++)
 {
   boot_printf (".");
   ide_read (drive, partition, bn, buf, 1);
   bcopy (buf,
   (char *)(paddr + i * 512),
   512);
 }
      for (j = 0;
    j <= (((((exec_info->a_data) + ((4096) - 1)) / (4096)) * (4096))
   / 512);
    j++ , bn++)
 {
   boot_printf (".");
   ide_read (drive, partition, bn, buf, 1);
   bcopy (buf,
   (char *)(paddr
     + (((((exec_info->a_text) + ((4096) - 1)) / (4096)) * (4096)))
     + j * 512),
   512);
 }
    }
  else
    {
      boot_printf ("I am unknown a.out image.(0x%x)\n", ((*exec_info).a_info & 0xffff));
      for (;;)
 ;
    }
  boot_printf ("\n");
  return (0);
}

variable_types: drive int

variable_types: bn int

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

variable_types:
buf
char [1024]

variable_types:
tmp
char [1024]

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

variable_types:
paddr
void *


repo: monaka/B-Free

decompiled_code:
__int64 __fastcall ide_read_multi_module(unsigned int a1, int a2, int a3, unsigned int *a4)
{
unsigned int v6; // ebp
unsigned int *v7; // rbx
signed int v8; // er12
void (*v10)(void); // [rsp+8h] [rbp-40h]

boot_printf("Multiple module boot.\n");
a4[4] = base_mem;
a4[2] = ext_mem;
a4[3] = real_mem;
boot_printf("Module %d\n", a4[1]);
v6 = a3 + 2;
v10 = (void (*)(void))a4[10];
if ( (int)a4[1] > 0 )
{
v7 = a4 + 6;
v8 = 0;
do
{
boot_printf("[%d] Baddr = %d, paddr = 0x%x, vaddr = 0x%x, length = %d\n", (unsigned int)v8, v6, v7[3], v7[2], *v7);
ide_read_module(a1, a2, v6, (__int64)v7);
v6 = v6 + (int)*v7 / 512 - 2;
++v8;
v7 += 16;
}
while ( (int)a4[1] > v8 );
}
boot_printf("load done.\n");
boot_printf("exec_info->a_entry = 0x%x\n", v10);
v10();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1, int a2, int a3, unsigned int *a4)
{
unsigned int v6; // ebp
unsigned int *v7; // rbx
signed int v8; // er12
void (*v10)(void); // [rsp+8h] [rbp-40h]

boot_printf("Multiple module boot.\n");
a4[4] = base_mem;
a4[2] = ext_mem;
a4[3] = real_mem;
boot_printf("Module %d\n", a4[1]);
v6 = a3 + 2;
v10 = (void (*)(void))a4[10];
if ( (int)a4[1] > 0 )
{
v7 = a4 + 6;
v8 = 0;
do
{
boot_printf("[%d] Baddr = %d, paddr = 0x%x, vaddr = 0x%x, length = %d\n", (unsigned int)v8, v6, v7[3], v7[2], *v7);
func15(a1, a2, v6, (__int64)v7);
v6 = v6 + (int)*v7 / 512 - 2;
++v8;
v7 += 16;
}
while ( (int)a4[1] > v8 );
}
boot_printf("load done.\n");
boot_printf("exec_info->a_entry = 0x%x\n", v10);
v10();
return 0LL;
}

original_code:
int
ide_read_multi_module (int drive, int partition, int offset, struct boot_header *info)
{
  int i;
  int bn;
  void (*entry)();
  boot_printf ("Multiple module boot.\n");
  info->machine.base_mem = base_mem;
  info->machine.ext_mem = ext_mem;
  info->machine.real_mem = real_mem;
  boot_printf ("Module %d\n", info->count);
  bn = offset + (1024 / 512);
  entry = (void (*)())(info->modules[0].entry);
  for (i = 0; i < info->count; i++)
    {
      boot_printf ("[%d] Baddr = %d, paddr = 0x%x, vaddr = 0x%x, length = %d\n",
       i,
       bn,
       info->modules[i].paddr,
       info->modules[i].vaddr,
       info->modules[i].length);
      ide_read_module (drive, partition, bn, &(info->modules[i]));
      bn += (info->modules[i].length / 512) - 2;
    }
  boot_printf ("load done.\n");
  boot_printf ("exec_info->a_entry = 0x%x\n", entry);
  (*entry)();
  return (0);
}

canonical_original_code:
int ide_read_multi_module(int drive, int partition, int offset, struct boot_header *info)
{
  int i;
  int bn;
  void (*entry)();
  boot_printf ("Multiple module boot.\n");
  info->machine.base_mem = base_mem;
  info->machine.ext_mem = ext_mem;
  info->machine.real_mem = real_mem;
  boot_printf ("Module %d\n", info->count);
  bn = offset + (1024 / 512);
  entry = (void (*)())(info->modules[0].entry);
  for (i = 0; i < info->count; i++)
    {
      boot_printf ("[%d] Baddr = %d, paddr = 0x%x, vaddr = 0x%x, length = %d\n",
       i,
       bn,
       info->modules[i].paddr,
       info->modules[i].vaddr,
       info->modules[i].length);
      ide_read_module (drive, partition, bn, &(info->modules[i]));
      bn += (info->modules[i].length / 512) - 2;
    }
  boot_printf ("load done.\n");
  boot_printf ("exec_info->a_entry = 0x%x\n", entry);
  (*entry)();
  return (0);
}

variable_types: partition int

variable_types: offset int

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

variable_types: i int

variable_types:
entry
void (*)()

return_type: int

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

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 ide_boot()
{
__int64 result; // rax
unsigned int v1[130]; // [rsp+0h] [rbp-208h] BYREF

if ( (unsigned int)ide_read(0, 0, 1uLL, (__int64)v1, 1) == 1 )
{
boot_printf("2nd boot size (512 block) = %d\n", v1[0]);
boot_printf("kernel start block = %d\n", v1[0] + 2);
ide_read(0, 0, v1[0] + 2, 2048LL, 1);
if ( loc_800 == 1 )
{
boot_printf("read multiple module.\n");
ide_read_multi_module(0, 0, v1[0] + 2, (unsigned int *)&loc_800);
boot_printf("boot end\n");
}
else
{
boot_printf("Unknown kernel module.(magic ID = %d)\n", 0LL);
}
result = 0LL;
}
else
{
boot_printf("cannot read from IDE HD.\n");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 result; // rax
unsigned int v1[130]; // [rsp+0h] [rbp-208h] BYREF

if ( (unsigned int)func12(0, 0, 1uLL, (__int64)v1, 1) == 1 )
{
boot_printf("2nd boot size (512 block) = %d\n", v1[0]);
boot_printf("kernel start block = %d\n", v1[0] + 2);
func12(0, 0, v1[0] + 2, 2048LL, 1);
if ( loc_800 == 1 )
{
boot_printf("read multiple module.\n");
func16(0, 0, v1[0] + 2, (unsigned int *)&loc_800);
boot_printf("boot end\n");
}
else
{
boot_printf("Unknown kernel module.(magic ID = %d)\n", 0LL);
}
result = 0LL;
}
else
{
boot_printf("cannot read from IDE HD.\n");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
ide_boot (char **arg)
{
  int drive = 0;
  int partition = 0;
  BYTE buf[512];
  struct boot_header *infop;
  int *second_boot_size;
  if (ide_read (0, partition, 1, buf, 1) != 1)
    {
      boot_printf ("cannot read from IDE HD.\n");
      return (-1);
    }
  second_boot_size = (int *)buf;
  boot_printf ("2nd boot size (512 block) = %d\n", *second_boot_size);
  boot_printf ("kernel start block = %d\n", 2 + *second_boot_size);
  infop = (struct boot_header *)(0x00000800);
  ide_read (drive, partition, 2 + *second_boot_size, (char *)infop, 1);
  if (infop->cookie == 0x0001)
    {
      boot_printf ("read multiple module.\n");
      ide_read_multi_module (drive, partition, 2 + *second_boot_size, infop);
      boot_printf ("boot end\n");
    }
  else
    {
      boot_printf ("Unknown kernel module.(magic ID = %d)\n");
    }
  return (0);
}

canonical_original_code:
int ide_boot(char **arg)
{
  int drive = 0;
  int partition = 0;
  unsigned char buf[512];
  struct boot_header *infop;
  int *second_boot_size;
  if (ide_read (0, partition, 1, buf, 1) != 1)
    {
      boot_printf ("cannot read from IDE HD.\n");
      return (-1);
    }
  second_boot_size = (int *)buf;
  boot_printf ("2nd boot size (512 block) = %d\n", *second_boot_size);
  boot_printf ("kernel start block = %d\n", 2 + *second_boot_size);
  infop = (struct boot_header *)(0x00000800);
  ide_read (drive, partition, 2 + *second_boot_size, (char *)infop, 1);
  if (infop->cookie == 0x0001)
    {
      boot_printf ("read multiple module.\n");
      ide_read_multi_module (drive, partition, 2 + *second_boot_size, infop);
      boot_printf ("boot end\n");
    }
  else
    {
      boot_printf ("Unknown kernel module.(magic ID = %d)\n");
    }
  return (0);
}

variable_types:
arg
char **

variable_types:
buf
unsigned char [512]

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

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


decompiled_code:
__int64 intr_ide()
{
boot_printf("IDE:interrupt!\n");
lock();
ide_intr_flag = 1;
return unlock();
}

canonical_decompiled_code:
__int64 func5()
{
boot_printf("IDE:interrupt!\n");
lock();
ide_intr_flag = 1;
return unlock();
}

original_code:
void
intr_ide ()
{
  boot_printf ("IDE:interrupt!\n");
  lock ();
  ide_intr_flag = TRUE;
  unlock ();
}

canonical_original_code:
void intr_ide()
{
  boot_printf ("IDE:interrupt!\n");
  lock ();
  ide_intr_flag = TRUE;
  unlock ();
}

return_type: void


decompiled_code:
__int64 __fastcall read_partition_table(__int64 a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbx
unsigned int i; // ebp
__int64 v5; // [rsp+0h] [rbp-218h] BYREF
char src[90]; // [rsp+1BEh] [rbp-5Ah] BYREF

v2 = a2;
ide_read_low(0, 0, 0, 1u, (__int64)&v5, 1);
bcopy(src, a2, 0x60uLL);
for ( i = 0; i != 4; ++i )
{
boot_printf(
"partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
i,
v2[4],
*((_QWORD *)v2 + 1),
*((_QWORD *)v2 + 2),
*v2);
boot_printf("begin(CHS): %d/%d/%d\n", v2[3] | (4 * v2[2]) & 0x300u, v2[1], v2[2] & 0x3F);
boot_printf("end(CHS): %d/%d/%d\n", v2[7] | (4 * v2[6]) & 0x300u, v2[5], v2[6] & 0x3F);
v2 += 24;
}
return 0LL;
}

original_code:
int
read_partition_table (int drive, struct ide_partition *table)
{
  BYTE buf[512];
  int i;
  ide_read_low (0, 0, 0, 1, buf, 1);
  bcopy (&buf[(0x1be)], (char *)table, sizeof (struct ide_partition) * 4);
  for (i = 0; i < 4; i++)
    {
      boot_printf ("partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
       i,
       table[i].type,
       table[i].start,
       table[i].length,
       table[i].boot_flag);
      boot_printf ("begin(CHS): %d/%d/%d\n",
       table[i].begin[2] | ((table[i].begin[1] & 0xc0) << 2),
       table[i].begin[0],
       table[i].begin[1] & 0x3f);
      boot_printf ("end(CHS): %d/%d/%d\n",
       table[i].end[2] | ((table[i].end[1] & 0xc0) << 2),
       table[i].end[0],
       table[i].end[1] & 0x3f);
    }
  return (0);
}

canonical_original_code:
int read_partition_table(int drive, struct ide_partition *table)
{
  unsigned char buf[512];
  int i;
  ide_read_low (0, 0, 0, 1, buf, 1);
  bcopy (&buf[(0x1be)], (char *)table, sizeof (struct ide_partition) * 4);
  for (i = 0; i < 4; i++)
    {
      boot_printf ("partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
       i,
       table[i].type,
       table[i].start,
       table[i].length,
       table[i].boot_flag);
      boot_printf ("begin(CHS): %d/%d/%d\n",
       table[i].begin[2] | ((table[i].begin[1] & 0xc0) << 2),
       table[i].begin[0],
       table[i].begin[1] & 0x3f);
      boot_printf ("end(CHS): %d/%d/%d\n",
       table[i].end[2] | ((table[i].end[1] & 0xc0) << 2),
       table[i].end[0],
       table[i].end[1] & 0x3f);
    }
  return (0);
}

variable_types: struct ide_partition { unsigned char boot_flag; unsigned char begin[3]; unsigned char type; unsigned char end[3]; unsigned long start; unsigned long length; } *


decompiled_code:
__int64 __fastcall ide_read(unsigned int a1, int a2, unsigned __int64 a3, __int64 a4, int a5)
{
unsigned int v7; // ebx
int v8; // er13
unsigned int v9; // esi
__int64 result; // rax

if ( partition_table[3 * a2 + 2] < a3 )
{
boot_printf("Block numer is invalid (blockno = %d)\n", (unsigned int)a3);
boot_printf("Total block of partition is %d\n", partition_table[3 * a2 + 2]);
boot_printf("Buffer address = 0x%x, length = %d\n", (unsigned int)a4, (unsigned int)a5);
result = 4294967294LL;
}
else
{
v7 = LODWORD(partition_table[3 * a2 + 1]) + a3;
if ( a5 <= 0 )
{
result = 0LL;
}
else
{
v8 = v7 + a5;
do
{
v9 = ide_parameter[6] * ide_parameter[3];
ide_read_low(a1, v7 / v9, v7 % v9 / ide_parameter[6], v7 % ide_parameter[6] + 1, a4, 1);
++v7;
a4 += 512LL;
}
while ( v7 != v8 );
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, int a2, unsigned __int64 a3, __int64 a4, int a5)
{
unsigned int v7; // ebx
int v8; // er13
unsigned int v9; // esi
__int64 result; // rax

if ( partition_table[3 * a2 + 2] < a3 )
{
boot_printf("Block numer is invalid (blockno = %d)\n", (unsigned int)a3);
boot_printf("Total block of partition is %d\n", partition_table[3 * a2 + 2]);
boot_printf("Buffer address = 0x%x, length = %d\n", (unsigned int)a4, (unsigned int)a5);
result = 4294967294LL;
}
else
{
v7 = LODWORD(partition_table[3 * a2 + 1]) + a3;
if ( a5 <= 0 )
{
result = 0LL;
}
else
{
v8 = v7 + a5;
do
{
v9 = ide_parameter[6] * ide_parameter[3];
func8(a1, v7 / v9, v7 % v9 / ide_parameter[6], v7 % ide_parameter[6] + 1, a4, 1);
++v7;
a4 += 512LL;
}
while ( v7 != v8 );
result = 0LL;
}
}
return result;
}

original_code:
int
ide_read (int drive, int partition, ULONG block, BYTE *buf, int length)
{
  unsigned int true_block;
  int i;
  int cylinder, sector, head;
  if ((block > partition_table[partition].length) || (block < 0))
    {
      boot_printf ("Block numer is invalid (blockno = %d)\n", (int)block);
      boot_printf ("Total block of partition is %d\n", partition_table[partition].length);
      boot_printf ("Buffer address = 0x%x, length = %d\n", (int)buf, length);
      return ((-2));
    }
  true_block = partition_table[partition].start + block;
  if (true_block < 0)
    {
      int i;
      boot_printf ("ERROR!! read block number is invalid!.\n");
      boot_printf ("true_block = %d, partition = %d, startblock = %d, block = %d\n",
       true_block, partition, partition_table[partition].start, block);
      boot_printf ("Buffer address = 0x%x, length = %d\n", buf, length);
      for (i = 0; i < 4; i++)
 {
   boot_printf ("partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
    i,
    partition_table[i].type,
    partition_table[i].start,
    partition_table[i].length,
    partition_table[i].boot_flag);
   boot_printf ("begin(CHS): %d/%d/%d\n",
    partition_table[i].begin[2] | ((partition_table[i].begin[1] & 0xc0) << 2),
    partition_table[i].begin[0],
    partition_table[i].begin[1] & 0x3f);
   boot_printf ("end(CHS): %d/%d/%d\n",
    partition_table[i].end[2] | ((partition_table[i].end[1] & 0xc0) << 2),
    partition_table[i].end[0],
    partition_table[i].end[1] & 0x3f);
 }
      for (;;)
 ;
      return ((-2));
    }
  for (i = 0; i < length; i++)
    {
      cylinder = (true_block + i) / (ide_parameter.n_head * ide_parameter.n_sector);
      head = ((true_block + i) % (ide_parameter.n_head * ide_parameter.n_sector)) / ide_parameter.n_sector;
      sector = ((true_block + i) % ide_parameter.n_sector) + 1;
      ide_read_low (drive, cylinder, head, sector, (buf + (i * 512)), 1);
    }
  return ((0));
}

canonical_original_code:
int ide_read(int drive, int partition, unsigned long block, unsigned char *buf, int length)
{
  unsigned int true_block;
  int i;
  int cylinder; int sector; int head;
  if ((block > partition_table[partition].length) || (block < 0))
    {
      boot_printf ("Block numer is invalid (blockno = %d)\n", (int)block);
      boot_printf ("Total block of partition is %d\n", partition_table[partition].length);
      boot_printf ("Buffer address = 0x%x, length = %d\n", (int)buf, length);
      return ((-2));
    }
  true_block = partition_table[partition].start + block;
  if (true_block < 0)
    {
      int i;
      boot_printf ("ERROR!! read block number is invalid!.\n");
      boot_printf ("true_block = %d, partition = %d, startblock = %d, block = %d\n",
       true_block, partition, partition_table[partition].start, block);
      boot_printf ("Buffer address = 0x%x, length = %d\n", buf, length);
      for (i = 0; i < 4; i++)
 {
   boot_printf ("partition[%d] type = 0x%x, start = %d, length = %d, bootable = %d\n",
    i,
    partition_table[i].type,
    partition_table[i].start,
    partition_table[i].length,
    partition_table[i].boot_flag);
   boot_printf ("begin(CHS): %d/%d/%d\n",
    partition_table[i].begin[2] | ((partition_table[i].begin[1] & 0xc0) << 2),
    partition_table[i].begin[0],
    partition_table[i].begin[1] & 0x3f);
   boot_printf ("end(CHS): %d/%d/%d\n",
    partition_table[i].end[2] | ((partition_table[i].end[1] & 0xc0) << 2),
    partition_table[i].end[0],
    partition_table[i].end[1] & 0x3f);
 }
      for (;;)
 ;
      return ((-2));
    }
  for (i = 0; i < length; i++)
    {
      cylinder = (true_block + i) / (ide_parameter.n_head * ide_parameter.n_sector);
      head = ((true_block + i) % (ide_parameter.n_head * ide_parameter.n_sector)) / ide_parameter.n_sector;
      sector = ((true_block + i) % ide_parameter.n_sector) + 1;
      ide_read_low (drive, cylinder, head, sector, (buf + (i * 512)), 1);
    }
  return ((0));
}

variable_types:
block
unsigned long

variable_types:
buf
unsigned char *

variable_types: length int

variable_types: cylinder int

variable_types: sector int

variable_types: head int


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

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

canonical_original_code:
int psys_remove(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_getgid()
{
__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(15LL, 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(15LL, v4, &v1) || !v2 )
return v3;
MEMORY[0x7FFF0028] = v2;
return 0xFFFFFFFFLL;
}

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

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

return_type: unsigned short


access

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

v2 = strlen(a1);
return call_lowlib(1LL, 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(1LL, v2, a1, a2);
}

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

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

variable_types:
path
char *

variable_types: mode int


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

v1 = get_tid(v3);
result = 0LL;
if ( !v1 )
{
if ( (unsigned int)vmap_reg(v3[0], last_page, a1, 0LL) )
{
result = 0LL;
}
else
{
result = last_page;
last_page += a1;
}
}
return result;
}

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

v1 = get_tid(v3);
result = 0LL;
if ( !v1 )
{
if ( (unsigned int)vmap_reg(v3[0], last_page, a1, 0LL) )
{
result = 0LL;
}
else
{
result = last_page;
last_page += a1;
}
}
return result;
}

original_code:
static VP
get_system_memory (UW size)
{
  ID mytid;
  VP rp;
  ER errno;
  if (get_tid (&mytid) != (0))
    {
      return ((0));
    }
  errno = vmap_reg (mytid, (VP) last_page, size, 0);
  if (errno)
    {
      return ((0));
    }
  rp = (VP)last_page;
  last_page += size;
  return (rp);
}

canonical_original_code:
static void *get_system_memory(unsigned long size)
{
  int mytid;
  void *rp;
  int errno;
  if (get_tid (&mytid) != (0))
    {
      return ((0));
    }
  errno = vmap_reg (mytid, (void *) last_page, size, 0);
  if (errno)
    {
      return ((0));
    }
  rp = (void *)last_page;
  last_page += size;
  return (rp);
}

variable_types:
size
unsigned long

variable_types: mytid int

variable_types:
rp
void *

variable_types: errno int

return_type: void *


decompiled_code:
__int64 __fastcall init_malloc(void *a1)
{
unsigned int v1; // ebx
_QWORD *v3; // rax
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !a1 )
a1 = &end;
last_page = (int)(((_DWORD)a1 + 4095) & 0xFFFFF000);
v1 = get_tid(v4);
if ( !v1 )
{
v1 = vcre_reg(v4[0], last_page, 10485760LL, 10485760LL, 65537LL, 0LL);
if ( !v1 )
{
qword_400 = 0LL;
v3 = (_QWORD *)get_system_memory(40960LL);
if ( v3 )
{
v3[2] = 40936LL;
*v3 = &alloc_list;
v3[1] = &alloc_list;
alloc_list = (__int64)v3;
qword_3F8 = (__int64)v3;
pivot = (__int64)&alloc_list;
}
else
{
v1 = -10;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1)
{
unsigned int v1; // ebx
_QWORD *v3; // rax
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( !a1 )
a1 = &end;
last_page = (int)(((_DWORD)a1 + 4095) & 0xFFFFF000);
v1 = get_tid(v4);
if ( !v1 )
{
v1 = vcre_reg(v4[0], last_page, 10485760LL, 10485760LL, 65537LL, 0LL);
if ( !v1 )
{
qword_400 = 0LL;
v3 = (_QWORD *)func0(40960LL);
if ( v3 )
{
v3[2] = 40936LL;
*v3 = &alloc_list;
v3[1] = &alloc_list;
alloc_list = (__int64)v3;
qword_3F8 = (__int64)v3;
pivot = (__int64)&alloc_list;
}
else
{
v1 = -10;
}
}
}
return v1;
}

original_code:
ER
init_malloc (UW free_memory_erea)
{
  ID mytid;
  struct alloc_entry_t *p;
  ER err;
  if (free_memory_erea)
    {
      last_page = free_memory_erea;
    }
  else
    {
      last_page = (UW)&_end;
    }
  last_page = ((((int)last_page) + (4096) - 1) & ~((4096) - 1));
  err = get_tid (&mytid);
  if (err != (0))
    {
      return (err);
    }
  err = vcre_reg (mytid, (VP) last_page, (1024 * 1024 * 10), (1024 * 1024 * 10),
    (0x00000001) | (0x00000001) | (0x00010000), (0));
  if (err)
    {
      return (err);
    }
  alloc_list.size = 0;
  p = (struct alloc_entry_t *)get_system_memory ((4096 * 10));
  if (p == (0))
    {
      return ((-10));
    }
  p->size = (4096 * 10) - sizeof (struct alloc_entry_t);
  p->next = &alloc_list;
  p->before = &alloc_list;
  alloc_list.next = p;
  alloc_list.before = p;
  free_list = &alloc_list;
  pivot = &alloc_list;
  return ((0));
}

canonical_original_code:
int init_malloc(unsigned long free_memory_erea)
{
  int mytid;
  struct alloc_entry_t *p;
  int err;
  if (free_memory_erea)
    {
      last_page = free_memory_erea;
    }
  else
    {
      last_page = (UW)&_end;
    }
  last_page = ((((int)last_page) + (4096) - 1) & ~((4096) - 1));
  err = get_tid (&mytid);
  if (err != (0))
    {
      return (err);
    }
  err = vcre_reg (mytid, (void *) last_page, (1024 * 1024 * 10), (1024 * 1024 * 10),
    (0x00000001) | (0x00000001) | (0x00010000), (0));
  if (err)
    {
      return (err);
    }
  alloc_list.size = 0;
  p = (struct alloc_entry_t *)get_system_memory ((4096 * 10));
  if (p == (0))
    {
      return ((-10));
    }
  p->size = (4096 * 10) - sizeof (struct alloc_entry_t);
  p->next = &alloc_list;
  p->before = &alloc_list;
  alloc_list.next = p;
  alloc_list.before = p;
  free_list = &alloc_list;
  pivot = &alloc_list;
  return ((0));
}

variable_types: struct alloc_entry_t { struct alloc_entry_t *next; struct alloc_entry_t *before; unsigned long size; char alloc_data[]; } *

variable_types: err int


getpgrp

decompiled_code:
void getpgrp()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
getpgrp (void)
{
  return (call_lowlib (16));
}

canonical_original_code:
int getpgrp()
{
  return (call_lowlib (16));
}


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

result = MitnCell_GetCellAsName(&v3, a1);
if ( !(_DWORD)result )
{
*(_QWORD *)(v3 + 32) = a2;
result = MitnStack_Push(3LL);
}
return result;
}

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

result = MitnCell_GetCellAsName(&v3, a1);
if ( !(_DWORD)result )
{
*(_QWORD *)(v3 + 32) = a2;
result = MitnStack_Push(3LL);
}
return result;
}

original_code:
ER MitnDict_DefineOperator(B *name, Cell *c)
{
  ER result;
  Cell *targetCell;
  result = MitnCell_GetCellAsName(&targetCell, name);
  if (result == (0))
    {
      targetCell->value.name.link = c;
      result = MitnStack_Push(3, targetCell);
    }
  return result;
}

canonical_original_code:
int MitnDict_DefineOperator(char *name, struct _cell *c)
{
  int result;
  struct _cell *targetCell;
  result = MitnCell_GetCellAsName(&targetCell, name);
  if (result == (0))
    {
      targetCell->value.name.link = c;
      result = MitnStack_Push(3, targetCell);
    }
  return result;
}

variable_types:
name
char *

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: result int


decompiled_code:
int __fastcall MitnDict_FindCellFromDict(_QWORD *a1, const char *a2)
{
__int64 v2; // rbx
int result; // eax

v2 = MitnStack_Top[36];
if ( (_UNKNOWN *)v2 == (_UNKNOWN *)((char *)&MitnStack_Bottom + 264) )
{
LABEL_5:
*a1 = 0LL;
result = -33;
}
else
{
while ( *(_QWORD *)(v2 + 8) == 269221888LL )
{
result = strcmp(a2, (const char *)(v2 + 40));
if ( !result )
{
*a1 = *(_QWORD *)(v2 + 32);
return result;
}
v2 = *(_QWORD *)(v2 + 24);
if ( (_UNKNOWN *)v2 == (_UNKNOWN *)((char *)&MitnStack_Bottom + 264) )
goto LABEL_5;
}
result = -5;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(_QWORD *a1, const char *a2)
{
__int64 v2; // rbx
int result; // eax

v2 = MitnStack_Top[36];
if ( (_UNKNOWN *)v2 == (_UNKNOWN *)((char *)&MitnStack_Bottom + 264) )
{
LABEL_5:
*a1 = 0LL;
result = -33;
}
else
{
while ( *(_QWORD *)(v2 + 8) == 269221888LL )
{
result = strcmp(a2, (const char *)(v2 + 40));
if ( !result )
{
*a1 = *(_QWORD *)(v2 + 32);
return result;
}
v2 = *(_QWORD *)(v2 + 24);
if ( (_UNKNOWN *)v2 == (_UNKNOWN *)((char *)&MitnStack_Bottom + 264) )
goto LABEL_5;
}
result = -5;
}
return result;
}

original_code:
ER MitnDict_FindCellFromDict(Cell **c, B * str)
{
  extern Cell MitnStack_Top[];
  extern Cell MitnStack_Bottom[];
  Cell *nameCell;
  for (nameCell = MitnStack_Top[3].next;
       nameCell != &MitnStack_Bottom[3];
       nameCell = nameCell->next) {
    if (nameCell->type != (0x000C0000 | (0x10000000))) {
      return (-5);
    }
    if (strcmp (str, nameCell->value.name.str) == 0) {
      *c = nameCell->value.name.link;
      return (0);
    }
  }
  *c = (0);
  return (-33);
}

canonical_original_code:
int MitnDict_FindCellFromDict(struct _cell **c, char *str)
{
  extern struct _cell MitnStack_Top[];
  extern struct _cell MitnStack_Bottom[];
  struct _cell *nameCell;
  for (nameCell = MitnStack_Top[3].next;
       nameCell != &MitnStack_Bottom[3];
       nameCell = nameCell->next) {
    if (nameCell->type != (0x000C0000 | (0x10000000))) {
      return (-5);
    }
    if (strcmp (str, nameCell->value.name.str) == 0) {
      *c = nameCell->value.name.link;
      return (0);
    }
  }
  *c = (0);
  return (-33);
}

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:
str
char *

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


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

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

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

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


getlogin

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

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

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

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

original_code:
int
getlogin (char *login)
{
  return (call_lowlib (73, strlen (login), login));
}

canonical_original_code:
int getlogin(char *login)
{
  return (call_lowlib (73, strlen (login), login));
}

variable_types:
login
char *


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

v4[3] = a1;
v4[4] = a2;
v4[2] = 0;
v2 = 100;
while ( (unsigned int)cre_mbf(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[10]; // [rsp+0h] [rbp-28h] BYREF

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

original_code:
ID
get_port (W minsize, W maxsize)
{
  ID msg_port;
  T_CMBF create_argument;
  W errno;
  create_argument.bufsz = minsize;
  create_argument.maxmsz = maxsize;
  create_argument.mbfatr = (0x00000000);
  for (msg_port = (100);
       msg_port <= (256);
       msg_port++)
    {
      errno = cre_mbf (msg_port, &create_argument);
      if (errno == (0))
 {
   return (msg_port);
 }
    }
  return (0);
}

canonical_original_code:
int get_port(long minsize, long maxsize)
{
  int msg_port;
  struct t_cmbf create_argument;
  long errno;
  create_argument.bufsz = minsize;
  create_argument.maxmsz = maxsize;
  create_argument.mbfatr = (0x00000000);
  for (msg_port = (100);
       msg_port <= (256);
       msg_port++)
    {
      errno = cre_mbf (msg_port, &create_argument);
      if (errno == (0))
 {
   return (msg_port);
 }
    }
  return (0);
}

variable_types: minsize long

variable_types: maxsize long

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

variable_types: errno long


decompiled_code:
__int64 __fastcall get_req(unsigned int a1, __int64 a2, __int64 *a3)
{
__int64 v4; // rdx

sys_errno = rcv_mbf(a2, a3, a1);
v4 = 0LL;
if ( !sys_errno )
v4 = *a3;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, __int64 *a3)
{
__int64 v4; // rdx

sys_errno = rcv_mbf(a2, a3, a1);
v4 = 0LL;
if ( !sys_errno )
v4 = *a3;
return v4;
}

original_code:
W
get_req (ID port, VP request, W *size)
{
  extern ER sys_errno;
  sys_errno = rcv_mbf (request, (INT *)size, port);
  if (sys_errno != (0))
    return (0);
  return (*size);
}

canonical_original_code:
long get_req(int port, void *request, long *size)
{
  extern int sys_errno;
  sys_errno = rcv_mbf (request, (int *)size, port);
  if (sys_errno != (0))
    return (0);
  return (*size);
}

variable_types: port int

variable_types:
request
void *

variable_types:
size
long *

return_type: long


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

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

canonical_original_code:
int psys_fcntl(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 parse_line(char *nptr)
{
char *i; // r13
char v2; // bp
unsigned int v3; // er12
unsigned int v4; // ebx
__int64 v5; // r12
char v6; // bp
int v7; // eax
char v9[264]; // [rsp+0h] [rbp-138h] BYREF
__int64 v10[6]; // [rsp+108h] [rbp-30h] BYREF

if ( !*nptr )
return 0;
for ( i = nptr; ; ++i )
{
while ( 1 )
{
v2 = *i;
v3 = *i;
v4 = isspace(v3);
if ( v4 )
break;
if ( v2 == 40 )
{
i = edit_str(v9, i + 1, 41);
if ( !i )
return (unsigned int)-33;
MitnCell_GetCellAsStr(v10, v9);
MitnStack_BottomPush(2LL, v10[0]);
}
else if ( (unsigned int)isnum(v3) )
{
v5 = atoi(i);
while ( 1 )
{
v6 = *i;
v7 = isspace(*i);
if ( !v6 || v7 )
break;
++i;
}
MitnCell_GetCellAsLong(v10, v5);
MitnStack_BottomPush(2LL, v10[0]);
}
else
{
i = edit_str(v9, i, 32);
if ( !(unsigned int)MitnDict_FindCellFromDict(v10, v9)
&& ((*(_QWORD *)(v10[0] + 8) - 570490880LL) & 0xFFFFFFFFFFFEFFFFLL) == 0 )
{
MitnStack_BottomPush(2LL, v10[0]);
}
}
if ( !*i )
return v4;
}
if ( !v2 )
break;
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *nptr)
{
char *i; // r13
char v2; // bp
unsigned int v3; // er12
unsigned int v4; // ebx
__int64 v5; // r12
char v6; // bp
int v7; // eax
char v9[264]; // [rsp+0h] [rbp-138h] BYREF
__int64 v10[6]; // [rsp+108h] [rbp-30h] BYREF

if ( !*nptr )
return 0;
for ( i = nptr; ; ++i )
{
while ( 1 )
{
v2 = *i;
v3 = *i;
v4 = isspace(v3);
if ( v4 )
break;
if ( v2 == 40 )
{
i = func0(v9, i + 1, 41);
if ( !i )
return (unsigned int)-33;
MitnCell_GetCellAsStr(v10, v9);
MitnStack_BottomPush(2LL, v10[0]);
}
else if ( (unsigned int)isnum(v3) )
{
v5 = atoi(i);
while ( 1 )
{
v6 = *i;
v7 = isspace(*i);
if ( !v6 || v7 )
break;
++i;
}
MitnCell_GetCellAsLong(v10, v5);
MitnStack_BottomPush(2LL, v10[0]);
}
else
{
i = func0(v9, i, 32);
if ( !(unsigned int)MitnDict_FindCellFromDict(v10, v9)
&& ((*(_QWORD *)(v10[0] + 8) - 570490880LL) & 0xFFFFFFFFFFFEFFFFLL) == 0 )
{
MitnStack_BottomPush(2LL, v10[0]);
}
}
if ( !*i )
return v4;
}
if ( !v2 )
break;
}
return 0;
}

original_code:
ER
parse_line (B *line)
{
  Cell *c;
  B *pos;
  ER result;
  pos = line;
  while(TRUE)
    {
      if (*pos == '\0')
 {
   return (0);
 }
      while (isspace(*pos))
 {
   if (*pos == '\0')
     {
       return (0);
     }
   pos++;
 }
      if (*pos == '(')
 {
   B str[255];
   pos = edit_str(str, ++pos, ')');
   if (pos == (0))
     {
       return (-33);
     }
   MitnCell_GetCellAsStr(&c, str);
   MitnStack_BottomPush(2, c);
 }
      else if (isnum(*pos))
 {
   long num;
   num = atoi(pos);
   for( ; !(isspace(*pos) || *pos == '\0'); pos++)
     {
     }
   MitnCell_GetCellAsLong(&c, num);
   MitnStack_BottomPush(2, c);
 }
      else
 {
   B str[255];
   pos = edit_str(str, pos, ' ');
   result = MitnDict_FindCellFromDict(&c, str);
   if (result != (0))
     {
       continue;
     }
   switch (c->type)
     {
     case (0x00020000 | (0x20000000) | (0x02000000)):
     case (0x00010000 | (0x20000000) | (0x02000000)):
       MitnStack_BottomPush(2, c);
       break;
     default:
       break;
     }
 }
    }
  return (0);
}

canonical_original_code:
int parse_line(char *line)
{
  struct _cell *c;
  char *pos;
  int result;
  pos = line;
  while(TRUE)
    {
      if (*pos == '\0')
 {
   return (0);
 }
      while (isspace(*pos))
 {
   if (*pos == '\0')
     {
       return (0);
     }
   pos++;
 }
      if (*pos == '(')
 {
   char str[255];
   pos = edit_str(str, ++pos, ')');
   if (pos == (0))
     {
       return (-33);
     }
   MitnCell_GetCellAsStr(&c, str);
   MitnStack_BottomPush(2, c);
 }
      else if (isnum(*pos))
 {
   long num;
   num = atoi(pos);
   for( ; !(isspace(*pos) || *pos == '\0'); pos++)
     {
     }
   MitnCell_GetCellAsLong(&c, num);
   MitnStack_BottomPush(2, c);
 }
      else
 {
   char str[255];
   pos = edit_str(str, pos, ' ');
   result = MitnDict_FindCellFromDict(&c, str);
   if (result != (0))
     {
       continue;
     }
   switch (c->type)
     {
     case (0x00020000 | (0x20000000) | (0x02000000)):
     case (0x00010000 | (0x20000000) | (0x02000000)):
       MitnStack_BottomPush(2, c);
       break;
     default:
       break;
     }
 }
    }
  return (0);
}

variable_types:
line
char *

variable_types:
pos
char *

variable_types:
str
char [255]

variable_types: num long

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


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

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

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


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

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

original_code:
int
dup2 (int fd, int fd2)
{
  return (call_lowlib (67, fd, fd2));
}

canonical_original_code:
int dup2(int fd, int fd2)
{
  return (call_lowlib (67, fd, fd2));
}

variable_types: fd int


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

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

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


decompiled_code:
__int64 init_memory()
{
__int64 i; // rax
int v1; // ebx

last_addr = (__int64)&end;
enable_A20();
for ( i = 0x100000LL; ; i += 0x100000LL )
{
v1 = i;
*(_DWORD *)i = 0;
*(_DWORD *)i = 170;
if ( *(_DWORD *)i != 170 )
break;
v1 = i + 0x100000;
if ( i == 250609664 )
break;
}
boot_printf("Extended Memory = %d K bytes\n", (unsigned int)((v1 - 0x100000) / 1000));
boot_printf("USE Memory = %d bytes\n", last_addr);
ext_mem = v1 - 0x100000;
base_mem = 655360LL;
real_mem = v1 - 393216;
return init_malloc(655360LL, 102400);
}

original_code:
void
init_memory (void)
{
  volatile int *p;
  last_addr = (void *)&end;
  enable_A20 ();
  for (p = (int *)0x100000; (int)p < 0xf000000; p = (int *)((int)p + 0x100000))
    {
      *p = 0;
      *p = 0xAA;
      if (*p != 0xAA)
 break;
    }
  boot_printf ("Extended Memory = %d K bytes\n", ((int)p - 0x100000) / 1000);
  boot_printf ("USE Memory      = %d bytes\n", last_addr);
  ext_mem = ((int)p - 0x100000);
  base_mem = (640 * 1024);
  real_mem = ext_mem + (640 * 1024);
  init_malloc ((void *)(640 * 1024), (1024 * 100));
}

canonical_original_code:
void init_memory()
{
  int *p;
  last_addr = (void *)&end;
  enable_A20 ();
  for (p = (int *)0x100000; (int)p < 0xf000000; p = (int *)((int)p + 0x100000))
    {
      *p = 0;
      *p = 0xAA;
      if (*p != 0xAA)
 break;
    }
  boot_printf ("Extended Memory = %d K bytes\n", ((int)p - 0x100000) / 1000);
  boot_printf ("USE Memory      = %d bytes\n", last_addr);
  ext_mem = ((int)p - 0x100000);
  base_mem = (640 * 1024);
  real_mem = ext_mem + (640 * 1024);
  init_malloc ((void *)(640 * 1024), (1024 * 100));
}

variable_types:
p
int *


malloc

original_code:
void *
malloc (int size)
{
  int true_size;
  struct alloc_entry *p, *prev;
  struct alloc_entry *alloced;
  if (alloc_reg == (LONG)0)
    {
      return ((LONG)0);
    }
  true_size = (size + sizeof (struct alloc_entry));
  for (prev = alloc_reg, p = alloc_reg->next;
       p->size < true_size;
       prev = p, p = p->next)
    {
      if (p == alloc_reg)
 {
   return ((LONG)0);
 }
    }
  if (p->size == true_size)
    {
      if (p->next == p)
 {
   alloc_reg = (LONG)0;
   p->next = (LONG)0;
 }
      else
 {
   prev->next = p->next;
 }
      return ((void *)(p->body));
    }
  alloced = (struct alloc_entry *)(((char *)p) + (p->size - true_size));
  p->size -= true_size;
  alloced->size = true_size;
  return (alloced->body);
}

canonical_original_code:
void *malloc(int size)
{
  int true_size;
  struct alloc_entry *p; struct alloc_entry *prev;
  struct alloc_entry *alloced;
  if (alloc_reg == (long)0)
    {
      return ((long)0);
    }
  true_size = (size + sizeof (struct alloc_entry));
  for (prev = alloc_reg, p = alloc_reg->next;
       p->size < true_size;
       prev = p, p = p->next)
    {
      if (p == alloc_reg)
 {
   return ((long)0);
 }
    }
  if (p->size == true_size)
    {
      if (p->next == p)
 {
   alloc_reg = (long)0;
   p->next = (long)0;
 }
      else
 {
   prev->next = p->next;
 }
      return ((void *)(p->body));
    }
  alloced = (struct alloc_entry *)(((char *)p) + (p->size - true_size));
  p->size -= true_size;
  alloced->size = true_size;
  return (alloced->body);
}

variable_types: size int

variable_types: struct alloc_entry { struct alloc_entry *next; int size; unsigned char body[]; } *


free

decompiled_code:
__int64 __fastcall free(__int64 a1)
{
unsigned __int64 v1; // rcx
__int64 result; // rax
__int64 v3; // r9
__int64 v4; // rdx
int v5; // edx
int v6; // esi
__int64 *v7; // r8
int v8; // er8
int v9; // esi

v1 = a1 - 16;
result = ext_mem;
if ( a1 - 16 >= (unsigned __int64)(ext_mem + 946176) )
{
result = ext_mem + 0x100000;
if ( v1 <= ext_mem + 0x100000 )
{
v3 = alloc_reg;
result = *(_QWORD *)alloc_reg;
v4 = alloc_reg;
if ( alloc_reg == *(_QWORD *)alloc_reg )
{
v5 = *(_DWORD *)(a1 - 8);
result = v1 + v5;
if ( alloc_reg == result )
{
*(_DWORD *)(a1 - 8) = *(_DWORD *)(alloc_reg + 8) + v5;
*(_QWORD *)(a1 - 16) = v1;
alloc_reg = a1 - 16;
}
else
{
v6 = *(_DWORD *)(alloc_reg + 8);
result = alloc_reg + v6;
if ( v1 == result )
{
*(_DWORD *)(alloc_reg + 8) = v6 + v5;
}
else
{
*(_QWORD *)alloc_reg = v1;
*(_QWORD *)(a1 - 16) = v3;
}
}
}
else
{
while ( 1 )
{
v8 = *(_DWORD *)(a1 - 8);
if ( result == v1 + v8 )
{
*(_DWORD *)(a1 - 8) = *(_DWORD *)(result + 8) + v8;
*(_QWORD *)(a1 - 16) = *(_QWORD *)result;
*(_QWORD *)v4 = v1;
v7 = (__int64 *)(a1 - 16);
}
else
{
*(_QWORD *)(a1 - 16) = result;
*(_QWORD *)v4 = v1;
v7 = (__int64 *)result;
}
v9 = *(_DWORD *)(v4 + 8);
if ( v1 == v4 + v9 )
{
*(_DWORD *)(v4 + 8) = *(_DWORD *)(a1 - 8) + v9;
*(_QWORD *)v4 = *(_QWORD *)(a1 - 16);
}
result = *v7;
if ( v3 == *v7 )
break;
v4 = (__int64)v7;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned __int64 v1; // rcx
__int64 result; // rax
__int64 v3; // r9
__int64 v4; // rdx
int v5; // edx
int v6; // esi
__int64 *v7; // r8
int v8; // er8
int v9; // esi

v1 = a1 - 16;
result = ext_mem;
if ( a1 - 16 >= (unsigned __int64)(ext_mem + 946176) )
{
result = ext_mem + 0x100000;
if ( v1 <= ext_mem + 0x100000 )
{
v3 = alloc_reg;
result = *(_QWORD *)alloc_reg;
v4 = alloc_reg;
if ( alloc_reg == *(_QWORD *)alloc_reg )
{
v5 = *(_DWORD *)(a1 - 8);
result = v1 + v5;
if ( alloc_reg == result )
{
*(_DWORD *)(a1 - 8) = *(_DWORD *)(alloc_reg + 8) + v5;
*(_QWORD *)(a1 - 16) = v1;
alloc_reg = a1 - 16;
}
else
{
v6 = *(_DWORD *)(alloc_reg + 8);
result = alloc_reg + v6;
if ( v1 == result )
{
*(_DWORD *)(alloc_reg + 8) = v6 + v5;
}
else
{
*(_QWORD *)alloc_reg = v1;
*(_QWORD *)(a1 - 16) = v3;
}
}
}
else
{
while ( 1 )
{
v8 = *(_DWORD *)(a1 - 8);
if ( result == v1 + v8 )
{
*(_DWORD *)(a1 - 8) = *(_DWORD *)(result + 8) + v8;
*(_QWORD *)(a1 - 16) = *(_QWORD *)result;
*(_QWORD *)v4 = v1;
v7 = (__int64 *)(a1 - 16);
}
else
{
*(_QWORD *)(a1 - 16) = result;
*(_QWORD *)v4 = v1;
v7 = (__int64 *)result;
}
v9 = *(_DWORD *)(v4 + 8);
if ( v1 == v4 + v9 )
{
*(_DWORD *)(v4 + 8) = *(_DWORD *)(a1 - 8) + v9;
*(_QWORD *)v4 = *(_QWORD *)(a1 - 16);
}
result = *v7;
if ( v3 == *v7 )
break;
v4 = (__int64)v7;
}
}
}
}
return result;
}

original_code:
void
free (void *ptr)
{
  struct alloc_entry *current, *prev;
  struct alloc_entry *new_entry;
  new_entry = (struct alloc_entry *)((char *)ptr - sizeof (struct alloc_entry));
  if (((char *)new_entry < (char *)(void *)ext_mem
                            + (1024 * 1024) - (1024 * 100))
      || ((char *)new_entry > (char *)(void *)ext_mem + (1024 * 1024)))
    {
      return;
    }
  if (alloc_reg == alloc_reg->next)
    {
      if (((char *)new_entry + new_entry->size) == (char *)alloc_reg)
 {
   new_entry->size += alloc_reg->size;
   new_entry->next = new_entry;
   alloc_reg = new_entry;
 }
      else if (((char *)alloc_reg + alloc_reg->size) == (char *)new_entry)
 {
   alloc_reg->size += new_entry->size;
 }
      else
 {
   alloc_reg->next = new_entry;
   new_entry->next = alloc_reg;
 }
      return;
    }
  for (prev = alloc_reg, current = alloc_reg->next;
       current != alloc_reg;
       prev = current, current = current->next)
    {
      if ((char *)current == ((char *)new_entry + new_entry->size))
 {
   new_entry->size += current->size;
   new_entry->next = current->next;
   current = new_entry;
   prev->next = current;
 }
      else
 {
   new_entry->next = current;
   prev->next = new_entry;
 }
      if ((char *)new_entry == ((char *)prev + prev->size))
 {
   prev->size += new_entry->size;
   prev->next = new_entry->next;
 }
    }
}

canonical_original_code:
void free(void *ptr)
{
  struct alloc_entry *current; struct alloc_entry *prev;
  struct alloc_entry *new_entry;
  new_entry = (struct alloc_entry *)((char *)ptr - sizeof (struct alloc_entry));
  if (((char *)new_entry < (char *)(void *)ext_mem
                            + (1024 * 1024) - (1024 * 100))
      || ((char *)new_entry > (char *)(void *)ext_mem + (1024 * 1024)))
    {
      return;
    }
  if (alloc_reg == alloc_reg->next)
    {
      if (((char *)new_entry + new_entry->size) == (char *)alloc_reg)
 {
   new_entry->size += alloc_reg->size;
   new_entry->next = new_entry;
   alloc_reg = new_entry;
 }
      else if (((char *)alloc_reg + alloc_reg->size) == (char *)new_entry)
 {
   alloc_reg->size += new_entry->size;
 }
      else
 {
   alloc_reg->next = new_entry;
   new_entry->next = alloc_reg;
 }
      return;
    }
  for (prev = alloc_reg, current = alloc_reg->next;
       current != alloc_reg;
       prev = current, current = current->next)
    {
      if ((char *)current == ((char *)new_entry + new_entry->size))
 {
   new_entry->size += current->size;
   new_entry->next = current->next;
   current = new_entry;
   prev->next = current;
 }
      else
 {
   new_entry->next = current;
   prev->next = new_entry;
 }
      if ((char *)new_entry == ((char *)prev + prev->size))
 {
   prev->size += new_entry->size;
   prev->next = new_entry->next;
 }
    }
}

variable_types:
ptr
void *

user_defined_types: struct alloc_entry { struct alloc_entry *next; int size; unsigned char body[]; }


remove

decompiled_code:
void remove()
{
;
}

original_code:
int
remove (char *path)
{
  return (call_lowlib (75, strlen (path), path));
}

canonical_original_code:
int remove(char *path)
{
  return (call_lowlib (75, strlen (path), path));
}

variable_types:
path
char *


InitFileTable

decompiled_code:
__int64 *InitFileTable()
{
__int64 *result; // rax

result = &_file_table__;
do
{
*(_DWORD *)result = -1;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 1024LL;
result += 132;
}
while ( result != (__int64 *)(unsigned int)((_DWORD)&_file_table__ + 10560) );
return result;
}

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

result = &_file_table__;
do
{
*(_DWORD *)result = -1;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 1024LL;
result += 132;
}
while ( result != (__int64 *)(unsigned int)((_DWORD)&_file_table__ + 10560) );
return result;
}

original_code:
static void
InitFileTable(void)
{
  int i;
  for(i = 0; i < 10; i++)
    {
      __file_table__[i].device = -1;
      __file_table__[i].count = 0;
      __file_table__[i].length = 0;
      __file_table__[i].bufsize = 1024;
    }
}

canonical_original_code:
static void InitFileTable()
{
  int i;
  for(i = 0; i < 10; i++)
    {
      __file_table__[i].device = -1;
      __file_table__[i].count = 0;
      __file_table__[i].length = 0;
      __file_table__[i].bufsize = 1024;
    }
}

variable_types: i int


decompiled_code:
__int64 __fastcall open_device(__int64 a1, _DWORD *a2, _QWORD *a3)
{
__int64 *v4; // rdx
__int64 v5; // rax
unsigned int v6; // edx
unsigned int v7; // eax

*a3 = 0LL;
v4 = _file_table__;
v5 = 0LL;
while ( *(_DWORD *)v4 != -1 )
{
*a3 = ++v5;
v4 += 132;
if ( v5 == 10 )
{
dbg_printf("init: File table exhaust.", a2, v4);
return (unsigned int)-10;
}
}
v7 = find_port(a1, a2);
v6 = v7;
if ( v7 )
{
dbg_printf("init: Port not found.", a2, v7);
v6 = -63;
}
else
{
LODWORD(_file_table__[132 * *a3]) = *a2;
_file_table__[132 * *a3 + 1] = 0LL;
_file_table__[132 * *a3 + 2] = 0LL;
_file_table__[132 * *a3 + 3] = 1024LL;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2, _QWORD *a3)
{
__int64 *v4; // rdx
__int64 v5; // rax
unsigned int v6; // edx
unsigned int v7; // eax

*a3 = 0LL;
v4 = _file_table__;
v5 = 0LL;
while ( *(_DWORD *)v4 != -1 )
{
*a3 = ++v5;
v4 += 132;
if ( v5 == 10 )
{
dbg_printf("init: File table exhaust.", a2, v4);
return (unsigned int)-10;
}
}
v7 = find_port(a1, a2);
v6 = v7;
if ( v7 )
{
dbg_printf("init: Port not found.", a2, v7);
v6 = -63;
}
else
{
LODWORD(_file_table__[132 * *a3]) = *a2;
_file_table__[132 * *a3 + 1] = 0LL;
_file_table__[132 * *a3 + 2] = 0LL;
_file_table__[132 * *a3 + 3] = 1024LL;
}
return v6;
}

original_code:
ER
open_device (B *dev_name, ID *id, W *dev_desc)
{
  for(*dev_desc = 0;
      (*dev_desc < 10) && (__file_table__[*dev_desc].device != -1);
      (*dev_desc)++)
    {
    }
  if (*dev_desc == 10)
    {
      dbg_printf ("init: File table exhaust.");
      return ((-10));
    }
  if (find_port (dev_name, id) != E_PORT_OK)
    {
      dbg_printf ("init: Port not found.");
      return ((-63));
    }
  __file_table__[*dev_desc].device = *id;
  __file_table__[*dev_desc].count = 0;
  __file_table__[*dev_desc].length = 0;
  __file_table__[*dev_desc].bufsize = 1024;
  return ((0));
}

canonical_original_code:
int open_device(char *dev_name, int *id, long *dev_desc)
{
  for(*dev_desc = 0;
      (*dev_desc < 10) && (__file_table__[*dev_desc].device != -1);
      (*dev_desc)++)
    {
    }
  if (*dev_desc == 10)
    {
      dbg_printf ("init: File table exhaust.");
      return ((-10));
    }
  if (find_port (dev_name, id) != E_PORT_OK)
    {
      dbg_printf ("init: Port not found.");
      return ((-63));
    }
  __file_table__[*dev_desc].device = *id;
  __file_table__[*dev_desc].count = 0;
  __file_table__[*dev_desc].length = 0;
  __file_table__[*dev_desc].bufsize = 1024;
  return ((0));
}

variable_types:
id
int *


decompiled_code:
__int64 __fastcall close_device(__int64 a1)
{
LODWORD(_file_table__[132 * a1]) = -1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
LODWORD(_file_table__[132 * a1]) = -1;
return 0LL;
}

original_code:
ER
close_device (W dev_desc)
{
  __file_table__[dev_desc].device = -1;
  return ((0));
}

canonical_original_code:
int close_device(long dev_desc)
{
  __file_table__[dev_desc].device = -1;
  return ((0));
}


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

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

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


decompiled_code:
__int64 __fastcall find_entry(char *s1)
{
const char *v1; // rbp
__int64 v2; // rbx

v1 = table;
v2 = 0LL;
while ( strncmp(s1, v1, 0x28uLL) )
{
++v2;
v1 += 52;
if ( v2 == 100 )
return -1LL;
}
return v2;
}

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

v1 = table;
v2 = 0LL;
while ( strncmp(s1, v1, 0x28uLL) )
{
++v2;
v1 += 52;
if ( v2 == 100 )
return -1LL;
}
return v2;
}

original_code:
static W
find_entry (PORT_NAME name)
{
  W index;
  for (index = 0; index < 100; index++)
    {
      if (strncmp (name, table[index].name, 40) == 0)
 {
   return (index);
 }
    }
  return (-1);
}

canonical_original_code:
static long find_entry(char name[-1])
{
  long index;
  for (index = 0; index < 100; index++)
    {
      if (strncmp (name, table[index].name, 40) == 0)
 {
   return (index);
 }
    }
  return (-1);
}

variable_types:
name
char [-1]

variable_types: index long


decompiled_code:
void init_regist_table()
{
bzero(table, 0x1450uLL);
}

canonical_decompiled_code:
void func1()
{
bzero(table, 0x1450uLL);
}

original_code:
void
init_regist_table (void)
{
  bzero (table, sizeof (table));
}

canonical_original_code:
void init_regist_table()
{
  bzero (table, sizeof (table));
}


decompiled_code:
__int64 __fastcall regist_database(char *src, int a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax
int *v6; // rax
__int64 v7; // rbx

v4 = find_entry(src);
result = 1LL;
if ( v4 < 0 )
{
v6 = &dword_1CC;
v7 = 0LL;
while ( *v6 )
{
++v7;
v6 += 13;
if ( v7 == 100 )
return 3LL;
}
strncpy(&table[52 * v7], src, 0x29uLL);
*(_DWORD *)&table[52 * v7 + 44] = a2;
dword_1D0[13 * v7] = a3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, int a2, int a3)
{
__int64 v4; // rdx
__int64 result; // rax
int *v6; // rax
__int64 v7; // rbx

v4 = func0(src);
result = 1LL;
if ( v4 < 0 )
{
v6 = &dword_1CC;
v7 = 0LL;
while ( *v6 )
{
++v7;
v6 += 13;
if ( v7 == 100 )
return 3LL;
}
strncpy(&table[52 * v7], src, 0x29uLL);
*(_DWORD *)&table[52 * v7 + 44] = a2;
dword_1D0[13 * v7] = a3;
result = 0LL;
}
return result;
}

original_code:
PORT_MANAGER_ERROR
regist_database (PORT_NAME name, ID port, ID task)
{
  W counter;
  if (find_entry (name) >= 0)
    {
      return (E_PORT_DUPLICATION);
    }
  for (counter = 0; counter < 100; counter++)
    {
      if (table[counter].port == 0)
 {
   strncpy (table[counter].name, name, (40 + 1));
   table[counter].port = port;
   table[counter].task = task;
   return (E_PORT_OK);
 }
    }
  return (E_PORT_FULL);
}

canonical_original_code:
enum port_manager_error_t regist_database(char name[-1], int port, int task)
{
  long counter;
  if (find_entry (name) >= 0)
    {
      return (E_PORT_DUPLICATION);
    }
  for (counter = 0; counter < 100; counter++)
    {
      if (table[counter].port == 0)
 {
   strncpy (table[counter].name, name, (40 + 1));
   table[counter].port = port;
   table[counter].task = task;
   return (E_PORT_OK);
 }
    }
  return (E_PORT_FULL);
}

variable_types: port int

variable_types: task int

variable_types: counter long

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 unregist_database(char *a1, _DWORD *a2, int a3)
{
__int64 v4; // rax
char *v5; // rdx
unsigned int v6; // ecx

v4 = find_entry(a1);
if ( v4 < 0 )
return 2;
v5 = &table[52 * v4];
*a2 = *((_DWORD *)v5 + 11);
v6 = 4;
if ( *((_DWORD *)v5 + 12) == a3 )
{
bzero(&table[52 * v4], 0x34uLL);
v6 = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, _DWORD *a2, int a3)
{
__int64 v4; // rax
char *v5; // rdx
unsigned int v6; // ecx

v4 = func0(a1);
if ( v4 < 0 )
return 2;
v5 = &table[52 * v4];
*a2 = *((_DWORD *)v5 + 11);
v6 = 4;
if ( *((_DWORD *)v5 + 12) == a3 )
{
bzero(&table[52 * v4], 0x34uLL);
v6 = 0;
}
return v6;
}

original_code:
PORT_MANAGER_ERROR
unregist_database (PORT_NAME name, ID *port, ID task)
{
  W index;
  index = find_entry (name);
  if (index < 0)
    {
      return (E_PORT_NOTFOUND);
    }
  *port = table[index].port;
  if (table[index].task != task)
    {
      return (E_PORT_INVALID);
    }
  bzero (&table[index], sizeof (struct data_entry_t));
  return (E_PORT_OK);
}

canonical_original_code:
enum port_manager_error_t unregist_database(char name[-1], int *port, int task)
{
  long index;
  index = find_entry (name);
  if (index < 0)
    {
      return (E_PORT_NOTFOUND);
    }
  *port = table[index].port;
  if (table[index].task != task)
    {
      return (E_PORT_INVALID);
    }
  bzero (&table[index], sizeof (struct data_entry_t));
  return (E_PORT_OK);
}

variable_types:
port
int *

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

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 }


decompiled_code:
__int64 __fastcall find_database(char *a1, _DWORD *a2)
{
__int64 v2; // rax

v2 = find_entry(a1);
if ( v2 == -1 )
return 2LL;
*a2 = dword_1CC[13 * v2];
return 0LL;
}

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

v2 = func0(a1);
if ( v2 == -1 )
return 2LL;
*a2 = dword_1CC[13 * v2];
return 0LL;
}

original_code:
PORT_MANAGER_ERROR
find_database (PORT_NAME name, ID *port)
{
  W index;
  index = find_entry (name);
  if (index == -1)
    {
      return (E_PORT_NOTFOUND);
    }
  *port = table[index].port;
  return (E_PORT_OK);
}

canonical_original_code:
enum port_manager_error_t find_database(char name[-1], int *port)
{
  long index;
  index = find_entry (name);
  if (index == -1)
    {
      return (E_PORT_NOTFOUND);
    }
  *port = table[index].port;
  return (E_PORT_OK);
}


decompiled_code:
__int64 __fastcall erase_cursor(__int64 a1)
{
__int64 *v1; // rdx
__int64 result; // rax

if ( video_mode == 1LL )
{
v1 = &w[11 * a1];
result = draw_istring(
v1[7] * *((int *)v1 + 2) + SLODWORD(w[11 * a1 + 2]) + 1,
v1[8] * *((int *)v1 + 3) + *((int *)v1 + 5) + 1,
&unk_C90,
0LL,
15LL,
0LL);
}
return result;
}

original_code:
void erase_cursor(W winid)
{
  if (video_mode == 1) {
    draw_istring(w[winid].font_w*w[winid].curpos.x + w[winid].x + 1,
   w[winid].font_h*w[winid].curpos.y + w[winid].y + 1,
   " ", 0, 15, 0);
  }
}

canonical_original_code:
void erase_cursor(long winid)
{
  if (video_mode == 1) {
    draw_istring(w[winid].font_w*w[winid].curpos.x + w[winid].x + 1,
   w[winid].font_h*w[winid].curpos.y + w[winid].y + 1,
   " ", 0, 15, 0);
  }
}

variable_types: winid long


decompiled_code:
__int64 __fastcall write_char(unsigned __int8 a1, __int64 a2)
{
__int64 *v3; // r12
__int64 v4; // rax
__int64 v5; // rax
int v6; // edx

if ( a1 > 0x1Fu )
{
if ( (a1 & 0x80u) == 0 )
{
if ( video_mode == 1LL )
{
v3 = &w[11 * a2];
write_vram_xy(w[11 * a2 + 7], w[11 * a2 + 8], a1, 0LL, a2);
v4 = w[11 * a2 + 7] + 1;
w[11 * a2 + 7] = v4;
if ( v4 >= *(int *)v3 )
{
v5 = v3[8] + 1;
v3[8] = v5;
v3[7] = 0LL;
v6 = *((_DWORD *)v3 + 1);
if ( v5 >= v6 )
{
w[11 * a2 + 8] = v6 - 1;
scroll_up(a2);
}
}
}
else
{
write_vram_xy(curpos, qword_C88, a1, 0LL, a2);
if ( ++curpos > 79 )
{
++qword_C88;
curpos = 0LL;
if ( qword_C88 > 24 )
{
qword_C88 = 24LL;
scroll_up(a2);
}
}
}
}
}
else
{
switch ( a1 )
{
case 9u:
next_tab(a2);
break;
case 0xAu:
caridge_return(a2);
break;
case 8u:
backspace(a2);
break;
}
}
if ( video_mode == 1LL )
goto_cursol(w[11 * a2 + 7], w[11 * a2 + 8], a2);
else
goto_cursol(curpos, qword_C88, a2);
return 0LL;
}

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

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

variable_types:
ch
unsigned char


decompiled_code:
__int64 __fastcall clear_wconsole(__int64 a1)
{
__int64 v1; // rbp
__int64 i; // rbx

v1 = 0LL;
if ( video_mode == 1LL )
{
fillbox_vga(
LODWORD(w[11 * a1 + 2]),
HIDWORD(w[11 * a1 + 2]),
LODWORD(w[11 * a1 + 3]),
HIDWORD(w[11 * a1 + 3]),
15LL);
}
else
{
do
{
for ( i = 0LL; i != 80; ++i )
write_vram_xy(i, v1, 32LL, 225LL, a1);
++v1;
}
while ( v1 != 25 );
}
return set_curpos(0LL, 0LL, a1);
}

original_code:
void
clear_wconsole (W winid)
{
  W x, y;
  if (video_mode == 1) {
    fillbox_vga(w[winid].x, w[winid].y, w[winid].width, w[winid].height, 15);
  }
  else {
    for (y = 0; y < 25; y++)
      for (x = 0; x < 80; x++) {
 write_vram_xy (x, y, ' ', 0xE1, winid);
      }
  }
  set_curpos (0, 0, winid);
}

canonical_original_code:
void clear_wconsole(long winid)
{
  long x; long y;
  if (video_mode == 1) {
    fillbox_vga(w[winid].x, w[winid].y, w[winid].width, w[winid].height, 15);
  }
  else {
    for (y = 0; y < 25; y++)
      for (x = 0; x < 80; x++) {
 write_vram_xy (x, y, ' ', 0xE1, winid);
      }
  }
  set_curpos (0, 0, winid);
}

variable_types: x long

variable_types: y long


decompiled_code:
__int64 init_tcpip()
{
if ( !initialized )
{
init_timer();
init_link();
init_ip();
init_udp();
init_tcp();
init_arp();
initialized = 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( !initialized )
{
init_timer();
init_link();
init_ip();
init_udp();
init_tcp();
init_arp();
initialized = 1LL;
}
return 0LL;
}

original_code:
ER
init_tcpip ()
{
  if (!initialized)
    {
      init_timer ();
      init_link ();
      init_ip ();
      init_udp ();
      init_tcp ();
      init_arp ();
      initialized = 1;
    }
  return ((0));
}

canonical_original_code:
int init_tcpip()
{
  if (!initialized)
    {
      init_timer ();
      init_link ();
      init_ip ();
      init_udp ();
      init_tcp ();
      init_arp ();
      initialized = 1;
    }
  return ((0));
}


startup

decompiled_code:
void __noreturn startup()
{
if ( (unsigned int)init_tcpip() )
{
dbg_printf("TCP/IP: Can not start task(s).\n");
slp_tsk();
}
while ( 1 )
slp_tsk();
}

canonical_decompiled_code:
void __noreturn func1()
{
if ( (unsigned int)func0() )
{
dbg_printf("TCP/IP: Can not start task(s).\n");
slp_tsk();
}
while ( 1 )
slp_tsk();
}

original_code:
ER
startup ()
{
  if (init_tcpip () != (0))
    {
      dbg_printf ("TCP/IP: Can not start task(s).\n");
      slp_tsk ();
    }
  for (;;)
    {
      slp_tsk ();
    }
}

canonical_original_code:
int startup()
{
  if (init_tcpip () != (0))
    {
      dbg_printf ("TCP/IP: Can not start task(s).\n");
      slp_tsk ();
    }
  for (;;)
    {
      slp_tsk ();
    }
}


decompiled_code:
__int64 __fastcall get_config_data(__int64 a1, __int16 a2, __int16 a3, __int16 a4)
{
outl(0xCF8u, (a2 << 11) | (a3 << 8) | (4 * a4));
return (int)inl(0xCFCu);
}

original_code:
UW get_config_data(int iBusNum, int iDevNum, int iFuncNum, int iRegAddr)
{
  UW config_addr;
  UW config_data;
  config_addr = ((0x8000 | iBusNum) << 16) |
    (iDevNum << 11) |
      (iFuncNum << 8) |
 (iRegAddr << 2);
  outl(0x0CF8, config_addr);
  config_data = inl(0x0CFC);
  return config_data;
}

canonical_original_code:
unsigned long get_config_data(int iBusNum, int iDevNum, int iFuncNum, int iRegAddr)
{
  unsigned long config_addr;
  unsigned long config_data;
  config_addr = ((0x8000 | iBusNum) << 16) |
    (iDevNum << 11) |
      (iFuncNum << 8) |
 (iRegAddr << 2);
  outl(0x0CF8, config_addr);
  config_data = inl(0x0CFC);
  return config_data;
}

variable_types: iBusNum int

variable_types: iDevNum int

variable_types: iFuncNum int

variable_types: iRegAddr int

return_type: unsigned long


probe

decompiled_code:
__int64 probe()
{
unsigned int i; // ebp
unsigned int j; // ebx

dbg_printf("HCM_PCI: start probing.\n");
for ( i = 0; i != 255; ++i )
{
for ( j = 0; j != 31; ++j )
{
if ( (unsigned __int16)get_config_data(i, j, 0, 0) != 0xFFFF )
dbg_printf("HCM_PCI: Device found at BUS=%d DEV=%d\n", i, j);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int i; // ebp
unsigned int j; // ebx

dbg_printf("HCM_PCI: start probing.\n");
for ( i = 0; i != 255; ++i )
{
for ( j = 0; j != 31; ++j )
{
if ( (unsigned __int16)func0(i, j, 0, 0) != 0xFFFF )
dbg_printf("HCM_PCI: Device found at BUS=%d DEV=%d\n", i, j);
}
}
return 0LL;
}

original_code:
ER
probe (struct device *dev)
{
  int i;
  int j;
  UW config_data;
  dbg_printf("HCM_PCI: start probing.\n");
  for(i = 0; i < 0xFF; i++)
    {
      for(j = 0; j < 0x1F; j++)
 {
   config_data =
     get_config_data(i, j, 0, 0);
   if ((config_data & 0xFFFF) == 0xFFFF)
     {
       continue;
     }
   dbg_printf("HCM_PCI: Device found at BUS=%d DEV=%d\n", i, j);
 }
    }
  return ((0));
}

canonical_original_code:
int probe(struct device *dev)
{
  int i;
  int j;
  unsigned long config_data;
  dbg_printf("HCM_PCI: start probing.\n");
  for(i = 0; i < 0xFF; i++)
    {
      for(j = 0; j < 0x1F; j++)
 {
   config_data =
     get_config_data(i, j, 0, 0);
   if ((config_data & 0xFFFF) == 0xFFFF)
     {
       continue;
     }
   dbg_printf("HCM_PCI: Device found at BUS=%d DEV=%d\n", i, j);
 }
    }
  return ((0));
}

variable_types: struct device { unsigned long uwBusNumber; unsigned long uwDeviceNumber; unsigned long uwFunctionNumber; unsigned short uhVendorID; unsigned short uhDeviceID; unsigned long uwRevisionID; } *

variable_types: j int


close

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

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

original_code:
int
close (int fd)
{
  return (call_lowlib (5, fd));
}

canonical_original_code:
int close(int fd)
{
  return (call_lowlib (5, fd));
}

variable_types: fd int


geteuid

decompiled_code:
__int64 geteuid()
{
return call_lowlib(14LL);
}

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

original_code:
int
geteuid (void)
{
  return (call_lowlib (14));
}

canonical_original_code:
int geteuid()
{
  return (call_lowlib (14));
}


decompiled_code:
__int64 __fastcall posix_ls(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx

v2 = open(*(const char **)(a2 + 8), 0, 0LL);
v3 = v2;
if ( v2 < 0LL )
{
printf("cannot file open.\n");
}
else if ( stat((const char *)v2, &st_3) )
{
printf("cannot stat for file.\n");
}
else
{
if ( (byte_BD1 & 0x10) != 0 )
printf("%s %d/%d %d bytes\n", *(const char **)(a2 + 8), qword_BE0, qword_BE8, qword_BF8);
close(v3);
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx

v2 = open(*(const char **)(a2 + 8), 0, 0LL);
v3 = v2;
if ( v2 < 0LL )
{
printf("cannot file open.\n");
}
else if ( stat((const char *)v2, &st_3) )
{
printf("cannot stat for file.\n");
}
else
{
if ( (byte_BD1 & 0x10) != 0 )
printf("%s %d/%d %d bytes\n", *(const char **)(a2 + 8), qword_BE0, qword_BE8, qword_BF8);
close(v3);
v3 = 0LL;
}
return v3;
}

original_code:
W
posix_ls (W ac, B **av)
{
  W fd;
  static struct stat st;
  fd = open (av[1], 0x00, 0);
  if (fd < 0)
    {
      printf ("cannot file open.\n");
      return (fd);
    }
  if (stat (fd, &st))
    {
      printf ("cannot stat for file.\n");
      return (fd);
    }
  if (st.st_size < 0)
    {
      printf ("file size is 0.\n");
      return (0);
    }
  if (st.st_mode & (0010000))
    {
      printf ("%s %d/%d %d bytes\n", av[1], st.st_uid, st.st_gid, st.st_size);
    }
  else if (st.st_mode & (0020000))
    {
    }
  close (fd);
  return (0);
}

canonical_original_code:
long posix_ls(long ac, char **av)
{
  long fd;
  static struct stat st;
  fd = open (av[1], 0x00, 0);
  if (fd < 0)
    {
      printf ("cannot file open.\n");
      return (fd);
    }
  if (stat (fd, &st))
    {
      printf ("cannot stat for file.\n");
      return (fd);
    }
  if (st.st_size < 0)
    {
      printf ("file size is 0.\n");
      return (0);
    }
  if (st.st_mode & (0010000))
    {
      printf ("%s %d/%d %d bytes\n", av[1], st.st_uid, st.st_gid, st.st_size);
    }
  else if (st.st_mode & (0020000))
    {
    }
  close (fd);
  return (0);
}

variable_types: ac long

variable_types:
av
char **

variable_types: fd long

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_mode; unsigned long st_nlink; unsigned long st_uid; unsigned long st_gid; unsigned long st_rdev; unsigned long st_size; unsigned long st_blksize; unsigned long st_blocks; unsigned long st_atime; unsigned long st_mtime; unsigned long st_ctime; }


decompiled_code:
__int64 __fastcall posix_cat(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // ebx
__int64 v4; // r13
unsigned int v5; // er14
int v6; // eax
__off_t v7; // rbx
__int64 i; // r12
int v10; // eax
__int64 v11; // rbp
__int64 v12; // rbx

v2 = open(*(const char **)(a2 + 8), 0, 0LL);
v3 = v2;
v4 = v2;
if ( v2 < 0LL )
{
printf("cannot file open.\n");
v5 = v3;
}
else
{
v5 = stat((const char *)v2, &st_2);
if ( v5 )
{
printf("cannot stat for file.\n");
v5 = v3;
}
else
{
if ( a1 <= 2 )
{
v7 = 0LL;
}
else
{
v6 = atoi(*(const char **)(a2 + 16));
v7 = v6;
if ( qword_B78 < (unsigned __int64)v6 )
{
printf("offset overflow\n");
return (unsigned int)-33;
}
printf("lseek: offset = %d, mode = %d\n", v6, 0LL);
if ( (unsigned int)lseek(v4, v7, 0) )
{
printf("cannot lseek.\n");
return (unsigned int)-5;
}
printf("lseek success.\n");
}
printf("file size is = %d\n", qword_B78);
for ( i = qword_B78 - v7; i > 0; i -= v12 )
{
printf("read: %d, 0x%x, %d\n", v4, buf_1, 1024LL);
v10 = read(v4, buf_1, 0x400uLL);
v11 = v10;
if ( v10 <= 0 )
break;
printf("read size = %d\n", v10);
v12 = 0LL;
do
putc(buf_1[v12++], (FILE *)(unsigned int)((_DWORD)&_file_table__ + 1056));
while ( v11 != v12 );
}
printf("\nread done\n");
close(v4);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // eax
int v3; // ebx
__int64 v4; // r13
unsigned int v5; // er14
int v6; // eax
__off_t v7; // rbx
__int64 i; // r12
int v10; // eax
__int64 v11; // rbp
__int64 v12; // rbx

v2 = open(*(const char **)(a2 + 8), 0, 0LL);
v3 = v2;
v4 = v2;
if ( v2 < 0LL )
{
printf("cannot file open.\n");
v5 = v3;
}
else
{
v5 = stat((const char *)v2, &st_2);
if ( v5 )
{
printf("cannot stat for file.\n");
v5 = v3;
}
else
{
if ( a1 <= 2 )
{
v7 = 0LL;
}
else
{
v6 = atoi(*(const char **)(a2 + 16));
v7 = v6;
if ( qword_B78 < (unsigned __int64)v6 )
{
printf("offset overflow\n");
return (unsigned int)-33;
}
printf("lseek: offset = %d, mode = %d\n", v6, 0LL);
if ( (unsigned int)lseek(v4, v7, 0) )
{
printf("cannot lseek.\n");
return (unsigned int)-5;
}
printf("lseek success.\n");
}
printf("file size is = %d\n", qword_B78);
for ( i = qword_B78 - v7; i > 0; i -= v12 )
{
printf("read: %d, 0x%x, %d\n", v4, buf_1, 1024LL);
v10 = read(v4, buf_1, 0x400uLL);
v11 = v10;
if ( v10 <= 0 )
break;
printf("read size = %d\n", v10);
v12 = 0LL;
do
putc(buf_1[v12++], (FILE *)(unsigned int)((_DWORD)&_file_table__ + 1056));
while ( v11 != v12 );
}
printf("\nread done\n");
close(v4);
}
}
return v5;
}

original_code:
ER
posix_cat (W ac, B **av)
{
  W fd;
  static struct stat st;
  static B buf[1024];
  W length, rlength;
  W i;
  W offset = 0;
  fd = open (av[1], 0x00, 0);
  if (fd < 0)
    {
      printf ("cannot file open.\n");
      return (fd);
    }
  if (stat (fd, &st))
    {
      printf ("cannot stat for file.\n");
      return (fd);
    }
  if (st.st_size < 0)
    {
      printf ("file size is 0.\n");
      return (0);
    }
  if (ac > 2)
    {
      offset = atoi (av[2]);
      if (offset > st.st_size)
 {
   printf ("offset overflow\n");
   return ((-33));
 }
      printf ("lseek: offset = %d, mode = %d\n", offset, 0);
      if (lseek (fd, offset, 0))
 {
   printf ("cannot lseek.\n");
   return ((-5));
 }
      printf ("lseek success.\n");
    }
  printf ("file size is = %d\n", st.st_size);
  for (rlength = st.st_size - offset; rlength > 0; rlength -= length)
    {
      printf ("read: %d, 0x%x, %d\n", fd, buf,sizeof (buf));
      if ((length = read (fd, buf, sizeof (buf))) <= 0)
 {
   break;
 }
      printf ("read size = %d\n", length);
      for (i = 0; i < length; i++)
 {
   putc (buf[i], (&__file_table__[1]));
 }
    }
  printf ("\nread done\n");
  close (fd);
  return (0);
}

canonical_original_code:
int posix_cat(long ac, char **av)
{
  long fd;
  static struct stat st;
  static char buf[1024];
  long length; long rlength;
  long i;
  long offset = 0;
  fd = open (av[1], 0x00, 0);
  if (fd < 0)
    {
      printf ("cannot file open.\n");
      return (fd);
    }
  if (stat (fd, &st))
    {
      printf ("cannot stat for file.\n");
      return (fd);
    }
  if (st.st_size < 0)
    {
      printf ("file size is 0.\n");
      return (0);
    }
  if (ac > 2)
    {
      offset = atoi (av[2]);
      if (offset > st.st_size)
 {
   printf ("offset overflow\n");
   return ((-33));
 }
      printf ("lseek: offset = %d, mode = %d\n", offset, 0);
      if (lseek (fd, offset, 0))
 {
   printf ("cannot lseek.\n");
   return ((-5));
 }
      printf ("lseek success.\n");
    }
  printf ("file size is = %d\n", st.st_size);
  for (rlength = st.st_size - offset; rlength > 0; rlength -= length)
    {
      printf ("read: %d, 0x%x, %d\n", fd, buf,sizeof (buf));
      if ((length = read (fd, buf, sizeof (buf))) <= 0)
 {
   break;
 }
      printf ("read size = %d\n", length);
      for (i = 0; i < length; i++)
 {
   putc (buf[i], (&__file_table__[1]));
 }
    }
  printf ("\nread done\n");
  close (fd);
  return (0);
}

variable_types:
buf
char [1024]

variable_types: length long

variable_types: rlength long

variable_types: i long

variable_types: offset long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_mode; unsigned long st_nlink; unsigned long st_uid; unsigned long st_gid; unsigned long st_rdev; unsigned long st_size; unsigned long st_blksize; unsigned long st_blocks; unsigned long st_atime; unsigned long st_mtime; unsigned long st_ctime; }


decompiled_code:
__int64 p_open()
{
__int64 result; // rax
int oflag[2]; // [rsp+8h] [rbp-120h] BYREF
char file[264]; // [rsp+10h] [rbp-118h] BYREF
__int64 v3[2]; // [rsp+118h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, v3);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(oflag, v3[0]);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, v3);
if ( !(_DWORD)result )
{
result = MitnCell_ToString(file, v3[0], 255LL);
if ( !(_DWORD)result )
{
if ( open(file, oflag[0], 438LL) < 0LL )
{
printf("open failed. %s\n", file);
result = 4294967291LL;
}
else
{
result = MitnCell_GetCellAsLong(v3);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v3[0]);
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
int oflag[2]; // [rsp+8h] [rbp-120h] BYREF
char file[264]; // [rsp+10h] [rbp-118h] BYREF
__int64 v3[2]; // [rsp+118h] [rbp-10h] BYREF

result = MitnStack_Pop(1LL, v3);
if ( !(_DWORD)result )
{
result = MitnCell_GetLongFromCell(oflag, v3[0]);
if ( !(_DWORD)result )
{
result = MitnStack_Pop(1LL, v3);
if ( !(_DWORD)result )
{
result = MitnCell_ToString(file, v3[0], 255LL);
if ( !(_DWORD)result )
{
if ( open(file, oflag[0], 438LL) < 0LL )
{
printf("open failed. %s\n", file);
result = 4294967291LL;
}
else
{
result = MitnCell_GetCellAsLong(v3);
if ( !(_DWORD)result )
result = MitnStack_Push(1LL, v3[0]);
}
}
}
}
}
return result;
}

original_code:
ER
p_open(void)
{
  W fd;
  Cell *c;
  B fname[255];
  ER result;
  W oflag;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&oflag, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_ToString(fname, c, 255);
  if ((result) != (0)) { return (result); };
  fd = open (fname, oflag, 0666);
  if (fd < 0)
    {
      printf("open failed. %s\n", fname);
      return (-5);
    }
  result = MitnCell_GetCellAsLong(&c, fd);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

canonical_original_code:
int p_open()
{
  long fd;
  struct _cell *c;
  char fname[255];
  int result;
  long oflag;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&oflag, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_ToString(fname, c, 255);
  if ((result) != (0)) { return (result); };
  fd = open (fname, oflag, 0666);
  if (fd < 0)
    {
      printf("open failed. %s\n", fname);
      return (-5);
    }
  result = MitnCell_GetCellAsLong(&c, fd);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Push(1, c);
  if ((result) != (0)) { return (result); };
  return (0);
}

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

variable_types:
fname
char [255]

variable_types: result int

variable_types: oflag long


decompiled_code:
__int64 p_close()
{
unsigned int v0; // ebx
int fd[2]; // [rsp+0h] [rbp-18h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v0 = MitnStack_Pop(1LL, &v3);
if ( !v0 )
{
v0 = MitnCell_GetLongFromCell(fd, v3);
if ( !v0 )
close(fd[0]);
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx
int fd[2]; // [rsp+0h] [rbp-18h] BYREF
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v0 = MitnStack_Pop(1LL, &v3);
if ( !v0 )
{
v0 = MitnCell_GetLongFromCell(fd, v3);
if ( !v0 )
close(fd[0]);
}
return v0;
}

original_code:
ER
p_close(void)
{
  Cell *c;
  long fd;
  ER result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&fd, c);
  if ((result) != (0)) { return (result); };
  close(fd);
  return (0);
}

canonical_original_code:
int p_close()
{
  struct _cell *c;
  long fd;
  int result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&fd, c);
  if ((result) != (0)) { return (result); };
  close(fd);
  return (0);
}


decompiled_code:
__int64 p_write()
{
unsigned int v0; // ebx
size_t v2; // rax
int fd[2]; // [rsp+8h] [rbp-120h] BYREF
char s[264]; // [rsp+10h] [rbp-118h] BYREF
__int64 v5[2]; // [rsp+118h] [rbp-10h] BYREF

v0 = MitnStack_Pop(1LL, v5);
if ( !v0 )
{
v0 = MitnCell_GetLongFromCell(fd, v5[0]);
if ( !v0 )
{
v0 = MitnStack_Pop(1LL, v5);
if ( !v0 )
{
v0 = MitnCell_ToString(s, v5[0], 255LL);
if ( !v0 )
{
v2 = strlen(s);
if ( (int)write(fd[0], s, v2) < 0 )
v0 = -5;
}
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // ebx
size_t v2; // rax
int fd[2]; // [rsp+8h] [rbp-120h] BYREF
char s[264]; // [rsp+10h] [rbp-118h] BYREF
__int64 v5[2]; // [rsp+118h] [rbp-10h] BYREF

v0 = MitnStack_Pop(1LL, v5);
if ( !v0 )
{
v0 = MitnCell_GetLongFromCell(fd, v5[0]);
if ( !v0 )
{
v0 = MitnStack_Pop(1LL, v5);
if ( !v0 )
{
v0 = MitnCell_ToString(s, v5[0], 255LL);
if ( !v0 )
{
v2 = strlen(s);
if ( (int)write(fd[0], s, v2) < 0 )
v0 = -5;
}
}
}
}
return v0;
}

original_code:
ER
p_write(void)
{
  Cell *c;
  B str[255];
  long fd;
  ER result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&fd, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_ToString(str, c, 255);
  if ((result) != (0)) { return (result); };
  if (write (fd, str, strlen(str)) < 0)
    {
      return (-5);
    }
  return (0);
}

canonical_original_code:
int p_write()
{
  struct _cell *c;
  char str[255];
  long fd;
  int result;
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_GetLongFromCell(&fd, c);
  if ((result) != (0)) { return (result); };
  result = MitnStack_Pop(1, &c);
  if ((result) != (0)) { return (result); };
  result = MitnCell_ToString(str, c, 255);
  if ((result) != (0)) { return (result); };
  if (write (fd, str, strlen(str)) < 0)
    {
      return (-5);
    }
  return (0);
}

variable_types:
str
char [255]


decompiled_code:
__int64 __fastcall posix_writefile(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
const char *v3; // rbp
size_t v4; // rax
__int64 result; // rax

v2 = open(*(const char **)(a2 + 8), 10, 438LL);
if ( v2 < 0 )
{
printf("cannot open file. %s\n", *(const char **)(a2 + 8));
result = 4294967291LL;
}
else
{
v3 = *(const char **)(a2 + 16);
v4 = strlen(v3);
if ( (int)write(v2, v3, v4) < 0 )
{
result = 4294967291LL;
}
else
{
close(v2);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
const char *v3; // rbp
size_t v4; // rax
__int64 result; // rax

v2 = open(*(const char **)(a2 + 8), 10, 438LL);
if ( v2 < 0 )
{
printf("cannot open file. %s\n", *(const char **)(a2 + 8));
result = 4294967291LL;
}
else
{
v3 = *(const char **)(a2 + 16);
v4 = strlen(v3);
if ( (int)write(v2, v3, v4) < 0 )
{
result = 4294967291LL;
}
else
{
close(v2);
result = 0LL;
}
}
return result;
}

original_code:
ER
posix_writefile (W ac, B **av)
{
  W fd;
  fd = open (av[1], 0x08|0x02, 0666);
  if (fd < 0)
    {
      printf ("cannot open file. %s\n", av[1]);
      return (-5);
    }
  if (write (fd, av[2], strlen(av[2])) < 0)
    {
      return (-5);
    }
  close(fd);
  return (0);
}

canonical_original_code:
int posix_writefile(long ac, char **av)
{
  long fd;
  fd = open (av[1], 0x08|0x02, 0666);
  if (fd < 0)
    {
      printf ("cannot open file. %s\n", av[1]);
      return (-5);
    }
  if (write (fd, av[2], strlen(av[2])) < 0)
    {
      return (-5);
    }
  close(fd);
  return (0);
}


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

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

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

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

variable_types:
argp
void *

variable_types:
args
struct a {  } *


chdir

decompiled_code:
__int64 __fastcall chdir(__int64 a1)
{
return CALL_SYSCALL(3LL, a1);
}

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

original_code:
int
chdir (char *path)
{
  return (call_lowlib (2, strlen (path), path));
}

canonical_original_code:
int chdir(char *path)
{
  return (call_lowlib (2, strlen (path), path));
}

variable_types:
path
char *


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

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

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


getpid

decompiled_code:
void getpid()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int
getpid (void)
{
  return (call_lowlib (17));
}

canonical_original_code:
int getpid()
{
  return (call_lowlib (17));
}


sigsetjmp

decompiled_code:
__int64 sigsetjmp()
{
return call_lowlib(64LL);
}

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

original_code:
int
sigsetjmp (void)
{
  return (call_lowlib (64));
}

canonical_original_code:
int sigsetjmp()
{
  return (call_lowlib (64));
}


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

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

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


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

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

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


creat

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

v2 = strlen(a1);
return call_lowlib(6LL, 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(6LL, v2, a1, a2);
}

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

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

variable_types: mode int


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

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

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


setgid

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

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

original_code:
int
setgid (int gid)
{
  return (call_lowlib (28, gid));
}

canonical_original_code:
int setgid(int gid)
{
  return (call_lowlib (28, gid));
}

variable_types: gid int


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

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

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


unlink

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

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

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

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

original_code:
int
unlink (char *path)
{
  return (call_lowlib (36, strlen (path), path));
}

canonical_original_code:
int unlink(char *path)
{
  return (call_lowlib (36, strlen (path), path));
}


decompiled_code:
__int64 __fastcall recv_port_manager(__int64 a1, int a2, int a3)
{
int v4[4]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = a2;
v4[1] = a3;
return snd_mbf(a1, 8LL, v4);
}

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

v4[0] = a2;
v4[1] = a3;
return snd_mbf(a1, 8LL, v4);
}

original_code:
static void
recv_port_manager (ID rport, PORT_MANAGER_ERROR errno, ID port)
{
  struct recv_port_message_t recv_msg;
  recv_msg.error = errno;
  recv_msg.port = port;
  snd_mbf (rport, sizeof (recv_msg), &recv_msg);
}

canonical_original_code:
static void recv_port_manager(int rport, enum port_manager_error_t errno, int port)
{
  struct recv_port_message_t recv_msg;
  recv_msg.error = errno;
  recv_msg.port = port;
  snd_mbf (rport, sizeof (recv_msg), &recv_msg);
}

variable_types: rport int

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

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


decompiled_code:
__int64 __fastcall regist_port(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = regist_database(a1 + 24, *(unsigned int *)(a1 + 68), *(unsigned int *)(a1 + 72));
if ( v1 )
result = recv_port_manager(*(unsigned int *)(a1 + 16), v1, 0);
else
result = recv_port_manager(*(unsigned int *)(a1 + 16), 0, *(_DWORD *)(a1 + 68));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = regist_database(a1 + 24, *(unsigned int *)(a1 + 68), *(unsigned int *)(a1 + 72));
if ( v1 )
result = func0(*(unsigned int *)(a1 + 16), v1, 0);
else
result = func0(*(unsigned int *)(a1 + 16), 0, *(_DWORD *)(a1 + 68));
return result;
}

original_code:
void
regist_port (struct port_manager_msg_t *msgp)
{
  PORT_MANAGER_ERROR errno;
  errno = regist_database (msgp->body.regist.name,
      msgp->body.regist.port,
      msgp->body.regist.task);
  if (errno == E_PORT_OK)
    {
      recv_port_manager (msgp->hdr.rport,
    errno,
    msgp->body.regist.port);
    }
  else
    {
      recv_port_manager (msgp->hdr.rport, errno, 0);
    }
}

canonical_original_code:
void regist_port(struct port_manager_msg_t *msgp)
{
  enum port_manager_error_t errno;
  errno = regist_database (msgp->body.regist.name,
      msgp->body.regist.port,
      msgp->body.regist.task);
  if (errno == E_PORT_OK)
    {
      recv_port_manager (msgp->hdr.rport,
    errno,
    msgp->body.regist.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 }

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