// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x38(%rsp), %r12
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
andq $0x0, 0x20(%r12)
leaq 0x98(%rsp), %rdi
callq 0x2aba
leaq 0x90(%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(%rbx), %rcx
imulq $0x18, %rax, %rax
sarq $0x20, %r15
movq (%rcx,%rax), %rax
movq (%rax,%r15,8), %rdx
movslq %r14d, %rax
imulq $0x18, %rax, %rax
sarq $0x20, %r14
movq (%rcx,%rax), %rax
movq (%rax,%r14,8), %rax
movq %rax, 0x28(%rsp)
movq %rsp, %rsi
movq %rdx, 0x20(%rsp)
movq %rdx, (%rsi)
leaq 0x30(%rsp), %rdi
callq 0x3fde
movq (%rsp), %r13
movq 0x20(%r13), %r14
addq $0x10, %r13
leaq 0x30(%rsp), %r15
leaq 0x8(%rsp), %rbp
cmpq %r13, %r14
je 0x24b4
movslq 0x20(%r14), %rax
movslq 0x24(%r14), %rcx
movq 0x8(%rbx), %rdx
imulq $0x18, %rax, %rax
movq (%rdx,%rax), %rax
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4138
cmpq %r12, %rax
jne 0x24a7
leaq 0x98(%rsp), %rdi
movq %rbp, %rsi
callq 0x418e
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x43c2
movq %r14, %rdi
callq 0x2190
movq %rax, %r14
jmp 0x2443
leaq 0x30(%rsp), %r15
leaq 0x8(%rsp), %r13
movq 0x28(%rsp), %rax
cmpq %rax, (%rsp)
je 0x2571
movq 0xa8(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rsp)
leaq 0x98(%rsp), %rdi
callq 0x472c
movq %r15, %rdi
movq %rsp, %rsi
callq 0x3fde
movq (%rsp), %r14
movq 0x20(%r14), %rbp
addq $0x10, %r14
cmpq %r14, %rbp
je 0x24be
movslq 0x20(%rbp), %rax
movslq 0x24(%rbp), %rcx
movq 0x8(%rbx), %rdx
imulq $0x18, %rax, %rax
movq (%rdx,%rax), %rax
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x4138
cmpq %r12, %rax
jne 0x2564
leaq 0x98(%rsp), %rdi
movq %r13, %rsi
callq 0x418e
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq %rax, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x43c2
movq %rbp, %rdi
callq 0x2190
movq %rax, %rbp
jmp 0x2500
xorl %ebx, %ebx
leaq 0x60(%rsp), %r14
movq %rsp, %r15
movq 0x20(%rsp), %r12
movq %rax, (%rsp)
cmpq %r12, %rax
je 0x259b
movq %r14, %rdi
movq %r15, %rsi
callq 0x4782
incl %ebx
movq (%rax), %rax
jmp 0x2580
leaq 0x60(%rsp), %rdi
callq 0x2e4c
leaq 0x98(%rsp), %rdi
callq 0x2ef4
leaq 0x30(%rsp), %rdi
callq 0x2f4c
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25e5
movq %rax, %rbx
jmp 0x25ff
jmp 0x25e5
jmp 0x25e5
jmp 0x25e5
jmp 0x25e5
jmp 0x25e5
jmp 0x25e5
jmp 0x25e5
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2e4c
leaq 0x98(%rsp), %rdi
callq 0x2ef4
leaq 0x30(%rsp), %rdi
callq 0x2f4c
movq %rbx, %rdi
callq 0x2240