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

repo: anachrocomputer/vec

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-D8h]
double v8; // [rsp+10h] [rbp-C8h]
double v9; // [rsp+20h] [rbp-B8h] BYREF
double v10; // [rsp+28h] [rbp-B0h] BYREF
char v11[168]; // [rsp+30h] [rbp-A8h] 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(v11, 144LL) < 0 )
{
fwrite("Failed to get plot information\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
getplotsize(&v9, &v10);
v4 = v9 * 0.5;
v5 = 0.5 * v10;
v8 = v9 * 0.25;
v7 = v10 * 0.25;
writedisplay("LIBTEST");
moveto(0.0);
lineto(v9, v5);
moveto(v4);
lineto(v4, v10);
lineTest((__int64)v11, v8, v5 + v7, v8, v7);
circleTest(v8, v7, v8, v7);
arcTest(v4 + v8, v5 + v7, v8);
textTest(v4 + v8, v7, v8);
plotend(v11);
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-D8h]
double v8; // [rsp+10h] [rbp-C8h]
double v9; // [rsp+20h] [rbp-B8h] BYREF
double v10; // [rsp+28h] [rbp-B0h] BYREF
char v11[168]; // [rsp+30h] [rbp-A8h] 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(v11, 144LL) < 0 )
{
fwrite("Failed to get plot information\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
getplotsize(&v9, &v10);
v4 = v9 * 0.5;
v5 = 0.5 * v10;
v8 = v9 * 0.25;
v7 = v10 * 0.25;
writedisplay("LIBTEST");
moveto(0.0);
lineto(v9, v5);
moveto(v4);
lineto(v4, v10);
func0((__int64)v11, v8, v5 + v7, v8, v7);
func1(v8, v7, v8, v7);
func2(v4 + v8, v5 + v7, v8);
func3(v4 + v8, v7, v8);
plotend(v11);
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: xc double

variable_types: yc double

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)
{
int i; // ebp
__int64 result; // rax
int j; // er13
double v8; // xmm3_8

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
result = moveto(a5);
if ( a1 > 0 )
{
for ( j = 0; j != a1; ++j )
{
v8 = (double)j * (a3 + a3 - (a4 + a4));
arc(a3 + v8 + a5);
result = arc(v8 + a5 + a3 + a3 - a4);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, double a3, double a4, double a5)
{
int i; // ebp
__int64 result; // rax
int j; // er13
double v8; // xmm3_8

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
result = moveto(a5);
if ( a1 > 0 )
{
for ( j = 0; j != a1; ++j )
{
v8 = (double)j * (a3 + a3 - (a4 + a4));
arc(a3 + v8 + a5);
result = arc(v8 + a5 + a3 + a3 - a4);
}
}
}
}
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: angle double

variable_types: ix int

variable_types: iy int

variable_types: y double

variable_types: pitch double

return_type: void


drawy

decompiled_code:
__int64 __fastcall drawy(int a1, int a2, double a3, double a4)
{
int v4; // ebp
double v5; // r14
__int64 result; // rax
int i; // er13

if ( a1 > 0 )
{
v4 = 0;
do
{
v5 = (double)++v4 * (a3 + a3 - (a4 + a4));
result = moveto(v5);
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
arc(v5);
result = arc(v5);
}
}
}
while ( v4 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, double a3, double a4)
{
int v4; // ebp
double v5; // r14
__int64 result; // rax
int i; // er13

if ( a1 > 0 )
{
v4 = 0;
do
{
v5 = (double)++v4 * (a3 + a3 - (a4 + a4));
result = moveto(v5);
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
arc(v5);
result = arc(v5);
}
}
}
while ( v4 != 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: argc int

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: i int

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)
{
}

variable_types: maxx double

variable_types: maxy double


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
char v5; // r14
double v6; // r15
int v7; // eax
double v8; // rbp
__int64 v9; // rax
double v10; // xmm1_8
double v11; // xmm5_8
int v12; // er15
double v13; // xmm0_8
int v14; // ebx
int v15; // er15
double v17; // [rsp+0h] [rbp-F8h]
double v18; // [rsp+0h] [rbp-F8h]
double v19; // [rsp+8h] [rbp-F0h]
double v20; // [rsp+10h] [rbp-E8h]
double v21; // [rsp+18h] [rbp-E0h]
double v22; // [rsp+18h] [rbp-E0h]
double v23; // [rsp+20h] [rbp-D8h]
double v24; // [rsp+28h] [rbp-D0h]
char v25[64]; // [rsp+30h] [rbp-C8h] BYREF
int v26; // [rsp+70h] [rbp-88h]
double v27; // [rsp+80h] [rbp-78h]
double v28; // [rsp+90h] [rbp-68h]
double v29; // [rsp+98h] [rbp-60h]
double v30; // [rsp+B0h] [rbp-48h]
double v31; // [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 )
goto LABEL_6;
}
else if ( v7 > 113 )
{
if ( v7 != 115 )
{
LABEL_6:
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 <= 109 )
{
goto LABEL_6;
}
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(v25, 144LL) < 0 )
{
fwrite("Failed to get plot information\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
v8 = v30;
v9 = (unsigned int)(v26 - 3);
v19 = v31;
if ( (unsigned int)v9 <= 3 )
{
v4 = CSWTCH_8[v9];
v3 = CSWTCH_9[v9];
v5 = v26 & 1;
v6 = CSWTCH_10[v9];
v17 = CSWTCH_11[v9];
}
v20 = (v6 - v28) * 0.5;
v23 = (v17 - v29) * 0.5;
v10 = v27;
v11 = v17 * v27;
v18 = v6 * v27 / (double)v4;
v24 = v11 / (double)v3;
if ( v4 > 1 )
{
v12 = 1;
while ( 1 )
{
v13 = (double)v12++ * v18;
v21 = v13 - v10 * v20;
moveto(v21);
lineto(v21, v19);
if ( v4 == v12 )
break;
v10 = v27;
}
}
if ( v3 > 1 )
{
v22 = v24 - v23 * v27;
moveto(0.0);
lineto(v8, v22);
}
v14 = 0;
do
{
v15 = 0;
do
{
if ( v5 )
postcard_port((double)v14 * v18 - v27 * v20, (double)v15 * v24 - v23 * v27, v18, v24, v8, v19);
++v15;
}
while ( v3 != v15 );
++v14;
}
while ( v4 != v14 );
plotend();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // er13
char v5; // r14
double v6; // r15
int v7; // eax
double v8; // rbp
__int64 v9; // rax
double v10; // xmm1_8
double v11; // xmm5_8
int v12; // er15
double v13; // xmm0_8
int v14; // ebx
int v15; // er15
double v17; // [rsp+0h] [rbp-F8h]
double v18; // [rsp+0h] [rbp-F8h]
double v19; // [rsp+8h] [rbp-F0h]
double v20; // [rsp+10h] [rbp-E8h]
double v21; // [rsp+18h] [rbp-E0h]
double v22; // [rsp+18h] [rbp-E0h]
double v23; // [rsp+20h] [rbp-D8h]
double v24; // [rsp+28h] [rbp-D0h]
char v25[64]; // [rsp+30h] [rbp-C8h] BYREF
int v26; // [rsp+70h] [rbp-88h]
double v27; // [rsp+80h] [rbp-78h]
double v28; // [rsp+90h] [rbp-68h]
double v29; // [rsp+98h] [rbp-60h]
double v30; // [rsp+B0h] [rbp-48h]
double v31; // [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 )
goto LABEL_6;
}
else if ( v7 > 113 )
{
if ( v7 != 115 )
{
LABEL_6:
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 <= 109 )
{
goto LABEL_6;
}
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(v25, 144LL) < 0 )
{
fwrite("Failed to get plot information\n", 1uLL, 0x1FuLL, stderr);
exit(1);
}
v8 = v30;
v9 = (unsigned int)(v26 - 3);
v19 = v31;
if ( (unsigned int)v9 <= 3 )
{
v4 = CSWTCH_8[v9];
v3 = CSWTCH_9[v9];
v5 = v26 & 1;
v6 = CSWTCH_10[v9];
v17 = CSWTCH_11[v9];
}
v20 = (v6 - v28) * 0.5;
v23 = (v17 - v29) * 0.5;
v10 = v27;
v11 = v17 * v27;
v18 = v6 * v27 / (double)v4;
v24 = v11 / (double)v3;
if ( v4 > 1 )
{
v12 = 1;
while ( 1 )
{
v13 = (double)v12++ * v18;
v21 = v13 - v10 * v20;
moveto(v21);
lineto(v21, v19);
if ( v4 == v12 )
break;
v10 = v27;
}
}
if ( v3 > 1 )
{
v22 = v24 - v23 * v27;
moveto(0.0);
lineto(v8, v22);
}
v14 = 0;
do
{
v15 = 0;
do
{
if ( v5 )
func0((double)v14 * v18 - v27 * v20, (double)v15 * v24 - v23 * v27, v18, v24, v8, v19);
++v15;
}
while ( v3 != v15 );
++v14;
}
while ( v4 != v14 );
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:
argv
char *[]

variable_types: opt int

variable_types: j int

variable_types: dx double

variable_types: dy double

variable_types: nx int

variable_types: trueWidthmm double

variable_types: trueHeightmm double

variable_types: borderx double

variable_types: bordery 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; }


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

v4 = a3 / 5.0;
circle(a1, a2, a3 / 5.0 * 1.414213562373095);
circle(a1, a2, v4 + v4);
circle(a1 - v4, a2, v4);
circle(a1, a2 + v4, 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+18h] [rbp-10h]

v4 = a3 / 5.0;
circle(a1, a2, a3 / 5.0 * 1.414213562373095);
circle(a1, a2, v4 + v4);
circle(a1 - v4, a2, v4);
circle(a1, a2 + v4, 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: ht double

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

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: n int

variable_types: interior double

variable_types: delta double

variable_types: i int

variable_types: y double


rotate

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

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

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

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

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: 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 v5; // ebx
double v6; // xmm1_8
double v7; // xmm2_8
double v8; // xmm0_8
__int64 result; // rax
double i; // [rsp+8h] [rbp-50h]
double cosx; // [rsp+40h] [rbp-18h] BYREF
double sinx[2]; // [rsp+48h] [rbp-10h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3, double a4, double a5)
{
int v5; // ebx
double v6; // xmm1_8
double v7; // xmm2_8
double v8; // xmm0_8
__int64 result; // rax
double i; // [rsp+8h] [rbp-50h]
double cosx; // [rsp+40h] [rbp-18h] BYREF
double sinx[2]; // [rsp+48h] [rbp-10h] BYREF

v5 = 1;
moveto(a1 + a3 + a4);
v6 = *(double *)&LC1;
v7 = (double)1;
for ( i = *(double *)&LC0; ; i = cosx )
{
++v5;
v8 = cos(v7 * 0.0174532925199433 * a5);
result = lineto((v8 * a4 + a3) * i + a1, v6 * (v8 * a4 + a3) + a2);
if ( v5 == 361 )
break;
sincos(0.0174532925199433 * (double)v5, sinx, &cosx);
v6 = sinx[0];
v7 = (double)v5;
}
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: i int

variable_types: y double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
double v5; // r12
double v6; // rbp
double v7; // xmm2_8
double v8; // r14
double v9; // xmm4_8
double v11; // [rsp+10h] [rbp-38h] BYREF
double v12[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);
}
v4 = 0;
getplotsize(&v11, v12);
v5 = v11 * 0.5;
v6 = 0.5 * v12[0];
moveto(0.0);
lineto(v11, v6);
moveto(v5);
lineto(v5, v12[0]);
v7 = 0.25 * v12[0];
v8 = 0.25 * v12[0] / 3.0;
do
{
pencolr(v4 & 3);
v9 = (double)v4++;
drawlobes(v5, v6, v7, v8, v9);
}
while ( v4 != 9 );
plotend(v5, v6, v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
double v5; // r12
double v6; // rbp
double v7; // xmm2_8
double v8; // r14
double v9; // xmm4_8
double v11; // [rsp+10h] [rbp-38h] BYREF
double v12[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);
}
v4 = 0;
getplotsize(&v11, v12);
v5 = v11 * 0.5;
v6 = 0.5 * v12[0];
moveto(0.0);
lineto(v11, v6);
moveto(v5);
lineto(v5, v12[0]);
v7 = 0.25 * v12[0];
v8 = 0.25 * v12[0] / 3.0;
do
{
pencolr(v4 & 3);
v9 = (double)v4++;
func0(v5, v6, v7, v8, v9);
}
while ( v4 != 9 );
plotend(v5, v6, v7);
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 v5; // xmm2_8
int v6; // ebp
double v7; // xmm3_8
__int64 result; // rax
double v9; // [rsp+0h] [rbp-58h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx[6]; // [rsp+28h] [rbp-30h] BYREF

v5 = a4 * 0.25;
v9 = 6.283185307179586 / (double)a1;
if ( a1 > 0 )
{
v6 = 0;
do
{
v7 = (double)v6++ * v9;
sincos(v7, sinx, &cosx);
moveto(a2 + a4 * cosx, sinx[0] * a4 + a3);
sincos(v7 + 1.570796326794897, sinx, &cosx);
result = arc(a2 + v5 * cosx, sinx[0] * v5 + a3, 57.29577951308232 * (1.2 * v9));
}
while ( a1 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, double a2, double a3, double a4)
{
double v5; // xmm2_8
int v6; // ebp
double v7; // xmm3_8
__int64 result; // rax
double v9; // [rsp+0h] [rbp-58h]
double cosx; // [rsp+20h] [rbp-38h] BYREF
double sinx[6]; // [rsp+28h] [rbp-30h] BYREF

v5 = a4 * 0.25;
v9 = 6.283185307179586 / (double)a1;
if ( a1 > 0 )
{
v6 = 0;
do
{
v7 = (double)v6++ * v9;
sincos(v7, sinx, &cosx);
moveto(a2 + a4 * cosx, sinx[0] * a4 + a3);
sincos(v7 + 1.570796326794897, sinx, &cosx);
result = arc(a2 + v5 * cosx, sinx[0] * v5 + a3, 57.29577951308232 * (1.2 * v9));
}
while ( a1 != v6 );
}
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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
double v5; // rbp
int v6; // edi
double v8; // [rsp+0h] [rbp-38h]
double v9; // [rsp+8h] [rbp-30h]
double v10; // [rsp+8h] [rbp-30h]
double v11; // [rsp+10h] [rbp-28h] BYREF
double v12[4]; // [rsp+18h] [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(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
v4 = 0;
getplotsize(&v11, v12);
v9 = v12[0];
v5 = v11 * 0.5;
v8 = 0.5 * v12[0];
circle(v11 * 0.5, 0.5 * v12[0], 0.5 * v12[0]);
v10 = v9 / 24.0;
do
{
v6 = v4++;
ringoshapes(v6 + 16, v5, v8, (double)v4 * v10);
}
while ( v4 != 11 );
plotend(v5, v8);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int v4; // ebx
double v5; // rbp
int v6; // edi
double v8; // [rsp+0h] [rbp-38h]
double v9; // [rsp+8h] [rbp-30h]
double v10; // [rsp+8h] [rbp-30h]
double v11; // [rsp+10h] [rbp-28h] BYREF
double v12[4]; // [rsp+18h] [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(0LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
v4 = 0;
getplotsize(&v11, v12);
v9 = v12[0];
v5 = v11 * 0.5;
v8 = 0.5 * v12[0];
circle(v11 * 0.5, 0.5 * v12[0], 0.5 * v12[0]);
v10 = v9 / 24.0;
do
{
v6 = v4++;
func0(v6 + 16, v5, v8, (double)v4 * v10);
}
while ( v4 != 11 );
plotend(v5, v8);
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 []


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

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

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; // ebx
double v6; // xmm0_8
double v7; // xmm1_8
__int64 result; // rax
double v9; // xmm1_8
double v10; // xmm0_8
double v11; // xmm2_8
double v12; // xmm1_8
double v13; // [rsp+0h] [rbp-48h]
double v14; // [rsp+8h] [rbp-40h]
double cosx; // [rsp+30h] [rbp-18h] BYREF
double sinx[2]; // [rsp+38h] [rbp-10h] BYREF

v5 = 0;
sincos(a5, sinx, &cosx);
v6 = 0.0;
v7 = *(double *)&LC0;
v13 = cosx;
v14 = sinx[0];
while ( 1 )
{
v9 = v7 * a3;
++v5;
v10 = v6 * a4;
v11 = v13 * v9 - v14 * v10 + a1;
v12 = v9 * v14 + v10 * v13 + a2;
if ( v5 != 1 )
break;
moveto(v11, v12);
LABEL_3:
sincos((double)v5 * 0.08726646259971647, sinx, &cosx);
v7 = cosx;
v6 = sinx[0];
}
result = lineto(v11, v12);
if ( v5 != 37 )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1, double a2, double a3, double a4, double a5)
{
int v5; // ebx
double v6; // xmm0_8
double v7; // xmm1_8
__int64 result; // rax
double v9; // xmm1_8
double v10; // xmm0_8
double v11; // xmm2_8
double v12; // xmm1_8
double v13; // [rsp+0h] [rbp-48h]
double v14; // [rsp+8h] [rbp-40h]
double cosx; // [rsp+30h] [rbp-18h] BYREF
double sinx[2]; // [rsp+38h] [rbp-10h] BYREF

v5 = 0;
sincos(a5, sinx, &cosx);
v6 = 0.0;
v7 = *(double *)&LC0;
v13 = cosx;
v14 = sinx[0];
while ( 1 )
{
v9 = v7 * a3;
++v5;
v10 = v6 * a4;
v11 = v13 * v9 - v14 * v10 + a1;
v12 = v9 * v14 + v10 * v13 + a2;
if ( v5 != 1 )
break;
moveto(v11, v12);
LABEL_3:
sincos((double)v5 * 0.08726646259971647, sinx, &cosx);
v7 = cosx;
v6 = sinx[0];
}
result = lineto(v11, v12);
if ( v5 != 37 )
goto LABEL_3;
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; // ebx
double v7; // xmm3_8
double v8; // r14
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm2_8
double v12; // xmm0_8
double v13; // xmm1_8
double v14; // xmm2_8
double v15; // xmm1_8
__int64 result; // rax
double x; // [rsp+8h] [rbp-60h]
double v19; // [rsp+10h] [rbp-58h]
double v20; // [rsp+18h] [rbp-50h]
double cosx; // [rsp+40h] [rbp-28h] BYREF
double sinx[4]; // [rsp+48h] [rbp-20h] BYREF

v6 = 0;
sincos(a5, sinx, &cosx);
v7 = *(double *)&LC0;
v8 = 2.0 / a6;
v9 = 0.0;
v19 = cosx;
v20 = sinx[0];
while ( 1 )
{
if ( v9 >= 0.0 )
{
x = pow(v9, v8);
if ( v7 >= 0.0 )
goto LABEL_3;
}
else
{
*(_QWORD *)&x = COERCE_UNSIGNED_INT64(pow(COERCE_DOUBLE(*(_QWORD *)&v9 ^ LC4), v8)) ^ LC4;
if ( v7 >= 0.0 )
{
LABEL_3:
v10 = pow(v7, v8);
v11 = x;
goto LABEL_4;
}
}
v11 = x;
*(_QWORD *)&v10 = COERCE_UNSIGNED_INT64(pow(COERCE_DOUBLE(*(_QWORD *)&v7 ^ LC4), v8)) ^ LC4;
LABEL_4:
v12 = v10 * a3;
++v6;
v13 = a4 * v11;
v14 = v19 * v12 - v20 * (a4 * v11) + a1;
v15 = v13 * v19 + v12 * v20 + a2;
if ( v6 != 1 )
break;
moveto(v14, v15);
LABEL_6:
sincos((double)v6 * 0.08726646259971647, sinx, &cosx);
v7 = cosx;
v9 = sinx[0];
}
result = lineto(v14, v15);
if ( v6 != 37 )
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; // ebx
double v7; // xmm3_8
double v8; // r14
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm2_8
double v12; // xmm0_8
double v13; // xmm1_8
double v14; // xmm2_8
double v15; // xmm1_8
__int64 result; // rax
double x; // [rsp+8h] [rbp-60h]
double v19; // [rsp+10h] [rbp-58h]
double v20; // [rsp+18h] [rbp-50h]
double cosx; // [rsp+40h] [rbp-28h] BYREF
double sinx[4]; // [rsp+48h] [rbp-20h] BYREF

v6 = 0;
sincos(a5, sinx, &cosx);
v7 = *(double *)&LC0;
v8 = 2.0 / a6;
v9 = 0.0;
v19 = cosx;
v20 = sinx[0];
while ( 1 )
{
if ( v9 >= 0.0 )
{
x = pow(v9, v8);
if ( v7 >= 0.0 )
goto LABEL_3;
}
else
{
*(_QWORD *)&x = COERCE_UNSIGNED_INT64(pow(COERCE_DOUBLE(*(_QWORD *)&v9 ^ LC4), v8)) ^ LC4;
if ( v7 >= 0.0 )
{
LABEL_3:
v10 = pow(v7, v8);
v11 = x;
goto LABEL_4;
}
}
v11 = x;
*(_QWORD *)&v10 = COERCE_UNSIGNED_INT64(pow(COERCE_DOUBLE(*(_QWORD *)&v7 ^ LC4), v8)) ^ LC4;
LABEL_4:
v12 = v10 * a3;
++v6;
v13 = a4 * v11;
v14 = v19 * v12 - v20 * (a4 * v11) + a1;
v15 = v13 * v19 + v12 * v20 + a2;
if ( v6 != 1 )
break;
moveto(v14, v15);
LABEL_6:
sincos((double)v6 * 0.08726646259971647, sinx, &cosx);
v7 = cosx;
v9 = sinx[0];
}
result = lineto(v14, v15);
if ( v6 != 37 )
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 v5; // ebp
double v6; // xmm0_8
__int64 result; // rax
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 v13; // [rsp+40h] [rbp-38h]
double cosx; // [rsp+50h] [rbp-28h] BYREF
double sinx[4]; // [rsp+58h] [rbp-20h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func3(int a1, double a2, double a3, double a4, double a5)
{
int v5; // ebp
double v6; // xmm0_8
__int64 result; // rax
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 v13; // [rsp+40h] [rbp-38h]
double cosx; // [rsp+50h] [rbp-28h] BYREF
double sinx[4]; // [rsp+58h] [rbp-20h] BYREF

v11 = 6.283185307179586 / (double)a1;
if ( a1 > 0 )
{
v5 = 0;
do
{
v6 = (double)v5++ * v11;
sincos(v6 + a5, sinx, &cosx);
v9 = cosx * a4;
v10 = sinx[0] * a4;
sincos(v6 + a5 + v11, sinx, &cosx);
v13 = cosx;
v12 = sinx[0];
moveto(a2, a3);
lineto((v9 + v13 * a4) * 0.5 + a2, (v10 + v12 * a4) * 0.5 + a3);
result = arc(
v9 + a2,
v10 + a3,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(57.29577951308232 * (6.283185307179586 / (double)a1) + 180.0) ^ LC4));
}
while ( a1 != v5 );
}
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(&v5, v6);
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(&v5, v6);
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

v1 = 5;
turn(120.0);
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

v1 = 4;
turn(108.0);
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
unsigned int v5; // eax
bool v6; // cc
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2, __int64 a3, int a4)
{
char v4; // bl
unsigned int v5; // eax
bool v6; // cc
__int64 result; // rax

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

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;
   }
}


title

decompiled_code:
int __fastcall title(char *s, char a2, char a3, double a4)
{
unsigned int v4; // ebp
int result; // eax
int v6; // eax
unsigned int v8; // er13
unsigned __int64 v9; // r15
int v10; // eax
int v11; // edx
double v12; // r14

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

canonical_decompiled_code:
int __fastcall func11(char *s, char a2, char a3, double a4)
{
unsigned int v4; // ebp
int result; // eax
int v6; // eax
unsigned int v8; // er13
unsigned __int64 v9; // r15
int v10; // eax
int v11; // edx
double v12; // r14

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

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

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

variable_types:
str
char []

variable_types: size double

variable_types: posn int

variable_types: x int

variable_types: y int

variable_types: xc double

variable_types: yc double

variable_types: len int


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

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

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

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

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

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


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

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

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

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

variable_types: deg double


forward

decompiled_code:
int __fastcall forward(double a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax
__int64 v7; // rdx
__int64 v8; // rsi

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

canonical_decompiled_code:
int __fastcall func14(double a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
double v3; // xmm0_8
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax
__int64 v7; // rdx
__int64 v8; // rsi

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

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

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

variable_types: mm double

variable_types: newx double

variable_types: newy double


turn

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

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

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

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


pen

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

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

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

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

variable_types: flag int