getObjectColorQuadratic

repo: Fireblend/Yet-Another-RayTracer

decompiled_code:
__int64 __fastcall getObjectColorQuadratic(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 96) + 160LL);
}

original_code:
rgb* getObjectColorQuadratic(struct object *quadratic){
 QuadraticData *data = (QuadraticData*)quadratic->data;
 return data->color;
}

canonical_original_code:
struct rgb *getObjectColorQuadratic(struct object *quadratic){
 struct QuadraticData *data = (QuadraticData*)quadratic->data;
 return data->color;
}

variable_types: struct object { long double position[3]; struct intDataNode { struct intData { long double t; long double *vector; struct object *obj; long double u; } *data; struct intDataNode *next; } *(*getIntersection)(long double *eye, long double *directionV, struct object *obj); struct rgb *(*getColorAt)(long double *eye, long double *directionV, struct intData *obj, struct lightNode { long double *data; long double c1; struct lightNode *next; } *lights, int rDepth, int tDepth); long double *(*getNormalV)(long double *intersection, struct object *obj); struct rgb *(*getObjectColor)(struct object *obj); struct rgb *(*getTexturesColor)(struct intData *inter); long double **(*getBumpmapVects)(struct intData *inter, struct object *sphere); void *data; long double ka; int texCount; struct objTexture { long double thRes; int mode; struct objTexture *next; } *textList; int planeCount; int *planes; int hasCutout; struct textureNode { struct rgb *data; int width; int height; int mode; struct textureNode *next; } *cutout; struct textureNode *bumpmap; int kn; long double kr; } *

variable_types: struct QuadraticData { long double A; struct rgb { float r; float g; float b; } *color; } *

user_defined_types: struct object { long double position[3]; struct intDataNode *(*getIntersection)(long double *eye, long double *directionV, struct object *obj); struct rgb *(*getColorAt)(long double *eye, long double *directionV, struct intData *obj, struct lightNode *lights, int rDepth, int tDepth); long double *(*getNormalV)(long double *intersection, struct object *obj); struct rgb *(*getObjectColor)(struct object *obj); struct rgb *(*getTexturesColor)(struct intData *inter); long double **(*getBumpmapVects)(struct intData *inter, struct object *sphere); void *data; long double ka; int texCount; struct objTexture *textList; int planeCount; int *planes; int hasCutout; struct textureNode *cutout; struct textureNode *bumpmap; int kn; long double kr; }

user_defined_types: struct QuadraticData { long double A; struct rgb *color; }

user_defined_types: struct intDataNode { struct intData *data; struct intDataNode *next; }


getIntersectionQuadratic

decompiled_code:
__int64 __fastcall getIntersectionQuadratic(long double *a1, long double *a2, __int64 a3)
{
long double *v4; // rax
long double v5; // rt0
long double v6; // fst4
long double v7; // fst6
long double v8; // rt2
long double v9; // fst4
long double v10; // fst3
long double v11; // fst7
long double v12; // fst1
long double v13; // fst4
long double v14; // fst3
__int64 v15; // r12
__int64 v17; // rbx
long double v18; // [rsp+70h] [rbp-C8h]
long double v19; // [rsp+80h] [rbp-B8h]
double v20; // [rsp+90h] [rbp-A8h]
long double v21; // [rsp+90h] [rbp-A8h]
long double v22; // [rsp+A0h] [rbp-98h]
long double v23; // [rsp+C0h] [rbp-78h]

v4 = *(long double **)(a3 + 96);
v19 = a1[1];
v18 = a1[2];
v5 = *a1;
v6 = a2[1];
v7 = *a2;
v20 = v6;
v8 = v6;
v9 = a2[2];
v10 = v4[3] * v7 * v8 + v4[4] * v8 * v9 + v4[5] * v7 * v9;
v23 = v10 + v10 + *v4 * ((double)v7 * (double)v7) + v4[1] * (v20 * v20) + v4[2] * ((double)v9 * (double)v9);
v11 = v5 * v4[3];
v21 = v4[4] * v19;
v22 = v4[5] * v18;
v12 = *v4 * v5 * v7
+ v4[1] * v19 * v8
+ v4[2] * v18 * v9
+ v11 * v8
+ v4[3] * v19 * v7
+ v21 * v9
+ v4[4] * v18 * v8
+ v22 * v7
+ v4[5] * v5 * v9
+ v4[6] * v7
+ v4[7] * v8
+ v4[8] * v9;
v13 = v19 * v4[7] + v5 * v4[6] + v11 * v19 + v18 * v21 + v5 * v22 + v4[8] * v18;
v14 = (double)(v12 + v12) * (double)(v12 + v12)
- (v13
+ v13
+ *v4 * ((double)v5 * (double)v5)
+ v4[1] * ((double)v19 * (double)v19)
+ v4[2] * ((double)v18 * (double)v18)
+ v4[9])
* (v23
* 4.0);
if ( v14 <= 0.0001 )
{
if ( v14 < 0.0000001 && v14 > -0.0000001 )
{
v15 = createDataNode(1LL, a3);
if ( (unsigned int)checkCutPlanes(v15, a3) )
return v15;
}
return 0LL;
}
if ( (double)v14 < 0.0 )
{
sqrt(v14);
v15 = createDataNode(1LL, a3);
sqrt(v14);
}
else
{
v15 = createDataNode(1LL, a3);
}
v17 = createDataNode(1LL, a3);
if ( !(unsigned int)checkCutPlanes(v15, a3) )
{
if ( !(unsigned int)checkCutPlanes(v17, a3) )
*(_QWORD *)(v15 + 8) = v17;
return v15;
}
if ( (unsigned int)checkCutPlanes(v17, a3) )
return 0LL;
return v17;
}

canonical_decompiled_code:
__int64 __fastcall func1(long double *a1, long double *a2, __int64 a3)
{
long double *v4; // rax
long double v5; // rt0
long double v6; // fst4
long double v7; // fst6
long double v8; // rt2
long double v9; // fst4
long double v10; // fst3
long double v11; // fst7
long double v12; // fst1
long double v13; // fst4
long double v14; // fst3
__int64 v15; // r12
__int64 v17; // rbx
long double v18; // [rsp+70h] [rbp-C8h]
long double v19; // [rsp+80h] [rbp-B8h]
double v20; // [rsp+90h] [rbp-A8h]
long double v21; // [rsp+90h] [rbp-A8h]
long double v22; // [rsp+A0h] [rbp-98h]
long double v23; // [rsp+C0h] [rbp-78h]

v4 = *(long double **)(a3 + 96);
v19 = a1[1];
v18 = a1[2];
v5 = *a1;
v6 = a2[1];
v7 = *a2;
v20 = v6;
v8 = v6;
v9 = a2[2];
v10 = v4[3] * v7 * v8 + v4[4] * v8 * v9 + v4[5] * v7 * v9;
v23 = v10 + v10 + *v4 * ((double)v7 * (double)v7) + v4[1] * (v20 * v20) + v4[2] * ((double)v9 * (double)v9);
v11 = v5 * v4[3];
v21 = v4[4] * v19;
v22 = v4[5] * v18;
v12 = *v4 * v5 * v7
+ v4[1] * v19 * v8
+ v4[2] * v18 * v9
+ v11 * v8
+ v4[3] * v19 * v7
+ v21 * v9
+ v4[4] * v18 * v8
+ v22 * v7
+ v4[5] * v5 * v9
+ v4[6] * v7
+ v4[7] * v8
+ v4[8] * v9;
v13 = v19 * v4[7] + v5 * v4[6] + v11 * v19 + v18 * v21 + v5 * v22 + v4[8] * v18;
v14 = (double)(v12 + v12) * (double)(v12 + v12)
- (v13
+ v13
+ *v4 * ((double)v5 * (double)v5)
+ v4[1] * ((double)v19 * (double)v19)
+ v4[2] * ((double)v18 * (double)v18)
+ v4[9])
* (v23
* 4.0);
if ( v14 <= 0.0001 )
{
if ( v14 < 0.0000001 && v14 > -0.0000001 )
{
v15 = createDataNode(1LL, a3);
if ( (unsigned int)checkCutPlanes(v15, a3) )
return v15;
}
return 0LL;
}
if ( (double)v14 < 0.0 )
{
sqrt(v14);
v15 = createDataNode(1LL, a3);
sqrt(v14);
}
else
{
v15 = createDataNode(1LL, a3);
}
v17 = createDataNode(1LL, a3);
if ( !(unsigned int)checkCutPlanes(v15, a3) )
{
if ( !(unsigned int)checkCutPlanes(v17, a3) )
*(_QWORD *)(v15 + 8) = v17;
return v15;
}
if ( (unsigned int)checkCutPlanes(v17, a3) )
return 0LL;
return v17;
}

original_code:
intDataNode *getIntersectionQuadratic(long double *eye, long double *directionV, object *obj){
 QuadraticData *data = (QuadraticData*)obj->data;
 long double A, B, C, D, E, F, G, H, J, K, a, b, c, xd, yd, zd, xe, ye, ze;
 A = data->A;
 B = data->B;
 C = data->C;
 D = data->D;
 E = data->E;
 F = data->F;
 G = data->G;
 H = data->H;
 J = data->J;
 K = data->K;
 xd = directionV[0];
 yd = directionV[1];
 zd = directionV[2];
 xe = eye[0];
 ye = eye[1];
 ze = eye[2];
 a = (A * pow(xd, 2)) + (B * pow(yd, 2))+ (C * pow(zd, 2)) + (2*((D*xd*yd) + (E*yd*zd) + (F*xd*zd)));
 b = 2*((A*xe*xd)+(B*ye*yd)+(C*ze*zd)+(D*xe*yd)+(D*ye*xd)
 +(E*ye*zd)+(E*ze*yd)+(F*ze*xd)+(F*xe*zd)+(G*xd)+(H*yd)+(J*zd));
 c = (A*pow(xe, 2)) + (B*pow(ye, 2))+
   (C*pow(ze, 2)) + (2*((D*xe*ye) + (E*ye*ze) + (F*ze*xe)+
     (G*xe) + (H*ye) + (J*ze))) + K;
 long double disc = pow(b, 2)-(4*a*c);
 long double t;
 if(disc > 0.0001){
  t = ((-b) - sqrt(disc))/(2*a);
  intDataNode *newDataNode = createDataNode(t, xe, ye, ze, xd, yd, zd, 1, obj);
  t = ((-b) + sqrt(disc))/(2*a);
  intDataNode *newDataNode2 = createDataNode(t, xe, ye, ze, xd, yd, zd, 1, obj);
  if(checkCutPlanes(newDataNode, obj)){
   if(checkCutPlanes(newDataNode2, obj)){
    return ((void *)0);
   }
   else{
    return newDataNode2;
   }
  }
  else{
   if(checkCutPlanes(newDataNode2, obj)){
    return newDataNode;
   }
   else{
    newDataNode->next = newDataNode2;
    return newDataNode;
   }
  }
 }
 else if (disc < 0.0000001 && disc > -0.0000001){
  t = (-b)/(2*a);
  intDataNode *newDataNode = createDataNode(t, xe, ye, ze, xd, yd, zd, 1, obj);
  if(checkCutPlanes(newDataNode, obj)){
   return newDataNode;
  }
  else{
   return ((void *)0);
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct intDataNode *getIntersectionQuadratic(long double *eye, long double *directionV, struct object *obj){
 struct QuadraticData *data = (QuadraticData*)obj->data;
 long double A; long double B; long double C; long double D; long double E; long double F; long double G; long double H; long double J; long double K; long double a; long double b; long double c; long double xd; long double yd; long double zd; long double xe; long double ye; long double ze;
 A = data->A;
 B = data->B;
 C = data->C;
 D = data->D;
 E = data->E;
 F = data->F;
 G = data->G;
 H = data->H;
 J = data->J;
 K = data->K;
 xd = directionV[0];
 yd = directionV[1];
 zd = directionV[2];
 xe = eye[0];
 ye = eye[1];
 ze = eye[2];
 a = (A * pow(xd, 2)) + (B * pow(yd, 2))+ (C * pow(zd, 2)) + (2*((D*xd*yd) + (E*yd*zd) + (F*xd*zd)));
 b = 2*((A*xe*xd)+(B*ye*yd)+(C*ze*zd)+(D*xe*yd)+(D*ye*xd)
 +(E*ye*zd)+(E*ze*yd)+(F*ze*xd)+(F*xe*zd)+(G*xd)+(H*yd)+(J*zd));
 c = (A*pow(xe, 2)) + (B*pow(ye, 2))+
   (C*pow(ze, 2)) + (2*((D*xe*ye) + (E*ye*ze) + (F*ze*xe)+
     (G*xe) + (H*ye) + (J*ze))) + K;
 long double disc = pow(b, 2)-(4*a*c);
 long double t;
 if(disc > 0.0001){
  t = ((-b) - sqrt(disc))/(2*a);
  struct intDataNode *newDataNode = createDataNode(t, xe, ye, ze, xd, yd, zd, 1, obj);
  t = ((-b) + sqrt(disc))/(2*a);
  struct intDataNode *newDataNode2 = createDataNode(t, xe, ye, ze, xd, yd, zd, 1, obj);
  if(checkCutPlanes(newDataNode, obj)){
   if(checkCutPlanes(newDataNode2, obj)){
    return ((void *)0);
   }
   else{
    return newDataNode2;
   }
  }
  else{
   if(checkCutPlanes(newDataNode2, obj)){
    return newDataNode;
   }
   else{
    newDataNode->next = newDataNode2;
    return newDataNode;
   }
  }
 }
 else if (disc < 0.0000001 && disc > -0.0000001){
  t = (-b)/(2*a);
  struct intDataNode *newDataNode = createDataNode(t, xe, ye, ze, xd, yd, zd, 1, obj);
  if(checkCutPlanes(newDataNode, obj)){
   return newDataNode;
  }
  else{
   return ((void *)0);
  }
 }
 return ((void *)0);
}

variable_types:
eye
long double *

variable_types:
directionV
long double *

variable_types:
obj
struct object *

variable_types:
A
long double

variable_types:
B
long double

variable_types:
C
long double

variable_types:
D
long double

variable_types:
E
long double

variable_types:
F
long double

variable_types:
G
long double

variable_types:
H
long double

variable_types:
J
long double

variable_types:
K
long double

variable_types:
a
long double

variable_types:
b
long double

variable_types:
c
long double

variable_types:
xd
long double

variable_types:
yd
long double

variable_types:
zd
long double

variable_types:
xe
long double

variable_types:
ye
long double

variable_types:
ze
long double

variable_types:
disc
long double

variable_types:
t
long double

variable_types: struct intDataNode { struct intData { long double t; long double *vector; struct object { long double position[3]; struct intDataNode *(*getIntersection)(long double *eye, long double *directionV, struct object *obj); struct rgb { float r; float g; float b; } *(*getColorAt)(long double *eye, long double *directionV, struct intData *obj, struct lightNode { long double *data; long double c1; struct lightNode *next; } *lights, int rDepth, int tDepth); long double *(*getNormalV)(long double *intersection, struct object *obj); struct rgb *(*getObjectColor)(struct object *obj); struct rgb *(*getTexturesColor)(struct intData *inter); long double **(*getBumpmapVects)(struct intData *inter, struct object *sphere); void *data; long double ka; int texCount; struct objTexture { long double thRes; int mode; struct objTexture *next; } *textList; int planeCount; int *planes; int hasCutout; struct textureNode { struct rgb *data; int width; int height; int mode; struct textureNode *next; } *cutout; struct textureNode *bumpmap; int kn; long double kr; } *obj; long double u; } *data; struct intDataNode *next; } *

user_defined_types: struct intData { long double t; long double *vector; struct object *obj; long double u; }


getTexturesColorQuadratic

decompiled_code:
_DWORD *getTexturesColorQuadratic()
{
_DWORD *result; // rax

result = calloc(1uLL, 0xCuLL);
*(_QWORD *)result = 0x3F8000003F800000LL;
result[2] = 1065353216;
return result;
}

canonical_decompiled_code:
_DWORD *func2()
{
_DWORD *result; // rax

result = calloc(1uLL, 0xCuLL);
*(_QWORD *)result = 0x3F8000003F800000LL;
result[2] = 1065353216;
return result;
}

original_code:
rgb* getTexturesColorQuadratic(struct intData *inter){
 rgb *result = (rgb*) calloc (1, sizeof(rgb));
 result->r = 1; result->g = 1; result->b = 1;
 return result;
}

canonical_original_code:
struct rgb *getTexturesColorQuadratic(struct intData *inter){
 struct rgb *result = (rgb*) calloc (1, sizeof(rgb));
 result->r = 1; result->g = 1; result->b = 1;
 return result;
}

variable_types: struct intData { long double t; long double *vector; struct object { long double position[3]; struct intDataNode { struct intData *data; struct intDataNode *next; } *(*getIntersection)(long double *eye, long double *directionV, struct object *obj); struct rgb *(*getColorAt)(long double *eye, long double *directionV, struct intData *obj, struct lightNode { long double *data; long double c1; struct lightNode *next; } *lights, int rDepth, int tDepth); long double *(*getNormalV)(long double *intersection, struct object *obj); struct rgb *(*getObjectColor)(struct object *obj); struct rgb *(*getTexturesColor)(struct intData *inter); long double **(*getBumpmapVects)(struct intData *inter, struct object *sphere); void *data; long double ka; int texCount; struct objTexture { long double thRes; int mode; struct objTexture *next; } *textList; int planeCount; int *planes; int hasCutout; struct textureNode { struct rgb *data; int width; int height; int mode; struct textureNode *next; } *cutout; struct textureNode *bumpmap; int kn; long double kr; } *obj; long double u; } *

variable_types: struct rgb { float r; float g; float b; } *


getNormalVQuadratic

decompiled_code:
long double *__fastcall getNormalVQuadratic(long double *a1, __int64 a2)
{
long double *result; // rax
long double *v3; // rdx
long double v4; // fst7
long double v5; // fst6
long double v6; // fst5
long double v7; // fst4
long double v8; // fst3
long double v9; // fst2
long double v10; // fst0
long double v11; // fst1
long double v12; // fst4
long double v13; // fst0
long double v14; // fst5
long double v15; // fst7
long double v16; // fst6
double v17; // xmm0_8
long double v18; // fst4
double v19; // xmm0_8
long double v20; // [rsp+0h] [rbp-58h]
long double v21; // [rsp+10h] [rbp-48h]
long double *v22; // [rsp+10h] [rbp-48h]
long double v23; // [rsp+20h] [rbp-38h]
long double v24; // [rsp+30h] [rbp-28h]

result = (long double *)calloc(3uLL, 0x10uLL);
v3 = *(long double **)(a2 + 96);
v4 = *a1;
v5 = a1[1];
v6 = a1[2];
v20 = v3[1];
v21 = v3[2];
v7 = v3[3];
v8 = v3[4];
v9 = v3[5];
v23 = v3[7];
v24 = v3[8];
v10 = *v3 * v4 + v5 * v7 + v6 * v9 + v3[6];
*result = v10;
v11 = v7;
v12 = v10;
v13 = v11 * v4 + v20 * v5 + v6 * v8 + v23;
result[1] = v13;
v14 = v5 * v8 + v4 * v9 + v6 * v21 + v24;
result[2] = v14;
v15 = v12;
v16 = v13;
v17 = (double)v14 * (double)v14 + (double)v13 * (double)v13 + (double)v12 * (double)v12;
if ( v17 < 0.0 )
{
v22 = result;
v19 = sqrt(v17);
result = v22;
v14 = v22[2];
v16 = v22[1];
v18 = v19;
v15 = *v22;
}
else
{
v18 = sqrt(v17);
}
*result = v15 / v18;
result[1] = v16 / v18;
result[2] = v14 / v18;
return result;
}

canonical_decompiled_code:
long double *__fastcall func3(long double *a1, __int64 a2)
{
long double *result; // rax
long double *v3; // rdx
long double v4; // fst7
long double v5; // fst6
long double v6; // fst5
long double v7; // fst4
long double v8; // fst3
long double v9; // fst2
long double v10; // fst0
long double v11; // fst1
long double v12; // fst4
long double v13; // fst0
long double v14; // fst5
long double v15; // fst7
long double v16; // fst6
double v17; // xmm0_8
long double v18; // fst4
double v19; // xmm0_8
long double v20; // [rsp+0h] [rbp-58h]
long double v21; // [rsp+10h] [rbp-48h]
long double *v22; // [rsp+10h] [rbp-48h]
long double v23; // [rsp+20h] [rbp-38h]
long double v24; // [rsp+30h] [rbp-28h]

result = (long double *)calloc(3uLL, 0x10uLL);
v3 = *(long double **)(a2 + 96);
v4 = *a1;
v5 = a1[1];
v6 = a1[2];
v20 = v3[1];
v21 = v3[2];
v7 = v3[3];
v8 = v3[4];
v9 = v3[5];
v23 = v3[7];
v24 = v3[8];
v10 = *v3 * v4 + v5 * v7 + v6 * v9 + v3[6];
*result = v10;
v11 = v7;
v12 = v10;
v13 = v11 * v4 + v20 * v5 + v6 * v8 + v23;
result[1] = v13;
v14 = v5 * v8 + v4 * v9 + v6 * v21 + v24;
result[2] = v14;
v15 = v12;
v16 = v13;
v17 = (double)v14 * (double)v14 + (double)v13 * (double)v13 + (double)v12 * (double)v12;
if ( v17 < 0.0 )
{
v22 = result;
v19 = sqrt(v17);
result = v22;
v14 = v22[2];
v16 = v22[1];
v18 = v19;
v15 = *v22;
}
else
{
v18 = sqrt(v17);
}
*result = v15 / v18;
result[1] = v16 / v18;
result[2] = v14 / v18;
return result;
}

original_code:
long double *getNormalVQuadratic(long double *intersection, struct object* obj){
 long double *normal = (long double*) calloc(3, sizeof(long double));
 QuadraticData *data = (QuadraticData*)obj->data;
 long double xi, yi, zi, A, B, C, D, E, F, G, H, J, K;
 xi = intersection[0];
 yi = intersection[1];
 zi = intersection[2];
 A = data->A;
 B = data->B;
 C = data->C;
 D = data->D;
 E = data->E;
 F = data->F;
 G = data->G;
 H = data->H;
 J = data->J;
 K = data->K;
 normal[0] = (A*xi)+ (D*yi)+ (F*zi) + G;
 normal[1] = (D*xi) + (B*yi) + (E*zi) + H;
 normal[2] = (F*xi) + (E*yi) + (C*zi) + J;
 long double l = sqrt(pow(normal[0],2)+pow(normal[1],2)+pow(normal[2],2));
 normal[0] = normal[0]/l;
 normal[1] = normal[1]/l;
 normal[2] = normal[2]/l;
 return normal;
}

canonical_original_code:
long double *getNormalVQuadratic(long double *intersection, struct object *obj){
 long double *normal = (long double*) calloc(3, sizeof(long double));
 struct QuadraticData *data = (QuadraticData*)obj->data;
 long double xi; long double yi; long double zi; long double A; long double B; long double C; long double D; long double E; long double F; long double G; long double H; long double J; long double K;
 xi = intersection[0];
 yi = intersection[1];
 zi = intersection[2];
 A = data->A;
 B = data->B;
 C = data->C;
 D = data->D;
 E = data->E;
 F = data->F;
 G = data->G;
 H = data->H;
 J = data->J;
 K = data->K;
 normal[0] = (A*xi)+ (D*yi)+ (F*zi) + G;
 normal[1] = (D*xi) + (B*yi) + (E*zi) + H;
 normal[2] = (F*xi) + (E*yi) + (C*zi) + J;
 long double l = sqrt(pow(normal[0],2)+pow(normal[1],2)+pow(normal[2],2));
 normal[0] = normal[0]/l;
 normal[1] = normal[1]/l;
 normal[2] = normal[2]/l;
 return normal;
}

variable_types:
intersection
long double *

variable_types: struct object { long double position[3]; struct intDataNode { struct intData { long double t; long double *vector; struct object *obj; long double u; } *data; struct intDataNode *next; } *(*getIntersection)(long double *eye, long double *directionV, struct object *obj); struct rgb { float r; float g; float b; } *(*getColorAt)(long double *eye, long double *directionV, struct intData *obj, struct lightNode { long double *data; long double c1; struct lightNode *next; } *lights, int rDepth, int tDepth); long double *(*getNormalV)(long double *intersection, struct object *obj); struct rgb *(*getObjectColor)(struct object *obj); struct rgb *(*getTexturesColor)(struct intData *inter); long double **(*getBumpmapVects)(struct intData *inter, struct object *sphere); void *data; long double ka; int texCount; struct objTexture { long double thRes; int mode; struct objTexture *next; } *textList; int planeCount; int *planes; int hasCutout; struct textureNode { struct rgb *data; int width; int height; int mode; struct textureNode *next; } *cutout; struct textureNode *bumpmap; int kn; long double kr; } *

variable_types:
normal
long double *

variable_types: struct QuadraticData { long double A; struct rgb { float r; float g; float b; } *color; } *

variable_types:
xi
long double

variable_types:
yi
long double

variable_types:
zi
long double

variable_types:
A
long double

variable_types:
B
long double

variable_types:
C
long double

variable_types:
D
long double

variable_types:
E
long double

variable_types:
F
long double

variable_types:
G
long double

variable_types:
H
long double

variable_types:
l
long double

return_type: long double *


createQuadraticData

decompiled_code:
long double *__fastcall createQuadraticData(long double a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7, long double a8, long double a9, long double a10, long double a11, long double a12, long double a13)
{
long double *v19; // r12
float *v20; // rax

v19 = (long double *)calloc(1uLL, 0xB0uLL);
*v19 = a1;
v19[1] = a2;
v19[2] = a3;
v19[3] = a4;
v19[4] = a5;
v19[5] = a6;
v19[6] = a7;
v19[7] = a8;
v19[8] = a9;
v19[9] = a10;
v20 = (float *)calloc(1uLL, 0xCuLL);
*((_QWORD *)v19 + 20) = v20;
*v20 = a11;
v20[1] = a12;
v20[2] = a13;
return v19;
}

canonical_decompiled_code:
long double *__fastcall func4(long double a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7, long double a8, long double a9, long double a10, long double a11, long double a12, long double a13)
{
long double *v19; // r12
float *v20; // rax

v19 = (long double *)calloc(1uLL, 0xB0uLL);
*v19 = a1;
v19[1] = a2;
v19[2] = a3;
v19[3] = a4;
v19[4] = a5;
v19[5] = a6;
v19[6] = a7;
v19[7] = a8;
v19[8] = a9;
v19[9] = a10;
v20 = (float *)calloc(1uLL, 0xCuLL);
*((_QWORD *)v19 + 20) = v20;
*v20 = a11;
v20[1] = a12;
v20[2] = a13;
return v19;
}

original_code:
QuadraticData *createQuadraticData(long double A,long double B,long double C,
long double D,long double E,long double F,long double G,long double H, long double J,long double K, long double r, long double g, long double b){
 QuadraticData *data = (QuadraticData*) calloc(1, sizeof(QuadraticData));
 data->A = A;
 data->B = B;
 data->C = C;
 data->D = D;
 data->E = E;
 data->F = F;
 data->G = G;
 data->H = H;
 data->J = J;
 data->K = K;
 rgb *ncolor = (rgb*) calloc(1, sizeof(rgb));
 ncolor->r = r;
 ncolor->g = g;
 ncolor->b = b;
 data->color = ncolor;
 return data;
}

canonical_original_code:
struct QuadraticData *createQuadraticData(long double A, long double B, long double C, long double D, long double E, long double F, long double G, long double H, long double J, long double K, long double r, long double g, long double b){
 struct QuadraticData *data = (QuadraticData*) calloc(1, sizeof(QuadraticData));
 data->A = A;
 data->B = B;
 data->C = C;
 data->D = D;
 data->E = E;
 data->F = F;
 data->G = G;
 data->H = H;
 data->J = J;
 data->K = K;
 struct rgb *ncolor = (rgb*) calloc(1, sizeof(rgb));
 ncolor->r = r;
 ncolor->g = g;
 ncolor->b = b;
 data->color = ncolor;
 return data;
}

variable_types:
J
long double

variable_types:
K
long double

variable_types:
r
long double

variable_types:
g
long double

variable_types:
b
long double

return_type: struct QuadraticData { long double A; struct rgb { float r; float g; float b; } *color; } *


addLight

decompiled_code:
long double *__fastcall addLight(long double **a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7, long double a8, long double a9, long double a10, long double a11)
{
long double *v16; // rbx
long double *result; // rax
long double *v18; // rdx

v16 = (long double *)calloc(4uLL, 0x10uLL);
result = (long double *)malloc(0x80uLL);
if ( result )
{
v18 = *a1;
*(_QWORD *)result = v16;
*a1 = result;
*((_QWORD *)result + 14) = v18;
*v16 = a2;
v16[1] = a3;
v16[2] = a4;
v16[3] = a8;
result[1] = a9;
result[2] = a10;
result[3] = a11;
result[6] = a7;
result[5] = a6;
result[4] = a5;
}
return result;
}

canonical_decompiled_code:
long double *__fastcall func1(long double **a1, long double a2, long double a3, long double a4, long double a5, long double a6, long double a7, long double a8, long double a9, long double a10, long double a11)
{
long double *v16; // rbx
long double *result; // rax
long double *v18; // rdx

v16 = (long double *)calloc(4uLL, 0x10uLL);
result = (long double *)malloc(0x80uLL);
if ( result )
{
v18 = *a1;
*(_QWORD *)result = v16;
*a1 = result;
*((_QWORD *)result + 14) = v18;
*v16 = a2;
v16[1] = a3;
v16[2] = a4;
v16[3] = a8;
result[1] = a9;
result[2] = a10;
result[3] = a11;
result[6] = a7;
result[5] = a6;
result[4] = a5;
}
return result;
}

original_code:
lightNode *addLight(lightNode **previous, long double x, long double y, long double z, long double r, long double g, long double b, long double i, long double c1, long double c2, long double c3)
{
 long double *newData = (long double*)calloc(4, sizeof(long double));
 lightNode *newNode = malloc(sizeof(lightNode));
 if (newNode == ((void *)0))
 return ((void *)0);
 newData[0] = x;
 newData[1] = y;
 newData[2] = z;
 newData[3] = i;
 newNode->next = *previous;
 *previous = newNode;
 newNode->data = newData;
 newNode->c1 = c1;
 newNode->c2 = c2;
 newNode->c3 = c3;
 newNode->b = b;
 newNode->g = g;
 newNode->r = r;
 return *previous;
}

canonical_original_code:
struct lightNode *addLight(struct lightNode **previous, long double x, long double y, long double z, long double r, long double g, long double b, long double i, long double c1, long double c2, long double c3)
{
 long double *newData = (long double*)calloc(4, sizeof(long double));
 struct lightNode *newNode = malloc(sizeof(lightNode));
 if (newNode == ((void *)0))
 return ((void *)0);
 newData[0] = x;
 newData[1] = y;
 newData[2] = z;
 newData[3] = i;
 newNode->next = *previous;
 *previous = newNode;
 newNode->data = newData;
 newNode->c1 = c1;
 newNode->c2 = c2;
 newNode->c3 = c3;
 newNode->b = b;
 newNode->g = g;
 newNode->r = r;
 return *previous;
}

variable_types:
previous
struct lightNode **

variable_types:
x
long double

variable_types:
y
long double

variable_types:
z
long double

variable_types:
i
long double

variable_types:
newData
long double *

variable_types: struct lightNode { long double *data; long double c1; struct lightNode *next; } *


get

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

for ( result = a2; a1; --a1 )
result = *(_QWORD *)(result + 24);
return result;
}

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

for ( result = a2; a1; --a1 )
result = *(_QWORD *)(result + 24);
return result;
}

original_code:
textureNode *get(int count, textureNode *txt){
 textureNode *hey = txt;
 while(count != 0){
  hey = hey->next;
  count--;
 }
 return hey;
}

canonical_original_code:
struct textureNode *get(int count, struct textureNode *txt){
 struct textureNode *hey = txt;
 while(count != 0){
  hey = hey->next;
  count--;
 }
 return hey;
}

variable_types: count int

variable_types:
txt
struct textureNode *

variable_types: struct textureNode { struct rgb { float r; float g; float b; } *data; int width; int height; int mode; struct textureNode *next; } *

user_defined_types: struct textureNode { struct rgb *data; int width; int height; int mode; struct textureNode *next; }


addCutPlane

decompiled_code:
long double *__fastcall addCutPlane(long double **a1, long double *a2)
{
long double *v2; // r15
long double *v3; // r13
long double *v4; // rax
long double v5; // fst7
long double *v6; // r14
long double v7; // fst6
long double v8; // fst5
long double v9; // fst4
long double v10; // fst3
long double v11; // fst2
long double v12; // rt1
long double v13; // fst2
long double v14; // rtt
long double v15; // fst2
long double v16; // fst0
long double v17; // rt2
long double v18; // fst5
long double v19; // fst7
long double v20; // fst6
long double v21; // fst4
long double v22; // fst5
double v23; // xmm0_8
long double v24; // fst3
long double v25; // rt1
long double v26; // fst3
long double v27; // fst3
long double v28; // fst4
long double *v29; // r12
long double *v30; // rax
long double v32; // [rsp+0h] [rbp-88h]
long double v33; // [rsp+0h] [rbp-88h]
long double v34; // [rsp+20h] [rbp-68h]
long double v35; // [rsp+30h] [rbp-58h]

v2 = (long double *)calloc(3uLL, 0x10uLL);
v3 = (long double *)calloc(3uLL, 0x10uLL);
v4 = (long double *)calloc(3uLL, 0x10uLL);
v5 = *a2;
v6 = v4;
v7 = a2[3] - v5;
*v2 = v7;
v8 = a2[1];
v9 = a2[4] - v8;
v2[1] = v9;
v10 = a2[2];
v11 = a2[5] - v10;
v2[2] = v11;
v12 = v11;
v13 = a2[6] - v5;
*v3 = v13;
v34 = v8;
v14 = v13;
v32 = a2[7] - v8;
v3[1] = v32;
v15 = a2[8] - v10;
v3[2] = v15;
v16 = v9 * v15;
v17 = v12 * v14 - v15 * v7;
v18 = v7 * v32 - v14 * v9;
v19 = -(v5 * (v16 - v12 * v32) + v34 * v17 + v10 * v18);
v20 = v16 - v12 * v32;
v21 = v18;
v22 = v17;
v23 = (double)v21 * (double)v21 + (double)v20 * (double)v20 + (double)v17 * (double)v17;
if ( v23 < 0.0 )
v24 = sqrt(v23);
else
v24 = sqrt(v23);
v25 = v24;
v26 = v20 / v24;
*v6 = v26;
v35 = v26;
v27 = v22 / v25;
v6[1] = v27;
v28 = v21 / v25;
v6[2] = v28;
v33 = v19 / v25;
v29 = (long double *)malloc(0x50uLL);
if ( v29 )
{
v30 = *a1;
*a1 = v29;
*((_QWORD *)v29 + 8) = v30;
*v29 = v35;
v29[1] = v27;
v29[2] = v28;
v29[3] = v33;
free(v2);
free(v3);
free(v6);
}
return v29;
}

canonical_decompiled_code:
long double *__fastcall func3(long double **a1, long double *a2)
{
long double *v2; // r15
long double *v3; // r13
long double *v4; // rax
long double v5; // fst7
long double *v6; // r14
long double v7; // fst6
long double v8; // fst5
long double v9; // fst4
long double v10; // fst3
long double v11; // fst2
long double v12; // rt1
long double v13; // fst2
long double v14; // rtt
long double v15; // fst2
long double v16; // fst0
long double v17; // rt2
long double v18; // fst5
long double v19; // fst7
long double v20; // fst6
long double v21; // fst4
long double v22; // fst5
double v23; // xmm0_8
long double v24; // fst3
long double v25; // rt1
long double v26; // fst3
long double v27; // fst3
long double v28; // fst4
long double *v29; // r12
long double *v30; // rax
long double v32; // [rsp+0h] [rbp-88h]
long double v33; // [rsp+0h] [rbp-88h]
long double v34; // [rsp+20h] [rbp-68h]
long double v35; // [rsp+30h] [rbp-58h]

v2 = (long double *)calloc(3uLL, 0x10uLL);
v3 = (long double *)calloc(3uLL, 0x10uLL);
v4 = (long double *)calloc(3uLL, 0x10uLL);
v5 = *a2;
v6 = v4;
v7 = a2[3] - v5;
*v2 = v7;
v8 = a2[1];
v9 = a2[4] - v8;
v2[1] = v9;
v10 = a2[2];
v11 = a2[5] - v10;
v2[2] = v11;
v12 = v11;
v13 = a2[6] - v5;
*v3 = v13;
v34 = v8;
v14 = v13;
v32 = a2[7] - v8;
v3[1] = v32;
v15 = a2[8] - v10;
v3[2] = v15;
v16 = v9 * v15;
v17 = v12 * v14 - v15 * v7;
v18 = v7 * v32 - v14 * v9;
v19 = -(v5 * (v16 - v12 * v32) + v34 * v17 + v10 * v18);
v20 = v16 - v12 * v32;
v21 = v18;
v22 = v17;
v23 = (double)v21 * (double)v21 + (double)v20 * (double)v20 + (double)v17 * (double)v17;
if ( v23 < 0.0 )
v24 = sqrt(v23);
else
v24 = sqrt(v23);
v25 = v24;
v26 = v20 / v24;
*v6 = v26;
v35 = v26;
v27 = v22 / v25;
v6[1] = v27;
v28 = v21 / v25;
v6[2] = v28;
v33 = v19 / v25;
v29 = (long double *)malloc(0x50uLL);
if ( v29 )
{
v30 = *a1;
*a1 = v29;
*((_QWORD *)v29 + 8) = v30;
*v29 = v35;
v29[1] = v27;
v29[2] = v28;
v29[3] = v33;
free(v2);
free(v3);
free(v6);
}
return v29;
}

original_code:
cutPlane *addCutPlane(cutPlane **previous, ptsNode *points)
{
 long double d;
 long double *vect1 = (long double*) calloc(3, sizeof(long double));
 long double *vect2 = (long double*) calloc(3, sizeof(long double));
 long double *norm = (long double*) calloc(3, sizeof(long double));
 vect1[0] = points[1].x - points[0].x;
 vect1[1] = points[1].y - points[0].y;
 vect1[2] = points[1].z - points[0].z;
 vect2[0] = points[2].x - points[0].x;
 vect2[1] = points[2].y - points[0].y;
 vect2[2] = points[2].z - points[0].z;
 norm[0] = (vect1[1] * vect2[2]) - (vect2[1] * vect1[2]);
 norm[1] = (vect2[0] * vect1[2]) - (vect1[0] * vect2[2]);
 norm[2] = (vect1[0] * vect2[1]) - (vect2[0] * vect1[1]);
 d = -(norm[0]*points[0].x + norm[1]*points[0].y + norm[2]*points[0].z);
 long double l = sqrt(pow(norm[0],2) + pow(norm[1],2) + pow(norm[2],2));
 norm[0] = norm[0]/l;
 norm[1] = norm[1]/l;
 norm[2] = norm[2]/l;
 d = d/l;
 cutPlane *newNode = malloc(sizeof(cutPlane));
 if (newNode == ((void *)0))
  return ((void *)0);
 newNode->next = *previous;
 *previous = newNode;
 newNode->a = norm[0];
 newNode->b = norm[1];
 newNode->c = norm[2];
 newNode->d = d;
 free(vect1);
 free(vect2);
 free(norm);
 return *previous;
}

canonical_original_code:
struct cutPlane *addCutPlane(struct cutPlane **previous, struct ptsNode *points)
{
 long double d;
 long double *vect1 = (long double*) calloc(3, sizeof(long double));
 long double *vect2 = (long double*) calloc(3, sizeof(long double));
 long double *norm = (long double*) calloc(3, sizeof(long double));
 vect1[0] = points[1].x - points[0].x;
 vect1[1] = points[1].y - points[0].y;
 vect1[2] = points[1].z - points[0].z;
 vect2[0] = points[2].x - points[0].x;
 vect2[1] = points[2].y - points[0].y;
 vect2[2] = points[2].z - points[0].z;
 norm[0] = (vect1[1] * vect2[2]) - (vect2[1] * vect1[2]);
 norm[1] = (vect2[0] * vect1[2]) - (vect1[0] * vect2[2]);
 norm[2] = (vect1[0] * vect2[1]) - (vect2[0] * vect1[1]);
 d = -(norm[0]*points[0].x + norm[1]*points[0].y + norm[2]*points[0].z);
 long double l = sqrt(pow(norm[0],2) + pow(norm[1],2) + pow(norm[2],2));
 norm[0] = norm[0]/l;
 norm[1] = norm[1]/l;
 norm[2] = norm[2]/l;
 d = d/l;
 struct cutPlane *newNode = malloc(sizeof(cutPlane));
 if (newNode == ((void *)0))
  return ((void *)0);
 newNode->next = *previous;
 *previous = newNode;
 newNode->a = norm[0];
 newNode->b = norm[1];
 newNode->c = norm[2];
 newNode->d = d;
 free(vect1);
 free(vect2);
 free(norm);
 return *previous;
}

variable_types:
previous
struct cutPlane **

variable_types:
points
struct ptsNode { long double x; } *

variable_types:
d
long double

variable_types:
norm
long double *

variable_types: struct cutPlane { long double a; struct cutPlane *next; } *


getCutPlane

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

for ( result = a2; a1; --a1 )
result = *(_QWORD *)(result + 64);
return result;
}

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

for ( result = a2; a1; --a1 )
result = *(_QWORD *)(result + 64);
return result;
}

original_code:
cutPlane *getCutPlane(int count, cutPlane *planes){
 cutPlane *current = planes;
 while(count != 0){
  count--;
  current = current->next;
 }
 return current;
}

canonical_original_code:
struct cutPlane *getCutPlane(int count, struct cutPlane *planes){
 struct cutPlane *current = planes;
 while(count != 0){
  count--;
  current = current->next;
 }
 return current;
}

variable_types:
planes
struct cutPlane *

return_type: struct cutPlane { long double a; struct cutPlane *next; } *


getObjectColorDisc

decompiled_code:
__int64 __fastcall getObjectColorDisc(__int64 a1)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 96) + 152LL);
}

original_code:
rgb* getObjectColorDisc(struct object *disc){
 DiscData *data = (DiscData*)disc->data;
 return data->color;
}

canonical_original_code:
struct rgb *getObjectColorDisc(struct object *disc){
 struct DiscData *data = (DiscData*)disc->data;
 return data->color;
}

variable_types: struct object { long double position[3]; struct intDataNode { struct intData { long double t; long double *vector; struct object *obj; long double u; } *data; struct intDataNode *next; } *(*getIntersection)(long double *eye, long double *directionV, struct object *obj); struct rgb *(*getColorAt)(long double *eye, long double *directionV, struct intData *obj, struct lightNode { long double *data; long double c1; struct lightNode *next; } *lights, int rDepth, int tDepth); long double *(*getNormalV)(long double *intersection, struct object *obj); struct rgb *(*getObjectColor)(struct object *obj); struct rgb *(*getTexturesColor)(struct intData *inter); long double **(*getBumpmapVects)(struct intData *inter, struct object *sphere); void *data; long double ka; int texCount; struct objTexture { long double thRes; int mode; struct objTexture *next; } *textList; int planeCount; int *planes; int hasCutout; struct textureNode { struct rgb *data; int width; int height; int mode; struct textureNode *next; } *cutout; struct textureNode *bumpmap; int kn; long double kr; } *

variable_types: struct DiscData { long double a; long double *origin; long double *V; long double *U; struct rgb { float r; float g; float b; } *color; } *

user_defined_types: struct DiscData { long double a; long double *origin; long double *V; long double *U; struct rgb *color; }


getNormalVDisc

decompiled_code:
long double *__fastcall getNormalVDisc(__int64 a1, __int64 a2)
{
long double *result; // rax
long double *v3; // rdx

result = (long double *)calloc(3uLL, 0x10uLL);
v3 = *(long double **)(a2 + 96);
*result = *v3;
result[1] = v3[1];
result[2] = v3[2];
return result;
}

canonical_decompiled_code:
long double *__fastcall func1(__int64 a1, __int64 a2)
{
long double *result; // rax
long double *v3; // rdx

result = (long double *)calloc(3uLL, 0x10uLL);
v3 = *(long double **)(a2 + 96);
*result = *v3;
result[1] = v3[1];
result[2] = v3[2];
return result;
}

original_code:
long double *getNormalVDisc(long double *intersection, struct object * obj){
 long double *V = (long double*)calloc(3, sizeof(long double));
 DiscData *data = (DiscData*)obj->data;
 V[0] = data->a;
 V[1] = data->b;
 V[2] = data->c;
 return V;
}

canonical_original_code:
long double *getNormalVDisc(long double *intersection, struct object *obj){
 long double *V = (long double*)calloc(3, sizeof(long double));
 struct DiscData *data = (DiscData*)obj->data;
 V[0] = data->a;
 V[1] = data->b;
 V[2] = data->c;
 return V;
}

variable_types:
intersection
long double *

variable_types: struct object { long double position[3]; struct intDataNode { struct intData { long double t; long double *vector; struct object *obj; long double u; } *data; struct intDataNode *next; } *(*getIntersection)(long double *eye, long double *directionV, struct object *obj); struct rgb { float r; float g; float b; } *(*getColorAt)(long double *eye, long double *directionV, struct intData *obj, struct lightNode { long double *data; long double c1; struct lightNode *next; } *lights, int rDepth, int tDepth); long double *(*getNormalV)(long double *intersection, struct object *obj); struct rgb *(*getObjectColor)(struct object *obj); struct rgb *(*getTexturesColor)(struct intData *inter); long double **(*getBumpmapVects)(struct intData *inter, struct object *sphere); void *data; long double ka; int texCount; struct objTexture { long double thRes; int mode; struct objTexture *next; } *textList; int planeCount; int *planes; int hasCutout; struct textureNode { struct rgb *data; int width; int height; int mode; struct textureNode *next; } *cutout; struct textureNode *bumpmap; int kn; long double kr; } *

variable_types:
V
long double *


getUVDisc

decompiled_code:
long double *getUVDisc()
{
long double *result; // rax

result = (long double *)calloc(2uLL, 0x10uLL);
*result = 0.5;
result[1] = *result;
return result;
}

canonical_decompiled_code:
long double *func2()
{
long double *result; // rax

result = (long double *)calloc(2uLL, 0x10uLL);
*result = 0.5;
result[1] = *result;
return result;
}

original_code:
long double *getUVDisc(struct intData *inter){
 long double *result = (long double*) calloc(2, sizeof(long double));
 result[0] = 0.5;
 result[1] = 0.5;
 return result;
}

variable_types: struct intData { long double t; long double *vector; struct object { long double position[3]; struct intDataNode { struct intData *data; struct intDataNode *next; } *(*getIntersection)(long double *eye, long double *directionV, struct object *obj); struct rgb { float r; float g; float b; } *(*getColorAt)(long double *eye, long double *directionV, struct intData *obj, struct lightNode { long double *data; long double c1; struct lightNode *next; } *lights, int rDepth, int tDepth); long double *(*getNormalV)(long double *intersection, struct object *obj); struct rgb *(*getObjectColor)(struct object *obj); struct rgb *(*getTexturesColor)(struct intData *inter); long double **(*getBumpmapVects)(struct intData *inter, struct object *sphere); void *data; long double ka; int texCount; struct objTexture { long double thRes; int mode; struct objTexture *next; } *textList; int planeCount; int *planes; int hasCutout; struct textureNode { struct rgb *data; int width; int height; int mode; struct textureNode *next; } *cutout; struct textureNode *bumpmap; int kn; long double kr; } *obj; long double u; } *

variable_types:
result
long double *


setup

repo: Fireedud/Brainfuck

decompiled_code:
void *__fastcall setup(int a1)
{
return calloc(a1, 4uLL);
}

canonical_decompiled_code:
void *__fastcall func7(int a1)
{
return calloc(a1, 4uLL);
}

original_code:
char *setup(int size)
{
 char *ptr = calloc(size, sizeof(int));
 return ptr;
}

variable_types: size int

variable_types:
ptr
char *

return_type: char *


eval

decompiled_code:
__int64 __fastcall eval(unsigned __int8 *a1, _BYTE *a2, __int64 a3)
{
__int64 result; // rax
int v6; // ebx
__int64 v7; // rax
int v8; // eax
__int64 v9; // rax

result = *a1;
if ( (unsigned __int8)(result + 1) > 1u )
{
v6 = 0;
do
{
switch ( (char)result )
{
case '+':
++*a2;
break;
case ',':
*a2 = getchar();
break;
case '-':
--*a2;
break;
case '.':
putchar((char)*a2);
break;
case '<':
--a2;
break;
case '>':
++a2;
break;
case '[':
if ( *a2 )
{
v8 = *(_DWORD *)(a3 + 400) + 1;
*(_DWORD *)(a3 + 400) = v8;
if ( *(_DWORD *)(a3 + 4LL * v8) != v6 )
*(_DWORD *)(a3 + 4LL * v8) = v6;
}
else if ( a1[v6] != 93 )
{
v9 = v6 + 1;
do
v6 = v9++;
while ( a1[v9 - 1] != 93 );
}
break;
case ']':
v7 = *(int *)(a3 + 400);
if ( *a2 )
v6 = *(_DWORD *)(a3 + 4 * v7);
else
*(_DWORD *)(a3 + 400) = v7 - 1;
break;
default:
break;
}
result = a1[++v6];
}
while ( (unsigned __int8)(result + 1) > 1u );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1, _BYTE *a2, __int64 a3)
{
__int64 result; // rax
int v6; // ebx
__int64 v7; // rax
int v8; // eax
__int64 v9; // rax

result = *a1;
if ( (unsigned __int8)(result + 1) > 1u )
{
v6 = 0;
do
{
switch ( (char)result )
{
case '+':
++*a2;
break;
case ',':
*a2 = getchar();
break;
case '-':
--*a2;
break;
case '.':
putchar((char)*a2);
break;
case '<':
--a2;
break;
case '>':
++a2;
break;
case '[':
if ( *a2 )
{
v8 = *(_DWORD *)(a3 + 400) + 1;
*(_DWORD *)(a3 + 400) = v8;
if ( *(_DWORD *)(a3 + 4LL * v8) != v6 )
*(_DWORD *)(a3 + 4LL * v8) = v6;
}
else if ( a1[v6] != 93 )
{
v9 = v6 + 1;
do
v6 = v9++;
while ( a1[v9 - 1] != 93 );
}
break;
case ']':
v7 = *(int *)(a3 + 400);
if ( *a2 )
v6 = *(_DWORD *)(a3 + 4 * v7);
else
*(_DWORD *)(a3 + 400) = v7 - 1;
break;
default:
break;
}
result = a1[++v6];
}
while ( (unsigned __int8)(result + 1) > 1u );
}
return result;
}

original_code:
void eval(char line[], char *ptr, struct LeftBrackets *list)
{
 int i = 0;
 for(i=0; line[i] != (-1) && line[i] != '\0'; i++) {
  switch(line[i]) {
   case '>':
    ptr++;
    break;
   case '<':
    ptr--;
    break;
   case '+':
    (*ptr)++;
    break;
   case '-':
    (*ptr)--;
    break;
   case '.':
    putchar(*ptr);
    break;
   case ',':
    *ptr = getchar();
    break;
   case '[':
    if(*ptr == '\0') {
     int j = i;
     while(line[j] != ']'){
      j++;
     }
     i = j;
    } else {
     (list->counter)++;
     if(list->loc[(list->counter)] != i) {
      list->loc[list->counter] = i;
     }
    }
    break;
   case ']':
    if(*ptr != '\0') {
     i = list->loc[list->counter];
    } else {
     (list->counter)--;
    }
    break;
   default:
    break;
  }
 }
}

variable_types:
line
char []

variable_types: struct LeftBrackets { int loc[100]; int counter; } *

variable_types: i int

variable_types: j int

return_type: void


repo: FlorianHe/spacewar

decompiled_code:
int __fastcall is_dead(__int64 a1, __int64 a2, __int64 a3)
{
int v4; // er13

v4 = *(_DWORD *)(a2 + 24);
graph_mort();
deletenode(a1, *(unsigned int *)(a2 + 24));
*(_DWORD *)(a3 + 4LL * v4 + 16) = 0;
return close(v4);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
int v4; // er13

v4 = *(_DWORD *)(a2 + 24);
graph_mort();
deletenode(a1, *(unsigned int *)(a2 + 24));
*(_DWORD *)(a3 + 4LL * v4 + 16) = 0;
return close(v4);
}

original_code:
void is_dead(t_player **list, t_player *pl, t_serv *serv)
{
  int fd;
  fd = pl->player_fd;
  graph_mort(list, pl);
  deletenode(list, pl->player_fd);
  serv->fd_type[fd] = 0;
  close(fd);
}

canonical_original_code:
void is_dead(struct s_player **list, struct s_player *pl, struct s_serv *serv)
{
  int fd;
  fd = pl->player_fd;
  graph_mort(list, pl);
  deletenode(list, pl->player_fd);
  serv->fd_type[fd] = 0;
  close(fd);
}

variable_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } **

variable_types:
pl
struct s_player *

variable_types: struct s_serv { int player; int game; int port; int id_player; int fd_type[512]; void (*fct_read[512])(); struct s_player *next; } *

variable_types: fd int

user_defined_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile *missile; struct s_player *next; }


decompiled_code:
unsigned int __fastcall applique_mort(__int64 a1, _DWORD *a2, __int64 a3)
{
int v3; // eax
unsigned int result; // eax

if ( (unsigned int)(*a2 - 405) <= 0x1E
|| (unsigned int)(*a2 - 365) <= 0x1E
|| (v3 = a2[1], (unsigned int)(v3 - 405) <= 0x1E)
|| (result = v3 - 365, result <= 0x1E) )
{
result = is_dead(a1, (__int64)a2, a3);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func1(__int64 a1, _DWORD *a2, __int64 a3)
{
int v3; // eax
unsigned int result; // eax

if ( (unsigned int)(*a2 - 405) <= 0x1E
|| (unsigned int)(*a2 - 365) <= 0x1E
|| (v3 = a2[1], (unsigned int)(v3 - 405) <= 0x1E)
|| (result = v3 - 365, result <= 0x1E) )
{
result = func0(a1, (__int64)a2, a3);
}
return result;
}

original_code:
void applique_mort(t_player **list, t_player *pl, t_serv *serv)
{
  if (pl->X - 20 >= 385 && pl->X - 20 <= 415)
    is_dead(list, pl, serv);
  else if (pl->X + 20 >= 385 && pl->X + 20 <= 415)
    is_dead(list, pl, serv);
  else if (pl->Y - 20 >= 385 && pl->Y - 20 <= 415)
    is_dead(list, pl, serv);
  else if (pl->Y + 20 >= 385 && pl->Y + 20 <= 415)
    is_dead(list, pl, serv);
}

canonical_original_code:
void applique_mort(struct s_player **list, struct s_player *pl, struct s_serv *serv)
{
  if (pl->X - 20 >= 385 && pl->X - 20 <= 415)
    is_dead(list, pl, serv);
  else if (pl->X + 20 >= 385 && pl->X + 20 <= 415)
    is_dead(list, pl, serv);
  else if (pl->Y - 20 >= 385 && pl->Y - 20 <= 415)
    is_dead(list, pl, serv);
  else if (pl->Y + 20 >= 385 && pl->Y + 20 <= 415)
    is_dead(list, pl, serv);
}

user_defined_types: struct s_serv { int player; int game; int port; int id_player; int fd_type[512]; void (*fct_read[512])(); struct s_player *next; }

user_defined_types: struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; }


mort

decompiled_code:
unsigned int __fastcall mort(__int64 *a1, __int64 a2)
{
__int64 i; // rbx
unsigned int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(i + 24);
if ( result )
break;
i = *(_QWORD *)(i + 40);
if ( !i )
return result;
}
result = applique_mort((__int64)a1, (_DWORD *)i, a2);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func2(__int64 *a1, __int64 a2)
{
__int64 i; // rbx
unsigned int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(i + 24);
if ( result )
break;
i = *(_QWORD *)(i + 40);
if ( !i )
return result;
}
result = func1((__int64)a1, (_DWORD *)i, a2);
}
return result;
}

original_code:
void mort(t_player **list, t_serv *serv)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 applique_mort(list, tmp, serv);
      tmp = tmp->next;
    }
}

canonical_original_code:
void mort(struct s_player **list, struct s_serv *serv)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 applique_mort(list, tmp, serv);
      tmp = tmp->next;
    }
}

variable_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *


decompiled_code:
__int64 __fastcall gravite_top_left(__int64 a1, _DWORD *a2)
{
++*a2;
++a2[1];
return graph_avance();
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2)
{
++*a2;
++a2[1];
return graph_avance();
}

original_code:
void gravite_top_left(t_player **list, t_player *pl)
{
  pl->X += 1;
  pl->Y += 1;
  graph_avance(list, pl);
}

canonical_original_code:
void gravite_top_left(struct s_player **list, struct s_player *pl)
{
  pl->X += 1;
  pl->Y += 1;
  graph_avance(list, pl);
}


decompiled_code:
__int64 __fastcall gravite_top_right(__int64 a1, _DWORD *a2)
{
--*a2;
++a2[1];
return graph_avance();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2)
{
--*a2;
++a2[1];
return graph_avance();
}

original_code:
void gravite_top_right(t_player **list, t_player *pl)
{
  pl->X -= 1;
  pl->Y += 1;
  graph_avance(list, pl);
}

canonical_original_code:
void gravite_top_right(struct s_player **list, struct s_player *pl)
{
  pl->X -= 1;
  pl->Y += 1;
  graph_avance(list, pl);
}


decompiled_code:
__int64 __fastcall gravite_bot_left(__int64 a1, _DWORD *a2)
{
++*a2;
--a2[1];
return graph_avance();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _DWORD *a2)
{
++*a2;
--a2[1];
return graph_avance();
}

original_code:
void gravite_bot_left(t_player **list, t_player *pl)
{
  pl->X += 1;
  pl->Y -= 1;
  graph_avance(list, pl);
}

canonical_original_code:
void gravite_bot_left(struct s_player **list, struct s_player *pl)
{
  pl->X += 1;
  pl->Y -= 1;
  graph_avance(list, pl);
}


decompiled_code:
__int64 __fastcall gravite_bot_right(__int64 a1, _DWORD *a2)
{
--*a2;
--a2[1];
return graph_avance();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2)
{
--*a2;
--a2[1];
return graph_avance();
}

original_code:
void gravite_bot_right(t_player **list, t_player *pl)
{
  pl->X -= 1;
  pl->Y -= 1;
  graph_avance(list, pl);
}

canonical_original_code:
void gravite_bot_right(struct s_player **list, struct s_player *pl)
{
  pl->X -= 1;
  pl->Y -= 1;
  graph_avance(list, pl);
}


decompiled_code:
__int64 __fastcall applique_gravite(__int64 a1, int *a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // edx
__int64 result; // rax

v2 = a2[2];
if ( v2 > 9999 )
{
v3 = *a2;
if ( (unsigned int)*a2 > 0x190 )
{
result = (unsigned int)(v3 - 400);
if ( (unsigned int)result <= 0x190 )
{
result = (unsigned int)a2[1];
if ( (unsigned int)(result - 400) > 0x190 )
{
if ( (unsigned int)result <= 0x190 )
result = gravite_top_right(a1, a2);
goto LABEL_7;
}
LABEL_14:
result = gravite_bot_right(a1, a2);
goto LABEL_7;
}
}
else
{
v4 = a2[1];
if ( v4 <= 0x190 )
{
result = gravite_top_left(a1, a2);
goto LABEL_7;
}
result = (unsigned int)(v3 - 400);
if ( (unsigned int)result > 0x190 )
{
if ( v4 - 400 <= 0x190 )
result = gravite_bot_left(a1, a2);
goto LABEL_7;
}
if ( v4 - 400 <= 0x190 )
goto LABEL_14;
}
LABEL_7:
a2[2] = 0;
return result;
}
result = (unsigned int)(v2 + 1);
a2[2] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int *a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // edx
__int64 result; // rax

v2 = a2[2];
if ( v2 > 9999 )
{
v3 = *a2;
if ( (unsigned int)*a2 > 0x190 )
{
result = (unsigned int)(v3 - 400);
if ( (unsigned int)result <= 0x190 )
{
result = (unsigned int)a2[1];
if ( (unsigned int)(result - 400) > 0x190 )
{
if ( (unsigned int)result <= 0x190 )
result = func1(a1, a2);
goto LABEL_7;
}
LABEL_14:
result = func3(a1, a2);
goto LABEL_7;
}
}
else
{
v4 = a2[1];
if ( v4 <= 0x190 )
{
result = func0(a1, a2);
goto LABEL_7;
}
result = (unsigned int)(v3 - 400);
if ( (unsigned int)result > 0x190 )
{
if ( v4 - 400 <= 0x190 )
result = func2(a1, a2);
goto LABEL_7;
}
if ( v4 - 400 <= 0x190 )
goto LABEL_14;
}
LABEL_7:
a2[2] = 0;
return result;
}
result = (unsigned int)(v2 + 1);
a2[2] = result;
return result;
}

original_code:
void applique_gravite(t_player **list, t_player *pl)
{
  if (pl->time >= 10000)
    {
      if (pl->X >= 0 && pl->X <= 400 && pl->Y >= 0 && pl->Y <= 400)
 gravite_top_left(list, pl);
      else if (pl->X >= 400 && pl->X <= 800 && pl->Y <= 800 && pl->Y >= 400)
 gravite_bot_right(list, pl);
      else if (pl->X >= 0 && pl->X <= 400 && pl->Y <= 800 && pl->Y >= 400)
 gravite_bot_left(list, pl);
      else if (pl->X >= 400 && pl->X <= 800 && pl->Y <= 400 && pl->Y >= 0)
 gravite_top_right(list, pl);
      pl->time = 0;
    }
  else
    pl->time++;
}

canonical_original_code:
void applique_gravite(struct s_player **list, struct s_player *pl)
{
  if (pl->time >= 10000)
    {
      if (pl->X >= 0 && pl->X <= 400 && pl->Y >= 0 && pl->Y <= 400)
 gravite_top_left(list, pl);
      else if (pl->X >= 400 && pl->X <= 800 && pl->Y <= 800 && pl->Y >= 400)
 gravite_bot_right(list, pl);
      else if (pl->X >= 0 && pl->X <= 400 && pl->Y <= 800 && pl->Y >= 400)
 gravite_bot_left(list, pl);
      else if (pl->X >= 400 && pl->X <= 800 && pl->Y <= 400 && pl->Y >= 0)
 gravite_top_right(list, pl);
      pl->time = 0;
    }
  else
    pl->time++;
}


decompiled_code:
int __fastcall init_player(__int64 a1, int a2)
{
int v2; // eax
unsigned int v3; // eax
int result; // eax
__int64 i; // rbx
int v6; // ebp
size_t v7; // rax
unsigned int v8; // [rsp+0h] [rbp-148h] BYREF
unsigned int v9; // [rsp+4h] [rbp-144h]
unsigned int v10; // [rsp+14h] [rbp-134h]
int v11; // [rsp+18h] [rbp-130h]
__int64 v12; // [rsp+20h] [rbp-128h]
char s[248]; // [rsp+30h] [rbp-118h] BYREF
int v14; // [rsp+128h] [rbp-20h]
__int16 v15; // [rsp+12Ch] [rbp-1Ch]

v8 = rand() % 800;
v2 = rand() % 800;
v9 = v2;
if ( v8 - 300 <= 0xC8 )
{
v8 = rand() % 300;
if ( v9 - 300 > 0xC8 )
goto LABEL_3;
}
else if ( (unsigned int)(v2 - 300) > 0xC8 )
{
goto LABEL_3;
}
v9 = rand() % 300;
LABEL_3:
v3 = *(_DWORD *)(a1 + 12);
v11 = a2;
v12 = 0LL;
v10 = v3;
*(_DWORD *)(a1 + 12) = v3 + 1;
addnode(a1 + 6160, &v8);
memset(s, 0, sizeof(s));
v15 = 0;
v14 = 0;
result = sprintf(s, "New %d %d %d 0\n", v10, v8, v9);
for ( i = *(_QWORD *)(a1 + 6160); i; i = *(_QWORD *)(i + 40) )
{
while ( 1 )
{
v6 = *(_DWORD *)(i + 24);
if ( v6 )
break;
i = *(_QWORD *)(i + 40);
if ( !i )
return result;
}
v7 = strlen(s);
result = write(v6, s, v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
int v2; // eax
unsigned int v3; // eax
int result; // eax
__int64 i; // rbx
int v6; // ebp
size_t v7; // rax
unsigned int v8; // [rsp+0h] [rbp-148h] BYREF
unsigned int v9; // [rsp+4h] [rbp-144h]
unsigned int v10; // [rsp+14h] [rbp-134h]
int v11; // [rsp+18h] [rbp-130h]
__int64 v12; // [rsp+20h] [rbp-128h]
char s[248]; // [rsp+30h] [rbp-118h] BYREF
int v14; // [rsp+128h] [rbp-20h]
__int16 v15; // [rsp+12Ch] [rbp-1Ch]

v8 = rand() % 800;
v2 = rand() % 800;
v9 = v2;
if ( v8 - 300 <= 0xC8 )
{
v8 = rand() % 300;
if ( v9 - 300 > 0xC8 )
goto LABEL_3;
}
else if ( (unsigned int)(v2 - 300) > 0xC8 )
{
goto LABEL_3;
}
v9 = rand() % 300;
LABEL_3:
v3 = *(_DWORD *)(a1 + 12);
v11 = a2;
v12 = 0LL;
v10 = v3;
*(_DWORD *)(a1 + 12) = v3 + 1;
addnode(a1 + 6160, &v8);
memset(s, 0, sizeof(s));
v15 = 0;
v14 = 0;
result = sprintf(s, "New %d %d %d 0\n", v10, v8, v9);
for ( i = *(_QWORD *)(a1 + 6160); i; i = *(_QWORD *)(i + 40) )
{
while ( 1 )
{
v6 = *(_DWORD *)(i + 24);
if ( v6 )
break;
i = *(_QWORD *)(i + 40);
if ( !i )
return result;
}
v7 = strlen(s);
result = write(v6, s, v7);
}
return result;
}

original_code:
void init_player(t_serv *serv, int fd)
{
  char buff[254];
  t_player new;
  t_player *tmp;
  new.X = rand() % 800;
  new.Y = rand() % 800;
  if (new.X >= 300 && new.X <= 500)
    new.X = rand() % 300;
  if (new.Y >= 300 && new.Y <= 500)
    new.Y = rand() % 300;
  new.player_id = serv->id_player++;
  new.player_fd = fd;
  new.missile = ((void *)0);
  addnode(&(serv->next), &new);
  memset(buff, '\0', 254);
  sprintf(buff, "New %d %d %d 0\n", new.player_id, new.X,
   new.Y);
  tmp = serv->next;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 write(tmp->player_fd, buff, strlen(buff));
      tmp = tmp->next;
    }
}

canonical_original_code:
void init_player(struct s_serv *serv, int fd)
{
  char buff[254];
  struct s_player new;
  struct s_player *tmp;
  new.X = rand() % 800;
  new.Y = rand() % 800;
  if (new.X >= 300 && new.X <= 500)
    new.X = rand() % 300;
  if (new.Y >= 300 && new.Y <= 500)
    new.Y = rand() % 300;
  new.player_id = serv->id_player++;
  new.player_fd = fd;
  new.missile = ((void *)0);
  addnode(&(serv->next), &new);
  memset(buff, '\0', 254);
  sprintf(buff, "New %d %d %d 0\n", new.player_id, new.X,
   new.Y);
  tmp = serv->next;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 write(tmp->player_fd, buff, strlen(buff));
      tmp = tmp->next;
    }
}

variable_types: struct s_serv { int player; int game; int port; int id_player; int fd_type[512]; void (*fct_read[512])(); struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *next; } *

variable_types:
buff
char [254]


decompiled_code:
unsigned int __fastcall add_player(__int64 a1, int a2)
{
unsigned int result; // eax
unsigned int *i; // rbx
size_t v4; // rax
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-118h] BYREF
int v7; // [rsp+F8h] [rbp-20h]
__int16 v8; // [rsp+FCh] [rbp-1Ch]

result = init_player(a1, a2);
for ( i = *(unsigned int **)(a1 + 6160); i; i = (unsigned int *)*((_QWORD *)i + 5) )
{
result = i[6];
if ( result )
{
if ( result != a2 )
{
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
sprintf(v6, "New %d %d %d %d\n", i[5], *i, i[1], i[4]);
v4 = strlen(v6);
write(1, v6, v4);
v5 = strlen(v6);
result = write(a2, v6, v5);
}
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func1(__int64 a1, int a2)
{
unsigned int result; // eax
unsigned int *i; // rbx
size_t v4; // rax
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-118h] BYREF
int v7; // [rsp+F8h] [rbp-20h]
__int16 v8; // [rsp+FCh] [rbp-1Ch]

result = func0(a1, a2);
for ( i = *(unsigned int **)(a1 + 6160); i; i = (unsigned int *)*((_QWORD *)i + 5) )
{
result = i[6];
if ( result )
{
if ( result != a2 )
{
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
sprintf(v6, "New %d %d %d %d\n", i[5], *i, i[1], i[4]);
v4 = strlen(v6);
write(1, v6, v4);
v5 = strlen(v6);
result = write(a2, v6, v5);
}
}
}
return result;
}

original_code:
void add_player(t_serv *serv, int fd)
{
  t_player *tmp;
  char buff[254];
  init_player(serv, fd);
  tmp = serv->next;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0 && tmp->player_fd != fd)
 {
   memset(buff, '\0', 254);
   sprintf(buff, "New %d %d %d %d\n", tmp->player_id, tmp->X,
    tmp->Y, tmp->rotation);
   write(1, buff, strlen(buff));
   write(fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void add_player(struct s_serv *serv, int fd)
{
  struct s_player *tmp;
  char buff[254];
  init_player(serv, fd);
  tmp = serv->next;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0 && tmp->player_fd != fd)
 {
   memset(buff, '\0', 254);
   sprintf(buff, "New %d %d %d %d\n", tmp->player_id, tmp->X,
    tmp->Y, tmp->rotation);
   write(1, buff, strlen(buff));
   write(fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}


decompiled_code:
unsigned int __fastcall add_client(__int64 a1, unsigned int a2)
{
int v2; // eax

v2 = xaccept(a2);
*(_DWORD *)(a1 + 4LL * v2 + 16) = 2;
*(_QWORD *)(a1 + 8LL * v2 + 2064) = &client_read;
return add_player(a1, v2);
}

canonical_decompiled_code:
unsigned int __fastcall func2(__int64 a1, unsigned int a2)
{
int v2; // eax

v2 = xaccept(a2);
*(_DWORD *)(a1 + 4LL * v2 + 16) = 2;
*(_QWORD *)(a1 + 8LL * v2 + 2064) = &client_read;
return func1(a1, v2);
}

original_code:
void add_client(t_serv *e, int fd)
{
  int client;
  client = xaccept(fd);
  e->fd_type[client] = 2;
  e->fct_read[client] = client_read;
  add_player(e, client);
}

canonical_original_code:
void add_client(struct s_serv *e, int fd)
{
  int client;
  client = xaccept(fd);
  e->fd_type[client] = 2;
  e->fct_read[client] = client_read;
  add_player(e, client);
}

variable_types: client int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // rdx
__int64 v5[2]; // [rsp+0h] [rbp-1838h] BYREF
char v6[512]; // [rsp+10h] [rbp-1828h] BYREF
__int64 v7; // [rsp+1810h] [rbp-28h]

v5[0] = 0x500000002LL;
v5[1] = 0x100001092LL;
v7 = 0LL;
v3 = time(0LL);
srand(v3);
checking(v5, (unsigned int)argc, argv);
if ( (unsigned int)(LODWORD(v5[0]) - 2) > 8 )
error((int)"Value must be between 2 and 10\n", argc, v4);
if ( (unsigned int)(HIDWORD(v5[0]) - 5) > 5 )
error((int)"Value must be between 5 and 10\n", argc, v4);
memset(v6, 0, sizeof(v6));
serveur(v5);
while ( 1 )
run(v5);
}

original_code:
int main(int ac, char **av)
{
  t_serv serv;
  serv.game = 5;
  serv.player = 2;
  serv.port = 4242;
  serv.next = ((void *)0);
  serv.id_player = 1;
  srand (time(((void *)0)));
  checking(&serv, ac, av);
  if (serv.player < 2 || serv.player > 10)
    error("Value must be between 2 and 10\n");
  if (serv.game < 5 || serv.game > 10)
    error("Value must be between 5 and 10\n");
  memset(serv.fd_type, 0, 512);
  serveur(&serv);
  while (1)
    run(&serv);
}

canonical_original_code:
int main(int ac, char **av)
{
  struct s_serv serv;
  serv.game = 5;
  serv.player = 2;
  serv.port = 4242;
  serv.next = ((void *)0);
  serv.id_player = 1;
  srand (time(((void *)0)));
  checking(&serv, ac, av);
  if (serv.player < 2 || serv.player > 10)
    error("Value must be between 2 and 10\n");
  if (serv.game < 5 || serv.game > 10)
    error("Value must be between 5 and 10\n");
  memset(serv.fd_type, 0, 512);
  serveur(&serv);
  while (1)
    run(&serv);
}

variable_types: ac int

variable_types:
av
char **

variable_types: struct s_serv { int player; int game; int port; int id_player; int fd_type[512]; void (*fct_read[512])(); struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *next; }

return_type: int


xaccept

decompiled_code:
__int64 __fastcall xaccept(int a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( a1 == -1 )
{
write(2, "ACCEPT ERROR\n", 0xDuLL);
if ( close(-1) == -1 )
{
write(2, "ERROR: close\n", 0xDuLL);
exit(0);
}
exit(1);
}
v2 = v1;
write(1, "NEW CONNECTION SUCCESS\n", 0x17uLL);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // eax
unsigned int v2; // er12
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

addr_len = 16;
v1 = accept(a1, &addr, &addr_len);
if ( a1 == -1 )
{
write(2, "ACCEPT ERROR\n", 0xDuLL);
if ( close(-1) == -1 )
{
write(2, "ERROR: close\n", 0xDuLL);
exit(0);
}
exit(1);
}
v2 = v1;
write(1, "NEW CONNECTION SUCCESS\n", 0x17uLL);
return v2;
}

original_code:
int xaccept(int fd)
{
  struct sockaddr_in sin;
  int sin_size;
  int client;
  sin_size = sizeof(sin);
  client = accept(fd, (struct sockaddr *)&sin, (socklen_t *)&sin_size);
  if (fd == -1)
    {
      write(2, "ACCEPT ERROR\n", 13);
      if (close(fd) == -1)
 {
   write (2, "ERROR: close\n", 13);
   exit(0);
 }
      exit(1);
    }
  write(1, "NEW CONNECTION SUCCESS\n", 23);
  return (client);
}

canonical_original_code:
int xaccept(int fd)
{
  struct sockaddr_in sin;
  int sin_size;
  int client;
  sin_size = sizeof(sin);
  client = accept(fd, (struct sockaddr *)&sin, (unsigned int *)&sin_size);
  if (fd == -1)
    {
      write(2, "ACCEPT ERROR\n", 13);
      if (close(fd) == -1)
 {
   write (2, "ERROR: close\n", 13);
   exit(0);
 }
      exit(1);
    }
  write(1, "NEW CONNECTION SUCCESS\n", 23);
  return (client);
}

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 __fastcall graph_droite(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rcx
__int64 v4; // rdx
int result; // eax
size_t v6; // rax
size_t v7; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
memset(savedregs, 0, 0xF8uLL);
v3 = *(unsigned int *)(a2 + 16);
*(_WORD *)&savedregs[252] = 0;
v4 = *(unsigned int *)(a2 + 20);
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Dro %d %d\n", v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v6 = strlen(savedregs);
write(1, savedregs, v6);
v7 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rcx
__int64 v4; // rdx
int result; // eax
size_t v6; // rax
size_t v7; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
memset(savedregs, 0, 0xF8uLL);
v3 = *(unsigned int *)(a2 + 16);
*(_WORD *)&savedregs[252] = 0;
v4 = *(unsigned int *)(a2 + 20);
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Dro %d %d\n", v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v6 = strlen(savedregs);
write(1, savedregs, v6);
v7 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v7);
}
return result;
}

original_code:
void graph_droite(t_player **list, t_player *perso)
{
  t_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Dro %d %d\n", perso->player_id, perso->rotation);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void graph_droite(struct s_player **list, struct s_player *perso)
{
  struct s_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Dro %d %d\n", perso->player_id, perso->rotation);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

variable_types:
perso
struct s_player *


decompiled_code:
__int64 __fastcall gravite_top_left_tir(__int64 a1, _DWORD *a2)
{
++*a2;
++a2[1];
return graph_tir();
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2)
{
++*a2;
++a2[1];
return graph_tir();
}

original_code:
void gravite_top_left_tir(t_player **list, t_missile *tir)
{
  tir->x += 1;
  tir->y += 1;
  graph_tir(list, tir);
}

canonical_original_code:
void gravite_top_left_tir(struct s_player **list, struct s_missile *tir)
{
  tir->x += 1;
  tir->y += 1;
  graph_tir(list, tir);
}

variable_types:
tir
struct s_missile *


decompiled_code:
__int64 __fastcall gravite_top_right_tir(__int64 a1, _DWORD *a2)
{
--*a2;
++a2[1];
return graph_tir();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2)
{
--*a2;
++a2[1];
return graph_tir();
}

original_code:
void gravite_top_right_tir(t_player **list, t_missile *tir)
{
  tir->x -= 1;
  tir->y += 1;
  graph_tir(list, tir);
}

canonical_original_code:
void gravite_top_right_tir(struct s_player **list, struct s_missile *tir)
{
  tir->x -= 1;
  tir->y += 1;
  graph_tir(list, tir);
}


decompiled_code:
__int64 __fastcall gravite_bot_left_tir(__int64 a1, _DWORD *a2)
{
++*a2;
--a2[1];
return graph_tir();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _DWORD *a2)
{
++*a2;
--a2[1];
return graph_tir();
}

original_code:
void gravite_bot_left_tir(t_player **list, t_missile *tir)
{
  tir->x += 1;
  tir->y -= 1;
  graph_tir(list, tir);
}

canonical_original_code:
void gravite_bot_left_tir(struct s_player **list, struct s_missile *tir)
{
  tir->x += 1;
  tir->y -= 1;
  graph_tir(list, tir);
}


decompiled_code:
__int64 __fastcall gravite_bot_right_tir(__int64 a1, _DWORD *a2)
{
--*a2;
--a2[1];
return graph_tir();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2)
{
--*a2;
--a2[1];
return graph_tir();
}

original_code:
void gravite_bot_right_tir(t_player **list, t_missile *tir)
{
  tir->x -= 1;
  tir->y -= 1;
  graph_tir(list, tir);
}

canonical_original_code:
void gravite_bot_right_tir(struct s_player **list, struct s_missile *tir)
{
  tir->x -= 1;
  tir->y -= 1;
  graph_tir(list, tir);
}


decompiled_code:
__int64 __fastcall gravite_tir(__int64 a1, int *a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // edx
__int64 result; // rax

v2 = a2[5];
if ( v2 > 2 )
{
v3 = *a2;
if ( (unsigned int)*a2 > 0x190 )
{
result = (unsigned int)(v3 - 400);
if ( (unsigned int)result <= 0x190 )
{
result = (unsigned int)a2[1];
if ( (unsigned int)(result - 400) > 0x190 )
{
if ( (unsigned int)result <= 0x190 )
result = gravite_top_right_tir(a1, a2);
goto LABEL_7;
}
LABEL_14:
result = gravite_bot_right_tir(a1, a2);
goto LABEL_7;
}
}
else
{
v4 = a2[1];
if ( v4 <= 0x190 )
{
result = gravite_top_left_tir(a1, a2);
goto LABEL_7;
}
result = (unsigned int)(v3 - 400);
if ( (unsigned int)result > 0x190 )
{
if ( v4 - 400 <= 0x190 )
result = gravite_bot_left_tir(a1, a2);
goto LABEL_7;
}
if ( v4 - 400 <= 0x190 )
goto LABEL_14;
}
LABEL_7:
a2[5] = 0;
return result;
}
result = (unsigned int)(v2 + 1);
a2[5] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int *a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // edx
__int64 result; // rax

v2 = a2[5];
if ( v2 > 2 )
{
v3 = *a2;
if ( (unsigned int)*a2 > 0x190 )
{
result = (unsigned int)(v3 - 400);
if ( (unsigned int)result <= 0x190 )
{
result = (unsigned int)a2[1];
if ( (unsigned int)(result - 400) > 0x190 )
{
if ( (unsigned int)result <= 0x190 )
result = func1(a1, a2);
goto LABEL_7;
}
LABEL_14:
result = func3(a1, a2);
goto LABEL_7;
}
}
else
{
v4 = a2[1];
if ( v4 <= 0x190 )
{
result = func0(a1, a2);
goto LABEL_7;
}
result = (unsigned int)(v3 - 400);
if ( (unsigned int)result > 0x190 )
{
if ( v4 - 400 <= 0x190 )
result = func2(a1, a2);
goto LABEL_7;
}
if ( v4 - 400 <= 0x190 )
goto LABEL_14;
}
LABEL_7:
a2[5] = 0;
return result;
}
result = (unsigned int)(v2 + 1);
a2[5] = result;
return result;
}

original_code:
void gravite_tir(t_player **list, t_missile *tir)
{
  if (tir->time_grav >= 3)
    {
      if (tir->x >= 0 && tir->x <= 400 && tir->y >= 0 && tir->y <= 400)
 gravite_top_left_tir(list, tir);
      else if (tir->x >= 400 && tir->x <= 800 && tir->y <= 800 &&
        tir->y >= 400)
 gravite_bot_right_tir(list, tir);
      else if (tir->x >= 0 && tir->x <= 400 && tir->y <= 800 && tir->y >= 400)
 gravite_bot_left_tir(list, tir);
      else if (tir->x >= 400 && tir->x <= 800 && tir->y <= 400 && tir->y >= 0)
 gravite_top_right_tir(list, tir);
      tir->time_grav = 0;
    }
  else
    tir->time_grav++;
}

canonical_original_code:
void gravite_tir(struct s_player **list, struct s_missile *tir)
{
  if (tir->time_grav >= 3)
    {
      if (tir->x >= 0 && tir->x <= 400 && tir->y >= 0 && tir->y <= 400)
 gravite_top_left_tir(list, tir);
      else if (tir->x >= 400 && tir->x <= 800 && tir->y <= 800 &&
        tir->y >= 400)
 gravite_bot_right_tir(list, tir);
      else if (tir->x >= 0 && tir->x <= 400 && tir->y <= 800 && tir->y >= 400)
 gravite_bot_left_tir(list, tir);
      else if (tir->x >= 400 && tir->x <= 800 && tir->y <= 400 && tir->y >= 0)
 gravite_top_right_tir(list, tir);
      tir->time_grav = 0;
    }
  else
    tir->time_grav++;
}


decompiled_code:
int __fastcall graph_tir(__int64 *a1, unsigned int *a2)
{
__int64 v2; // rbx
__int64 v3; // r8
__int64 v4; // rcx
__int64 v5; // rdx
int result; // eax
size_t v7; // rax
size_t v8; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
v3 = a2[1];
memset(savedregs, 0, 0xF8uLL);
v4 = *a2;
*(_WORD *)&savedregs[252] = 0;
v5 = a2[3];
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Tir %d %d %d\n", v5, v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v7 = strlen(savedregs);
write(1, savedregs, v7);
v8 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v8);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, unsigned int *a2)
{
__int64 v2; // rbx
__int64 v3; // r8
__int64 v4; // rcx
__int64 v5; // rdx
int result; // eax
size_t v7; // rax
size_t v8; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
v3 = a2[1];
memset(savedregs, 0, 0xF8uLL);
v4 = *a2;
*(_WORD *)&savedregs[252] = 0;
v5 = a2[3];
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Tir %d %d %d\n", v5, v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v7 = strlen(savedregs);
write(1, savedregs, v7);
v8 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v8);
}
return result;
}

original_code:
void graph_tir(t_player **list, t_missile *tir)
{
  t_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Tir %d %d %d\n", tir->nb_tir, tir->x, tir->y);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void graph_tir(struct s_player **list, struct s_missile *tir)
{
  struct s_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Tir %d %d %d\n", tir->nb_tir, tir->x, tir->y);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}


decompiled_code:
int __fastcall graph_tir_suppr(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
int result; // eax
size_t v5; // rax
size_t v6; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
memset(savedregs, 0, 0xF8uLL);
*(_WORD *)&savedregs[252] = 0;
v3 = *(unsigned int *)(a2 + 12);
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "MoT %d\n", v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v5 = strlen(savedregs);
write(1, savedregs, v5);
v6 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v6);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rdx
int result; // eax
size_t v5; // rax
size_t v6; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
memset(savedregs, 0, 0xF8uLL);
*(_WORD *)&savedregs[252] = 0;
v3 = *(unsigned int *)(a2 + 12);
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "MoT %d\n", v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v5 = strlen(savedregs);
write(1, savedregs, v5);
v6 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v6);
}
return result;
}

original_code:
void graph_tir_suppr(t_player **list, t_missile *tir)
{
  t_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "MoT %d\n", tir->nb_tir);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void graph_tir_suppr(struct s_player **list, struct s_missile *tir)
{
  struct s_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "MoT %d\n", tir->nb_tir);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}


decompiled_code:
int __fastcall connection_close(__int64 a1, __int64 a2)
{
printf("%d: Connection closed\n", a2);
graph_close(a1 + 6160, (unsigned int)a2);
deletenode(a1 + 6160, (unsigned int)a2);
*(_DWORD *)(a1 + 4LL * (int)a2 + 16) = 0;
return close(a2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
printf("%d: Connection closed\n", a2);
graph_close(a1 + 6160, (unsigned int)a2);
deletenode(a1 + 6160, (unsigned int)a2);
*(_DWORD *)(a1 + 4LL * (int)a2 + 16) = 0;
return close(a2);
}

original_code:
void connection_close(t_serv *serv, int fd)
{
  printf("%d: Connection closed\n", fd);
  graph_close(&(serv->next), fd);
  deletenode(&(serv->next), fd);
  serv->fd_type[fd] = 0;
  close(fd);
}

canonical_original_code:
void connection_close(struct s_serv *serv, int fd)
{
  printf("%d: Connection closed\n", fd);
  graph_close(&(serv->next), fd);
  deletenode(&(serv->next), fd);
  serv->fd_type[fd] = 0;
  close(fd);
}


decompiled_code:
__int64 __fastcall exec_cmd(__int64 a1, unsigned int a2, const char *a3)
{
__int64 result; // rax

result = a1;
if ( !strcmp(a3, "Avance\n") )
return avance(a1 + 6160, a2);
if ( !strcmp(a3, "Droite\n") )
return droite(a1 + 6160, a2);
if ( !strcmp(a3, "Gauche\n") )
return gauche(a1 + 6160, a2);
if ( !strcmp(a3, "Tir\n") )
result = tir(a1 + 6160, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, const char *a3)
{
__int64 result; // rax

result = a1;
if ( !strcmp(a3, "Avance\n") )
return avance(a1 + 6160, a2);
if ( !strcmp(a3, "Droite\n") )
return droite(a1 + 6160, a2);
if ( !strcmp(a3, "Gauche\n") )
return gauche(a1 + 6160, a2);
if ( !strcmp(a3, "Tir\n") )
result = tir(a1 + 6160, a2);
return result;
}

original_code:
void exec_cmd(t_serv *serv, int fd, char *buff)
{
  if (strcmp(buff, "Avance\n") == 0)
    avance(&(serv->next), fd);
  else if (strcmp(buff, "Droite\n") == 0)
    droite(&(serv->next), fd);
  else if (strcmp(buff, "Gauche\n") == 0)
    gauche(&(serv->next), fd);
  else if (strcmp(buff, "Tir\n") == 0)
    tir(&(serv->next), fd);
}

canonical_original_code:
void exec_cmd(struct s_serv *serv, int fd, char *buff)
{
  if (strcmp(buff, "Avance\n") == 0)
    avance(&(serv->next), fd);
  else if (strcmp(buff, "Droite\n") == 0)
    droite(&(serv->next), fd);
  else if (strcmp(buff, "Gauche\n") == 0)
    gauche(&(serv->next), fd);
  else if (strcmp(buff, "Tir\n") == 0)
    tir(&(serv->next), fd);
}

variable_types:
buff
char *


decompiled_code:
void __fastcall client_read(__int64 a1, unsigned int a2)
{
int v2; // ebx
__int16 buf; // [rsp+6h] [rbp-22h] BYREF
char *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

asprintf(ptr, &fmt);
while ( buf != 10 )
{
buf = 0;
v2 = read(a2, &buf, 1uLL);
if ( v2 <= 0 )
{
connection_close(a1, a2);
buf = 10;
}
asprintf(ptr, "%s%s", ptr[0], (const char *)&buf);
}
if ( v2 > 0 )
exec_cmd(a1, a2, ptr[0]);
free(ptr[0]);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, unsigned int a2)
{
int v2; // ebx
__int16 buf; // [rsp+6h] [rbp-22h] BYREF
char *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

asprintf(ptr, &fmt);
while ( buf != 10 )
{
buf = 0;
v2 = read(a2, &buf, 1uLL);
if ( v2 <= 0 )
{
func0(a1, a2);
buf = 10;
}
asprintf(ptr, "%s%s", ptr[0], (const char *)&buf);
}
if ( v2 > 0 )
func1(a1, a2, ptr[0]);
free(ptr[0]);
}

original_code:
void client_read(t_serv *e, int fd)
{
  int r;
  char tmp[2];
  char *buff;
  asprintf(&buff, "");
  while (strcmp(tmp, "\n") != 0)
    {
      memset(tmp, '\0', 2);
      r = read(fd, tmp, 1);
      if (r <= 0)
 {
   connection_close(e, fd);
   sprintf(tmp, "\n");
 }
      asprintf(&buff, "%s%s", buff, tmp);
    }
  if (r > 0)
    exec_cmd(e, fd, buff);
  free(buff);
}

canonical_original_code:
void client_read(struct s_serv *e, int fd)
{
  int r;
  char tmp[2];
  char *buff;
  asprintf(&buff, "");
  while (strcmp(tmp, "\n") != 0)
    {
      memset(tmp, '\0', 2);
      r = read(fd, tmp, 1);
      if (r <= 0)
 {
   connection_close(e, fd);
   sprintf(tmp, "\n");
 }
      asprintf(&buff, "%s%s", buff, tmp);
    }
  if (r > 0)
    exec_cmd(e, fd, buff);
  free(buff);
}

variable_types: r int

variable_types:
tmp
char [2]


deletemissile

decompiled_code:
__int64 __fastcall deletemissile(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = graph_tir_suppr(a1, a3);
*(_DWORD *)(a3 + 12) = 0;
--*(_DWORD *)(a2 + 28);
return result;
}

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

result = graph_tir_suppr(a1, a3);
*(_DWORD *)(a3 + 12) = 0;
--*(_DWORD *)(a2 + 28);
return result;
}

original_code:
void deletemissile(t_player **l, t_player *pl, t_missile *tir)
{
  graph_tir_suppr(l, tir);
  tir->nb_tir = 0;
  pl->nb_missile--;
}

canonical_original_code:
void deletemissile(struct s_player **l, struct s_player *pl, struct s_missile *tir)
{
  graph_tir_suppr(l, tir);
  tir->nb_tir = 0;
  pl->nb_missile--;
}

variable_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } **


original_code:
void collide_vaisseau(t_player **list, t_missile *tir)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if ((tir->x >= tmp->X - 20 && tir->x <= tmp->X + 20)
   && (tir->y >= tmp->Y - 20 && tir->y <= tmp->Y + 20))
 is_dead(list, tmp);
      tmp = tmp->next;
    }
}

canonical_original_code:
void collide_vaisseau(struct s_player **list, struct s_missile *tir)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if ((tir->x >= tmp->X - 20 && tir->x <= tmp->X + 20)
   && (tir->y >= tmp->Y - 20 && tir->y <= tmp->Y + 20))
 is_dead(list, tmp);
      tmp = tmp->next;
    }
}


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

collide_vaisseau(a1, a3);
if ( *a3 > 0x320u
|| (v4 = a3[1], v4 > 0x320)
|| (result = (unsigned int)(*a3 - 385), (unsigned int)result <= 0x1E)
|| v4 - 385 <= 0x1E )
{
result = deletemissile((__int64)a1, a2, (__int64)a3);
}
return result;
}

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

func1(a1, a3);
if ( *a3 > 0x320u
|| (v4 = a3[1], v4 > 0x320)
|| (result = (unsigned int)(*a3 - 385), (unsigned int)result <= 0x1E)
|| v4 - 385 <= 0x1E )
{
result = func0((__int64)a1, a2, (__int64)a3);
}
return result;
}

original_code:
void collide_tir(t_player **list, t_player *pl, t_missile *tir)
{
  collide_vaisseau(list, tir);
  if (tir->x < 0 || tir->x > 800 || tir->y < 0 || tir->y > 800)
    deletemissile(list, pl, tir);
  else if (tir->x >= 385 && tir->x <= 415)
    deletemissile(list, pl, tir);
  else if (tir->y >= 385 && tir->y <= 415)
    deletemissile(list, pl, tir);
}

canonical_original_code:
void collide_tir(struct s_player **list, struct s_player *pl, struct s_missile *tir)
{
  collide_vaisseau(list, tir);
  if (tir->x < 0 || tir->x > 800 || tir->y < 0 || tir->y > 800)
    deletemissile(list, pl, tir);
  else if (tir->x >= 385 && tir->x <= 415)
    deletemissile(list, pl, tir);
  else if (tir->y >= 385 && tir->y <= 415)
    deletemissile(list, pl, tir);
}

variable_types:
pl
struct s_player *


original_code:
void move_tir(t_player **list, t_player *pl)
{
  static int i = 0;
  int j;
  t_missile *tmp2;
  tmp2 = pl->missile;
  while (tmp2 != ((void *)0))
    {
      j = 0;
      while (j < 8 && tmp2->rotation != tab_value_tir[j].rotation_)
 j++;
      if (j != 8 && tmp2->time >= 3500 && tmp2->nb_tir != 0)
 {
   tab_value_tir[j].funct(tmp2, 1);
   gravite_tir(list, tmp2);
   collide_tir(list, pl, tmp2);
   graph_tir(list, tmp2);
   tmp2->time = 0;
 }
      else
 tmp2->time++;
      tmp2 = tmp2->next;
    }
}

canonical_original_code:
void move_tir(struct s_player **list, struct s_player *pl)
{
  static int i = 0;
  int j;
  struct s_missile *tmp2;
  tmp2 = pl->missile;
  while (tmp2 != ((void *)0))
    {
      j = 0;
      while (j < 8 && tmp2->rotation != tab_value_tir[j].rotation_)
 j++;
      if (j != 8 && tmp2->time >= 3500 && tmp2->nb_tir != 0)
 {
   tab_value_tir[j].funct(tmp2, 1);
   gravite_tir(list, tmp2);
   collide_tir(list, pl, tmp2);
   graph_tir(list, tmp2);
   tmp2->time = 0;
 }
      else
 tmp2->time++;
      tmp2 = tmp2->next;
    }
}

variable_types: i int

variable_types: j int

variable_types: struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *


decompiled_code:
__int64 __fastcall pop_tir(__int64 a1)
{
__int64 result; // rax
int i; // edx

result = 0LL;
for ( i = 0; *(_DWORD *)(a1 + 8) != i; i = tab_value_tir[4 * result] )
{
if ( ++result == 8 )
return result;
}
return ((__int64 (__fastcall *)(__int64, __int64))*(&off_128 + 2 * (int)result))(a1, 30LL);
}

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

result = 0LL;
for ( i = 0; *(_DWORD *)(a1 + 8) != i; i = tab_value_tir[4 * result] )
{
if ( ++result == 8 )
return result;
}
return ((__int64 (__fastcall *)(__int64, __int64))*(&off_128 + 2 * (int)result))(a1, 30LL);
}

original_code:
void pop_tir(t_missile *tir)
{
  int j;
  j = 0;
  while (j < 8 && tir->rotation != tab_value_tir[j].rotation_)
    j++;
  if (j != 8)
    tab_value_tir[j].funct(tir, 30);
}

canonical_original_code:
void pop_tir(struct s_missile *tir)
{
  int j;
  j = 0;
  while (j < 8 && tir->rotation != tab_value_tir[j].rotation_)
    j++;
  if (j != 8)
    tab_value_tir[j].funct(tir, 30);
}


setType

original_code:
int setType(t_serv *e, fd_set *fd_read)
{
  int i;
  int fd_max;
  i = 0;
  fd_max = 0;
  while (i < 512)
    {
      if (e->fd_type[i] != 0)
        {
          ((void) (((fd_read)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
          fd_max = i;
        }
      i++;
    }
  return (i);
}

canonical_original_code:
int setType(struct s_serv *e, struct fd_set *fd_read)
{
  int i;
  int fd_max;
  i = 0;
  fd_max = 0;
  while (i < 512)
    {
      if (e->fd_type[i] != 0)
        {
          ((void) (((fd_read)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
          fd_max = i;
        }
      i++;
    }
  return (i);
}

variable_types: struct s_serv { int player; int game; int port; int id_player; int fd_type[512]; void (*fct_read[512])(); struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *next; } *

variable_types: struct fd_set { long __fds_bits[-1]; } *


Zero

decompiled_code:
void __fastcall Zero(__int64 a1)
{
--*(_DWORD *)(a1 + 4);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
--*(_DWORD *)(a1 + 4);
}

original_code:
void Zero(t_player *player)
{
  player->Y = player->Y - 1;
}

canonical_original_code:
void Zero(struct s_player *player)
{
  player->Y = player->Y - 1;
}

variable_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *


decompiled_code:
void __fastcall Hundred_eighty(__int64 a1)
{
++*(_DWORD *)(a1 + 4);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
++*(_DWORD *)(a1 + 4);
}

original_code:
void Hundred_eighty(t_player *player)
{
  player->Y = player->Y + 1;
}

canonical_original_code:
void Hundred_eighty(struct s_player *player)
{
  player->Y = player->Y + 1;
}


original_code:
void tir2(t_player **list, t_player *player)
{
  static int i = 1;
  t_missile *missile;
  missile = xmalloc(sizeof(t_missile));
  missile->rotation = player->rotation;
  missile->x = player->X;
  missile->y = player->Y;
  pop_tir(missile);
  missile->nb_tir = i++;
  graph_tir(list, missile);
  addmissile(&(player->missile), missile);
}

canonical_original_code:
void tir2(struct s_player **list, struct s_player *player)
{
  static int i = 1;
  struct s_missile *missile;
  missile = xmalloc(sizeof(t_missile));
  missile->rotation = player->rotation;
  missile->x = player->X;
  missile->y = player->Y;
  pop_tir(missile);
  missile->nb_tir = i++;
  graph_tir(list, missile);
  addmissile(&(player->missile), missile);
}

variable_types:
player
struct s_player *


tir

original_code:
void *tir(t_player **list, int num_player)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   if (tmp->nb_missile < 5)
     {
       tir2(list, tmp);
       tmp->nb_missile++;
     }
   return (((void *)0));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void *tir(struct s_player **list, int num_player)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   if (tmp->nb_missile < 5)
     {
       tir2(list, tmp);
       tmp->nb_missile++;
     }
   return (((void *)0));
 }
      tmp = tmp->next;
    }
}

return_type: void *


serveur

decompiled_code:
__int64 __fastcall serveur(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rbx
__int64 result; // rax

v1 = xsocket();
v2 = (int)v1;
xbind(v1, a1);
result = xlisten((unsigned int)v2);
*(_DWORD *)(a1 + 4 * v2 + 16) = 1;
*(_QWORD *)(a1 + 8 * v2 + 2064) = &serveur_read;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rbx
__int64 result; // rax

v1 = xsocket();
v2 = (int)v1;
xbind(v1, a1);
result = xlisten((unsigned int)v2);
*(_DWORD *)(a1 + 4 * v2 + 16) = 1;
*(_QWORD *)(a1 + 8 * v2 + 2064) = &serveur_read;
return result;
}

original_code:
int serveur(t_serv *e)
{
  int fd;
  fd = xsocket();
  xbind(fd, e);
  xlisten(fd);
  e->fd_type[fd] = 1;
  e->fct_read[fd] = serveur_read;
}

canonical_original_code:
int serveur(struct s_serv *e)
{
  int fd;
  fd = xsocket();
  xbind(fd, e);
  xlisten(fd);
  e->fd_type[fd] = 1;
  e->fct_read[fd] = serveur_read;
}

variable_types: fd int


droite

original_code:
void droite(t_player **list, int num_player)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   tmp->rotation = tmp->rotation + 45;
   if (tmp->rotation >= 360)
     tmp->rotation = 0;
   graph_droite(list, tmp);
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void droite(struct s_player **list, int num_player)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   tmp->rotation = tmp->rotation + 45;
   if (tmp->rotation >= 360)
     tmp->rotation = 0;
   graph_droite(list, tmp);
 }
      tmp = tmp->next;
    }
}


original_code:
void check_value(t_player *player)
{
  if (player->X > 0)
    player->X = player->X % 800;
  else if (player->X < 0)
    player->X = 800 + player->X;
  if (player->Y > 0)
    player->Y = player->Y % 800;
  else if (player->Y < 0)
    player->Y = 800 + player->Y;
}

canonical_original_code:
void check_value(struct s_player *player)
{
  if (player->X > 0)
    player->X = player->X % 800;
  else if (player->X < 0)
    player->X = 800 + player->X;
  if (player->Y > 0)
    player->Y = player->Y % 800;
  else if (player->Y < 0)
    player->Y = 800 + player->Y;
}


decompiled_code:
__int64 __fastcall check_rotation(__int64 a1)
{
__int64 result; // rax
int i; // edx

result = 0LL;
for ( i = 0; *(_DWORD *)(a1 + 16) != i; i = tab_value_[4 * result] )
{
if ( ++result == 8 )
return result;
}
return ((__int64 (*)(void))*(&off_1A8 + 2 * (int)result))();
}

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

result = 0LL;
for ( i = 0; *(_DWORD *)(a1 + 16) != i; i = tab_value_[4 * result] )
{
if ( ++result == 8 )
return result;
}
return ((__int64 (*)(void))*(&off_1A8 + 2 * (int)result))();
}

original_code:
void check_rotation(t_player *player)
{
  int j;
  j = 0;
  while (j < 8 && player->rotation != tab_value_[j].rotation_)
    j++;
  if (j != 8)
    tab_value_[j].funct(player);
}

canonical_original_code:
void check_rotation(struct s_player *player)
{
  int j;
  j = 0;
  while (j < 8 && player->rotation != tab_value_[j].rotation_)
    j++;
  if (j != 8)
    tab_value_[j].funct(player);
}


avance

decompiled_code:
__int64 __fastcall avance(__int64 *a1, int a2)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
while ( 1 )
{
if ( *(_DWORD *)(i + 24) == a2 )
{
result = *(unsigned int *)(i + 12);
if ( (int)result > 0 )
break;
}
i = *(_QWORD *)(i + 40);
if ( !i )
return result;
}
check_value((int *)i);
check_rotation(i);
check_value((int *)i);
--*(_DWORD *)(i + 12);
graph_avance(a1, i);
result = graph_essence(a1, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, int a2)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
while ( 1 )
{
if ( *(_DWORD *)(i + 24) == a2 )
{
result = *(unsigned int *)(i + 12);
if ( (int)result > 0 )
break;
}
i = *(_QWORD *)(i + 40);
if ( !i )
return result;
}
func0((int *)i);
func1(i);
func0((int *)i);
--*(_DWORD *)(i + 12);
graph_avance(a1, i);
result = graph_essence(a1, i);
}
return result;
}

original_code:
void avance(t_player **list, int num_player)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player && tmp->essence > 0)
       {
   check_value(tmp);
   check_rotation(tmp);
   check_value(tmp);
   tmp->essence--;
   graph_avance(list, tmp);
   graph_essence(list, tmp);
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void avance(struct s_player **list, int num_player)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player && tmp->essence > 0)
       {
   check_value(tmp);
   check_rotation(tmp);
   check_value(tmp);
   tmp->essence--;
   graph_avance(list, tmp);
   graph_essence(list, tmp);
 }
      tmp = tmp->next;
    }
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
exit(1);
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
exit(1);
return result;
}

original_code:
void *xmalloc(int size)
{
  void *ptr;
  ptr = malloc(size);
  if (ptr == ((void *)0))
    exit(1);
  else
    return (ptr);
}

variable_types: size int

variable_types:
ptr
void *


deletenode

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

for ( result = *a1; result; result = *(_QWORD *)(result + 40) )
{
if ( *(_DWORD *)(result + 24) == a2 )
*(_DWORD *)(result + 24) = 0;
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 40) )
{
if ( *(_DWORD *)(result + 24) == a2 )
*(_DWORD *)(result + 24) = 0;
}
return result;
}

original_code:
void deletenode(t_player **list, int fd_pl)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == fd_pl)
 tmp->player_fd = 0;
      tmp = tmp->next;
    }
}

canonical_original_code:
void deletenode(struct s_player **list, int fd_pl)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == fd_pl)
 tmp->player_fd = 0;
      tmp = tmp->next;
    }
}