decompiled_code:
__int64 __fastcall get_fidvid(unsigned int a1, _DWORD *a2, int *a3)
{
unsigned int v3; // ebx
int v6; // eax
int v7; // ebp
char v8; // rax^4
char v9[24]; // [rsp+0h] [rbp-48h] BYREF
__int64 buf; // [rsp+18h] [rbp-30h] BYREF

buf = 0LL;
v3 = 1;
if ( a1 <= 0x20 )
{
sprintf(v9, "/dev/cpu/%d/msr", a1);
v6 = open(v9, 0);
v7 = v6;
if ( v6 >= 0 )
{
lseek(v6, 3221291074LL, 1);
if ( read(v7, &buf, 8uLL) == 8 )
{
v8 = BYTE4(buf);
*a2 = buf & 0x3F;
*a3 = v8 & 0x1F;
v3 = 0;
}
close(v7);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, _DWORD *a2, int *a3)
{
unsigned int v3; // ebx
int v6; // eax
int v7; // ebp
char v8; // rax^4
char v9[24]; // [rsp+0h] [rbp-48h] BYREF
__int64 buf; // [rsp+18h] [rbp-30h] BYREF

buf = 0LL;
v3 = 1;
if ( a1 <= 0x20 )
{
sprintf(v9, "/dev/cpu/%d/msr", a1);
v6 = open(v9, 0);
v7 = v6;
if ( v6 >= 0 )
{
lseek(v6, 3221291074LL, 1);
if ( read(v7, &buf, 8uLL) == 8 )
{
v8 = BYTE4(buf);
*a2 = buf & 0x3F;
*a3 = v8 & 0x1F;
v3 = 0;
}
close(v7);
}
}
return v3;
}

original_code:
static int get_fidvid(uint32_t cpu, uint32_t *fid, uint32_t *vid)
{
 int err = 1;
 uint64_t msr = 0;
 int fd;
 char file[20];
 if (cpu > 32)
  goto out;
 sprintf(file, "/dev/cpu/%d/msr", cpu);
 fd = open(file, 00);
 if (fd < 0)
  goto out;
 lseek(fd, 0xc0010042, 1);
 if (read(fd, &msr, 8) != 8)
  goto err1;
 *fid = ((uint32_t )(msr & 0xffffffffull)) & 0x0000003f;
 *vid = ((uint32_t )(msr>>32 & 0xffffffffull)) & 0x0000001f;
 err = 0;
err1:
 close(fd);
out:
 return err;
}

canonical_original_code:
static int get_fidvid(unsigned int cpu, unsigned int *fid, unsigned int *vid)
{
 int err = 1;
 unsigned long msr = 0;
 int fd;
 char file[20];
 if (cpu > 32)
  goto out;
 sprintf(file, "/dev/cpu/%d/msr", cpu);
 fd = open(file, 00);
 if (fd < 0)
  goto out;
 lseek(fd, 0xc0010042, 1);
 if (read(fd, &msr, 8) != 8)
  goto err1;
 *fid = ((unsigned int )(msr & 0xffffffffull)) & 0x0000003f;
 *vid = ((unsigned int )(msr>>32 & 0xffffffffull)) & 0x0000001f;
 err = 0;
err1:
 close(fd);
out:
 return err;
}

variable_types:
fid
unsigned int *

variable_types:
vid
unsigned int *

variable_types: err int

variable_types:
msr
unsigned long

variable_types: fd int

variable_types:
file
char [20]


main

canonical_name: main

repo: emagii/cpufrequtils

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // ebp
unsigned int v5; // eax
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 0;
if ( argc > 1 )
v3 = strtoul(argv[1], 0LL, 0);
if ( (unsigned int)get_fidvid(v3, v8, &v7) )
{
puts("can't get fid, vid from MSR");
puts("Possible trouble: you don't run a powernow-k8 capable cpu");
puts("or you are not root, or the msr driver is not present");
exit(1);
}
v4 = find_millivolts_from_vid(v7);
v5 = find_freq_from_fid(v8[0]);
printf("cpu %d currently at %d MHz and %d mV\n", v3, v5, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // ebp
unsigned int v5; // eax
int v7; // [rsp+8h] [rbp-20h] BYREF
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = 0;
if ( argc > 1 )
v3 = strtoul(argv[1], 0LL, 0);
if ( (unsigned int)func9(v3, v8, &v7) )
{
puts("can't get fid, vid from MSR");
puts("Possible trouble: you don't run a powernow-k8 capable cpu");
puts("or you are not root, or the msr driver is not present");
exit(1);
}
v4 = func8(v7);
v5 = func7(v8[0]);
printf("cpu %d currently at %d MHz and %d mV\n", v3, v5, v4);
return 0;
}

original_code:
int main (int argc, char *argv[])
{
 int err;
 int cpu;
 uint32_t fid, vid;
 if (argc < 2)
  cpu = 0;
 else
  cpu = strtoul(argv[1], ((void *)0), 0);
 err = get_fidvid(cpu, &fid, &vid);
 if (err) {
  printf("can't get fid, vid from MSR\n");
  printf("Possible trouble: you don't run a powernow-k8 capable cpu\n");
  printf("or you are not root, or the msr driver is not present\n");
  exit(1);
 }
 printf("cpu %d currently at %d MHz and %d mV\n",
   cpu,
   find_freq_from_fid(fid),
   find_millivolts_from_vid(vid));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int err;
 int cpu;
 unsigned int fid; unsigned int vid;
 if (argc < 2)
  cpu = 0;
 else
  cpu = strtoul(argv[1], ((void *)0), 0);
 err = get_fidvid(cpu, &fid, &vid);
 if (err) {
  printf("can't get fid, vid from MSR\n");
  printf("Possible trouble: you don't run a powernow-k8 capable cpu\n");
  printf("or you are not root, or the msr driver is not present\n");
  exit(1);
 }
 printf("cpu %d currently at %d MHz and %d mV\n",
   cpu,
   find_freq_from_fid(fid),
   find_millivolts_from_vid(vid));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: cpu int

variable_types:
fid
unsigned int

variable_types:
vid
unsigned int

return_type: int


decompiled_code:
void __fastcall decode_psb(__int64 a1, int a2)
{
int v2; // er12
unsigned int *v3; // rbx
unsigned int i; // ebp

if ( *(_BYTE *)(a1 + 10) == 18 )
{
v2 = a2;
printf(
"PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
18LL,
*(unsigned __int8 *)(a1 + 11),
*(unsigned __int16 *)(a1 + 12),
*(unsigned __int8 *)(a1 + 14),
*(unsigned __int8 *)(a1 + 15));
v3 = (unsigned int *)(a1 + 16);
if ( a2 >= 0 )
printf("Overriding number of pst :%d\n", (unsigned int)a2);
else
v2 = *(unsigned __int8 *)(a1 + 15);
if ( v2 > 0 )
{
for ( i = 1; ; ++i )
{
if ( !relevant || relevant == *v3 )
{
printf(
" PST %d cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
i,
*v3,
*((unsigned __int8 *)v3 + 4),
*((unsigned __int8 *)v3 + 5),
*((unsigned __int8 *)v3 + 6),
*((unsigned __int8 *)v3 + 7));
fsb = *((unsigned __int8 *)v3 + 4);
decode_pst((__int64)(v3 + 2), *((unsigned __int8 *)v3 + 7));
}
v3 = (unsigned int *)((char *)v3 + 2 * *((unsigned __int8 *)v3 + 7) + 8);
if ( i == v2 )
break;
}
}
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
int v2; // er12
unsigned int *v3; // rbx
unsigned int i; // ebp

if ( *(_BYTE *)(a1 + 10) == 18 )
{
v2 = a2;
printf(
"PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
18LL,
*(unsigned __int8 *)(a1 + 11),
*(unsigned __int16 *)(a1 + 12),
*(unsigned __int8 *)(a1 + 14),
*(unsigned __int8 *)(a1 + 15));
v3 = (unsigned int *)(a1 + 16);
if ( a2 >= 0 )
printf("Overriding number of pst :%d\n", (unsigned int)a2);
else
v2 = *(unsigned __int8 *)(a1 + 15);
if ( v2 > 0 )
{
for ( i = 1; ; ++i )
{
if ( !relevant || relevant == *v3 )
{
printf(
" PST %d cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
i,
*v3,
*((unsigned __int8 *)v3 + 4),
*((unsigned __int8 *)v3 + 5),
*((unsigned __int8 *)v3 + 6),
*((unsigned __int8 *)v3 + 7));
fsb = *((unsigned __int8 *)v3 + 4);
func7((__int64)(v3 + 2), *((unsigned __int8 *)v3 + 7));
}
v3 = (unsigned int *)((char *)v3 + 2 * *((unsigned __int8 *)v3 + 7) + 8);
if ( i == v2 )
break;
}
}
}
}

original_code:
static
void decode_psb(char *p, int numpst)
{
 int i;
 struct psb_header *psb;
 struct pst_header *pst;
 psb = (struct psb_header*) p;
 if (psb->version != 0x12)
  return;
 printf("PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
   psb->version,
   psb->flags,
   psb->settlingtime,
   psb->res1,
   psb->numpst);
 sgtc = psb->settlingtime * 100;
 if (sgtc < 10000)
  sgtc = 10000;
 p = ((char *) psb) + sizeof(struct psb_header);
 if (numpst < 0)
  numpst = psb->numpst;
 else
  printf("Overriding number of pst :%d\n", numpst);
 for (i = 0; i < numpst; i++) {
  pst = (struct pst_header*) p;
  if (relevant != 0) {
   if (relevant!= pst->cpuid)
    goto next_one;
  }
  printf("  PST %d  cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
    i+1,
    pst->cpuid,
    pst->fsb,
    pst->maxfid,
    pst->startvid,
    pst->numpstates);
  fsb = pst->fsb;
  decode_pst(p + sizeof(struct pst_header), pst->numpstates);
next_one:
  p += sizeof(struct pst_header) + 2*pst->numpstates;
 }
}

canonical_original_code:
static void decode_psb(char *p, int numpst)
{
 int i;
 struct psb_header *psb;
 struct pst_header *pst;
 psb = (struct psb_header *) p;
 if (psb->version != 0x12)
  return;
 printf("PSB version: %hhx flags: %hhx settling time %hhuus res1 %hhx num pst %hhu\n",
   psb->version,
   psb->flags,
   psb->settlingtime,
   psb->res1,
   psb->numpst);
 sgtc = psb->settlingtime * 100;
 if (sgtc < 10000)
  sgtc = 10000;
 p = ((char *) psb) + sizeof(struct psb_header);
 if (numpst < 0)
  numpst = psb->numpst;
 else
  printf("Overriding number of pst :%d\n", numpst);
 for (i = 0; i < numpst; i++) {
  pst = (struct pst_header *) p;
  if (relevant != 0) {
   if (relevant!= pst->cpuid)
    goto next_one;
  }
  printf("  PST %d  cpuid %.3x fsb %hhu mfid %hhx svid %hhx numberstates %hhu\n",
    i+1,
    pst->cpuid,
    pst->fsb,
    pst->maxfid,
    pst->startvid,
    pst->numpstates);
  fsb = pst->fsb;
  decode_pst(p + sizeof(struct pst_header), pst->numpstates);
next_one:
  p += sizeof(struct pst_header) + 2*pst->numpstates;
 }
}

variable_types:
p
char *

variable_types: numpst int

variable_types: i int

variable_types: struct psb_header { char signature[10]; unsigned char version; unsigned char flags; unsigned short settlingtime; unsigned char res1; unsigned char numpst; } *

variable_types: struct pst_header { unsigned int cpuid; unsigned char fsb; unsigned char maxfid; unsigned char startvid; unsigned char numpstates; } *

return_type: void


decompiled_code:
int print_help()
{
puts("Usage: dump_psb [options]");
puts("Options:");
puts(" -n, --numpst Set number of PST tables to scan");
return puts(" -r, --relevant Only display PSTs relevant to cpuid N");
}

canonical_decompiled_code:
int func9()
{
puts("Usage: dump_psb [options]");
puts("Options:");
puts(" -n, --numpst Set number of PST tables to scan");
return puts(" -r, --relevant Only display PSTs relevant to cpuid N");
}

original_code:
void print_help(void)
{
 printf ("Usage: dump_psb [options]\n");
 printf ("Options:\n");
 printf ("  -n, --numpst     Set number of PST tables to scan\n");
 printf ("  -r, --relevant   Only display PSTs relevant to cpuid N\n");
}

canonical_original_code:
void print_help()
{
 printf ("Usage: dump_psb [options]\n");
 printf ("Options:\n");
 printf ("  -n, --numpst     Set number of PST tables to scan\n");
 printf ("  -r, --relevant   Only display PSTs relevant to cpuid N\n");
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
int v5; // eax
int v6; // ebx
char *v7; // r12
char *v8; // rbx

v3 = -1;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "hr:n:", &info_opts, 0LL);
if ( v4 != 110 )
break;
v3 = strtol(_bss_start, 0LL, 10);
}
if ( v4 <= 110 )
break;
if ( v4 == 114 )
relevant = strtol(_bss_start, 0LL, 16);
}
if ( v4 == 63 || v4 == 104 )
break;
if ( v4 == -1 )
goto LABEL_7;
}
print_help();
LABEL_7:
v5 = open("/dev/mem", 0);
v6 = v5;
if ( v5 < 0 )
{
puts("Couldn't open /dev/mem. Are you root?");
exit(1);
}
v7 = (char *)mmap(0LL, 0x40000uLL, 1, 1, v5, 786432LL);
close(v6);
v8 = v7;
while ( memcmp(v8, "AMDK7PNOW!", 0xAuLL) )
{
v8 += 16;
if ( v8 - v7 > 0x3FFFF )
goto LABEL_18;
}
decode_psb((__int64)v8, v3);
LABEL_18:
munmap(v7, 0x40000uLL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
int v5; // eax
int v6; // ebx
char *v7; // r12
char *v8; // rbx

v3 = -1;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v4 = getopt_long(argc, (char *const *)argv, "hr:n:", &info_opts, 0LL);
if ( v4 != 110 )
break;
v3 = strtol(_bss_start, 0LL, 10);
}
if ( v4 <= 110 )
break;
if ( v4 == 114 )
relevant = strtol(_bss_start, 0LL, 16);
}
if ( v4 == 63 || v4 == 104 )
break;
if ( v4 == -1 )
goto LABEL_7;
}
func9();
LABEL_7:
v5 = open("/dev/mem", 0);
v6 = v5;
if ( v5 < 0 )
{
puts("Couldn't open /dev/mem. Are you root?");
exit(1);
}
v7 = (char *)mmap(0LL, 0x40000uLL, 1, 1, v5, 786432LL);
close(v6);
v8 = v7;
while ( memcmp(v8, "AMDK7PNOW!", 0xAuLL) )
{
v8 += 16;
if ( v8 - v7 > 0x3FFFF )
goto LABEL_18;
}
func8((__int64)v8, v3);
LABEL_18:
munmap(v7, 0x40000uLL);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{
 int fd;
 int numpst=-1;
 int ret=0, cont=1;
 char *mem = ((void *)0);
 char *p;
 do {
  ret = getopt_long(argc, argv, "hr:n:", info_opts, ((void *)0));
  switch (ret){
  case '?':
  case 'h':
   print_help();
   cont = 0;
   break;
  case 'r':
   relevant = strtol(optarg, ((void *)0), 16);
   break;
  case 'n':
   numpst = strtol(optarg, ((void *)0), 10);
   break;
  case -1:
   cont = 0;
   break;
  }
 } while(cont);
 fd = open("/dev/mem", 00);
 if (fd < 0) {
  printf ("Couldn't open /dev/mem. Are you root?\n");
  exit(1);
 }
 mem = mmap(mem, 0x100000 - 0xc0000, 0x1, 0x01, fd, 0xc0000);
 close(fd);
 for (p = mem; p - mem < (0x100000 - 0xc0000); p+=16) {
  if (memcmp(p, "AMDK7PNOW!", 10) == 0) {
   decode_psb(p, numpst);
   break;
  }
 }
 munmap(mem, (0x100000 - 0xc0000));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd;
 int numpst = -1;
 int ret = 0; int cont = 1;
 char *mem = ((void *)0);
 char *p;
 do {
  ret = getopt_long(argc, argv, "hr:n:", info_opts, ((void *)0));
  switch (ret){
  case '?':
  case 'h':
   print_help();
   cont = 0;
   break;
  case 'r':
   relevant = strtol(optarg, ((void *)0), 16);
   break;
  case 'n':
   numpst = strtol(optarg, ((void *)0), 10);
   break;
  case -1:
   cont = 0;
   break;
  }
 } while(cont);
 fd = open("/dev/mem", 00);
 if (fd < 0) {
  printf ("Couldn't open /dev/mem. Are you root?\n");
  exit(1);
 }
 mem = mmap(mem, 0x100000 - 0xc0000, 0x1, 0x01, fd, 0xc0000);
 close(fd);
 for (p = mem; p - mem < (0x100000 - 0xc0000); p+=16) {
  if (memcmp(p, "AMDK7PNOW!", 10) == 0) {
   decode_psb(p, numpst);
   break;
  }
 }
 munmap(mem, (0x100000 - 0xc0000));
 return 0;
}

variable_types: ret int

variable_types: cont int

variable_types:
mem
char *


usage

decompiled_code:
int usage()
{
return puts(
"cpufreq-aperf [OPTIONS]\n"
"\n"
"-c [ --cpu ] CPU The CPU core to measure - default all cores\n"
"-i [ --intervall ] seconds Refresh rate - default 1 second\n"
"-o [ --once ] Exit after one intervall\n"
"-h [ --help ] This help text\n"
"The msr driver must be loaded for this command to work");
}

canonical_decompiled_code:
int func7()
{
return puts(
"cpufreq-aperf [OPTIONS]\n"
"\n"
"-c [ --cpu ] CPU The CPU core to measure - default all cores\n"
"-i [ --intervall ] seconds Refresh rate - default 1 second\n"
"-o [ --once ] Exit after one intervall\n"
"-h [ --help ] This help text\n"
"The msr driver must be loaded for this command to work");
}

original_code:
void usage()
{
 printf("usage: ./bench\n");
 printf("Options:\n");
 printf(" -l, --load=<long int>\t\tinitial load time in us\n");
 printf(" -s, --sleep=<long int>\t\tinitial sleep time in us\n");
 printf(" -x, --load-step=<long int>\ttime to be added to load time, in us\n");
 printf(" -y, --sleep-step=<long int>\ttime to be added to sleep time, in us\n");
 printf(" -c, --cpu=<cpu #>\t\t\tCPU Nr. to use, starting at 0\n");
 printf(" -p, --prio=<priority>\t\t\tscheduler priority, HIGH, LOW or DEFAULT\n");
 printf(" -g, --governor=<governor>\t\tcpufreq governor to test\n");
 printf(" -n, --cycles=<int>\t\t\tload/sleep cycles\n");
 printf(" -r, --rounds<int>\t\t\tload/sleep rounds\n");
 printf(" -f, --file=<configfile>\t\tconfig file to use\n");
 printf(" -o, --output=<dir>\t\t\toutput path. Filename will be OUTPUTPATH/benchmark_TIMESTAMP.log\n");
 printf(" -v, --verbose\t\t\t\tverbose output on/off\n");
 printf(" -h, --help\t\t\t\tPrint this help screen\n");
 exit (1);
}


decompiled_code:
int print_help()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax

v0 = dcgettext(0LL, "Usage: cpufreq-set [options]\n", 5);
printf(v0);
v1 = dcgettext(0LL, "Options:\n", 5);
printf(v1);
v2 = dcgettext(0LL, " -c CPU, --cpu CPU number of CPU where cpufreq settings shall be modified\n", 5);
printf(v2);
v3 = dcgettext(0LL, " -d FREQ, --min FREQ new minimum CPU frequency the governor may select\n", 5);
printf(v3);
v4 = dcgettext(0LL, " -u FREQ, --max FREQ new maximum CPU frequency the governor may select\n", 5);
printf(v4);
v5 = dcgettext(0LL, " -g GOV, --governor GOV new cpufreq governor\n", 5);
printf(v5);
v6 = dcgettext(
0LL,
" -f FREQ, --freq FREQ specific frequency to be set. Requires userspace\n"
" governor to be available and loaded\n",
5);
printf(v6);
v7 = dcgettext(0LL, " -r, --related Switches all hardware-related CPUs\n", 5);
printf(v7);
v8 = dcgettext(0LL, " -h, --help Prints out this screen\n", 5);
printf(v8);
putchar(10);
v9 = dcgettext(
0LL,
"Notes:\n"
"1. Omitting the -c or --cpu argument is equivalent to setting it to zero\n"
"2. The -f FREQ, --freq FREQ parameter cannot be combined with any other parameter\n"
" except the -c CPU, --cpu CPU parameter\n"
"3. FREQuencies can be passed in Hz, kHz (default), MHz, GHz, or THz\n"
" by postfixing the value with the wanted unit name, without any space\n"
" (FREQuency in kHz =^ Hz * 0.001 =^ MHz * 1000 =^ GHz * 1000000).\n",
5);
return printf(v9);
}

canonical_decompiled_code:
int func2()
{
char *v0; // rax
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax

v0 = dcgettext(0LL, "Usage: cpufreq-set [options]\n", 5);
printf(v0);
v1 = dcgettext(0LL, "Options:\n", 5);
printf(v1);
v2 = dcgettext(0LL, " -c CPU, --cpu CPU number of CPU where cpufreq settings shall be modified\n", 5);
printf(v2);
v3 = dcgettext(0LL, " -d FREQ, --min FREQ new minimum CPU frequency the governor may select\n", 5);
printf(v3);
v4 = dcgettext(0LL, " -u FREQ, --max FREQ new maximum CPU frequency the governor may select\n", 5);
printf(v4);
v5 = dcgettext(0LL, " -g GOV, --governor GOV new cpufreq governor\n", 5);
printf(v5);
v6 = dcgettext(
0LL,
" -f FREQ, --freq FREQ specific frequency to be set. Requires userspace\n"
" governor to be available and loaded\n",
5);
printf(v6);
v7 = dcgettext(0LL, " -r, --related Switches all hardware-related CPUs\n", 5);
printf(v7);
v8 = dcgettext(0LL, " -h, --help Prints out this screen\n", 5);
printf(v8);
putchar(10);
v9 = dcgettext(
0LL,
"Notes:\n"
"1. Omitting the -c or --cpu argument is equivalent to setting it to zero\n"
"2. The -f FREQ, --freq FREQ parameter cannot be combined with any other parameter\n"
" except the -c CPU, --cpu CPU parameter\n"
"3. FREQuencies can be passed in Hz, kHz (default), MHz, GHz, or THz\n"
" by postfixing the value with the wanted unit name, without any space\n"
" (FREQuency in kHz =^ Hz * 0.001 =^ MHz * 1000 =^ GHz * 1000000).\n",
5);
return printf(v9);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rax
int v5; // [rsp+10h] [rbp-98h] BYREF
__int64 v6; // [rsp+18h] [rbp-90h]
int *v7; // [rsp+20h] [rbp-88h]
__int64 v8; // [rsp+30h] [rbp-78h]
__int64 v9; // [rsp+38h] [rbp-70h]
__int64 v10; // [rsp+40h] [rbp-68h]

v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v5 = 0;
v6 = 0LL;
v7 = &v5;
setlocale(6, &locale);
textdomain("cpufrequtils");
while ( getopt_long(argc, (char *const *)argv, "c:d:u:g:f:hr", &set_opts, 0LL) != -1 )
;
v4 = dcgettext(
0LL,
"At least one parameter out of -f/--freq, -d/--min, -u/--max, and\n-g/--governor must be passed\n",
5);
printf(v4);
return -22;
}


repo: emancu/pso

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v5; // [rsp+Ch] [rbp-7Ch] BYREF
char v6[120]; // [rsp+10h] [rbp-78h] BYREF

v5 = 0;
dec_into_string(v6, &v5, 4294967241LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
hex_into_string(v6, &v5, 10LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
hex_into_string(v6, &v5, 160LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
hex_into_string(v6, &v5, 2575LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
hex_into_string(v6, &v5, 0x1000000LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
hex_into_string(v6, &v5, 167772160LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
hex_into_string(v6, &v5, 1342177280LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
hex_into_string(v6, &v5, 2684354560LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
dec_into_string(v6, &v5, 4026531840LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
dec_into_string(v6, &v5, 1879048192LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v5 = 0;
hex_into_string(v6, &v5, 4026531840LL);
v6[v5] = 0;
printf("Test %s\n", v6);
v3 = 0x10000000;
while ( 1 )
{
v5 = 0;
if ( (int)hex_into_string(v6, &v5, v3) < 0 || (int)dec_into_string(v6, &v5, v3) < 0 )
break;
if ( !++v3 )
{
puts("There was no error whatsoever");
return 0;
}
}
printf("Not enough space: %s\n", v6);
return 0;
}

variable_types: x char

variable_types: i char


usage

repo: emaniacs/primeNumber

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
fprintf(
_bss_start,
"%s\n"
"Usage:\n"
" %s <options> number\n"
"Options:\n"
" -h show this help.\n"
" -q quiet mode.\n"
" -g <number> generate prime number\n"
" -n <number> find prime number\n"
" -s <char> use 'char' as separator. (default is newline).\n"
"Return:\n"
" 0 if number is prime.\n"
" 1 if number is not a prime.\n"
" -1 error\n",
a1,
a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
fprintf(
_bss_start,
"%s\n"
"Usage:\n"
" %s <options> number\n"
"Options:\n"
" -h show this help.\n"
" -q quiet mode.\n"
" -g <number> generate prime number\n"
" -n <number> find prime number\n"
" -s <char> use 'char' as separator. (default is newline).\n"
"Return:\n"
" 0 if number is prime.\n"
" 1 if number is not a prime.\n"
" -1 error\n",
a1,
a1);
return 0xFFFFFFFFLL;
}

original_code:
int usage(char *self) {
    fprintf(stdout, "%s\nUsage:\n    %s <options> number\nOptions:\n    -h           show this help.\n    -q           quiet mode.\n    -g <number>  generate prime number\n    -n <number>  find prime number\n    -s <char>    use 'char' as separator. (default is newline).\nReturn:\n    0       if number is prime.\n    1       if number is not a prime.\n    -1      error\n",
self, self);
    return -1;
}

variable_types:
self
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // ebx
__int64 v6; // rdx
int v7; // edi
int v8; // eax
char *endptr[8]; // [rsp+18h] [rbp-40h] BYREF

v3 = 0;
v4 = getopt(argc, (char *const *)argv, "qhngs:");
if ( v4 == -1 )
{
if ( optind >= argc
|| ((endptr[0] = 0LL, v7 = strtol(argv[optind], endptr, 10), *endptr[0]) ? (v8 = 0, v6 = 0LL) : (v8 = v7, LOBYTE(v6) = v7 > 0),
v8 <= 1) )
{
fwrite("Please enter valid integer, above than 1\n", 1uLL, 0x29uLL, _bss_start);
v3 = v4;
}
else if ( (unsigned int)its_prime((unsigned int)v8, endptr, v6) )
{
fwrite("true\n", 1uLL, 5uLL, _bss_start);
}
else
{
fwrite("false\n", 1uLL, 6uLL, _bss_start);
v3 = 1;
}
}
else
{
if ( v4 != 63 )
abort();
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // ebx
__int64 v6; // rdx
int v7; // edi
int v8; // eax
char *endptr[8]; // [rsp+18h] [rbp-40h] BYREF

v3 = 0;
v4 = getopt(argc, (char *const *)argv, "qhngs:");
if ( v4 == -1 )
{
if ( optind >= argc
|| ((endptr[0] = 0LL, v7 = strtol(argv[optind], endptr, 10), *endptr[0]) ? (v8 = 0, v6 = 0LL) : (v8 = v7, LOBYTE(v6) = v7 > 0),
v8 <= 1) )
{
fwrite("Please enter valid integer, above than 1\n", 1uLL, 0x29uLL, _bss_start);
v3 = v4;
}
else if ( (unsigned int)func8((unsigned int)v8, endptr, v6) )
{
fwrite("true\n", 1uLL, 5uLL, _bss_start);
}
else
{
fwrite("false\n", 1uLL, 6uLL, _bss_start);
v3 = 1;
}
}
else
{
if ( v4 != 63 )
abort();
v3 = -1;
}
return v3;
}

original_code:
int main(int argc, char *argv[]) {
    int ret = 0;
    char *sep = "\n";
    int number = 0;
    int quiet = 0;
    int generate = 0;
    int nth = 0;
    int c;
    while ((c=getopt(argc, argv, "qhngs:")) != -1) {
        switch(c) {
            case 'q':
                quiet = 1; break;
            case 'h':
                return usage(argv[0]); break;
            case 'n':
                nth = 1; break;
            case 'g':
                generate = 1; break;
            case 's':
                sep = optarg; break;
            case '?':
                return -1;
            default:
                abort();
        }
    }
    if (optind < argc) {
        char *garbage = ((void *)0);
        number = strtol(argv[optind], &garbage, 10);
        if (*garbage != 0)
            number = 0;
    }
    if (nth && number >= 1) {
        fprintf(stdout, "%d\n", find_prime(number));
    }
    else if (generate && number >= 1) {
        generate_prime(number, sep);
    }
    else if (number > 1) {
        if (its_prime(number) && !quiet){
            fprintf(stdout, "true\n");
        }
        else {
            ret = 1;
            if (! quiet)
                fprintf(stdout, "false\n");
        }
    }
    else {
        fprintf(stdout, "Please enter valid integer, above than 1\n");
        return -1;
    }
    return ret;
}

variable_types:
sep
char *

variable_types: number int

variable_types: quiet int

variable_types: generate int

variable_types: nth int

variable_types: c int

variable_types:
garbage
char *


original_code:
int its_prime (int number) {
    if (number == 2)
        return 1;
    if ((number & 1) == 0)
        return 0;
    int start = 3;
    int to = number / 2;
    for (; start < to; start+=2) {
        if (number % start == 0) {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int its_prime(int number) {
    if (number == 2)
        return 1;
    if ((number & 1) == 0)
        return 0;
    int start = 3;
    int to = number / 2;
    for (; start < to; start+=2) {
        if (number % start == 0) {
            return 0;
        }
    }
    return 1;
}

variable_types: start int

variable_types: to int


decompiled_code:
__int64 __fastcall find_prime(int a1)
{
unsigned int v1; // ebx
int i; // ebp

if ( a1 <= 0 )
return 1;
v1 = 1;
for ( i = 0; i < a1; i -= ((unsigned int)its_prime(v1) == 0) - 1 )
++v1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
unsigned int v1; // ebx
int i; // ebp

if ( a1 <= 0 )
return 1;
v1 = 1;
for ( i = 0; i < a1; i -= ((unsigned int)func8(v1) == 0) - 1 )
++v1;
return v1;
}

original_code:
int find_prime(int number) {
    int x = 0, prime = 1;
    while(x<number) {
        prime++;
        if (its_prime(prime))
            x++;
    }
    return prime;
}

canonical_original_code:
int find_prime(int number) {
    int x = 0; int prime = 1;
    while(x<number) {
        prime++;
        if (its_prime(prime))
            x++;
    }
    return prime;
}

variable_types: x int

variable_types: prime int


decompiled_code:
int __fastcall generate_prime(int a1, const char *a2)
{
int v2; // ebx
int v3; // er12

if ( a1 > 0 )
{
v2 = 3;
v3 = 0;
while ( 1 )
{
if ( (unsigned int)its_prime(v2 - 1) )
{
fprintf(_bss_start, "%d", (unsigned int)(v2 - 1));
if ( a1 <= ++v3 )
return fputc(10, _bss_start);
fputs(a2, _bss_start);
}
else if ( a1 <= v3 )
{
return fputc(10, _bss_start);
}
++v2;
}
}
return fputc(10, _bss_start);
}

canonical_decompiled_code:
int __fastcall func10(int a1, const char *a2)
{
int v2; // ebx
int v3; // er12

if ( a1 > 0 )
{
v2 = 3;
v3 = 0;
while ( 1 )
{
if ( (unsigned int)func8(v2 - 1) )
{
fprintf(_bss_start, "%d", (unsigned int)(v2 - 1));
if ( a1 <= ++v3 )
return fputc(10, _bss_start);
fputs(a2, _bss_start);
}
else if ( a1 <= v3 )
{
return fputc(10, _bss_start);
}
++v2;
}
}
return fputc(10, _bss_start);
}

original_code:
void generate_prime(int number, char *separator) {
    int loop = 0, prime = 2;
    for (; loop < number; prime++) {
        if (its_prime(prime)) {
            fprintf(stdout, "%d", prime);
            loop++;
            if (loop < number)
                fprintf(stdout, "%s", separator);
        }
    }
    fprintf(stdout, "\n");
}

canonical_original_code:
void generate_prime(int number, char *separator) {
    int loop = 0; int prime = 2;
    for (; loop < number; prime++) {
        if (its_prime(prime)) {
            fprintf(stdout, "%d", prime);
            loop++;
            if (loop < number)
                fprintf(stdout, "%s", separator);
        }
    }
    fprintf(stdout, "\n");
}

variable_types:
separator
char *

variable_types: loop int


decompiled_code:
__int64 circbuf_size()
{
return (write_pointer + 5000 - read_pointer) % 0x1388u;
}

canonical_decompiled_code:
__int64 func7()
{
return (write_pointer + 5000 - read_pointer) % 0x1388u;
}

original_code:
static unsigned int circbuf_size(void)
{
    return (write_pointer + 5000 - read_pointer) % 5000;
}

canonical_original_code:
static unsigned int circbuf_size()
{
    return (write_pointer + 5000 - read_pointer) % 5000;
}

return_type: unsigned int


decompiled_code:
__int64 read_cb()
{
unsigned int v0; // eax
__int64 v1; // rsi

v0 = read_pointer;
v1 = 0LL;
if ( write_pointer != read_pointer )
{
read_pointer = (read_pointer + 1) % 0x1388u;
v1 = slots[2 * v0];
}
return v1;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // eax
__int64 v1; // rsi

v0 = read_pointer;
v1 = 0LL;
if ( write_pointer != read_pointer )
{
read_pointer = (read_pointer + 1) % 0x1388u;
v1 = slots[2 * v0];
}
return v1;
}

original_code:
static struct slot read_cb(void)
{
    struct slot foo;
    if (write_pointer == read_pointer) {
        return (struct slot){ .pointer=((void *)0), .size=0, .lfsr=0 };
    }
    foo = slots[read_pointer++];
    read_pointer %= 5000;
    return foo;
}

canonical_original_code:
static struct slot read_cb()
{
    struct slot foo;
    if (write_pointer == read_pointer) {
        return (struct slot){ .pointer=((void *)0), .size=0, .lfsr=0 };
    }
    foo = slots[read_pointer++];
    read_pointer %= 5000;
    return foo;
}

variable_types: struct slot { void *pointer; unsigned int size; unsigned int lfsr; }


prng

decompiled_code:
__int64 prng()
{
lfsr = ((unsigned int)lfsr >> 1) | (unsigned __int16)(((unsigned __int16)((unsigned int)lfsr >> 5) ^ (unsigned __int16)(lfsr ^ ((unsigned int)lfsr >> 3) ^ ((unsigned int)lfsr >> 2))) << 15);
return (unsigned __int16)lfsr;
}

canonical_decompiled_code:
__int64 func9()
{
lfsr = ((unsigned int)lfsr >> 1) | (unsigned __int16)(((unsigned __int16)((unsigned int)lfsr >> 5) ^ (unsigned __int16)(lfsr ^ ((unsigned int)lfsr >> 3) ^ ((unsigned int)lfsr >> 2))) << 15);
return (unsigned __int16)lfsr;
}

original_code:
static int prng(void)
{
    static unsigned int bit;
    bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
    lfsr = (lfsr >> 1) | (bit << 15);
    return lfsr & 0xffff;
}

canonical_original_code:
static int prng()
{
    static unsigned int bit;
    bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
    lfsr = (lfsr >> 1) | (bit << 15);
    return lfsr & 0xffff;
}

variable_types:
bit
unsigned int


decompiled_code:
__int64 __fastcall write_cb(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

if ( (unsigned int)circbuf_size() == 4999 )
{
fwrite("circular buffer overflow\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v2 = write_pointer;
v3 = 2LL * (unsigned int)write_pointer;
slots[v3] = a1;
qword_4040A8[v3] = a2;
result = (v2 + 1) % 0x1388u;
write_pointer = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

if ( (unsigned int)func7() == 4999 )
{
fwrite("circular buffer overflow\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
v2 = write_pointer;
v3 = 2LL * (unsigned int)write_pointer;
slots[v3] = a1;
qword_4040A8[v3] = a2;
result = (v2 + 1) % 0x1388u;
write_pointer = result;
return result;
}

original_code:
static void write_cb(struct slot foo)
{
    if (circbuf_size() == 5000 - 1) {
        fprintf(stderr, "circular buffer overflow\n");
        exit(1);
    }
    slots[write_pointer++] = foo;
    write_pointer %= 5000;
}

user_defined_types: struct slot { void *pointer; unsigned int size; unsigned int lfsr; }


main

decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char **v4; // r12
__int64 v5; // r14
unsigned int v6; // edx
int v7; // ebx
int v8; // rdx^4
__int64 v9; // rdx
unsigned __int8 *v10; // rbp
__int64 v11; // r13
unsigned __int8 v12; // r12
unsigned __int8 v13; // bl
__int64 v14; // rdx
const char **v15; // rbx
__int64 v16; // rbp

LABEL_1:
while ( 1 )
{
v3 = prng(*(_QWORD *)&argc, argv, envp) & 0x7FF;
printf("%s %d: ", "tryit.c", 68LL);
printf("try to allocate %d bytes\n", (unsigned int)v3);
v4 = (const char **)pvPortMalloc((int)v3);
printf("%s %d: ", "tryit.c", 70LL);
argv = v4;
*(_QWORD *)&argc = "malloc returned %p\n";
printf("malloc returned %p\n", v4);
if ( !v4 )
break;
printf("allocate a block, size %d\n", (unsigned int)v3);
argv = (const char **)(((unsigned __int64)(unsigned int)lfsr << 32) | v3 & 0x7FF);
*(_QWORD *)&argc = v4;
write_cb((__int64)v4, (__int64)argv);
if ( (int)v3 > 0 )
{
v15 = v4;
v16 = (__int64)v4 + (unsigned int)(v3 - 1) + 1;
do
{
*(_BYTE *)v15 = prng(v4, argv, envp);
v15 = (const char **)((char *)v15 + 1);
}
while ( v15 != (const char **)v16 );
}
}
while ( 1 )
{
if ( !(unsigned int)circbuf_size() )
goto LABEL_1;
v5 = read_cb();
v7 = v6;
lfsr = v8;
argv = (const char **)v6;
printf("free a block, size %d\n", v6);
if ( v7 > 0 )
break;
LABEL_7:
*(_QWORD *)&argc = v5;
vPortFree(v5);
if ( (prng(v5, argv, v14) & 1) == 0 )
goto LABEL_1;
}
v10 = (unsigned __int8 *)v5;
v11 = (unsigned int)(v7 - 1) + v5 + 1;
while ( 1 )
{
v12 = *v10;
v13 = prng("free a block, size %d\n", argv, v9);
if ( v12 != v13 )
break;
if ( ++v10 == (unsigned __int8 *)v11 )
goto LABEL_7;
}
printf("%s %d: ", "tryit.c", 84LL);
printf("OUCH: u=%02X, v=%02X\n", v12, v13);
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
const char **v4; // r12
__int64 v5; // r14
unsigned int v6; // edx
int v7; // ebx
int v8; // rdx^4
__int64 v9; // rdx
unsigned __int8 *v10; // rbp
__int64 v11; // r13
unsigned __int8 v12; // r12
unsigned __int8 v13; // bl
__int64 v14; // rdx
const char **v15; // rbx
__int64 v16; // rbp

LABEL_1:
while ( 1 )
{
v3 = func9(*(_QWORD *)&argc, argv, envp) & 0x7FF;
printf("%s %d: ", "tryit.c", 68LL);
printf("try to allocate %d bytes\n", (unsigned int)v3);
v4 = (const char **)func11((int)v3);
printf("%s %d: ", "tryit.c", 70LL);
argv = v4;
*(_QWORD *)&argc = "malloc returned %p\n";
printf("malloc returned %p\n", v4);
if ( !v4 )
break;
printf("allocate a block, size %d\n", (unsigned int)v3);
argv = (const char **)(((unsigned __int64)(unsigned int)lfsr << 32) | v3 & 0x7FF);
*(_QWORD *)&argc = v4;
func10((__int64)v4, (__int64)argv);
if ( (int)v3 > 0 )
{
v15 = v4;
v16 = (__int64)v4 + (unsigned int)(v3 - 1) + 1;
do
{
*(_BYTE *)v15 = func9(v4, argv, envp);
v15 = (const char **)((char *)v15 + 1);
}
while ( v15 != (const char **)v16 );
}
}
while ( 1 )
{
if ( !(unsigned int)func7() )
goto LABEL_1;
v5 = func8();
v7 = v6;
lfsr = v8;
argv = (const char **)v6;
printf("free a block, size %d\n", v6);
if ( v7 > 0 )
break;
LABEL_7:
*(_QWORD *)&argc = v5;
func12(v5);
if ( (func9(v5, argv, v14) & 1) == 0 )
goto LABEL_1;
}
v10 = (unsigned __int8 *)v5;
v11 = (unsigned int)(v7 - 1) + v5 + 1;
while ( 1 )
{
v12 = *v10;
v13 = func9("free a block, size %d\n", argv, v9);
if ( v12 != v13 )
break;
if ( ++v10 == (unsigned __int8 *)v11 )
goto LABEL_7;
}
printf("%s %d: ", "tryit.c", 84LL);
printf("OUCH: u=%02X, v=%02X\n", v12, v13);
return 1;
}

original_code:
int main(void)
{
    int i, size;
    char *p;
    while (1) {
        size = prng() & 0x7FF;
        printf("%s %d: ", "tryit.c", 68); printf("try to allocate %d bytes\n", size);
        p = (char *) pvPortMalloc(size);
        printf("%s %d: ", "tryit.c", 70); printf("malloc returned %p\n", p);
        if (p == ((void *)0)) {
            while (circbuf_size() > 0) {
                struct slot foo = read_cb();
                p = foo.pointer;
                lfsr = foo.lfsr;
                size = foo.size;
                printf("free a block, size %d\n", size);
                for (i = 0; i < size; i++) {
                    unsigned char u = p[i];
                    unsigned char v = (unsigned char) prng();
                    if (u != v) {
                        printf("%s %d: ", "tryit.c", 84); printf("OUCH: u=%02X, v=%02X\n", u, v);
                        return 1;
                    }
                }
                vPortFree(p);
                if ((prng() & 1) == 0) break;
            }
        } else {
            printf("allocate a block, size %d\n", size);
            write_cb((struct slot){.pointer=p, .size=size, .lfsr=lfsr});
            for (i = 0; i < size; i++) {
                p[i] = (unsigned char) prng();
            }
        }
    }
    return 0;
}

canonical_original_code:
int main()
{
    int i; int size;
    char *p;
    while (1) {
        size = prng() & 0x7FF;
        printf("%s %d: ", "tryit.c", 68); printf("try to allocate %d bytes\n", size);
        p = (char *) pvPortMalloc(size);
        printf("%s %d: ", "tryit.c", 70); printf("malloc returned %p\n", p);
        if (p == ((void *)0)) {
            while (circbuf_size() > 0) {
                struct slot foo = read_cb();
                p = foo.pointer;
                lfsr = foo.lfsr;
                size = foo.size;
                printf("free a block, size %d\n", size);
                for (i = 0; i < size; i++) {
                    unsigned char u = p[i];
                    unsigned char v = (unsigned char) prng();
                    if (u != v) {
                        printf("%s %d: ", "tryit.c", 84); printf("OUCH: u=%02X, v=%02X\n", u, v);
                        return 1;
                    }
                }
                vPortFree(p);
                if ((prng() & 1) == 0) break;
            }
        } else {
            printf("allocate a block, size %d\n", size);
            write_cb((struct slot){.pointer=p, .size=size, .lfsr=lfsr});
            for (i = 0; i < size; i++) {
                p[i] = (unsigned char) prng();
            }
        }
    }
    return 0;
}

variable_types: i int

variable_types: size int

variable_types:
p
char *

variable_types:
u
unsigned char

variable_types:
v
unsigned char


pvPortMalloc

original_code:
void *pvPortMalloc( size_t xWantedSize )
{
    xBlockLink *pxBlock, *pxPreviousSizeBlock, *pxNewBlockLink;
    static portBASE_TYPE xHeapHasBeenInitialised = 0;
    void *pvReturn = ((void *)0);
    ;
    {
        if ( xHeapHasBeenInitialised == 0 )
        {
            { xBlockLink *pxFirstFreeBlock; xStartSize.pxNextSizeBlock = ( void * ) xHeap.ucHeap; xStartSize.xBlockSize = ( size_t ) 0; xStartAddr.pxNextAddrBlock = ( void * ) xHeap.ucHeap; xEnd.xBlockSize = 4096; xEnd.pxNextSizeBlock = ((void *)0); xEnd.pxNextAddrBlock = ((void *)0); pxFirstFreeBlock = ( void * ) xHeap.ucHeap; pxFirstFreeBlock->xBlockSize = 4096; pxFirstFreeBlock->pxNextSizeBlock = &xEnd; pxFirstFreeBlock->pxNextAddrBlock = &xEnd; };
            xHeapHasBeenInitialised = 1;
        }
        if ( xWantedSize > 0 )
        {
            xWantedSize += heapSTRUCT_SIZE;
            if( xWantedSize & ((1 << 2) - 1) )
            {
                xWantedSize += ( (1 << 2) - ( xWantedSize & ((1 << 2) - 1) ) );
            }
        }
        if ( ( xWantedSize > 0 ) && ( xWantedSize < 4096 ) )
        {
            pxPreviousSizeBlock = &xStartSize;
            pxBlock = xStartSize.pxNextSizeBlock;
            while ( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextSizeBlock ) )
            {
                pxPreviousSizeBlock = pxBlock;
                pxBlock = pxBlock->pxNextSizeBlock;
            }
            if ( pxBlock != &xEnd )
            {
                xBlockLink *pxPreviousAddrBlock = &xStartAddr;
                pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousSizeBlock->pxNextSizeBlock ) +
                                        heapSTRUCT_SIZE );
                while ((int) pxPreviousAddrBlock->pxNextAddrBlock < (int) pxBlock)
                    pxPreviousAddrBlock = pxPreviousAddrBlock->pxNextAddrBlock;
                ;
                pxPreviousSizeBlock->pxNextSizeBlock = pxBlock->pxNextSizeBlock;
                pxPreviousAddrBlock->pxNextAddrBlock = pxBlock->pxNextAddrBlock;
                if ( ( pxBlock->xBlockSize - xWantedSize ) > ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) ) )
                {
                    pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );
                    pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
                    ;
                    pxBlock->xBlockSize = xWantedSize;
                    ;
                    { xBlockLink *pxIterator; size_t xBlockSize; xBlockSize = pxNewBlockLink->xBlockSize; for( pxIterator = &xStartSize; pxIterator->pxNextSizeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextSizeBlock ) { } pxNewBlockLink->pxNextSizeBlock = pxIterator->pxNextSizeBlock; pxIterator->pxNextSizeBlock = pxNewBlockLink; for ( pxIterator = &xStartAddr; pxIterator->pxNextAddrBlock != &xEnd && (int) pxIterator->pxNextAddrBlock < (int) pxNewBlockLink; pxIterator = pxIterator->pxNextAddrBlock ) { } pxNewBlockLink->pxNextAddrBlock = pxIterator->pxNextAddrBlock; pxIterator->pxNextAddrBlock = pxNewBlockLink; };
                }
                ;
                xFreeBytesRemaining -= pxBlock->xBlockSize;
            }
        }
    }
    ;
    return pvReturn;
}

canonical_original_code:
void *pvPortMalloc(unsigned long xWantedSize)
{
    struct A_BLOCK_LINK *pxBlock; struct A_BLOCK_LINK *pxPreviousSizeBlock; struct A_BLOCK_LINK *pxNewBlockLink;
    static int xHeapHasBeenInitialised = 0;
    void *pvReturn = ((void *)0);
    ;
    {
        if ( xHeapHasBeenInitialised == 0 )
        {
            { struct A_BLOCK_LINK *pxFirstFreeBlock; xStartSize.pxNextSizeBlock = ( void * ) xHeap.ucHeap; xStartSize.xBlockSize = ( unsigned long ) 0; xStartAddr.pxNextAddrBlock = ( void * ) xHeap.ucHeap; xEnd.xBlockSize = 4096; xEnd.pxNextSizeBlock = ((void *)0); xEnd.pxNextAddrBlock = ((void *)0); pxFirstFreeBlock = ( void * ) xHeap.ucHeap; pxFirstFreeBlock->xBlockSize = 4096; pxFirstFreeBlock->pxNextSizeBlock = &xEnd; pxFirstFreeBlock->pxNextAddrBlock = &xEnd; };
            xHeapHasBeenInitialised = 1;
        }
        if ( xWantedSize > 0 )
        {
            xWantedSize += heapSTRUCT_SIZE;
            if( xWantedSize & ((1 << 2) - 1) )
            {
                xWantedSize += ( (1 << 2) - ( xWantedSize & ((1 << 2) - 1) ) );
            }
        }
        if ( ( xWantedSize > 0 ) && ( xWantedSize < 4096 ) )
        {
            pxPreviousSizeBlock = &xStartSize;
            pxBlock = xStartSize.pxNextSizeBlock;
            while ( ( pxBlock->xBlockSize < xWantedSize ) && ( pxBlock->pxNextSizeBlock ) )
            {
                pxPreviousSizeBlock = pxBlock;
                pxBlock = pxBlock->pxNextSizeBlock;
            }
            if ( pxBlock != &xEnd )
            {
                struct A_BLOCK_LINK *pxPreviousAddrBlock = &xStartAddr;
                pvReturn = ( void * ) ( ( ( unsigned char * ) pxPreviousSizeBlock->pxNextSizeBlock ) +
                                        heapSTRUCT_SIZE );
                while ((int) pxPreviousAddrBlock->pxNextAddrBlock < (int) pxBlock)
                    pxPreviousAddrBlock = pxPreviousAddrBlock->pxNextAddrBlock;
                ;
                pxPreviousSizeBlock->pxNextSizeBlock = pxBlock->pxNextSizeBlock;
                pxPreviousAddrBlock->pxNextAddrBlock = pxBlock->pxNextAddrBlock;
                if ( ( pxBlock->xBlockSize - xWantedSize ) > ( ( unsigned long ) ( heapSTRUCT_SIZE * 2 ) ) )
                {
                    pxNewBlockLink = ( void * ) ( ( ( unsigned char * ) pxBlock ) + xWantedSize );
                    pxNewBlockLink->xBlockSize = pxBlock->xBlockSize - xWantedSize;
                    ;
                    pxBlock->xBlockSize = xWantedSize;
                    ;
                    { struct A_BLOCK_LINK *pxIterator; unsigned long xBlockSize; xBlockSize = pxNewBlockLink->xBlockSize; for( pxIterator = &xStartSize; pxIterator->pxNextSizeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextSizeBlock ) { } pxNewBlockLink->pxNextSizeBlock = pxIterator->pxNextSizeBlock; pxIterator->pxNextSizeBlock = pxNewBlockLink; for ( pxIterator = &xStartAddr; pxIterator->pxNextAddrBlock != &xEnd && (int) pxIterator->pxNextAddrBlock < (int) pxNewBlockLink; pxIterator = pxIterator->pxNextAddrBlock ) { } pxNewBlockLink->pxNextAddrBlock = pxIterator->pxNextAddrBlock; pxIterator->pxNextAddrBlock = pxNewBlockLink; };
                }
                ;
                xFreeBytesRemaining -= pxBlock->xBlockSize;
            }
        }
    }
    ;
    return pvReturn;
}

variable_types:
xWantedSize
unsigned long

variable_types: struct A_BLOCK_LINK { struct A_BLOCK_LINK *pxNextSizeBlock; struct A_BLOCK_LINK *pxNextAddrBlock; unsigned long xBlockSize; } *

variable_types: xHeapHasBeenInitialised int

variable_types:
pvReturn
void *

variable_types:
xBlockSize
unsigned long

return_type: void *


vPortFree

original_code:
void vPortFree( void *pv )
{
    unsigned char *puc = ( unsigned char * ) pv;
    xBlockLink *pxLink;
    if( pv )
    {
        puc -= heapSTRUCT_SIZE;
        pxLink = ( void * ) puc;
        ;
        {
            xBlockLink *previousPrevious, *previous, *successor;
            previousPrevious = ((void *)0);
            previous = &xStartAddr;
            while (previous->pxNextAddrBlock != &xEnd) {
                successor = previous->pxNextAddrBlock;
                if ((unsigned int) successor >= (unsigned int) pxLink)
                    break;
                previousPrevious = previous;
                previous = successor;
            }
            if (successor != &xEnd && ((xBlockLink*) (((char*)pxLink) + pxLink->xBlockSize)) == successor) {
                { xBlockLink *previousBySize, *successorBySize; previous->pxNextAddrBlock = successor->pxNextAddrBlock; previousBySize = &xStartSize; while (previousBySize->pxNextSizeBlock != ((void *)0)) { successorBySize = previousBySize->pxNextSizeBlock; if (successorBySize->xBlockSize >= successor->xBlockSize) break; previousBySize = successorBySize; } previousBySize->pxNextSizeBlock = successor->pxNextSizeBlock; };
                pxLink->xBlockSize += successor->xBlockSize;
            }
            if (previous != &xStartAddr && ((xBlockLink*) (((char*)previous) + previous->xBlockSize)) == pxLink) {
                { xBlockLink *previousBySize, *successorBySize; previousPrevious->pxNextAddrBlock = previous->pxNextAddrBlock; previousBySize = &xStartSize; while (previousBySize->pxNextSizeBlock != ((void *)0)) { successorBySize = previousBySize->pxNextSizeBlock; if (successorBySize->xBlockSize >= previous->xBlockSize) break; previousBySize = successorBySize; } previousBySize->pxNextSizeBlock = previous->pxNextSizeBlock; };
                previous->xBlockSize += pxLink->xBlockSize;
                pxLink = previous;
            }
            { xBlockLink *pxIterator; size_t xBlockSize; xBlockSize = ( ( xBlockLink * ) pxLink )->xBlockSize; for( pxIterator = &xStartSize; pxIterator->pxNextSizeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextSizeBlock ) { } ( ( xBlockLink * ) pxLink )->pxNextSizeBlock = pxIterator->pxNextSizeBlock; pxIterator->pxNextSizeBlock = ( ( xBlockLink * ) pxLink ); for ( pxIterator = &xStartAddr; pxIterator->pxNextAddrBlock != &xEnd && (int) pxIterator->pxNextAddrBlock < (int) ( ( xBlockLink * ) pxLink ); pxIterator = pxIterator->pxNextAddrBlock ) { } ( ( xBlockLink * ) pxLink )->pxNextAddrBlock = pxIterator->pxNextAddrBlock; pxIterator->pxNextAddrBlock = ( ( xBlockLink * ) pxLink ); };
            xFreeBytesRemaining += pxLink->xBlockSize;
        }
        ;
    }
}

canonical_original_code:
void vPortFree(void *pv)
{
    unsigned char *puc = ( unsigned char * ) pv;
    struct A_BLOCK_LINK *pxLink;
    if( pv )
    {
        puc -= heapSTRUCT_SIZE;
        pxLink = ( void * ) puc;
        ;
        {
            struct A_BLOCK_LINK *previousPrevious; struct A_BLOCK_LINK *previous; struct A_BLOCK_LINK *successor;
            previousPrevious = ((void *)0);
            previous = &xStartAddr;
            while (previous->pxNextAddrBlock != &xEnd) {
                successor = previous->pxNextAddrBlock;
                if ((unsigned int) successor >= (unsigned int) pxLink)
                    break;
                previousPrevious = previous;
                previous = successor;
            }
            if (successor != &xEnd && ((struct A_BLOCK_LINK *) (((char *)pxLink) + pxLink->xBlockSize)) == successor) {
                { struct A_BLOCK_LINK *previousBySize; struct A_BLOCK_LINK *successorBySize; previous->pxNextAddrBlock = successor->pxNextAddrBlock; previousBySize = &xStartSize; while (previousBySize->pxNextSizeBlock != ((void *)0)) { successorBySize = previousBySize->pxNextSizeBlock; if (successorBySize->xBlockSize >= successor->xBlockSize) break; previousBySize = successorBySize; } previousBySize->pxNextSizeBlock = successor->pxNextSizeBlock; };
                pxLink->xBlockSize += successor->xBlockSize;
            }
            if (previous != &xStartAddr && ((struct A_BLOCK_LINK *) (((char *)previous) + previous->xBlockSize)) == pxLink) {
                { struct A_BLOCK_LINK *previousBySize; struct A_BLOCK_LINK *successorBySize; previousPrevious->pxNextAddrBlock = previous->pxNextAddrBlock; previousBySize = &xStartSize; while (previousBySize->pxNextSizeBlock != ((void *)0)) { successorBySize = previousBySize->pxNextSizeBlock; if (successorBySize->xBlockSize >= previous->xBlockSize) break; previousBySize = successorBySize; } previousBySize->pxNextSizeBlock = previous->pxNextSizeBlock; };
                previous->xBlockSize += pxLink->xBlockSize;
                pxLink = previous;
            }
            { struct A_BLOCK_LINK *pxIterator; unsigned long xBlockSize; xBlockSize = ( ( struct A_BLOCK_LINK * ) pxLink )->xBlockSize; for( pxIterator = &xStartSize; pxIterator->pxNextSizeBlock->xBlockSize < xBlockSize; pxIterator = pxIterator->pxNextSizeBlock ) { } ( ( struct A_BLOCK_LINK * ) pxLink )->pxNextSizeBlock = pxIterator->pxNextSizeBlock; pxIterator->pxNextSizeBlock = ( ( struct A_BLOCK_LINK * ) pxLink ); for ( pxIterator = &xStartAddr; pxIterator->pxNextAddrBlock != &xEnd && (int) pxIterator->pxNextAddrBlock < (int) ( ( struct A_BLOCK_LINK * ) pxLink ); pxIterator = pxIterator->pxNextAddrBlock ) { } ( ( struct A_BLOCK_LINK * ) pxLink )->pxNextAddrBlock = pxIterator->pxNextAddrBlock; pxIterator->pxNextAddrBlock = ( ( struct A_BLOCK_LINK * ) pxLink ); };
            xFreeBytesRemaining += pxLink->xBlockSize;
        }
        ;
    }
}

variable_types:
pv
void *

variable_types:
puc
unsigned char *

user_defined_types: struct A_BLOCK_LINK { struct A_BLOCK_LINK *pxNextSizeBlock; struct A_BLOCK_LINK *pxNextAddrBlock; unsigned long xBlockSize; }


xPortGetFreeHeapSize

decompiled_code:
__int64 xPortGetFreeHeapSize()
{
return xFreeBytesRemaining;
}

canonical_decompiled_code:
__int64 func13()
{
return xFreeBytesRemaining;
}

original_code:
size_t xPortGetFreeHeapSize( void )
{
    return xFreeBytesRemaining;
}

canonical_original_code:
unsigned long xPortGetFreeHeapSize()
{
    return xFreeBytesRemaining;
}

return_type: unsigned long


vPortInitialiseBlocks

decompiled_code:
void vPortInitialiseBlocks()
{
;
}

canonical_decompiled_code:
void func14()
{
;
}

original_code:
void vPortInitialiseBlocks( void )
{
}

canonical_original_code:
void vPortInitialiseBlocks()
{
}


repo: emboss/openssl-prng

decompiled_code:
__int64 __fastcall RAND_set_rand_method(__int64 a1)
{
if ( funct_ref )
{
ENGINE_finish();
funct_ref = 0LL;
}
default_RAND_meth = a1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( funct_ref )
{
ENGINE_finish();
funct_ref = 0LL;
}
default_RAND_meth = a1;
return 1LL;
}

original_code:
int RAND_set_rand_method(const RAND_METHOD *meth)
 {
 if(funct_ref)
  {
  ENGINE_finish(funct_ref);
  funct_ref = ((void *)0);
  }
 default_RAND_meth = meth;
 return 1;
 }

canonical_original_code:
int RAND_set_rand_method(struct rand_meth_st *meth)
 {
 if(funct_ref)
  {
  ENGINE_finish(funct_ref);
  funct_ref = ((void *)0);
  }
 default_RAND_meth = meth;
 return 1;
 }

variable_types: struct rand_meth_st { void (*seed)(void *buf, int num); int (*bytes)(unsigned char *buf, int num); void (*cleanup)(); void (*add)(void *buf, int num, double entropy); int (*pseudorand)(unsigned char *buf, int num); int (*status)(); } *


decompiled_code:
__int64 RAND_cleanup()
{
__int64 v0; // rax
void (*v1)(void); // rax

v0 = RAND_get_rand_method();
if ( v0 )
{
v1 = *(void (**)(void))(v0 + 16);
if ( v1 )
v1();
}
return RAND_set_rand_method(0LL);
}

original_code:
void RAND_cleanup(void)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->cleanup)
  meth->cleanup();
 RAND_set_rand_method(((void *)0));
 }

canonical_original_code:
void RAND_cleanup()
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->cleanup)
  meth->cleanup();
 RAND_set_rand_method(((void *)0));
 }

user_defined_types: struct rand_meth_st { void (*seed)(void *buf, int num); int (*bytes)(unsigned char *buf, int num); void (*cleanup)(); void (*add)(void *buf, int num, double entropy); int (*pseudorand)(unsigned char *buf, int num); int (*status)(); }


decompiled_code:
__int64 __fastcall RAND_add(__int64 a1, unsigned int a2, double a3)
{
__int64 result; // rax

result = RAND_get_rand_method();
if ( result )
{
result = *(_QWORD *)(result + 24);
if ( result )
result = ((__int64 (__fastcall *)(__int64, _QWORD, double))result)(a1, a2, a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2, double a3)
{
__int64 result; // rax

result = func1();
if ( result )
{
result = *(_QWORD *)(result + 24);
if ( result )
result = ((__int64 (__fastcall *)(__int64, _QWORD, double))result)(a1, a2, a3);
}
return result;
}

original_code:
void RAND_add(const void *buf, int num, double entropy)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->add)
  meth->add(buf,num,entropy);
 }

canonical_original_code:
void RAND_add(void *buf, int num, double entropy)
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->add)
  meth->add(buf,num,entropy);
 }

variable_types:
buf
void *

variable_types: num int

variable_types: entropy double


decompiled_code:
__int64 __fastcall RAND_bytes(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64, _QWORD); // rax
__int64 result; // rax

v2 = RAND_get_rand_method();
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 8);
if ( v3 )
result = v3(a1, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64, _QWORD); // rax
__int64 result; // rax

v2 = func1();
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 8);
if ( v3 )
result = v3(a1, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int RAND_bytes(unsigned char *buf, int num)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->bytes)
  return meth->bytes(buf,num);
 return(-1);
 }

canonical_original_code:
int RAND_bytes(unsigned char *buf, int num)
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->bytes)
  return meth->bytes(buf,num);
 return(-1);
 }

variable_types:
buf
unsigned char *


decompiled_code:
__int64 __fastcall RAND_pseudo_bytes(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64, _QWORD); // rax
__int64 result; // rax

v2 = RAND_get_rand_method();
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 32);
if ( v3 )
result = v3(a1, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
__int64 (__fastcall *v3)(__int64, _QWORD); // rax
__int64 result; // rax

v2 = func1();
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = *(__int64 (__fastcall **)(__int64, _QWORD))(v2 + 32);
if ( v3 )
result = v3(a1, a2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int RAND_pseudo_bytes(unsigned char *buf, int num)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->pseudorand)
  return meth->pseudorand(buf,num);
 return(-1);
 }

canonical_original_code:
int RAND_pseudo_bytes(unsigned char *buf, int num)
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->pseudorand)
  return meth->pseudorand(buf,num);
 return(-1);
 }


decompiled_code:
__int64 __fastcall RAND_status(__int64 a1, __int64 a2)
{
__int64 v2; // rax
unsigned int v3; // edx
__int64 (__fastcall *v4)(__int64, __int64, _QWORD); // rax

v2 = RAND_get_rand_method();
v3 = 0;
if ( v2 )
{
v4 = *(__int64 (__fastcall **)(__int64, __int64, _QWORD))(v2 + 40);
if ( v4 )
v3 = v4(a1, a2, 0LL);
}
return v3;
}

original_code:
int RAND_status(void)
 {
 const RAND_METHOD *meth = RAND_get_rand_method();
 if (meth && meth->status)
  return meth->status();
 return 0;
 }

canonical_original_code:
int RAND_status()
 {
 struct rand_meth_st *meth = RAND_get_rand_method();
 if (meth && meth->status)
  return meth->status();
 return 0;
 }


decompiled_code:
int dump_random()
{
unsigned int v0; // eax
char *v1; // rbx
int v3; // [rsp+Ch] [rbp-1Ch] BYREF
char v4; // [rsp+10h] [rbp-18h] BYREF

v3 = 0;
RAND_bytes(&v3, 4LL);
v0 = getpid();
printf("pid=%d ", v0);
v1 = (char *)&v3;
do
printf("\\x%02x", (unsigned __int8)*v1++);
while ( v1 != &v4 );
return puts(&s);
}

canonical_decompiled_code:
int func0()
{
unsigned int v0; // eax
char *v1; // rbx
int v3; // [rsp+Ch] [rbp-1Ch] BYREF
char v4; // [rsp+10h] [rbp-18h] BYREF

v3 = 0;
RAND_bytes(&v3, 4LL);
v0 = getpid();
printf("pid=%d ", v0);
v1 = (char *)&v3;
do
printf("\\x%02x", (unsigned __int8)*v1++);
while ( v1 != &v4 );
return puts(&s);
}

original_code:
static void dump_random(void)
{
    int i;
    unsigned char buf[4];
    memset(buf, 0, sizeof(buf));
    RAND_bytes(buf, sizeof(buf));
    printf("pid=%d ", getpid());
    for (i = 0; i < sizeof(buf); i++)
 printf("\\x%02x", buf[i]);
    puts("");
}

canonical_original_code:
static void dump_random()
{
    int i;
    unsigned char buf[4];
    memset(buf, 0, sizeof(buf));
    RAND_bytes(buf, sizeof(buf));
    printf("pid=%d ", getpid());
    for (i = 0; i < sizeof(buf); i++)
 printf("\\x%02x", buf[i]);
    puts("");
}

variable_types: i int

variable_types:
buf
unsigned char [4]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // ebp
__pid_t v5; // eax
__pid_t v6; // ebx
__pid_t v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

RAND_bytes(v8, 4LL);
v3 = fork();
v8[0] = v3;
if ( v3 )
{
if ( v3 <= 0 )
{
perror("fork");
v4 = 1;
}
else
{
wait(0LL);
while ( 1 )
{
v5 = fork();
v6 = v5;
v4 = v5;
if ( !v5 )
break;
if ( v5 > 0 )
wait(0LL);
else
perror("fork");
if ( v8[0] == v6 )
return 0;
}
if ( getpid() == v8[0] )
dump_random();
}
}
else
{
v4 = 0;
dump_random();
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__pid_t v3; // eax
int v4; // ebp
__pid_t v5; // eax
__pid_t v6; // ebx
__pid_t v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

RAND_bytes(v8, 4LL);
v3 = fork();
v8[0] = v3;
if ( v3 )
{
if ( v3 <= 0 )
{
perror("fork");
v4 = 1;
}
else
{
wait(0LL);
while ( 1 )
{
v5 = fork();
v6 = v5;
v4 = v5;
if ( !v5 )
break;
if ( v5 > 0 )
wait(0LL);
else
perror("fork");
if ( v8[0] == v6 )
return 0;
}
if ( getpid() == v8[0] )
func0();
}
}
else
{
v4 = 0;
func0();
}
return v4;
}

original_code:
int main(void)
{
    pid_t pid, xpid;
    RAND_bytes((unsigned char *)&pid, sizeof(pid));
    pid = fork();
    if (pid == 0) {
 dump_random();
 return 0;
    } else if (pid > 0) {
 wait(((void *)0));
 do {
     xpid = fork();
     if (xpid == 0) {
  if (getpid() == pid) {
      dump_random();
  }
  return 0;
     } else if (xpid > 0) {
  wait(((void *)0));
     } else {
  perror("fork");
     }
 } while (pid != xpid);
    } else {
 perror("fork");
 return 1;
    }
    return 0;
}

canonical_original_code:
int main()
{
    int pid; int xpid;
    RAND_bytes((unsigned char *)&pid, sizeof(pid));
    pid = fork();
    if (pid == 0) {
 dump_random();
 return 0;
    } else if (pid > 0) {
 wait(((void *)0));
 do {
     xpid = fork();
     if (xpid == 0) {
  if (getpid() == pid) {
      dump_random();
  }
  return 0;
     } else if (xpid > 0) {
  wait(((void *)0));
     } else {
  perror("fork");
     }
 } while (pid != xpid);
    } else {
 perror("fork");
 return 1;
    }
    return 0;
}

variable_types: pid int

variable_types: xpid int


original_code:
int RAND_poll(void)
{
 unsigned long l;
 pid_t curr_pid = getpid();
 l=curr_pid;
 RAND_add(&l,sizeof(l),0.0);
 l=getuid();
 RAND_add(&l,sizeof(l),0.0);
 l=time(((void *)0));
 RAND_add(&l,sizeof(l),0.0);
 return 0;
}

canonical_original_code:
int RAND_poll()
{
 unsigned long l;
 int curr_pid = getpid();
 l=curr_pid;
 RAND_add(&l,sizeof(l),0.0);
 l=getuid();
 RAND_add(&l,sizeof(l),0.0);
 l=time(((void *)0));
 RAND_add(&l,sizeof(l),0.0);
 return 0;
}

variable_types:
l
unsigned long


decompiled_code:
__int64 __fastcall my_putnbr(unsigned int a1)
{
if ( a1 > 9 )
my_putnbr(a1 / 0xAuLL);
return my_putchar((unsigned int)(char)(a1 % 0xA + 48));
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
if ( a1 > 9 )
func0(a1 / 0xAuLL);
return my_putchar((unsigned int)(char)(a1 % 0xA + 48));
}

original_code:
void my_putnbr(unsigned int nb)
{
  if (nb > 9)
    my_putnbr(nb / 10);
  my_putchar(nb % 10 + '0');
}

variable_types:
nb
unsigned int


decompiled_code:
__int64 refresh_win()
{
print_list();
wrefresh(g_ctrl);
wrefresh(*(WINDOW **)&g_ctrl->_regtop);
wrefresh(stdscr);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
print_list();
wrefresh(g_ctrl);
wrefresh(*(WINDOW **)&g_ctrl->_regtop);
wrefresh(stdscr);
return 1LL;
}

original_code:
t_bool refresh_win(int focus)
{
  print_list(focus);
  wrefresh(g_ctrl.menu[0].win);
  wrefresh(g_ctrl.menu[1].win);
  wrefresh(stdscr);
  return (1);
}

canonical_original_code:
unsigned char refresh_win(int focus)
{
  print_list(focus);
  wrefresh(g_ctrl.menu[0].win);
  wrefresh(g_ctrl.menu[1].win);
  wrefresh(stdscr);
  return (1);
}

variable_types: focus int

return_type: unsigned char


decompiled_code:
__int64 __fastcall catch_key()
{
int v0; // ebp
int v1; // eax
int v2; // ebx
void (__fastcall *v3)(WINDOW **); // rdx
_DWORD *v4; // rax
int v5; // edx
__int64 v6; // rdi

keypad(stdscr, 1);
while ( 1 )
{
if ( v0 == 9 )
{
v1 = (g_ctrl->_bkgrnd.chars[2] + 1) % 2;
g_ctrl->_bkgrnd.chars[2] = v1;
wbkgd(*(&g_ctrl + 7 * v1), 0x100uLL);
wbkgd(*(&g_ctrl + 7 * ((g_ctrl->_bkgrnd.chars[2] + 1) % 2)), 0x400uLL);
LABEL_10:
v4 = &g_movetab;
v2 = 0;
do
{
++v2;
v5 = v4[6];
v4 += 6;
}
while ( v5 != v0 && v5 );
goto LABEL_4;
}
if ( v0 != 259 )
goto LABEL_10;
v2 = 0;
LABEL_4:
v3 = (void (__fastcall *)(WINDOW **))*(&funcs_F6 + 3 * v2);
if ( v3 )
{
v3(&g_ctrl + 7 * g_ctrl->_bkgrnd.chars[2]);
}
else
{
v6 = qword_1B0[3 * v2];
if ( v6 )
exec_sh(v6, &g_ctrl + 7 * g_ctrl->_bkgrnd.chars[2]);
}
refresh_win((unsigned int)g_ctrl->_bkgrnd.chars[2]);
if ( v2 != -1 )
{
v0 = wgetch(stdscr);
if ( v0 == 113 )
return 1LL;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1()
{
int v0; // ebp
int v1; // eax
int v2; // ebx
void (__fastcall *v3)(WINDOW **); // rdx
_DWORD *v4; // rax
int v5; // edx
__int64 v6; // rdi

keypad(stdscr, 1);
while ( 1 )
{
if ( v0 == 9 )
{
v1 = (g_ctrl->_bkgrnd.chars[2] + 1) % 2;
g_ctrl->_bkgrnd.chars[2] = v1;
wbkgd(*(&g_ctrl + 7 * v1), 0x100uLL);
wbkgd(*(&g_ctrl + 7 * ((g_ctrl->_bkgrnd.chars[2] + 1) % 2)), 0x400uLL);
LABEL_10:
v4 = &g_movetab;
v2 = 0;
do
{
++v2;
v5 = v4[6];
v4 += 6;
}
while ( v5 != v0 && v5 );
goto LABEL_4;
}
if ( v0 != 259 )
goto LABEL_10;
v2 = 0;
LABEL_4:
v3 = (void (__fastcall *)(WINDOW **))*(&funcs_F6 + 3 * v2);
if ( v3 )
{
v3(&g_ctrl + 7 * g_ctrl->_bkgrnd.chars[2]);
}
else
{
v6 = qword_1B0[3 * v2];
if ( v6 )
exec_sh(v6, &g_ctrl + 7 * g_ctrl->_bkgrnd.chars[2]);
}
func0((unsigned int)g_ctrl->_bkgrnd.chars[2]);
if ( v2 != -1 )
{
v0 = wgetch(stdscr);
if ( v0 == 113 )
return 1LL;
}
}
}

original_code:
t_bool catch_key()
{
  int i;
  int key;
  keypad(stdscr, 1);
  i = -1;
  while (i == -1 || (key = wgetch(stdscr)) != 'q')
    {
      i = 0;
      if (key == '\t')
 {
   g_ctrl.focus = (g_ctrl.focus + 1) % 2;
   wbkgd(g_ctrl.menu[g_ctrl.focus].win, (((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
   wbkgd(g_ctrl.menu[(g_ctrl.focus + 1) % 2].win, (((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
 }
      while (g_movetab[i].c != 0 && g_movetab[i].c != key)
 i++;
      if (g_movetab[i].fct != ((void *)0))
 g_movetab[i].fct(&(g_ctrl.menu[g_ctrl.focus]));
      else if (g_movetab[i].sh != ((void *)0))
 exec_sh(g_movetab[i].sh, &(g_ctrl.menu[g_ctrl.focus]));
      refresh_win(g_ctrl.focus);
    }
  return (1);
}

canonical_original_code:
unsigned char catch_key()
{
  int i;
  int key;
  keypad(stdscr, 1);
  i = -1;
  while (i == -1 || (key = wgetch(stdscr)) != 'q')
    {
      i = 0;
      if (key == '\t')
 {
   g_ctrl.focus = (g_ctrl.focus + 1) % 2;
   wbkgd(g_ctrl.menu[g_ctrl.focus].win, (((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
   wbkgd(g_ctrl.menu[(g_ctrl.focus + 1) % 2].win, (((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
 }
      while (g_movetab[i].c != 0 && g_movetab[i].c != key)
 i++;
      if (g_movetab[i].fct != ((void *)0))
 g_movetab[i].fct(&(g_ctrl.menu[g_ctrl.focus]));
      else if (g_movetab[i].sh != ((void *)0))
 exec_sh(g_movetab[i].sh, &(g_ctrl.menu[g_ctrl.focus]));
      refresh_win(g_ctrl.focus);
    }
  return (1);
}

variable_types: key int


decompiled_code:
__int64 __fastcall my_strndup(char *a1, int a2)
{
int v2; // eax
__int64 v3; // rcx
char v4; // dl
__int64 v5; // rax

if ( !a1 )
return 0LL;
v2 = my_strlen();
v3 = my_malloc((unsigned int)(v2 + 1));
if ( v3 )
{
v4 = *a1;
if ( a2 > 0 )
{
if ( v4 )
{
v5 = 0LL;
do
{
*(_BYTE *)(v3 + v5++) = v4;
v4 = a1[v5];
}
while ( a2 > (int)v5 && v4 );
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2)
{
int v2; // eax
__int64 v3; // rcx
char v4; // dl
__int64 v5; // rax

if ( !a1 )
return 0LL;
v2 = my_strlen();
v3 = my_malloc((unsigned int)(v2 + 1));
if ( v3 )
{
v4 = *a1;
if ( a2 > 0 )
{
if ( v4 )
{
v5 = 0LL;
do
{
*(_BYTE *)(v3 + v5++) = v4;
v4 = a1[v5];
}
while ( a2 > (int)v5 && v4 );
}
}
}
return v3;
}

original_code:
char *my_strndup(char *str, int len)
{
  char *ret;
  int i;
  if (!str)
    return (str);
  i = 0;
  if ((ret = my_malloc(sizeof(*ret) * (my_strlen(str) + 1))) == ((void *)0))
    return (((void *)0));
  while (str[i] != '\0' && i < len)
    {
      ret[i] = str[i];
      i++;
    }
  return (ret);
}

variable_types:
str
char *

variable_types: len int

variable_types:
ret
char *

return_type: char *


decompiled_code:
__int64 __fastcall my_read(int a1, void *a2, int a3)
{
unsigned int v3; // ebx

v3 = 0;
if ( a3 > 0 )
{
if ( a2 )
{
v3 = read(a1, a2, a3);
if ( v3 == -1 )
print_errno(2LL);
}
else
{
print_errno(1LL);
v3 = -1;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, void *a2, int a3)
{
unsigned int v3; // ebx

v3 = 0;
if ( a3 > 0 )
{
if ( a2 )
{
v3 = read(a1, a2, a3);
if ( v3 == -1 )
print_errno(2LL);
}
else
{
print_errno(1LL);
v3 = -1;
}
}
return v3;
}

original_code:
int my_read(const int fd, void *buf, const int count)
{
  int ret;
  if (count <= 0)
    return (0);
  if (!buf)
    {
      print_errno(1);
      return (-1);
    }
  if ((ret = read(fd, buf, count)) == -1)
    {
      print_errno(2);
      return (-1);
    }
  if (ret == 0)
    return (0);
  return (ret);
}

canonical_original_code:
int my_read(int fd, void *buf, int count)
{
  int ret;
  if (count <= 0)
    return (0);
  if (!buf)
    {
      print_errno(1);
      return (-1);
    }
  if ((ret = read(fd, buf, count)) == -1)
    {
      print_errno(2);
      return (-1);
    }
  if (ret == 0)
    return (0);
  return (ret);
}

variable_types: fd int

variable_types: count int

variable_types: ret int


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

if ( a1 )
{
v2 = open(a1, a2);
if ( v2 == -1 )
{
my_putstr(a1);
print_errno(3LL);
}
}
else
{
print_errno(1LL);
v2 = -1;
}
return v2;
}

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

if ( a1 )
{
v2 = open(a1, a2);
if ( v2 == -1 )
{
my_putstr(a1);
print_errno(3LL);
}
}
else
{
print_errno(1LL);
v2 = -1;
}
return v2;
}

original_code:
int my_open(char *path, int flags)
{
  int fd;
  if (!path)
    {
      print_errno(1);
      return (-1);
    }
  if ((fd = open(path, flags)) == -1)
    {
      my_putstr(path);
      print_errno(3);
      return (-1);
    }
  else
    return (fd);
}

variable_types:
path
char *

variable_types: flags int


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

if ( a1 )
{
v2 = open(a1, a2 | 0x40);
if ( v2 == -1 )
print_errno(4LL);
}
else
{
print_errno(1LL);
v2 = -1;
}
return v2;
}

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

if ( a1 )
{
v2 = open(a1, a2 | 0x40);
if ( v2 == -1 )
print_errno(4LL);
}
else
{
print_errno(1LL);
v2 = -1;
}
return v2;
}

original_code:
int my_create(char *path, int flags, int mode)
{
  int fd;
  if (!path)
    {
      print_errno(1);
      return (-1);
    }
  if ((fd = open(path, flags | 0100, mode)) == -1)
    {
      print_errno(4);
      return (-1);
    }
  else
    return (fd);
}

variable_types: mode int


decompiled_code:
int __fastcall my_close(int a1)
{
int result; // eax

if ( a1 < 0 || (result = close(a1), result == -1) )
{
print_errno(5LL);
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
int result; // eax

if ( a1 < 0 || (result = close(a1), result == -1) )
{
print_errno(5LL);
result = -1;
}
return result;
}

original_code:
int my_close(int fd)
{
  int ret;
  if (fd < 0 || (ret = close(fd)) == -1)
    {
      print_errno(5);
      return (-1);
    }
  return (ret);
}


original_code:
char *my_stradd(char *str1, char *str2)
{
  char *ret;
  int i;
  int j;
  if (!(ret = my_malloc(my_strlen(str1) + my_strlen(str2) + 1)))
    return (ret);
  i = 0;
  while (str1 && str1[i] != '\0')
    {
      ret[i] = str1[i];
      i++;
    }
  j = 0;
  while (str2 && str2[j] != '\0')
    {
      ret[i + j] = str2[j];
      j++;
    }
  return (ret);
}

variable_types: i int

variable_types: j int


decompiled_code:
int __fastcall mk_subcol(int a1, int a2, int a3, int a4)
{
int result; // eax

if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a4 - 1, a2) != -1 )
waddch(*((WINDOW **)&g_ctrl + 7 * a1), HIDWORD(acs_map[59]));
if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a4, a2) != -1 )
wvline(*((WINDOW **)&g_ctrl + 7 * a1), 0LL, LINES - 4);
if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a3, a2) != -1 )
waddch(*((WINDOW **)&g_ctrl + 7 * a1), LODWORD(acs_map[55]));
result = wmove(*((WINDOW **)&g_ctrl + 7 * a1), LINES - 4, a2);
if ( result != -1 )
result = waddch(*((WINDOW **)&g_ctrl + 7 * a1), LODWORD(acs_map[59]));
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, int a3, int a4)
{
int result; // eax

if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a4 - 1, a2) != -1 )
waddch(*((WINDOW **)&g_ctrl + 7 * a1), HIDWORD(acs_map[59]));
if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a4, a2) != -1 )
wvline(*((WINDOW **)&g_ctrl + 7 * a1), 0LL, LINES - 4);
if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a3, a2) != -1 )
waddch(*((WINDOW **)&g_ctrl + 7 * a1), LODWORD(acs_map[55]));
result = wmove(*((WINDOW **)&g_ctrl + 7 * a1), LINES - 4, a2);
if ( result != -1 )
result = waddch(*((WINDOW **)&g_ctrl + 7 * a1), LODWORD(acs_map[59]));
return result;
}

original_code:
void mk_subcol(int menu, int col, int inter, int start)
{
  (wmove((g_ctrl.menu[menu].win),(start - 1),(col)) == (-1) ? (-1) : waddch((g_ctrl.menu[menu].win),((acs_map[(unsigned char)(('w'))]))));
  (wmove((g_ctrl.menu[menu].win),(start),(col)) == (-1) ? (-1) : wvline((g_ctrl.menu[menu].win),(0),((LINES - 2 - 1) - 1)));
  (wmove((g_ctrl.menu[menu].win),(inter),(col)) == (-1) ? (-1) : waddch((g_ctrl.menu[menu].win),((acs_map[(unsigned char)(('n'))]))));
  (wmove((g_ctrl.menu[menu].win),((LINES - 2 - 1) - 1),(col)) == (-1) ? (-1) : waddch((g_ctrl.menu[menu].win),((acs_map[(unsigned char)(('v'))]))));
}

variable_types: menu int

variable_types: col int

variable_types: inter int

variable_types: start int


decompiled_code:
int __fastcall mk_subline(int a1, int a2)
{
int result; // eax

if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a2, 0) != -1 )
waddch(*((WINDOW **)&g_ctrl + 7 * a1), LODWORD(acs_map[58]));
if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a2, 1) != -1 )
whline(*((WINDOW **)&g_ctrl + 7 * a1), 0LL, (COLS - 5) / 2);
result = wmove(*((WINDOW **)&g_ctrl + 7 * a1), a2, (COLS - 5) / 2 - 1);
if ( result != -1 )
result = waddch(*((WINDOW **)&g_ctrl + 7 * a1), HIDWORD(acs_map[58]));
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1, int a2)
{
int result; // eax

if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a2, 0) != -1 )
waddch(*((WINDOW **)&g_ctrl + 7 * a1), LODWORD(acs_map[58]));
if ( wmove(*((WINDOW **)&g_ctrl + 7 * a1), a2, 1) != -1 )
whline(*((WINDOW **)&g_ctrl + 7 * a1), 0LL, (COLS - 5) / 2);
result = wmove(*((WINDOW **)&g_ctrl + 7 * a1), a2, (COLS - 5) / 2 - 1);
if ( result != -1 )
result = waddch(*((WINDOW **)&g_ctrl + 7 * a1), HIDWORD(acs_map[58]));
return result;
}

original_code:
void mk_subline(int menu, int line)
{
  (wmove((g_ctrl.menu[menu].win),(line),(0)) == (-1) ? (-1) : waddch((g_ctrl.menu[menu].win),((acs_map[(unsigned char)(('t'))]))));
  (wmove((g_ctrl.menu[menu].win),(line),(1)) == (-1) ? (-1) : whline((g_ctrl.menu[menu].win),(0),(((COLS - 4 - 1) / 2))));
  (wmove((g_ctrl.menu[menu].win),(line),(((COLS - 4 - 1) / 2) - 1)) == (-1) ? (-1) : waddch((g_ctrl.menu[menu].win),((acs_map[(unsigned char)(('u'))]))));
}

variable_types: line int


mkbox

decompiled_code:
int mkbox()
{
WINDOW **v0; // rbp
int i; // ebx
int result; // eax

wrefresh(stdscr);
v0 = (WINDOW **)&g_ctrl;
for ( i = 0; i != 2; ++i )
{
wborder(*v0, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
mk_subline(i, 2);
mk_subline(i, 4);
mk_subcol(i, (COLS - 5) / 2 - 13, 4, 3);
result = mk_subcol(i, 12, 4, 3);
v0 += 7;
}
return result;
}

canonical_decompiled_code:
int func2()
{
WINDOW **v0; // rbp
int i; // ebx
int result; // eax

wrefresh(stdscr);
v0 = (WINDOW **)&g_ctrl;
for ( i = 0; i != 2; ++i )
{
wborder(*v0, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
func1(i, 2);
func1(i, 4);
func0(i, (COLS - 5) / 2 - 13, 4, 3);
result = func0(i, 12, 4, 3);
v0 += 7;
}
return result;
}

original_code:
void mkbox()
{
  int i;
  i = 0;
  wrefresh(stdscr);
  while (i < 2)
    {
      wborder(g_ctrl.menu[i].win, 0, 0, 0, 0, 0, 0, 0, 0);
      mk_subline(i, 2);
      mk_subline(i, 4);
      mk_subcol(i, ((COLS - 4 - 1) / 2) - 13 , 4, 3);
      mk_subcol(i, 11 + 1, 4, 3);
      i++;
    }
}


decompiled_code:
int __fastcall printw_error(const char *a1)
{
wattr_on(stdscr, 0x800uLL, 0LL);
mvprintw(LINES - 1, 0, "%s", a1);
return wattr_off(stdscr, 0x800uLL, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
wattr_on(stdscr, 0x800uLL, 0LL);
mvprintw(LINES - 1, 0, "%s", a1);
return wattr_off(stdscr, 0x800uLL, 0LL);
}


variable_types: struct s_item { char right[11]; char *name; char **pwd; 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]; } s_stat; int color; } *

variable_types: c char

user_defined_types: struct s_item { char right[11]; char *name; char **pwd; struct stat s_stat; int color; }

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


newitem

decompiled_code:
__int64 __fastcall newitem(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
char *v6; // rbp

v2 = my_malloc(184LL);
if ( v2 )
{
v3 = my_strdup(a1);
*(_QWORD *)(v2 + 16) = v3;
if ( v3 )
{
*(_QWORD *)(v2 + 24) = a2;
v4 = creat_path(a2);
v5 = my_stradd(v4, &unk_161);
v6 = (char *)my_stradd(v5, a1);
stat(v6, (struct stat *)(v2 + 32));
select_attr(v2);
fill_right(v2);
free(v6);
}
else
{
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
char *v6; // rbp

v2 = my_malloc(184LL);
if ( v2 )
{
v3 = my_strdup(a1);
*(_QWORD *)(v2 + 16) = v3;
if ( v3 )
{
*(_QWORD *)(v2 + 24) = a2;
v4 = creat_path(a2);
v5 = my_stradd(v4, &unk_161);
v6 = (char *)my_stradd(v5, a1);
stat(v6, (struct stat *)(v2 + 32));
func0(v2);
func1(v2);
free(v6);
}
else
{
v2 = 0LL;
}
}
return v2;
}

original_code:
t_item *newitem(char *name, char **src_path)
{
  t_item *item;
  char *temp;
  if ((item = my_malloc(sizeof(*item))) == ((void *)0))
    return (((void *)0));
  if ((item->name = my_strdup(name)) == ((void *)0))
    return (((void *)0));
  item->pwd = src_path;
  temp = creat_path(src_path);
  temp = my_stradd(temp, "/");
  temp = my_stradd(temp, name);
  stat(temp, &item->s_stat);
  select_attr(item);
  fill_right(item);
  free(temp);
  return (item);
}

canonical_original_code:
struct s_item *newitem(char *name, char **src_path)
{
  struct s_item *item;
  char *temp;
  if ((item = my_malloc(sizeof(*item))) == ((void *)0))
    return (((void *)0));
  if ((item->name = my_strdup(name)) == ((void *)0))
    return (((void *)0));
  item->pwd = src_path;
  temp = creat_path(src_path);
  temp = my_stradd(temp, "/");
  temp = my_stradd(temp, name);
  stat(temp, &item->s_stat);
  select_attr(item);
  fill_right(item);
  free(temp);
  return (item);
}

variable_types:
name
char *

variable_types:
temp
char *

return_type: struct s_item { char right[11]; char *name; char **pwd; 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]; } s_stat; int color; } *


decompiled_code:
__int64 __fastcall select_attr(__int64 a1)
{
int v1; // eax

v1 = g_attrtab[0];
if ( g_attrtab[0] )
v1 = g_attrtab[0] != (*(_DWORD *)(a1 + 56) & g_attrtab[0]);
*(_DWORD *)(a1 + 176) = g_attrtab[2 * v1 + 1];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax

v1 = g_attrtab[0];
if ( g_attrtab[0] )
v1 = g_attrtab[0] != (*(_DWORD *)(a1 + 56) & g_attrtab[0]);
*(_DWORD *)(a1 + 176) = g_attrtab[2 * v1 + 1];
return 1LL;
}

original_code:
t_bool select_attr(t_item *item)
{
  int i;
  i = 0;
  while (g_attrtab[i].cmp != 0 &&
  (int)(item->s_stat.st_mode & g_attrtab[i].cmp) != g_attrtab[i].cmp)
    i++;
  item->color = g_attrtab[i].color;
  return (1);
}

canonical_original_code:
unsigned char select_attr(struct s_item *item)
{
  int i;
  i = 0;
  while (g_attrtab[i].cmp != 0 &&
  (int)(item->s_stat.st_mode & g_attrtab[i].cmp) != g_attrtab[i].cmp)
    i++;
  item->color = g_attrtab[i].color;
  return (1);
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
void __fastcall my_nputnstr(char *a1, int a2, int a3)
{
char v5; // si
__int64 v6; // rbx
int v7; // ebp
bool v8; // dl

if ( a1 )
{
v5 = *a1;
if ( a3 >= 0 && v5 )
{
v6 = 1LL;
do
{
waddch(*((WINDOW **)&g_ctrl + 7 * a2), (unsigned int)v5);
v7 = v6;
v5 = a1[v6];
v8 = a3 >= (int)v6++;
}
while ( v5 != 0 && v8 );
}
else
{
v7 = 0;
}
for ( ; a3 >= v7; ++v7 )
{
if ( a3 + 1 == v7 && (int)my_strlen(a1) > a3 )
waddch(*((WINDOW **)&g_ctrl + 7 * a2), 0x7EuLL);
else
waddch(*((WINDOW **)&g_ctrl + 7 * a2), 0x20uLL);
}
}
}

canonical_decompiled_code:
void __fastcall func1(char *a1, int a2, int a3)
{
char v5; // si
__int64 v6; // rbx
int v7; // ebp
bool v8; // dl

if ( a1 )
{
v5 = *a1;
if ( a3 >= 0 && v5 )
{
v6 = 1LL;
do
{
waddch(*((WINDOW **)&g_ctrl + 7 * a2), (unsigned int)v5);
v7 = v6;
v5 = a1[v6];
v8 = a3 >= (int)v6++;
}
while ( v5 != 0 && v8 );
}
else
{
v7 = 0;
}
for ( ; a3 >= v7; ++v7 )
{
if ( a3 + 1 == v7 && (int)my_strlen(a1) > a3 )
waddch(*((WINDOW **)&g_ctrl + 7 * a2), 0x7EuLL);
else
waddch(*((WINDOW **)&g_ctrl + 7 * a2), 0x20uLL);
}
}
}

original_code:
void my_nputnstr(char *str, int win, int max)
{
  int i;
  if (!str)
    return ;
  i = 0;
  while (str[i] != '\0' && i <= max)
    {
      waddch(g_ctrl.menu[win].win, (chtype) str[i]);
      i++;
    }
  while (i <= max)
    {
      if (i == max + 1 && my_strlen(str) > max)
 waddch(g_ctrl.menu[win].win, (chtype) '~');
      else
 waddch(g_ctrl.menu[win].win, (chtype) ' ');
      i++;
    }
}

canonical_original_code:
void my_nputnstr(char *str, int win, int max)
{
  int i;
  if (!str)
    return ;
  i = 0;
  while (str[i] != '\0' && i <= max)
    {
      waddch(g_ctrl.menu[win].win, (unsigned int) str[i]);
      i++;
    }
  while (i <= max)
    {
      if (i == max + 1 && my_strlen(str) > max)
 waddch(g_ctrl.menu[win].win, (unsigned int) '~');
      else
 waddch(g_ctrl.menu[win].win, (unsigned int) ' ');
      i++;
    }
}

variable_types:
str
char *

variable_types: win int

variable_types: max int


printfield

decompiled_code:
void __fastcall printfield(int a1, __int64 a2, int a3)
{
struct tm *v6; // rax
__int64 v7; // rsi
void *v8; // rdi
__int64 v9; // rax
char *v10; // r12
char s[68]; // [rsp+4h] [rbp-44h] BYREF

my_bzero(s, 11LL);
v6 = localtime((const time_t *)(a2 + 120));
strftime(s, 0xCuLL, "%a %d %Y", v6);
v7 = *(_QWORD *)(a2 + 16);
v8 = &unk_4B7;
if ( (*(_DWORD *)(a2 + 56) & 0xF000) != 0x4000 )
v8 = &unk_4B9;
v9 = my_stradd(v8, v7);
if ( v9 )
{
v10 = (char *)v9;
wmove(*((WINDOW **)&g_ctrl + 7 * a3), a1, 1);
my_nputnstr((char *)a2, a3, 8);
wmove(*((WINDOW **)&g_ctrl + 7 * a3), a1, 13);
my_nputnstr(v10, a3, (COLS - 5) / 2 - 27);
wmove(*((WINDOW **)&g_ctrl + 7 * a3), a1, (COLS - 5) / 2 - 12);
my_nputnstr(s, a3, 10);
free(v10);
}
}

original_code:
void printfield(int line, t_item *item, int win)
{
  char buff[12];
  char *name;
  char *temp;
  my_bzero(buff, 11);
  strftime(buff, 12, "%a %d %Y", localtime(&item->s_stat.st_mtime));
  name = item->name;
  if (((((item->s_stat.st_mode)) & 0170000) == (0040000)))
    temp = "/";
  else
    temp = " ";
  if ((name = my_stradd(temp, name)) == ((void *)0))
    return ;
  wmove(g_ctrl.menu[win].win, line, 1);
  my_nputnstr(item->right, win, 11 - 3);
  wmove(g_ctrl.menu[win].win, line, 2 + 11);
  my_nputnstr(name, win, ((COLS - 4 - 1) / 2) - (2 + 1) -
       (11 + 1) - (11 + 1));
  wmove(g_ctrl.menu[win].win, line, ((COLS - 4 - 1) / 2) - (11 + 1));
  my_nputnstr(buff, win, 11 - 1);
  free(name);
}

canonical_original_code:
void printfield(int line, struct s_item *item, int win)
{
  char buff[12];
  char *name;
  char *temp;
  my_bzero(buff, 11);
  strftime(buff, 12, "%a %d %Y", localtime(&item->s_stat.st_mtime));
  name = item->name;
  if (((((item->s_stat.st_mode)) & 0170000) == (0040000)))
    temp = "/";
  else
    temp = " ";
  if ((name = my_stradd(temp, name)) == ((void *)0))
    return ;
  wmove(g_ctrl.menu[win].win, line, 1);
  my_nputnstr(item->right, win, 11 - 3);
  wmove(g_ctrl.menu[win].win, line, 2 + 11);
  my_nputnstr(name, win, ((COLS - 4 - 1) / 2) - (2 + 1) -
       (11 + 1) - (11 + 1));
  wmove(g_ctrl.menu[win].win, line, ((COLS - 4 - 1) / 2) - (11 + 1));
  my_nputnstr(buff, win, 11 - 1);
  free(name);
}

variable_types: struct s_item { char right[11]; char *name; char **pwd; 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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } s_stat; int color; } *

variable_types:
buff
char [12]


decompiled_code:
__int64 __fastcall printfield_name(int a1, __int64 a2)
{
char *v2; // rbp
__int64 result; // rax

wattr_on(*((WINDOW **)&g_ctrl + 7 * a1), 0x200000uLL, 0LL);
wmove(*((WINDOW **)&g_ctrl + 7 * a1), 3, 1);
my_nputnstr("Right", a1, 9);
wmove(*((WINDOW **)&g_ctrl + 7 * a1), 3, 13);
my_nputnstr("Name", a1, (COLS - 5) / 2 - 27);
wmove(*((WINDOW **)&g_ctrl + 7 * a1), 3, (COLS - 5) / 2 - 12);
my_nputnstr("Last Modify", a1, 10);
wmove(*((WINDOW **)&g_ctrl + 7 * a1), 1, 1);
v2 = (char *)creat_path(a2);
result = 0LL;
if ( v2 )
{
my_nputnstr(v2, a1, (COLS - 5) / 2 - 3);
if ( (unsigned int)my_strlen(v2) != 1 )
free(v2);
wattr_off(*((WINDOW **)&g_ctrl + 7 * a1), 0x200000uLL, 0LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
char *v2; // rbp
__int64 result; // rax

wattr_on(*((WINDOW **)&g_ctrl + 7 * a1), 0x200000uLL, 0LL);
wmove(*((WINDOW **)&g_ctrl + 7 * a1), 3, 1);
func1("Right", a1, 9);
wmove(*((WINDOW **)&g_ctrl + 7 * a1), 3, 13);
func1("Name", a1, (COLS - 5) / 2 - 27);
wmove(*((WINDOW **)&g_ctrl + 7 * a1), 3, (COLS - 5) / 2 - 12);
func1("Last Modify", a1, 10);
wmove(*((WINDOW **)&g_ctrl + 7 * a1), 1, 1);
v2 = (char *)creat_path(a2);
result = 0LL;
if ( v2 )
{
func1(v2, a1, (COLS - 5) / 2 - 3);
if ( (unsigned int)my_strlen(v2) != 1 )
free(v2);
wattr_off(*((WINDOW **)&g_ctrl + 7 * a1), 0x200000uLL, 0LL);
result = 1LL;
}
return result;
}

original_code:
t_bool printfield_name(int win, char **path)
{
  char *pwd;
  wattr_on(g_ctrl.menu[win].win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
  wmove(g_ctrl.menu[win].win, 3, 1);
  my_nputnstr("Right", win, 11 - 2);
  wmove(g_ctrl.menu[win].win, 3, 1 + 11 + 1);
  my_nputnstr("Name", win, ((COLS - 4 - 1) / 2) - (2 + 1) - (11 + 1)
       - (11 + 1));
  wmove(g_ctrl.menu[win].win, 3, ((COLS - 4 - 1) / 2) - (11 + 1));
  my_nputnstr("Last Modify", win, 11 - 1);
  wmove(g_ctrl.menu[win].win, 1, 1);
  if ((pwd = creat_path(path)) == 0)
    return (0);
  my_nputnstr(pwd, win, ((COLS - 4 - 1) / 2) - 3);
  if (my_strlen(pwd) != 1)
      free(pwd);
  wattr_off(g_ctrl.menu[win].win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
  return (1);
}

canonical_original_code:
unsigned char printfield_name(int win, char **path)
{
  char *pwd;
  wattr_on(g_ctrl.menu[win].win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
  wmove(g_ctrl.menu[win].win, 3, 1);
  my_nputnstr("Right", win, 11 - 2);
  wmove(g_ctrl.menu[win].win, 3, 1 + 11 + 1);
  my_nputnstr("Name", win, ((COLS - 4 - 1) / 2) - (2 + 1) - (11 + 1)
       - (11 + 1));
  wmove(g_ctrl.menu[win].win, 3, ((COLS - 4 - 1) / 2) - (11 + 1));
  my_nputnstr("Last Modify", win, 11 - 1);
  wmove(g_ctrl.menu[win].win, 1, 1);
  if ((pwd = creat_path(path)) == 0)
    return (0);
  my_nputnstr(pwd, win, ((COLS - 4 - 1) / 2) - 3);
  if (my_strlen(pwd) != 1)
      free(pwd);
  wattr_off(g_ctrl.menu[win].win, (attr_t)(((chtype)((1U)) << ((13) + 8))), ((void *)0));
  return (1);
}

variable_types:
path
char **

variable_types:
pwd
char *


decompiled_code:
__int64 __fastcall print_list(int a1)
{
int i; // er13
__int64 result; // rax
__int64 v3; // r14
int v4; // eax
int j; // ebx
unsigned int v6; // ebp
_QWORD *v7; // [rsp+8h] [rbp-40h]

v7 = g_ctrl;
for ( i = 0; i != 2; ++i )
{
v3 = v7[1];
v4 = *((_DWORD *)v7 + 7);
for ( j = 0; *(_QWORD *)(v3 + 8LL * v4); v4 = *((_DWORD *)v7 + 7) + j )
{
if ( g_ctrl[8] <= v4 )
break;
v6 = select_attr(a1, i, j);
wattr_on((WINDOW *)*v7, v6, 0LL);
printfield(j + 5, *(_QWORD *)(v3 + 8LL * (*((_DWORD *)v7 + 7) + j)), i);
wattr_off((WINDOW *)*v7, v6, 0LL);
++j;
}
result = printfield_name(i, v7[2]);
v7 += 7;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int i; // er13
__int64 result; // rax
__int64 v3; // r14
int v4; // eax
int j; // ebx
unsigned int v6; // ebp
_QWORD *v7; // [rsp+8h] [rbp-40h]

v7 = g_ctrl;
for ( i = 0; i != 2; ++i )
{
v3 = v7[1];
v4 = *((_DWORD *)v7 + 7);
for ( j = 0; *(_QWORD *)(v3 + 8LL * v4); v4 = *((_DWORD *)v7 + 7) + j )
{
if ( g_ctrl[8] <= v4 )
break;
v6 = func0(a1, i, j);
wattr_on((WINDOW *)*v7, v6, 0LL);
func2(j + 5, *(_QWORD *)(v3 + 8LL * (*((_DWORD *)v7 + 7) + j)), i);
wattr_off((WINDOW *)*v7, v6, 0LL);
++j;
}
result = func3(i, v7[2]);
v7 += 7;
}
return result;
}

original_code:
void print_list(int focus)
{
  int i;
  int j;
  t_item **itab;
  int attr;
  i = 0;
  while (i < 2)
    {
      j = 0;
      itab = g_ctrl.menu[i].list;
      while (itab[g_ctrl.menu[i].limit[0]+ j] != ((void *)0) &&
      g_ctrl.menu[i].limit[0]+ j < g_ctrl.menu[0].limit[1])
 {
   attr = select_attr(focus, i, j);
   wattr_on(g_ctrl.menu[i].win, (attr_t)(attr), ((void *)0));
   printfield(j + 5, itab[g_ctrl.menu[i].limit[0] + j], i);
   wattr_off(g_ctrl.menu[i].win, (attr_t)(attr), ((void *)0));
   j++;
 }
      printfield_name(i, g_ctrl.menu[i].path);
      i++;
    }
}

canonical_original_code:
void print_list(int focus)
{
  int i;
  int j;
  struct s_item **itab;
  int attr;
  i = 0;
  while (i < 2)
    {
      j = 0;
      itab = g_ctrl.menu[i].list;
      while (itab[g_ctrl.menu[i].limit[0]+ j] != ((void *)0) &&
      g_ctrl.menu[i].limit[0]+ j < g_ctrl.menu[0].limit[1])
 {
   attr = select_attr(focus, i, j);
   wattr_on(g_ctrl.menu[i].win, (attr_t)(attr), ((void *)0));
   printfield(j + 5, itab[g_ctrl.menu[i].limit[0] + j], i);
   wattr_off(g_ctrl.menu[i].win, (attr_t)(attr), ((void *)0));
   j++;
 }
      printfield_name(i, g_ctrl.menu[i].path);
      i++;
    }
}

variable_types: focus int

variable_types: i int

variable_types: j int

variable_types: struct s_item { char right[11]; char *name; char **pwd; 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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; } s_stat; int color; } **

variable_types: attr int


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

result = 1024LL;
if ( a2 == a1 )
{
result = 768LL;
if ( *((_DWORD *)&g_ctrl + 14 * a2 + 6) != *((_DWORD *)&g_ctrl + 14 * a2 + 7) + a3 )
result = *(unsigned int *)(*(_QWORD *)(*((_QWORD *)&g_ctrl + 7 * a2 + 1) + 8LL * a3) + 176LL);
}
return result;
}

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

result = 1024LL;
if ( a2 == a1 )
{
result = 768LL;
if ( *((_DWORD *)&g_ctrl + 14 * a2 + 6) != *((_DWORD *)&g_ctrl + 14 * a2 + 7) + a3 )
result = *(unsigned int *)(*(_QWORD *)(*((_QWORD *)&g_ctrl + 7 * a2 + 1) + 8LL * a3) + 176LL);
}
return result;
}

original_code:
static int select_attr(int focus, int i, int j)
{
  if (i != focus)
    return ((((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
  else if (g_ctrl.menu[i].cur == g_ctrl.menu[i].limit[0]+ j)
    return ((((chtype)(((3))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
  else
    return (g_ctrl.menu[i].list[j]->color);
}


decompiled_code:
__int64 __fastcall recurs_strtok(_BYTE *a1, __int64 a2, int a3)
{
char v4; // di
_BYTE *v5; // rbp
int v6; // er13
int v7; // er14
char v8; // di
__int64 v9; // rbx
__int64 v10; // rbx
__int64 v11; // rax

v4 = *a1;
v5 = a1;
v6 = 0;
if ( v4 )
{
while ( (unsigned __int8)my_is_in((unsigned int)v4, a2) == 1 )
{
++v6;
v4 = *++v5;
if ( !*v5 )
goto LABEL_4;
}
v8 = a1[v6];
if ( v8 )
{
v7 = v6;
v9 = v6;
while ( !(unsigned __int8)my_is_in((unsigned int)v8, a2) )
{
++v7;
v8 = a1[++v9];
if ( !v8 )
goto LABEL_9;
}
if ( a1[v9] )
{
v10 = recurs_strtok(&a1[v9 + 1], a2, (unsigned int)(a3 + 1));
goto LABEL_13;
}
}
else
{
v7 = v6;
}
}
else
{
LABEL_4:
v7 = v6;
}
LABEL_9:
v10 = my_malloc((unsigned int)(8 * a3 + 8));
LABEL_13:
if ( v10 )
{
v11 = my_strndup(v5, (unsigned int)(v7 - v6));
*(_QWORD *)(v10 + 8LL * a3 - 8) = v11;
if ( !v11 )
v10 = 0LL;
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2, int a3)
{
char v4; // di
_BYTE *v5; // rbp
int v6; // er13
int v7; // er14
char v8; // di
__int64 v9; // rbx
__int64 v10; // rbx
__int64 v11; // rax

v4 = *a1;
v5 = a1;
v6 = 0;
if ( v4 )
{
while ( (unsigned __int8)my_is_in((unsigned int)v4, a2) == 1 )
{
++v6;
v4 = *++v5;
if ( !*v5 )
goto LABEL_4;
}
v8 = a1[v6];
if ( v8 )
{
v7 = v6;
v9 = v6;
while ( !(unsigned __int8)my_is_in((unsigned int)v8, a2) )
{
++v7;
v8 = a1[++v9];
if ( !v8 )
goto LABEL_9;
}
if ( a1[v9] )
{
v10 = func0(&a1[v9 + 1], a2, (unsigned int)(a3 + 1));
goto LABEL_13;
}
}
else
{
v7 = v6;
}
}
else
{
LABEL_4:
v7 = v6;
}
LABEL_9:
v10 = my_malloc((unsigned int)(8 * a3 + 8));
LABEL_13:
if ( v10 )
{
v11 = my_strndup(v5, (unsigned int)(v7 - v6));
*(_QWORD *)(v10 + 8LL * a3 - 8) = v11;
if ( !v11 )
v10 = 0LL;
}
return v10;
}

original_code:
static char **recurs_strtok(char *str, char *delim, int wcount)
{
  int i;
  int j;
  char **ret;
  j = 0;
  while (str[j] != '\0' && my_is_in(str[j], delim) == 1)
    j++;
  i = j;
  while (str[i] != '\0' && my_is_in(str[i], delim) == 0)
    i++;
  if (str[i] != '\0')
    ret = recurs_strtok(str + i + 1, delim, wcount + 1);
  else
    ret = my_malloc((wcount + 1) * sizeof(*ret));
  if (ret == ((void *)0))
    return (((void *)0));
  if ((ret[wcount - 1] = my_strndup(str + j, i - j)) == ((void *)0))
    return (((void *)0));
  return (ret);
}

variable_types:
delim
char *

variable_types: wcount int

variable_types:
ret
char **

return_type: char **


decompiled_code:
__int64 __fastcall strtok_tab(_BYTE *a1, __int64 a2)
{
return recurs_strtok(a1, a2, 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, __int64 a2)
{
return func0(a1, a2, 1);
}

original_code:
char **strtok_tab(char *str, char *delim)
{
  return (recurs_strtok(str, delim, 1));
}


decompiled_code:
__int64 __fastcall my_memset(__int64 a1, char a2, int a3)
{
__int64 v3; // rax

if ( a3 <= 0 || !a1 )
return 0LL;
v3 = 0LL;
do
*(_BYTE *)(a1 + v3++) = a2;
while ( a3 > (int)v3 );
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, int a3)
{
__int64 v3; // rax

if ( a3 <= 0 || !a1 )
return 0LL;
v3 = 0LL;
do
*(_BYTE *)(a1 + v3++) = a2;
while ( a3 > (int)v3 );
return a1;
}

original_code:
void *my_memset(void *s, char c, int n)
{
  int i;
  char *temp;
  i = 0;
  if (n <= 0 || !s)
    return (((void *)0));
  temp = s;
  while (i < n)
    {
      temp[i] = c;
      i++;
    }
  return (s);
}

variable_types:
s
void *

variable_types: c char

variable_types: n int


decompiled_code:
ssize_t __fastcall my_putchar(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

original_code:
void my_putchar(char c)
{
  write(1, &c, 1);
}


original_code:
char *my_revstr(char *str)
{
  int i;
  int len;
  int temp;
  i = 0;
  len = my_strlen(str) - 1;
  if (!str)
    return (str);
  while (i < len - i)
    {
      temp = str[i];
      str[i] = str[len - i];
      str[len - i] = temp;
      i++;
    }
  return (str);
}

variable_types:
str
char *

variable_types: len int

variable_types: temp int


original_code:
char *my_revmem(char *str, int len)
{
  int i;
  int temp;
  i = 0;
  len--;
  if (!str)
    return (str);
  while (i < len - i)
    {
      temp = str[i];
      str[i] = str[len - i];
      str[len - i] = temp;
      i++;
    }
  return (str);
}


decompiled_code:
ssize_t __fastcall my_putstr(void *buf)
{
int v1; // eax

v1 = my_strlen();
return write(1, buf, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func0(void *buf)
{
int v1; // eax

v1 = my_strlen();
return write(1, buf, v1);
}

original_code:
void my_putstr(const char *str)
{
  write(1, str, my_strlen(str));
}

canonical_original_code:
void my_putstr(char *str)
{
  write(1, str, my_strlen(str));
}


original_code:
char **add_tab(char *str, char **tab)
{
  char **new_array;
  int line;
  int i;
  i = 0;
  line = 0;
  if (tab == ((void *)0))
    return (((void *)0));
  while (tab[line] != ((void *)0))
    line++;
  if ((new_array = my_malloc(sizeof(*new_array) * (line + 2))) == ((void *)0))
    return (((void *)0));
  while (tab[i])
    {
      new_array[i] = my_strdup(tab[i]);
      i++;
    }
  new_array[i] = my_strdup(str);
  new_array[i + 1] = ((void *)0);
  return (new_array);
}

variable_types:
tab
char **

variable_types: line int


decompiled_code:
void __fastcall my_bzero(__int64 a1, int a2)
{
__int64 v2; // rax

if ( a1 && a2 > 0 )
{
v2 = 0LL;
do
*(_BYTE *)(a1 + v2++) = 0;
while ( a2 > (int)v2 );
}
}

original_code:
void my_bzero(void *ptr, const int len)
{
  int i;
  char *temp;
  i = 0;
  temp = ptr;
  while (ptr != ((void *)0) && len > 0 && i < len)
    {
      temp[i] = '\0';
      i++;
    }
}

canonical_original_code:
void my_bzero(void *ptr, int len)
{
  int i;
  char *temp;
  i = 0;
  temp = ptr;
  while (ptr != ((void *)0) && len > 0 && i < len)
    {
      temp[i] = '\0';
      i++;
    }
}

variable_types:
ptr
void *

variable_types:
temp
char *


decompiled_code:
__int64 __fastcall print_error(void *buf)
{
int v1; // eax

v1 = my_strlen();
write(2, buf, v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *buf)
{
int v1; // eax

v1 = my_strlen();
write(2, buf, v1);
return 0LL;
}

original_code:
void *print_error(const char *str)
{
  write(2, str, my_strlen(str));
  return (((void *)0));
}

canonical_original_code:
void *print_error(char *str)
{
  write(2, str, my_strlen(str));
  return (((void *)0));
}


decompiled_code:
__int64 __fastcall print_errno(int a1)
{
char *v1; // rbx
int v2; // eax

v1 = str_error[a1];
v2 = my_strlen(v1);
write(2, v1, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
char *v1; // rbx
int v2; // eax

v1 = str_error[a1];
v2 = my_strlen(v1);
write(2, v1, v2);
return 0LL;
}

original_code:
t_bool print_errno(int my_errno)
{
  write(2, str_error[my_errno], my_strlen(str_error[my_errno]));
  return (0);
}

canonical_original_code:
unsigned char print_errno(int my_errno)
{
  write(2, str_error[my_errno], my_strlen(str_error[my_errno]));
  return (0);
}