deplacement

decompiled_code:
__int64 __fastcall deplacement(__int64 a1, int **a2, char a3, unsigned int a4)
{
int v6; // eax
unsigned int v7; // er14
int *v9; // r15
int v10; // eax
int *v11; // rax
int *v12; // r15
char v13; // al
_QWORD *v14; // r14
unsigned int *v15; // r14
int *v16; // r15
_DWORD *v17; // rax
_QWORD *v18; // r15
int *v19; // rax
int *v20; // r14
char v21; // al
int *v22; // rax
int v23; // er15
_QWORD *v24; // r15
_DWORD *v25; // rax
_QWORD *v26; // rcx
int *v27; // r15
void *v28; // r14
int *v29; // rax
_QWORD *v30; // r15
int *v31; // rax
int *v32; // rax
int *v33; // r14
char v34; // al
int *v35; // rax
int *v36; // r15
char v37; // al
int *v38; // rax
int *v39; // rax
int *v40; // rax
int *v41; // rax
int *v42; // rax
_DWORD *v43; // [rsp+0h] [rbp-58h]
int v44; // [rsp+0h] [rbp-58h]
int v45; // [rsp+0h] [rbp-58h]
int v46; // [rsp+8h] [rbp-50h]
_QWORD *v47; // [rsp+8h] [rbp-50h]
int v48; // [rsp+8h] [rbp-50h]
unsigned int *v49; // [rsp+10h] [rbp-48h]
_DWORD *v50; // [rsp+10h] [rbp-48h]
_QWORD *v51; // [rsp+10h] [rbp-48h]
_DWORD *v52; // [rsp+18h] [rbp-40h]
_DWORD *v53; // [rsp+18h] [rbp-40h]

v6 = nbBouleDeplace(a1, (__int64)a2);
if ( v6 != 2 )
{
if ( v6 != 3 )
{
v7 = -1;
if ( v6 != 1 )
return v7;
v9 = a2[1];
v10 = direction(v9, (unsigned int *)a2[2]);
v7 = v10;
if ( v10 != -1 )
{
v11 = caseSuivant(a1, v9, v10);
v12 = v11;
if ( v11 )
{
v13 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *v11) + v11[1]);
if ( v13 == 46 )
{
if ( a4 == 1 )
addToList(a2);
else
deplaceBoule((_QWORD *)a1, a2[1], v12);
v7 = 0;
}
else if ( v13 == a3 )
{
v14 = malloc(0x20uLL);
v43 = malloc(4uLL);
*v14 = v43;
v14[1] = malloc(8uLL);
v14[2] = malloc(8uLL);
v14[3] = malloc(8uLL);
*v43 = **a2 + 1;
v14[1] = a2[1];
v14[2] = v12;
v14[3] = a2[2];
deplacement(a1, v14, (unsigned int)a3, a4);
free(v14);
v7 = 0;
}
else
{
v7 = -1;
if ( a4 != 1 )
puts(s);
}
}
else
{
v7 = -1;
if ( a4 != 1 )
puts(aCaseArriv);
}
return v7;
}
if ( a4 == 1 )
return v7;
LABEL_19:
puts("Deplacement impssible cases non adjacente");
return v7;
}
v23 = direction(a2[1], (unsigned int *)a2[3]);
v45 = v23;
v48 = directionTroisBoules((__int64)a2, a1);
if ( v48 == -1 || v23 == -1 )
{
v7 = -1;
if ( a4 != 1 )
puts(aDeplacementImp_0);
return v7;
}
if ( v23 != v48 )
{
v24 = malloc(0x18uLL);
v25 = malloc(4uLL);
v26 = v24;
*v24 = v25;
*v25 = 2;
v27 = a2[1];
v26[1] = v27;
v51 = v26;
v26[2] = a2[3];
v28 = malloc(0x18uLL);
v52 = malloc(4uLL);
*(_QWORD *)v28 = v52;
*((_QWORD *)v28 + 1) = malloc(8uLL);
*((_QWORD *)v28 + 2) = malloc(8uLL);
*v52 = 2;
v29 = caseSuivant(a1, v27, v48);
*((_QWORD *)v28 + 1) = v29;
*((_QWORD *)v28 + 2) = caseSuivant(a1, v29, v45);
v30 = malloc(0x18uLL);
v53 = malloc(4uLL);
*v30 = v53;
v30[1] = malloc(8uLL);
v30[2] = malloc(8uLL);
*v53 = 2;
v31 = caseSuivant(a1, *((int **)v28 + 1), v48);
v30[1] = v31;
v30[2] = caseSuivant(a1, v31, v45);
deplacement(a1, v30, (unsigned int)a3, a4);
deplacement(a1, v28, (unsigned int)a3, a4);
deplacement(a1, v51, (unsigned int)a3, a4);
free(a2);
return 0;
}
v32 = caseSuivant(a1, a2[2], v23);
v33 = v32;
if ( v32 )
{
v34 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *v32) + v32[1]);
if ( v34 == 46 )
{
if ( a4 == 1 )
{
addToList(a2);
}
else
{
deplaceBoule((_QWORD *)a1, a2[2], v33);
v40 = caseSuivant(a1, a2[1], v23);
deplaceBoule((_QWORD *)a1, v40, a2[2]);
deplaceBoule((_QWORD *)a1, a2[1], a2[3]);
}
return 0;
}
if ( v34 == a3 )
{
v7 = -1;
if ( a4 != 1 )
puts("Case suivante est de la meme couleur deplacment 3 boules max");
return v7;
}
v35 = caseSuivant(a1, v33, v23);
v36 = v35;
if ( v35 )
{
v37 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *v35) + v35[1]);
if ( v37 == 46 )
{
if ( a4 == 1 )
{
addToList(a2);
}
else
{
deplaceBoule((_QWORD *)a1, v33, v36);
deplaceBoule((_QWORD *)a1, a2[2], v33);
v41 = caseSuivant(a1, a2[1], v45);
deplaceBoule((_QWORD *)a1, v41, a2[2]);
deplaceBoule((_QWORD *)a1, a2[1], a2[3]);
}
return 0;
}
if ( v37 != a3 )
{
v38 = caseSuivant(a1, v36, v45);
if ( v38 )
{
if ( *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *v38) + v38[1]) == 46 )
{
if ( a4 == 1 )
{
addToList(a2);
}
else
{
deplaceBoule((_QWORD *)a1, v36, v38);
deplaceBoule((_QWORD *)a1, v33, v36);
deplaceBoule((_QWORD *)a1, a2[2], v33);
v39 = caseSuivant(a1, a2[1], v45);
deplaceBoule((_QWORD *)a1, v39, a2[2]);
deplaceBoule((_QWORD *)a1, a2[1], a2[3]);
}
v7 = 0;
}
else
{
v7 = -1;
if ( a4 != 1 )
puts("Case apres 2 billes adverse non vide deplacement 3 boules ");
}
return v7;
}
if ( a4 != 1 )
{
deplaceBoule((_QWORD *)a1, v33, v36);
deplaceBoule((_QWORD *)a1, a2[2], v33);
v42 = caseSuivant(a1, a2[1], v45);
deplaceBoule((_QWORD *)a1, v42, a2[2]);
deplaceBoule((_QWORD *)a1, a2[1], a2[3]);
if ( a3 == 66 )
++*(_DWORD *)(a1 + 12);
else
++*(_DWORD *)(a1 + 8);
return 0;
}
LABEL_46:
addToList(a2);
return 0;
}
v7 = -1;
if ( a4 != 1 )
puts("Case apres la bille adverse non vide deplacement 3 boules ");
return v7;
}
v7 = -1;
if ( a4 == 1 )
return v7;
}
else
{
v7 = -1;
if ( a4 == 1 )
return v7;
}
puts(aCaseArriv_1);
return v7;
}
v15 = (unsigned int *)a2[2];
v16 = a2[1];
v46 = direction(v16, v15);
v49 = (unsigned int *)a2[3];
v44 = direction(v16, v49);
if ( v44 == -1 || v46 == -1 )
{
v7 = -1;
if ( a4 == 1 )
return v7;
goto LABEL_19;
}
if ( *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * (int)*v15) + (int)v15[1]) == a3 )
{
if ( v46 != v44 )
{
v47 = malloc(0x18uLL);
v17 = malloc(4uLL);
*v47 = v17;
*v17 = 2;
v47[1] = v16;
v47[2] = v49;
v18 = malloc(0x18uLL);
v50 = malloc(4uLL);
*v18 = v50;
v18[2] = malloc(8uLL);
*v50 = 2;
v18[1] = v15;
v18[2] = caseSuivant(a1, (int *)v15, v44);
deplacement(a1, v47, (unsigned int)a3, a4);
deplacement(a1, v18, (unsigned int)a3, a4);
free(a2);
return 0;
}
v19 = caseSuivant(a1, (int *)v15, v44);
v20 = v19;
if ( v19 )
{
v21 = *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *v19) + v19[1]);
if ( v21 == 46 )
{
if ( a4 == 1 )
{
addToList(a2);
}
else
{
deplaceBoule((_QWORD *)a1, a2[2], v20);
deplaceBoule((_QWORD *)a1, a2[1], a2[2]);
}
return 0;
}
if ( v21 == a3 )
{
a2[2] = v20;
deplacement(a1, a2, (unsigned int)a3, a4);
return 0;
}
v22 = caseSuivant(a1, v20, v44);
if ( !v22 )
{
if ( a4 != 1 )
{
deplaceBoule((_QWORD *)a1, a2[2], v20);
deplaceBoule((_QWORD *)a1, a2[1], a2[2]);
if ( a3 == 66 )
++*(_DWORD *)(a1 + 12);
else
++*(_DWORD *)(a1 + 8);
return 0;
}
goto LABEL_46;
}
if ( *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * *v22) + v22[1]) == 46 )
{
if ( a4 == 1 )
{
addToList(a2);
}
else
{
deplaceBoule((_QWORD *)a1, v20, v22);
deplaceBoule((_QWORD *)a1, a2[2], v20);
deplaceBoule((_QWORD *)a1, a2[1], a2[2]);
}
v7 = 0;
}
else
{
v7 = -1;
if ( a4 != 1 )
puts("Case apres la bille adverse non vide deplacement 2 boules ");
}
}
else
{
v7 = -1;
if ( a4 != 1 )
puts(aCaseArriv_0);
}
}
else
{
v7 = -1;
if ( a4 != 1 )
puts(aLes2Boules);
}
return v7;
}

original_code:
int deplacement(Plateau *p, int **coor,char couleur, int list){
 int *caseSuivDir;
 int dirBoule, dirDep;
 switch(nbBouleDeplace(p,coor)){
  case 1:
   dirDep = direction(coor[1],coor[2]);
   if(dirDep!=-1){
     caseSuivDir = caseSuivant(p,coor[1], dirDep);
    if(caseSuivDir != ((void *)0)){
     if(p->tableau[caseSuivDir[0]][caseSuivDir[1]] == '.'){
      if (list==1){
       addToList(coor);
      }
      else {
       deplaceBoule(p,coor[1], caseSuivDir);
      }
      return 0;
     }
     else if (p->tableau[caseSuivDir[0]][caseSuivDir[1]] == couleur){
      int ** coordonnee = malloc( sizeof(int *) * 4);
      coordonnee[0] = malloc(sizeof(int) * 1);
      coordonnee[1] = malloc( sizeof(int) * 2);
      coordonnee[2] = malloc( sizeof(int) * 2);
      coordonnee[3] = malloc( sizeof(int) * 2);
      coordonnee[0][0] = coor[0][0]+1;
      coordonnee[1] = coor[1];
      coordonnee[2] = caseSuivDir;
      coordonnee[3] = coor[2];
      deplacement(p,coordonnee,couleur,list);
      free(coordonnee);
     }
     else {
      if (list==1){
      }
      else {
       printf("case arrivé NON VIDE boule adverse (deplace 1 boule)\n");
      }
      return -1;
     }
    }else {
     if (list==1){
     }
     else {
      printf("case arrivé NULL(en dehors du plateau) (deplace 1 boule)\n");
     }
     return -1;
    }
   }else{
    if (list==1){
    }
    else {
     printf("Deplacement impssible cases non adjacente\n");
    }
    return -1;
   }
   break;
  case 2:
   dirBoule = direction(coor[1],coor[2]);
   dirDep = direction(coor[1],coor[3]);
   if (dirDep != -1 && dirBoule!=-1){
    if(couleur != p->tableau[coor[2][0]][coor[2][1]]){
     if (list==1){
     }
     else {
      printf("Les 2 boules à deplacer ne sont pas de la meme couleur\n");
     }
     return -1;
    }
    if (dirDep == dirBoule){
     caseSuivDir = caseSuivant(p,coor[2], dirDep);
     if(caseSuivDir != ((void *)0)){
      if(p->tableau[caseSuivDir[0]][caseSuivDir[1]] == '.'){
       if (list==1){
        addToList(coor);
       }
       else {
        deplaceBoule(p,coor[2], caseSuivDir);
        deplaceBoule(p,coor[1], coor[2]);
       }
      }
      else if (couleur != p->tableau[caseSuivDir[0]][caseSuivDir[1]]){
       int * caseADeplacerD = caseSuivant(p,caseSuivDir, dirDep);
       if (caseADeplacerD != ((void *)0)){
        if(p->tableau[caseADeplacerD[0]][caseADeplacerD[1]] == '.'){
         if (list==1){
          addToList(coor);
         }
         else {
          deplaceBoule(p,caseSuivDir, caseADeplacerD);
          deplaceBoule(p,coor[2], caseSuivDir);
          deplaceBoule(p,coor[1], coor[2]);
         }
        }
        else {
         if (list==1){
         }
         else {
          printf("Case apres la bille adverse non vide deplacement 2 boules \n");
         }
         return -1;
        }
       }
       else{
        if (list==1){
         addToList(coor);
        }
        else {
         deplaceBoule(p,coor[2], caseSuivDir);
         deplaceBoule(p,coor[1], coor[2]);
         if (couleur == 'B'){
          p->billesNoiresperdues++;
         }else{
          p->billesBlachesperdues++;
         }
        }
       }
      }
      else {
       coor[2] = caseSuivDir;
       deplacement(p,coor,couleur,list);
      }
     }else {
      if (list==1){
      }
      else {
       printf("case arrivé NULL(en dehors du plateau) (deplace 2 boule)\n");
      }return -1;
     }
    }
    else{
     int ** boule1, **boule2;
     boule1 = malloc( sizeof(int *) * 3);
     boule1[0] = malloc( sizeof(int) * 1);
     boule1[1] = malloc( sizeof(int) * 2);
     boule1[2] = malloc( sizeof(int) * 2);
     boule1[0][0] = 2;
     boule1[1] = coor[1];
     boule1[2] = coor[3];
     boule2 = malloc( sizeof(int *) * 3);
     boule2[0] = malloc( sizeof(int) * 1);
     boule2[1] = malloc( sizeof(int) * 2);
     boule2[2] = malloc( sizeof(int) * 2);
     boule2[0][0] = 2;
     boule2[1] = coor[2];
     boule2[2] = caseSuivant(p,coor[2], dirDep);
     deplacement(p,boule1,couleur,list );
     deplacement(p,boule2,couleur,list );
     free(coor);
    }
   }else {
    if (list==1){
      }
      else {
       printf("Deplacement impssible cases non adjacente\n");}
    return -1;
   }
   break;
  case 3:
   dirDep = direction(coor[1],coor[3]);
   dirBoule = directionTroisBoules(coor,p);
   if (dirBoule == -1 || dirDep == -1){
    if (list==1){
      }
      else {
       printf("Deplacement impssible cases non adjacente ou boules trop eloigné\n");}
    return -1;
   }
   else if (dirDep == dirBoule){
    caseSuivDir = caseSuivant(p,coor[2], dirDep);
    if(caseSuivDir != ((void *)0)){
     if(p->tableau[caseSuivDir[0]][caseSuivDir[1]] == '.'){
       if (list==1){
        addToList(coor);
       }
       else {
        deplaceBoule(p,coor[2], caseSuivDir);
        caseSuivDir = caseSuivant(p,coor[1], dirDep);
        deplaceBoule(p,caseSuivDir, coor[2]);
        deplaceBoule(p,coor[1], coor[3]);
       }
     }
     else if (p->tableau[caseSuivDir[0]][caseSuivDir[1]] == couleur){
      if (list==1){
      }
      else {
       printf("Case suivante est de la meme couleur deplacment 3 boules max\n");}
      return -1;
     }
     else {
      int *caseSuivDir2 = caseSuivant(p,caseSuivDir, dirDep);
      if(caseSuivDir2 != ((void *)0)){
       if(p->tableau[caseSuivDir2[0]][caseSuivDir2[1]] == '.'){
        if (list==1){
         addToList(coor);
        }
        else {
         deplaceBoule(p,caseSuivDir, caseSuivDir2);
         deplaceBoule(p,coor[2], caseSuivDir);
         caseSuivDir = caseSuivant(p,coor[1], dirDep);
         deplaceBoule(p,caseSuivDir, coor[2]);
         deplaceBoule(p,coor[1], coor[3]);
        }
       }
       else if(p->tableau[caseSuivDir2[0]][caseSuivDir2[1]] == couleur){
        if (list==1){
        }
        else {
         printf("Case apres la bille adverse non vide deplacement 3 boules \n");}
        return -1;
       }
       else {
        int *caseSuivDir3 = caseSuivant(p,caseSuivDir2, dirDep);
        if(caseSuivDir3 != ((void *)0)){
         if(p->tableau[caseSuivDir3[0]][caseSuivDir3[1]] == '.'){
          if (list==1){
           addToList(coor);
          }
          else {
           deplaceBoule(p,caseSuivDir2, caseSuivDir3);
           deplaceBoule(p,caseSuivDir, caseSuivDir2);
           deplaceBoule(p,coor[2], caseSuivDir);
           caseSuivDir = caseSuivant(p,coor[1], dirDep);
           deplaceBoule(p,caseSuivDir, coor[2]);
           deplaceBoule(p,coor[1], coor[3]);
          }
         }
         else {
          if (list==1){
          }
          else {
           printf("Case apres 2 billes adverse non vide deplacement 3 boules \n"); }
          return -1;
         }
        }
        else {
         if (list==1){
          addToList(coor);
         }
         else {
          deplaceBoule(p,caseSuivDir, caseSuivDir2);
          deplaceBoule(p,coor[2], caseSuivDir);
          caseSuivDir = caseSuivant(p,coor[1], dirDep);
          deplaceBoule(p,caseSuivDir, coor[2]);
          deplaceBoule(p,coor[1], coor[3]);
          if (couleur == 'B'){
           p->billesNoiresperdues++;
          }else{
           p->billesBlachesperdues++;
          }
         }
        }
       }
      }
      else {
       if (list==1){
      }
      else {
       printf("case arrivé NULL(en dehors du plateau) (deplace 3 boule)\n");}
       return -1;
      }
     }
    }
    else {
     if (list==1){
      }
      else {
       printf("case arrivé NULL(en dehors du plateau) (deplace 3 boule)\n");}
     return -1;
    }
   }
   else{
    int ** boule1, **boule2, **boule3;
    boule1 = malloc( sizeof(int *) * 3);
    boule1[0] = malloc( sizeof(int) * 1);
    boule1[1] = malloc( sizeof(int) * 2);
    boule1[2] = malloc( sizeof(int) * 2);
    boule1[0][0] = 2;
    boule1[1] = coor[1];
    boule1[2] = coor[3];
    boule2 = malloc( sizeof(int *) * 3);
    boule2[0] = malloc( sizeof(int) * 1);
    boule2[1] = malloc( sizeof(int) * 2);
    boule2[2] = malloc( sizeof(int) * 2);
    boule2[0][0] = 2;
    boule2[1] = caseSuivant(p,coor[1], dirBoule);
    boule2[2] = caseSuivant(p,boule2[1], dirDep);
    boule3 = malloc( sizeof(int *) * 3);
    boule3[0] = malloc( sizeof(int) * 1);
    boule3[1] = malloc( sizeof(int) * 2);
    boule3[2] = malloc( sizeof(int) * 2);
    boule3[0][0] = 2;
    boule3[1] = caseSuivant(p,boule2[1], dirBoule);
    boule3[2] = caseSuivant(p,boule3[1], dirDep);
    deplacement(p,boule3,couleur, list);
    deplacement(p,boule2,couleur,list);
    deplacement(p,boule1,couleur,list);
    free(coor);
   }
   break;
  default :
   return -1;
   break;
 }
 return 0;
}

canonical_original_code:
int deplacement(struct Plateau *p, int **coor, char couleur, int list){
 int *caseSuivDir;
 int dirBoule; int dirDep;
 switch(nbBouleDeplace(p,coor)){
  case 1:
   dirDep = direction(coor[1],coor[2]);
   if(dirDep!=-1){
     caseSuivDir = caseSuivant(p,coor[1], dirDep);
    if(caseSuivDir != ((void *)0)){
     if(p->tableau[caseSuivDir[0]][caseSuivDir[1]] == '.'){
      if (list==1){
       addToList(coor);
      }
      else {
       deplaceBoule(p,coor[1], caseSuivDir);
      }
      return 0;
     }
     else if (p->tableau[caseSuivDir[0]][caseSuivDir[1]] == couleur){
      int **coordonnee = malloc( sizeof(int *) * 4);
      coordonnee[0] = malloc(sizeof(int) * 1);
      coordonnee[1] = malloc( sizeof(int) * 2);
      coordonnee[2] = malloc( sizeof(int) * 2);
      coordonnee[3] = malloc( sizeof(int) * 2);
      coordonnee[0][0] = coor[0][0]+1;
      coordonnee[1] = coor[1];
      coordonnee[2] = caseSuivDir;
      coordonnee[3] = coor[2];
      deplacement(p,coordonnee,couleur,list);
      free(coordonnee);
     }
     else {
      if (list==1){
      }
      else {
       printf("case arrivé NON VIDE boule adverse (deplace 1 boule)\n");
      }
      return -1;
     }
    }else {
     if (list==1){
     }
     else {
      printf("case arrivé NULL(en dehors du plateau) (deplace 1 boule)\n");
     }
     return -1;
    }
   }else{
    if (list==1){
    }
    else {
     printf("Deplacement impssible cases non adjacente\n");
    }
    return -1;
   }
   break;
  case 2:
   dirBoule = direction(coor[1],coor[2]);
   dirDep = direction(coor[1],coor[3]);
   if (dirDep != -1 && dirBoule!=-1){
    if(couleur != p->tableau[coor[2][0]][coor[2][1]]){
     if (list==1){
     }
     else {
      printf("Les 2 boules à deplacer ne sont pas de la meme couleur\n");
     }
     return -1;
    }
    if (dirDep == dirBoule){
     caseSuivDir = caseSuivant(p,coor[2], dirDep);
     if(caseSuivDir != ((void *)0)){
      if(p->tableau[caseSuivDir[0]][caseSuivDir[1]] == '.'){
       if (list==1){
        addToList(coor);
       }
       else {
        deplaceBoule(p,coor[2], caseSuivDir);
        deplaceBoule(p,coor[1], coor[2]);
       }
      }
      else if (couleur != p->tableau[caseSuivDir[0]][caseSuivDir[1]]){
       int *caseADeplacerD = caseSuivant(p,caseSuivDir, dirDep);
       if (caseADeplacerD != ((void *)0)){
        if(p->tableau[caseADeplacerD[0]][caseADeplacerD[1]] == '.'){
         if (list==1){
          addToList(coor);
         }
         else {
          deplaceBoule(p,caseSuivDir, caseADeplacerD);
          deplaceBoule(p,coor[2], caseSuivDir);
          deplaceBoule(p,coor[1], coor[2]);
         }
        }
        else {
         if (list==1){
         }
         else {
          printf("Case apres la bille adverse non vide deplacement 2 boules \n");
         }
         return -1;
        }
       }
       else{
        if (list==1){
         addToList(coor);
        }
        else {
         deplaceBoule(p,coor[2], caseSuivDir);
         deplaceBoule(p,coor[1], coor[2]);
         if (couleur == 'B'){
          p->billesNoiresperdues++;
         }else{
          p->billesBlachesperdues++;
         }
        }
       }
      }
      else {
       coor[2] = caseSuivDir;
       deplacement(p,coor,couleur,list);
      }
     }else {
      if (list==1){
      }
      else {
       printf("case arrivé NULL(en dehors du plateau) (deplace 2 boule)\n");
      }return -1;
     }
    }
    else{
     int **boule1; int **boule2;
     boule1 = malloc( sizeof(int *) * 3);
     boule1[0] = malloc( sizeof(int) * 1);
     boule1[1] = malloc( sizeof(int) * 2);
     boule1[2] = malloc( sizeof(int) * 2);
     boule1[0][0] = 2;
     boule1[1] = coor[1];
     boule1[2] = coor[3];
     boule2 = malloc( sizeof(int *) * 3);
     boule2[0] = malloc( sizeof(int) * 1);
     boule2[1] = malloc( sizeof(int) * 2);
     boule2[2] = malloc( sizeof(int) * 2);
     boule2[0][0] = 2;
     boule2[1] = coor[2];
     boule2[2] = caseSuivant(p,coor[2], dirDep);
     deplacement(p,boule1,couleur,list );
     deplacement(p,boule2,couleur,list );
     free(coor);
    }
   }else {
    if (list==1){
      }
      else {
       printf("Deplacement impssible cases non adjacente\n");}
    return -1;
   }
   break;
  case 3:
   dirDep = direction(coor[1],coor[3]);
   dirBoule = directionTroisBoules(coor,p);
   if (dirBoule == -1 || dirDep == -1){
    if (list==1){
      }
      else {
       printf("Deplacement impssible cases non adjacente ou boules trop eloigné\n");}
    return -1;
   }
   else if (dirDep == dirBoule){
    caseSuivDir = caseSuivant(p,coor[2], dirDep);
    if(caseSuivDir != ((void *)0)){
     if(p->tableau[caseSuivDir[0]][caseSuivDir[1]] == '.'){
       if (list==1){
        addToList(coor);
       }
       else {
        deplaceBoule(p,coor[2], caseSuivDir);
        caseSuivDir = caseSuivant(p,coor[1], dirDep);
        deplaceBoule(p,caseSuivDir, coor[2]);
        deplaceBoule(p,coor[1], coor[3]);
       }
     }
     else if (p->tableau[caseSuivDir[0]][caseSuivDir[1]] == couleur){
      if (list==1){
      }
      else {
       printf("Case suivante est de la meme couleur deplacment 3 boules max\n");}
      return -1;
     }
     else {
      int *caseSuivDir2 = caseSuivant(p,caseSuivDir, dirDep);
      if(caseSuivDir2 != ((void *)0)){
       if(p->tableau[caseSuivDir2[0]][caseSuivDir2[1]] == '.'){
        if (list==1){
         addToList(coor);
        }
        else {
         deplaceBoule(p,caseSuivDir, caseSuivDir2);
         deplaceBoule(p,coor[2], caseSuivDir);
         caseSuivDir = caseSuivant(p,coor[1], dirDep);
         deplaceBoule(p,caseSuivDir, coor[2]);
         deplaceBoule(p,coor[1], coor[3]);
        }
       }
       else if(p->tableau[caseSuivDir2[0]][caseSuivDir2[1]] == couleur){
        if (list==1){
        }
        else {
         printf("Case apres la bille adverse non vide deplacement 3 boules \n");}
        return -1;
       }
       else {
        int *caseSuivDir3 = caseSuivant(p,caseSuivDir2, dirDep);
        if(caseSuivDir3 != ((void *)0)){
         if(p->tableau[caseSuivDir3[0]][caseSuivDir3[1]] == '.'){
          if (list==1){
           addToList(coor);
          }
          else {
           deplaceBoule(p,caseSuivDir2, caseSuivDir3);
           deplaceBoule(p,caseSuivDir, caseSuivDir2);
           deplaceBoule(p,coor[2], caseSuivDir);
           caseSuivDir = caseSuivant(p,coor[1], dirDep);
           deplaceBoule(p,caseSuivDir, coor[2]);
           deplaceBoule(p,coor[1], coor[3]);
          }
         }
         else {
          if (list==1){
          }
          else {
           printf("Case apres 2 billes adverse non vide deplacement 3 boules \n"); }
          return -1;
         }
        }
        else {
         if (list==1){
          addToList(coor);
         }
         else {
          deplaceBoule(p,caseSuivDir, caseSuivDir2);
          deplaceBoule(p,coor[2], caseSuivDir);
          caseSuivDir = caseSuivant(p,coor[1], dirDep);
          deplaceBoule(p,caseSuivDir, coor[2]);
          deplaceBoule(p,coor[1], coor[3]);
          if (couleur == 'B'){
           p->billesNoiresperdues++;
          }else{
           p->billesBlachesperdues++;
          }
         }
        }
       }
      }
      else {
       if (list==1){
      }
      else {
       printf("case arrivé NULL(en dehors du plateau) (deplace 3 boule)\n");}
       return -1;
      }
     }
    }
    else {
     if (list==1){
      }
      else {
       printf("case arrivé NULL(en dehors du plateau) (deplace 3 boule)\n");}
     return -1;
    }
   }
   else{
    int **boule1; int **boule2; int **boule3;
    boule1 = malloc( sizeof(int *) * 3);
    boule1[0] = malloc( sizeof(int) * 1);
    boule1[1] = malloc( sizeof(int) * 2);
    boule1[2] = malloc( sizeof(int) * 2);
    boule1[0][0] = 2;
    boule1[1] = coor[1];
    boule1[2] = coor[3];
    boule2 = malloc( sizeof(int *) * 3);
    boule2[0] = malloc( sizeof(int) * 1);
    boule2[1] = malloc( sizeof(int) * 2);
    boule2[2] = malloc( sizeof(int) * 2);
    boule2[0][0] = 2;
    boule2[1] = caseSuivant(p,coor[1], dirBoule);
    boule2[2] = caseSuivant(p,boule2[1], dirDep);
    boule3 = malloc( sizeof(int *) * 3);
    boule3[0] = malloc( sizeof(int) * 1);
    boule3[1] = malloc( sizeof(int) * 2);
    boule3[2] = malloc( sizeof(int) * 2);
    boule3[0][0] = 2;
    boule3[1] = caseSuivant(p,boule2[1], dirBoule);
    boule3[2] = caseSuivant(p,boule3[1], dirDep);
    deplacement(p,boule3,couleur, list);
    deplacement(p,boule2,couleur,list);
    deplacement(p,boule1,couleur,list);
    free(coor);
   }
   break;
  default :
   return -1;
   break;
 }
 return 0;
}

variable_types: couleur char

variable_types: list int

variable_types:
caseSuivDir
int *

variable_types: dirBoule int

variable_types: dirDep int

variable_types:
coordonnee
int **

variable_types:
caseADeplacerD
int *


gameTest

decompiled_code:
void __fastcall __noreturn gameTest(_QWORD *a1)
{
void *v1; // rbp
__int64 v2; // rax

v1 = malloc(9uLL);
affichagePlateau(a1);
while ( scanf("%s", v1) != -1 )
{
printf("\x1B[2J\x1B[1;1H");
v2 = decoupageCoups(v1);
if ( v2 )
{
deplacement(
a1,
v2,
(unsigned int)*(char *)(*(_QWORD *)(*a1 + 8LL * **(int **)(v2 + 8)) + **(int **)(v2 + 8)),
0LL);
affichagePlateau(a1);
}
else
{
puts("coups invalide");
}
}
sauvegarde(a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(_QWORD *a1)
{
void *v1; // rbp
__int64 v2; // rax

v1 = malloc(9uLL);
affichagePlateau(a1);
while ( scanf("%s", v1) != -1 )
{
printf("\x1B[2J\x1B[1;1H");
v2 = decoupageCoups(v1);
if ( v2 )
{
deplacement(
a1,
v2,
(unsigned int)*(char *)(*(_QWORD *)(*a1 + 8LL * **(int **)(v2 + 8)) + **(int **)(v2 + 8)),
0LL);
affichagePlateau(a1);
}
else
{
puts("coups invalide");
}
}
sauvegarde(a1);
exit(0);
}

original_code:
int gameTest(Plateau *p){
  char *coups = malloc(sizeof(char)*9);
 int **coordonnee;
 affichagePlateau(p);
 while(scanf("%s" ,coups) != (-1)){
  printf("\033[2J\033[1;1H");
  coordonnee = decoupageCoups(coups);
  if (coordonnee != ((void *)0)){
   deplacement(p,coordonnee,p->tableau[coordonnee[1][0]][coordonnee[1][0]],0);
   affichagePlateau(p);
  }
  else printf("coups invalide\n");
 };
 sauvegarde(p);
 exit(0);
}

canonical_original_code:
int gameTest(struct Plateau *p){
  char *coups = malloc(sizeof(char)*9);
 int **coordonnee;
 affichagePlateau(p);
 while(scanf("%s" ,coups) != (-1)){
  printf("\033[2J\033[1;1H");
  coordonnee = decoupageCoups(coups);
  if (coordonnee != ((void *)0)){
   deplacement(p,coordonnee,p->tableau[coordonnee[1][0]][coordonnee[1][0]],0);
   affichagePlateau(p);
  }
  else printf("coups invalide\n");
 };
 sauvegarde(p);
 exit(0);
}

variable_types: struct Plateau { char **tableau; int billesBlachesperdues; int billesNoiresperdues; char JoueurSuivant; int typeBlanc; int typeNoir; } *

variable_types:
coups
char *

return_type: int


gamePIA

decompiled_code:
__int64 __fastcall gamePIA(__int64 a1)
{
const char *v1; // r12
int v2; // ebp
__int64 v3; // rsi
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // r13
__int64 v8; // r13
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

v1 = (const char *)malloc(9uLL);
v2 = *(_BYTE *)(a1 + 16) == 78;
affichagePlateau(a1);
v3 = *(unsigned int *)(a1 + 8);
if ( (int)v3 <= 5 )
{
while ( *(int *)(a1 + 12) <= 5 )
{
if ( (v2 & 1) != 0 )
{
if ( v2 % 2 == 1 )
{
puts("\n\nTOUR NOIR");
if ( *(_DWORD *)(a1 + 24) == 1 )
{
v8 = play(78LL, a1);
sleep(1u);
deplacement(a1, v8, 78LL, 0LL);
*(_BYTE *)(a1 + 16) = 66;
}
else
{
scanf("%s", v1);
if ( !strcmp(v1, "SAVE") || !strcmp(v1, "save") )
{
sauvegarde(a1);
puts(aContinuer);
scanf("%s", v9);
if ( (v9[0] & 0xDF) != 89 )
return 0xFFFFFFFFLL;
scanf("%s", v1);
}
v6 = decoupageCoups(v1);
if ( v6 )
{
if ( *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * **(int **)(v6 + 8)) + *(int *)(*(_QWORD *)(v6 + 8) + 4LL)) == 78 )
{
if ( (unsigned int)deplacement(a1, v6, 78LL, 0LL) == -1 )
--v2;
else
*(_BYTE *)(a1 + 16) = 66;
}
else
{
puts("ERREUR Tu ne peux pas deplacer ce pion");
--v2;
}
}
else
{
puts(aCoordonn);
--v2;
}
}
++v2;
}
}
else
{
puts("\n\nTOUR BLANC\n");
if ( *(_DWORD *)(a1 + 20) == 1 )
{
v7 = play(66LL, a1);
sleep(1u);
deplacement(a1, v7, 66LL, 0LL);
*(_BYTE *)(a1 + 16) = 78;
}
else
{
scanf("%s", v1);
if ( !strcmp(v1, "SAVE") || !strcmp(v1, "save") )
{
sauvegarde(a1);
puts(aContinuer);
scanf("%s", v9);
if ( (v9[0] & 0xDF) != 89 )
return 0xFFFFFFFFLL;
scanf("%s", v1);
}
v5 = decoupageCoups(v1);
if ( v5 )
{
if ( *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * **(int **)(v5 + 8)) + *(int *)(*(_QWORD *)(v5 + 8) + 4LL)) == 66 )
{
if ( (unsigned int)deplacement(a1, v5, 66LL, 0LL) == -1 )
--v2;
else
*(_BYTE *)(a1 + 16) = 78;
}
else
{
puts("ERREUR Tu ne peux pas deplacer ce pion");
--v2;
}
}
else
{
puts(aCoordonn);
--v2;
}
}
++v2;
}
printf("\x1B[2J\x1B[1;1H");
affichagePlateau(a1);
v3 = *(unsigned int *)(a1 + 8);
if ( (int)v3 > 5 )
break;
}
}
if ( *(_DWORD *)(a1 + 12) == 6 )
{
printf("bille blanche perdu %d\n", v3);
printf("bille Noir perdu %d\n", *(unsigned int *)(a1 + 12));
puts("Blanc gagne");
}
else
{
printf("bille blanche perdu %d\n", v3);
printf("bille Noir perdu %d\n", *(unsigned int *)(a1 + 12));
puts("Noir gagne");
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
const char *v1; // r12
int v2; // ebp
__int64 v3; // rsi
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // r13
__int64 v8; // r13
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

v1 = (const char *)malloc(9uLL);
v2 = *(_BYTE *)(a1 + 16) == 78;
affichagePlateau(a1);
v3 = *(unsigned int *)(a1 + 8);
if ( (int)v3 <= 5 )
{
while ( *(int *)(a1 + 12) <= 5 )
{
if ( (v2 & 1) != 0 )
{
if ( v2 % 2 == 1 )
{
puts("\n\nTOUR NOIR");
if ( *(_DWORD *)(a1 + 24) == 1 )
{
v8 = play(78LL, a1);
sleep(1u);
deplacement(a1, v8, 78LL, 0LL);
*(_BYTE *)(a1 + 16) = 66;
}
else
{
scanf("%s", v1);
if ( !strcmp(v1, "SAVE") || !strcmp(v1, "save") )
{
sauvegarde(a1);
puts(aContinuer);
scanf("%s", v9);
if ( (v9[0] & 0xDF) != 89 )
return 0xFFFFFFFFLL;
scanf("%s", v1);
}
v6 = decoupageCoups(v1);
if ( v6 )
{
if ( *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * **(int **)(v6 + 8)) + *(int *)(*(_QWORD *)(v6 + 8) + 4LL)) == 78 )
{
if ( (unsigned int)deplacement(a1, v6, 78LL, 0LL) == -1 )
--v2;
else
*(_BYTE *)(a1 + 16) = 66;
}
else
{
puts("ERREUR Tu ne peux pas deplacer ce pion");
--v2;
}
}
else
{
puts(aCoordonn);
--v2;
}
}
++v2;
}
}
else
{
puts("\n\nTOUR BLANC\n");
if ( *(_DWORD *)(a1 + 20) == 1 )
{
v7 = play(66LL, a1);
sleep(1u);
deplacement(a1, v7, 66LL, 0LL);
*(_BYTE *)(a1 + 16) = 78;
}
else
{
scanf("%s", v1);
if ( !strcmp(v1, "SAVE") || !strcmp(v1, "save") )
{
sauvegarde(a1);
puts(aContinuer);
scanf("%s", v9);
if ( (v9[0] & 0xDF) != 89 )
return 0xFFFFFFFFLL;
scanf("%s", v1);
}
v5 = decoupageCoups(v1);
if ( v5 )
{
if ( *(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * **(int **)(v5 + 8)) + *(int *)(*(_QWORD *)(v5 + 8) + 4LL)) == 66 )
{
if ( (unsigned int)deplacement(a1, v5, 66LL, 0LL) == -1 )
--v2;
else
*(_BYTE *)(a1 + 16) = 78;
}
else
{
puts("ERREUR Tu ne peux pas deplacer ce pion");
--v2;
}
}
else
{
puts(aCoordonn);
--v2;
}
}
++v2;
}
printf("\x1B[2J\x1B[1;1H");
affichagePlateau(a1);
v3 = *(unsigned int *)(a1 + 8);
if ( (int)v3 > 5 )
break;
}
}
if ( *(_DWORD *)(a1 + 12) == 6 )
{
printf("bille blanche perdu %d\n", v3);
printf("bille Noir perdu %d\n", *(unsigned int *)(a1 + 12));
puts("Blanc gagne");
}
else
{
printf("bille blanche perdu %d\n", v3);
printf("bille Noir perdu %d\n", *(unsigned int *)(a1 + 12));
puts("Noir gagne");
}
return 0LL;
}

original_code:
int gamePIA(Plateau *p){
 int tour =0;
 char *coups = malloc(sizeof(char)*9);
 int **coordonnee;
 if (p->JoueurSuivant == 'N'){
  tour=1;
 }
 affichagePlateau(p);
 while(p->billesBlachesperdues < 6 && p->billesNoiresperdues < 6){
  switch(tour%2){
   case 0 :
    printf("\n\nTOUR BLANC\n\n");
    if (p->typeBlanc == 1){
     int ** coor =play('B',p);
                    sleep(1);
        deplacement(p,coor,'B',0);
        p->JoueurSuivant = 'N';
    }
    else {
     scanf("%s" ,coups);
     if ((strcmp(coups,"SAVE")==0)||(strcmp(coups,"save")==0)){
      char continueJouer;
      sauvegarde(p);
      printf("Continuer à jouer ? [Y/n]\n");
      scanf("%s" ,&continueJouer);
      if (continueJouer == 'y' || continueJouer == 'Y'){
       scanf("%s" ,coups);
      }
      else return -1;
     }
     coordonnee = decoupageCoups(coups);
     if (coordonnee != ((void *)0)){
      if(p->tableau[coordonnee[1][0]][coordonnee[1][1]]=='B'){
       if ( deplacement(p,coordonnee,'B',0) !=-1 ){
         p->JoueurSuivant = 'N';
        }
        else {
         tour--;
        }
      }else{
       printf("ERREUR Tu ne peux pas deplacer ce pion\n");
       tour--;
      }
     }
     else{
      printf("coordonnées INVALIDE\n");
      tour--;
     }
    }
    tour++;
    break;
   case 1 :
    printf("\n\nTOUR NOIR\n");
    if (p->typeNoir == 1){
     int ** coor =play('N',p);
     sleep(1);
     deplacement(p,coor,'N',0);
     p->JoueurSuivant = 'B';
    }
    else {
     scanf("%s" ,coups);
     if ((strcmp(coups,"SAVE")==0)||(strcmp(coups,"save")==0)){
      char continueJouer;
      sauvegarde(p);
      printf("Continuer à jouer ? [Y/n]\n");
      scanf("%s" ,&continueJouer);
      if (continueJouer == 'y' || continueJouer == 'Y'){
       scanf("%s" ,coups);
      }
      else return -1;
     }
     coordonnee = decoupageCoups(coups);
     if (coordonnee != ((void *)0)){
      if(p->tableau[coordonnee[1][0]][coordonnee[1][1]]=='N'){
       if ( deplacement(p,coordonnee,'N',0) !=-1 ){
         p->JoueurSuivant = 'B';
        }
        else {
         tour--;
        }
      }else{
       printf("ERREUR Tu ne peux pas deplacer ce pion\n");
       tour--;
      }
     }
     else{
      printf("coordonnées INVALIDE\n");
      tour--;
     }
    }
    tour++;
    break;
  }
  printf("\033[2J\033[1;1H");
  affichagePlateau(p);
 }
 if (p->billesNoiresperdues==6){
  printf("bille blanche perdu %d\n",p->billesBlachesperdues);
  printf("bille Noir perdu %d\n",p->billesNoiresperdues);
  printf("Blanc gagne\n");
 }else{
  printf("bille blanche perdu %d\n",p->billesBlachesperdues);
  printf("bille Noir perdu %d\n",p->billesNoiresperdues);
  printf("Noir gagne\n");
 }
 return 0;
}

canonical_original_code:
int gamePIA(struct Plateau *p){
 int tour = 0;
 char *coups = malloc(sizeof(char)*9);
 int **coordonnee;
 if (p->JoueurSuivant == 'N'){
  tour=1;
 }
 affichagePlateau(p);
 while(p->billesBlachesperdues < 6 && p->billesNoiresperdues < 6){
  switch(tour%2){
   case 0 :
    printf("\n\nTOUR BLANC\n\n");
    if (p->typeBlanc == 1){
     int **coor = play('B',p);
                    sleep(1);
        deplacement(p,coor,'B',0);
        p->JoueurSuivant = 'N';
    }
    else {
     scanf("%s" ,coups);
     if ((strcmp(coups,"SAVE")==0)||(strcmp(coups,"save")==0)){
      char continueJouer;
      sauvegarde(p);
      printf("Continuer à jouer ? [Y/n]\n");
      scanf("%s" ,&continueJouer);
      if (continueJouer == 'y' || continueJouer == 'Y'){
       scanf("%s" ,coups);
      }
      else return -1;
     }
     coordonnee = decoupageCoups(coups);
     if (coordonnee != ((void *)0)){
      if(p->tableau[coordonnee[1][0]][coordonnee[1][1]]=='B'){
       if ( deplacement(p,coordonnee,'B',0) !=-1 ){
         p->JoueurSuivant = 'N';
        }
        else {
         tour--;
        }
      }else{
       printf("ERREUR Tu ne peux pas deplacer ce pion\n");
       tour--;
      }
     }
     else{
      printf("coordonnées INVALIDE\n");
      tour--;
     }
    }
    tour++;
    break;
   case 1 :
    printf("\n\nTOUR NOIR\n");
    if (p->typeNoir == 1){
     int **coor = play('N',p);
     sleep(1);
     deplacement(p,coor,'N',0);
     p->JoueurSuivant = 'B';
    }
    else {
     scanf("%s" ,coups);
     if ((strcmp(coups,"SAVE")==0)||(strcmp(coups,"save")==0)){
      char continueJouer;
      sauvegarde(p);
      printf("Continuer à jouer ? [Y/n]\n");
      scanf("%s" ,&continueJouer);
      if (continueJouer == 'y' || continueJouer == 'Y'){
       scanf("%s" ,coups);
      }
      else return -1;
     }
     coordonnee = decoupageCoups(coups);
     if (coordonnee != ((void *)0)){
      if(p->tableau[coordonnee[1][0]][coordonnee[1][1]]=='N'){
       if ( deplacement(p,coordonnee,'N',0) !=-1 ){
         p->JoueurSuivant = 'B';
        }
        else {
         tour--;
        }
      }else{
       printf("ERREUR Tu ne peux pas deplacer ce pion\n");
       tour--;
      }
     }
     else{
      printf("coordonnées INVALIDE\n");
      tour--;
     }
    }
    tour++;
    break;
  }
  printf("\033[2J\033[1;1H");
  affichagePlateau(p);
 }
 if (p->billesNoiresperdues==6){
  printf("bille blanche perdu %d\n",p->billesBlachesperdues);
  printf("bille Noir perdu %d\n",p->billesNoiresperdues);
  printf("Blanc gagne\n");
 }else{
  printf("bille blanche perdu %d\n",p->billesBlachesperdues);
  printf("bille Noir perdu %d\n",p->billesNoiresperdues);
  printf("Noir gagne\n");
 }
 return 0;
}

variable_types: tour int

variable_types:
coor
int **

variable_types: continueJouer char

user_defined_types: struct Plateau { char **tableau; int billesBlachesperdues; int billesNoiresperdues; char JoueurSuivant; int typeBlanc; int typeNoir; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // eax
_BYTE v6[56]; // [rsp+0h] [rbp-38h] BYREF

creationPlateau(v6, argv, envp);
v3 = time(0LL);
srand(v3);
initPlateau(v6);
v4 = optionGlobales(argv, (unsigned int)argc, v6);
if ( v4 == 2 )
{
gameTest(v6);
}
else if ( v4 )
{
puts("ERROR");
}
else
{
gamePIA(v6);
}
return 0;
}

original_code:
int main(int argc, char const *argv[]){
 int mode;
    Plateau p = creationPlateau();
    srand(time(((void *)0)));
    initPlateau(&p);
    mode = optionGlobales(argv,argc,&p);
    if (mode==2){
     gameTest(&p);
    }
    else if (mode ==0){
     gamePIA(&p);
    }
    else{
        printf("ERROR\n");
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 int mode;
    struct Plateau p = creationPlateau();
    srand(time(((void *)0)));
    initPlateau(&p);
    mode = optionGlobales(argv,argc,&p);
    if (mode==2){
     gameTest(&p);
    }
    else if (mode ==0){
     gamePIA(&p);
    }
    else{
        printf("ERROR\n");
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: mode int

variable_types: struct Plateau { char **tableau; int billesBlachesperdues; int billesNoiresperdues; char JoueurSuivant; int typeBlanc; int typeNoir; }


initPlateau

decompiled_code:
__int64 __fastcall initPlateau(__int64 a1)
{
bool v1; // zf
bool v2; // sf
bool v3; // of
char v5; // di
int v6; // ecx
int v7; // esi
__int64 result; // rax
int v9; // edi
int v10; // edi

*(_DWORD *)(a1 + 20) = 2;
*(_DWORD *)(a1 + 24) = 2;
v5 = 78;
v6 = 0;
v7 = 0;
while ( 2 )
{
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * v6) + v7) = v5;
result = (unsigned int)(v7 + 1);
switch ( v6 )
{
case 0:
v3 = __OFSUB__((_DWORD)result, 4);
v1 = (_DWORD)result == 4;
v2 = v7 - 3 < 0;
if ( (int)result > 4 )
{
LODWORD(result) = v6;
v6 = 1;
}
goto LABEL_4;
case 1:
v3 = __OFSUB__((_DWORD)result, 5);
v1 = (_DWORD)result == 5;
v2 = v7 - 4 < 0;
if ( (int)result > 5 )
{
v5 = 46;
v6 = 2;
LODWORD(result) = 0;
}
goto LABEL_4;
case 2:
v3 = __OFSUB__((_DWORD)result, 6);
v1 = (_DWORD)result == 6;
v2 = v7 - 5 < 0;
if ( (int)result > 6 )
{
v5 = 46;
v6 = 3;
LODWORD(result) = 0;
}
else
{
v9 = (unsigned int)(v7 - 1) < 3 ? 0x20 : 0;
v3 = __OFADD__(46, v9);
v1 = v9 == -46;
v2 = v9 + 46 < 0;
v5 = v9 + 46;
}
goto LABEL_4;
case 3:
v3 = __OFSUB__((_DWORD)result, 7);
v1 = (_DWORD)result == 7;
v2 = v7 - 6 < 0;
if ( (int)result > 7 )
{
v6 = 4;
LODWORD(result) = 0;
}
goto LABEL_4;
case 4:
v3 = __OFSUB__((_DWORD)result, 8);
v1 = (_DWORD)result == 8;
v2 = v7 - 7 < 0;
if ( (int)result > 8 )
{
v6 = 5;
LODWORD(result) = 0;
}
goto LABEL_4;
case 5:
v3 = __OFSUB__((_DWORD)result, 7);
v1 = (_DWORD)result == 7;
v2 = v7 - 6 < 0;
if ( (int)result > 7 )
{
v6 = 6;
LODWORD(result) = 0;
}
goto LABEL_4;
case 6:
v3 = __OFSUB__((_DWORD)result, 6);
v1 = (_DWORD)result == 6;
v2 = v7 - 5 < 0;
if ( (int)result > 6 )
{
v5 = 66;
v6 = 7;
LODWORD(result) = 0;
}
else
{
v10 = (unsigned int)(v7 - 1) < 3 ? 0x14 : 0;
v3 = __OFADD__(46, v10);
v1 = v10 == -46;
v2 = v10 + 46 < 0;
v5 = v10 + 46;
}
goto LABEL_4;
case 7:
v3 = __OFSUB__((_DWORD)result, 5);
v1 = (_DWORD)result == 5;
v2 = v7 - 4 < 0;
if ( (int)result > 5 )
{
v6 = 8;
LODWORD(result) = 0;
}
goto LABEL_4;
case 8:
v3 = __OFSUB__((_DWORD)result, 4);
v1 = (_DWORD)result == 4;
v2 = v7 - 3 < 0;
if ( (int)result > 4 )
return result;
LABEL_4:
v7 = result;
continue;
default:
if ( v2 ^ v3 | v1 )
{
++v7;
continue;
}
return result;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
bool v1; // zf
bool v2; // sf
bool v3; // of
char v5; // di
int v6; // ecx
int v7; // esi
__int64 result; // rax
int v9; // edi
int v10; // edi

*(_DWORD *)(a1 + 20) = 2;
*(_DWORD *)(a1 + 24) = 2;
v5 = 78;
v6 = 0;
v7 = 0;
while ( 2 )
{
*(_BYTE *)(*(_QWORD *)(*(_QWORD *)a1 + 8LL * v6) + v7) = v5;
result = (unsigned int)(v7 + 1);
switch ( v6 )
{
case 0:
v3 = __OFSUB__((_DWORD)result, 4);
v1 = (_DWORD)result == 4;
v2 = v7 - 3 < 0;
if ( (int)result > 4 )
{
LODWORD(result) = v6;
v6 = 1;
}
goto LABEL_4;
case 1:
v3 = __OFSUB__((_DWORD)result, 5);
v1 = (_DWORD)result == 5;
v2 = v7 - 4 < 0;
if ( (int)result > 5 )
{
v5 = 46;
v6 = 2;
LODWORD(result) = 0;
}
goto LABEL_4;
case 2:
v3 = __OFSUB__((_DWORD)result, 6);
v1 = (_DWORD)result == 6;
v2 = v7 - 5 < 0;
if ( (int)result > 6 )
{
v5 = 46;
v6 = 3;
LODWORD(result) = 0;
}
else
{
v9 = (unsigned int)(v7 - 1) < 3 ? 0x20 : 0;
v3 = __OFADD__(46, v9);
v1 = v9 == -46;
v2 = v9 + 46 < 0;
v5 = v9 + 46;
}
goto LABEL_4;
case 3:
v3 = __OFSUB__((_DWORD)result, 7);
v1 = (_DWORD)result == 7;
v2 = v7 - 6 < 0;
if ( (int)result > 7 )
{
v6 = 4;
LODWORD(result) = 0;
}
goto LABEL_4;
case 4:
v3 = __OFSUB__((_DWORD)result, 8);
v1 = (_DWORD)result == 8;
v2 = v7 - 7 < 0;
if ( (int)result > 8 )
{
v6 = 5;
LODWORD(result) = 0;
}
goto LABEL_4;
case 5:
v3 = __OFSUB__((_DWORD)result, 7);
v1 = (_DWORD)result == 7;
v2 = v7 - 6 < 0;
if ( (int)result > 7 )
{
v6 = 6;
LODWORD(result) = 0;
}
goto LABEL_4;
case 6:
v3 = __OFSUB__((_DWORD)result, 6);
v1 = (_DWORD)result == 6;
v2 = v7 - 5 < 0;
if ( (int)result > 6 )
{
v5 = 66;
v6 = 7;
LODWORD(result) = 0;
}
else
{
v10 = (unsigned int)(v7 - 1) < 3 ? 0x14 : 0;
v3 = __OFADD__(46, v10);
v1 = v10 == -46;
v2 = v10 + 46 < 0;
v5 = v10 + 46;
}
goto LABEL_4;
case 7:
v3 = __OFSUB__((_DWORD)result, 5);
v1 = (_DWORD)result == 5;
v2 = v7 - 4 < 0;
if ( (int)result > 5 )
{
v6 = 8;
LODWORD(result) = 0;
}
goto LABEL_4;
case 8:
v3 = __OFSUB__((_DWORD)result, 4);
v1 = (_DWORD)result == 4;
v2 = v7 - 3 < 0;
if ( (int)result > 4 )
return result;
LABEL_4:
v7 = result;
continue;
default:
if ( v2 ^ v3 | v1 )
{
++v7;
continue;
}
return result;
}
}
}

original_code:
void initPlateau(Plateau *p){
 int j =0, i = 0;
 char car = 'N';
 p->typeBlanc = 2;
 p->typeNoir = 2;
 while (i < 9 ){
  p->tableau[i][j] = car;
        j++;
         switch (i){
    case 0:
     if (j >= 5 ){
      i++;
                   j =0;
     }
     break;
    case 1:
     if (j >= 6 ){
      i++;
                  j =0;
                  car = '.';
                 }
     break;
    case 2:
     if (j >= 7 ){
      i++;
                  j =0;
                  car = '.';
                 }
                 if(j<5 && j>=2)car = 'N';
     else car = '.';
     break;
    case 3:
     if (j >= 8 ){
      i++;
                  j =0;
     }
     break;
    case 4:
     if (j >= 9 ){
      i++;
                  j =0;
                 }
     break;
    case 5:
     if (j >=8 ){
      i++;
                  j =0;
              }
     break;
    case 6:
     if (j >= 7 ){
      i++;
                  j =0;
               car = 'B';
     }
     else if(j<5 && j>=2)car = 'B';
     else car = '.';
     break;
    case 7:
     if (j >= 6 ){
      i++;
                  j =0;
              }
     break;
    case 8:
     if (j >= 5 ){
      i++;
                  j =0;
     }
     break;
   }
    }
}

canonical_original_code:
void initPlateau(struct Plateau *p){
 int j = 0; int i = 0;
 char car = 'N';
 p->typeBlanc = 2;
 p->typeNoir = 2;
 while (i < 9 ){
  p->tableau[i][j] = car;
        j++;
         switch (i){
    case 0:
     if (j >= 5 ){
      i++;
                   j =0;
     }
     break;
    case 1:
     if (j >= 6 ){
      i++;
                  j =0;
                  car = '.';
                 }
     break;
    case 2:
     if (j >= 7 ){
      i++;
                  j =0;
                  car = '.';
                 }
                 if(j<5 && j>=2)car = 'N';
     else car = '.';
     break;
    case 3:
     if (j >= 8 ){
      i++;
                  j =0;
     }
     break;
    case 4:
     if (j >= 9 ){
      i++;
                  j =0;
                 }
     break;
    case 5:
     if (j >=8 ){
      i++;
                  j =0;
              }
     break;
    case 6:
     if (j >= 7 ){
      i++;
                  j =0;
               car = 'B';
     }
     else if(j<5 && j>=2)car = 'B';
     else car = '.';
     break;
    case 7:
     if (j >= 6 ){
      i++;
                  j =0;
              }
     break;
    case 8:
     if (j >= 5 ){
      i++;
                  j =0;
     }
     break;
   }
    }
}

variable_types: j int

variable_types: i int

variable_types: car char

return_type: void


affichagePlateau

original_code:
void affichagePlateau(Plateau *p){
 int j =0, i = 0;
 int modulo = 0;
 printf("       -----------\n    I / ");
 while (i < 9 ){
  if (modulo == 1){
   printf("\033[44m%c\033[0m ", p->tableau[i][j]);
  }
  else printf("%c ", p->tableau[i][j]);
        j++;
         switch (i){
    case 0:
     if (j >= 5 ){
      i++;
                   j =0;
                   printf("\\ \n   H / ");
                   if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 0) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 1:
     if (j >= 6 ){
      i++;
                  j =0;
                 printf("\\ \n  G / ");
                 if(j%2 == 0) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 1) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 2:
     if (j >= 7 ){
      i++;
                  j =0;
                  printf("\\ \n F / ");
                  if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 0) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 3:
     if (j >= 8 ){
      i++;
                  j =0;
                  printf("\\ \nE | ");
                  if(j%2 == 0) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     break;
    case 4:
     if (j >= 9 ){
      i++;
                  j =0;
                  printf("| \n D \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 5:
     if (j >=8 ){
      i++;
                  j =0;
                  printf("/ \n  C \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 6:
     if (j >= 7 ){
      i++;
                  j =0;
                  printf("/ 9\n   B \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 7:
     if (j >= 6 ){
      i++;
                  j =0;
                  printf("/ \033[44m8\033[0m\n    A \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 8:
     if (j >= 5 ){
      i++;
                  j =0;
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
   }
    }
 printf("/ 7\n       ----------- \033[44m6\033[0m\n          1 \033[44m2\033[0m 3 \033[44m4\033[0m 5\n");
}

canonical_original_code:
void affichagePlateau(struct Plateau *p){
 int j = 0; int i = 0;
 int modulo = 0;
 printf("       -----------\n    I / ");
 while (i < 9 ){
  if (modulo == 1){
   printf("\033[44m%c\033[0m ", p->tableau[i][j]);
  }
  else printf("%c ", p->tableau[i][j]);
        j++;
         switch (i){
    case 0:
     if (j >= 5 ){
      i++;
                   j =0;
                   printf("\\ \n   H / ");
                   if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 0) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 1:
     if (j >= 6 ){
      i++;
                  j =0;
                 printf("\\ \n  G / ");
                 if(j%2 == 0) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 1) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 2:
     if (j >= 7 ){
      i++;
                  j =0;
                  printf("\\ \n F / ");
                  if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 0) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 3:
     if (j >= 8 ){
      i++;
                  j =0;
                  printf("\\ \nE | ");
                  if(j%2 == 0) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     break;
    case 4:
     if (j >= 9 ){
      i++;
                  j =0;
                  printf("| \n D \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 5:
     if (j >=8 ){
      i++;
                  j =0;
                  printf("/ \n  C \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 6:
     if (j >= 7 ){
      i++;
                  j =0;
                  printf("/ 9\n   B \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 7:
     if (j >= 6 ){
      i++;
                  j =0;
                  printf("/ \033[44m8\033[0m\n    A \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 8:
     if (j >= 5 ){
      i++;
                  j =0;
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
   }
    }
 printf("/ 7\n       ----------- \033[44m6\033[0m\n          1 \033[44m2\033[0m 3 \033[44m4\033[0m 5\n");
}

variable_types: modulo int


affichagePlateauColor

original_code:
void affichagePlateauColor(Plateau *p, int pionX, int pionY){
  int j =0, i = 0;
 int modulo = 0;
 printf("       -----------\n    I / ");
 while (i < 9 ){
  if (modulo == 1 && !(pionX == i && pionY == j)){
   printf("\033[44m%c\033[0m ", p->tableau[i][j]);
  }
  else if (pionX == i && pionY == j){
   printf("\033[42m%c\033[0m ", p->tableau[i][j]);
  }
  else printf("%c ", p->tableau[i][j]);
        j++;
         switch (i){
    case 0:
     if (j >= 5 ){
      i++;
                   j =0;
                   printf("\\ \n   H / ");
                   if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 0) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 1:
     if (j >= 6 ){
      i++;
                  j =0;
                 printf("\\ \n  G / ");
                 if(j%2 == 0) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 1) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 2:
     if (j >= 7 ){
      i++;
                  j =0;
                  printf("\\ \n F / ");
                  if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 0) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 3:
     if (j >= 8 ){
      i++;
                  j =0;
                  printf("\\ \nE | ");
                  if(j%2 == 0) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     break;
    case 4:
     if (j >= 9 ){
      i++;
                  j =0;
                  printf("| \n D \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 5:
     if (j >=8 ){
      i++;
                  j =0;
                  printf("/ \n  C \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 6:
     if (j >= 7 ){
      i++;
                  j =0;
                  printf("/ 9\n   B \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 7:
     if (j >= 6 ){
      i++;
                  j =0;
                  printf("/ \033[44m8\033[0m\n    A \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 8:
     if (j >= 5 ){
      i++;
                  j =0;
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
   }
    }
 printf("/ 7\n       ----------- \033[44m6\033[0m\n          1 \033[44m2\033[0m 3 \033[44m4\033[0m 5\n");
}

canonical_original_code:
void affichagePlateauColor(struct Plateau *p, int pionX, int pionY){
  int j = 0; int i = 0;
 int modulo = 0;
 printf("       -----------\n    I / ");
 while (i < 9 ){
  if (modulo == 1 && !(pionX == i && pionY == j)){
   printf("\033[44m%c\033[0m ", p->tableau[i][j]);
  }
  else if (pionX == i && pionY == j){
   printf("\033[42m%c\033[0m ", p->tableau[i][j]);
  }
  else printf("%c ", p->tableau[i][j]);
        j++;
         switch (i){
    case 0:
     if (j >= 5 ){
      i++;
                   j =0;
                   printf("\\ \n   H / ");
                   if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 0) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 1:
     if (j >= 6 ){
      i++;
                  j =0;
                 printf("\\ \n  G / ");
                 if(j%2 == 0) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 1) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 2:
     if (j >= 7 ){
      i++;
                  j =0;
                  printf("\\ \n F / ");
                  if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 0) modulo = 0;
                  else modulo = 1;
                 }
     break;
    case 3:
     if (j >= 8 ){
      i++;
                  j =0;
                  printf("\\ \nE | ");
                  if(j%2 == 0) modulo = 0;
                  else modulo = 1;
     }
     else{
      if(j%2 == 1) modulo = 0;
                  else modulo = 1;
     }
     break;
    case 4:
     if (j >= 9 ){
      i++;
                  j =0;
                  printf("| \n D \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 5:
     if (j >=8 ){
      i++;
                  j =0;
                  printf("/ \n  C \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 6:
     if (j >= 7 ){
      i++;
                  j =0;
                  printf("/ 9\n   B \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 7:
     if (j >= 6 ){
      i++;
                  j =0;
                  printf("/ \033[44m8\033[0m\n    A \\ ");
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
    case 8:
     if (j >= 5 ){
      i++;
                  j =0;
     }
     if(j%2 == 0) modulo = 0;
                 else modulo = 1;
     break;
   }
    }
 printf("/ 7\n       ----------- \033[44m6\033[0m\n          1 \033[44m2\033[0m 3 \033[44m4\033[0m 5\n");
}

variable_types: pionX int

variable_types: pionY int


optionGlobales

decompiled_code:
__int64 __fastcall optionGlobales(__int64 a1, int a2, __int64 a3)
{
__int64 v6; // r13
__int64 v7; // rbx
__int64 result; // rax
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi

if ( a2 <= 1 )
return 0LL;
v6 = (unsigned int)(a2 + 1);
v7 = 2LL;
while ( 1 )
{
if ( !strcmp(*(const char **)(a1 + 8 * v7 - 8), "-N") )
{
if ( a2 == (_DWORD)v7 )
{
puts("Argument obligatoire : N");
return 1LL;
}
if ( !strcmp("IA", *(const char **)(a1 + 8 * v7))
|| !strcmp("ia", *(const char **)(a1 + 8 * v7))
|| !strcmp("robot", *(const char **)(a1 + 8 * v7)) )
{
*(_DWORD *)(a3 + 24) = 1;
}
else
{
if ( strcmp("human", *(const char **)(a1 + 8 * v7))
&& strcmp("h", *(const char **)(a1 + 8 * v7))
&& strcmp("H", *(const char **)(a1 + 8 * v7))
&& strcmp("Humain", *(const char **)(a1 + 8 * v7)) )
{
puts("erreur N : ");
return 1LL;
}
*(_DWORD *)(a3 + 24) = 2;
}
goto LABEL_5;
}
v9 = strcmp(*(const char **)(a1 + 8 * v7 - 8), "-B") != 0;
v10 = 0;
v11 = !v9;
if ( !v9 )
{
if ( a2 == (_DWORD)v7 )
{
puts("Argument obligatoire : B");
return 1LL;
}
if ( !strcmp("IA", *(const char **)(a1 + 8 * v7))
|| !strcmp("ia", *(const char **)(a1 + 8 * v7))
|| !strcmp("robot", *(const char **)(a1 + 8 * v7)) )
{
*(_DWORD *)(a3 + 20) = 1;
}
else
{
if ( strcmp("human", *(const char **)(a1 + 8 * v7))
&& strcmp("h", *(const char **)(a1 + 8 * v7))
&& strcmp("H", *(const char **)(a1 + 8 * v7))
&& strcmp("Humain", *(const char **)(a1 + 8 * v7)) )
{
puts("erreur B : ");
return 1LL;
}
*(_DWORD *)(a3 + 20) = 2;
}
goto LABEL_5;
}
v12 = "-c";
v13 = 3LL;
v14 = *(const char **)(a1 + 8 * v7 - 8);
do
{
if ( !v13 )
break;
v10 = *v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
if ( a2 == (_DWORD)v7 )
{
puts("Argument obligatoire : C");
return 1LL;
}
if ( (unsigned int)fichierConfig(*(_QWORD *)(a1 + 8 * v7), a3, *(_QWORD *)(a1 + 8 * v7 - 8), v13) )
{
puts("ERREUR fichier config option.c");
exit(-1);
}
goto LABEL_5;
}
if ( !strcmp(*(const char **)(a1 + 8 * v7 - 8), "-t") )
break;
LABEL_5:
if ( ++v7 == v6 )
return 0LL;
}
result = (unsigned int)a2;
if ( a2 != 2 )
{
puts("l'Option -t ne prend ni argument ni autre option");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3)
{
__int64 v6; // r13
__int64 v7; // rbx
__int64 result; // rax
bool v9; // al
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi

if ( a2 <= 1 )
return 0LL;
v6 = (unsigned int)(a2 + 1);
v7 = 2LL;
while ( 1 )
{
if ( !strcmp(*(const char **)(a1 + 8 * v7 - 8), "-N") )
{
if ( a2 == (_DWORD)v7 )
{
puts("Argument obligatoire : N");
return 1LL;
}
if ( !strcmp("IA", *(const char **)(a1 + 8 * v7))
|| !strcmp("ia", *(const char **)(a1 + 8 * v7))
|| !strcmp("robot", *(const char **)(a1 + 8 * v7)) )
{
*(_DWORD *)(a3 + 24) = 1;
}
else
{
if ( strcmp("human", *(const char **)(a1 + 8 * v7))
&& strcmp("h", *(const char **)(a1 + 8 * v7))
&& strcmp("H", *(const char **)(a1 + 8 * v7))
&& strcmp("Humain", *(const char **)(a1 + 8 * v7)) )
{
puts("erreur N : ");
return 1LL;
}
*(_DWORD *)(a3 + 24) = 2;
}
goto LABEL_5;
}
v9 = strcmp(*(const char **)(a1 + 8 * v7 - 8), "-B") != 0;
v10 = 0;
v11 = !v9;
if ( !v9 )
{
if ( a2 == (_DWORD)v7 )
{
puts("Argument obligatoire : B");
return 1LL;
}
if ( !strcmp("IA", *(const char **)(a1 + 8 * v7))
|| !strcmp("ia", *(const char **)(a1 + 8 * v7))
|| !strcmp("robot", *(const char **)(a1 + 8 * v7)) )
{
*(_DWORD *)(a3 + 20) = 1;
}
else
{
if ( strcmp("human", *(const char **)(a1 + 8 * v7))
&& strcmp("h", *(const char **)(a1 + 8 * v7))
&& strcmp("H", *(const char **)(a1 + 8 * v7))
&& strcmp("Humain", *(const char **)(a1 + 8 * v7)) )
{
puts("erreur B : ");
return 1LL;
}
*(_DWORD *)(a3 + 20) = 2;
}
goto LABEL_5;
}
v12 = "-c";
v13 = 3LL;
v14 = *(const char **)(a1 + 8 * v7 - 8);
do
{
if ( !v13 )
break;
v10 = *v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
if ( a2 == (_DWORD)v7 )
{
puts("Argument obligatoire : C");
return 1LL;
}
if ( (unsigned int)fichierConfig(*(_QWORD *)(a1 + 8 * v7), a3, *(_QWORD *)(a1 + 8 * v7 - 8), v13) )
{
puts("ERREUR fichier config option.c");
exit(-1);
}
goto LABEL_5;
}
if ( !strcmp(*(const char **)(a1 + 8 * v7 - 8), "-t") )
break;
LABEL_5:
if ( ++v7 == v6 )
return 0LL;
}
result = (unsigned int)a2;
if ( a2 != 2 )
{
puts("l'Option -t ne prend ni argument ni autre option");
result = 1LL;
}
return result;
}

original_code:
int optionGlobales(char const *option[], int nbArgs, Plateau *p){
  int i;
  for(i = 1; i<nbArgs; i++){
   if((strcmp(option[i],"-N")==0)){
    if((i+1) == nbArgs){
     printf("Argument obligatoire : N\n");
     return 1;
    }
    if ((strcmp("IA",option[i+1])==0)||(strcmp("ia",option[i+1])==0)||(strcmp("robot",option[i+1])==0)){
     p->typeNoir = 1;
    }
    else if((strcmp("human",option[i+1])==0)||(strcmp("h",option[i+1])==0)||(strcmp("H",option[i+1])==0)|| (strcmp("Humain",option[i+1])==0)){
     p->typeNoir = 2;
    }
    else {
     printf("erreur N : \n");
     return 1;
    }
   }
   else if((strcmp(option[i],"-B")==0)){
    if((i+1) == nbArgs){
     printf("Argument obligatoire : B\n");
     return 1;
    }
    if ((strcmp("IA",option[i+1])==0)||(strcmp("ia",option[i+1])==0)||(strcmp("robot",option[i+1])==0)){
     p->typeBlanc = 1;
    }
    else if((strcmp("human",option[i+1])==0)||(strcmp("h",option[i+1])==0)||(strcmp("H",option[i+1])==0)|| (strcmp("Humain",option[i+1])==0)){
     p->typeBlanc = 2;
    }
    else {
     printf("erreur B : \n");
     return 1;
    }
   }
   else if((strcmp(option[i],"-c")==0)){
    if((i+1) == nbArgs){
     printf("Argument obligatoire : C\n");
     return 1;
    }
    else {
     if(fichierConfig(option[i+1], p) != 0) {
      printf("ERREUR fichier config option.c\n");
      exit(-1);
     }
    }
   }
   else if ((strcmp(option[i],"-t")==0)){
    if( nbArgs != 2){
     printf("l'Option -t ne prend ni argument ni autre option\n");
     return 1;
    }
    else{
     return 2;
    }
   }
  }
  return 0;
}

canonical_original_code:
int optionGlobales(char *option[], int nbArgs, struct Plateau *p){
  int i;
  for(i = 1; i<nbArgs; i++){
   if((strcmp(option[i],"-N")==0)){
    if((i+1) == nbArgs){
     printf("Argument obligatoire : N\n");
     return 1;
    }
    if ((strcmp("IA",option[i+1])==0)||(strcmp("ia",option[i+1])==0)||(strcmp("robot",option[i+1])==0)){
     p->typeNoir = 1;
    }
    else if((strcmp("human",option[i+1])==0)||(strcmp("h",option[i+1])==0)||(strcmp("H",option[i+1])==0)|| (strcmp("Humain",option[i+1])==0)){
     p->typeNoir = 2;
    }
    else {
     printf("erreur N : \n");
     return 1;
    }
   }
   else if((strcmp(option[i],"-B")==0)){
    if((i+1) == nbArgs){
     printf("Argument obligatoire : B\n");
     return 1;
    }
    if ((strcmp("IA",option[i+1])==0)||(strcmp("ia",option[i+1])==0)||(strcmp("robot",option[i+1])==0)){
     p->typeBlanc = 1;
    }
    else if((strcmp("human",option[i+1])==0)||(strcmp("h",option[i+1])==0)||(strcmp("H",option[i+1])==0)|| (strcmp("Humain",option[i+1])==0)){
     p->typeBlanc = 2;
    }
    else {
     printf("erreur B : \n");
     return 1;
    }
   }
   else if((strcmp(option[i],"-c")==0)){
    if((i+1) == nbArgs){
     printf("Argument obligatoire : C\n");
     return 1;
    }
    else {
     if(fichierConfig(option[i+1], p) != 0) {
      printf("ERREUR fichier config option.c\n");
      exit(-1);
     }
    }
   }
   else if ((strcmp(option[i],"-t")==0)){
    if( nbArgs != 2){
     printf("l'Option -t ne prend ni argument ni autre option\n");
     return 1;
    }
    else{
     return 2;
    }
   }
  }
  return 0;
}

variable_types:
option
char *[]

variable_types: nbArgs int


IA

decompiled_code:
__int64 __fastcall IA(_QWORD *a1, char a2)
{
unsigned int j; // er14
_QWORD *v3; // rbx
_DWORD *v4; // r13
_DWORD *v5; // rbp
__int64 v6; // rax
size_t i; // r12
const char *v8; // rbx
__int64 result; // rax
unsigned int v10[17]; // [rsp+14h] [rbp-44h]

v10[2] = 0;
*(_QWORD *)v10 = (unsigned int)a2;
do
{
for ( i = 0LL; ; ++i )
{
v8 = *(const char **)(*a1 + 8LL * *(_QWORD *)&v10[1]);
if ( strlen(v8) <= i )
break;
if ( v8[i] == a2 )
{
for ( j = 0; j != 6; ++j )
{
v3 = malloc(0xCuLL);
v4 = malloc(4uLL);
*v3 = v4;
v5 = malloc(8uLL);
v3[1] = v5;
v3[2] = malloc(8uLL);
*v4 = 2;
*v5 = v10[1];
v5[1] = i;
v6 = caseSuivant(a1, v5, j);
if ( v6 )
{
v3[2] = v6;
deplacement(a1, v3, v10[0], 1LL);
}
}
}
}
result = ++*(_QWORD *)&v10[1];
}
while ( *(_QWORD *)&v10[1] != 9LL );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, char a2)
{
unsigned int j; // er14
_QWORD *v3; // rbx
_DWORD *v4; // r13
_DWORD *v5; // rbp
__int64 v6; // rax
size_t i; // r12
const char *v8; // rbx
__int64 result; // rax
unsigned int v10[17]; // [rsp+14h] [rbp-44h]

v10[2] = 0;
*(_QWORD *)v10 = (unsigned int)a2;
do
{
for ( i = 0LL; ; ++i )
{
v8 = *(const char **)(*a1 + 8LL * *(_QWORD *)&v10[1]);
if ( strlen(v8) <= i )
break;
if ( v8[i] == a2 )
{
for ( j = 0; j != 6; ++j )
{
v3 = malloc(0xCuLL);
v4 = malloc(4uLL);
*v3 = v4;
v5 = malloc(8uLL);
v3[1] = v5;
v3[2] = malloc(8uLL);
*v4 = 2;
*v5 = v10[1];
v5[1] = i;
v6 = caseSuivant(a1, v5, j);
if ( v6 )
{
v3[2] = v6;
deplacement(a1, v3, v10[0], 1LL);
}
}
}
}
result = ++*(_QWORD *)&v10[1];
}
while ( *(_QWORD *)&v10[1] != 9LL );
return result;
}

original_code:
void IA(Plateau *p, char couleur){
 int i,j,k;
 int * caseSui;
 for(i = 0; i < 9; i++){
        for (j = 0; j < strlen(p->tableau[i]);j++){
         if (p->tableau[i][j]==couleur){
          for (k = 0; k < 6; k++){
           int **coor = malloc(sizeof(int)*3);
           coor[0] = malloc(sizeof(int)*1);
           coor[1] = malloc(sizeof(int)*2);
           coor[2] = malloc(sizeof(int)*2);
           coor[0][0] = 2;
           coor[1][0] = i;
           coor[1][1] = j;
           caseSui = caseSuivant(p,coor[1], k);
           if(caseSui != ((void *)0)){
            coor[2] = caseSui;
            deplacement(p, coor,couleur, 1);
           }
          }
         }
        }
    }
}

canonical_original_code:
void IA(struct Plateau *p, char couleur){
 int i; int j; int k;
 int *caseSui;
 for(i = 0; i < 9; i++){
        for (j = 0; j < strlen(p->tableau[i]);j++){
         if (p->tableau[i][j]==couleur){
          for (k = 0; k < 6; k++){
           int **coor = malloc(sizeof(int)*3);
           coor[0] = malloc(sizeof(int)*1);
           coor[1] = malloc(sizeof(int)*2);
           coor[2] = malloc(sizeof(int)*2);
           coor[0][0] = 2;
           coor[1][0] = i;
           coor[1][1] = j;
           caseSui = caseSuivant(p,coor[1], k);
           if(caseSui != ((void *)0)){
            coor[2] = caseSui;
            deplacement(p, coor,couleur, 1);
           }
          }
         }
        }
    }
}

variable_types: struct Plateau { char **tableau; int billesBlachesperdues; int billesNoiresperdues; char JoueurSuivant; int typeBlanc; int typeNoir; } *

variable_types: couleur char

variable_types: k int

variable_types:
caseSui
int *


play

decompiled_code:
__int64 __fastcall play(char a1, _QWORD *a2)
{
coupsPossibles = malloc(0x50uLL);
tailleDeplacement = 0;
tailleListe = 10;
IA(a2, a1);
return *((_QWORD *)coupsPossibles + rand() % tailleDeplacement);
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1, _QWORD *a2)
{
coupsPossibles = malloc(0x50uLL);
tailleDeplacement = 0;
tailleListe = 10;
func0(a2, a1);
return *((_QWORD *)coupsPossibles + rand() % tailleDeplacement);
}

original_code:
int ** play(char color,Plateau *p){
 int **coorRandom;
 int r;
 coupsPossibles = malloc(sizeof(int**)*10);
 tailleDeplacement=0;
 tailleListe = 10;
 IA(p,color);
 r = rand()%(tailleDeplacement-0) +0;
    coorRandom = coupsPossibles[r];
    return coorRandom;
}

canonical_original_code:
int **play(char color, struct Plateau *p){
 int **coorRandom;
 int r;
 coupsPossibles = malloc(sizeof(int **)*10);
 tailleDeplacement=0;
 tailleListe = 10;
 IA(p,color);
 r = rand()%(tailleDeplacement-0) +0;
    coorRandom = coupsPossibles[r];
    return coorRandom;
}

variable_types: color char

variable_types:
coorRandom
int **

variable_types: r int

return_type: int **


addToList

decompiled_code:
__int64 __fastcall addToList(__int64 a1)
{
int v1; // eax
int v2; // ebp
char *v3; // r12
_QWORD *v4; // r13
__int64 v5; // r13
__int64 v6; // r13
__int64 v7; // r13
__int64 result; // rax
_QWORD *v9; // r13
__int64 v10; // r13
__int64 v11; // r13

v1 = tailleListe;
v2 = tailleDeplacement;
if ( tailleListe == tailleDeplacement )
{
tailleListe *= 2;
coupsPossibles = realloc(coupsPossibles, 16LL * v1);
}
v3 = (char *)coupsPossibles + 8 * v2;
if ( **(_DWORD **)a1 == 2 )
{
v9 = malloc(0x18uLL);
*(_QWORD *)v3 = v9;
*v9 = malloc(4uLL);
v10 = *(_QWORD *)v3;
*(_QWORD *)(v10 + 8) = malloc(8uLL);
v11 = *(_QWORD *)v3;
*(_QWORD *)(v11 + 16) = malloc(8uLL);
***(_DWORD ***)v3 = **(_DWORD **)a1;
*(_QWORD *)(*(_QWORD *)v3 + 8LL) = *(_QWORD *)(a1 + 8);
result = *(_QWORD *)v3;
*(_QWORD *)(*(_QWORD *)v3 + 16LL) = *(_QWORD *)(a1 + 16);
}
else
{
v4 = malloc(0x20uLL);
*(_QWORD *)v3 = v4;
*v4 = malloc(4uLL);
v5 = *(_QWORD *)v3;
*(_QWORD *)(v5 + 8) = malloc(8uLL);
v6 = *(_QWORD *)v3;
*(_QWORD *)(v6 + 16) = malloc(8uLL);
v7 = *(_QWORD *)v3;
*(_QWORD *)(v7 + 24) = malloc(8uLL);
***(_DWORD ***)v3 = **(_DWORD **)a1;
*(_QWORD *)(*(_QWORD *)v3 + 8LL) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(*(_QWORD *)v3 + 16LL) = *(_QWORD *)(a1 + 16);
result = *(_QWORD *)v3;
*(_QWORD *)(*(_QWORD *)v3 + 24LL) = *(_QWORD *)(a1 + 24);
}
tailleDeplacement = v2 + 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // eax
int v2; // ebp
char *v3; // r12
_QWORD *v4; // r13
__int64 v5; // r13
__int64 v6; // r13
__int64 v7; // r13
__int64 result; // rax
_QWORD *v9; // r13
__int64 v10; // r13
__int64 v11; // r13

v1 = tailleListe;
v2 = tailleDeplacement;
if ( tailleListe == tailleDeplacement )
{
tailleListe *= 2;
coupsPossibles = realloc(coupsPossibles, 16LL * v1);
}
v3 = (char *)coupsPossibles + 8 * v2;
if ( **(_DWORD **)a1 == 2 )
{
v9 = malloc(0x18uLL);
*(_QWORD *)v3 = v9;
*v9 = malloc(4uLL);
v10 = *(_QWORD *)v3;
*(_QWORD *)(v10 + 8) = malloc(8uLL);
v11 = *(_QWORD *)v3;
*(_QWORD *)(v11 + 16) = malloc(8uLL);
***(_DWORD ***)v3 = **(_DWORD **)a1;
*(_QWORD *)(*(_QWORD *)v3 + 8LL) = *(_QWORD *)(a1 + 8);
result = *(_QWORD *)v3;
*(_QWORD *)(*(_QWORD *)v3 + 16LL) = *(_QWORD *)(a1 + 16);
}
else
{
v4 = malloc(0x20uLL);
*(_QWORD *)v3 = v4;
*v4 = malloc(4uLL);
v5 = *(_QWORD *)v3;
*(_QWORD *)(v5 + 8) = malloc(8uLL);
v6 = *(_QWORD *)v3;
*(_QWORD *)(v6 + 16) = malloc(8uLL);
v7 = *(_QWORD *)v3;
*(_QWORD *)(v7 + 24) = malloc(8uLL);
***(_DWORD ***)v3 = **(_DWORD **)a1;
*(_QWORD *)(*(_QWORD *)v3 + 8LL) = *(_QWORD *)(a1 + 8);
*(_QWORD *)(*(_QWORD *)v3 + 16LL) = *(_QWORD *)(a1 + 16);
result = *(_QWORD *)v3;
*(_QWORD *)(*(_QWORD *)v3 + 24LL) = *(_QWORD *)(a1 + 24);
}
tailleDeplacement = v2 + 1;
return result;
}

original_code:
void addToList(int ** coor){
 if (tailleListe==tailleDeplacement){
   tailleListe*=2;
  coupsPossibles = realloc(coupsPossibles, sizeof(int**)*tailleListe);
 }
 if( coor[0][0]==2){
  coupsPossibles[tailleDeplacement] = malloc(sizeof(int*) * 3);
  coupsPossibles[tailleDeplacement][0] = malloc(sizeof(int) * 1);
  coupsPossibles[tailleDeplacement][1] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][2] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][0][0] = coor[0][0];
  coupsPossibles[tailleDeplacement][1] = coor[1];
  coupsPossibles[tailleDeplacement][2] = coor[2];
 }
 else{
  coupsPossibles[tailleDeplacement] = malloc(sizeof(int*) * 4);
  coupsPossibles[tailleDeplacement][0] = malloc(sizeof(int) * 1);
  coupsPossibles[tailleDeplacement][1] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][2] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][3] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][0][0] = coor[0][0];
  coupsPossibles[tailleDeplacement][1] = coor[1];
  coupsPossibles[tailleDeplacement][2] = coor[2];
  coupsPossibles[tailleDeplacement][3] = coor[3];
 }
 tailleDeplacement++;
}

canonical_original_code:
void addToList(int **coor){
 if (tailleListe==tailleDeplacement){
   tailleListe*=2;
  coupsPossibles = realloc(coupsPossibles, sizeof(int **)*tailleListe);
 }
 if( coor[0][0]==2){
  coupsPossibles[tailleDeplacement] = malloc(sizeof(int *) * 3);
  coupsPossibles[tailleDeplacement][0] = malloc(sizeof(int) * 1);
  coupsPossibles[tailleDeplacement][1] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][2] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][0][0] = coor[0][0];
  coupsPossibles[tailleDeplacement][1] = coor[1];
  coupsPossibles[tailleDeplacement][2] = coor[2];
 }
 else{
  coupsPossibles[tailleDeplacement] = malloc(sizeof(int *) * 4);
  coupsPossibles[tailleDeplacement][0] = malloc(sizeof(int) * 1);
  coupsPossibles[tailleDeplacement][1] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][2] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][3] = malloc( sizeof(int) * 2);
  coupsPossibles[tailleDeplacement][0][0] = coor[0][0];
  coupsPossibles[tailleDeplacement][1] = coor[1];
  coupsPossibles[tailleDeplacement][2] = coor[2];
  coupsPossibles[tailleDeplacement][3] = coor[3];
 }
 tailleDeplacement++;
}

variable_types:
coor
int **


syntaxeCoups

decompiled_code:
__int64 __fastcall syntaxeCoups(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = strlen((const char *)a1);
if ( v1 == 5 )
return 3 * (unsigned int)(*(_BYTE *)(a1 + 2) == 45) - 1;
if ( v1 == 8 )
{
if ( *(_BYTE *)(a1 + 2) == 45 )
result = 4 * (unsigned int)(*(_BYTE *)(a1 + 5) == 45) - 1;
else
result = 0xFFFFFFFFLL;
}
else
{
printf("%s est un coups non valide de taille : %d\n", (const char *)a1, v1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // eax
__int64 result; // rax

v1 = strlen((const char *)a1);
if ( v1 == 5 )
return 3 * (unsigned int)(*(_BYTE *)(a1 + 2) == 45) - 1;
if ( v1 == 8 )
{
if ( *(_BYTE *)(a1 + 2) == 45 )
result = 4 * (unsigned int)(*(_BYTE *)(a1 + 5) == 45) - 1;
else
result = 0xFFFFFFFFLL;
}
else
{
printf("%s est un coups non valide de taille : %d\n", (const char *)a1, v1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int syntaxeCoups(char * coups){
 int taille;
 taille = strlen(coups);
 if (taille == 5){
  if(coups[2]=='-')return 2;
  else return-1;
 }
 else if (taille == 8){
  if(coups[2]=='-' && coups[5]=='-')return 3;
  else return -1;
 }
 else {
  printf ("%s est un coups non valide de taille : %d\n", coups, taille);
  return -1;
 }
 return 0;
}

canonical_original_code:
int syntaxeCoups(char *coups){
 int taille;
 taille = strlen(coups);
 if (taille == 5){
  if(coups[2]=='-')return 2;
  else return-1;
 }
 else if (taille == 8){
  if(coups[2]=='-' && coups[5]=='-')return 3;
  else return -1;
 }
 else {
  printf ("%s est un coups non valide de taille : %d\n", coups, taille);
  return -1;
 }
 return 0;
}

variable_types:
coups
char *

variable_types: taille int


repo: T-bagwell/su

decompiled_code:
__int64 __fastcall bprint_finalize(__int64 a1, _QWORD *a2)
{
unsigned int v2; // ebp
const void *v3; // r14
void *v4; // r13
__int64 result; // rax
void *v6; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) + 1 <= v2 )
v2 = *(_DWORD *)(a1 + 8) + 1;
if ( a2 )
{
v3 = *(const void **)a1;
if ( *(_QWORD *)a1 == a1 + 20 )
{
v6 = malloc(v2);
v4 = v6;
if ( v6 )
{
memcpy(v6, v3, v2);
result = 0LL;
}
else
{
result = 4294967284LL;
}
}
else
{
v4 = realloc(*(void **)a1, v2);
if ( !v4 )
v4 = *(void **)a1;
*(_QWORD *)a1 = 0LL;
result = 0LL;
}
*a2 = v4;
}
else
{
result = 0LL;
if ( *(_QWORD *)a1 != a1 + 20 )
{
free((void *)a1);
result = 0LL;
}
}
*(_DWORD *)(a1 + 12) = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
unsigned int v2; // ebp
const void *v3; // r14
void *v4; // r13
__int64 result; // rax
void *v6; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) + 1 <= v2 )
v2 = *(_DWORD *)(a1 + 8) + 1;
if ( a2 )
{
v3 = *(const void **)a1;
if ( *(_QWORD *)a1 == a1 + 20 )
{
v6 = malloc(v2);
v4 = v6;
if ( v6 )
{
memcpy(v6, v3, v2);
result = 0LL;
}
else
{
result = 4294967284LL;
}
}
else
{
v4 = realloc(*(void **)a1, v2);
if ( !v4 )
v4 = *(void **)a1;
*(_QWORD *)a1 = 0LL;
result = 0LL;
}
*a2 = v4;
}
else
{
result = 0LL;
if ( *(_QWORD *)a1 != a1 + 20 )
{
free((void *)a1);
result = 0LL;
}
}
*(_DWORD *)(a1 + 12) = v2;
return result;
}

original_code:
int bprint_finalize(BPrint *buf, char **ret_str)
{
    unsigned real_size = ((buf->len + 1) > (buf->size) ? (buf->size) : (buf->len + 1));
    char *str;
    int ret = 0;
    if (ret_str) {
        if (((buf)->str != (buf)->reserved_internal_buffer)) {
            str = realloc(buf->str, real_size);
            if (!str)
                str = buf->str;
            buf->str = ((void *)0);
        } else {
            str = malloc(real_size);
            if (str)
                memcpy(str, buf->str, real_size);
            else
                ret = -12;
        }
        *ret_str = str;
    } else {
        if (((buf)->str != (buf)->reserved_internal_buffer))
            free(&buf->str);
    }
    buf->size = real_size;
    return ret;
}

canonical_original_code:
int bprint_finalize(struct BPrint *buf, char **ret_str)
{
    unsigned int real_size = ((buf->len + 1) > (buf->size) ? (buf->size) : (buf->len + 1));
    char *str;
    int ret = 0;
    if (ret_str) {
        if (((buf)->str != (buf)->reserved_internal_buffer)) {
            str = realloc(buf->str, real_size);
            if (!str)
                str = buf->str;
            buf->str = ((void *)0);
        } else {
            str = malloc(real_size);
            if (str)
                memcpy(str, buf->str, real_size);
            else
                ret = -12;
        }
        *ret_str = str;
    } else {
        if (((buf)->str != (buf)->reserved_internal_buffer))
            free(&buf->str);
    }
    buf->size = real_size;
    return ret;
}

variable_types: struct BPrint { char *str; unsigned int len; unsigned int size; unsigned int size_max; char reserved_internal_buffer[1]; char reserved_padding[-1]; } *

variable_types:
str
char *

variable_types: ret int


decompiled_code:
_BOOL8 __fastcall bprint_is_complete(__int64 a1)
{
return *(_DWORD *)(a1 + 8) < *(_DWORD *)(a1 + 12);
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_DWORD *)(a1 + 8) < *(_DWORD *)(a1 + 12);
}

original_code:
int bprint_is_complete(const BPrint *buf)
{
    return buf->len < buf->size;
}

canonical_original_code:
int bprint_is_complete(struct BPrint *buf)
{
    return buf->len < buf->size;
}

user_defined_types: struct BPrint { char *str; unsigned int len; unsigned int size; unsigned int size_max; char reserved_internal_buffer[1]; char reserved_padding[-1]; }


decompiled_code:
__int64 __fastcall bprint_alloc(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v3; // er12
int v5; // eax
unsigned int v6; // esi
unsigned int v7; // eax
unsigned int v8; // ebp
void *v9; // r13
void *v10; // r12
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
v3 = *(_DWORD *)(a1 + 16);
if ( v2 == v3 )
return 4294967291LL;
if ( !bprint_is_complete(a1) )
return 4294967274LL;
v5 = *(_DWORD *)(a1 + 8);
v6 = -2 - v5;
if ( -2 - v5 > a2 )
v6 = a2;
v7 = v5 + v6 + 1;
v8 = 2 * v2;
if ( v2 > v3 >> 1 )
v8 = v3;
if ( v8 < v7 )
{
if ( v3 <= v7 )
v7 = v3;
v8 = v7;
}
v9 = *(void **)a1;
if ( *(_QWORD *)a1 != a1 + 20 )
{
v10 = realloc(*(void **)a1, v8);
if ( !v10 )
return 4294967284LL;
if ( v9 )
goto LABEL_14;
goto LABEL_20;
}
v10 = malloc(v8);
result = 4294967284LL;
if ( v10 )
{
LABEL_20:
memcpy(v10, *(const void **)a1, (unsigned int)(*(_DWORD *)(a1 + 8) + 1));
LABEL_14:
*(_QWORD *)a1 = v10;
*(_DWORD *)(a1 + 12) = v8;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
unsigned int v2; // er13
unsigned int v3; // er12
int v5; // eax
unsigned int v6; // esi
unsigned int v7; // eax
unsigned int v8; // ebp
void *v9; // r13
void *v10; // r12
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
v3 = *(_DWORD *)(a1 + 16);
if ( v2 == v3 )
return 4294967291LL;
if ( !func2(a1) )
return 4294967274LL;
v5 = *(_DWORD *)(a1 + 8);
v6 = -2 - v5;
if ( -2 - v5 > a2 )
v6 = a2;
v7 = v5 + v6 + 1;
v8 = 2 * v2;
if ( v2 > v3 >> 1 )
v8 = v3;
if ( v8 < v7 )
{
if ( v3 <= v7 )
v7 = v3;
v8 = v7;
}
v9 = *(void **)a1;
if ( *(_QWORD *)a1 != a1 + 20 )
{
v10 = realloc(*(void **)a1, v8);
if ( !v10 )
return 4294967284LL;
if ( v9 )
goto LABEL_14;
goto LABEL_20;
}
v10 = malloc(v8);
result = 4294967284LL;
if ( v10 )
{
LABEL_20:
memcpy(v10, *(const void **)a1, (unsigned int)(*(_DWORD *)(a1 + 8) + 1));
LABEL_14:
*(_QWORD *)a1 = v10;
*(_DWORD *)(a1 + 12) = v8;
result = 0LL;
}
return result;
}

original_code:
static int bprint_alloc(BPrint *buf, unsigned room)
{
    char *old, *new;
    unsigned minsz, newsz;
    if (buf->size == buf->size_max) {
        return -5;
    }
    if (!bprint_is_complete(buf)) {
        return -22;
    }
    minsz = buf->len + 1 + (((0x7fffffff * 2U + 1U) - buf->len - 1) > (room) ? (room) : ((0x7fffffff * 2U + 1U) - buf->len - 1));
    newsz = buf->size > buf->size_max / 2 ? buf->size_max : buf->size * 2;
    if (newsz < minsz) {
        newsz = ((buf->size_max) > (minsz) ? (minsz) : (buf->size_max));
    }
    old = ((buf)->str != (buf)->reserved_internal_buffer) ? buf->str : ((void *)0);
    new = realloc(old, newsz);
    if (!new) {
        return -12;
    }
    if (!old) {
        memcpy(new, buf->str, buf->len + 1);
    }
    buf->str = new;
    buf->size = newsz;
    return 0;
}

canonical_original_code:
static int bprint_alloc(struct BPrint *buf, unsigned int room)
{
    char *old; char *new;
    unsigned int minsz; unsigned int newsz;
    if (buf->size == buf->size_max) {
        return -5;
    }
    if (!bprint_is_complete(buf)) {
        return -22;
    }
    minsz = buf->len + 1 + (((0x7fffffff * 2U + 1U) - buf->len - 1) > (room) ? (room) : ((0x7fffffff * 2U + 1U) - buf->len - 1));
    newsz = buf->size > buf->size_max / 2 ? buf->size_max : buf->size * 2;
    if (newsz < minsz) {
        newsz = ((buf->size_max) > (minsz) ? (minsz) : (buf->size_max));
    }
    old = ((buf)->str != (buf)->reserved_internal_buffer) ? buf->str : ((void *)0);
    new = realloc(old, newsz);
    if (!new) {
        return -12;
    }
    if (!old) {
        memcpy(new, buf->str, buf->len + 1);
    }
    buf->str = new;
    buf->size = newsz;
    return 0;
}

variable_types:
room
unsigned int

variable_types:
old
char *

variable_types:
new
char *

variable_types:
minsz
unsigned int

variable_types:
newsz
unsigned int


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

if ( a3 == 1 )
a3 = 1004;
*(_QWORD *)a1 = a1 + 20;
*(_DWORD *)(a1 + 8) = 0;
result = 1004LL;
if ( a3 <= 0x3EC )
result = a3;
*(_DWORD *)(a1 + 12) = result;
*(_DWORD *)(a1 + 16) = a3;
*(_BYTE *)(a1 + 20) = 0;
if ( (unsigned int)result < a2 )
result = bprint_alloc(a1, a2 - 1);
return result;
}

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

if ( a3 == 1 )
a3 = 1004;
*(_QWORD *)a1 = a1 + 20;
*(_DWORD *)(a1 + 8) = 0;
result = 1004LL;
if ( a3 <= 0x3EC )
result = a3;
*(_DWORD *)(a1 + 12) = result;
*(_DWORD *)(a1 + 16) = a3;
*(_BYTE *)(a1 + 20) = 0;
if ( (unsigned int)result < a2 )
result = func3(a1, a2 - 1);
return result;
}

original_code:
void bprint_init(BPrint *buf, unsigned size_init, unsigned size_max)
{
    unsigned size_auto = (char *)buf + sizeof(*buf) - buf->reserved_internal_buffer;
    if (size_max == 1) {
        size_max = size_auto;
    }
    buf->str = buf->reserved_internal_buffer;
    buf->len = 0;
    buf->size = ((size_auto) > (size_max) ? (size_max) : (size_auto));
    buf->size_max = size_max;
    *buf->str = 0;
    if (size_init > buf->size) {
        bprint_alloc(buf, size_init - 1);
    }
}

canonical_original_code:
void bprint_init(struct BPrint *buf, unsigned int size_init, unsigned int size_max)
{
    unsigned int size_auto = (char *)buf + sizeof(*buf) - buf->reserved_internal_buffer;
    if (size_max == 1) {
        size_max = size_auto;
    }
    buf->str = buf->reserved_internal_buffer;
    buf->len = 0;
    buf->size = ((size_auto) > (size_max) ? (size_max) : (size_auto));
    buf->size_max = size_max;
    *buf->str = 0;
    if (size_init > buf->size) {
        bprint_alloc(buf, size_init - 1);
    }
}


decompiled_code:
__int64 __fastcall parser_ipaddr_to_int(char *a1, _BYTE *a2, _BYTE *a3, _BYTE *a4, _BYTE *a5)
{
char *v5; // rbx
int i; // ebp
char v10; // al
char *v11; // rdx
char nptr[4]; // [rsp+0h] [rbp-3Ch] BYREF

if ( a1 )
{
v5 = a1;
for ( i = 0; ; ++i )
{
*(_DWORD *)nptr = 0;
v10 = *v5;
if ( *v5 != 46 && v10 )
{
v11 = nptr;
do
{
*v11 = v10;
v10 = *++v5;
++v11;
}
while ( *v5 != 46 && v10 );
}
if ( i )
{
switch ( i )
{
case 1:
*a3 = atoi(nptr);
break;
case 2:
*a4 = atoi(nptr);
break;
case 3:
*a5 = atoi(nptr);
return 0LL;
}
}
else
{
*a2 = atoi(nptr);
}
fwrite("yyy\n", 1uLL, 4uLL, _bss_start);
++v5;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, _BYTE *a2, _BYTE *a3, _BYTE *a4, _BYTE *a5)
{
char *v5; // rbx
int i; // ebp
char v10; // al
char *v11; // rdx
char nptr[4]; // [rsp+0h] [rbp-3Ch] BYREF

if ( a1 )
{
v5 = a1;
for ( i = 0; ; ++i )
{
*(_DWORD *)nptr = 0;
v10 = *v5;
if ( *v5 != 46 && v10 )
{
v11 = nptr;
do
{
*v11 = v10;
v10 = *++v5;
++v11;
}
while ( *v5 != 46 && v10 );
}
if ( i )
{
switch ( i )
{
case 1:
*a3 = atoi(nptr);
break;
case 2:
*a4 = atoi(nptr);
break;
case 3:
*a5 = atoi(nptr);
return 0LL;
}
}
else
{
*a2 = atoi(nptr);
}
fwrite("yyy\n", 1uLL, 4uLL, _bss_start);
++v5;
}
}
return 0LL;
}

original_code:
int parser_ipaddr_to_int(unsigned char *ipaddr, unsigned char *val1, unsigned char *val2, unsigned char *val3, unsigned char *val4)
{
    unsigned char *p = ipaddr;
    unsigned char tmp_ipaddr[4];
    int i = 0;
    int j = 0;
    while (p) {
        memset(tmp_ipaddr, 0, sizeof(tmp_ipaddr));
        while (*p != '.' && *p != '\0') {
            tmp_ipaddr[i] = *p;
            i++;
            p++;
        }
        if (j == 0) {
            *val1 = atoi(tmp_ipaddr);
        } else if (j == 1) {
            *val2 = atoi(tmp_ipaddr);
        } else if (j == 2) {
            *val3 = atoi(tmp_ipaddr);
        } else if (j == 3) {
            *val4 = atoi(tmp_ipaddr);
            break;
        }
        fprintf(stdout, "yyy\n");
        i = 0;
        j++;
        p++;
    }
    return 0;
}

variable_types:
ipaddr
unsigned char *

variable_types:
p
unsigned char *

variable_types: i int

variable_types: j int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
size_t v4; // rax
int v5; // er13
int v6; // er15
int v7; // er14
char *v8; // rbx
int v9; // eax
int v10; // er12
char *v11; // rbp
int v13; // [rsp+0h] [rbp-A078h]
int fd; // [rsp+4h] [rbp-A074h]
__int16 v15; // [rsp+Ch] [rbp-A06Ch]
unsigned int v16; // [rsp+10h] [rbp-A068h] BYREF
unsigned int v17; // [rsp+14h] [rbp-A064h] BYREF
unsigned int v18; // [rsp+18h] [rbp-A060h] BYREF
unsigned int v19; // [rsp+1Ch] [rbp-A05Ch] BYREF
char dest[8]; // [rsp+20h] [rbp-A058h] BYREF
__int64 v21; // [rsp+28h] [rbp-A050h]
__int64 v22; // [rsp+30h] [rbp-A048h]
__int64 v23; // [rsp+38h] [rbp-A040h]
char s[41016]; // [rsp+40h] [rbp-A038h] BYREF

v19 = 0;
v18 = 0;
v17 = 0;
v16 = 0;
if ( argc <= 3 )
{
fwrite("./modifypcap_tool <source file> <dest file> <dest ip> <before port> <after port>\n", 1uLL, 0x51uLL, stderr);
exit(1);
}
memset(s, 0, 0xA000uLL);
*(_QWORD *)dest = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v3 = argv[3];
v4 = strlen(v3);
strncpy(dest, v3, v4);
parser_ipaddr_to_int(dest, &v19, &v18, &v17, &v16);
fprintf(_bss_start, "%x, %x, %x, %x\n", v19, v18, v17, v16);
v13 = open(argv[1], 0);
fd = open(argv[2], 66, 511LL);
LOWORD(v3) = atoi(argv[4]);
v15 = atoi(argv[5]);
v5 = BYTE1(v3);
v6 = 0;
v7 = (unsigned __int8)v3;
while ( 1 )
{
v9 = read(v13, s, 0xA000uLL);
v10 = v9;
if ( !v9 )
break;
v11 = &s[v9 - 1 + 1];
v8 = s;
do
{
if ( (unsigned __int8)*v8 == v19
&& (unsigned __int8)v8[1] == v18
&& (unsigned __int8)v8[2] == v17
&& (unsigned __int8)v8[3] == v16 )
{
fwrite("xxxxxxxx\n", 1uLL, 9uLL, _bss_start);
v6 = 1;
}
if ( (unsigned __int8)*v8 == v5 && (unsigned __int8)v8[1] == v7 )
{
if ( v6 )
{
*v8 = HIBYTE(v15);
v8[1] = v15;
fwrite("000\n", 1uLL, 4uLL, _bss_start);
v6 = 0;
}
}
++v8;
}
while ( v11 != v8 );
fwrite("xxx\n", 1uLL, 4uLL, _bss_start);
write(fd, s, v10);
memset(s, 0, 0xA000uLL);
}
close(fd);
close(v13);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx
size_t v4; // rax
int v5; // er13
int v6; // er15
int v7; // er14
char *v8; // rbx
int v9; // eax
int v10; // er12
char *v11; // rbp
int v13; // [rsp+0h] [rbp-A078h]
int fd; // [rsp+4h] [rbp-A074h]
__int16 v15; // [rsp+Ch] [rbp-A06Ch]
unsigned int v16; // [rsp+10h] [rbp-A068h] BYREF
unsigned int v17; // [rsp+14h] [rbp-A064h] BYREF
unsigned int v18; // [rsp+18h] [rbp-A060h] BYREF
unsigned int v19; // [rsp+1Ch] [rbp-A05Ch] BYREF
char dest[8]; // [rsp+20h] [rbp-A058h] BYREF
__int64 v21; // [rsp+28h] [rbp-A050h]
__int64 v22; // [rsp+30h] [rbp-A048h]
__int64 v23; // [rsp+38h] [rbp-A040h]
char s[41016]; // [rsp+40h] [rbp-A038h] BYREF

v19 = 0;
v18 = 0;
v17 = 0;
v16 = 0;
if ( argc <= 3 )
{
fwrite("./modifypcap_tool <source file> <dest file> <dest ip> <before port> <after port>\n", 1uLL, 0x51uLL, stderr);
exit(1);
}
memset(s, 0, 0xA000uLL);
*(_QWORD *)dest = 0LL;
v21 = 0LL;
v22 = 0LL;
v23 = 0LL;
v3 = argv[3];
v4 = strlen(v3);
strncpy(dest, v3, v4);
func7(dest, &v19, &v18, &v17, &v16);
fprintf(_bss_start, "%x, %x, %x, %x\n", v19, v18, v17, v16);
v13 = open(argv[1], 0);
fd = open(argv[2], 66, 511LL);
LOWORD(v3) = atoi(argv[4]);
v15 = atoi(argv[5]);
v5 = BYTE1(v3);
v6 = 0;
v7 = (unsigned __int8)v3;
while ( 1 )
{
v9 = read(v13, s, 0xA000uLL);
v10 = v9;
if ( !v9 )
break;
v11 = &s[v9 - 1 + 1];
v8 = s;
do
{
if ( (unsigned __int8)*v8 == v19
&& (unsigned __int8)v8[1] == v18
&& (unsigned __int8)v8[2] == v17
&& (unsigned __int8)v8[3] == v16 )
{
fwrite("xxxxxxxx\n", 1uLL, 9uLL, _bss_start);
v6 = 1;
}
if ( (unsigned __int8)*v8 == v5 && (unsigned __int8)v8[1] == v7 )
{
if ( v6 )
{
*v8 = HIBYTE(v15);
v8[1] = v15;
fwrite("000\n", 1uLL, 4uLL, _bss_start);
v6 = 0;
}
}
++v8;
}
while ( v11 != v8 );
fwrite("xxx\n", 1uLL, 4uLL, _bss_start);
write(fd, s, v10);
memset(s, 0, 0xA000uLL);
}
close(fd);
close(v13);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int input_fd = 0;
    int output_fd = 0;
    int ret = 0;
    int read_size = 0;
    unsigned char buffer[40960];
    unsigned char *p = ((void *)0);
    unsigned char ipaddr[32];
    unsigned int ipaddr1 = 0;
    unsigned int ipaddr2 = 0;
    unsigned int ipaddr3 = 0;
    unsigned int ipaddr4 = 0;
    int port_in = 0;
    int port_out = 0;
    int modify_flag = 0;
    if (argc < 4) {
        fprintf(stderr, "./modifypcap_tool <source file> <dest file> <dest ip> <before port> <after port>\n");
        exit(1);
    }
    memset(buffer, 0, sizeof(buffer));
    memset(ipaddr, 0, sizeof(ipaddr));
    strncpy(ipaddr, argv[3], strlen(argv[3]));
    parser_ipaddr_to_int(ipaddr, &ipaddr1, &ipaddr2, &ipaddr3, &ipaddr4);
    fprintf(stdout, "%x, %x, %x, %x\n", ipaddr1, ipaddr2, ipaddr3, ipaddr4);
    port_in = atoi(argv[4]);
    port_out = atoi(argv[5]);
    input_fd = open(argv[1], 00);
    output_fd = open(argv[2], 0100 | 02, (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3));
    port_in = atoi(argv[4]);
    port_out = atoi(argv[5]);
    while ((ret = read(input_fd, buffer, sizeof(buffer)))) {
        p = buffer;
        read_size = ret;
        while (read_size != 0) {
            if (p[0] == ipaddr1 && p[1] == ipaddr2 && p[2] == ipaddr3 && p[3] == ipaddr4) {
                fprintf(stdout, "xxxxxxxx\n");
                modify_flag = 1;
            }
            if (((p[0] == ((port_in & 0xFF00) >> 8)) && (p[1] == (port_in & 0xFF))) && modify_flag == 1) {
                p[0] = (port_out & 0xFF00) >> 8;
                p[1] = port_out & 0xFF;
                modify_flag = 0;
                fprintf(stdout, "000\n");
            }
            p++;
            read_size--;
        }
        fprintf(stdout, "xxx\n");
        ret = write(output_fd, buffer, ret);
        memset(buffer, 0, sizeof(buffer));
    }
    close(output_fd);
    close(input_fd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buffer
unsigned char [40960]

variable_types:
ipaddr
unsigned char [32]


decompiled_code:
__int64 get_local_time()
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
fprintf(stderr, "time = [%d]\n", timer);
return (unsigned int)timer;
}

canonical_decompiled_code:
__int64 func0()
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

time(&timer);
fprintf(stderr, "time = [%d]\n", timer);
return (unsigned int)timer;
}

original_code:
int get_local_time()
{
    time_t time_p;
    time(&time_p);
    fprintf(stderr, "time = [%d]\n", time_p);
    return (int) time_p;
}

canonical_original_code:
int get_local_time()
{
    long time_p;
    time(&time_p);
    fprintf(stderr, "time = [%d]\n", time_p);
    return (int) time_p;
}


decompiled_code:
__int64 __fastcall time_str2int(const char *a1)
{
return (unsigned int)(int)strtod(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
return (unsigned int)(int)strtod(a1, 0LL);
}

original_code:
int time_str2int(unsigned char *str)
{
    return strtod(str, ((void *)0));
}

variable_types:
str
unsigned char *


decompiled_code:
__int64 __fastcall check_time_val(int a1, int a2)
{
return 2 * (unsigned int)((int)abs32(a1 - a2) < 1001) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return 2 * (unsigned int)((int)abs32(a1 - a2) < 1001) - 1;
}

original_code:
int check_time_val(int local_time, int remote_time)
{
    if (abs(local_time - remote_time) > 1000) {
        return -1;
    }
    return 1;
}


reduce

repo: TACC/laser

original_code:
void reduce(laser_reduction *reducer, double val) {
  double delta;
  reducer->count++;
  reducer->values[0] += val;
  if(val < reducer->values[2]) reducer->values[2] = val;
  if(val > reducer->values[3]) reducer->values[3] = val;
  delta = val - reducer->values[1];
  reducer->values[1] += delta / reducer->count;
  reducer->values[6] += delta * (val - reducer->values[1]);
  reducer->values[4] = reducer->values[6] / reducer->count;
  if(reducer->custom != ((void *)0)) {
    reducer->values[5] = reducer->custom(reducer->values[5], val, reducer->count);
  }
}

canonical_original_code:
void reduce(struct laser_reduction *reducer, double val) {
  double delta;
  reducer->count++;
  reducer->values[0] += val;
  if(val < reducer->values[2]) reducer->values[2] = val;
  if(val > reducer->values[3]) reducer->values[3] = val;
  delta = val - reducer->values[1];
  reducer->values[1] += delta / reducer->count;
  reducer->values[6] += delta * (val - reducer->values[1]);
  reducer->values[4] = reducer->values[6] / reducer->count;
  if(reducer->custom != ((void *)0)) {
    reducer->values[5] = reducer->custom(reducer->values[5], val, reducer->count);
  }
}

variable_types: struct laser_reduction { short options; unsigned long count; double values[7]; double (*custom)(double, double, unsigned long); } *

variable_types: val double

variable_types: delta double


createReductionEvent

decompiled_code:
__int64 __fastcall createReductionEvent(__int64 a1, char a2, __int64 a3, __int64 a4)
{
__int64 v7[2]; // [rsp+0h] [rbp-428h] BYREF
char v8[1008]; // [rsp+10h] [rbp-418h] BYREF

v7[0] = 0LL;
v7[1] = 0LL;
memset(v8, 0, sizeof(v8));
if ( (a2 & 1) != 0 )
sprintf((char *)v7, "*Count, %ld;", *(_QWORD *)(a1 + 8));
if ( (a2 & 2) != 0 )
sprintf((char *)v7, "%s *Sum, %lf;", (const char *)v7, *(double *)(a1 + 16));
if ( (a2 & 4) != 0 )
sprintf((char *)v7, "%s *Mean, %lf;", (const char *)v7, *(double *)(a1 + 24));
if ( (a2 & 8) != 0 )
sprintf((char *)v7, "%s *Min, %lf;", (const char *)v7, *(double *)(a1 + 32));
if ( (a2 & 0x10) != 0 )
sprintf((char *)v7, "%s *Max, %lf;", (const char *)v7, *(double *)(a1 + 40));
if ( (a2 & 0x20) != 0 )
sprintf((char *)v7, "%s *Variance, %lf;", (const char *)v7, *(double *)(a1 + 48));
if ( (a2 & 0x40) != 0 )
sprintf((char *)v7, "%s *Custom, %lf;", (const char *)v7, *(double *)(a1 + 56));
return createEvent(a3, a4, 2LL, v7);
}

original_code:
laser_event *createReductionEvent(laser_reduction *reducer, short options, char *title, char *desc) {
  char datastr[1024] = "";
  if(options & 1) sprintf(datastr, "*Count, %ld;", reducer->count);
  if(options & 2) sprintf(datastr, "%s *Sum, %lf;", datastr, reducer->values[0]);
  if(options & 4) sprintf(datastr, "%s *Mean, %lf;", datastr, reducer->values[1]);
  if(options & 8) sprintf(datastr, "%s *Min, %lf;", datastr, reducer->values[2]);
  if(options & 16) sprintf(datastr, "%s *Max, %lf;", datastr, reducer->values[3]);
  if(options & 32) sprintf(datastr, "%s *Variance, %lf;", datastr, reducer->values[4]);
  if(options & 64) sprintf(datastr, "%s *Custom, %lf;", datastr, reducer->values[5]);
  return createEvent(title, desc, 2, datastr);
}

canonical_original_code:
struct laser_event *createReductionEvent(struct laser_reduction *reducer, short options, char *title, char *desc) {
  char datastr[1024] = "";
  if(options & 1) sprintf(datastr, "*Count, %ld;", reducer->count);
  if(options & 2) sprintf(datastr, "%s *Sum, %lf;", datastr, reducer->values[0]);
  if(options & 4) sprintf(datastr, "%s *Mean, %lf;", datastr, reducer->values[1]);
  if(options & 8) sprintf(datastr, "%s *Min, %lf;", datastr, reducer->values[2]);
  if(options & 16) sprintf(datastr, "%s *Max, %lf;", datastr, reducer->values[3]);
  if(options & 32) sprintf(datastr, "%s *Variance, %lf;", datastr, reducer->values[4]);
  if(options & 64) sprintf(datastr, "%s *Custom, %lf;", datastr, reducer->values[5]);
  return createEvent(title, desc, 2, datastr);
}

variable_types: options short

variable_types:
title
char *

variable_types:
desc
char *

variable_types:
datastr
char [1024]

return_type: struct laser_event { char *title; char *desc; long generated; short eventtype; char *data; } *

user_defined_types: struct laser_reduction { short options; unsigned long count; double values[7]; double (*custom)(double, double, unsigned long); }