decompiled_code:
__int64 __fastcall funcArgList_checkAndAddPointerPs(__int64 a1, _QWORD *a2)
{
_QWORD *i; // r15
__int64 result; // rax
_QWORD *j; // rbp
__int64 v6; // r12
__int64 v7; // r14
int v8; // er13

for ( i = *(_QWORD **)(a1 + 72); i; i = (_QWORD *)*i )
{
result = i[1];
v7 = *(_QWORD *)result;
v8 = *(_DWORD *)(result + 8);
for ( j = *(_QWORD **)(result + 16); j; j = (_QWORD *)*j )
{
if ( !a2 )
result = yyerror("Not enough arguments");
v6 = a2[1];
if ( *(_QWORD *)v6 != v7 )
result = yyerror("Function arg type mismatch");
if ( v8 )
{
result = (unsigned int)(*(_DWORD *)(v6 + 8) - 4);
if ( (unsigned int)result > 1 )
result = yyerror("Non-lvalue used where a pass-by-reference variable was needed");
*(_DWORD *)(v6 + 52) = 1;
}
a2 = (_QWORD *)*a2;
}
}
if ( a2 )
result = yyerror("too many arguments");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _QWORD *a2)
{
_QWORD *i; // r15
__int64 result; // rax
_QWORD *j; // rbp
__int64 v6; // r12
__int64 v7; // r14
int v8; // er13

for ( i = *(_QWORD **)(a1 + 72); i; i = (_QWORD *)*i )
{
result = i[1];
v7 = *(_QWORD *)result;
v8 = *(_DWORD *)(result + 8);
for ( j = *(_QWORD **)(result + 16); j; j = (_QWORD *)*j )
{
if ( !a2 )
result = yyerror("Not enough arguments");
v6 = a2[1];
if ( *(_QWORD *)v6 != v7 )
result = yyerror("Function arg type mismatch");
if ( v8 )
{
result = (unsigned int)(*(_DWORD *)(v6 + 8) - 4);
if ( (unsigned int)result > 1 )
result = yyerror("Non-lvalue used where a pass-by-reference variable was needed");
*(_DWORD *)(v6 + 52) = 1;
}
a2 = (_QWORD *)*a2;
}
}
if ( a2 )
result = yyerror("too many arguments");
return result;
}

original_code:
void funcArgList_checkAndAddPointerPs(ID* function, slist* paramExprs) {
    slist* idlists = function->typedIdentLists;
    while (idlists != ((void *)0)) {
        typedidentlist* idlist = idlists->data;
        TYPE* t = idlist->type;
        int pointerP = idlist->pointerP;
        slist* names = idlist->names;
        while (names != ((void *)0)) {
            if (paramExprs == ((void *)0)) {
                yyerror("Not enough arguments");
            }
            expr* e = paramExprs->data;
            if (e->type != t) {
                yyerror("Function arg type mismatch");
            }
            if (pointerP) {
                if (e->kind != globalVar && e->kind != localVar) {
                    yyerror("Non-lvalue used where a pass-by-reference variable was needed");
                }
                e->to_pointer_p = 1;
            }
            paramExprs = paramExprs->next;
            names = names->next;
        }
        idlists = idlists->next;
    }
    if (paramExprs != ((void *)0)) {
        yyerror("too many arguments");
    }
}

canonical_original_code:
void funcArgList_checkAndAddPointerPs(struct id_info *function, struct slist_struct *paramExprs) {
    struct slist_struct *idlists = function->typedIdentLists;
    while (idlists != ((void *)0)) {
        struct typedidentlist_struct *idlist = idlists->data;
        struct type_info *t = idlist->type;
        int pointerP = idlist->pointerP;
        struct slist_struct *names = idlist->names;
        while (names != ((void *)0)) {
            if (paramExprs == ((void *)0)) {
                yyerror("Not enough arguments");
            }
            struct expression_struct *e = paramExprs->data;
            if (e->type != t) {
                yyerror("Function arg type mismatch");
            }
            if (pointerP) {
                if (e->kind != globalVar && e->kind != localVar) {
                    yyerror("Non-lvalue used where a pass-by-reference variable was needed");
                }
                e->to_pointer_p = 1;
            }
            paramExprs = paramExprs->next;
            names = names->next;
        }
        idlists = idlists->next;
    }
    if (paramExprs != ((void *)0)) {
        yyerror("too many arguments");
    }
}

variable_types:
paramExprs
struct slist_struct *

variable_types: struct type_info { int ty_size; char *ty_name; enum type_kind { Integer=0, Char=1, Boolean=2, String=3, Array=4, Record=5, UndefinedType=6 } ty_kind; struct type_info *ty_next; union { struct { struct type_info *RangeType; int min; int max; } ty_subrange; struct { struct type_info *ElementType; struct type_info *IndexType; int min; int max; } ty_array; struct { struct id_info { char *id_name; int id_addr; int id_label; int id_level; struct type_info *id_type; enum identifier_kind { Constant_id=0, Type=1, Variable=2, FParameter=3, Field=4, Procedure=5, Function=6 } id_kind; struct id_info *id_left; struct id_info *id_right; struct id_info *id_next; struct expression_struct { struct type_info *type; enum expr_kind_enum { constant_expr=0, operation_bin=1, operation_un=2, registerVal=3, globalVar=4, localVar=5, functionCall=6, typecast=7 } kind; int int_val; char char_val; int bool_val; char *str_val; int str_const_index; struct expression_struct *offsetExpr; int pointer_p; int to_pointer_p; union { struct { struct expression_struct *operand1; struct expression_struct *operand2; enum operator_enum { op_and=0, op_or=1, op_not=2, op_negate=3, op_add=4, op_sub=5, op_mult=6, op_div=7, op_mod=8, op_equal=9, op_nequal=10, op_gt=11, op_lt=12, op_gte=13, op_lte=14 } op; } opdata; int reg_number; struct id_info *id; struct stmt_struct { enum stmt_type_enum { assign_stmt=0, if_stmt=1, while_stmt=2, repeat_stmt=3, for_stmt=4, stop_stmt=5, return_stmt=6, read_stmt=7, write_stmt=8, proc_stmt=9, null_stmt=10 } type; union { struct htslist_struct { struct slist_struct { struct slist_struct *next; void *data; } *head; struct slist_struct *tail; } *if_conditionals; struct slist_struct *exprList; struct expression_struct *expression; struct { struct stmt_struct *init; struct conditional_struct { struct expression_struct *condition; enum BranchType_enum { bt_equal0=0, bt_nequal0=1 } branchType; struct htslist_struct *statements; } *cBlock; } loopdata; struct { struct expression_struct *lvalue; struct expression_struct *rvalue; } assigndata; struct { char *name; struct slist_struct *paramExprs; } procdata; } data; } *funcCall; struct expression_struct *innerExpr; } edata; } *const_expr; struct slist_struct *typedIdentLists; int param_size; int pointer_p; } *FirstField; } ty_record; } ty_form; } *

variable_types: struct expression_struct { struct type_info { int ty_size; char *ty_name; enum type_kind { Integer=0, Char=1, Boolean=2, String=3, Array=4, Record=5, UndefinedType=6 } ty_kind; struct type_info *ty_next; union { struct { struct type_info *RangeType; int min; int max; } ty_subrange; struct { struct type_info *ElementType; struct type_info *IndexType; int min; int max; } ty_array; struct { struct id_info { char *id_name; int id_addr; int id_label; int id_level; struct type_info *id_type; enum identifier_kind { Constant_id=0, Type=1, Variable=2, FParameter=3, Field=4, Procedure=5, Function=6 } id_kind; struct id_info *id_left; struct id_info *id_right; struct id_info *id_next; struct expression_struct *const_expr; struct slist_struct { struct slist_struct *next; void *data; } *typedIdentLists; int param_size; int pointer_p; } *FirstField; } ty_record; } ty_form; } *type; enum expr_kind_enum { constant_expr=0, operation_bin=1, operation_un=2, registerVal=3, globalVar=4, localVar=5, functionCall=6, typecast=7 } kind; int int_val; char char_val; int bool_val; char *str_val; int str_const_index; struct expression_struct *offsetExpr; int pointer_p; int to_pointer_p; union { struct { struct expression_struct *operand1; struct expression_struct *operand2; enum operator_enum { op_and=0, op_or=1, op_not=2, op_negate=3, op_add=4, op_sub=5, op_mult=6, op_div=7, op_mod=8, op_equal=9, op_nequal=10, op_gt=11, op_lt=12, op_gte=13, op_lte=14 } op; } opdata; int reg_number; struct id_info *id; struct stmt_struct { enum stmt_type_enum { assign_stmt=0, if_stmt=1, while_stmt=2, repeat_stmt=3, for_stmt=4, stop_stmt=5, return_stmt=6, read_stmt=7, write_stmt=8, proc_stmt=9, null_stmt=10 } type; union { struct htslist_struct { struct slist_struct *head; struct slist_struct *tail; } *if_conditionals; struct slist_struct *exprList; struct expression_struct *expression; struct { struct stmt_struct *init; struct conditional_struct { struct expression_struct *condition; enum BranchType_enum { bt_equal0=0, bt_nequal0=1 } branchType; struct htslist_struct *statements; } *cBlock; } loopdata; struct { struct expression_struct *lvalue; struct expression_struct *rvalue; } assigndata; struct { char *name; struct slist_struct *paramExprs; } procdata; } data; } *funcCall; struct expression_struct *innerExpr; } edata; } *


printHelp

repo: willghatch/cpslc

decompiled_code:
void __fastcall __noreturn printHelp(int status)
{
puts("The incredible, amazing, and stupendous cpslc written by William Hatch.");
puts("Compiles CPSL programs into mips assembly suitable for spim or MARS");
puts("I/O to/from stdout/stdin unless otherwise specified with these flags.");
puts("Options:");
puts("-v --verbose print symbol table");
puts("-h --help print this message");
puts("-f <file> --file <file> set input file");
puts("-o <file> --output <file> set output file");
putchar(10);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int status)
{
puts("The incredible, amazing, and stupendous cpslc written by William Hatch.");
puts("Compiles CPSL programs into mips assembly suitable for spim or MARS");
puts("I/O to/from stdout/stdin unless otherwise specified with these flags.");
puts("Options:");
puts("-v --verbose print symbol table");
puts("-h --help print this message");
puts("-f <file> --file <file> set input file");
puts("-o <file> --output <file> set output file");
putchar(10);
exit(status);
}

original_code:
void printHelp(int exitStatus) {
    printf("The incredible, amazing, and stupendous cpslc written by William Hatch.\n");
    printf("Compiles CPSL programs into mips assembly suitable for spim or MARS\n");
    printf("I/O to/from stdout/stdin unless otherwise specified with these flags.\n");
    printf("Options:\n");
    printf("-v --verbose                print symbol table\n");
    printf("-h --help                   print this message\n");
    printf("-f <file> --file <file>     set input file\n");
    printf("-o <file> --output <file>   set output file\n");
    printf("\n");
    exit(exitStatus);
}

variable_types: exitStatus int

return_type: void


putIntervalArray

repo: willghatch/qiafph

decompiled_code:
__int64 __fastcall putIntervalArray(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdx

result = (unsigned int)(nmeasures * sdivPerDiv * mdivision);
if ( (int)result > 1 )
{
v3 = (unsigned int)(result - 2);
result = 0LL;
do
{
*(_DWORD *)(a2 + 4 * result) = *(_DWORD *)(a1 + 8 * result + 8) - *(_DWORD *)(a1 + 8 * result);
v4 = result++;
}
while ( v4 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdx

result = (unsigned int)(nmeasures * sdivPerDiv * mdivision);
if ( (int)result > 1 )
{
v3 = (unsigned int)(result - 2);
result = 0LL;
do
{
*(_DWORD *)(a2 + 4 * result) = *(_DWORD *)(a1 + 8 * result + 8) - *(_DWORD *)(a1 + 8 * result);
v4 = result++;
}
while ( v4 != v3 );
}
return result;
}

original_code:
void putIntervalArray(Note* part, int* intervals) {
    int intervalLen = mdivision * sdivPerDiv * nmeasures - 1;
    for(int i = 0; i < intervalLen; ++i) {
        intervals[i] = part[i+1].pitch - part[i].pitch;
    }
}

canonical_original_code:
void putIntervalArray(struct notestruct *part, int *intervals) {
    int intervalLen = mdivision * sdivPerDiv * nmeasures - 1;
    for(int i = 0; i < intervalLen; ++i) {
        intervals[i] = part[i+1].pitch - part[i].pitch;
    }
}

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

variable_types:
intervals
int *

variable_types: intervalLen int

variable_types: i int


partsCp

decompiled_code:
void *__fastcall partsCp(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
void *result; // rax

if ( nparts > 0 )
{
v2 = 0LL;
do
{
result = memcpy(*(void **)(a2 + 8 * v2), *(const void **)(a1 + 8 * v2), 8LL * totalSubdivisions);
++v2;
}
while ( nparts > (int)v2 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
void *result; // rax

if ( nparts > 0 )
{
v2 = 0LL;
do
{
result = memcpy(*(void **)(a2 + 8 * v2), *(const void **)(a1 + 8 * v2), 8LL * totalSubdivisions);
++v2;
}
while ( nparts > (int)v2 );
}
return result;
}

original_code:
void partsCp(Note** srcParts, Note** dstParts) {
    for(int i = 0; i < nparts; ++i) {
        memcpy(dstParts[i], srcParts[i], sizeof(Note)*totalSubdivisions);
    }
}

canonical_original_code:
void partsCp(struct notestruct **srcParts, struct notestruct **dstParts) {
    for(int i = 0; i < nparts; ++i) {
        memcpy(dstParts[i], srcParts[i], sizeof(Note)*totalSubdivisions);
    }
}

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

variable_types:
dstParts
struct notestruct **


partsIntervalsCp

decompiled_code:
void *__fastcall partsIntervalsCp(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
void *result; // rax

if ( nparts > 0 )
{
v2 = 0LL;
do
{
result = memcpy(*(void **)(a2 + 8 * v2), *(const void **)(a1 + 8 * v2), 4LL * totalSubdivisions);
++v2;
}
while ( nparts > (int)v2 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
void *result; // rax

if ( nparts > 0 )
{
v2 = 0LL;
do
{
result = memcpy(*(void **)(a2 + 8 * v2), *(const void **)(a1 + 8 * v2), 4LL * totalSubdivisions);
++v2;
}
while ( nparts > (int)v2 );
}
return result;
}

original_code:
void partsIntervalsCp(int** src, int** dst) {
    for(int i = 0; i < nparts; ++i) {
        memcpy(dst[i], src[i], sizeof(int)*totalSubdivisions);
    }
}

canonical_original_code:
void partsIntervalsCp(int **src, int **dst) {
    for(int i = 0; i < nparts; ++i) {
        memcpy(dst[i], src[i], sizeof(int)*totalSubdivisions);
    }
}

variable_types:
src
int **

variable_types:
dst
int **


chordInfoCp

decompiled_code:
void *__fastcall chordInfoCp(void *src, void *dest)
{
return memcpy(dest, src, 32 * mdivision * (__int64)nmeasures);
}

canonical_decompiled_code:
void *__fastcall func3(void *src, void *dest)
{
return memcpy(dest, src, 32 * mdivision * (__int64)nmeasures);
}

original_code:
void chordInfoCp(ChordInfo* src, ChordInfo* dst) {
    memcpy(dst, src, sizeof(ChordInfo)*nmeasures*mdivision);
}

canonical_original_code:
void chordInfoCp(struct ChordInfoStruct *src, struct ChordInfoStruct *dst) {
    memcpy(dst, src, sizeof(ChordInfo)*nmeasures*mdivision);
}

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

variable_types:
dst
struct ChordInfoStruct *

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


printHelp

decompiled_code:
void __fastcall __noreturn printHelp(int status)
{
fwrite("qiafph -- qiafph is a four part harmonizer\n", 1uLL, 0x2BuLL, stderr);
fwrite("Written by William Hatch for CS 5600 at USU\n", 1uLL, 0x2CuLL, stderr);
fwrite("Generates four part harmony. Configured at the moment in source\n", 1uLL, 0x41uLL, stderr);
fwrite("in rulescores.h and globalvars.h\n", 1uLL, 0x21uLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite("-m <file> --midge <file> Midge output file\n", 1uLL, 0x31uLL, stderr);
fwrite("-a <file> --analysis <file> Analysis info output file\n", 1uLL, 0x39uLL, stderr);
fwrite("-n <int> --nparts <int> Number of parts (default 4, must be > 2)\n", 1uLL, 0x48uLL, stderr);
fwrite("-v --verbose Print some extra info to stderr\n", 1uLL, 0x3FuLL, stderr);
fwrite("-h --help Print this message to stderr\n", 1uLL, 0x3CuLL, stderr);
fwrite("\nA music output format (midge or musedata) must be supplied\n", 1uLL, 0x3CuLL, stderr);
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int status)
{
fwrite("qiafph -- qiafph is a four part harmonizer\n", 1uLL, 0x2BuLL, stderr);
fwrite("Written by William Hatch for CS 5600 at USU\n", 1uLL, 0x2CuLL, stderr);
fwrite("Generates four part harmony. Configured at the moment in source\n", 1uLL, 0x41uLL, stderr);
fwrite("in rulescores.h and globalvars.h\n", 1uLL, 0x21uLL, stderr);
fwrite("Options:\n", 1uLL, 9uLL, stderr);
fwrite("-m <file> --midge <file> Midge output file\n", 1uLL, 0x31uLL, stderr);
fwrite("-a <file> --analysis <file> Analysis info output file\n", 1uLL, 0x39uLL, stderr);
fwrite("-n <int> --nparts <int> Number of parts (default 4, must be > 2)\n", 1uLL, 0x48uLL, stderr);
fwrite("-v --verbose Print some extra info to stderr\n", 1uLL, 0x3FuLL, stderr);
fwrite("-h --help Print this message to stderr\n", 1uLL, 0x3CuLL, stderr);
fwrite("\nA music output format (midge or musedata) must be supplied\n", 1uLL, 0x3CuLL, stderr);
exit(status);
}

original_code:
void printHelp(int exitStatus) {
    fprintf(stderr, "qiafph -- qiafph is a four part harmonizer\n");
    fprintf(stderr, "Written by William Hatch for CS 5600 at USU\n");
    fprintf(stderr, "Generates four part harmony.  Configured at the moment in source\n");
    fprintf(stderr, "in rulescores.h and globalvars.h\n");
    fprintf(stderr, "Options:\n");
    fprintf(stderr, "-m <file>  --midge <file>      Midge output file\n");
    fprintf(stderr, "-a <file>  --analysis <file>   Analysis info output file\n");
    fprintf(stderr, "-n <int>   --nparts <int>      Number of parts (default 4, must be > 2)\n");
    fprintf(stderr, "-v         --verbose           Print some extra info to stderr\n");
    fprintf(stderr, "-h         --help              Print this message to stderr\n");
    fprintf(stderr, "\nA music output format (midge or musedata) must be supplied\n");
    exit(exitStatus);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int longind; // [rsp+4Ch] [rbp-FCh] BYREF
struct option longopts; // [rsp+50h] [rbp-F8h] BYREF
const char *v7; // [rsp+70h] [rbp-D8h]
int v8; // [rsp+78h] [rbp-D0h]
__int64 v9; // [rsp+80h] [rbp-C8h]
int v10; // [rsp+88h] [rbp-C0h]
const char *v11; // [rsp+90h] [rbp-B8h]
int v12; // [rsp+98h] [rbp-B0h]
__int64 v13; // [rsp+A0h] [rbp-A8h]
int v14; // [rsp+A8h] [rbp-A0h]
const char *v15; // [rsp+B0h] [rbp-98h]
int v16; // [rsp+B8h] [rbp-90h]
__int64 v17; // [rsp+C0h] [rbp-88h]
int v18; // [rsp+C8h] [rbp-80h]
const char *v19; // [rsp+D0h] [rbp-78h]
int v20; // [rsp+D8h] [rbp-70h]
__int64 v21; // [rsp+E0h] [rbp-68h]
int v22; // [rsp+E8h] [rbp-60h]
__int64 v23; // [rsp+F0h] [rbp-58h]
int v24; // [rsp+F8h] [rbp-50h]
__int64 v25; // [rsp+100h] [rbp-48h]
int v26; // [rsp+108h] [rbp-40h]

verboseP = 0;
nparts = 4;
longopts.name = "midge";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 109;
v7 = "analysis";
v8 = 1;
v9 = 0LL;
v10 = 97;
v11 = "nparts";
v12 = 1;
v13 = 0LL;
v14 = 110;
v15 = "help";
v16 = 0;
v17 = 0LL;
v18 = 104;
v19 = "verbose";
v20 = 0;
v21 = 0LL;
v22 = 118;
v23 = 0LL;
v24 = 0;
v25 = 0LL;
v26 = 0;
longind = 0;
v3 = getopt_long(argc, (char *const *)argv, "vhn:m:a:", &longopts, &longind);
if ( v3 != -1 )
{
if ( v3 != 63 )
printHelp(1);
printHelp(1);
}
printHelp(1);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int longind; // [rsp+4Ch] [rbp-FCh] BYREF
struct option longopts; // [rsp+50h] [rbp-F8h] BYREF
const char *v7; // [rsp+70h] [rbp-D8h]
int v8; // [rsp+78h] [rbp-D0h]
__int64 v9; // [rsp+80h] [rbp-C8h]
int v10; // [rsp+88h] [rbp-C0h]
const char *v11; // [rsp+90h] [rbp-B8h]
int v12; // [rsp+98h] [rbp-B0h]
__int64 v13; // [rsp+A0h] [rbp-A8h]
int v14; // [rsp+A8h] [rbp-A0h]
const char *v15; // [rsp+B0h] [rbp-98h]
int v16; // [rsp+B8h] [rbp-90h]
__int64 v17; // [rsp+C0h] [rbp-88h]
int v18; // [rsp+C8h] [rbp-80h]
const char *v19; // [rsp+D0h] [rbp-78h]
int v20; // [rsp+D8h] [rbp-70h]
__int64 v21; // [rsp+E0h] [rbp-68h]
int v22; // [rsp+E8h] [rbp-60h]
__int64 v23; // [rsp+F0h] [rbp-58h]
int v24; // [rsp+F8h] [rbp-50h]
__int64 v25; // [rsp+100h] [rbp-48h]
int v26; // [rsp+108h] [rbp-40h]

verboseP = 0;
nparts = 4;
longopts.name = "midge";
longopts.has_arg = 1;
longopts.flag = 0LL;
longopts.val = 109;
v7 = "analysis";
v8 = 1;
v9 = 0LL;
v10 = 97;
v11 = "nparts";
v12 = 1;
v13 = 0LL;
v14 = 110;
v15 = "help";
v16 = 0;
v17 = 0LL;
v18 = 104;
v19 = "verbose";
v20 = 0;
v21 = 0LL;
v22 = 118;
v23 = 0LL;
v24 = 0;
v25 = 0LL;
v26 = 0;
longind = 0;
v3 = getopt_long(argc, (char *const *)argv, "vhn:m:a:", &longopts, &longind);
if ( v3 != -1 )
{
if ( v3 != 63 )
func4(1);
func4(1);
}
func4(1);
}

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

return_type: int

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

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

result = (unsigned int)(12 * (a1 / 12));
switch ( a1 % 12 )
{
case 0:
result = 67LL;
break;
case 1:
case 2:
result = 68LL;
break;
case 3:
case 4:
result = 69LL;
break;
case 5:
result = 70LL;
break;
case 6:
case 7:
result = 71LL;
break;
case 8:
case 9:
result = 65LL;
break;
case 10:
case 11:
result = 66LL;
break;
default:
return result;
}
return result;
}

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

result = (unsigned int)(12 * (a1 / 12));
switch ( a1 % 12 )
{
case 0:
result = 67LL;
break;
case 1:
case 2:
result = 68LL;
break;
case 3:
case 4:
result = 69LL;
break;
case 5:
result = 70LL;
break;
case 6:
case 7:
result = 71LL;
break;
case 8:
case 9:
result = 65LL;
break;
case 10:
case 11:
result = 66LL;
break;
default:
return 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;
    }
}


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)
{
unsigned int v3; // edx
int v4; // eax

v3 = a1 + a3;
v4 = (int)v3 % 12;
if ( a1 <= a2 )
{
v3 = 1;
if ( a1 != a2 )
{
switch ( v4 )
{
case 0:
case 5:
v3 = a2 - a1 == 1;
break;
case 2:
case 4:
case 7:
case 9:
case 11:
v3 = a2 - a1 == 2;
break;
default:
return v3;
}
}
}
else
{
switch ( v4 )
{
case 0:
case 2:
case 4:
case 7:
case 9:
v3 = a1 - a2 == 2;
break;
case 5:
case 11:
v3 = a1 - a2 == 1;
break;
default:
return v3;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, int a2, int a3)
{
unsigned int v3; // edx
int v4; // eax

v3 = a1 + a3;
v4 = (int)v3 % 12;
if ( a1 <= a2 )
{
v3 = 1;
if ( a1 != a2 )
{
switch ( v4 )
{
case 0:
case 5:
v3 = a2 - a1 == 1;
break;
case 2:
case 4:
case 7:
case 9:
case 11:
v3 = a2 - a1 == 2;
break;
default:
return v3;
}
}
}
else
{
switch ( v4 )
{
case 0:
case 2:
case 4:
case 7:
case 9:
v3 = a1 - a2 == 2;
break;
case 5:
case 11:
v3 = a1 - a2 == 1;
break;
default:
return v3;
}
}
return v3;
}

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


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; // ebx
int v7; // eax
int v8; // ebx
int v9; // edx
__int64 result; // rax
int v11; // eax
int v12; // edx
int v13; // eax

*a4 = 1;
v6 = a2 - *a1;
*a4 = *a1 != 0;
if ( (unsigned int)minorChordP(a3) )
{
v11 = a1[3];
v8 = v6 - v11;
if ( v11 )
goto LABEL_9;
goto LABEL_8;
}
if ( !(unsigned int)diminishedChordP(a3) )
{
v7 = a1[4];
v8 = v6 - v7;
if ( !v7 )
*a4 = 0;
goto LABEL_5;
}
v13 = a1[3];
v8 = v6 - v13;
if ( !v13 )
{
LABEL_8:
*a4 = 0;
LABEL_9:
if ( !(unsigned int)diminishedChordP(a3) )
{
LABEL_5:
v9 = a1[7];
result = (unsigned int)(v8 - v9);
if ( !v9 )
*a4 = 0;
goto LABEL_12;
}
}
v12 = a1[6];
result = (unsigned int)(v8 - v12);
if ( !v12 )
*a4 = 0;
LABEL_12:
if ( a3 == 9 )
return (unsigned int)(result - a1[9]);
if ( (unsigned int)(a3 - 6) <= 2 )
return (unsigned int)(result - a1[10]);
if ( a3 == 5 )
result = (unsigned int)(result - a1[11]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, int a2, int a3, _DWORD *a4)
{
int v6; // ebx
int v7; // eax
int v8; // ebx
int v9; // edx
__int64 result; // rax
int v11; // eax
int v12; // edx
int v13; // eax

*a4 = 1;
v6 = a2 - *a1;
*a4 = *a1 != 0;
if ( (unsigned int)func1(a3) )
{
v11 = a1[3];
v8 = v6 - v11;
if ( v11 )
goto LABEL_9;
goto LABEL_8;
}
if ( !(unsigned int)func2(a3) )
{
v7 = a1[4];
v8 = v6 - v7;
if ( !v7 )
*a4 = 0;
goto LABEL_5;
}
v13 = a1[3];
v8 = v6 - v13;
if ( !v13 )
{
LABEL_8:
*a4 = 0;
LABEL_9:
if ( !(unsigned int)func2(a3) )
{
LABEL_5:
v9 = a1[7];
result = (unsigned int)(v8 - v9);
if ( !v9 )
*a4 = 0;
goto LABEL_12;
}
}
v12 = a1[6];
result = (unsigned int)(v8 - v12);
if ( !v12 )
*a4 = 0;
LABEL_12:
if ( a3 == 9 )
return (unsigned int)(result - a1[9]);
if ( (unsigned int)(a3 - 6) <= 2 )
return (unsigned int)(result - a1[10]);
if ( a3 == 5 )
result = (unsigned int)(result - a1[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:
unsigned __int64 __fastcall chordAnalyze_most(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax
void *v4; // rsp
__int64 v5; // rax
int v6; // er9
int v7; // er8
int j; // er13
int v9; // er11
int v10; // er15
int v11; // er10
int v12; // er14
__int64 v13; // rdi
__int64 v14; // [rsp+0h] [rbp-40h] BYREF
unsigned int i; // [rsp+Ch] [rbp-34h]

v14 = a2;
result = (4LL * sdivPerDiv * nparts + 15) & 0xFFFFFFFFFFFFFFF0LL;
v4 = alloca(4LL * sdivPerDiv * nparts);
for ( i = 0; nmeasures > (int)i; result = i )
{
v9 = mdivision;
for ( j = 0; mdivision > j; v9 = mdivision )
{
v10 = sdivPerDiv;
if ( sdivPerDiv > 0 )
{
v11 = nparts;
v7 = sdivPerDiv * j + v9 * sdivPerDiv * i;
v12 = sdivPerDiv + v7;
v6 = 0;
v13 = nparts;
do
{
if ( v11 > 0 )
{
v5 = 0LL;
do
{
*((_DWORD *)&v14 + v6 + v5) = *(_DWORD *)(*(_QWORD *)(a1 + 8 * v5) + 8LL * v7);
++v5;
}
while ( v13 != v5 );
}
v6 += v11;
++v7;
}
while ( v7 != v12 );
}
getChordInfo_most((int *)&v14, nparts * v10, (_DWORD *)(v14 + 32LL * (int)(i * v9 + j++)));
}
++i;
}
return result;
}

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

v14 = a2;
result = (4LL * sdivPerDiv * nparts + 15) & 0xFFFFFFFFFFFFFFF0LL;
v4 = alloca(4LL * sdivPerDiv * nparts);
for ( i = 0; nmeasures > (int)i; result = i )
{
v9 = mdivision;
for ( j = 0; mdivision > j; v9 = mdivision )
{
v10 = sdivPerDiv;
if ( sdivPerDiv > 0 )
{
v11 = nparts;
v7 = sdivPerDiv * j + v9 * sdivPerDiv * i;
v12 = sdivPerDiv + v7;
v6 = 0;
v13 = nparts;
do
{
if ( v11 > 0 )
{
v5 = 0LL;
do
{
*((_DWORD *)&v14 + v6 + v5) = *(_DWORD *)(*(_QWORD *)(a1 + 8 * v5) + 8LL * v7);
++v5;
}
while ( v13 != v5 );
}
v6 += v11;
++v7;
}
while ( v7 != v12 );
}
func5((int *)&v14, nparts * v10, (_DWORD *)(v14 + 32LL * (int)(i * v9 + j++)));
}
++i;
}
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


decompiled_code:
__int64 __fastcall chordAnalyze_putKeyAssociation(_DWORD *a1, int a2)
{
__int64 result; // rax
_DWORD *v3; // rbp
__int64 v4; // r14
int v5; // ebx
int v6; // edi

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

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, int a2)
{
__int64 result; // rax
_DWORD *v3; // rbp
__int64 v4; // r14
int v5; // ebx
int v6; // edi

result = (unsigned int)(mdivision * nmeasures);
if ( (int)result > 0 )
{
v3 = a1;
v4 = (__int64)&a1[8 * (unsigned int)(result - 1) + 8];
do
{
v5 = (*v3 + a2) % 12;
v6 = v3[2];
switch ( v5 )
{
case 0:
result = func3(v6);
v5 = 1;
break;
case 1:
v5 = 2;
result = 0LL;
break;
case 2:
result = func1(v6);
break;
case 3:
result = 0LL;
break;
case 4:
result = func1(v6);
v5 = 3;
break;
case 5:
result = func3(v6);
v5 = 4;
break;
case 6:
v5 = 5;
result = 0LL;
break;
case 7:
result = func3(v6);
v5 = 5;
break;
case 8:
v5 = 6;
result = 0LL;
break;
case 9:
result = func1(v6);
v5 = 6;
break;
case 10:
v5 = 7;
result = 0LL;
break;
case 11:
result = func2(v6);
v5 = 7;
break;
default:
v5 = 0;
result = 0LL;
break;
}
v3[7] = result;
v3[6] = v5;
v3 += 8;
}
while ( v3 != (_DWORD *)v4 );
}
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 v5; // er14
__int64 v6; // rdx
void *v7; // rsp
int v8; // edi
int v9; // er15
__int64 i; // rcx
_DWORD *v11; // rax
__int64 v12; // rdx
_DWORD *v13; // rdx
_DWORD *v14; // rax
unsigned int v15; // edx
_DWORD v17[12]; // [rsp+0h] [rbp-30h] BYREF

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

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
int v2; // ebp
__int64 *v3; // rdi
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebx
int v2; // ebp
__int64 *v3; // rdi
__int64 result; // rax

v1 = rand() % nparts;
v2 = rand() % totalSubdivisions;
v3 = (__int64 *)(a1 + 8LL * v1);
*(_DWORD *)(*v3 + 8LL * v2) = *(_DWORD *)(rangemin + 4LL * v1) + rand() % *(_DWORD *)(rangediff + 4LL * v1);
result = *v3;
*(_DWORD *)(*v3 + 8LL * v2 + 4) = 0;
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:
__int64 __fastcall changeRandMdivision(__int64 a1)
{
int v1; // ebp
int v2; // ebx
int v3; // edx
__int64 result; // rax
int v5; // edx
_QWORD *v6; // rsi
int v7; // ecx

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // ebp
int v2; // ebx
int v3; // edx
__int64 result; // rax
int v5; // edx
_QWORD *v6; // rsi
int v7; // ecx

v1 = rand() % nparts;
v2 = rand() % (mdivision * nmeasures);
v3 = rand() % *(_DWORD *)(rangediff + 4LL * v1);
result = rangemin;
v5 = *(_DWORD *)(rangemin + 4LL * v1) + v3;
if ( sdivPerDiv > 0 )
{
v6 = (_QWORD *)(a1 + 8LL * v1);
result = 8LL * v2;
v7 = 0;
do
{
*(_DWORD *)(*v6 + result) = v5;
*(_DWORD *)(*v6 + result + 4) = 0;
++v7;
result += 8LL;
}
while ( sdivPerDiv > 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:
__int64 __fastcall changeNRandMdivisions(__int64 a1, int a2)
{
int i; // ebx
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
int i; // ebx
__int64 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 = changeNRandMdivisions(a1, 1);
break;
case 12:
result = changeNRandMdivisions(a1, 2);
break;
case 13:
result = changeNRandMdivisions(a1, 3);
break;
case 14:
result = changeNRandMdivisions(a1, 4);
break;
case 15:
result = changeNRandMdivisions(a1, 5);
break;
case 16:
result = changeNRandMdivisions(a1, 6);
break;
case 17:
result = changeNRandMdivisions(a1, 7);
break;
case 18:
result = changeNRandMdivisions(a1, 8);
break;
case 19:
result = changeNRandMdivisions(a1, 9);
break;
case 20:
result = 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 = func2(a1, 1);
break;
case 12:
result = func2(a1, 2);
break;
case 13:
result = func2(a1, 3);
break;
case 14:
result = func2(a1, 4);
break;
case 15:
result = func2(a1, 5);
break;
case 16:
result = func2(a1, 6);
break;
case 17:
result = func2(a1, 7);
break;
case 18:
result = func2(a1, 8);
break;
case 19:
result = func2(a1, 9);
break;
case 20:
result = 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, int a2)
{
int i; // ebx
__int64 result; // rax

if ( a1 )
{
rtprint(*a1, (unsigned int)(a2 + 1));
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
putchar(9);
}
vecprint(a1[2]);
result = rtprint(a1[1], (unsigned int)(a2 + 1));
}
return result;
}

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

if ( a1 )
{
func0(*a1, (unsigned int)(a2 + 1));
if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
putchar(9);
}
vecprint(a1[2]);
result = func0(a1[1], (unsigned int)(a2 + 1));
}
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:
double __fastcall myvecdist2(__int64 a1, __int64 a2)
{
double result; // xmm0_8
double v3; // xmm0_8

if ( !a1 || !a2 )
return *(double *)&LC0;
v3 = vecdist2();
if ( v3 < 0.0 )
result = sqrt(v3);
else
result = sqrt(v3);
return result;
}

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

if ( !a1 || !a2 )
return *(double *)&LC0;
v3 = vecdist2();
if ( v3 < 0.0 )
result = sqrt(v3);
else
result = sqrt(v3);
return result;
}

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
unsigned __int64 *v5; // r12
unsigned __int64 *v6; // r14
__int64 *v7; // rbx
__int64 v8; // rax
__int64 v9; // rbx
__int64 v10; // r13
_BYTE v11[12]; // [rsp+0h] [rbp-50h] BYREF
int v12; // [rsp+Ch] [rbp-44h]
int v13; // [rsp+10h] [rbp-40h]
unsigned int v14; // [rsp+14h] [rbp-3Ch]
unsigned __int64 v15; // [rsp+18h] [rbp-38h]

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

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

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

decompiled_code:
__int64 __fastcall contains(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // edx
__int64 v6; // rsi
__int64 v7; // rdx
__int64 v8; // rax
double v9; // xmm0_8

v5 = *(_DWORD *)a3;
if ( v5 <= 0 )
return 1LL;
v6 = *(_QWORD *)(a3 + 8);
v7 = 8LL * (unsigned int)v5;
v8 = 0LL;
while ( 1 )
{
v9 = *(double *)(v6 + v8);
if ( *(double *)(*(_QWORD *)(a1 + 8) + v8) > v9 )
break;
if ( v9 > *(double *)(*(_QWORD *)(a2 + 8) + v8) )
return 0LL;
v8 += 8LL;
if ( v8 == v7 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // edx
__int64 v6; // rsi
__int64 v7; // rdx
__int64 v8; // rax
double v9; // xmm0_8

v5 = *(_DWORD *)a3;
if ( v5 <= 0 )
return 1LL;
v6 = *(_QWORD *)(a3 + 8);
v7 = 8LL * (unsigned int)v5;
v8 = 0LL;
while ( 1 )
{
v9 = *(double *)(v6 + v8);
if ( *(double *)(*(_QWORD *)(a1 + 8) + v8) > v9 )
break;
if ( v9 > *(double *)(*(_QWORD *)(a2 + 8) + v8) )
return 0LL;
v8 += 8LL;
if ( v8 == v7 )
return 1LL;
}
return 0LL;
}

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

decompiled_code:
void __fastcall rrangesearch(_QWORD *a1, __int64 a2, __int64 a3, int a4)
{
int *v6; // r14
int v7; // er15

if ( a1 )
{
v6 = (int *)a1[2];
v7 = *v6;
if ( (unsigned int)contains(a2, a3, (__int64)v6) )
vecprint(v6);
if ( *(double *)(*(_QWORD *)(a1[2] + 8LL) + 8LL * a4) >= *(double *)(*(_QWORD *)(a2 + 8) + 8LL * a4) )
rrangesearch(*a1, a2, a3, (unsigned int)((a4 + 1) % v7));
if ( *(double *)(*(_QWORD *)(a3 + 8) + 8LL * a4) > *(double *)(*(_QWORD *)(a1[2] + 8LL) + 8LL * a4) )
rrangesearch(a1[1], a2, a3, (unsigned int)((a4 + 1) % v7));
}
}

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 func1(__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 func2(__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
double v3; // xmm0_8

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

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

v1 = *a1;
if ( *a1 > 0 )
{
v2 = 0;
do
{
v3 = func2((__int64)a1, v2);
printf("%g\t", v3);
++v2;
}
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; // xmm1_4
float v4; // xmm0_4
double v6; // [rsp+8h] [rbp-40h]
double cosx; // [rsp+10h] [rbp-38h] BYREF
double sinx; // [rsp+18h] [rbp-30h] BYREF
int v9[9]; // [rsp+24h] [rbp-24h] BYREF

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

canonical_decompiled_code:
float *__fastcall func3(float *a1, __int64 a2, float a3)
{
float v3; // xmm1_4
float v4; // xmm0_4
double v6; // [rsp+8h] [rbp-40h]
double cosx; // [rsp+10h] [rbp-38h] BYREF
double sinx; // [rsp+18h] [rbp-30h] BYREF
int v9[9]; // [rsp+24h] [rbp-24h] BYREF

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

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


decompiled_code:
float __fastcall quat_normal(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = (float)(a1[3] * a1[3]) + (float)((float)((float)(a1[1] * a1[1]) + (float)(*a1 * *a1)) + (float)(a1[2] * a1[2]));
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

canonical_decompiled_code:
float __fastcall func4(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = (float)(a1[3] * a1[3]) + (float)((float)((float)(a1[1] * a1[1]) + (float)(*a1 * *a1)) + (float)(a1[2] * a1[2]));
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

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 *a3)
{
float *v4; // r12
float *v5; // rsi
int v7[4]; // [rsp+0h] [rbp-48h] BYREF
int v8[14]; // [rsp+10h] [rbp-38h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, float *a2, float *a3)
{
float *v4; // r12
float *v5; // rsi
int v7[4]; // [rsp+0h] [rbp-48h] BYREF
int v8[14]; // [rsp+10h] [rbp-38h] BYREF

v4 = (float *)quat_conjugate(v7, a2);
v5 = func7((float *)v8, a2, a3);
func6((float *)v8, v5, v4);
return v3_make(a1, *(float *)v8, *(float *)&v8[1], *(float *)&v8[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; }