original_code:
void assign_crowding_distance (NSGA2Type *nsga2Params, population *pop, int *dist, int **obj_array, int front_size)
{
    int i, j;
    for (i=0; i<nsga2Params->nobj; i++)
    {
        for (j=0; j<front_size; j++)
        {
            obj_array[i][j] = dist[j];
        }
        quicksort_front_obj (pop, i, obj_array[i], front_size);
    }
    for (j=0; j<front_size; j++)
    {
        pop->ind[dist[j]].crowd_dist = 0.0;
    }
    for (i=0; i<nsga2Params->nobj; i++)
    {
        pop->ind[obj_array[i][0]].crowd_dist = 1.0e14;
    }
    for (i=0; i<nsga2Params->nobj; i++)
    {
        for (j=1; j<front_size-1; j++)
        {
            if (pop->ind[obj_array[i][j]].crowd_dist != 1.0e14)
            {
                if (pop->ind[obj_array[i][front_size-1]].obj[i] == pop->ind[obj_array[i][0]].obj[i])
                {
                    pop->ind[obj_array[i][j]].crowd_dist += 0.0;
                }
                else
                {
                    pop->ind[obj_array[i][j]].crowd_dist += (pop->ind[obj_array[i][j+1]].obj[i] - pop->ind[obj_array[i][j-1]].obj[i])/(pop->ind[obj_array[i][front_size-1]].obj[i] - pop->ind[obj_array[i][0]].obj[i]);
                }
            }
        }
    }
    for (j=0; j<front_size; j++)
    {
        if (pop->ind[dist[j]].crowd_dist != 1.0e14)
        {
            pop->ind[dist[j]].crowd_dist = (pop->ind[dist[j]].crowd_dist)/nsga2Params->nobj;
        }
    }
    return;
}

canonical_original_code:
void assign_crowding_distance(struct NSGA2Type *nsga2Params, struct population *pop, int *dist, int **obj_array, int front_size)
{
    int i; int j;
    for (i=0; i<nsga2Params->nobj; i++)
    {
        for (j=0; j<front_size; j++)
        {
            obj_array[i][j] = dist[j];
        }
        quicksort_front_obj (pop, i, obj_array[i], front_size);
    }
    for (j=0; j<front_size; j++)
    {
        pop->ind[dist[j]].crowd_dist = 0.0;
    }
    for (i=0; i<nsga2Params->nobj; i++)
    {
        pop->ind[obj_array[i][0]].crowd_dist = 1.0e14;
    }
    for (i=0; i<nsga2Params->nobj; i++)
    {
        for (j=1; j<front_size-1; j++)
        {
            if (pop->ind[obj_array[i][j]].crowd_dist != 1.0e14)
            {
                if (pop->ind[obj_array[i][front_size-1]].obj[i] == pop->ind[obj_array[i][0]].obj[i])
                {
                    pop->ind[obj_array[i][j]].crowd_dist += 0.0;
                }
                else
                {
                    pop->ind[obj_array[i][j]].crowd_dist += (pop->ind[obj_array[i][j+1]].obj[i] - pop->ind[obj_array[i][j-1]].obj[i])/(pop->ind[obj_array[i][front_size-1]].obj[i] - pop->ind[obj_array[i][0]].obj[i]);
                }
            }
        }
    }
    for (j=0; j<front_size; j++)
    {
        if (pop->ind[dist[j]].crowd_dist != 1.0e14)
        {
            pop->ind[dist[j]].crowd_dist = (pop->ind[dist[j]].crowd_dist)/nsga2Params->nobj;
        }
    }
    return;
}

variable_types: struct population { struct individual { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist; } *ind; } *

variable_types: i int


original_code:
void assign_crowding_distance_list (NSGA2Type *nsga2Params, population *pop, list *lst, int front_size)
{
    int **obj_array;
    int *dist;
    int i, j;
    list *temp;
    temp = lst;
    if (front_size==1)
    {
        pop->ind[lst->index].crowd_dist = 1.0e14;
        return;
    }
    if (front_size==2)
    {
        pop->ind[lst->index].crowd_dist = 1.0e14;
        pop->ind[lst->child->index].crowd_dist = 1.0e14;
        return;
    }
    obj_array = (int **)malloc(nsga2Params->nobj*sizeof(int*));
    dist = (int *)malloc(front_size*sizeof(int));
    for (i=0; i<nsga2Params->nobj; i++)
    {
        obj_array[i] = (int *)malloc(front_size*sizeof(int));
    }
    for (j=0; j<front_size; j++)
    {
        dist[j] = temp->index;
        temp = temp->child;
    }
    assign_crowding_distance (nsga2Params, pop, dist, obj_array, front_size);
    free (dist);
    for (i=0; i<nsga2Params->nobj; i++)
    {
        free (obj_array[i]);
    }
    free (obj_array);
    return;
}

canonical_original_code:
void assign_crowding_distance_list(struct NSGA2Type *nsga2Params, struct population *pop, struct lists *lst, int front_size)
{
    int **obj_array;
    int *dist;
    int i; int j;
    struct lists *temp;
    temp = lst;
    if (front_size==1)
    {
        pop->ind[lst->index].crowd_dist = 1.0e14;
        return;
    }
    if (front_size==2)
    {
        pop->ind[lst->index].crowd_dist = 1.0e14;
        pop->ind[lst->child->index].crowd_dist = 1.0e14;
        return;
    }
    obj_array = (int **)malloc(nsga2Params->nobj*sizeof(int *));
    dist = (int *)malloc(front_size*sizeof(int));
    for (i=0; i<nsga2Params->nobj; i++)
    {
        obj_array[i] = (int *)malloc(front_size*sizeof(int));
    }
    for (j=0; j<front_size; j++)
    {
        dist[j] = temp->index;
        temp = temp->child;
    }
    assign_crowding_distance (nsga2Params, pop, dist, obj_array, front_size);
    free (dist);
    for (i=0; i<nsga2Params->nobj; i++)
    {
        free (obj_array[i]);
    }
    free (obj_array);
    return;
}

variable_types: struct NSGA2Type { double seed; int nreal; int nbin; int nobj; int ncon; int popsize; double pcross_real; double pcross_bin; double pmut_real; double pmut_bin; double eta_c; double eta_m; int ngen; int nbinmut; int nrealmut; int nbincross; int nrealcross; int *nbits; double *min_realvar; double *max_realvar; double *min_binvar; double *max_binvar; int bitlength; int choice; int obj1; int obj2; int obj3; int angle1; int angle2; } *

variable_types: struct lists { int index; struct lists *parent; struct lists *child; } *

variable_types:
dist
int *

variable_types: j int

return_type: void

user_defined_types: struct population { struct individual *ind; }

user_defined_types: struct individual { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist; }


original_code:
void assign_crowding_distance_indices (NSGA2Type *nsga2Params, population *pop, int c1, int c2)
{
    int **obj_array;
    int *dist;
    int i, j;
    int front_size;
    front_size = c2-c1+1;
    if (front_size==1)
    {
        pop->ind[c1].crowd_dist = 1.0e14;
        return;
    }
    if (front_size==2)
    {
        pop->ind[c1].crowd_dist = 1.0e14;
        pop->ind[c2].crowd_dist = 1.0e14;
        return;
    }
    obj_array = (int **)malloc(nsga2Params->nobj*sizeof(int*));
    dist = (int *)malloc(front_size*sizeof(int));
    for (i=0; i<nsga2Params->nobj; i++)
    {
        obj_array[i] = (int *)malloc(front_size*sizeof(int));
    }
    for (j=0; j<front_size; j++)
    {
        dist[j] = c1++;
    }
    assign_crowding_distance(nsga2Params, pop, dist, obj_array, front_size);
    free (dist);
    for (i=0; i<nsga2Params->nobj; i++)
    {
        free (obj_array[i]);
    }
    free (obj_array);
    return;
}

canonical_original_code:
void assign_crowding_distance_indices(struct NSGA2Type *nsga2Params, struct population *pop, int c1, int c2)
{
    int **obj_array;
    int *dist;
    int i; int j;
    int front_size;
    front_size = c2-c1+1;
    if (front_size==1)
    {
        pop->ind[c1].crowd_dist = 1.0e14;
        return;
    }
    if (front_size==2)
    {
        pop->ind[c1].crowd_dist = 1.0e14;
        pop->ind[c2].crowd_dist = 1.0e14;
        return;
    }
    obj_array = (int **)malloc(nsga2Params->nobj*sizeof(int *));
    dist = (int *)malloc(front_size*sizeof(int));
    for (i=0; i<nsga2Params->nobj; i++)
    {
        obj_array[i] = (int *)malloc(front_size*sizeof(int));
    }
    for (j=0; j<front_size; j++)
    {
        dist[j] = c1++;
    }
    assign_crowding_distance(nsga2Params, pop, dist, obj_array, front_size);
    free (dist);
    for (i=0; i<nsga2Params->nobj; i++)
    {
        free (obj_array[i]);
    }
    free (obj_array);
    return;
}

user_defined_types: struct NSGA2Type { double seed; int nreal; int nbin; int nobj; int ncon; int popsize; double pcross_real; double pcross_bin; double pmut_real; double pmut_bin; double eta_c; double eta_m; int ngen; int nbinmut; int nrealmut; int nbincross; int nrealcross; int *nbits; double *min_realvar; double *max_realvar; double *min_binvar; double *max_binvar; int bitlength; int choice; int obj1; int obj2; int obj3; int angle1; int angle2; }


original_code:
void bin_mutate_ind (NSGA2Type *nsga2Params, individual *ind)
{
    int j, k;
    double prob;
    for (j=0; j<nsga2Params->nbin; j++)
    {
        for (k=0; k<nsga2Params->nbits[j]; k++)
        {
            prob = randomperc();
            if (prob <=nsga2Params->pmut_bin)
            {
                if (ind->gene[j][k] == 0)
                {
                    ind->gene[j][k] = 1;
                }
                else
                {
                    ind->gene[j][k] = 0;
                }
                nsga2Params->nbinmut+=1;
            }
        }
    }
    return;
}

canonical_original_code:
void bin_mutate_ind(struct NSGA2Type *nsga2Params, struct individual *ind)
{
    int j; int k;
    double prob;
    for (j=0; j<nsga2Params->nbin; j++)
    {
        for (k=0; k<nsga2Params->nbits[j]; k++)
        {
            prob = randomperc();
            if (prob <=nsga2Params->pmut_bin)
            {
                if (ind->gene[j][k] == 0)
                {
                    ind->gene[j][k] = 1;
                }
                else
                {
                    ind->gene[j][k] = 0;
                }
                nsga2Params->nbinmut+=1;
            }
        }
    }
    return;
}

variable_types: struct individual { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist; } *

variable_types: k int

variable_types: prob double


original_code:
void real_mutate_ind (NSGA2Type *nsga2Params, individual *ind)
{
    int j;
    double rnd, delta1, delta2, mut_pow, deltaq;
    double y, yl, yu, val, xy;
    for (j=0; j<nsga2Params->nreal; j++)
    {
        if (randomperc() <= nsga2Params->pmut_real)
        {
            y = ind->xreal[j];
            yl = nsga2Params->min_realvar[j];
            yu = nsga2Params->max_realvar[j];
            delta1 = (y-yl)/(yu-yl);
            delta2 = (yu-y)/(yu-yl);
            rnd = randomperc();
            mut_pow = 1.0/(nsga2Params->eta_m+1.0);
            if (rnd <= 0.5)
            {
                xy = 1.0-delta1;
                val = 2.0*rnd+(1.0-2.0*rnd)*(pow(xy,(nsga2Params->eta_m+1.0)));
                deltaq = pow(val,mut_pow) - 1.0;
            }
            else
            {
                xy = 1.0-delta2;
                val = 2.0*(1.0-rnd)+2.0*(rnd-0.5)*(pow(xy,(nsga2Params->eta_m+1.0)));
                deltaq = 1.0 - (pow(val,mut_pow));
            }
            y = y + deltaq*(yu-yl);
            if (y<yl)
                y = yl;
            if (y>yu)
                y = yu;
            ind->xreal[j] = y;
            nsga2Params->nrealmut+=1;
        }
    }
    return;
}

canonical_original_code:
void real_mutate_ind(struct NSGA2Type *nsga2Params, struct individual *ind)
{
    int j;
    double rnd; double delta1; double delta2; double mut_pow; double deltaq;
    double y; double yl; double yu; double val; double xy;
    for (j=0; j<nsga2Params->nreal; j++)
    {
        if (randomperc() <= nsga2Params->pmut_real)
        {
            y = ind->xreal[j];
            yl = nsga2Params->min_realvar[j];
            yu = nsga2Params->max_realvar[j];
            delta1 = (y-yl)/(yu-yl);
            delta2 = (yu-y)/(yu-yl);
            rnd = randomperc();
            mut_pow = 1.0/(nsga2Params->eta_m+1.0);
            if (rnd <= 0.5)
            {
                xy = 1.0-delta1;
                val = 2.0*rnd+(1.0-2.0*rnd)*(pow(xy,(nsga2Params->eta_m+1.0)));
                deltaq = pow(val,mut_pow) - 1.0;
            }
            else
            {
                xy = 1.0-delta2;
                val = 2.0*(1.0-rnd)+2.0*(rnd-0.5)*(pow(xy,(nsga2Params->eta_m+1.0)));
                deltaq = 1.0 - (pow(val,mut_pow));
            }
            y = y + deltaq*(yu-yl);
            if (y<yl)
                y = yl;
            if (y>yu)
                y = yu;
            ind->xreal[j] = y;
            nsga2Params->nrealmut+=1;
        }
    }
    return;
}

variable_types: rnd double

variable_types: deltaq double

variable_types: y double

variable_types: yl double

variable_types: yu double

variable_types: val double

variable_types: xy double


decompiled_code:
void __fastcall mutation_ind(__int64 a1, __int64 a2)
{
if ( *(_DWORD *)(a1 + 8) )
real_mutate_ind(a1, a2);
if ( *(_DWORD *)(a1 + 12) )
bin_mutate_ind(a1, a2);
}

original_code:
void mutation_ind (NSGA2Type *nsga2Params, individual *ind)
{
    if (nsga2Params->nreal!=0)
    {
        real_mutate_ind(nsga2Params, ind);
    }
    if (nsga2Params->nbin!=0)
    {
        bin_mutate_ind(nsga2Params, ind);
    }
    return;
}

canonical_original_code:
void mutation_ind(struct NSGA2Type *nsga2Params, struct individual *ind)
{
    if (nsga2Params->nreal!=0)
    {
        real_mutate_ind(nsga2Params, ind);
    }
    if (nsga2Params->nbin!=0)
    {
        bin_mutate_ind(nsga2Params, ind);
    }
    return;
}


decompiled_code:
void __fastcall mutation_pop(__int64 a1, _QWORD *a2)
{
__int64 v2; // rbx

if ( *(int *)(a1 + 24) > 0 )
{
v2 = 0LL;
do
mutation_ind(a1, *a2 + (v2++ << 6));
while ( *(_DWORD *)(a1 + 24) > (int)v2 );
}
}

original_code:
void mutation_pop (NSGA2Type *nsga2Params, population *pop)
{
    int i;
    for (i=0; i<nsga2Params->popsize; i++)
    {
        mutation_ind(nsga2Params, &(pop->ind[i]));
    }
    return;
}

canonical_original_code:
void mutation_pop(struct NSGA2Type *nsga2Params, struct population *pop)
{
    int i;
    for (i=0; i<nsga2Params->popsize; i++)
    {
        mutation_ind(nsga2Params, &(pop->ind[i]));
    }
    return;
}


decompiled_code:
void *__fastcall allocate_memory_pop(__int64 a1, _QWORD *a2, int a3)
{
void *result; // rax
unsigned __int64 v5; // rbp
__int64 v6; // rbx

result = malloc((__int64)a3 << 6);
*a2 = result;
if ( a3 > 0 )
{
v5 = (unsigned __int64)(unsigned int)a3 << 6;
v6 = 0LL;
do
{
result = allocate_memory_ind(a1, (_QWORD *)(*a2 + v6));
v6 += 64LL;
}
while ( v6 != v5 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, _QWORD *a2, int a3)
{
void *result; // rax
unsigned __int64 v5; // rbp
__int64 v6; // rbx

result = malloc((__int64)a3 << 6);
*a2 = result;
if ( a3 > 0 )
{
v5 = (unsigned __int64)(unsigned int)a3 << 6;
v6 = 0LL;
do
{
result = func0(a1, (_QWORD *)(*a2 + v6));
v6 += 64LL;
}
while ( v6 != v5 );
}
return result;
}

original_code:
void allocate_memory_pop (NSGA2Type *nsga2Params, population *pop, int size)
{
    int i;
    pop->ind = (individual *)malloc(size*sizeof(individual));
    for (i=0; i<size; i++)
    {
        allocate_memory_ind (nsga2Params, &(pop->ind[i]));
    }
    return;
}

canonical_original_code:
void allocate_memory_pop(struct NSGA2Type *nsga2Params, struct population *pop, int size)
{
    int i;
    pop->ind = (struct individual *)malloc(size*sizeof(individual));
    for (i=0; i<size; i++)
    {
        allocate_memory_ind (nsga2Params, &(pop->ind[i]));
    }
    return;
}

variable_types: size int


original_code:
void deallocate_memory_ind (NSGA2Type *nsga2Params, individual *ind)
{
    int j;
    if (nsga2Params->nreal != 0)
    {
        free(ind->xreal);
    }
    if (nsga2Params->nbin != 0)
    {
        for (j=0; j<nsga2Params->nbin; j++)
        {
            free(ind->gene[j]);
        }
        free(ind->xbin);
        free(ind->gene);
    }
    free(ind->obj);
    if (nsga2Params->ncon != 0)
    {
        free(ind->constr);
    }
    return;
}

canonical_original_code:
void deallocate_memory_ind(struct NSGA2Type *nsga2Params, struct individual *ind)
{
    int j;
    if (nsga2Params->nreal != 0)
    {
        free(ind->xreal);
    }
    if (nsga2Params->nbin != 0)
    {
        for (j=0; j<nsga2Params->nbin; j++)
        {
            free(ind->gene[j]);
        }
        free(ind->xbin);
        free(ind->gene);
    }
    free(ind->obj);
    if (nsga2Params->ncon != 0)
    {
        free(ind->constr);
    }
    return;
}


decompiled_code:
void __fastcall deallocate_memory_pop(_DWORD *a1, void **a2, int a3)
{
unsigned __int64 v3; // rbp
__int64 v4; // rbx

if ( a3 > 0 )
{
v3 = (unsigned __int64)(unsigned int)a3 << 6;
v4 = 0LL;
do
{
deallocate_memory_ind(a1, (void **)((char *)*a2 + v4));
v4 += 64LL;
}
while ( v4 != v3 );
}
free(*a2);
}

canonical_decompiled_code:
void __fastcall func3(_DWORD *a1, void **a2, int a3)
{
unsigned __int64 v3; // rbp
__int64 v4; // rbx

if ( a3 > 0 )
{
v3 = (unsigned __int64)(unsigned int)a3 << 6;
v4 = 0LL;
do
{
func2(a1, (void **)((char *)*a2 + v4));
v4 += 64LL;
}
while ( v4 != v3 );
}
free(*a2);
}

original_code:
void deallocate_memory_pop (NSGA2Type *nsga2Params, population *pop, int size)
{
    int i;
    for (i=0; i<size; i++)
    {
        deallocate_memory_ind (nsga2Params, &(pop->ind[i]));
    }
    free (pop->ind);
    return;
}

canonical_original_code:
void deallocate_memory_pop(struct NSGA2Type *nsga2Params, struct population *pop, int size)
{
    int i;
    for (i=0; i<size; i++)
    {
        deallocate_memory_ind (nsga2Params, &(pop->ind[i]));
    }
    free (pop->ind);
    return;
}

variable_types: struct population { struct individual { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist; } *ind; } *


original_code:
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
    double g;
    g = 1.0 + xreal[1];
    obj[0] = xreal[0];
    obj[1] = g*exp(-obj[0]/g);
    constr[0] = obj[1]/(0.858*exp(-0.541*obj[0]))-1.0;
    constr[1] = obj[1]/(0.728*exp(-0.295*obj[0]))-1.0;
    return;
}

canonical_original_code:
void test_problem(double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
    double g;
    g = 1.0 + xreal[1];
    obj[0] = xreal[0];
    obj[1] = g*exp(-obj[0]/g);
    constr[0] = obj[1]/(0.858*exp(-0.541*obj[0]))-1.0;
    constr[1] = obj[1]/(0.728*exp(-0.295*obj[0]))-1.0;
    return;
}

variable_types:
xreal
double *

variable_types:
xbin
double *

variable_types:
gene
int **

variable_types:
obj
double *

variable_types:
constr
double *

variable_types: g double


tournament

original_code:
individual* tournament (NSGA2Type *nsga2Params, individual *ind1, individual *ind2)
{
    int flag;
    flag = check_dominance (nsga2Params, ind1, ind2);
    if (flag==1)
    {
        return (ind1);
    }
    if (flag==-1)
    {
        return (ind2);
    }
    if (ind1->crowd_dist > ind2->crowd_dist)
    {
        return(ind1);
    }
    if (ind2->crowd_dist > ind1->crowd_dist)
    {
        return(ind2);
    }
    if ((randomperc()) <= 0.5)
    {
        return(ind1);
    }
    else
    {
        return(ind2);
    }
}

canonical_original_code:
struct individual *tournament(struct NSGA2Type *nsga2Params, struct individual *ind1, struct individual *ind2)
{
    int flag;
    flag = check_dominance (nsga2Params, ind1, ind2);
    if (flag==1)
    {
        return (ind1);
    }
    if (flag==-1)
    {
        return (ind2);
    }
    if (ind1->crowd_dist > ind2->crowd_dist)
    {
        return(ind1);
    }
    if (ind2->crowd_dist > ind1->crowd_dist)
    {
        return(ind2);
    }
    if ((randomperc()) <= 0.5)
    {
        return(ind1);
    }
    else
    {
        return(ind2);
    }
}

variable_types: struct NSGA2Type { double seed; int nreal; int nbin; int nobj; int ncon; int popsize; double pcross_real; double pcross_bin; double pmut_real; double pmut_bin; double eta_c; double eta_m; int ngen; int nbinmut; int nrealmut; int nbincross; int nrealcross; int *nbits; double *min_realvar; double *max_realvar; double *min_binvar; double *max_binvar; int bitlength; int choice; int obj1; int obj2; int obj3; int angle1; int angle2; } *

variable_types: flag int

return_type: struct individual { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist; } *


selection

original_code:
void selection (NSGA2Type *nsga2Params, population *old_pop, population *new_pop)
{
    int *a1, *a2;
    int temp;
    int i;
    int rand;
    individual *parent1, *parent2;
    a1 = (int *)malloc(nsga2Params->popsize*sizeof(int));
    a2 = (int *)malloc(nsga2Params->popsize*sizeof(int));
    for (i=0; i<nsga2Params->popsize; i++)
    {
        a1[i] = a2[i] = i;
    }
    for (i=0; i<nsga2Params->popsize; i++)
    {
        rand = rnd (i, nsga2Params->popsize-1);
        temp = a1[rand];
        a1[rand] = a1[i];
        a1[i] = temp;
        rand = rnd (i, nsga2Params->popsize-1);
        temp = a2[rand];
        a2[rand] = a2[i];
        a2[i] = temp;
    }
    for (i=0; i<nsga2Params->popsize; i+=4)
    {
        parent1 = tournament (nsga2Params, &old_pop->ind[a1[i]], &old_pop->ind[a1[i+1]]);
        parent2 = tournament (nsga2Params, &old_pop->ind[a1[i+2]], &old_pop->ind[a1[i+3]]);
        crossover (nsga2Params, parent1, parent2, &new_pop->ind[i], &new_pop->ind[i+1]);
        parent1 = tournament (nsga2Params, &old_pop->ind[a2[i]], &old_pop->ind[a2[i+1]]);
        parent2 = tournament (nsga2Params, &old_pop->ind[a2[i+2]], &old_pop->ind[a2[i+3]]);
        crossover (nsga2Params, parent1, parent2, &new_pop->ind[i+2], &new_pop->ind[i+3]);
    }
    free (a1);
    free (a2);
    return;
}

canonical_original_code:
void selection(struct NSGA2Type *nsga2Params, struct population *old_pop, struct population *new_pop)
{
    int *a1; int *a2;
    int temp;
    int i;
    int rand;
    struct individual *parent1; struct individual *parent2;
    a1 = (int *)malloc(nsga2Params->popsize*sizeof(int));
    a2 = (int *)malloc(nsga2Params->popsize*sizeof(int));
    for (i=0; i<nsga2Params->popsize; i++)
    {
        a1[i] = a2[i] = i;
    }
    for (i=0; i<nsga2Params->popsize; i++)
    {
        rand = rnd (i, nsga2Params->popsize-1);
        temp = a1[rand];
        a1[rand] = a1[i];
        a1[i] = temp;
        rand = rnd (i, nsga2Params->popsize-1);
        temp = a2[rand];
        a2[rand] = a2[i];
        a2[i] = temp;
    }
    for (i=0; i<nsga2Params->popsize; i+=4)
    {
        parent1 = tournament (nsga2Params, &old_pop->ind[a1[i]], &old_pop->ind[a1[i+1]]);
        parent2 = tournament (nsga2Params, &old_pop->ind[a1[i+2]], &old_pop->ind[a1[i+3]]);
        crossover (nsga2Params, parent1, parent2, &new_pop->ind[i], &new_pop->ind[i+1]);
        parent1 = tournament (nsga2Params, &old_pop->ind[a2[i]], &old_pop->ind[a2[i+1]]);
        parent2 = tournament (nsga2Params, &old_pop->ind[a2[i+2]], &old_pop->ind[a2[i+3]]);
        crossover (nsga2Params, parent1, parent2, &new_pop->ind[i+2], &new_pop->ind[i+3]);
    }
    free (a1);
    free (a2);
    return;
}

variable_types: temp int

variable_types: i int

variable_types: rand int

variable_types: struct individual { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist; } *


original_code:
int check_dominance (NSGA2Type *nsga2Params, individual *a, individual *b)
{
    int i;
    int flag1;
    int flag2;
    flag1 = 0;
    flag2 = 0;
    if (a->constr_violation<0 && b->constr_violation<0)
    {
        if (a->constr_violation > b->constr_violation)
        {
            return (1);
        }
        else
        {
            if (a->constr_violation < b->constr_violation)
            {
                return (-1);
            }
            else
            {
                return (0);
            }
        }
    }
    else
    {
        if (a->constr_violation < 0 && b->constr_violation == 0)
        {
            return (-1);
        }
        else
        {
            if (a->constr_violation == 0 && b->constr_violation <0)
            {
                return (1);
            }
            else
            {
                for (i=0; i<nsga2Params->nobj; i++)
                {
                    if (a->obj[i] < b->obj[i])
                    {
                        flag1 = 1;
                    }
                    else
                    {
                        if (a->obj[i] > b->obj[i])
                        {
                            flag2 = 1;
                        }
                    }
                }
                if (flag1==1 && flag2==0)
                {
                    return (1);
                }
                else
                {
                    if (flag1==0 && flag2==1)
                    {
                        return (-1);
                    }
                    else
                    {
                        return (0);
                    }
                }
            }
        }
    }
}

canonical_original_code:
int check_dominance(struct NSGA2Type *nsga2Params, struct individual *a, struct individual *b)
{
    int i;
    int flag1;
    int flag2;
    flag1 = 0;
    flag2 = 0;
    if (a->constr_violation<0 && b->constr_violation<0)
    {
        if (a->constr_violation > b->constr_violation)
        {
            return (1);
        }
        else
        {
            if (a->constr_violation < b->constr_violation)
            {
                return (-1);
            }
            else
            {
                return (0);
            }
        }
    }
    else
    {
        if (a->constr_violation < 0 && b->constr_violation == 0)
        {
            return (-1);
        }
        else
        {
            if (a->constr_violation == 0 && b->constr_violation <0)
            {
                return (1);
            }
            else
            {
                for (i=0; i<nsga2Params->nobj; i++)
                {
                    if (a->obj[i] < b->obj[i])
                    {
                        flag1 = 1;
                    }
                    else
                    {
                        if (a->obj[i] > b->obj[i])
                        {
                            flag2 = 1;
                        }
                    }
                }
                if (flag1==1 && flag2==0)
                {
                    return (1);
                }
                else
                {
                    if (flag1==0 && flag2==1)
                    {
                        return (-1);
                    }
                    else
                    {
                        return (0);
                    }
                }
            }
        }
    }
}

variable_types:
b
struct individual *

return_type: int


original_code:
void initialize_ind (NSGA2Type *nsga2Params, individual *ind)
{
    int j, k;
    if (nsga2Params->nreal!=0)
    {
        for (j=0; j<nsga2Params->nreal; j++)
        {
            ind->xreal[j] = rndreal (nsga2Params->min_realvar[j], nsga2Params->max_realvar[j]);
        }
    }
    if (nsga2Params->nbin!=0)
    {
        for (j=0; j<nsga2Params->nbin; j++)
        {
            for (k=0; k<nsga2Params->nbits[j]; k++)
            {
                if (randomperc() <= 0.5)
                {
                    ind->gene[j][k] = 0;
                }
                else
                {
                    ind->gene[j][k] = 1;
                }
            }
        }
    }
    return;
}

canonical_original_code:
void initialize_ind(struct NSGA2Type *nsga2Params, struct individual *ind)
{
    int j; int k;
    if (nsga2Params->nreal!=0)
    {
        for (j=0; j<nsga2Params->nreal; j++)
        {
            ind->xreal[j] = rndreal (nsga2Params->min_realvar[j], nsga2Params->max_realvar[j]);
        }
    }
    if (nsga2Params->nbin!=0)
    {
        for (j=0; j<nsga2Params->nbin; j++)
        {
            for (k=0; k<nsga2Params->nbits[j]; k++)
            {
                if (randomperc() <= 0.5)
                {
                    ind->gene[j][k] = 0;
                }
                else
                {
                    ind->gene[j][k] = 1;
                }
            }
        }
    }
    return;
}

variable_types: j int

variable_types: k int


decompiled_code:
void __fastcall initialize_pop(__int64 a1, _QWORD *a2)
{
__int64 v2; // rbx

if ( *(int *)(a1 + 24) > 0 )
{
v2 = 0LL;
do
initialize_ind(a1, *a2 + (v2++ << 6));
while ( *(_DWORD *)(a1 + 24) > (int)v2 );
}
}

original_code:
void initialize_pop (NSGA2Type *nsga2Params, population *pop)
{
    int i;
    for (i=0; i<nsga2Params->popsize; i++)
    {
        initialize_ind (nsga2Params, &(pop->ind[i]));
    }
    return;
}

canonical_original_code:
void initialize_pop(struct NSGA2Type *nsga2Params, struct population *pop)
{
    int i;
    for (i=0; i<nsga2Params->popsize; i++)
    {
        initialize_ind (nsga2Params, &(pop->ind[i]));
    }
    return;
}


original_code:
void crowding_fill (NSGA2Type *nsga2Params, population *mixed_pop, population *new_pop, int count, int front_size, list *elite)
{
    int *dist;
    list *temp;
    int i, j;
    assign_crowding_distance_list (nsga2Params, mixed_pop, elite->child, front_size);
    dist = (int *)malloc(front_size*sizeof(int));
    temp = elite->child;
    for (j=0; j<front_size; j++)
    {
        dist[j] = temp->index;
        temp = temp->child;
    }
    quicksort_dist (mixed_pop, dist, front_size);
    for (i=count, j=front_size-1; i<nsga2Params->popsize; i++, j--)
    {
        copy_ind(nsga2Params, &mixed_pop->ind[dist[j]], &new_pop->ind[i]);
    }
    free (dist);
    return;
}

canonical_original_code:
void crowding_fill(struct NSGA2Type *nsga2Params, struct population *mixed_pop, struct population *new_pop, int count, int front_size, struct lists *elite)
{
    int *dist;
    struct lists *temp;
    int i; int j;
    assign_crowding_distance_list (nsga2Params, mixed_pop, elite->child, front_size);
    dist = (int *)malloc(front_size*sizeof(int));
    temp = elite->child;
    for (j=0; j<front_size; j++)
    {
        dist[j] = temp->index;
        temp = temp->child;
    }
    quicksort_dist (mixed_pop, dist, front_size);
    for (i=count, j=front_size-1; i<nsga2Params->popsize; i++, j--)
    {
        copy_ind(nsga2Params, &mixed_pop->ind[dist[j]], &new_pop->ind[i]);
    }
    free (dist);
    return;
}

variable_types: count int

variable_types: struct lists { int index; struct lists *parent; struct lists *child; } *

variable_types:
dist
int *


original_code:
void fill_nondominated_sort (NSGA2Type *nsga2Params, population *mixed_pop, population *new_pop)
{
    int flag;
    int i, j;
    int end;
    int front_size;
    int archieve_size;
    int rank=1;
    list *pool;
    list *elite;
    list *temp1, *temp2;
    pool = (list *)malloc(sizeof(list));
    elite = (list *)malloc(sizeof(list));
    front_size = 0;
    archieve_size=0;
    pool->index = -1;
    pool->parent = ((void *)0);
    pool->child = ((void *)0);
    elite->index = -1;
    elite->parent = ((void *)0);
    elite->child = ((void *)0);
    temp1 = pool;
    for (i=0; i<2*nsga2Params->popsize; i++)
    {
        insert (temp1,i);
        temp1 = temp1->child;
    }
    i=0;
    do
    {
        temp1 = pool->child;
        insert (elite, temp1->index);
        front_size = 1;
        temp2 = elite->child;
        temp1 = del (temp1);
        temp1 = temp1->child;
        do
        {
            temp2 = elite->child;
            if (temp1==((void *)0))
            {
                break;
            }
            do
            {
                end = 0;
                flag = check_dominance (nsga2Params, &(mixed_pop->ind[temp1->index]), &(mixed_pop->ind[temp2->index]));
                if (flag == 1)
                {
                    insert (pool, temp2->index);
                    temp2 = del (temp2);
                    front_size--;
                    temp2 = temp2->child;
                }
                if (flag == 0)
                {
                    temp2 = temp2->child;
                }
                if (flag == -1)
                {
                    end = 1;
                }
            }
            while (end!=1 && temp2!=((void *)0));
            if (flag == 0 || flag == 1)
            {
                insert (elite, temp1->index);
                front_size++;
                temp1 = del (temp1);
            }
            temp1 = temp1->child;
        }
        while (temp1 != ((void *)0));
        temp2 = elite->child;
        j=i;
        if ( (archieve_size+front_size) <= nsga2Params->popsize)
        {
            do
            {
                copy_ind (nsga2Params, &mixed_pop->ind[temp2->index], &new_pop->ind[i]);
                new_pop->ind[i].rank = rank;
                archieve_size+=1;
                temp2 = temp2->child;
                i+=1;
            }
            while (temp2 != ((void *)0));
            assign_crowding_distance_indices (nsga2Params, new_pop, j, i-1);
            rank+=1;
        }
        else
        {
            crowding_fill (nsga2Params, mixed_pop, new_pop, i, front_size, elite);
            archieve_size = nsga2Params->popsize;
            for (j=i; j<nsga2Params->popsize; j++)
            {
                new_pop->ind[j].rank = rank;
            }
        }
        temp2 = elite->child;
        do
        {
            temp2 = del (temp2);
            temp2 = temp2->child;
        }
        while (elite->child !=((void *)0));
    }
    while (archieve_size < nsga2Params->popsize);
    while (pool!=((void *)0))
    {
        temp1 = pool;
        pool = pool->child;
        free (temp1);
    }
    while (elite!=((void *)0))
    {
        temp1 = elite;
        elite = elite->child;
        free (temp1);
    }
    return;
}

canonical_original_code:
void fill_nondominated_sort(struct NSGA2Type *nsga2Params, struct population *mixed_pop, struct population *new_pop)
{
    int flag;
    int i; int j;
    int end;
    int front_size;
    int archieve_size;
    int rank = 1;
    struct lists *pool;
    struct lists *elite;
    struct lists *temp1; struct lists *temp2;
    pool = (struct lists *)malloc(sizeof(list));
    elite = (struct lists *)malloc(sizeof(list));
    front_size = 0;
    archieve_size=0;
    pool->index = -1;
    pool->parent = ((void *)0);
    pool->child = ((void *)0);
    elite->index = -1;
    elite->parent = ((void *)0);
    elite->child = ((void *)0);
    temp1 = pool;
    for (i=0; i<2*nsga2Params->popsize; i++)
    {
        insert (temp1,i);
        temp1 = temp1->child;
    }
    i=0;
    do
    {
        temp1 = pool->child;
        insert (elite, temp1->index);
        front_size = 1;
        temp2 = elite->child;
        temp1 = del (temp1);
        temp1 = temp1->child;
        do
        {
            temp2 = elite->child;
            if (temp1==((void *)0))
            {
                break;
            }
            do
            {
                end = 0;
                flag = check_dominance (nsga2Params, &(mixed_pop->ind[temp1->index]), &(mixed_pop->ind[temp2->index]));
                if (flag == 1)
                {
                    insert (pool, temp2->index);
                    temp2 = del (temp2);
                    front_size--;
                    temp2 = temp2->child;
                }
                if (flag == 0)
                {
                    temp2 = temp2->child;
                }
                if (flag == -1)
                {
                    end = 1;
                }
            }
            while (end!=1 && temp2!=((void *)0));
            if (flag == 0 || flag == 1)
            {
                insert (elite, temp1->index);
                front_size++;
                temp1 = del (temp1);
            }
            temp1 = temp1->child;
        }
        while (temp1 != ((void *)0));
        temp2 = elite->child;
        j=i;
        if ( (archieve_size+front_size) <= nsga2Params->popsize)
        {
            do
            {
                copy_ind (nsga2Params, &mixed_pop->ind[temp2->index], &new_pop->ind[i]);
                new_pop->ind[i].rank = rank;
                archieve_size+=1;
                temp2 = temp2->child;
                i+=1;
            }
            while (temp2 != ((void *)0));
            assign_crowding_distance_indices (nsga2Params, new_pop, j, i-1);
            rank+=1;
        }
        else
        {
            crowding_fill (nsga2Params, mixed_pop, new_pop, i, front_size, elite);
            archieve_size = nsga2Params->popsize;
            for (j=i; j<nsga2Params->popsize; j++)
            {
                new_pop->ind[j].rank = rank;
            }
        }
        temp2 = elite->child;
        do
        {
            temp2 = del (temp2);
            temp2 = temp2->child;
        }
        while (elite->child !=((void *)0));
    }
    while (archieve_size < nsga2Params->popsize);
    while (pool!=((void *)0))
    {
        temp1 = pool;
        pool = pool->child;
        free (temp1);
    }
    while (elite!=((void *)0))
    {
        temp1 = elite;
        elite = elite->child;
        free (temp1);
    }
    return;
}

variable_types: struct population { struct individual { int rank; double constr_violation; double *xreal; int **gene; double *xbin; double *obj; double *constr; double crowd_dist; } *ind; } *

variable_types: end int

variable_types: rank int

user_defined_types: struct lists { int index; struct lists *parent; struct lists *child; }


original_code:
void assign_rank_and_crowding_distance (NSGA2Type *nsga2Params, population *new_pop)
{
    int flag;
    int i;
    int end;
    int front_size;
    int rank=1;
    list *orig;
    list *cur;
    list *temp1, *temp2;
    orig = (list *)malloc(sizeof(list));
    cur = (list *)malloc(sizeof(list));
    front_size = 0;
    orig->index = -1;
    orig->parent = ((void *)0);
    orig->child = ((void *)0);
    cur->index = -1;
    cur->parent = ((void *)0);
    cur->child = ((void *)0);
    temp1 = orig;
    for (i=0; i<nsga2Params->popsize; i++)
    {
        insert (temp1,i);
        temp1 = temp1->child;
    }
    do
    {
        if (orig->child->child == ((void *)0))
        {
            new_pop->ind[orig->child->index].rank = rank;
            new_pop->ind[orig->child->index].crowd_dist = 1.0e14;
            break;
        }
        temp1 = orig->child;
        insert (cur, temp1->index);
        front_size = 1;
        temp2 = cur->child;
        temp1 = del (temp1);
        temp1 = temp1->child;
        do
        {
            temp2 = cur->child;
            do
            {
                end = 0;
                flag = check_dominance (nsga2Params, &(new_pop->ind[temp1->index]), &(new_pop->ind[temp2->index]));
                if (flag == 1)
                {
                    insert (orig, temp2->index);
                    temp2 = del (temp2);
                    front_size--;
                    temp2 = temp2->child;
                }
                if (flag == 0)
                {
                    temp2 = temp2->child;
                }
                if (flag == -1)
                {
                    end = 1;
                }
            }
            while (end!=1 && temp2!=((void *)0));
            if (flag == 0 || flag == 1)
            {
                insert (cur, temp1->index);
                front_size++;
                temp1 = del (temp1);
            }
            temp1 = temp1->child;
        }
        while (temp1 != ((void *)0));
        temp2 = cur->child;
        do
        {
            new_pop->ind[temp2->index].rank = rank;
            temp2 = temp2->child;
        }
        while (temp2 != ((void *)0));
        assign_crowding_distance_list (nsga2Params, new_pop, cur->child, front_size);
        temp2 = cur->child;
        do
        {
            temp2 = del (temp2);
            temp2 = temp2->child;
        }
        while (cur->child !=((void *)0));
        rank+=1;
    }
    while (orig->child!=((void *)0));
    free (orig);
    free (cur);
    return;
}

canonical_original_code:
void assign_rank_and_crowding_distance(struct NSGA2Type *nsga2Params, struct population *new_pop)
{
    int flag;
    int i;
    int end;
    int front_size;
    int rank = 1;
    struct lists *orig;
    struct lists *cur;
    struct lists *temp1; struct lists *temp2;
    orig = (struct lists *)malloc(sizeof(list));
    cur = (struct lists *)malloc(sizeof(list));
    front_size = 0;
    orig->index = -1;
    orig->parent = ((void *)0);
    orig->child = ((void *)0);
    cur->index = -1;
    cur->parent = ((void *)0);
    cur->child = ((void *)0);
    temp1 = orig;
    for (i=0; i<nsga2Params->popsize; i++)
    {
        insert (temp1,i);
        temp1 = temp1->child;
    }
    do
    {
        if (orig->child->child == ((void *)0))
        {
            new_pop->ind[orig->child->index].rank = rank;
            new_pop->ind[orig->child->index].crowd_dist = 1.0e14;
            break;
        }
        temp1 = orig->child;
        insert (cur, temp1->index);
        front_size = 1;
        temp2 = cur->child;
        temp1 = del (temp1);
        temp1 = temp1->child;
        do
        {
            temp2 = cur->child;
            do
            {
                end = 0;
                flag = check_dominance (nsga2Params, &(new_pop->ind[temp1->index]), &(new_pop->ind[temp2->index]));
                if (flag == 1)
                {
                    insert (orig, temp2->index);
                    temp2 = del (temp2);
                    front_size--;
                    temp2 = temp2->child;
                }
                if (flag == 0)
                {
                    temp2 = temp2->child;
                }
                if (flag == -1)
                {
                    end = 1;
                }
            }
            while (end!=1 && temp2!=((void *)0));
            if (flag == 0 || flag == 1)
            {
                insert (cur, temp1->index);
                front_size++;
                temp1 = del (temp1);
            }
            temp1 = temp1->child;
        }
        while (temp1 != ((void *)0));
        temp2 = cur->child;
        do
        {
            new_pop->ind[temp2->index].rank = rank;
            temp2 = temp2->child;
        }
        while (temp2 != ((void *)0));
        assign_crowding_distance_list (nsga2Params, new_pop, cur->child, front_size);
        temp2 = cur->child;
        do
        {
            temp2 = del (temp2);
            temp2 = temp2->child;
        }
        while (cur->child !=((void *)0));
        rank+=1;
    }
    while (orig->child!=((void *)0));
    free (orig);
    free (cur);
    return;
}


repo: amluto/libseccomp

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

result = x86_64_syscall_resolve_name();
if ( (int)result >= 0 )
result = (unsigned int)result | 0x40000000;
return result;
}

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

result = x86_64_syscall_resolve_name();
if ( (int)result >= 0 )
result = (unsigned int)result | 0x40000000;
return result;
}

original_code:
int x32_syscall_resolve_name(const char *name)
{
 int syscall;
 syscall = x86_64_syscall_resolve_name(name);
 if (syscall >= 0)
  syscall |= 0x40000000;
 return syscall;
}

canonical_original_code:
int x32_syscall_resolve_name(char *name)
{
 int syscall;
 syscall = x86_64_syscall_resolve_name(name);
 if (syscall >= 0)
  syscall |= 0x40000000;
 return syscall;
}

variable_types:
name
char *

variable_types: syscall int


decompiled_code:
__int64 __fastcall x32_syscall_resolve_num(__int64 a1)
{
if ( (int)a1 >= 0 )
a1 = (unsigned int)a1 & 0xBFFFFFFF;
return x86_64_syscall_resolve_num(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( (int)a1 >= 0 )
a1 = (unsigned int)a1 & 0xBFFFFFFF;
return x86_64_syscall_resolve_num(a1);
}

original_code:
const char *x32_syscall_resolve_num(int num)
{
 int syscall = num;
 if (syscall >= 0)
  syscall &= (~0x40000000);
 return x86_64_syscall_resolve_num(syscall);
}

variable_types: num int

return_type: char *


decompiled_code:
int __fastcall bpf_decode_op(_WORD *a1)
{
int result; // eax

switch ( *a1 )
{
case 0:
case 0x20:
case 0x40:
case 0x60:
case 0x80:
case 0xA0:
result = printf("%-3s", "ld");
break;
case 1:
case 9:
case 0x11:
case 0x21:
case 0x29:
case 0x31:
case 0x41:
case 0x49:
case 0x51:
case 0x61:
case 0x69:
case 0x71:
case 0x81:
case 0x89:
case 0x91:
case 0xA1:
case 0xA9:
case 0xB1:
result = printf("%-3s", "ldx");
break;
case 2:
result = printf("%-3s", "st");
break;
case 3:
result = printf("%-3s", "stx");
break;
case 4:
case 0xC:
result = printf("%-3s", "add");
break;
case 5:
case 0xD:
result = printf("%-3s", "jmp");
break;
case 6:
case 0xE:
case 0x16:
result = printf("%-3s", "ret");
break;
case 7:
result = printf("%-3s", "tax");
break;
case 8:
case 0x28:
case 0x48:
case 0x68:
case 0x88:
case 0xA8:
result = printf("%-3s", "ldh");
break;
case 0x10:
case 0x30:
case 0x50:
case 0x70:
case 0x90:
case 0xB0:
result = printf("%-3s", "ldb");
break;
case 0x14:
case 0x1C:
result = printf("%-3s", "sub");
break;
case 0x15:
case 0x1D:
result = printf("%-3s", "jeq");
break;
case 0x24:
case 0x2C:
result = printf("%-3s", "mul");
break;
case 0x25:
case 0x2D:
result = printf("%-3s", "jgt");
break;
case 0x34:
case 0x3C:
result = printf("%-3s", "div");
break;
case 0x35:
case 0x3D:
result = printf("%-3s", "jge");
break;
case 0x44:
case 0x4C:
result = printf("%-3s", "or");
break;
case 0x45:
case 0x4D:
result = printf("%-3s", "jset");
break;
case 0x54:
case 0x5C:
result = printf("%-3s", "and");
break;
case 0x64:
case 0x6C:
result = printf("%-3s", "lsh");
break;
case 0x74:
case 0x7C:
result = printf("%-3s", "rsh");
break;
case 0x84:
case 0x8C:
result = printf("%-3s", "neg");
break;
case 0x87:
result = printf("%-3s", "txa");
break;
default:
result = printf("%-3s", "???");
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(_WORD *a1)
{
int result; // eax

switch ( *a1 )
{
case 0:
case 0x20:
case 0x40:
case 0x60:
case 0x80:
case 0xA0:
result = printf("%-3s", "ld");
break;
case 1:
case 9:
case 0x11:
case 0x21:
case 0x29:
case 0x31:
case 0x41:
case 0x49:
case 0x51:
case 0x61:
case 0x69:
case 0x71:
case 0x81:
case 0x89:
case 0x91:
case 0xA1:
case 0xA9:
case 0xB1:
result = printf("%-3s", "ldx");
break;
case 2:
result = printf("%-3s", "st");
break;
case 3:
result = printf("%-3s", "stx");
break;
case 4:
case 0xC:
result = printf("%-3s", "add");
break;
case 5:
case 0xD:
result = printf("%-3s", "jmp");
break;
case 6:
case 0xE:
case 0x16:
result = printf("%-3s", "ret");
break;
case 7:
result = printf("%-3s", "tax");
break;
case 8:
case 0x28:
case 0x48:
case 0x68:
case 0x88:
case 0xA8:
result = printf("%-3s", "ldh");
break;
case 0x10:
case 0x30:
case 0x50:
case 0x70:
case 0x90:
case 0xB0:
result = printf("%-3s", "ldb");
break;
case 0x14:
case 0x1C:
result = printf("%-3s", "sub");
break;
case 0x15:
case 0x1D:
result = printf("%-3s", "jeq");
break;
case 0x24:
case 0x2C:
result = printf("%-3s", "mul");
break;
case 0x25:
case 0x2D:
result = printf("%-3s", "jgt");
break;
case 0x34:
case 0x3C:
result = printf("%-3s", "div");
break;
case 0x35:
case 0x3D:
result = printf("%-3s", "jge");
break;
case 0x44:
case 0x4C:
result = printf("%-3s", "or");
break;
case 0x45:
case 0x4D:
result = printf("%-3s", "jset");
break;
case 0x54:
case 0x5C:
result = printf("%-3s", "and");
break;
case 0x64:
case 0x6C:
result = printf("%-3s", "lsh");
break;
case 0x74:
case 0x7C:
result = printf("%-3s", "rsh");
break;
case 0x84:
case 0x8C:
result = printf("%-3s", "neg");
break;
case 0x87:
result = printf("%-3s", "txa");
break;
default:
result = printf("%-3s", "???");
break;
}
return result;
}

variable_types: struct sock_filter { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; } *


decompiled_code:
int __fastcall bpf_decode_args(__int16 *a1, int a2)
{
__int16 v2; // dx
int result; // eax
__int16 v4; // dx
__int64 v5; // rsi
unsigned int v6; // eax

v2 = *a1;
result = *a1 & 7;
switch ( *a1 & 7 )
{
case 0:
case 1:
v4 = *a1 & 0xE0;
if ( v4 == 32 )
{
result = printf("$data[%u]", *((unsigned int *)a1 + 1));
}
else if ( v4 == 96 )
{
result = printf("$temp[%u]", *((unsigned int *)a1 + 1));
}
break;
case 2:
case 3:
result = printf("$temp[%u]", *((unsigned int *)a1 + 1));
break;
case 4:
if ( (v2 & 8) == 0 && (*a1 & 0xE0) == 64 )
result = printf("0x%.8x", *((unsigned int *)a1 + 1));
else
result = printf("%u", *((unsigned int *)a1 + 1));
break;
case 5:
if ( (v2 & 0xF0) != 0 )
result = printf(
"%-4u true:%.4u false:%.4u",
*((unsigned int *)a1 + 1),
a2 + 1 + (unsigned int)*((unsigned __int8 *)a1 + 2),
a2 + 1 + (unsigned int)*((unsigned __int8 *)a1 + 3));
else
result = printf("%.4u", (unsigned int)(a2 + *((_DWORD *)a1 + 1) + 1));
break;
case 6:
if ( (*a1 & 0x18) == 16 )
return printf("$acc");
if ( (v2 & 8) != 0 )
{
result = printf("???");
}
else
{
v5 = *((unsigned int *)a1 + 1);
v6 = *((_DWORD *)a1 + 1) & 0x7FFF0000;
if ( v6 == 327680 )
return printf("ERRNO(%u)", (unsigned __int16)v5);
if ( v6 <= 0x50000 )
{
if ( !v6 )
return printf("KILL");
if ( v6 == 196608 )
return printf("TRAP");
}
else
{
if ( v6 == 2146435072 )
return printf("TRACE(%u)", (unsigned __int16)v5);
if ( v6 == 2147418112 )
return printf("ALLOW");
}
result = printf("0x%.8x", v5);
}
break;
case 7:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int16 *a1, int a2)
{
__int16 v2; // dx
int result; // eax
__int16 v4; // dx
__int64 v5; // rsi
unsigned int v6; // eax

v2 = *a1;
result = *a1 & 7;
switch ( *a1 & 7 )
{
case 0:
case 1:
v4 = *a1 & 0xE0;
if ( v4 == 32 )
{
result = printf("$data[%u]", *((unsigned int *)a1 + 1));
}
else if ( v4 == 96 )
{
result = printf("$temp[%u]", *((unsigned int *)a1 + 1));
}
break;
case 2:
case 3:
result = printf("$temp[%u]", *((unsigned int *)a1 + 1));
break;
case 4:
if ( (v2 & 8) == 0 && (*a1 & 0xE0) == 64 )
result = printf("0x%.8x", *((unsigned int *)a1 + 1));
else
result = printf("%u", *((unsigned int *)a1 + 1));
break;
case 5:
if ( (v2 & 0xF0) != 0 )
result = printf(
"%-4u true:%.4u false:%.4u",
*((unsigned int *)a1 + 1),
a2 + 1 + (unsigned int)*((unsigned __int8 *)a1 + 2),
a2 + 1 + (unsigned int)*((unsigned __int8 *)a1 + 3));
else
result = printf("%.4u", (unsigned int)(a2 + *((_DWORD *)a1 + 1) + 1));
break;
case 6:
if ( (*a1 & 0x18) == 16 )
return printf("$acc");
if ( (v2 & 8) != 0 )
{
result = printf("???");
}
else
{
v5 = *((unsigned int *)a1 + 1);
v6 = *((_DWORD *)a1 + 1) & 0x7FFF0000;
if ( v6 == 327680 )
return printf("ERRNO(%u)", (unsigned __int16)v5);
if ( v6 <= 0x50000 )
{
if ( !v6 )
return printf("KILL");
if ( v6 == 196608 )
return printf("TRAP");
}
else
{
if ( v6 == 2146435072 )
return printf("TRACE(%u)", (unsigned __int16)v5);
if ( v6 == 2147418112 )
return printf("ALLOW");
}
result = printf("0x%.8x", v5);
}
break;
case 7:
return result;
}
return result;
}

original_code:
static void bpf_decode_args(const bpf_instr_raw *bpf, unsigned int line)
{
 switch (((bpf->code) & 0x07)) {
 case 0x00:
 case 0x01:
  switch (((bpf->code) & 0xe0)) {
  case 0x20:
   printf("$data[%u]", bpf->k);
   break;
  case 0x60:
   printf("$temp[%u]", bpf->k);
   break;
  }
  break;
 case 0x02:
 case 0x03:
  printf("$temp[%u]", bpf->k);
  break;
 case 0x04:
  if (((bpf->code) & 0x08) == 0x00) {
   switch (((bpf->code) & 0xf0)) {
   case 0x40:
   case 0x50:
    printf("0x%.8x", bpf->k);
    break;
   default:
    printf("%u", bpf->k);
   }
  } else
   printf("%u", bpf->k);
  break;
 case 0x05:
  if (((bpf->code) & 0xf0) == 0x00) {
   printf("%.4u", (line + 1) + bpf->k);
  } else {
   printf("%-4u true:%.4u false:%.4u",
          bpf->k,
          (line + 1) + bpf->jt,
          (line + 1) + bpf->jf);
  }
  break;
 case 0x06:
  if (((bpf->code) & 0x18) == 0x10) {
   printf("$acc");
  } else if (((bpf->code) & 0x08) == 0x00) {
   uint32_t act = bpf->k & 0x7fff0000U;
   uint32_t data = bpf->k & 0x0000ffffU;
   switch (act) {
   case 0x00000000U:
    printf("KILL");
    break;
   case 0x00030000U:
    printf("TRAP");
    break;
   case 0x00050000U:
    printf("ERRNO(%u)", data);
    break;
   case 0x7ff00000U:
    printf("TRACE(%u)", data);
    break;
   case 0x7fff0000U:
    printf("ALLOW");
    break;
   default:
    printf("0x%.8x", bpf->k);
   }
  } else if (((bpf->code) & 0x08) == 0x08) {
   printf("???");
  }
  break;
 case 0x07:
  break;
 default:
  printf("???");
 }
}

canonical_original_code:
static void bpf_decode_args(struct sock_filter *bpf, unsigned int line)
{
 switch (((bpf->code) & 0x07)) {
 case 0x00:
 case 0x01:
  switch (((bpf->code) & 0xe0)) {
  case 0x20:
   printf("$data[%u]", bpf->k);
   break;
  case 0x60:
   printf("$temp[%u]", bpf->k);
   break;
  }
  break;
 case 0x02:
 case 0x03:
  printf("$temp[%u]", bpf->k);
  break;
 case 0x04:
  if (((bpf->code) & 0x08) == 0x00) {
   switch (((bpf->code) & 0xf0)) {
   case 0x40:
   case 0x50:
    printf("0x%.8x", bpf->k);
    break;
   default:
    printf("%u", bpf->k);
   }
  } else
   printf("%u", bpf->k);
  break;
 case 0x05:
  if (((bpf->code) & 0xf0) == 0x00) {
   printf("%.4u", (line + 1) + bpf->k);
  } else {
   printf("%-4u true:%.4u false:%.4u",
          bpf->k,
          (line + 1) + bpf->jt,
          (line + 1) + bpf->jf);
  }
  break;
 case 0x06:
  if (((bpf->code) & 0x18) == 0x10) {
   printf("$acc");
  } else if (((bpf->code) & 0x08) == 0x00) {
   unsigned int act = bpf->k & 0x7fff0000U;
   unsigned int data = bpf->k & 0x0000ffffU;
   switch (act) {
   case 0x00000000U:
    printf("KILL");
    break;
   case 0x00030000U:
    printf("TRAP");
    break;
   case 0x00050000U:
    printf("ERRNO(%u)", data);
    break;
   case 0x7ff00000U:
    printf("TRACE(%u)", data);
    break;
   case 0x7fff0000U:
    printf("ALLOW");
    break;
   default:
    printf("0x%.8x", bpf->k);
   }
  } else if (((bpf->code) & 0x08) == 0x08) {
   printf("???");
  }
  break;
 case 0x07:
  break;
 default:
  printf("???");
 }
}

variable_types:
line
unsigned int

variable_types:
act
unsigned int

variable_types:
data
unsigned int

user_defined_types: struct sock_filter { unsigned short code; unsigned char jt; unsigned char jf; unsigned int k; }


decompiled_code:
__int64 __fastcall util_getopt(int argc, char *const *a2, int *a3)
{
unsigned int v4; // ebp
int v5; // eax
int longind; // [rsp+1Ch] [rbp-9Ch] BYREF
struct option v8; // [rsp+20h] [rbp-98h] BYREF
void *v9; // [rsp+40h] [rbp-78h]
int v10; // [rsp+48h] [rbp-70h]
int *v11; // [rsp+50h] [rbp-68h]
int v12; // [rsp+58h] [rbp-60h]
__int64 v13; // [rsp+60h] [rbp-58h]
int v14; // [rsp+68h] [rbp-50h]
__int64 v15; // [rsp+70h] [rbp-48h]
int v16; // [rsp+78h] [rbp-40h]

if ( !a3 )
return (unsigned int)-14;
*a3 = 0;
v4 = 0;
while ( 1 )
{
longind = 0;
v8.name = (const char *)&LC0;
v8.has_arg = 0;
v8.flag = a3;
v8.val = 1;
v9 = &LC1;
v10 = 0;
v11 = a3;
v12 = 0;
v13 = 0LL;
v14 = 0;
v15 = 0LL;
v16 = 0;
v5 = getopt_long(argc, a2, "bp", &v8, &longind);
if ( v5 == -1 )
break;
if ( v5 == 98 )
{
*a3 = 1;
}
else if ( v5 == 112 )
{
*a3 = 0;
}
else if ( v5 )
{
v4 = -22;
}
}
if ( v4 == -22 || optind < argc )
{
fprintf(stderr, "usage %s: [--bpf,-b] [--pfc,-p]\n", *(const char **)a2);
v4 = -22;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(int argc, char *const *a2, int *a3)
{
unsigned int v4; // ebp
int v5; // eax
int longind; // [rsp+1Ch] [rbp-9Ch] BYREF
struct option v8; // [rsp+20h] [rbp-98h] BYREF
void *v9; // [rsp+40h] [rbp-78h]
int v10; // [rsp+48h] [rbp-70h]
int *v11; // [rsp+50h] [rbp-68h]
int v12; // [rsp+58h] [rbp-60h]
__int64 v13; // [rsp+60h] [rbp-58h]
int v14; // [rsp+68h] [rbp-50h]
__int64 v15; // [rsp+70h] [rbp-48h]
int v16; // [rsp+78h] [rbp-40h]

if ( !a3 )
return (unsigned int)-14;
*a3 = 0;
v4 = 0;
while ( 1 )
{
longind = 0;
v8.name = (const char *)&LC0;
v8.has_arg = 0;
v8.flag = a3;
v8.val = 1;
v9 = &LC1;
v10 = 0;
v11 = a3;
v12 = 0;
v13 = 0LL;
v14 = 0;
v15 = 0LL;
v16 = 0;
v5 = getopt_long(argc, a2, "bp", &v8, &longind);
if ( v5 == -1 )
break;
if ( v5 == 98 )
{
*a3 = 1;
}
else if ( v5 == 112 )
{
*a3 = 0;
}
else if ( v5 )
{
v4 = -22;
}
}
if ( v4 == -22 || optind < argc )
{
fprintf(stderr, "usage %s: [--bpf,-b] [--pfc,-p]\n", *(const char **)a2);
v4 = -22;
}
return v4;
}

original_code:
int util_getopt(int argc, char *argv[], struct util_options *opts)
{
 int rc = 0;
 if (opts == ((void *)0))
  return -14;
 memset(opts, 0, sizeof(*opts));
 while (1) {
  int c, option_index = 0;
  const struct option long_options[] = {
   {"bpf", 0, &(opts->bpf_flg), 1},
   {"pfc", 0, &(opts->bpf_flg), 0},
   {0, 0, 0, 0},
  };
  c = getopt_long(argc, argv, "bp",
    long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 0:
   break;
  case 'b':
   opts->bpf_flg = 1;
   break;
  case 'p':
   opts->bpf_flg = 0;
   break;
  default:
   rc = -22;
   break;
  }
 }
 if (rc == -22 || optind < argc) {
  fprintf(stderr, "usage %s: [--bpf,-b] [--pfc,-p]\n", argv[0]);
  rc = -22;
 }
 return rc;
}

canonical_original_code:
int util_getopt(int argc, char *argv[], struct util_options *opts)
{
 int rc = 0;
 if (opts == ((void *)0))
  return -14;
 memset(opts, 0, sizeof(*opts));
 while (1) {
  int c; int option_index = 0;
  struct option long_options[] = {
   {"bpf", 0, &(opts->bpf_flg), 1},
   {"pfc", 0, &(opts->bpf_flg), 0},
   {0, 0, 0, 0},
  };
  c = getopt_long(argc, argv, "bp",
    long_options, &option_index);
  if (c == -1)
   break;
  switch (c) {
  case 0:
   break;
  case 'b':
   opts->bpf_flg = 1;
   break;
  case 'p':
   opts->bpf_flg = 0;
   break;
  default:
   rc = -22;
   break;
  }
 }
 if (rc == -22 || optind < argc) {
  fprintf(stderr, "usage %s: [--bpf,-b] [--pfc,-p]\n", argv[0]);
  rc = -22;
 }
 return rc;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
opts
struct util_options { int bpf_flg; } *

variable_types: rc int

variable_types: c int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []


decompiled_code:
__int64 __fastcall util_filter_output(_DWORD *a1, __int64 a2)
{
if ( !a1 )
return 4294967282LL;
if ( *a1 )
return seccomp_export_bpf(a2, 1LL);
return seccomp_export_pfc(a2, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, __int64 a2)
{
if ( !a1 )
return 4294967282LL;
if ( *a1 )
return seccomp_export_bpf(a2, 1LL);
return seccomp_export_pfc(a2, 1LL);
}

original_code:
int util_filter_output(const struct util_options *opts,
         const scmp_filter_ctx ctx)
{
 int rc;
 if (opts == ((void *)0))
  return -14;
 if (opts->bpf_flg)
  rc = seccomp_export_bpf(ctx, 1);
 else
  rc = seccomp_export_pfc(ctx, 1);
 return rc;
}

canonical_original_code:
int util_filter_output(struct util_options *opts, void *ctx)
{
 int rc;
 if (opts == ((void *)0))
  return -14;
 if (opts->bpf_flg)
  rc = seccomp_export_bpf(ctx, 1);
 else
  rc = seccomp_export_pfc(ctx, 1);
 return rc;
}

variable_types:
ctx
void *


decompiled_code:
int util_trap_install()
{
int result; // eax
sigset_t v1; // [rsp+0h] [rbp-138h] BYREF
struct sigaction v2; // [rsp+80h] [rbp-B8h] BYREF

memset(&v2, 0, sizeof(v2));
sigemptyset(&v1);
sigaddset(&v1, 31);
v2.sa_handler = (__sighandler_t)trap_handler;
v2.sa_flags = 4;
if ( sigaction(31, &v2, 0LL) < 0 || (result = sigprocmask(1, &v1, 0LL)) != 0 )
result = -*_errno_location();
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax
sigset_t v1; // [rsp+0h] [rbp-138h] BYREF
struct sigaction v2; // [rsp+80h] [rbp-B8h] BYREF

memset(&v2, 0, sizeof(v2));
sigemptyset(&v1);
sigaddset(&v1, 31);
v2.sa_handler = (__sighandler_t)trap_handler;
v2.sa_flags = 4;
if ( sigaction(31, &v2, 0LL) < 0 || (result = sigprocmask(1, &v1, 0LL)) != 0 )
result = -*_errno_location();
return result;
}

original_code:
int util_trap_install(void)
{
 struct sigaction signal_handler;
 sigset_t signal_mask;
 memset(&signal_handler, 0, sizeof(signal_handler));
 sigemptyset(&signal_mask);
 sigaddset(&signal_mask, 31);
 signal_handler.__sigaction_handler.sa_sigaction = &_trap_handler;
 signal_handler.sa_flags = 4;
 if (sigaction(31, &signal_handler, ((void *)0)) < 0)
  return -(*__errno_location ());
 if (sigprocmask(1, &signal_mask, ((void *)0)))
  return -(*__errno_location ());
 return 0;
}

canonical_original_code:
int util_trap_install()
{
 struct sigaction signal_handler;
 struct __sigset_t signal_mask;
 memset(&signal_handler, 0, sizeof(signal_handler));
 sigemptyset(&signal_mask);
 sigaddset(&signal_mask, 31);
 signal_handler.__sigaction_handler.sa_sigaction = &_trap_handler;
 signal_handler.sa_flags = 4;
 if (sigaction(31, &signal_handler, ((void *)0)) < 0)
  return -(*__errno_location ());
 if (sigprocmask(1, &signal_mask, ((void *)0)))
  return -(*__errno_location ());
 return 0;
}

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

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

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


decompiled_code:
int __fastcall util_action_parse(char *s1)
{
int result; // eax
int v2; // edx
int v3; // edx

if ( !s1 )
return -1;
result = strcasecmp(s1, "KILL");
if ( result )
{
v2 = strcasecmp(s1, "TRAP");
result = 196608;
if ( v2 )
{
v3 = strcasecmp(s1, "ERRNO");
result = 327843;
if ( v3 )
{
if ( !strcasecmp(s1, "TRACE") )
result = -1;
else
result = strcasecmp(s1, "ALLOW") == 0 ? 2147418112 : -1;
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(char *s1)
{
int result; // eax
int v2; // edx
int v3; // edx

if ( !s1 )
return -1;
result = strcasecmp(s1, "KILL");
if ( result )
{
v2 = strcasecmp(s1, "TRAP");
result = 196608;
if ( v2 )
{
v3 = strcasecmp(s1, "ERRNO");
result = 327843;
if ( v3 )
{
if ( !strcasecmp(s1, "TRACE") )
result = -1;
else
result = strcasecmp(s1, "ALLOW") == 0 ? 2147418112 : -1;
}
}
}
return result;
}

original_code:
int util_action_parse(const char *action)
{
 if (action == ((void *)0))
  return -1;
 if (strcasecmp(action, "KILL") == 0)
  return 0x00000000U;
 else if (strcasecmp(action, "TRAP") == 0)
  return 0x00030000U;
 else if (strcasecmp(action, "ERRNO") == 0)
  return (0x00050000U | ((163) & 0x0000ffffU));
 else if (strcasecmp(action, "TRACE") == 0)
  return -1;
 else if (strcasecmp(action, "ALLOW") == 0)
  return 0x7fff0000U;
 return -1;
}

canonical_original_code:
int util_action_parse(char *action)
{
 if (action == ((void *)0))
  return -1;
 if (strcasecmp(action, "KILL") == 0)
  return 0x00000000U;
 else if (strcasecmp(action, "TRAP") == 0)
  return 0x00030000U;
 else if (strcasecmp(action, "ERRNO") == 0)
  return (0x00050000U | ((163) & 0x0000ffffU));
 else if (strcasecmp(action, "TRACE") == 0)
  return -1;
 else if (strcasecmp(action, "ALLOW") == 0)
  return 0x7fff0000U;
 return -1;
}

variable_types:
action
char *


decompiled_code:
__int64 __fastcall util_file_write(char *file)
{
ssize_t v1; // rbp
int v2; // eax
int v3; // ebx
unsigned int v4; // ebp
char s[8]; // [rsp+8h] [rbp-20h] BYREF

strcpy(s, "testing");
v1 = strlen(s);
v2 = open(file, 65, 384LL);
if ( v2 < 0 )
return *_errno_location();
v3 = v2;
if ( write(v2, s, v1) < v1 )
{
v4 = *_errno_location();
close(v3);
return v4;
}
v4 = 0;
if ( close(v3) < 0 )
return *_errno_location();
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *file)
{
ssize_t v1; // rbp
int v2; // eax
int v3; // ebx
unsigned int v4; // ebp
char s[8]; // [rsp+8h] [rbp-20h] BYREF

strcpy(s, "testing");
v1 = strlen(s);
v2 = open(file, 65, 384LL);
if ( v2 < 0 )
return *_errno_location();
v3 = v2;
if ( write(v2, s, v1) < v1 )
{
v4 = *_errno_location();
close(v3);
return v4;
}
v4 = 0;
if ( close(v3) < 0 )
return *_errno_location();
return v4;
}

original_code:
int util_file_write(const char *path)
{
 int fd;
 const char buf[] = "testing";
 ssize_t buf_len = strlen(buf);
 fd = open(path, 01 | 0100, 0400 | 0200);
 if (fd < 0)
  return (*__errno_location ());
 if (write(fd, buf, buf_len) < buf_len) {
  int rc = (*__errno_location ());
  close(fd);
  return rc;
 }
 if (close(fd) < 0)
  return (*__errno_location ());
 return 0;
}

canonical_original_code:
int util_file_write(char *path)
{
 int fd;
 char buf[] = "testing";
 long buf_len = strlen(buf);
 fd = open(path, 01 | 0100, 0400 | 0200);
 if (fd < 0)
  return (*__errno_location ());
 if (write(fd, buf, buf_len) < buf_len) {
  int rc = (*__errno_location ());
  close(fd);
  return rc;
 }
 if (close(fd) < 0)
  return (*__errno_location ());
 return 0;
}

variable_types:
path
char *

variable_types: fd int

variable_types:
buf
char []


main

canonical_name: main

repo: amonakov/glsanity

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
const char *v4; // rbx
Display *v5; // rax
Display *v6; // rbx
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = getenv("DISPLAY");
if ( !v3 )
{
printf("fatal: %s:\tDISPLAY not set\n", "X display");
exit(1);
}
v4 = v3;
printf("info: %s:\t%s\n", "X display", v3);
v5 = XOpenDisplay(v4);
v6 = v5;
if ( !v5 )
{
printf("fatal: %s:\tfailed to open connection\n", "X display");
exit(1);
}
if ( !XQueryExtension(v5, "GLX", v8, v8, v8) )
{
printf("fatal: %s:\tnot present; see the Xorg log for details\n", "X Ext. \"GLX\"");
exit(1);
}
printf("info: %s:\tpresent\n", "X Ext. \"GLX\"");
if ( XQueryExtension(v6, "NV-GLX", v8, v8, v8) )
printf("info: %s:\tpresent\n", "X Ext. \"NV-GLX\"");
else
printf("info: %s:\tnot present; OK for non-nVidia drivers\n", "X Ext. \"NV-GLX\"");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  const char *msg1 = "libGL.so.1";
  void *libgl = dlopen("libGL.so.1", 0x00001);
  if (!libgl)
    ({printf("fatal: %s:\t""loading with dlopen failed:\n%s""\n", msg1, dlerror()); exit(1);});
  void *libgl_sym = dlsym(libgl, "glXQueryVersion");
  if (!libgl_sym)
    ({printf("fatal: %s:\t""dlsym failed: %s""\n", msg1, dlerror()); exit(1);});
  Dl_info libgl_info;
  if (!dladdr(libgl_sym, &libgl_info))
    ({printf("fatal: %s:\t""dladdr failed""\n", msg1); exit(1);});
  printf("info:  %s:\t""loaded from: %s""\n", msg1, libgl_info.dli_fname);
  char *real_path = canonicalize_file_name(libgl_info.dli_fname);
  if (strcmp(real_path, libgl_info.dli_fname))
    printf("info:  %s:\t""symlink to:  %s""\n", msg1, real_path);
  free(real_path);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *msg1 = "libGL.so.1";
  void *libgl = dlopen("libGL.so.1", 0x00001);
  if (!libgl)
    ({printf("fatal: %s:\t""loading with dlopen failed:\n%s""\n", msg1, dlerror()); exit(1);});
  void *libgl_sym = dlsym(libgl, "glXQueryVersion");
  if (!libgl_sym)
    ({printf("fatal: %s:\t""dlsym failed: %s""\n", msg1, dlerror()); exit(1);});
  struct Dl_info libgl_info;
  if (!dladdr(libgl_sym, &libgl_info))
    ({printf("fatal: %s:\t""dladdr failed""\n", msg1); exit(1);});
  printf("info:  %s:\t""loaded from: %s""\n", msg1, libgl_info.dli_fname);
  char *real_path = canonicalize_file_name(libgl_info.dli_fname);
  if (strcmp(real_path, libgl_info.dli_fname))
    printf("info:  %s:\t""symlink to:  %s""\n", msg1, real_path);
  free(real_path);
  return 0;
}

variable_types:
libgl
void *

variable_types: struct Dl_info { char *dli_fname; void *dli_fbase; char *dli_sname; void *dli_saddr; }


hashf

repo: amorilia/nifclib

decompiled_code:
__int64 __fastcall hashf(__int64 a1, char *a2)
{
char v2; // dl
int v3; // eax

v2 = *a2;
if ( *a2 )
{
v3 = 0;
do
{
++a2;
v3 += v2;
v2 = *a2;
}
while ( *a2 );
}
else
{
v3 = 0;
}
return (unsigned int)(v3 % *(_DWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2)
{
char v2; // dl
int v3; // eax

v2 = *a2;
if ( *a2 )
{
v3 = 0;
do
{
++a2;
v3 += v2;
v2 = *a2;
}
while ( *a2 );
}
else
{
v3 = 0;
}
return (unsigned int)(v3 % *(_DWORD *)(a1 + 8));
}

original_code:
static int
hashf(hash *h, char *key)
{
 int sum = 0;
 while (*key)
  sum += (int)(*(key++));
 return sum % h->cnt;
}

canonical_original_code:
static int hashf(struct hash *h, char *key)
{
 int sum = 0;
 while (*key)
  sum += (int)(*(key++));
 return sum % h->cnt;
}

variable_types: struct hash { struct kvp_list { struct kvp { char *val; char *key; } *items; int cnt; int cap; } **items; int cnt; } *

variable_types:
key
char *

variable_types: sum int

user_defined_types: struct hash { struct kvp_list **items; int cnt; }

user_defined_types: struct kvp_list { struct kvp *items; int cnt; int cap; }


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

result = 0LL;
if ( *a3 )
{
if ( a2 <= 0 )
{
result = 0LL;
}
else
{
v4 = 0LL;
while ( 1 )
{
if ( a3[v4] != *(_BYTE *)(a1 + v4) )
return 0LL;
if ( !a3[v4 + 1] )
break;
if ( ++v4 == a2 )
return 0LL;
}
result = 1LL;
}
}
return result;
}

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

result = 0LL;
if ( *a3 )
{
if ( a2 <= 0 )
{
result = 0LL;
}
else
{
v4 = 0LL;
while ( 1 )
{
if ( a3[v4] != *(_BYTE *)(a1 + v4) )
return 0LL;
if ( !a3[v4 + 1] )
break;
if ( ++v4 == a2 )
return 0LL;
}
result = 1LL;
}
}
return result;
}

original_code:
int
starts_with(const char *buf, int len, const char *text)
{
 int i,j = 0;
 if (!text[j])
  return 0;
 for (i = 0; i < len; i++) {
  if (text[j++] != buf[i])
   return 0;
  if (!text[j])
   return 1;
 }
 return 0;
}

canonical_original_code:
int starts_with(char *buf, int len, char *text)
{
 int i; int j = 0;
 if (!text[j])
  return 0;
 for (i = 0; i < len; i++) {
  if (text[j++] != buf[i])
   return 0;
  if (!text[j])
   return 1;
 }
 return 0;
}

variable_types:
buf
char *

variable_types: len int

variable_types:
text
char *

variable_types: i int

variable_types: j int


find

decompiled_code:
__int64 __fastcall find(_BYTE *a1, __int64 a2, int a3)
{
__int64 v4; // r15
__int64 i; // rbx
unsigned int v6; // er14

v4 = (unsigned int)(a3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = i;
if ( (unsigned int)starts_with(a2 + i, a3 - (int)i, a1) )
break;
if ( i == v4 )
return (unsigned int)-1;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 a2, int a3)
{
__int64 v4; // r15
__int64 i; // rbx
unsigned int v6; // er14

v4 = (unsigned int)(a3 - 1);
for ( i = 0LL; ; ++i )
{
v6 = i;
if ( (unsigned int)func1(a2 + i, a3 - (int)i, a1) )
break;
if ( i == v4 )
return (unsigned int)-1;
}
return v6;
}

original_code:
int
find(const char *what, const char *buf, int maxlen)
{
 int i = 0;
 while (!starts_with (&buf[i], maxlen-i, what)) {
  i++;
  if (i == maxlen)
   return -1;
 }
 return i;
}

canonical_original_code:
int find(char *what, char *buf, int maxlen)
{
 int i = 0;
 while (!starts_with (&buf[i], maxlen-i, what)) {
  i++;
  if (i == maxlen)
   return -1;
 }
 return i;
}

variable_types:
what
char *

variable_types: maxlen int


replace

decompiled_code:
void __fastcall replace(_BYTE *a1, int a2, char a3, char a4)
{
_BYTE *v4; // rax

if ( a2 > 0 )
{
v4 = a1;
do
{
if ( *v4 == a3 )
*v4 = a4;
++v4;
}
while ( v4 != &a1[a2 - 1 + 1] );
}
}

original_code:
void
replace(char *buf, int maxlen, char a, char b)
{
 int i;
 for (i = 0; i < maxlen; i++)
  if (buf[i] == a)
   buf[i] = b;
}

variable_types: a char

variable_types: b char


hashrelease

original_code:
void
hashrelease(hash *h, int kvp)
{
 int i;
 for (i = 0; i < h->cnt; i++) {
  kvp_list *list = h->items[i];
  if (!list)
   continue;
  if (kvp) {
   int j;
   for (j = 0; j < list->cnt; j++) {
    if (list->items[j].val) {
     free (list->items[j].val);
     list->items[j].val = ((void *)0);
    }
    free (list->items[j].key);
   }
  }
  if (list->items)
   free (list->items);
  free (h->items[i]);
 }
 free (h->items);
 free (h);
}

canonical_original_code:
void hashrelease(struct hash *h, int kvp)
{
 int i;
 for (i = 0; i < h->cnt; i++) {
  struct kvp_list *list = h->items[i];
  if (!list)
   continue;
  if (kvp) {
   int j;
   for (j = 0; j < list->cnt; j++) {
    if (list->items[j].val) {
     free (list->items[j].val);
     list->items[j].val = ((void *)0);
    }
    free (list->items[j].key);
   }
  }
  if (list->items)
   free (list->items);
  free (h->items[i]);
 }
 free (h->items);
 free (h);
}

variable_types: kvp int

variable_types: struct kvp_list { struct kvp { char *val; char *key; } *items; int cnt; int cap; } *


hashadd

original_code:
int
hashadd(hash *h, char *key, char *val)
{
 if ( hashget (h, key) )
  return -1;
 int idx = hashf (h, key);
 if (!h->items[idx]) {
  h->items[idx] = malloc (sizeof(kvp_list));
  if (!h->items[idx]) {
   printf ("out of memory\n");
   return 0;
  }
  h->items[idx]->items = ((void *)0);
  h->items[idx]->cap = 0;
  h->items[idx]->cnt = 0;
 }
 kvp_list *l = h->items[idx];
 if (!l->items) {
  l->items = malloc (2*sizeof(kvp));
  if (!l->items) {
   printf ("out of memory\n");
   return 0;
  }
  l->cnt = 0;
  l->cap = 2;
 }
 if (l->cnt == l->cap) {
  l->cap += l->cap / 2;
  l->items = realloc (l->items, l->cap*sizeof(kvp));
  if (!l->items) {
   printf ("out of memory\n");
   return 0;
  }
 }
 l->items[l->cnt].val = val;
 l->items[l->cnt].key = key;
 l->cnt++;
 return 1;
}

canonical_original_code:
int hashadd(struct hash *h, char *key, char *val)
{
 if ( hashget (h, key) )
  return -1;
 int idx = hashf (h, key);
 if (!h->items[idx]) {
  h->items[idx] = malloc (sizeof(kvp_list));
  if (!h->items[idx]) {
   printf ("out of memory\n");
   return 0;
  }
  h->items[idx]->items = ((void *)0);
  h->items[idx]->cap = 0;
  h->items[idx]->cnt = 0;
 }
 struct kvp_list *l = h->items[idx];
 if (!l->items) {
  l->items = malloc (2*sizeof(kvp));
  if (!l->items) {
   printf ("out of memory\n");
   return 0;
  }
  l->cnt = 0;
  l->cap = 2;
 }
 if (l->cnt == l->cap) {
  l->cap += l->cap / 2;
  l->items = realloc (l->items, l->cap*sizeof(kvp));
  if (!l->items) {
   printf ("out of memory\n");
   return 0;
  }
 }
 l->items[l->cnt].val = val;
 l->items[l->cnt].key = key;
 l->cnt++;
 return 1;
}

variable_types:
val
char *

variable_types: idx int


hashprint

decompiled_code:
int __fastcall hashprint(__int64 a1)
{
int result; // eax
__int64 v2; // r12
__int64 v3; // rbp
__int64 v4; // rbx

if ( !a1 )
return puts("(null)");
result = printf("hash buckets: %d\n", *(unsigned int *)(a1 + 8));
if ( *(int *)(a1 + 8) > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v2);
if ( v3 )
{
result = printf(
"b[%3d]=lst(cnt: %d, cap: %d)\n",
(unsigned int)v2,
*(unsigned int *)(v3 + 8),
*(unsigned int *)(v3 + 12));
if ( *(int *)(v3 + 8) > 0 )
{
v4 = 0LL;
do
{
result = printf(
"\tlst[%3d]=%s, %s\n",
(unsigned int)v4,
*(const char **)(*(_QWORD *)v3 + 16 * v4 + 8),
*(const char **)(*(_QWORD *)v3 + 16 * v4));
++v4;
}
while ( *(_DWORD *)(v3 + 8) > (int)v4 );
}
}
else
{
result = printf("b[%3d]=(null)\n", (unsigned int)v2);
}
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax
__int64 v2; // r12
__int64 v3; // rbp
__int64 v4; // rbx

if ( !a1 )
return puts("(null)");
result = printf("hash buckets: %d\n", *(unsigned int *)(a1 + 8));
if ( *(int *)(a1 + 8) > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8 * v2);
if ( v3 )
{
result = printf(
"b[%3d]=lst(cnt: %d, cap: %d)\n",
(unsigned int)v2,
*(unsigned int *)(v3 + 8),
*(unsigned int *)(v3 + 12));
if ( *(int *)(v3 + 8) > 0 )
{
v4 = 0LL;
do
{
result = printf(
"\tlst[%3d]=%s, %s\n",
(unsigned int)v4,
*(const char **)(*(_QWORD *)v3 + 16 * v4 + 8),
*(const char **)(*(_QWORD *)v3 + 16 * v4));
++v4;
}
while ( *(_DWORD *)(v3 + 8) > (int)v4 );
}
}
else
{
result = printf("b[%3d]=(null)\n", (unsigned int)v2);
}
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (int)v2 );
}
return result;
}

original_code:
void
hashprint(hash *h)
{
 if (!h) {
  printf ("(null)\n");
  return;
 }
 printf ("hash buckets: %d\n", h->cnt);
 int b;
 for (b = 0; b < h->cnt; b++) {
  kvp_list *l = h->items[b];
  if (!l) {
   printf ("b[%3d]=(null)\n", b);
   continue;
  }
  printf ("b[%3d]=lst(cnt: %d, cap: %d)\n", b, l->cnt, l->cap);
  int i;
  for (i = 0; i < l->cnt; i++)
   printf ("\tlst[%3d]=%s, %s\n", i,
    l->items[i].key, l->items[i].val);
 }
}

canonical_original_code:
void hashprint(struct hash *h)
{
 if (!h) {
  printf ("(null)\n");
  return;
 }
 printf ("hash buckets: %d\n", h->cnt);
 int b;
 for (b = 0; b < h->cnt; b++) {
  struct kvp_list *l = h->items[b];
  if (!l) {
   printf ("b[%3d]=(null)\n", b);
   continue;
  }
  printf ("b[%3d]=lst(cnt: %d, cap: %d)\n", b, l->cnt, l->cap);
  int i;
  for (i = 0; i < l->cnt; i++)
   printf ("\tlst[%3d]=%s, %s\n", i,
    l->items[i].key, l->items[i].val);
 }
}

variable_types: b int


DoReadNif

decompiled_code:
int __fastcall DoReadNif(const char *a1)
{
int result; // eax

result = strlen(a1);
if ( result > 3
&& (a1[result - 1] & 0xDF) == 70
&& (a1[result - 2] & 0xDF) == 73
&& (a1[result - 3] & 0xDF) == 78
&& a1[result - 4] == 46 )
{
if ( !(unsigned int)readnif(a1) )
{
printf("files ok %d\n", (unsigned int)nifcnt);
exit(1);
}
total_bytes += NIFF_FSIZE;
total_blocks += NIFF_BLOCK_COUNT;
total_niobjects += NIFF_OBJECT_COUNT;
total_malloc_calls += NIFF_MALLOCS;
total_reallocs += NIFF_REALLOCS;
printf("%5d\r", (unsigned int)++nifcnt);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

result = strlen(a1);
if ( result > 3
&& (a1[result - 1] & 0xDF) == 70
&& (a1[result - 2] & 0xDF) == 73
&& (a1[result - 3] & 0xDF) == 78
&& a1[result - 4] == 46 )
{
if ( !(unsigned int)readnif(a1) )
{
printf("files ok %d\n", (unsigned int)nifcnt);
exit(1);
}
total_bytes += NIFF_FSIZE;
total_blocks += NIFF_BLOCK_COUNT;
total_niobjects += NIFF_OBJECT_COUNT;
total_malloc_calls += NIFF_MALLOCS;
total_reallocs += NIFF_REALLOCS;
printf("%5d\r", (unsigned int)++nifcnt);
result = fflush(stdout);
}
return result;
}

original_code:
static void
DoReadNif(char *fname)
{
 int len = strlen (fname);
 if (len < 4)
  return;
 if (fname[len-1] == 'f' || fname[len-1] == 'F')
  if (fname[len-2] == 'i' || fname[len-2] == 'I')
   if (fname[len-3] == 'n' || fname[len-3] == 'N')
    if (fname[len-4] == '.') {
     if (!readnif (fname)) {
       printf ("files ok %d\n", nifcnt);
       exit (1);
     } else {
      total_bytes += NIFF_FSIZE;
      total_blocks += NIFF_BLOCK_COUNT;
      total_niobjects += NIFF_OBJECT_COUNT;
      total_malloc_calls += NIFF_MALLOCS;
      total_reallocs += NIFF_REALLOCS;
     }
     nifcnt++;
     printf ("%5d\r", nifcnt); fflush (stdout);
 }
}

variable_types:
fname
char *


decompiled_code:
__int64 __fastcall time_interval(_QWORD *a1, _QWORD *a2)
{
return a2[1] + 1000000LL * (*a2 - *a1) - a1[1];
}

original_code:
long
time_interval(struct timeval *a, struct timeval *b)
{
 return ( (b->tv_sec - a->tv_sec) * 1000000 ) + (b->tv_usec - a->tv_usec);
}

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

variable_types:
b
struct timeval *

return_type: long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rbp
struct timeval v7; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

gettimeofday(&tv, 0LL);
pathwalk(".", (void (__fastcall *)(char *))DoReadNif);
gettimeofday(&v7, 0LL);
v3 = time_interval(&tv, &v7);
v4 = v3 / 1000000;
v5 = 1LL;
if ( v3 / 1000000 )
v5 = v3 / 1000000;
printf("files done: %d (%ld file(s) per second)\n", (unsigned int)nifcnt, nifcnt / v5);
printf("time taken: %ld %.2ld:%.2ld\n", v4, v4 / 60, v4 % 60);
printf("total byte(s) read: %lld\n", total_bytes);
printf("major niff block(s) parsed: %d\n", (unsigned int)total_blocks);
printf("niff object(s) parsed: %d\n", (unsigned int)total_niobjects);
printf("malloc call(s): %d\n", (unsigned int)total_malloc_calls);
printf("realloc(s): %d\n", (unsigned int)total_reallocs);
printf("byte(s)/second: %lld\n", total_bytes / v5);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // rbp
struct timeval v7; // [rsp+0h] [rbp-38h] BYREF
struct timeval tv; // [rsp+10h] [rbp-28h] BYREF

gettimeofday(&tv, 0LL);
func1(".", (void (__fastcall *)(char *))DoReadNif);
gettimeofday(&v7, 0LL);
v3 = func2(&tv, &v7);
v4 = v3 / 1000000;
v5 = 1LL;
if ( v3 / 1000000 )
v5 = v3 / 1000000;
printf("files done: %d (%ld file(s) per second)\n", (unsigned int)nifcnt, nifcnt / v5);
printf("time taken: %ld %.2ld:%.2ld\n", v4, v4 / 60, v4 % 60);
printf("total byte(s) read: %lld\n", total_bytes);
printf("major niff block(s) parsed: %d\n", (unsigned int)total_blocks);
printf("niff object(s) parsed: %d\n", (unsigned int)total_niobjects);
printf("malloc call(s): %d\n", (unsigned int)total_malloc_calls);
printf("realloc(s): %d\n", (unsigned int)total_reallocs);
printf("byte(s)/second: %lld\n", total_bytes / v5);
return 0;
}

original_code:
int
main(int argc, char **argv)
{
 struct timeval tstart, tstop;
 char *dir = ".";
 gettimeofday (&tstart, ((void *)0));
 pathwalk (dir, DoReadNif);
 gettimeofday (&tstop, ((void *)0));
 long ttaken = time_interval (&tstart, &tstop) / (1000*1000);
 printf ("files done: %d (%ld file(s) per second)\n",
  nifcnt, nifcnt / (ttaken ? ttaken : 1));
 printf ("time taken: %ld %.2ld:%.2ld\n",
  ttaken, ttaken / 60, ttaken % 60);
 printf ("total byte(s) read: %lld\n", total_bytes);
 printf ("major niff block(s) parsed: %d\n", total_blocks);
 printf ("niff object(s) parsed: %d\n", total_niobjects);
 printf ("malloc call(s): %d\n", total_malloc_calls);
 printf ("realloc(s): %d\n", total_reallocs);
 printf ("byte(s)/second: %lld\n",
  (total_bytes/(ttaken ? ttaken : 1)));
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct timeval tstart; struct timeval tstop;
 char *dir = ".";
 gettimeofday (&tstart, ((void *)0));
 pathwalk (dir, DoReadNif);
 gettimeofday (&tstop, ((void *)0));
 long ttaken = time_interval (&tstart, &tstop) / (1000*1000);
 printf ("files done: %d (%ld file(s) per second)\n",
  nifcnt, nifcnt / (ttaken ? ttaken : 1));
 printf ("time taken: %ld %.2ld:%.2ld\n",
  ttaken, ttaken / 60, ttaken % 60);
 printf ("total byte(s) read: %lld\n", total_bytes);
 printf ("major niff block(s) parsed: %d\n", total_blocks);
 printf ("niff object(s) parsed: %d\n", total_niobjects);
 printf ("malloc call(s): %d\n", total_malloc_calls);
 printf ("realloc(s): %d\n", total_reallocs);
 printf ("byte(s)/second: %lld\n",
  (total_bytes/(ttaken ? ttaken : 1)));
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

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

variable_types:
dir
char *

variable_types: ttaken long


partGetPos

repo: amotta/StickyParticles

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = vectGetNull();
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = vectGetNull();
return result;
}

original_code:
vect_t partGetPos(part_t* part){
    if(!part) return vectGetNull();
    return part->pos;
}

canonical_original_code:
struct vect_t partGetPos(struct PARTICLE *part){
    if(!part) return vectGetNull();
    return part->pos;
}

variable_types: struct PARTICLE { struct vect_t pos; struct PARTICLE *next; } *

return_type: struct vect_t { double x; double y; }


partSetPos

decompiled_code:
void __fastcall partSetPos(double *a1, double a2, double a3)
{
if ( a1 )
{
*a1 = a2;
a1[1] = a3;
}
}

canonical_decompiled_code:
void __fastcall func3(double *a1, double a2, double a3)
{
if ( a1 )
{
*a1 = a2;
a1[1] = a3;
}
}

original_code:
void partSetPos(part_t* part, vect_t pos){
    if(!part) return;
    part->pos = pos;
}

canonical_original_code:
void partSetPos(struct PARTICLE *part, struct vect_t pos){
    if(!part) return;
    part->pos = pos;
}

variable_types: struct PARTICLE { struct vect_t { double x; double y; } pos; struct PARTICLE *next; } *

variable_types:
pos
struct vect_t

user_defined_types: struct PARTICLE { struct vect_t pos; struct PARTICLE *next; }


partGetNext

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

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

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

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

original_code:
part_t* partGetNext(part_t* part){
    if(!part) return ((void *)0);
    return part->next;
}

canonical_original_code:
struct PARTICLE *partGetNext(struct PARTICLE *part){
    if(!part) return ((void *)0);
    return part->next;
}

variable_types:
part
struct PARTICLE *

return_type: struct PARTICLE { struct vect_t { double x; double y; } pos; struct PARTICLE *next; } *


partSetNext

decompiled_code:
void __fastcall partSetNext(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 + 16) = a2;
}

original_code:
void partSetNext(part_t* part, part_t* next){
    if(!part) return;
    part->next = next;
}

canonical_original_code:
void partSetNext(struct PARTICLE *part, struct PARTICLE *next){
    if(!part) return;
    part->next = next;
}

variable_types:
next
struct PARTICLE *


partCheckPart

decompiled_code:
__int64 __fastcall partCheckPart(__int64 *a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // [rsp+0h] [rbp-48h] BYREF
__int64 v8; // [rsp+20h] [rbp-28h] BYREF

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
partGetCirc(&v7, a2);
partGetCirc(&v8, a1);
result = circCheckCirc(&v8, a1, v3, v4, v5, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, __int64 *a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__int64 v7; // [rsp+0h] [rbp-48h] BYREF
__int64 v8; // [rsp+20h] [rbp-28h] BYREF

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
partGetCirc(&v7, a2);
partGetCirc(&v8, a1);
result = circCheckCirc(&v8, a1, v3, v4, v5, v6);
}
return result;
}

original_code:
_Bool partCheckPart(part_t* partOne, part_t* partTwo){
    if(!partOne || !partTwo) return 0;
    return circCheckCirc(
        partGetCirc(partOne),
        partGetCirc(partTwo)
    );
}

canonical_original_code:
_Bool partCheckPart(struct PARTICLE *partOne, struct PARTICLE *partTwo){
    if(!partOne || !partTwo) return 0;
    return circCheckCirc(
        partGetCirc(partOne),
        partGetCirc(partTwo)
    );
}

variable_types:
partTwo
struct PARTICLE *


partCheckBorder

decompiled_code:
__int64 __fastcall partCheckBorder(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx
__int64 v3; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
if ( a1 )
{
partGetCirc(&v3, a1);
result = circCheckBorder(&v3, a1, v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx
__int64 v3; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
if ( a1 )
{
partGetCirc(&v3, a1);
result = circCheckBorder(&v3, a1, v2);
}
return result;
}

original_code:
int partCheckBorder(part_t* part){
    if(!part) return (0);
    return circCheckBorder(partGetCirc(part));
}

canonical_original_code:
int partCheckBorder(struct PARTICLE *part){
    if(!part) return (0);
    return circCheckBorder(partGetCirc(part));
}


partCheckCirc

decompiled_code:
__int64 __fastcall partCheckCirc(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
__int64 v6; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
if ( a1 )
{
partGetCirc(&v6, a1);
result = circCheckCirc(&v6, a1, v2, v3, v4, v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
__int64 v6; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
if ( a1 )
{
partGetCirc(&v6, a1);
result = circCheckCirc(&v6, a1, v2, v3, v4, v5);
}
return result;
}

original_code:
_Bool partCheckCirc(part_t* part, circ_t circ){
    if(!part) return 0;
    return circCheckCirc(partGetCirc(part), circ);
}

canonical_original_code:
_Bool partCheckCirc(struct PARTICLE *part, struct circ_t circ){
    if(!part) return 0;
    return circCheckCirc(partGetCirc(part), circ);
}

variable_types: struct circ_t { struct vect_t pos; double r; }


partDraw

decompiled_code:
__int64 __fastcall partDraw(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
if ( a1 )
{
partGetCirc(&v2, a1);
gfxCirc(0LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1)
{
__int64 result; // rax
__int64 v2; // [rsp+0h] [rbp-28h] BYREF

result = 0LL;
if ( a1 )
{
partGetCirc(&v2, a1);
gfxCirc(0LL);
result = 1LL;
}
return result;
}

original_code:
_Bool partDraw(part_t* part){
    if(!part) return 0;
    gfxCirc(partGetCirc(part), 0);
    return 1;
}

canonical_original_code:
_Bool partDraw(struct PARTICLE *part){
    if(!part) return 0;
    gfxCirc(partGetCirc(part), 0);
    return 1;
}


partFree

decompiled_code:
__int64 __fastcall partFree(void *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
{
free(a1);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
free(a1);
result = 1LL;
}
return result;
}

original_code:
_Bool partFree(part_t* part){
    if(!part) return 0;
    free(part);
    return 1;
}

canonical_original_code:
_Bool partFree(struct PARTICLE *part){
    if(!part) return 0;
    free(part);
    return 1;
}


gfxCirc

decompiled_code:
__int64 __fastcall gfxCirc(char a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
int i; // ebx
float v10; // xmm0_4
float v11; // xmm1_4
double v13; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a1 )
glBegin(9LL);
else
glBegin(2LL);
for ( i = 0; i != 120; ++i )
{
sincos((double)i * 0.05235987755982988, sinx, &v13);
v10 = a12 * v13 + a10;
v11 = a12 * sinx[0] + a11;
glVertex3f(v10, v11, 0.0);
}
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
int i; // ebx
float v10; // xmm0_4
float v11; // xmm1_4
double v13; // [rsp+0h] [rbp-28h] BYREF
double sinx[4]; // [rsp+8h] [rbp-20h] BYREF

if ( a1 )
glBegin(9LL);
else
glBegin(2LL);
for ( i = 0; i != 120; ++i )
{
sincos((double)i * 0.05235987755982988, sinx, &v13);
v10 = a12 * v13 + a10;
v11 = a12 * sinx[0] + a11;
glVertex3f(v10, v11, 0.0);
}
return glEnd();
}

original_code:
void gfxCirc(circ_t circ, _Bool filled){
    int i;
    double angle;
    angle = 2 * 3.14159265358979323846 / 120;
    if(filled){
        glBegin(0x0009);
    }else{
        glBegin(0x0002);
    }
    for(i = 0; i < 120; i++){
        glVertex3f(
            circ.pos.x + cos(angle * i) * circ.r,
            circ.pos.y + sin(angle * i) * circ.r,
            0
        );
    }
    glEnd();
}

canonical_original_code:
void gfxCirc(struct circ_t circ, _Bool filled){
    int i;
    double angle;
    angle = 2 * 3.14159265358979323846 / 120;
    if(filled){
        glBegin(0x0009);
    }else{
        glBegin(0x0002);
    }
    for(i = 0; i < 120; i++){
        glVertex3f(
            circ.pos.x + cos(angle * i) * circ.r,
            circ.pos.y + sin(angle * i) * circ.r,
            0
        );
    }
    glEnd();
}

variable_types: struct circ_t { struct vect_t { double x; double y; } pos; double r; }

variable_types: i int

variable_types: angle double

user_defined_types: struct circ_t { struct vect_t pos; double r; }


gfxClear

decompiled_code:
__int64 gfxClear()
{
return glClear(0x4000LL);
}

canonical_decompiled_code:
__int64 func1()
{
return glClear(0x4000LL);
}

original_code:
void gfxClear(){
    glClear(0x00004000);
}

canonical_original_code:
void gfxClear(){
    glClear(0x00004000);
}


gfxColor

decompiled_code:
__int64 __fastcall gfxColor(double a1, double a2, double a3)
{
float v3; // xmm0_4
float v4; // xmm2_4
float v5; // xmm1_4

glColor3d();
v3 = a1;
v4 = a3;
v5 = a2;
return glClearColor(v3, v5, v4, 1.0);
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, double a2, double a3)
{
float v3; // xmm0_4
float v4; // xmm2_4
float v5; // xmm1_4

glColor3d();
v3 = a1;
v4 = a3;
v5 = a2;
return glClearColor(v3, v5, v4, 1.0);
}

original_code:
void gfxColor(double r, double g, double b){
    glColor3d(r, g, b);
    glClearColor(r, g, b, 1);
}

variable_types: r double

variable_types: g double

variable_types: b double


gfxLine

decompiled_code:
__int64 __fastcall gfxLine(double a1, double a2, double a3, double a4)
{
float v4; // xmm0_4
float v5; // xmm1_4
float v6; // xmm0_4
float v7; // xmm1_4

glBegin(1LL);
v4 = a1;
v5 = a2;
glVertex3f(v4, v5, 0.0);
v6 = a3;
v7 = a4;
glVertex3f(v6, v7, 0.0);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func3(double a1, double a2, double a3, double a4)
{
float v4; // xmm0_4
float v5; // xmm1_4
float v6; // xmm0_4
float v7; // xmm1_4

glBegin(1LL);
v4 = a1;
v5 = a2;
glVertex3f(v4, v5, 0.0);
v6 = a3;
v7 = a4;
glVertex3f(v6, v7, 0.0);
return glEnd();
}

original_code:
void gfxLine(double x1, double y1, double x2, double y2){
    glBegin(0x0001);
    glVertex3f(x1, y1, 0);
    glVertex3f(x2, y2, 0);
    glEnd();
}


gfxRect

decompiled_code:
__int64 __fastcall gfxRect(char a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13)
{
__m128i v10; // xmm1
__m128i v11; // xmm3
__m128i v12; // xmm4
float v13; // er15
__m128i v14; // xmm5
float v15; // ebx

if ( a1 )
glBegin(9LL);
else
glBegin(2LL);
v10 = 0LL;
*(float *)v10.m128i_i32 = a13;
v11 = 0LL;
*(float *)v11.m128i_i32 = a10;
glVertex3f(*(float *)v11.m128i_i32, *(float *)v10.m128i_i32, 0.0);
v12 = 0LL;
*(float *)v12.m128i_i32 = a11;
v13 = COERCE_FLOAT(_mm_cvtsi128_si32(v12));
glVertex3f(*(float *)v12.m128i_i32, COERCE_FLOAT(_mm_cvtsi128_si32(v10)), 0.0);
v14 = 0LL;
*(float *)v14.m128i_i32 = a12;
v15 = COERCE_FLOAT(_mm_cvtsi128_si32(v14));
glVertex3f(v13, *(float *)v14.m128i_i32, 0.0);
glVertex3f(COERCE_FLOAT(_mm_cvtsi128_si32(v11)), v15, 0.0);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13)
{
__m128i v10; // xmm1
__m128i v11; // xmm3
__m128i v12; // xmm4
float v13; // er15
__m128i v14; // xmm5
float v15; // ebx

if ( a1 )
glBegin(9LL);
else
glBegin(2LL);
v10 = 0LL;
*(float *)v10.m128i_i32 = a13;
v11 = 0LL;
*(float *)v11.m128i_i32 = a10;
glVertex3f(*(float *)v11.m128i_i32, *(float *)v10.m128i_i32, 0.0);
v12 = 0LL;
*(float *)v12.m128i_i32 = a11;
v13 = COERCE_FLOAT(_mm_cvtsi128_si32(v12));
glVertex3f(*(float *)v12.m128i_i32, COERCE_FLOAT(_mm_cvtsi128_si32(v10)), 0.0);
v14 = 0LL;
*(float *)v14.m128i_i32 = a12;
v15 = COERCE_FLOAT(_mm_cvtsi128_si32(v14));
glVertex3f(v13, *(float *)v14.m128i_i32, 0.0);
glVertex3f(COERCE_FLOAT(_mm_cvtsi128_si32(v11)), v15, 0.0);
return glEnd();
}

original_code:
void gfxRect(rect_t rect, _Bool filled){
    if(filled){
        glBegin(0x0009);
    }else{
        glBegin(0x0002);
    }
    glVertex3f(rect.left, rect.top, 0);
    glVertex3f(rect.right, rect.top, 0);
    glVertex3f(rect.right, rect.bottom, 0);
    glVertex3f(rect.left, rect.bottom, 0);
    glEnd();
}

canonical_original_code:
void gfxRect(struct rect_t rect, _Bool filled){
    if(filled){
        glBegin(0x0009);
    }else{
        glBegin(0x0002);
    }
    glVertex3f(rect.left, rect.top, 0);
    glVertex3f(rect.right, rect.top, 0);
    glVertex3f(rect.right, rect.bottom, 0);
    glVertex3f(rect.left, rect.bottom, 0);
    glEnd();
}

variable_types: struct rect_t { double left; double right; double bottom; double top; }


emitterGetPos

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = vectGetNull();
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = vectGetNull();
return result;
}

original_code:
vect_t emitterGetPos(emitter_t* emitter){
    if(!emitter) return vectGetNull();
    return emitter->pos;
}

canonical_original_code:
struct vect_t emitterGetPos(struct EMITTER *emitter){
    if(!emitter) return vectGetNull();
    return emitter->pos;
}

variable_types: struct EMITTER { struct vect_t pos; double angle; double alpha; double flow; double speed; } *


emitterSetPos

decompiled_code:
void __fastcall emitterSetPos(double *a1, double a2, double a3)
{
double v4; // xmm2_8

if ( a1 )
{
*a1 = a2;
a1[1] = a3;
v4 = getGameCenter();
a1[2] = atan2(a3 - a3, a2 - v4) + 3.141592653589793;
}
}

canonical_decompiled_code:
void __fastcall func2(double *a1, double a2, double a3)
{
double v4; // xmm2_8

if ( a1 )
{
*a1 = a2;
a1[1] = a3;
v4 = getGameCenter();
a1[2] = atan2(a3 - a3, a2 - v4) + 3.141592653589793;
}
}

original_code:
void emitterSetPos(emitter_t* emitter, vect_t pos){
    vect_t gameCenter;
    double diffX, diffY;
    if(!emitter) return;
    emitter->pos = pos;
    gameCenter = getGameCenter();
    diffX = pos.x - gameCenter.x;
    diffY = pos.y - gameCenter.y;
    emitter->angle = atan2(diffY, diffX) + 3.14159265358979323846;
}

canonical_original_code:
void emitterSetPos(struct EMITTER *emitter, struct vect_t pos){
    struct vect_t gameCenter;
    double diffX; double diffY;
    if(!emitter) return;
    emitter->pos = pos;
    gameCenter = getGameCenter();
    diffX = pos.x - gameCenter.x;
    diffY = pos.y - gameCenter.y;
    emitter->angle = atan2(diffY, diffX) + 3.14159265358979323846;
}

variable_types: struct EMITTER { struct vect_t { double x; double y; } pos; double angle; double alpha; double flow; double speed; } *

variable_types:
gameCenter
struct vect_t { double x; double y; }

variable_types: diffX double

variable_types: diffY double

user_defined_types: struct EMITTER { struct vect_t pos; double angle; double alpha; double flow; double speed; }