decompiled_code:
__int64 __fastcall extract_head(__int64 a1)
{
_QWORD *v1; // r8
__int64 v2; // r12
_QWORD *v3; // rax

if ( !a1 )
return 0LL;
v1 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
return v2;
v3 = (_QWORD *)v1[1];
v2 = v1[2];
if ( v3 )
{
*v3 = 0LL;
*(_QWORD *)a1 = v3;
free(v1);
return v2;
}
free(*(void **)a1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
_QWORD *v1; // r8
__int64 v2; // r12
_QWORD *v3; // rax

if ( !a1 )
return 0LL;
v1 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( !v2 )
return v2;
v3 = (_QWORD *)v1[1];
v2 = v1[2];
if ( v3 )
{
*v3 = 0LL;
*(_QWORD *)a1 = v3;
free(v1);
return v2;
}
free(*(void **)a1);
return v2;
}

original_code:
void* extract_head(struct list_type *l) {
  if(l!=((void *)0) && l->head!=((void *)0) && l->tail!=((void *)0)){
    cell* old_head;
    old_head = l->head;
    void* content;
    content = old_head->content;
    if(l->head->next!=((void *)0)){
      l->head->next->previous = ((void *)0);
      l->head = l->head->next;
      free(old_head);
    }
    else{
       free(l->head);
    }
    return content;
  }
  return ((void *)0);
}

canonical_original_code:
void *extract_head(struct list_type *l) {
  if(l!=((void *)0) && l->head!=((void *)0) && l->tail!=((void *)0)){
    struct cell_type *old_head;
    old_head = l->head;
    void *content;
    content = old_head->content;
    if(l->head->next!=((void *)0)){
      l->head->next->previous = ((void *)0);
      l->head = l->head->next;
      free(old_head);
    }
    else{
       free(l->head);
    }
    return content;
  }
  return ((void *)0);
}

variable_types: struct list_type { struct cell_type { struct cell_type *previous; struct cell_type *next; void *content; } *head; struct cell_type *tail; } *

variable_types:
content
void *


repo: nasrallahmounir/Posix

decompiled_code:
__int64 list_size()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
return 0LL;
}

original_code:
int list_size(struct list_type *l){
  cell* current;
  int size;
  size = 0;
  while(current!=((void *)0)){
    size++;
    current=current->next;
  }
  return size;
}

canonical_original_code:
int list_size(struct list_type *l){
  struct cell_type *current;
  int size;
  size = 0;
  while(current!=((void *)0)){
    size++;
    current=current->next;
  }
  return size;
}

variable_types: struct cell_type { struct cell_type *previous; struct cell_type *next; void *content; } *

variable_types: size int

return_type: int

user_defined_types: struct list_type { struct cell_type *head; struct cell_type *tail; }


size

decompiled_code:
__int64 size()
{
return list_size(fifo);
}

canonical_decompiled_code:
__int64 func10()
{
return func14(fifo);
}

original_code:
int size(){
  return list_size(fifo);
}

canonical_original_code:
int size(){
  return list_size(fifo);
}


convertfrom

decompiled_code:
double __fastcall convertfrom(const char *a1, double result)
{
if ( !strcmp(a1, "GBP") )
return result / 0.8796;
if ( !strcmp(a1, "USD") )
return result / 1.3605;
if ( !strcmp(a1, "JPY") )
return result / 124.25;
if ( !strcmp(a1, "CNY") )
return result / 6.8264;
if ( strcmp(a1, "EUR") )
{
perror("Unknown currency");
exit(1);
}
return result;
}

canonical_decompiled_code:
double __fastcall func7(const char *a1, double result)
{
if ( !strcmp(a1, "GBP") )
return result / 0.8796;
if ( !strcmp(a1, "USD") )
return result / 1.3605;
if ( !strcmp(a1, "JPY") )
return result / 124.25;
if ( !strcmp(a1, "CNY") )
return result / 6.8264;
if ( strcmp(a1, "EUR") )
{
perror("Unknown currency");
exit(1);
}
return result;
}

original_code:
double convertfrom(char* input_currency, double input_amount) {
 if (strcmp(input_currency, "GBP") == 0)
  return (input_amount / 0.8796);
 else if (strcmp(input_currency, "USD") == 0)
  return (input_amount / 1.3605);
 else if (strcmp(input_currency, "JPY") == 0)
  return (input_amount / 124.25);
 else if (strcmp(input_currency, "CNY") == 0)
  return (input_amount / 6.8264);
 else if (strcmp(input_currency, "EUR") == 0)
  return input_amount;
 else {
  perror("Unknown currency");
  exit(1);
 }
}

canonical_original_code:
double convertfrom(char *input_currency, double input_amount) {
 if (strcmp(input_currency, "GBP") == 0)
  return (input_amount / 0.8796);
 else if (strcmp(input_currency, "USD") == 0)
  return (input_amount / 1.3605);
 else if (strcmp(input_currency, "JPY") == 0)
  return (input_amount / 124.25);
 else if (strcmp(input_currency, "CNY") == 0)
  return (input_amount / 6.8264);
 else if (strcmp(input_currency, "EUR") == 0)
  return input_amount;
 else {
  perror("Unknown currency");
  exit(1);
 }
}

return_type: double


convertto

decompiled_code:
double __fastcall convertto(const char *a1, double result)
{
if ( !strcmp(a1, "GBP") )
return result * 0.8796;
if ( !strcmp(a1, "USD") )
return result * 1.3605;
if ( !strcmp(a1, "JPY") )
return result * 124.25;
if ( !strcmp(a1, "CNY") )
return result * 6.8264;
if ( strcmp(a1, "EUR") )
{
perror("Unknown currency");
exit(1);
}
return result;
}

canonical_decompiled_code:
double __fastcall func8(const char *a1, double result)
{
if ( !strcmp(a1, "GBP") )
return result * 0.8796;
if ( !strcmp(a1, "USD") )
return result * 1.3605;
if ( !strcmp(a1, "JPY") )
return result * 124.25;
if ( !strcmp(a1, "CNY") )
return result * 6.8264;
if ( strcmp(a1, "EUR") )
{
perror("Unknown currency");
exit(1);
}
return result;
}

original_code:
double convertto(char* target_currency, double input_amount) {
 if (strcmp(target_currency, "GBP") == 0)
  return (input_amount * 0.8796);
 else if (strcmp(target_currency, "USD") == 0)
  return (input_amount * 1.3605);
 else if (strcmp(target_currency, "JPY") == 0)
  return (input_amount * 124.25);
 else if (strcmp(target_currency, "CNY") == 0)
  return (input_amount * 6.8264);
 else if (strcmp(target_currency, "EUR") == 0)
  return input_amount;
 else {
  perror("Unknown currency");
  exit(1);
 }
}

canonical_original_code:
double convertto(char *target_currency, double input_amount) {
 if (strcmp(target_currency, "GBP") == 0)
  return (input_amount * 0.8796);
 else if (strcmp(target_currency, "USD") == 0)
  return (input_amount * 1.3605);
 else if (strcmp(target_currency, "JPY") == 0)
  return (input_amount * 124.25);
 else if (strcmp(target_currency, "CNY") == 0)
  return (input_amount * 6.8264);
 else if (strcmp(target_currency, "EUR") == 0)
  return input_amount;
 else {
  perror("Unknown currency");
  exit(1);
 }
}


convert

decompiled_code:
double __fastcall convert(const char *a1, const char *a2, double a3)
{
double v3; // xmm0_8

v3 = convertfrom(a1, a3);
return convertto(a2, v3);
}

canonical_decompiled_code:
double __fastcall func9(const char *a1, const char *a2, double a3)
{
double v3; // xmm0_8

v3 = func7(a1, a3);
return func8(a2, v3);
}

original_code:
double convert(char* input_currency, char* target_currency, double input_amount) {
 return convertto(target_currency, convertfrom(input_currency, input_amount));
}

canonical_original_code:
double convert(char *input_currency, char *target_currency, double input_amount) {
 return convertto(target_currency, convertfrom(input_currency, input_amount));
}


decompiled_code:
char *__fastcall determine_currency(unsigned int a1)
{
if ( a1 > 4 )
{
perror("Unknown currency");
exit(1);
}
return CSWTCH_4[a1];
}

canonical_decompiled_code:
char *__fastcall func10(unsigned int a1)
{
if ( a1 > 4 )
{
perror("Unknown currency");
exit(1);
}
return CSWTCH_4[a1];
}

original_code:
char* determine_currency(int curr_nb) {
 switch(curr_nb) {
  case 0: return "EUR";
  case 1: return "GBP";
  case 2: return "USD";
  case 3: return "JPY";
  case 4: return "CNY";
  default: perror("Unknown currency"); exit(1);
 }
}

canonical_original_code:
char *determine_currency(int curr_nb) {
 switch(curr_nb) {
  case 0: return "EUR";
  case 1: return "GBP";
  case 2: return "USD";
  case 3: return "JPY";
  case 4: return "CNY";
  default: perror("Unknown currency"); exit(1);
 }
}

return_type: char *


decompiled_code:
__int64 init_stack()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(0x10uLL);
stack = (__int64)v0;
if ( v0 )
{
init_list(v0);
result = 0LL;
}
else
{
fprintf(stderr, "Malloc error -- line : %d, file : %s \n", 14LL, "src/stack_list.c");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
void *v0; // rax
__int64 result; // rax

v0 = malloc(0x10uLL);
stack = (__int64)v0;
if ( v0 )
{
func11(v0);
result = 0LL;
}
else
{
fprintf(stderr, "Malloc error -- line : %d, file : %s \n", 14LL, "src/stack_list.c");
result = 1LL;
}
return result;
}

original_code:
int init_stack(){
  stack = (struct list_type*)malloc(sizeof(struct list_type));
  if(stack==((void *)0)){
    fprintf(stderr,"Malloc error -- line : %d, file : %s \n",14,"src/stack_list.c");
    return 1;
  }
  else{
    init_list(stack);
    return 0;
    }
}

canonical_original_code:
int init_stack(){
  stack = (struct list_type *)malloc(sizeof(struct list_type));
  if(stack==((void *)0)){
    fprintf(stderr,"Malloc error -- line : %d, file : %s \n",14,"src/stack_list.c");
    return 1;
  }
  else{
    init_list(stack);
    return 0;
    }
}

user_defined_types: struct cell_type { struct cell_type *previous; struct cell_type *next; void *content; }


push

decompiled_code:
__int64 __fastcall push(__int64 a1)
{
insert_head(stack, a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
insert_head(stack, a1);
return 0LL;
}

original_code:
int push(void* element){
  insert_head(stack, element);
  return 0;
}

canonical_original_code:
int push(void *element){
  insert_head(stack, element);
  return 0;
}

variable_types:
element
void *


pop

decompiled_code:
__int64 pop()
{
return extract_head(stack);
}

canonical_decompiled_code:
__int64 func9()
{
return func12(stack);
}

original_code:
void* pop(){
  return extract_head(stack);
}

canonical_original_code:
void *pop(){
  return extract_head(stack);
}

return_type: void *


size

decompiled_code:
__int64 size()
{
return list_size(stack);
}

canonical_decompiled_code:
__int64 func10()
{
return func14(stack);
}

original_code:
int size(){
  return list_size(stack);
}

canonical_original_code:
int size(){
  return list_size(stack);
}


decompiled_code:
void __noreturn exo_I_a()
{
int v0; // ebx
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax

v0 = 7;
while ( 1 )
{
v1 = fork();
if ( v1 == -1 )
break;
if ( !v1 )
{
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
if ( !--v0 )
exit(0);
}
fwrite(&unk_402008, 1uLL, 0x1EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
int v0; // ebx
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax

v0 = 7;
while ( 1 )
{
v1 = fork();
if ( v1 == -1 )
break;
if ( !v1 )
{
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
if ( !--v0 )
exit(0);
}
fwrite(&unk_402008, 1uLL, 0x1EuLL, stderr);
exit(1);
}

original_code:
void exo_I_a(){
  int i;
  pid_t pid;
  for(i=0;i<7;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:;
    }
  }
  exit(0);
}

canonical_original_code:
void exo_I_a(){
  int i;
  int pid;
  for(i=0;i<7;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:;
    }
  }
  exit(0);
}

variable_types: i int

variable_types: pid int

return_type: void


decompiled_code:
void __fastcall __noreturn exo_I_b(int *a1)
{
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax

if ( *a1 <= 6 )
{
v1 = fork();
++*a1;
if ( v1 != -1 )
{
if ( v1 )
exo_I_b(a1);
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
fwrite(&unk_402070, 1uLL, 0x23uLL, stderr);
exit(1);
}
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(int *a1)
{
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax

if ( *a1 <= 6 )
{
v1 = fork();
++*a1;
if ( v1 != -1 )
{
if ( v1 )
func8(a1);
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
fwrite(&unk_402070, 1uLL, 0x23uLL, stderr);
exit(1);
}
exit(0);
}

original_code:
void exo_I_b(int* i){
  if(*i<7){
    pid_t pid;
    pid=fork();
    *i = *i + 1;
    switch(pid){
    case -1: fprintf(stderr,"Erreur lors de la création du fils");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:
      exo_I_b(i);
    }
  }
  exit(0);
}

canonical_original_code:
void exo_I_b(int *i){
  if(*i<7){
    int pid;
    pid=fork();
    *i = *i + 1;
    switch(pid){
    case -1: fprintf(stderr,"Erreur lors de la création du fils");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:
      exo_I_b(i);
    }
  }
  exit(0);
}

variable_types:
i
int *


decompiled_code:
void __noreturn exo_II_1()
{
int v0; // ebx
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax

v0 = 7;
while ( 1 )
{
v1 = fork();
if ( v1 == -1 )
break;
if ( !v1 )
{
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
if ( !--v0 )
{
wait(0LL);
exit(0);
}
}
fwrite(&unk_402008, 1uLL, 0x1EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
int v0; // ebx
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax

v0 = 7;
while ( 1 )
{
v1 = fork();
if ( v1 == -1 )
break;
if ( !v1 )
{
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
if ( !--v0 )
{
wait(0LL);
exit(0);
}
}
fwrite(&unk_402008, 1uLL, 0x1EuLL, stderr);
exit(1);
}

original_code:
void exo_II_1(){
  int i;
  pid_t pid;
  for(i=0;i<7;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:;}
  }
  wait(((void *)0));
  exit(0);
}

canonical_original_code:
void exo_II_1(){
  int i;
  int pid;
  for(i=0;i<7;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:;}
  }
  wait(((void *)0));
  exit(0);
}


decompiled_code:
void __noreturn exo_II_2()
{
int v0; // ebx
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax

v0 = 7;
while ( 1 )
{
v1 = fork();
if ( v1 == -1 )
break;
if ( !v1 )
{
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
wait(0LL);
if ( !--v0 )
exit(0);
}
fwrite(&unk_402008, 1uLL, 0x1EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func10()
{
int v0; // ebx
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax

v0 = 7;
while ( 1 )
{
v1 = fork();
if ( v1 == -1 )
break;
if ( !v1 )
{
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
wait(0LL);
if ( !--v0 )
exit(0);
}
fwrite(&unk_402008, 1uLL, 0x1EuLL, stderr);
exit(1);
}

original_code:
void exo_II_2(){
  int i;
  pid_t pid;
  for(i=0;i<7;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:
      wait(((void *)0));
    }
  }
  exit(0);
}

canonical_original_code:
void exo_II_2(){
  int i;
  int pid;
  for(i=0;i<7;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:
      wait(((void *)0));
    }
  }
  exit(0);
}


decompiled_code:
void __noreturn exo_II_3()
{
int i; // ebx
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = 7; ; --i )
{
v1 = fork();
if ( v1 == -1 )
break;
if ( !v1 )
{
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
if ( i == 1 )
{
waitpid(v1, stat_loc, 0);
exit(0);
}
}
fwrite(&unk_402008, 1uLL, 0x1EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func11()
{
int i; // ebx
__pid_t v1; // eax
unsigned int v2; // er12
unsigned int v3; // eax
int stat_loc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = 7; ; --i )
{
v1 = fork();
if ( v1 == -1 )
break;
if ( !v1 )
{
v2 = getppid();
v3 = getpid();
printf(format, v3, v2);
exit(0);
}
if ( i == 1 )
{
waitpid(v1, stat_loc, 0);
exit(0);
}
}
fwrite(&unk_402008, 1uLL, 0x1EuLL, stderr);
exit(1);
}

original_code:
void exo_II_3(){
  int i,status;
  pid_t pid;
  for(i=0;i<7;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:
      if(i==7 -1){
        waitpid(pid,&status,0);
      }
    }
  }
  exit(0);
}

canonical_original_code:
void exo_II_3(){
  int i; int status;
  int pid;
  for(i=0;i<7;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork");
      exit(1);
    case 0:
      printf("Je suis un processus fils, mon pid est le %d, mon père est %d \n",getpid(),getppid());
      exit(0);
    default:
      if(i==7 -1){
        waitpid(pid,&status,0);
      }
    }
  }
  exit(0);
}

variable_types: status int


decompiled_code:
__int64 exo_III_main()
{
unsigned int i; // ebp
__pid_t v1; // ebx
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = 0; i != 3; ++i )
{
v1 = fork();
if ( !v1 )
{
printf("i=%d\n", i);
if ( i )
{
while ( !fork() )
{
if ( ++v1 == i )
goto LABEL_11;
}
i = v1;
wait((__WAIT_STATUS)&stat_loc);
}
else
{
LABEL_11:
printf("j=%d \n", i);
}
exit(i);
}
wait((__WAIT_STATUS)&stat_loc);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int i; // ebp
__pid_t v1; // ebx
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = 0; i != 3; ++i )
{
v1 = fork();
if ( !v1 )
{
printf("i=%d\n", i);
if ( i )
{
while ( !fork() )
{
if ( ++v1 == i )
goto LABEL_11;
}
i = v1;
wait((__WAIT_STATUS)&stat_loc);
}
else
{
LABEL_11:
printf("j=%d \n", i);
}
exit(i);
}
wait((__WAIT_STATUS)&stat_loc);
}
return 0LL;
}

original_code:
int exo_III_main (int arg, char* argv[]) {
  int i, j, p;
  int status;
  for (i=0; i<3 ; i++)
    if ((p=fork ()) == 0) {
      printf ("i=%d\n", i);
      j=0;
      while (j<i && ((p=fork()) == 0))
 j++;
      if (p==0)
 printf("j=%d \n",j);
      else{
 wait(&status);}
      exit(j);
    }
  else{
    wait(&status);
  }
  return (0);
}

canonical_original_code:
int exo_III_main(int arg, char *argv[]) {
  int i; int j; int p;
  int status;
  for (i=0; i<3 ; i++)
    if ((p=fork ()) == 0) {
      printf ("i=%d\n", i);
      j=0;
      while (j<i && ((p=fork()) == 0))
 j++;
      if (p==0)
 printf("j=%d \n",j);
      else{
 wait(&status);}
      exit(j);
    }
  else{
    wait(&status);
  }
  return (0);
}

variable_types: arg int

variable_types:
argv
char *[]

variable_types: j int

variable_types: p int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
exo_II_1(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func9(argc, argv, envp);
}

original_code:
int main(){
  int i = 0;
  exo_II_1();
}

canonical_original_code:
int main(){
  int i = 0;
  exo_II_1();
}


decompiled_code:
__int64 __fastcall cut_down(char *a1, _QWORD *a2)
{
char *v2; // rax
char *v3; // rbp
__int64 v4; // r12
char *v5; // rax
__int64 result; // rax

v2 = strtok(a1, " \n");
if ( v2 )
{
v3 = v2;
v4 = 1LL;
do
{
v5 = (char *)malloc(0x18uLL);
a2[v4 - 1] = v5;
strcpy(v5, v3);
v3 = strtok(0LL, " \n");
result = (unsigned int)v4++;
}
while ( v3 );
a2[(int)result] = 0LL;
}
else
{
*a2 = 0LL;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, _QWORD *a2)
{
char *v2; // rax
char *v3; // rbp
__int64 v4; // r12
char *v5; // rax
__int64 result; // rax

v2 = strtok(a1, " \n");
if ( v2 )
{
v3 = v2;
v4 = 1LL;
do
{
v5 = (char *)malloc(0x18uLL);
a2[v4 - 1] = v5;
strcpy(v5, v3);
v3 = strtok(0LL, " \n");
result = (unsigned int)v4++;
}
while ( v3 );
a2[(int)result] = 0LL;
}
else
{
*a2 = 0LL;
result = 0LL;
}
return result;
}

original_code:
int cut_down(char *buf, char **cmd) {
  char* s = strtok(buf, " \n");
  int i = 0;
  while (s != ((void *)0)) {
    cmd[i] = (char*) malloc(sizeof(char) * 24);
    strcpy(cmd[i], s);
    s = strtok(((void *)0), " \n");
    i++;
  }
  cmd[i] = ((void *)0);
  return i;
}

canonical_original_code:
int cut_down(char *buf, char **cmd) {
  char *s = strtok(buf, " \n");
  int i = 0;
  while (s != ((void *)0)) {
    cmd[i] = (char *) malloc(sizeof(char) * 24);
    strcpy(cmd[i], s);
    s = strtok(((void *)0), " \n");
    i++;
  }
  cmd[i] = ((void *)0);
  return i;
}

variable_types:
buf
char *

variable_types:
cmd
char **

variable_types:
s
char *


check

original_code:
int check() {
 int i, j, sums[8];
 for (i = 0; i < 8; i++)
  sums[i] = 0;
 for (i = 0; i < 3; i++) {
  for (j = 0; j < 3; j++) {
   sums[i] += magicsq[i][j];
   sums[i+3] += magicsq[j][i];
   if (i == j) sums[6] += magicsq[i][j];
   if ((i+j) == 2) sums[7] += magicsq[i][j];
  }
 }
 int result = 1;
 i = 1;
 while ((i < 8) && (result == 1)) {
  if (sums[0] != sums[i])
   result = 0;
  i++;
 }
 return result;
}

canonical_original_code:
int check() {
 int i; int j; int sums[8];
 for (i = 0; i < 8; i++)
  sums[i] = 0;
 for (i = 0; i < 3; i++) {
  for (j = 0; j < 3; j++) {
   sums[i] += magicsq[i][j];
   sums[i+3] += magicsq[j][i];
   if (i == j) sums[6] += magicsq[i][j];
   if ((i+j) == 2) sums[7] += magicsq[i][j];
  }
 }
 int result = 1;
 i = 1;
 while ((i < 8) && (result == 1)) {
  if (sums[0] != sums[i])
   result = 0;
  i++;
 }
 return result;
}

variable_types:
sums
int [8]

variable_types: result int


display

decompiled_code:
int display()
{
int *v0; // rbx
__int64 v1; // rsi

v0 = magicsq;
do
{
v1 = (unsigned int)*v0;
v0 += 3;
printf(" %d", v1);
printf(" %d", (unsigned int)*(v0 - 2));
printf(" %d", (unsigned int)*(v0 - 1));
putchar(10);
}
while ( &_bss_start != (_UNKNOWN *)v0 );
return putchar(10);
}

canonical_decompiled_code:
int func8()
{
int *v0; // rbx
__int64 v1; // rsi

v0 = magicsq;
do
{
v1 = (unsigned int)*v0;
v0 += 3;
printf(" %d", v1);
printf(" %d", (unsigned int)*(v0 - 2));
printf(" %d", (unsigned int)*(v0 - 1));
putchar(10);
}
while ( &_bss_start != (_UNKNOWN *)v0 );
return putchar(10);
}

original_code:
void display() {
 int i, j;
 for (i = 0; i < 3; i++) {
  for (j = 0; j < 3; j++)
   printf("  %d", magicsq[i][j]);
  printf("\n");
 }
 printf("\n");
}

canonical_original_code:
void display() {
 int i; int j;
 for (i = 0; i < 3; i++) {
  for (j = 0; j < 3; j++)
   printf("  %d", magicsq[i][j]);
  printf("\n");
 }
 printf("\n");
}


solve

original_code:
int solve(int x){
  int compute = 0;
  register int i,j;
  register int b,c,d,e;
  magicsq[0][1] = x;
  for(b=0;b<10;b++){
    magicsq[1][0]=b;
    for(c=0;c<10;c++){
      magicsq[1][1]=c;
      for(d=0;d<10;d++){
 magicsq[1][2]=d;
 for(e=0;e<10;e++){
   magicsq[2][1]=e;
   if(check()==1){
     compute++;
     display();
   }
 }
      }
    }
  }
  return compute;
}

canonical_original_code:
int solve(int x){
  int compute = 0;
  register int i; register int j;
  register int b; register int c; register int d; register int e;
  magicsq[0][1] = x;
  for(b=0;b<10;b++){
    magicsq[1][0]=b;
    for(c=0;c<10;c++){
      magicsq[1][1]=c;
      for(d=0;d<10;d++){
 magicsq[1][2]=d;
 for(e=0;e<10;e++){
   magicsq[2][1]=e;
   if(check()==1){
     compute++;
     display();
   }
 }
      }
    }
  }
  return compute;
}

variable_types: x int

variable_types: compute int

variable_types: b int

variable_types: c int

variable_types: d int

variable_types: e int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
__pid_t v4; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

for ( i = 0; i != 10; ++i )
{
v4 = fork();
if ( v4 == -1 )
{
fprintf(stderr, format, "src/decoder.c", 95LL);
exit(1);
}
if ( !v4 )
solve(i, argv);
wait((__WAIT_STATUS)&stat_loc);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
__pid_t v4; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

for ( i = 0; i != 10; ++i )
{
v4 = fork();
if ( v4 == -1 )
{
fprintf(stderr, format, "src/decoder.c", 95LL);
exit(1);
}
if ( !v4 )
func9(i, argv);
wait((__WAIT_STATUS)&stat_loc);
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
  int i,status;
  pid_t pid;
  int cmpt = 0;
  for(i=0;i<10;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork() -- Fichier : %s Linge : %d \n","src/decoder.c",95);
      exit(1);
    case 0:
      solve(i);
    default:
      wait(&status);
      }
    }
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int i; int status;
  int pid;
  int cmpt = 0;
  for(i=0;i<10;i++){
    pid=fork();
    switch(pid){
    case -1:
      fprintf(stderr,"Erreur lors de l'appel à fork() -- Fichier : %s Linge : %d \n","src/decoder.c",95);
      exit(1);
    case 0:
      solve(i);
    default:
      wait(&status);
      }
    }
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: pid int

variable_types: cmpt int


decompiled_code:
int __fastcall handle_sigalrm(unsigned int a1)
{
if ( a1 != 14 )
fprintf(stderr, "Wrong signal: %d\n", a1);
return puts("End of sleep");
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
if ( a1 != 14 )
fprintf(stderr, "Wrong signal: %d\n", a1);
return puts("End of sleep");
}

original_code:
void handle_sigalrm(int sig) {
  if (sig != 14) {
    fprintf(stderr, "Wrong signal: %d\n", sig);
  }
  printf("End of sleep\n");
}

variable_types: sig int


mysleep

decompiled_code:
int __fastcall mysleep(unsigned int seconds)
{
sigset_t v2; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v3; // [rsp+80h] [rbp-A8h] BYREF

v3.sa_handler = (__sighandler_t)handle_sigalrm;
v3.sa_flags = 0x80000000;
sigfillset(&v3.sa_mask);
sigaction(14, &v3, 0LL);
sigprocmask(0, 0LL, &v2);
sigdelset(&v2, 14);
alarm(seconds);
return sigsuspend(&v2);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int seconds)
{
sigset_t v2; // [rsp+0h] [rbp-128h] BYREF
struct sigaction v3; // [rsp+80h] [rbp-A8h] BYREF

v3.sa_handler = (__sighandler_t)handle_sigalrm;
v3.sa_flags = 0x80000000;
sigfillset(&v3.sa_mask);
sigaction(14, &v3, 0LL);
sigprocmask(0, 0LL, &v2);
sigdelset(&v2, 14);
alarm(seconds);
return sigsuspend(&v2);
}

original_code:
void mysleep(int sec){
  struct sigaction action;
  sigset_t mask;
  action.__sigaction_handler.sa_handler = &handle_sigalrm;
  action.sa_flags = 0x80000000;
  sigfillset(&action.sa_mask);
  sigaction(14, &action, ((void *)0));
  sigprocmask(0, ((void *)0), &mask);
  sigdelset(&mask, 14);
  alarm(sec);
  sigsuspend(&mask);
  return;
}

canonical_original_code:
void mysleep(int sec){
  struct sigaction action;
  struct __sigset_t mask;
  action.__sigaction_handler.sa_handler = &handle_sigalrm;
  action.sa_flags = 0x80000000;
  sigfillset(&action.sa_mask);
  sigaction(14, &action, ((void *)0));
  sigprocmask(0, ((void *)0), &mask);
  sigdelset(&mask, 14);
  alarm(sec);
  sigsuspend(&mask);
  return;
}

variable_types: sec int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // eax
unsigned int v5; // ebx
struct sigaction v6; // [rsp+0h] [rbp-A8h] BYREF

if ( argc == 2 )
{
v4 = atol(argv[1]);
v6.sa_handler = (__sighandler_t)1;
v6.sa_flags = 0x10000000;
v5 = v4;
sigfillset(&v6.sa_mask);
sigaction(1, &v6, 0LL);
sigaction(10, &v6, 0LL);
sigaction(9, &v6, 0LL);
sigaction(2, &v6, 0LL);
mysleep(v5);
}
else
{
fwrite("./mysleep seconds ", 1uLL, 0x12uLL, stderr);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // eax
unsigned int v5; // ebx
struct sigaction v6; // [rsp+0h] [rbp-A8h] BYREF

if ( argc == 2 )
{
v4 = atol(argv[1]);
v6.sa_handler = (__sighandler_t)1;
v6.sa_flags = 0x10000000;
v5 = v4;
sigfillset(&v6.sa_mask);
sigaction(1, &v6, 0LL);
sigaction(10, &v6, 0LL);
sigaction(9, &v6, 0LL);
sigaction(2, &v6, 0LL);
func8(v5);
}
else
{
fwrite("./mysleep seconds ", 1uLL, 0x12uLL, stderr);
}
return 0;
}

original_code:
int main(int argc,char* argv[]) {
  if(argc==2){
    int sec = atol(argv[1]);
    struct sigaction action;
    action.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
    action.sa_flags = 0x10000000;
    sigfillset(&action.sa_mask);
    sigaction(1, &action, ((void *)0));
    sigaction(10, &action, ((void *)0));
    sigaction(9, &action, ((void *)0));
    sigaction(2, &action, ((void *)0));
    mysleep(sec);
  }
  else{
    fprintf(stderr,"./mysleep seconds ");
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  if(argc==2){
    int sec = atol(argv[1]);
    struct sigaction action;
    action.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
    action.sa_flags = 0x10000000;
    sigfillset(&action.sa_mask);
    sigaction(1, &action, ((void *)0));
    sigaction(10, &action, ((void *)0));
    sigaction(9, &action, ((void *)0));
    sigaction(2, &action, ((void *)0));
    mysleep(sec);
  }
  else{
    fprintf(stderr,"./mysleep seconds ");
  }
  return 0;
}

variable_types:
argv
char *[]

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


handler

decompiled_code:
void __fastcall handler(int a1)
{
++global_counter;
++counter[a1];
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
++global_counter;
++counter[a1];
}

original_code:
void handler(int sig) {
  global_counter++;
  counter[sig]++;
}


decompiled_code:
int print_stat()
{
__int64 v0; // rbx
__int64 v1; // rdx
__int64 v2; // rsi
int result; // eax

v0 = 0LL;
printf("\nCompteur global : %d \n", (unsigned int)global_counter);
do
{
v1 = (unsigned int)counter[v0];
v2 = (unsigned int)v0++;
result = printf("\nCompteur pour le signal %d : %d \n", v2, v1);
}
while ( v0 != 66 );
return result;
}

canonical_decompiled_code:
int func8()
{
__int64 v0; // rbx
__int64 v1; // rdx
__int64 v2; // rsi
int result; // eax

v0 = 0LL;
printf("\nCompteur global : %d \n", (unsigned int)global_counter);
do
{
v1 = (unsigned int)counter[v0];
v2 = (unsigned int)v0++;
result = printf("\nCompteur pour le signal %d : %d \n", v2, v1);
}
while ( v0 != 66 );
return result;
}

original_code:
void print_stat(){
  int i;
  printf("\nCompteur global : %d \n", global_counter);
  for(i=0;i<=(64 + 1);i++){
    printf("\nCompteur pour le signal %d : %d \n",i,counter[i]);
  }
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int v4; // edi

for ( i = 0; i != 66; ++i )
{
v4 = i;
signal(v4, handler);
}
while ( dword_404068 <= 3 )
;
print_stat();
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int i; // ebx
int v4; // edi

for ( i = 0; i != 66; ++i )
{
v4 = i;
signal(v4, handler);
}
while ( dword_404068 <= 3 )
;
func8();
exit(0);
}

original_code:
int main() {
  int i;
  for(i=0;i<=(64 + 1);i++){
    signal(i,handler);
  }
  while (1) {
    if(counter[2]>=4){
      print_stat();
      exit(0);
    }
  }
  return 0;
}


decompiled_code:
__int64 init_default_global_state()
{
__int64 v0; // rdi

v0 = *((unsigned int *)&GlobalState + 16);
*((_QWORD *)&GlobalState + 21) = stdout;
*((_QWORD *)&GlobalState + 23) = stderr;
return set_output_line_length(v0);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdi

v0 = *((unsigned int *)&GlobalState + 16);
*((_QWORD *)&GlobalState + 21) = stdout;
*((_QWORD *)&GlobalState + 23) = stderr;
return set_output_line_length(v0);
}

original_code:
static void
init_default_global_state(void)
{
    GlobalState.outputfile = stdout;
    GlobalState.logfile = stderr;
    set_output_line_length(GlobalState.max_line_length);
}

canonical_original_code:
static void init_default_global_state()
{
    GlobalState.outputfile = stdout;
    GlobalState.logfile = stderr;
    set_output_line_length(GlobalState.max_line_length);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v5; // ebx
const char *v6; // rdi
unsigned __int64 v7; // rdx
unsigned int v8; // er8
struct _IO_FILE *v9; // rdi
const char *v11; // rsi
int v12; // eax
const char *v13; // rsi
__int64 v14; // rdx
void *v15; // rcx

v5 = 1;
init_default_global_state(argc, argv, envp);
init_game_header();
init_tag_lists();
init_hashtab();
init_lex_tables();
if ( argc > 1 )
{
do
{
v6 = argv[v5];
v7 = 8LL * v5;
if ( *v6 == 45 )
{
v8 = v6[1];
switch ( v6[1] )
{
case '#':
case 'E':
case 'b':
case 'w':
v11 = v6 + 2;
v12 = v5 + 1;
if ( v6[2] )
goto LABEL_32;
if ( argc > v12 )
{
v11 = argv[v7 / 8 + 1];
v5 += 2;
if ( *v11 )
{
if ( *v11 != 45 )
goto LABEL_33;
}
}
fprintf(*((FILE **)&GlobalState + 23), "Usage: -%c value\n", v8);
goto LABEL_18;
case '-':
v13 = (const char *)&unk_111;
if ( v5 + 1 < argc )
v13 = argv[v7 / 8 + 1];
v5 += process_long_form_argument(v6 + 2, v13, v7);
continue;
case '7':
case 'C':
case 'D':
case 'F':
case 'M':
case 'N':
case 'P':
case 'S':
case 'U':
case 'V':
case 'Z':
case 'r':
case 's':
++v5;
process_argument(v8, &unk_111, v7);
continue;
case '?':
++v5;
process_argument(104LL, &unk_111, v7);
continue;
case 'A':
case 'L':
case 'R':
case 'a':
case 'c':
case 'd':
case 'f':
case 'l':
case 'n':
case 'o':
v11 = v6 + 2;
v12 = v5 + 1;
if ( v6[2] )
goto LABEL_32;
if ( argc > v12 )
{
v11 = argv[v7 / 8 + 1];
v5 += 2;
if ( *v11 )
{
if ( *v11 != 45 )
goto LABEL_33;
}
}
fprintf(*((FILE **)&GlobalState + 23), "Usage: -%c filename\n", v8);
goto LABEL_18;
case 'T':
++v5;
process_argument(84LL, v6 + 2, v7);
continue;
case 'W':
case 'e':
case 'h':
++v5;
process_argument(v8, v6 + 2, v7);
continue;
case 't':
case 'v':
case 'x':
case 'z':
v11 = v6 + 2;
v12 = v5 + 1;
if ( v6[2] )
{
LABEL_32:
v5 = v12;
}
else if ( argc <= v12 || (v11 = argv[v7 / 8 + 1], v5 += 2, !*v11) || *v11 == 45 )
{
fprintf(*((FILE **)&GlobalState + 23), "Usage: -%cfilename or -%c filename\n", v8, v8);
exit(1);
}
LABEL_33:
process_argument(v8, v11, v7);
continue;
default:
fprintf(*((FILE **)&GlobalState + 23), "Unknown flag %s. Use -%c for usage details.\n", argv[v5], 104LL);
exit(1);
}
}
++v5;
add_filename_to_source_list(v6, 0LL, v7);
}
while ( v5 < argc );
}
init_duplicate_hash_table();
if ( *((_DWORD *)&GlobalState + 12) )
{
if ( !(unsigned int)open_eco_file(*((_QWORD *)&GlobalState + 20)) )
{
fprintf(*((FILE **)&GlobalState + 23), "Unable to open the ECO file %s.\n", *((const char **)&GlobalState + 20));
exit(1);
}
*((_DWORD *)&GlobalState + 13) = 1;
yyparse(2LL);
*((_DWORD *)&GlobalState + 13) = 0;
}
if ( !(unsigned int)open_first_file() )
LABEL_18:
exit(1);
yyparse(*((unsigned int *)&GlobalState + 38));
clear_duplicate_hash_table();
if ( *((_DWORD *)&GlobalState + 1) )
{
v14 = *((_QWORD *)&GlobalState + 14);
v15 = &unk_111;
if ( v14 != 1 )
v15 = &unk_112;
fprintf(*((FILE **)&GlobalState + 23), "%lu game%s matched out of %lu.\n", v14, v15, *((_QWORD *)&GlobalState + 13));
}
v9 = (struct _IO_FILE *)*((_QWORD *)&GlobalState + 23);
if ( stderr != v9 && v9 )
fclose(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v5; // ebx
const char *v6; // rdi
unsigned __int64 v7; // rdx
unsigned int v8; // er8
struct _IO_FILE *v9; // rdi
const char *v11; // rsi
int v12; // eax
const char *v13; // rsi
__int64 v14; // rdx
void *v15; // rcx

v5 = 1;
func0(argc, argv, envp);
init_game_header();
init_tag_lists();
init_hashtab();
init_lex_tables();
if ( argc > 1 )
{
do
{
v6 = argv[v5];
v7 = 8LL * v5;
if ( *v6 == 45 )
{
v8 = v6[1];
switch ( v6[1] )
{
case '#':
case 'E':
case 'b':
case 'w':
v11 = v6 + 2;
v12 = v5 + 1;
if ( v6[2] )
goto LABEL_32;
if ( argc > v12 )
{
v11 = argv[v7 / 8 + 1];
v5 += 2;
if ( *v11 )
{
if ( *v11 != 45 )
goto LABEL_33;
}
}
fprintf(*((FILE **)&GlobalState + 23), "Usage: -%c value\n", v8);
goto LABEL_18;
case '-':
v13 = (const char *)&unk_111;
if ( v5 + 1 < argc )
v13 = argv[v7 / 8 + 1];
v5 += process_long_form_argument(v6 + 2, v13, v7);
continue;
case '7':
case 'C':
case 'D':
case 'F':
case 'M':
case 'N':
case 'P':
case 'S':
case 'U':
case 'V':
case 'Z':
case 'r':
case 's':
++v5;
process_argument(v8, &unk_111, v7);
continue;
case '?':
++v5;
process_argument(104LL, &unk_111, v7);
continue;
case 'A':
case 'L':
case 'R':
case 'a':
case 'c':
case 'd':
case 'f':
case 'l':
case 'n':
case 'o':
v11 = v6 + 2;
v12 = v5 + 1;
if ( v6[2] )
goto LABEL_32;
if ( argc > v12 )
{
v11 = argv[v7 / 8 + 1];
v5 += 2;
if ( *v11 )
{
if ( *v11 != 45 )
goto LABEL_33;
}
}
fprintf(*((FILE **)&GlobalState + 23), "Usage: -%c filename\n", v8);
goto LABEL_18;
case 'T':
++v5;
process_argument(84LL, v6 + 2, v7);
continue;
case 'W':
case 'e':
case 'h':
++v5;
process_argument(v8, v6 + 2, v7);
continue;
case 't':
case 'v':
case 'x':
case 'z':
v11 = v6 + 2;
v12 = v5 + 1;
if ( v6[2] )
{
LABEL_32:
v5 = v12;
}
else if ( argc <= v12 || (v11 = argv[v7 / 8 + 1], v5 += 2, !*v11) || *v11 == 45 )
{
fprintf(*((FILE **)&GlobalState + 23), "Usage: -%cfilename or -%c filename\n", v8, v8);
exit(1);
}
LABEL_33:
process_argument(v8, v11, v7);
continue;
default:
fprintf(*((FILE **)&GlobalState + 23), "Unknown flag %s. Use -%c for usage details.\n", argv[v5], 104LL);
exit(1);
}
}
++v5;
add_filename_to_source_list(v6, 0LL, v7);
}
while ( v5 < argc );
}
init_duplicate_hash_table();
if ( *((_DWORD *)&GlobalState + 12) )
{
if ( !(unsigned int)open_eco_file(*((_QWORD *)&GlobalState + 20)) )
{
fprintf(*((FILE **)&GlobalState + 23), "Unable to open the ECO file %s.\n", *((const char **)&GlobalState + 20));
exit(1);
}
*((_DWORD *)&GlobalState + 13) = 1;
yyparse(2LL);
*((_DWORD *)&GlobalState + 13) = 0;
}
if ( !(unsigned int)open_first_file() )
LABEL_18:
exit(1);
yyparse(*((unsigned int *)&GlobalState + 38));
clear_duplicate_hash_table();
if ( *((_DWORD *)&GlobalState + 1) )
{
v14 = *((_QWORD *)&GlobalState + 14);
v15 = &unk_111;
if ( v14 != 1 )
v15 = &unk_112;
fprintf(*((FILE **)&GlobalState + 23), "%lu game%s matched out of %lu.\n", v14, v15, *((_QWORD *)&GlobalState + 13));
}
v9 = (struct _IO_FILE *)*((_QWORD *)&GlobalState + 23);
if ( stderr != v9 && v9 )
fclose(v9);
return 0;
}

original_code:
int
main(int argc, char *argv[])
{ int argnum;
    init_default_global_state();
    init_game_header();
    init_tag_lists();
    init_hashtab();
    init_lex_tables();
    for(argnum = 1; argnum < argc; ){
        const char *argument = argv[argnum];
        if(argument[0] == '-'){
            switch(argument[1]){
                case SEVEN_TAG_ROSTER_ARGUMENT:
                case DONT_KEEP_COMMENTS_ARGUMENT:
                case DONT_KEEP_DUPLICATES_ARGUMENT:
                case DONT_KEEP_VARIATIONS_ARGUMENT:
                case DONT_KEEP_NAGS_ARGUMENT:
                case DONT_MATCH_PERMUTATIONS_ARGUMENT:
                case CHECK_ONLY_ARGUMENT:
                case KEEP_SILENT_ARGUMENT:
                case USE_SOUNDEX_ARGUMENT:
                case MATCH_CHECKMATE_ARGUMENT:
                case SUPPRESS_ORIGINALS_ARGUMENT:
                case OUTPUT_FEN_STRING_ARGUMENT:
                case USE_VIRTUAL_HASH_TABLE_ARGUMENT:
                    process_argument(argument[1], "");
                    argnum++;
                    break;
                case ALTERNATIVE_HELP_ARGUMENT:
                    process_argument(HELP_ARGUMENT, "");
                    argnum++;
                    break;
                case TAG_EXTRACTION_ARGUMENT:
                    process_argument(argument[1], &(argument[2]));
                    argnum++;
                    break;
                case USE_ECO_FILE_ARGUMENT:
                case OUTPUT_FORMAT_ARGUMENT:
                case HELP_ARGUMENT:
                    process_argument(argument[1], &(argument[2]));
                    argnum++;
                    break;
                case LONG_FORM_ARGUMENT:
                    {
                      int args_processed;
                      const char *possible_associated_value = "";
                      if(argnum + 1 < argc) {
                          possible_associated_value = argv[argnum+1];
                      }
                      args_processed =
                          process_long_form_argument(&argument[2],
                                                     possible_associated_value);
                      argnum += args_processed;
                    }
                    break;
                case FILE_OF_ARGUMENTS_ARGUMENT:
                case APPEND_TO_OUTPUT_FILE_ARGUMENT:
                case CHECK_FILE_ARGUMENT:
                case DUPLICATES_FILE_ARGUMENT:
                case FILE_OF_FILES_ARGUMENT:
                case WRITE_TO_LOG_FILE_ARGUMENT:
                case APPEND_TO_LOG_FILE_ARGUMENT:
                case NON_MATCHING_GAMES_ARGUMENT:
                case WRITE_TO_OUTPUT_FILE_ARGUMENT:
                case TAG_ROSTER_ARGUMENT:
                    {
                        const char argument_letter = argument[1];
                        const char *filename = &(argument[2]);
                        if(*filename == '\0'){
                             argnum++;
                             if(argnum < argc){
                                 filename = argv[argnum];
                                 argnum++;
                             }
                            if((*filename == '\0') || (*filename == '-')){
                                fprintf(GlobalState.logfile,
                                        "Usage: -%c filename\n",
                                        argument_letter);
                                exit(1);
                            }
                        }
                        else {
                            argnum++;
                        }
                        process_argument(argument[1], filename);
                    }
                    break;
                case BOUNDS_ARGUMENT:
                case ECO_OUTPUT_LEVEL_ARGUMENT:
                case LINE_WIDTH_ARGUMENT:
                case GAMES_PER_FILE_ARGUMENT:
                    {
                        const char argument_letter = argument[1];
                        const char *associated_value = &(argument[2]);
                        if(*associated_value == '\0'){
                             argnum++;
                             if(argnum < argc){
                                 associated_value = argv[argnum];
                                 argnum++;
                             }
                            if((*associated_value == '\0') ||
                                       (*associated_value == '-')){
                                fprintf(GlobalState.logfile,
                                        "Usage: -%c value\n",
                                        argument_letter);
                                exit(1);
                            }
                        }
                        else {
                            argnum++;
                        }
                        process_argument(argument[1], associated_value);
                    }
                    break;
                case TAGS_ARGUMENT:
                case MOVES_ARGUMENT:
                case POSITIONS_ARGUMENT:
                case ENDINGS_ARGUMENT:
                    {
                        const char *filename = &(argument[2]);
                        const char argument_letter = argument[1];
                        if(*filename == '\0'){
                             argnum++;
                             if(argnum < argc){
                                 filename = argv[argnum];
                                 argnum++;
                             }
                            if((*filename == '\0') || (*filename == '-')){
                                fprintf(GlobalState.logfile,
                                        "Usage: -%cfilename or -%c filename\n",
                                        argument_letter,argument_letter);
                                exit(1);
                            }
                        }
                        else{
                            argnum++;
                        }
                        process_argument(argument_letter,filename);
                    }
                    break;
                default:
                    fprintf(GlobalState.logfile,
                            "Unknown flag %s. Use -%c for usage details.\n",
                            argument,HELP_ARGUMENT);
                    exit(1);
                    break;
            }
        }
        else{
            add_filename_to_source_list(argument,NORMALFILE);
            argnum++;
        }
    }
    init_duplicate_hash_table();
    if(GlobalState.add_ECO){
        if(open_eco_file(GlobalState.eco_file)){
            GlobalState.parsing_ECO_file = TRUE;
            yyparse(ECOFILE);
            GlobalState.parsing_ECO_file = FALSE;
        }
        else{
            fprintf(GlobalState.logfile,"Unable to open the ECO file %s.\n",
                        GlobalState.eco_file);
            exit(1);
        }
    }
    if(!open_first_file()){
        exit(1);
    }
    yyparse(GlobalState.current_file_type);
    clear_duplicate_hash_table();
    if(GlobalState.verbose){
        fprintf(GlobalState.logfile,"%lu game%s matched out of %lu.\n",
                        GlobalState.num_games_matched,
                        GlobalState.num_games_matched == 1?"":"s",
                        GlobalState.num_games_processed);
    }
    if((GlobalState.logfile != stderr) && (GlobalState.logfile != ((void *)0))){
        (void) fclose(GlobalState.logfile);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{ int argnum;
    init_default_global_state();
    init_game_header();
    init_tag_lists();
    init_hashtab();
    init_lex_tables();
    for(argnum = 1; argnum < argc; ){
        char *argument = argv[argnum];
        if(argument[0] == '-'){
            switch(argument[1]){
                case SEVEN_TAG_ROSTER_ARGUMENT:
                case DONT_KEEP_COMMENTS_ARGUMENT:
                case DONT_KEEP_DUPLICATES_ARGUMENT:
                case DONT_KEEP_VARIATIONS_ARGUMENT:
                case DONT_KEEP_NAGS_ARGUMENT:
                case DONT_MATCH_PERMUTATIONS_ARGUMENT:
                case CHECK_ONLY_ARGUMENT:
                case KEEP_SILENT_ARGUMENT:
                case USE_SOUNDEX_ARGUMENT:
                case MATCH_CHECKMATE_ARGUMENT:
                case SUPPRESS_ORIGINALS_ARGUMENT:
                case OUTPUT_FEN_STRING_ARGUMENT:
                case USE_VIRTUAL_HASH_TABLE_ARGUMENT:
                    process_argument(argument[1], "");
                    argnum++;
                    break;
                case ALTERNATIVE_HELP_ARGUMENT:
                    process_argument(HELP_ARGUMENT, "");
                    argnum++;
                    break;
                case TAG_EXTRACTION_ARGUMENT:
                    process_argument(argument[1], &(argument[2]));
                    argnum++;
                    break;
                case USE_ECO_FILE_ARGUMENT:
                case OUTPUT_FORMAT_ARGUMENT:
                case HELP_ARGUMENT:
                    process_argument(argument[1], &(argument[2]));
                    argnum++;
                    break;
                case LONG_FORM_ARGUMENT:
                    {
                      int args_processed;
                      char *possible_associated_value = "";
                      if(argnum + 1 < argc) {
                          possible_associated_value = argv[argnum+1];
                      }
                      args_processed =
                          process_long_form_argument(&argument[2],
                                                     possible_associated_value);
                      argnum += args_processed;
                    }
                    break;
                case FILE_OF_ARGUMENTS_ARGUMENT:
                case APPEND_TO_OUTPUT_FILE_ARGUMENT:
                case CHECK_FILE_ARGUMENT:
                case DUPLICATES_FILE_ARGUMENT:
                case FILE_OF_FILES_ARGUMENT:
                case WRITE_TO_LOG_FILE_ARGUMENT:
                case APPEND_TO_LOG_FILE_ARGUMENT:
                case NON_MATCHING_GAMES_ARGUMENT:
                case WRITE_TO_OUTPUT_FILE_ARGUMENT:
                case TAG_ROSTER_ARGUMENT:
                    {
                        char argument_letter = argument[1];
                        char *filename = &(argument[2]);
                        if(*filename == '\0'){
                             argnum++;
                             if(argnum < argc){
                                 filename = argv[argnum];
                                 argnum++;
                             }
                            if((*filename == '\0') || (*filename == '-')){
                                fprintf(GlobalState.logfile,
                                        "Usage: -%c filename\n",
                                        argument_letter);
                                exit(1);
                            }
                        }
                        else {
                            argnum++;
                        }
                        process_argument(argument[1], filename);
                    }
                    break;
                case BOUNDS_ARGUMENT:
                case ECO_OUTPUT_LEVEL_ARGUMENT:
                case LINE_WIDTH_ARGUMENT:
                case GAMES_PER_FILE_ARGUMENT:
                    {
                        char argument_letter = argument[1];
                        char *associated_value = &(argument[2]);
                        if(*associated_value == '\0'){
                             argnum++;
                             if(argnum < argc){
                                 associated_value = argv[argnum];
                                 argnum++;
                             }
                            if((*associated_value == '\0') ||
                                       (*associated_value == '-')){
                                fprintf(GlobalState.logfile,
                                        "Usage: -%c value\n",
                                        argument_letter);
                                exit(1);
                            }
                        }
                        else {
                            argnum++;
                        }
                        process_argument(argument[1], associated_value);
                    }
                    break;
                case TAGS_ARGUMENT:
                case MOVES_ARGUMENT:
                case POSITIONS_ARGUMENT:
                case ENDINGS_ARGUMENT:
                    {
                        char *filename = &(argument[2]);
                        char argument_letter = argument[1];
                        if(*filename == '\0'){
                             argnum++;
                             if(argnum < argc){
                                 filename = argv[argnum];
                                 argnum++;
                             }
                            if((*filename == '\0') || (*filename == '-')){
                                fprintf(GlobalState.logfile,
                                        "Usage: -%cfilename or -%c filename\n",
                                        argument_letter,argument_letter);
                                exit(1);
                            }
                        }
                        else{
                            argnum++;
                        }
                        process_argument(argument_letter,filename);
                    }
                    break;
                default:
                    fprintf(GlobalState.logfile,
                            "Unknown flag %s. Use -%c for usage details.\n",
                            argument,HELP_ARGUMENT);
                    exit(1);
                    break;
            }
        }
        else{
            add_filename_to_source_list(argument,NORMALFILE);
            argnum++;
        }
    }
    init_duplicate_hash_table();
    if(GlobalState.add_ECO){
        if(open_eco_file(GlobalState.eco_file)){
            GlobalState.parsing_ECO_file = TRUE;
            yyparse(ECOFILE);
            GlobalState.parsing_ECO_file = FALSE;
        }
        else{
            fprintf(GlobalState.logfile,"Unable to open the ECO file %s.\n",
                        GlobalState.eco_file);
            exit(1);
        }
    }
    if(!open_first_file()){
        exit(1);
    }
    yyparse(GlobalState.current_file_type);
    clear_duplicate_hash_table();
    if(GlobalState.verbose){
        fprintf(GlobalState.logfile,"%lu game%s matched out of %lu.\n",
                        GlobalState.num_games_matched,
                        GlobalState.num_games_matched == 1?"":"s",
                        GlobalState.num_games_processed);
    }
    if((GlobalState.logfile != stderr) && (GlobalState.logfile != ((void *)0))){
        (void) fclose(GlobalState.logfile);
    }
    return 0;
}

variable_types: argnum int

variable_types:
argument
char *

variable_types:
filename
char *


MallocOrDie

decompiled_code:
void *__fastcall MallocOrDie(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
perror("Malloc Or Die");
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
perror("Malloc Or Die");
abort();
}
return result;
}

original_code:
void *
MallocOrDie(size_t nbytes)
{ void *result;
    result = malloc(nbytes);
    if(result == ((void *)0)){
        perror("Malloc Or Die");
        abort();
    }
    return result;
}

canonical_original_code:
void *MallocOrDie(unsigned long nbytes)
{ void *result;
    result = malloc(nbytes);
    if(result == ((void *)0)){
        perror("Malloc Or Die");
        abort();
    }
    return result;
}

variable_types:
nbytes
unsigned long

variable_types:
result
void *


ReallocOrDie

decompiled_code:
void *__fastcall ReallocOrDie(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
perror("Realloc Or Die");
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
perror("Realloc Or Die");
abort();
}
return result;
}

original_code:
void *
ReallocOrDie(void *space,size_t nbytes)
{ void *result;
    result = realloc(space,nbytes);
    if(result == ((void *)0)){
        perror("Realloc Or Die");
        abort();
    }
    return result;
}

canonical_original_code:
void *ReallocOrDie(void *space, unsigned long nbytes)
{ void *result;
    result = realloc(space,nbytes);
    if(result == ((void *)0)){
        perror("Realloc Or Die");
        abort();
    }
    return result;
}

variable_types:
space
void *


decompiled_code:
__int64 __fastcall move_char(char a1)
{
return (a1 == 45) | (unsigned __int8)(((*_ctype_b_loc())[a1] & 0xC00) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
return (a1 == 45) | (unsigned __int8)(((*_ctype_b_loc())[a1] & 0xC00) != 0);
}

original_code:
static Boolean
move_char(char c)
{
    return (Boolean) ((*__ctype_b_loc ())[(int) (((int) c))] & (unsigned short int) _ISalpha) || ((*__ctype_b_loc ())[(int) (((int) c))] & (unsigned short int) _ISdigit) || (c == '-');
}

canonical_original_code:
static enum Boolean move_char(char c)
{
    return (Boolean) ((*__ctype_b_loc ())[(int) (((int) c))] & (unsigned short) _ISalpha) || ((*__ctype_b_loc ())[(int) (((int) c))] & (unsigned short) _ISdigit) || (c == '-');
}

variable_types: c char

return_type: enum Boolean { FALSE=0, TRUE=1 }


decompiled_code:
__int64 __fastcall compose_positional_variation(char *a1)
{
__int64 v1; // r14
__int64 v2; // r12
int v3; // ebp
char *v4; // rdi
__int64 v5; // rax
char v6; // bl
int v7; // er13
char *v8; // rax
char *v9; // r13
const char *v10; // rdx
unsigned int v12; // eax

v1 = 0LL;
v2 = 0LL;
v3 = 0;
v4 = strtok(a1, " ");
if ( !v4 )
{
v12 = 4;
goto LABEL_16;
}
do
{
if ( *v4 == 42 )
{
v12 = ((unsigned int)(v3 + 1) >> 1) + 4;
goto LABEL_16;
}
v8 = strip_move_number(v4);
v9 = v8;
if ( v8 )
{
v5 = decode_move(v8);
if ( v5 )
{
if ( v2 )
*(_QWORD *)(v2 + 88) = v5;
else
v1 = v5;
*(_QWORD *)(v5 + 88) = 0LL;
v2 = v5;
v6 = 1;
v7 = 1;
}
else
{
v10 = v9;
v6 = 0;
v7 = 0;
fprintf(*((FILE **)&GlobalState + 23), "Failed to identify %s\n", v10);
}
++v3;
}
else
{
v6 = 1;
v7 = 1;
}
v4 = strtok(0LL, " ");
}
while ( v4 && v6 );
if ( v7 )
{
v12 = ((unsigned int)(v3 + 1) >> 1) + 4;
LABEL_16:
if ( *((_DWORD *)&GlobalState + 24) < v12 )
*((_DWORD *)&GlobalState + 24) = v12;
return v1;
}
if ( !v1 )
return v1;
free_move_list(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
__int64 v1; // r14
__int64 v2; // r12
int v3; // ebp
char *v4; // rdi
__int64 v5; // rax
char v6; // bl
int v7; // er13
char *v8; // rax
char *v9; // r13
const char *v10; // rdx
unsigned int v12; // eax

v1 = 0LL;
v2 = 0LL;
v3 = 0;
v4 = strtok(a1, " ");
if ( !v4 )
{
v12 = 4;
goto LABEL_16;
}
do
{
if ( *v4 == 42 )
{
v12 = ((unsigned int)(v3 + 1) >> 1) + 4;
goto LABEL_16;
}
v8 = func0(v4);
v9 = v8;
if ( v8 )
{
v5 = decode_move(v8);
if ( v5 )
{
if ( v2 )
*(_QWORD *)(v2 + 88) = v5;
else
v1 = v5;
*(_QWORD *)(v5 + 88) = 0LL;
v2 = v5;
v6 = 1;
v7 = 1;
}
else
{
v10 = v9;
v6 = 0;
v7 = 0;
fprintf(*((FILE **)&GlobalState + 23), "Failed to identify %s\n", v10);
}
++v3;
}
else
{
v6 = 1;
v7 = 1;
}
v4 = strtok(0LL, " ");
}
while ( v4 && v6 );
if ( v7 )
{
v12 = ((unsigned int)(v3 + 1) >> 1) + 4;
LABEL_16:
if ( *((_DWORD *)&GlobalState + 24) < v12 )
*((_DWORD *)&GlobalState + 24) = v12;
return v1;
}
if ( !v1 )
return v1;
free_move_list(v1);
return 0LL;
}

original_code:
static Move *
compose_positional_variation(char *line)
{ char *move;
    Move *head = ((void *)0), *tail = ((void *)0);
    Boolean Ok = TRUE;
    unsigned depth = 0;
    move = strtok(line," ");
    while(Ok && (move != ((void *)0)) && (*move != '*')){
        if((move = strip_move_number(move)) == ((void *)0)){
        }
        else{
            Move *next = decode_move((unsigned char *) move);
            if(next == ((void *)0)){
                fprintf(GlobalState.logfile,"Failed to identify %s\n",move);
                Ok = FALSE;
            }
            else{
                if(tail == ((void *)0)){
                    head = next;
                    tail = next;
                }
                else{
                    tail->next = next;
                    tail = next;
                }
                next->next = ((void *)0);
            }
            depth++;
        }
        move = strtok(((void *)0)," ");
    }
    if(Ok){
        depth = ((depth+1) / 2) + 4;
        if(depth > GlobalState.depth_of_positional_search){
            GlobalState.depth_of_positional_search = depth;
        }
    }
    else{
        if(head != ((void *)0)){
            free_move_list(head);
        }
        head = ((void *)0);
    }
    return head;
}

canonical_original_code:
static struct move *compose_positional_variation(char *line)
{ char *move;
    struct move *head = ((void *)0); struct move *tail = ((void *)0);
    enum Boolean Ok = TRUE;
    unsigned int depth = 0;
    move = strtok(line," ");
    while(Ok && (move != ((void *)0)) && (*move != '*')){
        if((move = strip_move_number(move)) == ((void *)0)){
        }
        else{
            struct move *next = decode_move((unsigned char *) move);
            if(next == ((void *)0)){
                fprintf(GlobalState.logfile,"Failed to identify %s\n",move);
                Ok = FALSE;
            }
            else{
                if(tail == ((void *)0)){
                    head = next;
                    tail = next;
                }
                else{
                    tail->next = next;
                    tail = next;
                }
                next->next = ((void *)0);
            }
            depth++;
        }
        move = strtok(((void *)0)," ");
    }
    if(Ok){
        depth = ((depth+1) / 2) + 4;
        if(depth > GlobalState.depth_of_positional_search){
            GlobalState.depth_of_positional_search = depth;
        }
    }
    else{
        if(head != ((void *)0)){
            free_move_list(head);
        }
        head = ((void *)0);
    }
    return head;
}

variable_types:
line
char *

variable_types:
move
char *

variable_types: struct move { unsigned char move[-1]; enum MoveClass { PAWN_MOVE=0, PAWN_MOVE_WITH_PROMOTION=1, ENPASSANT_PAWN_MOVE=2, PIECE_MOVE=3, KINGSIDE_CASTLE=4, QUEENSIDE_CASTLE=5, UNKNOWN_MOVE=6 } class; char from_col; char from_rank; char to_col; char to_rank; enum Piece { OFF=0, EMPTY=1, PAWN=2, KNIGHT=3, BISHOP=4, ROOK=5, QUEEN=6, KING=7, NUM_PIECE_VALUES=8 } piece_to_move; enum Piece { OFF=0, EMPTY=1, PAWN=2, KNIGHT=3, BISHOP=4, ROOK=5, QUEEN=6, KING=7, NUM_PIECE_VALUES=8 } captured_piece; enum Piece { OFF=0, EMPTY=1, PAWN=2, KNIGHT=3, BISHOP=4, ROOK=5, QUEEN=6, KING=7, NUM_PIECE_VALUES=8 } promoted_piece; enum CheckStatus { NOCHECK=0, CHECK=1, CHECKMATE=2 } check_status; char *epd; struct string_list { char *str; struct string_list *next; } *Nags; struct comment_list { struct string_list *Comment; struct comment_list *next; } *Comment; char *terminating_result; struct variation { struct comment_list *prefix_comment; struct move *moves; struct comment_list *suffix_comment; struct variation *next; } *Variants; struct move *prev; } *

variable_types:
Ok
enum Boolean { FALSE=0, TRUE=1 }

variable_types:
depth
unsigned int

user_defined_types: struct move { unsigned char move[-1]; enum MoveClass class; char from_col; char from_rank; char to_col; char to_rank; enum Piece piece_to_move; enum Piece captured_piece; enum Piece promoted_piece; enum CheckStatus check_status; char *epd; struct string_list *Nags; struct comment_list *Comment; char *terminating_result; struct variation *Variants; struct move *prev; }


decompiled_code:
__int64 __fastcall textual_variation_match(char *haystack, char *needle)
{
__int64 result; // rax
char *v3; // rbp
size_t v4; // rax

result = 0LL;
v3 = haystack;
while ( (result & 1) == 0 && v3 )
{
v3 = strstr(v3, needle);
result = 0LL;
if ( v3 )
{
if ( haystack == v3 || !(unsigned int)move_char(*(v3 - 1)) )
{
v4 = strlen(needle);
if ( !(unsigned int)move_char(v3[v4]) )
return 1LL;
}
while ( 1 )
{
result = move_char(*v3);
if ( !(_DWORD)result )
break;
++v3;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *haystack, char *needle)
{
__int64 result; // rax
char *v3; // rbp
size_t v4; // rax

result = 0LL;
v3 = haystack;
while ( (result & 1) == 0 && v3 )
{
v3 = strstr(v3, needle);
result = 0LL;
if ( v3 )
{
if ( haystack == v3 || !(unsigned int)func1(*(v3 - 1)) )
{
v4 = strlen(needle);
if ( !(unsigned int)func1(v3[v4]) )
return 1LL;
}
while ( 1 )
{
result = func1(*v3);
if ( !(_DWORD)result )
break;
++v3;
}
}
}
return result;
}

original_code:
static Boolean
textual_variation_match(const char *variation_move,const unsigned char *actual_move)
{ const char *match_point;
    Boolean found = FALSE;
    for(match_point = variation_move; !found && (match_point != ((void *)0)); ){
        match_point = strstr(match_point,(const char *) actual_move);
        if(match_point != ((void *)0)){
            found = TRUE;
            if(match_point != variation_move){
                if(move_char(match_point[-1])){
                    found = FALSE;
                }
            }
            if(move_char(match_point[strlen((const char *) actual_move)])){
                found = FALSE;
            }
            if(!found){
                while(move_char(*match_point)){
                    match_point++;
                }
            }
        }
    }
    return found;
}

canonical_original_code:
static enum Boolean textual_variation_match(char *variation_move, unsigned char *actual_move)
{ char *match_point;
    enum Boolean found = FALSE;
    for(match_point = variation_move; !found && (match_point != ((void *)0)); ){
        match_point = strstr(match_point,(char *) actual_move);
        if(match_point != ((void *)0)){
            found = TRUE;
            if(match_point != variation_move){
                if(move_char(match_point[-1])){
                    found = FALSE;
                }
            }
            if(move_char(match_point[strlen((char *) actual_move)])){
                found = FALSE;
            }
            if(!found){
                while(move_char(*match_point)){
                    match_point++;
                }
            }
        }
    }
    return found;
}

variable_types:
found
enum Boolean { FALSE=0, TRUE=1 }


original_code:
static Boolean
permutation_match(Move *current_game_head, variation_list variation)
{ variant_move *moves_of_the_variation;
    Move *next_move;
    unsigned variant_index = 0;
    Boolean matches = TRUE;
    unsigned matched_moves = 0;
    Boolean white_to_move = TRUE;
    moves_of_the_variation = variation.moves;
    for(variant_index = 0; variant_index < variation.length; variant_index++){
        moves_of_the_variation[variant_index].matched = FALSE;
    }
    next_move = current_game_head;
    if((variation.num_white_disallowed_moves > 0) ||
            (variation.num_black_disallowed_moves > 0)){
        unsigned tested_moves = 0;
        Boolean disallowed_move_found = FALSE;
        while((!disallowed_move_found) && (tested_moves < variation.length) &&
                                        (next_move != ((void *)0))){
            if(white_to_move){
                variant_index = 0;
            }
            else{
                variant_index = 1;
            }
            while((!disallowed_move_found) && (variant_index < variation.length)){
                if((*moves_of_the_variation[variant_index].move ==
                            '!') &&
                   (textual_variation_match(
                      moves_of_the_variation[variant_index].move,next_move->move))){
                    disallowed_move_found = TRUE;
                }
                if(!disallowed_move_found){
                    variant_index += 2;
                }
            }
            if(!disallowed_move_found){
                tested_moves++;
                white_to_move = !white_to_move;
                next_move = next_move->next;
            }
        }
        if(disallowed_move_found){
            matches = FALSE;
        }
        else{
            for(variant_index = 0; variant_index < variation.length; variant_index++){
                if(*moves_of_the_variation[variant_index].move == '!'){
                    moves_of_the_variation[variant_index].matched = TRUE;
                    if((variant_index & 1) == 0){
                        variation.num_white_any_moves++;
                    }
                    else{
                        variation.num_black_any_moves++;
                    }
                }
            }
        }
    }
    next_move = current_game_head;
    white_to_move = TRUE;
    while(matches && (matched_moves < variation.length) && (next_move != ((void *)0))){
        matches = FALSE;
        if(white_to_move){
            variant_index = 0;
        }
        else{
            variant_index = 1;
        }
        while((!matches) && (variant_index < variation.length)){
            if(moves_of_the_variation[variant_index].matched){
            }
            else{
                Boolean this_move_matches = textual_variation_match(
                            moves_of_the_variation[variant_index].move,
                                        next_move->move);
                if(this_move_matches){
                    moves_of_the_variation[variant_index].matched = TRUE;
                    matches = TRUE;
                }
            }
            if(!matches){
                variant_index += 2;
            }
        }
        if(!matches){
            if(white_to_move && (variation.num_white_any_moves > 0)){
                matches = TRUE;
                variation.num_white_any_moves--;
            }
            else if(!white_to_move && (variation.num_black_any_moves > 0)){
                matches = TRUE;
                variation.num_black_any_moves--;
            }
            else{
            }
        }
        if(matches){
            matched_moves++;
            next_move = next_move->next;
            white_to_move = !white_to_move;
        }
    }
    if(matches){
        matches = matched_moves == (variation.length);
    }
    return matches;
}

canonical_original_code:
static enum Boolean permutation_match(struct move *current_game_head, struct variation_list variation)
{ struct variant_move *moves_of_the_variation;
    struct move *next_move;
    unsigned int variant_index = 0;
    enum Boolean matches = TRUE;
    unsigned int matched_moves = 0;
    enum Boolean white_to_move = TRUE;
    moves_of_the_variation = variation.moves;
    for(variant_index = 0; variant_index < variation.length; variant_index++){
        moves_of_the_variation[variant_index].matched = FALSE;
    }
    next_move = current_game_head;
    if((variation.num_white_disallowed_moves > 0) ||
            (variation.num_black_disallowed_moves > 0)){
        unsigned int tested_moves = 0;
        enum Boolean disallowed_move_found = FALSE;
        while((!disallowed_move_found) && (tested_moves < variation.length) &&
                                        (next_move != ((void *)0))){
            if(white_to_move){
                variant_index = 0;
            }
            else{
                variant_index = 1;
            }
            while((!disallowed_move_found) && (variant_index < variation.length)){
                if((*moves_of_the_variation[variant_index].move ==
                            '!') &&
                   (textual_variation_match(
                      moves_of_the_variation[variant_index].move,next_move->move))){
                    disallowed_move_found = TRUE;
                }
                if(!disallowed_move_found){
                    variant_index += 2;
                }
            }
            if(!disallowed_move_found){
                tested_moves++;
                white_to_move = !white_to_move;
                next_move = next_move->next;
            }
        }
        if(disallowed_move_found){
            matches = FALSE;
        }
        else{
            for(variant_index = 0; variant_index < variation.length; variant_index++){
                if(*moves_of_the_variation[variant_index].move == '!'){
                    moves_of_the_variation[variant_index].matched = TRUE;
                    if((variant_index & 1) == 0){
                        variation.num_white_any_moves++;
                    }
                    else{
                        variation.num_black_any_moves++;
                    }
                }
            }
        }
    }
    next_move = current_game_head;
    white_to_move = TRUE;
    while(matches && (matched_moves < variation.length) && (next_move != ((void *)0))){
        matches = FALSE;
        if(white_to_move){
            variant_index = 0;
        }
        else{
            variant_index = 1;
        }
        while((!matches) && (variant_index < variation.length)){
            if(moves_of_the_variation[variant_index].matched){
            }
            else{
                enum Boolean this_move_matches = textual_variation_match(
                            moves_of_the_variation[variant_index].move,
                                        next_move->move);
                if(this_move_matches){
                    moves_of_the_variation[variant_index].matched = TRUE;
                    matches = TRUE;
                }
            }
            if(!matches){
                variant_index += 2;
            }
        }
        if(!matches){
            if(white_to_move && (variation.num_white_any_moves > 0)){
                matches = TRUE;
                variation.num_white_any_moves--;
            }
            else if(!white_to_move && (variation.num_black_any_moves > 0)){
                matches = TRUE;
                variation.num_black_any_moves--;
            }
            else{
            }
        }
        if(matches){
            matched_moves++;
            next_move = next_move->next;
            white_to_move = !white_to_move;
        }
    }
    if(matches){
        matches = matched_moves == (variation.length);
    }
    return matches;
}

variable_types: struct variation_list { struct variant_move { char *move; enum Boolean { FALSE=0, TRUE=1 } matched; } *moves; unsigned int num_white_any_moves; unsigned int num_black_any_moves; unsigned int num_white_disallowed_moves; unsigned int num_black_disallowed_moves; unsigned int length; struct variation_list *next; }

variable_types:
matches
enum Boolean { FALSE=0, TRUE=1 }

user_defined_types: struct variation_list { struct variant_move *moves; unsigned int num_white_any_moves; unsigned int num_black_any_moves; unsigned int num_white_disallowed_moves; unsigned int num_black_disallowed_moves; unsigned int length; struct variation_list *next; }

user_defined_types: struct variant_move { char *move; enum Boolean matched; }

user_defined_types: enum MoveClass { PAWN_MOVE=0, PAWN_MOVE_WITH_PROMOTION=1, ENPASSANT_PAWN_MOVE=2, PIECE_MOVE=3, KINGSIDE_CASTLE=4, QUEENSIDE_CASTLE=5, UNKNOWN_MOVE=6 }

user_defined_types: enum Piece { OFF=0, EMPTY=1, PAWN=2, KNIGHT=3, BISHOP=4, ROOK=5, QUEEN=6, KING=7, NUM_PIECE_VALUES=8 }

user_defined_types: enum CheckStatus { NOCHECK=0, CHECK=1, CHECKMATE=2 }

user_defined_types: struct string_list { char *str; struct string_list *next; }

user_defined_types: struct comment_list { struct string_list *Comment; struct comment_list *next; }

user_defined_types: struct variation { struct comment_list *prefix_comment; struct move *moves; struct comment_list *suffix_comment; struct variation *next; }


decompiled_code:
__int64 __fastcall add_positional_variation_from_line(char *a1)
{
__int64 result; // rax
__int64 v2; // rbp

result = non_blank_line();
if ( (_DWORD)result )
{
result = compose_positional_variation(a1);
v2 = result;
if ( result )
{
store_hash_value(result, 0LL);
result = free_move_list(v2);
GlobalState[7] = 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
__int64 result; // rax
__int64 v2; // rbp

result = non_blank_line();
if ( (_DWORD)result )
{
result = func2(a1);
v2 = result;
if ( result )
{
store_hash_value(result, 0LL);
result = free_move_list(v2);
GlobalState[7] = 1;
}
}
return result;
}

original_code:
void
add_positional_variation_from_line(char *line)
{
    if(non_blank_line(line)){
        Move *next_variation = compose_positional_variation(line);
        if(next_variation != ((void *)0)){
            store_hash_value(next_variation,(const char *)((void *)0));
            free_move_list(next_variation);
            GlobalState.positional_variations = TRUE;
        }
    }
}

canonical_original_code:
void add_positional_variation_from_line(char *line)
{
    if(non_blank_line(line)){
        struct move *next_variation = compose_positional_variation(line);
        if(next_variation != ((void *)0)){
            store_hash_value(next_variation,(char *)((void *)0));
            free_move_list(next_variation);
            GlobalState.positional_variations = TRUE;
        }
    }
}


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

result = store_hash_value(0LL, a1);
GlobalState[7] = 1;
return result;
}

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

result = store_hash_value(0LL, a1);
GlobalState[7] = 1;
return result;
}

original_code:
void
add_fen_positional_match(const char *fen_string)
{
    store_hash_value((Move *)((void *)0),fen_string);
    GlobalState.positional_variations = TRUE;
}

canonical_original_code:
void add_fen_positional_match(char *fen_string)
{
    store_hash_value((struct move *)((void *)0),fen_string);
    GlobalState.positional_variations = TRUE;
}


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

result = 1LL;
if ( GlobalState[19] )
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 36) == 2 )
break;
a1 = *(_QWORD *)(a1 + 88);
}
result = 1LL;
}
return result;
}

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

result = 1LL;
if ( GlobalState[19] )
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)(a1 + 36) == 2 )
break;
a1 = *(_QWORD *)(a1 + 88);
}
result = 1LL;
}
return result;
}

original_code:
Boolean
check_for_only_checkmate(const Move *moves)
{
    if(GlobalState.match_only_checkmate) {
        while(moves != ((void *)0) && moves->check_status != CHECKMATE) {
            moves = moves->next;
        }
        if(moves == ((void *)0)) {
            return FALSE;
        }
        else {
            return TRUE;
        }
    }
    else {
        return TRUE;
    }
}

canonical_original_code:
enum Boolean check_for_only_checkmate(struct move *moves)
{
    if(GlobalState.match_only_checkmate) {
        while(moves != ((void *)0) && moves->check_status != CHECKMATE) {
            moves = moves->next;
        }
        if(moves == ((void *)0)) {
            return FALSE;
        }
        else {
            return TRUE;
        }
    }
    else {
        return TRUE;
    }
}


decompiled_code:
_BOOL8 __fastcall check_for_only_stalemate(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rdx
__int64 v5; // rax
_BOOL8 result; // rax

v4 = (unsigned int)GlobalState[20];
if ( !(_DWORD)v4 || !a2 )
return 1LL;
do
{
v5 = a2;
a2 = *(_QWORD *)(a2 + 88);
}
while ( a2 );
if ( *(_DWORD *)(v5 + 36) )
result = 0LL;
else
result = find_all_moves(a1, *(unsigned int *)(a1 + 576), v4, a4, 0LL) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // rdx
__int64 v5; // rax
_BOOL8 result; // rax

v4 = (unsigned int)GlobalState[20];
if ( !(_DWORD)v4 || !a2 )
return 1LL;
do
{
v5 = a2;
a2 = *(_QWORD *)(a2 + 88);
}
while ( a2 );
if ( *(_DWORD *)(v5 + 36) )
result = 0LL;
else
result = find_all_moves(a1, *(unsigned int *)(a1 + 576), v4, a4, 0LL) == 0;
return result;
}

original_code:
Boolean
check_for_only_stalemate(const Board *board, const Move *moves)
{
    if(GlobalState.match_only_stalemate) {
        const Move *move = moves;
        if(move != ((void *)0)) {
            MovePair *available_moves;
            while(move->next != ((void *)0)) {
                move = move->next;
            }
            if(move->check_status != NOCHECK) {
                return FALSE;
            }
            available_moves = find_all_moves(board, board->to_move);
            if(available_moves == ((void *)0)) {
                return TRUE;
            }
            else {
                return FALSE;
            }
        }
        else {
            return TRUE;
        }
    }
    else {
        return TRUE;
    }
}

canonical_original_code:
enum Boolean check_for_only_stalemate(struct Board *board, struct move *moves)
{
    if(GlobalState.match_only_stalemate) {
        struct move *move = moves;
        if(move != ((void *)0)) {
            struct move_pair *available_moves;
            while(move->next != ((void *)0)) {
                move = move->next;
            }
            if(move->check_status != NOCHECK) {
                return FALSE;
            }
            available_moves = find_all_moves(board, board->to_move);
            if(available_moves == ((void *)0)) {
                return TRUE;
            }
            else {
                return FALSE;
            }
        }
        else {
            return TRUE;
        }
    }
    else {
        return TRUE;
    }
}

variable_types: struct Board { enum Piece { OFF=0, EMPTY=1, PAWN=2, KNIGHT=3, BISHOP=4, ROOK=5, QUEEN=6, KING=7, NUM_PIECE_VALUES=8 } board[-1][-1]; enum Colour { BLACK=0, WHITE=1 } to_move; unsigned int move_number; enum Boolean { FALSE=0, TRUE=1 } WKingCastle; enum Boolean { FALSE=0, TRUE=1 } BKingCastle; char WKingCol; char WKingRank; char BKingCol; char BKingRank; enum Boolean { FALSE=0, TRUE=1 } EnPassant; char ep_rank; char ep_col; unsigned long hash_value; unsigned int halfmove_clock; } *

variable_types: struct move_pair { char from_col; char from_rank; char to_col; char to_rank; struct move_pair *next; } *

user_defined_types: struct Board { enum Piece board[-1][-1]; enum Colour to_move; unsigned int move_number; enum Boolean WKingCastle; enum Boolean BKingCastle; char WKingCol; char WKingRank; char BKingCol; char BKingRank; enum Boolean EnPassant; char ep_rank; char ep_col; unsigned long hash_value; unsigned int halfmove_clock; }


decompiled_code:
_BOOL8 __fastcall check_textual_variations(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, char *needle)
{
_BOOL8 result; // rax
__int64 v13; // rbx

result = 1LL;
v13 = games_to_keep;
if ( games_to_keep )
{
do
{
if ( GlobalState[6] )
{
result = permutation_match(
needle,
a2,
a3,
a4,
a5,
a6,
*(_QWORD *)v13,
*(_QWORD *)(v13 + 8),
*(_QWORD *)(v13 + 16),
*(_QWORD *)(v13 + 24));
v13 = *(_QWORD *)(v13 + 32);
if ( !v13 )
return result;
}
else
{
a2 = *(_QWORD *)v13;
result = straight_match_isra_0(needle, *(_QWORD *)v13, *(_DWORD *)(v13 + 24));
v13 = *(_QWORD *)(v13 + 32);
if ( !v13 )
return result;
}
}
while ( !result );
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10, int a11, char *needle)
{
_BOOL8 result; // rax
__int64 v13; // rbx

result = 1LL;
v13 = games_to_keep;
if ( games_to_keep )
{
do
{
if ( GlobalState[6] )
{
result = func4(
needle,
a2,
a3,
a4,
a5,
a6,
*(_QWORD *)v13,
*(_QWORD *)(v13 + 8),
*(_QWORD *)(v13 + 16),
*(_QWORD *)(v13 + 24));
v13 = *(_QWORD *)(v13 + 32);
if ( !v13 )
return result;
}
else
{
a2 = *(_QWORD *)v13;
result = func5(needle, *(_QWORD *)v13, *(_DWORD *)(v13 + 24));
v13 = *(_QWORD *)(v13 + 32);
if ( !v13 )
return result;
}
}
while ( !result );
}
return result;
}

original_code:
Boolean
check_textual_variations(Game game_details)
{ Boolean wanted = FALSE;
    variation_list *variation;
    if(games_to_keep != ((void *)0)){
        for(variation = games_to_keep; (variation != ((void *)0)) && !wanted;
                    variation = variation->next){
            if(GlobalState.match_permutations){
                wanted = permutation_match(game_details.moves,*variation);
            }
            else{
                wanted = straight_match(game_details.moves,*variation);
            }
        }
    }
    else{
        wanted = TRUE;
    }
    return wanted;
}

canonical_original_code:
enum Boolean check_textual_variations(struct Game game_details)
{ enum Boolean wanted = FALSE;
    struct variation_list *variation;
    if(games_to_keep != ((void *)0)){
        for(variation = games_to_keep; (variation != ((void *)0)) && !wanted;
                    variation = variation->next){
            if(GlobalState.match_permutations){
                wanted = permutation_match(game_details.moves,*variation);
            }
            else{
                wanted = straight_match(game_details.moves,*variation);
            }
        }
    }
    else{
        wanted = TRUE;
    }
    return wanted;
}

variable_types: struct Game { char **tags; int tags_length; struct comment_list { struct string_list { char *str; struct string_list *next; } *Comment; struct comment_list *next; } *prefix_comment; unsigned long final_hash_value; unsigned long cumulative_hash_value; struct move { unsigned char move[-1]; enum MoveClass { PAWN_MOVE=0, PAWN_MOVE_WITH_PROMOTION=1, ENPASSANT_PAWN_MOVE=2, PIECE_MOVE=3, KINGSIDE_CASTLE=4, QUEENSIDE_CASTLE=5, UNKNOWN_MOVE=6 } class; char from_col; char from_rank; char to_col; char to_rank; enum Piece { OFF=0, EMPTY=1, PAWN=2, KNIGHT=3, BISHOP=4, ROOK=5, QUEEN=6, KING=7, NUM_PIECE_VALUES=8 } piece_to_move; enum Piece { OFF=0, EMPTY=1, PAWN=2, KNIGHT=3, BISHOP=4, ROOK=5, QUEEN=6, KING=7, NUM_PIECE_VALUES=8 } captured_piece; enum Piece { OFF=0, EMPTY=1, PAWN=2, KNIGHT=3, BISHOP=4, ROOK=5, QUEEN=6, KING=7, NUM_PIECE_VALUES=8 } promoted_piece; enum CheckStatus { NOCHECK=0, CHECK=1, CHECKMATE=2 } check_status; char *epd; struct string_list *Nags; struct comment_list *Comment; char *terminating_result; struct variation { struct comment_list *prefix_comment; struct move *moves; struct comment_list *suffix_comment; struct variation *next; } *Variants; struct move *prev; } *moves; enum Boolean { FALSE=0, TRUE=1 } moves_checked; enum Boolean { FALSE=0, TRUE=1 } moves_ok; }

variable_types:
wanted
enum Boolean { FALSE=0, TRUE=1 }

variable_types: struct variation_list { struct variant_move { char *move; enum Boolean { FALSE=0, TRUE=1 } matched; } *moves; unsigned int num_white_any_moves; unsigned int num_black_any_moves; unsigned int num_white_disallowed_moves; unsigned int num_black_disallowed_moves; unsigned int length; struct variation_list *next; } *

user_defined_types: struct Game { char **tags; int tags_length; struct comment_list *prefix_comment; unsigned long final_hash_value; unsigned long cumulative_hash_value; struct move *moves; enum Boolean moves_checked; enum Boolean moves_ok; }


decompiled_code:
_BOOL8 __fastcall check_move_bounds(unsigned int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( GlobalState[18] )
{
result = 0LL;
if ( GlobalState[32] <= a1 )
result = GlobalState[33] >= a1;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(unsigned int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( GlobalState[18] )
{
result = 0LL;
if ( GlobalState[32] <= a1 )
result = GlobalState[33] >= a1;
}
return result;
}

original_code:
Boolean
check_move_bounds(unsigned number_of_moves)
{ Boolean in_bounds = TRUE;
    if(GlobalState.check_move_bounds){
         in_bounds = (GlobalState.lower_move_bound <= number_of_moves) &&
                         (number_of_moves <= GlobalState.upper_move_bound);
    }
    return in_bounds;
}

canonical_original_code:
enum Boolean check_move_bounds(unsigned int number_of_moves)
{ enum Boolean in_bounds = TRUE;
    if(GlobalState.check_move_bounds){
         in_bounds = (GlobalState.lower_move_bound <= number_of_moves) &&
                         (number_of_moves <= GlobalState.upper_move_bound);
    }
    return in_bounds;
}


decompiled_code:
_BOOL8 __fastcall comment_line(_BYTE *a1)
{
return *a1 == 37;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_BYTE *a1)
{
return *a1 == 37;
}

original_code:
Boolean
comment_line(const char *line)
{
    return *line == '%';
}

canonical_original_code:
enum Boolean comment_line(char *line)
{
    return *line == '%';
}


decompiled_code:
_BOOL8 __fastcall non_blank_line(_BYTE *a1)
{
_BOOL4 v1; // er12
_BYTE *v2; // rbp
__int64 v3; // rbx
const unsigned __int16 *v4; // rax

v1 = 0;
if ( !a1 )
return v1;
v2 = a1;
v1 = comment_line(a1);
if ( !v1 )
{
v3 = (char)*a1;
if ( (_BYTE)v3 )
{
v4 = *_ctype_b_loc();
while ( (v4[v3] & 0x2000) != 0 )
{
v3 = (char)*++v2;
if ( !(_BYTE)v3 )
return v1;
}
v1 = 1;
}
return v1;
}
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_BYTE *a1)
{
_BOOL4 v1; // er12
_BYTE *v2; // rbp
__int64 v3; // rbx
const unsigned __int16 *v4; // rax

v1 = 0;
if ( !a1 )
return v1;
v2 = a1;
v1 = func1(a1);
if ( !v1 )
{
v3 = (char)*a1;
if ( (_BYTE)v3 )
{
v4 = *_ctype_b_loc();
while ( (v4[v3] & 0x2000) != 0 )
{
v3 = (char)*++v2;
if ( !(_BYTE)v3 )
return v1;
}
v1 = 1;
}
return v1;
}
return 0LL;
}

original_code:
Boolean
non_blank_line(const char *line)
{ Boolean blank = TRUE;
    if(line != ((void *)0)){
        if(comment_line(line)){
        }
        else{
            while(blank && (*line != '\0')){
                if(!((*__ctype_b_loc ())[(int) (((int) *line))] & (unsigned short int) _ISspace)){
                    blank = FALSE;
                }
                else{
                    line++;
                }
            }
        }
    }
    return !blank;
}

canonical_original_code:
enum Boolean non_blank_line(char *line)
{ enum Boolean blank = TRUE;
    if(line != ((void *)0)){
        if(comment_line(line)){
        }
        else{
            while(blank && (*line != '\0')){
                if(!((*__ctype_b_loc ())[(int) (((int) *line))] & (unsigned short) _ISspace)){
                    blank = FALSE;
                }
                else{
                    line++;
                }
            }
        }
    }
    return !blank;
}

variable_types:
blank
enum Boolean { FALSE=0, TRUE=1 }


decompiled_code:
_BOOL8 __fastcall blank_line(_BYTE *a1)
{
return !non_blank_line(a1);
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_BYTE *a1)
{
return !func2(a1);
}

original_code:
Boolean
blank_line(const char *line)
{
    return !non_blank_line(line);
}

canonical_original_code:
enum Boolean blank_line(char *line)
{
    return !non_blank_line(line);
}


decompiled_code:
__int64 __fastcall retrieve_virtual_entry(__int64 off, void *ptr)
{
unsigned int v2; // er12
__int64 result; // rax

v2 = 0;
if ( !hash_file )
return v2;
v2 = fseek(hash_file, off, 0);
if ( v2 )
{
fprintf(*((FILE **)&GlobalState + 23), "Fseek error to %ld in retrieve_virtual_entry\n", off);
result = 0LL;
}
else
{
if ( fread(ptr, 0x20uLL, 1uLL, hash_file) != 1 )
{
fprintf(*((FILE **)&GlobalState + 23), "Fread error from %ld in retrieve_virtual_entry\n", off);
return v2;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 off, void *ptr)
{
unsigned int v2; // er12
__int64 result; // rax

v2 = 0;
if ( !hash_file )
return v2;
v2 = fseek(hash_file, off, 0);
if ( v2 )
{
fprintf(*((FILE **)&GlobalState + 23), "Fseek error to %ld in retrieve_virtual_entry\n", off);
result = 0LL;
}
else
{
if ( fread(ptr, 0x20uLL, 1uLL, hash_file) != 1 )
{
fprintf(*((FILE **)&GlobalState + 23), "Fread error from %ld in retrieve_virtual_entry\n", off);
return v2;
}
result = 1LL;
}
return result;
}

original_code:
static int
retrieve_virtual_entry(long ix,VirtualHashLog *entry)
{
    if(hash_file == ((void *)0)){
        return 0;
    }
    else if(fseek(hash_file,ix,0) != 0){
        fprintf(GlobalState.logfile,
                        "Fseek error to %ld in retrieve_virtual_entry\n",ix);
        return 0;
    }
    else if(fread((void *)entry,sizeof(*entry),1,hash_file) != 1){
        fprintf(GlobalState.logfile,
                        "Fread error from %ld in retrieve_virtual_entry\n",ix);
        return 0;
    }
    else{
        return 1;
    }
}

canonical_original_code:
static int retrieve_virtual_entry(long ix, struct VirtualHashLog *entry)
{
    if(hash_file == ((void *)0)){
        return 0;
    }
    else if(fseek(hash_file,ix,0) != 0){
        fprintf(GlobalState.logfile,
                        "Fseek error to %ld in retrieve_virtual_entry\n",ix);
        return 0;
    }
    else if(fread((void *)entry,sizeof(*entry),1,hash_file) != 1){
        fprintf(GlobalState.logfile,
                        "Fread error from %ld in retrieve_virtual_entry\n",ix);
        return 0;
    }
    else{
        return 1;
    }
}

variable_types: ix long

variable_types: struct VirtualHashLog { unsigned long final_hash_value; int file_number; long next; } *


decompiled_code:
__int64 __fastcall write_virtual_entry(__int64 off, void *ptr)
{
__int64 result; // rax

if ( fseek(hash_file, off, 0) )
{
fprintf(*((FILE **)&GlobalState + 23), "Fseek error to %ld in write_virtual_entry\n", off);
result = 0LL;
}
else if ( fwrite(ptr, 0x20uLL, 1uLL, hash_file) == 1 )
{
result = 1LL;
}
else
{
fprintf(*((FILE **)&GlobalState + 23), "Fwrite error from %ld in write_virtual_entry\n", off);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 off, void *ptr)
{
__int64 result; // rax

if ( fseek(hash_file, off, 0) )
{
fprintf(*((FILE **)&GlobalState + 23), "Fseek error to %ld in write_virtual_entry\n", off);
result = 0LL;
}
else if ( fwrite(ptr, 0x20uLL, 1uLL, hash_file) == 1 )
{
result = 1LL;
}
else
{
fprintf(*((FILE **)&GlobalState + 23), "Fwrite error from %ld in write_virtual_entry\n", off);
result = 0LL;
}
return result;
}

original_code:
static int
write_virtual_entry(long where,const VirtualHashLog *entry)
{
    if(fseek(hash_file,where,0) != 0){
        fprintf(GlobalState.logfile,
                "Fseek error to %ld in write_virtual_entry\n",where);
        return 0;
    }
    else if(fwrite((void *)entry,sizeof(*entry),1,hash_file) != 1){
        fprintf(GlobalState.logfile,
                "Fwrite error from %ld in write_virtual_entry\n",where);
        return 0;
    }
    else{
        return 1;
    }
}

canonical_original_code:
static int write_virtual_entry(long where, struct VirtualHashLog *entry)
{
    if(fseek(hash_file,where,0) != 0){
        fprintf(GlobalState.logfile,
                "Fseek error to %ld in write_virtual_entry\n",where);
        return 0;
    }
    else if(fwrite((void *)entry,sizeof(*entry),1,hash_file) != 1){
        fprintf(GlobalState.logfile,
                "Fwrite error from %ld in write_virtual_entry\n",where);
        return 0;
    }
    else{
        return 1;
    }
}

variable_types: where long

user_defined_types: struct VirtualHashLog { unsigned long final_hash_value; int file_number; long next; }


decompiled_code:
int init_duplicate_hash_table()
{
__int64 v0; // rax
__int64 v1; // rdx
FILE *v2; // rax

if ( HIDWORD(GlobalState[8]) )
{
v0 = MallocOrDie(131056LL);
VirtualLogTable = v0;
v1 = v0 + 131056;
do
{
*(_QWORD *)(v0 + 8) = -1LL;
v0 += 16LL;
*(_QWORD *)(v0 - 16) = -1LL;
}
while ( v1 != v0 );
v2 = fopen(VIRTUAL_FILE, "w+b");
hash_file = v2;
if ( !v2 )
LODWORD(v2) = fprintf((FILE *)GlobalState[23], "Unable to open %s\n", VIRTUAL_FILE);
}
else
{
LogTable = MallocOrDie(65528LL);
LODWORD(v2) = (unsigned int)memset((void *)LogTable, 0, 0xFFF8uLL);
}
return (int)v2;
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rax
__int64 v1; // rdx
FILE *v2; // rax

if ( HIDWORD(GlobalState[8]) )
{
v0 = MallocOrDie(131056LL);
VirtualLogTable = v0;
v1 = v0 + 131056;
do
{
*(_QWORD *)(v0 + 8) = -1LL;
v0 += 16LL;
*(_QWORD *)(v0 - 16) = -1LL;
}
while ( v1 != v0 );
v2 = fopen(VIRTUAL_FILE, "w+b");
hash_file = v2;
if ( !v2 )
LODWORD(v2) = fprintf((FILE *)GlobalState[23], "Unable to open %s\n", VIRTUAL_FILE);
}
else
{
LogTable = MallocOrDie(65528LL);
LODWORD(v2) = (unsigned int)memset((void *)LogTable, 0, 0xFFF8uLL);
}
return (int)v2;
}

original_code:
void
init_duplicate_hash_table(void)
{ int i;
   if(GlobalState.use_virtual_hash_table){
       VirtualLogTable = (LogHeaderEntry *)
            MallocOrDie(8191*sizeof(*VirtualLogTable));
       for(i = 0; i < 8191; i++){
           VirtualLogTable[i].head = VirtualLogTable[i].tail = -1;
       }
       hash_file = fopen(VIRTUAL_FILE,"w+b");
       if(hash_file == ((void *)0)){
           fprintf(GlobalState.logfile,"Unable to open %s\n",
                    VIRTUAL_FILE);
       }
    }
    else{
       LogTable = (HashLog**) MallocOrDie(8191*sizeof(*LogTable));
       for(i = 0; i < 8191; i++){
           LogTable[i] = ((void *)0);
       }
    }
}

canonical_original_code:
void init_duplicate_hash_table()
{ int i;
   if(GlobalState.use_virtual_hash_table){
       VirtualLogTable = (struct LogHeaderEntry *)
            MallocOrDie(8191*sizeof(*VirtualLogTable));
       for(i = 0; i < 8191; i++){
           VirtualLogTable[i].head = VirtualLogTable[i].tail = -1;
       }
       hash_file = fopen(VIRTUAL_FILE,"w+b");
       if(hash_file == ((void *)0)){
           fprintf(GlobalState.logfile,"Unable to open %s\n",
                    VIRTUAL_FILE);
       }
    }
    else{
       LogTable = (struct HashLog **) MallocOrDie(8191*sizeof(*LogTable));
       for(i = 0; i < 8191; i++){
           LogTable[i] = ((void *)0);
       }
    }
}

variable_types: i int

user_defined_types: struct HashLog { unsigned long combined_hash_value; int file_number; struct HashLog *next; }