main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // eax
void *v5; // r13
_QWORD *v6; // r14
_QWORD *v7; // rbp
_QWORD *v8; // r15
void *v9; // rax
__int64 v10; // r8
__int64 v11; // rsi
__int64 v12; // r12
int v13; // eax
__int64 v14; // rbx
void *v15; // rax
__int64 v16; // rdi
void *v17; // rax
__int64 v18; // rdi
void *v19; // rax
__int64 v20; // rdi
__int64 i; // rdx
int v22; // ebx
__int64 v23; // rdx
__int64 v24; // rbx
_QWORD *v25; // rbp
__int64 v26; // r12
int v27; // eax
_QWORD *v28; // rcx
bool v29; // cc
__int64 v30; // r8
int v31; // ebx
__int64 j; // r8
int v33; // eax
__int64 v34; // rdx
int v35; // eax
__int64 v37; // rdx
_DWORD *v38; // [rsp+8h] [rbp-140h]
double v39; // [rsp+8h] [rbp-140h]
void *src; // [rsp+10h] [rbp-138h]
int v41; // [rsp+1Ch] [rbp-12Ch]
char *v42; // [rsp+20h] [rbp-128h]
char *v43; // [rsp+28h] [rbp-120h]
__int64 v44; // [rsp+30h] [rbp-118h]
__int64 v45; // [rsp+30h] [rbp-118h]
_QWORD *v46; // [rsp+30h] [rbp-118h]
__int64 v47; // [rsp+38h] [rbp-110h]
__int64 v48; // [rsp+38h] [rbp-110h]
__int64 v49; // [rsp+38h] [rbp-110h]
int longind; // [rsp+4Ch] [rbp-FCh] BYREF
struct option longopts; // [rsp+50h] [rbp-F8h] BYREF
const char *v52; // [rsp+70h] [rbp-D8h]
int v53; // [rsp+78h] [rbp-D0h]
__int64 v54; // [rsp+80h] [rbp-C8h]
int v55; // [rsp+88h] [rbp-C0h]
const char *v56; // [rsp+90h] [rbp-B8h]
int v57; // [rsp+98h] [rbp-B0h]
__int64 v58; // [rsp+A0h] [rbp-A8h]
int v59; // [rsp+A8h] [rbp-A0h]
const char *v60; // [rsp+B0h] [rbp-98h]
int v61; // [rsp+B8h] [rbp-90h]
__int64 v62; // [rsp+C0h] [rbp-88h]
int v63; // [rsp+C8h] [rbp-80h]
const char *v64; // [rsp+D0h] [rbp-78h]
int v65; // [rsp+D8h] [rbp-70h]
__int64 v66; // [rsp+E0h] [rbp-68h]
int v67; // [rsp+E8h] [rbp-60h]
__int64 v68; // [rsp+F0h] [rbp-58h]
int v69; // [rsp+F8h] [rbp-50h]
__int64 v70; // [rsp+100h] [rbp-48h]
int v71; // [rsp+108h] [rbp-40h]

verboseP = 0;
nparts = 4;
longopts.name = "midge";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 109;
v52 = "analysis";
v53 = 1;
v54 = 0LL;
v55 = 97;
v56 = "nparts";
v57 = 1;
v58 = 0LL;
v59 = 110;
v60 = "help";
v61 = 0;
v62 = 0LL;
v63 = 104;
v64 = "verbose";
v65 = 0;
v66 = 0LL;
v67 = 118;
v68 = 0LL;
v69 = 0;
v70 = 0LL;
v71 = 0;
v41 = 0;
v43 = 0LL;
v42 = 0LL;
while ( 2 )
{
longind = 0;
v3 = getopt_long(argc, (char *const *)argv, "vhn:m:a:", &longopts, &longind);
if ( v3 != -1 )
{
switch ( v3 )
{
case 'a':
v43 = optarg;
continue;
case 'h':
v41 = 1;
continue;
case 'm':
v42 = optarg;
continue;
case 'n':
nparts = atoi(optarg);
if ( nparts <= 1 )
goto LABEL_6;
continue;
case 'v':
verboseP = 1;
continue;
default:
goto LABEL_6;
}
}
break;
}
if ( v41 )
printHelp(0);
if ( !v42 )
LABEL_6:
printHelp(1);
initGlobals();
v4 = time(0LL);
srand(v4);
rangemin = malloc(4LL * nparts);
v47 = rangemin;
rangemax = malloc(4LL * nparts);
v44 = rangemax;
v38 = malloc(4LL * nparts);
rangediff = v38;
src = malloc(32 * mdivision * (__int64)nmeasures);
v5 = malloc(32 * mdivision * (__int64)nmeasures);
v6 = malloc(8LL * (nparts + 1));
v7 = malloc(8LL * (nparts + 1));
v8 = malloc(8LL * (nparts + 1));
v9 = malloc(8LL * (nparts + 1));
v10 = v44;
v11 = v47;
v12 = (__int64)v9;
v13 = nparts;
if ( nparts > 0 )
{
v45 = v47;
v14 = 0LL;
v48 = v10;
do
{
v15 = malloc(8LL * totalSubdivisions);
v16 = totalSubdivisions;
v6[v14] = v15;
v17 = malloc(8 * v16);
v18 = totalSubdivisions;
v7[v14] = v17;
v19 = malloc(4 * v18);
v20 = totalSubdivisions;
v8[v14] = v19;
*(_QWORD *)(v12 + 8 * v14) = malloc(4 * v20);
v13 = nparts;
++v14;
}
while ( nparts > (int)v14 );
v11 = v45;
v10 = v48;
}
*(_QWORD *)v11 = 0x260000001CLL;
v6[v13] = 0LL;
v7[v13] = 0LL;
v8[v13] = 0LL;
*(_QWORD *)(v12 + 8LL * v13) = 0LL;
*(_QWORD *)v10 = 0x3700000030LL;
if ( v13 <= 2 )
{
if ( v13 <= 0 )
goto LABEL_31;
}
else
{
*(_DWORD *)(v11 + 8) = 43;
*(_DWORD *)(v10 + 8) = 62;
if ( v13 != 3 )
{
*(_DWORD *)(v11 + 12) = 50;
*(_DWORD *)(v10 + 12) = 67;
if ( v13 != 4 )
{
for ( i = 4LL; i != v13; *(_DWORD *)(v10 + 4 * i++) = v22 + 10 )
{
v22 = *(_DWORD *)(v10 + 4 * i - 4);
*(_DWORD *)(v11 + 4 * i) = *(_DWORD *)(v11 + 4 * i - 4) + 10;
}
goto LABEL_21;
}
}
}
v37 = 0LL;
do
{
*(_DWORD *)(v11 + 4 * v37) += 12;
*(_DWORD *)(v10 + 4 * v37++) += 12;
}
while ( v13 > (int)v37 );
LABEL_21:
v23 = 0LL;
do
{
v38[v23] = *(_DWORD *)(v10 + 4 * v23) - *(_DWORD *)(v11 + 4 * v23);
++v23;
}
while ( v13 > (int)v23 );
v49 = v12;
v24 = 0LL;
v46 = v7;
v25 = v6;
do
{
v26 = 0LL;
if ( totalSubdivisions > 0 )
{
do
{
v27 = rand();
v28 = (_QWORD *)(*v25 + 8 * v26++);
v29 = totalSubdivisions <= (int)v26;
*v28 = (unsigned int)(*(_DWORD *)(rangemin + 4 * v24) + v27 % *(_DWORD *)(rangediff + 4 * v24));
}
while ( !v29 );
v13 = nparts;
}
++v24;
++v25;
}
while ( v13 > (int)v24 );
v7 = v46;
v12 = v49;
if ( v13 > 0 )
{
v30 = 0LL;
do
putIntervalArray(v6[v30], v8[v30]);
while ( nparts > (int)v30 );
}
LABEL_31:
chordAnalyze_most(v6, src);
chordAnalyze_putKeyAssociation(src, 0LL);
pieceScore = (int)scorePiece(v6, src, v8);
partsCp((__int64)v6, (__int64)v7);
v31 = 40000;
chordInfoCp(src, v5);
partsIntervalsCp((__int64)v8, v12);
v39 = *(double *)&LC11;
do
{
mutatePiece(v7);
for ( j = 0LL; nparts > (int)j; putIntervalArray(v7[j], *(_QWORD *)(v12 + 8 * j)) )
;
chordAnalyze_most(v7, v5);
chordAnalyze_putKeyAssociation(v5, 0LL);
v33 = scorePiece(v7, v5, v12);
v34 = v33;
v35 = v33 - pieceScore;
if ( v35 <= 0 && (double)-v35 / v39 >= 1.0 )
{
partsCp((__int64)v6, (__int64)v7);
chordInfoCp(src, v5);
partsIntervalsCp((__int64)v8, v12);
}
else
{
pieceScore = v34;
partsCp((__int64)v7, (__int64)v6);
chordInfoCp(v5, src);
partsIntervalsCp(v12, (__int64)v8);
++v41;
}
v39 = fmax(0.0, v39 - 1.0);
--v31;
}
while ( v31 );
partsCp((__int64)v6, (__int64)v7);
chordInfoCp(src, v5);
partsIntervalsCp((__int64)v8, v12);
outputMidge(v6, v42);
if ( v43 )
outputAnalysis(v43, v6, src);
if ( verboseP )
{
fprintf(stderr, "Piece Score: %d\n", pieceScore);
fprintf(stderr, "Acceptance rate: %f\n", (double)v41 / 40000.0);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // eax
void *v5; // r13
_QWORD *v6; // r14
_QWORD *v7; // rbp
_QWORD *v8; // r15
void *v9; // rax
__int64 v10; // r8
__int64 v11; // rsi
__int64 v12; // r12
int v13; // eax
__int64 v14; // rbx
void *v15; // rax
__int64 v16; // rdi
void *v17; // rax
__int64 v18; // rdi
void *v19; // rax
__int64 v20; // rdi
__int64 i; // rdx
int v22; // ebx
__int64 v23; // rdx
__int64 v24; // rbx
_QWORD *v25; // rbp
__int64 v26; // r12
int v27; // eax
_QWORD *v28; // rcx
bool v29; // cc
__int64 v30; // r8
int v31; // ebx
__int64 j; // r8
int v33; // eax
__int64 v34; // rdx
int v35; // eax
__int64 v37; // rdx
_DWORD *v38; // [rsp+8h] [rbp-140h]
double v39; // [rsp+8h] [rbp-140h]
void *src; // [rsp+10h] [rbp-138h]
int v41; // [rsp+1Ch] [rbp-12Ch]
char *v42; // [rsp+20h] [rbp-128h]
char *v43; // [rsp+28h] [rbp-120h]
__int64 v44; // [rsp+30h] [rbp-118h]
__int64 v45; // [rsp+30h] [rbp-118h]
_QWORD *v46; // [rsp+30h] [rbp-118h]
__int64 v47; // [rsp+38h] [rbp-110h]
__int64 v48; // [rsp+38h] [rbp-110h]
__int64 v49; // [rsp+38h] [rbp-110h]
int longind; // [rsp+4Ch] [rbp-FCh] BYREF
struct option longopts; // [rsp+50h] [rbp-F8h] BYREF
const char *v52; // [rsp+70h] [rbp-D8h]
int v53; // [rsp+78h] [rbp-D0h]
__int64 v54; // [rsp+80h] [rbp-C8h]
int v55; // [rsp+88h] [rbp-C0h]
const char *v56; // [rsp+90h] [rbp-B8h]
int v57; // [rsp+98h] [rbp-B0h]
__int64 v58; // [rsp+A0h] [rbp-A8h]
int v59; // [rsp+A8h] [rbp-A0h]
const char *v60; // [rsp+B0h] [rbp-98h]
int v61; // [rsp+B8h] [rbp-90h]
__int64 v62; // [rsp+C0h] [rbp-88h]
int v63; // [rsp+C8h] [rbp-80h]
const char *v64; // [rsp+D0h] [rbp-78h]
int v65; // [rsp+D8h] [rbp-70h]
__int64 v66; // [rsp+E0h] [rbp-68h]
int v67; // [rsp+E8h] [rbp-60h]
__int64 v68; // [rsp+F0h] [rbp-58h]
int v69; // [rsp+F8h] [rbp-50h]
__int64 v70; // [rsp+100h] [rbp-48h]
int v71; // [rsp+108h] [rbp-40h]

verboseP = 0;
nparts = 4;
longopts.name = "midge";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 109;
v52 = "analysis";
v53 = 1;
v54 = 0LL;
v55 = 97;
v56 = "nparts";
v57 = 1;
v58 = 0LL;
v59 = 110;
v60 = "help";
v61 = 0;
v62 = 0LL;
v63 = 104;
v64 = "verbose";
v65 = 0;
v66 = 0LL;
v67 = 118;
v68 = 0LL;
v69 = 0;
v70 = 0LL;
v71 = 0;
v41 = 0;
v43 = 0LL;
v42 = 0LL;
while ( 2 )
{
longind = 0;
v3 = getopt_long(argc, (char *const *)argv, "vhn:m:a:", &longopts, &longind);
if ( v3 != -1 )
{
switch ( v3 )
{
case 'a':
v43 = optarg;
continue;
case 'h':
v41 = 1;
continue;
case 'm':
v42 = optarg;
continue;
case 'n':
nparts = atoi(optarg);
if ( nparts <= 1 )
goto LABEL_6;
continue;
case 'v':
verboseP = 1;
continue;
default:
goto LABEL_6;
}
}
break;
}
if ( v41 )
func4(0);
if ( !v42 )
LABEL_6:
func4(1);
initGlobals();
v4 = time(0LL);
srand(v4);
rangemin = malloc(4LL * nparts);
v47 = rangemin;
rangemax = malloc(4LL * nparts);
v44 = rangemax;
v38 = malloc(4LL * nparts);
rangediff = v38;
src = malloc(32 * mdivision * (__int64)nmeasures);
v5 = malloc(32 * mdivision * (__int64)nmeasures);
v6 = malloc(8LL * (nparts + 1));
v7 = malloc(8LL * (nparts + 1));
v8 = malloc(8LL * (nparts + 1));
v9 = malloc(8LL * (nparts + 1));
v10 = v44;
v11 = v47;
v12 = (__int64)v9;
v13 = nparts;
if ( nparts > 0 )
{
v45 = v47;
v14 = 0LL;
v48 = v10;
do
{
v15 = malloc(8LL * totalSubdivisions);
v16 = totalSubdivisions;
v6[v14] = v15;
v17 = malloc(8 * v16);
v18 = totalSubdivisions;
v7[v14] = v17;
v19 = malloc(4 * v18);
v20 = totalSubdivisions;
v8[v14] = v19;
*(_QWORD *)(v12 + 8 * v14) = malloc(4 * v20);
v13 = nparts;
++v14;
}
while ( nparts > (int)v14 );
v11 = v45;
v10 = v48;
}
*(_QWORD *)v11 = 0x260000001CLL;
v6[v13] = 0LL;
v7[v13] = 0LL;
v8[v13] = 0LL;
*(_QWORD *)(v12 + 8LL * v13) = 0LL;
*(_QWORD *)v10 = 0x3700000030LL;
if ( v13 <= 2 )
{
if ( v13 <= 0 )
goto LABEL_31;
}
else
{
*(_DWORD *)(v11 + 8) = 43;
*(_DWORD *)(v10 + 8) = 62;
if ( v13 != 3 )
{
*(_DWORD *)(v11 + 12) = 50;
*(_DWORD *)(v10 + 12) = 67;
if ( v13 != 4 )
{
for ( i = 4LL; i != v13; *(_DWORD *)(v10 + 4 * i++) = v22 + 10 )
{
v22 = *(_DWORD *)(v10 + 4 * i - 4);
*(_DWORD *)(v11 + 4 * i) = *(_DWORD *)(v11 + 4 * i - 4) + 10;
}
goto LABEL_21;
}
}
}
v37 = 0LL;
do
{
*(_DWORD *)(v11 + 4 * v37) += 12;
*(_DWORD *)(v10 + 4 * v37++) += 12;
}
while ( v13 > (int)v37 );
LABEL_21:
v23 = 0LL;
do
{
v38[v23] = *(_DWORD *)(v10 + 4 * v23) - *(_DWORD *)(v11 + 4 * v23);
++v23;
}
while ( v13 > (int)v23 );
v49 = v12;
v24 = 0LL;
v46 = v7;
v25 = v6;
do
{
v26 = 0LL;
if ( totalSubdivisions > 0 )
{
do
{
v27 = rand();
v28 = (_QWORD *)(*v25 + 8 * v26++);
v29 = totalSubdivisions <= (int)v26;
*v28 = (unsigned int)(*(_DWORD *)(rangemin + 4 * v24) + v27 % *(_DWORD *)(rangediff + 4 * v24));
}
while ( !v29 );
v13 = nparts;
}
++v24;
++v25;
}
while ( v13 > (int)v24 );
v7 = v46;
v12 = v49;
if ( v13 > 0 )
{
v30 = 0LL;
do
func0(v6[v30], v8[v30]);
while ( nparts > (int)v30 );
}
LABEL_31:
chordAnalyze_most(v6, src);
chordAnalyze_putKeyAssociation(src, 0LL);
pieceScore = (int)scorePiece(v6, src, v8);
func1((__int64)v6, (__int64)v7);
v31 = 40000;
func3(src, v5);
func2((__int64)v8, v12);
v39 = *(double *)&LC11;
do
{
mutatePiece(v7);
for ( j = 0LL; nparts > (int)j; func0(v7[j], *(_QWORD *)(v12 + 8 * j)) )
;
chordAnalyze_most(v7, v5);
chordAnalyze_putKeyAssociation(v5, 0LL);
v33 = scorePiece(v7, v5, v12);
v34 = v33;
v35 = v33 - pieceScore;
if ( v35 <= 0 && (double)-v35 / v39 >= 1.0 )
{
func1((__int64)v6, (__int64)v7);
func3(src, v5);
func2((__int64)v8, v12);
}
else
{
pieceScore = v34;
func1((__int64)v7, (__int64)v6);
func3(v5, src);
func2(v12, (__int64)v8);
++v41;
}
v39 = fmax(0.0, v39 - 1.0);
--v31;
}
while ( v31 );
func1((__int64)v6, (__int64)v7);
func3(src, v5);
func2((__int64)v8, v12);
outputMidge(v6, v42);
if ( v43 )
outputAnalysis(v43, v6, src);
if ( verboseP )
{
fprintf(stderr, "Piece Score: %d\n", pieceScore);
fprintf(stderr, "Acceptance rate: %f\n", (double)v41 / 40000.0);
}
return 0;
}

original_code:
int main(int argc, char** argv) {
    char* midgeOutFile = ((void *)0);
    char* museDataOutFile = ((void *)0);
    char* analysisOutFile = ((void *)0);
    verboseP = 0;
    nparts = 4;
    int printHelpP = 0;
    struct option long_options[] =
        {
            {"midge", 1, 0, 'm'},
            {"analysis", 1, 0, 'a'},
            {"nparts", 1, 0, 'n'},
            {"help", 0, 0, 'h'},
            {"verbose", 0, 0, 'v'},
            {0,0,0,0}
        };
    while (1) {
        int c;
        int option_index = 0;
        c = getopt_long(argc, argv, "vhn:m:a:", long_options, &option_index);
        if (c == -1) {
            break;
        }
        switch(c) {
            case 'h':
                printHelpP = 1;
                break;
            case 'm':
                midgeOutFile = optarg;
                break;
            case 'a':
                analysisOutFile = optarg;
                break;
            case 'v':
                verboseP = 1;;
                break;
            case 'n':
                nparts = atoi(optarg);
                if (nparts < 2) {printHelp(1);}
                break;
            case '?':
                printHelp(1);
                break;
            default:
                printHelp(1);
                break;
        }
    }
    if(printHelpP) {
        printHelp(0);
    }
    if (museDataOutFile == ((void *)0) && midgeOutFile == ((void *)0)) {
        printHelp(1);
    }
    initGlobals();
    srand(time(((void *)0)));
    Note **parts, **trialParts;
    int **partsIntervals, **trialPartsIntervals;
    ChordInfo *chordInfo, *trialChordInfo;
    int key = 0;
    rangemin = malloc(sizeof(int) * nparts);
    rangemax = malloc(sizeof(int) * nparts);
    rangediff = malloc(sizeof(int) * nparts);
    chordInfo = malloc(sizeof(ChordInfo) * nmeasures * mdivision);
    trialChordInfo = malloc(sizeof(ChordInfo) * nmeasures * mdivision);
    parts = malloc(sizeof(Note*) * (nparts + 1));
    trialParts = malloc(sizeof(Note*) * (nparts + 1));
    partsIntervals = malloc(sizeof(int*) * (nparts+1));
    trialPartsIntervals = malloc(sizeof(int*) * (nparts+1));
    for (int i = 0; i < nparts; ++i) {
        parts[i] = malloc(sizeof(Note) * totalSubdivisions);
        trialParts[i] = malloc(sizeof(Note) * totalSubdivisions);
        partsIntervals[i] = malloc(sizeof(int) * totalSubdivisions);
        trialPartsIntervals[i] = malloc(sizeof(int) * totalSubdivisions);
    }
    parts[nparts] = 0;
    trialParts[nparts] = 0;
    partsIntervals[nparts] = 0;
    trialPartsIntervals[nparts] = 0;
    rangemin[0] = 28;
    rangemax[0] = 48;
    rangemin[1] = 38;
    rangemax[1] = 55;
    if (nparts > 2) {
        rangemin[2] = 43;
        rangemax[2] = 62;
    }
    if (nparts > 3) {
        rangemin[3] = 50;
        rangemax[3] = 67;
    }
    if (nparts > 4) {
        for(int i = 4; i < nparts; ++i) {
            rangemin[i] = rangemin[i-1] + 10;
            rangemax[i] = rangemax[i-1] + 10;
        }
    }
    if (nparts <= 4) {
        for(int i = 0; i < nparts; ++i) {
            rangemin[i] += 12;
            rangemax[i] += 12;
    }
    }
    for (int i = 0; i < nparts; ++i) {
        rangediff[i] = rangemax[i] - rangemin[i];
    }
    for (int i = 0; i < nparts; ++i) {
        for (int j = 0; j < totalSubdivisions; ++j) {
            int p = (rand() % rangediff[i]) + rangemin[i];
            parts[i][j].pitch = p;
            parts[i][j].flags = 0;
        }
    }
    for(int i = 0; i < nparts; ++i) {
        putIntervalArray(parts[i], partsIntervals[i]);
    }
    chordAnalyze_most(parts, chordInfo);
    chordAnalyze_putKeyAssociation(chordInfo, key);
    pieceScore = scorePiece(parts, chordInfo, partsIntervals);
    partsCp(parts, trialParts);
    chordInfoCp(chordInfo, trialChordInfo);
    partsIntervalsCp(partsIntervals, trialPartsIntervals);
    int acceptedChangeP = 1;
    double temperature = 5000;
    double coolRate = 1;
    double takechanceThresh = 1;
    int numPasses = 40000;
    int numAccepted = 0;
    int numRejected = 0;
    if (0) {
        numPasses = 0;
    }
    for(int i = 0; i < numPasses; ++i) {
        acceptedChangeP = 0;
        mutatePiece(trialParts);
        for(int i = 0; i < nparts; ++i) {
            putIntervalArray(trialParts[i], trialPartsIntervals[i]);
        }
        chordAnalyze_most(trialParts, trialChordInfo);
        chordAnalyze_putKeyAssociation(trialChordInfo, key);
        long trialScore = scorePiece(trialParts, trialChordInfo, trialPartsIntervals);
        int scoreDiff = trialScore - pieceScore;
        if (scoreDiff > 0) {
            acceptedChangeP = 1;
        } else {
            double takechance = -scoreDiff / temperature;
            acceptedChangeP = takechance < takechanceThresh ? 1 : 0;
        }
        if (acceptedChangeP) {
            pieceScore = trialScore;
            partsCp(trialParts, parts);
            chordInfoCp(trialChordInfo, chordInfo);
            partsIntervalsCp(trialPartsIntervals, partsIntervals);
            ++numAccepted;
        } else {
            partsCp(parts, trialParts);
            chordInfoCp(chordInfo, trialChordInfo);
            partsIntervalsCp(partsIntervals, trialPartsIntervals);
            ++numRejected;
        }
        temperature -= coolRate;
        if (temperature < 0) {
            temperature = 0;
        }
    }
    partsCp(parts, trialParts);
    chordInfoCp(chordInfo, trialChordInfo);
    partsIntervalsCp(partsIntervals, trialPartsIntervals);
    if (museDataOutFile != ((void *)0)) {
        outputMD(parts, museDataOutFile);
    }
    if (midgeOutFile != ((void *)0)) {
        outputMidge(parts, midgeOutFile);
    }
    if (analysisOutFile != ((void *)0)) {
        outputAnalysis(analysisOutFile, parts, chordInfo);
    }
    if (verboseP) {
        fprintf(stderr, "Piece Score: %d\n", pieceScore);
        fprintf(stderr, "Acceptance rate: %f\n", (double)numAccepted / numPasses);
    }
}

canonical_original_code:
int main(int argc, char **argv) {
    char *midgeOutFile = ((void *)0);
    char *museDataOutFile = ((void *)0);
    char *analysisOutFile = ((void *)0);
    verboseP = 0;
    nparts = 4;
    int printHelpP = 0;
    struct option long_options[] = {
            {"midge", 1, 0, 'm'},
            {"analysis", 1, 0, 'a'},
            {"nparts", 1, 0, 'n'},
            {"help", 0, 0, 'h'},
            {"verbose", 0, 0, 'v'},
            {0,0,0,0}
        };
    while (1) {
        int c;
        int option_index = 0;
        c = getopt_long(argc, argv, "vhn:m:a:", long_options, &option_index);
        if (c == -1) {
            break;
        }
        switch(c) {
            case 'h':
                printHelpP = 1;
                break;
            case 'm':
                midgeOutFile = optarg;
                break;
            case 'a':
                analysisOutFile = optarg;
                break;
            case 'v':
                verboseP = 1;;
                break;
            case 'n':
                nparts = atoi(optarg);
                if (nparts < 2) {printHelp(1);}
                break;
            case '?':
                printHelp(1);
                break;
            default:
                printHelp(1);
                break;
        }
    }
    if(printHelpP) {
        printHelp(0);
    }
    if (museDataOutFile == ((void *)0) && midgeOutFile == ((void *)0)) {
        printHelp(1);
    }
    initGlobals();
    srand(time(((void *)0)));
    struct notestruct **parts; struct notestruct **trialParts;
    int **partsIntervals; int **trialPartsIntervals;
    struct ChordInfoStruct *chordInfo; struct ChordInfoStruct *trialChordInfo;
    int key = 0;
    rangemin = malloc(sizeof(int) * nparts);
    rangemax = malloc(sizeof(int) * nparts);
    rangediff = malloc(sizeof(int) * nparts);
    chordInfo = malloc(sizeof(ChordInfo) * nmeasures * mdivision);
    trialChordInfo = malloc(sizeof(ChordInfo) * nmeasures * mdivision);
    parts = malloc(sizeof(struct notestruct *) * (nparts + 1));
    trialParts = malloc(sizeof(struct notestruct *) * (nparts + 1));
    partsIntervals = malloc(sizeof(int *) * (nparts+1));
    trialPartsIntervals = malloc(sizeof(int *) * (nparts+1));
    for (int i = 0; i < nparts; ++i) {
        parts[i] = malloc(sizeof(Note) * totalSubdivisions);
        trialParts[i] = malloc(sizeof(Note) * totalSubdivisions);
        partsIntervals[i] = malloc(sizeof(int) * totalSubdivisions);
        trialPartsIntervals[i] = malloc(sizeof(int) * totalSubdivisions);
    }
    parts[nparts] = 0;
    trialParts[nparts] = 0;
    partsIntervals[nparts] = 0;
    trialPartsIntervals[nparts] = 0;
    rangemin[0] = 28;
    rangemax[0] = 48;
    rangemin[1] = 38;
    rangemax[1] = 55;
    if (nparts > 2) {
        rangemin[2] = 43;
        rangemax[2] = 62;
    }
    if (nparts > 3) {
        rangemin[3] = 50;
        rangemax[3] = 67;
    }
    if (nparts > 4) {
        for(int i = 4; i < nparts; ++i) {
            rangemin[i] = rangemin[i-1] + 10;
            rangemax[i] = rangemax[i-1] + 10;
        }
    }
    if (nparts <= 4) {
        for(int i = 0; i < nparts; ++i) {
            rangemin[i] += 12;
            rangemax[i] += 12;
    }
    }
    for (int i = 0; i < nparts; ++i) {
        rangediff[i] = rangemax[i] - rangemin[i];
    }
    for (int i = 0; i < nparts; ++i) {
        for (int j = 0; j < totalSubdivisions; ++j) {
            int p = (rand() % rangediff[i]) + rangemin[i];
            parts[i][j].pitch = p;
            parts[i][j].flags = 0;
        }
    }
    for(int i = 0; i < nparts; ++i) {
        putIntervalArray(parts[i], partsIntervals[i]);
    }
    chordAnalyze_most(parts, chordInfo);
    chordAnalyze_putKeyAssociation(chordInfo, key);
    pieceScore = scorePiece(parts, chordInfo, partsIntervals);
    partsCp(parts, trialParts);
    chordInfoCp(chordInfo, trialChordInfo);
    partsIntervalsCp(partsIntervals, trialPartsIntervals);
    int acceptedChangeP = 1;
    double temperature = 5000;
    double coolRate = 1;
    double takechanceThresh = 1;
    int numPasses = 40000;
    int numAccepted = 0;
    int numRejected = 0;
    if (0) {
        numPasses = 0;
    }
    for(int i = 0; i < numPasses; ++i) {
        acceptedChangeP = 0;
        mutatePiece(trialParts);
        for(int i = 0; i < nparts; ++i) {
            putIntervalArray(trialParts[i], trialPartsIntervals[i]);
        }
        chordAnalyze_most(trialParts, trialChordInfo);
        chordAnalyze_putKeyAssociation(trialChordInfo, key);
        long trialScore = scorePiece(trialParts, trialChordInfo, trialPartsIntervals);
        int scoreDiff = trialScore - pieceScore;
        if (scoreDiff > 0) {
            acceptedChangeP = 1;
        } else {
            double takechance = -scoreDiff / temperature;
            acceptedChangeP = takechance < takechanceThresh ? 1 : 0;
        }
        if (acceptedChangeP) {
            pieceScore = trialScore;
            partsCp(trialParts, parts);
            chordInfoCp(trialChordInfo, chordInfo);
            partsIntervalsCp(trialPartsIntervals, partsIntervals);
            ++numAccepted;
        } else {
            partsCp(parts, trialParts);
            chordInfoCp(chordInfo, trialChordInfo);
            partsIntervalsCp(partsIntervals, trialPartsIntervals);
            ++numRejected;
        }
        temperature -= coolRate;
        if (temperature < 0) {
            temperature = 0;
        }
    }
    partsCp(parts, trialParts);
    chordInfoCp(chordInfo, trialChordInfo);
    partsIntervalsCp(partsIntervals, trialPartsIntervals);
    if (museDataOutFile != ((void *)0)) {
        outputMD(parts, museDataOutFile);
    }
    if (midgeOutFile != ((void *)0)) {
        outputMidge(parts, midgeOutFile);
    }
    if (analysisOutFile != ((void *)0)) {
        outputAnalysis(analysisOutFile, parts, chordInfo);
    }
    if (verboseP) {
        fprintf(stderr, "Piece Score: %d\n", pieceScore);
        fprintf(stderr, "Acceptance rate: %f\n", (double)numAccepted / numPasses);
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
midgeOutFile
char *

variable_types:
museDataOutFile
char *

variable_types:
analysisOutFile
char *

variable_types: printHelpP int

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

variable_types: c int

variable_types:
partsIntervals
int **

variable_types:
trialPartsIntervals
int **

variable_types: key int

variable_types: j int

variable_types: p int

variable_types: acceptedChangeP int

variable_types: temperature double

variable_types: coolRate double

variable_types: takechanceThresh double

variable_types: numPasses int

variable_types: numAccepted int

variable_types: numRejected int

variable_types: trialScore long

variable_types: scoreDiff int

variable_types: takechance double

user_defined_types: struct notestruct { int pitch; int flags; }

user_defined_types: enum ChordTypeEnum { ch_nochord=0, ch_maj=1, ch_min=2, ch_dim=3, ch_aug=4, ch_maj_7=5, ch_dom_7=6, ch_min_7=7, ch_halfdim_7=8, ch_fulldim_7=9, ch_aug_7=10 }


getNoteName

repo: willghatch/qiafph

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

result = (unsigned int)(a1 % 12);
if ( (unsigned int)result <= 0xB )
result = (unsigned __int8)CSWTCH_2[result];
return result;
}

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

result = (unsigned int)(a1 % 12);
if ( (unsigned int)result <= 0xB )
result = (unsigned __int8)CSWTCH_2[result];
return result;
}

original_code:
char getNoteName(Note n) {
    int p = n.pitch;
    p = p % 12;
    switch(p) {
        case 0:
            return 'C';
        case 2:
        case 1:
            return 'D';
        case 4:
        case 3:
            return 'E';
        case 5:
            return 'F';
        case 7:
        case 6:
            return 'G';
        case 9:
        case 8:
            return 'A';
        case 11:
        case 10:
            return 'B';
    }
}

canonical_original_code:
char getNoteName(struct notestruct n) {
    int p = n.pitch;
    p = p % 12;
    switch(p) {
        case 0:
            return 'C';
        case 2:
        case 1:
            return 'D';
        case 4:
        case 3:
            return 'E';
        case 5:
            return 'F';
        case 7:
        case 6:
            return 'G';
        case 9:
        case 8:
            return 'A';
        case 11:
        case 10:
            return 'B';
    }
}

variable_types: struct notestruct { int pitch; int flags; }

return_type: char


decompiled_code:
__int64 __fastcall getNoteName_lowercase(int a1)
{
return (unsigned int)getNoteName(a1) + 32;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (unsigned int)func0(a1) + 32;
}

original_code:
char getNoteName_lowercase(Note n) {
    char c = getNoteName(n);
    return c + 32;
}

canonical_original_code:
char getNoteName_lowercase(struct notestruct n) {
    char c = getNoteName(n);
    return c + 32;
}

variable_types: c char


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

switch ( a1 % 12 )
{
case 1:
case 3:
case 6:
case 8:
case 10:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( a1 % 12 )
{
case 1:
case 3:
case 6:
case 8:
case 10:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int flat_p(Note n) {
    int p = n.pitch % 12;
    switch(p) {
        case 8:
        case 10:
        case 1:
        case 3:
        case 6:
            return 1;
        default:
            return 0;
    }
}

canonical_original_code:
int flat_p(struct notestruct n) {
    int p = n.pitch % 12;
    switch(p) {
        case 8:
        case 10:
        case 1:
        case 3:
        case 6:
            return 1;
        default:
            return 0;
    }
}

return_type: int


getNoteOctave

decompiled_code:
__int64 __fastcall getNoteOctave(int a1)
{
return (unsigned int)(a1 / 12);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
return (unsigned int)(a1 / 12);
}

original_code:
int getNoteOctave(Note n) {
    return n.pitch / 12;
}

canonical_original_code:
int getNoteOctave(struct notestruct n) {
    return n.pitch / 12;
}


leadingToneP

decompiled_code:
_BOOL8 __fastcall leadingToneP(int a1, int a2)
{
return (a2 + 11) % 12 == a1 % 12;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1, int a2)
{
return (a2 + 11) % 12 == a1 % 12;
}

original_code:
int leadingToneP(int pitch, int key) {
    int lt = (key + 11) % 12;
    pitch %= 12;
    return pitch == lt;
}

variable_types: pitch int

variable_types: lt int


tonicNoteP

decompiled_code:
_BOOL8 __fastcall tonicNoteP(int a1, int a2)
{
return a1 % 12 == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int a1, int a2)
{
return a1 % 12 == a2;
}

original_code:
int tonicNoteP(int pitch, int key) {
    pitch %= 12;
    return pitch == key;
}

variable_types: key int


noteInKeyP

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

switch ( (a1 + a2) % 12 )
{
case 0:
case 2:
case 4:
case 5:
case 7:
case 9:
case 11:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( (a1 + a2) % 12 )
{
case 0:
case 2:
case 4:
case 5:
case 7:
case 9:
case 11:
result = 1LL;
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
int noteInKeyP(Note n, int key) {
    int p = n.pitch;
    p = (p + key) % 12;
    switch(p) {
        case 0:
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
        case 11:
            return 1;
        default:
            return 0;
    }
}

canonical_original_code:
int noteInKeyP(struct notestruct n, int key) {
    int p = n.pitch;
    p = (p + key) % 12;
    switch(p) {
        case 0:
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
        case 11:
            return 1;
        default:
            return 0;
    }
}


stepwiseInKeyP

decompiled_code:
__int64 __fastcall stepwiseInKeyP(int a1, int a2, int a3, __int64 a4, _BOOL4 a5)
{
int v5; // eax
__int64 result; // rax

v5 = (a1 + a3) % 12;
if ( a1 <= a2 )
{
a5 = 1;
if ( a1 == a2 )
{
LABEL_4:
result = a5;
}
else
{
switch ( v5 )
{
case 0:
case 5:
result = a2 - a1 == 1;
break;
case 2:
case 4:
case 7:
case 9:
case 11:
result = a2 - a1 == 2;
break;
default:
goto LABEL_4;
}
}
}
else
{
switch ( v5 )
{
case 0:
case 2:
case 4:
case 7:
case 9:
a5 = a1 - a2 == 2;
goto LABEL_4;
case 5:
case 11:
result = a1 - a2 == 1;
break;
default:
goto LABEL_4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, int a3, __int64 a4, _BOOL4 a5)
{
int v5; // eax
__int64 result; // rax

v5 = (a1 + a3) % 12;
if ( a1 <= a2 )
{
a5 = 1;
if ( a1 == a2 )
{
LABEL_4:
result = a5;
}
else
{
switch ( v5 )
{
case 0:
case 5:
result = a2 - a1 == 1;
break;
case 2:
case 4:
case 7:
case 9:
case 11:
result = a2 - a1 == 2;
break;
default:
goto LABEL_4;
}
}
}
else
{
switch ( v5 )
{
case 0:
case 2:
case 4:
case 7:
case 9:
a5 = a1 - a2 == 2;
goto LABEL_4;
case 5:
case 11:
result = a1 - a2 == 1;
break;
default:
goto LABEL_4;
}
}
return result;
}

original_code:
int stepwiseInKeyP(int p1, int p2, int key) {
    int p1KeyOffset = (p1 + key) % 12;
    if (1) {
        if (p1 > p2) {
            switch(p1KeyOffset) {
                case 0:
                case 2:
                case 4:
                case 7:
                case 9:
                    return p1 - p2 == 2;
                case 5:
                case 11:
                    return p1 - p2 == 1;
            }
        } else {
            if (p1 == p2) {
                return 1;
            }
            switch(p1KeyOffset) {
                case 2:
                case 4:
                case 7:
                case 9:
                case 11:
                    return p2 - p1 == 2;
                case 0:
                case 5:
                    return p2 - p1 == 1;
            }
        }
    }
}


allocChordArray

decompiled_code:
void allocChordArray()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
ChordInfo* allocChordArray() {
    ChordInfo* ptr = malloc(sizeof(ChordInfo)*nmeasures*(mdivision/sdivPerDiv));
}

canonical_original_code:
struct ChordInfoStruct *allocChordArray() {
    struct ChordInfoStruct *ptr = malloc(sizeof(ChordInfo)*nmeasures*(mdivision/sdivPerDiv));
}

variable_types: struct ChordInfoStruct { int rootNote; int inversion; enum ChordTypeEnum { ch_nochord=0, ch_maj=1, ch_min=2, ch_dim=3, ch_aug=4, ch_maj_7=5, ch_dom_7=6, ch_min_7=7, ch_halfdim_7=8, ch_fulldim_7=9, ch_aug_7=10 } type; int fullChordP; int doubledNote; int numNonChordSdivs; int numInPieceKey; int inNormalKeyChordsP; } *

user_defined_types: struct ChordInfoStruct { int rootNote; int inversion; enum ChordTypeEnum type; int fullChordP; int doubledNote; int numNonChordSdivs; int numInPieceKey; int inNormalKeyChordsP; }


minorChordP

decompiled_code:
__int64 __fastcall minorChordP(int a1)
{
return (a1 == 7) | (unsigned __int8)(a1 == 2);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
return (a1 == 7) | (unsigned __int8)(a1 == 2);
}

original_code:
int minorChordP(ChordType t) {
    return t == ch_min || t == ch_min_7;
}

canonical_original_code:
int minorChordP(enum ChordTypeEnum t) {
    return t == ch_min || t == ch_min_7;
}

variable_types: enum ChordTypeEnum { ch_nochord=0, ch_maj=1, ch_min=2, ch_dim=3, ch_aug=4, ch_maj_7=5, ch_dom_7=6, ch_min_7=7, ch_halfdim_7=8, ch_fulldim_7=9, ch_aug_7=10 }


diminishedChordP

decompiled_code:
__int64 __fastcall diminishedChordP(int a1)
{
return (a1 == 3) | (unsigned __int8)((unsigned int)(a1 - 8) <= 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
return (a1 == 3) | (unsigned __int8)((unsigned int)(a1 - 8) <= 1);
}

original_code:
int diminishedChordP(ChordType t) {
    return t == ch_dim || t == ch_halfdim_7 || t == ch_fulldim_7;
}

canonical_original_code:
int diminishedChordP(enum ChordTypeEnum t) {
    return t == ch_dim || t == ch_halfdim_7 || t == ch_fulldim_7;
}


majorChordP

decompiled_code:
_BOOL8 __fastcall majorChordP(int a1)
{
return (a1 & 0xFFFFFFFB) == 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return (a1 & 0xFFFFFFFB) == 1;
}

original_code:
int majorChordP(ChordType t) {
    return t == ch_maj || t == ch_maj_7;
}

canonical_original_code:
int majorChordP(enum ChordTypeEnum t) {
    return t == ch_maj || t == ch_maj_7;
}


countNonChordTones

decompiled_code:
__int64 __fastcall countNonChordTones(_DWORD *a1, int a2, int a3, _DWORD *a4)
{
int v6; // esi
int v7; // eax
_DWORD *v8; // r8
_DWORD *v9; // r9
int v10; // edx
int v11; // ecx
int v12; // ecx
int v13; // eax
int v14; // edx
__int64 result; // rax
int v16; // ecx
int v17; // edx
int v18; // edx

*a4 = 1;
v6 = a2 - *a1;
*a4 = *a1 != 0;
minorChordP(a3);
v7 = diminishedChordP(a3);
v10 = v7;
if ( v11 )
{
v16 = v8[3];
v13 = v6 - v16;
if ( !v16 )
*v9 = 0;
}
else
{
if ( !v7 )
{
v17 = v8[4];
v13 = v6 - v17;
if ( !v17 )
*v9 = 0;
goto LABEL_14;
}
v12 = v8[3];
v13 = v6 - v12;
if ( v12 )
goto LABEL_6;
*v9 = 0;
}
if ( v10 )
{
LABEL_6:
v14 = v8[6];
result = (unsigned int)(v13 - v14);
if ( v14 )
goto LABEL_7;
goto LABEL_15;
}
LABEL_14:
v18 = v8[7];
result = (unsigned int)(v13 - v18);
if ( v18 )
{
LABEL_7:
if ( a3 != 9 )
goto LABEL_8;
return (unsigned int)(result - v8[9]);
}
LABEL_15:
*v9 = 0;
if ( a3 == 9 )
return (unsigned int)(result - v8[9]);
LABEL_8:
if ( (unsigned int)(a3 - 6) <= 2 )
return (unsigned int)(result - v8[10]);
if ( a3 == 5 )
result = (unsigned int)(result - v8[11]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, int a2, int a3, _DWORD *a4)
{
int v6; // esi
int v7; // eax
_DWORD *v8; // r8
_DWORD *v9; // r9
int v10; // edx
int v11; // ecx
int v12; // ecx
int v13; // eax
int v14; // edx
__int64 result; // rax
int v16; // ecx
int v17; // edx
int v18; // edx

*a4 = 1;
v6 = a2 - *a1;
*a4 = *a1 != 0;
func1(a3);
v7 = func2(a3);
v10 = v7;
if ( v11 )
{
v16 = v8[3];
v13 = v6 - v16;
if ( !v16 )
*v9 = 0;
}
else
{
if ( !v7 )
{
v17 = v8[4];
v13 = v6 - v17;
if ( !v17 )
*v9 = 0;
goto LABEL_14;
}
v12 = v8[3];
v13 = v6 - v12;
if ( v12 )
goto LABEL_6;
*v9 = 0;
}
if ( v10 )
{
LABEL_6:
v14 = v8[6];
result = (unsigned int)(v13 - v14);
if ( v14 )
goto LABEL_7;
goto LABEL_15;
}
LABEL_14:
v18 = v8[7];
result = (unsigned int)(v13 - v18);
if ( v18 )
{
LABEL_7:
if ( a3 != 9 )
goto LABEL_8;
return (unsigned int)(result - v8[9]);
}
LABEL_15:
*v9 = 0;
if ( a3 == 9 )
return (unsigned int)(result - v8[9]);
LABEL_8:
if ( (unsigned int)(a3 - 6) <= 2 )
return (unsigned int)(result - v8[10]);
if ( a3 == 5 )
result = (unsigned int)(result - v8[11]);
return result;
}

original_code:
int countNonChordTones(int* intervalCount, int sdivs, ChordType ct, int* fullChordP) {
    int ncc = sdivs;
    *fullChordP = 1;
    ncc -= intervalCount[0];
    if (intervalCount[0] == 0)
        {*fullChordP = 0;}
    if (minorChordP(ct) || diminishedChordP(ct)) {
        ncc -= intervalCount[3];
        if(intervalCount[3] == 0)
            {*fullChordP = 0;}
    } else {
        ncc -= intervalCount[4];
        if(intervalCount[4] == 0)
            {*fullChordP = 0;}
    }
    if (diminishedChordP(ct)) {
        ncc -= intervalCount[6];
        if(intervalCount[6] == 0)
            {*fullChordP = 0;}
    } else {
        ncc -= intervalCount[7];
        if(intervalCount[7] == 0)
            {*fullChordP = 0;}
    }
    if (ct == ch_fulldim_7)
        {ncc -= intervalCount[9];}
    if (ct == ch_halfdim_7 || ct == ch_min_7 || ct == ch_dom_7)
        {ncc -= intervalCount[10];}
    if (ct == ch_maj_7)
        {ncc -= intervalCount[11];}
    return ncc;
}

canonical_original_code:
int countNonChordTones(int *intervalCount, int sdivs, enum ChordTypeEnum ct, int *fullChordP) {
    int ncc = sdivs;
    *fullChordP = 1;
    ncc -= intervalCount[0];
    if (intervalCount[0] == 0)
        {*fullChordP = 0;}
    if (minorChordP(ct) || diminishedChordP(ct)) {
        ncc -= intervalCount[3];
        if(intervalCount[3] == 0)
            {*fullChordP = 0;}
    } else {
        ncc -= intervalCount[4];
        if(intervalCount[4] == 0)
            {*fullChordP = 0;}
    }
    if (diminishedChordP(ct)) {
        ncc -= intervalCount[6];
        if(intervalCount[6] == 0)
            {*fullChordP = 0;}
    } else {
        ncc -= intervalCount[7];
        if(intervalCount[7] == 0)
            {*fullChordP = 0;}
    }
    if (ct == ch_fulldim_7)
        {ncc -= intervalCount[9];}
    if (ct == ch_halfdim_7 || ct == ch_min_7 || ct == ch_dom_7)
        {ncc -= intervalCount[10];}
    if (ct == ch_maj_7)
        {ncc -= intervalCount[11];}
    return ncc;
}

variable_types:
intervalCount
int *

variable_types: sdivs int

variable_types:
fullChordP
int *

variable_types: ncc int


decompiled_code:
__int64 __fastcall chordAnalyze_most(__int64 a1, __int64 a2)
{
int v2; // er11
void *v3; // rsp
__int64 result; // rax
int v5; // er12
int v6; // er15
int v7; // er10
int v8; // er9
int v9; // er8
int v10; // er14
__int64 v11; // rax
__int64 v12; // rdx
__int64 v13; // [rsp+0h] [rbp-40h] BYREF
unsigned int v14; // [rsp+Ch] [rbp-34h]

v13 = a2;
v14 = 0;
v2 = mdivision;
v3 = alloca(4LL * sdivPerDiv * nparts);
for ( result = nmeasures; nmeasures > (int)v14; result = v14 )
{
v5 = 0;
if ( v2 > 0 )
{
do
{
v6 = sdivPerDiv;
v7 = nparts;
if ( sdivPerDiv > 0 )
{
v8 = 0;
v9 = sdivPerDiv * (v5 + v2 * v14);
v10 = sdivPerDiv + v9;
do
{
if ( v7 > 0 )
{
v11 = 0LL;
do
{
*((_DWORD *)&v13 + v8 + v11) = *(_DWORD *)(*(_QWORD *)(a1 + 8 * v11) + 8LL * v9);
v12 = v11++;
}
while ( v12 != v7 - 1 );
}
++v9;
v8 += v7;
}
while ( v10 != v9 );
}
++v5;
getChordInfo_most((int *)&v13, v7 * v6);
v2 = mdivision;
}
while ( mdivision > v5 );
}
++v14;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // er11
void *v3; // rsp
__int64 result; // rax
int v5; // er12
int v6; // er15
int v7; // er10
int v8; // er9
int v9; // er8
int v10; // er14
__int64 v11; // rax
__int64 v12; // rdx
__int64 v13; // [rsp+0h] [rbp-40h] BYREF
unsigned int v14; // [rsp+Ch] [rbp-34h]

v13 = a2;
v14 = 0;
v2 = mdivision;
v3 = alloca(4LL * sdivPerDiv * nparts);
for ( result = nmeasures; nmeasures > (int)v14; result = v14 )
{
v5 = 0;
if ( v2 > 0 )
{
do
{
v6 = sdivPerDiv;
v7 = nparts;
if ( sdivPerDiv > 0 )
{
v8 = 0;
v9 = sdivPerDiv * (v5 + v2 * v14);
v10 = sdivPerDiv + v9;
do
{
if ( v7 > 0 )
{
v11 = 0LL;
do
{
*((_DWORD *)&v13 + v8 + v11) = *(_DWORD *)(*(_QWORD *)(a1 + 8 * v11) + 8LL * v9);
v12 = v11++;
}
while ( v12 != v7 - 1 );
}
++v9;
v8 += v7;
}
while ( v10 != v9 );
}
++v5;
func5((int *)&v13, v7 * v6);
v2 = mdivision;
}
while ( mdivision > v5 );
}
++v14;
}
return result;
}

original_code:
void chordAnalyze_most(Note** parts, ChordInfo* chords) {
    int sdivPitches[nparts*sdivPerDiv];
    for(int measure = 0; measure < nmeasures; ++measure) {
        int sdivPitch = 0;
        for(int beat = 0; beat < mdivision; ++beat) {
            for(int sdiv = 0; sdiv < sdivPerDiv; ++sdiv) {
                for(int partno = 0; partno < nparts; ++partno) {
                    int globalSdivNo = measure*mdivision*sdivPerDiv + beat*sdivPerDiv + sdiv;
                    sdivPitches[sdiv*nparts + partno] = parts[partno][globalSdivNo].pitch;
                }
            }
            getChordInfo_most(sdivPitches, nparts*sdivPerDiv, chords+(measure*mdivision+beat));
        }
    }
}

canonical_original_code:
void chordAnalyze_most(struct notestruct **parts, struct ChordInfoStruct *chords) {
    int sdivPitches[-1];
    for(int measure = 0; measure < nmeasures; ++measure) {
        int sdivPitch = 0;
        for(int beat = 0; beat < mdivision; ++beat) {
            for(int sdiv = 0; sdiv < sdivPerDiv; ++sdiv) {
                for(int partno = 0; partno < nparts; ++partno) {
                    int globalSdivNo = measure*mdivision*sdivPerDiv + beat*sdivPerDiv + sdiv;
                    sdivPitches[sdiv*nparts + partno] = parts[partno][globalSdivNo].pitch;
                }
            }
            getChordInfo_most(sdivPitches, nparts*sdivPerDiv, chords+(measure*mdivision+beat));
        }
    }
}

variable_types: struct notestruct { int pitch; int flags; } **

variable_types:
sdivPitches
int [-1]

variable_types: measure int

variable_types: sdivPitch int

variable_types: beat int

variable_types: sdiv int

variable_types: partno int

variable_types: globalSdivNo int

return_type: void


decompiled_code:
__int64 __fastcall chordAnalyze_putKeyAssociation(_DWORD *a1, int a2)
{
__int64 result; // rax
_DWORD *v4; // rsi
__int64 v5; // r8
int v6; // edi
int v7; // ecx

result = (unsigned int)(mdivision * nmeasures);
if ( (int)result > 0 )
{
v4 = a1;
v5 = (__int64)&a1[8 * (unsigned int)(result - 1) + 8];
do
{
v6 = v4[2];
v7 = (a2 + *v4) % 12;
switch ( v7 )
{
case 0:
result = majorChordP(v6);
v7 = 1;
break;
case 1:
v7 = 2;
result = 0LL;
break;
case 2:
result = minorChordP(v6);
break;
case 3:
goto LABEL_5;
case 4:
result = minorChordP(v6);
v7 = 3;
break;
case 5:
result = majorChordP(v6);
v7 = 4;
break;
case 6:
v7 = 5;
result = 0LL;
break;
case 7:
result = majorChordP(v6);
v7 = 5;
break;
case 8:
v7 = 6;
result = 0LL;
break;
case 9:
result = minorChordP(v6);
v7 = 6;
break;
case 10:
v7 = 7;
LABEL_5:
result = 0LL;
break;
case 11:
result = diminishedChordP(v6);
v7 = 7;
break;
default:
JUMPOUT(0x778LL);
}
v4[7] = result;
v4 += 8;
*(v4 - 2) = v7;
}
while ( v4 != (_DWORD *)v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, int a2)
{
__int64 result; // rax
_DWORD *v4; // rsi
__int64 v5; // r8
int v6; // edi
int v7; // ecx

result = (unsigned int)(mdivision * nmeasures);
if ( (int)result > 0 )
{
v4 = a1;
v5 = (__int64)&a1[8 * (unsigned int)(result - 1) + 8];
do
{
v6 = v4[2];
v7 = (a2 + *v4) % 12;
switch ( v7 )
{
case 0:
result = func3(v6);
v7 = 1;
break;
case 1:
v7 = 2;
result = 0LL;
break;
case 2:
result = func1(v6);
break;
case 3:
goto LABEL_5;
case 4:
result = func1(v6);
v7 = 3;
break;
case 5:
result = func3(v6);
v7 = 4;
break;
case 6:
v7 = 5;
result = 0LL;
break;
case 7:
result = func3(v6);
v7 = 5;
break;
case 8:
v7 = 6;
result = 0LL;
break;
case 9:
result = func1(v6);
v7 = 6;
break;
case 10:
v7 = 7;
LABEL_5:
result = 0LL;
break;
case 11:
result = func2(v6);
v7 = 7;
break;
default:
JUMPOUT(0x778LL);
}
v4[7] = result;
v4 += 8;
*(v4 - 2) = v7;
}
while ( v4 != (_DWORD *)v5 );
}
return result;
}

original_code:
void chordAnalyze_putKeyAssociation(ChordInfo* chordInfo, int key) {
    for(int i = 0; i < nmeasures*mdivision; ++i) {
        int interval = (chordInfo[i].rootNote + key) % 12;
        ChordType t = chordInfo[i].type;
        int m = 0;
        int M = 0;
        int num = 0;
        switch(interval) {
            case 0:
                M = majorChordP(t);
                m = minorChordP(t);
                num = 1;
                break;
            case 1:
                M = 0;
                m = 0;
                num = 2;
                break;
            case 2:
                M = minorChordP(t);
                m = diminishedChordP(t);
                num = 2;
                break;
            case 3:
                M = 0;
                m = majorChordP(t);
                num = 3;
                break;
            case 4:
                M = minorChordP(t);
                m = 0;
                num = 3;
                break;
            case 5:
                M = majorChordP(t);
                m = minorChordP(t);
                num = 4;
                break;
            case 6:
                M = 0;
                m = 0;
                num = 5;
                break;
            case 7:
                M = majorChordP(t);
                m = minorChordP(t) || majorChordP(t);
                num = 5;
                break;
            case 8:
                M = 0;
                m = majorChordP(t);
                num = 6;
                break;
            case 9:
                M = minorChordP(t);
                m = 0;
                num = 6;
                break;
            case 10:
                M = 0;
                m = majorChordP(t);
                num = 7;
                break;
            case 11:
                M = diminishedChordP(t);
                m = diminishedChordP(t);
                num = 7;
                break;
        }
        chordInfo[i].inNormalKeyChordsP = M;
        chordInfo[i].numInPieceKey = num;
    }
}

canonical_original_code:
void chordAnalyze_putKeyAssociation(struct ChordInfoStruct *chordInfo, int key) {
    for(int i = 0; i < nmeasures*mdivision; ++i) {
        int interval = (chordInfo[i].rootNote + key) % 12;
        enum ChordTypeEnum t = chordInfo[i].type;
        int m = 0;
        int M = 0;
        int num = 0;
        switch(interval) {
            case 0:
                M = majorChordP(t);
                m = minorChordP(t);
                num = 1;
                break;
            case 1:
                M = 0;
                m = 0;
                num = 2;
                break;
            case 2:
                M = minorChordP(t);
                m = diminishedChordP(t);
                num = 2;
                break;
            case 3:
                M = 0;
                m = majorChordP(t);
                num = 3;
                break;
            case 4:
                M = minorChordP(t);
                m = 0;
                num = 3;
                break;
            case 5:
                M = majorChordP(t);
                m = minorChordP(t);
                num = 4;
                break;
            case 6:
                M = 0;
                m = 0;
                num = 5;
                break;
            case 7:
                M = majorChordP(t);
                m = minorChordP(t) || majorChordP(t);
                num = 5;
                break;
            case 8:
                M = 0;
                m = majorChordP(t);
                num = 6;
                break;
            case 9:
                M = minorChordP(t);
                m = 0;
                num = 6;
                break;
            case 10:
                M = 0;
                m = majorChordP(t);
                num = 7;
                break;
            case 11:
                M = diminishedChordP(t);
                m = diminishedChordP(t);
                num = 7;
                break;
        }
        chordInfo[i].inNormalKeyChordsP = M;
        chordInfo[i].numInPieceKey = num;
    }
}

variable_types: i int

variable_types: interval int

variable_types: m int

variable_types: M int

variable_types: num int


numPartsOnNote

decompiled_code:
__int64 __fastcall numPartsOnNote(int a1, int a2, __int64 a3)
{
int v4; // er13
__int64 v5; // rdx
void *v6; // rsp
_DWORD *v7; // rax
int v8; // er9
int v9; // er14
_DWORD *v10; // rcx
__int64 i; // rsi
__int64 v12; // rdx
_DWORD *v13; // rax
_DWORD *v14; // rdx
_DWORD *v15; // rax
unsigned int v16; // er8
__int64 v18; // [rsp+0h] [rbp-20h] BYREF

v4 = nparts;
v5 = 4LL * nparts;
v6 = alloca(v5);
v7 = memset(&v18, 0, v5);
v8 = sdivPerDiv;
v9 = sdivPerDiv * a2;
if ( v4 <= 0 )
return 0LL;
v10 = v7;
for ( i = 0LL; i != v4; ++i )
{
if ( v8 > 0 )
{
v12 = *(_QWORD *)(a3 + 8 * i);
v13 = (_DWORD *)(v12 + 8LL * v9);
v14 = (_DWORD *)(8 * (v9 + (unsigned __int64)(unsigned int)(v8 - 1) + 1) + v12);
do
{
if ( *v13 == a1 )
v10[i] = 1;
v13 += 2;
}
while ( v13 != v14 );
}
}
v15 = v10;
v16 = 0;
do
v16 += *v15++;
while ( &v10[i] != v15 );
return v16;
}

original_code:
int numPartsOnNote(int pitch, int mdivNum, Note** parts) {
    int onPitch[nparts];
    memset(onPitch, 0, sizeof(int) * nparts);
    int sdivNum = mdivNum * sdivPerDiv;
    for (int i = 0; i < nparts; ++i) {
        for(int j = 0; j < sdivPerDiv; ++j) {
            if (parts[i][sdivNum+j].pitch == pitch) {
                onPitch[i] = 1;
            }
        }
    }
    int ret = 0;
    for (int i = 0; i < nparts; ++i) {
        ret += onPitch[i];
    }
    return ret;
}

canonical_original_code:
int numPartsOnNote(int pitch, int mdivNum, struct notestruct **parts) {
    int onPitch[-1];
    memset(onPitch, 0, sizeof(int) * nparts);
    int sdivNum = mdivNum * sdivPerDiv;
    for (int i = 0; i < nparts; ++i) {
        for(int j = 0; j < sdivPerDiv; ++j) {
            if (parts[i][sdivNum+j].pitch == pitch) {
                onPitch[i] = 1;
            }
        }
    }
    int ret = 0;
    for (int i = 0; i < nparts; ++i) {
        ret += onPitch[i];
    }
    return ret;
}

variable_types: pitch int

variable_types: mdivNum int

variable_types:
onPitch
int [-1]

variable_types: sdivNum int

variable_types: j int

variable_types: ret int


changeRandSdivision

decompiled_code:
__int64 __fastcall changeRandSdivision(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // edx
__int64 result; // rax

v1 = rand() % nparts;
v2 = rand() % totalSubdivisions;
v3 = rand() % *(_DWORD *)(rangediff + 4LL * v1);
result = rangemin;
*(_QWORD *)(*(_QWORD *)(a1 + 8LL * v1) + 8 * v2) = (unsigned int)(*(_DWORD *)(rangemin + 4LL * v1) + v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // edx
__int64 result; // rax

v1 = rand() % nparts;
v2 = rand() % totalSubdivisions;
v3 = rand() % *(_DWORD *)(rangediff + 4LL * v1);
result = rangemin;
*(_QWORD *)(*(_QWORD *)(a1 + 8LL * v1) + 8 * v2) = (unsigned int)(*(_DWORD *)(rangemin + 4LL * v1) + v3);
return result;
}

original_code:
void changeRandSdivision(Note** parts) {
    int part = rand() % nparts;
    int sdiv = rand() % totalSubdivisions;
    int pitch = (rand() % rangediff[part]) + rangemin[part];
    parts[part][sdiv].pitch = pitch;
    parts[part][sdiv].flags = 0;
}

canonical_original_code:
void changeRandSdivision(struct notestruct **parts) {
    int part = rand() % nparts;
    int sdiv = rand() % totalSubdivisions;
    int pitch = (rand() % rangediff[part]) + rangemin[part];
    parts[part][sdiv].pitch = pitch;
    parts[part][sdiv].flags = 0;
}

variable_types: struct notestruct { int pitch; int flags; } **

variable_types: part int


changeRandMdivision

decompiled_code:
int *__fastcall changeRandMdivision(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // edx
int *result; // rax
int v5; // edx
__int64 v6; // rcx
int *v7; // rcx

v1 = rand() % nparts;
v2 = rand() % (nmeasures * mdivision);
v3 = rand() % *(_DWORD *)(rangediff + 4LL * v1);
result = (int *)rangemin;
v5 = *(_DWORD *)(rangemin + 4LL * v1) + v3;
if ( sdivPerDiv > 0 )
{
v6 = *(_QWORD *)(a1 + 8LL * v1);
result = (int *)(v6 + 8 * v2);
v7 = (int *)(v6 + 8 * (v2 + (unsigned int)(sdivPerDiv - 1) + 1));
do
{
*result = v5;
result += 2;
*(result - 1) = 0;
}
while ( result != v7 );
}
return result;
}

canonical_decompiled_code:
int *__fastcall func1(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
int v3; // edx
int *result; // rax
int v5; // edx
__int64 v6; // rcx
int *v7; // rcx

v1 = rand() % nparts;
v2 = rand() % (nmeasures * mdivision);
v3 = rand() % *(_DWORD *)(rangediff + 4LL * v1);
result = (int *)rangemin;
v5 = *(_DWORD *)(rangemin + 4LL * v1) + v3;
if ( sdivPerDiv > 0 )
{
v6 = *(_QWORD *)(a1 + 8LL * v1);
result = (int *)(v6 + 8 * v2);
v7 = (int *)(v6 + 8 * (v2 + (unsigned int)(sdivPerDiv - 1) + 1));
do
{
*result = v5;
result += 2;
*(result - 1) = 0;
}
while ( result != v7 );
}
return result;
}

original_code:
void changeRandMdivision(Note** parts) {
    int part = rand() % nparts;
    int mdiv = rand() % (nmeasures * mdivision);
    int pitch = (rand() % rangediff[part]) + rangemin[part];
    for(int i = 0; i < sdivPerDiv; ++i) {
        parts[part][mdiv+i].pitch = pitch;
        parts[part][mdiv+i].flags = 0;
    }
}

canonical_original_code:
void changeRandMdivision(struct notestruct **parts) {
    int part = rand() % nparts;
    int mdiv = rand() % (nmeasures * mdivision);
    int pitch = (rand() % rangediff[part]) + rangemin[part];
    for(int i = 0; i < sdivPerDiv; ++i) {
        parts[part][mdiv+i].pitch = pitch;
        parts[part][mdiv+i].flags = 0;
    }
}

variable_types: mdiv int


changeNRandMdivisions

decompiled_code:
int *__fastcall changeNRandMdivisions(__int64 a1, int a2)
{
int i; // ebx
int *result; // rax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = changeRandMdivision(a1);
}
return result;
}

canonical_decompiled_code:
int *__fastcall func2(__int64 a1, int a2)
{
int i; // ebx
int *result; // rax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = func1(a1);
}
return result;
}

original_code:
void changeNRandMdivisions(Note** parts, int n) {
    for (int i = 0; i < n; ++i) {
        changeRandMdivision(parts);
    }
}

canonical_original_code:
void changeNRandMdivisions(struct notestruct **parts, int n) {
    for (int i = 0; i < n; ++i) {
        changeRandMdivision(parts);
    }
}

variable_types: n int


changeNRandSdivisions

decompiled_code:
__int64 __fastcall changeNRandSdivisions(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = changeRandSdivision(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = func0(a1);
}
return result;
}

original_code:
void changeNRandSdivisions(Note** parts, int n) {
    for (int i = 0; i < n; ++i) {
        changeRandSdivision(parts);
    }
}

canonical_original_code:
void changeNRandSdivisions(struct notestruct **parts, int n) {
    for (int i = 0; i < n; ++i) {
        changeRandSdivision(parts);
    }
}


putRandSdivisionInChord

decompiled_code:
void putRandSdivisionInChord()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void putRandSdivisionInChord(Note** parts, ChordInfo* chords) {
}

canonical_original_code:
void putRandSdivisionInChord(struct notestruct **parts, struct ChordInfoStruct *chords) {
}

variable_types: struct ChordInfoStruct { int rootNote; int inversion; enum ChordTypeEnum { ch_nochord=0, ch_maj=1, ch_min=2, ch_dim=3, ch_aug=4, ch_maj_7=5, ch_dom_7=6, ch_min_7=7, ch_halfdim_7=8, ch_fulldim_7=9, ch_aug_7=10 } type; int fullChordP; int doubledNote; int numNonChordSdivs; int numInPieceKey; int inNormalKeyChordsP; } *


mutatePiece

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

result = (unsigned int)(rand() % 21);
switch ( (int)result )
{
case 0:
result = changeNRandSdivisions(a1, 20);
break;
case 1:
result = changeNRandSdivisions(a1, 1);
break;
case 2:
result = changeNRandSdivisions(a1, 2);
break;
case 3:
result = changeNRandSdivisions(a1, 3);
break;
case 4:
result = changeNRandSdivisions(a1, 4);
break;
case 5:
result = changeNRandSdivisions(a1, 5);
break;
case 6:
result = changeNRandSdivisions(a1, 6);
break;
case 7:
result = changeNRandSdivisions(a1, 7);
break;
case 8:
result = changeNRandSdivisions(a1, 8);
break;
case 9:
result = changeNRandSdivisions(a1, 9);
break;
case 10:
result = changeNRandSdivisions(a1, 10);
break;
case 11:
result = (__int64)changeNRandMdivisions(a1, 1);
break;
case 12:
result = (__int64)changeNRandMdivisions(a1, 2);
break;
case 13:
result = (__int64)changeNRandMdivisions(a1, 3);
break;
case 14:
result = (__int64)changeNRandMdivisions(a1, 4);
break;
case 15:
result = (__int64)changeNRandMdivisions(a1, 5);
break;
case 16:
result = (__int64)changeNRandMdivisions(a1, 6);
break;
case 17:
result = (__int64)changeNRandMdivisions(a1, 7);
break;
case 18:
result = (__int64)changeNRandMdivisions(a1, 8);
break;
case 19:
result = (__int64)changeNRandMdivisions(a1, 9);
break;
case 20:
result = (__int64)changeNRandMdivisions(a1, 10);
break;
default:
return result;
}
return result;
}

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

result = (unsigned int)(rand() % 21);
switch ( (int)result )
{
case 0:
result = func3(a1, 20);
break;
case 1:
result = func3(a1, 1);
break;
case 2:
result = func3(a1, 2);
break;
case 3:
result = func3(a1, 3);
break;
case 4:
result = func3(a1, 4);
break;
case 5:
result = func3(a1, 5);
break;
case 6:
result = func3(a1, 6);
break;
case 7:
result = func3(a1, 7);
break;
case 8:
result = func3(a1, 8);
break;
case 9:
result = func3(a1, 9);
break;
case 10:
result = func3(a1, 10);
break;
case 11:
result = (__int64)func2(a1, 1);
break;
case 12:
result = (__int64)func2(a1, 2);
break;
case 13:
result = (__int64)func2(a1, 3);
break;
case 14:
result = (__int64)func2(a1, 4);
break;
case 15:
result = (__int64)func2(a1, 5);
break;
case 16:
result = (__int64)func2(a1, 6);
break;
case 17:
result = (__int64)func2(a1, 7);
break;
case 18:
result = (__int64)func2(a1, 8);
break;
case 19:
result = (__int64)func2(a1, 9);
break;
case 20:
result = (__int64)func2(a1, 10);
break;
default:
return result;
}
return result;
}

original_code:
void mutatePiece(Note** parts) {
    int mutation = rand() % 21;
    switch(mutation) {
        case 0:
            changeNRandSdivisions(parts, 20); return;
        case 1:
            changeNRandSdivisions(parts, 1); return;
        case 2:
            changeNRandSdivisions(parts, 2); return;
        case 3:
            changeNRandSdivisions(parts, 3); return;
        case 4:
            changeNRandSdivisions(parts, 4); return;
        case 5:
            changeNRandSdivisions(parts, 5); return;
        case 6:
            changeNRandSdivisions(parts, 6); return;
        case 7:
            changeNRandSdivisions(parts, 7); return;
        case 8:
            changeNRandSdivisions(parts, 8); return;
        case 9:
            changeNRandSdivisions(parts, 9); return;
        case 10:
            changeNRandSdivisions(parts, 10); return;
        case 11:
            changeNRandMdivisions(parts, 1); return;
        case 12:
            changeNRandMdivisions(parts, 2); return;
        case 13:
            changeNRandMdivisions(parts, 3); return;
        case 14:
            changeNRandMdivisions(parts, 4); return;
        case 15:
            changeNRandMdivisions(parts, 5); return;
        case 16:
            changeNRandMdivisions(parts, 6); return;
        case 17:
            changeNRandMdivisions(parts, 7); return;
        case 18:
            changeNRandMdivisions(parts, 8); return;
        case 19:
            changeNRandMdivisions(parts, 9); return;
        case 20:
            changeNRandMdivisions(parts, 10); return;
    }
}

canonical_original_code:
void mutatePiece(struct notestruct **parts) {
    int mutation = rand() % 21;
    switch(mutation) {
        case 0:
            changeNRandSdivisions(parts, 20); return;
        case 1:
            changeNRandSdivisions(parts, 1); return;
        case 2:
            changeNRandSdivisions(parts, 2); return;
        case 3:
            changeNRandSdivisions(parts, 3); return;
        case 4:
            changeNRandSdivisions(parts, 4); return;
        case 5:
            changeNRandSdivisions(parts, 5); return;
        case 6:
            changeNRandSdivisions(parts, 6); return;
        case 7:
            changeNRandSdivisions(parts, 7); return;
        case 8:
            changeNRandSdivisions(parts, 8); return;
        case 9:
            changeNRandSdivisions(parts, 9); return;
        case 10:
            changeNRandSdivisions(parts, 10); return;
        case 11:
            changeNRandMdivisions(parts, 1); return;
        case 12:
            changeNRandMdivisions(parts, 2); return;
        case 13:
            changeNRandMdivisions(parts, 3); return;
        case 14:
            changeNRandMdivisions(parts, 4); return;
        case 15:
            changeNRandMdivisions(parts, 5); return;
        case 16:
            changeNRandMdivisions(parts, 6); return;
        case 17:
            changeNRandMdivisions(parts, 7); return;
        case 18:
            changeNRandMdivisions(parts, 8); return;
        case 19:
            changeNRandMdivisions(parts, 9); return;
        case 20:
            changeNRandMdivisions(parts, 10); return;
    }
}

variable_types: mutation int


rtprint

decompiled_code:
__int64 __fastcall rtprint(_QWORD *a1, unsigned int a2)
{
_QWORD *v3; // r12
int v4; // ebp
int i; // ebx
__int64 result; // rax

if ( a1 )
{
v3 = a1;
do
{
v4 = a2++;
rtprint(*v3, a2);
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
putchar(9);
}
result = vecprint(v3[2]);
v3 = (_QWORD *)v3[1];
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, unsigned int a2)
{
_QWORD *v3; // r12
int v4; // ebp
int i; // ebx
__int64 result; // rax

if ( a1 )
{
v3 = a1;
do
{
v4 = a2++;
func0(*v3, a2);
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
putchar(9);
}
result = vecprint(v3[2]);
v3 = (_QWORD *)v3[1];
}
while ( v3 );
}
return result;
}

original_code:
void rtprint(TREENODE *subroot, int level){
    int i;
    if( subroot != ((void *)0) ){
 rtprint(subroot->left, level+1);
 for(i=0; i<level;i++){
     printf("\t");
 }
 vecprint(subroot->pvec);
 rtprint(subroot->right, level+1);
    }
}

canonical_original_code:
void rtprint(struct TreeNode *subroot, int level){
    int i;
    if( subroot != ((void *)0) ){
 rtprint(subroot->left, level+1);
 for(i=0; i<level;i++){
     printf("\t");
 }
 vecprint(subroot->pvec);
 rtprint(subroot->right, level+1);
    }
}

variable_types: struct TreeNode { struct TreeNode *left; struct TreeNode *right; struct Vector { int len; double *vec; int flag; } *pvec; } *

variable_types: level int

variable_types: i int

user_defined_types: struct TreeNode { struct TreeNode *left; struct TreeNode *right; struct Vector *pvec; }


tprint

decompiled_code:
__int64 __fastcall tprint(_QWORD *a1)
{
return rtprint(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
return func0(a1, 0);
}

original_code:
void tprint(TREENODE *subroot){
    rtprint(subroot, 0);
}

canonical_original_code:
void tprint(struct TreeNode *subroot){
    rtprint(subroot, 0);
}

user_defined_types: struct Vector { int len; double *vec; int flag; }


talloc

decompiled_code:
_QWORD *talloc()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
TREENODE *talloc(){
    TREENODE *tp;
    tp = (TREENODE *) malloc( sizeof(TREENODE) );
    ((void) (0));
    tp->left = ((void *)0);
    tp->right = ((void *)0);
    return(tp);
}

canonical_original_code:
struct TreeNode *talloc(){
    struct TreeNode *tp;
    tp = (struct TreeNode *) malloc( sizeof(TREENODE) );
    ((void) (0));
    tp->left = ((void *)0);
    tp->right = ((void *)0);
    return(tp);
}

return_type: struct TreeNode { struct TreeNode *left; struct TreeNode *right; struct Vector { int len; double *vec; int flag; } *pvec; } *


tfree

decompiled_code:
void __fastcall tfree(void *ptr)
{
if ( ptr )
{
tfree(*(void **)ptr);
tfree(*((void **)ptr + 1));
vecfree(*((_QWORD *)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
func3(*(void **)ptr);
func3(*((void **)ptr + 1));
vecfree(*((_QWORD *)ptr + 2));
free(ptr);
}
}

original_code:
void tfree(TREENODE *tp){
    if(tp != ((void *)0) ){
 tfree(tp->left);
 tfree(tp->right);
 vecfree(tp->pvec);
 free( (char *) tp);
    }
}

canonical_original_code:
void tfree(struct TreeNode *tp){
    if(tp != ((void *)0) ){
 tfree(tp->left);
 tfree(tp->right);
 vecfree(tp->pvec);
 free( (char *) tp);
    }
}


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

if ( a1 && a2 )
{
v2 = vecdist2();
if ( v2 < 0.0 )
sqrt(v2);
}
}

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

if ( a1 && a2 )
{
v2 = vecdist2();
if ( v2 < 0.0 )
sqrt(v2);
}
}

original_code:
NUMBER myvecdist2( VECTOR *vp1, VECTOR *vp2){
    if( (vp1 == ((void *)0)) || (vp2 == ((void *)0)) ) { return (10000000) ;}
    else{ return( sqrt(vecdist2(vp1, vp2)) ) ; }
}

canonical_original_code:
double myvecdist2(struct Vector *vp1, struct Vector *vp2){
    if( (vp1 == ((void *)0)) || (vp2 == ((void *)0)) ) { return (10000000) ;}
    else{ return( sqrt(vecdist2(vp1, vp2)) ) ; }
}

variable_types: struct Vector { int len; double *vec; int flag; } *

return_type: double


rnnsearch

original_code:
VECTOR *rnnsearch(TREENODE *subroot, VECTOR *vp, VECTOR *best, int level){
    NUMBER mindist;
    NUMBER rootdist;
    int numdims;
    numdims = vp->len;
    if(subroot == ((void *)0)) {
        return(best);
    }
    rootdist = myvecdist2( vp, subroot->pvec);
    mindist = myvecdist2( vp, best);
    if( rootdist < mindist){
        if((subroot->pvec)->flag==0){
            best = subroot->pvec;
            mindist = rootdist;
        }
    }
    if( (vp->vec)[level] > ((subroot->pvec)->vec)[level]){
 best = rnnsearch( subroot->right, vp, best, (level+1)% numdims);
 mindist = myvecdist2(vp, best);
 if( (vp->vec)[level] <= ( ((subroot->pvec)->vec)[level] + mindist ) ){
     best = rnnsearch( subroot->left, vp, best, (level+1)% numdims);
        }
    }else{
 best = rnnsearch( subroot->left, vp, best, (level+1)% numdims);
 mindist = myvecdist2(vp, best);
 if( ( (vp->vec)[level] + mindist) > ((subroot->pvec)->vec)[level] ){
     best = rnnsearch( subroot->right, vp, best, (level+1)%numdims);
 }
    }
    return(best);
}

canonical_original_code:
struct Vector *rnnsearch(struct TreeNode *subroot, struct Vector *vp, struct Vector *best, int level){
    double mindist;
    double rootdist;
    int numdims;
    numdims = vp->len;
    if(subroot == ((void *)0)) {
        return(best);
    }
    rootdist = myvecdist2( vp, subroot->pvec);
    mindist = myvecdist2( vp, best);
    if( rootdist < mindist){
        if((subroot->pvec)->flag==0){
            best = subroot->pvec;
            mindist = rootdist;
        }
    }
    if( (vp->vec)[level] > ((subroot->pvec)->vec)[level]){
 best = rnnsearch( subroot->right, vp, best, (level+1)% numdims);
 mindist = myvecdist2(vp, best);
 if( (vp->vec)[level] <= ( ((subroot->pvec)->vec)[level] + mindist ) ){
     best = rnnsearch( subroot->left, vp, best, (level+1)% numdims);
        }
    }else{
 best = rnnsearch( subroot->left, vp, best, (level+1)% numdims);
 mindist = myvecdist2(vp, best);
 if( ( (vp->vec)[level] + mindist) > ((subroot->pvec)->vec)[level] ){
     best = rnnsearch( subroot->right, vp, best, (level+1)%numdims);
 }
    }
    return(best);
}

variable_types: struct TreeNode { struct TreeNode *left; struct TreeNode *right; struct Vector *pvec; } *

variable_types:
vp
struct Vector *

variable_types:
best
struct Vector *

variable_types: mindist double

variable_types: rootdist double

variable_types: numdims int

return_type: struct Vector { int len; double *vec; int flag; } *


nnsearch

decompiled_code:
unsigned __int64 __fastcall nnsearch(_QWORD *a1, __int64 a2, int a3)
{
unsigned __int64 result; // rax
void *v4; // rsp
__int64 *v5; // r12
unsigned __int64 *v6; // r13
unsigned __int64 *v7; // rbx
__int64 v8; // rax
__int64 v9; // r15
__int64 v10; // r14
__int64 v11; // r12
_BYTE v12[12]; // [rsp+0h] [rbp-50h] BYREF
int v13; // [rsp+Ch] [rbp-44h]
int v14; // [rsp+10h] [rbp-40h]
unsigned int v15; // [rsp+14h] [rbp-3Ch]
_BYTE *v16; // [rsp+18h] [rbp-38h]

result = (8LL * a3 + 15) & 0xFFFFFFFFFFFFFFF0LL;
v13 = a3;
v4 = alloca(8LL * a3);
if ( a3 > 0 )
{
v5 = (__int64 *)v12;
v14 = 0;
v16 = v12;
v6 = (unsigned __int64 *)v12;
v7 = (unsigned __int64 *)&v12[8 * a3];
v15 = 0;
do
{
while ( 1 )
{
v8 = rnnsearch(a1, a2, 0LL, 0);
if ( !v8 )
break;
*v5++ = v8;
++v15;
*(_DWORD *)(v8 + 16) = 1;
if ( v5 == (__int64 *)v7 )
goto LABEL_6;
}
*v5++ = 0LL;
v14 = 1;
}
while ( v5 != (__int64 *)v7 );
LABEL_6:
v9 = 1LL;
v10 = (unsigned int)(v13 + 1);
do
{
v11 = *(_QWORD *)&v16[8 * v9 - 8];
if ( v11 )
{
printf("nearest neighbor %d: ", (unsigned int)v9);
vecprint(v11);
}
++v9;
}
while ( v10 != v9 );
if ( v14 == 1 )
printf("Warning: only %d nodes found.\n", v15);
do
{
result = *v6;
if ( *v6 )
*(_DWORD *)(result + 16) = 0;
++v6;
}
while ( v6 != v7 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(_QWORD *a1, __int64 a2, int a3)
{
unsigned __int64 result; // rax
void *v4; // rsp
__int64 *v5; // r12
unsigned __int64 *v6; // r13
unsigned __int64 *v7; // rbx
__int64 v8; // rax
__int64 v9; // r15
__int64 v10; // r14
__int64 v11; // r12
_BYTE v12[12]; // [rsp+0h] [rbp-50h] BYREF
int v13; // [rsp+Ch] [rbp-44h]
int v14; // [rsp+10h] [rbp-40h]
unsigned int v15; // [rsp+14h] [rbp-3Ch]
_BYTE *v16; // [rsp+18h] [rbp-38h]

result = (8LL * a3 + 15) & 0xFFFFFFFFFFFFFFF0LL;
v13 = a3;
v4 = alloca(8LL * a3);
if ( a3 > 0 )
{
v5 = (__int64 *)v12;
v14 = 0;
v16 = v12;
v6 = (unsigned __int64 *)v12;
v7 = (unsigned __int64 *)&v12[8 * a3];
v15 = 0;
do
{
while ( 1 )
{
v8 = func5(a1, a2, 0LL, 0);
if ( !v8 )
break;
*v5++ = v8;
++v15;
*(_DWORD *)(v8 + 16) = 1;
if ( v5 == (__int64 *)v7 )
goto LABEL_6;
}
*v5++ = 0LL;
v14 = 1;
}
while ( v5 != (__int64 *)v7 );
LABEL_6:
v9 = 1LL;
v10 = (unsigned int)(v13 + 1);
do
{
v11 = *(_QWORD *)&v16[8 * v9 - 8];
if ( v11 )
{
printf("nearest neighbor %d: ", (unsigned int)v9);
vecprint(v11);
}
++v9;
}
while ( v10 != v9 );
if ( v14 == 1 )
printf("Warning: only %d nodes found.\n", v15);
do
{
result = *v6;
if ( *v6 )
*(_DWORD *)(result + 16) = 0;
++v6;
}
while ( v6 != v7 );
}
return result;
}

original_code:
void nnsearch(TREENODE *subroot, VECTOR *vp, int count){
    VECTOR *best;
    VECTOR* bestArr[count];
    int k;
    int nodecounter = 0;
    int emptyNodeFlag = 0;
    for(k=0;k<count;k++) {
        best = rnnsearch(subroot, vp, (VECTOR *)((void *)0), 0);
        if(best != ((void *)0)){
            best->flag = 1;
            nodecounter += 1;
        }else{
            emptyNodeFlag = 1;
        }
        bestArr[k] = best;
    }
    for(k=0;k<count;k++) {
        best = bestArr[k];
        if(best != ((void *)0)){
        printf("nearest neighbor %d: ",k+1);
        vecprint(best);
        }
    }
    if(emptyNodeFlag==1){
        printf("Warning: only %d nodes found.\n",nodecounter);
    }
    for(k=0;k<count;k++) {
        if(bestArr[k] != ((void *)0)){ bestArr[k]->flag = 0; }
    }
}

canonical_original_code:
void nnsearch(struct TreeNode *subroot, struct Vector *vp, int count){
    struct Vector *best;
    struct Vector *bestArr[-1];
    int k;
    int nodecounter = 0;
    int emptyNodeFlag = 0;
    for(k=0;k<count;k++) {
        best = rnnsearch(subroot, vp, (struct Vector *)((void *)0), 0);
        if(best != ((void *)0)){
            best->flag = 1;
            nodecounter += 1;
        }else{
            emptyNodeFlag = 1;
        }
        bestArr[k] = best;
    }
    for(k=0;k<count;k++) {
        best = bestArr[k];
        if(best != ((void *)0)){
        printf("nearest neighbor %d: ",k+1);
        vecprint(best);
        }
    }
    if(emptyNodeFlag==1){
        printf("Warning: only %d nodes found.\n",nodecounter);
    }
    for(k=0;k<count;k++) {
        if(bestArr[k] != ((void *)0)){ bestArr[k]->flag = 0; }
    }
}

variable_types: count int

variable_types: struct Vector { int len; double *vec; int flag; } *[-1]

variable_types: k int

variable_types: nodecounter int

variable_types: emptyNodeFlag int


contains

original_code:
BOOLEAN contains( VECTOR *vpLow, VECTOR *vpHigh, VECTOR *vp){
    BOOLEAN res;
    int i;
    int numdims;
    numdims = vp->len;
    for(i=0, res=1; res && (i< numdims); i++){
       if( ( (vp->vec)[i] < (vpLow->vec)[i] ) ||
    ((vp->vec)[i] > (vpHigh->vec)[i]) ){
    res = 0;
       }
    }
    return(res);
}

canonical_original_code:
int contains(struct Vector *vpLow, struct Vector *vpHigh, struct Vector *vp){
    int res;
    int i;
    int numdims;
    numdims = vp->len;
    for(i=0, res=1; res && (i< numdims); i++){
       if( ( (vp->vec)[i] < (vpLow->vec)[i] ) ||
    ((vp->vec)[i] > (vpHigh->vec)[i]) ){
    res = 0;
       }
    }
    return(res);
}

variable_types:
vpHigh
struct Vector *

variable_types: res int


rrangesearch

original_code:
void rrangesearch(TREENODE *subroot, VECTOR *vpLow, VECTOR *vpHigh, int level){
    int numdims;
    if( subroot != ((void *)0) ){
        numdims = (subroot->pvec)->len;
 if( contains( vpLow, vpHigh, subroot->pvec ) ){
     vecprint(subroot->pvec);
 }
 if( (vpLow->vec)[level] <= ((subroot->pvec)->vec)[level] ){
     rrangesearch( subroot->left, vpLow, vpHigh, (level+1)% numdims);
 }
 if( (vpHigh->vec)[level] > ((subroot->pvec)->vec)[level] ){
     rrangesearch( subroot->right, vpLow, vpHigh, (level+1)% numdims);
 }
    }
    return;
}

canonical_original_code:
void rrangesearch(struct TreeNode *subroot, struct Vector *vpLow, struct Vector *vpHigh, int level){
    int numdims;
    if( subroot != ((void *)0) ){
        numdims = (subroot->pvec)->len;
 if( contains( vpLow, vpHigh, subroot->pvec ) ){
     vecprint(subroot->pvec);
 }
 if( (vpLow->vec)[level] <= ((subroot->pvec)->vec)[level] ){
     rrangesearch( subroot->left, vpLow, vpHigh, (level+1)% numdims);
 }
 if( (vpHigh->vec)[level] > ((subroot->pvec)->vec)[level] ){
     rrangesearch( subroot->right, vpLow, vpHigh, (level+1)% numdims);
 }
    }
    return;
}

variable_types: struct TreeNode { struct TreeNode *left; struct TreeNode *right; struct Vector { int len; double *vec; int flag; } *pvec; } *

variable_types:
vpLow
struct Vector *


rangesearch

decompiled_code:
void __fastcall rangesearch(_QWORD *a1, __int64 a2, __int64 a3)
{
rrangesearch(a1, a2, a3, 0);
}

canonical_decompiled_code:
void __fastcall func9(_QWORD *a1, __int64 a2, __int64 a3)
{
func8(a1, a2, a3, 0);
}

original_code:
void rangesearch(TREENODE *subroot, VECTOR *vpLow, VECTOR *vpHigh){
    rrangesearch(subroot, vpLow, vpHigh, 0);
}

canonical_original_code:
void rangesearch(struct TreeNode *subroot, struct Vector *vpLow, struct Vector *vpHigh){
    rrangesearch(subroot, vpLow, vpHigh, 0);
}


vecfree

decompiled_code:
void __fastcall vecfree(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void vecfree( VECTOR *pvec){
    free( (char *) pvec->vec);
    pvec->len =0;
    free( (char *) pvec);
}

canonical_original_code:
void vecfree(struct Vector *pvec){
    free( (char *) pvec->vec);
    pvec->len =0;
    free( (char *) pvec);
}


vecput

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

result = *(_QWORD *)(a1 + 8);
*(double *)(result + 8LL * a2) = a3;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(double *)(result + 8LL * a2) = a3;
return result;
}

original_code:
void vecput( VECTOR *pvec, int pos, NUMBER val){
    ((void) (0)) ;
    ((void) (0));
    (pvec->vec)[pos] = val;
}

canonical_original_code:
void vecput(struct Vector *pvec, int pos, double val){
    ((void) (0)) ;
    ((void) (0));
    (pvec->vec)[pos] = val;
}

variable_types: pos int

variable_types: val double


vecget

decompiled_code:
double __fastcall vecget(__int64 a1, int a2)
{
return *(double *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
}

canonical_decompiled_code:
double __fastcall func3(__int64 a1, int a2)
{
return *(double *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
}

original_code:
NUMBER vecget( VECTOR *pvec, int pos){
    ((void) (0)) ;
    ((void) (0));
    return( (pvec->vec)[pos] );
}

canonical_original_code:
double vecget(struct Vector *pvec, int pos){
    ((void) (0)) ;
    ((void) (0));
    return( (pvec->vec)[pos] );
}

variable_types: struct Vector { int len; double *vec; int flag; } *


vecprint

decompiled_code:
int __fastcall vecprint(int *a1)
{
int v1; // er12
int v2; // ebx
int v3; // esi
double v4; // xmm0_8

v1 = *a1;
if ( *a1 > 0 )
{
v2 = 0;
do
{
v3 = v2++;
v4 = vecget((__int64)a1, v3);
printf("%g\t", v4);
}
while ( v1 != v2 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func4(int *a1)
{
int v1; // er12
int v2; // ebx
int v3; // esi
double v4; // xmm0_8

v1 = *a1;
if ( *a1 > 0 )
{
v2 = 0;
do
{
v3 = v2++;
v4 = func3((__int64)a1, v3);
printf("%g\t", v4);
}
while ( v1 != v2 );
}
return putchar(10);
}

original_code:
void vecprint( VECTOR *p){
    int i, length;
    length = p->len;
    for(i=0; i< length; i++){
 printf("%g\t", vecget(p, i));
    }
    printf("\n");
}

canonical_original_code:
void vecprint(struct Vector *p){
    int i; int length;
    length = p->len;
    for(i=0; i< length; i++){
 printf("%g\t", vecget(p, i));
    }
    printf("\n");
}

variable_types: i int

variable_types: length int


checkword

decompiled_code:
void checkword()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void checkword(char *s){
   ((void) (0));
}

variable_types:
s
char *


prhelp

decompiled_code:
int prhelp()
{
puts("\t i \t\t for insertion");
puts("\t n \t\t for nn search ");
puts("\t r \t\t for range search ");
puts("\t p \t\t to print the tree");
puts("\t x \t\t to exit");
return puts("\t h \t\t to print this help message");
}

canonical_decompiled_code:
int func1()
{
puts("\t i \t\t for insertion");
puts("\t n \t\t for nn search ");
puts("\t r \t\t for range search ");
puts("\t p \t\t to print the tree");
puts("\t x \t\t to exit");
return puts("\t h \t\t to print this help message");
}

original_code:
void prhelp(){
    printf("\t i \t\t for insertion\n");
    printf("\t n \t\t for nn search \n");
    printf("\t r \t\t for range search \n");
    printf("\t p \t\t to print the tree\n");
    printf("\t x \t\t to exit\n");
    printf("\t h \t\t to print this help message\n");
}


main

repo: windytan/squelch

original_code:
int main(int argc, char **argv) {
  short int ssize = 16;
  unsigned int buflen = 2048;
  int limit = 1024;
  unsigned int duration = 4096;
  unsigned int ttime = 512;
  unsigned short bufptr = 0;
  short int pcm;
  short int outbuf[buflen];
  short int silcount = 0, ampcount = 0;
  float amp = 1.0f;
  _Bool silent = 0, falling = 0, rising = 0;
  int c;
  while ((c = getopt (argc, argv, "u:l:L:d:t:")) != -1)
    switch (c) {
      case 'u':
        buflen = atoi(optarg);
        break;
      case 'l':
        limit = atoi(optarg);
        break;
      case 'L':
        limit = lroundf(pow(10, atof(optarg)/20.0) * pow(2, 15));
        break;
      case 'd':
        duration = atoi(optarg);
        break;
      case 't':
        ttime = atoi(optarg);
        break;
      case '?':
        fprintf (stderr, "Unknown option `-%c'.\n", optopt);
        return 1;
      default:
        break;
    }
  while (read(0, &pcm, ssize/8)) {
    if (silent) {
      if (falling) {
        amp = (float)(ttime - ampcount) / ttime;
        outbuf[bufptr] = pcm * amp;
        ampcount ++;
        if (ampcount > ttime)
          falling = 0;
      } else {
        outbuf[bufptr] = 0x0000;
      }
      if (abs(pcm) > limit) {
        silent = 0;
        rising = 1;
        ampcount = 0;
        silcount = 0;
      }
    } else {
      if (rising) {
        amp = ((float)ampcount) / ttime;
        outbuf[bufptr] = pcm * amp;
        ampcount ++;
        if (ampcount > ttime) rising = 0;
      } else {
        outbuf[bufptr] = pcm;
      }
      if (abs(pcm) < limit) {
        silcount ++;
        if (silcount > duration) {
          silent = 1;
          falling = 1;
          ampcount = 0;
        }
      }
    }
    if (++bufptr == buflen) {
      if (!write(1, &outbuf, 2 * buflen))
        return (1);
      fflush(stdout);
      bufptr = 0;
    }
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  short ssize = 16;
  unsigned int buflen = 2048;
  int limit = 1024;
  unsigned int duration = 4096;
  unsigned int ttime = 512;
  unsigned short bufptr = 0;
  short pcm;
  short outbuf[-1];
  short silcount = 0; short ampcount = 0;
  float amp = 1.0f;
  _Bool silent = 0; _Bool falling = 0; _Bool rising = 0;
  int c;
  while ((c = getopt (argc, argv, "u:l:L:d:t:")) != -1)
    switch (c) {
      case 'u':
        buflen = atoi(optarg);
        break;
      case 'l':
        limit = atoi(optarg);
        break;
      case 'L':
        limit = lroundf(pow(10, atof(optarg)/20.0) * pow(2, 15));
        break;
      case 'd':
        duration = atoi(optarg);
        break;
      case 't':
        ttime = atoi(optarg);
        break;
      case '?':
        fprintf (stderr, "Unknown option `-%c'.\n", optopt);
        return 1;
      default:
        break;
    }
  while (read(0, &pcm, ssize/8)) {
    if (silent) {
      if (falling) {
        amp = (float)(ttime - ampcount) / ttime;
        outbuf[bufptr] = pcm * amp;
        ampcount ++;
        if (ampcount > ttime)
          falling = 0;
      } else {
        outbuf[bufptr] = 0x0000;
      }
      if (abs(pcm) > limit) {
        silent = 0;
        rising = 1;
        ampcount = 0;
        silcount = 0;
      }
    } else {
      if (rising) {
        amp = ((float)ampcount) / ttime;
        outbuf[bufptr] = pcm * amp;
        ampcount ++;
        if (ampcount > ttime) rising = 0;
      } else {
        outbuf[bufptr] = pcm;
      }
      if (abs(pcm) < limit) {
        silcount ++;
        if (silcount > duration) {
          silent = 1;
          falling = 1;
          ampcount = 0;
        }
      }
    }
    if (++bufptr == buflen) {
      if (!write(1, &outbuf, 2 * buflen))
        return (1);
      fflush(stdout);
      bufptr = 0;
    }
  }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ssize short

variable_types:
buflen
unsigned int

variable_types: limit int

variable_types:
duration
unsigned int

variable_types:
ttime
unsigned int

variable_types:
bufptr
unsigned short

variable_types: pcm short

variable_types:
outbuf
short [-1]

variable_types: silcount short

variable_types: ampcount short

variable_types: amp float

variable_types: c int


canonical_original_code:
void quat_calcw(struct quat_t *r) {
 float t = 1.0 - (r->x*r->x) - (r->y*r->y) - (r->z*r->z);
 if (t<0) r->w = 0;
 else r->w = -sqrt(t);
}

variable_types:
r
struct quat_t { float x; } *

variable_types: t float


decompiled_code:
float *__fastcall quat_makev(float *a1, __int64 a2, float a3)
{
float v3; // xmm0_4
float *result; // rax
float v5; // xmm5_4
float v6; // xmm6_4
float v7; // xmm3_4
float v8; // xmm4_4
double v9; // [rsp+4h] [rbp-40h]
double cosx; // [rsp+Ch] [rbp-38h] BYREF
double sinx; // [rsp+14h] [rbp-30h] BYREF
int v12[9]; // [rsp+20h] [rbp-24h] BYREF

sincos(a3 * 0.5, &sinx, &cosx);
v3 = sinx;
v9 = cosx;
v3_normalize(v12, a2);
result = a1;
v5 = *(float *)v12 * v3;
v6 = *(float *)&v12[1] * v3;
v7 = v9;
a1[3] = v7;
v8 = v3 * *(float *)&v12[2];
*a1 = v5;
a1[1] = v6;
a1[2] = v8;
return result;
}

canonical_decompiled_code:
float *__fastcall func3(float *a1, __int64 a2, float a3)
{
float v3; // xmm0_4
float *result; // rax
float v5; // xmm5_4
float v6; // xmm6_4
float v7; // xmm3_4
float v8; // xmm4_4
double v9; // [rsp+4h] [rbp-40h]
double cosx; // [rsp+Ch] [rbp-38h] BYREF
double sinx; // [rsp+14h] [rbp-30h] BYREF
int v12[9]; // [rsp+20h] [rbp-24h] BYREF

sincos(a3 * 0.5, &sinx, &cosx);
v3 = sinx;
v9 = cosx;
v3_normalize(v12, a2);
result = a1;
v5 = *(float *)v12 * v3;
v6 = *(float *)&v12[1] * v3;
v7 = v9;
a1[3] = v7;
v8 = v3 * *(float *)&v12[2];
*a1 = v5;
a1[1] = v6;
a1[2] = v8;
return result;
}

original_code:
quat_t *quat_makev(quat_t *r, fp_t angle, const v3_t *u) {
 v3_t v;
 fp_t sin_a = sin(0.5 * angle);
 fp_t cos_a = cos(0.5 * angle);
 v3_normalize(&v, u);
 r->w = cos_a;
 r->x = v.x * sin_a;
 r->y = v.y * sin_a;
 r->z = v.z * sin_a;
 return r;
}

canonical_original_code:
struct quat_t *quat_makev(struct quat_t *r, float angle, struct v3_t *u) {
 struct v3_t v;
 float sin_a = sin(0.5 * angle);
 float cos_a = cos(0.5 * angle);
 v3_normalize(&v, u);
 r->w = cos_a;
 r->x = v.x * sin_a;
 r->y = v.y * sin_a;
 r->z = v.z * sin_a;
 return r;
}

variable_types:
r
struct quat_t *

variable_types: angle float

variable_types:
u
struct v3_t { float x; } *

variable_types:
v
struct v3_t { float x; }

return_type: struct quat_t { float x; } *

user_defined_types:
struct v3_t { float x; }
struct quat_t { float x; }


original_code:
fp_t quat_normal(quat_t *q) {
 return sqrt(q->x*q->x + q->y*q->y + q->z*q->z + q->w*q->w);
}

canonical_original_code:
float quat_normal(struct quat_t *q) {
 return sqrt(q->x*q->x + q->y*q->y + q->z*q->z + q->w*q->w);
}

variable_types:
q
struct quat_t { float x; } *

return_type: float


decompiled_code:
__int64 __fastcall quat_rotatep(__int64 a1, float *a2)
{
float *v2; // rdx
float *v3; // rsi
float *v4; // r9
__int64 v5; // r8
int v7[4]; // [rsp+0h] [rbp-28h] BYREF
int v8[6]; // [rsp+10h] [rbp-18h] BYREF

quat_conjugate(v8, a2);
v3 = quat_mulv((float *)v7, a2, v2);
quat_mulq((float *)v7, v3, v4);
return v3_make(v5, *(float *)v7, *(float *)&v7[1], *(float *)&v7[2]);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, float *a2)
{
float *v2; // rdx
float *v3; // rsi
float *v4; // r9
__int64 v5; // r8
int v7[4]; // [rsp+0h] [rbp-28h] BYREF
int v8[6]; // [rsp+10h] [rbp-18h] BYREF

quat_conjugate(v8, a2);
v3 = func7((float *)v7, a2, v2);
func6((float *)v7, v3, v4);
return v3_make(v5, *(float *)v7, *(float *)&v7[1], *(float *)&v7[2]);
}

original_code:
v3_t *quat_rotatep(v3_t *out, const quat_t *q, const v3_t *in) {
 quat_t tmp, inv;
 quat_mulq(&tmp, quat_mulv(&tmp, q, in), quat_conjugate(&inv, q));
 return v3_make(out, tmp.x, tmp.y, tmp.z);
}

canonical_original_code:
struct v3_t *quat_rotatep(struct v3_t *out, struct quat_t *q, struct v3_t *in) {
 struct quat_t tmp; struct quat_t inv;
 quat_mulq(&tmp, quat_mulv(&tmp, q, in), quat_conjugate(&inv, q));
 return v3_make(out, tmp.x, tmp.y, tmp.z);
}

variable_types:
out
struct v3_t *

variable_types:
in
struct v3_t *

variable_types:
tmp
struct quat_t { float x; }

variable_types:
inv
struct quat_t { float x; }

return_type: struct v3_t { float x; } *

user_defined_types:
struct quat_t { float x; }
struct v3_t { float x; }


original_code:
void md5model_end(struct md5model *model) {
 int i;
 for(i=0; i<model->num.joints; i++) {
 }
 for(i=0; i<model->num.meshes; i++) {
  struct md5mesh *mesh = &model->meshes[i];
  free(mesh->verts);
  free(mesh->tris);
  free(mesh->weights);
 }
 free(model->meshes);
 free(model->base);
 free(model->jinfo);
}

variable_types: struct md5model { struct { int joints; } num; struct md5joint { struct v3_t { float x; } pos; struct quat_t { float x; } ori; } *base; struct md5jinfo { char *name; int parent; } *jinfo; struct md5mesh { struct { int verts; } num; struct md5vertex { struct v3_t pos; struct v2_t { float x; } st; int start; int count; } *verts; struct md5tri { int idx[3]; } *tris; struct md5weight { struct v3_t pos; int joint; float bias; } *weights; char *shader; } *meshes; } *

variable_types: i int

variable_types: struct md5mesh { struct { int verts; } num; struct md5vertex { struct v3_t { float x; } pos; struct v2_t { float x; } st; int start; int count; } *verts; struct md5tri { int idx[3]; } *tris; struct md5weight { struct v3_t pos; int joint; float bias; } *weights; char *shader; } *

user_defined_types: struct md5model { struct { int joints; } num; struct md5joint *base; struct md5jinfo *jinfo; struct md5mesh *meshes; }

user_defined_types: struct md5mesh { struct { int verts; } num; struct md5vertex *verts; struct md5tri *tris; struct md5weight *weights; char *shader; }

user_defined_types: struct md5joint { struct v3_t pos; struct quat_t ori; }

user_defined_types: struct md5vertex { struct v3_t pos; struct v2_t st; int start; int count; }


original_code:
void md5model_mkmesh(struct md5mesh *mesh, struct md5joint *skel)
{
 int j, k;
 for (j=0; j<mesh->num.verts; j++) {
  v3_make(&mesh->verts[j].pos, 0, 0, 0);
  const struct md5vertex *vertex = &mesh->verts[j];
  for (k=vertex->start; k<vertex->start + vertex->count; k++) {
   v3_t wv;
   const struct md5weight *weight = &mesh->weights[k];
   const struct md5joint *joint = &skel[weight->joint];
   quat_rotatep(&wv, &joint->ori, &weight->pos);
   mesh->verts[j].pos.x += (joint->pos.x + wv.x) * weight->bias;
   mesh->verts[j].pos.y += (joint->pos.y + wv.y) * weight->bias;
   mesh->verts[j].pos.z += (joint->pos.z + wv.z) * weight->bias;
  }
 }
}

canonical_original_code:
void md5model_mkmesh(struct md5mesh *mesh, struct md5joint *skel)
{
 int j; int k;
 for (j=0; j<mesh->num.verts; j++) {
  v3_make(&mesh->verts[j].pos, 0, 0, 0);
  struct md5vertex *vertex = &mesh->verts[j];
  for (k=vertex->start; k<vertex->start + vertex->count; k++) {
   struct v3_t wv;
   struct md5weight *weight = &mesh->weights[k];
   struct md5joint *joint = &skel[weight->joint];
   quat_rotatep(&wv, &joint->ori, &weight->pos);
   mesh->verts[j].pos.x += (joint->pos.x + wv.x) * weight->bias;
   mesh->verts[j].pos.y += (joint->pos.y + wv.y) * weight->bias;
   mesh->verts[j].pos.z += (joint->pos.z + wv.z) * weight->bias;
  }
 }
}

variable_types: struct md5joint { struct v3_t pos; struct quat_t { float x; } ori; } *

variable_types: j int

variable_types: k int

variable_types: struct md5vertex { struct v3_t { float x; } pos; struct v2_t { float x; } st; int start; int count; } *

variable_types:
wv
struct v3_t { float x; }

variable_types: struct md5weight { struct v3_t { float x; } pos; int joint; float bias; } *

variable_types: struct md5joint { struct v3_t { float x; } pos; struct quat_t { float x; } ori; } *

user_defined_types: struct md5weight { struct v3_t pos; int joint; float bias; }


decompiled_code:
float *__fastcall v3_fill(float *a1, float a2, float a3, float a4)
{
float *result; // rax

result = a1;
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
return result;
}

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

result = a1;
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
return result;
}

original_code:
static v3_t *v3_fill(v3_t *u, fp_t x, fp_t y, fp_t z) {
 u->x = x;
 u->y = y;
 u->z = z;
 return u;
}

canonical_original_code:
static struct v3_t *v3_fill(struct v3_t *u, float x, float y, float z) {
 u->x = x;
 u->y = y;
 u->z = z;
 return u;
}

variable_types:
u
struct v3_t *

variable_types: x float

variable_types: y float

variable_types: z float


decompiled_code:
// attributes: thunk
float *__fastcall v3_make(float *a1, float a2, float a3, float a4)
{
return v3_fill(a1, a2, a3, a4);
}

canonical_decompiled_code:
float *__fastcall func1(float *a1, float a2, float a3, float a4)
{
return func0(a1, a2, a3, a4);
}

original_code:
v3_t *v3_make(v3_t *u, fp_t x, fp_t y, fp_t z) {
 return v3_fill(u, x, y, z);
}

canonical_original_code:
struct v3_t *v3_make(struct v3_t *u, float x, float y, float z) {
 return v3_fill(u, x, y, z);
}


decompiled_code:
int *__fastcall v3_minus(int *a1, _DWORD *a2)
{
int *result; // rax
int v3; // xmm2_4
int v4; // xmm3_4

result = a1;
v3 = a2[1] ^ LC0;
v4 = a2[2] ^ LC0;
*a1 = *a2 ^ LC0;
a1[1] = v3;
a1[2] = v4;
return result;
}

canonical_decompiled_code:
int *__fastcall func2(int *a1, _DWORD *a2)
{
int *result; // rax
int v3; // xmm2_4
int v4; // xmm3_4

result = a1;
v3 = a2[1] ^ LC0;
v4 = a2[2] ^ LC0;
*a1 = *a2 ^ LC0;
a1[1] = v3;
a1[2] = v4;
return result;
}

original_code:
v3_t *v3_minus(v3_t *r, const v3_t *u) {
 r->x = - u->x;
 r->y = - u->y;
 r->z = - u->z;
 return r;
}

canonical_original_code:
struct v3_t *v3_minus(struct v3_t *r, struct v3_t *u) {
 r->x = - u->x;
 r->y = - u->y;
 r->z = - u->z;
 return r;
}

variable_types:
r
struct v3_t *


decompiled_code:
float *__fastcall v3_scale(float *a1, float *a2, float a3)
{
float *result; // rax
float v4; // xmm3_4
float v5; // xmm2_4

result = a1;
v4 = a2[2];
v5 = a2[1] / a3;
*a1 = *a2 / a3;
a1[1] = v5;
a1[2] = v4 / a3;
return result;
}

canonical_decompiled_code:
float *__fastcall func3(float *a1, float *a2, float a3)
{
float *result; // rax
float v4; // xmm3_4
float v5; // xmm2_4

result = a1;
v4 = a2[2];
v5 = a2[1] / a3;
*a1 = *a2 / a3;
a1[1] = v5;
a1[2] = v4 / a3;
return result;
}

original_code:
v3_t *v3_scale(v3_t *r, const v3_t *u, fp_t k) {
 r->x = u->x / k;
 r->y = u->y / k;
 r->z = u->z / k;
 return r;
}

canonical_original_code:
struct v3_t *v3_scale(struct v3_t *r, struct v3_t *u, float k) {
 r->x = u->x / k;
 r->y = u->y / k;
 r->z = u->z / k;
 return r;
}

variable_types: k float


decompiled_code:
float *__fastcall v3_add(float *a1, float *a2, float *a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm2_4

result = a1;
v4 = a2[1] + a3[1];
v5 = a2[2] + a3[2];
*a1 = *a2 + *a3;
a1[1] = v4;
a1[2] = v5;
return result;
}

canonical_decompiled_code:
float *__fastcall func4(float *a1, float *a2, float *a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm2_4

result = a1;
v4 = a2[1] + a3[1];
v5 = a2[2] + a3[2];
*a1 = *a2 + *a3;
a1[1] = v4;
a1[2] = v5;
return result;
}

original_code:
v3_t *v3_add(v3_t *r, const v3_t *u, const v3_t *v) {
 r->x = u->x + v->x;
 r->y = u->y + v->y;
 r->z = u->z + v->z;
 return r;
}

canonical_original_code:
struct v3_t *v3_add(struct v3_t *r, struct v3_t *u, struct v3_t *v) {
 r->x = u->x + v->x;
 r->y = u->y + v->y;
 r->z = u->z + v->z;
 return r;
}

variable_types:
v
struct v3_t *


decompiled_code:
float *__fastcall v3_sub(float *a1, float *a2, float *a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm2_4

result = a1;
v4 = a2[1] - a3[1];
v5 = a2[2] - a3[2];
*a1 = *a2 - *a3;
a1[1] = v4;
a1[2] = v5;
return result;
}

canonical_decompiled_code:
float *__fastcall func5(float *a1, float *a2, float *a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm2_4

result = a1;
v4 = a2[1] - a3[1];
v5 = a2[2] - a3[2];
*a1 = *a2 - *a3;
a1[1] = v4;
a1[2] = v5;
return result;
}

original_code:
v3_t *v3_sub(v3_t *r, const v3_t *u, const v3_t *v) {
 r->x = u->x - v->x;
 r->y = u->y - v->y;
 r->z = u->z - v->z;
 return r;
}

canonical_original_code:
struct v3_t *v3_sub(struct v3_t *r, struct v3_t *u, struct v3_t *v) {
 r->x = u->x - v->x;
 r->y = u->y - v->y;
 r->z = u->z - v->z;
 return r;
}


decompiled_code:
float *__fastcall v3_cross(float *a1, float *a2, float *a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm0_4
float v6; // xmm6_4
float v7; // xmm2_4
float v8; // xmm4_4
float v9; // xmm1_4

result = a1;
v4 = a3[2];
v5 = a3[1];
v6 = *a2;
v7 = a2[1] * *a3;
v8 = (float)(a2[1] * v4) - (float)(a2[2] * v5);
v9 = (float)(v4 * *a2) - (float)(a2[2] * *a3);
*a1 = v8;
a1[1] = v9;
a1[2] = (float)(v5 * v6) - v7;
return result;
}

canonical_decompiled_code:
float *__fastcall func6(float *a1, float *a2, float *a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm0_4
float v6; // xmm6_4
float v7; // xmm2_4
float v8; // xmm4_4
float v9; // xmm1_4

result = a1;
v4 = a3[2];
v5 = a3[1];
v6 = *a2;
v7 = a2[1] * *a3;
v8 = (float)(a2[1] * v4) - (float)(a2[2] * v5);
v9 = (float)(v4 * *a2) - (float)(a2[2] * *a3);
*a1 = v8;
a1[1] = v9;
a1[2] = (float)(v5 * v6) - v7;
return result;
}

original_code:
v3_t *v3_cross(v3_t *r, const v3_t *u, const v3_t *v) {
 v3_t tmp;
 tmp.x = u->y*v->z - u->z*v->y;
 tmp.y = u->x*v->z - u->z*v->x;
 tmp.z = u->x*v->y - u->y*v->x;
 *r = tmp;
 return r;
}

canonical_original_code:
struct v3_t *v3_cross(struct v3_t *r, struct v3_t *u, struct v3_t *v) {
 struct v3_t tmp;
 tmp.x = u->y*v->z - u->z*v->y;
 tmp.y = u->x*v->z - u->z*v->x;
 tmp.z = u->x*v->y - u->y*v->x;
 *r = tmp;
 return r;
}

variable_types:
tmp
struct v3_t { float x; }


decompiled_code:
float __fastcall v3_dot(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

canonical_decompiled_code:
float __fastcall func7(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

original_code:
fp_t v3_dot(const v3_t *u, const v3_t *v) {
 return u->x * v->x + u->y * v->y + u->z * v->z;
}

canonical_original_code:
float v3_dot(struct v3_t *u, struct v3_t *v) {
 return u->x * v->x + u->y * v->y + u->z * v->z;
}

variable_types:
u
struct v3_t { float x; } *


decompiled_code:
float *__fastcall v3_project(__int64 a1, float *a2, float *a3)
{
float v5; // xmm0_4
float *v6; // rdx
float v7; // xmm3_4
float *v8; // r8

v5 = v3_dot(a2, a3);
v7 = v5 / v3_dot(v6, a3);
return v3_scale(v8, a3, v7);
}

canonical_decompiled_code:
float *__fastcall func8(__int64 a1, float *a2, float *a3)
{
float v5; // xmm0_4
float *v6; // rdx
float v7; // xmm3_4
float *v8; // r8

v5 = func7(a2, a3);
v7 = v5 / func7(v6, a3);
return func3(v8, a3, v7);
}

original_code:
v3_t *v3_project(v3_t *r, const v3_t *u, const v3_t *v) {
 return v3_scale(r, v, v3_dot(u, v) / v3_dot(v, v));
}

canonical_original_code:
struct v3_t *v3_project(struct v3_t *r, struct v3_t *u, struct v3_t *v) {
 return v3_scale(r, v, v3_dot(u, v) / v3_dot(v, v));
}


decompiled_code:
void __fastcall v3_norm(float *a1)
{
float v1; // xmm0_4

v1 = v3_dot(a1, a1);
if ( v1 < 0.0 )
sqrtf(v1);
}

canonical_decompiled_code:
void __fastcall func9(float *a1)
{
float v1; // xmm0_4

v1 = func7(a1, a1);
if ( v1 < 0.0 )
sqrtf(v1);
}

original_code:
fp_t v3_norm(const v3_t *u) {
 return sqrt(v3_dot(u, u));
}

canonical_original_code:
float v3_norm(struct v3_t *u) {
 return sqrt(v3_dot(u, u));
}