// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0xd4e8
movq 0xf8(%rbx), %rax
cmpq 0x100(%rbx), %rax
je 0xd460
leaq 0x48(%rbx), %r15
leaq 0x110(%rbx), %r14
callq 0x2080
cltq
movq 0xf8(%rbx), %rdi
movq 0x100(%rbx), %rcx
movq %rcx, %r8
subq %rdi, %r8
sarq $0x3, %r8
xorl %edx, %edx
divq %r8
movslq %edx, %rax
cmpq %rax, %r8
jbe 0xd4d3
leaq (%rdi,%rax,8), %rdx
addq $0x8, %rdx
movq -0x8(%rdx), %rsi
movq %rsi, -0x20(%rbp)
cmpq %rcx, %rdx
je 0xd3db
leaq (%rdi,%rax,8), %rdi
subq %rdx, %rcx
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x2240
movq 0x100(%rbx), %rcx
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
jmp 0xd3e2
movq %rsi, %rdx
shrq $0x20, %rdx
addq $-0x8, %rcx
movq %rcx, 0x100(%rbx)
movq %rbx, %rdi
callq 0xd5b4
testb %al, %al
je 0xd44c
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
movq %rbx, %rdi
callq 0xd6be
movq %rbx, %rdi
callq 0xd08e
testb %al, %al
jne 0xd478
movslq -0x20(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
movq 0x140(%rbx), %rax
movq -0x8(%rax,%rsi,8), %rax
movl -0x4(%rax,%rdx,4), %ecx
movq %r15, %rdi
callq 0x43de
movslq -0x20(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq 0x138(%rbx), %rdx
movq -0x8(%rdx,%rax,8), %rax
movb $0x0, -0x1(%rax,%rcx)
movq 0xf8(%rbx), %rax
cmpq 0x100(%rbx), %rax
jne 0xd375
movl 0x4(%rbx), %eax
imull (%rbx), %eax
cmpl %eax, 0x18(%rbx)
jge 0xd4c8
movq %rbx, %rdi
callq 0xd778
incl 0x18(%rbx)
jmp 0xd4c8
movq 0x118(%rbx), %rsi
cmpq 0x120(%rbx), %rsi
je 0xd499
movq -0x20(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x118(%rbx)
jmp 0xd4a5
leaq -0x20(%rbp), %rdx
movq %r14, %rdi
callq 0xdcd0
decl 0x18(%rbx)
movq 0x140(%rbx), %rax
movslq -0x20(%rbp), %rcx
movq -0x8(%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movl -0x4(%rax,%rcx,4), %esi
movq %rbx, %rdi
callq 0xd314
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2226(%rip), %rdi      # 0xf700
movq %rax, %rsi
movq %r8, %rdx
xorl %eax, %eax
callq 0x2200
nop