// File: /workspace/github_cpp_makefile_star2_O2/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 0x17188
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x896b
ucomisd 0x1e8af(%rip), %xmm0    # 0x27218
jbe 0x89c3
movsd 0x1e8ad(%rip), %xmm2    # 0x27220
movsd 0x1e8ad(%rip), %xmm1    # 0x27228
ucomisd %xmm0, %xmm2
jbe 0x8987
addsd %xmm1, %xmm0
jmp 0x897b
movsd 0x1e8a9(%rip), %xmm2    # 0x27238
ucomisd %xmm1, %xmm0
jbe 0x899b
addsd %xmm2, %xmm0
jmp 0x898f
movapd 0x1e68d(%rip), %xmm2    # 0x27030
xorpd %xmm0, %xmm2
maxsd %xmm0, %xmm2
ucomisd 0x1e865(%rip), %xmm2    # 0x27218
jbe 0x89bf
subsd %xmm2, %xmm1
movapd %xmm1, %xmm0
jmp 0x89c3
movapd %xmm2, %xmm0
xorpd %xmm2, %xmm2
cmpeqsd %xmm0, %xmm2
movsd 0x1e85c(%rip), %xmm1    # 0x27230
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
xorl %r14d, %r14d
movslq 0x20(%rbx), %rax
cmpq %rax, %r14
jge 0x8b53
cvtsi2sdl 0x1c(%rbx), %xmm0
mulsd 0x88(%rbx), %xmm0
callq 0x32a0
movq 0x1a0(%rbx), %rax
cvtsi2sdl (%rax,%r14,4), %xmm2
cvtsi2sdl 0x1c(%rbx), %xmm1
movapd %xmm0, (%rsp)
mulsd 0x88(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x32a0
movapd %xmm0, 0x40(%rsp)
cvtsi2sdl 0x1c(%rbx), %xmm0
mulsd 0x10(%rsp), %xmm0
callq 0x32a0
movapd %xmm0, 0x30(%rsp)
movq 0x1a0(%rbx), %rax
cvtsi2sdl (%rax,%r14,4), %xmm1
cvtsi2sdl 0x1c(%rbx), %xmm0
mulsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
callq 0x32a0
movapd (%rsp), %xmm1
unpcklpd 0x30(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movapd 0x40(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
subpd %xmm2, %xmm1
movapd 0x20(%rsp), %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
imulq $0x18, %r14, %r15
xorl %r12d, %r12d
movslq 0x1c(%rbx), %rax
cmpq %rax, %r12
jge 0x8b4b
movq 0x188(%rbx), %rax
movq (%rax,%r15), %rax
cvtsi2sdl (%rax,%r12,4), %xmm0
addsd 0x88(%rbx), %xmm0
callq 0x32a0
movapd %xmm0, (%rsp)
movsd 0x88(%rbx), %xmm0
callq 0x32a0
movaps %xmm0, 0x40(%rsp)
movq 0x188(%rbx), %rax
movq (%rax,%r15), %rax
cvtsi2sdl (%rax,%r12,4), %xmm0
addsd 0x10(%rsp), %xmm0
callq 0x32a0
movapd %xmm0, 0x30(%rsp)
movapd 0x10(%rsp), %xmm0
callq 0x32a0
movapd (%rsp), %xmm1
unpcklpd 0x30(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movapd 0x40(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
subpd %xmm2, %xmm1
movapd 0x20(%rsp), %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
incq %r12
jmp 0x8aab
incq %r14
jmp 0x89f3
movsd 0x1e6b5(%rip), %xmm1    # 0x27210
xorpd %xmm0, %xmm0
callq 0x1707c
movsd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
subsd %xmm1, %xmm0
callq 0x35c0
ucomisd (%rsp), %xmm0
jbe 0x8b95
movapd 0x10(%rsp), %xmm0
movsd %xmm0, 0x88(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop