// File: /workspace/github_cpp_makefile_star2_O1/razimantv[P]DancingLinks/spangram/spangram.cpp
// Function: find_placements(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, int, int, TrieNode const&, int, int, std::vector<std::vector<bool, std::allocator<bool>>, std::allocator<std::vector<bool, std::allocator<bool>>>>&, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>>>&)
void find_placements(const Grid& grid, int m, int n, const TrieNode& node,
                     int i, int j, std::vector<std::vector<bool>>& visited,
                     Path& path, std::vector<Placement>& placements) {
  // Check if the current cell is valid and can extend the current word
  if (i < 0 || i >= m || j < 0 || j >= n || visited[i][j] ||
      !node.children[grid[i][j] - 'a'])
    return;

  // Process current cell
  visited[i][j] = true;
  path.push_back({i, j});
  const TrieNode* next = node.children[grid[i][j] - 'a'];
  if (next->end) {
    // If we are at a word end, we can have a placement here
    // Find the corresponding word and placement
    std::string word;
    for (const auto& [x, y] : path) word += grid[x][y];
    placements.push_back({word, path});
  }
  // Recurse to all neighbours
  for (const auto& [dx, dy] : neighbours)
    // If the step is diagonal, ensure it won't cause self-intersection
    if (abs(dx) != abs(dy) or !contains_pair(path, {i + dx, j}, {i, j + dy}))
      find_placements(grid, m, n, *next, i + dx, j + dy, visited, path,
                      placements);

  // Undo to backtrack
  path.pop_back();
  visited[i][j] = false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
testl %r8d, %r8d
js 0x286d
movl %r9d, %ebx
cmpl %edx, %r9d
jge 0x286d
movl %r8d, %r14d
cmpl %esi, %r8d
jge 0x286d
testl %ebx, %ebx
js 0x286d
movq %rcx, %r13
movq 0xc0(%rsp), %rax
movl %r14d, %r15d
movq (%rax), %rax
leaq (%r15,%r15,4), %r8
movq (%rax,%r8,8), %rax
movl $0x1, %r9d
movl %ebx, %ecx
shlq %cl, %r9
movl %ebx, %r10d
shrl $0x6, %r10d
movq (%rax,%r10,8), %rcx
btq %rbx, %rcx
jb 0x286d
movq %rdi, %r12
movl %ebx, %ebp
movq (%rdi), %rdi
shlq $0x5, %r15
movq (%rdi,%r15), %rdi
movsbq (%rdi,%rbp), %rdi
cmpq $0x0, -0x308(%r13,%rdi,8)
je 0x286d
movq %r8, 0x40(%rsp)
movl %esi, 0x8(%rsp)
movl %edx, 0xc(%rsp)
movq 0xc8(%rsp), %rdi
movq %r9, 0x38(%rsp)
orq %r9, %rcx
movq %r10, 0x30(%rsp)
movq %rcx, (%rax,%r10,8)
leaq 0x50(%rsp), %rsi
movl %r14d, (%rsi)
movl %ebx, 0x4(%rsi)
callq 0x3b0c
movq (%r12), %rax
movq (%rax,%r15), %rax
movsbq (%rax,%rbp), %rax
movq -0x308(%r13,%rax,8), %rax
movq %rax, 0x48(%rsp)
cmpb $0x1, 0xd0(%rax)
jne 0x278f
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0xc8(%rsp), %rax
movq (%rax), %r15
movq 0x8(%rax), %rbp
cmpq %rbp, %r15
je 0x2715
leaq 0x10(%rsp), %r13
movslq (%r15), %rax
movq (%r12), %rcx
shlq $0x5, %rax
movslq 0x4(%r15), %rdx
movq (%rcx,%rax), %rax
movsbl (%rax,%rdx), %esi
movq %r13, %rdi
callq 0x2130
addq $0x8, %r15
cmpq %rbp, %r15
jne 0x26ed
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0xc8(%rsp), %rdx
callq 0x34fc
leaq 0x50(%rsp), %rsi
movq 0xd0(%rsp), %rdi
callq 0x3c66
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2758
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2773
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x278f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x69f2(%rip), %r15      # 0x9188
movq 0x69f3(%rip), %rbp      # 0x9190
cmpq %rbp, %r15
je 0x283b
movl (%r15), %r13d
movl 0x4(%r15), %eax
movl %r13d, %ecx
negl %ecx
cmovsl %r13d, %ecx
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
cmpl %edx, %ecx
jne 0x27f3
leal (%r14,%r13), %ecx
movl %ecx, 0x50(%rsp)
movl %ebx, 0x54(%rsp)
addl %ebx, %eax
movl %r14d, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq 0xc8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x252c
testb %al, %al
jne 0x2832
addl %r14d, %r13d
movl 0x4(%r15), %r9d
addl %ebx, %r9d
subq $0x8, %rsp
movq %r12, %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movq 0x50(%rsp), %rcx
movl %r13d, %r8d
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
callq 0x25cc
addq $0x20, %rsp
addq $0x8, %r15
jmp 0x279d
movq 0xc8(%rsp), %rax
addq $-0x8, 0x8(%rax)
movq 0xc0(%rsp), %rax
movq (%rax), %rax
movq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x38(%rsp), %rcx
notq %rcx
movq 0x30(%rsp), %rdx
andq %rcx, (%rax,%rdx,8)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x3550
jmp 0x2893
jmp 0x2890
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x28af
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq %rbx, %rdi
callq 0x2280