decompiled_code:
__int64 __fastcall draw_quad(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
draw_curve(a1, a2, a3, a4, a5, a6);
draw_curve(a3, a4, a5, a6, a7, a8);
draw_curve(a5, a6, a7, a8, a1, a2);
return draw_curve(a7, a8, a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
func1(a1, a2, a3, a4, a5, a6);
func1(a3, a4, a5, a6, a7, a8);
func1(a5, a6, a7, a8, a1, a2);
return func1(a7, a8, a1, a2, a3, a4);
}

original_code:
void draw_quad(const double x1, const double y1, const double x2, const double y2,
               const double x3, const double y3, const double x4, const double y4)
{
   draw_curve(x1, y1, x2, y2, x3, y3);
   draw_curve(x2, y2, x3, y3, x4, y4);
   draw_curve(x3, y3, x4, y4, x1, y1);
   draw_curve(x4, y4, x1, y1, x2, y2);
}

canonical_original_code:
void draw_quad(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
   draw_curve(x1, y1, x2, y2, x3, y3);
   draw_curve(x2, y2, x3, y3, x4, y4);
   draw_curve(x3, y3, x4, y4, x1, y1);
   draw_curve(x4, y4, x1, y1, x2, y2);
}


lineTest

repo: anachrocomputer/vec

original_code:
void lineTest(const double xc, const double yc, const double wd, const double ht, const PlotInfo_t *const info)
{
   const double len = wd / 16.0;
   double hside = wd * 0.8;
   double vside = ht * 0.8;
   moveto(xc - len, yc);
   lineto(xc + len, yc);
   moveto(xc, yc - len);
   lineto(xc, yc + len);
   rectangle(xc - hside, yc - vside, xc + hside, yc + vside);
   hside = wd * 0.7;
   vside = ht * 0.7;
   roundrect(xc - hside, yc - vside, xc + hside, yc + vside, wd / 8);
   hlabel(xc - (wd / 2.0), yc - (ht / 2.0), 5.0, info->plotterName);
   hlabel(xc + (wd / 2.0), yc - (ht / 2.0), 5.0, info->paperName);
}

canonical_original_code:
void lineTest(double xc, double yc, double wd, double ht, struct PlotInfo *info)
{
   double len = wd / 16.0;
   double hside = wd * 0.8;
   double vside = ht * 0.8;
   moveto(xc - len, yc);
   lineto(xc + len, yc);
   moveto(xc, yc - len);
   lineto(xc, yc + len);
   rectangle(xc - hside, yc - vside, xc + hside, yc + vside);
   hside = wd * 0.7;
   vside = ht * 0.7;
   roundrect(xc - hside, yc - vside, xc + hside, yc + vside, wd / 8);
   hlabel(xc - (wd / 2.0), yc - (ht / 2.0), 5.0, info->plotterName);
   hlabel(xc + (wd / 2.0), yc - (ht / 2.0), 5.0, info->paperName);
}

variable_types: xc double

variable_types: yc double

variable_types: wd double

variable_types: ht double

variable_types: struct PlotInfo { int versionMajor; int versionMinor; char *plotterName; char *paperName; char *portName; char *plotTitle; char *paperCapacityISO; char *paperCapacityANSI; int plotterInterface; int plotterLanguage; int paperSize; int orientation; int nPenStalls; int nPens; double unitsPermm; double unitsPerInch; double widthInmm; double heightInmm; double widthInInches; double heightInInches; double widthInUnits; double heightInUnits; } *

variable_types: len double

variable_types: hside double

variable_types: vside double

return_type: void


circleTest

original_code:
void circleTest(const double xc, const double yc, const double wd, const double ht, const PlotInfo_t *const info)
{
   const double major = wd / 2.0;
   const double minor = ht / 2.0;
   circle(xc, yc, minor);
   ellipse(xc, yc, major, minor, 0.0);
   ellipse(xc, yc, major, minor, (3.14159265358979323846 / 4.0));
   ellipse(xc, yc, major, minor, (3.14159265358979323846 / 2.0));
   circle(xc, yc, major);
}

canonical_original_code:
void circleTest(double xc, double yc, double wd, double ht, struct PlotInfo *info)
{
   double major = wd / 2.0;
   double minor = ht / 2.0;
   circle(xc, yc, minor);
   ellipse(xc, yc, major, minor, 0.0);
   ellipse(xc, yc, major, minor, (3.14159265358979323846 / 4.0));
   ellipse(xc, yc, major, minor, (3.14159265358979323846 / 2.0));
   circle(xc, yc, major);
}

variable_types: major double

variable_types: minor double

user_defined_types: struct PlotInfo { int versionMajor; int versionMinor; char *plotterName; char *paperName; char *portName; char *plotTitle; char *paperCapacityISO; char *paperCapacityANSI; int plotterInterface; int plotterLanguage; int paperSize; int orientation; int nPenStalls; int nPens; double unitsPermm; double unitsPerInch; double widthInmm; double heightInmm; double widthInInches; double heightInInches; double widthInUnits; double heightInUnits; }


arcTest

decompiled_code:
__int64 __fastcall arcTest(double a1, double a2, double a3)
{
double v3; // r14
int i; // ebx
__int64 result; // rax

v3 = a1 - a3 * 0.5;
moveto(v3);
lineto(a3 * 0.5 + a1, a2);
moveto(a3 * 0.5 + a1);
lineto(v3, a3 * 0.5 + a2);
moveto(a1);
lineto(a1, a2 - a3 * 0.5);
moveto(v3);
lineto(a3 * 0.5 + a1, a3 * 0.5 + a2);
for ( i = 0; i != 7; result = arc(a1, a2, 45.0 * (double)i) )
moveto(a1 - a3 * 0.0625 * (double)++i);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, double a2, double a3)
{
double v3; // r14
int i; // ebx
__int64 result; // rax

v3 = a1 - a3 * 0.5;
moveto(v3);
lineto(a3 * 0.5 + a1, a2);
moveto(a3 * 0.5 + a1);
lineto(v3, a3 * 0.5 + a2);
moveto(a1);
lineto(a1, a2 - a3 * 0.5);
moveto(v3);
lineto(a3 * 0.5 + a1, a3 * 0.5 + a2);
for ( i = 0; i != 7; result = arc(a1, a2, 45.0 * (double)i) )
moveto(a1 - a3 * 0.0625 * (double)++i);
return result;
}

original_code:
void arcTest(const double xc, const double yc, const double wd, const double ht, const PlotInfo_t *const info)
{
   double radius = wd / 2.0;
   const double delta = 3.14159265358979323846 / 4.0;
   double angle;
   int i;
   moveto(xc - radius, yc);
   lineto(xc + radius, yc);
   moveto(xc + radius, yc - radius);
   lineto(xc - radius, yc + radius);
   moveto(xc, yc + radius);
   lineto(xc, yc - radius);
   moveto(xc - radius, yc - radius);
   lineto(xc + radius, yc + radius);
   for (i = 0; i < 7; i++) {
      radius = (wd / 16.0) * (i + 1);
      angle = 45.0 * (i + 1);
      moveto(xc - radius, yc);
      arc(xc, yc, angle);
   }
}

canonical_original_code:
void arcTest(double xc, double yc, double wd, double ht, struct PlotInfo *info)
{
   double radius = wd / 2.0;
   double delta = 3.14159265358979323846 / 4.0;
   double angle;
   int i;
   moveto(xc - radius, yc);
   lineto(xc + radius, yc);
   moveto(xc + radius, yc - radius);
   lineto(xc - radius, yc + radius);
   moveto(xc, yc + radius);
   lineto(xc, yc - radius);
   moveto(xc - radius, yc - radius);
   lineto(xc + radius, yc + radius);
   for (i = 0; i < 7; i++) {
      radius = (wd / 16.0) * (i + 1);
      angle = 45.0 * (i + 1);
      moveto(xc - radius, yc);
      arc(xc, yc, angle);
   }
}

variable_types: radius double

variable_types: delta double

variable_types: angle double

variable_types: i int


textTest

decompiled_code:
__int64 __fastcall textTest(double a1, double a2, double a3)
{
moveto(a1 - a3 * 0.0625);
lineto(a3 * 0.0625 + a1, a2);
moveto(a1);
lineto(a1, a3 * 0.0625 + a2);
return hlabel("ABCDEF", a1, a2, 10.0);
}

canonical_decompiled_code:
__int64 __fastcall func3(double a1, double a2, double a3)
{
moveto(a1 - a3 * 0.0625);
lineto(a3 * 0.0625 + a1, a2);
moveto(a1);
lineto(a1, a3 * 0.0625 + a2);
return hlabel("ABCDEF", a1, a2, 10.0);
}

original_code:
void textTest(const double xc, const double yc, const double wd, const double ht, const PlotInfo_t *const info)
{
   const double len = wd / 16.0;
   moveto(xc - len, yc);
   lineto(xc + len, yc);
   moveto(xc, yc - len);
   lineto(xc, yc + len);
   hlabel(xc, yc, 10.0, "ABCDEF");
}

canonical_original_code:
void textTest(double xc, double yc, double wd, double ht, struct PlotInfo *info)
{
   double len = wd / 16.0;
   moveto(xc - len, yc);
   lineto(xc + len, yc);
   moveto(xc, yc - len);
   lineto(xc, yc + len);
   hlabel(xc, yc, 10.0, "ABCDEF");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
double v4; // rbp
double v5; // rbx
double v7; // [rsp+0h] [rbp-C8h]
double v8; // [rsp+8h] [rbp-C0h]
char v9[144]; // [rsp+10h] [rbp-B8h] BYREF
double v10; // [rsp+A0h] [rbp-28h] BYREF
double v11[4]; // [rsp+A8h] [rbp-20h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "no:p:q:s:t:v:");
if ( v3 == -1 )
break;
if ( v3 - 110 > 8 || ((1LL << ((unsigned __int8)v3 - 110)) & 0x16F) == 0 )
{
fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-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);
}
if ( (int)getplotinfo(v9, 144LL) < 0 )
{
fwrite("Failed to get plot information\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
getplotsize(v11, &v10);
v4 = v11[0] * 0.5;
v5 = 0.5 * v10;
v7 = v11[0] * 0.25;
v8 = v10 * 0.25;
writedisplay("LIBTEST");
moveto(0.0);
lineto(v11[0], v5);
moveto(v4);
lineto(v4, v10);
lineTest((__int64)v9, v7, v5 + v8, v7, v8);
circleTest(v7, v8, v7, v8);
arcTest(v4 + v7, v5 + v8, v7);
textTest(v4 + v7, v8, v7);
plotend(v9);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
double v4; // rbp
double v5; // rbx
double v7; // [rsp+0h] [rbp-C8h]
double v8; // [rsp+8h] [rbp-C0h]
char v9[144]; // [rsp+10h] [rbp-B8h] BYREF
double v10; // [rsp+A0h] [rbp-28h] BYREF
double v11[4]; // [rsp+A8h] [rbp-20h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "no:p:q:s:t:v:");
if ( v3 == -1 )
break;
if ( v3 - 110 > 8 || ((1LL << ((unsigned __int8)v3 - 110)) & 0x16F) == 0 )
{
fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-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);
}
if ( (int)getplotinfo(v9, 144LL) < 0 )
{
fwrite("Failed to get plot information\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
getplotsize(v11, &v10);
v4 = v11[0] * 0.5;
v5 = 0.5 * v10;
v7 = v11[0] * 0.25;
v8 = v10 * 0.25;
writedisplay("LIBTEST");
moveto(0.0);
lineto(v11[0], v5);
moveto(v4);
lineto(v4, v10);
func0((__int64)v9, v7, v5 + v8, v7, v8);
func1(v7, v8, v7, v8);
func2(v4 + v7, v5 + v8, v7);
func3(v4 + v7, v8, v7);
plotend(v9);
return 0;
}

original_code:
int main(int argc, char * const argv[])
{
   int opt;
   double xc, yc;
   double h4, w4;
   double maxx, maxy;
   PlotInfo_t info;
   while ((opt = getopt(argc, argv, "no:p:q:s:t:v:")) != -1) {
      switch (opt) {
      case 's':
      case 'n':
      case 'o':
      case 'p':
      case 'q':
      case 't':
      case 'v':
         plotopt(opt, optarg);
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-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);
   }
   if (getplotinfo(&info, sizeof (info)) < 0) {
      fputs("Failed to get plot information\n", stderr);
      exit(1);
   }
   getplotsize(&maxx, &maxy);
   xc = maxx / 2.0;
   yc = maxy / 2.0;
   w4 = maxx / 4.0;
   h4 = maxy / 4.0;
   writedisplay("LIBTEST");
   moveto(0.0, yc);
   lineto(maxx, yc);
   moveto(xc, 0.0);
   lineto(xc, maxy);
   lineTest(w4, yc + h4, w4, h4, &info);
   circleTest(w4, h4, w4, h4, &info);
   arcTest(xc + w4, yc + h4, w4, h4, &info);
   textTest(xc + w4, h4, w4, h4, &info);
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   double xc; double yc;
   double h4; double w4;
   double maxx; double maxy;
   struct PlotInfo info;
   while ((opt = getopt(argc, argv, "no:p:q:s:t:v:")) != -1) {
      switch (opt) {
      case 's':
      case 'n':
      case 'o':
      case 'p':
      case 'q':
      case 't':
      case 'v':
         plotopt(opt, optarg);
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-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);
   }
   if (getplotinfo(&info, sizeof (info)) < 0) {
      fputs("Failed to get plot information\n", stderr);
      exit(1);
   }
   getplotsize(&maxx, &maxy);
   xc = maxx / 2.0;
   yc = maxy / 2.0;
   w4 = maxx / 4.0;
   h4 = maxy / 4.0;
   writedisplay("LIBTEST");
   moveto(0.0, yc);
   lineto(maxx, yc);
   moveto(xc, 0.0);
   lineto(xc, maxy);
   lineTest(w4, yc + h4, w4, h4, &info);
   circleTest(w4, h4, w4, h4, &info);
   arcTest(xc + w4, yc + h4, w4, h4, &info);
   textTest(xc + w4, h4, w4, h4, &info);
   plotend();
   return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: maxx double

variable_types: maxy double

variable_types: struct PlotInfo { int versionMajor; int versionMinor; char *plotterName; char *paperName; char *portName; char *plotTitle; char *paperCapacityISO; char *paperCapacityANSI; int plotterInterface; int plotterLanguage; int paperSize; int orientation; int nPenStalls; int nPens; double unitsPermm; double unitsPerInch; double widthInmm; double heightInmm; double widthInInches; double heightInInches; double widthInUnits; double heightInUnits; }

return_type: int


drawx

decompiled_code:
__int64 __fastcall drawx(int a1, int a2, double a3, double a4, double a5, double a6)
{
int v6; // er13
double v7; // r15
__int64 result; // rax
int i; // ebx
double v10; // [rsp+0h] [rbp-68h]
double v11; // [rsp+8h] [rbp-60h]

v11 = a3 + a3 - (a4 + a4);
if ( a2 > 0 )
{
v6 = 0;
do
{
v7 = (double)++v6 * v11;
result = moveto(a5, v7);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v10 = (double)i * v11 + a5;
arc(a3 + v10, v7, a6);
result = arc(v10 + a3 + a3 - a4, v7, a6);
}
}
}
while ( v6 != a2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, double a3, double a4, double a5, double a6)
{
int v6; // er13
double v7; // r15
__int64 result; // rax
int i; // ebx
double v10; // [rsp+0h] [rbp-68h]
double v11; // [rsp+8h] [rbp-60h]

v11 = a3 + a3 - (a4 + a4);
if ( a2 > 0 )
{
v6 = 0;
do
{
v7 = (double)++v6 * v11;
result = moveto(a5, v7);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
v10 = (double)i * v11 + a5;
arc(a3 + v10, v7, a6);
result = arc(v10 + a3 + a3 - a4, v7, a6);
}
}
}
while ( v6 != a2 );
}
return result;
}

original_code:
void drawx(const int nx, const int ny, const double r1, const double r2, const double offset, const double angle)
{
   int ix, iy;
   double x1, x2;
   double y;
   const double d1 = r1 * 2.0;
   const double pitch = (r1 * 2.0) - (r2 * 2.0);
   for (iy = 0; iy < ny; iy++) {
      x1 = offset;
      y = (double)(iy + 1) * pitch;
      moveto(x1, y);
      for (ix = 0; ix < nx; ix++) {
         x1 = ((double)ix * pitch) + offset;
         x2 = x1 + r1;
         arc(x2, y, angle);
         x2 = x1 + d1 - r2;
         arc(x2, y, angle);
      }
   }
}

canonical_original_code:
void drawx(int nx, int ny, double r1, double r2, double offset, double angle)
{
   int ix; int iy;
   double x1; double x2;
   double y;
   double d1 = r1 * 2.0;
   double pitch = (r1 * 2.0) - (r2 * 2.0);
   for (iy = 0; iy < ny; iy++) {
      x1 = offset;
      y = (double)(iy + 1) * pitch;
      moveto(x1, y);
      for (ix = 0; ix < nx; ix++) {
         x1 = ((double)ix * pitch) + offset;
         x2 = x1 + r1;
         arc(x2, y, angle);
         x2 = x1 + d1 - r2;
         arc(x2, y, angle);
      }
   }
}

variable_types: nx int

variable_types: ny int

variable_types: offset double

variable_types: ix int

variable_types: iy int

variable_types: y double

variable_types: pitch double


drawy

decompiled_code:
__int64 __fastcall drawy(int a1, int a2, double a3, double a4, double a5, double a6)
{
int v6; // er13
double v7; // r15
__int64 result; // rax
int i; // ebx
double v10; // [rsp+0h] [rbp-68h]
double v11; // [rsp+8h] [rbp-60h]

v11 = a3 + a3 - (a4 + a4);
if ( a1 > 0 )
{
v6 = 0;
do
{
v7 = (double)++v6 * v11;
result = moveto(v7, a5);
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
v10 = (double)i * v11 + a5;
arc(v7, a3 + v10, a6);
result = arc(v7, v10 + a3 + a3 - a4, a6);
}
}
}
while ( v6 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, double a3, double a4, double a5, double a6)
{
int v6; // er13
double v7; // r15
__int64 result; // rax
int i; // ebx
double v10; // [rsp+0h] [rbp-68h]
double v11; // [rsp+8h] [rbp-60h]

v11 = a3 + a3 - (a4 + a4);
if ( a1 > 0 )
{
v6 = 0;
do
{
v7 = (double)++v6 * v11;
result = moveto(v7, a5);
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
v10 = (double)i * v11 + a5;
arc(v7, a3 + v10, a6);
result = arc(v7, v10 + a3 + a3 - a4, a6);
}
}
}
while ( v6 != a1 );
}
return result;
}

original_code:
void drawy(const int nx, const int ny, const double r1, const double r2, const double offset, const double angle)
{
   int ix, iy;
   double x;
   double y1, y2;
   const double d1 = r1 * 2.0;
   const double pitch = (r1 * 2.0) - (r2 * 2.0);
   for (ix = 0; ix < nx; ix++) {
      x = (double)(ix + 1) * pitch;
      y1 = offset;
      moveto(x, y1);
      for (iy = 0; iy < ny; iy++) {
         y1 = ((double)iy * pitch) + offset;
         y2 = y1 + r1;
         arc(x, y2, angle);
         y2 = y1 + d1 - r2;
         arc(x, y2, angle);
      }
   }
}

canonical_original_code:
void drawy(int nx, int ny, double r1, double r2, double offset, double angle)
{
   int ix; int iy;
   double x;
   double y1; double y2;
   double d1 = r1 * 2.0;
   double pitch = (r1 * 2.0) - (r2 * 2.0);
   for (ix = 0; ix < nx; ix++) {
      x = (double)(ix + 1) * pitch;
      y1 = offset;
      moveto(x, y1);
      for (iy = 0; iy < ny; iy++) {
         y1 = ((double)iy * pitch) + offset;
         y2 = y1 + r1;
         arc(x, y2, angle);
         y2 = y1 + d1 - r2;
         arc(x, y2, angle);
      }
   }
}

variable_types: x double


main

original_code:
int main(int argc, char * const argv[])
{
   int opt;
   int nx, ny;
   double scale;
   double r1, r2;
   double d2;
   double maxx, maxy;
   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);
      }
   }
   nx = 8;
   ny = 5;
   scale = 40.0;
   r1 = 30.0 * scale;
   r2 = 7.5 * scale;
   d2 = 2.0 * r2;
   plotbegin(1);
   getplotsize(&maxx, &maxy);
   drawx(nx, ny, r1, r2, 0.0, 180.0);
   drawx(nx, ny, r1, r2, -d2, -180.0);
   drawy(nx, ny, r1, r2, -d2, -180.0);
   drawy(nx, ny, r1, r2, 0.0, 180.0);
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   int nx; int ny;
   double scale;
   double r1; double r2;
   double d2;
   double maxx; double maxy;
   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);
      }
   }
   nx = 8;
   ny = 5;
   scale = 40.0;
   r1 = 30.0 * scale;
   r2 = 7.5 * scale;
   d2 = 2.0 * r2;
   plotbegin(1);
   getplotsize(&maxx, &maxy);
   drawx(nx, ny, r1, r2, 0.0, 180.0);
   drawx(nx, ny, r1, r2, -d2, -180.0);
   drawy(nx, ny, r1, r2, -d2, -180.0);
   drawy(nx, ny, r1, r2, 0.0, 180.0);
   plotend();
   return (0);
}

variable_types: scale double


original_code:
void postcard_port(const double x, const double y, const double wd, const double ht, const double maxx, const double maxy)
{
   int i;
   _Bool right = 1;
   _Bool bottom = 1;
   double yc = y + (ht / 2.0);
   double x1 = x + (wd / 16.0);
   double x2 = x + wd - (wd / 16.0);
   double sx2 = x + wd - (5.0 * 40.0);
   double sy2 = y + (5.0 * 40.0);
   double sx1 = sx2 - (22.0 * 40.0);
   double sy1 = sy2 + (19.0 * 40.0);
   double ax = sx1 - (12.0 * 40.0);
   double ay1 = yc - (5.0 * 40.0);
   double ay2 = y + (5.0 * 40.0);
   if (x1 < 0.0)
      x1 = 0.0;
   if (x2 > maxx)
      x2 = maxx;
   if (sx2 > maxx) {
      sx2 = maxx;
      right = 0;
   }
   if (sy2 > maxy)
      sy2 = maxy;
   if (sy2 < 0.0) {
      sy2 = 0.0;
      bottom = 0;
   }
   if (ay2 < 0.0)
      ay2 = 0.0;
   moveto(x1, yc);
   lineto(x2, yc);
   moveto(sx1, sy1);
   lineto(sx1, sy2);
   if (bottom)
      lineto(sx2, sy2);
   else
      moveto(sx2, sy2);
   if (right)
      lineto(sx2, sy1);
   else
      moveto(sx2, sy1);
   lineto(sx1, sy1);
   for (i = 0; i < 5; i++) {
      moveto(ax - (12.0 * 40.0) * (double)i, ay1);
      lineto(ax - (12.0 * 40.0) * (double)i, ay2);
   }
}

canonical_original_code:
void postcard_port(double x, double y, double wd, double ht, double maxx, double maxy)
{
   int i;
   _Bool right = 1;
   _Bool bottom = 1;
   double yc = y + (ht / 2.0);
   double x1 = x + (wd / 16.0);
   double x2 = x + wd - (wd / 16.0);
   double sx2 = x + wd - (5.0 * 40.0);
   double sy2 = y + (5.0 * 40.0);
   double sx1 = sx2 - (22.0 * 40.0);
   double sy1 = sy2 + (19.0 * 40.0);
   double ax = sx1 - (12.0 * 40.0);
   double ay1 = yc - (5.0 * 40.0);
   double ay2 = y + (5.0 * 40.0);
   if (x1 < 0.0)
      x1 = 0.0;
   if (x2 > maxx)
      x2 = maxx;
   if (sx2 > maxx) {
      sx2 = maxx;
      right = 0;
   }
   if (sy2 > maxy)
      sy2 = maxy;
   if (sy2 < 0.0) {
      sy2 = 0.0;
      bottom = 0;
   }
   if (ay2 < 0.0)
      ay2 = 0.0;
   moveto(x1, yc);
   lineto(x2, yc);
   moveto(sx1, sy1);
   lineto(sx1, sy2);
   if (bottom)
      lineto(sx2, sy2);
   else
      moveto(sx2, sy2);
   if (right)
      lineto(sx2, sy1);
   else
      moveto(sx2, sy1);
   lineto(sx1, sy1);
   for (i = 0; i < 5; i++) {
      moveto(ax - (12.0 * 40.0) * (double)i, ay1);
      lineto(ax - (12.0 * 40.0) * (double)i, ay2);
   }
}

variable_types: wd double

variable_types: ht double

variable_types: yc double

variable_types: ax double


decompiled_code:
void postcard_land()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void postcard_land(const double x, const double y, const double wd, const double ht, const double maxx, const double maxy)
{
}

canonical_original_code:
void postcard_land(double x, double y, double wd, double ht, double maxx, double maxy)
{
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // bp
int v5; // er14
__int64 v6; // r15
int v7; // eax
double v8; // r12
double v9; // xmm5_8
int i; // er15
double v11; // r13
double v12; // r13
int v13; // er15
int v14; // er13
__int64 v16; // [rsp+0h] [rbp-F8h]
double v17; // [rsp+0h] [rbp-F8h]
double v18; // [rsp+8h] [rbp-F0h]
double v19; // [rsp+18h] [rbp-E0h]
double v20; // [rsp+20h] [rbp-D8h]
double v21; // [rsp+28h] [rbp-D0h]
char v22[64]; // [rsp+30h] [rbp-C8h] BYREF
int v23; // [rsp+70h] [rbp-88h]
double v24; // [rsp+80h] [rbp-78h]
double v25; // [rsp+90h] [rbp-68h]
double v26; // [rsp+98h] [rbp-60h]
double v27; // [rsp+B0h] [rbp-48h]
double v28; // [rsp+B8h] [rbp-40h]

while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "no:p:q:s:t:v:");
if ( v7 == -1 )
break;
if ( v7 != 116 )
{
if ( v7 > 116 )
{
if ( v7 != 118 )
{
LABEL_9:
fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-s <size>] [-t title]\n", *argv);
fwrite(" <size> ::= A1 | A2 | A3 | A4 | A5 | A6\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
}
else if ( v7 > 113 )
{
if ( v7 != 115 )
goto LABEL_9;
}
else if ( v7 <= 109 )
{
goto LABEL_9;
}
plotopt((unsigned int)v7, optarg);
}
}
if ( (int)plotbegin(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
if ( (int)getplotinfo(v22, 144LL) < 0 )
{
fwrite("Failed to get plot information\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
v19 = v27;
v8 = v28;
if ( v23 == 5 )
{
v16 = LC9;
v6 = LC7;
v3 = 1;
v5 = 2;
v4 = 1;
}
else if ( v23 > 5 )
{
if ( v23 == 6 )
{
v16 = LC11;
v6 = LC12;
v3 = 1;
v5 = 1;
v4 = 0;
}
}
else if ( v23 == 3 )
{
v16 = LC8;
v6 = LC10;
v3 = 2;
v5 = 4;
v4 = 1;
}
else if ( v23 == 4 )
{
v16 = LC7;
v6 = LC8;
v3 = 2;
v5 = 2;
v4 = 0;
}
v18 = (*(double *)&v6 - v25) * 0.5;
v9 = *(double *)&v16;
v20 = (*(double *)&v16 - v26) * 0.5;
v17 = *(double *)&v6 * v24 / (double)v5;
v21 = v24 * v9 / (double)v3;
if ( v5 > 1 )
{
for ( i = 1; i != v5; ++i )
{
v11 = (double)i * v17 - v18 * v24;
moveto(v11, 0.0);
lineto(v11, v8);
}
}
if ( v3 > 1 )
{
v12 = v21 - v20 * v24;
moveto(0.0, v12);
lineto(v19, v12);
}
v13 = 0;
do
{
v14 = 0;
do
{
if ( v4 )
postcard_port((double)v13 * v17 - v24 * v18, (double)v14 * v21 - v20 * v24, v17, v21, v19, v8);
++v14;
}
while ( v3 != v14 );
++v13;
}
while ( v5 != v13 );
plotend();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
char v4; // bp
int v5; // er14
__int64 v6; // r15
int v7; // eax
double v8; // r12
double v9; // xmm5_8
int i; // er15
double v11; // r13
double v12; // r13
int v13; // er15
int v14; // er13
__int64 v16; // [rsp+0h] [rbp-F8h]
double v17; // [rsp+0h] [rbp-F8h]
double v18; // [rsp+8h] [rbp-F0h]
double v19; // [rsp+18h] [rbp-E0h]
double v20; // [rsp+20h] [rbp-D8h]
double v21; // [rsp+28h] [rbp-D0h]
char v22[64]; // [rsp+30h] [rbp-C8h] BYREF
int v23; // [rsp+70h] [rbp-88h]
double v24; // [rsp+80h] [rbp-78h]
double v25; // [rsp+90h] [rbp-68h]
double v26; // [rsp+98h] [rbp-60h]
double v27; // [rsp+B0h] [rbp-48h]
double v28; // [rsp+B8h] [rbp-40h]

while ( 1 )
{
v7 = getopt(argc, (char *const *)argv, "no:p:q:s:t:v:");
if ( v7 == -1 )
break;
if ( v7 != 116 )
{
if ( v7 > 116 )
{
if ( v7 != 118 )
{
LABEL_9:
fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-s <size>] [-t title]\n", *argv);
fwrite(" <size> ::= A1 | A2 | A3 | A4 | A5 | A6\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
}
else if ( v7 > 113 )
{
if ( v7 != 115 )
goto LABEL_9;
}
else if ( v7 <= 109 )
{
goto LABEL_9;
}
plotopt((unsigned int)v7, optarg);
}
}
if ( (int)plotbegin(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
if ( (int)getplotinfo(v22, 144LL) < 0 )
{
fwrite("Failed to get plot information\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
v19 = v27;
v8 = v28;
if ( v23 == 5 )
{
v16 = LC9;
v6 = LC7;
v3 = 1;
v5 = 2;
v4 = 1;
}
else if ( v23 > 5 )
{
if ( v23 == 6 )
{
v16 = LC11;
v6 = LC12;
v3 = 1;
v5 = 1;
v4 = 0;
}
}
else if ( v23 == 3 )
{
v16 = LC8;
v6 = LC10;
v3 = 2;
v5 = 4;
v4 = 1;
}
else if ( v23 == 4 )
{
v16 = LC7;
v6 = LC8;
v3 = 2;
v5 = 2;
v4 = 0;
}
v18 = (*(double *)&v6 - v25) * 0.5;
v9 = *(double *)&v16;
v20 = (*(double *)&v16 - v26) * 0.5;
v17 = *(double *)&v6 * v24 / (double)v5;
v21 = v24 * v9 / (double)v3;
if ( v5 > 1 )
{
for ( i = 1; i != v5; ++i )
{
v11 = (double)i * v17 - v18 * v24;
moveto(v11, 0.0);
lineto(v11, v8);
}
}
if ( v3 > 1 )
{
v12 = v21 - v20 * v24;
moveto(0.0, v12);
lineto(v19, v12);
}
v13 = 0;
do
{
v14 = 0;
do
{
if ( v4 )
func0((double)v13 * v17 - v24 * v18, (double)v14 * v21 - v20 * v24, v17, v21, v19, v8);
++v14;
}
while ( v3 != v14 );
++v13;
}
while ( v5 != v13 );
plotend();
return 0;
}

original_code:
int main(int argc, char * const argv[])
{
   int opt;
   int i, j;
   _Bool portrait;
   double x, y;
   double dx, dy;
   int nx, ny;
   double maxx, maxy;
   double trueWidthmm;
   double trueHeightmm;
   double borderx;
   double bordery;
   PlotInfo_t info;
   while ((opt = getopt(argc, argv, "no:p:q:s:t:v:")) != -1) {
      switch (opt) {
      case 's':
      case 'n':
      case 'o':
      case 'p':
      case 'q':
      case 'v':
         plotopt(opt, optarg);
         break;
      case 't':
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-s <size>] [-t title]\n", argv[0]);
         fprintf(stderr, "       <size> ::= A1 | A2 | A3 | A4 | A5 | A6\n");
         exit(1);
      }
   }
   if (plotbegin(0) < 0) {
      fputs("Failed to initialise HPGL library\n", stderr);
      exit(1);
   }
   if (getplotinfo(&info, sizeof (info)) < 0) {
      fputs("Failed to get plot information\n", stderr);
      exit(1);
   }
   maxx = info.widthInUnits;
   maxy = info.heightInUnits;
   switch (info.paperSize) {
   case ISO_A3:
      nx = 4;
      ny = 2;
      trueWidthmm = 420;
      trueHeightmm = 297;
      portrait = 1;
      break;
   case ISO_A4:
      nx = 2;
      ny = 2;
      trueWidthmm = 297;
      trueHeightmm = 210;
      portrait = 0;
      break;
   case ISO_A5:
      nx = 2;
      ny = 1;
      trueWidthmm = 210;
      trueHeightmm = 148;
      portrait = 1;
      break;
   case ISO_A6:
      nx = 1;
      ny = 1;
      trueWidthmm = 184;
      trueHeightmm = 105;
      portrait = 0;
      break;
   }
   borderx = (trueWidthmm - info.widthInmm) / 2.0;
   bordery = (trueHeightmm - info.heightInmm) / 2.0;
   dx = (trueWidthmm * info.unitsPermm) / (double)nx;
   dy = (trueHeightmm * info.unitsPermm) / (double)ny;
   for (i = 1; i < nx; i++) {
      x = (dx * (double)i) - (borderx * info.unitsPermm);
      moveto(x, 0);
      lineto(x, maxy);
   }
   for (i = 1; i < ny; i++) {
      y = (dy * (double)i) - (bordery * info.unitsPermm);
      moveto(0, y);
      lineto(maxx, y);
   }
   for (i = 0; i < nx; i++)
      for (j = 0; j < ny; j++) {
         x = (dx * (double)i) - (borderx * info.unitsPermm);
         y = (dy * (double)j) - (bordery * info.unitsPermm);
         if (portrait)
            postcard_port(x, y, dx, dy, maxx, maxy);
         else
            postcard_land(x, y, dx, dy, maxx, maxy);
      }
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   int i; int j;
   _Bool portrait;
   double x; double y;
   double dx; double dy;
   int nx; int ny;
   double maxx; double maxy;
   double trueWidthmm;
   double trueHeightmm;
   double borderx;
   double bordery;
   struct PlotInfo info;
   while ((opt = getopt(argc, argv, "no:p:q:s:t:v:")) != -1) {
      switch (opt) {
      case 's':
      case 'n':
      case 'o':
      case 'p':
      case 'q':
      case 'v':
         plotopt(opt, optarg);
         break;
      case 't':
         break;
      default:
         fprintf(stderr, "Usage: %s [-p pen] [-q plotter] [-s <size>] [-t title]\n", argv[0]);
         fprintf(stderr, "       <size> ::= A1 | A2 | A3 | A4 | A5 | A6\n");
         exit(1);
      }
   }
   if (plotbegin(0) < 0) {
      fputs("Failed to initialise HPGL library\n", stderr);
      exit(1);
   }
   if (getplotinfo(&info, sizeof (info)) < 0) {
      fputs("Failed to get plot information\n", stderr);
      exit(1);
   }
   maxx = info.widthInUnits;
   maxy = info.heightInUnits;
   switch (info.paperSize) {
   case ISO_A3:
      nx = 4;
      ny = 2;
      trueWidthmm = 420;
      trueHeightmm = 297;
      portrait = 1;
      break;
   case ISO_A4:
      nx = 2;
      ny = 2;
      trueWidthmm = 297;
      trueHeightmm = 210;
      portrait = 0;
      break;
   case ISO_A5:
      nx = 2;
      ny = 1;
      trueWidthmm = 210;
      trueHeightmm = 148;
      portrait = 1;
      break;
   case ISO_A6:
      nx = 1;
      ny = 1;
      trueWidthmm = 184;
      trueHeightmm = 105;
      portrait = 0;
      break;
   }
   borderx = (trueWidthmm - info.widthInmm) / 2.0;
   bordery = (trueHeightmm - info.heightInmm) / 2.0;
   dx = (trueWidthmm * info.unitsPermm) / (double)nx;
   dy = (trueHeightmm * info.unitsPermm) / (double)ny;
   for (i = 1; i < nx; i++) {
      x = (dx * (double)i) - (borderx * info.unitsPermm);
      moveto(x, 0);
      lineto(x, maxy);
   }
   for (i = 1; i < ny; i++) {
      y = (dy * (double)i) - (bordery * info.unitsPermm);
      moveto(0, y);
      lineto(maxx, y);
   }
   for (i = 0; i < nx; i++)
      for (j = 0; j < ny; j++) {
         x = (dx * (double)i) - (borderx * info.unitsPermm);
         y = (dy * (double)j) - (bordery * info.unitsPermm);
         if (portrait)
            postcard_port(x, y, dx, dy, maxx, maxy);
         else
            postcard_land(x, y, dx, dy, maxx, maxy);
      }
   plotend();
   return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: i int

variable_types: j int

variable_types: dx double

variable_types: dy double

variable_types: trueWidthmm double

variable_types: trueHeightmm double

variable_types: borderx double

variable_types: bordery double


decompiled_code:
__int64 __fastcall circle4(double a1, double a2, double a3)
{
double v4; // [rsp+0h] [rbp-18h]

v4 = a3 / 5.0;
circle(a1, a2, a3 / 5.0 * 1.414213562373095);
circle(a1, a2, v4 + v4);
circle(a1 - v4, a2, v4);
circle(a1, v4 + a2, v4);
circle(a1, a2 - v4, v4);
return circle(a1 + v4, a2, v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3)
{
double v4; // [rsp+0h] [rbp-18h]

v4 = a3 / 5.0;
circle(a1, a2, a3 / 5.0 * 1.414213562373095);
circle(a1, a2, v4 + v4);
circle(a1 - v4, a2, v4);
circle(a1, v4 + a2, v4);
circle(a1, a2 - v4, v4);
return circle(a1 + v4, a2, v4);
}

original_code:
void circle4(const double x0, const double y0, const double ht)
{
   const double radius = ht / 5.0;
   circle(x0, y0, radius * sqrt(2.0));
   circle(x0, y0, radius * 2.0);
   circle(x0 - radius, y0, radius);
   circle(x0, y0 + radius, radius);
   circle(x0, y0 - radius, radius);
   circle(x0 + radius, y0, radius);
}

canonical_original_code:
void circle4(double x0, double y0, double ht)
{
   double radius = ht / 5.0;
   circle(x0, y0, radius * sqrt(2.0));
   circle(x0, y0, radius * 2.0);
   circle(x0 - radius, y0, radius);
   circle(x0, y0 + radius, radius);
   circle(x0, y0 - radius, radius);
   circle(x0 + radius, y0, radius);
}

variable_types: radius double


circlearcs

original_code:
void circlearcs(const double x0, const double y0, const double ht)
{
   int i;
   const double radius = ht / 2.5;
   circle(x0, y0, radius);
   moveto(x0, y0 - radius);
   lineto(x0, y0 + radius);
   for (i = 0; i < 22; i++) {
      const double x1 = x0 - radius - (8.0 * 40.0 * (double)i);
      const double y1 = y0;
      const double r = 10.0 * 40.0 * (double)(i + 1);
      const double d = x0 - x1;
      const double x = ((d * d) - (radius * radius) + (r * r)) / (2.0 * d);
      const double t1 = -d + radius - r;
      const double t2 = -d - radius + r;
      const double t3 = -d + radius + r;
      const double t4 = d + radius + r;
      const double a = (1.0 / d) * sqrt(t1 * t2 * t3 * t4);
      const double arcx = x1 + x;
      const double arcy = y0 - (a / 2.0);
      const double theta = atan2(a / 2.0, x) * 2.0;
      moveto(arcx, arcy);
      arc(x1, y1, theta * (180.0 / 3.14159265358979323846));
   }
}

canonical_original_code:
void circlearcs(double x0, double y0, double ht)
{
   int i;
   double radius = ht / 2.5;
   circle(x0, y0, radius);
   moveto(x0, y0 - radius);
   lineto(x0, y0 + radius);
   for (i = 0; i < 22; i++) {
      double x1 = x0 - radius - (8.0 * 40.0 * (double)i);
      double y1 = y0;
      double r = 10.0 * 40.0 * (double)(i + 1);
      double d = x0 - x1;
      double x = ((d * d) - (radius * radius) + (r * r)) / (2.0 * d);
      double t1 = -d + radius - r;
      double t2 = -d - radius + r;
      double t3 = -d + radius + r;
      double t4 = d + radius + r;
      double a = (1.0 / d) * sqrt(t1 * t2 * t3 * t4);
      double arcx = x1 + x;
      double arcy = y0 - (a / 2.0);
      double theta = atan2(a / 2.0, x) * 2.0;
      moveto(arcx, arcy);
      arc(x1, y1, theta * (180.0 / 3.14159265358979323846));
   }
}

variable_types: r double

variable_types: d double

variable_types: x double

variable_types: a double

variable_types: arcx double

variable_types: arcy double

variable_types: theta double


yinyang

decompiled_code:
__int64 __fastcall yinyang(int a1, double a2, double a3, double a4)
{
double v4; // xmm0_8
__int64 result; // rax
int i; // ebx
double v7; // [rsp+8h] [rbp-70h]
double v9; // [rsp+20h] [rbp-58h]
double v10; // [rsp+28h] [rbp-50h]
double v11; // [rsp+30h] [rbp-48h]
double v12; // [rsp+38h] [rbp-40h]
double cosx; // [rsp+40h] [rbp-38h] BYREF
double sinx[6]; // [rsp+48h] [rbp-30h] BYREF

v12 = 6.283185307179586 / (double)a1;
v11 = a4 * 0.25;
v4 = sin(v12 * 0.5);
v7 = v4 * (a4 * 0.25);
result = circle(a2, a3, v11 + v4 * v11);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
sincos((double)i * v12, sinx, &cosx);
v10 = v11 * sinx[0];
v9 = v11 * cosx;
moveto(cosx * v7 + v11 * cosx + a2, sinx[0] * v7 + v11 * sinx[0] + a3);
arc(v9 + a2, v10 + a3, (double)(a1 - 2) * 180.0 / (double)a1 * 0.5 + 180.0);
result = circle(v9 + a2, v10 + a3, v7 / 3.0);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, double a2, double a3, double a4)
{
double v4; // xmm0_8
__int64 result; // rax
int i; // ebx
double v7; // [rsp+8h] [rbp-70h]
double v9; // [rsp+20h] [rbp-58h]
double v10; // [rsp+28h] [rbp-50h]
double v11; // [rsp+30h] [rbp-48h]
double v12; // [rsp+38h] [rbp-40h]
double cosx; // [rsp+40h] [rbp-38h] BYREF
double sinx[6]; // [rsp+48h] [rbp-30h] BYREF

v12 = 6.283185307179586 / (double)a1;
v11 = a4 * 0.25;
v4 = sin(v12 * 0.5);
v7 = v4 * (a4 * 0.25);
result = circle(a2, a3, v11 + v4 * v11);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
sincos((double)i * v12, sinx, &cosx);
v10 = v11 * sinx[0];
v9 = v11 * cosx;
moveto(cosx * v7 + v11 * cosx + a2, sinx[0] * v7 + v11 * sinx[0] + a3);
arc(v9 + a2, v10 + a3, (double)(a1 - 2) * 180.0 / (double)a1 * 0.5 + 180.0);
result = circle(v9 + a2, v10 + a3, v7 / 3.0);
}
}
return result;
}

original_code:
void yinyang(const double x0, const double y0, const double ht, const int n)
{
   const double interior = ((double)(n - 2) * 180.0) / (double)n;
   const double delta = (2.0 * 3.14159265358979323846) / (double)n;
   const double r = ht / 4.0;
   const double r2 = r * sin(delta / 2.0);
   int i;
   circle(x0, y0, r + r2);
   for (i = 0; i < n; i++) {
      const double theta = delta * (double)i;
      const double x = r * cos(theta);
      const double y = r * sin(theta);
      const double arcx = x + (r2 * cos(theta));
      const double arcy = y + (r2 * sin(theta));
      moveto(x0 + arcx, y0 + arcy);
      arc(x0 + x, y0 + y, 180.0 + (interior / 2.0));
      circle(x0 + x, y0 + y, r2 / 3.0);
   }
}

canonical_original_code:
void yinyang(double x0, double y0, double ht, int n)
{
   double interior = ((double)(n - 2) * 180.0) / (double)n;
   double delta = (2.0 * 3.14159265358979323846) / (double)n;
   double r = ht / 4.0;
   double r2 = r * sin(delta / 2.0);
   int i;
   circle(x0, y0, r + r2);
   for (i = 0; i < n; i++) {
      double theta = delta * (double)i;
      double x = r * cos(theta);
      double y = r * sin(theta);
      double arcx = x + (r2 * cos(theta));
      double arcy = y + (r2 * sin(theta));
      moveto(x0 + arcx, y0 + arcy);
      arc(x0 + x, y0 + y, 180.0 + (interior / 2.0));
      circle(x0 + x, y0 + y, r2 / 3.0);
   }
}

variable_types: ht double

variable_types: n int

variable_types: interior double

variable_types: delta double

variable_types: y double


rotate

decompiled_code:
void __fastcall rotate(double *a1, double *a2, double a3, double a4)
{
double v5; // xmm0_8
double v6; // xmm2_8

v5 = *a1;
v6 = *a2;
*a1 = *a1 * a4 - *a2 * a3;
*a2 = v5 * a3 + v6 * a4;
}

canonical_decompiled_code:
void __fastcall func4(double *a1, double *a2, double a3, double a4)
{
double v5; // xmm0_8
double v6; // xmm2_8

v5 = *a1;
v6 = *a2;
*a1 = *a1 * a4 - *a2 * a3;
*a2 = v5 * a3 + v6 * a4;
}

original_code:
void rotate(double *x, double *y, const double st, const double ct)
{
   const double newx = (*x * ct) - (*y * st);
   const double newy = (*x * st) + (*y * ct);
   *x = newx;
   *y = newy;
}

canonical_original_code:
void rotate(double *x, double *y, double st, double ct)
{
   double newx = (*x * ct) - (*y * st);
   double newy = (*x * st) + (*y * ct);
   *x = newx;
   *y = newy;
}

variable_types:
x
double *

variable_types:
y
double *

variable_types: st double

variable_types: ct double

variable_types: newx double

variable_types: newy double


original_code:
void plot_lr(const double xc, const double yc, const double r1, const double r2)
{
   const int n = 9;
   const double delta = (2.0 * 3.14159265358979323846) / (double)n;
   const double degrees = 180.0 + (delta * (180.0 / 3.14159265358979323846));
   const double r = r2 * 0.8;
   int i;
   for (i = 0; i < n; i++) {
      const double theta = delta * (double)i;
      const double x = r * cos(theta);
      const double y = r * sin(theta);
      const double xn = r * cos(theta + delta);
      const double yn = r * sin(theta + delta);
      const double xp = r * cos(theta - delta);
      const double yp = r * sin(theta - delta);
      const double x1 = (x + xn) / 2.0;
      const double y1 = (y + yn) / 2.0;
      const double x2 = (x * 0.4) + (xp * 0.6);
      const double y2 = (y * 0.4) + (yp * 0.6);
      moveto(xc + x2, yc + y2);
      arc(xc + x, yc + y, degrees);
      arc(xc + x1, yc + y1, 180.0);
   }
}

canonical_original_code:
void plot_lr(double xc, double yc, double r1, double r2)
{
   int n = 9;
   double delta = (2.0 * 3.14159265358979323846) / (double)n;
   double degrees = 180.0 + (delta * (180.0 / 3.14159265358979323846));
   double r = r2 * 0.8;
   int i;
   for (i = 0; i < n; i++) {
      double theta = delta * (double)i;
      double x = r * cos(theta);
      double y = r * sin(theta);
      double xn = r * cos(theta + delta);
      double yn = r * sin(theta + delta);
      double xp = r * cos(theta - delta);
      double yp = r * sin(theta - delta);
      double x1 = (x + xn) / 2.0;
      double y1 = (y + yn) / 2.0;
      double x2 = (x * 0.4) + (xp * 0.6);
      double y2 = (y * 0.4) + (yp * 0.6);
      moveto(xc + x2, yc + y2);
      arc(xc + x, yc + y, degrees);
      arc(xc + x1, yc + y1, 180.0);
   }
}

variable_types: xc double

variable_types: yc double

variable_types: degrees double

variable_types: r double

variable_types: i int

variable_types: xn double

variable_types: yn double

variable_types: xp double

variable_types: yp double


original_code:
void plot_ur(const double xc, const double yc, const double r1, const double r2)
{
   const int n = 16;
   const double delta = (2.0 * 3.14159265358979323846) / (double)n;
   const double r = r2 * sin(delta / 2.0);
   const double d = sqrt(3.0 * r * r);
   int i;
   for (i = 0; i < n; i++) {
      const double theta = delta * (double)i;
      const double st = sin(theta);
      const double ct = cos(theta);
      const double x = r2 * ct;
      const double y = r2 * st;
      const double x1 = (r2 - d) * ct;
      const double y1 = (r2 - d) * st;
      double x2 = r2 - d;
      double y2 = -r;
      double x3 = r2 - d;
      double y3 = r;
      rotate(&x2, &y2, st, ct);
      rotate(&x3, &y3, st, ct);
      moveto(xc, yc);
      lineto(xc + x1, yc + y1);
      arc(xc + x2, yc + y2, -60.0);
      arc(xc + x, yc + y, 300.0);
      arc(xc + x3, yc + y3, -60.0);
   }
}

canonical_original_code:
void plot_ur(double xc, double yc, double r1, double r2)
{
   int n = 16;
   double delta = (2.0 * 3.14159265358979323846) / (double)n;
   double r = r2 * sin(delta / 2.0);
   double d = sqrt(3.0 * r * r);
   int i;
   for (i = 0; i < n; i++) {
      double theta = delta * (double)i;
      double st = sin(theta);
      double ct = cos(theta);
      double x = r2 * ct;
      double y = r2 * st;
      double x1 = (r2 - d) * ct;
      double y1 = (r2 - d) * st;
      double x2 = r2 - d;
      double y2 = -r;
      double x3 = r2 - d;
      double y3 = r;
      rotate(&x2, &y2, st, ct);
      rotate(&x3, &y3, st, ct);
      moveto(xc, yc);
      lineto(xc + x1, yc + y1);
      arc(xc + x2, yc + y2, -60.0);
      arc(xc + x, yc + y, 300.0);
      arc(xc + x3, yc + y3, -60.0);
   }
}

variable_types: n int

variable_types: delta double

variable_types: d double

variable_types: theta double

variable_types: x double


drawlobes

decompiled_code:
__int64 __fastcall drawlobes(double a1, double a2, double a3, double a4, double a5)
{
int i; // ebx
double v6; // xmm0_8
__int64 result; // rax
double cosx; // [rsp+30h] [rbp-28h] BYREF
double sinx[4]; // [rsp+38h] [rbp-20h] BYREF

moveto(a1 + a3 + a4);
for ( i = 1; i != 361; ++i )
{
sincos((double)i * 0.0174532925199433, sinx, &cosx);
v6 = cos((double)i * 0.0174532925199433 * a5);
result = lineto((v6 * a4 + a3) * cosx + a1, (v6 * a4 + a3) * sinx[0] + a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3, double a4, double a5)
{
int i; // ebx
double v6; // xmm0_8
__int64 result; // rax
double cosx; // [rsp+30h] [rbp-28h] BYREF
double sinx[4]; // [rsp+38h] [rbp-20h] BYREF

moveto(a1 + a3 + a4);
for ( i = 1; i != 361; ++i )
{
sincos((double)i * 0.0174532925199433, sinx, &cosx);
v6 = cos((double)i * 0.0174532925199433 * a5);
result = lineto((v6 * a4 + a3) * cosx + a1, (v6 * a4 + a3) * sinx[0] + a2);
}
return result;
}

original_code:
void drawlobes(const double x0, const double y0, const double a, const double b, const double l)
{
   int i;
   moveto(x0 + a + b, y0);
   for (i = 1; i <= 360; i++) {
      const double theta = i * (3.14159265358979323846 / 180.0);
      const double r = a + (b * cos(l * theta));
      const double x = r * cos(theta);
      const double y = r * sin(theta);
      lineto(x0 + x, y0 + y);
   }
}

canonical_original_code:
void drawlobes(double x0, double y0, double a, double b, double l)
{
   int i;
   moveto(x0 + a + b, y0);
   for (i = 1; i <= 360; i++) {
      double theta = i * (3.14159265358979323846 / 180.0);
      double r = a + (b * cos(l * theta));
      double x = r * cos(theta);
      double y = r * sin(theta);
      lineto(x0 + x, y0 + y);
   }
}

variable_types: a double

variable_types: b double

variable_types: l double

variable_types: y double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
double v4; // rbp
double v5; // r12
double v6; // r14
int i; // ebx
double v9; // [rsp+8h] [rbp-40h]
double v10; // [rsp+10h] [rbp-38h] BYREF
double v11[6]; // [rsp+18h] [rbp-30h] 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(v11, &v10);
v9 = 0.5 * v11[0];
v4 = 0.5 * v10;
moveto(0.0);
lineto(v11[0], v4);
moveto(v9);
lineto(v9, v10);
v5 = 0.25 * v10;
v6 = 0.25 * v10 / 3.0;
for ( i = 0; i != 9; ++i )
{
pencolr((unsigned int)(i % 4));
drawlobes(v9, v4, v5, v6, (double)i);
}
plotend();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
double v4; // rbp
double v5; // r12
double v6; // r14
int i; // ebx
double v9; // [rsp+8h] [rbp-40h]
double v10; // [rsp+10h] [rbp-38h] BYREF
double v11[6]; // [rsp+18h] [rbp-30h] 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(v11, &v10);
v9 = 0.5 * v11[0];
v4 = 0.5 * v10;
moveto(0.0);
lineto(v11[0], v4);
moveto(v9);
lineto(v9, v10);
v5 = 0.25 * v10;
v6 = 0.25 * v10 / 3.0;
for ( i = 0; i != 9; ++i )
{
pencolr((unsigned int)(i % 4));
func0(v9, v4, v5, v6, (double)i);
}
plotend();
return 0;
}

original_code:
int main(int argc, char *const argv[])
{
   int opt;
   double a, b;
   double maxx, maxy;
   double xc, yc;
   double w4, h4;
   int i;
   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;
   w4 = maxx / 4.0;
   h4 = maxy / 4.0;
   moveto(0.0, yc);
   lineto(maxx, yc);
   moveto(xc, 0.0);
   lineto(xc, maxy);
   a = maxy / 4.0;
   b = a / 3.0;
   for (i = 0; i < 9; i++) {
      pencolr(i % 4);
      drawlobes(xc, yc, a, b, (double)i);
   }
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   double a; double b;
   double maxx; double maxy;
   double xc; double yc;
   double w4; double h4;
   int i;
   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;
   w4 = maxx / 4.0;
   h4 = maxy / 4.0;
   moveto(0.0, yc);
   lineto(maxx, yc);
   moveto(xc, 0.0);
   lineto(xc, maxy);
   a = maxy / 4.0;
   b = a / 3.0;
   for (i = 0; i < 9; i++) {
      pencolr(i % 4);
      drawlobes(xc, yc, a, b, (double)i);
   }
   plotend();
   return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: maxx double

variable_types: maxy double

variable_types: xc double

variable_types: yc double


ringoshapes

decompiled_code:
__int64 __fastcall ringoshapes(int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm7_8
double v9; // rbp
int i; // ebx
double v11; // xmm4_8
double v12; // xmm5_8
__int64 result; // rax
double v14; // [rsp+8h] [rbp-50h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx[6]; // [rsp+28h] [rbp-30h] BYREF

v8 = a4 * 0.25;
v14 = 6.283185307179586 / (double)a1;
if ( a1 > 0 )
{
v9 = a4;
for ( i = 0; i != a1; ++i )
{
sincos((double)i * v14, sinx, &cosx);
moveto(v9 * cosx + a2, v9 * sinx[0] + a3, a4, a5, v11, v12, a8, v8);
sincos((double)i * v14 + 1.570796326794897, sinx, &cosx);
a5 = v8 * cosx;
a4 = v14 * 1.2 * 57.29577951308232;
result = arc(v8 * cosx + a2, v8 * sinx[0] + a3, a4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm7_8
double v9; // rbp
int i; // ebx
double v11; // xmm4_8
double v12; // xmm5_8
__int64 result; // rax
double v14; // [rsp+8h] [rbp-50h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx[6]; // [rsp+28h] [rbp-30h] BYREF

v8 = a4 * 0.25;
v14 = 6.283185307179586 / (double)a1;
if ( a1 > 0 )
{
v9 = a4;
for ( i = 0; i != a1; ++i )
{
sincos((double)i * v14, sinx, &cosx);
moveto(v9 * cosx + a2, v9 * sinx[0] + a3, a4, a5, v11, v12, a8, v8);
sincos((double)i * v14 + 1.570796326794897, sinx, &cosx);
a5 = v8 * cosx;
a4 = v14 * 1.2 * 57.29577951308232;
result = arc(v8 * cosx + a2, v8 * sinx[0] + a3, a4);
}
}
return result;
}

original_code:
void ringoshapes(const double x0, const double y0, const double radius, const int nshapes)
{
   int i;
   double x, y;
   double xc, yc;
   const double d = radius / 4.0;
   const double delta = 2.0 * 3.14159265358979323846 / (double)nshapes;
   for (i = 0; i < nshapes; i++) {
      const double theta = i * delta;
      x = (radius * cos(theta)) + x0;
      y = (radius * sin(theta)) + y0;
      moveto(x, y);
      xc = (d * cos(theta + (3.14159265358979323846 / 2.0))) + x0;
      yc = (d * sin(theta + (3.14159265358979323846 / 2.0))) + y0;
      arc(xc, yc, (delta * 1.2) * (180.0 / 3.14159265358979323846));
   }
}

canonical_original_code:
void ringoshapes(double x0, double y0, double radius, int nshapes)
{
   int i;
   double x; double y;
   double xc; double yc;
   double d = radius / 4.0;
   double delta = 2.0 * 3.14159265358979323846 / (double)nshapes;
   for (i = 0; i < nshapes; i++) {
      double theta = i * delta;
      x = (radius * cos(theta)) + x0;
      y = (radius * sin(theta)) + y0;
      moveto(x, y);
      xc = (d * cos(theta + (3.14159265358979323846 / 2.0))) + x0;
      yc = (d * sin(theta + (3.14159265358979323846 / 2.0))) + y0;
      arc(xc, yc, (delta * 1.2) * (180.0 / 3.14159265358979323846));
   }
}

variable_types: radius double

variable_types: nshapes int

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm3_8
unsigned int v4; // eax
double v5; // r12
double v6; // rbx
double v7; // xmm6_8
double v8; // rbp
double v9; // xmm4_8
double v10; // xmm5_8
int i; // ebx
int v12; // edi
double v14; // [rsp+8h] [rbp-30h]
double v15; // [rsp+10h] [rbp-28h] BYREF
double v16[4]; // [rsp+18h] [rbp-20h] BYREF

while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v4 == -1 )
break;
if ( v4 - 110 > 8 || ((1LL << ((unsigned __int8)v4 - 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(v4, optarg);
}
if ( (int)plotbegin(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v16, &v15);
v5 = 0.5 * v16[0];
v6 = v15;
v7 = v15;
v8 = 0.5 * v15;
circle(0.5 * v16[0], 0.5 * v15, 0.5 * v15);
v10 = v6 / 24.0;
v14 = v6 / 24.0;
for ( i = 0; i != 11; ringoshapes(v12 + 16, v5, v8, (double)i * v14, v3, v9, v10, v7) )
v12 = i++;
plotend();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm3_8
unsigned int v4; // eax
double v5; // r12
double v6; // rbx
double v7; // xmm6_8
double v8; // rbp
double v9; // xmm4_8
double v10; // xmm5_8
int i; // ebx
int v12; // edi
double v14; // [rsp+8h] [rbp-30h]
double v15; // [rsp+10h] [rbp-28h] BYREF
double v16[4]; // [rsp+18h] [rbp-20h] BYREF

while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v4 == -1 )
break;
if ( v4 - 110 > 8 || ((1LL << ((unsigned __int8)v4 - 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(v4, optarg);
}
if ( (int)plotbegin(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v16, &v15);
v5 = 0.5 * v16[0];
v6 = v15;
v7 = v15;
v8 = 0.5 * v15;
circle(0.5 * v16[0], 0.5 * v15, 0.5 * v15);
v10 = v6 / 24.0;
v14 = v6 / 24.0;
for ( i = 0; i != 11; func0(v12 + 16, v5, v8, (double)i * v14, v3, v9, v10, v7) )
v12 = i++;
plotend();
return 0;
}

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;
   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 / 24.0;
   for (i = 0; i < 11; i++) {
      r = radius * (i + 1);
      ringoshapes(xc, yc, r, 16 + i);
   }
   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;
   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 / 24.0;
   for (i = 0; i < 11; i++) {
      r = radius * (i + 1);
      ringoshapes(xc, yc, r, 16 + i);
   }
   plotend();
   return (0);
}

variable_types: height double

variable_types: r double


original_code:
void draw_arcs(const double x, const double y, const double r, const char str[])
{
   moveto(x, y + r);
   if (str[0] == '0') {
      arc(x, y, 90.0);
   }
   else if (str[0] == '1') {
      lineto(x - r, y);
   }
   else {
      arc(x - r, y + r, -90.0);
   }
   if (str[1] == '0') {
      arc(x, y, 90.0);
   }
   else if (str[1] == '1') {
      lineto(x, y - r);
   }
   else {
      arc(x - r, y - r, -90.0);
   }
   if (str[2] == '0') {
      arc(x, y, 90.0);
   }
   else if (str[2] == '1') {
      lineto(x + r, y);
   }
   else {
      arc(x + r, y - r, -90.0);
   }
   if (str[3] == '0') {
      arc(x, y, 90.0);
   }
   else if (str[3] == '1') {
      lineto(x, y + r);
   }
   else {
      arc(x + r, y + r, -90.0);
   }
}

variable_types: x double

variable_types:
str
char []


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
double v4; // r14
int v5; // er12
int i; // ebp
int j; // ebx
__int64 v8; // rsi
double v10; // [rsp+0h] [rbp-58h]
double v11; // [rsp+8h] [rbp-50h]
char v12[8]; // [rsp+18h] [rbp-40h] BYREF
double v13; // [rsp+20h] [rbp-38h] BYREF
double v14[6]; // [rsp+28h] [rbp-30h] 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(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v14, &v13);
v10 = v13 / 9.0;
v4 = v13 / 9.0 * 0.45;
v11 = 0.5 * v14[0] - 0.5 * v13;
rectangle(v11, 0.0, 0.5 * v14[0] + 0.5 * v13);
v5 = 0;
for ( i = 0; i != 9; ++i )
{
for ( j = 0; j != 9; ++j )
{
v8 = (unsigned int)(j + v5);
v12[0] = (char)((int)v8 / 27) % 3 + 48;
v12[1] = (char)((int)v8 / 9) % 3 + 48;
v12[2] = (int)v8 / 3 % 3 + 48;
v12[3] = (j + v5) % 3 + 48;
v12[4] = 0;
printf("%2d %s ", v8, v12);
draw_arcs(v12, (double)j * v10 + v11 + v10 * 0.5, v10 * 0.5 + (double)i * v10, v4);
}
putchar(10);
v5 += 9;
}
plotend();
return 0;
}

original_code:
int main(int argc, char * const argv[])
{
   int opt;
   int i, j;
   double height;
   double xc, yc;
   double x0, y0;
   double maxx, maxy;
   double left, right;
   double gridsz;
   double radius;
   char str[8];
   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(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;
   gridsz = height / 9.0;
   radius = gridsz * 0.45;
   left = xc - (height / 2.0);
   right = xc + (height / 2.0);
   rectangle(left, 0.0, right, maxy);
   for (i = 0; i < 9; i++) {
      for (j = 0; j < 9; j++) {
         const int n = (i * 9) + j;
         str[0] = ((n / 27) % 3) + '0';
         str[1] = ((n / 9) % 3) + '0';
         str[2] = ((n / 3) % 3) + '0';
         str[3] = (n % 3) + '0';
         str[4] = '\0';
         printf("%2d %s ", n, str);
         x0 = left + (j * gridsz) + (gridsz / 2.0);
         y0 = (i * gridsz) + (gridsz / 2.0);
         draw_arcs(x0, y0, radius, str);
      }
      printf("\n");
   }
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   int i; int j;
   double height;
   double xc; double yc;
   double x0; double y0;
   double maxx; double maxy;
   double left; double right;
   double gridsz;
   double radius;
   char str[8];
   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(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;
   gridsz = height / 9.0;
   radius = gridsz * 0.45;
   left = xc - (height / 2.0);
   right = xc + (height / 2.0);
   rectangle(left, 0.0, right, maxy);
   for (i = 0; i < 9; i++) {
      for (j = 0; j < 9; j++) {
         int n = (i * 9) + j;
         str[0] = ((n / 27) % 3) + '0';
         str[1] = ((n / 9) % 3) + '0';
         str[2] = ((n / 3) % 3) + '0';
         str[3] = (n % 3) + '0';
         str[4] = '\0';
         printf("%2d %s ", n, str);
         x0 = left + (j * gridsz) + (gridsz / 2.0);
         y0 = (i * gridsz) + (gridsz / 2.0);
         draw_arcs(x0, y0, radius, str);
      }
      printf("\n");
   }
   plotend();
   return (0);
}

variable_types: j int

variable_types: left double

variable_types: right double

variable_types: gridsz double

variable_types:
str
char [8]

variable_types: n int


rotate

canonical_decompiled_code:
void __fastcall func0(double *a1, double *a2, double a3, double a4)
{
double v5; // xmm0_8
double v6; // xmm2_8

v5 = *a1;
v6 = *a2;
*a1 = *a1 * a4 - *a2 * a3;
*a2 = v5 * a3 + v6 * a4;
}

variable_types:
x
double *

variable_types:
y
double *

variable_types: st double

variable_types: ct double

variable_types: newx double

variable_types: newy 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 func1(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: a double

variable_types: b double

variable_types: theta double

variable_types: npts int

variable_types: delta double

variable_types: sintheta double

variable_types: costheta double

variable_types: i int

variable_types: t double

variable_types: y double


decompiled_code:
__int64 __fastcall half_superellipse(double a1, double a2, double a3, double a4, double a5, double a6)
{
int v6; // er12
int i; // ebp
double v8; // rbx
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm2_8
double v12; // xmm1_8
__int64 result; // rax
double v14; // r14
double v16; // [rsp+10h] [rbp-68h]
double v17; // [rsp+18h] [rbp-60h]
double cosx; // [rsp+40h] [rbp-38h] BYREF
double sinx[6]; // [rsp+48h] [rbp-30h] BYREF

sincos(a5, sinx, &cosx);
v16 = cosx;
v17 = sinx[0];
v6 = 1;
for ( i = 0; ; ++i )
{
sincos((double)i * 0.08726646259971647, sinx, &cosx);
v14 = cosx;
if ( sinx[0] < 0.0 )
*(_QWORD *)&v8 = COERCE_UNSIGNED_INT64(pow(COERCE_DOUBLE(*(_QWORD *)&sinx[0] ^ LC3), 2.0 / a6)) ^ LC3;
else
v8 = pow(sinx[0], 2.0 / a6);
if ( v14 < 0.0 )
*(_QWORD *)&v9 = COERCE_UNSIGNED_INT64(pow(COERCE_DOUBLE(*(_QWORD *)&v14 ^ LC3), 2.0 / a6)) ^ LC3;
else
v9 = pow(v14, 2.0 / a6);
v10 = v9 * a3;
v11 = v16 * v10 - v17 * (v8 * a4);
v12 = v8 * a4 * v16 + v10 * v17;
if ( i )
break;
moveto(v11 + a1, v12 + a2);
LABEL_6:
++v6;
}
result = lineto(v11 + a1, v12 + a2);
if ( v6 <= 36 )
goto LABEL_6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, double a2, double a3, double a4, double a5, double a6)
{
int v6; // er12
int i; // ebp
double v8; // rbx
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm2_8
double v12; // xmm1_8
__int64 result; // rax
double v14; // r14
double v16; // [rsp+10h] [rbp-68h]
double v17; // [rsp+18h] [rbp-60h]
double cosx; // [rsp+40h] [rbp-38h] BYREF
double sinx[6]; // [rsp+48h] [rbp-30h] BYREF

sincos(a5, sinx, &cosx);
v16 = cosx;
v17 = sinx[0];
v6 = 1;
for ( i = 0; ; ++i )
{
sincos((double)i * 0.08726646259971647, sinx, &cosx);
v14 = cosx;
if ( sinx[0] < 0.0 )
*(_QWORD *)&v8 = COERCE_UNSIGNED_INT64(pow(COERCE_DOUBLE(*(_QWORD *)&sinx[0] ^ LC3), 2.0 / a6)) ^ LC3;
else
v8 = pow(sinx[0], 2.0 / a6);
if ( v14 < 0.0 )
*(_QWORD *)&v9 = COERCE_UNSIGNED_INT64(pow(COERCE_DOUBLE(*(_QWORD *)&v14 ^ LC3), 2.0 / a6)) ^ LC3;
else
v9 = pow(v14, 2.0 / a6);
v10 = v9 * a3;
v11 = v16 * v10 - v17 * (v8 * a4);
v12 = v8 * a4 * v16 + v10 * v17;
if ( i )
break;
moveto(v11 + a1, v12 + a2);
LABEL_6:
++v6;
}
result = lineto(v11 + a1, v12 + a2);
if ( v6 <= 36 )
goto LABEL_6;
return result;
}

original_code:
void half_superellipse(const double x0, const double y0, const double a, const double b, const double theta, const double d)
{
   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++) {
      double sinpt, cospt;
      const double t = (double)i * delta;
      const double st = sin(t);
      const double ct = cos(t);
      if (st < 0.0)
         sinpt = -pow(-st, 2.0 / d);
      else
         sinpt = pow(st, 2.0 / d);
      if (ct < 0.0)
         cospt = -pow(-ct, 2.0 / d);
      else
         cospt = pow(ct, 2.0 / d);
      const double x = (a * cospt * costheta) - (b * sinpt * sintheta);
      const double y = (a * cospt * sintheta) + (b * sinpt * costheta);
      if (i == 0)
         moveto(x0 + x, y0 + y);
      else
         lineto(x0 + x, y0 + y);
   }
}

canonical_original_code:
void half_superellipse(double x0, double y0, double a, double b, double theta, double d)
{
   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 sinpt; double cospt;
      double t = (double)i * delta;
      double st = sin(t);
      double ct = cos(t);
      if (st < 0.0)
         sinpt = -pow(-st, 2.0 / d);
      else
         sinpt = pow(st, 2.0 / d);
      if (ct < 0.0)
         cospt = -pow(-ct, 2.0 / d);
      else
         cospt = pow(ct, 2.0 / d);
      double x = (a * cospt * costheta) - (b * sinpt * sintheta);
      double y = (a * cospt * sintheta) + (b * sinpt * costheta);
      if (i == 0)
         moveto(x0 + x, y0 + y);
      else
         lineto(x0 + x, y0 + y);
   }
}

variable_types: d double

variable_types: sinpt double

variable_types: cospt double

variable_types: x double


flower

decompiled_code:
__int64 __fastcall flower(int a1, double a2, double a3, double a4, double a5)
{
int i; // ebp
double v6; // rbx
double v7; // r13
__int64 result; // rax
double v9; // [rsp+20h] [rbp-58h]
double v10; // [rsp+28h] [rbp-50h]
double v11; // [rsp+30h] [rbp-48h]
double cosx; // [rsp+40h] [rbp-38h] BYREF
double sinx[6]; // [rsp+48h] [rbp-30h] BYREF

v11 = 6.283185307179586 / (double)a1;
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
sincos((double)i * v11 + a5, sinx, &cosx);
v9 = a4 * cosx;
v10 = a4 * sinx[0];
sincos((double)i * v11 + a5 + v11, sinx, &cosx);
v6 = cosx;
v7 = sinx[0];
moveto(a2, a3);
lineto((v6 * a4 + v9) * 0.5 + a2, (v7 * a4 + v10) * 0.5 + a3);
result = arc(
v9 + a2,
v10 + a3,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(6.283185307179586 / (double)a1 * 57.29577951308232 + 180.0) ^ LC3));
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, double a2, double a3, double a4, double a5)
{
int i; // ebp
double v6; // rbx
double v7; // r13
__int64 result; // rax
double v9; // [rsp+20h] [rbp-58h]
double v10; // [rsp+28h] [rbp-50h]
double v11; // [rsp+30h] [rbp-48h]
double cosx; // [rsp+40h] [rbp-38h] BYREF
double sinx[6]; // [rsp+48h] [rbp-30h] BYREF

v11 = 6.283185307179586 / (double)a1;
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
{
sincos((double)i * v11 + a5, sinx, &cosx);
v9 = a4 * cosx;
v10 = a4 * sinx[0];
sincos((double)i * v11 + a5 + v11, sinx, &cosx);
v6 = cosx;
v7 = sinx[0];
moveto(a2, a3);
lineto((v6 * a4 + v9) * 0.5 + a2, (v7 * a4 + v10) * 0.5 + a3);
result = arc(
v9 + a2,
v10 + a3,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(6.283185307179586 / (double)a1 * 57.29577951308232 + 180.0) ^ LC3));
}
}
return result;
}

original_code:
void flower(const double xc, const double yc, const double r2, const double angle, const int n)
{
   const double delta = (2.0 * 3.14159265358979323846) / (double)n;
   const double degrees = 180.0 + (delta * (180.0 / 3.14159265358979323846));
   int i;
   for (i = 0; i < n; i++) {
      const double theta = angle + (delta * (double)i);
      const double x = r2 * cos(theta);
      const double y = r2 * sin(theta);
      const double x1 = r2 * cos(theta + delta);
      const double y1 = r2 * sin(theta + delta);
      const double x2 = (x + x1) / 2.0;
      const double y2 = (y + y1) / 2.0;
      moveto(xc, yc);
      lineto(xc + x2, yc + y2);
      arc(xc + x, yc + y, -degrees);
   }
}

canonical_original_code:
void flower(double xc, double yc, double r2, double angle, int n)
{
   double delta = (2.0 * 3.14159265358979323846) / (double)n;
   double degrees = 180.0 + (delta * (180.0 / 3.14159265358979323846));
   int i;
   for (i = 0; i < n; i++) {
      double theta = angle + (delta * (double)i);
      double x = r2 * cos(theta);
      double y = r2 * sin(theta);
      double x1 = r2 * cos(theta + delta);
      double y1 = r2 * sin(theta + delta);
      double x2 = (x + x1) / 2.0;
      double y2 = (y + y1) / 2.0;
      moveto(xc, yc);
      lineto(xc + x2, yc + y2);
      arc(xc + x, yc + y, -degrees);
   }
}

variable_types: xc double

variable_types: yc double

variable_types: angle double

variable_types: n int

variable_types: degrees double


decorate

decompiled_code:
__int64 __fastcall decorate(char a1, double a2, double a3, double a4, double a5, double a6)
{
__int64 result; // rax

if ( (a1 & 1) != 0 )
result = flower(5, a2, a3, a4 * 0.5, a6);
else
result = ellipse();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, double a2, double a3, double a4, double a5, double a6)
{
__int64 result; // rax

if ( (a1 & 1) != 0 )
result = func3(5, a2, a3, a4 * 0.5, a6);
else
result = ellipse();
return result;
}

original_code:
void decorate(const int side, const double xc, const double yc, const double wd, const double ht, const double angle)
{
   if ((side % 2) == 0)
      ellipse(xc, yc, wd, ht, angle);
   else
      flower(xc, yc, wd / 2.0, angle, 5);
}

canonical_original_code:
void decorate(int side, double xc, double yc, double wd, double ht, double angle)
{
   if ((side % 2) == 0)
      ellipse(xc, yc, wd, ht, angle);
   else
      flower(xc, yc, wd / 2.0, angle, 5);
}

variable_types: side int

variable_types: wd double

variable_types: ht double


hexgrid

original_code:
void hexgrid(const double side, const int nx, const int ny)
{
   int i, j;
   const double width = 2.0 * side * cos(30.0 * (3.14159265358979323846 / 180.0));
   for (i = 0; i < ny; i++) {
      const double y = 2.0 * side * (double)i;
      const double y1 = y + (side * sin(30.0 * (3.14159265358979323846 / 180.0)));
      const double y3 = y1 + side;
      const double y4 = y + (2.0 * side);
      for (j = 0; j < nx; j++) {
         const double x = width * (double)j;
         const double x1 = x + (side * cos(30 * (3.14159265358979323846 / 180.0)));
         const double x2 = x + width;
         moveto(x, y1);
         lineto(x1, y);
         lineto(x2, y1);
      }
      for (j = 0; j < (nx + 1); j++) {
         const double x = width * (double)j;
         moveto(x, y1);
         lineto(x, y3);
      }
      for (j = 0; j < nx; j++) {
         const double x = width * (double)j;
         const double x1 = x + (side * cos(30 * (3.14159265358979323846 / 180.0)));
         const double x2 = x + width;
         moveto(x, y3);
         lineto(x1, y4);
         lineto(x2, y3);
      }
   }
}

canonical_original_code:
void hexgrid(double side, int nx, int ny)
{
   int i; int j;
   double width = 2.0 * side * cos(30.0 * (3.14159265358979323846 / 180.0));
   for (i = 0; i < ny; i++) {
      double y = 2.0 * side * (double)i;
      double y1 = y + (side * sin(30.0 * (3.14159265358979323846 / 180.0)));
      double y3 = y1 + side;
      double y4 = y + (2.0 * side);
      for (j = 0; j < nx; j++) {
         double x = width * (double)j;
         double x1 = x + (side * cos(30 * (3.14159265358979323846 / 180.0)));
         double x2 = x + width;
         moveto(x, y1);
         lineto(x1, y);
         lineto(x2, y1);
      }
      for (j = 0; j < (nx + 1); j++) {
         double x = width * (double)j;
         moveto(x, y1);
         lineto(x, y3);
      }
      for (j = 0; j < nx; j++) {
         double x = width * (double)j;
         double x1 = x + (side * cos(30 * (3.14159265358979323846 / 180.0)));
         double x2 = x + width;
         moveto(x, y3);
         lineto(x1, y4);
         lineto(x2, y3);
      }
   }
}

variable_types: side double

variable_types: nx int

variable_types: ny int

variable_types: j int

variable_types: width double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
char v6[32]; // [rsp+8h] [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(v6, &v5);
hexgrid(5, 3, 1800.0);
plotend();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v5; // [rsp+0h] [rbp-28h] BYREF
char v6[32]; // [rsp+8h] [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(v6, &v5);
func0(5, 3, 1800.0);
plotend();
return 0;
}

original_code:
int main(int argc, char * const argv[])
{
   int opt;
   double side;
   double maxx, maxy;
   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);
   side = 45.0 * 40.0;
   hexgrid(side, 5, 3);
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   double side;
   double maxx; double maxy;
   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);
   side = 45.0 * 40.0;
   hexgrid(side, 5, 3);
   plotend();
   return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: maxx double

variable_types: maxy double


hexa

decompiled_code:
__int64 __fastcall hexa(double a1)
{
int v1; // ebx

turn(120.0);
v1 = 5;
do
{
forward(a1);
turn(-60.0);
--v1;
}
while ( v1 );
return turn(180.0);
}

original_code:
void hexa(const double len)
{
   int i;
   turn(120.0);
   for (i = 0; i < 5; i++) {
      forward(len);
      turn(-60.0);
   }
   turn(180.0);
}

canonical_original_code:
void hexa(double len)
{
   int i;
   turn(120.0);
   for (i = 0; i < 5; i++) {
      forward(len);
      turn(-60.0);
   }
   turn(180.0);
}

variable_types: len double

variable_types: i int


penta

decompiled_code:
__int64 __fastcall penta(double a1)
{
int v1; // ebx

turn(108.0);
v1 = 4;
do
{
forward(a1);
turn(-72.0);
--v1;
}
while ( v1 );
return turn(180.0);
}

original_code:
void penta(const double len)
{
   int i;
   turn(108.0);
   for (i = 0; i < 4; i++) {
      forward(len);
      turn(-72.0);
   }
   turn(180.0);
}

canonical_original_code:
void penta(double len)
{
   int i;
   turn(108.0);
   for (i = 0; i < 4; i++) {
      forward(len);
      turn(-72.0);
   }
   turn(180.0);
}


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 func9(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 func10()
{
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;
   }
}