freeCommands

decompiled_code:
void __fastcall freeCommands(void ***a1)
{
void **v1; // rbx
void **v2; // rdi

v1 = (void **)a1;
v2 = *a1;
if ( v2 )
{
do
{
freeToken(v2);
free(*v1++);
v2 = (void **)*v1;
}
while ( *v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void ***a1)
{
void **v1; // rbx
void **v2; // rdi

v1 = (void **)a1;
v2 = *a1;
if ( v2 )
{
do
{
func0(v2);
free(*v1++);
v2 = (void **)*v1;
}
while ( *v1 );
}
}

original_code:
void freeCommands(char ***arr)
{
 int i = 0;
 while (arr[i] != ((void *)0))
 {
  freeToken(arr[i]);
  free(arr[i]);
 i++;
 }
}

variable_types:
arr
char ***


runpause

decompiled_code:
int __fastcall runpause(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax
const char *v4; // rdi
int result; // eax
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // rbx
int *v9; // rax
char *v10; // rax

v3 = *(_QWORD *)(a1 + 8LL * a3);
v4 = *(const char **)(v3 + 8);
if ( !v4 )
return puts("Error: \"pause\" needs one parameter!");
if ( *(_QWORD *)(v3 + 16) )
return puts("Error: \"pause\" has only one parameter!");
v6 = atol(v4);
v7 = findchild(v6, a2);
v8 = v7;
if ( !v7 )
return puts("Error: In \"pause,\" unable to find process!");
if ( !*(_DWORD *)(v7 + 4) )
return puts("Error: Process already paused!");
result = kill(v6, 19);
if ( result )
{
if ( result < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
printf("Pause failed: %s\n", v10);
exit(1);
}
}
else
{
*(_DWORD *)(v8 + 4) = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax
const char *v4; // rdi
int result; // eax
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // rbx
int *v9; // rax
char *v10; // rax

v3 = *(_QWORD *)(a1 + 8LL * a3);
v4 = *(const char **)(v3 + 8);
if ( !v4 )
return puts("Error: \"pause\" needs one parameter!");
if ( *(_QWORD *)(v3 + 16) )
return puts("Error: \"pause\" has only one parameter!");
v6 = atol(v4);
v7 = findchild(v6, a2);
v8 = v7;
if ( !v7 )
return puts("Error: In \"pause,\" unable to find process!");
if ( !*(_DWORD *)(v7 + 4) )
return puts("Error: Process already paused!");
result = kill(v6, 19);
if ( result )
{
if ( result < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
printf("Pause failed: %s\n", v10);
exit(1);
}
}
else
{
*(_DWORD *)(v8 + 4) = 0;
}
return result;
}

original_code:
void runpause(char *** commands, struct jobnode **jobs, int i)
{
 if (commands[i][1] == ((void *)0))
 {
  printf("%s\n", "Error: \"pause\" needs one parameter!");
 }
 else if (commands[i][2] != ((void *)0))
 {
  printf("%s\n", "Error: \"pause\" has only one parameter!");
 }
 else
 {
  int pausetarget = atol(commands[i][1]);
  struct jobnode *paused = findchild(pausetarget, jobs);
  if (paused == ((void *)0))
  {
   printf("%s\n", "Error: In \"pause,\" unable to find process!");
  }
  else
  {
   if (paused->running == 0)
   {
    printf("%s\n", "Error: Process already paused!");
   }
   else
   {
   int killresult = kill(pausetarget, 19);
   if (killresult == 0)
   {
    paused->running = 0;
   }
   else if(killresult < 0)
    {
     printf("Pause failed: %s\n", strerror((*__errno_location ())));
     exit(1);
    }
   }
  }
 }
}

canonical_original_code:
void runpause(char ***commands, struct jobnode **jobs, int i)
{
 if (commands[i][1] == ((void *)0))
 {
  printf("%s\n", "Error: \"pause\" needs one parameter!");
 }
 else if (commands[i][2] != ((void *)0))
 {
  printf("%s\n", "Error: \"pause\" has only one parameter!");
 }
 else
 {
  int pausetarget = atol(commands[i][1]);
  struct jobnode *paused = findchild(pausetarget, jobs);
  if (paused == ((void *)0))
  {
   printf("%s\n", "Error: In \"pause,\" unable to find process!");
  }
  else
  {
   if (paused->running == 0)
   {
    printf("%s\n", "Error: Process already paused!");
   }
   else
   {
   int killresult = kill(pausetarget, 19);
   if (killresult == 0)
   {
    paused->running = 0;
   }
   else if(killresult < 0)
    {
     printf("Pause failed: %s\n", strerror((*__errno_location ())));
     exit(1);
    }
   }
  }
 }
}

variable_types:
commands
char ***

variable_types: struct jobnode { int pid; int running; char **command; struct jobnode *next; } **

variable_types: i int

variable_types: pausetarget int

variable_types: killresult int

return_type: void


resume

decompiled_code:
int __fastcall resume(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax
const char *v4; // rdi
int result; // eax
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // rbx
int *v9; // rax
char *v10; // rax

v3 = *(_QWORD *)(a1 + 8LL * a3);
v4 = *(const char **)(v3 + 8);
if ( !v4 )
return puts("Error: \"resume\" needs one parameter!");
if ( *(_QWORD *)(v3 + 16) )
return puts("Error: \"resume\" has only one parameter!");
v6 = atol(v4);
v7 = findchild(v6, a2);
v8 = v7;
if ( !v7 )
return puts("Error: In \"resume,\" unable to find process!");
if ( *(_DWORD *)(v7 + 4) == 1 )
return puts("Error: Process already running!");
result = kill(v6, 18);
if ( result )
{
if ( result < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
printf("Resume failed: %s\n", v10);
exit(1);
}
}
else
{
*(_DWORD *)(v8 + 4) = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax
const char *v4; // rdi
int result; // eax
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // rbx
int *v9; // rax
char *v10; // rax

v3 = *(_QWORD *)(a1 + 8LL * a3);
v4 = *(const char **)(v3 + 8);
if ( !v4 )
return puts("Error: \"resume\" needs one parameter!");
if ( *(_QWORD *)(v3 + 16) )
return puts("Error: \"resume\" has only one parameter!");
v6 = atol(v4);
v7 = findchild(v6, a2);
v8 = v7;
if ( !v7 )
return puts("Error: In \"resume,\" unable to find process!");
if ( *(_DWORD *)(v7 + 4) == 1 )
return puts("Error: Process already running!");
result = kill(v6, 18);
if ( result )
{
if ( result < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
printf("Resume failed: %s\n", v10);
exit(1);
}
}
else
{
*(_DWORD *)(v8 + 4) = 1;
}
return result;
}

original_code:
void resume(char *** commands, struct jobnode **jobs, int i)
{
 if (commands[i][1] == ((void *)0))
 {
  printf("%s\n", "Error: \"resume\" needs one parameter!");
 }
 else if (commands[i][2] != ((void *)0))
 {
  printf("%s\n", "Error: \"resume\" has only one parameter!");
 }
 else
 {
  int resumetarget = atol(commands[i][1]);
  struct jobnode *resume = findchild(resumetarget, jobs);
  if (resume == ((void *)0))
  {
   printf("%s\n", "Error: In \"resume,\" unable to find process!");
  }
  else
  {
   if (resume->running == 1)
   {
    printf("%s\n", "Error: Process already running!");
   }
   else
   {
    int killresult = kill(resumetarget, 18);
    if (killresult == 0)
    {
     resume->running = 1;
    }
    else if(killresult < 0)
    {
     printf("Resume failed: %s\n", strerror((*__errno_location ())));
     exit(1);
    }
   }
  }
 }
}

canonical_original_code:
void resume(char ***commands, struct jobnode **jobs, int i)
{
 if (commands[i][1] == ((void *)0))
 {
  printf("%s\n", "Error: \"resume\" needs one parameter!");
 }
 else if (commands[i][2] != ((void *)0))
 {
  printf("%s\n", "Error: \"resume\" has only one parameter!");
 }
 else
 {
  int resumetarget = atol(commands[i][1]);
  struct jobnode *resume = findchild(resumetarget, jobs);
  if (resume == ((void *)0))
  {
   printf("%s\n", "Error: In \"resume,\" unable to find process!");
  }
  else
  {
   if (resume->running == 1)
   {
    printf("%s\n", "Error: Process already running!");
   }
   else
   {
    int killresult = kill(resumetarget, 18);
    if (killresult == 0)
    {
     resume->running = 1;
    }
    else if(killresult < 0)
    {
     printf("Resume failed: %s\n", strerror((*__errno_location ())));
     exit(1);
    }
   }
  }
 }
}

variable_types: resumetarget int

variable_types: struct jobnode { int pid; int running; char **command; struct jobnode *next; } *


modefun

decompiled_code:
int __fastcall modefun(__int64 a1, int *a2)
{
int result; // eax
const char *v3; // rbp
size_t v4; // r12

result = *a2;
if ( *a2 != 2 )
{
v3 = *(const char **)(a1 + 8);
if ( v3 )
{
if ( *(_QWORD *)(a1 + 16) )
{
result = fprintf(stderr, "%s\n", "Too many parameters, mode only allows one.");
}
else
{
v4 = strlen(*(const char **)(a1 + 8));
result = strncasecmp("parallel", v3, v4);
if ( result )
{
result = strncasecmp("sequential", v3, v4);
if ( result )
result = fprintf(
stderr,
"%s\n",
"Incorrect mode specified, please only use parallel or sequential. Thank you.");
else
*a2 = 1;
}
else
{
*a2 = 0;
}
}
}
else if ( result )
{
result = puts("sequential mode");
}
else
{
result = puts("parallel mode");
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int *a2)
{
int result; // eax
const char *v3; // rbp
size_t v4; // r12

result = *a2;
if ( *a2 != 2 )
{
v3 = *(const char **)(a1 + 8);
if ( v3 )
{
if ( *(_QWORD *)(a1 + 16) )
{
result = fprintf(stderr, "%s\n", "Too many parameters, mode only allows one.");
}
else
{
v4 = strlen(*(const char **)(a1 + 8));
result = strncasecmp("parallel", v3, v4);
if ( result )
{
result = strncasecmp("sequential", v3, v4);
if ( result )
result = fprintf(
stderr,
"%s\n",
"Incorrect mode specified, please only use parallel or sequential. Thank you.");
else
*a2 = 1;
}
else
{
*a2 = 0;
}
}
}
else if ( result )
{
result = puts("sequential mode");
}
else
{
result = puts("parallel mode");
}
}
return result;
}

original_code:
void modefun(char **commands, int *sequential)
{
 if((*sequential) != 2)
 {
  if(commands[1] == ((void *)0))
  {
   if((*sequential))
   {
    printf("%s\n","sequential mode");
   }
   else
   {
    printf("%s\n", "parallel mode");
   }
  }
  else if(commands[2] == ((void *)0))
  {
   if(strncasecmp("parallel", commands[1], strlen(commands[1])) == 0)
   {
    (*sequential) = 0;
   }
   else if(strncasecmp("sequential",commands[1], strlen(commands[1])) == 0)
   {
    (*sequential) = 1;
   }
   else
   {
    fprintf(stderr, "%s\n", "Incorrect mode specified, please only use parallel or sequential. Thank you.");
   }
  }
  else
  {
   fprintf(stderr, "%s\n", "Too many parameters, mode only allows one.");
  }
 }
}

variable_types:
commands
char **

variable_types:
sequential
int *


runSequential

decompiled_code:
void __fastcall runSequential(const char ***a1, int *a2, _QWORD *a3)
{
const char **v3; // rbx
const char ***v6; // rbp
bool v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
const char *v12; // rsi
int v13; // eax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int stat_loc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = *a1;
if ( *a1 )
{
v6 = a1 + 1;
do
{
if ( !strcmp(*v3, "exit") )
{
if ( v3[1] )
puts("Error: \"exit\" has no parameters!");
else
*a2 = 2;
}
else
{
v7 = strcmp(*v3, "mode") != 0;
v8 = 0;
v9 = !v7;
if ( v7 )
{
v10 = "jobs";
v11 = 5LL;
v12 = *v3;
do
{
if ( !v11 )
break;
v8 = *v12 < (unsigned int)*v10;
v9 = *v12++ == *v10++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
{
if ( v3[1] )
puts("Error: \"jobs\" has no parameters!");
else
jobs_print(*a3, v12, *v3, v11);
}
else
{
v13 = fork();
if ( v13 )
{
if ( v13 <= 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "Fork failed: %s\n", v19);
exit(1);
}
if ( waitpid(v13, stat_loc, 0) == -1 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Wait failed: %s\n", v15);
exit(1);
}
}
else if ( execv(*v3, (char *const *)v3) < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
printf("Execv of \"%s\" failed: %s\n", *v3, v17);
exit(1);
}
}
}
else
{
modefun((__int64)v3, a2);
}
}
v3 = *v6++;
}
while ( v3 );
}
}

canonical_decompiled_code:
void __fastcall func3(const char ***a1, int *a2, _QWORD *a3)
{
const char **v3; // rbx
const char ***v6; // rbp
bool v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
const char *v12; // rsi
int v13; // eax
int *v14; // rax
char *v15; // rax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax
int stat_loc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = *a1;
if ( *a1 )
{
v6 = a1 + 1;
do
{
if ( !strcmp(*v3, "exit") )
{
if ( v3[1] )
puts("Error: \"exit\" has no parameters!");
else
*a2 = 2;
}
else
{
v7 = strcmp(*v3, "mode") != 0;
v8 = 0;
v9 = !v7;
if ( v7 )
{
v10 = "jobs";
v11 = 5LL;
v12 = *v3;
do
{
if ( !v11 )
break;
v8 = *v12 < (unsigned int)*v10;
v9 = *v12++ == *v10++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
{
if ( v3[1] )
puts("Error: \"jobs\" has no parameters!");
else
jobs_print(*a3, v12, *v3, v11);
}
else
{
v13 = fork();
if ( v13 )
{
if ( v13 <= 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "Fork failed: %s\n", v19);
exit(1);
}
if ( waitpid(v13, stat_loc, 0) == -1 )
{
v14 = _errno_location();
v15 = strerror(*v14);
fprintf(stderr, "Wait failed: %s\n", v15);
exit(1);
}
}
else if ( execv(*v3, (char *const *)v3) < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
printf("Execv of \"%s\" failed: %s\n", *v3, v17);
exit(1);
}
}
}
else
{
func2((__int64)v3, a2);
}
}
v3 = *v6++;
}
while ( v3 );
}
}

original_code:
void runSequential(char *** commands, int *sequential, struct jobnode **jobs)
{
 int i = 0;
 while (commands[i] != ((void *)0))
 {
  char **argj = commands[i];
  if (strcmp(commands[i][0], "exit") == 0)
  {
   if (commands[i][1] == ((void *)0))
   {
    (*sequential) = 2;
   }
   else
   {
    printf("%s\n", "Error: \"exit\" has no parameters!");
   }
  }
  else if (strcmp(commands[i][0], "mode") == 0)
  {
   modefun(commands[i], sequential);
  }
  else if (strcmp(commands[i][0], "jobs") == 0)
  {
   if (commands[i][1] == ((void *)0))
   {
    jobs_print(*jobs);
   }
   else
   {
    printf("%s\n", "Error: \"jobs\" has no parameters!");
   }
  }
  else
  {
   pid_t pid = fork();
   int childreturn;
   if (pid == 0)
   {
    if (execv(argj[0], argj) < 0)
       {
     printf("Execv of \"%s\" failed: %s\n", argj[0], strerror((*__errno_location ())));
     exit(1);
    }
   }
   else if (pid > 0)
   {
         int check;
         check = waitpid(pid, &childreturn, 0);
           if (check == -1)
    {
     fprintf(stderr, "Wait failed: %s\n", strerror((*__errno_location ())));
     exit(1);
    }
       }
   else
   {
    fprintf(stderr, "Fork failed: %s\n", strerror((*__errno_location ())));
    exit(1);
   }
  }
  i++;
 }
}

canonical_original_code:
void runSequential(char ***commands, int *sequential, struct jobnode **jobs)
{
 int i = 0;
 while (commands[i] != ((void *)0))
 {
  char **argj = commands[i];
  if (strcmp(commands[i][0], "exit") == 0)
  {
   if (commands[i][1] == ((void *)0))
   {
    (*sequential) = 2;
   }
   else
   {
    printf("%s\n", "Error: \"exit\" has no parameters!");
   }
  }
  else if (strcmp(commands[i][0], "mode") == 0)
  {
   modefun(commands[i], sequential);
  }
  else if (strcmp(commands[i][0], "jobs") == 0)
  {
   if (commands[i][1] == ((void *)0))
   {
    jobs_print(*jobs);
   }
   else
   {
    printf("%s\n", "Error: \"jobs\" has no parameters!");
   }
  }
  else
  {
   int pid = fork();
   int childreturn;
   if (pid == 0)
   {
    if (execv(argj[0], argj) < 0)
       {
     printf("Execv of \"%s\" failed: %s\n", argj[0], strerror((*__errno_location ())));
     exit(1);
    }
   }
   else if (pid > 0)
   {
         int check;
         check = waitpid(pid, &childreturn, 0);
           if (check == -1)
    {
     fprintf(stderr, "Wait failed: %s\n", strerror((*__errno_location ())));
     exit(1);
    }
       }
   else
   {
    fprintf(stderr, "Fork failed: %s\n", strerror((*__errno_location ())));
    exit(1);
   }
  }
  i++;
 }
}

variable_types:
argj
char **

variable_types: pid int

variable_types: childreturn int

variable_types: check int

user_defined_types: struct jobnode { int pid; int running; char **command; struct jobnode *next; }


runParallel

decompiled_code:
void __fastcall runParallel(const char ***a1, int *a2, _QWORD *a3)
{
const char **v3; // rbp
__int64 v7; // rbx
const char *v8; // rdx
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi
__pid_t v15; // eax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax

v3 = *a1;
if ( *a1 )
{
v7 = 0LL;
do
{
v8 = *v3;
if ( !strcmp(*v3, "exit") )
{
if ( v3[1] )
puts("Error: \"exit\" has no parameters!");
else
*a2 = 2;
}
else
{
v9 = strcmp(*v3, "mode") != 0;
v10 = 0;
v11 = !v9;
if ( v9 )
{
v12 = "jobs";
v13 = 5LL;
v14 = *v3;
do
{
if ( !v13 )
break;
v10 = *v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
if ( v3[1] )
puts("Error: \"jobs\" has no parameters!");
jobs_print(*a3, v14, v8, v13);
}
else if ( !strcmp(*v3, "pause") )
{
runpause((__int64)a1, (__int64)a3, v7);
}
else if ( !strcmp(*v3, "resume") )
{
resume((__int64)a1, (__int64)a3, v7);
}
else
{
v15 = fork();
if ( v15 )
{
if ( v15 <= 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "Fork failed: %s\n", v19);
exit(1);
}
jobs_append(a1[v7], (unsigned int)v15, a3);
}
else if ( execv(*v3, (char *const *)v3) < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
printf("Execv of \"%s\" failed: %s\n", *v3, v17);
exit(1);
}
}
}
else
{
modefun((__int64)v3, a2);
}
}
v3 = a1[++v7];
}
while ( v3 );
}
}

canonical_decompiled_code:
void __fastcall func4(const char ***a1, int *a2, _QWORD *a3)
{
const char **v3; // rbp
__int64 v7; // rbx
const char *v8; // rdx
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi
__pid_t v15; // eax
int *v16; // rax
char *v17; // rax
int *v18; // rax
char *v19; // rax

v3 = *a1;
if ( *a1 )
{
v7 = 0LL;
do
{
v8 = *v3;
if ( !strcmp(*v3, "exit") )
{
if ( v3[1] )
puts("Error: \"exit\" has no parameters!");
else
*a2 = 2;
}
else
{
v9 = strcmp(*v3, "mode") != 0;
v10 = 0;
v11 = !v9;
if ( v9 )
{
v12 = "jobs";
v13 = 5LL;
v14 = *v3;
do
{
if ( !v13 )
break;
v10 = *v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
if ( v3[1] )
puts("Error: \"jobs\" has no parameters!");
jobs_print(*a3, v14, v8, v13);
}
else if ( !strcmp(*v3, "pause") )
{
func0((__int64)a1, (__int64)a3, v7);
}
else if ( !strcmp(*v3, "resume") )
{
func1((__int64)a1, (__int64)a3, v7);
}
else
{
v15 = fork();
if ( v15 )
{
if ( v15 <= 0 )
{
v18 = _errno_location();
v19 = strerror(*v18);
fprintf(stderr, "Fork failed: %s\n", v19);
exit(1);
}
jobs_append(a1[v7], (unsigned int)v15, a3);
}
else if ( execv(*v3, (char *const *)v3) < 0 )
{
v16 = _errno_location();
v17 = strerror(*v16);
printf("Execv of \"%s\" failed: %s\n", *v3, v17);
exit(1);
}
}
}
else
{
func2((__int64)v3, a2);
}
}
v3 = a1[++v7];
}
while ( v3 );
}
}

original_code:
void runParallel(char ***commands, int *sequential, struct jobnode **jobs)
{
 int i = 0;
 while(commands[i] != ((void *)0))
 {
  char **argj = commands[i];
  if (strcmp(commands[i][0], "exit") == 0)
  {
   if (commands[i][1] == ((void *)0))
   {
    (*sequential) = 2;
   }
   else
   {
    printf("%s\n", "Error: \"exit\" has no parameters!");
   }
  }
  else if (strcmp(commands[i][0], "mode") == 0)
  {
   modefun(commands[i], sequential);
  }
  else if (strcmp(commands[i][0], "jobs") == 0)
  {
   if (commands[i][1] != ((void *)0))
   {
    printf("%s\n", "Error: \"jobs\" has no parameters!");
   }
    jobs_print(*jobs);
  }
  else if (strcmp(commands[i][0], "pause") == 0)
  {
   runpause(commands,jobs, i);
  }
  else if (strcmp(commands[i][0], "resume") == 0)
  {
   resume(commands, jobs, i);
  }
  else
  {
   pid_t pid1 = fork();
   if (pid1 == 0)
   {
    if (execv(argj[0], argj) < 0)
    {
     printf("Execv of \"%s\" failed: %s\n", argj[0], strerror((*__errno_location ())));
     exit(1);
    }
   }
   else if (pid1 > 0)
   {
    jobs_append(commands[i], pid1, jobs);
   }
   else
   {
    fprintf(stderr, "Fork failed: %s\n", strerror((*__errno_location ())));
    exit(1);
   }
  }
 i++;
 }
}

canonical_original_code:
void runParallel(char ***commands, int *sequential, struct jobnode **jobs)
{
 int i = 0;
 while(commands[i] != ((void *)0))
 {
  char **argj = commands[i];
  if (strcmp(commands[i][0], "exit") == 0)
  {
   if (commands[i][1] == ((void *)0))
   {
    (*sequential) = 2;
   }
   else
   {
    printf("%s\n", "Error: \"exit\" has no parameters!");
   }
  }
  else if (strcmp(commands[i][0], "mode") == 0)
  {
   modefun(commands[i], sequential);
  }
  else if (strcmp(commands[i][0], "jobs") == 0)
  {
   if (commands[i][1] != ((void *)0))
   {
    printf("%s\n", "Error: \"jobs\" has no parameters!");
   }
    jobs_print(*jobs);
  }
  else if (strcmp(commands[i][0], "pause") == 0)
  {
   runpause(commands,jobs, i);
  }
  else if (strcmp(commands[i][0], "resume") == 0)
  {
   resume(commands, jobs, i);
  }
  else
  {
   int pid1 = fork();
   if (pid1 == 0)
   {
    if (execv(argj[0], argj) < 0)
    {
     printf("Execv of \"%s\" failed: %s\n", argj[0], strerror((*__errno_location ())));
     exit(1);
    }
   }
   else if (pid1 > 0)
   {
    jobs_append(commands[i], pid1, jobs);
   }
   else
   {
    fprintf(stderr, "Fork failed: %s\n", strerror((*__errno_location ())));
    exit(1);
   }
  }
 i++;
 }
}


runProcesses

decompiled_code:
void __fastcall runProcesses(const char ***a1, int *a2, _QWORD *a3)
{
if ( *a2 )
runSequential(a1, a2, a3);
else
runParallel(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func5(const char ***a1, int *a2, _QWORD *a3)
{
if ( *a2 )
func3(a1, a2, a3);
else
func4(a1, a2, a3);
}

original_code:
void runProcesses(char *** commands, int *sequential, struct jobnode **jobs)
{
 if((*sequential))
  {
   runSequential(commands, sequential, jobs);
  }
  else
  {
   runParallel(commands, sequential, jobs);
  }
}

canonical_original_code:
void runProcesses(char ***commands, int *sequential, struct jobnode **jobs)
{
 if((*sequential))
  {
   runSequential(commands, sequential, jobs);
  }
  else
  {
   runParallel(commands, sequential, jobs);
  }
}


commandCount

decompiled_code:
__int64 __fastcall commandCount(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int commandCount(char ***commands)
{
 int i = 0;
 while (commands[i] != ((void *)0))
 {
  i++;
 }
 return i;
}

return_type: int


preparellel

decompiled_code:
int __fastcall preparellel(__int64 a1)
{
unsigned int *v2; // rbp
int result; // eax
__pid_t v4; // eax
unsigned int v5; // ebx
int v6; // edi
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
struct pollfd fds; // [rsp+4h] [rbp-24h] BYREF
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

fds.fd = 0;
fds.events = 1;
fds.revents = 0;
while ( 1 )
{
result = poll(&fds, 1uLL, 200);
if ( result )
break;
v4 = waitpid(0, stat_loc, 1);
v5 = v4;
if ( v4 > 0 )
{
v2 = (unsigned int *)findchild((unsigned int)v4, a1);
if ( !v2 )
goto LABEL_6;
printf("%s", "Process ");
printf("%d", *v2);
printf("%s", " (");
jobs_commandprint(*((_QWORD *)v2 + 1), 0LL);
printf("%s", ") ");
puts("completed");
printf("%s", "Shell shell shell:");
if ( fflush(stdout) )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Flush failed: %s\n", v9);
}
if ( !(unsigned int)jobs_delete(v5, a1) )
LABEL_6:
puts("Something went terribly, terribly wrong");
}
else if ( v4 == -1 )
{
v6 = *_errno_location();
if ( v6 != 10 )
{
v7 = strerror(v6);
fprintf(stderr, "Wait failed: %s\n", v7);
}
}
}
if ( result <= 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Poll Failed: %s\n", v11);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int *v2; // rbp
int result; // eax
__pid_t v4; // eax
unsigned int v5; // ebx
int v6; // edi
char *v7; // rax
int *v8; // rax
char *v9; // rax
int *v10; // rax
char *v11; // rax
struct pollfd fds; // [rsp+4h] [rbp-24h] BYREF
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

fds.fd = 0;
fds.events = 1;
fds.revents = 0;
while ( 1 )
{
result = poll(&fds, 1uLL, 200);
if ( result )
break;
v4 = waitpid(0, stat_loc, 1);
v5 = v4;
if ( v4 > 0 )
{
v2 = (unsigned int *)findchild((unsigned int)v4, a1);
if ( !v2 )
goto LABEL_6;
printf("%s", "Process ");
printf("%d", *v2);
printf("%s", " (");
jobs_commandprint(*((_QWORD *)v2 + 1), 0LL);
printf("%s", ") ");
puts("completed");
printf("%s", "Shell shell shell:");
if ( fflush(stdout) )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(stderr, "Flush failed: %s\n", v9);
}
if ( !(unsigned int)jobs_delete(v5, a1) )
LABEL_6:
puts("Something went terribly, terribly wrong");
}
else if ( v4 == -1 )
{
v6 = *_errno_location();
if ( v6 != 10 )
{
v7 = strerror(v6);
fprintf(stderr, "Wait failed: %s\n", v7);
}
}
}
if ( result <= 0 )
{
v10 = _errno_location();
v11 = strerror(*v10);
fprintf(stderr, "Poll Failed: %s\n", v11);
exit(1);
}
return result;
}

original_code:
void preparellel(struct jobnode **jobs)
{
 int check = 0;
 int rv = 0;
 int childreturn;
 struct pollfd pfd;
 pfd.fd = 0;
 pfd.events = 0x001;
 pfd.revents = 0;
 while (1)
 {
  rv = poll(&pfd, 1, 200);
  if (rv == 0)
  {
   check = waitpid(0, &childreturn, 1);
   if (check > 0)
    {
     struct jobnode* child = findchild(check, jobs);
     if (child != ((void *)0))
     {
      printf("%s", "Process ");
      printf("%d", child->pid);
      printf("%s", " (");
      jobs_commandprint(child->command, 0);
      printf("%s", ") ");
      printf("%s\n", "completed");
      printf("%s", "Shell shell shell:");
      int flush = fflush(stdout);
      if (flush)
      {
       fprintf(stderr, "Flush failed: %s\n", strerror((*__errno_location ())));
      }
      int delete = jobs_delete(check, jobs);
      if(!delete)
      {
       printf("%s\n", "Something went terribly, terribly wrong");
      }
     }
     else
     {
      printf("%s\n", "Something went terribly, terribly wrong");
     }
    }
   else if (check == -1)
   {
    if ((*__errno_location ()) != 10)
    {
     fprintf(stderr, "Wait failed: %s\n", strerror((*__errno_location ())));
    }
   }
  }
  else if (rv > 0)
  {
   break;
  }
  else
  {
   fprintf(stderr, "Poll Failed: %s\n", strerror((*__errno_location ())));
   exit(1);
  }
 }
}

canonical_original_code:
void preparellel(struct jobnode **jobs)
{
 int check = 0;
 int rv = 0;
 int childreturn;
 struct pollfd pfd;
 pfd.fd = 0;
 pfd.events = 0x001;
 pfd.revents = 0;
 while (1)
 {
  rv = poll(&pfd, 1, 200);
  if (rv == 0)
  {
   check = waitpid(0, &childreturn, 1);
   if (check > 0)
    {
     struct jobnode *child = findchild(check, jobs);
     if (child != ((void *)0))
     {
      printf("%s", "Process ");
      printf("%d", child->pid);
      printf("%s", " (");
      jobs_commandprint(child->command, 0);
      printf("%s", ") ");
      printf("%s\n", "completed");
      printf("%s", "Shell shell shell:");
      int flush = fflush(stdout);
      if (flush)
      {
       fprintf(stderr, "Flush failed: %s\n", strerror((*__errno_location ())));
      }
      int delete = jobs_delete(check, jobs);
      if(!delete)
      {
       printf("%s\n", "Something went terribly, terribly wrong");
      }
     }
     else
     {
      printf("%s\n", "Something went terribly, terribly wrong");
     }
    }
   else if (check == -1)
   {
    if ((*__errno_location ()) != 10)
    {
     fprintf(stderr, "Wait failed: %s\n", strerror((*__errno_location ())));
    }
   }
  }
  else if (rv > 0)
  {
   break;
  }
  else
  {
   fprintf(stderr, "Poll Failed: %s\n", strerror((*__errno_location ())));
   exit(1);
  }
 }
}

variable_types: rv int

variable_types: struct pollfd { int fd; short events; short revents; }

variable_types: flush int

variable_types: delete int


original_code:
void jobs_append(char **newcommand, pid_t newpid, struct jobnode **head) {
 if (newcommand == ((void *)0))
 {
  return;
 }
 struct jobnode *newnode = (struct jobnode*) malloc(sizeof(struct jobnode));
 if(newnode==((void *)0))
 {
  printf("%s\n", "Malloc Fails: Exiting Now!");
  exit(1);
 }
 int count =0;
 while(newcommand[count]!= ((void *)0))
 {
  count++;
 }
 (newnode->command) = (char **) malloc(sizeof(char**)*(count+1));
 char **temp = newnode->command;
 int x = 0;
 while(newcommand[x] != ((void *)0))
 {
  temp[x] = strdup(newcommand[x]);
  if (temp[x] == ((void *)0))
  {
   printf("Strdup Fails: %s\n", strerror((*__errno_location ())));
   exit(1);
  }
  x++;
 }
 temp[x] = ((void *)0);
 newnode->pid = newpid;
 newnode->running = 1;
 newnode->next = ((void *)0);
  while((*head) != ((void *)0))
        {
  head = &((*head)->next);
 }
 (*head)=newnode;
}

canonical_original_code:
void jobs_append(char **newcommand, int newpid, struct jobnode **head) {
 if (newcommand == ((void *)0))
 {
  return;
 }
 struct jobnode *newnode = (struct jobnode*) malloc(sizeof(struct jobnode));
 if(newnode==((void *)0))
 {
  printf("%s\n", "Malloc Fails: Exiting Now!");
  exit(1);
 }
 int count = 0;
 while(newcommand[count]!= ((void *)0))
 {
  count++;
 }
 (newnode->command) = (char **) malloc(sizeof(char **)*(count+1));
 char **temp = newnode->command;
 int x = 0;
 while(newcommand[x] != ((void *)0))
 {
  temp[x] = strdup(newcommand[x]);
  if (temp[x] == ((void *)0))
  {
   printf("Strdup Fails: %s\n", strerror((*__errno_location ())));
   exit(1);
  }
  x++;
 }
 temp[x] = ((void *)0);
 newnode->pid = newpid;
 newnode->running = 1;
 newnode->next = ((void *)0);
  while((*head) != ((void *)0))
        {
  head = &((*head)->next);
 }
 (*head)=newnode;
}

variable_types:
newcommand
char **

variable_types: newpid int

variable_types: count int

variable_types:
temp
char **

variable_types: x int


decompiled_code:
__int64 __fastcall jobs_delete(int a1, void **a2)
{
char *v2; // rbx

v2 = (char *)*a2;
if ( !*a2 )
return 0LL;
while ( *(_DWORD *)v2 != a1 )
{
a2 = (void **)(v2 + 16);
v2 = (char *)*((_QWORD *)v2 + 2);
if ( !v2 )
return 0LL;
}
*a2 = (void *)*((_QWORD *)v2 + 2);
freeToken(*((_QWORD *)v2 + 1));
free(v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, void **a2)
{
char *v2; // rbx

v2 = (char *)*a2;
if ( !*a2 )
return 0LL;
while ( *(_DWORD *)v2 != a1 )
{
a2 = (void **)(v2 + 16);
v2 = (char *)*((_QWORD *)v2 + 2);
if ( !v2 )
return 0LL;
}
*a2 = (void *)*((_QWORD *)v2 + 2);
freeToken(*((_QWORD *)v2 + 1));
free(v2);
return 1LL;
}

original_code:
int jobs_delete(pid_t target, struct jobnode **head) {
 while((*head) != ((void *)0))
        {
  if((*head)->pid== target)
         {
   struct jobnode *temp = (*head);
   (*head) = (*head)->next;
   freeToken(temp->command);
   free(temp);
   return 1;
                }
  head = &((*head)->next);
        }
 return 0;
}

canonical_original_code:
int jobs_delete(int target, struct jobnode **head) {
 while((*head) != ((void *)0))
        {
  if((*head)->pid== target)
         {
   struct jobnode *temp = (*head);
   (*head) = (*head)->next;
   freeToken(temp->command);
   free(temp);
   return 1;
                }
  head = &((*head)->next);
        }
 return 0;
}

variable_types: target int

variable_types: struct jobnode { int pid; int running; char **command; struct jobnode *next; } **


findchild

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

for ( result = *a2; result; result = *(_QWORD *)(result + 16) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = *a2; result; result = *(_QWORD *)(result + 16) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
struct jobnode *findchild(pid_t target, struct jobnode **head)
{
 struct jobnode *temp = *head;
 while (temp != ((void *)0))
 {
  if (temp->pid == target)
  {
   return temp;
  }
  temp = temp->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct jobnode *findchild(int target, struct jobnode **head)
{
 struct jobnode *temp = *head;
 while (temp != ((void *)0))
 {
  if (temp->pid == target)
  {
   return temp;
  }
  temp = temp->next;
 }
 return ((void *)0);
}

variable_types:
head
struct jobnode **

variable_types: struct jobnode { int pid; int running; char **command; struct jobnode *next; } *


decompiled_code:
void __fastcall jobs_clear(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[2];
freeToken(v2[1]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

v1 = ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[2];
freeToken(v2[1]);
free(v2);
}
while ( v1 );
}
}

original_code:
void jobs_clear(struct jobnode *list)
{
 while(list != ((void *)0))
  {
   struct jobnode *temp = list;
   list = list->next;
   freeToken(temp->command);
   free(temp);
  }
}


decompiled_code:
int __fastcall jobs_commandprint(const char **a1, int a2)
{
int result; // eax
const char *v4; // rsi
const char **v5; // rbx

if ( !a1 )
return puts("Something went terribly, terribly wrong");
if ( *a1 )
{
result = printf("%s", *a1);
v4 = a1[1];
if ( v4 )
{
v5 = a1 + 2;
do
{
result = printf(" %s", v4);
v4 = *v5++;
}
while ( v4 );
}
}
if ( a2 )
result = puts(&byte_34E);
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char **a1, int a2)
{
int result; // eax
const char *v4; // rsi
const char **v5; // rbx

if ( !a1 )
return puts("Something went terribly, terribly wrong");
if ( *a1 )
{
result = printf("%s", *a1);
v4 = a1[1];
if ( v4 )
{
v5 = a1 + 2;
do
{
result = printf(" %s", v4);
v4 = *v5++;
}
while ( v4 );
}
}
if ( a2 )
result = puts(&byte_34E);
return result;
}

original_code:
void jobs_commandprint(char **commands, int newline)
{
 int x =0;
 if(commands==((void *)0))
 {
  printf("%s\n", "Something went terribly, terribly wrong");
  return;
 }
 if(commands[x]!=((void *)0))
 {
  printf("%s",commands[x]);
  x++;
 }
 while (commands[x]!=((void *)0))
 {
  printf(" %s", commands[x]);
  x++;
 }
 if (newline)
 {
  printf("%s\n", "");
 }
}

canonical_original_code:
void jobs_commandprint(char **commands, int newline)
{
 int x = 0;
 if(commands==((void *)0))
 {
  printf("%s\n", "Something went terribly, terribly wrong");
  return;
 }
 if(commands[x]!=((void *)0))
 {
  printf("%s",commands[x]);
  x++;
 }
 while (commands[x]!=((void *)0))
 {
  printf(" %s", commands[x]);
  x++;
 }
 if (newline)
 {
  printf("%s\n", "");
 }
}

variable_types:
commands
char **

variable_types: newline int


decompiled_code:
int __fastcall jobs_print(const char ***a1)
{
const char ***v1; // rbx
int result; // eax
int *v3; // rax
char *v4; // rax

if ( !a1 )
return puts("\nNo processes currently running");
v1 = a1;
puts(&byte_34E);
puts("\tProcess Id\tState\t\tCommand");
do
{
printf("%s\t", &byte_34E);
printf("%d", *(unsigned int *)v1);
printf("%s\t\t", &byte_34E);
if ( *((_DWORD *)v1 + 1) )
printf("%s", "Running\t\t");
else
printf("%s", "Paused\t\t");
jobs_commandprint(v1[1], 1);
result = fflush(stdout);
if ( result )
{
v3 = _errno_location();
v4 = strerror(*v3);
result = fprintf(stderr, "Flush failed: %s\n", v4);
}
v1 = (const char ***)v1[2];
}
while ( v1 );
return result;
}

canonical_decompiled_code:
int __fastcall func5(const char ***a1)
{
const char ***v1; // rbx
int result; // eax
int *v3; // rax
char *v4; // rax

if ( !a1 )
return puts("\nNo processes currently running");
v1 = a1;
puts(&byte_34E);
puts("\tProcess Id\tState\t\tCommand");
do
{
printf("%s\t", &byte_34E);
printf("%d", *(unsigned int *)v1);
printf("%s\t\t", &byte_34E);
if ( *((_DWORD *)v1 + 1) )
printf("%s", "Running\t\t");
else
printf("%s", "Paused\t\t");
func4(v1[1], 1);
result = fflush(stdout);
if ( result )
{
v3 = _errno_location();
v4 = strerror(*v3);
result = fprintf(stderr, "Flush failed: %s\n", v4);
}
v1 = (const char ***)v1[2];
}
while ( v1 );
return result;
}

original_code:
void jobs_print(const struct jobnode *head) {
 if (head == ((void *)0))
 {
  printf("%s\n", "\nNo processes currently running");
  return;
 }
 printf("%s\n","");
 printf("%s\n", "\tProcess Id\tState\t\tCommand");
 while(head != ((void *)0))
        {
  printf("%s\t", "");
                printf("%d", head->pid);
  printf("%s\t\t", "");
  if (head->running)
  {
   printf("%s", "Running\t\t");
  }
  else
  {
   printf("%s", "Paused\t\t");
  }
               jobs_commandprint(head->command, 1);
  int flush = fflush(stdout);
  if (flush)
  {
   fprintf(stderr, "Flush failed: %s\n", strerror((*__errno_location ())));
  }
                head = head->next;
        }
}

canonical_original_code:
void jobs_print(struct jobnode *head) {
 if (head == ((void *)0))
 {
  printf("%s\n", "\nNo processes currently running");
  return;
 }
 printf("%s\n","");
 printf("%s\n", "\tProcess Id\tState\t\tCommand");
 while(head != ((void *)0))
        {
  printf("%s\t", "");
                printf("%d", head->pid);
  printf("%s\t\t", "");
  if (head->running)
  {
   printf("%s", "Running\t\t");
  }
  else
  {
   printf("%s", "Paused\t\t");
  }
               jobs_commandprint(head->command, 1);
  int flush = fflush(stdout);
  if (flush)
  {
   fprintf(stderr, "Flush failed: %s\n", strerror((*__errno_location ())));
  }
                head = head->next;
        }
}


decompiled_code:
void __fastcall paths_append(char *src, char **a2)
{
char **v2; // rbx
char *v3; // rax
char *v4; // rbp
char *v5; // rax
char *v6; // rsi

if ( src )
{
v2 = a2;
v3 = (char *)malloc(0x88uLL);
v4 = v3;
if ( !v3 )
{
puts("Malloc Fails: Exiting Now!");
exit(1);
}
strncpy(v3, src, 0x7FuLL);
*((_QWORD *)v4 + 16) = 0LL;
v5 = *a2;
if ( *a2 )
{
do
{
v6 = v5;
v5 = (char *)*((_QWORD *)v5 + 16);
}
while ( v5 );
v2 = (char **)(v6 + 128);
}
*v2 = v4;
}
}

canonical_decompiled_code:
void __fastcall func0(char *src, char **a2)
{
char **v2; // rbx
char *v3; // rax
char *v4; // rbp
char *v5; // rax
char *v6; // rsi

if ( src )
{
v2 = a2;
v3 = (char *)malloc(0x88uLL);
v4 = v3;
if ( !v3 )
{
puts("Malloc Fails: Exiting Now!");
exit(1);
}
strncpy(v3, src, 0x7FuLL);
*((_QWORD *)v4 + 16) = 0LL;
v5 = *a2;
if ( *a2 )
{
do
{
v6 = v5;
v5 = (char *)*((_QWORD *)v5 + 16);
}
while ( v5 );
v2 = (char **)(v6 + 128);
}
*v2 = v4;
}
}

original_code:
void paths_append(const char *name, struct node **head) {
 if (name == ((void *)0))
 {
  return;
 }
 struct node *newnode = (struct node*) malloc(sizeof(struct node));
 if(newnode==((void *)0))
 {
  printf("%s\n", "Malloc Fails: Exiting Now!");
  exit(1);
 }
 strncpy((newnode->name), name, 127);
 newnode->next = ((void *)0);
  while((*head) != ((void *)0))
        {
         head = &((*head)->next);
 }
 (*head)=newnode;
}

canonical_original_code:
void paths_append(char *name, struct node **head) {
 if (name == ((void *)0))
 {
  return;
 }
 struct node *newnode = (struct node*) malloc(sizeof(struct node));
 if(newnode==((void *)0))
 {
  printf("%s\n", "Malloc Fails: Exiting Now!");
  exit(1);
 }
 strncpy((newnode->name), name, 127);
 newnode->next = ((void *)0);
  while((*head) != ((void *)0))
        {
         head = &((*head)->next);
 }
 (*head)=newnode;
}

variable_types:
name
char *

variable_types: struct node { char name[128]; struct node *next; } **


decompiled_code:
int __fastcall paths_print(const char *a1)
{
const char *i; // rbx
int result; // eax

for ( i = a1; i; i = (const char *)*((_QWORD *)i + 16) )
result = printf("Node at address %p has value %s\n", i, i);
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
const char *i; // rbx
int result; // eax

for ( i = a1; i; i = (const char *)*((_QWORD *)i + 16) )
result = printf("Node at address %p has value %s\n", i, i);
return result;
}

original_code:
void paths_print(const struct node *head) {
        while(head != ((void *)0))
        {
                printf("Node at address %p has value %s\n", head, head->name);
                head = head->next;
        }
}

canonical_original_code:
void paths_print(struct node *head) {
        while(head != ((void *)0))
        {
                printf("Node at address %p has value %s\n", head, head->name);
                head = head->next;
        }
}

variable_types: struct node { char name[128]; struct node *next; } *


decompiled_code:
void __fastcall paths_clear(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 16);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 16);
free(v2);
}
}

original_code:
void paths_clear(struct node *list)
{
 while(list != ((void *)0))
  {
   struct node *temp = list;
   list = list->next;
   free(temp);
  }
}

user_defined_types: struct node { char name[128]; struct node *next; }


readn

repo: jleverenz/cvsps-esr

decompiled_code:
__int64 __fastcall readn(int fd, void *buf, __int64 a3)
{
int v5; // er15
int v6; // ebx
int v7; // eax
int v8; // er14

if ( (int)a3 > 0 )
{
v5 = a3;
v6 = a3;
while ( 1 )
{
v7 = read(fd, buf, v6);
v8 = v7;
if ( v7 < 0 )
{
if ( *_errno_location() != 4 || v5 == v6 )
return v8;
}
else
{
if ( !v7 )
return a3 - v6;
v6 -= v7;
if ( !v6 )
return a3 - v6;
buf = (char *)buf + v7;
}
if ( v6 <= 0 )
return a3 - v6;
}
}
v6 = a3;
return a3 - v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void *buf, __int64 a3)
{
int v5; // er15
int v6; // ebx
int v7; // eax
int v8; // er14

if ( (int)a3 > 0 )
{
v5 = a3;
v6 = a3;
while ( 1 )
{
v7 = read(fd, buf, v6);
v8 = v7;
if ( v7 < 0 )
{
if ( *_errno_location() != 4 || v5 == v6 )
return v8;
}
else
{
if ( !v7 )
return a3 - v6;
v6 -= v7;
if ( !v6 )
return a3 - v6;
buf = (char *)buf + v7;
}
if ( v6 <= 0 )
return a3 - v6;
}
}
v6 = a3;
return a3 - v6;
}

original_code:
ssize_t readn(int fd, void *buf, size_t len)
{
  int nleft,nread;
  nleft = len;
  while (nleft > 0)
  {
    nread = read(fd,buf,nleft);
    if (nread < 0)
    {
      if ((*__errno_location ()) == 4 && nleft != (int)len)
        continue;
      else
     return (nread);
    }
    else if (nread == 0)
      break;
    nleft -= nread;
    if (nleft)
      buf = ((char *)buf) + nread;
  }
  return (len - nleft);
}

canonical_original_code:
long readn(int fd, void *buf, unsigned long len)
{
  int nleft; int nread;
  nleft = len;
  while (nleft > 0)
  {
    nread = read(fd,buf,nleft);
    if (nread < 0)
    {
      if ((*__errno_location ()) == 4 && nleft != (int)len)
        continue;
      else
     return (nread);
    }
    else if (nread == 0)
      break;
    nleft -= nread;
    if (nleft)
      buf = ((char *)buf) + nread;
  }
  return (len - nleft);
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types: nleft int

variable_types: nread int

return_type: long


writen

decompiled_code:
__int64 __fastcall writen(int fd, void *buf, __int64 a3)
{
int v5; // er15
int v6; // ebx
int v8; // eax
int v9; // er13

if ( (int)a3 > 0 )
{
v5 = a3;
v6 = a3;
while ( 1 )
{
v8 = write(fd, buf, v6);
v9 = v8;
if ( v8 < 0 )
{
if ( *_errno_location() != 4 )
return v9;
if ( v5 == v6 )
return v9;
}
else
{
if ( !v8 )
return v9;
v6 -= v8;
if ( !v6 )
return a3 - v6;
buf = (char *)buf + v8;
}
if ( v6 <= 0 )
return a3 - v6;
}
}
v6 = a3;
return a3 - v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *buf, __int64 a3)
{
int v5; // er15
int v6; // ebx
int v8; // eax
int v9; // er13

if ( (int)a3 > 0 )
{
v5 = a3;
v6 = a3;
while ( 1 )
{
v8 = write(fd, buf, v6);
v9 = v8;
if ( v8 < 0 )
{
if ( *_errno_location() != 4 )
return v9;
if ( v5 == v6 )
return v9;
}
else
{
if ( !v8 )
return v9;
v6 -= v8;
if ( !v6 )
return a3 - v6;
buf = (char *)buf + v8;
}
if ( v6 <= 0 )
return a3 - v6;
}
}
v6 = a3;
return a3 - v6;
}

original_code:
ssize_t writen(int fd, const void *buf, size_t len)
{
  int nleft, nwritten;
  nleft = len;
  while (nleft > 0)
  {
    nwritten = write(fd,buf,nleft);
    if (nwritten < 0 && (*__errno_location ()) == 4)
    {
      if (nleft == (int)len)
 return nwritten;
      continue;
    }
    if (nwritten <= 0)
      return nwritten;
    nleft -= nwritten;
    if (nleft)
      buf = ((char *)buf) + nwritten;
  }
  return (len - nleft);
}

canonical_original_code:
long writen(int fd, void *buf, unsigned long len)
{
  int nleft; int nwritten;
  nleft = len;
  while (nleft > 0)
  {
    nwritten = write(fd,buf,nleft);
    if (nwritten < 0 && (*__errno_location ()) == 4)
    {
      if (nleft == (int)len)
 return nwritten;
      continue;
    }
    if (nwritten <= 0)
      return nwritten;
    nleft -= nwritten;
    if (nleft)
      buf = ((char *)buf) + nwritten;
  }
  return (len - nleft);
}

variable_types: nwritten int


hexdump

decompiled_code:
void hexdump(unsigned __int8 *a1, int a2, const char *a3, ...)
{
unsigned __int8 *v3; // rbp
int v4; // ebx
const unsigned __int16 **v5; // rdx
char v6; // al
__int64 v7; // rax
_DWORD *v8; // rdx
int v9; // ecx
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

v3 = a1;
if ( (debuglvl & 0x20) != 0 )
{
va_start(va, a3);
vdebug(0x20u, a3, va);
hexbuff_1 = 0LL;
qword_6C8 = 0LL;
qword_6D0 = 0LL;
qword_6D8 = 0LL;
qword_6E0 = 0LL;
qword_6E8 = 0LL;
byte_6F0 = 0;
printbuff_0 = 0LL;
qword_698 = 0LL;
byte_6A0 = 0;
if ( a2 )
{
v4 = 0;
do
{
sprintf((char *)&hexbuff_1 + 3 * v4, "%02x ", *v3);
v5 = _ctype_b_loc();
v6 = *v3;
if ( ((*v5)[(char)*v3] & 0x4000) == 0 )
v6 = 46;
*((_BYTE *)&printbuff_0 + v4) = v6;
++v3;
if ( v4 == 15 )
{
debug(0x20u, "%s %s", (const char *)&hexbuff_1, (const char *)&printbuff_0);
hexbuff_1 = 0LL;
qword_6C8 = 0LL;
qword_6D0 = 0LL;
qword_6D8 = 0LL;
qword_6E0 = 0LL;
qword_6E8 = 0LL;
byte_6F0 = 0;
printbuff_0 = 0LL;
qword_698 = 0LL;
byte_6A0 = 0;
v4 = 0;
}
else
{
++v4;
}
}
while ( v3 != &a1[a2] );
if ( v4 > 0 )
{
if ( (v4 & 0xF) != 0 )
{
v7 = v4 + 1;
v8 = (_DWORD *)((char *)&hexbuff_1 + 3 * v4);
do
{
*v8 = 2127992;
byte_68F[v7] = 46;
v9 = v7++ & 0xF;
v8 = (_DWORD *)((char *)v8 + 3);
}
while ( v9 );
}
debug(0x20u, "%s %s", (const char *)&hexbuff_1, (const char *)&printbuff_0);
}
}
}
}

canonical_decompiled_code:
void func3(unsigned __int8 *a1, int a2, const char *a3, ...)
{
unsigned __int8 *v3; // rbp
int v4; // ebx
const unsigned __int16 **v5; // rdx
char v6; // al
__int64 v7; // rax
_DWORD *v8; // rdx
int v9; // ecx
gcc_va_list va; // [rsp+8h] [rbp-F0h] BYREF

v3 = a1;
if ( (debuglvl & 0x20) != 0 )
{
va_start(va, a3);
func0(0x20u, a3, va);
hexbuff_1 = 0LL;
qword_6C8 = 0LL;
qword_6D0 = 0LL;
qword_6D8 = 0LL;
qword_6E0 = 0LL;
qword_6E8 = 0LL;
byte_6F0 = 0;
printbuff_0 = 0LL;
qword_698 = 0LL;
byte_6A0 = 0;
if ( a2 )
{
v4 = 0;
do
{
sprintf((char *)&hexbuff_1 + 3 * v4, "%02x ", *v3);
v5 = _ctype_b_loc();
v6 = *v3;
if ( ((*v5)[(char)*v3] & 0x4000) == 0 )
v6 = 46;
*((_BYTE *)&printbuff_0 + v4) = v6;
++v3;
if ( v4 == 15 )
{
func1(0x20u, "%s %s", (const char *)&hexbuff_1, (const char *)&printbuff_0);
hexbuff_1 = 0LL;
qword_6C8 = 0LL;
qword_6D0 = 0LL;
qword_6D8 = 0LL;
qword_6E0 = 0LL;
qword_6E8 = 0LL;
byte_6F0 = 0;
printbuff_0 = 0LL;
qword_698 = 0LL;
byte_6A0 = 0;
v4 = 0;
}
else
{
++v4;
}
}
while ( v3 != &a1[a2] );
if ( v4 > 0 )
{
if ( (v4 & 0xF) != 0 )
{
v7 = v4 + 1;
v8 = (_DWORD *)((char *)&hexbuff_1 + 3 * v4);
do
{
*v8 = 2127992;
byte_68F[v7] = 46;
v9 = v7++ & 0xF;
v8 = (_DWORD *)((char *)v8 + 3);
}
while ( v9 );
}
func1(0x20u, "%s %s", (const char *)&hexbuff_1, (const char *)&printbuff_0);
}
}
}
}

original_code:
void hexdump(const char *ptr, int size, const char *fmt, ...)
{
    static char hexbuff[49];
    static char printbuff[17];
    int count = 0;
    va_list ap;
    if (!(debuglvl & 0x0020))
 return;
    __builtin_va_start(ap,fmt);
    vdebug(0x0020, fmt, ap);
    memset(hexbuff, 0, 49);
    memset(printbuff, 0, 17);
    while (size--)
    {
 sprintf(hexbuff + (count*3), "%02x ", (int)*((unsigned char *)ptr));
 if (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short int) _ISprint))
     printbuff[count] = *ptr;
 else
     printbuff[count] = '.';
 ptr++;
 if ( count++ == 15 )
 {
     count = 0;
     debug(0x0020, "%s %s", hexbuff, printbuff);
     memset(hexbuff, 0, 49);
     memset(printbuff, 0, 17);
 }
    }
    if ( count > 0 ) {
 while ( count % 16 != 0 ) {
     sprintf(hexbuff + (count * 3), "xx ");
     printbuff[count++] = '.';
 }
 debug(0x0020, "%s %s", hexbuff, printbuff);
    }
    __builtin_va_end(ap);
}

canonical_original_code:
void hexdump(char *ptr, int size, char *fmt, ...)
{
    static char hexbuff[49];
    static char printbuff[17];
    int count = 0;
    __builtin_va_list ap;
    if (!(debuglvl & 0x0020))
 return;
    __builtin_va_start(ap,fmt);
    vdebug(0x0020, fmt, ap);
    memset(hexbuff, 0, 49);
    memset(printbuff, 0, 17);
    while (size--)
    {
 sprintf(hexbuff + (count*3), "%02x ", (int)*((unsigned char *)ptr));
 if (((*__ctype_b_loc ())[(int) ((*ptr))] & (unsigned short) _ISprint))
     printbuff[count] = *ptr;
 else
     printbuff[count] = '.';
 ptr++;
 if ( count++ == 15 )
 {
     count = 0;
     debug(0x0020, "%s %s", hexbuff, printbuff);
     memset(hexbuff, 0, 49);
     memset(printbuff, 0, 17);
 }
    }
    if ( count > 0 ) {
 while ( count % 16 != 0 ) {
     sprintf(hexbuff + (count * 3), "xx ");
     printbuff[count++] = '.';
 }
 debug(0x0020, "%s %s", hexbuff, printbuff);
    }
    __builtin_va_end(ap);
}

variable_types:
ptr
char *

variable_types: size int

variable_types:
fmt
char *

variable_types:
hexbuff
char [49]

variable_types:
printbuff
char [17]

variable_types: count int


decompiled_code:
int __fastcall to_hex(char *s, unsigned __int8 *a2, __int64 a3)
{
char *v3; // rbx
char *v5; // r12
int result; // eax

v3 = s;
if ( a3 )
{
v5 = &s[3 * a3];
do
{
result = sprintf(v3, "%02x ", *a2);
v3 += 3;
++a2;
}
while ( v5 != v3 );
}
else
{
v5 = s;
}
*v5 = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func4(char *s, unsigned __int8 *a2, __int64 a3)
{
char *v3; // rbx
char *v5; // r12
int result; // eax

v3 = s;
if ( a3 )
{
v5 = &s[3 * a3];
do
{
result = sprintf(v3, "%02x ", *a2);
v3 += 3;
++a2;
}
while ( v5 != v3 );
}
else
{
v5 = s;
}
*v5 = 0;
return result;
}

original_code:
void
to_hex( char* dest, const char* src, size_t n )
{
    while ( n-- )
    {
 sprintf( dest, "%02x ", (int)*((unsigned char *)src));
 dest += 3;
 src++;
    }
    *dest = 0;
}

canonical_original_code:
void to_hex(char *dest, char *src, unsigned long n)
{
    while ( n-- )
    {
 sprintf( dest, "%02x ", (int)*((unsigned char *)src));
 dest += 3;
 src++;
    }
    *dest = 0;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall hash_string(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
{
++a1;
result = (unsigned int)(v1 + 37 * result);
v1 = *a1;
}
while ( *a1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1)
{
char v1; // dl
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 0LL;
LODWORD(result) = 0;
do
{
++a1;
result = (unsigned int)(v1 + 37 * result);
v1 = *a1;
}
while ( *a1 );
return result;
}

original_code:
static unsigned int hash_string(register const char *key)
{
    register unsigned int hash = 0;
    while(*key)
 hash = hash * 37 + *key++;
    return hash;
}

canonical_original_code:
static unsigned int hash_string(char *key)
{
    register unsigned int hash = 0;
    while(*key)
 hash = hash * 37 + *key++;
    return hash;
}

variable_types:
key
char *

variable_types:
hash
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall reset_hash_iterator(__int64 a1)
{
*(_DWORD *)(a1 + 16) = 0;
*(_QWORD *)(a1 + 24) = 0LL;
}

original_code:
void reset_hash_iterator(struct hash_table *tbl)
{
    tbl->iterator = 0;
    tbl->iterator_ptr = ((void *)0);
}

variable_types: struct hash_table { int ht_size; struct list_head { struct list_head *next; } *ht_lists; int iterator; struct list_head *iterator_ptr; } *

user_defined_types: struct hash_table { int ht_size; struct list_head *ht_lists; int iterator; struct list_head *iterator_ptr; }


decompiled_code:
__int64 __fastcall put_hash_object_ex(__int64 a1, char *a2, __int64 a3, int a4, _QWORD *a5, _QWORD *a6)
{
__int64 *v10; // rbx
_QWORD *v11; // rax
size_t v13; // rax
char *v14; // rax
char *v15; // r12
char *v16; // rax

v10 = (__int64 *)(*(_QWORD *)(a1 + 8) + 16LL * ((unsigned int)hash_string(a2) % *(_DWORD *)a1));
v11 = scan_list((_QWORD **)v10, a2);
if ( !v11 )
{
if ( a5 )
*a5 = 0LL;
if ( a6 )
*a6 = 0LL;
if ( a4 )
{
v13 = strlen(a2);
v14 = (char *)malloc(v13 + 33);
v15 = v14;
if ( v14 )
{
*(_QWORD *)v14 = v14 + 32;
strcpy(v14 + 32, a2);
LABEL_19:
*((_QWORD *)v15 + 1) = a3;
list_add((_QWORD *)v15 + 2, v10);
return 0LL;
}
}
else
{
v16 = (char *)malloc(0x20uLL);
v15 = v16;
if ( v16 )
{
*(_QWORD *)v16 = a2;
goto LABEL_19;
}
}
debug(2LL, (__int64)"malloc failed put_hash_object key='%s'", a2);
return 0xFFFFFFFFLL;
}
if ( a5 )
*a5 = *v11;
if ( a6 )
*a6 = v11[1];
if ( !a4 )
*v11 = a2;
v11[1] = a3;
return 0LL;
}

original_code:
int put_hash_object_ex(struct hash_table *tbl, const char *key, void *obj, int copy,
         char ** oldkey, void ** oldobj)
{
    struct list_head *head;
    struct hash_entry *entry;
    unsigned int hash;
    int retval = 0;
    hash = hash_string(key) % tbl->ht_size;
    head = &tbl->ht_lists[hash];
    entry = scan_list(head, key);
    if (entry)
    {
 if (oldkey)
     *oldkey = entry->he_key;
 if (oldobj)
     *oldobj = entry->he_obj;
 if (!copy)
     entry->he_key = (char*)key;
 entry->he_obj = obj;
    }
    else
    {
 size_t s = sizeof(*entry);
 if (oldkey)
     *oldkey = ((void *)0);
 if (oldobj)
     *oldobj = ((void *)0);
 if (copy)
     s += strlen(key) + 1;
 entry = (struct hash_entry *)malloc(s);
 if (!entry)
 {
     debug(0x0002,"malloc failed put_hash_object key='%s'",key);
     retval = -1;
 }
 else
 {
     if (copy)
     {
  entry->he_key = (char *)(entry + 1);
  strcpy(entry->he_key, key);
     }
     else
     {
  entry->he_key = (char*)key;
     }
     entry->he_obj = obj;
     list_add(&entry->he_list, head);
 }
    }
    return retval;
}

canonical_original_code:
int put_hash_object_ex(struct hash_table *tbl, char *key, void *obj, int copy, char **oldkey, void **oldobj)
{
    struct list_head *head;
    struct hash_entry *entry;
    unsigned int hash;
    int retval = 0;
    hash = hash_string(key) % tbl->ht_size;
    head = &tbl->ht_lists[hash];
    entry = scan_list(head, key);
    if (entry)
    {
 if (oldkey)
     *oldkey = entry->he_key;
 if (oldobj)
     *oldobj = entry->he_obj;
 if (!copy)
     entry->he_key = (char *)key;
 entry->he_obj = obj;
    }
    else
    {
 unsigned long s = sizeof(*entry);
 if (oldkey)
     *oldkey = ((void *)0);
 if (oldobj)
     *oldobj = ((void *)0);
 if (copy)
     s += strlen(key) + 1;
 entry = (struct hash_entry *)malloc(s);
 if (!entry)
 {
     debug(0x0002,"malloc failed put_hash_object key='%s'",key);
     retval = -1;
 }
 else
 {
     if (copy)
     {
  entry->he_key = (char *)(entry + 1);
  strcpy(entry->he_key, key);
     }
     else
     {
  entry->he_key = (char *)key;
     }
     entry->he_obj = obj;
     list_add(&entry->he_list, head);
 }
    }
    return retval;
}

variable_types:
obj
void *

variable_types: copy int

variable_types:
oldkey
char **

variable_types:
oldobj
void **

variable_types: struct list_head { struct list_head *next; } *

variable_types: struct hash_entry { char *he_key; void *he_obj; struct list_head { struct list_head *next; } he_list; } *

variable_types: retval int

variable_types:
s
unsigned long

user_defined_types: struct hash_entry { char *he_key; void *he_obj; struct list_head he_list; }


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

put_hash_object_ex(a1, a2, a3, 1, 0LL, &v4);
return v4;
}

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

func8(a1, a2, a3, 1, 0LL, &v4);
return v4;
}

original_code:
void *put_hash_object(struct hash_table *tbl, const char *key, void *obj)
{
    void * retval;
    put_hash_object_ex(tbl, key, obj, HT_KEYCOPY, ((void *)0), &retval);
    return retval;
}

canonical_original_code:
void *put_hash_object(struct hash_table *tbl, char *key, void *obj)
{
    void *retval;
    put_hash_object_ex(tbl, key, obj, HT_KEYCOPY, ((void *)0), &retval);
    return retval;
}

variable_types:
retval
void *

return_type: void *

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
_BOOL8 __fastcall list_empty(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_QWORD *a1)
{
return *a1 == (_QWORD)a1;
}

original_code:
static __inline__ int list_empty(struct list_head *head)
{
        return head->next == head;
}


debug

decompiled_code:
__int64 debug(__int64 a1, __int64 a2, ...)
{
__int64 result; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

result = debuglvl & (unsigned int)a1;
if ( (debuglvl & (unsigned int)a1) != 0 )
{
va_start(va, a2);
result = vdebug(a1, a2, va);
}
return result;
}

canonical_decompiled_code:
__int64 func0(__int64 a1, __int64 a2, ...)
{
__int64 result; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

result = debuglvl & (unsigned int)a1;
if ( (debuglvl & (unsigned int)a1) != 0 )
{
va_start(va, a2);
result = vdebug(a1, a2, va);
}
return result;
}

original_code:
static __inline__ void debug(unsigned int dtype, const char *fmt, ...)
{
    va_list ap;
    if (!(debuglvl & dtype))
 return;
    __builtin_va_start(ap,fmt);
    vdebug(dtype, fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
static __inline__ void debug(unsigned int dtype, char *fmt, ...)
{
    __builtin_va_list ap;
    if (!(debuglvl & dtype))
 return;
    __builtin_va_start(ap,fmt);
    vdebug(dtype, fmt, ap);
    __builtin_va_end(ap);
}

variable_types:
dtype
unsigned int

variable_types:
fmt
char *


decompiled_code:
__int64 __fastcall tcp_create_socket(int a1)
{
int v1; // ebx
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v1 = socket(2, 1, 0);
if ( v1 < 0 )
debug(1LL, (__int64)"tcp: can't create socket");
if ( a1 )
setsockopt(v1, 1, 2, optval, 4u);
optval[0] = 1;
setsockopt(v1, 6, 1, optval, 4u);
debug(64LL, (__int64)"tcp: socket created");
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
int v1; // ebx
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v1 = socket(2, 1, 0);
if ( v1 < 0 )
func0(1LL, (__int64)"tcp: can't create socket");
if ( a1 )
setsockopt(v1, 1, 2, optval, 4u);
optval[0] = 1;
setsockopt(v1, 6, 1, optval, 4u);
func0(64LL, (__int64)"tcp: socket created");
return (unsigned int)v1;
}

original_code:
int
tcp_create_socket(int reuse_addr)
{
  int retval;
  int yes = 1;
  if ((retval = socket(2, SOCK_STREAM, 0)) < 0)
  {
    debug(0x0001, "tcp: can't create socket");
  }
  if (reuse_addr)
  {
    setsockopt( retval, 1, 2, (char *)&yes, sizeof(int));
  }
  yes = 1;
  setsockopt (retval,
              IPPROTO_TCP,
              1,
              (char *) &yes,
              sizeof(int));
  debug(0x0040, "tcp: socket created");
  return retval;
}

variable_types: yes int


decompiled_code:
__int64 __fastcall tcp_bind_and_listen(int fd, __int16 a2)
{
__int64 result; // rax
struct sockaddr v3; // [rsp+0h] [rbp-28h] BYREF

*(_DWORD *)&v3.sa_data[10] = 0;
v3.sa_family = 2;
*(_QWORD *)&v3.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)v3.sa_data = _bswap_16(a2);
if ( bind(fd, &v3, 0x10u) < 0 )
{
debug(1LL, (__int64)"tcp: can't bind to socket");
result = 0xFFFFFFFFLL;
}
else if ( listen(fd, 5) < 0 )
{
debug(1LL, (__int64)"tcp: can't listen on socket");
result = 0xFFFFFFFFLL;
}
else
{
debug(64LL, (__int64)"tcp: socket bound and listening");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int16 a2)
{
__int64 result; // rax
struct sockaddr v3; // [rsp+0h] [rbp-28h] BYREF

*(_DWORD *)&v3.sa_data[10] = 0;
v3.sa_family = 2;
*(_QWORD *)&v3.sa_data[2] = (unsigned int)func1(0);
*(_WORD *)v3.sa_data = func2(a2);
if ( bind(fd, &v3, 0x10u) < 0 )
{
func0(1LL, (__int64)"tcp: can't bind to socket");
result = 0xFFFFFFFFLL;
}
else if ( listen(fd, 5) < 0 )
{
func0(1LL, (__int64)"tcp: can't listen on socket");
result = 0xFFFFFFFFLL;
}
else
{
func0(64LL, (__int64)"tcp: socket bound and listening");
result = 0LL;
}
return result;
}

original_code:
int
tcp_bind_and_listen(int sockfd, unsigned short tcp_port)
{
  struct sockaddr_in addr;
  memset((char *) &addr, 0, sizeof(struct sockaddr_in));
  addr.sin_family = 2;
  addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  addr.sin_port = htons(tcp_port);
  if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
  {
    debug(0x0001, "tcp: can't bind to socket");
    return -1;
  }
  if (listen(sockfd, 5) < 0)
  {
    debug(0x0001, "tcp: can't listen on socket");
    return -1;
  }
  debug(0x0040, "tcp: socket bound and listening");
  return 0;
}

canonical_original_code:
int tcp_bind_and_listen(int sockfd, unsigned short tcp_port)
{
  struct sockaddr_in addr;
  memset((char *) &addr, 0, sizeof(struct sockaddr_in));
  addr.sin_family = 2;
  addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  addr.sin_port = htons(tcp_port);
  if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
  {
    debug(0x0001, "tcp: can't bind to socket");
    return -1;
  }
  if (listen(sockfd, 5) < 0)
  {
    debug(0x0001, "tcp: can't listen on socket");
    return -1;
  }
  debug(0x0040, "tcp: socket bound and listening");
  return 0;
}

variable_types: sockfd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall tcp_accept_connection(int a1)
{
int v1; // eax
unsigned int v2; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 < 0 )
{
v2 = -1;
if ( *_errno_location() != 4 )
debug(1LL, (__int64)"tcp: error accepting connection");
}
else
{
v2 = v1;
debug(64LL, (__int64)"tcp: got connection (fd=%d)", (unsigned int)v1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
int v1; // eax
unsigned int v2; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( v1 < 0 )
{
v2 = -1;
if ( *_errno_location() != 4 )
func0(1LL, (__int64)"tcp: error accepting connection");
}
else
{
v2 = v1;
func0(64LL, (__int64)"tcp: got connection (fd=%d)", (unsigned int)v1);
}
return v2;
}

original_code:
int
tcp_accept_connection(int sockfd)
{
  struct sockaddr_in remaddr;
  socklen_t addrlen;
  int retval;
  addrlen = sizeof(struct sockaddr_in);
  if ((retval = accept(sockfd, (struct sockaddr *) &remaddr, &addrlen)) < 0)
  {
    if ((*__errno_location ()) != 4 )
      debug(0x0001, "tcp: error accepting connection");
    return -1;
  }
  debug(0x0040, "tcp: got connection (fd=%d)", retval);
  return retval;
}

canonical_original_code:
int tcp_accept_connection(int sockfd)
{
  struct sockaddr_in remaddr;
  unsigned int addrlen;
  int retval;
  addrlen = sizeof(struct sockaddr_in);
  if ((retval = accept(sockfd, (struct sockaddr *) &remaddr, &addrlen)) < 0)
  {
    if ((*__errno_location ()) != 4 )
      debug(0x0001, "tcp: error accepting connection");
    return -1;
  }
  debug(0x0040, "tcp: got connection (fd=%d)", retval);
  return retval;
}

variable_types:
addrlen
unsigned int


decompiled_code:
__int64 __fastcall tcp_get_client_ip(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
if ( getpeername(a1, &addr, &len) >= 0 )
return _bswap_32(*(unsigned int *)&addr.sa_data[2]);
debug(1LL, (__int64)"tcp: error getting remote's ip address");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
if ( getpeername(a1, &addr, &len) >= 0 )
return func1(*(unsigned int *)&addr.sa_data[2]);
func0(1LL, (__int64)"tcp: error getting remote's ip address");
return 0LL;
}

original_code:
unsigned int
tcp_get_client_ip(int fd)
{
  struct sockaddr_in remaddr;
  socklen_t addrlen;
  int retval;
  unsigned int saddr;
  addrlen = sizeof(struct sockaddr_in);
  if ((retval = getpeername(fd, (struct sockaddr *) &remaddr, &addrlen)) < 0)
  {
    debug(0x0001, "tcp: error getting remote's ip address");
    return 0;
  }
  saddr = ntohl(remaddr.sin_addr.s_addr);
  return saddr;
}

canonical_original_code:
unsigned int tcp_get_client_ip(int fd)
{
  struct sockaddr_in remaddr;
  unsigned int addrlen;
  int retval;
  unsigned int saddr;
  addrlen = sizeof(struct sockaddr_in);
  if ((retval = getpeername(fd, (struct sockaddr *) &remaddr, &addrlen)) < 0)
  {
    debug(0x0001, "tcp: error getting remote's ip address");
    return 0;
  }
  saddr = ntohl(remaddr.sin_addr.s_addr);
  return saddr;
}

variable_types: fd int

variable_types:
saddr
unsigned int


decompiled_code:
__int64 __fastcall convert_address(struct in_addr *a1, const char *a2)
{
unsigned int v2; // ebx
struct hostent *v4; // r13
int v5; // eax
char v6[268]; // [rsp+0h] [rbp-138h] BYREF
struct in_addr inp; // [rsp+10Ch] [rbp-2Ch] BYREF

if ( inet_aton(a2, &inp) )
{
a1->s_addr = inp.s_addr;
v2 = 0;
}
else
{
v2 = 0;
v4 = gethostbyname(a2);
if ( !v4 )
{
v5 = *_h_errno_location();
if ( v5 == 3 )
{
strcpy(v6, "NO_RECOVERY");
}
else if ( v5 > 3 )
{
if ( v5 == 4 )
strcpy(v6, "NO_ADDRESS");
}
else if ( v5 == 1 )
{
strcpy(v6, "HOST_NOT_FOUND");
}
else if ( v5 == 2 )
{
strcpy(v6, "TRY_AGAIN");
}
debug(1LL, (__int64)"gethostbyname failed for %s: %s", a2, v6);
v2 = -1;
}
*(_QWORD *)&a1->s_addr = **(_QWORD **)v4->h_addr_list;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(struct in_addr *a1, const char *a2)
{
unsigned int v2; // ebx
struct hostent *v4; // r13
int v5; // eax
char v6[268]; // [rsp+0h] [rbp-138h] BYREF
struct in_addr inp; // [rsp+10Ch] [rbp-2Ch] BYREF

if ( inet_aton(a2, &inp) )
{
a1->s_addr = inp.s_addr;
v2 = 0;
}
else
{
v2 = 0;
v4 = gethostbyname(a2);
if ( !v4 )
{
v5 = *_h_errno_location();
if ( v5 == 3 )
{
strcpy(v6, "NO_RECOVERY");
}
else if ( v5 > 3 )
{
if ( v5 == 4 )
strcpy(v6, "NO_ADDRESS");
}
else if ( v5 == 1 )
{
strcpy(v6, "HOST_NOT_FOUND");
}
else if ( v5 == 2 )
{
strcpy(v6, "TRY_AGAIN");
}
func0(1LL, (__int64)"gethostbyname failed for %s: %s", a2, v6);
v2 = -1;
}
*(_QWORD *)&a1->s_addr = **(_QWORD **)v4->h_addr_list;
}
return v2;
}

original_code:
int
convert_address(long *dest, const char *addr_str)
{
  struct in_addr ip;
  int retval = 0;
  char errstr[256];
  if ( inet_aton(addr_str, &ip) )
  {
    memcpy(dest, &ip.s_addr, sizeof(ip.s_addr));
  }
  else
  {
    struct hostent *host;
    if ((host = gethostbyname(addr_str)) == ((void *)0))
    {
      switch((*__h_errno_location ()))
      {
      case 1:
 strcpy(errstr, "HOST_NOT_FOUND");
 break;
      case 4:
 strcpy(errstr, "NO_ADDRESS");
 break;
      case 3:
 strcpy(errstr, "NO_RECOVERY");
 break;
      case 2:
 strcpy(errstr, "TRY_AGAIN");
 break;
      }
      debug(0x0001, "gethostbyname failed for %s: %s", addr_str, errstr);
      retval = -1;
    }
    memcpy(dest, host->h_addr_list[0], sizeof(unsigned long));
  }
  return retval;
}

canonical_original_code:
int convert_address(long *dest, char *addr_str)
{
  struct in_addr ip;
  int retval = 0;
  char errstr[256];
  if ( inet_aton(addr_str, &ip) )
  {
    memcpy(dest, &ip.s_addr, sizeof(ip.s_addr));
  }
  else
  {
    struct hostent *host;
    if ((host = gethostbyname(addr_str)) == ((void *)0))
    {
      switch((*__h_errno_location ()))
      {
      case 1:
 strcpy(errstr, "HOST_NOT_FOUND");
 break;
      case 4:
 strcpy(errstr, "NO_ADDRESS");
 break;
      case 3:
 strcpy(errstr, "NO_RECOVERY");
 break;
      case 2:
 strcpy(errstr, "TRY_AGAIN");
 break;
      }
      debug(0x0001, "gethostbyname failed for %s: %s", addr_str, errstr);
      retval = -1;
    }
    memcpy(dest, host->h_addr_list[0], sizeof(unsigned long));
  }
  return retval;
}

variable_types:
dest
long *

variable_types:
ip
struct in_addr { unsigned int s_addr; }

variable_types:
errstr
char [256]

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
__int64 __fastcall tcp_connect(int fd, const char *a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v5; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

if ( (int)convert_address((struct in_addr *)&v5, a2) < 0 )
return 0xFFFFFFFFLL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = v5;
*(_WORD *)addr.sa_data = _bswap_16(a3);
if ( connect(fd, &addr, 0x10u) < 0 )
{
debug(1LL, (__int64)"connect error");
result = 0xFFFFFFFFLL;
}
else
{
debug(32LL, (__int64)"tcp: connection established on port %d", a3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, const char *a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v5; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

if ( (int)func7((struct in_addr *)&v5, a2) < 0 )
return 0xFFFFFFFFLL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = v5;
*(_WORD *)addr.sa_data = func2(a3);
if ( connect(fd, &addr, 0x10u) < 0 )
{
func0(1LL, (__int64)"connect error");
result = 0xFFFFFFFFLL;
}
else
{
func0(32LL, (__int64)"tcp: connection established on port %d", a3);
result = 0LL;
}
return result;
}

original_code:
int
tcp_connect(int sockfd, const char *rem_addr, unsigned short port)
{
  struct sockaddr_in addr;
  int addrlen;
  long ipno;
  if ( convert_address(&ipno , rem_addr) < 0 )
  {
    return -1;
  }
  addrlen = sizeof(struct sockaddr_in);
  memset((char *) &addr, 0, sizeof(struct sockaddr_in));
  addr.sin_family = 2;
  addr.sin_addr.s_addr = ipno;
  addr.sin_port = htons(port);
  if (connect(sockfd, (struct sockaddr *)&addr, addrlen) < 0)
  {
    debug(0x0001, "connect error");
    return -1;
  }
  debug(0x0020, "tcp: connection established on port %d", port);
  return 0;
}

canonical_original_code:
int tcp_connect(int sockfd, char *rem_addr, unsigned short port)
{
  struct sockaddr_in addr;
  int addrlen;
  long ipno;
  if ( convert_address(&ipno , rem_addr) < 0 )
  {
    return -1;
  }
  addrlen = sizeof(struct sockaddr_in);
  memset((char *) &addr, 0, sizeof(struct sockaddr_in));
  addr.sin_family = 2;
  addr.sin_addr.s_addr = ipno;
  addr.sin_port = htons(port);
  if (connect(sockfd, (struct sockaddr *)&addr, addrlen) < 0)
  {
    debug(0x0001, "connect error");
    return -1;
  }
  debug(0x0020, "tcp: connection established on port %d", port);
  return 0;
}

variable_types:
port
unsigned short

variable_types: addrlen int

variable_types: ipno long


decompiled_code:
__int64 __fastcall tcp_get_local_address(int a1, _DWORD *a2, __int16 *a3)
{
__int64 result; // rax
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

len = 16;
if ( getsockname(a1, &addr, &len) < 0 )
{
debug(1LL, (__int64)"getsockname failed");
result = 0xFFFFFFFFLL;
}
else
{
*a2 = _bswap_32(*(unsigned int *)&addr.sa_data[2]);
*a3 = _bswap_16(*(__int16 *)addr.sa_data);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, _DWORD *a2, __int16 *a3)
{
__int64 result; // rax
socklen_t len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

len = 16;
if ( getsockname(a1, &addr, &len) < 0 )
{
func0(1LL, (__int64)"getsockname failed");
result = 0xFFFFFFFFLL;
}
else
{
*a2 = func1(*(unsigned int *)&addr.sa_data[2]);
*a3 = func2(*(__int16 *)addr.sa_data);
result = 0LL;
}
return result;
}

original_code:
int tcp_get_local_address(int sockfd, unsigned int *ip, unsigned short *port)
{
    struct sockaddr_in addr;
    socklen_t addrlen = sizeof(struct sockaddr_in);
    if(getsockname(sockfd, (struct sockaddr *)&addr, &addrlen) < 0)
    {
 debug(0x0001, "getsockname failed" );
 return -1;
    }
    *ip = ntohl( addr.sin_addr.s_addr );
    *port = ntohs( addr.sin_port );
    return 0;
}

canonical_original_code:
int tcp_get_local_address(int sockfd, unsigned int *ip, unsigned short *port)
{
    struct sockaddr_in addr;
    unsigned int addrlen = sizeof(struct sockaddr_in);
    if(getsockname(sockfd, (struct sockaddr *)&addr, &addrlen) < 0)
    {
 debug(0x0001, "getsockname failed" );
 return -1;
    }
    *ip = ntohl( addr.sin_addr.s_addr );
    *port = ntohs( addr.sin_port );
    return 0;
}

variable_types:
ip
unsigned int *

variable_types:
port
unsigned short *


original_code:
static int get_int_substr(const char * str, const regmatch_t * p)
{
    char buff[256];
    if(p->rm_so == -1)
     return 0;
    if(p->rm_eo - p->rm_so >= sizeof(buff))
     return 0;
    memcpy(buff, str + p->rm_so, p->rm_eo - p->rm_so);
    buff[p->rm_eo - p->rm_so] = 0;
    return atoi(buff);
}

canonical_original_code:
static int get_int_substr(char *str, struct regmatch_t *p)
{
    char buff[256];
    if(p->rm_so == -1)
     return 0;
    if(p->rm_eo - p->rm_so >= sizeof(buff))
     return 0;
    memcpy(buff, str + p->rm_so, p->rm_eo - p->rm_so);
    buff[p->rm_eo - p->rm_so] = 0;
    return atoi(buff);
}

variable_types:
str
char *

variable_types: struct regmatch_t { int rm_so; int rm_eo; } *

variable_types:
buff
char [256]


decompiled_code:
time_t __fastcall mktime_utc(struct tm *tp, char *value)
{
char *v2; // rbx
time_t v3; // rbp

v2 = getenv("TZ");
setenv("TZ", value, 1);
tzset();
v3 = mktime(tp);
if ( v2 )
setenv("TZ", v2, 1);
else
unsetenv("TZ");
tzset();
return v3;
}

canonical_decompiled_code:
time_t __fastcall func2(struct tm *tp, char *value)
{
char *v2; // rbx
time_t v3; // rbp

v2 = getenv("TZ");
setenv("TZ", value, 1);
tzset();
v3 = mktime(tp);
if ( v2 )
setenv("TZ", v2, 1);
else
unsetenv("TZ");
tzset();
return v3;
}

original_code:
static time_t mktime_utc(struct tm * tm, const char* tzbuf)
{
    char * old_tz = getenv("TZ");
    time_t ret;
    setenv("TZ", tzbuf, 1);
    tzset();
    ret = mktime(tm);
    if (old_tz)
 setenv("TZ", old_tz, 1);
    else
 unsetenv("TZ");
    tzset();
    return ret;
}

canonical_original_code:
static long mktime_utc(struct tm *tm, char *tzbuf)
{
    char *old_tz = getenv("TZ");
    long ret;
    setenv("TZ", tzbuf, 1);
    tzset();
    ret = mktime(tm);
    if (old_tz)
 setenv("TZ", old_tz, 1);
    else
 unsetenv("TZ");
    tzset();
    return ret;
}

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

variable_types:
tzbuf
char *

variable_types: ret long


chop

decompiled_code:
const char *__fastcall chop(const char *a1)
{
const char *i; // rax

for ( i = &a1[strlen(a1) - 1]; a1 <= i; *i-- = 0 )
{
if ( *i != 10 && *i != 13 )
break;
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func3(const char *a1)
{
const char *i; // rax

for ( i = &a1[strlen(a1) - 1]; a1 <= i; *i-- = 0 )
{
if ( *i != 10 && *i != 13 )
break;
}
return a1;
}

original_code:
char *chop( char* src )
{
    char* p = src + strlen(src) - 1;
    while( p >= src )
    {
 if ( *p == '\n' || *p == '\r' )
 {
     *p-- = 0;
 }
 else
 {
     break;
 }
    }
    return( src );
}

canonical_original_code:
char *chop(char *src)
{
    char *p = src + strlen(src) - 1;
    while( p >= src )
    {
 if ( *p == '\n' || *p == '\r' )
 {
     *p-- = 0;
 }
 else
 {
     break;
 }
    }
    return( src );
}

variable_types:
src
char *

variable_types:
p
char *

return_type: char *


decompiled_code:
char *get_cvsps_dir()
{
char *v1; // rcx
struct stat v2; // [rsp-18h] [rbp-98h] BYREF

if ( prefix_4 )
return &prefix_4;
v1 = getenv("HOME");
if ( !v1 )
{
debug(2LL, (__int64)"HOME environment variable not set");
exit(1);
}
if ( snprintf(&prefix_4, 0x1000uLL, "%s/%s", v1, ".cvsps") > 4095 )
{
debug(2LL, (__int64)"prefix buffer overflow");
exit(1);
}
if ( stat(&prefix_4, &v2) < 0 )
{
if ( mkdir(&prefix_4, 0x1FFu) < 0 )
{
debug(1LL, (__int64)"Cannot create the cvsps directory '%s'", ".cvsps");
exit(1);
}
}
else if ( (v2.st_mode & 0xF000) != 0x4000 )
{
debug(2LL, (__int64)"cvsps directory '%s' is not a directory!", ".cvsps");
}
return &prefix_4;
}

canonical_decompiled_code:
char *func5()
{
char *v1; // rcx
struct stat v2; // [rsp-18h] [rbp-98h] BYREF

if ( prefix_4 )
return &prefix_4;
v1 = getenv("HOME");
if ( !v1 )
{
func0(2LL, (__int64)"HOME environment variable not set");
exit(1);
}
if ( snprintf(&prefix_4, 0x1000uLL, "%s/%s", v1, ".cvsps") > 4095 )
{
func0(2LL, (__int64)"prefix buffer overflow");
exit(1);
}
if ( stat(&prefix_4, &v2) < 0 )
{
if ( mkdir(&prefix_4, 0x1FFu) < 0 )
{
func0(1LL, (__int64)"Cannot create the cvsps directory '%s'", ".cvsps");
exit(1);
}
}
else if ( (v2.st_mode & 0xF000) != 0x4000 )
{
func0(2LL, (__int64)"cvsps directory '%s' is not a directory!", ".cvsps");
}
return &prefix_4;
}

original_code:
char *get_cvsps_dir()
{
    struct stat sbuf;
    static char prefix[4096];
    const char * home;
    if (prefix[0])
 return prefix;
    if (!(home = getenv("HOME")))
    {
 debug(0x0002, "HOME environment variable not set");
 exit(1);
    }
    if (snprintf(prefix, 4096, "%s/%s", home, ".cvsps") >= 4096)
    {
 debug(0x0002, "prefix buffer overflow");
 exit(1);
    }
    if (stat(prefix, &sbuf) < 0)
    {
 int ret;
 ret = mkdir(prefix, 0777);
 if (ret < 0)
 {
     debug(0x0001, "Cannot create the cvsps directory '%s'", ".cvsps");
     exit(1);
 }
    }
    else
    {
 if (!(((((sbuf.st_mode)) & 0170000) == (0040000))))
     debug(0x0002, "cvsps directory '%s' is not a directory!", ".cvsps");
    }
    return prefix;
}

canonical_original_code:
char *get_cvsps_dir()
{
    struct stat sbuf;
    static char prefix[4096];
    char *home;
    if (prefix[0])
 return prefix;
    if (!(home = getenv("HOME")))
    {
 debug(0x0002, "HOME environment variable not set");
 exit(1);
    }
    if (snprintf(prefix, 4096, "%s/%s", home, ".cvsps") >= 4096)
    {
 debug(0x0002, "prefix buffer overflow");
 exit(1);
    }
    if (stat(prefix, &sbuf) < 0)
    {
 int ret;
 ret = mkdir(prefix, 0777);
 if (ret < 0)
 {
     debug(0x0001, "Cannot create the cvsps directory '%s'", ".cvsps");
     exit(1);
 }
    }
    else
    {
 if (!(((((sbuf.st_mode)) & 0170000) == (0040000))))
     debug(0x0002, "cvsps directory '%s' is not a directory!", ".cvsps");
    }
    return prefix;
}

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

variable_types:
prefix
char [4096]

variable_types:
home
char *

variable_types: ret int

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


xstrdup

decompiled_code:
char *__fastcall xstrdup(const char *a1)
{
char *result; // rax

if ( !a1 )
_assert_fail("str", "util.c", 0x85u, "xstrdup");
result = strdup(a1);
if ( !result )
{
debug(1LL, (__int64)"strdup failed");
exit(1);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func6(const char *a1)
{
char *result; // rax

if ( !a1 )
_assert_fail("str", "util.c", 0x85u, "xstrdup");
result = strdup(a1);
if ( !result )
{
func0(1LL, (__int64)"strdup failed");
exit(1);
}
return result;
}

original_code:
char *xstrdup(char const *str)
{
    char *ret;
    ((void) sizeof ((str) ? 1 : 0), __extension__ ({ if (str) ; else __assert_fail ("str", "util.c", 133, __extension__ __PRETTY_FUNCTION__); }));
    ret = strdup(str);
    if (!ret)
    {
 debug(0x0001, "strdup failed");
 exit(1);
    }
    return ret;
}

canonical_original_code:
char *xstrdup(char *str)
{
    char *ret;
    ((void) sizeof ((str) ? 1 : 0), __extension__ ({ if (str) ; else __assert_fail ("str", "util.c", 133, __extension__ __PRETTY_FUNCTION__); }));
    ret = strdup(str);
    if (!ret)
    {
 debug(0x0001, "strdup failed");
 exit(1);
    }
    return ret;
}

variable_types:
ret
char *


strzncpy

decompiled_code:
char *__fastcall strzncpy(char *a1, const char *a2, int a3)
{
__int64 v3; // rbx
char *result; // rax

v3 = a3;
result = strncpy(a1, a2, a3);
a1[v3 - 1] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func7(char *a1, const char *a2, int a3)
{
__int64 v3; // rbx
char *result; // rax

v3 = a3;
result = strncpy(a1, a2, a3);
a1[v3 - 1] = 0;
return result;
}

original_code:
void strzncpy(char * dst, const char * src, int n)
{
    strncpy(dst, src, n);
    dst[n - 1] = 0;
}

canonical_original_code:
void strzncpy(char *dst, char *src, int n)
{
    strncpy(dst, src, n);
    dst[n - 1] = 0;
}

variable_types:
dst
char *

variable_types: n int


decompiled_code:
__int64 __fastcall get_string(const void *a1)
{
void *v1; // rax
char *v3; // rbx

if ( !a1 )
return 0LL;
v1 = tfind(a1, &string_tree, (__compar_fn_t)&strcmp);
if ( !v1 )
{
v3 = xstrdup((const char *)a1);
v1 = tsearch(v3, &string_tree, (__compar_fn_t)&strcmp);
*(_QWORD *)v1 = v3;
}
return *(_QWORD *)v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(const void *a1)
{
void *v1; // rax
char *v3; // rbx

if ( !a1 )
return 0LL;
v1 = tfind(a1, &string_tree, (__compar_fn_t)&strcmp);
if ( !v1 )
{
v3 = func6((const char *)a1);
v1 = tsearch(v3, &string_tree, (__compar_fn_t)&strcmp);
*(_QWORD *)v1 = v3;
}
return *(_QWORD *)v1;
}

original_code:
char *get_string(char const *str)
{
    char ** res;
    if (!str)
 return ((void *)0);
    res = (char **)tfind(str, &string_tree, (compare_func)strcmp);
    if (!res)
    {
 char *key = xstrdup(str);
 res = (char **)tsearch(key, &string_tree, (compare_func)strcmp);
 *res = key;
    }
    return *res;
}

canonical_original_code:
char *get_string(char *str)
{
    char **res;
    if (!str)
 return ((void *)0);
    res = (char **)tfind(str, &string_tree, (int (*)(void *, void *))strcmp);
    if (!res)
    {
 char *key = xstrdup(str);
 res = (char **)tsearch(key, &string_tree, (int (*)(void *, void *))strcmp);
 *res = key;
    }
    return *res;
}

variable_types:
res
char **

variable_types:
key
char *


decompiled_code:
int timing_start()
{
return gettimeofday(&start_time, 0LL);
}

canonical_decompiled_code:
int func10()
{
return gettimeofday(&start_time, 0LL);
}

original_code:
void timing_start()
{
    gettimeofday(&start_time, ((void *)0));
}


decompiled_code:
int __fastcall timing_stop(const char *a1)
{
__time_t v1; // rdx
__suseconds_t v2; // rax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
v1 = v4.tv_sec - start_time.tv_sec;
v4.tv_sec -= start_time.tv_sec;
v2 = v4.tv_usec - start_time.tv_usec;
v4.tv_usec -= start_time.tv_usec;
if ( v4.tv_usec < 0 )
{
v4.tv_sec = v1 - 1;
v4.tv_usec = v2 + 1000000;
}
return printf("Elapsed time for %s: %d.%06d\n", a1, LODWORD(v4.tv_sec), LODWORD(v4.tv_usec));
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
__time_t v1; // rdx
__suseconds_t v2; // rax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
v1 = v4.tv_sec - start_time.tv_sec;
v4.tv_sec -= start_time.tv_sec;
v2 = v4.tv_usec - start_time.tv_usec;
v4.tv_usec -= start_time.tv_usec;
if ( v4.tv_usec < 0 )
{
v4.tv_sec = v1 - 1;
v4.tv_usec = v2 + 1000000;
}
return printf("Elapsed time for %s: %d.%06d\n", a1, LODWORD(v4.tv_sec), LODWORD(v4.tv_usec));
}

original_code:
void timing_stop(const char * msg)
{
    struct timeval stop_time;
    gettimeofday(&stop_time, ((void *)0));
    stop_time.tv_sec -= start_time.tv_sec;
    stop_time.tv_usec -= start_time.tv_usec;
    if (stop_time.tv_usec < 0)
 stop_time.tv_sec--,stop_time.tv_usec += 1000000;
    printf("Elapsed time for %s: %d.%06d\n", msg, (int)stop_time.tv_sec, (int)stop_time.tv_usec);
}

canonical_original_code:
void timing_stop(char *msg)
{
    struct timeval stop_time;
    gettimeofday(&stop_time, ((void *)0));
    stop_time.tv_sec -= start_time.tv_sec;
    stop_time.tv_usec -= start_time.tv_usec;
    if (stop_time.tv_usec < 0)
 stop_time.tv_sec--,stop_time.tv_usec += 1000000;
    printf("Elapsed time for %s: %d.%06d\n", msg, (int)stop_time.tv_sec, (int)stop_time.tv_usec);
}

variable_types:
msg
char *

variable_types: struct timeval { long tv_sec; long tv_usec; }


original_code:
int escape_filename(char * dst, int len, const char * src)
{
    static char * naughty_chars = " \\\"'@<>=;|&()#$`?*[!:{";
    if (len > 0)
    {
 while (len > 1 && *src)
 {
     if (strchr(naughty_chars, *src))
     {
  if (len == 2)
      break;
  *dst++ = '\\';
  len--;
     }
     *dst++ = *src++;
     len--;
 }
 *dst = 0;
    }
    return (*src == 0) ? 0 : -1;
}

canonical_original_code:
int escape_filename(char *dst, int len, char *src)
{
    static char *naughty_chars = " \\\"'@<>=;|&()#$`?*[!:{";
    if (len > 0)
    {
 while (len > 1 && *src)
 {
     if (strchr(naughty_chars, *src))
     {
  if (len == 2)
      break;
  *dst++ = '\\';
  len--;
     }
     *dst++ = *src++;
     len--;
 }
 *dst = 0;
    }
    return (*src == 0) ? 0 : -1;
}

variable_types: len int


decompiled_code:
char *__fastcall strcpy_a(char *a1, const char *a2, int a3)
{
char *v3; // rbx
char *result; // rax

v3 = &a1[a3 - 1];
*v3 = 0;
result = strncpy(a1, a2, a3);
if ( *v3 )
{
debug(2LL, (__int64)"FATAL: internal buffer exhausted.");
exit(1);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func13(char *a1, const char *a2, int a3)
{
char *v3; // rbx
char *result; // rax

v3 = &a1[a3 - 1];
*v3 = 0;
result = strncpy(a1, a2, a3);
if ( *v3 )
{
func0(2LL, (__int64)"FATAL: internal buffer exhausted.");
exit(1);
}
return result;
}

original_code:
void strcpy_a(char * dst, const char * src, int n)
{
    dst[n - 1] = 0;
    strncpy(dst, src, n);
    if (dst[n - 1] != 0) {
 debug(0x0002, "FATAL: internal buffer exhausted.");
 exit(1);
    }
}

canonical_original_code:
void strcpy_a(char *dst, char *src, int n)
{
    dst[n - 1] = 0;
    strncpy(dst, src, n);
    if (dst[n - 1] != 0) {
 debug(0x0002, "FATAL: internal buffer exhausted.");
 exit(1);
    }
}


decompiled_code:
__int64 __fastcall count_hash(__int64 a1, _DWORD *a2, unsigned int *a3)
{
unsigned int i; // ebx
__int64 result; // rax

reset_hash_iterator();
for ( i = 0; ; ++i )
{
result = next_hash_entry(a1);
if ( !result )
break;
}
*a2 += i;
if ( *a3 >= i )
i = *a3;
*a3 = i;
return result;
}

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

reset_hash_iterator();
for ( i = 0; ; ++i )
{
result = next_hash_entry(a1);
if ( !result )
break;
}
*a2 += i;
if ( *a3 >= i )
i = *a3;
*a3 = i;
return result;
}

original_code:
static void count_hash(struct hash_table *hash, unsigned int *total,
 unsigned int *max_val)
{
    int counter = 0;
    reset_hash_iterator(hash);
    while (next_hash_entry(hash))
 counter++;
    *total += counter;
    *max_val= ((*max_val) > (counter) ? (*max_val) : (counter));
}

variable_types: struct hash_table { int ht_size; struct list_head { struct list_head *next; } *ht_lists; int iterator; struct list_head *iterator_ptr; } *

variable_types:
total
unsigned int *

variable_types: counter int


decompiled_code:
void __fastcall stat_ps_tree_node(const void *nodep, __int64 value, __int64 level)
{
__int64 v3; // rbx
unsigned int v4; // eax
int v5; // edx
_QWORD *v6; // rax
unsigned int v7; // edx
unsigned int v8; // eax
int v9; // edx
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !author_hash )
author_hash = create_hash_table(1023LL, value, level);
if ( (value & 0xFFFFFFFD) == 1 )
{
v3 = *(_QWORD *)nodep;
++num_patch_sets;
v10[0] = 0LL;
if ( (int)put_hash_object_ex(author_hash, *(_QWORD *)(v3 + 40), *(_QWORD *)(v3 + 40), 0LL, 0LL, v10) >= 0 && !v10[0] )
{
v8 = strlen(*(const char **)(v3 + 40));
++num_authors;
v9 = v8;
if ( max_author_len >= v8 )
v9 = max_author_len;
max_author_len = v9;
total_author_len += v8;
}
v4 = strlen(*(const char **)(v3 + 32));
v5 = v4;
if ( max_descr_len >= v4 )
v5 = max_descr_len;
max_descr_len = v5;
total_descr_len += v4;
v6 = *(_QWORD **)(v3 + 80);
if ( v6 == (_QWORD *)(v3 + 80) )
{
v7 = 0;
}
else
{
v7 = 0;
do
{
++v7;
v6 = (_QWORD *)*v6;
}
while ( v6 != (_QWORD *)(v3 + 80) );
}
num_ps_member += v7;
if ( max_ps_member_in_ps >= v7 )
v7 = max_ps_member_in_ps;
max_ps_member_in_ps = v7;
}
}

canonical_decompiled_code:
void __fastcall func1(const void *nodep, __int64 value, __int64 level)
{
__int64 v3; // rbx
unsigned int v4; // eax
int v5; // edx
_QWORD *v6; // rax
unsigned int v7; // edx
unsigned int v8; // eax
int v9; // edx
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

if ( !author_hash )
author_hash = create_hash_table(1023LL, value, level);
if ( (value & 0xFFFFFFFD) == 1 )
{
v3 = *(_QWORD *)nodep;
++num_patch_sets;
v10[0] = 0LL;
if ( (int)put_hash_object_ex(author_hash, *(_QWORD *)(v3 + 40), *(_QWORD *)(v3 + 40), 0LL, 0LL, v10) >= 0 && !v10[0] )
{
v8 = strlen(*(const char **)(v3 + 40));
++num_authors;
v9 = v8;
if ( max_author_len >= v8 )
v9 = max_author_len;
max_author_len = v9;
total_author_len += v8;
}
v4 = strlen(*(const char **)(v3 + 32));
v5 = v4;
if ( max_descr_len >= v4 )
v5 = max_descr_len;
max_descr_len = v5;
total_descr_len += v4;
v6 = *(_QWORD **)(v3 + 80);
if ( v6 == (_QWORD *)(v3 + 80) )
{
v7 = 0;
}
else
{
v7 = 0;
do
{
++v7;
v6 = (_QWORD *)*v6;
}
while ( v6 != (_QWORD *)(v3 + 80) );
}
num_ps_member += v7;
if ( max_ps_member_in_ps >= v7 )
v7 = max_ps_member_in_ps;
max_ps_member_in_ps = v7;
}
}

original_code:
static void stat_ps_tree_node(const void * nodep, const VISIT which, const int depth)
{
    int desc_len;
    PatchSet * ps;
    struct list_head * next;
    int counter;
    void * old;
    if (!author_hash)
 author_hash = create_hash_table(1023);
    switch(which)
    {
    case postorder:
    case leaf:
 ps = *(PatchSet**)nodep;
 num_patch_sets++;
 old = ((void *)0);
 if (put_hash_object_ex(author_hash, ps->author, ps->author, HT_NO_KEYCOPY, ((void *)0), &old) >= 0 && !old)
 {
     int len = strlen(ps->author);
     num_authors++;
     max_author_len = ((max_author_len) > (len) ? (max_author_len) : (len));
     total_author_len += len;
 }
 desc_len = strlen(ps->descr);
 max_descr_len = ((max_descr_len) > (desc_len) ? (max_descr_len) : (desc_len));
 total_descr_len += desc_len;
 counter = 0;
 next = ps->members.next;
 while (next != &ps->members)
 {
     counter++;
     next = next->next;
 }
 num_ps_member += counter;
 max_ps_member_in_ps = ((max_ps_member_in_ps) > (counter) ? (max_ps_member_in_ps) : (counter));
 break;
    default:
 break;
    }
}

canonical_original_code:
static void stat_ps_tree_node(void *nodep, enum VISIT which, int depth)
{
    int desc_len;
    struct _PatchSet *ps;
    struct list_head *next;
    int counter;
    void *old;
    if (!author_hash)
 author_hash = create_hash_table(1023);
    switch(which)
    {
    case postorder:
    case leaf:
 ps = *(struct _PatchSet **)nodep;
 num_patch_sets++;
 old = ((void *)0);
 if (put_hash_object_ex(author_hash, ps->author, ps->author, HT_NO_KEYCOPY, ((void *)0), &old) >= 0 && !old)
 {
     int len = strlen(ps->author);
     num_authors++;
     max_author_len = ((max_author_len) > (len) ? (max_author_len) : (len));
     total_author_len += len;
 }
 desc_len = strlen(ps->descr);
 max_descr_len = ((max_descr_len) > (desc_len) ? (max_descr_len) : (desc_len));
 total_descr_len += desc_len;
 counter = 0;
 next = ps->members.next;
 while (next != &ps->members)
 {
     counter++;
     next = next->next;
 }
 num_ps_member += counter;
 max_ps_member_in_ps = ((max_ps_member_in_ps) > (counter) ? (max_ps_member_in_ps) : (counter));
 break;
    default:
 break;
    }
}

variable_types:
nodep
void *

variable_types: enum VISIT { preorder=0, postorder=1, endorder=2, leaf=3 }

variable_types: depth int

variable_types: struct _PatchSet { int psid; long date; long min_date; long max_date; char *descr; char *author; char *commitid; struct list_head { struct list_head *next; } tags; char *branch; struct list_head members; _Bool branch_add; int funk_factor; int mark; struct list_head branches; struct list_head all_link; struct list_head collision_link; } *

variable_types: struct list_head { struct list_head *next; } *

variable_types:
old
void *

user_defined_types: struct _PatchSet { int psid; long date; long min_date; long max_date; char *descr; char *author; char *commitid; struct list_head tags; char *branch; struct list_head members; _Bool branch_add; int funk_factor; int mark; struct list_head branches; struct list_head all_link; struct list_head collision_link; }