// File: /workspace/github_cpp_makefile_star2_O2/drarwood[P]gags/Main.cpp
// Function: main
int main(int argc, char** argv) {

    // 1. Show header
    ShowHeader();
    
    // 2. Parse command line
    ARGS theseArgs;
    ParseCommand(argc, argv, &theseArgs);
    if(!theseArgs.ok) {
        ShowOptions();
        exit(EXIT_FAILURE);
    }
    cout << "Arguments: " << endl;
    cout << "        --pheno      -p " << theseArgs.phenoString << endl;
    cout << "        --ns         -n " << theseArgs.nsString << endl;
    cout << "        --means      -m " << theseArgs.meansString << endl;
    cout << "        --sd         -s " << theseArgs.sdsString << endl;
    cout << "        --seed       -r " << theseArgs.seed << endl;
    cout << "        --mrate      -y " << theseArgs.mRate << endl;
    cout << "        --popsize    -z " << theseArgs.popsize << endl;
    cout << "        --exclusions -e " << theseArgs.exclusionsString << endl;
    cout << "        --iterations -i " << theseArgs.iterations << endl;
    cout << "        --out        -o " << theseArgs.outString << endl << endl;    
    srand(theseArgs.seed);
    
    // Create vectors for list arguments
    vector<int> ns;
    SplitIntArgs(theseArgs.nsString, ns);
    vector<double> means;
    SplitDoubleArgs(theseArgs.meansString, means);
    vector<double> sds;
    SplitDoubleArgs(theseArgs.sdsString, sds);

    // Get required precision input by user
    vector<int> t1;
    DetermineDoubleArgsPrecision(theseArgs.meansString, t1);
    vector<int> t2;
    DetermineDoubleArgsPrecision(theseArgs.sdsString, t2);
    
    // read exclusions file    
    map<string,int> exclusions;
    if (theseArgs.exclusionsString.length() > 0) {
        ReadExclusionsFile(theseArgs.exclusionsString, exclusions);
    }

    // Load the phenotypes
    cout << "Reading phenotypes..." << endl;
    vector<string> idVector;
    vector<double> phenoVector;
    map<string,double> phenoMap;
    ReadPhenotypeFileMinusExclusions(theseArgs.phenoString, idVector, phenoVector, phenoMap, exclusions);    
        
    // Check number of individuals required to formulate the distribution is more than the number with pheneotype
    unsigned int total_n = 0;
    for (unsigned int i = 0; i<ns.size(); ++i) {
        total_n += ns[i];
    }
    //cout << total_n << endl;
    if (total_n > phenoVector.size()) {
        cout << "Unable to process this data as required sample sizes for distributions larger than N in phenotype file" << endl;
    }
    
    // At this point we want to order the Ns and adjust ordering of means and SDs in vecto
    vector<int>    nsSorted;  
    vector<double> meansSorted;
    vector<double> sdsSorted;
    vector<int>    meansPrecision;
    vector<int>    sdsPrecision;

    map<int,int>   jsUsed;

    nsSorted = ns;
    sort(nsSorted.begin(), nsSorted.end());
    for (unsigned int i = 0; i < nsSorted.size(); ++i) {
        for (unsigned int j = 0; j < ns.size(); ++j) {
            if (ns[j] == nsSorted[i] && jsUsed.find(j) == jsUsed.end()) {
                meansSorted.push_back(means[j]);
                sdsSorted.push_back(sds[j]);
                meansPrecision.push_back(t1[j]);
                sdsPrecision.push_back(t2[j]);
                jsUsed[j] = 0;
                break;
            }
        }
    }
    ns.clear();
    means.clear();
    sds.clear();
    
    // If the smallest N >= 10% of total_n then we carry on as usual
    bool solveIndependently;
    bool solveIndependentlyEverSet = false;
    int  independentGroupIndex = 0;
    int  smallestOffset = 0;
    int  nSubtract     = 0;
    int  n;
    
    
    do { 
        
        if ( ((double) nsSorted[smallestOffset] / (double) (total_n-nSubtract)) > 0.1 ) {
            solveIndependently = false;
            n = total_n-nSubtract;            
            for (unsigned int i = smallestOffset; i < nsSorted.size(); ++i) {
                ns.push_back(nsSorted[i]);
                means.push_back(meansSorted[i]);
                sds.push_back(sdsSorted[i]);
            }
        }
        // else we need to solve as seperate problem
        else {
            solveIndependently = true;
            solveIndependentlyEverSet = true;
            n = nsSorted[smallestOffset];
            ns.push_back(nsSorted[smallestOffset]);
            means.push_back(meansSorted[smallestOffset]);
            sds.push_back(sdsSorted[smallestOffset]);
            nSubtract += nsSorted[smallestOffset];
            smallestOffset++;
        }
 
        
        // 1. Initialise solutions
        cout << "Initialising solutions..." << endl;
        vector<vector<string> > population(theseArgs.popsize);
        cout << "Exclusion list size " << exclusions.size() << endl;
        InitializeSolutions(n, idVector, population, exclusions);
        
        // 2. Score solutions
        cout << "Scoring solutions..." << endl;
        vector<double> scores(theseArgs.popsize);
        //double thiscore;
        for (int i = 0; i < theseArgs.popsize; ++i) {
            scores[i] = ScoreSolution(population[i], phenoMap, ns, means, sds);
        }
        
        // 3. Determine the lowest (best) score  and solution with lowest score
        double lowestScore;
        int    bestSolutionIndex;
        DetermineBestSolution(scores, lowestScore, bestSolutionIndex);
        cout << "Best score and solution ID presently: " << lowestScore << " "  << bestSolutionIndex << endl;
        
        // 4. Determine if we have found a solution that is good enough by chance using the best one we have in the population
        bool solutionFound;
        solutionFound = TestBestSolution(population[bestSolutionIndex], phenoMap, ns, means, sds, meansPrecision, sdsPrecision);
        
        // 5. If solution found by chance then output it
        if (solutionFound) {
            cout << "Solution found" << endl;
            if (!solveIndependentlyEverSet) {
                independentGroupIndex++;
                OutputSolution(population[bestSolutionIndex], phenoMap, ns, theseArgs.outString, independentGroupIndex);
            }
            else {
                independentGroupIndex++;
                OutputIndependentSolution(population[bestSolutionIndex], phenoMap, ns, theseArgs.outString, independentGroupIndex);
                // add samples from last solution to exclusion list so we don't include them again
                for (vector<string>::iterator it = population[bestSolutionIndex].begin(); it != population[bestSolutionIndex].end(); ++it) {
                    exclusions[*it] = 0;
                }
            }
        }
        
        
        // 6. else we need tocyce up to max iterations to try and find solution
        else {
            
            // Determine highest (worst) score and solution with worst score
            bool   carryOn = true;
            double highestScore;
            int    worstSolutionIndex;
            DetermineWorstSolution(scores, highestScore, worstSolutionIndex);

            cout << "Iteration 1 ";
            
            // Iterate through for MAX iterations
            for (int i = 0; i < theseArgs.iterations; ++i) {
                
                int iter = (i+1)*100;
                if (100 % iter == 0) {
                    cout << iter << " ";
                }

                // [re]generate Roulette Wheel
                vector<double> rWheel;
                GenerateRouletteWheel(rWheel, scores);
                
                // Spin the wheel x2 to select solutions
                vector<int> randomIndicies;
                int ri1 = SpinWheel(rWheel);
                randomIndicies.push_back(ri1);
                int ri2;
                do {
                    ri2 = SpinWheel(rWheel);
                } while (ri1 == ri2);
                randomIndicies.push_back(ri2);
                
                // Crossover
                vector<vector<string> > chrXY(2);   
                map<string,int> chrXAlleles;
                map<string,int> chrYAlleles;
                CrossoverPMX(population, randomIndicies, idVector, chrXY, chrXAlleles, chrYAlleles);
                
                // Mutate
                Mutate(chrXY, ns, theseArgs.mRate, idVector, phenoMap, chrXAlleles, chrYAlleles, exclusions);
                
                // Identify the worst 2 scores in the population frist
                vector<int> worst2Solutions;
                DetermineX2LeastFit(worst2Solutions, scores);
                
                // 1.  First see if either provide us with a good enough solution //            
                for (int j = 0; j < 2; ++j) {
                    
                    // get score for current child
                    double thisScore = ScoreSolution(chrXY[j], phenoMap, ns, means, sds);
                    
                    // if this score lower (i.e. better) than lowest score in the population check whether solution good enough
                    if (thisScore < lowestScore) {
                    
                        lowestScore = thisScore;
                        
                        // check if we have found a solution
                        solutionFound = TestBestSolution(chrXY[j], phenoMap, ns, means, sds, meansPrecision, sdsPrecision);
                        
                        // if it is - print out and stop
                        if (solutionFound) {
                            
                            cout << thisScore << endl;
                            cout << "Solution found! " << endl;
                            
                            if (!solveIndependentlyEverSet) {
                                independentGroupIndex++;
                                OutputSolution(chrXY[j], phenoMap, ns, theseArgs.outString, independentGroupIndex);
                            }
                            else {
                                independentGroupIndex++;
                                OutputIndependentSolution(chrXY[j], phenoMap, ns, theseArgs.outString, independentGroupIndex);
                                // add samples from last solution to exclusion list so we don't include them again
                                for (vector<string>::iterator it = chrXY[j].begin(); it != chrXY[j].end(); ++it) {
                                    exclusions[*it] = 0;
                                }
                            }
                            
                            carryOn = false;
                            break;
                        }
                        else {
                            // place this solution in the population and update respective score
                            population[worst2Solutions[j]] = chrXY[j];
                            scores[worst2Solutions[j]] = thisScore;
                        }
                    }
                    else {
                        // place this solution in the population
                        population[worst2Solutions[j]] = chrXY[j];
                        scores[worst2Solutions[j]] = thisScore;
                    }
                }
                if (!carryOn) {
                    break;
                }
                // cout << lowestScore << endl;
                randomIndicies.clear();
            }  
        }
        
        // clear out the vectors
        ns.clear();
        means.clear();
        sds.clear();
        population.clear();
        scores.clear();
        
        if (!solutionFound) {
            cout << theseArgs.iterations << endl;
            cout << "Sorry - no solution not found this time." << endl;
            cout << "Error score: " << lowestScore << endl;
        }
                
    } while (solveIndependently);
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x498, %rsp            # imm = 0x498
movq %rsi, %rbx
movl %edi, %ebp
callq 0x86a8
leaq 0x338(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x358(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x378(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x398(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x3b8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x3d8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x328(%rsp), %rdx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x8870
cmpb $0x0, 0x400(%rsp)
je 0x473e
movq 0xb896(%rip), %rdi      # 0xefd8
leaq 0x68d7(%rip), %rsi      # 0xa020
callq 0x3250
movq %rax, %rdi
callq 0x3140
movq 0xb87b(%rip), %rdi      # 0xefd8
leaq 0x68c8(%rip), %rsi      # 0xa02c
callq 0x3250
leaq 0x328(%rsp), %rsi
movq %rax, %rdi
callq 0x3230
movq %rax, %rdi
callq 0x3140
movq 0xb850(%rip), %rdi      # 0xefd8
leaq 0x68b6(%rip), %rsi      # 0xa045
callq 0x3250
leaq 0x348(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3140
movq 0xb822(%rip), %rdi      # 0xefd8
leaq 0x68a1(%rip), %rsi      # 0xa05e
callq 0x3250
leaq 0x368(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3140
movq 0xb7f4(%rip), %rdi      # 0xefd8
leaq 0x688c(%rip), %rsi      # 0xa077
callq 0x3250
leaq 0x388(%rsp), %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3140
movq 0xb7c6(%rip), %rdi      # 0xefd8
leaq 0x6877(%rip), %rsi      # 0xa090
callq 0x3250
movl 0x3e8(%rsp), %esi
movq %rax, %rdi
callq 0x33f0
movq %rax, %rdi
callq 0x3140
movq 0xb79c(%rip), %rdi      # 0xefd8
leaq 0x6866(%rip), %rsi      # 0xa0a9
callq 0x3250
movsd 0x3f8(%rsp), %xmm0
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
callq 0x3140
movq 0xb770(%rip), %rdi      # 0xefd8
leaq 0x6853(%rip), %rsi      # 0xa0c2
callq 0x3250
movl 0x3ec(%rsp), %esi
movq %rax, %rdi
callq 0x33f0
movq %rax, %rdi
callq 0x3140
movq 0xb746(%rip), %rdi      # 0xefd8
leaq 0x6842(%rip), %rsi      # 0xa0db
callq 0x3250
leaq 0x3a8(%rsp), %r12
movq %rax, %rdi
movq %r12, %rsi
callq 0x3230
movq %rax, %rdi
callq 0x3140
movq 0xb718(%rip), %rdi      # 0xefd8
leaq 0x682d(%rip), %rsi      # 0xa0f4
callq 0x3250
movl 0x3f0(%rsp), %esi
movq %rax, %rdi
callq 0x33f0
movq %rax, %rdi
callq 0x3140
movq 0xb6ee(%rip), %rdi      # 0xefd8
leaq 0x681c(%rip), %rsi      # 0xa10d
callq 0x3250
leaq 0x3c8(%rsp), %rsi
movq %rax, %rdi
callq 0x3230
movq %rax, %rdi
callq 0x3140
movq %rax, %rdi
callq 0x3140
movl 0x3e8(%rsp), %edi
callq 0x3240
xorpd %xmm0, %xmm0
leaq 0x70(%rsp), %rsi
movapd %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movq %r14, %rdi
callq 0x9440
leaq 0x50(%rsp), %rsi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movq %rbx, %rdi
callq 0x934a
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rsi
movapd %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movq %r15, %rdi
callq 0x934a
leaq 0x310(%rsp), %rsi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movq %rbx, %rdi
callq 0x9534
xorpd %xmm0, %xmm0
leaq 0x2f0(%rsp), %rsi
movapd %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movq %r15, %rdi
callq 0x9534
leaq 0x298(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorl %eax, %eax
cmpq %rax, 0x3b0(%rsp)
je 0x3a05
leaq 0x430(%rsp), %rdi
movq %r12, %rsi
callq 0x3320
leaq 0x430(%rsp), %rdi
leaq 0x290(%rsp), %rsi
callq 0x617c
leaq 0x430(%rsp), %rdi
callq 0x3120
movq 0xb5cc(%rip), %rdi      # 0xefd8
leaq 0x6713(%rip), %rsi      # 0xa126
callq 0x3250
movq %rax, %rdi
callq 0x3140
xorpd %xmm0, %xmm0
movapd %xmm0, 0x1e0(%rsp)
andq $0x0, 0x1f0(%rsp)
movapd %xmm0, 0x1c0(%rsp)
andq $0x0, 0x1d0(%rsp)
leaq 0x238(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x410(%rsp), %rdi
leaq 0x328(%rsp), %rsi
callq 0x3320
leaq 0x410(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
leaq 0x1c0(%rsp), %rdx
leaq 0x230(%rsp), %rcx
leaq 0x290(%rsp), %r8
callq 0x9828
leaq 0x410(%rsp), %rdi
callq 0x3120
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
xorl %edx, %edx
xorl %ebx, %ebx
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0x3ad7
addl (%rax,%rdx,4), %ebx
incl %edx
jmp 0x3ac9
movl %ebx, %eax
movq 0x1c8(%rsp), %rcx
subq 0x1c0(%rsp), %rcx
sarq $0x3, %rcx
cmpq %rax, %rcx
jae 0x3b0d
movq 0xb4df(%rip), %rdi      # 0xefd8
leaq 0x663c(%rip), %rsi      # 0xa13c
callq 0x3250
movq %rax, %rdi
callq 0x3140
movl %ebx, 0xe4(%rsp)
xorpd %xmm0, %xmm0
leaq 0xc0(%rsp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movapd %xmm0, 0x1a0(%rsp)
andq $0x0, 0x1b0(%rsp)
movapd %xmm0, 0x180(%rsp)
andq $0x0, 0x190(%rsp)
movapd %xmm0, 0x160(%rsp)
andq $0x0, 0x170(%rsp)
movapd %xmm0, 0x140(%rsp)
andq $0x0, 0x150(%rsp)
leaq 0x458(%rsp), %r15
andl $0x0, (%r15)
andq $0x0, 0x8(%r15)
movq %r15, 0x10(%r15)
movq %r15, 0x18(%r15)
andq $0x0, 0x20(%r15)
leaq 0x70(%rsp), %rsi
callq 0x4948
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x4fa9
xorl %r13d, %r13d
leaq 0x450(%rsp), %rbx
leaq 0x200(%rsp), %r14
movl %r13d, %r13d
movq 0xc8(%rsp), %rax
subq 0xc0(%rsp), %rax
sarq $0x2, %rax
cmpq %r13, %rax
jbe 0x3cbb
xorl %r12d, %r12d
movl %r12d, %ebp
movq 0x70(%rsp), %rax
movq 0x78(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbp, %rcx
jbe 0x3cb3
movl (%rax,%rbp,4), %eax
movq 0xc0(%rsp), %rcx
cmpl (%rcx,%r13,4), %eax
jne 0x3c2a
movl %r12d, 0x200(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x53aa
cmpq %r15, %rax
je 0x3c2f
incl %r12d
jmp 0x3be4
leaq (,%rbp,8), %r15
movq 0x50(%rsp), %rsi
addq %r15, %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x4a12
addq 0x30(%rsp), %r15
leaq 0x180(%rsp), %rdi
movq %r15, %rsi
callq 0x4a12
shlq $0x2, %rbp
movq 0x310(%rsp), %rsi
addq %rbp, %rsi
leaq 0x160(%rsp), %rdi
callq 0x4a34
addq 0x2f0(%rsp), %rbp
leaq 0x140(%rsp), %rdi
movq %rbp, %rsi
callq 0x4a34
movl %r12d, 0x200(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a52
andl $0x0, (%rax)
leaq 0x458(%rsp), %r15
incl %r13d
jmp 0x3bc1
movq 0x70(%rsp), %rax
cmpq %rax, 0x78(%rsp)
je 0x3ccc
movq %rax, 0x78(%rsp)
movq 0x50(%rsp), %rax
cmpq %rax, 0x58(%rsp)
je 0x3cdd
movq %rax, 0x58(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x3cee
movq %rax, 0x38(%rsp)
leaq 0x14(%rsp), %rax
andl $0x0, (%rax)
movq $0x0, 0xd8(%rsp)
movsd 0x62fe(%rip), %xmm1     # 0xa008
leaq 0x70(%rsp), %r13
movl $0x0, 0x28(%rsp)
movl $0x0, 0x1c(%rsp)
movl 0x28(%rsp), %edx
movslq %edx, %rbp
movq 0xc0(%rsp), %rax
movl (%rax,%rbp,4), %ebx
cvtsi2sd %ebx, %xmm2
movl 0xe4(%rsp), %ecx
movl %ecx, %r15d
subl 0x1c(%rsp), %r15d
cvtsi2sd %r15, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x280(%rsp)
ucomisd %xmm1, %xmm2
ja 0x3dc7
leaq (%rax,%rbp,4), %rsi
movq %r13, %rdi
callq 0x4a34
leaq 0x200(%rsp), %r15
leaq (,%rbp,8), %r14
movq 0x1a0(%rsp), %rsi
addq %r14, %rsi
leaq 0x50(%rsp), %rdi
callq 0x4a12
addq 0x180(%rsp), %r14
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x4a12
movq 0xc0(%rsp), %rax
movl 0x1c(%rsp), %ecx
addl (%rax,%rbp,4), %ecx
movl %ecx, 0x1c(%rsp)
incl %ebp
movb $0x1, %al
movq %rax, 0xd8(%rsp)
movl %ebp, 0x28(%rsp)
jmp 0x3e34
movl %edx, %ebp
movl %ebp, %ebp
movq 0xc8(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbp, %rcx
jbe 0x3e29
leaq (%rax,%rbp,4), %rsi
movq %r13, %rdi
callq 0x4a34
leaq (,%rbp,8), %r14
movq 0x1a0(%rsp), %rsi
addq %r14, %rsi
leaq 0x50(%rsp), %rdi
callq 0x4a12
addq 0x180(%rsp), %r14
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x4a12
incl %ebp
movq 0xc0(%rsp), %rax
jmp 0x3dc9
movl %r15d, %ebx
leaq 0x200(%rsp), %r15
movq 0xb19d(%rip), %rdi      # 0xefd8
leaq 0x6361(%rip), %rsi      # 0xa1a3
callq 0x3250
movq %rax, %rdi
callq 0x3140
movslq 0x3ec(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
movq %r15, %rdx
callq 0x4aa0
movq 0xb16a(%rip), %rdi      # 0xefd8
leaq 0x6348(%rip), %rsi      # 0xa1bd
callq 0x3250
leaq 0x290(%rsp), %rbp
leaq 0x1e0(%rsp), %r14
movq 0x2b8(%rsp), %rsi
movq %rax, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x3140
movl %ebx, %edi
movq %r14, %rsi
leaq 0xa8(%rsp), %rdx
movq %rbp, %rcx
callq 0x6b1c
movq 0xb11a(%rip), %rdi      # 0xefd8
leaq 0x630d(%rip), %rsi      # 0xa1d2
callq 0x3250
movq %rax, %rdi
callq 0x3140
movslq 0x3ec(%rsp), %rsi
leaq 0x90(%rsp), %rdi
movq %r15, %rdx
callq 0x4af2
xorl %r14d, %r14d
xorl %r15d, %r15d
movslq 0x3ec(%rsp), %rax
cmpq %rax, %r15
jge 0x3f39
movq 0xa8(%rsp), %rdi
addq %r14, %rdi
leaq 0x230(%rsp), %rsi
movq %r13, %rdx
leaq 0x50(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x6c57
movq 0x90(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
addq $0x18, %r14
jmp 0x3ef0
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x6ded
movq 0xb07e(%rip), %rdi      # 0xefd8
leaq 0x6286(%rip), %rsi      # 0xa1e7
callq 0x3250
movsd 0x88(%rsp), %xmm0
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
leaq 0x64b5(%rip), %rsi      # 0xa436
callq 0x3250
movl 0x18(%rsp), %esi
movq %rax, %rdi
callq 0x33f0
movq %rax, %rdi
callq 0x3140
movslq 0x18(%rsp), %rax
imulq $0x18, %rax, %rdi
addq 0xa8(%rsp), %rdi
leaq 0x140(%rsp), %rax
movq %rax, (%rsp)
leaq 0x230(%rsp), %rsi
movq %r13, %rdx
leaq 0x50(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x160(%rsp), %r9
callq 0x6e2c
testb %al, %al
je 0x4082
movq 0xaff0(%rip), %rdi      # 0xefd8
leaq 0x621f(%rip), %rsi      # 0xa20e
callq 0x3250
movq %rax, %rdi
callq 0x3140
incl 0x14(%rsp)
movslq 0x18(%rsp), %rax
imulq $0x18, %rax, %rdi
addq 0xa8(%rsp), %rdi
testb $0x1, 0xd8(%rsp)
je 0x4547
leaq 0x230(%rsp), %rsi
movq %r13, %rdx
leaq 0x3c8(%rsp), %rcx
leaq 0x14(%rsp), %r8
callq 0x646c
movslq 0x18(%rsp), %rax
movq 0xa8(%rsp), %rcx
imulq $0x18, %rax, %rdx
movq (%rcx,%rdx), %r14
cltq
imulq $0x18, %rax, %rax
cmpq 0x8(%rcx,%rax), %r14
je 0x4569
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4b44
andl $0x0, (%rax)
addq $0x20, %r14
movl 0x18(%rsp), %eax
movq 0xa8(%rsp), %rcx
jmp 0x4051
leaq 0x90(%rsp), %rdi
leaq 0x408(%rsp), %rsi
leaq 0x28c(%rsp), %rdx
callq 0x7217
movq 0xaf32(%rip), %rdi      # 0xefd8
leaq 0x6170(%rip), %rsi      # 0xa21d
callq 0x3250
xorl %r14d, %r14d
xorl %ebx, %ebx
cmpl 0x3f0(%rsp), %ebx
jge 0x456c
incl %ebx
imull $0x64, %ebx, %eax
cmpl $0x64, %eax
jne 0x40ec
movq 0xaf03(%rip), %rdi      # 0xefd8
pushq $0x64
popq %rsi
callq 0x33f0
movq %rax, %rdi
leaq 0x634f(%rip), %rsi      # 0xa436
callq 0x3250
movl %ebx, 0xe8(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x260(%rsp)
andq $0x0, 0x270(%rsp)
leaq 0x260(%rsp), %r15
movq %r15, %rdi
leaq 0x90(%rsp), %rsi
callq 0x7084
xorpd %xmm0, %xmm0
movapd %xmm0, 0xf0(%rsp)
andq $0x0, 0x100(%rsp)
movq %r15, %rdi
callq 0x71d8
movl %eax, 0x2c(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
callq 0x4a34
leaq 0x200(%rsp), %r15
leaq 0x260(%rsp), %rdi
callq 0x71d8
movl %eax, 0xec(%rsp)
cmpl %eax, 0x2c(%rsp)
je 0x415d
leaq 0xf0(%rsp), %rdi
leaq 0xec(%rsp), %rsi
callq 0x4a34
leaq 0x108(%rsp), %r12
movq %r12, %rdi
pushq $0x2
popq %rsi
movq %r15, %rdx
callq 0x4aa0
movl %r14d, 0x20(%rsp)
movq %rbp, %rbx
movq %r13, %r14
andl $0x0, 0x208(%rsp)
andq $0x0, 0x210(%rsp)
leaq 0x208(%rsp), %rax
movq %rax, 0x218(%rsp)
movq %rax, 0x220(%rsp)
andq $0x0, 0x228(%rsp)
andl $0x0, 0x2c8(%rsp)
andq $0x0, 0x2d0(%rsp)
leaq 0x2c8(%rsp), %rax
movq %rax, 0x2d8(%rsp)
movq %rax, 0x2e0(%rsp)
andq $0x0, 0x2e8(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0x1e0(%rsp), %rbp
movq %rbp, %rdx
movq %r12, %rcx
movq %r15, %r8
leaq 0x2c0(%rsp), %r13
movq %r13, %r9
callq 0x7252
movsd 0x3f8(%rsp), %xmm0
movq %rbx, (%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
leaq 0x230(%rsp), %rcx
movq %r15, %r8
movq %r13, %r9
callq 0x7760
xorpd %xmm0, %xmm0
movapd %xmm0, 0x120(%rsp)
andq $0x0, 0x130(%rsp)
leaq 0x480(%rsp), %r15
movq %r15, %rdi
leaq 0x90(%rsp), %rsi
callq 0x4baa
leaq 0x120(%rsp), %rdi
movq %r15, %rsi
callq 0x7b87
movq %r15, %rdi
callq 0x4eae
xorl %ebp, %ebp
xorl %r15d, %r15d
movq %r14, %r13
movl 0x20(%rsp), %r14d
cmpq $0x30, %r15
je 0x43f8
movq 0x108(%rsp), %rdi
addq %r15, %rdi
leaq 0x230(%rsp), %rsi
movq %r13, %rdx
leaq 0x50(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x6c57
movsd 0x88(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movsd %xmm0, 0x20(%rsp)
jbe 0x43a1
movsd %xmm0, 0x88(%rsp)
movq 0x108(%rsp), %rdi
addq %r15, %rdi
leaq 0x140(%rsp), %rax
movq %rax, (%rsp)
leaq 0x230(%rsp), %rsi
movq %r13, %rdx
leaq 0x50(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x160(%rsp), %r9
callq 0x6e2c
movsd 0x20(%rsp), %xmm0
testb %al, %al
jne 0x447e
movq 0x108(%rsp), %rsi
addq %r15, %rsi
movq 0x120(%rsp), %rax
movslq (%rax,%rbp), %rax
imulq $0x18, %rax, %rdi
addq 0xa8(%rsp), %rdi
callq 0x4bf8
movsd 0x20(%rsp), %xmm0
movq 0x120(%rsp), %rax
movslq (%rax,%rbp), %rax
shlq $0x3, %rax
addq 0x90(%rsp), %rax
xorl %r14d, %r14d
jmp 0x43e7
movq 0x108(%rsp), %rsi
addq %r15, %rsi
movq 0x120(%rsp), %rax
movslq (%rax,%rbp), %rax
imulq $0x18, %rax, %rdi
addq 0xa8(%rsp), %rdi
callq 0x4bf8
movsd 0x20(%rsp), %xmm0
movq 0x120(%rsp), %rax
movslq (%rax,%rbp), %rax
shlq $0x3, %rax
addq 0x90(%rsp), %rax
movsd %xmm0, (%rax)
addq $0x18, %r15
addq $0x4, %rbp
jmp 0x42be
movq 0xf0(%rsp), %rax
cmpq %rax, 0xf8(%rsp)
je 0x4412
movq %rax, 0xf8(%rsp)
leaq 0x290(%rsp), %rbp
leaq 0x120(%rsp), %rdi
callq 0x4e7a
leaq 0x2c0(%rsp), %rdi
callq 0x4d5a
leaq 0x200(%rsp), %rdi
callq 0x4d5a
leaq 0x108(%rsp), %rdi
callq 0x4cc2
leaq 0xf0(%rsp), %rdi
callq 0x4e7a
leaq 0x260(%rsp), %rdi
callq 0x4eae
cmpq $0x30, %r15
movl 0xe8(%rsp), %ebx
je 0x40b7
jmp 0x456c
movq 0xab53(%rip), %rdi      # 0xefd8
callq 0x33b0
leaq 0x290(%rsp), %rbp
movq %rax, %rdi
callq 0x3140
movq 0xab37(%rip), %rdi      # 0xefd8
leaq 0x5d82(%rip), %rsi      # 0xa22a
callq 0x3250
movq %rax, %rdi
callq 0x3140
incl 0x14(%rsp)
movq 0x108(%rsp), %rdi
addq %r15, %rdi
testb $0x1, 0xd8(%rsp)
je 0x451a
leaq 0x230(%rsp), %rsi
movq %r13, %rdx
leaq 0x3c8(%rsp), %rcx
leaq 0x14(%rsp), %r8
callq 0x646c
movq 0x108(%rsp), %rax
movq (%rax,%r15), %r14
cmpq 0x8(%rax,%r15), %r14
je 0x453f
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4b44
andl $0x0, (%rax)
addq $0x20, %r14
movq 0x108(%rsp), %rax
jmp 0x44f7
movb $0x1, %r14b
leaq 0x230(%rsp), %rsi
movq %r13, %rdx
leaq 0x3c8(%rsp), %rcx
leaq 0x14(%rsp), %r8
callq 0x62b0
jmp 0x441a
movb $0x1, %r14b
jmp 0x441a
movb $0x1, %r14b
leaq 0x230(%rsp), %rsi
movq %r13, %rdx
leaq 0x3c8(%rsp), %rcx
leaq 0x14(%rsp), %r8
callq 0x62b0
jmp 0x456c
movb $0x1, %r14b
movq 0x70(%rsp), %rax
cmpq %rax, 0x78(%rsp)
je 0x457d
movq %rax, 0x78(%rsp)
movq 0x50(%rsp), %rax
cmpq %rax, 0x58(%rsp)
je 0x458e
movq %rax, 0x58(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x459f
movq %rax, 0x38(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x4ce4
movq 0x90(%rsp), %rax
cmpq %rax, 0x98(%rsp)
je 0x45c6
movq %rax, 0x98(%rsp)
testb $0x1, %r14b
jne 0x462e
movl 0x3f0(%rsp), %esi
movq 0xa9fe(%rip), %rdi      # 0xefd8
callq 0x33f0
movq %rax, %rdi
callq 0x3140
movq 0xa9ea(%rip), %rdi      # 0xefd8
leaq 0x5c46(%rip), %rsi      # 0xa23b
callq 0x3250
movq %rax, %rdi
callq 0x3140
movq 0xa9cf(%rip), %rdi      # 0xefd8
leaq 0x5c54(%rip), %rsi      # 0xa264
callq 0x3250
movsd 0x88(%rsp), %xmm0
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
callq 0x3140
leaq 0x90(%rsp), %rdi
callq 0x4eae
leaq 0xa8(%rsp), %rdi
callq 0x4cc2
movsd 0x59b8(%rip), %xmm1     # 0xa008
movsd 0x280(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3d1f
leaq 0x450(%rsp), %rdi
callq 0x4dbe
leaq 0x140(%rsp), %rdi
callq 0x4e7a
leaq 0x160(%rsp), %rdi
callq 0x4e7a
leaq 0x180(%rsp), %rdi
callq 0x4eae
leaq 0x1a0(%rsp), %rdi
callq 0x4eae
leaq 0xc0(%rsp), %rdi
callq 0x4e7a
leaq 0x230(%rsp), %rdi
callq 0x4e16
leaq 0x1c0(%rsp), %rdi
callq 0x4eae
leaq 0x1e0(%rsp), %rdi
callq 0x4cec
leaq 0x290(%rsp), %rdi
callq 0x4d5a
leaq 0x2f0(%rsp), %rdi
callq 0x4e7a
leaq 0x310(%rsp), %rdi
callq 0x4e7a
leaq 0x30(%rsp), %rdi
callq 0x4eae
leaq 0x50(%rsp), %rdi
callq 0x4eae
leaq 0x70(%rsp), %rdi
callq 0x4e7a
leaq 0x328(%rsp), %rdi
callq 0x4d0e
xorl %eax, %eax
addq $0x498, %rsp            # imm = 0x498
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x8762
pushq $0x1
popq %rdi
callq 0x32c0
movq %rax, %rbx
leaq 0x430(%rsp), %rdi
callq 0x3120
jmp 0x48ee
jmp 0x4777
movq %rax, %rbx
leaq 0x410(%rsp), %rdi
callq 0x3120
jmp 0x48c7
movq %rax, %rbx
jmp 0x48c7
movq %rax, %rbx
jmp 0x48fb
movq %rax, %rbx
jmp 0x4908
movq %rax, %rbx
jmp 0x4915
movq %rax, %rbx
jmp 0x491f
movq %rax, %rbx
jmp 0x4929
jmp 0x4804
movq %rax, %rbx
jmp 0x48ee
jmp 0x4804
jmp 0x47fd
jmp 0x47c9
jmp 0x4804
movq %rax, %rbx
jmp 0x4933
jmp 0x4804
jmp 0x4804
jmp 0x47fd
jmp 0x47fd
movq %rax, %rbx
jmp 0x486c
jmp 0x47fd
jmp 0x4809
jmp 0x480e
movq %rax, %rbx
leaq 0x480(%rsp), %rdi
callq 0x4eae
jmp 0x4811
jmp 0x4809
movq %rax, %rbx
jmp 0x4852
jmp 0x47fd
jmp 0x4804
jmp 0x480e
movq %rax, %rbx
jmp 0x481e
jmp 0x4809
movq %rax, %rbx
jmp 0x485f
jmp 0x480e
movq %rax, %rbx
jmp 0x4879
movq %rax, %rbx
jmp 0x4845
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x4e7a
leaq 0x2c0(%rsp), %rdi
callq 0x4d5a
leaq 0x200(%rsp), %rdi
callq 0x4d5a
leaq 0x108(%rsp), %rdi
callq 0x4cc2
leaq 0xf0(%rsp), %rdi
callq 0x4e7a
leaq 0x260(%rsp), %rdi
callq 0x4eae
leaq 0x90(%rsp), %rdi
callq 0x4eae
leaq 0xa8(%rsp), %rdi
callq 0x4cc2
leaq 0x450(%rsp), %rdi
callq 0x4dbe
leaq 0x140(%rsp), %rdi
callq 0x4e7a
leaq 0x160(%rsp), %rdi
callq 0x4e7a
leaq 0x180(%rsp), %rdi
callq 0x4eae
leaq 0x1a0(%rsp), %rdi
callq 0x4eae
leaq 0xc0(%rsp), %rdi
callq 0x4e7a
leaq 0x230(%rsp), %rdi
callq 0x4e16
leaq 0x1c0(%rsp), %rdi
callq 0x4eae
leaq 0x1e0(%rsp), %rdi
callq 0x4cec
leaq 0x290(%rsp), %rdi
callq 0x4d5a
leaq 0x2f0(%rsp), %rdi
callq 0x4e7a
leaq 0x310(%rsp), %rdi
callq 0x4e7a
leaq 0x30(%rsp), %rdi
callq 0x4eae
leaq 0x50(%rsp), %rdi
callq 0x4eae
leaq 0x70(%rsp), %rdi
callq 0x4e7a
leaq 0x328(%rsp), %rdi
callq 0x4d0e
movq %rbx, %rdi
callq 0x3410