// File: bobverity[P]MavericK/MCMCobject_admixture.cpp
// Function: MCMCobject_admixture::group_update()
void MCMCobject_admixture::group_update() {
    
    // update group allocation for this gene copy
    groupIndex=-1;
    for (int ind=0; ind<n; ind++) {
        for (int l=0; l<loci; l++) {
            for (int p=0; p<ploidy_vec[ind]; p++) {
                groupIndex++;
                
                // subtract this gene copy from allele counts and admix counts
                if (data[ind][l][p]!=0) {   // if not missing data
                    alleleCounts[linearGroup[groupIndex]-1][l][data[ind][l][p]-1]--;
                    alleleCountsTotals[linearGroup[groupIndex]-1][l]--;
                    
                    admixCounts[ind][linearGroup[groupIndex]-1]--;
                    admixCountsTotals[ind]--;
                }
                
                // calculate probability of this gene copy from all demes
                thisData = data[ind][l][p];
                probVecSum = 0;
                for (int k=0; k<K; k++) {
                    if (thisData==0) {
                        logProbVec[k] = 0;
                    } else {
                        thisAlleleCounts = alleleCounts[k][l][thisData-1];
                        thisAlleleCountsTotals = alleleCountsTotals[k][l];
                        if ((thisAlleleCounts<int(1e4)) && (thisAlleleCountsTotals<int(1e4))) {
                            logProbVec[k] = beta*log_lookup_0[thisAlleleCounts] - beta*log_lookup[thisAlleleCountsTotals][J[l]-1];
                        } else {
                            logProbVec[k] = beta*log((thisAlleleCounts + lambda)/double(thisAlleleCountsTotals + J[l]*lambda));
                        }
                    }
                    probVec[k] = double(admixCounts[ind][k]+alpha)*exp(logProbVec[k]);
                    probVecSum += probVec[k];
                }
                
                // resample grouping
                linearGroup[groupIndex] = sample1(probVec, probVecSum);
                group[ind][l][p] = linearGroup[groupIndex];
                
                // add this gene copy to allele counts and admix counts
                if (data[ind][l][p]!=0) {   // if not missing data
                    alleleCounts[linearGroup[groupIndex]-1][l][data[ind][l][p]-1]++;
                    alleleCountsTotals[linearGroup[groupIndex]-1][l]++;
                    
                    admixCounts[ind][linearGroup[groupIndex]-1]++;
                    admixCountsTotals[ind]++;
                }
            } // p
        } // l
    } // ind
    
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0xa8(%rsp)
movl $0xffffffff, 0x108(%rax) # imm = 0xFFFFFFFF
movl $0x0, 0xbc(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xbc(%rsp), %eax
cmpl 0x20(%rcx), %eax
jge 0x131dc
movl $0x0, 0xb8(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xb8(%rsp), %eax
cmpl 0x24(%rcx), %eax
jge 0x131c4
movl $0x0, 0xb4(%rsp)
movq 0xa8(%rsp), %rdi
movl 0xb4(%rsp), %eax
movl %eax, 0xa4(%rsp)
addq $0x40, %rdi
movslq 0xbc(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movl 0xa4(%rsp), %eax
cmpl (%rcx), %eax
jge 0x131ac
movq 0xa8(%rsp), %rdi
movl 0x108(%rdi), %eax
addl $0x1, %eax
movl %eax, 0x108(%rdi)
movslq 0xbc(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8ba0
cmpl $0x0, (%rax)
je 0x12b31
movq 0xa8(%rsp), %rax
movq %rax, %rcx
addq $0x110, %rcx            # imm = 0x110
movq %rcx, 0x80(%rsp)
movq %rax, %rdi
addq $0xc0, %rdi
movslq 0x108(%rax), %rsi
callq 0x8ba0
movq 0x80(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq 0xa8(%rsp), %rdi
movq %rax, 0x88(%rsp)
movslq 0xbc(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8ba0
movq 0x88(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8ba0
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movl (%rcx), %edx
addl $-0x1, %edx
movl %edx, (%rcx)
movq %rax, %rcx
addq $0x128, %rcx            # imm = 0x128
movq %rcx, 0x90(%rsp)
movq %rax, %rdi
addq $0xc0, %rdi
movslq 0x108(%rax), %rsi
callq 0x8ba0
movq 0x90(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8ba0
movq 0xa8(%rsp), %rdi
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
addq $0x188, %rdi            # imm = 0x188
movslq 0xbc(%rsp), %rsi
callq 0x8c60
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movq %rcx, 0x98(%rsp)
movq %rax, %rdi
addq $0xc0, %rdi
movslq 0x108(%rax), %rsi
callq 0x8ba0
movq 0x98(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8ba0
movq 0xa8(%rsp), %rdi
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
addq $0x1a0, %rdi            # imm = 0x1A0
movslq 0xbc(%rsp), %rsi
callq 0x8ba0
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq 0xa8(%rsp), %rdi
movslq 0xbc(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0xb0(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, 0x278(%rax)
movl $0x0, 0xb0(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xb0(%rsp), %eax
cmpl 0x1c(%rcx), %eax
jge 0x12f2d
movq 0xa8(%rsp), %rax
cmpl $0x0, 0xb0(%rax)
jne 0x12be0
movq 0xa8(%rsp), %rdi
addq $0x238, %rdi            # imm = 0x238
movslq 0xb0(%rsp), %rsi
callq 0x8c20
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x12e40
movq 0xa8(%rsp), %rdi
addq $0x110, %rdi            # imm = 0x110
movslq 0xb0(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movq 0xa8(%rsp), %rax
movl 0xb0(%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8ba0
movq 0xa8(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0xb4(%rdi)
addq $0x128, %rdi            # imm = 0x128
movslq 0xb0(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8ba0
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movl (%rcx), %ecx
movl %ecx, 0xb8(%rax)
cmpl $0x2710, 0xb4(%rax)     # imm = 0x2710
jge 0x12d8c
movq 0xa8(%rsp), %rax
cmpl $0x2710, 0xb8(%rax)     # imm = 0x2710
jge 0x12d8c
movq 0xa8(%rsp), %rax
movsd 0x98(%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
movslq 0xb4(%rax), %rsi
leaq 0x5a77d(%rip), %rdi     # 0x6d438
callq 0x8c20
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x98(%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movslq 0xb8(%rax), %rsi
leaq 0x5a72f(%rip), %rdi     # 0x6d420
callq 0x8bc0
movq 0xa8(%rsp), %rdi
movq %rax, 0x58(%rsp)
addq $0x28, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8ba0
movq 0x58(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8c20
movsd 0x60(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
movsd 0x70(%rsp), %xmm2
movq 0xa8(%rsp), %rdi
mulsd (%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
addq $0x238, %rdi            # imm = 0x238
movslq 0xb0(%rsp), %rsi
callq 0x8c20
movsd 0x78(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x12e3e
movq 0xa8(%rsp), %rdi
movsd 0x98(%rdi), %xmm0
movsd %xmm0, 0x48(%rsp)
cvtsi2sdl 0xb4(%rdi), %xmm0
addsd 0x78(%rdi), %xmm0
movsd %xmm0, 0x40(%rsp)
cvtsi2sdl 0xb8(%rdi), %xmm0
movsd %xmm0, 0x38(%rsp)
addq $0x28, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8ba0
movsd 0x38(%rsp), %xmm2
movsd 0x40(%rsp), %xmm0
movq %rax, %rcx
movq 0xa8(%rsp), %rax
cvtsi2sdl (%rcx), %xmm1
movsd 0x78(%rax), %xmm3
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
callq 0x4390
movq 0xa8(%rsp), %rdi
movaps %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
addq $0x238, %rdi            # imm = 0x238
movslq 0xb0(%rsp), %rsi
callq 0x8c20
movsd 0x50(%rsp), %xmm0
movsd %xmm0, (%rax)
jmp 0x12e40
movq 0xa8(%rsp), %rdi
addq $0x188, %rdi            # imm = 0x188
movslq 0xbc(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb0(%rsp), %rsi
callq 0x8ba0
movq 0xa8(%rsp), %rdi
cvtsi2sdl (%rax), %xmm0
addsd 0x88(%rdi), %xmm0
movsd %xmm0, 0x28(%rsp)
addq $0x238, %rdi            # imm = 0x238
movslq 0xb0(%rsp), %rsi
callq 0x8c20
movsd (%rax), %xmm0
callq 0x4760
movq 0xa8(%rsp), %rdi
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
addq $0x260, %rdi            # imm = 0x260
movslq 0xb0(%rsp), %rsi
callq 0x8c20
movsd 0x30(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
movsd %xmm0, (%rax)
addq $0x260, %rdi            # imm = 0x260
movslq 0xb0(%rsp), %rsi
callq 0x8c20
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movsd (%rcx), %xmm0
addsd 0x278(%rax), %xmm0
movsd %xmm0, 0x278(%rax)
movl 0xb0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb0(%rsp)
jmp 0x12b8f
movq 0xa8(%rsp), %rax
movq %rax, %rdi
addq $0x260, %rdi            # imm = 0x260
movsd 0x278(%rax), %xmm0
callq 0x39240
movl %eax, %ecx
movq 0xa8(%rsp), %rax
movl %ecx, 0x20(%rsp)
movq %rax, %rdi
addq $0xc0, %rdi
movslq 0x108(%rax), %rsi
callq 0x8ba0
movl 0x20(%rsp), %edx
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movl %edx, (%rcx)
movq %rax, %rdi
addq $0xc0, %rdi
movslq 0x108(%rax), %rsi
callq 0x8ba0
movq 0xa8(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x24(%rsp)
addq $0xd8, %rdi
movslq 0xbc(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8ba0
movl 0x24(%rsp), %ecx
movq 0xa8(%rsp), %rdi
movl %ecx, (%rax)
movslq 0xbc(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8ba0
cmpl $0x0, (%rax)
je 0x13194
movq 0xa8(%rsp), %rax
movq %rax, %rcx
addq $0x110, %rcx            # imm = 0x110
movq %rcx, (%rsp)
movq %rax, %rdi
addq $0xc0, %rdi
movslq 0x108(%rax), %rsi
callq 0x8ba0
movq (%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq 0xa8(%rsp), %rdi
movq %rax, 0x8(%rsp)
movslq 0xbc(%rsp), %rsi
callq 0x8c40
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb4(%rsp), %rsi
callq 0x8ba0
movq 0x8(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8ba0
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movl (%rcx), %edx
addl $0x1, %edx
movl %edx, (%rcx)
movq %rax, %rcx
addq $0x128, %rcx            # imm = 0x128
movq %rcx, 0x10(%rsp)
movq %rax, %rdi
addq $0xc0, %rdi
movslq 0x108(%rax), %rsi
callq 0x8ba0
movq 0x10(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8c60
movq %rax, %rdi
movslq 0xb8(%rsp), %rsi
callq 0x8ba0
movq 0xa8(%rsp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
addq $0x188, %rdi            # imm = 0x188
movslq 0xbc(%rsp), %rsi
callq 0x8c60
movq %rax, %rcx
movq 0xa8(%rsp), %rax
movq %rcx, 0x18(%rsp)
movq %rax, %rdi
addq $0xc0, %rdi
movslq 0x108(%rax), %rsi
callq 0x8ba0
movq 0x18(%rsp), %rdi
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x8ba0
movq 0xa8(%rsp), %rdi
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
addq $0x1a0, %rdi            # imm = 0x1A0
movslq 0xbc(%rsp), %rsi
callq 0x8ba0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x13196
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x1291a
jmp 0x131ae
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x128f7
jmp 0x131c6
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x128d4
addq $0xc8, %rsp
retq
nopw %cs:(%rax,%rax)