arrive

decompiled_code:
int __fastcall arrive(__int64 a1, __int64 a2, const char *a3)
{
if ( (_BYTE)a1 == 115 )
{
pthread_mutex_lock(&southM);
while ( scurr )
pthread_cond_wait(&southQ, &southM);
scurr = 1;
a3 = "South";
}
else if ( (char)a1 > 115 )
{
if ( (_BYTE)a1 == 119 )
{
pthread_mutex_lock(&westM);
while ( wcurr )
pthread_cond_wait(&westQ, &westM);
wcurr = 1;
a3 = "West";
}
}
else if ( (_BYTE)a1 == 101 )
{
pthread_mutex_lock(&eastM);
while ( ecurr )
pthread_cond_wait(&eastQ, &eastM);
ecurr = 1;
a3 = "East";
}
else if ( (_BYTE)a1 == 110 )
{
pthread_mutex_lock(&northM);
while ( ncurr )
pthread_cond_wait(&northQ, &northM);
ncurr = 1;
a3 = "North";
}
return printf("CART %d from %s arrives at crossing\n", a1 >> 32, a3);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2, const char *a3)
{
if ( (_BYTE)a1 == 115 )
{
pthread_mutex_lock(&southM);
while ( scurr )
pthread_cond_wait(&southQ, &southM);
scurr = 1;
a3 = "South";
}
else if ( (char)a1 > 115 )
{
if ( (_BYTE)a1 == 119 )
{
pthread_mutex_lock(&westM);
while ( wcurr )
pthread_cond_wait(&westQ, &westM);
wcurr = 1;
a3 = "West";
}
}
else if ( (_BYTE)a1 == 101 )
{
pthread_mutex_lock(&eastM);
while ( ecurr )
pthread_cond_wait(&eastQ, &eastM);
ecurr = 1;
a3 = "East";
}
else if ( (_BYTE)a1 == 110 )
{
pthread_mutex_lock(&northM);
while ( ncurr )
pthread_cond_wait(&northQ, &northM);
ncurr = 1;
a3 = "North";
}
return printf("CART %d from %s arrives at crossing\n", a1 >> 32, a3);
}

original_code:
void arrive(train c){
    char* direction;
    switch(c.direction){
        case 'n':
            direction="North";
            pthread_mutex_lock(&northM);
            while(ncurr != 0){pthread_cond_wait(&northQ,&northM);}
            ncurr = 1;
            break;
        case 'e':
            direction="East";
            pthread_mutex_lock(&eastM);
            while(ecurr != 0){pthread_cond_wait(&eastQ,&eastM);}
            ecurr = 1;
            break;
        case 's':
            direction="South";
            pthread_mutex_lock(&southM);
            while(scurr != 0){pthread_cond_wait(&southQ,&southM);}
            scurr = 1;
            break;
        case 'w':
            direction="West";
            pthread_mutex_lock(&westM);
            while (wcurr != 0){pthread_cond_wait(&westQ,&westM);}
            wcurr = 1;
            break;
        default:
            break;
    }
    printf("CART %d from %s arrives at crossing\n",c.trainID,direction);
}

canonical_original_code:
void arrive(struct train c){
    char *direction;
    switch(c.direction){
        case 'n':
            direction="North";
            pthread_mutex_lock(&northM);
            while(ncurr != 0){pthread_cond_wait(&northQ,&northM);}
            ncurr = 1;
            break;
        case 'e':
            direction="East";
            pthread_mutex_lock(&eastM);
            while(ecurr != 0){pthread_cond_wait(&eastQ,&eastM);}
            ecurr = 1;
            break;
        case 's':
            direction="South";
            pthread_mutex_lock(&southM);
            while(scurr != 0){pthread_cond_wait(&southQ,&southM);}
            scurr = 1;
            break;
        case 'w':
            direction="West";
            pthread_mutex_lock(&westM);
            while (wcurr != 0){pthread_cond_wait(&westQ,&westM);}
            wcurr = 1;
            break;
        default:
            break;
    }
    printf("CART %d from %s arrives at crossing\n",c.trainID,direction);
}

variable_types: struct train { char direction; int trainID; }


cross

repo: tseale/deadlocks

decompiled_code:
int __fastcall cross(__int64 a1)
{
const char *v1; // r12

pthread_mutex_lock(&intersection);
if ( (_BYTE)a1 == 115 )
{
while ( ecurr == 1 && !sdead && sstall != 2 || estall == 2 || wstall == 2 || nstall == 2 )
pthread_cond_wait(&southC, &intersection);
if ( sstall == 2 )
printf("STARVATION AVERTED: %s\n", "South");
scurr = 0;
sdead = 0;
sleep(1u);
sstall = 0;
pthread_cond_signal(&westC);
pthread_cond_signal(&southQ);
if ( wcurr == 1 )
++wstall;
v1 = "South";
pthread_mutex_unlock(&southM);
}
else if ( (char)a1 > 115 )
{
if ( (_BYTE)a1 == 119 )
{
while ( scurr == 1 && !wdead && wstall != 2 || estall == 2 || nstall == 2 || sstall == 2 )
pthread_cond_wait(&westC, &intersection);
if ( wstall == 2 )
printf("STARVATION AVERTED: %s\n", "West");
wcurr = 0;
wdead = 0;
sleep(1u);
wstall = 0;
pthread_cond_signal(&northC);
pthread_cond_signal(&westQ);
if ( ncurr == 1 )
++nstall;
v1 = "West";
pthread_mutex_unlock(&westM);
}
}
else if ( (_BYTE)a1 == 101 )
{
while ( ncurr == 1 && !edead && estall != 2 || nstall == 2 || wstall == 2 || sstall == 2 )
pthread_cond_wait(&eastC, &intersection);
if ( estall == 2 )
printf("STARVATION AVERTED: %s\n", "East");
ecurr = 0;
edead = 0;
sleep(1u);
estall = 0;
pthread_cond_signal(&southC);
pthread_cond_signal(&eastQ);
if ( scurr == 1 )
++sstall;
v1 = "East";
pthread_mutex_unlock(&eastM);
}
else if ( (_BYTE)a1 == 110 )
{
while ( wcurr == 1 && !ndead && nstall != 2 || estall == 2 || wstall == 2 || sstall == 2 )
pthread_cond_wait(&northC, &intersection);
if ( nstall == 2 )
printf("STARVATION AVERTED: %s\n", "North");
ncurr = 0;
ndead = 0;
sleep(1u);
nstall = 0;
pthread_cond_signal(&eastC);
pthread_cond_signal(&northQ);
if ( ecurr == 1 )
++estall;
v1 = "North";
pthread_mutex_unlock(&northM);
}
printf("CART %d from %s leaving crossing\n", a1 >> 32, v1);
return pthread_mutex_unlock(&intersection);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
const char *v1; // r12

pthread_mutex_lock(&intersection);
if ( (_BYTE)a1 == 115 )
{
while ( ecurr == 1 && !sdead && sstall != 2 || estall == 2 || wstall == 2 || nstall == 2 )
pthread_cond_wait(&southC, &intersection);
if ( sstall == 2 )
printf("STARVATION AVERTED: %s\n", "South");
scurr = 0;
sdead = 0;
sleep(1u);
sstall = 0;
pthread_cond_signal(&westC);
pthread_cond_signal(&southQ);
if ( wcurr == 1 )
++wstall;
v1 = "South";
pthread_mutex_unlock(&southM);
}
else if ( (char)a1 > 115 )
{
if ( (_BYTE)a1 == 119 )
{
while ( scurr == 1 && !wdead && wstall != 2 || estall == 2 || nstall == 2 || sstall == 2 )
pthread_cond_wait(&westC, &intersection);
if ( wstall == 2 )
printf("STARVATION AVERTED: %s\n", "West");
wcurr = 0;
wdead = 0;
sleep(1u);
wstall = 0;
pthread_cond_signal(&northC);
pthread_cond_signal(&westQ);
if ( ncurr == 1 )
++nstall;
v1 = "West";
pthread_mutex_unlock(&westM);
}
}
else if ( (_BYTE)a1 == 101 )
{
while ( ncurr == 1 && !edead && estall != 2 || nstall == 2 || wstall == 2 || sstall == 2 )
pthread_cond_wait(&eastC, &intersection);
if ( estall == 2 )
printf("STARVATION AVERTED: %s\n", "East");
ecurr = 0;
edead = 0;
sleep(1u);
estall = 0;
pthread_cond_signal(&southC);
pthread_cond_signal(&eastQ);
if ( scurr == 1 )
++sstall;
v1 = "East";
pthread_mutex_unlock(&eastM);
}
else if ( (_BYTE)a1 == 110 )
{
while ( wcurr == 1 && !ndead && nstall != 2 || estall == 2 || wstall == 2 || sstall == 2 )
pthread_cond_wait(&northC, &intersection);
if ( nstall == 2 )
printf("STARVATION AVERTED: %s\n", "North");
ncurr = 0;
ndead = 0;
sleep(1u);
nstall = 0;
pthread_cond_signal(&eastC);
pthread_cond_signal(&northQ);
if ( ecurr == 1 )
++estall;
v1 = "North";
pthread_mutex_unlock(&northM);
}
printf("CART %d from %s leaving crossing\n", a1 >> 32, v1);
return pthread_mutex_unlock(&intersection);
}

original_code:
void cross(train c){
    pthread_mutex_lock(&intersection);
    char* direction;
    switch(c.direction){
        case 'n':
            direction="North";
            while ((wcurr == 1 && ndead == 0 && nstall != 2) || estall == 2 || wstall == 2 || sstall ==2 ){
                pthread_cond_wait(&northC,&intersection);
            }
            if (nstall==2){printf("STARVATION AVERTED: %s\n",direction);}
            ncurr = 0; ndead=0;
            sleep(1);
            nstall=0;
            pthread_cond_signal(&eastC);
            pthread_cond_signal(&northQ);
            if(ecurr == 1){estall++;}
            pthread_mutex_unlock(&northM);
            break;
        case 'e':
            direction="East";
            while ((ncurr == 1 && edead == 0 && estall != 2)|| nstall == 2 || wstall == 2 || sstall ==2){
                pthread_cond_wait(&eastC,&intersection);
            }
            if (estall==2){printf("STARVATION AVERTED: %s\n",direction);}
            ecurr = 0; edead=0;
            sleep(1);
            estall = 0;
            pthread_cond_signal(&southC);
            pthread_cond_signal(&eastQ);
            if(scurr == 1){sstall++;}
            pthread_mutex_unlock(&eastM);
            break;
        case 's':
            direction="South";
            while ((ecurr == 1 && sdead == 0 && sstall != 2)|| estall == 2 || wstall == 2 || nstall ==2){
                pthread_cond_wait(&southC,&intersection);
            }
            if (sstall==2){printf("STARVATION AVERTED: %s\n",direction);}
            scurr = 0; sdead=0;
            sleep(1);
            sstall=0;
            pthread_cond_signal(&westC);
            pthread_cond_signal(&southQ);
            if(wcurr == 1){wstall++;}
            pthread_mutex_unlock(&southM);
            break;
        case 'w':
            direction="West";
            while ((scurr == 1 && wdead == 0 && wstall != 2)|| estall == 2 || nstall == 2 || sstall ==2){
                pthread_cond_wait(&westC,&intersection);
            }
            if (wstall==2){printf("STARVATION AVERTED: %s\n",direction);}
            wcurr = 0; wdead=0;
            sleep(1);
            wstall=0;
            pthread_cond_signal(&northC);
            pthread_cond_signal(&westQ);
            if(ncurr ==1){nstall++;}
            pthread_mutex_unlock(&westM);
            break;
        default:
            break;
    }
    printf("CART %d from %s leaving crossing\n",c.trainID,direction);
 pthread_mutex_unlock(&intersection);
}

canonical_original_code:
void cross(struct train c){
    pthread_mutex_lock(&intersection);
    char *direction;
    switch(c.direction){
        case 'n':
            direction="North";
            while ((wcurr == 1 && ndead == 0 && nstall != 2) || estall == 2 || wstall == 2 || sstall ==2 ){
                pthread_cond_wait(&northC,&intersection);
            }
            if (nstall==2){printf("STARVATION AVERTED: %s\n",direction);}
            ncurr = 0; ndead=0;
            sleep(1);
            nstall=0;
            pthread_cond_signal(&eastC);
            pthread_cond_signal(&northQ);
            if(ecurr == 1){estall++;}
            pthread_mutex_unlock(&northM);
            break;
        case 'e':
            direction="East";
            while ((ncurr == 1 && edead == 0 && estall != 2)|| nstall == 2 || wstall == 2 || sstall ==2){
                pthread_cond_wait(&eastC,&intersection);
            }
            if (estall==2){printf("STARVATION AVERTED: %s\n",direction);}
            ecurr = 0; edead=0;
            sleep(1);
            estall = 0;
            pthread_cond_signal(&southC);
            pthread_cond_signal(&eastQ);
            if(scurr == 1){sstall++;}
            pthread_mutex_unlock(&eastM);
            break;
        case 's':
            direction="South";
            while ((ecurr == 1 && sdead == 0 && sstall != 2)|| estall == 2 || wstall == 2 || nstall ==2){
                pthread_cond_wait(&southC,&intersection);
            }
            if (sstall==2){printf("STARVATION AVERTED: %s\n",direction);}
            scurr = 0; sdead=0;
            sleep(1);
            sstall=0;
            pthread_cond_signal(&westC);
            pthread_cond_signal(&southQ);
            if(wcurr == 1){wstall++;}
            pthread_mutex_unlock(&southM);
            break;
        case 'w':
            direction="West";
            while ((scurr == 1 && wdead == 0 && wstall != 2)|| estall == 2 || nstall == 2 || sstall ==2){
                pthread_cond_wait(&westC,&intersection);
            }
            if (wstall==2){printf("STARVATION AVERTED: %s\n",direction);}
            wcurr = 0; wdead=0;
            sleep(1);
            wstall=0;
            pthread_cond_signal(&northC);
            pthread_cond_signal(&westQ);
            if(ncurr ==1){nstall++;}
            pthread_mutex_unlock(&westM);
            break;
        default:
            break;
    }
    printf("CART %d from %s leaving crossing\n",c.trainID,direction);
 pthread_mutex_unlock(&intersection);
}

variable_types:
direction
char *

return_type: void

user_defined_types: struct train { char direction; int trainID; }


leave

decompiled_code:
int leave()
{
pthread_mutex_lock(&intersection);
--active_carts;
return pthread_mutex_unlock(&intersection);
}

canonical_decompiled_code:
int func9()
{
pthread_mutex_lock(&intersection);
--active_carts;
return pthread_mutex_unlock(&intersection);
}

original_code:
void leave(train c){
    pthread_mutex_lock(&intersection);
    active_carts--;
    pthread_mutex_unlock(&intersection);
}

canonical_original_code:
void leave(struct train c){
    pthread_mutex_lock(&intersection);
    active_carts--;
    pthread_mutex_unlock(&intersection);
}


decompiled_code:
int __fastcall manage_thread(void *a1, __int64 a2, const char *a3)
{
arrive(*(_QWORD *)a1, a2, a3);
cross(*(_QWORD *)a1);
return leave();
}

canonical_decompiled_code:
int __fastcall func10(void *a1, __int64 a2, const char *a3)
{
func7(*(_QWORD *)a1, a2, a3);
func8(*(_QWORD *)a1);
return func9();
}

original_code:
void *manage_thread(void *c){
    train* cart = (train*)c;
    arrive(*cart);
    cross(*cart);
    leave(*cart);
}

canonical_original_code:
void *manage_thread(void *c){
    struct train *cart = (train*)c;
    arrive(*cart);
    cross(*cart);
    leave(*cart);
}

variable_types:
c
void *

variable_types: struct train { char direction; int trainID; } *

return_type: void *


repo: tseesing/spcct

decompiled_code:
__int64 __fastcall nq_container_parent_is_child(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // rbp
__int64 result; // rax
unsigned int *v5; // rbx
unsigned int v6; // edx

v3 = a1 + 48LL * a3;
if ( *(_DWORD *)(v3 + 36) != -1 )
goto LABEL_12;
result = 1LL;
if ( a3 == a2 )
return result;
v5 = *(unsigned int **)(v3 + 24);
if ( !v5 )
{
LABEL_12:
*(_DWORD *)(v3 + 36) = -1;
return 0LL;
}
v6 = *v5;
if ( *v5 != a2 )
{
*(_DWORD *)(v3 + 36) = 90;
while ( *(_DWORD *)(a1 + 48LL * v6 + 36) != -1 || !(unsigned int)nq_container_parent_is_child(a1, a2) )
{
v5 = (unsigned int *)*((_QWORD *)v5 + 1);
if ( !v5 )
goto LABEL_12;
v6 = *v5;
}
*(_DWORD *)(v3 + 36) = -1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // rbp
__int64 result; // rax
unsigned int *v5; // rbx
unsigned int v6; // edx

v3 = a1 + 48LL * a3;
if ( *(_DWORD *)(v3 + 36) != -1 )
goto LABEL_12;
result = 1LL;
if ( a3 == a2 )
return result;
v5 = *(unsigned int **)(v3 + 24);
if ( !v5 )
{
LABEL_12:
*(_DWORD *)(v3 + 36) = -1;
return 0LL;
}
v6 = *v5;
if ( *v5 != a2 )
{
*(_DWORD *)(v3 + 36) = 90;
while ( *(_DWORD *)(a1 + 48LL * v6 + 36) != -1 || !(unsigned int)func0(a1, a2) )
{
v5 = (unsigned int *)*((_QWORD *)v5 + 1);
if ( !v5 )
goto LABEL_12;
v6 = *v5;
}
*(_DWORD *)(v3 + 36) = -1;
result = 1LL;
}
return result;
}

original_code:
static int nq_container_parent_is_child (pkg_dts * pkgtab_p, unsigned int parent_off, unsigned int child_off)
{
    pkg_rs_node * child = pkgtab_p[child_off].child;
    if (pkgtab_p[child_off].first_stack != -1)
    {
        pkgtab_p[child_off].first_stack = -1;
        return 0;
    }
    if ((child_off == parent_off) || (child && (child->data == parent_off)))
    {
        return 1;
    }
    pkgtab_p[child_off].first_stack = 0x5A;
    while(child)
    {
        if ((pkgtab_p[child->data].first_stack == -1 ) && nq_container_parent_is_child (pkgtab_p, parent_off, child->data))
        {
            pkgtab_p[child_off].first_stack = -1;
            return 1;
        }
        child = child->next;
    }
    pkgtab_p[child_off].first_stack = -1;
    return 0;
}

canonical_original_code:
static int nq_container_parent_is_child(struct _pkg_dts *pkgtab_p, unsigned int parent_off, unsigned int child_off)
{
    struct _pkg_rs_node *child = pkgtab_p[child_off].child;
    if (pkgtab_p[child_off].first_stack != -1)
    {
        pkgtab_p[child_off].first_stack = -1;
        return 0;
    }
    if ((child_off == parent_off) || (child && (child->data == parent_off)))
    {
        return 1;
    }
    pkgtab_p[child_off].first_stack = 0x5A;
    while(child)
    {
        if ((pkgtab_p[child->data].first_stack == -1 ) && nq_container_parent_is_child (pkgtab_p, parent_off, child->data))
        {
            pkgtab_p[child_off].first_stack = -1;
            return 1;
        }
        child = child->next;
    }
    pkgtab_p[child_off].first_stack = -1;
    return 0;
}

variable_types: struct _pkg_dts { unsigned char active; char *pkgname; struct _pkg_rs_node { unsigned int data; union { struct _pkg_rs_node *next; struct _pkg_rs_node *prev; }; } *ancestor; struct _pkg_rs_node *child; unsigned int level; int first_stack; int second_stack; } *

return_type: int

user_defined_types: struct _pkg_dts { unsigned char active; char *pkgname; struct _pkg_rs_node *ancestor; struct _pkg_rs_node *child; unsigned int level; int first_stack; int second_stack; }


decompiled_code:
__int64 __fastcall nq_container_first_adjust_level(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
__int64 v4; // rax
unsigned int v5; // edx

v3 = 0;
v4 = a1 + 48LL * a3;
v5 = *(_DWORD *)(a1 + 48LL * a2 + 32) + 1;
if ( *(_DWORD *)(v4 + 32) < v5 )
{
*(_DWORD *)(v4 + 32) = v5;
v3 = v5;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // er8
__int64 v4; // rax
unsigned int v5; // edx

v3 = 0;
v4 = a1 + 48LL * a3;
v5 = *(_DWORD *)(a1 + 48LL * a2 + 32) + 1;
if ( *(_DWORD *)(v4 + 32) < v5 )
{
*(_DWORD *)(v4 + 32) = v5;
v3 = v5;
}
return v3;
}

original_code:
static int nq_container_first_adjust_level(pkg_dts * pkgtab_p, unsigned int new_parent_off,
        unsigned int child_off)
{
    pkg_dts * parent = &pkgtab_p[new_parent_off];
    pkg_dts * child = &pkgtab_p[child_off];
    if (child->level >= parent->level + 1)
        return 0;
    child->level = parent->level + 1;
    return child->level;
}

canonical_original_code:
static int nq_container_first_adjust_level(struct _pkg_dts *pkgtab_p, unsigned int new_parent_off, unsigned int child_off)
{
    struct _pkg_dts *parent = &pkgtab_p[new_parent_off];
    struct _pkg_dts *child = &pkgtab_p[child_off];
    if (child->level >= parent->level + 1)
        return 0;
    child->level = parent->level + 1;
    return child->level;
}

user_defined_types: struct _pkg_rs_node { unsigned int data; union { struct _pkg_rs_node *next; struct _pkg_rs_node *prev; }; }


decompiled_code:
void __fastcall nq_container_pkg_dts_free_rs(_QWORD *a1)
{
_QWORD *v2; // rbx
void *v3; // rdi
_QWORD *v4; // rbx
void *v5; // rdi
void *v6; // rdi

v2 = (_QWORD *)a1[2];
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
v4 = (_QWORD *)a1[3];
a1[2] = 0LL;
while ( v4 )
{
v5 = v4;
v4 = (_QWORD *)v4[1];
free(v5);
}
v6 = (void *)a1[1];
a1[3] = 0LL;
if ( v6 )
free(v6);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
_QWORD *v2; // rbx
void *v3; // rdi
_QWORD *v4; // rbx
void *v5; // rdi
void *v6; // rdi

v2 = (_QWORD *)a1[2];
while ( v2 )
{
v3 = v2;
v2 = (_QWORD *)v2[1];
free(v3);
}
v4 = (_QWORD *)a1[3];
a1[2] = 0LL;
while ( v4 )
{
v5 = v4;
v4 = (_QWORD *)v4[1];
free(v5);
}
v6 = (void *)a1[1];
a1[3] = 0LL;
if ( v6 )
free(v6);
}

original_code:
static void nq_container_pkg_dts_free_rs(pkg_dts *node)
{
    pkg_rs_node *lcl_node;
    pkg_rs_node *lcl_node_f;
    lcl_node = node->ancestor;
    while(lcl_node)
    {
        lcl_node_f = lcl_node->prev;
        free(lcl_node);
        lcl_node = lcl_node_f;
    }
    node->ancestor = ((void *)0);
    lcl_node = node->child;
    while(lcl_node)
    {
        lcl_node_f = lcl_node->next;
        free(lcl_node);
        lcl_node = lcl_node_f;
    }
    node->child = ((void *)0);
    if (node->pkgname)
        free(node->pkgname);
}

canonical_original_code:
static void nq_container_pkg_dts_free_rs(struct _pkg_dts *node)
{
    struct _pkg_rs_node *lcl_node;
    struct _pkg_rs_node *lcl_node_f;
    lcl_node = node->ancestor;
    while(lcl_node)
    {
        lcl_node_f = lcl_node->prev;
        free(lcl_node);
        lcl_node = lcl_node_f;
    }
    node->ancestor = ((void *)0);
    lcl_node = node->child;
    while(lcl_node)
    {
        lcl_node_f = lcl_node->next;
        free(lcl_node);
        lcl_node = lcl_node_f;
    }
    node->child = ((void *)0);
    if (node->pkgname)
        free(node->pkgname);
}

variable_types: struct _pkg_rs_node { unsigned int data; union { struct _pkg_rs_node *next; struct _pkg_rs_node *prev; }; } *


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

v2 = calloc(0x10uLL, 1uLL);
if ( v2 )
{
v3 = *a1;
*(_DWORD *)v2 = a2;
v2[1] = v3;
*a1 = (__int64)v2;
result = 0LL;
}
else
{
nq_errmsg("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, int a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx
__int64 result; // rax

v2 = calloc(0x10uLL, 1uLL);
if ( v2 )
{
v3 = *a1;
*(_DWORD *)v2 = a2;
v2[1] = v3;
*a1 = (__int64)v2;
result = 0LL;
}
else
{
nq_errmsg("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int nq_container_pkg_add_rs (pkg_rs_node ** node, unsigned int index, OPTYPE optype)
{
    pkg_rs_node * lcl_node;
    lcl_node = (pkg_rs_node *)malloc(sizeof(pkg_rs_node));
    if (!lcl_node)
    {
        nq_errmsg("malloc");
        return -1;
    }
    memset(lcl_node, 0, sizeof(pkg_rs_node));
    lcl_node->data = index;
    switch(optype)
    {
        case CHILD:
            lcl_node->next = *node;
            *node = lcl_node;
            break;
        case PARENT:
            lcl_node->prev = *node;
            *node = lcl_node;
            break;
        default:
            nq_errmsg("Unknow OPTYPE: %d", optype);
            free(lcl_node);
            return -1;
    }
    return 0;
}

canonical_original_code:
static int nq_container_pkg_add_rs(struct _pkg_rs_node **node, unsigned int index, enum OPTYPE optype)
{
    struct _pkg_rs_node *lcl_node;
    lcl_node = (struct _pkg_rs_node *)malloc(sizeof(pkg_rs_node));
    if (!lcl_node)
    {
        nq_errmsg("malloc");
        return -1;
    }
    memset(lcl_node, 0, sizeof(pkg_rs_node));
    lcl_node->data = index;
    switch(optype)
    {
        case CHILD:
            lcl_node->next = *node;
            *node = lcl_node;
            break;
        case PARENT:
            lcl_node->prev = *node;
            *node = lcl_node;
            break;
        default:
            nq_errmsg("Unknow OPTYPE: %d", optype);
            free(lcl_node);
            return -1;
    }
    return 0;
}

variable_types: struct _pkg_rs_node { unsigned int data; union { struct _pkg_rs_node *next; struct _pkg_rs_node *prev; }; } **

variable_types:
index
unsigned int

variable_types:
optype
enum OPTYPE { CHILD=0, PARENT=1 }


decompiled_code:
__int64 __fastcall nqstack_push(_DWORD *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rsi

LODWORD(result) = *a1;
if ( *a1 >= a1[1] )
{
nq_errmsg("Stack overflow");
result = 4294967294LL;
}
else
{
v4 = 48LL * a3 + a2;
if ( *(_DWORD *)(v4 + 36) == -1 )
{
*(_DWORD *)(v4 + 36) = result;
a1[(unsigned int)result + 2] = a3;
*a1 = result + 1;
result = (unsigned int)result;
}
else
{
*(_DWORD *)(v4 + 40) = result;
a1[(unsigned int)result + 2] = a3;
*a1 = result + 1;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
__int64 v4; // rsi

LODWORD(result) = *a1;
if ( *a1 >= a1[1] )
{
nq_errmsg("Stack overflow");
result = 4294967294LL;
}
else
{
v4 = 48LL * a3 + a2;
if ( *(_DWORD *)(v4 + 36) == -1 )
{
*(_DWORD *)(v4 + 36) = result;
a1[(unsigned int)result + 2] = a3;
*a1 = result + 1;
result = (unsigned int)result;
}
else
{
*(_DWORD *)(v4 + 40) = result;
a1[(unsigned int)result + 2] = a3;
*a1 = result + 1;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
static int nqstack_push(nqstack * pkgstack_p, pkg_dts * pkgtab_p, unsigned int pkg_off)
{
    int r_val = -2;
    if (pkgstack_p->top >= pkgstack_p->size)
    {
        nq_errmsg("Stack overflow");
        return r_val;
    }
    r_val = pkgstack_p->top;
    if (pkgtab_p[pkg_off].first_stack != -1)
    {
        pkgtab_p[pkg_off].second_stack = r_val;
        r_val = -1;
    }
    else
    {
        pkgtab_p[pkg_off].first_stack = r_val;
    }
    pkgstack_p->stack[pkgstack_p->top] = pkg_off;
    pkgstack_p->top++;
    return r_val;
}

canonical_original_code:
static int nqstack_push(struct _nqstack *pkgstack_p, struct _pkg_dts *pkgtab_p, unsigned int pkg_off)
{
    int r_val = -2;
    if (pkgstack_p->top >= pkgstack_p->size)
    {
        nq_errmsg("Stack overflow");
        return r_val;
    }
    r_val = pkgstack_p->top;
    if (pkgtab_p[pkg_off].first_stack != -1)
    {
        pkgtab_p[pkg_off].second_stack = r_val;
        r_val = -1;
    }
    else
    {
        pkgtab_p[pkg_off].first_stack = r_val;
    }
    pkgstack_p->stack[pkgstack_p->top] = pkg_off;
    pkgstack_p->top++;
    return r_val;
}

variable_types: struct _nqstack { unsigned int top; unsigned int size; unsigned int stack[10000]; } *


decompiled_code:
__int64 __fastcall nqstack_show(_DWORD *a1, __int64 a2)
{
int v4; // er12
int v5; // eax
int v6; // er13
bool v7; // r14
__int64 v8; // rbx
__int64 v9; // rdx
const char *v10; // rsi
const char *v11; // rdi

v4 = a1[*a1 - 1 + 2];
v5 = isatty(1);
v6 = v5;
if ( *a1 == 1 )
{
v8 = 0LL;
}
else
{
v7 = v5 != 0;
LODWORD(v8) = 0;
do
{
while ( 1 )
{
v9 = (unsigned int)a1[(unsigned int)v8 + 2];
v10 = *(const char **)(a2 + 48 * v9 + 8);
if ( v4 != (_DWORD)v9 || !v7 )
break;
v8 = (unsigned int)(v8 + 1);
printf("\x1B[1;31m%s\x1B[0m <- ", v10);
if ( *a1 - 1 <= (unsigned int)v8 )
goto LABEL_7;
}
v8 = (unsigned int)(v8 + 1);
printf("%s <- ", v10);
}
while ( *a1 - 1 > (unsigned int)v8 );
}
LABEL_7:
v11 = "\x1B[1;31m%s\x1B[0m";
if ( !v6 )
v11 = "%s";
return nq_normsg(v11, *(_QWORD *)(a2 + 48LL * (unsigned int)a1[v8 + 2] + 8));
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, __int64 a2)
{
int v4; // er12
int v5; // eax
int v6; // er13
bool v7; // r14
__int64 v8; // rbx
__int64 v9; // rdx
const char *v10; // rsi
const char *v11; // rdi

v4 = a1[*a1 - 1 + 2];
v5 = isatty(1);
v6 = v5;
if ( *a1 == 1 )
{
v8 = 0LL;
}
else
{
v7 = v5 != 0;
LODWORD(v8) = 0;
do
{
while ( 1 )
{
v9 = (unsigned int)a1[(unsigned int)v8 + 2];
v10 = *(const char **)(a2 + 48 * v9 + 8);
if ( v4 != (_DWORD)v9 || !v7 )
break;
v8 = (unsigned int)(v8 + 1);
printf("\x1B[1;31m%s\x1B[0m <- ", v10);
if ( *a1 - 1 <= (unsigned int)v8 )
goto LABEL_7;
}
v8 = (unsigned int)(v8 + 1);
printf("%s <- ", v10);
}
while ( *a1 - 1 > (unsigned int)v8 );
}
LABEL_7:
v11 = "\x1B[1;31m%s\x1B[0m";
if ( !v6 )
v11 = "%s";
return nq_normsg(v11, *(_QWORD *)(a2 + 48LL * (unsigned int)a1[v8 + 2] + 8));
}

original_code:
static void nqstack_show (nqstack * pkgstack_p, pkg_dts * pkgtab_p)
{
    unsigned int istack;
    unsigned int ipkgtab;
    unsigned int dup_item_off;
    int is_stdout;
    dup_item_off = pkgstack_p->stack[pkgstack_p->top - 1];
    is_stdout = isatty(1);
    for (istack = 0; istack < pkgstack_p->top - 1; istack++)
    {
        ipkgtab = pkgstack_p->stack[istack];
        if (is_stdout && (dup_item_off == ipkgtab))
            printf("\e[1;31m%s\e[0m <- ", pkgtab_p[ipkgtab].pkgname);
        else
            printf("%s <- ", pkgtab_p[ipkgtab].pkgname);
    }
    if (is_stdout)
        nq_normsg("\e[1;31m%s\e[0m", pkgtab_p[pkgstack_p->stack[istack]].pkgname);
    else
        nq_normsg("%s", pkgtab_p[pkgstack_p->stack[istack]].pkgname);
}

canonical_original_code:
static void nqstack_show(struct _nqstack *pkgstack_p, struct _pkg_dts *pkgtab_p)
{
    unsigned int istack;
    unsigned int ipkgtab;
    unsigned int dup_item_off;
    int is_stdout;
    dup_item_off = pkgstack_p->stack[pkgstack_p->top - 1];
    is_stdout = isatty(1);
    for (istack = 0; istack < pkgstack_p->top - 1; istack++)
    {
        ipkgtab = pkgstack_p->stack[istack];
        if (is_stdout && (dup_item_off == ipkgtab))
            printf("\e[1;31m%s\e[0m <- ", pkgtab_p[ipkgtab].pkgname);
        else
            printf("%s <- ", pkgtab_p[ipkgtab].pkgname);
    }
    if (is_stdout)
        nq_normsg("\e[1;31m%s\e[0m", pkgtab_p[pkgstack_p->stack[istack]].pkgname);
    else
        nq_normsg("%s", pkgtab_p[pkgstack_p->stack[istack]].pkgname);
}

variable_types:
istack
unsigned int

variable_types:
ipkgtab
unsigned int

user_defined_types: struct _nqstack { unsigned int top; unsigned int size; unsigned int stack[10000]; }


decompiled_code:
__int64 __fastcall nq_traversal_dep_recursion_check(__int64 a1, unsigned int a2, int *a3)
{
unsigned int *v4; // rbx
__int64 result; // rax

v4 = *(unsigned int **)(a1 + 48LL * a2 + 24);
if ( (unsigned int)nqstack_push(a3, a1, a2) == -1 )
{
nqstack_show(a3, a1);
result = nqstack_pop_isra_0(a3, a1);
}
else
{
for ( ; v4; v4 = (unsigned int *)*((_QWORD *)v4 + 1) )
nq_traversal_dep_recursion_check(a1, *v4, a3);
result = nqstack_pop_isra_0(a3, a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, int *a3)
{
unsigned int *v4; // rbx
__int64 result; // rax

v4 = *(unsigned int **)(a1 + 48LL * a2 + 24);
if ( (unsigned int)func0(a3, a1, a2) == -1 )
{
func1(a3, a1);
result = func2(a3, a1);
}
else
{
for ( ; v4; v4 = (unsigned int *)*((_QWORD *)v4 + 1) )
func3(a1, *v4, a3);
result = func2(a3, a1);
}
return result;
}

original_code:
static void nq_traversal_dep_recursion_check(pkg_dts * pkgtab_p, unsigned int root_pkg_off, struct _nqstack * pkgstack_p)
{
    pkg_rs_node * child;
    pkg_dts * root_pkg = &pkgtab_p[root_pkg_off];
    child = root_pkg->child;
    if (nqstack_push (pkgstack_p, pkgtab_p, root_pkg_off) == -1)
    {
        nqstack_show (pkgstack_p, pkgtab_p);
        nqstack_pop (pkgstack_p, pkgtab_p);
        return ;
    }
    while (child)
    {
        nq_traversal_dep_recursion_check(pkgtab_p, child->data, pkgstack_p);
        child = child->next;
    }
    nqstack_pop (pkgstack_p, pkgtab_p);
}

canonical_original_code:
static void nq_traversal_dep_recursion_check(struct _pkg_dts *pkgtab_p, unsigned int root_pkg_off, struct _nqstack *pkgstack_p)
{
    struct _pkg_rs_node *child;
    struct _pkg_dts *root_pkg = &pkgtab_p[root_pkg_off];
    child = root_pkg->child;
    if (nqstack_push (pkgstack_p, pkgtab_p, root_pkg_off) == -1)
    {
        nqstack_show (pkgstack_p, pkgtab_p);
        nqstack_pop (pkgstack_p, pkgtab_p);
        return ;
    }
    while (child)
    {
        nq_traversal_dep_recursion_check(pkgtab_p, child->data, pkgstack_p);
        child = child->next;
    }
    nqstack_pop (pkgstack_p, pkgtab_p);
}


decompiled_code:
void __fastcall nq_traversal_set_get_depend_func(__int64 a1)
{
get_depend_func = a1;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
get_depend_func = a1;
}

original_code:
void nq_traversal_set_get_depend_func(int (* func)(char *, raw_node **))
{
    get_depend_func = func;
}

canonical_original_code:
void nq_traversal_set_get_depend_func(int (*func)(char *, struct _raw_node **))
{
    get_depend_func = func;
}

variable_types: int (*)(char *, struct _raw_node { char *name; struct _raw_node *prev; struct _raw_node *next; } **)


decompiled_code:
__int64 __fastcall nq_traversal_get_pkg_depend(_QWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = get_depend_func(*a1, a1 + 2);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = get_depend_func(*a1, a1 + 2);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int nq_traversal_get_pkg_depend(pkg_node * parent_node)
{
    if (!parent_node)
        return -1;
    return get_depend_func(parent_node->name, &parent_node->child);
}

canonical_original_code:
int nq_traversal_get_pkg_depend(struct _pkg_node *parent_node)
{
    if (!parent_node)
        return -1;
    return get_depend_func(parent_node->name, &parent_node->child);
}

variable_types: struct _pkg_node { char *name; unsigned int con_offset; unsigned int level; struct _raw_node { char *name; struct _raw_node *prev; struct _raw_node *next; } *child; struct _pkg_node *next; struct _pkg_node *prev; } *

user_defined_types: struct _pkg_node { char *name; unsigned int con_offset; unsigned int level; struct _raw_node *child; struct _pkg_node *next; struct _pkg_node *prev; }


decompiled_code:
void *__fastcall pkg_thread_get_rdeps(void *a1)
{
pthread_mutex_t *v1; // r13
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rax
int *v5; // rax
char *v6; // rax
_DWORD v8[14]; // [rsp+0h] [rbp-38h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 96);
while ( 1 )
{
while ( msgrcv(*((_DWORD *)a1 + 8), v8, 4uLL, 0LL, 0) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
nq_errmsg("msgrcv: %s", v6);
}
if ( v8[2] == 1 )
break;
pthread_mutex_lock(v1);
v2 = *((_QWORD *)a1 + 18);
if ( v2 )
{
if ( v2 == *((_QWORD *)a1 + 17) )
{
*((_QWORD *)a1 + 17) = 0LL;
*((_QWORD *)a1 + 18) = 0LL;
}
else
{
v3 = *(_QWORD *)(v2 + 32);
*((_QWORD *)a1 + 18) = v3;
*(_QWORD *)(v3 + 24) = 0LL;
}
pthread_mutex_unlock(v1);
if ( (int)nq_traversal_get_pkg_depend(v2) < 0 )
{
nq_errmsg("get \"%s\" 's dependencies failed", *(const char **)v2);
*(_QWORD *)(v2 + 16) = 0LL;
}
pthread_mutex_lock((pthread_mutex_t *)a1 + 1);
v4 = *((_QWORD *)a1 + 10);
*(_QWORD *)(v2 + 24) = v4;
if ( v4 )
*(_QWORD *)(v4 + 32) = v2;
else
*((_QWORD *)a1 + 11) = v2;
*((_QWORD *)a1 + 10) = v2;
pthread_mutex_unlock((pthread_mutex_t *)a1 + 1);
sem_post((sem_t *)a1);
}
else
{
nq_errmsg("Null raw node ? Something about thread synchronization error had occured!");
pthread_mutex_unlock(v1);
}
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
pthread_mutex_t *v1; // r13
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rax
int *v5; // rax
char *v6; // rax
_DWORD v8[14]; // [rsp+0h] [rbp-38h] BYREF

v1 = (pthread_mutex_t *)((char *)a1 + 96);
while ( 1 )
{
while ( msgrcv(*((_DWORD *)a1 + 8), v8, 4uLL, 0LL, 0) < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
nq_errmsg("msgrcv: %s", v6);
}
if ( v8[2] == 1 )
break;
pthread_mutex_lock(v1);
v2 = *((_QWORD *)a1 + 18);
if ( v2 )
{
if ( v2 == *((_QWORD *)a1 + 17) )
{
*((_QWORD *)a1 + 17) = 0LL;
*((_QWORD *)a1 + 18) = 0LL;
}
else
{
v3 = *(_QWORD *)(v2 + 32);
*((_QWORD *)a1 + 18) = v3;
*(_QWORD *)(v3 + 24) = 0LL;
}
pthread_mutex_unlock(v1);
if ( (int)nq_traversal_get_pkg_depend(v2) < 0 )
{
nq_errmsg("get \"%s\" 's dependencies failed", *(const char **)v2);
*(_QWORD *)(v2 + 16) = 0LL;
}
pthread_mutex_lock((pthread_mutex_t *)a1 + 1);
v4 = *((_QWORD *)a1 + 10);
*(_QWORD *)(v2 + 24) = v4;
if ( v4 )
*(_QWORD *)(v4 + 32) = v2;
else
*((_QWORD *)a1 + 11) = v2;
*((_QWORD *)a1 + 10) = v2;
pthread_mutex_unlock((pthread_mutex_t *)a1 + 1);
sem_post((sem_t *)a1);
}
else
{
nq_errmsg("Null raw node ? Something about thread synchronization error had occured!");
pthread_mutex_unlock(v1);
}
}
return 0LL;
}

original_code:
static void * pkg_thread_get_rdeps (void * data)
{
    int r_val;
    msg_node r_msg;
    pkg_node * raw_node;
    nq_thread_pool * thread_pool;
    thread_pool = (nq_thread_pool *)data;
    while(1)
    {
        if(msgrcv(thread_pool->msgid, &r_msg, sizeof(POOL_CMD), 0, 0) < 0)
        {
            nq_errmsg("msgrcv: %s", strerror((*__errno_location ())));
            continue ;
        }
        if (r_msg.cmd == EXIT)
            break;
        do { } while(0);
        pthread_mutex_lock(&thread_pool->raw_mutex);
        if (thread_pool->raw_rear)
        {
            do { } while(0);
            raw_node = thread_pool->raw_rear;
            if (thread_pool->raw_head == thread_pool->raw_rear)
            {
                thread_pool->raw_head = ((void *)0);
                thread_pool->raw_rear = ((void *)0);
            }
            else
            {
                thread_pool->raw_rear = raw_node->prev;
                thread_pool->raw_rear->next = ((void *)0);
            }
            pthread_mutex_unlock(&thread_pool->raw_mutex);
        }
        else
        {
            nq_errmsg("Null raw node ? Something about thread synchronization error had occured!");
            pthread_mutex_unlock(&thread_pool->raw_mutex);
            continue ;
        }
        r_val = nq_traversal_get_pkg_depend(raw_node);
        if (r_val < 0)
        {
            nq_errmsg("get \"%s\" 's dependencies failed", raw_node->name);
            raw_node->child = ((void *)0);
        }
        pthread_mutex_lock(&thread_pool->pdt_mutex);
        raw_node->next = thread_pool->pdt_head;
        if (thread_pool->pdt_head)
        {
            thread_pool->pdt_head->prev = raw_node;
        }
        else
        {
            thread_pool->pdt_rear = raw_node;
        }
        thread_pool->pdt_head = raw_node;
        pthread_mutex_unlock(&thread_pool->pdt_mutex);
        sem_post(&thread_pool->pdt_sem);
    }
    return ((void *)0);
}

canonical_original_code:
static void *pkg_thread_get_rdeps(void *data)
{
    int r_val;
    struct msg_node_ r_msg;
    struct _pkg_node *raw_node;
    struct nq_thread_pool_ *thread_pool;
    thread_pool = (struct nq_thread_pool_ *)data;
    while(1)
    {
        if(msgrcv(thread_pool->msgid, &r_msg, sizeof(POOL_CMD), 0, 0) < 0)
        {
            nq_errmsg("msgrcv: %s", strerror((*__errno_location ())));
            continue ;
        }
        if (r_msg.cmd == EXIT)
            break;
        do { } while(0);
        pthread_mutex_lock(&thread_pool->raw_mutex);
        if (thread_pool->raw_rear)
        {
            do { } while(0);
            raw_node = thread_pool->raw_rear;
            if (thread_pool->raw_head == thread_pool->raw_rear)
            {
                thread_pool->raw_head = ((void *)0);
                thread_pool->raw_rear = ((void *)0);
            }
            else
            {
                thread_pool->raw_rear = raw_node->prev;
                thread_pool->raw_rear->next = ((void *)0);
            }
            pthread_mutex_unlock(&thread_pool->raw_mutex);
        }
        else
        {
            nq_errmsg("Null raw node ? Something about thread synchronization error had occured!");
            pthread_mutex_unlock(&thread_pool->raw_mutex);
            continue ;
        }
        r_val = nq_traversal_get_pkg_depend(raw_node);
        if (r_val < 0)
        {
            nq_errmsg("get \"%s\" 's dependencies failed", raw_node->name);
            raw_node->child = ((void *)0);
        }
        pthread_mutex_lock(&thread_pool->pdt_mutex);
        raw_node->next = thread_pool->pdt_head;
        if (thread_pool->pdt_head)
        {
            thread_pool->pdt_head->prev = raw_node;
        }
        else
        {
            thread_pool->pdt_rear = raw_node;
        }
        thread_pool->pdt_head = raw_node;
        pthread_mutex_unlock(&thread_pool->pdt_mutex);
        sem_post(&thread_pool->pdt_sem);
    }
    return ((void *)0);
}

variable_types:
data
void *

variable_types: struct msg_node_ { long mtype; enum POOL_CMD { EXIT=1, EXEC=2 } cmd; }

variable_types: struct nq_thread_pool_ { union sem_t { char __size[32]; long __align; } pdt_sem; int msgid; int threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } pdt_mutex; struct _pkg_node { char *name; unsigned int con_offset; unsigned int level; struct _raw_node { char *name; struct _raw_node *prev; struct _raw_node *next; } *child; struct _pkg_node *next; struct _pkg_node *prev; } *pdt_head; struct _pkg_node *pdt_rear; union pthread_mutex_t raw_mutex; struct _pkg_node *raw_head; struct _pkg_node *raw_rear; unsigned long *ptid; } *

user_defined_types: struct msg_node_ { long mtype; enum POOL_CMD cmd; }

user_defined_types: struct nq_thread_pool_ { union sem_t pdt_sem; int msgid; int threads; union pthread_mutex_t pdt_mutex; struct _pkg_node *pdt_head; struct _pkg_node *pdt_rear; union pthread_mutex_t raw_mutex; struct _pkg_node *raw_head; struct _pkg_node *raw_rear; unsigned long *ptid; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
pthread_mutex_t *nq_thread_pool_create()
{
pthread_mutex_t *v0; // rax
pthread_mutex_t *v1; // r12
int v2; // ebp
int v3; // ebx
int v4; // eax
int *v6; // rbx
char *v7; // rax
char *v8; // rax

v0 = (pthread_mutex_t *)calloc(0xF0uLL, 1uLL);
v1 = v0;
if ( !v0 )
return v1;
v2 = 0;
v0[3].__list.__next = (struct __pthread_internal_list *)&v0[4];
v3 = 10;
pthread_mutex_init(v0 + 1, 0LL);
pthread_mutex_init((pthread_mutex_t *)((char *)v1 + 96), 0LL);
sem_init((sem_t *)v1, 0, 0);
v4 = msgget(0, 1920);
*((_DWORD *)&v1->__align + 8) = v4;
if ( v4 >= 0 )
{
do
{
while ( !pthread_create((pthread_t *)v1[3].__list.__next + v2, 0LL, pkg_thread_get_rdeps, v1) )
{
++v2;
if ( !--v3 )
goto LABEL_7;
}
nq_errmsg("pthread_create");
--v3;
}
while ( v3 );
LABEL_7:
*((_DWORD *)&v1->__align + 9) = v2;
return v1;
}
v6 = _errno_location();
v7 = strerror(*v6);
nq_errmsg("msgget: %s", v7);
if ( pthread_mutex_destroy((pthread_mutex_t *)&loc_28) )
nq_errmsg("pthread_mutex_destroy");
if ( pthread_mutex_destroy((pthread_mutex_t *)&loc_60) )
nq_errmsg("pthread_mutex_destroy");
if ( sem_destroy(0LL) < 0 )
{
v8 = strerror(*v6);
nq_errmsg("sem_destroy: %s", v8);
}
free(v1);
return 0LL;
}

canonical_decompiled_code:
pthread_mutex_t *func2()
{
pthread_mutex_t *v0; // rax
pthread_mutex_t *v1; // r12
int v2; // ebp
int v3; // ebx
int v4; // eax
int *v6; // rbx
char *v7; // rax
char *v8; // rax

v0 = (pthread_mutex_t *)calloc(0xF0uLL, 1uLL);
v1 = v0;
if ( !v0 )
return v1;
v2 = 0;
v0[3].__list.__next = (struct __pthread_internal_list *)&v0[4];
v3 = 10;
pthread_mutex_init(v0 + 1, 0LL);
pthread_mutex_init((pthread_mutex_t *)((char *)v1 + 96), 0LL);
sem_init((sem_t *)v1, 0, 0);
v4 = msgget(0, 1920);
*((_DWORD *)&v1->__align + 8) = v4;
if ( v4 >= 0 )
{
do
{
while ( !pthread_create((pthread_t *)v1[3].__list.__next + v2, 0LL, pkg_thread_get_rdeps, v1) )
{
++v2;
if ( !--v3 )
goto LABEL_7;
}
nq_errmsg("pthread_create");
--v3;
}
while ( v3 );
LABEL_7:
*((_DWORD *)&v1->__align + 9) = v2;
return v1;
}
v6 = _errno_location();
v7 = strerror(*v6);
nq_errmsg("msgget: %s", v7);
if ( pthread_mutex_destroy((pthread_mutex_t *)&loc_28) )
nq_errmsg("pthread_mutex_destroy");
if ( pthread_mutex_destroy((pthread_mutex_t *)&loc_60) )
nq_errmsg("pthread_mutex_destroy");
if ( sem_destroy(0LL) < 0 )
{
v8 = strerror(*v6);
nq_errmsg("sem_destroy: %s", v8);
}
free(v1);
return 0LL;
}

original_code:
nq_thread_pool * nq_thread_pool_create ()
{
    do { } while(0);
    nq_thread_pool * r_pool = ((void *)0);
    int loop_cnt;
    void * r_mem_ptr;
    r_mem_ptr = malloc(sizeof(nq_thread_pool) + sizeof(pthread_t) * 10);
    if (!r_mem_ptr)
        return ((void *)0);
    memset(r_mem_ptr, 0, sizeof(nq_thread_pool) + sizeof(pthread_t) * 10);
    r_pool = (nq_thread_pool *)r_mem_ptr;
    r_pool->ptid = (pthread_t *)(r_pool+1);
    pthread_mutex_init(&r_pool->pdt_mutex, ((void *)0));
    pthread_mutex_init(&r_pool->raw_mutex, ((void *)0));
    sem_init(&r_pool->pdt_sem, 0, 0);
    if((r_pool->msgid = msgget(((__key_t) 0), 0600 | 01000 | 02000)) < 0)
    {
        nq_errmsg("msgget: %s", strerror((*__errno_location ())));
        r_pool = ((void *)0);
        goto ERROR_RET_1;
    }
    do { } while(0);
    int pid_index = 0;
    for (loop_cnt = 0; loop_cnt < 10; loop_cnt++)
    {
        if (pthread_create(&r_pool->ptid[pid_index], ((void *)0), pkg_thread_get_rdeps, r_pool) != 0)
        {
            nq_errmsg("pthread_create");
        }
        else
        {
            ++pid_index;
        }
    }
    r_pool->threads = pid_index;
    goto FUNC_RET;
ERROR_RET_1:
    if (pthread_mutex_destroy(&r_pool->pdt_mutex) != 0)
        nq_errmsg("pthread_mutex_destroy");
    if (pthread_mutex_destroy(&r_pool->raw_mutex) != 0)
        nq_errmsg("pthread_mutex_destroy");
    if(sem_destroy(&r_pool->pdt_sem) < 0)
        nq_errmsg("sem_destroy: %s", strerror((*__errno_location ())));
    free(r_mem_ptr);
FUNC_RET:
    return r_pool;
}

canonical_original_code:
struct nq_thread_pool_ *nq_thread_pool_create()
{
    do { } while(0);
    struct nq_thread_pool_ *r_pool = ((void *)0);
    int loop_cnt;
    void *r_mem_ptr;
    r_mem_ptr = malloc(sizeof(nq_thread_pool) + sizeof(pthread_t) * 10);
    if (!r_mem_ptr)
        return ((void *)0);
    memset(r_mem_ptr, 0, sizeof(nq_thread_pool) + sizeof(pthread_t) * 10);
    r_pool = (struct nq_thread_pool_ *)r_mem_ptr;
    r_pool->ptid = (unsigned long *)(r_pool+1);
    pthread_mutex_init(&r_pool->pdt_mutex, ((void *)0));
    pthread_mutex_init(&r_pool->raw_mutex, ((void *)0));
    sem_init(&r_pool->pdt_sem, 0, 0);
    if((r_pool->msgid = msgget(((int) 0), 0600 | 01000 | 02000)) < 0)
    {
        nq_errmsg("msgget: %s", strerror((*__errno_location ())));
        r_pool = ((void *)0);
        goto ERROR_RET_1;
    }
    do { } while(0);
    int pid_index = 0;
    for (loop_cnt = 0; loop_cnt < 10; loop_cnt++)
    {
        if (pthread_create(&r_pool->ptid[pid_index], ((void *)0), pkg_thread_get_rdeps, r_pool) != 0)
        {
            nq_errmsg("pthread_create");
        }
        else
        {
            ++pid_index;
        }
    }
    r_pool->threads = pid_index;
    goto FUNC_RET;
ERROR_RET_1:
    if (pthread_mutex_destroy(&r_pool->pdt_mutex) != 0)
        nq_errmsg("pthread_mutex_destroy");
    if (pthread_mutex_destroy(&r_pool->raw_mutex) != 0)
        nq_errmsg("pthread_mutex_destroy");
    if(sem_destroy(&r_pool->pdt_sem) < 0)
        nq_errmsg("sem_destroy: %s", strerror((*__errno_location ())));
    free(r_mem_ptr);
FUNC_RET:
    return r_pool;
}

return_type: struct nq_thread_pool_ { union sem_t { char __size[32]; long __align; } pdt_sem; int msgid; int threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } pdt_mutex; struct _pkg_node { char *name; unsigned int con_offset; unsigned int level; struct _raw_node { char *name; struct _raw_node *prev; struct _raw_node *next; } *child; struct _pkg_node *next; struct _pkg_node *prev; } *pdt_head; struct _pkg_node *pdt_rear; union pthread_mutex_t raw_mutex; struct _pkg_node *raw_head; struct _pkg_node *raw_rear; unsigned long *ptid; } *


decompiled_code:
__int64 __fastcall nq_thread_pool_get_product(__int64 a1)
{
pthread_mutex_t *v1; // rbp
__int64 v2; // r12
__int64 v3; // rax
__int64 result; // rax

v1 = (pthread_mutex_t *)(a1 + 40);
sem_wait((sem_t *)a1);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 40));
v2 = *(_QWORD *)(a1 + 88);
if ( v2 )
{
if ( *(_QWORD *)(a1 + 80) == v2 )
{
*(_QWORD *)(a1 + 80) = 0LL;
*(_QWORD *)(a1 + 88) = 0LL;
}
else
{
v3 = *(_QWORD *)(v2 + 32);
*(_QWORD *)(a1 + 88) = v3;
*(_QWORD *)(v3 + 24) = 0LL;
}
pthread_mutex_unlock(v1);
result = v2;
}
else
{
nq_errmsg("Null product node ? Something thread synchronization error had occured!");
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
pthread_mutex_t *v1; // rbp
__int64 v2; // r12
__int64 v3; // rax
__int64 result; // rax

v1 = (pthread_mutex_t *)(a1 + 40);
sem_wait((sem_t *)a1);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 40));
v2 = *(_QWORD *)(a1 + 88);
if ( v2 )
{
if ( *(_QWORD *)(a1 + 80) == v2 )
{
*(_QWORD *)(a1 + 80) = 0LL;
*(_QWORD *)(a1 + 88) = 0LL;
}
else
{
v3 = *(_QWORD *)(v2 + 32);
*(_QWORD *)(a1 + 88) = v3;
*(_QWORD *)(v3 + 24) = 0LL;
}
pthread_mutex_unlock(v1);
result = v2;
}
else
{
nq_errmsg("Null product node ? Something thread synchronization error had occured!");
pthread_mutex_unlock(v1);
result = 0LL;
}
return result;
}

original_code:
pkg_node * nq_thread_pool_get_product (nq_thread_pool * thread_pool)
{
    do { } while(0);
    pkg_node * r_pkg_node;
    sem_wait(&thread_pool->pdt_sem);
    pthread_mutex_lock(&thread_pool->pdt_mutex);
    r_pkg_node = thread_pool->pdt_rear;
    if (r_pkg_node)
    {
        if (thread_pool->pdt_head == thread_pool->pdt_rear)
        {
            thread_pool->pdt_head = ((void *)0);
            thread_pool->pdt_rear = ((void *)0);
        }
        else
        {
            thread_pool->pdt_rear = r_pkg_node->prev;
            r_pkg_node->prev->next = ((void *)0);
        }
    }
    else
    {
        nq_errmsg("Null product node ? Something thread synchronization error had occured!");
    }
    pthread_mutex_unlock(&thread_pool->pdt_mutex);
    return r_pkg_node;
}

canonical_original_code:
struct _pkg_node *nq_thread_pool_get_product(struct nq_thread_pool_ *thread_pool)
{
    do { } while(0);
    struct _pkg_node *r_pkg_node;
    sem_wait(&thread_pool->pdt_sem);
    pthread_mutex_lock(&thread_pool->pdt_mutex);
    r_pkg_node = thread_pool->pdt_rear;
    if (r_pkg_node)
    {
        if (thread_pool->pdt_head == thread_pool->pdt_rear)
        {
            thread_pool->pdt_head = ((void *)0);
            thread_pool->pdt_rear = ((void *)0);
        }
        else
        {
            thread_pool->pdt_rear = r_pkg_node->prev;
            r_pkg_node->prev->next = ((void *)0);
        }
    }
    else
    {
        nq_errmsg("Null product node ? Something thread synchronization error had occured!");
    }
    pthread_mutex_unlock(&thread_pool->pdt_mutex);
    return r_pkg_node;
}

variable_types: struct nq_thread_pool_ { union sem_t { char __size[32]; long __align; } pdt_sem; int msgid; int threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } pdt_mutex; struct _pkg_node *pdt_head; struct _pkg_node *pdt_rear; union pthread_mutex_t raw_mutex; struct _pkg_node *raw_head; struct _pkg_node *raw_rear; unsigned long *ptid; } *

return_type: struct _pkg_node { char *name; unsigned int con_offset; unsigned int level; struct _raw_node { char *name; struct _raw_node *prev; struct _raw_node *next; } *child; struct _pkg_node *next; struct _pkg_node *prev; } *


original_code:
void nq_thread_pool_add_raw_material(nq_thread_pool * thread_pool, pkg_node * raw_node)
{
    do { } while(0);
    msg_node exec_cmd = {
        .mtype = 1,
        .cmd = EXEC
    };
    pthread_mutex_lock(&thread_pool->raw_mutex);
    raw_node->prev = ((void *)0);
    raw_node->next = thread_pool->raw_head;
    if (raw_node->next)
        raw_node->next->prev = raw_node;
    thread_pool->raw_head = raw_node;
    if (!thread_pool->raw_rear)
        thread_pool->raw_rear = raw_node;
    pthread_mutex_unlock(&thread_pool->raw_mutex);
    msgsnd(thread_pool->msgid, &exec_cmd, sizeof(POOL_CMD), 0);
}

canonical_original_code:
void nq_thread_pool_add_raw_material(struct nq_thread_pool_ *thread_pool, struct _pkg_node *raw_node)
{
    do { } while(0);
    struct msg_node_ exec_cmd = {
        .mtype = 1,
        .cmd = EXEC
    };
    pthread_mutex_lock(&thread_pool->raw_mutex);
    raw_node->prev = ((void *)0);
    raw_node->next = thread_pool->raw_head;
    if (raw_node->next)
        raw_node->next->prev = raw_node;
    thread_pool->raw_head = raw_node;
    if (!thread_pool->raw_rear)
        thread_pool->raw_rear = raw_node;
    pthread_mutex_unlock(&thread_pool->raw_mutex);
    msgsnd(thread_pool->msgid, &exec_cmd, sizeof(POOL_CMD), 0);
}

user_defined_types: union sem_t { char __size[32]; long __align; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct _raw_node { char *name; struct _raw_node *prev; struct _raw_node *next; }


decompiled_code:
__int64 __fastcall nq_thread_pool_destroy(void *ptr)
{
int v2; // ebx
int v3; // eax
__int64 v4; // rbx
pthread_t v5; // rdi
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
int v8; // [rsp+8h] [rbp-20h]

v7 = 1LL;
v8 = 1;
nq_thread_pool_check_value_isra_0((__int64)ptr);
if ( *((int *)ptr + 9) > 0 )
{
v2 = 0;
do
{
++v2;
msgsnd(*((_DWORD *)ptr + 8), &v7, 4uLL, 0);
v3 = *((_DWORD *)ptr + 9);
}
while ( v3 > v2 );
if ( v3 > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)ptr + 19) + 8 * v4++);
pthread_join(v5, 0LL);
}
while ( *((_DWORD *)ptr + 9) > (int)v4 );
}
}
pthread_mutex_destroy((pthread_mutex_t *)ptr + 1);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 96));
sem_destroy((sem_t *)ptr);
msgctl(*((_DWORD *)ptr + 8), 0, 0LL);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
int v2; // ebx
int v3; // eax
__int64 v4; // rbx
pthread_t v5; // rdi
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
int v8; // [rsp+8h] [rbp-20h]

v7 = 1LL;
v8 = 1;
func1((__int64)ptr);
if ( *((int *)ptr + 9) > 0 )
{
v2 = 0;
do
{
++v2;
msgsnd(*((_DWORD *)ptr + 8), &v7, 4uLL, 0);
v3 = *((_DWORD *)ptr + 9);
}
while ( v3 > v2 );
if ( v3 > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)ptr + 19) + 8 * v4++);
pthread_join(v5, 0LL);
}
while ( *((_DWORD *)ptr + 9) > (int)v4 );
}
}
pthread_mutex_destroy((pthread_mutex_t *)ptr + 1);
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 96));
sem_destroy((sem_t *)ptr);
msgctl(*((_DWORD *)ptr + 8), 0, 0LL);
free(ptr);
return 0LL;
}

original_code:
int nq_thread_pool_destroy (nq_thread_pool * thread_pool)
{
    int loop_cnt;
    msg_node exit_cmd = {
        .mtype = 1,
        .cmd = EXIT
    };
    do { } while(0);
    nq_thread_pool_check_value(thread_pool);
    for (loop_cnt = 0; loop_cnt < thread_pool->threads; loop_cnt++)
        msgsnd(thread_pool->msgid, &exit_cmd, sizeof(POOL_CMD), 0);
    for (loop_cnt = 0; loop_cnt < thread_pool->threads; loop_cnt++)
        pthread_join(thread_pool->ptid[loop_cnt], ((void *)0));
    pthread_mutex_destroy(&thread_pool->pdt_mutex);
    pthread_mutex_destroy(&thread_pool->raw_mutex);
    sem_destroy(&thread_pool->pdt_sem);
    msgctl(thread_pool->msgid, 0, ((void *)0));
    free(thread_pool);
    thread_pool = ((void *)0);
    return 0;
}

canonical_original_code:
int nq_thread_pool_destroy(struct nq_thread_pool_ *thread_pool)
{
    int loop_cnt;
    struct msg_node_ exit_cmd = {
        .mtype = 1,
        .cmd = EXIT
    };
    do { } while(0);
    nq_thread_pool_check_value(thread_pool);
    for (loop_cnt = 0; loop_cnt < thread_pool->threads; loop_cnt++)
        msgsnd(thread_pool->msgid, &exit_cmd, sizeof(POOL_CMD), 0);
    for (loop_cnt = 0; loop_cnt < thread_pool->threads; loop_cnt++)
        pthread_join(thread_pool->ptid[loop_cnt], ((void *)0));
    pthread_mutex_destroy(&thread_pool->pdt_mutex);
    pthread_mutex_destroy(&thread_pool->raw_mutex);
    sem_destroy(&thread_pool->pdt_sem);
    msgctl(thread_pool->msgid, 0, ((void *)0));
    free(thread_pool);
    thread_pool = ((void *)0);
    return 0;
}


decompiled_code:
void __noreturn nq_errmsg_exit(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
fwrite("Error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func0(const char *a1, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a1);
fwrite("Error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, a1, arg);
fputc(10, stderr);
exit(1);
}

original_code:
void nq_errmsg_exit(char *fmt, ...)
{
    va_list arglist;
    __builtin_va_start(arglist,fmt);
    fprintf(stderr, "Error: ");
    vfprintf(stderr, fmt, arglist);
    fprintf(stderr, "\n");
    __builtin_va_end(arglist);
    exit(1);
}

canonical_original_code:
void nq_errmsg_exit(char *fmt, ...)
{
    __builtin_va_list arglist;
    __builtin_va_start(arglist,fmt);
    fprintf(stderr, "Error: ");
    vfprintf(stderr, fmt, arglist);
    fprintf(stderr, "\n");
    __builtin_va_end(arglist);
    exit(1);
}

variable_types:
fmt
char *


decompiled_code:
int nq_warnmsg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("Warning: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func1(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("Warning: ", 1uLL, 9uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

original_code:
void nq_warnmsg(char *fmt, ...)
{
    va_list arglist;
    __builtin_va_start(arglist,fmt);
    fprintf(stderr, "Warning: ");
    vfprintf(stderr, fmt, arglist);
    fprintf(stderr, "\n");
    __builtin_va_end(arglist);
}

canonical_original_code:
void nq_warnmsg(char *fmt, ...)
{
    __builtin_va_list arglist;
    __builtin_va_start(arglist,fmt);
    fprintf(stderr, "Warning: ");
    vfprintf(stderr, fmt, arglist);
    fprintf(stderr, "\n");
    __builtin_va_end(arglist);
}


decompiled_code:
int nq_errmsg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("Error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

canonical_decompiled_code:
int func2(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
fwrite("Error: ", 1uLL, 7uLL, stderr);
vfprintf(stderr, format, arg);
return fputc(10, stderr);
}

original_code:
void nq_errmsg(char *fmt, ...)
{
    va_list arglist;
    __builtin_va_start(arglist,fmt);
    fprintf(stderr, "Error: ");
    vfprintf(stderr, fmt, arglist);
    fprintf(stderr, "\n");
    __builtin_va_end(arglist);
}

canonical_original_code:
void nq_errmsg(char *fmt, ...)
{
    __builtin_va_list arglist;
    __builtin_va_start(arglist,fmt);
    fprintf(stderr, "Error: ");
    vfprintf(stderr, fmt, arglist);
    fprintf(stderr, "\n");
    __builtin_va_end(arglist);
}


decompiled_code:
int nq_normsg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stdout, format, arg);
return fputc(10, stdout);
}

canonical_decompiled_code:
int func3(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
vfprintf(stdout, format, arg);
return fputc(10, stdout);
}

original_code:
void nq_normsg(char *fmt, ...)
{
    va_list arglist;
    __builtin_va_start(arglist,fmt);
    vfprintf(stdout, fmt, arglist);
    fprintf(stdout, "\n");
    __builtin_va_end(arglist);
}

canonical_original_code:
void nq_normsg(char *fmt, ...)
{
    __builtin_va_list arglist;
    __builtin_va_start(arglist,fmt);
    vfprintf(stdout, fmt, arglist);
    fprintf(stdout, "\n");
    __builtin_va_end(arglist);
}


decompiled_code:
__int64 __fastcall nq_set_fd_nonblocking(int fd)
{
int v1; // eax
int *v3; // rax
char *v4; // rax

v1 = fcntl(fd, 3, 0LL);
if ( v1 >= 0 )
{
BYTE1(v1) |= 8u;
if ( fcntl(fd, 4, (unsigned int)v1) >= 0 )
return 0LL;
}
v3 = _errno_location();
v4 = strerror(*v3);
nq_errmsg("fcntl: %s", v4);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd)
{
int v1; // eax
int *v3; // rax
char *v4; // rax

v1 = fcntl(fd, 3, 0LL);
if ( v1 >= 0 )
{
BYTE1(v1) |= 8u;
if ( fcntl(fd, 4, (unsigned int)v1) >= 0 )
return 0LL;
}
v3 = _errno_location();
v4 = strerror(*v3);
func2("fcntl: %s", v4);
return 0xFFFFFFFFLL;
}

original_code:
int nq_set_fd_nonblocking(int fd)
{
    int fd_flag;
    if((fd_flag = fcntl(fd, 3, 0)) < 0)
    {
        nq_errmsg("fcntl: %s", strerror((*__errno_location ())));
        return -1;
    }
    fd_flag |= 04000;
    if(fcntl(fd, 4, fd_flag) < 0)
    {
        nq_errmsg("fcntl: %s", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: fd int


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

if ( stat(a1, &v4) >= 0 )
return v4.st_size;
v2 = _errno_location();
v3 = strerror(*v2);
nq_errmsg("stat: %s", v3);
return -1LL;
}

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

if ( stat(a1, &v4) >= 0 )
return v4.st_size;
v2 = _errno_location();
v3 = strerror(*v2);
func2("stat: %s", v3);
return -1LL;
}

original_code:
off_t nq_get_file_length(char * path)
{
    struct stat st_buf;
    if(stat (path, &st_buf) < 0)
    {
        nq_errmsg("stat: %s", strerror((*__errno_location ())));
        return (off_t)-1;
    }
    return st_buf.st_size;
}

canonical_original_code:
long nq_get_file_length(char *path)
{
    struct stat st_buf;
    if(stat (path, &st_buf) < 0)
    {
        nq_errmsg("stat: %s", strerror((*__errno_location ())));
        return (off_t)-1;
    }
    return st_buf.st_size;
}

variable_types:
path
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

return_type: long

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


repo: tshikaboom/flood-it

decompiled_code:
__int64 __fastcall ajoute_Zsg(__int64 a1, int a2, int a3)
{
int v3; // eax
__int64 v4; // rbp
__int64 result; // rax

v3 = a3;
if ( a2 >= a3 )
v3 = a2;
if ( *(_DWORD *)(a1 + 24) < v3 )
exit(1);
v4 = a3;
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
if ( *(_DWORD *)(result + 4LL * a3) != -1 )
{
*(_QWORD *)a1 = liste_ajoute(*(_QWORD *)a1);
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
*(_DWORD *)(result + 4 * v4) = -1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
int v3; // eax
__int64 v4; // rbp
__int64 result; // rax

v3 = a3;
if ( a2 >= a3 )
v3 = a2;
if ( *(_DWORD *)(a1 + 24) < v3 )
exit(1);
v4 = a3;
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
if ( *(_DWORD *)(result + 4LL * a3) != -1 )
{
*(_QWORD *)a1 = liste_ajoute(*(_QWORD *)a1);
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
*(_DWORD *)(result + 4 * v4) = -1;
}
return result;
}

original_code:
void ajoute_Zsg(Zones *z, int i, int j)
{
  if (i > z->nbcase || j > z->nbcase)
    exit(1);
  if (z->App[i][j] != -1) {
    z->Lzsg = liste_ajoute(z->Lzsg, i, j);
    z->App[i][j] = -1;
  }
}

canonical_original_code:
void ajoute_Zsg(struct Zones *z, int i, int j)
{
  if (i > z->nbcase || j > z->nbcase)
    exit(1);
  if (z->App[i][j] != -1) {
    z->Lzsg = liste_ajoute(z->Lzsg, i, j);
    z->App[i][j] = -1;
  }
}

variable_types: struct Zones { struct Liste_C { int i; int j; struct Liste_C *next; } *Lzsg; struct Liste_C **B; int **App; int nbcase; int nbcl; } *

variable_types: i int

variable_types: j int

user_defined_types: struct Zones { struct Liste_C *Lzsg; struct Liste_C **B; int **App; int nbcase; int nbcl; }


decompiled_code:
__int64 __fastcall ajoute_Bordure(__int64 a1, int a2, int a3, int a4)
{
__int64 v4; // rbx
int v5; // eax
__int64 *v7; // r12
__int64 result; // rax

v4 = a3;
v5 = a3;
if ( a2 >= a3 )
v5 = a2;
if ( *(_DWORD *)(a1 + 24) < v5 )
exit(1);
v7 = (__int64 *)(*(_QWORD *)(a1 + 8) + 8LL * a4);
result = liste_ajoute(*v7);
*v7 = result;
if ( a4 <= 99 )
{
result = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2);
*(_DWORD *)(result + 4 * v4) = a4;
}
return result;
}

original_code:
void ajoute_Bordure(Zones *z, int i, int j, int clCase)
{
  if (i > z->nbcase || j > z->nbcase)
      exit(1);
  z->B[clCase] = liste_ajoute(z->B[clCase], i, j);
  if (clCase<100)
    z->App[i][j] = clCase;
}

canonical_original_code:
void ajoute_Bordure(struct Zones *z, int i, int j, int clCase)
{
  if (i > z->nbcase || j > z->nbcase)
      exit(1);
  z->B[clCase] = liste_ajoute(z->B[clCase], i, j);
  if (clCase<100)
    z->App[i][j] = clCase;
}

variable_types: clCase int

user_defined_types: struct Liste_C { int i; int j; struct Liste_C *next; }


original_code:
void init_Zones (int **M, Zones *newZone)
{
  int i, j;
  int a, b;
  newZone->Lzsg = ((void *)0);
  newZone->B = ((void *)0);
  newZone->App = malloc(sizeof(int *) * newZone->nbcase);
  if (newZone->App == ((void *)0)) {
    fprintf(stderr, "Allocation de App failed!\n");
    exit(1);
  }
  for (i=0; i<newZone->nbcase; i++) {
    newZone->App[i] = malloc(sizeof(int) * newZone->nbcase);
    for(j=0; j < newZone->nbcase; j++)
      newZone->App[i][j] = -2;
  }
  for (a=0; a<newZone->nbcase; a++)
      newZone->App[0][a] = -2;
  for (a=0; a<newZone->nbcase; a++) {
    for (b=0; b<newZone->nbcase; b++)
      printf("%d\t", newZone->App[a][b]);
    printf("\n");
  }
  fprintf(stderr, "%s %d\n", "Zones.c", 36 );
  newZone->B = (Liste_case **) malloc(sizeof(Liste_case *) * newZone->nbcl);
  if (newZone->B == ((void *)0)) {
    fprintf(stderr, "Allocation de B failed!\n");
    exit(1);
  }
  for(i=0; i < newZone->nbcl; i++)
      newZone->B[i] = ((void *)0);
  newZone->Lzsg = liste_init();
  if ( (newZone->Lzsg == ((void *)0)) || (newZone->B == ((void *)0)))
      exit(1);
  ajoute_Zsg(newZone, 0, 0);
  fprintf(stderr, "%s %d\n", "Zones.c", 55 );
  ajoute_Bordure(newZone, 0, 1, M[0][1]);
  fprintf(stderr, "%s %d\n", "Zones.c", 57 );
  ajoute_Bordure(newZone, 1, 0, M[1][0]);
  fprintf(stderr, "%s %d\n", "Zones.c", 59 );
  ajoute_Bordure(newZone, 1, 1, M[1][1]);
  fprintf(stderr, "%s %d\n", "Zones.c", 61 );
}

canonical_original_code:
void init_Zones(int **M, struct Zones *newZone)
{
  int i; int j;
  int a; int b;
  newZone->Lzsg = ((void *)0);
  newZone->B = ((void *)0);
  newZone->App = malloc(sizeof(int *) * newZone->nbcase);
  if (newZone->App == ((void *)0)) {
    fprintf(stderr, "Allocation de App failed!\n");
    exit(1);
  }
  for (i=0; i<newZone->nbcase; i++) {
    newZone->App[i] = malloc(sizeof(int) * newZone->nbcase);
    for(j=0; j < newZone->nbcase; j++)
      newZone->App[i][j] = -2;
  }
  for (a=0; a<newZone->nbcase; a++)
      newZone->App[0][a] = -2;
  for (a=0; a<newZone->nbcase; a++) {
    for (b=0; b<newZone->nbcase; b++)
      printf("%d\t", newZone->App[a][b]);
    printf("\n");
  }
  fprintf(stderr, "%s %d\n", "Zones.c", 36 );
  newZone->B = (struct Liste_C **) malloc(sizeof(struct Liste_C *) * newZone->nbcl);
  if (newZone->B == ((void *)0)) {
    fprintf(stderr, "Allocation de B failed!\n");
    exit(1);
  }
  for(i=0; i < newZone->nbcl; i++)
      newZone->B[i] = ((void *)0);
  newZone->Lzsg = liste_init();
  if ( (newZone->Lzsg == ((void *)0)) || (newZone->B == ((void *)0)))
      exit(1);
  ajoute_Zsg(newZone, 0, 0);
  fprintf(stderr, "%s %d\n", "Zones.c", 55 );
  ajoute_Bordure(newZone, 0, 1, M[0][1]);
  fprintf(stderr, "%s %d\n", "Zones.c", 57 );
  ajoute_Bordure(newZone, 1, 0, M[1][0]);
  fprintf(stderr, "%s %d\n", "Zones.c", 59 );
  ajoute_Bordure(newZone, 1, 1, M[1][1]);
  fprintf(stderr, "%s %d\n", "Zones.c", 61 );
}

variable_types:
M
int **

variable_types: a int

variable_types: b int


decompiled_code:
_BOOL8 __fastcall appartient_Bordure_coord(__int64 a1, int a2, int a3)
{
return *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * a3) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 a1, int a2, int a3)
{
return *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * a3) > 0;
}

original_code:
int appartient_Bordure_coord(Zones *z, int i, int j)
{
  return (z->App[i][j] > 0);
}

canonical_original_code:
int appartient_Bordure_coord(struct Zones *z, int i, int j)
{
  return (z->App[i][j] > 0);
}


decompiled_code:
_BOOL8 __fastcall appartient_Zsg(__int64 a1, int a2, int a3)
{
return *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * a3) == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, int a2, int a3)
{
return *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * a2) + 4LL * a3) == -1;
}

original_code:
int appartient_Zsg(Zones *z, int i, int j)
{
  return (z->App[i][j] == -1);
}

canonical_original_code:
int appartient_Zsg(struct Zones *z, int i, int j)
{
  return (z->App[i][j] == -1);
}


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

result = *(int **)(*(_QWORD *)(a2 + 8) + 8LL * a3);
if ( !result )
return 0LL;
while ( *(_DWORD *)(*(_QWORD *)(a1 + 8LL * *result) + 4LL * result[1]) != a3 )
{
result = (int *)*((_QWORD *)result + 1);
if ( !result )
return result;
}
return (_DWORD *)(ajoute_Zsg + 1);
}

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

result = *(int **)(*(_QWORD *)(a2 + 8) + 8LL * a3);
if ( !result )
return 0LL;
while ( *(_DWORD *)(*(_QWORD *)(a1 + 8LL * *result) + 4LL * result[1]) != a3 )
{
result = (int *)*((_QWORD *)result + 1);
if ( !result )
return result;
}
return (_DWORD *)(ajoute_Zsg + 1);
}

original_code:
int appartient_Bordure(int ** M, Zones *z, int cl)
{
  Liste_case *l = ((void *)0);
  l = z->B[cl];
  int i,j;
  while(1) {
    if (l == ((void *)0))
      return 0;
    i = l->i;
    j = l->j;
    if (M[i][j] == cl)
      return 1;
    l = l->next;
  }
}

canonical_original_code:
int appartient_Bordure(int **M, struct Zones *z, int cl)
{
  struct Liste_C *l = ((void *)0);
  l = z->B[cl];
  int i; int j;
  while(1) {
    if (l == ((void *)0))
      return 0;
    i = l->i;
    j = l->j;
    if (M[i][j] == cl)
      return 1;
    l = l->next;
  }
}

variable_types: cl int

variable_types: struct Liste_C { int i; int j; struct Liste_C *next; } *


aggranditZone

original_code:
void aggranditZone(int ** M, Zones *z, int cl)
{
  int i, j, nbcase = z->nbcase;
  int **v;
  Pile p;
  Element *e = ((void *)0);
  Liste_case *l = z->B[cl];
  init_pile(&p);
  v = malloc(sizeof(int*) * nbcase);
  for (i=0; i<nbcase; i++) {
    v[i] = malloc(sizeof(int *) * nbcase);
    for (j=0; j<nbcase; j++)
      v[i][j] = 0;
  }
  while(l != ((void *)0)) {
    empile(&p, l->i, l->j);
    v[l->i][l->j] = 1;
    l = l->next;
  }
  liste_detruit(z->B[cl]);
  z->B[cl]=((void *)0);
  while(p.e != ((void *)0)) {
    e = depile(&p);
    i = e->i;
    j = e->j;
    free(e);
    if (M[i][j] == cl) {
      ajoute_Zsg(z, i, j);
      if ((i > 0) &&
   !((v[i - 1][j] == 1) || (appartient_Zsg(z, i - 1, j)))) {
 empile(&p, i - 1, j);
 v[i-1][j] = 1;
      }
      if ((i < nbcase-1) &&
   !(v[i + 1][j] || (appartient_Zsg(z, i + 1, j)))) {
 empile(&p, i + 1, j);
 v[i+1][j] = 1;
      }
      if ((j < nbcase-1) &&
   !( v[i][j + 1] || (appartient_Zsg(z, i, j + 1)))) {
 empile(&p, i, j + 1);
 v[i][j+1] = 1;
      }
      if ((j > 0) &&
   !(v[i][j - 1] || (appartient_Zsg(z, i, j - 1)))) {
 empile(&p, i, j - 1);
 v[i][j-1] = 1;
      }
    }
    else
 ajoute_Bordure(z, i, j, M[i][j]);
  }
  for(i=0; i<nbcase; i++)
      free(v[i]);
  free(v);
}

canonical_original_code:
void aggranditZone(int **M, struct Zones *z, int cl)
{
  int i; int j; int nbcase = z->nbcase;
  int **v;
  struct Pile p;
  struct Element_pile *e = ((void *)0);
  struct Liste_C *l = z->B[cl];
  init_pile(&p);
  v = malloc(sizeof(int *) * nbcase);
  for (i=0; i<nbcase; i++) {
    v[i] = malloc(sizeof(int *) * nbcase);
    for (j=0; j<nbcase; j++)
      v[i][j] = 0;
  }
  while(l != ((void *)0)) {
    empile(&p, l->i, l->j);
    v[l->i][l->j] = 1;
    l = l->next;
  }
  liste_detruit(z->B[cl]);
  z->B[cl]=((void *)0);
  while(p.e != ((void *)0)) {
    e = depile(&p);
    i = e->i;
    j = e->j;
    free(e);
    if (M[i][j] == cl) {
      ajoute_Zsg(z, i, j);
      if ((i > 0) &&
   !((v[i - 1][j] == 1) || (appartient_Zsg(z, i - 1, j)))) {
 empile(&p, i - 1, j);
 v[i-1][j] = 1;
      }
      if ((i < nbcase-1) &&
   !(v[i + 1][j] || (appartient_Zsg(z, i + 1, j)))) {
 empile(&p, i + 1, j);
 v[i+1][j] = 1;
      }
      if ((j < nbcase-1) &&
   !( v[i][j + 1] || (appartient_Zsg(z, i, j + 1)))) {
 empile(&p, i, j + 1);
 v[i][j+1] = 1;
      }
      if ((j > 0) &&
   !(v[i][j - 1] || (appartient_Zsg(z, i, j - 1)))) {
 empile(&p, i, j - 1);
 v[i][j-1] = 1;
      }
    }
    else
 ajoute_Bordure(z, i, j, M[i][j]);
  }
  for(i=0; i<nbcase; i++)
      free(v[i]);
  free(v);
}

variable_types: nbcase int

variable_types:
v
int **

variable_types: struct Pile { struct Element_pile { int i; int j; struct Element_pile *next; } *e; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // rbx
unsigned int v5; // er13
_QWORD *v6; // rbp
__int64 v7; // r12
void *v8; // rax
_QWORD *v9; // r13
int v10; // er12
__int64 v11; // rbx
__int64 v12; // rdx
__int64 v13; // rcx
__int64 v14; // rdx
_QWORD *v15; // r13
int v16; // er12
__int64 v17; // rbx
__int64 v18; // rdx
__int64 v19; // rcx
unsigned int v20; // eax
_QWORD *v21; // r13
int v22; // er12
__int64 v23; // rbx
__int64 v24; // rdx
__int64 v25; // rcx
_QWORD *v26; // r13
int v27; // er12
__int64 v28; // rbx
__int64 v29; // rdx
__int64 v30; // rcx
__int64 v31; // rdx
_QWORD *v32; // r13
int i; // er12
__int64 v34; // rbx
__int64 v35; // rdx
__int64 v36; // rcx
__int64 v37; // rdx
_QWORD *v38; // r13
int v39; // er12
__int64 v40; // rbx
__int64 v41; // rdx
__int64 v42; // rcx
int v43; // [rsp+4h] [rbp-44h] BYREF
unsigned int v44; // [rsp+8h] [rbp-40h] BYREF
unsigned int v45; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned int v46; // [rsp+10h] [rbp-38h] BYREF
int v47; // [rsp+14h] [rbp-34h] BYREF
__int64 v48[6]; // [rsp+18h] [rbp-30h] BYREF

if ( argc == 5 )
{
_isoc99_sscanf(argv[1], "%d", &v43);
_isoc99_sscanf(argv[2], "%d", &v44);
_isoc99_sscanf(argv[3], "%d", &v45);
_isoc99_sscanf(argv[4], "%d", &v46);
v4 = v43;
v5 = v43;
v6 = malloc(8LL * v43);
if ( !v6 )
exit(1);
v7 = 0LL;
if ( (int)v4 > 0 )
{
while ( 1 )
{
v8 = malloc(4 * v4);
v6[v7] = v8;
if ( !v8 )
puts("OUCH");
v5 = v43;
if ( v43 <= (int)++v7 )
break;
v4 = v43;
}
}
Gene_instance_genere_matrice(v5, v44, v45, v46, v6);
Grille_init((unsigned int)v43, v44, 500LL, v48);
Grille_ouvre_fenetre(v48[0]);
if ( v43 > 0 )
{
v9 = v6;
v10 = 0;
do
{
v11 = 0LL;
do
{
v12 = (unsigned int)v11;
v13 = *(unsigned int *)(*v9 + 4 * v11++);
Grille_chg_case(v48[0], (unsigned int)v10, v12, v13);
}
while ( v43 > (int)v11 );
++v10;
++v9;
}
while ( v43 > v10 && v43 > 0 );
}
Grille_redessine_Grille();
do
{
puts("Flood-it: menu");
puts("1 Strategie recursive");
puts("2 Strategie iterative");
puts("3 Strategie rapide");
puts("4 Strategie max-bordures");
puts("5 Strategie largeur\n");
puts("0 Quitter");
printf(">> ");
_isoc99_scanf("%d", &v47);
switch ( v47 )
{
case 0:
break;
case 1:
Gene_instance_genere_matrice((unsigned int)v43, v44, v45, v46, v6);
Grille_init((unsigned int)v43, v44, 500LL, v48);
Grille_ouvre_fenetre(v48[0]);
v14 = (unsigned int)v43;
if ( v43 > 0 )
{
v15 = v6;
v16 = 0;
do
{
v17 = 0LL;
do
{
v18 = (unsigned int)v17;
v19 = *(unsigned int *)(*v15 + 4 * v17++);
Grille_chg_case(v48[0], (unsigned int)v16, v18, v19);
v14 = (unsigned int)v43;
}
while ( v43 > (int)v17 );
++v16;
++v15;
}
while ( v43 > v16 && v43 > 0 );
}
v20 = strategie_aleatoire_rec(v48[0], v6, v14, v44);
goto LABEL_25;
case 2:
Gene_instance_genere_matrice((unsigned int)v43, v44, v45, v46, v6);
Grille_init((unsigned int)v43, v44, 500LL, v48);
Grille_ouvre_fenetre(v48[0]);
v37 = (unsigned int)v43;
if ( v43 > 0 )
{
v38 = v6;
v39 = 0;
do
{
v40 = 0LL;
do
{
v41 = (unsigned int)v40;
v42 = *(unsigned int *)(*v38 + 4 * v40++);
Grille_chg_case(v48[0], (unsigned int)v39, v41, v42);
v37 = (unsigned int)v43;
}
while ( v43 > (int)v40 );
++v39;
++v38;
}
while ( v43 > v39 && v43 > 0 );
}
v20 = strategie_aleatoire_imp(v48[0], v6, v37, v44);
goto LABEL_25;
case 3:
Gene_instance_genere_matrice((unsigned int)v43, v44, v45, v46, v6);
Grille_init((unsigned int)v43, v44, 500LL, v48);
Grille_ouvre_fenetre(v48[0]);
v31 = (unsigned int)v43;
if ( v43 > 0 )
{
v32 = v6;
for ( i = 0; i < v43; ++i )
{
v34 = 0LL;
do
{
v35 = (unsigned int)v34;
v36 = *(unsigned int *)(*v32 + 4 * v34++);
Grille_chg_case(v48[0], (unsigned int)i, v35, v36);
v31 = (unsigned int)v43;
}
while ( v43 > (int)v34 );
++v32;
}
}
v20 = strategie_aleatoire_rapide(v48[0], v6, v31, v44);
goto LABEL_25;
case 4:
Gene_instance_genere_matrice((unsigned int)v43, v44, v45, v46, v6);
Grille_init((unsigned int)v43, v44, 500LL, v48);
Grille_ouvre_fenetre(v48[0]);
if ( v43 > 0 )
{
v26 = v6;
v27 = 0;
do
{
v28 = 0LL;
do
{
v29 = (unsigned int)v28;
v30 = *(unsigned int *)(*v26 + 4 * v28++);
Grille_chg_case(v48[0], (unsigned int)v27, v29, v30);
}
while ( v43 > (int)v28 );
++v27;
++v26;
}
while ( v43 > v27 && v43 > 0 );
}
v20 = maxBordure(v48[0], v6);
goto LABEL_25;
case 5:
Gene_instance_genere_matrice((unsigned int)v43, v44, v45, v46, v6);
Grille_init((unsigned int)v43, v44, 500LL, v48);
Grille_ouvre_fenetre(v48[0]);
if ( v43 > 0 )
{
v21 = v6;
v22 = 0;
do
{
v23 = 0LL;
do
{
v24 = (unsigned int)v23;
v25 = *(unsigned int *)(*v21 + 4 * v23++);
Grille_chg_case(v48[0], (unsigned int)v22, v24, v25);
}
while ( v43 > (int)v23 );
++v22;
++v21;
}
while ( v43 > v22 && v43 > 0 );
}
v20 = StrategieLarge(v48[0], v6);
LABEL_25:
printf("%d iterations au total\n", v20);
Grille_redessine_Grille();
Grille_attente_touche();
Grille_ferme_fenetre();
Grille_free(v48);
break;
default:
puts("choix?\n");
break;
}
result = v47;
}
while ( v47 );
}
else
{
printf("usage: %s <nb_de_case nb_de_couleurs niveau_difficulte graine>\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc,char**argv)
{
  int nbcase, nbcl, nivdif, graine, i, j;
  int **M;
  Grille *G;
  if (argc != 5) {
    printf("usage: %s <nb_de_case nb_de_couleurs niveau_difficulte graine>\n",argv[0]);
    return 1;
  }
  sscanf(argv[1], "%d", &nbcase);
  sscanf(argv[2], "%d", &nbcl);
  sscanf(argv[3], "%d", &nivdif);
  sscanf(argv[4], "%d", &graine);
  M=(int **) malloc(sizeof(int*)*nbcase);
  if(M==((void *)0))
      exit(1);
  for (i=0;i<nbcase;i++) {
      M[i]=(int*) malloc(sizeof(int)*nbcase);
      if (M[i]==0) printf("OUCH\n");
    }
  Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
  Grille_init(nbcase,nbcl, 500,&G);
  Grille_ouvre_fenetre(G);
  for (i=0;i<nbcase; i++ )
    for (j=0;j<nbcase;j++)
      Grille_chg_case(G,i,j,M[i][j]);
  Grille_redessine_Grille();
  int menuchoix;
  do {
    printf("Flood-it: menu\n");
    printf("1 Strategie recursive\n");
    printf("2 Strategie iterative\n");
    printf("3 Strategie rapide\n");
    printf("4 Strategie max-bordures\n");
    printf("5 Strategie largeur\n\n");
    printf("0 Quitter\n");
    printf(">> ");
    scanf("%d", &menuchoix);
    switch (menuchoix) {
    case 1:
      Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
 for (j=0;j<nbcase;j++)
   Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", strategie_aleatoire_rec(G, M, nbcase, nbcl));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
      break;
    case 2:
            Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
 for (j=0;j<nbcase;j++)
   Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", strategie_aleatoire_imp(G, M, nbcase, nbcl));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
      break;
    case 3:
      Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
 for (j=0;j<nbcase;j++)
   Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", strategie_aleatoire_rapide(G, M, nbcase, nbcl));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
      break;
    case 4:
      Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
       for (j=0;j<nbcase;j++)
        Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", maxBordure(G, M, nbcase));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
      break;
    case 5:
      Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
       for (j=0;j<nbcase;j++)
        Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", StrategieLarge(G, M, nbcase));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
    case 0:
      break;
    default:
      printf("choix?\n\n");
    }
  } while (menuchoix < 0 || menuchoix > 4 || menuchoix != 0);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  int nbcase; int nbcl; int nivdif; int graine; int i; int j;
  int **M;
  struct grille *G;
  if (argc != 5) {
    printf("usage: %s <nb_de_case nb_de_couleurs niveau_difficulte graine>\n",argv[0]);
    return 1;
  }
  sscanf(argv[1], "%d", &nbcase);
  sscanf(argv[2], "%d", &nbcl);
  sscanf(argv[3], "%d", &nivdif);
  sscanf(argv[4], "%d", &graine);
  M=(int **) malloc(sizeof(int *)*nbcase);
  if(M==((void *)0))
      exit(1);
  for (i=0;i<nbcase;i++) {
      M[i]=(int *) malloc(sizeof(int)*nbcase);
      if (M[i]==0) printf("OUCH\n");
    }
  Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
  Grille_init(nbcase,nbcl, 500,&G);
  Grille_ouvre_fenetre(G);
  for (i=0;i<nbcase; i++ )
    for (j=0;j<nbcase;j++)
      Grille_chg_case(G,i,j,M[i][j]);
  Grille_redessine_Grille();
  int menuchoix;
  do {
    printf("Flood-it: menu\n");
    printf("1 Strategie recursive\n");
    printf("2 Strategie iterative\n");
    printf("3 Strategie rapide\n");
    printf("4 Strategie max-bordures\n");
    printf("5 Strategie largeur\n\n");
    printf("0 Quitter\n");
    printf(">> ");
    scanf("%d", &menuchoix);
    switch (menuchoix) {
    case 1:
      Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
 for (j=0;j<nbcase;j++)
   Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", strategie_aleatoire_rec(G, M, nbcase, nbcl));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
      break;
    case 2:
            Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
 for (j=0;j<nbcase;j++)
   Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", strategie_aleatoire_imp(G, M, nbcase, nbcl));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
      break;
    case 3:
      Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
 for (j=0;j<nbcase;j++)
   Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", strategie_aleatoire_rapide(G, M, nbcase, nbcl));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
      break;
    case 4:
      Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
       for (j=0;j<nbcase;j++)
        Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", maxBordure(G, M, nbcase));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
      break;
    case 5:
      Gene_instance_genere_matrice(nbcase, nbcl, nivdif, graine, M);
      Grille_init(nbcase,nbcl, 500,&G);
      Grille_ouvre_fenetre(G);
      for (i=0;i<nbcase; i++ )
       for (j=0;j<nbcase;j++)
        Grille_chg_case(G,i,j,M[i][j]);
      printf("%d iterations au total\n", StrategieLarge(G, M, nbcase));
      Grille_redessine_Grille();
      Grille_attente_touche();
      Grille_ferme_fenetre();
      Grille_free(&G);
    case 0:
      break;
    default:
      printf("choix?\n\n");
    }
  } while (menuchoix < 0 || menuchoix > 4 || menuchoix != 0);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: nbcl int

variable_types: nivdif int

variable_types: graine int

variable_types: struct grille { int nbcase; int nbcl; int taille_pixel; int cas_aff; int taille_case; int modulo; unsigned int *T_coul; } *

variable_types: menuchoix int


original_code:
void colorie_zone_imp(int ** tab, int i, int j, int cl, int* taille, int nbCases)
{
  Pile p;
  init_pile(&p);
  int **matriceIncr;
  int compteur, compteur2;
  Element *e = ((void *)0);
  int couleurActuelle = tab[i][j];
  matriceIncr = (int **) malloc(nbCases*sizeof(int *));
  for (compteur=0; compteur<nbCases; compteur++)
    matriceIncr[compteur] = (int *) malloc(nbCases * sizeof(int));
  for (compteur=0; compteur<nbCases; compteur++)
    for (compteur2=0; compteur2<nbCases; compteur2++)
      matriceIncr[compteur][compteur2] = 0;
  printf("wat?\n");
  printf("debut colorie_imp: taille %d etc\n", *taille);
  if (cl == couleurActuelle)
    return;
  empile(&p, i , j);
  matriceIncr[i][j] = 1;
  *taille = *taille + 1;
  *taille = 0;
  printf("nbcases au carre: %d\n", nbCases*nbCases);
  while(! pile_vide(p)) {
       e = depile(&p);
      i = e->i;
      j = e->j;
      tab[i][j] = cl;
      if (i-1 >= 0 && (couleurActuelle == tab[i-1][j])) {
 if (matriceIncr[i-1][j] == 0) {
   *taille = *taille+1;
   matriceIncr[i-1][j] = 1;
 }
 empile(&p, (i-1), j);
      }
      if (j-1 >= 0 && (couleurActuelle == tab[i][j-1])) {
 if (matriceIncr[i][j-1] == 0) {
   *taille = *taille+1;
   matriceIncr[i][j-1] = 1;
 }
 empile(&p, i, (j - 1));
      }
      if (i+1 < nbCases && (tab[i+1][j] == couleurActuelle)) {
 if (matriceIncr[i+1][j] == 0) {
   *taille = *taille+1;
   matriceIncr[i+1][j] = 1;
 }
 empile(&p, (i+1), j);
      }
      if (j+1 < nbCases && (tab[i][j+1] == couleurActuelle)) {
 if (matriceIncr[i][j+1] == 0) {
   *taille = *taille+1;
   matriceIncr[i][j+1] = 1;
 }
 empile(&p, i, (j+1));
      }
      printf("fin colorie_imp: taille %d\n", *taille);
      free(e);
    }
}

canonical_original_code:
void colorie_zone_imp(int **tab, int i, int j, int cl, int *taille, int nbCases)
{
  struct Pile p;
  init_pile(&p);
  int **matriceIncr;
  int compteur; int compteur2;
  struct Element_pile *e = ((void *)0);
  int couleurActuelle = tab[i][j];
  matriceIncr = (int **) malloc(nbCases*sizeof(int *));
  for (compteur=0; compteur<nbCases; compteur++)
    matriceIncr[compteur] = (int *) malloc(nbCases * sizeof(int));
  for (compteur=0; compteur<nbCases; compteur++)
    for (compteur2=0; compteur2<nbCases; compteur2++)
      matriceIncr[compteur][compteur2] = 0;
  printf("wat?\n");
  printf("debut colorie_imp: taille %d etc\n", *taille);
  if (cl == couleurActuelle)
    return;
  empile(&p, i , j);
  matriceIncr[i][j] = 1;
  *taille = *taille + 1;
  *taille = 0;
  printf("nbcases au carre: %d\n", nbCases*nbCases);
  while(! pile_vide(p)) {
       e = depile(&p);
      i = e->i;
      j = e->j;
      tab[i][j] = cl;
      if (i-1 >= 0 && (couleurActuelle == tab[i-1][j])) {
 if (matriceIncr[i-1][j] == 0) {
   *taille = *taille+1;
   matriceIncr[i-1][j] = 1;
 }
 empile(&p, (i-1), j);
      }
      if (j-1 >= 0 && (couleurActuelle == tab[i][j-1])) {
 if (matriceIncr[i][j-1] == 0) {
   *taille = *taille+1;
   matriceIncr[i][j-1] = 1;
 }
 empile(&p, i, (j - 1));
      }
      if (i+1 < nbCases && (tab[i+1][j] == couleurActuelle)) {
 if (matriceIncr[i+1][j] == 0) {
   *taille = *taille+1;
   matriceIncr[i+1][j] = 1;
 }
 empile(&p, (i+1), j);
      }
      if (j+1 < nbCases && (tab[i][j+1] == couleurActuelle)) {
 if (matriceIncr[i][j+1] == 0) {
   *taille = *taille+1;
   matriceIncr[i][j+1] = 1;
 }
 empile(&p, i, (j+1));
      }
      printf("fin colorie_imp: taille %d\n", *taille);
      free(e);
    }
}

variable_types:
tab
int **

variable_types: i int

variable_types: j int

variable_types:
taille
int *

variable_types: nbCases int

variable_types:
matriceIncr
int **

variable_types: compteur int

variable_types: struct Element_pile { int i; int j; struct Element_pile *next; } *

variable_types: couleurActuelle int


decompiled_code:
__int64 __fastcall colorie_zone_rec(__int64 a1, int a2, int a3, unsigned int a4, _DWORD *a5, unsigned int a6)
{
__int64 v6; // r10
__int64 v7; // r14
__int64 *v8; // r11
__int64 result; // rax
int v10; // er15
__int64 v13; // [rsp+8h] [rbp-60h]
_DWORD *v14; // [rsp+8h] [rbp-60h]
_DWORD *v15; // [rsp+10h] [rbp-58h]
_DWORD *v16; // [rsp+10h] [rbp-58h]
_DWORD *v17; // [rsp+10h] [rbp-58h]
int v18; // [rsp+18h] [rbp-50h]
unsigned int v19; // [rsp+18h] [rbp-50h]
unsigned int v20; // [rsp+1Ch] [rbp-4Ch]
unsigned int v21; // [rsp+1Ch] [rbp-4Ch]
unsigned int v22; // [rsp+1Ch] [rbp-4Ch]
__int64 *v23; // [rsp+20h] [rbp-48h]
__int64 *v24; // [rsp+20h] [rbp-48h]
__int64 v25; // [rsp+28h] [rbp-40h]
__int64 v26; // [rsp+28h] [rbp-40h]

v6 = a3;
v7 = 8LL * a2;
v8 = (__int64 *)(a1 + v7);
v13 = 4LL * a3;
result = *(_QWORD *)(a1 + v7) + v13;
v10 = *(_DWORD *)result;
*(_DWORD *)result = a4;
if ( v10 != a4 )
{
if ( a2 > 0 && *(_DWORD *)(*(_QWORD *)(a1 + v7 - 8) + 4LL * a3) == v10 )
{
v25 = a3;
v20 = a6;
v15 = a5;
fprintf(stderr, "Going to: i->%d j->%d\n", (unsigned int)(a2 - 1), (unsigned int)a3);
colorie_zone_rec(a1, (unsigned int)(a2 - 1), (unsigned int)a3, a4, v15, v20);
v6 = v25;
v8 = (__int64 *)(a1 + v7);
a6 = v20;
a5 = v15;
}
if ( a3 > 0 && *(_DWORD *)(*v8 + v13 - 4) == v10 )
{
v26 = v6;
v23 = v8;
v21 = a6;
v16 = a5;
fprintf(stderr, "Going to: i->%d j->%d\n", (unsigned int)a2, (unsigned int)(a3 - 1));
colorie_zone_rec(a1, (unsigned int)a2, (unsigned int)(a3 - 1), a4, v16, v21);
v6 = v26;
v8 = v23;
a6 = v21;
a5 = v16;
}
result = a6 - 1;
v18 = result;
if ( (int)result > a2 )
{
result = *(_QWORD *)(a1 + v7 + 8);
if ( *(_DWORD *)(result + 4 * v6) == v10 )
{
v24 = v8;
v22 = a6;
v17 = a5;
fprintf(stderr, "Going to: i->%d j->%d\n", (unsigned int)(a2 + 1), (unsigned int)a3);
result = colorie_zone_rec(a1, (unsigned int)(a2 + 1), (unsigned int)a3, a4, v17, v22);
v8 = v24;
a6 = v22;
a5 = v17;
}
}
if ( v18 > a3 )
{
result = *v8;
if ( *(_DWORD *)(*v8 + v13 + 4) == v10 )
{
v19 = a6;
v14 = a5;
fprintf(stderr, "Going to: i->%d j->%d\n", (unsigned int)a2, (unsigned int)(a3 + 1));
result = colorie_zone_rec(a1, (unsigned int)a2, (unsigned int)(a3 + 1), a4, v14, v19);
a5 = v14;
}
}
++*a5;
}
return result;
}

original_code:
void colorie_zone_rec(int ** tab, int i, int j, int cl, int* taille, int nbCases)
{
  int couleurActuelle = tab[i][j];
  tab[i][j] = cl;
  if(cl == couleurActuelle)
    return;
  if ((i > 0) && (couleurActuelle == tab[i-1][j])) {
    fprintf(stderr, "Going to: i->%d j->%d\n", (i - 1), j);
    colorie_zone_rec(tab, (i-1), j, cl, taille, nbCases);
  }
  if ((j > 0) && (couleurActuelle == tab[i][j-1])) {
    fprintf(stderr, "Going to: i->%d j->%d\n", i, (j - 1));
    colorie_zone_rec(tab, i, (j-1), cl, taille, nbCases);
  }
  if ((i < (nbCases - 1)) && (tab[i+1][j] == couleurActuelle)) {
    fprintf(stderr, "Going to: i->%d j->%d\n", (i + 1), j);
    colorie_zone_rec(tab, (i+1), j, cl, taille, nbCases);
  }
  if( (j < (nbCases - 1)) && (tab[i][j+1] == couleurActuelle)) {
    fprintf(stderr, "Going to: i->%d j->%d\n", i, (j + 1));
    colorie_zone_rec(tab, i, (j+1), cl, taille, nbCases);
  }
  (*taille)++;
}

canonical_original_code:
void colorie_zone_rec(int **tab, int i, int j, int cl, int *taille, int nbCases)
{
  int couleurActuelle = tab[i][j];
  tab[i][j] = cl;
  if(cl == couleurActuelle)
    return;
  if ((i > 0) && (couleurActuelle == tab[i-1][j])) {
    fprintf(stderr, "Going to: i->%d j->%d\n", (i - 1), j);
    colorie_zone_rec(tab, (i-1), j, cl, taille, nbCases);
  }
  if ((j > 0) && (couleurActuelle == tab[i][j-1])) {
    fprintf(stderr, "Going to: i->%d j->%d\n", i, (j - 1));
    colorie_zone_rec(tab, i, (j-1), cl, taille, nbCases);
  }
  if ((i < (nbCases - 1)) && (tab[i+1][j] == couleurActuelle)) {
    fprintf(stderr, "Going to: i->%d j->%d\n", (i + 1), j);
    colorie_zone_rec(tab, (i+1), j, cl, taille, nbCases);
  }
  if( (j < (nbCases - 1)) && (tab[i][j+1] == couleurActuelle)) {
    fprintf(stderr, "Going to: i->%d j->%d\n", i, (j + 1));
    colorie_zone_rec(tab, i, (j+1), cl, taille, nbCases);
  }
  (*taille)++;
}

variable_types: cl int


decompiled_code:
__int64 __fastcall strategie_aleatoire_imp(__int64 a1, __int64 a2, int a3, int a4)
{
unsigned int v5; // eax
int v6; // eax
_QWORD *v7; // r14
unsigned int v8; // ebx
__int64 v9; // r15
__int64 v10; // rcx
__int64 v11; // rdx
unsigned int v13; // [rsp+Ch] [rbp-5Ch]
unsigned int v15[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v5 = time(0LL);
srand(v5);
v15[0] = 0;
printf("nbCases %d \n", (unsigned int)a3);
v13 = 0;
if ( a3 * a3 - 1 > 0 )
{
do
{
v6 = rand();
v7 = (_QWORD *)a2;
colorie_zone_imp(a2, 0, 0, v6 % a4, v15, a3);
printf(" ->%d ", v15[0]);
if ( a3 > 0 )
{
v8 = 0;
do
{
v9 = 0LL;
do
{
v10 = *(unsigned int *)(*v7 + 4 * v9);
v11 = (unsigned int)v9++;
Grille_chg_case(a1, v8, v11, v10);
}
while ( a3 != v9 );
++v8;
++v7;
}
while ( a3 != v8 );
}
Grille_redessine_Grille();
++v13;
Grille_attente_touche();
}
while ( (int)v15[0] < a3 * a3 - 1 );
}
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int a3, int a4)
{
unsigned int v5; // eax
int v6; // eax
_QWORD *v7; // r14
unsigned int v8; // ebx
__int64 v9; // r15
__int64 v10; // rcx
__int64 v11; // rdx
unsigned int v13; // [rsp+Ch] [rbp-5Ch]
unsigned int v15[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v5 = time(0LL);
srand(v5);
v15[0] = 0;
printf("nbCases %d \n", (unsigned int)a3);
v13 = 0;
if ( a3 * a3 - 1 > 0 )
{
do
{
v6 = rand();
v7 = (_QWORD *)a2;
func0(a2, 0, 0, v6 % a4, v15, a3);
printf(" ->%d ", v15[0]);
if ( a3 > 0 )
{
v8 = 0;
do
{
v9 = 0LL;
do
{
v10 = *(unsigned int *)(*v7 + 4 * v9);
v11 = (unsigned int)v9++;
Grille_chg_case(a1, v8, v11, v10);
}
while ( a3 != v9 );
++v8;
++v7;
}
while ( a3 != v8 );
}
Grille_redessine_Grille();
++v13;
Grille_attente_touche();
}
while ( (int)v15[0] < a3 * a3 - 1 );
}
return v13;
}

original_code:
int strategie_aleatoire_imp(Grille* G, int ** tab, int nbCases, int nbCl)
{
  srand(time(((void *)0)));
  int r, i, j, taille = 0, cpt = 0;
  printf("nbCases %d \n", nbCases);
  while(taille < nbCases*nbCases-1) {
    r = rand() % nbCl;
    colorie_zone_imp(tab, 0, 0, r, &taille, nbCases);
    printf(" ->%d  ", taille);
    for (i=0;i<nbCases; i++ )
      for (j=0;j<nbCases ;j++)
 Grille_chg_case(G,i,j,tab[i][j]);
    Grille_redessine_Grille();
    cpt++;
    Grille_attente_touche();
  }
  return cpt;
}

canonical_original_code:
int strategie_aleatoire_imp(struct grille *G, int **tab, int nbCases, int nbCl)
{
  srand(time(((void *)0)));
  int r; int i; int j; int taille = 0; int cpt = 0;
  printf("nbCases %d \n", nbCases);
  while(taille < nbCases*nbCases-1) {
    r = rand() % nbCl;
    colorie_zone_imp(tab, 0, 0, r, &taille, nbCases);
    printf(" ->%d  ", taille);
    for (i=0;i<nbCases; i++ )
      for (j=0;j<nbCases ;j++)
 Grille_chg_case(G,i,j,tab[i][j]);
    Grille_redessine_Grille();
    cpt++;
    Grille_attente_touche();
  }
  return cpt;
}

variable_types: nbCl int

variable_types: r int

variable_types: taille int

variable_types: cpt int

user_defined_types: struct grille { int nbcase; int nbcl; int taille_pixel; int cas_aff; int taille_case; int modulo; unsigned int *T_coul; }


decompiled_code:
__int64 __fastcall strategie_aleatoire_rec(__int64 a1, __int64 a2, signed int a3, int a4)
{
unsigned int v5; // eax
int v6; // eax
_QWORD *v7; // r14
unsigned int v8; // ebx
__int64 v9; // r15
__int64 v10; // rcx
__int64 v11; // rdx
unsigned int v13; // [rsp+Ch] [rbp-5Ch]
int v15[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v5 = time(0LL);
srand(v5);
v13 = 0;
if ( a3 * a3 )
{
do
{
v15[0] = 0;
v6 = rand();
v7 = (_QWORD *)a2;
colorie_zone_rec(a2, 0, 0, v6 % a4, v15, a3);
if ( a3 > 0 )
{
v8 = 0;
do
{
v9 = 0LL;
do
{
v10 = *(unsigned int *)(*v7 + 4 * v9);
v11 = (unsigned int)v9++;
Grille_chg_case(a1, v8, v11, v10);
}
while ( a3 != v9 );
++v8;
++v7;
}
while ( a3 != v8 );
}
Grille_redessine_Grille();
Grille_attente_touche();
++v13;
}
while ( v15[0] < a3 * a3 );
}
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, signed int a3, int a4)
{
unsigned int v5; // eax
int v6; // eax
_QWORD *v7; // r14
unsigned int v8; // ebx
__int64 v9; // r15
__int64 v10; // rcx
__int64 v11; // rdx
unsigned int v13; // [rsp+Ch] [rbp-5Ch]
int v15[15]; // [rsp+2Ch] [rbp-3Ch] BYREF

v5 = time(0LL);
srand(v5);
v13 = 0;
if ( a3 * a3 )
{
do
{
v15[0] = 0;
v6 = rand();
v7 = (_QWORD *)a2;
func1(a2, 0, 0, v6 % a4, v15, a3);
if ( a3 > 0 )
{
v8 = 0;
do
{
v9 = 0LL;
do
{
v10 = *(unsigned int *)(*v7 + 4 * v9);
v11 = (unsigned int)v9++;
Grille_chg_case(a1, v8, v11, v10);
}
while ( a3 != v9 );
++v8;
++v7;
}
while ( a3 != v8 );
}
Grille_redessine_Grille();
Grille_attente_touche();
++v13;
}
while ( v15[0] < a3 * a3 );
}
return v13;
}

original_code:
int strategie_aleatoire_rec(Grille* G, int ** tab, int nbCases, int nbCl)
{
  srand(time(((void *)0)));
  int r, i, j, taille = 0, cpt = 0;
  while(taille < (nbCases * nbCases)) {
    taille = 0;
    r = rand() % nbCl;
    colorie_zone_rec(tab, 0, 0, r, &taille, nbCases);
    for (i=0;i<nbCases; i++ )
      for (j=0;j<nbCases;j++)
 Grille_chg_case(G,i,j,tab[i][j]);
    Grille_redessine_Grille();
    Grille_attente_touche();
    cpt++;
  }
  return cpt;
}

canonical_original_code:
int strategie_aleatoire_rec(struct grille *G, int **tab, int nbCases, int nbCl)
{
  srand(time(((void *)0)));
  int r; int i; int j; int taille = 0; int cpt = 0;
  while(taille < (nbCases * nbCases)) {
    taille = 0;
    r = rand() % nbCl;
    colorie_zone_rec(tab, 0, 0, r, &taille, nbCases);
    for (i=0;i<nbCases; i++ )
      for (j=0;j<nbCases;j++)
 Grille_chg_case(G,i,j,tab[i][j]);
    Grille_redessine_Grille();
    Grille_attente_touche();
    cpt++;
  }
  return cpt;
}