// File: 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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x24(%rbp)
movq -0x24(%rbp), %rsi
callq 0x3c650
testb $0x1, %al
jne 0xf99b
movb $0x0, -0x1(%rbp)
jmp 0xfe9b
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
callq 0x3d5b0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x101b0
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
callq 0x101e0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x10210
testb $0x1, %al
jne 0xf9e4
jmp 0xfa48
leaq -0x40(%rbp), %rdi
callq 0x10250
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rsi
callq 0x3c650
testb $0x1, %al
jne 0xfa0f
jmp 0xfa18
movb $0x0, -0x1(%rbp)
jmp 0xfe9b
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rsi
callq 0x3d4c0
cmpl -0x1c(%rbp), %eax
je 0xfa3b
movb $0x0, -0x1(%rbp)
jmp 0xfe9b
jmp 0xfa3d
leaq -0x40(%rbp), %rdi
callq 0x10270
jmp 0xf9d1
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x10290
movq -0x18(%rbp), %rdi
callq 0x9db0
movl %eax, -0xe8(%rbp)
jmp 0xfa70
movl -0xe8(%rbp), %eax
cmpl $0x0, %eax
jbe 0xfb1f
movq -0x18(%rbp), %rdi
callq 0x9d90
movl %eax, -0xec(%rbp)
jmp 0xfa90
movl -0xec(%rbp), %eax
cmpl $0x0, %eax
jbe 0xfb1f
movq -0x18(%rbp), %rdi
callq 0x9db0
movl %eax, -0xf0(%rbp)
jmp 0xfab0
movl -0xf0(%rbp), %eax
decl %eax
movl %eax, -0xf8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9d90
movl %eax, -0xf4(%rbp)
jmp 0xfacf
movl -0xf8(%rbp), %esi
movl -0xf4(%rbp), %edx
decl %edx
leaq -0x94(%rbp), %rdi
callq 0x9dc0
jmp 0xfaeb
leaq -0x80(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0x102b0
jmp 0xfafd
jmp 0xfb28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x103c0
jmp 0xfea9
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9db0
movl %eax, -0xfc(%rbp)
jmp 0xfb39
movl -0xfc(%rbp), %eax
cmpl $0x0, %eax
jbe 0xfbdd
movq -0x18(%rbp), %rdi
callq 0x9d90
movl %eax, -0x100(%rbp)
jmp 0xfb59
movq -0x10(%rbp), %rdi
callq 0xb6c0
movl %eax, -0x104(%rbp)
jmp 0xfb6a
movl -0x100(%rbp), %eax
movl -0x104(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0xfbdd
movq -0x18(%rbp), %rdi
callq 0x9db0
movl %eax, -0x108(%rbp)
jmp 0xfb8e
movl -0x108(%rbp), %eax
decl %eax
movl %eax, -0x110(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9d90
movl %eax, -0x10c(%rbp)
jmp 0xfbad
movl -0x110(%rbp), %esi
movl -0x10c(%rbp), %edx
incl %edx
leaq -0x9c(%rbp), %rdi
callq 0x9dc0
jmp 0xfbc9
leaq -0x80(%rbp), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x102b0
jmp 0xfbdb
jmp 0xfbe6
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9db0
movl %eax, -0x114(%rbp)
jmp 0xfbf7
movq -0x10(%rbp), %rdi
callq 0xb6a0
movl %eax, -0x118(%rbp)
jmp 0xfc08
movl -0x114(%rbp), %eax
movl -0x118(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0xfc97
movq -0x18(%rbp), %rdi
callq 0x9d90
movl %eax, -0x11c(%rbp)
jmp 0xfc2c
movl -0x11c(%rbp), %eax
cmpl $0x0, %eax
jbe 0xfc97
movq -0x18(%rbp), %rdi
callq 0x9db0
movl %eax, -0x120(%rbp)
jmp 0xfc48
movl -0x120(%rbp), %eax
incl %eax
movl %eax, -0x128(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9d90
movl %eax, -0x124(%rbp)
jmp 0xfc67
movl -0x128(%rbp), %esi
movl -0x124(%rbp), %edx
decl %edx
leaq -0xa4(%rbp), %rdi
callq 0x9dc0
jmp 0xfc83
leaq -0x80(%rbp), %rdi
leaq -0xa4(%rbp), %rsi
callq 0x102b0
jmp 0xfc95
jmp 0xfca0
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9db0
movl %eax, -0x12c(%rbp)
jmp 0xfcb1
movq -0x10(%rbp), %rdi
callq 0xb6a0
movl %eax, -0x130(%rbp)
jmp 0xfcc2
movl -0x12c(%rbp), %eax
movl -0x130(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0xfd6e
movq -0x18(%rbp), %rdi
callq 0x9d90
movl %eax, -0x134(%rbp)
jmp 0xfcea
movq -0x10(%rbp), %rdi
callq 0xb6c0
movl %eax, -0x138(%rbp)
jmp 0xfcfb
movl -0x134(%rbp), %eax
movl -0x138(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0xfd6e
movq -0x18(%rbp), %rdi
callq 0x9db0
movl %eax, -0x13c(%rbp)
jmp 0xfd1f
movl -0x13c(%rbp), %eax
incl %eax
movl %eax, -0x144(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9d90
movl %eax, -0x140(%rbp)
jmp 0xfd3e
movl -0x144(%rbp), %esi
movl -0x140(%rbp), %edx
incl %edx
leaq -0xac(%rbp), %rdi
callq 0x9dc0
jmp 0xfd5a
leaq -0x80(%rbp), %rdi
leaq -0xac(%rbp), %rsi
callq 0x102b0
jmp 0xfd6c
jmp 0xfd77
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
leaq -0x80(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x102e0
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x10310
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x10340
testb $0x1, %al
jne 0xfdc4
jmp 0xfe59
leaq -0xc0(%rbp), %rdi
callq 0x10380
movq (%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
movq -0xd0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rsi
callq 0x3c650
movb %al, -0x145(%rbp)
jmp 0xfe00
movb -0x145(%rbp), %al
testb $0x1, %al
jne 0xfe46
jmp 0xfe0c
movq -0x10(%rbp), %rdi
movq -0xd0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rsi
callq 0x3d4c0
movl %eax, -0x14c(%rbp)
jmp 0xfe32
movl -0x14c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0xfe46
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xfe48
leaq -0xc0(%rbp), %rdi
callq 0x103a0
jmp 0xfda8
cmpl $0x0, -0x68(%rbp)
jbe 0xfe7c
movl -0x68(%rbp), %eax
addl -0x64(%rbp), %eax
cmpl $0x4, %eax
sete %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0xe4(%rbp)
jmp 0xfe92
cmpl $0x3, -0x64(%rbp)
setae %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0xe4(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x103c0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x3370
nopw %cs:(%rax,%rax)