// File: 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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movb $0x0, -0x19(%rbp)
movb -0x19(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1c846
jmp 0x1ce1e
movq -0xc0(%rbp), %rax
movq (%rax), %rdi
movsd 0x30(%rax), %xmm0
movq 0x8(%rax), %rax
mulsd (%rax), %xmm0
callq 0x1ec00
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jb 0x1c881
movb $0x1, -0x19(%rbp)
jmp 0x1ce19
movq -0xc0(%rbp), %rax
movq (%rax), %rdi
callq 0x1e170
movq -0xc0(%rbp), %rsi
movsd 0x30(%rsi), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x30(%rbp)
movsd -0x28(%rbp), %xmm0
leaq -0x40(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
leaq -0x30(%rbp), %rdx
callq 0x14e50
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x154c0
jmp 0x1c8e1
leaq -0x58(%rbp), %rdi
callq 0x1f720
movq 0x2c6df(%rip), %rdi     # 0x48fd0
leaq 0x2cbd8(%rip), %rsi     # 0x494d0
callq 0x4280
movq %rax, -0xd0(%rbp)
jmp 0x1c906
movq -0xd0(%rbp), %rdi
leaq 0x2cc5c(%rip), %rsi     # 0x49570
callq 0x4280
movq %rax, -0xd8(%rbp)
jmp 0x1c922
movq -0xc0(%rbp), %rax
movq 0xa8(%rax), %rdi
callq 0x1f740
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0x4090
movq %rax, -0xe0(%rbp)
jmp 0x1c94d
movq -0xe0(%rbp), %rdi
leaq 0x2cc15(%rip), %rsi     # 0x49570
callq 0x4280
movq %rax, -0xe8(%rbp)
jmp 0x1c969
movl $0xf, %edi
callq 0x1f760
movl %eax, -0xec(%rbp)
jmp 0x1c97b
movq -0xe8(%rbp), %rdi
movl -0xec(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %esi
callq 0x4360
movq %rax, -0xf8(%rbp)
jmp 0x1c99c
movl $0x9, %edi
callq 0x1f780
movl %eax, -0xfc(%rbp)
jmp 0x1c9ae
movq -0xf8(%rbp), %rdi
movl -0xfc(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %esi
callq 0x4450
movq %rax, -0x108(%rbp)
jmp 0x1c9cf
movq -0x108(%rbp), %rdi
movsd -0x10(%rbp), %xmm0
callq 0x4550
movq %rax, -0x110(%rbp)
jmp 0x1c9e9
movq -0x110(%rbp), %rdi
leaq 0x2cb79(%rip), %rsi     # 0x49570
callq 0x4280
movq %rax, -0x118(%rbp)
jmp 0x1ca05
movl $0xf, %edi
callq 0x1f760
movl %eax, -0x11c(%rbp)
jmp 0x1ca17
movq -0x118(%rbp), %rdi
movl -0x11c(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %esi
callq 0x4360
movq %rax, -0x128(%rbp)
jmp 0x1ca38
movl $0x9, %edi
callq 0x1f780
movl %eax, -0x12c(%rbp)
jmp 0x1ca4a
movq -0x128(%rbp), %rdi
movl -0x12c(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %esi
callq 0x4450
movq %rax, -0x138(%rbp)
jmp 0x1ca6b
movq -0x138(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
callq 0x4550
movq %rax, -0x140(%rbp)
jmp 0x1ca85
movq -0x140(%rbp), %rdi
leaq 0x2cadd(%rip), %rsi     # 0x49570
callq 0x4280
jmp 0x1ca9a
movq -0xc0(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jae 0x1cb36
movq -0xc0(%rbp), %rax
movq 0xc0(%rax), %rax
movl -0x70(%rbp), %ecx
leaq (%rax,%rcx,8), %rdi
callq 0x1e220
movq %rax, %rcx
movq -0xc0(%rbp), %rax
movq %rcx, -0x78(%rbp)
movq -0x78(%rbp), %rcx
movb 0x7c(%rcx), %dl
movq 0xb0(%rax), %rax
movl -0x70(%rbp), %ecx
andb $0x1, %dl
movb %dl, (%rax,%rcx)
movq -0x78(%rbp), %rax
movzbl 0x7c(%rax), %esi
andl $0x1, %esi
movq 0x2c4c5(%rip), %rdi     # 0x48fd0
callq 0x4500
jmp 0x1cb12
movq -0x78(%rbp), %rax
movb $0x0, 0x7c(%rax)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x1cab2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1ce0e
movq 0x2c493(%rip), %rdi     # 0x48fd0
movq 0x2c46c(%rip), %rsi     # 0x48fb0
callq 0x4300
jmp 0x1cb4b
movq -0xc0(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
movq 0x8(%rax), %rax
testb $0x1, 0x49(%rax)
je 0x1cd83
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jae 0x1cbc3
movq -0xc0(%rbp), %rcx
movl -0x84(%rbp), %eax
movq 0xb0(%rcx), %rcx
movl -0x88(%rbp), %edx
movb (%rcx,%rdx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movl %eax, -0x84(%rbp)
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x1cb7c
movq -0xc0(%rbp), %rax
cvtsi2sdl -0x84(%rbp), %xmm0
movl -0x6c(%rbp), %ecx
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movq 0x8(%rax), %rax
testb $0x1, 0x4a(%rax)
je 0x1cc65
movsd -0x80(%rbp), %xmm0
movsd 0x15416(%rip), %xmm1    # 0x32010
ucomisd %xmm1, %xmm0
jbe 0x1cc65
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jae 0x1cc53
movq -0xc0(%rbp), %rax
movq 0xb0(%rax), %rcx
movl -0x8c(%rbp), %edx
movb (%rcx,%rdx), %dl
xorb $-0x1, %dl
movq 0xb0(%rax), %rax
movl -0x8c(%rbp), %ecx
andb $0x1, %dl
movb %dl, (%rax,%rcx)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1cc0a
movsd 0x153ad(%rip), %xmm0    # 0x32008
subsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movl $0x20, %edi
callq 0x42c0
movq %rax, -0x148(%rbp)
jmp 0x1cc78
movq -0x148(%rbp), %rdi
movsd -0x80(%rbp), %xmm1
xorps %xmm2, %xmm2
movaps %xmm1, %xmm0
callq 0x272f0
jmp 0x1cc91
movq -0xc0(%rbp), %rax
movq -0x148(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movq 0x8(%rax), %rax
movq 0x90(%rax), %rdi
leaq -0x98(%rbp), %rsi
callq 0x1f7a0
movq %rax, -0x150(%rbp)
jmp 0x1ccc6
movq -0xc0(%rbp), %rax
movq -0x150(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movq 0x8(%rax), %rax
movq 0x90(%rax), %rdi
callq 0xb8c0
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xb890
testb $0x1, %al
jne 0x1cd0b
jmp 0x1cd55
leaq -0xa0(%rbp), %rdi
callq 0xb8f0
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
jmp 0x1cd81
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl $0x20, %esi
callq 0x42d0
jmp 0x1ce0e
movl $0x8, %edi
callq 0x4130
movq %rax, %rdi
leaq 0x17580(%rip), %rax     # 0x342e9
movq %rax, (%rdi)
movq 0x2c245(%rip), %rsi     # 0x48fb8
xorl %eax, %eax
movl %eax, %edx
callq 0x44c0
jmp 0x1ce30
jmp 0x1cd83
movq -0xc0(%rbp), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x160(%rbp)
movl $0x18, %edi
callq 0x42c0
movq %rax, -0x158(%rbp)
jmp 0x1cdab
movq -0x158(%rbp), %rdi
movsd -0x10(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
callq 0x271b0
jmp 0x1cdc3
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rsi
callq 0x1f7e0
jmp 0x1cde6
leaq -0x40(%rbp), %rdi
callq 0x1e090
jmp 0x1ce19
movq -0x158(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl $0x18, %esi
callq 0x42d0
leaq -0x40(%rbp), %rdi
callq 0x1e090
jmp 0x1ce27
jmp 0x1c838
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x44e0