// File: /workspace/github_cpp_makefile_star2_O2/macfergus[P]baduk/cppsrc/baduk/agent.cpp
// Function: baduk::isPointAnEye(baduk::Board const&, baduk::Point const&, baduk::Stone)
bool isPointAnEye(Board const& board, Point const& point, Stone stone) {
    // An eye is an empty point.
    if (!board.isEmpty(point)) {
        return false;
    }

    // All adjacent points must contain friendly stones.
    for (auto neighbor : board.neighbors(point)) {
        if (board.isEmpty(neighbor)) {
            return false;
        }
        if (board.at(neighbor) != stone) {
            return false;
        }
    }

    // We must control 3 out of 4 corners in the middle. On the edge we must
    // control all corners.
    unsigned int friendly_corners = 0;
    unsigned int off_board_corners = 0;
    std::vector<Point> corners;
    if (point.row() > 0 && point.col() > 0) {
        corners.push_back(Point(point.row() - 1, point.col() - 1));
    } else {
        ++off_board_corners;
    }
    if (point.row() > 0 && point.col() < board.numCols() - 1) {
        corners.push_back(Point(point.row() - 1, point.col() + 1));
    } else {
        ++off_board_corners;
    }
    if (point.row() < board.numRows() - 1 && point.col() > 0) {
        corners.push_back(Point(point.row() + 1, point.col() - 1));
    } else {
        ++off_board_corners;
    }
    if (point.row() < board.numRows() - 1 &&
            point.col() < board.numCols() - 1) {
        corners.push_back(Point(point.row() + 1, point.col() + 1));
    } else {
        ++off_board_corners;
    }
    for (auto corner : corners) {
        if (!board.isEmpty(corner) && board.at(corner) == stone) {
            ++friendly_corners;
        }
    }
    if (off_board_corners > 0) {
        return off_board_corners + friendly_corners == 4;
    }
    return friendly_corners >= 3;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
movq (%rsi), %rsi
callq 0xfa38
testb %al, %al
je 0x6597
movq (%r15), %rsi
movq %r14, %rdi
callq 0x10160
movq (%rax), %r13
movq 0x8(%rax), %rbp
cmpq %rbp, %r13
je 0x65aa
movq (%r13), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xfa38
testb %al, %al
jne 0x6597
movq %r14, %rdi
movq %r12, %rsi
callq 0x10118
addq $0x8, %r13
cmpl %ebx, %eax
je 0x656c
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andq $0x0, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movl (%r15), %eax
testl %eax, %eax
je 0x65e4
movl 0x4(%r15), %ecx
testl %ecx, %ecx
je 0x65ea
decl %eax
decl %ecx
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x69ce
xorl %r12d, %r12d
jmp 0x65ee
pushq $0x1
popq %r12
jmp 0x661d
pushq $0x1
popq %r12
movl (%r15), %eax
testl %eax, %eax
je 0x661d
movl 0x4(%r15), %ecx
movl 0xc(%r14), %edx
decl %edx
cmpl %edx, %ecx
jae 0x661d
decl %eax
incl %ecx
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x69ce
jmp 0x6620
incl %r12d
movl (%r15), %ecx
movl 0x8(%r14), %eax
decl %eax
cmpl %eax, %ecx
jae 0x6655
movl 0x4(%r15), %edx
testl %edx, %edx
je 0x6655
incl %ecx
decl %edx
leaq 0x8(%rsp), %rsi
movl %ecx, (%rsi)
movl %edx, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x69ce
movl 0x8(%r14), %eax
decl %eax
jmp 0x6658
incl %r12d
movl (%r15), %ecx
cmpl %eax, %ecx
jae 0x6687
movl 0x4(%r15), %eax
movl 0xc(%r14), %edx
decl %edx
cmpl %edx, %eax
jae 0x6687
incl %ecx
incl %eax
leaq 0x8(%rsp), %rsi
movl %ecx, (%rsi)
movl %eax, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x69ce
jmp 0x668a
incl %r12d
movq %r12, 0x30(%rsp)
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r12
xorl %r13d, %r13d
cmpq %r12, %rbp
je 0x66cf
movq (%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xfa38
testb %al, %al
jne 0x66c9
movq %r14, %rdi
movq %r15, %rsi
callq 0x10118
xorl %ecx, %ecx
cmpl %ebx, %eax
sete %cl
addl %ecx, %r13d
addq $0x8, %rbp
jmp 0x669c
movq 0x30(%rsp), %rdx
leal (%rdx,%r13), %eax
xorl %ecx, %ecx
cmpl $0x4, %eax
sete %cl
xorl %ebx, %ebx
cmpl $0x3, %r13d
setae %bl
testl %edx, %edx
cmovnel %ecx, %ebx
leaq 0x10(%rsp), %rdi
callq 0x699a
jmp 0x6599
jmp 0x6705
jmp 0x6705
jmp 0x6705
jmp 0x6705
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x699a
movq %rbx, %rdi
callq 0x32b0