// File: /workspace/github_cpp_makefile_star2_O1/jeffreyan11[P]go-engine/board.cpp
// Function: Board::getPotentialEscape(int, unsigned short)
Move Board::getPotentialEscape(Player p, Move m) {
    if (m == MOVE_PASS)
        return MOVE_PASS;
    int x = getX(m);
    int y = getY(m);
    assert(pieces[index(x, y)] != EMPTY);

    if (pieces[index(x+1, y)] == p) {
        Chain *node = nullptr;
        searchChainsByID(node, chainID[index(x+1, y)]);
        if (node->liberties == 1) {
            Move esc = node->libertyList[0];
            int ex = getX(esc);
            int ey = getY(esc);
            if (pieces[index(ex+1, ey)] == p && chainID[index(ex+1, ey)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex+1, ey)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex-1, ey)] == p && chainID[index(ex-1, ey)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex-1, ey)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex, ey+1)] == p && chainID[index(ex, ey+1)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex, ey+1)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex, ey-1)] == p && chainID[index(ex, ey-1)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex, ey-1)]);
                if (conn->liberties > 2)
                    return esc;
            }
        }
    }

    if (pieces[index(x-1, y)] == p) {
        Chain *node = nullptr;
        searchChainsByID(node, chainID[index(x-1, y)]);
        if (node->liberties == 1) {
            Move esc = node->libertyList[0];
            int ex = getX(esc);
            int ey = getY(esc);
            if (pieces[index(ex+1, ey)] == p && chainID[index(ex+1, ey)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex+1, ey)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex-1, ey)] == p && chainID[index(ex-1, ey)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex-1, ey)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex, ey+1)] == p && chainID[index(ex, ey+1)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex, ey+1)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex, ey-1)] == p && chainID[index(ex, ey-1)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex, ey-1)]);
                if (conn->liberties > 2)
                    return esc;
            }
        }
    }

    if (pieces[index(x, y+1)] == p) {
        Chain *node = nullptr;
        searchChainsByID(node, chainID[index(x, y+1)]);
        if (node->liberties == 1) {
            Move esc = node->libertyList[0];
            int ex = getX(esc);
            int ey = getY(esc);
            if (pieces[index(ex+1, ey)] == p && chainID[index(ex+1, ey)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex+1, ey)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex-1, ey)] == p && chainID[index(ex-1, ey)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex-1, ey)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex, ey+1)] == p && chainID[index(ex, ey+1)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex, ey+1)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex, ey-1)] == p && chainID[index(ex, ey-1)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex, ey-1)]);
                if (conn->liberties > 2)
                    return esc;
            }
        }
    }

    if (pieces[index(x, y-1)] == p) {
        Chain *node = nullptr;
        searchChainsByID(node, chainID[index(x, y-1)]);
        if (node->liberties == 1) {
            Move esc = node->libertyList[0];
            int ex = getX(esc);
            int ey = getY(esc);
            if (pieces[index(ex+1, ey)] == p && chainID[index(ex+1, ey)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex+1, ey)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex-1, ey)] == p && chainID[index(ex-1, ey)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex-1, ey)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex, ey+1)] == p && chainID[index(ex, ey+1)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex, ey+1)]);
                if (conn->liberties > 2)
                    return esc;
            }
            if (pieces[index(ex, ey-1)] == p && chainID[index(ex, ey-1)] != node->id) {
                Chain *conn = nullptr;
                searchChainsByID(conn, chainID[index(ex, ey-1)]);
                if (conn->liberties > 2)
                    return esc;
            }
        }
    }

    return MOVE_PASS;
}

// Assembly:
movw $0x8000, %ax            # imm = 0x8000
cmpl $0x8000, %edx           # imm = 0x8000
je 0x506f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movzwl %dx, %r8d
shrl $0x8, %r8d
movzbl %dl, %r9d
movq (%rdi), %rcx
movl 0x7794(%rip), %r13d     # 0xc18c
movl %r13d, %r10d
imull %r9d, %r10d
leal (%r10,%r8), %eax
incl %eax
movslq %eax, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4b85
movq 0x20(%rdi), %rbx
movl 0x1028(%rdi), %eax
testl %eax, %eax
je 0x4a38
movl (%rbx,%rdx,4), %r11d
xorl %edx, %edx
movslq %edx, %r14
movq 0x28(%rdi,%r14,8), %r14
cmpl %r11d, (%r14)
je 0x4a3b
incl %edx
cmpl %edx, %eax
jne 0x4a25
xorl %r14d, %r14d
movb $0x1, %dl
cmpl $0x1, 0xc(%r14)
jne 0x4b7d
movq %r9, -0x8(%rsp)
movzwl 0x410(%r14), %eax
movl %eax, %r15d
shrl $0x8, %r15d
movzbl %al, %r12d
movq %rcx, %r11
movl %r13d, %ecx
imull %r12d, %r13d
leal (%r15,%r13), %edx
incl %edx
movslq %edx, %rdx
movq %r11, %r9
cmpl %esi, (%r11,%rdx,4)
jne 0x4aab
movl (%rbx,%rdx,4), %ebp
cmpl (%r14), %ebp
je 0x4aab
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4aa1
movl $0x1, %r11d
movslq %r11d, %r11
movq 0x28(%rdi,%r11,8), %rdx
incl %r11d
cmpl %ebp, (%rdx)
jne 0x4a92
cmpl $0x2, 0xc(%rdx)
jg 0x4d1b
leal (%r15,%r13), %edx
decl %edx
movslq %edx, %rdx
cmpl %esi, (%r9,%rdx,4)
movl %ecx, %r13d
jne 0x4aec
movl (%rbx,%rdx,4), %ebp
cmpl (%r14), %ebp
je 0x4aec
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4ae2
movl $0x1, %r11d
movslq %r11d, %r11
movq 0x28(%rdi,%r11,8), %rdx
incl %r11d
cmpl %ebp, (%rdx)
jne 0x4ad3
cmpl $0x2, 0xc(%rdx)
jg 0x4d22
leal 0x1(%r12), %edx
imull %r13d, %edx
addl %r15d, %edx
movslq %edx, %rdx
movq %r9, %rcx
cmpl %esi, (%r9,%rdx,4)
movq -0x8(%rsp), %r9
jne 0x4b38
movl (%rbx,%rdx,4), %ebp
cmpl (%r14), %ebp
je 0x4b38
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4b2e
movl $0x1, %r11d
movslq %r11d, %r11
movq 0x28(%rdi,%r11,8), %rdx
incl %r11d
cmpl %ebp, (%rdx)
jne 0x4b1f
cmpl $0x2, 0xc(%rdx)
jg 0x4d10
decl %r12d
imull %r13d, %r12d
addl %r15d, %r12d
movslq %r12d, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4b79
movl (%rbx,%rdx,4), %ebx
cmpl (%r14), %ebx
je 0x4b79
movq 0x28(%rdi), %rdx
cmpl %ebx, (%rdx)
je 0x4b6f
movl $0x1, %r11d
movslq %r11d, %r11
movq 0x28(%rdi,%r11,8), %rdx
incl %r11d
cmpl %ebx, (%rdx)
jne 0x4b60
cmpl $0x2, 0xc(%rdx)
jg 0x4d10
movb $0x1, %dl
jmp 0x4b7d
testb %dl, %dl
je 0x5065
leal (%r10,%r8), %edx
decl %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4d3e
movq 0x20(%rdi), %r11
movl 0x1028(%rdi), %r10d
testl %r10d, %r10d
je 0x4bc1
movl (%r11,%rdx,4), %ebx
xorl %edx, %edx
movslq %edx, %r14
movq 0x28(%rdi,%r14,8), %r14
cmpl %ebx, (%r14)
je 0x4bc4
incl %edx
cmpl %edx, %r10d
jne 0x4bad
xorl %r14d, %r14d
movb $0x1, %bl
cmpl $0x1, 0xc(%r14)
jne 0x4d36
movzwl 0x410(%r14), %edx
movl %edx, %r15d
shrl $0x8, %r15d
movl %edx, -0x8(%rsp)
movzbl %dl, %r12d
movl %r13d, %r10d
imull %r12d, %r13d
leal (%r15,%r13), %edx
incl %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4c34
movl (%r11,%rdx,4), %ebp
cmpl (%r14), %ebp
je 0x4c34
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4c21
movl $0x1, %ebx
movslq %ebx, %rbx
movq 0x28(%rdi,%rbx,8), %rdx
incl %ebx
cmpl %ebp, (%rdx)
jne 0x4c13
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel -0x8(%rsp), %eax
jge 0x4d31
movb $0x1, %bl
leal (%r15,%r13), %edx
decl %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4c7e
movl (%r11,%rdx,4), %ebp
cmpl (%r14), %ebp
movl %r10d, %r13d
je 0x4c81
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4c69
movl $0x1, %ebx
movslq %ebx, %rbx
movq 0x28(%rdi,%rbx,8), %rdx
incl %ebx
cmpl %ebp, (%rdx)
jne 0x4c5b
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel -0x8(%rsp), %eax
jge 0x4d17
movb $0x1, %bl
jmp 0x4c81
movl %r10d, %r13d
leal 0x1(%r12), %edx
imull %r13d, %edx
addl %r15d, %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4cc8
movl (%r11,%rdx,4), %ebp
cmpl (%r14), %ebp
je 0x4cc8
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4cb9
movl $0x1, %ebx
movslq %ebx, %rbx
movq 0x28(%rdi,%rbx,8), %rdx
incl %ebx
cmpl %ebp, (%rdx)
jne 0x4cab
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel -0x8(%rsp), %eax
jge 0x4d17
movb $0x1, %bl
decl %r12d
imull %r13d, %r12d
addl %r15d, %r12d
movslq %r12d, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4d36
movl (%r11,%rdx,4), %r11d
cmpl (%r14), %r11d
je 0x4d36
movq 0x28(%rdi), %rdx
cmpl %r11d, (%rdx)
je 0x4d02
movl $0x1, %r10d
movslq %r10d, %r10
movq 0x28(%rdi,%r10,8), %rdx
incl %r10d
cmpl %r11d, (%rdx)
jne 0x4cf2
cmpl $0x3, 0xc(%rdx)
setl %bl
cmovgel -0x8(%rsp), %eax
jmp 0x4d36
xorl %edx, %edx
jmp 0x4b7d
xorl %ebx, %ebx
jmp 0x4d36
xorl %edx, %edx
movl %ecx, %r13d
jmp 0x4d24
xorl %edx, %edx
movq %r9, %rcx
movq -0x8(%rsp), %r9
jmp 0x4b7d
xorl %ebx, %ebx
movl %r10d, %r13d
testb %bl, %bl
je 0x5065
leal 0x1(%r9), %edx
imull %r13d, %edx
addl %r8d, %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4edf
movq 0x20(%rdi), %r11
movl 0x1028(%rdi), %r10d
testl %r10d, %r10d
je 0x4d7f
movl (%r11,%rdx,4), %ebx
xorl %edx, %edx
movslq %edx, %r14
movq 0x28(%rdi,%r14,8), %r14
cmpl %ebx, (%r14)
je 0x4d82
incl %edx
cmpl %edx, %r10d
jne 0x4d6b
xorl %r14d, %r14d
movb $0x1, %bl
cmpl $0x1, 0xc(%r14)
jne 0x4ed7
movzwl 0x410(%r14), %edx
movl %edx, %r15d
shrl $0x8, %r15d
movl %edx, -0x8(%rsp)
movzbl %dl, %r12d
movl %r13d, %r10d
imull %r12d, %r13d
leal (%r15,%r13), %edx
incl %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4df2
movl (%r11,%rdx,4), %ebp
cmpl (%r14), %ebp
je 0x4df2
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4ddf
movl $0x1, %ebx
movslq %ebx, %rbx
movq 0x28(%rdi,%rbx,8), %rdx
incl %ebx
cmpl %ebp, (%rdx)
jne 0x4dd1
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel -0x8(%rsp), %eax
jge 0x4ed2
movb $0x1, %bl
leal (%r15,%r13), %edx
decl %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4e3c
movl (%r11,%rdx,4), %ebp
cmpl (%r14), %ebp
movl %r10d, %r13d
je 0x4e3f
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4e27
movl $0x1, %ebx
movslq %ebx, %rbx
movq 0x28(%rdi,%rbx,8), %rdx
incl %ebx
cmpl %ebp, (%rdx)
jne 0x4e19
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel -0x8(%rsp), %eax
jge 0x4ece
movb $0x1, %bl
jmp 0x4e3f
movl %r10d, %r13d
leal 0x1(%r12), %edx
imull %r13d, %edx
addl %r15d, %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4e86
movl (%r11,%rdx,4), %ebp
cmpl (%r14), %ebp
je 0x4e86
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4e77
movl $0x1, %ebx
movslq %ebx, %rbx
movq 0x28(%rdi,%rbx,8), %rdx
incl %ebx
cmpl %ebp, (%rdx)
jne 0x4e69
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel -0x8(%rsp), %eax
jge 0x4ece
movb $0x1, %bl
decl %r12d
imull %r13d, %r12d
addl %r15d, %r12d
movslq %r12d, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4ed7
movl (%r11,%rdx,4), %r11d
cmpl (%r14), %r11d
je 0x4ed7
movq 0x28(%rdi), %rdx
cmpl %r11d, (%rdx)
je 0x4ec0
movl $0x1, %r10d
movslq %r10d, %r10
movq 0x28(%rdi,%r10,8), %rdx
incl %r10d
cmpl %r11d, (%rdx)
jne 0x4eb0
cmpl $0x3, 0xc(%rdx)
setl %bl
cmovgel -0x8(%rsp), %eax
jmp 0x4ed7
xorl %ebx, %ebx
jmp 0x4ed7
xorl %ebx, %ebx
movl %r10d, %r13d
testb %bl, %bl
je 0x5065
decl %r9d
imull %r13d, %r9d
addl %r8d, %r9d
movslq %r9d, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x5061
movq 0x20(%rdi), %r9
movl 0x1028(%rdi), %r8d
testl %r8d, %r8d
je 0x4f1f
movl (%r9,%rdx,4), %r10d
xorl %edx, %edx
movslq %edx, %r11
movq 0x28(%rdi,%r11,8), %r11
cmpl %r10d, (%r11)
je 0x4f22
incl %edx
cmpl %edx, %r8d
jne 0x4f0b
xorl %r11d, %r11d
movb $0x1, %r8b
cmpl $0x1, 0xc(%r11)
jne 0x505c
movzwl 0x410(%r11), %r10d
movl %r10d, %ebx
shrl $0x8, %ebx
movzbl %r10b, %r14d
movl %r13d, %r15d
imull %r14d, %r15d
leal (%r15,%rbx), %edx
incl %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4f8d
movl (%r9,%rdx,4), %ebp
cmpl (%r11), %ebp
je 0x4f8d
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4f7d
movl $0x1, %r12d
movslq %r12d, %r12
movq 0x28(%rdi,%r12,8), %rdx
incl %r12d
cmpl %ebp, (%rdx)
jne 0x4f6e
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel %r10d, %eax
jge 0x5059
leal (%r15,%rbx), %edx
decl %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4fd1
movl (%r9,%rdx,4), %ebp
cmpl (%r11), %ebp
je 0x4fd1
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x4fc1
movl $0x1, %r15d
movslq %r15d, %r15
movq 0x28(%rdi,%r15,8), %rdx
incl %r15d
cmpl %ebp, (%rdx)
jne 0x4fb2
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel %r10d, %eax
jge 0x5059
leal 0x1(%r14), %edx
imull %r13d, %edx
addl %ebx, %edx
movslq %edx, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x5015
movl (%r9,%rdx,4), %ebp
cmpl (%r11), %ebp
je 0x5015
movq 0x28(%rdi), %rdx
cmpl %ebp, (%rdx)
je 0x5009
movl $0x1, %r15d
movslq %r15d, %r15
movq 0x28(%rdi,%r15,8), %rdx
incl %r15d
cmpl %ebp, (%rdx)
jne 0x4ffa
movl 0xc(%rdx), %edx
cmpl $0x3, %edx
cmovgel %r10d, %eax
jge 0x5059
decl %r14d
imull %r13d, %r14d
addl %ebx, %r14d
movslq %r14d, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x505c
movl (%r9,%rdx,4), %ecx
cmpl (%r11), %ecx
je 0x505c
movq 0x28(%rdi), %rdx
cmpl %ecx, (%rdx)
je 0x504b
movl $0x1, %esi
movslq %esi, %rsi
movq 0x28(%rdi,%rsi,8), %rdx
incl %esi
cmpl %ecx, (%rdx)
jne 0x503d
cmpl $0x3, 0xc(%rdx)
setl %r8b
cmovgel %r10d, %eax
jmp 0x505c
xorl %r8d, %r8d
testb %r8b, %r8b
je 0x5065
movw $0x8000, %ax            # imm = 0x8000
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq