main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
char v5; // bp
const char *v6; // rsi
int v7; // eax
size_t v8; // rdx
const char *v9; // rdi
FILE *v10; // rcx
int v11; // eax
unsigned int v12; // er12
FILE *v13; // rbp
bool v14; // cf
bool v15; // zf
const char **v16; // rbp
char **v17; // r14
__int64 *v18; // r15
const char *v19; // r13
__int64 v20; // rcx
const char *v21; // rdi
bool (__fastcall *v22)(__int64, _DWORD *, _DWORD *); // rax
__int64 (__fastcall *v23)(__int64, _DWORD *, _DWORD *, unsigned int, unsigned int, unsigned int); // rax
char *v24; // r13
__int64 v25; // r9
char v26; // r15
__int64 v27; // r9
__int64 v28; // rsi
int v29; // ebx
int v30; // [rsp+0h] [rbp-E8h]
unsigned int v31; // [rsp+4h] [rbp-E4h]
char v32; // [rsp+8h] [rbp-E0h]
double v33; // [rsp+8h] [rbp-E0h]
char v34; // [rsp+10h] [rbp-D8h]
int v35; // [rsp+10h] [rbp-D8h]
unsigned int v36; // [rsp+14h] [rbp-D4h]
unsigned int v37; // [rsp+14h] [rbp-D4h]
unsigned int v38; // [rsp+18h] [rbp-D0h]
unsigned int v39; // [rsp+1Ch] [rbp-CCh]
unsigned int v40; // [rsp+20h] [rbp-C8h]
int v41; // [rsp+24h] [rbp-C4h]
char *ptr; // [rsp+28h] [rbp-C0h]
unsigned int v43; // [rsp+38h] [rbp-B0h] BYREF
unsigned int v44; // [rsp+3Ch] [rbp-ACh] BYREF
struct timeval tv; // [rsp+40h] [rbp-A8h] BYREF
bool (__fastcall *v46)(__int64, _DWORD *, _DWORD *); // [rsp+50h] [rbp-98h] BYREF
__int64 (__fastcall *v47)(__int64, _DWORD *, _DWORD *, unsigned int, unsigned int, unsigned int); // [rsp+58h] [rbp-90h]
char *endptr[8]; // [rsp+60h] [rbp-88h] BYREF
char v49; // [rsp+A0h] [rbp-48h]

v3 = 4;
v5 = 0;
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
v31 = 4;
v46 = 0LL;
v47 = 0LL;
v30 = 1;
while ( 1 )
{
v6 = (const char *)argv;
v7 = getopt(argc, (char *const *)argv, "n:qhd:");
if ( v7 == -1 )
break;
if ( v7 == 104 )
{
usage();
exit(0);
}
if ( v7 > 104 )
{
if ( v7 == 110 )
{
v11 = strtol(optarg, endptr, 10);
v30 = v11;
if ( *endptr[0] || v11 <= 0 )
{
v8 = 47LL;
v9 = "Option -n requires a positive integer argument\n";
v10 = stderr;
LABEL_20:
fwrite(v9, 1uLL, v8, v10);
LABEL_24:
usage();
exit(1);
}
}
else if ( v7 == 113 )
{
v5 = 1;
}
}
else
{
if ( v7 == 63 )
{
v12 = optopt;
v13 = stderr;
if ( optopt == 110 )
{
fwrite("Option -n requires an argument\n", 1uLL, 0x1FuLL, stderr);
}
else if ( ((*_ctype_b_loc())[v12] & 0x4000) != 0 )
{
fprintf(v13, "Unknown option `-%c'.\n", v12);
}
else
{
fprintf(v13, "Unknown option character `\\x%x'.\n", v12);
}
goto LABEL_24;
}
if ( v7 == 100 )
{
v31 = strtol(optarg, endptr, 10);
v3 = v31;
if ( *endptr[0] )
{
if ( *endptr[0] != 44 || !endptr[0][1] || (v3 = strtol(endptr[0] + 1, endptr, 10), *endptr[0]) )
{
v8 = 58LL;
v9 = "Option -d requires argument either DEPTH or DEPTH1,DEPTH2\n";
v10 = stderr;
goto LABEL_20;
}
}
}
}
}
if ( argc <= optind )
goto LABEL_80;
v32 = v5;
v14 = __CFADD__(argc, ~optind);
v15 = argc + ~optind == 0;
v36 = v3;
v34 = 0;
v16 = &argv[optind];
v17 = (char **)&v46;
v18 = (__int64 *)(&v46 + (unsigned int)(argc + ~optind));
do
{
v19 = *v16;
v20 = 6LL;
v21 = "human";
v6 = *v16;
do
{
if ( !v20 )
break;
v14 = *v6 < (unsigned int)*v21;
v15 = *v6++ == *v21++;
--v20;
}
while ( v15 );
if ( (!v14 && !v15) == v14 )
{
*v17 = (char *)play_human_turn_is_game_over;
v34 = 1;
}
else
{
v6 = "hand-ai";
if ( !strcmp(*v16, "hand-ai") )
{
*v17 = (char *)play_hand_minimax_ai_turn_is_game_over;
}
else
{
v6 = "naive-ai";
if ( !strcmp(v19, "naive-ai") )
{
*v17 = (char *)play_naive_minimax_ai_turn_is_game_over;
}
else
{
v6 = "learning-ai";
if ( !strcmp(v19, "learning-ai") )
{
*v17 = (char *)play_learning_minimax_ai_turn_is_game_over;
}
else
{
v6 = "random";
if ( strcmp(v19, "random") )
{
fprintf(
stderr,
"Unrecognized player type %s. Expected one of human, hand-ai, naive-ai, learning-ai, random.\n",
v19);
usage();
exit(1);
}
*v17 = (char *)play_random_turn_is_game_over;
}
}
}
}
if ( v18 == (__int64 *)v17 )
break;
++v17;
++v16;
v14 = endptr < v17;
v15 = endptr == v17;
}
while ( endptr != v17 );
v22 = v46;
v5 = v32;
v3 = v36;
if ( !v46 )
{
LABEL_80:
v34 = 1;
v22 = play_human_turn_is_game_over;
}
v46 = v22;
v23 = v47;
if ( !v47 )
v23 = play_hand_minimax_ai_turn_is_game_over;
v47 = v23;
if ( v5 && v34 )
{
v6 = (_BYTE *)(learning_static_eval + 1);
fwrite(
"WARNING: Quiet mode enabled but a human is playing.\n"
" This is going to make the game awfully hard for her or him!\n",
1uLL,
0x79uLL,
stderr);
}
init_weights(&weights, v6);
v35 = 0;
ptr = (char *)calloc(v30, 0x1A04uLL);
v24 = ptr;
v41 = v30 >> 1;
v40 = 0;
v39 = 0;
v38 = 0;
v37 = 0;
LABEL_50:
init_learning_ai_game_state(v24);
reset_othello_bd(endptr);
while ( !v5 )
{
show_othello_bd(stdout, endptr);
v27 = v3;
if ( v49 == 1 )
v27 = v31;
v26 = ((__int64 (__fastcall *)(char **, unsigned int *, unsigned int *, _QWORD, _QWORD, __int64))*(&v46 + ((1 - v49) >> 1)))(
endptr,
&v43,
&v44,
v43,
v44,
v27);
v28 = (unsigned int)-v49;
if ( v43 == -1 )
{
printf("Player %d passes.\n", v28);
LABEL_54:
add_board(v24, endptr);
if ( v26 )
goto LABEL_60;
}
else
{
printf("Player %d's move: %d %d.\n", v28, v43, v44);
add_board(v24, endptr);
if ( v26 )
{
LABEL_60:
if ( !v5 )
show_othello_bd(stdout, endptr);
v33 = score(endptr);
if ( v33 > 0.0 )
{
puts("Player 1 wins!");
if ( v41 < v35 )
++v39;
++v37;
}
else if ( v33 < 0.0 )
{
puts("Player -1 wins!");
++v38;
if ( v41 < v35 )
++v40;
}
else
{
puts("Tie!");
}
if ( trees[0] )
{
free_minimax_tree();
trees[0] = 0LL;
}
if ( trees[1] )
{
free_minimax_tree();
trees[1] = 0LL;
}
v29 = 10;
do
{
update_weights_from_game(&weights, v24, (unsigned int)(int)v33, 1LL);
--v29;
}
while ( v29 );
v24 += 6660;
printf("WEIGHTS: ");
print_weights(&weights);
printf("\nSCORE: 1: %d (%d); 2: %d (%d)\n", v37, v39, v38, v40);
if ( v30 == ++v35 )
{
free(ptr);
exit(0);
}
goto LABEL_50;
}
}
}
v25 = v3;
if ( v49 == 1 )
v25 = v31;
v26 = ((__int64 (__fastcall *)(char **, unsigned int *, unsigned int *, _QWORD, _QWORD, __int64))*(&v46 + ((1 - v49) >> 1)))(
endptr,
&v43,
&v44,
v43,
v44,
v25);
goto LABEL_54;
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
char v5; // bp
const char *v6; // rsi
int v7; // eax
size_t v8; // rdx
const char *v9; // rdi
FILE *v10; // rcx
int v11; // eax
unsigned int v12; // er12
FILE *v13; // rbp
bool v14; // cf
bool v15; // zf
const char **v16; // rbp
char **v17; // r14
__int64 *v18; // r15
const char *v19; // r13
__int64 v20; // rcx
const char *v21; // rdi
bool (__fastcall *v22)(__int64, _DWORD *, _DWORD *); // rax
__int64 (__fastcall *v23)(__int64, _DWORD *, _DWORD *, unsigned int, unsigned int, unsigned int); // rax
char *v24; // r13
__int64 v25; // r9
char v26; // r15
__int64 v27; // r9
__int64 v28; // rsi
int v29; // ebx
int v30; // [rsp+0h] [rbp-E8h]
unsigned int v31; // [rsp+4h] [rbp-E4h]
char v32; // [rsp+8h] [rbp-E0h]
double v33; // [rsp+8h] [rbp-E0h]
char v34; // [rsp+10h] [rbp-D8h]
int v35; // [rsp+10h] [rbp-D8h]
unsigned int v36; // [rsp+14h] [rbp-D4h]
unsigned int v37; // [rsp+14h] [rbp-D4h]
unsigned int v38; // [rsp+18h] [rbp-D0h]
unsigned int v39; // [rsp+1Ch] [rbp-CCh]
unsigned int v40; // [rsp+20h] [rbp-C8h]
int v41; // [rsp+24h] [rbp-C4h]
char *ptr; // [rsp+28h] [rbp-C0h]
unsigned int v43; // [rsp+38h] [rbp-B0h] BYREF
unsigned int v44; // [rsp+3Ch] [rbp-ACh] BYREF
struct timeval tv; // [rsp+40h] [rbp-A8h] BYREF
bool (__fastcall *v46)(__int64, _DWORD *, _DWORD *); // [rsp+50h] [rbp-98h] BYREF
__int64 (__fastcall *v47)(__int64, _DWORD *, _DWORD *, unsigned int, unsigned int, unsigned int); // [rsp+58h] [rbp-90h]
char *endptr[8]; // [rsp+60h] [rbp-88h] BYREF
char v49; // [rsp+A0h] [rbp-48h]

v3 = 4;
v5 = 0;
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
v31 = 4;
v46 = 0LL;
v47 = 0LL;
v30 = 1;
while ( 1 )
{
v6 = (const char *)argv;
v7 = getopt(argc, (char *const *)argv, "n:qhd:");
if ( v7 == -1 )
break;
if ( v7 == 104 )
{
func7();
exit(0);
}
if ( v7 > 104 )
{
if ( v7 == 110 )
{
v11 = strtol(optarg, endptr, 10);
v30 = v11;
if ( *endptr[0] || v11 <= 0 )
{
v8 = 47LL;
v9 = "Option -n requires a positive integer argument\n";
v10 = stderr;
LABEL_20:
fwrite(v9, 1uLL, v8, v10);
LABEL_24:
func7();
exit(1);
}
}
else if ( v7 == 113 )
{
v5 = 1;
}
}
else
{
if ( v7 == 63 )
{
v12 = optopt;
v13 = stderr;
if ( optopt == 110 )
{
fwrite("Option -n requires an argument\n", 1uLL, 0x1FuLL, stderr);
}
else if ( ((*_ctype_b_loc())[v12] & 0x4000) != 0 )
{
fprintf(v13, "Unknown option `-%c'.\n", v12);
}
else
{
fprintf(v13, "Unknown option character `\\x%x'.\n", v12);
}
goto LABEL_24;
}
if ( v7 == 100 )
{
v31 = strtol(optarg, endptr, 10);
v3 = v31;
if ( *endptr[0] )
{
if ( *endptr[0] != 44 || !endptr[0][1] || (v3 = strtol(endptr[0] + 1, endptr, 10), *endptr[0]) )
{
v8 = 58LL;
v9 = "Option -d requires argument either DEPTH or DEPTH1,DEPTH2\n";
v10 = stderr;
goto LABEL_20;
}
}
}
}
}
if ( argc <= optind )
goto LABEL_80;
v32 = v5;
v14 = __CFADD__(argc, ~optind);
v15 = argc + ~optind == 0;
v36 = v3;
v34 = 0;
v16 = &argv[optind];
v17 = (char **)&v46;
v18 = (__int64 *)(&v46 + (unsigned int)(argc + ~optind));
do
{
v19 = *v16;
v20 = 6LL;
v21 = "human";
v6 = *v16;
do
{
if ( !v20 )
break;
v14 = *v6 < (unsigned int)*v21;
v15 = *v6++ == *v21++;
--v20;
}
while ( v15 );
if ( (!v14 && !v15) == v14 )
{
*v17 = (char *)play_human_turn_is_game_over;
v34 = 1;
}
else
{
v6 = "hand-ai";
if ( !strcmp(*v16, "hand-ai") )
{
*v17 = (char *)play_hand_minimax_ai_turn_is_game_over;
}
else
{
v6 = "naive-ai";
if ( !strcmp(v19, "naive-ai") )
{
*v17 = (char *)play_naive_minimax_ai_turn_is_game_over;
}
else
{
v6 = "learning-ai";
if ( !strcmp(v19, "learning-ai") )
{
*v17 = (char *)play_learning_minimax_ai_turn_is_game_over;
}
else
{
v6 = "random";
if ( strcmp(v19, "random") )
{
fprintf(
stderr,
"Unrecognized player type %s. Expected one of human, hand-ai, naive-ai, learning-ai, random.\n",
v19);
func7();
exit(1);
}
*v17 = (char *)play_random_turn_is_game_over;
}
}
}
}
if ( v18 == (__int64 *)v17 )
break;
++v17;
++v16;
v14 = endptr < v17;
v15 = endptr == v17;
}
while ( endptr != v17 );
v22 = v46;
v5 = v32;
v3 = v36;
if ( !v46 )
{
LABEL_80:
v34 = 1;
v22 = play_human_turn_is_game_over;
}
v46 = v22;
v23 = v47;
if ( !v47 )
v23 = play_hand_minimax_ai_turn_is_game_over;
v47 = v23;
if ( v5 && v34 )
{
v6 = (_BYTE *)(learning_static_eval + 1);
fwrite(
"WARNING: Quiet mode enabled but a human is playing.\n"
" This is going to make the game awfully hard for her or him!\n",
1uLL,
0x79uLL,
stderr);
}
init_weights(&weights, v6);
v35 = 0;
ptr = (char *)calloc(v30, 0x1A04uLL);
v24 = ptr;
v41 = v30 >> 1;
v40 = 0;
v39 = 0;
v38 = 0;
v37 = 0;
LABEL_50:
init_learning_ai_game_state(v24);
reset_othello_bd(endptr);
while ( !v5 )
{
show_othello_bd(stdout, endptr);
v27 = v3;
if ( v49 == 1 )
v27 = v31;
v26 = ((__int64 (__fastcall *)(char **, unsigned int *, unsigned int *, _QWORD, _QWORD, __int64))*(&v46 + ((1 - v49) >> 1)))(
endptr,
&v43,
&v44,
v43,
v44,
v27);
v28 = (unsigned int)-v49;
if ( v43 == -1 )
{
printf("Player %d passes.\n", v28);
LABEL_54:
add_board(v24, endptr);
if ( v26 )
goto LABEL_60;
}
else
{
printf("Player %d's move: %d %d.\n", v28, v43, v44);
add_board(v24, endptr);
if ( v26 )
{
LABEL_60:
if ( !v5 )
show_othello_bd(stdout, endptr);
v33 = score(endptr);
if ( v33 > 0.0 )
{
puts("Player 1 wins!");
if ( v41 < v35 )
++v39;
++v37;
}
else if ( v33 < 0.0 )
{
puts("Player -1 wins!");
++v38;
if ( v41 < v35 )
++v40;
}
else
{
puts("Tie!");
}
if ( trees[0] )
{
free_minimax_tree();
trees[0] = 0LL;
}
if ( trees[1] )
{
free_minimax_tree();
trees[1] = 0LL;
}
v29 = 10;
do
{
update_weights_from_game(&weights, v24, (unsigned int)(int)v33, 1LL);
--v29;
}
while ( v29 );
v24 += 6660;
printf("WEIGHTS: ");
print_weights(&weights);
printf("\nSCORE: 1: %d (%d); 2: %d (%d)\n", v37, v39, v38, v40);
if ( v30 == ++v35 )
{
free(ptr);
exit(0);
}
goto LABEL_50;
}
}
}
v25 = v3;
if ( v49 == 1 )
v25 = v31;
v26 = ((__int64 (__fastcall *)(char **, unsigned int *, unsigned int *, _QWORD, _QWORD, __int64))*(&v46 + ((1 - v49) >> 1)))(
endptr,
&v43,
&v44,
v43,
v44,
v25);
goto LABEL_54;
}

original_code:
int main (int argc, char **argv) {
  struct timeval cur;
  gettimeofday(&cur,((void *)0));
  srand(cur.tv_usec);
  _Bool (*play[2]) (othello_bd*,int*,int*,int,int,int) = { ((void *)0), ((void *)0) };
  int ngames = 1;
  _Bool quiet = 0;
  int depth1 = 4, depth2 = 4;
  int c;
  while (( c = getopt (argc, argv, "n:qhd:")) != -1) {
    char *tail;
    switch (c) {
      case 'n':
        ngames = strtol(optarg,&tail,10);
        if (*tail || ngames <= 0 ) {
          fprintf(stderr,"Option -n requires a positive integer argument\n");
          usage();
          exit(1);
        }
        break;
      case 'd':
        depth1 = strtol(optarg,&tail,10);
        if (!(*tail)) {
          depth2 = depth1;
        } else if (*tail == ',') {
          if (*(tail+1)) {
            depth2 = strtol(tail+1,&tail,10);
            if (*tail) {
              fprintf(stderr,"Option -d requires argument either DEPTH or DEPTH1,DEPTH2\n");
              usage();
              exit(1);
            }
          } else {
            fprintf(stderr,"Option -d requires argument either DEPTH or DEPTH1,DEPTH2\n");
            usage();
            exit(1);
          }
        } else {
          fprintf(stderr,"Option -d requires argument either DEPTH or DEPTH1,DEPTH2\n");
          usage();
          exit(1);
        }
        break;
      case 'q':
        quiet = 1;
        break;
      case 'h':
        usage();
        exit(0);
        break;
      case '?':
        if (optopt == 'n') {
          fprintf(stderr,"Option -n requires an argument\n");
        }
        else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short int) _ISprint)) {
          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
        } else {
          fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
        }
        usage();
        exit(1);
        break;
    }
  }
  _Bool have_human_player = 0;
  for (int k = optind ; k < argc && k < 2 + optind ; ++k) {
    if (!strcmp(argv[k],"human")) {
      play[k-optind] = play_human_turn_is_game_over;
      have_human_player = 1;
    } else if (!strcmp(argv[k],"hand-ai")) {
      play[k-optind] = play_hand_minimax_ai_turn_is_game_over;
    } else if (!strcmp(argv[k],"naive-ai")) {
      play[k-optind] = play_naive_minimax_ai_turn_is_game_over;
    } else if (!strcmp(argv[k],"learning-ai")) {
      play[k-optind] = play_learning_minimax_ai_turn_is_game_over;
    } else if (!strcmp(argv[k],"random")) {
      play[k-optind] = play_random_turn_is_game_over;
    } else {
      fprintf(stderr,"Unrecognized player type %s. Expected one of human, hand-ai, naive-ai, learning-ai, random.\n",argv[k]);
      usage();
      exit(1);
    }
  }
  if (!play[0]) {
    play[0] = play_human_turn_is_game_over;
    have_human_player = 1;
  }
  if (!play[1]) {
    play[1] = play_hand_minimax_ai_turn_is_game_over;
  }
  if (quiet && have_human_player) {
    fprintf(stderr,"WARNING: Quiet mode enabled but a human is playing.\n"
                   "         This is going to make the game awfully hard for her or him!\n");
  }
  init_weights(&weights);
  int wins1 = 0, wins2 = 0, wins1backhalf = 0, wins2backhalf = 0;
  learning_ai_game_state *lags_arr = (learning_ai_game_state*)calloc(ngames,sizeof(learning_ai_game_state));
  for (int game = 0 ; game < ngames ; ++game) {
    othello_bd the_bd;
    othello_bd *bd = &the_bd;
    init_learning_ai_game_state(&lags_arr[game]);
    reset_othello_bd(bd);
    _Bool game_over = 0;
    while (!game_over) {
      if (!quiet) {
        show_othello_bd(stdout,bd);
      }
      int x,y;
      game_over = (play[(1-bd->turn)>>1])(bd,&x,&y,x,y,bd->turn == 1 ? depth1 : depth2);
      if (!quiet) {
        if (x != -1) {
          printf("Player %d's move: %d %d.\n",-bd->turn,x,y);
        } else {
          printf("Player %d passes.\n",-bd->turn);
        }
      }
      add_board(&lags_arr[game],bd);
    }
    if (!quiet) {
      show_othello_bd(stdout,bd);
    }
    double winner = score(bd);
    if (winner > 0) {
      printf("Player 1 wins!\n");
      if (game > ngames/2) {
        ++wins1backhalf;
      }
      ++wins1;
    } else if (winner < 0) {
      printf("Player -1 wins!\n");
      ++wins2;
      if (game > ngames/2) {
        ++wins2backhalf;
      }
    } else {
      printf("Tie!\n");
    }
    for (int k = 0 ; k < 2 ; ++k) {
      if (trees[k]) {
        free_minimax_tree(trees[k]);
        trees[k] = ((void *)0);
      }
    }
    for (int l = 0 ; l < 10 ; ++l) {
      for (int k = game >= 0 ? game : 0 ; k <= game ; ++k) {
        update_weights_from_game(&weights,&lags_arr[k],winner,1);
      }
    }
    printf("WEIGHTS: ");
    print_weights(&weights);
    printf("\nSCORE: 1: %d (%d); 2: %d (%d)\n",wins1,wins1backhalf,wins2,wins2backhalf);
  }
  free((void*)lags_arr);
  exit(0);
}

canonical_original_code:
int main(int argc, char **argv) {
  struct timeval cur;
  gettimeofday(&cur,((void *)0));
  srand(cur.tv_usec);
  _Bool (*play[2])(struct othello_bd *, int *, int *, int, int, int) = { ((void *)0), ((void *)0) };
  int ngames = 1;
  _Bool quiet = 0;
  int depth1 = 4; int depth2 = 4;
  int c;
  while (( c = getopt (argc, argv, "n:qhd:")) != -1) {
    char *tail;
    switch (c) {
      case 'n':
        ngames = strtol(optarg,&tail,10);
        if (*tail || ngames <= 0 ) {
          fprintf(stderr,"Option -n requires a positive integer argument\n");
          usage();
          exit(1);
        }
        break;
      case 'd':
        depth1 = strtol(optarg,&tail,10);
        if (!(*tail)) {
          depth2 = depth1;
        } else if (*tail == ',') {
          if (*(tail+1)) {
            depth2 = strtol(tail+1,&tail,10);
            if (*tail) {
              fprintf(stderr,"Option -d requires argument either DEPTH or DEPTH1,DEPTH2\n");
              usage();
              exit(1);
            }
          } else {
            fprintf(stderr,"Option -d requires argument either DEPTH or DEPTH1,DEPTH2\n");
            usage();
            exit(1);
          }
        } else {
          fprintf(stderr,"Option -d requires argument either DEPTH or DEPTH1,DEPTH2\n");
          usage();
          exit(1);
        }
        break;
      case 'q':
        quiet = 1;
        break;
      case 'h':
        usage();
        exit(0);
        break;
      case '?':
        if (optopt == 'n') {
          fprintf(stderr,"Option -n requires an argument\n");
        }
        else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short) _ISprint)) {
          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
        } else {
          fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
        }
        usage();
        exit(1);
        break;
    }
  }
  _Bool have_human_player = 0;
  for (int k = optind; k < argc && k < 2 + optind ; ++k) {
    if (!strcmp(argv[k],"human")) {
      play[k-optind] = play_human_turn_is_game_over;
      have_human_player = 1;
    } else if (!strcmp(argv[k],"hand-ai")) {
      play[k-optind] = play_hand_minimax_ai_turn_is_game_over;
    } else if (!strcmp(argv[k],"naive-ai")) {
      play[k-optind] = play_naive_minimax_ai_turn_is_game_over;
    } else if (!strcmp(argv[k],"learning-ai")) {
      play[k-optind] = play_learning_minimax_ai_turn_is_game_over;
    } else if (!strcmp(argv[k],"random")) {
      play[k-optind] = play_random_turn_is_game_over;
    } else {
      fprintf(stderr,"Unrecognized player type %s. Expected one of human, hand-ai, naive-ai, learning-ai, random.\n",argv[k]);
      usage();
      exit(1);
    }
  }
  if (!play[0]) {
    play[0] = play_human_turn_is_game_over;
    have_human_player = 1;
  }
  if (!play[1]) {
    play[1] = play_hand_minimax_ai_turn_is_game_over;
  }
  if (quiet && have_human_player) {
    fprintf(stderr,"WARNING: Quiet mode enabled but a human is playing.\n"
                   "         This is going to make the game awfully hard for her or him!\n");
  }
  init_weights(&weights);
  int wins1 = 0; int wins2 = 0; int wins1backhalf = 0; int wins2backhalf = 0;
  struct learning_ai_game_state *lags_arr = (learning_ai_game_state*)calloc(ngames,sizeof(learning_ai_game_state));
  for (int game = 0; game < ngames ; ++game) {
    struct othello_bd the_bd;
    struct othello_bd *bd = &the_bd;
    init_learning_ai_game_state(&lags_arr[game]);
    reset_othello_bd(bd);
    _Bool game_over = 0;
    while (!game_over) {
      if (!quiet) {
        show_othello_bd(stdout,bd);
      }
      int x; int y;
      game_over = (play[(1-bd->turn)>>1])(bd,&x,&y,x,y,bd->turn == 1 ? depth1 : depth2);
      if (!quiet) {
        if (x != -1) {
          printf("Player %d's move: %d %d.\n",-bd->turn,x,y);
        } else {
          printf("Player %d passes.\n",-bd->turn);
        }
      }
      add_board(&lags_arr[game],bd);
    }
    if (!quiet) {
      show_othello_bd(stdout,bd);
    }
    double winner = score(bd);
    if (winner > 0) {
      printf("Player 1 wins!\n");
      if (game > ngames/2) {
        ++wins1backhalf;
      }
      ++wins1;
    } else if (winner < 0) {
      printf("Player -1 wins!\n");
      ++wins2;
      if (game > ngames/2) {
        ++wins2backhalf;
      }
    } else {
      printf("Tie!\n");
    }
    for (int k = 0; k < 2 ; ++k) {
      if (trees[k]) {
        free_minimax_tree(trees[k]);
        trees[k] = ((void *)0);
      }
    }
    for (int l = 0; l < 10 ; ++l) {
      for (int k = game >= 0 ? game : 0; k <= game ; ++k) {
        update_weights_from_game(&weights,&lags_arr[k],winner,1);
      }
    }
    printf("WEIGHTS: ");
    print_weights(&weights);
    printf("\nSCORE: 1: %d (%d); 2: %d (%d)\n",wins1,wins1backhalf,wins2,wins2backhalf);
  }
  free((void *)lags_arr);
  exit(0);
}

variable_types: argc int

variable_types:
argv
char **

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

variable_types: _Bool (*[2])(struct othello_bd { char board[8][8]; char turn; char just_passed; } *, int *, int *, int, int, int)

variable_types: ngames int

variable_types: c int

variable_types:
tail
char *

variable_types: k int

variable_types: struct learning_ai_game_state { int turns; struct board_counts { int turn; int squares_filled; int score; int counts[10]; } cts[-1]; } *

variable_types: game int

variable_types: x int

variable_types: y int

variable_types: winner double

variable_types: l int

user_defined_types: struct learning_ai_game_state { int turns; struct board_counts cts[-1]; }


repo: ajdunlap/othello

original_code:
_Bool play_piece_or_legal_move (int play,othello_bd *bd,int x,int y) {
  if (bd->board[x][y]) {
    return 0;
  }
  int legal_move = 0;
  for (int x_dir = -1 ; x_dir <= 1 ; ++x_dir) {
    for (int y_dir = -1 ; y_dir <= 1 ; y_dir += (x_dir ? 1 : 2)) {
      int max_x = x;
      int max_y = y;
      _Bool on_board = 1;
      do {
        max_x += x_dir;
        max_y += y_dir;
      } while ((on_board = (max_x >= 0 && max_y >= 0 && max_x < 8 && max_y < 8)) && bd->board[max_x][max_y] == -bd->turn);
      if (on_board && bd->board[max_x][max_y] == bd->turn) {
        int cur_x = x+x_dir;
        int cur_y = y+y_dir;
        for ( ; cur_x*x_dir < max_x*x_dir || cur_y*y_dir < max_y*y_dir ; cur_x += x_dir, cur_y += y_dir) {
          if (play) {
            legal_move = 1;
            bd->board[cur_x][cur_y] = bd->turn;
          } else {
            return 1;
          }
        }
      }
    }
  }
  if (play && legal_move) {
    bd->just_passed = 0;
    bd->board[x][y] = bd->turn;
    bd->turn = -(bd->turn);
  }
  return legal_move;
}

canonical_original_code:
_Bool play_piece_or_legal_move(int play, struct othello_bd *bd, int x, int y) {
  if (bd->board[x][y]) {
    return 0;
  }
  int legal_move = 0;
  for (int x_dir = -1; x_dir <= 1 ; ++x_dir) {
    for (int y_dir = -1; y_dir <= 1 ; y_dir += (x_dir ? 1 : 2)) {
      int max_x = x;
      int max_y = y;
      _Bool on_board = 1;
      do {
        max_x += x_dir;
        max_y += y_dir;
      } while ((on_board = (max_x >= 0 && max_y >= 0 && max_x < 8 && max_y < 8)) && bd->board[max_x][max_y] == -bd->turn);
      if (on_board && bd->board[max_x][max_y] == bd->turn) {
        int cur_x = x+x_dir;
        int cur_y = y+y_dir;
        for ( ; cur_x*x_dir < max_x*x_dir || cur_y*y_dir < max_y*y_dir ; cur_x += x_dir, cur_y += y_dir) {
          if (play) {
            legal_move = 1;
            bd->board[cur_x][cur_y] = bd->turn;
          } else {
            return 1;
          }
        }
      }
    }
  }
  if (play && legal_move) {
    bd->just_passed = 0;
    bd->board[x][y] = bd->turn;
    bd->turn = -(bd->turn);
  }
  return legal_move;
}

variable_types: play int

variable_types: struct othello_bd { char board[8][8]; char turn; char just_passed; } *


decompiled_code:
__int64 __fastcall play_piece_if_legal(__int64 a1, signed int a2, signed int a3)
{
return (unsigned __int8)play_piece_or_legal_move(1, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, signed int a2, signed int a3)
{
return (unsigned __int8)func0(1, a1, a2, a3);
}

original_code:
int play_piece_if_legal (othello_bd *bd,int x,int y) {
  return play_piece_or_legal_move (1,bd,x,y);
}

canonical_original_code:
int play_piece_if_legal(struct othello_bd *bd, int x, int y) {
  return play_piece_or_legal_move (1,bd,x,y);
}

return_type: int

user_defined_types: struct othello_bd { char board[8][8]; char turn; char just_passed; }


decompiled_code:
__int64 __fastcall legal_move(__int64 a1, signed int a2, signed int a3)
{
return (unsigned __int8)play_piece_or_legal_move(0, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, signed int a2, signed int a3)
{
return (unsigned __int8)func0(0, a1, a2, a3);
}

original_code:
int legal_move (othello_bd *bd,int x,int y) {
  return play_piece_or_legal_move(0,bd,x,y);
}

canonical_original_code:
int legal_move(struct othello_bd *bd, int x, int y) {
  return play_piece_or_legal_move(0,bd,x,y);
}


decompiled_code:
__int64 __fastcall have_legal_moves(__int64 a1)
{
signed int v1; // ebp
signed int i; // ebx
__int64 result; // rax

v1 = 0;
while ( 2 )
{
for ( i = 0; i != 8; ++i )
{
result = legal_move(a1, v1, i);
if ( (_DWORD)result )
return 1LL;
}
if ( ++v1 != 8 )
continue;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
signed int v1; // ebp
signed int i; // ebx
__int64 result; // rax

v1 = 0;
while ( 2 )
{
for ( i = 0; i != 8; ++i )
{
result = func2(a1, v1, i);
if ( (_DWORD)result )
return 1LL;
}
if ( ++v1 != 8 )
continue;
break;
}
return result;
}

original_code:
int have_legal_moves (othello_bd *bd) {
  for (int i = 0 ; i < 8 ; ++i) {
    for (int j = 0 ; j < 8 ; ++j) {
      if (legal_move(bd,i,j)) {
        return 1;
      }
    }
  }
  return 0;
}

canonical_original_code:
int have_legal_moves(struct othello_bd *bd) {
  for (int i = 0; i < 8 ; ++i) {
    for (int j = 0; j < 8 ; ++j) {
      if (legal_move(bd,i,j)) {
        return 1;
      }
    }
  }
  return 0;
}

variable_types: i int

variable_types: j int


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

*(_BYTE *)(a1 + 64) = -*(_BYTE *)(a1 + 64);
result = 1LL;
if ( !*(_BYTE *)(a1 + 65) )
{
*(_BYTE *)(a1 + 65) = 1;
result = 0LL;
}
return result;
}

original_code:
int pass_turn_is_game_over (othello_bd *bd) {
  bd->turn = -(bd->turn);
  if (bd->just_passed) {
    return 1;
  } else {
    bd->just_passed = 1;
    return 0;
  }
}

canonical_original_code:
int pass_turn_is_game_over(struct othello_bd *bd) {
  bd->turn = -(bd->turn);
  if (bd->just_passed) {
    return 1;
  } else {
    bd->just_passed = 1;
    return 0;
  }
}


decompiled_code:
__int64 __fastcall random_move(__int64 a1, unsigned int *a2, unsigned int *a3)
{
char v3; // r13
int v4; // ebp
unsigned int v5; // ebx
unsigned int i; // er14
__int64 result; // rax
int v8; // eax
int v9; // edx
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
do
{
for ( i = 0; i != 8; ++i )
{
while ( 1 )
{
result = legal_move(a1, v5, i);
if ( (_DWORD)result )
{
v8 = rand();
++v4;
v3 = 1;
v9 = v8 % v4;
result = (unsigned int)(v8 / v4);
if ( !v9 )
break;
}
if ( ++i == 8 )
goto LABEL_7;
}
result = (__int64)a3;
*a2 = v5;
*a3 = i;
}
LABEL_7:
++v5;
}
while ( v5 != 8 );
if ( !v3 )
{
result = (__int64)a3;
*a2 = -1;
*a3 = -1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int *a2, unsigned int *a3)
{
char v3; // r13
int v4; // ebp
unsigned int v5; // ebx
unsigned int i; // er14
__int64 result; // rax
int v8; // eax
int v9; // edx
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF

v3 = 0;
v4 = 0;
v5 = 0;
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
do
{
for ( i = 0; i != 8; ++i )
{
while ( 1 )
{
result = legal_move(a1, v5, i);
if ( (_DWORD)result )
{
v8 = rand();
++v4;
v3 = 1;
v9 = v8 % v4;
result = (unsigned int)(v8 / v4);
if ( !v9 )
break;
}
if ( ++i == 8 )
goto LABEL_7;
}
result = (__int64)a3;
*a2 = v5;
*a3 = i;
}
LABEL_7:
++v5;
}
while ( v5 != 8 );
if ( !v3 )
{
result = (__int64)a3;
*a2 = -1;
*a3 = -1;
}
return result;
}

original_code:
void random_move (othello_bd *bd, int *x, int *y) {
  int sofar = 0;
  struct timeval cur;
  gettimeofday(&cur,((void *)0));
  srand(cur.tv_usec);
  _Bool has_move = 0;
  for (int i = 0 ; i < 8 ; ++i) {
    for (int j = 0 ; j < 8 ; ++j) {
      if (legal_move(bd,i,j)) {
        has_move = 1;
        ++sofar;
        int n = rand() % sofar;
        if (0 == n) {
          *x = i;
          *y = j;
        }
      }
    }
  }
  if (!has_move) {
    *x = -1;
    *y = -1;
  }
}

canonical_original_code:
void random_move(struct othello_bd *bd, int *x, int *y) {
  int sofar = 0;
  struct timeval cur;
  gettimeofday(&cur,((void *)0));
  srand(cur.tv_usec);
  _Bool has_move = 0;
  for (int i = 0; i < 8 ; ++i) {
    for (int j = 0; j < 8 ; ++j) {
      if (legal_move(bd,i,j)) {
        has_move = 1;
        ++sofar;
        int n = rand() % sofar;
        if (0 == n) {
          *x = i;
          *y = j;
        }
      }
    }
  }
  if (!has_move) {
    *x = -1;
    *y = -1;
  }
}

variable_types:
x
int *

variable_types:
y
int *

variable_types: sofar int

variable_types: n int

return_type: void

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


repo: ajraymond/restartd

decompiled_code:
int dump_config()
{
int result; // eax
__int64 v1; // rbp
int v2; // ebx
__int64 v3; // rsi
const char *v4; // rdx

result = config_process_number;
if ( config_process_number > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
v3 = (unsigned int)v2++;
v4 = (const char *)(v1 + config_process);
v1 += 992LL;
result = printf(
"ID=%d\n name=%s\n regexp=%s\n running=%s\n not_running=%s\n",
v3,
v4,
v4 + 64,
v4 + 448,
v4 + 192);
}
while ( config_process_number > v2 );
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
__int64 v1; // rbp
int v2; // ebx
__int64 v3; // rsi
const char *v4; // rdx

result = config_process_number;
if ( config_process_number > 0 )
{
v1 = 0LL;
v2 = 0;
do
{
v3 = (unsigned int)v2++;
v4 = (const char *)(v1 + config_process);
v1 += 992LL;
result = printf(
"ID=%d\n name=%s\n regexp=%s\n running=%s\n not_running=%s\n",
v3,
v4,
v4 + 64,
v4 + 448,
v4 + 192);
}
while ( config_process_number > v2 );
}
return result;
}

original_code:
void dump_config(void) {
    int i;
    for(i=0; i<config_process_number; i++) {
        printf("ID=%d\n  name=%s\n  regexp=%s\n  running=%s\n  not_running=%s\n", i,
            config_process[i].name,
            config_process[i].regexp,
            config_process[i].running,
            config_process[i].not_running);
    }
}

canonical_original_code:
void dump_config() {
    int i;
    for(i=0; i<config_process_number; i++) {
        printf("ID=%d\n  name=%s\n  regexp=%s\n  running=%s\n  not_running=%s\n", i,
            config_process[i].name,
            config_process[i].regexp,
            config_process[i].running,
            config_process[i].not_running);
    }
}


decompiled_code:
void __fastcall got_signal(int a1)
{
if ( a1 == 15 )
{
syslog(6, "Got SIGTERM. Exiting.");
unlink("/var/run/restartd.pid");
exit(0);
}
if ( a1 == 1 )
{
syslog(6, "Got SIGHUP. Reloading config file.");
read_config();
syslog(6, "Config file has been read. Found %d process to check.", (unsigned int)config_process_number);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 15 )
{
syslog(6, "Got SIGTERM. Exiting.");
unlink("/var/run/restartd.pid");
exit(0);
}
if ( a1 == 1 )
{
syslog(6, "Got SIGHUP. Reloading config file.");
read_config();
syslog(6, "Config file has been read. Found %d process to check.", (unsigned int)config_process_number);
}
}

original_code:
void got_signal(int sig)
{
    if (sig == 15) {
        syslog(6, "Got SIGTERM. Exiting.");
        unlink("/var/run/restartd.pid");
        exit(0);
    }
    if (sig == 1) {
        syslog(6, "Got SIGHUP. Reloading config file.");
        read_config();
        syslog(6,
               "Config file has been read. Found %d process to check.",
               config_process_number);
    }
}

variable_types: sig int


repo: ajrisi/algorithms

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

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

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

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

original_code:
void *dqueue_front(dqueue *q)
{
  if(q == ((void *)0)) {
    return ((void *)0);
  }
  if(q->head == ((void *)0)) {
    return ((void *)0);
  }
  return q->tail->data;
}

canonical_original_code:
void *dqueue_front(struct dqueue_s *q)
{
  if(q == ((void *)0)) {
    return ((void *)0);
  }
  if(q->head == ((void *)0)) {
    return ((void *)0);
  }
  return q->tail->data;
}

variable_types: struct dqueue_s { unsigned int size; struct queue_item_s { void *data; struct queue_item_s *prev; } *head; struct queue_item_s *tail; void *(*itemdup_fn)(void *); void (*itemfree_fn)(void *); } *

return_type: void *

user_defined_types: struct dqueue_s { unsigned int size; struct queue_item_s *head; struct queue_item_s *tail; void *(*itemdup_fn)(void *); void (*itemfree_fn)(void *); }


original_code:
void *dqueue_dequeue(dqueue *q)
{
  queue_item *oldtail;
  void *oldtail_data;
  if(q == ((void *)0)) {
    return ((void *)0);
  }
  if(q->tail == ((void *)0)) {
    return ((void *)0);
  }
  oldtail = q->tail;
  q->tail = oldtail->prev;
  oldtail_data = oldtail->data;
  free(oldtail);
  q->size--;
  if(q->tail == ((void *)0)) {
    q->head = ((void *)0);
  }
  return oldtail_data;
}

canonical_original_code:
void *dqueue_dequeue(struct dqueue_s *q)
{
  struct queue_item_s *oldtail;
  void *oldtail_data;
  if(q == ((void *)0)) {
    return ((void *)0);
  }
  if(q->tail == ((void *)0)) {
    return ((void *)0);
  }
  oldtail = q->tail;
  q->tail = oldtail->prev;
  oldtail_data = oldtail->data;
  free(oldtail);
  q->size--;
  if(q->tail == ((void *)0)) {
    q->head = ((void *)0);
  }
  return oldtail_data;
}

variable_types: struct queue_item_s { void *data; struct queue_item_s *prev; } *


decompiled_code:
__int64 __fastcall dqueue_size(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
unsigned int dqueue_size(dqueue *q)
{
  if(q == ((void *)0)) {
    return 0;
  }
  return q->size;
}

canonical_original_code:
unsigned int dqueue_size(struct dqueue_s *q)
{
  if(q == ((void *)0)) {
    return 0;
  }
  return q->size;
}

return_type: unsigned int

user_defined_types: struct queue_item_s { void *data; struct queue_item_s *prev; }


decompiled_code:
_BOOL8 __fastcall dqueue_isempty(_DWORD *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *a1 == 0;
else
result = 1LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1)
{
_BOOL8 result; // rax

if ( a1 )
result = *a1 == 0;
else
result = 1LL;
return result;
}

original_code:
int dqueue_isempty(dqueue *q)
{
  if(q == ((void *)0)) {
    return 1;
  }
  return (q->size == 0);
}

canonical_original_code:
int dqueue_isempty(struct dqueue_s *q)
{
  if(q == ((void *)0)) {
    return 1;
  }
  return (q->size == 0);
}


decompiled_code:
void __fastcall dqueue_free(void *ptr)
{
void *v2; // rdi
__int64 v3; // rdi
void (*v4)(void); // rax

if ( ptr )
{
while ( 1 )
{
v2 = ptr;
if ( dqueue_isempty(ptr) )
break;
while ( 1 )
{
v3 = dqueue_dequeue((__int64)ptr);
v4 = (void (*)(void))*((_QWORD *)ptr + 4);
if ( !v4 || !v3 )
break;
v4();
v2 = ptr;
if ( dqueue_isempty(ptr) )
goto LABEL_6;
}
}
LABEL_6:
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
void *v2; // rdi
__int64 v3; // rdi
void (*v4)(void); // rax

if ( ptr )
{
while ( 1 )
{
v2 = ptr;
if ( func4(ptr) )
break;
while ( 1 )
{
v3 = func2((__int64)ptr);
v4 = (void (*)(void))*((_QWORD *)ptr + 4);
if ( !v4 || !v3 )
break;
v4();
v2 = ptr;
if ( func4(ptr) )
goto LABEL_6;
}
}
LABEL_6:
free(v2);
}
}

original_code:
void dqueue_free(dqueue *q)
{
  void *tmp;
  if(q == ((void *)0)) {
    return;
  }
  while(!dqueue_isempty(q)) {
    tmp = dqueue_dequeue(q);
    if((q->itemfree_fn != ((void *)0)) &&
       (tmp != ((void *)0))) {
      q->itemfree_fn(tmp);
    }
  }
  free(q);
}

canonical_original_code:
void dqueue_free(struct dqueue_s *q)
{
  void *tmp;
  if(q == ((void *)0)) {
    return;
  }
  while(!dqueue_isempty(q)) {
    tmp = dqueue_dequeue(q);
    if((q->itemfree_fn != ((void *)0)) &&
       (tmp != ((void *)0))) {
      q->itemfree_fn(tmp);
    }
  }
  free(q);
}

variable_types:
tmp
void *


variable_types: struct prng_s { unsigned long long u; unsigned long long v; unsigned long long w; } *

variable_types:
x
unsigned long long

return_type: unsigned long long


decompiled_code:
double __fastcall prng_d(__int64 *a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = prng_ll(a1);
if ( v1 < 0 )
result = ((double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)))
* 5.421010862427522e-20;
else
result = (double)(int)v1 * 5.421010862427522e-20;
return result;
}

canonical_original_code:
double prng_d(struct prng_s *r)
{
  return 5.42101086242752217E-20 * prng_ll(r);
}

return_type: double

user_defined_types: struct prng_s { unsigned long long u; unsigned long long v; unsigned long long w; }


decompiled_code:
// attributes: thunk
__int64 __fastcall prng_ui(__int64 *a1)
{
return prng_ll(a1);
}

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

original_code:
unsigned int prng_ui(prng *r)
{
  return (unsigned int)prng_ll(r);
}

canonical_original_code:
unsigned int prng_ui(struct prng_s *r)
{
  return (unsigned int)prng_ll(r);
}


decompiled_code:
void __fastcall prng_free(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void prng_free(prng *r)
{
  if(r == ((void *)0)) {
    return;
  }
  free(r);
}

canonical_original_code:
void prng_free(struct prng_s *r)
{
  if(r == ((void *)0)) {
    return;
  }
  free(r);
}


decompiled_code:
__int64 __fastcall row_col_to_1d(int a1, int a2, int a3)
{
return (unsigned int)(a3 * a1 + a2);
}

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

original_code:
static int row_col_to_1d(int row, int col, int width)
{
  return(row*width)+col;
}

variable_types: row int

variable_types: col int

variable_types: width int


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

result = 0xFFFFFFFFLL;
if ( a1 )
result = (unsigned int)find_next_free_vertex_isra_0(*(_DWORD *)a1, *(_QWORD *)(a1 + 16), *(_DWORD *)(a1 + 28)) == -1;
return result;
}

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

result = 0xFFFFFFFFLL;
if ( a1 )
result = (unsigned int)func1(*(_DWORD *)a1, *(_QWORD *)(a1 + 16), *(_DWORD *)(a1 + 28)) == -1;
return result;
}

original_code:
int graph_isfull(graph *g)
{
  if(g == ((void *)0)) {
    return -1;
  }
  return (find_next_free_vertex(g) == -1);
}

canonical_original_code:
int graph_isfull(struct graph_s *g)
{
  if(g == ((void *)0)) {
    return -1;
  }
  return (find_next_free_vertex(g) == -1);
}

variable_types: struct graph_s { int max_verticies; void **edges; void **verticies; int nedges; int nverticies; int next_free_vertex; void *(*dupedge_fn)(void *); void *(*dupvertex_fn)(void *); void (*freeedge_fn)(void *); void (*freevertex_fn)(void *); } *


original_code:
int graph_add_vertex(graph *g, void *vertex)
{
  int v_index;
  void *add_vertex;
  if(g == ((void *)0)) {
    return -1;
  }
  v_index = find_next_free_vertex(g);
  if(v_index == -1) {
    return -1;
  }
  if(g->dupvertex_fn != ((void *)0)) {
    add_vertex = g->dupvertex_fn(vertex);
  } else {
    add_vertex = vertex;
  }
  g->verticies[v_index] = add_vertex;
  return g->nverticies++;
}

canonical_original_code:
int graph_add_vertex(struct graph_s *g, void *vertex)
{
  int v_index;
  void *add_vertex;
  if(g == ((void *)0)) {
    return -1;
  }
  v_index = find_next_free_vertex(g);
  if(v_index == -1) {
    return -1;
  }
  if(g->dupvertex_fn != ((void *)0)) {
    add_vertex = g->dupvertex_fn(vertex);
  } else {
    add_vertex = vertex;
  }
  g->verticies[v_index] = add_vertex;
  return g->nverticies++;
}

variable_types:
vertex
void *

user_defined_types: struct graph_s { int max_verticies; void **edges; void **verticies; int nedges; int nverticies; int next_free_vertex; void *(*dupedge_fn)(void *); void *(*dupvertex_fn)(void *); void (*freeedge_fn)(void *); void (*freevertex_fn)(void *); }


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

if ( a1 && *(_DWORD *)a1 > a2 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
else
result = 0LL;
return result;
}

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

if ( a1 && *(_DWORD *)a1 > a2 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
else
result = 0LL;
return result;
}

original_code:
void *graph_get_vertex(graph *g, int vertex)
{
  if(g == ((void *)0)) {
    return ((void *)0);
  }
  if(vertex >= g->max_verticies) {
    return ((void *)0);
  }
  return g->verticies[vertex];
}

canonical_original_code:
void *graph_get_vertex(struct graph_s *g, int vertex)
{
  if(g == ((void *)0)) {
    return ((void *)0);
  }
  if(vertex >= g->max_verticies) {
    return ((void *)0);
  }
  return g->verticies[vertex];
}

variable_types: vertex int


decompiled_code:
__int64 __fastcall graph_nedges_dst(int *a1, int a2)
{
int v2; // edx
int i; // ecx
int v4; // eax
__int64 v5; // r9
int v6; // er8
unsigned int v7; // er8
int v8; // ecx

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
if ( *a1 <= a2 )
return (unsigned int)-1;
if ( v2 > 0 )
{
for ( i = 0; i != v2; i = v8 + 1 )
{
v4 = row_col_to_1d(i, a2, v2);
v7 = v6 - ((*(_QWORD *)(v5 + 8LL * v4) == 0LL) - 1);
}
return v7;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, int a2)
{
int v2; // edx
int i; // ecx
int v4; // eax
__int64 v5; // r9
int v6; // er8
unsigned int v7; // er8
int v8; // ecx

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
if ( *a1 <= a2 )
return (unsigned int)-1;
if ( v2 > 0 )
{
for ( i = 0; i != v2; i = v8 + 1 )
{
v4 = func0(i, a2, v2);
v7 = v6 - ((*(_QWORD *)(v5 + 8LL * v4) == 0LL) - 1);
}
return v7;
}
return 0LL;
}

original_code:
int graph_nedges_dst(graph *g, int vertex)
{
  int i;
  int edge_index;
  int total_edges;
  if(g == ((void *)0)) {
    return -1;
  }
  if(vertex >= g->max_verticies) {
    return -1;
  }
  total_edges = 0;
  for(i = 0; i < g->max_verticies; i++) {
    edge_index = row_col_to_1d(i, vertex, g->max_verticies);
    if(g->edges[edge_index] != ((void *)0)) {
      total_edges++;
    }
  }
  return total_edges;
}

canonical_original_code:
int graph_nedges_dst(struct graph_s *g, int vertex)
{
  int i;
  int edge_index;
  int total_edges;
  if(g == ((void *)0)) {
    return -1;
  }
  if(vertex >= g->max_verticies) {
    return -1;
  }
  total_edges = 0;
  for(i = 0; i < g->max_verticies; i++) {
    edge_index = row_col_to_1d(i, vertex, g->max_verticies);
    if(g->edges[edge_index] != ((void *)0)) {
      total_edges++;
    }
  }
  return total_edges;
}

variable_types: i int


decompiled_code:
__int64 __fastcall graph_nedges_src(int *a1, int a2)
{
int v3; // edx
int i; // ecx
int v5; // eax
__int64 v6; // r10
int v7; // er8
unsigned int v8; // er8
int v9; // ecx

if ( !a1 )
return (unsigned int)-1;
v3 = *a1;
if ( *a1 <= a2 )
return (unsigned int)-1;
if ( v3 > 0 )
{
for ( i = 0; i != v3; i = v9 + 1 )
{
v5 = row_col_to_1d(a2, i, v3);
v8 = v7 - ((*(_QWORD *)(v6 + 8LL * v5) == 0LL) - 1);
}
return v8;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int *a1, int a2)
{
int v3; // edx
int i; // ecx
int v5; // eax
__int64 v6; // r10
int v7; // er8
unsigned int v8; // er8
int v9; // ecx

if ( !a1 )
return (unsigned int)-1;
v3 = *a1;
if ( *a1 <= a2 )
return (unsigned int)-1;
if ( v3 > 0 )
{
for ( i = 0; i != v3; i = v9 + 1 )
{
v5 = func0(a2, i, v3);
v8 = v7 - ((*(_QWORD *)(v6 + 8LL * v5) == 0LL) - 1);
}
return v8;
}
return 0LL;
}

original_code:
int graph_nedges_src(graph *g, int vertex)
{
  int i;
  int edge_index;
  int total_edges;
  if(g == ((void *)0)) {
    return -1;
  }
  if(vertex >= g->max_verticies) {
    return -1;
  }
  total_edges = 0;
  for(i = 0; i < g->max_verticies; i++) {
    edge_index = row_col_to_1d(vertex, i, g->max_verticies);
    if(g->edges[edge_index] != ((void *)0)) {
      total_edges++;
    }
  }
  return total_edges;
}

canonical_original_code:
int graph_nedges_src(struct graph_s *g, int vertex)
{
  int i;
  int edge_index;
  int total_edges;
  if(g == ((void *)0)) {
    return -1;
  }
  if(vertex >= g->max_verticies) {
    return -1;
  }
  total_edges = 0;
  for(i = 0; i < g->max_verticies; i++) {
    edge_index = row_col_to_1d(vertex, i, g->max_verticies);
    if(g->edges[edge_index] != ((void *)0)) {
      total_edges++;
    }
  }
  return total_edges;
}


decompiled_code:
__int64 __fastcall graph_nedges(int *a1, int a2)
{
int *v2; // r11
int v3; // eax
int v4; // er10

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *a1 <= a2 )
return 0xFFFFFFFFLL;
graph_nedges_src(a1, a2);
v3 = graph_nedges_dst(v2, a2);
return (unsigned int)(v4 + v3);
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1, int a2)
{
int *v2; // r11
int v3; // eax
int v4; // er10

if ( !a1 )
return 0xFFFFFFFFLL;
if ( *a1 <= a2 )
return 0xFFFFFFFFLL;
func6(a1, a2);
v3 = func5(v2, a2);
return (unsigned int)(v4 + v3);
}

original_code:
int graph_nedges(graph *g, int vertex)
{
  int total_edges;
  if(g == ((void *)0)) {
    return -1;
  }
  if(vertex >= g->max_verticies) {
    return -1;
  }
  total_edges = 0;
  total_edges += graph_nedges_src(g, vertex);
  total_edges += graph_nedges_dst(g, vertex);
  return total_edges;
}

canonical_original_code:
int graph_nedges(struct graph_s *g, int vertex)
{
  int total_edges;
  if(g == ((void *)0)) {
    return -1;
  }
  if(vertex >= g->max_verticies) {
    return -1;
  }
  total_edges = 0;
  total_edges += graph_nedges_src(g, vertex);
  total_edges += graph_nedges_dst(g, vertex);
  return total_edges;
}


decompiled_code:
__int64 __fastcall graph_get_edge_dst(_DWORD *a1, int a2)
{
unsigned int v2; // er8

if ( a1 )
v2 = a2 % *a1;
else
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, int a2)
{
unsigned int v2; // er8

if ( a1 )
v2 = a2 % *a1;
else
v2 = -1;
return v2;
}

original_code:
int graph_get_edge_dst(graph *g, int edge_index)
{
  if(g == ((void *)0)) {
    return -1;
  }
  return edge_index % g->max_verticies;
}

canonical_original_code:
int graph_get_edge_dst(struct graph_s *g, int edge_index)
{
  if(g == ((void *)0)) {
    return -1;
  }
  return edge_index % g->max_verticies;
}


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

if ( a1 )
result = (unsigned int)((int)(a2 - graph_get_edge_dst(a1, a2)) / *a1);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = (unsigned int)((int)(a2 - func8(a1, a2)) / *a1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int graph_get_edge_src(graph *g, int edge_index)
{
  if(g == ((void *)0)) {
    return -1;
  }
  return (edge_index - graph_get_edge_dst(g, edge_index)) / g->max_verticies;
}

canonical_original_code:
int graph_get_edge_src(struct graph_s *g, int edge_index)
{
  if(g == ((void *)0)) {
    return -1;
  }
  return (edge_index - graph_get_edge_dst(g, edge_index)) / g->max_verticies;
}


decompiled_code:
__int64 __fastcall graph_get_edge(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
int v4; // ecx
int v5; // eax
__int64 v6; // rcx

if ( !a1 )
return 0LL;
v2 = graph_get_edge_src((_DWORD *)a1, a2);
result = graph_get_vertex(a1, v2);
if ( result )
{
v5 = graph_get_edge_dst((_DWORD *)a1, v4);
result = graph_get_vertex(a1, v5);
if ( result )
{
if ( *(_DWORD *)a1 * *(_DWORD *)a1 > (int)v6 )
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v6);
return 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
int v4; // ecx
int v5; // eax
__int64 v6; // rcx

if ( !a1 )
return 0LL;
v2 = func9((_DWORD *)a1, a2);
result = func4(a1, v2);
if ( result )
{
v5 = func8((_DWORD *)a1, v4);
result = func4(a1, v5);
if ( result )
{
if ( *(_DWORD *)a1 * *(_DWORD *)a1 > (int)v6 )
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v6);
return 0LL;
}
}
return result;
}

original_code:
void *graph_get_edge(graph *g, int edge_index)
{
  if(g == ((void *)0)) {
    return ((void *)0);
  }
  if((graph_get_vertex(g, graph_get_edge_src(g, edge_index)) == ((void *)0)) ||
     (graph_get_vertex(g, graph_get_edge_dst(g, edge_index)) == ((void *)0))) {
    return ((void *)0);
  }
  if(edge_index >= (g->max_verticies)*(g->max_verticies)) {
    return ((void *)0);
  }
  return g->edges[edge_index];
}

canonical_original_code:
void *graph_get_edge(struct graph_s *g, int edge_index)
{
  if(g == ((void *)0)) {
    return ((void *)0);
  }
  if((graph_get_vertex(g, graph_get_edge_src(g, edge_index)) == ((void *)0)) ||
     (graph_get_vertex(g, graph_get_edge_dst(g, edge_index)) == ((void *)0))) {
    return ((void *)0);
  }
  if(edge_index >= (g->max_verticies)*(g->max_verticies)) {
    return ((void *)0);
  }
  return g->edges[edge_index];
}


decompiled_code:
void __fastcall graph_remove_edge(__int64 a1, int a2)
{
int v3; // eax
int v4; // eax
__int64 v5; // rdi
void (__fastcall *v6)(__int64); // rax

if ( a1 )
{
v3 = graph_get_edge_src((_DWORD *)a1, a2);
if ( graph_get_vertex(a1, v3) )
{
v4 = graph_get_edge_dst((_DWORD *)a1, a2);
if ( graph_get_vertex(a1, v4) )
{
v5 = graph_get_edge(a1, a2);
if ( v5 )
{
v6 = *(void (__fastcall **)(__int64))(a1 + 56);
if ( v6 )
v6(v5);
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2) = 0LL;
--*(_DWORD *)(a1 + 24);
}
}
}
}
}

original_code:
void graph_remove_edge(graph *g, int edge_index)
{
  void *edge_to_remove;
  if(g == ((void *)0)) {
    return;
  }
  if((graph_get_vertex(g, graph_get_edge_src(g, edge_index)) == ((void *)0)) ||
     (graph_get_vertex(g, graph_get_edge_dst(g, edge_index)) == ((void *)0))) {
    return;
  }
  edge_to_remove = graph_get_edge(g, edge_index);
  if(edge_to_remove == ((void *)0)) {
    return;
  }
  if(g->freeedge_fn != ((void *)0)) {
    g->freeedge_fn(edge_to_remove);
  }
  g->edges[edge_index] = ((void *)0);
  g->nedges--;
}

canonical_original_code:
void graph_remove_edge(struct graph_s *g, int edge_index)
{
  void *edge_to_remove;
  if(g == ((void *)0)) {
    return;
  }
  if((graph_get_vertex(g, graph_get_edge_src(g, edge_index)) == ((void *)0)) ||
     (graph_get_vertex(g, graph_get_edge_dst(g, edge_index)) == ((void *)0))) {
    return;
  }
  edge_to_remove = graph_get_edge(g, edge_index);
  if(edge_to_remove == ((void *)0)) {
    return;
  }
  if(g->freeedge_fn != ((void *)0)) {
    g->freeedge_fn(edge_to_remove);
  }
  g->edges[edge_index] = ((void *)0);
  g->nedges--;
}


original_code:
int graph_add_edge(graph *g, void *edge_data, int vertex_from, int vertex_to)
{
  int edge_index;
  void *edge_data_copy;
  if(g == ((void *)0)) {
    return -1;
  }
  if((graph_get_vertex(g, vertex_from) == ((void *)0)) ||
     (graph_get_vertex(g, vertex_to) == ((void *)0))) {
    return -1;
  }
  edge_index = row_col_to_1d(vertex_from, vertex_to, g->max_verticies);
  if(g->dupedge_fn != ((void *)0)) {
    edge_data_copy = g->dupedge_fn(edge_data);
  } else {
    edge_data_copy = edge_data;
  }
  if(g->edges[edge_index] != ((void *)0)) {
    graph_remove_edge(g, edge_index);
  }
  g->edges[edge_index] = edge_data_copy;
  g->nedges++;
  return edge_index;
}

canonical_original_code:
int graph_add_edge(struct graph_s *g, void *edge_data, int vertex_from, int vertex_to)
{
  int edge_index;
  void *edge_data_copy;
  if(g == ((void *)0)) {
    return -1;
  }
  if((graph_get_vertex(g, vertex_from) == ((void *)0)) ||
     (graph_get_vertex(g, vertex_to) == ((void *)0))) {
    return -1;
  }
  edge_index = row_col_to_1d(vertex_from, vertex_to, g->max_verticies);
  if(g->dupedge_fn != ((void *)0)) {
    edge_data_copy = g->dupedge_fn(edge_data);
  } else {
    edge_data_copy = edge_data;
  }
  if(g->edges[edge_index] != ((void *)0)) {
    graph_remove_edge(g, edge_index);
  }
  g->edges[edge_index] = edge_data_copy;
  g->nedges++;
  return edge_index;
}


decompiled_code:
void __fastcall graph_remove_vertex(__int64 a1, int a2)
{
int v3; // edx
int v4; // ebp
int v5; // eax
int v6; // edi
int v7; // eax
__int64 v8; // rax
void (__fastcall *v9)(__int64); // rdx

if ( a1 )
{
v3 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 > a2 )
{
if ( *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) )
{
if ( v3 > 0 )
{
v4 = 0;
do
{
v5 = row_col_to_1d(a2, v4, v3);
graph_remove_edge(a1, v5);
v6 = v4++;
v7 = row_col_to_1d(v6, a2, *(_DWORD *)a1);
graph_remove_edge(a1, v7);
v3 = *(_DWORD *)a1;
}
while ( *(_DWORD *)a1 > v4 );
}
if ( *(_QWORD *)(a1 + 64) )
{
v8 = graph_get_vertex(a1, a2);
v9(v8);
}
*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) = 0LL;
--*(_DWORD *)(a1 + 28);
}
}
}
}

original_code:
void graph_remove_vertex(graph *g, int vertex)
{
  int i;
  if(g == ((void *)0)) {
    return;
  }
  if(vertex >= g->max_verticies) {
    return;
  }
  if(g->verticies[vertex] == ((void *)0)) {
    return;
  }
  for(i = 0; i < g->max_verticies; i++) {
    graph_remove_edge(g, row_col_to_1d(vertex, i, g->max_verticies));
    graph_remove_edge(g, row_col_to_1d(i, vertex, g->max_verticies));
  }
  if(g->freevertex_fn != ((void *)0)) {
    g->freevertex_fn(graph_get_vertex(g, vertex));
  }
  g->verticies[vertex] = ((void *)0);
  g->nverticies--;
}

canonical_original_code:
void graph_remove_vertex(struct graph_s *g, int vertex)
{
  int i;
  if(g == ((void *)0)) {
    return;
  }
  if(vertex >= g->max_verticies) {
    return;
  }
  if(g->verticies[vertex] == ((void *)0)) {
    return;
  }
  for(i = 0; i < g->max_verticies; i++) {
    graph_remove_edge(g, row_col_to_1d(vertex, i, g->max_verticies));
    graph_remove_edge(g, row_col_to_1d(i, vertex, g->max_verticies));
  }
  if(g->freevertex_fn != ((void *)0)) {
    g->freevertex_fn(graph_get_vertex(g, vertex));
  }
  g->verticies[vertex] = ((void *)0);
  g->nverticies--;
}


decompiled_code:
void __fastcall graph_free(void *ptr)
{
int v1; // ebx
int v2; // esi

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0;
do
{
v2 = v1++;
graph_remove_vertex((__int64)ptr, v2);
}
while ( *(_DWORD *)ptr > v1 );
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
int v1; // ebx
int v2; // esi

if ( ptr )
{
if ( *(int *)ptr > 0 )
{
v1 = 0;
do
{
v2 = v1++;
func13((__int64)ptr, v2);
}
while ( *(_DWORD *)ptr > v1 );
}
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
}

original_code:
void graph_free(graph *g)
{
  int i;
  if(g == ((void *)0)) {
    return;
  }
  for(i = 0; i < g->max_verticies; i++) {
    graph_remove_vertex(g, i);
  }
  free(g->edges);
  free(g->verticies);
  free(g);
}

canonical_original_code:
void graph_free(struct graph_s *g)
{
  int i;
  if(g == ((void *)0)) {
    return;
  }
  for(i = 0; i < g->max_verticies; i++) {
    graph_remove_vertex(g, i);
  }
  free(g->edges);
  free(g->verticies);
  free(g);
}


ithprime

decompiled_code:
__int64 __fastcall ithprime(unsigned __int64 a1)
{
__int64 result; // rax
int v2; // edx

result = 0LL;
if ( a1 <= 0x14 )
{
v2 = primetbl[a1];
if ( v2 )
result = (1 << (a1 + 8)) - v2;
}
return result;
}

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

result = 0LL;
if ( a1 <= 0x14 )
{
v2 = primetbl[a1];
if ( v2 )
result = (1 << (a1 + 8)) - v2;
}
return result;
}

original_code:
static unsigned long ithprime(size_t i)
{
  if ((i < sizeof primetbl / sizeof (int)) && (primetbl[i])) {
    return ((1 << (8 + i)) - primetbl[i]);
  } else {
    return 0;
  }
}

canonical_original_code:
static unsigned long ithprime(unsigned long i)
{
  if ((i < sizeof primetbl / sizeof (int)) && (primetbl[i])) {
    return ((1 << (8 + i)) - primetbl[i]);
  } else {
    return 0;
  }
}

variable_types:
i
unsigned long

return_type: unsigned long


inserted

original_code:
static void *inserted(hashtable *master,
        unsigned long h,
        void *item,
        int copying)
{
  void *hh;
  master->hstatus.probes++;
  hh = master->htbl[h];
  if (hh == ((void *)0)) {
    if(copying) {
      master->htbl[h] = item;
    } else if ((master->htbl[h] = (master->dupe == ((void *)0)) ? item : master->dupe(item))) {
      master->hstatus.hentries++;
    } else {
      master->hstatus.herror |= hshNOMEM;
    }
  } else if (copying) {
    return ((void *)0);
  } else if (hh == (void*)master) {
    return ((void *)0);
  } else if (0 != master->cmp(master->htbl[h], item)) {
    return ((void *)0);
  }
  return master->htbl[h];
}

canonical_original_code:
static void *inserted(struct hashtable_s *master, unsigned long h, void *item, int copying)
{
  void *hh;
  master->hstatus.probes++;
  hh = master->htbl[h];
  if (hh == ((void *)0)) {
    if(copying) {
      master->htbl[h] = item;
    } else if ((master->htbl[h] = (master->dupe == ((void *)0)) ? item : master->dupe(item))) {
      master->hstatus.hentries++;
    } else {
      master->hstatus.herror |= hshNOMEM;
    }
  } else if (copying) {
    return ((void *)0);
  } else if (hh == (void *)master) {
    return ((void *)0);
  } else if (0 != master->cmp(master->htbl[h], item)) {
    return ((void *)0);
  }
  return master->htbl[h];
}

variable_types: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 } herror; } hstatus; } *

variable_types:
h
unsigned long

variable_types:
item
void *

variable_types: copying int

variable_types:
hh
void *

user_defined_types: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s hstatus; }

user_defined_types: struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e herror; }


putintbl

original_code:
static void *putintbl(hashtable *master, void *item, int copying)
{
  unsigned long h;
  unsigned long h2;
  void *stored;
  h = master->hash(item) % master->size;
  stored = inserted(master, h, item, copying);
  if ((stored == ((void *)0)) &&
      (master->hstatus.herror == hshOK)) {
    h2 = master->rehash(item) % (master->size >> 3) + 1;
    do {
      master->hstatus.misses++;
      h = (h + h2) % master->size;
      stored = inserted(master, h, item, copying);
    } while ((stored == ((void *)0)) &&
      (master->hstatus.herror == hshOK));
  }
  return stored;
}

canonical_original_code:
static void *putintbl(struct hashtable_s *master, void *item, int copying)
{
  unsigned long h;
  unsigned long h2;
  void *stored;
  h = master->hash(item) % master->size;
  stored = inserted(master, h, item, copying);
  if ((stored == ((void *)0)) &&
      (master->hstatus.herror == hshOK)) {
    h2 = master->rehash(item) % (master->size >> 3) + 1;
    do {
      master->hstatus.misses++;
      h = (h + h2) % master->size;
      stored = inserted(master, h, item, copying);
    } while ((stored == ((void *)0)) &&
      (master->hstatus.herror == hshOK));
  }
  return stored;
}

variable_types:
stored
void *

user_defined_types: enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 }


found

decompiled_code:
_BOOL8 __fastcall found(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v5; // rdx
__int64 *v7; // rdi
_BOOL8 result; // rax

v5 = *a1;
++a1[7];
v7 = *(__int64 **)(v5 + 8 * a2);
if ( !v7 || a1 == v7 )
result = 0LL;
else
result = ((unsigned int (__fastcall *)(__int64 *, __int64))a1[4])(v7, a3) == 0;
return result;
}

original_code:
static int found(hashtable *master, unsigned long h, void *item)
{
  void *hh;
  master->hstatus.probes++;
  hh = master->htbl[h];
  if((hh == ((void *)0)) ||
     (hh == (void*)master)) {
    return 0;
  }
  return !(master->cmp(hh, item));
}

canonical_original_code:
static int found(struct hashtable_s *master, unsigned long h, void *item)
{
  void *hh;
  master->hstatus.probes++;
  hh = master->htbl[h];
  if((hh == ((void *)0)) ||
     (hh == (void *)master)) {
    return 0;
  }
  return !(master->cmp(hh, item));
}


huntup

original_code:
static unsigned long huntup(hashtable *master, void *item)
{
  unsigned long h;
  unsigned long h2;
  h = master->hash(item) % master->size;
  if (!(found(master, h, item)) && master->htbl[h]) {
    h2 = master->rehash(item) % (master->size >> 3) + 1;
    do {
      master->hstatus.misses++;
      h = (h + h2) % master->size;
    } while (!(found(master, h, item)) && (master->htbl[h]));
  }
  return h;
}

canonical_original_code:
static unsigned long huntup(struct hashtable_s *master, void *item)
{
  unsigned long h;
  unsigned long h2;
  h = master->hash(item) % master->size;
  if (!(found(master, h, item)) && master->htbl[h]) {
    h2 = master->rehash(item) % (master->size >> 3) + 1;
    do {
      master->hstatus.misses++;
      h = (h + h2) % master->size;
    } while (!(found(master, h, item)) && (master->htbl[h]));
  }
  return h;
}


reorganize

original_code:
static int reorganize(hashtable *master)
{
  void **newtbl;
  void **oldtbl;
  unsigned long newsize, oldsize;
  unsigned long oldentries, j;
  unsigned int i;
  oldsize = master->size;
  oldtbl = master->htbl;
  oldentries = 0;
  if (master->hstatus.hdeleted > (master->hstatus.hentries / 4))
    newsize = oldsize;
  else {
    newsize = ithprime(0);
    for (i = 1; newsize && (newsize <= oldsize); i++) {
      newsize = ithprime(i);
    }
  }
  if (newsize != 0) {
    newtbl = calloc(newsize, sizeof(*newtbl));
  } else {
    return 0;
  }
  master->size = newsize;
  master->htbl = newtbl;
  for (j = 0; j < oldsize; j++) {
    if ((oldtbl[j] != ((void *)0)) &&
 (oldtbl[j] != (void*)master)) {
      (void) putintbl(master, oldtbl[j], 1);
      oldentries++;
    }
  }
  if (oldentries !=
      (master->hstatus.hentries - master->hstatus.hdeleted)) {
    master->hstatus.herror |= hshINTERR;
    free(master->htbl);
    master->htbl = oldtbl;
    master->size = oldsize;
    return 0;
  } else {
    master->hstatus.hentries = oldentries;
    master->hstatus.hdeleted = 0;
    free(oldtbl);
  }
  return 1;
}

canonical_original_code:
static int reorganize(struct hashtable_s *master)
{
  void **newtbl;
  void **oldtbl;
  unsigned long newsize; unsigned long oldsize;
  unsigned long oldentries; unsigned long j;
  unsigned int i;
  oldsize = master->size;
  oldtbl = master->htbl;
  oldentries = 0;
  if (master->hstatus.hdeleted > (master->hstatus.hentries / 4))
    newsize = oldsize;
  else {
    newsize = ithprime(0);
    for (i = 1; newsize && (newsize <= oldsize); i++) {
      newsize = ithprime(i);
    }
  }
  if (newsize != 0) {
    newtbl = calloc(newsize, sizeof(*newtbl));
  } else {
    return 0;
  }
  master->size = newsize;
  master->htbl = newtbl;
  for (j = 0; j < oldsize; j++) {
    if ((oldtbl[j] != ((void *)0)) &&
 (oldtbl[j] != (void *)master)) {
      (void) putintbl(master, oldtbl[j], 1);
      oldentries++;
    }
  }
  if (oldentries !=
      (master->hstatus.hentries - master->hstatus.hdeleted)) {
    master->hstatus.herror |= hshINTERR;
    free(master->htbl);
    master->htbl = oldtbl;
    master->size = oldsize;
    return 0;
  } else {
    master->hstatus.hentries = oldentries;
    master->hstatus.hdeleted = 0;
    free(oldtbl);
  }
  return 1;
}

variable_types:
newtbl
void **

variable_types:
oldtbl
void **

variable_types:
newsize
unsigned long

variable_types:
oldsize
unsigned long

variable_types:
oldentries
unsigned long

variable_types:
j
unsigned long

variable_types:
i
unsigned int


decompiled_code:
void __fastcall hashtable_free(void *ptr)
{
_QWORD *v2; // r8
unsigned __int64 v3; // rbx
void *v4; // rdi
void (*v5)(void); // rax

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *((_QWORD *)ptr + 1) )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 && ptr != v4 )
{
v5 = (void (*)(void))*((_QWORD *)ptr + 6);
if ( v5 )
{
v5();
v2 = *(_QWORD **)ptr;
}
}
++v3;
}
while ( *((_QWORD *)ptr + 1) > v3 );
}
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
_QWORD *v2; // r8
unsigned __int64 v3; // rbx
void *v4; // rdi
void (*v5)(void); // rax

if ( ptr )
{
v2 = *(_QWORD **)ptr;
if ( *((_QWORD *)ptr + 1) )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 && ptr != v4 )
{
v5 = (void (*)(void))*((_QWORD *)ptr + 6);
if ( v5 )
{
v5();
v2 = *(_QWORD **)ptr;
}
}
++v3;
}
while ( *((_QWORD *)ptr + 1) > v3 );
}
free(v2);
free(ptr);
}
}

original_code:
void hashtable_free(hashtable *m)
{
  unsigned long i;
  void *h;
  if(m == ((void *)0)) {
    return;
  }
  for (i = 0; i < m->size; i++) {
    if ((h = m->htbl[i]) && ((void*)m != h)) {
      if(m->undupe != ((void *)0)) {
 m->undupe(m->htbl[i]);
      }
    }
  }
  free(m->htbl);
  free(m);
}

canonical_original_code:
void hashtable_free(struct hashtable_s *m)
{
  unsigned long i;
  void *h;
  if(m == ((void *)0)) {
    return;
  }
  for (i = 0; i < m->size; i++) {
    if ((h = m->htbl[i]) && ((void *)m != h)) {
      if(m->undupe != ((void *)0)) {
 m->undupe(m->htbl[i]);
      }
    }
  }
  free(m->htbl);
  free(m);
}

variable_types:
h
void *


decompiled_code:
__int64 __fastcall hashtable_insert(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0LL;
if ( (__int64)(*(_QWORD *)(a1 + 8) - (*(_QWORD *)(a1 + 8) >> 3) - *(_QWORD *)(a1 + 72)) > 0
|| (unsigned int)reorganize(a1) )
{
return putintbl(a1, a2, 0);
}
*(_DWORD *)(a1 + 88) |= 2u;
return 0LL;
}

original_code:
void *hashtable_insert(hashtable *m, void *item)
{
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  if ((((long)(m->size - (m->size >> 3)) - (long)m->hstatus.hentries) <= 0) && !reorganize(m)) {
    m->hstatus.herror |= hshTBLFULL;
    return ((void *)0);
  }
  return putintbl(m, item, 0);
}

canonical_original_code:
void *hashtable_insert(struct hashtable_s *m, void *item)
{
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  if ((((long)(m->size - (m->size >> 3)) - (long)m->hstatus.hentries) <= 0) && !reorganize(m)) {
    m->hstatus.herror |= hshTBLFULL;
    return ((void *)0);
  }
  return putintbl(m, item, 0);
}


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

if ( a1 )
result = *(_QWORD *)(*a1 + 8 * huntup((__int64)a1, a2));
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(*a1 + 8 * func4((__int64)a1, a2));
else
result = 0LL;
return result;
}

original_code:
void *hashtable_find(hashtable *m, void *item)
{
  unsigned long h;
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  h = huntup(m, item);
  return m->htbl[h];
}

canonical_original_code:
void *hashtable_find(struct hashtable_s *m, void *item)
{
  unsigned long h;
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  h = huntup(m, item);
  return m->htbl[h];
}


decompiled_code:
__int64 __fastcall hashtable_remove(_QWORD *a1, __int64 a2)
{
__int64 *v2; // rdx
__int64 result; // rax

if ( !a1 )
return 0LL;
v2 = (__int64 *)(*a1 + 8 * huntup((__int64)a1, a2));
result = *v2;
if ( *v2 )
{
*v2 = (__int64)a1;
++a1[10];
}
return result;
}

original_code:
void *hashtable_remove(hashtable *m, void *item)
{
  unsigned long h;
  void *olditem;
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  h = huntup(m, item);
  olditem = m->htbl[h];
  if(olditem != ((void *)0)) {
    m->htbl[h] = (void*)m;
    m->hstatus.hdeleted++;
  }
  return olditem;
}

canonical_original_code:
void *hashtable_remove(struct hashtable_s *m, void *item)
{
  unsigned long h;
  void *olditem;
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  h = huntup(m, item);
  olditem = m->htbl[h];
  if(olditem != ((void *)0)) {
    m->htbl[h] = (void *)m;
    m->hstatus.hdeleted++;
  }
  return olditem;
}

variable_types:
olditem
void *


decompiled_code:
__int64 __fastcall hashtable_foreach(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
__int64 v3; // rbx
_QWORD *v6; // rdi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v3 = 0LL;
if ( !a1[1] )
return 0LL;
while ( 1 )
{
v6 = *(_QWORD **)(*a1 + 8 * v3);
if ( v6 )
{
if ( a1 != v6 )
{
result = a2(v6, a3);
if ( (_DWORD)result )
break;
}
}
if ( a1[1] <= (unsigned __int64)++v3 )
return 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD *, __int64), __int64 a3)
{
__int64 v3; // rbx
_QWORD *v6; // rdi
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v3 = 0LL;
if ( !a1[1] )
return 0LL;
while ( 1 )
{
v6 = *(_QWORD **)(*a1 + 8 * v3);
if ( v6 )
{
if ( a1 != v6 )
{
result = a2(v6, a3);
if ( (_DWORD)result )
break;
}
}
if ( a1[1] <= (unsigned __int64)++v3 )
return 0LL;
}
return result;
}

original_code:
int hashtable_foreach(hashtable *m, hshexecfn exec, void *datum)
{
  int err;
  unsigned long i;
  void *hh;
  if ((m == ((void *)0)) ||
      (exec == ((void *)0))) {
    return -1;
  }
  for (i = 0; i < m->size; i++) {
    hh = m->htbl[i];
    if((hh != ((void *)0)) &&
       (hh != (void*)m)) {
      err = exec(hh, datum);
      if(err != 0) {
 return err;
      }
    }
  }
  return 0;
}

canonical_original_code:
int hashtable_foreach(struct hashtable_s *m, int (*exec)(void *item, void *datum), void *datum)
{
  int err;
  unsigned long i;
  void *hh;
  if ((m == ((void *)0)) ||
      (exec == ((void *)0))) {
    return -1;
  }
  for (i = 0; i < m->size; i++) {
    hh = m->htbl[i];
    if((hh != ((void *)0)) &&
       (hh != (void *)m)) {
      err = exec(hh, datum);
      if(err != 0) {
 return err;
      }
    }
  }
  return 0;
}

variable_types:
exec
int (*)(void *item, void *datum)

variable_types:
datum
void *

variable_types: err int


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

result = a1 + 56;
if ( !a1 )
result = 0LL;
return result;
}

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

result = a1 + 56;
if ( !a1 )
result = 0LL;
return result;
}

original_code:
hshstats *hashtable_stats(hashtable *m)
{
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  return &(m->hstatus);
}

canonical_original_code:
struct hshstats_s *hashtable_stats(struct hashtable_s *m)
{
  if(m == ((void *)0)) {
    return ((void *)0);
  }
  return &(m->hstatus);
}

variable_types: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s hstatus; } *

return_type: struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 } herror; } *


hshstrhash

original_code:
unsigned long hshstrhash(const char * string)
{
  unsigned long hash = 0;
  while(*string) {
    hash = *string++ + ( hash << 6 ) + ( hash << 16 ) - hash;
  }
  return hash;
}

canonical_original_code:
unsigned long hshstrhash(char *string)
{
  unsigned long hash = 0;
  while(*string) {
    hash = *string++ + ( hash << 6 ) + ( hash << 16 ) - hash;
  }
  return hash;
}

variable_types:
string
char *

variable_types:
hash
unsigned long


hshstrehash

original_code:
unsigned long hshstrehash(const char * string)
{
  unsigned long hash = 0;
  unsigned long a = 63689;
  unsigned long b = 378551;
  while(*string) {
    hash = hash*a + *string++;
    a *= b;
  }
  return hash;
}

canonical_original_code:
unsigned long hshstrehash(char *string)
{
  unsigned long hash = 0;
  unsigned long a = 63689;
  unsigned long b = 378551;
  while(*string) {
    hash = hash*a + *string++;
    a *= b;
  }
  return hash;
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


original_code:
static trie_node **lookup_node(trie *t, char *key, unsigned int len)
{
  int i;
  trie_node **n;
  if(t == ((void *)0)) {
    return ((void *)0);
  }
  n = &(t->root_node);
  for(i = 0; (i < len-1) && (*n != ((void *)0)); (n = &((*n)->next[ (int)*(key + i) ]), i++))
    ;
  if(i != (len - 1)) {
    return ((void *)0);
  } else {
    return &((*n)->next[ (int)*(key + i) ]);
  }
}

canonical_original_code:
static struct trie_node_s **lookup_node(struct trie_s *t, char *key, unsigned int len)
{
  int i;
  struct trie_node_s **n;
  if(t == ((void *)0)) {
    return ((void *)0);
  }
  n = &(t->root_node);
  for(i = 0; (i < len-1) && (*n != ((void *)0)); (n = &((*n)->next[ (int)*(key + i) ]), i++))
    ;
  if(i != (len - 1)) {
    return ((void *)0);
  } else {
    return &((*n)->next[ (int)*(key + i) ]);
  }
}

variable_types: struct trie_s { struct trie_node_s *root_node; unsigned int size; } *

variable_types:
key
char *

variable_types:
len
unsigned int

variable_types: i int

variable_types: struct trie_node_s { void *value; struct trie_node_s *next[256]; } **


decompiled_code:
void *trie_node_new()
{
return calloc(1uLL, 0x808uLL);
}

canonical_decompiled_code:
void *func1()
{
return calloc(1uLL, 0x808uLL);
}

original_code:
static trie_node *trie_node_new()
{
  trie_node *tn;
  tn = (trie_node*)calloc(1, sizeof(trie_node));
  return tn;
}

canonical_original_code:
static struct trie_node_s *trie_node_new()
{
  struct trie_node_s *tn;
  tn = (struct trie_node_s *)calloc(1, sizeof(trie_node));
  return tn;
}

variable_types: struct trie_node_s { void *value; struct trie_node_s *next[256]; } *


decompiled_code:
void __fastcall trie_node_free(void *ptr)
{
void **v2; // rbp
void **v3; // rbx
void *v4; // rdi

if ( ptr )
{
v2 = (void **)((char *)ptr + 2056);
v3 = (void **)((char *)ptr + 8);
do
{
v4 = *v3++;
trie_node_free(v4);
}
while ( v3 != v2 );
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void **v2; // rbp
void **v3; // rbx
void *v4; // rdi

if ( ptr )
{
v2 = (void **)((char *)ptr + 2056);
v3 = (void **)((char *)ptr + 8);
do
{
v4 = *v3++;
func2(v4);
}
while ( v3 != v2 );
free(ptr);
}
}

original_code:
static void trie_node_free(trie_node *tn)
{
  int i;
  if(tn == ((void *)0)) {
    return;
  }
  for(i = 0; i < 256; i++) {
    trie_node_free(tn->next[i]);
  }
  free(tn);
}

canonical_original_code:
static void trie_node_free(struct trie_node_s *tn)
{
  int i;
  if(tn == ((void *)0)) {
    return;
  }
  for(i = 0; i < 256; i++) {
    trie_node_free(tn->next[i]);
  }
  free(tn);
}

user_defined_types: struct trie_node_s { void *value; struct trie_node_s *next[256]; }


decompiled_code:
__int64 __fastcall foreach_in(_QWORD *a1, unsigned int a2, const void *a3, __int64 (__fastcall *a4)(const void *))
{
__int64 result; // rax
char *v8; // rax
void *v9; // r12
size_t v10; // r14
const void *v11; // rsi
unsigned int v12; // ebx
size_t v13; // rdx
__int64 v14; // r15
char *v15; // r14
unsigned int v16; // eax
unsigned int v17; // [rsp+0h] [rbp-3Ch]

if ( !a1 )
return 0LL;
if ( !*a1 || (result = a4(a3), !(_DWORD)result) )
{
v8 = (char *)calloc(a2 + 2, 1uLL);
v9 = v8;
if ( v8 )
{
v10 = a2;
v11 = a3;
v12 = a2 + 1;
v13 = v10;
v14 = 0LL;
v15 = &v8[v10];
memcpy(v8, v11, v13);
do
{
*v15 = v14;
v16 = foreach_in(a1[v14 + 1], v12, v9, a4);
if ( v16 )
break;
++v14;
}
while ( v14 != 256 );
v17 = v16;
free(v9);
result = v17;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, unsigned int a2, const void *a3, __int64 (__fastcall *a4)(const void *))
{
__int64 result; // rax
char *v8; // rax
void *v9; // r12
size_t v10; // r14
const void *v11; // rsi
unsigned int v12; // ebx
size_t v13; // rdx
__int64 v14; // r15
char *v15; // r14
unsigned int v16; // eax
unsigned int v17; // [rsp+0h] [rbp-3Ch]

if ( !a1 )
return 0LL;
if ( !*a1 || (result = a4(a3), !(_DWORD)result) )
{
v8 = (char *)calloc(a2 + 2, 1uLL);
v9 = v8;
if ( v8 )
{
v10 = a2;
v11 = a3;
v12 = a2 + 1;
v13 = v10;
v14 = 0LL;
v15 = &v8[v10];
memcpy(v8, v11, v13);
do
{
*v15 = v14;
v16 = func3(a1[v14 + 1], v12, v9, a4);
if ( v16 )
break;
++v14;
}
while ( v14 != 256 );
v17 = v16;
free(v9);
result = v17;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
static int foreach_in(trie_node *n, unsigned int depth, char *s, int(*fn)(char *, unsigned int, void*))
{
  int i;
  int ret;
  char *sc;
  if(n == ((void *)0)) {
    return 0;
  }
  ret = 0;
  if(n->value != ((void *)0)) {
    ret = fn(s, depth, n->value);
    if(ret != 0) {
      return ret;
    }
  }
  sc = (char*)calloc(depth+2, sizeof(char));
  if(sc == ((void *)0)) {
    return 1;
  }
  memcpy(sc, s, depth);
  for(i = 0; i < 256; i++) {
    sc[depth] = i;
    ret = foreach_in(n->next[i], depth+1, sc, fn);
    if(ret != 0) {
      break;
    }
  }
  free(sc);
  return ret;
}

canonical_original_code:
static int foreach_in(struct trie_node_s *n, unsigned int depth, char *s, int (*fn)(char *, unsigned int, void *))
{
  int i;
  int ret;
  char *sc;
  if(n == ((void *)0)) {
    return 0;
  }
  ret = 0;
  if(n->value != ((void *)0)) {
    ret = fn(s, depth, n->value);
    if(ret != 0) {
      return ret;
    }
  }
  sc = (char *)calloc(depth+2, sizeof(char));
  if(sc == ((void *)0)) {
    return 1;
  }
  memcpy(sc, s, depth);
  for(i = 0; i < 256; i++) {
    sc[depth] = i;
    ret = foreach_in(n->next[i], depth+1, sc, fn);
    if(ret != 0) {
      break;
    }
  }
  free(sc);
  return ret;
}

variable_types:
depth
unsigned int

variable_types:
s
char *

variable_types:
fn
int (*)(char *, unsigned int, void *)

variable_types: ret int

variable_types:
sc
char *


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

v0 = calloc(1uLL, 0x10uLL);
if ( v0 )
{
v1 = trie_node_new();
*v0 = v1;
if ( !v1 )
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

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

v0 = calloc(1uLL, 0x10uLL);
if ( v0 )
{
v1 = func1();
*v0 = v1;
if ( !v1 )
{
v3 = v0;
v0 = 0LL;
free(v3);
}
}
return v0;
}

original_code:
trie *trie_new(void)
{
  trie *t;
  t = (trie*)calloc(1, sizeof(trie));
  if(t == ((void *)0)) {
    return ((void *)0);
  }
  t->root_node = trie_node_new();
  if(t->root_node == ((void *)0)) {
    free(t);
    return ((void *)0);
  }
  return t;
}

canonical_original_code:
struct trie_s *trie_new()
{
  struct trie_s *t;
  t = (struct trie_s *)calloc(1, sizeof(trie));
  if(t == ((void *)0)) {
    return ((void *)0);
  }
  t->root_node = trie_node_new();
  if(t->root_node == ((void *)0)) {
    free(t);
    return ((void *)0);
  }
  return t;
}

variable_types: struct trie_s { struct trie_node_s { void *value; struct trie_node_s *next[256]; } *root_node; unsigned int size; } *

user_defined_types: struct trie_s { struct trie_node_s *root_node; unsigned int size; }


decompiled_code:
void __fastcall trie_free(void *ptr)
{
if ( ptr )
{
trie_node_free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( ptr )
{
func2(*(void **)ptr);
free(ptr);
}
}

original_code:
void trie_free(trie *t)
{
  if(t == ((void *)0)) {
    return;
  }
  trie_node_free(t->root_node);
  free(t);
}

canonical_original_code:
void trie_free(struct trie_s *t)
{
  if(t == ((void *)0)) {
    return;
  }
  trie_node_free(t->root_node);
  free(t);
}


original_code:
int trie_insert_n(trie *t, char *key, int len, void *value)
{
  trie_node **n;
  int i;
  if(t == ((void *)0)) {
    return -1;
  }
  n = &(t->root_node);
  for(i = 0; i < len; i++) {
    n = &((*n)->next[ (int)*(key + i) ]);
    if(*n == ((void *)0)) {
      *n = trie_node_new();
      if(*n == ((void *)0)) {
 return -1;
      }
    }
  }
  if((*n)->value != ((void *)0)) {
    t->size--;
  }
  (*n)->value = value;
  t->size++;
  return 0;
}

canonical_original_code:
int trie_insert_n(struct trie_s *t, char *key, int len, void *value)
{
  struct trie_node_s **n;
  int i;
  if(t == ((void *)0)) {
    return -1;
  }
  n = &(t->root_node);
  for(i = 0; i < len; i++) {
    n = &((*n)->next[ (int)*(key + i) ]);
    if(*n == ((void *)0)) {
      *n = trie_node_new();
      if(*n == ((void *)0)) {
 return -1;
      }
    }
  }
  if((*n)->value != ((void *)0)) {
    t->size--;
  }
  (*n)->value = value;
  t->size++;
  return 0;
}

variable_types: len int

variable_types:
value
void *


decompiled_code:
__int64 __fastcall trie_insert(__int64 a1, char *a2, __int64 a3)
{
int v4; // eax

v4 = strlen(a2);
return trie_insert_n(a1, a2, v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2, __int64 a3)
{
int v4; // eax

v4 = strlen(a2);
return func6(a1, a2, v4, a3);
}

original_code:
int trie_insert(trie *t, char *key, void *value)
{
  return trie_insert_n(t, key, strlen(key), value);
}

canonical_original_code:
int trie_insert(struct trie_s *t, char *key, void *value)
{
  return trie_insert_n(t, key, strlen(key), value);
}


original_code:
void trie_remove_n(trie *t, char *key, unsigned int len)
{
  int i;
  int allnull;
  trie_node **n;
  allnull = 1;
  if(t == ((void *)0)) {
    return;
  }
  n = lookup_node(t, key, len);
  if((n != ((void *)0)) &&
     (*n != ((void *)0)) &&
     ((*n)->value != ((void *)0))) {
    (*n)->value = ((void *)0);
    t->size--;
  }
  for( ;
 ((n != ((void *)0)) &&
  (*n != ((void *)0))) ;
 n = lookup_node(t, key, --len)) {
    allnull = 1;
    for(i = 0; i < 256; i++) {
      if( (*n)->next[i] != ((void *)0)) {
 allnull = 0;
 break;
      }
    }
    if(allnull) {
      trie_node_free(*n);
      *n = ((void *)0);
    }
  }
}

canonical_original_code:
void trie_remove_n(struct trie_s *t, char *key, unsigned int len)
{
  int i;
  int allnull;
  struct trie_node_s **n;
  allnull = 1;
  if(t == ((void *)0)) {
    return;
  }
  n = lookup_node(t, key, len);
  if((n != ((void *)0)) &&
     (*n != ((void *)0)) &&
     ((*n)->value != ((void *)0))) {
    (*n)->value = ((void *)0);
    t->size--;
  }
  for( ;
 ((n != ((void *)0)) &&
  (*n != ((void *)0))) ;
 n = lookup_node(t, key, --len)) {
    allnull = 1;
    for(i = 0; i < 256; i++) {
      if( (*n)->next[i] != ((void *)0)) {
 allnull = 0;
 break;
      }
    }
    if(allnull) {
      trie_node_free(*n);
      *n = ((void *)0);
    }
  }
}

variable_types: allnull int


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

v2 = strlen(a2);
trie_remove_n(a1, a2, v2);
}

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

v2 = strlen(a2);
func10(a1, a2, v2);
}

original_code:
void trie_remove(trie *t, char *key)
{
  trie_remove_n(t, key, strlen(key));
}

canonical_original_code:
void trie_remove(struct trie_s *t, char *key)
{
  trie_remove_n(t, key, strlen(key));
}


decompiled_code:
__int64 __fastcall trie_size(__int64 a1)
{
if ( !a1 )
BUG();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
if ( !a1 )
BUG();
return 0LL;
}

original_code:
unsigned int trie_size(trie *t)
{
  if(t != ((void *)0)) {
    return 0;
  }
  return t->size;
}

canonical_original_code:
unsigned int trie_size(struct trie_s *t)
{
  if(t != ((void *)0)) {
    return 0;
  }
  return t->size;
}


decompiled_code:
__int64 __fastcall trie_foreach(_QWORD **a1, __int64 (__fastcall *a2)(const void *))
{
return foreach_in(*a1, 0, 0LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD **a1, __int64 (__fastcall *a2)(const void *))
{
return func3(*a1, 0, 0LL, a2);
}

original_code:
int trie_foreach(trie *t, int(*foreach_fn)(char *, unsigned int, void*))
{
  return foreach_in(t->root_node, 0, ((void *)0), foreach_fn);
}

canonical_original_code:
int trie_foreach(struct trie_s *t, int (*foreach_fn)(char *, unsigned int, void *))
{
  return foreach_in(t->root_node, 0, ((void *)0), foreach_fn);
}


original_code:
static void sift_up(heap *h, int insert_index)
{
  int parent_index;
  int swap_tmp;
  void *parent_item;
  void *insert_item;
  if(h == ((void *)0)) {
    return;
  }
  if(insert_index == 1) {
    return;
  }
  parent_index = insert_index >> 1;
  parent_item = h->heap_items[parent_index];
  insert_item = h->heap_items[insert_index];
  if(h->orderitem_fn(insert_item, parent_item)) {
    swap_tmp = insert_index;
    h->heap_items[parent_index] = insert_item;
    h->heap_items[insert_index] = parent_item;
    insert_index = parent_index;
    parent_index = swap_tmp;
    sift_up(h, insert_index);
  }
}

canonical_original_code:
static void sift_up(struct heap_s *h, int insert_index)
{
  int parent_index;
  int swap_tmp;
  void *parent_item;
  void *insert_item;
  if(h == ((void *)0)) {
    return;
  }
  if(insert_index == 1) {
    return;
  }
  parent_index = insert_index >> 1;
  parent_item = h->heap_items[parent_index];
  insert_item = h->heap_items[insert_index];
  if(h->orderitem_fn(insert_item, parent_item)) {
    swap_tmp = insert_index;
    h->heap_items[parent_index] = insert_item;
    h->heap_items[insert_index] = parent_item;
    insert_index = parent_index;
    parent_index = swap_tmp;
    sift_up(h, insert_index);
  }
}

variable_types: struct heap_s { int max_heap_size; void **heap_items; void *(*dupitem_fn)(void *); int (*orderitem_fn)(void *, void *); void (*freeitem_fn)(void *); int next_free_idx; } *


decompiled_code:
_BOOL8 __fastcall heap_isempty(__int64 a1)
{
return *(_DWORD *)(a1 + 40) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_DWORD *)(a1 + 40) == 1;
}

original_code:
int heap_isempty(heap *h)
{
  return (h->next_free_idx == 1);
}

canonical_original_code:
int heap_isempty(struct heap_s *h)
{
  return (h->next_free_idx == 1);
}

user_defined_types: struct heap_s { int max_heap_size; void **heap_items; void *(*dupitem_fn)(void *); int (*orderitem_fn)(void *, void *); void (*freeitem_fn)(void *); int next_free_idx; }


original_code:
void *heap_extract(heap *h)
{
  void *minitem;
  if(h == ((void *)0)) {
    return ((void *)0);
  }
  if(heap_isempty(h)) {
    return ((void *)0);
  }
  minitem = h->heap_items[1];
  h->next_free_idx--;
  h->heap_items[1] = h->heap_items[h->next_free_idx];
  h->heap_items[h->next_free_idx] = ((void *)0);
  sift_down(h, 1);
  return minitem;
}

canonical_original_code:
void *heap_extract(struct heap_s *h)
{
  void *minitem;
  if(h == ((void *)0)) {
    return ((void *)0);
  }
  if(heap_isempty(h)) {
    return ((void *)0);
  }
  minitem = h->heap_items[1];
  h->next_free_idx--;
  h->heap_items[1] = h->heap_items[h->next_free_idx];
  h->heap_items[h->next_free_idx] = ((void *)0);
  sift_down(h, 1);
  return minitem;
}

variable_types:
minitem
void *


decompiled_code:
_BOOL8 __fastcall heap_isfull(_DWORD *a1)
{
return a1[10] >= *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_DWORD *a1)
{
return a1[10] >= *a1;
}

original_code:
int heap_isfull(heap *h)
{
  return (h->next_free_idx >= h->max_heap_size);
}

canonical_original_code:
int heap_isfull(struct heap_s *h)
{
  return (h->next_free_idx >= h->max_heap_size);
}


original_code:
void *heap_insert(heap *h, void *data)
{
  int insert_index;
  if(h == ((void *)0)) {
    return ((void *)0);
  }
  if(heap_isfull(h)) {
    return ((void *)0);
  }
  if(h->dupitem_fn != ((void *)0)) {
    data = h->dupitem_fn(data);
    if(data == ((void *)0)) {
      return ((void *)0);
    }
  }
  insert_index = h->next_free_idx;
  h->heap_items[insert_index] = data;
  h->next_free_idx++;
  sift_up(h, insert_index);
  return data;
}

canonical_original_code:
void *heap_insert(struct heap_s *h, void *data)
{
  int insert_index;
  if(h == ((void *)0)) {
    return ((void *)0);
  }
  if(heap_isfull(h)) {
    return ((void *)0);
  }
  if(h->dupitem_fn != ((void *)0)) {
    data = h->dupitem_fn(data);
    if(data == ((void *)0)) {
      return ((void *)0);
    }
  }
  insert_index = h->next_free_idx;
  h->heap_items[insert_index] = data;
  h->next_free_idx++;
  sift_up(h, insert_index);
  return data;
}

variable_types:
data
void *


original_code:
void heap_free(heap *h)
{
  int i;
  if(h->dupitem_fn != ((void *)0)) {
    for(i = 1; i < h->next_free_idx; i++) {
      h->freeitem_fn(h->heap_items[i]);
    }
  }
  free(h->heap_items);
  free(h);
}

canonical_original_code:
void heap_free(struct heap_s *h)
{
  int i;
  if(h->dupitem_fn != ((void *)0)) {
    for(i = 1; i < h->next_free_idx; i++) {
      h->freeitem_fn(h->heap_items[i]);
    }
  }
  free(h->heap_items);
  free(h);
}


decompiled_code:
void __fastcall di_free(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
}
}

original_code:
static void di_free(void *di)
{
  if(di == ((void *)0)) {
    return;
  }
  free( ((dictionary_item*)di)->key );
  free( ((dictionary_item*)di)->value );
  free(di);
}

canonical_original_code:
static void di_free(void *di)
{
  if(di == ((void *)0)) {
    return;
  }
  free( ((struct dictionary_item_s *)di)->key );
  free( ((struct dictionary_item_s *)di)->value );
  free(di);
}

variable_types:
di
void *

user_defined_types: struct dictionary_item_s { char *key; char *value; }


decompiled_code:
int __fastcall di_cmp(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

canonical_decompiled_code:
int __fastcall func1(const char **a1, const char **a2)
{
return strcmp(*a1, *a2);
}

original_code:
static int di_cmp(void *a, void *b)
{
  return strcmp( ((dictionary_item*)a)->key, ((dictionary_item*)b)->key );
}

canonical_original_code:
static int di_cmp(void *a, void *b)
{
  return strcmp( ((struct dictionary_item_s *)a)->key, ((struct dictionary_item_s *)b)->key );
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
__int64 __fastcall di_rehash(_QWORD *a1)
{
return rehash_string(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
return rehash_string(*a1);
}

original_code:
static unsigned long di_rehash(void *di)
{
  return rehash_string( ((dictionary_item*)di)->key );
}

canonical_original_code:
static unsigned long di_rehash(void *di)
{
  return rehash_string( ((struct dictionary_item_s *)di)->key );
}


decompiled_code:
__int64 __fastcall di_hash(_QWORD *a1)
{
return hash_string(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
return hash_string(*a1);
}

original_code:
static unsigned long di_hash(void *di)
{
  return hash_string( ((dictionary_item*)di)->key );
}

canonical_original_code:
static unsigned long di_hash(void *di)
{
  return hash_string( ((struct dictionary_item_s *)di)->key );
}


decompiled_code:
__int64 dictionary_new()
{
return hashtable_new(di_hash, di_rehash, di_cmp, di_dup, di_free);
}

canonical_decompiled_code:
__int64 func4()
{
return hashtable_new(di_hash, di_rehash, di_cmp, di_dup, di_free);
}

original_code:
dictionary *dictionary_new()
{
  return (dictionary*)hashtable_new(di_hash, di_rehash, di_cmp, di_dup, di_free);
}

canonical_original_code:
struct hashtable_s *dictionary_new()
{
  return (struct hashtable_s *)hashtable_new(di_hash, di_rehash, di_cmp, di_dup, di_free);
}

return_type: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 } herror; } hstatus; } *


decompiled_code:
__int64 __fastcall dictionary_set(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a2;
v4[1] = a3;
return hashtable_insert(a1, v4);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4[3]; // [rsp+0h] [rbp-18h] BYREF

v4[0] = a2;
v4[1] = a3;
return hashtable_insert(a1, v4);
}

original_code:
char *dictionary_set(dictionary *d, char *key, char *value)
{
  dictionary_item di;
  di.key = key;
  di.value = value;
  return (char*)hashtable_insert( (hashtable*)d, (void*)&di);
}

canonical_original_code:
char *dictionary_set(struct hashtable_s *d, char *key, char *value)
{
  struct dictionary_item_s di;
  di.key = key;
  di.value = value;
  return (char *)hashtable_insert( (struct hashtable_s *)d, (void *)&di);
}

variable_types: struct hashtable_s { void **htbl; unsigned long size; unsigned long (*hash)(void *item); unsigned long (*rehash)(void *item); int (*cmp)(void *litem, void *ritem); void *(*dupe)(void *item); void (*undupe)(void *item); struct hshstats_s { unsigned long probes; unsigned long misses; unsigned long hentries; unsigned long hdeleted; enum hsherr_e { hshOK=0, hshNOMEM=1, hshTBLFULL=2, hshINTERR=4 } herror; } hstatus; } *

variable_types:
key
char *

variable_types:
value
char *

variable_types: struct dictionary_item_s { char *key; char *value; }

return_type: char *


decompiled_code:
__int64 __fastcall dictionary_get(__int64 a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
return hashtable_find(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
return hashtable_find(a1, v3);
}

original_code:
char *dictionary_get(dictionary *d, char *key)
{
  dictionary_item di;
  di.key = key;
  di.value = ((void *)0);
  return (char*)hashtable_find( (hashtable*)d, (void*)&di );
}

canonical_original_code:
char *dictionary_get(struct hashtable_s *d, char *key)
{
  struct dictionary_item_s di;
  di.key = key;
  di.value = ((void *)0);
  return (char *)hashtable_find( (struct hashtable_s *)d, (void *)&di );
}


decompiled_code:
void __fastcall dictionary_remove(__int64 a1, __int64 a2)
{
void *v2; // rax
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
v2 = (void *)hashtable_remove(a1, v3);
di_free(v2);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int64 a2)
{
void *v2; // rax
__int64 v3[3]; // [rsp+0h] [rbp-18h] BYREF

v3[0] = a2;
v3[1] = 0LL;
v2 = (void *)hashtable_remove(a1, v3);
func0(v2);
}

original_code:
void dictionary_remove(dictionary *d, char *key)
{
  dictionary_item di;
  di.key = key;
  di.value = ((void *)0);
  di_free( hashtable_remove( (hashtable*)d, (void*)&di) );
}

canonical_original_code:
void dictionary_remove(struct hashtable_s *d, char *key)
{
  struct dictionary_item_s di;
  di.key = key;
  di.value = ((void *)0);
  di_free( hashtable_remove( (struct hashtable_s *)d, (void *)&di) );
}


decompiled_code:
// attributes: thunk
__int64 dictionary_free()
{
return hashtable_free();
}

canonical_decompiled_code:
__int64 func8()
{
return hashtable_free();
}

original_code:
void dictionary_free(dictionary *d)
{
  hashtable_free( (hashtable*)d );
}

canonical_original_code:
void dictionary_free(struct hashtable_s *d)
{
  hashtable_free( (struct hashtable_s *)d );
}


cmpchr

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

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

original_code:
int cmpchr(char *x, char *y)
{
  return *y - *x;
}

variable_types:
x
char *

variable_types:
y
char *


main

canonical_name: main

repo: ajross/project-euler

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // rsi

v3 = 0;
v4 = 0LL;
do
{
if ( (unsigned int)(-1431655765 * v3) <= 0x55555555 || (unsigned int)(-858993459 * v3) <= 0x33333333 )
v4 = (unsigned int)(v3 + v4);
++v3;
}
while ( v3 != 1000 );
printf("The total is: %d\n", v4);
return 0;
}

original_code:
int main(int argc, char** argv) {
   int sum = 0;
   int i;
   for (i = 0; i < 1000; i++) {
       if ((i % 3 == 0) || (i % 5 == 0)) {
           sum += i;
       }
   }
   printf("The total is: %d\n", sum);
   return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
   int sum = 0;
   int i;
   for (i = 0; i < 1000; i++) {
       if ((i % 3 == 0) || (i % 5 == 0)) {
           sum += i;
       }
   }
   printf("The total is: %d\n", sum);
   return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: sum int

variable_types: i int


repo: ajtowns/altos

decompiled_code:
void ao_aes_set_mode()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void
ao_aes_set_mode(enum ao_aes_mode mode)
{
 (void) mode;
}

variable_types: enum ao_aes_mode { ao_aes_mode_cbc_mac=0 }


decompiled_code:
__int64 __fastcall ao_aes_set_key(const __m128i *a1)
{
key = (__int128)_mm_loadu_si128(a1);
return xrijndaelKeySched_constprop_0_isra_0();
}

canonical_decompiled_code:
__int64 __fastcall func13(const __m128i *a1)
{
key = (__int128)_mm_loadu_si128(a1);
return func11();
}

original_code:
void
ao_aes_set_key( uint8_t *in)
{
 memcpy(key, in, 16);
 xrijndaelKeySched((word32 *) key, 128, 128, &rkk);
}

canonical_original_code:
void ao_aes_set_key(unsigned char *in)
{
 memcpy(key, in, 16);
 xrijndaelKeySched((unsigned int *) key, 128, 128, &rkk);
}

variable_types:
in
unsigned char *


decompiled_code:
void ao_aes_zero_iv()
{
iv = 0LL;
}

canonical_decompiled_code:
void func14()
{
iv = 0LL;
}

original_code:
void
ao_aes_zero_iv(void)
{
 memset(iv, '\0', sizeof (iv));
}

canonical_original_code:
void ao_aes_zero_iv()
{
 memset(iv, '\0', sizeof (iv));
}