// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq %rdi, %rbx
movl 0x2bc8(%rdi), %ebp
movl %esi, 0x64(%rsp)
addl %esi, %ebp
movslq 0x2d18(%rdi), %rsi
leaq 0x10(%rsp), %rdx
movl $0x1, (%rdx)
leaq 0x40(%rsp), %r15
leaq 0x68(%rsp), %rcx
movq %r15, %rdi
callq 0xed32
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x6b8e
movslq %ebp, %r15
leaq 0x98(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq %r15, %rsi
callq 0xb4ea
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq %r15, %rsi
callq 0xb5ac
movl %ebp, 0x30(%rsp)
testl %ebp, %ebp
jle 0xff99
movl 0x30(%rsp), %eax
movq %rax, (%rsp)
xorl %r14d, %r14d
leaq 0xc0(%rsp), %r15
leaq 0x10(%rsp), %r13
movslq 0x2d1c(%rbx), %rsi
movq %r15, %rdi
leaq 0x37(%rsp), %rdx
callq 0xb5ac
movq 0x98(%rsp), %rax
leaq (%r14,%r14,2), %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movups (%rax,%r12,8), %xmm0
movq 0x10(%rax,%r12,8), %rcx
movaps 0xc0(%rsp), %xmm1
movups %xmm1, (%rax,%r12,8)
movq 0xd0(%rsp), %rdx
movq %rdx, 0x10(%rax,%r12,8)
movq 0x20(%rsp), %rax
movq %rcx, 0x20(%rsp)
movaps 0x10(%rsp), %xmm1
movaps %xmm0, 0x10(%rsp)
movaps %xmm1, 0xc0(%rsp)
movq %rax, 0xd0(%rsp)
movq %r13, %rdi
callq 0xb634
movq %r15, %rdi
callq 0xb634
movslq 0x2d1c(%rbx), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x6b04
movq 0x80(%rsp), %rax
movq (%rax,%r12,8), %rdi
movapd 0x10(%rsp), %xmm0
movupd 0x8(%rax,%r12,8), %xmm1
movupd %xmm0, (%rax,%r12,8)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax,%r12,8)
movq %rdi, 0x10(%rsp)
movupd %xmm1, 0x18(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0xfed2
callq 0x3310
movq %r14, 0x8(%rsp)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xfee6
callq 0x3310
cmpl $0x0, 0x2d1c(%rbx)
jle 0xff87
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x2d20(%rbx), %rax
movslq (%rax,%r14,4), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x6b04
movq 0x98(%rsp), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rbp), %rdi
movapd 0x10(%rsp), %xmm0
movupd 0x8(%rax,%rbp), %xmm1
movupd %xmm0, (%rax,%rbp)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax,%rbp)
movq %rdi, 0x10(%rsp)
movupd %xmm1, 0x18(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rdi, %rdi
je 0xff61
callq 0x3310
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xff70
callq 0x3310
incq %r14
movslq 0x2d1c(%rbx), %rax
addq $0x18, %rbp
cmpq %rax, %r14
jl 0xfef8
movq 0x8(%rsp), %r14
incq %r14
cmpq (%rsp), %r14
jne 0xfde6
movl 0x2d18(%rbx), %eax
xorpd %xmm0, %xmm0
testl %eax, %eax
jle 0x1013a
movsd %xmm0, 0x8(%rsp)
xorl %r14d, %r14d
cmpl $0x0, 0x2d1c(%rbx)
jle 0x10125
leaq (%r14,%r14,2), %r15
xorl %r12d, %r12d
movq 0x2cd0(%rbx), %rax
cmpl $0x0, (%rax,%r14,4)
jle 0x10112
leaq (%r12,%r12,2), %rax
movq %rax, 0x28(%rsp)
leaq (,%r12,8), %rax
leaq (%rax,%rax,2), %rbp
xorl %r13d, %r13d
movq 0x2d00(%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq (%rax,%r13,4), %rax
testq %rax, %rax
je 0x100fb
movq 0x40(%rsp), %rcx
movslq (%rcx,%r14,4), %rcx
movq 0x98(%rsp), %rdx
leaq (%rcx,%rcx,2), %rcx
movq -0x18(%rdx,%rcx,8), %rcx
movq (%rcx,%rbp), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl -0x4(%rcx,%rax,4), %xmm0
addsd 0x2c50(%rbx), %xmm0
callq 0x3290
movq 0x40(%rsp), %rax
movslq (%rax,%r14,4), %rax
movq 0x80(%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, (%rsp)
mulsd 0x2c50(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x3290
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x40(%rsp), %rax
movslq (%rax,%r14,4), %rcx
movq 0x98(%rsp), %rdx
leaq (%rcx,%rcx,2), %rcx
movq -0x18(%rdx,%rcx,8), %rcx
movq 0x2d00(%rbx), %rdx
movq (%rdx,%r15,8), %rdx
movq (%rdx,%rbp), %rdx
movslq (%rdx,%r13,4), %rdx
movq (%rcx,%rbp), %rcx
incl -0x4(%rcx,%rdx,4)
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movslq (%rax,%r14,4), %rax
movq 0x80(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
incl (%rax,%r12,4)
incq %r13
movq 0x2cd0(%rbx), %rax
movslq (%rax,%r14,4), %rax
cmpq %rax, %r13
jl 0xfff2
incq %r12
movslq 0x2d1c(%rbx), %rax
cmpq %rax, %r12
jl 0xffc8
incq %r14
movslq 0x2d18(%rbx), %rax
cmpq %rax, %r14
jl 0xffb4
jmp 0x10140
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%rsp)
movl 0x30(%rsp), %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x38(%rsp)
callq 0x3290
mulsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd 0x38(%rsp), %xmm0
callq 0x3290
addsd (%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x270ca(%rip), %xmm0    # 0x37260
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
leaq 0x68(%rsp), %r15
movq 0x40(%rsp), %rax
cmpl $0x0, (%rax)
je 0x105b9
movq %r15, %rdi
movl %r14d, %esi
callq 0x1c517
movq 0x68(%rsp), %rax
cmpl $0x0, (%rax)
je 0x105b9
cmpl $0x0, 0x2d18(%rbx)
jle 0x104d1
xorl %r13d, %r13d
movq 0x68(%rsp), %rax
movl (%rax,%r13,4), %eax
movq 0x40(%rsp), %rcx
cmpl (%rcx,%r13,4), %eax
je 0x104be
cmpl $0x0, 0x2d1c(%rbx)
leaq (%r13,%r13,2), %rbp
jle 0x10351
xorl %r14d, %r14d
movq 0x2cd0(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jle 0x1033e
leaq (%r14,%r14,2), %rax
movq %rax, 0x28(%rsp)
leaq (,%r14,8), %rax
leaq (%rax,%rax,2), %r12
xorl %r15d, %r15d
movq 0x2d00(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, (%rax,%r15,4)
je 0x10327
movq 0x40(%rsp), %rcx
movslq (%rcx,%r13,4), %rdx
movq 0x80(%rsp), %rsi
leaq (%rdx,%rdx,2), %rdx
movq -0x18(%rsi,%rdx,8), %rdx
decl (%rdx,%r14,4)
movslq (%rcx,%r13,4), %rdx
movq 0x98(%rsp), %rsi
leaq (%rdx,%rdx,2), %rdx
movq -0x18(%rsi,%rdx,8), %rdx
movslq (%rax,%r15,4), %rdi
movq (%rdx,%r12), %rdx
decl -0x4(%rdx,%rdi,4)
movslq (%rcx,%r13,4), %rcx
leaq (%rcx,%rcx,2), %rcx
movq -0x18(%rsi,%rcx,8), %rcx
movslq (%rax,%r15,4), %rax
movq (%rcx,%r12), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl -0x4(%rcx,%rax,4), %xmm0
addsd 0x2c50(%rbx), %xmm0
callq 0x3290
movq 0x40(%rsp), %rax
movslq (%rax,%r13,4), %rax
movq 0x80(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
xorps %xmm2, %xmm2
cvtsi2sdl (%rax,%r14,4), %xmm2
movq 0x2d20(%rbx), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%r14,4), %xmm1
movsd %xmm0, (%rsp)
mulsd 0x2c50(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x3290
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
incq %r15
movq 0x2cd0(%rbx), %rax
movslq (%rax,%r13,4), %rax
cmpq %rax, %r15
jl 0x10238
incq %r14
movslq 0x2d1c(%rbx), %rax
cmpq %rax, %r14
jl 0x1020e
cmpl $0x0, 0x2d1c(%rbx)
jle 0x104be
xorl %r14d, %r14d
movq 0x2cd0(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jle 0x104ab
leaq (%r14,%r14,2), %rax
movq %rax, 0x28(%rsp)
leaq (,%r14,8), %rax
leaq (%rax,%rax,2), %r15
xorl %r12d, %r12d
movq 0x2d00(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq (%rax,%r12,4), %rax
testq %rax, %rax
je 0x10494
movq 0x68(%rsp), %rcx
movslq (%rcx,%r13,4), %rcx
movq 0x98(%rsp), %rdx
leaq (%rcx,%rcx,2), %rcx
movq -0x18(%rdx,%rcx,8), %rcx
movq (%rcx,%r15), %rcx
xorps %xmm0, %xmm0
cvtsi2sdl -0x4(%rcx,%rax,4), %xmm0
addsd 0x2c50(%rbx), %xmm0
callq 0x3290
movq 0x68(%rsp), %rax
movslq (%rax,%r13,4), %rax
movq 0x80(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
xorps %xmm2, %xmm2
cvtsi2sdl (%rax,%r14,4), %xmm2
movq 0x2d20(%rbx), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%r14,4), %xmm1
movsd %xmm0, (%rsp)
mulsd 0x2c50(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x3290
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x68(%rsp), %rax
movslq (%rax,%r13,4), %rcx
movq 0x98(%rsp), %rdx
leaq (%rcx,%rcx,2), %rcx
movq -0x18(%rdx,%rcx,8), %rcx
movq 0x2d00(%rbx), %rdx
movq (%rdx,%rbp,8), %rdx
movq (%rdx,%r15), %rdx
movslq (%rdx,%r12,4), %rdx
movq (%rcx,%r15), %rcx
incl -0x4(%rcx,%rdx,4)
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movslq (%rax,%r13,4), %rax
movq 0x80(%rsp), %rcx
leaq (%rax,%rax,2), %rax
movq -0x18(%rcx,%rax,8), %rax
incl (%rax,%r14,4)
incq %r12
movq 0x2cd0(%rbx), %rax
movslq (%rax,%r13,4), %rax
cmpq %rax, %r12
jl 0x1038b
incq %r14
movslq 0x2d1c(%rbx), %rax
cmpq %rax, %r14
jl 0x10361
incq %r13
movslq 0x2d18(%rbx), %rax
cmpq %rax, %r13
jl 0x101e1
leaq 0x40(%rsp), %rdi
leaq 0x68(%rsp), %r15
movq %r15, %rsi
callq 0xb2d4
movl 0x30(%rsp), %r14d
movl 0x2d18(%rbx), %ebp
movsd 0x38(%rsp), %xmm0
callq 0x3290
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rax
cmpq %rax, %rdx
sete %sil
movq %rdx, %rcx
addq $0x4, %rcx
cmpq %rax, %rcx
sete %dil
orb %sil, %dil
je 0x10522
movq %rdx, %rsi
jmp 0x1053a
movl (%rdx), %edi
movq %rcx, %rsi
cmpl (%rcx), %edi
jl 0x1052e
movq %rdx, %rsi
addq $0x4, %rcx
movq %rsi, %rdx
cmpq %rax, %rcx
jne 0x10522
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl (%rsi), %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0xb0(%rsp), %xmm0
callq 0x3260
movsd %xmm0, 0x28(%rsp)
movsd 0x38(%rsp), %xmm0
subsd 0xb8(%rsp), %xmm0
addsd 0x26cd1(%rip), %xmm0    # 0x37260
callq 0x3260
movsd 0x28(%rsp), %xmm1
subsd %xmm0, %xmm1
addsd (%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
callq 0x1aa59
movsd %xmm0, 0x58(%rsp)
jmp 0x101aa
movslq 0x64(%rsp), %rax
movq 0x2e00(%rbx), %rcx
movsd 0x58(%rsp), %xmm0
movsd %xmm0, (%rcx,%rax,8)
leaq 0x80(%rsp), %rdi
callq 0xb634
leaq 0x98(%rsp), %rdi
callq 0xb572
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x105f9
callq 0x3310
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x10608
callq 0x3310
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x1063f
movq %rax, %rbx
jmp 0x1064c
movq %rax, %rbx
jmp 0x1065b
jmp 0x1062f
jmp 0x1062f
jmp 0x1062f
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xb634
leaq 0x98(%rsp), %rdi
callq 0xb572
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x1065b
callq 0x3310
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x1066a
callq 0x3310
movq %rbx, %rdi
callq 0x3580