decompiled_code:
__int64 __fastcall draw_petal(double a1, double a2, double a3, double a4, double a5)
{
int i; // ebx
double v7; // xmm0_8
double v8; // xmm5_8
double v9; // xmm1_8
double v10; // xmm0_8
__int64 result; // rax
double v12; // [rsp+8h] [rbp-90h]
double v13; // [rsp+10h] [rbp-88h]
double v14; // [rsp+18h] [rbp-80h]
double v15; // [rsp+20h] [rbp-78h]
double v16; // [rsp+28h] [rbp-70h]
double v17; // [rsp+38h] [rbp-60h]
double v20; // [rsp+58h] [rbp-40h]
double v21; // [rsp+60h] [rbp-38h]
double v22; // [rsp+68h] [rbp-30h]
double cosx; // [rsp+70h] [rbp-28h] BYREF
double sinx[4]; // [rsp+78h] [rbp-20h] BYREF

sincos(a4, sinx, &cosx);
v21 = cosx;
v22 = sinx[0];
v12 = a5 * cosx + a1;
v13 = a5 * sinx[0] + a2;
v20 = tan(a3 * 0.5);
for ( i = 1; i != 7; ++i )
{
v7 = (double)i * 160.0;
v8 = v22 * v7;
*(_QWORD *)&v9 = *(_QWORD *)&v7 ^ LC2;
v17 = v12 + v22 * v7;
v10 = v7 / v20;
v15 = v10 * v21 + a1;
v16 = v8;
v14 = v22 * v10 + a2;
moveto(v15 + v8, v14 + v9 * v21);
lineto(v17, v13 + v9 * v21);
arc(v12, v13, 180.0);
result = lineto(v15 - v16, v14 - v9 * v21);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3, double a4, double a5)
{
int i; // ebx
double v7; // xmm0_8
double v8; // xmm5_8
double v9; // xmm1_8
double v10; // xmm0_8
__int64 result; // rax
double v12; // [rsp+8h] [rbp-90h]
double v13; // [rsp+10h] [rbp-88h]
double v14; // [rsp+18h] [rbp-80h]
double v15; // [rsp+20h] [rbp-78h]
double v16; // [rsp+28h] [rbp-70h]
double v17; // [rsp+38h] [rbp-60h]
double v20; // [rsp+58h] [rbp-40h]
double v21; // [rsp+60h] [rbp-38h]
double v22; // [rsp+68h] [rbp-30h]
double cosx; // [rsp+70h] [rbp-28h] BYREF
double sinx[4]; // [rsp+78h] [rbp-20h] BYREF

sincos(a4, sinx, &cosx);
v21 = cosx;
v22 = sinx[0];
v12 = a5 * cosx + a1;
v13 = a5 * sinx[0] + a2;
v20 = tan(a3 * 0.5);
for ( i = 1; i != 7; ++i )
{
v7 = (double)i * 160.0;
v8 = v22 * v7;
*(_QWORD *)&v9 = *(_QWORD *)&v7 ^ LC2;
v17 = v12 + v22 * v7;
v10 = v7 / v20;
v15 = v10 * v21 + a1;
v16 = v8;
v14 = v22 * v10 + a2;
moveto(v15 + v8, v14 + v9 * v21);
lineto(v17, v13 + v9 * v21);
arc(v12, v13, 180.0);
result = lineto(v15 - v16, v14 - v9 * v21);
}
return result;
}

original_code:
void draw_petal(const double xc, const double yc, const double delta, const double theta, const double radius)
{
   int i;
   const double tipx = xc + (radius * cos(theta));
   const double tipy = yc + (radius * sin(theta));
   for (i = 1; i <= 6; i++) {
      const double len = 4.0 * 40.0 * (double)i;
      const double offx = len * sin(theta);
      const double offy = -len * cos(theta);
      const double arcx = tipx + offx;
      const double arcy = tipy + offy;
      const double baslen = len / tan(delta / 2.0);
      const double basx = baslen * cos(theta);
      const double basy = baslen * sin(theta);
      moveto(xc + basx + offx, yc + basy + offy);
      lineto(arcx, arcy);
      arc(tipx, tipy, 180.0);
      lineto(xc + basx - offx, yc + basy - offy);
   }
}

canonical_original_code:
void draw_petal(double xc, double yc, double delta, double theta, double radius)
{
   int i;
   double tipx = xc + (radius * cos(theta));
   double tipy = yc + (radius * sin(theta));
   for (i = 1; i <= 6; i++) {
      double len = 4.0 * 40.0 * (double)i;
      double offx = len * sin(theta);
      double offy = -len * cos(theta);
      double arcx = tipx + offx;
      double arcy = tipy + offy;
      double baslen = len / tan(delta / 2.0);
      double basx = baslen * cos(theta);
      double basy = baslen * sin(theta);
      moveto(xc + basx + offx, yc + basy + offy);
      lineto(arcx, arcy);
      arc(tipx, tipy, 180.0);
      lineto(xc + basx - offx, yc + basy - offy);
   }
}

variable_types: xc double

variable_types: yc double

variable_types: delta double

variable_types: radius double

variable_types: tipx double

variable_types: tipy double

variable_types: len double

variable_types: offx double

variable_types: offy double

variable_types: arcx double

variable_types: arcy double

variable_types: baslen double

variable_types: basx double

variable_types: basy double


main

canonical_name: main

repo: anachrocomputer/vec

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
double v4; // rbp
int i; // ebx
int j; // ebx
double v8; // [rsp+0h] [rbp-58h]
double v9; // [rsp+8h] [rbp-50h]
double v10; // [rsp+10h] [rbp-48h]
double v11; // [rsp+18h] [rbp-40h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx; // [rsp+28h] [rbp-30h] BYREF
double v14; // [rsp+30h] [rbp-28h] BYREF
double v15[4]; // [rsp+38h] [rbp-20h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v3 == -1 )
break;
if ( v3 - 110 > 8 || ((1LL << ((unsigned __int8)v3 - 110)) & 0x167) == 0 )
{
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", *argv);
fwrite(" <size> ::= A1 | A2 | A3 | A4 | A5\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
plotopt(v3, optarg);
}
if ( (int)plotbegin(1LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v15, &v14);
v8 = 0.5 * v15[0];
v9 = 0.5 * v14;
v4 = v14 / 3.0;
for ( i = 0; i != 8; ++i )
{
sincos((double)i * 0.7853981633974483, &sinx, &cosx);
v10 = v4 * cosx + v8;
v11 = v4 * sinx + v9;
moveto(v8, v9);
lineto(v10, v11);
}
for ( j = 0; j != 8; ++j )
draw_petal(v8, v9, 0.7853981633974483, (double)j * 0.7853981633974483, v4);
plotend();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
double v4; // rbp
int i; // ebx
int j; // ebx
double v8; // [rsp+0h] [rbp-58h]
double v9; // [rsp+8h] [rbp-50h]
double v10; // [rsp+10h] [rbp-48h]
double v11; // [rsp+18h] [rbp-40h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx; // [rsp+28h] [rbp-30h] BYREF
double v14; // [rsp+30h] [rbp-28h] BYREF
double v15[4]; // [rsp+38h] [rbp-20h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v3 == -1 )
break;
if ( v3 - 110 > 8 || ((1LL << ((unsigned __int8)v3 - 110)) & 0x167) == 0 )
{
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", *argv);
fwrite(" <size> ::= A1 | A2 | A3 | A4 | A5\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
plotopt(v3, optarg);
}
if ( (int)plotbegin(1LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v15, &v14);
v8 = 0.5 * v15[0];
v9 = 0.5 * v14;
v4 = v14 / 3.0;
for ( i = 0; i != 8; ++i )
{
sincos((double)i * 0.7853981633974483, &sinx, &cosx);
v10 = v4 * cosx + v8;
v11 = v4 * sinx + v9;
moveto(v8, v9);
lineto(v10, v11);
}
for ( j = 0; j != 8; ++j )
func0(v8, v9, 0.7853981633974483, (double)j * 0.7853981633974483, v4);
plotend();
return 0;
}

original_code:
int main(int argc, char * const argv[])
{
   int opt;
   int i;
   double xc, yc;
   double maxx, maxy;
   double delta;
   int npetals = 8;
   double radius;
   while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
      switch (opt) {
      case 's':
      case 'n':
      case 'o':
      case 'p':
      case 't':
      case 'v':
         plotopt(opt, optarg);
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
         fprintf(stderr, "       <size> ::= A1 | A2 | A3 | A4 | A5\n");
         exit(1);
      }
   }
   if (plotbegin(1) < 0) {
      fputs("Failed to initialise HPGL library\n", stderr);
      exit(1);
   }
   getplotsize(&maxx, &maxy);
   xc = maxx / 2.0;
   yc = maxy / 2.0;
   delta = (2.0 * 3.14159265358979323846) / (double)npetals;
   radius = (maxy / 3.0);
   for (i = 0; i < npetals; i++) {
      const double theta = (double)i * delta;
      const double x = xc + (radius * cos(theta));
      const double y = yc + (radius * sin(theta));
      moveto(xc, yc);
      lineto(x, y);
   }
   for (i = 0; i < npetals; i++) {
      const double theta = delta * (double)i;
      draw_petal(xc, yc, delta, theta, radius);
   }
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   int i;
   double xc; double yc;
   double maxx; double maxy;
   double delta;
   int npetals = 8;
   double radius;
   while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
      switch (opt) {
      case 's':
      case 'n':
      case 'o':
      case 'p':
      case 't':
      case 'v':
         plotopt(opt, optarg);
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
         fprintf(stderr, "       <size> ::= A1 | A2 | A3 | A4 | A5\n");
         exit(1);
      }
   }
   if (plotbegin(1) < 0) {
      fputs("Failed to initialise HPGL library\n", stderr);
      exit(1);
   }
   getplotsize(&maxx, &maxy);
   xc = maxx / 2.0;
   yc = maxy / 2.0;
   delta = (2.0 * 3.14159265358979323846) / (double)npetals;
   radius = (maxy / 3.0);
   for (i = 0; i < npetals; i++) {
      double theta = (double)i * delta;
      double x = xc + (radius * cos(theta));
      double y = yc + (radius * sin(theta));
      moveto(xc, yc);
      lineto(x, y);
   }
   for (i = 0; i < npetals; i++) {
      double theta = delta * (double)i;
      draw_petal(xc, yc, delta, theta, radius);
   }
   plotend();
   return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: i int

variable_types: maxx double

variable_types: maxy double

variable_types: npetals int

variable_types: theta double

variable_types: x double

variable_types: y double

return_type: int


original_code:
void ringoboxes2(const double x0, const double y0, const double radius, int nboxes, const int ninner, const int offset, const double slant)
{
   int i, j, k, n;
   double side, s2;
   double theta;
   double delta;
   double s, c;
   double x[4], y[4];
   double rx[4], ry[4];
   double inc;
   double sr, cr;
   side = (2.0 * 3.14159265358979323846 * radius) / (double)nboxes;
   side *= 0.8;
   s2 = side / 2.0;
   inc = s2 / (double)ninner;
   delta = (2.0 * 3.14159265358979323846) / (double)nboxes;
   delta *= 2.0;
   nboxes /= 2;
   for (i = 0; i < nboxes; i++) {
      theta = (double)i * delta;
      if (offset)
         theta += delta / 2.0;
      s = sin(theta);
      c = cos(theta);
      for (k = 0; k < ninner; k++) {
         sr = sin(slant);
         cr = cos(slant);
         x[0] = -s2;
         y[0] = -s2;
         x[1] = s2;
         y[1] = -s2;
         x[2] = s2;
         y[2] = s2;
         x[3] = -s2;
         y[3] = s2;
         for (n = 0; n < 4; n++) {
            x[n] = (x[n] * cr) - (y[n] * sr);
            y[n] = (x[n] * sr) + (y[n] * cr);
         }
         for (j = 0; j < 4; j++) {
            if (x[j] < 0)
               x[j] += k * inc;
            else
               x[j] -= k * inc;
            if (y[j] < 0)
               y[j] += k * inc;
            else
               y[j] -= k * inc;
            rx[j] = (x[j] * c) - (y[j] * s);
            ry[j] = (x[j] * s) + (y[j] * c);
            rx[j] += x0 + (c * (radius + s2));
            ry[j] += y0 + (s * (radius + s2));
         }
         moveto(rx[0], ry[0]);
         lineto(rx[1], ry[1]);
         lineto(rx[2], ry[2]);
         lineto(rx[3], ry[3]);
         lineto(rx[0], ry[0]);
      }
   }
}

canonical_original_code:
void ringoboxes2(double x0, double y0, double radius, int nboxes, int ninner, int offset, double slant)
{
   int i; int j; int k; int n;
   double side; double s2;
   double theta;
   double delta;
   double s; double c;
   double x[4]; double y[4];
   double rx[4]; double ry[4];
   double inc;
   double sr; double cr;
   side = (2.0 * 3.14159265358979323846 * radius) / (double)nboxes;
   side *= 0.8;
   s2 = side / 2.0;
   inc = s2 / (double)ninner;
   delta = (2.0 * 3.14159265358979323846) / (double)nboxes;
   delta *= 2.0;
   nboxes /= 2;
   for (i = 0; i < nboxes; i++) {
      theta = (double)i * delta;
      if (offset)
         theta += delta / 2.0;
      s = sin(theta);
      c = cos(theta);
      for (k = 0; k < ninner; k++) {
         sr = sin(slant);
         cr = cos(slant);
         x[0] = -s2;
         y[0] = -s2;
         x[1] = s2;
         y[1] = -s2;
         x[2] = s2;
         y[2] = s2;
         x[3] = -s2;
         y[3] = s2;
         for (n = 0; n < 4; n++) {
            x[n] = (x[n] * cr) - (y[n] * sr);
            y[n] = (x[n] * sr) + (y[n] * cr);
         }
         for (j = 0; j < 4; j++) {
            if (x[j] < 0)
               x[j] += k * inc;
            else
               x[j] -= k * inc;
            if (y[j] < 0)
               y[j] += k * inc;
            else
               y[j] -= k * inc;
            rx[j] = (x[j] * c) - (y[j] * s);
            ry[j] = (x[j] * s) + (y[j] * c);
            rx[j] += x0 + (c * (radius + s2));
            ry[j] += y0 + (s * (radius + s2));
         }
         moveto(rx[0], ry[0]);
         lineto(rx[1], ry[1]);
         lineto(rx[2], ry[2]);
         lineto(rx[3], ry[3]);
         lineto(rx[0], ry[0]);
      }
   }
}

variable_types: radius double

variable_types: nboxes int

variable_types: ninner int

variable_types: offset int

variable_types: slant double

variable_types: j int

variable_types: k int

variable_types: n int

variable_types: side double

variable_types: delta double

variable_types: s double

variable_types: c double

variable_types:
x
double [4]

variable_types:
y
double [4]

variable_types:
rx
double [4]

variable_types:
ry
double [4]

variable_types: inc double

variable_types: sr double

variable_types: cr double

return_type: void


original_code:
int main(int argc, char * const argv[])
{
   int opt;
   int i;
   double xc, yc;
   double maxx, maxy;
   double height;
   double radius;
   double r;
   double slant;
   while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
      switch (opt) {
      case 'n':
      case 'o':
      case 'p':
      case 's':
      case 't':
      case 'v':
         plotopt(opt, optarg);
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
         fprintf(stderr, "       <size> ::= A1 | A2 | A3 | A4 | A5\n");
         exit(1);
      }
   }
   if (plotbegin(0) < 0) {
      fputs("Failed to initialise HPGL library\n", stderr);
      exit(1);
   }
   getplotsize(&maxx, &maxy);
   xc = maxx / 2.0;
   yc = maxy / 2.0;
   height = maxy;
   circle(xc, yc, yc);
   radius = height / 12.0;
   for (i = 0; i < 4; i++) {
      if (i & 1)
         slant = (20.0);
      else
         slant = -(20.0);
      r = radius * (i + 1.5);
      ringoboxes2(xc, yc, r, 18 * (i + 1), 1, 0, slant * (3.14159265358979323846 / 180.0));
   }
   pencolr(1);
   for (i = 0; i < 4; i++) {
      if (i & 1)
         slant = (20.0);
      else
         slant = -(20.0);
      r = radius * (i + 1.5);
      ringoboxes2(xc, yc, r, 18 * (i + 1), 1, 1, slant * (3.14159265358979323846 / 180.0));
   }
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   int i;
   double xc; double yc;
   double maxx; double maxy;
   double height;
   double radius;
   double r;
   double slant;
   while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
      switch (opt) {
      case 'n':
      case 'o':
      case 'p':
      case 's':
      case 't':
      case 'v':
         plotopt(opt, optarg);
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
         fprintf(stderr, "       <size> ::= A1 | A2 | A3 | A4 | A5\n");
         exit(1);
      }
   }
   if (plotbegin(0) < 0) {
      fputs("Failed to initialise HPGL library\n", stderr);
      exit(1);
   }
   getplotsize(&maxx, &maxy);
   xc = maxx / 2.0;
   yc = maxy / 2.0;
   height = maxy;
   circle(xc, yc, yc);
   radius = height / 12.0;
   for (i = 0; i < 4; i++) {
      if (i & 1)
         slant = (20.0);
      else
         slant = -(20.0);
      r = radius * (i + 1.5);
      ringoboxes2(xc, yc, r, 18 * (i + 1), 1, 0, slant * (3.14159265358979323846 / 180.0));
   }
   pencolr(1);
   for (i = 0; i < 4; i++) {
      if (i & 1)
         slant = (20.0);
      else
         slant = -(20.0);
      r = radius * (i + 1.5);
      ringoboxes2(xc, yc, r, 18 * (i + 1), 1, 1, slant * (3.14159265358979323846 / 180.0));
   }
   plotend();
   return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: i int

variable_types: xc double

variable_types: yc double

variable_types: maxx double

variable_types: maxy double

variable_types: height double

variable_types: radius double

variable_types: r double


decompiled_code:
__int64 __fastcall draw_star(int a1, double a2, double a3, double a4, double a5, double a6)
{
__int64 result; // rax
int v7; // ebx
int v9; // er13
double v10; // xmm0_8
int v11; // er13
double v12; // r14
double v13; // xmm1_8
int v14; // er13
double v15; // r15
double v16; // xmm2_8
int v17; // er13
double v18; // xmm1_8
double v19; // [rsp+8h] [rbp-60h]

result = (unsigned int)(a1 - 1);
v19 = a4 / (double)(int)result;
v7 = a1 / 2;
if ( a1 > 1 )
{
v9 = 0;
do
{
v10 = (double)v9 * v19 + (double)v9 * v19 + a2;
moveto(v10, a3);
lineto(a5, a6);
lineto(v19 + v10, a3);
++v9;
}
while ( v9 < v7 );
v11 = 0;
v12 = a4 + a2;
do
{
v13 = (double)v11 * v19 + (double)v11 * v19 + a3;
moveto(v12, v13);
lineto(a5, a6);
lineto(v12, v19 + v13);
++v11;
}
while ( v11 < v7 );
v14 = 0;
v15 = a4 + a3;
do
{
v16 = v12 - ((double)v14 * v19 + (double)v14 * v19);
moveto(v16, v15);
lineto(a5, a6);
lineto(v16 - v19, v15);
++v14;
}
while ( v14 < v7 );
v17 = 0;
do
{
v18 = v15 - ((double)v17 * v19 + (double)v17 * v19);
moveto(a2, v18);
lineto(a5, a6);
result = lineto(a2, v18 - v19);
++v17;
}
while ( v17 < v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3, double a4, double a5, double a6)
{
__int64 result; // rax
int v7; // ebx
int v9; // er13
double v10; // xmm0_8
int v11; // er13
double v12; // r14
double v13; // xmm1_8
int v14; // er13
double v15; // r15
double v16; // xmm2_8
int v17; // er13
double v18; // xmm1_8
double v19; // [rsp+8h] [rbp-60h]

result = (unsigned int)(a1 - 1);
v19 = a4 / (double)(int)result;
v7 = a1 / 2;
if ( a1 > 1 )
{
v9 = 0;
do
{
v10 = (double)v9 * v19 + (double)v9 * v19 + a2;
moveto(v10, a3);
lineto(a5, a6);
lineto(v19 + v10, a3);
++v9;
}
while ( v9 < v7 );
v11 = 0;
v12 = a4 + a2;
do
{
v13 = (double)v11 * v19 + (double)v11 * v19 + a3;
moveto(v12, v13);
lineto(a5, a6);
lineto(v12, v19 + v13);
++v11;
}
while ( v11 < v7 );
v14 = 0;
v15 = a4 + a3;
do
{
v16 = v12 - ((double)v14 * v19 + (double)v14 * v19);
moveto(v16, v15);
lineto(a5, a6);
lineto(v16 - v19, v15);
++v14;
}
while ( v14 < v7 );
v17 = 0;
do
{
v18 = v15 - ((double)v17 * v19 + (double)v17 * v19);
moveto(a2, v18);
lineto(a5, a6);
result = lineto(a2, v18 - v19);
++v17;
}
while ( v17 < v7 );
}
return result;
}

original_code:
void draw_star(const double x0, const double y0, const double gridsz, const double xc, const double yc, const int n)
{
   int i;
   const double d = gridsz / (double)(n - 1);
   for (i = 0; i < (n / 2); i++) {
      const double x1 = x0 + (i * d * 2.0);
      const double x2 = x1 + d;
      moveto(x1, y0);
      lineto(xc, yc);
      lineto(x2, y0);
   }
   for (i = 0; i < (n / 2); i++) {
      const double y1 = y0 + (i * d * 2.0);
      const double y2 = y1 + d;
      moveto(x0 + gridsz, y1);
      lineto(xc, yc);
      lineto(x0 + gridsz, y2);
   }
   for (i = 0; i < (n / 2); i++) {
      const double x1 = x0 + gridsz - (i * d * 2.0);
      const double x2 = x1 - d;
      moveto(x1, y0 + gridsz);
      lineto(xc, yc);
      lineto(x2, y0 + gridsz);
   }
   for (i = 0; i < (n / 2); i++) {
      const double y1 = y0 + gridsz - (i * d * 2.0);
      const double y2 = y1 - d;
      moveto(x0, y1);
      lineto(xc, yc);
      lineto(x0, y2);
   }
}

canonical_original_code:
void draw_star(double x0, double y0, double gridsz, double xc, double yc, int n)
{
   int i;
   double d = gridsz / (double)(n - 1);
   for (i = 0; i < (n / 2); i++) {
      double x1 = x0 + (i * d * 2.0);
      double x2 = x1 + d;
      moveto(x1, y0);
      lineto(xc, yc);
      lineto(x2, y0);
   }
   for (i = 0; i < (n / 2); i++) {
      double y1 = y0 + (i * d * 2.0);
      double y2 = y1 + d;
      moveto(x0 + gridsz, y1);
      lineto(xc, yc);
      lineto(x0 + gridsz, y2);
   }
   for (i = 0; i < (n / 2); i++) {
      double x1 = x0 + gridsz - (i * d * 2.0);
      double x2 = x1 - d;
      moveto(x1, y0 + gridsz);
      lineto(xc, yc);
      lineto(x2, y0 + gridsz);
   }
   for (i = 0; i < (n / 2); i++) {
      double y1 = y0 + gridsz - (i * d * 2.0);
      double y2 = y1 - d;
      moveto(x0, y1);
      lineto(xc, yc);
      lineto(x0, y2);
   }
}

variable_types: gridsz double

variable_types: n int

variable_types: d double


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
char *v5; // r15
double v6; // r12
int i; // er13
int j; // er13
int k; // er12
int l; // ebx
double v11; // xmm1_8
double v13; // [rsp+0h] [rbp-68h]
double v14; // [rsp+18h] [rbp-50h]
double v15; // [rsp+20h] [rbp-48h] BYREF
double v16[8]; // [rsp+28h] [rbp-40h] BYREF

v3 = 7;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v4 == -1 )
break;
if ( v4 == 115 )
{
v5 = optarg;
if ( strchr(optarg, 49) )
{
v3 = 15;
}
else if ( strchr(v5, 50) )
{
v3 = 9;
}
else if ( strchr(v5, 52) )
{
v3 = 7;
}
else if ( strchr(v5, 53) )
{
v3 = 7;
}
}
else if ( v4 <= 115 )
{
if ( (unsigned int)(v4 - 110) > 2 )
goto LABEL_8;
}
else if ( (v4 & 0xFFFFFFFD) != 116 )
{
LABEL_8:
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", *argv);
fwrite(" <size> ::= A1 | A2 | A3 | A4 | A5\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
plotopt((unsigned int)v4, optarg);
}
if ( (int)plotbegin(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v16, &v15);
v13 = v15 / (double)v3;
v14 = 0.5 * v16[0] - 0.5 * v15;
v6 = 0.5 * v15 + 0.5 * v16[0];
rectangle(v14, 0.0, v6);
for ( i = 1; i != v3; ++i )
{
moveto((double)i * v13 + v14, 0.0);
lineto((double)i * v13 + v14, v15);
}
for ( j = 1; j != v3; ++j )
{
moveto(v14, (double)j * v13);
lineto(v6, (double)j * v13);
}
for ( k = 0; k < v3; ++k )
{
for ( l = 0;
l < v3;
draw_star(
9,
(double)k * v13 + v14,
v11,
v13,
(double)(k + 1) * v13 / (double)(v3 + 1) + (double)k * v13 + v14,
(double)l * v13 / (double)(v3 + 1) + v11) )
{
v11 = (double)l++ * v13;
}
}
plotend();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // ebx
char *v5; // r15
double v6; // r12
int i; // er13
int j; // er13
int k; // er12
int l; // ebx
double v11; // xmm1_8
double v13; // [rsp+0h] [rbp-68h]
double v14; // [rsp+18h] [rbp-50h]
double v15; // [rsp+20h] [rbp-48h] BYREF
double v16[8]; // [rsp+28h] [rbp-40h] BYREF

v3 = 7;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v4 == -1 )
break;
if ( v4 == 115 )
{
v5 = optarg;
if ( strchr(optarg, 49) )
{
v3 = 15;
}
else if ( strchr(v5, 50) )
{
v3 = 9;
}
else if ( strchr(v5, 52) )
{
v3 = 7;
}
else if ( strchr(v5, 53) )
{
v3 = 7;
}
}
else if ( v4 <= 115 )
{
if ( (unsigned int)(v4 - 110) > 2 )
goto LABEL_8;
}
else if ( (v4 & 0xFFFFFFFD) != 116 )
{
LABEL_8:
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", *argv);
fwrite(" <size> ::= A1 | A2 | A3 | A4 | A5\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
plotopt((unsigned int)v4, optarg);
}
if ( (int)plotbegin(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v16, &v15);
v13 = v15 / (double)v3;
v14 = 0.5 * v16[0] - 0.5 * v15;
v6 = 0.5 * v15 + 0.5 * v16[0];
rectangle(v14, 0.0, v6);
for ( i = 1; i != v3; ++i )
{
moveto((double)i * v13 + v14, 0.0);
lineto((double)i * v13 + v14, v15);
}
for ( j = 1; j != v3; ++j )
{
moveto(v14, (double)j * v13);
lineto(v6, (double)j * v13);
}
for ( k = 0; k < v3; ++k )
{
for ( l = 0;
l < v3;
func0(
9,
(double)k * v13 + v14,
v11,
v13,
(double)(k + 1) * v13 / (double)(v3 + 1) + (double)k * v13 + v14,
(double)l * v13 / (double)(v3 + 1) + v11) )
{
v11 = (double)l++ * v13;
}
}
plotend();
return 0;
}

original_code:
int main(int argc, char * const argv[])
{
   int opt;
   int i, j;
   int ncells;
   double height;
   double xc;
   double maxx, maxy;
   double left, right;
   double gridsz;
   ncells = 7;
   while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
      switch (opt) {
      case 's':
         if (strchr(optarg, '1'))
            ncells = 15;
         else if (strchr(optarg, '2'))
            ncells = 9;
         else if (strchr(optarg, '4'))
            ncells = 7;
         else if (strchr(optarg, '5'))
            ncells = 7;
      case 'n':
      case 'o':
      case 'p':
      case 't':
      case 'v':
         plotopt(opt, optarg);
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
         fprintf(stderr, "       <size> ::= A1 | A2 | A3 | A4 | A5\n");
         exit(1);
      }
   }
   if (plotbegin(0) < 0) {
      fputs("Failed to initialise HPGL library\n", stderr);
      exit(1);
   }
   getplotsize(&maxx, &maxy);
   xc = maxx / 2.0;
   height = maxy;
   gridsz = maxy / (double)ncells;
   left = xc - (height / 2.0);
   right = xc + (height / 2.0);
   rectangle(left, 0.0, right, maxy);
   for (i = 1; i < ncells; i++) {
      const double x = left + (i * gridsz);
      moveto(x, 0.0);
      lineto(x, maxy);
   }
   for (i = 1; i < ncells; i++) {
      const double y = i * gridsz;
      moveto(left, y);
      lineto(right, y);
   }
   for (i = 0; i < ncells; i++) {
      for (j = 0; j < ncells; j++) {
         const double x0 = left + (i * gridsz);
         const double y0 = j * gridsz;
         const double xc = x0 + ((gridsz * (i + 1)) / (double)(ncells + 1));
         const double yc = y0 + ((gridsz * (j + 1)) / (double)(ncells + 1));
         draw_star(x0, y0, gridsz, xc, yc, 9);
      }
   }
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   int i; int j;
   int ncells;
   double height;
   double xc;
   double maxx; double maxy;
   double left; double right;
   double gridsz;
   ncells = 7;
   while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
      switch (opt) {
      case 's':
         if (strchr(optarg, '1'))
            ncells = 15;
         else if (strchr(optarg, '2'))
            ncells = 9;
         else if (strchr(optarg, '4'))
            ncells = 7;
         else if (strchr(optarg, '5'))
            ncells = 7;
      case 'n':
      case 'o':
      case 'p':
      case 't':
      case 'v':
         plotopt(opt, optarg);
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
         fprintf(stderr, "       <size> ::= A1 | A2 | A3 | A4 | A5\n");
         exit(1);
      }
   }
   if (plotbegin(0) < 0) {
      fputs("Failed to initialise HPGL library\n", stderr);
      exit(1);
   }
   getplotsize(&maxx, &maxy);
   xc = maxx / 2.0;
   height = maxy;
   gridsz = maxy / (double)ncells;
   left = xc - (height / 2.0);
   right = xc + (height / 2.0);
   rectangle(left, 0.0, right, maxy);
   for (i = 1; i < ncells; i++) {
      double x = left + (i * gridsz);
      moveto(x, 0.0);
      lineto(x, maxy);
   }
   for (i = 1; i < ncells; i++) {
      double y = i * gridsz;
      moveto(left, y);
      lineto(right, y);
   }
   for (i = 0; i < ncells; i++) {
      for (j = 0; j < ncells; j++) {
         double x0 = left + (i * gridsz);
         double y0 = j * gridsz;
         double xc = x0 + ((gridsz * (i + 1)) / (double)(ncells + 1));
         double yc = y0 + ((gridsz * (j + 1)) / (double)(ncells + 1));
         draw_star(x0, y0, gridsz, xc, yc, 9);
      }
   }
   plotend();
   return (0);
}

variable_types: j int

variable_types: ncells int

variable_types: left double

variable_types: right double

variable_types: x double

variable_types: y double


original_code:
void ellipse_foci(const double x1, const double y1, const double x2, const double y2, const double d)
{
   const double dx = x2 - x1;
   const double dy = y2 - y1;
   const double f2 = sqrt((dx * dx) + (dy * dy)) / 2.0;
   const double a = d / 2.0;
   const double b = sqrt((a * a) - (f2 * f2));
   const double x0 = (x1 + x2) / 2.0;
   const double y0 = (y1 + y2) / 2.0;
   const double theta = atan2(dy, dx);
   ellipse(x0, y0, a, b, theta);
}

canonical_original_code:
void ellipse_foci(double x1, double y1, double x2, double y2, double d)
{
   double dx = x2 - x1;
   double dy = y2 - y1;
   double f2 = sqrt((dx * dx) + (dy * dy)) / 2.0;
   double a = d / 2.0;
   double b = sqrt((a * a) - (f2 * f2));
   double x0 = (x1 + x2) / 2.0;
   double y0 = (y1 + y2) / 2.0;
   double theta = atan2(dy, dx);
   ellipse(x0, y0, a, b, theta);
}

variable_types: dx double

variable_types: dy double

variable_types: a double

variable_types: b double

variable_types: theta double


decompiled_code:
__int64 __fastcall half_ellipse(double a1, double a2, double a3, double a4, double a5)
{
int v5; // ebp
int i; // ebx
double v7; // xmm0_8
double v8; // xmm1_8
__int64 result; // rax
double v10; // [rsp+0h] [rbp-58h]
double v11; // [rsp+8h] [rbp-50h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx[6]; // [rsp+28h] [rbp-30h] BYREF

sincos(a5, sinx, &cosx);
v10 = cosx;
v11 = sinx[0];
v5 = 1;
for ( i = 0; ; ++i )
{
sincos((double)i * 0.08726646259971647, sinx, &cosx);
v7 = v10 * (a3 * cosx) - v11 * (a4 * sinx[0]);
v8 = a3 * cosx * v11 + a4 * sinx[0] * v10;
if ( !i )
{
moveto(v7 + a1, v8 + a2);
goto LABEL_3;
}
result = lineto(v7 + a1, v8 + a2);
if ( v5 > 36 )
break;
LABEL_3:
++v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(double a1, double a2, double a3, double a4, double a5)
{
int v5; // ebp
int i; // ebx
double v7; // xmm0_8
double v8; // xmm1_8
__int64 result; // rax
double v10; // [rsp+0h] [rbp-58h]
double v11; // [rsp+8h] [rbp-50h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx[6]; // [rsp+28h] [rbp-30h] BYREF

sincos(a5, sinx, &cosx);
v10 = cosx;
v11 = sinx[0];
v5 = 1;
for ( i = 0; ; ++i )
{
sincos((double)i * 0.08726646259971647, sinx, &cosx);
v7 = v10 * (a3 * cosx) - v11 * (a4 * sinx[0]);
v8 = a3 * cosx * v11 + a4 * sinx[0] * v10;
if ( !i )
{
moveto(v7 + a1, v8 + a2);
goto LABEL_3;
}
result = lineto(v7 + a1, v8 + a2);
if ( v5 > 36 )
break;
LABEL_3:
++v5;
}
return result;
}

original_code:
void half_ellipse(const double x0, const double y0, const double a, const double b, const double theta)
{
   const int npts = 36;
   const double delta = 3.14159265358979323846 / (double)npts;
   const double sintheta = sin(theta);
   const double costheta = cos(theta);
   int i;
   for (i = 0; i <= npts; i++) {
      const double t = (double)i * delta;
      const double x = (a * cos(t) * costheta) - (b * sin(t) * sintheta);
      const double y = (a * cos(t) * sintheta) + (b * sin(t) * costheta);
      if (i == 0)
         moveto(x0 + x, y0 + y);
      else
         lineto(x0 + x, y0 + y);
   }
}

canonical_original_code:
void half_ellipse(double x0, double y0, double a, double b, double theta)
{
   int npts = 36;
   double delta = 3.14159265358979323846 / (double)npts;
   double sintheta = sin(theta);
   double costheta = cos(theta);
   int i;
   for (i = 0; i <= npts; i++) {
      double t = (double)i * delta;
      double x = (a * cos(t) * costheta) - (b * sin(t) * sintheta);
      double y = (a * cos(t) * sintheta) + (b * sin(t) * costheta);
      if (i == 0)
         moveto(x0 + x, y0 + y);
      else
         lineto(x0 + x, y0 + y);
   }
}

variable_types: npts int

variable_types: delta double

variable_types: sintheta double

variable_types: costheta double

variable_types: i int

variable_types: t double


turtle

decompiled_code:
__int64 __fastcall turtle(int a1, int a2, __int64 a3, int a4)
{
char v4; // bl
__int64 result; // rax
int v6; // eax

v4 = a4;
Pltdev = a1;
Main_flags = a4;
if ( a1 == 3 )
{
Scale = 0x3FF0000000000000LL;
goto LABEL_8;
}
if ( a1 <= 3 )
{
if ( a1 != 1 )
{
if ( a1 != 2 )
return 1LL;
Maxx = 0x40A4FE1025A70292LL;
Maxy = 0x409C2C8EEF2A4015LL;
Scale = 0x4024000000000000LL;
printf("IP1;PS%d;\n", 1LL);
goto LABEL_8;
}
if ( a2 == 4 )
{
Minx = 0LL;
Miny = 0LL;
Maxx = 0x40C53B0000000000LL;
Maxy = 0x40BF310000000000LL;
Scale = 0x403C47AE147AE148LL;
goto LABEL_27;
}
if ( a2 > 4 )
{
if ( a2 == 5 )
{
Minx = 0LL;
Miny = 0LL;
Maxx = 0x40BF310000000000LL;
Maxy = 0x40B53B0000000000LL;
Scale = 0x4034000000000000LL;
goto LABEL_27;
}
}
else
{
if ( a2 == 1 )
{
Minx = 0xC0CF310000000000LL;
Miny = 0xC0C53B0000000000LL;
Maxx = 0x40CF310000000000LL;
Maxy = 0x40C53B0000000000LL;
Scale = 0x4054000000000000LL;
goto LABEL_27;
}
if ( a2 == 3 )
{
Minx = 0LL;
Miny = 0LL;
Maxx = 0x40CF310000000000LL;
Maxy = 0x40C53B0000000000LL;
Scale = 0x4044000000000000LL;
LABEL_27:
if ( (v4 & 4) == 0 )
Scale = 0x4044000000000000LL;
printf("IN;SP%d;\n", 1LL);
goto LABEL_8;
}
}
fwrite("paper size not supported\n", 1uLL, 0x19uLL, stderr);
goto LABEL_27;
}
result = 1LL;
if ( a1 != 4 )
return result;
LABEL_8:
*(double *)&Homex = (*(double *)&Minx + *(double *)&Maxx) * 0.5;
*(double *)&Homey = (*(double *)&Miny + *(double *)&Maxy) * 0.5;
Penstate = 1;
Pencol = 1;
Heading = 0LL;
Xvec = 0x3FF0000000000000LL;
Yvec = 0LL;
if ( (v4 & 2) != 0 )
{
if ( Pltdev == 1 )
{
puts("VS10;");
}
else
{
if ( (unsigned int)(Pltdev - 2) <= 2 )
{
if ( (v4 & 1) == 0 )
goto LABEL_15;
v6 = Pltdev;
goto LABEL_13;
}
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
}
}
if ( (v4 & 1) == 0 )
goto LABEL_15;
v6 = Pltdev;
if ( Pltdev == 1 )
{
printf("PU;PA%d,%d;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
printf("PD;PA%d,%d;\n", (unsigned int)(int)*(double *)&Maxx, (unsigned int)(int)*(double *)&Miny);
printf("PD;PA%d,%d;\n", (unsigned int)(int)*(double *)&Maxx, (unsigned int)(int)*(double *)&Maxy);
printf("PD;PA%d,%d;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Maxy);
printf("PD;PA%d,%d;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
goto LABEL_15;
}
LABEL_13:
if ( (unsigned int)(v6 - 2) > 2 )
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
LABEL_15:
if ( Pltdev == 2 )
{
printf("MA%d,%d\n", (unsigned int)(int)*(double *)&Homex, (unsigned int)(int)*(double *)&Homey);
goto LABEL_39;
}
if ( Pltdev > 2 )
{
if ( (unsigned int)(Pltdev - 3) <= 1 )
goto LABEL_39;
LABEL_42:
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
goto LABEL_39;
}
if ( Pltdev != 1 )
goto LABEL_42;
printf("PU;PA%d,%d;\n", (unsigned int)(int)*(double *)&Homex, (unsigned int)(int)*(double *)&Homey);
LABEL_39:
Xpos = Homex;
Ypos = Homey;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, __int64 a3, int a4)
{
char v4; // bl
__int64 result; // rax
int v6; // eax

v4 = a4;
Pltdev = a1;
Main_flags = a4;
if ( a1 == 3 )
{
Scale = 0x3FF0000000000000LL;
goto LABEL_8;
}
if ( a1 <= 3 )
{
if ( a1 != 1 )
{
if ( a1 != 2 )
return 1LL;
Maxx = 0x40A4FE1025A70292LL;
Maxy = 0x409C2C8EEF2A4015LL;
Scale = 0x4024000000000000LL;
printf("IP1;PS%d;\n", 1LL);
goto LABEL_8;
}
if ( a2 == 4 )
{
Minx = 0LL;
Miny = 0LL;
Maxx = 0x40C53B0000000000LL;
Maxy = 0x40BF310000000000LL;
Scale = 0x403C47AE147AE148LL;
goto LABEL_27;
}
if ( a2 > 4 )
{
if ( a2 == 5 )
{
Minx = 0LL;
Miny = 0LL;
Maxx = 0x40BF310000000000LL;
Maxy = 0x40B53B0000000000LL;
Scale = 0x4034000000000000LL;
goto LABEL_27;
}
}
else
{
if ( a2 == 1 )
{
Minx = 0xC0CF310000000000LL;
Miny = 0xC0C53B0000000000LL;
Maxx = 0x40CF310000000000LL;
Maxy = 0x40C53B0000000000LL;
Scale = 0x4054000000000000LL;
goto LABEL_27;
}
if ( a2 == 3 )
{
Minx = 0LL;
Miny = 0LL;
Maxx = 0x40CF310000000000LL;
Maxy = 0x40C53B0000000000LL;
Scale = 0x4044000000000000LL;
LABEL_27:
if ( (v4 & 4) == 0 )
Scale = 0x4044000000000000LL;
printf("IN;SP%d;\n", 1LL);
goto LABEL_8;
}
}
fwrite("paper size not supported\n", 1uLL, 0x19uLL, stderr);
goto LABEL_27;
}
result = 1LL;
if ( a1 != 4 )
return result;
LABEL_8:
*(double *)&Homex = (*(double *)&Minx + *(double *)&Maxx) * 0.5;
*(double *)&Homey = (*(double *)&Miny + *(double *)&Maxy) * 0.5;
Penstate = 1;
Pencol = 1;
Heading = 0LL;
Xvec = 0x3FF0000000000000LL;
Yvec = 0LL;
if ( (v4 & 2) != 0 )
{
if ( Pltdev == 1 )
{
puts("VS10;");
}
else
{
if ( (unsigned int)(Pltdev - 2) <= 2 )
{
if ( (v4 & 1) == 0 )
goto LABEL_15;
v6 = Pltdev;
goto LABEL_13;
}
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
}
}
if ( (v4 & 1) == 0 )
goto LABEL_15;
v6 = Pltdev;
if ( Pltdev == 1 )
{
printf("PU;PA%d,%d;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
printf("PD;PA%d,%d;\n", (unsigned int)(int)*(double *)&Maxx, (unsigned int)(int)*(double *)&Miny);
printf("PD;PA%d,%d;\n", (unsigned int)(int)*(double *)&Maxx, (unsigned int)(int)*(double *)&Maxy);
printf("PD;PA%d,%d;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Maxy);
printf("PD;PA%d,%d;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
goto LABEL_15;
}
LABEL_13:
if ( (unsigned int)(v6 - 2) > 2 )
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
LABEL_15:
if ( Pltdev == 2 )
{
printf("MA%d,%d\n", (unsigned int)(int)*(double *)&Homex, (unsigned int)(int)*(double *)&Homey);
goto LABEL_39;
}
if ( Pltdev > 2 )
{
if ( (unsigned int)(Pltdev - 3) <= 1 )
goto LABEL_39;
LABEL_42:
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
goto LABEL_39;
}
if ( Pltdev != 1 )
goto LABEL_42;
printf("PU;PA%d,%d;\n", (unsigned int)(int)*(double *)&Homex, (unsigned int)(int)*(double *)&Homey);
LABEL_39:
Xpos = Homex;
Ypos = Homey;
return 0LL;
}

original_code:
int turtle(const int dev, const int siz, const int ori, const int flags)
{
   Pltdev = dev;
   Main_flags = flags;
   switch (dev) {
   case (1):
      switch (siz) {
      case (1):
         Minx = -15970.0;
         Miny = -10870.0;
         Maxx = 15970.0;
         Maxy = 10870.0;
         Scale = 80.0;
         break;
      case (3):
         Minx = 0.0;
         Miny = 0.0;
         Maxx = 15970.0;
         Maxy = 10870.0;
         Scale = 40.0;
         break;
      case (4):
         Minx = 0.0;
         Miny = 0.0;
         Maxx = 10870.0;
         Maxy = 7985.0;
         Scale = 28.28;
         break;
      case (5):
         Minx = 0.0;
         Miny = 0.0;
         Maxx = 7985.0;
         Maxy = 5435.0;
         Scale = 20.0;
         break;
       default:
         fprintf(stderr, "paper size not supported\n");
         break;
      }
      if ((flags & (4)) == 0)
         Scale = 40.0;
      printf("IN;SP%d;\n", (1));
      break;
   case (2):
      Maxx = 3800.0;
      Maxy = 2550.0;
      Maxx /= 1.4142;
      Maxy /= 1.4142;
      Scale = 10.0;
      printf("IP1;PS%d;\n", (1));
      break;
   case (3):
      Scale = 1.0;
      break;
   case (4):
      break;
   default:
      return (1);
   }
   Homex = (Minx + Maxx) / 2.0;
   Homey = (Miny + Maxy) / 2.0;
   Penstate = (1);
   Pencol = (1);
   Heading = 0.0;
   Xvec = cos(Heading * (3.14159265358979323846 / 180.0));
   Yvec = sin(Heading * (3.14159265358979323846 / 180.0));
   if (flags & (2)) {
      switch (Pltdev) {
      case (1):
         printf("VS10;\n");
         break;
      case (2):
         break;
      case (3):
         break;
      case (4):
         break;
      default:
         fprintf(stderr, "Turtle graphics not initialised\n");
         break;
      }
   }
   if (flags & (1)) {
      switch (Pltdev) {
      case (1):
         printf("PU;PA%d,%d;\n", (int)Minx, (int)Miny);
         printf("PD;PA%d,%d;\n", (int)Maxx, (int)Miny);
         printf("PD;PA%d,%d;\n", (int)Maxx, (int)Maxy);
         printf("PD;PA%d,%d;\n", (int)Minx, (int)Maxy);
         printf("PD;PA%d,%d;\n", (int)Minx, (int)Miny);
         break;
      case (2):
         break;
      case (3):
         break;
      case (4):
         break;
      default:
         fprintf(stderr, "Turtle graphics not initialised\n");
         break;
      }
   }
   switch (Pltdev) {
   case (1):
      printf("PU;PA%d,%d;\n", (int)Homex, (int)Homey);
      break;
   case (2):
      printf("MA%d,%d\n", (int)Homex, (int)Homey);
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
   Xpos = Homex;
   Ypos = Homey;
   return (0);
}

canonical_original_code:
int turtle(int dev, int siz, int ori, int flags)
{
   Pltdev = dev;
   Main_flags = flags;
   switch (dev) {
   case (1):
      switch (siz) {
      case (1):
         Minx = -15970.0;
         Miny = -10870.0;
         Maxx = 15970.0;
         Maxy = 10870.0;
         Scale = 80.0;
         break;
      case (3):
         Minx = 0.0;
         Miny = 0.0;
         Maxx = 15970.0;
         Maxy = 10870.0;
         Scale = 40.0;
         break;
      case (4):
         Minx = 0.0;
         Miny = 0.0;
         Maxx = 10870.0;
         Maxy = 7985.0;
         Scale = 28.28;
         break;
      case (5):
         Minx = 0.0;
         Miny = 0.0;
         Maxx = 7985.0;
         Maxy = 5435.0;
         Scale = 20.0;
         break;
       default:
         fprintf(stderr, "paper size not supported\n");
         break;
      }
      if ((flags & (4)) == 0)
         Scale = 40.0;
      printf("IN;SP%d;\n", (1));
      break;
   case (2):
      Maxx = 3800.0;
      Maxy = 2550.0;
      Maxx /= 1.4142;
      Maxy /= 1.4142;
      Scale = 10.0;
      printf("IP1;PS%d;\n", (1));
      break;
   case (3):
      Scale = 1.0;
      break;
   case (4):
      break;
   default:
      return (1);
   }
   Homex = (Minx + Maxx) / 2.0;
   Homey = (Miny + Maxy) / 2.0;
   Penstate = (1);
   Pencol = (1);
   Heading = 0.0;
   Xvec = cos(Heading * (3.14159265358979323846 / 180.0));
   Yvec = sin(Heading * (3.14159265358979323846 / 180.0));
   if (flags & (2)) {
      switch (Pltdev) {
      case (1):
         printf("VS10;\n");
         break;
      case (2):
         break;
      case (3):
         break;
      case (4):
         break;
      default:
         fprintf(stderr, "Turtle graphics not initialised\n");
         break;
      }
   }
   if (flags & (1)) {
      switch (Pltdev) {
      case (1):
         printf("PU;PA%d,%d;\n", (int)Minx, (int)Miny);
         printf("PD;PA%d,%d;\n", (int)Maxx, (int)Miny);
         printf("PD;PA%d,%d;\n", (int)Maxx, (int)Maxy);
         printf("PD;PA%d,%d;\n", (int)Minx, (int)Maxy);
         printf("PD;PA%d,%d;\n", (int)Minx, (int)Miny);
         break;
      case (2):
         break;
      case (3):
         break;
      case (4):
         break;
      default:
         fprintf(stderr, "Turtle graphics not initialised\n");
         break;
      }
   }
   switch (Pltdev) {
   case (1):
      printf("PU;PA%d,%d;\n", (int)Homex, (int)Homey);
      break;
   case (2):
      printf("MA%d,%d\n", (int)Homex, (int)Homey);
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
   Xpos = Homex;
   Ypos = Homey;
   return (0);
}

variable_types: dev int

variable_types: siz int

variable_types: ori int

variable_types: flags int


show

decompiled_code:
int show()
{
int result; // eax

if ( Pltdev == 2 )
return puts("MA0,0;");
if ( Pltdev <= 2 )
{
if ( Pltdev == 1 )
return printf("PU;PA%d,%d;SP0;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
return fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
}
result = Pltdev - 3;
if ( (unsigned int)(Pltdev - 3) > 1 )
return fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
return result;
}

canonical_decompiled_code:
int func9()
{
int result; // eax

if ( Pltdev == 2 )
return puts("MA0,0;");
if ( Pltdev <= 2 )
{
if ( Pltdev == 1 )
return printf("PU;PA%d,%d;SP0;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
return fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
}
result = Pltdev - 3;
if ( (unsigned int)(Pltdev - 3) > 1 )
return fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
return result;
}

original_code:
void show(void)
{
   switch (Pltdev) {
   case (1):
      printf("PU;PA%d,%d;SP0;\n", (int)Minx, (int)Miny);
      break;
   case (2):
      printf("MA0,0;\n");
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
}

canonical_original_code:
void show()
{
   switch (Pltdev) {
   case (1):
      printf("PU;PA%d,%d;SP0;\n", (int)Minx, (int)Miny);
      break;
   case (2):
      printf("MA0,0;\n");
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
}


title

decompiled_code:
int __fastcall title(char *s, char a2, char a3, double a4)
{
unsigned int v4; // er14
int result; // eax
unsigned int v7; // er15
unsigned __int64 v8; // r13
int v9; // edx
int v10; // eax
double v11; // rbx

if ( Pltdev == 1 )
{
if ( (a2 & 3) == 2 )
{
v7 = (int)((*(double *)&Miny + *(double *)&Maxy) * 0.5);
v8 = 0xBFD0000000000000LL;
}
else if ( (a2 & 3u) > 2 )
{
v7 = (int)*(double *)&Miny;
v8 = 0x3FD0000000000000LL;
}
else
{
v7 = (int)*(double *)&Maxy;
v8 = 0xBFF0000000000000LL;
}
v9 = strlen(s);
v10 = a2 & 0xC;
if ( v10 == 8 )
{
v4 = (int)((*(double *)&Minx + *(double *)&Maxx) * 0.5);
v11 = -(double)v9 * 0.5;
}
else if ( (a2 & 0xCu) > 8 )
{
v11 = 0.0;
if ( v10 == 12 )
{
v4 = (int)*(double *)&Maxx;
v11 = -(double)v9;
if ( (Main_flags & 1) != 0 )
v11 = -(double)v9 - 0.5;
}
}
else if ( (a2 & 8) != 0 )
{
v11 = 0.0;
}
else
{
v4 = (int)*(double *)&Minx;
v11 = 0.0;
if ( (Main_flags & 1) != 0 )
v11 = 0.5;
}
if ( (a3 & 1) != 0 )
puts("SL.36;");
else
puts("SL0;");
printf("SI%1.2f,%1.2f;\n", a4 / 13.1579, a4 / 10.0);
printf("PU;PA%d,%d;CP%1.2f,%1.2f;LB%s%c;\n", v4, v7, v11, *(double *)&v8, s, 3LL);
result = printf("PU;PA%d,%d;\n", (unsigned int)(int)*(double *)&Xpos, (unsigned int)(int)*(double *)&Ypos);
}
else
{
result = Pltdev - 2;
if ( (unsigned int)(Pltdev - 2) > 2 )
result = fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *s, char a2, char a3, double a4)
{
unsigned int v4; // er14
int result; // eax
unsigned int v7; // er15
unsigned __int64 v8; // r13
int v9; // edx
int v10; // eax
double v11; // rbx

if ( Pltdev == 1 )
{
if ( (a2 & 3) == 2 )
{
v7 = (int)((*(double *)&Miny + *(double *)&Maxy) * 0.5);
v8 = 0xBFD0000000000000LL;
}
else if ( (a2 & 3u) > 2 )
{
v7 = (int)*(double *)&Miny;
v8 = 0x3FD0000000000000LL;
}
else
{
v7 = (int)*(double *)&Maxy;
v8 = 0xBFF0000000000000LL;
}
v9 = strlen(s);
v10 = a2 & 0xC;
if ( v10 == 8 )
{
v4 = (int)((*(double *)&Minx + *(double *)&Maxx) * 0.5);
v11 = -(double)v9 * 0.5;
}
else if ( (a2 & 0xCu) > 8 )
{
v11 = 0.0;
if ( v10 == 12 )
{
v4 = (int)*(double *)&Maxx;
v11 = -(double)v9;
if ( (Main_flags & 1) != 0 )
v11 = -(double)v9 - 0.5;
}
}
else if ( (a2 & 8) != 0 )
{
v11 = 0.0;
}
else
{
v4 = (int)*(double *)&Minx;
v11 = 0.0;
if ( (Main_flags & 1) != 0 )
v11 = 0.5;
}
if ( (a3 & 1) != 0 )
puts("SL.36;");
else
puts("SL0;");
printf("SI%1.2f,%1.2f;\n", a4 / 13.1579, a4 / 10.0);
printf("PU;PA%d,%d;CP%1.2f,%1.2f;LB%s%c;\n", v4, v7, v11, *(double *)&v8, s, 3LL);
result = printf("PU;PA%d,%d;\n", (unsigned int)(int)*(double *)&Xpos, (unsigned int)(int)*(double *)&Ypos);
}
else
{
result = Pltdev - 2;
if ( (unsigned int)(Pltdev - 2) > 2 )
result = fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
}
return result;
}

original_code:
void title(const char str[], const double size, const int posn, const int flags)
{
   int x, y;
   double xc = 0.0;
   double yc = 0.0;
   const int len = strlen(str);
   switch (Pltdev) {
   case (1):
      switch (posn & 0x03) {
      case 0:
      case (1):
         y = (int)Maxy;
         yc = -1.0;
         break;
      case (2):
         y = (int)((Miny + Maxy) / 2.0);
         yc = -0.25;
         break;
      case (3):
         y = (int)Miny;
         yc = 0.25;
         break;
      }
      switch (posn & 0x0c) {
      case 0:
      case (4):
         x = (int)Minx;
         xc = 0.0;
         if (Main_flags & (1))
           xc += 0.5;
         break;
      case (8):
         x = (int)((Minx + Maxx) / 2.0);
         xc = -((double)len) / 2.0;
         break;
      case (12):
         x = (int)Maxx;
         xc = -((double)len);
         if (Main_flags & (1))
           xc -= 0.5;
         break;
      }
      if (flags & (1))
         printf("SL.36;\n");
      else
         printf("SL0;\n");
      printf("SI%1.2f,%1.2f;\n", size / 13.1579, size / 10.0);
      printf("PU;PA%d,%d;CP%1.2f,%1.2f;LB%s%c;\n", x, y, xc, yc, str, (0x03));
      printf("PU;PA%d,%d;\n", (int)Xpos, (int)Ypos);
      break;
   case (2):
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
}

canonical_original_code:
void title(char str[], double size, int posn, int flags)
{
   int x; int y;
   double xc = 0.0;
   double yc = 0.0;
   int len = strlen(str);
   switch (Pltdev) {
   case (1):
      switch (posn & 0x03) {
      case 0:
      case (1):
         y = (int)Maxy;
         yc = -1.0;
         break;
      case (2):
         y = (int)((Miny + Maxy) / 2.0);
         yc = -0.25;
         break;
      case (3):
         y = (int)Miny;
         yc = 0.25;
         break;
      }
      switch (posn & 0x0c) {
      case 0:
      case (4):
         x = (int)Minx;
         xc = 0.0;
         if (Main_flags & (1))
           xc += 0.5;
         break;
      case (8):
         x = (int)((Minx + Maxx) / 2.0);
         xc = -((double)len) / 2.0;
         break;
      case (12):
         x = (int)Maxx;
         xc = -((double)len);
         if (Main_flags & (1))
           xc -= 0.5;
         break;
      }
      if (flags & (1))
         printf("SL.36;\n");
      else
         printf("SL0;\n");
      printf("SI%1.2f,%1.2f;\n", size / 13.1579, size / 10.0);
      printf("PU;PA%d,%d;CP%1.2f,%1.2f;LB%s%c;\n", x, y, xc, yc, str, (0x03));
      printf("PU;PA%d,%d;\n", (int)Xpos, (int)Ypos);
      break;
   case (2):
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
}

variable_types:
str
char []

variable_types: size double

variable_types: posn int

variable_types: x int

variable_types: y int

variable_types: xc double

variable_types: yc double

variable_types: len int


decompiled_code:
int bottom_left()
{
int result; // eax

Xpos = Minx;
Ypos = Miny;
if ( Pltdev == 2 )
return printf("MA%d,%d\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
if ( Pltdev <= 2 )
{
if ( Pltdev == 1 )
return printf("PU;PA%d,%d;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
return fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
}
result = Pltdev - 3;
if ( (unsigned int)(Pltdev - 3) > 1 )
return fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
return result;
}

canonical_decompiled_code:
int func11()
{
int result; // eax

Xpos = Minx;
Ypos = Miny;
if ( Pltdev == 2 )
return printf("MA%d,%d\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
if ( Pltdev <= 2 )
{
if ( Pltdev == 1 )
return printf("PU;PA%d,%d;\n", (unsigned int)(int)*(double *)&Minx, (unsigned int)(int)*(double *)&Miny);
return fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
}
result = Pltdev - 3;
if ( (unsigned int)(Pltdev - 3) > 1 )
return fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
return result;
}

original_code:
void bottom_left(void)
{
   Xpos = Minx;
   Ypos = Miny;
   switch (Pltdev) {
   case (1):
      printf("PU;PA%d,%d;\n", (int)Xpos, (int)Ypos);
      break;
   case (2):
      printf("MA%d,%d\n", (int)Xpos, (int)Ypos);
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
}

canonical_original_code:
void bottom_left()
{
   Xpos = Minx;
   Ypos = Miny;
   switch (Pltdev) {
   case (1):
      printf("PU;PA%d,%d;\n", (int)Xpos, (int)Ypos);
      break;
   case (2):
      printf("MA%d,%d\n", (int)Xpos, (int)Ypos);
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
}


decompiled_code:
void __fastcall set_heading(double a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

Heading = *(_QWORD *)&a1;
sincos(a1 * 0.0174532925199433, sinx, (double *)&v1);
Xvec = v1;
Yvec = *(_QWORD *)&sinx[0];
}

canonical_decompiled_code:
void __fastcall func12(double a1)
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

Heading = *(_QWORD *)&a1;
sincos(a1 * 0.0174532925199433, sinx, (double *)&v1);
Xvec = v1;
Yvec = *(_QWORD *)&sinx[0];
}

variable_types: deg double


forward

decompiled_code:
int __fastcall forward(double a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
int result; // eax

v1 = a1 * *(double *)&Scale;
v2 = v1 * *(double *)&Xvec + *(double *)&Xpos;
v3 = v1 * *(double *)&Yvec + *(double *)&Ypos;
if ( Pltdev != 2 )
{
if ( Pltdev > 2 )
{
result = Pltdev - 3;
if ( (unsigned int)(Pltdev - 3) <= 1 )
goto LABEL_7;
}
else if ( Pltdev == 1 )
{
if ( Penstate == 1 )
result = printf("PD;PA%d,%d;\n", (unsigned int)(int)v2, (unsigned int)(int)v3);
else
result = printf("PU;PA%d,%d;\n", (unsigned int)(int)v2, (unsigned int)(int)v3);
goto LABEL_7;
}
result = fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
goto LABEL_7;
}
if ( Penstate == 1 )
result = printf("DA%d,%d\n", (unsigned int)(int)v2, (unsigned int)(int)v3);
else
result = printf("MA%d,%d\n", (unsigned int)(int)v2, (unsigned int)(int)v3);
LABEL_7:
Xpos = *(_QWORD *)&v2;
Ypos = *(_QWORD *)&v3;
return result;
}

canonical_decompiled_code:
int __fastcall func13(double a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
int result; // eax

v1 = a1 * *(double *)&Scale;
v2 = v1 * *(double *)&Xvec + *(double *)&Xpos;
v3 = v1 * *(double *)&Yvec + *(double *)&Ypos;
if ( Pltdev != 2 )
{
if ( Pltdev > 2 )
{
result = Pltdev - 3;
if ( (unsigned int)(Pltdev - 3) <= 1 )
goto LABEL_7;
}
else if ( Pltdev == 1 )
{
if ( Penstate == 1 )
result = printf("PD;PA%d,%d;\n", (unsigned int)(int)v2, (unsigned int)(int)v3);
else
result = printf("PU;PA%d,%d;\n", (unsigned int)(int)v2, (unsigned int)(int)v3);
goto LABEL_7;
}
result = fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
goto LABEL_7;
}
if ( Penstate == 1 )
result = printf("DA%d,%d\n", (unsigned int)(int)v2, (unsigned int)(int)v3);
else
result = printf("MA%d,%d\n", (unsigned int)(int)v2, (unsigned int)(int)v3);
LABEL_7:
Xpos = *(_QWORD *)&v2;
Ypos = *(_QWORD *)&v3;
return result;
}

original_code:
void forward(const double mm)
{
   const double len = mm * Scale;
   const double newx = Xpos + (Xvec * len);
   const double newy = Ypos + (Yvec * len);
   switch (Pltdev) {
   case (1):
      if (Penstate == (1))
         printf("PD;PA%d,%d;\n", (int)newx, (int)newy);
      else
         printf("PU;PA%d,%d;\n", (int)newx, (int)newy);
      break;
   case (2):
      if (Penstate == (1))
         printf("DA%d,%d\n", (int)newx, (int)newy);
      else
         printf("MA%d,%d\n", (int)newx, (int)newy);
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
   Xpos = newx;
   Ypos = newy;
}

canonical_original_code:
void forward(double mm)
{
   double len = mm * Scale;
   double newx = Xpos + (Xvec * len);
   double newy = Ypos + (Yvec * len);
   switch (Pltdev) {
   case (1):
      if (Penstate == (1))
         printf("PD;PA%d,%d;\n", (int)newx, (int)newy);
      else
         printf("PU;PA%d,%d;\n", (int)newx, (int)newy);
      break;
   case (2):
      if (Penstate == (1))
         printf("DA%d,%d\n", (int)newx, (int)newy);
      else
         printf("MA%d,%d\n", (int)newx, (int)newy);
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
   Xpos = newx;
   Ypos = newy;
}

variable_types: mm double

variable_types: len double

variable_types: newx double

variable_types: newy double


turn

decompiled_code:
void __fastcall turn(double a1)
{
double v1; // xmm0_8
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = a1 + *(double *)&Heading;
if ( v1 > 360.0 )
v1 = v1 - 360.0;
Heading = *(_QWORD *)&v1;
if ( v1 < 0.0 )
*(double *)&Heading = v1 + 360.0;
sincos(0.0174532925199433 * *(double *)&Heading, sinx, (double *)&v2);
Xvec = v2;
Yvec = *(_QWORD *)&sinx[0];
}

canonical_decompiled_code:
void __fastcall func14(double a1)
{
double v1; // xmm0_8
__int64 v2; // [rsp+0h] [rbp-18h] BYREF
double sinx[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = a1 + *(double *)&Heading;
if ( v1 > 360.0 )
v1 = v1 - 360.0;
Heading = *(_QWORD *)&v1;
if ( v1 < 0.0 )
*(double *)&Heading = v1 + 360.0;
sincos(0.0174532925199433 * *(double *)&Heading, sinx, (double *)&v2);
Xvec = v2;
Yvec = *(_QWORD *)&sinx[0];
}


pen

decompiled_code:
void __fastcall pen(int a1)
{
Penstate = a1;
}

canonical_decompiled_code:
void __fastcall func15(int a1)
{
Penstate = a1;
}

original_code:
void pen(const int flag)
{
   Penstate = flag;
}

canonical_original_code:
void pen(int flag)
{
   Penstate = flag;
}

variable_types: flag int


colour

decompiled_code:
void __fastcall colour(unsigned int a1)
{
if ( Pencol != a1 )
{
if ( Pltdev == 2 )
{
printf("PS%d;\n", a1);
goto LABEL_7;
}
if ( Pltdev > 2 )
{
if ( (unsigned int)(Pltdev - 3) <= 1 )
goto LABEL_7;
}
else if ( Pltdev == 1 )
{
printf("SP%d;\n", a1);
LABEL_7:
Pencol = a1;
return;
}
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
goto LABEL_7;
}
}

canonical_decompiled_code:
void __fastcall func16(unsigned int a1)
{
if ( Pencol != a1 )
{
if ( Pltdev == 2 )
{
printf("PS%d;\n", a1);
goto LABEL_7;
}
if ( Pltdev > 2 )
{
if ( (unsigned int)(Pltdev - 3) <= 1 )
goto LABEL_7;
}
else if ( Pltdev == 1 )
{
printf("SP%d;\n", a1);
LABEL_7:
Pencol = a1;
return;
}
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
goto LABEL_7;
}
}

original_code:
void colour(const int c)
{
   if (Pencol == c)
      return;
   switch (Pltdev) {
   case (1):
      printf("SP%d;\n", c);
      break;
   case (2):
      printf("PS%d;\n", c);
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
   Pencol = c;
}

canonical_original_code:
void colour(int c)
{
   if (Pencol == c)
      return;
   switch (Pltdev) {
   case (1):
      printf("SP%d;\n", c);
      break;
   case (2):
      printf("PS%d;\n", c);
      break;
   case (3):
      break;
   case (4):
      break;
   default:
      fprintf(stderr, "Turtle graphics not initialised\n");
      break;
   }
   Pencol = c;
}

variable_types: c int


decompiled_code:
double page_width()
{
if ( Pltdev )
return (*(double *)&Maxx - *(double *)&Minx) / *(double *)&Scale;
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
return 0.0;
}

canonical_decompiled_code:
double func17()
{
if ( Pltdev )
return (*(double *)&Maxx - *(double *)&Minx) / *(double *)&Scale;
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
return 0.0;
}

original_code:
double page_width(void)
{
   if (Pltdev != (0))
      return ((Maxx - Minx) / Scale);
   else {
      fprintf(stderr, "Turtle graphics not initialised\n");
      return (0.0);
   }
}

canonical_original_code:
double page_width()
{
   if (Pltdev != (0))
      return ((Maxx - Minx) / Scale);
   else {
      fprintf(stderr, "Turtle graphics not initialised\n");
      return (0.0);
   }
}

return_type: double


decompiled_code:
double page_height()
{
if ( Pltdev )
return (*(double *)&Maxy - *(double *)&Miny) / *(double *)&Scale;
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
return 0.0;
}

canonical_decompiled_code:
double func18()
{
if ( Pltdev )
return (*(double *)&Maxy - *(double *)&Miny) / *(double *)&Scale;
fwrite("Turtle graphics not initialised\n", 1uLL, 0x20uLL, stderr);
return 0.0;
}

original_code:
double page_height(void)
{
   if (Pltdev != (0))
      return ((Maxy - Miny) / Scale);
   else {
      fprintf(stderr, "Turtle graphics not initialised\n");
      return (0.0);
   }
}

canonical_original_code:
double page_height()
{
   if (Pltdev != (0))
      return ((Maxy - Miny) / Scale);
   else {
      fprintf(stderr, "Turtle graphics not initialised\n");
      return (0.0);
   }
}


decompiled_code:
void sig_handler()
{
keep_running = 0;
}

canonical_decompiled_code:
void func8()
{
keep_running = 0;
}

original_code:
void sig_handler(int signum) {
 keep_running = 0;
}

variable_types: signum int


decompiled_code:
__int64 __fastcall xmit_recv(int fd, void *buf, char a3)
{
int v3; // eax
unsigned int v4; // ebx
__int64 v5; // rdx
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
char bufa[12]; // [rsp+Ch] [rbp-2Ch] BYREF
struct pollfd fds; // [rsp+18h] [rbp-20h] BYREF

bufa[0] = a3;
fprintf(stderr, "TX : %02hhx\n", (unsigned int)a3);
write(fd, bufa, 1uLL);
fds.events = 1;
fds.fd = fd;
v3 = poll(&fds, 1uLL, 1000);
v4 = v3;
if ( v3 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "err poll: %s\n", v8);
}
else if ( v3 )
{
v4 = read(fd, buf, 1uLL);
if ( v4 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(stderr, "read err: %s\n", v10);
}
else
{
v5 = (unsigned int)*(char *)buf;
if ( (*(_BYTE *)buf & 0xF0) == 224 )
{
fprintf(stderr, "recv err: %02hhx\n", v5);
v4 = -3;
}
else
{
fprintf(stderr, "RX : %02hhx\n", v5);
v4 = 0;
}
}
}
else
{
fwrite("timed out...\n", 1uLL, 0xDuLL, stderr);
v4 = -2;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, void *buf, char a3)
{
int v3; // eax
unsigned int v4; // ebx
__int64 v5; // rdx
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
char bufa[12]; // [rsp+Ch] [rbp-2Ch] BYREF
struct pollfd fds; // [rsp+18h] [rbp-20h] BYREF

bufa[0] = a3;
fprintf(stderr, "TX : %02hhx\n", (unsigned int)a3);
write(fd, bufa, 1uLL);
fds.events = 1;
fds.fd = fd;
v3 = poll(&fds, 1uLL, 1000);
v4 = v3;
if ( v3 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
fprintf(stderr, "err poll: %s\n", v8);
}
else if ( v3 )
{
v4 = read(fd, buf, 1uLL);
if ( v4 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
fprintf(stderr, "read err: %s\n", v10);
}
else
{
v5 = (unsigned int)*(char *)buf;
if ( (*(_BYTE *)buf & 0xF0) == 224 )
{
fprintf(stderr, "recv err: %02hhx\n", v5);
v4 = -3;
}
else
{
fprintf(stderr, "RX : %02hhx\n", v5);
v4 = 0;
}
}
}
else
{
fwrite("timed out...\n", 1uLL, 0xDuLL, stderr);
v4 = -2;
}
return v4;
}

original_code:
int xmit_recv(int fd, char* dest, char send){
 fprintf(stderr, "TX : %02hhx\n", send);
 write(fd, &send, 1);
 struct pollfd pfd;
 pfd.events = 0x001;
 pfd.fd = fd;
 int ret = poll(&pfd, 1, 1000);
 if(-1 == ret){
  fprintf(stderr, "err poll: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 if(0 == ret){
  fprintf(stderr, "timed out...\n");
  return -2;
 }
 ret = read(fd, dest, 1);
 if(-1 == ret){
  fprintf(stderr, "read err: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 if((0xe0) == (*dest & 0xF0)){
  fprintf(stderr, "recv err: %02hhx\n", *dest);
  return -3;
 }
 fprintf(stderr, "RX : %02hhx\n", *dest);
 return 0;
}

canonical_original_code:
int xmit_recv(int fd, char *dest, char send){
 fprintf(stderr, "TX : %02hhx\n", send);
 write(fd, &send, 1);
 struct pollfd pfd;
 pfd.events = 0x001;
 pfd.fd = fd;
 int ret = poll(&pfd, 1, 1000);
 if(-1 == ret){
  fprintf(stderr, "err poll: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 if(0 == ret){
  fprintf(stderr, "timed out...\n");
  return -2;
 }
 ret = read(fd, dest, 1);
 if(-1 == ret){
  fprintf(stderr, "read err: %s\n", strerror((*__errno_location ())));
  return -1;
 }
 if((0xe0) == (*dest & 0xF0)){
  fprintf(stderr, "recv err: %02hhx\n", *dest);
  return -3;
 }
 fprintf(stderr, "RX : %02hhx\n", *dest);
 return 0;
}

variable_types: fd int

variable_types:
dest
char *

variable_types: send char

variable_types: struct pollfd { int fd; short events; short revents; }

variable_types: ret int


repo: anayjoshi/naga

decompiled_code:
__int64 render_boundary()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx

if ( screen_height > 1u )
{
v0 = 1;
do
curses_show_char((unsigned __int8)v0++, 0LL, 380LL);
while ( (unsigned __int8)v0 < (unsigned int)screen_height );
if ( screen_height > 1u )
{
v1 = 1;
do
curses_show_char((unsigned __int8)v1++, screen_width, 380LL);
while ( (unsigned __int8)v1 < (unsigned int)screen_height );
}
}
if ( screen_width > 1u )
{
v2 = 1;
do
curses_show_char(0LL, (unsigned __int8)v2++, 301LL);
while ( (unsigned __int8)v2 < (unsigned int)screen_width );
if ( screen_width > 1u )
{
v3 = 1;
do
curses_show_char(screen_height, (unsigned __int8)v3++, 301LL);
while ( (unsigned __int8)v3 < (unsigned int)screen_width );
}
}
curses_show_char(0LL, 0LL, 303LL);
curses_show_char(0LL, screen_width, 348LL);
curses_show_char(screen_height, 0LL, 348LL);
return curses_show_char(screen_height, screen_width, 47LL);
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebx
int v1; // ebx
int v2; // ebx
int v3; // ebx

if ( screen_height > 1u )
{
v0 = 1;
do
curses_show_char((unsigned __int8)v0++, 0LL, 380LL);
while ( (unsigned __int8)v0 < (unsigned int)screen_height );
if ( screen_height > 1u )
{
v1 = 1;
do
curses_show_char((unsigned __int8)v1++, screen_width, 380LL);
while ( (unsigned __int8)v1 < (unsigned int)screen_height );
}
}
if ( screen_width > 1u )
{
v2 = 1;
do
curses_show_char(0LL, (unsigned __int8)v2++, 301LL);
while ( (unsigned __int8)v2 < (unsigned int)screen_width );
if ( screen_width > 1u )
{
v3 = 1;
do
curses_show_char(screen_height, (unsigned __int8)v3++, 301LL);
while ( (unsigned __int8)v3 < (unsigned int)screen_width );
}
}
curses_show_char(0LL, 0LL, 303LL);
curses_show_char(0LL, screen_width, 348LL);
curses_show_char(screen_height, 0LL, 348LL);
return curses_show_char(screen_height, screen_width, 47LL);
}

variable_types:
i
unsigned char


decompiled_code:
__int64 __fastcall render_food(__int16 a1)
{
return curses_show_char(HIBYTE(a1), (unsigned __int8)a1, 1060LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int16 a1)
{
return curses_show_char(HIBYTE(a1), (unsigned __int8)a1, 1060LL);
}

original_code:
static void render_food(struct point food)
{
    curses_show_char(food.y, food.x, '$' | (((chtype)(((4))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))));
}

variable_types: struct point { unsigned char x; unsigned char y; }


decompiled_code:
__int64 __fastcall render_score(unsigned __int16 a1)
{
__int64 v1; // rdx
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
int v6; // [rsp+Ch] [rbp-Ch] BYREF

v6 = 538976288;
itos(a1, &v6);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 11, 339LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 10, 355LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 9, 367LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 8, 370LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 7, 357LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 6, 314LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 5, 288LL);
v1 = (unsigned int)(char)v6;
BYTE1(v1) |= 1u;
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 4, v1);
v2 = (unsigned int)SBYTE1(v6);
BYTE1(v2) |= 1u;
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 3, v2);
v3 = (unsigned int)SBYTE2(v6);
BYTE1(v3) |= 1u;
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 2, v3);
v4 = (unsigned int)SHIBYTE(v6);
BYTE1(v4) |= 1u;
return curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 1, v4);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1)
{
__int64 v1; // rdx
__int64 v2; // rdx
__int64 v3; // rdx
__int64 v4; // rdx
int v6; // [rsp+Ch] [rbp-Ch] BYREF

v6 = 538976288;
itos(a1, &v6);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 11, 339LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 10, 355LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 9, 367LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 8, 370LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 7, 357LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 6, 314LL);
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 5, 288LL);
v1 = (unsigned int)(char)v6;
BYTE1(v1) |= 1u;
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 4, v1);
v2 = (unsigned int)SBYTE1(v6);
BYTE1(v2) |= 1u;
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 3, v2);
v3 = (unsigned int)SBYTE2(v6);
BYTE1(v3) |= 1u;
curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 2, v3);
v4 = (unsigned int)SHIBYTE(v6);
BYTE1(v4) |= 1u;
return curses_show_char((unsigned int)screen_height - 2, (unsigned int)screen_width - 1, v4);
}

variable_types:
score
unsigned short

variable_types:
s
char [4]


decompiled_code:
__int64 render_screen()
{
int v0; // eax
__int16 v1; // dx
__int64 result; // rax

curses_clear_screen();
render_boundary();
render_score(current_score);
render_food(live_food);
render_naga(the_naga, *((unsigned __int8 **)&the_naga + 1));
if ( stdscr )
{
v0 = (unsigned __int16)stdscr->_maxy + 1;
v1 = stdscr->_maxx + 1;
}
else
{
v0 = -1;
v1 = -1;
}
screen_width = v1 - 1;
result = (unsigned int)(v0 - 1);
screen_height = result;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
__int16 v1; // dx
__int64 result; // rax

curses_clear_screen();
func0();
func3(current_score);
func1(live_food);
func2(the_naga, *((unsigned __int8 **)&the_naga + 1));
if ( stdscr )
{
v0 = (unsigned __int16)stdscr->_maxy + 1;
v1 = stdscr->_maxx + 1;
}
else
{
v0 = -1;
v1 = -1;
}
screen_width = v1 - 1;
result = (unsigned int)(v0 - 1);
screen_height = result;
return result;
}

original_code:
void render_screen()
{
    curses_clear_screen();
    render_boundary();
    render_score(current_score);
    render_food(live_food);
    render_naga(the_naga);
    (screen_height = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), screen_width = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
    screen_width = screen_width - 1;
    screen_height = screen_height - 1;
}

canonical_original_code:
void render_screen()
{
    curses_clear_screen();
    render_boundary();
    render_score(current_score);
    render_food(live_food);
    render_naga(the_naga);
    (screen_height = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), screen_width = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
    screen_width = screen_width - 1;
    screen_height = screen_height - 1;
}


repo: anchor/vaultaire-tools

decompiled_code:
__int64 __fastcall get_envvar_int(const char *a1, _DWORD *a2)
{
char *v2; // rax
unsigned int v3; // edx
const char *v4; // rbx
int *v5; // r12
int v6; // eax

v2 = getenv(a1);
v3 = 0;
if ( v2 )
{
v4 = v2;
v5 = __errno_location();
*v5 = 0;
v6 = strtol(v4, 0LL, 10);
*a2 = v6;
if ( *v5 || (v3 = 1, !v6) )
v3 = -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, _DWORD *a2)
{
char *v2; // rax
unsigned int v3; // edx
const char *v4; // rbx
int *v5; // r12
int v6; // eax

v2 = getenv(a1);
v3 = 0;
if ( v2 )
{
v4 = v2;
v5 = __errno_location();
*v5 = 0;
v6 = strtol(v4, 0LL, 10);
*a2 = v6;
if ( *v5 || (v3 = 1, !v6) )
v3 = -1;
}
return v3;
}

original_code:
char get_envvar_int(const char *name, int *v) {
        char *var = getenv(name);
        if (!var) {
                return 0;
        }
        (*__errno_location ()) = 0;
        *v = strtol(var, ((void *)0), 10);
        if ((*__errno_location ()) != 0 || *v == 0) {
                return -1;
        }
        return 1;
}

canonical_original_code:
char get_envvar_int(char *name, int *v) {
        char *var = getenv(name);
        if (!var) {
                return 0;
        }
        (*__errno_location ()) = 0;
        *v = strtol(var, ((void *)0), 10);
        if ((*__errno_location ()) != 0 || *v == 0) {
                return -1;
        }
        return 1;
}

variable_types:
name
char *

variable_types:
v
int *

variable_types:
var
char *

return_type: char


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

if ( !getenv("RADOS_USER") )
{
perror("Must set RADOS_USER");
exit(1);
}
if ( (int)rados_create() < 0 )
{
perror("rados_create");
exit(1);
}
if ( (int)rados_conf_read_file() < 0 )
{
perror("rados_conf_read_file: ");
exit(1);
}
if ( (int)rados_connect() < 0 )
{
perror("rados_connect: ");
exit(1);
}
if ( !getenv("RADOS_POOL") )
{
perror("Must set RADOS_POOL");
exit(1);
}
result = rados_ioctx_create();
if ( (int)result < 0 )
{
perror("rados_ioctx_create: ");
exit(1);
}
return result;
}

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

if ( !getenv("RADOS_USER") )
{
perror("Must set RADOS_USER");
exit(1);
}
if ( (int)rados_create() < 0 )
{
perror("rados_create");
exit(1);
}
if ( (int)rados_conf_read_file() < 0 )
{
perror("rados_conf_read_file: ");
exit(1);
}
if ( (int)rados_connect() < 0 )
{
perror("rados_connect: ");
exit(1);
}
if ( !getenv("RADOS_POOL") )
{
perror("Must set RADOS_POOL");
exit(1);
}
result = rados_ioctx_create();
if ( (int)result < 0 )
{
perror("rados_ioctx_create: ");
exit(1);
}
return result;
}

original_code:
void init_rados(rados_t *cluster, rados_ioctx_t *io) {
        int err;
        char *user = getenv("RADOS_USER");
        do { if ( !user ) { perror( "Must set RADOS_USER" ); exit( 1 ); } } while( 0 );
        err = rados_create(cluster, user);
        do { if ( err < 0 ) { perror( "rados_create" ); exit( 1 ); } } while( 0 );
        err = rados_conf_read_file(*cluster, "/etc/ceph/ceph.conf");
        do { if ( err < 0 ) { perror( "rados_conf_read_file: " ); exit( 1 ); } } while( 0 );
        err = rados_connect(*cluster);
        do { if ( err < 0 ) { perror( "rados_connect: " ); exit( 1 ); } } while( 0 );
        char *pool = getenv("RADOS_POOL");
        do { if ( !pool ) { perror( "Must set RADOS_POOL" ); exit( 1 ); } } while( 0 );
        err = rados_ioctx_create(*cluster, pool, io);
        do { if ( err < 0 ) { perror( "rados_ioctx_create: " ); exit( 1 ); } } while( 0 );
}

canonical_original_code:
void init_rados(void **cluster, void **io) {
        int err;
        char *user = getenv("RADOS_USER");
        do { if ( !user ) { perror( "Must set RADOS_USER" ); exit( 1 ); } } while( 0 );
        err = rados_create(cluster, user);
        do { if ( err < 0 ) { perror( "rados_create" ); exit( 1 ); } } while( 0 );
        err = rados_conf_read_file(*cluster, "/etc/ceph/ceph.conf");
        do { if ( err < 0 ) { perror( "rados_conf_read_file: " ); exit( 1 ); } } while( 0 );
        err = rados_connect(*cluster);
        do { if ( err < 0 ) { perror( "rados_connect: " ); exit( 1 ); } } while( 0 );
        char *pool = getenv("RADOS_POOL");
        do { if ( !pool ) { perror( "Must set RADOS_POOL" ); exit( 1 ); } } while( 0 );
        err = rados_ioctx_create(*cluster, pool, io);
        do { if ( err < 0 ) { perror( "rados_ioctx_create: " ); exit( 1 ); } } while( 0 );
}

variable_types:
cluster
void **

variable_types:
io
void **

variable_types: err int

variable_types:
user
char *

variable_types:
pool
char *


decompiled_code:
void __fastcall init_oids(int a1, char **a2, _DWORD *a3)
{
unsigned int v4; // eax
char **v5; // rbp
int v6; // ebx
time_t v7; // rax

v4 = time(0LL);
srand(v4);
if ( a1 > 0 )
{
v5 = a2;
do
{
v6 = rand();
*v5 = (char *)malloc(0x64uLL);
v7 = time(0LL);
sprintf(*v5, "bench_rados_%lld_%s", v7, &word_list[100 * (v6 % 1000)]);
*a3++ = strlen(*v5++);
}
while ( v5 != &a2[(unsigned int)(a1 - 1) + 1] );
}
}

canonical_decompiled_code:
void __fastcall func9(int a1, char **a2, _DWORD *a3)
{
unsigned int v4; // eax
char **v5; // rbp
int v6; // ebx
time_t v7; // rax

v4 = time(0LL);
srand(v4);
if ( a1 > 0 )
{
v5 = a2;
do
{
v6 = rand();
*v5 = (char *)malloc(0x64uLL);
v7 = time(0LL);
sprintf(*v5, "bench_rados_%lld_%s", v7, &word_list[100 * (v6 % 1000)]);
*a3++ = strlen(*v5++);
}
while ( v5 != &a2[(unsigned int)(a1 - 1) + 1] );
}
}

original_code:
void init_oids(int n, char **oids, int *oid_len) {
        int i;
        srand(time(((void *)0)));
        for (i = 0; i < n; i++) {
                int j = rand() % word_list_size;
                oids[i] = malloc(100);
                sprintf(oids[i], "bench_rados_%lld_%s", (long long)time(((void *)0)), word_list[j]);
                oid_len[i] = strlen(oids[i]);
        }
}

variable_types: n int

variable_types:
oids
char **

variable_types: i int

variable_types: j int


decompiled_code:
void __fastcall cleanup_oids(int a1, void **a2, void *a3)
{
void **v4; // rbx

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

canonical_decompiled_code:
void __fastcall func10(int a1, void **a2, void *a3)
{
void **v4; // rbx

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

original_code:
void cleanup_oids(int n, char **oids, int *oid_len) {
        int i;
        for (i = 0; i < n; i++) {
                free(oids[i]);
        }
        free(oid_len);
        free(oids);
}


decompiled_code:
int __fastcall write_oid(__int64 a1, const char *a2, int a3, __int64 (__fastcall *a4)(__int64, const char *))
{
int result; // eax
int v7; // ebx
__int64 v8; // [rsp+8h] [rbp-30h]

result = puts(a2);
if ( a3 > 0 )
{
v7 = 0;
do
{
if ( (int)rados_aio_create_completion() < 0 )
{
perror("rados_aio_create_completion");
exit(1);
}
rados_aio_append();
result = a4(v8, a2);
++v7;
}
while ( a3 != v7 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, const char *a2, int a3, __int64 (__fastcall *a4)(__int64, const char *))
{
int result; // eax
int v7; // ebx
__int64 v8; // [rsp+8h] [rbp-30h]

result = puts(a2);
if ( a3 > 0 )
{
v7 = 0;
do
{
if ( (int)rados_aio_create_completion() < 0 )
{
perror("rados_aio_create_completion");
exit(1);
}
rados_aio_append();
result = a4(v8, a2);
++v7;
}
while ( a3 != v7 );
}
return result;
}

original_code:
void write_oid(rados_ioctx_t *io, char *oid, int nwrites, int (*wait)(rados_completion_t)) {
        int i;
        int ret;
        printf("%s\n", oid);
        for (i = 0; i < nwrites; i++) {
                rados_completion_t comp;
                ret = rados_aio_create_completion(((void *)0), ((void *)0), ((void *)0), &comp);
                do { if ( ret < 0 ) { perror( "rados_aio_create_completion" ); exit( 1 ); } } while( 0 );
                rados_aio_append(*io, oid, comp, "four", 4);
                (*wait)(comp);
        }
}

canonical_original_code:
void write_oid(void **io, char *oid, int nwrites, int (*wait)(void *)) {
        int i;
        int ret;
        printf("%s\n", oid);
        for (i = 0; i < nwrites; i++) {
                void *comp;
                ret = rados_aio_create_completion(((void *)0), ((void *)0), ((void *)0), &comp);
                do { if ( ret < 0 ) { perror( "rados_aio_create_completion" ); exit( 1 ); } } while( 0 );
                rados_aio_append(*io, oid, comp, "four", 4);
                (*wait)(comp);
        }
}

variable_types:
oid
char *

variable_types: nwrites int

variable_types:
wait
int (*)(void *)

variable_types: ret int

variable_types:
comp
void *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er14
__int64 v5; // rbx
char **v6; // rbp
_DWORD *v7; // r13
time_t v8; // r14
__int64 v9; // rbx
time_t v10; // rax
double v11; // xmm0_8
int v12; // edi
__int64 v13; // rbx
__int64 v15; // [rsp+8h] [rbp-40h] BYREF
__int64 v16; // [rsp+10h] [rbp-38h] BYREF
int v17; // [rsp+18h] [rbp-30h] BYREF
int v18[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

init_rados(&v15, &v16, envp);
if ( (unsigned __int8)get_envvar_int("RADOS_NUM_OIDS", v18) != 1 )
{
perror("Must set RADOS_NUM_OIDS to an integral value");
exit(1);
}
if ( (unsigned __int8)get_envvar_int("RADOS_NUM_WRITES", &v17) != 1 )
{
perror("Must set RADOS_NUM_WRITES to an integral value");
exit(1);
}
v3 = v17 / v18[0];
if ( v17 % v18[0] )
puts("Warning: num_oids is not a factor of num_writes.");
v4 = v18[0];
v5 = v18[0];
v6 = (char **)malloc(8LL * v18[0]);
v7 = malloc(4 * v5);
init_oids(v4, v6, v7);
v8 = time(0LL);
if ( v18[0] > 0 )
{
v9 = 0LL;
do
write_oid((__int64)&v16, v6[v9++], v3, (__int64 (__fastcall *)(__int64, const char *))rados_aio_wait_for_complete);
while ( v18[0] > (int)v9 );
}
v10 = time(0LL);
v11 = difftime(v10, v8);
printf("%f\n", v11);
v12 = v18[0];
if ( v18[0] > 0 )
{
v13 = 0LL;
do
{
rados_remove();
v12 = v18[0];
++v13;
}
while ( v18[0] > (int)v13 );
}
cleanup_oids(v12, (void **)v6, v7);
rados_ioctx_destroy();
rados_shutdown();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er14
__int64 v5; // rbx
char **v6; // rbp
_DWORD *v7; // r13
time_t v8; // r14
__int64 v9; // rbx
time_t v10; // rax
double v11; // xmm0_8
int v12; // edi
__int64 v13; // rbx
__int64 v15; // [rsp+8h] [rbp-40h] BYREF
__int64 v16; // [rsp+10h] [rbp-38h] BYREF
int v17; // [rsp+18h] [rbp-30h] BYREF
int v18[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

func8(&v15, &v16, envp);
if ( (unsigned __int8)func7("RADOS_NUM_OIDS", v18) != 1 )
{
perror("Must set RADOS_NUM_OIDS to an integral value");
exit(1);
}
if ( (unsigned __int8)func7("RADOS_NUM_WRITES", &v17) != 1 )
{
perror("Must set RADOS_NUM_WRITES to an integral value");
exit(1);
}
v3 = v17 / v18[0];
if ( v17 % v18[0] )
puts("Warning: num_oids is not a factor of num_writes.");
v4 = v18[0];
v5 = v18[0];
v6 = (char **)malloc(8LL * v18[0]);
v7 = malloc(4 * v5);
func9(v4, v6, v7);
v8 = time(0LL);
if ( v18[0] > 0 )
{
v9 = 0LL;
do
func11((__int64)&v16, v6[v9++], v3, (__int64 (__fastcall *)(__int64, const char *))rados_aio_wait_for_complete);
while ( v18[0] > (int)v9 );
}
v10 = time(0LL);
v11 = difftime(v10, v8);
printf("%f\n", v11);
v12 = v18[0];
if ( v18[0] > 0 )
{
v13 = 0LL;
do
{
rados_remove();
v12 = v18[0];
++v13;
}
while ( v18[0] > (int)v13 );
}
func10(v12, (void **)v6, v7);
rados_ioctx_destroy();
rados_shutdown();
return 0;
}

original_code:
int main() {
        int ret;
        int num_oids;
        int num_writes;
        int writes_per_oid;
        time_t write_start;
        time_t write_end;
        int i;
        char **oids;
        int *oid_len;
        rados_ioctx_t io;
        rados_t cluster;
        init_rados(&cluster, &io);
        ret = get_envvar_int("RADOS_NUM_OIDS", &num_oids);
        do { if ( ret != 1 ) { perror( "Must set RADOS_NUM_OIDS to an integral value" ); exit( 1 ); } } while( 0 );
        ret = get_envvar_int("RADOS_NUM_WRITES", &num_writes);
        do { if ( ret != 1 ) { perror( "Must set RADOS_NUM_WRITES to an integral value" ); exit( 1 ); } } while( 0 );
        writes_per_oid = num_writes / num_oids;
        if (num_writes % num_oids != 0) {
                printf("Warning: num_oids is not a factor of num_writes.\n");
        }
        oids = malloc(num_oids * sizeof(char*));
        oid_len = malloc(num_oids * sizeof(int));
        init_oids(num_oids, oids, oid_len);
        write_start = time(((void *)0));
        for (i = 0; i < num_oids; i++) {
                write_oid(&io, oids[i], writes_per_oid, rados_aio_wait_for_complete);
        }
        write_end = time(((void *)0));
        printf("%f\n", difftime(write_end, write_start));
        for (i = 0; i < num_oids; i++) {
                rados_remove(io, oids[i]);
        }
        cleanup_oids(num_oids, oids, oid_len);
        rados_ioctx_destroy(io);
        rados_shutdown(cluster);
        return 0;
}

canonical_original_code:
int main() {
        int ret;
        int num_oids;
        int num_writes;
        int writes_per_oid;
        long write_start;
        long write_end;
        int i;
        char **oids;
        int *oid_len;
        void *io;
        void *cluster;
        init_rados(&cluster, &io);
        ret = get_envvar_int("RADOS_NUM_OIDS", &num_oids);
        do { if ( ret != 1 ) { perror( "Must set RADOS_NUM_OIDS to an integral value" ); exit( 1 ); } } while( 0 );
        ret = get_envvar_int("RADOS_NUM_WRITES", &num_writes);
        do { if ( ret != 1 ) { perror( "Must set RADOS_NUM_WRITES to an integral value" ); exit( 1 ); } } while( 0 );
        writes_per_oid = num_writes / num_oids;
        if (num_writes % num_oids != 0) {
                printf("Warning: num_oids is not a factor of num_writes.\n");
        }
        oids = malloc(num_oids * sizeof(char *));
        oid_len = malloc(num_oids * sizeof(int));
        init_oids(num_oids, oids, oid_len);
        write_start = time(((void *)0));
        for (i = 0; i < num_oids; i++) {
                write_oid(&io, oids[i], writes_per_oid, rados_aio_wait_for_complete);
        }
        write_end = time(((void *)0));
        printf("%f\n", difftime(write_end, write_start));
        for (i = 0; i < num_oids; i++) {
                rados_remove(io, oids[i]);
        }
        cleanup_oids(num_oids, oids, oid_len);
        rados_ioctx_destroy(io);
        rados_shutdown(cluster);
        return 0;
}

variable_types:
io
void *

variable_types:
cluster
void *


repo: andi-bigswitch/oflops

original_code:
void
init_data(struct traf_gen_det *det) {
  strcpy(det->src_ip,"10.1.1.1");
  strcpy(det->dst_ip_min,"10.1.1.2");
  strcpy(det->dst_ip_max,"10.1.1.2");
  strcpy(det->mac_src,"00:1e:68:9a:c5:75");
  strcpy(det->mac_dst,"00:15:17:7b:92:0a");
  det->vlan = 0xffff;
  det->vlan_p = 0;
  det->vlan_cfi = 0;
  det->udp_src_port = 8080;
  det->udp_dst_port = 8080;
  det->pkt_size = 1400;
  det->delay = 100*1000;
}

variable_types: struct traf_gen_det { char intf_name[20]; char src_ip[20]; char mac_dst[20]; unsigned short udp_src_port; unsigned int pkt_size; unsigned short vlan; unsigned short vlan_p; unsigned short vlan_cfi; unsigned int delay; } *


decompiled_code:
__int64 __fastcall read_mac_addr(__int64 a1, const char *a2)
{
__int64 i; // rbp
char *v4; // rax
const char *v5; // rbx

for ( i = 0LL; ; ++i )
{
v4 = index(a2, 58);
if ( !v4 )
break;
*v4 = 0;
v5 = v4 + 1;
*(_BYTE *)(a1 + i) = strtol(a2, 0LL, 16);
a2 = v5;
}
*(_BYTE *)(a1 + (int)i) = strtol(a2, 0LL, 16);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
__int64 i; // rbp
char *v4; // rax
const char *v5; // rbx

for ( i = 0LL; ; ++i )
{
v4 = index(a2, 58);
if ( !v4 )
break;
*v4 = 0;
v5 = v4 + 1;
*(_BYTE *)(a1 + i) = strtol(a2, 0LL, 16);
a2 = v5;
}
*(_BYTE *)(a1 + (int)i) = strtol(a2, 0LL, 16);
return 0LL;
}

original_code:
int
read_mac_addr(uint8_t *addr, char *str) {
  char *p = str, *tmp;
  int i = 0;
  do {
    tmp = index(p, ':');
    if(tmp != ((void *)0)) {
      *tmp = '\0';
      tmp++;
    }
    addr[i] = (uint8_t)strtol(p, ((void *)0), 16);
    i++;
    p = tmp;
  } while (p!= ((void *)0));
  return 0;
}

canonical_original_code:
int read_mac_addr(unsigned char *addr, char *str) {
  char *p = str; char *tmp;
  int i = 0;
  do {
    tmp = index(p, ':');
    if(tmp != ((void *)0)) {
      *tmp = '\0';
      tmp++;
    }
    addr[i] = (unsigned char)strtol(p, ((void *)0), 16);
    i++;
    p = tmp;
  } while (p!= ((void *)0));
  return 0;
}

variable_types:
addr
unsigned char *

variable_types:
str
char *

variable_types:
p
char *

variable_types:
tmp
char *


decompiled_code:
__int64 __fastcall ip_sum_calc(unsigned __int16 a1, __int64 a2)
{
unsigned __int16 v4; // r8
int v5; // esi
unsigned int v6; // eax
unsigned int i; // edx

v4 = a1;
if ( a1 )
{
v5 = 0;
v6 = 0;
do
{
v6 += (unsigned __int16)(*(unsigned __int8 *)(a2 + 2LL * (unsigned __int16)v5 + 2)
+ (*(_WORD *)(a2 + 2LL * (unsigned __int16)v5) << 8));
v5 += 2;
}
while ( v4 > (unsigned __int16)v5 );
for ( i = HIWORD(v6); HIWORD(v6); i = HIWORD(v6) )
v6 = i + (unsigned __int16)v6;
}
else
{
v6 = 0;
}
return ~v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int16 a1, __int64 a2)
{
unsigned __int16 v4; // r8
int v5; // esi
unsigned int v6; // eax
unsigned int i; // edx

v4 = a1;
if ( a1 )
{
v5 = 0;
v6 = 0;
do
{
v6 += (unsigned __int16)(*(unsigned __int8 *)(a2 + 2LL * (unsigned __int16)v5 + 2)
+ (*(_WORD *)(a2 + 2LL * (unsigned __int16)v5) << 8));
v5 += 2;
}
while ( v4 > (unsigned __int16)v5 );
for ( i = HIWORD(v6); HIWORD(v6); i = HIWORD(v6) )
v6 = i + (unsigned __int16)v6;
}
else
{
v6 = 0;
}
return ~v6;
}

original_code:
uint16_t ip_sum_calc(uint16_t len_ip_header, uint16_t buff[]) {
  uint16_t word16;
  uint32_t sum=0;
  uint16_t i;
  for (i=0;i<len_ip_header;i=i+2){
    word16 =((buff[i]<<8)&0xFF00)+(buff[i+1]&0xFF);
    sum = sum + (uint32_t) word16;
  }
  while (sum>>16)
    sum = (sum & 0xFFFF)+(sum >> 16);
  sum = ~sum;
  return ((uint16_t) sum);
}

canonical_original_code:
unsigned short ip_sum_calc(unsigned short len_ip_header, unsigned short buff[]) {
  unsigned short word16;
  unsigned int sum = 0;
  unsigned short i;
  for (i=0;i<len_ip_header;i=i+2){
    word16 =((buff[i]<<8)&0xFF00)+(buff[i+1]&0xFF);
    sum = sum + (unsigned int) word16;
  }
  while (sum>>16)
    sum = (sum & 0xFFFF)+(sum >> 16);
  sum = ~sum;
  return ((unsigned short) sum);
}

variable_types:
buff
unsigned short []

variable_types:
sum
unsigned int

variable_types:
i
unsigned short

return_type: unsigned short


original_code:
int
innitialize_generator_packet(struct pkt_details *state, struct traf_gen_det *det) {
  state->data = (void *)malloc(det->pkt_size);
  state->data_len = det->pkt_size;
  bzero((void *)state->data, state->data_len);
  if(state->data_len < sizeof(struct ether_vlan_header) + sizeof(struct iphdr) + sizeof(struct tcphdr)) {
    printf("packet size is too small\n");
    return 0;
  }
  state->eth_vlan = (struct ether_vlan_header *) state->data;
  state->eth = (struct ether_header *) state->data;
  read_mac_addr(state->eth_vlan->ether_dhost, det->mac_dst);
  read_mac_addr(state->eth_vlan->ether_shost, det->mac_src);
  if(det->vlan != 0 && det->vlan != 0xffff) {
    state->eth_vlan->tpid = htons(0x8100);
    state->eth_vlan->vid = htons(det->vlan) >>4;
    state->eth_vlan->ether_type = htons(0x0800);
    state->ip = (struct iphdr *)(state->data + sizeof(struct ether_vlan_header));
    state->ip->tot_len=htons(state->data_len - sizeof(struct ether_vlan_header));
    state->udp = (struct udphdr *)
      (state->data + sizeof(struct ether_vlan_header) + sizeof(struct iphdr));
    state->udp->len = htons(state->data_len - sizeof(struct ether_vlan_header) - sizeof(struct iphdr));
    state->pktgen = (struct pktgen_hdr *)
      (state->data + sizeof(struct ether_vlan_header) + sizeof(struct iphdr) + sizeof(struct udphdr));
  } else {
    state->eth->ether_type = htons(0x0800);
    state->ip = (struct iphdr *)(state->data + sizeof(struct ether_header));
    state->ip->tot_len=htons(state->data_len - sizeof(struct ether_header));
    state->udp = (struct udphdr *)
      (state->data + sizeof(struct ether_header) + sizeof(struct iphdr));
    state->udp->len = htons(state->data_len - sizeof(struct ether_header) - sizeof(struct iphdr));
    state->pktgen = (struct pktgen_hdr *)
      (state->data + sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct udphdr));
  }
  state->ip->protocol=1;
  state->ip->ihl=5;
  state->ip->version=4;
  state->ip->ttl = 100;
  state->ip->protocol = IPPROTO_UDP;
  state->ip->saddr = inet_addr(det->src_ip);
  state->ip->daddr = inet_addr(det->dst_ip_min);
  state->ip->check=ip_sum_calc(20, (uint16_t *) state->ip);
  state->udp->source = htons(det->udp_src_port);
  state->udp->dest = htons(det->udp_dst_port);
  state->pktgen->magic = 0xbe9be955;
  return 1;
}

canonical_original_code:
int innitialize_generator_packet(struct pkt_details *state, struct traf_gen_det *det) {
  state->data = (void *)malloc(det->pkt_size);
  state->data_len = det->pkt_size;
  bzero((void *)state->data, state->data_len);
  if(state->data_len < sizeof(struct ether_vlan_header) + sizeof(struct iphdr) + sizeof(struct tcphdr)) {
    printf("packet size is too small\n");
    return 0;
  }
  state->eth_vlan = (struct ether_vlan_header *) state->data;
  state->eth = (struct ether_header *) state->data;
  read_mac_addr(state->eth_vlan->ether_dhost, det->mac_dst);
  read_mac_addr(state->eth_vlan->ether_shost, det->mac_src);
  if(det->vlan != 0 && det->vlan != 0xffff) {
    state->eth_vlan->tpid = htons(0x8100);
    state->eth_vlan->vid = htons(det->vlan) >>4;
    state->eth_vlan->ether_type = htons(0x0800);
    state->ip = (struct iphdr *)(state->data + sizeof(struct ether_vlan_header));
    state->ip->tot_len=htons(state->data_len - sizeof(struct ether_vlan_header));
    state->udp = (struct udphdr *)
      (state->data + sizeof(struct ether_vlan_header) + sizeof(struct iphdr));
    state->udp->len = htons(state->data_len - sizeof(struct ether_vlan_header) - sizeof(struct iphdr));
    state->pktgen = (struct pktgen_hdr *)
      (state->data + sizeof(struct ether_vlan_header) + sizeof(struct iphdr) + sizeof(struct udphdr));
  } else {
    state->eth->ether_type = htons(0x0800);
    state->ip = (struct iphdr *)(state->data + sizeof(struct ether_header));
    state->ip->tot_len=htons(state->data_len - sizeof(struct ether_header));
    state->udp = (struct udphdr *)
      (state->data + sizeof(struct ether_header) + sizeof(struct iphdr));
    state->udp->len = htons(state->data_len - sizeof(struct ether_header) - sizeof(struct iphdr));
    state->pktgen = (struct pktgen_hdr *)
      (state->data + sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct udphdr));
  }
  state->ip->protocol=1;
  state->ip->ihl=5;
  state->ip->version=4;
  state->ip->ttl = 100;
  state->ip->protocol = IPPROTO_UDP;
  state->ip->saddr = inet_addr(det->src_ip);
  state->ip->daddr = inet_addr(det->dst_ip_min);
  state->ip->check=ip_sum_calc(20, (unsigned short *) state->ip);
  state->udp->source = htons(det->udp_src_port);
  state->udp->dest = htons(det->udp_dst_port);
  state->pktgen->magic = 0xbe9be955;
  return 1;
}

variable_types: struct pkt_details { int traffic_gen; unsigned int seq_num; struct timeval { long tv_sec; long tv_usec; } timestamp; struct ether_header { unsigned char ether_dhost[6]; unsigned char ether_shost[6]; unsigned short ether_type; } *eth; struct ether_vlan_header { unsigned int ether_dhost[6]; unsigned int ether_shost[6]; unsigned int tpid; unsigned char pcp; unsigned char cfi; unsigned short vid; unsigned int ether_type; } *eth_vlan; struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *ip; struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; } *udp; void *data; int data_len; struct pktgen_hdr { unsigned int magic; unsigned int seq_num; unsigned int tv_sec; unsigned int tv_usec; struct timeval time; } *pktgen; } *

user_defined_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; }

user_defined_types: struct pkt_details { int traffic_gen; unsigned int seq_num; struct timeval timestamp; struct ether_header *eth; struct ether_vlan_header *eth_vlan; struct iphdr *ip; struct udphdr *udp; void *data; int data_len; struct pktgen_hdr *pktgen; }

user_defined_types: struct traf_gen_det { char intf_name[20]; char src_ip[20]; char mac_dst[20]; unsigned short udp_src_port; unsigned int pkt_size; unsigned short vlan; unsigned short vlan_p; unsigned short vlan_cfi; unsigned int delay; }