// File: /workspace/github_cpp_makefile_star2_O2/bobverity[P]MavericK/MCMCobject_noAdmixture.cpp
// Function: MCMCobject_noAdmixture::group_update()
void MCMCobject_noAdmixture::group_update() {
    
    // update group allocation for all individuals
    for (int ind=0; ind<n; ind++) {
        
        // subtract individual ind from allele counts
        for (int l=0; l<loci; l++) {
            for (int p=0; p<ploidy_vec[ind]; p++) {
                if (data[ind][l][p]!=0) {   // if not missing data
                    alleleCounts[group[ind]-1][l][data[ind][l][p]-1]--;
                    alleleCountsTotals[group[ind]-1][l]--;
                }
            }
        }
        
        // calculate probability of individual ind from all demes
        if (beta==0) {    // special case if beta==0 (draw from prior)
            logProbVec = vector<double>(K,-log(double(K)));
            probVec = vector<double>(K,1/double(K));
            probVecSum = 1.0;
        } else {
            for (int k=0; k<K; k++) {
                d_logLikeConditional(ind, k);   // update logProbVec[k]
            }
            logProbVecMax = *max_element(begin(logProbVec),end(logProbVec));
            probVecSum = 0;
            for (int k=0; k<K; k++) {
                probVec[k] = exp(beta*logProbVec[k]-beta*logProbVecMax);
                probVecSum += probVec[k];
            }
        }
        
        // resample grouping
        group[ind] = sample1(probVec, probVecSum);
        
        // add individual ind to allele counts
        for (int l=0; l<loci; l++) {
            for (int p=0; p<ploidy_vec[ind]; p++) {
                if (data[ind][l][p]!=0) {   // if not missing data
                    alleleCounts[group[ind]-1][l][data[ind][l][p]-1]++;
                    alleleCountsTotals[group[ind]-1][l]++;
                }
            }
        }
        
    }
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0x170(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x198(%rdi), %r15
xorl %r12d, %r12d
movslq 0x20(%rbx), %rax
cmpq %rax, %r12
jge 0xbd63
movq 0x40(%rbx), %rax
imulq $0x18, %r12, %rbp
xorl %ecx, %ecx
movslq 0x24(%rbx), %rdx
cmpq %rdx, %rcx
jge 0xbb6b
movq (%rbx), %rdx
addq %rbp, %rdx
movq 0x90(%rbx), %rsi
movq 0xa8(%rbx), %rdi
addq $-0x18, %rdi
movq 0xc0(%rbx), %r8
addq $-0x18, %r8
imulq $0x18, %rcx, %r9
xorl %r10d, %r10d
movslq (%rax,%r12,4), %r11
cmpq %r11, %r10
jge 0xbb66
movq (%rdx), %r11
movq (%r11,%r9), %r11
movslq (%r11,%r10,4), %r11
testq %r11, %r11
je 0xbb61
movslq (%rsi,%r12,4), %r14
imulq $0x18, %r14, %r14
movq (%rdi,%r14), %r14
movq (%r14,%r9), %r14
decl -0x4(%r14,%r11,4)
movslq (%rsi,%r12,4), %r11
imulq $0x18, %r11, %r11
movq (%r8,%r11), %r11
decl (%r11,%rcx,4)
incq %r10
jmp 0xbb23
incq %rcx
jmp 0xbaf0
movsd 0x78(%rbx), %xmm0
ucomisd 0x1b500(%rip), %xmm0    # 0x27078
jne 0xbcc3
jp 0xbcc3
movslq 0x1c(%rbx), %r14
cvtsi2sd %r14d, %xmm0
callq 0x32d0
xorpd 0x1b496(%rip), %xmm0    # 0x27030
movlpd %xmm0, 0x10(%rsp)
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
leaq 0x10(%rsp), %rdx
movq %r15, %r14
leaq 0xf(%rsp), %r15
movq %r15, %rcx
callq 0x5120
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x55b8
movq %r13, %rdi
callq 0x51a2
movslq 0x1c(%rbx), %rsi
cvtsi2sd %esi, %xmm0
movsd 0x1b62b(%rip), %xmm1    # 0x27210
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq %r13, %rdi
leaq 0x10(%rsp), %rdx
movq %r15, %rcx
movq %r14, %r15
callq 0x5120
movq %r14, %rdi
movq %r13, %rsi
callq 0x55b8
movq %r13, %rdi
callq 0x51a2
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x1b0(%rbx)
movsd 0x1b5e2(%rip), %xmm0    # 0x27210
movq %r15, %rdi
callq 0x17127
movq 0x90(%rbx), %rcx
movl %eax, (%rcx,%r12,4)
movq 0x40(%rbx), %rax
xorl %edx, %edx
movslq 0x24(%rbx), %rsi
cmpq %rsi, %rdx
jge 0xbcbb
movq (%rbx), %rsi
addq %rbp, %rsi
movq 0xa8(%rbx), %rdi
movq 0xc0(%rbx), %r8
addq $-0x18, %rdi
addq $-0x18, %r8
imulq $0x18, %rdx, %r9
xorl %r10d, %r10d
movslq (%rax,%r12,4), %r11
cmpq %r11, %r10
jge 0xbcb6
movq (%rsi), %r11
movq (%r11,%r9), %r11
movslq (%r11,%r10,4), %r11
testq %r11, %r11
je 0xbcb1
movslq (%rcx,%r12,4), %r14
imulq $0x18, %r14, %r14
movq (%rdi,%r14), %r14
movq (%r14,%r9), %r14
incl -0x4(%r14,%r11,4)
movslq (%rcx,%r12,4), %r11
imulq $0x18, %r11, %r11
movq (%r8,%r11), %r11
incl (%r11,%rdx,4)
incq %r10
jmp 0xbc73
incq %rdx
jmp 0xbc47
incq %r12
jmp 0xbad9
xorl %r14d, %r14d
cmpl 0x1c(%rbx), %r14d
jge 0xbcdf
movq %rbx, %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0xc4cc
incl %r14d
jmp 0xbcc6
movq 0x170(%rbx), %rdi
movq 0x178(%rbx), %rsi
callq 0xc694
movsd (%rax), %xmm0
movsd %xmm0, 0x190(%rbx)
andq $0x0, 0x1b0(%rbx)
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
movslq 0x1c(%rbx), %rax
cmpq %rax, %r14
jge 0xbc2e
movsd 0x78(%rbx), %xmm0
movq 0x170(%rbx), %rax
movsd 0x190(%rbx), %xmm1
mulsd %xmm0, %xmm1
mulsd (%rax,%r14,8), %xmm0
subsd %xmm1, %xmm0
callq 0x35c0
movq 0x198(%rbx), %rax
movsd %xmm0, (%rax,%r14,8)
addsd 0x1b0(%rbx), %xmm0
movsd %xmm0, 0x1b0(%rbx)
incq %r14
jmp 0xbd0d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq