// File: /workspace/github_cpp_makefile_star2_O2/gchen98[P]macs/algorithm.cpp
// Function: GraphBuilder::addMutations(double, double)
void GraphBuilder::addMutations(double startPos,double endPos){
    bool bEndMutate = false;
    while(!bEndMutate){
        // find the next point on this interval
        startPos+=pRandNumGenerator->expRV(dLastTreeLength*
        pConfig->dTheta);
        if (startPos>=endPos){
            bEndMutate = true;
        }else{
            //if (pMutationPtrVector->size()==0){
            //   cout<<HAPLOBEGIN<<endl;
            //}
            double dRandomSpot = pRandNumGenerator->unifRV() * dLastTreeLength;
            double dMutationTime=-1.;
            EdgePtr selectedEdge = getRandomEdgeOnTree(dMutationTime,dRandomSpot);
            //cerr<<"Mutation time is "<<dMutationTime<<endl;
            mutateBelowEdge(selectedEdge);
            NodePtrVector::iterator it;

            cout<<MUTATIONSITE<<FIELD_DELIMITER<<pMutationPtrVector->size()<<
            FIELD_DELIMITER<< setw(15) << setprecision(9)<<startPos<<
            FIELD_DELIMITER<< setw(15) << setprecision(9)<<dMutationTime<<
            FIELD_DELIMITER;
            unsigned int iSampleSize = pConfig->iSampleSize;
            for (unsigned int iSampleIndex=0;iSampleIndex<iSampleSize;++iSampleIndex){
                SampleNode * sample = static_cast<SampleNode*>(pSampleNodeArray[iSampleIndex].get());
                sites[iSampleIndex]=sample->bAffected;
                cout<<sample->bAffected;
                sample->bAffected=false;
            }
            cout<<endl;
            double dFreq=0.;
            if (pConfig->bSNPAscertainment){
                // first compute the MAF
                int counts=0;
                for (unsigned int i=0;i<iSampleSize;++i){
                    counts=counts+sites[i];
                }
                dFreq = 1.*counts/iSampleSize;
                if (pConfig->bFlipAlleles && dFreq>.5){
                    for (unsigned int i=0;i<iSampleSize;++i){
                        sites[i]=!sites[i];
                    }
                    dFreq = 1.-dFreq;
                }
                AlleleFreqBinPtr query(new AlleleFreqBin(dFreq,dFreq,0.));
                AlleleFreqBinPtrSet::iterator it = pConfig->pAlleleFreqBinPtrSet->find(query);
                if (it!=pConfig->pAlleleFreqBinPtrSet->end()){
                    AlleleFreqBinPtr bin = *it;
                    ++bin->iObservedCounts;
                }else throw "Did not find a frequency range for freq";
            }
            pMutationPtrVector->push_back(MutationPtr(new Mutation(startPos,dFreq)));

        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rdi, %r14
xorl %r15d, %r15d
movq 0x12307(%rip), %r13     # 0x1efd0
testb $0x1, %r15b
jne 0xcf4f
movsd 0x30(%r14), %xmm0
movq (%r14), %rdi
movq 0x8(%r14), %rax
mulsd (%rax), %xmm0
callq 0xddac
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
ucomisd 0x20(%rsp), %xmm1
setae %r15b
jae 0xccc9
movq (%r14), %rdi
callq 0xdaee
mulsd 0x30(%r14), %xmm0
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x18(%rsp)
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x18(%rsp), %rdx
callq 0x86f4
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8b66
movq %r13, %rdi
leaq 0x126ec(%rip), %rsi     # 0x1f438
callq 0x3210
movq %rax, %rdi
leaq 0x1277d(%rip), %rsi     # 0x1f4d8
callq 0x3210
movq 0xa8(%r14), %rcx
movq 0x8(%rcx), %rsi
subq (%rcx), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x31a0
movq %rax, %rdi
leaq 0x12754(%rip), %rsi     # 0x1f4d8
callq 0x3210
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0xf, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq $0x9, 0x8(%rax,%rcx)
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3370
movq %rax, %rdi
leaq 0x1271a(%rip), %rsi     # 0x1f4d8
callq 0x3210
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0xf, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq $0x9, 0x8(%rax,%rcx)
movsd 0x18(%rsp), %xmm0
movq %rax, %rdi
callq 0x3370
movq %rax, %rdi
leaq 0x126e0(%rip), %rsi     # 0x1f4d8
callq 0x3210
movq 0x8(%r14), %rax
movl 0x30(%rax), %r12d
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0xce37
movq 0xb0(%r14), %rax
movq 0xc0(%r14), %rcx
movq (%rcx,%rbp,8), %rbx
movzbl 0x7c(%rbx), %esi
movb %sil, (%rax,%rbp)
movq %r13, %rdi
callq 0x33b0
movb $0x0, 0x7c(%rbx)
incq %rbp
jmp 0xce07
movq %r13, %rdi
callq 0x3100
movq 0x8(%r14), %rcx
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
cmpb $0x1, 0x49(%rcx)
jne 0xcf09
movq 0xb0(%r14), %rax
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %r12
je 0xce71
movzbl (%rax,%rdx), %edi
addl %edi, %esi
incq %rdx
jmp 0xce61
cvtsi2sd %esi, %xmm1
cvtsi2sd %r12, %xmm0
divsd %xmm0, %xmm1
cmpb $0x1, 0x4a(%rcx)
movsd %xmm1, (%rsp)
jne 0xceb5
ucomisd 0x8cef(%rip), %xmm1     # 0x15b80
jbe 0xceb5
xorl %ecx, %ecx
cmpq %rcx, %r12
je 0xcea3
xorb $0x1, (%rax,%rcx)
incq %rcx
jmp 0xce95
movsd 0x715d(%rip), %xmm0     # 0x14008
subsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
pushq $0x20
popq %rdi
callq 0x3260
movq %rax, %rbp
xorps %xmm2, %xmm2
movq %rax, %rdi
movsd (%rsp), %xmm0
movapd %xmm0, %xmm1
callq 0xf6dc
movq %rbp, 0x10(%rsp)
movq 0x8(%r14), %rax
movq 0x90(%rax), %rdi
leaq 0x10(%rsp), %rsi
callq 0xf26e
movq 0x8(%r14), %rcx
movq 0x90(%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0xcf5e
movq 0x20(%rax), %rax
incl 0x18(%rax)
movq 0xa8(%r14), %rbp
pushq $0x18
popq %rdi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
callq 0xf67a
movq %r12, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0xf302
leaq 0x30(%rsp), %rdi
callq 0xdff8
jmp 0xccc9
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x8
popq %rdi
callq 0x3110
leaq 0x92ce(%rip), %rcx      # 0x1623b
movq %rcx, (%rax)
movq 0x12049(%rip), %rsi     # 0x1efc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x33e0
jmp 0xcfaa
movq %rax, %rbx
pushq $0x20
popq %rsi
movq %rbp, %rdi
jmp 0xcf9b
jmp 0xcfaa
jmp 0xcfaa
movq %rax, %rbx
pushq $0x18
popq %rsi
movq %r12, %rdi
callq 0x3270
jmp 0xcfad
jmp 0xcfaa
jmp 0xcfaa
jmp 0xcfaa
jmp 0xcfaa
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xdff8
movq %rbx, %rdi
callq 0x3400
nop