// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdi, (%rsp)
testl %r8d, %r8d
js 0x2876
movl %r9d, %ebx
cmpl %edx, %r9d
jge 0x2876
movl %r8d, %ebp
cmpl %esi, %r8d
jge 0x2876
testl %ebx, %ebx
js 0x2876
movq %rcx, %r13
movq 0xc0(%rsp), %rax
movl %ebp, %r14d
movq (%rax), %rax
leaq (%r14,%r14,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 0x2876
movl %ebx, %r15d
movq (%rsp), %rdi
movq (%rdi), %rdi
shlq $0x5, %r14
movq (%rdi,%r14), %rdi
movsbq (%rdi,%r15), %rdi
cmpq $0x0, -0x308(%r13,%rdi,8)
je 0x2876
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 %ebp, (%rsi)
movl %ebx, 0x4(%rsi)
callq 0x3b06
movq (%rsp), %rax
movq (%rax), %rax
movq (%rax,%r14), %rax
movsbq (%rax,%r15), %rax
movq -0x308(%r13,%rax,8), %rax
movq %rax, 0x48(%rsp)
cmpb $0x1, 0xd0(%rax)
jne 0x279a
leaq 0x20(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
movq 0xc8(%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r12
cmpq %r12, %r14
je 0x2725
leaq 0x10(%rsp), %r15
movslq (%r14), %rax
movq (%rsp), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
movslq 0x4(%r14), %rdx
movq (%rcx,%rax), %rax
movsbl (%rax,%rdx), %esi
movq %r15, %rdi
callq 0x2130
addq $0x8, %r14
cmpq %r12, %r14
jne 0x26fa
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0xc8(%rsp), %rdx
callq 0x34e2
leaq 0x50(%rsp), %rsi
movq 0xd0(%rsp), %rdi
callq 0x3c68
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x2768
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2160
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2783
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x279a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x69e7(%rip), %r14      # 0x9188
movq 0x69e8(%rip), %r12      # 0x9190
cmpq %r12, %r14
je 0x2844
movl (%r14), %r15d
movl 0x4(%r14), %r13d
movl %r15d, %eax
negl %eax
cmovsl %r15d, %eax
movl %r13d, %ecx
negl %ecx
cmovsl %r13d, %ecx
addl %ebx, %r13d
addl %ebp, %r15d
cmpl %ecx, %eax
jne 0x2801
movl %r15d, 0x50(%rsp)
movl %ebx, 0x54(%rsp)
movl %ebp, 0x10(%rsp)
movl %r13d, 0x14(%rsp)
movq 0xc8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x252c
testb %al, %al
jne 0x283b
subq $0x8, %rsp
movq 0x8(%rsp), %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movq 0x50(%rsp), %rcx
movl %r15d, %r8d
movl %r13d, %r9d
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
pushq 0xd8(%rsp)
callq 0x25cf
addq $0x20, %rsp
addq $0x8, %r14
jmp 0x27a8
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 0x3536
jmp 0x289c
jmp 0x2899
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x28b3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq %rbx, %rdi
callq 0x2280