// File: /workspace/github_cpp_makefile_star2_O3/roornelas[P]small-world/./search.hpp
// Function: searchBFS(Graph*, std::pair<int, int>, std::pair<int, int>)
int searchBFS (Graph* g, pair<int, int> start, pair<int, int> end) {
  int i1 = start.first;
  int j1 = start.second;
  int i2 = end.first;
  int j2 = end.second;

  set<Node*> visited;
  queue<Node*> nodes;
  unordered_map<Node*, Node*> parents;
  Node* begin = g->find_node(i1, j1);
  Node* target = g->find_node(i2, j2);
  Node* curr = begin;
  visited.insert(curr);

  for (pair<int, int> f : curr->friends) {
    Node* temp = g->find_node(f.first, f.second);
    if (visited.find(temp) == visited.end()) {
      nodes.push(temp);
      parents.insert(make_pair(temp, curr));
    }
  }

  while (curr != target) {
    curr = nodes.front();
    nodes.pop();
    visited.insert(curr);

    for (pair<int, int> f : curr->friends) {
      Node* temp = g->find_node(f.first, f.second);
      if (visited.find(temp) == visited.end()) {
        nodes.push(temp);
        parents.insert(make_pair(temp, curr));
      }
    }
  }

  int dist = 0;
  curr = target;
  while (curr != begin) {
    dist++;
    curr = parents.at(curr);
  }
  return dist;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
leaq 0x88(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0x410c
leaq 0xe0(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movslq %r15d, %rax
movq 0x8(%r14), %rcx
leaq (%rax,%rax,2), %rax
sarq $0x20, %r15
movq (%rcx,%rax,8), %rax
movq (%rax,%r15,8), %r15
movslq %ebx, %rax
leaq (%rax,%rax,2), %rax
sarq $0x20, %rbx
movq (%rcx,%rax,8), %rax
movq (%rax,%rbx,8), %rbx
leaq 0x8(%rsp), %rsi
movq %r15, (%rsi)
leaq 0x80(%rsp), %rdi
callq 0x4282
movq %r15, 0x28(%rsp)
movq 0x8(%rsp), %rax
movq 0x20(%rax), %r15
leaq 0x10(%rax), %r13
cmpq %r13, %r15
je 0x25ca
leaq 0x30(%rsp), %rbp
leaq 0x18(%rsp), %r12
movslq 0x20(%r15), %rax
movslq 0x24(%r15), %rcx
movq 0x8(%r14), %rdx
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x2562
leaq 0x88(%rsp), %r8
movq %r8, %rcx
movq %rdi, %rdx
movq 0x20(%rdi), %rsi
xorl %edi, %edi
cmpq %rax, %rsi
setb %dil
movq %rdx, %r8
cmovbq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x2524
leaq 0x88(%rsp), %rdi
cmpq %rdi, %r8
je 0x2562
cmpq %rax, %rsi
cmovbq %rcx, %rdx
cmpq 0x20(%rdx), %rax
jae 0x25b1
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
je 0x2580
movq %rax, (%rcx)
addq $0x8, 0x60(%rsp)
jmp 0x258d
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x4394
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
leaq 0xb0(%rsp), %rdi
movq %r12, %rsi
callq 0x45a8
movq %r15, %rdi
callq 0x2190
movq %rax, %r15
cmpq %r13, %rax
jne 0x24f2
movq 0x8(%rsp), %rax
cmpq %rbx, %rax
je 0x273e
leaq 0xb0(%rsp), %r15
leaq 0x18(%rsp), %r12
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
movq (%rax), %rdx
movq %rdx, 0x8(%rsp)
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x2601
addq $0x8, %rax
jmp 0x2633
movq 0x48(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x2160
movq 0x58(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x40(%rsp)
leaq 0x80(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4282
movq 0x8(%rsp), %rax
movq 0x20(%rax), %r13
leaq 0x10(%rax), %rbp
cmpq %rbp, %r13
je 0x2735
movslq 0x20(%r13), %rax
movslq 0x24(%r13), %rcx
movq 0x8(%r14), %rdx
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rax
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x26d0
leaq 0x88(%rsp), %r8
movq %r8, %rcx
movq %rdi, %rdx
movq 0x20(%rdi), %rsi
xorl %edi, %edi
cmpq %rax, %rsi
setb %dil
movq %rdx, %r8
cmovbq %rcx, %r8
movq 0x10(%rdx,%rdi,8), %rdi
testq %rdi, %rdi
jne 0x2692
leaq 0x88(%rsp), %rdi
cmpq %rdi, %r8
je 0x26d0
cmpq %rax, %rsi
cmovbq %rcx, %rdx
cmpq 0x20(%rdx), %rax
jae 0x271c
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
je 0x26ee
movq %rax, (%rcx)
addq $0x8, 0x60(%rsp)
jmp 0x26fd
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4394
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x45a8
movq %r13, %rdi
callq 0x2190
movq %rax, %r13
cmpq %rbp, %rax
jne 0x2660
movq 0x8(%rsp), %rax
cmpq %rbx, %rax
jne 0x25e0
movq %rbx, 0x8(%rsp)
movq 0x28(%rsp), %r10
cmpq %r10, %rbx
je 0x27ae
movq 0xb0(%rsp), %rdi
movq 0xb8(%rsp), %r8
xorl %r14d, %r14d
movq %rbx, %rax
xorl %edx, %edx
divq %r8
movq (%rdi,%rdx,8), %rax
testq %rax, %rax
je 0x27ea
movq %rdx, %rcx
movq (%rax), %r9
cmpq 0x8(%r9), %rbx
je 0x279b
movq (%r9), %r9
testq %r9, %r9
je 0x27ea
movq 0x8(%r9), %rsi
movq %rsi, %rax
xorl %edx, %edx
divq %r8
cmpq %rcx, %rdx
jne 0x27ea
cmpq %rsi, %rbx
jne 0x277d
incl %r14d
movq 0x10(%r9), %rbx
movq %rbx, 0x8(%rsp)
cmpq %r10, %rbx
jne 0x2760
jmp 0x27b1
xorl %r14d, %r14d
leaq 0xb0(%rsp), %rdi
callq 0x319c
leaq 0x30(%rsp), %rdi
callq 0x320c
leaq 0x80(%rsp), %rdi
callq 0x3264
movl %r14d, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2ae0(%rip), %rdi      # 0x52d1
callq 0x21d0
jmp 0x2807
movq %rax, %rbx
jmp 0x2821
jmp 0x2807
jmp 0x2807
jmp 0x2807
jmp 0x2807
jmp 0x2807
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x319c
leaq 0x30(%rsp), %rdi
callq 0x320c
leaq 0x80(%rsp), %rdi
callq 0x3264
movq %rbx, %rdi
callq 0x2240