// File: davidjosepha[P]slitherlink/src/generator/generator.cpp
// Function: Generator::findNumberToRemove()
void Generator::findNumberToRemove() {
    fillEligibleVector();
    bool coordsFound = false;

    while (!eligibleCoordinates_.empty() && !coordsFound) {
        int random = rand() % eligibleCoordinates_.size();
        Coordinates attempt = eligibleCoordinates_.at(random);
        eligibleCoordinates_.erase(eligibleCoordinates_.begin() + random);

        // Checks if the number in question is needed to retain a balance
        if (isBalanced(attempt.i, attempt.j)) {
            removeNumber(attempt.i, attempt.j);

            // If unsolvable, bring number back and look for another
            if (!checkIfSolved()) {
                setOldNumber(attempt.i, attempt.j);
                markNecessary(attempt.i, attempt.j);
            } else {
                ineligibleCoordinates_.push_back(attempt);
                coordsFound = true;
                numberCount_ --;
                minusCounts(oldNumbers_[attempt.i-1][attempt.j-1]);
            }
        }
    }

    // If no more candidates, bring back the previously removed number
    if (!coordsFound && numberCount_ < m_ * n_) {
        getNecessaryCoordinate();
        numberCount_ ++;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x40(%rbp)
callq 0x11450
movb $0x0, -0x9(%rbp)
movq -0x40(%rbp), %rdi
addq $0xf8, %rdi
callq 0x11e20
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x41(%rbp)
jne 0x112d1
movb -0x9(%rbp), %al
xorb $-0x1, %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x112dd
jmp 0x11419
callq 0x2070
movq -0x40(%rbp), %rdi
cltq
movq %rax, -0x58(%rbp)
addq $0xf8, %rdi
callq 0x11e60
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movq -0x58(%rbp), %rax
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, -0x10(%rbp)
addq $0xf8, %rdi
movslq -0x10(%rbp), %rsi
callq 0x11e80
movq -0x40(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq %rdi, %rax
addq $0xf8, %rax
movq %rax, -0x50(%rbp)
addq $0xf8, %rdi
callq 0x11f30
movq %rax, -0x30(%rbp)
movslq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x11f60
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x11fa0
movq -0x50(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x11ec0
movq -0x40(%rbp), %rdi
movq %rax, -0x38(%rbp)
movl -0x18(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x114f0
testb $0x1, %al
jne 0x1138c
jmp 0x11414
movq -0x40(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x11660
movq -0x40(%rbp), %rdi
callq 0x10d90
testb $0x1, %al
jne 0x113c8
movq -0x40(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x116c0
movq -0x40(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x11710
jmp 0x11412
movq -0x40(%rbp), %rdi
addq $0x110, %rdi            # imm = 0x110
leaq -0x18(%rbp), %rsi
callq 0x11fe0
movq -0x40(%rbp), %rdi
movb $0x1, -0x9(%rbp)
movl 0x18(%rdi), %eax
addl $-0x1, %eax
movl %eax, 0x18(%rdi)
movq 0x140(%rdi), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %esi
callq 0x11220
jmp 0x11414
jmp 0x112ad
testb $0x1, -0x9(%rbp)
jne 0x11446
movq -0x40(%rbp), %rdx
movl 0x18(%rdx), %eax
movl (%rdx), %ecx
imull 0x4(%rdx), %ecx
cmpl %ecx, %eax
jge 0x11446
movq -0x40(%rbp), %rdi
callq 0x11750
movq -0x40(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)