// File: /workspace/github_cpp_makefile_star2_O1/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
addl %esi, %eax
movq %rax, 0x8(%rsp)
movq 0x2cd0(%rdi), %rax
movq 0x2cd8(%rdi), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
movl %esi, 0x54(%rsp)
jle 0x493b
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
xorl %ebx, %ebx
addl (%rax,%rdx,4), %ebx
incq %rdx
cmpq %rdx, %rcx
jne 0x492e
jmp 0x493d
xorl %ebx, %ebx
movslq 0x2d1c(%rbp), %r15
movslq 0x8(%rsp), %r14
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0xe0(%rsp)
callq 0x3290
xorpd 0x326dc(%rip), %xmm0    # 0x37040
leaq 0x58(%rsp), %rdx
movlpd %xmm0, (%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rcx
movq %r14, %rsi
callq 0x5bba
movslq %ebx, %rax
imulq %rax, %r15
leaq 0xc0(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0x70(%rsp), %rcx
movq %r15, %rsi
callq 0x59a0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x49b2
callq 0x3310
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq %r14, %rsi
callq 0x5a30
movslq 0x2d18(%rbp), %r15
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r14, %rsi
callq 0x5916
leaq 0x90(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0xa8(%rsp), %rcx
movq %r15, %rsi
callq 0x59a0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4a09
callq 0x3310
leaq 0x70(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
movq %r14, %rsi
callq 0x5a30
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movupd 0x3048(%rbp), %xmm0
movq 0x3058(%rbp), %rax
leaq 0x70(%rsp), %r15
movaps (%r15), %xmm1
movups %xmm1, 0x3048(%rbp)
movq 0x10(%r15), %rcx
movq %rcx, 0x3058(%rbp)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movapd (%rdi), %xmm1
movapd %xmm0, (%rdi)
movapd %xmm1, (%r15)
movq %rcx, 0x10(%r15)
callq 0x5ab8
movq %r15, %rdi
callq 0x5ab8
movslq 0x2d18(%rbp), %r15
leaq 0xa8(%rsp), %rdi
leaq 0x3f(%rsp), %rdx
movq %r14, %rsi
callq 0x5916
leaq 0x70(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
leaq 0x3e(%rsp), %rcx
movq %r15, %rsi
callq 0x59a0
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movupd 0x3060(%rbp), %xmm0
movq 0x3070(%rbp), %rax
leaq 0x70(%rsp), %r14
movaps (%r14), %xmm1
movups %xmm1, 0x3060(%rbp)
movq 0x10(%r14), %rcx
movq %rcx, 0x3070(%rbp)
movq 0x10(%rdi), %rcx
movq %rax, 0x10(%rdi)
movapd (%rdi), %xmm1
movapd %xmm0, (%rdi)
movapd %xmm1, (%r14)
movq %rcx, 0x10(%r14)
callq 0x5b7a
movq %r14, %rdi
callq 0x5b7a
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x4b30
callq 0x3310
movq 0x8(%rsp), %rax
movl %eax, %r15d
testl %eax, %eax
movq %rbp, 0x48(%rsp)
movq %r15, 0x28(%rsp)
jle 0x4da2
xorl %ebx, %ebx
leaq 0x70(%rsp), %r14
leaq 0xa8(%rsp), %r13
leaq 0x10(%rsp), %r12
movslq 0x2d1c(%rbp), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x5af2
movq 0x58(%rsp), %rax
movq %rbx, (%rsp)
leaq (%rbx,%rbx,2), %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movups (%rax,%r15,8), %xmm0
movq 0x10(%rax,%r15,8), %rcx
movaps 0x70(%rsp), %xmm1
movups %xmm1, (%rax,%r15,8)
movq 0x80(%rsp), %rdx
movq %rdx, 0x10(%rax,%r15,8)
movq 0x20(%rsp), %rax
movq %rcx, 0x20(%rsp)
movaps 0x10(%rsp), %xmm1
movaps %xmm0, 0x10(%rsp)
movaps %xmm1, 0x70(%rsp)
movq %rax, 0x80(%rsp)
movq %r12, %rdi
callq 0x5b7a
movq %r14, %rdi
callq 0x5b7a
movslq 0x2d1c(%rbp), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x5af2
movq 0x3048(%rbp), %rax
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movupd (%rax,%r15,8), %xmm0
movq 0x10(%rax,%r15,8), %rcx
movaps 0x70(%rsp), %xmm1
movups %xmm1, (%rax,%r15,8)
movq 0x80(%rsp), %rdx
movq %rdx, 0x10(%rax,%r15,8)
movq 0x20(%rsp), %rax
movq %rcx, 0x20(%rsp)
movapd 0x10(%rsp), %xmm1
movapd %xmm0, 0x10(%rsp)
movapd %xmm1, 0x70(%rsp)
movq %rax, 0x80(%rsp)
movq %r12, %rdi
callq 0x5b7a
movq %r14, %rdi
callq 0x5b7a
cmpl $0x0, 0x2d1c(%rbp)
movq %rbp, %rcx
jle 0x4d82
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x2d20(%rcx), %rax
movslq (%rax,%rbp,4), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x5916
movq 0x58(%rsp), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r13), %rdi
movaps 0x10(%rsp), %xmm0
movups 0x8(%rax,%r13), %xmm1
movups %xmm0, (%rax,%r13)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax,%r13)
movq %rdi, 0x10(%rsp)
movups %xmm1, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x4cd9
callq 0x3310
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4ce8
callq 0x3310
movq 0x48(%rsp), %rbx
movq 0x2d20(%rbx), %rax
movslq (%rax,%rbp,4), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x5916
movq 0x3048(%rbx), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r13), %rdi
movapd 0x10(%rsp), %xmm0
movupd 0x8(%rax,%r13), %xmm1
movupd %xmm0, (%rax,%r13)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax,%r13)
movq %rdi, 0x10(%rsp)
movupd %xmm1, 0x18(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0x4d57
callq 0x3310
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4d66
callq 0x3310
incq %rbp
movq 0x48(%rsp), %rcx
movslq 0x2d1c(%rcx), %rax
addq $0x18, %r13
cmpq %rax, %rbp
jl 0x4c77
movq (%rsp), %rbx
incq %rbx
movq 0x28(%rsp), %r15
cmpq %r15, %rbx
movq %rcx, %rbp
leaq 0xa8(%rsp), %r13
jne 0x4b5e
xorpd %xmm0, %xmm0
callq 0x3290
movsd %xmm0, 0x3040(%rbp)
cmpl $0x0, 0x2c34(%rbp)
jle 0x571b
xorl %eax, %eax
movq %rax, 0xd8(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x4eb5
xorl %r14d, %r14d
cmpl $0x0, 0x2d1c(%rbp)
jle 0x4ea4
leaq (%r14,%r14,2), %r15
xorl %r12d, %r12d
xorpd %xmm0, %xmm0
callq 0x3290
movsd %xmm0, (%rsp)
movq 0x2d20(%rbp), %rax
movl (%rax,%r12,4), %eax
leaq (%r12,%r12,2), %r13
testl %eax, %eax
jle 0x4e61
xorl %ebx, %ebx
movsd 0x321f1(%rip), %xmm0    # 0x37008
movsd 0x321f1(%rip), %xmm1    # 0x37010
callq 0x1d4cc
callq 0x3290
movapd %xmm0, %xmm1
movq 0x58(%rsp), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r13,8), %rax
movsd %xmm0, (%rax,%rbx,8)
movsd (%rsp), %xmm0
callq 0x1aa59
movsd %xmm0, (%rsp)
incq %rbx
movq 0x2d20(%rbp), %rax
movslq (%rax,%r12,4), %rax
cmpq %rax, %rbx
jl 0x4e0f
testl %eax, %eax
movsd (%rsp), %xmm1
jle 0x4e91
movq 0x58(%rsp), %rcx
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r13,8), %rcx
movl %eax, %eax
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x4e7b
incq %r12
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r12
jl 0x4dec
incq %r14
movq 0x28(%rsp), %r15
cmpq %r15, %r14
jne 0x4dd8
cmpl $0x0, 0x2c38(%rbp)
jle 0x53dc
xorl %eax, %eax
movl %eax, 0x8c(%rsp)
cmpl $0x0, 0x2d18(%rbp)
jle 0x5104
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
cmpl $0x0, 0x8(%rsp)
jle 0x4f10
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x90(%rsp), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
cmpq %rbx, %r15
jne 0x4eea
cmpl $0x0, 0x2d1c(%rbp)
jle 0x50f1
movq $0x0, 0x40(%rsp)
movq 0x2cd0(%rbp), %rax
cmpl $0x0, (%rax,%r14,4)
jle 0x50d4
movslq %r12d, %r12
xorl %r13d, %r13d
incq %r12
movq 0x2d00(%rbp), %rax
leaq (%r14,%r14,2), %rbp
movq (%rax,%rbp,8), %rax
movq 0x40(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, (%rax,%r13,4)
je 0x500b
xorpd %xmm0, %xmm0
callq 0x3290
cmpl $0x0, 0x8(%rsp)
jle 0x4fdc
xorl %ebx, %ebx
movq 0x58(%rsp), %rax
leaq (%rbx,%rbx,2), %rcx
movq (%rax,%rcx,8), %rax
movq 0x40(%rsp), %rcx
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x48(%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), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm1, (%rax,%rbx,8)
callq 0x1aa59
incq %rbx
cmpq %r15, %rbx
jne 0x4f7a
cmpl $0x0, 0x8(%rsp)
jle 0x500b
movq 0xc0(%rsp), %rax
leaq (%r12,%r12,2), %rcx
movq (%rax,%rcx,8), %rax
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r15
jne 0x4ff5
cmpl $0x0, 0x8(%rsp)
jle 0x50b8
xorl %ebx, %ebx
movq 0x90(%rsp), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xc0(%rsp), %rax
leaq (%r12,%r12,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rsp)
movq 0x48(%rsp), %r15
xorps %xmm0, %xmm0
cvtsi2sdl 0x2d1c(%r15), %xmm0
callq 0x3290
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x2cd0(%r15), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r14,4), %xmm0
callq 0x3290
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
callq 0x1aa59
movq 0x90(%rsp), %rax
movq (%rax,%rbp,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x28(%rsp), %r15
cmpq %rbx, %r15
jne 0x5018
incq %r13
movq 0x48(%rsp), %rbp
movq 0x2cd0(%rbp), %rax
movslq (%rax,%r14,4), %rax
cmpq %rax, %r13
jl 0x4f3e
movq 0x40(%rsp), %rdx
incq %rdx
movslq 0x2d1c(%rbp), %rax
movq %rdx, 0x40(%rsp)
cmpq %rax, %rdx
jl 0x4f26
incq %r14
movslq 0x2d18(%rbp), %rax
cmpq %rax, %r14
jl 0x4ee1
cmpl $0x0, 0x8(%rsp)
jle 0x517c
xorl %r14d, %r14d
cmpl $0x0, 0x2d1c(%rbp)
jle 0x516f
xorl %ebx, %ebx
movq 0x2d20(%rbp), %rax
cmpl $0x0, (%rax,%rbx,4)
jle 0x5160
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x58(%rsp), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
leaq (%rbx,%rbx,2), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movq 0x2d20(%rbp), %rax
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r15
jl 0x5129
incq %rbx
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %rbx
jl 0x5119
incq %r14
movq 0x28(%rsp), %r15
cmpq %r15, %r14
jne 0x510e
cmpl $0x0, 0x2d18(%rbp)
jle 0x5306
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x30(%rsp)
xorl %esi, %esi
cmpl $0x0, 0x2d1c(%rbp)
jle 0x52f3
movq $0x0, (%rsp)
movq 0x2cd0(%rbp), %rax
cmpl $0x0, (%rax,%rsi,4)
jle 0x52d8
movq 0x30(%rsp), %rax
cltq
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
cmpl $0x0, 0x8(%rsp)
setle %al
incq 0x30(%rsp)
movq 0x2d00(%rbp), %rcx
leaq (%rsi,%rsi,2), %rdx
movq %rdx, 0x40(%rsp)
movq (%rcx,%rdx,8), %rcx
movq (%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl $0x0, (%rcx,%r13,4)
sete %cl
orb %al, %cl
jne 0x52c1
xorl %ebx, %ebx
movq 0x58(%rsp), %rax
leaq (%rbx,%rbx,2), %r15
movq (%rax,%r15,8), %rax
movq (%rsp), %rcx
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %r14
movq 0x2d00(%rbp), %rcx
movq %rsi, %r12
leaq (,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx), %rcx
movq (%rcx,%r14), %rcx
movslq (%rcx,%r13,4), %rcx
movq (%rax,%r14), %rax
movsd -0x8(%rax,%rcx,8), %xmm0
movq 0x90(%rsp), %rax
movq (%rax,%rdx), %rax
movsd (%rax,%rbx,8), %xmm1
movq 0xc0(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
addsd (%rax,%rbx,8), %xmm1
callq 0x1aa59
movq 0x58(%rsp), %rax
movq (%rax,%r15,8), %rax
movq 0x2d00(%rbp), %rcx
movq 0x40(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%r14), %rcx
movslq (%rcx,%r13,4), %rcx
movq (%rax,%r14), %rax
movsd %xmm0, -0x8(%rax,%rcx,8)
incq %rbx
movq 0x28(%rsp), %r15
cmpq %r15, %rbx
movq %r12, %rsi
jne 0x5209
incq %r13
movq 0x2cd0(%rbp), %rax
movslq (%rax,%rsi,4), %rax
cmpq %rax, %r13
jl 0x51ca
movq (%rsp), %rdx
incq %rdx
movslq 0x2d1c(%rbp), %rax
movq %rdx, (%rsp)
cmpq %rax, %rdx
jl 0x51aa
incq %rsi
movslq 0x2d18(%rbp), %rax
cmpq %rax, %rsi
jl 0x5195
cmpl $0x0, 0x8(%rsp)
jle 0x53c7
xorl %r14d, %r14d
cmpl $0x0, 0x2d1c(%rbp)
jle 0x53b6
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x2d20(%rbp), %rax
movl (%rax,%r15,4), %eax
testl %eax, %eax
jle 0x5370
xorl %ebx, %ebx
movq 0x58(%rsp), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%rbx,8), %xmm1
callq 0x1aa59
incq %rbx
movq 0x2d20(%rbp), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %rbx
jl 0x533e
testl %eax, %eax
jle 0x53a3
movq 0x58(%rsp), %rcx
leaq (%r14,%r14,2), %rdx
movq (%rcx,%rdx,8), %rcx
leaq (%r15,%r15,2), %rdx
movq (%rcx,%rdx,8), %rcx
movl %eax, %eax
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x538d
incq %r15
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r15
jl 0x5324
incq %r14
movq 0x28(%rsp), %r15
cmpq %r15, %r14
jne 0x5314
movl 0x8c(%rsp), %eax
incl %eax
cmpl 0x2c38(%rbp), %eax
jl 0x4ec4
cmpl $0x0, 0x2d18(%rbp)
jle 0x54c9
xorl %r14d, %r14d
xorpd %xmm0, %xmm0
callq 0x3290
cmpl $0x0, 0x8(%rsp)
jle 0x54b6
xorl %r15d, %r15d
movslq 0x2d1c(%rbp), %rax
testq %rax, %rax
movsd %xmm0, (%rsp)
jle 0x547c
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 0x58(%rsp), %rsi
xorpd %xmm0, %xmm0
xorl %edi, %edi
testl %ecx, %ecx
jle 0x5472
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 0x546a
movq (%rsi), %rbx
movq (%rbx,%r8,8), %rbx
addsd -0x8(%rbx,%r11,8), %xmm0
incq %r10
cmpq %r10, %rcx
jne 0x5453
incq %rdi
cmpq %rax, %rdi
jne 0x5441
jmp 0x5480
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0xe0(%rsp), %xmm0
callq 0x3290
movsd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd (%rsp), %xmm0
callq 0x1aa59
incq %r15
cmpq 0x28(%rsp), %r15
jne 0x5403
incq %r14
movslq 0x2d18(%rbp), %rax
cmpq %rax, %r14
jl 0x53ec
cmpl $0x0, 0x2d18(%rbp)
jle 0x55e0
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
cmpl $0x0, 0x2d1c(%rbp)
jle 0x55cb
xorl %r15d, %r15d
cmpl $0x0, 0x2ba4(%rbp)
jle 0x55b8
xorl %r12d, %r12d
movq 0x2d00(%rbp), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, (%rax,%r12,4)
je 0x55a5
movsd %xmm0, (%rsp)
xorpd %xmm0, %xmm0
callq 0x3290
cmpl $0x0, 0x8(%rsp)
jle 0x5598
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 0x58(%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 0x1aa59
incq %rbx
cmpq 0x28(%rsp), %rbx
jne 0x5536
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
incq %r12
movslq 0x2ba4(%rbp), %rax
cmpq %rax, %r12
jl 0x54fd
incq %r15
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r15
jl 0x54ed
incq %r14
movslq 0x2d18(%rbp), %rax
cmpq %rax, %r14
jl 0x54dd
jmp 0x55e4
xorpd %xmm0, %xmm0
ucomisd 0x3040(%rbp), %xmm0
movq 0x28(%rsp), %r15
jbe 0x5705
movsd %xmm0, 0x3040(%rbp)
cmpl $0x0, 0x8(%rsp)
jle 0x56a0
xorl %r14d, %r14d
cmpl $0x0, 0x2d1c(%rbp)
jle 0x568f
xorl %ebx, %ebx
movq 0x2d20(%rbp), %rax
cmpl $0x0, (%rax,%rbx,4)
jle 0x5680
xorl %r15d, %r15d
movq 0x58(%rsp), %rax
leaq (,%r14,8), %rcx
leaq (%rcx,%rcx,2), %r12
movq (%rax,%r12), %rax
leaq (,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %r13
movq (%rax,%r13), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x35a0
movq 0x3048(%rbp), %rax
movq (%rax,%r12), %rax
movq (%rax,%r13), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movq 0x2d20(%rbp), %rax
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r15
jl 0x5628
incq %rbx
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %rbx
jl 0x5618
incq %r14
movq 0x28(%rsp), %r15
cmpq %r15, %r14
jne 0x560d
cmpl $0x0, 0x2d18(%rbp)
jle 0x5705
xorl %ebx, %ebx
cmpl $0x0, 0x8(%rsp)
jle 0x56f6
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 0x3060(%rbp), %rax
movq (%rax,%r15), %rax
movq 0x28(%rsp), %r15
movsd %xmm0, (%rax,%r14,8)
incq %r14
cmpq %r14, %r15
jne 0x56b5
incq %rbx
movslq 0x2d18(%rbp), %rax
cmpq %rax, %rbx
jl 0x56ab
movq 0xd8(%rsp), %rax
incl %eax
cmpl 0x2c34(%rbp), %eax
jl 0x4dc2
cmpb $0x0, 0x2c49(%rbp)
je 0x584b
movq 0x2d20(%rbp), %rax
movq 0x2d28(%rbp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
jle 0x575c
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %edx, %edx
movl 0x54(%rsp), %edi
addl (%rax,%rsi,4), %edx
incq %rsi
cmpq %rsi, %rcx
jne 0x574f
jmp 0x5762
xorl %edx, %edx
movl 0x54(%rsp), %edi
subl 0x2d1c(%rbp), %edx
movq 0x8(%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 %edi, %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 0x31810(%rip), %xmm0    # 0x37020
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 0x5b7a
leaq 0x58(%rsp), %rdi
callq 0x5ab8
leaq 0xc0(%rsp), %rdi
callq 0x5b7a
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 0x58ea
callq 0x3310
jmp 0x58ea
jmp 0x58e7
jmp 0x58e7
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x58f7
callq 0x3310
jmp 0x58f7
movq %rax, %rbx
jmp 0x58f7
movq %rax, %rbx
jmp 0x5901
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x590e
callq 0x3310
jmp 0x590e
movq %rax, %rbx
jmp 0x590e
jmp 0x58e7
jmp 0x58e7
jmp 0x58e7
jmp 0x58e7
jmp 0x58e7
jmp 0x58e7
jmp 0x58e7
jmp 0x58e7
jmp 0x58e7
jmp 0x58e7
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x5b7a
leaq 0x58(%rsp), %rdi
callq 0x5ab8
leaq 0xc0(%rsp), %rdi
callq 0x5b7a
movq %rbx, %rdi
callq 0x3580