// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq %rdi, %rbx
movl 0x2bc8(%rdi), %r14d
movl %esi, 0x4c(%rsp)
addl %esi, %r14d
movslq 0x2d18(%rdi), %rsi
leaq 0x80(%rsp), %rdx
movl $0x1, (%rdx)
leaq 0x28(%rsp), %r15
leaq 0x68(%rsp), %rcx
movq %r15, %rdi
callq 0x5f08
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x5fce
movslq %r14d, %r15
leaq 0x68(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %r15, %rsi
callq 0x9820
leaq 0x50(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
movq %r15, %rsi
callq 0x9894
xorl %r13d, %r13d
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
movq %rax, 0x8(%rsp)
leaq 0xb0(%rsp), %r15
leaq 0x1f(%rsp), %r12
movl %r14d, 0x18(%rsp)
cmpq 0x8(%rsp), %r13
je 0xd3f3
movslq 0x2d1c(%rbx), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x9894
movq %r13, 0x10(%rsp)
imulq $0x18, %r13, %r14
movq 0x68(%rsp), %rdi
addq %r14, %rdi
movq %r15, %rsi
callq 0xa27c
movq %r15, %rdi
callq 0x98e6
movslq 0x2d1c(%rbx), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x5f7c
movq 0x50(%rsp), %rdi
addq %r14, %rdi
movq %r15, %rsi
callq 0x6266
movq %r15, %rdi
callq 0x61d0
xorl %ebp, %ebp
xorl %r13d, %r13d
movslq 0x2d1c(%rbx), %rax
cmpq %rax, %r13
jge 0xd3e1
movq 0x2d20(%rbx), %rax
movslq (%rax,%r13,4), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x5f7c
movq 0x68(%rsp), %rax
movq (%rax,%r14), %rdi
addq %rbp, %rdi
movq %r15, %rsi
callq 0x6266
movq %r15, %rdi
callq 0x61d0
incq %r13
addq $0x18, %rbp
jmp 0xd39a
movq 0x10(%rsp), %r13
incq %r13
movl 0x18(%rsp), %r14d
jmp 0xd32d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %r15d, %r15d
movslq 0x2d18(%rbx), %rax
cmpq %rax, %r15
jge 0xd550
imulq $0x18, %r15, %r12
xorl %r13d, %r13d
movslq 0x2d1c(%rbx), %rax
cmpq %rax, %r13
jge 0xd543
imulq $0x18, %r13, %rbp
xorl %r14d, %r14d
movq 0x2cd0(%rbx), %rax
movslq (%rax,%r15,4), %rax
cmpq %rax, %r14
jge 0xd53b
movq 0x2d00(%rbx), %rax
movq (%rax,%r12), %rax
movq (%rax,%rbp), %rax
movslq (%rax,%r14,4), %rax
testq %rax, %rax
je 0xd533
movq 0x28(%rsp), %rcx
movslq (%rcx,%r15,4), %rcx
movq 0x68(%rsp), %rdx
imulq $0x18, %rcx, %rcx
movq -0x18(%rdx,%rcx), %rcx
movq (%rcx,%rbp), %rcx
cvtsi2sdl -0x4(%rcx,%rax,4), %xmm0
addsd 0x2c50(%rbx), %xmm0
callq 0x32d0
movq 0x28(%rsp), %rax
movslq (%rax,%r15,4), %rax
movq 0x50(%rsp), %rcx
imulq $0x18, %rax, %rax
movq -0x18(%rcx,%rax), %rax
cvtsi2sdl (%rax,%r13,4), %xmm2
movq 0x2d20(%rbx), %rax
cvtsi2sdl (%rax,%r13,4), %xmm1
movsd %xmm0, 0x8(%rsp)
mulsd 0x2c50(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x32d0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x28(%rsp), %rax
movslq (%rax,%r15,4), %rcx
movq 0x68(%rsp), %rdx
imulq $0x18, %rcx, %rcx
movq -0x18(%rdx,%rcx), %rcx
movq 0x2d00(%rbx), %rdx
movq (%rdx,%r12), %rdx
movq (%rdx,%rbp), %rdx
movslq (%rdx,%r14,4), %rdx
movq (%rcx,%rbp), %rcx
incl -0x4(%rcx,%rdx,4)
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movslq (%rax,%r15,4), %rax
movq 0x50(%rsp), %rcx
imulq $0x18, %rax, %rax
movq -0x18(%rcx,%rax), %rax
incl (%rax,%r13,4)
incq %r14
jmp 0xd42e
incq %r13
jmp 0xd417
incq %r15
movl 0x18(%rsp), %r14d
jmp 0xd400
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x32d0
mulsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x32d0
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x19c71(%rip), %xmm0    # 0x27210
addsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
leaq 0x80(%rsp), %r15
movq 0x28(%rsp), %rax
cmpl $0x0, (%rax)
je 0xd927
movq %r15, %rdi
movl %r14d, %esi
callq 0x1610c
movq 0x80(%rsp), %rax
cmpl $0x0, (%rax)
je 0xd927
xorl %r13d, %r13d
movslq 0x2d18(%rbx), %rax
cmpq %rax, %r13
jge 0xd864
movq 0x80(%rsp), %rax
movl (%rax,%r13,4), %eax
movq 0x28(%rsp), %rcx
cmpl (%rcx,%r13,4), %eax
jne 0xd60f
incq %r13
jmp 0xd5e3
imulq $0x18, %r13, %rbp
xorl %r12d, %r12d
movslq 0x2d1c(%rbx), %rax
cmpq %rax, %r12
jge 0xd72b
imulq $0x18, %r12, %r14
xorl %r15d, %r15d
movq 0x2cd0(%rbx), %rax
movslq (%rax,%r13,4), %rax
cmpq %rax, %r15
jge 0xd723
movq 0x2d00(%rbx), %rax
movq (%rax,%rbp), %rax
movq (%rax,%r14), %rax
cmpl $0x0, (%rax,%r15,4)
je 0xd71b
movq 0x28(%rsp), %rcx
movslq (%rcx,%r13,4), %rdx
movq 0x50(%rsp), %rsi
imulq $0x18, %rdx, %rdx
movq -0x18(%rsi,%rdx), %rdx
decl (%rdx,%r12,4)
movslq (%rcx,%r13,4), %rdx
movq 0x68(%rsp), %rsi
imulq $0x18, %rdx, %rdx
movq -0x18(%rsi,%rdx), %rdx
movslq (%rax,%r15,4), %rdi
movq (%rdx,%r14), %rdx
decl -0x4(%rdx,%rdi,4)
movslq (%rcx,%r13,4), %rcx
imulq $0x18, %rcx, %rcx
movq -0x18(%rsi,%rcx), %rcx
movslq (%rax,%r15,4), %rax
movq (%rcx,%r14), %rcx
cvtsi2sdl -0x4(%rcx,%rax,4), %xmm0
addsd 0x2c50(%rbx), %xmm0
callq 0x32d0
movq 0x28(%rsp), %rax
movslq (%rax,%r13,4), %rax
movq 0x50(%rsp), %rcx
imulq $0x18, %rax, %rax
movq -0x18(%rcx,%rax), %rax
cvtsi2sdl (%rax,%r12,4), %xmm2
movq 0x2d20(%rbx), %rax
cvtsi2sdl (%rax,%r12,4), %xmm1
movsd %xmm0, 0x8(%rsp)
mulsd 0x2c50(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x32d0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
incq %r15
jmp 0xd62d
incq %r12
jmp 0xd616
xorl %r12d, %r12d
cltq
cmpq %rax, %r12
jge 0xd60a
imulq $0x18, %r12, %r14
xorl %r15d, %r15d
movq 0x2cd0(%rbx), %rax
movslq (%rax,%r13,4), %rax
cmpq %rax, %r15
jge 0xd856
movq 0x2d00(%rbx), %rax
movq (%rax,%rbp), %rax
movq (%rax,%r14), %rax
movslq (%rax,%r15,4), %rax
testq %rax, %rax
je 0xd84e
movq 0x80(%rsp), %rcx
movslq (%rcx,%r13,4), %rcx
movq 0x68(%rsp), %rdx
imulq $0x18, %rcx, %rcx
movq -0x18(%rdx,%rcx), %rcx
movq (%rcx,%r14), %rcx
cvtsi2sdl -0x4(%rcx,%rax,4), %xmm0
addsd 0x2c50(%rbx), %xmm0
callq 0x32d0
movq 0x80(%rsp), %rax
movslq (%rax,%r13,4), %rax
movq 0x50(%rsp), %rcx
imulq $0x18, %rax, %rax
movq -0x18(%rcx,%rax), %rax
cvtsi2sdl (%rax,%r12,4), %xmm2
movq 0x2d20(%rbx), %rax
cvtsi2sdl (%rax,%r12,4), %xmm1
movsd %xmm0, 0x8(%rsp)
mulsd 0x2c50(%rbx), %xmm1
addsd %xmm2, %xmm1
movapd %xmm1, %xmm0
callq 0x32d0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x80(%rsp), %rax
movslq (%rax,%r13,4), %rcx
movq 0x68(%rsp), %rdx
imulq $0x18, %rcx, %rcx
movq -0x18(%rdx,%rcx), %rcx
movq 0x2d00(%rbx), %rdx
movq (%rdx,%rbp), %rdx
movq (%rdx,%r14), %rdx
movslq (%rdx,%r15,4), %rdx
movq (%rcx,%r14), %rcx
incl -0x4(%rcx,%rdx,4)
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movslq (%rax,%r13,4), %rax
movq 0x50(%rsp), %rcx
imulq $0x18, %rax, %rax
movq -0x18(%rcx,%rax), %rax
incl (%rax,%r12,4)
incq %r15
jmp 0xd740
incq %r12
movl 0x2d1c(%rbx), %eax
jmp 0xd72e
leaq 0x28(%rsp), %rdi
leaq 0x80(%rsp), %r15
movq %r15, %rsi
callq 0x969e
movl 0x18(%rsp), %r14d
movl 0x2d18(%rbx), %ebp
movsd 0x20(%rsp), %xmm0
callq 0x32d0
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0xe459
cvtsi2sd %ebp, %xmm0
mulsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0x98(%rsp), %xmm0
callq 0x32a0
movsd %xmm0, 0xa8(%rsp)
movsd 0x20(%rsp), %xmm0
subsd 0xa0(%rsp), %xmm0
addsd 0x19917(%rip), %xmm0    # 0x27210
callq 0x32a0
movsd 0xa8(%rsp), %xmm1
subsd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
callq 0x14ce5
movsd %xmm0, 0x40(%rsp)
jmp 0xd5b6
movslq 0x4c(%rsp), %rax
movq 0x2e00(%rbx), %rcx
movsd 0x40(%rsp), %xmm0
movsd %xmm0, (%rcx,%rax,8)
leaq 0x50(%rsp), %rdi
callq 0x98e6
leaq 0x68(%rsp), %rdi
callq 0x9872
leaq 0x80(%rsp), %rdi
callq 0x61d0
leaq 0x28(%rsp), %rdi
callq 0x61d0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0xd99f
movq %rax, %rbx
jmp 0xd9a9
movq %rax, %rbx
jmp 0xd9b6
jmp 0xd992
jmp 0xd992
jmp 0xd992
jmp 0xd992
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x98e6
leaq 0x68(%rsp), %rdi
callq 0x9872
leaq 0x80(%rsp), %rdi
callq 0x61d0
leaq 0x28(%rsp), %rdi
callq 0x61d0
movq %rbx, %rdi
callq 0x35a0