// File: /workspace/github_cpp_makefile_star2_O1/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, 0xc(%rsp)
movslq %esi, %r15
cmpl $0x1, %eax
jne 0xef64
movslq 0x2c20(%rbx), %rax
testq %rax, %rax
jle 0xef36
movq 0x2e00(%rbx), %rcx
movq 0x2ed8(%rbx), %rdx
leaq (,%r15,8), %rsi
leaq (%rsi,%rsi,2), %rdi
movq (%rdx,%rdi), %rdx
movq 0x2ef0(%rbx), %rsi
movq (%rsi,%rdi), %rsi
movq 0x2f08(%rbx), %r8
movq (%r8,%rdi), %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movsd (%rcx,%r15,8), %xmm0
movsd %xmm0, (%rdx,%r9,8)
movq %r8, (%rsi,%r9,8)
movq %r8, (%rdi,%r9,8)
incq %r9
cmpq %r9, %rax
jne 0xef1a
movq 0x2e00(%rbx), %rax
movq 0x2f20(%rbx), %rcx
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rcx,%r15,8)
movq 0x2f38(%rbx), %rax
movq $0x0, (%rax,%r15,8)
jmp 0xf388
movslq 0x2c20(%rbx), %rsi
leaq 0x70(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x5916
movslq 0x2c20(%rbx), %rdx
testq %rdx, %rdx
jle 0xf043
leal -0x1(%rdx), %eax
cvtsi2sd %eax, %xmm0
movq 0x70(%rsp), %rax
leal 0x1(%rdx), %ecx
andl $-0x2, %ecx
decq %rdx
movq %rdx, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
movdqa 0x2809c(%rip), %xmm2    # 0x37050
xorl %edx, %edx
movdqa 0x280a2(%rip), %xmm3    # 0x37060
pxor %xmm3, %xmm1
pcmpeqd %xmm4, %xmm4
movdqa 0x282e2(%rip), %xmm5    # 0x372b0
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm1, %xmm7
pcmpeqd %xmm1, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0xf013
xorps %xmm7, %xmm7
cvtsi2sd %edx, %xmm7
divsd %xmm0, %xmm7
movsd %xmm7, (%rax,%rdx,8)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0xf036
leal 0x1(%rdx), %esi
xorps %xmm6, %xmm6
cvtsi2sd %esi, %xmm6
divsd %xmm0, %xmm6
movsd %xmm6, 0x8(%rax,%rdx,8)
addq $0x2, %rdx
paddq %xmm5, %xmm2
cmpq %rdx, %rcx
jne 0xefce
movl 0x2c20(%rbx), %eax
testl %eax, %eax
jle 0xf2a6
leaq 0x970(%rbx), %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
leaq 0x88(%rsp), %r12
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %r13
movq %r15, 0x18(%rsp)
leaq (%r15,%r15,2), %rax
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rax
movsd (%rax,%r14,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0xff, %edi
callq 0x3030
movq %rax, %r15
movq %rax, %rdi
leaq 0x28226(%rip), %rsi     # 0x372d0
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x3080
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq %r15, %rdi
callq 0x3140
movq %r15, %rdx
addq %rax, %rdx
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x6e56
movq %r12, %rdi
leaq 0x281ec(%rip), %rsi     # 0x372d5
movq %rbp, %rdx
callq 0xf984
leaq 0x40(%rsp), %r15
movq %r12, %rdi
leaq 0x28822(%rip), %rsi     # 0x37922
callq 0x35e0
movq %r15, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xf128
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0xf131
movupd (%rcx), %xmm0
movupd %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movzbl 0x2c3c(%rbx), %esi
leaq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rdx
callq 0x1db19
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0xf16e
callq 0x3310
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xf188
callq 0x3310
movl 0x2c24(%rbx), %ecx
movl 0x2c28(%rbx), %r8d
movl 0x2c2c(%rbx), %r9d
movq %r12, %rdi
movq %rbx, %rsi
movl 0xc(%rsp), %edx
movsd 0x10(%rsp), %xmm0
callq 0xc304
movq %r12, %rdi
movl $0x1, %esi
callq 0xd30e
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x1
pushq $0x0
callq 0xda82
addq $0x10, %rsp
leaq 0x1b8(%rsp), %rdi
callq 0x1c6b7
cvtsi2sdl 0x2c28(%rbx), %xmm1
movsd 0x1b0(%rsp), %xmm2
divsd %xmm1, %xmm2
movq 0x2ed8(%rbx), %rax
movq (%rax,%r13), %rax
movsd %xmm2, (%rax,%r14,8)
movsd 0x1d0(%rsp), %xmm3
divsd %xmm1, %xmm3
divsd %xmm0, %xmm1
mulsd %xmm2, %xmm2
subsd %xmm2, %xmm3
movq 0x2ef0(%rbx), %rax
movq (%rax,%r13), %rax
xorpd %xmm0, %xmm0
maxsd %xmm3, %xmm0
movsd %xmm0, (%rax,%r14,8)
divsd %xmm1, %xmm0
ucomisd 0x27e59(%rip), %xmm0    # 0x370a8
jb 0xf257
sqrtsd %xmm0, %xmm0
jmp 0xf25c
callq 0x3280
movq 0x2f08(%rbx), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax,%r14,8)
movq %r12, %rdi
callq 0xfa06
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xf28e
callq 0x3310
incq %r14
movslq 0x2c20(%rbx), %rax
cmpq %rax, %r14
jl 0xf082
movq 0x18(%rsp), %r15
leaq (,%r15,8), %rcx
leaq (%rcx,%rcx,2), %rdx
movq 0x2ed8(%rbx), %rcx
movq 0x2f08(%rbx), %rsi
movq (%rcx,%rdx), %rcx
movslq %eax, %rdi
decl %eax
movsd 0x27fef(%rip), %xmm1    # 0x372c0
movsd -0x8(%rcx,%rdi,8), %xmm0
mulsd %xmm1, %xmm0
mulsd (%rcx), %xmm1
addsd %xmm0, %xmm1
movq (%rsi,%rdx), %rdx
movsd (%rdx), %xmm2
movsd 0x27fd5(%rip), %xmm3    # 0x372c8
movapd %xmm2, %xmm0
mulsd %xmm3, %xmm0
movsd -0x8(%rdx,%rdi,8), %xmm4
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm3
mulsd %xmm2, %xmm0
addsd %xmm3, %xmm0
cmpl $0x3, %edi
jl 0xf337
movl %eax, %esi
movl $0x1, %edi
addsd (%rcx,%rdi,8), %xmm1
movsd (%rdx,%rdi,8), %xmm2
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm0
incq %rdi
cmpq %rdi, %rsi
jne 0xf31d
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm2
divsd %xmm2, %xmm0
movq 0x2f20(%rbx), %rax
movsd %xmm1, (%rax,%r15,8)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xf367
sqrtsd %xmm0, %xmm0
jmp 0xf36c
callq 0x3280
movq 0x2f38(%rbx), %rax
movsd %xmm0, (%rax,%r15,8)
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0xf388
callq 0x3310
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf39c
movq %rax, %rbx
jmp 0xf401
jmp 0xf3d6
movq %rax, %rbx
jmp 0xf3ba
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0xf3ba
callq 0x3310
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xf3ed
callq 0x3310
jmp 0xf3ed
movq %rax, %rbx
jmp 0xf3ed
jmp 0xf3dd
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0xfa06
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xf401
callq 0x3310
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0xf410
callq 0x3310
movq %rbx, %rdi
callq 0x3580