// File: /workspace/github_cpp_makefile_star2_O3/bobverity[P]MavericK/EM_algorithm.cpp
// Function: EM_admix(globals&, int)
void EM_admix(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // create empty objects
    int geneCopies = sum(globals.ploidy_vec)*globals.loci;
    vector< vector<double> > logProbMat(geneCopies,vector<double>(K,-log(double(K))));
    double logProbSum;
    vector< vector< vector<double> > > logAlleleFreqs(K);
    double logAlleleFreqsSum;
    vector< vector<double> > logAdmixFreqs(globals.n,vector<double>(K));
    double logLike=0;
    double logLike_this_i=0;
    double logLike_this_ik=0;
    
    // initialise logAlleleFreqs and logAdmixFreqs and zero global maximum likelihood allele frequencies
    globals.max_alleleFreqs = vector< vector< vector<double> > >(K);
    globals.max_admixFreqs = vector< vector<double> >(globals.n,vector<double>(K));
    for (int k=0; k<K; k++) {
        logAlleleFreqs[k] = vector< vector<double> >(globals.loci);
        globals.max_alleleFreqs[k] = vector< vector<double> >(globals.loci);
        for (int l=0; l<globals.loci; l++) {
            logAlleleFreqs[k][l] = vector<double>(globals.J[l]);
            globals.max_alleleFreqs[k][l] = vector<double>(globals.J[l]);
        }
    }
    
    // repeat EM multiple times
    globals.maxLike = log(double(0));
    for (int EMrep=0; EMrep<globals.EMrepeats; EMrep++) {
        
        // initialise random allele frequencies
        for (int k=0; k<K; k++) {
            for (int l=0; l<globals.loci; l++) {
                logAlleleFreqsSum = log(double(0));
                for (int j=0; j<globals.J[l]; j++) {
                    logAlleleFreqs[k][l][j] = log(runif1(0.1,0.9));
                    logAlleleFreqsSum = logSum(logAlleleFreqsSum, logAlleleFreqs[k][l][j]);
                }
                for (int j=0; j<globals.J[l]; j++) {
                    logAlleleFreqs[k][l][j] -= logAlleleFreqsSum;
                }
            }
        }
        
        // EM iterations
        for (int EMiter=0; EMiter<globals.EMiterations; EMiter++) {
            
            // loop through all individuals
            int groupIndex = -1;
            for (int i=0; i<globals.n; i++) {
                
                // zero admixture freqs for this individual
                for (int k=0; k<K; k++) {
                    logAdmixFreqs[i][k] = log(double(0));
                }
                
                // calculate probability matrix and contribute to ML admixture freqs
                for (int l=0; l<globals.loci; l++) {
                    for (int p=0; p<globals.ploidy_vec[i]; p++) {
                        groupIndex++;
                        if (globals.data[i][l][p]!=0) {
                            logProbSum = log(double(0));
                            for (int k=0; k<K; k++) {
                                logProbMat[groupIndex][k] = logAlleleFreqs[k][l][globals.data[i][l][p]-1];
                                logProbSum = logSum(logProbSum,logProbMat[groupIndex][k]);
                            }
                            for (int k=0; k<K; k++) {
                                logProbMat[groupIndex][k] -= logProbSum;
                            }
                        }
                        for (int k=0; k<K; k++) {
                            logAdmixFreqs[i][k] = logSum(logAdmixFreqs[i][k],logProbMat[groupIndex][k]-log(double(globals.loci))-log(double(globals.ploidy_vec[i])));
                        }
                    }
                }
            } // i loop
            
            // zero allele frequencies
            for (int k=0; k<K; k++) {
                for (int l=0; l<globals.loci; l++) {
                    for (int j=0; j<globals.J[l]; j++) {
                        logAlleleFreqs[k][l][j] = log(double(0));
                    }
                }
            }
            
            // add contribution to allele frequencies
            groupIndex = -1;
            for (int i=0; i<globals.n; i++) {
                for (int l=0; l<globals.loci; l++) {
                    for (int p=0; p<globals.ploidy_vec[i]; p++) {
                        groupIndex++;
                        if (globals.data[i][l][p]!=0) {
                            for (int k=0; k<K; k++) {
                                logAlleleFreqs[k][l][globals.data[i][l][p]-1] = logSum(logAlleleFreqs[k][l][globals.data[i][l][p]-1], logAdmixFreqs[i][k]+logProbMat[groupIndex][k]);
                            }
                        }
                    }
                }
            }
            
            // normalise allele frequencies
            for (int k=0; k<K; k++) {
                for (int l=0; l<globals.loci; l++) {
                    logProbSum = log(double(0));
                    for (int j=0; j<globals.J[l]; j++) {
                        logProbSum = logSum(logProbSum, logAlleleFreqs[k][l][j]);
                    }
                    for (int j=0; j<globals.J[l]; j++) {
                        logAlleleFreqs[k][l][j] -= logProbSum;
                    }
                }
            }
            
        } // end of EM iterations loop
        
        
        logLike = 0;
        for (int i=0; i<globals.n; i++) {
            logLike_this_i = log(double(0));
            for (int k=0; k<K; k++) {
                logLike_this_ik = 0;
                for (int l=0; l<globals.loci; l++) {
                    for (int p=0; p<globals.ploidy_vec[i]; p++) {
                        if (globals.data[i][l][p]!=0) {
                            logLike_this_ik += logAlleleFreqs[k][l][globals.data[i][l][p]-1];
                        }
                    }
                }
                logLike_this_i = logSum(logLike_this_i, logLike_this_ik - log(double(K)));
            }
            logLike += logLike_this_i;
        }
        
        // calculate log-likelihood
        double logLike = 0;
        double temp;
        for (int i=0; i<globals.n; i++) {
            for (int l=0; l<globals.loci; l++) {
                for (int p=0; p<globals.ploidy; p++) {
                    if (globals.data[i][l][p]!=0) {
                        temp = log(double(0));
                        for (int k=0; k<K; k++) {
                            temp = logSum(temp, logAdmixFreqs[i][k]+logAlleleFreqs[k][l][globals.data[i][l][p]-1]);
                        }
                        logLike += temp;
                    }
                }
            }
        }
        
        // replace current values if more likely
        if (logLike>globals.maxLike) {
            globals.maxLike = logLike;
            for (int k=0; k<K; k++) {
                for (int l=0; l<globals.loci; l++) {
                    for (int j=0; j<globals.J[l]; j++) {
                        globals.max_alleleFreqs[k][l][j] = exp(logAlleleFreqs[k][l][j]);
                    }
                }
            }
            for (int i=0; i<globals.n; i++) {
                for (int k=0; k<K; k++) {
                    globals.max_admixFreqs[i][k] = exp(logAdmixFreqs[i][k]);
                }
            }
        }
        
    } // end of repeat EM loop
    
    // calculate model comparison statistics
    if (globals.outputComparisonStatistics_on) {
        
        int freeParameters = K*(sum(globals.J)-globals.loci) + globals.n*(K-1);
        globals.AIC[Kindex] = 2*freeParameters - 2*globals.maxLike;
        globals.BIC[Kindex] = freeParameters*log(double(globals.geneCopies)) - 2*globals.maxLike;
        globals.DIC_Spiegelhalter[Kindex] = -4*globals.structure_loglike_mean[Kindex][0] + 2*globals.maxLike;
        globals.DIC_Gelman[Kindex] = -2*globals.structure_loglike_mean[Kindex][0] + 2*globals.structure_loglike_var[Kindex][0];
        
    }
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %rbp
movl 0x2bc8(%rdi), %eax
movl %esi, 0x88(%rsp)
addl %esi, %eax
movq %rax, 0x10(%rsp)
movq 0x2cd0(%rdi), %rax
movq 0x2cd8(%rdi), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0x4902
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
xorl %ebx, %ebx
addl (%rax,%rdx,4), %ebx
incq %rdx
cmpq %rdx, %rcx
jne 0x48f5
jmp 0x4904
xorl %ebx, %ebx
movslq 0x2d1c(%rbp), %r15
movslq 0x10(%rsp), %r14
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0xe0(%rsp)
callq 0x3290
xorpd 0x31715(%rip), %xmm0    # 0x36040
leaq 0x48(%rsp), %rdx
movlpd %xmm0, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0x90(%rsp), %rcx
movq %r14, %rsi
callq 0x5b2e
movslq %ebx, %rax
imulq %rax, %r15
leaq 0xc0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x60(%rsp), %rcx
movq %r15, %rsi
callq 0x591c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4979
callq 0x3310
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r14, %rsi
callq 0x59ac
movslq 0x2d18(%rbp), %r15
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r14, %rsi
callq 0x588e
leaq 0x90(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xa8(%rsp), %rcx
movq %r15, %rsi
callq 0x591c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x49d0
callq 0x3310
leaq 0x60(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
movq %r14, %rsi
callq 0x59ac
movq 0x3058(%rbp), %rax
leaq 0x60(%rsp), %r15
movapd (%r15), %xmm0
movq 0x10(%r15), %rcx
movq %rcx, 0x3058(%rbp)
movupd 0x3048(%rbp), %xmm1
movupd %xmm0, 0x3048(%rbp)
leaq 0x20(%rsp), %rdi
movapd %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
callq 0x5a2a
movq %r15, %rdi
callq 0x5a2a
movslq 0x2d18(%rbp), %r15
leaq 0xa8(%rsp), %rdi
leaq 0x3f(%rsp), %rdx
movq %r14, %rsi
callq 0x588e
leaq 0x60(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
leaq 0x3e(%rsp), %rcx
movq %r15, %rsi
callq 0x591c
movq 0x3070(%rbp), %rax
leaq 0x60(%rsp), %r14
movapd (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x3070(%rbp)
movupd 0x3060(%rbp), %xmm1
movupd %xmm0, 0x3060(%rbp)
leaq 0x20(%rsp), %rdi
movapd %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x5ae8
movq %r14, %rdi
callq 0x5ae8
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x4adb
callq 0x3310
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
testl %eax, %eax
movq %rbp, 0x18(%rsp)
jle 0x4cf4
movl 0x2d1c(%rbp), %eax
xorl %ebx, %ebx
leaq 0x60(%rsp), %r14
leaq 0xa8(%rsp), %r15
leaq 0x20(%rsp), %r12
movslq %eax, %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x5a6a
movq 0x48(%rsp), %rax
leaq (%rbx,%rbx,2), %r13
movq 0x10(%rax,%r13,8), %rcx
movaps 0x60(%rsp), %xmm0
movups (%rax,%r13,8), %xmm1
movups %xmm0, (%rax,%r13,8)
movq 0x70(%rsp), %rdx
movq %rdx, 0x10(%rax,%r13,8)
movaps %xmm1, 0x20(%rsp)
movq %rcx, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq %r12, %rdi
callq 0x5ae8
movq %r14, %rdi
callq 0x5ae8
movslq 0x2d1c(%rbp), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x5a6a
movq 0x3048(%rbp), %rax
movq 0x10(%rax,%r13,8), %rcx
movapd 0x60(%rsp), %xmm0
movupd (%rax,%r13,8), %xmm1
movupd %xmm0, (%rax,%r13,8)
movq 0x70(%rsp), %rdx
movq %rdx, 0x10(%rax,%r13,8)
movapd %xmm1, 0x20(%rsp)
movq %rcx, 0x30(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq %r12, %rdi
callq 0x5ae8
movq %r14, %rdi
callq 0x5ae8
movl 0x2d1c(%rbp), %eax
testl %eax, %eax
jle 0x4ce6
movq %rbx, (%rsp)
movq %rbp, %rcx
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x2d20(%rcx), %rax
movslq (%rax,%r15,4), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x588e
movq 0x48(%rsp), %rax
movq (%rax,%r13,8), %rax
movq (%rax,%rbp), %rdi
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%rax,%rbp)
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rax,%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %rdi, %rdi
je 0x4c50
callq 0x3310
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4c50
callq 0x3310
movq 0x18(%rsp), %rbx
movq 0x2d20(%rbx), %rax
movslq (%rax,%r15,4), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x588e
movq 0x3048(%rbx), %rax
movq (%rax,%r13,8), %rax
movq (%rax,%rbp), %rdi
movapd 0x20(%rsp), %xmm0
movupd %xmm0, (%rax,%rbp)
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rax,%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %rdi, %rdi
je 0x4cbb
callq 0x3310
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4cbb
callq 0x3310
incq %r15
movq 0x18(%rsp), %rcx
movslq 0x2d1c(%rcx), %rax
addq $0x18, %rbp
cmpq %rax, %r15
jl 0x4bf0
movq %rcx, %rbp
movq (%rsp), %rbx
leaq 0xa8(%rsp), %r15
incq %rbx
cmpq 0x8(%rsp), %rbx
jne 0x4b0e
xorpd %xmm0, %xmm0
callq 0x3290
movsd %xmm0, 0x3040(%rbp)
cmpl $0x0, 0x2c34(%rbp)
movq 0x8(%rsp), %r8
jle 0x5695
xorl %eax, %eax
movq %rax, 0xd8(%rsp)
cmpl $0x0, 0x10(%rsp)
jle 0x4e0e
movl 0x2d1c(%rbp), %eax
xorl %r14d, %r14d
testl %eax, %eax
jle 0x4e02
leaq (%r14,%r14,2), %r15
xorl %r12d, %r12d
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x2d20(%rbp), %rax
cmpl $0x0, (%rax,%r12,4)
jle 0x4dea
movsd %xmm0, (%rsp)
leaq (%r12,%r12,2), %r13
xorl %ebx, %ebx
movsd 0x31296(%rip), %xmm0    # 0x36008
movsd 0x31296(%rip), %xmm1    # 0x36010
callq 0x1d178
callq 0x3290
movapd %xmm0, %xmm1
movq 0x48(%rsp), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r13,8), %rax
movsd %xmm0, (%rax,%rbx,8)
movsd (%rsp), %xmm0
callq 0x1a75d
movsd %xmm0, (%rsp)
incq %rbx
movq 0x2d20(%rbp), %rax
movslq (%rax,%r12,4), %rax
cmpq %rax, %rbx
jl 0x4d6a
testl %eax, %eax
movsd (%rsp), %xmm1
jle 0x4dea
movq 0x48(%rsp), %rcx
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r13,8), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x4dd4
incq %r12
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r12
jl 0x4d44
movq 0x8(%rsp), %r8
incq %r14
cmpq %r8, %r14
jne 0x4d35
cmpl $0x0, 0x2c38(%rbp)
jle 0x533c
xorl %eax, %eax
movl %eax, 0x8c(%rsp)
movl 0x2d18(%rbp), %eax
testl %eax, %eax
jle 0x5089
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
cmpl $0x0, 0x10(%rsp)
jle 0x4e6f
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x8(%rsp), %r8
movq 0x90(%rsp), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
cmpq %rbx, %r8
jne 0x4e44
movl 0x2d1c(%rbp), %ecx
testl %ecx, %ecx
jle 0x5076
movq 0x2cd0(%rbp), %rax
movq $0x0, 0x80(%rsp)
cmpl $0x0, (%rax,%r14,4)
jle 0x5057
movslq %r12d, %r12
xorl %r13d, %r13d
incq %r12
movq 0x2d00(%rbp), %rax
movq %r14, %r15
leaq (%r14,%r14,2), %rbp
movq (%rax,%rbp,8), %rax
movq 0x80(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, (%rax,%r13,4)
je 0x4f85
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x8(%rsp), %r8
cmpl $0x0, 0x10(%rsp)
jle 0x5032
xorl %ebx, %ebx
movq 0x48(%rsp), %rax
leaq (%rbx,%rbx,2), %rcx
movq (%rax,%rcx,8), %rax
movq 0x80(%rsp), %rcx
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x18(%rsp), %rdx
movq 0x2d00(%rdx), %rdx
movq (%rdx,%rbp,8), %rdx
movq (%rdx,%rcx), %rdx
movslq (%rdx,%r13,4), %rdx
movq (%rax,%rcx), %rax
movsd -0x8(%rax,%rdx,8), %xmm1
movq 0xc0(%rsp), %rax
leaq (%r12,%r12,2), %r14
movq (%rax,%r14,8), %rax
movsd %xmm1, (%rax,%rbx,8)
callq 0x1a75d
incq %rbx
movq 0x8(%rsp), %r8
cmpq %r8, %rbx
jne 0x4eec
cmpl $0x0, 0x10(%rsp)
jle 0x5032
movq 0xc0(%rsp), %rax
movq (%rax,%r14,8), %rax
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r8
jne 0x4f6f
cmpl $0x0, 0x10(%rsp)
jle 0x5032
movq 0x90(%rsp), %rax
movq (%rax,%rbp,8), %rax
xorl %ebx, %ebx
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0xc0(%rsp), %rax
leaq (%r12,%r12,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rsp)
movq 0x18(%rsp), %r14
xorps %xmm0, %xmm0
cvtsi2sdl 0x2d1c(%r14), %xmm0
callq 0x3290
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x2cd0(%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r15,4), %xmm0
callq 0x3290
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
callq 0x1a75d
movq 0x90(%rsp), %rax
movq (%rax,%rbp,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x8(%rsp), %r8
cmpq %rbx, %r8
jne 0x4f9e
incq %r13
movq 0x18(%rsp), %rbp
movq 0x2cd0(%rbp), %rax
movq %r15, %r14
movslq (%rax,%r15,4), %rcx
cmpq %rcx, %r13
jl 0x4ea1
movl 0x2d1c(%rbp), %ecx
movq 0x80(%rsp), %rdi
incq %rdi
movslq %ecx, %rdx
movq %rdi, 0x80(%rsp)
cmpq %rdx, %rdi
jl 0x4e90
incq %r14
movslq 0x2d18(%rbp), %rax
cmpq %rax, %r14
jl 0x4e3b
cmpl $0x0, 0x10(%rsp)
jle 0x510a
movl 0x2d1c(%rbp), %eax
xorl %r14d, %r14d
testl %eax, %eax
jle 0x50fc
movq 0x2d20(%rbp), %rcx
xorl %r15d, %r15d
cmpl $0x0, (%rcx,%r15,4)
jle 0x50f1
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x48(%rsp), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x2d20(%rbp), %rcx
movslq (%rcx,%r15,4), %rax
cmpq %rax, %rbx
jl 0x50b0
movl 0x2d1c(%rbp), %eax
movq 0x8(%rsp), %r8
incq %r15
movslq %eax, %rdx
cmpq %rdx, %r15
jl 0x50a7
incq %r14
cmpq %r8, %r14
jne 0x5099
movl 0x2d18(%rbp), %eax
testl %eax, %eax
jle 0x526e
movl 0x2d1c(%rbp), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, (%rsp)
xorl %r9d, %r9d
testl %ecx, %ecx
jle 0x525f
movq 0x2cd0(%rbp), %rax
xorl %r12d, %r12d
movq %r9, 0x40(%rsp)
cmpl $0x0, (%rax,%r9,4)
jle 0x524a
movq (%rsp), %rcx
movslq %ecx, %rcx
movq %rcx, (%rsp)
movq 0x2d00(%rbp), %rcx
xorl %r13d, %r13d
cmpl $0x0, 0x10(%rsp)
setle %sil
incq (%rsp)
leaq (%r9,%r9,2), %rbp
movq (%rcx,%rbp,8), %rdx
leaq (%r12,%r12,2), %r15
movq (%rdx,%r15,8), %rdx
movl (%rdx,%r13,4), %edx
testl %edx, %edx
sete %dil
orb %sil, %dil
jne 0x522f
movq 0x48(%rsp), %rax
xorl %ebx, %ebx
leaq (%rbx,%rbx,2), %r14
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rax
movslq %edx, %rcx
movsd -0x8(%rax,%rcx,8), %xmm0
movq 0x90(%rsp), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%rbx,8), %xmm1
movq 0xc0(%rsp), %rax
movq (%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
addsd (%rax,%rbx,8), %xmm1
callq 0x1a75d
movq 0x48(%rsp), %rax
movq (%rax,%r14,8), %rsi
leaq (,%r12,8), %rcx
leaq (%rcx,%rcx,2), %rdi
movq 0x18(%rsp), %rcx
movq 0x2d00(%rcx), %rcx
movq (%rcx,%rbp,8), %rdx
movq (%rdx,%rdi), %rdx
movslq (%rdx,%r13,4), %rdx
movq (%rsi,%rdi), %rsi
movsd %xmm0, -0x8(%rsi,%rdx,8)
incq %rbx
movq 0x8(%rsp), %r8
cmpq %r8, %rbx
jne 0x5192
movq 0x18(%rsp), %rax
movq 0x2cd0(%rax), %rax
movq 0x40(%rsp), %r9
incq %r13
movslq (%rax,%r9,4), %rdx
cmpq %rdx, %r13
jl 0x515b
movq 0x18(%rsp), %rbp
movl 0x2d1c(%rbp), %ecx
incq %r12
movslq %ecx, %rdx
cmpq %rdx, %r12
jl 0x513b
movl 0x2d18(%rbp), %eax
incq %r9
movslq %eax, %rdx
cmpq %rdx, %r9
jl 0x5124
cmpl $0x0, 0x10(%rsp)
jle 0x5327
movl 0x2d1c(%rbp), %eax
xorl %r14d, %r14d
testl %eax, %eax
jle 0x531b
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x2d20(%rbp), %rax
cmpl $0x0, (%rax,%r15,4)
jle 0x5303
xorl %r12d, %r12d
movq 0x48(%rsp), %rax
leaq (%r14,%r14,2), %rbx
movq (%rax,%rbx,8), %rax
leaq (%r15,%r15,2), %r13
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm1
callq 0x1a75d
incq %r12
movq 0x2d20(%rbp), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %r12
jl 0x52a7
testl %eax, %eax
jle 0x5303
movq 0x48(%rsp), %rcx
movq (%rcx,%rbx,8), %rcx
movq (%rcx,%r13,8), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x52ed
incq %r15
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r15
jl 0x528d
movq 0x8(%rsp), %r8
incq %r14
cmpq %r8, %r14
jne 0x5282
movl 0x8c(%rsp), %eax
incl %eax
cmpl 0x2c38(%rbp), %eax
jl 0x4e1d
movl 0x2d18(%rbp), %eax
xorpd %xmm0, %xmm0
testl %eax, %eax
jle 0x555e
xorl %r14d, %r14d
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x8(%rsp), %r8
cmpl $0x0, 0x10(%rsp)
jle 0x5423
xorl %r15d, %r15d
movslq 0x2d1c(%rbp), %rax
testq %rax, %rax
movsd %xmm0, (%rsp)
jle 0x53e6
movq 0x2cd0(%rbp), %rcx
movl (%rcx,%r14,4), %ecx
leaq (%r14,%r14,2), %rdx
shlq $0x3, %rdx
addq 0x2d00(%rbp), %rdx
leaq (%r15,%r15,2), %rsi
shlq $0x3, %rsi
addq 0x48(%rsp), %rsi
xorpd %xmm0, %xmm0
xorl %edi, %edi
testl %ecx, %ecx
jle 0x53dc
movq (%rdx), %r9
leaq (%rdi,%rdi,2), %r8
movq (%r9,%r8,8), %r9
xorl %r10d, %r10d
movslq (%r9,%r10,4), %r11
testq %r11, %r11
je 0x53d4
movq (%rsi), %rbx
movq (%rbx,%r8,8), %rbx
addsd -0x8(%rbx,%r11,8), %xmm0
incq %r10
cmpq %r10, %rcx
jne 0x53bd
incq %rdi
cmpq %rax, %rdi
jne 0x53ab
jmp 0x53ea
xorpd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0xe0(%rsp), %xmm0
callq 0x3290
movsd 0x40(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd (%rsp), %xmm0
callq 0x1a75d
incq %r15
movq 0x8(%rsp), %r8
cmpq %r8, %r15
jne 0x536d
incq %r14
movslq 0x2d18(%rbp), %rax
cmpq %rax, %r14
jl 0x5351
testl %eax, %eax
jle 0x555a
movl 0x2d1c(%rbp), %ecx
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
testl %ecx, %ecx
jle 0x5549
movl 0x2ba4(%rbp), %eax
xorl %r15d, %r15d
testl %eax, %eax
jle 0x5534
xorl %r12d, %r12d
movq 0x2d00(%rbp), %rcx
leaq (%r14,%r14,2), %rdx
movq (%rcx,%rdx,8), %rcx
leaq (%r15,%r15,2), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl $0x0, (%rcx,%r12,4)
je 0x551f
movsd %xmm0, (%rsp)
xorpd %xmm0, %xmm0
callq 0x3290
cmpl $0x0, 0x10(%rsp)
jle 0x5507
xorl %ebx, %ebx
movq 0x90(%rsp), %rax
leaq (,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%rbx,8), %xmm1
movq 0x48(%rsp), %rax
leaq (%rbx,%rbx,2), %rdx
movq (%rax,%rdx,8), %rax
leaq (,%r15,8), %rdx
leaq (%rdx,%rdx,2), %rdx
movq 0x2d00(%rbp), %rsi
movq (%rsi,%rcx), %rcx
movq (%rcx,%rdx), %rcx
movslq (%rcx,%r12,4), %rcx
movq (%rax,%rdx), %rax
addsd -0x8(%rax,%rcx,8), %xmm1
callq 0x1a75d
incq %rbx
movq 0x8(%rsp), %r8
cmpq %r8, %rbx
jne 0x54a0
jmp 0x550c
movq 0x8(%rsp), %r8
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movl 0x2ba4(%rbp), %eax
incq %r12
movslq %eax, %rcx
cmpq %rcx, %r12
jl 0x5467
movl 0x2d1c(%rbp), %ecx
incq %r15
movslq %ecx, %rdx
cmpq %rdx, %r15
jl 0x545c
movl 0x2d18(%rbp), %eax
incq %r14
movslq %eax, %rdx
cmpq %rdx, %r14
jl 0x544b
jmp 0x555e
xorpd %xmm0, %xmm0
ucomisd 0x3040(%rbp), %xmm0
jbe 0x567f
movsd %xmm0, 0x3040(%rbp)
cmpl $0x0, 0x10(%rsp)
jle 0x561d
movl 0x2d1c(%rbp), %eax
xorl %r14d, %r14d
testl %eax, %eax
jle 0x560b
movq 0x2d20(%rbp), %rcx
xorl %r15d, %r15d
cmpl $0x0, (%rcx,%r15,4)
jle 0x5600
xorl %ebx, %ebx
movq 0x48(%rsp), %rax
leaq (,%r14,8), %rcx
leaq (%rcx,%rcx,2), %r12
movq (%rax,%r12), %rax
leaq (,%r15,8), %rcx
leaq (%rcx,%rcx,2), %r13
movq (%rax,%r13), %rax
movsd (%rax,%rbx,8), %xmm0
callq 0x35a0
movq 0x3048(%rbp), %rax
movq (%rax,%r12), %rax
movq (%rax,%r13), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x2d20(%rbp), %rcx
movslq (%rcx,%r15,4), %rax
cmpq %rax, %rbx
jl 0x559f
movl 0x2d1c(%rbp), %eax
movq 0x8(%rsp), %r8
incq %r15
movslq %eax, %rdx
cmpq %rdx, %r15
jl 0x5596
incq %r14
cmpq %r8, %r14
jne 0x5588
movl 0x2d18(%rbp), %eax
testl %eax, %eax
jle 0x567f
xorl %ebx, %ebx
cmpl $0x0, 0x10(%rsp)
jle 0x5674
xorl %r14d, %r14d
movq 0x90(%rsp), %rax
leaq (,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %r15
movq (%rax,%r15), %rax
movsd (%rax,%r14,8), %xmm0
callq 0x35a0
movq 0x8(%rsp), %r8
movq 0x3060(%rbp), %rax
movq (%rax,%r15), %rax
movsd %xmm0, (%rax,%r14,8)
incq %r14
cmpq %r14, %r8
jne 0x562d
movl 0x2d18(%rbp), %eax
incq %rbx
movslq %eax, %rcx
cmpq %rcx, %rbx
jl 0x5623
movq 0xd8(%rsp), %rax
incl %eax
cmpl 0x2c34(%rbp), %eax
jl 0x4d19
cmpb $0x0, 0x2c49(%rbp)
je 0x57c2
movq 0x2d20(%rbp), %rax
movq 0x2d28(%rbp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0x56d2
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %edx, %edx
addl (%rax,%rsi,4), %edx
incq %rsi
cmpq %rsi, %rcx
jne 0x56c5
jmp 0x56d4
xorl %edx, %edx
subl 0x2d1c(%rbp), %edx
movq 0x10(%rsp), %rcx
imull %ecx, %edx
decl %ecx
imull 0x2d18(%rbp), %ecx
addl %edx, %ecx
leal (%rcx,%rcx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x3040(%rbp), %xmm1
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movslq 0x88(%rsp), %rbx
movq 0x3078(%rbp), %rax
leaq (,%rbx,8), %r14
movsd %xmm0, (%rax,%rbx,8)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x2d50(%rbp), %xmm0
callq 0x3290
movsd 0x3040(%rbp), %xmm1
mulsd (%rsp), %xmm0
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movq 0x3090(%rbp), %rax
movsd %xmm0, (%rax,%rbx,8)
movq 0x2e60(%rbp), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx), %rax
movsd (%rax), %xmm0
movsd 0x3040(%rbp), %xmm1
addsd %xmm1, %xmm1
mulsd 0x30899(%rip), %xmm0    # 0x36020
addsd %xmm1, %xmm0
movq 0x30a8(%rbp), %rdx
movsd %xmm0, (%rdx,%rbx,8)
movsd (%rax), %xmm0
movq 0x2e78(%rbp), %rax
movq (%rax,%rcx), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm1
addsd %xmm0, %xmm0
subsd %xmm0, %xmm1
movq 0x30c0(%rbp), %rax
movsd %xmm1, (%rax,%rbx,8)
leaq 0x90(%rsp), %rdi
callq 0x5ae8
leaq 0x48(%rsp), %rdi
callq 0x5a2a
leaq 0xc0(%rsp), %rdi
callq 0x5ae8
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x5861
callq 0x3310
jmp 0x5861
jmp 0x585e
jmp 0x585e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x586e
callq 0x3310
jmp 0x586e
movq %rax, %rbx
jmp 0x586e
movq %rax, %rbx
jmp 0x5878
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x5885
callq 0x3310
jmp 0x5885
movq %rax, %rbx
jmp 0x5885
jmp 0x585e
jmp 0x585e
jmp 0x585e
jmp 0x585e
jmp 0x585e
jmp 0x585e
jmp 0x585e
jmp 0x585e
jmp 0x585e
jmp 0x585e
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x5ae8
leaq 0x48(%rsp), %rdi
callq 0x5a2a
leaq 0xc0(%rsp), %rdi
callq 0x5ae8
movq %rbx, %rdi
callq 0x3580
nop