// File: /workspace/github_cpp_makefile_star2_O3/bobverity[P]MavericK/exhaustive.cpp
// Function: exhaustive_noAdmix(globals&, int)
void exhaustive_noAdmix(globals &globals, int Kindex) {
    int K = globals.Kmin+Kindex;
    
    // initialise group
    vector<int> group(globals.n,1);
    vector<int> newGroup = group;
    
    // initialise alleleCounts array
    vector< vector< vector<int> > > alleleCounts(K);
    vector< vector<int> > alleleCountsTotals(K);
    for (int k=0; k<K; k++) {
        alleleCounts[k] = vector< vector<int> >(globals.loci);
        alleleCountsTotals[k] = vector<int>(globals.loci);
        for (int l=0; l<globals.loci; l++) {
            alleleCounts[k][l] = vector<int>(globals.J[l]);
        }
    }
    
    // populate alleleCounts array and calculate starting likelihood
    double logLike=0;
    for (int ind=0; ind<globals.n; ind++) {
        for (int l=0; l<globals.loci; l++) {
            for (int p=0; p<globals.ploidy_vec[ind]; p++) {
                if (globals.data[ind][l][p]!=0) {
                    logLike += log(alleleCounts[group[ind]-1][l][globals.data[ind][l][p]-1] + globals.lambda) - log(alleleCountsTotals[group[ind]-1][l] + globals.J[l]*globals.lambda);
                    alleleCounts[group[ind]-1][l][globals.data[ind][l][p]-1]++;
                    alleleCountsTotals[group[ind]-1][l]++;
                }
            }
        }
    }
    double combined_logLike = logLike -globals.n*log(double(K));
    combined_logLike += log(double(K));
    
    // loop through all possible groupings
    int uniques = 0;  // number of unique elements in group. Forms part of combinatorial constant needed to calculate correct likelihood when only searching over unique partitions (see Notes.c for details)
    double logLike_total = combined_logLike;
    while (group[0]!=0) {
        
        increment_restrictedGrowth(newGroup,K);
        if (newGroup[0]==0)
            break;
        
        // loop through all individuals
        for (int ind=0; ind<globals.n; ind++) {
            
            // if group allocation for this individual has changed
            if (newGroup[ind]!=group[ind]) {
                
                // subtract old group from allele counts and likelihood
                for (int l=0; l<globals.loci; l++) {
                    for (int p=0; p<globals.ploidy_vec[ind]; p++) {
                        if (globals.data[ind][l][p]!=0) {
                            alleleCountsTotals[group[ind]-1][l]--;
                            alleleCounts[group[ind]-1][l][globals.data[ind][l][p]-1]--;
                            logLike -= log(alleleCounts[group[ind]-1][l][globals.data[ind][l][p]-1] + globals.lambda) - log(alleleCountsTotals[group[ind]-1][l] + globals.J[l]*globals.lambda);
                        }
                    }
                }
                
                // add new group to allele counts and likelihood
                for (int l=0; l<globals.loci; l++) {
                    for (int p=0; p<globals.ploidy_vec[ind]; p++) {
                        if (globals.data[ind][l][p]!=0) {
                            logLike += log(alleleCounts[newGroup[ind]-1][l][globals.data[ind][l][p]-1] + globals.lambda) - log(alleleCountsTotals[newGroup[ind]-1][l] + globals.J[l]*globals.lambda);
                            alleleCounts[newGroup[ind]-1][l][globals.data[ind][l][p]-1]++;
                            alleleCountsTotals[newGroup[ind]-1][l]++;
                        }
                    }
                }
                
            }
        }
        
        // update group
        group = newGroup;
        
        // some combinatorics to account for searching unique partitions only (see Notes.c for details)
        combined_logLike = logLike -globals.n*log(double(K));
        uniques = *max_element(begin(group),end(group));
        combined_logLike += my_lgamma(double(K)+1)-my_lgamma(double(K)-double(uniques)+1);
        
        // add to running sum
        logLike_total = logSum(logLike_total, combined_logLike);
    
    }
    
    globals.logEvidence_exhaustive[Kindex] = logLike_total;
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl 0x2bc8(%rdi), %ebx
movl %esi, 0x74(%rsp)
addl %esi, %ebx
movq %rdi, 0x8(%rsp)
movslq 0x2d18(%rdi), %rsi
leaq 0x30(%rsp), %rdx
movl $0x1, (%rdx)
leaq 0x50(%rsp), %r15
leaq 0x78(%rsp), %rcx
movq %r15, %rdi
callq 0xe8e0
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x6ad4
movslq %ebx, %r15
leaq 0xa8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %r15, %rsi
callq 0xb22a
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %r15, %rsi
callq 0xb2e8
movl %ebx, 0x20(%rsp)
testl %ebx, %ebx
jle 0xfbe9
movl 0x20(%rsp), %eax
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rax
movl 0x2d1c(%rax), %eax
xorl %r14d, %r14d
leaq 0xd0(%rsp), %r15
leaq 0x30(%rsp), %r13
movslq %eax, %rsi
movq %r15, %rdi
leaq 0x27(%rsp), %rdx
callq 0xb2e8
movq 0xa8(%rsp), %rax
leaq (%r14,%r14,2), %r12
movq 0x10(%rax,%r12,8), %rcx
movaps 0xd0(%rsp), %xmm0
movupd (%rax,%r12,8), %xmm1
movups %xmm0, (%rax,%r12,8)
movq 0xe0(%rsp), %rdx
movq %rdx, 0x10(%rax,%r12,8)
movapd %xmm1, 0x30(%rsp)
movq %rcx, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
movq $0x0, 0xe0(%rsp)
movq %r13, %rdi
callq 0xb366
movq %r15, %rdi
callq 0xb366
movq 0x8(%rsp), %rax
movslq 0x2d1c(%rax), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x6a48
movq 0x90(%rsp), %rax
movq (%rax,%r12,8), %rdi
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rax,%r12,8)
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rax,%r12,8)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0xfb40
callq 0x3310
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xfb40
callq 0x3310
movq 0x8(%rsp), %rax
movl 0x2d1c(%rax), %eax
testl %eax, %eax
jle 0xfbdb
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x8(%rsp), %rcx
movq 0x2d20(%rcx), %rax
movslq (%rax,%rbp,4), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x6a48
movq 0xa8(%rsp), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rbx), %rdi
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rax,%rbx)
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rax,%rbx)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0xfbc3
callq 0x3310
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xfbc3
callq 0x3310
incq %rbp
movq 0x8(%rsp), %rcx
movslq 0x2d1c(%rcx), %rax
addq $0x18, %rbx
cmpq %rax, %rbp
jl 0xfb5c
incq %r14
cmpq 0x18(%rsp), %r14
jne 0xfa68
movq 0x8(%rsp), %rax
movl 0x2d18(%rax), %ecx
testl %ecx, %ecx
jle 0xfdb7
movl 0x2d1c(%rax), %eax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r15d, %r15d
movl 0x20(%rsp), %ebp
movq 0x8(%rsp), %rbx
testl %eax, %eax
jle 0xfda6
movq 0x8(%rsp), %rcx
movq 0x2cd0(%rcx), %rcx
leaq (%r15,%r15,2), %r14
xorl %r12d, %r12d
cmpl $0x0, (%rcx,%r15,4)
jle 0xfd8c
movq 0x8(%rsp), %rax
movq 0x2d00(%rax), %rax
leaq (%r12,%r12,2), %rdx
movq %rdx, 0x28(%rsp)
leaq (,%r12,8), %rdx
leaq (%rdx,%rdx,2), %rbp
xorl %r13d, %r13d
movq (%rax,%r14,8), %rdx
movq 0x28(%rsp), %rsi
movq (%rdx,%rsi,8), %rdx
movslq (%rdx,%r13,4), %rdx
testq %rdx, %rdx
je 0xfd6d
movq 0x50(%rsp), %rax
movslq (%rax,%r15,4), %rax
movq 0xa8(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
movq (%rax,%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl -0x4(%rax,%rdx,4), %xmm0
addsd 0x2c50(%rbx), %xmm0
callq 0x3290
movq 0x50(%rsp), %rax
movslq (%rax,%r15,4), %rax
movq 0x90(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
xorps %xmm2, %xmm2
cvtsi2sdl (%rax,%r12,4), %xmm2
movq 0x2d20(%rbx), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%r12,4), %xmm1
movsd %xmm0, 0x10(%rsp)
mulsd 0x2c50(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x3290
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x50(%rsp), %rcx
movslq (%rcx,%r15,4), %rax
movq 0xa8(%rsp), %rdx
leaq (%rax,%rax,2), %rax
movq -0x18(%rdx,%rax,8), %rdx
movq 0x2d00(%rbx), %rax
movq (%rax,%r14,8), %rsi
movq (%rsi,%rbp), %rsi
movslq (%rsi,%r13,4), %rsi
movq (%rdx,%rbp), %rdx
incl -0x4(%rdx,%rsi,4)
movslq (%rcx,%r15,4), %rcx
movq 0x90(%rsp), %rdx
leaq (%rcx,%rcx,2), %rcx
movq -0x18(%rdx,%rcx,8), %rcx
incl (%rcx,%r12,4)
movq 0x2cd0(%rbx), %rcx
incq %r13
movslq (%rcx,%r15,4), %rdx
cmpq %rdx, %r13
jl 0xfc62
movq 0x8(%rsp), %rax
movl 0x2d1c(%rax), %eax
movl 0x20(%rsp), %ebp
incq %r12
movslq %eax, %rdx
cmpq %rdx, %r12
jl 0xfc33
movq 0x8(%rsp), %rcx
movl 0x2d18(%rcx), %ecx
incq %r15
movslq %ecx, %rdx
cmpq %rdx, %r15
jl 0xfc18
jmp 0xfdc5
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x20(%rsp), %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x48(%rsp)
callq 0x3290
mulsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x3290
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
movsd 0x26447(%rip), %xmm0    # 0x36260
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
leaq 0x78(%rsp), %r14
movq 0x8(%rsp), %r15
movq 0x50(%rsp), %rax
cmpl $0x0, (%rax)
je 0x1024e
movq %r14, %rdi
movl %ebp, %esi
callq 0x1c1eb
movq 0x78(%rsp), %rax
cmpl $0x0, (%rax)
je 0x1024e
cmpl $0x0, 0x2d18(%r15)
jle 0x1016b
xorl %r13d, %r13d
movq 0x78(%rsp), %rax
movl (%rax,%r13,4), %eax
movq 0x50(%rsp), %rcx
cmpl (%rcx,%r13,4), %eax
je 0x10158
movl 0x2d1c(%r15), %eax
testl %eax, %eax
jle 0x10158
movq 0x2cd0(%r15), %rcx
leaq (,%r13,2), %rdi
addq %r13, %rdi
xorl %r14d, %r14d
movq %rdi, 0x28(%rsp)
cmpl $0x0, (%rcx,%r13,4)
jle 0xffdf
leaq (%r14,%r14,2), %r12
leaq (,%r14,8), %rax
leaq (%rax,%rax,2), %r15
xorl %ebx, %ebx
movq 0x8(%rsp), %rbp
movq 0x2d00(%rbp), %rax
movq (%rax,%rdi,8), %rax
movq (%rax,%r12,8), %rax
cmpl $0x0, (%rax,%rbx,4)
je 0xffc3
movq 0x50(%rsp), %rcx
movslq (%rcx,%r13,4), %rdx
movq 0x90(%rsp), %rsi
leaq (%rdx,%rdx,2), %rdx
movq -0x18(%rsi,%rdx,8), %rdx
decl (%rdx,%r14,4)
movslq (%rcx,%r13,4), %rdx
movq 0xa8(%rsp), %rsi
leaq (%rdx,%rdx,2), %rdx
movq -0x18(%rsi,%rdx,8), %rdx
movslq (%rax,%rbx,4), %rdi
movq (%rdx,%r15), %rdx
decl -0x4(%rdx,%rdi,4)
movslq (%rcx,%r13,4), %rcx
leaq (%rcx,%rcx,2), %rcx
movq -0x18(%rsi,%rcx,8), %rcx
movslq (%rax,%rbx,4), %rax
movq (%rcx,%r15), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl -0x4(%rcx,%rax,4), %xmm0
addsd 0x2c50(%rbp), %xmm0
callq 0x3290
movq 0x50(%rsp), %rax
movslq (%rax,%r13,4), %rax
movq 0x90(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
xorps %xmm2, %xmm2
cvtsi2sdl (%rax,%r14,4), %xmm2
movq 0x2d20(%rbp), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%r14,4), %xmm1
movsd %xmm0, 0x10(%rsp)
mulsd 0x2c50(%rbp), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x3290
movq 0x28(%rsp), %rdi
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x2cd0(%rbp), %rcx
incq %rbx
movslq (%rcx,%r13,4), %rax
cmpq %rax, %rbx
jl 0xfec7
movq 0x8(%rsp), %r15
movl 0x2d1c(%r15), %eax
incq %r14
movslq %eax, %rdx
cmpq %rdx, %r14
jl 0xfeaa
testl %eax, %eax
jle 0x10158
movq 0x2cd0(%r15), %rcx
xorl %r14d, %r14d
cmpl $0x0, (%rcx,%r13,4)
jle 0x10149
movq 0x2d00(%r15), %rax
xorl %r12d, %r12d
movq (%rax,%rdi,8), %rdx
leaq (%r14,%r14,2), %rsi
movq (%rdx,%rsi,8), %rdx
movslq (%rdx,%r12,4), %rdx
testq %rdx, %rdx
je 0x10132
movq 0x78(%rsp), %rax
movslq (%rax,%r13,4), %rax
movq 0xa8(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
leaq (,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rbx
movq (%rax,%rbx), %rax
xorps %xmm0, %xmm0
cvtsi2sdl -0x4(%rax,%rdx,4), %xmm0
addsd 0x2c50(%r15), %xmm0
callq 0x3290
movq 0x78(%rsp), %rax
movslq (%rax,%r13,4), %rax
movq 0x90(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
xorps %xmm2, %xmm2
cvtsi2sdl (%rax,%r14,4), %xmm2
movq 0x2d20(%r15), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%r14,4), %xmm1
movsd %xmm0, 0x10(%rsp)
mulsd 0x2c50(%r15), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x3290
movq 0x28(%rsp), %rdi
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x78(%rsp), %rcx
movslq (%rcx,%r13,4), %rax
movq 0xa8(%rsp), %rdx
leaq (%rax,%rax,2), %rax
movq -0x18(%rdx,%rax,8), %rdx
movq 0x2d00(%r15), %rax
movq (%rax,%rdi,8), %rsi
movq (%rsi,%rbx), %rsi
movslq (%rsi,%r12,4), %rsi
movq (%rdx,%rbx), %rdx
incl -0x4(%rdx,%rsi,4)
movslq (%rcx,%r13,4), %rcx
movq 0x90(%rsp), %rdx
leaq (%rcx,%rcx,2), %rcx
movq -0x18(%rdx,%rcx,8), %rcx
incl (%rcx,%r14,4)
movq 0x2cd0(%r15), %rcx
incq %r12
movslq (%rcx,%r13,4), %rdx
cmpq %rdx, %r12
jl 0x10015
movl 0x2d1c(%r15), %eax
incq %r14
movslq %eax, %rdx
cmpq %rdx, %r14
jl 0x10000
incq %r13
movslq 0x2d18(%r15), %rax
cmpq %rax, %r13
jl 0xfe69
leaq 0x50(%rsp), %rdi
leaq 0x78(%rsp), %r14
movq %r14, %rsi
callq 0xafde
movl 0x20(%rsp), %ebp
movl 0x2d18(%r15), %ebx
movsd 0x48(%rsp), %xmm0
callq 0x3290
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
cmpq %rcx, %rax
sete %sil
movq %rax, %rdx
addq $0x4, %rdx
cmpq %rcx, %rdx
sete %dil
orb %sil, %dil
jne 0x101cd
movl (%rax), %esi
movl (%rdx), %edi
cmpl %edi, %esi
cmovlel %edi, %esi
cmovlq %rdx, %rax
addq $0x4, %rdx
cmpq %rcx, %rdx
jne 0x101b9
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
mulsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0xc8(%rsp)
movsd 0xc0(%rsp), %xmm0
callq 0x3260
movsd %xmm0, 0x28(%rsp)
movsd 0x48(%rsp), %xmm0
subsd 0xc8(%rsp), %xmm0
addsd 0x2603d(%rip), %xmm0    # 0x36260
callq 0x3260
movsd 0x28(%rsp), %xmm1
subsd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
callq 0x1a75d
movsd %xmm0, 0x68(%rsp)
jmp 0xfe32
movslq 0x74(%rsp), %rax
movq 0x2e00(%r15), %rcx
movsd 0x68(%rsp), %xmm0
movsd %xmm0, (%rcx,%rax,8)
leaq 0x90(%rsp), %rdi
callq 0xb366
leaq 0xa8(%rsp), %rdi
callq 0xb2a8
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x1028e
callq 0x3310
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x1029d
callq 0x3310
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x102d4
movq %rax, %rbx
jmp 0x102e1
movq %rax, %rbx
jmp 0x102f0
jmp 0x102c4
jmp 0x102c4
jmp 0x102c4
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xb366
leaq 0xa8(%rsp), %rdi
callq 0xb2a8
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x102f0
callq 0x3310
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x102ff
callq 0x3310
movq %rbx, %rdi
callq 0x3580