decompiled_code:
unsigned __int64 __fastcall safe_read(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
ssize_t v5; // rax

if ( !a3 )
return 0LL;
v4 = 0LL;
do
{
v5 = read(fd, (void *)(a2 + v4), a3 - v4);
if ( !v5 )
break;
if ( v5 >= 0 )
{
v4 += v5;
}
else if ( *_errno_location() != 4 )
{
return -1LL;
}
}
while ( a3 > v4 );
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
ssize_t v5; // rax

if ( !a3 )
return 0LL;
v4 = 0LL;
do
{
v5 = read(fd, (void *)(a2 + v4), a3 - v4);
if ( !v5 )
break;
if ( v5 >= 0 )
{
v4 += v5;
}
else if ( *_errno_location() != 4 )
{
return -1LL;
}
}
while ( a3 > v4 );
return v4;
}

original_code:
ssize_t
safe_read (int fd, void *buf, size_t count)
{
 ssize_t r;
 size_t reads = 0;
 while (reads < count &&
        (r = read(fd, (char *)buf + reads, count - reads)) != 0)
 {
  if (r < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -1;
  }
  reads += r;
 }
 return reads;
}

canonical_original_code:
long safe_read(int fd, void *buf, unsigned long count)
{
 long r;
 unsigned long reads = 0;
 while (reads < count &&
        (r = read(fd, (char *)buf + reads, count - reads)) != 0)
 {
  if (r < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -1;
  }
  reads += r;
 }
 return reads;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: r long

variable_types:
reads
unsigned long


decompiled_code:
unsigned __int64 __fastcall safe_write(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
ssize_t v5; // rax

if ( !a3 )
return 0LL;
v4 = 0LL;
do
{
v5 = write(fd, (const void *)(a2 + v4), a3 - v4);
if ( !v5 )
break;
if ( v5 >= 0 )
{
v4 += v5;
}
else if ( *_errno_location() != 4 )
{
return -1LL;
}
}
while ( a3 > v4 );
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(int fd, __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
ssize_t v5; // rax

if ( !a3 )
return 0LL;
v4 = 0LL;
do
{
v5 = write(fd, (const void *)(a2 + v4), a3 - v4);
if ( !v5 )
break;
if ( v5 >= 0 )
{
v4 += v5;
}
else if ( *_errno_location() != 4 )
{
return -1LL;
}
}
while ( a3 > v4 );
return v4;
}

original_code:
ssize_t
safe_write (int fd, const void *buf, size_t count)
{
 ssize_t w;
 size_t written = 0;
 while (written < count &&
        (w = write(fd, (char *)buf + written, count - written)) != 0)
 {
  if (w < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -1;
  }
  written += w;
 }
 return written;
}

canonical_original_code:
long safe_write(int fd, void *buf, unsigned long count)
{
 long w;
 unsigned long written = 0;
 while (written < count &&
        (w = write(fd, (char *)buf + written, count - written)) != 0)
 {
  if (w < 0) {
   if ((*__errno_location ()) == 4)
    continue;
   return -1;
  }
  written += w;
 }
 return written;
}

variable_types: w long

variable_types:
written
unsigned long

return_type: long


decompiled_code:
unsigned int *__fastcall unspare2_endian_transform(unsigned int *a1)
{
unsigned int *v1; // rax
unsigned int v2; // edx
unsigned int *result; // rax
unsigned int v4; // edx

*a1 = _byteswap_ulong(*a1);
a1[65] = _byteswap_ulong(a1[65]);
v1 = a1 + 1;
do
{
v2 = *v1++;
*(v1 - 1) = _byteswap_ulong(v2);
}
while ( a1 + 65 != v1 );
result = a1 + 66;
do
{
v4 = *result;
result += 2;
*(result - 2) = _byteswap_ulong(v4);
*(result - 1) = _byteswap_ulong(*(result - 1));
}
while ( result != a1 + 82 );
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int *a1)
{
unsigned int *v1; // rax
unsigned int v2; // edx
unsigned int *result; // rax
unsigned int v4; // edx

*a1 = _byteswap_ulong(*a1);
a1[65] = _byteswap_ulong(a1[65]);
v1 = a1 + 1;
do
{
v2 = *v1++;
*(v1 - 1) = _byteswap_ulong(v2);
}
while ( a1 + 65 != v1 );
result = a1 + 66;
do
{
v4 = *result;
result += 2;
*(result - 2) = _byteswap_ulong(v4);
*(result - 1) = _byteswap_ulong(*(result - 1));
}
while ( result != a1 + 82 );
return result;
}

original_code:
static void
unspare2_endian_transform (nand_ecclayout_t *oob)
{
 unsigned i, eccpos_entries, oobfree_entries;
 eccpos_entries = sizeof(oob->eccpos) / sizeof(unsigned);
 oobfree_entries = sizeof(oob->oobfree) / sizeof(struct nand_oobfree);
 oob->eccbytes = ((((oob->eccbytes) & 0x000000ff) << 24) | (((oob->eccbytes) & 0x0000ff00) << 8) | (((oob->eccbytes) & 0x00ff0000) >> 8) | (((oob->eccbytes) & 0xff000000) >> 24));
 oob->oobavail = ((((oob->oobavail) & 0x000000ff) << 24) | (((oob->oobavail) & 0x0000ff00) << 8) | (((oob->oobavail) & 0x00ff0000) >> 8) | (((oob->oobavail) & 0xff000000) >> 24));
 for (i = 0; i < eccpos_entries; i++)
  oob->eccpos[i] = ((((oob->eccpos[i]) & 0x000000ff) << 24) | (((oob->eccpos[i]) & 0x0000ff00) << 8) | (((oob->eccpos[i]) & 0x00ff0000) >> 8) | (((oob->eccpos[i]) & 0xff000000) >> 24));
 for (i = 0; i < oobfree_entries; i++) {
  oob->oobfree[i].offset = ((((oob->oobfree[i].offset) & 0x000000ff) << 24) | (((oob->oobfree[i].offset) & 0x0000ff00) << 8) | (((oob->oobfree[i].offset) & 0x00ff0000) >> 8) | (((oob->oobfree[i].offset) & 0xff000000) >> 24));
  oob->oobfree[i].length = ((((oob->oobfree[i].length) & 0x000000ff) << 24) | (((oob->oobfree[i].length) & 0x0000ff00) << 8) | (((oob->oobfree[i].length) & 0x00ff0000) >> 8) | (((oob->oobfree[i].length) & 0xff000000) >> 24));
 }
}

canonical_original_code:
static void unspare2_endian_transform(struct nand_ecclayout_user *oob)
{
 unsigned int i; unsigned int eccpos_entries; unsigned int oobfree_entries;
 eccpos_entries = sizeof(oob->eccpos) / sizeof(unsigned int);
 oobfree_entries = sizeof(oob->oobfree) / sizeof(struct nand_oobfree);
 oob->eccbytes = ((((oob->eccbytes) & 0x000000ff) << 24) | (((oob->eccbytes) & 0x0000ff00) << 8) | (((oob->eccbytes) & 0x00ff0000) >> 8) | (((oob->eccbytes) & 0xff000000) >> 24));
 oob->oobavail = ((((oob->oobavail) & 0x000000ff) << 24) | (((oob->oobavail) & 0x0000ff00) << 8) | (((oob->oobavail) & 0x00ff0000) >> 8) | (((oob->oobavail) & 0xff000000) >> 24));
 for (i = 0; i < eccpos_entries; i++)
  oob->eccpos[i] = ((((oob->eccpos[i]) & 0x000000ff) << 24) | (((oob->eccpos[i]) & 0x0000ff00) << 8) | (((oob->eccpos[i]) & 0x00ff0000) >> 8) | (((oob->eccpos[i]) & 0xff000000) >> 24));
 for (i = 0; i < oobfree_entries; i++) {
  oob->oobfree[i].offset = ((((oob->oobfree[i].offset) & 0x000000ff) << 24) | (((oob->oobfree[i].offset) & 0x0000ff00) << 8) | (((oob->oobfree[i].offset) & 0x00ff0000) >> 8) | (((oob->oobfree[i].offset) & 0xff000000) >> 24));
  oob->oobfree[i].length = ((((oob->oobfree[i].length) & 0x000000ff) << 24) | (((oob->oobfree[i].length) & 0x0000ff00) << 8) | (((oob->oobfree[i].length) & 0x00ff0000) >> 8) | (((oob->oobfree[i].length) & 0xff000000) >> 24));
 }
}

variable_types: struct nand_ecclayout_user { unsigned int eccbytes; unsigned int eccpos[64]; unsigned int oobavail; struct nand_oobfree { unsigned int offset; unsigned int length; } oobfree[8]; } *

variable_types:
i
unsigned int

return_type: void

user_defined_types: struct nand_ecclayout_user { unsigned int eccbytes; unsigned int eccpos[64]; unsigned int oobavail; struct nand_oobfree oobfree[8]; }


decompiled_code:
size_t unspare2_helper()
{
fwrite("Usage: unspare2 devfile imgfile\n", 1uLL, 0x20uLL, stderr);
fwrite("unspare2: A utility to extract the OOB layout\n", 1uLL, 0x2EuLL, stderr);
fprintf(stderr, "version: %s\n", "0.2.8");
fwrite("options:\n", 1uLL, 9uLL, stderr);
fwrite(" -h\t", 1uLL, 4uLL, stderr);
fwrite("display this help message and exit\n", 1uLL, 0x23uLL, stderr);
fwrite(" -e\t", 1uLL, 4uLL, stderr);
return fwrite("convert the endian differed from the local machine\n", 1uLL, 0x33uLL, stderr);
}

canonical_decompiled_code:
size_t func1()
{
fwrite("Usage: unspare2 devfile imgfile\n", 1uLL, 0x20uLL, stderr);
fwrite("unspare2: A utility to extract the OOB layout\n", 1uLL, 0x2EuLL, stderr);
fprintf(stderr, "version: %s\n", "0.2.8");
fwrite("options:\n", 1uLL, 9uLL, stderr);
fwrite(" -h\t", 1uLL, 4uLL, stderr);
fwrite("display this help message and exit\n", 1uLL, 0x23uLL, stderr);
fwrite(" -e\t", 1uLL, 4uLL, stderr);
return fwrite("convert the endian differed from the local machine\n", 1uLL, 0x33uLL, stderr);
}

original_code:
static void
unspare2_helper (void)
{
 fprintf(stderr, "Usage: unspare2 devfile imgfile\n");
 fprintf(stderr, "unspare2: A utility to extract the OOB layout\n");
 fprintf(stderr, "version: %s\n", "0.2.8");
 fprintf(stderr, "options:\n");
 fprintf(stderr, " -h	");
 fprintf(stderr, "display this help message and exit\n");
 fprintf(stderr, " -e	");
 fprintf(stderr, "convert the endian differed from the local machine\n");
}

canonical_original_code:
static void unspare2_helper()
{
 fprintf(stderr, "Usage: unspare2 devfile imgfile\n");
 fprintf(stderr, "unspare2: A utility to extract the OOB layout\n");
 fprintf(stderr, "version: %s\n", "0.2.8");
 fprintf(stderr, "options:\n");
 fprintf(stderr, " -h	");
 fprintf(stderr, "display this help message and exit\n");
 fprintf(stderr, " -e	");
 fprintf(stderr, "convert the endian differed from the local machine\n");
}


decompiled_code:
__int64 __fastcall unspare2_dump(char *file, char *name)
{
int v2; // ebp
unsigned int v3; // er12
int v4; // eax
unsigned int v5; // ebp
unsigned int v7[94]; // [rsp+0h] [rbp-178h] BYREF

memset(v7, 0, 0x148uLL);
v2 = open(file, 2);
if ( v2 < 0 )
fprintf(stderr, "cannot open the device %s\n", file);
v3 = ioctl(v2, 0x81484D11uLL, v7);
if ( (v3 & 0x80000000) != 0 )
{
fwrite("ioctl failed\n", 1uLL, 0xDuLL, stderr);
close(v2);
return v3;
}
close(v2);
if ( !v3 )
{
if ( (unspare2_flags & 1) != 0 )
unspare2_endian_transform(v7);
v4 = open(name, 577, 420LL);
v5 = v4;
if ( v4 < 0 )
{
fprintf(stderr, "cannot open the image %s\n", name);
if ( safe_write(v5, v7, 328LL) == 328 )
{
LABEL_13:
v3 = -1;
close(v5);
unlink(name);
return v3;
}
}
else if ( safe_write((unsigned int)v4, v7, 328LL) == 328 )
{
close(v5);
return v3;
}
fwrite("write oob info back to image failed\n", 1uLL, 0x24uLL, stderr);
goto LABEL_13;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *file, char *name)
{
int v2; // ebp
unsigned int v3; // er12
int v4; // eax
unsigned int v5; // ebp
unsigned int v7[94]; // [rsp+0h] [rbp-178h] BYREF

memset(v7, 0, 0x148uLL);
v2 = open(file, 2);
if ( v2 < 0 )
fprintf(stderr, "cannot open the device %s\n", file);
v3 = ioctl(v2, 0x81484D11uLL, v7);
if ( (v3 & 0x80000000) != 0 )
{
fwrite("ioctl failed\n", 1uLL, 0xDuLL, stderr);
close(v2);
return v3;
}
close(v2);
if ( !v3 )
{
if ( (unspare2_flags & 1) != 0 )
func0(v7);
v4 = open(name, 577, 420LL);
v5 = v4;
if ( v4 < 0 )
{
fprintf(stderr, "cannot open the image %s\n", name);
if ( safe_write(v5, v7, 328LL) == 328 )
{
LABEL_13:
v3 = -1;
close(v5);
unlink(name);
return v3;
}
}
else if ( safe_write((unsigned int)v4, v7, 328LL) == 328 )
{
close(v5);
return v3;
}
fwrite("write oob info back to image failed\n", 1uLL, 0x24uLL, stderr);
goto LABEL_13;
}
return v3;
}

original_code:
static int
unspare2_dump (const char *devfile, const char *imgfile)
{
 int fd, retval = 0;
 ssize_t written;
 nand_ecclayout_t oob;
 memset(&oob, 0, sizeof(nand_ecclayout_t));
 if ((fd = open(devfile, 02)) < 0) {
  retval = -1;
  fprintf(stderr, "cannot open the device %s\n", devfile);
 }
 if ((retval = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('M')) << (0 +8)) | (((17)) << 0) | ((((sizeof(struct nand_ecclayout_user)))) << ((0 +8)+8))), &oob)) < 0)
  fprintf(stderr, "ioctl failed\n");
 close(fd);
 if (retval)
  return retval;
 if ((unspare2_flags & 0x01))
  unspare2_endian_transform(&oob);
 if ((fd = open(imgfile, 01 | 0100 | 01000, 0644)) < 0) {
  retval = -1;
  fprintf(stderr, "cannot open the image %s\n", imgfile);
 }
 written = safe_write(fd, &oob, sizeof(nand_ecclayout_t));
 if (written != sizeof(nand_ecclayout_t)) {
  retval = -1;
  fprintf(stderr, "write oob info back to image failed\n");
 }
 close(fd);
 if (retval)
  unlink(imgfile);
 return retval;
}

canonical_original_code:
static int unspare2_dump(char *devfile, char *imgfile)
{
 int fd; int retval = 0;
 long written;
 struct nand_ecclayout_user oob;
 memset(&oob, 0, sizeof(nand_ecclayout_t));
 if ((fd = open(devfile, 02)) < 0) {
  retval = -1;
  fprintf(stderr, "cannot open the device %s\n", devfile);
 }
 if ((retval = ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('M')) << (0 +8)) | (((17)) << 0) | ((((sizeof(struct nand_ecclayout_user)))) << ((0 +8)+8))), &oob)) < 0)
  fprintf(stderr, "ioctl failed\n");
 close(fd);
 if (retval)
  return retval;
 if ((unspare2_flags & 0x01))
  unspare2_endian_transform(&oob);
 if ((fd = open(imgfile, 01 | 0100 | 01000, 0644)) < 0) {
  retval = -1;
  fprintf(stderr, "cannot open the image %s\n", imgfile);
 }
 written = safe_write(fd, &oob, sizeof(nand_ecclayout_t));
 if (written != sizeof(nand_ecclayout_t)) {
  retval = -1;
  fprintf(stderr, "write oob info back to image failed\n");
 }
 close(fd);
 if (retval)
  unlink(imgfile);
 return retval;
}

variable_types:
devfile
char *

variable_types:
imgfile
char *

variable_types: retval int

variable_types: written long

variable_types: struct nand_ecclayout_user { unsigned int eccbytes; unsigned int eccpos[64]; unsigned int oobavail; struct nand_oobfree { unsigned int offset; unsigned int length; } oobfree[8]; }

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
char *v5; // r13
char *v6; // r14
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

printf("unspare2-%s: OOB extracting tool for yaffs2utils\n", "0.2.8");
if ( getuid() )
fwrite("warning: non-root users\n", 1uLL, 0x18uLL, stderr);
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "he", &long_options_0, longind);
if ( v3 == -1 )
break;
if ( v3 != 101 )
{
unspare2_helper();
if ( v3 == 104 )
v3 = 0;
else
v3 = -1;
return v3;
}
unspare2_flags |= 1u;
}
if ( argc - optind <= 1 )
{
unspare2_helper();
}
else
{
v5 = (char *)argv[optind];
v6 = (char *)argv[optind + 1];
v3 = unspare2_dump(v5, v6);
if ( v3 )
fwrite("failed", 1uLL, 6uLL, stderr);
else
printf("OOB info for %s was saved in %s\n", v5, v6);
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
char *v5; // r13
char *v6; // r14
int longind[11]; // [rsp+Ch] [rbp-2Ch] BYREF

printf("unspare2-%s: OOB extracting tool for yaffs2utils\n", "0.2.8");
if ( getuid() )
fwrite("warning: non-root users\n", 1uLL, 0x18uLL, stderr);
while ( 1 )
{
v3 = getopt_long(argc, (char *const *)argv, "he", &long_options_0, longind);
if ( v3 == -1 )
break;
if ( v3 != 101 )
{
func1();
if ( v3 == 104 )
v3 = 0;
else
v3 = -1;
return v3;
}
unspare2_flags |= 1u;
}
if ( argc - optind <= 1 )
{
func1();
}
else
{
v5 = (char *)argv[optind];
v6 = (char *)argv[optind + 1];
v3 = func2(v5, v6);
if ( v3 )
fwrite("failed", 1uLL, 6uLL, stderr);
else
printf("OOB info for %s was saved in %s\n", v5, v6);
}
return v3;
}

original_code:
int
main (int argc, char **argv)
{
 int retval;
 char *devpath, *imgpath;
 int option, option_index;
 static const char *short_options = "he";
 static const struct option long_options[] = {
  {"help", 0, 0, 'h'},
  {"endian", 0, 0, 'e'},
 };
 printf("unspare2-%s: OOB extracting tool for yaffs2utils\n",
  "0.2.8");
 if (getuid() != 0)
  fprintf(stderr, "warning: non-root users\n");
 while ((option = getopt_long(argc, argv, short_options,
         long_options, &option_index)) != (-1))
 {
  switch (option) {
  case 'e':
   unspare2_flags |= 0x01;
   break;
  case 'h':
   unspare2_helper();
   return 0;
  default:
   unspare2_helper();
   return -1;
  }
 }
 if (argc - optind < 2) {
  unspare2_helper();
  return -1;
 }
 devpath = argv[optind];
 imgpath = argv[optind + 1];
 retval = unspare2_dump(devpath, imgpath);
 if (!retval)
  printf("OOB info for %s was saved in %s\n", devpath, imgpath);
 else
  fprintf(stderr, "failed");
 return retval;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int retval;
 char *devpath; char *imgpath;
 int option; int option_index;
 static char *short_options = "he";
 static struct option long_options[] = {
  {"help", 0, 0, 'h'},
  {"endian", 0, 0, 'e'},
 };
 printf("unspare2-%s: OOB extracting tool for yaffs2utils\n",
  "0.2.8");
 if (getuid() != 0)
  fprintf(stderr, "warning: non-root users\n");
 while ((option = getopt_long(argc, argv, short_options,
         long_options, &option_index)) != (-1))
 {
  switch (option) {
  case 'e':
   unspare2_flags |= 0x01;
   break;
  case 'h':
   unspare2_helper();
   return 0;
  default:
   unspare2_helper();
   return -1;
  }
 }
 if (argc - optind < 2) {
  unspare2_helper();
  return -1;
 }
 devpath = argv[optind];
 imgpath = argv[optind + 1];
 retval = unspare2_dump(devpath, imgpath);
 if (!retval)
  printf("OOB info for %s was saved in %s\n", devpath, imgpath);
 else
  fprintf(stderr, "failed");
 return retval;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
devpath
char *

variable_types:
imgpath
char *

variable_types: option int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


decompiled_code:
unsigned __int64 __fastcall yaffs_pack_tags1(__int64 a1, _DWORD *a2)
{
int v2; // ecx
unsigned __int64 v3; // rax
int v4; // edx
unsigned __int64 result; // rax

v2 = a2[6];
v3 = ((unsigned __int64)(a2[3] & 0x3FF) << 22) | a2[2] & 0xFFFFF | ((unsigned __int64)(a2[7] & 3) << 20);
v4 = a2[1];
*(_DWORD *)(a1 + 8) = -1;
result = ((unsigned __int64)(v2 == 0) << 62) | ((unsigned __int64)(v4 & 0x3FFFF) << 32) | v3;
*(_QWORD *)a1 = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, _DWORD *a2)
{
int v2; // ecx
unsigned __int64 v3; // rax
int v4; // edx
unsigned __int64 result; // rax

v2 = a2[6];
v3 = ((unsigned __int64)(a2[3] & 0x3FF) << 22) | a2[2] & 0xFFFFF | ((unsigned __int64)(a2[7] & 3) << 20);
v4 = a2[1];
*(_DWORD *)(a1 + 8) = -1;
result = ((unsigned __int64)(v2 == 0) << 62) | ((unsigned __int64)(v4 & 0x3FFFF) << 32) | v3;
*(_QWORD *)a1 = result;
return result;
}

original_code:
void yaffs_pack_tags1(struct yaffs_packed_tags1 *pt,
        const struct yaffs_ext_tags *t)
{
 pt->chunk_id = t->chunk_id;
 pt->serial_number = t->serial_number;
 pt->n_bytes = t->n_bytes;
 pt->obj_id = t->obj_id;
 pt->ecc = 0;
 pt->deleted = (t->is_deleted) ? 0 : 1;
 pt->unused_stuff = 0;
 pt->should_be_ff = 0xffffffff;
}

canonical_original_code:
void yaffs_pack_tags1(struct yaffs_packed_tags1 *pt, struct yaffs_ext_tags *t)
{
 pt->chunk_id = t->chunk_id;
 pt->serial_number = t->serial_number;
 pt->n_bytes = t->n_bytes;
 pt->obj_id = t->obj_id;
 pt->ecc = 0;
 pt->deleted = (t->is_deleted) ? 0 : 1;
 pt->unused_stuff = 0;
 pt->should_be_ff = 0xffffffff;
}

variable_types: struct yaffs_packed_tags1 { unsigned int chunk_id; unsigned int serial_number; unsigned int n_bytes; unsigned int obj_id; unsigned int ecc; unsigned int deleted; unsigned int unused_stuff; unsigned int should_be_ff; } *

variable_types: struct yaffs_ext_tags { unsigned int chunk_used; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; enum yaffs_ecc_result { YAFFS_ECC_RESULT_UNKNOWN=0, YAFFS_ECC_RESULT_NO_ERROR=1, YAFFS_ECC_RESULT_FIXED=2, YAFFS_ECC_RESULT_UNFIXED=3 } ecc_result; unsigned int block_bad; unsigned int is_deleted; unsigned int serial_number; unsigned int seq_number; unsigned int extra_available; unsigned int extra_parent_id; unsigned int extra_is_shrink; unsigned int extra_shadows; enum yaffs_obj_type { YAFFS_OBJECT_TYPE_UNKNOWN=0, YAFFS_OBJECT_TYPE_FILE=1, YAFFS_OBJECT_TYPE_SYMLINK=2, YAFFS_OBJECT_TYPE_DIRECTORY=3, YAFFS_OBJECT_TYPE_HARDLINK=4, YAFFS_OBJECT_TYPE_SPECIAL=5 } extra_obj_type; long extra_file_size; unsigned int extra_equiv_id; } *

user_defined_types: struct yaffs_ext_tags { unsigned int chunk_used; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; enum yaffs_ecc_result ecc_result; unsigned int block_bad; unsigned int is_deleted; unsigned int serial_number; unsigned int seq_number; unsigned int extra_available; unsigned int extra_parent_id; unsigned int extra_is_shrink; unsigned int extra_shadows; enum yaffs_obj_type extra_obj_type; long extra_file_size; unsigned int extra_equiv_id; }


original_code:
void yaffs_unpack_tags1(struct yaffs_ext_tags *t,
   const struct yaffs_packed_tags1 *pt)
{
 if (memcmp(all_ff, pt, sizeof(struct yaffs_packed_tags1))) {
  t->block_bad = 0;
  if (pt->should_be_ff != 0xffffffff)
   t->block_bad = 1;
  t->chunk_used = 1;
  t->obj_id = pt->obj_id;
  t->chunk_id = pt->chunk_id;
  t->n_bytes = pt->n_bytes;
  t->ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
  t->is_deleted = (pt->deleted) ? 0 : 1;
  t->serial_number = pt->serial_number;
 } else {
  memset(t, 0, sizeof(struct yaffs_ext_tags));
 }
}

canonical_original_code:
void yaffs_unpack_tags1(struct yaffs_ext_tags *t, struct yaffs_packed_tags1 *pt)
{
 if (memcmp(all_ff, pt, sizeof(struct yaffs_packed_tags1))) {
  t->block_bad = 0;
  if (pt->should_be_ff != 0xffffffff)
   t->block_bad = 1;
  t->chunk_used = 1;
  t->obj_id = pt->obj_id;
  t->chunk_id = pt->chunk_id;
  t->n_bytes = pt->n_bytes;
  t->ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
  t->is_deleted = (pt->deleted) ? 0 : 1;
  t->serial_number = pt->serial_number;
 } else {
  memset(t, 0, sizeof(struct yaffs_ext_tags));
 }
}

user_defined_types: struct yaffs_packed_tags1 { unsigned int chunk_id; unsigned int serial_number; unsigned int n_bytes; unsigned int obj_id; unsigned int ecc; unsigned int deleted; unsigned int unused_stuff; unsigned int should_be_ff; }

user_defined_types: enum yaffs_ecc_result { YAFFS_ECC_RESULT_UNKNOWN=0, YAFFS_ECC_RESULT_NO_ERROR=1, YAFFS_ECC_RESULT_FIXED=2, YAFFS_ECC_RESULT_UNFIXED=3 }

user_defined_types: enum yaffs_obj_type { YAFFS_OBJECT_TYPE_UNKNOWN=0, YAFFS_OBJECT_TYPE_FILE=1, YAFFS_OBJECT_TYPE_SYMLINK=2, YAFFS_OBJECT_TYPE_DIRECTORY=3, YAFFS_OBJECT_TYPE_HARDLINK=4, YAFFS_OBJECT_TYPE_SPECIAL=5 }


original_code:
int yaffs_ecc_correct(unsigned char *data, unsigned char *read_ecc,
        const unsigned char *test_ecc)
{
 unsigned char d0, d1, d2;
 d0 = read_ecc[0] ^ test_ecc[0];
 d1 = read_ecc[1] ^ test_ecc[1];
 d2 = read_ecc[2] ^ test_ecc[2];
 if ((d0 | d1 | d2) == 0)
  return 0;
 if (((d0 ^ (d0 >> 1)) & 0x55) == 0x55 &&
     ((d1 ^ (d1 >> 1)) & 0x55) == 0x55 &&
     ((d2 ^ (d2 >> 1)) & 0x54) == 0x54) {
  unsigned byte;
  unsigned bit;
  bit = byte = 0;
  if (d1 & 0x80)
   byte |= 0x80;
  if (d1 & 0x20)
   byte |= 0x40;
  if (d1 & 0x08)
   byte |= 0x20;
  if (d1 & 0x02)
   byte |= 0x10;
  if (d0 & 0x80)
   byte |= 0x08;
  if (d0 & 0x20)
   byte |= 0x04;
  if (d0 & 0x08)
   byte |= 0x02;
  if (d0 & 0x02)
   byte |= 0x01;
  if (d2 & 0x80)
   bit |= 0x04;
  if (d2 & 0x20)
   bit |= 0x02;
  if (d2 & 0x08)
   bit |= 0x01;
  data[byte] ^= (1 << bit);
  return 1;
 }
 if ((yaffs_hweight8(d0) +
      yaffs_hweight8(d1) +
      yaffs_hweight8(d2)) == 1) {
  read_ecc[0] = test_ecc[0];
  read_ecc[1] = test_ecc[1];
  read_ecc[2] = test_ecc[2];
  return 1;
 }
 return -1;
}

canonical_original_code:
int yaffs_ecc_correct(unsigned char *data, unsigned char *read_ecc, unsigned char *test_ecc)
{
 unsigned char d0; unsigned char d1; unsigned char d2;
 d0 = read_ecc[0] ^ test_ecc[0];
 d1 = read_ecc[1] ^ test_ecc[1];
 d2 = read_ecc[2] ^ test_ecc[2];
 if ((d0 | d1 | d2) == 0)
  return 0;
 if (((d0 ^ (d0 >> 1)) & 0x55) == 0x55 &&
     ((d1 ^ (d1 >> 1)) & 0x55) == 0x55 &&
     ((d2 ^ (d2 >> 1)) & 0x54) == 0x54) {
  unsigned int byte;
  unsigned int bit;
  bit = byte = 0;
  if (d1 & 0x80)
   byte |= 0x80;
  if (d1 & 0x20)
   byte |= 0x40;
  if (d1 & 0x08)
   byte |= 0x20;
  if (d1 & 0x02)
   byte |= 0x10;
  if (d0 & 0x80)
   byte |= 0x08;
  if (d0 & 0x20)
   byte |= 0x04;
  if (d0 & 0x08)
   byte |= 0x02;
  if (d0 & 0x02)
   byte |= 0x01;
  if (d2 & 0x80)
   bit |= 0x04;
  if (d2 & 0x20)
   bit |= 0x02;
  if (d2 & 0x08)
   bit |= 0x01;
  data[byte] ^= (1 << bit);
  return 1;
 }
 if ((yaffs_hweight8(d0) +
      yaffs_hweight8(d1) +
      yaffs_hweight8(d2)) == 1) {
  read_ecc[0] = test_ecc[0];
  read_ecc[1] = test_ecc[1];
  read_ecc[2] = test_ecc[2];
  return 1;
 }
 return -1;
}

variable_types:
data
unsigned char *

variable_types:
byte
unsigned int

variable_types:
bit
unsigned int


original_code:
void yaffs_ecc_calc_other(const unsigned char *data, unsigned n_bytes,
     struct yaffs_ecc_other *ecc_other)
{
 unsigned int i;
 unsigned char col_parity = 0;
 unsigned line_parity = 0;
 unsigned line_parity_prime = 0;
 unsigned char b;
 for (i = 0; i < n_bytes; i++) {
  b = column_parity_table[*data++];
  col_parity ^= b;
  if (b & 0x01) {
   line_parity ^= i;
   line_parity_prime ^= ~i;
  }
 }
 ecc_other->col_parity = (col_parity >> 2) & 0x3f;
 ecc_other->line_parity = line_parity;
 ecc_other->line_parity_prime = line_parity_prime;
}

canonical_original_code:
void yaffs_ecc_calc_other(unsigned char *data, unsigned int n_bytes, struct yaffs_ecc_other *ecc_other)
{
 unsigned int i;
 unsigned char col_parity = 0;
 unsigned int line_parity = 0;
 unsigned int line_parity_prime = 0;
 unsigned char b;
 for (i = 0; i < n_bytes; i++) {
  b = column_parity_table[*data++];
  col_parity ^= b;
  if (b & 0x01) {
   line_parity ^= i;
   line_parity_prime ^= ~i;
  }
 }
 ecc_other->col_parity = (col_parity >> 2) & 0x3f;
 ecc_other->line_parity = line_parity;
 ecc_other->line_parity_prime = line_parity_prime;
}

variable_types: struct yaffs_ecc_other { unsigned char col_parity; unsigned int line_parity; unsigned int line_parity_prime; } *

variable_types:
i
unsigned int

variable_types:
b
unsigned char


decompiled_code:
__int64 __fastcall yaffs_ecc_correct_other(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
__int64 result; // rax
__int64 v8; // rdi
unsigned int v9; // er13
__int64 v10; // rdx
unsigned int v11; // er14
__int64 v12; // r9
int v13; // ebx
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
int v17; // ebx
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r8
unsigned int v21; // ecx

result = 0LL;
v8 = (unsigned int)(*(_DWORD *)(a4 + 4) ^ *((_DWORD *)a3 + 1));
v9 = *(_DWORD *)(a4 + 8) ^ *((_DWORD *)a3 + 2);
v10 = *a3;
LOBYTE(v10) = *(_BYTE *)a4 ^ v10;
v11 = (unsigned __int8)v10;
if ( (unsigned __int8)v10 | v9 | (unsigned int)v8 )
{
v12 = ~v9;
if ( (_DWORD)v12 == (_DWORD)v8 && (((unsigned __int8)v10 ^ ((unsigned __int8)v10 >> 1)) & 0x15) == 21 )
{
v21 = ((unsigned int)v10 >> 3) & 4;
if ( (v10 & 8) != 0 )
v21 = ((unsigned int)v10 >> 3) & 4 | 2;
if ( (v10 & 2) != 0 )
LOBYTE(v21) = v21 | 1;
if ( (unsigned int)v12 < (unsigned int)a2 )
{
*(_BYTE *)(a1 + v12) ^= 1 << v21;
return 1LL;
}
}
else
{
v13 = yaffs_hweight32(v8, a2, v10, (unsigned __int8)v10 | v9 | (unsigned int)v8, a1);
v17 = yaffs_hweight32(v9, a2, v14, v15, v16) + v13;
result = v17 + (unsigned int)yaffs_hweight8(v11, a2, v18, v19, v20);
if ( (_DWORD)result == 1 )
{
*(_QWORD *)a3 = *(_QWORD *)a4;
*((_DWORD *)a3 + 2) = *(_DWORD *)(a4 + 8);
return result;
}
}
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int8 *a3, __int64 a4)
{
__int64 result; // rax
__int64 v8; // rdi
unsigned int v9; // er13
__int64 v10; // rdx
unsigned int v11; // er14
__int64 v12; // r9
int v13; // ebx
__int64 v14; // rdx
__int64 v15; // rcx
__int64 v16; // r8
int v17; // ebx
__int64 v18; // rdx
__int64 v19; // rcx
__int64 v20; // r8
unsigned int v21; // ecx

result = 0LL;
v8 = (unsigned int)(*(_DWORD *)(a4 + 4) ^ *((_DWORD *)a3 + 1));
v9 = *(_DWORD *)(a4 + 8) ^ *((_DWORD *)a3 + 2);
v10 = *a3;
LOBYTE(v10) = *(_BYTE *)a4 ^ v10;
v11 = (unsigned __int8)v10;
if ( (unsigned __int8)v10 | v9 | (unsigned int)v8 )
{
v12 = ~v9;
if ( (_DWORD)v12 == (_DWORD)v8 && (((unsigned __int8)v10 ^ ((unsigned __int8)v10 >> 1)) & 0x15) == 21 )
{
v21 = ((unsigned int)v10 >> 3) & 4;
if ( (v10 & 8) != 0 )
v21 = ((unsigned int)v10 >> 3) & 4 | 2;
if ( (v10 & 2) != 0 )
LOBYTE(v21) = v21 | 1;
if ( (unsigned int)v12 < (unsigned int)a2 )
{
*(_BYTE *)(a1 + v12) ^= 1 << v21;
return 1LL;
}
}
else
{
v13 = yaffs_hweight32(v8, a2, v10, (unsigned __int8)v10 | v9 | (unsigned int)v8, a1);
v17 = yaffs_hweight32(v9, a2, v14, v15, v16) + v13;
result = v17 + (unsigned int)yaffs_hweight8(v11, a2, v18, v19, v20);
if ( (_DWORD)result == 1 )
{
*(_QWORD *)a3 = *(_QWORD *)a4;
*((_DWORD *)a3 + 2) = *(_DWORD *)(a4 + 8);
return result;
}
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int yaffs_ecc_correct_other(unsigned char *data, unsigned n_bytes,
       struct yaffs_ecc_other *read_ecc,
       const struct yaffs_ecc_other *test_ecc)
{
 unsigned char delta_col;
 unsigned delta_line;
 unsigned delta_line_prime;
 unsigned bit;
 delta_col = read_ecc->col_parity ^ test_ecc->col_parity;
 delta_line = read_ecc->line_parity ^ test_ecc->line_parity;
 delta_line_prime =
     read_ecc->line_parity_prime ^ test_ecc->line_parity_prime;
 if ((delta_col | delta_line | delta_line_prime) == 0)
  return 0;
 if (delta_line == ~delta_line_prime &&
     (((delta_col ^ (delta_col >> 1)) & 0x15) == 0x15)) {
  bit = 0;
  if (delta_col & 0x20)
   bit |= 0x04;
  if (delta_col & 0x08)
   bit |= 0x02;
  if (delta_col & 0x02)
   bit |= 0x01;
  if (delta_line >= n_bytes)
   return -1;
  data[delta_line] ^= (1 << bit);
  return 1;
 }
 if ((yaffs_hweight32(delta_line) +
      yaffs_hweight32(delta_line_prime) +
      yaffs_hweight8(delta_col)) == 1) {
  *read_ecc = *test_ecc;
  return 1;
 }
 return -1;
}

canonical_original_code:
int yaffs_ecc_correct_other(unsigned char *data, unsigned int n_bytes, struct yaffs_ecc_other *read_ecc, struct yaffs_ecc_other *test_ecc)
{
 unsigned char delta_col;
 unsigned int delta_line;
 unsigned int delta_line_prime;
 unsigned int bit;
 delta_col = read_ecc->col_parity ^ test_ecc->col_parity;
 delta_line = read_ecc->line_parity ^ test_ecc->line_parity;
 delta_line_prime =
     read_ecc->line_parity_prime ^ test_ecc->line_parity_prime;
 if ((delta_col | delta_line | delta_line_prime) == 0)
  return 0;
 if (delta_line == ~delta_line_prime &&
     (((delta_col ^ (delta_col >> 1)) & 0x15) == 0x15)) {
  bit = 0;
  if (delta_col & 0x20)
   bit |= 0x04;
  if (delta_col & 0x08)
   bit |= 0x02;
  if (delta_col & 0x02)
   bit |= 0x01;
  if (delta_line >= n_bytes)
   return -1;
  data[delta_line] ^= (1 << bit);
  return 1;
 }
 if ((yaffs_hweight32(delta_line) +
      yaffs_hweight32(delta_line_prime) +
      yaffs_hweight8(delta_col)) == 1) {
  *read_ecc = *test_ecc;
  return 1;
 }
 return -1;
}

user_defined_types: struct yaffs_ecc_other { unsigned char col_parity; unsigned int line_parity; unsigned int line_parity_prime; }


variable_types: struct yaffs_obj_hdr { enum yaffs_obj_type { YAFFS_OBJECT_TYPE_UNKNOWN=0, YAFFS_OBJECT_TYPE_FILE=1, YAFFS_OBJECT_TYPE_SYMLINK=2, YAFFS_OBJECT_TYPE_DIRECTORY=3, YAFFS_OBJECT_TYPE_HARDLINK=4, YAFFS_OBJECT_TYPE_SPECIAL=5 } type; int parent_obj_id; unsigned short sum_no_longer_used; char name[-1]; unsigned int yst_mode; unsigned int yst_uid; unsigned int yst_gid; unsigned int yst_atime; unsigned int yst_mtime; unsigned int yst_ctime; unsigned int file_size_low; int equiv_id; char alias[-1]; unsigned int yst_rdev; unsigned int win_ctime[2]; unsigned int win_atime[2]; unsigned int win_mtime[2]; unsigned int inband_shadowed_obj_id; unsigned int inband_is_shrink; unsigned int file_size_high; unsigned int reserved[1]; int shadows_obj; unsigned int is_shrink; } *

user_defined_types: struct yaffs_obj_hdr { enum yaffs_obj_type type; int parent_obj_id; unsigned short sum_no_longer_used; char name[-1]; unsigned int yst_mode; unsigned int yst_uid; unsigned int yst_gid; unsigned int yst_atime; unsigned int yst_mtime; unsigned int yst_ctime; unsigned int file_size_low; int equiv_id; char alias[-1]; unsigned int yst_rdev; unsigned int win_ctime[2]; unsigned int win_atime[2]; unsigned int win_mtime[2]; unsigned int inband_shadowed_obj_id; unsigned int inband_is_shrink; unsigned int file_size_high; unsigned int reserved[1]; int shadows_obj; unsigned int is_shrink; }


variable_types:
reverse
unsigned int

variable_types: union yaffs_tags_union { struct yaffs_tags { unsigned int chunk_id; unsigned int serial_number; unsigned int n_bytes_lsb; unsigned int obj_id; unsigned int ecc; unsigned int n_bytes_msb; } as_tags; unsigned char as_bytes[8]; } *

variable_types:
pb
unsigned char *

variable_types:
tb
unsigned char *

user_defined_types: union yaffs_tags_union { struct yaffs_tags as_tags; unsigned char as_bytes[8]; }


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

*a1 = _byteswap_ulong(*a1);
a1[1] = _byteswap_ulong(a1[1]);
a1[2] = _byteswap_ulong(a1[2]);
result = _byteswap_ulong(a1[3]);
a1[3] = result;
return result;
}

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

*a1 = _byteswap_ulong(*a1);
a1[1] = _byteswap_ulong(a1[1]);
a1[2] = _byteswap_ulong(a1[2]);
result = _byteswap_ulong(a1[3]);
a1[3] = result;
return result;
}

variable_types: struct yaffs_packed_tags2 { struct yaffs_packed_tags2_tags_only { unsigned int seq_number; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; } t; struct yaffs_ecc_other { unsigned char col_parity; unsigned int line_parity; unsigned int line_parity_prime; } ecc; } *

variable_types: struct yaffs_packed_tags2_tags_only { unsigned int seq_number; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; } *

user_defined_types: struct yaffs_packed_tags2 { struct yaffs_packed_tags2_tags_only t; struct yaffs_ecc_other ecc; }


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

*(_DWORD *)(a1 + 20) = _byteswap_ulong(*(_DWORD *)(a1 + 20));
result = _byteswap_ulong(*(_DWORD *)(a1 + 24));
*(_DWORD *)(a1 + 24) = result;
return result;
}

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

*(_DWORD *)(a1 + 20) = _byteswap_ulong(*(_DWORD *)(a1 + 20));
result = _byteswap_ulong(*(_DWORD *)(a1 + 24));
*(_DWORD *)(a1 + 24) = result;
return result;
}

original_code:
void
packedtags2_eccother_endian_transform (struct yaffs_packed_tags2 *t)
{
 struct yaffs_ecc_other *e = &t->ecc;
 e->line_parity = ((((e->line_parity) & 0x000000ff) << 24) | (((e->line_parity) & 0x0000ff00) << 8) | (((e->line_parity) & 0x00ff0000) >> 8) | (((e->line_parity) & 0xff000000) >> 24));
 e->line_parity_prime = ((((e->line_parity_prime) & 0x000000ff) << 24) | (((e->line_parity_prime) & 0x0000ff00) << 8) | (((e->line_parity_prime) & 0x00ff0000) >> 8) | (((e->line_parity_prime) & 0xff000000) >> 24));
}

canonical_original_code:
void packedtags2_eccother_endian_transform(struct yaffs_packed_tags2 *t)
{
 struct yaffs_ecc_other *e = &t->ecc;
 e->line_parity = ((((e->line_parity) & 0x000000ff) << 24) | (((e->line_parity) & 0x0000ff00) << 8) | (((e->line_parity) & 0x00ff0000) >> 8) | (((e->line_parity) & 0xff000000) >> 24));
 e->line_parity_prime = ((((e->line_parity_prime) & 0x000000ff) << 24) | (((e->line_parity_prime) & 0x0000ff00) << 8) | (((e->line_parity_prime) & 0x00ff0000) >> 8) | (((e->line_parity_prime) & 0xff000000) >> 24));
}

user_defined_types: struct yaffs_packed_tags2_tags_only { unsigned int seq_number; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; }


decompiled_code:
__int64 __fastcall yaffs_hweight8(unsigned __int8 a1)
{
return (unsigned int)yaffs_count_bits_table[a1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
return (unsigned int)yaffs_count_bits_table[a1];
}

original_code:
int yaffs_hweight8(u8 x)
{
 int ret_val;
 ret_val = yaffs_count_bits_table[x];
 return ret_val;
}

canonical_original_code:
int yaffs_hweight8(unsigned char x)
{
 int ret_val;
 ret_val = yaffs_count_bits_table[x];
 return ret_val;
}

variable_types:
x
unsigned char


decompiled_code:
__int64 __fastcall yaffs_hweight32(unsigned __int8 a1)
{
unsigned __int8 v1; // ch
unsigned __int8 v2; // ecx^2
unsigned __int8 v3; // cl
int v4; // eax
int v5; // edx

yaffs_hweight8(a1);
yaffs_hweight8(v1);
yaffs_hweight8(v2);
v4 = yaffs_hweight8(v3);
return (unsigned int)(v5 + v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1)
{
unsigned __int8 v1; // ch
unsigned __int8 v2; // ecx^2
unsigned __int8 v3; // cl
int v4; // eax
int v5; // edx

func0(a1);
func0(v1);
func0(v2);
v4 = func0(v3);
return (unsigned int)(v5 + v4);
}

original_code:
int yaffs_hweight32(u32 x)
{
 return yaffs_hweight8(x & 0xff) +
  yaffs_hweight8((x >> 8) & 0xff) +
  yaffs_hweight8((x >> 16) & 0xff) +
  yaffs_hweight8((x >> 24) & 0xff);
}

canonical_original_code:
int yaffs_hweight32(unsigned int x)
{
 return yaffs_hweight8(x & 0xff) +
  yaffs_hweight8((x >> 8) & 0xff) +
  yaffs_hweight8((x >> 16) & 0xff) +
  yaffs_hweight8((x >> 24) & 0xff);
}

variable_types:
x
unsigned int


decompiled_code:
void __fastcall progress_winch_updater(int a1)
{
int v1; // er8
int v2; // eax
char v3[2]; // [rsp+0h] [rbp-10h] BYREF
unsigned __int16 v4; // [rsp+2h] [rbp-Eh]

if ( a1 == 28 )
{
v1 = ioctl(1, 0x5413uLL, v3);
v2 = 80;
if ( v1 >= 0 )
v2 = v4;
yaffs2_progress_columns = v2;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int v1; // er8
int v2; // eax
char v3[2]; // [rsp+0h] [rbp-10h] BYREF
unsigned __int16 v4; // [rsp+2h] [rbp-Eh]

if ( a1 == 28 )
{
v1 = ioctl(1, 0x5413uLL, v3);
v2 = 80;
if ( v1 >= 0 )
v2 = v4;
yaffs2_progress_columns = v2;
}
}

original_code:
static void
progress_winch_updater (int sig)
{
 int retval;
 struct winsize wsize;
 if (sig != 28)
  return;
 retval = ioctl(1, 0x5413, &wsize);
 yaffs2_progress_columns = retval < 0 ? 80 : wsize.ws_col;
}

canonical_original_code:
static void progress_winch_updater(int sig)
{
 int retval;
 struct winsize wsize;
 if (sig != 28)
  return;
 retval = ioctl(1, 0x5413, &wsize);
 yaffs2_progress_columns = retval < 0 ? 80 : wsize.ws_col;
}

variable_types: sig int

variable_types: retval int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
int __fastcall progress_bar(unsigned int a1, unsigned int a2)
{
double v2; // xmm0_8
__m128d v3; // xmm3
__m128d v4; // xmm1
signed int v5; // er15
int v6; // er13
int v7; // ebx
bool v8; // cf
int v9; // ebx

v2 = log10((double)(int)a2);
if ( COERCE_DOUBLE(*(_QWORD *)&v2 & LC1) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = v2;
v4.m128d_f64[0] = (double)(int)v2;
*(_QWORD *)&v2 = COERCE_UNSIGNED_INT64(v4.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v3, v4) & LC2)) | ~LC1 & *(_QWORD *)&v2;
}
v5 = a1 * (yaffs2_progress_columns - (2 * (int)v2 + 10)) / a2;
v6 = yaffs2_progress_columns - (2 * (int)v2 + 10) - v5;
printf("\r[");
v7 = v5 - 1;
if ( v5 > 0 )
{
do
{
putchar(61);
v8 = v7-- == 0;
}
while ( !v8 );
}
v9 = v6 - 1;
if ( v6 > 0 )
{
do
{
putchar(32);
v8 = v9-- == 0;
}
while ( !v8 );
}
printf("] %*u/%*u", (int)v2, a1, (int)v2, a2);
printf(" %3u%%", 100 * a1 / a2);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, unsigned int a2)
{
double v2; // xmm0_8
__m128d v3; // xmm3
__m128d v4; // xmm1
signed int v5; // er15
int v6; // er13
int v7; // ebx
bool v8; // cf
int v9; // ebx

v2 = log10((double)(int)a2);
if ( COERCE_DOUBLE(*(_QWORD *)&v2 & LC1) < 4.503599627370496e15 )
{
v3.m128d_f64[0] = v2;
v4.m128d_f64[0] = (double)(int)v2;
*(_QWORD *)&v2 = COERCE_UNSIGNED_INT64(v4.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v3, v4) & LC2)) | ~LC1 & *(_QWORD *)&v2;
}
v5 = a1 * (yaffs2_progress_columns - (2 * (int)v2 + 10)) / a2;
v6 = yaffs2_progress_columns - (2 * (int)v2 + 10) - v5;
printf("\r[");
v7 = v5 - 1;
if ( v5 > 0 )
{
do
{
putchar(61);
v8 = v7-- == 0;
}
while ( !v8 );
}
v9 = v6 - 1;
if ( v6 > 0 )
{
do
{
putchar(32);
v8 = v9-- == 0;
}
while ( !v8 );
}
printf("] %*u/%*u", (int)v2, a1, (int)v2, a2);
printf(" %3u%%", 100 * a1 / a2);
return fflush(stdout);
}

original_code:
void
progress_bar (unsigned current, unsigned max)
{
 int maxdigits = ceil(log10(max));
 int used = maxdigits * 2 + 10;
 int hashes = (current * (yaffs2_progress_columns - used)) / max;
 int spaces = yaffs2_progress_columns - used - hashes;
 if (yaffs2_progress_columns - used < 0)
  return;
 printf("\r[");
 while (hashes-- > 0)
  putchar('=');
 while (spaces-- > 0)
  putchar(' ');
 printf("] %*u/%*u", maxdigits, current, maxdigits, max);
 printf(" %3u%%", current * 100 / max);
 fflush(stdout);
}

canonical_original_code:
void progress_bar(unsigned int current, unsigned int max)
{
 int maxdigits = ceil(log10(max));
 int used = maxdigits * 2 + 10;
 int hashes = (current * (yaffs2_progress_columns - used)) / max;
 int spaces = yaffs2_progress_columns - used - hashes;
 if (yaffs2_progress_columns - used < 0)
  return;
 printf("\r[");
 while (hashes-- > 0)
  putchar('=');
 while (spaces-- > 0)
  putchar(' ');
 printf("] %*u/%*u", maxdigits, current, maxdigits, max);
 printf(" %3u%%", current * 100 / max);
 fflush(stdout);
}

variable_types:
current
unsigned int

variable_types:
max
unsigned int

variable_types: maxdigits int

variable_types: used int

variable_types: hashes int

variable_types: spaces int


decompiled_code:
__int64 progress_init()
{
progress_winch_updater(28);
signal(28, progress_winch_updater);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
func0(28);
signal(28, progress_winch_updater);
return 0LL;
}

original_code:
int
progress_init (void)
{
 progress_winch_updater(28);
 signal(28, progress_winch_updater);
 return 0;
}

canonical_original_code:
int progress_init()
{
 progress_winch_updater(28);
 signal(28, progress_winch_updater);
 return 0;
}


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

result = 0LL;
if ( !*(_DWORD *)(a1 + 8) && *(_DWORD *)(a1 + 36) )
{
result = 1LL;
if ( *(_DWORD *)(a1 + 52) == 1 )
result = *(_QWORD *)(a1 + 56) >> 31 == 0LL;
}
return result;
}

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

result = 0LL;
if ( !*(_DWORD *)(a1 + 8) && *(_DWORD *)(a1 + 36) )
{
result = 1LL;
if ( *(_DWORD *)(a1 + 52) == 1 )
result = *(_QWORD *)(a1 + 56) >> 31 == 0LL;
}
return result;
}

original_code:
static int yaffs_check_tags_extra_packable(const struct yaffs_ext_tags *t)
{
 if(t->chunk_id != 0 || !t->extra_available)
  return 0;
 if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE &&
     (t->extra_file_size>> 31) != 0)
  return 0;
 return 1;
}

canonical_original_code:
static int yaffs_check_tags_extra_packable(struct yaffs_ext_tags *t)
{
 if(t->chunk_id != 0 || !t->extra_available)
  return 0;
 if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE &&
     (t->extra_file_size>> 31) != 0)
  return 0;
 return 1;
}

variable_types: struct yaffs_ext_tags { unsigned int chunk_used; unsigned int obj_id; unsigned int chunk_id; unsigned int n_bytes; enum yaffs_ecc_result { YAFFS_ECC_RESULT_UNKNOWN=0, YAFFS_ECC_RESULT_NO_ERROR=1, YAFFS_ECC_RESULT_FIXED=2, YAFFS_ECC_RESULT_UNFIXED=3 } ecc_result; unsigned int block_bad; unsigned int is_deleted; unsigned int serial_number; unsigned int seq_number; unsigned int extra_available; unsigned int extra_parent_id; unsigned int extra_is_shrink; unsigned int extra_shadows; enum yaffs_obj_type { YAFFS_OBJECT_TYPE_UNKNOWN=0, YAFFS_OBJECT_TYPE_FILE=1, YAFFS_OBJECT_TYPE_SYMLINK=2, YAFFS_OBJECT_TYPE_DIRECTORY=3, YAFFS_OBJECT_TYPE_HARDLINK=4, YAFFS_OBJECT_TYPE_SPECIAL=5 } extra_obj_type; long extra_file_size; unsigned int extra_equiv_id; } *


original_code:
void yaffs_pack_tags2_tags_only(struct yaffs_packed_tags2_tags_only *ptt,
    const struct yaffs_ext_tags *t)
{
 ptt->chunk_id = t->chunk_id;
 ptt->seq_number = t->seq_number;
 ptt->n_bytes = t->n_bytes;
 ptt->obj_id = t->obj_id;
 if (yaffs_check_tags_extra_packable(t)) {
  ptt->chunk_id = 0x80000000 | t->extra_parent_id;
  if (t->extra_is_shrink)
   ptt->chunk_id |= 0x40000000;
  if (t->extra_shadows)
   ptt->chunk_id |= 0x20000000;
  ptt->obj_id &= ~((0x0f) << (28));
  ptt->obj_id |= (t->extra_obj_type << (28));
  if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
   ptt->n_bytes = t->extra_equiv_id;
  else if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE)
   ptt->n_bytes = (unsigned) t->extra_file_size;
  else
   ptt->n_bytes = 0;
 }
 yaffs_dump_packed_tags2_tags_only(ptt);
 yaffs_dump_tags2(t);
}

canonical_original_code:
void yaffs_pack_tags2_tags_only(struct yaffs_packed_tags2_tags_only *ptt, struct yaffs_ext_tags *t)
{
 ptt->chunk_id = t->chunk_id;
 ptt->seq_number = t->seq_number;
 ptt->n_bytes = t->n_bytes;
 ptt->obj_id = t->obj_id;
 if (yaffs_check_tags_extra_packable(t)) {
  ptt->chunk_id = 0x80000000 | t->extra_parent_id;
  if (t->extra_is_shrink)
   ptt->chunk_id |= 0x40000000;
  if (t->extra_shadows)
   ptt->chunk_id |= 0x20000000;
  ptt->obj_id &= ~((0x0f) << (28));
  ptt->obj_id |= (t->extra_obj_type << (28));
  if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
   ptt->n_bytes = t->extra_equiv_id;
  else if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE)
   ptt->n_bytes = (unsigned int) t->extra_file_size;
  else
   ptt->n_bytes = 0;
 }
 yaffs_dump_packed_tags2_tags_only(ptt);
 yaffs_dump_tags2(t);
}


decompiled_code:
__int64 __fastcall yaffs_pack_tags2(_DWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r10
int v4; // er11

result = yaffs_pack_tags2_tags_only(a1, a2);
if ( v4 )
result = yaffs_ecc_calc_other(v3, 16LL, v3 + 16);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r10
int v4; // er11

result = func1(a1, a2);
if ( v4 )
result = yaffs_ecc_calc_other(v3, 16LL, v3 + 16);
return result;
}

original_code:
void yaffs_pack_tags2(struct yaffs_packed_tags2 *pt,
        const struct yaffs_ext_tags *t, int tags_ecc)
{
 yaffs_pack_tags2_tags_only(&pt->t, t);
 if (tags_ecc)
  yaffs_ecc_calc_other((unsigned char *)&pt->t,
        sizeof(struct yaffs_packed_tags2_tags_only),
        &pt->ecc);
}

canonical_original_code:
void yaffs_pack_tags2(struct yaffs_packed_tags2 *pt, struct yaffs_ext_tags *t, int tags_ecc)
{
 yaffs_pack_tags2_tags_only(&pt->t, t);
 if (tags_ecc)
  yaffs_ecc_calc_other((unsigned char *)&pt->t,
        sizeof(struct yaffs_packed_tags2_tags_only),
        &pt->ecc);
}


original_code:
void yaffs_unpack_tags2_tags_only(struct yaffs_ext_tags *t,
      struct yaffs_packed_tags2_tags_only *ptt)
{
 memset(t, 0, sizeof(struct yaffs_ext_tags));
 if (ptt->seq_number == 0xffffffff)
  return;
 t->block_bad = 0;
 t->chunk_used = 1;
 t->obj_id = ptt->obj_id;
 t->chunk_id = ptt->chunk_id;
 t->n_bytes = ptt->n_bytes;
 t->is_deleted = 0;
 t->serial_number = 0;
 t->seq_number = ptt->seq_number;
 if (ptt->chunk_id & 0x80000000) {
  t->chunk_id = 0;
  t->n_bytes = 0;
  t->extra_available = 1;
  t->extra_parent_id = ptt->chunk_id & (~(0xf0000000));
  t->extra_is_shrink = ptt->chunk_id & 0x40000000 ? 1 : 0;
  t->extra_shadows = ptt->chunk_id & 0x20000000 ? 1 : 0;
  t->extra_obj_type = ptt->obj_id >> (28);
  t->obj_id &= ~((0x0f) << (28));
  if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
   t->extra_equiv_id = ptt->n_bytes;
  else
   t->extra_file_size = ptt->n_bytes;
 }
 yaffs_dump_packed_tags2_tags_only(ptt);
 yaffs_dump_tags2(t);
}


decompiled_code:
void __fastcall yaffs_unpack_tags2(__int64 a1, int *a2, int a3)
{
int v3; // er8
char v4[36]; // [rsp+4h] [rbp-24h] BYREF

if ( *a2 != -1 && a3 )
{
yaffs_ecc_calc_other(a2, 16LL, v4);
yaffs_ecc_correct_other(a2, 16LL, a2 + 4, v4);
}
yaffs_unpack_tags2_tags_only(a1, a2);
*(_DWORD *)(a1 + 16) = v3;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int *a2, int a3)
{
int v3; // er8
char v4[36]; // [rsp+4h] [rbp-24h] BYREF

if ( *a2 != -1 && a3 )
{
yaffs_ecc_calc_other(a2, 16LL, v4);
yaffs_ecc_correct_other(a2, 16LL, a2 + 4, v4);
}
func3(a1, a2);
*(_DWORD *)(a1 + 16) = v3;
}

original_code:
void yaffs_unpack_tags2(struct yaffs_ext_tags *t, struct yaffs_packed_tags2 *pt,
   int tags_ecc)
{
 enum yaffs_ecc_result ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
 if (pt->t.seq_number != 0xffffffff && tags_ecc) {
  struct yaffs_ecc_other ecc;
  int result;
  yaffs_ecc_calc_other((unsigned char *)&pt->t,
    sizeof(struct yaffs_packed_tags2_tags_only),
    &ecc);
  result =
      yaffs_ecc_correct_other((unsigned char *)&pt->t,
    sizeof(struct yaffs_packed_tags2_tags_only),
    &pt->ecc, &ecc);
  switch (result) {
  case 0:
   ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
   break;
  case 1:
   ecc_result = YAFFS_ECC_RESULT_FIXED;
   break;
  case -1:
   ecc_result = YAFFS_ECC_RESULT_UNFIXED;
   break;
  default:
   ecc_result = YAFFS_ECC_RESULT_UNKNOWN;
  }
 }
 yaffs_unpack_tags2_tags_only(t, &pt->t);
 t->ecc_result = ecc_result;
 yaffs_dump_packed_tags2(pt);
 yaffs_dump_tags2(t);
}

variable_types: enum yaffs_ecc_result { YAFFS_ECC_RESULT_UNKNOWN=0, YAFFS_ECC_RESULT_NO_ERROR=1, YAFFS_ECC_RESULT_FIXED=2, YAFFS_ECC_RESULT_UNFIXED=3 }

variable_types: struct yaffs_ecc_other { unsigned char col_parity; unsigned int line_parity; unsigned int line_parity_prime; }

variable_types: result int


repo: juur/FailOS

decompiled_code:
__int64 __fastcall pci_write_conf32(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned int a5)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return outportl(3324LL, a5);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned int a5)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return outportl(3324LL, a5);
}

original_code:
void pci_write_conf32(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t val)
{
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 outportl(0xcfc, val);
}

canonical_original_code:
void pci_write_conf32(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg, unsigned int val)
{
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 outportl(0xcfc, val);
}

variable_types:
bus
unsigned char

variable_types:
dev
unsigned char

variable_types:
func
unsigned char

variable_types:
reg
unsigned char

variable_types:
val
unsigned int

variable_types:
port
unsigned int


decompiled_code:
__int64 __fastcall pci_write_conf16(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int16 a5)
{
int v6; // ebp

v6 = a4 & 2;
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return outportw((unsigned int)(v6 + 3324), a5);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4, unsigned __int16 a5)
{
int v6; // ebp

v6 = a4 & 2;
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return outportw((unsigned int)(v6 + 3324), a5);
}

original_code:
void pci_write_conf16(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t val)
{
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 outportw((uint16_t)(0xcfc + (reg&2)), val);
}

canonical_original_code:
void pci_write_conf16(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg, unsigned short val)
{
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 outportw((unsigned short)(0xcfc + (reg&2)), val);
}

variable_types:
val
unsigned short


decompiled_code:
__int64 __fastcall pci_read_conf32(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportl(3324LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportl(3324LL);
}

original_code:
uint32_t pci_read_conf32(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
{
 uint32_t ret;
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportl(0xcfc);
 return ret;
}

canonical_original_code:
unsigned int pci_read_conf32(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg)
{
 unsigned int ret;
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportl(0xcfc);
 return ret;
}

variable_types:
ret
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall pci_read_conf16(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
int v4; // ebx

v4 = a4 & 2;
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportw((unsigned int)(v4 + 3324));
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
int v4; // ebx

v4 = a4 & 2;
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportw((unsigned int)(v4 + 3324));
}

original_code:
uint16_t pci_read_conf16(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
{
 uint16_t ret;
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportw((uint16_t)(0xcfc + (reg&2)));
 return ret;
}

canonical_original_code:
unsigned short pci_read_conf16(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg)
{
 unsigned short ret;
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportw((unsigned short)(0xcfc + (reg&2)));
 return ret;
}

variable_types:
ret
unsigned short

return_type: unsigned short


decompiled_code:
__int64 __fastcall pci_read_conf8(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
int v4; // ebx

v4 = a4 & 3;
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportb((unsigned int)(v4 + 3324));
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
int v4; // ebx

v4 = a4 & 3;
outportl(3320LL, (a2 << 11) | (a3 << 8) | a4 | (a1 << 16) | 0x80000000);
return inportb((unsigned int)(v4 + 3324));
}

original_code:
uint8_t pci_read_conf8(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
{
 uint8_t ret;
 uint32_t port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportb((uint16_t)(0xcfc + (reg&3)));
 return ret;
}

canonical_original_code:
unsigned char pci_read_conf8(unsigned char bus, unsigned char dev, unsigned char func, unsigned char reg)
{
 unsigned char ret;
 unsigned int port = (0x80000000U)|(bus<<16)|(dev<<11)|(func<<8)|(reg);
 outportl(0xcf8, port);
 ret = inportb((unsigned short)(0xcfc + (reg&3)));
 return ret;
}

variable_types:
ret
unsigned char

return_type: unsigned char


decompiled_code:
int __fastcall print_pci_dev(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rdx
unsigned int *v3; // rbx
unsigned int v4; // ebp
int result; // eax
__int64 v6; // rdx
const char *v7; // r8

printf(
"pci_dev: %x:%x [%x,%x,%x] REV:%x %x:%x",
*(unsigned __int16 *)(a1 + 11),
*(unsigned __int16 *)(a1 + 13),
*(unsigned __int8 *)(a1 + 22),
*(unsigned __int8 *)(a1 + 21),
*(unsigned __int8 *)(a1 + 20),
*(unsigned __int8 *)(a1 + 19),
*(unsigned __int16 *)(a1 + 55),
*(unsigned __int16 *)(a1 + 57));
v1 = *(unsigned __int8 *)(a1 + 71);
v2 = *(unsigned __int8 *)(a1 + 72);
if ( __PAIR16__(v2, v1) )
printf(" int[0x%x,0x%x]", v1, v2);
v3 = (unsigned int *)(a1 + 76);
v4 = 0;
result = printf("\n");
do
{
v6 = *v3;
if ( (_DWORD)v6 )
{
v7 = (const char *)&unk_674;
if ( *((_BYTE *)v3 + 10) )
v7 = (const char *)&unk_670;
result = printf("pci_dev: bar[%x] 0x%x[%x] %s\n", v4, v6, v3[1], v7);
}
++v4;
v3 += 3;
}
while ( v4 != 6 );
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
__int64 v1; // rsi
__int64 v2; // rdx
unsigned int *v3; // rbx
unsigned int v4; // ebp
int result; // eax
__int64 v6; // rdx
const char *v7; // r8

printf(
"pci_dev: %x:%x [%x,%x,%x] REV:%x %x:%x",
*(unsigned __int16 *)(a1 + 11),
*(unsigned __int16 *)(a1 + 13),
*(unsigned __int8 *)(a1 + 22),
*(unsigned __int8 *)(a1 + 21),
*(unsigned __int8 *)(a1 + 20),
*(unsigned __int8 *)(a1 + 19),
*(unsigned __int16 *)(a1 + 55),
*(unsigned __int16 *)(a1 + 57));
v1 = *(unsigned __int8 *)(a1 + 71);
v2 = *(unsigned __int8 *)(a1 + 72);
if ( __PAIR16__(v2, v1) )
printf(" int[0x%x,0x%x]", v1, v2);
v3 = (unsigned int *)(a1 + 76);
v4 = 0;
result = printf("\n");
do
{
v6 = *v3;
if ( (_DWORD)v6 )
{
v7 = (const char *)&unk_674;
if ( *((_BYTE *)v3 + 10) )
v7 = (const char *)&unk_670;
result = printf("pci_dev: bar[%x] 0x%x[%x] %s\n", v4, v6, v3[1], v7);
}
++v4;
v3 += 3;
}
while ( v4 != 6 );
return result;
}

original_code:
void print_pci_dev(struct pci_dev *d)
{
 int i;
 printf("pci_dev: %x:%x [%x,%x,%x] REV:%x %x:%x",
   d->cfg.vendor_id,
   d->cfg.device_id,
   d->cfg.class_code,
   d->cfg.subclass,
   d->cfg.progif,
   d->cfg.rev,
   d->cfg.sub_vendor_id,
   d->cfg.sub_id
    );
 if(d->cfg.int_line || d->cfg.int_pin) {
  printf(" int[0x%x,0x%x]", d->cfg.int_line, d->cfg.int_pin);
 }
 printf("\n");
 for(i=0;i<6;i++)
 {
  if(!d->bars[i].addr) continue;
  printf("pci_dev:   bar[%x] 0x%x[%x] %s\n",
    i, d->bars[i].addr, d->bars[i].len,
    d->bars[i].mem ? "MEM" : "IO");
 }
}

variable_types: struct pci_dev { struct pci_dev *next; unsigned char bus; struct pcicfg { unsigned short vendor_id; unsigned short device_id; unsigned short cmd_reg; unsigned short status_reg; unsigned int rev; unsigned char progif; unsigned char subclass; unsigned char class_code; unsigned char pad0; unsigned char pad1; unsigned char header_type; unsigned char pad2; unsigned int bar[6]; unsigned int pad3; unsigned short sub_vendor_id; unsigned short sub_id; unsigned int pad4; unsigned int pad5; unsigned int res0; unsigned int res1; unsigned char int_line; unsigned char int_pin; unsigned char pad6; unsigned char pad7; } cfg; struct pcibar { unsigned int addr; unsigned int len; union { struct { unsigned char pad; } io; struct { unsigned char bits; unsigned char prefs; } mem; } un; _Bool mem; } bars[6]; } *

variable_types: i int

user_defined_types: struct pci_dev { struct pci_dev *next; unsigned char bus; struct pcicfg cfg; struct pcibar bars[6]; }


original_code:
struct pci_dev *add_pci_device(int bus, int dev, int func)
{
 struct pci_dev *ret;
 uint32_t vend_id,dev_id,class,subclass,prog,rev_id,subsys,subsysvend,header,intr,intrl;
 uint32_t bar_save,bar_addr,bits,pref;
 int bar;
 int tmp,off;
 dev_id = pci_read_conf16(bus,dev,func,0x2);
 vend_id = pci_read_conf16(bus,dev,func,0x0);
 class = pci_read_conf8(bus,dev,func,0x9 +2);
 subclass = pci_read_conf8(bus,dev,func,0x9 +1);
 prog = pci_read_conf8(bus,dev,func,0x9);
 if(class == 0xff && subclass == 0xff) return ((void*)0);
 rev_id = pci_read_conf8(bus,dev,func,0x8);
 subsys = pci_read_conf16(bus,dev,func,0x2e);
 subsysvend = pci_read_conf16(bus,dev,func,0x2c);
 header = pci_read_conf8(bus,dev,func,0xe);
 intr = pci_read_conf8(bus,dev,func,0x3d);
 intrl = pci_read_conf8(bus,dev,func,0x3c);
 if(header != 0x80 && header != 0x00 ) {
  printf("add_pci: %x:%x does not support header=%x PCI-to-PCI/Cardbus\n", vend_id, dev_id, header);
  return ((void*)0);
 }
 ret = kmalloc(sizeof(struct pci_dev),"pcidev", ((void*)0), 0);
 if(!ret) return ((void*)0);
 ret->cfg.vendor_id = vend_id;
 ret->cfg.device_id = dev_id;
 ret->cfg.rev = rev_id;
 ret->cfg.class_code = class;
 ret->cfg.subclass = subclass;
 ret->cfg.progif = prog;
 ret->cfg.header_type = header;
 ret->cfg.sub_vendor_id = subsysvend;
 ret->cfg.sub_id = subsys;
 ret->cfg.int_line = intrl;
 ret->cfg.int_pin = intr;
 ret->bus = bus;
 ret->dev = dev;
 ret->func = func;
 for(bar=0;bar<6;bar++) {
  bar_save = bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
  if(bar_addr == 0x0) {
   continue;
  } else if(bar_addr & 1) {
   ret->bars[bar].mem = 0;
   bar_addr &= 0xfffffffc;
   ret->bars[bar].addr = bar_addr;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)),0xffffffff);
   bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
   bar_addr &= 0xfffffffc;
   ret->bars[bar].len = (~bar_addr)+1;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)), bar_save);
  } else {
   ret->bars[bar].mem = 1;
   ret->bars[bar].un.mem.bits = bits = (bar_addr & 0x06) >> 1;
   ret->bars[bar].un.mem.prefs = pref = (bar_addr & 0x08) >> 3;
   if(bits) {
    printf("PCI: non-32bit BARs unsupported");
    bar = 6;
    continue;
   }
   bar_addr &= 0xfffffff0;
   ret->bars[bar].addr = bar_addr;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)),0xffffffff);
   bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
   bar_addr &= 0xfffffff0;
   ret->bars[bar].len = (~bar_addr)+1;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)), bar_save);
   tmp = ret->bars[bar].len;
   off = 0;
   while(tmp>0) {
    if(!create_page_entry_4k(kernel_pd,
      ret->bars[bar].addr + off,
      ret->bars[bar].addr + off,
      0x001|0x002, ((void*)0)))
     goto fail;
    tmp -= (1024*4);
    off += (1024*4);
   }
  }
 }
 ret->next = pci_devs;
 pci_devs = ret;
 print_pci_dev(ret);
 switch(ret->cfg.vendor_id) {
  case 0x1022:
   switch(ret->cfg.device_id) {
    case 0x2000:
     init_nic_pcnet(ret);
     break;
    default:
     goto unknown;
   }
   break;
  case 0x8086:
   switch(ret->cfg.device_id) {
    case 0x7010:
    case 0x7111:
     if(ret->cfg.class_code == 0x01) {
      init_ide(ret);
      goto unknown;
      break;
     }
     goto unknown;
     break;
    case 0x2922:
     init_ahci(ret);
     break;
    default:
     goto unknown;
   }
   break;
  default:
   goto unknown;
 }
 return(ret);
unknown:
 return(ret);
fail:
 if(ret) kfree(ret);
 return ((void*)0);
}

canonical_original_code:
struct pci_dev *add_pci_device(int bus, int dev, int func)
{
 struct pci_dev *ret;
 unsigned int vend_id; unsigned int dev_id; unsigned int class; unsigned int subclass; unsigned int prog; unsigned int rev_id; unsigned int subsys; unsigned int subsysvend; unsigned int header; unsigned int intr; unsigned int intrl;
 unsigned int bar_save; unsigned int bar_addr; unsigned int bits; unsigned int pref;
 int bar;
 int tmp; int off;
 dev_id = pci_read_conf16(bus,dev,func,0x2);
 vend_id = pci_read_conf16(bus,dev,func,0x0);
 class = pci_read_conf8(bus,dev,func,0x9 +2);
 subclass = pci_read_conf8(bus,dev,func,0x9 +1);
 prog = pci_read_conf8(bus,dev,func,0x9);
 if(class == 0xff && subclass == 0xff) return ((void *)0);
 rev_id = pci_read_conf8(bus,dev,func,0x8);
 subsys = pci_read_conf16(bus,dev,func,0x2e);
 subsysvend = pci_read_conf16(bus,dev,func,0x2c);
 header = pci_read_conf8(bus,dev,func,0xe);
 intr = pci_read_conf8(bus,dev,func,0x3d);
 intrl = pci_read_conf8(bus,dev,func,0x3c);
 if(header != 0x80 && header != 0x00 ) {
  printf("add_pci: %x:%x does not support header=%x PCI-to-PCI/Cardbus\n", vend_id, dev_id, header);
  return ((void *)0);
 }
 ret = kmalloc(sizeof(struct pci_dev),"pcidev", ((void *)0), 0);
 if(!ret) return ((void *)0);
 ret->cfg.vendor_id = vend_id;
 ret->cfg.device_id = dev_id;
 ret->cfg.rev = rev_id;
 ret->cfg.class_code = class;
 ret->cfg.subclass = subclass;
 ret->cfg.progif = prog;
 ret->cfg.header_type = header;
 ret->cfg.sub_vendor_id = subsysvend;
 ret->cfg.sub_id = subsys;
 ret->cfg.int_line = intrl;
 ret->cfg.int_pin = intr;
 ret->bus = bus;
 ret->dev = dev;
 ret->func = func;
 for(bar=0;bar<6;bar++) {
  bar_save = bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
  if(bar_addr == 0x0) {
   continue;
  } else if(bar_addr & 1) {
   ret->bars[bar].mem = 0;
   bar_addr &= 0xfffffffc;
   ret->bars[bar].addr = bar_addr;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)),0xffffffff);
   bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
   bar_addr &= 0xfffffffc;
   ret->bars[bar].len = (~bar_addr)+1;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)), bar_save);
  } else {
   ret->bars[bar].mem = 1;
   ret->bars[bar].un.mem.bits = bits = (bar_addr & 0x06) >> 1;
   ret->bars[bar].un.mem.prefs = pref = (bar_addr & 0x08) >> 3;
   if(bits) {
    printf("PCI: non-32bit BARs unsupported");
    bar = 6;
    continue;
   }
   bar_addr &= 0xfffffff0;
   ret->bars[bar].addr = bar_addr;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)),0xffffffff);
   bar_addr = pci_read_conf32(bus,dev,func,(0x10 +((bar)*0x4)));
   bar_addr &= 0xfffffff0;
   ret->bars[bar].len = (~bar_addr)+1;
   pci_write_conf32(bus,dev,func,(0x10 +((bar)*0x4)), bar_save);
   tmp = ret->bars[bar].len;
   off = 0;
   while(tmp>0) {
    if(!create_page_entry_4k(kernel_pd,
      ret->bars[bar].addr + off,
      ret->bars[bar].addr + off,
      0x001|0x002, ((void *)0)))
     goto fail;
    tmp -= (1024*4);
    off += (1024*4);
   }
  }
 }
 ret->next = pci_devs;
 pci_devs = ret;
 print_pci_dev(ret);
 switch(ret->cfg.vendor_id) {
  case 0x1022:
   switch(ret->cfg.device_id) {
    case 0x2000:
     init_nic_pcnet(ret);
     break;
    default:
     goto unknown;
   }
   break;
  case 0x8086:
   switch(ret->cfg.device_id) {
    case 0x7010:
    case 0x7111:
     if(ret->cfg.class_code == 0x01) {
      init_ide(ret);
      goto unknown;
      break;
     }
     goto unknown;
     break;
    case 0x2922:
     init_ahci(ret);
     break;
    default:
     goto unknown;
   }
   break;
  default:
   goto unknown;
 }
 return(ret);
unknown:
 return(ret);
fail:
 if(ret) kfree(ret);
 return ((void *)0);
}

variable_types: bus int

variable_types: dev int

variable_types: func int

variable_types:
class
unsigned int

variable_types:
subclass
unsigned int

variable_types:
prog
unsigned int

variable_types:
subsys
unsigned int

variable_types:
subsysvend
unsigned int

variable_types:
header
unsigned int

variable_types:
intr
unsigned int

variable_types:
intrl
unsigned int

variable_types:
bits
unsigned int

variable_types:
pref
unsigned int

variable_types: bar int

variable_types: tmp int

variable_types: off int

return_type: struct pci_dev { struct pci_dev *next; unsigned char bus; struct pcicfg { unsigned short vendor_id; unsigned short device_id; unsigned short cmd_reg; unsigned short status_reg; unsigned int rev; unsigned char progif; unsigned char subclass; unsigned char class_code; unsigned char pad0; unsigned char pad1; unsigned char header_type; unsigned char pad2; unsigned int bar[6]; unsigned int pad3; unsigned short sub_vendor_id; unsigned short sub_id; unsigned int pad4; unsigned int pad5; unsigned int res0; unsigned int res1; unsigned char int_line; unsigned char int_pin; unsigned char pad6; unsigned char pad7; } cfg; struct pcibar { unsigned int addr; unsigned int len; union { struct { unsigned char pad; } io; struct { unsigned char bits; unsigned char prefs; } mem; } un; _Bool mem; } bars[6]; } *


original_code:
void init_ahci(struct pci_dev *d)
{
 uint32_t mem = d->bars[5].addr;
 struct GHC *ghc;
 struct PORT *port;
 struct _PxCMD cmd;
 int num,i;
 ghc = (struct GHC *)(0L + mem);
 if(ghc->CAP2 & (1 << 0)) {
  printf("init_ahci: BOH\n");
  ghc->BOHC |= 0x2;
 }
 ghc->GHC |= (1 << 0);
 ghc->GHC |= (1 << 31);
 printf("init_ahci: CAP: %x CAP2: %x GHC: %x BOHC: %x\n"
   "init_ahci: CAP.NP: %x CAP.S64A: %x CAP.NCS: %x\n",
   ghc->CAP.b,
   ghc->CAP2,
   ghc->GHC,
   ghc->BOHC,
   ghc->CAP.a.NP,
   ghc->CAP.a.S64A,
   ghc->CAP.a.NCS
   );
 printf("init_ahci: PI: %x VS: %x\n",
   ghc->PI,
   ghc->VS
    );
 for(num = 0; num < ghc->CAP.a.NP; num++) {
  if(!((1 << num) & ghc->PI)) continue;
  printf("init_ahci: port[%x]: ", num);
  port = (struct PORT *)(0L + mem + 0x100 + (num * 0x80));
  if( port->PxSSTS.a.det != 0x3 ) {
   printf("DET failed\n");
   continue;
  }
  cmd = port->PxCMD.a;
  printf("cmd=%x ", port->PxCMD.b);
  if( !(cmd.ST || cmd.CR || cmd.FRE || cmd.FR) ) {
   printf("port not idle %d%d%d%d ",
     cmd.ST,
     cmd.CR,
     cmd.FRE,
     cmd.FR
     );
  }
  printf("PxIS: %x ", port->PxIS);
  printf("PxCMD: %x (ATAPI:%s POD:%x) ",
    port->PxCMD.b,
    port->PxCMD.a.ATAPI ? "Y" : "N",
    port->PxCMD.a.POD);
  printf("\ninit_ahci: port[%x]: CH %p ", num, (void *)port->PxCLB);
  struct SIG pxsig;
  uint32_t pxsigtmp = port->PxSIG.b;
  if (pxsigtmp != 0xffffffff) {
   pxsig = *(struct SIG *)&pxsigtmp;
   printf("PxSIG: [%x %x.%x.%x] ",
     pxsig.sector,
     pxsig.lba_low, pxsig.lba_mid, pxsig.lba_high);
  }
  printf("PxSSTS{ DET:%x SPD:%x IPM:%x } ",
    port->PxSSTS.a.det,
    port->PxSSTS.a.spd,
    port->PxSSTS.a.ipm);
  if((port->PxCLB = (struct CommandHeader *)kmalloc_align((sizeof(struct CommandHeader) * 32), "PxCLB", ((void*)0), 0)) == ((void*)0)) {
   printf("malloc failed PxCLB\n");
   continue;
  }
  if((port->PxFB = (uint64_t)kmalloc_align(4096, "PxFB", ((void*)0),0)) == 0) {
   printf("malloc failed PxCLB\n");
   kfree(port->PxCLB);
   continue;
  }
  port->PxCLB->CFL = 4;
  port->PxCMD.a.FRE = 1;
  port->PxSERR = 0;
  port->PxCMD.a.ST = 1;
  for(i=0;i<10000000;i++) ;
  pxsigtmp = port->PxSIG.b;
  if (pxsigtmp != 0xffffffff) {
   pxsig = *(struct SIG *)&pxsigtmp;
   printf("PxSIG: [%x %x.%x.%x] ",
     pxsig.sector,
     pxsig.lba_low, pxsig.lba_mid, pxsig.lba_high);
  }
  printf("\n");
 }
}

canonical_original_code:
void init_ahci(struct pci_dev *d)
{
 unsigned int mem = d->bars[5].addr;
 struct GHC *ghc;
 struct PORT *port;
 struct _PxCMD cmd;
 int num; int i;
 ghc = (struct GHC *)(0L + mem);
 if(ghc->CAP2 & (1 << 0)) {
  printf("init_ahci: BOH\n");
  ghc->BOHC |= 0x2;
 }
 ghc->GHC |= (1 << 0);
 ghc->GHC |= (1 << 31);
 printf("init_ahci: CAP: %x CAP2: %x GHC: %x BOHC: %x\n"
   "init_ahci: CAP.NP: %x CAP.S64A: %x CAP.NCS: %x\n",
   ghc->CAP.b,
   ghc->CAP2,
   ghc->GHC,
   ghc->BOHC,
   ghc->CAP.a.NP,
   ghc->CAP.a.S64A,
   ghc->CAP.a.NCS
   );
 printf("init_ahci: PI: %x VS: %x\n",
   ghc->PI,
   ghc->VS
    );
 for(num = 0; num < ghc->CAP.a.NP; num++) {
  if(!((1 << num) & ghc->PI)) continue;
  printf("init_ahci: port[%x]: ", num);
  port = (struct PORT *)(0L + mem + 0x100 + (num * 0x80));
  if( port->PxSSTS.a.det != 0x3 ) {
   printf("DET failed\n");
   continue;
  }
  cmd = port->PxCMD.a;
  printf("cmd=%x ", port->PxCMD.b);
  if( !(cmd.ST || cmd.CR || cmd.FRE || cmd.FR) ) {
   printf("port not idle %d%d%d%d ",
     cmd.ST,
     cmd.CR,
     cmd.FRE,
     cmd.FR
     );
  }
  printf("PxIS: %x ", port->PxIS);
  printf("PxCMD: %x (ATAPI:%s POD:%x) ",
    port->PxCMD.b,
    port->PxCMD.a.ATAPI ? "Y" : "N",
    port->PxCMD.a.POD);
  printf("\ninit_ahci: port[%x]: CH %p ", num, (void *)port->PxCLB);
  struct SIG pxsig;
  unsigned int pxsigtmp = port->PxSIG.b;
  if (pxsigtmp != 0xffffffff) {
   pxsig = *(struct SIG *)&pxsigtmp;
   printf("PxSIG: [%x %x.%x.%x] ",
     pxsig.sector,
     pxsig.lba_low, pxsig.lba_mid, pxsig.lba_high);
  }
  printf("PxSSTS{ DET:%x SPD:%x IPM:%x } ",
    port->PxSSTS.a.det,
    port->PxSSTS.a.spd,
    port->PxSSTS.a.ipm);
  if((port->PxCLB = (struct CommandHeader *)kmalloc_align((sizeof(struct CommandHeader) * 32), "PxCLB", ((void *)0), 0)) == ((void *)0)) {
   printf("malloc failed PxCLB\n");
   continue;
  }
  if((port->PxFB = (unsigned long)kmalloc_align(4096, "PxFB", ((void *)0),0)) == 0) {
   printf("malloc failed PxCLB\n");
   kfree(port->PxCLB);
   continue;
  }
  port->PxCLB->CFL = 4;
  port->PxCMD.a.FRE = 1;
  port->PxSERR = 0;
  port->PxCMD.a.ST = 1;
  for(i=0;i<10000000;i++) ;
  pxsigtmp = port->PxSIG.b;
  if (pxsigtmp != 0xffffffff) {
   pxsig = *(struct SIG *)&pxsigtmp;
   printf("PxSIG: [%x %x.%x.%x] ",
     pxsig.sector,
     pxsig.lba_low, pxsig.lba_mid, pxsig.lba_high);
  }
  printf("\n");
 }
}

variable_types: struct pci_dev { struct pci_dev *next; unsigned char bus; struct pcicfg { unsigned short vendor_id; unsigned short device_id; unsigned short cmd_reg; unsigned short status_reg; unsigned int rev; unsigned char progif; unsigned char subclass; unsigned char class_code; unsigned char pad0; unsigned char pad1; unsigned char header_type; unsigned char pad2; unsigned int bar[6]; unsigned int pad3; unsigned short sub_vendor_id; unsigned short sub_id; unsigned int pad4; unsigned int pad5; unsigned int res0; unsigned int res1; unsigned char int_line; unsigned char int_pin; unsigned char pad6; unsigned char pad7; } cfg; struct pcibar { unsigned int addr; unsigned int len; union { struct { unsigned char pad; } io; struct { unsigned char bits; unsigned char prefs; } mem; } un; _Bool mem; } bars[6]; } *

variable_types:
mem
unsigned int

variable_types: struct GHC { union { struct _CAP { int NP; int SXS; int EMS; int CCCS; int NCS; int PSC; int SSC; int PMD; int FBSS; int SPM; int SAM; int res; int ISS; int SCLO; int SAL; int SALP; int SSS; int SMPS; int SSNTF; int SNCQ; int S64A; } a; unsigned int b; } CAP; unsigned int GHC; unsigned int IS; unsigned int PI; unsigned int VS; unsigned int CCC_CTL; unsigned int CCC_PORTS; unsigned int EM_LOC; unsigned int EM_CTL; unsigned int CAP2; unsigned int BOHC; } *

variable_types: struct PORT { struct CommandHeader { int CFL; int A; int W; int P; int R; int B; int C; int res; int PMP; int PRDTL; unsigned int PRDBC; struct CommandTable { unsigned char CFIS[64]; unsigned char ACMD[16]; unsigned char res[32]; } *CTBA; unsigned int dw_res[4]; } *PxCLB; unsigned long PxFB; unsigned int PxIS; unsigned int PxIE; union { struct _PxCMD { unsigned int ST; unsigned int SUD; unsigned int POD; unsigned int CLO; unsigned int FRE; unsigned int res; unsigned int CCS; unsigned int MPSS; unsigned int FR; unsigned int CR; unsigned int CPS; unsigned int PMA; unsigned int HPCP; unsigned int MPSP; unsigned int CPD; unsigned int ESP; unsigned int FBSCP; unsigned int APSTE; unsigned int ATAPI; unsigned int DLAE; unsigned int ALPE; unsigned int ASP; unsigned int ICC; } a; unsigned int b; } PxCMD; unsigned int res0; unsigned int PxTFD; union { struct SIG { unsigned int sector; unsigned int lba_low; unsigned int lba_mid; unsigned int lba_high; } a; unsigned int b; } PxSIG; union { struct SSTS { unsigned int det; unsigned int spd; unsigned int ipm; unsigned int res; } a; unsigned int b; } PxSSTS; unsigned int PxSCTL; unsigned int PxSERR; unsigned int PxSACT; unsigned int PxCI; unsigned int PxSNTF; unsigned int PxFBS; unsigned char res1[44]; unsigned char PxVS[16]; } *

variable_types: num int

variable_types: i int

variable_types:
pxsigtmp
unsigned int

user_defined_types: struct CommandHeader { int CFL; int A; int W; int P; int R; int B; int C; int res; int PMP; int PRDTL; unsigned int PRDBC; struct CommandTable *CTBA; unsigned int dw_res[4]; }

user_defined_types: struct GHC { union { struct _CAP a; unsigned int b; } CAP; unsigned int GHC; unsigned int IS; unsigned int PI; unsigned int VS; unsigned int CCC_CTL; unsigned int CCC_PORTS; unsigned int EM_LOC; unsigned int EM_CTL; unsigned int CAP2; unsigned int BOHC; }

user_defined_types: struct PORT { struct CommandHeader *PxCLB; unsigned long PxFB; unsigned int PxIS; unsigned int PxIE; union { struct _PxCMD a; unsigned int b; } PxCMD; unsigned int res0; unsigned int PxTFD; union { struct SIG a; unsigned int b; } PxSIG; union { struct SSTS a; unsigned int b; } PxSSTS; unsigned int PxSCTL; unsigned int PxSERR; unsigned int PxSACT; unsigned int PxCI; unsigned int PxSNTF; unsigned int PxFBS; unsigned char res1[44]; unsigned char PxVS[16]; }


decompiled_code:
unsigned __int64 get_cr3()
{
return __readcr3();
}

canonical_decompiled_code:
unsigned __int64 func0()
{
return __readcr3();
}

original_code:
static inline pt_t *get_cr3(void)
{
 uint64_t ret;
 __asm__ volatile("mov %%cr3, %0":"=r"(ret));
 return (pt_t*)ret;
}

canonical_original_code:
static inline union pt_t *get_cr3()
{
 unsigned long ret;
 __asm__ volatile("mov %%cr3, %0":"=r"(ret));
 return (union pt_t *)ret;
}

variable_types:
ret
unsigned long

return_type: union pt_t { struct pe_t { unsigned int present; unsigned int write; unsigned int user; unsigned int pwt; unsigned int pcd; unsigned int access; unsigned int dirty; unsigned int last; unsigned int global; unsigned int cow; unsigned int avl; unsigned long base; unsigned int avail; unsigned int nx; } table_pe[512]; unsigned long table_u64[512]; } *

user_defined_types: union pt_t { struct pe_t table_pe[512]; unsigned long table_u64[512]; }


decompiled_code:
unsigned __int64 get_cr2()
{
return __readcr2();
}

canonical_decompiled_code:
unsigned __int64 func1()
{
return __readcr2();
}

original_code:
static inline uint64_t get_cr2(void)
{
 uint64_t ret;
 __asm__ volatile("mov %%cr2, %0":"=r"(ret));
 return ret;
}

canonical_original_code:
static inline unsigned long get_cr2()
{
 unsigned long ret;
 __asm__ volatile("mov %%cr2, %0":"=r"(ret));
 return ret;
}

return_type: unsigned long


decompiled_code:
unsigned __int64 get_cr0()
{
return __readcr0();
}

canonical_decompiled_code:
unsigned __int64 func2()
{
return __readcr0();
}

original_code:
static inline uint64_t get_cr0(void)
{
 uint64_t ret;
 __asm__ volatile("mov %%cr0, %0":"=r"(ret));
 return ret;
}

canonical_original_code:
static inline unsigned long get_cr0()
{
 unsigned long ret;
 __asm__ volatile("mov %%cr0, %0":"=r"(ret));
 return ret;
}


decompiled_code:
unsigned __int64 get_cr4()
{
return __readcr4();
}

canonical_decompiled_code:
unsigned __int64 func3()
{
return __readcr4();
}

original_code:
static inline uint64_t get_cr4(void)
{
 uint64_t ret;
 __asm__ volatile("mov %%cr4, %0":"=r"(ret));
 return ret;
}

canonical_original_code:
static inline unsigned long get_cr4()
{
 unsigned long ret;
 __asm__ volatile("mov %%cr4, %0":"=r"(ret));
 return ret;
}


mktime

original_code:
static uint64_t mktime(uint64_t year, uint64_t mon, uint64_t day, uint64_t hour, uint64_t min, uint64_t sec)
{
 if (0 >= (int) (mon -= 2)) {
  mon += 12;
  year -= 1;
 }
 return (((
     (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
     year*365 - 719499
    )*24 + hour
   )*60 + min
     )*60 + sec;
}

canonical_original_code:
static unsigned long mktime(unsigned long year, unsigned long mon, unsigned long day, unsigned long hour, unsigned long min, unsigned long sec)
{
 if (0 >= (int) (mon -= 2)) {
  mon += 12;
  year -= 1;
 }
 return (((
     (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
     year*365 - 719499
    )*24 + hour
   )*60 + min
     )*60 + sec;
}

variable_types:
year
unsigned long

variable_types:
mon
unsigned long

variable_types:
day
unsigned long

variable_types:
hour
unsigned long

variable_types:
min
unsigned long

variable_types:
sec
unsigned long


original_code:
void gdt_set_gate32(uint8_t entry, uint32_t base, uint32_t limit, uint8_t dpl, uint8_t flag, uint8_t type)
{
    volatile struct gdt_entry *ge = &gdt[entry/sizeof(struct gdt_entry)];
    ge->islong = 0;
 ge->base_low = (uint16_t)(base & 0xffff);
 ge->base_middle = (uint8_t) (base >> 16) & 0xff;
 ge->base_high = (uint8_t) (base >> 24) & 0xff;
 ge->limit_low = (uint16_t)(limit & 0xffff);
 ge->limit_middle = (uint8_t)((limit >> 16) & 0x0f);
    switch(type)
    {
        case 0x13:
   ge->accessed = 0;
   ge->readable = (flag & 0x01) == 0x01;
   ge->ce = (flag & 0x02) == 0x02;
   ge->res = 1;
   ge->issegment = 1;
   ge->dpl = dpl;
   ge->present = (flag & 0x04) == 0x04;
   ge->avl = (flag & 0x40) == 0x40;
   ge->def = 1;
   ge->granularity = (flag & 0x20) == 0x20;
            break;
        case 0x12:
   ge->accessed = 0;
   ge->readable = (flag & 0x01) == 0x01;
   ge->ce = (flag & 0x02) == 0x02;
   ge->res = 0;
   ge->issegment = 1;
   ge->dpl = dpl;
   ge->present = (flag & 0x04) == 0x04;
   ge->avl = (flag & 0x40) == 0x40;
   ge->def = 1;
   ge->granularity = (flag & 0x20) == 0x20;
            break;
        default:
            printf("PANIC: unknown gdt_set_gate type %x\n", type);
    }
}

canonical_original_code:
void gdt_set_gate32(unsigned char entry, unsigned int base, unsigned int limit, unsigned char dpl, unsigned char flag, unsigned char type)
{
    struct gdt_entry *ge = &gdt[entry/sizeof(struct gdt_entry)];
    ge->islong = 0;
 ge->base_low = (unsigned short)(base & 0xffff);
 ge->base_middle = (unsigned char) (base >> 16) & 0xff;
 ge->base_high = (unsigned char) (base >> 24) & 0xff;
 ge->limit_low = (unsigned short)(limit & 0xffff);
 ge->limit_middle = (unsigned char)((limit >> 16) & 0x0f);
    switch(type)
    {
        case 0x13:
   ge->accessed = 0;
   ge->readable = (flag & 0x01) == 0x01;
   ge->ce = (flag & 0x02) == 0x02;
   ge->res = 1;
   ge->issegment = 1;
   ge->dpl = dpl;
   ge->present = (flag & 0x04) == 0x04;
   ge->avl = (flag & 0x40) == 0x40;
   ge->def = 1;
   ge->granularity = (flag & 0x20) == 0x20;
            break;
        case 0x12:
   ge->accessed = 0;
   ge->readable = (flag & 0x01) == 0x01;
   ge->ce = (flag & 0x02) == 0x02;
   ge->res = 0;
   ge->issegment = 1;
   ge->dpl = dpl;
   ge->present = (flag & 0x04) == 0x04;
   ge->avl = (flag & 0x40) == 0x40;
   ge->def = 1;
   ge->granularity = (flag & 0x20) == 0x20;
            break;
        default:
            printf("PANIC: unknown gdt_set_gate type %x\n", type);
    }
}

variable_types:
entry
unsigned char

variable_types:
base
unsigned int

variable_types:
limit
unsigned int

variable_types:
dpl
unsigned char

variable_types:
flag
unsigned char

variable_types:
type
unsigned char

variable_types: struct gdt_entry { unsigned short limit_low; unsigned short base_low; unsigned char base_middle; unsigned int accessed; unsigned int readable; unsigned int ce; unsigned int res; unsigned int issegment; unsigned int dpl; unsigned int present; unsigned int limit_middle; unsigned int avl; unsigned int islong; unsigned int def; unsigned int granularity; unsigned char base_high; } *


original_code:
void gdt_set_gate64(uint8_t entry, uint64_t base, uint32_t limit, uint8_t dpl, uint8_t flag, uint8_t type)
{
 volatile struct gdt_entry *ge = &gdt[entry/sizeof(struct gdt_entry)];
 ge->base_low = (uint16_t)(base & 0xffff);
 ge->base_middle = (uint8_t) ((base >> 16) & 0xff);
 ge->base_high = (uint8_t) ((base >> 24) & 0xff);
 switch(type)
 {
  case 0x11:
   ge->islong = 1;
            ge->accessed = 0;
            ge->readable = 0;
            ge->res = 1;
            ge->issegment = 1;
            ge->avl = 0;
   ge->granularity = 1;
            ge->ce = (flag & 0x02) == 0x02;
            ge->dpl = dpl;
            ge->present = (flag & 0x04) == 0x04;
            ge->def = (flag & 0x10) == 0x10;
   ge->limit_low = (uint16_t)(limit & 0xffff);
   ge->limit_middle = (uint8_t)((limit >> 16) & 0x0f);
   break;
  case 0x10:
   ge->islong = 1;
   ge->accessed = 0;
   ge->ce = 0;
   ge->res = 0;
   ge->issegment = 1;
   ge->avl = 0;
   ge->def = 0;
   ge->granularity = 1;
   ge->dpl = dpl;
   ge->readable = (flag & 0x01) == 0x01;
   ge->present = (flag & 0x04) == 0x04;
   ge->limit_low = (uint16_t)(limit & 0xffff);
   ge->limit_middle = (uint8_t)((limit >> 16) & 0x0f);
   break;
        case 0x09:
        case 0x0b:
        case 0x02:
            {
                volatile struct gdt_sysdesc_64 *geh = (struct gdt_sysdesc_64 *)ge;
                geh->base_very_high = (uint32_t)((base >> 32) & 0xffffffff);
    geh->always0a = 0;
    geh->always0b = 0;
    geh->always0c = 0;
    geh->always0d = 0;
    geh->always0e = 0;
    geh->type = type;
                ge->dpl = dpl;
                ge->present = (flag & 0x04) == 0x04;
                ge->avl = (flag & 0x40) == 0x40;
                ge->granularity = (flag & 0x20) == 0x20;
                ge->limit_low = (uint16_t)(limit & 0xffff);
                ge->limit_middle = (uint8_t)((limit >> 16) & 0x0f);
            }
            break;
        case 0x0c:
            {
                volatile struct callgate_entry *ce = (struct callgate_entry *)ge;
                ce->target_very_high = (uint32_t)(base >> 32) & 0xffffffff;
                ce->res0 = 0;
                ce->type = type;
                ce->always0a = 0;
                ce->dpl = dpl;
                ce->present = (flag & 0x04) == 0x04;
                ce->res1 = 0;
                ce->always0b = 0;
                ce->res2 = 0;
            }
            break;
        case 0x0e:
        case 0x0f:
            {
                volatile struct idt_entry *ie = (struct idt_entry *)ge;
                ie->target_very_high = (uint32_t)(base >> 32) & 0xffffffff;
                ie->res0 = 0;
                ie->type = type;
                ie->always0 = 0;
                ie->dpl = dpl;
                ie->present = (flag & 0x04);
            }
            break;
        default:
            printf("PANIC: unknown gate64 type %x\n", type);
            break;
    }
}

canonical_original_code:
void gdt_set_gate64(unsigned char entry, unsigned long base, unsigned int limit, unsigned char dpl, unsigned char flag, unsigned char type)
{
 struct gdt_entry *ge = &gdt[entry/sizeof(struct gdt_entry)];
 ge->base_low = (unsigned short)(base & 0xffff);
 ge->base_middle = (unsigned char) ((base >> 16) & 0xff);
 ge->base_high = (unsigned char) ((base >> 24) & 0xff);
 switch(type)
 {
  case 0x11:
   ge->islong = 1;
            ge->accessed = 0;
            ge->readable = 0;
            ge->res = 1;
            ge->issegment = 1;
            ge->avl = 0;
   ge->granularity = 1;
            ge->ce = (flag & 0x02) == 0x02;
            ge->dpl = dpl;
            ge->present = (flag & 0x04) == 0x04;
            ge->def = (flag & 0x10) == 0x10;
   ge->limit_low = (unsigned short)(limit & 0xffff);
   ge->limit_middle = (unsigned char)((limit >> 16) & 0x0f);
   break;
  case 0x10:
   ge->islong = 1;
   ge->accessed = 0;
   ge->ce = 0;
   ge->res = 0;
   ge->issegment = 1;
   ge->avl = 0;
   ge->def = 0;
   ge->granularity = 1;
   ge->dpl = dpl;
   ge->readable = (flag & 0x01) == 0x01;
   ge->present = (flag & 0x04) == 0x04;
   ge->limit_low = (unsigned short)(limit & 0xffff);
   ge->limit_middle = (unsigned char)((limit >> 16) & 0x0f);
   break;
        case 0x09:
        case 0x0b:
        case 0x02:
            {
                struct gdt_sysdesc_64 *geh = (struct gdt_sysdesc_64 *)ge;
                geh->base_very_high = (unsigned int)((base >> 32) & 0xffffffff);
    geh->always0a = 0;
    geh->always0b = 0;
    geh->always0c = 0;
    geh->always0d = 0;
    geh->always0e = 0;
    geh->type = type;
                ge->dpl = dpl;
                ge->present = (flag & 0x04) == 0x04;
                ge->avl = (flag & 0x40) == 0x40;
                ge->granularity = (flag & 0x20) == 0x20;
                ge->limit_low = (unsigned short)(limit & 0xffff);
                ge->limit_middle = (unsigned char)((limit >> 16) & 0x0f);
            }
            break;
        case 0x0c:
            {
                struct callgate_entry *ce = (struct callgate_entry *)ge;
                ce->target_very_high = (unsigned int)(base >> 32) & 0xffffffff;
                ce->res0 = 0;
                ce->type = type;
                ce->always0a = 0;
                ce->dpl = dpl;
                ce->present = (flag & 0x04) == 0x04;
                ce->res1 = 0;
                ce->always0b = 0;
                ce->res2 = 0;
            }
            break;
        case 0x0e:
        case 0x0f:
            {
                struct idt_entry *ie = (struct idt_entry *)ge;
                ie->target_very_high = (unsigned int)(base >> 32) & 0xffffffff;
                ie->res0 = 0;
                ie->type = type;
                ie->always0 = 0;
                ie->dpl = dpl;
                ie->present = (flag & 0x04);
            }
            break;
        default:
            printf("PANIC: unknown gate64 type %x\n", type);
            break;
    }
}

variable_types:
base
unsigned long

variable_types: struct gdt_sysdesc_64 { unsigned short limit_low; unsigned short base_low; unsigned char base_middle; unsigned int type; unsigned int always0a; unsigned int dpl; unsigned int present; unsigned int limit_middle; unsigned int avl; unsigned int always0b; unsigned int granularity; unsigned char base_high; unsigned int base_very_high; unsigned char always0c; unsigned int always0d; unsigned int always0e; } *

variable_types: struct callgate_entry { unsigned short target_low; unsigned short sel; unsigned char res0; unsigned int type; unsigned int always0a; unsigned int dpl; unsigned int present; unsigned short target_high; unsigned int target_very_high; unsigned char res1; unsigned int always0b; unsigned int res2; } *

variable_types: struct idt_entry { unsigned short target_low; unsigned short target_sel; unsigned int ist; unsigned int res0; unsigned int type; unsigned int always0; unsigned int dpl; unsigned int present; unsigned short target_high; unsigned int target_very_high; unsigned int res1; } *

user_defined_types: struct gdt_entry { unsigned short limit_low; unsigned short base_low; unsigned char base_middle; unsigned int accessed; unsigned int readable; unsigned int ce; unsigned int res; unsigned int issegment; unsigned int dpl; unsigned int present; unsigned int limit_middle; unsigned int avl; unsigned int islong; unsigned int def; unsigned int granularity; unsigned char base_high; }


decompiled_code:
void gdt_flush()
{
__lgdt(gdtp);
}

canonical_decompiled_code:
void func8()
{
__lgdt(gdtp);
}

original_code:
void gdt_flush(void)
{
 __asm__ volatile (
   "lgdt	%0\n"
   :
   :"m"(gdtp)
   );
}

canonical_original_code:
void gdt_flush()
{
 __asm__ volatile (
   "lgdt	%0\n"
   :
   :"m"(gdtp)
   );
}


decompiled_code:
void idt_flush()
{
__lidt(idtp);
}

canonical_decompiled_code:
void func9()
{
__lidt(idtp);
}

original_code:
void idt_flush(void)
{
 __asm__ volatile("lidt %0"::"m"(idtp));
}

canonical_original_code:
void idt_flush()
{
 __asm__ volatile("lidt %0"::"m"(idtp));
}


decompiled_code:
void tss_flush()
{
__asm { ltr di }
}

canonical_decompiled_code:
void func10()
{
__asm { ltr di }
}

original_code:
void tss_flush(uint16_t tsss)
{
 __asm__ volatile("ltr %0"::"r"(tsss));
}

canonical_original_code:
void tss_flush(unsigned short tsss)
{
 __asm__ volatile("ltr %0"::"r"(tsss));
}

variable_types:
tsss
unsigned short


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

outportb(67LL, 0LL);
delay = (unsigned __int8)inportb(64LL);
result = (unsigned int)inportb(64LL) << 8;
delay |= result;
return result;
}

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

outportb(67LL, 0LL);
delay = (unsigned __int8)inportb(64LL);
result = (unsigned int)inportb(64LL) << 8;
delay |= result;
return result;
}

original_code:
void timer_int(void)
{
 outportb(0x43, 0x0);
 delay = inportb(0x40);
 delay |= inportb(0x40) << 8;
}

canonical_original_code:
void timer_int()
{
 outportb(0x43, 0x0);
 delay = inportb(0x40);
 delay |= inportb(0x40) << 8;
}


decompiled_code:
__int64 __fastcall spin_lock(__int64 a1)
{
__int64 result; // rax
int v2; // ett
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

LODWORD(result) = 0;
v3 = a1;
while ( 1 )
{
v2 = result;
result = (unsigned int)_InterlockedCompareExchange((volatile signed __int32 *)&v3, result, result);
if ( v2 == (_DWORD)result )
break;
_mm_pause();
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
int v2; // ett
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

LODWORD(result) = 0;
v3 = a1;
while ( 1 )
{
v2 = result;
result = (unsigned int)_InterlockedCompareExchange((volatile signed __int32 *)&v3, result, result);
if ( v2 == (_DWORD)result )
break;
_mm_pause();
}
return result;
}

original_code:
void spin_lock(int *lock)
{
 __asm__ volatile (
   "1: lock; cmpxchgl %1, %0; jz 2f; pause; jmp 1b; 2:"
   :
   : "m" (lock), "r" (0)
   );
}

variable_types:
lock
int *


tod

decompiled_code:
unsigned __int64 tod()
{
unsigned __int8 v0; // r14
unsigned __int8 v1; // r13
unsigned __int8 v2; // r12
unsigned __int8 v3; // bp
unsigned __int8 v4; // bl
unsigned __int8 v5; // al
unsigned __int16 v6; // cx
__int16 v7; // dx
char v8; // al
char v9; // r9
char v10; // r8
__int16 v11; // dx
char v12; // bp
char v13; // si
unsigned __int16 v14; // di
unsigned __int16 v15; // dx
char v16; // r14
char v17; // r13
char v18; // bl
unsigned __int64 result; // rax

outportb(112LL, 0LL);
v0 = inportb(113LL);
outportb(112LL, 2LL);
v1 = inportb(113LL);
outportb(112LL, 4LL);
v2 = inportb(113LL);
outportb(112LL, 6LL);
inportb(113LL);
outportb(112LL, 7LL);
v3 = inportb(113LL);
outportb(112LL, 8LL);
v4 = inportb(113LL);
outportb(112LL, 9LL);
v5 = inportb(113LL);
v6 = v5;
v7 = v5 & 0xF;
v8 = v3 & 0xF;
v9 = v0 & 0xF;
v10 = v1 & 0xF;
v11 = v7 + 10 * (v6 >> 4);
v12 = v3 >> 4;
v13 = v4 & 0xF;
v14 = v11 + 1900;
v15 = v11 + 2000;
v16 = 5 * (v0 >> 4);
v17 = 5 * (v1 >> 4);
v18 = 5 * (v4 >> 4);
if ( v14 < 0x7B2u )
v14 = v15;
result = mktime(
v14,
(unsigned __int8)(v13 + 2 * v18),
(unsigned __int8)(v8 + 10 * v12),
(unsigned __int8)((v2 & 0xF) + 10 * (v2 >> 4)),
(unsigned __int8)(v10 + 2 * v17),
(unsigned __int8)(v9 + 2 * v16));
qword_4468 = 0LL;
kerntime = result;
return result;
}

canonical_decompiled_code:
unsigned __int64 func14()
{
unsigned __int8 v0; // r14
unsigned __int8 v1; // r13
unsigned __int8 v2; // r12
unsigned __int8 v3; // bp
unsigned __int8 v4; // bl
unsigned __int8 v5; // al
unsigned __int16 v6; // cx
__int16 v7; // dx
char v8; // al
char v9; // r9
char v10; // r8
__int16 v11; // dx
char v12; // bp
char v13; // si
unsigned __int16 v14; // di
unsigned __int16 v15; // dx
char v16; // r14
char v17; // r13
char v18; // bl
unsigned __int64 result; // rax

outportb(112LL, 0LL);
v0 = inportb(113LL);
outportb(112LL, 2LL);
v1 = inportb(113LL);
outportb(112LL, 4LL);
v2 = inportb(113LL);
outportb(112LL, 6LL);
inportb(113LL);
outportb(112LL, 7LL);
v3 = inportb(113LL);
outportb(112LL, 8LL);
v4 = inportb(113LL);
outportb(112LL, 9LL);
v5 = inportb(113LL);
v6 = v5;
v7 = v5 & 0xF;
v8 = v3 & 0xF;
v9 = v0 & 0xF;
v10 = v1 & 0xF;
v11 = v7 + 10 * (v6 >> 4);
v12 = v3 >> 4;
v13 = v4 & 0xF;
v14 = v11 + 1900;
v15 = v11 + 2000;
v16 = 5 * (v0 >> 4);
v17 = 5 * (v1 >> 4);
v18 = 5 * (v4 >> 4);
if ( v14 < 0x7B2u )
v14 = v15;
result = func5(
v14,
(unsigned __int8)(v13 + 2 * v18),
(unsigned __int8)(v8 + 10 * v12),
(unsigned __int8)((v2 & 0xF) + 10 * (v2 >> 4)),
(unsigned __int8)(v10 + 2 * v17),
(unsigned __int8)(v9 + 2 * v16));
qword_4468 = 0LL;
kerntime = result;
return result;
}

original_code:
void tod(void)
{
 uint8_t sec,min,hrs,dayw,daym,mon;
 uint16_t year;
 outportb(0x70, 0x0);
 sec = inportb(0x71);
 outportb(0x70, 0x2);
 min = inportb(0x71);
 outportb(0x70, 0x4);
 hrs = inportb(0x71);
 outportb(0x70, 0x6);
 dayw = inportb(0x71);
 outportb(0x70, 0x7);
 daym = inportb(0x71);
 outportb(0x70, 0x8);
 mon = inportb(0x71);
 outportb(0x70, 0x9);
 year = inportb(0x71);
 ((sec)=((sec)&15)+((sec)>>4)*10);
 ((min)=((min)&15)+((min)>>4)*10);
 ((hrs)=((hrs)&15)+((hrs)>>4)*10);
 ((dayw)=((dayw)&15)+((dayw)>>4)*10);
 ((daym)=((daym)&15)+((daym)>>4)*10);
 ((mon)=((mon)&15)+((mon)>>4)*10);
 ((year)=((year)&15)+((year)>>4)*10);
 year += 1900;
 if(year<1970) year+=100;
 kerntime.tv_sec = mktime(year,mon,daym,hrs,min,sec);
 kerntime.tv_usec = 0;
}

canonical_original_code:
void tod()
{
 unsigned char sec; unsigned char min; unsigned char hrs; unsigned char dayw; unsigned char daym; unsigned char mon;
 unsigned short year;
 outportb(0x70, 0x0);
 sec = inportb(0x71);
 outportb(0x70, 0x2);
 min = inportb(0x71);
 outportb(0x70, 0x4);
 hrs = inportb(0x71);
 outportb(0x70, 0x6);
 dayw = inportb(0x71);
 outportb(0x70, 0x7);
 daym = inportb(0x71);
 outportb(0x70, 0x8);
 mon = inportb(0x71);
 outportb(0x70, 0x9);
 year = inportb(0x71);
 ((sec)=((sec)&15)+((sec)>>4)*10);
 ((min)=((min)&15)+((min)>>4)*10);
 ((hrs)=((hrs)&15)+((hrs)>>4)*10);
 ((dayw)=((dayw)&15)+((dayw)>>4)*10);
 ((daym)=((daym)&15)+((daym)>>4)*10);
 ((mon)=((mon)&15)+((mon)>>4)*10);
 ((year)=((year)&15)+((year)>>4)*10);
 year += 1900;
 if(year<1970) year+=100;
 kerntime.tv_sec = mktime(year,mon,daym,hrs,min,sec);
 kerntime.tv_usec = 0;
}

variable_types:
sec
unsigned char

variable_types:
min
unsigned char

variable_types:
hrs
unsigned char

variable_types:
dayw
unsigned char

variable_types:
daym
unsigned char

variable_types:
mon
unsigned char

variable_types:
year
unsigned short


decompiled_code:
__int64 __fastcall sys_time(_QWORD *a1)
{
bool v1; // zf
__int64 result; // rax

if ( !a1 )
return kerntime;
v1 = (unsigned __int8)is_valid() == 0;
result = kerntime;
if ( !v1 )
*a1 = kerntime;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(_QWORD *a1)
{
bool v1; // zf
__int64 result; // rax

if ( !a1 )
return kerntime;
v1 = (unsigned __int8)is_valid() == 0;
result = kerntime;
if ( !v1 )
*a1 = kerntime;
return result;
}

original_code:
time_t sys_time(void *const tloc)
{
 if(tloc && is_valid(tloc))
  *(time_t *)tloc = kerntime.tv_sec;
 return kerntime.tv_sec;
}

canonical_original_code:
long sys_time(void *tloc)
{
 if(tloc && is_valid(tloc))
  *(long *)tloc = kerntime.tv_sec;
 return kerntime.tv_sec;
}

variable_types:
tloc
void *


original_code:
void print_reg(const struct regs *restrict const r)
{
 printf( "rax: %lx rbx: %lx rcx: %lx rdx: %lx\n"
   "rdi: %lx\n"
   "int: %0x err: %x\n"
   "rip:    %lx\n"
   "rflags: %lx\n"
   "rsp:    %lx\n"
   "cs:     %lx fs: %lx fsbase: %lx\n"
   "ss:     %lx gs: %lx gsbase: %lx kerngsbase: %lx\n",
   r->rax, r->rbx, r->rcx, r->rdx,
   r->rdi,
   (int)r->int_num,
   (int)r->error_code,
   r->rip,
   r->rflags,
   r->rsp,
   r->cs, r->fs, read_msr(0xc0000100),
   r->ss, r->gs, read_msr(0xc0000101), read_msr(0xc0000102));
}

canonical_original_code:
void print_reg(struct regs *r)
{
 printf( "rax: %lx rbx: %lx rcx: %lx rdx: %lx\n"
   "rdi: %lx\n"
   "int: %0x err: %x\n"
   "rip:    %lx\n"
   "rflags: %lx\n"
   "rsp:    %lx\n"
   "cs:     %lx fs: %lx fsbase: %lx\n"
   "ss:     %lx gs: %lx gsbase: %lx kerngsbase: %lx\n",
   r->rax, r->rbx, r->rcx, r->rdx,
   r->rdi,
   (int)r->int_num,
   (int)r->error_code,
   r->rip,
   r->rflags,
   r->rsp,
   r->cs, r->fs, read_msr(0xc0000100),
   r->ss, r->gs, read_msr(0xc0000101), read_msr(0xc0000102));
}

variable_types: struct regs { unsigned long ds; unsigned long r15; unsigned long r11; unsigned long rdi; unsigned long rdx; unsigned long int_num; unsigned long error_code; unsigned long rip; unsigned long cs; unsigned long rflags; unsigned long rsp; unsigned long ss; } *


decompiled_code:
__int64 sys_getppid()
{
return tasks[332 * curtask + 221];
}

canonical_decompiled_code:
__int64 func0()
{
return tasks[332 * curtask + 221];
}

original_code:
pid_t sys_getppid(void)
{
 return tasks[curtask].ppid;
}

canonical_original_code:
int sys_getppid()
{
 return tasks[curtask].ppid;
}


decompiled_code:
__int64 sys_getpid()
{
return curtask;
}

canonical_decompiled_code:
__int64 func1()
{
return curtask;
}

original_code:
pid_t sys_getpid(void)
{
 return curtask;
}

canonical_original_code:
int sys_getpid()
{
 return curtask;
}


decompiled_code:
// attributes: thunk
__int64 sys_gettid()
{
return sys_getpid();
}

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

original_code:
pid_t sys_gettid(void)
{
 return curtask;
}

canonical_original_code:
int sys_gettid()
{
 return curtask;
}


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

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

original_code:
long sys_kludge()
{
 return 0;
}

canonical_original_code:
long sys_kludge()
{
 return 0;
}


decompiled_code:
__int64 sys_pause()
{
lock_tasks();
tasks[332 * curtask + 196] = 4;
unlock_tasks();
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
lock_tasks();
tasks[332 * curtask + 196] = 4;
unlock_tasks();
return 0LL;
}

original_code:
long sys_pause()
{
 lock_tasks();
 tasks[curtask].state = 4;
 unlock_tasks();
 return 0;
}