// File: guitld[P]Graph-Algorithms/source/Graph.cpp
// Function: Graph::BFS(int, int)
int Graph::BFS(int u, int v){
     if (adj_lists.find(u) == adj_lists.end() || adj_lists.find(v) == adj_lists.end()){
          cout << "Vertex not found" << endl;
          return 0;
     }

     // Defining structures for the algorithm
     vector <int> visited;
     queue <int> queue;
     queue.push(u);
     unordered_map <int, int> parentNode;
     
     while (!queue.empty()){
          // Popping first item of the queue
          int curr_v = queue.front();
          queue.pop();
          // Looping through its neighbors
          for (auto const &neighbor : adj_lists[curr_v]){
               // If the neighbor vertex is not marked as visited, the vertex is added to the queue and marked as visited
               // The father vertex is setted in the parent hash map
               if (find(visited.begin(), visited.end(), neighbor.first) == visited.end()){
                    parentNode[neighbor.first] = curr_v;
                    visited.push_back(neighbor.first);
                    queue.push(neighbor.first);
               }
               // If the vertex was found, loops through the parent hash map to print the BFS path
               if (neighbor.first == v){
                    cout << v << "<-";
                    parentNode[get<0>(neighbor)] = curr_v;
                    int count = 0;
                    while (v != u){
                         v = parentNode[v];
                         cout << v;
                         if (v != u)
                              cout << "<-";
                         count++;
                    }
                    cout << endl;
                    return count;
               }
          }
     }
     cout << "No path found" << endl;
     return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x148(%rbp)
leaq -0x14(%rbp), %rsi
callq 0x6060
movq -0x148(%rbp), %rdi
movq %rax, -0x20(%rbp)
callq 0x59a0
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x6030
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x139(%rbp)
jne 0x3f20
movq -0x148(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x6060
movq -0x148(%rbp), %rdi
movq %rax, -0x30(%rbp)
callq 0x59a0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x6030
movb %al, -0x139(%rbp)
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0x3f2c
jmp 0x3f5a
movq 0x19095(%rip), %rdi     # 0x1cfc8
leaq 0xf0eb(%rip), %rsi      # 0x13025
callq 0x2190
movq %rax, %rdi
movq 0x1906f(%rip), %rsi     # 0x1cfb8
callq 0x21d0
movl $0x0, -0x4(%rbp)
jmp 0x4351
leaq -0x50(%rbp), %rdi
callq 0x5ca0
leaq -0xa0(%rbp), %rdi
callq 0x6090
jmp 0x3f71
leaq -0xa0(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x60c0
jmp 0x3f83
leaq -0xe8(%rbp), %rdi
callq 0x5bf0
leaq -0xa0(%rbp), %rdi
callq 0x60f0
movb %al, -0x149(%rbp)
jmp 0x3fa3
movb -0x149(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3fb4
jmp 0x42d5
leaq -0xa0(%rbp), %rdi
callq 0x6110
movq %rax, -0x158(%rbp)
jmp 0x3fc9
movq -0x158(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xec(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x6130
jmp 0x3fe6
movq -0x148(%rbp), %rdi
leaq -0xec(%rbp), %rsi
callq 0x5890
movq %rax, -0x160(%rbp)
jmp 0x4002
movq -0x160(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x5a70
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdi
callq 0x5aa0
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x5ad0
testb $0x1, %al
jne 0x4052
jmp 0x42d0
leaq -0x100(%rbp), %rdi
callq 0x5b00
movq %rax, -0x110(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x61e0
movq -0x170(%rbp), %rdi
movq %rax, -0x120(%rbp)
callq 0x6210
movq %rax, -0x128(%rbp)
movq -0x110(%rbp), %rdx
movq -0x120(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x6190
movq %rax, -0x168(%rbp)
jmp 0x40b2
movq -0x168(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x6210
movq %rax, -0x130(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x6150
testb $0x1, %al
jne 0x40ec
jmp 0x419d
movl -0xec(%rbp), %eax
movl %eax, -0x17c(%rbp)
movq -0x110(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x5c40
movq %rax, -0x178(%rbp)
jmp 0x4114
movq -0x178(%rbp), %rax
movl -0x17c(%rbp), %ecx
movl %ecx, (%rax)
movq -0x110(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x5ea0
jmp 0x4135
movq -0x110(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x60c0
jmp 0x414a
jmp 0x419d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x4346
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x433a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x6010
jmp 0x433a
movq -0x110(%rbp), %rax
movl (%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x42bd
movl -0x18(%rbp), %esi
movq 0x18e0f(%rip), %rdi     # 0x1cfc8
callq 0x22b0
movq %rax, -0x188(%rbp)
jmp 0x41c7
movq -0x188(%rbp), %rdi
leaq 0xee61(%rip), %rsi      # 0x13036
callq 0x2190
jmp 0x41dc
movl -0xec(%rbp), %eax
movl %eax, -0x194(%rbp)
movq -0x110(%rbp), %rdi
callq 0x6240
movq %rax, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x5c40
movq %rax, -0x190(%rbp)
jmp 0x420c
movq -0x190(%rbp), %rax
movl -0x194(%rbp), %ecx
movl %ecx, (%rax)
movl $0x0, -0x134(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x4293
leaq -0xe8(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x5c40
movq %rax, -0x1a0(%rbp)
jmp 0x4246
movq -0x1a0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %esi
movq 0x18d6c(%rip), %rdi     # 0x1cfc8
callq 0x22b0
jmp 0x4263
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x4282
movq 0x18d56(%rip), %rdi     # 0x1cfc8
leaq 0xedbd(%rip), %rsi      # 0x13036
callq 0x2190
jmp 0x4280
jmp 0x4282
movl -0x134(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x134(%rbp)
jmp 0x4225
movq 0x18d2e(%rip), %rdi     # 0x1cfc8
movq 0x18d17(%rip), %rsi     # 0x1cfb8
callq 0x21d0
jmp 0x42a8
movl -0x134(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x138(%rbp)
jmp 0x4317
jmp 0x42bf
leaq -0x100(%rbp), %rdi
callq 0x5b20
jmp 0x4036
jmp 0x3f8f
movq 0x18cec(%rip), %rdi     # 0x1cfc8
leaq 0xed56(%rip), %rsi      # 0x13039
callq 0x2190
movq %rax, -0x1a8(%rbp)
jmp 0x42f1
movq -0x1a8(%rbp), %rdi
movq 0x18cb9(%rip), %rsi     # 0x1cfb8
callq 0x21d0
jmp 0x4306
movl $0x0, -0x4(%rbp)
movl $0x1, -0x138(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x6010
leaq -0xa0(%rbp), %rdi
callq 0x6260
leaq -0x50(%rbp), %rdi
callq 0x5f90
jmp 0x4351
leaq -0xa0(%rbp), %rdi
callq 0x6260
leaq -0x50(%rbp), %rdi
callq 0x5f90
jmp 0x435d
movl -0x4(%rbp), %eax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0xa8(%rbp), %rdi
callq 0x22c0
nopl (%rax)