// File: /workspace/github_cpp_makefile_star2_O2/gchen98[P]macs/datastructures.cpp
// Function: GraphBuilder::printHaplotypes()
void GraphBuilder::printHaplotypes(){
    unsigned int iTotalSites = pMutationPtrVector->size();
    bool bZeroCellCount=false;
    if (pConfig->bDebug) cerr<<"Total sites: "<<iTotalSites<<endl;
    if (iTotalSites){
        int iReducedSites=iTotalSites;
        if (pConfig->bSNPAscertainment){
            // first see if any expected count exceed actual counts
            bool bSufficientObs=false;
            do{
                bSufficientObs=true;
                AlleleFreqBinPtrSet::iterator it=pConfig->pAlleleFreqBinPtrSet->begin();
                while(bSufficientObs && !bZeroCellCount && it!=pConfig->pAlleleFreqBinPtrSet->end()){
                    AlleleFreqBinPtr bin = *it;
                    int iExpectedCount = static_cast<int>(bin->dFreq * iReducedSites);
                    if (!iExpectedCount && bin->dFreq>0.){
                        bZeroCellCount = true;
                        if (pConfig->bDebug){
                            cerr<<"Setting zero cell count true because expecting a proportion of "<<
                            bin->dFreq<<" but found "<<iExpectedCount<<endl;
                        }
                    }
                    else if (bin->iObservedCounts<iExpectedCount){
                        bSufficientObs = false;
                        --iReducedSites;
                    }else{
                        ++it;
                    }
                }
            }while(!bSufficientObs && !bZeroCellCount);
            if (bZeroCellCount){
                cerr<<"Warning: Some observed SNP counts were zero when they should have been positive.\n"<<
                "No ascertainment correction was applied.\n"<<
                "Try expanding frequency bin sizes and/or increasing mutation rate.\n";
                iReducedSites = 0;
            }else{
                int tally=0;
                for (AlleleFreqBinPtrSet::iterator it=pConfig->pAlleleFreqBinPtrSet->begin();
                it!=pConfig->pAlleleFreqBinPtrSet->end();++it){
                    AlleleFreqBinPtr bin = *it;
                    double dStart = bin->dStart;
                    double dEnd = bin->dEnd;
                    int iExpectedCount = static_cast<int>(bin->dFreq * iReducedSites);

                    tally+=iExpectedCount;
                    if (pConfig->bDebug) {
                        cerr<<"Looking for SNPs in range "<<dStart<<" to "<<dEnd<<endl;
                        cerr<<"iObserved count: "<<bin->iObservedCounts<<endl;
                        cerr<<"Expecting "<<iExpectedCount<<" SNPS."<<endl;
                    }
                    #ifdef DIAG
                    if (bin->iObservedCounts<iExpectedCount){
                        throw "Too many expected counts";
                    }
                    #endif
                    while(iExpectedCount>0){
                        int iRandIndex = static_cast<int>(pRandNumGenerator->unifRV()*iTotalSites);
                        MutationPtr mutation = pMutationPtrVector->at(iRandIndex);
                        if (!mutation->bPrintOutput && mutation->dFreq>=dStart && mutation->dFreq<=dEnd){
                            mutation->bPrintOutput = true;
                            --iExpectedCount;
                        }
                    }
                }
                iReducedSites = tally;
                cerr<<"Total sites reduced from "<<iTotalSites<<" to "<<iReducedSites<<endl;
            }
        }
        if (iReducedSites){
            MutationPtrVector::iterator it;
            // copy to a temporary vector if ascertained
            cout<<TOTALSAMPLES<<FIELD_DELIMITER<<pConfig->iSampleSize<<endl;
            cout<<TOTALSITES<<FIELD_DELIMITER<<iReducedSites<<endl;
            cout<<SNPBEGIN<<endl;
            if (pConfig->bSNPAscertainment && !bZeroCellCount){
                int origIndex=0;
                bool indexPrinted=false;
                for (it = pMutationPtrVector->begin();
                it!=pMutationPtrVector->end();++it){
                    MutationPtr mutation = *it;
                    if (mutation->bPrintOutput){
                        if (indexPrinted) cout<<FIELD_DELIMITER;
                        cout<<origIndex;
                        indexPrinted=true;
                    }
                    ++origIndex;
                }
            }else{
                for(int i=0;i<iReducedSites;++i){
                  if (i) cout<<FIELD_DELIMITER;
                  cout<<i;
                }
            }
            cout<<endl<<SNPEND<<endl;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0xa8(%rdi), %rax
movq 0x8(%rax), %r14
subq (%rax), %r14
movq 0x8(%rdi), %rax
shrq $0x3, %r14
cmpb $0x1, 0x48(%rax)
jne 0x1133f
movq 0xdcd0(%rip), %rdi      # 0x1eff0
leaq 0x53ca(%rip), %rsi      # 0x166f1
callq 0x3250
movl %r14d, %esi
movq %rax, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x3100
testl %r14d, %r14d
je 0x1173d
movq 0x8(%rbx), %rax
cmpb $0x1, 0x49(%rax)
jne 0x1149d
movq %r14, %rcx
xorl %r14d, %r14d
xorpd %xmm1, %xmm1
leaq 0x5398(%rip), %rbp      # 0x166ff
leaq 0x53d1(%rip), %r12      # 0x1673f
movq %rcx, %rax
movq %rcx, 0x8(%rsp)
movl %eax, (%rsp)
movq 0x8(%rbx), %rax
movq 0x90(%rax), %rax
movq 0x18(%rax), %r13
movb $0x1, %al
cvtsi2sdl (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
testb $0x1, %al
je 0x11454
testb $0x1, %r14b
jne 0x1145e
movq 0x8(%rbx), %rcx
movq 0x90(%rcx), %rax
addq $0x8, %rax
cmpq %rax, %r13
je 0x114a5
movq 0x20(%r13), %r15
movsd 0x10(%r15), %xmm0
ucomisd %xmm1, %xmm0
mulsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %eax
jbe 0x11430
testl %eax, %eax
jne 0x11430
movb $0x1, %al
cmpb $0x1, 0x48(%rcx)
movb $0x1, %r14b
jne 0x11395
movq 0xdc01(%rip), %rdi      # 0x1eff0
movq %rbp, %rsi
callq 0x3250
movsd 0x10(%r15), %xmm0
movq %rax, %rdi
callq 0x3370
movq %rax, %rdi
movq %r12, %rsi
callq 0x3250
movq %rax, %rdi
xorl %esi, %esi
callq 0x33f0
movq %rax, %rdi
callq 0x3100
xorpd %xmm1, %xmm1
movb $0x1, %al
movb $0x1, %r14b
jmp 0x11395
cmpl %eax, 0x18(%r15)
jge 0x11440
decl (%rsp)
xorl %eax, %eax
jmp 0x1138a
movq %r13, %rdi
callq 0x32a0
xorpd %xmm1, %xmm1
movq %rax, %r13
jmp 0x11388
testb $0x1, %r14b
je 0x11379
movq 0xdb8b(%rip), %rdi      # 0x1eff0
leaq 0x52df(%rip), %rsi      # 0x1674b
callq 0x3250
leaq 0x5325(%rip), %rsi      # 0x1679d
movq %rax, %rdi
callq 0x3250
leaq 0x5340(%rip), %rsi      # 0x167c7
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3250
movl %r14d, %ebp
jmp 0x1165a
movq 0x8(%rbx), %rax
movq 0x90(%rax), %rcx
movl 0x8(%rsp), %edx
cvtsi2sd %rdx, %xmm0
movsd %xmm0, (%rsp)
movq 0x18(%rcx), %r12
xorl %ebp, %ebp
movq 0xdb25(%rip), %r14      # 0x1eff0
addq $0x8, %rcx
cmpq %rcx, %r12
je 0x11612
movq 0x20(%r12), %r15
movsd (%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%r15), %xmm0
mulsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %r13d
cmpb $0x1, 0x48(%rax)
jne 0x115a5
movq %r14, %rdi
leaq 0x52f2(%rip), %rsi      # 0x1680b
callq 0x3250
movq %rax, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x3370
movq %rax, %rdi
leaq 0x3b63(%rip), %rsi      # 0x15099
callq 0x3250
movq %rax, %rdi
movsd 0x18(%rsp), %xmm0
callq 0x3370
movq %rax, %rdi
callq 0x3100
movq %r14, %rdi
leaq 0x52cb(%rip), %rsi      # 0x16826
callq 0x3250
movl 0x18(%r15), %esi
movq %rax, %rdi
callq 0x33f0
movq %rax, %rdi
callq 0x3100
movq %r14, %rdi
leaq 0x52ba(%rip), %rsi      # 0x16838
callq 0x3250
movq %rax, %rdi
movl %r13d, %esi
callq 0x33f0
movq %rax, %rdi
leaq 0x52ab(%rip), %rsi      # 0x16843
callq 0x3250
movq %rax, %rdi
callq 0x3100
addl %r13d, %ebp
testl %r13d, %r13d
jle 0x115f7
movq (%rbx), %rdi
callq 0xdaee
mulsd (%rsp), %xmm0
cvttsd2si %xmm0, %eax
movq 0xa8(%rbx), %rdi
movslq %eax, %rsi
callq 0x11dae
movq (%rax), %rax
cmpb $0x0, 0x10(%rax)
jne 0x115a8
movsd (%rax), %xmm0
ucomisd 0x20(%rsp), %xmm0
jb 0x115a8
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x115a8
movb $0x1, 0x10(%rax)
decl %r13d
jmp 0x115a8
movq %r12, %rdi
callq 0x32a0
movq %rax, %r12
movq 0x8(%rbx), %rax
movq 0x90(%rax), %rcx
jmp 0x114cb
movq 0xd9d7(%rip), %rdi      # 0x1eff0
leaq 0x522a(%rip), %rsi      # 0x1684a
callq 0x3250
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x31a0
leaq 0x3a61(%rip), %rsi      # 0x15099
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
movl %ebp, %esi
callq 0x33f0
movq %rax, %rdi
callq 0x3100
testl %ebp, %ebp
je 0x1173d
movq 0xd96f(%rip), %r14      # 0x1efd0
leaq 0xdf98(%rip), %rsi      # 0x1f600
movq %r14, %rdi
callq 0x3210
leaq 0xdfc9(%rip), %r15      # 0x1f640
movq %rax, %rdi
movq %r15, %rsi
callq 0x3210
movq 0x8(%rbx), %rcx
movl 0x30(%rcx), %esi
movq %rax, %rdi
callq 0x31a0
movq %rax, %rdi
callq 0x3100
leaq 0xdf80(%rip), %rsi      # 0x1f620
movq %r14, %rdi
callq 0x3210
movq %rax, %rdi
movq %r15, %rsi
callq 0x3210
movq %rax, %rdi
movl %ebp, %esi
callq 0x33f0
movq %rax, %rdi
callq 0x3100
leaq 0xdef4(%rip), %rsi      # 0x1f5c0
movq %r14, %rdi
callq 0x3210
movq %rax, %rdi
callq 0x3100
movq 0x8(%rbx), %rax
cmpb $0x0, 0x49(%rax)
je 0x1174c
movq 0xa8(%rbx), %rax
movq (%rax), %r12
xorl %ebp, %ebp
movq 0xd8d7(%rip), %r14      # 0x1efd0
leaq 0xdf40(%rip), %r15      # 0x1f640
xorl %ecx, %ecx
cmpq 0x8(%rax), %r12
je 0x11782
movq (%r12), %rdx
cmpb $0x1, 0x10(%rdx)
jne 0x11735
testb $0x1, %cl
je 0x11722
movq %r14, %rdi
movq %r15, %rsi
callq 0x3210
movq %r14, %rdi
movl %ebp, %esi
callq 0x33f0
movq 0xa8(%rbx), %rax
movb $0x1, %cl
incl %ebp
addq $0x8, %r12
jmp 0x11702
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
testl %ebp, %ebp
cmovlel %ebx, %ebp
movq 0xd876(%rip), %r14      # 0x1efd0
leaq 0xdedf(%rip), %r15      # 0x1f640
cmpl %ebx, %ebp
je 0x11782
testl %ebx, %ebx
je 0x11774
movq %r14, %rdi
movq %r15, %rsi
callq 0x3210
movq %r14, %rdi
movl %ebx, %esi
callq 0x33f0
incl %ebx
jmp 0x11761
movq 0xd847(%rip), %rdi      # 0x1efd0
callq 0x3100
leaq 0xde4b(%rip), %rsi      # 0x1f5e0
movq %rax, %rdi
callq 0x3210
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3100
nop