process

decompiled_code:
unsigned int __fastcall process(int a1, int a2)
{
unsigned int result; // eax
void *v3; // rsp
pthread_t *v4; // rbx
pthread_t *v5; // r13
pthread_t *v6; // r12
pthread_t v7; // rdi
_BYTE v8[12]; // [rsp+0h] [rbp-30h] BYREF
int arg[9]; // [rsp+Ch] [rbp-24h] BYREF

result = (8 * a2 + 15) & 0xFFFFFFF0;
arg[0] = a1;
v3 = alloca(8LL * a2);
if ( a2 > 0 )
{
v4 = (pthread_t *)v8;
v5 = (pthread_t *)&v8[8 * a2];
v6 = (pthread_t *)v8;
do
pthread_create(v6++, 0LL, primalityCheck, arg);
while ( v6 != v5 );
do
{
v7 = *v4++;
result = pthread_join(v7, 0LL);
}
while ( v4 != v5 );
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func7(int a1, int a2)
{
unsigned int result; // eax
void *v3; // rsp
pthread_t *v4; // rbx
pthread_t *v5; // r13
pthread_t *v6; // r12
pthread_t v7; // rdi
_BYTE v8[12]; // [rsp+0h] [rbp-30h] BYREF
int arg[9]; // [rsp+Ch] [rbp-24h] BYREF

result = (8 * a2 + 15) & 0xFFFFFFF0;
arg[0] = a1;
v3 = alloca(8LL * a2);
if ( a2 > 0 )
{
v4 = (pthread_t *)v8;
v5 = (pthread_t *)&v8[8 * a2];
v6 = (pthread_t *)v8;
do
pthread_create(v6++, 0LL, primalityCheck, arg);
while ( v6 != v5 );
do
{
v7 = *v4++;
result = pthread_join(v7, 0LL);
}
while ( v4 != v5 );
}
return result;
}

original_code:
void process(int max, int numberOfThreads) {
 int i;
 pthread_t threads[numberOfThreads];
 for (i = 0; i < numberOfThreads; i++)
  pthread_create(&threads[i], ((void *)0), primalityCheck, (void*) &max);
 for (i = 0; i < numberOfThreads; i++)
  pthread_join(threads[i], ((void *)0));
}

canonical_original_code:
void process(int max, int numberOfThreads) {
 int i;
 unsigned long threads[-1];
 for (i = 0; i < numberOfThreads; i++)
  pthread_create(&threads[i], ((void *)0), primalityCheck, (void *) &max);
 for (i = 0; i < numberOfThreads; i++)
  pthread_join(threads[i], ((void *)0));
}

variable_types: max int

variable_types: numberOfThreads int

variable_types: i int

variable_types:
threads
unsigned long [-1]


isPrime

repo: boutrosc/CS-Projects

decompiled_code:
__int64 __fastcall isPrime(int a1)
{
int v1; // ebx
double v2; // xmm1_8
double v3; // xmm0_8

if ( a1 == 1 )
return 0LL;
if ( a1 == 2 )
return 1LL;
if ( (a1 & 1) == 0 )
return 0LL;
v1 = 3;
v2 = (double)a1;
while ( 1 )
{
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
if ( (int)v3 < v1 )
return 1LL;
if ( !(a1 % v1) )
break;
v1 += 2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // ebx
double v2; // xmm1_8
double v3; // xmm0_8

if ( a1 == 1 )
return 0LL;
if ( a1 == 2 )
return 1LL;
if ( (a1 & 1) == 0 )
return 0LL;
v1 = 3;
v2 = (double)a1;
while ( 1 )
{
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
if ( (int)v3 < v1 )
return 1LL;
if ( !(a1 % v1) )
break;
v1 += 2;
}
return 0LL;
}

original_code:
int isPrime(int number) {
 int i;
 if (number == 1)
  return 0;
 if (number == 2)
  return 1;
 if (number % 2 == 0)
  return 0;
 for (i = 3; i <= (int) sqrt((double) number); i += 2) {
  if (number % i == 0)
   return 0;
 }
 return 1;
}

variable_types: number int

return_type: int


primalityCheck

decompiled_code:
void __fastcall __noreturn primalityCheck(void *a1)
{
int i; // edi

for ( i = COUNTER; i < *(_DWORD *)a1; COUNTER = i )
{
if ( (unsigned int)isPrime(i) == 1 )
fprintf(stdout, "%i\n", (unsigned int)COUNTER);
i = COUNTER + 1;
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(void *a1)
{
int i; // edi

for ( i = COUNTER; i < *(_DWORD *)a1; COUNTER = i )
{
if ( (unsigned int)func8(i) == 1 )
fprintf(stdout, "%i\n", (unsigned int)COUNTER);
i = COUNTER + 1;
}
pthread_exit(0LL);
}

original_code:
void* primalityCheck(void* max) {
 int* maxNum = (int*) max;
 while (COUNTER < *maxNum) {
  if (isPrime(COUNTER) == 1)
   fprintf(stdout, "%i\n", COUNTER);
  COUNTER++;
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *primalityCheck(void *max) {
 int *maxNum = (int*) max;
 while (COUNTER < *maxNum) {
  if (isPrime(COUNTER) == 1)
   fprintf(stdout, "%i\n", COUNTER);
  COUNTER++;
 }
 pthread_exit(((void *)0));
}

variable_types:
max
void *

variable_types:
maxNum
int *

return_type: void *


handleInput

decompiled_code:
void __fastcall handleInput(int a1)
{
if ( a1 != 3 )
{
fwrite("Usage : <maxNumbers> <numberOfThreads>\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
if ( a1 != 3 )
{
fwrite("Usage : <maxNumbers> <numberOfThreads>\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
}

original_code:
void handleInput(int argc) {
 if (argc != 3) {
  fprintf(stderr, "Usage : <maxNumbers> <numberOfThreads>\n");
  exit(1);
 }
}

variable_types: argc int

return_type: void


print

decompiled_code:
int __fastcall print(int a1, int a2, int a3, int a4, unsigned int a5, unsigned int a6)
{
return fprintf(
stderr,
"Max numbers: %i\nThreads: %i\nElasped time: %lf\n",
a5,
a6,
(double)(a4 - a2) / 1000000000.0 + (double)(a3 - a1));
}

canonical_decompiled_code:
int __fastcall func11(int a1, int a2, int a3, int a4, unsigned int a5, unsigned int a6)
{
return fprintf(
stderr,
"Max numbers: %i\nThreads: %i\nElasped time: %lf\n",
a5,
a6,
(double)(a4 - a2) / 1000000000.0 + (double)(a3 - a1));
}

original_code:
void print(struct timespec start, struct timespec stop, int max, int numberOfThreads) {
 double accum = (stop.tv_sec - start.tv_sec)
   + (stop.tv_nsec - start.tv_nsec) / 1E9;
 fprintf(stderr, "Max numbers: %i\nThreads: %i\nElasped time: %lf\n", max, numberOfThreads, accum);
}

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

variable_types:
stop
struct timespec

variable_types: accum double


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // ebp
struct timespec v5; // [rsp+0h] [rbp-38h] BYREF
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF

handleInput(argc, argv, envp);
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
clock_gettime(0, &v5);
process(v3, v4);
clock_gettime(0, &tp);
print(v5.tv_sec, v5.tv_nsec, tp.tv_sec, tp.tv_nsec, v3, v4);
pthread_exit(0LL);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
unsigned int v4; // ebp
struct timespec v5; // [rsp+0h] [rbp-38h] BYREF
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF

func10(argc, argv, envp);
v3 = atoi(argv[1]);
v4 = atoi(argv[2]);
clock_gettime(0, &v5);
func7(v3, v4);
clock_gettime(0, &tp);
func11(v5.tv_sec, v5.tv_nsec, tp.tv_sec, tp.tv_nsec, v3, v4);
pthread_exit(0LL);
}

original_code:
int main(int argc, char *argv[]) {
 handleInput(argc);
 int max = atoi(argv[1]), numberOfThreads = atoi(argv[2]);
 clockid_t clk_id = 0;
 struct timespec start, stop;
 clock_gettime(clk_id, &start);
 process(max, numberOfThreads);
 clock_gettime(clk_id, &stop);
 print(start, stop, max, numberOfThreads);
 pthread_exit(((void *)0));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 handleInput(argc);
 int max = atoi(argv[1]); int numberOfThreads = atoi(argv[2]);
 int clk_id = 0;
 struct timespec start; struct timespec stop;
 clock_gettime(clk_id, &start);
 process(max, numberOfThreads);
 clock_gettime(clk_id, &stop);
 print(start, stop, max, numberOfThreads);
 pthread_exit(((void *)0));
 return 0;
}

variable_types:
argv
char *[]

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


process

decompiled_code:
int __fastcall process(const char *a1, int a2, unsigned int a3, int a4, unsigned int a5, unsigned int a6, unsigned int a7)
{
FILE *v11; // r13
int result; // eax
int v13; // ebx
int v14; // er14
int v15; // eax
int i; // ebx

v11 = fopen(a1, "w");
result = fprintf(v11, "%i %i %i %i\n", (unsigned int)a2, a5, a6, a7);
if ( a3 == a4 )
{
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = fprintf(v11, "%i\n", a3);
}
}
else
{
v13 = a4 - a3;
v14 = 0;
if ( a2 > 0 )
{
do
{
v15 = rand();
++v14;
result = fprintf(v11, "%i\n", a3 + v15 % v13);
}
while ( a2 != v14 );
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, int a2, unsigned int a3, int a4, unsigned int a5, unsigned int a6, unsigned int a7)
{
FILE *v11; // r13
int result; // eax
int v13; // ebx
int v14; // er14
int v15; // eax
int i; // ebx

v11 = fopen(a1, "w");
result = fprintf(v11, "%i %i %i %i\n", (unsigned int)a2, a5, a6, a7);
if ( a3 == a4 )
{
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = fprintf(v11, "%i\n", a3);
}
}
else
{
v13 = a4 - a3;
v14 = 0;
if ( a2 > 0 )
{
do
{
v15 = rand();
++v14;
result = fprintf(v11, "%i\n", a3 + v15 % v13);
}
while ( a2 != v14 );
}
}
return result;
}


input

decompiled_code:
int input()
{
int v1; // [rsp+8h] [rbp-40h]
unsigned int v2; // [rsp+Ch] [rbp-3Ch]
int v3; // [rsp+10h] [rbp-38h]
unsigned int v4; // [rsp+14h] [rbp-34h]
unsigned int v5; // [rsp+18h] [rbp-30h]
unsigned int v6; // [rsp+1Ch] [rbp-2Ch]
char v7[40]; // [rsp+20h] [rbp-28h] BYREF

puts("Name output file : ");
__isoc99_scanf();
puts("Number of items : ");
__isoc99_scanf();
puts("Min range of item weight : ");
__isoc99_scanf();
puts("Max range of item weight : ");
__isoc99_scanf();
puts("Number of bins : ");
__isoc99_scanf();
puts("Min range of bin weight : ");
__isoc99_scanf();
puts("Max range of bin weight : ");
__isoc99_scanf();
return process(v7, v1, v2, v3, v4, v5, v6);
}

canonical_decompiled_code:
int func8()
{
int v1; // [rsp+8h] [rbp-40h]
unsigned int v2; // [rsp+Ch] [rbp-3Ch]
int v3; // [rsp+10h] [rbp-38h]
unsigned int v4; // [rsp+14h] [rbp-34h]
unsigned int v5; // [rsp+18h] [rbp-30h]
unsigned int v6; // [rsp+1Ch] [rbp-2Ch]
char v7[40]; // [rsp+20h] [rbp-28h] BYREF

puts("Name output file : ");
__isoc99_scanf();
puts("Number of items : ");
__isoc99_scanf();
puts("Min range of item weight : ");
__isoc99_scanf();
puts("Max range of item weight : ");
__isoc99_scanf();
puts("Number of bins : ");
__isoc99_scanf();
puts("Min range of bin weight : ");
__isoc99_scanf();
puts("Max range of bin weight : ");
__isoc99_scanf();
return func7(v7, v1, v2, v3, v4, v5, v6);
}

original_code:
void input() {
    int itemNum, itemMin, itemMax, binNum, binMin, binMax;
    char fname[20];
    printf("Name output file : \n");
    scanf("%s", fname);
    printf("Number of items : \n");
    scanf("%i", &itemNum);
    printf("Min range of item weight : \n");
    scanf("%i", &itemMin);
    printf("Max range of item weight : \n");
    scanf("%i", &itemMax);
    printf("Number of bins : \n");
    scanf("%i", &binNum);
    printf("Min range of bin weight : \n");
    scanf("%i", &binMin);
    printf("Max range of bin weight : \n");
    scanf("%i", &binMax);
    process(fname, itemNum, itemMin, itemMax, binNum, binMin, binMax);
}

canonical_original_code:
void input() {
    int itemNum; int itemMin; int itemMax; int binNum; int binMin; int binMax;
    char fname[20];
    printf("Name output file : \n");
    scanf("%s", fname);
    printf("Number of items : \n");
    scanf("%i", &itemNum);
    printf("Min range of item weight : \n");
    scanf("%i", &itemMin);
    printf("Max range of item weight : \n");
    scanf("%i", &itemMax);
    printf("Number of bins : \n");
    scanf("%i", &binNum);
    printf("Min range of bin weight : \n");
    scanf("%i", &binMin);
    printf("Max range of bin weight : \n");
    scanf("%i", &binMax);
    process(fname, itemNum, itemMin, itemMax, binNum, binMin, binMax);
}

variable_types: itemNum int

variable_types: itemMin int

variable_types: itemMax int

variable_types: binNum int

variable_types: binMin int

variable_types: binMax int

variable_types:
fname
char [20]


repo: boz/elfcrunch

decompiled_code:
__int64 __fastcall do_help(_QWORD *a1, const char **a2)
{
_QWORD *v2; // rbx
const char **v4; // rax
const char *v5; // rdx
const char *v7; // r8
const char **v8; // rax

if ( !a1 )
{
v7 = "no head";
LABEL_15:
fprintf(stderr, "%s/%s(): %s\n", "help.c", "do_help", v7);
return 0xFFFFFFFFLL;
}
v2 = a1;
LABEL_3:
if ( *a2 )
{
LABEL_4:
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
while ( 1 )
{
while ( 1 )
{
v4 = (const char **)v2[2];
if ( !v4 || !*v4 )
{
v7 = "bad command!";
goto LABEL_15;
}
if ( !*a2 )
break;
if ( !strcmp(*v4, *a2) )
{
++a2;
goto LABEL_3;
}
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
v5 = v4[1];
if ( !v5 )
break;
printf("%s:\t%s\n", *v4, v5);
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
v7 = "no message";
goto LABEL_15;
}
v8 = (const char **)v2[2];
if ( v8 )
{
printf("%s:\t%s\noptions:\n", *v8, v8[1]);
goto LABEL_4;
}
fprintf(stderr, "%s/%s(): %s\n", "help.c", "do_help", "no command here");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, const char **a2)
{
_QWORD *v2; // rbx
const char **v4; // rax
const char *v5; // rdx
const char *v7; // r8
const char **v8; // rax

if ( !a1 )
{
v7 = "no head";
LABEL_15:
fprintf(stderr, "%s/%s(): %s\n", "help.c", "do_help", v7);
return 0xFFFFFFFFLL;
}
v2 = a1;
LABEL_3:
if ( *a2 )
{
LABEL_4:
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
while ( 1 )
{
while ( 1 )
{
v4 = (const char **)v2[2];
if ( !v4 || !*v4 )
{
v7 = "bad command!";
goto LABEL_15;
}
if ( !*a2 )
break;
if ( !strcmp(*v4, *a2) )
{
++a2;
goto LABEL_3;
}
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
v5 = v4[1];
if ( !v5 )
break;
printf("%s:\t%s\n", *v4, v5);
v2 = (_QWORD *)*v2;
if ( !v2 )
return 0LL;
}
v7 = "no message";
goto LABEL_15;
}
v8 = (const char **)v2[2];
if ( v8 )
{
printf("%s:\t%s\noptions:\n", *v8, v8[1]);
goto LABEL_4;
}
fprintf(stderr, "%s/%s(): %s\n", "help.c", "do_help", "no command here");
return 0xFFFFFFFFLL;
}

original_code:
int do_help( cmd_node_t * head , char **argv )
{
   cmd_node_t * cur;
   int ret = 0;
   if(!head)
      do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "no head" ); return( ((int)-1) );} while(0);;
   if(! *argv ) {
      if( ! head->cmd )
         do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "no command here" ); return( ((int)-1) );} while(0);;
      printf("%s:\t%s\noptions:\n",head->cmd->str,head->cmd->msg);
   }
   for( cur = head->opts ; cur ; cur = cur->next ){
      if(! cur->cmd || !cur->cmd->str )
            do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "bad command!" ); return( ((int)-1) );} while(0);;
      if(!*argv)
      {
         if(!cur->cmd->msg)
            do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "no message" ); return( ((int)-1) );} while(0);;
         printf("%s:\t%s\n",cur->cmd->str,cur->cmd->msg);
      }
      else
      {
         if( !strcmp(cur->cmd->str , argv[0] ) )
         {
            ret = do_help( cur , argv + 1 );
            break;
         }
      }
   }
   return(ret);
}

canonical_original_code:
int do_help(struct _cmd_node_t *head, char **argv)
{
   struct _cmd_node_t *cur;
   int ret = 0;
   if(!head)
      do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "no head" ); return( ((int)-1) );} while(0);;
   if(! *argv ) {
      if( ! head->cmd )
         do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "no command here" ); return( ((int)-1) );} while(0);;
      printf("%s:\t%s\noptions:\n",head->cmd->str,head->cmd->msg);
   }
   for( cur = head->opts ; cur ; cur = cur->next ){
      if(! cur->cmd || !cur->cmd->str )
            do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "bad command!" ); return( ((int)-1) );} while(0);;
      if(!*argv)
      {
         if(!cur->cmd->msg)
            do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "no message" ); return( ((int)-1) );} while(0);;
         printf("%s:\t%s\n",cur->cmd->str,cur->cmd->msg);
      }
      else
      {
         if( !strcmp(cur->cmd->str , argv[0] ) )
         {
            ret = do_help( cur , argv + 1 );
            break;
         }
      }
   }
   return(ret);
}

variable_types: struct _cmd_node_t { struct _cmd_node_t *next; struct _cmd_node_t *opts; struct cmd_t { char *str; char *msg; int (*func)(char **); } *cmd; } *

variable_types:
argv
char **

variable_types: ret int

user_defined_types: struct _cmd_node_t { struct _cmd_node_t *next; struct _cmd_node_t *opts; struct cmd_t *cmd; }


decompiled_code:
int __fastcall command_help(const char **a1)
{
_QWORD *v1; // rax
const char *v2; // r8
_QWORD *v3; // rbp
int result; // eax
_QWORD *v5; // rbx
const char *v6; // rdx
const char **v7; // rax

v1 = (_QWORD *)get_command_head();
v2 = "can't get commands";
if ( !v1 )
{
LABEL_11:
fprintf(stderr, "%s/%s(): %s\n", "help.c", "command_help", v2);
return -1;
}
v3 = v1;
if ( *a1 )
return do_help(v1, a1);
result = printf("%s:\t%s\noptions:\n", command_h[0], command_h[1]);
v5 = (_QWORD *)v3[1];
if ( v5 )
{
while ( 1 )
{
v7 = (const char **)v5[2];
if ( !v7 )
break;
if ( !*v7 )
break;
v6 = v7[1];
if ( !v6 )
break;
result = printf("%s:\t%s\n", *v7, v6);
v5 = (_QWORD *)*v5;
if ( !v5 )
return result;
}
v2 = "command has no name";
goto LABEL_11;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char **a1)
{
_QWORD *v1; // rax
const char *v2; // r8
_QWORD *v3; // rbp
int result; // eax
_QWORD *v5; // rbx
const char *v6; // rdx
const char **v7; // rax

v1 = (_QWORD *)get_command_head();
v2 = "can't get commands";
if ( !v1 )
{
LABEL_11:
fprintf(stderr, "%s/%s(): %s\n", "help.c", "command_help", v2);
return -1;
}
v3 = v1;
if ( *a1 )
return func0(v1, a1);
result = printf("%s:\t%s\noptions:\n", command_h[0], command_h[1]);
v5 = (_QWORD *)v3[1];
if ( v5 )
{
while ( 1 )
{
v7 = (const char **)v5[2];
if ( !v7 )
break;
if ( !*v7 )
break;
v6 = v7[1];
if ( !v6 )
break;
result = printf("%s:\t%s\n", *v7, v6);
v5 = (_QWORD *)*v5;
if ( !v5 )
return result;
}
v2 = "command has no name";
goto LABEL_11;
}
return result;
}

original_code:
int command_help( char** argv ){
   cmd_node_t * cmds;
   if(!(cmds = get_command_head()))
      do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "can't get commands" ); return( ((int)-1) );} while(0);;
   if(!*argv){
      printf("%s:\t%s\noptions:\n",command_h.str,command_h.msg);
      for(cmds = cmds->opts; cmds ; cmds=cmds->next){
         if(!cmds->cmd ||!cmds->cmd->str ||!cmds->cmd->msg )
            do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "command has no name" ); return( ((int)-1) );} while(0);;
         printf("%s:\t%s\n",cmds->cmd->str,cmds->cmd->msg);
      }
   }
   else
   {
      return( do_help( cmds , argv ) );
   }
}

canonical_original_code:
int command_help(char **argv){
   struct _cmd_node_t *cmds;
   if(!(cmds = get_command_head()))
      do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "can't get commands" ); return( ((int)-1) );} while(0);;
   if(!*argv){
      printf("%s:\t%s\noptions:\n",command_h.str,command_h.msg);
      for(cmds = cmds->opts; cmds ; cmds=cmds->next){
         if(!cmds->cmd ||!cmds->cmd->str ||!cmds->cmd->msg )
            do { fprintf(stderr,"%s/%s(): %s\n", "help.c" ,__func__ , "command has no name" ); return( ((int)-1) );} while(0);;
         printf("%s:\t%s\n",cmds->cmd->str,cmds->cmd->msg);
      }
   }
   else
   {
      return( do_help( cmds , argv ) );
   }
}

user_defined_types: struct cmd_t { char *str; char *msg; int (*func)(char **); }


decompiled_code:
__int64 register_help()
{
return register_command("/", command_h);
}

canonical_decompiled_code:
__int64 func2()
{
return register_command("/", command_h);
}

original_code:
int register_help()
{
   return( register_command( "/" , &command_h ) );
}


decompiled_code:
void *get_command_head()
{
return &command_head;
}

canonical_decompiled_code:
void *func0()
{
return &command_head;
}

original_code: cmd_node_t * get_command_head() { return &command_head; }

canonical_original_code: struct _cmd_node_t *get_command_head() { return &command_head; }

return_type: struct _cmd_node_t { struct _cmd_node_t *next; struct _cmd_node_t *opts; struct cmd_t { char *str; char *msg; int (*func)(char **); } *cmd; } *


decompiled_code:
__int64 __fastcall is_good_path(_BYTE *a1)
{
__int64 result; // rax
_BYTE *v2; // rbx
char v3; // bp
int v4; // eax

if ( !a1 )
return 0LL;
result = 0LL;
v2 = a1;
if ( *a1 == 47 )
{
while ( 1 )
{
v3 = *++v2;
if ( !v3 )
break;
v4 = isalnum(v3);
if ( v3 != 47 && !v4 )
return 0LL;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
__int64 result; // rax
_BYTE *v2; // rbx
char v3; // bp
int v4; // eax

if ( !a1 )
return 0LL;
result = 0LL;
v2 = a1;
if ( *a1 == 47 )
{
while ( 1 )
{
v3 = *++v2;
if ( !v3 )
break;
v4 = isalnum(v3);
if ( v3 != 47 && !v4 )
return 0LL;
}
result = 1LL;
}
return result;
}

original_code:
int is_good_path( char * path )
{
   if( !path || *path != '/' )
      return (0);
   while( *++path != 0 )
      if( !( isalnum(*path) || *path == '/' ) )
         return(0);
   return(1);
}

canonical_original_code:
int is_good_path(char *path)
{
   if( !path || *path != '/' )
      return (0);
   while( *++path != 0 )
      if( !( isalnum(*path) || *path == '/' ) )
         return(0);
   return(1);
}

variable_types:
path
char *


decompiled_code:
__int64 __fastcall insert_command(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rax
char *v5; // r12
__int64 **v6; // rsi
const char *v8; // r8

if ( a2 == 0 || a1 == 0 || !a3 )
{
v8 = "null arg";
}
else
{
v4 = strchr((const char *)(a1 + 1), 47);
v5 = v4;
if ( !v4 )
{
*(_QWORD *)(a2 + 8) = add_comm_to_list(*(_QWORD **)(a2 + 8), a3);
return 0LL;
}
*v4 = 0;
v6 = find_command(*(__int64 ***)(a2 + 8), (const char *)(a1 + 1));
if ( v6 )
{
*v5 = 47;
if ( (int)insert_command(v5, v6, a3) >= 0 )
return 0LL;
v8 = "recursive badness";
}
else
{
v8 = "request sub-command, but none available";
}
}
fprintf(stderr, "%s/%s(): %s\n", "commands.c", "insert_command", v8);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
char *v4; // rax
char *v5; // r12
__int64 **v6; // rsi
const char *v8; // r8

if ( a2 == 0 || a1 == 0 || !a3 )
{
v8 = "null arg";
}
else
{
v4 = strchr((const char *)(a1 + 1), 47);
v5 = v4;
if ( !v4 )
{
*(_QWORD *)(a2 + 8) = add_comm_to_list(*(_QWORD **)(a2 + 8), a3);
return 0LL;
}
*v4 = 0;
v6 = find_command(*(__int64 ***)(a2 + 8), (const char *)(a1 + 1));
if ( v6 )
{
*v5 = 47;
if ( (int)func2(v5, v6, a3) >= 0 )
return 0LL;
v8 = "recursive badness";
}
else
{
v8 = "request sub-command, but none available";
}
}
fprintf(stderr, "%s/%s(): %s\n", "commands.c", "insert_command", v8);
return 0xFFFFFFFFLL;
}

original_code:
int insert_command( char * path , cmd_node_t * head , cmd_t * comm )
{
   if( !comm || ! path || ! head )
      do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "null arg" ); return( -1 );} while(0);;
   char * nextstr;
   if( !(nextstr = strchr( path + 1 , '/' )) ) {
      head->opts = add_comm_to_list( head->opts , comm );
   }
   else
   {
      *nextstr = 0;
      cmd_node_t * nextnode ;
      if(!(nextnode = find_command( head->opts , path + 1 )))
         do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "request sub-command, but none available" ); return( -1 );} while(0);;
      *nextstr = '/';
      if( insert_command( nextstr , nextnode , comm ) < 0 )
         do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "recursive badness" ); return( -1 );} while(0);;
   }
   return(0);
}

canonical_original_code:
int insert_command(char *path, struct _cmd_node_t *head, struct cmd_t *comm)
{
   if( !comm || ! path || ! head )
      do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "null arg" ); return( -1 );} while(0);;
   char *nextstr;
   if( !(nextstr = strchr( path + 1 , '/' )) ) {
      head->opts = add_comm_to_list( head->opts , comm );
   }
   else
   {
      *nextstr = 0;
      struct _cmd_node_t *nextnode;
      if(!(nextnode = find_command( head->opts , path + 1 )))
         do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "request sub-command, but none available" ); return( -1 );} while(0);;
      *nextstr = '/';
      if( insert_command( nextstr , nextnode , comm ) < 0 )
         do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "recursive badness" ); return( -1 );} while(0);;
   }
   return(0);
}

variable_types:
comm
struct cmd_t *

variable_types:
nextstr
char *


decompiled_code:
__int64 __fastcall register_command(char *s, __int64 a2)
{
char *v2; // rdi
_QWORD *v4; // rax
const char *v5; // r8

if ( s && (unsigned int)is_good_path(s) )
{
if ( !qword_398 )
{
v4 = calloc(1uLL, 0x18uLL);
v4[2] = a2;
qword_398 = (__int64)v4;
return 0LL;
}
v2 = strdup(s);
if ( (int)insert_command((__int64)v2, (__int64)&command_head, a2) >= 0 )
{
free(v2);
return 0LL;
}
free(v2);
v5 = "can't insert";
}
else
{
v5 = "bad arg";
}
fprintf(stderr, "%s/%s(): %s\n", "commands.c", "register_command", v5);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, __int64 a2)
{
char *v2; // rdi
_QWORD *v4; // rax
const char *v5; // r8

if ( s && (unsigned int)func1(s) )
{
if ( !qword_398 )
{
v4 = calloc(1uLL, 0x18uLL);
v4[2] = a2;
qword_398 = (__int64)v4;
return 0LL;
}
v2 = strdup(s);
if ( (int)func2((__int64)v2, (__int64)&command_head, a2) >= 0 )
{
free(v2);
return 0LL;
}
free(v2);
v5 = "can't insert";
}
else
{
v5 = "bad arg";
}
fprintf(stderr, "%s/%s(): %s\n", "commands.c", "register_command", v5);
return 0xFFFFFFFFLL;
}

original_code:
int register_command( char * path , cmd_t * comm ){
   if(!path || !is_good_path(path) )
      do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "bad arg" ); return( -1 );} while(0);;
   cmd_node_t * head = command_head.opts;
   if( ! head ) {
      head = calloc( 1 , sizeof(*head) );
      head->cmd = comm;
      command_head.opts = head;
   } else {
      char * npath = strdup(path);
      if( insert_command( npath , &command_head , comm ) < 0 ) {
         free(npath);
         do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "can't insert" ); return( -1 );} while(0);;
      }
      free(npath);
   }
   return(0);
}

canonical_original_code:
int register_command(char *path, struct cmd_t *comm){
   if(!path || !is_good_path(path) )
      do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "bad arg" ); return( -1 );} while(0);;
   struct _cmd_node_t *head = command_head.opts;
   if( ! head ) {
      head = calloc( 1 , sizeof(*head) );
      head->cmd = comm;
      command_head.opts = head;
   } else {
      char *npath = strdup(path);
      if( insert_command( npath , &command_head , comm ) < 0 ) {
         free(npath);
         do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "can't insert" ); return( -1 );} while(0);;
      }
      free(npath);
   }
   return(0);
}

variable_types: struct cmd_t { char *str; char *msg; int (*func)(char **); } *

variable_types:
npath
char *


decompiled_code:
__int64 __fastcall run_commands(__int64 **a1, const char **a2)
{
__int64 **v2; // rbx
const char **v3; // rbp
__int64 **v4; // rax
__int64 *v5; // rax
const char *v7; // r8

if ( a2 && (v2 = a1, v3 = a2, a1) )
{
while ( 1 )
{
v4 = find_command((__int64 **)v2[1], *v3);
if ( !v4 )
break;
++v3;
v2 = v4;
}
v5 = v2[2];
if ( v5 )
return ((__int64 (__fastcall *)(const char **))v5[2])(v3);
v7 = "no command";
}
else
{
v7 = "null args";
}
fprintf(stderr, "%s/%s(): %s\n", "commands.c", "run_commands", v7);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 **a1, const char **a2)
{
__int64 **v2; // rbx
const char **v3; // rbp
__int64 **v4; // rax
__int64 *v5; // rax
const char *v7; // r8

if ( a2 && (v2 = a1, v3 = a2, a1) )
{
while ( 1 )
{
v4 = find_command((__int64 **)v2[1], *v3);
if ( !v4 )
break;
++v3;
v2 = v4;
}
v5 = v2[2];
if ( v5 )
return ((__int64 (__fastcall *)(const char **))v5[2])(v3);
v7 = "no command";
}
else
{
v7 = "null args";
}
fprintf(stderr, "%s/%s(): %s\n", "commands.c", "run_commands", v7);
return 0xFFFFFFFFLL;
}

original_code:
int run_commands( cmd_node_t * head , char ** cvec )
{
   int ret;
   if(!head || !cvec ) do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "null args" ); return( -1 );} while(0);;
   cmd_node_t * next;
   if(!(next = find_command( head->opts , cvec[0] )))
   {
      if( head->cmd )
         ret = head->cmd->func( cvec );
      else
         do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "no command" ); return( -1 );} while(0);;
   }
   else
      ret = run_commands( next , ++cvec );
   return(ret);
}

canonical_original_code:
int run_commands(struct _cmd_node_t *head, char **cvec)
{
   int ret;
   if(!head || !cvec ) do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "null args" ); return( -1 );} while(0);;
   struct _cmd_node_t *next;
   if(!(next = find_command( head->opts , cvec[0] )))
   {
      if( head->cmd )
         ret = head->cmd->func( cvec );
      else
         do { fprintf(stderr,"%s/%s(): %s\n", "commands.c" ,__func__ , "no command" ); return( -1 );} while(0);;
   }
   else
      ret = run_commands( next , ++cvec );
   return(ret);
}

variable_types:
cvec
char **


decompiled_code:
__int64 __fastcall run_command(const char **a1)
{
return run_commands(&command_head, a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char **a1)
{
return func4(&command_head, a1);
}

original_code:
int run_command( char ** cvec )
{
   return( run_commands( &command_head , cvec ) );
}

canonical_original_code:
int run_command(char **cvec)
{
   return( run_commands( &command_head , cvec ) );
}


decompiled_code:
__int64 __fastcall print_node(const char **a1)
{
printf("%02d\t%s\n", *(unsigned int *)a1, a1[1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
printf("%02d\t%s\n", *(unsigned int *)a1, a1[1]);
return 0LL;
}

original_code:
int print_node( btree_data_t * data , void * arg )
{
   printf("%02d\t%s\n",data->key, (char*)data->data);
   return(0);
}

canonical_original_code:
int print_node(struct btree_data_t *data, void *arg)
{
   printf("%02d\t%s\n",data->key, (char *)data->data);
   return(0);
}

variable_types: struct btree_data_t { unsigned int key; void *data; } *

variable_types:
arg
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
int v5; // [rsp+0h] [rbp-18h] BYREF
char *v6; // [rsp+8h] [rbp-10h]

v5 = 10;
v3 = new_btree(argc, argv, envp);
v6 = strdup("ten");
btree_insert(v3, &v5);
v5 = 15;
v6 = strdup("fifteen");
btree_insert(v3, &v5);
v5 = 12;
v6 = strdup("twelve");
btree_insert(v3, &v5);
v5 = 20;
v6 = strdup("twenty");
btree_insert(v3, &v5);
v5 = 5;
v6 = strdup("five");
btree_insert(v3, &v5);
v5 = 8;
v6 = strdup("eight");
btree_insert(v3, &v5);
v5 = 3;
v6 = strdup("three");
btree_insert(v3, &v5);
puts("preorder:");
btree_traverse(v3, print_node, 0LL, 0LL);
puts("inorder:");
btree_traverse(v3, print_node, 0LL, 1LL);
puts("postorder:");
btree_traverse(v3, print_node, 0LL, 2LL);
free_btree(v3);
return 0;
}

original_code:
int main( int argc , char *argv[] )
{
   btree_data_t data;
   btree_t * tree;
   tree = new_btree();
   data.key = 10;
   data.data = strdup( "ten" );
   btree_insert(tree,&data);
   data.key = 15;
   data.data = strdup( "fifteen" );
   btree_insert(tree,&data);
   data.key = 12;
   data.data = strdup( "twelve" );
   btree_insert(tree,&data);
   data.key = 20;
   data.data = strdup( "twenty" );
   btree_insert(tree,&data);
   data.key = 5;
   data.data = strdup( "five" );
   btree_insert(tree,&data);
   data.key = 8;
   data.data = strdup( "eight" );
   btree_insert(tree,&data);
   data.key = 3;
   data.data = strdup( "three" );
   btree_insert(tree,&data);
   printf("preorder:\n");
   btree_traverse(tree,print_node,((void *)0),0);
   printf("inorder:\n");
   btree_traverse(tree,print_node,((void *)0),1);
   printf("postorder:\n");
   btree_traverse(tree,print_node,((void *)0),2);
   free_btree(tree);
   return(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   struct btree_data_t data;
   struct btree_t_ *tree;
   tree = new_btree();
   data.key = 10;
   data.data = strdup( "ten" );
   btree_insert(tree,&data);
   data.key = 15;
   data.data = strdup( "fifteen" );
   btree_insert(tree,&data);
   data.key = 12;
   data.data = strdup( "twelve" );
   btree_insert(tree,&data);
   data.key = 20;
   data.data = strdup( "twenty" );
   btree_insert(tree,&data);
   data.key = 5;
   data.data = strdup( "five" );
   btree_insert(tree,&data);
   data.key = 8;
   data.data = strdup( "eight" );
   btree_insert(tree,&data);
   data.key = 3;
   data.data = strdup( "three" );
   btree_insert(tree,&data);
   printf("preorder:\n");
   btree_traverse(tree,print_node,((void *)0),0);
   printf("inorder:\n");
   btree_traverse(tree,print_node,((void *)0),1);
   printf("postorder:\n");
   btree_traverse(tree,print_node,((void *)0),2);
   free_btree(tree);
   return(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct btree_t_ { struct bnode_t_ { struct btree_data_t { unsigned int key; void *data; } data; struct bnode_t_ *lchld; struct bnode_t_ *rchld; } *root; void (*free_node_data)(struct bnode_t_ *node); } *

user_defined_types: struct btree_t_ { struct bnode_t_ *root; void (*free_node_data)(struct bnode_t_ *node); }

user_defined_types: struct bnode_t_ { struct btree_data_t data; struct bnode_t_ *lchld; struct bnode_t_ *rchld; }


decompiled_code:
void __fastcall free_data(__int64 a1)
{
void *v1; // rdi

if ( a1 )
{
v1 = *(void **)(a1 + 8);
if ( v1 )
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
void *v1; // rdi

if ( a1 )
{
v1 = *(void **)(a1 + 8);
if ( v1 )
free(v1);
}
}

original_code:
void free_data( bnode_t * node )
{
   if(node)
      if( node->data.data ) free( node->data.data );
}

canonical_original_code:
void free_data(struct bnode_t_ *node)
{
   if(node)
      if( node->data.data ) free( node->data.data );
}

variable_types: struct bnode_t_ { struct btree_data_t { unsigned int key; void *data; } data; struct bnode_t_ *lchld; struct bnode_t_ *rchld; } *


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

result = xcalloc(1LL, 16LL);
*(_QWORD *)(result + 8) = free_data;
return result;
}

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

result = xcalloc(1LL, 16LL);
*(_QWORD *)(result + 8) = free_data;
return result;
}

original_code:
btree_t * new_btree()
{
   btree_t * tree;
   tree = xcalloc(1,sizeof(*tree));
   tree->free_node_data = free_data;
   return(tree);
}

canonical_original_code:
struct btree_t_ *new_btree()
{
   struct btree_t_ *tree;
   tree = xcalloc(1,sizeof(*tree));
   tree->free_node_data = free_data;
   return(tree);
}

return_type: struct btree_t_ { struct bnode_t_ { struct btree_data_t { unsigned int key; void *data; } data; struct bnode_t_ *lchld; struct bnode_t_ *rchld; } *root; void (*free_node_data)(struct bnode_t_ *node); } *


decompiled_code:
void __fastcall btree_destroy(__int64 a1, _QWORD *a2)
{
if ( a2 )
{
btree_destroy(a1, a2[2]);
btree_destroy(a1, a2[3]);
(*(void (__fastcall **)(_QWORD *))(a1 + 8))(a2);
free(a2);
}
}

original_code:
void btree_destroy( btree_t * tree , bnode_t * root )
{
   if( root )
   {
      btree_destroy( tree , root->lchld );
      btree_destroy( tree , root->rchld );
      tree->free_node_data( root );
      if( root ) free( root );
   }
}

canonical_original_code:
void btree_destroy(struct btree_t_ *tree, struct bnode_t_ *root)
{
   if( root )
   {
      btree_destroy( tree , root->lchld );
      btree_destroy( tree , root->rchld );
      tree->free_node_data( root );
      if( root ) free( root );
   }
}

variable_types:
root
struct bnode_t_ *

user_defined_types: struct btree_data_t { unsigned int key; void *data; }


decompiled_code:
__int64 __fastcall btree_find_child(__int64 a1, unsigned int a2)
{
__int64 v2; // rax

while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == a2 )
break;
v2 = *(_QWORD *)(a1 + 16);
if ( *(_DWORD *)a1 < a2 )
v2 = *(_QWORD *)(a1 + 24);
a1 = v2;
}
return a1;
}

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

while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == a2 )
break;
v2 = *(_QWORD *)(a1 + 16);
if ( *(_DWORD *)a1 < a2 )
v2 = *(_QWORD *)(a1 + 24);
a1 = v2;
}
return a1;
}

original_code:
bnode_t * btree_find_child( bnode_t * root , nkey_t key )
{
   bnode_t * ret;
   if(!root)
      ret = ((void *)0);
   else if( key == root->data.key )
      ret = root;
   else if ( key > root->data.key )
      ret = btree_find_child( root->rchld , key );
   else
      ret = btree_find_child( root->lchld , key );
   return( ret );
}

canonical_original_code:
struct bnode_t_ *btree_find_child(struct bnode_t_ *root, unsigned int key)
{
   struct bnode_t_ *ret;
   if(!root)
      ret = ((void *)0);
   else if( key == root->data.key )
      ret = root;
   else if ( key > root->data.key )
      ret = btree_find_child( root->rchld , key );
   else
      ret = btree_find_child( root->lchld , key );
   return( ret );
}

variable_types:
key
unsigned int

return_type: struct bnode_t_ { struct btree_data_t { unsigned int key; void *data; } data; struct bnode_t_ *lchld; struct bnode_t_ *rchld; } *


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

result = btree_find(a1, a2);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

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

result = func6(a1, a2);
if ( result )
result = *(_QWORD *)(result + 8);
return result;
}

original_code:
void * btree_find_data( btree_t * tree , nkey_t key )
{
   bnode_t * node;
   if(!( node = btree_find(tree,key)))
      return(((void *)0));
   return( node->data.data );
}

canonical_original_code:
void *btree_find_data(struct btree_t_ *tree, unsigned int key)
{
   struct bnode_t_ *node;
   if(!( node = btree_find(tree,key)))
      return(((void *)0));
   return( node->data.data );
}


decompiled_code:
__int64 __fastcall btree_postorder_traverse(__int64 a1, __int64 (__fastcall *a2)(__int64, __int64), __int64 a3)
{
__int64 result; // rax

if ( a1 )
{
btree_postorder_traverse(*(_QWORD *)(a1 + 24));
btree_postorder_traverse(*(_QWORD *)(a1 + 16));
result = a2(a1, a3);
}
return result;
}

original_code:
void btree_postorder_traverse( bnode_t * node ,
                              btree_callback func ,
                              void * data )
{
   if(node)
   {
      btree_postorder_traverse( node->rchld , func , data);
      btree_postorder_traverse( node->lchld , func , data);
      func( &(node->data) , data );
   }
}

canonical_original_code:
void btree_postorder_traverse(struct bnode_t_ *node, int (*func)(struct btree_data_t *, void *), void *data)
{
   if(node)
   {
      btree_postorder_traverse( node->rchld , func , data);
      btree_postorder_traverse( node->lchld , func , data);
      func( &(node->data) , data );
   }
}

variable_types:
func
int (*)(struct btree_data_t *, void *)

variable_types:
data
void *


decompiled_code:
__int64 __fastcall list_default_keycheck(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
return (unsigned int)(*a1 - *a2);
}

original_code:
int list_default_keycheck( list_data_t * a , list_data_t * b )
{
   return( a->key - b->key );
}

canonical_original_code:
int list_default_keycheck(struct list_data_ *a, struct list_data_ *b)
{
   return( a->key - b->key );
}

variable_types: struct list_data_ { unsigned int key; void *data; } *

variable_types:
b
struct list_data_ *


decompiled_code:
__int64 __fastcall new_list(__int64 (__fastcall *a1)(_DWORD *a1, _DWORD *a2))
{
__int64 (__fastcall *v1)(_DWORD *, _DWORD *); // rbx
__int64 result; // rax

v1 = a1;
result = xcalloc(1LL, 40LL);
if ( !a1 )
v1 = list_default_keycheck;
*(_QWORD *)(result + 32) = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 (__fastcall *a1)(_DWORD *a1, _DWORD *a2))
{
__int64 (__fastcall *v1)(_DWORD *, _DWORD *); // rbx
__int64 result; // rax

v1 = a1;
result = xcalloc(1LL, 40LL);
if ( !a1 )
v1 = list_default_keycheck;
*(_QWORD *)(result + 32) = v1;
return result;
}

original_code:
list_t * new_list( list_cmp_func func )
{
   list_t * list;
   list = xcalloc( 1,sizeof(*list));
   list->cmp = (func) ? (func) : (list_default_keycheck);
   return(list);
}

canonical_original_code:
struct list_ *new_list(int (*func)(struct list_data_ *a, struct list_data_ *b))
{
   struct list_ *list;
   list = xcalloc( 1,sizeof(*list));
   list->cmp = (func) ? (func) : (list_default_keycheck);
   return(list);
}

variable_types: int (*)(struct list_data_ *a, struct list_data_ *b)

variable_types: struct list_ { struct list_node_ { struct list_node_ *next; struct list_data_ { unsigned int key; void *data; } data; } head; int size; int (*cmp)(struct list_data_ *a, struct list_data_ *b); } *

user_defined_types: struct list_ { struct list_node_ head; int size; int (*cmp)(struct list_data_ *a, struct list_data_ *b); }

user_defined_types: struct list_node_ { struct list_node_ *next; struct list_data_ data; }


decompiled_code:
__int64 __fastcall list_free_list(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbp
void *v3; // r12
__int64 result; // rax

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
v3 = 0LL;
while ( 1 )
{
if ( a2 )
a2(v2[2]);
if ( v3 )
free(v3);
v3 = v2;
if ( !*v2 )
break;
v2 = (_QWORD *)*v2;
}
free(v2);
}
free(ptr);
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "list.c", "list_free_list", "bad args");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbp
void *v3; // r12
__int64 result; // rax

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
v3 = 0LL;
while ( 1 )
{
if ( a2 )
a2(v2[2]);
if ( v3 )
free(v3);
v3 = v2;
if ( !*v2 )
break;
v2 = (_QWORD *)*v2;
}
free(v2);
}
free(ptr);
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "list.c", "list_free_list", "bad args");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int list_free_list( list_t * list , free_cb cb )
{
   if(!list) do { fprintf(stderr,"%s/%s(): %s\n", "list.c" ,__func__ , "bad args" ); return( -1 );} while(0);;
   list_node_t * cur,
               * prev;
   prev = ((void *)0);
   cur = (&list->head)->next;
   for( cur = (&list->head)->next ; cur ; cur = cur->next ){
      if(cb) (*cb)(cur->data.data);
      if(prev)
      {
         free( prev );
      }
      prev = cur;
   }
   if(prev)
   {
      free( prev );
   }
   free( list );
   return(0);
}

canonical_original_code:
int list_free_list(struct list_ *list, int (*cb)(void *a))
{
   if(!list) do { fprintf(stderr,"%s/%s(): %s\n", "list.c" ,__func__ , "bad args" ); return( -1 );} while(0);;
   struct list_node_ *cur; struct list_node_ *prev;
   prev = ((void *)0);
   cur = (&list->head)->next;
   for( cur = (&list->head)->next ; cur ; cur = cur->next ){
      if(cb) (*cb)(cur->data.data);
      if(prev)
      {
         free( prev );
      }
      prev = cur;
   }
   if(prev)
   {
      free( prev );
   }
   free( list );
   return(0);
}

variable_types:
cb
int (*)(void *a)

variable_types: struct list_node_ { struct list_node_ *next; struct list_data_ { unsigned int key; void *data; } data; } *


original_code:
int list_insert( list_t * list , list_data_t * data )
{
   nkey_t key;
   list_node_t * node;
   list_node_t * cur,
               * prev;
   if(!data||!list) do { fprintf(stderr,"%s/%s(): %s\n", "list.c" ,__func__ , "null args" ); return( -1 );} while(0);;
   prev = &list->head;
   for( cur = prev->next ; cur; cur = cur->next )
   {
      if( list->cmp( data , &cur->data ) <= 0 )
         break;
      prev = cur;
   }
   node = xcalloc( 1 , sizeof( list_node_t ));
   prev->next = node;
   node->next = cur;
   node->data = *data;
   list->size++;
   return(0);
}

canonical_original_code:
int list_insert(struct list_ *list, struct list_data_ *data)
{
   unsigned int key;
   struct list_node_ *node;
   struct list_node_ *cur; struct list_node_ *prev;
   if(!data||!list) do { fprintf(stderr,"%s/%s(): %s\n", "list.c" ,__func__ , "null args" ); return( -1 );} while(0);;
   prev = &list->head;
   for( cur = prev->next ; cur; cur = cur->next )
   {
      if( list->cmp( data , &cur->data ) <= 0 )
         break;
      prev = cur;
   }
   node = xcalloc( 1 , sizeof( list_node_t ));
   prev->next = node;
   node->next = cur;
   node->data = *data;
   list->size++;
   return(0);
}

variable_types:
data
struct list_data_ *

user_defined_types: struct list_data_ { unsigned int key; void *data; }


decompiled_code:
__int64 __fastcall list_map_over_data(_QWORD *a1, int (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
_QWORD *v3; // rbx
__int64 result; // rax

if ( a2 )
{
if ( a1 && (v3 = (_QWORD *)*a1) != 0LL )
{
while ( a2(v3[2], a3) >= 0 )
{
v3 = (_QWORD *)*v3;
if ( !v3 )
goto LABEL_8;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_8:
result = 0LL;
}
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "list.c", "list_map_over_data", "bad args");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int (__fastcall *a2)(_QWORD, __int64), __int64 a3)
{
_QWORD *v3; // rbx
__int64 result; // rax

if ( a2 )
{
if ( a1 && (v3 = (_QWORD *)*a1) != 0LL )
{
while ( a2(v3[2], a3) >= 0 )
{
v3 = (_QWORD *)*v3;
if ( !v3 )
goto LABEL_8;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_8:
result = 0LL;
}
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "list.c", "list_map_over_data", "bad args");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int list_map_over_data( list_t * list , list_callback cb , void * arg )
{
   list_node_t * cur;
   if(!cb) do { fprintf(stderr,"%s/%s(): %s\n", "list.c" ,__func__ , "bad args" ); return( -1 );} while(0);;
   if( list ) {
      for( cur = (&list->head)->next ; cur ; cur = cur->next ){
         if( (*cb)(cur->data.data,arg) <0)
            return(-1);
      }
   }
   return(0);
}

canonical_original_code:
int list_map_over_data(struct list_ *list, int (*cb)(void *a, void *arg), void *arg)
{
   struct list_node_ *cur;
   if(!cb) do { fprintf(stderr,"%s/%s(): %s\n", "list.c" ,__func__ , "bad args" ); return( -1 );} while(0);;
   if( list ) {
      for( cur = (&list->head)->next ; cur ; cur = cur->next ){
         if( (*cb)(cur->data.data,arg) <0)
            return(-1);
      }
   }
   return(0);
}

variable_types:
cb
int (*)(void *a, void *arg)


decompiled_code:
__int64 __fastcall get_dsymcount(__int64 a1)
{
int v1; // ebx
__int64 result; // rax
const char *v3; // r8

if ( !a1 )
{
v3 = "null arg";
goto LABEL_8;
}
v1 = rel_plt_max_sym_indx();
if ( v1 < 0 )
{
v3 = "rel_plt symcount";
LABEL_8:
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "get_dsymcount", v3);
return 0xFFFFFFFFLL;
}
result = rel_max_dsym_indx(a1);
if ( (int)result < 0 )
{
v3 = "rel symcount";
goto LABEL_8;
}
if ( v1 >= (int)result )
result = (unsigned int)v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebx
__int64 result; // rax
const char *v3; // r8

if ( !a1 )
{
v3 = "null arg";
goto LABEL_8;
}
v1 = rel_plt_max_sym_indx();
if ( v1 < 0 )
{
v3 = "rel_plt symcount";
LABEL_8:
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "get_dsymcount", v3);
return 0xFFFFFFFFLL;
}
result = rel_max_dsym_indx(a1);
if ( (int)result < 0 )
{
v3 = "rel symcount";
goto LABEL_8;
}
if ( v1 >= (int)result )
result = (unsigned int)v1;
return result;
}

original_code:
int get_dsymcount( elf_t * elf )
{
   if( ! elf )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "null arg" ); return( -1 );} while(0);;
   int relsc,
       relpltsc,
       max;
   if((relpltsc = rel_plt_max_sym_indx( elf )) < 0 )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "rel_plt symcount" ); return( -1 );} while(0);;
   if((relsc = rel_max_dsym_indx( elf ))< 0)
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "rel symcount" ); return( -1 );} while(0);;
   max = ( relpltsc > relsc ) ? relpltsc : relsc;
   return(max);
}

canonical_original_code:
int get_dsymcount(struct elf_t *elf)
{
   if( ! elf )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "null arg" ); return( -1 );} while(0);;
   int relsc; int relpltsc; int max;
   if((relpltsc = rel_plt_max_sym_indx( elf )) < 0 )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "rel_plt symcount" ); return( -1 );} while(0);;
   if((relsc = rel_max_dsym_indx( elf ))< 0)
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "rel symcount" ); return( -1 );} while(0);;
   max = ( relpltsc > relsc ) ? relpltsc : relsc;
   return(max);
}

variable_types: struct elf_t { char *name; void *data; int fd; unsigned long size; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *sht; int sht_count; struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *pht; int pht_count; struct Elf32_Dyn { int d_tag; union { unsigned int d_val; unsigned int d_ptr; } d_un; } *dynamic; char *shstrtab; unsigned long shstrtab_len; char *dstrtab; unsigned long dstrtab_len; char *strtab; unsigned long strtab_len; struct Elf32_Sym { unsigned int st_name; unsigned int st_value; unsigned int st_size; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; } *dsymtab; unsigned long dsymtab_len; struct Elf32_Sym *symtab; unsigned long symtab_len; void *rel_plt; unsigned long rel_plt_size; unsigned long rel_plt_entsize; unsigned int rel_plt_type; struct Elf32_Rel { unsigned int r_offset; unsigned int r_info; } *rel; unsigned long rel_size; unsigned long rel_entsize; struct Elf32_Rela { unsigned int r_offset; unsigned int r_info; int r_addend; } *rela; unsigned long relasz; unsigned long relaent; } *

variable_types: relsc int

variable_types: relpltsc int

variable_types: max int

user_defined_types: struct elf_t { char *name; void *data; int fd; unsigned long size; struct Elf32_Ehdr *ehdr; struct Elf32_Shdr *sht; int sht_count; struct Elf32_Phdr *pht; int pht_count; struct Elf32_Dyn *dynamic; char *shstrtab; unsigned long shstrtab_len; char *dstrtab; unsigned long dstrtab_len; char *strtab; unsigned long strtab_len; struct Elf32_Sym *dsymtab; unsigned long dsymtab_len; struct Elf32_Sym *symtab; unsigned long symtab_len; void *rel_plt; unsigned long rel_plt_size; unsigned long rel_plt_entsize; unsigned int rel_plt_type; struct Elf32_Rel *rel; unsigned long rel_size; unsigned long rel_entsize; struct Elf32_Rela *rela; unsigned long relasz; unsigned long relaent; }


decompiled_code:
__int64 __fastcall get_dsymtab(__int64 a1)
{
__int64 v1; // r12
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
const char *v6; // r8
int v7; // eax

if ( !a1 )
{
v1 = 0LL;
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "get_dsymtab", "null args");
return v1;
}
v1 = *(_QWORD *)(a1 + 128);
if ( v1 )
return v1;
v3 = dyn_sym_by_type(a1, 6LL, 0LL);
v6 = "can't get dsymtab entry";
v1 = v3;
if ( !v3 )
{
LABEL_8:
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "get_dsymtab", v6);
return v1;
}
v1 = data_at_addr(a1, *(unsigned int *)(v3 + 4), v4, v5, "can't get dsymtab entry");
if ( !v1 )
{
v6 = "can't get dsymtab";
goto LABEL_8;
}
v7 = get_dsymcount(a1);
*(_QWORD *)(a1 + 128) = v1;
*(_QWORD *)(a1 + 136) = v7;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r12
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rcx
const char *v6; // r8
int v7; // eax

if ( !a1 )
{
v1 = 0LL;
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "get_dsymtab", "null args");
return v1;
}
v1 = *(_QWORD *)(a1 + 128);
if ( v1 )
return v1;
v3 = dyn_sym_by_type(a1, 6LL, 0LL);
v6 = "can't get dsymtab entry";
v1 = v3;
if ( !v3 )
{
LABEL_8:
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "get_dsymtab", v6);
return v1;
}
v1 = data_at_addr(a1, *(unsigned int *)(v3 + 4), v4, v5, "can't get dsymtab entry");
if ( !v1 )
{
v6 = "can't get dsymtab";
goto LABEL_8;
}
v7 = func0(a1);
*(_QWORD *)(a1 + 128) = v1;
*(_QWORD *)(a1 + 136) = v7;
return v1;
}

original_code:
Elf32_Sym * get_dsymtab( elf_t * elf )
{
   Elf32_Dyn * dyn;
   Elf32_Sym * dsymtab;
   addr_t addr;
   size_t size;
   if( ! elf )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "null args" ); return( ((void *)0) );} while(0);;
   if( elf->dsymtab )
      return( elf->dsymtab);
   if( ! (dyn = dyn_sym_by_type( elf , 6 , 0 ) ))
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "can't get dsymtab entry" ); return( ((void *)0) );} while(0);;
   if( ! (dsymtab = data_at_addr( elf , dyn->d_un.d_ptr ) ) )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "can't get dsymtab" ); return( ((void *)0) );} while(0);;
   elf->dsymtab_len = get_dsymcount( elf );
   return(( elf->dsymtab = dsymtab ));
}

canonical_original_code:
struct Elf32_Sym *get_dsymtab(struct elf_t *elf)
{
   struct Elf32_Dyn *dyn;
   struct Elf32_Sym *dsymtab;
   unsigned int addr;
   unsigned long size;
   if( ! elf )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "null args" ); return( ((void *)0) );} while(0);;
   if( elf->dsymtab )
      return( elf->dsymtab);
   if( ! (dyn = dyn_sym_by_type( elf , 6 , 0 ) ))
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "can't get dsymtab entry" ); return( ((void *)0) );} while(0);;
   if( ! (dsymtab = data_at_addr( elf , dyn->d_un.d_ptr ) ) )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "can't get dsymtab" ); return( ((void *)0) );} while(0);;
   elf->dsymtab_len = get_dsymcount( elf );
   return(( elf->dsymtab = dsymtab ));
}

variable_types: struct elf_t { char *name; void *data; int fd; unsigned long size; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *ehdr; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *sht; int sht_count; struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; } *pht; int pht_count; struct Elf32_Dyn { int d_tag; union { unsigned int d_val; unsigned int d_ptr; } d_un; } *dynamic; char *shstrtab; unsigned long shstrtab_len; char *dstrtab; unsigned long dstrtab_len; char *strtab; unsigned long strtab_len; struct Elf32_Sym *dsymtab; unsigned long dsymtab_len; struct Elf32_Sym *symtab; unsigned long symtab_len; void *rel_plt; unsigned long rel_plt_size; unsigned long rel_plt_entsize; unsigned int rel_plt_type; struct Elf32_Rel { unsigned int r_offset; unsigned int r_info; } *rel; unsigned long rel_size; unsigned long rel_entsize; struct Elf32_Rela { unsigned int r_offset; unsigned int r_info; int r_addend; } *rela; unsigned long relasz; unsigned long relaent; } *

variable_types: struct Elf32_Sym { unsigned int st_name; unsigned int st_value; unsigned int st_size; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; } *

variable_types:
addr
unsigned int

variable_types:
size
unsigned long


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

if ( a1 )
{
if ( a2 >= 0 )
{
v2 = get_dsymtab(a1);
if ( v2 )
{
if ( (unsigned __int64)a2 < *(_QWORD *)(a1 + 136) )
return 16LL * a2 + v2;
}
}
}
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "dsym_by_index", "bad args");
return 0LL;
}

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

if ( a1 )
{
if ( a2 >= 0 )
{
v2 = func1(a1);
if ( v2 )
{
if ( (unsigned __int64)a2 < *(_QWORD *)(a1 + 136) )
return 16LL * a2 + v2;
}
}
}
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "dsym_by_index", "bad args");
return 0LL;
}

original_code:
Elf32_Sym * dsym_by_index( elf_t * elf , int indx )
{
   Elf32_Sym * dsymtab;
   if( ! elf || indx < 0 ||
       !( dsymtab = get_dsymtab( elf ) ) ||
       indx >= elf->dsymtab_len )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "bad args" ); return( ((void *)0) );} while(0);;
   return( dsymtab + indx );
}

canonical_original_code:
struct Elf32_Sym *dsym_by_index(struct elf_t *elf, int indx)
{
   struct Elf32_Sym *dsymtab;
   if( ! elf || indx < 0 ||
       !( dsymtab = get_dsymtab( elf ) ) ||
       indx >= elf->dsymtab_len )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "bad args" ); return( ((void *)0) );} while(0);;
   return( dsymtab + indx );
}

variable_types: indx int

return_type: struct Elf32_Sym { unsigned int st_name; unsigned int st_value; unsigned int st_size; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; } *

user_defined_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

user_defined_types: struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; }

user_defined_types: struct Elf32_Phdr { unsigned int p_type; unsigned int p_offset; unsigned int p_vaddr; unsigned int p_paddr; unsigned int p_filesz; unsigned int p_memsz; unsigned int p_flags; unsigned int p_align; }

user_defined_types: struct Elf32_Dyn { int d_tag; union { unsigned int d_val; unsigned int d_ptr; } d_un; }

user_defined_types: struct Elf32_Rel { unsigned int r_offset; unsigned int r_info; }

user_defined_types: struct Elf32_Rela { unsigned int r_offset; unsigned int r_info; int r_addend; }


decompiled_code:
__int64 __fastcall dsym_name_by_index(__int64 a1, int a2)
{
unsigned int *v2; // rax

if ( a1 )
{
v2 = (unsigned int *)dsym_by_index(a1, a2);
if ( v2 )
return dstr_by_offset(a1, *v2);
}
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "dsym_name_by_index", "bad args");
return 0LL;
}

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

if ( a1 )
{
v2 = (unsigned int *)func2(a1, a2);
if ( v2 )
return dstr_by_offset(a1, *v2);
}
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "dsym_name_by_index", "bad args");
return 0LL;
}

original_code:
char * dsym_name_by_index( elf_t * elf , int indx )
{
   Elf32_Sym * sym;
   if( ! elf || ! ( sym = dsym_by_index( elf , indx ) ) )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "bad args" ); return( ((void *)0) );} while(0);;
   return( dstr_by_offset( elf , sym->st_name ) );
}

canonical_original_code:
char *dsym_name_by_index(struct elf_t *elf, int indx)
{
   struct Elf32_Sym *sym;
   if( ! elf || ! ( sym = dsym_by_index( elf , indx ) ) )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "bad args" ); return( ((void *)0) );} while(0);;
   return( dstr_by_offset( elf , sym->st_name ) );
}

return_type: char *

user_defined_types: struct Elf32_Sym { unsigned int st_name; unsigned int st_value; unsigned int st_size; unsigned char st_info; unsigned char st_other; unsigned short st_shndx; }


decompiled_code:
__int64 __fastcall dsym_by_type(__int64 a1, int a2, int a3)
{
int v3; // ebx
__int64 v5; // rax
__int64 v6; // rsi
__int64 v7; // rcx
__int64 v8; // r8
__int64 result; // rax

if ( a1 && (v3 = a3, a3 >= 0) && (v5 = get_dsymtab(a1)) != 0 )
{
v6 = *(_QWORD *)(a1 + 136);
v7 = 0LL;
if ( v6 )
{
while ( 1 )
{
while ( 1 )
{
v8 = v5;
if ( (*(_BYTE *)(v5 + 12) & 0xF) == a2 )
break;
++v7;
v5 += 16LL;
if ( v6 == v7 )
goto LABEL_10;
}
if ( v3 <= 0 )
break;
++v7;
--v3;
v5 += 16LL;
if ( v6 == v7 )
goto LABEL_10;
}
}
else
{
LABEL_10:
v8 = 0LL;
}
result = v8;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "dsym_by_type", "bad args");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, int a3)
{
int v3; // ebx
__int64 v5; // rax
__int64 v6; // rsi
__int64 v7; // rcx
__int64 v8; // r8
__int64 result; // rax

if ( a1 && (v3 = a3, a3 >= 0) && (v5 = func1(a1)) != 0 )
{
v6 = *(_QWORD *)(a1 + 136);
v7 = 0LL;
if ( v6 )
{
while ( 1 )
{
while ( 1 )
{
v8 = v5;
if ( (*(_BYTE *)(v5 + 12) & 0xF) == a2 )
break;
++v7;
v5 += 16LL;
if ( v6 == v7 )
goto LABEL_10;
}
if ( v3 <= 0 )
break;
++v7;
--v3;
v5 += 16LL;
if ( v6 == v7 )
goto LABEL_10;
}
}
else
{
LABEL_10:
v8 = 0LL;
}
result = v8;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "dsymtab.c", "dsym_by_type", "bad args");
result = 0LL;
}
return result;
}

original_code:
Elf32_Sym * dsym_by_type( elf_t * elf , int type , int indx )
{
   Elf32_Sym * symtab;
   int i;
   if( ! elf || indx < 0 || !( symtab = get_dsymtab( elf ) ) )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "bad args" ); return( ((void *)0) );} while(0);;
   for( i = 0 ; i < elf->dsymtab_len ; i++ )
   {
      int ntype = ((symtab[i].st_info) & 0xf);
      if( ( ntype == type) && (indx-- <= 0) )
         return(&symtab[i]);
   }
   return(((void *)0));
}

canonical_original_code:
struct Elf32_Sym *dsym_by_type(struct elf_t *elf, int type, int indx)
{
   struct Elf32_Sym *symtab;
   int i;
   if( ! elf || indx < 0 || !( symtab = get_dsymtab( elf ) ) )
      do { fprintf(stderr,"%s/%s(): %s\n", "dsymtab.c" ,__func__ , "bad args" ); return( ((void *)0) );} while(0);;
   for( i = 0 ; i < elf->dsymtab_len ; i++ )
   {
      int ntype = ((symtab[i].st_info) & 0xf);
      if( ( ntype == type) && (indx-- <= 0) )
         return(&symtab[i]);
   }
   return(((void *)0));
}

variable_types: type int

variable_types: i int

variable_types: ntype int


decompiled_code:
__int64 __fastcall command_test1(const char **a1)
{
const char **v1; // rbx
const char *i; // rdi
__int64 result; // rax

if ( a1 )
{
v1 = a1;
puts("inside test1");
for ( i = *a1; i; ++v1 )
{
puts(i);
i = v1[1];
}
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "testcommands.c", "command_test1", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
const char **v1; // rbx
const char *i; // rdi
__int64 result; // rax

if ( a1 )
{
v1 = a1;
puts("inside test1");
for ( i = *a1; i; ++v1 )
{
puts(i);
i = v1[1];
}
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "testcommands.c", "command_test1", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int command_test1( char** argv ){
   if( !argv ) do { fprintf(stderr,"%s/%s(): %s\n", "testcommands.c" ,__func__ , "null arg" ); return( ((int)-1) );} while(0);;
   printf("inside test1\n");
   while( *argv != 0 ){
      printf("%s\n",*argv++);
   }
   return(((int)0));
}

canonical_original_code:
int command_test1(char **argv){
   if( !argv ) do { fprintf(stderr,"%s/%s(): %s\n", "testcommands.c" ,__func__ , "null arg" ); return( ((int)-1) );} while(0);;
   printf("inside test1\n");
   while( *argv != 0 ){
      printf("%s\n",*argv++);
   }
   return(((int)0));
}

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall command_test2(const char **a1)
{
const char **v1; // rbx
const char *i; // rdi
__int64 result; // rax

if ( a1 )
{
v1 = a1;
puts("inside test2");
for ( i = *a1; i; ++v1 )
{
puts(i);
i = v1[1];
}
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "testcommands.c", "command_test2", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1)
{
const char **v1; // rbx
const char *i; // rdi
__int64 result; // rax

if ( a1 )
{
v1 = a1;
puts("inside test2");
for ( i = *a1; i; ++v1 )
{
puts(i);
i = v1[1];
}
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "testcommands.c", "command_test2", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int command_test2( char** argv ){
   if( !argv ) do { fprintf(stderr,"%s/%s(): %s\n", "testcommands.c" ,__func__ , "null arg" ); return( ((int)-1) );} while(0);;
   printf("inside test2\n");
   while( *argv != 0 ){
      printf("%s\n",*argv++);
   }
   return(((int)0));
}

canonical_original_code:
int command_test2(char **argv){
   if( !argv ) do { fprintf(stderr,"%s/%s(): %s\n", "testcommands.c" ,__func__ , "null arg" ); return( ((int)-1) );} while(0);;
   printf("inside test2\n");
   while( *argv != 0 ){
      printf("%s\n",*argv++);
   }
   return(((int)0));
}


decompiled_code:
__int64 register_test1()
{
return register_command("/", command1);
}

canonical_decompiled_code:
__int64 func2()
{
return register_command("/", command1);
}

original_code:
int register_test1()
{
   return( register_command( "/" , &command1 ) );
}


decompiled_code:
__int64 register_test2()
{
return register_command("/test1/", command2);
}

canonical_decompiled_code:
__int64 func3()
{
return register_command("/test1/", command2);
}

original_code:
int register_test2()
{
   return ( register_command( "/test1/",&command2 ) );
}


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

if ( a1 )
{
puts("set command");
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "set.c", "command_set", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 )
{
puts("set command");
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "set.c", "command_set", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int command_set( char** argv ){
   if( !argv ) do { fprintf(stderr,"%s/%s(): %s\n", "set.c" ,__func__ , "null arg" ); return( ((int)-1) );} while(0);;
   printf("set command\n");
   return(((int)0));
}

canonical_original_code:
int command_set(char **argv){
   if( !argv ) do { fprintf(stderr,"%s/%s(): %s\n", "set.c" ,__func__ , "null arg" ); return( ((int)-1) );} while(0);;
   printf("set command\n");
   return(((int)0));
}


decompiled_code:
__int64 register_set()
{
return register_command("/", command);
}

canonical_decompiled_code:
__int64 func1()
{
return register_command("/", command);
}

original_code:
int register_set()
{
   return( register_command( "/" , &command ) );
}


decompiled_code:
__int64 __fastcall command_show(_QWORD *a1)
{
__int64 result; // rax

if ( a1 && *a1 )
{
puts("Show command");
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "show.c", "command_show", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

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

if ( a1 && *a1 )
{
puts("Show command");
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "show.c", "command_show", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int command_show( char** argv ){
   if( !argv || ! *argv )
      do { fprintf(stderr,"%s/%s(): %s\n", "show.c" ,__func__ , "null arg" ); return( ((int)-1) );} while(0);;
   printf("Show command\n");
   return(((int)0));
}

canonical_original_code:
int command_show(char **argv){
   if( !argv || ! *argv )
      do { fprintf(stderr,"%s/%s(): %s\n", "show.c" ,__func__ , "null arg" ); return( ((int)-1) );} while(0);;
   printf("Show command\n");
   return(((int)0));
}


decompiled_code:
__int64 register_show()
{
return register_command("/", command);
}

original_code:
int register_show()
{
   return( register_command( "/" , &command ) );
}


decompiled_code:
__int64 __fastcall command_map(const char **a1)
{
const char *v2; // rdi
__int64 **v3; // rax
const char *v4; // rdi
__int64 v5; // rsi
__int64 v6; // rbp
unsigned int v7; // eax
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
if ( !v2 )
v2 = "main";
v3 = (__int64 **)func_by_str(v2);
if ( v3 )
{
v4 = a1[1];
v5 = 0xFFFFFFFFLL;
v6 = **v3;
if ( v4 )
{
v7 = atoi(v4);
v5 = v7;
if ( !v7 )
v5 = 0xFFFFFFFFLL;
}
dump_dot_map((unsigned int)v6, v5);
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "map.c", "command_map", "can't find function");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "map.c", "command_map", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1)
{
const char *v2; // rdi
__int64 **v3; // rax
const char *v4; // rdi
__int64 v5; // rsi
__int64 v6; // rbp
unsigned int v7; // eax
__int64 result; // rax

if ( a1 )
{
v2 = *a1;
if ( !v2 )
v2 = "main";
v3 = (__int64 **)func_by_str(v2);
if ( v3 )
{
v4 = a1[1];
v5 = 0xFFFFFFFFLL;
v6 = **v3;
if ( v4 )
{
v7 = atoi(v4);
v5 = v7;
if ( !v7 )
v5 = 0xFFFFFFFFLL;
}
dump_dot_map((unsigned int)v6, v5);
result = 0LL;
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "map.c", "command_map", "can't find function");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "%s/%s(): %s\n", "map.c", "command_map", "null arg");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int command_map( char** argv ){
   char * target;
   func_t * func;
   addr_t addr = 0;
   int depth = -1;
   if(! argv ) do { fprintf(stderr,"%s/%s(): %s\n", "map.c" ,__func__ , "null arg" ); return( -1 );} while(0);;
   target = *argv ? *argv : "main";
   if(!(func = func_by_str( target )))
      do { fprintf(stderr,"%s/%s(): %s\n", "map.c" ,__func__ , "can't find function" ); return( ((int)-1) );} while(0);
   addr = ( func->obj )->addr;
   if( argv[1] )
      if(!(depth = atoi( argv[1] )))
         depth = -1;
   dump_dot_map( addr , depth );
   return(((int)0));
}

canonical_original_code:
int command_map(char **argv){
   char *target;
   struct func_t *func;
   unsigned int addr = 0;
   int depth = -1;
   if(! argv ) do { fprintf(stderr,"%s/%s(): %s\n", "map.c" ,__func__ , "null arg" ); return( -1 );} while(0);;
   target = *argv ? *argv : "main";
   if(!(func = func_by_str( target )))
      do { fprintf(stderr,"%s/%s(): %s\n", "map.c" ,__func__ , "can't find function" ); return( ((int)-1) );} while(0);
   addr = ( func->obj )->addr;
   if( argv[1] )
      if(!(depth = atoi( argv[1] )))
         depth = -1;
   dump_dot_map( addr , depth );
   return(((int)0));
}

variable_types:
target
char *

variable_types: struct func_t { struct eobj_t { long addr; unsigned long offset; unsigned long size; char *name; } *obj; struct list_ { struct list_node_ { struct list_node_ *next; struct list_data_ { unsigned int key; void *data; } data; } head; int size; int (*cmp)(struct list_data_ *a, struct list_data_ *b); } *calls; } *

variable_types: depth int

user_defined_types: struct func_t { struct eobj_t *obj; struct list_ *calls; }


decompiled_code:
__int64 register_map()
{
return register_command("/", map_command);
}

canonical_decompiled_code:
__int64 func1()
{
return register_command("/", map_command);
}

original_code:
int register_map()
{
   return( register_command( "/" , &map_command ) );
}


repo: bqk-/bigInteger

decompiled_code:
_BOOL8 __fastcall is_empty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return a1 == 0;
}

original_code:
Boolean is_empty(Dlist list)
{
 if(list!=((void *)0))
 {
  return 0;
 }
 else
 {
  return 1;
 }
}

canonical_original_code:
int is_empty(struct elem *list)
{
 if(list!=((void *)0))
 {
  return 0;
 }
 else
 {
  return 1;
 }
}

variable_types: struct elem { int value; struct elem *next; struct elem *prev; } *


removeHead

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

if ( is_empty(a1) || is_empty(*(_QWORD *)(a1 + 8)) )
return 0LL;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 16) = 0LL;
return result;
}

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

if ( func0(a1) || func0(*(_QWORD *)(a1 + 8)) )
return 0LL;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 16) = 0LL;
return result;
}

original_code:
Dlist removeHead(Dlist list)
{
 if(!is_empty(list) && !is_empty(list->next))
 {
  Element* temp=malloc(sizeof(Element));
  temp=list;
  temp->next->prev=((void *)0);
  return temp->next;
 }
 else
 {
  return ((void *)0);
 }
}

canonical_original_code:
struct elem *removeHead(struct elem *list)
{
 if(!is_empty(list) && !is_empty(list->next))
 {
  struct elem *temp = malloc(sizeof(Element));
  temp=list;
  temp->next->prev=((void *)0);
  return temp->next;
 }
 else
 {
  return ((void *)0);
 }
}

variable_types:
list
struct elem *

return_type: struct elem { int value; struct elem *next; struct elem *prev; } *


decompiled_code:
__int64 __fastcall back2start(__int64 a1)
{
__int64 v1; // rbx
_BOOL4 v2; // er8
__int64 result; // rax

v1 = a1;
v2 = is_empty(a1);
result = 0LL;
if ( !v2 )
{
do
{
result = v1;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
_BOOL4 v2; // er8
__int64 result; // rax

v1 = a1;
v2 = func0(a1);
result = 0LL;
if ( !v2 )
{
do
{
result = v1;
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return result;
}

original_code:
Dlist back2start(Dlist list)
{
 if(is_empty(list))
 {
  return ((void *)0);
 }
 else
 {
  Element* temp=malloc(sizeof(Element));
  temp=list;
  while(temp->prev!=((void *)0))
  {
   temp=temp->prev;
  }
  return temp;
 }
}

canonical_original_code:
struct elem *back2start(struct elem *list)
{
 if(is_empty(list))
 {
  return ((void *)0);
 }
 else
 {
  struct elem *temp = malloc(sizeof(Element));
  temp=list;
  while(temp->prev!=((void *)0))
  {
   temp=temp->prev;
  }
  return temp;
 }
}

user_defined_types: struct elem { int value; struct elem *next; struct elem *prev; }


decompiled_code:
__int64 __fastcall back2end(__int64 a1)
{
__int64 v1; // rbx
_BOOL4 v2; // er8
__int64 result; // rax

v1 = a1;
v2 = is_empty(a1);
result = 0LL;
if ( !v2 )
{
do
{
result = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
_BOOL4 v2; // er8
__int64 result; // rax

v1 = a1;
v2 = func0(a1);
result = 0LL;
if ( !v2 )
{
do
{
result = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
}
return result;
}

original_code:
Dlist back2end(Dlist list)
{
 if(is_empty(list))
 {
  return ((void *)0);
 }
 else
 {
  Element* temp=malloc(sizeof(Element));
  temp=list;
  while(temp->next!=((void *)0))
  {
   temp=temp->next;
  }
  return temp;
 }
}

canonical_original_code:
struct elem *back2end(struct elem *list)
{
 if(is_empty(list))
 {
  return ((void *)0);
 }
 else
 {
  struct elem *temp = malloc(sizeof(Element));
  temp=list;
  while(temp->next!=((void *)0))
  {
   temp=temp->next;
  }
  return temp;
 }
}


removeTail

decompiled_code:
__int64 __fastcall removeTail(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx

if ( is_empty(a1) || is_empty(*(_QWORD *)(a1 + 8)) )
return 0LL;
v1 = a1;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 8);
}
while ( v1 );
*(_QWORD *)(*(_QWORD *)(v2 + 16) + 8LL) = 0LL;
return a1;
}

original_code:
Dlist removeTail(Dlist list)
{
 if(!is_empty(list) && !is_empty(list->next))
 {
  Element* temp=malloc(sizeof(Element));
  temp=list;
  while(temp->next!=((void *)0))
  {
   temp=temp->next;
  }
  temp->prev->next=((void *)0);
  return list;
 }
 else
 {
  return ((void *)0);
 }
}

canonical_original_code:
struct elem *removeTail(struct elem *list)
{
 if(!is_empty(list) && !is_empty(list->next))
 {
  struct elem *temp = malloc(sizeof(Element));
  temp=list;
  while(temp->next!=((void *)0))
  {
   temp=temp->next;
  }
  temp->prev->next=((void *)0);
  return list;
 }
 else
 {
  return ((void *)0);
 }
}


headValue

decompiled_code:
__int64 __fastcall headValue(__int64 a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = is_empty(a1);
result = 0LL;
if ( !v1 )
result = *(unsigned int *)back2start(a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = func0(a1);
result = 0LL;
if ( !v1 )
result = *(unsigned int *)func2(a1);
return result;
}

original_code:
int headValue(Dlist list)
{
 if(is_empty(list))
 {
  return 0;
 }
 else
 {
  Element* temp=malloc(sizeof(Element));
  temp=list;
  temp=back2start(temp);
  return temp->value;
 }
}

canonical_original_code:
int headValue(struct elem *list)
{
 if(is_empty(list))
 {
  return 0;
 }
 else
 {
  struct elem *temp = malloc(sizeof(Element));
  temp=list;
  temp=back2start(temp);
  return temp->value;
 }
}


nbrElement

original_code:
int nbrElement(Dlist list)
{
 if(is_empty(list))
 {
  return 0;
 }
 else
 {
  int i=1;
  Element* temp=malloc(sizeof(Element));
  temp=list;
  while(temp->prev!=((void *)0))
  {
   temp=temp->prev;
  }
  while(temp->next!=((void *)0))
  {
   i++;
   temp=temp->next;
  }
  return i;
 }
}

canonical_original_code:
int nbrElement(struct elem *list)
{
 if(is_empty(list))
 {
  return 0;
 }
 else
 {
  int i = 1;
  struct elem *temp = malloc(sizeof(Element));
  temp=list;
  while(temp->prev!=((void *)0))
  {
   temp=temp->prev;
  }
  while(temp->next!=((void *)0))
  {
   i++;
   temp=temp->next;
  }
  return i;
 }
}


displayList

original_code:
void displayList(Dlist list)
{
 Element* temp=malloc(sizeof(Element));
 temp=list;
 printf("-------------------------------\n");
 while(temp!=((void *)0))
 {
  printf("%d > ",temp->value);
  temp=temp->next;
 }
 printf("NULL\n");
 printf("-------------------------------\n");
}

canonical_original_code:
void displayList(struct elem *list)
{
 struct elem *temp = malloc(sizeof(Element));
 temp=list;
 printf("-------------------------------\n");
 while(temp!=((void *)0))
 {
  printf("%d > ",temp->value);
  temp=temp->next;
 }
 printf("NULL\n");
 printf("-------------------------------\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
menu_localalias();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0();
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 menu();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 menu();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void __fastcall convert_string_to_mac(char *s, __int64 a2)
{
char *v2; // rbp
__int64 v3; // rbx
int v4; // eax
char *v5; // rax
int v6[7]; // [rsp+0h] [rbp-1Ch] BYREF

if ( s )
{
v2 = s;
v3 = 1LL;
do
{
v6[0] = 0;
_isoc99_sscanf(v2, &unk_274, v6);
*(_BYTE *)(a2 + v3 - 1) = v6[0];
v5 = strchr(v2, 58);
if ( !v5 )
break;
v2 = v5 + 1;
v4 = v3++;
}
while ( v4 <= 5 );
}
}

original_code:
void convert_string_to_mac(const char* string, unsigned char* mac)
{
 int c;
 for(c = 0; c < 6 && string; c++) {
  int x = 0;
  if (string)
   sscanf(string, "%x", &x);
  mac[c] = x;
  string = strchr(string, ':');
  if (string)
   string++;
 }
}

canonical_original_code:
void convert_string_to_mac(char *string, unsigned char *mac)
{
 int c;
 for(c = 0; c < 6 && string; c++) {
  int x = 0;
  if (string)
   sscanf(string, "%x", &x);
  mac[c] = x;
  string = strchr(string, ':');
  if (string)
   string++;
 }
}

variable_types:
string
char *

variable_types:
mac
unsigned char *

variable_types: c int

variable_types: x int


decompiled_code:
char *__fastcall kilo_mega_ize(unsigned int a1)
{
char *result; // rax
unsigned int v2; // er10
__int64 v3; // r9
double v4; // xmm0_8

if ( a1 > 0x3FF )
{
v2 = a1 >> 10;
if ( a1 <= 0xFFFFF )
{
v3 = 107LL;
v4 = (double)(a1 & 0x3FF) / 102.4;
}
else
{
v3 = 77LL;
v4 = (double)((a1 >> 10) & 0x3FF) / 102.4;
v2 = a1 >> 20;
}
snprintf(buf_3, 0x14uLL, "%d.%d%c", v2, (unsigned int)(int)v4, v3);
result = buf_3;
}
else
{
snprintf(buf_3, 0x14uLL, "%d", a1);
result = buf_3;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned int a1)
{
char *result; // rax
unsigned int v2; // er10
__int64 v3; // r9
double v4; // xmm0_8

if ( a1 > 0x3FF )
{
v2 = a1 >> 10;
if ( a1 <= 0xFFFFF )
{
v3 = 107LL;
v4 = (double)(a1 & 0x3FF) / 102.4;
}
else
{
v3 = 77LL;
v4 = (double)((a1 >> 10) & 0x3FF) / 102.4;
v2 = a1 >> 20;
}
snprintf(buf_3, 0x14uLL, "%d.%d%c", v2, (unsigned int)(int)v4, v3);
result = buf_3;
}
else
{
snprintf(buf_3, 0x14uLL, "%d", a1);
result = buf_3;
}
return result;
}

original_code:
const char* kilo_mega_ize(unsigned int val) {
 static char buf[20];
 char c = 0;
 int rest;
 if (val >= 1024) {
  rest = (val & 1023) / 102.4;
  val = val >> 10;
  c = 'k';
 }
 if (val >= 1024) {
  rest = (val & 1023) / 102.4;
  val = val >> 10;
  c = 'M';
 }
 if (c)
  snprintf(buf, sizeof(buf), "%d.%d%c", val, rest, c);
 else
  snprintf(buf, sizeof(buf), "%d", val);
 return buf;
}

canonical_original_code:
char *kilo_mega_ize(unsigned int val) {
 static char buf[20];
 char c = 0;
 int rest;
 if (val >= 1024) {
  rest = (val & 1023) / 102.4;
  val = val >> 10;
  c = 'k';
 }
 if (val >= 1024) {
  rest = (val & 1023) / 102.4;
  val = val >> 10;
  c = 'M';
 }
 if (c)
  snprintf(buf, sizeof(buf), "%d.%d%c", val, rest, c);
 else
  snprintf(buf, sizeof(buf), "%d", val);
 return buf;
}

variable_types:
val
unsigned int

variable_types:
buf
char [20]

variable_types: c char

variable_types: rest int


decompiled_code:
char *__fastcall mac_sprint_short(__int64 a1)
{
sprintf(etherbuf_2, "%02x%02x", *(unsigned __int8 *)(a1 + 4), *(unsigned __int8 *)(a1 + 5));
return etherbuf_2;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1)
{
sprintf(etherbuf_2, "%02x%02x", *(unsigned __int8 *)(a1 + 4), *(unsigned __int8 *)(a1 + 5));
return etherbuf_2;
}

original_code:
const char* mac_sprint_short(const unsigned char *mac)
{
 static char etherbuf[5];
 sprintf(etherbuf, "%02x%02x",
  mac[4], mac[5]);
 return etherbuf;
}

canonical_original_code:
char *mac_sprint_short(unsigned char *mac)
{
 static char etherbuf[5];
 sprintf(etherbuf, "%02x%02x",
  mac[4], mac[5]);
 return etherbuf;
}

variable_types:
etherbuf
char [5]


decompiled_code:
char *__fastcall ip_sprintf(unsigned int a1)
{
sprintf(ipbuf_1, "%d.%d.%d.%d", (unsigned __int8)a1, BYTE1(a1), BYTE2(a1), HIBYTE(a1));
return ipbuf_1;
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1)
{
sprintf(ipbuf_1, "%d.%d.%d.%d", (unsigned __int8)a1, BYTE1(a1), BYTE2(a1), HIBYTE(a1));
return ipbuf_1;
}

original_code:
const char* ip_sprintf(const unsigned int ip)
{
 static char ipbuf[18];
 unsigned char* cip = (unsigned char*)&ip;
 sprintf(ipbuf, "%d.%d.%d.%d",
  cip[0], cip[1], cip[2], cip[3]);
 return ipbuf;
}

canonical_original_code:
char *ip_sprintf(unsigned int ip)
{
 static char ipbuf[18];
 unsigned char *cip = (unsigned char*)&ip;
 sprintf(ipbuf, "%d.%d.%d.%d",
  cip[0], cip[1], cip[2], cip[3]);
 return ipbuf;
}

variable_types:
ip
unsigned int

variable_types:
ipbuf
char [18]

variable_types:
cip
unsigned char *


decompiled_code:
char *__fastcall ip_sprintf_short(unsigned int a1)
{
sprintf(ipbuf_0, ".%d", HIBYTE(a1));
return ipbuf_0;
}

canonical_decompiled_code:
char *__fastcall func4(unsigned int a1)
{
sprintf(ipbuf_0, ".%d", HIBYTE(a1));
return ipbuf_0;
}

original_code:
const char* ip_sprintf_short(const unsigned int ip)
{
 static char ipbuf[5];
 unsigned char* cip = (unsigned char*)&ip;
 sprintf(ipbuf, ".%d", cip[3]);
 return ipbuf;
}

canonical_original_code:
char *ip_sprintf_short(unsigned int ip)
{
 static char ipbuf[5];
 unsigned char *cip = (unsigned char*)&ip;
 sprintf(ipbuf, ".%d", cip[3]);
 return ipbuf;
}

variable_types:
ipbuf
char [5]


normalize

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

if ( a2 > (int)(float)((float)(a3 / (float)a1) * (float)a2) )
a2 = (int)(float)((float)(a3 / (float)a1) * (float)a2);
if ( a2 || (result = 1LL, a3 <= 0.0) )
{
result = 0LL;
if ( a2 >= 0 )
result = (unsigned int)a2;
}
return result;
}

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

if ( a2 > (int)(float)((float)(a3 / (float)a1) * (float)a2) )
a2 = (int)(float)((float)(a3 / (float)a1) * (float)a2);
if ( a2 || (result = 1LL, a3 <= 0.0) )
{
result = 0LL;
if ( a2 >= 0 )
result = (unsigned int)a2;
}
return result;
}

original_code:
int normalize(float oval, int max_val, int max) {
 int val;
 val= (oval / max_val) * max;
 if (val > max)
  val = max;
 if (val == 0 && oval > 0)
  val = 1;
 if (val < 0)
  val = 0;
 return val;
}

variable_types: oval float

variable_types: max int

variable_types: val int


AddIWADDir

repo: bradharding/doomretro

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

result = num_iwad_dirs;
if ( num_iwad_dirs <= 127 )
{
iwad_dirs[num_iwad_dirs] = a1;
num_iwad_dirs = result + 1;
}
return result;
}

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

result = num_iwad_dirs;
if ( num_iwad_dirs <= 127 )
{
iwad_dirs[num_iwad_dirs] = a1;
num_iwad_dirs = result + 1;
}
return result;
}

original_code:
static void AddIWADDir(char *dir)
{
    if (num_iwad_dirs < 128)
        iwad_dirs[num_iwad_dirs++] = dir;
}

variable_types:
dir
char *


SaveGameIWADName

decompiled_code:
const char *SaveGameIWADName()
{
const char *v0; // r8
const char **v1; // rax
int v2; // edx
const char *v4; // r8

v0 = "DOOM1";
if ( !gamemode )
return v0;
if ( !FREEDOOM )
{
v0 = "hacx";
if ( !hacx )
{
v1 = (const char **)&off_1950;
v2 = 1;
v0 = "doom2";
while ( gamemission != v2 )
{
v0 = *v1;
v1 += 2;
if ( !*v0 )
return "unknown";
v2 = *((_DWORD *)v1 - 2);
}
}
return v0;
}
v4 = "freedoom2";
if ( gamemode != 2 )
v4 = "freedoom";
return v4;
}

canonical_decompiled_code:
const char *func1()
{
const char *v0; // r8
const char **v1; // rax
int v2; // edx
const char *v4; // r8

v0 = "DOOM1";
if ( !gamemode )
return v0;
if ( !FREEDOOM )
{
v0 = "hacx";
if ( !hacx )
{
v1 = (const char **)&off_1950;
v2 = 1;
v0 = "doom2";
while ( gamemission != v2 )
{
v0 = *v1;
v1 += 2;
if ( !*v0 )
return "unknown";
v2 = *((_DWORD *)v1 - 2);
}
}
return v0;
}
v4 = "freedoom2";
if ( gamemode != 2 )
v4 = "freedoom";
return v4;
}

original_code:
static char *SaveGameIWADName(void)
{
    if (gamemode == shareware)
        return "DOOM1";
    if (FREEDOOM)
        return (gamemode == commercial ? "freedoom2" : "freedoom");
    else if (hacx)
        return "hacx";
    for (size_t i = 0; iwads[i].name[0]; i++)
        if (gamemission == iwads[i].mission)
            return iwads[i].name;
    return "unknown";
}

canonical_original_code:
static char *SaveGameIWADName()
{
    if (gamemode == shareware)
        return "DOOM1";
    if (FREEDOOM)
        return (gamemode == commercial ? "freedoom2" : "freedoom");
    else if (hacx)
        return "hacx";
    for (unsigned long i = 0; iwads[i].name[0]; i++)
        if (gamemission == iwads[i].mission)
            return iwads[i].name;
    return "unknown";
}

variable_types:
i
unsigned long


AddDoomWADPath

decompiled_code:
char *AddDoomWADPath()
{
char *result; // rax
const char *v1; // rdi

result = getenv("DOOMWADPATH");
if ( result )
{
v1 = result;
AddIWADDir((__int64)result);
while ( 1 )
{
result = strchr(v1, 58);
if ( !result )
break;
*result = 0;
v1 = result + 1;
AddIWADDir((__int64)(result + 1));
}
}
return result;
}

canonical_decompiled_code:
char *func2()
{
char *result; // rax
const char *v1; // rdi

result = getenv("DOOMWADPATH");
if ( result )
{
v1 = result;
func0((__int64)result);
while ( 1 )
{
result = strchr(v1, 58);
if ( !result )
break;
*result = 0;
v1 = result + 1;
func0((__int64)(result + 1));
}
}
return result;
}

original_code:
static void AddDoomWADPath(void)
{
    char *doomwadpath = getenv("DOOMWADPATH");
    char *p;
    if (!doomwadpath)
        return;
    AddIWADDir(doomwadpath);
    p = doomwadpath;
    while (1)
    {
        if ((p = strchr(p, ':')))
        {
            *p++ = '\0';
            AddIWADDir(p);
        }
        else
            break;
    }
}

canonical_original_code:
static void AddDoomWADPath()
{
    char *doomwadpath = getenv("DOOMWADPATH");
    char *p;
    if (!doomwadpath)
        return;
    AddIWADDir(doomwadpath);
    p = doomwadpath;
    while (1)
    {
        if ((p = strchr(p, ':')))
        {
            *p++ = '\0';
            AddIWADDir(p);
        }
        else
            break;
    }
}

variable_types:
doomwadpath
char *

variable_types:
p
char *


AddIWADPath

decompiled_code:
void __fastcall AddIWADPath(__int64 a1, __int64 a2)
{
char *v2; // r12
const char *v3; // r13
const char *v4; // rdi
__int64 v5; // rax
char *v6; // rax
__int64 v7; // rax

v2 = (char *)M_StringDuplicate();
v3 = v2;
while ( 1 )
{
v6 = strchr(v3, 58);
if ( !v6 )
break;
*v6 = 0;
v4 = v3;
v3 = v6 + 1;
v5 = M_StringJoin(v4, a2, 0LL);
AddIWADDir(v5);
}
v7 = M_StringJoin(v3, a2, 0LL);
AddIWADDir(v7);
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
char *v2; // r12
const char *v3; // r13
const char *v4; // rdi
__int64 v5; // rax
char *v6; // rax
__int64 v7; // rax

v2 = (char *)M_StringDuplicate();
v3 = v2;
while ( 1 )
{
v6 = strchr(v3, 58);
if ( !v6 )
break;
*v6 = 0;
v4 = v3;
v3 = v6 + 1;
v5 = M_StringJoin(v4, a2, 0LL);
func0(v5);
}
v7 = M_StringJoin(v3, a2, 0LL);
func0(v7);
free(v2);
}

original_code:
static void AddIWADPath(const char *path, const char *suffix)
{
    char *p;
    char *dup_path = M_StringDuplicate(path);
    char *left = dup_path;
    while (1)
        if ((p = strchr(left, ':')))
        {
            *p = '\0';
            AddIWADDir(M_StringJoin(left, suffix, ((void *)0)));
            left = p + 1;
        }
        else
            break;
    AddIWADDir(M_StringJoin(left, suffix, ((void *)0)));
    free(dup_path);
}

canonical_original_code:
static void AddIWADPath(char *path, char *suffix)
{
    char *p;
    char *dup_path = M_StringDuplicate(path);
    char *left = dup_path;
    while (1)
        if ((p = strchr(left, ':')))
        {
            *p = '\0';
            AddIWADDir(M_StringJoin(left, suffix, ((void *)0)));
            left = p + 1;
        }
        else
            break;
    AddIWADDir(M_StringJoin(left, suffix, ((void *)0)));
    free(dup_path);
}

variable_types:
path
char *

variable_types:
suffix
char *

variable_types:
left
char *


AddXdgDirs

decompiled_code:
void AddXdgDirs()
{
char *v0; // rbp
char *v1; // rdi
__int64 v2; // rax
char *v3; // rbp
char *v4; // rdi

v0 = 0LL;
v1 = getenv("XDG_DATA_HOME");
if ( !v1 )
{
v4 = getenv("HOME");
if ( !v4 )
v4 = "/";
v1 = (char *)M_StringJoin(v4, "/.local/share", 0LL);
v0 = v1;
}
v2 = M_StringJoin(v1, "/games/doom", 0LL);
AddIWADDir(v2);
free(v0);
v3 = getenv("XDG_DATA_DIRS");
if ( !v3 )
v3 = "/usr/local/share:/usr/share";
AddIWADPath((__int64)v3, (__int64)"/games/doom");
AddIWADPath((__int64)v3, (__int64)"/doom");
AddIWADPath((__int64)v3, (__int64)"/games/doom3bfg/base/wads");
}

canonical_decompiled_code:
void func4()
{
char *v0; // rbp
char *v1; // rdi
__int64 v2; // rax
char *v3; // rbp
char *v4; // rdi

v0 = 0LL;
v1 = getenv("XDG_DATA_HOME");
if ( !v1 )
{
v4 = getenv("HOME");
if ( !v4 )
v4 = "/";
v1 = (char *)M_StringJoin(v4, "/.local/share", 0LL);
v0 = v1;
}
v2 = M_StringJoin(v1, "/games/doom", 0LL);
func0(v2);
free(v0);
v3 = getenv("XDG_DATA_DIRS");
if ( !v3 )
v3 = "/usr/local/share:/usr/share";
func3((__int64)v3, (__int64)"/games/doom");
func3((__int64)v3, (__int64)"/doom");
func3((__int64)v3, (__int64)"/games/doom3bfg/base/wads");
}

original_code:
static void AddXdgDirs(void)
{
    char *env = getenv("XDG_DATA_HOME");
    char *tmp_env = ((void *)0);
    if (!env)
    {
        char *homedir = getenv("HOME");
        if (!homedir)
            homedir = "/";
        tmp_env = M_StringJoin(homedir, "/.local/share", ((void *)0));
        env = tmp_env;
    }
    AddIWADDir(M_StringJoin(env, "/games/doom", ((void *)0)));
    free(tmp_env);
    if (!(env = getenv("XDG_DATA_DIRS")))
        env = "/usr/local/share:/usr/share";
    AddIWADPath(env, "/games/doom");
    AddIWADPath(env, "/doom");
    AddIWADPath(env, "/games/doom3bfg/base/wads");
}

canonical_original_code:
static void AddXdgDirs()
{
    char *env = getenv("XDG_DATA_HOME");
    char *tmp_env = ((void *)0);
    if (!env)
    {
        char *homedir = getenv("HOME");
        if (!homedir)
            homedir = "/";
        tmp_env = M_StringJoin(homedir, "/.local/share", ((void *)0));
        env = tmp_env;
    }
    AddIWADDir(M_StringJoin(env, "/games/doom", ((void *)0)));
    free(tmp_env);
    if (!(env = getenv("XDG_DATA_DIRS")))
        env = "/usr/local/share:/usr/share";
    AddIWADPath(env, "/games/doom");
    AddIWADPath(env, "/doom");
    AddIWADPath(env, "/games/doom3bfg/base/wads");
}

variable_types:
env
char *

variable_types:
homedir
char *


AddSteamDirs

decompiled_code:
void AddSteamDirs()
{
char *v0; // rdi
void *v1; // rbp

v0 = getenv("HOME");
if ( !v0 )
v0 = "/";
v1 = (void *)M_StringJoin(v0, "/.steam/root/steamapps/common", 0LL);
AddIWADPath((__int64)v1, (__int64)"/Doom 2/base");
AddIWADPath((__int64)v1, (__int64)"/Ultimate Doom/base");
AddIWADPath((__int64)v1, (__int64)"/Final Doom/base");
AddIWADPath((__int64)v1, (__int64)"/DOOM 3 BFG Edition/base/wads");
free(v1);
}

canonical_decompiled_code:
void func5()
{
char *v0; // rdi
void *v1; // rbp

v0 = getenv("HOME");
if ( !v0 )
v0 = "/";
v1 = (void *)M_StringJoin(v0, "/.steam/root/steamapps/common", 0LL);
func3((__int64)v1, (__int64)"/Doom 2/base");
func3((__int64)v1, (__int64)"/Ultimate Doom/base");
func3((__int64)v1, (__int64)"/Final Doom/base");
func3((__int64)v1, (__int64)"/DOOM 3 BFG Edition/base/wads");
free(v1);
}

original_code:
static void AddSteamDirs(void)
{
    char *homedir = getenv("HOME");
    char *steampath;
    if (!homedir)
        homedir = "/";
    steampath = M_StringJoin(homedir, "/.steam/root/steamapps/common", ((void *)0));
    AddIWADPath(steampath, "/Doom 2/base");
    AddIWADPath(steampath, "/Ultimate Doom/base");
    AddIWADPath(steampath, "/Final Doom/base");
    AddIWADPath(steampath, "/DOOM 3 BFG Edition/base/wads");
    free(steampath);
}

canonical_original_code:
static void AddSteamDirs()
{
    char *homedir = getenv("HOME");
    char *steampath;
    if (!homedir)
        homedir = "/";
    steampath = M_StringJoin(homedir, "/.steam/root/steamapps/common", ((void *)0));
    AddIWADPath(steampath, "/Doom 2/base");
    AddIWADPath(steampath, "/Ultimate Doom/base");
    AddIWADPath(steampath, "/Final Doom/base");
    AddIWADPath(steampath, "/DOOM 3 BFG Edition/base/wads");
    free(steampath);
}

variable_types:
steampath
char *


BuildIWADDirList

decompiled_code:
void BuildIWADDirList()
{
char *v0; // rdi

if ( !iwad_dirs_built_0 )
{
v0 = getenv("DOOMWADDIR");
if ( v0 )
AddIWADDir((__int64)v0);
AddDoomWADPath();
AddXdgDirs();
AddSteamDirs();
iwad_dirs_built_0 = 1;
}
}

canonical_decompiled_code:
void func6()
{
char *v0; // rdi

if ( !iwad_dirs_built_0 )
{
v0 = getenv("DOOMWADDIR");
if ( v0 )
func0((__int64)v0);
func2();
func4();
func5();
iwad_dirs_built_0 = 1;
}
}

original_code:
static void BuildIWADDirList(void)
{
    char *doomwaddir;
    static _Bool iwad_dirs_built;
    if (iwad_dirs_built)
        return;
    if ((doomwaddir = getenv("DOOMWADDIR")))
        AddIWADDir(doomwaddir);
    AddDoomWADPath();
    AddXdgDirs();
    AddSteamDirs();
    iwad_dirs_built = 1;
}

canonical_original_code:
static void BuildIWADDirList()
{
    char *doomwaddir;
    static _Bool iwad_dirs_built;
    if (iwad_dirs_built)
        return;
    if ((doomwaddir = getenv("DOOMWADDIR")))
        AddIWADDir(doomwaddir);
    AddDoomWADPath();
    AddXdgDirs();
    AddSteamDirs();
    iwad_dirs_built = 1;
}

variable_types:
doomwaddir
char *


DirIsFile

decompiled_code:
bool __fastcall DirIsFile(const char *a1, const char *a2)
{
char *v2; // r8
bool result; // al
const char *v4; // rax

v2 = strchr(a1, 47);
result = 0;
if ( v2 )
{
v4 = (const char *)leafname(a1);
result = strcasecmp(v4, a2) == 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func7(const char *a1, const char *a2)
{
char *v2; // r8
bool result; // al
const char *v4; // rax

v2 = strchr(a1, 47);
result = 0;
if ( v2 )
{
v4 = (const char *)leafname(a1);
result = strcasecmp(v4, a2) == 0;
}
return result;
}

original_code:
static _Bool DirIsFile(char *path, char *filename)
{
    return (strchr(path, '/') && !strcasecmp(leafname(path), filename));
}

variable_types:
filename
char *


CheckDirectoryHasIWAD

decompiled_code:
void *__fastcall CheckDirectoryHasIWAD(__int64 a1, const char *a2)
{
void *v2; // r12
bool v3; // al
void *v4; // rbp

v2 = (void *)((__int64 (*)(void))M_FileCaseExists)();
v3 = DirIsFile((const char *)a1, a2);
if ( !v2 || !v3 )
{
if ( *(_BYTE *)a1 != 46 || *(_BYTE *)(a1 + 1) )
v4 = (void *)M_StringJoin(a1, "/", a2);
else
v4 = (void *)M_StringDuplicate(a2);
free(v2);
v2 = (void *)M_FileCaseExists(v4);
free(v4);
}
return v2;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, const char *a2)
{
void *v2; // r12
bool v3; // al
void *v4; // rbp

v2 = (void *)((__int64 (*)(void))M_FileCaseExists)();
v3 = func7((const char *)a1, a2);
if ( !v2 || !v3 )
{
if ( *(_BYTE *)a1 != 46 || *(_BYTE *)(a1 + 1) )
v4 = (void *)M_StringJoin(a1, "/", a2);
else
v4 = (void *)M_StringDuplicate(a2);
free(v2);
v2 = (void *)M_FileCaseExists(v4);
free(v4);
}
return v2;
}

original_code:
static char *CheckDirectoryHasIWAD(char *dir, char *iwadname)
{
    char *filename;
    char *probe = M_FileCaseExists(dir);
    if (DirIsFile(dir, iwadname) && probe)
        return probe;
    if (!strcmp(dir, "."))
        filename = M_StringDuplicate(iwadname);
    else
        filename = M_StringJoin(dir, "/", iwadname, ".wad", ((void *)0));
    free(probe);
    probe = M_FileCaseExists(filename);
    free(filename);
    return probe;
}

variable_types:
iwadname
char *

variable_types:
probe
char *