// File: gchen98[P]macs/datastructures.cpp
// Function: GraphBuilder::insertNodeInRunningEdge(boost::intrusive_ptr<Node>&, boost::shared_ptr<Edge>&)
void GraphBuilder::insertNodeInRunningEdge(NodePtr & newNode,EdgePtr & tempEdge){

    NodePtr & bottomNode = tempEdge->getBottomNodeRef();
    NodePtr & topNode = tempEdge->getTopNodeRef();
    #ifdef DIAG
    if (newNode->getHeight()<=bottomNode->getHeight() ||
    newNode->getHeight() >= topNode->getHeight()){
           cerr<<"Edge has heights "<<bottomNode->getHeight()<<
        " and "<<topNode->getHeight()<<endl;
        cerr<<"New node has height "<<newNode->getHeight()<<endl;
        throw "Node to insert does not fit within coal edge ";
    }
    #endif

    EdgePtr tempEdgeCopy = tempEdge;

    tempEdge = EdgePtr(new Edge(topNode,newNode));
    tempEdge->iGraphIteration = iGraphIteration;
    newNode->addNewEdge(Node::TOP_EDGE,tempEdge);
    tempEdge->getTopNodeRef()->replaceOldWithNewEdge(
    Node::BOTTOM_EDGE,tempEdgeCopy,tempEdge);

    EdgePtr newBottomEdge = EdgePtr(new Edge(newNode,bottomNode));
    newBottomEdge->iGraphIteration = iGraphIteration;
    newNode->addNewEdge(Node::BOTTOM_EDGE,newBottomEdge);
    addEdge(newBottomEdge);
    bottomNode->replaceOldWithNewEdge(Node::TOP_EDGE,tempEdgeCopy,
    newBottomEdge);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1de60
movq %rax, %rdi
callq 0x1deb0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1de60
movq %rax, %rdi
callq 0x1e1e0
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x1df40
movl $0x30, %edi
callq 0x42c0
movq %rax, -0x70(%rbp)
jmp 0x29d56
movq -0x70(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x27460
jmp 0x29d69
movq -0x70(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x1e5c0
jmp 0x29d78
movq -0x18(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movq %rsi, -0x90(%rbp)
callq 0x1e630
movq -0x90(%rbp), %rdi
callq 0x1e090
movq -0x78(%rbp), %rax
movl 0xd0(%rax), %eax
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1de60
movl -0x84(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rdi
callq 0x1ded0
movq %rax, %rdi
movq -0x18(%rbp), %rdx
xorl %esi, %esi
callq 0x276f0
movq -0x18(%rbp), %rdi
callq 0x1de60
movq %rax, %rdi
callq 0x1e1e0
movq %rax, -0x80(%rbp)
jmp 0x29de8
movq -0x80(%rbp), %rdi
callq 0x1ded0
movq %rax, %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %esi
leaq -0x38(%rbp), %rdx
callq 0x277b0
jmp 0x29e08
movl $0x30, %edi
callq 0x42c0
movq %rax, -0x98(%rbp)
jmp 0x29e1b
movq -0x98(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x27460
jmp 0x29e31
movq -0x98(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x1e5c0
jmp 0x29e43
movq -0x78(%rbp), %rax
movl 0xd0(%rax), %eax
movl %eax, -0xa4(%rbp)
leaq -0x68(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x1de60
movl -0xa4(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rdi
callq 0x1ded0
movq -0xa0(%rbp), %rdx
movq %rax, %rdi
movl $0x1, %esi
callq 0x276f0
movq -0x78(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x29f50
jmp 0x29e9b
movq -0x20(%rbp), %rdi
callq 0x1ded0
movq %rax, %rdi
xorl %esi, %esi
leaq -0x38(%rbp), %rdx
leaq -0x68(%rbp), %rcx
callq 0x277b0
jmp 0x29eb8
leaq -0x68(%rbp), %rdi
callq 0x1e090
leaq -0x38(%rbp), %rdi
callq 0x1e090
addq $0xb0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x29f31
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x30, %esi
callq 0x42d0
jmp 0x29f31
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x30, %esi
callq 0x42d0
jmp 0x29f31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x1e090
leaq -0x38(%rbp), %rdi
callq 0x1e090
movq -0x50(%rbp), %rdi
callq 0x44e0
nopw %cs:(%rax,%rax)