isVectInCirc

decompiled_code:
__int64 __fastcall isVectInCirc(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
return isCircInCirc(a1, a2, a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6)
{
return isCircInCirc(a1, a2, a3, a4, a5, a6);
}

original_code:
_Bool isVectInCirc(vect_t vect, circ_t circExt){
    circ_t circInt = {
        .pos = vect,
        .r = 0
    };
    return isCircInCirc(circInt, circExt);
}

canonical_original_code:
_Bool isVectInCirc(struct vect_t vect, struct circ_t circExt){
    struct circ_t circInt = {
        .pos = vect,
        .r = 0
    };
    return isCircInCirc(circInt, circExt);
}

variable_types:
vect
struct vect_t { double x; double y; }

variable_types: struct circ_t { struct vect_t pos; double r; }

variable_types: struct circ_t { struct vect_t { double x; double y; } pos; double r; }


isVectInGameCirc

repo: amotta/StickyParticles

decompiled_code:
__int64 __fastcall isVectInGameCirc(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
__int64 v7; // [rsp+10h] [rbp-28h] BYREF

getGameCirc(&v7);
return isVectInCirc((__int64)&v7, a2, v2, v3, v4, v5);
}

original_code:
_Bool isVectInGameCirc(vect_t vect){
    return isVectInCirc(vect, getGameCirc());
}

canonical_original_code:
_Bool isVectInGameCirc(struct vect_t vect){
    return isVectInCirc(vect, getGameCirc());
}


isVectInRect

decompiled_code:
bool __fastcall isVectInRect(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
bool result; // al

if ( a1 <= a9 || a10 <= a1 || a2 <= a11 )
result = 0;
else
result = a12 > a2;
return result;
}

canonical_decompiled_code:
bool __fastcall func3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
bool result; // al

if ( a1 <= a9 || a10 <= a1 || a2 <= a11 )
result = 0;
else
result = a12 > a2;
return result;
}

original_code:
_Bool isVectInRect(vect_t vect, rect_t rect){
    if(
       rect.left < vect.x
       && vect.x < rect.right
       && rect.bottom < vect.y
       && vect.y < rect.top
    ){
        return 1;
    }else{
        return 0;
    }
}

canonical_original_code:
_Bool isVectInRect(struct vect_t vect, struct rect_t rect){
    if(
       rect.left < vect.x
       && vect.x < rect.right
       && rect.bottom < vect.y
       && vect.y < rect.top
    ){
        return 1;
    }else{
        return 0;
    }
}

variable_types: struct rect_t { double left; double right; double bottom; double top; }


isCircInRect

original_code:
_Bool isCircInRect(circ_t circ, rect_t rect){
    if(
       rect.right - rect.left < circ.r
       || rect.top - rect.bottom < circ.r
    ){
        return 0;
    }
    rect_t rectInt = {
        .left = rect.left + circ.r,
        .right = rect.right - circ.r,
        .bottom = rect.bottom + circ.r,
        .top = rect.top - circ.r
    };
    return isVectInRect(circ.pos, rectInt);
}

canonical_original_code:
_Bool isCircInRect(struct circ_t circ, struct rect_t rect){
    if(
       rect.right - rect.left < circ.r
       || rect.top - rect.bottom < circ.r
    ){
        return 0;
    }
    struct rect_t rectInt = {
        .left = rect.left + circ.r,
        .right = rect.right - circ.r,
        .bottom = rect.bottom + circ.r,
        .top = rect.top - circ.r
    };
    return isVectInRect(circ.pos, rectInt);
}

user_defined_types: struct circ_t { struct vect_t pos; double r; }

user_defined_types: struct rect_t { double left; double right; double bottom; double top; }


isCircInGameRect

original_code:
_Bool isCircInGameRect(circ_t circ){
    return isCircInRect(circ, getGameRect());
}

canonical_original_code:
_Bool isCircInGameRect(struct circ_t circ){
    return isCircInRect(circ, getGameRect());
}


isVectInGameRect

decompiled_code:
bool __fastcall isVectInGameRect(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm4_8
double v9; // xmm5_8
__int64 v12[5]; // [rsp+10h] [rbp-28h] BYREF

getGameRect(v12);
return isVectInRect(
a1,
a2,
a3,
a4,
v8,
v9,
a7,
a8,
*(double *)v12,
*(double *)&v12[1],
*(double *)&v12[2],
*(double *)&v12[3]);
}

canonical_decompiled_code:
bool __fastcall func7(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm4_8
double v9; // xmm5_8
__int64 v12[5]; // [rsp+10h] [rbp-28h] BYREF

getGameRect(v12);
return func3(
a1,
a2,
a3,
a4,
v8,
v9,
a7,
a8,
*(double *)v12,
*(double *)&v12[1],
*(double *)&v12[2],
*(double *)&v12[3]);
}

original_code:
_Bool isVectInGameRect(vect_t vect){
    return isVectInRect(vect, getGameRect());
}

canonical_original_code:
_Bool isVectInGameRect(struct vect_t vect){
    return isVectInRect(vect, getGameRect());
}


vectAdd

decompiled_code:
double __fastcall vectAdd(double a1, double a2, double a3)
{
return a1 + a3;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2, double a3)
{
return a1 + a3;
}

original_code:
vect_t vectAdd(vect_t vectOne, vect_t vectTwo){
    vect_t sum = {
        .x = vectOne.x + vectTwo.x,
        .y = vectOne.y + vectTwo.y
    };
    return sum;
}

canonical_original_code:
struct vect_t vectAdd(struct vect_t vectOne, struct vect_t vectTwo){
    struct vect_t sum = {
        .x = vectOne.x + vectTwo.x,
        .y = vectOne.y + vectTwo.y
    };
    return sum;
}

variable_types:
vectOne
struct vect_t

variable_types:
vectTwo
struct vect_t

variable_types:
sum
struct vect_t { double x; double y; }

return_type: struct vect_t { double x; double y; }


vectSub

decompiled_code:
__m128 __fastcall vectSub(double a1, double a2, __m128 a3)
{
*(double *)a3.m128_u64 = *(double *)a3.m128_u64 - a1;
return a3;
}

canonical_decompiled_code:
__m128 __fastcall func1(double a1, double a2, __m128 a3)
{
*(double *)a3.m128_u64 = *(double *)a3.m128_u64 - a1;
return a3;
}

original_code:
vect_t vectSub(vect_t vectOne, vect_t vectTwo){
    vect_t diff = {
        .x = vectTwo.x - vectOne.x,
        .y = vectTwo.y - vectOne.y
    };
    return diff;
}

canonical_original_code:
struct vect_t vectSub(struct vect_t vectOne, struct vect_t vectTwo){
    struct vect_t diff = {
        .x = vectTwo.x - vectOne.x,
        .y = vectTwo.y - vectOne.y
    };
    return diff;
}

variable_types:
diff
struct vect_t { double x; double y; }


vectScale

decompiled_code:
double __fastcall vectScale(double a1, double a2, double a3)
{
return a1 * a3;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2, double a3)
{
return a1 * a3;
}

original_code:
vect_t vectScale(vect_t vect, double factor){
    vect_t res = {
        .x = vect.x * factor,
        .y = vect.y * factor
    };
    return res;
}

canonical_original_code:
struct vect_t vectScale(struct vect_t vect, double factor){
    struct vect_t res = {
        .x = vect.x * factor,
        .y = vect.y * factor
    };
    return res;
}

variable_types:
vect
struct vect_t

variable_types: factor double

variable_types:
res
struct vect_t { double x; double y; }


vectLen

decompiled_code:
void __fastcall vectLen(double a1, double a2)
{
double v2; // xmm0_8

v2 = a1 * a1 + a2 * a2;
if ( v2 < 0.0 )
sqrt(v2);
}

canonical_decompiled_code:
void __fastcall func3(double a1, double a2)
{
double v2; // xmm0_8

v2 = a1 * a1 + a2 * a2;
if ( v2 < 0.0 )
sqrt(v2);
}

original_code:
double vectLen(vect_t vect){
    return sqrt(vect.x * vect.x + vect.y * vect.y);
}

canonical_original_code:
double vectLen(struct vect_t vect){
    return sqrt(vect.x * vect.x + vect.y * vect.y);
}

return_type: double


vectDist

decompiled_code:
void __fastcall vectDist(__m128 a1, double a2, double a3, double a4)
{
double v4; // xmm0_8

*(_QWORD *)&v4 = vectSub(a3, a4, a1).m128_u64[0];
vectLen(v4, a4);
}

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

*(_QWORD *)&v4 = func1(a3, a4, a1).m128_u64[0];
func3(v4, a4);
}

original_code:
double vectDist(vect_t start, vect_t end){
    return vectLen(vectSub(end, start));
}

canonical_original_code:
double vectDist(struct vect_t start, struct vect_t end){
    return vectLen(vectSub(end, start));
}

variable_types:
start
struct vect_t { double x; double y; }

variable_types:
end
struct vect_t


vectGetNull

decompiled_code:
double vectGetNull()
{
return 0.0;
}

canonical_decompiled_code:
double func5()
{
return 0.0;
}

original_code:
vect_t vectGetNull(){
    vect_t nullVect = {
        .x = 0,
        .y = 0
    };
    return nullVect;
}

canonical_original_code:
struct vect_t vectGetNull(){
    struct vect_t nullVect = {
        .x = 0,
        .y = 0
    };
    return nullVect;
}

variable_types:
nullVect
struct vect_t { double x; double y; }


getGameCenter

decompiled_code:
double getGameCenter()
{
return *(double *)&LC1;
}

canonical_decompiled_code:
double func6()
{
return *(double *)&LC1;
}

original_code:
vect_t getGameCenter(){
    vect_t gameCenter = {
        .x = 8.0 / 2,
        .y = 6.0 / 2
    };
    return gameCenter;
}

canonical_original_code:
struct vect_t getGameCenter(){
    struct vect_t gameCenter = {
        .x = 8.0 / 2,
        .y = 6.0 / 2
    };
    return gameCenter;
}

variable_types:
gameCenter
struct vect_t { double x; double y; }


gameUIHandleReshape

decompiled_code:
__int64 __fastcall gameUIHandleReshape(int a1, int a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // xmm1_8
double v6; // xmm0_8

v2 = (double)a1;
sizeX = a1;
v3 = (double)a2;
sizeY = a2;
if ( (double)a1 / (double)a2 <= 1.333333333333333 )
{
xMin = 0LL;
xMax = LC3;
v6 = (v3 / (v2 * 0.125) - 6.0) * 0.5;
*(double *)&yMin = 0.0 - v6;
*(double *)&yMax = v6 + 6.0;
}
else
{
yMin = 0LL;
yMax = LC2;
v4 = (v2 / (v3 / 6.0) - 8.0) * 0.5;
*(double *)&xMin = 0.0 - v4;
*(double *)&xMax = v4 + 8.0;
}
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(*(double *)&xMin, *(double *)&xMax, *(double *)&yMin, *(double *)&yMax, -1.0, 1.0);
glMatrixMode(5888LL);
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
double v4; // xmm1_8
double v6; // xmm0_8

v2 = (double)a1;
sizeX = a1;
v3 = (double)a2;
sizeY = a2;
if ( (double)a1 / (double)a2 <= 1.333333333333333 )
{
xMin = 0LL;
xMax = LC3;
v6 = (v3 / (v2 * 0.125) - 6.0) * 0.5;
*(double *)&yMin = 0.0 - v6;
*(double *)&yMax = v6 + 6.0;
}
else
{
yMin = 0LL;
yMax = LC2;
v4 = (v2 / (v3 / 6.0) - 8.0) * 0.5;
*(double *)&xMin = 0.0 - v4;
*(double *)&xMax = v4 + 8.0;
}
glViewport(0LL, 0LL, (unsigned int)a1, (unsigned int)a2);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(*(double *)&xMin, *(double *)&xMax, *(double *)&yMin, *(double *)&yMax, -1.0, 1.0);
glMatrixMode(5888LL);
return glutPostRedisplay();
}

original_code:
void gameUIHandleReshape(int x, int y){
    double aspectRatio;
    double pxPerUnit;
    double diff;
 sizeX = x;
 sizeY = y;
    aspectRatio = (double) sizeX / sizeY;
    if(aspectRatio > 8.0 / 6.0){
        yMin = 0;
        yMax = 6.0;
        pxPerUnit = sizeY / 6.0;
        diff = (sizeX / pxPerUnit - 8.0) / 2;
        xMin = 0 - diff;
        xMax = 8.0 + diff;
    }else{
        xMin = 0;
        xMax = 8.0;
        pxPerUnit = sizeX / 8.0;
        diff = (sizeY / pxPerUnit - 6.0) / 2;
        yMin = 0 - diff;
        yMax = 6.0 + diff;
    }
 glViewport(0, 0, sizeX, sizeY);
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(xMin, xMax, yMin, yMax, -1, +1);
 glMatrixMode(0x1700);
 glutPostRedisplay();
}

variable_types: x int

variable_types: y int

variable_types: aspectRatio double

variable_types: pxPerUnit double

variable_types: diff double

return_type: void


gameUIHandleMouse

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

if ( currentGame )
result = gameSetTarget(
currentGame,
(*(double *)&xMax - *(double *)&xMin) / (double)sizeX * (double)a1 + *(double *)&xMin,
*(double *)&yMax - (*(double *)&yMax - *(double *)&yMin) / (double)sizeY * (double)a2);
return result;
}

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

if ( currentGame )
result = gameSetTarget(
currentGame,
(*(double *)&xMax - *(double *)&xMin) / (double)sizeX * (double)a1 + *(double *)&xMin,
*(double *)&yMax - (*(double *)&yMax - *(double *)&yMin) / (double)sizeY * (double)a2);
return result;
}

original_code:
void gameUIHandleMouse(int x, int y){
    if(!currentGame) return;
    vect_t target = {
        .x = xMin + (xMax - xMin) / sizeX * x,
        .y = yMax - (yMax - yMin) / sizeY * y
    };
    gameSetTarget(currentGame, target);
}

canonical_original_code:
void gameUIHandleMouse(int x, int y){
    if(!currentGame) return;
    struct vect_t target = {
        .x = xMin + (xMax - xMin) / sizeX * x,
        .y = yMax - (yMax - yMin) / sizeY * y
    };
    gameSetTarget(currentGame, target);
}

variable_types:
target
struct vect_t { double x; double y; }


gameUIHandleRedraw

decompiled_code:
__int64 gameUIHandleRedraw()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(0x4000LL);
glLoadIdentity();
gameDraw(currentGame);
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func2()
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(0x4000LL);
glLoadIdentity();
gameDraw(currentGame);
return glutSwapBuffers();
}

original_code:
void gameUIHandleRedraw(){
    glClearColor(1, 1, 1, 0);
    glClear(0x00004000);
    glLoadIdentity();
    gameDraw(currentGame);
 glutSwapBuffers();
}


gameUIInit

decompiled_code:
__int64 gameUIInit()
{
sizeX = 600;
sizeY = 400;
glutInitWindowSize(600LL, 400LL);
glutInitWindowPosition(0LL, 0LL);
glutInitDisplayMode(2LL);
windowID = glutCreateWindow("Sticky Particles");
gameUIHandleRedraw((unsigned int)sizeX, (unsigned int)sizeY);
glutMotionFunc(gameUIHandleMouse);
glutPassiveMotionFunc(gameUIHandleMouse);
glutDisplayFunc(gameUIHandleRedraw);
return glutReshapeFunc(gameUIHandleReshape);
}

canonical_decompiled_code:
__int64 func3()
{
sizeX = 600;
sizeY = 400;
glutInitWindowSize(600LL, 400LL);
glutInitWindowPosition(0LL, 0LL);
glutInitDisplayMode(2LL);
windowID = glutCreateWindow("Sticky Particles");
func2((unsigned int)sizeX, (unsigned int)sizeY);
glutMotionFunc(gameUIHandleMouse);
glutPassiveMotionFunc(gameUIHandleMouse);
glutDisplayFunc(gameUIHandleRedraw);
return glutReshapeFunc(gameUIHandleReshape);
}

original_code:
void gameUIInit(){
 sizeX = 600;
 sizeY = 400;
 glutInitWindowSize(sizeX, sizeY);
 glutInitWindowPosition(0, 0);
 glutInitDisplayMode(0x0000 | 0x0002);
 windowID = glutCreateWindow("Sticky Particles");
 gameUIHandleRedraw(sizeX, sizeY);
    glutMotionFunc(gameUIHandleMouse);
    glutPassiveMotionFunc(gameUIHandleMouse);
 glutDisplayFunc(gameUIHandleRedraw);
 glutReshapeFunc(gameUIHandleReshape);
}


gameUIUpdate

decompiled_code:
__int64 gameUIUpdate()
{
glutSetWindow((unsigned int)windowID);
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func4()
{
glutSetWindow((unsigned int)windowID);
return glutPostRedisplay();
}

original_code:
void gameUIUpdate(){
    glutSetWindow(windowID);
    glutPostRedisplay();
}


gameUIGetWindow

decompiled_code:
__int64 gameUIGetWindow()
{
return (unsigned int)windowID;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)windowID;
}

original_code:
int gameUIGetWindow(){
 return windowID;
}

return_type: int


isCircInCirc

decompiled_code:
bool __fastcall isCircInCirc(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
bool result; // al

result = 0;
if ( a11 <= a14 )
result = a14 - a11 > vectDist(a12, a13, a9, a10);
return result;
}

canonical_decompiled_code:
bool __fastcall func0(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
bool result; // al

result = 0;
if ( a11 <= a14 )
result = a14 - a11 > vectDist(a12, a13, a9, a10);
return result;
}

original_code:
_Bool isCircInCirc(circ_t circInt, circ_t circExt){
    if(circInt.r > circExt.r){
        return 0;
    }
    if(vectDist(circExt.pos, circInt.pos) < circExt.r - circInt.r){
        return 1;
    }else{
        return 0;
    }
}

canonical_original_code:
_Bool isCircInCirc(struct circ_t circInt, struct circ_t circExt){
    if(circInt.r > circExt.r){
        return 0;
    }
    if(vectDist(circExt.pos, circInt.pos) < circExt.r - circInt.r){
        return 1;
    }else{
        return 0;
    }
}

variable_types: struct circ_t { struct vect_t { double x; double y; } pos; double r; }

variable_types:
circExt
struct circ_t


circCheckCirc

decompiled_code:
bool __fastcall circCheckCirc(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
bool result; // al

result = 0;
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a9 - a12) & LC0) <= a11 + a14
&& COERCE_DOUBLE(LC0 & COERCE_UNSIGNED_INT64(a10 - a13)) <= a11 + a14 )
{
result = vectDist(a9, a10, a12, a13) <= a11 + a14;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func1(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
bool result; // al

result = 0;
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a9 - a12) & LC0) <= a11 + a14
&& COERCE_DOUBLE(LC0 & COERCE_UNSIGNED_INT64(a10 - a13)) <= a11 + a14 )
{
result = vectDist(a9, a10, a12, a13) <= a11 + a14;
}
return result;
}

original_code:
_Bool circCheckCirc(circ_t circOne, circ_t circTwo){
    if(
       fabs(circOne.pos.x - circTwo.pos.x) > circOne.r + circTwo.r
       || fabs(circOne.pos.y - circTwo.pos.y) > circOne.r + circTwo.r
    ){
        return 0;
    }
    if(vectDist(circOne.pos, circTwo.pos) > circOne.r + circTwo.r){
        return 0;
    }else{
        return 1;
    }
}

canonical_original_code:
_Bool circCheckCirc(struct circ_t circOne, struct circ_t circTwo){
    if(
       fabs(circOne.pos.x - circTwo.pos.x) > circOne.r + circTwo.r
       || fabs(circOne.pos.y - circTwo.pos.y) > circOne.r + circTwo.r
    ){
        return 0;
    }
    if(vectDist(circOne.pos, circTwo.pos) > circOne.r + circTwo.r){
        return 0;
    }else{
        return 1;
    }
}

variable_types:
circTwo
struct circ_t


circCheckBorder

decompiled_code:
__int64 __fastcall circCheckBorder(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
__int64 result; // rax

result = 2 * (unsigned int)(a11 > a9);
if ( a9 > 8.0 - a11 )
result = (2 * (a11 > a9)) | 4u;
if ( a11 > a10 )
result = (unsigned int)result | 8;
if ( a10 > 6.0 - a11 )
result = (unsigned int)result | 0x10;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
__int64 result; // rax

result = 2 * (unsigned int)(a11 > a9);
if ( a9 > 8.0 - a11 )
result = (2 * (a11 > a9)) | 4u;
if ( a11 > a10 )
result = (unsigned int)result | 8;
if ( a10 > 6.0 - a11 )
result = (unsigned int)result | 0x10;
return result;
}

original_code:
int circCheckBorder(circ_t circ){
    int dir = (0);
    if(circ.pos.x < circ.r){
        dir |= (1 << 1);
    }
    if(circ.pos.x > 8.0 - circ.r){
        dir |= (1 << 2);
    }
    if(circ.pos.y < circ.r){
        dir |= (1 << 3);
    }
    if(circ.pos.y > 6.0 - circ.r){
        dir |= (1 << 4);
    }
    return dir;
}

canonical_original_code:
int circCheckBorder(struct circ_t circ){
    int dir = (0);
    if(circ.pos.x < circ.r){
        dir |= (1 << 1);
    }
    if(circ.pos.x > 8.0 - circ.r){
        dir |= (1 << 2);
    }
    if(circ.pos.y < circ.r){
        dir |= (1 << 3);
    }
    if(circ.pos.y > 6.0 - circ.r){
        dir |= (1 << 4);
    }
    return dir;
}

variable_types: dir int


circGetNull

decompiled_code:
__int64 __fastcall circGetNull(__int64 a1, double a2, double a3)
{
double v3; // xmm0_8
__int64 result; // rax

v3 = vectGetNull();
result = a1;
*(_QWORD *)(a1 + 16) = 0LL;
*(double *)a1 = v3;
*(double *)(a1 + 8) = a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, double a2, double a3)
{
double v3; // xmm0_8
__int64 result; // rax

v3 = vectGetNull();
result = a1;
*(_QWORD *)(a1 + 16) = 0LL;
*(double *)a1 = v3;
*(double *)(a1 + 8) = a3;
return result;
}

original_code:
circ_t circGetNull(){
    circ_t nullCirc = {
        .pos = vectGetNull(),
        .r = 0
    };
    return nullCirc;
}

canonical_original_code:
struct circ_t circGetNull(){
    struct circ_t nullCirc = {
        .pos = vectGetNull(),
        .r = 0
    };
    return nullCirc;
}

return_type: struct circ_t { struct vect_t { double x; double y; } pos; double r; }


getGameCirc

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

*(double *)a1 = getGameCenter();
*(_QWORD *)(a1 + 16) = LC4;
result = a1;
*(double *)(a1 + 8) = a3;
return result;
}

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

*(double *)a1 = getGameCenter();
*(_QWORD *)(a1 + 16) = LC4;
result = a1;
*(double *)(a1 + 8) = a3;
return result;
}

original_code:
circ_t getGameCirc(){
    circ_t gameCirc = {
        .pos = getGameCenter(),
        .r = 6.0 / 2
    };
    return gameCirc;
}

canonical_original_code:
struct circ_t getGameCirc(){
    struct circ_t gameCirc = {
        .pos = getGameCenter(),
        .r = 6.0 / 2
    };
    return gameCirc;
}


isCircInGameCirc

decompiled_code:
bool __fastcall isCircInGameCirc(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v17; // xmm4_8
double v18; // xmm5_8
__int64 v20[5]; // [rsp+0h] [rbp-28h] BYREF

getGameCirc((__int64)v20, a1, a2);
return isCircInCirc(
a1,
a2,
a3,
a4,
v17,
v18,
a7,
a8,
a9,
a10,
a11,
*(double *)v20,
*(double *)&v20[1],
*(double *)&v20[2]);
}

canonical_decompiled_code:
bool __fastcall func6(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v17; // xmm4_8
double v18; // xmm5_8
__int64 v20[5]; // [rsp+0h] [rbp-28h] BYREF

func5((__int64)v20, a1, a2);
return func0(
a1,
a2,
a3,
a4,
v17,
v18,
a7,
a8,
a9,
a10,
a11,
*(double *)v20,
*(double *)&v20[1],
*(double *)&v20[2]);
}

original_code:
_Bool isCircInGameCirc(circ_t circ){
    return isCircInCirc(circ, getGameCirc());
}

canonical_original_code:
_Bool isCircInGameCirc(struct circ_t circ){
    return isCircInCirc(circ, getGameCirc());
}


gameDrawBackground

decompiled_code:
__int64 gameDrawBackground()
{
__int64 v1; // [rsp+0h] [rbp-48h] BYREF
__int64 v2; // [rsp+20h] [rbp-28h] BYREF

gfxColor(1.0, 1.0, 1.0);
gfxClear();
gfxColor(0.0, 0.0, 0.0);
getGameRect(&v2);
gfxRect(0LL);
gfxColor(0.0, 0.0, 0.0);
getGameCirc(&v1);
return gfxCirc(0LL);
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v1; // [rsp+0h] [rbp-48h] BYREF
__int64 v2; // [rsp+20h] [rbp-28h] BYREF

gfxColor(1.0, 1.0, 1.0);
gfxClear();
gfxColor(0.0, 0.0, 0.0);
getGameRect(&v2);
gfxRect(0LL);
gfxColor(0.0, 0.0, 0.0);
getGameCirc(&v1);
return gfxCirc(0LL);
}

original_code:
void gameDrawBackground(){
    gfxColor(1, 1, 1);
    gfxClear();
    gfxColor(0, 0, 0);
    gfxRect(getGameRect(), 0);
    gfxColor(0, 0, 0);
    gfxCirc(getGameCirc(), 0);
}


main

canonical_name: main

repo: amoweb/RaspberryBoucle

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
__int64 v4; // rbx
_QWORD *v5; // rbp
int v6; // er14
int v7; // er12
_QWORD *v8; // rdi

puts("Boucle Midi - amoweb.fr");
IHMinit("Boucle Midi - amoweb.fr", argv);
if ( (unsigned __int8)midiInit() )
exit(-1);
midiOpenDevice(3LL, 2LL);
while ( 1 )
{
LABEL_4:
v3 = 0;
v4 = 0LL;
do
{
while ( (unsigned __int8)inputAvailable() )
{
midiReadLast((char *)&record + 24 * (v3 % 0x3E8));
if ( !(_DWORD)v4 )
{
v4 = *((int *)&record + 6 * (v3 % 0x3E8) + 4);
puts("Recording");
}
++v3;
if ( (unsigned __int8)IHMuserEntry() )
{
printf("Recorded=%d t=%ld\n", v3, qword_4040F0[3 * (v3 % 0x3E8)] - v4);
while ( 1 )
{
LABEL_8:
v5 = &record;
v6 = 0;
puts("Playing\r");
v7 = Pt_Time();
do
{
while ( (int)(Pt_Time() - v7) < v5[2] - v4 )
{
if ( (unsigned __int8)IHMuserEntry() )
goto LABEL_4;
midiFlush();
}
v8 = v5;
v6 += 2;
v5 += 6;
midiWrite(v8);
}
while ( v6 < (int)v3 );
}
}
}
}
while ( !(unsigned __int8)IHMuserEntry() );
printf("Recorded=%d t=%ld\n", v3, qword_4040F0[3 * (v3 % 0x3E8)] - v4);
if ( v3 )
goto LABEL_8;
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
__int64 v4; // rbx
_QWORD *v5; // rbp
int v6; // er14
int v7; // er12
_QWORD *v8; // rdi

puts("Boucle Midi - amoweb.fr");
func15("Boucle Midi - amoweb.fr", argv);
if ( (unsigned __int8)func7() )
exit(-1);
func8(3LL, 2LL);
while ( 1 )
{
LABEL_4:
v3 = 0;
v4 = 0LL;
do
{
while ( (unsigned __int8)func9() )
{
func13((char *)&record + 24 * (v3 % 0x3E8));
if ( !(_DWORD)v4 )
{
v4 = *((int *)&record + 6 * (v3 % 0x3E8) + 4);
puts("Recording");
}
++v3;
if ( (unsigned __int8)func16() )
{
printf("Recorded=%d t=%ld\n", v3, qword_4040F0[3 * (v3 % 0x3E8)] - v4);
while ( 1 )
{
LABEL_8:
v5 = &record;
v6 = 0;
puts("Playing\r");
v7 = Pt_Time();
do
{
while ( (int)(Pt_Time() - v7) < v5[2] - v4 )
{
if ( (unsigned __int8)func16() )
goto LABEL_4;
func14();
}
v8 = v5;
v6 += 2;
v5 += 6;
func11(v8);
}
while ( v6 < (int)v3 );
}
}
}
}
while ( !(unsigned __int8)func16() );
printf("Recorded=%d t=%ld\n", v3, qword_4040F0[3 * (v3 % 0x3E8)] - v4);
if ( v3 )
goto LABEL_8;
}
}

original_code:
int main()
{
        printf("Boucle Midi - amoweb.fr\n");
        IHMinit();
        if(midiInit())
                exit(-1);
        midiOpenDevice(3, 2);
beginRecord:
        while(1) {
                int tStartRecord = 0;
                int pos = 0;
                while(1) {
                        if(inputAvailable()) {
                                midiReadLast(&(record[pos%1000]));
                                if(tStartRecord == 0) {
                                        tStartRecord = record[pos%1000].t;
                                        printf("Recording\n");
                                }
                                pos++;
                        }
                        if(IHMuserEntry()){
                                break;
                        }
                }
                printf("Recorded=%d t=%ld\n", pos, record[pos%1000].t-tStartRecord);
                while(1) {
                        if(pos == 0)
                                goto beginRecord;
                        printf("Playing\r\n");
                        int tStartPlay = Pt_Time(((void *)0));
                        for(int i=0; i<pos; i++) {
                                while(Pt_Time(((void *)0))-tStartPlay < record[i].t-tStartRecord) {
                                        if(IHMuserEntry())
                                                goto beginRecord;
                                        midiFlush();
                                }
                                midiWrite(&record[i]);
                                i++;
                        }
                }
                pos = 0;
                midiFlush();
        }
}

canonical_original_code:
int main()
{
        printf("Boucle Midi - amoweb.fr\n");
        IHMinit();
        if(midiInit())
                exit(-1);
        midiOpenDevice(3, 2);
beginRecord:
        while(1) {
                int tStartRecord = 0;
                int pos = 0;
                while(1) {
                        if(inputAvailable()) {
                                midiReadLast(&(record[pos%1000]));
                                if(tStartRecord == 0) {
                                        tStartRecord = record[pos%1000].t;
                                        printf("Recording\n");
                                }
                                pos++;
                        }
                        if(IHMuserEntry()){
                                break;
                        }
                }
                printf("Recorded=%d t=%ld\n", pos, record[pos%1000].t-tStartRecord);
                while(1) {
                        if(pos == 0)
                                goto beginRecord;
                        printf("Playing\r\n");
                        int tStartPlay = Pt_Time(((void *)0));
                        for(int i = 0; i<pos; i++) {
                                while(Pt_Time(((void *)0))-tStartPlay < record[i].t-tStartRecord) {
                                        if(IHMuserEntry())
                                                goto beginRecord;
                                        midiFlush();
                                }
                                midiWrite(&record[i]);
                                i++;
                        }
                }
                pos = 0;
                midiFlush();
        }
}

variable_types: tStartRecord int

variable_types: pos int

variable_types: tStartPlay int

variable_types: i int


midiInit

decompiled_code:
__int64 midiInit()
{
int v0; // er13
unsigned int v1; // er12
int v2; // ebp
__int64 v3; // rax
__int64 v4; // rbx

v0 = -1;
v1 = -1;
v2 = 0;
Pm_Initialize();
nbEventWaiting = 0;
iEventWaiting = 0;
while ( (int)Pm_CountDevices() > v2 )
{
v3 = Pm_GetDeviceInfo();
v4 = v3;
if ( *(_QWORD *)(v3 + 24) )
{
printf("%d: %s, %s", (unsigned int)v2, *(const char **)(v3 + 8), *(const char **)(v3 + 16));
if ( *(_DWORD *)(v4 + 24) )
{
v1 = v2;
printf(" (input)");
}
if ( *(_DWORD *)(v4 + 28) )
{
v0 = v2;
printf(" (output)");
}
putchar(10);
}
++v2;
}
LOBYTE(v1) = v0 == -1 || v1 == -1;
if ( (_BYTE)v1 )
puts("Midi port not found.\r");
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // er13
unsigned int v1; // er12
int v2; // ebp
__int64 v3; // rax
__int64 v4; // rbx

v0 = -1;
v1 = -1;
v2 = 0;
Pm_Initialize();
nbEventWaiting = 0;
iEventWaiting = 0;
while ( (int)Pm_CountDevices() > v2 )
{
v3 = Pm_GetDeviceInfo();
v4 = v3;
if ( *(_QWORD *)(v3 + 24) )
{
printf("%d: %s, %s", (unsigned int)v2, *(const char **)(v3 + 8), *(const char **)(v3 + 16));
if ( *(_DWORD *)(v4 + 24) )
{
v1 = v2;
printf(" (input)");
}
if ( *(_DWORD *)(v4 + 28) )
{
v0 = v2;
printf(" (output)");
}
putchar(10);
}
++v2;
}
LOBYTE(v1) = v0 == -1 || v1 == -1;
if ( (_BYTE)v1 )
puts("Midi port not found.\r");
return v1;
}

original_code:
_Bool midiInit()
{
        Pm_Initialize();
        nbEventWaiting = 0;
        iEventWaiting = 0;
        int portIn = -1;
        int portOut = -1;
        for (int i = 0; i < Pm_CountDevices(); i++) {
                const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
                if ((info->input) || (info->output)) {
                        printf("%d: %s, %s", i, info->interf, info->name);
                        if (info->input) {
                                portIn = i;
                                printf(" (input)");
                        }
                        if (info->output) {
                                portOut = i;
                                printf(" (output)");
                        }
                        printf("\n");
                }
        }
        if(portOut == -1 || portIn == -1) {
                printf("Midi port not found.\r\n");
                return -1;
        }
        return 0;
}

canonical_original_code:
_Bool midiInit()
{
        Pm_Initialize();
        nbEventWaiting = 0;
        iEventWaiting = 0;
        int portIn = -1;
        int portOut = -1;
        for (int i = 0; i < Pm_CountDevices(); i++) {
                struct PmDeviceInfo *info = Pm_GetDeviceInfo(i);
                if ((info->input) || (info->output)) {
                        printf("%d: %s, %s", i, info->interf, info->name);
                        if (info->input) {
                                portIn = i;
                                printf(" (input)");
                        }
                        if (info->output) {
                                portOut = i;
                                printf(" (output)");
                        }
                        printf("\n");
                }
        }
        if(portOut == -1 || portIn == -1) {
                printf("Midi port not found.\r\n");
                return -1;
        }
        return 0;
}

variable_types: portIn int

variable_types: portOut int

variable_types: struct PmDeviceInfo { int structVersion; char *interf; char *name; int input; int output; int opened; } *


midiOpenDevice

decompiled_code:
__int64 midiOpenDevice()
{
Pt_Start();
Pm_OpenInput();
Pm_SetFilter();
return Pm_OpenOutput();
}

canonical_decompiled_code:
__int64 func8()
{
Pt_Start();
Pm_OpenInput();
Pm_SetFilter();
return Pm_OpenOutput();
}

original_code:
void midiOpenDevice(int inId, int outId)
{
        Pt_Start(1, ((void *)0), ((void *)0));
        Pm_OpenInput(&in, inId, ((void *)0), 1000,
                        (PmTimestamp (*)(void *)) Pt_Time, ((void *)0));
        Pm_SetFilter(in, (1 << 0x0E) | (1 << 0x08));
        Pm_OpenOutput(&out, outId, ((void *)0), 1000,
                        (PmTimestamp (*)(void *)) Pt_Time, ((void *)0), 0);
}

canonical_original_code:
void midiOpenDevice(int inId, int outId)
{
        Pt_Start(1, ((void *)0), ((void *)0));
        Pm_OpenInput(&in, inId, ((void *)0), 1000,
                        (int (*)(void *)) Pt_Time, ((void *)0));
        Pm_SetFilter(in, (1 << 0x0E) | (1 << 0x08));
        Pm_OpenOutput(&out, outId, ((void *)0), 1000,
                        (int (*)(void *)) Pt_Time, ((void *)0), 0);
}

variable_types: inId int

variable_types: outId int


inputAvailable

decompiled_code:
__int64 inputAvailable()
{
int v0; // er8
__int64 result; // rax

v0 = Pm_Poll();
result = 1LL;
if ( v0 != 1 && nbEventWaiting <= 0 )
{
Pm_Poll();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // er8
__int64 result; // rax

v0 = Pm_Poll();
result = 1LL;
if ( v0 != 1 && nbEventWaiting <= 0 )
{
Pm_Poll();
result = 0LL;
}
return result;
}

original_code:
_Bool inputAvailable()
{
        if(Pm_Poll(in) == 1 || nbEventWaiting > 0)
                return 1;
        else if(Pm_Poll(in) == 0)
                return 0;
        return 0;
}


midiNoteOn

decompiled_code:
__int64 __fastcall midiNoteOn(__int16 a1, int a2)
{
int v2; // ebx
int v3; // eax

v2 = (unsigned __int16)(a1 << 8) | (a2 << 16) & 0xFF0000;
v3 = Pt_Time();
LOBYTE(v2) = -112;
outBuffer = v2;
dword_40BE04 = v3;
return Pm_Write();
}

canonical_decompiled_code:
__int64 __fastcall func10(__int16 a1, int a2)
{
int v2; // ebx
int v3; // eax

v2 = (unsigned __int16)(a1 << 8) | (a2 << 16) & 0xFF0000;
v3 = Pt_Time();
LOBYTE(v2) = -112;
outBuffer = v2;
dword_40BE04 = v3;
return Pm_Write();
}

original_code:
void midiNoteOn(int note, int vol)
{
        outBuffer[0].timestamp = Pt_Time(((void *)0));
        outBuffer[0].message = ((((vol) << 16) & 0xFF0000) | (((note) << 8) & 0xFF00) | ((0x90) & 0xFF));
        Pm_Write(out, outBuffer, 1);
}

variable_types: note int

variable_types: vol int


midiWrite

decompiled_code:
__int64 __fastcall midiWrite(int *a1)
{
int v1; // eax
int v2; // edx

v1 = Pt_Time();
v2 = *a1;
dword_40BE04 = v1;
outBuffer = *((unsigned __int8 *)a1 + 8) | (unsigned __int16)((_WORD)v2 << 8) | (a1[1] << 16) & 0xFF0000;
return Pm_Write();
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1)
{
int v1; // eax
int v2; // edx

v1 = Pt_Time();
v2 = *a1;
dword_40BE04 = v1;
outBuffer = *((unsigned __int8 *)a1 + 8) | (unsigned __int16)((_WORD)v2 << 8) | (a1[1] << 16) & 0xFF0000;
return Pm_Write();
}

original_code:
void midiWrite(struct Note *note)
{
        outBuffer[0].timestamp = Pt_Time(((void *)0));
        outBuffer[0].message = ((((note->vol) << 16) & 0xFF0000) | (((note->note) << 8) & 0xFF00) | ((note->status) & 0xFF));
        Pm_Write(out, outBuffer, 1);
}

variable_types: struct Note { int note; int vol; int status; long t; } *


midiNoteOff

decompiled_code:
__int64 __fastcall midiNoteOff(__int16 a1)
{
return midiNoteOn(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int16 a1)
{
return func10(a1, 0);
}

original_code:
void midiNoteOff(int note)
{
        midiNoteOn(note, 0);
}


midiReadLast

decompiled_code:
__int64 __fastcall midiReadLast(__int64 a1)
{
int v1; // edx
int v2; // ecx
unsigned __int8 v3; // esi^2
__int64 result; // rax

v1 = nbEventWaiting;
if ( !nbEventWaiting )
{
iEventWaiting = 0;
v1 = Pm_Read();
}
LODWORD(result) = inBuffer[2 * iEventWaiting];
v2 = iEventWaiting + 1;
*(_QWORD *)(a1 + 16) = dword_409EC4[2 * iEventWaiting];
*(_DWORD *)a1 = BYTE1(result);
v3 = BYTE2(result);
result = (unsigned __int8)result;
*(_DWORD *)(a1 + 8) = (unsigned __int8)result;
nbEventWaiting = v1 - 1;
*(_DWORD *)(a1 + 4) = v3;
iEventWaiting = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // edx
int v2; // ecx
unsigned __int8 v3; // esi^2
__int64 result; // rax

v1 = nbEventWaiting;
if ( !nbEventWaiting )
{
iEventWaiting = 0;
v1 = Pm_Read();
}
LODWORD(result) = inBuffer[2 * iEventWaiting];
v2 = iEventWaiting + 1;
*(_QWORD *)(a1 + 16) = dword_409EC4[2 * iEventWaiting];
*(_DWORD *)a1 = BYTE1(result);
v3 = BYTE2(result);
result = (unsigned __int8)result;
*(_DWORD *)(a1 + 8) = (unsigned __int8)result;
nbEventWaiting = v1 - 1;
*(_DWORD *)(a1 + 4) = v3;
iEventWaiting = v2;
return result;
}

original_code:
void midiReadLast(struct Note *note)
{
        if(nbEventWaiting == 0) {
                iEventWaiting = 0;
                nbEventWaiting = Pm_Read(in, inBuffer, 1);
        }
        note->t = inBuffer[iEventWaiting].timestamp;
        note->note = (((inBuffer[iEventWaiting].message) >> 8) & 0xFF);
        note->vol = (((inBuffer[iEventWaiting].message) >> 16) & 0xFF);
        note->status = ((inBuffer[iEventWaiting].message) & 0xFF);
        nbEventWaiting--;
        iEventWaiting++;
}

user_defined_types: struct Note { int note; int vol; int status; long t; }


midiFlush

decompiled_code:
__int64 midiFlush()
{
nbEventWaiting = 0;
iEventWaiting = 0;
return Pm_Read();
}

canonical_decompiled_code:
__int64 func14()
{
nbEventWaiting = 0;
iEventWaiting = 0;
return Pm_Read();
}

original_code:
void midiFlush()
{
        nbEventWaiting = 0;
        iEventWaiting = 0;
        Pm_Read(in, inBuffer, 1);
}


IHMinit

decompiled_code:
int IHMinit()
{
fdMouse = open("/dev/input/mice", 4202522);
return fcntl(fdMouse, 4, 2048LL);
}

canonical_decompiled_code:
int func15()
{
fdMouse = open("/dev/input/mice", 4202522);
return fcntl(fdMouse, 4, 2048LL);
}

original_code:
void IHMinit()
{
        fdMouse = open("/dev/input/mice", "r");
        fcntl(fdMouse, 4, 04000);
}


IHMuserEntry

decompiled_code:
__int64 IHMuserEntry()
{
int v0; // er8
__int64 result; // rax

v0 = read(fdMouse, &b, 2uLL);
result = 0LL;
if ( v0 != -1 )
{
if ( (b & 1) != 0 )
{
result = 76LL;
}
else
{
result = 82LL;
if ( (b & 2) == 0 )
{
result = b & 4;
if ( (b & 4) != 0 )
result = 77LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func16()
{
int v0; // er8
__int64 result; // rax

v0 = read(fdMouse, &b, 2uLL);
result = 0LL;
if ( v0 != -1 )
{
if ( (b & 1) != 0 )
{
result = 76LL;
}
else
{
result = 82LL;
if ( (b & 2) == 0 )
{
result = b & 4;
if ( (b & 4) != 0 )
result = 77LL;
}
}
}
return result;
}

original_code:
char IHMuserEntry()
{
        int r = read(fdMouse, b, 2);
        if(r != -1) {
                int lb=(b[0]&1)>0;
                int rb=(b[0]&2)>0;
                int mb=(b[0]&4)>0;
                if(lb)
                        return 'L';
                if(rb)
                        return 'R';
                if(mb)
                        return 'M';
        }
        return 0;
}

canonical_original_code:
char IHMuserEntry()
{
        int r = read(fdMouse, b, 2);
        if(r != -1) {
                int lb = (b[0]&1)>0;
                int rb = (b[0]&2)>0;
                int mb = (b[0]&4)>0;
                if(lb)
                        return 'L';
                if(rb)
                        return 'R';
                if(mb)
                        return 'M';
        }
        return 0;
}

variable_types: r int

variable_types: lb int

variable_types: rb int

variable_types: mb int

return_type: char


bert

repo: anachrocomputer/vec

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

if ( a1 )
{
turn(-90.0);
hilb((unsigned int)(a1 - 1), a2);
forward(a2);
turn(90.0);
bert((unsigned int)(a1 - 1), a2);
forward(a2);
bert((unsigned int)(a1 - 1), a2);
turn(90.0);
forward(a2);
hilb((unsigned int)(a1 - 1), a2);
result = turn(-90.0);
}
return result;
}

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

if ( a1 )
{
func15(-90.0);
func8((unsigned int)(a1 - 1), a2);
func14(a2);
func15(90.0);
func7((unsigned int)(a1 - 1), a2);
func14(a2);
func7((unsigned int)(a1 - 1), a2);
func15(90.0);
func14(a2);
func8((unsigned int)(a1 - 1), a2);
result = func15(-90.0);
}
return result;
}

original_code:
void bert(const int level, const double len)
{
   if (level == 0)
      return;
   turn(-90.0);
   hilb(level - 1, len);
   forward(len);
   turn(90.0);
   bert(level - 1, len);
   forward(len);
   bert(level - 1, len);
   turn(90.0);
   forward(len);
   hilb(level - 1, len);
   turn(-90.0);
}

canonical_original_code:
void bert(int level, double len)
{
   if (level == 0)
      return;
   turn(-90.0);
   hilb(level - 1, len);
   forward(len);
   turn(90.0);
   bert(level - 1, len);
   forward(len);
   bert(level - 1, len);
   turn(90.0);
   forward(len);
   hilb(level - 1, len);
   turn(-90.0);
}

variable_types: level int

variable_types: len double


hilb

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

if ( a1 )
{
turn(90.0);
bert(a1 - 1, a2);
forward(a2);
turn(-90.0);
hilb((unsigned int)(a1 - 1), a2);
forward(a2);
hilb((unsigned int)(a1 - 1), a2);
turn(-90.0);
forward(a2);
bert(a1 - 1, a2);
result = turn(90.0);
}
return result;
}

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

if ( a1 )
{
func15(90.0);
func7(a1 - 1, a2);
func14(a2);
func15(-90.0);
func8((unsigned int)(a1 - 1), a2);
func14(a2);
func8((unsigned int)(a1 - 1), a2);
func15(-90.0);
func14(a2);
func7(a1 - 1, a2);
result = func15(90.0);
}
return result;
}

original_code:
void hilb(const int level, const double len)
{
   if (level == 0)
      return;
   turn(90.0);
   bert(level - 1, len);
   forward(len);
   turn(-90.0);
   hilb(level - 1, len);
   forward(len);
   hilb(level - 1, len);
   turn(-90.0);
   forward(len);
   bert(level - 1, len);
   turn(90.0);
}

canonical_original_code:
void hilb(int level, double len)
{
   if (level == 0)
      return;
   turn(90.0);
   bert(level - 1, len);
   forward(len);
   turn(-90.0);
   hilb(level - 1, len);
   forward(len);
   hilb(level - 1, len);
   turn(-90.0);
   forward(len);
   bert(level - 1, len);
   turn(90.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


colour

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

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

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

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

variable_types: c int


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

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

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

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


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

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

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

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
double v4; // r15
double v5; // rbp
double v6; // r14
double v7; // xmm0_8
int v8; // eax
__int64 v9; // rdi
double v11; // [rsp+8h] [rbp-30h]

v3 = 1;
turtle(1LL, 3LL, 0LL, 5LL);
title("HILBERT");
v4 = page_height("HILBERT", 7LL, 3.75);
v5 = page_width();
v11 = 135.0;
do
{
bottom_left();
set_heading(0.0);
pen(0LL);
v6 = v11;
v7 = (v5 - 270.0) * 0.5 + 0.5 * v11;
v11 = 0.5 * v11;
forward(v7);
turn(90.0);
forward((v4 - 270.0) * 0.5 + v11);
turn(-90.0);
pen(1LL);
v8 = v3 & 3;
switch ( v8 )
{
case 2:
colour(3LL);
break;
case 3:
colour(4LL);
break;
case 1:
colour(2LL);
break;
default:
colour(1LL);
break;
}
v9 = v3++;
hilb(v9, v6);
}
while ( v3 != 6 );
show();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
double v4; // r15
double v5; // rbp
double v6; // r14
double v7; // xmm0_8
int v8; // eax
__int64 v9; // rdi
double v11; // [rsp+8h] [rbp-30h]

v3 = 1;
func9(1LL, 3LL, 0LL, 5LL);
func11("HILBERT");
v4 = func19("HILBERT", 7LL, 3.75);
v5 = func18();
v11 = 135.0;
do
{
func12();
func13(0.0);
func16(0LL);
v6 = v11;
v7 = (v5 - 270.0) * 0.5 + 0.5 * v11;
v11 = 0.5 * v11;
func14(v7);
func15(90.0);
func14((v4 - 270.0) * 0.5 + v11);
func15(-90.0);
func16(1LL);
v8 = v3 & 3;
switch ( v8 )
{
case 2:
func17(3LL);
break;
case 3:
func17(4LL);
break;
case 1:
func17(2LL);
break;
default:
func17(1LL);
break;
}
v9 = v3++;
func8(v9, v6);
}
while ( v3 != 6 );
func10();
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
   int level;
   const double overall = 270.0;
   const int maxlevel = 5;
   double size;
   double height;
   double width;
   turtle((1), (3), (0), (1)|(4));
   title("HILBERT", 3.75, (3)|(4), (1));
   height = page_height();
   width = page_width();
   size = overall / 2.0;
   for (level = 1; level <= maxlevel; level++) {
      bottom_left();
      set_heading(0.0);
      pen((0));
      forward((size / 2.0) + ((width - overall) / 2.0));
      turn(90.0);
      forward((size / 2.0) + ((height - overall) / 2.0));
      turn(-90.0);
      pen((1));
      switch (level % 4) {
      case 0:
         colour((1));
         break;
      case 1:
         colour((2));
         break;
      case 2:
         colour((3));
         break;
      case 3:
         colour((4));
         break;
      }
      hilb(level, size);
      size /= 2.0;
   }
   show();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int level;
   double overall = 270.0;
   int maxlevel = 5;
   double size;
   double height;
   double width;
   turtle((1), (3), (0), (1)|(4));
   title("HILBERT", 3.75, (3)|(4), (1));
   height = page_height();
   width = page_width();
   size = overall / 2.0;
   for (level = 1; level <= maxlevel; level++) {
      bottom_left();
      set_heading(0.0);
      pen((0));
      forward((size / 2.0) + ((width - overall) / 2.0));
      turn(90.0);
      forward((size / 2.0) + ((height - overall) / 2.0));
      turn(-90.0);
      pen((1));
      switch (level % 4) {
      case 0:
         colour((1));
         break;
      case 1:
         colour((2));
         break;
      case 2:
         colour((3));
         break;
      case 3:
         colour((4));
         break;
      }
      hilb(level, size);
      size /= 2.0;
   }
   show();
   return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: level int

variable_types: overall double

variable_types: maxlevel int

variable_types: height double

variable_types: width double


drawoneline

decompiled_code:
__int64 __fastcall drawoneline(double a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm2_8
double v7; // [rsp+10h] [rbp-28h]
double v8; // [rsp+18h] [rbp-20h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

sincos(a5, sinx, &cosx);
v5 = a3 * 0.5;
v7 = cosx * v5 - sinx[0] * a4;
v8 = v5 * sinx[0] + a4 * cosx;
moveto(
cosx * COERCE_DOUBLE(*(_QWORD *)&v5 ^ LC1) - sinx[0] * a4 + a1,
a4 * cosx + sinx[0] * COERCE_DOUBLE(*(_QWORD *)&v5 ^ LC1) + a2);
return lineto(v7 + a1, v8 + a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3, double a4, double a5)
{
double v5; // xmm2_8
double v7; // [rsp+10h] [rbp-28h]
double v8; // [rsp+18h] [rbp-20h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

sincos(a5, sinx, &cosx);
v5 = a3 * 0.5;
v7 = cosx * v5 - sinx[0] * a4;
v8 = v5 * sinx[0] + a4 * cosx;
moveto(
cosx * COERCE_DOUBLE(*(_QWORD *)&v5 ^ LC1) - sinx[0] * a4 + a1,
a4 * cosx + sinx[0] * COERCE_DOUBLE(*(_QWORD *)&v5 ^ LC1) + a2);
return lineto(v7 + a1, v8 + a2);
}

original_code:
void drawoneline(const double xc, const double yc, const double len, const double y, const double theta)
{
   const double s = sin(theta);
   const double c = cos(theta);
   const double halflen = len / 2.0;
   double x1, y1;
   double x2, y2;
   double rx1, ry1;
   double rx2, ry2;
   x1 = -halflen;
   y1 = y;
   x2 = halflen;
   y2 = y;
   rx1 = (x1 * c) - (y1 * s);
   ry1 = (x1 * s) + (y1 * c);
   rx2 = (x2 * c) - (y2 * s);
   ry2 = (x2 * s) + (y2 * c);
   moveto(xc + rx1, yc + ry1);
   lineto(xc + rx2, yc + ry2);
}

canonical_original_code:
void drawoneline(double xc, double yc, double len, double y, double theta)
{
   double s = sin(theta);
   double c = cos(theta);
   double halflen = len / 2.0;
   double x1; double y1;
   double x2; double y2;
   double rx1; double ry1;
   double rx2; double ry2;
   x1 = -halflen;
   y1 = y;
   x2 = halflen;
   y2 = y;
   rx1 = (x1 * c) - (y1 * s);
   ry1 = (x1 * s) + (y1 * c);
   rx2 = (x2 * c) - (y2 * s);
   ry2 = (x2 * s) + (y2 * c);
   moveto(xc + rx1, yc + ry1);
   lineto(xc + rx2, yc + ry2);
}

variable_types: len double

variable_types: y double

variable_types: theta double

variable_types: s double

variable_types: c double

variable_types: halflen double


drawlinesegs

original_code:
void drawlinesegs(const double xc, const double yc, const double pitch, const int nsegs, const double gap, const double y, const double theta, const int nodeflag)
{
   const double s = sin(theta);
   const double c = cos(theta);
   const double len = pitch - gap;
   const double radius = gap / 2.0;
   double x1, y1;
   double x2, y2;
   double x3, y3;
   double rx1, ry1;
   double rx2, ry2;
   double rx3, ry3;
   int i;
   for (i = 0; i < nsegs; i++) {
      const double xoff = (nsegs / 2.0) * pitch;
      x1 = (i * pitch) + radius - xoff;
      y1 = y;
      x2 = x1 + len;
      y2 = y;
      x3 = x1 - radius;
      y3 = y;
      rx1 = (x1 * c) - (y1 * s);
      ry1 = (x1 * s) + (y1 * c);
      rx2 = (x2 * c) - (y2 * s);
      ry2 = (x2 * s) + (y2 * c);
      if (nodeflag) {
         rx3 = (x3 * c) - (y3 * s);
         ry3 = (x3 * s) + (y3 * c);
         circle(xc + rx3, yc + ry3, radius);
      }
      moveto(xc + rx1, yc + ry1);
      lineto(xc + rx2, yc + ry2);
   }
   if (nodeflag) {
      x3 = x1 + len + radius;
      y3 = y;
      rx3 = (x3 * c) - (y3 * s);
      ry3 = (x3 * s) + (y3 * c);
      circle(xc + rx3, yc + ry3, radius);
   }
}

canonical_original_code:
void drawlinesegs(double xc, double yc, double pitch, int nsegs, double gap, double y, double theta, int nodeflag)
{
   double s = sin(theta);
   double c = cos(theta);
   double len = pitch - gap;
   double radius = gap / 2.0;
   double x1; double y1;
   double x2; double y2;
   double x3; double y3;
   double rx1; double ry1;
   double rx2; double ry2;
   double rx3; double ry3;
   int i;
   for (i = 0; i < nsegs; i++) {
      double xoff = (nsegs / 2.0) * pitch;
      x1 = (i * pitch) + radius - xoff;
      y1 = y;
      x2 = x1 + len;
      y2 = y;
      x3 = x1 - radius;
      y3 = y;
      rx1 = (x1 * c) - (y1 * s);
      ry1 = (x1 * s) + (y1 * c);
      rx2 = (x2 * c) - (y2 * s);
      ry2 = (x2 * s) + (y2 * c);
      if (nodeflag) {
         rx3 = (x3 * c) - (y3 * s);
         ry3 = (x3 * s) + (y3 * c);
         circle(xc + rx3, yc + ry3, radius);
      }
      moveto(xc + rx1, yc + ry1);
      lineto(xc + rx2, yc + ry2);
   }
   if (nodeflag) {
      x3 = x1 + len + radius;
      y3 = y;
      rx3 = (x3 * c) - (y3 * s);
      ry3 = (x3 * s) + (y3 * c);
      circle(xc + rx3, yc + ry3, radius);
   }
}

variable_types: xc double

variable_types: yc double

variable_types: pitch double

variable_types: nsegs int

variable_types: gap double

variable_types: nodeflag int

variable_types: radius double

variable_types: i int

variable_types: xoff double


drawlines

original_code:
void drawlines(const double xc, const double yc, const int npts, const double pitch, const double theta, const int nodeflag)
{
   const double s60 = sin(60.0 * (3.14159265358979323846 / 180.0));
   const double ystep = s60 * pitch;
   int i;
   for (i = -(npts / 2); i <= (npts / 2); i++) {
      double nsegs;
      if (i < 0)
         nsegs = npts - (-i + 1);
      else
         nsegs = npts - (i + 1);
      drawlinesegs(xc, yc, pitch, nsegs, 8.0 * 40.0, i * ystep, theta, nodeflag);
   }
}

canonical_original_code:
void drawlines(double xc, double yc, int npts, double pitch, double theta, int nodeflag)
{
   double s60 = sin(60.0 * (3.14159265358979323846 / 180.0));
   double ystep = s60 * pitch;
   int i;
   for (i = -(npts / 2); i <= (npts / 2); i++) {
      double nsegs;
      if (i < 0)
         nsegs = npts - (-i + 1);
      else
         nsegs = npts - (i + 1);
      drawlinesegs(xc, yc, pitch, nsegs, 8.0 * 40.0, i * ystep, theta, nodeflag);
   }
}

variable_types: npts int

variable_types: ystep double

variable_types: nsegs double


isogrid

decompiled_code:
void __fastcall isogrid(int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v8; // xmm4_8
double v9; // xmm5_8
double v10; // xmm4_8
double v11; // xmm5_8

drawlines(a1, 1, a2, a3, a4, 0.0, a6, a7, a8);
drawlines(a1, 0, a2, a3, a4, 1.047197551196598, v8, v9, a8);
drawlines(a1, 0, a2, a3, a4, 2.094395102393195, v10, v11, a8);
}

original_code:
void isogrid(const double xc, const double yc, const int npts, const double pitch)
{
   int i;
   double theta;
   for (i = 0; i < 3; i++) {
      theta = (i * 60) * (3.14159265358979323846 / 180.0);
      drawlines(xc, yc, npts, pitch, theta, i == 0);
   }
}

canonical_original_code:
void isogrid(double xc, double yc, int npts, double pitch)
{
   int i;
   double theta;
   for (i = 0; i < 3; i++) {
      theta = (i * 60) * (3.14159265358979323846 / 180.0);
      drawlines(xc, yc, npts, pitch, theta, i == 0);
   }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm3_8
double v4; // xmm6_8
unsigned int v5; // eax
double v6; // xmm4_8
double v7; // xmm5_8
double v9; // [rsp+0h] [rbp-28h] BYREF
double v10[4]; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v5 == -1 )
break;
if ( v5 - 110 > 8 || ((1LL << ((unsigned __int8)v5 - 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(v5, optarg);
}
if ( (int)plotbegin(1LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(&v9, v10);
isogrid(9, v9 * 0.5, 0.5 * v10[0], 960.0, v3, v6, v7, v4);
plotend();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // xmm3_8
double v4; // xmm6_8
unsigned int v5; // eax
double v6; // xmm4_8
double v7; // xmm5_8
double v9; // [rsp+0h] [rbp-28h] BYREF
double v10[4]; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v5 == -1 )
break;
if ( v5 - 110 > 8 || ((1LL << ((unsigned __int8)v5 - 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(v5, optarg);
}
if ( (int)plotbegin(1LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(&v9, v10);
func3(9, v9 * 0.5, 0.5 * v10[0], 960.0, v3, v6, v7, v4);
plotend();
return 0;
}

original_code:
int main(int argc, char * const argv[])
{
   int opt;
   double xc, yc;
   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);
   xc = maxx / 2.0;
   yc = maxy / 2.0;
   isogrid(xc, yc, 9, 24.0 * 40.0);
   plotend();
   return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int opt;
   double xc; double yc;
   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);
   xc = maxx / 2.0;
   yc = maxy / 2.0;
   isogrid(xc, yc, 9, 24.0 * 40.0);
   plotend();
   return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: maxx double

variable_types: maxy double


drawline

decompiled_code:
__int64 __fastcall drawline(double a1, double a2, double a3, double a4)
{
double v5; // xmm5_8
double v6; // xmm7_8
double v7; // xmm4_8
double v8; // xmm4_8
double v9; // xmm5_8
double v10; // xmm5_8
unsigned int v11; // er13
unsigned int v12; // er14
unsigned int v13; // ebp
unsigned int v14; // ebx
__int64 result; // rax
double v16; // xmm0_8
double v17; // xmm0_8
double v18; // [rsp+0h] [rbp-78h]
double v19; // [rsp+0h] [rbp-78h]
double v20; // [rsp+8h] [rbp-70h]
char s[72]; // [rsp+30h] [rbp-48h] BYREF

v5 = a3 - *(double *)&wcx_3;
v6 = a4 - *(double *)&wcy_2;
v7 = (a2 - *(double *)&wcy_2) * (a2 - *(double *)&wcy_2) + (a1 - *(double *)&wcx_3) * (a1 - *(double *)&wcx_3);
if ( v7 < 0.0 )
{
v20 = a4 - *(double *)&wcy_2;
v18 = a3 - *(double *)&wcx_3;
v16 = sqrt(v7);
v5 = v18;
v8 = v16;
v6 = v20;
}
else
{
v8 = sqrt(v7);
}
v9 = v5 * v5 + v6 * v6;
if ( v9 < 0.0 )
{
v19 = v8;
v17 = sqrt(v9);
v8 = v19;
v10 = v17;
}
else
{
v10 = sqrt(v9);
}
if ( v10 <= v8 )
{
v11 = getdevx(a3);
v12 = getdevy(a4);
v13 = getdevx(a1);
v14 = getdevy(a2);
wcx_3 = *(_QWORD *)&a1;
wcy_2 = *(_QWORD *)&a2;
}
else
{
v11 = getdevx(a1);
v12 = getdevy(a2);
v13 = getdevx(a3);
v14 = getdevy(a4);
wcx_3 = *(_QWORD *)&a3;
wcy_2 = *(_QWORD *)&a4;
}
if ( cx_1 != v11 || cy_0 != v12 )
{
snprintf(s, 0x20uLL, "\nPU;PA%d,%d;", v11, v12);
hpglout(s);
}
snprintf(s, 0x20uLL, "PD;PA%d,%d;", v13, v14);
result = hpglout(s);
cx_1 = v13;
cy_0 = v14;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3, double a4)
{
double v5; // xmm5_8
double v6; // xmm7_8
double v7; // xmm4_8
double v8; // xmm4_8
double v9; // xmm5_8
double v10; // xmm5_8
unsigned int v11; // er13
unsigned int v12; // er14
unsigned int v13; // ebp
unsigned int v14; // ebx
__int64 result; // rax
double v16; // xmm0_8
double v17; // xmm0_8
double v18; // [rsp+0h] [rbp-78h]
double v19; // [rsp+0h] [rbp-78h]
double v20; // [rsp+8h] [rbp-70h]
char s[72]; // [rsp+30h] [rbp-48h] BYREF

v5 = a3 - *(double *)&wcx_3;
v6 = a4 - *(double *)&wcy_2;
v7 = (a2 - *(double *)&wcy_2) * (a2 - *(double *)&wcy_2) + (a1 - *(double *)&wcx_3) * (a1 - *(double *)&wcx_3);
if ( v7 < 0.0 )
{
v20 = a4 - *(double *)&wcy_2;
v18 = a3 - *(double *)&wcx_3;
v16 = sqrt(v7);
v5 = v18;
v8 = v16;
v6 = v20;
}
else
{
v8 = sqrt(v7);
}
v9 = v5 * v5 + v6 * v6;
if ( v9 < 0.0 )
{
v19 = v8;
v17 = sqrt(v9);
v8 = v19;
v10 = v17;
}
else
{
v10 = sqrt(v9);
}
if ( v10 <= v8 )
{
v11 = getdevx(a3);
v12 = getdevy(a4);
v13 = getdevx(a1);
v14 = getdevy(a2);
wcx_3 = *(_QWORD *)&a1;
wcy_2 = *(_QWORD *)&a2;
}
else
{
v11 = getdevx(a1);
v12 = getdevy(a2);
v13 = getdevx(a3);
v14 = getdevy(a4);
wcx_3 = *(_QWORD *)&a3;
wcy_2 = *(_QWORD *)&a4;
}
if ( cx_1 != v11 || cy_0 != v12 )
{
snprintf(s, 0x20uLL, "\nPU;PA%d,%d;", v11, v12);
hpglout(s);
}
snprintf(s, 0x20uLL, "PD;PA%d,%d;", v13, v14);
result = hpglout(s);
cx_1 = v13;
cy_0 = v14;
return result;
}

original_code:
void drawline(const double wx1, const double wy1, const double wx2, const double wy2)
{
   static int cx = -32767, cy = -32767;
   static double wcx = -1.0, wcy = -1.0;
   int x1, y1, x2, y2;
   const double dx1 = wx1 - wcx;
   const double dy1 = wy1 - wcy;
   const double dx2 = wx2 - wcx;
   const double dy2 = wy2 - wcy;
   const double d1 = sqrt((dx1 * dx1) + (dy1 * dy1));
   const double d2 = sqrt((dx2 * dx2) + (dy2 * dy2));
   char hpgl[32];
   if (d1 < d2) {
      x1 = getdevx(wx1);
      y1 = getdevy(wy1);
      x2 = getdevx(wx2);
      y2 = getdevy(wy2);
      wcx = wx2;
      wcy = wy2;
   }
   else {
      x1 = getdevx(wx2);
      y1 = getdevy(wy2);
      x2 = getdevx(wx1);
      y2 = getdevy(wy1);
      wcx = wx1;
      wcy = wy1;
   }
   if ((cx != x1) || (cy != y1)) {
      snprintf(hpgl, sizeof (hpgl), "\nPU;PA%d,%d;", x1, y1);
      hpglout(hpgl);
   }
   snprintf(hpgl, sizeof (hpgl), "PD;PA%d,%d;", x2, y2);
   hpglout(hpgl);
   cx = x2;
   cy = y2;
}

canonical_original_code:
void drawline(double wx1, double wy1, double wx2, double wy2)
{
   static int cx = -32767; static int cy = -32767;
   static double wcx = -1.0; static double wcy = -1.0;
   int x1; int y1; int x2; int y2;
   double dx1 = wx1 - wcx;
   double dy1 = wy1 - wcy;
   double dx2 = wx2 - wcx;
   double dy2 = wy2 - wcy;
   double d1 = sqrt((dx1 * dx1) + (dy1 * dy1));
   double d2 = sqrt((dx2 * dx2) + (dy2 * dy2));
   char hpgl[32];
   if (d1 < d2) {
      x1 = getdevx(wx1);
      y1 = getdevy(wy1);
      x2 = getdevx(wx2);
      y2 = getdevy(wy2);
      wcx = wx2;
      wcy = wy2;
   }
   else {
      x1 = getdevx(wx2);
      y1 = getdevy(wy2);
      x2 = getdevx(wx1);
      y2 = getdevy(wy1);
      wcx = wx1;
      wcy = wy1;
   }
   if ((cx != x1) || (cy != y1)) {
      snprintf(hpgl, sizeof (hpgl), "\nPU;PA%d,%d;", x1, y1);
      hpglout(hpgl);
   }
   snprintf(hpgl, sizeof (hpgl), "PD;PA%d,%d;", x2, y2);
   hpglout(hpgl);
   cx = x2;
   cy = y2;
}

variable_types: cx int

variable_types: cy int

variable_types: wcx double

variable_types: wcy double

variable_types:
hpgl
char [32]


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

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

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

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


lineTest

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

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

variable_types: xc double

variable_types: yc double

variable_types: wd double

variable_types: ht double

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

variable_types: len double

variable_types: hside double

variable_types: vside double


circleTest

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

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

variable_types: major double

variable_types: minor double

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


arcTest

decompiled_code:
__int64 __fastcall arcTest(double a1, double a2, double a3)
{
int v3; // ebx
__int64 result; // rax
double v5; // [rsp+20h] [rbp-28h]
double v6; // [rsp+28h] [rbp-20h]

v3 = 0;
v5 = a1 - a3 * 0.5;
moveto(v5);
lineto(a3 * 0.5 + a1, a2);
v6 = a3 * 0.5 + a1;
moveto(v6);
lineto(v5, a3 * 0.5 + a2);
moveto(a1);
lineto(a1, a2 - a3 * 0.5);
moveto(v5);
lineto(v6, a3 * 0.5 + a2);
do
{
moveto(a1 - a3 * 0.0625 * (double)++v3);
result = arc(a1, a2, (double)v3 * 45.0);
}
while ( v3 != 7 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, double a2, double a3)
{
int v3; // ebx
__int64 result; // rax
double v5; // [rsp+20h] [rbp-28h]
double v6; // [rsp+28h] [rbp-20h]

v3 = 0;
v5 = a1 - a3 * 0.5;
moveto(v5);
lineto(a3 * 0.5 + a1, a2);
v6 = a3 * 0.5 + a1;
moveto(v6);
lineto(v5, a3 * 0.5 + a2);
moveto(a1);
lineto(a1, a2 - a3 * 0.5);
moveto(v5);
lineto(v6, a3 * 0.5 + a2);
do
{
moveto(a1 - a3 * 0.0625 * (double)++v3);
result = arc(a1, a2, (double)v3 * 45.0);
}
while ( v3 != 7 );
return result;
}

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

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

variable_types: radius double

variable_types: delta double

variable_types: angle double

variable_types: i int