// File: /workspace/github_cpp_makefile_star2_O2/gchen98[P]macs/algorithm.cpp
// Function: GraphBuilder::invokeRecombination(GeneConversion*&)
void GraphBuilder::invokeRecombination(GeneConversionPtr & geneConversionPtr){
    double dSplitPoint=0.0;
    double dRandomSpot = pRandNumGenerator->unifRV() * dLastTreeLength;
    EdgePtr selectedXoverEdge = getRandomEdgeOnTree(dSplitPoint,dRandomSpot);
    xOverNode = NodePtr(new Node(Node::XOVER,
    selectedXoverEdge->getBottomNodeRef()->getPopulation(),dSplitPoint));
    // save old edge if gene conversion
    if (this->bBeginGeneConversion) geneConversionPtr->xOverNode = xOverNode;

    if(pConfig->bDebug){
         cerr<<"Adding xover point at "<<dSplitPoint<<
        " for edge "<<selectedXoverEdge->getBottomNodeRef()->getHeight()<<
        " to "<<selectedXoverEdge->getTopNodeRef()->getHeight()<<
        " of population "<<selectedXoverEdge->getBottomNodeRef()->getPopulation()<<endl;
    }
    EventPtr pXoverEventWrapper = EventPtr(new XoverEvent
    (Event::XOVER,dSplitPoint,xOverNode->getPopulation()));
    // insert the xover node at the selected edge
    insertNodeInEdge(xOverNode,selectedXoverEdge);

    // mark the edge above the xover.  this is the old coalescing line to prune.
    // set up a coalescing line that is visible to the
    // event building method
    NodePtr nodeAboveXover = NodePtr(new Node
    (Node::QUERY,xOverNode->getPopulation(),Node::MAX_HEIGHT));
    coalescingEdge = EdgePtr(new Edge(nodeAboveXover,xOverNode));
    nodeAboveXover->addNewEdge(Node::BOTTOM_EDGE,coalescingEdge);
    xOverNode->addNewEdge(Node::TOP_EDGE,coalescingEdge);
    // similarly, set up a line that runs straight up from the grandMRCA
    // in case migration events need to be inserted above the grandMRCA.
    NodePtr nodeAboveOrigin = NodePtr(new Node
    (Node::QUERY,grandMRCA->getPopulation(),Node::MAX_HEIGHT));
    originExtension = EdgePtr(new Edge(nodeAboveOrigin,grandMRCA));
    nodeAboveOrigin->addNewEdge(Node::BOTTOM_EDGE,originExtension);
    grandMRCA->addNewEdge(Node::TOP_EDGE,originExtension);
    // now initialize the parameters that will be sent to the event traversal routine
    EventPtr newCoalEvent;
    // Traverse the events to find the proper coalescent waiting time.
    if (pConfig->bDebug){
      cerr<<"Calling traverse events\n";
    }
    traverseEvents(true,xOverNode,newCoalEvent);
    if (pConfig->bDebug){
      cerr<<"Traverse events completed successfully\n";
    }
    dSplitPoint = newCoalEvent->getTime();
    bool bNewOrigin = false;
    EdgePtr selectedCoalEdge;
    if (dSplitPoint<this->grandMRCA->getHeight()){
        if(pConfig->bDebug) cerr<<"Coalescing at height "<<dSplitPoint<<endl;
        try{
            selectedCoalEdge = getRandomEdgeToCoalesce(
            coalescingEdge,dSplitPoint);
        }catch(unsigned int numEdges){
            printDataStructures();
            throw
             "Didn't find an edge to coalesce with, exiting\n";
        }
    }else{
        bNewOrigin = true;
    }
    NodePtr coalNode;
    // save the previous grand MRCA
    NodePtr oldGrandMRCA = grandMRCA;
    // discard the grandMRCA extending edge above the grandMRCA
    grandMRCA = originExtension->getBottomNodeRef();
    grandMRCA->clearTopEdges();
    if (bNewOrigin){
        coalNode = NodePtr(new Node(Node::COAL,
        grandMRCA->getPopulation(),dSplitPoint));
        if(pConfig->bDebug) cerr<<"Creating new grand ancestor at "<<
        coalNode->getHeight()<<endl;
        #ifdef DIAG
        if (grandMRCA->getPopulation()!=coalNode->getPopulation()){
            throw "Old grandMRCA and new grandMRCA don't match in pop\n";
        }
        #endif
        EdgePtr shortEdge = EdgePtr(new Edge(coalNode,grandMRCA));
        shortEdge->iGraphIteration=iGraphIteration;
        addEdge(shortEdge);
        grandMRCA->addNewEdge(Node::TOP_EDGE,shortEdge);
        grandMRCA = coalNode;
        grandMRCA->addNewEdge(Node::BOTTOM_EDGE,shortEdge);
    }else{
        coalNode = NodePtr(new Node(
        Node::COAL,coalescingEdge->getBottomNodeRef()->getPopulation(),
        dSplitPoint));
        insertNodeInEdge(coalNode,selectedCoalEdge);
    }
    // set the variable proposed grandMRCA so that marking current tree can reach at least this
    // height
    localMRCA = coalNode;
    coalNode->setEvent(newCoalEvent);
    EdgePtr coalEdgeCopy = coalescingEdge;
    coalescingEdge = EdgePtr(new Edge(coalNode,coalescingEdge->getBottomNodeRef()));
    coalescingEdge->iGraphIteration = coalEdgeCopy->iGraphIteration;
    coalescingEdge->getBottomNodeRef()->replaceOldWithNewEdge(Node::TOP_EDGE,
    coalEdgeCopy,coalescingEdge);
    coalescingEdge->getTopNodeRef()->addNewEdge(Node::BOTTOM_EDGE,
    coalescingEdge);
    addEdge(coalescingEdge);
    coalescingEdge->iGraphIteration=iGraphIteration;
    EdgePtr edgeBelowXover = xOverNode->getBottomEdgeByIndex(0);
    markEdgesBelow(edgeBelowXover);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x78(%rsp), %r14
andq $0x0, (%r14)
movq (%rdi), %rdi
callq 0xdaee
mulsd 0x30(%rbx), %xmm0
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x86f4
pushq $0x78
popq %rdi
callq 0x3260
movq %rax, %r12
leaq 0x48(%rsp), %rdi
callq 0xda24
leaq 0x20(%rax), %rdi
callq 0xda4e
movswl 0x62(%rax), %edx
movsd 0x78(%rsp), %xmm0
pushq $0x1
popq %rsi
movq %r12, %rdi
movsd %xmm0, (%rsp)
callq 0xfa82
leaq 0x20(%rsp), %r13
movq %r12, (%r13)
incq 0x8(%r12)
leaq 0x48(%rbx), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0xdb6e
movq %r13, %rdi
callq 0xdb46
cmpb $0x1, 0xf8(%rbx)
jne 0x91fc
movq (%r15), %rdi
addq $0x10, %rdi
movq %r14, %rsi
callq 0xdb16
movq 0x8(%rbx), %rax
cmpb $0x1, 0x48(%rax)
jne 0x92c7
movq 0x15ddf(%rip), %rdi     # 0x1eff0
leaq 0xcae8(%rip), %rsi      # 0x15d00
callq 0x3250
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x3370
leaq 0xcae6(%rip), %rsi      # 0x15d17
movq %rax, %rdi
callq 0x3250
movq %rax, %r15
leaq 0x48(%rsp), %rdi
callq 0xda24
leaq 0x20(%rax), %rdi
callq 0xda4e
movsd 0x70(%rax), %xmm0
movq %r15, %rdi
callq 0x3370
leaq 0xbe36(%rip), %rsi      # 0x15099
movq %rax, %rdi
callq 0x3250
movq %rax, %r15
leaq 0x48(%rsp), %rdi
callq 0xda24
leaq 0x18(%rax), %rdi
callq 0xda4e
movsd 0x70(%rax), %xmm0
movq %r15, %rdi
callq 0x3370
leaq 0xca8d(%rip), %rsi      # 0x15d22
movq %rax, %rdi
callq 0x3250
movq %rax, %r15
leaq 0x48(%rsp), %rdi
callq 0xda24
leaq 0x20(%rax), %rdi
callq 0xda4e
movswl 0x62(%rax), %esi
movq %r15, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3100
pushq $0x28
popq %rdi
callq 0x3260
movq %rax, %r15
movq %r14, %rdi
callq 0xda4e
movswl 0x62(%rax), %edx
pushq $0x5
popq %rsi
movq %r15, %rdi
movsd (%rsp), %xmm0
callq 0xfcb2
movq %r15, 0x70(%rsp)
incq 0x8(%r15)
leaq 0x48(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x10fe8
pushq $0x78
popq %rdi
callq 0x3260
movq %rax, %r15
movq %r14, %rdi
callq 0xda4e
movswl 0x62(%rax), %edx
leaq 0xad93(%rip), %rax      # 0x140b8
movsd (%rax), %xmm0
pushq $0x4
popq %rsi
movq %r15, %rdi
movsd %xmm0, (%rsp)
callq 0xfa82
movq %r15, 0x40(%rsp)
incq 0x8(%r15)
pushq $0x30
popq %rdi
callq 0x3260
movq %rax, %r15
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0xf72e
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0xdb9a
leaq 0x78(%rbx), %r15
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xdbce
leaq 0x28(%rsp), %rdi
callq 0xdff8
leaq 0x40(%rsp), %rdi
callq 0xda4e
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0xf880
movq %r14, %rdi
callq 0xda4e
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0xf880
pushq $0x78
popq %rdi
callq 0x3260
movq %rax, %r13
leaq 0x38(%rbx), %r12
movq %r12, %rdi
callq 0xda4e
movswl 0x62(%rax), %edx
pushq $0x4
popq %rsi
movq %r13, %rdi
movsd (%rsp), %xmm0
callq 0xfa82
movq %r13, 0x38(%rsp)
incq 0x8(%r13)
pushq $0x30
popq %rdi
callq 0x3260
movq %rax, %r13
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0xf72e
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0xdb9a
leaq 0x88(%rbx), %r13
leaq 0x20(%rsp), %rsi
movq %r13, %rdi
callq 0xdbce
leaq 0x28(%rsp), %rdi
callq 0xdff8
leaq 0x38(%rsp), %rdi
callq 0xda4e
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0xf880
movq %r12, %rdi
callq 0xda4e
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0xf880
andq $0x0, 0x30(%rsp)
movq 0x8(%rbx), %rax
cmpb $0x1, 0x48(%rax)
jne 0x947c
movq 0x15b80(%rip), %rdi     # 0x1eff0
leaq 0xc8bb(%rip), %rsi      # 0x15d32
callq 0x3250
pushq $0x1
popq %rsi
leaq 0x30(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rdx
callq 0x9a62
movq 0x8(%rbx), %rax
cmpb $0x1, 0x48(%rax)
jne 0x94ac
movq 0x15b50(%rip), %rdi     # 0x1eff0
leaq 0xc8a4(%rip), %rsi      # 0x15d4b
callq 0x3250
leaq 0x30(%rsp), %rdi
callq 0x8044
movsd 0x18(%rax), %xmm0
movsd %xmm0, (%rsp)
movsd %xmm0, 0x78(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %r12, %rdi
callq 0xda4e
movsd 0x70(%rax), %xmm0
movsd %xmm0, 0x80(%rsp)
ucomisd (%rsp), %xmm0
jbe 0x954b
movq 0x8(%rbx), %rax
cmpb $0x1, 0x48(%rax)
jne 0x951d
movq 0x15af4(%rip), %rdi     # 0x1eff0
leaq 0xc870(%rip), %rsi      # 0x15d73
callq 0x3250
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x3370
movq %rax, %rdi
callq 0x3100
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movsd (%rsp), %xmm0
callq 0x888c
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xdbce
leaq 0x18(%rsp), %rdi
callq 0xdff8
andq $0x0, 0x8(%rsp)
movq (%r12), %rax
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x9563
incq 0x8(%rax)
movq %r13, %rdi
callq 0xda24
leaq 0x20(%rax), %rsi
movq %r12, %rdi
callq 0xdb16
movq %r12, %rdi
callq 0xda4e
andw $0x0, 0x68(%rax)
movsd 0x80(%rsp), %xmm0
ucomisd (%rsp), %xmm0
ja 0x96b0
pushq $0x78
popq %rdi
callq 0x3260
movq %rax, %r13
movq %r12, %rdi
callq 0xda4e
movswl 0x62(%rax), %edx
movq %r13, %rdi
xorl %esi, %esi
movsd (%rsp), %xmm0
callq 0xfa82
leaq 0x10(%rsp), %rbp
movq %r13, (%rbp)
incq 0x8(%r13)
leaq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0xdb6e
movq %rbp, %rdi
callq 0xdb46
movq 0x8(%rbx), %rax
cmpb $0x1, 0x48(%rax)
jne 0x961f
movq 0x159ff(%rip), %rdi     # 0x1eff0
leaq 0xc7c0(%rip), %rsi      # 0x15db8
callq 0x3250
movq %rax, %r13
leaq 0x8(%rsp), %rdi
callq 0xda4e
movsd 0x70(%rax), %xmm0
movq %r13, %rdi
callq 0x3370
movq %rax, %rdi
callq 0x3100
pushq $0x30
popq %rdi
callq 0x3260
movq %rax, %r13
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0xf72e
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xdb9a
movl 0xd0(%rbx), %ebp
leaq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0xda24
movl %ebp, 0x14(%rax)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x10d3a
movq %r12, %rdi
callq 0xda4e
leaq 0x10(%rsp), %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0xf880
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0xdb16
movq %r12, %rdi
callq 0xda4e
pushq $0x1
popq %rsi
leaq 0x10(%rsp), %rdx
movq %rax, %rdi
callq 0xf880
leaq 0x18(%rsp), %rdi
callq 0xdff8
jmp 0x9715
pushq $0x78
popq %rdi
callq 0x3260
movq %rax, %r12
movq %r15, %rdi
callq 0xda24
leaq 0x20(%rax), %rdi
callq 0xda4e
movswl 0x62(%rax), %edx
movq %r12, %rdi
xorl %esi, %esi
movsd (%rsp), %xmm0
callq 0xfa82
leaq 0x10(%rsp), %r13
movq %r12, (%r13)
incq 0x8(%r12)
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0xdb6e
movq %r13, %rdi
callq 0xdb46
leaq 0x20(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x10fe8
leaq 0x40(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xdb16
leaq 0x8(%rsp), %rdi
callq 0xda4e
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0xdbfc
movq 0x78(%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x80(%rbx), %rax
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x9758
lock
incl 0x8(%rax)
leaq 0x18(%rsp), %r12
pushq $0x30
popq %rdi
callq 0x3260
movq %rax, %r13
movq %r15, %rdi
callq 0xda24
leaq 0x20(%rax), %rdx
leaq 0x8(%rsp), %rsi
movq %r13, %rdi
callq 0xf72e
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0xdb9a
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0xdbce
leaq 0x60(%rsp), %rdi
callq 0xdff8
leaq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0xda24
movl 0x14(%rax), %ebp
movq %r15, %rdi
callq 0xda24
movl %ebp, 0x14(%rax)
movq %r15, %rdi
callq 0xda24
leaq 0x20(%rax), %rdi
callq 0xda4e
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r15, %rcx
callq 0xf8d4
movq %r15, %rdi
callq 0xda24
leaq 0x18(%rax), %rdi
callq 0xda4e
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %r15, %rdx
callq 0xf880
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10d3a
movl 0xd0(%rbx), %ebp
movq %r15, %rdi
callq 0xda24
movl %ebp, 0x14(%rax)
movq %r14, %rdi
callq 0xda4e
leaq 0x40(%rax), %rsi
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0xe1ca
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8e9c
leaq 0x60(%rsp), %rdi
callq 0xdff8
movq %r12, %rdi
callq 0xdff8
leaq 0x68(%rsp), %rdi
callq 0xdb46
leaq 0x8(%rsp), %rdi
callq 0xdb46
leaq 0x28(%rsp), %rdi
callq 0xdff8
leaq 0x30(%rsp), %rdi
callq 0x6ce8
leaq 0x38(%rsp), %rdi
callq 0xdb46
leaq 0x40(%rsp), %rdi
callq 0xdb46
leaq 0x70(%rsp), %rdi
callq 0x6ce8
leaq 0x50(%rsp), %rdi
callq 0xdff8
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
pushq $0x30
jmp 0x98cb
movq %rax, %r14
pushq $0x78
popq %rsi
movq %r12, %rdi
jmp 0x98cf
movq %rax, %r14
pushq $0x78
popq %rsi
movq %r13, %rdi
callq 0x3270
jmp 0x9a05
jmp 0x9a02
jmp 0x9a02
movq %rax, %r14
cmpl $0x1, %edx
jne 0x9a19
movq %r14, %rdi
callq 0x30d0
movq %rbx, %rdi
callq 0x10736
pushq $0x8
popq %rdi
callq 0x3110
leaq 0xc47b(%rip), %rcx      # 0x15d89
movq %rcx, (%rax)
movq 0x156a8(%rip), %rsi     # 0x1efc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x33e0
movq %rax, %r14
callq 0x33a0
jmp 0x9a19
movq %rax, %r14
jmp 0x9a19
movq %rax, %r14
leaq 0x60(%rsp), %rdi
callq 0xdff8
jmp 0x99f8
movq %rax, %r14
pushq $0x30
popq %rsi
movq %r13, %rdi
callq 0x3270
jmp 0x99f8
jmp 0x9a02
movq %rax, %r14
pushq $0x30
popq %rsi
movq %r13, %rdi
callq 0x3270
jmp 0x9a2d
movq %rax, %r14
pushq $0x78
popq %rsi
movq %r13, %rdi
jmp 0x998a
jmp 0x99f0
movq %rax, %r14
pushq $0x30
popq %rsi
movq %r15, %rdi
callq 0x3270
jmp 0x9a37
movq %rax, %r14
pushq $0x78
popq %rsi
movq %r15, %rdi
callq 0x3270
jmp 0x9a41
jmp 0x99a9
movq %rax, %r14
jmp 0x9a41
movq %rax, %r14
pushq $0x28
popq %rsi
movq %r15, %rdi
jmp 0x99ca
jmp 0x9a5d
movq %rax, %r14
pushq $0x78
popq %rsi
movq %r12, %rdi
callq 0x3270
jmp 0x9a4b
jmp 0x9a5d
jmp 0x99f5
movq %rax, %r14
leaq 0x18(%rsp), %rdi
jmp 0x99fb
movq %rax, %r14
jmp 0x9a23
jmp 0x99e9
movq %rax, %r14
jmp 0x9a2d
jmp 0x99f0
movq %rax, %r14
jmp 0x9a37
movq %rax, %r14
movq %r12, %rdi
callq 0xdff8
jmp 0x9a05
movq %rax, %r14
leaq 0x68(%rsp), %rdi
callq 0xdb46
leaq 0x8(%rsp), %rdi
callq 0xdb46
leaq 0x28(%rsp), %rdi
callq 0xdff8
leaq 0x30(%rsp), %rdi
callq 0x6ce8
leaq 0x38(%rsp), %rdi
callq 0xdb46
leaq 0x40(%rsp), %rdi
callq 0xdb46
leaq 0x70(%rsp), %rdi
callq 0x6ce8
leaq 0x50(%rsp), %rdi
callq 0xdff8
movq %r14, %rdi
callq 0x3400
movq %rax, %r14
jmp 0x9a4b