// File: /workspace/github_cpp_makefile_star2_O1/bobverity[P]MavericK/MCMCobject_admixture.cpp
// Function: MCMCobject_admixture::alpha_update()
void MCMCobject_admixture::alpha_update() {
    
    double alpha_new = rnorm1(alpha,alphaPropSD);
    
    // reflect off boundries at 0 and 10
    if (alpha_new<0 || alpha_new>10) {
        // use multiple reflections to bring into range [-10,+20]
        while (alpha_new< -10)
            alpha_new += 20;
        while (alpha_new> 20)
            alpha_new -= 20;
        
        // use one more reflection to bring into range [0,10]
        if (alpha_new<0)
            alpha_new = -alpha_new;
        if (alpha_new>10)
            alpha_new = 20-alpha_new;
    }
    
    // don't let alpha_new equal exactly 0 (to avoid nan values)
    if (alpha_new==0) {
        alpha_new = UNDERFLO;
    }
    
    // calculate likelihood under old and new alpha values. Likelihood only derives from admixture proportions - not allele freqencies
    double logProb_old = 0;
    double logProb_new = 0;
    for (int i=0; i<n; i++) {
        logProb_old += my_lgamma(K*alpha)-my_lgamma(admixCountsTotals[i]+K*alpha);
        logProb_new += my_lgamma(K*alpha_new)-my_lgamma(admixCountsTotals[i]+K*alpha_new);
        for (int k=0; k<K; k++) {
            logProb_old += my_lgamma(admixCounts[i][k]+alpha)-my_lgamma(alpha);
            logProb_new += my_lgamma(admixCounts[i][k]+alpha_new)-my_lgamma(alpha_new);
        }
    }
    // perform Metropolis step
    if (runif1(0.0,1.0)<exp(logProb_new-logProb_old)) {
        alpha = alpha_new;
    }
    
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movsd 0x88(%rdi), %xmm0
movsd 0x90(%rdi), %xmm1
callq 0x1d6a2
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0xa3a5
ucomisd 0x2cec5(%rip), %xmm0    # 0x37268
jbe 0xa417
movsd 0x2cec3(%rip), %xmm1    # 0x37270
ucomisd %xmm0, %xmm1
jbe 0xa3c5
movsd 0x2cebd(%rip), %xmm2    # 0x37278
addsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
ja 0xa3bb
ucomisd 0x2ceab(%rip), %xmm0    # 0x37278
jbe 0xa3e9
movsd 0x2cea9(%rip), %xmm1    # 0x37280
movsd 0x2ce99(%rip), %xmm2    # 0x37278
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
ja 0xa3df
movapd %xmm0, %xmm1
movapd 0x2cc4b(%rip), %xmm0    # 0x37040
xorpd %xmm1, %xmm0
maxsd %xmm1, %xmm0
ucomisd 0x2ce63(%rip), %xmm0    # 0x37268
jbe 0xa417
movsd 0x2ce69(%rip), %xmm1    # 0x37278
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm2, %xmm2
cmpeqsd %xmm0, %xmm2
movsd 0x2ce60(%rip), %xmm1    # 0x37288
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, 0x10(%rsp)
cmpl $0x0, 0x20(%rbx)
jle 0xa5d1
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movapd %xmm1, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x1c(%rbx), %xmm0
mulsd 0x88(%rbx), %xmm0
callq 0x3260
movq 0x1a0(%rbx), %rax
xorps %xmm2, %xmm2
cvtsi2sdl (%rax,%r14,4), %xmm2
xorps %xmm1, %xmm1
cvtsi2sdl 0x1c(%rbx), %xmm1
movapd %xmm0, 0x20(%rsp)
mulsd 0x88(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x3260
movapd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x1c(%rbx), %xmm0
mulsd 0x10(%rsp), %xmm0
callq 0x3260
movapd %xmm0, 0x30(%rsp)
movq 0x1a0(%rbx), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%r14,4), %xmm1
xorps %xmm0, %xmm0
cvtsi2sdl 0x1c(%rbx), %xmm0
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
callq 0x3260
movapd 0x20(%rsp), %xmm1
unpcklpd 0x30(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movapd 0x40(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd %xmm1, %xmm0
subpd %xmm2, %xmm0
addpd (%rsp), %xmm0
cmpl $0x0, 0x1c(%rbx)
jle 0xa5bb
leaq (,%r14,8), %rax
leaq (%rax,%rax,2), %r15
xorl %r12d, %r12d
movapd %xmm0, 0x20(%rsp)
movq 0x188(%rbx), %rax
movq (%rax,%r15), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r12,4), %xmm0
addsd 0x88(%rbx), %xmm0
callq 0x3260
movapd %xmm0, (%rsp)
movsd 0x88(%rbx), %xmm0
callq 0x3260
movaps %xmm0, 0x40(%rsp)
movq 0x188(%rbx), %rax
movq (%rax,%r15), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r12,4), %xmm0
addsd 0x10(%rsp), %xmm0
callq 0x3260
movapd %xmm0, 0x30(%rsp)
movapd 0x10(%rsp), %xmm0
callq 0x3260
movapd (%rsp), %xmm1
unpcklpd 0x30(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movapd 0x40(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
movapd 0x20(%rsp), %xmm0
subpd %xmm2, %xmm1
addpd %xmm1, %xmm0
incq %r12
movslq 0x1c(%rbx), %rax
cmpq %rax, %r12
jl 0xa51a
incq %r14
movslq 0x20(%rbx), %rax
movapd %xmm0, %xmm1
cmpq %rax, %r14
jl 0xa44b
jmp 0xa5d5
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movsd 0x2cc7d(%rip), %xmm1    # 0x37260
xorpd %xmm0, %xmm0
callq 0x1d4cc
movsd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
subsd %xmm1, %xmm0
callq 0x35a0
ucomisd (%rsp), %xmm0
jbe 0xa61d
movapd 0x10(%rsp), %xmm0
movsd %xmm0, 0x88(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop