// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
movq (%rsi), %rsi
callq 0xf80a
testb %al, %al
je 0x6411
movq (%r15), %rsi
movq %r14, %rdi
callq 0x101c8
movq (%rax), %r13
movq 0x8(%rax), %rbp
cmpq %rbp, %r13
je 0x6418
movq (%r13), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xf80a
testb %al, %al
jne 0x6411
movq %r14, %rdi
movq %r12, %rsi
callq 0x1017e
cmpl %ebx, %eax
jne 0x6411
addq $0x8, %r13
jmp 0x63e4
xorl %ebx, %ebx
jmp 0x6570
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movl (%r15), %eax
testl %eax, %eax
je 0x6452
movl 0x4(%r15), %ecx
testl %ecx, %ecx
je 0x645a
decl %eax
decl %ecx
leaq 0x18(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
movq %rsp, %rdi
callq 0x683a
xorl %r12d, %r12d
jmp 0x6460
movl $0x1, %r12d
jmp 0x648d
movl $0x1, %r12d
movl (%r15), %eax
testl %eax, %eax
je 0x648d
movl 0x4(%r15), %ecx
movl 0xc(%r14), %edx
decl %edx
cmpl %edx, %ecx
jae 0x648d
decl %eax
incl %ecx
leaq 0x18(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
movq %rsp, %rdi
callq 0x683a
jmp 0x6490
incl %r12d
movl (%r15), %ecx
movl 0x8(%r14), %eax
decl %eax
cmpl %eax, %ecx
jae 0x64c3
movl 0x4(%r15), %edx
testl %edx, %edx
je 0x64c3
incl %ecx
decl %edx
leaq 0x18(%rsp), %rsi
movl %ecx, (%rsi)
movl %edx, 0x4(%rsi)
movq %rsp, %rdi
callq 0x683a
movl 0x8(%r14), %eax
decl %eax
jmp 0x64c6
incl %r12d
movl (%r15), %ecx
cmpl %eax, %ecx
jae 0x64f3
movl 0x4(%r15), %eax
movl 0xc(%r14), %edx
decl %edx
cmpl %edx, %eax
jae 0x64f3
incl %ecx
incl %eax
leaq 0x18(%rsp), %rsi
movl %ecx, (%rsi)
movl %eax, 0x4(%rsi)
movq %rsp, %rdi
callq 0x683a
jmp 0x64f6
incl %r12d
movq %r12, 0x20(%rsp)
movq (%rsp), %r15
movq 0x8(%rsp), %r13
xorl %ebp, %ebp
cmpq %r13, %r15
je 0x653e
movq (%r15), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xf80a
testb %al, %al
jne 0x6531
movq %r14, %rdi
movq %r12, %rsi
callq 0x1017e
xorl %ecx, %ecx
cmpl %ebx, %eax
sete %cl
addl %ecx, %ebp
addq $0x8, %r15
cmpq %r13, %r15
jne 0x650b
movq (%rsp), %r15
movq 0x20(%rsp), %rdx
leal (%rdx,%rbp), %eax
xorl %ecx, %ecx
cmpl $0x4, %eax
sete %cl
xorl %ebx, %ebx
cmpl $0x3, %ebp
setae %bl
testl %edx, %edx
cmovnel %ecx, %ebx
testq %r15, %r15
je 0x6570
movq 0x10(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x3180
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6589
jmp 0x6589
jmp 0x6589
jmp 0x6589
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x65a2
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x3180
movq %rbx, %rdi
callq 0x32b0