// File: /workspace/github_cpp_makefile_star2_O3/bobverity[P]MavericK/EM_algorithm.cpp
// Function: EM_noAdmix(globals&, int)
void EM_noAdmix(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // create empty objects
    vector< vector<double> > logProbMat(globals.n,vector<double>(K));
    double logProbSum;
    vector< vector< vector<double> > > logAlleleFreqs(K);
    double logAlleleFreqsSum;
    double logLike=0;
    double logLike_this_i=0;
    double logLike_this_ik=0;
    
    // initialise logAlleleFreqs and zero global maximum likelihood allele frequencies
    globals.max_alleleFreqs = vector< vector< 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++) {
            
            // calculate assignment probability matrix
            for (int i=0; i<globals.n; i++) {
                logProbSum = log(double(0));
                for (int k=0; k<K; k++) {
                    logProbMat[i][k] = 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) {
                                logProbMat[i][k] += logAlleleFreqs[k][l][globals.data[i][l][p]-1];
                            }
                        }
                    }
                    logProbSum = logSum(logProbSum, logProbMat[i][k]);
                }
                for (int k=0; k<K; k++) {
                    logProbMat[i][k] -= logProbSum;
                }
            }
            
            // 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 probability-weighted contribution to allele frequencies
            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++) {
                        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], logProbMat[i][k]);
                            }
                        }
                    }
                }
            }
            
            // normalise 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++) {
                        // control for underflow
                        if (logAlleleFreqs[k][l][j] < -1e300)
                            logAlleleFreqs[k][l][j] = -1e300;
                        logAlleleFreqsSum = logSum(logAlleleFreqsSum, logAlleleFreqs[k][l][j]);
                    }
                    for (int j=0; j<globals.J[l]; j++) {
                        logAlleleFreqs[k][l][j] -= logAlleleFreqsSum;
                    }
                }
            }
            
        } // end of EM iterations loop
        
        // calculate log-likelihood
        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;
        }
        
        // 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]);
                    }
                }
            }
        }
        
    } // end of repeat EM loop
    
    // calculate model comparison statistics
    if (globals.outputComparisonStatistics_on) {
        
        int freeParameters = K*(sum(globals.J)-globals.loci);
        globals.AIC[Kindex] = 2*freeParameters - 2*globals.maxLike;
        globals.BIC[Kindex] = freeParameters*log(double(globals.n)) - 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 $0xb8, %rsp
movq %rdi, %rbp
movslq 0x2bc8(%rdi), %r13
movslq %esi, %rax
movq %rax, 0x88(%rsp)
addq %rax, %r13
movslq 0x2d18(%rdi), %r15
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r13, %rsi
callq 0x588e
leaq 0xa0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r15, %rsi
callq 0x591c
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3d47
callq 0x3310
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r13, %rsi
callq 0x59ac
leaq 0x40(%rsp), %rdi
leaq 0x7(%rsp), %rdx
movq %r13, %rsi
callq 0x59ac
movq 0x3058(%rbp), %rax
leaq 0x40(%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
movl %r13d, %eax
movq %rax, 0x10(%rsp)
testl %r13d, %r13d
movq %r13, 0x18(%rsp)
jle 0x3fde
movl 0x2d1c(%rbp), %eax
xorl %r12d, %r12d
leaq 0x7(%rsp), %rbx
leaq 0x20(%rsp), %rdi
movq %rdi, %r14
movslq %eax, %rsi
leaq 0x40(%rsp), %rdi
movq %rbx, %rdx
callq 0x5a6a
movq 0x60(%rsp), %rax
movq %r12, 0x8(%rsp)
leaq (%r12,%r12,2), %r12
movq 0x10(%rax,%r12,8), %rcx
movaps 0x40(%rsp), %xmm0
movups (%rax,%r12,8), %xmm1
movups %xmm0, (%rax,%r12,8)
movq 0x50(%rsp), %rdx
movq %rdx, 0x10(%rax,%r12,8)
movaps %xmm1, 0x20(%rsp)
movq %rcx, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq %r14, %r15
movq %r14, %rdi
callq 0x5ae8
leaq 0x40(%rsp), %rdi
callq 0x5ae8
movslq 0x2d1c(%rbp), %rsi
leaq 0x40(%rsp), %rdi
movq %rbx, %rdx
callq 0x5a6a
movq 0x3048(%rbp), %rax
movq 0x10(%rax,%r12,8), %rcx
movapd 0x40(%rsp), %xmm0
movupd (%rax,%r12,8), %xmm1
movupd %xmm0, (%rax,%r12,8)
movq 0x50(%rsp), %rdx
movq %rdx, 0x10(%rax,%r12,8)
movapd %xmm1, 0x20(%rsp)
movq %rcx, 0x30(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq %r15, %rdi
callq 0x5ae8
leaq 0x40(%rsp), %rdi
callq 0x5ae8
movl 0x2d1c(%rbp), %eax
testl %eax, %eax
movq %r15, %rdi
jle 0x3fc6
xorl %r13d, %r13d
xorl %r15d, %r15d
leaq 0x40(%rsp), %rbx
movq 0x2d20(%rbp), %rax
movslq (%rax,%r15,4), %rsi
movq %rbx, %rdx
callq 0x588e
movq 0x60(%rsp), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r13), %rdi
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%rax,%r13)
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rax,%r13)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %rdi, %rdi
je 0x3f40
callq 0x3310
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3f40
callq 0x3310
movq 0x2d20(%rbp), %rax
movslq (%rax,%r15,4), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x588e
movq 0x3048(%rbp), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r13), %rdi
movapd 0x20(%rsp), %xmm0
movupd %xmm0, (%rax,%r13)
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rax,%r13)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %rdi, %rdi
je 0x3fa7
callq 0x3310
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3fa7
callq 0x3310
incq %r15
movslq 0x2d1c(%rbp), %rax
addq $0x18, %r13
cmpq %rax, %r15
movq %r14, %rdi
jl 0x3ee2
movq 0x18(%rsp), %r13
movq 0x8(%rsp), %r12
incq %r12
cmpq 0x10(%rsp), %r12
leaq 0x7(%rsp), %rbx
jne 0x3deb
xorpd %xmm0, %xmm0
callq 0x3290
movsd %xmm0, 0x3040(%rbp)
cmpl $0x0, 0x2c34(%rbp)
jle 0x4703
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x98(%rsp)
xorl %eax, %eax
movq %rax, 0x90(%rsp)
testl %r13d, %r13d
jle 0x410f
movl 0x2d1c(%rbp), %eax
xorl %r15d, %r15d
testl %eax, %eax
jle 0x4101
leaq (%r15,%r15,2), %r12
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x2d20(%rbp), %rax
cmpl $0x0, (%rax,%r13,4)
jle 0x40e9
movsd %xmm0, 0x8(%rsp)
leaq (,%r13,2), %r14
addq %r13, %r14
xorl %ebx, %ebx
movsd 0x31f9a(%rip), %xmm0    # 0x36008
movsd 0x31f9a(%rip), %xmm1    # 0x36010
callq 0x1d178
callq 0x3290
movapd %xmm0, %xmm1
movq 0x60(%rsp), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r14,8), %rax
movsd %xmm0, (%rax,%rbx,8)
movsd 0x8(%rsp), %xmm0
callq 0x1a75d
movsd %xmm0, 0x8(%rsp)
incq %rbx
movq 0x2d20(%rbp), %rax
movslq (%rax,%r13,4), %rax
cmpq %rax, %rbx
jl 0x4066
testl %eax, %eax
movsd 0x8(%rsp), %xmm1
jle 0x40e9
movq 0x60(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r14,8), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x40d3
incq %r13
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r13
jl 0x4038
movq 0x18(%rsp), %r13
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x4029
cmpl $0x0, 0x2c38(%rbp)
jle 0x4513
xorl %eax, %eax
movl %eax, 0x78(%rsp)
movl 0x2d18(%rbp), %ecx
testl %ecx, %ecx
jle 0x423e
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
callq 0x3290
testl %r13d, %r13d
jle 0x422b
xorl %r13d, %r13d
movq 0xa0(%rsp), %rax
leaq (%r15,%r15,2), %r12
movq (%rax,%r12,8), %rax
movq $0x0, (%rax,%r13,8)
movslq 0x2d1c(%rbp), %rcx
testq %rcx, %rcx
jle 0x41e1
movq 0x2cd0(%rbp), %rdx
movl (%rdx,%r15,4), %edx
leaq (,%r12,8), %rsi
addq 0x2d00(%rbp), %rsi
xorpd %xmm1, %xmm1
xorl %edi, %edi
testl %edx, %edx
jle 0x41d7
movq (%rsi), %r9
leaq (%rdi,%rdi,2), %r8
movq (%r9,%r8,8), %r9
leaq (,%r13,2), %r10
addq %r13, %r10
shlq $0x3, %r10
addq 0x60(%rsp), %r10
xorl %r11d, %r11d
movslq (%r9,%r11,4), %rbx
testq %rbx, %rbx
je 0x41cf
movq (%r10), %r14
movq (%r14,%r8,8), %r14
addsd -0x8(%r14,%rbx,8), %xmm1
movsd %xmm1, (%rax,%r13,8)
incq %r11
cmpq %r11, %rdx
jne 0x41b2
incq %rdi
cmpq %rcx, %rdi
jne 0x418c
jmp 0x41e5
xorpd %xmm1, %xmm1
callq 0x1a75d
incq %r13
cmpq 0x10(%rsp), %r13
jne 0x4148
movq 0x18(%rsp), %r13
testl %r13d, %r13d
movq 0x10(%rsp), %rdx
jle 0x422b
movq 0xa0(%rsp), %rax
movq (%rax,%r12,8), %rax
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rdx
jne 0x4215
incq %r15
movslq 0x2d18(%rbp), %rcx
cmpq %rcx, %r15
jl 0x4133
testl %r13d, %r13d
jle 0x42ba
movl 0x2d1c(%rbp), %eax
xorl %r15d, %r15d
testl %eax, %eax
jle 0x42aa
movq 0x2d20(%rbp), %rcx
xorl %r14d, %r14d
cmpl $0x0, (%rcx,%r14,4)
jle 0x429f
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x60(%rsp), %rax
leaq (%r15,%r15,2), %rcx
movq (%rax,%rcx,8), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %rbx
movq 0x2d20(%rbp), %rcx
movslq (%rcx,%r14,4), %rax
cmpq %rax, %rbx
jl 0x4263
movl 0x2d1c(%rbp), %eax
incq %r14
movslq %eax, %rdx
cmpq %rdx, %r14
jl 0x425a
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x424c
movl 0x2d18(%rbp), %ecx
testl %ecx, %ecx
jle 0x4420
movl 0x2d1c(%rbp), %eax
xorl %esi, %esi
testl %eax, %eax
jle 0x4411
movq 0x2cd0(%rbp), %rcx
movq $0x0, 0x8(%rsp)
cmpl $0x0, (%rcx,%rsi,4)
jle 0x43f2
xorl %r12d, %r12d
movq 0x2d00(%rbp), %rax
leaq (%rsi,%rsi,2), %rdx
movq %rdx, 0x80(%rsp)
movq (%rax,%rdx,8), %rax
movq 0x8(%rsp), %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rax,%rdx,8), %rax
cmpl $0x0, (%rax,%r12,4)
je 0x43dc
testl %r13d, %r13d
jle 0x43dc
movq %rbp, %r13
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x60(%rsp), %rax
movq (%rax,%rbp), %rax
movq 0x8(%rsp), %rcx
leaq (,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %r15
movq 0x2d00(%r13), %rcx
movq %rsi, %r14
leaq (,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rcx,%rdx), %rcx
movq (%rcx,%r15), %rcx
movslq (%rcx,%r12,4), %rcx
movq (%rax,%r15), %rax
movsd -0x8(%rax,%rcx,8), %xmm0
movq 0xa0(%rsp), %rax
movq (%rax,%rdx), %rax
movsd (%rax,%rbx,8), %xmm1
callq 0x1a75d
movq 0x60(%rsp), %rax
movq (%rax,%rbp), %rax
movq 0x2d00(%r13), %rcx
movq 0x80(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rcx,%r15), %rcx
movslq (%rcx,%r12,4), %rcx
movq (%rax,%r15), %rax
movsd %xmm0, -0x8(%rax,%rcx,8)
incq %rbx
addq $0x18, %rbp
cmpq %rbx, 0x10(%rsp)
movq %r14, %rsi
jne 0x432e
movq 0x2cd0(%r13), %rcx
movq %r13, %rbp
movq 0x18(%rsp), %r13
incq %r12
movslq (%rcx,%rsi,4), %rax
cmpq %rax, %r12
jl 0x42ef
movl 0x2d1c(%rbp), %eax
movq 0x8(%rsp), %r8
incq %r8
movslq %eax, %rdx
movq %r8, 0x8(%rsp)
cmpq %rdx, %r8
jl 0x42e2
movl 0x2d18(%rbp), %ecx
incq %rsi
movslq %ecx, %rdx
cmpq %rdx, %rsi
jl 0x42ca
testl %r13d, %r13d
jle 0x4501
movl 0x2d1c(%rbp), %eax
xorl %r15d, %r15d
testl %eax, %eax
jle 0x44f3
xorl %r12d, %r12d
xorpd %xmm0, %xmm0
callq 0x3290
movq 0x2d20(%rbp), %rax
cmpl $0x0, (%rax,%r12,4)
jle 0x44db
xorl %r14d, %r14d
movq 0x60(%rsp), %rax
leaq (%r15,%r15,2), %rbx
movq (%rax,%rbx,8), %rax
leaq (%r12,%r12,2), %r13
movq (%rax,%r13,8), %rax
movsd (%rax,%r14,8), %xmm1
movsd 0x31b9a(%rip), %xmm2    # 0x36018
ucomisd %xmm1, %xmm2
jbe 0x449a
movabsq $-0x1c81bc377ff8a64, %rcx # imm = 0xFE37E43C8800759C
movq %rcx, (%rax,%r14,8)
movsd 0x31b7e(%rip), %xmm1    # 0x36018
callq 0x1a75d
incq %r14
movq 0x2d20(%rbp), %rax
movslq (%rax,%r12,4), %rax
cmpq %rax, %r14
jl 0x445b
testl %eax, %eax
jle 0x44db
movq 0x60(%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 0x44c5
incq %r12
movslq 0x2d1c(%rbp), %rax
cmpq %rax, %r12
jl 0x443d
movq 0x18(%rsp), %r13
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x4432
movl 0x78(%rsp), %eax
incl %eax
cmpl 0x2c38(%rbp), %eax
jl 0x411e
cmpl $0x0, 0x2d18(%rbp)
jle 0x4630
xorpd %xmm1, %xmm1
xorl %r15d, %r15d
movsd %xmm1, 0x78(%rsp)
xorpd %xmm0, %xmm0
callq 0x3290
testl %r13d, %r13d
jle 0x460c
xorl %r13d, %r13d
movslq 0x2d1c(%rbp), %rax
testq %rax, %rax
movsd %xmm0, 0x8(%rsp)
jle 0x45c3
movq 0x2cd0(%rbp), %rcx
movl (%rcx,%r15,4), %ecx
leaq (%r15,%r15,2), %rdx
shlq $0x3, %rdx
addq 0x2d00(%rbp), %rdx
leaq (,%r13,2), %rsi
addq %r13, %rsi
shlq $0x3, %rsi
addq 0x60(%rsp), %rsi
xorpd %xmm0, %xmm0
xorl %edi, %edi
testl %ecx, %ecx
jle 0x45b9
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 0x45b1
movq (%rsi), %rbx
movq (%rbx,%r8,8), %rbx
addsd -0x8(%rbx,%r11,8), %xmm0
incq %r10
cmpq %r10, %rcx
jne 0x459a
incq %rdi
cmpq %rax, %rdi
jne 0x4588
jmp 0x45c7
xorpd %xmm0, %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0x98(%rsp), %xmm0
callq 0x3290
movsd 0x80(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x1a75d
incq %r13
cmpq 0x10(%rsp), %r13
movsd 0x78(%rsp), %xmm1
jne 0x4542
jmp 0x4612
movsd 0x78(%rsp), %xmm1
addsd %xmm0, %xmm1
incq %r15
movslq 0x2d18(%rbp), %rax
cmpq %rax, %r15
movq 0x18(%rsp), %r13
jl 0x4527
jmp 0x4634
xorpd %xmm1, %xmm1
ucomisd 0x3040(%rbp), %xmm1
jbe 0x46ed
movsd %xmm1, 0x3040(%rbp)
testl %r13d, %r13d
jle 0x46ed
movl 0x2d1c(%rbp), %eax
xorl %r15d, %r15d
testl %eax, %eax
jle 0x46df
movq 0x2d20(%rbp), %rcx
xorl %r14d, %r14d
cmpl $0x0, (%rcx,%r14,4)
jle 0x46d4
xorl %ebx, %ebx
movq 0x60(%rsp), %rax
leaq (,%r15,8), %rcx
leaq (%rcx,%rcx,2), %r12
movq (%rax,%r12), %rax
leaq (,%r14,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,%r14,4), %rax
cmpq %rax, %rbx
jl 0x4673
movl 0x2d1c(%rbp), %eax
movq 0x18(%rsp), %r13
incq %r14
movslq %eax, %rdx
cmpq %rdx, %r14
jl 0x466a
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x465c
movq 0x90(%rsp), %rax
incl %eax
cmpl 0x2c34(%rbp), %eax
jl 0x400f
cmpb $0x0, 0x2c49(%rbp)
je 0x482f
movq 0x2d20(%rbp), %rcx
movq 0x2d28(%rbp), %rdx
subq %rcx, %rdx
shrq $0x2, %rdx
testl %edx, %edx
jle 0x4748
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %eax, %eax
movq 0x88(%rsp), %r14
addl (%rcx,%rsi,4), %eax
incq %rsi
cmpq %rsi, %rdx
jne 0x473b
jmp 0x4752
xorl %eax, %eax
movq 0x88(%rsp), %r14
subl 0x2d1c(%rbp), %eax
imull %r13d, %eax
leal (%rax,%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x3040(%rbp), %xmm1
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movq 0x3078(%rbp), %rcx
leaq (,%r14,8), %rbx
movsd %xmm0, (%rcx,%r14,8)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x2d18(%rbp), %xmm0
callq 0x3290
movsd 0x3040(%rbp), %xmm1
mulsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movq 0x3090(%rbp), %rax
movsd %xmm0, (%rax,%r14,8)
movq 0x2e60(%rbp), %rax
leaq (%rbx,%rbx,2), %rcx
movq (%rax,%rcx), %rax
movsd (%rax), %xmm0
movsd 0x3040(%rbp), %xmm1
addsd %xmm1, %xmm1
mulsd 0x3182e(%rip), %xmm0    # 0x36020
addsd %xmm1, %xmm0
movq 0x30a8(%rbp), %rdx
movsd %xmm0, (%rdx,%r14,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,%r14,8)
leaq 0x60(%rsp), %rdi
callq 0x5a2a
leaq 0xa0(%rsp), %rdi
callq 0x5ae8
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4888
movq %rax, %rbx
jmp 0x4895
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x48a2
callq 0x3310
jmp 0x48a2
movq %rax, %rbx
jmp 0x48a2
jmp 0x4888
jmp 0x4888
jmp 0x4888
jmp 0x4888
jmp 0x4888
jmp 0x4888
jmp 0x4888
jmp 0x4888
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x5a2a
leaq 0xa0(%rsp), %rdi
callq 0x5ae8
movq %rbx, %rdi
callq 0x3580