// File: 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
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x28(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3150
leaq -0xa8(%rbp), %rdi
callq 0x3170
jmp 0x2456
leaq -0xf0(%rbp), %rdi
callq 0x31a0
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x31c0
movq %rax, -0x1e8(%rbp)
jmp 0x247a
movq -0x1e8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0x31c0
movq %rax, -0x1f0(%rbp)
jmp 0x24a0
movq -0x1f0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x3200
movb %dl, -0x1f9(%rbp)
movq %rax, -0x1f8(%rbp)
jmp 0x24db
movb -0x1f9(%rbp), %al
movq -0x1f8(%rbp), %rcx
movq %rcx, -0x118(%rbp)
movb %al, -0x110(%rbp)
movq -0x108(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rdi
callq 0x3250
movq %rax, -0x128(%rbp)
movq -0x120(%rbp), %rdi
callq 0x3280
movq %rax, -0x130(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x32b0
testb $0x1, %al
jne 0x2549
jmp 0x26c9
leaq -0x128(%rbp), %rdi
callq 0x32e0
movq (%rax), %rax
movq %rax, -0x138(%rbp)
movq -0x18(%rbp), %rdi
movl -0x138(%rbp), %esi
movl -0x134(%rbp), %edx
callq 0x31c0
movq %rax, -0x208(%rbp)
jmp 0x257d
movq -0x208(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x3330
movq %rax, -0x210(%rbp)
jmp 0x25a4
movq -0x210(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3370
movq %rax, -0x150(%rbp)
leaq -0x148(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x3300
testb $0x1, %al
jne 0x25de
jmp 0x26b6
leaq -0xa8(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x33a0
jmp 0x25f3
leaq -0x140(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x3410
movq %rdx, -0x220(%rbp)
movq %rax, -0x218(%rbp)
jmp 0x2616
movq -0x220(%rbp), %rax
movq -0x218(%rbp), %rcx
movq %rcx, -0x160(%rbp)
movq %rax, -0x158(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x33d0
movb %dl, -0x229(%rbp)
movq %rax, -0x228(%rbp)
jmp 0x2654
movb -0x229(%rbp), %al
movq -0x228(%rbp), %rcx
movq %rcx, -0x170(%rbp)
movb %al, -0x168(%rbp)
jmp 0x26b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x297e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x34e0
leaq -0xa8(%rbp), %rdi
callq 0x3500
jmp 0x297e
jmp 0x26b8
leaq -0x128(%rbp), %rdi
callq 0x3440
jmp 0x252d
jmp 0x26cb
movq -0x108(%rbp), %rax
cmpq -0x100(%rbp), %rax
je 0x28dd
leaq -0xa8(%rbp), %rdi
callq 0x3470
movq %rax, -0x238(%rbp)
jmp 0x26f4
movq -0x238(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x108(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3490
jmp 0x2713
leaq -0x58(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x3200
movb %dl, -0x241(%rbp)
movq %rax, -0x240(%rbp)
jmp 0x2732
movb -0x241(%rbp), %al
movq -0x240(%rbp), %rcx
movq %rcx, -0x180(%rbp)
movb %al, -0x178(%rbp)
movq -0x108(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rdi
callq 0x3250
movq %rax, -0x190(%rbp)
movq -0x188(%rbp), %rdi
callq 0x3280
movq %rax, -0x198(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x32b0
testb $0x1, %al
jne 0x27a0
jmp 0x28d8
leaq -0x190(%rbp), %rdi
callq 0x32e0
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1a0(%rbp), %esi
movl -0x19c(%rbp), %edx
callq 0x31c0
movq %rax, -0x250(%rbp)
jmp 0x27d4
movq -0x250(%rbp), %rax
movq %rax, -0x1a8(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x3330
movq %rax, -0x258(%rbp)
jmp 0x27fb
movq -0x258(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x3370
movq %rax, -0x1b8(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x3300
testb $0x1, %al
jne 0x2835
jmp 0x28c5
leaq -0xa8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x33a0
jmp 0x284a
leaq -0x1a8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x3410
movq %rdx, -0x268(%rbp)
movq %rax, -0x260(%rbp)
jmp 0x286d
movq -0x268(%rbp), %rax
movq -0x260(%rbp), %rcx
movq %rcx, -0x1c8(%rbp)
movq %rax, -0x1c0(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x33d0
movb %dl, -0x271(%rbp)
movq %rax, -0x270(%rbp)
jmp 0x28ab
movb -0x271(%rbp), %al
movq -0x270(%rbp), %rcx
movq %rcx, -0x1d8(%rbp)
movb %al, -0x1d0(%rbp)
jmp 0x28c7
leaq -0x190(%rbp), %rdi
callq 0x3440
jmp 0x2784
jmp 0x26cb
movl $0x0, -0x1dc(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
cmpq -0xf8(%rbp), %rax
je 0x2942
movl -0x1dc(%rbp), %eax
incl %eax
movl %eax, -0x1dc(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x34b0
movq %rax, -0x280(%rbp)
jmp 0x292f
movq -0x280(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x108(%rbp)
jmp 0x28f5
movl -0x1dc(%rbp), %eax
movl %eax, -0x284(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x34e0
leaq -0xa8(%rbp), %rdi
callq 0x3500
leaq -0x58(%rbp), %rdi
callq 0x3520
movl -0x284(%rbp), %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x3520
movq -0xb0(%rbp), %rdi
callq 0x22a0
nopw %cs:(%rax,%rax)