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

v0 = *((_DWORD *)&peticion + 2);
switch ( v0 )
{
case 0u:
printf(
"Peticion de alta del cliente %d/%d, con pid %ld\n",
(unsigned int)(num_clientes + 1),
(unsigned int)max_clientes,
peticion);
*((_DWORD *)vector_clientes + num_clientes) = peticion;
sem_wait(sclientes);
++num_clientes;
sem_post(sclientes);
respuesta[2] = 0;
break;
case 1u:
sem_wait(mutex);
raizarbol = insertar_elemento(raizarbol, *(unsigned int *)dato);
respuesta[2] = 0;
sem_post(mutex);
break;
case 2u:
sem_wait(mutex);
respuesta[2] = 0;
raizarbol = borrar(raizarbol, *(unsigned int *)dato);
sem_post(mutex);
break;
case 3u:
sem_wait(mutex);
if ( buscar(raizarbol, *(unsigned int *)dato) )
v0 = 2;
respuesta[2] = v0;
sem_post(mutex);
break;
case 4u:
if ( (unsigned int)baja((unsigned int)peticion) == 1 )
{
sem_wait(sclientes);
--num_clientes;
sem_post(sclientes);
printf(
"Peticion de baja del cliente %ld, clientes conectados %d/%d\n",
peticion,
(unsigned int)num_clientes,
(unsigned int)max_clientes);
respuesta[2] = 0;
sem_post(s1);
}
else
{
respuesta[2] = 1;
}
break;
default:
return registrando_en_logfile(2);
}
return registrando_en_logfile(2);
}

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

v0 = *((_DWORD *)&peticion + 2);
switch ( v0 )
{
case 0u:
printf(
"Peticion de alta del cliente %d/%d, con pid %ld\n",
(unsigned int)(num_clientes + 1),
(unsigned int)max_clientes,
peticion);
*((_DWORD *)vector_clientes + num_clientes) = peticion;
sem_wait(sclientes);
++num_clientes;
sem_post(sclientes);
respuesta[2] = 0;
break;
case 1u:
sem_wait(mutex);
raizarbol = insertar_elemento(raizarbol, *(unsigned int *)dato);
respuesta[2] = 0;
sem_post(mutex);
break;
case 2u:
sem_wait(mutex);
respuesta[2] = 0;
raizarbol = borrar(raizarbol, *(unsigned int *)dato);
sem_post(mutex);
break;
case 3u:
sem_wait(mutex);
if ( buscar(raizarbol, *(unsigned int *)dato) )
v0 = 2;
respuesta[2] = v0;
sem_post(mutex);
break;
case 4u:
if ( (unsigned int)baja((unsigned int)peticion) == 1 )
{
sem_wait(sclientes);
--num_clientes;
sem_post(sclientes);
printf(
"Peticion de baja del cliente %ld, clientes conectados %d/%d\n",
peticion,
(unsigned int)num_clientes,
(unsigned int)max_clientes);
respuesta[2] = 0;
sem_post(s1);
}
else
{
respuesta[2] = 1;
}
break;
default:
return func13(2);
}
return func13(2);
}

original_code:
void operacion_arbol(void)
{
    switch(peticion.codigo_operacion)
    {
    case 0:
        printf("Peticion de alta del cliente %d/%d, con pid %ld\n",num_clientes+1,max_clientes,peticion.tipo);
        vector_clientes[num_clientes]=peticion.tipo;
        sem_wait(sclientes);
        num_clientes++;
        sem_post(sclientes);
        respuesta.codigo_error=0;
        break;
    case 1:
        sem_wait(mutex);
        raizarbol=insertar_elemento(raizarbol,*dato);
        respuesta.codigo_error=0;
        sem_post(mutex);
        break;
    case 2:
        sem_wait(mutex);
        respuesta.codigo_error=0;
        raizarbol=borrar(raizarbol,*dato);
        sem_post(mutex);
        break;
    case 3:
        sem_wait(mutex);
        if(buscar(raizarbol,*dato)!=((void *)0))
        {
            respuesta.codigo_error=2;
        }
        else
        {
            respuesta.codigo_error=3;
        }
        sem_post(mutex);
        break;
    case 4:
        if(baja(peticion.tipo)==1)
        {
            sem_wait(sclientes);
            num_clientes--;
            sem_post(sclientes);
            printf("Peticion de baja del cliente %ld, clientes conectados %d/%d\n",peticion.tipo,num_clientes,max_clientes);
            respuesta.codigo_error=0;
            sem_post(s1);
        }
        else
        {
            respuesta.codigo_error=1;
        }
        break;
    }
    registrando_en_logfile(2);
   return;
}

canonical_original_code:
void operacion_arbol()
{
    switch(peticion.codigo_operacion)
    {
    case 0:
        printf("Peticion de alta del cliente %d/%d, con pid %ld\n",num_clientes+1,max_clientes,peticion.tipo);
        vector_clientes[num_clientes]=peticion.tipo;
        sem_wait(sclientes);
        num_clientes++;
        sem_post(sclientes);
        respuesta.codigo_error=0;
        break;
    case 1:
        sem_wait(mutex);
        raizarbol=insertar_elemento(raizarbol,*dato);
        respuesta.codigo_error=0;
        sem_post(mutex);
        break;
    case 2:
        sem_wait(mutex);
        respuesta.codigo_error=0;
        raizarbol=borrar(raizarbol,*dato);
        sem_post(mutex);
        break;
    case 3:
        sem_wait(mutex);
        if(buscar(raizarbol,*dato)!=((void *)0))
        {
            respuesta.codigo_error=2;
        }
        else
        {
            respuesta.codigo_error=3;
        }
        sem_post(mutex);
        break;
    case 4:
        if(baja(peticion.tipo)==1)
        {
            sem_wait(sclientes);
            num_clientes--;
            sem_post(sclientes);
            printf("Peticion de baja del cliente %ld, clientes conectados %d/%d\n",peticion.tipo,num_clientes,max_clientes);
            respuesta.codigo_error=0;
            sem_post(s1);
        }
        else
        {
            respuesta.codigo_error=1;
        }
        break;
    }
    registrando_en_logfile(2);
   return;
}


visualizar

decompiled_code:
unsigned int *__fastcall visualizar(unsigned int *a1)
{
if ( a1 )
{
visualizar(*((_QWORD *)a1 + 2));
printf(" %d ", *a1);
visualizar(*((_QWORD *)a1 + 1));
}
return a1;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int *a1)
{
if ( a1 )
{
func0(*((_QWORD *)a1 + 2));
printf(" %d ", *a1);
func0(*((_QWORD *)a1 + 1));
}
return a1;
}

original_code:
Nodo* visualizar(Nodo* raiz)
{
    if (raiz != ((void *)0))
    {
        visualizar(raiz->izq);
        printf(" %d ",raiz->dato);
        visualizar(raiz->der);
    }
    return raiz;
}

canonical_original_code:
struct NodoArbol *visualizar(struct NodoArbol *raiz)
{
    if (raiz != ((void *)0))
    {
        visualizar(raiz->izq);
        printf(" %d ",raiz->dato);
        visualizar(raiz->der);
    }
    return raiz;
}

variable_types:
raiz
struct NodoArbol *

return_type: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; } *


borrar

decompiled_code:
unsigned int *__fastcall borrar(__int64 a1, signed int a2)
{
_QWORD *v2; // rbp
__int64 v3; // rax
unsigned int *v4; // rbx
unsigned int *v5; // r15
unsigned int *v6; // r13
unsigned int *j; // rax
__int64 v8; // rax
__int64 v10; // rax
unsigned int *i; // rax
__int64 v12; // rax
__int64 v13; // rax
unsigned int *k; // rax
__int64 v15; // rax
unsigned int *v16; // rax
__int64 v17; // rax

v2 = (_QWORD *)buscar();
v3 = buscar_padre(a1, (unsigned int)a2);
if ( !v2 )
{
respuesta[2] = 3;
return (unsigned int *)a1;
}
v4 = (unsigned int *)v3;
v5 = (unsigned int *)v2[1];
if ( v5 )
{
if ( v3 )
{
v6 = (unsigned int *)v2[2];
if ( !v6 )
{
for ( i = (unsigned int *)*((_QWORD *)v5 + 2); i; i = (unsigned int *)*((_QWORD *)i + 2) )
v5 = i;
if ( (int)*v4 <= a2 )
{
v13 = buscar_padre(a1, *v5);
*((_QWORD *)v4 + 1) = v5;
if ( *(_DWORD *)v13 != *(_DWORD *)v2 )
{
*(_QWORD *)(v13 + 8) = *((_QWORD *)v5 + 2);
*((_QWORD *)v5 + 1) = v2[1];
}
*((_QWORD *)v5 + 2) = v2[2];
}
else
{
v12 = buscar_padre(a1, *v5);
*((_QWORD *)v4 + 2) = v5;
if ( *(_DWORD *)v12 != *(_DWORD *)v2 )
{
*(_QWORD *)(v12 + 8) = *((_QWORD *)v5 + 2);
*((_QWORD *)v5 + 1) = v2[1];
}
*((_QWORD *)v5 + 2) = v2[2];
}
goto LABEL_11;
}
goto LABEL_5;
}
v4 = (unsigned int *)v2[2];
if ( !v4 )
{
v16 = (unsigned int *)*((_QWORD *)v5 + 2);
if ( v16 )
{
do
{
v4 = v16;
v16 = (unsigned int *)*((_QWORD *)v16 + 2);
}
while ( v16 );
}
else
{
v4 = (unsigned int *)v2[1];
}
v17 = buscar_padre(a1, *v4);
if ( *(_DWORD *)v17 != *(_DWORD *)v2 )
{
*(_QWORD *)(v17 + 16) = *((_QWORD *)v4 + 1);
*((_QWORD *)v4 + 1) = v2[1];
}
*((_QWORD *)v4 + 2) = v2[2];
goto LABEL_39;
}
goto LABEL_34;
}
v6 = (unsigned int *)v2[2];
if ( v6 )
{
if ( v3 )
{
LABEL_5:
for ( j = (unsigned int *)*((_QWORD *)v6 + 1); j; j = (unsigned int *)*((_QWORD *)j + 1) )
v6 = j;
if ( (int)*v4 <= a2 )
{
v10 = buscar_padre(a1, *v6);
*((_QWORD *)v4 + 1) = v6;
if ( *(_DWORD *)v10 != *(_DWORD *)v2 )
{
*(_QWORD *)(v10 + 8) = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v2[2];
}
*((_QWORD *)v6 + 1) = v2[1];
}
else
{
v8 = buscar_padre(a1, *v6);
*((_QWORD *)v4 + 2) = v6;
if ( *(_DWORD *)v8 != *(_DWORD *)v2 )
{
*(_QWORD *)(v8 + 8) = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v2[2];
}
*((_QWORD *)v6 + 1) = v2[1];
}
goto LABEL_11;
}
v4 = (unsigned int *)v2[2];
LABEL_34:
for ( k = (unsigned int *)*((_QWORD *)v4 + 1); k; k = (unsigned int *)*((_QWORD *)k + 1) )
v4 = k;
v15 = buscar_padre(a1, *v4);
if ( *(_DWORD *)v15 != *(_DWORD *)v2 )
{
*(_QWORD *)(v15 + 8) = *((_QWORD *)v4 + 2);
*((_QWORD *)v4 + 2) = v2[2];
}
*((_QWORD *)v4 + 1) = v2[1];
goto LABEL_39;
}
if ( !v3 )
{
LABEL_39:
free(v2);
return v4;
}
if ( *(_DWORD *)v3 <= a2 )
*(_QWORD *)(v3 + 8) = 0LL;
else
*(_QWORD *)(v3 + 16) = 0LL;
LABEL_11:
free(v2);
return (unsigned int *)a1;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(__int64 a1, signed int a2)
{
_QWORD *v2; // rbp
__int64 v3; // rax
unsigned int *v4; // rbx
unsigned int *v5; // r15
unsigned int *v6; // r13
unsigned int *j; // rax
__int64 v8; // rax
__int64 v10; // rax
unsigned int *i; // rax
__int64 v12; // rax
__int64 v13; // rax
unsigned int *k; // rax
__int64 v15; // rax
unsigned int *v16; // rax
__int64 v17; // rax

v2 = (_QWORD *)buscar();
v3 = buscar_padre(a1, (unsigned int)a2);
if ( !v2 )
{
respuesta[2] = 3;
return (unsigned int *)a1;
}
v4 = (unsigned int *)v3;
v5 = (unsigned int *)v2[1];
if ( v5 )
{
if ( v3 )
{
v6 = (unsigned int *)v2[2];
if ( !v6 )
{
for ( i = (unsigned int *)*((_QWORD *)v5 + 2); i; i = (unsigned int *)*((_QWORD *)i + 2) )
v5 = i;
if ( (int)*v4 <= a2 )
{
v13 = buscar_padre(a1, *v5);
*((_QWORD *)v4 + 1) = v5;
if ( *(_DWORD *)v13 != *(_DWORD *)v2 )
{
*(_QWORD *)(v13 + 8) = *((_QWORD *)v5 + 2);
*((_QWORD *)v5 + 1) = v2[1];
}
*((_QWORD *)v5 + 2) = v2[2];
}
else
{
v12 = buscar_padre(a1, *v5);
*((_QWORD *)v4 + 2) = v5;
if ( *(_DWORD *)v12 != *(_DWORD *)v2 )
{
*(_QWORD *)(v12 + 8) = *((_QWORD *)v5 + 2);
*((_QWORD *)v5 + 1) = v2[1];
}
*((_QWORD *)v5 + 2) = v2[2];
}
goto LABEL_11;
}
goto LABEL_5;
}
v4 = (unsigned int *)v2[2];
if ( !v4 )
{
v16 = (unsigned int *)*((_QWORD *)v5 + 2);
if ( v16 )
{
do
{
v4 = v16;
v16 = (unsigned int *)*((_QWORD *)v16 + 2);
}
while ( v16 );
}
else
{
v4 = (unsigned int *)v2[1];
}
v17 = buscar_padre(a1, *v4);
if ( *(_DWORD *)v17 != *(_DWORD *)v2 )
{
*(_QWORD *)(v17 + 16) = *((_QWORD *)v4 + 1);
*((_QWORD *)v4 + 1) = v2[1];
}
*((_QWORD *)v4 + 2) = v2[2];
goto LABEL_39;
}
goto LABEL_34;
}
v6 = (unsigned int *)v2[2];
if ( v6 )
{
if ( v3 )
{
LABEL_5:
for ( j = (unsigned int *)*((_QWORD *)v6 + 1); j; j = (unsigned int *)*((_QWORD *)j + 1) )
v6 = j;
if ( (int)*v4 <= a2 )
{
v10 = buscar_padre(a1, *v6);
*((_QWORD *)v4 + 1) = v6;
if ( *(_DWORD *)v10 != *(_DWORD *)v2 )
{
*(_QWORD *)(v10 + 8) = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v2[2];
}
*((_QWORD *)v6 + 1) = v2[1];
}
else
{
v8 = buscar_padre(a1, *v6);
*((_QWORD *)v4 + 2) = v6;
if ( *(_DWORD *)v8 != *(_DWORD *)v2 )
{
*(_QWORD *)(v8 + 8) = *((_QWORD *)v6 + 2);
*((_QWORD *)v6 + 2) = v2[2];
}
*((_QWORD *)v6 + 1) = v2[1];
}
goto LABEL_11;
}
v4 = (unsigned int *)v2[2];
LABEL_34:
for ( k = (unsigned int *)*((_QWORD *)v4 + 1); k; k = (unsigned int *)*((_QWORD *)k + 1) )
v4 = k;
v15 = buscar_padre(a1, *v4);
if ( *(_DWORD *)v15 != *(_DWORD *)v2 )
{
*(_QWORD *)(v15 + 8) = *((_QWORD *)v4 + 2);
*((_QWORD *)v4 + 2) = v2[2];
}
*((_QWORD *)v4 + 1) = v2[1];
goto LABEL_39;
}
if ( !v3 )
{
LABEL_39:
free(v2);
return v4;
}
if ( *(_DWORD *)v3 <= a2 )
*(_QWORD *)(v3 + 8) = 0LL;
else
*(_QWORD *)(v3 + 16) = 0LL;
LABEL_11:
free(v2);
return (unsigned int *)a1;
}

original_code:
Nodo* borrar(Nodo* raiz,int d)
{
    Nodo *paux1,*paux2,*borr,*padre;
    borr=buscar(raiz,d);
    padre=buscar_padre(raiz,d);
    if(borr!=((void *)0))
    {
        if(borr->der==((void *)0) && borr->izq==((void *)0))
        {
            if(padre==((void *)0))
            {
                free(borr);
                return ((void *)0);
            }
            else
            {
                if(padre->dato>d)
                {
                    padre->izq=((void *)0);
                }
                else
                {
                    padre->der=((void *)0);
                }
            }
        }
        else
        {
            if(padre!=((void *)0))
            {
                if(borr->izq!=((void *)0))
                {
                    paux1=borr->izq;
                    paux2=paux1->der;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->der;
                    }
                    if(padre->dato>d)
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->izq=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->izq=borr->izq;
                        }
                        paux1->der=borr->der;
                    }
                    else
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->der=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->izq=borr->izq;
                        }
                        paux1->der=borr->der;
                    }
                }
                else
                {
                    paux1=borr->der;
                    paux2=paux1->izq;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->izq;
                    }
                    if(padre->dato>d)
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->izq=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->der=borr->der;
                        }
                        paux1->izq=borr->izq;
                    }
                    else
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->der=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->der=borr->der;
                        }
                        paux1->izq=borr->izq;
                    }
                }
            }
            else
            {
                if(borr->izq!=((void *)0))
                {
                    paux1=borr->izq;
                    paux2=paux1->der;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->der;
                    }
                    paux2=buscar_padre(raiz,paux1->dato);
                    if(paux2->dato!=borr->dato)
                    {
                        paux2->der=paux1->izq;
                        paux1->izq=borr->izq;
                    }
                    paux1->der=borr->der;
                }
                else
                {
                    paux1=borr->der;
                    paux2=paux1->izq;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->izq;
                    }
                    paux2=buscar_padre(raiz,paux1->dato);
                    if(paux2->dato!=borr->dato)
                    {
                        paux2->izq=paux1->der;
                        paux1->der=borr->der;
                    }
                    paux1->izq=borr->izq;
                }
                free(borr);
                return (paux1);
            }
        }
        free(borr);
        return raiz;
    }
    else
    {
        respuesta.codigo_error=3;
        return raiz;
    }
}

canonical_original_code:
struct NodoArbol *borrar(struct NodoArbol *raiz, int d)
{
    struct NodoArbol *paux1; struct NodoArbol *paux2; struct NodoArbol *borr; struct NodoArbol *padre;
    borr=buscar(raiz,d);
    padre=buscar_padre(raiz,d);
    if(borr!=((void *)0))
    {
        if(borr->der==((void *)0) && borr->izq==((void *)0))
        {
            if(padre==((void *)0))
            {
                free(borr);
                return ((void *)0);
            }
            else
            {
                if(padre->dato>d)
                {
                    padre->izq=((void *)0);
                }
                else
                {
                    padre->der=((void *)0);
                }
            }
        }
        else
        {
            if(padre!=((void *)0))
            {
                if(borr->izq!=((void *)0))
                {
                    paux1=borr->izq;
                    paux2=paux1->der;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->der;
                    }
                    if(padre->dato>d)
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->izq=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->izq=borr->izq;
                        }
                        paux1->der=borr->der;
                    }
                    else
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->der=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->izq=borr->izq;
                        }
                        paux1->der=borr->der;
                    }
                }
                else
                {
                    paux1=borr->der;
                    paux2=paux1->izq;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->izq;
                    }
                    if(padre->dato>d)
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->izq=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->der=borr->der;
                        }
                        paux1->izq=borr->izq;
                    }
                    else
                    {
                        paux2=buscar_padre(raiz,paux1->dato);
                        padre->der=paux1;
                        if(paux2->dato!=borr->dato)
                        {
                            paux2->der=paux1->izq;
                            paux1->der=borr->der;
                        }
                        paux1->izq=borr->izq;
                    }
                }
            }
            else
            {
                if(borr->izq!=((void *)0))
                {
                    paux1=borr->izq;
                    paux2=paux1->der;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->der;
                    }
                    paux2=buscar_padre(raiz,paux1->dato);
                    if(paux2->dato!=borr->dato)
                    {
                        paux2->der=paux1->izq;
                        paux1->izq=borr->izq;
                    }
                    paux1->der=borr->der;
                }
                else
                {
                    paux1=borr->der;
                    paux2=paux1->izq;
                    while(paux2!=((void *)0))
                    {
                        paux1=paux2;
                        paux2=paux1->izq;
                    }
                    paux2=buscar_padre(raiz,paux1->dato);
                    if(paux2->dato!=borr->dato)
                    {
                        paux2->izq=paux1->der;
                        paux1->der=borr->der;
                    }
                    paux1->izq=borr->izq;
                }
                free(borr);
                return (paux1);
            }
        }
        free(borr);
        return raiz;
    }
    else
    {
        respuesta.codigo_error=3;
        return raiz;
    }
}

variable_types: d int

variable_types: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; } *


decompiled_code:
int atender_peticion()
{
cliente_activo = getpid();
*((_DWORD *)&cliente_activo + 2) = 1;
return msgsnd(Q_clientes_activos, &cliente_activo, 4uLL, 0);
}

canonical_decompiled_code:
int func0()
{
cliente_activo = getpid();
*((_DWORD *)&cliente_activo + 2) = 1;
return msgsnd(Q_clientes_activos, &cliente_activo, 4uLL, 0);
}

original_code:
void atender_peticion(int sig)
{
    cliente_activo.tipo = getpid();
    cliente_activo.codigo_operacion = 1;
    msgsnd(Q_clientes_activos, &cliente_activo,sizeof(int),0);
}

variable_types: sig int

return_type: void


decompiled_code:
int __fastcall abrir_cola(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&format, (unsigned int)*v4);
exit(-1);
}
result = msgget(v2, 0);
if ( result < 0 )
{
puts(&s);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&format, (unsigned int)*v4);
exit(-1);
}
result = msgget(v2, 0);
if ( result < 0 )
{
puts(&s);
exit(-1);
}
return result;
}

original_code:
int abrir_cola(char nombre[], char id)
{
    int cola;
    key_t llave = ftok(nombre, id);
    if(llave < 0)
    {
        printf("¡Error! ftok fallo con errno = %d\n",(*__errno_location ()));
        exit(-1);
    }
    cola = msgget(llave, 0);
    if(cola < 0)
    {
        printf("¡Error! No esta ejecutado el servidor.\n");
        exit(-1);
    }
    return cola;
}

canonical_original_code:
int abrir_cola(char nombre[], char id)
{
    int cola;
    int llave = ftok(nombre, id);
    if(llave < 0)
    {
        printf("¡Error! ftok fallo con errno = %d\n",(*__errno_location ()));
        exit(-1);
    }
    cola = msgget(llave, 0);
    if(cola < 0)
    {
        printf("¡Error! No esta ejecutado el servidor.\n");
        exit(-1);
    }
    return cola;
}

variable_types:
nombre
char []

variable_types: id char

variable_types: cola int

variable_types: llave int

return_type: int


decompiled_code:
int __fastcall abrir_memoria_compartida(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax
int *v5; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&byte_288, (unsigned int)*v4);
exit(-1);
}
result = shmget(v2, 4uLL, 384);
if ( result < 0 )
{
v5 = _errno_location();
printf(&byte_2D0, (unsigned int)*v5);
exit(-1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(const char *a1, char a2)
{
int v2; // eax
int result; // eax
int *v4; // rax
int *v5; // rax

v2 = ftok(a1, a2);
if ( v2 < 0 )
{
v4 = _errno_location();
printf(&byte_288, (unsigned int)*v4);
exit(-1);
}
result = shmget(v2, 4uLL, 384);
if ( result < 0 )
{
v5 = _errno_location();
printf(&byte_2D0, (unsigned int)*v5);
exit(-1);
}
return result;
}

original_code:
int abrir_memoria_compartida(char nombre[], char id)
{
    int memoria;
    key_t keymemo=ftok(nombre,id);
    if(keymemo < 0)
    {
        printf("¡Error! Fallo recuperando token de mem. compartida. [ERROR %d]\n", (*__errno_location ()));
        exit(-1);
    }
    memoria = shmget(keymemo,sizeof(int),0600);
    if(memoria < 0)
    {
        printf("¡Error! No se pudo acceder a la memoria compartida, [ERROR %d]\n", (*__errno_location ()));
        exit(-1);
    }
    return memoria;
}

canonical_original_code:
int abrir_memoria_compartida(char nombre[], char id)
{
    int memoria;
    int keymemo = ftok(nombre,id);
    if(keymemo < 0)
    {
        printf("¡Error! Fallo recuperando token de mem. compartida. [ERROR %d]\n", (*__errno_location ()));
        exit(-1);
    }
    memoria = shmget(keymemo,sizeof(int),0600);
    if(memoria < 0)
    {
        printf("¡Error! No se pudo acceder a la memoria compartida, [ERROR %d]\n", (*__errno_location ()));
        exit(-1);
    }
    return memoria;
}

variable_types: memoria int

variable_types: keymemo int


buscar

decompiled_code:
__int64 __fastcall buscar(__int64 a1, int a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 > a2 )
return buscar(*(_QWORD *)(a1 + 16));
result = a1;
if ( *(_DWORD *)a1 < a2 )
result = buscar(*(_QWORD *)(a1 + 8));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 > a2 )
return func0(*(_QWORD *)(a1 + 16));
result = a1;
if ( *(_DWORD *)a1 < a2 )
result = func0(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
Nodo* buscar(Nodo* raiz,int d)
{
    if (raiz==((void *)0))
    {
        return ((void *)0);
    }
    else if (d<raiz->dato)
    {
        buscar(raiz->izq,d);
    }
    else if (d>raiz->dato)
    {
        buscar(raiz->der,d);
    }
    else
    {
        return raiz;
    }
}

canonical_original_code:
struct NodoArbol *buscar(struct NodoArbol *raiz, int d)
{
    if (raiz==((void *)0))
    {
        return ((void *)0);
    }
    else if (d<raiz->dato)
    {
        buscar(raiz->izq,d);
    }
    else if (d>raiz->dato)
    {
        buscar(raiz->der,d);
    }
    else
    {
        return raiz;
    }
}

user_defined_types: struct NodoArbol { int dato; struct NodoArbol *der; struct NodoArbol *izq; }


decompiled_code:
__int64 __fastcall buscar_padre(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 v3; // rax

if ( !a1 )
return 0LL;
v2 = 0LL;
while ( *(_DWORD *)a1 != a2 )
{
if ( *(_DWORD *)a1 >= a2 )
v3 = *(_QWORD *)(a1 + 16);
else
v3 = *(_QWORD *)(a1 + 8);
v2 = a1;
if ( !v3 )
return 0LL;
a1 = v3;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 v3; // rax

if ( !a1 )
return 0LL;
v2 = 0LL;
while ( *(_DWORD *)a1 != a2 )
{
if ( *(_DWORD *)a1 >= a2 )
v3 = *(_QWORD *)(a1 + 16);
else
v3 = *(_QWORD *)(a1 + 8);
v2 = a1;
if ( !v3 )
return 0LL;
a1 = v3;
}
return v2;
}

original_code:
Nodo* buscar_padre(Nodo* raiz,int d)
{
    Nodo *paux2,*paux1;
    paux1=raiz;
    paux2=((void *)0);
    if(raiz==((void *)0))
        return paux2;
    while (paux1->dato!=d)
    {
        if(paux1->dato<d)
        {
            paux2=paux1;
            paux1=paux1->der;
        }
        else
        {
            paux2=paux1;
            paux1=paux1->izq;
        }
        if (paux1==((void *)0))
        {
            return ((void *)0);
        }
    }
    return paux2;
}

canonical_original_code:
struct NodoArbol *buscar_padre(struct NodoArbol *raiz, int d)
{
    struct NodoArbol *paux2; struct NodoArbol *paux1;
    paux1=raiz;
    paux2=((void *)0);
    if(raiz==((void *)0))
        return paux2;
    while (paux1->dato!=d)
    {
        if(paux1->dato<d)
        {
            paux2=paux1;
            paux1=paux1->der;
        }
        else
        {
            paux2=paux1;
            paux1=paux1->izq;
        }
        if (paux1==((void *)0))
        {
            return ((void *)0);
        }
    }
    return paux2;
}


decompiled_code:
void matar_cliente_inactivo()
{
if ( (unsigned int)baja((unsigned int)matar_pid) == 1 )
{
sem_wait(sclientes);
--num_clientes;
sem_post(sclientes);
printf(
"Eliminado el cliente %d por inactividad, clientes conectados %d/%d\n",
(unsigned int)matar_pid,
(unsigned int)num_clientes,
(unsigned int)max_clientes);
sem_post(s1);
}
}

canonical_decompiled_code:
void func0()
{
if ( (unsigned int)baja((unsigned int)matar_pid) == 1 )
{
sem_wait(sclientes);
--num_clientes;
sem_post(sclientes);
printf(
"Eliminado el cliente %d por inactividad, clientes conectados %d/%d\n",
(unsigned int)matar_pid,
(unsigned int)num_clientes,
(unsigned int)max_clientes);
sem_post(s1);
}
}

original_code:
void matar_cliente_inactivo(int sig)
{
    if(baja(matar_pid)==1)
    {
        sem_wait(sclientes);
        num_clientes--;
        sem_post(sclientes);
        printf("Eliminado el cliente %d por inactividad, clientes conectados %d/%d\n",matar_pid,num_clientes,max_clientes);
        sem_post(s1);
    }
}


decompiled_code:
void __noreturn control_clientes()
{
__int64 v0; // rbx
__pid_t v1; // edi

puts("Iniciando el control de clientes activos...");
signal(14, (__sighandler_t)matar_cliente_inactivo);
while ( 1 )
{
while ( num_clientes <= 0 )
;
v0 = 0LL;
do
{
v1 = *(_DWORD *)(vector_clientes + 4 * v0);
if ( v1 )
{
matar_pid = *(_DWORD *)(vector_clientes + 4 * v0);
kill(v1, 10);
alarm(5u);
printf("Comprobando actividad del cliente %d\n", (unsigned int)matar_pid);
msgrcv(Q_clientes_activos, &cliente_activo, 4uLL, *(int *)(vector_clientes + 4 * v0), 0);
alarm(0);
sleep(0x14u);
}
++v0;
}
while ( num_clientes > (int)v0 );
}
}

canonical_decompiled_code:
void __noreturn func1()
{
__int64 v0; // rbx
__pid_t v1; // edi

puts("Iniciando el control de clientes activos...");
signal(14, (__sighandler_t)matar_cliente_inactivo);
while ( 1 )
{
while ( num_clientes <= 0 )
;
v0 = 0LL;
do
{
v1 = *(_DWORD *)(vector_clientes + 4 * v0);
if ( v1 )
{
matar_pid = *(_DWORD *)(vector_clientes + 4 * v0);
kill(v1, 10);
alarm(5u);
printf("Comprobando actividad del cliente %d\n", (unsigned int)matar_pid);
msgrcv(Q_clientes_activos, &cliente_activo, 4uLL, *(int *)(vector_clientes + 4 * v0), 0);
alarm(0);
sleep(0x14u);
}
++v0;
}
while ( num_clientes > (int)v0 );
}
}

original_code:
void *control_clientes(void *parametro)
{
    int i;
    printf("Iniciando el control de clientes activos...\n");
    signal (14,matar_cliente_inactivo);
    while(1)
    {
        for(i=0; i<num_clientes; i++)
        {
            if(vector_clientes[i]!=0)
            {
                matar_pid = vector_clientes[i];
                kill(vector_clientes[i],10);
                alarm(5);
                printf("Comprobando actividad del cliente %d\n",matar_pid);
                msgrcv(Q_clientes_activos,&cliente_activo,sizeof(int),vector_clientes[i],0);
                alarm(0);
                sleep(20);
            }
        }
    }
}

variable_types:
parametro
void *

variable_types: i int

return_type: void *


baja

decompiled_code:
__int64 __fastcall baja(__pid_t pid)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 i; // rax

sem_wait(sclientes);
if ( max_clientes <= 0 )
{
LABEL_5:
sem_post(sclientes);
result = 0LL;
}
else
{
v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( *(_DWORD *)(vector_clientes + 4 * v1) == pid )
break;
if ( ++v1 == max_clientes )
goto LABEL_5;
}
for ( i = 4LL * (int)v1 + 4; max_clientes - 1 > v2; i += 4LL )
{
*(_DWORD *)(vector_clientes + i - 4) = *(_DWORD *)(vector_clientes + i);
++v2;
}
sem_post(sclientes);
kill(pid, 2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__pid_t pid)
{
__int64 v1; // rax
int v2; // edx
__int64 result; // rax
__int64 i; // rax

sem_wait(sclientes);
if ( max_clientes <= 0 )
{
LABEL_5:
sem_post(sclientes);
result = 0LL;
}
else
{
v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( *(_DWORD *)(vector_clientes + 4 * v1) == pid )
break;
if ( ++v1 == max_clientes )
goto LABEL_5;
}
for ( i = 4LL * (int)v1 + 4; max_clientes - 1 > v2; i += 4LL )
{
*(_DWORD *)(vector_clientes + i - 4) = *(_DWORD *)(vector_clientes + i);
++v2;
}
sem_post(sclientes);
kill(pid, 2);
result = 1LL;
}
return result;
}

original_code:
int baja(int pid)
{
    int i,encontrado=0;
    sem_wait(sclientes);
    for(i=0; i<max_clientes; i++)
    {
        if(vector_clientes[i]==pid)
        {
            encontrado=1;
            break;
        }
    }
    if(encontrado!=1)
    {
        sem_post(sclientes);
        return 0;
    }
    for(i=i; i<max_clientes-1; i++)
    {
        vector_clientes[i]=vector_clientes[i+1];
    }
    sem_post(sclientes);
    kill(pid,2);
    return 1;
}

canonical_original_code:
int baja(int pid)
{
    int i; int encontrado = 0;
    sem_wait(sclientes);
    for(i=0; i<max_clientes; i++)
    {
        if(vector_clientes[i]==pid)
        {
            encontrado=1;
            break;
        }
    }
    if(encontrado!=1)
    {
        sem_post(sclientes);
        return 0;
    }
    for(i=i; i<max_clientes-1; i++)
    {
        vector_clientes[i]=vector_clientes[i+1];
    }
    sem_post(sclientes);
    kill(pid,2);
    return 1;
}

variable_types: pid int

variable_types: encontrado int


reader

decompiled_code:
void __fastcall reader(unsigned int a1)
{
unsigned int v1; // ebx

while ( !stop )
{
ta_sem_wait();
ta_lock();
v1 = readerloc;
readerloc = (readerloc + 1) % datalen;
ta_unlock();
ta_sem_signal();
fprintf(_bss_start, "reader %d read location %d\n", a1, v1);
if ( (random() & 1) == 0 )
ta_yield();
}
}

canonical_decompiled_code:
void __fastcall func8(unsigned int a1)
{
unsigned int v1; // ebx

while ( !stop )
{
ta_sem_wait();
ta_lock();
v1 = readerloc;
readerloc = (readerloc + 1) % datalen;
ta_unlock();
ta_sem_signal();
fprintf(_bss_start, "reader %d read location %d\n", a1, v1);
if ( (random() & 1) == 0 )
ta_yield();
}
}

original_code:
void reader(void *arg)
{
    int tid = (int)arg;
    int val = 0;
    while (!stop)
    {
        ta_sem_wait(&readersem);
        ta_lock(&rmutex);
        int loc = readerloc;
        readerloc = (readerloc+1) % datalen;
        ta_unlock(&rmutex);
        val = data[loc];
        ta_sem_signal(&writersem);
        fprintf(stderr, "reader %d read location %d\n", tid, loc);
        if (random() % 2 == 0)
            ta_yield();
    }
}

variable_types:
arg
void *

variable_types: tid int

variable_types: val int

variable_types: loc int


writer

decompiled_code:
void __fastcall writer(unsigned int a1)
{
int v1; // ebx
int v2; // ebp
int v3; // er12
int v4; // ecx

v1 = stop;
if ( !stop )
{
v2 = 1000000;
do
{
ta_sem_wait();
ta_lock();
v3 = v1;
v1 = (v1 + 1) % datalen;
ta_unlock();
v4 = v2++;
*((_DWORD *)data + v3) = v4;
ta_sem_signal();
fprintf(_bss_start, "writer %d wrote location %d\n", a1, (unsigned int)v3);
if ( (random() & 1) == 0 )
ta_yield();
}
while ( !stop );
}
}

canonical_decompiled_code:
void __fastcall func9(unsigned int a1)
{
int v1; // ebx
int v2; // ebp
int v3; // er12
int v4; // ecx

v1 = stop;
if ( !stop )
{
v2 = 1000000;
do
{
ta_sem_wait();
ta_lock();
v3 = v1;
v1 = (v1 + 1) % datalen;
ta_unlock();
v4 = v2++;
*((_DWORD *)data + v3) = v4;
ta_sem_signal();
fprintf(_bss_start, "writer %d wrote location %d\n", a1, (unsigned int)v3);
if ( (random() & 1) == 0 )
ta_yield();
}
while ( !stop );
}
}

original_code:
void writer(void *arg)
{
    int tid = (int)arg;
    int val = 1000000;
    int writerloc = 0;
    while (!stop)
    {
        ta_sem_wait(&writersem);
        ta_lock(&wmutex);
        int loc = writerloc;
        writerloc = (writerloc+1) % datalen;
        ta_unlock(&wmutex);
        data[loc] = val++;
        ta_sem_signal(&readersem);
        fprintf(stderr, "writer %d wrote location %d\n", tid, loc);
        if (random() % 2 == 0)
            ta_yield();
    }
}

variable_types: writerloc int


killerthr

decompiled_code:
time_t killerthr()
{
time_t v0; // rbx
time_t result; // rax

v0 = time(0LL) + 3;
do
{
ta_yield();
result = time(0LL);
}
while ( v0 > result );
stop = 1;
return result;
}

canonical_decompiled_code:
time_t func7()
{
time_t v0; // rbx
time_t result; // rax

v0 = time(0LL) + 3;
do
{
ta_yield();
result = time(0LL);
}
while ( v0 > result );
stop = 1;
return result;
}

original_code:
void killerthr(void *arg)
{
    time_t now = time(((void *)0));
    time_t finish = now + 3;
    while (now < finish)
    {
        ta_yield();
        now = time(((void *)0));
    }
    stop = 1;
}

canonical_original_code:
void killerthr(void *arg)
{
    long now = time(((void *)0));
    long finish = now + 3;
    while (now < finish)
    {
        ta_yield();
        now = time(((void *)0));
    }
    stop = 1;
}

variable_types: now long

variable_types: finish long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // rax
__int64 i; // rbx

v3 = time(0LL);
srandom(v3);
ta_libinit();
v4 = malloc(0x190uLL);
data = v4;
if ( !v4 )
__assert_fail("data", "test07.c", 0x57u, "main");
memset(v4, 0, 0x190uLL);
datalen = 100;
ta_sem_init();
ta_sem_init();
ta_lock_init();
ta_lock_init();
ta_create();
for ( i = 0LL; i != 5; ++i )
{
ta_create();
ta_create();
}
if ( (unsigned int)ta_waitall() )
__assert_fail("rv == 0", "test07.c", 0x69u, "main");
ta_sem_destroy();
ta_sem_destroy();
ta_lock_destroy();
ta_lock_destroy();
free(data);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    srandom(time(((void *)0)));
    ta_libinit();
    int i = 0;
    int nrw = 5;
    data = (int *)malloc(sizeof(int) * 100);
    ((void) sizeof ((data) ? 1 : 0), __extension__ ({ if (data) ; else __assert_fail ("data", "test07.c", 87, __extension__ __PRETTY_FUNCTION__); }));
    memset(data, 0, sizeof(int)*100);
    datalen = 100;
    ta_sem_init(&readersem, 0);
    ta_sem_init(&writersem, 100);
    ta_lock_init(&rmutex);
    ta_lock_init(&wmutex);
    ta_create(killerthr, (void *)i);
    for (i = 0; i < nrw; i++)
    {
        ta_create(reader, (void *)i);
        ta_create(writer, (void *)i);
    }
    int rv = ta_waitall();
    ((void) sizeof ((rv == 0) ? 1 : 0), __extension__ ({ if (rv == 0) ; else __assert_fail ("rv == 0", "test07.c", 105, __extension__ __PRETTY_FUNCTION__); }));
    ta_sem_destroy(&readersem);
    ta_sem_destroy(&writersem);
    ta_lock_destroy(&rmutex);
    ta_lock_destroy(&wmutex);
    free(data);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: nrw int

variable_types: rv int


decompiled_code:
_QWORD *create_queue()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

canonical_decompiled_code:
_QWORD *func30()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
return result;
}

original_code:
queue* create_queue(){
    queue* q = (queue*)malloc(sizeof(queue));
    q->head = ((void *)0);
    q->tail = ((void *)0);
    q->length = 0;
    return q;
}

canonical_original_code:
struct queue *create_queue(){
    struct queue *q = (queue*)malloc(sizeof(queue));
    q->head = ((void *)0);
    q->tail = ((void *)0);
    q->length = 0;
    return q;
}

variable_types: struct queue { struct queue_node { struct control_block { struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long __gregs[23]; struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int __element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *__fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *thread; struct queue_node *next; struct queue_node *prev; } *head; struct queue_node *tail; int length; } *

user_defined_types: struct queue { struct queue_node *head; struct queue_node *tail; int length; }

user_defined_types: struct queue_node { struct control_block *thread; struct queue_node *next; struct queue_node *prev; }

user_defined_types: struct control_block { struct ucontext_t *ctx; int status; }

user_defined_types: struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long __gregs[23]; struct _libc_fpstate *__fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


len

decompiled_code:
__int64 __fastcall len(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func31(__int64 a1)
{
return *(unsigned int *)(a1 + 16);
}

original_code:
int len(queue* q){
    return q->length;
}

canonical_original_code:
int len(struct queue *q){
    return q->length;
}

user_defined_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

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

user_defined_types: struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; }

user_defined_types: struct _libc_xmmreg { unsigned int __element[4]; }


push

original_code:
void push(queue* q, tcb* thread){
    queue_node* n = create_queue_node(thread);
    if (len(q) == 0){
 q->head = n;
 q->tail = n;
 n->next = ((void *)0);
 n->prev = ((void *)0);
 q->length++;
    }
    else{
 q->tail->prev = n;
 n->next = q->tail;
 q->tail = n;
 q->tail->prev = ((void *)0);
 q->length++;
    }
}

canonical_original_code:
void push(struct queue *q, struct control_block *thread){
    struct queue_node *n = create_queue_node(thread);
    if (len(q) == 0){
 q->head = n;
 q->tail = n;
 n->next = ((void *)0);
 n->prev = ((void *)0);
 q->length++;
    }
    else{
 q->tail->prev = n;
 n->next = q->tail;
 q->tail = n;
 q->tail->prev = ((void *)0);
 q->length++;
    }
}

variable_types:
thread
struct control_block *

variable_types: struct queue_node { struct control_block { struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long __gregs[23]; struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int __element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *__fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *thread; struct queue_node *next; struct queue_node *prev; } *


pop

original_code:
tcb* pop(queue* q) {
    if (q->length > 1){
        tcb* thread = q->head->thread;
 queue_node* head = q->head;
        q->head = q->head->prev;
 free(head);
 q->head->next = ((void *)0);
 q->length--;
 return thread;
    }
    else if (q->length == 1){
 tcb* thread = q->head->thread;
 q->head = ((void *)0);
 q->tail = ((void *)0);
 free(q->head);
 q->length--;
 return thread;
    }
    else {
 printf("Error: Queue length 0\n");
 exit(1);
    }
}

canonical_original_code:
struct control_block *pop(struct queue *q) {
    if (q->length > 1){
        struct control_block *thread = q->head->thread;
 struct queue_node *head = q->head;
        q->head = q->head->prev;
 free(head);
 q->head->next = ((void *)0);
 q->length--;
 return thread;
    }
    else if (q->length == 1){
 struct control_block *thread = q->head->thread;
 q->head = ((void *)0);
 q->tail = ((void *)0);
 free(q->head);
 q->length--;
 return thread;
    }
    else {
 printf("Error: Queue length 0\n");
 exit(1);
    }
}

variable_types: struct queue { struct queue_node { struct control_block *thread; struct queue_node *next; struct queue_node *prev; } *head; struct queue_node *tail; int length; } *

variable_types: struct control_block { struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long __gregs[23]; struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int __element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *__fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *


decompiled_code:
__int64 __fastcall get_head(__int64 a1)
{
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func34(__int64 a1)
{
return **(_QWORD **)a1;
}

original_code:
tcb* get_head(queue* q){
    return q->head->thread;
}

canonical_original_code:
struct control_block *get_head(struct queue *q){
    return q->head->thread;
}

return_type: struct control_block { struct ucontext_t { unsigned long __uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long __gregs[23]; struct _libc_fpstate { unsigned short __cwd; unsigned short __swd; unsigned short __ftw; unsigned short __fop; unsigned long __rip; unsigned long __rdp; unsigned int __mxcsr; unsigned int __mxcr_mask; struct _libc_fpxreg { unsigned short __significand[4]; unsigned short __exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int __element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *__fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *


decompiled_code:
void __fastcall destroy_queue(void *ptr)
{
__int64 v1; // rbx
int i; // ebp
__int64 v3; // r12

v1 = *(_QWORD *)ptr;
for ( i = 0; (int)len(ptr) > i; ++i )
{
v3 = *(_QWORD *)(v1 + 16);
free(**(void ***)v1);
free(*(void **)v1);
free((void *)v1);
v1 = v3;
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func35(void *ptr)
{
__int64 v1; // rbx
int i; // ebp
__int64 v3; // r12

v1 = *(_QWORD *)ptr;
for ( i = 0; (int)func31(ptr) > i; ++i )
{
v3 = *(_QWORD *)(v1 + 16);
free(**(void ***)v1);
free(*(void **)v1);
free((void *)v1);
v1 = v3;
}
free(ptr);
}

original_code:
void destroy_queue(queue* q){
    queue_node* cur = q->head;
    int i = 0;
    for (;i<len(q);i++){
 queue_node* prev = cur->prev;
 free(cur->thread->ctx);
 free(cur->thread);
 free(cur);
 cur = prev;
    }
    free(q);
}

canonical_original_code:
void destroy_queue(struct queue *q){
    struct queue_node *cur = q->head;
    int i = 0;
    for (;i<len(q);i++){
 struct queue_node *prev = cur->prev;
 free(cur->thread->ctx);
 free(cur->thread);
 free(cur);
 cur = prev;
    }
    free(q);
}

variable_types: i int


think

decompiled_code:
__int64 __fastcall think(unsigned int a1)
{
fprintf(_bss_start, "Philosopher %d is thinking\n", a1);
return ta_yield();
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
fprintf(_bss_start, "Philosopher %d is thinking\n", a1);
return ta_yield();
}

original_code:
void think(int i)
{
    fprintf(stderr, "Philosopher %d is thinking\n", i);
    ta_yield();
}


eat

decompiled_code:
__int64 __fastcall eat(unsigned int a1)
{
fprintf(_bss_start, "Philosopher %d is eating\n", a1);
return ta_yield();
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
fprintf(_bss_start, "Philosopher %d is eating\n", a1);
return ta_yield();
}

original_code:
void eat(int i)
{
    fprintf(stderr, "Philosopher %d is eating\n", i);
    ta_yield();
}


testSafetyAndLiveness

original_code:
void testSafetyAndLiveness(int i, shared_data_t *data)
{
    if (data->state[i] == 1 &&
 (data->state[(i+1)%5] != 2 &&
  data->state[(i-1)%5] != 2))
    {
 data->state[i] = 2;
 ta_sem_signal(&data->mayEat[i]);
    }
}

canonical_original_code:
void testSafetyAndLiveness(int i, struct shared_data_t *data)
{
    if (data->state[i] == 1 &&
 (data->state[(i+1)%5] != 2 &&
  data->state[(i-1)%5] != 2))
    {
 data->state[i] = 2;
 ta_sem_signal(&data->mayEat[i]);
    }
}

variable_types: struct shared_data_t { int stop; int atTable; struct tasem_t { int value; struct queue { struct queue_node { struct control_block { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *thread; struct queue_node *next; struct queue_node *prev; } *head; struct queue_node *tail; int length; } *w_queue; } atTableSem; struct tasem_t mutex; int state[5]; struct tasem_t mayEat[5]; } *

user_defined_types: struct shared_data_t { int stop; int atTable; struct tasem_t atTableSem; struct tasem_t mutex; int state[5]; struct tasem_t mayEat[5]; }

user_defined_types: struct tasem_t { int value; struct queue *w_queue; }

user_defined_types: struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t uc_stack; struct mcontext_t uc_mcontext; struct __sigset_t uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; }

user_defined_types: struct mcontext_t { long long gregs[23]; struct _libc_fpstate *fpregs; unsigned long long __reserved1[8]; }

user_defined_types: struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg _st[8]; struct _libc_xmmreg _xmm[16]; unsigned int __glibc_reserved1[24]; }


philosophize

decompiled_code:
int __fastcall philosophize(_DWORD *a1)
{
unsigned int v1; // ebx
int result; // eax

ta_sem_wait();
v1 = a1[1];
a1[1] = v1 + 1;
ta_sem_signal();
for ( result = fprintf(_bss_start, "Philosopher %d has been seated\n", v1);
!*a1;
result = release_chopsticks(v1, (__int64)a1) )
{
think(v1);
take_chopsticks(v1, (__int64)a1);
eat(v1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(_DWORD *a1)
{
unsigned int v1; // ebx
int result; // eax

ta_sem_wait();
v1 = a1[1];
a1[1] = v1 + 1;
ta_sem_signal();
for ( result = fprintf(_bss_start, "Philosopher %d has been seated\n", v1);
!*a1;
result = func12(v1, (__int64)a1) )
{
func8(v1);
func11(v1, (__int64)a1);
func9(v1);
}
return result;
}

original_code:
void philosophize(void *vptr)
{
    shared_data_t *data = (shared_data_t*)vptr;
    int philosopher_index = 0;
    ta_sem_wait(&data->atTableSem);
    philosopher_index = data->atTable++;
    ta_sem_signal(&data->atTableSem);
    fprintf(stderr, "Philosopher %d has been seated\n", philosopher_index);
    while (!data->stop)
    {
        think(philosopher_index);
        take_chopsticks(philosopher_index, data);
        eat(philosopher_index);
        release_chopsticks(philosopher_index, data);
    }
}

canonical_original_code:
void philosophize(void *vptr)
{
    struct shared_data_t *data = (shared_data_t*)vptr;
    int philosopher_index = 0;
    ta_sem_wait(&data->atTableSem);
    philosopher_index = data->atTable++;
    ta_sem_signal(&data->atTableSem);
    fprintf(stderr, "Philosopher %d has been seated\n", philosopher_index);
    while (!data->stop)
    {
        think(philosopher_index);
        take_chopsticks(philosopher_index, data);
        eat(philosopher_index);
        release_chopsticks(philosopher_index, data);
    }
}

variable_types:
vptr
void *

variable_types: struct shared_data_t { int stop; int atTable; struct tasem_t { int value; struct queue { struct queue_node { struct control_block { struct ucontext_t { unsigned long uc_flags; struct ucontext_t *uc_link; struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; } uc_stack; struct mcontext_t { long long gregs[23]; struct _libc_fpstate { unsigned short cwd; unsigned short swd; unsigned short ftw; unsigned short fop; unsigned long rip; unsigned long rdp; unsigned int mxcsr; unsigned int mxcr_mask; struct _libc_fpxreg { unsigned short significand[4]; unsigned short exponent; unsigned short __glibc_reserved1[3]; } _st[8]; struct _libc_xmmreg { unsigned int element[4]; } _xmm[16]; unsigned int __glibc_reserved1[24]; } *fpregs; unsigned long long __reserved1[8]; } uc_mcontext; struct __sigset_t { unsigned long __val[-1]; } uc_sigmask; struct _libc_fpstate __fpregs_mem; unsigned long long __ssp[4]; } *ctx; int status; } *thread; struct queue_node *next; struct queue_node *prev; } *head; struct queue_node *tail; int length; } *w_queue; } atTableSem; struct tasem_t chopstickSem[5]; } *

user_defined_types: struct shared_data_t { int stop; int atTable; struct tasem_t atTableSem; struct tasem_t chopstickSem[5]; }


SuperFastHash

original_code:
uint32_t SuperFastHash (const char *data, int len) {
 uint32_t hash = 0, tmp;
 int rem;
 if (len <= 0 || data == ((void *)0)) return 0;
 rem = len & 3;
 len >>= 2;
 for (;len > 0; len--) {
  hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
  tmp = (((((uint32_t)(((const uint8_t *)(data+2))[1])) << 8) +(uint32_t)(((const uint8_t *)(data+2))[0]) ) << 11) ^ hash;
  hash = (hash << 16) ^ tmp;
  data += 2*sizeof (uint16_t);
  hash += hash >> 11;
 }
 switch (rem) {
  case 3: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
    hash ^= hash << 16;
    hash ^= data[sizeof (uint16_t)] << 18;
    hash += hash >> 11;
    break;
  case 2: hash += ((((uint32_t)(((const uint8_t *)(data))[1])) << 8) +(uint32_t)(((const uint8_t *)(data))[0]) );
    hash ^= hash << 11;
    hash += hash >> 17;
    break;
  case 1: hash += *data;
    hash ^= hash << 10;
    hash += hash >> 1;
 }
 hash ^= hash << 3;
 hash += hash >> 5;
 hash ^= hash << 4;
 hash += hash >> 17;
 hash ^= hash << 25;
 hash += hash >> 6;
 return hash;
}

canonical_original_code:
unsigned int SuperFastHash(char *data, int len) {
 unsigned int hash = 0; unsigned int tmp;
 int rem;
 if (len <= 0 || data == ((void *)0)) return 0;
 rem = len & 3;
 len >>= 2;
 for (;len > 0; len--) {
  hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
  tmp = (((((unsigned int)(((unsigned char *)(data+2))[1])) << 8) +(unsigned int)(((unsigned char *)(data+2))[0]) ) << 11) ^ hash;
  hash = (hash << 16) ^ tmp;
  data += 2*sizeof (unsigned short);
  hash += hash >> 11;
 }
 switch (rem) {
  case 3: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
    hash ^= hash << 16;
    hash ^= data[sizeof (unsigned short)] << 18;
    hash += hash >> 11;
    break;
  case 2: hash += ((((unsigned int)(((unsigned char *)(data))[1])) << 8) +(unsigned int)(((unsigned char *)(data))[0]) );
    hash ^= hash << 11;
    hash += hash >> 17;
    break;
  case 1: hash += *data;
    hash ^= hash << 10;
    hash += hash >> 1;
 }
 hash ^= hash << 3;
 hash += hash >> 5;
 hash ^= hash << 4;
 hash += hash >> 17;
 hash ^= hash << 25;
 hash += hash >> 6;
 return hash;
}

variable_types:
data
char *

variable_types: len int

variable_types:
hash
unsigned int

variable_types:
tmp
unsigned int

variable_types: rem int

return_type: unsigned int


copy

decompiled_code:
__int64 __fastcall copy(const char *a1, const char *a2)
{
int v2; // ebp
__int64 result; // rax
int v4; // er12
int v5; // eax
_BYTE v6[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = open(a1, 0);
result = 1LL;
if ( v2 != -1 )
{
v4 = open(a2, 2113);
result = 1LL;
if ( v4 != -1 )
{
while ( 1 )
{
v5 = read(v2, v6, 0x200uLL);
if ( v5 <= 0 )
break;
write(v4, v6, v5);
}
close(v2);
close(v4);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, const char *a2)
{
int v2; // ebp
__int64 result; // rax
int v4; // er12
int v5; // eax
_BYTE v6[536]; // [rsp+0h] [rbp-218h] BYREF

v2 = open(a1, 0);
result = 1LL;
if ( v2 != -1 )
{
v4 = open(a2, 2113);
result = 1LL;
if ( v4 != -1 )
{
while ( 1 )
{
v5 = read(v2, v6, 0x200uLL);
if ( v5 <= 0 )
break;
write(v4, v6, v5);
}
close(v2);
close(v4);
result = 0LL;
}
}
return result;
}

original_code:
int copy(char *src, char *dest) {
 int inF, ouF;
   char line[512];
   int bytes;
   if ( (inF = open(src, 00)) == -1 ) {
    return 1;
   }
   if ( (ouF = open(dest, 01 | 0100 | 04000)) == -1 ) {
      return 1;
   }
 while ( (bytes = read(inF, line, sizeof(line))) > 0 )
      write(ouF, line, bytes);
   close(inF);
   close(ouF);
   return 0;
}

canonical_original_code:
int copy(char *src, char *dest) {
 int inF; int ouF;
   char line[512];
   int bytes;
   if ( (inF = open(src, 00)) == -1 ) {
    return 1;
   }
   if ( (ouF = open(dest, 01 | 0100 | 04000)) == -1 ) {
      return 1;
   }
 while ( (bytes = read(inF, line, sizeof(line))) > 0 )
      write(ouF, line, bytes);
   close(inF);
   close(ouF);
   return 0;
}

variable_types:
src
char *

variable_types:
dest
char *

variable_types: inF int

variable_types: ouF int

variable_types:
line
char [512]

variable_types: bytes int


original_code:
int create_line(line* line_obj)
{
 line_obj->ne=0;
 line_obj->alloted=0;
}

canonical_original_code:
int create_line(struct line_t *line_obj)
{
 line_obj->ne=0;
 line_obj->alloted=0;
}

variable_types: struct line_t { struct coords_t { int x1; int y1; int z1; int x2; int y2; int z2; } *coords_obj; int ne; int alloted; } *

user_defined_types: struct line_t { struct coords_t *coords_obj; int ne; int alloted; }


decompiled_code:
int __fastcall line_add_implemented(__int64 a1, unsigned int a2, unsigned int a3, int a4, unsigned int a5, unsigned int a6, int a7)
{
int result; // eax

printf("ALLOTED %d\n", *(unsigned int *)(a1 + 12));
if ( !*(_DWORD *)(a1 + 12) )
{
*(_QWORD *)a1 = malloc(0x60uLL);
*(_DWORD *)(a1 + 12) = 4;
puts("Empty line");
}
if ( *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 12) )
line_reallot(a1);
*(_DWORD *)(*(_QWORD *)a1 + 24LL * *(int *)(a1 + 8)) = a2;
*(_DWORD *)(*(_QWORD *)a1 + 24LL * *(int *)(a1 + 8) + 4) = a3;
*(_DWORD *)(*(_QWORD *)a1 + 24LL * *(int *)(a1 + 8) + 8) = a4;
*(_DWORD *)(*(_QWORD *)a1 + 24LL * *(int *)(a1 + 8) + 12) = a5;
*(_DWORD *)(*(_QWORD *)a1 + 24LL * *(int *)(a1 + 8) + 16) = a6;
*(_DWORD *)(*(_QWORD *)a1 + 24LL * *(int *)(a1 + 8) + 20) = a7;
result = printf("%d%d%d%d\n", a2, a5, a3, a6);
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
int line_add_implemented(line* line_obj, int x1, int y1, int z1, int x2, int y2, int z2)
{
 printf("ALLOTED %d\n",line_obj->alloted);
 if ( line_obj->alloted == 0 )
 {
  line_obj->coords_obj=(coords*)malloc(sizeof(coords)*4);
  line_obj->alloted=4;
  printf("Empty line\n");
 }
 if ( line_obj->ne == line_obj->alloted )
  line_reallot(line_obj);
 line_obj->coords_obj[line_obj->ne].x1=x1;
 line_obj->coords_obj[line_obj->ne].y1=y1;
 line_obj->coords_obj[line_obj->ne].z1=z1;
 line_obj->coords_obj[line_obj->ne].x2=x2;
 line_obj->coords_obj[line_obj->ne].y2=y2;
 line_obj->coords_obj[line_obj->ne].z2=z2;
 printf("%d%d%d%d\n",x1,x2,y1,y2);
 line_obj->ne++;
}

canonical_original_code:
int line_add_implemented(struct line_t *line_obj, int x1, int y1, int z1, int x2, int y2, int z2)
{
 printf("ALLOTED %d\n",line_obj->alloted);
 if ( line_obj->alloted == 0 )
 {
  line_obj->coords_obj=(struct coords_t *)malloc(sizeof(coords)*4);
  line_obj->alloted=4;
  printf("Empty line\n");
 }
 if ( line_obj->ne == line_obj->alloted )
  line_reallot(line_obj);
 line_obj->coords_obj[line_obj->ne].x1=x1;
 line_obj->coords_obj[line_obj->ne].y1=y1;
 line_obj->coords_obj[line_obj->ne].z1=z1;
 line_obj->coords_obj[line_obj->ne].x2=x2;
 line_obj->coords_obj[line_obj->ne].y2=y2;
 line_obj->coords_obj[line_obj->ne].z2=z2;
 printf("%d%d%d%d\n",x1,x2,y1,y2);
 line_obj->ne++;
}

user_defined_types: struct coords_t { int x1; int y1; int z1; int x2; int y2; int z2; }


original_code:
int line_reallot(line* line_obj)
{
 int i;
 printf("New Reallot %d\n",line_obj->alloted*2);
 line line_tmp;
 line_tmp.ne=0;
 line_tmp.coords_obj=(coords*)malloc(sizeof(coords)*line_obj->alloted*2);
 line_tmp.alloted=line_obj->alloted*2;
 for(i=0; i < line_obj->ne; i++)
 {
  line_ops.line_add(&line_tmp, line_obj->coords_obj[i].x1, line_obj->coords_obj[i].y1, line_obj->coords_obj[i].z1, line_obj->coords_obj[i].x2, line_obj->coords_obj[i].y2, line_obj->coords_obj[i].z2);
 }
 free(line_obj->coords_obj);
 line_obj->coords_obj=line_tmp.coords_obj;
 line_obj->alloted*=2;
}

canonical_original_code:
int line_reallot(struct line_t *line_obj)
{
 int i;
 printf("New Reallot %d\n",line_obj->alloted*2);
 struct line_t line_tmp;
 line_tmp.ne=0;
 line_tmp.coords_obj=(struct coords_t *)malloc(sizeof(coords)*line_obj->alloted*2);
 line_tmp.alloted=line_obj->alloted*2;
 for(i=0; i < line_obj->ne; i++)
 {
  line_ops.line_add(&line_tmp, line_obj->coords_obj[i].x1, line_obj->coords_obj[i].y1, line_obj->coords_obj[i].z1, line_obj->coords_obj[i].x2, line_obj->coords_obj[i].y2, line_obj->coords_obj[i].z2);
 }
 free(line_obj->coords_obj);
 line_obj->coords_obj=line_tmp.coords_obj;
 line_obj->alloted*=2;
}

variable_types: struct line_t { struct coords_t { int x1; int y1; int z1; int x2; int y2; int z2; } *coords_obj; int ne; int alloted; }


decompiled_code:
int __fastcall line_display_implemented(__int64 a1)
{
__int64 v1; // rbp
int result; // eax

if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
puts("COORDS");
printf(
"\t%d %d %d\n",
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1),
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 4),
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 8));
result = printf(
"\t%d %d %d\n",
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 12),
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 16),
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 20));
++v1;
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbp
int result; // eax

if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
puts("COORDS");
printf(
"\t%d %d %d\n",
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1),
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 4),
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 8));
result = printf(
"\t%d %d %d\n",
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 12),
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 16),
*(unsigned int *)(*(_QWORD *)a1 + 24 * v1 + 20));
++v1;
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
return result;
}

original_code:
int line_display_implemented(line* line_obj)
{
 int i;
 for(i=0; i < line_obj->ne; i++)
 {
  printf("COORDS\n");
  printf("\t%d %d %d\n",line_obj->coords_obj[i].x1,line_obj->coords_obj[i].y1,line_obj->coords_obj[i].z1);
  printf("\t%d %d %d\n",line_obj->coords_obj[i].x2,line_obj->coords_obj[i].y2,line_obj->coords_obj[i].z2);
 }
}

canonical_original_code:
int line_display_implemented(struct line_t *line_obj)
{
 int i;
 for(i=0; i < line_obj->ne; i++)
 {
  printf("COORDS\n");
  printf("\t%d %d %d\n",line_obj->coords_obj[i].x1,line_obj->coords_obj[i].y1,line_obj->coords_obj[i].z1);
  printf("\t%d %d %d\n",line_obj->coords_obj[i].x2,line_obj->coords_obj[i].y2,line_obj->coords_obj[i].z2);
 }
}

variable_types: i int


original_code:
int hashlist_add_implemented2(hashlist2* list1,char* key_name,char* extra,int x,int y,int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == ((void *)0) )
        {
                 list1->Hash = (hash2*)malloc(sizeof(hash2) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }
        float alloted_percent = ((float)list1->alloted/list1->size)*100 ;
        if ( alloted_percent >= 80 )
                hashlist_reallot2(list1);
        hash_value = hashalgo(key_name,list1->size);
        while (list1->Hash[hash_value].valid == 1)
        {
                if (!strcmp(list1->Hash[hash_value].key_name,key_name))
   return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        }
        list1->Hash[hash_value].key_name = (char*)malloc(sizeof(char)*strlen(key_name)+1);
        list1->Hash[hash_value].extra = (char*)malloc(sizeof(char)*strlen(extra)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);
        strcpy(list1->Hash[hash_value].extra,extra);
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
}

canonical_original_code:
int hashlist_add_implemented2(struct hashlist_t2 *list1, char *key_name, char *extra, int x, int y, int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == ((void *)0) )
        {
                 list1->Hash = (struct hash_t2 *)malloc(sizeof(hash2) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }
        float alloted_percent = ((float)list1->alloted/list1->size)*100;
        if ( alloted_percent >= 80 )
                hashlist_reallot2(list1);
        hash_value = hashalgo(key_name,list1->size);
        while (list1->Hash[hash_value].valid == 1)
        {
                if (!strcmp(list1->Hash[hash_value].key_name,key_name))
   return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        }
        list1->Hash[hash_value].key_name = (char *)malloc(sizeof(char)*strlen(key_name)+1);
        list1->Hash[hash_value].extra = (char *)malloc(sizeof(char)*strlen(extra)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);
        strcpy(list1->Hash[hash_value].extra,extra);
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
}

variable_types: struct hashlist_t2 { int size; int alloted; struct hash_t2 { char *key_name; char *extra; int x; int y; int z; int valid; } *Hash; } *

variable_types:
extra
char *

variable_types: x int

variable_types: y int

variable_types: z int

user_defined_types: struct hashlist_t2 { int size; int alloted; struct hash_t2 *Hash; }


original_code:
void hashlist_reallot2(hashlist2* list1)
{
        int i;
        float alloted_percent = ((float)list1->alloted/list1->size)*100 ;
        printf("Realloting Hashlist with allocation %f  New Size %d\n",alloted_percent,list1->size*2);
        hashlist2 list2;
        list2.Hash=(hash2*)malloc(sizeof(hash2)*list1->size*2);
        list2.size=list1->size*2;
        for( i=0; i < list2.size-1; i++)
                list2.Hash[i].valid=0;
        list2.alloted=0;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        hashlist_ops2.hashlist_add2(&list2,list1->Hash[i].key_name,list1->Hash[i].extra,list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
        hash2* hash_tmp = list1->Hash;
        list1->Hash=list2.Hash;
        list1->size=list2.size;
        list1->alloted=list2.alloted;
        free(hash_tmp);
}

canonical_original_code:
void hashlist_reallot2(struct hashlist_t2 *list1)
{
        int i;
        float alloted_percent = ((float)list1->alloted/list1->size)*100;
        printf("Realloting Hashlist with allocation %f  New Size %d\n",alloted_percent,list1->size*2);
        struct hashlist_t2 list2;
        list2.Hash=(struct hash_t2 *)malloc(sizeof(hash2)*list1->size*2);
        list2.size=list1->size*2;
        for( i=0; i < list2.size-1; i++)
                list2.Hash[i].valid=0;
        list2.alloted=0;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        hashlist_ops2.hashlist_add2(&list2,list1->Hash[i].key_name,list1->Hash[i].extra,list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
        struct hash_t2 *hash_tmp = list1->Hash;
        list1->Hash=list2.Hash;
        list1->size=list2.size;
        list1->alloted=list2.alloted;
        free(hash_tmp);
}

variable_types: struct hashlist_t2 { int size; int alloted; struct hash_t2 { char *key_name; char *extra; int x; int y; int z; int valid; } *Hash; }


decompiled_code:
int __fastcall hashlist_display_implemented2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

LODWORD(v1) = puts("Displaying Hash list");
if ( *(_DWORD *)(a1 + 4) && *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v1 = *(_QWORD *)(a1 + 8) + 32 * v2;
if ( *(_DWORD *)(v1 + 28) == 1 )
{
printf("\tName :- %s\t\tExtra\t:- %s\n ", *(const char **)v1, *(const char **)(v1 + 8));
LODWORD(v1) = printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(*(_QWORD *)(a1 + 8) + 32 * v2 + 16),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + 32 * v2 + 20),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + 32 * v2 + 24));
}
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return v1;
}

original_code:
void hashlist_display_implemented2(hashlist2* list1)
{
        int i;
        printf("Displaying Hash list\n");
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        printf("\tName   :- %s\t\tExtra	:- %s\n ",list1->Hash[i].key_name, list1->Hash[i].extra);
                        printf("\tCoords :- %d %d %d\n",list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
}

canonical_original_code:
void hashlist_display_implemented2(struct hashlist_t2 *list1)
{
        int i;
        printf("Displaying Hash list\n");
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        printf("\tName   :- %s\t\tExtra	:- %s\n ",list1->Hash[i].key_name, list1->Hash[i].extra);
                        printf("\tCoords :- %d %d %d\n",list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
}

user_defined_types: struct hash_t2 { char *key_name; char *extra; int x; int y; int z; int valid; }


decompiled_code:
void __fastcall hashlist_initialize_implemented2(__int64 a1)
{
*(_DWORD *)a1 = 10;
*(_DWORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void hashlist_initialize_implemented2(hashlist2* list1)
{
        list1->size=10;
        list1->alloted=0;
        list1->Hash=((void *)0);
}

canonical_original_code:
void hashlist_initialize_implemented2(struct hashlist_t2 *list1)
{
        list1->size=10;
        list1->alloted=0;
        list1->Hash=((void *)0);
}


decompiled_code:
__int64 __fastcall hashlist_findhash_implemented2(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rbp

if ( !*(_DWORD *)(a1 + 4) )
return 0LL;
if ( *(int *)a1 <= 0 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = v2 + 32LL * (unsigned int)(*(_DWORD *)a1 - 1) + 32;
while ( 1 )
{
v4 = v2;
if ( *(_DWORD *)(v2 + 28) == 1 && !strcmp(*(const char **)v2, a2) )
break;
v2 += 32LL;
if ( v2 == v3 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rbp

if ( !*(_DWORD *)(a1 + 4) )
return 0LL;
if ( *(int *)a1 <= 0 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = v2 + 32LL * (unsigned int)(*(_DWORD *)a1 - 1) + 32;
while ( 1 )
{
v4 = v2;
if ( *(_DWORD *)(v2 + 28) == 1 && !strcmp(*(const char **)v2, a2) )
break;
v2 += 32LL;
if ( v2 == v3 )
return 0LL;
}
return v4;
}

original_code:
hash2* hashlist_findhash_implemented2(hashlist2* list1, char* key_name)
{
        int i;
        if (list1->alloted == 0) return ((void *)0);
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1 && !strcmp(list1->Hash[i].key_name,key_name))
                        return &list1->Hash[i];
        }
        return ((void *)0);
}

canonical_original_code:
struct hash_t2 *hashlist_findhash_implemented2(struct hashlist_t2 *list1, char *key_name)
{
        int i;
        if (list1->alloted == 0) return ((void *)0);
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1 && !strcmp(list1->Hash[i].key_name,key_name))
                        return &list1->Hash[i];
        }
        return ((void *)0);
}

variable_types: struct hashlist_t2 { int size; int alloted; struct hash_t2 *Hash; } *

return_type: struct hash_t2 { char *key_name; char *extra; int x; int y; int z; int valid; } *


original_code:
void hashlist_destroy_implemented2(hashlist2* list1)
{
        int i;
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
   free(list1->Hash[i].key_name);
        }
 free(list1->Hash);
}

canonical_original_code:
void hashlist_destroy_implemented2(struct hashlist_t2 *list1)
{
        int i;
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
   free(list1->Hash[i].key_name);
        }
 free(list1->Hash);
}


original_code:
int hashlist_add_implemented(hashlist* list1,char* key_name,int x,int y,int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == ((void *)0) )
        {
                 list1->Hash = (hash*)malloc(sizeof(hash) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }
        float alloted_percent = ((float)list1->alloted/list1->size)*100 ;
        if ( alloted_percent >= 80 )
                hashlist_reallot(list1);
        hash_value = hashalgo(key_name,list1->size);
        while (list1->Hash[hash_value].valid == 1)
        {
                if (!strcmp(list1->Hash[hash_value].key_name,key_name))
   return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        }
        list1->Hash[hash_value].key_name = (char*)malloc(sizeof(char)*strlen(key_name)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
}

canonical_original_code:
int hashlist_add_implemented(struct hashlist_t *list1, char *key_name, int x, int y, int z)
{
        int hash_value;
        int i;
        if ( list1->Hash == ((void *)0) )
        {
                 list1->Hash = (struct hash_t *)malloc(sizeof(hash) * list1->size );
                 for( i=0; i<list1->size-1; i++)
                        list1->Hash[i].valid=0;
        }
        float alloted_percent = ((float)list1->alloted/list1->size)*100;
        if ( alloted_percent >= 80 )
                hashlist_reallot(list1);
        hash_value = hashalgo(key_name,list1->size);
        while (list1->Hash[hash_value].valid == 1)
        {
                if (!strcmp(list1->Hash[hash_value].key_name,key_name))
   return;
                if ( hash_value == list1->size-1 )
                        hash_value=-1;
                hash_value++;
        }
        list1->Hash[hash_value].key_name = (char *)malloc(sizeof(char)*strlen(key_name)+1);
        strcpy(list1->Hash[hash_value].key_name,key_name);
        list1->Hash[hash_value].x = x;
        list1->Hash[hash_value].y = y;
        list1->Hash[hash_value].z = z;
        list1->Hash[hash_value].valid = 1;
        list1->alloted++;
}

variable_types: struct hashlist_t { int size; int alloted; struct hash_t { char *key_name; int x; int y; int z; int valid; } *Hash; } *

user_defined_types: struct hashlist_t { int size; int alloted; struct hash_t *Hash; }


original_code:
void hashlist_reallot(hashlist* list1)
{
        int i;
        float alloted_percent = ((float)list1->alloted/list1->size)*100 ;
        printf("Realloting Hashlist with allocation %f  New Size %d\n",alloted_percent,list1->size*2);
        hashlist hashlist2;
        hashlist2.Hash=(hash*)malloc(sizeof(hash)*list1->size*2);
        hashlist2.size=list1->size*2;
        for( i=0; i < hashlist2.size-1; i++)
                hashlist2.Hash[i].valid=0;
        hashlist2.alloted=0;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        hashlist_ops.hashlist_add(&hashlist2,list1->Hash[i].key_name,list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
        hash* hash_tmp = list1->Hash;
        list1->Hash=hashlist2.Hash;
        list1->size=hashlist2.size;
        list1->alloted=hashlist2.alloted;
        free(hash_tmp);
}

canonical_original_code:
void hashlist_reallot(struct hashlist_t *list1)
{
        int i;
        float alloted_percent = ((float)list1->alloted/list1->size)*100;
        printf("Realloting Hashlist with allocation %f  New Size %d\n",alloted_percent,list1->size*2);
        struct hashlist_t hashlist2;
        hashlist2.Hash=(struct hash_t *)malloc(sizeof(hash)*list1->size*2);
        hashlist2.size=list1->size*2;
        for( i=0; i < hashlist2.size-1; i++)
                hashlist2.Hash[i].valid=0;
        hashlist2.alloted=0;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        hashlist_ops.hashlist_add(&hashlist2,list1->Hash[i].key_name,list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
        struct hash_t *hash_tmp = list1->Hash;
        list1->Hash=hashlist2.Hash;
        list1->size=hashlist2.size;
        list1->alloted=hashlist2.alloted;
        free(hash_tmp);
}

variable_types: struct hashlist_t { int size; int alloted; struct hash_t { char *key_name; int x; int y; int z; int valid; } *Hash; }


decompiled_code:
int __fastcall hashlist_display_implemented(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

LODWORD(v1) = puts("Displaying Hash list");
if ( *(_DWORD *)(a1 + 4) && *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v1 = *(_QWORD *)(a1 + 8) + 24 * v2;
if ( *(_DWORD *)(v1 + 20) == 1 )
{
printf("\tName :- %s\n", *(const char **)v1);
LODWORD(v1) = printf(
"\tCoords :- %d %d %d\n",
*(unsigned int *)(*(_QWORD *)(a1 + 8) + 24 * v2 + 8),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + 24 * v2 + 12),
*(unsigned int *)(*(_QWORD *)(a1 + 8) + 24 * v2 + 16));
}
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return v1;
}

original_code:
void hashlist_display_implemented(hashlist* list1)
{
        int i;
        printf("Displaying Hash list\n");
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        printf("\tName   :- %s\n",list1->Hash[i].key_name);
                        printf("\tCoords :- %d %d %d\n",list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
}

canonical_original_code:
void hashlist_display_implemented(struct hashlist_t *list1)
{
        int i;
        printf("Displaying Hash list\n");
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
                {
                        printf("\tName   :- %s\n",list1->Hash[i].key_name);
                        printf("\tCoords :- %d %d %d\n",list1->Hash[i].x,list1->Hash[i].y,list1->Hash[i].z);
                }
        }
}

user_defined_types: struct hash_t { char *key_name; int x; int y; int z; int valid; }


decompiled_code:
void __fastcall hashlist_initialize_implemented(__int64 a1)
{
*(_DWORD *)a1 = 10;
*(_DWORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void hashlist_initialize_implemented(hashlist* list1)
{
        list1->size=10;
        list1->alloted=0;
        list1->Hash=((void *)0);
}

canonical_original_code:
void hashlist_initialize_implemented(struct hashlist_t *list1)
{
        list1->size=10;
        list1->alloted=0;
        list1->Hash=((void *)0);
}


decompiled_code:
__int64 __fastcall hashlist_findhash_implemented(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rbp

if ( !*(_DWORD *)(a1 + 4) )
return 0LL;
if ( *(int *)a1 <= 0 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = v2 + 24LL * (unsigned int)(*(_DWORD *)a1 - 1) + 24;
while ( 1 )
{
v4 = v2;
if ( *(_DWORD *)(v2 + 20) == 1 && !strcmp(*(const char **)v2, a2) )
break;
v2 += 24LL;
if ( v2 == v3 )
return 0LL;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // rbp

if ( !*(_DWORD *)(a1 + 4) )
return 0LL;
if ( *(int *)a1 <= 0 )
return 0LL;
v2 = *(_QWORD *)(a1 + 8);
v3 = v2 + 24LL * (unsigned int)(*(_DWORD *)a1 - 1) + 24;
while ( 1 )
{
v4 = v2;
if ( *(_DWORD *)(v2 + 20) == 1 && !strcmp(*(const char **)v2, a2) )
break;
v2 += 24LL;
if ( v2 == v3 )
return 0LL;
}
return v4;
}

original_code:
hash* hashlist_findhash_implemented(hashlist* list1, char* key_name)
{
        int i;
        if (list1->alloted == 0) return ((void *)0);
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1 && !strcmp(list1->Hash[i].key_name,key_name))
                        return &list1->Hash[i];
        }
        return ((void *)0);
}

canonical_original_code:
struct hash_t *hashlist_findhash_implemented(struct hashlist_t *list1, char *key_name)
{
        int i;
        if (list1->alloted == 0) return ((void *)0);
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1 && !strcmp(list1->Hash[i].key_name,key_name))
                        return &list1->Hash[i];
        }
        return ((void *)0);
}

variable_types: struct hashlist_t { int size; int alloted; struct hash_t *Hash; } *

return_type: struct hash_t { char *key_name; int x; int y; int z; int valid; } *


original_code:
void hashlist_destroy_implemented(hashlist* list1)
{
        int i;
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
   free(list1->Hash[i].key_name);
        }
 free(list1->Hash);
}

canonical_original_code:
void hashlist_destroy_implemented(struct hashlist_t *list1)
{
        int i;
        if (list1->alloted == 0) return;
        for(i=0; i < list1->size; i++)
        {
                if(list1->Hash[i].valid == 1)
   free(list1->Hash[i].key_name);
        }
 free(list1->Hash);
}


hashalgo

original_code:
int hashalgo(char* str,int M)
{
 int i,j,k,length;
 long mult,sum=0;
 length=strlen(str)/4;
 for(i=0;i<strlen(str);i++)
 {
  sum+=str[i]^(23+i%4);
 }
 sum=53*sum^3+3*sum^2-5*sum+8;
 if ( sum <0 )
   sum = -sum;
 return sum % M;
}

canonical_original_code:
int hashalgo(char *str, int M)
{
 int i; int j; int k; int length;
 long mult; long sum = 0;
 length=strlen(str)/4;
 for(i=0;i<strlen(str);i++)
 {
  sum+=str[i]^(23+i%4);
 }
 sum=53*sum^3+3*sum^2-5*sum+8;
 if ( sum <0 )
   sum = -sum;
 return sum % M;
}

variable_types:
str
char *

variable_types: M int

variable_types: j int

variable_types: k int

variable_types: length int

variable_types: mult long

variable_types: sum long


relpath

decompiled_code:
char *__fastcall relpath(char *src)
{
size_t v1; // rax
char *v2; // rbp
int v3; // er12
size_t v4; // rax
char *v5; // rbx
char *v6; // rax
char *v7; // rbp
char delim[2]; // [rsp+Eh] [rbp-AAh] BYREF
struct stat v10; // [rsp+10h] [rbp-A8h] BYREF

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
strcpy(v2, src);
strcpy(delim, "/");
v3 = strlen(v2) - (*v2 == 47);
v4 = strlen(src);
v5 = (char *)malloc(v4 + 2);
v6 = strtok(v2, delim);
strcpy(v5, v6);
while ( 1 )
{
if ( stat(v5, &v10) || (v10.st_mode & 0xF000) != 0x4000 )
{
if ( v3 == strlen(v5) )
return v5;
mkdir(v5, 0x1FFu);
}
v7 = strtok(0LL, delim);
if ( !v7 )
break;
*(_WORD *)&v5[strlen(v5)] = 47;
strcat(v5, v7);
}
free(v5);
return v5;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
size_t v1; // rax
char *v2; // rbp
int v3; // er12
size_t v4; // rax
char *v5; // rbx
char *v6; // rax
char *v7; // rbp
char delim[2]; // [rsp+Eh] [rbp-AAh] BYREF
struct stat v10; // [rsp+10h] [rbp-A8h] BYREF

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
strcpy(v2, src);
strcpy(delim, "/");
v3 = strlen(v2) - (*v2 == 47);
v4 = strlen(src);
v5 = (char *)malloc(v4 + 2);
v6 = strtok(v2, delim);
strcpy(v5, v6);
while ( 1 )
{
if ( stat(v5, &v10) || (v10.st_mode & 0xF000) != 0x4000 )
{
if ( v3 == strlen(v5) )
return v5;
mkdir(v5, 0x1FFu);
}
v7 = strtok(0LL, delim);
if ( !v7 )
break;
*(_WORD *)&v5[strlen(v5)] = 47;
strcat(v5, v7);
}
free(v5);
return v5;
}

original_code:
char* relpath(char* name)
{
    struct stat sb;
    char* name_tmp=malloc(strlen(name)*sizeof(char)+1);
    strcpy(name_tmp,name);
    int len = strlen(name_tmp);
    char delims[] = "/";
    if (name_tmp[0]=='/')
        len--;
    char *result = ((void *)0);
    char* prev=malloc(strlen(name)+sizeof(char)+1);
    result = strtok(name_tmp,delims);
    strcpy(prev,result);
    while( result != ((void *)0) )
    {
        if (!(stat(prev, &sb) == 0 && ((((sb.st_mode)) & 0170000) == (0040000))))
        {
            if ( len == strlen(prev))
            {
  return prev;
            }
            else
                mkdir(prev,0777);
        }
        result = strtok( ((void *)0), delims );
        if (result!=((void *)0))
        {
            strcat(prev,"/");
            strcat(prev,result);
        }
    }
    free(prev);
}

canonical_original_code:
char *relpath(char *name)
{
    struct stat sb;
    char *name_tmp = malloc(strlen(name)*sizeof(char)+1);
    strcpy(name_tmp,name);
    int len = strlen(name_tmp);
    char delims[] = "/";
    if (name_tmp[0]=='/')
        len--;
    char *result = ((void *)0);
    char *prev = malloc(strlen(name)+sizeof(char)+1);
    result = strtok(name_tmp,delims);
    strcpy(prev,result);
    while( result != ((void *)0) )
    {
        if (!(stat(prev, &sb) == 0 && ((((sb.st_mode)) & 0170000) == (0040000))))
        {
            if ( len == strlen(prev))
            {
  return prev;
            }
            else
                mkdir(prev,0777);
        }
        result = strtok( ((void *)0), delims );
        if (result!=((void *)0))
        {
            strcat(prev,"/");
            strcat(prev,result);
        }
    }
    free(prev);
}

variable_types:
name
char *

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

variable_types: len int

variable_types:
delims
char []

variable_types:
result
char *

variable_types:
prev
char *

return_type: char *

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


decompiled_code:
__int64 __fastcall set_area(_DWORD *a1, int a2, int a3, int a4, int a5, int a6)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
a1[3] = a5;
a1[4] = a6;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, int a2, int a3, int a4, int a5, int a6)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
a1[3] = a5;
a1[4] = a6;
return 1LL;
}

original_code:
int set_area(area* a1,int no,int x1,int x2, int y1, int y2)
{
    a1->no=no;
    a1->x1=x1;
    a1->x2=x2;
    a1->y1=y1;
    a1->y2=y2;
    return 1;
}

canonical_original_code:
int set_area(struct area_t *a1, int no, int x1, int x2, int y1, int y2)
{
    a1->no=no;
    a1->x1=x1;
    a1->x2=x2;
    a1->y1=y1;
    a1->y2=y2;
    return 1;
}

variable_types: struct area_t { int no; int x1; int x2; int y1; int y2; } *

variable_types: no int


canonical_original_code:
int calculate_area(struct area_t *a1, struct area_t *a2, int weight, int alloted_weight)
{
    if (a1->x2 - a1->x1 >= a1->y2 - a1->y1)
    {
 a2->y1=a1->y1;
 a2->y2=a1->y2;
 a2->x1=a1->x1+((float)a1->x2/100)*alloted_weight;
 a2->x2=a2->x1+((float)a1->x2/100)*weight;
    }
    else
    {
 a2->x1=a1->x1;
 a2->x2=a1->x2;
 a2->y1=a1->y1+((float)a1->y2/100)*alloted_weight;
 a2->y2=a2->y1+((float)a1->y2/100)*weight;
    }
    return 1;
}

variable_types: weight int

user_defined_types: struct area_t { int no; int x1; int x2; int y1; int y2; }


decompiled_code:
__int64 __fastcall random_range(int a1, int a2)
{
return (unsigned int)(int)(float)((int)(float)((float)((float)rand() * 4.6566129e-10) * (float)(a2 - a1 + 1)) + a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
return (unsigned int)(int)(float)((int)(float)((float)((float)rand() * 4.6566129e-10) * (float)(a2 - a1 + 1)) + a1);
}

original_code:
int random_range(int a1, int a2)
{
    int num;
    float unit;
    num=rand();
    unit=num/(float) 2147483647;
    unit=a1 + (int)(unit * ((a2 - a1) + 1));
    return (int)unit;
}

variable_types: num int

variable_types: unit float


decompiled_code:
void *gnu_getcwd()
{
void *v0; // rbx
int i; // ebp

v0 = malloc(0x64uLL);
for ( i = 100; !getcwd((char *)v0, i); v0 = malloc(i) )
{
i *= 2;
free(v0);
}
return v0;
}

canonical_decompiled_code:
void *func0()
{
void *v0; // rbx
int i; // ebp

v0 = malloc(0x64uLL);
for ( i = 100; !getcwd((char *)v0, i); v0 = malloc(i) )
{
i *= 2;
free(v0);
}
return v0;
}

original_code:
char* gnu_getcwd ()
{
  int size = 100;
  char *buffer = (char*)malloc(sizeof(char)*size);
  while (1)
    {
      char *value = getcwd (buffer, size);
      if (value != 0)
        return buffer;
      size *= 2;
      free (buffer);
      buffer = malloc(sizeof(char)*size);
    }
}

canonical_original_code:
char *gnu_getcwd()
{
  int size = 100;
  char *buffer = (char*)malloc(sizeof(char)*size);
  while (1)
    {
      char *value = getcwd (buffer, size);
      if (value != 0)
        return buffer;
      size *= 2;
      free (buffer);
      buffer = malloc(sizeof(char)*size);
    }
}

variable_types: size int

variable_types:
buffer
char *

variable_types:
value
char *