// File: /workspace/github_cpp_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
movq %rcx, 0x8(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq 0x8(%rsi), %rsi
imulq (%r12), %rsi
leaq 0x60(%rsp), %rbx
movb $0x0, (%rbx)
leaq 0xf0(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movq %rbx, %rdx
callq 0x1be6
movq (%r12), %rax
movq 0x8(%r12), %rsi
movq %rax, (%rbx)
movq %rsi, 0x8(%rbx)
imulq %rax, %rsi
leaq 0xb8(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0x48(%rsp), %rcx
callq 0x1c4e
movq %r14, 0x30(%rsp)
movq %r12, 0x28(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
xorl %esi, %esi
movq %r15, 0xd0(%rsp)
movq %r15, %rdx
callq 0x1fb0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
cmpq %rdx, %rdi
movq 0x8(%rsp), %r15
je 0x170e
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
addq $0x3f, %rax
movq %rax, 0xe0(%rsp)
leaq 0x60(%rsp), %rbx
leaq 0x48(%rsp), %rbp
movq %r12, 0x38(%rsp)
movq (%rdi), %rax
movq %rax, 0x40(%rsp)
movq 0x8(%rdi), %r14
leaq 0x10(%rdi), %rsi
cmpq %rdx, %rsi
je 0x13c8
subq %rsi, %rdx
callq 0x1120
movq 0x18(%rsp), %rdx
addq $-0x10, %rdx
movq %rdx, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x40(%rsp), %r8
imulq %r8, %rcx
leaq (%rcx,%r14), %rax
addq $0x3f, %rax
addq %r14, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0xf0(%rsp), %rax
movq %rcx, %rdx
andq 0xe0(%rsp), %rdx
xorl %esi, %esi
movabsq $-0x8000000000000000, %rdi # imm = 0x8000000000000000
cmpq %rdi, %rdx
setbe %sil
movl $0x1, %edx
shlq %cl, %rdx
orq %rdx, -0x8(%rax,%rsi,8)
cmpq (%r15), %r8
jne 0x143c
cmpq 0x8(%r15), %r14
je 0x170e
movq 0x40(%rsp), %rcx
leaq -0x1(%rcx), %rax
movq %rax, 0x60(%rsp)
movq %r14, 0x68(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x70(%rsp)
movq %r14, 0x78(%rsp)
movq %rcx, 0x80(%rsp)
leaq -0x1(%r14), %rax
movq %rax, 0x88(%rsp)
movq %rcx, 0x90(%rsp)
movq %r14, 0xe8(%rsp)
leaq 0x1(%r14), %rax
movq %rax, 0x98(%rsp)
movl $0x4, %edx
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rcx
callq 0x1df6
movq 0xa0(%rsp), %r14
movq 0xa8(%rsp), %r13
movq %r12, 0x48(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x28(%rsp), %rcx
movq %rcx, 0x58(%rsp)
movq %r12, 0x60(%rsp)
movq %rax, 0x68(%rsp)
movq %rcx, 0x70(%rsp)
movq %r13, %rax
subq %r14, %rax
movq %rax, %rbx
sarq $0x6, %rbx
testq %rbx, %rbx
jle 0x1594
andq $-0x40, %rax
addq %r14, %rax
movq %rax, 0xd8(%rsp)
incq %rbx
movq %r14, %r15
leaq 0x60(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1b60
testb %al, %al
jne 0x15fe
leaq 0x10(%r15), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1b60
testb %al, %al
jne 0x1601
leaq 0x20(%r15), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1b60
testb %al, %al
jne 0x1601
leaq 0x30(%r15), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1b60
testb %al, %al
jne 0x1601
addq $0x40, %r15
decq %rbx
cmpq $0x1, %rbx
jg 0x150b
movq %r13, %rax
movq 0xd8(%rsp), %rcx
subq %rcx, %rax
movq 0x8(%rsp), %r15
movq 0x38(%rsp), %r12
leaq 0x48(%rsp), %rbp
jmp 0x1597
movq %r14, %rcx
sarq $0x4, %rax
cmpq $0x1, %rax
leaq 0x60(%rsp), %rbx
je 0x15e8
cmpq $0x2, %rax
je 0x15cf
cmpq $0x3, %rax
jne 0x166e
movq %rbx, %rdi
movq %rcx, %r12
movq %rcx, %rsi
callq 0x1b60
testb %al, %al
jne 0x160b
addq $0x10, %r12
movq %r12, %rcx
movq %rbx, %rdi
movq %rcx, %r12
movq %rcx, %rsi
callq 0x1b60
testb %al, %al
jne 0x160b
addq $0x10, %r12
movq %r12, %rcx
movq %rbx, %rdi
movq %rcx, %r12
movq %rcx, %rsi
callq 0x1b60
testb %al, %al
cmoveq %r13, %r12
jmp 0x160b
movq %r15, %r12
movq 0x8(%rsp), %r15
leaq 0x48(%rsp), %rbp
cmpq %r13, %r12
sete %al
leaq 0x10(%r12), %rbx
cmpq %r13, %rbx
sete %cl
orb %al, %cl
jne 0x1654
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1b60
testb %al, %al
jne 0x163b
movups (%rbx), %xmm0
movups %xmm0, (%r12)
addq $0x10, %r12
addq $0x10, %rbx
cmpq %r13, %rbx
jne 0x1620
movq 0xa0(%rsp), %r14
movq 0xa8(%rsp), %r13
cmpq %r13, %r12
leaq 0x60(%rsp), %rbx
je 0x1669
movq %r12, 0xa8(%rsp)
movq %r12, %r13
movq 0x38(%rsp), %r12
cmpq %r13, %r14
je 0x16e3
movq 0x28(%rsp), %rax
movq 0x8(%r14), %rcx
movq 0x8(%rax), %rax
imulq (%r14), %rax
shlq $0x4, %rax
addq 0xb8(%rsp), %rax
shlq $0x4, %rcx
movq 0x40(%rsp), %rdx
movq %rdx, (%rcx,%rax)
movq 0xe8(%rsp), %rdx
movq %rdx, 0x8(%rcx,%rax)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x16c5
movups (%r14), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x16d2
leaq 0x10(%rsp), %rdi
movq %r14, %rdx
callq 0x1fb0
addq $0x10, %r14
cmpq %r13, %r14
jne 0x1673
movq 0xa0(%rsp), %r14
testq %r14, %r14
je 0x16fb
movq 0xb0(%rsp), %rsi
subq %r14, %rsi
movq %r14, %rdi
callq 0x10e0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
cmpq %rdx, %rdi
jne 0x13a6
xorps %xmm0, %xmm0
movq 0x30(%rsp), %r14
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
movups (%r15), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq 0xd0(%rsp), %r15
cmpq (%r15), %rax
jne 0x1753
movq 0x8(%r15), %rax
cmpq %rax, 0x68(%rsp)
jne 0x1753
leaq 0x8(%r14), %rbx
xorl %esi, %esi
jmp 0x17dc
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x176c
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r14)
jmp 0x1779
leaq 0x60(%rsp), %rdx
movq %r14, %rdi
callq 0x20d4
movq 0x28(%rsp), %rax
movq 0x68(%rsp), %rcx
movq 0x8(%rax), %rax
imulq 0x60(%rsp), %rax
shlq $0x4, %rax
addq 0xb8(%rsp), %rax
shlq $0x4, %rcx
movups (%rcx,%rax), %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x60(%rsp), %rax
cmpq (%r15), %rax
jne 0x1753
movq 0x8(%r15), %rax
cmpq %rax, 0x68(%rsp)
jne 0x1753
leaq 0x8(%r14), %rbx
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x17dc
movups (%r15), %xmm0
movups %xmm0, (%rsi)
movq (%rbx), %rax
addq $0x10, %rax
movq %rax, (%rbx)
jmp 0x17ea
movq %r14, %rdi
movq %r15, %rdx
callq 0x1fb0
movq (%rbx), %rax
movq (%r14), %rcx
cmpq %rax, %rcx
setne %dl
addq $-0x10, %rax
cmpq %rcx, %rax
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x1833
addq $0x10, %rcx
movups -0x10(%rcx), %xmm0
movaps %xmm0, 0x60(%rsp)
movups (%rax), %xmm0
movups %xmm0, -0x10(%rcx)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rax)
addq $-0x10, %rax
leaq 0x10(%rcx), %rdx
cmpq %rax, %rcx
movq %rdx, %rcx
jb 0x180b
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x184a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x1867
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x1884
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq %r14, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18a2
jmp 0x18bd
movq %rax, %r14
jmp 0x1916
movq %rax, %r14
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x18e2
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rsi
jmp 0x18da
movq %rax, %r14
jmp 0x18e2
movq %rax, %r14
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x18e2
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x18f9
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x1916
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x1933
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x10e0
movq %r14, %rdi
callq 0x1130