// File: gchen98[P]macs/datastructures.cpp
// Function: Node::replaceOldWithNewEdge(Node::EdgeLocation, boost::shared_ptr<Edge>&, boost::shared_ptr<Edge>&)
void Node::replaceOldWithNewEdge(EdgeLocation iLocation,
EdgePtr & oldEdge,EdgePtr & newEdge){
    bool found = false;
    unsigned int i=0;
    if (iLocation==Node::TOP_EDGE){
        while(!found && i<this->topEdgeSize){
            WeakEdgePtr & topEdge = i?topEdge2:topEdge1;
            if (topEdge.lock()==oldEdge){
                topEdge=WeakEdgePtr(newEdge);
                found = true;
            }else{
                ++i;
            }
        }
        #ifdef DIAG
        if (!found) throw "Can't find top edge in replace edge";
        #endif
    }else if (iLocation==Node::BOTTOM_EDGE){
        while(!found && i<this->bottomEdgeSize){
            WeakEdgePtr & bottomEdge = i?bottomEdge2:bottomEdge1;
            if (bottomEdge.lock()==oldEdge){
                bottomEdge = WeakEdgePtr(newEdge);
                found = true;
            }else{
                ++i;
            }
        }
        if (!found) throw "Can't find bottom edge in replace edge";
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movb $0x0, -0x21(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x278ca
jmp 0x277ec
xorl %eax, %eax
testb $0x1, -0x21(%rbp)
movb %al, -0x91(%rbp)
jne 0x27813
movq -0x90(%rbp), %rcx
movl -0x28(%rbp), %eax
movzwl 0x68(%rcx), %ecx
cmpl %ecx, %eax
setb %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0x27822
jmp 0x278c5
cmpl $0x0, -0x28(%rbp)
je 0x2783c
movq -0x90(%rbp), %rax
addq $0x30, %rax
movq %rax, -0xa0(%rbp)
jmp 0x2784e
movq -0x90(%rbp), %rax
addq $0x20, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1fe60
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x1e4e0
movb %al, -0xa1(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x1e090
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x2788e
jmp 0x278b7
movq -0x20(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x2b810
movq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2b850
leaq -0x50(%rbp), %rdi
callq 0x2b8a0
movb $0x1, -0x21(%rbp)
jmp 0x278c0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x277ec
jmp 0x279e0
cmpl $0x1, -0xc(%rbp)
jne 0x279de
jmp 0x278d6
xorl %eax, %eax
testb $0x1, -0x21(%rbp)
movb %al, -0xa2(%rbp)
jne 0x278fd
movq -0x90(%rbp), %rcx
movl -0x28(%rbp), %eax
movzwl 0x6a(%rcx), %ecx
cmpl %ecx, %eax
setb %al
movb %al, -0xa2(%rbp)
movb -0xa2(%rbp), %al
testb $0x1, %al
jne 0x2790c
jmp 0x279af
cmpl $0x0, -0x28(%rbp)
je 0x27926
movq -0x90(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xb0(%rbp)
jmp 0x27938
movq -0x90(%rbp), %rax
addq $0x40, %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x1fe60
movq -0x18(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x1e4e0
movb %al, -0xb1(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x1e090
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x27978
jmp 0x279a1
movq -0x20(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x2b810
movq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2b850
leaq -0x80(%rbp), %rdi
callq 0x2b8a0
movb $0x1, -0x21(%rbp)
jmp 0x279aa
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x278d6
testb $0x1, -0x21(%rbp)
jne 0x279dc
movl $0x8, %edi
callq 0x4130
movq %rax, %rdi
leaq 0xcd29(%rip), %rax      # 0x346f2
movq %rax, (%rdi)
movq 0x215e5(%rip), %rsi     # 0x48fb8
xorl %eax, %eax
movl %eax, %edx
callq 0x44c0
jmp 0x279de
jmp 0x279e0
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)