// File: /workspace/github_cpp_makefile_star2_O3/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 0x1d34e
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0xa043
ucomisd 0x2c227(%rip), %xmm0    # 0x36268
jbe 0xa0b5
movsd 0x2c225(%rip), %xmm1    # 0x36270
ucomisd %xmm0, %xmm1
jbe 0xa063
movsd 0x2c21f(%rip), %xmm2    # 0x36278
addsd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
ja 0xa059
ucomisd 0x2c20d(%rip), %xmm0    # 0x36278
jbe 0xa087
movsd 0x2c20b(%rip), %xmm1    # 0x36280
movsd 0x2c1fb(%rip), %xmm2    # 0x36278
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
ja 0xa07d
movapd %xmm0, %xmm1
movapd 0x2bfad(%rip), %xmm0    # 0x36040
xorpd %xmm1, %xmm0
maxsd %xmm1, %xmm0
ucomisd 0x2c1c5(%rip), %xmm0    # 0x36268
jbe 0xa0b5
movsd 0x2c1cb(%rip), %xmm1    # 0x36278
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
xorpd %xmm2, %xmm2
cmpeqsd %xmm0, %xmm2
movsd 0x2c1c2(%rip), %xmm1    # 0x36288
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, 0x10(%rsp)
cmpl $0x0, 0x20(%rbx)
jle 0xa272
movl 0x1c(%rbx), %eax
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movapd %xmm1, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %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
movl 0x1c(%rbx), %eax
testl %eax, %eax
jle 0xa25c
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 0xa1bb
incq %r14
movslq 0x20(%rbx), %rcx
movapd %xmm0, %xmm1
cmpq %rcx, %r14
jl 0xa0ec
jmp 0xa276
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movsd 0x2bfdc(%rip), %xmm1    # 0x36260
xorpd %xmm0, %xmm0
callq 0x1d178
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 0xa2be
movapd 0x10(%rsp), %xmm0
movsd %xmm0, 0x88(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq