// File: davidjosepha[P]slitherlink/src/solver/solver.cpp
// Function: Solver::solveDepth(int)
void Solver::solveDepth(int depth) {
    bool usingPrioQueue = true;

    if (usingPrioQueue) {
        int initSize = epq_.size();
        int guesses = 0;

        while (!epq_.empty() && guesses++ < initSize && !multipleSolutions_) {

            PrioEdge pe = epq_.top();

            if (pe.h) {
                makeHLineGuess(pe.coords.i, pe.coords.j, depth);
                if (grid_->getHLine(pe.coords.i, pe.coords.j) == EMPTY) {
                    pe.priority = pe.priority - 1;
                    epq_.push(pe);
                }
                if (grid_->getUpdated()) {
                    break;
                }
            } else {
                makeVLineGuess(pe.coords.i, pe.coords.j, depth);
                if (grid_->getVLine(pe.coords.i, pe.coords.j) == EMPTY) {
                    pe.priority = pe.priority - 1;
                    epq_.push(pe);
                }
                if (grid_->getUpdated()) {
                    break;
                }
            }
            epq_.pop();
        }
    } else {
        for (int i = 0; i < grid_->getHeight()+1; i++) {
            for (int j = 0; j < grid_->getWidth(); j++) {
                applyRules(selectedRules_);
                makeHLineGuess(i, j, depth);
            }
        }

        for (int i = 0; i < grid_->getHeight(); i++) {
            for (int j = 0; j < grid_->getWidth()+1; j++) {
                applyRules(selectedRules_);
                makeVLineGuess(i, j, depth);
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movb $0x1, -0xd(%rbp)
testb $0x1, -0xd(%rbp)
je 0xd92f
movq -0x78(%rbp), %rdi
addq $0x38, %rdi
callq 0x8780
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x78(%rbp), %rdi
addq $0x38, %rdi
callq 0x8750
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x79(%rbp)
jne 0xd7b9
movl -0x18(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x79(%rbp)
jge 0xd7b9
movq -0x78(%rbp), %rax
movb 0x64(%rax), %al
xorb $-0x1, %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0xd7c5
jmp 0xd92a
movq -0x78(%rbp), %rsi
addq $0x38, %rsi
leaq -0x30(%rbp), %rdi
callq 0x87a0
testb $0x1, -0x20(%rbp)
je 0xd87f
movq -0x78(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
movl -0xc(%rbp), %ecx
callq 0xde60
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0x5bf0
cmpl $0x0, %eax
jne 0xd862
movq -0x78(%rbp), %rdi
movsd -0x28(%rbp), %xmm0
movsd 0x7bfd(%rip), %xmm1     # 0x15418
subsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
addq $0x38, %rdi
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x48(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x87f0
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xfc70
testb $0x1, %al
jne 0xd875
jmp 0xd87a
jmp 0xd92a
jmp 0xd918
movq -0x78(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
movl -0xc(%rbp), %ecx
callq 0xe7d0
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0x5c90
cmpl $0x0, %eax
jne 0xd901
movq -0x78(%rbp), %rdi
movsd -0x28(%rbp), %xmm0
movsd 0x7b5e(%rip), %xmm1     # 0x15418
subsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
addq $0x38, %rdi
movq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x60(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x87f0
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xfc70
testb $0x1, %al
jne 0xd914
jmp 0xd916
jmp 0xd92a
jmp 0xd918
movq -0x78(%rbp), %rdi
addq $0x38, %rdi
callq 0x8820
jmp 0xd77f
jmp 0xda46
movl $0x0, -0x64(%rbp)
movq -0x78(%rbp), %rax
movl -0x64(%rbp), %ecx
movl %ecx, -0x80(%rbp)
movq 0x8(%rax), %rdi
callq 0x2ad0
movl %eax, %ecx
movl -0x80(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0xd9b5
movl $0x0, -0x68(%rbp)
movq -0x78(%rbp), %rax
movl -0x68(%rbp), %ecx
movl %ecx, -0x84(%rbp)
movq 0x8(%rax), %rdi
callq 0x2af0
movl %eax, %ecx
movl -0x84(%rbp), %eax
cmpl %ecx, %eax
jge 0xd9a8
movq -0x78(%rbp), %rdi
movq 0x20(%rdi), %rsi
callq 0xcd80
movq -0x78(%rbp), %rdi
movl -0x64(%rbp), %esi
movl -0x68(%rbp), %edx
movl -0xc(%rbp), %ecx
callq 0xde60
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0xd95c
jmp 0xd9aa
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xd936
movl $0x0, -0x6c(%rbp)
movq -0x78(%rbp), %rax
movl -0x6c(%rbp), %ecx
movl %ecx, -0x88(%rbp)
movq 0x8(%rax), %rdi
callq 0x2ad0
movl %eax, %ecx
movl -0x88(%rbp), %eax
cmpl %ecx, %eax
jge 0xda44
movl $0x0, -0x70(%rbp)
movq -0x78(%rbp), %rax
movl -0x70(%rbp), %ecx
movl %ecx, -0x8c(%rbp)
movq 0x8(%rax), %rdi
callq 0x2af0
movl %eax, %ecx
movl -0x8c(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0xda34
movq -0x78(%rbp), %rdi
movq 0x20(%rdi), %rsi
callq 0xcd80
movq -0x78(%rbp), %rdi
movl -0x6c(%rbp), %esi
movl -0x70(%rbp), %edx
movl -0xc(%rbp), %ecx
callq 0xe7d0
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0xd9e5
jmp 0xda36
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xd9bc
jmp 0xda46
addq $0xb0, %rsp
popq %rbp
retq
nop