// File: /workspace/github_cpp_makefile_star2_O2/kdungs[P]codecon/src/maze.cc
// Function: solveBfs(Maze const&, Point const&, Point const&)
auto solveBfs(const Maze& maze, const Point& from, const Point& to)
    -> std::vector<Point> {
  auto visited = std::vector<bool>(maze.rows * maze.cols, false);
  auto prev = std::vector<Point>(maze.rows * maze.cols, {maze.rows, maze.cols});

  auto getAddress =
      [&maze](const Point& p) { return p.row * maze.cols + p.col; };

  auto getNeighbours = [&maze, &visited, &getAddress](const Point& p) {
    auto ns = std::vector<Point>{{p.row - 1, p.col},
                                 {p.row + 1, p.col},
                                 {p.row, p.col - 1},
                                 {p.row, p.col + 1}};
    ns.erase(std::remove_if(std::begin(ns), std::end(ns),
                            [&maze, &visited, &getAddress](const Point& np) {
                              const auto addr = getAddress(np);
                              return (np.row >= maze.rows) ||
                                     (np.col >= maze.cols) || !maze.map[addr] ||
                                     visited[addr];
                            }),
             std::end(ns));
    return ns;
  };

  auto queue = std::vector<Point>{};
  queue.emplace_back(from);

  while (!queue.empty()) {
    auto cur = queue.front();
    queue.erase(std::begin(queue));
    visited[getAddress(cur)] = true;

    if (cur == to) {
      break;
    }

    auto ns = getNeighbours(cur);
    for (const auto& n : ns) {
      prev[getAddress(n)] = cur;
      queue.emplace_back(n);
    }
  }

  auto path = std::vector<Point>{};
  for (auto cur = to; cur != from; cur = prev[getAddress(cur)]) {
    path.emplace_back(cur);
  }
  path.emplace_back(from);
  std::reverse(std::begin(path), std::end(path));
  return path;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rcx, 0x18(%rsp)
movq %rdx, %r15
movq %rsi, %rbp
movq %rdi, %r14
movq 0x8(%rsi), %rsi
imulq (%rbp), %rsi
leaq 0x20(%rsp), %rbx
movb $0x0, (%rbx)
leaq 0xe0(%rsp), %rdi
leaq 0xa0(%rsp), %rcx
movq %rbx, %rdx
callq 0x1946
movq (%rbp), %rax
movq 0x8(%rbp), %rsi
movq %rax, (%rbx)
movq %rsi, 0x8(%rbx)
imulq %rax, %rsi
leaq 0xc8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
callq 0x19aa
movq %r14, 0x78(%rsp)
movq %rbp, 0x10(%rsp)
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq %r15, %rsi
callq 0x1a00
movq %r15, 0xb8(%rsp)
movq %rbp, 0x8(%rsp)
movq 0x80(%rsp), %rdi
movq 0x88(%rsp), %rdx
cmpq %rdx, %rdi
je 0x161b
movq (%rdi), %r15
movq 0x8(%rdi), %rbx
leaq 0x10(%rdi), %rsi
cmpq %rdx, %rsi
je 0x1380
subq %rsi, %rdx
callq 0x1120
movq 0x88(%rsp), %rdx
addq $-0x10, %rdx
movq %rdx, 0x88(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rsi
imulq %r15, %rsi
addq %rbx, %rsi
leaq 0xe0(%rsp), %rdi
callq 0x1a38
orq %rdx, (%rax)
movq 0x18(%rsp), %rax
cmpq (%rax), %r15
jne 0x13c5
movq 0x18(%rsp), %rax
cmpq 0x8(%rax), %rbx
je 0x161b
leaq -0x1(%r15), %rax
movq %rax, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
leaq 0x1(%r15), %rax
movq %rax, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movq %r15, 0x40(%rsp)
leaq -0x1(%rbx), %rax
movq %rax, 0x48(%rsp)
movq %r15, 0x50(%rsp)
movq %rbx, 0xc0(%rsp)
leaq 0x1(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
pushq $0x4
popq %rdx
leaq 0xa0(%rsp), %rcx
callq 0x1bc6
movq 0x60(%rsp), %r14
movq 0x68(%rsp), %r12
movq %rbp, 0xa0(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x10(%rsp), %rcx
movq %rcx, 0xb0(%rsp)
movq %rbp, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq %r12, %rbp
subq %r14, %rbp
movq %rbp, %rbx
sarq $0x6, %rbx
movq %r12, %r13
testq %rbx, %rbx
jle 0x14da
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x18ee
testb %al, %al
jne 0x151f
leaq 0x10(%r14), %r12
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x18ee
testb %al, %al
jne 0x1522
leaq 0x20(%r14), %r12
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x18ee
testb %al, %al
jne 0x1522
leaq 0x30(%r14), %r12
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x18ee
testb %al, %al
jne 0x1522
addq $0x40, %r14
decq %rbx
addq $-0x40, %rbp
movq %r13, %r12
jmp 0x146d
sarq $0x4, %rbp
cmpq $0x1, %rbp
je 0x15f1
cmpq $0x2, %rbp
je 0x15d5
cmpq $0x3, %rbp
jne 0x1611
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x18ee
movq 0x8(%rsp), %rbp
testb %al, %al
jne 0x1609
addq $0x10, %r14
jmp 0x15da
movq %r14, %r12
movq 0x8(%rsp), %rbp
cmpq %r13, %r12
je 0x155d
movq %r12, %rbx
addq $0x10, %r12
cmpq %r13, %r12
je 0x155a
leaq 0xa0(%rsp), %rdi
movq %r12, %rsi
callq 0x18ee
testb %al, %al
jne 0x152f
movups (%r12), %xmm0
movups %xmm0, (%rbx)
addq $0x10, %rbx
jmp 0x152f
movq %rbx, %r12
movq 0x68(%rsp), %rdx
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x1c00
movq 0x60(%rsp), %rbx
movq 0x68(%rsp), %r14
movq 0xc0(%rsp), %r12
cmpq %r14, %rbx
je 0x15c6
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
imulq (%rbx), %rax
shlq $0x4, %rax
addq 0xc8(%rsp), %rax
movq 0x8(%rbx), %rcx
shlq $0x4, %rcx
movq %r15, (%rcx,%rax)
movq %r12, 0x8(%rcx,%rax)
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x1a00
addq $0x10, %rbx
jmp 0x1581
leaq 0x60(%rsp), %rdi
callq 0x1c62
jmp 0x1347
movq 0x8(%rsp), %rbp
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x18ee
testb %al, %al
jne 0x1609
addq $0x10, %r14
jmp 0x15f6
movq 0x8(%rsp), %rbp
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x18ee
testb %al, %al
cmoveq %r12, %r14
movq %r14, %r12
jmp 0x1527
movq 0x8(%rsp), %rbp
jmp 0x155d
xorps %xmm0, %xmm0
movq 0x78(%rsp), %r14
andq $0x0, 0x10(%r14)
movups %xmm0, (%r14)
movq 0x18(%rsp), %rax
movups (%rax), %xmm0
leaq 0x20(%rsp), %rbx
movaps %xmm0, (%rbx)
movq 0xb8(%rsp), %r15
movq 0x20(%rsp), %rax
cmpq (%r15), %rax
jne 0x1659
movq 0x8(%r15), %rax
cmpq %rax, 0x28(%rsp)
je 0x1693
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1a72
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
imulq 0x20(%rsp), %rax
shlq $0x4, %rax
addq 0xc8(%rsp), %rax
movq 0x28(%rsp), %rcx
shlq $0x4, %rcx
movups (%rcx,%rax), %xmm0
movaps %xmm0, 0x20(%rsp)
jmp 0x1644
movq %r14, %rdi
movq %r15, %rsi
callq 0x1a00
movq (%r14), %rdi
movq 0x8(%r14), %rsi
callq 0x2121
leaq 0x80(%rsp), %rdi
callq 0x1c62
leaq 0xc8(%rsp), %rdi
callq 0x1c62
leaq 0xe0(%rsp), %rdi
callq 0x1aaa
movq %r14, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16f5
movq %rax, %rbx
jmp 0x172f
jmp 0x16fa
jmp 0x1708
jmp 0x1708
jmp 0x16f5
movq %rax, %rbx
jmp 0x1715
movq %rax, %rbx
movq 0x78(%rsp), %rdi
jmp 0x1710
jmp 0x1708
jmp 0x1708
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x1c62
leaq 0x80(%rsp), %rdi
callq 0x1c62
leaq 0xc8(%rsp), %rdi
callq 0x1c62
leaq 0xe0(%rsp), %rdi
callq 0x1aaa
movq %rbx, %rdi
callq 0x1130