MeanXY

decompiled_code:
void __fastcall MeanXY(double *a1, double *a2)
{
double v2; // xmm1_8

v2 = *(double *)&sum_weight;
*a1 = *(double *)&sum_x / *(double *)&sum_weight;
*a2 = *(double *)&sum_y / v2;
}

canonical_decompiled_code:
void __fastcall func5(double *a1, double *a2)
{
double v2; // xmm1_8

v2 = *(double *)&sum_weight;
*a1 = *(double *)&sum_x / *(double *)&sum_weight;
*a2 = *(double *)&sum_y / v2;
}

original_code:
void MeanXY (double *xMean, double *yMean)
{
    *xMean = sum_x / sum_weight;
    *yMean = sum_y / sum_weight;
}

canonical_original_code:
void MeanXY(double *xMean, double *yMean)
{
    *xMean = sum_x / sum_weight;
    *yMean = sum_y / sum_weight;
}

variable_types:
xMean
double *

variable_types:
yMean
double *


SDevXY

repo: prjemian/lake

decompiled_code:
void __fastcall SDevXY(double *a1, double *a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // xmm1_8
double v9; // xmm1_8
double v10; // xmm1_8
double v11; // xmm1_8

v2 = *(double *)&sum_x;
v3 = *(double *)&sum_weight;
*a1 = 0.0;
v4 = v2 * v2 / v3;
if ( *(double *)&sum_x2 > v4 )
{
v8 = (*(double *)&sum_x2 - v4) / v3;
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
*a1 = v9;
}
v5 = *(double *)&sum_y;
v6 = *(double *)&sum_y2;
*a2 = 0.0;
v7 = v5 * v5 / v3;
if ( v6 > v7 )
{
v10 = (v6 - v7) / v3;
if ( v10 < 0.0 )
v11 = sqrt(v10);
else
v11 = sqrt(v10);
*a2 = v11;
}
}

canonical_decompiled_code:
void __fastcall func6(double *a1, double *a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // xmm1_8
double v9; // xmm1_8
double v10; // xmm1_8
double v11; // xmm1_8

v2 = *(double *)&sum_x;
v3 = *(double *)&sum_weight;
*a1 = 0.0;
v4 = v2 * v2 / v3;
if ( *(double *)&sum_x2 > v4 )
{
v8 = (*(double *)&sum_x2 - v4) / v3;
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
*a1 = v9;
}
v5 = *(double *)&sum_y;
v6 = *(double *)&sum_y2;
*a2 = 0.0;
v7 = v5 * v5 / v3;
if ( v6 > v7 )
{
v10 = (v6 - v7) / v3;
if ( v10 < 0.0 )
v11 = sqrt(v10);
else
v11 = sqrt(v10);
*a2 = v11;
}
}

original_code:
void SDevXY (double *xDev, double *yDev)
{
    *xDev = 0.0;
    if (sum_x2 > ((sum_x*sum_x)/sum_weight) )
        *xDev = sqrt (( sum_x2 - ( (sum_x*sum_x)/sum_weight) )/sum_weight);
    *yDev = 0.0;
    if (sum_y2 > ((sum_y*sum_y)/sum_weight) )
        *yDev = sqrt (( sum_y2 - ( (sum_y*sum_y)/sum_weight) )/sum_weight);
}

canonical_original_code:
void SDevXY(double *xDev, double *yDev)
{
    *xDev = 0.0;
    if (sum_x2 > ((sum_x*sum_x)/sum_weight) )
        *xDev = sqrt (( sum_x2 - ( (sum_x*sum_x)/sum_weight) )/sum_weight);
    *yDev = 0.0;
    if (sum_y2 > ((sum_y*sum_y)/sum_weight) )
        *yDev = sqrt (( sum_y2 - ( (sum_y*sum_y)/sum_weight) )/sum_weight);
}

variable_types:
xDev
double *

variable_types:
yDev
double *

return_type: void


SErrXY

decompiled_code:
void __fastcall SErrXY(double *a1, double *a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // xmm1_8
double v9; // xmm1_8
double v10; // xmm1_8
double v11; // xmm1_8

v2 = *(double *)&sum_x;
v3 = *(double *)&sum_weight;
*a1 = 0.0;
v4 = v2 * v2 / v3;
if ( *(double *)&sum_x2 > v4 )
{
v8 = (*(double *)&sum_x2 - v4) / (v3 - 1.0);
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
*a1 = v9;
}
v5 = *(double *)&sum_y;
v6 = *(double *)&sum_y2;
*a2 = 0.0;
v7 = v5 * v5 / v3;
if ( v6 > v7 )
{
v10 = (v6 - v7) / (v3 - 1.0);
if ( v10 < 0.0 )
v11 = sqrt(v10);
else
v11 = sqrt(v10);
*a2 = v11;
}
}

canonical_decompiled_code:
void __fastcall func7(double *a1, double *a2)
{
double v2; // xmm0_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm0_8
double v8; // xmm1_8
double v9; // xmm1_8
double v10; // xmm1_8
double v11; // xmm1_8

v2 = *(double *)&sum_x;
v3 = *(double *)&sum_weight;
*a1 = 0.0;
v4 = v2 * v2 / v3;
if ( *(double *)&sum_x2 > v4 )
{
v8 = (*(double *)&sum_x2 - v4) / (v3 - 1.0);
if ( v8 < 0.0 )
v9 = sqrt(v8);
else
v9 = sqrt(v8);
*a1 = v9;
}
v5 = *(double *)&sum_y;
v6 = *(double *)&sum_y2;
*a2 = 0.0;
v7 = v5 * v5 / v3;
if ( v6 > v7 )
{
v10 = (v6 - v7) / (v3 - 1.0);
if ( v10 < 0.0 )
v11 = sqrt(v10);
else
v11 = sqrt(v10);
*a2 = v11;
}
}

original_code:
void SErrXY (double *xErr, double *yErr)
{
    *xErr = 0.0;
    if (sum_x2 > ((sum_x*sum_x)/sum_weight) )
        *xErr = sqrt (( sum_x2 - ( (sum_x*sum_x)/sum_weight) )/( sum_weight-1 ));
    *yErr = 0.0;
    if (sum_y2 > ((sum_y*sum_y)/sum_weight) )
        *yErr = sqrt (( sum_y2 - ((sum_y*sum_y)/sum_weight) )/( sum_weight-1 ));
}

canonical_original_code:
void SErrXY(double *xErr, double *yErr)
{
    *xErr = 0.0;
    if (sum_x2 > ((sum_x*sum_x)/sum_weight) )
        *xErr = sqrt (( sum_x2 - ( (sum_x*sum_x)/sum_weight) )/( sum_weight-1 ));
    *yErr = 0.0;
    if (sum_y2 > ((sum_y*sum_y)/sum_weight) )
        *yErr = sqrt (( sum_y2 - ((sum_y*sum_y)/sum_weight) )/( sum_weight-1 ));
}

variable_types:
xErr
double *

variable_types:
yErr
double *


SumLR

decompiled_code:
void __fastcall SumLR(double *a1, double *a2)
{
double v2; // xmm3_8
double v3; // xmm0_8

v2 = *(double *)&sum_weight * *(double *)&sum_x2 - *(double *)&sum_x * *(double *)&sum_x;
v3 = (*(double *)&sum_x2 * *(double *)&sum_y - *(double *)&sum_x * *(double *)&sum_xy) / v2;
*a1 = (*(double *)&sum_weight * *(double *)&sum_xy - *(double *)&sum_x * *(double *)&sum_y) / v2;
*a2 = v3;
}

canonical_decompiled_code:
void __fastcall func8(double *a1, double *a2)
{
double v2; // xmm3_8
double v3; // xmm0_8

v2 = *(double *)&sum_weight * *(double *)&sum_x2 - *(double *)&sum_x * *(double *)&sum_x;
v3 = (*(double *)&sum_x2 * *(double *)&sum_y - *(double *)&sum_x * *(double *)&sum_xy) / v2;
*a1 = (*(double *)&sum_weight * *(double *)&sum_xy - *(double *)&sum_x * *(double *)&sum_y) / v2;
*a2 = v3;
}

original_code:
void SumLR (double *slope, double *constant)
{
    double determ = (sum_weight*sum_x2 - sum_x*sum_x);
    *slope = (sum_weight*sum_xy - sum_x*sum_y) / determ;
    *constant = (sum_x2*sum_y - sum_x*sum_xy) / determ;
}

canonical_original_code:
void SumLR(double *slope, double *constant)
{
    double determ = (sum_weight*sum_x2 - sum_x*sum_x);
    *slope = (sum_weight*sum_xy - sum_x*sum_y) / determ;
    *constant = (sum_x2*sum_y - sum_x*sum_xy) / determ;
}

variable_types:
slope
double *

variable_types:
constant
double *

variable_types: determ double


VarLR

decompiled_code:
void __fastcall VarLR(double *a1, double *a2)
{
double v2; // xmm1_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm1_8
__int64 v8; // [rsp+0h] [rbp-28h]
double v9; // [rsp+8h] [rbp-20h]

v2 = *(double *)&sum_x2;
v3 = *(double *)&sum_weight * *(double *)&sum_x2 - *(double *)&sum_x * *(double *)&sum_x;
v4 = *(double *)&sum_weight / v3;
if ( *(double *)&sum_weight / v3 < 0.0 )
{
v9 = *(double *)&sum_weight * *(double *)&sum_x2 - *(double *)&sum_x * *(double *)&sum_x;
v8 = sum_x2;
v5 = sqrt(v4);
v3 = v9;
v2 = *(double *)&v8;
}
else
{
v5 = sqrt(v4);
}
v6 = v2 / v3;
*a1 = v5;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
*a2 = v7;
}

canonical_decompiled_code:
void __fastcall func9(double *a1, double *a2)
{
double v2; // xmm1_8
double v3; // xmm2_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm1_8
double v7; // xmm1_8
__int64 v8; // [rsp+0h] [rbp-28h]
double v9; // [rsp+8h] [rbp-20h]

v2 = *(double *)&sum_x2;
v3 = *(double *)&sum_weight * *(double *)&sum_x2 - *(double *)&sum_x * *(double *)&sum_x;
v4 = *(double *)&sum_weight / v3;
if ( *(double *)&sum_weight / v3 < 0.0 )
{
v9 = *(double *)&sum_weight * *(double *)&sum_x2 - *(double *)&sum_x * *(double *)&sum_x;
v8 = sum_x2;
v5 = sqrt(v4);
v3 = v9;
v2 = *(double *)&v8;
}
else
{
v5 = sqrt(v4);
}
v6 = v2 / v3;
*a1 = v5;
if ( v6 < 0.0 )
v7 = sqrt(v6);
else
v7 = sqrt(v6);
*a2 = v7;
}

original_code:
void VarLR (double *slope, double *constant)
{
    double determ = (sum_weight*sum_x2 - sum_x*sum_x);
    *slope = sqrt (sum_weight / determ);
    *constant = sqrt (sum_x2 / determ);
}

canonical_original_code:
void VarLR(double *slope, double *constant)
{
    double determ = (sum_weight*sum_x2 - sum_x*sum_x);
    *slope = sqrt (sum_weight / determ);
    *constant = sqrt (sum_x2 / determ);
}


AskString

decompiled_code:
char *__fastcall AskString(const char *a1, const char *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%s> ==> ", a1, a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%s\n", a2);
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, const char *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%s> ==> ", a1, a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%s\n", a2);
return result;
}

original_code:
void AskString (char *question, char *answer)
{
    char reply[256];
    printf ("%s <%s> ==> ", question, answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%s\n", answer);
}

canonical_original_code:
void AskString(char *question, char *answer)
{
    char reply[256];
    printf ("%s <%s> ==> ", question, answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%s\n", answer);
}

variable_types:
question
char *

variable_types:
answer
char *

variable_types:
reply
char [256]


AskDouble

decompiled_code:
char *__fastcall AskDouble(const char *a1, double *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%lg> ==> ", a1, *a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%le", a2);
return result;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, double *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%lg> ==> ", a1, *a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%le", a2);
return result;
}

original_code:
void AskDouble (char *question, double *answer)
{
    char reply[256];
    printf ("%s <%lg> ==> ", question, *answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%le", answer);
}

canonical_original_code:
void AskDouble(char *question, double *answer)
{
    char reply[256];
    printf ("%s <%lg> ==> ", question, *answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%le", answer);
}

variable_types:
answer
double *


AskInt

decompiled_code:
char *__fastcall AskInt(const char *a1, unsigned int *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%d> ==> ", a1, *a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%d", a2);
return result;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, unsigned int *a2)
{
char *result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s <%d> ==> ", a1, *a2);
result = fgets(v3, 256, stdin);
if ( v3[0] )
result = (char *)_isoc99_sscanf(v3, "%d", a2);
return result;
}

original_code:
void AskInt (char *question, int *answer)
{
    char reply[256];
    printf ("%s <%d> ==> ", question, *answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%d", answer);
}

canonical_original_code:
void AskInt(char *question, int *answer)
{
    char reply[256];
    printf ("%s <%d> ==> ", question, *answer);
    fgets (reply, 256, stdin);
    if (reply[0])
        sscanf (reply, "%d", answer);
}

variable_types:
answer
int *


AskYesOrNo

decompiled_code:
__int64 __fastcall AskYesOrNo(const char *a1, unsigned int a2)
{
__int64 result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s (Y=yes, N=no) <%c> ==> ", a1, (unsigned int)(char)a2);
fgets(v3, 256, stdin);
result = (unsigned __int8)v3[0];
if ( v3[0] == 89 )
return 121LL;
if ( v3[0] <= 89 )
{
if ( !v3[0] )
return a2;
if ( v3[0] == 78 )
return 110LL;
return 0LL;
}
if ( v3[0] != 110 && v3[0] != 121 )
return 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, unsigned int a2)
{
__int64 result; // rax
char v3[264]; // [rsp+0h] [rbp-108h] BYREF

printf("%s (Y=yes, N=no) <%c> ==> ", a1, (unsigned int)(char)a2);
fgets(v3, 256, stdin);
result = (unsigned __int8)v3[0];
if ( v3[0] == 89 )
return 121LL;
if ( v3[0] <= 89 )
{
if ( !v3[0] )
return a2;
if ( v3[0] == 78 )
return 110LL;
return 0LL;
}
if ( v3[0] != 110 && v3[0] != 121 )
return 0LL;
return result;
}

original_code:
char AskYesOrNo (char *question, char standard)
{
    char reply[256];
    do {
        printf ("%s (Y=yes, N=no) <%c> ==> ", question, standard);
        fgets (reply, 256, stdin);
        switch (reply[0]) {
            case (char) 0:
                reply[0] = standard;
                break;
            case 'y':
            case 'Y':
                reply[0] = 'y';
                break;
            case 'n':
            case 'N':
                reply[0] = 'n';
                break;
            default:
                reply[0] = 0;
        }
    } while (!reply);
    return reply[0];
}

canonical_original_code:
char AskYesOrNo(char *question, char standard)
{
    char reply[256];
    do {
        printf ("%s (Y=yes, N=no) <%c> ==> ", question, standard);
        fgets (reply, 256, stdin);
        switch (reply[0]) {
            case (char) 0:
                reply[0] = standard;
                break;
            case 'y':
            case 'Y':
                reply[0] = 'y';
                break;
            case 'n':
            case 'N':
                reply[0] = 'n';
                break;
            default:
                reply[0] = 0;
        }
    } while (!reply);
    return reply[0];
}

variable_types: standard char

return_type: char


Spinner

decompiled_code:
int __fastcall Spinner(int a1)
{
int v1; // eax

v1 = a1 % 4;
if ( a1 % 4 == 2 )
{
putchar(47);
}
else if ( v1 == 3 )
{
putchar(124);
}
else if ( (a1 & 3) != 0 )
{
if ( v1 == 1 )
putchar(45);
}
else
{
putchar(92);
}
putchar(8);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
int v1; // eax

v1 = a1 % 4;
if ( a1 % 4 == 2 )
{
putchar(47);
}
else if ( v1 == 3 )
{
putchar(124);
}
else if ( (a1 & 3) != 0 )
{
if ( v1 == 1 )
putchar(45);
}
else
{
putchar(92);
}
putchar(8);
return fflush(stdout);
}

original_code:
void Spinner (int i)
{
    switch (i % 4) {
        case 1: printf ("%c", '-'); break;
        case 2: printf ("%c", '/'); break;
        case 3: printf ("%c", '|'); break;
        case 0: printf ("%c", '\\'); break;
    }
    printf ("%c", 0x08);
    fflush(stdout);
}

canonical_original_code:
void Spinner(int i)
{
    switch (i % 4) {
        case 1: printf ("%c", '-'); break;
        case 2: printf ("%c", '/'); break;
        case 3: printf ("%c", '|'); break;
        case 0: printf ("%c", '\\'); break;
    }
    printf ("%c", 0x08);
    fflush(stdout);
}

variable_types: i int


Iswap

decompiled_code:
__int64 __fastcall Iswap(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void Iswap (int *a, int *b)
{
    int c = *a;
    *a = *b;
    *b = c;
}

canonical_original_code:
void Iswap(int *a, int *b)
{
    int c = *a;
    *a = *b;
    *b = c;
}

variable_types:
a
int *

variable_types:
b
int *

variable_types: c int


Plot

original_code:
void Plot (int n, double *x, double *y)
{
    char screen[(20)+2][(75)+2+1];
    int i, r, c, nRow, nCol;
    double xMin, xMax, yMin, yMax, ColDel, RowDel;
    if (n < 2) return;
    for (r = 0; r < (20)+2; r++) {
        for (c = 0; c < (75)+2; c++)
            screen[r][c] = ' ';
        screen[r][(75)+2] = (char) 0;
    }
    for (r = 1; r <= (20); r++) {
        screen[r][0] = '|';
        screen[r][(75)+1] = '|';
    }
    for (c = 1; c <= (75); c++) {
        screen[0][c] = '-';
        screen[(20)+1][c] = '-';
    }
    xMin = x[1];
    xMax = x[1];
    yMin = y[1];
    yMax = y[1];
    for (i = 2; i <= n; i++) {
        xMin = (dminarg1=(xMin),dminarg2=(x[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        xMax = (dmaxarg1=(xMax),dmaxarg2=(x[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
        yMin = (dminarg1=(yMin),dminarg2=(y[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        yMax = (dmaxarg1=(yMax),dmaxarg2=(y[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
    }
    ColDel = ((75) - 1) / (xMax - xMin);
    RowDel = ((20) - 1) / (yMax - yMin);
    for (i = 1; i <= n; i++) {
        c = ColDel * (x[i] - xMin) + 1;
        r = RowDel * (y[i] - yMin) + 1;
        screen[r][c] = 'O';
    }
    printf ("row:    min=%lg   step=%lg   max=%lg\n", xMin, ColDel, xMax);
    printf ("column: min=%lg   step=%lg   max=%lg\n", yMin, RowDel, yMax);
    for (r = (20) + 1; r >= 0; r--)
        printf ("%s\n", screen[r]);
}

canonical_original_code:
void Plot(int n, double *x, double *y)
{
    char screen[-1][-1];
    int i; int r; int c; int nRow; int nCol;
    double xMin; double xMax; double yMin; double yMax; double ColDel; double RowDel;
    if (n < 2) return;
    for (r = 0; r < (20)+2; r++) {
        for (c = 0; c < (75)+2; c++)
            screen[r][c] = ' ';
        screen[r][(75)+2] = (char) 0;
    }
    for (r = 1; r <= (20); r++) {
        screen[r][0] = '|';
        screen[r][(75)+1] = '|';
    }
    for (c = 1; c <= (75); c++) {
        screen[0][c] = '-';
        screen[(20)+1][c] = '-';
    }
    xMin = x[1];
    xMax = x[1];
    yMin = y[1];
    yMax = y[1];
    for (i = 2; i <= n; i++) {
        xMin = (dminarg1=(xMin),dminarg2=(x[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        xMax = (dmaxarg1=(xMax),dmaxarg2=(x[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
        yMin = (dminarg1=(yMin),dminarg2=(y[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        yMax = (dmaxarg1=(yMax),dmaxarg2=(y[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
    }
    ColDel = ((75) - 1) / (xMax - xMin);
    RowDel = ((20) - 1) / (yMax - yMin);
    for (i = 1; i <= n; i++) {
        c = ColDel * (x[i] - xMin) + 1;
        r = RowDel * (y[i] - yMin) + 1;
        screen[r][c] = 'O';
    }
    printf ("row:    min=%lg   step=%lg   max=%lg\n", xMin, ColDel, xMax);
    printf ("column: min=%lg   step=%lg   max=%lg\n", yMin, RowDel, yMax);
    for (r = (20) + 1; r >= 0; r--)
        printf ("%s\n", screen[r]);
}

variable_types: n int

variable_types:
x
double *

variable_types:
y
double *

variable_types:
screen
char [-1][-1]

variable_types: r int

variable_types: nRow int

variable_types: nCol int

variable_types: xMin double

variable_types: xMax double

variable_types: yMin double

variable_types: yMax double

variable_types: ColDel double

variable_types: RowDel double


ResPlot

original_code:
void ResPlot (int n, double *x)
{
    char screen[(20)+2][(75)+2+1];
    int i, r, c, nRow, nCol, mPlus, mMinus, nPack;
    double xMin, xMax, ColDel, RowDel;
    if (n < 2) return;
    nPack = ((double) n / (75) - 1.0/n) + 1;
    nCol = ((double) n - 1./n)/nPack + 1;
    for (r = 0; r < (20)+2; r++) {
        for (c = 0; c < nCol+2; c++)
            screen[r][c] = ' ';
        screen[r][nCol+2] = (char) 0;
    }
    for (r = 1; r <= (20); r++) {
        screen[r][0] = '|';
        screen[r][nCol+1] = '|';
    }
    for (c = 1; c <= nCol; c++) {
        screen[0][c] = '-';
        screen[(20)+1][c] = '-';
    }
    xMin = x[1];
    xMax = x[1];
    for (i = 2; i <= n; i++) {
        xMin = (dminarg1=(xMin),dminarg2=(x[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        xMax = (dmaxarg1=(xMax),dmaxarg2=(x[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
    }
    RowDel = ((20) - 1) / (xMax - xMin);
    mMinus = RowDel*(-1.0 - xMin) + 1;
    mPlus = RowDel*( 1.0 - xMin) + 1;
    for (c = 1; c < nCol+1; c++) {
        screen[mMinus][c] = '=';
        screen[mPlus][c] = '=';
    }
    for (i = 1; i <= n; i++) {
        c = ((double) i - 1./n)/nPack + 1;
        r = RowDel * (x[i] - xMin) + 1;
        screen[r][c] = 'O';
    }
    printf ("row:    min=%lg   step=%lg   max=%lg\n", xMin, RowDel, xMax);
    printf ("column: min=%d    max=%d\n", 1, n);
    for (r = (20) + 1; r >= 0; r--)
        printf ("%s\n", screen[r]);
}

canonical_original_code:
void ResPlot(int n, double *x)
{
    char screen[-1][-1];
    int i; int r; int c; int nRow; int nCol; int mPlus; int mMinus; int nPack;
    double xMin; double xMax; double ColDel; double RowDel;
    if (n < 2) return;
    nPack = ((double) n / (75) - 1.0/n) + 1;
    nCol = ((double) n - 1./n)/nPack + 1;
    for (r = 0; r < (20)+2; r++) {
        for (c = 0; c < nCol+2; c++)
            screen[r][c] = ' ';
        screen[r][nCol+2] = (char) 0;
    }
    for (r = 1; r <= (20); r++) {
        screen[r][0] = '|';
        screen[r][nCol+1] = '|';
    }
    for (c = 1; c <= nCol; c++) {
        screen[0][c] = '-';
        screen[(20)+1][c] = '-';
    }
    xMin = x[1];
    xMax = x[1];
    for (i = 2; i <= n; i++) {
        xMin = (dminarg1=(xMin),dminarg2=(x[i]),(dminarg1) < (dminarg2) ? (dminarg1) : (dminarg2));
        xMax = (dmaxarg1=(xMax),dmaxarg2=(x[i]),(dmaxarg1) > (dmaxarg2) ? (dmaxarg1) : (dmaxarg2));
    }
    RowDel = ((20) - 1) / (xMax - xMin);
    mMinus = RowDel*(-1.0 - xMin) + 1;
    mPlus = RowDel*( 1.0 - xMin) + 1;
    for (c = 1; c < nCol+1; c++) {
        screen[mMinus][c] = '=';
        screen[mPlus][c] = '=';
    }
    for (i = 1; i <= n; i++) {
        c = ((double) i - 1./n)/nPack + 1;
        r = RowDel * (x[i] - xMin) + 1;
        screen[r][c] = 'O';
    }
    printf ("row:    min=%lg   step=%lg   max=%lg\n", xMin, RowDel, xMax);
    printf ("column: min=%d    max=%d\n", 1, n);
    for (r = (20) + 1; r >= 0; r--)
        printf ("%s\n", screen[r]);
}

variable_types: i int

variable_types: mPlus int

variable_types: mMinus int

variable_types: nPack int


BSearch

original_code:
void BSearch (double z, double *x, int NumPts, int *iTest)
{
    *iTest = -1;
    if (z < x[1]) return;
    *iTest = NumPts + 1;
    if (z > x[NumPts]) return;
    if (iLo < 1 || iHi > NumPts || iLo >= iHi) {
      iLo = 1;
      iHi = NumPts;
    }
    while (z < x[iLo])
        iLo /= 2;
    while (z > x[iHi])
      iHi = (iHi + 1 + NumPts) / 2;
    *iTest = iHi;
    while (iHi - iLo > 1) {
        *iTest = (iLo + iHi) / 2;
        if (z >= x[*iTest])
            iLo = *iTest;
        else
            iHi = *iTest;
    }
}

canonical_original_code:
void BSearch(double z, double *x, int NumPts, int *iTest)
{
    *iTest = -1;
    if (z < x[1]) return;
    *iTest = NumPts + 1;
    if (z > x[NumPts]) return;
    if (iLo < 1 || iHi > NumPts || iLo >= iHi) {
      iLo = 1;
      iHi = NumPts;
    }
    while (z < x[iLo])
        iLo /= 2;
    while (z > x[iHi])
      iHi = (iHi + 1 + NumPts) / 2;
    *iTest = iHi;
    while (iHi - iLo > 1) {
        *iTest = (iLo + iHi) / 2;
        if (z >= x[*iTest])
            iLo = *iTest;
        else
            iHi = *iTest;
    }
}

variable_types: z double

variable_types: NumPts int

variable_types:
iTest
int *


strtrim

original_code:
void strtrim (char *inStr, char *outStr, char* list)
{
  char *in = inStr;
  char *out = outStr;
  *outStr = 0;
  while (*in) {
    if (!((*__ctype_b_loc ())[(int) ((*in))] & (unsigned short int) _ISspace)) {
      *out = *in;
      out++;
      *out = 0;
    }
    in++;
  }
}

canonical_original_code:
void strtrim(char *inStr, char *outStr, char *list)
{
  char *in = inStr;
  char *out = outStr;
  *outStr = 0;
  while (*in) {
    if (!((*__ctype_b_loc ())[(int) ((*in))] & (unsigned short) _ISspace)) {
      *out = *in;
      out++;
      *out = 0;
    }
    in++;
  }
}

variable_types:
inStr
char *

variable_types:
outStr
char *

variable_types:
list
char *

variable_types:
in
char *

variable_types:
out
char *


reverse

repo: profil/miniature-society

original_code:
void reverse(int socket, char *data) {
 char tmp, *p;
 if(data == ((void *)0) || !(*data))
  return;
 p = data + strlen(data) - 1;
 while(p > data) {
  tmp = *data;
  *data = *p;
  *p = tmp;
  data++;
  p--;
 }
}

canonical_original_code:
void reverse(int socket, char *data) {
 char tmp; char *p;
 if(data == ((void *)0) || !(*data))
  return;
 p = data + strlen(data) - 1;
 while(p > data) {
  tmp = *data;
  *data = *p;
  *p = tmp;
  data++;
  p--;
 }
}

variable_types: socket int

variable_types:
data
char *

variable_types: tmp char

variable_types:
p
char *


whoami

decompiled_code:
int __fastcall whoami(unsigned int a1, char *a2)
{
return snprintf(a2, 0x400uLL, "%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int a1, char *a2)
{
return snprintf(a2, 0x400uLL, "%d\n", a1);
}

original_code:
void whoami(int s, char *data) {
 snprintf(data, 1024, "%d\n", s);
}

variable_types: s int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v4; // er14
void *v5; // rbp
__m128i v6; // xmm1
__m128i v7; // xmm2
__m128i v8; // xmm3
__m128i v9; // xmm4
__m128i v10; // xmm5
__m128i v11; // xmm6
__m128i v12; // xmm7
int v13; // er15
int v14; // eax
__int64 v15; // r14
int v16; // eax
char *v17; // rax
char *v18; // r9
size_t v19; // rax
unsigned __int64 v20; // rcx
size_t v21; // r14
bool v22; // zf
_BOOL8 v23; // rax
int v24; // eax
unsigned __int64 v25; // rcx
int v26; // er14
size_t v27; // rax
int fd; // [rsp+4h] [rbp-1F4h]
char *v30; // [rsp+8h] [rbp-1F0h]
char *v31; // [rsp+8h] [rbp-1F0h]
char *v32; // [rsp+8h] [rbp-1F0h]
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-1DCh] BYREF
void (__fastcall *v34)(__int64, const char *); // [rsp+28h] [rbp-1D0h]
char *s2; // [rsp+30h] [rbp-1C8h]
int (__fastcall *v36)(unsigned int, char *); // [rsp+38h] [rbp-1C0h]
struct sockaddr addr; // [rsp+40h] [rbp-1B8h] BYREF
__m128i v38[8]; // [rsp+C0h] [rbp-138h] BYREF
fd_set readfds; // [rsp+140h] [rbp-B8h] BYREF

v34 = reverse;
s2 = "whoami";
v36 = whoami;
if ( argc <= 2 )
{
fprintf(stderr, "usage: %s <host> <port>\n", *argv);
}
else
{
fd = con(argv[1], argv[2], 0LL);
if ( listen(fd, 10) == -1 )
{
close(fd);
fwrite("Error listening!\n", 1uLL, 0x11uLL, stderr);
return 1;
}
memset(v38, 0, sizeof(v38));
memset(&readfds, 0, sizeof(readfds));
v38[0].m128i_i64[fd / 64] |= 1LL << (fd % 64);
v3 = fd;
v4 = fd + 1;
LABEL_4:
while ( 1 )
{
v5 = malloc(0x400uLL);
v6 = _mm_loadu_si128(&v38[1]);
v7 = _mm_loadu_si128(&v38[2]);
v8 = _mm_loadu_si128(&v38[3]);
v9 = _mm_loadu_si128(&v38[4]);
v10 = _mm_loadu_si128(&v38[5]);
*(__m128i *)readfds.fds_bits = _mm_loadu_si128(v38);
v11 = _mm_loadu_si128(&v38[6]);
*(__m128i *)&readfds.fds_bits[2] = v6;
v12 = _mm_loadu_si128(&v38[7]);
*(__m128i *)&readfds.fds_bits[4] = v7;
*(__m128i *)&readfds.fds_bits[6] = v8;
*(__m128i *)&readfds.fds_bits[8] = v9;
*(__m128i *)&readfds.fds_bits[10] = v10;
*(__m128i *)&readfds.fds_bits[12] = v11;
*(__m128i *)&readfds.fds_bits[14] = v12;
if ( select(v4, &readfds, 0LL, 0LL, 0LL) == -1 )
break;
v13 = 0;
if ( v3 >= 0 )
{
while ( 1 )
{
while ( 1 )
{
v15 = v13 >> 6;
if ( (readfds.fds_bits[v15] & (1LL << v13)) != 0 )
break;
LABEL_11:
if ( v3 < ++v13 )
goto LABEL_18;
}
if ( fd != v13 )
break;
addr_len[0] = 128;
v16 = accept(fd, &addr, addr_len);
if ( v16 == -1 )
{
fwrite("Error in accept()\n", 1uLL, 0x12uLL, stderr);
goto LABEL_11;
}
v38[0].m128i_i64[v16 / 64] |= 1LL << (v16 % 64);
if ( v3 < v16 )
v3 = v16;
++v13;
puts("Connected by someone!");
if ( v3 < v13 )
{
LABEL_18:
v4 = v3 + 1;
goto LABEL_4;
}
}
v14 = recv(v13, v5, 0x3FFuLL, 0);
if ( v14 <= 0 )
{
if ( v14 )
fwrite("Error in recv()\n", 1uLL, 0x10uLL, stderr);
else
fprintf(stderr, "Socket %d disconnected.\n", (unsigned int)v13);
close(v13);
v38[0].m128i_i64[v15] &= ~(1LL << v13);
goto LABEL_11;
}
*((_BYTE *)v5 + v14) = 0;
printf("Got data: %s\nProcessing and sending...\n", (const char *)v5);
v17 = strchr((const char *)v5, 59);
v18 = v17;
if ( !v17 )
{
LABEL_20:
v19 = strlen((const char *)v5);
send(v13, v5, v19, 0);
goto LABEL_11;
}
v20 = 8LL;
v21 = v17 - (_BYTE *)v5;
if ( (unsigned __int64)(v17 - (_BYTE *)v5) <= 8 )
v20 = v17 - (_BYTE *)v5;
v22 = memcmp(v5, "reverse", v20) == 0;
v23 = !v22;
if ( !v22 )
{
v30 = v18;
v24 = strncmp((const char *)v5, s2, v21);
v18 = v30;
if ( v24 )
{
LABEL_26:
v25 = 10LL;
if ( v21 <= 0xA )
v25 = v21;
v22 = memcmp(v5, "broadcast", v25) == 0;
v26 = !v22;
if ( v22 )
{
v31 = v18;
puts("Sending broadcast...");
v5 = v31 + 1;
do
{
if ( (v38[0].m128i_i64[v26 >> 6] & (1LL << v26)) != 0 && fd != v26 && v13 != v26 )
{
v27 = strlen((const char *)v5);
send(v26, v5, v27, 0);
}
++v26;
}
while ( v26 <= v3 );
}
goto LABEL_20;
}
v23 = 1LL;
}
v5 = v18 + 1;
v32 = v18;
v21 = -1LL;
(*(&v34 + 2 * v23))((unsigned int)v13, v18 + 1);
v18 = v32;
goto LABEL_26;
}
}
fwrite("Error in select()\n", 1uLL, 0x12uLL, stderr);
}
return 1;
}

original_code:
int main(int argc, char *argv[]) {
 int s, inc, numfds;
 struct sockaddr_storage sinc;
 struct commands cmd[] = { {"reverse", reverse},
        {"whoami", whoami}
       };
 fd_set md, rd;
 if(argc < 3) {
  fprintf(stderr, "usage: %s <host> <port>\n", argv[0]);
  return 1;
 }
 s = con(argv[1], argv[2], 0);
 if(listen(s, 10) == -1) {
  close(s);
  fprintf(stderr, "Error listening!\n");
  return 1;
 }
 numfds = s;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&md)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&md)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
 while(1) {
  int msglen, i;
  socklen_t addr_len;
  char *data = malloc(sizeof(char) * 1024);
  rd = md;
  if(select(numfds+1, &rd, 0, 0, 0) == -1) {
   fprintf(stderr, "Error in select()\n");
   return 1;
  }
  for(i = 0; i <= numfds; i++) {
   if(((((&rd)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if(i == s) {
     addr_len = sizeof sinc;
     if((inc = accept(s, (struct sockaddr *)&sinc, &addr_len)) == -1) {
      fprintf(stderr, "Error in accept()\n");
     }
     else {
      ((void) (((&md)->__fds_bits)[((inc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((inc) % (8 * (int) sizeof (__fd_mask)))))));
      if(inc > numfds)
       numfds = inc;
      printf("Connected by someone!\n");
     }
    }
    else {
     if((msglen = recv(i, data, 1024 -1, 0)) <= 0) {
      if(msglen == 0)
       fprintf(stderr, "Socket %d disconnected.\n", i);
      else
       fprintf(stderr, "Error in recv()\n");
      close(i);
      ((void) (((&md)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
     }
     else {
      char *index;
      int j;
      data[msglen] = '\0';
      printf("Got data: %s\nProcessing and sending...\n", data);
      if((index = strchr(data, ';')) != ((void *)0)) {
       for(j = 0; j < sizeof(cmd)/sizeof(cmd[0]); j++) {
        if(!strncmp(data, cmd[j].name, index-data)) {
         data = index + 1;
         cmd[j].func(i, data);
         break;
        }
       }
       if(!strncmp(data, "broadcast", index-data)) {
        printf("Sending broadcast...\n");
        data = index + 1;
        for(j = 0; j <= numfds; j++) {
         if(((((&md)->__fds_bits)[((j) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((j) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
          if(j != s && j != i) {
           send(j, data, strlen(data), 0);
          }
         }
        }
       }
      }
      send(i, data, strlen(data), 0);
     }
    }
   }
  }
 }
 close(s);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int s; int inc; int numfds;
 struct sockaddr_storage sinc;
 struct commands cmd[] = { {"reverse", reverse},
        {"whoami", whoami}
       };
 struct fd_set md; struct fd_set rd;
 if(argc < 3) {
  fprintf(stderr, "usage: %s <host> <port>\n", argv[0]);
  return 1;
 }
 s = con(argv[1], argv[2], 0);
 if(listen(s, 10) == -1) {
  close(s);
  fprintf(stderr, "Error listening!\n");
  return 1;
 }
 numfds = s;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&md)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&md)->__fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
 while(1) {
  int msglen; int i;
  unsigned int addr_len;
  char *data = malloc(sizeof(char) * 1024);
  rd = md;
  if(select(numfds+1, &rd, 0, 0, 0) == -1) {
   fprintf(stderr, "Error in select()\n");
   return 1;
  }
  for(i = 0; i <= numfds; i++) {
   if(((((&rd)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    if(i == s) {
     addr_len = sizeof sinc;
     if((inc = accept(s, (struct sockaddr *)&sinc, &addr_len)) == -1) {
      fprintf(stderr, "Error in accept()\n");
     }
     else {
      ((void) (((&md)->__fds_bits)[((inc) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((inc) % (8 * (int) sizeof (__fd_mask)))))));
      if(inc > numfds)
       numfds = inc;
      printf("Connected by someone!\n");
     }
    }
    else {
     if((msglen = recv(i, data, 1024 -1, 0)) <= 0) {
      if(msglen == 0)
       fprintf(stderr, "Socket %d disconnected.\n", i);
      else
       fprintf(stderr, "Error in recv()\n");
      close(i);
      ((void) (((&md)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
     }
     else {
      char *index;
      int j;
      data[msglen] = '\0';
      printf("Got data: %s\nProcessing and sending...\n", data);
      if((index = strchr(data, ';')) != ((void *)0)) {
       for(j = 0; j < sizeof(cmd)/sizeof(cmd[0]); j++) {
        if(!strncmp(data, cmd[j].name, index-data)) {
         data = index + 1;
         cmd[j].func(i, data);
         break;
        }
       }
       if(!strncmp(data, "broadcast", index-data)) {
        printf("Sending broadcast...\n");
        data = index + 1;
        for(j = 0; j <= numfds; j++) {
         if(((((&md)->__fds_bits)[((j) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((j) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
          if(j != s && j != i) {
           send(j, data, strlen(data), 0);
          }
         }
        }
       }
      }
      send(i, data, strlen(data), 0);
     }
    }
   }
  }
 }
 close(s);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: inc int

variable_types: numfds int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types: struct commands { char *name; void (*func)(int, char *); } []

variable_types:
md
struct fd_set { long __fds_bits[-1]; }

variable_types:
rd
struct fd_set { long __fds_bits[-1]; }

variable_types: msglen int

variable_types: i int

variable_types:
index
char *

variable_types: j int

return_type: int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


repo: profil/raytracer

original_code:
int sphere_intersect(struct ray r, struct sphere *spheres, int spheres_len, int *sphere_id) {
 int i;
 float t = 100000, distance = 0;
 for(i = 0; i < spheres_len; i++) {
  distance = sphere_collision(r, spheres[i]);
  if(distance > 0.0f) {
   if(distance < t) {
    t = distance;
    *sphere_id = i;
   }
  }
 }
 return t != 100000 ? t : 0;
}

canonical_original_code:
int sphere_intersect(struct ray r, struct sphere *spheres, int spheres_len, int *sphere_id) {
 int i;
 float t = 100000; float distance = 0;
 for(i = 0; i < spheres_len; i++) {
  distance = sphere_collision(r, spheres[i]);
  if(distance > 0.0f) {
   if(distance < t) {
    t = distance;
    *sphere_id = i;
   }
  }
 }
 return t != 100000 ? t : 0;
}

variable_types: struct ray { struct vector { float x; } p; struct vector d; }

variable_types: struct sphere { struct vector c; float r; unsigned int color; } *

variable_types: t float

variable_types: distance float

user_defined_types: struct ray { struct vector p; struct vector d; }


vec

decompiled_code:
__m128i __fastcall vec(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

canonical_decompiled_code:
__m128i __fastcall func0(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

original_code:
struct vector vec(float x, float y, float z) {
 struct vector c;
 c.x = x;
 c.y = y;
 c.z = z;
 return c;
}

variable_types: x float

variable_types: y float

variable_types: z float

variable_types:
c
struct vector { float x; }

return_type: struct vector { float x; }


add

original_code:
struct vector add(struct vector a, struct vector b) {
 struct vector c;
 c.x = a.x + b.x;
 c.y = a.y + b.y;
 c.z = a.z + b.z;
 return c;
}

variable_types:
a
struct vector

variable_types:
b
struct vector


sub

original_code:
struct vector sub(struct vector a, struct vector b) {
 struct vector c;
 c.x = a.x - b.x;
 c.y = a.y - b.y;
 c.z = a.z - b.z;
 return c;
}


scale

original_code:
struct vector scale(float i, struct vector a) {
 struct vector c;
 c.x = a.x * i;
 c.y = a.y * i;
 c.z = a.z * i;
 return c;
}

variable_types: i float


cross

decompiled_code:
__m128i __fastcall cross(double a1, float a2, double a3, float a4)
{
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

*(float *)&v5.m128i_i32[1] = (float)(a2 * *(float *)&a3) - (float)(a4 * *(float *)&a1);
*(float *)v5.m128i_i32 = (float)(*((float *)&a1 + 1) * a4) - (float)(a2 * *((float *)&a3 + 1));
return _mm_loadl_epi64(&v5);
}

canonical_decompiled_code:
__m128i __fastcall func4(double a1, float a2, double a3, float a4)
{
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

*(float *)&v5.m128i_i32[1] = (float)(a2 * *(float *)&a3) - (float)(a4 * *(float *)&a1);
*(float *)v5.m128i_i32 = (float)(*((float *)&a1 + 1) * a4) - (float)(a2 * *((float *)&a3 + 1));
return _mm_loadl_epi64(&v5);
}

original_code:
struct vector cross(struct vector a, struct vector b) {
 struct vector c;
 c.x = a.y*b.z - a.z*b.y;
 c.y = a.z*b.x - a.x*b.z;
 c.z = a.x*b.y - a.y*b.x;
 return c;
}


dot

decompiled_code:
float __fastcall dot(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

canonical_decompiled_code:
float __fastcall func5(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

original_code:
float dot(struct vector a, struct vector b) {
 return a.x*b.x + a.y*b.y + a.z*b.z;
}

variable_types:
a
struct vector { float x; }

return_type: float


norm

decompiled_code:
__m128i __fastcall norm(double a1, float a2)
{
double v2; // xmm0_8
double v3; // xmm0_8
float v4; // xmm0_4

v2 = dot(a1, a2, a1, a2);
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = 1.0 / v3;
return scale(v4, a1);
}

canonical_decompiled_code:
__m128i __fastcall func6(double a1, float a2)
{
double v2; // xmm0_8
double v3; // xmm0_8
float v4; // xmm0_4

v2 = func5(a1, a2, a1, a2);
if ( v2 < 0.0 )
v3 = sqrt(v2);
else
v3 = sqrt(v2);
v4 = 1.0 / v3;
return func3(v4, a1);
}

original_code:
struct vector norm(struct vector a) {
 return scale(1.0f / sqrt(dot(a, a)), a);
}


clamp

decompiled_code:
__int64 __fastcall clamp(int a1)
{
__int64 result; // rax

result = 255LL;
if ( a1 <= 255 )
result = (unsigned int)a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax

result = 255LL;
if ( a1 <= 255 )
result = (unsigned int)a1;
return result;
}

original_code:
unsigned char clamp(int input) {
 if(input > 0xff) {
  return 0xff;
 }
 else {
  return (unsigned char)input;
 }
}

variable_types: input int

return_type: unsigned char


radiance

original_code:
unsigned int radiance(struct ray current_ray, struct sphere *spheres, int spheres_len, struct sphere *lights, int lights_len, int depth) {
 float distance, lambert, lambertAmount = 0;
 int sphere_id, i;
 unsigned int color;
 unsigned char r, g, b;
 struct sphere current_sphere;
 struct vector hit, normal;
 struct ray shadow;
 for(color = 0; depth < 5; depth++) {
  if((distance = sphere_intersect(current_ray, spheres, spheres_len, &sphere_id)) == 0) {
   break;
  }
  current_sphere = spheres[sphere_id];
  hit = add(current_ray.p, scale(distance, current_ray.d));
  normal = norm(sub(hit, current_sphere.c));
  r = current_sphere.color >> 16 & 0xff;
  g = current_sphere.color >> 8 & 0xff;
  b = current_sphere.color & 0xff;
  for(i = 0; i < lights_len; i++) {
   shadow.d = norm(sub(lights[i].c, hit));
   shadow.p = hit;
   if(!sphere_intersect(shadow, spheres, spheres_len, &sphere_id)) {
    if((lambert = dot(shadow.d, normal)) > 0.0f) {
     lambertAmount += lambert;
    }
   }
  }
  if(lambertAmount > 1)
   lambertAmount = 1;
  r = clamp(r * lambertAmount);
  g = clamp(g * lambertAmount);
  b = clamp(b * lambertAmount);
  color = r << 16 | g << 8 | b;
  current_ray.p = hit;
  current_ray.d = sub(current_ray.d, scale(2.0f * dot(normal, current_ray.d), normal));
 }
 return color;
}

canonical_original_code:
unsigned int radiance(struct ray current_ray, struct sphere *spheres, int spheres_len, struct sphere *lights, int lights_len, int depth) {
 float distance; float lambert; float lambertAmount = 0;
 int sphere_id; int i;
 unsigned int color;
 unsigned char r; unsigned char g; unsigned char b;
 struct sphere current_sphere;
 struct vector hit; struct vector normal;
 struct ray shadow;
 for(color = 0; depth < 5; depth++) {
  if((distance = sphere_intersect(current_ray, spheres, spheres_len, &sphere_id)) == 0) {
   break;
  }
  current_sphere = spheres[sphere_id];
  hit = add(current_ray.p, scale(distance, current_ray.d));
  normal = norm(sub(hit, current_sphere.c));
  r = current_sphere.color >> 16 & 0xff;
  g = current_sphere.color >> 8 & 0xff;
  b = current_sphere.color & 0xff;
  for(i = 0; i < lights_len; i++) {
   shadow.d = norm(sub(lights[i].c, hit));
   shadow.p = hit;
   if(!sphere_intersect(shadow, spheres, spheres_len, &sphere_id)) {
    if((lambert = dot(shadow.d, normal)) > 0.0f) {
     lambertAmount += lambert;
    }
   }
  }
  if(lambertAmount > 1)
   lambertAmount = 1;
  r = clamp(r * lambertAmount);
  g = clamp(g * lambertAmount);
  b = clamp(b * lambertAmount);
  color = r << 16 | g << 8 | b;
  current_ray.p = hit;
  current_ray.d = sub(current_ray.d, scale(2.0f * dot(normal, current_ray.d), normal));
 }
 return color;
}

variable_types:
lights
struct sphere *

variable_types: depth int

variable_types: lambert float

variable_types: lambertAmount float

variable_types:
color
unsigned int

variable_types:
r
unsigned char

variable_types:
g
unsigned char

variable_types:
b
unsigned char

variable_types: struct sphere { struct vector { float x; } c; float r; unsigned int color; }

variable_types:
hit
struct vector { float x; }

variable_types:
normal
struct vector { float x; }

return_type: unsigned int

user_defined_types: struct sphere { struct vector c; float r; unsigned int color; }


ray

decompiled_code:
__int64 __fastcall ray(__int64 a1, double a2, float a3, double a4, float a5)
{
__int64 result; // rax

result = a1;
*(double *)a1 = a2;
*(float *)(a1 + 8) = a3;
*(double *)(a1 + 12) = a4;
*(float *)(a1 + 20) = a5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, double a2, float a3, double a4, float a5)
{
__int64 result; // rax

result = a1;
*(double *)a1 = a2;
*(float *)(a1 + 8) = a3;
*(double *)(a1 + 12) = a4;
*(float *)(a1 + 20) = a5;
return result;
}

original_code:
struct ray ray(struct vector p, struct vector d) {
 struct ray r;
 r.p = p;
 r.d = d;
 return r;
}

variable_types:
p
struct vector

variable_types:
d
struct vector

variable_types: struct ray { struct vector { float x; } p; struct vector d; }


repo: programble/forklimit

decompiled_code:
void *__fastcall get_func_ptr(void *a1, const char *a2)
{
void *result; // rax
char *v3; // rax

result = dlsym(a1, a2);
if ( !result )
{
v3 = dlerror();
fprintf(stderr, "forklimit: cannot find function %s: %s\n", a2, v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, const char *a2)
{
void *result; // rax
char *v3; // rax

result = dlsym(a1, a2);
if ( !result )
{
v3 = dlerror();
fprintf(stderr, "forklimit: cannot find function %s: %s\n", a2, v3);
exit(1);
}
return result;
}

original_code:
static inline void *get_func_ptr(void *handle, char *sym)
{
    void *ptr = dlsym(handle, sym);
    if (!ptr) {
        fprintf(stderr, "forklimit: " "cannot find function %s: %s\n", sym, dlerror());
        exit(1);
    }
    return ptr;
}

variable_types:
handle
void *

variable_types:
sym
char *

variable_types:
ptr
void *

return_type: void *


init

decompiled_code:
char *init()
{
void *v0; // rax
void *v1; // rbp
_DWORD *v2; // rax
char *v3; // rdi
int v4; // eax
char *v5; // rax
char *result; // rax
char *v7; // rax

v0 = dlopen("libc.so.6", 1);
if ( !v0 )
{
v7 = dlerror();
fprintf(stderr, "forklimit: cannot open libc: %s\n", v7);
exit(1);
}
v1 = v0;
fork_ptr = (__int64)get_func_ptr(v0, "fork");
execve_ptr = (__int64)get_func_ptr(v1, "execve");
v2 = mmap(0LL, 4uLL, 3, 33, -1, 0LL);
fork_count = (__int64)v2;
if ( v2 == (_DWORD *)-1LL )
{
perror("forklimit: mmap");
exit(1);
}
*v2 = 0;
v3 = getenv("FORK_LIMIT");
v4 = fork_limit;
if ( v3 )
{
v4 = atoi(v3);
fork_limit = v4;
}
if ( !v4 )
fork_limit = 100;
v5 = getenv("LD_PRELOAD");
result = strdup(v5);
ld_preload = result;
return result;
}

canonical_decompiled_code:
char *func3()
{
void *v0; // rax
void *v1; // rbp
_DWORD *v2; // rax
char *v3; // rdi
int v4; // eax
char *v5; // rax
char *result; // rax
char *v7; // rax

v0 = dlopen("libc.so.6", 1);
if ( !v0 )
{
v7 = dlerror();
fprintf(stderr, "forklimit: cannot open libc: %s\n", v7);
exit(1);
}
v1 = v0;
fork_ptr = (__int64)func2(v0, "fork");
execve_ptr = (__int64)func2(v1, "execve");
v2 = mmap(0LL, 4uLL, 3, 33, -1, 0LL);
fork_count = (__int64)v2;
if ( v2 == (_DWORD *)-1LL )
{
perror("forklimit: mmap");
exit(1);
}
*v2 = 0;
v3 = getenv("FORK_LIMIT");
v4 = fork_limit;
if ( v3 )
{
v4 = atoi(v3);
fork_limit = v4;
}
if ( !v4 )
fork_limit = 100;
v5 = getenv("LD_PRELOAD");
result = strdup(v5);
ld_preload = result;
return result;
}

original_code:
static void __attribute__((constructor)) init(void)
{
    void *handle = dlopen("libc.so.6", 0x00001);
    if (!handle) {
        fprintf(stderr, "forklimit: " "cannot open libc: %s\n", dlerror());
        exit(1);
    }
    fork_ptr = get_func_ptr(handle, "fork");
    execve_ptr = get_func_ptr(handle, "execve");
    fork_count = mmap(((void *)0), sizeof(int), 0x1 | 0x2, 0x20 | 0x01, -1, 0);
    if (fork_count == ((void *) -1)) {
        perror("forklimit: " "mmap");
        exit(1);
    }
    *fork_count = 0;
    char *env_limit = getenv("FORK_LIMIT");
    if (env_limit)
        fork_limit = atoi(env_limit);
    if (!fork_limit)
        fork_limit = 100;
    ld_preload = strdup(getenv("LD_PRELOAD"));
}

canonical_original_code:
static void init()
{
    void *handle = dlopen("libc.so.6", 0x00001);
    if (!handle) {
        fprintf(stderr, "forklimit: " "cannot open libc: %s\n", dlerror());
        exit(1);
    }
    fork_ptr = get_func_ptr(handle, "fork");
    execve_ptr = get_func_ptr(handle, "execve");
    fork_count = mmap(((void *)0), sizeof(int), 0x1 | 0x2, 0x20 | 0x01, -1, 0);
    if (fork_count == ((void *) -1)) {
        perror("forklimit: " "mmap");
        exit(1);
    }
    *fork_count = 0;
    char *env_limit = getenv("FORK_LIMIT");
    if (env_limit)
        fork_limit = atoi(env_limit);
    if (!fork_limit)
        fork_limit = 100;
    ld_preload = strdup(getenv("LD_PRELOAD"));
}


fork

decompiled_code:
__int64 fork()
{
_DWORD *v0; // rdx
int v1; // eax
bool v2; // cc

v0 = (_DWORD *)fork_count;
if ( *(_DWORD *)fork_count == -1 )
LABEL_5:
exit(1);
v1 = *(_DWORD *)fork_count + 1;
v2 = v1 <= fork_limit;
*(_DWORD *)fork_count = v1;
if ( !v2 )
{
*v0 = -1;
fwrite("forklimit: fork limit exceeded\n", 1uLL, 0x1FuLL, stderr);
goto LABEL_5;
}
return fork_ptr();
}

canonical_decompiled_code:
__int64 func8()
{
_DWORD *v0; // rdx
int v1; // eax
bool v2; // cc

v0 = (_DWORD *)fork_count;
if ( *(_DWORD *)fork_count == -1 )
LABEL_5:
exit(1);
v1 = *(_DWORD *)fork_count + 1;
v2 = v1 <= fork_limit;
*(_DWORD *)fork_count = v1;
if ( !v2 )
{
*v0 = -1;
fwrite("forklimit: fork limit exceeded\n", 1uLL, 0x1FuLL, stderr);
goto LABEL_5;
}
return fork_ptr();
}

original_code:
pid_t fork(void)
{
    if (*fork_count == -1)
        exit(1);
    if (++*fork_count > fork_limit) {
        *fork_count = -1;
        fprintf(stderr, "forklimit: " "fork limit exceeded\n");
        exit(1);
    }
    return (*fork_ptr)();
}

canonical_original_code:
int fork()
{
    if (*fork_count == -1)
        exit(1);
    if (++*fork_count > fork_limit) {
        *fork_count = -1;
        fprintf(stderr, "forklimit: " "fork limit exceeded\n");
        exit(1);
    }
    return (*fork_ptr)();
}


execve

decompiled_code:
__int64 __fastcall execve(__int64 a1, __int64 a2, const char **a3)
{
const char *v3; // rax
const char *v4; // rbp
const char **v7; // r12
const char **v8; // r15

v3 = *a3;
if ( !*a3 )
{
LABEL_7:
fwrite("forklimit: LD_PRELOAD changed\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
v4 = ld_preload;
v7 = a3;
v8 = a3;
while ( memcmp(v3, "LD_PRELOAD", 0xAuLL) || strcmp(v3 + 11, v4) )
{
v3 = v8[1];
++v8;
if ( !v3 )
goto LABEL_7;
}
return execve_ptr(a1, a2, v7);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, const char **a3)
{
const char *v3; // rax
const char *v4; // rbp
const char **v7; // r12
const char **v8; // r15

v3 = *a3;
if ( !*a3 )
{
LABEL_7:
fwrite("forklimit: LD_PRELOAD changed\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}
v4 = ld_preload;
v7 = a3;
v8 = a3;
while ( memcmp(v3, "LD_PRELOAD", 0xAuLL) || strcmp(v3 + 11, v4) )
{
v3 = v8[1];
++v8;
if ( !v3 )
goto LABEL_7;
}
return execve_ptr(a1, a2, v7);
}

original_code:
int execve(const char *filename, char *const argv[], char *const envp[])
{
    for (char *const *env = envp; *env; env++) {
        if (!strncmp(*env, "LD_PRELOAD", 10) && !strcmp(*env + 11, ld_preload))
            return (*execve_ptr)(filename, argv, envp);
    }
    fprintf(stderr, "forklimit: " "LD_PRELOAD changed\n");
    exit(1);
}

canonical_original_code:
int execve(char *filename, char *argv[], char *envp[])
{
    for (char **env = envp; *env; env++) {
        if (!strncmp(*env, "LD_PRELOAD", 10) && !strcmp(*env + 11, ld_preload))
            return (*execve_ptr)(filename, argv, envp);
    }
    fprintf(stderr, "forklimit: " "LD_PRELOAD changed\n");
    exit(1);
}

variable_types:
filename
char *

variable_types:
argv
char *[]

variable_types:
envp
char *[]

variable_types:
env
char **


repo: prosig/max-subarray

decompiled_code:
__suseconds_t get_usecs()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func8()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
long
get_usecs(void)
{
    struct timeval t;
    gettimeofday(&t,((void *)0));
    return t.tv_sec*1000000+t.tv_usec;
}

canonical_original_code:
long get_usecs()
{
    struct timeval t;
    gettimeofday(&t,((void *)0));
    return t.tv_sec*1000000+t.tv_usec;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: long


decompiled_code:
void __fastcall free_matrix(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

if ( !ptr )
{
puts("[ERROR] could not free memory for matrix - already freed");
exit(1);
}
v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

canonical_decompiled_code:
void __fastcall func13(void *ptr, int a2)
{
void *v2; // r12
void **v3; // rbx
void **v4; // rbp
void *v5; // rdi

if ( !ptr )
{
puts("[ERROR] could not free memory for matrix - already freed");
exit(1);
}
v2 = ptr;
if ( a2 > 0 )
{
v3 = (void **)ptr;
v4 = (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8);
do
{
v5 = *v3++;
free(v5);
}
while ( v3 != v4 );
}
free(v2);
}

original_code:
void
free_matrix(
    int** matrix,
    int n)
{
    if(!matrix)
    {
        printf("[ERROR] could not free memory for matrix - already freed\n");
        exit(1);
    }
    else
    {
        for (int i=0; i<n; i++)
        {
            free(matrix[i]);
        }
    }
    free(matrix);
}

canonical_original_code:
void free_matrix(int **matrix, int n)
{
    if(!matrix)
    {
        printf("[ERROR] could not free memory for matrix - already freed\n");
        exit(1);
    }
    else
    {
        for (int i = 0; i<n; i++)
        {
            free(matrix[i]);
        }
    }
    free(matrix);
}

variable_types:
matrix
int **

variable_types: n int

variable_types: i int


decompiled_code:
int __fastcall print_matrix(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // r14
__int64 v4; // r13
__int64 v6; // rbp
__int64 v7; // rbx
__int64 v8; // rsi
int result; // eax

if ( a2 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v6 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v7 = 0LL;
if ( a3 > 0 )
{
do
{
v8 = *(unsigned int *)(*v3 + v7);
v7 += 4LL;
printf("%d\t", v8);
}
while ( v6 != v7 );
}
++v3;
result = putchar(10);
}
while ( v3 != (_QWORD *)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // r14
__int64 v4; // r13
__int64 v6; // rbp
__int64 v7; // rbx
__int64 v8; // rsi
int result; // eax

if ( a2 > 0 )
{
v3 = a1;
v4 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v6 = 4LL * (unsigned int)(a3 - 1) + 4;
do
{
v7 = 0LL;
if ( a3 > 0 )
{
do
{
v8 = *(unsigned int *)(*v3 + v7);
v7 += 4LL;
printf("%d\t", v8);
}
while ( v6 != v7 );
}
++v3;
result = putchar(10);
}
while ( v3 != (_QWORD *)v4 );
}
return result;
}

original_code:
void
print_matrix(
    int **matrix,
    int m,
    int n)
{
    for(int i=0; i<m; i++)
    {
        for(int j=0; j<n; j++)
        {
            printf("%d\t", matrix[i][j]);
        }
        printf("\n");
    }
}

canonical_original_code:
void print_matrix(int **matrix, int m, int n)
{
    for(int i = 0; i<m; i++)
    {
        for(int j = 0; j<n; j++)
        {
            printf("%d\t", matrix[i][j]);
        }
        printf("\n");
    }
}

variable_types: m int

variable_types: j int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebp
char v6; // [rsp+Fh] [rbp-E9h]
char buf[112]; // [rsp+10h] [rbp-E8h] BYREF
char v8[120]; // [rsp+80h] [rbp-78h] BYREF

v3 = open("/dev/testCharDevice", 2, envp);
if ( v3 == -1 )
{
printf("file %s either does not exit, or locked by another process, or you are not root!\n", "/dev/testCharDevice");
exit(-1);
}
v4 = v3;
printf("r - read from device,\nw- write from device\nEnter command: ");
__isoc99_scanf();
if ( v6 == 114 )
{
read(v4, v8, 0x64uLL);
printf("device: %s\n", v8);
}
else if ( v6 == 119 )
{
printf("enter data: ");
__isoc99_scanf();
write(v4, buf, 0x64uLL);
}
else
{
puts("command not recognized");
}
close(v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  int i, fd;
  char ch, write_buf[100], read_buf[100];
  fd = open("/dev/testCharDevice", 02);
  if(fd == -1){
    printf("file %s either does not exit, or locked by another process, or you are not root!\n", "/dev/testCharDevice");
    exit(-1);
  }
  printf("r - read from device,\nw- write from device\nEnter command: ");
  scanf("%c", &ch);
  switch (ch){
  case 'w':
    printf ("enter data: ");
    scanf("%s", write_buf);
    write(fd, write_buf, sizeof(write_buf));
    break;
  case 'r':
    read(fd, read_buf, sizeof(read_buf));
    printf ("device: %s\n", read_buf);
    break;
  default:
    printf ("command not recognized\n");
    break;
  }
  close(fd);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int i; int fd;
  char ch; char write_buf[100]; char read_buf[100];
  fd = open("/dev/testCharDevice", 02);
  if(fd == -1){
    printf("file %s either does not exit, or locked by another process, or you are not root!\n", "/dev/testCharDevice");
    exit(-1);
  }
  printf("r - read from device,\nw- write from device\nEnter command: ");
  scanf("%c", &ch);
  switch (ch){
  case 'w':
    printf ("enter data: ");
    scanf("%s", write_buf);
    write(fd, write_buf, sizeof(write_buf));
    break;
  case 'r':
    read(fd, read_buf, sizeof(read_buf));
    printf ("device: %s\n", read_buf);
    break;
  default:
    printf ("command not recognized\n");
    break;
  }
  close(fd);
  return 0;
}

variable_types: argc int

variable_types: fd int

variable_types: ch char


repo: psankar/simplefs

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er12
_BOOL8 v5; // rbp
int v6; // edi
int v8; // [rsp+0h] [rbp-178h] BYREF
__int64 v9; // [rsp+8h] [rbp-170h]
__int64 v10; // [rsp+10h] [rbp-168h]
__int64 v11; // [rsp+18h] [rbp-160h]
__int128 v12[2]; // [rsp+20h] [rbp-158h] BYREF
char v13[16]; // [rsp+40h] [rbp-138h] BYREF
char v14[264]; // [rsp+50h] [rbp-128h] BYREF

strcpy(v13, "urugan.\n");
v12[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402570);
qmemcpy(v14, "vanakkam", sizeof(v14));
v8 = 0x8000;
v9 = 3LL;
v10 = 5LL;
v11 = 41LL;
v12[1] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402580);
if ( argc == 2 )
{
v3 = open(argv[1], 2);
v4 = v3;
if ( v3 == -1 )
{
perror("Error opening the device");
}
else
{
if ( (unsigned int)write_superblock(v3)
|| (unsigned int)write_root_inode(v4)
|| (unsigned int)write_journal_inode(v4)
|| (unsigned int)write_welcome_inode(v4)
|| (unsigned int)write_journal(v4, &v8)
|| (unsigned int)write_dirent(v4) )
{
LODWORD(v5) = 1;
}
else
{
v5 = (unsigned int)write_block(v4, v12, v11) != 0;
}
v6 = v4;
v4 = v5;
close(v6);
}
}
else
{
v4 = -1;
puts("Usage: mkfs-simplefs <device>");
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er12
_BOOL8 v5; // rbp
int v6; // edi
int v8; // [rsp+0h] [rbp-178h] BYREF
__int64 v9; // [rsp+8h] [rbp-170h]
__int64 v10; // [rsp+10h] [rbp-168h]
__int64 v11; // [rsp+18h] [rbp-160h]
__int128 v12[2]; // [rsp+20h] [rbp-158h] BYREF
char v13[16]; // [rsp+40h] [rbp-138h] BYREF
char v14[264]; // [rsp+50h] [rbp-128h] BYREF

strcpy(v13, "urugan.\n");
v12[0] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402570);
qmemcpy(v14, "vanakkam", sizeof(v14));
v8 = 0x8000;
v9 = 3LL;
v10 = 5LL;
v11 = 41LL;
v12[1] = (__int128)_mm_load_si128((const __m128i *)&xmmword_402580);
if ( argc == 2 )
{
v3 = open(argv[1], 2);
v4 = v3;
if ( v3 == -1 )
{
perror("Error opening the device");
}
else
{
if ( (unsigned int)func10(v3)
|| (unsigned int)func7(v4)
|| (unsigned int)func8(v4)
|| (unsigned int)func9(v4)
|| (unsigned int)func11(v4, &v8)
|| (unsigned int)func12(v4) )
{
LODWORD(v5) = 1;
}
else
{
v5 = (unsigned int)func13(v4, v12, v11) != 0;
}
v6 = v4;
v4 = v5;
close(v6);
}
}
else
{
v4 = -1;
puts("Usage: mkfs-simplefs <device>");
}
return v4;
}

original_code:
int main(int argc, char *argv[])
{
 int fd;
 ssize_t ret;
 char welcomefile_body[] = "Love is God. God is Love. Anbe Murugan.\n";
 struct simplefs_inode welcome = {
  .mode = 0100000,
  .inode_no = (SIMPLEFS_JOURNAL_INODE_NUMBER + 1),
  .data_block_number = (SIMPLEFS_ROOTDIR_DATABLOCK_NUMBER + 1),
  .file_size = sizeof(welcomefile_body),
 };
 struct simplefs_dir_record record = {
  .filename = "vanakkam",
  .inode_no = (SIMPLEFS_JOURNAL_INODE_NUMBER + 1),
 };
 if (argc != 2) {
  printf("Usage: mkfs-simplefs <device>\n");
  return -1;
 }
 fd = open(argv[1], 02);
 if (fd == -1) {
  perror("Error opening the device");
  return -1;
 }
 ret = 1;
 do {
  if (write_superblock(fd))
   break;
  if (write_root_inode(fd))
   break;
  if (write_journal_inode(fd))
   break;
  if (write_welcome_inode(fd, &welcome))
   break;
  if (write_journal(fd))
   break;
  if (write_dirent(fd, &record))
   break;
  if (write_block(fd, welcomefile_body, welcome.file_size))
   break;
  ret = 0;
 } while (0);
 close(fd);
 return ret;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd;
 long ret;
 char welcomefile_body[] = "Love is God. God is Love. Anbe Murugan.\n";
 struct simplefs_inode welcome = {
  .mode = 0100000,
  .inode_no = (SIMPLEFS_JOURNAL_INODE_NUMBER + 1),
  .data_block_number = (SIMPLEFS_ROOTDIR_DATABLOCK_NUMBER + 1),
  .file_size = sizeof(welcomefile_body),
 };
 struct simplefs_dir_record record = {
  .filename = "vanakkam",
  .inode_no = (SIMPLEFS_JOURNAL_INODE_NUMBER + 1),
 };
 if (argc != 2) {
  printf("Usage: mkfs-simplefs <device>\n");
  return -1;
 }
 fd = open(argv[1], 02);
 if (fd == -1) {
  perror("Error opening the device");
  return -1;
 }
 ret = 1;
 do {
  if (write_superblock(fd))
   break;
  if (write_root_inode(fd))
   break;
  if (write_journal_inode(fd))
   break;
  if (write_welcome_inode(fd, &welcome))
   break;
  if (write_journal(fd))
   break;
  if (write_dirent(fd, &record))
   break;
  if (write_block(fd, welcomefile_body, welcome.file_size))
   break;
  ret = 0;
 } while (0);
 close(fd);
 return ret;
}

variable_types: ret long

variable_types: struct simplefs_inode { unsigned int mode; unsigned long inode_no; unsigned long data_block_number; union { unsigned long file_size; unsigned long dir_children_count; }; }

variable_types: struct simplefs_dir_record { char filename[255]; unsigned long inode_no; }


decompiled_code:
__int64 __fastcall write_root_inode(int a1)
{
__int64 result; // rax
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]
__int64 v5; // [rsp+18h] [rbp-10h]

v2 = 0x4000;
v3 = 1LL;
v4 = 4LL;
v5 = 1LL;
if ( write(a1, &v2, 0x20uLL) == 32 )
{
puts("root directory inode written succesfully");
result = 0LL;
}
else
{
puts("The inode store was not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 result; // rax
int v2; // [rsp+0h] [rbp-28h] BYREF
__int64 v3; // [rsp+8h] [rbp-20h]
__int64 v4; // [rsp+10h] [rbp-18h]
__int64 v5; // [rsp+18h] [rbp-10h]

v2 = 0x4000;
v3 = 1LL;
v4 = 4LL;
v5 = 1LL;
if ( write(a1, &v2, 0x20uLL) == 32 )
{
puts("root directory inode written succesfully");
result = 0LL;
}
else
{
puts("The inode store was not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int write_root_inode(int fd)
{
 ssize_t ret;
 struct simplefs_inode root_inode;
 root_inode.mode = 0040000;
 root_inode.inode_no = SIMPLEFS_ROOTDIR_INODE_NUMBER;
 root_inode.data_block_number = SIMPLEFS_ROOTDIR_DATABLOCK_NUMBER;
 root_inode.dir_children_count = 1;
 ret = write(fd, &root_inode, sizeof(root_inode));
 if (ret != sizeof(root_inode)) {
  printf
      ("The inode store was not written properly. Retry your mkfs\n");
  return -1;
 }
 printf("root directory inode written succesfully\n");
 return 0;
}

canonical_original_code:
static int write_root_inode(int fd)
{
 long ret;
 struct simplefs_inode root_inode;
 root_inode.mode = 0040000;
 root_inode.inode_no = SIMPLEFS_ROOTDIR_INODE_NUMBER;
 root_inode.data_block_number = SIMPLEFS_ROOTDIR_DATABLOCK_NUMBER;
 root_inode.dir_children_count = 1;
 ret = write(fd, &root_inode, sizeof(root_inode));
 if (ret != sizeof(root_inode)) {
  printf
      ("The inode store was not written properly. Retry your mkfs\n");
  return -1;
 }
 printf("root directory inode written succesfully\n");
 return 0;
}

user_defined_types: struct simplefs_inode { unsigned int mode; unsigned long inode_no; unsigned long data_block_number; union { unsigned long file_size; unsigned long dir_children_count; }; }


decompiled_code:
__int64 __fastcall write_journal_inode(int a1)
{
__int64 result; // rax
_QWORD v2[5]; // [rsp+0h] [rbp-28h] BYREF

v2[1] = 2LL;
v2[2] = 2LL;
if ( write(a1, v2, 0x20uLL) == 32 )
{
puts("journal inode written succesfully");
result = 0LL;
}
else
{
puts("Error while writing journal inode. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 result; // rax
_QWORD v2[5]; // [rsp+0h] [rbp-28h] BYREF

v2[1] = 2LL;
v2[2] = 2LL;
if ( write(a1, v2, 0x20uLL) == 32 )
{
puts("journal inode written succesfully");
result = 0LL;
}
else
{
puts("Error while writing journal inode. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int write_journal_inode(int fd)
{
 ssize_t ret;
 struct simplefs_inode journal;
 journal.inode_no = SIMPLEFS_JOURNAL_INODE_NUMBER;
 journal.data_block_number = SIMPLEFS_JOURNAL_BLOCK_NUMBER;
 ret = write(fd, &journal, sizeof(journal));
 if (ret != sizeof(journal)) {
  printf("Error while writing journal inode. Retry your mkfs\n");
  return -1;
 }
 printf("journal inode written succesfully\n");
 return 0;
}

canonical_original_code:
static int write_journal_inode(int fd)
{
 long ret;
 struct simplefs_inode journal;
 journal.inode_no = SIMPLEFS_JOURNAL_INODE_NUMBER;
 journal.data_block_number = SIMPLEFS_JOURNAL_BLOCK_NUMBER;
 ret = write(fd, &journal, sizeof(journal));
 if (ret != sizeof(journal)) {
  printf("Error while writing journal inode. Retry your mkfs\n");
  return -1;
 }
 printf("journal inode written succesfully\n");
 return 0;
}


decompiled_code:
__int64 __fastcall write_welcome_inode(int fd, const void *a2)
{
__int64 result; // rax

if ( write(fd, a2, 0x20uLL) == 32 )
{
puts("welcomefile inode written succesfully");
if ( lseek(fd, 4000LL, 1) == -1 )
{
puts("The padding bytes are not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
else
{
puts("inode store padding bytes (after the three inodes) written sucessfully");
result = 0LL;
}
}
else
{
puts("The welcomefile inode was not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, const void *a2)
{
__int64 result; // rax

if ( write(fd, a2, 0x20uLL) == 32 )
{
puts("welcomefile inode written succesfully");
if ( lseek(fd, 4000LL, 1) == -1 )
{
puts("The padding bytes are not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
else
{
puts("inode store padding bytes (after the three inodes) written sucessfully");
result = 0LL;
}
}
else
{
puts("The welcomefile inode was not written properly. Retry your mkfs");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int write_welcome_inode(int fd, const struct simplefs_inode *i)
{
 off_t nbytes;
 ssize_t ret;
 ret = write(fd, i, sizeof(*i));
 if (ret != sizeof(*i)) {
  printf
      ("The welcomefile inode was not written properly. Retry your mkfs\n");
  return -1;
 }
 printf("welcomefile inode written succesfully\n");
 nbytes = 4096 - (sizeof(*i) * 3);
 ret = lseek(fd, nbytes, 1);
 if (ret == (off_t)-1) {
  printf
      ("The padding bytes are not written properly. Retry your mkfs\n");
  return -1;
 }
 printf
     ("inode store padding bytes (after the three inodes) written sucessfully\n");
 return 0;
}

canonical_original_code:
static int write_welcome_inode(int fd, struct simplefs_inode *i)
{
 long nbytes;
 long ret;
 ret = write(fd, i, sizeof(*i));
 if (ret != sizeof(*i)) {
  printf
      ("The welcomefile inode was not written properly. Retry your mkfs\n");
  return -1;
 }
 printf("welcomefile inode written succesfully\n");
 nbytes = 4096 - (sizeof(*i) * 3);
 ret = lseek(fd, nbytes, 1);
 if (ret == (off_t)-1) {
  printf
      ("The padding bytes are not written properly. Retry your mkfs\n");
  return -1;
 }
 printf
     ("inode store padding bytes (after the three inodes) written sucessfully\n");
 return 0;
}

variable_types: struct simplefs_inode { unsigned int mode; unsigned long inode_no; unsigned long data_block_number; union { unsigned long file_size; unsigned long dir_children_count; }; } *

variable_types: nbytes long


decompiled_code:
__int64 __fastcall write_journal(int a1)
{
__int64 result; // rax

if ( lseek(a1, 0x2000LL, 1) == -1 )
{
puts("Can't write journal. Retry you mkfs");
result = 0xFFFFFFFFLL;
}
else
{
puts("Journal written successfully");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
__int64 result; // rax

if ( lseek(a1, 0x2000LL, 1) == -1 )
{
puts("Can't write journal. Retry you mkfs");
result = 0xFFFFFFFFLL;
}
else
{
puts("Journal written successfully");
result = 0LL;
}
return result;
}

original_code:
int write_journal(int fd)
{
 ssize_t ret;
 ret = lseek(fd, 4096 * SIMPLEFS_JOURNAL_BLOCKS, 1);
 if (ret == (off_t)-1) {
  printf("Can't write journal. Retry you mkfs\n");
  return -1;
 }
 printf("Journal written successfully\n");
 return 0;
}

canonical_original_code:
int write_journal(int fd)
{
 long ret;
 ret = lseek(fd, 4096 * SIMPLEFS_JOURNAL_BLOCKS, 1);
 if (ret == (off_t)-1) {
  printf("Can't write journal. Retry you mkfs\n");
  return -1;
 }
 printf("Journal written successfully\n");
 return 0;
}


decompiled_code:
__int64 __fastcall write_dirent(int fd, const void *a2)
{
__int64 result; // rax

if ( write(fd, a2, 0x108uLL) == 264 )
{
puts("root directory datablocks (name+inode_no pair for welcomefile) written succesfully");
if ( lseek(fd, 3832LL, 1) == -1 )
{
puts("Writing the padding for rootdirectory children datablock has failed");
result = 0xFFFFFFFFLL;
}
else
{
puts("padding after the rootdirectory children written succesfully");
result = 0LL;
}
}
else
{
puts("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int fd, const void *a2)
{
__int64 result; // rax

if ( write(fd, a2, 0x108uLL) == 264 )
{
puts("root directory datablocks (name+inode_no pair for welcomefile) written succesfully");
if ( lseek(fd, 3832LL, 1) == -1 )
{
puts("Writing the padding for rootdirectory children datablock has failed");
result = 0xFFFFFFFFLL;
}
else
{
puts("padding after the rootdirectory children written succesfully");
result = 0LL;
}
}
else
{
puts("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int write_dirent(int fd, const struct simplefs_dir_record *record)
{
 ssize_t nbytes = sizeof(*record), ret;
 ret = write(fd, record, nbytes);
 if (ret != nbytes) {
  printf
      ("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed\n");
  return -1;
 }
 printf
     ("root directory datablocks (name+inode_no pair for welcomefile) written succesfully\n");
 nbytes = 4096 - sizeof(*record);
 ret = lseek(fd, nbytes, 1);
 if (ret == (off_t)-1) {
  printf
      ("Writing the padding for rootdirectory children datablock has failed\n");
  return -1;
 }
 printf
     ("padding after the rootdirectory children written succesfully\n");
 return 0;
}

canonical_original_code:
int write_dirent(int fd, struct simplefs_dir_record *record)
{
 long nbytes = sizeof(*record); long ret;
 ret = write(fd, record, nbytes);
 if (ret != nbytes) {
  printf
      ("Writing the rootdirectory datablock (name+inode_no pair for welcomefile) has failed\n");
  return -1;
 }
 printf
     ("root directory datablocks (name+inode_no pair for welcomefile) written succesfully\n");
 nbytes = 4096 - sizeof(*record);
 ret = lseek(fd, nbytes, 1);
 if (ret == (off_t)-1) {
  printf
      ("Writing the padding for rootdirectory children datablock has failed\n");
  return -1;
 }
 printf
     ("padding after the rootdirectory children written succesfully\n");
 return 0;
}

variable_types: struct simplefs_dir_record { char filename[255]; unsigned long inode_no; } *


decompiled_code:
__int64 __fastcall write_block(int a1, const void *a2, size_t a3)
{
__int64 result; // rax

if ( a3 == write(a1, a2, a3) )
{
puts("block has been written succesfully");
result = 0LL;
}
else
{
puts("Writing file body has failed");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, const void *a2, size_t a3)
{
__int64 result; // rax

if ( a3 == write(a1, a2, a3) )
{
puts("block has been written succesfully");
result = 0LL;
}
else
{
puts("Writing file body has failed");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int write_block(int fd, char *block, size_t len)
{
 ssize_t ret;
 ret = write(fd, block, len);
 if (ret != len) {
  printf("Writing file body has failed\n");
  return -1;
 }
 printf("block has been written succesfully\n");
 return 0;
}

canonical_original_code:
int write_block(int fd, char *block, unsigned long len)
{
 long ret;
 ret = write(fd, block, len);
 if (ret != len) {
  printf("Writing file body has failed\n");
  return -1;
 }
 printf("block has been written succesfully\n");
 return 0;
}

variable_types:
block
char *

variable_types:
len
unsigned long


createdisk

decompiled_code:
void __fastcall createdisk(char *file, int a2)
{
_DWORD *v2; // rbp
int v3; // eax
ssize_t v4; // rax
const char *v5; // rdi

printf("Creating disk %s\n", file);
v2 = malloc(0x200uLL);
v3 = creat(file, 0x1C0u);
if ( v3 == -1 )
{
v5 = "createdisk creat() failed";
goto LABEL_6;
}
*(_QWORD *)v2 = 0xFFFFFFFFLL;
v2[2] = 512;
v2[3] = a2;
v4 = write(v3, v2, 0x200uLL);
if ( v4 == -1 )
{
v5 = "createdisk: write failed";
LABEL_6:
puts(v5);
perror("createdisk");
exit(-1);
}
if ( v2[2] != v4 )
{
v5 = "createdisk: write failed, too few bytes written";
goto LABEL_6;
}
close(*v2);
free(v2);
}

canonical_decompiled_code:
void __fastcall func7(char *file, int a2)
{
_DWORD *v2; // rbp
int v3; // eax
ssize_t v4; // rax
const char *v5; // rdi

printf("Creating disk %s\n", file);
v2 = malloc(0x200uLL);
v3 = creat(file, 0x1C0u);
if ( v3 == -1 )
{
v5 = "createdisk creat() failed";
goto LABEL_6;
}
*(_QWORD *)v2 = 0xFFFFFFFFLL;
v2[2] = 512;
v2[3] = a2;
v4 = write(v3, v2, 0x200uLL);
if ( v4 == -1 )
{
v5 = "createdisk: write failed";
LABEL_6:
puts(v5);
perror("createdisk");
exit(-1);
}
if ( v2[2] != v4 )
{
v5 = "createdisk: write failed, too few bytes written";
goto LABEL_6;
}
close(*v2);
free(v2);
}

original_code:
void createdisk(char *disk_name, int size)
{
  printf("Creating disk %s\n", disk_name);
  int fd;
  disk_t disk = malloc(512);
  ssize_t bytes_written;
  fd = creat(disk_name, (0400|0200|0100));
  if(fd == -1) {
    printf("createdisk creat() failed\n");
    perror("createdisk");
    exit(-1);
  }
  disk->fd = -1;
  disk->last_block = 0;
  disk->block_size = 512;
  disk->size = size;
  bytes_written = write(fd, disk, 512);
  if(bytes_written == -1) {
    printf("createdisk: write failed\n");
    perror("createdisk");
    exit(-1);
  }
  if(bytes_written != disk->block_size) {
    printf("createdisk: write failed, too few bytes written\n");
    perror("createdisk");
    exit(-1);
  }
  close(disk->fd);
  free(disk);
  return;
}

canonical_original_code:
void createdisk(char *disk_name, int size)
{
  printf("Creating disk %s\n", disk_name);
  int fd;
  struct diskt *disk = malloc(512);
  long bytes_written;
  fd = creat(disk_name, (0400|0200|0100));
  if(fd == -1) {
    printf("createdisk creat() failed\n");
    perror("createdisk");
    exit(-1);
  }
  disk->fd = -1;
  disk->last_block = 0;
  disk->block_size = 512;
  disk->size = size;
  bytes_written = write(fd, disk, 512);
  if(bytes_written == -1) {
    printf("createdisk: write failed\n");
    perror("createdisk");
    exit(-1);
  }
  if(bytes_written != disk->block_size) {
    printf("createdisk: write failed, too few bytes written\n");
    perror("createdisk");
    exit(-1);
  }
  close(disk->fd);
  free(disk);
  return;
}

variable_types: size int

variable_types: struct diskt { int fd; int last_block; int block_size; int size; } *


opendisk

decompiled_code:
unsigned int *__fastcall opendisk(char *file)
{
unsigned int *v1; // r12
int v2; // eax
int v3; // ebx
__int64 v4; // rcx
__int64 v5; // rdx

v1 = (unsigned int *)malloc(0x200uLL);
printf("Opening disk %s\n", file);
v2 = open(file, 2);
if ( v2 == -1 )
{
puts("opendisk failed");
perror("opendisk");
exit(-1);
}
v3 = v2;
read(v2, v1, 0x200uLL);
v4 = v1[2];
v5 = v1[3];
*v1 = v3;
printf("Disk %s opened. size = %d, block size = %d\n", file, v5, v4);
return v1;
}

canonical_decompiled_code:
unsigned int *__fastcall func8(char *file)
{
unsigned int *v1; // r12
int v2; // eax
int v3; // ebx
__int64 v4; // rcx
__int64 v5; // rdx

v1 = (unsigned int *)malloc(0x200uLL);
printf("Opening disk %s\n", file);
v2 = open(file, 2);
if ( v2 == -1 )
{
puts("opendisk failed");
perror("opendisk");
exit(-1);
}
v3 = v2;
read(v2, v1, 0x200uLL);
v4 = v1[2];
v5 = v1[3];
*v1 = v3;
printf("Disk %s opened. size = %d, block size = %d\n", file, v5, v4);
return v1;
}

original_code:
disk_t opendisk(char *disk_name)
{
  int fd;
  disk_t disk = malloc(512);
  printf("Opening disk %s\n", disk_name);
  fd = open(disk_name, 02);
  if(fd == -1) {
    printf("opendisk failed\n");
    perror("opendisk");
    exit(-1);
  }
  read(fd, (void *) disk, 512);
  disk->fd = fd;
  printf("Disk %s opened. size = %d, block size = %d\n", disk_name, disk->size, disk->block_size);
  return(disk);
}

canonical_original_code:
struct diskt *opendisk(char *disk_name)
{
  int fd;
  struct diskt *disk = malloc(512);
  printf("Opening disk %s\n", disk_name);
  fd = open(disk_name, 02);
  if(fd == -1) {
    printf("opendisk failed\n");
    perror("opendisk");
    exit(-1);
  }
  read(fd, (void *) disk, 512);
  disk->fd = fd;
  printf("Disk %s opened. size = %d, block size = %d\n", disk_name, disk->size, disk->block_size);
  return(disk);
}

return_type: struct diskt { int fd; int last_block; int block_size; int size; } *


seekblock

decompiled_code:
__off_t __fastcall seekblock(int *a1, int a2)
{
__off_t result; // rax

if ( a2 < 0 )
{
puts("seekblock: tried to seek below the beginning of the disk!");
printf("seekblock: seek block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("seekblock: tried to seek past the end of the disk!");
printf(
"seekblock: seek block %d. Disk size is %d, so last block is %d.\n",
(unsigned int)a2,
(unsigned int)a1[3],
(unsigned int)(a1[3] - 1));
exit(-1);
}
result = lseek(*a1, a1[2] * (a2 + 1), 0);
if ( result == -1 )
{
puts("seekblock: lseek failed");
perror("seekblock");
exit(-1);
}
a1[1] = a2;
return result;
}

canonical_decompiled_code:
__off_t __fastcall func9(int *a1, int a2)
{
__off_t result; // rax

if ( a2 < 0 )
{
puts("seekblock: tried to seek below the beginning of the disk!");
printf("seekblock: seek block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("seekblock: tried to seek past the end of the disk!");
printf(
"seekblock: seek block %d. Disk size is %d, so last block is %d.\n",
(unsigned int)a2,
(unsigned int)a1[3],
(unsigned int)(a1[3] - 1));
exit(-1);
}
result = lseek(*a1, a1[2] * (a2 + 1), 0);
if ( result == -1 )
{
puts("seekblock: lseek failed");
perror("seekblock");
exit(-1);
}
a1[1] = a2;
return result;
}

original_code:
int seekblock(disk_t disk, int block)
{
  off_t offset;
  if(block < 0) {
    printf("seekblock: tried to seek below the beginning of the disk!\n");
    printf("seekblock: seek block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block >= disk->size) {
    printf("seekblock: tried to seek past the end of the disk!\n");
    printf("seekblock: seek block %d.  Disk size is %d, so last block is %d.\n", block, disk->size, disk->size-1);
    exit(-1);
  }
  offset = lseek(disk->fd, (block+1)*disk->block_size, 0);
  if(offset == -1) {
    printf("seekblock: lseek failed\n");
    perror("seekblock");
    exit(-1);
  }
  disk->last_block = block;
}

canonical_original_code:
int seekblock(struct diskt *disk, int block)
{
  long offset;
  if(block < 0) {
    printf("seekblock: tried to seek below the beginning of the disk!\n");
    printf("seekblock: seek block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block >= disk->size) {
    printf("seekblock: tried to seek past the end of the disk!\n");
    printf("seekblock: seek block %d.  Disk size is %d, so last block is %d.\n", block, disk->size, disk->size-1);
    exit(-1);
  }
  offset = lseek(disk->fd, (block+1)*disk->block_size, 0);
  if(offset == -1) {
    printf("seekblock: lseek failed\n");
    perror("seekblock");
    exit(-1);
  }
  disk->last_block = block;
}

variable_types: block int

variable_types: offset long

user_defined_types: struct diskt { int fd; int last_block; int block_size; int size; }


readblock

decompiled_code:
__int64 __fastcall readblock(int *a1, int a2, void *a3)
{
ssize_t v4; // rax
const char *v6; // rdi

if ( a2 < 0 )
{
puts("readblock: There are no blocks < 0!!!");
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("readblock: tried to read past the end of the disk!");
printf("readblock: read block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[1] + 1 != a2 )
seekblock(a1, a2);
v4 = read(*a1, a3, a1[2]);
if ( v4 == -1 )
{
v6 = "readblock read failed";
LABEL_11:
puts(v6);
perror("readblock");
exit(-1);
}
if ( a1[2] != v4 )
{
puts("readblock: read failed, too few bytes read");
v6 = "readblock: probably because you read data that was not previously written.";
goto LABEL_11;
}
a1[1] = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, int a2, void *a3)
{
ssize_t v4; // rax
const char *v6; // rdi

if ( a2 < 0 )
{
puts("readblock: There are no blocks < 0!!!");
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("readblock: tried to read past the end of the disk!");
printf("readblock: read block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[1] + 1 != a2 )
func9(a1, a2);
v4 = read(*a1, a3, a1[2]);
if ( v4 == -1 )
{
v6 = "readblock read failed";
LABEL_11:
puts(v6);
perror("readblock");
exit(-1);
}
if ( a1[2] != v4 )
{
puts("readblock: read failed, too few bytes read");
v6 = "readblock: probably because you read data that was not previously written.";
goto LABEL_11;
}
a1[1] = a2;
return 0LL;
}

original_code:
int readblock(disk_t disk, int block, unsigned char *databuf)
{
  off_t offset;
  ssize_t bytes_read;
  if(block < 0) {
    printf("readblock: There are no blocks < 0!!!\n");
    exit(-1);
  }
  if(block >= disk->size) {
    printf("readblock: tried to read past the end of the disk!\n");
    printf("readblock: read block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block != disk->last_block+1)
    seekblock(disk, block);
  bytes_read = read(disk->fd, (void *)databuf, disk->block_size);
  if(bytes_read == -1) {
    printf("readblock read failed\n");
    perror("readblock");
    exit(-1);
  }
  if(bytes_read != disk->block_size) {
    printf("readblock: read failed, too few bytes read\n");
    printf("readblock: probably because you read data that was not previously written.\n");
    perror("readblock");
    exit(-1);
  }
  disk->last_block = block;
  return 0;
}

canonical_original_code:
int readblock(struct diskt *disk, int block, unsigned char *databuf)
{
  long offset;
  long bytes_read;
  if(block < 0) {
    printf("readblock: There are no blocks < 0!!!\n");
    exit(-1);
  }
  if(block >= disk->size) {
    printf("readblock: tried to read past the end of the disk!\n");
    printf("readblock: read block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block != disk->last_block+1)
    seekblock(disk, block);
  bytes_read = read(disk->fd, (void *)databuf, disk->block_size);
  if(bytes_read == -1) {
    printf("readblock read failed\n");
    perror("readblock");
    exit(-1);
  }
  if(bytes_read != disk->block_size) {
    printf("readblock: read failed, too few bytes read\n");
    printf("readblock: probably because you read data that was not previously written.\n");
    perror("readblock");
    exit(-1);
  }
  disk->last_block = block;
  return 0;
}

variable_types:
databuf
unsigned char *


writeblock

decompiled_code:
__int64 __fastcall writeblock(int *a1, int a2, const void *a3)
{
size_t v5; // rdx
int v6; // edi
ssize_t v7; // rax
const char *v9; // rdi

if ( a2 < 0 )
{
puts("writeblock: There are no blocks < 0!!!");
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("writeblock: tried to write past the end of the disk!");
printf("writeblock: write block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[1] + 1 != a2 )
seekblock(a1, a2);
v5 = a1[2];
v6 = *a1;
a1[1] = a2;
v7 = write(v6, a3, v5);
if ( v7 == -1 )
{
v9 = "writeblock failed";
LABEL_11:
puts(v9);
perror("writeblock");
exit(-1);
}
if ( a1[2] != v7 )
{
v9 = "writeblock: write failed, too few bytes written";
goto LABEL_11;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, int a2, const void *a3)
{
size_t v5; // rdx
int v6; // edi
ssize_t v7; // rax
const char *v9; // rdi

if ( a2 < 0 )
{
puts("writeblock: There are no blocks < 0!!!");
exit(-1);
}
if ( a1[3] <= a2 )
{
puts("writeblock: tried to write past the end of the disk!");
printf("writeblock: write block %d, disk size is %d.\n", (unsigned int)a2, (unsigned int)a1[3]);
exit(-1);
}
if ( a1[1] + 1 != a2 )
func9(a1, a2);
v5 = a1[2];
v6 = *a1;
a1[1] = a2;
v7 = write(v6, a3, v5);
if ( v7 == -1 )
{
v9 = "writeblock failed";
LABEL_11:
puts(v9);
perror("writeblock");
exit(-1);
}
if ( a1[2] != v7 )
{
v9 = "writeblock: write failed, too few bytes written";
goto LABEL_11;
}
return 0LL;
}

original_code:
int writeblock(disk_t disk, int block, unsigned char *databuf)
{
  off_t offset;
  ssize_t bytes_written;
  if(block < 0) {
    printf("writeblock: There are no blocks < 0!!!\n");
    exit(-1);
  }
  if(block >= disk->size) {
    printf("writeblock: tried to write past the end of the disk!\n");
    printf("writeblock: write block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block != disk->last_block + 1)
    seekblock(disk, block);
  disk->last_block = block;
  bytes_written = write(disk->fd, databuf, disk->block_size);
  if(bytes_written == -1) {
    printf("writeblock failed\n");
    perror("writeblock");
    exit(-1);
  }
  if(bytes_written != disk->block_size) {
    printf("writeblock: write failed, too few bytes written\n");
    perror("writeblock");
    exit(-1);
  }
  return 0;
}

canonical_original_code:
int writeblock(struct diskt *disk, int block, unsigned char *databuf)
{
  long offset;
  long bytes_written;
  if(block < 0) {
    printf("writeblock: There are no blocks < 0!!!\n");
    exit(-1);
  }
  if(block >= disk->size) {
    printf("writeblock: tried to write past the end of the disk!\n");
    printf("writeblock: write block %d, disk size is %d.\n", block, disk->size);
    exit(-1);
  }
  if(block != disk->last_block + 1)
    seekblock(disk, block);
  disk->last_block = block;
  bytes_written = write(disk->fd, databuf, disk->block_size);
  if(bytes_written == -1) {
    printf("writeblock failed\n");
    perror("writeblock");
    exit(-1);
  }
  if(bytes_written != disk->block_size) {
    printf("writeblock: write failed, too few bytes written\n");
    perror("writeblock");
    exit(-1);
  }
  return 0;
}


usage

repo: psi-im/psimedia

decompiled_code:
int usage()
{
puts("usage: alsalatency rec (capture_device)");
puts(" alsalatency loop (play_device) (capture_device)");
putchar(10);
return puts("note: if capture_device or play_device are omitted, 'default' is assumed.\n");
}

canonical_decompiled_code:
int func7()
{
puts("usage: alsalatency rec (capture_device)");
puts(" alsalatency loop (play_device) (capture_device)");
putchar(10);
return puts("note: if capture_device or play_device are omitted, 'default' is assumed.\n");
}

original_code:
static void usage()
{
    printf("usage: alsalatency rec  (capture_device)\n");
    printf("       alsalatency loop (play_device) (capture_device)\n");
    printf("\n");
    printf("note: if capture_device or play_device are omitted, 'default' is assumed.\n\n");
}


repo: psilord/manifold

original_code:
void intqueue_free(IntQueue *iq)
{
 Symbol **sq = ((void *)0);
 int i, j;
 for (i = 0; i < iq->num_slices; i++)
 {
  sq = iq->slice[i];
  for (j = iq->slice_top[i]; j < iq->num_syms; j++)
  {
   if (sq[j] != ((void *)0))
   {
    symbol_free(sq[j]);
   }
  }
  free(iq->slice[i]);
 }
 free(iq->slice);
 free(iq->slice_top);
}

canonical_original_code:
void intqueue_free(struct IntQueue_s *iq)
{
 struct Symbol_s **sq = ((void *)0);
 int i; int j;
 for (i = 0; i < iq->num_slices; i++)
 {
  sq = iq->slice[i];
  for (j = iq->slice_top[i]; j < iq->num_syms; j++)
  {
   if (sq[j] != ((void *)0))
   {
    symbol_free(sq[j]);
   }
  }
  free(iq->slice[i]);
 }
 free(iq->slice);
 free(iq->slice_top);
}

variable_types: struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s { unsigned short dim; float vec[1]; } ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *

variable_types: i int

variable_types: j int

user_defined_types: struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; }


original_code:
void intqueue_enqueue(IntQueue *iq, Symbol *sym)
{
 int i;
 Symbol **sq = ((void *)0);
 sq = iq->slice[iq->curr_slice];
 switch(iq->slice_top[iq->curr_slice])
 {
  case 0:
   symbol_free(sq[0]);
   for (i = 1; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->ready = TRUE;
   iq->ready_slice = iq->curr_slice;
   break;
  case 1:
   for (i = iq->slice_top[iq->curr_slice]; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->slice_top[iq->curr_slice]--;
   iq->ready = TRUE;
   iq->ready_slice = iq->curr_slice;
   break;
  default:
   for (i = iq->slice_top[iq->curr_slice]; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->slice_top[iq->curr_slice]--;
   if (iq->ready == TRUE)
   {
    printf("intqueue_enqueue(): cannot go from ready to "
     "nonready!\n");
    exit(1);
   }
   iq->ready = FALSE;
   break;
 }
 iq->curr_slice = (iq->curr_slice + 1) % iq->num_slices;
}

canonical_original_code:
void intqueue_enqueue(struct IntQueue_s *iq, struct Symbol_s *sym)
{
 int i;
 struct Symbol_s **sq = ((void *)0);
 sq = iq->slice[iq->curr_slice];
 switch(iq->slice_top[iq->curr_slice])
 {
  case 0:
   symbol_free(sq[0]);
   for (i = 1; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->ready = TRUE;
   iq->ready_slice = iq->curr_slice;
   break;
  case 1:
   for (i = iq->slice_top[iq->curr_slice]; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->slice_top[iq->curr_slice]--;
   iq->ready = TRUE;
   iq->ready_slice = iq->curr_slice;
   break;
  default:
   for (i = iq->slice_top[iq->curr_slice]; i < iq->num_syms; i++)
   {
    sq[i-1] = sq[i];
   }
   (iq->slice[iq->curr_slice])[iq->num_syms - 1] = sym;
   iq->slice_top[iq->curr_slice]--;
   if (iq->ready == TRUE)
   {
    printf("intqueue_enqueue(): cannot go from ready to "
     "nonready!\n");
    exit(1);
   }
   iq->ready = FALSE;
   break;
 }
 iq->curr_slice = (iq->curr_slice + 1) % iq->num_slices;
}

variable_types:
sym
struct Symbol_s *

variable_types: struct Symbol_s { unsigned short dim; float vec[1]; } **


decompiled_code:
__int64 __fastcall intqueue_ready(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

original_code:
int intqueue_ready(IntQueue *iq)
{
 return iq->ready;
}

canonical_original_code:
int intqueue_ready(struct IntQueue_s *iq)
{
 return iq->ready;
}

user_defined_types: struct Symbol_s { unsigned short dim; float vec[1]; }


decompiled_code:
__int64 __fastcall intqueue_dequeue(unsigned int *a1)
{
__int64 result; // rax

if ( a1[7] )
result = symbol_abstract(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * (int)a1[8]), *a1);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
__int64 result; // rax

if ( a1[7] )
result = symbol_abstract(*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * (int)a1[8]), *a1);
else
result = 0LL;
return result;
}

original_code:
Symbol* intqueue_dequeue(IntQueue *iq)
{
 Symbol *abstraction;
 if (iq->ready == FALSE)
 {
  return ((void *)0);
 }
 abstraction = symbol_abstract(iq->slice[iq->ready_slice], iq->num_syms);
 return abstraction;
}

canonical_original_code:
struct Symbol_s *intqueue_dequeue(struct IntQueue_s *iq)
{
 struct Symbol_s *abstraction;
 if (iq->ready == FALSE)
 {
  return ((void *)0);
 }
 abstraction = symbol_abstract(iq->slice[iq->ready_slice], iq->num_syms);
 return abstraction;
}

variable_types: struct IntQueue_s { int num_syms; int num_slices; struct Symbol_s ***slice; int *slice_top; int curr_slice; int ready; int ready_slice; } *

variable_types: struct Symbol_s { unsigned short dim; float vec[1]; } *


decompiled_code:
__int64 __fastcall intqueue_integrations(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
return *a1;
}

original_code:
int intqueue_integrations(IntQueue *iq)
{
 return iq->num_syms;
}

canonical_original_code:
int intqueue_integrations(struct IntQueue_s *iq)
{
 return iq->num_syms;
}


decompiled_code:
int __fastcall intqueue_stdout(unsigned int *a1)
{
const char *v2; // rsi
int result; // eax
__int64 v4; // r13
__int64 v5; // r14
__int64 v6; // rbx
__int64 v7; // rdi

puts("\t\tIntegration Queue:");
v2 = "TRUE";
if ( a1[7] != 1 )
v2 = "FALSE";
printf("\t\t\tReady: %s\n", v2);
printf("\t\t\tReady slice: %d\n", a1[8]);
printf("\t\t\tNum Syms: %d\n", *a1);
result = printf("\t\t\tNum Slices: %d\n", a1[1]);
if ( (int)a1[1] > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v4);
printf("\t\t\t\tSlice: %d\n", (unsigned int)v4);
result = *a1;
if ( (int)*a1 > 0 )
{
v6 = 0LL;
do
{
while ( *(_DWORD *)(*((_QWORD *)a1 + 2) + 4 * v4) > (int)v6 )
{
++v6;
result = puts("\t\t\t\t\tN/A");
if ( (int)*a1 <= (int)v6 )
goto LABEL_10;
}
printf("\t\t\t\t\t");
v7 = *(_QWORD *)(v5 + 8 * v6++);
result = symbol_stdout(v7);
}
while ( (int)*a1 > (int)v6 );
}
LABEL_10:
++v4;
}
while ( (int)a1[1] > (int)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
const char *v2; // rsi
int result; // eax
__int64 v4; // r13
__int64 v5; // r14
__int64 v6; // rbx
__int64 v7; // rdi

puts("\t\tIntegration Queue:");
v2 = "TRUE";
if ( a1[7] != 1 )
v2 = "FALSE";
printf("\t\t\tReady: %s\n", v2);
printf("\t\t\tReady slice: %d\n", a1[8]);
printf("\t\t\tNum Syms: %d\n", *a1);
result = printf("\t\t\tNum Slices: %d\n", a1[1]);
if ( (int)a1[1] > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v4);
printf("\t\t\t\tSlice: %d\n", (unsigned int)v4);
result = *a1;
if ( (int)*a1 > 0 )
{
v6 = 0LL;
do
{
while ( *(_DWORD *)(*((_QWORD *)a1 + 2) + 4 * v4) > (int)v6 )
{
++v6;
result = puts("\t\t\t\t\tN/A");
if ( (int)*a1 <= (int)v6 )
goto LABEL_10;
}
printf("\t\t\t\t\t");
v7 = *(_QWORD *)(v5 + 8 * v6++);
result = symbol_stdout(v7);
}
while ( (int)*a1 > (int)v6 );
}
LABEL_10:
++v4;
}
while ( (int)a1[1] > (int)v4 );
}
return result;
}

original_code:
void intqueue_stdout(IntQueue *iq)
{
 int i, j;
 Symbol **sq = ((void *)0);
 printf("\t\tIntegration Queue:\n");
 printf("\t\t\tReady: %s\n", iq->ready==TRUE?"TRUE":"FALSE");
 printf("\t\t\tReady slice: %d\n", iq->ready_slice);
 printf("\t\t\tNum Syms: %d\n", iq->num_syms);
 printf("\t\t\tNum Slices: %d\n", iq->num_slices);
 for (i = 0; i < iq->num_slices; i++)
 {
  sq = iq->slice[i];
  printf("\t\t\t\tSlice: %d\n", i);
  for (j = 0; j < iq->num_syms; j++)
  {
   if (j < iq->slice_top[i]) {
    printf("\t\t\t\t\tN/A\n");
   } else {
    printf("\t\t\t\t\t");
    symbol_stdout(sq[j]);
   }
  }
 }
}

canonical_original_code:
void intqueue_stdout(struct IntQueue_s *iq)
{
 int i; int j;
 struct Symbol_s **sq = ((void *)0);
 printf("\t\tIntegration Queue:\n");
 printf("\t\t\tReady: %s\n", iq->ready==TRUE?"TRUE":"FALSE");
 printf("\t\t\tReady slice: %d\n", iq->ready_slice);
 printf("\t\t\tNum Syms: %d\n", iq->num_syms);
 printf("\t\t\tNum Slices: %d\n", iq->num_slices);
 for (i = 0; i < iq->num_slices; i++)
 {
  sq = iq->slice[i];
  printf("\t\t\t\tSlice: %d\n", i);
  for (j = 0; j < iq->num_syms; j++)
  {
   if (j < iq->slice_top[i]) {
    printf("\t\t\t\t\tN/A\n");
   } else {
    printf("\t\t\t\t\t");
    symbol_stdout(sq[j]);
   }
  }
 }
}