// File: micahcc[P]polygon_skeleton/voronoi.cpp
// Function: Voronoi::Implementation::getNode(Vector const*, Vector const*)
Voronoi::Node::Ptr Voronoi::Implementation::getNode(
        const Point* ptA, const Point* ptB)
{
    if(ptA > ptB) std::swap(ptA, ptB);
    auto result = m_nodes.emplace(std::make_tuple(ptA, ptB, nullptr), nullptr);

    // if node exists, just return it
    if(!result.second) {
        assert(result.first->second != nullptr);
        return result.first->second;
    }

    // need to construct a new node and add its parents and location
    auto new_node = std::make_shared<Node>();
    result.first->second = new_node;

    // Add parents
    new_node->parents.insert((ptA - m_points->data()) / sizeof(Point));
    new_node->parents.insert((ptB - m_points->data()) / sizeof(Point));

    // Add position
    new_node->x = (ptA->x + ptB->x)*0.5;
    new_node->y = (ptA->y + ptB->y)*0.5;

    return new_node;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0xc8(%rbp)
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0xc3ae
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x11f20
movq -0xb8(%rbp), %rax
addq $0x90, %rax
movq %rax, -0xd8(%rbp)
movq $0x0, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
leaq -0x18(%rbp), %rsi
leaq -0x20(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x11fb0
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq $0x0, -0x58(%rbp)
leaq -0x58(%rbp), %rdx
callq 0x11f60
movb %dl, -0x60(%rbp)
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x30(%rbp)
movb -0x60(%rbp), %al
movb %al, -0x28(%rbp)
testb $0x1, -0x28(%rbp)
jne 0xc481
leaq -0x30(%rbp), %rdi
callq 0x11de0
movq %rax, %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x11400
testb $0x1, %al
jne 0xc43f
jmp 0xc441
jmp 0xc460
leaq 0x17573(%rip), %rdi     # 0x239bb
leaq 0x16e7f(%rip), %rsi     # 0x232ce
movl $0x3f5, %edx            # imm = 0x3F5
leaq 0x175e1(%rip), %rcx     # 0x23a3c
callq 0x3170
leaq -0x30(%rbp), %rdi
callq 0x11de0
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
addq $0x18, %rsi
callq 0x114f0
jmp 0xc689
movq -0xc8(%rbp), %rdi
movb $0x0, -0x69(%rbp)
callq 0x11e10
leaq -0x30(%rbp), %rdi
callq 0x11de0
movq -0xc8(%rbp), %rsi
movq %rax, %rdi
addq $0x18, %rdi
callq 0x11e80
movq -0xc8(%rbp), %rdi
callq 0x11430
movq %rax, %rcx
movq -0xb8(%rbp), %rax
addq $0x8, %rcx
movq %rcx, -0xf8(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, -0xf0(%rbp)
movq 0xe0(%rax), %rdi
callq 0x11f00
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movq -0xf0(%rbp), %rax
subq %rcx, %rax
sarq $0x3, %rax
shrq $0x3, %rax
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rsi
callq 0x11eb0
movb %dl, -0xe1(%rbp)
movq %rax, -0xe0(%rbp)
jmp 0xc51d
movq -0xc8(%rbp), %rdi
movb -0xe1(%rbp), %al
movq -0xe0(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movb %al, -0x90(%rbp)
callq 0x11430
movq %rax, %rcx
movq -0xb8(%rbp), %rax
addq $0x8, %rcx
movq %rcx, -0x118(%rbp)
movq -0x20(%rbp), %rcx
movq %rcx, -0x110(%rbp)
movq 0xe0(%rax), %rdi
callq 0x11f00
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movq -0x110(%rbp), %rax
subq %rcx, %rax
sarq $0x3, %rax
shrq $0x3, %rax
movq %rax, -0xa0(%rbp)
leaq -0xa0(%rbp), %rsi
callq 0x11eb0
movb %dl, -0x101(%rbp)
movq %rax, -0x100(%rbp)
jmp 0xc5ad
movq -0xc8(%rbp), %rdi
movb -0x101(%rbp), %al
movq -0x100(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movb %al, -0xa8(%rbp)
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
movq -0x20(%rbp), %rax
addss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x16c66(%rip), %xmm1    # 0x23250
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x120(%rbp)
callq 0x11430
movss -0x120(%rbp), %xmm0
movq -0xc8(%rbp), %rdi
movss %xmm0, (%rax)
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x20(%rbp), %rax
addss 0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x16c20(%rip), %xmm1    # 0x23250
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x11c(%rbp)
callq 0x11430
movss -0x11c(%rbp), %xmm0
movss %xmm0, 0x4(%rax)
movb $0x1, -0x69(%rbp)
testb $0x1, -0x69(%rbp)
jne 0xc687
jmp 0xc67b
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
callq 0x8a20
jmp 0xc699
movq -0xc8(%rbp), %rdi
callq 0x8a20
jmp 0xc689
movq -0xc0(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)