// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0xa8(%rax), %rdi
callq 0x1f740
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movl %ecx, -0xc(%rbp)
movb $0x0, -0xd(%rbp)
movq 0x8(%rax), %rax
testb $0x1, 0x48(%rax)
je 0x2a98e
movq 0x1e688(%rip), %rdi     # 0x48ff0
leaq 0x9ee5(%rip), %rsi      # 0x34854
callq 0x42b0
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x43e0
movq %rax, %rdi
movq 0x1e627(%rip), %rsi     # 0x48fb0
callq 0x4300
cmpl $0x0, -0xc(%rbp)
je 0x2afed
movq -0xa8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, -0x14(%rbp)
movq 0x8(%rax), %rax
testb $0x1, 0x49(%rax)
je 0x2adc8
movb $0x0, -0x15(%rbp)
movq -0xa8(%rbp), %rax
movb $0x1, -0x15(%rbp)
movq 0x8(%rax), %rax
movq 0x90(%rax), %rdi
callq 0xb860
movq %rax, -0x20(%rbp)
xorl %eax, %eax
testb $0x1, -0x15(%rbp)
movb %al, -0xa9(%rbp)
je 0x2aa20
xorl %eax, %eax
testb $0x1, -0xd(%rbp)
movb %al, -0xa9(%rbp)
jne 0x2aa20
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x90(%rax), %rdi
callq 0xb8c0
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xb890
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x2aa2f
jmp 0x2aaff
leaq -0x20(%rbp), %rdi
callq 0xb8f0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsd 0x10(%rax), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x2aad4
movq -0x30(%rbp), %rax
movsd 0x10(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2aad4
movq -0xa8(%rbp), %rax
movb $0x1, -0xd(%rbp)
movq 0x8(%rax), %rax
testb $0x1, 0x48(%rax)
je 0x2aad2
movq 0x1e564(%rip), %rdi     # 0x48ff0
leaq 0x9dcf(%rip), %rsi      # 0x34862
callq 0x42b0
movq %rax, %rdi
movq -0x30(%rbp), %rax
movsd 0x10(%rax), %xmm0
callq 0x4550
movq %rax, %rdi
leaq 0x9def(%rip), %rsi      # 0x348a2
callq 0x42b0
movq %rax, %rdi
movl -0x34(%rbp), %esi
callq 0x44d0
movq %rax, %rdi
movq 0x1e4e3(%rip), %rsi     # 0x48fb0
callq 0x4300
jmp 0x2aafa
movq -0x30(%rbp), %rax
movl 0x18(%rax), %eax
cmpl -0x34(%rbp), %eax
jge 0x2aaef
movb $0x0, -0x15(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2aaf8
leaq -0x20(%rbp), %rdi
callq 0xb920
jmp 0x2aafa
jmp 0x2a9d6
jmp 0x2ab01
xorl %eax, %eax
testb $0x1, -0x15(%rbp)
movb %al, -0xaa(%rbp)
jne 0x2ab1a
movb -0xd(%rbp), %al
xorb $-0x1, %al
movb %al, -0xaa(%rbp)
movb -0xaa(%rbp), %al
testb $0x1, %al
jne 0x2a9b7
testb $0x1, -0xd(%rbp)
je 0x2ab6b
movq 0x1e4bb(%rip), %rdi     # 0x48ff0
leaq 0x9d72(%rip), %rsi      # 0x348ae
callq 0x42b0
movq %rax, %rdi
leaq 0x9db5(%rip), %rsi      # 0x34900
callq 0x42b0
movq %rax, %rdi
leaq 0x9dd0(%rip), %rsi      # 0x3492a
callq 0x42b0
movl $0x0, -0x14(%rbp)
jmp 0x2adc6
movq -0xa8(%rbp), %rax
movl $0x0, -0x38(%rbp)
movq 0x8(%rax), %rax
movq 0x90(%rax), %rdi
callq 0xb860
movq %rax, -0x40(%rbp)
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x90(%rax), %rdi
callq 0xb8c0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xb890
testb $0x1, %al
jne 0x2abbe
jmp 0x2ad79
leaq -0x40(%rbp), %rdi
callq 0xb8f0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movsd (%rcx), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x50(%rbp), %rcx
movsd 0x8(%rcx), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x50(%rbp), %rcx
movsd 0x10(%rcx), %xmm0
cvtsi2sdl -0x14(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x64(%rbp)
movl -0x64(%rbp), %ecx
addl -0x38(%rbp), %ecx
movl %ecx, -0x38(%rbp)
movq 0x8(%rax), %rax
testb $0x1, 0x48(%rax)
je 0x2acdb
movq 0x1e3c6(%rip), %rdi     # 0x48ff0
leaq 0x9d3d(%rip), %rsi      # 0x3496e
callq 0x42b0
movq %rax, %rdi
movsd -0x58(%rbp), %xmm0
callq 0x4550
movq %rax, %rdi
leaq 0x851c(%rip), %rsi      # 0x33169
callq 0x42b0
movq %rax, %rdi
movsd -0x60(%rbp), %xmm0
callq 0x4550
movq %rax, %rdi
movq 0x1e347(%rip), %rsi     # 0x48fb0
callq 0x4300
movq 0x1e37b(%rip), %rdi     # 0x48ff0
leaq 0x9d0d(%rip), %rsi      # 0x34989
callq 0x42b0
movq %rax, %rdi
movq -0x50(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x44d0
movq %rax, %rdi
movq 0x1e316(%rip), %rsi     # 0x48fb0
callq 0x4300
movq 0x1e34a(%rip), %rdi     # 0x48ff0
leaq 0x9cee(%rip), %rsi      # 0x3499b
callq 0x42b0
movq %rax, %rdi
movl -0x64(%rbp), %esi
callq 0x44d0
movq %rax, %rdi
leaq 0x9cdf(%rip), %rsi      # 0x349a6
callq 0x42b0
movq %rax, %rdi
movq 0x1e2da(%rip), %rsi     # 0x48fb0
callq 0x4300
jmp 0x2acdd
cmpl $0x0, -0x64(%rbp)
jle 0x2ad69
movq -0xa8(%rbp), %rax
movq (%rax), %rdi
callq 0x1e170
movq -0xa8(%rbp), %rax
movl -0xc(%rbp), %ecx
cvtsi2sd %rcx, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x68(%rbp)
movq 0xa8(%rax), %rdi
movslq -0x68(%rbp), %rsi
callq 0x2bf40
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
testb $0x1, 0x10(%rax)
jne 0x2ad64
movq -0x70(%rbp), %rax
movsd (%rax), %xmm0
ucomisd -0x58(%rbp), %xmm0
jb 0x2ad64
movq -0x70(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x2ad64
movq -0x70(%rbp), %rax
movb $0x1, 0x10(%rax)
movl -0x64(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x2acdd
jmp 0x2ad6b
leaq -0x40(%rbp), %rdi
callq 0xb920
jmp 0x2ab8d
movl -0x38(%rbp), %eax
movl %eax, -0x14(%rbp)
movq 0x1e26a(%rip), %rdi     # 0x48ff0
leaq 0x9c20(%rip), %rsi      # 0x349ad
callq 0x42b0
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x43e0
movq %rax, %rdi
leaq 0x83c2(%rip), %rsi      # 0x33169
callq 0x42b0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x44d0
movq %rax, %rdi
movq 0x1e1ef(%rip), %rsi     # 0x48fb0
callq 0x4300
jmp 0x2adc8
cmpl $0x0, -0x14(%rbp)
je 0x2afeb
leaq -0x78(%rbp), %rdi
callq 0x2ba10
movq 0x1e1ee(%rip), %rdi     # 0x48fd0
leaq 0x1e8af(%rip), %rsi     # 0x49698
callq 0x4280
movq %rax, %rdi
leaq 0x1e8e0(%rip), %rsi     # 0x496d8
callq 0x4280
movq %rax, %rdi
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %esi
callq 0x43e0
movq %rax, %rdi
movq 0x1e193(%rip), %rsi     # 0x48fb0
callq 0x4300
movq 0x1e1a7(%rip), %rdi     # 0x48fd0
leaq 0x1e888(%rip), %rsi     # 0x496b8
callq 0x4280
movq %rax, %rdi
leaq 0x1e899(%rip), %rsi     # 0x496d8
callq 0x4280
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x44d0
movq %rax, %rdi
movq 0x1e157(%rip), %rsi     # 0x48fb0
callq 0x4300
movq 0x1e16b(%rip), %rdi     # 0x48fd0
leaq 0x1e7ec(%rip), %rsi     # 0x49658
callq 0x4280
movq %rax, %rdi
movq 0x1e135(%rip), %rsi     # 0x48fb0
callq 0x4300
movq -0xa8(%rbp), %rax
movq 0x8(%rax), %rax
testb $0x1, 0x49(%rax)
je 0x2af64
testb $0x1, -0xd(%rbp)
jne 0x2af64
movq -0xa8(%rbp), %rax
movl $0x0, -0x7c(%rbp)
movb $0x0, -0x7d(%rbp)
movq 0xa8(%rax), %rdi
callq 0x26150
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0xa8(%rbp), %rax
movq 0xa8(%rax), %rdi
callq 0x25fa0
movq %rax, -0x90(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x2ba30
testb $0x1, %al
jne 0x2aeff
jmp 0x2af62
leaq -0x78(%rbp), %rdi
callq 0x265b0
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
testb $0x1, 0x10(%rax)
je 0x2af4b
testb $0x1, -0x7d(%rbp)
je 0x2af38
movq 0x1e0a4(%rip), %rdi     # 0x48fd0
leaq 0x1e7a5(%rip), %rsi     # 0x496d8
callq 0x4280
movl -0x7c(%rbp), %esi
movq 0x1e08e(%rip), %rdi     # 0x48fd0
callq 0x44d0
movb $0x1, -0x7d(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2ba70
jmp 0x2aecf
jmp 0x2afba
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2afb8
cmpl $0x0, -0x9c(%rbp)
je 0x2af95
movq 0x1e047(%rip), %rdi     # 0x48fd0
leaq 0x1e748(%rip), %rsi     # 0x496d8
callq 0x4280
movl -0x9c(%rbp), %esi
movq 0x1e02e(%rip), %rdi     # 0x48fd0
callq 0x44d0
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x2af6e
jmp 0x2afba
movq 0x1e00f(%rip), %rdi     # 0x48fd0
movq 0x1dfe8(%rip), %rsi     # 0x48fb0
callq 0x4300
movq %rax, %rdi
leaq 0x1e6a1(%rip), %rsi     # 0x49678
callq 0x4280
movq %rax, %rdi
movq 0x1dfca(%rip), %rsi     # 0x48fb0
callq 0x4300
jmp 0x2afed
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)