// File: /workspace/github_cpp_makefile_star2_O2/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, 0x4(%rsp)
movq %rdx, %rbx
movq %rdi, 0x20(%rsp)
movq (%rdi), %rax
movq 0x8(%rax), %r12
cmpb $0x0, 0x1c(%r12)
je 0x1a29
movl %r8d, %ebp
cmpl $-0x1, %r8d
je 0x1a09
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x2, %rax
movslq %ebp, %rcx
cmpq %rcx, %rax
jae 0x1b11
movl 0x18(%r12), %eax
movq %r12, %rcx
movq 0x8(%rcx), %rcx
cmpb $0x0, 0x1c(%rcx)
je 0x1a3c
movl 0x18(%rcx), %edx
cmpl %eax, %edx
cmovlq %rcx, %r12
cmovll %edx, %eax
jmp 0x1a11
movq %rsi, %rdi
movq %rbx, %rsi
callq 0x1b34
movb $0x1, %r15b
jmp 0x1b1e
testl %eax, %eax
je 0x1b11
movq %rsi, 0x10(%rsp)
movq %r12, %rdi
callq 0x200a
movq 0x10(%r12), %r14
xorl %r15d, %r15d
movzbl 0x4(%rsp), %eax
movl %eax, 0x8(%rsp)
movq %rbx, 0x18(%rsp)
movq 0x18(%r14), %r14
cmpq 0x10(%r12), %r14
je 0x1b16
movl 0x28(%r14), %eax
movl %eax, 0xc(%rsp)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0x1e1a
movq %r14, %r13
movq 0x8(%r13), %r13
cmpq %r14, %r13
je 0x1aa2
movq 0x20(%r13), %rdi
callq 0x200a
jmp 0x1a8e
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
movl 0x8(%rsp), %ecx
movl %ebp, %ebx
movl %ebp, %r8d
callq 0x19c0
movl %eax, %ebp
movq %r14, %r13
movq (%r13), %r13
cmpq %r14, %r13
je 0x1ad6
movq 0x20(%r13), %rdi
callq 0x2052
jmp 0x1ac2
movzbl %r15b, %r15d
testb %bpl, %bpl
pushq $0x1
popq %rax
cmovnel %eax, %r15d
movq 0x18(%rsp), %rcx
addq $-0x4, 0x8(%rcx)
movl %r15d, %eax
notb %al
orb 0x4(%rsp), %al
testb $0x1, %al
movl %ebx, %ebp
movq %rcx, %rbx
jne 0x1a67
movq %r12, %rdi
callq 0x2052
jmp 0x1a34
xorl %r15d, %r15d
jmp 0x1b1e
movq %r12, %rdi
callq 0x2052
andb $0x1, %r15b
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq