// File: /workspace/github_cpp_makefile_star2_O2/bobverity[P]MavericK/TI.cpp
// Function: TI_noAdmixture(globals&, int)
void TI_noAdmixture(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // special case if K==1
    if (K==1) {
        for (int TIrep=0; TIrep<globals.thermodynamicRungs; TIrep++) {
            globals.TIpoint_mean[Kindex][TIrep] = globals.logEvidence_exhaustive[Kindex];
            globals.TIpoint_var[Kindex][TIrep] = 0;
            globals.TIpoint_SE[Kindex][TIrep] = 0;
        }
        globals.logEvidence_TI[Kindex] = globals.logEvidence_exhaustive[Kindex];
        globals.logEvidence_TI_SE[Kindex] = 0;
        return;
    }
    
    // set up beta vector
    vector<double> betaVec(globals.thermodynamicRungs);
    for (int TIrep=0; TIrep<globals.thermodynamicRungs; TIrep++)
        betaVec[TIrep] = double(TIrep)/(globals.thermodynamicRungs-1);
    
    // carry out thermodynamic integration
    for (int TIrep=0; TIrep<globals.thermodynamicRungs; TIrep++) {
        double beta = betaVec[TIrep];
        
        char * buffer = new char[255];
        sprintf(buffer, "%.2f", beta);
        string s = buffer;
        coutAndLog("  power = "+s+"\n", globals.outputLog_on, globals.outputLog_fileStream);
        
        // define MCMC object
        MCMCobject_noAdmixture TI_MCMC(globals, Kindex, globals.thermodynamicBurnin, globals.thermodynamicSamples, globals.thermodynamicThinning, beta);
        
        // perform MCMC
        TI_MCMC.reset(true);
        TI_MCMC.perform_MCMC(globals, false, true, false, false, false, 1);
        
        // calculate autocorrelation
        double autoCorr = calculateAutoCorr(TI_MCMC.logLikeGroup_store);
        double ESS = globals.thermodynamicSamples/autoCorr;
        
        // save results of this power
        globals.TIpoint_mean[Kindex][TIrep] = TI_MCMC.logLikeGroup_sum/double(globals.thermodynamicSamples);
        globals.TIpoint_var[Kindex][TIrep] = TI_MCMC.logLikeGroup_sumSquared/double(globals.thermodynamicSamples) - globals.TIpoint_mean[Kindex][TIrep]*globals.TIpoint_mean[Kindex][TIrep];
		// avoid arithmetic underflow
		if (globals.TIpoint_var[Kindex][TIrep]<0)
			globals.TIpoint_var[Kindex][TIrep] = 0;
        globals.TIpoint_SE[Kindex][TIrep] = sqrt(globals.TIpoint_var[Kindex][TIrep]/ESS);
        
    }
    
    // calculate thermodynamic integral estimate. Note that at this stage we assume equally spaced rungs.
    double Dsum = 0.5*globals.TIpoint_mean[Kindex][0] + 0.5*globals.TIpoint_mean[Kindex][globals.thermodynamicRungs-1];
    double Vsum = 0.25*globals.TIpoint_SE[Kindex][0]*globals.TIpoint_SE[Kindex][0] + 0.25*globals.TIpoint_SE[Kindex][globals.thermodynamicRungs-1]*globals.TIpoint_SE[Kindex][globals.thermodynamicRungs-1];
    if (globals.thermodynamicRungs>2) {
        for (int TIrep=1; TIrep<(globals.thermodynamicRungs-1); TIrep++) {
            Dsum += globals.TIpoint_mean[Kindex][TIrep];
            Vsum += globals.TIpoint_SE[Kindex][TIrep]*globals.TIpoint_SE[Kindex][TIrep];
        }
    }
    Dsum /= double(globals.thermodynamicRungs-1);
    Vsum /= double(globals.thermodynamicRungs-1)*double(globals.thermodynamicRungs-1);
    globals.logEvidence_TI[Kindex] = Dsum;
    globals.logEvidence_TI_SE[Kindex] = sqrt(Vsum);
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x378, %rsp            # imm = 0x378
movq %rdi, %rbx
movl 0x2bc8(%rdi), %eax
addl %esi, %eax
movl %esi, 0x14(%rsp)
movslq %esi, %rbp
cmpl $0x1, %eax
movq %rdi, (%rsp)
jne 0xc749
movl 0x2c20(%rbx), %eax
movq 0x2e00(%rbx), %rcx
imulq $0x18, %rbp, %rdx
movq 0x2ed8(%rbx), %rsi
addq %rdx, %rsi
movq 0x2ef0(%rbx), %rdi
addq %rdx, %rdi
addq 0x2f08(%rbx), %rdx
xorl %r8d, %r8d
testl %eax, %eax
cmovlel %r8d, %eax
movsd (%rcx,%rbp,8), %xmm0
cmpq %r8, %rax
je 0xc798
movq (%rsi), %r9
movsd %xmm0, (%r9,%r8,8)
movq (%rdi), %r9
andq $0x0, (%r9,%r8,8)
movq (%rdx), %r9
andq $0x0, (%r9,%r8,8)
incq %r8
jmp 0xc721
movslq 0x2c20(%rbx), %rsi
leaq 0x30(%rsp), %r14
leaq 0x88(%rsp), %rdx
movq %r14, %rdi
callq 0x4f6c
movl 0x2c20(%rbx), %eax
leal -0x1(%rax), %ecx
cvtsi2sd %ecx, %xmm0
movq (%r14), %rcx
xorl %edx, %edx
testl %eax, %eax
movl $0x0, %esi
cmovgl %eax, %esi
cmpq %rdx, %rsi
je 0xc7b9
cvtsi2sd %edx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
jmp 0xc781
movq (%rsp), %rcx
movq 0x2f20(%rcx), %rax
movsd %xmm0, (%rax,%rbp,8)
movq 0x2f38(%rcx), %rax
andq $0x0, (%rax,%rbp,8)
jmp 0xca88
movq (%rsp), %rdx
leaq 0x970(%rdx), %rcx
movq %rcx, 0x28(%rsp)
xorl %r13d, %r13d
leaq 0x68(%rsp), %r14
leaq 0x48(%rsp), %r12
pushq $0x1
popq %r15
movq %rbp, 0x18(%rsp)
imulq $0x18, %rbp, %rcx
movq %rdx, %rbp
movq %rcx, 0x8(%rsp)
movslq %eax, %rsi
cmpq %rsi, %r13
jge 0xc9ad
movq %r12, %rbx
movq 0x30(%rsp), %rax
movsd (%rax,%r13,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0xff, %edi
callq 0x3030
movq %rax, %r12
movq %rax, %rdi
leaq 0x1aa36(%rip), %rsi     # 0x27258
movsd 0x20(%rsp), %xmm0
movb $0x1, %al
callq 0x3080
movq %r14, %rdi
movq %r12, %rsi
leaq 0x88(%rsp), %rbp
movq %rbp, %rdx
callq 0x3130
movq %rbp, %rdi
leaq 0x1aa0e(%rip), %rsi     # 0x2725d
movq %r14, %rdx
callq 0xcf4d
movq %rbx, %r12
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0x1b054(%rip), %rdx     # 0x278bb
callq 0xcf2e
movq (%rsp), %rbx
movzbl 0x2c3c(%rbx), %esi
movq %r12, %rdi
movq 0x28(%rsp), %rdx
callq 0x1768c
movq %r12, %rdi
callq 0x3170
movq %rbp, %rdi
callq 0x3170
movl 0x2c24(%rbx), %ecx
movl 0x2c28(%rbx), %r8d
movl 0x2c2c(%rbx), %r9d
movq %rbp, %rdi
movq %rbx, %rsi
movl 0x14(%rsp), %edx
movsd 0x20(%rsp), %xmm0
callq 0xa7a4
movq %rbp, %rdi
movq %rbp, %rbx
movl %r15d, %ebp
movl %r15d, %esi
callq 0xb1c6
movq %rbx, %rdi
movq (%rsp), %rsi
xorl %edx, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x1
pushq $0x0
callq 0xb66a
popq %rax
popq %rcx
leaq 0x1b8(%rsp), %rdi
callq 0x16215
movq (%rsp), %rbp
cvtsi2sdl 0x2c28(%rbp), %xmm1
movsd 0x1b0(%rsp), %xmm2
divsd %xmm1, %xmm2
movq 0x2ed8(%rbp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %rax
movsd %xmm2, (%rax,%r13,8)
movsd 0x1d0(%rsp), %xmm3
divsd %xmm1, %xmm3
divsd %xmm0, %xmm1
mulsd %xmm2, %xmm2
subsd %xmm2, %xmm3
movq 0x2ef0(%rbp), %rax
movq (%rax,%rcx), %rax
xorpd %xmm0, %xmm0
maxsd %xmm3, %xmm0
movsd %xmm0, (%rax,%r13,8)
divsd %xmm1, %xmm0
ucomisd 0x1a714(%rip), %xmm0    # 0x27078
leaq 0x88(%rsp), %rbx
jb 0xc974
sqrtsd %xmm0, %xmm0
jmp 0xc979
callq 0x32c0
movq 0x2f08(%rbp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx), %rax
movsd %xmm0, (%rax,%r13,8)
movq %rbx, %rdi
callq 0xcfc4
movq %r14, %rdi
callq 0x3170
incq %r13
movl 0x2c20(%rbp), %eax
jmp 0xc7eb
movq 0x2ed8(%rbp), %rax
movq 0x2f08(%rbp), %rdx
movq 0x8(%rsp), %rdi
movq (%rax,%rdi), %rcx
leal -0x1(%rsi), %eax
movsd 0x1a879(%rip), %xmm1    # 0x27248
movsd -0x8(%rcx,%rsi,8), %xmm0
mulsd %xmm1, %xmm0
mulsd (%rcx), %xmm1
addsd %xmm0, %xmm1
movq (%rdx,%rdi), %rdx
movsd (%rdx), %xmm2
movsd 0x1a85f(%rip), %xmm3    # 0x27250
movapd %xmm2, %xmm0
mulsd %xmm3, %xmm0
movsd -0x8(%rdx,%rsi,8), %xmm4
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm3
mulsd %xmm2, %xmm0
addsd %xmm3, %xmm0
cmpl $0x3, %esi
jl 0xca3a
movl %eax, %esi
pushq $0x1
popq %rdi
movq 0x18(%rsp), %r14
cmpq %rdi, %rsi
je 0xca3f
addsd (%rcx,%rdi,8), %xmm1
movsd (%rdx,%rdi,8), %xmm2
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %rdi
jmp 0xca1e
movq 0x18(%rsp), %r14
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm2
divsd %xmm2, %xmm0
movq 0x2f20(%rbp), %rax
movsd %xmm1, (%rax,%r14,8)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xca6c
sqrtsd %xmm0, %xmm0
jmp 0xca71
callq 0x32c0
movq 0x2f38(%rbp), %rax
movsd %xmm0, (%rax,%r14,8)
leaq 0x30(%rsp), %rdi
callq 0x51a2
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xcaa3
jmp 0xcaa8
movq %rax, %rbx
jmp 0xcabc
movq %rax, %rbx
jmp 0xcae5
movq %rax, %rbx
jmp 0xcadb
jmp 0xcacb
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3170
leaq 0x88(%rsp), %rdi
callq 0x3170
jmp 0xcadb
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0xcfc4
leaq 0x68(%rsp), %rdi
callq 0x3170
leaq 0x30(%rsp), %rdi
callq 0x51a2
movq %rbx, %rdi
callq 0x35a0