// File: /workspace/github_cpp_makefile_star2_O1/jeffreyan11[P]go-engine/board.cpp
// Function: Board::isMoveValid(int, unsigned short)
bool Board::isMoveValid(Player p, Move m) {
    if (m == MOVE_PASS)
        return true;

    int x = getX(m);
    int y = getY(m);
    assert(pieces[index(x, y)] == EMPTY);

    // First check if the move makes a capture, since if so then
    // it cannot possibly be a suicide
    Player victim = otherPlayer(p);
    int eastID = (pieces[index(x+1, y)] == victim) * chainID[index(x+1, y)];
    int westID = (pieces[index(x-1, y)] == victim) * chainID[index(x-1, y)];
    int northID = (pieces[index(x, y+1)] == victim) * chainID[index(x, y+1)];
    int southID = (pieces[index(x, y-1)] == victim) * chainID[index(x, y-1)];

    if (eastID) {
        Chain *node = nullptr;
        searchChainsByID(node, eastID);
        if (node->liberties == 1)
            return true;
    }
    if (westID) {
        Chain *node = nullptr;
        searchChainsByID(node, westID);
        if (node->liberties == 1)
            return true;
    }
    if (northID) {
        Chain *node = nullptr;
        searchChainsByID(node, northID);
        if (node->liberties == 1)
            return true;
    }
    if (southID) {
        Chain *node = nullptr;
        searchChainsByID(node, southID);
        if (node->liberties == 1)
            return true;
    }

    if (isEye(victim, m))
        return false;

    pieces[index(x, y)] = p;

    // Suicides are illegal
    if (pieces[index(x+1, y)] && pieces[index(x-1, y)]
     && pieces[index(x, y+1)] && pieces[index(x, y-1)]) {
        if (doCaptures<false>(p, coordToMove(x, y))) {
            pieces[index(x, y)] = EMPTY;
            return false;
        }
    }

    pieces[index(x, y)] = EMPTY;
    return true;
}

// Assembly:
movb $0x1, %al
cmpl $0x8000, %edx           # imm = 0x8000
je 0x404e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ecx
movq %rdi, %rbx
movzwl %dx, %esi
movl %esi, 0xc(%rsp)
movl %esi, %r15d
shrl $0x8, %r15d
movzbl %dl, %r12d
movl $0x3, %esi
movl %ecx, 0x14(%rsp)
subl %ecx, %esi
movq (%rdi), %r13
movl 0x8326(%rip), %r9d      # 0xc18c
movl %r9d, %r14d
imull %r12d, %r14d
leal (%r14,%r15), %ecx
incl %ecx
movslq %ecx, %r10
cmpl %esi, (%r13,%r10,4)
movq 0x20(%rdi), %r11
setne %r8b
leal (%r14,%r15), %ecx
decl %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
movl $0x0, %edi
cmpl %esi, (%r13,%rdx,4)
jne 0x3e9e
movl (%r11,%rdx,4), %edi
leal 0x1(%r12), %ebp
movl %r9d, %edx
movl %ebp, 0x10(%rsp)
imull %ebp, %edx
addl %r15d, %edx
movslq %edx, %rbp
movl $0x0, %edx
cmpl %esi, (%r13,%rbp,4)
jne 0x3ec3
movl (%r11,%rbp,4), %edx
movl (%r11,%r10,4), %r10d
leal -0x1(%r12), %ebp
imull %ebp, %r9d
addl %r15d, %r9d
movslq %r9d, %r9
cmpl %esi, (%r13,%r9,4)
jne 0x3ee1
movl (%r11,%r9,4), %ecx
testl %r10d, %r10d
sete %r9b
orb %r9b, %r8b
jne 0x3f17
movq 0x28(%rbx), %r8
cmpl %r10d, (%r8)
je 0x3f0c
movl $0x1, %r9d
movslq %r9d, %r9
movq 0x28(%rbx,%r9,8), %r8
incl %r9d
cmpl %r10d, (%r8)
jne 0x3efc
cmpl $0x1, 0xc(%r8)
je 0x4040
testl %edi, %edi
je 0x3f45
movq 0x28(%rbx), %r8
cmpl %edi, (%r8)
je 0x3f3a
movl $0x1, %r9d
movslq %r9d, %r9
movq 0x28(%rbx,%r9,8), %r8
incl %r9d
cmpl %edi, (%r8)
jne 0x3f2a
cmpl $0x1, 0xc(%r8)
je 0x4040
testl %edx, %edx
je 0x3f70
movq 0x28(%rbx), %rdi
cmpl %edx, (%rdi)
je 0x3f66
movl $0x1, %r8d
movslq %r8d, %r8
movq 0x28(%rbx,%r8,8), %rdi
incl %r8d
cmpl %edx, (%rdi)
jne 0x3f57
cmpl $0x1, 0xc(%rdi)
je 0x4040
testl %ecx, %ecx
je 0x3f99
movq 0x28(%rbx), %rdx
cmpl %ecx, (%rdx)
je 0x3f8f
movl $0x1, %edi
movslq %edi, %rdi
movq 0x28(%rbx,%rdi,8), %rdx
incl %edi
cmpl %ecx, (%rdx)
jne 0x3f81
cmpl $0x1, 0xc(%rdx)
je 0x4040
movq %rbx, %rdi
movl 0xc(%rsp), %edx
callq 0x4050
testb %al, %al
je 0x3fb0
xorl %eax, %eax
jmp 0x4040
leal 0x1(%r15), %edx
addl %r15d, %r14d
movslq %r14d, %rax
movl 0x14(%rsp), %esi
movl %esi, (%r13,%rax,4)
movl 0x81c3(%rip), %eax      # 0xc18c
movl %eax, %ecx
imull %r12d, %ecx
addl %ecx, %edx
movslq %edx, %rdx
cmpl $0x0, (%r13,%rdx,4)
je 0x4026
leal -0x1(%r15), %edx
addl %edx, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%r13,%rcx,4)
je 0x4026
movl 0x10(%rsp), %ecx
imull %eax, %ecx
addl %r15d, %ecx
movslq %ecx, %rcx
cmpl $0x0, (%r13,%rcx,4)
je 0x4026
imull %ebp, %eax
addl %r15d, %eax
cltq
cmpl $0x0, (%r13,%rax,4)
je 0x4026
movq %rbx, %rdi
movl 0xc(%rsp), %edx
callq 0x5640
testl %eax, %eax
je 0x4026
xorl %eax, %eax
jmp 0x4028
movb $0x1, %al
imull 0x815c(%rip), %r12d     # 0xc18c
movq (%rbx), %rcx
addl %r15d, %r12d
movslq %r12d, %rdx
movl $0x0, (%rcx,%rdx,4)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop