decompiled_code:
__int64 __fastcall cpu_drcindex_to_drcname(int a1, _BYTE *a2, int a3)
{
_BYTE *v4; // r13
int v5; // eax
int v6; // ebp
int i; // ebx
unsigned int v8; // er12
__int64 result; // rax
int v10; // eax
char v11; // al
char v12; // [rsp+Bh] [rbp-2Dh] BYREF
int buf[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = a2;
v5 = open("/proc/device-tree/cpus/ibm,drc-indexes", 0);
if ( v5 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-indexes", 1uLL, 0x34uLL, stderr);
result = 0LL;
}
else
{
v6 = v5;
read(v5, buf, 4uLL);
for ( i = 0; ; ++i )
{
if ( !read(v6, buf, 4uLL) )
{
v8 = 0;
close(v6);
LABEL_7:
close(v6);
goto LABEL_8;
}
if ( buf[0] == a1 )
break;
}
close(v6);
v10 = open("/proc/device-tree/cpus/ibm,drc-names", 0);
v6 = v10;
if ( v10 >= 0 )
{
read(v10, buf, 4uLL);
if ( !i )
goto LABEL_20;
do
{
if ( read(v6, &v12, 1uLL) != 1 )
{
close(v6);
return 0LL;
}
}
while ( v12 || --i );
while ( 1 )
{
LABEL_20:
if ( read(v6, &v12, 1uLL) != 1 )
{
LABEL_21:
v8 = 1;
goto LABEL_7;
}
if ( v4 == &a2[a3 - 1] )
break;
v11 = v12;
*v4++ = v12;
if ( !v11 )
goto LABEL_21;
}
*v4 = 0;
v8 = 1;
goto LABEL_7;
}
v8 = 0;
fwrite("error opening /proc/device-tree/cpus/ibm,drc-names", 1uLL, 0x32uLL, stderr);
LABEL_8:
result = v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, _BYTE *a2, int a3)
{
_BYTE *v4; // r13
int v5; // eax
int v6; // ebp
int i; // ebx
unsigned int v8; // er12
__int64 result; // rax
int v10; // eax
char v11; // al
char v12; // [rsp+Bh] [rbp-2Dh] BYREF
int buf[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v4 = a2;
v5 = open("/proc/device-tree/cpus/ibm,drc-indexes", 0);
if ( v5 < 0 )
{
fwrite("error opening /proc/device-tree/cpus/ibm,drc-indexes", 1uLL, 0x34uLL, stderr);
result = 0LL;
}
else
{
v6 = v5;
read(v5, buf, 4uLL);
for ( i = 0; ; ++i )
{
if ( !read(v6, buf, 4uLL) )
{
v8 = 0;
close(v6);
LABEL_7:
close(v6);
goto LABEL_8;
}
if ( buf[0] == a1 )
break;
}
close(v6);
v10 = open("/proc/device-tree/cpus/ibm,drc-names", 0);
v6 = v10;
if ( v10 >= 0 )
{
read(v10, buf, 4uLL);
if ( !i )
goto LABEL_20;
do
{
if ( read(v6, &v12, 1uLL) != 1 )
{
close(v6);
return 0LL;
}
}
while ( v12 || --i );
while ( 1 )
{
LABEL_20:
if ( read(v6, &v12, 1uLL) != 1 )
{
LABEL_21:
v8 = 1;
goto LABEL_7;
}
if ( v4 == &a2[a3 - 1] )
break;
v11 = v12;
*v4++ = v12;
if ( !v11 )
goto LABEL_21;
}
*v4 = 0;
v8 = 1;
goto LABEL_7;
}
v8 = 0;
fwrite("error opening /proc/device-tree/cpus/ibm,drc-names", 1uLL, 0x32uLL, stderr);
LABEL_8:
result = v8;
}
return result;
}

original_code:
int
cpu_drcindex_to_drcname(uint32_t drc_idx, char *drc_name, int buf_size) {
 int fd, offset=0, found=0;
 uint32_t index;
 uint8_t ch;
 if ((fd = open("/proc/device-tree/cpus/ibm,drc-indexes",
    00)) < 0) {
  fprintf(stderr, "error opening /proc/device-tree/cpus/"
   "ibm,drc-indexes");
  return 0;
 }
 read(fd, &index, 4);
 while ((read(fd, &index, 4)) != 0) {
  if (index == drc_idx) {
   found = 1;
   break;
  }
  offset++;
 }
 close(fd);
 if (found) {
  if ((fd = open("/proc/device-tree/cpus/ibm,drc-names",
    00)) < 0) {
   fprintf(stderr, "error opening /proc/device-tree/cpus/"
    "ibm,drc-names");
   return 0;
  }
  read(fd, &index, 4);
  while (offset > 0) {
   do {
    if ((read(fd, &ch, 1)) != 1) {
     close(fd);
     return 0;
    }
   } while (ch != 0);
   offset--;
  }
  while ((read(fd, &ch, 1)) == 1) {
   if (offset+1 == buf_size) {
    drc_name[offset] = '\0';
    break;
   }
   drc_name[offset++] = ch;
   if (ch == 0)
    break;
  }
 }
 close(fd);
 return found;
}

canonical_original_code:
int cpu_drcindex_to_drcname(unsigned int drc_idx, char *drc_name, int buf_size) {
 int fd; int offset = 0; int found = 0;
 unsigned int index;
 unsigned char ch;
 if ((fd = open("/proc/device-tree/cpus/ibm,drc-indexes",
    00)) < 0) {
  fprintf(stderr, "error opening /proc/device-tree/cpus/"
   "ibm,drc-indexes");
  return 0;
 }
 read(fd, &index, 4);
 while ((read(fd, &index, 4)) != 0) {
  if (index == drc_idx) {
   found = 1;
   break;
  }
  offset++;
 }
 close(fd);
 if (found) {
  if ((fd = open("/proc/device-tree/cpus/ibm,drc-names",
    00)) < 0) {
   fprintf(stderr, "error opening /proc/device-tree/cpus/"
    "ibm,drc-names");
   return 0;
  }
  read(fd, &index, 4);
  while (offset > 0) {
   do {
    if ((read(fd, &ch, 1)) != 1) {
     close(fd);
     return 0;
    }
   } while (ch != 0);
   offset--;
  }
  while ((read(fd, &ch, 1)) == 1) {
   if (offset+1 == buf_size) {
    drc_name[offset] = '\0';
    break;
   }
   drc_name[offset++] = ch;
   if (ch == 0)
    break;
  }
 }
 close(fd);
 return found;
}

variable_types: fd int

variable_types: offset int

variable_types: found int

variable_types:
index
unsigned int

variable_types:
ch
unsigned char


decompiled_code:
__int64 __fastcall cpu_drcname_to_drcindex(char *s2, void *a2)
{
int v2; // eax
int v3; // ebp
int v4; // ebx
int v5; // er12
char *v6; // r15
char v7; // al
unsigned int v8; // er14
int v9; // eax
char v11; // [rsp+1Bh] [rbp-7Dh] BYREF
char buf[4]; // [rsp+1Ch] [rbp-7Ch] BYREF
char s1[120]; // [rsp+20h] [rbp-78h] BYREF

v2 = open("/proc/device-tree/cpus/ibm,drc-names", 0);
if ( v2 < 0 )
{
v8 = 0;
fwrite("error opening /proc/device-tree/cpus/ibm,drc-names", 1uLL, 0x32uLL, stderr);
return v8;
}
v3 = v2;
read(v2, buf, 4uLL);
v4 = 1;
LABEL_3:
v5 = v4 - 1;
v6 = s1;
do
{
v8 = read(v3, &v11, 1uLL);
if ( v8 != 1 )
{
if ( !strcmp(s1, s2) )
goto LABEL_10;
if ( !v8 )
{
close(v3);
goto LABEL_17;
}
LABEL_8:
++v4;
goto LABEL_3;
}
v7 = v11;
*v6++ = v11;
}
while ( v7 );
if ( strcmp(s1, s2) )
goto LABEL_8;
LABEL_10:
close(v3);
v9 = open("/proc/device-tree/cpus/ibm,drc-indexes", 0);
v3 = v9;
if ( v9 < 0 )
{
v8 = 0;
fwrite("error opening /proc/device-tree/cpus/ibm,drc-indexes", 1uLL, 0x34uLL, stderr);
}
else
{
read(v9, buf, 4uLL);
if ( v4 == 1 )
{
LABEL_20:
v8 = read(v3, a2, 4uLL) == 4;
LABEL_17:
close(v3);
}
else
{
while ( read(v3, buf, 4uLL) == 4 )
{
if ( !--v5 )
goto LABEL_20;
}
v8 = 0;
close(v3);
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2, void *a2)
{
int v2; // eax
int v3; // ebp
int v4; // ebx
int v5; // er12
char *v6; // r15
char v7; // al
unsigned int v8; // er14
int v9; // eax
char v11; // [rsp+1Bh] [rbp-7Dh] BYREF
char buf[4]; // [rsp+1Ch] [rbp-7Ch] BYREF
char s1[120]; // [rsp+20h] [rbp-78h] BYREF

v2 = open("/proc/device-tree/cpus/ibm,drc-names", 0);
if ( v2 < 0 )
{
v8 = 0;
fwrite("error opening /proc/device-tree/cpus/ibm,drc-names", 1uLL, 0x32uLL, stderr);
return v8;
}
v3 = v2;
read(v2, buf, 4uLL);
v4 = 1;
LABEL_3:
v5 = v4 - 1;
v6 = s1;
do
{
v8 = read(v3, &v11, 1uLL);
if ( v8 != 1 )
{
if ( !strcmp(s1, s2) )
goto LABEL_10;
if ( !v8 )
{
close(v3);
goto LABEL_17;
}
LABEL_8:
++v4;
goto LABEL_3;
}
v7 = v11;
*v6++ = v11;
}
while ( v7 );
if ( strcmp(s1, s2) )
goto LABEL_8;
LABEL_10:
close(v3);
v9 = open("/proc/device-tree/cpus/ibm,drc-indexes", 0);
v3 = v9;
if ( v9 < 0 )
{
v8 = 0;
fwrite("error opening /proc/device-tree/cpus/ibm,drc-indexes", 1uLL, 0x34uLL, stderr);
}
else
{
read(v9, buf, 4uLL);
if ( v4 == 1 )
{
LABEL_20:
v8 = read(v3, a2, 4uLL) == 4;
LABEL_17:
close(v3);
}
else
{
while ( read(v3, buf, 4uLL) == 4 )
{
if ( !--v5 )
goto LABEL_20;
}
v8 = 0;
close(v3);
}
}
return v8;
}

original_code:
int
cpu_drcname_to_drcindex(char *drc_name, uint32_t *drc_idx) {
 int fd, offset=0, found=0, i, rc;
 uint32_t index;
 uint8_t ch;
 char buffer[64];
 if ((fd = open("/proc/device-tree/cpus/ibm,drc-names",
    00)) < 0) {
  fprintf(stderr, "error opening /proc/device-tree/cpus/"
   "ibm,drc-names");
  return 0;
 }
 read(fd, &index, 4);
 do {
  i = 0;
  while ((rc = read(fd, &ch, 1)) == 1) {
   buffer[i++] = ch;
   if (ch == 0)
    break;
  }
  if (!strcmp(buffer, drc_name)) {
   found = 1;
   break;
  }
  offset++;
 } while (rc);
 close(fd);
 if (found) {
  if ((fd = open("/proc/device-tree/cpus/ibm,drc-indexes",
    00)) < 0) {
   fprintf(stderr, "error opening /proc/device-tree/cpus/"
    "ibm,drc-indexes");
   return 0;
  }
  read(fd, &index, 4);
  while (offset > 0) {
   if ((read(fd, &index, 4)) != 4) {
    close(fd);
    return 0;
   }
   offset--;
  }
  if ((read(fd, drc_idx, 4)) != 4)
   found = 0;
 }
 close(fd);
 return found;
}

canonical_original_code:
int cpu_drcname_to_drcindex(char *drc_name, unsigned int *drc_idx) {
 int fd; int offset = 0; int found = 0; int i; int rc;
 unsigned int index;
 unsigned char ch;
 char buffer[64];
 if ((fd = open("/proc/device-tree/cpus/ibm,drc-names",
    00)) < 0) {
  fprintf(stderr, "error opening /proc/device-tree/cpus/"
   "ibm,drc-names");
  return 0;
 }
 read(fd, &index, 4);
 do {
  i = 0;
  while ((rc = read(fd, &ch, 1)) == 1) {
   buffer[i++] = ch;
   if (ch == 0)
    break;
  }
  if (!strcmp(buffer, drc_name)) {
   found = 1;
   break;
  }
  offset++;
 } while (rc);
 close(fd);
 if (found) {
  if ((fd = open("/proc/device-tree/cpus/ibm,drc-indexes",
    00)) < 0) {
   fprintf(stderr, "error opening /proc/device-tree/cpus/"
    "ibm,drc-indexes");
   return 0;
  }
  read(fd, &index, 4);
  while (offset > 0) {
   if ((read(fd, &index, 4)) != 4) {
    close(fd);
    return 0;
   }
   offset--;
  }
  if ((read(fd, drc_idx, 4)) != 4)
   found = 0;
 }
 close(fd);
 return found;
}

variable_types: i int

variable_types: rc int

variable_types:
buffer
char [64]

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
char *v4; // r13
char *v5; // r12
int v6; // eax
int v7; // er12
int v9; // eax
int v10; // er12
__int64 i; // rbx
__int64 v12; // rsi
int v13; // ebx
unsigned int v14; // ebx
int v15; // ebx
int v16; // eax
int v17; // er12
__int64 j; // rbx
__int64 v19; // rsi
const char *v20; // rdx
int longind; // [rsp+8h] [rbp-90h] BYREF
unsigned int v22; // [rsp+Ch] [rbp-8Ch] BYREF
char dest[32]; // [rsp+10h] [rbp-88h] BYREF
_DWORD v24[26]; // [rsp+30h] [rbp-68h] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
longind = 0;
v6 = getopt_long(argc, (char *const *)argv, "hc:f:t:", &long_options, &longind);
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
v4 = optarg;
}
else if ( v6 > 102 )
{
if ( v6 == 104 )
{
v7 = 0;
print_usage(*argv);
return v7;
}
if ( v6 != 116 )
goto LABEL_15;
v3 = optarg;
}
else
{
if ( v6 == 63 )
{
v7 = -1;
print_usage(*argv);
return v7;
}
if ( v6 == 99 )
v5 = optarg;
else
LABEL_15:
puts("huh?");
}
}
if ( !v5 )
{
v7 = 1;
fwrite("--context not specified\n", 1uLL, 0x18uLL, stderr);
return v7;
}
if ( !v4 )
{
v7 = 2;
fwrite("--from not specified\n", 1uLL, 0x15uLL, stderr);
return v7;
}
if ( !v3 )
{
v7 = 3;
fwrite("--to not specified\n", 1uLL, 0x13uLL, stderr);
return v7;
}
if ( strcmp(v5, "cpu") )
{
if ( strcmp(v5, "mem") )
{
v20 = v5;
v7 = 1;
fprintf(stderr, "invalid --context flag: %s\n", v20);
return v7;
}
if ( strcmp(v4, "drc-index") )
goto LABEL_42;
v13 = strtoul(argv[argc - 1], 0LL, 0);
if ( strcmp(v3, "drc-name") )
return 0;
if ( (unsigned int)mem_drcindex_to_drcname_constprop_0(v13, (__int64)dest) )
goto LABEL_41;
LABEL_54:
v7 = 4;
fprintf(stderr, "could not find the drc-name corresponding to drc-index 0x%08x\n", v22);
return v7;
}
if ( !strcmp(v4, "interrupt-server") )
{
v14 = strtol(argv[argc - 1], 0LL, 0);
v7 = strcmp(v3, "drc-index");
if ( v7 )
{
if ( strcmp(v3, "drc-name") )
goto LABEL_42;
if ( (unsigned int)cpu_interruptserver_to_drcindex(v14, &v22) )
{
if ( (unsigned int)cpu_drcindex_to_drcname(v22, dest, 20) )
goto LABEL_41;
goto LABEL_54;
}
}
else if ( (unsigned int)cpu_interruptserver_to_drcindex(v14, &v22) )
{
goto LABEL_59;
}
v7 = 4;
fprintf(stderr, "could not find the drc-index corresponding to interrupt-server 0x%08x\n", v14);
return v7;
}
if ( strcmp(v4, "drc-index") )
{
if ( strcmp(v4, "drc-name") )
{
v7 = 2;
fprintf(stderr, "invalid --from flag: %s\n", v4);
return v7;
}
strncpy(dest, argv[argc - 1], 0x14uLL);
v7 = strcmp(v3, "drc-index");
if ( v7 )
{
if ( !strcmp(v3, "interrupt-server") )
{
if ( (unsigned int)cpu_drcname_to_drcindex(dest, &v22) )
{
v9 = cpu_drcindex_to_interruptserver(v22, (__int64)v24, 16);
v10 = v9;
if ( v9 )
{
if ( v9 > 16 )
fprintf(
stderr,
"warning: only the first %d servers in the list of %d were returned; increase MAX_IRQ_SERVERS_PER_CPU to "
"retrieve the entire list\n",
16LL,
(unsigned int)v9);
for ( i = 0LL; v10 > (int)i; ++i )
{
v12 = (unsigned int)v24[i];
printf("0x%08x\n", v12);
}
return 0;
}
LABEL_66:
v7 = 4;
fprintf(stderr, "could not find the interrupt-server corresponding to drc-index 0x%08x\n", v22);
return v7;
}
LABEL_65:
v7 = 4;
fprintf(stderr, "could not find the drc-index corresponding to drc-name %s\n", dest);
return v7;
}
LABEL_42:
v7 = 3;
fprintf(stderr, "invalid --to flag: %s\n", v3);
return v7;
}
if ( !(unsigned int)cpu_drcname_to_drcindex(dest, &v22) )
goto LABEL_65;
LABEL_59:
printf("0x%08x\n", v22);
return v7;
}
v22 = strtol(argv[argc - 1], 0LL, 0);
v15 = v22;
if ( !strcmp(v3, "drc-name") )
{
if ( !(unsigned int)cpu_drcindex_to_drcname(v15, dest, 20) )
goto LABEL_54;
LABEL_41:
v7 = 0;
puts(dest);
return v7;
}
if ( strcmp(v3, "interrupt-server") )
goto LABEL_42;
v16 = cpu_drcindex_to_interruptserver(v15, (__int64)v24, 16);
v17 = v16;
if ( !v16 )
goto LABEL_66;
if ( v16 > 16 )
fprintf(
stderr,
"warning: only the first %d servers in the list of %d were returned; increase MAX_IRQ_SERVERS_PER_CPU to retrieve t"
"he entire list\n",
16LL,
(unsigned int)v16);
for ( j = 0LL; v17 > (int)j; ++j )
{
v19 = (unsigned int)v24[j];
printf("0x%08x\n", v19);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r14
char *v4; // r13
char *v5; // r12
int v6; // eax
int v7; // er12
int v9; // eax
int v10; // er12
__int64 i; // rbx
__int64 v12; // rsi
int v13; // ebx
unsigned int v14; // ebx
int v15; // ebx
int v16; // eax
int v17; // er12
__int64 j; // rbx
__int64 v19; // rsi
const char *v20; // rdx
int longind; // [rsp+8h] [rbp-90h] BYREF
unsigned int v22; // [rsp+Ch] [rbp-8Ch] BYREF
char dest[32]; // [rsp+10h] [rbp-88h] BYREF
_DWORD v24[26]; // [rsp+30h] [rbp-68h] BYREF

v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
longind = 0;
v6 = getopt_long(argc, (char *const *)argv, "hc:f:t:", &long_options, &longind);
if ( v6 == -1 )
break;
if ( v6 == 102 )
{
v4 = optarg;
}
else if ( v6 > 102 )
{
if ( v6 == 104 )
{
v7 = 0;
func1(*argv);
return v7;
}
if ( v6 != 116 )
goto LABEL_15;
v3 = optarg;
}
else
{
if ( v6 == 63 )
{
v7 = -1;
func1(*argv);
return v7;
}
if ( v6 == 99 )
v5 = optarg;
else
LABEL_15:
puts("huh?");
}
}
if ( !v5 )
{
v7 = 1;
fwrite("--context not specified\n", 1uLL, 0x18uLL, stderr);
return v7;
}
if ( !v4 )
{
v7 = 2;
fwrite("--from not specified\n", 1uLL, 0x15uLL, stderr);
return v7;
}
if ( !v3 )
{
v7 = 3;
fwrite("--to not specified\n", 1uLL, 0x13uLL, stderr);
return v7;
}
if ( strcmp(v5, "cpu") )
{
if ( strcmp(v5, "mem") )
{
v20 = v5;
v7 = 1;
fprintf(stderr, "invalid --context flag: %s\n", v20);
return v7;
}
if ( strcmp(v4, "drc-index") )
goto LABEL_42;
v13 = strtoul(argv[argc - 1], 0LL, 0);
if ( strcmp(v3, "drc-name") )
return 0;
if ( (unsigned int)func0(v13, (__int64)dest) )
goto LABEL_41;
LABEL_54:
v7 = 4;
fprintf(stderr, "could not find the drc-name corresponding to drc-index 0x%08x\n", v22);
return v7;
}
if ( !strcmp(v4, "interrupt-server") )
{
v14 = strtol(argv[argc - 1], 0LL, 0);
v7 = strcmp(v3, "drc-index");
if ( v7 )
{
if ( strcmp(v3, "drc-name") )
goto LABEL_42;
if ( (unsigned int)func2(v14, &v22) )
{
if ( (unsigned int)func3(v22, dest, 20) )
goto LABEL_41;
goto LABEL_54;
}
}
else if ( (unsigned int)func2(v14, &v22) )
{
goto LABEL_59;
}
v7 = 4;
fprintf(stderr, "could not find the drc-index corresponding to interrupt-server 0x%08x\n", v14);
return v7;
}
if ( strcmp(v4, "drc-index") )
{
if ( strcmp(v4, "drc-name") )
{
v7 = 2;
fprintf(stderr, "invalid --from flag: %s\n", v4);
return v7;
}
strncpy(dest, argv[argc - 1], 0x14uLL);
v7 = strcmp(v3, "drc-index");
if ( v7 )
{
if ( !strcmp(v3, "interrupt-server") )
{
if ( (unsigned int)func5(dest, &v22) )
{
v9 = func4(v22, (__int64)v24, 16);
v10 = v9;
if ( v9 )
{
if ( v9 > 16 )
fprintf(
stderr,
"warning: only the first %d servers in the list of %d were returned; increase MAX_IRQ_SERVERS_PER_CPU to "
"retrieve the entire list\n",
16LL,
(unsigned int)v9);
for ( i = 0LL; v10 > (int)i; ++i )
{
v12 = (unsigned int)v24[i];
printf("0x%08x\n", v12);
}
return 0;
}
LABEL_66:
v7 = 4;
fprintf(stderr, "could not find the interrupt-server corresponding to drc-index 0x%08x\n", v22);
return v7;
}
LABEL_65:
v7 = 4;
fprintf(stderr, "could not find the drc-index corresponding to drc-name %s\n", dest);
return v7;
}
LABEL_42:
v7 = 3;
fprintf(stderr, "invalid --to flag: %s\n", v3);
return v7;
}
if ( !(unsigned int)func5(dest, &v22) )
goto LABEL_65;
LABEL_59:
printf("0x%08x\n", v22);
return v7;
}
v22 = strtol(argv[argc - 1], 0LL, 0);
v15 = v22;
if ( !strcmp(v3, "drc-name") )
{
if ( !(unsigned int)func3(v15, dest, 20) )
goto LABEL_54;
LABEL_41:
v7 = 0;
puts(dest);
return v7;
}
if ( strcmp(v3, "interrupt-server") )
goto LABEL_42;
v16 = func4(v15, (__int64)v24, 16);
v17 = v16;
if ( !v16 )
goto LABEL_66;
if ( v16 > 16 )
fprintf(
stderr,
"warning: only the first %d servers in the list of %d were returned; increase MAX_IRQ_SERVERS_PER_CPU to retrieve t"
"he entire list\n",
16LL,
(unsigned int)v16);
for ( j = 0LL; v17 > (int)j; ++j )
{
v19 = (unsigned int)v24[j];
printf("0x%08x\n", v19);
}
return 0;
}

original_code:
int
main(int argc, char *argv[]) {
 int option_index, rc, i;
 char *context=((void *)0), *from=((void *)0), *to=((void *)0);
 uint32_t interruptserver, drcindex;
 unsigned long drc_tmp_idx;
 uint32_t intservs_array[16];
 char drcname[20];
 for (;;) {
  option_index = 0;
  rc = getopt_long(argc, argv, "hc:f:t:", long_options,
    &option_index);
  if (rc == -1)
   break;
  switch (rc) {
  case 'h':
   print_usage(argv[0]);
   return 0;
  case 'c':
   context = optarg;
   break;
  case 'f':
   from = optarg;
   break;
  case 't':
   to = optarg;
   break;
  case '?':
   print_usage(argv[0]);
   return -1;
   break;
  default:
   printf("huh?\n");
   break;
  }
 }
 if (!context) {
  fprintf(stderr, "--context not specified\n");
  return 1;
 }
 if (!from) {
  fprintf(stderr, "--from not specified\n");
  return 2;
 }
 if (!to) {
  fprintf(stderr, "--to not specified\n");
  return 3;
 }
 if (!strcmp(context, "cpu")) {
  if (!strcmp(from, "interrupt-server")) {
   interruptserver = strtol(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-index")) {
    if (!cpu_interruptserver_to_drcindex(
      interruptserver, &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "interrupt-server 0x%08x\n",
      interruptserver);
     return 4;
    }
    printf("0x%08x\n", drcindex);
   }
   else if (!strcmp(to, "drc-name")) {
    if (!cpu_interruptserver_to_drcindex(
      interruptserver, &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "interrupt-server 0x%08x\n",
      interruptserver);
     return 4;
    }
    if (!cpu_drcindex_to_drcname(drcindex,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else if (!strcmp(from, "drc-index")) {
   drcindex = strtol(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-name")) {
    if (!cpu_drcindex_to_drcname(drcindex,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
   else if (!strcmp(to, "interrupt-server")) {
    rc = cpu_drcindex_to_interruptserver(drcindex,
      intservs_array,
      16);
    if (!rc) {
     fprintf(stderr, "could not find the "
      "interrupt-server corresponding"
      " to drc-index 0x%08x\n",
      drcindex);
     return 4;
    }
    if (rc > 16)
     fprintf(stderr, "warning: only the "
      "first %d servers in the list "
      "of %d were returned; increase "
      "MAX_IRQ_SERVERS_PER_CPU to "
      "retrieve the entire list\n",
      16, rc);
    i = 0;
    while (i < rc)
     printf("0x%08x\n", intservs_array[i++]);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else if (!strcmp(from, "drc-name")) {
   strncpy(drcname, argv[argc-1], 20);
   if (!strcmp(to, "drc-index")) {
    if (!cpu_drcname_to_drcindex(drcname,
      &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "drc-name %s\n", drcname);
     return 4;
    }
    printf("0x%08x\n", drcindex);
   }
   else if (!strcmp(to, "interrupt-server")) {
    if (!cpu_drcname_to_drcindex(drcname,
      &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "drc-name %s\n", drcname);
     return 4;
    }
    rc = cpu_drcindex_to_interruptserver(drcindex,
      intservs_array,
      16);
    if (!rc) {
     fprintf(stderr, "could not find the "
      "interrupt-server corresponding"
      " to drc-index 0x%08x\n",
      drcindex);
     return 4;
    }
    if (rc > 16)
     fprintf(stderr, "warning: only the "
      "first %d servers in the list "
      "of %d were returned; increase "
      "MAX_IRQ_SERVERS_PER_CPU to "
      "retrieve the entire list\n",
      16, rc);
    i = 0;
    while (i < rc)
     printf("0x%08x\n", intservs_array[i++]);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else {
   fprintf(stderr, "invalid --from flag: %s\n", from);
   return 2;
  }
 }
 else if (!strcmp(context, "mem")) {
  if (!strcmp(from, "drc-index")) {
   drc_tmp_idx = strtoul(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-name")) {
    if (!mem_drcindex_to_drcname(drc_tmp_idx,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
  }
  else {
   fprintf(stderr, "invalid --to flag: %s\n", to);
   return 3;
  }
 }
 else {
  fprintf(stderr, "invalid --context flag: %s\n", context);
  return 1;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int option_index; int rc; int i;
 char *context = ((void *)0); char *from = ((void *)0); char *to = ((void *)0);
 unsigned int interruptserver; unsigned int drcindex;
 unsigned long drc_tmp_idx;
 unsigned int intservs_array[16];
 char drcname[20];
 for (;;) {
  option_index = 0;
  rc = getopt_long(argc, argv, "hc:f:t:", long_options,
    &option_index);
  if (rc == -1)
   break;
  switch (rc) {
  case 'h':
   print_usage(argv[0]);
   return 0;
  case 'c':
   context = optarg;
   break;
  case 'f':
   from = optarg;
   break;
  case 't':
   to = optarg;
   break;
  case '?':
   print_usage(argv[0]);
   return -1;
   break;
  default:
   printf("huh?\n");
   break;
  }
 }
 if (!context) {
  fprintf(stderr, "--context not specified\n");
  return 1;
 }
 if (!from) {
  fprintf(stderr, "--from not specified\n");
  return 2;
 }
 if (!to) {
  fprintf(stderr, "--to not specified\n");
  return 3;
 }
 if (!strcmp(context, "cpu")) {
  if (!strcmp(from, "interrupt-server")) {
   interruptserver = strtol(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-index")) {
    if (!cpu_interruptserver_to_drcindex(
      interruptserver, &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "interrupt-server 0x%08x\n",
      interruptserver);
     return 4;
    }
    printf("0x%08x\n", drcindex);
   }
   else if (!strcmp(to, "drc-name")) {
    if (!cpu_interruptserver_to_drcindex(
      interruptserver, &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "interrupt-server 0x%08x\n",
      interruptserver);
     return 4;
    }
    if (!cpu_drcindex_to_drcname(drcindex,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else if (!strcmp(from, "drc-index")) {
   drcindex = strtol(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-name")) {
    if (!cpu_drcindex_to_drcname(drcindex,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
   else if (!strcmp(to, "interrupt-server")) {
    rc = cpu_drcindex_to_interruptserver(drcindex,
      intservs_array,
      16);
    if (!rc) {
     fprintf(stderr, "could not find the "
      "interrupt-server corresponding"
      " to drc-index 0x%08x\n",
      drcindex);
     return 4;
    }
    if (rc > 16)
     fprintf(stderr, "warning: only the "
      "first %d servers in the list "
      "of %d were returned; increase "
      "MAX_IRQ_SERVERS_PER_CPU to "
      "retrieve the entire list\n",
      16, rc);
    i = 0;
    while (i < rc)
     printf("0x%08x\n", intservs_array[i++]);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else if (!strcmp(from, "drc-name")) {
   strncpy(drcname, argv[argc-1], 20);
   if (!strcmp(to, "drc-index")) {
    if (!cpu_drcname_to_drcindex(drcname,
      &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "drc-name %s\n", drcname);
     return 4;
    }
    printf("0x%08x\n", drcindex);
   }
   else if (!strcmp(to, "interrupt-server")) {
    if (!cpu_drcname_to_drcindex(drcname,
      &drcindex)) {
     fprintf(stderr, "could not find the "
      "drc-index corresponding to "
      "drc-name %s\n", drcname);
     return 4;
    }
    rc = cpu_drcindex_to_interruptserver(drcindex,
      intservs_array,
      16);
    if (!rc) {
     fprintf(stderr, "could not find the "
      "interrupt-server corresponding"
      " to drc-index 0x%08x\n",
      drcindex);
     return 4;
    }
    if (rc > 16)
     fprintf(stderr, "warning: only the "
      "first %d servers in the list "
      "of %d were returned; increase "
      "MAX_IRQ_SERVERS_PER_CPU to "
      "retrieve the entire list\n",
      16, rc);
    i = 0;
    while (i < rc)
     printf("0x%08x\n", intservs_array[i++]);
   }
   else {
    fprintf(stderr, "invalid --to flag: %s\n", to);
    return 3;
   }
  }
  else {
   fprintf(stderr, "invalid --from flag: %s\n", from);
   return 2;
  }
 }
 else if (!strcmp(context, "mem")) {
  if (!strcmp(from, "drc-index")) {
   drc_tmp_idx = strtoul(argv[argc-1], ((void *)0), 0);
   if (!strcmp(to, "drc-name")) {
    if (!mem_drcindex_to_drcname(drc_tmp_idx,
      drcname, 20)) {
     fprintf(stderr, "could not find the "
      "drc-name corresponding to "
      "drc-index 0x%08x\n", drcindex);
     return 4;
    }
    printf("%s\n", drcname);
   }
  }
  else {
   fprintf(stderr, "invalid --to flag: %s\n", to);
   return 3;
  }
 }
 else {
  fprintf(stderr, "invalid --context flag: %s\n", context);
  return 1;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
context
char *

variable_types:
from
char *

variable_types:
to
char *

variable_types:
interruptserver
unsigned int

variable_types:
drcindex
unsigned int

variable_types:
drcname
char [20]


decompiled_code:
time_t __fastcall compute_cur_year(time_t a1)
{
time_t result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = a1;
localtime_r(&timer, &tp);
*(_QWORD *)&tp.tm_sec = 0LL;
tp.tm_mon = 0;
cur_year = tp.tm_year++;
*(_QWORD *)&tp.tm_hour = 0x100000000LL;
tp.tm_isdst = -1;
result = mktime(&tp);
end_of_cur_year = result;
return result;
}

canonical_decompiled_code:
time_t __fastcall func0(time_t a1)
{
time_t result; // rax
time_t timer; // [rsp+8h] [rbp-50h] BYREF
struct tm tp; // [rsp+10h] [rbp-48h] BYREF

timer = a1;
localtime_r(&timer, &tp);
*(_QWORD *)&tp.tm_sec = 0LL;
tp.tm_mon = 0;
cur_year = tp.tm_year++;
*(_QWORD *)&tp.tm_hour = 0x100000000LL;
tp.tm_isdst = -1;
result = mktime(&tp);
end_of_cur_year = result;
return result;
}

original_code:
static void
compute_cur_year(time_t now)
{
 struct tm tm;
 localtime_r(&now, &tm);
 cur_year = tm.tm_year;
 tm.tm_mon = 0;
 tm.tm_mday = 1;
 tm.tm_year++;
 tm.tm_hour = 0;
 tm.tm_min = 0;
 tm.tm_sec = 0;
 tm.tm_isdst = -1;
 end_of_cur_year = mktime(&tm);
}

canonical_original_code:
static void compute_cur_year(long now)
{
 struct tm tm;
 localtime_r(&now, &tm);
 cur_year = tm.tm_year;
 tm.tm_mon = 0;
 tm.tm_mday = 1;
 tm.tm_year++;
 tm.tm_hour = 0;
 tm.tm_min = 0;
 tm.tm_sec = 0;
 tm.tm_isdst = -1;
 end_of_cur_year = mktime(&tm);
}

variable_types: now long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; }

return_type: void


decompiled_code:
__int64 __fastcall parse_syslog_date(char *a1, char **a2)
{
return parse_date(a1, a2, "%b %d %T", 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char **a2)
{
return func1(a1, a2, "%b %d %T", 0);
}

original_code:
time_t
parse_syslog_date(const char *start, char **end)
{
 return parse_date(start, end, "%b %d %T", false);
}

canonical_original_code:
long parse_syslog_date(char *start, char **end)
{
 return parse_date(start, end, "%b %d %T", false);
}

variable_types:
start
char *

variable_types:
end
char **

return_type: long


decompiled_code:
void __noreturn too_many_settings()
{
fprintf(stderr, "%s: cannot set fault or ident multiple times.\n", (const char *)progname);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
fprintf(stderr, "%s: cannot set fault or ident multiple times.\n", (const char *)progname);
exit(1);
}

original_code:
static void
too_many_settings(void)
{
 fprintf(stderr, "%s: cannot set fault or ident multiple times.\n",
        progname);
 exit(1);
}

canonical_original_code:
static void too_many_settings()
{
 fprintf(stderr, "%s: cannot set fault or ident multiple times.\n",
        progname);
 exit(1);
}


decompiled_code:
_BOOL8 __fastcall parse_on_off(__int64 a1)
{
bool v1; // zf
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 111 || *(_BYTE *)(a1 + 1) != 110 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
{
v1 = strcmp((const char *)a1, "off") == 0;
result = !v1;
if ( !v1 )
{
fprintf(stderr, "%s: expected 'on' or 'off'; saw '%s'.\n", (const char *)progname, (const char *)a1);
exit(1);
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
bool v1; // zf
_BOOL8 result; // rax

if ( *(_BYTE *)a1 != 111 || *(_BYTE *)(a1 + 1) != 110 || (result = 1LL, *(_BYTE *)(a1 + 2)) )
{
v1 = strcmp((const char *)a1, "off") == 0;
result = !v1;
if ( !v1 )
{
fprintf(stderr, "%s: expected 'on' or 'off'; saw '%s'.\n", (const char *)progname, (const char *)a1);
exit(1);
}
}
return result;
}

original_code:
static int
parse_on_off(const char *on_off)
{
 if (!strcmp(on_off, "on"))
  return 1;
 else if (!strcmp(on_off, "off"))
  return 0;
 fprintf(stderr, "%s: expected 'on' or 'off'; saw '%s'.\n", progname,
        on_off);
 exit(1);
}

canonical_original_code:
static int parse_on_off(char *on_off)
{
 if (!strcmp(on_off, "on"))
  return 1;
 else if (!strcmp(on_off, "off"))
  return 0;
 fprintf(stderr, "%s: expected 'on' or 'off'; saw '%s'.\n", progname,
        on_off);
 exit(1);
}


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"Usage: %s { -l | settings } [-v] enclosure [ component ]\n"
"\t-l | --list : report settings\n"
"\t-v | --verbose : verbose report\n"
"\t-V | --version : print the version of the command and exit\n"
"\t-h | --help : print this usage message and exit\n"
"\tsettings: [ -f on|off ] [ -i on|off ]\n"
"\t -f | --fault: turn component's fault LED element on/off.\n"
"\t -i | --ident: turn component's ident LED element on/off.\n"
"\tenclosure: sgN device name or location code of enclosure\n"
"\tcomponent: component's location sub-code -- e.g., P1-E2\n",
(const char *)progname);
}

canonical_decompiled_code:
int func2()
{
return fprintf(
stderr,
"Usage: %s { -l | settings } [-v] enclosure [ component ]\n"
"\t-l | --list : report settings\n"
"\t-v | --verbose : verbose report\n"
"\t-V | --version : print the version of the command and exit\n"
"\t-h | --help : print this usage message and exit\n"
"\tsettings: [ -f on|off ] [ -i on|off ]\n"
"\t -f | --fault: turn component's fault LED element on/off.\n"
"\t -i | --ident: turn component's ident LED element on/off.\n"
"\tenclosure: sgN device name or location code of enclosure\n"
"\tcomponent: component's location sub-code -- e.g., P1-E2\n",
(const char *)progname);
}

original_code:
static void
usage(void)
{
 fprintf(stderr,
  "Usage: %s { -l | settings } [-v] enclosure [ component ]\n"
  "\t-l | --list    : report settings\n"
  "\t-v | --verbose : verbose report\n"
  "\t-V | --version : print the version of the command "
        "and exit\n"
  "\t-h | --help    : print this usage message and exit\n"
  "\tsettings: [ -f on|off ] [ -i on|off ]\n"
  "\t  -f | --fault: turn component's fault LED element on/off.\n"
  "\t  -i | --ident: turn component's ident LED element on/off.\n"
  "\tenclosure: sgN device name or location code of enclosure\n"
  "\tcomponent: component's location sub-code -- e.g., P1-E2\n",
  progname);
}

canonical_original_code:
static void usage()
{
 fprintf(stderr,
  "Usage: %s { -l | settings } [-v] enclosure [ component ]\n"
  "\t-l | --list    : report settings\n"
  "\t-v | --verbose : verbose report\n"
  "\t-V | --version : print the version of the command "
        "and exit\n"
  "\t-h | --help    : print this usage message and exit\n"
  "\tsettings: [ -f on|off ] [ -i on|off ]\n"
  "\t  -f | --fault: turn component's fault LED element on/off.\n"
  "\t  -i | --ident: turn component's ident LED element on/off.\n"
  "\tenclosure: sgN device name or location code of enclosure\n"
  "\tcomponent: component's location sub-code -- e.g., P1-E2\n",
  progname);
}


decompiled_code:
int __fastcall open_sg_device(const char *a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-2Ch]
char s[40]; // [rsp+10h] [rbp-28h] BYREF

snprintf(s, 0x20uLL, "/dev/%s", a1);
result = open(s, 2);
if ( result < 0 )
{
v2 = result;
perror(s);
result = v2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char *a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-2Ch]
char s[40]; // [rsp+10h] [rbp-28h] BYREF

snprintf(s, 0x20uLL, "/dev/%s", a1);
result = open(s, 2);
if ( result < 0 )
{
v2 = result;
perror(s);
result = v2;
}
return result;
}

original_code:
int
open_sg_device(const char *encl)
{
 char dev_sg[32];
 int fd;
 snprintf(dev_sg, 32, "/dev/%s", encl);
 fd = open(dev_sg, 02);
 if (fd < 0)
  perror(dev_sg);
 return fd;
}

canonical_original_code:
int open_sg_device(char *encl)
{
 char dev_sg[32];
 int fd;
 snprintf(dev_sg, 32, "/dev/%s", encl);
 fd = open(dev_sg, 02);
 if (fd < 0)
  perror(dev_sg);
 return fd;
}

variable_types:
encl
char *

variable_types: fd int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
unsigned int v4; // er13
unsigned int v5; // er12
int v6; // ebx
int v7; // eax
int v8; // eax
char *v9; // r8
char *v10; // rdi
__int64 i; // rcx
__int64 v12; // rbp
__int64 v13; // rcx
__int64 v14; // r8
const char *v15; // rsi
int v17; // [rsp+0h] [rbp-368h]
const char *v18; // [rsp+8h] [rbp-360h]
int longind; // [rsp+1Ch] [rbp-34Ch] BYREF
char dest[128]; // [rsp+20h] [rbp-348h] BYREF
char s1[712]; // [rsp+A0h] [rbp-2C8h] BYREF

v3 = 0;
v4 = -1;
v5 = -1;
v6 = 0;
progname = (__int64)*argv;
while ( 2 )
{
longind = 0;
v7 = getopt_long(argc, (char *const *)argv, "f:hi:lvV", &long_options, &longind);
if ( v7 != -1 )
{
switch ( v7 )
{
case 'V':
printf("%s %s\n", *argv, (const char *)&unk_6CE);
exit(0);
case 'f':
if ( v4 != -1 )
goto LABEL_30;
v4 = parse_on_off((__int64)optarg);
continue;
case 'h':
usage();
exit(0);
case 'i':
if ( v5 != -1 )
LABEL_30:
too_many_settings();
v5 = parse_on_off((__int64)optarg);
continue;
case 'l':
v6 = 1;
continue;
case 'v':
v3 = 1;
continue;
default:
goto LABEL_4;
}
}
break;
}
v8 = optind;
if ( optind < argc )
{
++optind;
v9 = (char *)argv[v8];
if ( v8 + 1 < argc )
{
optind = v8 + 2;
if ( v8 + 2 < argc )
goto LABEL_4;
v18 = argv[v8 + 1];
}
else
{
v18 = 0LL;
}
if ( v6 || (v5 & v4) != -1 )
{
v10 = dest;
for ( i = 32LL; i; --i )
{
*(_DWORD *)v10 = 0;
v10 += 4;
}
if ( !(unsigned int)enclosure_dev_name_constprop_0(v9, dest) )
{
memset(s1, 0, 0x288uLL);
if ( !(unsigned int)read_vpd_from_lscfg(s1, dest) )
{
v12 = 0LL;
do
{
v17 = v12;
v15 = (&encl_list)[3 * v12];
if ( !v15 )
{
fprintf(stderr, "No indicator support for device type/model : %s\n", s1);
goto LABEL_27;
}
++v12;
}
while ( strcmp(s1, v15) );
if ( v6 )
{
if ( (v5 & v4) == -1 )
{
if ( ((unsigned int (__fastcall *)(char *, const char *, _QWORD, __int64, __int64))*(&off_AC8 + 3 * v17))(
dest,
v18,
v3,
v13,
v14) )
{
goto LABEL_36;
}
goto LABEL_27;
}
goto LABEL_4;
}
if ( !geteuid() )
{
if ( ((unsigned int (__fastcall *)(char *, const char *, _QWORD, _QWORD, _QWORD))*(&off_AD0 + 3 * v17))(
dest,
v18,
v4,
v5,
v3) )
{
LABEL_36:
exit(2);
}
LABEL_27:
exit(0);
}
fprintf(stderr, "%s: Turning LEDs on/off requires superuser privileges.\n", (const char *)progname);
}
}
exit(1);
}
}
LABEL_4:
usage();
exit(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
unsigned int v4; // er13
unsigned int v5; // er12
int v6; // ebx
int v7; // eax
int v8; // eax
char *v9; // r8
char *v10; // rdi
__int64 i; // rcx
__int64 v12; // rbp
__int64 v13; // rcx
__int64 v14; // r8
const char *v15; // rsi
int v17; // [rsp+0h] [rbp-368h]
const char *v18; // [rsp+8h] [rbp-360h]
int longind; // [rsp+1Ch] [rbp-34Ch] BYREF
char dest[128]; // [rsp+20h] [rbp-348h] BYREF
char s1[712]; // [rsp+A0h] [rbp-2C8h] BYREF

v3 = 0;
v4 = -1;
v5 = -1;
v6 = 0;
progname = (__int64)*argv;
while ( 2 )
{
longind = 0;
v7 = getopt_long(argc, (char *const *)argv, "f:hi:lvV", &long_options, &longind);
if ( v7 != -1 )
{
switch ( v7 )
{
case 'V':
printf("%s %s\n", *argv, (const char *)&unk_6CE);
exit(0);
case 'f':
if ( v4 != -1 )
goto LABEL_30;
v4 = func1((__int64)optarg);
continue;
case 'h':
func2();
exit(0);
case 'i':
if ( v5 != -1 )
LABEL_30:
func0();
v5 = func1((__int64)optarg);
continue;
case 'l':
v6 = 1;
continue;
case 'v':
v3 = 1;
continue;
default:
goto LABEL_4;
}
}
break;
}
v8 = optind;
if ( optind < argc )
{
++optind;
v9 = (char *)argv[v8];
if ( v8 + 1 < argc )
{
optind = v8 + 2;
if ( v8 + 2 < argc )
goto LABEL_4;
v18 = argv[v8 + 1];
}
else
{
v18 = 0LL;
}
if ( v6 || (v5 & v4) != -1 )
{
v10 = dest;
for ( i = 32LL; i; --i )
{
*(_DWORD *)v10 = 0;
v10 += 4;
}
if ( !(unsigned int)func4(v9, dest) )
{
memset(s1, 0, 0x288uLL);
if ( !(unsigned int)read_vpd_from_lscfg(s1, dest) )
{
v12 = 0LL;
do
{
v17 = v12;
v15 = (&encl_list)[3 * v12];
if ( !v15 )
{
fprintf(stderr, "No indicator support for device type/model : %s\n", s1);
goto LABEL_27;
}
++v12;
}
while ( strcmp(s1, v15) );
if ( v6 )
{
if ( (v5 & v4) == -1 )
{
if ( ((unsigned int (__fastcall *)(char *, const char *, _QWORD, __int64, __int64))*(&off_AC8 + 3 * v17))(
dest,
v18,
v3,
v13,
v14) )
{
goto LABEL_36;
}
goto LABEL_27;
}
goto LABEL_4;
}
if ( !geteuid() )
{
if ( ((unsigned int (__fastcall *)(char *, const char *, _QWORD, _QWORD, _QWORD))*(&off_AD0 + 3 * v17))(
dest,
v18,
v4,
v5,
v3) )
{
LABEL_36:
exit(2);
}
LABEL_27:
exit(0);
}
fprintf(stderr, "%s: Turning LEDs on/off requires superuser privileges.\n", (const char *)progname);
}
}
exit(1);
}
}
LABEL_4:
func2();
exit(1);
}

original_code:
int
main(int argc, char **argv)
{
 int rc, option_index, i;
 int list_opt = 0, verbose = 0, found = 0;
 int fault_setting = -1, ident_setting = -1;
 const char *enclosure = ((void *)0), *component = ((void *)0);
 char sg[128];
 struct dev_vpd vpd;
 progname = argv[0];
 for (;;) {
  option_index = 0;
  rc = getopt_long(argc, argv, "f:hi:lvV", long_options,
       &option_index);
  if (rc == -1)
   break;
  switch (rc) {
  case 'f':
   if (fault_setting != -1)
    too_many_settings();
   fault_setting = parse_on_off(optarg);
   break;
  case 'h':
   usage();
   exit(0);
  case 'i':
   if (ident_setting != -1)
    too_many_settings();
   ident_setting = parse_on_off(optarg);
   break;
  case 'l':
   list_opt = 1;
   break;
  case 'v':
   verbose = 1;
   break;
  case 'V':
   printf("%s %s\n", argv[0], "");
   exit(0);
  case '?':
  default:
   usage();
   exit(1);
  }
 }
 if (optind < argc)
  enclosure = argv[optind++];
 else {
  usage();
  exit(1);
 }
 if (optind < argc)
  component = argv[optind++];
 if (optind < argc) {
  usage();
  exit(1);
 }
 if (!list_opt && fault_setting == -1 &&
        ident_setting == -1) {
  usage();
  exit(1);
 }
 memset(sg, 0, sizeof(sg));
 if (enclosure_dev_name(enclosure, sg, sizeof(sg)) != 0)
  exit(1);
 memset(&vpd, 0, sizeof(vpd));
 if (read_vpd_from_lscfg(&vpd, sg) != 0)
  exit(1);
 for (i = 0; encl_list[i].mtm; i++)
  if (!strcmp(vpd.mtm, encl_list[i].mtm)) {
   found = 1;
   break;
  }
 if (!found) {
  fprintf(stderr, "No indicator support for device type/model :"
    " %s\n", vpd.mtm);
  exit(0);
 }
 if (list_opt) {
  if (fault_setting != -1 || ident_setting != -1) {
   usage();
   exit(1);
  }
  if (encl_list[i].list_leds(sg, component, verbose) != 0)
   exit(2);
 } else {
  if (geteuid() != 0) {
   fprintf(stderr, "%s: Turning LEDs on/off requires "
     "superuser privileges.\n", progname);
   exit(1);
  }
  if (encl_list[i].set_led(sg, component, fault_setting,
      ident_setting, verbose) != 0)
   exit(2);
 }
 exit(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int rc; int option_index; int i;
 int list_opt = 0; int verbose = 0; int found = 0;
 int fault_setting = -1; int ident_setting = -1;
 char *enclosure = ((void *)0); char *component = ((void *)0);
 char sg[128];
 struct dev_vpd vpd;
 progname = argv[0];
 for (;;) {
  option_index = 0;
  rc = getopt_long(argc, argv, "f:hi:lvV", long_options,
       &option_index);
  if (rc == -1)
   break;
  switch (rc) {
  case 'f':
   if (fault_setting != -1)
    too_many_settings();
   fault_setting = parse_on_off(optarg);
   break;
  case 'h':
   usage();
   exit(0);
  case 'i':
   if (ident_setting != -1)
    too_many_settings();
   ident_setting = parse_on_off(optarg);
   break;
  case 'l':
   list_opt = 1;
   break;
  case 'v':
   verbose = 1;
   break;
  case 'V':
   printf("%s %s\n", argv[0], "");
   exit(0);
  case '?':
  default:
   usage();
   exit(1);
  }
 }
 if (optind < argc)
  enclosure = argv[optind++];
 else {
  usage();
  exit(1);
 }
 if (optind < argc)
  component = argv[optind++];
 if (optind < argc) {
  usage();
  exit(1);
 }
 if (!list_opt && fault_setting == -1 &&
        ident_setting == -1) {
  usage();
  exit(1);
 }
 memset(sg, 0, sizeof(sg));
 if (enclosure_dev_name(enclosure, sg, sizeof(sg)) != 0)
  exit(1);
 memset(&vpd, 0, sizeof(vpd));
 if (read_vpd_from_lscfg(&vpd, sg) != 0)
  exit(1);
 for (i = 0; encl_list[i].mtm; i++)
  if (!strcmp(vpd.mtm, encl_list[i].mtm)) {
   found = 1;
   break;
  }
 if (!found) {
  fprintf(stderr, "No indicator support for device type/model :"
    " %s\n", vpd.mtm);
  exit(0);
 }
 if (list_opt) {
  if (fault_setting != -1 || ident_setting != -1) {
   usage();
   exit(1);
  }
  if (encl_list[i].list_leds(sg, component, verbose) != 0)
   exit(2);
 } else {
  if (geteuid() != 0) {
   fprintf(stderr, "%s: Turning LEDs on/off requires "
     "superuser privileges.\n", progname);
   exit(1);
  }
  if (encl_list[i].set_led(sg, component, fault_setting,
      ident_setting, verbose) != 0)
   exit(2);
 }
 exit(0);
}

variable_types:
argv
char **

variable_types: i int

variable_types: verbose int

variable_types: found int

variable_types:
enclosure
char *

variable_types:
component
char *

variable_types:
sg
char [128]

variable_types: struct dev_vpd { char mtm[128]; char location[128]; char full_loc[128]; char sn[128]; char fru[128]; struct dev_vpd *next; }


usage

decompiled_code:
void __noreturn usage(void)
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax

v0 = std::operator<<<std::char_traits<char>>(&std::cerr, "usage: ");
v1 = std::operator<<<std::char_traits<char>>(v0, progname);
v2 = std::operator<<<std::char_traits<char>>(v1, " [-C catalog_dir]");
std::ostream::operator<<(v2, &std::endl<char,std::char_traits<char>>);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(void)
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax

v0 = std::operator<<<std::char_traits<char>>(&std::cerr, "usage: ");
v1 = std::operator<<<std::char_traits<char>>(v0, progname);
v2 = std::operator<<<std::char_traits<char>>(v1, " [-C catalog_dir]");
std::ostream::operator<<(v2, &std::endl<char,std::char_traits<char>>);
exit(1);
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bool v3; // bl
char v4[35]; // [rsp+10h] [rbp-40h] BYREF
char v5; // [rsp+33h] [rbp-1Dh] BYREF
int v6; // [rsp+34h] [rbp-1Ch]
char *v7; // [rsp+38h] [rbp-18h]

v7 = "/etc/ppc64-diag/message_catalog";
progname = (__int64)*argv;
opterr = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "C:");
if ( v6 == -1 )
break;
if ( v6 == 63 )
usage();
if ( v6 == 67 )
v7 = optarg;
}
if ( argc != optind )
usage();
regex_text_policy = 1;
std::allocator<char>::allocator(&v5);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v4, v7, &v5);
v3 = (unsigned int)EventCatalog::parse(v4) != 0;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v4);
std::allocator<char>::~allocator(&v5);
if ( v3 )
exit(2);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
bool v3; // bl
char v4[35]; // [rsp+10h] [rbp-40h] BYREF
char v5; // [rsp+33h] [rbp-1Dh] BYREF
int v6; // [rsp+34h] [rbp-1Ch]
char *v7; // [rsp+38h] [rbp-18h]

v7 = "/etc/ppc64-diag/message_catalog";
progname = (__int64)*argv;
opterr = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "C:");
if ( v6 == -1 )
break;
if ( v6 == 63 )
func0();
if ( v6 == 67 )
v7 = optarg;
}
if ( argc != optind )
func0();
regex_text_policy = 1;
std::allocator<char>::allocator(&v5);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v4, v7, &v5);
v3 = (unsigned int)EventCatalog::parse(v4) != 0;
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v4);
std::allocator<char>::~allocator(&v5);
if ( v3 )
exit(2);
exit(0);
}

variable_types: argc int

variable_types: rc int

user_defined_types: struct dev_vpd { char mtm[128]; char location[128]; char full_loc[128]; char sn[128]; char fru[128]; struct dev_vpd *next; }


usage

repo: tzcoolman/FACS-OLD

decompiled_code:
__int64 usage()
{
fputc(10, stderr);
fwrite("Program: facs (Sequence decontamination using bloom filters)\n", 1uLL, 0x3DuLL, stderr);
fprintf(stderr, "Version: %s\n", "0.1");
fwrite("Contact: Enze Liu <enze.liu@scilifelab.se>\n\n", 1uLL, 0x2CuLL, stderr);
fwrite("Usage: facs <command> [options]\n\n", 1uLL, 0x23uLL, stderr);
fwrite("Command: build build a bloom filter from a FASTA reference file\n", 1uLL, 0x48uLL, stderr);
fwrite(
" query query a bloom filter given a FASTQ/FASTA file. Large files and compressed files supported\n",
1uLL,
0x71uLL,
stderr);
fwrite(
" check query a bloom filter given a FASTQ/FASTA file. Faster than query\n",
1uLL,
0x58uLL,
stderr);
fwrite(" remove remove (contamination) sequences from FASTQ/FASTA file\n", 1uLL, 0x4EuLL, stderr);
fwrite(" classify classify reads to the most likely reference genomes\n", 1uLL, 0x4BuLL, stderr);
fputc(10, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
fputc(10, stderr);
fwrite("Program: facs (Sequence decontamination using bloom filters)\n", 1uLL, 0x3DuLL, stderr);
fprintf(stderr, "Version: %s\n", "0.1");
fwrite("Contact: Enze Liu <enze.liu@scilifelab.se>\n\n", 1uLL, 0x2CuLL, stderr);
fwrite("Usage: facs <command> [options]\n\n", 1uLL, 0x23uLL, stderr);
fwrite("Command: build build a bloom filter from a FASTA reference file\n", 1uLL, 0x48uLL, stderr);
fwrite(
" query query a bloom filter given a FASTQ/FASTA file. Large files and compressed files supported\n",
1uLL,
0x71uLL,
stderr);
fwrite(
" check query a bloom filter given a FASTQ/FASTA file. Faster than query\n",
1uLL,
0x58uLL,
stderr);
fwrite(" remove remove (contamination) sequences from FASTQ/FASTA file\n", 1uLL, 0x4EuLL, stderr);
fwrite(" classify classify reads to the most likely reference genomes\n", 1uLL, 0x4BuLL, stderr);
fputc(10, stderr);
return 1LL;
}

original_code:
static int
usage(void)
{
    fprintf(stderr, "\n");
    fprintf(stderr, "Program: facs (Sequence decontamination using bloom filters)\n");
    fprintf(stderr, "Version: %s\n", "0.1");
    fprintf(stderr, "Contact: Enze Liu <enze.liu@scilifelab.se>\n\n");
    fprintf(stderr, "Usage:   facs <command> [options]\n\n");
    fprintf(stderr, "Command: build         build a bloom filter from a FASTA reference file\n");
    fprintf(stderr, "         query         query a bloom filter given a FASTQ/FASTA file. Large files and compressed files supported\n");
    fprintf(stderr, "         check         query a bloom filter given a FASTQ/FASTA file. Faster than query\n");
    fprintf(stderr, "         remove        remove (contamination) sequences from FASTQ/FASTA file\n");
    fprintf(stderr, "         classify      classify reads to the most likely reference genomes\n");
    fprintf(stderr, "\n");
    return 1;
}

canonical_original_code:
static int usage()
{
    fprintf(stderr, "\n");
    fprintf(stderr, "Program: facs (Sequence decontamination using bloom filters)\n");
    fprintf(stderr, "Version: %s\n", "0.1");
    fprintf(stderr, "Contact: Enze Liu <enze.liu@scilifelab.se>\n\n");
    fprintf(stderr, "Usage:   facs <command> [options]\n\n");
    fprintf(stderr, "Command: build         build a bloom filter from a FASTA reference file\n");
    fprintf(stderr, "         query         query a bloom filter given a FASTQ/FASTA file. Large files and compressed files supported\n");
    fprintf(stderr, "         check         query a bloom filter given a FASTQ/FASTA file. Faster than query\n");
    fprintf(stderr, "         remove        remove (contamination) sequences from FASTQ/FASTA file\n");
    fprintf(stderr, "         classify      classify reads to the most likely reference genomes\n");
    fprintf(stderr, "\n");
    return 1;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rdx

if ( argc <= 1 )
return usage(argc, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "build") )
return build_main((unsigned int)(argc - 1), argv + 1, envp);
if ( !strcmp(v3, "check") )
return check_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "query") )
return bq_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "remove") )
return remove_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "classify") )
return remove_l_main((unsigned int)(argc - 1), argv + 1);
usage(v3, "classify", v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
__int64 v4; // rdx

if ( argc <= 1 )
return func0(argc, argv, envp);
v3 = argv[1];
if ( !strcmp(v3, "build") )
return build_main((unsigned int)(argc - 1), argv + 1, envp);
if ( !strcmp(v3, "check") )
return check_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "query") )
return bq_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "remove") )
return remove_main((unsigned int)(argc - 1), argv + 1);
if ( !strcmp(v3, "classify") )
return remove_l_main((unsigned int)(argc - 1), argv + 1);
func0(v3, "classify", v4);
return 0;
}

original_code:
int main (int argc, char **argv)
{
  int ret=0;
  if (argc < 2) return usage();
  if (strcmp(argv[1], "build") == 0) ret = build_main(argc-1, argv+1);
  else if (strcmp(argv[1], "check") == 0) ret = check_main(argc-1, argv+1);
  else if (strcmp(argv[1], "query") == 0) ret = bq_main(argc-1, argv+1);
  else if (strcmp(argv[1], "remove") == 0) ret = remove_main(argc-1, argv+1);
  else if (strcmp(argv[1], "classify") == 0) ret = remove_l_main(argc-1,argv+1);
  else usage();
  return ret;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int ret = 0;
  if (argc < 2) return usage();
  if (strcmp(argv[1], "build") == 0) ret = build_main(argc-1, argv+1);
  else if (strcmp(argv[1], "check") == 0) ret = check_main(argc-1, argv+1);
  else if (strcmp(argv[1], "query") == 0) ret = bq_main(argc-1, argv+1);
  else if (strcmp(argv[1], "remove") == 0) ret = remove_main(argc-1, argv+1);
  else if (strcmp(argv[1], "classify") == 0) ret = remove_l_main(argc-1,argv+1);
  else usage();
  return ret;
}

variable_types: ret int


decompiled_code:
double __fastcall get_mu(__int64 a1, double a2)
{
double result; // xmm0_8

if ( a1 < 0 )
result = ((double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)))
* a2;
else
result = (double)(int)a1 * a2;
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, double a2)
{
double result; // xmm0_8

if ( a1 < 0 )
result = ((double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)))
* a2;
else
result = (double)(int)a1 * a2;
return result;
}

original_code:
double get_mu (unsigned long long num_hit, double prob)
{
       return ((double)num_hit)*prob;
}

canonical_original_code:
double get_mu(unsigned long long num_hit, double prob)
{
       return ((double)num_hit)*prob;
}

variable_types: prob double

return_type: double


decompiled_code:
double __fastcall get_sigma(__int64 a1, double a2)
{
double v3; // xmm0_8

if ( a1 < 0 )
v3 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
else
v3 = (double)(int)a1;
return v3 * a2 * (1.0 - a2);
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, double a2)
{
double v3; // xmm0_8

if ( a1 < 0 )
v3 = (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1)) + (double)(int)(a1 & 1 | ((unsigned __int64)a1 >> 1));
else
v3 = (double)(int)a1;
return v3 * a2 * (1.0 - a2);
}

original_code:
double get_sigma (unsigned long long num_hit, double prob)
{
       return (double)num_hit*prob*(1-prob);
}

canonical_original_code:
double get_sigma(unsigned long long num_hit, double prob)
{
       return (double)num_hit*prob*(1-prob);
}


decompiled_code:
__off_t __fastcall get_size(const char *a1)
{
int v1; // eax
struct stat64 v3; // [rsp+0h] [rbp-98h] BYREF

v1 = open64(a1, 0);
if ( v1 < 0 )
{
puts("open file error...");
exit(-1);
}
fstat64(v1, &v3);
return v3.st_size;
}

canonical_decompiled_code:
__off_t __fastcall func2(const char *a1)
{
int v1; // eax
struct stat64 v3; // [rsp+0h] [rbp-98h] BYREF

v1 = open64(a1, 0);
if ( v1 < 0 )
{
puts("open file error...");
exit(-1);
}
fstat64(v1, &v3);
return v3.st_size;
}

original_code:
long long get_size (char *filename)
{
long long tim;
struct stat statbuf;
if ((tim=open(filename, 00))<0)
    {
     printf("open file error...\n");
     exit(-1);
    }
fstat (tim, &statbuf);
return statbuf.st_size;
}

canonical_original_code:
long long get_size(char *filename)
{
long long tim;
struct stat statbuf;
if ((tim=open(filename, 00))<0)
    {
     printf("open file error...\n");
     exit(-1);
    }
fstat (tim, &statbuf);
return statbuf.st_size;
}

variable_types:
filename
char *

variable_types:
tim
long long

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

return_type: long long

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


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

result = 15LL;
if ( a1 > 10485759 )
{
result = 16LL;
if ( a1 > 20971519 )
{
result = 17LL;
if ( a1 > 52428799 )
{
result = 18LL;
if ( a1 > 104857599 )
result = (unsigned int)(a1 > 524287999) + 19;
}
}
}
return result;
}

original_code:
int kmer_suggestion (long long size)
{
  if (size<10*1048576)
     {
      return 15;
     }
  else if (size<20*1048576)
     {
      return 16;
     }
  else if (size<50*1048576)
     {
      return 17;
     }
  else if (size<100*1048576)
     {
      return 18;
     }
  else if (size<500*1048576)
     {
      return 19;
     }
  else
     {
      return 20;
     }
}

canonical_original_code:
int kmer_suggestion(long long size)
{
  if (size<10*1048576)
     {
      return 15;
     }
  else if (size<20*1048576)
     {
      return 16;
     }
  else if (size<50*1048576)
     {
      return 17;
     }
  else if (size<100*1048576)
     {
      return 18;
     }
  else if (size<500*1048576)
     {
      return 19;
     }
  else
     {
      return 20;
     }
}

variable_types:
size
long long


decompiled_code:
float __fastcall mco_suggestion(int a1)
{
__int64 v1; // rdi
float result; // xmm0_4

v1 = (unsigned int)(a1 - 16);
result = *(float *)&LC2;
if ( (unsigned int)v1 <= 4 )
result = CSWTCH_5[v1];
return result;
}

canonical_decompiled_code:
float __fastcall func4(int a1)
{
__int64 v1; // rdi
float result; // xmm0_4

v1 = (unsigned int)(a1 - 16);
result = *(float *)&LC2;
if ( (unsigned int)v1 <= 4 )
result = CSWTCH_5[v1];
return result;
}

original_code:
float mco_suggestion (int k_mer)
{
switch (k_mer)
  {
    case 15:
     return 0.4;
    case 16:
        return 0.3;
    case 17:
        return 0.3;
    case 18:
        return 0.3;
    case 19:
        return 0.4;
    case 20:
        return 0.3;
    default:
        return 0.4;
  }
}

canonical_original_code:
float mco_suggestion(int k_mer)
{
switch (k_mer)
  {
    case 15:
     return 0.4;
    case 16:
        return 0.3;
    case 17:
        return 0.3;
    case 18:
        return 0.3;
    case 19:
        return 0.4;
    case 20:
        return 0.3;
    default:
        return 0.4;
  }
}

return_type: float


original_code:
int
is_prime (unsigned long long m)
{
  unsigned long long a = (unsigned long long) ((long double)sqrt((double)(long double) m));
  unsigned long long currval = 3;
  if (m % 2 == 0 && m != 2)
    return 0;
  while (m % currval != 0 && currval < a)
    {
      if (m % (currval + 2) == 0)
 return 0;
      if (m % (currval + 4) == 0)
 return 0;
      currval += 8;
    }
  return (int) m % currval;
}

canonical_original_code:
int is_prime(unsigned long long m)
{
  unsigned long long a = (unsigned long long) ((long double)sqrt((double)(long double) m));
  unsigned long long currval = 3;
  if (m % 2 == 0 && m != 2)
    return 0;
  while (m % currval != 0 && currval < a)
    {
      if (m % (currval + 2) == 0)
 return 0;
      if (m % (currval + 4) == 0)
 return 0;
      currval += 8;
    }
  return (int) m % currval;
}

variable_types:
m
unsigned long long

variable_types:
a
unsigned long long

variable_types:
currval
unsigned long long


decompiled_code:
unsigned __int64 __fastcall find_close_prime(__int64 a1)
{
unsigned __int64 i; // r12

for ( i = ((a1 & 1) == 0) + a1; !(unsigned int)is_prime(i); i += 2LL )
;
return i;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(__int64 a1)
{
unsigned __int64 i; // r12

for ( i = ((a1 & 1) == 0) + a1; !(unsigned int)func5(i); i += 2LL )
;
return i;
}

original_code:
unsigned long long
find_close_prime (unsigned long long m)
{
  if ((m % 2) == 0)
    m += 1;
  while (!is_prime (m))
    {
      m += 2;
    }
  return m;
}

canonical_original_code:
unsigned long long find_close_prime(unsigned long long m)
{
  if ((m % 2) == 0)
    m += 1;
  while (!is_prime (m))
    {
      m += 2;
    }
  return m;
}

return_type: unsigned long long


decompiled_code:
unsigned __int64 __fastcall get_rec(__int64 a1)
{
double v1; // xmm0_8
unsigned __int64 v2; // rax
__int64 v3; // rdx
unsigned __int64 result; // rax

v1 = (double)(int)log(*(double *)(a1 + 24)) / -0.6931471805599453;
*(_DWORD *)(a1 + 8) = (int)v1;
v2 = find_close_prime(13 * *(_QWORD *)(a1 + 16) * (int)v1 / 9uLL);
v3 = *(_QWORD *)(a1 + 16);
*(_QWORD *)a1 = v2;
result = 9 * v2 / (13 * v3);
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
void
get_rec (struct bloomstat *stat)
{
  stat->ideal_hashes = (int) log (stat->e) / log (0.5);
  stat->elements =
    find_close_prime ((unsigned long long) 13 * stat->capacity *
        (unsigned long long) stat->ideal_hashes / (unsigned long long) 9);
  stat->ideal_hashes = 9 * stat->elements / (13 * stat->capacity);
}

canonical_original_code:
void get_rec(struct bloomstat *stat)
{
  stat->ideal_hashes = (int) log (stat->e) / log (0.5);
  stat->elements =
    find_close_prime ((unsigned long long) 13 * stat->capacity *
        (unsigned long long) stat->ideal_hashes / (unsigned long long) 9);
  stat->ideal_hashes = 9 * stat->elements / (13 * stat->capacity);
}

variable_types: struct bloomstat { unsigned long long elements; int ideal_hashes; unsigned long long capacity; double e; } *


decompiled_code:
__int64 __fastcall get_suggestion(__int64 a1, __int64 a2, double a3)
{
*(_QWORD *)(a1 + 16) = a2;
*(double *)(a1 + 24) = a3;
get_rec(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, double a3)
{
*(_QWORD *)(a1 + 16) = a2;
*(double *)(a1 + 24) = a3;
func7(a1);
return 0LL;
}

original_code:
int
get_suggestion (struct bloomstat *stats, unsigned long long n, double e)
{
  stats->capacity = n;
  stats->e = e;
  get_rec (stats);
  return 0;
}

canonical_original_code:
int get_suggestion(struct bloomstat *stats, unsigned long long n, double e)
{
  stats->capacity = n;
  stats->e = e;
  get_rec (stats);
  return 0;
}

variable_types:
n
unsigned long long

variable_types: e double

user_defined_types: struct bloomstat { unsigned long long elements; int ideal_hashes; unsigned long long capacity; double e; }


decompiled_code:
char **__fastcall fastq_process_m(__int64 a1, __int64 a2, char **a3, __int64 a4, float a5)
{
char **result; // rax
const char *v6; // rbp
char *v8; // r14
const char *v9; // r15
char *v10; // rbx
char *v11; // rax
_BYTE *v12; // r15
_BYTE *v13; // r15

result = *(char ***)(a2 + 24);
if ( result )
{
v6 = *(const char **)a2;
if ( result == a3 )
{
result = (char **)strlen(*(const char **)a2);
v8 = (char *)result + (_QWORD)v6;
}
else
{
v8 = *result;
}
if ( v6 && v6 != v8 )
{
do
{
v9 = strchr(v6, 10) + 1;
v10 = strstr(v9, "\n@");
if ( !v10 )
v10 = (char *)&v9[strlen(v9)];
v11 = strchr(v9, 10);
result = (char **)fastq_read_check(v9, v11 - v9, 110LL, a1, a4, a5);
if ( (_DWORD)result )
{
if ( (int)result <= 0 )
{
if ( !*v10 )
return result;
goto LABEL_9;
}
GOMP_critical_start();
memcpy(contam, v6, v10 - v6);
v13 = (char *)contam + v10 - v6;
contam = v13;
if ( *v10 )
{
*v13 = 10;
contam = (char *)contam + 1;
}
}
else
{
GOMP_critical_start();
memcpy(clean, v6, v10 - v6);
v12 = (char *)clean + v10 - v6;
clean = v12;
if ( *v10 )
{
*v12 = 10;
clean = (char *)clean + 1;
}
}
result = (char **)GOMP_critical_end();
if ( !*v10 )
return result;
LABEL_9:
v6 = v10 + 1;
}
while ( v10 + 1 != v8 );
}
}
return result;
}

canonical_decompiled_code:
char **__fastcall func1(__int64 a1, __int64 a2, char **a3, __int64 a4, float a5)
{
char **result; // rax
const char *v6; // rbp
char *v8; // r14
const char *v9; // r15
char *v10; // rbx
char *v11; // rax
_BYTE *v12; // r15
_BYTE *v13; // r15

result = *(char ***)(a2 + 24);
if ( result )
{
v6 = *(const char **)a2;
if ( result == a3 )
{
result = (char **)strlen(*(const char **)a2);
v8 = (char *)result + (_QWORD)v6;
}
else
{
v8 = *result;
}
if ( v6 && v6 != v8 )
{
do
{
v9 = strchr(v6, 10) + 1;
v10 = strstr(v9, "\n@");
if ( !v10 )
v10 = (char *)&v9[strlen(v9)];
v11 = strchr(v9, 10);
result = (char **)fastq_read_check(v9, v11 - v9, 110LL, a1, a4, a5);
if ( (_DWORD)result )
{
if ( (int)result <= 0 )
{
if ( !*v10 )
return result;
goto LABEL_9;
}
GOMP_critical_start();
memcpy(contam, v6, v10 - v6);
v13 = (char *)contam + v10 - v6;
contam = v13;
if ( *v10 )
{
*v13 = 10;
contam = (char *)contam + 1;
}
}
else
{
GOMP_critical_start();
memcpy(clean, v6, v10 - v6);
v12 = (char *)clean + v10 - v6;
clean = v12;
if ( *v10 )
{
*v12 = 10;
clean = (char *)clean + 1;
}
}
result = (char **)GOMP_critical_end();
if ( !*v10 )
return result;
LABEL_9:
v6 = v10 + 1;
}
while ( v10 + 1 != v8 );
}
}
return result;
}

original_code:
void
fastq_process_m (bloom * bl, Queue * info, Queue * tail, float tole_rate, F_set *File_head)
{
  int read_num = 0, read_contam = 0;
  char *p = info->location;
  char *next, *temp_start, *temp_end, *temp_piece = ((void *)0);
  if (info->next == ((void *)0))
    return;
  else if (info->next != tail)
    next = info->next->location;
  else
    next = strchr (p, '\0');
  while (p != next)
    {
      read_num++;
      temp_start = p;
      if (p == '\0' || p == ((void *)0))
 break;
      p = strchr (p, '\n') + 1;
      temp_end = strstr (p, "\n@");
      if (!temp_end)
 temp_end = strchr (p, '\0');
      int result =
 fastq_read_check (p, strchr (p, '\n') - p, 'n', bl, tole_rate, File_head);
      if (result == 0)
 {

#pragma omp critical
   {
     memcpy (clean, temp_start, temp_end - temp_start);
     clean += (temp_end - temp_start);
     if (*temp_end != '\0')
       {
  clean[0] = '\n';
  clean++;
       }
   }
 }
      else if (result > 0)
 {

#pragma omp critical
   {
            read_contam++;
     memcpy (contam, temp_start, temp_end - temp_start);
     contam += (temp_end - temp_start);
     if (*temp_end != '\0')
       {
  contam[0] = '\n';
  contam++;
       }
   }
 }
      if (*temp_end == '\0')
 break;
      p = temp_end + 1;
    }
  if (temp_piece)
    free (temp_piece);
}

canonical_original_code:
void fastq_process_m(struct bloom *bl, struct info *info, struct info *tail, float tole_rate, struct file_list *File_head)
{
  int read_num = 0; int read_contam = 0;
  char *p = info->location;
  char *next; char *temp_start; char *temp_end; char *temp_piece = ((void *)0);
  if (info->next == ((void *)0))
    return;
  else if (info->next != tail)
    next = info->next->location;
  else
    next = strchr (p, '\0');
  while (p != next)
    {
      read_num++;
      temp_start = p;
      if (p == '\0' || p == ((void *)0))
 break;
      p = strchr (p, '\n') + 1;
      temp_end = strstr (p, "\n@");
      if (!temp_end)
 temp_end = strchr (p, '\0');
      int result = fastq_read_check (p, strchr (p, '\n') - p, 'n', bl, tole_rate, File_head);
      if (result == 0)
 {

#pragma omp critical
   {
     memcpy (clean, temp_start, temp_end - temp_start);
     clean += (temp_end - temp_start);
     if (*temp_end != '\0')
       {
  clean[0] = '\n';
  clean++;
       }
   }
 }
      else if (result > 0)
 {

#pragma omp critical
   {
            read_contam++;
     memcpy (contam, temp_start, temp_end - temp_start);
     contam += (temp_end - temp_start);
     if (*temp_end != '\0')
       {
  contam[0] = '\n';
  contam++;
       }
   }
 }
      if (*temp_end == '\0')
 break;
      p = temp_end + 1;
    }
  if (temp_piece)
    free (temp_piece);
}

variable_types: struct bloom { char *vector; unsigned long long (*hash)(char *str); unsigned long long inserts; struct bloomstat { unsigned long long elements; int ideal_hashes; unsigned long long capacity; double e; } stat; int k_mer; int dx; float mcf; } *

variable_types: struct info { char *location; short *score; short *number; struct info *next; } *

variable_types:
tail
struct info *

variable_types: struct file_list { char *filename; short number; long long reads_num; long long reads_contam; long long hits; long long all_k; struct file_list *next; } *

variable_types:
p
char *

variable_types:
next
char *

variable_types: result int

user_defined_types: struct bloom { char *vector; unsigned long long (*hash)(char *str); unsigned long long inserts; struct bloomstat stat; int k_mer; int dx; float mcf; }


decompiled_code:
int __fastcall fasta_process_m(__int64 a1, __int64 a2, char **a3, __int64 a4, float a5)
{
char **v7; // rax
const char *v8; // r14
char *v9; // rbx
unsigned int v10; // ebp
char *v11; // r15
int v12; // eax
unsigned int v14; // [rsp+Ch] [rbp-3Ch]

puts("fasta processing...");
v7 = *(char ***)(a2 + 24);
if ( v7 )
{
v8 = *(const char **)a2;
if ( v7 == a3 )
v9 = (char *)&v8[strlen(*(const char **)a2)];
else
v9 = *v7;
v14 = 0;
v10 = 0;
if ( v8 != v9 )
{
while ( 1 )
{
++v10;
v11 = strchr(v8 + 1, 62);
if ( !v11 )
v11 = v9;
v12 = fasta_read_check(v8, v11, 110LL, a1, a4, COERCE_DOUBLE((unsigned __int64)LODWORD(a5)));
if ( v12 )
{
if ( v12 > 0 )
{
GOMP_critical_start();
++v14;
memcpy(contam, v8, v11 - v8);
contam = (char *)contam + v11 - v8;
GOMP_critical_end();
}
if ( v11 == v9 )
break;
}
else
{
GOMP_critical_start();
memcpy(clean, v8, v11 - v8);
clean = (char *)clean + v11 - v8;
GOMP_critical_end();
if ( v11 == v9 )
break;
}
v8 = v11;
}
}
LODWORD(v7) = printf("all->%d\ncontam->%d\n", v10, v14);
}
return (int)v7;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2, char **a3, __int64 a4, float a5)
{
char **v7; // rax
const char *v8; // r14
char *v9; // rbx
unsigned int v10; // ebp
char *v11; // r15
int v12; // eax
unsigned int v14; // [rsp+Ch] [rbp-3Ch]

puts("fasta processing...");
v7 = *(char ***)(a2 + 24);
if ( v7 )
{
v8 = *(const char **)a2;
if ( v7 == a3 )
v9 = (char *)&v8[strlen(*(const char **)a2)];
else
v9 = *v7;
v14 = 0;
v10 = 0;
if ( v8 != v9 )
{
while ( 1 )
{
++v10;
v11 = strchr(v8 + 1, 62);
if ( !v11 )
v11 = v9;
v12 = fasta_read_check(v8, v11, 110LL, a1, a4, COERCE_DOUBLE((unsigned __int64)LODWORD(a5)));
if ( v12 )
{
if ( v12 > 0 )
{
GOMP_critical_start();
++v14;
memcpy(contam, v8, v11 - v8);
contam = (char *)contam + v11 - v8;
GOMP_critical_end();
}
if ( v11 == v9 )
break;
}
else
{
GOMP_critical_start();
memcpy(clean, v8, v11 - v8);
clean = (char *)clean + v11 - v8;
GOMP_critical_end();
if ( v11 == v9 )
break;
}
v8 = v11;
}
}
LODWORD(v7) = printf("all->%d\ncontam->%d\n", v10, v14);
}
return (int)v7;
}

original_code:
void
fasta_process_m (bloom * bl, Queue * info, Queue * tail, float tole_rate, F_set *File_head)
{
  printf ("fasta processing...\n");
  int read_num = 0, read_contam = 0;
  char *p = info->location;
  char *next;
  char *temp = p;
  if (info->next == ((void *)0))
    return;
  else if (info->next != tail)
    next = info->next->location;
  else
    next = strchr (p, '\0');
  while (p != next)
    {
      read_num++;
      temp = strchr (p + 1, '>');
      if (!temp)
 temp = next;
      int result = fasta_read_check (p, temp, 'n', bl, tole_rate, File_head);
      if (result == 0)
 {

#pragma omp critical
   {
     memcpy (clean, p, temp - p);
     clean += (temp - p);
   }
 }
      else if (result > 0)
 {

#pragma omp critical
   {
            read_contam++;
     memcpy (contam, p, temp - p);
     contam += (temp - p);
   }
 }
      p = temp;
    }
  printf ("all->%d\ncontam->%d\n", read_num, read_contam);
}

canonical_original_code:
void fasta_process_m(struct bloom *bl, struct info *info, struct info *tail, float tole_rate, struct file_list *File_head)
{
  printf ("fasta processing...\n");
  int read_num = 0; int read_contam = 0;
  char *p = info->location;
  char *next;
  char *temp = p;
  if (info->next == ((void *)0))
    return;
  else if (info->next != tail)
    next = info->next->location;
  else
    next = strchr (p, '\0');
  while (p != next)
    {
      read_num++;
      temp = strchr (p + 1, '>');
      if (!temp)
 temp = next;
      int result = fasta_read_check (p, temp, 'n', bl, tole_rate, File_head);
      if (result == 0)
 {

#pragma omp critical
   {
     memcpy (clean, p, temp - p);
     clean += (temp - p);
   }
 }
      else if (result > 0)
 {

#pragma omp critical
   {
            read_contam++;
     memcpy (contam, p, temp - p);
     contam += (temp - p);
   }
 }
      p = temp;
    }
  printf ("all->%d\ncontam->%d\n", read_num, read_contam);
}

variable_types:
temp
char *

user_defined_types: struct info { char *location; short *score; short *number; struct info *next; }

user_defined_types: struct file_list { char *filename; short number; long long reads_num; long long reads_contam; long long hits; long long all_k; struct file_list *next; }


original_code:
void
save_result (char *source, char *obj_file, int type, char *prefix,
      char *clean, char *clean2, char *contam, char *contam2)
{
  printf ("source->%s\n",source);
  printf ("obj_file->%s\n",obj_file);
  printf ("prefix->%s\n",prefix);
  char *so = ((void *)0), *obj = ((void *)0);
  char *match = (char *) malloc (400 * sizeof (char)),
    *mismatch = (char *) malloc (400 * sizeof (char)),
    *so_name = (char *) malloc (200 * sizeof (char)),
    *obj_name = (char *) malloc (200 * sizeof (char));
  memset (match, 0, 400);
  memset (mismatch, 0, 400);
  memset (so_name, 0, 200);
  memset (obj_name, 0, 200);
  so = strrchr (source, '/');
  obj = strrchr (obj_file,'/');
  if (so)
     so += 1;
  else
     so = ((void *)0);
  if (obj)
     obj += 1;
  else
     obj = ((void *)0);
  if (so)
    strncat (so_name, so, strrchr (source, '.') - so);
  else
    strncat (so_name, source, strrchr (source, '.') - source);
  if (obj)
    strncat (obj_name, obj, strrchr (obj_file, '.') - obj);
  else
    strncat (obj_name, obj_file, strrchr (obj_file, '.') - obj_file);
  if (prefix)
    {
      strcat (match, prefix);
      strcat (mismatch, prefix);
    }
  else if (so)
    {
      strncat (match, source, so - source);
      strncat (mismatch, source, so - source);
    }
  strcat (match, so_name);
  strcat (mismatch, so_name);
  strcat (match, "_");
  strcat (mismatch, "_");
  strcat (match, obj_name);
  strcat (mismatch, obj_name);
  strcat (match, "_contam");
  strcat (mismatch, "_clean");
  if (type == 1)
    {
      strcat (match, ".fasta");
      strcat (mismatch, ".fasta");
    }
  else
    {
      strcat (match, ".fastq");
      strcat (mismatch, ".fastq");
    }
  printf ("match->%s\n", match);
  printf ("mis->%s\n", mismatch);
  write_result (match, contam2);
  write_result (mismatch, clean2);
  free (match);
  free (mismatch);
  free (so_name);
  free (obj_name);
  memset (contam2, 0, strlen (contam2));
  memset (clean2, 0, strlen (clean2));
  clean = clean2;
  contam = contam2;
}

canonical_original_code:
void save_result(char *source, char *obj_file, int type, char *prefix, char *clean, char *clean2, char *contam, char *contam2)
{
  printf ("source->%s\n",source);
  printf ("obj_file->%s\n",obj_file);
  printf ("prefix->%s\n",prefix);
  char *so = ((void *)0); char *obj = ((void *)0);
  char *match = (char *) malloc (400 * sizeof (char)); char *mismatch = (char *) malloc (400 * sizeof (char)); char *so_name = (char *) malloc (200 * sizeof (char)); char *obj_name = (char *) malloc (200 * sizeof (char));
  memset (match, 0, 400);
  memset (mismatch, 0, 400);
  memset (so_name, 0, 200);
  memset (obj_name, 0, 200);
  so = strrchr (source, '/');
  obj = strrchr (obj_file,'/');
  if (so)
     so += 1;
  else
     so = ((void *)0);
  if (obj)
     obj += 1;
  else
     obj = ((void *)0);
  if (so)
    strncat (so_name, so, strrchr (source, '.') - so);
  else
    strncat (so_name, source, strrchr (source, '.') - source);
  if (obj)
    strncat (obj_name, obj, strrchr (obj_file, '.') - obj);
  else
    strncat (obj_name, obj_file, strrchr (obj_file, '.') - obj_file);
  if (prefix)
    {
      strcat (match, prefix);
      strcat (mismatch, prefix);
    }
  else if (so)
    {
      strncat (match, source, so - source);
      strncat (mismatch, source, so - source);
    }
  strcat (match, so_name);
  strcat (mismatch, so_name);
  strcat (match, "_");
  strcat (mismatch, "_");
  strcat (match, obj_name);
  strcat (mismatch, obj_name);
  strcat (match, "_contam");
  strcat (mismatch, "_clean");
  if (type == 1)
    {
      strcat (match, ".fasta");
      strcat (mismatch, ".fasta");
    }
  else
    {
      strcat (match, ".fastq");
      strcat (mismatch, ".fastq");
    }
  printf ("match->%s\n", match);
  printf ("mis->%s\n", mismatch);
  write_result (match, contam2);
  write_result (mismatch, clean2);
  free (match);
  free (mismatch);
  free (so_name);
  free (obj_name);
  memset (contam2, 0, strlen (contam2));
  memset (clean2, 0, strlen (clean2));
  clean = clean2;
  contam = contam2;
}

variable_types:
source
char *

variable_types: type int

variable_types:
prefix
char *

variable_types:
clean
char *

variable_types:
contam
char *

variable_types:
so
char *

variable_types:
obj
char *

variable_types:
match
char *

variable_types:
mismatch
char *


decompiled_code:
__int64 __fastcall remove_reads(char *a1, __int64 a2, __int64 a3, const char *a4, double a5)
{
unsigned int *v6; // rbp
void *v7; // rax
_QWORD *v8; // rbx
char *v9; // r12
int v10; // er15
size_t v11; // rax
void *v12; // r13
size_t v13; // rax
void *v14; // rax
void *v15; // r14
size_t v16; // rax
size_t v17; // rax
size_t v18; // rax
float v20; // [rsp+Ch] [rbp-8Ch]
_QWORD *v21; // [rsp+10h] [rbp-88h]
__int64 v22; // [rsp+18h] [rbp-80h]
__int64 v24[4]; // [rsp+30h] [rbp-68h] BYREF
float v25; // [rsp+50h] [rbp-48h]
int v26; // [rsp+54h] [rbp-44h]

v20 = *(float *)&a5;
v6 = (unsigned int *)malloc(0x48uLL);
v21 = malloc(0x20uLL);
v7 = malloc(0x20uLL);
v21[3] = v7;
v22 = (__int64)v7;
v8 = (_QWORD *)make_list(a2, a3);
v9 = (char *)mmaping(a1);
v10 = get_parainfo(v9, v21);
v11 = strlen(v9);
clean = malloc(v11);
v12 = clean;
v13 = strlen(v9);
v14 = malloc(v13);
contam = v14;
if ( v8 )
{
v15 = v14;
do
{
v16 = strlen(v9);
memset(v12, 0, v16);
v17 = strlen(v9);
memset(v15, 0, v17);
load_bloom(*v8, v6);
if ( v20 == 0.0 )
{
*(float *)&a5 = mco_suggestion(v6[14], a5, v20, 0.0);
v20 = *(float *)&a5;
}
v24[3] = (__int64)v8;
v24[2] = v22;
v25 = v20;
v24[1] = (__int64)v21;
v24[0] = (__int64)v6;
v26 = v10;
GOMP_parallel(remove_reads__omp_fn_0, v24, 0LL, 0LL);
save_result(a1, (const char *)*v8, v10, a4, (__int64)clean, (char *)v12, (__int64)contam, (char *)v15);
v8 = (_QWORD *)v8[6];
bloom_destroy(v6);
}
while ( v8 );
}
v18 = strlen(v9);
munmap(v9, v18);
puts("finish processing...");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, __int64 a2, __int64 a3, const char *a4, double a5)
{
unsigned int *v6; // rbp
void *v7; // rax
_QWORD *v8; // rbx
char *v9; // r12
int v10; // er15
size_t v11; // rax
void *v12; // r13
size_t v13; // rax
void *v14; // rax
void *v15; // r14
size_t v16; // rax
size_t v17; // rax
size_t v18; // rax
float v20; // [rsp+Ch] [rbp-8Ch]
_QWORD *v21; // [rsp+10h] [rbp-88h]
__int64 v22; // [rsp+18h] [rbp-80h]
__int64 v24[4]; // [rsp+30h] [rbp-68h] BYREF
float v25; // [rsp+50h] [rbp-48h]
int v26; // [rsp+54h] [rbp-44h]

v20 = *(float *)&a5;
v6 = (unsigned int *)malloc(0x48uLL);
v21 = malloc(0x20uLL);
v7 = malloc(0x20uLL);
v21[3] = v7;
v22 = (__int64)v7;
v8 = (_QWORD *)make_list(a2, a3);
v9 = (char *)mmaping(a1);
v10 = get_parainfo(v9, v21);
v11 = strlen(v9);
clean = malloc(v11);
v12 = clean;
v13 = strlen(v9);
v14 = malloc(v13);
contam = v14;
if ( v8 )
{
v15 = v14;
do
{
v16 = strlen(v9);
memset(v12, 0, v16);
v17 = strlen(v9);
memset(v15, 0, v17);
load_bloom(*v8, v6);
if ( v20 == 0.0 )
{
*(float *)&a5 = mco_suggestion(v6[14], a5, v20, 0.0);
v20 = *(float *)&a5;
}
v24[3] = (__int64)v8;
v24[2] = v22;
v25 = v20;
v24[1] = (__int64)v21;
v24[0] = (__int64)v6;
v26 = v10;
GOMP_parallel(remove_reads__omp_fn_0, v24, 0LL, 0LL);
func4(a1, (const char *)*v8, v10, a4, (__int64)clean, (char *)v12, (__int64)contam, (char *)v15);
v8 = (_QWORD *)v8[6];
bloom_destroy(v6);
}
while ( v8 );
}
v18 = strlen(v9);
munmap(v9, v18);
puts("finish processing...");
return 0LL;
}

original_code:
int remove_reads(char *source, char *ref, char *list, char *prefix, float tole_rate)
{
  int type = 1;
  char *position;
  char *clean2;
  char *contam2;
  bloom *bl_2 = (bloom *) malloc(sizeof(bloom));
  Queue *head = (Queue *) malloc(sizeof(Queue));
  Queue *tail = (Queue *) malloc(sizeof(Queue));
  head->next = tail;
  Queue *head2 = head;
  F_set *File_head = (F_set *) malloc(sizeof(F_set));
  File_head = make_list (ref, list);
  position = mmaping (source);
  type = get_parainfo (position, head);
  clean = (char *) malloc (strlen (position) * sizeof (char));
  contam = (char *) malloc (strlen (position) * sizeof (char));
  clean2 = clean;
  contam2 = contam;
  while (File_head)
    {
      memset (clean2, 0, strlen (position));
      memset (contam2, 0, strlen (position));
      load_bloom (File_head->filename, bl_2);
      if (tole_rate==0)
       tole_rate = mco_suggestion (bl_2->k_mer);

#pragma omp parallel
      {

#pragma omp single nowait
 {
   while (head != tail)
     {

#pragma omp task firstprivate(head)
       {
  if (head->location!=((void *)0)) {
    if (type == 1)
      fasta_process_m (bl_2, head, tail, tole_rate, File_head);
    else
      fastq_process_m (bl_2, head, tail, tole_rate, File_head);
                }
     }
          }
       head = head->next;
 }
      }
      save_result (source, File_head->filename, type, prefix, clean, clean2,
     contam, contam2);
      File_head = File_head->next;
      head = head2;
      bloom_destroy (bl_2);
    }
  munmap (position, strlen (position));
  printf ("finish processing...\n");
  return 0;
}

canonical_original_code:
int remove_reads(char *source, char *ref, char *list, char *prefix, float tole_rate)
{
  int type = 1;
  char *position;
  char *clean2;
  char *contam2;
  struct bloom *bl_2 = (bloom *) malloc(sizeof(bloom));
  struct info *head = (Queue *) malloc(sizeof(Queue));
  struct info *tail = (Queue *) malloc(sizeof(Queue));
  head->next = tail;
  struct info *head2 = head;
  struct file_list *File_head = (F_set *) malloc(sizeof(F_set));
  File_head = make_list (ref, list);
  position = mmaping (source);
  type = get_parainfo (position, head);
  clean = (char *) malloc (strlen (position) * sizeof (char));
  contam = (char *) malloc (strlen (position) * sizeof (char));
  clean2 = clean;
  contam2 = contam;
  while (File_head)
    {
      memset (clean2, 0, strlen (position));
      memset (contam2, 0, strlen (position));
      load_bloom (File_head->filename, bl_2);
      if (tole_rate==0)
       tole_rate = mco_suggestion (bl_2->k_mer);

#pragma omp parallel
      {

#pragma omp single nowait
 {
   while (head != tail)
     {

#pragma omp task firstprivate(head)
       {
  if (head->location!=((void *)0)) {
    if (type == 1)
      fasta_process_m (bl_2, head, tail, tole_rate, File_head);
    else
      fastq_process_m (bl_2, head, tail, tole_rate, File_head);
                }
     }
          }
       head = head->next;
 }
      }
      save_result (source, File_head->filename, type, prefix, clean, clean2,
     contam, contam2);
      File_head = File_head->next;
      head = head2;
      bloom_destroy (bl_2);
    }
  munmap (position, strlen (position));
  printf ("finish processing...\n");
  return 0;
}

variable_types:
ref
char *

variable_types:
list
char *

variable_types:
position
char *

variable_types: struct bloom { char *vector; unsigned long long (*hash)(char *str); unsigned long long inserts; struct bloomstat { unsigned long long elements; int ideal_hashes; unsigned long long capacity; double e; } stat; int k_mer; int dx; float mcf; } *


decompiled_code:
__int64 __fastcall remove_main(int argc, char **argv)
{
char *v2; // r12
char *v3; // r15
char *v4; // r14
char *v5; // r13
int v6; // eax
float v7; // xmm2_4
float v9; // [rsp+Ch] [rbp-3Ch]

if ( argc <= 1 )
remove_help();
v2 = 0LL;
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v9 = 0.0;
while ( 1 )
{
v6 = getopt(argc, argv, "t:r:o:q:l:h");
if ( v6 == -1 )
return remove_reads(v2, (__int64)v5, (__int64)v4, v3, COERCE_DOUBLE((unsigned __int64)LODWORD(v9)));
switch ( v6 )
{
case '?':
goto LABEL_7;
case 'h':
remove_help();
LABEL_7:
printf("Unknown option: -%c\n", (unsigned int)(char)optopt);
remove_help();
break;
case 'l':
if ( optarg )
v4 = optarg;
break;
case 'o':
if ( optarg )
v3 = optarg;
break;
case 'q':
if ( optarg )
v2 = optarg;
break;
case 'r':
if ( optarg )
v5 = optarg;
break;
case 't':
if ( optarg )
{
v7 = atof(optarg);
v9 = v7;
}
break;
default:
continue;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func6(int argc, char **argv)
{
char *v2; // r12
char *v3; // r15
char *v4; // r14
char *v5; // r13
int v6; // eax
float v7; // xmm2_4
float v9; // [rsp+Ch] [rbp-3Ch]

if ( argc <= 1 )
remove_help();
v2 = 0LL;
v3 = 0LL;
v4 = 0LL;
v5 = 0LL;
v9 = 0.0;
while ( 1 )
{
v6 = getopt(argc, argv, "t:r:o:q:l:h");
if ( v6 == -1 )
return func5(v2, (__int64)v5, (__int64)v4, v3, COERCE_DOUBLE((unsigned __int64)LODWORD(v9)));
switch ( v6 )
{
case '?':
goto LABEL_7;
case 'h':
remove_help();
LABEL_7:
printf("Unknown option: -%c\n", (unsigned int)(char)optopt);
remove_help();
break;
case 'l':
if ( optarg )
v4 = optarg;
break;
case 'o':
if ( optarg )
v3 = optarg;
break;
case 'q':
if ( optarg )
v2 = optarg;
break;
case 'r':
if ( optarg )
v5 = optarg;
break;
case 't':
if ( optarg )
{
v7 = atof(optarg);
v9 = v7;
}
break;
default:
continue;
}
}
}

original_code:
int remove_main(int argc, char** argv)
{
  if (argc < 2) remove_help();
  int opt;
  float tole_rate = 0;
  char* ref = ((void *)0);
  char* list = ((void *)0);
  char* target_path = ((void *)0);
  char* source = ((void *)0);
  while ((opt = getopt (argc, argv, "t:r:o:q:l:h")) != -1) {
      switch (opt) {
          case 't':
              (optarg) && ((tole_rate = atof(optarg)), 1);
              break;
          case 'o':
              (optarg) && ((target_path = optarg), 1);
              break;
          case 'q':
              (optarg) && (source = optarg, 1);
              break;
          case 'r':
              (optarg) && (ref = optarg, 1);
              break;
          case 'l':
              (optarg) && (list = optarg, 1);
              break;
          case 'h':
              remove_help();
          case '?':
              printf ("Unknown option: -%c\n", (char) optopt);
              remove_help();
      }
  }
  return remove_reads(source, ref, list, target_path, tole_rate);
}

canonical_original_code:
int remove_main(int argc, char **argv)
{
  if (argc < 2) remove_help();
  int opt;
  float tole_rate = 0;
  char *ref = ((void *)0);
  char *list = ((void *)0);
  char *target_path = ((void *)0);
  char *source = ((void *)0);
  while ((opt = getopt (argc, argv, "t:r:o:q:l:h")) != -1) {
      switch (opt) {
          case 't':
              (optarg) && ((tole_rate = atof(optarg)), 1);
              break;
          case 'o':
              (optarg) && ((target_path = optarg), 1);
              break;
          case 'q':
              (optarg) && (source = optarg, 1);
              break;
          case 'r':
              (optarg) && (ref = optarg, 1);
              break;
          case 'l':
              (optarg) && (list = optarg, 1);
              break;
          case 'h':
              remove_help();
          case '?':
              printf ("Unknown option: -%c\n", (char) optopt);
              remove_help();
      }
  }
  return remove_reads(source, ref, list, target_path, tole_rate);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int


decompiled_code:
__int64 query_usage()
{
fwrite("\nUsage: ./facs query [options]\n", 1uLL, 0x1FuLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite("\t-r reference bloom filter to query against\n", 1uLL, 0x2CuLL, stderr);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
fwrite("\nUsage: ./facs query [options]\n", 1uLL, 0x1FuLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite("\t-r reference bloom filter to query against\n", 1uLL, 0x2CuLL, stderr);
return 1LL;
}

original_code:
static int
query_usage(void)
{
    fprintf(stderr, "\nUsage: ./facs query [options]\n");
    fprintf(stderr, "Options:\n");
    fprintf(stderr, "\t-r reference bloom filter to query against\n");
    return 1;
}

canonical_original_code:
static int query_usage()
{
    fprintf(stderr, "\nUsage: ./facs query [options]\n");
    fprintf(stderr, "Options:\n");
    fprintf(stderr, "\t-r reference bloom filter to query against\n");
    return 1;
}


strrstr

decompiled_code:
const char *__fastcall strrstr(const char *a1, const char *a2)
{
const char *v2; // r12
char v3; // bp
size_t v4; // rax

v2 = &a1[(int)strlen(a1) - 1];
if ( a1 > v2 )
return 0LL;
v3 = *a2;
while ( 1 )
{
if ( *v2 == v3 )
{
v4 = strlen(a2);
if ( !memcmp(v2, a2, v4) )
break;
}
if ( a1 > --v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func3(const char *a1, const char *a2)
{
const char *v2; // r12
char v3; // bp
size_t v4; // rax

v2 = &a1[(int)strlen(a1) - 1];
if ( a1 > v2 )
return 0LL;
v3 = *a2;
while ( 1 )
{
if ( *v2 == v3 )
{
v4 = strlen(a2);
if ( !memcmp(v2, a2, v4) )
break;
}
if ( a1 > --v2 )
return 0LL;
}
return v2;
}

original_code:
char *strrstr(char *s, char *str)
{
    char *p;
    int len = strlen(s);
    for (p = s + len - 1; p >= s; p--) {
        if ((*p == *str) && (memcmp(p, str, strlen(str)) == 0))
            return p;
    }
    return ((void *)0);
}

variable_types:
s
char *

variable_types:
str
char *

variable_types:
p
char *

variable_types: len int

return_type: char *


decompiled_code:
void __fastcall clean_list(void *ptr, void *a2)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( ptr != a2 )
{
v2 = ptr;
do
{
v3 = v2;
v2 = (_QWORD *)v2[3];
free(v3);
}
while ( a2 != v2 );
}
free(a2);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr, void *a2)
{
_QWORD *v2; // rbx
void *v3; // rdi

if ( ptr != a2 )
{
v2 = ptr;
do
{
v3 = v2;
v2 = (_QWORD *)v2[3];
free(v3);
}
while ( a2 != v2 );
}
free(a2);
}

original_code:
void clean_list (Queue* head, Queue *tail)
{
Queue *element;
while (head!=tail)
   {
       element = head->next;
       memset(head,0,sizeof(Queue));
       free(head);
       head = element;
   }
free(tail);
}

canonical_original_code:
void clean_list(struct info *head, struct info *tail)
{
struct info *element;
while (head!=tail)
   {
       element = head->next;
       memset(head,0,sizeof(Queue));
       free(head);
       head = element;
   }
free(tail);
}

variable_types: struct info { char *location; short *score; short *number; struct info *next; } *

variable_types:
tail
struct info *


CHUNKgz

original_code:
long long CHUNKgz(gzFile zip, long long offset,int chunk,char *position,char *extra,int type)
{
         memset(position,0,chunk);
       char c, *position2 = position;
       char *x;
       int num=0;
         if (offset == 0)
          while (offset <10*100)
          {
             c = ((zip)->have ? ((zip)->have--, (zip)->pos++, *((zip)->next)++) : (gzgetc)(zip));
            if ((c == '@' && type==2)&&(c == '>' && type==1))
                  break;
             offset++;
          }
          if (extra!=((void *)0))
             {
             memcpy(position,extra,strlen(extra));
             position+=strlen(extra);
             }
          free(extra);
          while (((c=((zip)->have ? ((zip)->have--, (zip)->pos++, *((zip)->next)++) : (gzgetc)(zip)))!=(-1))&&(num<chunk))
          {
             *position=c;
             position++;
             num++;
          }
         x = strrstr(position2,"\n@");
         extra = (char*)malloc((position-x+1)*sizeof(char));
         memcpy (x,extra,position-x+1);
         offset+=(position-x+1);
        return offset;
}

canonical_original_code:
long long CHUNKgz(struct gzFile_s *zip, long long offset, int chunk, char *position, char *extra, int type)
{
         memset(position,0,chunk);
       char c; char *position2 = position;
       char *x;
       int num = 0;
         if (offset == 0)
          while (offset <10*100)
          {
             c = ((zip)->have ? ((zip)->have--, (zip)->pos++, *((zip)->next)++) : (gzgetc)(zip));
            if ((c == '@' && type==2)&&(c == '>' && type==1))
                  break;
             offset++;
          }
          if (extra!=((void *)0))
             {
             memcpy(position,extra,strlen(extra));
             position+=strlen(extra);
             }
          free(extra);
          while (((c=((zip)->have ? ((zip)->have--, (zip)->pos++, *((zip)->next)++) : (gzgetc)(zip)))!=(-1))&&(num<chunk))
          {
             *position=c;
             position++;
             num++;
          }
         x = strrstr(position2,"\n@");
         extra = (char *)malloc((position-x+1)*sizeof(char));
         memcpy (x,extra,position-x+1);
         offset+=(position-x+1);
        return offset;
}

variable_types: struct gzFile_s { unsigned int have; unsigned char *next; long pos; } *

variable_types:
offset
long long

variable_types: chunk int

variable_types:
extra
char *

variable_types: type int

variable_types: c char

variable_types:
x
char *

variable_types: num int


CHUNKer

original_code:
long long CHUNKer(gzFile zip,long long offset,int chunk,char *data,int type)
{
    char c, v;
    char *pos = ((void *)0);
    int length = 0;
    if (type == 2)
        v = '@';
    else
        v = '>';
    if (offset == 0)
        while (offset <10*100)
        {
            c = ((zip)->have ? ((zip)->have--, (zip)->pos++, *((zip)->next)++) : (gzgetc)(zip));
            if (c == v)
                break;
            offset++;
        }
    gzseek64 (zip,offset,0);
    gzread (zip,data,chunk);
    if (data != ((void *)0))
        length = strlen(data);
    if (length>=chunk) {
        if (type == 2) {
            pos = strrstr (data,"\n+");
            pos = bac_2_n (pos-1);
        } else {
            pos = strrchr (data,'>')-1;
        }
    }
    if (pos) {
        offset += (pos-data);
        memset (pos, 0, strlen(pos));
    }
    if (length<chunk)
        offset=-1;
    return offset;
}

canonical_original_code:
long long CHUNKer(struct gzFile_s *zip, long long offset, int chunk, char *data, int type)
{
    char c; char v;
    char *pos = ((void *)0);
    int length = 0;
    if (type == 2)
        v = '@';
    else
        v = '>';
    if (offset == 0)
        while (offset <10*100)
        {
            c = ((zip)->have ? ((zip)->have--, (zip)->pos++, *((zip)->next)++) : (gzgetc)(zip));
            if (c == v)
                break;
            offset++;
        }
    gzseek64 (zip,offset,0);
    gzread (zip,data,chunk);
    if (data != ((void *)0))
        length = strlen(data);
    if (length>=chunk) {
        if (type == 2) {
            pos = strrstr (data,"\n+");
            pos = bac_2_n (pos-1);
        } else {
            pos = strrchr (data,'>')-1;
        }
    }
    if (pos) {
        offset += (pos-data);
        memset (pos, 0, strlen(pos));
    }
    if (length<chunk)
        offset=-1;
    return offset;
}

variable_types:
data
char *

variable_types: v char

variable_types:
pos
char *

variable_types: length int

user_defined_types: struct gzFile_s { unsigned int have; unsigned char *next; long pos; }