// File: 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:
subq $0x388, %rsp            # imm = 0x388
movq %rdi, 0x380(%rsp)
movl %esi, 0x37c(%rsp)
movq 0x380(%rsp), %rax
movl 0x2bc8(%rax), %eax
movl 0x37c(%rsp), %ecx
addl %ecx, %eax
movl %eax, 0x378(%rsp)
movq 0x380(%rsp), %rax
movslq 0x2d18(%rax), %rax
movq %rax, 0x1b8(%rsp)
movslq 0x378(%rsp), %rax
movq %rax, 0x1c0(%rsp)
leaq 0x347(%rsp), %rdi
movq %rdi, 0x1c8(%rsp)
callq 0x8780
movq 0x1c0(%rsp), %rsi
movq 0x1c8(%rsp), %rdx
leaq 0x348(%rsp), %rdi
callq 0x8790
jmp 0x4d3f
leaq 0x333(%rsp), %rdi
movq %rdi, 0x1b0(%rsp)
callq 0x8810
movq 0x1b8(%rsp), %rsi
movq 0x1b0(%rsp), %rcx
leaq 0x360(%rsp), %rdi
leaq 0x348(%rsp), %rdx
callq 0x8820
jmp 0x4d7b
leaq 0x333(%rsp), %rdi
callq 0x88a0
leaq 0x348(%rsp), %rdi
callq 0x88b0
leaq 0x347(%rsp), %rdi
callq 0x8910
movslq 0x378(%rsp), %rax
movq %rax, 0x1a0(%rsp)
leaq 0x30f(%rsp), %rdi
movq %rdi, 0x1a8(%rsp)
callq 0x8920
movq 0x1a0(%rsp), %rsi
movq 0x1a8(%rsp), %rdx
leaq 0x310(%rsp), %rdi
callq 0x8930
jmp 0x4de6
leaq 0x30f(%rsp), %rdi
callq 0x89b0
movq $0x0, 0x2f8(%rsp)
movq $0x0, 0x2f0(%rsp)
movq $0x0, 0x2e8(%rsp)
movslq 0x378(%rsp), %rax
movq %rax, 0x190(%rsp)
leaq 0x2cf(%rsp), %rdi
movq %rdi, 0x198(%rsp)
callq 0x8920
movq 0x190(%rsp), %rsi
movq 0x198(%rsp), %rdx
leaq 0x2d0(%rsp), %rdi
callq 0x8930
jmp 0x4e5b
movq 0x380(%rsp), %rdi
addq $0x3048, %rdi           # imm = 0x3048
leaq 0x2d0(%rsp), %rsi
callq 0x89c0
leaq 0x2d0(%rsp), %rdi
callq 0x8a00
leaq 0x2cf(%rsp), %rdi
callq 0x89b0
movl $0x0, 0x2c8(%rsp)
movl 0x2c8(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x52c4
movq 0x380(%rsp), %rax
movslq 0x2d1c(%rax), %rax
movq %rax, 0x180(%rsp)
leaq 0x2af(%rsp), %rdi
movq %rdi, 0x188(%rsp)
callq 0x8810
movq 0x180(%rsp), %rsi
movq 0x188(%rsp), %rdx
leaq 0x2b0(%rsp), %rdi
callq 0x8a60
jmp 0x4efb
movslq 0x2c8(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
leaq 0x2b0(%rsp), %rsi
movq %rsi, 0x168(%rsp)
callq 0x8b00
movq 0x168(%rsp), %rdi
callq 0x8b40
leaq 0x2af(%rsp), %rdi
callq 0x88a0
movq 0x380(%rsp), %rax
movslq 0x2d1c(%rax), %rax
movq %rax, 0x170(%rsp)
leaq 0x28f(%rsp), %rdi
movq %rdi, 0x178(%rsp)
callq 0x8810
movq 0x170(%rsp), %rsi
movq 0x178(%rsp), %rdx
leaq 0x290(%rsp), %rdi
callq 0x8a60
jmp 0x4f8d
movq 0x380(%rsp), %rdi
addq $0x3048, %rdi           # imm = 0x3048
movslq 0x2c8(%rsp), %rsi
callq 0x8ae0
movq %rax, %rdi
leaq 0x290(%rsp), %rsi
callq 0x8b00
leaq 0x290(%rsp), %rdi
callq 0x8b40
leaq 0x28f(%rsp), %rdi
callq 0x88a0
movl $0x0, 0x288(%rsp)
movl 0x288(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x52ac
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
movslq 0x288(%rsp), %rsi
callq 0x8ba0
movslq (%rax), %rax
movq %rax, 0x158(%rsp)
leaq 0x26f(%rsp), %rdi
movq %rdi, 0x160(%rsp)
callq 0x8780
movq 0x158(%rsp), %rsi
movq 0x160(%rsp), %rdx
leaq 0x270(%rsp), %rdi
callq 0x8790
jmp 0x5054
movslq 0x2c8(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x288(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
leaq 0x270(%rsp), %rsi
movq %rsi, 0x140(%rsp)
callq 0x8be0
movq 0x140(%rsp), %rdi
callq 0x88b0
leaq 0x26f(%rsp), %rdi
callq 0x8910
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
movslq 0x288(%rsp), %rsi
callq 0x8ba0
movslq (%rax), %rax
movq %rax, 0x148(%rsp)
leaq 0x24f(%rsp), %rdi
movq %rdi, 0x150(%rsp)
callq 0x8780
movq 0x148(%rsp), %rsi
movq 0x150(%rsp), %rdx
leaq 0x250(%rsp), %rdi
callq 0x8790
jmp 0x5106
movq 0x380(%rsp), %rdi
addq $0x3048, %rdi           # imm = 0x3048
movslq 0x2c8(%rsp), %rsi
callq 0x8ae0
movq %rax, %rdi
movslq 0x288(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
leaq 0x250(%rsp), %rsi
callq 0x8be0
leaq 0x250(%rsp), %rdi
callq 0x88b0
leaq 0x24f(%rsp), %rdi
callq 0x8910
movl 0x288(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x288(%rsp)
jmp 0x4fde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x51b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x333(%rsp), %rdi
callq 0x88a0
leaq 0x348(%rsp), %rdi
callq 0x88b0
leaq 0x347(%rsp), %rdi
callq 0x8910
jmp 0x6627
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x30f(%rsp), %rdi
callq 0x89b0
jmp 0x661a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x2cf(%rsp), %rdi
callq 0x89b0
jmp 0x660d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x2af(%rsp), %rdi
callq 0x88a0
jmp 0x660d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x28f(%rsp), %rdi
callq 0x88a0
jmp 0x660d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x26f(%rsp), %rdi
callq 0x8910
jmp 0x660d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x24f(%rsp), %rdi
callq 0x8910
jmp 0x660d
jmp 0x52ae
movl 0x2c8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c8(%rsp)
jmp 0x4e9c
xorps %xmm0, %xmm0
callq 0x4390
movq 0x380(%rsp), %rax
movsd %xmm0, 0x3040(%rax)
movl $0x0, 0x248(%rsp)
movl 0x248(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2c34(%rcx), %eax
jge 0x6392
movl $0x0, 0x244(%rsp)
movl 0x244(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x55aa
movl $0x0, 0x240(%rsp)
movl 0x240(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x5592
xorps %xmm0, %xmm0
callq 0x4390
movsd %xmm0, 0x300(%rsp)
movl $0x0, 0x23c(%rsp)
movl 0x23c(%rsp), %eax
movl %eax, 0x13c(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
movslq 0x240(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0x13c(%rsp), %eax
cmpl (%rcx), %eax
jge 0x54c5
movsd 0x56c79(%rip), %xmm0    # 0x5c020
movsd 0x56c79(%rip), %xmm1    # 0x5c028
callq 0x39150
movsd %xmm0, 0x130(%rsp)
jmp 0x53bf
movsd 0x130(%rsp), %xmm0
callq 0x4390
movsd %xmm0, 0x110(%rsp)
movslq 0x244(%rsp), %rsi
leaq 0x310(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0x8ae0
movq %rax, %rdi
movslq 0x240(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x23c(%rsp), %rsi
callq 0x8c20
movsd 0x110(%rsp), %xmm0
movq 0x118(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x300(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
movslq 0x244(%rsp), %rsi
callq 0x8ae0
movq %rax, %rdi
movslq 0x240(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x23c(%rsp), %rsi
callq 0x8c20
movsd 0x120(%rsp), %xmm0
movsd (%rax), %xmm1
callq 0x339b0
movsd %xmm0, 0x128(%rsp)
jmp 0x5484
movsd 0x128(%rsp), %xmm0
movsd %xmm0, 0x300(%rsp)
movl 0x23c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x23c(%rsp)
jmp 0x5363
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0x660d
movl $0x0, 0x238(%rsp)
movl 0x238(%rsp), %eax
movl %eax, 0x10c(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
movslq 0x240(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0x10c(%rsp), %eax
cmpl (%rcx), %eax
jge 0x557a
movsd 0x300(%rsp), %xmm0
movsd %xmm0, 0x100(%rsp)
movslq 0x244(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x240(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x238(%rsp), %rsi
callq 0x8c20
movsd 0x100(%rsp), %xmm1
movsd (%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl 0x238(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x238(%rsp)
jmp 0x54d0
jmp 0x557c
movl 0x240(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x240(%rsp)
jmp 0x532c
jmp 0x5594
movl 0x244(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x244(%rsp)
jmp 0x530d
movl $0x0, 0x234(%rsp)
movl 0x234(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2c38(%rcx), %eax
jge 0x5f70
movl $0x0, 0x230(%rsp)
movl 0x230(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d18(%rcx), %eax
jge 0x5903
xorps %xmm0, %xmm0
callq 0x4390
movsd %xmm0, 0x328(%rsp)
movl $0x0, 0x22c(%rsp)
movl 0x22c(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x5871
movslq 0x230(%rsp), %rsi
leaq 0x360(%rsp), %rdi
callq 0x8bc0
movq %rax, %rdi
movslq 0x22c(%rsp), %rsi
callq 0x8c20
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x0, 0x228(%rsp)
movl 0x228(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x57f5
movl $0x0, 0x224(%rsp)
movl 0x224(%rsp), %eax
movl %eax, 0xfc(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2cd0, %rdi           # imm = 0x2CD0
movslq 0x230(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0xfc(%rsp), %eax
cmpl (%rcx), %eax
jge 0x57dd
movq 0x380(%rsp), %rdi
addq $0x2d00, %rdi           # imm = 0x2D00
movslq 0x230(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0x228(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x224(%rsp), %rsi
callq 0x8ba0
cmpl $0x0, (%rax)
je 0x57c5
movslq 0x22c(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x228(%rsp), %rsi
callq 0x8bc0
movq %rax, 0xe8(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d00, %rdi           # imm = 0x2D00
movslq 0x230(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0x228(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x224(%rsp), %rsi
callq 0x8ba0
movq 0xe8(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8c20
movsd (%rax), %xmm0
movsd %xmm0, 0xf0(%rsp)
movslq 0x230(%rsp), %rsi
leaq 0x360(%rsp), %rdi
callq 0x8bc0
movq %rax, %rdi
movslq 0x22c(%rsp), %rsi
callq 0x8c20
movsd 0xf0(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0x57c7
movl 0x224(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x224(%rsp)
jmp 0x5683
jmp 0x57df
movl 0x228(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x228(%rsp)
jmp 0x565d
movsd 0x328(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movslq 0x230(%rsp), %rsi
leaq 0x360(%rsp), %rdi
callq 0x8bc0
movq %rax, %rdi
movslq 0x22c(%rsp), %rsi
callq 0x8c20
movsd 0xd8(%rsp), %xmm0
movsd (%rax), %xmm1
callq 0x339b0
movsd %xmm0, 0xe0(%rsp)
jmp 0x5849
movsd 0xe0(%rsp), %xmm0
movsd %xmm0, 0x328(%rsp)
movl 0x22c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x22c(%rsp)
jmp 0x5612
movl $0x0, 0x220(%rsp)
movl 0x220(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x58eb
movsd 0x328(%rsp), %xmm0
movsd %xmm0, 0xd0(%rsp)
movslq 0x230(%rsp), %rsi
leaq 0x360(%rsp), %rdi
callq 0x8bc0
movq %rax, %rdi
movslq 0x220(%rsp), %rsi
callq 0x8c20
movsd 0xd0(%rsp), %xmm1
movsd (%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl 0x220(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x220(%rsp)
jmp 0x587c
jmp 0x58ed
movl 0x230(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x230(%rsp)
jmp 0x55db
movl $0x0, 0x21c(%rsp)
movl 0x21c(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x5a24
movl $0x0, 0x218(%rsp)
movl 0x218(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x5a0c
movl $0x0, 0x214(%rsp)
movl 0x214(%rsp), %eax
movl %eax, 0xcc(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
movslq 0x218(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0xcc(%rsp), %eax
cmpl (%rcx), %eax
jge 0x59f4
xorps %xmm0, %xmm0
callq 0x4390
movsd %xmm0, 0xc0(%rsp)
movslq 0x21c(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x218(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x214(%rsp), %rsi
callq 0x8c20
movsd 0xc0(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x214(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x214(%rsp)
jmp 0x5953
jmp 0x59f6
movl 0x218(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x218(%rsp)
jmp 0x592d
jmp 0x5a0e
movl 0x21c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x21c(%rsp)
jmp 0x590e
movl $0x0, 0x210(%rsp)
movl 0x210(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d18(%rcx), %eax
jge 0x5cd2
movl $0x0, 0x20c(%rsp)
movl 0x20c(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x5cba
movl $0x0, 0x208(%rsp)
movl 0x208(%rsp), %eax
movl %eax, 0xbc(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2cd0, %rdi           # imm = 0x2CD0
movslq 0x210(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0xbc(%rsp), %eax
cmpl (%rcx), %eax
jge 0x5ca2
movq 0x380(%rsp), %rdi
addq $0x2d00, %rdi           # imm = 0x2D00
movslq 0x210(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0x20c(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x208(%rsp), %rsi
callq 0x8ba0
cmpl $0x0, (%rax)
je 0x5c8a
movl $0x0, 0x204(%rsp)
movl 0x204(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x5c88
movslq 0x204(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x20c(%rsp), %rsi
callq 0x8bc0
movq %rax, 0xa0(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d00, %rdi           # imm = 0x2D00
movslq 0x210(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0x20c(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x208(%rsp), %rsi
callq 0x8ba0
movq 0xa0(%rsp), %rdi
movl (%rax), %eax
decl %eax
movslq %eax, %rsi
callq 0x8c20
movsd (%rax), %xmm0
movsd %xmm0, 0xa8(%rsp)
movslq 0x210(%rsp), %rsi
leaq 0x360(%rsp), %rdi
callq 0x8bc0
movq %rax, %rdi
movslq 0x204(%rsp), %rsi
callq 0x8c20
movsd 0xa8(%rsp), %xmm0
movsd (%rax), %xmm1
callq 0x339b0
movsd %xmm0, 0xb0(%rsp)
jmp 0x5be7
movslq 0x204(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x20c(%rsp), %rsi
callq 0x8bc0
movq %rax, 0x98(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d00, %rdi           # imm = 0x2D00
movslq 0x210(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0x20c(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x208(%rsp), %rsi
callq 0x8ba0
movq 0x98(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8c20
movsd 0xb0(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x204(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x204(%rsp)
jmp 0x5b07
jmp 0x5c8a
jmp 0x5c8c
movl 0x208(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x208(%rsp)
jmp 0x5a7b
jmp 0x5ca4
movl 0x20c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20c(%rsp)
jmp 0x5a55
jmp 0x5cbc
movl 0x210(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x210(%rsp)
jmp 0x5a2f
movl $0x0, 0x200(%rsp)
movl 0x200(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x5f58
movl $0x0, 0x1fc(%rsp)
movl 0x1fc(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x5f40
xorps %xmm0, %xmm0
callq 0x4390
movsd %xmm0, 0x300(%rsp)
movl $0x0, 0x1f8(%rsp)
movl 0x1f8(%rsp), %eax
movl %eax, 0x94(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
movslq 0x1fc(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0x94(%rsp), %eax
cmpl (%rcx), %eax
jge 0x5e7f
movslq 0x200(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x1f8(%rsp), %rsi
callq 0x8c20
movsd 0x5626c(%rip), %xmm0    # 0x5c018
ucomisd (%rax), %xmm0
jbe 0x5df3
movslq 0x200(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x1f8(%rsp), %rsi
callq 0x8c20
movsd 0x56229(%rip), %xmm0    # 0x5c018
movsd %xmm0, (%rax)
movsd 0x300(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movslq 0x200(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x1f8(%rsp), %rsi
callq 0x8c20
movsd 0x80(%rsp), %xmm0
movsd (%rax), %xmm1
callq 0x339b0
movsd %xmm0, 0x88(%rsp)
jmp 0x5e57
movsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x300(%rsp)
movl 0x1f8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1f8(%rsp)
jmp 0x5d33
movl $0x0, 0x1f4(%rsp)
movl 0x1f4(%rsp), %eax
movl %eax, 0x7c(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
movslq 0x1fc(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0x7c(%rsp), %eax
cmpl (%rcx), %eax
jge 0x5f28
movsd 0x300(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movslq 0x200(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x1f4(%rsp), %rsi
callq 0x8c20
movsd 0x70(%rsp), %xmm1
movsd (%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl 0x1f4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1f4(%rsp)
jmp 0x5e8a
jmp 0x5f2a
movl 0x1fc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1fc(%rsp)
jmp 0x5cfc
jmp 0x5f42
movl 0x200(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x200(%rsp)
jmp 0x5cdd
jmp 0x5f5a
movl 0x234(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x234(%rsp)
jmp 0x55b5
xorps %xmm0, %xmm0
movsd %xmm0, 0x2f8(%rsp)
movl $0x0, 0x1f0(%rsp)
movl 0x1f0(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d18(%rcx), %eax
jge 0x61ea
xorps %xmm0, %xmm0
callq 0x4390
movsd %xmm0, 0x2f0(%rsp)
movl $0x0, 0x1ec(%rsp)
movl 0x1ec(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x61b9
xorps %xmm0, %xmm0
movsd %xmm0, 0x2e8(%rsp)
movl $0x0, 0x1e8(%rsp)
movl 0x1e8(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x6148
movl $0x0, 0x1e4(%rsp)
movl 0x1e4(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2cd0, %rdi           # imm = 0x2CD0
movslq 0x1f0(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0x6c(%rsp), %eax
cmpl (%rcx), %eax
jge 0x6130
movq 0x380(%rsp), %rdi
addq $0x2d00, %rdi           # imm = 0x2D00
movslq 0x1f0(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0x1e8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x1e4(%rsp), %rsi
callq 0x8ba0
cmpl $0x0, (%rax)
je 0x6118
movslq 0x1ec(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x1e8(%rsp), %rsi
callq 0x8bc0
movq %rax, 0x60(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d00, %rdi           # imm = 0x2D00
movslq 0x1f0(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0x1e8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x1e4(%rsp), %rsi
callq 0x8ba0
movq 0x60(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8c20
movsd (%rax), %xmm0
addsd 0x2e8(%rsp), %xmm0
movsd %xmm0, 0x2e8(%rsp)
jmp 0x611a
movl 0x1e4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e4(%rsp)
jmp 0x600f
jmp 0x6132
movl 0x1e8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e8(%rsp)
jmp 0x5fe9
movsd 0x2f0(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x2e8(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
cvtsi2sdl 0x378(%rsp), %xmm0
callq 0x4390
movsd 0x48(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x50(%rsp), %xmm0
subsd %xmm2, %xmm1
callq 0x339b0
movsd %xmm0, 0x58(%rsp)
jmp 0x6194
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x2f0(%rsp)
movl 0x1ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1ec(%rsp)
jmp 0x5fbe
movsd 0x2f0(%rsp), %xmm0
addsd 0x2f8(%rsp), %xmm0
movsd %xmm0, 0x2f8(%rsp)
movl 0x1f0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1f0(%rsp)
jmp 0x5f87
movsd 0x2f8(%rsp), %xmm0
movq 0x380(%rsp), %rax
ucomisd 0x3040(%rax), %xmm0
jbe 0x637a
movsd 0x2f8(%rsp), %xmm0
movq 0x380(%rsp), %rax
movsd %xmm0, 0x3040(%rax)
movl $0x0, 0x1e0(%rsp)
movl 0x1e0(%rsp), %eax
cmpl 0x378(%rsp), %eax
jge 0x6378
movl $0x0, 0x1dc(%rsp)
movl 0x1dc(%rsp), %eax
movq 0x380(%rsp), %rcx
cmpl 0x2d1c(%rcx), %eax
jge 0x6360
movl $0x0, 0x1d8(%rsp)
movl 0x1d8(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
movslq 0x1dc(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0x44(%rsp), %eax
cmpl (%rcx), %eax
jge 0x6348
movslq 0x1e0(%rsp), %rsi
leaq 0x310(%rsp), %rdi
callq 0x8ae0
movq %rax, %rdi
movslq 0x1dc(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x1d8(%rsp), %rsi
callq 0x8c20
movsd (%rax), %xmm0
callq 0x4760
movsd %xmm0, 0x38(%rsp)
movq 0x380(%rsp), %rdi
addq $0x3048, %rdi           # imm = 0x3048
movslq 0x1e0(%rsp), %rsi
callq 0x8ae0
movq %rax, %rdi
movslq 0x1dc(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
movslq 0x1d8(%rsp), %rsi
callq 0x8c20
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x1d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1d8(%rsp)
jmp 0x6272
jmp 0x634a
movl 0x1dc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1dc(%rsp)
jmp 0x624c
jmp 0x6362
movl 0x1e0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e0(%rsp)
jmp 0x622d
jmp 0x637a
jmp 0x637c
movl 0x248(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x248(%rsp)
jmp 0x52e7
movq 0x380(%rsp), %rax
testb $0x1, 0x2c49(%rax)
je 0x65eb
movl 0x378(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2d20, %rdi           # imm = 0x2D20
callq 0x8c80
movl %eax, 0x34(%rsp)
jmp 0x63cc
movl 0x30(%rsp), %eax
movl 0x34(%rsp), %ecx
movq 0x380(%rsp), %rdx
subl 0x2d1c(%rdx), %ecx
imull %ecx, %eax
movl %eax, 0x1d4(%rsp)
movl 0x1d4(%rsp), %eax
shll %eax
cvtsi2sd %eax, %xmm0
movq 0x380(%rsp), %rax
movsd 0x3040(%rax), %xmm1
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq 0x380(%rsp), %rdi
addq $0x3078, %rdi           # imm = 0x3078
movslq 0x37c(%rsp), %rsi
callq 0x8c20
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
cvtsi2sdl 0x1d4(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x380(%rsp), %rax
cvtsi2sdl 0x2d18(%rax), %xmm0
callq 0x4390
movaps %xmm0, %xmm2
movsd 0x8(%rsp), %xmm0
movq 0x380(%rsp), %rax
movsd 0x55b90(%rip), %xmm1    # 0x5c008
mulsd 0x3040(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x380(%rsp), %rdi
addq $0x3090, %rdi           # imm = 0x3090
movslq 0x37c(%rsp), %rsi
callq 0x8c20
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x380(%rsp), %rdi
addq $0x2e60, %rdi           # imm = 0x2E60
movslq 0x37c(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8c20
movsd (%rax), %xmm0
movq 0x380(%rsp), %rax
movsd 0x55b01(%rip), %xmm1    # 0x5c008
mulsd 0x3040(%rax), %xmm1
movsd 0x55af9(%rip), %xmm2    # 0x5c010
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x380(%rsp), %rdi
addq $0x30a8, %rdi           # imm = 0x30A8
movslq 0x37c(%rsp), %rsi
callq 0x8c20
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x380(%rsp), %rdi
addq $0x2e60, %rdi           # imm = 0x2E60
movslq 0x37c(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8c20
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x380(%rsp), %rdi
addq $0x2e78, %rdi           # imm = 0x2E78
movslq 0x37c(%rsp), %rsi
callq 0x8bc0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8c20
movsd 0x20(%rsp), %xmm1
movsd 0x55a55(%rip), %xmm0    # 0x5c008
mulsd (%rax), %xmm0
addsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x380(%rsp), %rdi
addq $0x30c0, %rdi           # imm = 0x30C0
movslq 0x37c(%rsp), %rsi
callq 0x8c20
movsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0x310(%rsp), %rdi
callq 0x8a00
leaq 0x360(%rsp), %rdi
callq 0x8b40
addq $0x388, %rsp            # imm = 0x388
retq
leaq 0x310(%rsp), %rdi
callq 0x8a00
leaq 0x360(%rsp), %rdi
callq 0x8b40
movq 0x338(%rsp), %rdi
callq 0x4730
nopw %cs:(%rax,%rax)