decompiled_code:
__int64 __fastcall spawn_thread1(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
char *v3; // rax
char *v4; // rbp
_QWORD *v5; // rax
void *v6; // r13

result = 1LL;
if ( numthreads != 10 )
{
v2 = numthreads;
v3 = (char *)malloc(0x100000uLL);
*((_QWORD *)&thread1List[v2] + 1) = v3;
v4 = v3;
if ( v3 )
{
v5 = malloc(8uLL);
v6 = v5;
if ( v5 )
{
*v5 = a1;
LODWORD(thread1List[v2]) = clone((int (*)(void *))thread1Start, v4 + 0x100000, 3857, v5);
if ( LODWORD(thread1List[numthreads]) == -1 )
{
free(*((void **)&thread1List[numthreads] + 1));
free(v6);
result = 3LL;
}
else
{
result = 0LL;
++numthreads;
}
}
else
{
free(v4);
result = 2LL;
}
}
else
{
result = 2LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
char *v3; // rax
char *v4; // rbp
_QWORD *v5; // rax
void *v6; // r13

result = 1LL;
if ( numthreads != 10 )
{
v2 = numthreads;
v3 = (char *)malloc(0x100000uLL);
*((_QWORD *)&thread1List[v2] + 1) = v3;
v4 = v3;
if ( v3 )
{
v5 = malloc(8uLL);
v6 = v5;
if ( v5 )
{
*v5 = a1;
LODWORD(thread1List[v2]) = clone((int (*)(void *))thread1Start, v4 + 0x100000, 3857, v5);
if ( LODWORD(thread1List[numthreads]) == -1 )
{
free(*((void **)&thread1List[numthreads] + 1));
free(v6);
result = 3LL;
}
else
{
result = 0LL;
++numthreads;
}
}
else
{
free(v4);
result = 2LL;
}
}
else
{
result = 2LL;
}
}
return result;
}

original_code:
int spawn_thread1( void (*func)(void) )
{
 struct thread1Arguments* arguments = ((void *)0);
 if ( numthreads == 10 ) return 1;
 thread1List[numthreads].stack = malloc( (1024*1024) );
 if ( thread1List[numthreads].stack == 0 )
 {
  ;
  return 2;
 }
 arguments = (struct thread1Arguments*) malloc( sizeof(*arguments) );
 if ( arguments == 0 ) {
  free( thread1List[numthreads].stack );
  ;
  return 2;
 }
 arguments->function = func;
 thread1List[numthreads].pid = clone( &thread1Start, (char*) thread1List[numthreads].stack + (1024*1024),
  17 | 0x00000200 | 0x00000400 | 0x00000800 | 0x00000100, arguments );
 if ( thread1List[numthreads].pid == -1 )
 {
  free( thread1List[numthreads].stack );
  free( arguments );
  ;
  return 3;
 }
 numthreads ++;
 return 0;
}

canonical_original_code:
int spawn_thread1(void (*func)())
{
 struct thread1Arguments *arguments = ((void *)0);
 if ( numthreads == 10 ) return 1;
 thread1List[numthreads].stack = malloc( (1024*1024) );
 if ( thread1List[numthreads].stack == 0 )
 {
  ;
  return 2;
 }
 arguments = (struct thread1Arguments *) malloc( sizeof(*arguments) );
 if ( arguments == 0 ) {
  free( thread1List[numthreads].stack );
  ;
  return 2;
 }
 arguments->function = func;
 thread1List[numthreads].pid = clone( &thread1Start, (char *) thread1List[numthreads].stack + (1024*1024),
  17 | 0x00000200 | 0x00000400 | 0x00000800 | 0x00000100, arguments );
 if ( thread1List[numthreads].pid == -1 )
 {
  free( thread1List[numthreads].stack );
  free( arguments );
  ;
  return 3;
 }
 numthreads ++;
 return 0;
}

variable_types:
func
void (*)()

user_defined_types: struct thread1Arguments { void (*function)(); }


waitForAllthreads

decompiled_code:
__int64 waitForAllthreads()
{
__pid_t v0; // eax
int v1; // ebx
__pid_t v2; // ecx
int v3; // edi
__int64 v4; // rax
int v5; // ebp
__int64 v6; // r12

v0 = getpid();
v1 = numthreads;
if ( parentPid != v0 )
return 4LL;
LABEL_2:
if ( v1 > 0 )
{
do
{
LABEL_3:
v2 = wait(0LL);
if ( v2 == -1 )
exit(1);
v3 = numthreads;
if ( numthreads <= 0 )
break;
v4 = 0LL;
while ( 1 )
{
v1 = v4;
if ( LODWORD(thread1List[v4]) == v2 )
break;
if ( ++v4 == numthreads )
goto LABEL_3;
}
v5 = numthreads - 1;
v6 = (int)v4;
--numthreads;
free(*((void **)&thread1List[v6] + 1));
if ( v3 - 1 == v1 )
goto LABEL_2;
thread1List[v6] = (__int128)_mm_load_si128((const __m128i *)&thread1List[v5]);
}
while ( v5 > 0 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
__pid_t v0; // eax
int v1; // ebx
__pid_t v2; // ecx
int v3; // edi
__int64 v4; // rax
int v5; // ebp
__int64 v6; // r12

v0 = getpid();
v1 = numthreads;
if ( parentPid != v0 )
return 4LL;
LABEL_2:
if ( v1 > 0 )
{
do
{
LABEL_3:
v2 = wait(0LL);
if ( v2 == -1 )
exit(1);
v3 = numthreads;
if ( numthreads <= 0 )
break;
v4 = 0LL;
while ( 1 )
{
v1 = v4;
if ( LODWORD(thread1List[v4]) == v2 )
break;
if ( ++v4 == numthreads )
goto LABEL_3;
}
v5 = numthreads - 1;
v6 = (int)v4;
--numthreads;
free(*((void **)&thread1List[v6] + 1));
if ( v3 - 1 == v1 )
goto LABEL_2;
thread1List[v6] = (__int128)_mm_load_si128((const __m128i *)&thread1List[v5]);
}
while ( v5 > 0 );
}
return 0LL;
}

original_code:
int waitForAllthreads()
{
 pid_t pid;
 int i;
 int threadsRemaining = 0;
 pid = getpid();
 if ( pid != parentPid ) return 4;
 while ( numthreads > threadsRemaining )
 {
  pid = wait( 0 );
  if ( pid == -1 )
  {
   ;
   exit( 1 );
  }
  for ( i = 0; i < numthreads; ++ i )
  {
   if ( thread1List[i].pid == pid )
   {
    ;
    numthreads --;
    free( thread1List[i].stack );
    if ( i != numthreads )
    {
     thread1List[i] = thread1List[numthreads];
    }
    i = -1;
    break;
   }
  }
  if ( i == numthreads )
  {
   ;
  }
 }
 return 0;
}

canonical_original_code:
int waitForAllthreads()
{
 int pid;
 int i;
 int threadsRemaining = 0;
 pid = getpid();
 if ( pid != parentPid ) return 4;
 while ( numthreads > threadsRemaining )
 {
  pid = wait( 0 );
  if ( pid == -1 )
  {
   ;
   exit( 1 );
  }
  for ( i = 0; i < numthreads; ++ i )
  {
   if ( thread1List[i].pid == pid )
   {
    ;
    numthreads --;
    free( thread1List[i].stack );
    if ( i != numthreads )
    {
     thread1List[i] = thread1List[numthreads];
    }
    i = -1;
    break;
   }
  }
  if ( i == numthreads )
  {
   ;
  }
 }
 return 0;
}

variable_types: pid int

variable_types: i int

variable_types: threadsRemaining int

return_type: int


EvenOdd

decompiled_code:
int EvenOdd()
{
unsigned int v0; // ebx
int result; // eax
__int64 v2; // rsi

v0 = 1;
puts("I'm thread A:");
do
{
while ( 1 )
{
v2 = v0;
if ( (v0 & 1) != 0 )
break;
++v0;
printf("%d is even\n", v2);
result = thread1_Yield();
if ( v0 == 11 )
return result;
}
++v0;
printf("%d is odd\n", v2);
result = thread1_Yield();
}
while ( v0 != 11 );
return result;
}

canonical_decompiled_code:
int func12()
{
unsigned int v0; // ebx
int result; // eax
__int64 v2; // rsi

v0 = 1;
puts("I'm thread A:");
do
{
while ( 1 )
{
v2 = v0;
if ( (v0 & 1) != 0 )
break;
++v0;
printf("%d is even\n", v2);
result = func9();
if ( v0 == 11 )
return result;
}
++v0;
printf("%d is odd\n", v2);
result = func9();
}
while ( v0 != 11 );
return result;
}

original_code:
void EvenOdd()
{
 int i;
 printf( "I'm thread A:\n");
 for ( i = 1; i <= 10; i++ )
 {
  if (i%2==0)
  printf("%d is even\n", i );
  else
  printf("%d is odd\n", i);
  thread1_Yield();
 }
 return;
}

return_type: void


squares

decompiled_code:
int squares()
{
unsigned int v0; // ebx
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rcx
int result; // eax

v0 = 0;
puts("I'm thread C: ");
do
{
v1 = v0;
v2 = v0;
v3 = v0 * v0;
++v0;
printf("%d*%d = %d\n", v2, v1, v3);
result = thread1_Yield();
}
while ( v0 != 10 );
return result;
}

canonical_decompiled_code:
int func13()
{
unsigned int v0; // ebx
__int64 v1; // rdx
__int64 v2; // rsi
__int64 v3; // rcx
int result; // eax

v0 = 0;
puts("I'm thread C: ");
do
{
v1 = v0;
v2 = v0;
v3 = v0 * v0;
++v0;
printf("%d*%d = %d\n", v2, v1, v3);
result = func9();
}
while ( v0 != 10 );
return result;
}

original_code:
void squares()
{
 int i;
 printf("I'm thread C: \n");
 for ( i = 0; i < 10; ++ i )
 {
  printf( "%d*%d = %d\n", i, i, i*i );
  thread1_Yield();
 }
}


fib

decompiled_code:
__int64 fib()
{
int v0; // ebp
unsigned int v1; // ebx
__int64 result; // rax
unsigned int v3; // er12

v0 = 9;
v1 = 1;
puts("I'm thread B: ");
printf("fibonacci series:\n ");
puts("0\n1");
LODWORD(result) = 0;
do
{
v3 = v1;
v1 += result;
printf("%d\n", v1);
thread1_Yield();
result = v3;
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebp
unsigned int v1; // ebx
__int64 result; // rax
unsigned int v3; // er12

v0 = 9;
v1 = 1;
puts("I'm thread B: ");
printf("fibonacci series:\n ");
puts("0\n1");
LODWORD(result) = 0;
do
{
v3 = v1;
v1 += result;
printf("%d\n", v1);
func9();
result = v3;
--v0;
}
while ( v0 );
return result;
}

original_code:
void fib()
{
 int i,next;
 int first=0;
 int second=1;
 printf("I'm thread B: \n");
 printf("fibonacci series:\n ");
 printf( "0\n1\n" );
 for( i = 2; i<=10; i++ )
 {
  next = first + second;
  printf("%d\n",next);
  first = second;
  second = next;
  thread1_Yield();
 }
}

canonical_original_code:
void fib()
{
 int i; int next;
 int first = 0;
 int second = 1;
 printf("I'm thread B: \n");
 printf("fibonacci series:\n ");
 printf( "0\n1\n" );
 for( i = 2; i<=10; i++ )
 {
  next = first + second;
  printf("%d\n",next);
  first = second;
  second = next;
  thread1_Yield();
 }
}

variable_types: next int

variable_types: first int

variable_types: second int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // er12
int v5; // er13
char *v6; // rbx
char *v7; // rax
char *v8; // rax
int v9; // [rsp+0h] [rbp-4CE0h]
int fd; // [rsp+4h] [rbp-4CDCh]
char v11[15]; // [rsp+9h] [rbp-4CD7h] BYREF
struct stat v12; // [rsp+18h] [rbp-4CC8h] BYREF
char dest[16]; // [rsp+A8h] [rbp-4C38h] BYREF
char v14[496]; // [rsp+B8h] [rbp-4C28h] BYREF
char src[16]; // [rsp+2A8h] [rbp-4A38h] BYREF
char v16[496]; // [rsp+2B8h] [rbp-4A28h] BYREF
char filename[1024]; // [rsp+4A8h] [rbp-4838h] BYREF
char path[1024]; // [rsp+8A8h] [rbp-4438h] BYREF
char buf[16440]; // [rsp+CA8h] [rbp-4038h] BYREF

*(_OWORD *)dest = 0LL;
memset(v14, 0, sizeof(v14));
*(_OWORD *)src = 0LL;
memset(v16, 0, sizeof(v16));
if ( argc == 3 )
{
strcpy(dest, argv[1]);
strcpy(src, argv[2]);
}
else
{
if ( argc != 2 )
{
printf("take one or two arguments,%d given\n", (unsigned int)(argc - 1));
exit(1);
}
v3 = argv[1];
strcpy(dest, v3);
strcpy(src, v3);
}
correct_dict(dest);
correct_dict(src);
printf("copy from %s to %s..................\n", dest, src);
fd = inotify_init();
if ( fd >= 0 )
{
if ( inotify_add_watch(fd, argv[1], 0x88u) >= 0 )
{
while ( 1 )
{
v4 = read(fd, buf, 0x4000uLL);
if ( v4 <= 0 )
break;
v5 = 0;
do
{
v6 = &buf[v5];
if ( *((_DWORD *)v6 + 3) )
{
v7 = stpcpy(filename, dest);
strcpy(v7, v6 + 16);
printf("found a new %s \n", filename);
if ( (unsigned int)stat(filename, &v12) == -1 )
{
printf("can not get status of %s \n", filename);
v5 += *((_DWORD *)v6 + 3) + 16;
}
else if ( (v12.st_mode & 0x8000) == 0 )
{
printf("\t but not a file");
v5 += *((_DWORD *)v6 + 3) + 16;
}
else
{
get_format(filename);
if ( v11[0] )
{
v8 = stpcpy(path, src);
strcpy(v8, v11);
v9 = mkdir(path, 0x1FFu);
if ( *__errno_location() != 17 && v9 < 0 )
callerror("error in creating directory", path);
strcat(path, v6 + 16);
correct_ext(path, v11);
write_file(filename, path);
printf("just copyed from %s to %s \n", filename, path);
v5 += *((_DWORD *)v6 + 3) + 16;
}
else
{
puts("unknown file signature file skiped");
v5 += *((_DWORD *)v6 + 3) + 16;
}
}
}
else
{
v5 += 16;
}
}
while ( v5 < v4 );
}
callerror("Problem in reading watch instance", (char *)"");
}
callerror("can not add inotify watch", (char *)"");
}
callerror("cannot obtain an inotify instance", (char *)"");
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // er12
int v5; // er13
char *v6; // rbx
char *v7; // rax
char *v8; // rax
int v9; // [rsp+0h] [rbp-4CE0h]
int fd; // [rsp+4h] [rbp-4CDCh]
char v11[15]; // [rsp+9h] [rbp-4CD7h] BYREF
struct stat v12; // [rsp+18h] [rbp-4CC8h] BYREF
char dest[16]; // [rsp+A8h] [rbp-4C38h] BYREF
char v14[496]; // [rsp+B8h] [rbp-4C28h] BYREF
char src[16]; // [rsp+2A8h] [rbp-4A38h] BYREF
char v16[496]; // [rsp+2B8h] [rbp-4A28h] BYREF
char filename[1024]; // [rsp+4A8h] [rbp-4838h] BYREF
char path[1024]; // [rsp+8A8h] [rbp-4438h] BYREF
char buf[16440]; // [rsp+CA8h] [rbp-4038h] BYREF

*(_OWORD *)dest = 0LL;
memset(v14, 0, sizeof(v14));
*(_OWORD *)src = 0LL;
memset(v16, 0, sizeof(v16));
if ( argc == 3 )
{
strcpy(dest, argv[1]);
strcpy(src, argv[2]);
}
else
{
if ( argc != 2 )
{
printf("take one or two arguments,%d given\n", (unsigned int)(argc - 1));
exit(1);
}
v3 = argv[1];
strcpy(dest, v3);
strcpy(src, v3);
}
func7(dest);
func7(src);
printf("copy from %s to %s..................\n", dest, src);
fd = inotify_init();
if ( fd >= 0 )
{
if ( inotify_add_watch(fd, argv[1], 0x88u) >= 0 )
{
while ( 1 )
{
v4 = read(fd, buf, 0x4000uLL);
if ( v4 <= 0 )
break;
v5 = 0;
do
{
v6 = &buf[v5];
if ( *((_DWORD *)v6 + 3) )
{
v7 = stpcpy(filename, dest);
strcpy(v7, v6 + 16);
printf("found a new %s \n", filename);
if ( (unsigned int)func16(filename, &v12) == -1 )
{
printf("can not get status of %s \n", filename);
v5 += *((_DWORD *)v6 + 3) + 16;
}
else if ( (v12.st_mode & 0x8000) == 0 )
{
printf("\t but not a file");
v5 += *((_DWORD *)v6 + 3) + 16;
}
else
{
func12(filename);
if ( v11[0] )
{
v8 = stpcpy(path, src);
strcpy(v8, v11);
v9 = mkdir(path, 0x1FFu);
if ( *__errno_location() != 17 && v9 < 0 )
func8("error in creating directory", path);
strcat(path, v6 + 16);
func13(path, v11);
func9(filename, path);
printf("just copyed from %s to %s \n", filename, path);
v5 += *((_DWORD *)v6 + 3) + 16;
}
else
{
puts("unknown file signature file skiped");
v5 += *((_DWORD *)v6 + 3) + 16;
}
}
}
else
{
v5 += 16;
}
}
while ( v5 < v4 );
}
func8("Problem in reading watch instance", (char *)"");
}
func8("can not add inotify watch", (char *)"");
}
func8("cannot obtain an inotify instance", (char *)"");
}

original_code:
int main(int arg, char *argv[])
{
 int ifd, wd, i, n, a;
 char buf[16384];
 char fileloc[1024];
 char fileloc1[1024];
 char format[15];
        char arg1[512] = "";
        char arg2[512] = "";
 struct inotify_event *ev;
 struct stat sb;
        if (arg == 3){
         strcat(arg1,argv[1]);
         strcat(arg2,argv[2]);
        }
        else if (arg == 2){
         strcat(arg1,argv[1]);
         strcat(arg2,argv[1]);
        }
        else {
                printf("take one or two arguments,%d given\n",arg -1);
                exit(1);
        }
        correct_dict(arg1);
        correct_dict(arg2);
 printf("copy from %s to  %s..................\n",arg1,arg2);
 ifd = inotify_init();
 if (ifd < 0)
  callerror("cannot obtain an inotify instance","");
 wd = inotify_add_watch(ifd, argv[1], 0x00000008|0x00000080);
 if (wd < 0)
  callerror("can not add inotify watch","");
 while (1){
  n = read(ifd, buf, sizeof(buf));
  if (n<= 0)
   callerror("Problem in reading watch instance","");
  i = 0;
  while (i < n){
   ev = (struct inotify_event *) &buf[i];
   if (!ev->len){
    i += sizeof(struct inotify_event) + ev->len;
    continue;
   }
   fileloc[0] = '\0';
                 strcat(fileloc,arg1);
                 strcat(fileloc,ev->name);
   printf("found a new %s \n", fileloc);
   if (stat(fileloc, &sb) == -1){
    printf("can not get status of %s \n",fileloc);
                                i += sizeof(struct inotify_event) + ev->len;
                                continue;
   }
   if (!(sb.st_mode & 0100000)){
    printf("\t but not a file");
    i += sizeof(struct inotify_event) + ev->len;
    continue;
   }
   get_format(fileloc,format);
   if (format[0] == '\0'){
    printf("unknown file signature file skiped\n");
    i += sizeof(struct inotify_event) + ev->len;
    continue;
   }
                        fileloc1[0] = '\0';
                        strcat(fileloc1,arg2);
   strcat(fileloc1,format);
                        a = mkdir(fileloc1,0777);
                        if ((a < 0)&((*__errno_location ()) != 17))
                                callerror("error in creating directory",fileloc1);
                        strcat(fileloc1,ev->name);
   correct_ext(fileloc1,format);
                        write_file(fileloc,fileloc1);
   printf("just copyed from %s to  %s \n",fileloc,fileloc1);
   i += sizeof(struct inotify_event) + ev->len;
  }
 }
}

canonical_original_code:
int main(int arg, char *argv[])
{
 int ifd; int wd; int i; int n; int a;
 char buf[16384];
 char fileloc[1024];
 char fileloc1[1024];
 char format[15];
        char arg1[512] = "";
        char arg2[512] = "";
 struct inotify_event *ev;
 struct stat sb;
        if (arg == 3){
         strcat(arg1,argv[1]);
         strcat(arg2,argv[2]);
        }
        else if (arg == 2){
         strcat(arg1,argv[1]);
         strcat(arg2,argv[1]);
        }
        else {
                printf("take one or two arguments,%d given\n",arg -1);
                exit(1);
        }
        correct_dict(arg1);
        correct_dict(arg2);
 printf("copy from %s to  %s..................\n",arg1,arg2);
 ifd = inotify_init();
 if (ifd < 0)
  callerror("cannot obtain an inotify instance","");
 wd = inotify_add_watch(ifd, argv[1], 0x00000008|0x00000080);
 if (wd < 0)
  callerror("can not add inotify watch","");
 while (1){
  n = read(ifd, buf, sizeof(buf));
  if (n<= 0)
   callerror("Problem in reading watch instance","");
  i = 0;
  while (i < n){
   ev = (struct inotify_event *) &buf[i];
   if (!ev->len){
    i += sizeof(struct inotify_event) + ev->len;
    continue;
   }
   fileloc[0] = '\0';
                 strcat(fileloc,arg1);
                 strcat(fileloc,ev->name);
   printf("found a new %s \n", fileloc);
   if (stat(fileloc, &sb) == -1){
    printf("can not get status of %s \n",fileloc);
                                i += sizeof(struct inotify_event) + ev->len;
                                continue;
   }
   if (!(sb.st_mode & 0100000)){
    printf("\t but not a file");
    i += sizeof(struct inotify_event) + ev->len;
    continue;
   }
   get_format(fileloc,format);
   if (format[0] == '\0'){
    printf("unknown file signature file skiped\n");
    i += sizeof(struct inotify_event) + ev->len;
    continue;
   }
                        fileloc1[0] = '\0';
                        strcat(fileloc1,arg2);
   strcat(fileloc1,format);
                        a = mkdir(fileloc1,0777);
                        if ((a < 0)&((*__errno_location ()) != 17))
                                callerror("error in creating directory",fileloc1);
                        strcat(fileloc1,ev->name);
   correct_ext(fileloc1,format);
                        write_file(fileloc,fileloc1);
   printf("just copyed from %s to  %s \n",fileloc,fileloc1);
   i += sizeof(struct inotify_event) + ev->len;
  }
 }
}

variable_types: arg int

variable_types:
argv
char *[]

variable_types: ifd int

variable_types: wd int

variable_types: n int

variable_types: a int

variable_types:
buf
char [16384]

variable_types:
fileloc
char [1024]

variable_types:
format
char [15]

variable_types: struct inotify_event { int wd; unsigned int mask; unsigned int cookie; unsigned int len; char name[]; } *

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

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


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

result = strlen(a1);
if ( a1[(int)result - 1] != 47 )
*(_WORD *)&a1[result] = 47;
return result;
}

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

result = strlen(a1);
if ( a1[(int)result - 1] != 47 )
*(_WORD *)&a1[result] = 47;
return result;
}

original_code:
void correct_dict(char *p)
{
        int l;
        l = strlen(p);
        if (p[l-1]!='/')
                strcat(p,"/");
}

variable_types:
p
char *

variable_types: l int


callerror

decompiled_code:
void __fastcall __noreturn callerror(char *s, char *src)
{
char *v2; // rax
char v3[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = stpcpy(v3, s);
strcpy(v2, src);
perror(s);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(char *s, char *src)
{
char *v2; // rax
char v3[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = stpcpy(v3, s);
strcpy(v2, src);
perror(s);
exit(1);
}

original_code:
void callerror(char *string, char *file)
{
 char error[512] = "";
 strcat(error, string);
 strcat(error, file);
 perror(string);
 exit(1);
}

variable_types:
string
char *

variable_types:
file
char *

variable_types:
error
char [512]


decompiled_code:
ssize_t __fastcall write_file(char *src, char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
ssize_t result; // rax
_BYTE v6[552]; // [rsp+0h] [rbp-228h] BYREF

v2 = open(src, 0);
if ( v2 <= 0 )
callerror("error in opening ", src);
v3 = v2;
v4 = open(a2, 577, 420LL);
if ( v4 <= 0 )
callerror("error in opening ", a2);
while ( 1 )
{
result = read(v3, v6, 0x200uLL);
if ( (int)result <= 0 )
break;
if ( write(v4, v6, (int)result) != (int)result )
callerror("error in writing", a2);
}
if ( (_DWORD)result )
callerror("error in reading ", src);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func9(char *src, char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
ssize_t result; // rax
_BYTE v6[552]; // [rsp+0h] [rbp-228h] BYREF

v2 = open(src, 0);
if ( v2 <= 0 )
func8("error in opening ", src);
v3 = v2;
v4 = open(a2, 577, 420LL);
if ( v4 <= 0 )
func8("error in opening ", a2);
while ( 1 )
{
result = read(v3, v6, 0x200uLL);
if ( (int)result <= 0 )
break;
if ( write(v4, v6, (int)result) != (int)result )
func8("error in writing", a2);
}
if ( (_DWORD)result )
func8("error in reading ", src);
return result;
}

original_code:
void write_file(char *arg1,char *arg2)
{
        int fdr,fdw,n;
        char buf[512];
        fdr = open(arg1,00);
        if (fdr <= 0)
  callerror("error in opening ", arg1);
        fdw = open(arg2,01|0100|01000, 0644);
        if (fdw <= 0)
  callerror("error in opening ",arg2);
        while ((n = read(fdr,buf,sizeof(buf)))>0)
                if (write(fdw, buf, n) != n)
   callerror("error in writing", arg2);
        if (n < 0)
                callerror("error in reading ",arg1);
}

canonical_original_code:
void write_file(char *arg1, char *arg2)
{
        int fdr; int fdw; int n;
        char buf[512];
        fdr = open(arg1,00);
        if (fdr <= 0)
  callerror("error in opening ", arg1);
        fdw = open(arg2,01|0100|01000, 0644);
        if (fdw <= 0)
  callerror("error in opening ",arg2);
        while ((n = read(fdr,buf,sizeof(buf)))>0)
                if (write(fdw, buf, n) != n)
   callerror("error in writing", arg2);
        if (n < 0)
                callerror("error in reading ",arg1);
}

variable_types: fdr int

variable_types: fdw int

variable_types:
buf
char [512]


openfile

decompiled_code:
int __fastcall openfile(char *src)
{
int result; // eax

result = open(src, 0);
if ( result < 0 )
callerror("error in opening ", src);
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *src)
{
int result; // eax

result = open(src, 0);
if ( result < 0 )
func8("error in opening ", src);
return result;
}

original_code:
int openfile(char *file)
{
 int fd;
 fd = open(file,00);
 if (fd < 0){
  callerror("error in opening ",file);
 }
 return fd;
}

variable_types: fd int


cmp

original_code:
int cmp(char a[],char b[])
{
        int i,l;
        l = 4;
        for (i = 0; i<l; i++)
                if (a[i]!=b[i])
                        return 0;
        return 1;
}

canonical_original_code:
int cmp(char a[], char b[])
{
        int i; int l;
        l = 4;
        for (i = 0; i<l; i++)
                if (a[i]!=b[i])
                        return 0;
        return 1;
}

variable_types:
a
char []

variable_types:
b
char []

variable_types: i int


decompiled_code:
__int64 __fastcall get_format(char *src, char *a2)
{
int v2; // ebp
__int64 result; // rax
_WORD v4[6]; // [rsp+Eh] [rbp-3Ah] BYREF
int v5; // [rsp+1Ah] [rbp-2Eh] BYREF
__int16 v6; // [rsp+1Eh] [rbp-2Ah]
int v7; // [rsp+20h] [rbp-28h] BYREF
__int16 v8; // [rsp+24h] [rbp-24h]
char buf[34]; // [rsp+26h] [rbp-22h] BYREF

v4[5] = 0;
v8 = 102;
strcpy((char *)v4, "%PDF-");
*(_DWORD *)&v4[3] = -520103681;
v5 = 1196314761;
v6 = 13;
v7 = 0x20000000;
v2 = openfile(src);
if ( (int)read(v2, buf, 0xAuLL) < 0 )
callerror("error in reading", src);
close(v2);
*a2 = 0;
result = cmp((__int64)v4, (__int64)buf);
if ( (_DWORD)result )
{
strcpy(a2, "pdf/");
}
else
{
result = cmp((__int64)&v4[3], (__int64)buf);
if ( (_DWORD)result )
{
strcpy(a2, "jpg/");
}
else
{
result = cmp((__int64)&v5, (__int64)buf);
if ( (_DWORD)result )
{
strcpy(a2, "png/");
}
else
{
result = cmp((__int64)&v7, (__int64)buf);
if ( (_DWORD)result )
strcpy(a2, "mp4/");
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *src, char *a2)
{
int v2; // ebp
__int64 result; // rax
_WORD v4[6]; // [rsp+Eh] [rbp-3Ah] BYREF
int v5; // [rsp+1Ah] [rbp-2Eh] BYREF
__int16 v6; // [rsp+1Eh] [rbp-2Ah]
int v7; // [rsp+20h] [rbp-28h] BYREF
__int16 v8; // [rsp+24h] [rbp-24h]
char buf[34]; // [rsp+26h] [rbp-22h] BYREF

v4[5] = 0;
v8 = 102;
strcpy((char *)v4, "%PDF-");
*(_DWORD *)&v4[3] = -520103681;
v5 = 1196314761;
v6 = 13;
v7 = 0x20000000;
v2 = func10(src);
if ( (int)read(v2, buf, 0xAuLL) < 0 )
func8("error in reading", src);
close(v2);
*a2 = 0;
result = func11((__int64)v4, (__int64)buf);
if ( (_DWORD)result )
{
strcpy(a2, "pdf/");
}
else
{
result = func11((__int64)&v4[3], (__int64)buf);
if ( (_DWORD)result )
{
strcpy(a2, "jpg/");
}
else
{
result = func11((__int64)&v5, (__int64)buf);
if ( (_DWORD)result )
{
strcpy(a2, "png/");
}
else
{
result = func11((__int64)&v7, (__int64)buf);
if ( (_DWORD)result )
strcpy(a2, "mp4/");
}
}
}
return result;
}

original_code:
void get_format(char *loc, char *format)
{
 int fd, l;
 char buff[10];
        char pdf[] = {0x25,0x50,0x44,0x46,0x2d,'\0'};
        char jpg[] = {0xff,0xd8,0xff,0xe0,0x00,'\0'};
        char png[] = {0x89,0x50,0x4e,0x47,0x0d,'\0'};
        char mp4[] = {0x00,0x00,0x00,0x20,0x66,'\0'};
 fd = openfile(loc);
 l = read(fd,buff,10);
 if (l < 0)
  callerror("error in reading",loc);
 close(fd);
 format[0] = '\0';
 if (cmp(pdf,buff))
  strcat(format,"pdf/");
 else if (cmp(jpg,buff))
  strcat(format,"jpg/");
        else if (cmp(png,buff))
  strcat(format,"png/");
 else if (cmp(mp4,buff))
  strcat(format,"mp4/");
 else
  format[0] = '\0';
}

canonical_original_code:
void get_format(char *loc, char *format)
{
 int fd; int l;
 char buff[10];
        char pdf[] = {0x25,0x50,0x44,0x46,0x2d,'\0'};
        char jpg[] = {0xff,0xd8,0xff,0xe0,0x00,'\0'};
        char png[] = {0x89,0x50,0x4e,0x47,0x0d,'\0'};
        char mp4[] = {0x00,0x00,0x00,0x20,0x66,'\0'};
 fd = openfile(loc);
 l = read(fd,buff,10);
 if (l < 0)
  callerror("error in reading",loc);
 close(fd);
 format[0] = '\0';
 if (cmp(pdf,buff))
  strcat(format,"pdf/");
 else if (cmp(jpg,buff))
  strcat(format,"jpg/");
        else if (cmp(png,buff))
  strcat(format,"png/");
 else if (cmp(mp4,buff))
  strcat(format,"mp4/");
 else
  format[0] = '\0';
}

variable_types:
loc
char *

variable_types:
format
char *

variable_types:
buff
char [10]

variable_types:
pdf
char []

variable_types:
jpg
char []

variable_types:
png
char []


decompiled_code:
char *__fastcall correct_ext(char *s, char *src)
{
size_t v2; // rax

src[(int)strlen(src) - 1] = 0;
v2 = strlen(s);
s[v2] = 46;
return strcpy(&s[v2 + 1], src);
}

canonical_decompiled_code:
char *__fastcall func13(char *s, char *src)
{
size_t v2; // rax

src[(int)strlen(src) - 1] = 0;
v2 = strlen(s);
s[v2] = 46;
return strcpy(&s[v2 + 1], src);
}

original_code:
void correct_ext(char *file, char *format)
{
 int i;
 i = strlen(format);
 format[i - 1] ='\0';
 strcat(file,".");
 strcat(file,format);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
DIR *v4; // r12
struct dirent *v5; // rbp
const char *v6; // rbp
char *v7; // rax
int v8; // er15
char *v9; // rbx
int v10; // ebx
size_t v12; // rax
char *v13; // rdi
char *v14; // rsi
size_t v15; // rax
__m128i v16; // xmm0
char buf[5]; // [rsp+1h] [rbp-535h] BYREF
_WORD v18[6]; // [rsp+6h] [rbp-530h] BYREF
int v19; // [rsp+12h] [rbp-524h] BYREF
__int16 v20; // [rsp+16h] [rbp-520h]
int v21; // [rsp+18h] [rbp-51Eh] BYREF
__int16 v22; // [rsp+1Ch] [rbp-51Ah]
char name[112]; // [rsp+1Eh] [rbp-518h] BYREF
char path[112]; // [rsp+8Eh] [rbp-4A8h] BYREF
char dest[16]; // [rsp+FEh] [rbp-438h] BYREF
char v26[480]; // [rsp+10Eh] [rbp-428h] BYREF
int v27; // [rsp+2EEh] [rbp-248h]
char src[16]; // [rsp+2FEh] [rbp-238h] BYREF
char v29[480]; // [rsp+30Eh] [rbp-228h] BYREF
int v30; // [rsp+4EEh] [rbp-48h]

v18[5] = 0;
v22 = 102;
memset(v26, 0, sizeof(v26));
strcpy((char *)v18, "%PDF-");
*(_DWORD *)&v18[3] = -520103681;
v19 = 1196314761;
v20 = 13;
v21 = 0x20000000;
*(_OWORD *)dest = 0LL;
v27 = 0;
memset(v29, 0, sizeof(v29));
*(_OWORD *)src = 0LL;
v30 = 0;
if ( argc == 3 )
{
strcpy(dest, argv[1]);
strcpy(src, argv[2]);
}
else
{
if ( argc != 2 )
{
printf("take one or two arguments,%d given\n", (unsigned int)(argc - 1));
exit(1);
}
v3 = argv[1];
strcpy(dest, v3);
strcpy(src, v3);
}
correct_dict(dest, 0.0);
correct_dict(src, 0.0);
v4 = (DIR *)open_dir(dest);
LABEL_5:
v5 = readdir(v4);
if ( v5 )
{
while ( 1 )
{
if ( v5->d_type != 8 )
goto LABEL_5;
v6 = v5->d_name;
v7 = stpcpy(name, dest);
strcpy(v7, v6);
v8 = openfile(name);
if ( read(v8, buf, 5uLL) < 0 )
break;
close(v8);
v9 = stpcpy(path, src);
if ( (unsigned int)cmp(&v19, buf) )
{
strcpy(v9, "png/");
}
else if ( (unsigned int)cmp(&v18[3], buf) )
{
strcpy(v9, "jpg/");
}
else if ( (unsigned int)cmp(v18, buf) )
{
strcpy(v9, "pdf/");
}
else
{
if ( !(unsigned int)cmp(&v21, buf) )
goto LABEL_5;
strcpy(v9, "mp4/");
}
v10 = mkdir(path, 0x1FFu);
if ( *__errno_location() != 17 && v10 < 0 )
{
error[0] = 47;
v12 = strlen(error);
qmemcpy(&error[v12], "\nerror in creating directory ", 0x1DuLL);
v13 = (char *)&unk_4040FD + v12;
v14 = path;
goto LABEL_22;
}
strcat(path, v6);
write_file(name, path);
unlink(name);
v5 = readdir(v4);
if ( !v5 )
goto LABEL_16;
}
error[0] = 0;
v15 = strlen(error);
v16 = _mm_load_si128((const __m128i *)&xmmword_402070);
v14 = name;
*(__int16 *)((char *)&word_4040F0 + v15) = 8295;
v13 = &::dest[v15];
*(__m128i *)&error[v15] = v16;
LABEL_22:
strcpy(v13, v14);
perror(error);
exit(1);
}
LABEL_16:
closedir(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
DIR *v4; // r12
struct dirent *v5; // rbp
const char *v6; // rbp
char *v7; // rax
int v8; // er15
char *v9; // rbx
int v10; // ebx
size_t v12; // rax
char *v13; // rdi
char *v14; // rsi
size_t v15; // rax
__m128i v16; // xmm0
char buf[5]; // [rsp+1h] [rbp-535h] BYREF
_WORD v18[6]; // [rsp+6h] [rbp-530h] BYREF
int v19; // [rsp+12h] [rbp-524h] BYREF
__int16 v20; // [rsp+16h] [rbp-520h]
int v21; // [rsp+18h] [rbp-51Eh] BYREF
__int16 v22; // [rsp+1Ch] [rbp-51Ah]
char name[112]; // [rsp+1Eh] [rbp-518h] BYREF
char path[112]; // [rsp+8Eh] [rbp-4A8h] BYREF
char dest[16]; // [rsp+FEh] [rbp-438h] BYREF
char v26[480]; // [rsp+10Eh] [rbp-428h] BYREF
int v27; // [rsp+2EEh] [rbp-248h]
char src[16]; // [rsp+2FEh] [rbp-238h] BYREF
char v29[480]; // [rsp+30Eh] [rbp-228h] BYREF
int v30; // [rsp+4EEh] [rbp-48h]

v18[5] = 0;
v22 = 102;
memset(v26, 0, sizeof(v26));
strcpy((char *)v18, "%PDF-");
*(_DWORD *)&v18[3] = -520103681;
v19 = 1196314761;
v20 = 13;
v21 = 0x20000000;
*(_OWORD *)dest = 0LL;
v27 = 0;
memset(v29, 0, sizeof(v29));
*(_OWORD *)src = 0LL;
v30 = 0;
if ( argc == 3 )
{
strcpy(dest, argv[1]);
strcpy(src, argv[2]);
}
else
{
if ( argc != 2 )
{
printf("take one or two arguments,%d given\n", (unsigned int)(argc - 1));
exit(1);
}
v3 = argv[1];
strcpy(dest, v3);
strcpy(src, v3);
}
func7(dest, 0.0);
func7(src, 0.0);
v4 = (DIR *)open_dir(dest);
LABEL_5:
v5 = readdir(v4);
if ( v5 )
{
while ( 1 )
{
if ( v5->d_type != 8 )
goto LABEL_5;
v6 = v5->d_name;
v7 = stpcpy(name, dest);
strcpy(v7, v6);
v8 = func9(name);
if ( read(v8, buf, 5uLL) < 0 )
break;
close(v8);
v9 = stpcpy(path, src);
if ( (unsigned int)func10(&v19, buf) )
{
strcpy(v9, "png/");
}
else if ( (unsigned int)func10(&v18[3], buf) )
{
strcpy(v9, "jpg/");
}
else if ( (unsigned int)func10(v18, buf) )
{
strcpy(v9, "pdf/");
}
else
{
if ( !(unsigned int)func10(&v21, buf) )
goto LABEL_5;
strcpy(v9, "mp4/");
}
v10 = mkdir(path, 0x1FFu);
if ( *__errno_location() != 17 && v10 < 0 )
{
error[0] = 47;
v12 = strlen(error);
qmemcpy(&error[v12], "\nerror in creating directory ", 0x1DuLL);
v13 = (char *)&unk_4040FD + v12;
v14 = path;
goto LABEL_22;
}
strcat(path, v6);
func8(name, path);
unlink(name);
v5 = readdir(v4);
if ( !v5 )
goto LABEL_16;
}
error[0] = 0;
v15 = strlen(error);
v16 = _mm_load_si128((const __m128i *)&xmmword_402070);
v14 = name;
*(__int16 *)((char *)&word_4040F0 + v15) = 8295;
v13 = &::dest[v15];
*(__m128i *)&error[v15] = v16;
LABEL_22:
strcpy(v13, v14);
perror(error);
exit(1);
}
LABEL_16:
closedir(v4);
return 0;
}

variable_types: arg int

variable_types:
argv
char *[]

variable_types: ifd int

variable_types: wd int

variable_types: n int

variable_types: a int

variable_types:
buf
char [16384]

variable_types:
fileloc
char [1024]

variable_types:
format
char [15]

variable_types: struct inotify_event { int wd; unsigned int mask; unsigned int cookie; unsigned int len; char name[]; } *

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


canonical_original_code:
void correct_dict(char *p)
{
        int l;
        l = strlen(p);
        if (p[l-1]!='/')
                strcat(p,"/");
}

variable_types:
p
char *

variable_types: l int


decompiled_code:
ssize_t __fastcall write_file(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
ssize_t result; // rax
char *v6; // rdi
size_t v7; // rax
__m128i v8; // xmm0
size_t v9; // rax
__m128i v10; // xmm0
_BYTE v11[552]; // [rsp+0h] [rbp-228h] BYREF

v2 = open(a1, 0);
if ( v2 <= 0 )
{
error[0] = 0;
v9 = strlen(error);
v10 = _mm_load_si128((const __m128i *)&xmmword_402050);
a2 = a1;
*(__int16 *)((char *)&word_4040F0 + v9) = 8295;
v6 = &dest[v9];
*(__m128i *)&error[v9] = v10;
goto LABEL_10;
}
v3 = v2;
v4 = open(a2, 577, 420LL);
if ( v4 <= 0 )
{
error[0] = 0;
v7 = strlen(error);
v8 = _mm_load_si128((const __m128i *)&xmmword_402050);
goto LABEL_9;
}
while ( 1 )
{
result = read(v3, v11, 0x200uLL);
if ( (int)result <= 0 )
break;
if ( write(v4, v11, (int)result) != (int)result )
{
error[0] = 0;
v7 = strlen(error);
v8 = _mm_load_si128((const __m128i *)&xmmword_402060);
LABEL_9:
*(__m128i *)&error[v7] = v8;
v6 = &dest[v7];
*(__int16 *)((char *)&word_4040F0 + v7) = 8295;
LABEL_10:
strcpy(v6, a2);
perror(error);
exit(1);
}
}
if ( (_DWORD)result )
{
a2 = a1;
v6 = dest;
word_4040F0 = 8295;
*(__m128i *)error = _mm_load_si128((const __m128i *)&xmmword_402070);
goto LABEL_10;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func8(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12
ssize_t result; // rax
char *v6; // rdi
size_t v7; // rax
__m128i v8; // xmm0
size_t v9; // rax
__m128i v10; // xmm0
_BYTE v11[552]; // [rsp+0h] [rbp-228h] BYREF

v2 = open(a1, 0);
if ( v2 <= 0 )
{
error[0] = 0;
v9 = strlen(error);
v10 = _mm_load_si128((const __m128i *)&xmmword_402050);
a2 = a1;
*(__int16 *)((char *)&word_4040F0 + v9) = 8295;
v6 = &dest[v9];
*(__m128i *)&error[v9] = v10;
goto LABEL_10;
}
v3 = v2;
v4 = open(a2, 577, 420LL);
if ( v4 <= 0 )
{
error[0] = 0;
v7 = strlen(error);
v8 = _mm_load_si128((const __m128i *)&xmmword_402050);
goto LABEL_9;
}
while ( 1 )
{
result = read(v3, v11, 0x200uLL);
if ( (int)result <= 0 )
break;
if ( write(v4, v11, (int)result) != (int)result )
{
error[0] = 0;
v7 = strlen(error);
v8 = _mm_load_si128((const __m128i *)&xmmword_402060);
LABEL_9:
*(__m128i *)&error[v7] = v8;
v6 = &dest[v7];
*(__int16 *)((char *)&word_4040F0 + v7) = 8295;
LABEL_10:
strcpy(v6, a2);
perror(error);
exit(1);
}
}
if ( (_DWORD)result )
{
a2 = a1;
v6 = dest;
word_4040F0 = 8295;
*(__m128i *)error = _mm_load_si128((const __m128i *)&xmmword_402070);
goto LABEL_10;
}
return result;
}

variable_types: fdr int

variable_types: fdw int

variable_types:
buf
char [512]


openfile

decompiled_code:
int __fastcall openfile(char *src)
{
int result; // eax

result = open(src, 0);
if ( result < 0 )
{
word_4040F0 = 8295;
*(__m128i *)error = _mm_load_si128((const __m128i *)&xmmword_402050);
strcpy(dest, src);
perror(error);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(char *src)
{
int result; // eax

result = open(src, 0);
if ( result < 0 )
{
word_4040F0 = 8295;
*(__m128i *)error = _mm_load_si128((const __m128i *)&xmmword_402050);
strcpy(dest, src);
perror(error);
exit(1);
}
return result;
}

canonical_original_code:
int openfile(char *file)
{
 int fd;
 fd = open(file,00);
 if (fd < 0){
  callerror("error in opening ",file);
 }
 return fd;
}

variable_types:
file
char *

variable_types: fd int


cmp

decompiled_code:
__int64 __fastcall cmp(const char *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rcx
__int64 i; // rax

v2 = strlen(a1);
if ( v2 <= 0 )
return 1LL;
v3 = (unsigned int)(v2 - 1);
for ( i = 0LL; a1[i] == *(_BYTE *)(a2 + i); ++i )
{
if ( i == v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rcx
__int64 i; // rax

v2 = strlen(a1);
if ( v2 <= 0 )
return 1LL;
v3 = (unsigned int)(v2 - 1);
for ( i = 0LL; a1[i] == *(_BYTE *)(a2 + i); ++i )
{
if ( i == v3 )
return 1LL;
}
return 0LL;
}

variable_types:
a
char []

variable_types:
b
char []

variable_types: i int


repo: aklomp/anagram

original_code:
static _Bool
input_from_args (const struct config *config, struct input *input)
{
 char *p;
 input->str = ((void *)0);
 input->len = 0;
 if (config->words.ac == 0) {
  return 0;
 }
 for (int i = 0; i < config->words.ac; i++) {
  for (char *c = config->words.av[i]; *c; c++) {
   if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace)) {
    input->len++;
   }
  }
 }
 if (input->len == 0) {
  return 0;
 }
 if ((p = input->str = malloc(input->len)) == ((void *)0)) {
  return 0;
 }
 for (int i = 0; i < config->words.ac; i++) {
  for (char *c = config->words.av[i]; *c; c++) {
   if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace)) {
    *p++ = *c;
   }
  }
 }
 return 1;
}

canonical_original_code:
static _Bool input_from_args(struct config *config, struct input *input)
{
 char *p;
 input->str = ((void *)0);
 input->len = 0;
 if (config->words.ac == 0) {
  return 0;
 }
 for (int i = 0; i < config->words.ac; i++) {
  for (char *c = config->words.av[i]; *c; c++) {
   if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace)) {
    input->len++;
   }
  }
 }
 if (input->len == 0) {
  return 0;
 }
 if ((p = input->str = malloc(input->len)) == ((void *)0)) {
  return 0;
 }
 for (int i = 0; i < config->words.ac; i++) {
  for (char *c = config->words.av[i]; *c; c++) {
   if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace)) {
    *p++ = *c;
   }
  }
 }
 return 1;
}

variable_types: struct config { char *name; char *dictfile; struct args { char **av; int ac; } words; unsigned char minlength; unsigned char haslength; _Bool print_help; } *

variable_types: struct input { char *str; unsigned long len; } *

variable_types:
c
char *

user_defined_types: struct config { char *name; char *dictfile; struct args words; unsigned char minlength; unsigned char haslength; _Bool print_help; }


original_code:
static _Bool
input_from_stdin (struct input *input)
{
 ssize_t nread;
 char *t, *p;
 input->len = 0;
 if ((p = input->str = malloc(100)) == ((void *)0)) {
  return 0;
 }
 while (input->len < 100) {
  if ((nread = read(0, p, 100 - input->len)) < 0) {
   if ((*__errno_location ()) == 4) {
    continue;
   }
   break;
  }
  if (nread == 0) {
   break;
  }
  input->len += (size_t) nread;
  p += (size_t) nread;
 }
 for (char *h = t = input->str; h < input->str + input->len; h++) {
  if (!((*__ctype_b_loc ())[(int) ((*h))] & (unsigned short int) _ISspace)) {
   *t++ = *h;
  }
 }
 if (input->len == 0 || t == input->str) {
  free(input->str);
  input->str = ((void *)0);
  return 0;
 }
 *t = '\0';
 input->len = t - input->str;
 return 1;
}

canonical_original_code:
static _Bool input_from_stdin(struct input *input)
{
 long nread;
 char *t; char *p;
 input->len = 0;
 if ((p = input->str = malloc(100)) == ((void *)0)) {
  return 0;
 }
 while (input->len < 100) {
  if ((nread = read(0, p, 100 - input->len)) < 0) {
   if ((*__errno_location ()) == 4) {
    continue;
   }
   break;
  }
  if (nread == 0) {
   break;
  }
  input->len += (unsigned long) nread;
  p += (unsigned long) nread;
 }
 for (char *h = t = input->str; h < input->str + input->len; h++) {
  if (!((*__ctype_b_loc ())[(int) ((*h))] & (unsigned short) _ISspace)) {
   *t++ = *h;
  }
 }
 if (input->len == 0 || t == input->str) {
  free(input->str);
  input->str = ((void *)0);
  return 0;
 }
 *t = '\0';
 input->len = t - input->str;
 return 1;
}

variable_types: nread long

variable_types:
t
char *

variable_types:
h
char *

user_defined_types: struct input { char *str; unsigned long len; }


decompiled_code:
__int64 __fastcall input_get(__int64 a1, char **a2)
{
__int64 result; // rax

result = input_from_args(a1, a2);
if ( !(_BYTE)result )
result = input_from_stdin(a2);
return result;
}

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

result = func0(a1, a2);
if ( !(_BYTE)result )
result = func1(a2);
return result;
}

original_code:
_Bool
input_get (const struct config *config, struct input *input)
{
 if (input_from_args(config, input)) {
  return 1;
 }
 if (input_from_stdin(input)) {
  return 1;
 }
 return 0;
}

canonical_original_code:
_Bool input_get(struct config *config, struct input *input)
{
 if (input_from_args(config, input)) {
  return 1;
 }
 if (input_from_stdin(input)) {
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall get_uint8(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = strtol(optarg, &endptr, 10);
v2 = 0;
if ( (unsigned __int64)(v1 - 1) <= 0xFE && !*endptr )
{
*a1 = v1;
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // er8
char *endptr; // [rsp+8h] [rbp-10h] BYREF

v1 = strtol(optarg, &endptr, 10);
v2 = 0;
if ( (unsigned __int64)(v1 - 1) <= 0xFE && !*endptr )
{
*a1 = v1;
v2 = 1;
}
return v2;
}

original_code:
static _Bool
get_uint8 (uint8_t *dst)
{
 char *eptr;
 const long l = strtol(optarg, &eptr, 10);
 if (l <= 0 || l > 255 || *eptr != '\0') {
  return 0;
 }
 *dst = (uint8_t) l;
 return 1;
}

canonical_original_code:
static _Bool get_uint8(unsigned char *dst)
{
 char *eptr;
 long l = strtol(optarg, &eptr, 10);
 if (l <= 0 || l > 255 || *eptr != '\0') {
  return 0;
 }
 *dst = (unsigned char) l;
 return 1;
}

variable_types:
dst
unsigned char *

variable_types:
eptr
char *

variable_types: l long


decompiled_code:
__int64 __fastcall args_parse(const char **a1, __int64 a2)
{
unsigned int v2; // er12
char *const *v4; // rsi
int v5; // eax
unsigned int v6; // er12
const char *v8; // rdx
__int64 v9; // rax

LOBYTE(v2) = a2 == 0 || a1 == 0LL;
if ( (_BYTE)v2 )
return 0LL;
v4 = *(char *const **)a2;
*a1 = *v4;
while ( 1 )
{
while ( 1 )
{
v5 = getopt_long(*(_DWORD *)(a2 + 8), v4, ":hf:m:l:", &opts_0, 0LL);
if ( v5 == -1 )
{
v9 = optind;
v6 = 1;
*((_DWORD *)a1 + 6) = *(_DWORD *)(a2 + 8) - optind;
a1[2] = (const char *)(*(_QWORD *)a2 + 8 * v9);
return v6;
}
if ( v5 == 108 )
{
if ( !(unsigned __int8)get_uint8((_BYTE *)a1 + 33) )
goto LABEL_19;
goto LABEL_12;
}
if ( v5 <= 108 )
break;
if ( v5 != 109 )
goto LABEL_14;
if ( !(unsigned __int8)get_uint8((_BYTE *)a1 + 32) )
{
LABEL_19:
v6 = 0;
fprintf(stderr, "%s: '%s': invalid value.\n", *a1, optarg);
return v6;
}
LABEL_12:
v4 = *(char *const **)a2;
}
if ( v5 != 102 )
break;
v4 = *(char *const **)a2;
a1[1] = optarg;
}
if ( v5 == 104 )
{
*((_BYTE *)a1 + 34) = 1;
return 1;
}
LABEL_14:
v8 = *a1;
if ( optopt )
fprintf(stderr, "%s: '%c': unknown option.\n", v8, (unsigned int)optopt);
else
fprintf(stderr, "%s: %s: unknown option.\n", v8, *(const char **)(*(_QWORD *)a2 + 8LL * optind - 8));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char **a1, __int64 a2)
{
unsigned int v2; // er12
char *const *v4; // rsi
int v5; // eax
unsigned int v6; // er12
const char *v8; // rdx
__int64 v9; // rax

LOBYTE(v2) = a2 == 0 || a1 == 0LL;
if ( (_BYTE)v2 )
return 0LL;
v4 = *(char *const **)a2;
*a1 = *v4;
while ( 1 )
{
while ( 1 )
{
v5 = getopt_long(*(_DWORD *)(a2 + 8), v4, ":hf:m:l:", &opts_0, 0LL);
if ( v5 == -1 )
{
v9 = optind;
v6 = 1;
*((_DWORD *)a1 + 6) = *(_DWORD *)(a2 + 8) - optind;
a1[2] = (const char *)(*(_QWORD *)a2 + 8 * v9);
return v6;
}
if ( v5 == 108 )
{
if ( !(unsigned __int8)func0((_BYTE *)a1 + 33) )
goto LABEL_19;
goto LABEL_12;
}
if ( v5 <= 108 )
break;
if ( v5 != 109 )
goto LABEL_14;
if ( !(unsigned __int8)func0((_BYTE *)a1 + 32) )
{
LABEL_19:
v6 = 0;
fprintf(stderr, "%s: '%s': invalid value.\n", *a1, optarg);
return v6;
}
LABEL_12:
v4 = *(char *const **)a2;
}
if ( v5 != 102 )
break;
v4 = *(char *const **)a2;
a1[1] = optarg;
}
if ( v5 == 104 )
{
*((_BYTE *)a1 + 34) = 1;
return 1;
}
LABEL_14:
v8 = *a1;
if ( optopt )
fprintf(stderr, "%s: '%c': unknown option.\n", v8, (unsigned int)optopt);
else
fprintf(stderr, "%s: %s: unknown option.\n", v8, *(const char **)(*(_QWORD *)a2 + 8LL * optind - 8));
return v2;
}

original_code:
_Bool
args_parse (struct config *config, const struct args *args)
{
 int c;
 static const struct option opts[] = {
  { "help", 0, ((void *)0), 'h' },
  { "dictfile", 1, ((void *)0), 'f' },
  { "minlength", 1, ((void *)0), 'm' },
  { "haslength", 1, ((void *)0), 'l' },
  { ((void *)0) }
 };
 if (config == ((void *)0) || args == ((void *)0)) {
  return 0;
 }
 config->name = args->av[0];
 while ((c = getopt_long(args->ac, args->av, ":hf:m:l:", opts, ((void *)0))) != -1) {
  switch (c) {
  case 'h':
   config->print_help = 1;
   return 1;
  case 'f':
   config->dictfile = optarg;
   break;
  case 'm':
   if (!get_uint8(&config->minlength)) {
    fprintf(stderr, "%s: '%s': invalid value.\n",
            config->name, optarg);
    return 0;
   }
   break;
  case 'l':
   if (!get_uint8(&config->haslength)) {
    fprintf(stderr, "%s: '%s': invalid value.\n",
            config->name, optarg);
    return 0;
   }
   break;
  default:
   if (optopt != 0) {
    fprintf(stderr, "%s: '%c': unknown option.\n",
            config->name, optopt);
   } else {
    fprintf(stderr, "%s: %s: unknown option.\n",
            config->name, args->av[optind - 1]);
   }
   return 0;
  }
 }
 config->words.ac = args->ac - optind;
 config->words.av = args->av + optind;
 return 1;
}

canonical_original_code:
_Bool args_parse(struct config *config, struct args *args)
{
 int c;
 static struct option opts[] = {
  { "help", 0, ((void *)0), 'h' },
  { "dictfile", 1, ((void *)0), 'f' },
  { "minlength", 1, ((void *)0), 'm' },
  { "haslength", 1, ((void *)0), 'l' },
  { ((void *)0) }
 };
 if (config == ((void *)0) || args == ((void *)0)) {
  return 0;
 }
 config->name = args->av[0];
 while ((c = getopt_long(args->ac, args->av, ":hf:m:l:", opts, ((void *)0))) != -1) {
  switch (c) {
  case 'h':
   config->print_help = 1;
   return 1;
  case 'f':
   config->dictfile = optarg;
   break;
  case 'm':
   if (!get_uint8(&config->minlength)) {
    fprintf(stderr, "%s: '%s': invalid value.\n",
            config->name, optarg);
    return 0;
   }
   break;
  case 'l':
   if (!get_uint8(&config->haslength)) {
    fprintf(stderr, "%s: '%s': invalid value.\n",
            config->name, optarg);
    return 0;
   }
   break;
  default:
   if (optopt != 0) {
    fprintf(stderr, "%s: '%c': unknown option.\n",
            config->name, optopt);
   } else {
    fprintf(stderr, "%s: %s: unknown option.\n",
            config->name, args->av[optind - 1]);
   }
   return 0;
  }
 }
 config->words.ac = args->ac - optind;
 config->words.av = args->av + optind;
 return 1;
}

variable_types:
args
struct args *

variable_types: c int

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


decompiled_code:
void words_destroy()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)word_head;
if ( word_head )
{
do
{
v1 = v0;
v0 = (void **)v0[3];
histogram_destroy(v1 + 2);
free(*v1);
free(v1);
}
while ( v0 );
}
}

canonical_decompiled_code:
void func1()
{
void **v0; // rbx
void **v1; // rbp

v0 = (void **)word_head;
if ( word_head )
{
do
{
v1 = v0;
v0 = (void **)v0[3];
histogram_destroy(v1 + 2);
free(*v1);
free(v1);
}
while ( v0 );
}
}

original_code:
static void
words_destroy (void)
{
 struct word *w;
 struct word *t;
 for (w = word_head; w; w = t) {
  t = w->next;
  histogram_destroy(&w->hist);
  free(w->str);
  free(w);
 }
}

canonical_original_code:
static void words_destroy()
{
 struct word *w;
 struct word *t;
 for (w = word_head; w; w = t) {
  t = w->next;
  histogram_destroy(&w->hist);
  free(w->str);
  free(w);
 }
}

variable_types: struct word { char *str; unsigned long len; struct histogram { char *bins; int *freq; unsigned long len; int maxfreq; unsigned long ntotal; } *hist; struct word *next; } *

user_defined_types: struct word { char *str; unsigned long len; struct histogram *hist; struct word *next; }


usage

decompiled_code:
int __fastcall usage(const char **a1)
{
char *v1; // rbx
const char *i; // rdx
int result; // eax
_QWORD v4[4]; // [rsp+0h] [rbp-38h] BYREF
char v5; // [rsp+20h] [rbp-18h] BYREF

v4[1] = " -f|--dictfile <dictfile> Use this dictionary file (one word per line)";
v4[2] = " -m|--minlength <length> All anagram words must be at least this long";
v4[3] = " -l|--haslength <length> One anagram word must be at least this long\n";
fwrite("\nFind anagrams of the input phrases (as argument, else standard input)\n", 1uLL, 0x47uLL, stderr);
v1 = (char *)v4;
fprintf(stderr, "Usage: %s [-h] [-f dictfile] [-m minlength] [-l haslength] words...\n\n", *a1);
for ( i = " -h|--help Show this help text"; ; i = *(const char **)v1 )
{
v1 += 8;
result = fprintf(stderr, "%s\n", i);
if ( v1 == &v5 )
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char **a1)
{
char *v1; // rbx
const char *i; // rdx
int result; // eax
_QWORD v4[4]; // [rsp+0h] [rbp-38h] BYREF
char v5; // [rsp+20h] [rbp-18h] BYREF

v4[1] = " -f|--dictfile <dictfile> Use this dictionary file (one word per line)";
v4[2] = " -m|--minlength <length> All anagram words must be at least this long";
v4[3] = " -l|--haslength <length> One anagram word must be at least this long\n";
fwrite("\nFind anagrams of the input phrases (as argument, else standard input)\n", 1uLL, 0x47uLL, stderr);
v1 = (char *)v4;
fprintf(stderr, "Usage: %s [-h] [-f dictfile] [-m minlength] [-l haslength] words...\n\n", *a1);
for ( i = " -h|--help Show this help text"; ; i = *(const char **)v1 )
{
v1 += 8;
result = fprintf(stderr, "%s\n", i);
if ( v1 == &v5 )
break;
}
return result;
}

original_code:
static void
usage (const struct config *config)
{
 char *usage[] = {
  "  -h|--help                  Show this help text",
  "  -f|--dictfile <dictfile>   Use this dictionary file (one word per line)",
  "  -m|--minlength <length>    All anagram words must be at least this long",
  "  -l|--haslength <length>    One anagram word must be at least this long\n"
 };
 unsigned int i;
 fprintf(stderr, "\nFind anagrams of the input phrases (as argument, else standard input)\n");
 fprintf(stderr, "Usage: %s [-h] [-f dictfile] [-m minlength] [-l haslength] words...\n\n", config->name);
 for (i = 0; i < sizeof(usage) / sizeof(usage[0]); i++) {
  fprintf(stderr, "%s\n", usage[i]);
 }
}

canonical_original_code:
static void usage(struct config *config)
{
 char *usage[] = {
  "  -h|--help                  Show this help text",
  "  -f|--dictfile <dictfile>   Use this dictionary file (one word per line)",
  "  -m|--minlength <length>    All anagram words must be at least this long",
  "  -l|--haslength <length>    One anagram word must be at least this long\n"
 };
 unsigned int i;
 fprintf(stderr, "\nFind anagrams of the input phrases (as argument, else standard input)\n");
 fprintf(stderr, "Usage: %s [-h] [-f dictfile] [-m minlength] [-l haslength] words...\n\n", config->name);
 for (i = 0; i < sizeof(usage) / sizeof(usage[0]); i++) {
  fprintf(stderr, "%s\n", usage[i]);
 }
}

variable_types:
usage
char *[]

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall word_add(void *src, size_t n, __int64 a3)
{
__int64 result; // rax
_QWORD *v5; // rbp
void *v6; // rax
_BYTE *v7; // rax
bool v8; // zf
__int64 v9; // rax
__int64 v10[4]; // [rsp+0h] [rbp-20h] BYREF

if ( !n )
return 0LL;
if ( *(_QWORD *)(a3 + 32) < n )
return 0LL;
v10[0] = histogram_create();
if ( !v10[0] )
return 0LL;
if ( *(_DWORD *)(v10[0] + 24) > *(_DWORD *)(a3 + 24)
|| !(unsigned __int8)histogram_fits(v10[0], a3)
|| (v5 = malloc(0x20uLL)) == 0LL )
{
LABEL_7:
histogram_destroy(v10);
return 0LL;
}
v6 = malloc(n + 1);
*v5 = v6;
if ( !v6 )
{
free(v5);
goto LABEL_7;
}
v5[1] = n;
v5[3] = 0LL;
v7 = memcpy(v6, src, n);
v8 = word_head == 0LL;
v7[n] = 0;
v5[2] = v10[0];
if ( v8 )
{
word_tail = (__int64)v5;
result = 1LL;
word_head = v5;
}
else
{
v9 = word_tail;
word_tail = (__int64)v5;
*(_QWORD *)(v9 + 24) = v5;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, size_t n, __int64 a3)
{
__int64 result; // rax
_QWORD *v5; // rbp
void *v6; // rax
_BYTE *v7; // rax
bool v8; // zf
__int64 v9; // rax
__int64 v10[4]; // [rsp+0h] [rbp-20h] BYREF

if ( !n )
return 0LL;
if ( *(_QWORD *)(a3 + 32) < n )
return 0LL;
v10[0] = histogram_create();
if ( !v10[0] )
return 0LL;
if ( *(_DWORD *)(v10[0] + 24) > *(_DWORD *)(a3 + 24)
|| !(unsigned __int8)histogram_fits(v10[0], a3)
|| (v5 = malloc(0x20uLL)) == 0LL )
{
LABEL_7:
histogram_destroy(v10);
return 0LL;
}
v6 = malloc(n + 1);
*v5 = v6;
if ( !v6 )
{
free(v5);
goto LABEL_7;
}
v5[1] = n;
v5[3] = 0LL;
v7 = memcpy(v6, src, n);
v8 = word_head == 0LL;
v7[n] = 0;
v5[2] = v10[0];
if ( v8 )
{
word_tail = (__int64)v5;
result = 1LL;
word_head = v5;
}
else
{
v9 = word_tail;
word_tail = (__int64)v5;
*(_QWORD *)(v9 + 24) = v5;
result = 1LL;
}
return result;
}

original_code:
static int
word_add (const char *const word, const size_t len, const struct histogram *const inhist)
{
 struct word *w;
 struct histogram *h;
 if (len == 0) {
  goto err_0;
 }
 if (len > inhist->ntotal) {
  goto err_0;
 }
 if ((h = histogram_create(word, len)) == ((void *)0)) {
  goto err_0;
 }
 if (h->maxfreq > inhist->maxfreq) {
  goto err_1;
 }
 if (!histogram_fits(h, inhist)) {
  goto err_1;
 }
 if ((w = malloc(sizeof(*w))) == ((void *)0)) {
  goto err_1;
 }
 if ((w->str = malloc(len + 1)) == ((void *)0)) {
  goto err_2;
 }
 w->len = len;
 w->next = ((void *)0);
 memcpy(w->str, word, len);
 w->str[len] = '\0';
 w->hist = h;
 if (word_head == ((void *)0)) {
  word_head = word_tail = w;
 }
 else {
  word_tail->next = w;
  word_tail = w;
 }
 return 1;
err_2: free(w);
err_1: histogram_destroy(&h);
err_0: return 0;
}

canonical_original_code:
static int word_add(char *word, unsigned long len, struct histogram *inhist)
{
 struct word *w;
 struct histogram *h;
 if (len == 0) {
  goto err_0;
 }
 if (len > inhist->ntotal) {
  goto err_0;
 }
 if ((h = histogram_create(word, len)) == ((void *)0)) {
  goto err_0;
 }
 if (h->maxfreq > inhist->maxfreq) {
  goto err_1;
 }
 if (!histogram_fits(h, inhist)) {
  goto err_1;
 }
 if ((w = malloc(sizeof(*w))) == ((void *)0)) {
  goto err_1;
 }
 if ((w->str = malloc(len + 1)) == ((void *)0)) {
  goto err_2;
 }
 w->len = len;
 w->next = ((void *)0);
 memcpy(w->str, word, len);
 w->str[len] = '\0';
 w->hist = h;
 if (word_head == ((void *)0)) {
  word_head = word_tail = w;
 }
 else {
  word_tail->next = w;
  word_tail = w;
 }
 return 1;
err_2: free(w);
err_1: histogram_destroy(&h);
err_0: return 0;
}

variable_types:
word
char *

variable_types:
len
unsigned long

variable_types: struct histogram { char *bins; int *freq; unsigned long len; int maxfreq; unsigned long ntotal; } *


decompiled_code:
void __fastcall words_find(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 *v6; // rbx
unsigned __int64 v7; // r8
__int64 v8; // rax
__int64 v9; // rcx
__int64 v10; // [rsp+8h] [rbp-50h] BYREF
__int64 v11[9]; // [rsp+10h] [rbp-48h] BYREF

if ( !a4 && *(_QWORD *)(a2 + 32) < (unsigned __int64)*(unsigned __int8 *)(a1 + 33) )
return;
v6 = (__int64 *)word_head;
if ( !word_head )
return;
while ( (unsigned __int64)v6[1] > *(_QWORD *)(a2 + 32) || !(unsigned __int8)histogram_fits(v6[2], a2) )
{
LABEL_12:
v6 = (__int64 *)v6[3];
if ( !v6 )
return;
}
v10 = histogram_copy(a2);
if ( !v10 )
return;
if ( !(unsigned __int8)histogram_subtract(v10, v6[2]) )
goto LABEL_19;
v7 = v6[1];
if ( *(_QWORD *)(v10 + 32) )
{
v8 = *v6;
v9 = a4;
v11[1] = v6[1];
v11[2] = a3;
v11[0] = v8;
if ( !a4 )
v9 = *(unsigned __int8 *)(a1 + 33) <= v7;
words_find(a1, v10, v11, v9, v7);
histogram_destroy(&v10);
goto LABEL_12;
}
if ( a4 || *(unsigned __int8 *)(a1 + 33) <= v7 )
{
fwrite((const void *)*v6, v6[1], 1uLL, stdout);
for ( ; a3; a3 = *(_QWORD *)(a3 + 16) )
{
fputc(32, stdout);
fwrite(*(const void **)a3, *(_QWORD *)(a3 + 8), 1uLL, stdout);
}
fputc(10, stdout);
}
LABEL_19:
histogram_destroy(&v10);
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 *v6; // rbx
unsigned __int64 v7; // r8
__int64 v8; // rax
__int64 v9; // rcx
__int64 v10; // [rsp+8h] [rbp-50h] BYREF
__int64 v11[9]; // [rsp+10h] [rbp-48h] BYREF

if ( !a4 && *(_QWORD *)(a2 + 32) < (unsigned __int64)*(unsigned __int8 *)(a1 + 33) )
return;
v6 = (__int64 *)word_head;
if ( !word_head )
return;
while ( (unsigned __int64)v6[1] > *(_QWORD *)(a2 + 32) || !(unsigned __int8)histogram_fits(v6[2], a2) )
{
LABEL_12:
v6 = (__int64 *)v6[3];
if ( !v6 )
return;
}
v10 = histogram_copy(a2);
if ( !v10 )
return;
if ( !(unsigned __int8)histogram_subtract(v10, v6[2]) )
goto LABEL_19;
v7 = v6[1];
if ( *(_QWORD *)(v10 + 32) )
{
v8 = *v6;
v9 = a4;
v11[1] = v6[1];
v11[2] = a3;
v11[0] = v8;
if ( !a4 )
v9 = *(unsigned __int8 *)(a1 + 33) <= v7;
func5(a1, v10, v11, v9, v7);
histogram_destroy(&v10);
goto LABEL_12;
}
if ( a4 || *(unsigned __int8 *)(a1 + 33) <= v7 )
{
fwrite((const void *)*v6, v6[1], 1uLL, stdout);
for ( ; a3; a3 = *(_QWORD *)(a3 + 16) )
{
fputc(32, stdout);
fwrite(*(const void **)a3, *(_QWORD *)(a3 + 8), 1uLL, stdout);
}
fputc(10, stdout);
}
LABEL_19:
histogram_destroy(&v10);
}

original_code:
static void
words_find (const struct config *config, struct histogram *h, struct prev_word *prev, int len_satisfied)
{
 struct word *w;
 struct histogram *copy;
 struct prev_word pw;
 struct prev_word *p;
 if (!len_satisfied && h->ntotal < config->haslength) {
  return;
 }
 for (w = word_head; w; w = w->next)
 {
  if (w->len > h->ntotal) {
   continue;
  }
  if (histogram_fits(w->hist, h) == 0) {
   continue;
  }
  if ((copy = histogram_copy(h)) == ((void *)0)) {
   return;
  }
  if (!histogram_subtract(copy, w->hist)) {
   histogram_destroy(&copy);
   return;
  }
  if (copy->ntotal == 0)
  {
   if (len_satisfied || w->len >= config->haslength) {
    fwrite(w->str, w->len, 1, stdout);
    for (p = prev; p; p = p->prev) {
     fputc(' ', stdout);
     fwrite(p->str, p->len, 1, stdout);
    }
    fputc('\n', stdout);
   }
   histogram_destroy(&copy);
   return;
  }
  pw.str = w->str;
  pw.len = w->len;
  pw.prev = prev;
  words_find(config, copy, &pw, (len_satisfied || w->len >= config->haslength));
  histogram_destroy(&copy);
 }
}

canonical_original_code:
static void words_find(struct config *config, struct histogram *h, struct prev_word *prev, int len_satisfied)
{
 struct word *w;
 struct histogram *copy;
 struct prev_word pw;
 struct prev_word *p;
 if (!len_satisfied && h->ntotal < config->haslength) {
  return;
 }
 for (w = word_head; w; w = w->next)
 {
  if (w->len > h->ntotal) {
   continue;
  }
  if (histogram_fits(w->hist, h) == 0) {
   continue;
  }
  if ((copy = histogram_copy(h)) == ((void *)0)) {
   return;
  }
  if (!histogram_subtract(copy, w->hist)) {
   histogram_destroy(&copy);
   return;
  }
  if (copy->ntotal == 0)
  {
   if (len_satisfied || w->len >= config->haslength) {
    fwrite(w->str, w->len, 1, stdout);
    for (p = prev; p; p = p->prev) {
     fputc(' ', stdout);
     fwrite(p->str, p->len, 1, stdout);
    }
    fputc('\n', stdout);
   }
   histogram_destroy(&copy);
   return;
  }
  pw.str = w->str;
  pw.len = w->len;
  pw.prev = prev;
  words_find(config, copy, &pw, (len_satisfied || w->len >= config->haslength));
  histogram_destroy(&copy);
 }
}

variable_types: struct config { char *name; char *dictfile; struct args { char **av; int ac; } words; unsigned char minlength; unsigned char haslength; _Bool print_help; } *

variable_types: struct prev_word { char *str; unsigned long len; struct prev_word *prev; } *

user_defined_types: struct histogram { char *bins; int *freq; unsigned long len; int maxfreq; unsigned long ntotal; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
int v4; // er12
__int64 v6; // [rsp+8h] [rbp-60h] BYREF
size_t v7; // [rsp+10h] [rbp-58h] BYREF
__int64 v8; // [rsp+18h] [rbp-50h] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF
__int64 v10; // [rsp+28h] [rbp-40h]
__int128 v11[2]; // [rsp+30h] [rbp-38h] BYREF
__int64 v12; // [rsp+50h] [rbp-18h]

v3 = *((_QWORD *)&config_default + 4);
ptr = argv;
LODWORD(v10) = argc;
v12 = v3;
v7 = 0LL;
v8 = 0LL;
v11[0] = (__int128)_mm_loadu_si128((const __m128i *)&config_default);
v11[1] = (__int128)_mm_loadu_si128((const __m128i *)&config_default + 1);
if ( (unsigned __int8)args_parse(v11, &ptr, envp) )
{
if ( BYTE2(v12) )
{
v4 = 0;
usage((const char **)v11);
}
else
{
v4 = 1;
if ( (unsigned __int8)input_get(v11, &ptr) )
{
v6 = histogram_create(ptr, v10);
if ( v6 )
{
if ( (unsigned int)parse_dictfile((__int64)v11, v6, &v7, &v8) )
{
if ( BYTE1(v12) <= v7 && v8 )
words_find((__int64)v11, v6, 0LL, 0);
words_destroy();
v4 = 0;
histogram_destroy(&v6);
free(ptr);
}
else
{
fwrite("Could not parse file\n", 1uLL, 0x15uLL, stderr);
histogram_destroy(&v6);
free(ptr);
}
}
else
{
fwrite("Could not create histogram of input\n", 1uLL, 0x24uLL, stderr);
free(ptr);
}
}
}
}
else
{
v4 = 1;
usage((const char **)v11);
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
int v4; // er12
__int64 v6; // [rsp+8h] [rbp-60h] BYREF
size_t v7; // [rsp+10h] [rbp-58h] BYREF
__int64 v8; // [rsp+18h] [rbp-50h] BYREF
void *ptr; // [rsp+20h] [rbp-48h] BYREF
__int64 v10; // [rsp+28h] [rbp-40h]
__int128 v11[2]; // [rsp+30h] [rbp-38h] BYREF
__int64 v12; // [rsp+50h] [rbp-18h]

v3 = *((_QWORD *)&config_default + 4);
ptr = argv;
LODWORD(v10) = argc;
v12 = v3;
v7 = 0LL;
v8 = 0LL;
v11[0] = (__int128)_mm_loadu_si128((const __m128i *)&config_default);
v11[1] = (__int128)_mm_loadu_si128((const __m128i *)&config_default + 1);
if ( (unsigned __int8)args_parse(v11, &ptr, envp) )
{
if ( BYTE2(v12) )
{
v4 = 0;
func2((const char **)v11);
}
else
{
v4 = 1;
if ( (unsigned __int8)input_get(v11, &ptr) )
{
v6 = histogram_create(ptr, v10);
if ( v6 )
{
if ( (unsigned int)func4((__int64)v11, v6, &v7, &v8) )
{
if ( BYTE1(v12) <= v7 && v8 )
func5((__int64)v11, v6, 0LL, 0);
func1();
v4 = 0;
histogram_destroy(&v6);
free(ptr);
}
else
{
fwrite("Could not parse file\n", 1uLL, 0x15uLL, stderr);
histogram_destroy(&v6);
free(ptr);
}
}
else
{
fwrite("Could not create histogram of input\n", 1uLL, 0x24uLL, stderr);
free(ptr);
}
}
}
}
else
{
v4 = 1;
func2((const char **)v11);
}
return v4;
}

original_code:
int
main (int argc, char *argv[])
{
 struct config config = config_default;
 struct input input;
 struct histogram *inhist;
 size_t max_found_len = 0;
 size_t nwords = 0;
 if (!args_parse(&config, &(struct args) { .ac = argc, .av = argv })) {
  usage(&config);
  return 1;
 }
 if (config.print_help) {
  usage(&config);
  return 0;
 }
 if (!input_get(&config, &input)) {
  return 1;
 }
 if ((inhist = histogram_create(input.str, input.len)) == ((void *)0)) {
  fprintf(stderr, "Could not create histogram of input\n");
  free(input.str);
  return 1;
 }
 if (parse_dictfile(&config, inhist, &max_found_len, &nwords) == 0) {
  fprintf(stderr, "Could not parse file\n");
  histogram_destroy(&inhist);
  free(input.str);
  return 1;
 }
 if (max_found_len >= config.haslength && nwords > 0) {
  words_find(&config, inhist, ((void *)0), 0);
 }
 words_destroy();
 histogram_destroy(&inhist);
 free(input.str);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct config config = config_default;
 struct input input;
 struct histogram *inhist;
 unsigned long max_found_len = 0;
 unsigned long nwords = 0;
 if (!args_parse(&config, &(struct args) { .ac = argc, .av = argv })) {
  usage(&config);
  return 1;
 }
 if (config.print_help) {
  usage(&config);
  return 0;
 }
 if (!input_get(&config, &input)) {
  return 1;
 }
 if ((inhist = histogram_create(input.str, input.len)) == ((void *)0)) {
  fprintf(stderr, "Could not create histogram of input\n");
  free(input.str);
  return 1;
 }
 if (parse_dictfile(&config, inhist, &max_found_len, &nwords) == 0) {
  fprintf(stderr, "Could not parse file\n");
  histogram_destroy(&inhist);
  free(input.str);
  return 1;
 }
 if (max_found_len >= config.haslength && nwords > 0) {
  words_find(&config, inhist, ((void *)0), 0);
 }
 words_destroy();
 histogram_destroy(&inhist);
 free(input.str);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct config { char *name; char *dictfile; struct args { char **av; int ac; } words; unsigned char minlength; unsigned char haslength; _Bool print_help; }

variable_types: struct input { char *str; unsigned long len; }

variable_types:
nwords
unsigned long


decompiled_code:
__int64 __fastcall char_compare(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0LL;
if ( *(_BYTE *)a1 != *(_BYTE *)a2 )
result = 2 * (unsigned int)(*(_BYTE *)a1 >= *(_BYTE *)a2) - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0LL;
if ( *(_BYTE *)a1 != *(_BYTE *)a2 )
result = 2 * (unsigned int)(*(_BYTE *)a1 >= *(_BYTE *)a2) - 1;
return result;
}

original_code:
static int
char_compare (const void *const p1, const void *const p2)
{
 if (*(char *const)p1 == *(char *const)p2) {
  return 0;
 }
 return (*(char *const)p1 < *(char *const)p2) ? -1 : 1;
}

canonical_original_code:
static int char_compare(void *p1, void *p2)
{
 if (*(char *)p1 == *(char *)p2) {
  return 0;
 }
 return (*(char *)p1 < *(char *)p2) ? -1 : 1;
}


decompiled_code:
void __fastcall histogram_destroy(void ***a1)
{
if ( a1 )
{
if ( *a1 )
{
free(**a1);
free((*a1)[1]);
free(*a1);
*a1 = 0LL;
}
}
}

original_code:
void
histogram_destroy (struct histogram **h)
{
 if (h == ((void *)0) || *h == ((void *)0)) {
  return;
 }
 free((*h)->bins);
 free((*h)->freq);
 free(*h);
 *h = ((void *)0);
}

canonical_original_code:
void histogram_destroy(struct histogram **h)
{
 if (h == ((void *)0) || *h == ((void *)0)) {
  return;
 }
 free((*h)->bins);
 free((*h)->freq);
 free(*h);
 *h = ((void *)0);
}

variable_types: struct histogram { char *bins; int *freq; unsigned long len; int maxfreq; unsigned long ntotal; } **


original_code:
_Bool
histogram_fits (const struct histogram *h, const struct histogram *base)
{
 if (h->len > base->len) {
  return 0;
 }
 if (h->maxfreq > base->maxfreq) {
  return 0;
 }
 for (const char *b, *t = h->bins; t < h->bins + h->len; t++) {
  if ((b = find_character(base, *t)) == ((void *)0)) {
   return 0;
  }
  if (h->freq[t - h->bins] > base->freq[b - base->bins]) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
_Bool histogram_fits(struct histogram *h, struct histogram *base)
{
 if (h->len > base->len) {
  return 0;
 }
 if (h->maxfreq > base->maxfreq) {
  return 0;
 }
 for (char *b; char *t = h->bins; t < h->bins + h->len; t++) {
  if ((b = find_character(base, *t)) == ((void *)0)) {
   return 0;
  }
  if (h->freq[t - h->bins] > base->freq[b - base->bins]) {
   return 0;
  }
 }
 return 1;
}

variable_types:
base
struct histogram *

variable_types:
b
char *

variable_types:
t
char *


original_code:
_Bool
histogram_subtract (struct histogram *target, struct histogram *from)
{
 char *t;
 char *f;
 int *freq_t;
 int *freq_f;
 target->maxfreq = 0;
 for (f = from->bins, t = target->bins; f < from->bins + from->len; f++) {
  freq_t = target->freq + (t - target->bins);
  while (*t < *f) {
   if (*freq_t > target->maxfreq) {
    target->maxfreq = *freq_t;
   }
   if (++t == target->bins + target->len) {
    return 0;
   }
   freq_t = target->freq + (t - target->bins);
  }
  if (*t != *f) {
   return 0;
  }
  freq_f = from->freq + (f - from->bins);
  if (*freq_f > *freq_t) {
   return 0;
  }
  *freq_t -= *freq_f;
  target->ntotal -= *freq_f;
  if (*freq_t > target->maxfreq) {
   target->maxfreq = *freq_t;
  }
 }
 return 1;
}

canonical_original_code:
_Bool histogram_subtract(struct histogram *target, struct histogram *from)
{
 char *t;
 char *f;
 int *freq_t;
 int *freq_f;
 target->maxfreq = 0;
 for (f = from->bins, t = target->bins; f < from->bins + from->len; f++) {
  freq_t = target->freq + (t - target->bins);
  while (*t < *f) {
   if (*freq_t > target->maxfreq) {
    target->maxfreq = *freq_t;
   }
   if (++t == target->bins + target->len) {
    return 0;
   }
   freq_t = target->freq + (t - target->bins);
  }
  if (*t != *f) {
   return 0;
  }
  freq_f = from->freq + (f - from->bins);
  if (*freq_f > *freq_t) {
   return 0;
  }
  *freq_t -= *freq_f;
  target->ntotal -= *freq_f;
  if (*freq_t > target->maxfreq) {
   target->maxfreq = *freq_t;
  }
 }
 return 1;
}

variable_types:
from
struct histogram *

variable_types:
f
char *


decompiled_code:
__int64 __fastcall char_compare(const void *a1, const void *a2)
{
return 2 * (unsigned int)(*(_BYTE *)a1 >= *(_BYTE *)a2) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return 2 * (unsigned int)(*(_BYTE *)a1 >= *(_BYTE *)a2) - 1;
}

original_code:
static int
char_compare (const void *const p1, const void *const p2)
{
 return (*(char *const)p1 < *(char *const)p2) ? -1 : 1;
}

canonical_original_code:
static int char_compare(void *p1, void *p2)
{
 return (*(char *)p1 < *(char *)p2) ? -1 : 1;
}


decompiled_code:
__int64 __fastcall codec_choose_forced(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 )
{
if ( (a2 & 1) != 0 )
{
*a1 = &base64_stream_encode_avx2;
result = 1LL;
a1[1] = &base64_stream_decode_avx2;
}
else if ( (a2 & 2) != 0 )
{
*a1 = &base64_stream_encode_neon32;
result = 1LL;
a1[1] = &base64_stream_decode_neon32;
}
else if ( (a2 & 4) != 0 )
{
*a1 = &base64_stream_encode_neon64;
result = 1LL;
a1[1] = &base64_stream_decode_neon64;
}
else if ( (a2 & 8) != 0 )
{
*a1 = &base64_stream_encode_plain;
result = 1LL;
a1[1] = &base64_stream_decode_plain;
}
else if ( (a2 & 0x10) != 0 )
{
*a1 = &base64_stream_encode_ssse3;
result = 1LL;
a1[1] = &base64_stream_decode_ssse3;
}
else if ( (a2 & 0x20) != 0 )
{
*a1 = &base64_stream_encode_sse41;
result = 1LL;
a1[1] = &base64_stream_decode_sse41;
}
else if ( (a2 & 0x40) != 0 )
{
*a1 = &base64_stream_encode_sse42;
result = 1LL;
a1[1] = &base64_stream_decode_sse42;
}
else if ( (a2 & 0x80u) != 0 )
{
*a1 = &base64_stream_encode_avx;
result = 1LL;
a1[1] = &base64_stream_decode_avx;
}
else if ( (a2 & 0x100) != 0 )
{
*a1 = &base64_stream_encode_avx512;
result = 1LL;
a1[1] = &base64_stream_decode_avx512;
}
}
return result;
}

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

result = 0LL;
if ( a2 )
{
if ( (a2 & 1) != 0 )
{
*a1 = &base64_stream_encode_avx2;
result = 1LL;
a1[1] = &base64_stream_decode_avx2;
}
else if ( (a2 & 2) != 0 )
{
*a1 = &base64_stream_encode_neon32;
result = 1LL;
a1[1] = &base64_stream_decode_neon32;
}
else if ( (a2 & 4) != 0 )
{
*a1 = &base64_stream_encode_neon64;
result = 1LL;
a1[1] = &base64_stream_decode_neon64;
}
else if ( (a2 & 8) != 0 )
{
*a1 = &base64_stream_encode_plain;
result = 1LL;
a1[1] = &base64_stream_decode_plain;
}
else if ( (a2 & 0x10) != 0 )
{
*a1 = &base64_stream_encode_ssse3;
result = 1LL;
a1[1] = &base64_stream_decode_ssse3;
}
else if ( (a2 & 0x20) != 0 )
{
*a1 = &base64_stream_encode_sse41;
result = 1LL;
a1[1] = &base64_stream_decode_sse41;
}
else if ( (a2 & 0x40) != 0 )
{
*a1 = &base64_stream_encode_sse42;
result = 1LL;
a1[1] = &base64_stream_decode_sse42;
}
else if ( (a2 & 0x80u) != 0 )
{
*a1 = &base64_stream_encode_avx;
result = 1LL;
a1[1] = &base64_stream_decode_avx;
}
else if ( (a2 & 0x100) != 0 )
{
*a1 = &base64_stream_encode_avx512;
result = 1LL;
a1[1] = &base64_stream_decode_avx512;
}
}
return result;
}

original_code:
static _Bool
codec_choose_forced (struct codec *codec, int flags)
{
 if (!(flags & 0xFFFF)) {
  return 0;
 }
 if (flags & (1 << 0)) {
  codec->enc = base64_stream_encode_avx2;
  codec->dec = base64_stream_decode_avx2;
  return 1;
 }
 if (flags & (1 << 1)) {
  codec->enc = base64_stream_encode_neon32;
  codec->dec = base64_stream_decode_neon32;
  return 1;
 }
 if (flags & (1 << 2)) {
  codec->enc = base64_stream_encode_neon64;
  codec->dec = base64_stream_decode_neon64;
  return 1;
 }
 if (flags & (1 << 3)) {
  codec->enc = base64_stream_encode_plain;
  codec->dec = base64_stream_decode_plain;
  return 1;
 }
 if (flags & (1 << 4)) {
  codec->enc = base64_stream_encode_ssse3;
  codec->dec = base64_stream_decode_ssse3;
  return 1;
 }
 if (flags & (1 << 5)) {
  codec->enc = base64_stream_encode_sse41;
  codec->dec = base64_stream_decode_sse41;
  return 1;
 }
 if (flags & (1 << 6)) {
  codec->enc = base64_stream_encode_sse42;
  codec->dec = base64_stream_decode_sse42;
  return 1;
 }
 if (flags & (1 << 7)) {
  codec->enc = base64_stream_encode_avx;
  codec->dec = base64_stream_decode_avx;
  return 1;
 }
 if (flags & (1 << 8)) {
  codec->enc = base64_stream_encode_avx512;
  codec->dec = base64_stream_decode_avx512;
  return 1;
 }
 return 0;
}

canonical_original_code:
static _Bool codec_choose_forced(struct codec *codec, int flags)
{
 if (!(flags & 0xFFFF)) {
  return 0;
 }
 if (flags & (1 << 0)) {
  codec->enc = base64_stream_encode_avx2;
  codec->dec = base64_stream_decode_avx2;
  return 1;
 }
 if (flags & (1 << 1)) {
  codec->enc = base64_stream_encode_neon32;
  codec->dec = base64_stream_decode_neon32;
  return 1;
 }
 if (flags & (1 << 2)) {
  codec->enc = base64_stream_encode_neon64;
  codec->dec = base64_stream_decode_neon64;
  return 1;
 }
 if (flags & (1 << 3)) {
  codec->enc = base64_stream_encode_plain;
  codec->dec = base64_stream_decode_plain;
  return 1;
 }
 if (flags & (1 << 4)) {
  codec->enc = base64_stream_encode_ssse3;
  codec->dec = base64_stream_decode_ssse3;
  return 1;
 }
 if (flags & (1 << 5)) {
  codec->enc = base64_stream_encode_sse41;
  codec->dec = base64_stream_decode_sse41;
  return 1;
 }
 if (flags & (1 << 6)) {
  codec->enc = base64_stream_encode_sse42;
  codec->dec = base64_stream_decode_sse42;
  return 1;
 }
 if (flags & (1 << 7)) {
  codec->enc = base64_stream_encode_avx;
  codec->dec = base64_stream_decode_avx;
  return 1;
 }
 if (flags & (1 << 8)) {
  codec->enc = base64_stream_encode_avx512;
  codec->dec = base64_stream_decode_avx512;
  return 1;
 }
 return 0;
}

variable_types: struct codec { void (*enc)(struct base64_state { int eof; int bytes; int flags; unsigned char carry; } *state, char *src, unsigned long srclen, char *out, unsigned long *outlen); int (*dec)(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen); } *

variable_types: flags int

user_defined_types: struct codec { void (*enc)(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen); int (*dec)(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen); }


decompiled_code:
__int64 __fastcall codec_choose(_QWORD *a1, __int16 a2)
{
__int64 result; // rax

result = codec_choose_forced(a1, a2);
if ( !(_BYTE)result )
{
result = codec_choose_arm_constprop_0();
if ( !(_BYTE)result )
{
*a1 = &base64_stream_encode_plain;
a1[1] = &base64_stream_decode_plain;
}
}
return result;
}

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

result = func0(a1, a2);
if ( !(_BYTE)result )
{
result = func1();
if ( !(_BYTE)result )
{
*a1 = &base64_stream_encode_plain;
a1[1] = &base64_stream_decode_plain;
}
}
return result;
}

original_code:
void
codec_choose (struct codec *codec, int flags)
{
 if (codec_choose_forced(codec, flags)) {
  return;
 }
 if (codec_choose_arm(codec)) {
  return;
 }
 if (codec_choose_x86(codec)) {
  return;
 }
 codec->enc = base64_stream_encode_plain;
 codec->dec = base64_stream_decode_plain;
}

canonical_original_code:
void codec_choose(struct codec *codec, int flags)
{
 if (codec_choose_forced(codec, flags)) {
  return;
 }
 if (codec_choose_arm(codec)) {
  return;
 }
 if (codec_choose_x86(codec)) {
  return;
 }
 codec->enc = base64_stream_encode_plain;
 codec->dec = base64_stream_decode_plain;
}

user_defined_types: struct base64_state { int eof; int bytes; int flags; unsigned char carry; }


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

if ( !codec || (_BYTE)a2 )
result = codec_choose(&codec, a2);
*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = 0LL;
*(_BYTE *)(a1 + 12) = 0;
return result;
}

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

if ( !codec || (_BYTE)a2 )
result = codec_choose(&codec, a2);
*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = 0LL;
*(_BYTE *)(a1 + 12) = 0;
return result;
}

original_code:
void
base64_stream_encode_init (struct base64_state *state, int flags)
{
 if (codec.enc == ((void *)0) || flags & 0xFF) {
  codec_choose(&codec, flags);
 }
 state->eof = 0;
 state->bytes = 0;
 state->carry = 0;
 state->flags = flags;
}

canonical_original_code:
void base64_stream_encode_init(struct base64_state *state, int flags)
{
 if (codec.enc == ((void *)0) || flags & 0xFF) {
  codec_choose(&codec, flags);
 }
 state->eof = 0;
 state->bytes = 0;
 state->carry = 0;
 state->flags = flags;
}

variable_types: struct base64_state { int eof; int bytes; int flags; unsigned char carry; } *


decompiled_code:
// attributes: thunk
__int64 base64_stream_encode()
{
return codec();
}

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

original_code:
void
base64_stream_encode
 ( struct base64_state *state
 , const char *src
 , size_t srclen
 , char *out
 , size_t *outlen
 )
{
 codec.enc(state, src, srclen, out, outlen);
}

canonical_original_code:
void base64_stream_encode(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 codec.enc(state, src, srclen, out, outlen);
}

variable_types:
src
char *

variable_types:
srclen
unsigned long

variable_types:
out
char *

variable_types:
outlen
unsigned long *


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

if ( !qword_1D8 || (_WORD)a2 )
result = codec_choose(&codec, a2);
*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = 0LL;
*(_BYTE *)(a1 + 12) = 0;
return result;
}

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

if ( !qword_1D8 || (_WORD)a2 )
result = codec_choose(&codec, a2);
*(_DWORD *)(a1 + 8) = a2;
*(_QWORD *)a1 = 0LL;
*(_BYTE *)(a1 + 12) = 0;
return result;
}

original_code:
void
base64_stream_decode_init (struct base64_state *state, int flags)
{
 if (codec.dec == ((void *)0) || flags & 0xFFFF) {
  codec_choose(&codec, flags);
 }
 state->eof = 0;
 state->bytes = 0;
 state->carry = 0;
 state->flags = flags;
}

canonical_original_code:
void base64_stream_decode_init(struct base64_state *state, int flags)
{
 if (codec.dec == ((void *)0) || flags & 0xFFFF) {
  codec_choose(&codec, flags);
 }
 state->eof = 0;
 state->bytes = 0;
 state->carry = 0;
 state->flags = flags;
}


decompiled_code:
// attributes: thunk
__int64 base64_stream_decode()
{
return qword_1D8();
}

canonical_decompiled_code:
__int64 func4()
{
return qword_1D8();
}

original_code:
int
base64_stream_decode
 ( struct base64_state *state
 , const char *src
 , size_t srclen
 , char *out
 , size_t *outlen
 )
{
 return codec.dec(state, src, srclen, out, outlen);
}

canonical_original_code:
int base64_stream_decode(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 return codec.dec(state, src, srclen, out, outlen);
}


decompiled_code:
__int64 __fastcall base64_decode(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax
_DWORD v6[14]; // [rsp+0h] [rbp-38h] BYREF

base64_stream_decode_init((__int64)v6, a5);
result = base64_stream_decode();
if ( (_DWORD)result )
{
if ( v6[1] )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax
_DWORD v6[14]; // [rsp+0h] [rbp-38h] BYREF

func3((__int64)v6, a5);
result = func4();
if ( (_DWORD)result )
{
if ( v6[1] )
result = 0LL;
}
return result;
}

original_code:
int
base64_decode
 ( const char *src
 , size_t srclen
 , char *out
 , size_t *outlen
 , int flags
 )
{
 int ret;
 struct base64_state state;
 base64_stream_decode_init(&state, flags);
 ret = base64_stream_decode(&state, src, srclen, out, outlen);
 if (ret && (state.bytes == 0)) {
  return ret;
 }
 return 0;
}

canonical_original_code:
int base64_decode(char *src, unsigned long srclen, char *out, unsigned long *outlen, int flags)
{
 int ret;
 struct base64_state state;
 base64_stream_decode_init(&state, flags);
 ret = base64_stream_decode(&state, src, srclen, out, outlen);
 if (ret && (state.bytes == 0)) {
  return ret;
 }
 return 0;
}

variable_types: ret int

variable_types: struct base64_state { int eof; int bytes; int flags; unsigned char carry; }


decompiled_code:
__int64 base64_stream_decode_avx()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_avx ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_avx(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_ssse3()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_ssse3 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_ssse3(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
_BOOL8 __fastcall codec_supported(unsigned int a1)
{
char v2[14]; // [rsp+8h] [rbp-20h] BYREF
char v3[18]; // [rsp+16h] [rbp-12h] BYREF

return (unsigned int)base64_decode("aGVsbG8=", 8LL, v3, v2, a1) != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int a1)
{
char v2[14]; // [rsp+8h] [rbp-20h] BYREF
char v3[18]; // [rsp+16h] [rbp-12h] BYREF

return (unsigned int)base64_decode("aGVsbG8=", 8LL, v3, v2, a1) != -1;
}

original_code:
int
codec_supported (int flags)
{
 char *a = "aGVsbG8=";
 char b[10];
 size_t outlen;
 return (base64_decode(a, strlen(a), b, &outlen, flags) != -1);
}

canonical_original_code:
int codec_supported(int flags)
{
 char *a = "aGVsbG8=";
 char b[10];
 unsigned long outlen;
 return (base64_decode(a, strlen(a), b, &outlen, flags) != -1);
}

variable_types:
a
char *

variable_types:
b
char [10]

variable_types:
outlen
unsigned long


decompiled_code:
__int64 base64_stream_decode_neon32()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_neon32 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_neon32(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_avx2()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_avx2 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_avx2(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_avx512()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_avx512 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_avx512(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_sse41()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_sse41 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_sse41(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_sse42()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_sse42 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_sse42(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
__int64 base64_stream_decode_neon64()
{
return 0xFFFFFFFFLL;
}

original_code:
int base64_stream_decode_neon64 ( struct base64_state *state , const char *src , size_t srclen , char *out , size_t *outlen )
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}

canonical_original_code:
int base64_stream_decode_neon64(struct base64_state *state, char *src, unsigned long srclen, char *out, unsigned long *outlen)
{
 ((void)(state)); ((void)(src)); ((void)(srclen)); ((void)(out)); ((void)(outlen)); return -1;
}


decompiled_code:
// local variable allocation has failed, the output may be wrong!
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
size_t v4; // rax
__int64 i; // rax
__int64 v6; // rdx
int v7; // ecx
__int64 j; // rax
__int16 v9; // dx
unsigned int v10; // esi
__int64 v11; // rcx
__int64 k; // rax
int v13; // edx
__int16 v14; // cx
__int64 v15; // rsi
__int64 l; // rax
__int64 v17; // rdx
int v18; // ecx
__int64 m; // rax
__int64 v20; // rdx
int v21; // ecx
__int64 n; // rax
__int64 v23; // rdx
int v24; // ecx
__int64 ii; // rax
__int64 v26; // rdx
int v27; // ecx
__int64 jj; // rax
__int64 v29; // rdx
int v30; // ecx
int v32[258]; // [rsp+0h] [rbp-408h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
v4 = strlen(v3);
*(_QWORD *)&argc = _bss_start;
if ( v4 != 3 )
{
fwrite("input must be a string of 3 characters '-', '.' or '_'\n", 1uLL, 0x37uLL, _bss_start);
exit(1);
}
argv = (const char **)"fusing '%s' as replacements in base64 encoding\n";
fprintf(_bss_start, "fusing '%s' as replacements in base64 encoding\n", v3);
byte_4040DE = *v3;
byte_4040DF = v3[1];
padchar = v3[2];
}
printStart(*(_QWORD *)&argc, argv, envp);
puts("\n\n#if BASE64_LITTLE_ENDIAN");
puts("\n\n/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */\n");
clearDecodeTable(v32);
for ( i = 0LL; i != 64; ++i )
{
v6 = (unsigned __int8)b64chars[i];
v7 = 4 * i;
v32[v6] = v7;
}
uint32_array_to_c_hex(v32, 256LL, "base64_table_dec_32bit_d0");
puts("\n");
clearDecodeTable(v32);
for ( j = 0LL; j != 64; ++j )
{
v9 = j;
v10 = j;
v11 = (unsigned __int8)b64chars[j];
v32[v11] = (v10 >> 4) | (unsigned __int16)(v9 << 12);
}
uint32_array_to_c_hex(v32, 256LL, "base64_table_dec_32bit_d1");
puts("\n");
clearDecodeTable(v32);
for ( k = 0LL; k != 64; ++k )
{
v13 = k;
v14 = k;
v15 = (unsigned __int8)b64chars[k];
v32[v15] = (v14 << 6) & 0xF00 | (v13 << 22) & 0xC00000;
}
uint32_array_to_c_hex(v32, 256LL, "base64_table_dec_32bit_d2");
puts("\n");
clearDecodeTable(v32);
for ( l = 0LL; l != 64; ++l )
{
v17 = (unsigned __int8)b64chars[l];
v18 = l;
v32[v17] = v18 << 16;
}
uint32_array_to_c_hex(v32, 256LL, "base64_table_dec_32bit_d3");
puts("\n");
puts("#else");
puts("\n\n/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */\n");
clearDecodeTable(v32);
for ( m = 0LL; m != 64; ++m )
{
v20 = (unsigned __int8)b64chars[m];
v21 = m;
v32[v20] = v21 << 26;
}
uint32_array_to_c_hex(v32, 256LL, "base64_table_dec_32bit_d0");
puts("\n");
clearDecodeTable(v32);
for ( n = 0LL; n != 64; ++n )
{
v23 = (unsigned __int8)b64chars[n];
v24 = n;
v32[v23] = v24 << 20;
}
uint32_array_to_c_hex(v32, 256LL, "base64_table_dec_32bit_d1");
puts("\n");
clearDecodeTable(v32);
for ( ii = 0LL; ii != 64; ++ii )
{
v26 = (unsigned __int8)b64chars[ii];
v27 = ii;
v32[v26] = v27 << 14;
}
uint32_array_to_c_hex(v32, 256LL, "base64_table_dec_32bit_d2");
puts("\n");
clearDecodeTable(v32);
for ( jj = 0LL; jj != 64; ++jj )
{
v29 = (unsigned __int8)b64chars[jj];
v30 = jj;
v32[v29] = v30 << 8;
}
uint32_array_to_c_hex(v32, 256LL, "base64_table_dec_32bit_d3");
puts("\n");
puts("#endif");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
size_t v4; // rax
__int64 i; // rax
__int64 v6; // rdx
int v7; // ecx
__int64 j; // rax
__int16 v9; // dx
unsigned int v10; // esi
__int64 v11; // rcx
__int64 k; // rax
int v13; // edx
__int16 v14; // cx
__int64 v15; // rsi
__int64 l; // rax
__int64 v17; // rdx
int v18; // ecx
__int64 m; // rax
__int64 v20; // rdx
int v21; // ecx
__int64 n; // rax
__int64 v23; // rdx
int v24; // ecx
__int64 ii; // rax
__int64 v26; // rdx
int v27; // ecx
__int64 jj; // rax
__int64 v29; // rdx
int v30; // ecx
int v32[258]; // [rsp+0h] [rbp-408h] BYREF

if ( argc == 2 )
{
v3 = argv[1];
v4 = strlen(v3);
*(_QWORD *)&argc = _bss_start;
if ( v4 != 3 )
{
fwrite("input must be a string of 3 characters '-', '.' or '_'\n", 1uLL, 0x37uLL, _bss_start);
exit(1);
}
argv = (const char **)"fusing '%s' as replacements in base64 encoding\n";
fprintf(_bss_start, "fusing '%s' as replacements in base64 encoding\n", v3);
byte_4040DE = *v3;
byte_4040DF = v3[1];
padchar = v3[2];
}
func8(*(_QWORD *)&argc, argv, envp);
puts("\n\n#if BASE64_LITTLE_ENDIAN");
puts("\n\n/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */\n");
func7(v32);
for ( i = 0LL; i != 64; ++i )
{
v6 = (unsigned __int8)b64chars[i];
v7 = 4 * i;
v32[v6] = v7;
}
func9(v32, 256LL, "base64_table_dec_32bit_d0");
puts("\n");
func7(v32);
for ( j = 0LL; j != 64; ++j )
{
v9 = j;
v10 = j;
v11 = (unsigned __int8)b64chars[j];
v32[v11] = (v10 >> 4) | (unsigned __int16)(v9 << 12);
}
func9(v32, 256LL, "base64_table_dec_32bit_d1");
puts("\n");
func7(v32);
for ( k = 0LL; k != 64; ++k )
{
v13 = k;
v14 = k;
v15 = (unsigned __int8)b64chars[k];
v32[v15] = (v14 << 6) & 0xF00 | (v13 << 22) & 0xC00000;
}
func9(v32, 256LL, "base64_table_dec_32bit_d2");
puts("\n");
func7(v32);
for ( l = 0LL; l != 64; ++l )
{
v17 = (unsigned __int8)b64chars[l];
v18 = l;
v32[v17] = v18 << 16;
}
func9(v32, 256LL, "base64_table_dec_32bit_d3");
puts("\n");
puts("#else");
puts("\n\n/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */\n");
func7(v32);
for ( m = 0LL; m != 64; ++m )
{
v20 = (unsigned __int8)b64chars[m];
v21 = m;
v32[v20] = v21 << 26;
}
func9(v32, 256LL, "base64_table_dec_32bit_d0");
puts("\n");
func7(v32);
for ( n = 0LL; n != 64; ++n )
{
v23 = (unsigned __int8)b64chars[n];
v24 = n;
v32[v23] = v24 << 20;
}
func9(v32, 256LL, "base64_table_dec_32bit_d1");
puts("\n");
func7(v32);
for ( ii = 0LL; ii != 64; ++ii )
{
v26 = (unsigned __int8)b64chars[ii];
v27 = ii;
v32[v26] = v27 << 14;
}
func9(v32, 256LL, "base64_table_dec_32bit_d2");
puts("\n");
func7(v32);
for ( jj = 0LL; jj != 64; ++jj )
{
v29 = (unsigned __int8)b64chars[jj];
v30 = jj;
v32[v29] = v30 << 8;
}
func9(v32, 256LL, "base64_table_dec_32bit_d3");
puts("\n");
puts("#endif");
return 0;
}

original_code:
int main(int argc, char** argv)
{
 uint32_t x;
 uint32_t i = 0;
 uint32_t ary[256];
 if (argc == 2) {
  uint8_t* replacements = (uint8_t*)argv[1];
  if (strlen((char*)replacements) != 3) {
   fprintf(stderr, "input must be a string of 3 characters '-', '.' or '_'\n");
   exit(1);
  }
  fprintf(stderr, "fusing '%s' as replacements in base64 encoding\n", replacements);
  b64chars[62] = replacements[0];
  b64chars[63] = replacements[1];
  padchar = replacements[2];
 }
 printStart();
 printf("\n\n#if BASE64_LITTLE_ENDIAN\n");
 printf("\n\n/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 2;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d0");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = ((i & 0x30) >> 4) | ((i & 0x0F) << 12);
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d1");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = ((i & 0x03) << 22) | ((i & 0x3c) << 6);
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d2");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 16;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d3");
 printf("\n\n");
 printf("#else\n");
 printf("\n\n/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 26;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d0");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 20;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d1");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 14;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d2");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 8;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(uint32_t), "base64_table_dec_32bit_d3");
 printf("\n\n");
 printf("#endif\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned int x;
 unsigned int i = 0;
 unsigned int ary[256];
 if (argc == 2) {
  unsigned char *replacements = (uint8_t*)argv[1];
  if (strlen((char *)replacements) != 3) {
   fprintf(stderr, "input must be a string of 3 characters '-', '.' or '_'\n");
   exit(1);
  }
  fprintf(stderr, "fusing '%s' as replacements in base64 encoding\n", replacements);
  b64chars[62] = replacements[0];
  b64chars[63] = replacements[1];
  padchar = replacements[2];
 }
 printStart();
 printf("\n\n#if BASE64_LITTLE_ENDIAN\n");
 printf("\n\n/* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 2;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d0");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = ((i & 0x30) >> 4) | ((i & 0x0F) << 12);
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d1");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = ((i & 0x03) << 22) | ((i & 0x3c) << 6);
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d2");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 16;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d3");
 printf("\n\n");
 printf("#else\n");
 printf("\n\n/* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 26;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d0");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 20;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d1");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 14;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d2");
 printf("\n\n");
 clearDecodeTable(ary);
 for (i = 0; i < 64; ++i) {
  x = b64chars[i];
  ary[x] = i << 8;
 }
 uint32_array_to_c_hex(ary, sizeof(ary) / sizeof(unsigned int), "base64_table_dec_32bit_d3");
 printf("\n\n");
 printf("#endif\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
x
unsigned int

variable_types:
i
unsigned int

variable_types:
ary
unsigned int [256]

variable_types:
replacements
unsigned char *