decompiled_code:
__int64 __fastcall Terran_VieilMont(__int64 a1, __int64 a2, int a3, unsigned int a4, double a5)
{
__int64 v5; // rbp
double v6; // r12
__int64 result; // rax
__int64 v10; // r15
int v11; // edi

if ( a2 )
{
v5 = a1;
v6 = a5;
if ( !a1 )
{
Terran_Set(2LL, a2, a3);
Terran_AddHaut(*(_DWORD *)(a2 + 8), a5 / 3.0);
Terran_AddHaut(*(_DWORD *)(a2 + 12), a5 / 3.0);
result = Terran_AddHaut(*(_DWORD *)(a2 + 16), a5 / 3.0);
*(_DWORD *)a2 = 0;
return result;
}
if ( *(_DWORD *)a2 == 2 )
{
*(_DWORD *)a2 = 0;
v10 = *(_QWORD *)(a2 + 24);
if ( v10 == a1 )
{
v11 = *(_DWORD *)(a2 + 16);
v10 = *(_QWORD *)(a2 + 32);
}
else
{
if ( *(_QWORD *)(a2 + 32) != a1 )
{
v5 = 0LL;
if ( a3 <= 1 )
return result;
goto LABEL_18;
}
v11 = *(_DWORD *)(a2 + 8);
v5 = *(_QWORD *)(a2 + 40);
}
if ( v11 != -1 )
{
if ( (int)a4 / 10 < a3 && (int)(3 * a4) / 10 > a3 )
{
v6 = a5 * 0.9;
result = Terran_AddHaut(v11, a5 * 0.9);
}
else
{
v6 = a5 * 0.95;
result = Terran_AddHaut(v11, a5 * 0.95);
}
}
if ( a3 <= 1 )
return result;
if ( v10 )
result = Terran_VieilMont(a2, v10, (unsigned int)(a3 - 1), a4, v6);
LABEL_18:
if ( v5 )
result = Terran_VieilMont(a2, v5, (unsigned int)(a3 - 1), a4, v6);
return result;
}
}
return result;
}

original_code:
void Terran_VieilMont(STriangle* orig,STriangle* t,double h,int p,int max)
{
 int point=-1;
 STriangle* t1=((void *)0),*t2=((void *)0),*t3=((void *)0);
 if(t!=((void *)0))
 {
  if(orig==((void *)0))
  {
   Terran_Set(2,t,p);
   Terran_AddHaut(t->p1,h/3);
   Terran_AddHaut(t->p2,h/3);
   Terran_AddHaut(t->p3,h/3);
   t1=t->t1;
   t2=t->t2;
   t3=t->t3;
   t->type=0;
  }
 else
 if(t->type==2)
 {
  t->type=0;
  if(orig==t->t1)
  {
   point =t->p3;
   t1=t->t2;
   t2=t->t1;
  }
  else if(orig==t->t2)
  {
   point =t->p1;
   t1=t->t1;
   t2=t->t3;
  }
  else if(orig==t->t1)
  {
   point =t->p2;
   t1=t->t3;
   t2=t->t2;
  }
  if (point!=-1)
  {
   if ((p>(max/10))&&(p<(3*max/10)))
   {
    h*=0.90;
    Terran_AddHaut(point,h);
   }
   else
   {
    h*=0.95;
    Terran_AddHaut(point,h);
   }
  }
  if (p>1)
  {
   if(t1!=((void *)0)) Terran_VieilMont(t,t1,h,p-1,max);
   if(t2!=((void *)0)) Terran_VieilMont(t,t2,h,p-1,max);
   if(t3!=((void *)0)) Terran_VieilMont(t,t3,h,p-1,max);
  }
 }
 }
}

canonical_original_code:
void Terran_VieilMont(struct sTriangle *orig, struct sTriangle *t, double h, int p, int max)
{
 int point = -1;
 struct sTriangle *t1 = ((void *)0); struct sTriangle *t2 = ((void *)0); struct sTriangle *t3 = ((void *)0);
 if(t!=((void *)0))
 {
  if(orig==((void *)0))
  {
   Terran_Set(2,t,p);
   Terran_AddHaut(t->p1,h/3);
   Terran_AddHaut(t->p2,h/3);
   Terran_AddHaut(t->p3,h/3);
   t1=t->t1;
   t2=t->t2;
   t3=t->t3;
   t->type=0;
  }
 else
 if(t->type==2)
 {
  t->type=0;
  if(orig==t->t1)
  {
   point =t->p3;
   t1=t->t2;
   t2=t->t1;
  }
  else if(orig==t->t2)
  {
   point =t->p1;
   t1=t->t1;
   t2=t->t3;
  }
  else if(orig==t->t1)
  {
   point =t->p2;
   t1=t->t3;
   t2=t->t2;
  }
  if (point!=-1)
  {
   if ((p>(max/10))&&(p<(3*max/10)))
   {
    h*=0.90;
    Terran_AddHaut(point,h);
   }
   else
   {
    h*=0.95;
    Terran_AddHaut(point,h);
   }
  }
  if (p>1)
  {
   if(t1!=((void *)0)) Terran_VieilMont(t,t1,h,p-1,max);
   if(t2!=((void *)0)) Terran_VieilMont(t,t2,h,p-1,max);
   if(t3!=((void *)0)) Terran_VieilMont(t,t3,h,p-1,max);
  }
 }
 }
}

variable_types: max int


repo: sbksba/Delaunay

original_code:
void Vecteur_ProdVect(SVecteur *V1, SVecteur *V2, SVecteur *V3)
{
 V3->x=V1->y*V2->z-V1->z*V2->y;
 V3->y=V1->z*V2->x-V1->x*V2->z;
 V3->z=V1->x*V2->y-V1->y*V2->x;
}

canonical_original_code:
void Vecteur_ProdVect(struct sVecteur *V1, struct sVecteur *V2, struct sVecteur *V3)
{
 V3->x=V1->y*V2->z-V1->z*V2->y;
 V3->y=V1->z*V2->x-V1->x*V2->z;
 V3->z=V1->x*V2->y-V1->y*V2->x;
}

return_type: void


decompiled_code:
_BOOL8 __fastcall Vecteur_Zup(double *a1, double *a2)
{
return *a1 * a2[1] - a1[1] * *a2 > 0.0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(double *a1, double *a2)
{
return *a1 * a2[1] - a1[1] * *a2 > 0.0;
}

original_code:
int Vecteur_Zup(SVecteur *V1, SVecteur *V2)
{
return ((V1->x*V2->y-V1->y*V2->x)>0.0);
}

canonical_original_code:
int Vecteur_Zup(struct sVecteur *V1, struct sVecteur *V2)
{
return ((V1->x*V2->y-V1->y*V2->x)>0.0);
}

return_type: int


original_code:
int Delaunay_ChoisitPoint()
{
 STriangle *t;
 double coef1,coef2,coef3;
 double sum;
 t = tab.triangles->first->t;
 if(param.barycentre)
  {coef1=coef2=coef3=1;}
 else
  {
  coef1 = rand()%5+1;
  coef2 = rand()%5+1;
  coef3 = rand()%5+1;
  }
 sum = coef1 + coef2 + coef3;
 return Global_AddPoint( (tab.p[t->p1].x*coef1 + tab.p[t->p2].x*coef2 + tab.p[t->p3].x*coef3)/sum,
      (tab.p[t->p1].y*coef1 + tab.p[t->p2].y*coef2 + tab.p[t->p3].y*coef3)/sum,
      (tab.p[t->p1].z*coef1 + tab.p[t->p2].z*coef2 + tab.p[t->p3].z*coef3)/sum);
}

canonical_original_code:
int Delaunay_ChoisitPoint()
{
 struct sTriangle *t;
 double coef1; double coef2; double coef3;
 double sum;
 t = tab.triangles->first->t;
 if(param.barycentre)
  {coef1=coef2=coef3=1;}
 else
  {
  coef1 = rand()%5+1;
  coef2 = rand()%5+1;
  coef3 = rand()%5+1;
  }
 sum = coef1 + coef2 + coef3;
 return Global_AddPoint( (tab.p[t->p1].x*coef1 + tab.p[t->p2].x*coef2 + tab.p[t->p3].x*coef3)/sum,
      (tab.p[t->p1].y*coef1 + tab.p[t->p2].y*coef2 + tab.p[t->p3].y*coef3)/sum,
      (tab.p[t->p1].z*coef1 + tab.p[t->p2].z*coef2 + tab.p[t->p3].z*coef3)/sum);
}

variable_types: struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint { double x; } centre; double rayon; double critere; } *

variable_types: sum double

user_defined_types: struct sTriangle { int type; int flip_param; int p1; struct sTriangle *t1; struct sPoint centre; double rayon; double critere; }


decompiled_code:
_BOOL8 __fastcall Delaunay_PointInCercle(int a1, double *a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8

v2 = tab[3 * a1 + 3] - a2[6];
v3 = tab[3 * a1 + 4];
v4 = (v3 - a2[7]) * (v3 - a2[7]) + v2 * v2;
if ( v4 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
return a2[9] > v5;
}

original_code:
int Delaunay_PointInCercle(int p, STriangle *t)
{
 double dist = (tab.p[p].x-t->centre.x)*(tab.p[p].x-t->centre.x)+(tab.p[p].y-t->centre.y)*(tab.p[p].y-t->centre.y);
 dist = sqrt(dist);
 return (dist<t->rayon);
}

canonical_original_code:
int Delaunay_PointInCercle(int p, struct sTriangle *t)
{
 double dist = (tab.p[p].x-t->centre.x)*(tab.p[p].x-t->centre.x)+(tab.p[p].y-t->centre.y)*(tab.p[p].y-t->centre.y);
 dist = sqrt(dist);
 return (dist<t->rayon);
}

variable_types: p int

variable_types: dist double


achieveDestruction

decompiled_code:
__int64 __fastcall achieveDestruction(int a1)
{
unsigned int v1; // edx
_BYTE *v2; // rax

v1 = -4 * players - a1;
if ( numNodes <= 0 )
return 1;
v2 = (_BYTE *)(nodes + 4LL);
do
{
if ( !*v2 )
{
if ( !v1 )
return v1;
++v1;
}
v2 += 88;
}
while ( v2 != (_BYTE *)(nodes + 88LL * (unsigned int)(numNodes - 1) + 92) );
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // edx
_BYTE *v2; // rax

v1 = -4 * players - a1;
if ( numNodes <= 0 )
return 1;
v2 = (_BYTE *)(nodes + 4LL);
do
{
if ( !*v2 )
{
if ( !v1 )
return v1;
++v1;
}
v2 += 88;
}
while ( v2 != (_BYTE *)(nodes + 88LL * (unsigned int)(numNodes - 1) + 92) );
return 1;
}

original_code:
static int achieveDestruction(int numAcceptable)
{
 int alive = -4 * players - numAcceptable;
 int i = 0;
 for (; i < numNodes; i++) {
  if (!nodes[i].dead)
   if (0 == alive++)
    return 0;
 }
 return 1;
}

variable_types: numAcceptable int

variable_types: alive int

variable_types: i int


achieveRosetteHelper

decompiled_code:
__int64 __fastcall achieveRosetteHelper(int a1, __int64 a2)
{
__int64 result; // rax
int v3; // er14
int v4; // er15
__int64 v5; // rbp
__int64 v6; // rbx
int v7; // er13
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8

*(_BYTE *)(a2 + a1) = 1;
result = nodes + 88LL * a1;
v3 = *(_DWORD *)(result + 16);
v4 = (int)*(double *)(result + 56);
if ( numNodes > 0 )
{
v5 = 0LL;
v6 = 0LL;
v7 = *(_DWORD *)(result + 8);
do
{
result = nodes + v5;
if ( !*(_BYTE *)(nodes + v5 + 4) && !*(_BYTE *)(a2 + v6) )
{
v9 = (double)(int)(*(_QWORD *)(result + 8) - v7);
v10 = v9 * v9 + (double)(*(_DWORD *)(result + 16) - v3) * (double)(*(_DWORD *)(result + 16) - v3);
if ( v10 < 0.0 )
v8 = sqrt(v10);
else
v8 = sqrt(v10);
result = nodes;
if ( v8 - *(double *)(nodes + v5 + 56) - (double)v4 < 10.0 )
result = achieveRosetteHelper((unsigned int)v6, a2);
}
++v6;
v5 += 88LL;
}
while ( numNodes > (int)v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
__int64 result; // rax
int v3; // er14
int v4; // er15
__int64 v5; // rbp
__int64 v6; // rbx
int v7; // er13
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8

*(_BYTE *)(a2 + a1) = 1;
result = nodes + 88LL * a1;
v3 = *(_DWORD *)(result + 16);
v4 = (int)*(double *)(result + 56);
if ( numNodes > 0 )
{
v5 = 0LL;
v6 = 0LL;
v7 = *(_DWORD *)(result + 8);
do
{
result = nodes + v5;
if ( !*(_BYTE *)(nodes + v5 + 4) && !*(_BYTE *)(a2 + v6) )
{
v9 = (double)(int)(*(_QWORD *)(result + 8) - v7);
v10 = v9 * v9 + (double)(*(_DWORD *)(result + 16) - v3) * (double)(*(_DWORD *)(result + 16) - v3);
if ( v10 < 0.0 )
v8 = sqrt(v10);
else
v8 = sqrt(v10);
result = nodes;
if ( v8 - *(double *)(nodes + v5 + 56) - (double)v4 < 10.0 )
result = func1((unsigned int)v6, a2);
}
++v6;
v5 += 88LL;
}
while ( numNodes > (int)v6 );
}
return result;
}

original_code:
static void achieveRosetteHelper(int ix, char *touching)
{
 touching[ix] = 1;
 int x = nodes[ix].x;
 int y = nodes[ix].y;
 int r = nodes[ix].size;
 int i = 0;
 for (; i < numNodes; i++) {
  if (nodes[i].dead || touching[i])
   continue;
  double dx = nodes[i].x - x;
  double dy = nodes[i].y - y;
  if (sqrt(dx * dx + dy * dy) - nodes[i].size - r < 10)
   achieveRosetteHelper(i, touching);
 }
}

variable_types: ix int

variable_types:
touching
char *

variable_types: x int

variable_types: y int

variable_types: r int

variable_types: dx double

variable_types: dy double


achieveLazy

decompiled_code:
__int64 achieveLazy()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 1LL;
}

original_code:
int achieveLazy()
{
 return 1;
}

canonical_original_code:
int achieveLazy()
{
 return 1;
}


achieveFlawless

decompiled_code:
__int64 achieveFlawless()
{
_BYTE *v0; // rax

if ( players <= 0 )
return 2LL;
v0 = (_BYTE *)(guyDatas + 73LL);
while ( 1 )
{
if ( *v0 )
return 1LL;
if ( !v0[1] )
break;
v0 += 152;
if ( v0 == (_BYTE *)(guyDatas + 152LL * (unsigned int)(players - 1) + 225) )
return 2LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 func3()
{
_BYTE *v0; // rax

if ( players <= 0 )
return 2LL;
v0 = (_BYTE *)(guyDatas + 73LL);
while ( 1 )
{
if ( *v0 )
return 1LL;
if ( !v0[1] )
break;
v0 += 152;
if ( v0 == (_BYTE *)(guyDatas + 152LL * (unsigned int)(players - 1) + 225) )
return 2LL;
}
return 1LL;
}

original_code:
int achieveFlawless()
{
 int i = 0;
 for (; i < players; i++) {
  if (guyDatas[i].injured || !guyDatas[i].firstLife)
   return 1;
 }
 return 2;
}


achieveGardens

decompiled_code:
__int64 achieveGardens()
{
_DWORD *v0; // rax

if ( players <= 0 )
return 0LL;
v0 = (_DWORD *)(guyDatas + 16LL);
while ( *v0 != 70 )
{
v0 += 38;
if ( v0 == (_DWORD *)(guyDatas + 152LL * (unsigned int)(players - 1) + 168) )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
_DWORD *v0; // rax

if ( players <= 0 )
return 0LL;
v0 = (_DWORD *)(guyDatas + 16LL);
while ( *v0 != 70 )
{
v0 += 38;
if ( v0 == (_DWORD *)(guyDatas + 152LL * (unsigned int)(players - 1) + 168) )
return 0LL;
}
return 1LL;
}

original_code:
int achieveGardens()
{
 int i = 0;
 for (; i < players; i++) {
  if (guyDatas[i].controlType == 70)
   return 1;
 }
 return 0;
}


achieveCave

decompiled_code:
__int64 achieveCave()
{
_DWORD *v0; // rax

if ( players <= 0 )
return 0LL;
v0 = (_DWORD *)(guyDatas + 144LL);
do
{
if ( (unsigned int)(*v0 + 49) <= 0x62 && (int)v0[1] < -50 )
return 1LL;
v0 += 38;
}
while ( v0 != (_DWORD *)(guyDatas + 152LL * (unsigned int)(players - 1) + 296) );
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
_DWORD *v0; // rax

if ( players <= 0 )
return 0LL;
v0 = (_DWORD *)(guyDatas + 144LL);
do
{
if ( (unsigned int)(*v0 + 49) <= 0x62 && (int)v0[1] < -50 )
return 1LL;
v0 += 38;
}
while ( v0 != (_DWORD *)(guyDatas + 152LL * (unsigned int)(players - 1) + 296) );
return 0LL;
}

original_code:
int achieveCave()
{
 int i = 0;
 for (; i < players; i++) {
  if (abs(guyDatas[i].centerX) < 50
      && guyDatas[i].centerY < -50)
   return 1;
 }
 return 0;
}


achieveBuilding

decompiled_code:
__int64 achieveBuilding()
{
int *v0; // rax

if ( players <= 0 )
return 0LL;
v0 = (int *)(guyDatas + 148LL);
while ( *v0 >= -325 )
{
v0 += 38;
if ( v0 == (int *)(guyDatas + 152LL * (unsigned int)(players - 1) + 300) )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
int *v0; // rax

if ( players <= 0 )
return 0LL;
v0 = (int *)(guyDatas + 148LL);
while ( *v0 >= -325 )
{
v0 += 38;
if ( v0 == (int *)(guyDatas + 152LL * (unsigned int)(players - 1) + 300) )
return 0LL;
}
return 1LL;
}

original_code:
int achieveBuilding()
{
 int i = 0;
 for (; i < players; i++) {
  if (guyDatas[i].centerY < -325)
   return 1;
 }
 return 0;
}


achieveSumo

decompiled_code:
__int64 achieveSumo()
{
return achieveDestruction(70);
}

canonical_decompiled_code:
__int64 func7()
{
return func0(70);
}

original_code:
int achieveSumo()
{
 return achieveDestruction(70);
}


achieveDrop

decompiled_code:
__int64 achieveDrop()
{
return achieveDestruction(20);
}

canonical_decompiled_code:
__int64 func8()
{
return func0(20);
}

original_code:
int achieveDrop()
{
 return achieveDestruction(20);
}


achieveWalled

decompiled_code:
__int64 achieveWalled()
{
return achieveDestruction(20);
}

canonical_decompiled_code:
__int64 func9()
{
return func0(20);
}

original_code:
int achieveWalled()
{
 return achieveDestruction(20);
}


achieveBoulder

decompiled_code:
__int64 achieveBoulder()
{
__int64 v0; // rax

if ( numNodes <= 0 )
return 1LL;
v0 = nodes + 4LL;
do
{
if ( !*(_BYTE *)v0 && 3.0 == *(double *)(v0 + 60) )
return 0LL;
v0 += 88LL;
}
while ( v0 != nodes + 88LL * (unsigned int)(numNodes - 1) + 92 );
return 1LL;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 v0; // rax

if ( numNodes <= 0 )
return 1LL;
v0 = nodes + 4LL;
do
{
if ( !*(_BYTE *)v0 && 3.0 == *(double *)(v0 + 60) )
return 0LL;
v0 += 88LL;
}
while ( v0 != nodes + 88LL * (unsigned int)(numNodes - 1) + 92 );
return 1LL;
}

original_code:
int achieveBoulder()
{
 int i = 0;
 for (; i < numNodes; i++) {
  if (!nodes[i].dead && 3 == nodes[i].mass)
   return 0;
 }
 return 1;
}


achievePlain

decompiled_code:
__int64 achievePlain()
{
__int64 v0; // rax

if ( numNodes <= 0 )
return 1LL;
v0 = nodes + 4LL;
do
{
if ( !*(_BYTE *)v0 && 1.0 == *(double *)(v0 + 60) )
return 0LL;
v0 += 88LL;
}
while ( v0 != nodes + 88LL * (unsigned int)(numNodes - 1) + 92 );
return 1LL;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 v0; // rax

if ( numNodes <= 0 )
return 1LL;
v0 = nodes + 4LL;
do
{
if ( !*(_BYTE *)v0 && 1.0 == *(double *)(v0 + 60) )
return 0LL;
v0 += 88LL;
}
while ( v0 != nodes + 88LL * (unsigned int)(numNodes - 1) + 92 );
return 1LL;
}

original_code:
int achievePlain()
{
 int i = 0;
 for (; i < numNodes; i++) {
  if (!nodes[i].dead && 1 == nodes[i].mass)
   return 0;
 }
 return 1;
}


achieveManMech

original_code:
int achieveManMech()
{
 int count = 0;
 int result = 0;
 int i = 0;
 int j;
 for (; i < numNodes; i++) {
  if (nodes[i].dead || 14 != nodes[i].mass)
   continue;
  count++;
  for (j = 0; j < nodes[i].numConnections; j++) {
   if (nodes[i].connections[j].dead) {
    result = 1;
    break;
   }
  }
 }
 if (count < 5)
  return 0;
 return result;
}

variable_types: count int

variable_types: result int

variable_types: j int


achieveGunMech

decompiled_code:
__int64 achieveGunMech()
{
__int64 v0; // rax
double v1; // xmm0_8

if ( numNodes <= 0 )
return 1LL;
v0 = nodes + 4LL;
do
{
if ( !*(_BYTE *)v0 )
{
v1 = *(double *)(v0 + 60);
if ( v1 == 1.0 || v1 == 14.0 )
return 0LL;
}
v0 += 88LL;
}
while ( v0 != nodes + 88LL * (unsigned int)(numNodes - 1) + 92 );
return 1LL;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 v0; // rax
double v1; // xmm0_8

if ( numNodes <= 0 )
return 1LL;
v0 = nodes + 4LL;
do
{
if ( !*(_BYTE *)v0 )
{
v1 = *(double *)(v0 + 60);
if ( v1 == 1.0 || v1 == 14.0 )
return 0LL;
}
v0 += 88LL;
}
while ( v0 != nodes + 88LL * (unsigned int)(numNodes - 1) + 92 );
return 1LL;
}

original_code:
int achieveGunMech()
{
 int i = 0;
 for (; i < numNodes; i++) {
  if (!nodes[i].dead
      && (14 == nodes[i].mass || 1 == nodes[i].mass))
   return 0;
 }
 return 1;
}


achieveMechMech

original_code:
int achieveMechMech()
{
 unsigned char stage = 0;
 int pos[2] = { -1000, 1000 };;
 int i = 0;
 int j, k, l;
 for (; i < numNodes; i++) {
  if (nodes[i].dead || nodes[i].mass != 14
      || nodes[i].size != 6)
   continue;
  for (j = nodes[i].numConnections - 1; j >= 0; j--) {
   if (nodes[i].connections[j].dead)
    return 0;
   k = nodes[i].connections[j].id;
   if (nodes[k].dead)
    return 0;
   for (l = nodes[k].numConnections - 1; l >= 0; l--)
    if (nodes[k].connections[l].dead)
     return 0;
   if (stage ^ (nodes[k].x > pos[stage]))
    pos[stage] = nodes[k].x;
  }
  if (stage)
   return pos[0] < pos[1];
  else
   stage++;
 }
 return 0;
}

canonical_original_code:
int achieveMechMech()
{
 unsigned char stage = 0;
 int pos[2] = { -1000, 1000 };;
 int i = 0;
 int j; int k; int l;
 for (; i < numNodes; i++) {
  if (nodes[i].dead || nodes[i].mass != 14
      || nodes[i].size != 6)
   continue;
  for (j = nodes[i].numConnections - 1; j >= 0; j--) {
   if (nodes[i].connections[j].dead)
    return 0;
   k = nodes[i].connections[j].id;
   if (nodes[k].dead)
    return 0;
   for (l = nodes[k].numConnections - 1; l >= 0; l--)
    if (nodes[k].connections[l].dead)
     return 0;
   if (stage ^ (nodes[k].x > pos[stage]))
    pos[stage] = nodes[k].x;
  }
  if (stage)
   return pos[0] < pos[1];
  else
   stage++;
 }
 return 0;
}

variable_types:
stage
unsigned char

variable_types:
pos
int [2]

variable_types: k int

variable_types: l int


achieveAsteroids

decompiled_code:
__int64 achieveAsteroids()
{
__int64 v0; // rcx
_DWORD *v1; // rax
__int64 v2; // rdx

if ( numNodes <= 0 )
return 0LL;
v0 = nodes + 4LL;
while ( *(_BYTE *)v0 || 10.0 != *(double *)(v0 + 52) || players <= 0 )
{
LABEL_3:
v0 += 88LL;
if ( v0 == nodes + 88LL * (unsigned int)(numNodes - 1) + 92 )
return 0LL;
}
v1 = (_DWORD *)(guyDatas + 144LL);
while ( 1 )
{
v2 = (int)v1[1] - *(_QWORD *)(v0 + 12);
if ( (double)(int)(*v1 - *(_QWORD *)(v0 + 4)) * (double)(int)(*v1 - *(_QWORD *)(v0 + 4))
+ (double)(int)v2 * (double)(int)v2 <= 100.0 )
return 1LL;
v1 += 38;
if ( v1 == (_DWORD *)(guyDatas + 152LL * (unsigned int)(players - 1) + 296) )
goto LABEL_3;
}
}

canonical_decompiled_code:
__int64 func15()
{
__int64 v0; // rcx
_DWORD *v1; // rax
__int64 v2; // rdx

if ( numNodes <= 0 )
return 0LL;
v0 = nodes + 4LL;
while ( *(_BYTE *)v0 || 10.0 != *(double *)(v0 + 52) || players <= 0 )
{
LABEL_3:
v0 += 88LL;
if ( v0 == nodes + 88LL * (unsigned int)(numNodes - 1) + 92 )
return 0LL;
}
v1 = (_DWORD *)(guyDatas + 144LL);
while ( 1 )
{
v2 = (int)v1[1] - *(_QWORD *)(v0 + 12);
if ( (double)(int)(*v1 - *(_QWORD *)(v0 + 4)) * (double)(int)(*v1 - *(_QWORD *)(v0 + 4))
+ (double)(int)v2 * (double)(int)v2 <= 100.0 )
return 1LL;
v1 += 38;
if ( v1 == (_DWORD *)(guyDatas + 152LL * (unsigned int)(players - 1) + 296) )
goto LABEL_3;
}
}

original_code:
int achieveAsteroids()
{
 int i = 0, j;
 for (; i < numNodes; i++) {
  if (nodes[i].dead || nodes[i].size != 10)
   continue;
  for (j = 0; j < players; j++) {
   double dx = guyDatas[j].centerX - nodes[i].x;
   double dy = guyDatas[j].centerY - nodes[i].y;
   if (dx * dx + dy * dy <= 100)
    return 1;
  }
 }
 return 0;
}

canonical_original_code:
int achieveAsteroids()
{
 int i = 0; int j;
 for (; i < numNodes; i++) {
  if (nodes[i].dead || nodes[i].size != 10)
   continue;
  for (j = 0; j < players; j++) {
   double dx = guyDatas[j].centerX - nodes[i].x;
   double dy = guyDatas[j].centerY - nodes[i].y;
   if (dx * dx + dy * dy <= 100)
    return 1;
  }
 }
 return 0;
}


achievePlanet

decompiled_code:
__int64 achievePlanet()
{
__int64 v0; // rbx
int v1; // ebp
double v2; // xmm0_8
double v3; // xmm0_8

if ( players <= 0 )
return 0LL;
v0 = 0LL;
v1 = 0;
while ( 1 )
{
v2 = (double)*(int *)(guyDatas + v0 + 144) * (double)*(int *)(guyDatas + v0 + 144)
+ (double)*(int *)(guyDatas + v0 + 148) * (double)*(int *)(guyDatas + v0 + 148);
v3 = v2 < 0.0 ? sqrt(v2) : sqrt(v2);
if ( v3 > 390.0 )
break;
++v1;
v0 += 152LL;
if ( players <= v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 v0; // rbx
int v1; // ebp
double v2; // xmm0_8
double v3; // xmm0_8

if ( players <= 0 )
return 0LL;
v0 = 0LL;
v1 = 0;
while ( 1 )
{
v2 = (double)*(int *)(guyDatas + v0 + 144) * (double)*(int *)(guyDatas + v0 + 144)
+ (double)*(int *)(guyDatas + v0 + 148) * (double)*(int *)(guyDatas + v0 + 148);
v3 = v2 < 0.0 ? sqrt(v2) : sqrt(v2);
if ( v3 > 390.0 )
break;
++v1;
v0 += 152LL;
if ( players <= v1 )
return 0LL;
}
return 1LL;
}

original_code:
int achievePlanet()
{
 int i = 0;
 for (; i < players; i++) {
  double x = guyDatas[i].centerX;
  double y = guyDatas[i].centerY;
  if (sqrt(x * x + y * y) > 390)
   return 1;
 }
 return 0;
}

variable_types: x double

variable_types: y double


achieveRosette

decompiled_code:
__int64 achieveRosette()
{
__int64 v0; // rax
int v1; // ebx
char *v2; // rbp
char *v3; // rdx
double *v4; // rax
__int64 result; // rax

if ( numNodes <= 0 )
{
v1 = 0;
}
else
{
v0 = nodes + 4LL;
v1 = 0;
while ( *(_BYTE *)v0 || 6.0 == *(double *)(v0 + 52) )
{
++v1;
v0 += 88LL;
if ( v1 == numNodes )
goto LABEL_11;
}
}
if ( numNodes == v1 )
{
LABEL_11:
puts("WTF HOW\nPlz contact me!\n-Simon");
result = 1LL;
}
else
{
v2 = (char *)calloc(numNodes, 1uLL);
achieveRosetteHelper(v1, (__int64)v2);
if ( numNodes <= 0 )
{
LABEL_17:
free(v2);
result = 1LL;
}
else
{
v3 = v2;
v4 = (double *)(nodes + 56LL);
while ( *((_BYTE *)v4 - 52) || *v3 || 6.0 == *v4 )
{
++v3;
v4 += 11;
if ( v3 == &v2[numNodes] )
goto LABEL_17;
}
free(v2);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 v0; // rax
int v1; // ebx
char *v2; // rbp
char *v3; // rdx
double *v4; // rax
__int64 result; // rax

if ( numNodes <= 0 )
{
v1 = 0;
}
else
{
v0 = nodes + 4LL;
v1 = 0;
while ( *(_BYTE *)v0 || 6.0 == *(double *)(v0 + 52) )
{
++v1;
v0 += 88LL;
if ( v1 == numNodes )
goto LABEL_11;
}
}
if ( numNodes == v1 )
{
LABEL_11:
puts("WTF HOW\nPlz contact me!\n-Simon");
result = 1LL;
}
else
{
v2 = (char *)calloc(numNodes, 1uLL);
func1(v1, (__int64)v2);
if ( numNodes <= 0 )
{
LABEL_17:
free(v2);
result = 1LL;
}
else
{
v3 = v2;
v4 = (double *)(nodes + 56LL);
while ( *((_BYTE *)v4 - 52) || *v3 || 6.0 == *v4 )
{
++v3;
v4 += 11;
if ( v3 == &v2[numNodes] )
goto LABEL_17;
}
free(v2);
result = 0LL;
}
}
return result;
}

original_code:
int achieveRosette()
{
 int i;
 for (i = 0; i < numNodes && (nodes[i].dead || nodes[i].size == 6);
      i++);
 if (i == numNodes) {
  puts("WTF HOW\nPlz contact me!\n-Simon");
  return 1;
 }
 char *touching = calloc(numNodes, 1);
 achieveRosetteHelper(i, touching);
 for (i = 0; i < numNodes; i++)
  if (nodes[i].dead == 0 && touching[i] == 0
      && nodes[i].size != 6) {
   free(touching);
   return 0;
  }
 free(touching);
 return 1;
}

variable_types: i int


achieveBigPlanet

decompiled_code:
__int64 achieveBigPlanet()
{
unsigned int *v0; // rax
unsigned int v1; // edx

if ( numTools <= 0 )
return 1;
v0 = (unsigned int *)tools;
while ( 1 )
{
v1 = *v0;
if ( !*v0 && v0[1] != -1 )
break;
v0 += 3;
if ( v0 == (unsigned int *)(tools + 12LL * (unsigned int)(numTools - 1) + 12) )
return 1;
}
return v1;
}

canonical_decompiled_code:
__int64 func18()
{
unsigned int *v0; // rax
unsigned int v1; // edx

if ( numTools <= 0 )
return 1;
v0 = (unsigned int *)tools;
while ( 1 )
{
v1 = *v0;
if ( !*v0 && v0[1] != -1 )
break;
v0 += 3;
if ( v0 == (unsigned int *)(tools + 12LL * (unsigned int)(numTools - 1) + 12) )
return 1;
}
return v1;
}

original_code:
int achieveBigPlanet()
{
 int i = 0;
 for (; i < numTools; i++) {
  if (tools[i].type == 0 && tools[i].where != -1)
   return 0;
 }
 return 1;
}


achieveTutorial

decompiled_code:
__int64 achieveTutorial()
{
__int64 v0; // rax
int v1; // esi

if ( numNodes <= 0 )
return 1LL;
v0 = nodes + 4LL;
v1 = 0;
do
{
if ( !*(_BYTE *)v0 && 8.0 == *(double *)(v0 + 52) && ++v1 == 9 )
return 0LL;
v0 += 88LL;
}
while ( v0 != nodes + 88LL * (unsigned int)(numNodes - 1) + 92 );
return 1LL;
}

canonical_decompiled_code:
__int64 func19()
{
__int64 v0; // rax
int v1; // esi

if ( numNodes <= 0 )
return 1LL;
v0 = nodes + 4LL;
v1 = 0;
do
{
if ( !*(_BYTE *)v0 && 8.0 == *(double *)(v0 + 52) && ++v1 == 9 )
return 0LL;
v0 += 88LL;
}
while ( v0 != nodes + 88LL * (unsigned int)(numNodes - 1) + 92 );
return 1LL;
}

original_code:
int achieveTutorial()
{
 int count = 0;
 int i = 0;
 for (; i < numNodes; i++) {
  if (nodes[i].dead == 0 && nodes[i].size == 8) {
   if (++count == 9)
    return 0;
  }
 }
 return 1;
}


quitGfx

decompiled_code:
__int64 quitGfx()
{
return _glewBindBuffer(34962LL, 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
return _glewBindBuffer(34962LL, 0LL);
}

original_code:
void quitGfx()
{
 __glewBindBuffer(0x8892, 0);
}


setColorFromHue

variable_types:
hue
unsigned short

variable_types: r float

variable_types: g float

variable_types: b float


getColorFromHue

return_type: unsigned int


setColorWhite

decompiled_code:
__int64 setColorWhite()
{
return _glewUniform3f(
(unsigned int)uniColorId,
COERCE_DOUBLE((unsigned __int64)LC13),
COERCE_DOUBLE((unsigned __int64)LC13),
COERCE_DOUBLE((unsigned __int64)LC13));
}

canonical_decompiled_code:
__int64 func4()
{
return _glewUniform3f(
(unsigned int)uniColorId,
COERCE_DOUBLE((unsigned __int64)LC13),
COERCE_DOUBLE((unsigned __int64)LC13),
COERCE_DOUBLE((unsigned __int64)LC13));
}

original_code:
void setColorWhite()
{
 __glewUniform3f(uniColorId, 0.5, 0.5, 0.5);
}


setColorFromHex

decompiled_code:
__int64 __fastcall setColorFromHex(int a1)
{
double v1; // xmm0_8
__int64 result; // rax

if ( (cheats & 0x10) == 0 )
{
HIDWORD(v1) = 0;
*(float *)&v1 = (float)(int)(a1 & 0xFF000000) / 4278190100.0;
result = _glewUniform3f(
(unsigned int)uniColorId,
v1,
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT((float)(a1 & 0xFF0000) / 16711680.0)),
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT((float)(a1 & 0xFF00) / 65280.0)));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1)
{
double v1; // xmm0_8
__int64 result; // rax

if ( (cheats & 0x10) == 0 )
{
HIDWORD(v1) = 0;
*(float *)&v1 = (float)(int)(a1 & 0xFF000000) / 4278190100.0;
result = _glewUniform3f(
(unsigned int)uniColorId,
v1,
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT((float)(a1 & 0xFF0000) / 16711680.0)),
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT((float)(a1 & 0xFF00) / 65280.0)));
}
return result;
}

original_code:
void setColorFromHex(uint32_t color)
{
 if (cheats & 16)
  return;
 __glewUniform3f(uniColorId, (float) (color & 0xFF000000) / 0xFF000000,
      (float) (color & 0xFF0000) / 0xFF0000,
      (float) (color & 0xFF00) / 0xFF00);
}

canonical_original_code:
void setColorFromHex(unsigned int color)
{
 if (cheats & 16)
  return;
 __glewUniform3f(uniColorId, (float) (color & 0xFF000000) / 0xFF000000,
      (float) (color & 0xFF0000) / 0xFF0000,
      (float) (color & 0xFF00) / 0xFF00);
}

variable_types:
color
unsigned int


drawBox

decompiled_code:
__int64 __fastcall drawBox(float a1, float a2, float a3, float a4)
{
int v5[10]; // [rsp+0h] [rbp-28h] BYREF

*(float *)v5 = a1;
*(float *)&v5[1] = a2;
*(float *)&v5[2] = a3;
*(float *)&v5[3] = a2;
*(float *)&v5[4] = a3;
*(float *)&v5[5] = a4;
*(float *)&v5[6] = a1;
*(float *)&v5[7] = a4;
_glewBufferData(34962LL, 32LL, v5, 35040LL);
glDrawArrays(7LL, 0LL, 4LL);
_glewMapBufferRange(34962LL, 0LL, 0LL, 42LL);
return _glewUnmapBuffer(34962LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(float a1, float a2, float a3, float a4)
{
int v5[10]; // [rsp+0h] [rbp-28h] BYREF

*(float *)v5 = a1;
*(float *)&v5[1] = a2;
*(float *)&v5[2] = a3;
*(float *)&v5[3] = a2;
*(float *)&v5[4] = a3;
*(float *)&v5[5] = a4;
*(float *)&v5[6] = a1;
*(float *)&v5[7] = a4;
_glewBufferData(34962LL, 32LL, v5, 35040LL);
glDrawArrays(7LL, 0LL, 4LL);
_glewMapBufferRange(34962LL, 0LL, 0LL, 42LL);
return _glewUnmapBuffer(34962LL);
}

original_code:
void drawBox(float x1, float y1, float x2, float y2)
{
 float points[] = {
  x1, y1,
  x2, y1,
  x2, y2,
  x1, y2
 };
 __glewBufferData(0x8892, sizeof(points), points,
       0x88E0);
 glDrawArrays(0x0007, 0, 4);
 __glewMapBufferRange(0x8892, 0, 0,
    0x0002 | 0x0020 |
    0x0008);
 __glewUnmapBuffer(0x8892);
}

variable_types:
points
float []


drawRectangle

decompiled_code:
__int64 __fastcall drawRectangle(float a1, float a2, float a3, float a4)
{
int v5[10]; // [rsp+0h] [rbp-28h] BYREF

*(float *)v5 = a1;
*(float *)&v5[1] = a2;
*(float *)&v5[2] = a3;
*(float *)&v5[3] = a2;
*(float *)&v5[4] = a3;
*(float *)&v5[5] = a4;
*(float *)&v5[6] = a1;
*(float *)&v5[7] = a4;
_glewBufferData(34962LL, 32LL, v5, 35040LL);
glDrawArrays(2LL, 0LL, 4LL);
_glewMapBufferRange(34962LL, 0LL, 0LL, 42LL);
return _glewUnmapBuffer(34962LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(float a1, float a2, float a3, float a4)
{
int v5[10]; // [rsp+0h] [rbp-28h] BYREF

*(float *)v5 = a1;
*(float *)&v5[1] = a2;
*(float *)&v5[2] = a3;
*(float *)&v5[3] = a2;
*(float *)&v5[4] = a3;
*(float *)&v5[5] = a4;
*(float *)&v5[6] = a1;
*(float *)&v5[7] = a4;
_glewBufferData(34962LL, 32LL, v5, 35040LL);
glDrawArrays(2LL, 0LL, 4LL);
_glewMapBufferRange(34962LL, 0LL, 0LL, 42LL);
return _glewUnmapBuffer(34962LL);
}

original_code:
void drawRectangle(float x1, float y1, float x2, float y2)
{
 float points[] = {
  x1, y1,
  x2, y1,
  x2, y2,
  x1, y2
 };
 __glewBufferData(0x8892, sizeof(points), points,
       0x88E0);
 glDrawArrays(0x0002, 0, 4);
 __glewMapBufferRange(0x8892, 0, 0,
    0x0002 | 0x0020 |
    0x0008);
 __glewUnmapBuffer(0x8892);
}


drawLine

decompiled_code:
__int64 __fastcall drawLine(float a1, float a2, float a3, float a4)
{
int v5[6]; // [rsp+0h] [rbp-18h] BYREF

*(float *)v5 = a1;
*(float *)&v5[1] = a2;
*(float *)&v5[2] = a3;
*(float *)&v5[3] = a4;
_glewBufferData(34962LL, 16LL, v5, 35040LL);
glDrawArrays(1LL, 0LL, 2LL);
_glewMapBufferRange(34962LL, 0LL, 0LL, 42LL);
return _glewUnmapBuffer(34962LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(float a1, float a2, float a3, float a4)
{
int v5[6]; // [rsp+0h] [rbp-18h] BYREF

*(float *)v5 = a1;
*(float *)&v5[1] = a2;
*(float *)&v5[2] = a3;
*(float *)&v5[3] = a4;
_glewBufferData(34962LL, 16LL, v5, 35040LL);
glDrawArrays(1LL, 0LL, 2LL);
_glewMapBufferRange(34962LL, 0LL, 0LL, 42LL);
return _glewUnmapBuffer(34962LL);
}

original_code:
void drawLine(float x1, float y1, float x2, float y2)
{
 float points[] = { x1, y1, x2, y2 };
 __glewBufferData(0x8892, sizeof(points), points,
       0x88E0);
 glDrawArrays(0x0001, 0, 2);
 __glewMapBufferRange(0x8892, 0, 0,
    0x0002 | 0x0020 |
    0x0008);
 __glewUnmapBuffer(0x8892);
}


drawCircle

decompiled_code:
float __fastcall drawCircle(float result, float a2, float a3)
{
float v3; // xmm0_4
int v4; // ebx
float *v5; // rbp
float v6; // xmm0_4
float v7; // xmm3_4
float v8; // xmm2_4
float *v9; // rax
float v10; // xmm6_4
float x; // [rsp+Ch] [rbp-2Ch]
float v12; // [rsp+14h] [rbp-24h]
float cosx; // [rsp+18h] [rbp-20h] BYREF
float sinx[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v12 = result;
x = a3;
if ( result <= 0.0 )
{
result = -1.0 - a3;
if ( (float)(-1.0 - a3) > v12 )
return result;
}
else if ( result > (float)(a3 + 1.0) )
{
return result;
}
if ( a2 <= 0.0 )
{
result = -1.0 - a3;
if ( (float)(-1.0 - a3) > a2 )
return result;
}
else
{
result = a3 + 1.0;
if ( a2 > (float)(a3 + 1.0) )
return result;
}
if ( a3 < 0.0 )
v3 = sqrtf(a3);
else
v3 = fsqrt(a3);
v4 = (int)(float)(v3 * 60.0);
if ( v4 < 4 )
v4 = 4;
v5 = (float *)malloc(8LL * v4);
v6 = 6.283185307179586 / (double)v4;
sincosf(v6, sinx, &cosx);
v7 = cosx;
v8 = sinx[0];
v9 = v5;
result = 0.0;
do
{
v10 = x;
*v9 = v12 + x;
v9 += 2;
*(v9 - 1) = a2 + result;
x = (float)(v8 * result) + (float)(x * v7);
result = (float)(result * v7) - (float)(v10 * v8);
}
while ( &v5[2 * v4] != v9 );
_glewBufferData(34962LL, 8LL * v4, v5, 35040LL);
glDrawArrays(2LL, 0LL, (unsigned int)v4);
free(v5);
_glewMapBufferRange(34962LL, 0LL, 0LL, 42LL);
_glewUnmapBuffer(34962LL);
return result;
}

canonical_decompiled_code:
float __fastcall func9(float result, float a2, float a3)
{
float v3; // xmm0_4
int v4; // ebx
float *v5; // rbp
float v6; // xmm0_4
float v7; // xmm3_4
float v8; // xmm2_4
float *v9; // rax
float v10; // xmm6_4
float x; // [rsp+Ch] [rbp-2Ch]
float v12; // [rsp+14h] [rbp-24h]
float cosx; // [rsp+18h] [rbp-20h] BYREF
float sinx[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v12 = result;
x = a3;
if ( result <= 0.0 )
{
result = -1.0 - a3;
if ( (float)(-1.0 - a3) > v12 )
return result;
}
else if ( result > (float)(a3 + 1.0) )
{
return result;
}
if ( a2 <= 0.0 )
{
result = -1.0 - a3;
if ( (float)(-1.0 - a3) > a2 )
return result;
}
else
{
result = a3 + 1.0;
if ( a2 > (float)(a3 + 1.0) )
return result;
}
if ( a3 < 0.0 )
v3 = sqrtf(a3);
else
v3 = fsqrt(a3);
v4 = (int)(float)(v3 * 60.0);
if ( v4 < 4 )
v4 = 4;
v5 = (float *)malloc(8LL * v4);
v6 = 6.283185307179586 / (double)v4;
sincosf(v6, sinx, &cosx);
v7 = cosx;
v8 = sinx[0];
v9 = v5;
result = 0.0;
do
{
v10 = x;
*v9 = v12 + x;
v9 += 2;
*(v9 - 1) = a2 + result;
x = (float)(v8 * result) + (float)(x * v7);
result = (float)(result * v7) - (float)(v10 * v8);
}
while ( &v5[2 * v4] != v9 );
_glewBufferData(34962LL, 8LL * v4, v5, 35040LL);
glDrawArrays(2LL, 0LL, (unsigned int)v4);
free(v5);
_glewMapBufferRange(34962LL, 0LL, 0LL, 42LL);
_glewUnmapBuffer(34962LL);
return result;
}

original_code:
void drawCircle(float cx, float cy, float r)
{
 if (cx > 0) {
  if (cx > 1 + r)
   return;
 } else {
  if (cx < -1 - r)
   return;
 }
 if (cy > 0) {
  if (cy > 1 + r)
   return;
 } else {
  if (cy < -1 - r)
   return;
 }
 int numSegments = (int) (60 * sqrtf(r));
 if (numSegments < 4)
  numSegments = 4;
 float *points = malloc(numSegments * 2 * sizeof(float));
 float *current = points;
 float t = 2 * 3.14159265358979323846 / numSegments;
 float myCos = cosf(t);
 float mySin = sinf(t);
 float x = r;
 float y = 0;
 int count = numSegments;
 for (; count > 0; count--) {
  *(current++) = cx + x;
  *(current++) = cy + y;
  t = x;
  x = myCos * x + mySin * y;
  y = myCos * y - mySin * t;
 }
 __glewBufferData(0x8892, sizeof(float) * 2 * numSegments,
       points, 0x88E0);
 glDrawArrays(0x0002, 0, numSegments);
 free(points);
 __glewMapBufferRange(0x8892, 0, 0,
    0x0002 | 0x0020 |
    0x0008);
 __glewUnmapBuffer(0x8892);
}

variable_types: cx float

variable_types: cy float

variable_types: numSegments int

variable_types:
points
float *

variable_types:
current
float *

variable_types: t float

variable_types: myCos float

variable_types: mySin float

variable_types: x float

variable_types: y float


newConnectionLong

decompiled_code:
void __fastcall newConnectionLong(int a1, int a2, int a3, double a4, double a5, double a6, double a7, double a8)
{
__int64 v9; // rbx

v9 = *(_QWORD *)(nodes + 88LL * a1 + 72) + 56LL * a2;
*(_BYTE *)v9 = 0;
*(_DWORD *)(v9 + 4) = a3;
*(double *)(v9 + 8) = a5;
*(double *)(v9 + 16) = a6;
*(double *)(v9 + 24) = a7;
*(double *)(v9 + 32) = pow(a4, 0.7) - 1.0;
*(double *)(v9 + 40) = 0.7 * a8;
}

original_code:
void newConnectionLong(int node, int con, int id, double fric,
         double prefLen, double mid, double tol,
         double force)
{
 connection *who = nodes[node].connections + con;
 who->dead = 0;
 who->id = id;
 who->preflength = prefLen;
 who->midlength = mid;
 who->tolerance = tol;
 who->friction = pow(fric, 0.7) - 1;
 who->force = force * 0.7;
}

canonical_original_code:
void newConnectionLong(int node, int con, int id, double fric, double prefLen, double mid, double tol, double force)
{
 struct connection *who = nodes[node].connections + con;
 who->dead = 0;
 who->id = id;
 who->preflength = prefLen;
 who->midlength = mid;
 who->tolerance = tol;
 who->friction = pow(fric, 0.7) - 1;
 who->force = force * 0.7;
}

variable_types: node int

variable_types: con int

variable_types: id int

variable_types: fric double

variable_types: prefLen double

variable_types: mid double

variable_types: tol double

variable_types: force double

variable_types: struct connection { char dead; int id; double preflength; double midlength; double tolerance; double friction; double force; unsigned char hue; } *


newConnection

decompiled_code:
void __fastcall newConnection(int a1, int a2, int a3, double a4, double a5, double a6, double a7)
{
newConnectionLong(a1, a2, a3, a4, a5, a5, a6, a7);
}

canonical_decompiled_code:
void __fastcall func1(int a1, int a2, int a3, double a4, double a5, double a6, double a7)
{
func0(a1, a2, a3, a4, a5, a5, a6, a7);
}

original_code:
void newConnection(int node, int con, int id, double fric, double len,
     double tol, double force)
{
 newConnectionLong(node, con, id, fric, len, len, tol, force);
}

variable_types: len double


newNodeLong

original_code:
int newNodeLong(long X, long Y, double Px, double Py, double Xm, double Ym,
  double S, double M, int array)
{
 int ret = addNode();
 node *who = nodes + ret;
 who->dead = 0;
 who->x = X;
 who->y = Y;
 who->px = Px;
 who->py = Py;
 who->xmom = Xm;
 who->ymom = Ym;
 who->size = S;
 who->mass = M;
 who->numConnections = array;
 who->connections =
     (connection *) malloc(array * sizeof(connection));
 return ret;
}

canonical_original_code:
int newNodeLong(long X, long Y, double Px, double Py, double Xm, double Ym, double S, double M, int array)
{
 int ret = addNode();
 struct node *who = nodes + ret;
 who->dead = 0;
 who->x = X;
 who->y = Y;
 who->px = Px;
 who->py = Py;
 who->xmom = Xm;
 who->ymom = Ym;
 who->size = S;
 who->mass = M;
 who->numConnections = array;
 who->connections =
     (struct connection *) malloc(array * sizeof(connection));
 return ret;
}

variable_types: X long

variable_types: Y long

variable_types: Px double

variable_types: Py double

variable_types: Xm double

variable_types: Ym double

variable_types: S double

variable_types: M double

variable_types: array int

variable_types: ret int

variable_types: struct node { int netIndex; char dead; long x; long y; double px; double py; double xmom; double ymom; double size; double mass; struct connection { char dead; int id; double preflength; double midlength; double tolerance; double friction; double force; unsigned char hue; } *connections; int numConnections; } *

user_defined_types: struct node { int netIndex; char dead; long x; long y; double px; double py; double xmom; double ymom; double size; double mass; struct connection *connections; int numConnections; }


newNode

decompiled_code:
__int64 __fastcall newNode(int a1, int a2, int a3, double a4, double a5)
{
return newNodeLong(a1, a2, a3, 0.0, 0.0, 0.0, 0.0, a4, a5);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3, double a4, double a5)
{
return func2(a1, a2, a3, 0.0, 0.0, 0.0, 0.0, a4, a5);
}

original_code:
int newNode(int x, int y, double size, double mass, int array)
{
 return newNodeLong((long) x, (long) y, (double) 0, (double) 0, 0,
      0, size, mass, array);
}

variable_types: x int

variable_types: y int

variable_types: size double

variable_types: mass double


createConnection

decompiled_code:
__int64 __fastcall createConnection(int a1)
{
__int64 v1; // rbp
int v2; // eax

v1 = nodes + 88LL * a1;
v2 = *(_DWORD *)(v1 + 80) + 1;
*(_DWORD *)(v1 + 80) = v2;
*(_QWORD *)(v1 + 72) = realloc(*(void **)(v1 + 72), 56LL * v2);
return (unsigned int)(*(_DWORD *)(nodes + 88LL * a1 + 80) - 1);
}

original_code:
int createConnection(int who)
{
 nodes[who].connections =
     (connection *) realloc(nodes[who].connections,
       (++nodes[who].numConnections) *
       sizeof(connection));
 return nodes[who].numConnections - 1;
}

canonical_original_code:
int createConnection(int who)
{
 nodes[who].connections =
     (struct connection *) realloc(nodes[who].connections,
       (++nodes[who].numConnections) *
       sizeof(connection));
 return nodes[who].numConnections - 1;
}

variable_types: who int

user_defined_types: struct connection { char dead; int id; double preflength; double midlength; double tolerance; double friction; double force; unsigned char hue; }


positioncleanup

original_code:
void positioncleanup(node * who)
{
 who->px += who->xmom;
 int n = floor(who->px);
 who->x += n;
 who->px -= n;
 who->py += who->ymom;
 n = floor(who->py);
 who->y += n;
 who->py -= n;
}

canonical_original_code:
void positioncleanup(struct node *who)
{
 who->px += who->xmom;
 int n = floor(who->px);
 who->x += n;
 who->px -= n;
 who->py += who->ymom;
 n = floor(who->py);
 who->y += n;
 who->py -= n;
}

variable_types: n int


drawText

decompiled_code:
__int64 __fastcall drawText(int a1, int a2, char *a3, float a4)
{
__int64 result; // rax
char *v5; // r14
int v6; // er15
int i; // er13
double v8; // xmm0_8
int v9; // ebp
int j; // ebx
double v11; // xmm4_8
int v12; // eax
char v13; // r12
float v14; // [rsp+8h] [rbp-50h]
float v15; // [rsp+Ch] [rbp-4Ch]
float v16; // [rsp+10h] [rbp-48h]
float v17; // [rsp+18h] [rbp-40h]
float v18; // [rsp+1Ch] [rbp-3Ch]

v18 = (float)a1 / (float)width2;
v17 = (float)a2 / (float)height2;
v15 = a4 / (float)width2;
result = (unsigned __int8)*a3;
if ( (_BYTE)result )
{
v5 = a3;
v6 = -1;
do
{
if ( (_BYTE)result == 10 )
{
v17 = v17 - (float)(v15 * 9.0);
v6 = -1;
}
else
{
++v6;
v16 = v17;
for ( i = 0; i != 8; ++i )
{
v13 = gfxPrimitivesFontdata[8 * *v5 + i];
*(_QWORD *)&v8 = COERCE_UNSIGNED_INT((float)((float)(9 * v6) * v15) + v18);
v9 = -128;
for ( j = 0; j <= 7; ++j )
{
if ( ((unsigned __int8)v9 & (unsigned __int8)v13) != 0 )
{
v14 = *(float *)&v8;
do
{
*(_QWORD *)&v11 = LODWORD(v14);
*(float *)&v11 = v14 + v15;
v14 = v14 + v15;
v12 = v9;
LOBYTE(v12) = (unsigned __int8)v9 >> 1;
v9 = v12;
++j;
}
while ( ((unsigned __int8)v12 & (unsigned __int8)v13) != 0 );
drawBox(v8, v16, v11, v15 + v16);
*(_QWORD *)&v8 = LODWORD(v14);
}
*(float *)&v8 = *(float *)&v8 + v15;
LOBYTE(v9) = (unsigned __int8)v9 >> 1;
}
v16 = v16 - v15;
}
}
result = (unsigned __int8)*++v5;
}
while ( (_BYTE)result );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, char *a3, float a4)
{
__int64 result; // rax
char *v5; // r14
int v6; // er15
int i; // er13
double v8; // xmm0_8
int v9; // ebp
int j; // ebx
double v11; // xmm4_8
int v12; // eax
char v13; // r12
float v14; // [rsp+8h] [rbp-50h]
float v15; // [rsp+Ch] [rbp-4Ch]
float v16; // [rsp+10h] [rbp-48h]
float v17; // [rsp+18h] [rbp-40h]
float v18; // [rsp+1Ch] [rbp-3Ch]

v18 = (float)a1 / (float)width2;
v17 = (float)a2 / (float)height2;
v15 = a4 / (float)width2;
result = (unsigned __int8)*a3;
if ( (_BYTE)result )
{
v5 = a3;
v6 = -1;
do
{
if ( (_BYTE)result == 10 )
{
v17 = v17 - (float)(v15 * 9.0);
v6 = -1;
}
else
{
++v6;
v16 = v17;
for ( i = 0; i != 8; ++i )
{
v13 = gfxPrimitivesFontdata[8 * *v5 + i];
*(_QWORD *)&v8 = COERCE_UNSIGNED_INT((float)((float)(9 * v6) * v15) + v18);
v9 = -128;
for ( j = 0; j <= 7; ++j )
{
if ( ((unsigned __int8)v9 & (unsigned __int8)v13) != 0 )
{
v14 = *(float *)&v8;
do
{
*(_QWORD *)&v11 = LODWORD(v14);
*(float *)&v11 = v14 + v15;
v14 = v14 + v15;
v12 = v9;
LOBYTE(v12) = (unsigned __int8)v9 >> 1;
v9 = v12;
++j;
}
while ( ((unsigned __int8)v12 & (unsigned __int8)v13) != 0 );
drawBox(v8, v16, v11, v15 + v16);
*(_QWORD *)&v8 = LODWORD(v14);
}
*(float *)&v8 = *(float *)&v8 + v15;
LOBYTE(v9) = (unsigned __int8)v9 >> 1;
}
v16 = v16 - v15;
}
}
result = (unsigned __int8)*++v5;
}
while ( (_BYTE)result );
}
return result;
}

original_code:
void drawText(int X, int Y, float size, char *string)
{
 float x = (float) X / width2;
 float y = (float) Y / height2;
 size /= width2;
 int j = -1;
 int i = -1;
 int y2;
 int x2;
 register uint8_t row;
 register uint8_t test;
 float tempx, tempy;
 while (string[++j] != '\0') {
  i++;
  if (string[j] == '\n') {
   i = -1;
   y -= size * 9;
   continue;
  }
  tempy = y;
  for (y2 = 0; y2 < 8; y2++) {
   row = gfxPrimitivesFontdata[8 * string[j] + y2];
   test = 128;
   tempx = x + i * 9 * size;
   for (x2 = 0; x2 < 8; x2++) {
    if (row & test) {
     float oldX = tempx;
     do {
      tempx += size;
      test /= 2;
      x2++;
     } while (row & test);
     drawBox(oldX, tempy, tempx,
      tempy + size);
    }
    tempx += size;
    test /= 2;
   }
   tempy -= size;
  }
 }
}

canonical_original_code:
void drawText(int X, int Y, float size, char *string)
{
 float x = (float) X / width2;
 float y = (float) Y / height2;
 size /= width2;
 int j = -1;
 int i = -1;
 int y2;
 int x2;
 register unsigned char row;
 register unsigned char test;
 float tempx; float tempy;
 while (string[++j] != '\0') {
  i++;
  if (string[j] == '\n') {
   i = -1;
   y -= size * 9;
   continue;
  }
  tempy = y;
  for (y2 = 0; y2 < 8; y2++) {
   row = gfxPrimitivesFontdata[8 * string[j] + y2];
   test = 128;
   tempx = x + i * 9 * size;
   for (x2 = 0; x2 < 8; x2++) {
    if (row & test) {
     float oldX = tempx;
     do {
      tempx += size;
      test /= 2;
      x2++;
     } while (row & test);
     drawBox(oldX, tempy, tempx,
      tempy + size);
    }
    tempx += size;
    test /= 2;
   }
   tempy -= size;
  }
 }
}

variable_types: X int

variable_types: Y int

variable_types: size float

variable_types:
string
char *

variable_types: x float

variable_types: y float

variable_types: j int

variable_types: i int

variable_types:
row
unsigned char

variable_types:
test
unsigned char

variable_types: tempx float

variable_types: tempy float

variable_types: oldX float


print

decompiled_code:
int __fastcall print(int a1)
{
int result; // eax

result = a1 % 4;
if ( a1 % 4 == 2 )
{
fwrite(&unk_40200A, 1uLL, 2uLL, _bss_start);
result = fflush(_bss_start);
}
else if ( result > 2 )
{
fwrite(&unk_40200D, 1uLL, 2uLL, _bss_start);
result = fflush(_bss_start);
}
else if ( (a1 & 3) != 0 )
{
if ( result == 1 )
{
fwrite(&unk_402007, 1uLL, 2uLL, _bss_start);
result = fflush(_bss_start);
}
}
else
{
fwrite(&unk_402004, 1uLL, 2uLL, _bss_start);
result = fflush(_bss_start);
}
return result;
}

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

result = a1 % 4;
if ( a1 % 4 == 2 )
{
fwrite(&unk_40200A, 1uLL, 2uLL, _bss_start);
result = fflush(_bss_start);
}
else if ( result > 2 )
{
fwrite(&unk_40200D, 1uLL, 2uLL, _bss_start);
result = fflush(_bss_start);
}
else if ( (a1 & 3) != 0 )
{
if ( result == 1 )
{
fwrite(&unk_402007, 1uLL, 2uLL, _bss_start);
result = fflush(_bss_start);
}
}
else
{
fwrite(&unk_402004, 1uLL, 2uLL, _bss_start);
result = fflush(_bss_start);
}
return result;
}

original_code:
void print(int spin) {
    switch (spin%4) {
    case 0:
      fprintf(stdout, "\b|");
      fflush(stdout);
      break;
    case 1:
      fprintf(stdout, "\b/");
      fflush(stdout);
      break;
    case 2:
      fprintf(stdout, "\b-");
      fflush(stdout);
      break;
    case 3:
      fprintf(stdout, "\b\\");
      fflush(stdout);
      break;
    }
    return;
}

variable_types: spin int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // ebp
int v6; // ebx
__int64 v7; // rbx
int v8; // er14
int *v10; // r12
char *v11; // rbx
int *v12; // r12
char *v13; // rbx
int *v14; // r15
int v15; // [rsp+8h] [rbp-80h]
int v16; // [rsp+Ch] [rbp-7Ch]
struct timespec requested_time; // [rsp+10h] [rbp-78h] BYREF
char v18[4]; // [rsp+2Ah] [rbp-5Eh] BYREF
char buf; // [rsp+2Eh] [rbp-5Ah] BYREF
char v20; // [rsp+2Fh] [rbp-59h]
int v21[5]; // [rsp+30h] [rbp-58h] BYREF
char v22[68]; // [rsp+44h] [rbp-44h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 500000000LL;
v18[0] = 0;
v18[1] = 1;
v18[2] = 2;
v18[3] = 18;
v21[0] = open("/dev/dio0", 2, envp);
v3 = open("/dev/dio1", 2);
v21[1] = v3;
v4 = open("/dev/dio2", 2);
v21[2] = v4;
v5 = open("/dev/dio3", 2);
v21[3] = v5;
v6 = open("/dev/dio4", 2);
v21[4] = v6;
v20 = 3;
buf = 0x80;
write(v21[0], &buf, 2uLL);
write(v3, &buf, 2uLL);
write(v4, &buf, 2uLL);
write(v5, &buf, 2uLL);
write(v6, &buf, 2uLL);
v7 = 0LL;
v16 = 0;
do
{
if ( !v21[v7] )
{
fprintf(_bss_start, "Device %d failed to open\n", (unsigned int)v7);
v16 = -1;
}
++v7;
}
while ( v7 != 5 );
v8 = v16;
if ( !v16 )
{
fwrite("Checking\n", 1uLL, 9uLL, _bss_start);
fwrite("-> ", 1uLL, 4uLL, _bss_start);
fflush(_bss_start);
do
{
v14 = v21;
v10 = v21;
do
{
buf = 0;
v11 = v18;
do
{
v20 = *v11;
write(*v10, &buf, 2uLL);
++v11;
}
while ( v11 != &buf );
++v10;
}
while ( v10 != (int *)v22 );
nanosleep(&requested_time, 0LL);
v15 = v8 + 1;
print(v8);
v12 = v21;
do
{
buf = -1;
v13 = v18;
do
{
v20 = *v13;
write(*v12, &buf, 2uLL);
++v13;
}
while ( v13 != &buf );
++v12;
}
while ( v12 != (int *)v22 );
nanosleep(&requested_time, 0LL);
v8 += 2;
print(v15);
}
while ( v8 != 62 );
fwrite("\bDone!\n", 1uLL, 7uLL, _bss_start);
fflush(_bss_start);
do
close(*v14++);
while ( v14 != (int *)v22 );
}
return v16;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
int v4; // er12
int v5; // ebp
int v6; // ebx
__int64 v7; // rbx
int v8; // er14
int *v10; // r12
char *v11; // rbx
int *v12; // r12
char *v13; // rbx
int *v14; // r15
int v15; // [rsp+8h] [rbp-80h]
int v16; // [rsp+Ch] [rbp-7Ch]
struct timespec requested_time; // [rsp+10h] [rbp-78h] BYREF
char v18[4]; // [rsp+2Ah] [rbp-5Eh] BYREF
char buf; // [rsp+2Eh] [rbp-5Ah] BYREF
char v20; // [rsp+2Fh] [rbp-59h]
int v21[5]; // [rsp+30h] [rbp-58h] BYREF
char v22[68]; // [rsp+44h] [rbp-44h] BYREF

requested_time.tv_sec = 0LL;
requested_time.tv_nsec = 500000000LL;
v18[0] = 0;
v18[1] = 1;
v18[2] = 2;
v18[3] = 18;
v21[0] = open("/dev/dio0", 2, envp);
v3 = open("/dev/dio1", 2);
v21[1] = v3;
v4 = open("/dev/dio2", 2);
v21[2] = v4;
v5 = open("/dev/dio3", 2);
v21[3] = v5;
v6 = open("/dev/dio4", 2);
v21[4] = v6;
v20 = 3;
buf = 0x80;
write(v21[0], &buf, 2uLL);
write(v3, &buf, 2uLL);
write(v4, &buf, 2uLL);
write(v5, &buf, 2uLL);
write(v6, &buf, 2uLL);
v7 = 0LL;
v16 = 0;
do
{
if ( !v21[v7] )
{
fprintf(_bss_start, "Device %d failed to open\n", (unsigned int)v7);
v16 = -1;
}
++v7;
}
while ( v7 != 5 );
v8 = v16;
if ( !v16 )
{
fwrite("Checking\n", 1uLL, 9uLL, _bss_start);
fwrite("-> ", 1uLL, 4uLL, _bss_start);
fflush(_bss_start);
do
{
v14 = v21;
v10 = v21;
do
{
buf = 0;
v11 = v18;
do
{
v20 = *v11;
write(*v10, &buf, 2uLL);
++v11;
}
while ( v11 != &buf );
++v10;
}
while ( v10 != (int *)v22 );
nanosleep(&requested_time, 0LL);
v15 = v8 + 1;
func7(v8);
v12 = v21;
do
{
buf = -1;
v13 = v18;
do
{
v20 = *v13;
write(*v12, &buf, 2uLL);
++v13;
}
while ( v13 != &buf );
++v12;
}
while ( v12 != (int *)v22 );
nanosleep(&requested_time, 0LL);
v8 += 2;
func7(v15);
}
while ( v8 != 62 );
fwrite("\bDone!\n", 1uLL, 7uLL, _bss_start);
fflush(_bss_start);
do
close(*v14++);
while ( v14 != (int *)v22 );
}
return v16;
}

original_code:
int main(void) {
  int group[5], i, j, err = 0, dur = 0, spin = 0;
  unsigned char zero_byte = 0x00, full_byte = 0xff;
  unsigned char write_msg[2], port[4];
  struct timespec pause;
  pause.tv_sec = 0;
  pause.tv_nsec = 500000000;
  port[0] = 0x00;
  port[1] = 0x01;
  port[2] = 0x02;
  port[3] = 0x12;
  group[0] = open("/dev/dio0", 02);
  group[1] = open("/dev/dio1", 02);
  group[2] = open("/dev/dio2", 02);
  group[3] = open("/dev/dio3", 02);
  group[4] = open("/dev/dio4", 02);
  write_msg[1] = 0x03;
  write_msg[0] = 0x80;
  write(group[0], write_msg, 2);
  write(group[1], write_msg, 2);
  write(group[2], write_msg, 2);
  write(group[3], write_msg, 2);
  write(group[4], write_msg, 2);
  for ( i = 0; i < 5; i++ ) {
    if (!group[i]) {
      fprintf(stdout, "Device %d failed to open\n", i);
      err = -1;
    }
  }
  if (err)
    return err;
  fprintf(stdout, "Checking\n");
  fprintf(stdout, "->  ");
  fflush(stdout);
  while (1) {
    for ( i = 0; i < 5; i++) {
      write_msg[0] = zero_byte;
      for ( j = 0; j < 4; j++) {
 write_msg[1] = port[j];
 write(group[i], write_msg, 2);
      }
    }
    nanosleep(&pause, ((void *)0));
    print(spin++);
    for ( i = 0; i < 5; i++) {
      write_msg[0] = full_byte;
      for ( j = 0; j < 4; j++) {
 write_msg[1] = port[j];
 write(group[i], write_msg, 2);
      }
    }
    nanosleep(&pause, ((void *)0));
    print(spin++);
    if (dur++ >= 30)
      break;
  }
  fprintf(stdout, "\bDone!\n");
  fflush(stdout);
  for (i = 0; i < 5; i++)
    close(group[i]);
  return 0;
}

canonical_original_code:
int main() {
  int group[5]; int i; int j; int err = 0; int dur = 0; int spin = 0;
  unsigned char zero_byte = 0x00; unsigned char full_byte = 0xff;
  unsigned char write_msg[2]; unsigned char port[4];
  struct timespec pause;
  pause.tv_sec = 0;
  pause.tv_nsec = 500000000;
  port[0] = 0x00;
  port[1] = 0x01;
  port[2] = 0x02;
  port[3] = 0x12;
  group[0] = open("/dev/dio0", 02);
  group[1] = open("/dev/dio1", 02);
  group[2] = open("/dev/dio2", 02);
  group[3] = open("/dev/dio3", 02);
  group[4] = open("/dev/dio4", 02);
  write_msg[1] = 0x03;
  write_msg[0] = 0x80;
  write(group[0], write_msg, 2);
  write(group[1], write_msg, 2);
  write(group[2], write_msg, 2);
  write(group[3], write_msg, 2);
  write(group[4], write_msg, 2);
  for ( i = 0; i < 5; i++ ) {
    if (!group[i]) {
      fprintf(stdout, "Device %d failed to open\n", i);
      err = -1;
    }
  }
  if (err)
    return err;
  fprintf(stdout, "Checking\n");
  fprintf(stdout, "->  ");
  fflush(stdout);
  while (1) {
    for ( i = 0; i < 5; i++) {
      write_msg[0] = zero_byte;
      for ( j = 0; j < 4; j++) {
 write_msg[1] = port[j];
 write(group[i], write_msg, 2);
      }
    }
    nanosleep(&pause, ((void *)0));
    print(spin++);
    for ( i = 0; i < 5; i++) {
      write_msg[0] = full_byte;
      for ( j = 0; j < 4; j++) {
 write_msg[1] = port[j];
 write(group[i], write_msg, 2);
      }
    }
    nanosleep(&pause, ((void *)0));
    print(spin++);
    if (dur++ >= 30)
      break;
  }
  fprintf(stdout, "\bDone!\n");
  fflush(stdout);
  for (i = 0; i < 5; i++)
    close(group[i]);
  return 0;
}

variable_types:
group
int [5]

variable_types: err int

variable_types: dur int

variable_types:
port
unsigned char [4]

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 get_input()
{
char v0; // bp
int v1; // ebx
__int64 result; // rax
bool v3; // bp
unsigned __int8 v4; // dl
int v5; // eax
_BYTE v6[20]; // [rsp+0h] [rbp-38h] BYREF
unsigned __int8 buf; // [rsp+1Eh] [rbp-1Ah] BYREF
char v8; // [rsp+1Fh] [rbp-19h]

fwrite("input group (0-4) > ", 1uLL, 0x14uLL, stdout);
fflush(stdout);
fgets(v6, 20, stdin);
v0 = v6[0];
if ( v6[0] == 113 )
return 4294967287LL;
v1 = atoi(v6);
result = 1LL;
v3 = v1 == 0 && v0 != 48;
if ( !v3 )
{
*(_QWORD *)v6 = 0LL;
*(_QWORD *)&v6[8] = 0LL;
*(_DWORD *)&v6[16] = 0;
if ( (unsigned int)v1 <= 4 )
{
fwrite("input port (a,b,c,d) > ", 1uLL, 0x18uLL, stdout);
fflush(stdout);
fgets(v6, 20, stdin);
*(_OWORD *)&v6[1] = 0uLL;
*(_WORD *)&v6[17] = 0;
v6[19] = 0;
switch ( v6[0] )
{
case 'a':
v8 = 0;
goto LABEL_8;
case 'b':
v8 = 1;
goto LABEL_8;
case 'c':
v8 = 2;
goto LABEL_8;
case 'd':
v8 = 18;
LABEL_8:
fwrite("input hex data > ", 1uLL, 0x11uLL, stdout);
fflush(stdout);
buf = 0;
fgets(v6, 20, stdin);
v4 = buf;
switch ( v6[1] )
{
case '0':
goto LABEL_14;
case '1':
v4 = buf | 1;
v3 = 1;
goto LABEL_14;
case '2':
v4 = buf | 2;
v3 = 1;
goto LABEL_14;
case '3':
v4 = buf | 3;
v3 = 1;
goto LABEL_14;
case '4':
v4 = buf | 4;
v3 = 1;
goto LABEL_14;
case '5':
v4 = buf | 5;
v3 = 1;
goto LABEL_14;
case '6':
v4 = buf | 6;
v3 = 1;
goto LABEL_14;
case '7':
v4 = buf | 7;
v3 = 1;
goto LABEL_14;
case '8':
v4 = buf | 8;
v3 = 1;
goto LABEL_14;
case '9':
v4 = buf | 9;
v3 = 1;
goto LABEL_14;
case 'A':
case 'a':
v4 = buf | 0xA;
v3 = 1;
goto LABEL_14;
case 'B':
case 'b':
v4 = buf | 0xB;
v3 = 1;
goto LABEL_14;
case 'C':
case 'c':
v4 = buf | 0xC;
v3 = 1;
goto LABEL_14;
case 'D':
case 'd':
v4 = buf | 0xD;
v3 = 1;
goto LABEL_14;
case 'E':
case 'e':
v4 = buf | 0xE;
v3 = 1;
goto LABEL_14;
case 'F':
case 'f':
v4 = buf | 0xF;
v3 = 1;
LABEL_14:
switch ( v6[0] )
{
case '0':
if ( v3 )
goto LABEL_35;
goto LABEL_36;
case '1':
v5 = 0;
goto LABEL_32;
case '2':
v5 = 0;
goto LABEL_39;
case '3':
v5 = 0;
goto LABEL_42;
case '4':
v5 = 0;
goto LABEL_45;
case '5':
v5 = 0;
goto LABEL_48;
case '6':
v5 = 0;
goto LABEL_51;
case '7':
v5 = 0;
goto LABEL_54;
case '8':
v5 = 0;
goto LABEL_57;
case '9':
v5 = 0;
goto LABEL_60;
case 'A':
case 'a':
v5 = 0;
goto LABEL_63;
case 'B':
case 'b':
v5 = 0;
goto LABEL_66;
case 'C':
case 'c':
v5 = 0;
goto LABEL_69;
case 'D':
case 'd':
v5 = 0;
goto LABEL_72;
case 'E':
case 'e':
v5 = 0;
goto LABEL_75;
case 'F':
case 'f':
v5 = 0;
goto LABEL_78;
case 'q':
result = 0xFFFFFFFFLL;
break;
default:
result = 1LL;
break;
}
break;
case 'q':
result = 0xFFFFFFFFLL;
break;
default:
switch ( v6[0] )
{
case '0':
goto LABEL_34;
case '1':
v5 = 1;
LABEL_32:
v4 |= 0x10u;
goto LABEL_33;
case '2':
v5 = 1;
LABEL_39:
v4 |= 0x20u;
goto LABEL_33;
case '3':
v5 = 1;
LABEL_42:
v4 |= 0x30u;
goto LABEL_33;
case '4':
v5 = 1;
LABEL_45:
v4 |= 0x40u;
goto LABEL_33;
case '5':
v5 = 1;
LABEL_48:
v4 |= 0x50u;
goto LABEL_33;
case '6':
v5 = 1;
LABEL_51:
v4 |= 0x60u;
goto LABEL_33;
case '7':
v5 = 1;
LABEL_54:
v4 |= 0x70u;
goto LABEL_33;
case '8':
v5 = 1;
LABEL_57:
v4 |= 0x80u;
goto LABEL_33;
case '9':
v5 = 1;
LABEL_60:
v4 |= 0x90u;
goto LABEL_33;
case 'A':
case 'a':
v5 = 1;
LABEL_63:
v4 |= 0xA0u;
goto LABEL_33;
case 'B':
case 'b':
v5 = 1;
LABEL_66:
v4 |= 0xB0u;
goto LABEL_33;
case 'C':
case 'c':
v5 = 1;
LABEL_69:
v4 |= 0xC0u;
goto LABEL_33;
case 'D':
case 'd':
v5 = 1;
LABEL_72:
v4 |= 0xD0u;
goto LABEL_33;
case 'E':
case 'e':
v5 = 1;
LABEL_75:
v4 |= 0xE0u;
goto LABEL_33;
case 'F':
case 'f':
v5 = 1;
LABEL_78:
v4 |= 0xF0u;
LABEL_33:
if ( v5 )
LABEL_34:
v4 >>= 4;
LABEL_35:
buf = v4;
LABEL_36:
*(_QWORD *)v6 = 0LL;
*(_QWORD *)&v6[8] = 0LL;
*(_DWORD *)&v6[16] = 0;
write(*(&dev + v1), &buf, 2uLL);
result = 0LL;
break;
case 'q':
result = 0xFFFFFFFFLL;
break;
default:
result = 1LL;
break;
}
break;
}
break;
case 'q':
result = 4294967293LL;
break;
default:
result = 1LL;
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
char v0; // bp
int v1; // ebx
__int64 result; // rax
bool v3; // bp
unsigned __int8 v4; // dl
int v5; // eax
_BYTE v6[20]; // [rsp+0h] [rbp-38h] BYREF
unsigned __int8 buf; // [rsp+1Eh] [rbp-1Ah] BYREF
char v8; // [rsp+1Fh] [rbp-19h]

fwrite("input group (0-4) > ", 1uLL, 0x14uLL, stdout);
fflush(stdout);
fgets(v6, 20, stdin);
v0 = v6[0];
if ( v6[0] == 113 )
return 4294967287LL;
v1 = atoi(v6);
result = 1LL;
v3 = v1 == 0 && v0 != 48;
if ( !v3 )
{
*(_QWORD *)v6 = 0LL;
*(_QWORD *)&v6[8] = 0LL;
*(_DWORD *)&v6[16] = 0;
if ( (unsigned int)v1 <= 4 )
{
fwrite("input port (a,b,c,d) > ", 1uLL, 0x18uLL, stdout);
fflush(stdout);
fgets(v6, 20, stdin);
*(_OWORD *)&v6[1] = 0uLL;
*(_WORD *)&v6[17] = 0;
v6[19] = 0;
switch ( v6[0] )
{
case 'a':
v8 = 0;
goto LABEL_8;
case 'b':
v8 = 1;
goto LABEL_8;
case 'c':
v8 = 2;
goto LABEL_8;
case 'd':
v8 = 18;
LABEL_8:
fwrite("input hex data > ", 1uLL, 0x11uLL, stdout);
fflush(stdout);
buf = 0;
fgets(v6, 20, stdin);
v4 = buf;
switch ( v6[1] )
{
case '0':
goto LABEL_14;
case '1':
v4 = buf | 1;
v3 = 1;
goto LABEL_14;
case '2':
v4 = buf | 2;
v3 = 1;
goto LABEL_14;
case '3':
v4 = buf | 3;
v3 = 1;
goto LABEL_14;
case '4':
v4 = buf | 4;
v3 = 1;
goto LABEL_14;
case '5':
v4 = buf | 5;
v3 = 1;
goto LABEL_14;
case '6':
v4 = buf | 6;
v3 = 1;
goto LABEL_14;
case '7':
v4 = buf | 7;
v3 = 1;
goto LABEL_14;
case '8':
v4 = buf | 8;
v3 = 1;
goto LABEL_14;
case '9':
v4 = buf | 9;
v3 = 1;
goto LABEL_14;
case 'A':
case 'a':
v4 = buf | 0xA;
v3 = 1;
goto LABEL_14;
case 'B':
case 'b':
v4 = buf | 0xB;
v3 = 1;
goto LABEL_14;
case 'C':
case 'c':
v4 = buf | 0xC;
v3 = 1;
goto LABEL_14;
case 'D':
case 'd':
v4 = buf | 0xD;
v3 = 1;
goto LABEL_14;
case 'E':
case 'e':
v4 = buf | 0xE;
v3 = 1;
goto LABEL_14;
case 'F':
case 'f':
v4 = buf | 0xF;
v3 = 1;
LABEL_14:
switch ( v6[0] )
{
case '0':
if ( v3 )
goto LABEL_35;
goto LABEL_36;
case '1':
v5 = 0;
goto LABEL_32;
case '2':
v5 = 0;
goto LABEL_39;
case '3':
v5 = 0;
goto LABEL_42;
case '4':
v5 = 0;
goto LABEL_45;
case '5':
v5 = 0;
goto LABEL_48;
case '6':
v5 = 0;
goto LABEL_51;
case '7':
v5 = 0;
goto LABEL_54;
case '8':
v5 = 0;
goto LABEL_57;
case '9':
v5 = 0;
goto LABEL_60;
case 'A':
case 'a':
v5 = 0;
goto LABEL_63;
case 'B':
case 'b':
v5 = 0;
goto LABEL_66;
case 'C':
case 'c':
v5 = 0;
goto LABEL_69;
case 'D':
case 'd':
v5 = 0;
goto LABEL_72;
case 'E':
case 'e':
v5 = 0;
goto LABEL_75;
case 'F':
case 'f':
v5 = 0;
goto LABEL_78;
case 'q':
result = 0xFFFFFFFFLL;
break;
default:
result = 1LL;
break;
}
break;
case 'q':
result = 0xFFFFFFFFLL;
break;
default:
switch ( v6[0] )
{
case '0':
goto LABEL_34;
case '1':
v5 = 1;
LABEL_32:
v4 |= 0x10u;
goto LABEL_33;
case '2':
v5 = 1;
LABEL_39:
v4 |= 0x20u;
goto LABEL_33;
case '3':
v5 = 1;
LABEL_42:
v4 |= 0x30u;
goto LABEL_33;
case '4':
v5 = 1;
LABEL_45:
v4 |= 0x40u;
goto LABEL_33;
case '5':
v5 = 1;
LABEL_48:
v4 |= 0x50u;
goto LABEL_33;
case '6':
v5 = 1;
LABEL_51:
v4 |= 0x60u;
goto LABEL_33;
case '7':
v5 = 1;
LABEL_54:
v4 |= 0x70u;
goto LABEL_33;
case '8':
v5 = 1;
LABEL_57:
v4 |= 0x80u;
goto LABEL_33;
case '9':
v5 = 1;
LABEL_60:
v4 |= 0x90u;
goto LABEL_33;
case 'A':
case 'a':
v5 = 1;
LABEL_63:
v4 |= 0xA0u;
goto LABEL_33;
case 'B':
case 'b':
v5 = 1;
LABEL_66:
v4 |= 0xB0u;
goto LABEL_33;
case 'C':
case 'c':
v5 = 1;
LABEL_69:
v4 |= 0xC0u;
goto LABEL_33;
case 'D':
case 'd':
v5 = 1;
LABEL_72:
v4 |= 0xD0u;
goto LABEL_33;
case 'E':
case 'e':
v5 = 1;
LABEL_75:
v4 |= 0xE0u;
goto LABEL_33;
case 'F':
case 'f':
v5 = 1;
LABEL_78:
v4 |= 0xF0u;
LABEL_33:
if ( v5 )
LABEL_34:
v4 >>= 4;
LABEL_35:
buf = v4;
LABEL_36:
*(_QWORD *)v6 = 0LL;
*(_QWORD *)&v6[8] = 0LL;
*(_DWORD *)&v6[16] = 0;
write(*(&dev + v1), &buf, 2uLL);
result = 0LL;
break;
case 'q':
result = 0xFFFFFFFFLL;
break;
default:
result = 1LL;
break;
}
break;
}
break;
case 'q':
result = 4294967293LL;
break;
default:
result = 1LL;
break;
}
}
}
return result;
}

original_code:
int get_input(void) {
  int grp, i, single = 0;
  unsigned char temp[2];
  char in[20];
  fputs("input group (0-4) > ", stdout);
  fflush(stdout);
  fgets(in, 20, stdin);
  if (in[0] == 'q')
    return -9;
  grp = atoi(&in[0]);
  if (!grp && in[0] != '0')
    return 1;
  memset(in, '\0', 20);
  if (grp < 0 || grp > 4)
    return 1;
  fputs("input port (a,b,c,d)  > ", stdout);
  fflush(stdout);
  fgets(in, 20, stdin);
  memset(&in[1], '\0', 19);
  switch(in[0]) {
  case 'a':
    temp[1] = 0x00;
    break;
  case 'b':
    temp[1] = 0x01;
    break;
  case 'c':
    temp[1] = 0x02;
    break;
  case 'd':
    temp[1] = 0x12;
    break;
  case 'q':
    return -3;
  default:
    return 1;
  }
  fputs("input hex data > ", stdout);
  fflush(stdout);
  temp[0] = 0x00;
  fgets(in, 20, stdin);
  for (i = 1; i >= 0; i--) {
    switch (in[i]) {
    case '0':
      temp[0] |= (0x00 >> i*4);
      break;
    case '1':
      temp[0] |= (0x10 >> i*4);
      break;
    case '2':
      temp[0] |= (0x20 >> i*4);
      break;
    case '3':
      temp[0] |= (0x30 >> i*4);
      break;
    case '4':
      temp[0] |= (0x40 >> i*4);
      break;
    case '5':
      temp[0] |= (0x50 >> i*4);
      break;
    case '6':
      temp[0] |= (0x60 >> i*4);
      break;
    case '7':
      temp[0] |= (0x70 >> i*4);
      break;
    case '8':
      temp[0] |= (0x80 >> i*4);
      break;
    case '9':
      temp[0] |= (0x90 >> i*4);
      break;
    case 'A':
    case 'a':
      temp[0] |= (0xa0 >> i*4);
      break;
    case 'B':
    case 'b':
      temp[0] |= (0xb0 >> i*4);
      break;
    case 'C':
    case 'c':
      temp[0] |= (0xc0 >> i*4);
      break;
    case 'D':
    case 'd':
      temp[0] |= (0xd0 >> i*4);
      break;
    case 'E':
    case 'e':
      temp[0] |= (0xe0 >> i*4);
      break;
    case 'F':
    case 'f':
      temp[0] |= (0xf0 >> i*4);
      break;
    case 'q':
      return -1;
    default:
      if (i) {
 single = 1;
 continue;
      }
      return 1;
    }
    if (single)
      temp[0] >>= 4;
  }
  memset(in, '\0', 20);
  write(dev[grp], temp, 2);
  return 0;
}

canonical_original_code:
int get_input() {
  int grp; int i; int single = 0;
  unsigned char temp[2];
  char in[20];
  fputs("input group (0-4) > ", stdout);
  fflush(stdout);
  fgets(in, 20, stdin);
  if (in[0] == 'q')
    return -9;
  grp = atoi(&in[0]);
  if (!grp && in[0] != '0')
    return 1;
  memset(in, '\0', 20);
  if (grp < 0 || grp > 4)
    return 1;
  fputs("input port (a,b,c,d)  > ", stdout);
  fflush(stdout);
  fgets(in, 20, stdin);
  memset(&in[1], '\0', 19);
  switch(in[0]) {
  case 'a':
    temp[1] = 0x00;
    break;
  case 'b':
    temp[1] = 0x01;
    break;
  case 'c':
    temp[1] = 0x02;
    break;
  case 'd':
    temp[1] = 0x12;
    break;
  case 'q':
    return -3;
  default:
    return 1;
  }
  fputs("input hex data > ", stdout);
  fflush(stdout);
  temp[0] = 0x00;
  fgets(in, 20, stdin);
  for (i = 1; i >= 0; i--) {
    switch (in[i]) {
    case '0':
      temp[0] |= (0x00 >> i*4);
      break;
    case '1':
      temp[0] |= (0x10 >> i*4);
      break;
    case '2':
      temp[0] |= (0x20 >> i*4);
      break;
    case '3':
      temp[0] |= (0x30 >> i*4);
      break;
    case '4':
      temp[0] |= (0x40 >> i*4);
      break;
    case '5':
      temp[0] |= (0x50 >> i*4);
      break;
    case '6':
      temp[0] |= (0x60 >> i*4);
      break;
    case '7':
      temp[0] |= (0x70 >> i*4);
      break;
    case '8':
      temp[0] |= (0x80 >> i*4);
      break;
    case '9':
      temp[0] |= (0x90 >> i*4);
      break;
    case 'A':
    case 'a':
      temp[0] |= (0xa0 >> i*4);
      break;
    case 'B':
    case 'b':
      temp[0] |= (0xb0 >> i*4);
      break;
    case 'C':
    case 'c':
      temp[0] |= (0xc0 >> i*4);
      break;
    case 'D':
    case 'd':
      temp[0] |= (0xd0 >> i*4);
      break;
    case 'E':
    case 'e':
      temp[0] |= (0xe0 >> i*4);
      break;
    case 'F':
    case 'f':
      temp[0] |= (0xf0 >> i*4);
      break;
    case 'q':
      return -1;
    default:
      if (i) {
 single = 1;
 continue;
      }
      return 1;
    }
    if (single)
      temp[0] >>= 4;
  }
  memset(in, '\0', 20);
  write(dev[grp], temp, 2);
  return 0;
}

variable_types: grp int

variable_types: single int

variable_types:
temp
unsigned char [2]

variable_types:
in
char [20]


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // ebp
__int64 i; // rbx
__int64 j; // rbx
char buf[26]; // [rsp+Eh] [rbp-1Ah] BYREF

dev = open("/dev/dio0", 2, envp);
dword_404094 = open("/dev/dio1", 2);
dword_404098 = open("/dev/dio2", 2);
dword_40409C = open("/dev/dio3", 2);
dword_4040A0 = open("/dev/dio4", 2);
v3 = 0LL;
v4 = 0;
do
{
if ( !*(&dev + v3) )
{
printf("Well that went badly for dev %d\n", (unsigned int)v3);
v4 = 1;
}
++v3;
}
while ( v3 != 5 );
if ( v4 )
return 2;
buf[1] = 3;
buf[0] = 0x80;
for ( i = 0LL; i != 5; ++i )
write(*(&dev + i), buf, 2uLL);
while ( (int)get_input() >= 0 )
;
for ( j = 0LL; j != 5; ++j )
close(*(&dev + j));
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
int v4; // ebp
__int64 i; // rbx
__int64 j; // rbx
char buf[26]; // [rsp+Eh] [rbp-1Ah] BYREF

dev = open("/dev/dio0", 2, envp);
dword_404094 = open("/dev/dio1", 2);
dword_404098 = open("/dev/dio2", 2);
dword_40409C = open("/dev/dio3", 2);
dword_4040A0 = open("/dev/dio4", 2);
v3 = 0LL;
v4 = 0;
do
{
if ( !*(&dev + v3) )
{
printf("Well that went badly for dev %d\n", (unsigned int)v3);
v4 = 1;
}
++v3;
}
while ( v3 != 5 );
if ( v4 )
return 2;
buf[1] = 3;
buf[0] = 0x80;
for ( i = 0LL; i != 5; ++i )
write(*(&dev + i), buf, 2uLL);
while ( (int)func7() >= 0 )
;
for ( j = 0LL; j != 5; ++j )
close(*(&dev + j));
return v4;
}

original_code:
int main(void) {
  int grp, bad = 0;
  unsigned char write_msg[2];
  dev[0] = open("/dev/dio0", 02);
  dev[1] = open("/dev/dio1", 02);
  dev[2] = open("/dev/dio2", 02);
  dev[3] = open("/dev/dio3", 02);
  dev[4] = open("/dev/dio4", 02);
  for(grp = 0; grp < 5; grp++) {
    if (!dev[grp]) {
      printf("Well that went badly for dev %d\n", grp);
      bad = 1;
    }
  }
  if (bad)
    return 2;
  write_msg[1] = 0x03;
  write_msg[0] = 0x80;
  for (grp = 0; grp < 5; grp++)
    write(dev[grp], write_msg, 2);
  while (1) {
    if (get_input() < 0)
      break;
  }
  for(grp = 0; grp < 5; grp++)
    close(dev[grp]);
  return 0;
}

canonical_original_code:
int main() {
  int grp; int bad = 0;
  unsigned char write_msg[2];
  dev[0] = open("/dev/dio0", 02);
  dev[1] = open("/dev/dio1", 02);
  dev[2] = open("/dev/dio2", 02);
  dev[3] = open("/dev/dio3", 02);
  dev[4] = open("/dev/dio4", 02);
  for(grp = 0; grp < 5; grp++) {
    if (!dev[grp]) {
      printf("Well that went badly for dev %d\n", grp);
      bad = 1;
    }
  }
  if (bad)
    return 2;
  write_msg[1] = 0x03;
  write_msg[0] = 0x80;
  for (grp = 0; grp < 5; grp++)
    write(dev[grp], write_msg, 2);
  while (1) {
    if (get_input() < 0)
      break;
  }
  for(grp = 0; grp < 5; grp++)
    close(dev[grp]);
  return 0;
}

variable_types: bad int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3 = open("/dev/timing1", 2, envp);
if ( v3 <= 0 )
{
puts("Couldn't open do_csr");
exit(3);
}
v4 = v3;
buf[0] = 1541;
write(v3, buf, 4uLL);
close(v4);
return 0;
}

original_code:
int main(void) {
  int DO_CSR;
  __u32 cmd;
  DO_CSR = open("/dev/timing1", 02);
  if ( DO_CSR < 1 ) {
    printf("Couldn't open do_csr\n");
    exit(3);
  }
  cmd = 0x00000601;
  cmd |= 0x00000001;
  cmd = (cmd & 0xfffffff9) | 0x00000004;
  cmd &= 0xfffffeff;
  cmd |= 0x00000200;
  write(DO_CSR, &cmd, sizeof(__u32));
  close(DO_CSR);
  return 0;
}

canonical_original_code:
int main() {
  int DO_CSR;
  unsigned int cmd;
  DO_CSR = open("/dev/timing1", 02);
  if ( DO_CSR < 1 ) {
    printf("Couldn't open do_csr\n");
    exit(3);
  }
  cmd = 0x00000601;
  cmd |= 0x00000001;
  cmd = (cmd & 0xfffffff9) | 0x00000004;
  cmd &= 0xfffffeff;
  cmd |= 0x00000200;
  write(DO_CSR, &cmd, sizeof(__u32));
  close(DO_CSR);
  return 0;
}

variable_types:
cmd
unsigned int


repo: schaars/simple-web-server

decompiled_code:
void __fastcall create_file_manager(__int64 a1)
{
webdir = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
webdir = a1;
}

original_code:
void create_file_manager(char *web_dir) {
   webdir = web_dir;
}


decompiled_code:
void delete_file_manager()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void delete_file_manager() {
}

canonical_original_code:
void delete_file_manager() {
}


decompiled_code:
void *__fastcall file_manager_get(const char *a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax
int v5; // ebx
void *v6; // r12
int *v8; // rax
char *v9; // rax
struct stat v10; // [rsp+0h] [rbp-C0h] BYREF
char *ptr; // [rsp+98h] [rbp-28h] BYREF

asprintf(&ptr, "%s%s", (const char *)webdir, a1);
if ( stat(ptr, &v10) < 0 )
{
*a2 = 404;
free(ptr);
v6 = 0LL;
}
else
{
*a3 = v10.st_size;
v4 = open(ptr, 0);
v5 = v4;
if ( v4 == -1 )
{
*a2 = 401;
free(ptr);
v6 = 0LL;
}
else
{
v6 = mmap(0LL, v10.st_size, 1, 1, v4, 0LL);
if ( v6 == (void *)-1LL )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(
stderr,
"%c[%d;%dm(%s,%d) mmap %s size %ld fail: %s\n%c[%d;%dm\n",
27LL,
0LL,
31LL,
"file_manager_get",
61LL,
ptr,
v10.st_size,
v9,
27LL,
0LL,
37LL);
exit(-1);
}
*a2 = 200;
close(v5);
free(ptr);
}
}
return v6;
}

canonical_decompiled_code:
void *__fastcall func2(const char *a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax
int v5; // ebx
void *v6; // r12
int *v8; // rax
char *v9; // rax
struct stat v10; // [rsp+0h] [rbp-C0h] BYREF
char *ptr; // [rsp+98h] [rbp-28h] BYREF

asprintf(&ptr, "%s%s", (const char *)webdir, a1);
if ( stat(ptr, &v10) < 0 )
{
*a2 = 404;
free(ptr);
v6 = 0LL;
}
else
{
*a3 = v10.st_size;
v4 = open(ptr, 0);
v5 = v4;
if ( v4 == -1 )
{
*a2 = 401;
free(ptr);
v6 = 0LL;
}
else
{
v6 = mmap(0LL, v10.st_size, 1, 1, v4, 0LL);
if ( v6 == (void *)-1LL )
{
v8 = _errno_location();
v9 = strerror(*v8);
fprintf(
stderr,
"%c[%d;%dm(%s,%d) mmap %s size %ld fail: %s\n%c[%d;%dm\n",
27LL,
0LL,
31LL,
"file_manager_get",
61LL,
ptr,
v10.st_size,
v9,
27LL,
0LL,
37LL);
exit(-1);
}
*a2 = 200;
close(v5);
free(ptr);
}
}
return v6;
}

original_code:
char* file_manager_get(const char *file, int *status, int *length) {
   char *path;
   asprintf(&path, "%s%s", webdir, file);
   struct stat st;
   if (stat(path, &st) < 0) {
      *status = 404;
      free(path);
      return ((void *)0);
   }
   *length = st.st_size;
   int fd;
   if ((fd = open(path, 00)) == -1)
   {
      *status = 401;
      free(path);
      return ((void *)0);
   }
   char *c = (char*) mmap(0, st.st_size, 0x1, 0x01, fd, 0);
   if (c == ((void *) -1))
   {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "mmap %s size %ld fail: %s\n" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 61, path, (long) st.st_size, strerror((*__errno_location ())), 0x1B, 0, 37); exit(-1); } while(0);
   }
   *status = 200;
   close(fd);
   free(path);
   return c;
}

canonical_original_code:
char *file_manager_get(char *file, int *status, int *length) {
   char *path;
   asprintf(&path, "%s%s", webdir, file);
   struct stat st;
   if (stat(path, &st) < 0) {
      *status = 404;
      free(path);
      return ((void *)0);
   }
   *length = st.st_size;
   int fd;
   if ((fd = open(path, 00)) == -1)
   {
      *status = 401;
      free(path);
      return ((void *)0);
   }
   char *c = (char*) mmap(0, st.st_size, 0x1, 0x01, fd, 0);
   if (c == ((void *) -1))
   {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "mmap %s size %ld fail: %s\n" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 61, path, (long) st.st_size, strerror((*__errno_location ())), 0x1B, 0, 37); exit(-1); } while(0);
   }
   *status = 200;
   close(fd);
   free(path);
   return c;
}

variable_types:
file
char *

variable_types:
status
int *

variable_types:
length
int *

variable_types:
path
char *

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

variable_types: fd int

variable_types:
c
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:
int __fastcall file_manager_release(void *a1, int a2)
{
return munmap(a1, a2);
}

canonical_decompiled_code:
int __fastcall func3(void *a1, int a2)
{
return munmap(a1, a2);
}

original_code:
void file_manager_release(char *c, const int length) {
   munmap(c, length);
}

canonical_original_code:
void file_manager_release(char *c, int length) {
   munmap(c, length);
}

variable_types: length int


decompiled_code:
__int64 __fastcall file_manager_get_sendfile(const char *a1, _DWORD *a2, _DWORD *a3)
{
unsigned int v4; // ebx
struct stat v6; // [rsp+0h] [rbp-B0h] BYREF
char *ptr; // [rsp+98h] [rbp-18h] BYREF

asprintf(&ptr, "%s%s", (const char *)webdir, a1);
if ( stat(ptr, &v6) < 0 )
{
*a2 = 404;
free(ptr);
v4 = 0;
}
else
{
*a3 = v6.st_size;
v4 = open(ptr, 0);
if ( v4 == -1 )
{
*a2 = 401;
free(ptr);
v4 = 0;
}
else
{
free(ptr);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, _DWORD *a2, _DWORD *a3)
{
unsigned int v4; // ebx
struct stat v6; // [rsp+0h] [rbp-B0h] BYREF
char *ptr; // [rsp+98h] [rbp-18h] BYREF

asprintf(&ptr, "%s%s", (const char *)webdir, a1);
if ( stat(ptr, &v6) < 0 )
{
*a2 = 404;
free(ptr);
v4 = 0;
}
else
{
*a3 = v6.st_size;
v4 = open(ptr, 0);
if ( v4 == -1 )
{
*a2 = 401;
free(ptr);
v4 = 0;
}
else
{
free(ptr);
}
}
return v4;
}

original_code:
int file_manager_get_sendfile(const char *file, int *status, int *length) {
   char *path;
   asprintf(&path, "%s%s", webdir, file);
   struct stat st;
   if (stat(path, &st) < 0) {
      *status = 404;
      free(path);
      return 0;
   }
   *length = st.st_size;
   int fd;
   if ((fd = open(path, 00)) == -1)
   {
      *status = 401;
      free(path);
      return 0;
   }
   free(path);
   return fd;
}

canonical_original_code:
int file_manager_get_sendfile(char *file, int *status, int *length) {
   char *path;
   asprintf(&path, "%s%s", webdir, file);
   struct stat st;
   if (stat(path, &st) < 0) {
      *status = 404;
      free(path);
      return 0;
   }
   *length = st.st_size;
   int fd;
   if ((fd = open(path, 00)) == -1)
   {
      *status = 401;
      free(path);
      return 0;
   }
   free(path);
   return fd;
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int __fastcall file_manager_release_sendfile(int a1)
{
return close(a1);
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
return close(a1);
}

original_code:
void file_manager_release_sendfile(int fd) {
   close(fd);
}


decompiled_code:
__int64 __fastcall file_manager_get_filetype(char *haystack, char *a2)
{
__int64 result; // rax

if ( strstr(haystack, ".html") )
{
result = 0x6D74682F74786574LL;
strcpy(a2, "text/html");
}
else if ( strstr(haystack, ".gif") )
{
result = 0x69672F6567616D69LL;
strcpy(a2, "image/gif");
}
else
{
if ( strstr(haystack, ".jpg") )
{
result = 0x706A2F6567616D69LL;
qmemcpy(a2, "image/jpeg", 10);
}
else
{
result = 0x616C702F74786574LL;
qmemcpy(a2, "text/plain", 10);
}
a2[10] = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *haystack, char *a2)
{
__int64 result; // rax

if ( strstr(haystack, ".html") )
{
result = 0x6D74682F74786574LL;
strcpy(a2, "text/html");
}
else if ( strstr(haystack, ".gif") )
{
result = 0x69672F6567616D69LL;
strcpy(a2, "image/gif");
}
else
{
if ( strstr(haystack, ".jpg") )
{
result = 0x706A2F6567616D69LL;
qmemcpy(a2, "image/jpeg", 10);
}
else
{
result = 0x616C702F74786574LL;
qmemcpy(a2, "text/plain", 10);
}
a2[10] = 0;
}
return result;
}

original_code:
void file_manager_get_filetype(const char *filename, char *filetype)
{
   if (strstr(filename, ".html")) {
      strcpy(filetype, "text/html");
   } else if (strstr(filename, ".gif")) {
      strcpy(filetype, "image/gif");
   } else if (strstr(filename, ".jpg")) {
      strcpy(filetype, "image/jpeg");
   } else {
      strcpy(filetype, "text/plain");
   }
}

canonical_original_code:
void file_manager_get_filetype(char *filename, char *filetype)
{
   if (strstr(filename, ".html")) {
      strcpy(filetype, "text/html");
   } else if (strstr(filename, ".gif")) {
      strcpy(filetype, "image/gif");
   } else if (strstr(filename, ".jpg")) {
      strcpy(filetype, "image/jpeg");
   } else {
      strcpy(filetype, "text/plain");
   }
}

variable_types:
filename
char *

variable_types:
filetype
char *


decompiled_code:
void __fastcall handle_signal(int a1)
{
if ( a1 == 2 )
sub_6();
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
sub_6();
}

original_code:
void handle_signal(int sig) {
   if (sig == 2) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Exit on signal %d" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 19, sig, 0x1B, 0, 37); exit(-1); } while(0);
   }
}

variable_types: sig int


decompiled_code:
__int64 __fastcall accept_connections(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr addr; // [rsp+0h] [rbp-30h] BYREF
int optval[5]; // [rsp+1Ch] [rbp-14h] BYREF

v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Error while creating the socket%c[%d;%dm\n",
27LL,
0LL,
31LL,
"accept_connections",
26LL,
27LL,
0LL,
37LL);
exit(-1);
}
v2 = v1;
optval[0] = 1;
if ( setsockopt(v1, 6, 1, optval, 4u) == -1 )
perror("Cannot set TCP NO DELAY:");
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a1);
if ( bind(v2, &addr, 0x10u) == -1 )
{
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Cannot bind socket!%c[%d;%dm\n",
27LL,
0LL,
31LL,
"accept_connections",
39LL,
27LL,
0LL,
37LL);
exit(-1);
}
if ( listen(v2, 100) == -1 )
{
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Cannot listen on socket!%c[%d;%dm\n",
27LL,
0LL,
31LL,
"accept_connections",
43LL,
27LL,
0LL,
37LL);
exit(-1);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
int v1; // eax
unsigned int v2; // ebx
struct sockaddr addr; // [rsp+0h] [rbp-30h] BYREF
int optval[5]; // [rsp+1Ch] [rbp-14h] BYREF

v1 = socket(2, 1, 0);
if ( v1 == -1 )
{
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Error while creating the socket%c[%d;%dm\n",
27LL,
0LL,
31LL,
"accept_connections",
26LL,
27LL,
0LL,
37LL);
exit(-1);
}
v2 = v1;
optval[0] = 1;
if ( setsockopt(v1, 6, 1, optval, 4u) == -1 )
perror("Cannot set TCP NO DELAY:");
*(_DWORD *)&addr.sa_data[2] = func1(0);
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func2(a1);
if ( bind(v2, &addr, 0x10u) == -1 )
{
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Cannot bind socket!%c[%d;%dm\n",
27LL,
0LL,
31LL,
"accept_connections",
39LL,
27LL,
0LL,
37LL);
exit(-1);
}
if ( listen(v2, 100) == -1 )
{
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Cannot listen on socket!%c[%d;%dm\n",
27LL,
0LL,
31LL,
"accept_connections",
43LL,
27LL,
0LL,
37LL);
exit(-1);
}
return v2;
}

original_code:
int accept_connections(const int port) {
   int bootstrap = socket(2, SOCK_STREAM, 0);
   if (bootstrap == -1) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Error while creating the socket" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 26, 0x1B, 0, 37); exit(-1); } while(0);
   }
   int flag = 1;
   if (setsockopt(bootstrap, IPPROTO_TCP, 1, (char*)&flag, sizeof(int)) == -1) {
      perror("Cannot set TCP NO DELAY:");
   }
   struct sockaddr_in bootstrap_sin;
   bootstrap_sin.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
   bootstrap_sin.sin_family = 2;
   bootstrap_sin.sin_port = htons(port);
   if (bind(bootstrap, (struct sockaddr*)&bootstrap_sin, sizeof(bootstrap_sin)) == -1) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Cannot bind socket!" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 39, 0x1B, 0, 37); exit(-1); } while(0);
   }
   if (listen(bootstrap, 100) == -1) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Cannot listen on socket!" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 43, 0x1B, 0, 37); exit(-1); } while(0);
   }
   ;
   return bootstrap;
}

canonical_original_code:
int accept_connections(int port) {
   int bootstrap = socket(2, SOCK_STREAM, 0);
   if (bootstrap == -1) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Error while creating the socket" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 26, 0x1B, 0, 37); exit(-1); } while(0);
   }
   int flag = 1;
   if (setsockopt(bootstrap, IPPROTO_TCP, 1, (char *)&flag, sizeof(int)) == -1) {
      perror("Cannot set TCP NO DELAY:");
   }
   struct sockaddr_in bootstrap_sin;
   bootstrap_sin.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
   bootstrap_sin.sin_family = 2;
   bootstrap_sin.sin_port = htons(port);
   if (bind(bootstrap, (struct sockaddr *)&bootstrap_sin, sizeof(bootstrap_sin)) == -1) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Cannot bind socket!" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 39, 0x1B, 0, 37); exit(-1); } while(0);
   }
   if (listen(bootstrap, 100) == -1) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Cannot listen on socket!" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 43, 0x1B, 0, 37); exit(-1); } while(0);
   }
   ;
   return bootstrap;
}

variable_types: port int

variable_types: bootstrap int

variable_types: flag int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
unsigned int v4; // er13
int v5; // er14
int v6; // eax
unsigned int v7; // eax

v3 = 0LL;
v4 = 0;
v5 = -1;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "p:s:d:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'p':
v5 = atoi(optarg);
break;
case 's':
v4 = atoi(optarg);
break;
case 'd':
v3 = strdup(optarg);
break;
default:
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Usage: %s -p port -s pool_size -d web_directory%c[%d;%dm\n",
27LL,
0LL,
31LL,
"main",
68LL,
*argv,
27LL,
0LL,
37LL);
exit(-1);
}
}
if ( v4 != 0 && v5 != -1 && v3 )
{
signal(2, handle_signal);
create_file_manager(v3);
v7 = accept_connections(v5);
create_pool(v4, v7);
while ( 1 )
sleep(0xAu);
}
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Usage: %s -p port -s pool_size -d web_directory%c[%d;%dm\n",
27LL,
0LL,
31LL,
"main",
73LL,
*argv,
27LL,
0LL,
37LL);
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // r15
unsigned int v4; // er13
int v5; // er14
int v6; // eax
unsigned int v7; // eax

v3 = 0LL;
v4 = 0;
v5 = -1;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "p:s:d:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'p':
v5 = atoi(optarg);
break;
case 's':
v4 = atoi(optarg);
break;
case 'd':
v3 = strdup(optarg);
break;
default:
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Usage: %s -p port -s pool_size -d web_directory%c[%d;%dm\n",
27LL,
0LL,
31LL,
"main",
68LL,
*argv,
27LL,
0LL,
37LL);
exit(-1);
}
}
if ( v4 != 0 && v5 != -1 && v3 )
{
signal(2, handle_signal);
create_file_manager(v3);
v7 = func3(v5);
create_pool(v4, v7);
while ( 1 )
sleep(0xAu);
}
fprintf(
stderr,
"%c[%d;%dm(%s,%d) Usage: %s -p port -s pool_size -d web_directory%c[%d;%dm\n",
27LL,
0LL,
31LL,
"main",
73LL,
*argv,
27LL,
0LL,
37LL);
exit(-1);
}

original_code:
int main(int argc, char **argv) {
   int port = -1;
   int pool_size = 0;
   char* web_dir = ((void *)0);
   int opt;
   while ((opt = getopt(argc, argv, "p:s:d:")) != (-1)) {
      switch (opt) {
         case 'p':
            port = atoi(optarg);
            break;
         case 's':
            pool_size = atoi(optarg);
            break;
         case 'd':
            web_dir = strdup(optarg);
            break;
         default:
            do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Usage: %s -p port -s pool_size -d web_directory" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 68, argv[0], 0x1B, 0, 37); exit(-1); } while(0);
      }
   }
   if (port == -1 || pool_size == 0 || web_dir == ((void *)0)) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Usage: %s -p port -s pool_size -d web_directory" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 73, argv[0], 0x1B, 0, 37); exit(-1); } while(0);
   }
   signal(2, handle_signal);
   create_file_manager(web_dir);
   int bootstrap_s = accept_connections(port);
   create_pool(pool_size, bootstrap_s);
   while (1) {
      sleep(10);
   }
   delete_pool();
   delete_file_manager();
   free(web_dir);
   return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
   int port = -1;
   int pool_size = 0;
   char *web_dir = ((void *)0);
   int opt;
   while ((opt = getopt(argc, argv, "p:s:d:")) != (-1)) {
      switch (opt) {
         case 'p':
            port = atoi(optarg);
            break;
         case 's':
            pool_size = atoi(optarg);
            break;
         case 'd':
            web_dir = strdup(optarg);
            break;
         default:
            do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Usage: %s -p port -s pool_size -d web_directory" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 68, argv[0], 0x1B, 0, 37); exit(-1); } while(0);
      }
   }
   if (port == -1 || pool_size == 0 || web_dir == ((void *)0)) {
      do { fprintf(stderr, "%c[%d;%dm(%s,%d) " "Usage: %s -p port -s pool_size -d web_directory" "%c[%d;%dm\n", 0x1B, 0, 31, __FUNCTION__ , 73, argv[0], 0x1B, 0, 37); exit(-1); } while(0);
   }
   signal(2, handle_signal);
   create_file_manager(web_dir);
   int bootstrap_s = accept_connections(port);
   create_pool(pool_size, bootstrap_s);
   while (1) {
      sleep(10);
   }
   delete_pool();
   delete_file_manager();
   free(web_dir);
   return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int


decompiled_code:
__int64 __fastcall read_request(int a1, __int64 a2, int a3)
{
int v4; // er13
unsigned int v5; // ebx
__int64 v7; // [rsp+0h] [rbp-40h]
unsigned int v8; // [rsp+Ch] [rbp-34h]

if ( a3 <= 0 )
{
LABEL_7:
*(_BYTE *)(a2 + a3 - 1) = 0;
v8 = 1;
}
else
{
v4 = 0;
v7 = a3;
while ( 1 )
{
v5 = read(a1, (void *)(a2 + v4), a3 - v4);
v8 = v5;
*(_BYTE *)(a2 + v7 - 1) = 0;
if ( v5 == -1 )
{
perror("Read error: ");
return v8;
}
if ( !v5 )
return 1;
if ( strchr((const char *)(a2 + v4), 10) )
break;
v4 += v5;
if ( a3 <= v4 )
goto LABEL_7;
}
v8 = 0;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, int a3)
{
int v4; // er13
unsigned int v5; // ebx
__int64 v7; // [rsp+0h] [rbp-40h]
unsigned int v8; // [rsp+Ch] [rbp-34h]

if ( a3 <= 0 )
{
LABEL_7:
*(_BYTE *)(a2 + a3 - 1) = 0;
v8 = 1;
}
else
{
v4 = 0;
v7 = a3;
while ( 1 )
{
v5 = read(a1, (void *)(a2 + v4), a3 - v4);
v8 = v5;
*(_BYTE *)(a2 + v7 - 1) = 0;
if ( v5 == -1 )
{
perror("Read error: ");
return v8;
}
if ( !v5 )
return 1;
if ( strchr((const char *)(a2 + v4), 10) )
break;
v4 += v5;
if ( a3 <= v4 )
goto LABEL_7;
}
v8 = 0;
}
return v8;
}

original_code:
int read_request(const int s, char *req, const int length) {
   int pos = 0;
   while (pos < length) {
      int r = read(s, req+pos, length-pos);
      req[length-1] = '\0';
      if (r == -1) {
         perror("Read error: ");
         return -1;
      } else if (r == 0) {
         return 1;
      } else {
         if (strchr(req+pos, '\n')) {
            return 0;
         }
      }
      pos += r;
   }
   req[length-1] = '\0';
   return 1;
}

canonical_original_code:
int read_request(int s, char *req, int length) {
   int pos = 0;
   while (pos < length) {
      int r = read(s, req+pos, length-pos);
      req[length-1] = '\0';
      if (r == -1) {
         perror("Read error: ");
         return -1;
      } else if (r == 0) {
         return 1;
      } else {
         if (strchr(req+pos, '\n')) {
            return 0;
         }
      }
      pos += r;
   }
   req[length-1] = '\0';
   return 1;
}

variable_types: s int

variable_types:
req
char *

variable_types: pos int

variable_types: r int


decompiled_code:
void __fastcall write_complete(int fd, __int64 a2, int a3)
{
int v4; // ebx
int v5; // eax

if ( a3 > 0 )
{
v4 = 0;
while ( 1 )
{
v5 = write(fd, (const void *)(a2 + v4), a3 - v4);
if ( v5 == -1 )
break;
v4 += v5;
if ( a3 <= v4 )
return;
}
perror("Write error: ");
}
}

canonical_decompiled_code:
void __fastcall func1(int fd, __int64 a2, int a3)
{
int v4; // ebx
int v5; // eax

if ( a3 > 0 )
{
v4 = 0;
while ( 1 )
{
v5 = write(fd, (const void *)(a2 + v4), a3 - v4);
if ( v5 == -1 )
break;
v4 += v5;
if ( a3 <= v4 )
return;
}
perror("Write error: ");
}
}

original_code:
void write_complete(const int fd, const char *buf, const int length) {
   int written = 0;
   while (written < length) {
      int r = write(fd, buf+written, length-written);
      if (r == -1) {
         perror("Write error: ");
         return;
      } else {
         written += r;
      }
   }
}

canonical_original_code:
void write_complete(int fd, char *buf, int length) {
   int written = 0;
   while (written < length) {
      int r = write(fd, buf+written, length-written);
      if (r == -1) {
         perror("Write error: ");
         return;
      } else {
         written += r;
      }
   }
}

variable_types: fd int

variable_types:
buf
char *

variable_types: written int


clienterror

decompiled_code:
void __fastcall clienterror(int fd, const char *a2, const char *a3, const char *a4, const char *a5)
{
int v8; // eax
int v9; // eax
size_t v10; // rax
int v11; // eax
int v12; // eax
char s[8192]; // [rsp+0h] [rbp-2130h] BYREF
char v14[304]; // [rsp+2000h] [rbp-130h] BYREF

strcpy(s, "<title>Simple Web Server Error</title>");
sprintf(s, "%s\r\n", s);
sprintf(s, "%s%s: %s\r\n", s, a3, a4);
sprintf(s, "%s
%s: %s
\r\n", s, a5, a2);
sprintf(s, "%s
The Simple Web Server\r\n", s);
sprintf(v14, "HTTP/1.0 %s %s\r\n", a3, a4);
v8 = strlen(v14);
write_complete(fd, (__int64)v14, v8);
strcpy(v14, "Content-type: text/html\r\n");
v9 = strlen(v14);
write_complete(fd, (__int64)v14, v9);
v10 = strlen(s);
sprintf(v14, "Content-length: %d\r\n\r\n", v10);
v11 = strlen(v14);
write_complete(fd, (__int64)v14, v11);
v12 = strlen(s);
write_complete(fd, (__int64)s, v12);
}

canonical_decompiled_code:
void __fastcall func2(int fd, const char *a2, const char *a3, const char *a4, const char *a5)
{
int v8; // eax
int v9; // eax
size_t v10; // rax
int v11; // eax
int v12; // eax
char s[8192]; // [rsp+0h] [rbp-2130h] BYREF
char v14[304]; // [rsp+2000h] [rbp-130h] BYREF

strcpy(s, "<title>Simple Web Server Error</title>");
sprintf(s, "%s\r\n", s);
sprintf(s, "%s%s: %s\r\n", s, a3, a4);
sprintf(s, "%s
%s: %s
\r\n", s, a5, a2);
sprintf(s, "%s
The Simple Web Server\r\n", s);
sprintf(v14, "HTTP/1.0 %s %s\r\n", a3, a4);
v8 = strlen(v14);
func1(fd, (__int64)v14, v8);
strcpy(v14, "Content-type: text/html\r\n");
v9 = strlen(v14);
func1(fd, (__int64)v14, v9);
v10 = strlen(s);
sprintf(v14, "Content-length: %d\r\n\r\n", v10);
v11 = strlen(v14);
func1(fd, (__int64)v14, v11);
v12 = strlen(s);
func1(fd, (__int64)s, v12);
}

original_code:
void clienterror(const int fd, const char *cause, const char *errnum,
      const char *shortmsg, const char *longmsg)
{
   char buf[256], body[8192];
   sprintf(body, "<title>Simple Web Server Error</title>");
   sprintf(body, "%s\r\n", body);
   sprintf(body, "%s%s: %s\r\n", body, errnum, shortmsg);
   sprintf(body, "%s
%s: %s
\r\n", body, longmsg, cause);
   sprintf(body, "%s
The Simple Web Server\r\n", body);
   sprintf(buf, "HTTP/1.0 %s %s\r\n", errnum, shortmsg);
   write_complete(fd, buf, strlen(buf));
   sprintf(buf, "Content-type: text/html\r\n");
   write_complete(fd, buf, strlen(buf));
   sprintf(buf, "Content-length: %d\r\n\r\n", (int)strlen(body));
   write_complete(fd, buf, strlen(buf));
   write_complete(fd, body, strlen(body));
}

canonical_original_code:
void clienterror(int fd, char *cause, char *errnum, char *shortmsg, char *longmsg)
{
   char buf[256]; char body[8192];
   sprintf(body, "<title>Simple Web Server Error</title>");
   sprintf(body, "%s\r\n", body);
   sprintf(body, "%s%s: %s\r\n", body, errnum, shortmsg);
   sprintf(body, "%s
%s: %s
\r\n", body, longmsg, cause);
   sprintf(body, "%s
The Simple Web Server\r\n", body);
   sprintf(buf, "HTTP/1.0 %s %s\r\n", errnum, shortmsg);
   write_complete(fd, buf, strlen(buf));
   sprintf(buf, "Content-type: text/html\r\n");
   write_complete(fd, buf, strlen(buf));
   sprintf(buf, "Content-length: %d\r\n\r\n", (int)strlen(body));
   write_complete(fd, buf, strlen(buf));
   write_complete(fd, body, strlen(body));
}

variable_types:
cause
char *

variable_types:
errnum
char *

variable_types:
shortmsg
char *

variable_types:
longmsg
char *

variable_types:
buf
char [256]

variable_types:
body
char [8192]


clientsuccess

decompiled_code:
void __fastcall clientsuccess(int fd, __int64 a2, unsigned int a3)
{
int v4; // eax
char s[8192]; // [rsp+0h] [rbp-2110h] BYREF
char v6[272]; // [rsp+2000h] [rbp-110h] BYREF

file_manager_get_filetype(a2, v6);
strcpy(s, "HTTP/1.0 200 OK\r\n");
sprintf(s, "%sServer: Simple Web Server\r\n", s);
sprintf(s, "%sContent-length: %d\r\n", s, a3);
sprintf(s, "%sContent-type: %s\r\n\r\n", s, v6);
v4 = strlen(s);
write_complete(fd, (__int64)s, v4);
}

canonical_decompiled_code:
void __fastcall func3(int fd, __int64 a2, unsigned int a3)
{
int v4; // eax
char s[8192]; // [rsp+0h] [rbp-2110h] BYREF
char v6[272]; // [rsp+2000h] [rbp-110h] BYREF

file_manager_get_filetype(a2, v6);
strcpy(s, "HTTP/1.0 200 OK\r\n");
sprintf(s, "%sServer: Simple Web Server\r\n", s);
sprintf(s, "%sContent-length: %d\r\n", s, a3);
sprintf(s, "%sContent-type: %s\r\n\r\n", s, v6);
v4 = strlen(s);
func1(fd, (__int64)s, v4);
}

original_code:
void clientsuccess(const int fd, const char *filename, const int length, const int status) {
   char filetype[256], buf[8192];
   file_manager_get_filetype(filename, filetype);
   sprintf(buf, "HTTP/1.0 200 OK\r\n");
   sprintf(buf, "%sServer: Simple Web Server\r\n", buf);
   sprintf(buf, "%sContent-length: %d\r\n", buf, length);
   sprintf(buf, "%sContent-type: %s\r\n\r\n", buf, filetype);
   write_complete(fd, buf, strlen(buf));
}

canonical_original_code:
void clientsuccess(int fd, char *filename, int length, int status) {
   char filetype[256]; char buf[8192];
   file_manager_get_filetype(filename, filetype);
   sprintf(buf, "HTTP/1.0 200 OK\r\n");
   sprintf(buf, "%sServer: Simple Web Server\r\n", buf);
   sprintf(buf, "%sContent-length: %d\r\n", buf, length);
   sprintf(buf, "%sContent-type: %s\r\n\r\n", buf, filetype);
   write_complete(fd, buf, strlen(buf));
}

variable_types:
filename
char *

variable_types: length int

variable_types: status int

variable_types:
filetype
char [256]

variable_types:
buf
char [8192]