// File: /workspace/github_cpp_makefile_star2_O1/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, 0xc(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movq (%rsi), %rsi
callq 0xfe32
testb %al, %al
je 0x64a1
movq (%r15), %rsi
movq %r14, %rdi
callq 0x10892
movq (%rax), %r13
movq 0x8(%rax), %rbx
cmpq %rbx, %r13
sete %bpl
je 0x6431
movq (%r13), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xfe32
testb %al, %al
jne 0x642b
addq $0x8, %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0x10848
cmpl 0xc(%rsp), %eax
jne 0x642b
cmpq %rbx, %r13
sete %bpl
je 0x6431
movq (%r13), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xfe32
addq $0x8, %r13
testb %al, %al
je 0x63fa
testb $0x1, %bpl
je 0x64a1
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl (%r15), %eax
movl $0x1, %r12d
testl %eax, %eax
je 0x6472
movl 0x4(%r15), %ecx
testl %ecx, %ecx
je 0x6472
decl %eax
decl %ecx
leaq 0x30(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x6842
xorl %r12d, %r12d
movl (%r15), %eax
testl %eax, %eax
je 0x64a8
movl 0x4(%r15), %ecx
movl 0xc(%r14), %edx
decl %edx
cmpl %edx, %ecx
jae 0x64a8
decl %eax
incl %ecx
leaq 0x30(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x6842
jmp 0x64ab
xorl %ebx, %ebx
jmp 0x6588
incl %r12d
movl (%r15), %eax
movl 0x8(%r14), %ecx
decl %ecx
cmpl %ecx, %eax
jae 0x64da
movl 0x4(%r15), %ecx
testl %ecx, %ecx
je 0x64da
incl %eax
decl %ecx
leaq 0x30(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x6842
jmp 0x64dd
incl %r12d
movl (%r15), %eax
movl 0x8(%r14), %ecx
decl %ecx
cmpl %ecx, %eax
jae 0x6512
movl 0x4(%r15), %ecx
movl 0xc(%r14), %edx
decl %edx
cmpl %edx, %ecx
jae 0x6512
incl %eax
incl %ecx
leaq 0x30(%rsp), %rsi
movl %eax, (%rsi)
movl %ecx, 0x4(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x6842
jmp 0x6515
incl %r12d
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rbp
xorl %r13d, %r13d
cmpq %rbp, %rbx
je 0x6556
movq (%rbx), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0xfe32
testb %al, %al
jne 0x6550
movq %r14, %rdi
movq %r15, %rsi
callq 0x10848
xorl %ecx, %ecx
cmpl 0xc(%rsp), %eax
sete %cl
addl %ecx, %r13d
addq $0x8, %rbx
jmp 0x6522
leal (%r12,%r13), %eax
xorl %ecx, %ecx
cmpl $0x4, %eax
sete %cl
xorl %ebx, %ebx
cmpl $0x3, %r13d
setae %bl
testl %r12d, %r12d
cmovnel %ecx, %ebx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6588
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3180
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x65a1
jmp 0x65a1
jmp 0x65a1
jmp 0x65a1
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x65bb
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3180
movq %rbx, %rdi
callq 0x32b0
nop