main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
_DWORD *v5; // rax
__int64 v6; // r15
unsigned int v7; // er14
unsigned int v8; // er13
unsigned int v9; // er12
unsigned int v10; // ebp
unsigned int v11; // eax
unsigned int *v12; // rax
bool v13; // al
bool v14; // cf
bool v15; // zf
const char *v16; // rdi
__int64 v17; // rcx
char *v18; // rsi
void **v19; // rbx
pthread_t *v20; // rbp
pthread_t *v21; // rbx
pthread_t *v22; // r12
__int64 v24; // [rsp+0h] [rbp-B8h]
char v25[10]; // [rsp+16h] [rbp-A2h] BYREF
__int64 v26[2]; // [rsp+20h] [rbp-98h] BYREF
__int64 v27[2]; // [rsp+30h] [rbp-88h] BYREF
__int64 v28[2]; // [rsp+40h] [rbp-78h] BYREF
__int64 v29[2]; // [rsp+50h] [rbp-68h] BYREF
__int64 v30[2]; // [rsp+60h] [rbp-58h] BYREF
__int64 arg[9]; // [rsp+70h] [rbp-48h] BYREF

v3 = time(0LL);
srand(v3);
signal(2, (__sighandler_t)traitantC);
signal(19, (__sighandler_t)traitantC);
initAnneau();
initProducteur();
initSortieProduit();
r = creerRobot(1LL);
*(&r + 1) = creerRobot(2LL);
*(&r + 2) = creerRobot(3LL);
*(&r + 3) = creerRobot(4LL);
*(&r + 4) = creerRobot(5LL);
*(&r + 5) = creerRobot(6LL);
pthread_create(&tid, 0LL, (void *(*)(void *))&th_tournerAnneau, 0LL);
pthread_create(
(pthread_t *)(unsigned int)((_DWORD)&tid + 8),
0LL,
(void *(*)(void *))&th_creerComposantEtAjoutDansAnneau,
0LL);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 16), 0LL, (void *(*)(void *))&th_verifSortieProduit, 0LL);
arg[0] = 1LL;
arg[1] = r;
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 24), 0LL, (void *(*)(void *))&th_robot, arg);
v30[0] = 2LL;
v30[1] = *(&r + 1);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 32), 0LL, (void *(*)(void *))&th_robot, v30);
v29[0] = 3LL;
v29[1] = *(&r + 2);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 40), 0LL, (void *(*)(void *))&th_robot, v29);
v28[0] = 4LL;
v28[1] = *(&r + 3);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 48), 0LL, (void *(*)(void *))&th_robot, v28);
v27[0] = 5LL;
v27[1] = *(&r + 4);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 56), 0LL, (void *(*)(void *))&th_robot, v27);
v26[0] = 6LL;
v26[1] = *(&r + 5);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 64), 0LL, (void *(*)(void *))&th_robot, v26);
printAnneau();
usleep(0x61A80u);
printAnneau();
v4 = 10;
do
{
puts(" R6 ");
printf(
" C%d C%d C%d \n",
*(unsigned int *)(*(&r + 5) + 40),
*(unsigned int *)(*(&r + 5) + 44),
*(unsigned int *)(*(&r + 5) + 48));
printf(" 14 %d \n", (unsigned int)*(&bufComposantOuProduit + 14));
printf(
" R5 C%d C%d C%d\n",
*(unsigned int *)(*(&r + 4) + 40),
*(unsigned int *)(*(&r + 4) + 44),
*(unsigned int *)(*(&r + 4) + 48));
printf(
" 15 %d 13 %d\n",
(unsigned int)*(&bufComposantOuProduit + 15),
(unsigned int)*(&bufComposantOuProduit + 13));
puts(" ");
printf(
" 11 %d R4 C%d C%d C%d\n",
(unsigned int)bufComposantOuProduit,
*(unsigned int *)(*(&r + 3) + 40),
*(unsigned int *)(*(&r + 3) + 44),
*(unsigned int *)(*(&r + 3) + 48));
puts(" ");
printf(
" 0 %d 10 %d\n",
(unsigned int)bufComposantOuProduit,
(unsigned int)*(&bufComposantOuProduit + 10));
puts(" ");
v5 = (_DWORD *)*(&r + 3);
v6 = (unsigned int)v5[12];
v7 = v5[11];
v8 = v5[10];
v9 = *(&bufComposantOuProduit + 9);
v10 = *(&bufComposantOuProduit + 1);
v11 = resteTIlComposant();
printf(" %d => 1 %d 9 %d R3 C%d C%d C%d\n", v11, v10, v9, v8, v7, v6);
puts(" ");
printf(
" 2 %d 8 %d\n",
(unsigned int)*(&bufComposantOuProduit + 2),
(unsigned int)*(&bufComposantOuProduit + 8));
puts(" ");
v12 = (unsigned int *)*(&r + 2);
LODWORD(v24) = v12[12];
printf(
" %d <= 3 %d 7 %d R2 C%d C%d C%d\n",
(unsigned int)nbProduitSortie,
(unsigned int)*(&bufComposantOuProduit + 3),
(unsigned int)*(&bufComposantOuProduit + 7),
v12[10],
v12[11],
v24);
puts(" ");
printf(
" 4 %d 6 %d\n",
(unsigned int)*(&bufComposantOuProduit + 4),
(unsigned int)*(&bufComposantOuProduit + 6));
puts(" ");
printf(" 5 %d\n", (unsigned int)*(&bufComposantOuProduit + 5));
puts(" R1 ");
printf(
" C%d C%d C%d \n",
*(unsigned int *)(r + 40),
*(unsigned int *)(r + 44),
*(unsigned int *)(r + 48));
usleep(0x2710u);
--v4;
}
while ( v4 );
while ( 1 )
{
_isoc99_scanf("%9s", v25);
printf("la chaine vaut=%s\n", v25);
v13 = strcmp(v25, "stop") != 0;
v14 = 0;
v15 = !v13;
if ( !v13 )
break;
v16 = "fin";
v17 = 4LL;
v18 = v25;
do
{
if ( !v17 )
break;
v14 = (unsigned __int8)*v18 < (unsigned int)*v16;
v15 = *v18++ == *v16++;
--v17;
}
while ( v15 );
if ( (!v14 && !v15) == v14 )
fin(v16, v18);
gererChoix(v25);
}
puts("arretForce");
pthread_join(tid, 0LL);
pthread_join(*(&tid + 1), 0LL);
pthread_join(*(&tid + 2), 0LL);
printAnneau();
printVoidBuf(&produitsSortis);
libererBuf(&produitsSortis);
v19 = (void **)&r;
do
free(*v19++);
while ( v19 != (void **)(unsigned int)((_DWORD)&r + 48) );
v20 = (pthread_t *)(unsigned int)((_DWORD)&tid + 24);
v21 = &tid;
v22 = (pthread_t *)(unsigned int)((_DWORD)&tid + 72);
do
pthread_join(*v20++, 0LL);
while ( v20 != v22 );
do
pthread_detach(*v21++);
while ( v21 != v22 );
printf("fin main / nb de produit sortie=%d", (unsigned int)nbProduitSortie);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
_DWORD *v5; // rax
__int64 v6; // r15
unsigned int v7; // er14
unsigned int v8; // er13
unsigned int v9; // er12
unsigned int v10; // ebp
unsigned int v11; // eax
unsigned int *v12; // rax
bool v13; // al
bool v14; // cf
bool v15; // zf
const char *v16; // rdi
__int64 v17; // rcx
char *v18; // rsi
void **v19; // rbx
pthread_t *v20; // rbp
pthread_t *v21; // rbx
pthread_t *v22; // r12
__int64 v24; // [rsp+0h] [rbp-B8h]
char v25[10]; // [rsp+16h] [rbp-A2h] BYREF
__int64 v26[2]; // [rsp+20h] [rbp-98h] BYREF
__int64 v27[2]; // [rsp+30h] [rbp-88h] BYREF
__int64 v28[2]; // [rsp+40h] [rbp-78h] BYREF
__int64 v29[2]; // [rsp+50h] [rbp-68h] BYREF
__int64 v30[2]; // [rsp+60h] [rbp-58h] BYREF
__int64 arg[9]; // [rsp+70h] [rbp-48h] BYREF

v3 = time(0LL);
srand(v3);
signal(2, (__sighandler_t)traitantC);
signal(19, (__sighandler_t)traitantC);
initAnneau();
initProducteur();
initSortieProduit();
r = creerRobot(1LL);
*(&r + 1) = creerRobot(2LL);
*(&r + 2) = creerRobot(3LL);
*(&r + 3) = creerRobot(4LL);
*(&r + 4) = creerRobot(5LL);
*(&r + 5) = creerRobot(6LL);
pthread_create(&tid, 0LL, (void *(*)(void *))&th_tournerAnneau, 0LL);
pthread_create(
(pthread_t *)(unsigned int)((_DWORD)&tid + 8),
0LL,
(void *(*)(void *))&th_creerComposantEtAjoutDansAnneau,
0LL);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 16), 0LL, (void *(*)(void *))&th_verifSortieProduit, 0LL);
arg[0] = 1LL;
arg[1] = r;
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 24), 0LL, (void *(*)(void *))&th_robot, arg);
v30[0] = 2LL;
v30[1] = *(&r + 1);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 32), 0LL, (void *(*)(void *))&th_robot, v30);
v29[0] = 3LL;
v29[1] = *(&r + 2);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 40), 0LL, (void *(*)(void *))&th_robot, v29);
v28[0] = 4LL;
v28[1] = *(&r + 3);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 48), 0LL, (void *(*)(void *))&th_robot, v28);
v27[0] = 5LL;
v27[1] = *(&r + 4);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 56), 0LL, (void *(*)(void *))&th_robot, v27);
v26[0] = 6LL;
v26[1] = *(&r + 5);
pthread_create((pthread_t *)(unsigned int)((_DWORD)&tid + 64), 0LL, (void *(*)(void *))&th_robot, v26);
printAnneau();
usleep(0x61A80u);
printAnneau();
v4 = 10;
do
{
puts(" R6 ");
printf(
" C%d C%d C%d \n",
*(unsigned int *)(*(&r + 5) + 40),
*(unsigned int *)(*(&r + 5) + 44),
*(unsigned int *)(*(&r + 5) + 48));
printf(" 14 %d \n", (unsigned int)*(&bufComposantOuProduit + 14));
printf(
" R5 C%d C%d C%d\n",
*(unsigned int *)(*(&r + 4) + 40),
*(unsigned int *)(*(&r + 4) + 44),
*(unsigned int *)(*(&r + 4) + 48));
printf(
" 15 %d 13 %d\n",
(unsigned int)*(&bufComposantOuProduit + 15),
(unsigned int)*(&bufComposantOuProduit + 13));
puts(" ");
printf(
" 11 %d R4 C%d C%d C%d\n",
(unsigned int)bufComposantOuProduit,
*(unsigned int *)(*(&r + 3) + 40),
*(unsigned int *)(*(&r + 3) + 44),
*(unsigned int *)(*(&r + 3) + 48));
puts(" ");
printf(
" 0 %d 10 %d\n",
(unsigned int)bufComposantOuProduit,
(unsigned int)*(&bufComposantOuProduit + 10));
puts(" ");
v5 = (_DWORD *)*(&r + 3);
v6 = (unsigned int)v5[12];
v7 = v5[11];
v8 = v5[10];
v9 = *(&bufComposantOuProduit + 9);
v10 = *(&bufComposantOuProduit + 1);
v11 = resteTIlComposant();
printf(" %d => 1 %d 9 %d R3 C%d C%d C%d\n", v11, v10, v9, v8, v7, v6);
puts(" ");
printf(
" 2 %d 8 %d\n",
(unsigned int)*(&bufComposantOuProduit + 2),
(unsigned int)*(&bufComposantOuProduit + 8));
puts(" ");
v12 = (unsigned int *)*(&r + 2);
LODWORD(v24) = v12[12];
printf(
" %d <= 3 %d 7 %d R2 C%d C%d C%d\n",
(unsigned int)nbProduitSortie,
(unsigned int)*(&bufComposantOuProduit + 3),
(unsigned int)*(&bufComposantOuProduit + 7),
v12[10],
v12[11],
v24);
puts(" ");
printf(
" 4 %d 6 %d\n",
(unsigned int)*(&bufComposantOuProduit + 4),
(unsigned int)*(&bufComposantOuProduit + 6));
puts(" ");
printf(" 5 %d\n", (unsigned int)*(&bufComposantOuProduit + 5));
puts(" R1 ");
printf(
" C%d C%d C%d \n",
*(unsigned int *)(r + 40),
*(unsigned int *)(r + 44),
*(unsigned int *)(r + 48));
usleep(0x2710u);
--v4;
}
while ( v4 );
while ( 1 )
{
_isoc99_scanf("%9s", v25);
printf("la chaine vaut=%s\n", v25);
v13 = strcmp(v25, "stop") != 0;
v14 = 0;
v15 = !v13;
if ( !v13 )
break;
v16 = "fin";
v17 = 4LL;
v18 = v25;
do
{
if ( !v17 )
break;
v14 = (unsigned __int8)*v18 < (unsigned int)*v16;
v15 = *v18++ == *v16++;
--v17;
}
while ( v15 );
if ( (!v14 && !v15) == v14 )
func1(v16, v18);
func0(v25);
}
puts("arretForce");
pthread_join(tid, 0LL);
pthread_join(*(&tid + 1), 0LL);
pthread_join(*(&tid + 2), 0LL);
printAnneau();
printVoidBuf(&produitsSortis);
libererBuf(&produitsSortis);
v19 = (void **)&r;
do
free(*v19++);
while ( v19 != (void **)(unsigned int)((_DWORD)&r + 48) );
v20 = (pthread_t *)(unsigned int)((_DWORD)&tid + 24);
v21 = &tid;
v22 = (pthread_t *)(unsigned int)((_DWORD)&tid + 72);
do
pthread_join(*v20++, 0LL);
while ( v20 != v22 );
do
pthread_detach(*v21++);
while ( v21 != v22 );
printf("fin main / nb de produit sortie=%d", (unsigned int)nbProduitSortie);
return 0;
}

original_code:
int main(int argc, const char * argv[])
{
    srand((unsigned int)time(((void *)0)));
    int num;
    signal(2,traitantC);
    signal(19,traitantC);
    initAnneau();
    initProducteur();
    initSortieProduit();
    r[0] = creerRobot(1);
    r[1] = creerRobot(2);
    r[2] = creerRobot(3);
    r[3] = creerRobot(4);
    r[4] = creerRobot(5);
    r[5] = creerRobot(6);
    pthread_create(&tid[0], ((void *)0), (void*)th_tournerAnneau, ((void *)0));
    pthread_create(&tid[1], ((void *)0), (void*)th_creerComposantEtAjoutDansAnneau, ((void *)0));
    pthread_create(&tid[2], ((void *)0), (void*)th_verifSortieProduit, ((void *)0));
    void* arg[] = {(void*)1,r[0]};
    pthread_create(&tid[3], ((void *)0), (void*)th_robot, arg);
    void* arg1[] = {(void*)2,r[1]};
    pthread_create(&tid[4], ((void *)0), (void*)th_robot, arg1);
    void* arg2[] = {(void*)3,r[2]};
    pthread_create(&tid[5], ((void *)0), (void*)th_robot, arg2);
    void* arg3[] = {(void*)4,r[3]};
    pthread_create(&tid[6], ((void *)0), (void*)th_robot, arg3);
    void* arg4[] = {(void*)5,r[4]};
    pthread_create(&tid[7], ((void *)0), (void*)th_robot, arg4);
    void* arg5[] = {(void*)6,r[5]};
    pthread_create(&tid[8], ((void *)0), (void*)th_robot, arg5);
    printAnneau();
    usleep(400000);
    printAnneau();
    int k;
    for(k=0;k<10;k++){
        printf("     R6   \n");
        printf("  C%d C%d C%d  \n",r[5]->composant[0],r[5]->composant[1],r[5]->composant[2]);
        printf("                    14 %d     \n",bufComposantOuProduit[14]);
        printf("                                   R5 C%d C%d C%d\n",r[4]->composant[0],r[4]->composant[1],r[4]->composant[2]);
        printf("           15 %d                 13 %d\n",bufComposantOuProduit[15],bufComposantOuProduit[13]);
        printf("                                \n");
        printf("                                  11 %d  R4 C%d C%d C%d\n",bufComposantOuProduit[0],r[3]->composant[0],r[3]->composant[1],r[3]->composant[2]);
        printf("                                \n");
        printf("         0 %d                         10 %d\n",bufComposantOuProduit[0],bufComposantOuProduit[10]);
        printf("                                \n");
        printf("  %d => 1 %d                             9 %d   R3 C%d C%d C%d\n",resteTIlComposant(),bufComposantOuProduit[1],bufComposantOuProduit[9],r[3]->composant[0],r[3]->composant[1],r[3]->composant[2]);
        printf("                                \n");
        printf("         2 %d                        8 %d\n",bufComposantOuProduit[2],bufComposantOuProduit[8]);
        printf("                                \n");
        printf("     %d <=  3 %d                   7 %d  R2 C%d C%d C%d\n",nbProduitSortie,bufComposantOuProduit[3],bufComposantOuProduit[7],r[2]->composant[0],r[2]->composant[1],r[2]->composant[2]);
        printf("                                \n");
        printf("             4 %d               6 %d\n",bufComposantOuProduit[4],bufComposantOuProduit[6]);
        printf("                                \n");
        printf("                    5 %d\n",bufComposantOuProduit[5]);
        printf("                   R1 \n");
        printf("               C%d C%d C%d  \n",r[0]->composant[0],r[0]->composant[1],r[0]->composant[2]);
        usleep(10000);
    }
    char ppp[10];
    int go=1;
    while(go==1){
        scanf("%9s",ppp);
        printf("la chaine vaut=%s\n",ppp);
        if(strcmp(ppp,"stop")==0){
            printf("arretForce\n");
            go=0;
        }else if(strcmp(ppp,"fin")==0){
            fin();
        }else
            gererChoix(ppp);
    }
 pthread_join(tid[0],((void *)0));
 pthread_join(tid[1],((void *)0));
    pthread_join(tid[2],((void *)0));
    printAnneau();
    printVoidBuf(&produitsSortis);
    libererBuf(&produitsSortis);
    for(num=0;num<6;num++)
        free(r[num]);
    for(num=3;num<9;num++)
        pthread_join(tid[num],((void *)0));
    for(num=0;num<9;num++)
        pthread_detach(tid[num]);
    printf("fin main / nb de produit sortie=%d",nbProduitSortie);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    srand((unsigned int)time(((void *)0)));
    int num;
    signal(2,traitantC);
    signal(19,traitantC);
    initAnneau();
    initProducteur();
    initSortieProduit();
    r[0] = creerRobot(1);
    r[1] = creerRobot(2);
    r[2] = creerRobot(3);
    r[3] = creerRobot(4);
    r[4] = creerRobot(5);
    r[5] = creerRobot(6);
    pthread_create(&tid[0], ((void *)0), (void *)th_tournerAnneau, ((void *)0));
    pthread_create(&tid[1], ((void *)0), (void *)th_creerComposantEtAjoutDansAnneau, ((void *)0));
    pthread_create(&tid[2], ((void *)0), (void *)th_verifSortieProduit, ((void *)0));
    void *arg[] = {(void*)1,r[0]};
    pthread_create(&tid[3], ((void *)0), (void *)th_robot, arg);
    void *arg1[] = {(void*)2,r[1]};
    pthread_create(&tid[4], ((void *)0), (void *)th_robot, arg1);
    void *arg2[] = {(void*)3,r[2]};
    pthread_create(&tid[5], ((void *)0), (void *)th_robot, arg2);
    void *arg3[] = {(void*)4,r[3]};
    pthread_create(&tid[6], ((void *)0), (void *)th_robot, arg3);
    void *arg4[] = {(void*)5,r[4]};
    pthread_create(&tid[7], ((void *)0), (void *)th_robot, arg4);
    void *arg5[] = {(void*)6,r[5]};
    pthread_create(&tid[8], ((void *)0), (void *)th_robot, arg5);
    printAnneau();
    usleep(400000);
    printAnneau();
    int k;
    for(k=0;k<10;k++){
        printf("     R6   \n");
        printf("  C%d C%d C%d  \n",r[5]->composant[0],r[5]->composant[1],r[5]->composant[2]);
        printf("                    14 %d     \n",bufComposantOuProduit[14]);
        printf("                                   R5 C%d C%d C%d\n",r[4]->composant[0],r[4]->composant[1],r[4]->composant[2]);
        printf("           15 %d                 13 %d\n",bufComposantOuProduit[15],bufComposantOuProduit[13]);
        printf("                                \n");
        printf("                                  11 %d  R4 C%d C%d C%d\n",bufComposantOuProduit[0],r[3]->composant[0],r[3]->composant[1],r[3]->composant[2]);
        printf("                                \n");
        printf("         0 %d                         10 %d\n",bufComposantOuProduit[0],bufComposantOuProduit[10]);
        printf("                                \n");
        printf("  %d => 1 %d                             9 %d   R3 C%d C%d C%d\n",resteTIlComposant(),bufComposantOuProduit[1],bufComposantOuProduit[9],r[3]->composant[0],r[3]->composant[1],r[3]->composant[2]);
        printf("                                \n");
        printf("         2 %d                        8 %d\n",bufComposantOuProduit[2],bufComposantOuProduit[8]);
        printf("                                \n");
        printf("     %d <=  3 %d                   7 %d  R2 C%d C%d C%d\n",nbProduitSortie,bufComposantOuProduit[3],bufComposantOuProduit[7],r[2]->composant[0],r[2]->composant[1],r[2]->composant[2]);
        printf("                                \n");
        printf("             4 %d               6 %d\n",bufComposantOuProduit[4],bufComposantOuProduit[6]);
        printf("                                \n");
        printf("                    5 %d\n",bufComposantOuProduit[5]);
        printf("                   R1 \n");
        printf("               C%d C%d C%d  \n",r[0]->composant[0],r[0]->composant[1],r[0]->composant[2]);
        usleep(10000);
    }
    char ppp[10];
    int go = 1;
    while(go==1){
        scanf("%9s",ppp);
        printf("la chaine vaut=%s\n",ppp);
        if(strcmp(ppp,"stop")==0){
            printf("arretForce\n");
            go=0;
        }else if(strcmp(ppp,"fin")==0){
            fin();
        }else
            gererChoix(ppp);
    }
 pthread_join(tid[0],((void *)0));
 pthread_join(tid[1],((void *)0));
    pthread_join(tid[2],((void *)0));
    printAnneau();
    printVoidBuf(&produitsSortis);
    libererBuf(&produitsSortis);
    for(num=0;num<6;num++)
        free(r[num]);
    for(num=3;num<9;num++)
        pthread_join(tid[num],((void *)0));
    for(num=0;num<9;num++)
        pthread_detach(tid[num]);
    printf("fin main / nb de produit sortie=%d",nbProduitSortie);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
arg
void *[]

variable_types: k int

variable_types:
ppp
char [10]

variable_types: go int


initProducteur

decompiled_code:
void initProducteur()
{
nbC1 = 30;
nbC2 = 30;
nbC3 = 4000;
nbC4 = 20;
continuerProducteur = 1;
}

canonical_decompiled_code:
void func0()
{
nbC1 = 30;
nbC2 = 30;
nbC3 = 4000;
nbC4 = 20;
continuerProducteur = 1;
}

original_code:
void initProducteur(){
    nbC1 = 3*10;
    nbC2 = 3*10;
    nbC3 = 1*4000;
    nbC4 = 2*10;
    continuerProducteur = 1;
}

return_type: void


resteTIlComposant

decompiled_code:
_BOOL8 resteTIlComposant()
{
return (nbC4 | nbC3 | nbC2 | nbC1) != 0;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return (nbC4 | nbC3 | nbC2 | nbC1) != 0;
}

original_code:
int resteTIlComposant(){
    if(nbC1 == 0 && nbC2 == 0 && nbC3 == 0 && nbC4 == 0)
        return 0;
    return 1;
}

return_type: int


recupererUnComposant

decompiled_code:
__int64 recupererUnComposant()
{
int v0; // eax

do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v0 = rand() % 4;
if ( v0 != 2 )
break;
if ( nbC3 > 0 )
{
--nbC3;
return 103LL;
}
}
if ( v0 + 1 <= 3 )
break;
if ( nbC4 > 0 )
{
--nbC4;
return 104LL;
}
}
if ( v0 )
break;
if ( nbC1 > 0 )
{
--nbC1;
return 101LL;
}
}
if ( v0 != 1 )
break;
if ( nbC2 > 0 )
{
--nbC2;
return 102LL;
}
}
}
while ( nbC1 <= 0 );
--nbC1;
return 101LL;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax

do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v0 = rand() % 4;
if ( v0 != 2 )
break;
if ( nbC3 > 0 )
{
--nbC3;
return 103LL;
}
}
if ( v0 + 1 <= 3 )
break;
if ( nbC4 > 0 )
{
--nbC4;
return 104LL;
}
}
if ( v0 )
break;
if ( nbC1 > 0 )
{
--nbC1;
return 101LL;
}
}
if ( v0 != 1 )
break;
if ( nbC2 > 0 )
{
--nbC2;
return 102LL;
}
}
}
while ( nbC1 <= 0 );
--nbC1;
return 101LL;
}

original_code:
int recupererUnComposant(){
    int a;
    int c = -1;
    do{
        a = (1 + (rand () % (4-1+1)));
        switch (a) {
            case 1:
                if(nbC1 > 0){
                    c = 101;
                    nbC1--;
                }
                break;
            case 2:
                if(nbC2 > 0){
                    c = 102;
                    nbC2--;
                }
                break;
            case 3:
                if(nbC3 > 0){
                    c = 103;
                    nbC3--;
                }
                break;
            case 4:
                if(nbC4 > 0){
                    c = 104;
                    nbC4--;
                }
                break;
            default:
                if(nbC1 > 0){
                    c = 101;
                    nbC1--;
                }
                break;
        }
    }while(c==-1);
    return c;
}

variable_types: a int

variable_types: c int


decompiled_code:
int th_creerComposantEtAjoutDansAnneau()
{
unsigned int v0; // ebx

while ( resteTIlComposant() && continuerProducteur == 1 )
{
pthread_mutex_lock(&mutex_anneau);
pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
while ( nbElementDansBuffer > 9 )
{
puts("Producteur composant dormir while");
pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
}
++nbElementQuiAccedeAnneau;
pthread_mutex_unlock(&mutex_anneau);
if ( (unsigned int)isPostionBufLibre(1LL) == 1 )
{
v0 = recupererUnComposant();
ajouterElement((int)v0, 1LL, 51LL);
printf("composant ajouter %d\n", v0);
}
else
{
puts("composant non ajouter car case non libre");
}
pthread_mutex_lock(&mutex_anneau);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
}
return puts("Thread Producteur Composant terminer");
}

canonical_decompiled_code:
int func3()
{
unsigned int v0; // ebx

while ( func1() && continuerProducteur == 1 )
{
pthread_mutex_lock(&mutex_anneau);
pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
while ( nbElementDansBuffer > 9 )
{
puts("Producteur composant dormir while");
pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
}
++nbElementQuiAccedeAnneau;
pthread_mutex_unlock(&mutex_anneau);
if ( (unsigned int)isPostionBufLibre(1LL) == 1 )
{
v0 = func2();
ajouterElement((int)v0, 1LL, 51LL);
printf("composant ajouter %d\n", v0);
}
else
{
puts("composant non ajouter car case non libre");
}
pthread_mutex_lock(&mutex_anneau);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
}
return puts("Thread Producteur Composant terminer");
}

original_code:
void th_creerComposantEtAjoutDansAnneau(){
    while(resteTIlComposant() == 1 && continuerProducteur == 1){
        pthread_mutex_lock(&mutex_anneau);
        pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
        while(nbElementDansBuffer >= 16 -6){
            printf("Producteur composant dormir while\n");
            pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
        }
        nbElementQuiAccedeAnneau++;
        pthread_mutex_unlock(&mutex_anneau);
        if(isPostionBufLibre(1) == 1){
            int aa=recupererUnComposant();
            ajouterElement((void*)aa, 1, 51);
            printf("composant ajouter %d\n",aa);
        }else
            printf("composant non ajouter car case non libre\n");
        pthread_mutex_lock(&mutex_anneau);
        nbElementQuiAccedeAnneau--;
        pthread_cond_signal(&cond_anneauAttenteAcces);
        pthread_mutex_unlock(&mutex_anneau);
    }
    printf("Thread Producteur Composant terminer\n");
}

canonical_original_code:
void th_creerComposantEtAjoutDansAnneau(){
    while(resteTIlComposant() == 1 && continuerProducteur == 1){
        pthread_mutex_lock(&mutex_anneau);
        pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
        while(nbElementDansBuffer >= 16 -6){
            printf("Producteur composant dormir while\n");
            pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
        }
        nbElementQuiAccedeAnneau++;
        pthread_mutex_unlock(&mutex_anneau);
        if(isPostionBufLibre(1) == 1){
            int aa = recupererUnComposant();
            ajouterElement((void *)aa, 1, 51);
            printf("composant ajouter %d\n",aa);
        }else
            printf("composant non ajouter car case non libre\n");
        pthread_mutex_lock(&mutex_anneau);
        nbElementQuiAccedeAnneau--;
        pthread_cond_signal(&cond_anneauAttenteAcces);
        pthread_mutex_unlock(&mutex_anneau);
    }
    printf("Thread Producteur Composant terminer\n");
}

variable_types: aa int


changerModeRobot

decompiled_code:
void __fastcall changerModeRobot(int a1, __int64 a2)
{
*(_DWORD *)(a2 + 4) = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2)
{
*(_DWORD *)(a2 + 4) = a1;
}

original_code:
void changerModeRobot(int mode, robot *robot){
    robot->mode = mode;
}

canonical_original_code:
void changerModeRobot(int mode, struct _robot *robot){
    robot->mode = mode;
}

variable_types: mode int

variable_types: struct _robot { int continuer; int mode; int opNormal; int nbOpDegrade; int opDegrade[4]; struct _produit { int numProduit; int nbCNecessaire; int composant; struct _pileFIFO { struct _maillon { struct _maillon *next; int value; } *sommet; } listeDesOperationRequired; } *produit; int composant[3]; } *

user_defined_types: struct _robot { int continuer; int mode; int opNormal; int nbOpDegrade; int opDegrade[4]; struct _produit *produit; int composant[3]; }

user_defined_types: struct _produit { int numProduit; int nbCNecessaire; int composant; struct _pileFIFO listeDesOperationRequired; }

user_defined_types: struct _pileFIFO { struct _maillon *sommet; }


isProduitNextOpCanBeDone

decompiled_code:
_BOOL8 __fastcall isProduitNextOpCanBeDone(__int64 a1, _DWORD *a2)
{
__int64 v2; // rbx
_BOOL8 result; // rax

if ( a2[1] == 1 )
return a2[2] == (unsigned int)getNextOp();
v2 = 0LL;
result = 0LL;
if ( (int)a2[3] > 0 )
{
while ( (unsigned int)getSommetValue(a1 + 16) != a2[v2 + 4] )
{
if ( a2[3] <= (int)++v2 )
return 0LL;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, _DWORD *a2)
{
__int64 v2; // rbx
_BOOL8 result; // rax

if ( a2[1] == 1 )
return a2[2] == (unsigned int)getNextOp();
v2 = 0LL;
result = 0LL;
if ( (int)a2[3] > 0 )
{
while ( (unsigned int)getSommetValue(a1 + 16) != a2[v2 + 4] )
{
if ( a2[3] <= (int)++v2 )
return 0LL;
}
result = 1LL;
}
return result;
}

original_code:
int isProduitNextOpCanBeDone(produit *prod, robot *robot){
    if(robot->mode == 1){
        if(getNextOp(prod) == robot->opNormal)
            return 1;
    }else{
        int i;
            for(i=0;i<robot->nbOpDegrade; i++){
                if(getSommetValue(&prod->listeDesOperationRequired) == robot->opDegrade[i])
                    return 1;
            }
        return 0;
    }
    return 0;
}

canonical_original_code:
int isProduitNextOpCanBeDone(struct _produit *prod, struct _robot *robot){
    if(robot->mode == 1){
        if(getNextOp(prod) == robot->opNormal)
            return 1;
    }else{
        int i;
            for(i=0;i<robot->nbOpDegrade; i++){
                if(getSommetValue(&prod->listeDesOperationRequired) == robot->opDegrade[i])
                    return 1;
            }
        return 0;
    }
    return 0;
}

variable_types: struct _produit { int numProduit; int nbCNecessaire; int composant; struct _pileFIFO { struct _maillon { struct _maillon *next; int value; } *sommet; } listeDesOperationRequired; } *

variable_types: struct _robot { int continuer; int mode; int opNormal; int nbOpDegrade; int opDegrade[4]; struct _produit *produit; int composant[3]; } *

variable_types: i int


isComposantUsefulToBeTaken

decompiled_code:
__int64 __fastcall isComposantUsefulToBeTaken(int a1, _DWORD *a2)
{
int v2; // ecx
__int64 v3; // rdx
__int64 result; // rax
int v5; // edx

if ( a2[1] == 1 )
{
v5 = a2[2];
if ( v5 == 3 )
{
result = a1 == 103;
}
else if ( v5 > 3 )
{
result = a1 == 104;
if ( v5 != 4 )
result = 0LL;
}
else if ( v5 == 1 )
{
result = a1 == 101;
}
else if ( v5 == 2 )
{
result = a1 == 102;
}
else
{
result = 0LL;
}
}
else
{
v2 = a2[3];
v3 = 0LL;
if ( v2 > 0 )
{
do
{
result = (unsigned int)a2[v3 + 4];
if ( (_DWORD)result == 3 )
{
if ( a1 == 103 )
return 1LL;
}
else if ( (int)result > 3 )
{
if ( (_DWORD)result == 4 && a1 == 104 )
return 1LL;
}
else if ( (_DWORD)result == 1 )
{
if ( a1 == 101 )
return result;
}
else if ( (_DWORD)result == 2 && a1 == 102 )
{
return 1LL;
}
++v3;
}
while ( v2 > (int)v3 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, _DWORD *a2)
{
int v2; // ecx
__int64 v3; // rdx
__int64 result; // rax
int v5; // edx

if ( a2[1] == 1 )
{
v5 = a2[2];
if ( v5 == 3 )
{
result = a1 == 103;
}
else if ( v5 > 3 )
{
result = a1 == 104;
if ( v5 != 4 )
result = 0LL;
}
else if ( v5 == 1 )
{
result = a1 == 101;
}
else if ( v5 == 2 )
{
result = a1 == 102;
}
else
{
result = 0LL;
}
}
else
{
v2 = a2[3];
v3 = 0LL;
if ( v2 > 0 )
{
do
{
result = (unsigned int)a2[v3 + 4];
if ( (_DWORD)result == 3 )
{
if ( a1 == 103 )
return 1LL;
}
else if ( (int)result > 3 )
{
if ( (_DWORD)result == 4 && a1 == 104 )
return 1LL;
}
else if ( (_DWORD)result == 1 )
{
if ( a1 == 101 )
return result;
}
else if ( (_DWORD)result == 2 && a1 == 102 )
{
return 1LL;
}
++v3;
}
while ( v2 > (int)v3 );
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int isComposantUsefulToBeTaken(int composant, robot *robot){
    if(robot->mode == 1){
        switch (robot->opNormal) {
            case 1:
                if(composant == 101)
                    return 1;
                break;
            case 2:
                if(composant == 102)
                    return 1;
                break;
            case 3:
                if(composant == 103)
                    return 1;
                break;
            case 4:
                if(composant == 104)
                    return 1;
                break;
            default:
                return 0;
                break;
        }
    }else{
        int i;
        for(i=0;i<robot->nbOpDegrade; i++)
            switch (robot->opDegrade[i]) {
                case 1:
                    if(composant == 101)
                        return 1;
                    break;
                case 2:
                    if(composant == 102)
                        return 1;
                    break;
                case 3:
                    if(composant == 103)
                        return 1;
                    break;
                case 4:
                    if(composant == 104)
                        return 1;
                    break;
            }
    }
    return 0;
}

canonical_original_code:
int isComposantUsefulToBeTaken(int composant, struct _robot *robot){
    if(robot->mode == 1){
        switch (robot->opNormal) {
            case 1:
                if(composant == 101)
                    return 1;
                break;
            case 2:
                if(composant == 102)
                    return 1;
                break;
            case 3:
                if(composant == 103)
                    return 1;
                break;
            case 4:
                if(composant == 104)
                    return 1;
                break;
            default:
                return 0;
                break;
        }
    }else{
        int i;
        for(i=0;i<robot->nbOpDegrade; i++)
            switch (robot->opDegrade[i]) {
                case 1:
                    if(composant == 101)
                        return 1;
                    break;
                case 2:
                    if(composant == 102)
                        return 1;
                    break;
                case 3:
                    if(composant == 103)
                        return 1;
                    break;
                case 4:
                    if(composant == 104)
                        return 1;
                    break;
            }
    }
    return 0;
}

variable_types: composant int

user_defined_types: struct _maillon { struct _maillon *next; int value; }


isRobotAlreadyHaveComposant

decompiled_code:
_BOOL8 __fastcall isRobotAlreadyHaveComposant(_DWORD *a1)
{
if ( a1[10] != -1 )
return 1LL;
if ( a1[11] == -1 )
return a1[12] != -1;
return 1LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_DWORD *a1)
{
if ( a1[10] != -1 )
return 1LL;
if ( a1[11] == -1 )
return a1[12] != -1;
return 1LL;
}

original_code:
int isRobotAlreadyHaveComposant(robot *robot){
    int i;
    for(i=0;i<3; i++)
        if(robot->composant[i] != -1)
            return 1;
    return 0;
}

canonical_original_code:
int isRobotAlreadyHaveComposant(struct _robot *robot){
    int i;
    for(i=0;i<3; i++)
        if(robot->composant[i] != -1)
            return 1;
    return 0;
}


countNbComposant

decompiled_code:
__int64 __fastcall countNbComposant(_DWORD *a1)
{
return (a1[12] != -1) + (a1[11] != -1) + (unsigned int)(a1[10] != -1);
}

original_code:
int countNbComposant(robot *robot){
    int i, somme=0;
    for(i=0;i<3; i++)
        if(robot->composant[i] != -1)
            somme++;
    return somme;
}

canonical_original_code:
int countNbComposant(struct _robot *robot){
    int i; int somme = 0;
    for(i=0;i<3; i++)
        if(robot->composant[i] != -1)
            somme++;
    return somme;
}

variable_types: somme int


isRobotNeedToGiveProduit

decompiled_code:
_BOOL8 __fastcall isRobotNeedToGiveProduit(__int64 a1)
{
return *(_QWORD *)(a1 + 32) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return *(_QWORD *)(a1 + 32) != 0LL;
}

original_code:
int isRobotNeedToGiveProduit(robot *robot){
    if(robot->produit == ((void *)0))
        return 0;
    return 1;
}

canonical_original_code:
int isRobotNeedToGiveProduit(struct _robot *robot){
    if(robot->produit == ((void *)0))
        return 0;
    return 1;
}


isRobotFullOfComposant

decompiled_code:
_BOOL8 __fastcall isRobotFullOfComposant(_DWORD *a1)
{
if ( a1[10] == -1 )
return 0LL;
if ( a1[11] == -1 )
return 0LL;
return a1[12] != -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(_DWORD *a1)
{
if ( a1[10] == -1 )
return 0LL;
if ( a1[11] == -1 )
return 0LL;
return a1[12] != -1;
}

original_code:
int isRobotFullOfComposant(robot *robot){
    int i;
    for(i=0;i<3; i++)
        if(robot->composant[i] == -1)
            return 0;
    return 1;
}

canonical_original_code:
int isRobotFullOfComposant(struct _robot *robot){
    int i;
    for(i=0;i<3; i++)
        if(robot->composant[i] == -1)
            return 0;
    return 1;
}


ajouterComposant

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

if ( a2[10] == -1 )
{
LODWORD(result) = 0;
goto LABEL_6;
}
if ( a2[11] == -1 )
{
LODWORD(result) = 1;
goto LABEL_6;
}
result = 2LL;
if ( a2[12] == -1 )
{
LABEL_6:
result = (int)result;
a2[(int)result + 10] = a1;
}
return result;
}

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

if ( a2[10] == -1 )
{
LODWORD(result) = 0;
goto LABEL_6;
}
if ( a2[11] == -1 )
{
LODWORD(result) = 1;
goto LABEL_6;
}
result = 2LL;
if ( a2[12] == -1 )
{
LABEL_6:
result = (int)result;
a2[(int)result + 10] = a1;
}
return result;
}

original_code:
void ajouterComposant(int composant, robot *robot){
    int i;
    for(i=0;i<3; i++)
        if(robot->composant[i] == -1){
            robot->composant[i] = composant;
            break;
        }
}

canonical_original_code:
void ajouterComposant(int composant, struct _robot *robot){
    int i;
    for(i=0;i<3; i++)
        if(robot->composant[i] == -1){
            robot->composant[i] = composant;
            break;
        }
}


enleverLesComposants

decompiled_code:
void __fastcall enleverLesComposants(_DWORD *a1)
{
a1[10] = -1;
a1[11] = -1;
a1[12] = -1;
}

original_code:
void enleverLesComposants(robot *robot){
    int i;
    for(i=0;i<3; i++)
        robot->composant[i] = -1;
}

canonical_original_code:
void enleverLesComposants(struct _robot *robot){
    int i;
    for(i=0;i<3; i++)
        robot->composant[i] = -1;
}


enleverLeComposant

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

if ( a1 == a2[12] )
{
LODWORD(result) = 2;
goto LABEL_6;
}
if ( a1 == a2[11] )
{
LODWORD(result) = 1;
goto LABEL_6;
}
result = 0LL;
if ( a2[10] == a1 )
{
LABEL_6:
result = (int)result;
a2[(int)result + 10] = -1;
}
return result;
}

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

if ( a1 == a2[12] )
{
LODWORD(result) = 2;
goto LABEL_6;
}
if ( a1 == a2[11] )
{
LODWORD(result) = 1;
goto LABEL_6;
}
result = 0LL;
if ( a2[10] == a1 )
{
LABEL_6:
result = (int)result;
a2[(int)result + 10] = -1;
}
return result;
}

original_code:
void enleverLeComposant(int composant, robot *robot){
    int i;
    for(i = 3 -1 ; i>=0 ; i--)
        if(robot->composant[i] == composant){
            robot->composant[i] = -1;
            break;
        }
}

canonical_original_code:
void enleverLeComposant(int composant, struct _robot *robot){
    int i;
    for(i = 3 -1 ; i>=0 ; i--)
        if(robot->composant[i] == composant){
            robot->composant[i] = -1;
            break;
        }
}


procederALaCreationDuProduit

decompiled_code:
int __fastcall procederALaCreationDuProduit(unsigned int a1, __int64 a2)
{
int v2; // eax
unsigned int *v3; // rax

printf("sleep puis creation prod%d\n", a1);
v2 = rand();
usleep(10000 * (v2 % 10));
enleverLesComposants((_DWORD *)a2);
v3 = (unsigned int *)creerProduit(a1);
*(_QWORD *)(a2 + 32) = v3;
return printf("resultat produit:%d %d %d\n", v3[2], v3[1], *v3);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1, __int64 a2)
{
int v2; // eax
unsigned int *v3; // rax

printf("sleep puis creation prod%d\n", a1);
v2 = rand();
usleep(10000 * (v2 % 10));
func8((_DWORD *)a2);
v3 = (unsigned int *)creerProduit(a1);
*(_QWORD *)(a2 + 32) = v3;
return printf("resultat produit:%d %d %d\n", v3[2], v3[1], *v3);
}

original_code:
void procederALaCreationDuProduit(int numProd, robot *robot){
    printf("sleep puis creation prod%d\n",numProd);
    usleep(10000 * (rand() % 10));
    enleverLesComposants(robot);
    robot->produit = creerProduit(numProd);
    printf("resultat produit:%d %d %d\n",robot->produit->composant, robot->produit->nbCNecessaire, robot->produit->numProduit);
}

canonical_original_code:
void procederALaCreationDuProduit(int numProd, struct _robot *robot){
    printf("sleep puis creation prod%d\n",numProd);
    usleep(10000 * (rand() % 10));
    enleverLesComposants(robot);
    robot->produit = creerProduit(numProd);
    printf("resultat produit:%d %d %d\n",robot->produit->composant, robot->produit->nbCNecessaire, robot->produit->numProduit);
}

variable_types: numProd int


procederOpSuivanteDuProduit

decompiled_code:
__int64 __fastcall procederOpSuivanteDuProduit(__int64 a1)
{
__int64 result; // rax
int v2; // eax

result = isProduitNextOpCanBeDone(*(_QWORD *)(a1 + 32), (_DWORD *)a1);
if ( (_DWORD)result == 1 )
{
puts("sleep puis procede a l'op");
v2 = rand();
usleep(10000 * (v2 % 10));
pop(*(_QWORD *)(a1 + 32) + 16LL);
result = procederOpSuivanteDuProduit(a1);
}
return result;
}

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

result = func1(*(_QWORD *)(a1 + 32), (_DWORD *)a1);
if ( (_DWORD)result == 1 )
{
puts("sleep puis procede a l'op");
v2 = rand();
usleep(10000 * (v2 % 10));
pop(*(_QWORD *)(a1 + 32) + 16LL);
result = func11(a1);
}
return result;
}

original_code:
void procederOpSuivanteDuProduit(robot *robot){
    if(isProduitNextOpCanBeDone(robot->produit, robot) == 1){
        printf("sleep puis procede a l'op\n");
        usleep(10000 * (rand() % 10));
        pop(&robot->produit->listeDesOperationRequired);
        procederOpSuivanteDuProduit(robot);
    }
    return;
}

canonical_original_code:
void procederOpSuivanteDuProduit(struct _robot *robot){
    if(isProduitNextOpCanBeDone(robot->produit, robot) == 1){
        printf("sleep puis procede a l'op\n");
        usleep(10000 * (rand() % 10));
        pop(&robot->produit->listeDesOperationRequired);
        procederOpSuivanteDuProduit(robot);
    }
    return;
}


procederRemiseDuProduitSurAnneau

decompiled_code:
int __fastcall procederRemiseDuProduitSurAnneau(unsigned int a1, __int64 a2)
{
int result; // eax

if ( !isRobotNeedToGiveProduit(a2) )
return printf("erreur remise du produit");
printf(
"produit avant d'etre remis:%d %d %d et rob %d\n",
*(unsigned int *)(*(_QWORD *)(a2 + 32) + 8LL),
*(unsigned int *)(*(_QWORD *)(a2 + 32) + 4LL),
**(unsigned int **)(a2 + 32),
*(unsigned int *)(a2 + 8));
result = ajouterElement(*(_QWORD *)(a2 + 32), a1, 50LL);
*(_QWORD *)(a2 + 32) = 0LL;
return result;
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1, __int64 a2)
{
int result; // eax

if ( !func5(a2) )
return printf("erreur remise du produit");
printf(
"produit avant d'etre remis:%d %d %d et rob %d\n",
*(unsigned int *)(*(_QWORD *)(a2 + 32) + 8LL),
*(unsigned int *)(*(_QWORD *)(a2 + 32) + 4LL),
**(unsigned int **)(a2 + 32),
*(unsigned int *)(a2 + 8));
result = ajouterElement(*(_QWORD *)(a2 + 32), a1, 50LL);
*(_QWORD *)(a2 + 32) = 0LL;
return result;
}

original_code:
void procederRemiseDuProduitSurAnneau(int positionSurAnneau, robot *robot){
    if(isRobotNeedToGiveProduit(robot) == 1){
         printf("produit avant d'etre remis:%d %d %d et rob %d\n",robot->produit->composant, robot->produit->nbCNecessaire, robot->produit->numProduit, robot->opNormal);
        ajouterElement((void*)robot->produit, positionSurAnneau, 50);
        robot->produit = ((void *)0);
    }else
        printf("erreur remise du produit");
}

canonical_original_code:
void procederRemiseDuProduitSurAnneau(int positionSurAnneau, struct _robot *robot){
    if(isRobotNeedToGiveProduit(robot) == 1){
         printf("produit avant d'etre remis:%d %d %d et rob %d\n",robot->produit->composant, robot->produit->nbCNecessaire, robot->produit->numProduit, robot->opNormal);
        ajouterElement((void *)robot->produit, positionSurAnneau, 50);
        robot->produit = ((void *)0);
    }else
        printf("erreur remise du produit");
}

variable_types: positionSurAnneau int


decompiled_code:
int __fastcall th_robot(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // r13
unsigned int v3; // er12
void *v4; // rdi
unsigned int v6; // eax
unsigned int v7; // ebp
unsigned int v8; // eax
int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
__int64 v15; // rax
unsigned int v16; // eax
unsigned int v17; // eax
__int64 v18; // rbp
int v19; // eax
unsigned int v20; // er14
unsigned int v21; // eax
int v22; // eax
unsigned int *v23; // rax

v1 = a1[1];
v2 = *a1;
v3 = *a1;
while ( *(_DWORD *)v1 == 1 )
{
pthread_mutex_lock(&mutex_anneau);
pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
++nbElementQuiAccedeAnneau;
v18 = (unsigned int)countNbComposant((_DWORD *)v1);
v19 = hasEnoughComposantToDoProd(v18, *(unsigned int *)(v1 + 40));
v20 = v19;
if ( (int)v18 <= 0 || v19 <= 0 || isRobotNeedToGiveProduit(v1) )
{
pthread_mutex_unlock(&mutex_anneau);
v21 = getPositionDuRobot(v3);
v22 = getPositionType(v21);
if ( v22 == 51 )
{
v6 = getPositionDuRobot(v3);
v7 = getPointeur(v6);
if ( isRobotAlreadyHaveComposant((_DWORD *)v1) )
{
if ( *(_DWORD *)(v1 + 40) != v7 || isRobotFullOfComposant((_DWORD *)v1) )
goto LABEL_26;
v11 = getPositionDuRobot(v3);
v12 = prendreElement(v11);
ajouterComposant(v12, (_DWORD *)v1);
v13 = countNbComposant((_DWORD *)v1);
printf("Robot%d pris composant %d 1er nb=%d\n", v3, v7, v13);
}
else
{
if ( isRobotFullOfComposant((_DWORD *)v1) || (unsigned int)isComposantUsefulToBeTaken(v7, (_DWORD *)v1) != 1 )
goto LABEL_26;
v8 = getPositionDuRobot(v3);
v9 = prendreElement(v8);
ajouterComposant(v9, (_DWORD *)v1);
v10 = countNbComposant((_DWORD *)v1);
printf("Robot%d pris composant %d 2eme nb=%d\n", v3, v7, v10);
}
LABEL_24:
if ( isRobotNeedToGiveProduit(v1) )
{
v17 = getPositionDuRobot(v3);
procederRemiseDuProduitSurAnneau(v17, v1);
printf("Robot%d produit remis\n", v3);
}
goto LABEL_26;
}
if ( v22 != 50 )
{
if ( !v22 )
goto LABEL_24;
LABEL_26:
v23 = *(unsigned int **)(v1 + 32);
if ( v23 )
{
printf("Robot%d stocke un produit%d\n", v3, *v23);
if ( isRobotNeedToGiveProduit(v1) )
{
printf("Et a besoin de donner produit / %d\n", (unsigned int)nbElementDansBuffer);
printAnneau();
}
}
printf("Robot%d fin boucle et mode %d\n", v3, *(unsigned int *)(v1 + 4));
pthread_mutex_lock(&mutex_anneau);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
continue;
}
if ( isRobotNeedToGiveProduit(v1) )
goto LABEL_26;
v14 = getPositionDuRobot(v3);
v15 = getPointeur(v14);
if ( !isProduitNextOpCanBeDone(v15, (_DWORD *)v1) )
goto LABEL_26;
v16 = getPositionDuRobot(v3);
*(_QWORD *)(v1 + 32) = prendreElement(v16);
pthread_mutex_lock(&mutex_anneau);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
printf("Robot%d procede OpSuivante\n", v3);
procederOpSuivanteDuProduit(v1);
}
else
{
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
printf("Robot%d procede creation produit\n", v3);
procederALaCreationDuProduit(v20, v1);
}
}
v4 = *(void **)(v1 + 32);
if ( v4 )
free(v4);
return printf("Thread robot%d terminer\n", (unsigned int)v2);
}

canonical_decompiled_code:
int __fastcall func13(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // r13
unsigned int v3; // er12
void *v4; // rdi
unsigned int v6; // eax
unsigned int v7; // ebp
unsigned int v8; // eax
int v9; // eax
unsigned int v10; // eax
unsigned int v11; // eax
int v12; // eax
unsigned int v13; // eax
unsigned int v14; // eax
__int64 v15; // rax
unsigned int v16; // eax
unsigned int v17; // eax
__int64 v18; // rbp
int v19; // eax
unsigned int v20; // er14
unsigned int v21; // eax
int v22; // eax
unsigned int *v23; // rax

v1 = a1[1];
v2 = *a1;
v3 = *a1;
while ( *(_DWORD *)v1 == 1 )
{
pthread_mutex_lock(&mutex_anneau);
pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
++nbElementQuiAccedeAnneau;
v18 = (unsigned int)func4((_DWORD *)v1);
v19 = hasEnoughComposantToDoProd(v18, *(unsigned int *)(v1 + 40));
v20 = v19;
if ( (int)v18 <= 0 || v19 <= 0 || func5(v1) )
{
pthread_mutex_unlock(&mutex_anneau);
v21 = getPositionDuRobot(v3);
v22 = getPositionType(v21);
if ( v22 == 51 )
{
v6 = getPositionDuRobot(v3);
v7 = getPointeur(v6);
if ( func3((_DWORD *)v1) )
{
if ( *(_DWORD *)(v1 + 40) != v7 || func6((_DWORD *)v1) )
goto LABEL_26;
v11 = getPositionDuRobot(v3);
v12 = prendreElement(v11);
func7(v12, (_DWORD *)v1);
v13 = func4((_DWORD *)v1);
printf("Robot%d pris composant %d 1er nb=%d\n", v3, v7, v13);
}
else
{
if ( func6((_DWORD *)v1) || (unsigned int)func2(v7, (_DWORD *)v1) != 1 )
goto LABEL_26;
v8 = getPositionDuRobot(v3);
v9 = prendreElement(v8);
func7(v9, (_DWORD *)v1);
v10 = func4((_DWORD *)v1);
printf("Robot%d pris composant %d 2eme nb=%d\n", v3, v7, v10);
}
LABEL_24:
if ( func5(v1) )
{
v17 = getPositionDuRobot(v3);
func12(v17, v1);
printf("Robot%d produit remis\n", v3);
}
goto LABEL_26;
}
if ( v22 != 50 )
{
if ( !v22 )
goto LABEL_24;
LABEL_26:
v23 = *(unsigned int **)(v1 + 32);
if ( v23 )
{
printf("Robot%d stocke un produit%d\n", v3, *v23);
if ( func5(v1) )
{
printf("Et a besoin de donner produit / %d\n", (unsigned int)nbElementDansBuffer);
printAnneau();
}
}
printf("Robot%d fin boucle et mode %d\n", v3, *(unsigned int *)(v1 + 4));
pthread_mutex_lock(&mutex_anneau);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
continue;
}
if ( func5(v1) )
goto LABEL_26;
v14 = getPositionDuRobot(v3);
v15 = getPointeur(v14);
if ( !func1(v15, (_DWORD *)v1) )
goto LABEL_26;
v16 = getPositionDuRobot(v3);
*(_QWORD *)(v1 + 32) = prendreElement(v16);
pthread_mutex_lock(&mutex_anneau);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
printf("Robot%d procede OpSuivante\n", v3);
func11(v1);
}
else
{
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
printf("Robot%d procede creation produit\n", v3);
func10(v20, v1);
}
}
v4 = *(void **)(v1 + 32);
if ( v4 )
free(v4);
return printf("Thread robot%d terminer\n", (unsigned int)v2);
}

original_code:
void th_robot(void* arg[]){
    robot *robot = arg[1];
    int numRobot = (int)arg[0];
    while(robot->continuer == 1){
        pthread_mutex_lock(&mutex_anneau);
        pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
        nbElementQuiAccedeAnneau++;
        int nbCompo = countNbComposant(robot);
        int numProdACreer = 0;
            numProdACreer = hasEnoughComposantToDoProd(nbCompo, robot->composant[0]);
        if(nbCompo > 0 && numProdACreer > 0 && isRobotNeedToGiveProduit(robot) == 0){
            nbElementQuiAccedeAnneau--;
            pthread_cond_signal(&cond_anneauAttenteAcces);
            pthread_mutex_unlock(&mutex_anneau);
            printf("Robot%d procede creation produit\n", numRobot);
            procederALaCreationDuProduit(numProdACreer, robot);
            continue;
        }else{
            pthread_mutex_unlock(&mutex_anneau);
            int typePos = getPositionType(getPositionDuRobot(numRobot));
            if(typePos == 51){
                int composantSurAnneau = (int)getPointeur(getPositionDuRobot(numRobot));
                if(isRobotAlreadyHaveComposant(robot) == 1){
                    if(composantSurAnneau == robot->composant[0] && isRobotFullOfComposant(robot) == 0){
                        ajouterComposant((int)prendreElement(getPositionDuRobot(numRobot)), robot);
                        typePos = 0;
                        printf("Robot%d pris composant %d 1er nb=%d\n", numRobot,composantSurAnneau,countNbComposant(robot));
                    }
                }else{
                    if(isRobotFullOfComposant(robot) == 0 && isComposantUsefulToBeTaken(composantSurAnneau,robot) == 1){
                        ajouterComposant((int)prendreElement(getPositionDuRobot(numRobot)), robot);
                        typePos = 0;
                        printf("Robot%d pris composant %d 2eme nb=%d\n", numRobot,composantSurAnneau,countNbComposant(robot));
                    }
                }
            }else if(typePos == 50 && isRobotNeedToGiveProduit(robot) == 0){
                produit* produitSurAnneau = (produit*)getPointeur(getPositionDuRobot(numRobot));
                if(isProduitNextOpCanBeDone(produitSurAnneau, robot) == 1){
                    robot->produit = prendreElement(getPositionDuRobot(numRobot));
                    pthread_mutex_lock(&mutex_anneau);
                    nbElementQuiAccedeAnneau--;
                    pthread_cond_signal(&cond_anneauAttenteAcces);
                    pthread_mutex_unlock(&mutex_anneau);
                    printf("Robot%d procede OpSuivante\n", numRobot);
                    procederOpSuivanteDuProduit(robot);
                    continue;
                }
            }
            if(typePos == 0){
                if(isRobotNeedToGiveProduit(robot) == 1){
                    procederRemiseDuProduitSurAnneau(getPositionDuRobot(numRobot), robot);
                    printf("Robot%d produit remis\n", numRobot);
                }
            }
        }
        if(robot->produit != ((void *)0)){
            printf("Robot%d stocke un produit%d\n",numRobot,robot->produit->numProduit);
            if(isRobotNeedToGiveProduit(robot)){
                printf("Et a besoin de donner produit / %d\n", nbElementDansBuffer);
                printAnneau();
            }
        }
        printf("Robot%d fin boucle et mode %d\n", numRobot, robot->mode);
        pthread_mutex_lock(&mutex_anneau);
        nbElementQuiAccedeAnneau--;
        pthread_cond_signal(&cond_anneauAttenteAcces);
        pthread_mutex_unlock(&mutex_anneau);
    }
    if(robot->produit != ((void *)0))
        free(robot->produit);
    printf("Thread robot%d terminer\n", numRobot);
}

canonical_original_code:
void th_robot(void *arg[]){
    struct _robot *robot = arg[1];
    int numRobot = (int)arg[0];
    while(robot->continuer == 1){
        pthread_mutex_lock(&mutex_anneau);
        pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
        nbElementQuiAccedeAnneau++;
        int nbCompo = countNbComposant(robot);
        int numProdACreer = 0;
            numProdACreer = hasEnoughComposantToDoProd(nbCompo, robot->composant[0]);
        if(nbCompo > 0 && numProdACreer > 0 && isRobotNeedToGiveProduit(robot) == 0){
            nbElementQuiAccedeAnneau--;
            pthread_cond_signal(&cond_anneauAttenteAcces);
            pthread_mutex_unlock(&mutex_anneau);
            printf("Robot%d procede creation produit\n", numRobot);
            procederALaCreationDuProduit(numProdACreer, robot);
            continue;
        }else{
            pthread_mutex_unlock(&mutex_anneau);
            int typePos = getPositionType(getPositionDuRobot(numRobot));
            if(typePos == 51){
                int composantSurAnneau = (int)getPointeur(getPositionDuRobot(numRobot));
                if(isRobotAlreadyHaveComposant(robot) == 1){
                    if(composantSurAnneau == robot->composant[0] && isRobotFullOfComposant(robot) == 0){
                        ajouterComposant((int)prendreElement(getPositionDuRobot(numRobot)), robot);
                        typePos = 0;
                        printf("Robot%d pris composant %d 1er nb=%d\n", numRobot,composantSurAnneau,countNbComposant(robot));
                    }
                }else{
                    if(isRobotFullOfComposant(robot) == 0 && isComposantUsefulToBeTaken(composantSurAnneau,robot) == 1){
                        ajouterComposant((int)prendreElement(getPositionDuRobot(numRobot)), robot);
                        typePos = 0;
                        printf("Robot%d pris composant %d 2eme nb=%d\n", numRobot,composantSurAnneau,countNbComposant(robot));
                    }
                }
            }else if(typePos == 50 && isRobotNeedToGiveProduit(robot) == 0){
                struct _produit *produitSurAnneau = (produit*)getPointeur(getPositionDuRobot(numRobot));
                if(isProduitNextOpCanBeDone(produitSurAnneau, robot) == 1){
                    robot->produit = prendreElement(getPositionDuRobot(numRobot));
                    pthread_mutex_lock(&mutex_anneau);
                    nbElementQuiAccedeAnneau--;
                    pthread_cond_signal(&cond_anneauAttenteAcces);
                    pthread_mutex_unlock(&mutex_anneau);
                    printf("Robot%d procede OpSuivante\n", numRobot);
                    procederOpSuivanteDuProduit(robot);
                    continue;
                }
            }
            if(typePos == 0){
                if(isRobotNeedToGiveProduit(robot) == 1){
                    procederRemiseDuProduitSurAnneau(getPositionDuRobot(numRobot), robot);
                    printf("Robot%d produit remis\n", numRobot);
                }
            }
        }
        if(robot->produit != ((void *)0)){
            printf("Robot%d stocke un produit%d\n",numRobot,robot->produit->numProduit);
            if(isRobotNeedToGiveProduit(robot)){
                printf("Et a besoin de donner produit / %d\n", nbElementDansBuffer);
                printAnneau();
            }
        }
        printf("Robot%d fin boucle et mode %d\n", numRobot, robot->mode);
        pthread_mutex_lock(&mutex_anneau);
        nbElementQuiAccedeAnneau--;
        pthread_cond_signal(&cond_anneauAttenteAcces);
        pthread_mutex_unlock(&mutex_anneau);
    }
    if(robot->produit != ((void *)0))
        free(robot->produit);
    printf("Thread robot%d terminer\n", numRobot);
}

variable_types: numRobot int

variable_types: nbCompo int

variable_types: numProdACreer int

variable_types: typePos int

variable_types: composantSurAnneau int


initSortieProduit

decompiled_code:
__int64 initSortieProduit()
{
__int64 result; // rax

result = initBuf(&produitsSortis, 2LL);
nbProduitSortie = 0;
continuerSortie = 1;
return result;
}

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

result = initBuf(&produitsSortis, 2LL);
nbProduitSortie = 0;
continuerSortie = 1;
return result;
}

original_code:
void initSortieProduit(){
    initBuf(&produitsSortis, 2);
    nbProduitSortie = 0;
    continuerSortie = 1;
}


decompiled_code:
int th_verifSortieProduit()
{
unsigned int *v1; // rbx
void *v2; // rax

while ( continuerSortie == 1 )
{
pthread_mutex_lock(&mutex_anneau);
pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
++nbElementQuiAccedeAnneau;
pthread_mutex_unlock(&mutex_anneau);
if ( (unsigned int)getPositionType(3LL) == 50 )
{
v1 = (unsigned int *)getPointeur(3LL);
if ( (unsigned int)isProduitDone(v1) )
{
printf("Un produit a ete sortie Prod%d et total =%d\n", *v1, (unsigned int)nbProduitSortie);
v2 = (void *)prendreElement(3LL);
free(v2);
++nbProduitSortie;
}
else
{
printf("Produit non sortie Prod%d\n", *v1);
}
}
else
{
puts("Produit non sortie car s'en n'est pas un :)");
}
pthread_mutex_lock(&mutex_anneau);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
}
return puts("Thread verif Sortie produits terminer");
}

canonical_decompiled_code:
int func1()
{
unsigned int *v1; // rbx
void *v2; // rax

while ( continuerSortie == 1 )
{
pthread_mutex_lock(&mutex_anneau);
pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
++nbElementQuiAccedeAnneau;
pthread_mutex_unlock(&mutex_anneau);
if ( (unsigned int)getPositionType(3LL) == 50 )
{
v1 = (unsigned int *)getPointeur(3LL);
if ( (unsigned int)isProduitDone(v1) )
{
printf("Un produit a ete sortie Prod%d et total =%d\n", *v1, (unsigned int)nbProduitSortie);
v2 = (void *)prendreElement(3LL);
free(v2);
++nbProduitSortie;
}
else
{
printf("Produit non sortie Prod%d\n", *v1);
}
}
else
{
puts("Produit non sortie car s'en n'est pas un :)");
}
pthread_mutex_lock(&mutex_anneau);
--nbElementQuiAccedeAnneau;
pthread_cond_signal(&cond_anneauAttenteAcces);
pthread_mutex_unlock(&mutex_anneau);
}
return puts("Thread verif Sortie produits terminer");
}

original_code:
void th_verifSortieProduit(){
    while(continuerSortie == 1){
        pthread_mutex_lock(&mutex_anneau);
        pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
        nbElementQuiAccedeAnneau++;
        pthread_mutex_unlock(&mutex_anneau);
        if(getPositionType(3) == 50){
            produit* prod = (produit*)getPointeur(3);
            if(isProduitDone(prod)){
                printf("Un produit a ete sortie Prod%d et total =%d\n",prod->numProduit, nbProduitSortie);
                free(prendreElement(3));
                nbProduitSortie++;
            }else
                printf("Produit non sortie Prod%d\n",prod->numProduit);
        }else
            printf("Produit non sortie car s'en n'est pas un :)\n");
        pthread_mutex_lock(&mutex_anneau);
        nbElementQuiAccedeAnneau--;
        pthread_cond_signal(&cond_anneauAttenteAcces);
        pthread_mutex_unlock(&mutex_anneau);
    }
    printf("Thread verif Sortie produits terminer\n");
}

canonical_original_code:
void th_verifSortieProduit(){
    while(continuerSortie == 1){
        pthread_mutex_lock(&mutex_anneau);
        pthread_cond_wait(&cond_anneauATourner, &mutex_anneau);
        nbElementQuiAccedeAnneau++;
        pthread_mutex_unlock(&mutex_anneau);
        if(getPositionType(3) == 50){
            struct _produit *prod = (produit*)getPointeur(3);
            if(isProduitDone(prod)){
                printf("Un produit a ete sortie Prod%d et total =%d\n",prod->numProduit, nbProduitSortie);
                free(prendreElement(3));
                nbProduitSortie++;
            }else
                printf("Produit non sortie Prod%d\n",prod->numProduit);
        }else
            printf("Produit non sortie car s'en n'est pas un :)\n");
        pthread_mutex_lock(&mutex_anneau);
        nbElementQuiAccedeAnneau--;
        pthread_cond_signal(&cond_anneauAttenteAcces);
        pthread_mutex_unlock(&mutex_anneau);
    }
    printf("Thread verif Sortie produits terminer\n");
}


decompiled_code:
_BOOL8 __fastcall isProduitT0Done(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return *(_DWORD *)(a1 + 4) == 0;
}

original_code:
int isProduitT0Done(const produit *prod){
    if(prod->nbCNecessaire == 0)
        return 1;
    return 0;
}

canonical_original_code:
int isProduitT0Done(struct _produit *prod){
    if(prod->nbCNecessaire == 0)
        return 1;
    return 0;
}


isProduitDone

decompiled_code:
__int64 __fastcall isProduitDone(__int64 a1)
{
return isEmpty(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return isEmpty(a1 + 16);
}

original_code:
int isProduitDone(const produit *prod){
    return isEmpty(&(prod->listeDesOperationRequired));
}

canonical_original_code:
int isProduitDone(struct _produit *prod){
    return isEmpty(&(prod->listeDesOperationRequired));
}


popNextOp

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

if ( (unsigned int)isProduitDone(a1) )
result = 0xFFFFFFFFLL;
else
result = pop(a1 + 16);
return result;
}

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

if ( (unsigned int)func1(a1) )
result = 0xFFFFFFFFLL;
else
result = pop(a1 + 16);
return result;
}

original_code:
int popNextOp(produit *prod){
    if(isProduitDone(prod) == 0){
        return pop(&(prod->listeDesOperationRequired));
    }
    return -1;
}

canonical_original_code:
int popNextOp(struct _produit *prod){
    if(isProduitDone(prod) == 0){
        return pop(&(prod->listeDesOperationRequired));
    }
    return -1;
}


getNextOp

decompiled_code:
__int64 __fastcall getNextOp(__int64 a1)
{
return getSommetValue(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return getSommetValue(a1 + 16);
}

original_code:
int getNextOp(produit *prod){
    return getSommetValue(&(prod->listeDesOperationRequired));
}

canonical_original_code:
int getNextOp(struct _produit *prod){
    return getSommetValue(&(prod->listeDesOperationRequired));
}


sleeper

decompiled_code:
int __fastcall sleeper(float a1)
{
int v1; // eax

v1 = rand();
return usleep(1000 * (int)(float)((float)((float)v1 * a1) * 4.6566129e-10));
}

canonical_decompiled_code:
int __fastcall func0(float a1)
{
int v1; // eax

v1 = rand();
return usleep(1000 * (int)(float)((float)((float)v1 * a1) * 4.6566129e-10));
}

original_code:
void sleeper(float waitMs){
 waitMs = (float)rand() * waitMs / (float)2147483647;
 usleep((int)waitMs * 1000);
}

variable_types: waitMs float


producer

decompiled_code:
void __fastcall __noreturn producer(void *ptr)
{
__int64 v1; // rbp
_QWORD *v2; // rbx
int sval; // [rsp+8h] [rbp-30h] BYREF
int v4[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( *(_DWORD *)ptr < *((_DWORD *)ptr + 1) )
{
v1 = *(int *)ptr;
do
{
v2 = (_QWORD *)node_new();
*v2 = v1;
sem_wait(&empty);
list_add(buffer, v2);
sem_post(&full);
sleeper(*(float *)&SLEEP_TIME_MS);
sem_getvalue(&full, &sval);
sem_getvalue(&empty, v4);
printf(
"producer %i made item %i, full: %i, empty: %i\n",
(unsigned int)(*(_DWORD *)ptr / producerLoad),
(unsigned int)*v2,
(unsigned int)sval,
(unsigned int)v4[0]);
++v1;
}
while ( *((_DWORD *)ptr + 1) > (int)v1 );
}
free(ptr);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *ptr)
{
__int64 v1; // rbp
_QWORD *v2; // rbx
int sval; // [rsp+8h] [rbp-30h] BYREF
int v4[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( *(_DWORD *)ptr < *((_DWORD *)ptr + 1) )
{
v1 = *(int *)ptr;
do
{
v2 = (_QWORD *)node_new();
*v2 = v1;
sem_wait(&empty);
list_add(buffer, v2);
sem_post(&full);
func0(*(float *)&SLEEP_TIME_MS);
sem_getvalue(&full, &sval);
sem_getvalue(&empty, v4);
printf(
"producer %i made item %i, full: %i, empty: %i\n",
(unsigned int)(*(_DWORD *)ptr / producerLoad),
(unsigned int)*v2,
(unsigned int)sval,
(unsigned int)v4[0]);
++v1;
}
while ( *((_DWORD *)ptr + 1) > (int)v1 );
}
free(ptr);
pthread_exit(0LL);
}

original_code:
void *producer(void *params){
 struct runpars* pars = (struct runpars*) params;
 int i;
 for(i = pars->start; i < pars->end; i++){
  Node *n = node_new();
  n->elm = (void*) i;
  sem_wait(&empty);
  list_add(buffer, n);
  sem_post(&full);
  sleeper(SLEEP_TIME_MS);
  int fullC,emptyC;
  sem_getvalue(&full,&fullC);
  sem_getvalue(&empty,&emptyC);
  printf("producer %i made item %i, full: %i, empty: %i\n", pars->start/producerLoad, (int) n->elm, fullC, emptyC);
 }
 free(pars);
 pthread_exit(0);
}

canonical_original_code:
void *producer(void *params){
 struct runpars *pars = (struct runpars*) params;
 int i;
 for(i = pars->start; i < pars->end; i++){
  struct node *n = node_new();
  n->elm = (void *) i;
  sem_wait(&empty);
  list_add(buffer, n);
  sem_post(&full);
  sleeper(SLEEP_TIME_MS);
  int fullC; int emptyC;
  sem_getvalue(&full,&fullC);
  sem_getvalue(&empty,&emptyC);
  printf("producer %i made item %i, full: %i, empty: %i\n", pars->start/producerLoad, (int) n->elm, fullC, emptyC);
 }
 free(pars);
 pthread_exit(0);
}

variable_types:
params
void *

variable_types: struct runpars { int start; int end; } *

variable_types: struct node { void *elm; struct node *next; } *

variable_types: fullC int

variable_types: emptyC int

return_type: void *


consumer

decompiled_code:
void __fastcall __noreturn consumer(void *ptr)
{
int i; // ebp
_QWORD *v2; // rbx
int sval; // [rsp+8h] [rbp-20h] BYREF
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = *(_DWORD *)ptr; *((_DWORD *)ptr + 1) > i; ++i )
{
sem_wait(&full);
v2 = (_QWORD *)list_remove(buffer);
sem_post(&empty);
sleeper(*(float *)&SLEEP_TIME_MS);
sem_getvalue(&full, &sval);
sem_getvalue(&empty, v4);
printf("consumer ate item %i, full: %i, empty: %i\n", *v2, (unsigned int)sval, (unsigned int)v4[0]);
}
free(ptr);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *ptr)
{
int i; // ebp
_QWORD *v2; // rbx
int sval; // [rsp+8h] [rbp-20h] BYREF
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = *(_DWORD *)ptr; *((_DWORD *)ptr + 1) > i; ++i )
{
sem_wait(&full);
v2 = (_QWORD *)list_remove(buffer);
sem_post(&empty);
func0(*(float *)&SLEEP_TIME_MS);
sem_getvalue(&full, &sval);
sem_getvalue(&empty, v4);
printf("consumer ate item %i, full: %i, empty: %i\n", *v2, (unsigned int)sval, (unsigned int)v4[0]);
}
free(ptr);
pthread_exit(0LL);
}

original_code:
void *consumer(void *params){
 struct runpars* pars = (struct runpars*) params;
 int i;
 for(i = pars->start; i < pars->end; i++){
  sem_wait(&full);
  Node *n = list_remove(buffer);
  sem_post(&empty);
  sleeper(SLEEP_TIME_MS);
  int fullC,emptyC;
  sem_getvalue(&full,&fullC);
  sem_getvalue(&empty,&emptyC);
  printf("consumer ate item %i, full: %i, empty: %i\n", (int) n->elm, fullC, emptyC);
 }
 free(pars);
 pthread_exit(0);
}

canonical_original_code:
void *consumer(void *params){
 struct runpars *pars = (struct runpars*) params;
 int i;
 for(i = pars->start; i < pars->end; i++){
  sem_wait(&full);
  struct node *n = list_remove(buffer);
  sem_post(&empty);
  sleeper(SLEEP_TIME_MS);
  int fullC; int emptyC;
  sem_getvalue(&full,&fullC);
  sem_getvalue(&empty,&emptyC);
  printf("consumer ate item %i, full: %i, empty: %i\n", (int) n->elm, fullC, emptyC);
 }
 free(pars);
 pthread_exit(0);
}

user_defined_types: struct node { void *elm; struct node *next; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // ebp
int v8; // er12
unsigned int v9; // er13
int v10; // eax
__int64 v11; // r8
__int64 v12; // r9
__int64 v13; // rax
unsigned int v14; // eax
pthread_t *v15; // rbp
pthread_t *v16; // r12
__int64 v17; // rbx
__int64 v18; // rbx
int result; // eax

setbuf(stdout, 0LL);
if ( argc == 5 )
{
v3 = atoi(argv[1]);
if ( v3 <= 0 )
{
fprintf(stderr, "%d - producers must be > 0\n", (unsigned int)v3);
result = -1;
}
else
{
v4 = atoi(argv[2]);
if ( v4 <= 0 )
{
fprintf(stderr, "%d - consumers must be > 0\n", (unsigned int)v4);
result = -1;
}
else
{
v5 = atoi(argv[3]);
if ( v5 <= 0 )
{
fprintf(stderr, "%d - bufferSize must be > 0\n", (unsigned int)v5);
result = -1;
}
else
{
v6 = atoi(argv[4]);
if ( v6 <= 0 )
{
fprintf(stderr, "%d - products must be > 0\n", (unsigned int)v6);
result = -1;
}
else
{
buffer = list_new();
v7 = atoi(argv[1]);
prodN = v7;
v8 = atoi(argv[2]);
consN = v8;
v9 = atoi(argv[3]);
bufferSize = v9;
v10 = atoi(argv[4]);
v11 = (unsigned int)v10;
productsN = v10;
v12 = (unsigned int)(v10 / v7);
producerLoad = v10 / v7;
v13 = (unsigned int)(v10 / v8);
consumerLoad = v13;
printf(
"Starting! Here are the stats\n"
"prodN: %i\n"
"consN: %i\n"
"buffer: %i\n"
"products: %i\n"
"produderload: %i\n"
"consumerload: %i\n",
(unsigned int)v7,
(unsigned int)v8,
v9,
v11,
v12,
v13);
sem_init(&full, 0, 0);
sem_init(&empty, 0, bufferSize);
v14 = time(0LL);
srand(v14);
v15 = spawnNThreads(consN, consumer);
v16 = spawnNThreads(prodN, producer);
if ( prodN > 0 )
{
v17 = 0LL;
do
pthread_join(v16[v17++], 0LL);
while ( prodN > (int)v17 );
}
if ( consN > 0 )
{
v18 = 0LL;
do
pthread_join(v15[v18++], 0LL);
while ( consN > (int)v18 );
}
free(v16);
free(v15);
result = 0;
}
}
}
}
}
else
{
fwrite("usage: prodcons [procucers] [consumers] [bufferSize] [products]\n", 1uLL, 0x40uLL, stderr);
result = -1;
}
return result;
}

original_code:
int main(int argc, char* argv[]){
 setbuf(stdout,((void *)0));
 if(argc != 5){
  fprintf(stderr, "usage: prodcons [procucers] [consumers] [bufferSize] [products]\n");
  return -1;
 }
 if(atoi(argv[1]) <= 0) {
  fprintf(stderr,"%d - producers must be > 0\n", atoi(argv[1]));
  return -1;
 }
 if(atoi(argv[2]) <= 0) {
  fprintf(stderr,"%d - consumers must be > 0\n", atoi(argv[2]));
  return -1;
 }
 if(atoi(argv[3]) <= 0) {
  fprintf(stderr,"%d - bufferSize must be > 0\n", atoi(argv[3]));
  return -1;
 }
 if(atoi(argv[4]) <= 0) {
  fprintf(stderr,"%d - products must be > 0\n", atoi(argv[4]));
  return -1;
 }
 buffer = list_new();
 prodN = atoi(argv[1]);
 consN = atoi(argv[2]);
 bufferSize = atoi(argv[3]);
 productsN = atoi(argv[4]);
 producerLoad = productsN / prodN;
 consumerLoad = productsN / consN;
 printf("Starting! Here are the stats\n"
   "prodN: %i\n"
   "consN: %i\n"
   "buffer: %i\n"
   "products: %i\n"
   "produderload: %i\n"
   "consumerload: %i\n",
   prodN, consN, bufferSize, productsN, producerLoad, consumerLoad);
 sem_init(&full, 0, 0);
 sem_init(&empty, 0, bufferSize);
 srand(time(((void *)0)));
 pthread_t *consIds = spawnNThreads(consN, consumer);
 pthread_t *prodIds = spawnNThreads(prodN, producer);
 int i;
 for(i=0; i<prodN; i++){
  pthread_join(prodIds[i], ((void *)0));
 }
 for(i=0; i<consN; i++){
  pthread_join(consIds[i], ((void *)0));
 }
 free(prodIds);
 free(consIds);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 setbuf(stdout,((void *)0));
 if(argc != 5){
  fprintf(stderr, "usage: prodcons [procucers] [consumers] [bufferSize] [products]\n");
  return -1;
 }
 if(atoi(argv[1]) <= 0) {
  fprintf(stderr,"%d - producers must be > 0\n", atoi(argv[1]));
  return -1;
 }
 if(atoi(argv[2]) <= 0) {
  fprintf(stderr,"%d - consumers must be > 0\n", atoi(argv[2]));
  return -1;
 }
 if(atoi(argv[3]) <= 0) {
  fprintf(stderr,"%d - bufferSize must be > 0\n", atoi(argv[3]));
  return -1;
 }
 if(atoi(argv[4]) <= 0) {
  fprintf(stderr,"%d - products must be > 0\n", atoi(argv[4]));
  return -1;
 }
 buffer = list_new();
 prodN = atoi(argv[1]);
 consN = atoi(argv[2]);
 bufferSize = atoi(argv[3]);
 productsN = atoi(argv[4]);
 producerLoad = productsN / prodN;
 consumerLoad = productsN / consN;
 printf("Starting! Here are the stats\n"
   "prodN: %i\n"
   "consN: %i\n"
   "buffer: %i\n"
   "products: %i\n"
   "produderload: %i\n"
   "consumerload: %i\n",
   prodN, consN, bufferSize, productsN, producerLoad, consumerLoad);
 sem_init(&full, 0, 0);
 sem_init(&empty, 0, bufferSize);
 srand(time(((void *)0)));
 unsigned long *consIds = spawnNThreads(consN, consumer);
 unsigned long *prodIds = spawnNThreads(prodN, producer);
 int i;
 for(i=0; i<prodN; i++){
  pthread_join(prodIds[i], ((void *)0));
 }
 for(i=0; i<consN; i++){
  pthread_join(consIds[i], ((void *)0));
 }
 free(prodIds);
 free(consIds);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
consIds
unsigned long *

variable_types:
prodIds
unsigned long *


printavail

decompiled_code:
int printavail()
{
__int64 v0; // rbx

printf("Avaialble: [");
if ( n > 0 )
{
v0 = 0LL;
do
printf("%i,", *(unsigned int *)(*(_QWORD *)(s + 8) + 4 * v0++));
while ( n > (int)v0 );
}
return puts("]");
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbx

printf("Avaialble: [");
if ( n > 0 )
{
v0 = 0LL;
do
printf("%i,", *(unsigned int *)(*(_QWORD *)(s + 8) + 4 * v0++));
while ( n > (int)v0 );
}
return puts("]");
}

original_code:
void printavail(){
  printf("Avaialble: [");
  int i;
  for(i=0; i<n; i++){
    printf("%i,", s->available[i]);
  }
  puts("]");
}

variable_types: i int


Sleep

decompiled_code:
int __fastcall Sleep(float a1)
{
int v1; // eax

v1 = rand();
return usleep((int)(float)((float)((float)((float)v1 * a1) * 4.6566129e-10) * 1000.0));
}

canonical_decompiled_code:
int __fastcall func8(float a1)
{
int v1; // eax

v1 = rand();
return usleep((int)(float)((float)((float)((float)v1 * a1) * 4.6566129e-10) * 1000.0));
}

original_code:
void Sleep(float wait_time_ms)
{
  wait_time_ms = ((float)rand())*wait_time_ms / (float)2147483647;
  usleep((int) (wait_time_ms * 1e3f));
}


arrayLE

decompiled_code:
__int64 __fastcall arrayLE(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

if ( a3 <= 0 )
return 1LL;
v3 = 0LL;
while ( *(_DWORD *)(a1 + 4 * v3) <= *(_DWORD *)(a2 + 4 * v3) )
{
if ( ++v3 == a3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

if ( a3 <= 0 )
return 1LL;
v3 = 0LL;
while ( *(_DWORD *)(a1 + 4 * v3) <= *(_DWORD *)(a2 + 4 * v3) )
{
if ( ++v3 == a3 )
return 1LL;
}
return 0LL;
}

original_code:
int arrayLE(int* a, int* b, int len)
{
  int i;
  for(i=0; i<len; i++){
    if(a[i] > b[i]){
      return 0;
    }
  }
  return 1;
}

canonical_original_code:
int arrayLE(int *a, int *b, int len)
{
  int i;
  for(i=0; i<len; i++){
    if(a[i] > b[i]){
      return 0;
    }
  }
  return 1;
}

variable_types:
a
int *

variable_types:
b
int *

variable_types: len int


original_code:
int resource_request(int pi, int *request)
{
  if(!arrayLE(request, s->available, n))
    return 0;
  int work[n];
  int finish[m];
  int tmpNeed[n];
  int i;
  for(i=0;i<m;i++){
    finish[i]=0;
  }
  for(i=0;i<n;i++){
    work[i]=s->available[i] - request[i];
  }
  for(i=0;i<n;i++){
    tmpNeed[i]=s->need[pi][i] - request[i];
  }
  int k=0;
  while(1){
    while(!(!finish[k] && arrayLE(tmpNeed, work, n)) && k<m){
      k++;
    }
    if(!(!finish[k] && arrayLE(tmpNeed, work, n))){
      break;
    }
    for(i=0; i<n; i++){
      work[i] = work[i] + s->allocation[pi][k] + request[i];
    }
    finish[k]=1;
  }
  k=1;
  for(i=0; i<m; i++){
    if (!finish[i])
      k=0;
    break;
  }
  if(k){
    pthread_mutex_lock(&mutex);
    for(i=0; i<n; i++){
      s->allocation[pi][i] = s->allocation[pi][i] + request[i];
      s->available[i] = s->available[i] - request[i];
      s->need[pi][i] = s->need[pi][i] - request[i];
    }
    printavail();
    pthread_mutex_unlock(&mutex);
  }
  return k;
}

canonical_original_code:
int resource_request(int pi, int *request)
{
  if(!arrayLE(request, s->available, n))
    return 0;
  int work[-1];
  int finish[-1];
  int tmpNeed[-1];
  int i;
  for(i=0;i<m;i++){
    finish[i]=0;
  }
  for(i=0;i<n;i++){
    work[i]=s->available[i] - request[i];
  }
  for(i=0;i<n;i++){
    tmpNeed[i]=s->need[pi][i] - request[i];
  }
  int k = 0;
  while(1){
    while(!(!finish[k] && arrayLE(tmpNeed, work, n)) && k<m){
      k++;
    }
    if(!(!finish[k] && arrayLE(tmpNeed, work, n))){
      break;
    }
    for(i=0; i<n; i++){
      work[i] = work[i] + s->allocation[pi][k] + request[i];
    }
    finish[k]=1;
  }
  k=1;
  for(i=0; i<m; i++){
    if (!finish[i])
      k=0;
    break;
  }
  if(k){
    pthread_mutex_lock(&mutex);
    for(i=0; i<n; i++){
      s->allocation[pi][i] = s->allocation[pi][i] + request[i];
      s->available[i] = s->available[i] - request[i];
      s->need[pi][i] = s->need[pi][i] - request[i];
    }
    printavail();
    pthread_mutex_unlock(&mutex);
  }
  return k;
}

variable_types: pi int

variable_types:
request
int *

variable_types:
work
int [-1]

variable_types:
finish
int [-1]

variable_types:
tmpNeed
int [-1]

variable_types: k int


decompiled_code:
int __fastcall resource_release(int a1, __int64 a2)
{
__int64 v2; // rax
_DWORD *v3; // rcx
_DWORD *v4; // rdx

pthread_mutex_lock(&mutex);
if ( n > 0 )
{
v2 = 0LL;
do
{
*(_DWORD *)(*(_QWORD *)(s + 8) + 4 * v2) += *(_DWORD *)(a2 + 4 * v2);
v3 = (_DWORD *)(*(_QWORD *)(*(_QWORD *)(s + 24) + 8LL * a1) + 4 * v2);
*v3 -= *(_DWORD *)(a2 + 4 * v2);
v4 = (_DWORD *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8LL * a1) + 4 * v2);
*v4 += *(_DWORD *)(a2 + 4 * v2++);
}
while ( n > (int)v2 );
}
return pthread_mutex_unlock(&mutex);
}

original_code:
void resource_release(int i, int *request)
{
  int j;
  pthread_mutex_lock(&mutex);
  for(j=0; j<n; j++){
    s->available[j] = s->available[j] + request[j];
    s->allocation[i][j] = s->allocation[i][j] - request[j];
    s->need[i][j] = s->need[i][j] + request[j];
  }
  pthread_mutex_unlock(&mutex);
}

variable_types: j int


decompiled_code:
int __fastcall generate_request(unsigned int a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp
double v4; // xmm0_8
double v6; // [rsp+8h] [rbp-30h]

do
{
do
{
v2 = 0LL;
v3 = 0;
}
while ( n <= 0 );
do
{
v6 = (double)*(int *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8LL * (int)a1) + 4 * v2);
v4 = (double)rand() * v6 / 2147483647.0;
*(_DWORD *)(a2 + 4 * v2) = (int)v4;
v3 += (int)v4;
++v2;
}
while ( n > (int)v2 );
}
while ( !v3 );
return printf("Process %d: Requesting resources.\n", a1);
}

canonical_decompiled_code:
int __fastcall func12(unsigned int a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp
double v4; // xmm0_8
double v6; // [rsp+8h] [rbp-30h]

do
{
do
{
v2 = 0LL;
v3 = 0;
}
while ( n <= 0 );
do
{
v6 = (double)*(int *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8LL * (int)a1) + 4 * v2);
v4 = (double)rand() * v6 / 2147483647.0;
*(_DWORD *)(a2 + 4 * v2) = (int)v4;
v3 += (int)v4;
++v2;
}
while ( n > (int)v2 );
}
while ( !v3 );
return printf("Process %d: Requesting resources.\n", a1);
}

original_code:
void generate_request(int i, int *request)
{
  int j, sum = 0;
  while (!sum) {
    for (j = 0;j < n; j++) {
      request[j] = s->need[i][j] * ((double)rand())/ (double)2147483647;
      sum += request[j];
    }
  }
  printf("Process %d: Requesting resources.\n",i);
}

canonical_original_code:
void generate_request(int i, int *request)
{
  int j; int sum = 0;
  while (!sum) {
    for (j = 0;j < n; j++) {
      request[j] = s->need[i][j] * ((double)rand())/ (double)2147483647;
      sum += request[j];
    }
  }
  printf("Process %d: Requesting resources.\n",i);
}

variable_types: sum int


decompiled_code:
int __fastcall generate_release(unsigned int a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp
double v4; // xmm0_8
double v6; // [rsp+8h] [rbp-30h]

do
{
do
{
v2 = 0LL;
v3 = 0;
}
while ( n <= 0 );
do
{
v6 = (double)*(int *)(*(_QWORD *)(*(_QWORD *)(s + 24) + 8LL * (int)a1) + 4 * v2);
v4 = (double)rand() * v6 / 2147483647.0;
*(_DWORD *)(a2 + 4 * v2) = (int)v4;
v3 += (int)v4;
++v2;
}
while ( n > (int)v2 );
}
while ( !v3 );
return printf("Process %d: Releasing resources.\n", a1);
}

canonical_decompiled_code:
int __fastcall func13(unsigned int a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp
double v4; // xmm0_8
double v6; // [rsp+8h] [rbp-30h]

do
{
do
{
v2 = 0LL;
v3 = 0;
}
while ( n <= 0 );
do
{
v6 = (double)*(int *)(*(_QWORD *)(*(_QWORD *)(s + 24) + 8LL * (int)a1) + 4 * v2);
v4 = (double)rand() * v6 / 2147483647.0;
*(_DWORD *)(a2 + 4 * v2) = (int)v4;
v3 += (int)v4;
++v2;
}
while ( n > (int)v2 );
}
while ( !v3 );
return printf("Process %d: Releasing resources.\n", a1);
}

original_code:
void generate_release(int i, int *request)
{
  int j, sum = 0;
  while (!sum) {
    for (j = 0;j < n; j++) {
      request[j] = s->allocation[i][j] * ((double)rand())/ (double)2147483647;
      sum += request[j];
    }
  }
  printf("Process %d: Releasing resources.\n",i);
}

canonical_original_code:
void generate_release(int i, int *request)
{
  int j; int sum = 0;
  while (!sum) {
    for (j = 0;j < n; j++) {
      request[j] = s->allocation[i][j] * ((double)rand())/ (double)2147483647;
      sum += request[j];
    }
  }
  printf("Process %d: Releasing resources.\n",i);
}


decompiled_code:
void __fastcall __noreturn process_thread(void *a1)
{
void *v1; // rbx

v1 = malloc(4LL * n);
while ( 1 )
{
generate_request((unsigned int)a1, (__int64)v1);
while ( !(unsigned int)resource_request((int)a1, (__int64)v1) )
Sleep(100.0);
generate_release((unsigned int)a1, (__int64)v1);
resource_release((int)a1, (__int64)v1);
Sleep(1000.0);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func14(void *a1)
{
void *v1; // rbx

v1 = malloc(4LL * n);
while ( 1 )
{
func12((unsigned int)a1, (__int64)v1);
while ( !(unsigned int)func10((int)a1, (__int64)v1) )
func8(100.0);
func13((unsigned int)a1, (__int64)v1);
func11((int)a1, (__int64)v1);
func8(1000.0);
}
}

original_code:
void *process_thread(void *param)
{
  int i = (int) (long) param, j;
  int *request = malloc(n*sizeof(int));
  while (1) {
    generate_request(i, request);
    while (!resource_request(i, request)) {
      Sleep(100);
    }
    generate_release(i, request);
    resource_release(i, request);
    Sleep(1000);
  }
  free(request);
}

canonical_original_code:
void *process_thread(void *param)
{
  int i = (int) (long) param; int j;
  int *request = malloc(n*sizeof(int));
  while (1) {
    generate_request(i, request);
    while (!resource_request(i, request)) {
      Sleep(100);
    }
    generate_release(i, request);
    resource_release(i, request);
    Sleep(1000);
  }
  free(request);
}

variable_types:
param
void *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // r12
signed __int64 v4; // rax
void *v5; // rsp
void *v6; // rsp
signed __int64 v7; // rax
void *v8; // rsp
void *v9; // rsp
void *v10; // rsp
__int64 v11; // rbx
__int64 v12; // rbx
__int64 i; // r13
__int64 k; // r13
__int64 m; // r9
__int64 v16; // rsi
int ii; // er8
int v18; // ebx
__int64 jj; // r13
int v20; // ebx
__int64 v21; // rbx
void *v22; // rsp
_DWORD *v23; // rax
_DWORD *v24; // rdx
int v25; // ebx
int v26; // ebx
pthread_t *v27; // rax
pthread_t *v28; // r12
char *v29; // rbx
__int64 j; // rbx
__int64 l; // rbx
__int64 n; // rax
_QWORD *v33; // rax
__int64 v34; // rdi
int v35; // edx
__int64 kk; // rbx
_DWORD v37[2]; // [rsp+0h] [rbp-90h] BYREF
_DWORD *v38; // [rsp+8h] [rbp-88h]
_DWORD *v39; // [rsp+10h] [rbp-80h]
__int64 v40; // [rsp+18h] [rbp-78h]
struct timeval tv; // [rsp+20h] [rbp-70h] BYREF
__int64 v42[12]; // [rsp+30h] [rbp-60h] BYREF

pthread_mutex_init(&mutex, 0LL);
printf("Number of processes: ");
__isoc99_scanf();
printf("Number of resources: ");
__isoc99_scanf();
v3 = 4LL * ::n;
v4 = 16 * ((v3 + 15) / 0x10);
v5 = alloca(v4);
v39 = v37;
v6 = alloca(v4);
v38 = v37;
v7 = 16 * ((8LL * ::m + 15) / 0x10uLL);
v8 = alloca(v7);
v9 = alloca(v7);
v10 = alloca(v7);
if ( ::m > 0 )
{
v40 = (unsigned int)::m;
v11 = 0LL;
do
{
*(_QWORD *)&v37[2 * v11] = malloc(v3);
*(_QWORD *)&v37[2 * v11] = malloc(v3);
*(_QWORD *)&v37[2 * v11++] = malloc(v3);
}
while ( v11 != v40 );
}
v42[0] = (__int64)v39;
v42[1] = (__int64)v38;
v42[2] = (__int64)v37;
v42[3] = (__int64)v37;
v42[4] = (__int64)v37;
s = (__int64)v42;
printf("Resource vector: ");
if ( ::n > 0 )
{
v12 = 0LL;
do
{
__isoc99_scanf();
++v12;
}
while ( ::n > (int)v12 );
}
printf("Enter max matrix: ");
for ( i = 0LL; ::m > (int)i; ++i )
{
for ( j = 0LL; ::n > (int)j; ++j )
__isoc99_scanf();
}
printf("Enter allocation matrix: ");
for ( k = 0LL; ::m > (int)k; ++k )
{
for ( l = 0LL; ::n > (int)l; ++l )
__isoc99_scanf();
}
putchar(10);
for ( m = 0LL; ::m > (int)m; ++m )
{
for ( n = 0LL; ::n > (int)n; ++n )
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8 * m) + 4 * n) = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(s + 16) + 8 * m)
+ 4 * n)
- *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(s + 24) + 8 * m)
+ 4 * n);
}
v16 = 0LL;
for ( ii = 0; ::n > ii; v16 += 4LL )
{
if ( ::m > 0 )
{
v33 = *(_QWORD **)(s + 24);
v34 = (__int64)&v33[(unsigned int)(::m - 1) + 1];
v35 = 0;
do
v35 += *(_DWORD *)(*v33++ + v16);
while ( v33 != (_QWORD *)v34 );
}
else
{
v35 = 0;
}
*(_DWORD *)(*(_QWORD *)(s + 8) + v16) = *(_DWORD *)(*(_QWORD *)s + v16) - v35;
++ii;
}
puts("Need matrix:");
if ( ::n > 0 )
{
v18 = 0;
do
printf("R%d ", (unsigned int)++v18);
while ( v18 < ::n );
}
putchar(10);
for ( jj = 0LL; ::m > (int)jj; ++jj )
{
for ( kk = 0LL; ::n > (int)kk; ++kk )
printf("%d ", *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8 * jj) + 4 * kk));
putchar(10);
}
puts("Availability vector:");
if ( ::n > 0 )
{
v20 = 0;
do
printf("R%d ", (unsigned int)++v20);
while ( v20 < ::n );
}
putchar(10);
if ( ::n > 0 )
{
v21 = 0LL;
do
printf("%d ", *(unsigned int *)(*(_QWORD *)(s + 8) + 4 * v21++));
while ( ::n > (int)v21 );
}
putchar(10);
v22 = alloca(4LL * ::n);
if ( ::n > 0 )
{
v23 = v37;
v24 = &v37[::n];
do
*v23++ = 0;
while ( v24 != v23 );
}
if ( ::m > 0 )
{
v25 = 0;
do
resource_request(v25++, (__int64)v37);
while ( ::m > v25 );
}
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
v26 = ::m;
v27 = (pthread_t *)malloc(8LL * ::m);
if ( v26 > 0 )
{
v28 = v27;
v29 = 0LL;
do
pthread_create(v28++, 0LL, (void *(*)(void *))process_thread, v29++);
while ( ::m > (int)v29 );
}
pthread_exit(0LL);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
size_t v3; // r12
signed __int64 v4; // rax
void *v5; // rsp
void *v6; // rsp
signed __int64 v7; // rax
void *v8; // rsp
void *v9; // rsp
void *v10; // rsp
__int64 v11; // rbx
__int64 v12; // rbx
__int64 i; // r13
__int64 k; // r13
__int64 m; // r9
__int64 v16; // rsi
int ii; // er8
int v18; // ebx
__int64 jj; // r13
int v20; // ebx
__int64 v21; // rbx
void *v22; // rsp
_DWORD *v23; // rax
_DWORD *v24; // rdx
int v25; // ebx
int v26; // ebx
pthread_t *v27; // rax
pthread_t *v28; // r12
char *v29; // rbx
__int64 j; // rbx
__int64 l; // rbx
__int64 n; // rax
_QWORD *v33; // rax
__int64 v34; // rdi
int v35; // edx
__int64 kk; // rbx
_DWORD v37[2]; // [rsp+0h] [rbp-90h] BYREF
_DWORD *v38; // [rsp+8h] [rbp-88h]
_DWORD *v39; // [rsp+10h] [rbp-80h]
__int64 v40; // [rsp+18h] [rbp-78h]
struct timeval tv; // [rsp+20h] [rbp-70h] BYREF
__int64 v42[12]; // [rsp+30h] [rbp-60h] BYREF

pthread_mutex_init(&mutex, 0LL);
printf("Number of processes: ");
__isoc99_scanf();
printf("Number of resources: ");
__isoc99_scanf();
v3 = 4LL * ::n;
v4 = 16 * ((v3 + 15) / 0x10);
v5 = alloca(v4);
v39 = v37;
v6 = alloca(v4);
v38 = v37;
v7 = 16 * ((8LL * ::m + 15) / 0x10uLL);
v8 = alloca(v7);
v9 = alloca(v7);
v10 = alloca(v7);
if ( ::m > 0 )
{
v40 = (unsigned int)::m;
v11 = 0LL;
do
{
*(_QWORD *)&v37[2 * v11] = malloc(v3);
*(_QWORD *)&v37[2 * v11] = malloc(v3);
*(_QWORD *)&v37[2 * v11++] = malloc(v3);
}
while ( v11 != v40 );
}
v42[0] = (__int64)v39;
v42[1] = (__int64)v38;
v42[2] = (__int64)v37;
v42[3] = (__int64)v37;
v42[4] = (__int64)v37;
s = (__int64)v42;
printf("Resource vector: ");
if ( ::n > 0 )
{
v12 = 0LL;
do
{
__isoc99_scanf();
++v12;
}
while ( ::n > (int)v12 );
}
printf("Enter max matrix: ");
for ( i = 0LL; ::m > (int)i; ++i )
{
for ( j = 0LL; ::n > (int)j; ++j )
__isoc99_scanf();
}
printf("Enter allocation matrix: ");
for ( k = 0LL; ::m > (int)k; ++k )
{
for ( l = 0LL; ::n > (int)l; ++l )
__isoc99_scanf();
}
putchar(10);
for ( m = 0LL; ::m > (int)m; ++m )
{
for ( n = 0LL; ::n > (int)n; ++n )
*(_DWORD *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8 * m) + 4 * n) = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(s + 16) + 8 * m)
+ 4 * n)
- *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(s + 24) + 8 * m)
+ 4 * n);
}
v16 = 0LL;
for ( ii = 0; ::n > ii; v16 += 4LL )
{
if ( ::m > 0 )
{
v33 = *(_QWORD **)(s + 24);
v34 = (__int64)&v33[(unsigned int)(::m - 1) + 1];
v35 = 0;
do
v35 += *(_DWORD *)(*v33++ + v16);
while ( v33 != (_QWORD *)v34 );
}
else
{
v35 = 0;
}
*(_DWORD *)(*(_QWORD *)(s + 8) + v16) = *(_DWORD *)(*(_QWORD *)s + v16) - v35;
++ii;
}
puts("Need matrix:");
if ( ::n > 0 )
{
v18 = 0;
do
printf("R%d ", (unsigned int)++v18);
while ( v18 < ::n );
}
putchar(10);
for ( jj = 0LL; ::m > (int)jj; ++jj )
{
for ( kk = 0LL; ::n > (int)kk; ++kk )
printf("%d ", *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(s + 32) + 8 * jj) + 4 * kk));
putchar(10);
}
puts("Availability vector:");
if ( ::n > 0 )
{
v20 = 0;
do
printf("R%d ", (unsigned int)++v20);
while ( v20 < ::n );
}
putchar(10);
if ( ::n > 0 )
{
v21 = 0LL;
do
printf("%d ", *(unsigned int *)(*(_QWORD *)(s + 8) + 4 * v21++));
while ( ::n > (int)v21 );
}
putchar(10);
v22 = alloca(4LL * ::n);
if ( ::n > 0 )
{
v23 = v37;
v24 = &v37[::n];
do
*v23++ = 0;
while ( v24 != v23 );
}
if ( ::m > 0 )
{
v25 = 0;
do
func10(v25++, (__int64)v37);
while ( ::m > v25 );
}
gettimeofday(&tv, 0LL);
srand(tv.tv_usec);
v26 = ::m;
v27 = (pthread_t *)malloc(8LL * ::m);
if ( v26 > 0 )
{
v28 = v27;
v29 = 0LL;
do
pthread_create(v28++, 0LL, (void *(*)(void *))process_thread, v29++);
while ( ::m > (int)v29 );
}
pthread_exit(0LL);
}

original_code:
int main(int argc, char* argv[])
{
  pthread_mutex_init(&mutex, ((void *)0));
  int i, j;
  printf("Number of processes: ");
  scanf("%d", &m);
  printf("Number of resources: ");
  scanf("%d", &n);
  int res[n];
  int avail[n];
  int **max[m];
  int **alloc[m];
  int **need[m];
  for(i=0; i<m;i++){
    max[i] = malloc(sizeof(int)*n);
    alloc[i] = malloc(sizeof(int)*n);
    need[i] = malloc(sizeof(int)*n);
  }
  State p = (State)
  {
    .resource = (int*) res,
    .available = (int*) avail,
    .max = (int**) max,
    .allocation = (int**) alloc,
    .need = (int**) need
  };
  s = &p;
  printf("Resource vector: ");
  for(i = 0; i < n; i++)
    scanf("%d", &s->resource[i]);
  printf("Enter max matrix: ");
  for(i = 0;i < m; i++)
    for(j = 0;j < n; j++){
      scanf("%d", &s->max[i][j]);
    }
  printf("Enter allocation matrix: ");
  for(i = 0; i < m; i++)
    for(j = 0; j < n; j++) {
      scanf("%d", &s->allocation[i][j]);
    }
  printf("\n");
  for(i = 0; i < m; i++)
    for(j = 0; j < n; j++)
      s->need[i][j] = s->max[i][j] - s->allocation[i][j];
  for(j = 0; j < n; j++) {
    int sum = 0;
    for(i = 0; i < m; i++)
      sum += s->allocation[i][j];
    s->available[j] = s->resource[j] - sum;
  }
  printf("Need matrix:\n");
  for(i = 0; i < n; i++)
    printf("R%d ", i+1);
  printf("\n");
  for(i = 0; i < m; i++) {
    for(j = 0; j < n; j++)
      printf("%d  ",s->need[i][j]);
    printf("\n");
  }
  printf("Availability vector:\n");
  for(i = 0; i < n; i++)
    printf("R%d ", i+1);
  printf("\n");
  for(j = 0; j < n; j++)
    printf("%d  ",s->available[j]);
  printf("\n");
  int req[n];
  for(i=0; i<n; i++)
    req[i]=0;
  for(i=0; i<m; i++)
    if (!resource_request(i, req))
      exit -1;
  struct timeval tv;
  gettimeofday(&tv, ((void *)0));
  srand(tv.tv_usec);
  pthread_t *tid = malloc(m*sizeof(pthread_t));
  for (i = 0; i < m; i++)
    pthread_create(&tid[i], ((void *)0), process_thread, (void *) (long) i);
  pthread_exit(0);
  free(tid);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  pthread_mutex_init(&mutex, ((void *)0));
  int i; int j;
  printf("Number of processes: ");
  scanf("%d", &m);
  printf("Number of resources: ");
  scanf("%d", &n);
  int res[-1];
  int avail[-1];
  int **max[-1];
  int **alloc[-1];
  int **need[-1];
  for(i=0; i<m;i++){
    max[i] = malloc(sizeof(int)*n);
    alloc[i] = malloc(sizeof(int)*n);
    need[i] = malloc(sizeof(int)*n);
  }
  struct state p = (State)
  {
    .resource = (int*) res,
    .available = (int*) avail,
    .max = (int**) max,
    .allocation = (int**) alloc,
    .need = (int**) need
  };
  s = &p;
  printf("Resource vector: ");
  for(i = 0; i < n; i++)
    scanf("%d", &s->resource[i]);
  printf("Enter max matrix: ");
  for(i = 0;i < m; i++)
    for(j = 0;j < n; j++){
      scanf("%d", &s->max[i][j]);
    }
  printf("Enter allocation matrix: ");
  for(i = 0; i < m; i++)
    for(j = 0; j < n; j++) {
      scanf("%d", &s->allocation[i][j]);
    }
  printf("\n");
  for(i = 0; i < m; i++)
    for(j = 0; j < n; j++)
      s->need[i][j] = s->max[i][j] - s->allocation[i][j];
  for(j = 0; j < n; j++) {
    int sum = 0;
    for(i = 0; i < m; i++)
      sum += s->allocation[i][j];
    s->available[j] = s->resource[j] - sum;
  }
  printf("Need matrix:\n");
  for(i = 0; i < n; i++)
    printf("R%d ", i+1);
  printf("\n");
  for(i = 0; i < m; i++) {
    for(j = 0; j < n; j++)
      printf("%d  ",s->need[i][j]);
    printf("\n");
  }
  printf("Availability vector:\n");
  for(i = 0; i < n; i++)
    printf("R%d ", i+1);
  printf("\n");
  for(j = 0; j < n; j++)
    printf("%d  ",s->available[j]);
  printf("\n");
  int req[-1];
  for(i=0; i<n; i++)
    req[i]=0;
  for(i=0; i<m; i++)
    if (!resource_request(i, req))
      exit -1;
  struct timeval tv;
  gettimeofday(&tv, ((void *)0));
  srand(tv.tv_usec);
  unsigned long *tid = malloc(m*sizeof(pthread_t));
  for (i = 0; i < m; i++)
    pthread_create(&tid[i], ((void *)0), process_thread, (void *) (long) i);
  pthread_exit(0);
  free(tid);
}

variable_types: argc int

variable_types:
res
int [-1]

variable_types:
avail
int [-1]

variable_types:
max
int **[-1]

variable_types:
alloc
int **[-1]

variable_types:
need
int **[-1]

variable_types: struct state { int *resource; int *available; int **max; int **allocation; int **need; }

variable_types:
req
int [-1]

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

variable_types:
tid
unsigned long *


acmd

original_code:
int acmd (char *s, Cmd **cmd)
{
  char *tok;
  int n, cnt = 0;
  Cmd *cmd0 = cmds;
  cmds = cmds->next;
  cmd0->next = ((void *)0);
  cmd0->cmd = pp;
  while (1) {
    n = nexttoken(s, &tok);
    if (n == 0 || (((*tok) == ('|')) || ((*tok) == ('&')) || ((*tok) == ('<')) || ((*tok) == ('>'))))
      {
 *cmd = cmd0;
 *pp++ = ((void *)0);
 return cnt;
      }
    else
      {
 *pp++ = tok;
 cnt += n;
 s += n;
      }
  }
}

canonical_original_code:
int acmd(char *s, struct _cmd **cmd)
{
  char *tok;
  int n; int cnt = 0;
  struct _cmd *cmd0 = cmds;
  cmds = cmds->next;
  cmd0->next = ((void *)0);
  cmd0->cmd = pp;
  while (1) {
    n = nexttoken(s, &tok);
    if (n == 0 || (((*tok) == ('|')) || ((*tok) == ('&')) || ((*tok) == ('<')) || ((*tok) == ('>'))))
      {
 *cmd = cmd0;
 *pp++ = ((void *)0);
 return cnt;
      }
    else
      {
 *pp++ = tok;
 cnt += n;
 s += n;
      }
  }
}

variable_types:
s
char *

variable_types: struct _cmd { char **cmd; struct _cmd *next; } **

variable_types:
tok
char *

variable_types: n int

variable_types: cnt int


isidentifier

decompiled_code:
__int64 __fastcall isidentifier(char *a1)
{
char v2; // bl
char *v3; // rbp

while ( 1 )
{
v2 = *a1;
if ( !*a1 )
break;
v3 = strrchr("_-.,/~+", v2);
++a1;
if ( ((*_ctype_b_loc())[v2] & 8) == 0 && !v3 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1)
{
char v2; // bl
char *v3; // rbp

while ( 1 )
{
v2 = *a1;
if ( !*a1 )
break;
v3 = strrchr("_-.,/~+", v2);
++a1;
if ( ((*_ctype_b_loc())[v2] & 8) == 0 && !v3 )
return 0LL;
}
return 1LL;
}

original_code:
int isidentifier (char *s)
{
  while (*s)
    {
      char *p = strrchr ("_-.,/~+", *s);
      if (! ((*__ctype_b_loc ())[(int) ((*s++))] & (unsigned short int) _ISalnum) && (p == ((void *)0)))
 return 0;
    }
  return 1;
}

canonical_original_code:
int isidentifier(char *s)
{
  while (*s)
    {
      char *p = strrchr ("_-.,/~+", *s);
      if (! ((*__ctype_b_loc ())[(int) ((*s++))] & (unsigned short) _ISalnum) && (p == ((void *)0)))
 return 0;
    }
  return 1;
}

variable_types:
p
char *