// File: 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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x28(%rsp)
movsd 0x88(%rax), %xmm0
movsd 0x90(%rax), %xmm1
callq 0x39310
movsd %xmm0, 0x48(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x48(%rsp), %xmm0
ja 0x14611
movsd 0x48(%rsp), %xmm0
movsd 0x47c01(%rip), %xmm1    # 0x5c208
ucomisd %xmm1, %xmm0
jbe 0x146c1
jmp 0x14613
movsd 0x47bf5(%rip), %xmm0    # 0x5c210
ucomisd 0x48(%rsp), %xmm0
jbe 0x14639
movsd 0x47bed(%rip), %xmm0    # 0x5c218
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x14613
jmp 0x1463b
movsd 0x48(%rsp), %xmm0
movsd 0x47bcf(%rip), %xmm1    # 0x5c218
ucomisd %xmm1, %xmm0
jbe 0x14669
movsd 0x48(%rsp), %xmm0
movsd 0x47bbb(%rip), %xmm1    # 0x5c218
subsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x1463b
xorps %xmm0, %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x14697
movsd 0x48(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
movsd 0x47b63(%rip), %xmm1    # 0x5c208
ucomisd %xmm1, %xmm0
jbe 0x146bf
movsd 0x47b65(%rip), %xmm0    # 0x5c218
subsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x146c1
movsd 0x48(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x146e0
jp 0x146e0
movsd 0x47b46(%rip), %xmm0    # 0x5c220
movsd %xmm0, 0x48(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movq 0x28(%rsp), %rcx
movl 0x34(%rsp), %eax
cmpl 0x20(%rcx), %eax
jge 0x148f1
movq 0x28(%rsp), %rax
cvtsi2sdl 0x1c(%rax), %xmm0
mulsd 0x88(%rax), %xmm0
callq 0x4340
movq 0x28(%rsp), %rdi
movsd %xmm0, 0x18(%rsp)
addq $0x1a0, %rdi            # imm = 0x1A0
movslq 0x34(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movq 0x28(%rsp), %rax
cvtsi2sdl (%rcx), %xmm1
cvtsi2sdl 0x1c(%rax), %xmm0
movsd 0x88(%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x4340
movq 0x28(%rsp), %rax
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
cvtsi2sdl 0x1c(%rax), %xmm0
mulsd 0x48(%rsp), %xmm0
callq 0x4340
movq 0x28(%rsp), %rdi
movsd %xmm0, 0x20(%rsp)
addq $0x1a0, %rdi            # imm = 0x1A0
movslq 0x34(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movq 0x28(%rsp), %rax
cvtsi2sdl (%rcx), %xmm1
cvtsi2sdl 0x1c(%rax), %xmm0
movsd 0x48(%rsp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x4340
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x0, 0x30(%rsp)
movq 0x28(%rsp), %rcx
movl 0x30(%rsp), %eax
cmpl 0x1c(%rcx), %eax
jge 0x148df
movq 0x28(%rsp), %rdi
addq $0x188, %rdi            # imm = 0x188
movslq 0x34(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x30(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movq 0x28(%rsp), %rax
cvtsi2sdl (%rcx), %xmm0
addsd 0x88(%rax), %xmm0
callq 0x4340
movq 0x28(%rsp), %rax
movsd %xmm0, 0x8(%rsp)
movsd 0x88(%rax), %xmm0
callq 0x4340
movq 0x28(%rsp), %rdi
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
addq $0x188, %rdi            # imm = 0x188
movslq 0x34(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0x30(%rsp), %rsi
callq 0x8ba0
cvtsi2sdl (%rax), %xmm0
addsd 0x48(%rsp), %xmm0
callq 0x4340
movsd %xmm0, 0x10(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x4340
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x147f4
jmp 0x148e1
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x146fa
xorps %xmm0, %xmm0
movsd 0x47904(%rip), %xmm1    # 0x5c200
callq 0x39150
movsd %xmm0, (%rsp)
movsd 0x38(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
callq 0x4760
movsd (%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x14935
movq 0x28(%rsp), %rax
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x88(%rax)
addq $0x58, %rsp
retq
nopw (%rax,%rax)