// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movq %rdx, %r14
movq %rdi, 0x20(%rsp)
movq (%rdi), %rax
movq 0x8(%rax), %rbx
cmpb $0x0, 0x1c(%rbx)
je 0x1b55
cmpl $-0x1, %r8d
je 0x1a3e
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x2, %rax
movslq %r8d, %rcx
cmpq %rcx, %rax
jae 0x1b64
movl 0x18(%rbx), %eax
movq 0x8(%rbx), %rcx
cmpb $0x1, 0x1c(%rcx)
jne 0x1a61
movl 0x18(%rcx), %edx
cmpl %eax, %edx
cmovlq %rcx, %rbx
cmovll %edx, %eax
movq 0x8(%rcx), %rcx
cmpb $0x0, 0x1c(%rcx)
jne 0x1a4b
testl %eax, %eax
je 0x1b64
movq %rsi, 0x18(%rsp)
movl %r8d, 0x10(%rsp)
movq %rbx, %rdi
callq 0x2042
movq 0x10(%rbx), %rbp
xorl %r15d, %r15d
movzbl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x18(%rbp), %rbp
movq 0x10(%rbx), %r13
cmpq %r13, %rbp
je 0x1b41
movl 0x28(%rbp), %eax
movl %eax, 0x14(%rsp)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x1ab9
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%r14)
jmp 0x1ac6
movq %r14, %rdi
leaq 0x14(%rsp), %rdx
callq 0x1e40
movq 0x8(%rbp), %r12
cmpq %rbp, %r12
je 0x1ae0
movq 0x20(%r12), %rdi
callq 0x2042
movq 0x8(%r12), %r12
jmp 0x1aca
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
movl 0xc(%rsp), %ecx
movl 0x10(%rsp), %r8d
callq 0x19f6
movzbl %r15b, %r15d
testb %al, %al
movl $0x1, %eax
cmovnel %eax, %r15d
movq (%rbp), %r12
cmpq %rbp, %r12
je 0x1b23
movq 0x20(%r12), %rdi
callq 0x2090
movq (%r12), %r12
jmp 0x1b0e
addq $-0x4, 0x8(%r14)
movl %r15d, %eax
notb %al
orb 0x8(%rsp), %al
testb $0x1, %al
jne 0x1a8b
movq %rbx, %rdi
callq 0x2090
movb $0x1, %al
cmpq %r13, %rbp
jne 0x1b66
movq %rbx, %rdi
callq 0x2090
movl %r15d, %eax
jmp 0x1b66
movq %rsi, %rdi
movq %r14, %rsi
callq 0x1b82
movb $0x1, %al
jmp 0x1b66
xorl %eax, %eax
andb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq