// File: /workspace/github_cpp_makefile_star2_O2/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 $0xf8, %rsp
movq %rdi, %rbx
movl 0x2bc8(%rdi), %r14d
movl %esi, 0x68(%rsp)
addl %esi, %r14d
addq $0x2cd0, %rdi           # imm = 0x2CD0
movq %rdi, 0x90(%rsp)
callq 0x50fb
movl %eax, %ebp
movq %rbx, 0x10(%rsp)
movslq 0x2d1c(%rbx), %r15
movq %r14, 0x88(%rsp)
movslq %r14d, %r12
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0xe8(%rsp)
callq 0x32d0
xorpd 0x22d02(%rip), %xmm0    # 0x27030
leaq 0x70(%rsp), %rdx
movlpd %xmm0, (%rdx)
leaq 0x38(%rsp), %rdi
leaq 0x98(%rsp), %rcx
movq %r12, %rsi
callq 0x5120
movslq %ebp, %rax
imulq %rax, %r15
leaq 0xc8(%rsp), %rdi
leaq 0x38(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
movq %r15, %rsi
callq 0x4fbe
leaq 0x38(%rsp), %rdi
callq 0x51a2
leaq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r12, %rsi
callq 0x5014
movq 0x10(%rsp), %rbx
movslq 0x2d18(%rbx), %r15
leaq 0x98(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
movq %r12, %rsi
callq 0x4f6c
leaq 0x70(%rsp), %rdi
leaq 0x98(%rsp), %rdx
leaq 0xf(%rsp), %rcx
movq %r15, %rsi
callq 0x4fbe
leaq 0x98(%rsp), %rdi
callq 0x51a2
leaq 0x98(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
movq %r12, %rsi
callq 0x5014
leaq 0x3048(%rbx), %rdi
leaq 0x98(%rsp), %r13
movq %rdi, 0x60(%rsp)
movq %r13, %rsi
callq 0x54e6
movq %r13, %rdi
callq 0x5066
movslq 0x2d18(%rbx), %r13
leaq 0xb0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r12, %rsi
callq 0x4f6c
leaq 0x98(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
leaq 0x2f(%rsp), %rcx
movq %r13, %rsi
callq 0x4fbe
leaq 0x3060(%rbx), %rdi
leaq 0x98(%rsp), %rbp
movq %rdi, 0xe0(%rsp)
movq %rbp, %rsi
callq 0x5566
movq %rbp, %rdi
callq 0x50da
leaq 0xb0(%rsp), %r12
movq %r12, %rdi
callq 0x51a2
leaq 0x2d20(%rbx), %r13
xorl %r14d, %r14d
movq 0x88(%rsp), %rax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0x18(%rsp)
movq %r13, 0x30(%rsp)
cmpq 0x18(%rsp), %r14
je 0x45ad
movq 0x10(%rsp), %rbx
movslq 0x2d1c(%rbx), %rsi
movq %rbp, %rdi
movq %r12, %rdx
callq 0x5088
movq %r14, (%rsp)
imulq $0x18, %r14, %r15
movq 0x38(%rsp), %rdi
addq %r15, %rdi
movq %rbp, %rsi
callq 0x5566
movq %rbp, %rdi
callq 0x50da
movslq 0x2d1c(%rbx), %rsi
movq %rbp, %rdi
movq %r12, %rdx
callq 0x5088
movq 0x60(%rsp), %rax
movq (%rax), %rdi
addq %r15, %rdi
movq %rbp, %rsi
callq 0x5566
movq %rbp, %rdi
callq 0x50da
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
movslq 0x2d1c(%rax), %rax
cmpq %rax, %r14
jge 0x459c
movq 0x30(%rsp), %rbx
movq (%rbx), %rax
movslq (%rax,%r14,4), %rsi
movq %rbp, %rdi
movq %r12, %rdx
callq 0x4f6c
movq 0x38(%rsp), %rax
movq (%rax,%r15), %rdi
addq %r13, %rdi
movq %rbp, %rsi
callq 0x55b8
movq %rbp, %rdi
callq 0x51a2
movq (%rbx), %rax
movslq (%rax,%r14,4), %rsi
movq %rbp, %rdi
movq %r12, %rdx
callq 0x4f6c
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r15), %rdi
addq %r13, %rdi
movq %rbp, %rsi
callq 0x55b8
movq %rbp, %rdi
callq 0x51a2
incq %r14
addq $0x18, %r13
jmp 0x451e
movq (%rsp), %r14
incq %r14
movq 0x30(%rsp), %r13
jmp 0x44a9
xorpd %xmm0, %xmm0
callq 0x32d0
movq 0x10(%rsp), %rbp
movsd %xmm0, 0x3040(%rbp)
xorl %eax, %eax
cmpl 0x2c34(%rbp), %eax
jge 0x4dc0
xorl %r14d, %r14d
movl %eax, 0x6c(%rsp)
cmpq 0x18(%rsp), %r14
je 0x46a8
xorl %r15d, %r15d
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r15
jge 0x46a0
xorpd %xmm0, %xmm0
callq 0x32d0
movsd %xmm0, (%rsp)
xorl %ebx, %ebx
movq (%r13), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %rbx
jge 0x465f
movsd 0x229f5(%rip), %xmm0    # 0x27010
movsd 0x229f5(%rip), %xmm1    # 0x27018
callq 0x1707c
callq 0x32d0
movapd %xmm0, %xmm1
movq 0x38(%rsp), %rax
imulq $0x18, %r14, %rcx
movq (%rax,%rcx), %rax
imulq $0x18, %r15, %rcx
movq (%rax,%rcx), %rax
movsd %xmm0, (%rax,%rbx,8)
movsd (%rsp), %xmm0
callq 0x14ce5
movsd %xmm0, (%rsp)
incq %rbx
jmp 0x4606
imulq $0x18, %r14, %rcx
addq 0x38(%rsp), %rcx
testl %eax, %eax
movl $0x0, %edx
cmovlel %edx, %eax
xorl %edx, %edx
cmpq %rdx, %rax
je 0x4698
movq (%rcx), %rsi
imulq $0x18, %r15, %rdi
movq (%rsi,%rdi), %rsi
movsd (%rsi,%rdx,8), %xmm0
subsd (%rsp), %xmm0
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
jmp 0x4674
incq %r15
jmp 0x45e6
incq %r14
jmp 0x45d8
xorl %eax, %eax
cmpl 0x2c38(%rbp), %eax
jge 0x4b0a
movl %eax, 0x54(%rsp)
xorl %r15d, %r15d
pushq $-0x1
popq %rax
movl %eax, %r12d
movq 0x10(%rsp), %rax
movslq 0x2d18(%rax), %rax
cmpq %rax, %r15
jge 0x48c9
xorl %ebx, %ebx
cmpq %rbx, 0x18(%rsp)
je 0x4701
xorpd %xmm0, %xmm0
callq 0x32d0
movq 0x70(%rsp), %rax
imulq $0x18, %r15, %rcx
movq (%rax,%rcx), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
jmp 0x46da
imulq $0x18, %r15, %r14
xorl %ecx, %ecx
movq %r15, %rbp
movq 0x10(%rsp), %rax
movslq 0x2d1c(%rax), %rax
cmpq %rax, %rcx
jge 0x48c1
movslq %r12d, %r12
movq %rcx, 0xf0(%rsp)
imulq $0x18, %rcx, %r13
xorl %ecx, %ecx
movq 0x90(%rsp), %rax
movq (%rax), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %rcx
jge 0x48ac
incq %r12
movq 0x10(%rsp), %rax
movq 0x2d00(%rax), %rax
movq (%rax,%r14), %rax
movq (%rax,%r13), %rax
movq %rcx, 0x58(%rsp)
cmpl $0x0, (%rax,%rcx,4)
je 0x4805
xorpd %xmm0, %xmm0
callq 0x32d0
xorl %ebx, %ebx
xorl %r15d, %r15d
cmpq %r15, 0x18(%rsp)
je 0x47d7
movq 0x38(%rsp), %rax
movq (%rax,%rbx), %rax
movq 0x10(%rsp), %rcx
movq 0x2d00(%rcx), %rcx
movq (%rcx,%r14), %rcx
movq (%rcx,%r13), %rcx
movq 0x58(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movq (%rax,%r13), %rax
movsd -0x8(%rax,%rcx,8), %xmm1
movq 0xc8(%rsp), %rax
imulq $0x18, %r12, %rcx
movq (%rax,%rcx), %rax
movsd %xmm1, (%rax,%r15,8)
callq 0x14ce5
incq %r15
addq $0x18, %rbx
jmp 0x477c
imulq $0x18, %r12, %rax
addq 0xc8(%rsp), %rax
xorl %ecx, %ecx
movq %rbp, %r15
cmpq %rcx, 0x18(%rsp)
je 0x4805
movq (%rax), %rdx
movsd (%rdx,%rcx,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rcx,8)
incq %rcx
jmp 0x47e8
xorl %ebx, %ebx
cmpq %rbx, 0x18(%rsp)
je 0x489f
movq 0x70(%rsp), %rax
movq (%rax,%r14), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0xc8(%rsp), %rax
imulq $0x18, %r12, %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rsp)
movq 0x10(%rsp), %r15
cvtsi2sdl 0x2d1c(%r15), %xmm0
callq 0x32d0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq 0x2cd0(%r15), %rax
movq %rbp, %r15
cvtsi2sdl (%rax,%rbp,4), %xmm0
callq 0x32d0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
callq 0x14ce5
movq 0x70(%rsp), %rax
movq (%rax,%r14), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
jmp 0x4807
movq 0x58(%rsp), %rcx
incq %rcx
jmp 0x4730
movq 0xf0(%rsp), %rcx
incq %rcx
movq 0x30(%rsp), %r13
jmp 0x470a
incq %r15
jmp 0x46c3
xorl %r14d, %r14d
movq 0x10(%rsp), %rbp
cmpq 0x18(%rsp), %r14
je 0x4929
xorl %ebx, %ebx
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %rbx
jge 0x4924
xorl %r15d, %r15d
movq (%r13), %rax
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r15
jge 0x491f
xorpd %xmm0, %xmm0
callq 0x32d0
movq 0x38(%rsp), %rax
imulq $0x18, %r14, %rcx
movq (%rax,%rcx), %rax
imulq $0x18, %rbx, %rcx
movq (%rax,%rcx), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
jmp 0x48e9
incq %rbx
jmp 0x48da
incq %r14
jmp 0x48d1
xorl %ecx, %ecx
pushq $-0x1
popq %rax
movq %rax, (%rsp)
movslq 0x2d18(%rbp), %rax
cmpq %rax, %rcx
jge 0x4a6b
xorl %edx, %edx
movq %rcx, 0x58(%rsp)
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %rdx
jge 0x4a63
movq (%rsp), %rax
cltq
movq %rax, (%rsp)
xorl %r13d, %r13d
movq %rdx, 0x20(%rsp)
movq 0x90(%rsp), %rax
movq (%rax), %rax
movslq (%rax,%rcx,4), %rax
cmpq %rax, %r13
jge 0x4a56
incq (%rsp)
movq 0x2d00(%rbp), %rax
imulq $0x18, %rcx, %rbp
movq (%rax,%rbp), %rax
imulq $0x18, %rdx, %r12
movq (%rax,%r12), %rax
cmpl $0x0, (%rax,%r13,4)
je 0x4a3f
xorl %r14d, %r14d
xorl %ebx, %ebx
cmpq %rbx, 0x18(%rsp)
je 0x4a3f
movq 0x38(%rsp), %rax
movq (%rax,%r14), %rax
movq 0x10(%rsp), %r15
movq 0x2d00(%r15), %rcx
movq (%rcx,%rbp), %rcx
movq (%rcx,%r12), %rcx
movslq (%rcx,%r13,4), %rcx
movq (%rax,%r12), %rax
movsd -0x8(%rax,%rcx,8), %xmm0
movq 0x70(%rsp), %rax
movq (%rax,%rbp), %rax
movsd (%rax,%rbx,8), %xmm1
movq 0xc8(%rsp), %rax
imulq $0x18, (%rsp), %rcx
movq (%rax,%rcx), %rax
addsd (%rax,%rbx,8), %xmm1
callq 0x14ce5
movq 0x38(%rsp), %rax
movq (%rax,%r14), %rax
movq 0x2d00(%r15), %rcx
movq (%rcx,%rbp), %rcx
movq (%rcx,%r12), %rcx
movslq (%rcx,%r13,4), %rcx
movq (%rax,%r12), %rax
movsd %xmm0, -0x8(%rax,%rcx,8)
incq %rbx
addq $0x18, %r14
jmp 0x49ae
incq %r13
movq 0x10(%rsp), %rbp
movq 0x58(%rsp), %rcx
movq 0x20(%rsp), %rdx
jmp 0x496b
incq %rdx
movq 0x30(%rsp), %r13
jmp 0x4949
incq %rcx
jmp 0x4932
xorl %r14d, %r14d
movl 0x54(%rsp), %eax
cmpq 0x18(%rsp), %r14
je 0x4b03
xorl %r15d, %r15d
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r15
jge 0x4afb
xorpd %xmm0, %xmm0
callq 0x32d0
xorl %ebx, %ebx
movq (%r13), %rax
movslq (%rax,%r15,4), %rcx
imulq $0x18, %r14, %rax
addq 0x38(%rsp), %rax
cmpq %rcx, %rbx
jge 0x4ac7
movq (%rax), %rax
imulq $0x18, %r15, %rcx
movq (%rax,%rcx), %rax
movsd (%rax,%rbx,8), %xmm1
callq 0x14ce5
incq %rbx
jmp 0x4a97
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x4af6
movq (%rax), %rsi
imulq $0x18, %r15, %rdi
movq (%rsi,%rdi), %rsi
movsd (%rsi,%rdx,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsi,%rdx,8)
incq %rdx
jmp 0x4ad3
incq %r15
jmp 0x4a80
incq %r14
jmp 0x4a6e
incl %eax
jmp 0x46aa
xorl %r14d, %r14d
movslq 0x2d18(%rbp), %rax
xorpd %xmm0, %xmm0
cmpq %rax, %r14
jge 0x4bec
callq 0x32d0
xorl %r15d, %r15d
cmpq 0x18(%rsp), %r15
je 0x4be4
movl 0x2d1c(%rbp), %eax
movq 0x2cd0(%rbp), %rcx
imulq $0x18, %r14, %rdx
addq 0x2d00(%rbp), %rdx
imulq $0x18, %r15, %rsi
addq 0x38(%rsp), %rsi
testl %eax, %eax
movl $0x0, %edi
cmovlel %edi, %eax
xorpd %xmm1, %xmm1
xorl %edi, %edi
cmpq %rax, %rdi
je 0x4baf
movl (%rcx,%r14,4), %r8d
testl %r8d, %r8d
movl $0x0, %r9d
cmovlel %r9d, %r8d
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x4baa
movq (%rdx), %r10
imulq $0x18, %rdi, %r11
movq (%r10,%r11), %r10
movslq (%r10,%r9,4), %r10
testq %r10, %r10
je 0x4ba5
movq (%rsi), %rbx
movq (%rbx,%r11), %r11
addsd -0x8(%r11,%r10,8), %xmm1
incq %r9
jmp 0x4b7e
incq %rdi
jmp 0x4b65
movsd %xmm0, (%rsp)
movsd 0xe8(%rsp), %xmm0
movsd %xmm1, 0x20(%rsp)
callq 0x32d0
movsd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd (%rsp), %xmm0
callq 0x14ce5
incq %r15
jmp 0x4b29
incq %r14
jmp 0x4b0d
xorl %r15d, %r15d
cltq
cmpq %rax, %r15
jge 0x4cde
xorl %edx, %edx
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %rdx
jge 0x4cd0
xorl %r12d, %r12d
movq %rdx, 0x20(%rsp)
movslq 0x2ba4(%rbp), %rax
cmpq %rax, %r12
jge 0x4cc8
movq 0x2d00(%rbp), %rax
imulq $0x18, %r15, %r13
movq (%rax,%r13), %rax
imulq $0x18, %rdx, %rbp
movq (%rax,%rbp), %rax
cmpl $0x0, (%rax,%r12,4)
je 0x4cb6
movsd %xmm0, (%rsp)
xorpd %xmm0, %xmm0
callq 0x32d0
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpq %r14, 0x18(%rsp)
je 0x4ca4
movq 0x70(%rsp), %rax
movq (%rax,%r13), %rax
movsd (%rax,%r14,8), %xmm1
movq 0x38(%rsp), %rax
movq (%rax,%rbx), %rax
movq 0x10(%rsp), %rcx
movq 0x2d00(%rcx), %rcx
movq (%rcx,%r13), %rcx
movq (%rcx,%rbp), %rcx
movslq (%rcx,%r12,4), %rcx
movq (%rax,%rbp), %rax
addsd -0x8(%rax,%rcx,8), %xmm1
callq 0x14ce5
incq %r14
addq $0x18, %rbx
jmp 0x4c55
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movq 0x20(%rsp), %rdx
incq %r12
movq 0x10(%rsp), %rbp
movq 0x30(%rsp), %r13
jmp 0x4c14
incq %rdx
jmp 0x4bfc
incq %r15
movl 0x2d18(%rbp), %eax
jmp 0x4bef
ucomisd 0x3040(%rbp), %xmm0
jbe 0x4db5
movsd %xmm0, 0x3040(%rbp)
xorl %r14d, %r14d
cmpq 0x18(%rsp), %r14
je 0x4d66
xorl %ebx, %ebx
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %rbx
jge 0x4d61
xorl %r15d, %r15d
movq (%r13), %rax
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r15
jge 0x4d5c
movq 0x38(%rsp), %rax
imulq $0x18, %r14, %r12
movq (%rax,%r12), %rax
imulq $0x18, %rbx, %r13
movq (%rax,%r13), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x35c0
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r12), %rax
movq (%rax,%r13), %rax
movq 0x30(%rsp), %r13
movsd %xmm0, (%rax,%r15,8)
incq %r15
jmp 0x4d0f
incq %rbx
jmp 0x4d00
incq %r14
jmp 0x4cf7
xorl %ebx, %ebx
movslq 0x2d18(%rbp), %rax
cmpq %rax, %rbx
jge 0x4db5
xorl %r14d, %r14d
cmpq %r14, 0x18(%rsp)
je 0x4db0
movq 0x70(%rsp), %rax
imulq $0x18, %rbx, %r15
movq (%rax,%r15), %rax
movsd (%rax,%r14,8), %xmm0
callq 0x35c0
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r15), %rax
movsd %xmm0, (%rax,%r14,8)
incq %r14
jmp 0x4d77
incq %rbx
jmp 0x4d68
movl 0x6c(%rsp), %eax
incl %eax
jmp 0x45c5
cmpb $0x0, 0x2c49(%rbp)
je 0x4eb2
movq %r13, %rdi
callq 0x50fb
subl 0x2d1c(%rbp), %eax
movq 0x88(%rsp), %rcx
imull %ecx, %eax
decl %ecx
imull 0x2d18(%rbp), %ecx
addl %eax, %ecx
leal (%rcx,%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd 0x3040(%rbp), %xmm1
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movslq 0x68(%rsp), %rbx
movq 0x3078(%rbp), %rax
movsd %xmm0, (%rax,%rbx,8)
cvtsi2sd %ecx, %xmm0
movsd %xmm0, (%rsp)
cvtsi2sdl 0x2d50(%rbp), %xmm0
callq 0x32d0
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
imulq $0x18, %rbx, %rcx
movq (%rax,%rcx), %rax
movsd (%rax), %xmm0
movsd 0x3040(%rbp), %xmm1
addsd %xmm1, %xmm1
mulsd 0x22191(%rip), %xmm0    # 0x27008
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 0x70(%rsp), %rdi
callq 0x50da
leaq 0x38(%rsp), %rdi
callq 0x5066
leaq 0xc8(%rsp), %rdi
callq 0x50da
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x51a2
jmp 0x4f42
jmp 0x4f3f
jmp 0x4f3f
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x51a2
jmp 0x4f4c
movq %rax, %rbx
jmp 0x4f4c
movq %rax, %rbx
jmp 0x4f56
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x51a2
jmp 0x4f63
movq %rax, %rbx
jmp 0x4f63
jmp 0x4f3f
jmp 0x4f3f
jmp 0x4f3f
jmp 0x4f3f
jmp 0x4f3f
jmp 0x4f3f
jmp 0x4f3f
jmp 0x4f3f
jmp 0x4f3f
jmp 0x4f3f
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x50da
leaq 0x38(%rsp), %rdi
callq 0x5066
leaq 0xc8(%rsp), %rdi
callq 0x50da
movq %rbx, %rdi
callq 0x35a0
nop