// File: /workspace/github_cpp_makefile_star2_O3/razimantv[P]DancingLinks/sudoku/../DancingLinks/DancingLinks.cpp
// Function: DancingLinks::solve(std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>&, std::vector<int, std::allocator<int>>&, bool, int)
bool DancingLinks::solve(std::vector<std::vector<int> > &allsolutions,
                         std::vector<int> &cursolution, bool allneeded, int maxsel) {
  if (dummycolumn_->right_ptr()->essential() == false) {
    // No more constraints left to be satisfied. Success
    allsolutions.push_back(cursolution);
    return true;
  }
  if ((maxsel != -1) && (cursolution.size() >= maxsel))
    return false;

  // Find the essential column with the lowest degree
  DancingLinksColumn *chosencolumn = dummycolumn_->right_ptr();
  int mincnt = chosencolumn->size();
  for (DancingLinksColumn *ptr = chosencolumn->right_ptr(); ptr->essential();
       ptr = ptr->right_ptr()) {
    if (ptr->size() < mincnt) {
      chosencolumn = ptr;
      mincnt = ptr->size();
    }
  }

  // No way to satisfy some constraint. Failure
  if (mincnt == 0) return false;
  bool flag = false;

  // Remove the chosen column
  chosencolumn->RemoveColumn();
  for (DancingLinksCell *ptr = chosencolumn->dummycell()->down_ptr();
       ptr != chosencolumn->dummycell(); ptr = ptr->down_ptr()) {
    // Pick this row in candidate solution

    // Remove columns for all other cells in this row
    cursolution.push_back(ptr->row_id());
    for (DancingLinksCell *ptr2 = ptr->right_ptr(); ptr2 != ptr;
         ptr2 = ptr2->right_ptr()) {
      ptr2->column_ptr()->RemoveColumn();
    }

    // Recurse to solve the modified board
    if (solve(allsolutions, cursolution, allneeded, maxsel)) flag = true;

    // Unremove all those columns
    for (DancingLinksCell *ptr2 = ptr->left_ptr(); ptr2 != ptr;
         ptr2 = ptr2->left_ptr()) {
      ptr2->column_ptr()->UnremoveColumn();
    }
    cursolution.pop_back();

    // If only one solution needs to be found and we have found one, don't
    // bother
    // checking for the rest
    if ((flag == true) && (allneeded == false)) {
      chosencolumn->UnremoveColumn();
      return flag;
    }
  }
  // Unremove the chosen column
  chosencolumn->UnremoveColumn();
  return flag;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, 0xc(%rsp)
movq %rdx, %rbx
movq %rdi, 0x20(%rsp)
movq (%rdi), %rax
movq 0x8(%rax), %r12
cmpb $0x0, 0x1c(%r12)
je 0x1b4e
cmpl $-0x1, %r8d
je 0x1a4e
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x2, %rax
movslq %r8d, %rcx
cmpq %rcx, %rax
jae 0x1b5e
movl 0x18(%r12), %eax
movq 0x8(%r12), %rcx
cmpb $0x1, 0x1c(%rcx)
jne 0x1a74
movl 0x18(%rcx), %edx
cmpl %eax, %edx
cmovlq %rcx, %r12
cmovll %edx, %eax
movq 0x8(%rcx), %rcx
cmpb $0x0, 0x1c(%rcx)
jne 0x1a5e
testl %eax, %eax
je 0x1b5e
movq %rsi, 0x18(%rsp)
movl %r8d, 0x10(%rsp)
movq %r12, %rdi
callq 0x202c
movq 0x10(%r12), %rbp
xorl %r15d, %r15d
movzbl 0xc(%rsp), %r14d
movq 0x18(%rbp), %rbp
cmpq 0x10(%r12), %rbp
je 0x1b63
movl 0x28(%rbp), %eax
movl %eax, 0x14(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x1ac8
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x1ad5
movq %rbx, %rdi
leaq 0x14(%rsp), %rdx
callq 0x1e3a
movq 0x8(%rbp), %r13
cmpq %rbp, %r13
je 0x1aed
movq 0x20(%r13), %rdi
callq 0x202c
movq 0x8(%r13), %r13
jmp 0x1ad9
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
movl %r14d, %ecx
movl 0x10(%rsp), %r8d
callq 0x1a04
movzbl %r15b, %r15d
testb %al, %al
movl $0x1, %eax
cmovnel %eax, %r15d
movq (%rbp), %r13
cmpq %rbp, %r13
je 0x1b2e
movq 0x20(%r13), %rdi
callq 0x207c
movq (%r13), %r13
jmp 0x1b1a
addq $-0x4, 0x8(%rbx)
movl %r15d, %eax
notb %al
orb 0xc(%rsp), %al
testb $0x1, %al
jne 0x1a9c
movq %r12, %rdi
callq 0x207c
jmp 0x1b59
movq %rsi, %rdi
movq %rbx, %rsi
callq 0x1b8c
movb $0x1, %r15b
jmp 0x1b6b
xorl %r15d, %r15d
jmp 0x1b6b
movq %r12, %rdi
callq 0x207c
andb $0x1, %r15b
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq