// File: /workspace/github_cpp_makefile_star2_O2/bobverity[P]MavericK/mainMCMC.cpp
// Function: mainMCMC_noAdmixture(globals&, int)
void mainMCMC_noAdmixture(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // define temporary Qmatrix objects for calculating mean and sd over mainRepeats
    vector< vector< vector<double> > > Qmatrix_ind_allReps(globals.n, vector< vector<double> >(K, vector<double>(globals.mainRepeats)));
    vector< vector< vector<double> > > Qmatrix_pop_allReps(globals.uniquePops.size(), vector< vector<double> >(K, vector<double>(globals.mainRepeats)));
    
    // define MCMC object
    MCMCobject_noAdmixture mainMCMC(globals, Kindex, globals.mainBurnin, globals.mainSamples, globals.mainThinning, 1.0);
    
    // repeat analysis multiple times
    for (int mainRep=0; mainRep<globals.mainRepeats; mainRep++) {
        coutAndLog("  analysis "+to_string((long long)mainRep+1)+" of "+to_string((long long)globals.mainRepeats)+"\n", globals.outputLog_on, globals.outputLog_fileStream);
        
        // perform MCMC
        if (mainRep==0) {
            mainMCMC.reset(true);
        } else {
            mainMCMC.reset(false);
        }
        mainMCMC.perform_MCMC(globals, true, false, globals.fixLabels_on, globals.outputLikelihood_on, globals.outputPosteriorGrouping_on, mainRep);
        
        // save Qmatrix values
        if (globals.fixLabels_on) {
            for (int i=0; i<globals.n; i++) {
                for (int k=0; k<K; k++) {
                    Qmatrix_ind_allReps[i][k][mainRep] = mainMCMC.Qmatrix_ind[i][k];
                }
            }
            if (globals.outputQmatrix_pop_on) {
                for (int i=0; i<int(globals.uniquePops.size()); i++) {
                    for (int k=0; k<K; k++) {
                        Qmatrix_pop_allReps[i][k][mainRep] = mainMCMC.Qmatrix_pop[i][k];
                    }
                }
            }
        }
        
        // save harmonic mean of marginal likelihoods
        globals.logEvidence_harmonic[Kindex][mainRep] = mainMCMC.harmonic;
        
        // calculate Structure estimator from joint likelihoods
        globals.structure_loglike_mean[Kindex][mainRep] = mainMCMC.logLikeJoint_sum/double(globals.mainSamples);
        globals.structure_loglike_var[Kindex][mainRep] = mainMCMC.logLikeJoint_sumSquared/double(globals.mainSamples) - globals.structure_loglike_mean[Kindex][mainRep]*globals.structure_loglike_mean[Kindex][mainRep];
        globals.logEvidence_structure[Kindex][mainRep] = globals.structure_loglike_mean[Kindex][mainRep] - 0.5*globals.structure_loglike_var[Kindex][mainRep];
        
        // calculate elements of Evanno's delta K for the *previous* iteration
        if (Kindex>0)
            globals.L_1[Kindex][mainRep] = globals.logEvidence_structure[Kindex][mainRep]-globals.logEvidence_structure[Kindex-1][mainRep];
        if (Kindex>1) {
            globals.L_2[Kindex-1][mainRep] = abs(globals.L_1[Kindex][mainRep]-globals.L_1[Kindex-1][mainRep]);
        }
        
    }
    
    // save Qmatrices
    if (globals.fixLabels_on) {
        for (int i=0; i<globals.n; i++) {
            for (int k=0; k<K; k++) {
                globals.Qmatrix_ind[Kindex][i][k] = mean(Qmatrix_ind_allReps[i][k]);
                globals.QmatrixError_ind[Kindex][i][k] = sqrt(var(Qmatrix_ind_allReps[i][k])/double(globals.mainRepeats));
            }
        }
        if (globals.outputQmatrix_pop_on) {
            for (int i=0; i<int(globals.uniquePops.size()); i++) {
                for (int k=0; k<K; k++) {
                    globals.Qmatrix_pop[Kindex][i][k] = mean(Qmatrix_pop_allReps[i][k]);
                    globals.QmatrixError_pop[Kindex][i][k] = sqrt(var(Qmatrix_pop_allReps[i][k]));
                }
            }
        }
    }
    
    // calculate grand mean and standard error of harmonic mean estimator
    globals.logEvidence_harmonic_grandMean[Kindex] = mean(globals.logEvidence_harmonic[Kindex]);
    if (globals.mainRepeats>1) {
        globals.logEvidence_harmonic_grandSE[Kindex] = sqrt(var(globals.logEvidence_harmonic[Kindex], 0, true)/globals.mainRepeats);
    }
    
    // calculate grand mean and standard error of Structure estimator
    globals.logEvidence_structure_grandMean[Kindex] = mean(globals.logEvidence_structure[Kindex]);
    if (globals.mainRepeats>1) {
        globals.logEvidence_structure_grandSE[Kindex] = sqrt(var(globals.logEvidence_structure[Kindex], 0, true)/globals.mainRepeats);
    }
    
    // finalise calculation of Evanno's delta K for *previous* iteration
    if (Kindex>1) {
        globals.delta_K[Kindex-1] = mean(globals.L_2[Kindex-1])/sqrt(var(globals.logEvidence_structure[Kindex-1], 0, true));
    }
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdi, %rbx
movl 0x2bc8(%rdi), %r13d
movq %rsi, 0x10(%rsp)
addl %esi, %r13d
movslq 0x2d18(%rdi), %r15
movslq 0x2c0c(%rdi), %rsi
leaq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x4f6c
movslq %r13d, %r14
leaq 0x128(%rsp), %rdi
leaq 0x28(%rsp), %rdx
leaq 0xc8(%rsp), %rcx
movq %r14, %rsi
callq 0x4fbe
leaq 0x70(%rsp), %rdi
leaq 0x128(%rsp), %rdx
leaq 0x88(%rsp), %rcx
movq %r15, %rsi
callq 0x14a84
leaq 0x128(%rsp), %rdi
callq 0x50da
leaq 0x28(%rsp), %rdi
callq 0x51a2
movq 0x2c90(%rbx), %r15
subq 0x2c88(%rbx), %r15
movslq 0x2c0c(%rbx), %rsi
leaq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x4f6c
leaq 0x128(%rsp), %rdi
leaq 0x28(%rsp), %rdx
leaq 0xc8(%rsp), %rcx
movq %r14, %rsi
callq 0x4fbe
sarq $0x5, %r15
leaq 0x58(%rsp), %rdi
leaq 0x128(%rsp), %rdx
leaq 0x88(%rsp), %rcx
movq %r15, %rsi
callq 0x14a84
leaq 0x128(%rsp), %rdi
callq 0x50da
leaq 0x28(%rsp), %rdi
callq 0x51a2
movl 0x2c10(%rbx), %ecx
movl 0x2c14(%rbx), %r8d
movl 0x2c18(%rbx), %r9d
leaq 0x128(%rsp), %rdi
movsd 0x13941(%rip), %xmm0    # 0x27210
movq %rbx, %rsi
movq 0x10(%rsp), %r14
movl %r14d, %edx
callq 0xa7a4
leaq 0x970(%rbx), %rax
movq %rax, 0x50(%rsp)
movslq %r14d, %rax
movq %rax, 0x20(%rsp)
movl %r14d, %eax
xorl %ecx, %ecx
testl %r13d, %r13d
cmovlel %ecx, %r13d
leal -0x1(%r14), %ecx
movq %rcx, 0x18(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0xc8(%rsp), %r15
leaq 0xe8(%rsp), %rsi
imulq $0x18, %rax, %rax
movq %rax, 0x48(%rsp)
xorl %r10d, %r10d
movq %rbx, 0x8(%rsp)
movslq 0x2c0c(%rbx), %rax
cmpq %rax, %r10
jge 0x13c4e
movq %r10, %rbp
movq %rsi, %rbx
leaq 0x1(%r10), %r14
movq %r14, %rsi
movq %rdi, %r12
callq 0x60a6
movq %r15, %rdi
leaq 0x141d0(%rip), %rsi     # 0x27b30
movq %r12, %rdx
callq 0x6082
movq %r14, (%rsp)
leaq 0xa8(%rsp), %rdi
movq %r15, %rsi
leaq 0x141be(%rip), %rdx     # 0x27b3c
callq 0xcf2e
movq 0x8(%rsp), %rax
movslq 0x2c0c(%rax), %rsi
movq %rbx, %r14
movq %rbx, %rdi
callq 0x60a6
leaq 0x28(%rsp), %r12
movq %r12, %rdi
leaq 0xa8(%rsp), %rsi
movq %r14, %rdx
callq 0x601b
leaq 0x108(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
leaq 0x13ef4(%rip), %rdx     # 0x278bb
callq 0xcf2e
movq 0x8(%rsp), %rax
movzbl 0x2c3c(%rax), %esi
movq %r14, %rdi
movq 0x50(%rsp), %rdx
callq 0x1768c
movq %r14, %rdi
callq 0x3170
movq %r12, %rdi
callq 0x3170
movq %rbx, %rdi
callq 0x3170
leaq 0xa8(%rsp), %rdi
callq 0x3170
movq %r15, %rdi
callq 0x3170
leaq 0x88(%rsp), %rdi
callq 0x3170
xorl %esi, %esi
testq %rbp, %rbp
sete %sil
leaq 0x128(%rsp), %r12
movq %r12, %rdi
callq 0xb1c6
movq 0x8(%rsp), %r14
movzbl 0x2c4f(%r14), %r8d
movzbl 0x2c3d(%r14), %r9d
movzbl 0x2c48(%r14), %eax
movq %r12, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
pushq %rbp
pushq %rax
callq 0xb66a
popq %rax
popq %rcx
cmpb $0x1, 0x2c4f(%r14)
movq %rbx, %rsi
movq (%rsp), %r10
jne 0x13b5a
movq 0x8(%rsp), %rax
movl 0x2d18(%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0x13adf
imulq $0x18, %rcx, %rdx
movq 0x340(%rsp), %rsi
addq %rdx, %rsi
addq 0x70(%rsp), %rdx
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %r8, %r13
je 0x13ad7
movq (%rsi), %r9
movsd (%r9,%r8,8), %xmm0
movq (%rdx), %r9
movq (%r9,%rdi), %r9
movsd %xmm0, (%r9,%rbp,8)
incq %r8
addq $0x18, %rdi
jmp 0x13ab3
incq %rcx
movq %rbx, %rsi
jmp 0x13a95
movq 0x8(%rsp), %rax
cmpb $0x1, 0x2c3f(%rax)
jne 0x13b5a
movq 0x8(%rsp), %rcx
movq 0x2c90(%rcx), %rax
subq 0x2c88(%rcx), %rax
shrq $0x5, %rax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0x13b5a
imulq $0x18, %rcx, %rdx
movq 0x358(%rsp), %rsi
addq %rdx, %rsi
addq 0x58(%rsp), %rdx
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %r8, %r13
je 0x13b52
movq (%rsi), %r9
movsd (%r9,%r8,8), %xmm0
movq (%rdx), %r9
movq (%r9,%rdi), %r9
movsd %xmm0, (%r9,%rbp,8)
incq %r8
addq $0x18, %rdi
jmp 0x13b2e
incq %rcx
movq %rbx, %rsi
jmp 0x13b10
imulq $0x18, 0x20(%rsp), %rax
movsd 0x290(%rsp), %xmm0
movq 0x8(%rsp), %rbx
movq 0x2e18(%rbx), %rcx
movq (%rcx,%rax), %rcx
movsd %xmm0, (%rcx,%rbp,8)
movsd 0x280(%rsp), %xmm1
cvtsi2sdl 0x2c14(%rbx), %xmm2
divsd %xmm2, %xmm1
movq 0x2e60(%rbx), %rcx
movq (%rcx,%rax), %rcx
movsd %xmm1, (%rcx,%rbp,8)
movsd 0x288(%rsp), %xmm0
divsd %xmm2, %xmm0
mulsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movq 0x2e78(%rbx), %rdx
movq (%rdx,%rax), %rdx
movsd %xmm0, (%rdx,%rbp,8)
mulsd 0x13f20(%rip), %xmm0    # 0x27af0
addsd (%rcx,%rbp,8), %xmm0
movq 0x2e90(%rbx), %rcx
movq (%rcx,%rax), %rdx
movsd %xmm0, (%rdx,%rbp,8)
cmpl $0x0, 0x10(%rsp)
leaq 0x88(%rsp), %rdi
jle 0x13931
movq 0x48(%rsp), %rdx
movq -0x18(%rcx,%rdx), %rcx
subsd (%rcx,%rbp,8), %xmm0
movq 0x30d8(%rbx), %rcx
movq (%rcx,%rax), %rax
movsd %xmm0, (%rax,%rbp,8)
cmpl $0x1, 0x10(%rsp)
je 0x13931
imulq $0x18, 0x18(%rsp), %rax
movq (%rcx,%rax), %rcx
subsd (%rcx,%rbp,8), %xmm0
andpd 0x13ec7(%rip), %xmm0    # 0x27b00
movq 0x30f0(%rbx), %rcx
movq (%rcx,%rax), %rax
movlpd %xmm0, (%rax,%rbp,8)
jmp 0x13931
cmpb $0x1, 0x2c4f(%rbx)
jne 0x13dc5
xorl %ecx, %ecx
imulq $0x18, 0x20(%rsp), %r14
movslq 0x2d18(%rbx), %rax
cmpq %rax, %rcx
jge 0x13d0c
movq %rcx, (%rsp)
imulq $0x18, %rcx, %r12
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0x13d00
movq 0x70(%rsp), %rax
movq (%rax,%r12), %rdi
addq %r15, %rdi
callq 0x14ada
movq 0x2da0(%rbx), %rax
movq (%rax,%r14), %rax
movq (%rax,%r12), %rax
movsd %xmm0, (%rax,%rbp,8)
movq 0x70(%rsp), %rax
movq (%rax,%r12), %rdi
addq %r15, %rdi
xorpd %xmm0, %xmm0
pushq $0x1
popq %rsi
callq 0x14b15
cvtsi2sdl 0x2c0c(%rbx), %xmm1
divsd %xmm1, %xmm0
ucomisd 0x133a2(%rip), %xmm0    # 0x27078
jb 0x13cde
sqrtsd %xmm0, %xmm0
jmp 0x13ce3
callq 0x32c0
movq 0x2db8(%rbx), %rax
movq (%rax,%r14), %rax
movq (%rax,%r12), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
addq $0x18, %r15
jmp 0x13c80
movq (%rsp), %rcx
incq %rcx
jmp 0x13c63
cmpb $0x1, 0x2c3f(%rbx)
jne 0x13dc5
xorl %ecx, %ecx
movq 0x2c90(%rbx), %rax
subq 0x2c88(%rbx), %rax
shrq $0x5, %rax
cltq
cmpq %rax, %rcx
jge 0x13dc5
movq %rcx, (%rsp)
imulq $0x18, %rcx, %r12
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0x13db9
movq 0x58(%rsp), %rax
movq (%rax,%r12), %rdi
addq %r15, %rdi
callq 0x14ada
movq 0x2dd0(%rbx), %rax
movq (%rax,%r14), %rax
movq (%rax,%r12), %rax
movsd %xmm0, (%rax,%rbp,8)
movq 0x58(%rsp), %rax
movq (%rax,%r12), %rdi
addq %r15, %rdi
xorpd %xmm0, %xmm0
pushq $0x1
popq %rsi
callq 0x14b15
ucomisd 0x132e9(%rip), %xmm0    # 0x27078
jb 0x13d97
sqrtsd %xmm0, %xmm0
jmp 0x13d9c
callq 0x32c0
movq 0x2de8(%rbx), %rax
movq (%rax,%r14), %rax
movq (%rax,%r12), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
addq $0x18, %r15
jmp 0x13d45
movq (%rsp), %rcx
incq %rcx
jmp 0x13d1b
movq 0x20(%rsp), %r12
imulq $0x18, %r12, %r14
movq 0x2e18(%rbx), %rdi
addq %r14, %rdi
callq 0x14ada
movq 0x10(%rsp), %r15
movq 0x2e30(%rbx), %rax
movsd %xmm0, (%rax,%r12,8)
cmpl $0x2, 0x2c0c(%rbx)
jl 0x13e3c
movq 0x2e18(%rbx), %rdi
addq %r14, %rdi
pushq $0x1
popq %rsi
xorpd %xmm0, %xmm0
callq 0x14b15
cvtsi2sdl 0x2c0c(%rbx), %xmm1
divsd %xmm1, %xmm0
ucomisd 0x13256(%rip), %xmm0    # 0x27078
jb 0x13e2a
sqrtsd %xmm0, %xmm0
jmp 0x13e2f
callq 0x32c0
movq 0x2e48(%rbx), %rax
movsd %xmm0, (%rax,%r12,8)
movq 0x2e90(%rbx), %rdi
addq %r14, %rdi
callq 0x14ada
movq 0x2ea8(%rbx), %rax
movsd %xmm0, (%rax,%r12,8)
cmpl $0x2, 0x2c0c(%rbx)
jl 0x13ea5
addq 0x2e90(%rbx), %r14
pushq $0x1
popq %rsi
xorpd %xmm0, %xmm0
movq %r14, %rdi
callq 0x14b15
cvtsi2sdl 0x2c0c(%rbx), %xmm1
divsd %xmm1, %xmm0
ucomisd 0x131ed(%rip), %xmm0    # 0x27078
jb 0x13e93
sqrtsd %xmm0, %xmm0
jmp 0x13e98
callq 0x32c0
movq 0x2ec0(%rbx), %rax
movsd %xmm0, (%rax,%r12,8)
cmpl $0x2, %r15d
jl 0x13f0a
imulq $0x18, 0x18(%rsp), %r14
movq 0x30f0(%rbx), %rdi
addq %r14, %rdi
callq 0x14ada
movsd %xmm0, (%rsp)
addq 0x2e90(%rbx), %r14
pushq $0x1
popq %rsi
xorpd %xmm0, %xmm0
movq %r14, %rdi
callq 0x14b15
ucomisd 0x13195(%rip), %xmm0    # 0x27078
jb 0x13eeb
sqrtsd %xmm0, %xmm0
jmp 0x13ef0
callq 0x32c0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x3108(%rbx), %rax
movq 0x18(%rsp), %rcx
movsd %xmm1, (%rax,%rcx,8)
leaq 0x128(%rsp), %rdi
callq 0xcfc4
leaq 0x58(%rsp), %rdi
callq 0x5066
leaq 0x70(%rsp), %rdi
callq 0x5066
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x1401e
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x50da
jmp 0x13f5a
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x51a2
jmp 0x14028
movq %rax, %rbx
jmp 0x14028
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x50da
jmp 0x13f86
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x51a2
jmp 0x14032
movq %rax, %rbx
jmp 0x14032
jmp 0x1400e
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3170
jmp 0x13fb4
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3170
jmp 0x13fc3
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x3170
jmp 0x13fd5
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3170
jmp 0x13fe7
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x3170
leaq 0x88(%rsp), %rdi
callq 0x3170
jmp 0x14011
movq %rax, %rbx
jmp 0x13ff4
jmp 0x1400e
jmp 0x1400e
jmp 0x1400e
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0xcfc4
leaq 0x58(%rsp), %rdi
callq 0x5066
leaq 0x70(%rsp), %rdi
callq 0x5066
movq %rbx, %rdi
callq 0x35a0