// File: razimantv[P]DancingLinks/nqueens/../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:
subq $0x88, %rsp
movb %cl, %al
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
andb $0x1, %al
movb %al, 0x67(%rsp)
movl %r8d, 0x60(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x18(%rsp)
movq (%rax), %rdi
callq 0x2c30
movq %rax, %rdi
callq 0x2c40
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2883
movq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x2c50
movb $0x1, 0x87(%rsp)
jmp 0x2ac0
cmpl $-0x1, 0x60(%rsp)
je 0x28ab
movq 0x68(%rsp), %rdi
callq 0x17a0
movslq 0x60(%rsp), %rcx
cmpq %rcx, %rax
jb 0x28ab
movb $0x0, 0x87(%rsp)
jmp 0x2ac0
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x2c30
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdi
callq 0x2cc0
movl %eax, 0x54(%rsp)
movq 0x58(%rsp), %rdi
callq 0x2c30
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2c40
testb $0x1, %al
jne 0x28ea
jmp 0x2925
movq 0x48(%rsp), %rdi
callq 0x2cc0
cmpl 0x54(%rsp), %eax
jge 0x2912
movq 0x48(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2cc0
movl %eax, 0x54(%rsp)
jmp 0x2914
movq 0x48(%rsp), %rdi
callq 0x2c30
movq %rax, 0x48(%rsp)
jmp 0x28da
cmpl $0x0, 0x54(%rsp)
jne 0x2939
movb $0x0, 0x87(%rsp)
jmp 0x2ac0
movb $0x0, 0x47(%rsp)
movq 0x58(%rsp), %rdi
callq 0x47c0
movq 0x58(%rsp), %rdi
callq 0x2c00
movq %rax, %rdi
callq 0x2cd0
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
callq 0x2c00
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
je 0x2aa9
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
callq 0x2d10
movq 0x8(%rsp), %rdi
movl %eax, 0x34(%rsp)
leaq 0x34(%rsp), %rsi
callq 0x2ce0
movq 0x38(%rsp), %rdi
callq 0x2d20
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x38(%rsp), %rax
je 0x29e9
movq 0x28(%rsp), %rdi
callq 0x2d30
movq %rax, %rdi
callq 0x47c0
movq 0x28(%rsp), %rdi
callq 0x2d20
movq %rax, 0x28(%rsp)
jmp 0x29ba
movq 0x18(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movb 0x67(%rsp), %al
movl 0x60(%rsp), %r8d
andb $0x1, %al
movzbl %al, %ecx
callq 0x2820
testb $0x1, %al
jne 0x2a11
jmp 0x2a16
movb $0x1, 0x47(%rsp)
movq 0x38(%rsp), %rdi
callq 0x2d40
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq 0x38(%rsp), %rax
je 0x2a54
movq 0x20(%rsp), %rdi
callq 0x2d30
movq %rax, %rdi
callq 0x4870
movq 0x20(%rsp), %rdi
callq 0x2d40
movq %rax, 0x20(%rsp)
jmp 0x2a25
movq 0x68(%rsp), %rdi
callq 0x2d50
movb 0x47(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x2a93
movb 0x67(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2a93
movq 0x58(%rsp), %rdi
callq 0x4870
movb 0x47(%rsp), %al
andb $0x1, %al
movb %al, 0x87(%rsp)
jmp 0x2ac0
jmp 0x2a95
movq 0x38(%rsp), %rdi
callq 0x2cd0
movq %rax, 0x38(%rsp)
jmp 0x295f
movq 0x58(%rsp), %rdi
callq 0x4870
movb 0x47(%rsp), %al
andb $0x1, %al
movb %al, 0x87(%rsp)
movb 0x87(%rsp), %al
andb $0x1, %al
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)