emitterGetAngle

decompiled_code:
double __fastcall emitterGetAngle(__int64 a1)
{
double result; // xmm0_8

if ( a1 )
result = *(double *)(a1 + 16);
else
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func3(__int64 a1)
{
double result; // xmm0_8

if ( a1 )
result = *(double *)(a1 + 16);
else
result = 0.0;
return result;
}

original_code:
double emitterGetAngle(emitter_t* emitter){
    if(!emitter) return 0;
    return emitter->angle;
}

canonical_original_code:
double emitterGetAngle(struct EMITTER *emitter){
    if(!emitter) return 0;
    return emitter->angle;
}

return_type: double


emitterGetAlpha

repo: amotta/StickyParticles

decompiled_code:
double __fastcall emitterGetAlpha(__int64 a1)
{
double result; // xmm0_8

if ( a1 )
result = *(double *)(a1 + 24);
else
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1)
{
double result; // xmm0_8

if ( a1 )
result = *(double *)(a1 + 24);
else
result = 0.0;
return result;
}

original_code:
double emitterGetAlpha(emitter_t* emitter){
    if(!emitter) return 0;
    return emitter->alpha;
}

canonical_original_code:
double emitterGetAlpha(struct EMITTER *emitter){
    if(!emitter) return 0;
    return emitter->alpha;
}

variable_types: struct EMITTER { struct vect_t { double x; double y; } pos; double angle; double alpha; double flow; double speed; } *

user_defined_types: struct EMITTER { struct vect_t pos; double angle; double alpha; double flow; double speed; }


emitterSetAlpha

decompiled_code:
void __fastcall emitterSetAlpha(__int64 a1, double a2)
{
if ( a1 )
*(double *)(a1 + 24) = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, double a2)
{
if ( a1 )
*(double *)(a1 + 24) = a2;
}

original_code:
void emitterSetAlpha(emitter_t* emitter, double alpha){
    if(!emitter) return;
    emitter->alpha = alpha;
}

canonical_original_code:
void emitterSetAlpha(struct EMITTER *emitter, double alpha){
    if(!emitter) return;
    emitter->alpha = alpha;
}

variable_types: alpha double

return_type: void


emitterGetFlow

decompiled_code:
double __fastcall emitterGetFlow(__int64 a1)
{
double result; // xmm0_8

if ( a1 )
result = *(double *)(a1 + 32);
else
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func6(__int64 a1)
{
double result; // xmm0_8

if ( a1 )
result = *(double *)(a1 + 32);
else
result = 0.0;
return result;
}

original_code:
double emitterGetFlow(emitter_t* emitter){
    if(!emitter) return 0;
    return emitter->flow;
}

canonical_original_code:
double emitterGetFlow(struct EMITTER *emitter){
    if(!emitter) return 0;
    return emitter->flow;
}


emitterSetFlow

decompiled_code:
void __fastcall emitterSetFlow(__int64 a1, double a2)
{
if ( a1 )
*(double *)(a1 + 32) = a2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, double a2)
{
if ( a1 )
*(double *)(a1 + 32) = a2;
}

original_code:
void emitterSetFlow(emitter_t* emitter, double flow){
    if(!emitter) return;
    emitter->flow = flow;
}

canonical_original_code:
void emitterSetFlow(struct EMITTER *emitter, double flow){
    if(!emitter) return;
    emitter->flow = flow;
}

variable_types: flow double


emitterGetSpeed

decompiled_code:
double __fastcall emitterGetSpeed(__int64 a1)
{
double result; // xmm0_8

if ( a1 )
result = *(double *)(a1 + 40);
else
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func8(__int64 a1)
{
double result; // xmm0_8

if ( a1 )
result = *(double *)(a1 + 40);
else
result = 0.0;
return result;
}

original_code:
double emitterGetSpeed(emitter_t* emitter){
    if(!emitter) return 0;
    return emitter->speed;
}

canonical_original_code:
double emitterGetSpeed(struct EMITTER *emitter){
    if(!emitter) return 0;
    return emitter->speed;
}


emitterSetSpeed

decompiled_code:
void __fastcall emitterSetSpeed(__int64 a1, double a2)
{
if ( a1 )
*(double *)(a1 + 40) = a2;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, double a2)
{
if ( a1 )
*(double *)(a1 + 40) = a2;
}

original_code:
void emitterSetSpeed(emitter_t* emitter, double speed){
    if(!emitter) return;
    emitter->speed = speed;
}

canonical_original_code:
void emitterSetSpeed(struct EMITTER *emitter, double speed){
    if(!emitter) return;
    emitter->speed = speed;
}

variable_types: speed double


emitterDraw

decompiled_code:
__int64 __fastcall emitterDraw(__int64 a1, double a2, double a3)
{
__int64 result; // rax
double v4; // r12
double v5; // r13
double v6; // rbp
double v7; // r14
double v10; // [rsp+10h] [rbp-68h]
double v11; // [rsp+10h] [rbp-68h]
double v12; // [rsp+18h] [rbp-60h]
double cosx; // [rsp+20h] [rbp-58h] BYREF
double sinx[10]; // [rsp+28h] [rbp-50h] BYREF

result = 0LL;
if ( a1 )
{
emitterGetPos(a1);
v10 = emitterGetAngle(a1);
v12 = emitterGetAlpha(a1);
sincos(v10 - v12, sinx, &cosx);
v4 = cosx;
v5 = sinx[0];
sincos(v10 + v12, sinx, &cosx);
v6 = cosx;
v7 = sinx[0];
v11 = emitterGetSpeed(a1);
gfxColor(0.0, 0.0);
gfxLine(a2, a3, v4 * v11 + a2, v5 * v11 + a3);
gfxLine(a2, a3, v6 * v11 + a2, v7 * v11 + a3);
sinx[1] = a2 - 0.05;
sinx[2] = a2 + 0.05;
sinx[3] = a3 - 0.05;
sinx[4] = a3 + 0.05;
gfxRect(1LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, double a2, double a3)
{
__int64 result; // rax
double v4; // r12
double v5; // r13
double v6; // rbp
double v7; // r14
double v10; // [rsp+10h] [rbp-68h]
double v11; // [rsp+10h] [rbp-68h]
double v12; // [rsp+18h] [rbp-60h]
double cosx; // [rsp+20h] [rbp-58h] BYREF
double sinx[10]; // [rsp+28h] [rbp-50h] BYREF

result = 0LL;
if ( a1 )
{
func1(a1);
v10 = func3(a1);
v12 = func4(a1);
sincos(v10 - v12, sinx, &cosx);
v4 = cosx;
v5 = sinx[0];
sincos(v10 + v12, sinx, &cosx);
v6 = cosx;
v7 = sinx[0];
v11 = func8(a1);
gfxColor(0.0, 0.0);
gfxLine(a2, a3, v4 * v11 + a2, v5 * v11 + a3);
gfxLine(a2, a3, v6 * v11 + a2, v7 * v11 + a3);
sinx[1] = a2 - 0.05;
sinx[2] = a2 + 0.05;
sinx[3] = a3 - 0.05;
sinx[4] = a3 + 0.05;
gfxRect(1LL);
result = 1LL;
}
return result;
}

original_code:
_Bool emitterDraw(emitter_t* emitter){
    vect_t pos;
    double lineLen;
    double alphaOne, alphaTwo;
    if(!emitter) return 0;
    pos = emitterGetPos(emitter);
    alphaOne = emitterGetAngle(emitter) - emitterGetAlpha(emitter);
    alphaTwo = emitterGetAngle(emitter) + emitterGetAlpha(emitter);
    lineLen = 1.0 / 1.0 * emitterGetSpeed(emitter);
    gfxColor(0, 0, 0);
    gfxLine(
        pos.x, pos.y,
        pos.x + lineLen * cos(alphaOne), pos.y + lineLen * sin(alphaOne)
    );
    gfxLine(
        pos.x, pos.y,
        pos.x + lineLen * cos(alphaTwo), pos.y + lineLen * sin(alphaTwo)
    );
    rect_t rect = {
        .left = pos.x - 0.1 / 2,
        .right = pos.x + 0.1 / 2,
        .bottom = pos.y - 0.1 / 2,
        .top = pos.y + 0.1 / 2
    };
    gfxRect(rect, 1);
    return 1;
}

canonical_original_code:
_Bool emitterDraw(struct EMITTER *emitter){
    struct vect_t pos;
    double lineLen;
    double alphaOne; double alphaTwo;
    if(!emitter) return 0;
    pos = emitterGetPos(emitter);
    alphaOne = emitterGetAngle(emitter) - emitterGetAlpha(emitter);
    alphaTwo = emitterGetAngle(emitter) + emitterGetAlpha(emitter);
    lineLen = 1.0 / 1.0 * emitterGetSpeed(emitter);
    gfxColor(0, 0, 0);
    gfxLine(
        pos.x, pos.y,
        pos.x + lineLen * cos(alphaOne), pos.y + lineLen * sin(alphaOne)
    );
    gfxLine(
        pos.x, pos.y,
        pos.x + lineLen * cos(alphaTwo), pos.y + lineLen * sin(alphaTwo)
    );
    struct rect_t rect = {
        .left = pos.x - 0.1 / 2,
        .right = pos.x + 0.1 / 2,
        .bottom = pos.y - 0.1 / 2,
        .top = pos.y + 0.1 / 2
    };
    gfxRect(rect, 1);
    return 1;
}

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

variable_types: lineLen double

variable_types: alphaOne double

variable_types: alphaTwo double

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


emitterFree

decompiled_code:
void __fastcall emitterFree(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func12(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void emitterFree(emitter_t* emitter){
    if(!emitter) return;
    free(emitter);
}

canonical_original_code:
void emitterFree(struct EMITTER *emitter){
    if(!emitter) return;
    free(emitter);
}


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

decompiled_code:
__int64 __fastcall isVectInGameCirc(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
__int64 v7; // [rsp+0h] [rbp-38h] 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)
{
if ( a1 <= a9 )
return 0;
if ( a10 <= a1 )
return 0;
if ( a2 <= a11 )
return 0;
return a12 > a2;
}

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)
{
if ( a1 <= a9 )
return 0;
if ( a10 <= a1 )
return 0;
if ( a2 <= a11 )
return 0;
return a12 > a2;
}

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

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


isCircInRect

decompiled_code:
bool __fastcall isCircInRect(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, double a15)
{
bool result; // al

result = 0;
if ( a11 <= a13 - a12 && a11 <= a15 - a14 )
result = isVectInRect(
a9,
a10,
a12 + a11,
a15 - a11,
a14 + a11,
a15 - a14,
a7,
a8,
a12 + a11,
a13 - a11,
a14 + a11,
a15 - a11);
return result;
}

canonical_decompiled_code:
bool __fastcall func4(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, double a15)
{
bool result; // al

result = 0;
if ( a11 <= a13 - a12 && a11 <= a15 - a14 )
result = func3(
a9,
a10,
a12 + a11,
a15 - a11,
a14 + a11,
a15 - a14,
a7,
a8,
a12 + a11,
a13 - a11,
a14 + a11,
a15 - a11);
return result;
}

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


isCircInGameRect

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

v17 = getGameRect(v21);
return isCircInRect(
v17,
a2,
a3,
a4,
v18,
v19,
a7,
a8,
a9,
a10,
a11,
*(double *)v21,
*(double *)&v21[1],
*(double *)&v21[2],
*(double *)&v21[3]);
}

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

v17 = getGameRect(v21);
return func4(
v17,
a2,
a3,
a4,
v18,
v19,
a7,
a8,
a9,
a10,
a11,
*(double *)v21,
*(double *)&v21[1],
*(double *)&v21[2],
*(double *)&v21[3]);
}

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 v9; // xmm4_8
double v10; // xmm5_8
__int64 v12[7]; // [rsp+0h] [rbp-38h] BYREF

getGameRect(v12);
return isVectInRect(
a1,
a2,
a3,
a4,
v9,
v10,
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 v9; // xmm4_8
double v10; // xmm5_8
__int64 v12[7]; // [rsp+0h] [rbp-38h] BYREF

getGameRect(v12);
return func3(
a1,
a2,
a3,
a4,
v9,
v10,
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:
double __fastcall vectLen(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8

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

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

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

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


vectDist

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

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

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

*(_QWORD *)&v4 = func1(a3, a4, a1).m128_u64[0];
return 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

sizeX = a1;
sizeY = a2;
v2 = (double)a1;
v3 = (double)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

sizeX = a1;
sizeY = a2;
v2 = (double)a1;
v3 = (double)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


gameUIHandleMouse

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

result = currentGame;
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

result = currentGame;
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(COERCE_UNSIGNED_INT64(a10 - a13) & LC0) <= 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(COERCE_UNSIGNED_INT64(a10 - a13) & LC0) <= 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 *)a1 = vectGetNull();
*(double *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = 0LL;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, double a2, double a3)
{
*(double *)a1 = vectGetNull();
*(double *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = 0LL;
return a1;
}

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)
{
*(double *)a1 = getGameCenter();
*(double *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = LC4;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, double a2, double a3)
{
*(double *)a1 = getGameCenter();
*(double *)(a1 + 8) = a3;
*(_QWORD *)(a1 + 16) = LC4;
return a1;
}

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 func5(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

func4((__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(&v1);
gfxRect(0LL);
gfxColor(0.0, 0.0, 0.0);
getGameCirc(&v2);
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(&v1);
gfxRect(0LL);
gfxColor(0.0, 0.0, 0.0);
getGameCirc(&v2);
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)
{
int v3; // er12
int v4; // ebx
int v5; // er13
_QWORD *v6; // rbp

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

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebx
int v5; // er13
_QWORD *v6; // rbp

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

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 __fastcall midiInit()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // er13
int v3; // er12
__int64 v4; // rax

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

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

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

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; // edx
__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; // edx
__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

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

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

dword_40BE04 = Pt_Time();
v2 = (unsigned __int16)(a1 << 8) | (a2 << 16) & 0xFF0000;
LOBYTE(v2) = -112;
outBuffer = v2;
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(__int64 a1)
{
dword_40BE04 = Pt_Time();
outBuffer = *(unsigned __int8 *)(a1 + 8) | (unsigned __int16)((unsigned __int16)*(_DWORD *)a1 << 8) | (*(_DWORD *)(a1 + 4) << 16) & 0xFF0000;
return Pm_Write();
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
dword_40BE04 = Pt_Time();
outBuffer = *(unsigned __int8 *)(a1 + 8) | (unsigned __int16)((unsigned __int16)*(_DWORD *)a1 << 8) | (*(_DWORD *)(a1 + 4) << 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)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx
__int64 result; // rax

if ( !nbEventWaiting )
{
iEventWaiting = 0;
nbEventWaiting = Pm_Read();
}
v1 = iEventWaiting;
*(_QWORD *)(a1 + 16) = dword_409EC4[2 * iEventWaiting];
*(_DWORD *)a1 = (unsigned __int8)byte_409EC1[8 * v1];
LODWORD(v1) = iEventWaiting;
v2 = iEventWaiting;
*(_DWORD *)(a1 + 4) = (unsigned __int8)byte_409EC2[8 * iEventWaiting];
*(_DWORD *)(a1 + 8) = (unsigned __int8)inBuffer[8 * v2];
--nbEventWaiting;
result = (unsigned int)(v1 + 1);
iEventWaiting = result;
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; // edx
__int64 result; // rax

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

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

v0 = read(fdMouse, &b, 2uLL);
result = 0LL;
if ( v0 != -1 )
{
result = 76LL;
if ( (b & 1) == 0 )
{
result = 82LL;
if ( (b & 2) == 0 )
{
result = 0LL;
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
__int64 result; // rax
int v6; // eax

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

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

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

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

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

variable_types: dev int

variable_types: siz int

variable_types: ori int

variable_types: flags int


show

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

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

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

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

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

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


title

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

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

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

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

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

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

variable_types:
str
char []

variable_types: size double

variable_types: posn int

variable_types: x int

variable_types: y int

variable_types: xc double

variable_types: yc double

variable_types: len int


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

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

canonical_decompiled_code:
int 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
int result; // eax

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

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

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

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

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

variable_types: mm double

variable_types: newx double

variable_types: newy double


turn

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

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

canonical_decompiled_code:
void __fastcall 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 )
*(double *)&Heading = v1 + 360.0;
sincos(0.0174532925199433 * *(double *)&Heading, sinx, (double *)&v2);
Xvec = v2;
Yvec = *(_QWORD *)&sinx[0];
}


pen

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

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

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

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

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

variable_types: c int


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

canonical_decompiled_code:
double 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)
{
double v3; // r13
double v4; // r12
int i; // ebx
double v6; // rbp
int v7; // eax
double v9; // [rsp+8h] [rbp-30h]

turtle(1LL, 3LL, 0LL, 5LL);
title("HILBERT");
v3 = page_height("HILBERT", 7LL, 3.75);
v4 = page_width();
v9 = 135.0;
for ( i = 1; i != 6; ++i )
{
bottom_left();
set_heading(0.0);
pen(0LL);
v6 = v9;
v9 = 0.5 * v9;
forward((v4 - 270.0) * 0.5 + v9);
turn(90.0);
forward((v3 - 270.0) * 0.5 + v9);
turn(-90.0);
pen(1LL);
v7 = i % 4;
if ( i % 4 == 2 )
{
colour(3LL);
}
else if ( v7 > 2 )
{
colour(4LL);
}
else if ( (i & 3) != 0 )
{
if ( v7 == 1 )
colour(2LL);
}
else
{
colour(1LL);
}
hilb(i, v6);
}
show();
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 v6; // [rsp+10h] [rbp-38h]
double v7; // [rsp+18h] [rbp-30h]
double cosx; // [rsp+20h] [rbp-28h] BYREF
double sinx[4]; // [rsp+28h] [rbp-20h] BYREF

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

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

sincos(a5, sinx, &cosx);
v6 = cosx * (a3 * 0.5) - a4 * sinx[0];
v7 = a3 * 0.5 * sinx[0] + a4 * cosx;
moveto(
cosx * COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a3 * 0.5) ^ LC1) - a4 * sinx[0] + a1,
sinx[0] * COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a3 * 0.5) ^ LC1) + a4 * cosx + a2);
return lineto(v6 + a1, v7 + 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

decompiled_code:
void __fastcall drawlines(int a1, int a2, double a3, double a4, double a5, double a6)
{
int v6; // ebx
int v7; // er12
int v8; // eax

if ( a1 / -2 <= a1 / 2 )
{
v6 = a1 / -2;
v7 = a1 - 1;
do
{
if ( v6 >= 0 )
v8 = v7 - v6;
else
v8 = v7 + v6;
drawlinesegs((int)(double)v8, a2, a3, a4, a5, 320.0, (double)v6++ * (a5 * 0.8660254037844386), a6);
}
while ( v6 <= a1 / 2 );
}
}

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

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)
{
unsigned int v3; // eax
double v5; // [rsp+0h] [rbp-28h] BYREF
double v6[4]; // [rsp+8h] [rbp-20h] BYREF

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v3 == -1 )
break;
if ( v3 - 110 > 8 || ((1LL << ((unsigned __int8)v3 - 110)) & 0x167) == 0 )
{
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", *argv);
fwrite(" <size> ::= A1 | A2 | A3 | A4 | A5\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
plotopt(v3, optarg);
}
if ( (int)plotbegin(1LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v6, &v5);
isogrid(9, 0.5 * v6[0], 0.5 * v5, 960.0);
plotend();
return 0;
}

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

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "no:p:s:t:v:");
if ( v3 == -1 )
break;
if ( v3 - 110 > 8 || ((1LL << ((unsigned __int8)v3 - 110)) & 0x167) == 0 )
{
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", *argv);
fwrite(" <size> ::= A1 | A2 | A3 | A4 | A5\n", 1uLL, 0x29uLL, stderr);
exit(1);
}
plotopt(v3, optarg);
}
if ( (int)plotbegin(1LL) < 0 )
{
fwrite("Failed to initialise HPGL library\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
getplotsize(v6, &v5);
func3(9, 0.5 * v6[0], 0.5 * v5, 960.0);
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 v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
unsigned int v7; // er14
unsigned int v8; // er15
unsigned int v9; // er13
unsigned int v10; // er12
__int64 result; // rax
double v13; // [rsp+18h] [rbp-70h]
double v14; // [rsp+20h] [rbp-68h]
double v15; // [rsp+28h] [rbp-60h]
char s[88]; // [rsp+30h] [rbp-58h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3, double a4)
{
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
unsigned int v7; // er14
unsigned int v8; // er15
unsigned int v9; // er13
unsigned int v10; // er12
__int64 result; // rax
double v13; // [rsp+18h] [rbp-70h]
double v14; // [rsp+20h] [rbp-68h]
double v15; // [rsp+28h] [rbp-60h]
char s[88]; // [rsp+30h] [rbp-58h] BYREF

v13 = a3 - *(double *)&wcx_3;
v14 = a4 - *(double *)&wcy_2;
v4 = (a1 - *(double *)&wcx_3) * (a1 - *(double *)&wcx_3) + (a2 - *(double *)&wcy_2) * (a2 - *(double *)&wcy_2);
if ( v4 < 0.0 )
v15 = sqrt(v4);
else
v15 = sqrt(v4);
v5 = v13 * v13 + v14 * v14;
if ( v5 < 0.0 )
v6 = sqrt(v5);
else
v6 = sqrt(v5);
if ( v6 <= v15 )
{
v7 = getdevx(a3);
v8 = getdevy(a4);
v9 = getdevx(a1);
v10 = getdevy(a2);
wcx_3 = *(_QWORD *)&a1;
wcy_2 = *(_QWORD *)&a2;
}
else
{
v7 = getdevx(a1);
v8 = getdevy(a2);
v9 = getdevx(a3);
v10 = getdevy(a4);
wcx_3 = *(_QWORD *)&a3;
wcy_2 = *(_QWORD *)&a4;
}
if ( cx_1 != v7 || cy_0 != v8 )
{
snprintf(s, 0x20uLL, "\nPU;PA%d,%d;", v7, v8);
hpglout(s);
}
snprintf(s, 0x20uLL, "PD;PA%d,%d;", v9, v10);
result = hpglout(s);
cx_1 = v9;
cy_0 = v10;
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]