// File: /workspace/github_cpp_makefile_star2_O3/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 $0x388, %rsp            # imm = 0x388
movq %rdi, %rbx
movl 0x2bc8(%rdi), %eax
movl %esi, 0x4(%rsp)
addl %esi, %eax
cmpl $0x1, %eax
jne 0xeaf0
movslq 0x2c20(%rbx), %rdx
testq %rdx, %rdx
jle 0xef60
movslq 0x4(%rsp), %rax
movq 0x2e00(%rbx), %rcx
movq 0x2ed8(%rbx), %rsi
leaq (,%rax,8), %rdi
leaq (%rdi,%rdi,2), %r8
movq (%rsi,%r8), %rsi
movq 0x2ef0(%rbx), %rdi
movq (%rdi,%r8), %rdi
movq 0x2f08(%rbx), %r9
movq (%r9,%r8), %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rsi,%r10,8)
movq %r9, (%rdi,%r10,8)
movq %r9, (%r8,%r10,8)
incq %r10
cmpq %r10, %rdx
jne 0xead0
jmp 0xef6c
movslq 0x2c20(%rbx), %rsi
leaq 0x60(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x588e
movslq 0x2c20(%rbx), %rax
testq %rax, %rax
jle 0xee77
leal -0x1(%rax), %ecx
cvtsi2sd %ecx, %xmm0
movq 0x60(%rsp), %rcx
leal 0x1(%rax), %edx
andl $-0x2, %edx
movq %rax, %rsi
decq %rsi
movq %rsi, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
movdqa 0x2750d(%rip), %xmm2    # 0x36050
xorl %esi, %esi
movdqa 0x27513(%rip), %xmm3    # 0x36060
pxor %xmm3, %xmm1
pcmpeqd %xmm4, %xmm4
movdqa 0x27753(%rip), %xmm5    # 0x362b0
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, %edi
notl %edi
testb $0x1, %dil
je 0xeba2
xorps %xmm7, %xmm7
cvtsi2sd %esi, %xmm7
divsd %xmm0, %xmm7
movsd %xmm7, (%rcx,%rsi,8)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edi
testb $0x1, %dil
je 0xebc5
leal 0x1(%rsi), %edi
xorps %xmm6, %xmm6
cvtsi2sd %edi, %xmm6
divsd %xmm0, %xmm6
movsd %xmm6, 0x8(%rcx,%rsi,8)
addq $0x2, %rsi
paddq %xmm5, %xmm2
cmpq %rsi, %rdx
jne 0xeb5d
testl %eax, %eax
jle 0xee77
leaq 0x50(%rsp), %r14
leaq 0x970(%rbx), %rax
movq %rax, 0x38(%rsp)
movslq 0x4(%rsp), %rcx
xorl %r13d, %r13d
leaq 0x78(%rsp), %r12
leaq 0x98(%rsp), %rbp
leaq (,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x28(%rsp)
movq %rbx, 0x8(%rsp)
movq %r13, %rax
movq %r12, %r13
movq %r14, %rbx
movq 0x60(%rsp), %r15
movq %rax, 0x10(%rsp)
movsd (%r15,%rax,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0xff, %edi
callq 0x3030
movq %rax, %r14
movq %rax, %rdi
leaq 0x27676(%rip), %rsi     # 0x362d0
movsd 0x18(%rsp), %xmm0
movb $0x1, %al
callq 0x3080
leaq 0x88(%rsp), %r15
movq %r15, 0x78(%rsp)
movq %r14, %rdi
callq 0x3140
movq %r14, %rdx
addq %rax, %rdx
movq %r13, %r12
movq %r13, %rdi
movq %r14, %rsi
callq 0x6d9c
movq %rbp, %rdi
leaq 0x2763b(%rip), %rsi     # 0x362d5
movq %r12, %rdx
callq 0xf5f6
movq %rbx, %r14
movq %rbp, %rdi
leaq 0x27c73(%rip), %rsi     # 0x36922
callq 0x35e0
movq %r14, 0x40(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq %r13, %r12
je 0xecda
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0xece3
movupd (%rcx), %xmm0
movupd %xmm0, (%r14)
movq 0x10(%rsp), %r13
movq 0x8(%rax), %rdx
movq %rdx, 0x48(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x8(%rsp), %rax
movzbl 0x2c3c(%rax), %esi
leaq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rdx
callq 0x1d7c5
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0xed2a
callq 0x3310
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xed44
callq 0x3310
movq 0x8(%rsp), %rsi
movl 0x2c24(%rsi), %ecx
movl 0x2c28(%rsi), %r8d
movl 0x2c2c(%rsi), %r9d
movq %rbp, %rdi
movl 0x4(%rsp), %edx
movsd 0x18(%rsp), %xmm0
callq 0xc0a0
movq %rbp, %rdi
movl $0x1, %esi
callq 0xcf3c
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
xorl %edx, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x1
pushq $0x0
callq 0xd632
addq $0x10, %rsp
leaq 0x1c8(%rsp), %rdi
callq 0x1c398
movq 0x8(%rsp), %rcx
cvtsi2sdl 0x2c28(%rcx), %xmm1
movsd 0x1c0(%rsp), %xmm2
divsd %xmm1, %xmm2
movq 0x2ed8(%rcx), %rax
movq 0x30(%rsp), %rdx
movq (%rax,%rdx), %rax
movsd %xmm2, (%rax,%r13,8)
movsd 0x1e0(%rsp), %xmm3
divsd %xmm1, %xmm3
divsd %xmm0, %xmm1
mulsd %xmm2, %xmm2
subsd %xmm2, %xmm3
movq 0x2ef0(%rcx), %rax
movq (%rax,%rdx), %rax
xorpd %xmm0, %xmm0
maxsd %xmm3, %xmm0
movsd %xmm0, (%rax,%r13,8)
divsd %xmm1, %xmm0
ucomisd 0x2728f(%rip), %xmm0    # 0x360a8
jb 0xee21
sqrtsd %xmm0, %xmm0
jmp 0xee26
callq 0x3280
movq 0x8(%rsp), %rax
movq 0x2f08(%rax), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax,%r13,8)
movq %rbp, %rdi
callq 0xf678
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0xee58
callq 0x3310
incq %r13
movq 0x8(%rsp), %rbx
movslq 0x2c20(%rbx), %rax
cmpq %rax, %r13
jl 0xec24
movq 0x20(%rsp), %r14
jmp 0xee7c
movslq 0x4(%rsp), %r14
leaq (,%r14,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 0x27419(%rip), %xmm1    # 0x362c0
movsd -0x8(%rcx,%rdi,8), %xmm0
mulsd %xmm1, %xmm0
mulsd (%rcx), %xmm1
addsd %xmm0, %xmm1
movq (%rsi,%rdx), %rdx
movsd (%rdx), %xmm2
movsd 0x273ff(%rip), %xmm3    # 0x362c8
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 0xef0d
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 0xeef3
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm2, %xmm2
divsd %xmm2, %xmm0
movq 0x2f20(%rbx), %rax
movsd %xmm1, (%rax,%r14,8)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xef3d
sqrtsd %xmm0, %xmm0
jmp 0xef42
callq 0x3280
movq 0x2f38(%rbx), %rax
movsd %xmm0, (%rax,%r14,8)
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xef8c
callq 0x3310
jmp 0xef8c
movq 0x2e00(%rbx), %rcx
movslq 0x4(%rsp), %rax
movsd (%rcx,%rax,8), %xmm0
movq 0x2f20(%rbx), %rcx
movsd %xmm0, (%rcx,%rax,8)
movq 0x2f38(%rbx), %rcx
movq $0x0, (%rcx,%rax,8)
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0xf015
movq %rax, %rbx
jmp 0xf00b
jmp 0xefdd
movq %rax, %rbx
jmp 0xefc1
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0xefc1
callq 0x3310
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xeff4
callq 0x3310
jmp 0xeff4
movq %rax, %rbx
jmp 0xeff4
jmp 0xefe4
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0xf678
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xf00b
callq 0x3310
movq 0x60(%rsp), %r15
testq %r15, %r15
je 0xf01d
movq %r15, %rdi
callq 0x3310
movq %rbx, %rdi
callq 0x3580