// File: gchen98[P]macs/algorithm.cpp
// Function: GraphBuilder::pruneEdgesAbove(boost::shared_ptr<Edge>&)
void GraphBuilder::pruneEdgesAbove(EdgePtr & selectedEdge){
    NodePtr & topNode = selectedEdge->getTopNodeRef();
    short int topNodeType = topNode->getType();
    if (topNodeType==Node::COAL){
        EdgePtr edge0 = topNode->getBottomEdgeByIndex(0);
        EdgePtr edge1 = topNode->getBottomEdgeByIndex(1);
        if (topNode->getTopEdgeSize()==0){
            #ifdef DIAG
            if (topNode!=grandMRCA) throw "Top node is NOT grandMRCA!\n";
            #endif
            EdgePtr & otherEdge = edge0==selectedEdge ?
            edge1 : edge0;
            pruneEdgesBelow(otherEdge);
        }else{
            // just some coal node below the grandMRCA. fuse the other two edges.
            EdgePtr edgeAboveNode = topNode->getTopEdgeByIndex(0);
            EdgePtr & edgeBelowNode = edge0==
            selectedEdge?edge1:edge0;
            mergeEdges(edgeAboveNode,edgeBelowNode);
        }

    }else{
        #ifdef DIAG
        if (topNodeType!=Node::MIGRATION
        && topNodeType!=Node::QUERY){
            cerr<<"At edge with "<<selectedEdge->getBottomNodeRef()->getHeight()<<
            " and "<<selectedEdge->getTopNodeRef()->getHeight()<<endl;
            throw "Prune up did not find a migration node";
        }
        #endif
        EdgePtr topEdge = topNode->getTopEdgeByIndex(0);
        pruneEdgesAbove(topEdge);
    }
    topNode->removeEvent();
    deleteEdge(selectedEdge);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1de60
movq %rax, %rdi
callq 0x1e1e0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1ded0
movq %rax, %rdi
callq 0x1e200
movw %ax, -0x1a(%rbp)
movswl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jne 0x15dc3
movq -0x18(%rbp), %rdi
callq 0x1ded0
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
xorl %edx, %edx
callq 0x1e260
movq -0x18(%rbp), %rdi
callq 0x1ded0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
movl $0x1, %edx
callq 0x1e260
jmp 0x15c78
movq -0x18(%rbp), %rdi
callq 0x1ded0
movq %rax, %rdi
callq 0x1e4c0
movw %ax, -0x8a(%rbp)
jmp 0x15c92
movw -0x8a(%rbp), %ax
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0x15d12
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x1e4e0
testb $0x1, %al
jne 0x15cb4
jmp 0x15cc1
leaq -0x40(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x15cce
leaq -0x30(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x15cce
movq -0x88(%rbp), %rdi
movq -0x98(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rsi
callq 0x15b00
jmp 0x15ceb
jmp 0x15d9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x15db8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x15daf
movq -0x18(%rbp), %rdi
callq 0x1ded0
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
xorl %edx, %edx
callq 0x1e390
jmp 0x15d2b
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x1e4e0
testb $0x1, %al
jne 0x15d3e
jmp 0x15d4b
leaq -0x40(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x15d58
leaq -0x30(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x15d58
movq -0x88(%rbp), %rdi
movq -0xa0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdx
leaq -0x68(%rbp), %rsi
callq 0x2a2d0
jmp 0x15d79
leaq -0x68(%rbp), %rdi
callq 0x1e090
jmp 0x15d9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x1e090
jmp 0x15daf
leaq -0x40(%rbp), %rdi
callq 0x1e090
leaq -0x30(%rbp), %rdi
callq 0x1e090
jmp 0x15e18
leaq -0x40(%rbp), %rdi
callq 0x1e090
leaq -0x30(%rbp), %rdi
callq 0x1e090
jmp 0x15e42
movq -0x18(%rbp), %rdi
callq 0x1ded0
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
xorl %edx, %edx
callq 0x1e390
movq -0x88(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x15bf0
jmp 0x15df6
leaq -0x80(%rbp), %rdi
callq 0x1e090
jmp 0x15e18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x1e090
jmp 0x15e42
movq -0x18(%rbp), %rdi
callq 0x1ded0
movq %rax, %rdi
callq 0x1e480
movq -0x88(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2a370
addq $0xb0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x44e0
nopl (%rax,%rax)