// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
xorl %ebp, %ebp
movq 0x10a8c(%rip), %r13     # 0x1ffd0
movsd 0x30(%rbx), %xmm0
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
mulsd (%rcx), %xmm0
movsd %xmm0, (%rsp)
movq (%rax), %rdi
callq 0x10e1e
movsd 0x7a9f(%rip), %xmm1     # 0x17008
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x31e0
divsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movb $0x1, %al
movsd %xmm1, 0x8(%rsp)
ucomisd 0x20(%rsp), %xmm1
jae 0xf849
movq (%rbx), %rax
movq (%rax), %rdi
callq 0x10e1e
mulsd 0x30(%rbx), %xmm0
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x18(%rsp)
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x18(%rsp), %rdx
callq 0x9ad4
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa08e
movq 0x10e59(%rip), %rsi     # 0x20438
movq 0x10e5a(%rip), %rdx     # 0x20440
movq %r13, %rdi
callq 0x32a0
movq 0x10ee3(%rip), %rsi     # 0x204d8
movq 0x10ee4(%rip), %rdx     # 0x204e0
movq %rax, %rdi
callq 0x32a0
movq 0xa8(%rbx), %rcx
movq 0x8(%rcx), %rsi
subq (%rcx), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x31a0
movq 0x10eb3(%rip), %rsi     # 0x204d8
movq 0x10eb4(%rip), %rdx     # 0x204e0
movq %rax, %rdi
callq 0x32a0
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 0x3360
movq 0x10e72(%rip), %rsi     # 0x204d8
movq 0x10e73(%rip), %rdx     # 0x204e0
movq %rax, %rdi
callq 0x32a0
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 0x3360
movq 0x10e31(%rip), %rsi     # 0x204d8
movq 0x10e32(%rip), %rdx     # 0x204e0
movq %rax, %rdi
callq 0x32a0
movq 0x8(%rbx), %rax
movl 0x30(%rax), %r14d
testq %r14, %r14
je 0xf6fa
xorl %r12d, %r12d
movq 0xb0(%rbx), %rax
movq 0xc0(%rbx), %rcx
movq (%rcx,%r12,8), %r15
movb 0x7c(%r15), %cl
movb %cl, (%rax,%r12)
movzbl 0x7c(%r15), %esi
movq %r13, %rdi
callq 0x33a0
movb $0x0, 0x7c(%r15)
incq %r12
cmpq %r12, %r14
jne 0xf6c6
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31b0
movq 0x8(%rbx), %rax
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
cmpb $0x1, 0x49(%rax)
jne 0xf804
testq %r14, %r14
je 0xf75d
movq 0xb0(%rbx), %rcx
xorl %edx, %edx
xorl %esi, %esi
movzbl (%rcx,%rdx), %edi
addl %edi, %esi
incq %rdx
cmpq %rdx, %r14
jne 0xf749
cvtsi2sd %esi, %xmm1
jmp 0xf761
xorpd %xmm1, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
divsd %xmm0, %xmm1
cmpb $0x1, 0x4a(%rax)
movsd %xmm1, (%rsp)
jne 0xf7ae
ucomisd 0x93f8(%rip), %xmm1     # 0x18b78
jbe 0xf7ae
testq %r14, %r14
je 0xf79c
movq 0xb0(%rbx), %rax
xorl %ecx, %ecx
xorb $0x1, (%rax,%rcx)
incq %rcx
cmpq %rcx, %r14
jne 0xf790
movsd 0x7864(%rip), %xmm0     # 0x17008
subsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movl $0x20, %edi
callq 0x3260
movq %rax, %r14
xorps %xmm2, %xmm2
movq %rax, %rdi
movsd (%rsp), %xmm0
movapd %xmm0, %xmm1
callq 0x11ed2
movq %r14, 0x10(%rsp)
movq 0x8(%rbx), %rax
movq 0x90(%rax), %rdi
leaq 0x10(%rsp), %rsi
callq 0x11ac6
movq 0x8(%rbx), %rcx
movq 0x90(%rcx), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0xf862
movq 0x20(%rax), %rax
incl 0x18(%rax)
movq 0xa8(%rbx), %r14
movl $0x18, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
movsd (%rsp), %xmm1
callq 0x11e48
movq %r12, 0x10(%rsp)
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x11b42
leaq 0x30(%rsp), %rdi
callq 0x10dec
movl %ebp, %eax
movl %eax, %ebp
testb $0x1, %al
je 0xf544
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x3100
leaq 0x99b8(%rip), %rcx      # 0x1922b
movq %rcx, (%rax)
movq 0x10733(%rip), %rsi     # 0x1ffb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x33d0
jmp 0xf8b4
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
jmp 0xf8a5
jmp 0xf8b4
jmp 0xf8b4
movq %rax, %rbx
movl $0x18, %esi
movq %r12, %rdi
callq 0x3270
jmp 0xf8b7
jmp 0xf8b4
jmp 0xf8b4
jmp 0xf8b4
jmp 0xf8b4
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x10dec
movq %rbx, %rdi
callq 0x33f0
nop