main

canonical_name: main

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

if ( argc <= 1 )
{
puts("no argument given\n");
}
else
{
v3 = atoi(argv[1]);
srand(1u);
if ( v3 )
{
v4 = v3;
v5 = 0;
do
{
v6 = rand();
v7 = rand();
LOBYTE(v8) = pythagoras((double)v6 / 2147483647.0, (double)v7 / 2147483647.0) < 1.0;
v5 += v8;
--v4;
}
while ( v4 );
}
else
{
v5 = 0;
}
printf("total points: %i\npoints in circle: %i\n", (unsigned int)v3, (unsigned int)v5);
printf("pi: %f \n", (double)v5 / (double)v3 * 4.0);
}
return 0;
}

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

if ( argc <= 1 )
{
puts("no argument given\n");
}
else
{
v3 = atoi(argv[1]);
srand(1u);
if ( v3 )
{
v4 = v3;
v5 = 0;
do
{
v6 = rand();
v7 = rand();
LOBYTE(v8) = func0((double)v6 / 2147483647.0, (double)v7 / 2147483647.0) < 1.0;
v5 += v8;
--v4;
}
while ( v4 );
}
else
{
v5 = 0;
}
printf("total points: %i\npoints in circle: %i\n", (unsigned int)v3, (unsigned int)v5);
printf("pi: %f \n", (double)v5 / (double)v3 * 4.0);
}
return 0;
}

original_code:
int main(int argc, char *argv[]){
   if(argc<=1){
      printf("no argument given\n\n");
      return(0);
   }
   int input = atoi(argv[1]);
   int i=input, inCircle=0;
   double pi, x, y, z;
   srand(1);
   for (; i; i--) {
      x = (double)rand()/(double)2147483647;
      y = (double)rand()/(double)2147483647;
      z = pythagoras(x,y);
      if(z<1)
         inCircle++;
   }
 printf("total points: %i\npoints in circle: %i\n", input, inCircle);
 pi = (inCircle/(double)input) * 4;
 printf("pi: %f \n", pi);
 return(0);
}

canonical_original_code:
int main(int argc, char *argv[]){
   if(argc<=1){
      printf("no argument given\n\n");
      return(0);
   }
   int input = atoi(argv[1]);
   int i = input; int inCircle = 0;
   double pi; double x; double y; double z;
   srand(1);
   for (; i; i--) {
      x = (double)rand()/(double)2147483647;
      y = (double)rand()/(double)2147483647;
      z = pythagoras(x,y);
      if(z<1)
         inCircle++;
   }
 printf("total points: %i\npoints in circle: %i\n", input, inCircle);
 pi = (inCircle/(double)input) * 4;
 printf("pi: %f \n", pi);
 return(0);
}

variable_types:
argv
char *[]

variable_types: input int

variable_types: inCircle int

variable_types: pi double

variable_types: z double


repo: tzwaan/datastructuren

decompiled_code:
int __fastcall print_maze(unsigned int *a1, unsigned int *a2)
{
__int64 v2; // r13
int result; // eax
__int64 i; // rbx

v2 = 0LL;
for ( result = printf("length:%d\nwidth:%d\nrow:%d\ncollum:%d\n", *a1, a1[1], *a2, a2[1]);
(int)*a1 > (int)v2;
result = putchar(10) )
{
for ( i = 0LL; (int)a1[1] > (int)i; ++i )
{
if ( *a2 == (_DWORD)v2 && a2[1] == (_DWORD)i )
putchar(88);
else
putchar(*(char *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v2) + i));
}
++v2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, unsigned int *a2)
{
__int64 v2; // r13
int result; // eax
__int64 i; // rbx

v2 = 0LL;
for ( result = printf("length:%d\nwidth:%d\nrow:%d\ncollum:%d\n", *a1, a1[1], *a2, a2[1]);
(int)*a1 > (int)v2;
result = putchar(10) )
{
for ( i = 0LL; (int)a1[1] > (int)i; ++i )
{
if ( *a2 == (_DWORD)v2 && a2[1] == (_DWORD)i )
putchar(88);
else
putchar(*(char *)(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v2) + i));
}
++v2;
}
return result;
}

original_code:
void print_maze(maze_t *maze, walker_t *walker) {
   int i, j;
   printf("length:%d\nwidth:%d\nrow:%d\ncollum:%d\n",
           maze->length, maze->width, walker->row, walker->col);
   for(i=0; i<maze->length; i++) {
      for(j=0; j<maze->width; j++) {
         if((i == walker->row) && (j == walker->col)) {
            printf("X");
         }
         else {
            printf("%c", maze->maze[i][j]);
         }
      }
      printf("\n");
   }
}

canonical_original_code:
void print_maze(struct maze_t *maze, struct walker_t *walker) {
   int i; int j;
   printf("length:%d\nwidth:%d\nrow:%d\ncollum:%d\n",
           maze->length, maze->width, walker->row, walker->col);
   for(i=0; i<maze->length; i++) {
      for(j=0; j<maze->width; j++) {
         if((i == walker->row) && (j == walker->col)) {
            printf("X");
         }
         else {
            printf("%c", maze->maze[i][j]);
         }
      }
      printf("\n");
   }
}

variable_types: struct maze_t { int length; char **maze; } *

variable_types:
walker
struct walker_t { int row; } *

variable_types: i int

variable_types: j int

return_type: void


decompiled_code:
// attributes: thunk
void cleanup_maze(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func8(void *ptr)
{
free(ptr);
}

original_code:
void cleanup_maze (maze_t *maze) {
   free(maze);
   maze = ((void *)0);
}

canonical_original_code:
void cleanup_maze(struct maze_t *maze) {
   free(maze);
   maze = ((void *)0);
}

user_defined_types: struct maze_t { int length; char **maze; }


decompiled_code:
__int64 __fastcall random_solver(__int64 a1, __int64 a2)
{
__int64 v2; // r12

do
v2 = (unsigned int)(rand() % 4);
while ( !(unsigned int)move_walker(a1, a2, v2) );
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
__int64 v2; // r12

do
v2 = (unsigned int)(rand() % 4);
while ( !(unsigned int)func16(a1, a2, v2) );
return (unsigned int)v2;
}

original_code:
int random_solver(maze_t *maze, walker_t *walker) {
   int dir = (rand() % 4);
   while(!move_walker(maze, walker, dir)) {
      dir = (rand() % 4);
   }
   return dir;
}

canonical_original_code:
int random_solver(struct maze_t *maze, struct walker_t *walker) {
   int dir = (rand() % 4);
   while(!move_walker(maze, walker, dir)) {
      dir = (rand() % 4);
   }
   return dir;
}

variable_types: dir int

return_type: int


decompiled_code:
__int64 __fastcall wall_follower_right(__int64 a1, __int64 a2, int a3)
{
unsigned int i; // er12

for ( i = (a3 + 1) % 4; !(unsigned int)move_walker(a1, a2, i); i = ((_BYTE)i + 3) & 3 )
;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, __int64 a2, int a3)
{
unsigned int i; // er12

for ( i = (a3 + 1) % 4; !(unsigned int)func16(a1, a2, i); i = ((_BYTE)i + 3) & 3 )
;
return i;
}

original_code:
int wall_follower_right(maze_t *maze, walker_t *walker, int dir) {
   dir = ((dir+1) % 4);
   while(!move_walker(maze, walker, dir)) {
      dir = ((dir+3) % 4);
   }
   return dir;
}

canonical_original_code:
int wall_follower_right(struct maze_t *maze, struct walker_t *walker, int dir) {
   dir = ((dir+1) % 4);
   while(!move_walker(maze, walker, dir)) {
      dir = ((dir+3) % 4);
   }
   return dir;
}


decompiled_code:
__int64 __fastcall wall_follower_left(__int64 a1, __int64 a2, int a3)
{
unsigned int i; // er12

for ( i = (a3 + 3) % 4; !(unsigned int)move_walker(a1, a2, i); i = (int)(i + 1) % 4 )
;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, int a3)
{
unsigned int i; // er12

for ( i = (a3 + 3) % 4; !(unsigned int)func16(a1, a2, i); i = (int)(i + 1) % 4 )
;
return i;
}

original_code:
int wall_follower_left(maze_t *maze, walker_t *walker, int dir) {
   dir = ((dir+3) % 4);
   while(!move_walker(maze, walker, dir)) {
      dir = ((dir+1) % 4);
   }
   return dir;
}

canonical_original_code:
int wall_follower_left(struct maze_t *maze, struct walker_t *walker, int dir) {
   dir = ((dir+3) % 4);
   while(!move_walker(maze, walker, dir)) {
      dir = ((dir+1) % 4);
   }
   return dir;
}


decompiled_code:
__int64 __fastcall tremaux_solver(__int64 a1, int *a2, unsigned int a3)
{
unsigned int v4; // er14
char v5; // al
unsigned int v6; // er15
bool v7; // r12
_BOOL4 v8; // eax
signed int v9; // er12
unsigned int v10; // er12
bool v12; // [rsp+Bh] [rbp-3Dh]
_BOOL4 v13; // [rsp+Ch] [rbp-3Ch]

v4 = a3 + 4;
printf("start_dir:%d\n", a3);
v5 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * *a2) + a2[1]);
v6 = 0;
v7 = v5 == 83 || v5 == 32;
v8 = v7;
v12 = v7;
v9 = a3;
v13 = v8;
do
{
v6 -= ((unsigned int)check_clear_move(a1, a2, (unsigned int)(v9 % 4)) == 0) - 1;
++v9;
}
while ( v4 != v9 );
printf("counter:%d\n", v6);
if ( !v6 && v12 )
{
v10 = (int)(a3 + 2) % 4;
lay_breadcrumb(a1, a2);
lay_breadcrumb(a1, a2);
move_walker(a1, a2, v10);
return v10;
}
if ( v6 | v13 )
{
if ( v12 )
{
if ( !v6 )
return a3;
v10 = a3;
lay_breadcrumb(a1, a2);
while ( !(unsigned int)clear_move_walker(a1, a2, v10) )
v10 = (int)(v10 + 1) % 4;
}
else
{
v10 = a3;
if ( !v6 )
return a3;
while ( !(unsigned int)clear_move_walker(a1, a2, v10) )
v10 = (int)(v10 + 1) % 4;
}
}
else
{
v10 = a3;
lay_breadcrumb(a1, a2);
while ( !(unsigned int)move_walker(a1, a2, v10) )
v10 = (int)(v10 + 1) % 4;
}
return v10;
}

original_code:
int tremaux_solver(maze_t *maze, walker_t *walker, int dir) {
   int counter=0, i, new_path=0;
   printf("start_dir:%d\n", dir);
   if(maze->maze[walker->row][walker->col] == 32 ||
      maze->maze[walker->row][walker->col] == 83)
      new_path = 1;
   else
      new_path = 0;
   for(i=0; i<4; i++) {
      if(check_clear_move(maze, walker, ((dir + i) % 4))) {
         counter++;
      }
   }
   printf("counter:%d\n", counter);
   if(!counter && new_path) {
      dir = ((dir + 2) % 4);
      lay_breadcrumb(maze, walker);
      lay_breadcrumb(maze, walker);
      move_walker(maze, walker, dir);
      return dir;
   }
   if(!counter && !new_path) {
      lay_breadcrumb(maze, walker);
      while(!move_walker(maze, walker, dir))
         dir = ((dir + 1) % 4);
   }
   if(counter && new_path) {
      lay_breadcrumb(maze, walker);
      while(!clear_move_walker(maze, walker, dir))
         dir = ((dir + 1) % 4);
      return dir;
   }
   if(counter && !new_path) {
      while(!clear_move_walker(maze, walker, dir))
         dir = ((dir + 1) % 4);
      return dir;
   }
   return dir;
}

canonical_original_code:
int tremaux_solver(struct maze_t *maze, struct walker_t *walker, int dir) {
   int counter = 0; int i; int new_path = 0;
   printf("start_dir:%d\n", dir);
   if(maze->maze[walker->row][walker->col] == 32 ||
      maze->maze[walker->row][walker->col] == 83)
      new_path = 1;
   else
      new_path = 0;
   for(i=0; i<4; i++) {
      if(check_clear_move(maze, walker, ((dir + i) % 4))) {
         counter++;
      }
   }
   printf("counter:%d\n", counter);
   if(!counter && new_path) {
      dir = ((dir + 2) % 4);
      lay_breadcrumb(maze, walker);
      lay_breadcrumb(maze, walker);
      move_walker(maze, walker, dir);
      return dir;
   }
   if(!counter && !new_path) {
      lay_breadcrumb(maze, walker);
      while(!move_walker(maze, walker, dir))
         dir = ((dir + 1) % 4);
   }
   if(counter && new_path) {
      lay_breadcrumb(maze, walker);
      while(!clear_move_walker(maze, walker, dir))
         dir = ((dir + 1) % 4);
      return dir;
   }
   if(counter && !new_path) {
      while(!clear_move_walker(maze, walker, dir))
         dir = ((dir + 1) % 4);
      return dir;
   }
   return dir;
}

variable_types: counter int


original_code:
int check_move(maze_t *maze, walker_t *walker, int dir) {
   switch(dir) {
      case 0 : if(maze->maze[walker->row - 1][walker->col] != 35) {return 1;};
               break;
      case 1 : if(maze->maze[walker->row][walker->col + 1] != 35) {return 1;};
               break;
      case 2 : if(maze->maze[walker->row + 1][walker->col] != 35) {return 1;};
               break;
      case 3 : if(maze->maze[walker->row][walker->col - 1] != 35) {return 1;};
               break;
      default: return 0;
   }
   return 0;
}

canonical_original_code:
int check_move(struct maze_t *maze, struct walker_t *walker, int dir) {
   switch(dir) {
      case 0 : if(maze->maze[walker->row - 1][walker->col] != 35) {return 1;};
               break;
      case 1 : if(maze->maze[walker->row][walker->col + 1] != 35) {return 1;};
               break;
      case 2 : if(maze->maze[walker->row + 1][walker->col] != 35) {return 1;};
               break;
      case 3 : if(maze->maze[walker->row][walker->col - 1] != 35) {return 1;};
               break;
      default: return 0;
   }
   return 0;
}


original_code:
int check_clear_move(maze_t *maze, walker_t *walker, int dir) {
   switch(dir) {
      case 0 : if(maze->maze[walker->row - 1][walker->col] != 35 &&
                  maze->maze[walker->row - 1][walker->col] != 46) {return 1;};
               break;
      case 1 : if(maze->maze[walker->row][walker->col + 1] != 35 &&
                  maze->maze[walker->row][walker->col + 1] != 46) {return 1;};
               break;
      case 2 : if(maze->maze[walker->row + 1][walker->col] != 35 &&
                  maze->maze[walker->row + 1][walker->col] != 46) {return 1;};
               break;
      case 3 : if(maze->maze[walker->row][walker->col - 1] != 35 &&
                  maze->maze[walker->row][walker->col - 1] != 46) {return 1;};
               break;
      default: return 0;
   }
   return 0;
}

canonical_original_code:
int check_clear_move(struct maze_t *maze, struct walker_t *walker, int dir) {
   switch(dir) {
      case 0 : if(maze->maze[walker->row - 1][walker->col] != 35 &&
                  maze->maze[walker->row - 1][walker->col] != 46) {return 1;};
               break;
      case 1 : if(maze->maze[walker->row][walker->col + 1] != 35 &&
                  maze->maze[walker->row][walker->col + 1] != 46) {return 1;};
               break;
      case 2 : if(maze->maze[walker->row + 1][walker->col] != 35 &&
                  maze->maze[walker->row + 1][walker->col] != 46) {return 1;};
               break;
      case 3 : if(maze->maze[walker->row][walker->col - 1] != 35 &&
                  maze->maze[walker->row][walker->col - 1] != 46) {return 1;};
               break;
      default: return 0;
   }
   return 0;
}


original_code:
int at_exit(maze_t *maze, walker_t *walker) {
   if(maze->maze[walker->row][walker->col] == 69)
      return 1;
   return 0;
}

canonical_original_code:
int at_exit(struct maze_t *maze, struct walker_t *walker) {
   if(maze->maze[walker->row][walker->col] == 69)
      return 1;
   return 0;
}


decompiled_code:
_BOOL8 __fastcall move_walker(__int64 a1, int *a2, int a3)
{
_BOOL8 result; // rax
int v4; // er8

result = check_move(a1, a2, a3);
if ( result )
{
if ( v4 == 2 )
{
++*a2;
return 1LL;
}
if ( v4 > 2 )
{
if ( v4 != 3 )
return 0LL;
--a2[1];
result = 1LL;
}
else
{
if ( v4 )
{
if ( v4 == 1 )
{
++a2[1];
return 1LL;
}
return 0LL;
}
--*a2;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func16(__int64 a1, int *a2, int a3)
{
_BOOL8 result; // rax
int v4; // er8

result = func13(a1, a2, a3);
if ( result )
{
if ( v4 == 2 )
{
++*a2;
return 1LL;
}
if ( v4 > 2 )
{
if ( v4 != 3 )
return 0LL;
--a2[1];
result = 1LL;
}
else
{
if ( v4 )
{
if ( v4 == 1 )
{
++a2[1];
return 1LL;
}
return 0LL;
}
--*a2;
result = 1LL;
}
}
return result;
}

original_code:
int move_walker(maze_t *maze, walker_t *walker, int dir) {
   if(check_move(maze, walker, dir)) {
      switch(dir) {
         case 0 : walker->row--; return 1;
         case 1 : walker->col++; return 1;
         case 2 : walker->row++; return 1;
         case 3 : walker->col--; return 1;
         default: break;
      }
   }
   return 0;
}

canonical_original_code:
int move_walker(struct maze_t *maze, struct walker_t *walker, int dir) {
   if(check_move(maze, walker, dir)) {
      switch(dir) {
         case 0 : walker->row--; return 1;
         case 1 : walker->col++; return 1;
         case 2 : walker->row++; return 1;
         case 3 : walker->col--; return 1;
         default: break;
      }
   }
   return 0;
}


decompiled_code:
__int64 __fastcall clear_move_walker(__int64 a1, int *a2, int a3)
{
__int64 result; // rax
int v4; // er8

result = check_clear_move(a1, a2, a3);
if ( (_DWORD)result )
{
if ( v4 == 2 )
{
++*a2;
return 1LL;
}
if ( v4 > 2 )
{
if ( v4 != 3 )
return 0LL;
--a2[1];
result = 1LL;
}
else
{
if ( v4 )
{
if ( v4 == 1 )
{
++a2[1];
return 1LL;
}
return 0LL;
}
--*a2;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, int *a2, int a3)
{
__int64 result; // rax
int v4; // er8

result = func14(a1, a2, a3);
if ( (_DWORD)result )
{
if ( v4 == 2 )
{
++*a2;
return 1LL;
}
if ( v4 > 2 )
{
if ( v4 != 3 )
return 0LL;
--a2[1];
result = 1LL;
}
else
{
if ( v4 )
{
if ( v4 == 1 )
{
++a2[1];
return 1LL;
}
return 0LL;
}
--*a2;
result = 1LL;
}
}
return result;
}

original_code:
int clear_move_walker(maze_t *maze, walker_t *walker, int dir) {
   if(check_clear_move(maze, walker, dir)) {
      switch(dir) {
         case 0 : walker->row--; return 1;
         case 1 : walker->col++; return 1;
         case 2 : walker->row++; return 1;
         case 3 : walker->col--; return 1;
         default: break;
      }
   }
   return 0;
}

canonical_original_code:
int clear_move_walker(struct maze_t *maze, struct walker_t *walker, int dir) {
   if(check_clear_move(maze, walker, dir)) {
      switch(dir) {
         case 0 : walker->row--; return 1;
         case 1 : walker->col++; return 1;
         case 2 : walker->row++; return 1;
         case 3 : walker->col--; return 1;
         default: break;
      }
   }
   return 0;
}


decompiled_code:
// attributes: thunk
void cleanup_walker(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func19(void *ptr)
{
free(ptr);
}

original_code:
void cleanup_walker(walker_t *walker) {
   free(walker);
   walker = ((void *)0);
}

canonical_original_code:
void cleanup_walker(struct walker_t *walker) {
   free(walker);
   walker = ((void *)0);
}


decompiled_code:
_QWORD *maak_loods3()
{
_QWORD *v0; // r12

v0 = calloc(1uLL, 0x10uLL);
*v0 = maak_loods();
v0[1] = maak_loods();
return v0;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // r12

v0 = calloc(1uLL, 0x10uLL);
*v0 = func7();
v0[1] = func7();
return v0;
}

original_code:
loods3 *maak_loods3(void) {
 loods3 *loods = calloc(1, sizeof(loods3));
 loods->loods1 = maak_loods();
 loods->loods2 = maak_loods();
 return loods;
}

canonical_original_code:
struct loods3 *maak_loods3() {
 struct loods3 *loods = calloc(1, sizeof(loods3));
 loods->loods1 = maak_loods();
 loods->loods2 = maak_loods();
 return loods;
}

variable_types: struct loods3 { struct loods2 { struct container { struct container *next; char *content; } *begin; } *loods1; struct loods2 *loods2; } *

user_defined_types: struct loods3 { struct loods2 *loods1; struct loods2 *loods2; }

user_defined_types: struct loods2 { struct container *begin; }


decompiled_code:
// attributes: thunk
void *maak_container()
{
return maak_loods();
}

canonical_decompiled_code:
void *func9()
{
return func7();
}

original_code:
container *maak_container(void) {
 container *container = calloc(1, sizeof(container));
 return container;
}

canonical_original_code:
struct container *maak_container() {
 struct container *container = calloc(1, sizeof(container));
 return container;
}

variable_types: struct container { struct container *next; char *content; } *


decompiled_code:
void *__fastcall opslaan_oud(__int64 *a1, const char *a2)
{
_QWORD *v2; // rbp
__int64 v3; // rax
size_t v4; // rbx
void *v5; // rax

v2 = maak_loods();
v3 = *a1;
*a1 = (__int64)v2;
*v2 = v3;
v4 = strlen(a2);
v5 = malloc(v4);
v2[1] = v5;
return memcpy(v5, a2, v4 + 1);
}

canonical_decompiled_code:
void *__fastcall func12(__int64 *a1, const char *a2)
{
_QWORD *v2; // rbp
__int64 v3; // rax
size_t v4; // rbx
void *v5; // rax

v2 = func7();
v3 = *a1;
*a1 = (__int64)v2;
*v2 = v3;
v4 = strlen(a2);
v5 = malloc(v4);
v2[1] = v5;
return memcpy(v5, a2, v4 + 1);
}

original_code:
void opslaan_oud(loods2 *loods, char *content) {
 container *container = maak_container();
 container->next = loods->begin;
 loods->begin = container;
 container->content = malloc(strlen(content) * sizeof(char));
 strcpy(container->content, content);
}

canonical_original_code:
void opslaan_oud(struct loods2 *loods, char *content) {
 struct container *container = maak_container();
 container->next = loods->begin;
 loods->begin = container;
 container->content = malloc(strlen(content) * sizeof(char));
 strcpy(container->content, content);
}

variable_types: struct loods2 { struct container { struct container *next; char *content; } *begin; } *

variable_types:
content
char *


decompiled_code:
__int64 __fastcall leveren_oud(_QWORD *a1)
{
__int64 v1; // r12
void *v2; // r8

v1 = 0LL;
if ( !leeg(a1) )
{
v2 = (void *)*a1;
v1 = *(_QWORD *)(*a1 + 8LL);
*a1 = *(_QWORD *)*a1;
free(v2);
}
return v1;
}

original_code:
char *leveren_oud(loods2 *loods) {
 if (leeg(loods))
  return ((void *)0);
 container *container = loods->begin;
 char *content = loods->begin->content;
 loods->begin = container->next;
 free(container);
 return content;
}

canonical_original_code:
char *leveren_oud(struct loods2 *loods) {
 if (leeg(loods))
  return ((void *)0);
 struct container *container = loods->begin;
 char *content = loods->begin->content;
 loods->begin = container->next;
 free(container);
 return content;
}

return_type: char *

user_defined_types: struct container { struct container *next; char *content; }


decompiled_code:
_BOOL8 __fastcall verplaats_alles(_QWORD **a1)
{
_BOOL8 result; // rax

while ( 1 )
{
result = leeg(*a1);
if ( result )
break;
verplaatsen(a1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(_QWORD **a1)
{
_BOOL8 result; // rax

while ( 1 )
{
result = func10(*a1);
if ( result )
break;
func14(a1);
}
return result;
}

original_code:
void verplaats_alles(loods3 *loods) {
 while (!leeg(loods->loods1)) {
  verplaatsen(loods);
 }
}

canonical_original_code:
void verplaats_alles(struct loods3 *loods) {
 while (!leeg(loods->loods1)) {
  verplaatsen(loods);
 }
}


gcd

decompiled_code:
__int64 __fastcall gcd(int a1, int a2)
{
int v2; // edx
__int64 result; // rax

if ( (a1 & 1) != 0 )
{
result = (unsigned int)a1;
v2 = 0;
}
else
{
v2 = a2 & 1;
if ( (a2 & 1) != 0 )
{
v2 = 0;
}
else
{
do
{
a1 >>= 1;
++v2;
a2 >>= 1;
if ( (a1 & 1) != 0 )
{
result = (unsigned int)a1;
if ( (a1 & 1) != 0 )
goto LABEL_10;
goto LABEL_7;
}
}
while ( (a2 & 1) == 0 );
}
result = (unsigned int)a1;
a1 = -a2;
}
do
{
while ( (a1 & 1) == 0 )
LABEL_7:
a1 >>= 1;
LABEL_10:
if ( a1 <= 0 )
a2 = -a1;
else
result = (unsigned int)a1;
a1 = result - a2;
}
while ( (_DWORD)result != a2 );
if ( v2 )
{
do
{
++a1;
result = (unsigned int)(2 * result);
}
while ( a1 != v2 );
}
return result;
}

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

if ( (a1 & 1) != 0 )
{
result = (unsigned int)a1;
v2 = 0;
}
else
{
v2 = a2 & 1;
if ( (a2 & 1) != 0 )
{
v2 = 0;
}
else
{
do
{
a1 >>= 1;
++v2;
a2 >>= 1;
if ( (a1 & 1) != 0 )
{
result = (unsigned int)a1;
if ( (a1 & 1) != 0 )
goto LABEL_10;
goto LABEL_7;
}
}
while ( (a2 & 1) == 0 );
}
result = (unsigned int)a1;
a1 = -a2;
}
do
{
while ( (a1 & 1) == 0 )
LABEL_7:
a1 >>= 1;
LABEL_10:
if ( a1 <= 0 )
a2 = -a1;
else
result = (unsigned int)a1;
a1 = result - a2;
}
while ( (_DWORD)result != a2 );
if ( v2 )
{
do
{
++a1;
result = (unsigned int)(2 * result);
}
while ( a1 != v2 );
}
return result;
}

variable_types: u int

variable_types: v int

variable_types: k int

variable_types: t int


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

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

original_code:
unsigned int hash_int(void *value, unsigned int hash_table_size){
 return *((int*)value) % hash_table_size;
}

canonical_original_code:
unsigned int hash_int(void *value, unsigned int hash_table_size){
 return *((int *)value) % hash_table_size;
}

variable_types:
value
void *

return_type: unsigned int


decompiled_code:
__int64 __fastcall hash_char(char *a1, unsigned int a2)
{
char v2; // dl
_BYTE *v3; // rdi
unsigned int v4; // eax
int v5; // ecx
int v6; // eax

v2 = *a1;
if ( !*a1 )
return 0LL;
v3 = a1 + 1;
v4 = 0;
do
{
++v3;
v5 = 11 * v4;
v6 = v2;
v2 = *(v3 - 1);
v4 = v5 ^ v6;
}
while ( v2 );
return v4 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, unsigned int a2)
{
char v2; // dl
_BYTE *v3; // rdi
unsigned int v4; // eax
int v5; // ecx
int v6; // eax

v2 = *a1;
if ( !*a1 )
return 0LL;
v3 = a1 + 1;
v4 = 0;
do
{
++v3;
v5 = 11 * v4;
v6 = v2;
v2 = *(v3 - 1);
v4 = v5 ^ v6;
}
while ( v2 );
return v4 % a2;
}

original_code:
unsigned int hash_char(void *value, unsigned int hash_table_size){
 unsigned hash_value = 0;
    int i = 0;
    char c;
    while((c = ((char*)value)[i++]) != 0){
     hash_value = c ^ 11 * hash_value;
    }
    return (hash_value % hash_table_size);
}

canonical_original_code:
unsigned int hash_char(void *value, unsigned int hash_table_size){
 unsigned int hash_value = 0;
    int i = 0;
    char c;
    while((c = ((char *)value)[i++]) != 0){
     hash_value = c ^ 11 * hash_value;
    }
    return (hash_value % hash_table_size);
}

variable_types: c char


decompiled_code:
_BOOL8 __fastcall compare_int(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

original_code:
int compare_int(void *a, void *b){
 if(*((int *)a) == *((int *)b)){
  return 1;
 }
 return 0;
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
_BOOL8 __fastcall compare_char(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, const char *a2)
{
return strcmp(a1, a2) == 0;
}

original_code:
int compare_char(void *a, void *b){
 if(strcmp((char *)a,(char *)b) == 0) return 1;
 return 0;
}


decompiled_code:
__int64 __fastcall gcds_calc(unsigned int *a1, int a2)
{
unsigned int v3; // edi
__int64 v4; // rcx
__int64 v5; // r8
int v6; // er9
unsigned int v7; // eax
__int64 v8; // rcx
int v9; // esi

if ( a2 == 1 )
return *a1;
v3 = 1;
if ( a2 > 0 )
{
v3 = gcd(a1[a2 - 1], a1[a2 - 2]);
if ( v6 != 2 )
{
v4 = (int)v4;
while ( 1 )
{
v9 = *(_DWORD *)(v5 + 4 * v4);
if ( v9 < 0 )
break;
v7 = gcd(v3, v9);
v4 = v8 - 1;
v3 = v7;
if ( (_DWORD)v4 == -1 )
return v3;
}
v3 = -1;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, int a2)
{
unsigned int v3; // edi
__int64 v4; // rcx
__int64 v5; // r8
int v6; // er9
unsigned int v7; // eax
__int64 v8; // rcx
int v9; // esi

if ( a2 == 1 )
return *a1;
v3 = 1;
if ( a2 > 0 )
{
v3 = func0(a1[a2 - 1], a1[a2 - 2]);
if ( v6 != 2 )
{
v4 = (int)v4;
while ( 1 )
{
v9 = *(_DWORD *)(v5 + 4 * v4);
if ( v9 < 0 )
break;
v7 = func0(v3, v9);
v4 = v8 - 1;
v3 = v7;
if ( (_DWORD)v4 == -1 )
return v3;
}
v3 = -1;
}
}
return v3;
}

original_code:
int gcds_calc(int *ngram, int dist_count){
 int i, tmp;
 if(dist_count == 1 ) {
  return ngram[0];
 }else if(dist_count < 1){
  return 1;
 }
 tmp = gcd(ngram[dist_count-1],ngram[dist_count-2]);
 for (i = dist_count-3; i >= 0; --i) {
  if(ngram[i] < 0){
   return -1;
  }
  tmp = gcd(tmp,ngram[i]);
 }
 return tmp;
}

canonical_original_code:
int gcds_calc(int *ngram, int dist_count){
 int i; int tmp;
 if(dist_count == 1 ) {
  return ngram[0];
 }else if(dist_count < 1){
  return 1;
 }
 tmp = gcd(ngram[dist_count-1],ngram[dist_count-2]);
 for (i = dist_count-3; i >= 0; --i) {
  if(ngram[i] < 0){
   return -1;
  }
  tmp = gcd(tmp,ngram[i]);
 }
 return tmp;
}

variable_types:
ngram
int *

variable_types: tmp int


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

result = *a1;
if ( (_BYTE)result )
{
v3 = a1 + 1;
do
{
++v3;
*(double *)(a2 + 8 * result - 776) = *(double *)(a2 + 8 * result - 776) + 1.0;
result = *(v3 - 1);
}
while ( (_BYTE)result );
}
return result;
}

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

result = *a1;
if ( (_BYTE)result )
{
v3 = a1 + 1;
do
{
++v3;
*(double *)(a2 + 8 * result - 776) = *(double *)(a2 + 8 * result - 776) + 1.0;
result = *(v3 - 1);
}
while ( (_BYTE)result );
}
return result;
}

original_code:
void letter_freqs(char *input, double freqs[]){
 char c;
 unsigned long i = 0;
 while((c = input[i++]) != 0){
  freqs[c - 'a']++;
 }
}

variable_types:
input
char *

variable_types:
freqs
double []

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall hash_char_2(char *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
char *v4; // rdi

v2 = a1[1];
v3 = *a1;
if ( a1[1] )
{
v4 = a1 + 2;
do
{
++v4;
v3 = v2 + 16 * v3;
v2 = *(v4 - 1);
}
while ( *(v4 - 1) );
}
return v3 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax
char *v4; // rdi

v2 = a1[1];
v3 = *a1;
if ( a1[1] )
{
v4 = a1 + 2;
do
{
++v4;
v3 = v2 + 16 * v3;
v2 = *(v4 - 1);
}
while ( *(v4 - 1) );
}
return v3 % a2;
}

original_code:
unsigned int hash_char_2(void *value, unsigned int hash_table_size){
 char *data = (char*)value;
 unsigned h = data[0];
 int i;
 for (i = 1; data[i] != 0; ++i){
  h = (h << 4) + data[ i ];
 }
 return h % hash_table_size;
}

canonical_original_code:
unsigned int hash_char_2(void *value, unsigned int hash_table_size){
 char *data = (char*)value;
 unsigned int h = data[0];
 int i;
 for (i = 1; data[i] != 0; ++i){
  h = (h << 4) + data[ i ];
 }
 return h % hash_table_size;
}

variable_types:
data
char *

variable_types:
h
unsigned int

variable_types: i int


decompiled_code:
__int64 __fastcall q_compare_ngram(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a2 + 5) - *((_DWORD *)a1 + 5));
}

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

original_code:
int q_compare_ngram(const void * a, const void * b){
 return (*((kasiski_node_t *)b)).count - (*((kasiski_node_t *)a)).count;
}

canonical_original_code:
int q_compare_ngram(void *a, void *b){
 return (*((struct _kasiski_node *)b)).count - (*((struct _kasiski_node *)a)).count;
}

user_defined_types: struct _kasiski_node { struct _kasiski_node *next; int *positions; unsigned int _ngram_max_pos; int count; unsigned int len; int *distances; int gcd; }


decompiled_code:
__int64 __fastcall q_compare_gcd(const void *a1, const void *a2)
{
return (unsigned int)(**((_DWORD **)a2 + 2) - **((_DWORD **)a1 + 2));
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, const void *a2)
{
return (unsigned int)(**((_DWORD **)a2 + 2) - **((_DWORD **)a1 + 2));
}

original_code:
int q_compare_gcd(const void * a, const void * b){
 hash_table_node_t h_a = *((hash_table_node_t *)a);
 hash_table_node_t h_b = *((hash_table_node_t *)b);
 return (*((int*)h_b.value)) - (*((int*)h_a.value));
}

canonical_original_code:
int q_compare_gcd(void *a, void *b){
 struct _hash_table_node h_a = *((hash_table_node_t *)a);
 struct _hash_table_node h_b = *((hash_table_node_t *)b);
 return (*((int *)h_b.value)) - (*((int *)h_a.value));
}

variable_types: struct _hash_table_node { struct _hash_table_node *next; void *key; void *value; }


decompiled_code:
_QWORD *create_default_ngram_node()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax

v0 = malloc(0x30uLL);
if ( !v0 )
{
perror("node mallock failed\n");
exit(1);
}
v1 = v0;
v0[1] = malloc(0x320uLL);
v2 = malloc(0x320uLL);
v1[2] = 200LL;
v1[4] = v2;
return v1;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rax

v0 = malloc(0x30uLL);
if ( !v0 )
{
perror("node mallock failed\n");
exit(1);
}
v1 = v0;
v0[1] = malloc(0x320uLL);
v2 = malloc(0x320uLL);
v1[2] = 200LL;
v1[4] = v2;
return v1;
}

original_code:
kasiski_node_t *create_default_ngram_node(){
 kasiski_node_t *new_node = (kasiski_node_t *) malloc(sizeof(kasiski_node_t));
 if(new_node == ((void *)0)){
  perror("node mallock failed\n");
  exit(1);
 }
 new_node->positions = (int *) malloc(200 * sizeof(int));
 new_node->distances = (int *) malloc(200 * sizeof(int));
 new_node->count = 0;
 new_node->_ngram_max_pos = 200;
 return new_node;
}

canonical_original_code:
struct _kasiski_node *create_default_ngram_node(){
 struct _kasiski_node *new_node = (kasiski_node_t *) malloc(sizeof(kasiski_node_t));
 if(new_node == ((void *)0)){
  perror("node mallock failed\n");
  exit(1);
 }
 new_node->positions = (int *) malloc(200 * sizeof(int));
 new_node->distances = (int *) malloc(200 * sizeof(int));
 new_node->count = 0;
 new_node->_ngram_max_pos = 200;
 return new_node;
}

variable_types: struct _kasiski_node { struct _kasiski_node *next; int *positions; unsigned int _ngram_max_pos; int count; unsigned int len; int *distances; int gcd; } *


decompiled_code:
__int64 __fastcall add_position(__int64 a1, int a2, __int64 a3, _DWORD *a4)
{
int v6; // esi
unsigned int v8; // eax
_DWORD *v9; // rdi
__int64 result; // rax
int v11; // edx
__int64 v12; // rax
_DWORD *v13; // r8
__int64 v14; // rcx
void *v15; // rax
__int64 v16; // rsi
void *v17; // rax
__int64 v18; // rsi
void *v19; // rdi
void *v20; // rax

v6 = *(_DWORD *)(a1 + 16);
v8 = *(_DWORD *)(a1 + 20);
v9 = *(_DWORD **)(a1 + 8);
if ( v8 >= v6 - 1 )
{
v16 = (unsigned int)(2 * v6);
*(_DWORD *)(a1 + 16) = v16;
v17 = realloc(v9, 4 * v16);
v18 = *(unsigned int *)(a1 + 16);
v19 = *(void **)(a1 + 32);
*(_QWORD *)(a1 + 8) = v17;
v20 = realloc(v19, 4 * v18);
v9 = *(_DWORD **)(a1 + 8);
*(_QWORD *)(a1 + 32) = v20;
if ( !v9 || !v20 )
{
perror("ngram->position | distances allocation\n");
exit(1);
}
v8 = *(_DWORD *)(a1 + 20);
}
LODWORD(result) = v8 + 1;
*(_DWORD *)(a1 + 20) = result;
result = (int)result;
v9[(int)result - 1] = a2;
if ( *(int *)(a1 + 20) > 1 )
{
v11 = all_pos_max;
v12 = (unsigned int)*a4;
v13 = all_pos;
if ( (unsigned int)v12 >= all_pos_max - 1 )
{
all_pos_max *= 2;
v15 = realloc(all_pos, 8LL * v11);
v9 = *(_DWORD **)(a1 + 8);
all_pos = v15;
v13 = v15;
v12 = (unsigned int)*a4;
}
v14 = *(_QWORD *)(a1 + 32);
*a4 = v12 + 1;
v13[v12] = a2;
result = 4LL * *(int *)(a1 + 20);
*(_DWORD *)(v14 + result - 8) = *(_DWORD *)((char *)v9 + result - 4) - *v9;
}
return result;
}

original_code:
void add_position(kasiski_node_t *ngram, int position, int ngram_len, unsigned int *all_pos_counter){
 if(ngram->count >= ngram->_ngram_max_pos - 1){
  ngram->_ngram_max_pos *= 2;
  ngram->positions = (int *) realloc(ngram->positions,ngram->_ngram_max_pos * sizeof(int));
  ngram->distances = (int *) realloc(ngram->distances,ngram->_ngram_max_pos * sizeof(int));
  if(ngram->positions == ((void *)0) || ngram->distances == ((void *)0)){
   perror("ngram->position | distances allocation\n");
   exit(1);
  }
 }
 ngram->count++;
 ngram->positions[ngram->count - 1] = position;
 if(ngram->count < 2) return;
 if(*all_pos_counter >= all_pos_max - 1){
  all_pos_max *= 2;
  all_pos = (int *)realloc(all_pos,all_pos_max * sizeof(int));
 }
 all_pos[(*all_pos_counter)++] = position;
 ngram->distances[ngram->count - 2] = ngram->positions[ngram->count - 1] - ngram->positions[0];
}

canonical_original_code:
void add_position(struct _kasiski_node *ngram, int position, int ngram_len, unsigned int *all_pos_counter){
 if(ngram->count >= ngram->_ngram_max_pos - 1){
  ngram->_ngram_max_pos *= 2;
  ngram->positions = (int *) realloc(ngram->positions,ngram->_ngram_max_pos * sizeof(int));
  ngram->distances = (int *) realloc(ngram->distances,ngram->_ngram_max_pos * sizeof(int));
  if(ngram->positions == ((void *)0) || ngram->distances == ((void *)0)){
   perror("ngram->position | distances allocation\n");
   exit(1);
  }
 }
 ngram->count++;
 ngram->positions[ngram->count - 1] = position;
 if(ngram->count < 2) return;
 if(*all_pos_counter >= all_pos_max - 1){
  all_pos_max *= 2;
  all_pos = (int *)realloc(all_pos,all_pos_max * sizeof(int));
 }
 all_pos[(*all_pos_counter)++] = position;
 ngram->distances[ngram->count - 2] = ngram->positions[ngram->count - 1] - ngram->positions[0];
}

variable_types: position int


decompiled_code:
void __fastcall free_ngram_node(void *ptr)
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*((void **)ptr + 4));
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void free_ngram_node(kasiski_node_t* ngram_node) {
 free(ngram_node->distances);
 free(ngram_node->positions);
 free(ngram_node);
}

canonical_original_code:
void free_ngram_node(struct _kasiski_node *ngram_node) {
 free(ngram_node->distances);
 free(ngram_node->positions);
 free(ngram_node);
}


decompiled_code:
char *__fastcall substring_search(char *needle, __int64 a2, unsigned int a3, __int64 a4, int a5, _DWORD *a6)
{
char *result; // rax

while ( 1 )
{
result = strstr((const char *)(a2 + 1), needle);
a2 = (__int64)result;
if ( !result )
break;
add_position(a4, (_DWORD)result - a5, a3, a6);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(char *needle, __int64 a2, unsigned int a3, __int64 a4, int a5, _DWORD *a6)
{
char *result; // rax

while ( 1 )
{
result = strstr((const char *)(a2 + 1), needle);
a2 = (__int64)result;
if ( !result )
break;
func3(a4, (_DWORD)result - a5, a3, a6);
}
return result;
}

original_code:
void substring_search(const char *search,const char *text, int subl_len, kasiski_node_t *ngram, const char *orig_text,unsigned int *all_pos_counter){
 int pos;
 char *ptr;
 while((ptr = strstr(text + 1,search)) != ((void *)0)){
  pos = ptr - orig_text;
  add_position(ngram,pos,subl_len,all_pos_counter);
  text = ptr;
 }
}

canonical_original_code:
void substring_search(char *search, char *text, int subl_len, struct _kasiski_node *ngram, char *orig_text, unsigned int *all_pos_counter){
 int pos;
 char *ptr;
 while((ptr = strstr(text + 1,search)) != ((void *)0)){
  pos = ptr - orig_text;
  add_position(ngram,pos,subl_len,all_pos_counter);
  text = ptr;
 }
}

variable_types:
search
char *

variable_types:
text
char *

variable_types: pos int

variable_types:
ptr
char *


decompiled_code:
void __fastcall find_ngrams(char *haystack, int a2)
{
int v2; // er15
__int64 v4; // r12
char *v5; // rbp
unsigned int v6; // ebx
_QWORD *v7; // r15
int v8; // esi
__int64 v9; // rdi
int v10; // eax
unsigned int v11; // [rsp+Ch] [rbp-5Ch]
char *v12; // [rsp+10h] [rbp-58h]
unsigned int v13; // [rsp+18h] [rbp-50h]
int v14[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v2 = 0;
v4 = 3LL;
v5 = (char *)malloc(6uLL);
all_pos = calloc(all_pos_max, 4uLL);
v13 = a2 - 3;
while ( 2 )
{
v6 = 0;
ngram_count[v4] = 0;
v14[0] = 0;
v11 = v2 - 1;
while ( v4 != 3 )
{
if ( v6 > v11 )
goto LABEL_17;
substring(v5, haystack, *((unsigned int *)all_pos + v6), (unsigned int)v4);
LABEL_7:
if ( !t_search(v5, &hash_char, &compare_char, &hash_table_all_ngrams, 10007LL) )
{
t_insert(v5, v5, &hash_char, &hash_table_all_ngrams, v4 + 1, v4 + 1, 10007LL);
v12 = strstr(haystack, v5);
if ( v12 )
{
v7 = create_default_ngram_node();
add_position((__int64)v7, (_DWORD)v12 - (_DWORD)haystack, (unsigned int)v4, v14);
substring_search(v5, (__int64)v12, v4, (__int64)v7, (int)haystack, v14);
v8 = *((_DWORD *)v7 + 5);
if ( v8 > 1 )
{
v9 = v7[4];
*((_DWORD *)v7 + 6) = v4;
v10 = gcds_calc(v9, (unsigned int)(v8 - 1));
*((_DWORD *)v7 + 10) = v10;
if ( (unsigned int)(v10 - 1) > 2 || (mallock_ngrams_count & 1) != 0 && (ngram_count[v4] & 1) != 0 )
{
t_insert(v5, v7, &hash_char, &hash_table_ngrams, v4 + 1, 48LL, &unk_1ADC1);
++mallock_ngrams_count;
++ngram_count[v4];
}
}
free_ngram_node(v7);
}
}
++v6;
}
if ( v6 <= v13 )
{
substring(v5, haystack, v6, 3LL);
goto LABEL_7;
}
LABEL_17:
if ( ngram_count[v4] )
{
if ( ++v4 != 6 )
{
v2 = v14[0];
continue;
}
}
else
{
last_ngram_index = v4 - 1;
}
break;
}
free(v5);
free(all_pos);
}

canonical_decompiled_code:
void __fastcall func6(char *haystack, int a2)
{
int v2; // er15
__int64 v4; // r12
char *v5; // rbp
unsigned int v6; // ebx
_QWORD *v7; // r15
int v8; // esi
__int64 v9; // rdi
int v10; // eax
unsigned int v11; // [rsp+Ch] [rbp-5Ch]
char *v12; // [rsp+10h] [rbp-58h]
unsigned int v13; // [rsp+18h] [rbp-50h]
int v14[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v2 = 0;
v4 = 3LL;
v5 = (char *)malloc(6uLL);
all_pos = calloc(all_pos_max, 4uLL);
v13 = a2 - 3;
while ( 2 )
{
v6 = 0;
ngram_count[v4] = 0;
v14[0] = 0;
v11 = v2 - 1;
while ( v4 != 3 )
{
if ( v6 > v11 )
goto LABEL_17;
substring(v5, haystack, *((unsigned int *)all_pos + v6), (unsigned int)v4);
LABEL_7:
if ( !t_search(v5, &hash_char, &compare_char, &hash_table_all_ngrams, 10007LL) )
{
t_insert(v5, v5, &hash_char, &hash_table_all_ngrams, v4 + 1, v4 + 1, 10007LL);
v12 = strstr(haystack, v5);
if ( v12 )
{
v7 = func2();
func3((__int64)v7, (_DWORD)v12 - (_DWORD)haystack, (unsigned int)v4, v14);
func5(v5, (__int64)v12, v4, (__int64)v7, (int)haystack, v14);
v8 = *((_DWORD *)v7 + 5);
if ( v8 > 1 )
{
v9 = v7[4];
*((_DWORD *)v7 + 6) = v4;
v10 = gcds_calc(v9, (unsigned int)(v8 - 1));
*((_DWORD *)v7 + 10) = v10;
if ( (unsigned int)(v10 - 1) > 2 || (mallock_ngrams_count & 1) != 0 && (ngram_count[v4] & 1) != 0 )
{
t_insert(v5, v7, &hash_char, &hash_table_ngrams, v4 + 1, 48LL, &unk_1ADC1);
++mallock_ngrams_count;
++ngram_count[v4];
}
}
func4(v7);
}
}
++v6;
}
if ( v6 <= v13 )
{
substring(v5, haystack, v6, 3LL);
goto LABEL_7;
}
LABEL_17:
if ( ngram_count[v4] )
{
if ( ++v4 != 6 )
{
v2 = v14[0];
continue;
}
}
else
{
last_ngram_index = v4 - 1;
}
break;
}
free(v5);
free(all_pos);
}

original_code:
void find_ngrams(const char *c_text,unsigned int c_len){
 unsigned int sub_len,i,all_pos_counter = 0, pos_counter = 0;
 char *subst = (char *)malloc((5 + 1) * sizeof(char));
 kasiski_node_t *ngram_node;
 char *start_pos;
 int pos;
 all_pos = (int *)calloc(all_pos_max,sizeof(int));
 for(sub_len = 3; sub_len <= 5; sub_len++){
  ngram_count[sub_len] = 0;
  all_pos_counter = pos_counter;
  pos_counter = 0;
  for(i = 0; i <= (sub_len == 3 ? c_len - sub_len : all_pos_counter - 1); i++){
   if(sub_len != 3){
    substring(subst,c_text,all_pos[i],sub_len);
   }else{
    substring(subst,c_text,i,sub_len);
   }
   if(t_search(subst,hash_char,compare_char,hash_table_all_ngrams,10007) != ((void *)0)){
    continue;
   }
   t_insert(subst,subst,hash_char,hash_table_all_ngrams,sizeof(char)*sub_len+1,sizeof(char)*sub_len+1,10007);
   if((start_pos = strstr(c_text,subst)) != ((void *)0)){
    pos = start_pos - c_text;
    ngram_node = create_default_ngram_node(subst);
    add_position(ngram_node,pos,sub_len,&pos_counter);
    substring_search(subst,start_pos,sub_len,ngram_node,c_text,&pos_counter);
    if(ngram_node->count >= 2){
     ngram_node->len = sub_len;
     ngram_node->gcd = gcds_calc(ngram_node->distances,ngram_node->count - 1);
     if(((ngram_node->gcd == 1 || ngram_node->gcd == 2 || ngram_node->gcd == 3) &&
       (mallock_ngrams_count % 2 == 0 || ngram_count[sub_len] % 2 == 0))){
      free_ngram_node(ngram_node);
      continue;
     }
     t_insert(subst,ngram_node,hash_char,hash_table_ngrams,sizeof(char)*sub_len+1,sizeof(kasiski_node_t),110017);
     ngram_count[sub_len]++;
     mallock_ngrams_count++;
    }
    free_ngram_node(ngram_node);
   }
  }
  if(ngram_count[sub_len] == 0){
   last_ngram_index = sub_len - 1;
   break;
  } else {
  }
 }
 free(subst);
 free(all_pos);
}

canonical_original_code:
void find_ngrams(char *c_text, unsigned int c_len){
 unsigned int sub_len; unsigned int i; unsigned int all_pos_counter = 0; unsigned int pos_counter = 0;
 char *subst = (char *)malloc((5 + 1) * sizeof(char));
 struct _kasiski_node *ngram_node;
 char *start_pos;
 int pos;
 all_pos = (int *)calloc(all_pos_max,sizeof(int));
 for(sub_len = 3; sub_len <= 5; sub_len++){
  ngram_count[sub_len] = 0;
  all_pos_counter = pos_counter;
  pos_counter = 0;
  for(i = 0; i <= (sub_len == 3 ? c_len - sub_len : all_pos_counter - 1); i++){
   if(sub_len != 3){
    substring(subst,c_text,all_pos[i],sub_len);
   }else{
    substring(subst,c_text,i,sub_len);
   }
   if(t_search(subst,hash_char,compare_char,hash_table_all_ngrams,10007) != ((void *)0)){
    continue;
   }
   t_insert(subst,subst,hash_char,hash_table_all_ngrams,sizeof(char)*sub_len+1,sizeof(char)*sub_len+1,10007);
   if((start_pos = strstr(c_text,subst)) != ((void *)0)){
    pos = start_pos - c_text;
    ngram_node = create_default_ngram_node(subst);
    add_position(ngram_node,pos,sub_len,&pos_counter);
    substring_search(subst,start_pos,sub_len,ngram_node,c_text,&pos_counter);
    if(ngram_node->count >= 2){
     ngram_node->len = sub_len;
     ngram_node->gcd = gcds_calc(ngram_node->distances,ngram_node->count - 1);
     if(((ngram_node->gcd == 1 || ngram_node->gcd == 2 || ngram_node->gcd == 3) &&
       (mallock_ngrams_count % 2 == 0 || ngram_count[sub_len] % 2 == 0))){
      free_ngram_node(ngram_node);
      continue;
     }
     t_insert(subst,ngram_node,hash_char,hash_table_ngrams,sizeof(char)*sub_len+1,sizeof(kasiski_node_t),110017);
     ngram_count[sub_len]++;
     mallock_ngrams_count++;
    }
    free_ngram_node(ngram_node);
   }
  }
  if(ngram_count[sub_len] == 0){
   last_ngram_index = sub_len - 1;
   break;
  } else {
  }
 }
 free(subst);
 free(all_pos);
}

variable_types:
i
unsigned int

variable_types:
subst
char *


original_code:
void kasisky_hashmap_to_list(hash_table_node_t *hash_table[], int hash_table_size, kasiski_node_t *res[5], int *sizes){
 unsigned int i = 0, len = 0;
 hash_table_node_t *node;
 for (i = 0; i < hash_table_size; ++i) {
  node = hash_table[i];
  if(node != ((void *)0)){
   while(node != ((void *)0)){
    len = (*((kasiski_node_t *)node->value)).len;
    res[len][sizes[len]++] = *((kasiski_node_t *)node->value);
    node = node->next;
   }
  }
 }
}

canonical_original_code:
void kasisky_hashmap_to_list(struct _hash_table_node *hash_table[], int hash_table_size, struct _kasiski_node *res[5], int *sizes){
 unsigned int i = 0; unsigned int len = 0;
 struct _hash_table_node *node;
 for (i = 0; i < hash_table_size; ++i) {
  node = hash_table[i];
  if(node != ((void *)0)){
   while(node != ((void *)0)){
    len = (*((struct _kasiski_node *)node->value)).len;
    res[len][sizes[len]++] = *((struct _kasiski_node *)node->value);
    node = node->next;
   }
  }
 }
}

variable_types: struct _hash_table_node { struct _hash_table_node *next; void *key; void *value; } *[]

variable_types: struct _kasiski_node { struct _kasiski_node *next; int *positions; unsigned int _ngram_max_pos; int count; unsigned int len; int *distances; int gcd; } *[5]

variable_types:
sizes
int *

variable_types:
len
unsigned int


original_code:
hash_table_node_t *gcdcount_hashmap_to_list(hash_table_node_t *hash_table[],int size){
 unsigned int i = 0,j = 0;
 hash_table_node_t *node,*result;
 result = (hash_table_node_t *)malloc(sizeof(hash_table_node_t) * size);
 for (i = 0; i < 5351; ++i) {
  node = hash_table[i];
  if(node != ((void *)0)){
   while(node != ((void *)0)){
    result[j++] = *node;
    node = node->next;
   }
  }
 }
 return result;
}

canonical_original_code:
struct _hash_table_node *gcdcount_hashmap_to_list(struct _hash_table_node *hash_table[], int size){
 unsigned int i = 0; unsigned int j = 0;
 struct _hash_table_node *node; struct _hash_table_node *result;
 result = (struct _hash_table_node *)malloc(sizeof(hash_table_node_t) * size);
 for (i = 0; i < 5351; ++i) {
  node = hash_table[i];
  if(node != ((void *)0)){
   while(node != ((void *)0)){
    result[j++] = *node;
    node = node->next;
   }
  }
 }
 return result;
}

variable_types: size int

variable_types:
j
unsigned int

variable_types: struct _hash_table_node { struct _hash_table_node *next; void *key; void *value; } *


decompiled_code:
_QWORD *process_ngrams()
{
void **v0; // rax
int v1; // ebp
void **v2; // r14
__int64 v3; // rbx
void **v4; // rbp
int v5; // er13
int v6; // er12
int *v7; // rbx
__int64 v8; // r15
_DWORD *v9; // rdi
int v10; // eax
__int64 v11; // rax
size_t v12; // rbp
int v13; // er12
char *v14; // rbx
_QWORD *result; // rax
_QWORD *v16; // [rsp+0h] [rbp-58h]
int *ptr; // [rsp+8h] [rbp-50h]
int v18; // [rsp+18h] [rbp-40h] BYREF
int v19[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v16 = malloc(0x10uLL);
v0 = (void **)malloc(0x30uLL);
v1 = last_ngram_index;
v2 = v0;
if ( last_ngram_index <= 2 )
{
v13 = 0;
v12 = 0LL;
v5 = 0;
ptr = (int *)calloc(7uLL, 4uLL);
kasisky_hashmap_to_list(hash_table_ngrams, (int)&unk_1ADC1, (__int64)v2, (__int64)ptr);
goto LABEL_16;
}
v3 = 3LL;
do
{
v2[v3] = malloc(48LL * ngram_count[v3]);
++v3;
}
while ( v1 >= (int)v3 );
v4 = v2 + 3;
v5 = 0;
ptr = (int *)calloc(7uLL, 4uLL);
v6 = 3;
kasisky_hashmap_to_list(hash_table_ngrams, (int)&unk_1ADC1, (__int64)v2, (__int64)ptr);
v7 = ptr + 3;
do
{
v8 = 0LL;
qsort(*v4, *v7, 0x30uLL, (__compar_fn_t)q_compare_ngram);
v9 = *v4;
while ( 1 )
{
v10 = v9[12 * v8 + 10];
v18 = v10;
if ( *v7 == (_DWORD)v8 || v10 <= 0 )
break;
if ( v10 == 1 && *(double *)&friedman_result > 1.5 )
goto LABEL_7;
v11 = t_search(&v18, &hash_int, &compare_int, &hash_table_gcd_count, 5351LL);
if ( v11 )
{
v9 = *v4;
++**(_DWORD **)(v11 + 16);
LABEL_7:
if ( ++v8 == 30 )
break;
}
else
{
v19[0] = 1;
++v8;
++v5;
t_insert(&v18, v19, &hash_int, &hash_table_gcd_count, 4LL, 4LL, 5351LL);
v9 = *v4;
if ( v8 == 30 )
break;
}
}
free(v9);
++v6;
++v7;
++v4;
}
while ( last_ngram_index >= v6 );
v12 = v5;
v13 = v5;
LABEL_16:
free(ptr);
free(v2);
v14 = gcdcount_hashmap_to_list((const __m128i **)&hash_table_gcd_count, v5);
qsort(v14, v12, 0x18uLL, (__compar_fn_t)q_compare_gcd);
result = v16;
*(_DWORD *)v16 = v13;
v16[1] = v14;
return result;
}

canonical_decompiled_code:
_QWORD *func9()
{
void **v0; // rax
int v1; // ebp
void **v2; // r14
__int64 v3; // rbx
void **v4; // rbp
int v5; // er13
int v6; // er12
int *v7; // rbx
__int64 v8; // r15
_DWORD *v9; // rdi
int v10; // eax
__int64 v11; // rax
size_t v12; // rbp
int v13; // er12
char *v14; // rbx
_QWORD *result; // rax
_QWORD *v16; // [rsp+0h] [rbp-58h]
int *ptr; // [rsp+8h] [rbp-50h]
int v18; // [rsp+18h] [rbp-40h] BYREF
int v19[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v16 = malloc(0x10uLL);
v0 = (void **)malloc(0x30uLL);
v1 = last_ngram_index;
v2 = v0;
if ( last_ngram_index <= 2 )
{
v13 = 0;
v12 = 0LL;
v5 = 0;
ptr = (int *)calloc(7uLL, 4uLL);
func7(hash_table_ngrams, (int)&unk_1ADC1, (__int64)v2, (__int64)ptr);
goto LABEL_16;
}
v3 = 3LL;
do
{
v2[v3] = malloc(48LL * ngram_count[v3]);
++v3;
}
while ( v1 >= (int)v3 );
v4 = v2 + 3;
v5 = 0;
ptr = (int *)calloc(7uLL, 4uLL);
v6 = 3;
func7(hash_table_ngrams, (int)&unk_1ADC1, (__int64)v2, (__int64)ptr);
v7 = ptr + 3;
do
{
v8 = 0LL;
qsort(*v4, *v7, 0x30uLL, (__compar_fn_t)q_compare_ngram);
v9 = *v4;
while ( 1 )
{
v10 = v9[12 * v8 + 10];
v18 = v10;
if ( *v7 == (_DWORD)v8 || v10 <= 0 )
break;
if ( v10 == 1 && *(double *)&friedman_result > 1.5 )
goto LABEL_7;
v11 = t_search(&v18, &hash_int, &compare_int, &hash_table_gcd_count, 5351LL);
if ( v11 )
{
v9 = *v4;
++**(_DWORD **)(v11 + 16);
LABEL_7:
if ( ++v8 == 30 )
break;
}
else
{
v19[0] = 1;
++v8;
++v5;
t_insert(&v18, v19, &hash_int, &hash_table_gcd_count, 4LL, 4LL, 5351LL);
v9 = *v4;
if ( v8 == 30 )
break;
}
}
free(v9);
++v6;
++v7;
++v4;
}
while ( last_ngram_index >= v6 );
v12 = v5;
v13 = v5;
LABEL_16:
free(ptr);
free(v2);
v14 = func8((const __m128i **)&hash_table_gcd_count, v5);
qsort(v14, v12, 0x18uLL, (__compar_fn_t)q_compare_gcd);
result = v16;
*(_DWORD *)v16 = v13;
v16[1] = v14;
return result;
}

original_code:
kasiski_thread_result_t *process_ngrams(){
 int i, j;
 int *sizes;
 kasiski_node_t **res_list;
 hash_table_node_t *gcd_node,*values;
 int node_gcd, node_len = 0;
 kasiski_thread_result_t *result = (kasiski_thread_result_t *)malloc(sizeof(kasiski_thread_result_t));
 res_list = (kasiski_node_t **)malloc((5 + 1) * sizeof(kasiski_node_t *));
 for (i = 3; i <= last_ngram_index; ++i) {
  res_list[i] = (kasiski_node_t *)malloc(ngram_count[i] * sizeof(kasiski_node_t));
 }
 sizes = (int *)calloc(5 +2, sizeof(int));
 kasisky_hashmap_to_list(hash_table_ngrams,110017,res_list,sizes);
 for (i = 3; i <= last_ngram_index; ++i) {
  qsort(res_list[i],sizes[i],sizeof(kasiski_node_t),q_compare_ngram);
  for (j = 0; j < 30; ++j) {
   node_gcd = (res_list[i][j]).gcd;
   if(j == sizes[i] || node_gcd < 1){
    break;
   }
   if((node_gcd == 1 && friedman_result > 1.5)) continue;
   if((gcd_node = t_search(&node_gcd,hash_int,compare_int,hash_table_gcd_count,5351)) != ((void *)0)){
    (*((int *)gcd_node->value))++;
   }else{
    int node_value = 1;
    t_insert(&node_gcd,&node_value,hash_int,hash_table_gcd_count,sizeof(int),sizeof(int),5351);
    node_len++;
   }
  }
  free(res_list[i]);
 }
 free(sizes);
 free(res_list);
 values = gcdcount_hashmap_to_list(hash_table_gcd_count,node_len);
 qsort(values,node_len,sizeof(hash_table_node_t),q_compare_gcd);
 result->len = node_len;
 result->values = values;
 return result;
}

canonical_original_code:
struct _thread_result *process_ngrams(){
 int i; int j;
 int *sizes;
 struct _kasiski_node **res_list;
 struct _hash_table_node *gcd_node; struct _hash_table_node *values;
 int node_gcd; int node_len = 0;
 struct _thread_result *result = (kasiski_thread_result_t *)malloc(sizeof(kasiski_thread_result_t));
 res_list = (struct _kasiski_node **)malloc((5 + 1) * sizeof(struct _kasiski_node *));
 for (i = 3; i <= last_ngram_index; ++i) {
  res_list[i] = (struct _kasiski_node *)malloc(ngram_count[i] * sizeof(kasiski_node_t));
 }
 sizes = (int *)calloc(5 +2, sizeof(int));
 kasisky_hashmap_to_list(hash_table_ngrams,110017,res_list,sizes);
 for (i = 3; i <= last_ngram_index; ++i) {
  qsort(res_list[i],sizes[i],sizeof(kasiski_node_t),q_compare_ngram);
  for (j = 0; j < 30; ++j) {
   node_gcd = (res_list[i][j]).gcd;
   if(j == sizes[i] || node_gcd < 1){
    break;
   }
   if((node_gcd == 1 && friedman_result > 1.5)) continue;
   if((gcd_node = t_search(&node_gcd,hash_int,compare_int,hash_table_gcd_count,5351)) != ((void *)0)){
    (*((int *)gcd_node->value))++;
   }else{
    int node_value = 1;
    t_insert(&node_gcd,&node_value,hash_int,hash_table_gcd_count,sizeof(int),sizeof(int),5351);
    node_len++;
   }
  }
  free(res_list[i]);
 }
 free(sizes);
 free(res_list);
 values = gcdcount_hashmap_to_list(hash_table_gcd_count,node_len);
 qsort(values,node_len,sizeof(hash_table_node_t),q_compare_gcd);
 result->len = node_len;
 result->values = values;
 return result;
}

variable_types: i int

variable_types: j int

variable_types: struct _kasiski_node { struct _kasiski_node *next; int *positions; unsigned int _ngram_max_pos; int count; unsigned int len; int *distances; int gcd; } **

variable_types: struct _thread_result { unsigned int len; struct _hash_table_node { struct _hash_table_node *next; void *key; void *value; } *values; } *

user_defined_types: struct _thread_result { unsigned int len; struct _hash_table_node *values; }


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

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

original_code:
int q_compare_int(const void * a, const void * b){
 return ( *(int*)a - *(int*)b );
}

canonical_original_code:
int q_compare_int(void *a, void *b){
 return ( *(int *)a - *(int *)b );
}

variable_types:
a
void *

variable_types:
b
void *


original_code:
void free_hash_table(hash_table_node_t *hash_table[], int hash_table_size){
 unsigned int i = 0;
 hash_table_node_t *node,*old;
 for (i = 0; i < hash_table_size; ++i) {
  node = hash_table[i];
  if(node != ((void *)0)){
   while(node != ((void *)0)){
    free(node->key);
    free(node->value);
    old = node;
    node = old->next;
    free(old);
   }
  }
 }
}

canonical_original_code:
void free_hash_table(struct _hash_table_node *hash_table[], int hash_table_size){
 unsigned int i = 0;
 struct _hash_table_node *node; struct _hash_table_node *old;
 for (i = 0; i < hash_table_size; ++i) {
  node = hash_table[i];
  if(node != ((void *)0)){
   while(node != ((void *)0)){
    free(node->key);
    free(node->value);
    old = node;
    node = old->next;
    free(old);
   }
  }
 }
}

user_defined_types: struct _hash_table_node { struct _hash_table_node *next; void *key; void *value; }


decompiled_code:
double *__fastcall friedman_test(char *s)
{
double *v1; // r12
int v2; // eax

v1 = (double *)malloc(8uLL);
v2 = strlen(s);
*v1 = 0.0;
if ( (double)v2 >= 1.0 )
*v1 = 0.0265 / (COERCE_DOUBLE(index_of_coincidence((__int64)s, (double)v2, 0.0)) - 0.0385);
return v1;
}

canonical_decompiled_code:
double *__fastcall func0(char *s)
{
double *v1; // r12
int v2; // eax

v1 = (double *)malloc(8uLL);
v2 = strlen(s);
*v1 = 0.0;
if ( (double)v2 >= 1.0 )
*v1 = 0.0265 / (COERCE_DOUBLE(index_of_coincidence((__int64)s, (double)v2, 0.0)) - 0.0385);
return v1;
}

original_code:
void *friedman_test(void *ptr){
 char *c_text_s = ptr;
 double *friedman = (double *)malloc(sizeof(double));
 double k0 = 0.0, kp = 0.065, kr = 0.0385;
 double len = strlen(c_text_s);
 *friedman = 0.0;
 if(len < 1) return friedman;
 k0 = index_of_coincidence(c_text_s,len,0);
 *friedman = (kp - kr)/(k0 - kr);
 return friedman;
}

canonical_original_code:
void *friedman_test(void *ptr){
 char *c_text_s = ptr;
 double *friedman = (double *)malloc(sizeof(double));
 double k0 = 0.0; double kp = 0.065; double kr = 0.0385;
 double len = strlen(c_text_s);
 *friedman = 0.0;
 if(len < 1) return friedman;
 k0 = index_of_coincidence(c_text_s,len,0);
 *friedman = (kp - kr)/(k0 - kr);
 return friedman;
}

variable_types:
ptr
void *

variable_types:
friedman
double *

variable_types: kp double

variable_types: kr double

variable_types: len double

return_type: void *


original_code:
int ic_passwd_len(char *string, double len, double friedman, kasiski_thread_result_t *m_numbers){
 char **ics = (char **)malloc(1000 * sizeof(char *));
 unsigned long k, l = 0, m = 0;
 double diff_sum = 0.0, ic_min = 100, diff_avg, kasiski = 0.0,kas_diff;
 unsigned int result_m = 1,kasiski_key;
 if( m_numbers->len < 1){
  return 0;
 }
 kasiski_key = *((int*)m_numbers->values[0].key);
 for (l = 0; l < m_numbers->len; ++l) {
  m = *((int *)m_numbers->values[l].key);
  ics = text_to_columns(m,string,len,ics);
  diff_sum = 0;
  for (k = 0; k < m; ++k) {
   diff_sum += fabs(index_of_coincidence(ics[k],strlen(ics[k]),0.067));
   free(ics[k]);
  }
  diff_avg = diff_sum/m;
  if(diff_avg < ic_min){
   ic_min = diff_avg;
   result_m = m;
  }
  if(kasiski_key == m){
   kasiski = diff_avg;
  }
 }
 kas_diff = fabs(kasiski-ic_min);
 if(kas_diff <= 0.000040){
  result_m = kasiski_key;
 }
 if(ics != ((void *)0)) free(ics);
 return result_m;
}

canonical_original_code:
int ic_passwd_len(char *string, double len, double friedman, struct _thread_result *m_numbers){
 char **ics = (char **)malloc(1000 * sizeof(char *));
 unsigned long k; unsigned long l = 0; unsigned long m = 0;
 double diff_sum = 0.0; double ic_min = 100; double diff_avg; double kasiski = 0.0; double kas_diff;
 unsigned int result_m = 1; unsigned int kasiski_key;
 if( m_numbers->len < 1){
  return 0;
 }
 kasiski_key = *((int *)m_numbers->values[0].key);
 for (l = 0; l < m_numbers->len; ++l) {
  m = *((int *)m_numbers->values[l].key);
  ics = text_to_columns(m,string,len,ics);
  diff_sum = 0;
  for (k = 0; k < m; ++k) {
   diff_sum += fabs(index_of_coincidence(ics[k],strlen(ics[k]),0.067));
   free(ics[k]);
  }
  diff_avg = diff_sum/m;
  if(diff_avg < ic_min){
   ic_min = diff_avg;
   result_m = m;
  }
  if(kasiski_key == m){
   kasiski = diff_avg;
  }
 }
 kas_diff = fabs(kasiski-ic_min);
 if(kas_diff <= 0.000040){
  result_m = kasiski_key;
 }
 if(ics != ((void *)0)) free(ics);
 return result_m;
}

variable_types:
string
char *

variable_types: friedman double

variable_types:
ics
char **

variable_types:
k
unsigned long

variable_types:
l
unsigned long

variable_types:
m
unsigned long

variable_types: kasiski double


appMouse

repo: uOptim/pmg-enseirb

decompiled_code:
__int64 __fastcall appMouse(char a1, int a2, int a3, unsigned int a4)
{
__int64 result; // rax

result = a4;
if ( !a2 )
{
mouse_buttons |= 1 << a1;
LABEL_3:
mouse_old_x = a3;
mouse_old_y = a4;
return result;
}
if ( a2 != 1 )
goto LABEL_3;
mouse_buttons = 0;
mouse_old_x = a3;
mouse_old_y = a4;
return result;
}

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

result = a4;
if ( !a2 )
{
mouse_buttons |= 1 << a1;
LABEL_3:
mouse_old_x = a3;
mouse_old_y = a4;
return result;
}
if ( a2 != 1 )
goto LABEL_3;
mouse_buttons = 0;
mouse_old_x = a3;
mouse_old_y = a4;
return result;
}

original_code:
void appMouse(int button, int state, int x, int y)
{
 if (state == 0x0000) {
  mouse_buttons |= 1<<button;
 } else if (state == 0x0001) {
  mouse_buttons = 0;
 }
 mouse_old_x = x;
 mouse_old_y = y;
}

variable_types: button int

variable_types: state int

variable_types: x int

variable_types: y int


reshape

decompiled_code:
__int64 __fastcall reshape(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
*(double *)&aspect = (float)((float)a1 / (float)a2);
glMatrixMode(5889LL);
glLoadIdentity();
gluPerspective(*(double *)&fovy, *(double *)&aspect, *(double *)&near_clip, *(double *)&far_clip);
return glMatrixMode(5888LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
*(double *)&aspect = (float)((float)a1 / (float)a2);
glMatrixMode(5889LL);
glLoadIdentity();
gluPerspective(*(double *)&fovy, *(double *)&aspect, *(double *)&near_clip, *(double *)&far_clip);
return glMatrixMode(5888LL);
}

original_code:
void reshape (int w, int h) {
 glViewport(0, 0, (GLsizei)w, (GLsizei)h);
 aspect = w/(float)h;
 glMatrixMode(0x1701);
 glLoadIdentity();
 gluPerspective(fovy,aspect,near_clip,far_clip);
 glMatrixMode(0x1700);
}

canonical_original_code:
void reshape(int w, int h) {
 glViewport(0, 0, (int)w, (int)h);
 aspect = w/(float)h;
 glMatrixMode(0x1701);
 glLoadIdentity();
 gluPerspective(fovy,aspect,near_clip,far_clip);
 glMatrixMode(0x1700);
}

variable_types: w int

variable_types: h int


idle

decompiled_code:
__int64 idle()
{
animateGPU();
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func2()
{
animateGPU();
return glutPostRedisplay();
}

original_code:
void idle(void)
{
 animateGPU();
 glutPostRedisplay();
}

canonical_original_code:
void idle()
{
 animateGPU();
 glutPostRedisplay();
}


appMotion

decompiled_code:
__int64 __fastcall appMotion(int a1, int a2)
{
float v2; // xmm0_4
int v3; // xmm0_4
int v4; // xmm0_4
int v6; // xmm0_4

v2 = (float)(a2 - mouse_old_y);
if ( (mouse_buttons & 1) != 0 )
{
*(float *)&v3 = v2 * 0.2 + *(float *)&rotate_x;
rotate_x = v3;
*(float *)&v4 = (float)(a1 - mouse_old_x) * 0.2 + *(float *)&rotate_y;
rotate_y = v4;
}
else if ( (mouse_buttons & 4) != 0 )
{
*(float *)&v6 = v2 * 0.1 + *(float *)&translate_z;
translate_z = v6;
}
mouse_old_x = a1;
mouse_old_y = a2;
true_redisplay = 1;
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
float v2; // xmm0_4
int v3; // xmm0_4
int v4; // xmm0_4
int v6; // xmm0_4

v2 = (float)(a2 - mouse_old_y);
if ( (mouse_buttons & 1) != 0 )
{
*(float *)&v3 = v2 * 0.2 + *(float *)&rotate_x;
rotate_x = v3;
*(float *)&v4 = (float)(a1 - mouse_old_x) * 0.2 + *(float *)&rotate_y;
rotate_y = v4;
}
else if ( (mouse_buttons & 4) != 0 )
{
*(float *)&v6 = v2 * 0.1 + *(float *)&translate_z;
translate_z = v6;
}
mouse_old_x = a1;
mouse_old_y = a2;
true_redisplay = 1;
return glutPostRedisplay();
}

original_code:
void appMotion(int x, int y)
{
 float dx, dy;
 dx = x - mouse_old_x;
 dy = y - mouse_old_y;
 if (mouse_buttons & 1) {
  rotate_x += dy * 0.2;
  rotate_y += dx * 0.2;
 } else if (mouse_buttons & 4) {
  translate_z += dy * 0.1;
 }
 mouse_old_x = x;
 mouse_old_y = y;
 true_redisplay = 1;
 glutPostRedisplay();
}

canonical_original_code:
void appMotion(int x, int y)
{
 float dx; float dy;
 dx = x - mouse_old_x;
 dy = y - mouse_old_y;
 if (mouse_buttons & 1) {
  rotate_x += dy * 0.2;
  rotate_y += dx * 0.2;
 } else if (mouse_buttons & 4) {
  translate_z += dy * 0.1;
 }
 mouse_old_x = x;
 mouse_old_y = y;
 true_redisplay = 1;
 glutPostRedisplay();
}

variable_types: dx float

variable_types: dy float


timer

decompiled_code:
__int64 __fastcall timer(unsigned int a1)
{
animateGPU();
glutPostRedisplay();
return glutTimerFunc(TIMER_VAL, timer, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
animateGPU();
glutPostRedisplay();
return glutTimerFunc(TIMER_VAL, timer, a1);
}

original_code:
void timer(int arg)
{
 animateGPU();
 glutPostRedisplay();
 glutTimerFunc(TIMER_VAL, timer, arg) ;
}

variable_types: arg int


drawScene

decompiled_code:
__int64 __fastcall drawScene(__int64 a1)
{
if ( true_redisplay )
{
glLoadIdentity();
gluLookAt(
*(float *)&eye,
*((float *)&eye + 1),
*((float *)&eye + 2),
*(float *)&center,
*((float *)&center + 1),
*((float *)&center + 2),
*(float *)&up,
*((float *)&up + 1),
a1);
glTranslatef(0.0, 0.0, *(float *)&translate_z);
glTranslatef(
COERCE_DOUBLE((unsigned __int64)(unsigned int)center),
COERCE_DOUBLE((unsigned __int64)HIDWORD(center)),
*((float *)&center + 2));
glRotatef(*(float *)&rotate_x, 1.0, 0.0);
glRotatef(*(float *)&rotate_y, 0.0, COERCE_DOUBLE((unsigned __int64)LC3));
glTranslatef(
COERCE_DOUBLE((unsigned int)center ^ (unsigned __int64)(unsigned int)LC4),
COERCE_DOUBLE(HIDWORD(center) ^ (unsigned __int64)(unsigned int)LC4),
COERCE_FLOAT(*((_DWORD *)&center + 2) ^ LC4));
true_redisplay = 0;
}
renderAtoms();
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glBegin(6LL);
glColor4f(0.60000002, 0.60000002, 1.0, 0.40000001);
glVertex3f(*(float *)&center, min_ext[1], *((float *)&center + 2));
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], max_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(max_ext[0], min_ext[1], max_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(max_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( true_redisplay )
{
glLoadIdentity();
gluLookAt(
*(float *)&eye,
*((float *)&eye + 1),
*((float *)&eye + 2),
*(float *)&center,
*((float *)&center + 1),
*((float *)&center + 2),
*(float *)&up,
*((float *)&up + 1),
a1);
glTranslatef(0.0, 0.0, *(float *)&translate_z);
glTranslatef(
COERCE_DOUBLE((unsigned __int64)(unsigned int)center),
COERCE_DOUBLE((unsigned __int64)HIDWORD(center)),
*((float *)&center + 2));
glRotatef(*(float *)&rotate_x, 1.0, 0.0);
glRotatef(*(float *)&rotate_y, 0.0, COERCE_DOUBLE((unsigned __int64)LC3));
glTranslatef(
COERCE_DOUBLE((unsigned int)center ^ (unsigned __int64)(unsigned int)LC4),
COERCE_DOUBLE(HIDWORD(center) ^ (unsigned __int64)(unsigned int)LC4),
COERCE_FLOAT(*((_DWORD *)&center + 2) ^ LC4));
true_redisplay = 0;
}
renderAtoms();
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glBegin(6LL);
glColor4f(0.60000002, 0.60000002, 1.0, 0.40000001);
glVertex3f(*(float *)&center, min_ext[1], *((float *)&center + 2));
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], max_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(max_ext[0], min_ext[1], max_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(max_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
return glEnd();
}

original_code:
void drawScene() {
 if(true_redisplay) {
  glLoadIdentity();
  gluLookAt(
    (GLdouble)eye[0],(GLdouble)eye[1],(GLdouble)eye[2],
    (GLdouble)center[0],(GLdouble)center[1],(GLdouble)center[2],
    (GLdouble)up[0],(GLdouble)up[1],(GLdouble)up[2]);
  glTranslatef(0.0, 0.0, translate_z);
  glTranslatef(center[0], center[1], center[2]);
  glRotatef(rotate_x, 1.0, 0.0, 0.0);
  glRotatef(rotate_y, 0.0, 1.0, 0.0);
  glTranslatef(-center[0], -center[1], -center[2]);
  true_redisplay = 0;
 }
 renderAtoms();
 glEnable (0x0BE2);
 glBlendFunc (0x0302, 0x0303);
 glBegin(0x0006);
 glColor4f(.6f, 0.6f, 1.0f, 0.4f);
 glVertex3f(center[0], min_ext[1], center[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], max_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(max_ext[0], min_ext[1], max_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(max_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glEnd();
}

canonical_original_code:
void drawScene() {
 if(true_redisplay) {
  glLoadIdentity();
  gluLookAt(
    (double)eye[0],(double)eye[1],(double)eye[2],
    (double)center[0],(double)center[1],(double)center[2],
    (double)up[0],(double)up[1],(double)up[2]);
  glTranslatef(0.0, 0.0, translate_z);
  glTranslatef(center[0], center[1], center[2]);
  glRotatef(rotate_x, 1.0, 0.0, 0.0);
  glRotatef(rotate_y, 0.0, 1.0, 0.0);
  glTranslatef(-center[0], -center[1], -center[2]);
  true_redisplay = 0;
 }
 renderAtoms();
 glEnable (0x0BE2);
 glBlendFunc (0x0302, 0x0303);
 glBegin(0x0006);
 glColor4f(.6f, 0.6f, 1.0f, 0.4f);
 glVertex3f(center[0], min_ext[1], center[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], max_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(max_ext[0], min_ext[1], max_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(max_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glEnd();
}


display

decompiled_code:
__int64 display()
{
glClear(16640LL);
drawScene(16640LL);
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func6()
{
glClear(16640LL);
func5(16640LL);
return glutSwapBuffers();
}

original_code:
void display()
{
 glClear(0x00004000|0x00000100);
 drawScene();
 glutSwapBuffers();
}


initView

original_code:
void initView (float *min_ext, float *max_ext)
{
 GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
 GLfloat light_position1[] = {0.5, 0.5, 1.0, 0.0};
 float dif_ext[3];
 int i;
 glLightfv(0x4000, 0x1201, light_diffuse);
 glLightfv(0x4000, 0x1203, light_position1);
 glEnable(0x0B50);
 glEnable(0x4000);
 glEnable(0x0B71);
 for (i=0; i<3; i++)
  dif_ext[i] = max_ext[i] - min_ext[i];
 dis = 0.0;
 for (i=0; i<3; i++)
  dis += dif_ext[i]*dif_ext[i];
 dis = (float)sqrt((double)dis);
 for (i=0; i<3; i++)
  center[i] = min_ext[i] + dif_ext[i]/2.0;
 eye[0] = center[0];
 eye[1] = center[1];
 eye[2] = center[2] + dis;
 up[0] = 0.0;
 up[1] = 1.0;
 up[2] = 0.0;
 near_clip = (GLdouble)( 0.5*(dis-0.5*dif_ext[2]) );
 far_clip = (GLdouble)( 2.0*(dis+0.5*dif_ext[2]) );
 fovy = (GLdouble)( 0.5*dif_ext[1]/(dis-0.5*dif_ext[2]) );
 fovy = (GLdouble)( 2*atan((double)fovy)/3.14159265358979323846*180.0 );
 fovy = (GLdouble)(1.2*fovy);
 glEnable(0x0B57);
}

canonical_original_code:
void initView(float *min_ext, float *max_ext)
{
 float light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
 float light_position1[] = {0.5, 0.5, 1.0, 0.0};
 float dif_ext[3];
 int i;
 glLightfv(0x4000, 0x1201, light_diffuse);
 glLightfv(0x4000, 0x1203, light_position1);
 glEnable(0x0B50);
 glEnable(0x4000);
 glEnable(0x0B71);
 for (i=0; i<3; i++)
  dif_ext[i] = max_ext[i] - min_ext[i];
 dis = 0.0;
 for (i=0; i<3; i++)
  dis += dif_ext[i]*dif_ext[i];
 dis = (float)sqrt((double)dis);
 for (i=0; i<3; i++)
  center[i] = min_ext[i] + dif_ext[i]/2.0;
 eye[0] = center[0];
 eye[1] = center[1];
 eye[2] = center[2] + dis;
 up[0] = 0.0;
 up[1] = 1.0;
 up[2] = 0.0;
 near_clip = (GLdouble)( 0.5*(dis-0.5*dif_ext[2]) );
 far_clip = (GLdouble)( 2.0*(dis+0.5*dif_ext[2]) );
 fovy = (GLdouble)( 0.5*dif_ext[1]/(dis-0.5*dif_ext[2]) );
 fovy = (GLdouble)( 2*atan((double)fovy)/3.14159265358979323846*180.0 );
 fovy = (GLdouble)(1.2*fovy);
 glEnable(0x0B57);
}

variable_types: i int


appDestroy

decompiled_code:
void __noreturn appDestroy()
{
atomFinalize();
ocl_finalize();
vboFinalize();
if ( glutWindowHandle )
glutDestroyWindow();
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
atomFinalize();
ocl_finalize();
vboFinalize();
if ( glutWindowHandle )
glutDestroyWindow();
exit(0);
}

original_code:
void appDestroy()
{
 atomFinalize();
 ocl_finalize();
 vboFinalize();
 if(glutWindowHandle)
  glutDestroyWindow(glutWindowHandle);
 exit(0);
}


decompiled_code:
__int64 __fastcall change_skin(unsigned int a1)
{
ocl_readAtomCoordinatesFromAccel();
clearVBO();
setAtomsSkin(a1);
buildAtoms();
updateAtomCoordinatesToAccel();
resetAnimation();
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
ocl_readAtomCoordinatesFromAccel();
clearVBO();
setAtomsSkin(a1);
buildAtoms();
updateAtomCoordinatesToAccel();
resetAnimation();
return glutPostRedisplay();
}

original_code:
void change_skin(atom_skin_t skin)
{
 ocl_readAtomCoordinatesFromAccel();
 clearVBO();
 setAtomsSkin(skin);
 buildAtoms();
 updateAtomCoordinatesToAccel();
 resetAnimation();
 glutPostRedisplay();
}

canonical_original_code:
void change_skin(enum atom_skin_t skin)
{
 ocl_readAtomCoordinatesFromAccel();
 clearVBO();
 setAtomsSkin(skin);
 buildAtoms();
 updateAtomCoordinatesToAccel();
 resetAnimation();
 glutPostRedisplay();
}

variable_types: enum atom_skin_t { SPHERE_SKIN=0, PACMAN_SKIN=1 }


appKeyboard

decompiled_code:
int __fastcall appKeyboard(char a1)
{
__int64 v1; // rdi
int result; // eax
unsigned __int64 v3; // rdx
int v4; // xmm0_4
int v5; // xmm0_4

v1 = (unsigned __int8)(a1 - 13);
switch ( (char)v1 )
{
case 0:
case 14:
case 68:
case 100:
appDestroy(v1);
return result;
case 30:
result = -858993459 * TIMER_VAL;
TIMER_VAL -= TIMER_VAL / 0xAuLL;
break;
case 32:
v3 = 1LL;
if ( TIMER_VAL > 9uLL )
{
result = -858993459 * TIMER_VAL;
v3 = TIMER_VAL / 0xAuLL;
}
TIMER_VAL += v3;
break;
case 47:
true_redisplay = 1;
*(float *)&v4 = *(float *)&translate_z - 0.1;
translate_z = v4;
result = glutPostRedisplay();
break;
case 49:
true_redisplay = 1;
*(float *)&v5 = *(float *)&translate_z + 0.1;
translate_z = v5;
result = glutPostRedisplay();
break;
case 54:
case 86:
detect_collision = 1 - detect_collision;
result = printf("collision detect: %d\n", detect_collision);
break;
case 56:
case 88:
eating_enabled = 1 - eating_enabled;
result = printf("eating mode: %d\n", eating_enabled);
break;
case 57:
case 89:
force_enabled = 1 - force_enabled;
result = printf("force: %d\n", force_enabled);
break;
case 58:
case 90:
gravity_enabled = 1 - gravity_enabled;
result = printf("gravity: %d\n", gravity_enabled);
break;
case 64:
case 96:
move_enabled = 1 - move_enabled;
result = printf("move: %d\n", move_enabled);
break;
case 65:
case 97:
result = change_skin(0);
break;
case 67:
case 99:
result = change_skin(1u);
break;
case 77:
case 109:
result = zeroSpeeds();
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char a1)
{
__int64 v1; // rdi
int result; // eax
unsigned __int64 v3; // rdx
int v4; // xmm0_4
int v5; // xmm0_4

v1 = (unsigned __int8)(a1 - 13);
switch ( (char)v1 )
{
case 0:
case 14:
case 68:
case 100:
func8(v1);
return result;
case 30:
result = -858993459 * TIMER_VAL;
TIMER_VAL -= TIMER_VAL / 0xAuLL;
break;
case 32:
v3 = 1LL;
if ( TIMER_VAL > 9uLL )
{
result = -858993459 * TIMER_VAL;
v3 = TIMER_VAL / 0xAuLL;
}
TIMER_VAL += v3;
break;
case 47:
true_redisplay = 1;
*(float *)&v4 = *(float *)&translate_z - 0.1;
translate_z = v4;
result = glutPostRedisplay();
break;
case 49:
true_redisplay = 1;
*(float *)&v5 = *(float *)&translate_z + 0.1;
translate_z = v5;
result = glutPostRedisplay();
break;
case 54:
case 86:
detect_collision = 1 - detect_collision;
result = printf("collision detect: %d\n", detect_collision);
break;
case 56:
case 88:
eating_enabled = 1 - eating_enabled;
result = printf("eating mode: %d\n", eating_enabled);
break;
case 57:
case 89:
force_enabled = 1 - force_enabled;
result = printf("force: %d\n", force_enabled);
break;
case 58:
case 90:
gravity_enabled = 1 - gravity_enabled;
result = printf("gravity: %d\n", gravity_enabled);
break;
case 64:
case 96:
move_enabled = 1 - move_enabled;
result = printf("move: %d\n", move_enabled);
break;
case 65:
case 97:
result = func9(0);
break;
case 67:
case 99:
result = func9(1u);
break;
case 77:
case 109:
result = zeroSpeeds();
break;
default:
return result;
}
return result;
}

original_code:
void appKeyboard(unsigned char key, int x, int y)
{
 switch(key)
 {
  case '<' : translate_z -= 0.1; true_redisplay = 1; glutPostRedisplay(); break;
  case '>' : translate_z += 0.1; true_redisplay = 1; glutPostRedisplay(); break;
  case '+' : TIMER_VAL = TIMER_VAL - TIMER_VAL/10; break;
  case '-' : TIMER_VAL = TIMER_VAL + (TIMER_VAL/10 ? : 1); break;
  case 'e' :
  case 'E' : eating_enabled = 1 - eating_enabled;
       printf("eating mode: %d\n", eating_enabled); break;
  case 'n' :
  case 'N' : change_skin(SPHERE_SKIN); break;
  case 'p' :
  case 'P' : change_skin(PACMAN_SKIN); break;
  case 'z' :
  case 'Z' : zeroSpeeds(); break;
  case 'm' :
  case 'M' : move_enabled = 1 - move_enabled;
       printf("move: %d\n", move_enabled); break;
  case 'f' :
  case 'F' : force_enabled = 1 - force_enabled;
       printf("force: %d\n", force_enabled); break;
  case 'g' :
  case 'G' : gravity_enabled = 1 - gravity_enabled;
       printf("gravity: %d\n", gravity_enabled); break;
  case 'c' :
  case 'C' : detect_collision = 1 - detect_collision;
       printf("collision detect: %d\n", detect_collision); break;
  case '\033':
  case '\015':
  case 'Q':
  case 'q':
       appDestroy();
       break;
 }
}

variable_types:
key
unsigned char


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // ebx
const char *v5; // r12
int v7[11]; // [rsp+0h] [rbp-2Ch] BYREF

v3 = argv + 1;
v7[0] = argc;
glutInit(v7, argv, envp);
if ( v7[0] <= 1 )
goto LABEL_12;
v4 = v7[0] - 1;
while ( 1 )
{
while ( 1 )
{
v5 = *v3;
if ( strcmp(*v3, "--full-speed") )
{
if ( strcmp(*v3, "-fs") )
break;
}
full_speed = 1;
++v3;
v7[0] = v4--;
if ( !v4 )
goto LABEL_12;
}
if ( !strcmp(*v3, "--move") || *v5 == 45 && v5[1] == 109 && !v5[2] )
goto LABEL_8;
if ( !strcmp(*v3, "--collision") || !strcmp(*v3, "-c") )
{
detect_collision = 1;
move_enabled = 1;
goto LABEL_9;
}
if ( !strcmp(v5, "--gravity") || !strcmp(v5, "-g") )
{
gravity_enabled = 1;
move_enabled = 1;
goto LABEL_9;
}
if ( strcmp(v5, "--leonnard-force") && strcmp(v5, "-lf") )
break;
force_enabled = 1;
LABEL_8:
move_enabled = 1;
LABEL_9:
v7[0] = v4;
++v3;
if ( !--v4 )
goto LABEL_12;
}
MD_FILE = v5;
LABEL_12:
initializeAtoms();
glutInitDisplayMode(18LL);
glutInitWindowSize((unsigned int)winx, (unsigned int)winy);
glutWindowHandle = glutCreateWindow("Lennard-Jones Atoms");
initView((__int64)min_ext, (__int64)max_ext);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
if ( full_speed )
glutIdleFunc(idle);
else
glutTimerFunc(TIMER_VAL, timer, 0LL);
glutKeyboardFunc(appKeyboard);
glutMouseFunc(appMouse);
glutMotionFunc(appMotion);
buildAtoms();
buildVBO();
printf(
"#atoms = %d, #vertices = %d, #triangles = %d, #vertices per atom = %d\n",
natoms,
nb_vertices,
nb_indexes / 3uLL,
vertices_per_atom);
initializeComputeDevices();
glutMainLoop();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // ebx
const char *v5; // r12
int v7[11]; // [rsp+0h] [rbp-2Ch] BYREF

v3 = argv + 1;
v7[0] = argc;
glutInit(v7, argv, envp);
if ( v7[0] <= 1 )
goto LABEL_12;
v4 = v7[0] - 1;
while ( 1 )
{
while ( 1 )
{
v5 = *v3;
if ( strcmp(*v3, "--full-speed") )
{
if ( strcmp(*v3, "-fs") )
break;
}
full_speed = 1;
++v3;
v7[0] = v4--;
if ( !v4 )
goto LABEL_12;
}
if ( !strcmp(*v3, "--move") || *v5 == 45 && v5[1] == 109 && !v5[2] )
goto LABEL_8;
if ( !strcmp(*v3, "--collision") || !strcmp(*v3, "-c") )
{
detect_collision = 1;
move_enabled = 1;
goto LABEL_9;
}
if ( !strcmp(v5, "--gravity") || !strcmp(v5, "-g") )
{
gravity_enabled = 1;
move_enabled = 1;
goto LABEL_9;
}
if ( strcmp(v5, "--leonnard-force") && strcmp(v5, "-lf") )
break;
force_enabled = 1;
LABEL_8:
move_enabled = 1;
LABEL_9:
v7[0] = v4;
++v3;
if ( !--v4 )
goto LABEL_12;
}
MD_FILE = v5;
LABEL_12:
initializeAtoms();
glutInitDisplayMode(18LL);
glutInitWindowSize((unsigned int)winx, (unsigned int)winy);
glutWindowHandle = glutCreateWindow("Lennard-Jones Atoms");
func7((__int64)min_ext, (__int64)max_ext);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
if ( full_speed )
glutIdleFunc(idle);
else
glutTimerFunc(TIMER_VAL, timer, 0LL);
glutKeyboardFunc(appKeyboard);
glutMouseFunc(appMouse);
glutMotionFunc(appMotion);
buildAtoms();
buildVBO();
printf(
"#atoms = %d, #vertices = %d, #triangles = %d, #vertices per atom = %d\n",
natoms,
nb_vertices,
nb_indexes / 3uLL,
vertices_per_atom);
initializeComputeDevices();
glutMainLoop();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 glutInit(&argc, argv);
 argv++;
 while (argc > 1) {
  if(!strcmp(*argv, "--full-speed") || !strcmp(*argv, "-fs")) {
   full_speed = 1;
  }
  else if(!strcmp(*argv, "--move") || !strcmp(*argv, "-m")) {
   move_enabled = 1;
  }
  else if(!strcmp(*argv, "--collision") || !strcmp(*argv, "-c")) {
   detect_collision = 1;
   move_enabled = 1;
  }
  else if(!strcmp(*argv, "--gravity") || !strcmp(*argv, "-g")) {
   gravity_enabled = 1;
   move_enabled = 1;
  }
  else if(!strcmp(*argv, "--leonnard-force") || !strcmp(*argv, "-lf")) {
   force_enabled = 1;
   move_enabled = 1;
  }
  else
   break;
  argc--; argv++;
 }
 if(argc > 1)
  MD_FILE = *argv;
 initializeAtoms();
 unsigned int display_mode = 0x0000|0x0010|0x0002;
 glutInitDisplayMode(display_mode);
 glutInitWindowSize(winx, winy);
 glutWindowHandle = glutCreateWindow("Lennard-Jones Atoms");
 initView(min_ext, max_ext);
 glutDisplayFunc(display);
 glutReshapeFunc(reshape);
 if(full_speed)
  glutIdleFunc(idle);
 else
  glutTimerFunc(TIMER_VAL, timer, 0);
 glutKeyboardFunc(appKeyboard);
 glutMouseFunc(appMouse);
 glutMotionFunc(appMotion);
 buildAtoms();
 buildVBO();
 printf("#atoms = %d, #vertices = %d, #triangles = %d, #vertices per atom = %d\n",
   natoms, nb_vertices, nb_indexes/3, vertices_per_atom);
 initializeComputeDevices();
 glutMainLoop();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__off_t __fastcall file_size(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) < 0 )
{
perror("stat");
abort();
}
return v2.st_size;
}

canonical_decompiled_code:
__off_t __fastcall func0(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) < 0 )
{
perror("stat");
abort();
}
return v2.st_size;
}

original_code:
static size_t file_size(const char *filename) {
 struct stat sb;
 if (stat(filename, &sb) < 0) {
  perror ("stat");
  abort ();
 }
 return sb.st_size;
}

canonical_original_code:
static unsigned long file_size(char *filename) {
 struct stat sb;
 if (stat(filename, &sb) < 0) {
  perror ("stat");
  abort ();
 }
 return sb.st_size;
}

variable_types:
filename
char *

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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

return_type: unsigned long


decompiled_code:
__int64 ocl_readAtomCoordinatesFromAccel()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned int v2; // eax

v0 = atomPosAddr();
v1 = atomPosSize();
v2 = clEnqueueReadBuffer(queue, pos_buffer, 1LL, 0LL, v1, v0, 0LL, 0LL, 0LL);
if ( v2 )
{
fprintf(stderr, "(%d) Error: Failed to read from atom positions array!\n", v2);
exit(1);
}
return clFinish(queue);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned int v2; // eax

v0 = atomPosAddr();
v1 = atomPosSize();
v2 = clEnqueueReadBuffer(queue, pos_buffer, 1LL, 0LL, v1, v0, 0LL, 0LL, 0LL);
if ( v2 )
{
fprintf(stderr, "(%d) Error: Failed to read from atom positions array!\n", v2);
exit(1);
}
return clFinish(queue);
}

original_code:
void ocl_readAtomCoordinatesFromAccel(void)
{
 cl_int err;
 err = clEnqueueReadBuffer(queue, pos_buffer, 1, 0,
   atomPosSize(), atomPosAddr(), 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to read from atom positions array!\n", err); exit(1); } } while(0);
 clFinish(queue);
}

canonical_original_code:
void ocl_readAtomCoordinatesFromAccel()
{
 int err;
 err = clEnqueueReadBuffer(queue, pos_buffer, 1, 0,
   atomPosSize(), atomPosAddr(), 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to read from atom positions array!\n", err); exit(1); } } while(0);
 clFinish(queue);
}

variable_types: err int


decompiled_code:
__int64 ocl_readAtomSpeedFromAccel()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned int v2; // eax

v0 = atomSpeedAddr();
v1 = atomSpeedSize();
v2 = clEnqueueReadBuffer(queue, speed_buffer, 1LL, 0LL, v1, v0, 0LL, 0LL, 0LL);
if ( v2 )
{
fprintf(stderr, "(%d) Error: Failed to read from atom speeds array!\n", v2);
exit(1);
}
return clFinish(queue);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned int v2; // eax

v0 = atomSpeedAddr();
v1 = atomSpeedSize();
v2 = clEnqueueReadBuffer(queue, speed_buffer, 1LL, 0LL, v1, v0, 0LL, 0LL, 0LL);
if ( v2 )
{
fprintf(stderr, "(%d) Error: Failed to read from atom speeds array!\n", v2);
exit(1);
}
return clFinish(queue);
}

original_code:
void ocl_readAtomSpeedFromAccel(void)
{
 cl_int err;
 err = clEnqueueReadBuffer(queue, speed_buffer, 1, 0,
   atomSpeedSize(), atomSpeedAddr(), 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to read from atom speeds array!\n", err); exit(1); } } while(0);
 clFinish(queue);
}

canonical_original_code:
void ocl_readAtomSpeedFromAccel()
{
 int err;
 err = clEnqueueReadBuffer(queue, speed_buffer, 1, 0,
   atomSpeedSize(), atomSpeedAddr(), 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to read from atom speeds array!\n", err); exit(1); } } while(0);
 clFinish(queue);
}


decompiled_code:
__int64 ocl_updateVBOFromHost()
{
unsigned int v0; // eax
unsigned int v1; // eax
__int64 result; // rax

glFinish();
v0 = clEnqueueAcquireGLObjects(queue, 1LL, &vbo_buffer, 0LL, 0LL, 0LL);
if ( v0 )
{
fprintf(stderr, "(%d) Error: Failed to acquire lock!\n", v0);
goto LABEL_6;
}
v1 = clEnqueueWriteBuffer(queue, vbo_buffer, 1LL, 0LL, 12LL * nb_vertices, &vbo_vertex, 0LL, 0LL, 0LL);
if ( v1 )
{
fprintf(stderr, "(%d) Error: Failed to write to vbo_buffer array!\n", v1);
LABEL_6:
exit(1);
}
clFinish(queue);
result = clEnqueueReleaseGLObjects(queue, 1LL, &vbo_buffer, 0LL, 0LL, 0LL);
if ( (_DWORD)result )
{
fprintf(stderr, "(%d) Error: Failed to release lock!\n", (unsigned int)result);
goto LABEL_6;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // eax
unsigned int v1; // eax
__int64 result; // rax

glFinish();
v0 = clEnqueueAcquireGLObjects(queue, 1LL, &vbo_buffer, 0LL, 0LL, 0LL);
if ( v0 )
{
fprintf(stderr, "(%d) Error: Failed to acquire lock!\n", v0);
goto LABEL_6;
}
v1 = clEnqueueWriteBuffer(queue, vbo_buffer, 1LL, 0LL, 12LL * nb_vertices, &vbo_vertex, 0LL, 0LL, 0LL);
if ( v1 )
{
fprintf(stderr, "(%d) Error: Failed to write to vbo_buffer array!\n", v1);
LABEL_6:
exit(1);
}
clFinish(queue);
result = clEnqueueReleaseGLObjects(queue, 1LL, &vbo_buffer, 0LL, 0LL, 0LL);
if ( (_DWORD)result )
{
fprintf(stderr, "(%d) Error: Failed to release lock!\n", (unsigned int)result);
goto LABEL_6;
}
return result;
}

original_code:
void ocl_updateVBOFromHost(void)
{
 cl_int err;
 glFinish();
 err = clEnqueueAcquireGLObjects(queue, 1, &vbo_buffer, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to acquire lock!\n", err); exit(1); } } while(0);
 err = clEnqueueWriteBuffer(queue, vbo_buffer, 1, 0,
   sizeof(float) * 3 * nb_vertices, vbo_vertex, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to write to vbo_buffer array!\n", err); exit(1); } } while(0);
 clFinish(queue);
 err = clEnqueueReleaseGLObjects(queue, 1, &vbo_buffer, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to release lock!\n", err); exit(1); } } while(0);
}

canonical_original_code:
void ocl_updateVBOFromHost()
{
 int err;
 glFinish();
 err = clEnqueueAcquireGLObjects(queue, 1, &vbo_buffer, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to acquire lock!\n", err); exit(1); } } while(0);
 err = clEnqueueWriteBuffer(queue, vbo_buffer, 1, 0,
   sizeof(float) * 3 * nb_vertices, vbo_vertex, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to write to vbo_buffer array!\n", err); exit(1); } } while(0);
 clFinish(queue);
 err = clEnqueueReleaseGLObjects(queue, 1, &vbo_buffer, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to release lock!\n", err); exit(1); } } while(0);
}


decompiled_code:
__int64 ocl_finalize()
{
clReleaseMemObject(vbo_buffer);
clReleaseMemObject(min_buffer);
clReleaseMemObject(max_buffer);
clReleaseMemObject(pos_buffer);
clReleaseMemObject(speed_buffer);
clReleaseCommandQueue(queue);
clReleaseProgram(program);
return clReleaseContext(context);
}

canonical_decompiled_code:
__int64 func7()
{
clReleaseMemObject(vbo_buffer);
clReleaseMemObject(min_buffer);
clReleaseMemObject(max_buffer);
clReleaseMemObject(pos_buffer);
clReleaseMemObject(speed_buffer);
clReleaseCommandQueue(queue);
clReleaseProgram(program);
return clReleaseContext(context);
}

original_code:
void ocl_finalize(void)
{
 clReleaseMemObject(vbo_buffer);
 clReleaseMemObject(min_buffer);
 clReleaseMemObject(max_buffer);
 clReleaseMemObject(pos_buffer);
 clReleaseMemObject(speed_buffer);
 clReleaseCommandQueue(queue);
 clReleaseProgram(program);
 clReleaseContext(context);
}

canonical_original_code:
void ocl_finalize()
{
 clReleaseMemObject(vbo_buffer);
 clReleaseMemObject(min_buffer);
 clReleaseMemObject(max_buffer);
 clReleaseMemObject(pos_buffer);
 clReleaseMemObject(speed_buffer);
 clReleaseCommandQueue(queue);
 clReleaseProgram(program);
 clReleaseContext(context);
}


putsI

repo: uOptim/rubic-enseirb

decompiled_code:
int __fastcall putsI(unsigned int a1)
{
return printf("%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return printf("%d\n", a1);
}

original_code:
int32_t putsI(int32_t i) {
 return printf("%d\n", i);
}

canonical_original_code:
int putsI(int i) {
 return printf("%d\n", i);
}


putsF

decompiled_code:
int __fastcall putsF(double a1)
{
return printf("%lf\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(double a1)
{
return printf("%lf\n", a1);
}

original_code:
int32_t putsF(double f) {
 return printf("%lf\n", f);
}

canonical_original_code:
int putsF(double f) {
 return printf("%lf\n", f);
}

variable_types: f double


putsB

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

if ( a1 )
result = printf("true\n");
else
result = printf("false\n");
return result;
}

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

if ( a1 )
result = printf("true\n");
else
result = printf("false\n");
return result;
}

original_code:
int32_t putsB(int8_t b) {
 if (b == 0) {
  return printf("false\n");
 }
 else {
  return printf("true\n");
 }
}

canonical_original_code:
int putsB(char b) {
 if (b == 0) {
  return printf("false\n");
 }
 else {
  return printf("true\n");
 }
}

variable_types: b char


putsS

decompiled_code:
int __fastcall putsS(const char *a1)
{
return printf("%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return printf("%s\n", a1);
}

original_code:
int32_t putsS(char * s) {
 return printf("%s\n", s);
}

canonical_original_code:
int putsS(char *s) {
 return printf("%s\n", s);
}

variable_types:
s
char *


hash

decompiled_code:
__int64 __fastcall hash(char *a1)
{
__int16 v1; // ax
__int16 v2; // dx

v1 = *a1;
if ( !(_BYTE)v1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 += v1;
v1 = *a1;
}
while ( (_BYTE)v1 );
return v2 & 0x1FF;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
__int16 v1; // ax
__int16 v2; // dx

v1 = *a1;
if ( !(_BYTE)v1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 += v1;
v1 = *a1;
}
while ( (_BYTE)v1 );
return v2 & 0x1FF;
}

original_code:
static size_t hash(const char *key)
{
 size_t n = 0;
 const char *p = key;
 for (; *p != '\0'; p++) {
  n += *p;
 }
 return n % 512;
}

canonical_original_code:
static unsigned long hash(char *key)
{
 unsigned long n = 0;
 char *p = key;
 for (; *p != '\0'; p++) {
  n += *p;
 }
 return n % 512;
}

variable_types:
key
char *

variable_types:
n
unsigned long

variable_types:
p
char *


original_code:
void hashmap_free(struct hashmap **h, void (*free_data)(void *))
{
 unsigned int idx;
 struct cell *cur, *tmp;
 for (idx = 0; idx < 512; idx++) {
  cur = (*h)->array[idx];
  while (cur != ((void *)0)) {
   tmp = cur->next;
   free(cur->key);
   if (free_data != ((void *)0)) free_data(cur->data);
   free(cur);
   cur = tmp;
  }
 }
 free((*h)->array);
 free(*h);
 *h = ((void *)0);
}

canonical_original_code:
void hashmap_free(struct hashmap **h, void (*free_data)(void *))
{
 unsigned int idx;
 struct cell *cur; struct cell *tmp;
 for (idx = 0; idx < 512; idx++) {
  cur = (*h)->array[idx];
  while (cur != ((void *)0)) {
   tmp = cur->next;
   free(cur->key);
   if (free_data != ((void *)0)) free_data(cur->data);
   free(cur);
   cur = tmp;
  }
 }
 free((*h)->array);
 free(*h);
 *h = ((void *)0);
}

variable_types: struct hashmap { struct cell { void *data; char *key; struct cell *next; } **array; } **

variable_types:
idx
unsigned int


decompiled_code:
_QWORD *hashmap_new()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(8uLL);
if ( v0 )
{
v1 = calloc(0x200uLL, 8uLL);
*v0 = v1;
if ( !v1 )
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // r12
void *v1; // rax
void *v3; // rdi

v0 = malloc(8uLL);
if ( v0 )
{
v1 = calloc(0x200uLL, 8uLL);
*v0 = v1;
if ( !v1 )
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
struct hashmap * hashmap_new()
{
 struct hashmap *h = malloc(sizeof *h);
 if (h == ((void *)0))
  return ((void *)0);
 h->array = calloc(512, sizeof *h->array);
 if (h->array == ((void *)0)) {
  free(h);
  return ((void *)0);
 }
 return h;
}

canonical_original_code:
struct hashmap *hashmap_new()
{
 struct hashmap *h = malloc(sizeof *h);
 if (h == ((void *)0))
  return ((void *)0);
 h->array = calloc(512, sizeof *h->array);
 if (h->array == ((void *)0)) {
  free(h);
  return ((void *)0);
 }
 return h;
}

variable_types: struct hashmap { struct cell { void *data; char *key; struct cell *next; } **array; } *


decompiled_code:
__int64 __fastcall hashmap_set(_QWORD *a1, char *a2, __int64 a3)
{
__int64 v5; // rbp
char *v6; // r8
_QWORD *v7; // rax
_QWORD *v8; // rdx

v5 = hash(a2);
v7 = cell_new(v6, a3);
if ( !v7 )
return 0xFFFFFFFFLL;
v8 = (_QWORD *)(*a1 + 8 * v5);
if ( *v8 )
v7[2] = *v8;
*v8 = v7;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, char *a2, __int64 a3)
{
__int64 v5; // rbp
char *v6; // r8
_QWORD *v7; // rax
_QWORD *v8; // rdx

v5 = func0(a2);
v7 = cell_new(v6, a3);
if ( !v7 )
return 0xFFFFFFFFLL;
v8 = (_QWORD *)(*a1 + 8 * v5);
if ( *v8 )
v7[2] = *v8;
*v8 = v7;
return 0LL;
}

original_code:
int hashmap_set(struct hashmap *h, const char *k, void *v)
{
 size_t idx = hash(k);
 struct cell *c = cell_new(k, v);
 if (c == ((void *)0)) return -1;
 if (h->array[idx] != ((void *)0)) {
  c->next = h->array[idx];
 }
 h->array[idx] = c;
 return 0;
}

canonical_original_code:
int hashmap_set(struct hashmap *h, char *k, void *v)
{
 unsigned long idx = hash(k);
 struct cell *c = cell_new(k, v);
 if (c == ((void *)0)) return -1;
 if (h->array[idx] != ((void *)0)) {
  c->next = h->array[idx];
 }
 h->array[idx] = c;
 return 0;
}

variable_types:
k
char *

variable_types:
v
void *

variable_types:
idx
unsigned long

variable_types: struct cell { void *data; char *key; struct cell *next; } *


decompiled_code:
__int64 __fastcall hashmap_dump(__int64 *a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 i; // r12
__int64 result; // rax
__int64 j; // rbx

for ( i = 0LL; i != 4096; i += 8LL )
{
result = *a1;
for ( j = *(_QWORD *)(*a1 + i); j; j = *(_QWORD *)(j + 16) )
{
printf("Key: %s\n", *(const char **)(j + 8));
result = a2(*(_QWORD *)j);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 i; // r12
__int64 result; // rax
__int64 j; // rbx

for ( i = 0LL; i != 4096; i += 8LL )
{
result = *a1;
for ( j = *(_QWORD *)(*a1 + i); j; j = *(_QWORD *)(j + 16) )
{
printf("Key: %s\n", *(const char **)(j + 8));
result = a2(*(_QWORD *)j);
}
}
return result;
}

original_code:
void hashmap_dump(struct hashmap *h, void (*dump_data)(void *))
{
 unsigned int idx;
 struct cell *cur;
 for (idx = 0; idx < 512; idx++) {
  cur = h->array[idx];
  while (cur != ((void *)0)) {
   printf("Key: %s\n", cur->key);
   dump_data(cur->data);
   cur = cur->next;
  }
 }
}

user_defined_types: struct cell { void *data; char *key; struct cell *next; }


decompiled_code:
void __fastcall cst_free(void *ptr)
{
if ( *(_DWORD *)ptr == 3 )
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( *(_DWORD *)ptr == 3 )
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void cst_free(void *cst)
{
 struct cst *c = (struct cst *) cst;
 if (c->type == 3) {
  free(c->s);
  c->s = ((void *)0);
 }
 free(cst);
}

variable_types:
cst
void *

variable_types: struct cst { unsigned int type; union { int i; char c; double f; char *s; unsigned int o; }; } *


decompiled_code:
int __fastcall cst_dump(double *a1)
{
int v1; // eax

puts("Constant:");
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
return printf("* type: float, value: %g\n", a1[1]);
if ( v1 == 2 )
return printf("* type: bool, value: %i\n", (unsigned int)*((char *)a1 + 8));
if ( v1 )
return puts("Type Unknown");
return printf("* type: int, value: %d\n", *((unsigned int *)a1 + 2));
}

canonical_decompiled_code:
int __fastcall func13(double *a1)
{
int v1; // eax

puts("Constant:");
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
return printf("* type: float, value: %g\n", a1[1]);
if ( v1 == 2 )
return printf("* type: bool, value: %i\n", (unsigned int)*((char *)a1 + 8));
if ( v1 )
return puts("Type Unknown");
return printf("* type: int, value: %d\n", *((unsigned int *)a1 + 2));
}

original_code:
void cst_dump(const struct cst *c)
{
 puts("Constant:");
 switch (c->type) {
  case 0:
   printf("* type: int, value: %d\n", c->i);
   break;
  case 1:
   printf("* type: float, value: %g\n", c->f);
   break;
  case 2:
   printf("* type: bool, value: %i\n", c->c);
   break;
  default:
   printf("Type Unknown\n");
 }
}

canonical_original_code:
void cst_dump(struct cst *c)
{
 puts("Constant:");
 switch (c->type) {
  case 0:
   printf("* type: int, value: %d\n", c->i);
   break;
  case 1:
   printf("* type: float, value: %g\n", c->f);
   break;
  case 2:
   printf("* type: bool, value: %i\n", c->c);
   break;
  default:
   printf("Type Unknown\n");
 }
}

user_defined_types: struct cst { unsigned int type; union { int i; char c; double f; char *s; unsigned int o; }; }


decompiled_code:
__int64 __fastcall type_copy(__int64 a1)
{
return a1;
}

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

original_code:
void * type_copy(void *type) {
 return type;
}

canonical_original_code:
void *type_copy(void *type) {
 return type;
}

variable_types:
type
void *