// File: /workspace/github_cpp_makefile_star2_O3/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 0x4fe3
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 0x778d(%rip), %edx      # 0xc18c
movl %edx, %r10d
imull %r9d, %r10d
leal (%r10,%r8), %eax
incl %eax
movslq %eax, %r11
cmpl %esi, (%rcx,%r11,4)
jne 0x4b8c
movq 0x20(%rdi), %r13
movl 0x1028(%rdi), %eax
testl %eax, %eax
je 0x4a43
movl (%r13,%r11,4), %ebp
xorl %r14d, %r14d
movslq %r14d, %r11
movq 0x28(%rdi,%r11,8), %rbx
cmpl %ebp, (%rbx)
je 0x4a45
incl %r14d
cmpl %r14d, %eax
jne 0x4a2f
xorl %ebx, %ebx
cmpl $0x1, 0xc(%rbx)
jne 0x4b8c
movzwl 0x410(%rbx), %eax
movl %eax, %r14d
shrl $0x8, %r14d
movzbl %al, %r15d
movl %edx, %r12d
imull %r15d, %r12d
leal (%r12,%r14), %r11d
incl %r11d
movslq %r11d, %r11
cmpl %esi, (%rcx,%r11,4)
jne 0x4ab7
movl (%r13,%r11,4), %ebp
cmpl (%rbx), %ebp
je 0x4ab7
movq %r13, -0x8(%rsp)
movq 0x28(%rdi), %r13
cmpl %ebp, (%r13)
je 0x4aa7
movl $0x1, %r11d
movslq %r11d, %r11
movq 0x28(%rdi,%r11,8), %r13
incl %r11d
cmpl %ebp, (%r13)
jne 0x4a96
cmpl $0x2, 0xc(%r13)
movq -0x8(%rsp), %r13
jg 0x4fd9
addl %r14d, %r12d
decl %r12d
movslq %r12d, %r11
cmpl %esi, (%rcx,%r11,4)
jne 0x4afc
movl (%r13,%r11,4), %ebp
cmpl (%rbx), %ebp
je 0x4afc
movq 0x28(%rdi), %r12
cmpl %ebp, (%r12)
je 0x4af0
movl $0x1, %r11d
movslq %r11d, %r11
movq 0x28(%rdi,%r11,8), %r12
incl %r11d
cmpl %ebp, (%r12)
jne 0x4adf
cmpl $0x2, 0xc(%r12)
jg 0x4fd9
leal 0x1(%r15), %r11d
imull %edx, %r11d
addl %r14d, %r11d
movslq %r11d, %r11
cmpl %esi, (%rcx,%r11,4)
jne 0x4b46
movl (%r13,%r11,4), %ebp
cmpl (%rbx), %ebp
je 0x4b46
movq 0x28(%rdi), %r12
cmpl %ebp, (%r12)
je 0x4b3a
movl $0x1, %r11d
movslq %r11d, %r11
movq 0x28(%rdi,%r11,8), %r12
incl %r11d
cmpl %ebp, (%r12)
jne 0x4b29
cmpl $0x2, 0xc(%r12)
jg 0x4fd9
decl %r15d
imull %edx, %r15d
addl %r14d, %r15d
movslq %r15d, %r11
cmpl %esi, (%rcx,%r11,4)
jne 0x4b8c
movl (%r13,%r11,4), %r11d
cmpl (%rbx), %r11d
je 0x4b8c
movq 0x28(%rdi), %rbx
cmpl %r11d, (%rbx)
je 0x4b82
movl $0x1, %r14d
movslq %r14d, %r14
movq 0x28(%rdi,%r14,8), %rbx
incl %r14d
cmpl %r11d, (%rbx)
jne 0x4b72
cmpl $0x2, 0xc(%rbx)
jg 0x4fd9
addl %r8d, %r10d
decl %r10d
movslq %r10d, %r11
cmpl %esi, (%rcx,%r11,4)
jne 0x4cfb
movq 0x20(%rdi), %r10
movl 0x1028(%rdi), %eax
testl %eax, %eax
je 0x4bc6
movl (%r10,%r11,4), %ebx
xorl %ebp, %ebp
movslq %ebp, %r11
movq 0x28(%rdi,%r11,8), %r11
cmpl %ebx, (%r11)
je 0x4bc9
incl %ebp
cmpl %ebp, %eax
jne 0x4bb3
xorl %r11d, %r11d
cmpl $0x1, 0xc(%r11)
jne 0x4cfb
movzwl 0x410(%r11), %eax
movl %eax, %ebx
shrl $0x8, %ebx
movzbl %al, %r14d
movl %edx, %r15d
imull %r14d, %r15d
leal (%r15,%rbx), %ebp
incl %ebp
movslq %ebp, %r12
cmpl %esi, (%rcx,%r12,4)
jne 0x4c31
movl (%r10,%r12,4), %ebp
cmpl (%r11), %ebp
je 0x4c31
movq 0x28(%rdi), %r12
cmpl %ebp, (%r12)
je 0x4c25
movl $0x1, %r13d
movslq %r13d, %r13
movq 0x28(%rdi,%r13,8), %r12
incl %r13d
cmpl %ebp, (%r12)
jne 0x4c14
cmpl $0x2, 0xc(%r12)
jg 0x4fd9
addl %ebx, %r15d
decl %r15d
movslq %r15d, %r15
cmpl %esi, (%rcx,%r15,4)
jne 0x4c73
movl (%r10,%r15,4), %ebp
cmpl (%r11), %ebp
je 0x4c73
movq 0x28(%rdi), %r15
cmpl %ebp, (%r15)
je 0x4c68
movl $0x1, %r12d
movslq %r12d, %r12
movq 0x28(%rdi,%r12,8), %r15
incl %r12d
cmpl %ebp, (%r15)
jne 0x4c58
cmpl $0x2, 0xc(%r15)
jg 0x4fd9
leal 0x1(%r14), %ebp
imull %edx, %ebp
addl %ebx, %ebp
movslq %ebp, %r15
cmpl %esi, (%rcx,%r15,4)
jne 0x4cb8
movl (%r10,%r15,4), %ebp
cmpl (%r11), %ebp
je 0x4cb8
movq 0x28(%rdi), %r15
cmpl %ebp, (%r15)
je 0x4cad
movl $0x1, %r12d
movslq %r12d, %r12
movq 0x28(%rdi,%r12,8), %r15
incl %r12d
cmpl %ebp, (%r15)
jne 0x4c9d
cmpl $0x2, 0xc(%r15)
jg 0x4fd9
decl %r14d
imull %edx, %r14d
addl %ebx, %r14d
movslq %r14d, %rbx
cmpl %esi, (%rcx,%rbx,4)
jne 0x4cfb
movl (%r10,%rbx,4), %r10d
cmpl (%r11), %r10d
je 0x4cfb
movq 0x28(%rdi), %r11
cmpl %r10d, (%r11)
je 0x4cf0
movl $0x1, %ebx
movslq %ebx, %rbx
movq 0x28(%rdi,%rbx,8), %r11
incl %ebx
cmpl %r10d, (%r11)
jne 0x4ce1
cmpl $0x2, 0xc(%r11)
jg 0x4fd9
leal 0x1(%r9), %eax
imull %edx, %eax
addl %r8d, %eax
movslq %eax, %r11
cmpl %esi, (%rcx,%r11,4)
jne 0x4e6e
movq 0x20(%rdi), %r10
movl 0x1028(%rdi), %eax
testl %eax, %eax
je 0x4d39
movl (%r10,%r11,4), %ebx
xorl %ebp, %ebp
movslq %ebp, %r11
movq 0x28(%rdi,%r11,8), %r11
cmpl %ebx, (%r11)
je 0x4d3c
incl %ebp
cmpl %ebp, %eax
jne 0x4d26
xorl %r11d, %r11d
cmpl $0x1, 0xc(%r11)
jne 0x4e6e
movzwl 0x410(%r11), %eax
movl %eax, %ebx
shrl $0x8, %ebx
movzbl %al, %r14d
movl %edx, %r15d
imull %r14d, %r15d
leal (%r15,%rbx), %ebp
incl %ebp
movslq %ebp, %r12
cmpl %esi, (%rcx,%r12,4)
jne 0x4da4
movl (%r10,%r12,4), %ebp
cmpl (%r11), %ebp
je 0x4da4
movq 0x28(%rdi), %r12
cmpl %ebp, (%r12)
je 0x4d98
movl $0x1, %r13d
movslq %r13d, %r13
movq 0x28(%rdi,%r13,8), %r12
incl %r13d
cmpl %ebp, (%r12)
jne 0x4d87
cmpl $0x2, 0xc(%r12)
jg 0x4fd9
addl %ebx, %r15d
decl %r15d
movslq %r15d, %r15
cmpl %esi, (%rcx,%r15,4)
jne 0x4de6
movl (%r10,%r15,4), %ebp
cmpl (%r11), %ebp
je 0x4de6
movq 0x28(%rdi), %r15
cmpl %ebp, (%r15)
je 0x4ddb
movl $0x1, %r12d
movslq %r12d, %r12
movq 0x28(%rdi,%r12,8), %r15
incl %r12d
cmpl %ebp, (%r15)
jne 0x4dcb
cmpl $0x2, 0xc(%r15)
jg 0x4fd9
leal 0x1(%r14), %ebp
imull %edx, %ebp
addl %ebx, %ebp
movslq %ebp, %r15
cmpl %esi, (%rcx,%r15,4)
jne 0x4e2b
movl (%r10,%r15,4), %ebp
cmpl (%r11), %ebp
je 0x4e2b
movq 0x28(%rdi), %r15
cmpl %ebp, (%r15)
je 0x4e20
movl $0x1, %r12d
movslq %r12d, %r12
movq 0x28(%rdi,%r12,8), %r15
incl %r12d
cmpl %ebp, (%r15)
jne 0x4e10
cmpl $0x2, 0xc(%r15)
jg 0x4fd9
decl %r14d
imull %edx, %r14d
addl %ebx, %r14d
movslq %r14d, %rbx
cmpl %esi, (%rcx,%rbx,4)
jne 0x4e6e
movl (%r10,%rbx,4), %r10d
cmpl (%r11), %r10d
je 0x4e6e
movq 0x28(%rdi), %r11
cmpl %r10d, (%r11)
je 0x4e63
movl $0x1, %ebx
movslq %ebx, %rbx
movq 0x28(%rdi,%rbx,8), %r11
incl %ebx
cmpl %r10d, (%r11)
jne 0x4e54
cmpl $0x2, 0xc(%r11)
jg 0x4fd9
decl %r9d
imull %edx, %r9d
addl %r8d, %r9d
movslq %r9d, %r9
cmpl %esi, (%rcx,%r9,4)
jne 0x4fd5
movq 0x20(%rdi), %r8
movl 0x1028(%rdi), %eax
testl %eax, %eax
je 0x4eaf
movl (%r8,%r9,4), %r10d
xorl %r11d, %r11d
movslq %r11d, %r9
movq 0x28(%rdi,%r9,8), %r9
cmpl %r10d, (%r9)
je 0x4eb2
incl %r11d
cmpl %r11d, %eax
jne 0x4e9a
xorl %r9d, %r9d
cmpl $0x1, 0xc(%r9)
jne 0x4fd5
movzwl 0x410(%r9), %eax
movl %eax, %r10d
shrl $0x8, %r10d
movzbl %al, %r11d
movl %edx, %ebx
imull %r11d, %ebx
leal (%rbx,%r10), %ebp
incl %ebp
movslq %ebp, %r14
cmpl %esi, (%rcx,%r14,4)
jne 0x4f18
movl (%r8,%r14,4), %ebp
cmpl (%r9), %ebp
je 0x4f18
movq 0x28(%rdi), %r14
cmpl %ebp, (%r14)
je 0x4f0d
movl $0x1, %r15d
movslq %r15d, %r15
movq 0x28(%rdi,%r15,8), %r14
incl %r15d
cmpl %ebp, (%r14)
jne 0x4efd
cmpl $0x2, 0xc(%r14)
jg 0x4fd9
addl %r10d, %ebx
decl %ebx
movslq %ebx, %rbx
cmpl %esi, (%rcx,%rbx,4)
jne 0x4f58
movl (%r8,%rbx,4), %ebx
cmpl (%r9), %ebx
je 0x4f58
movq 0x28(%rdi), %r14
cmpl %ebx, (%r14)
je 0x4f4d
movl $0x1, %r15d
movslq %r15d, %r15
movq 0x28(%rdi,%r15,8), %r14
incl %r15d
cmpl %ebx, (%r14)
jne 0x4f3d
cmpl $0x2, 0xc(%r14)
jg 0x4fd9
leal 0x1(%r11), %ebx
imull %edx, %ebx
addl %r10d, %ebx
movslq %ebx, %rbx
cmpl %esi, (%rcx,%rbx,4)
jne 0x4f99
movl (%r8,%rbx,4), %ebx
cmpl (%r9), %ebx
je 0x4f99
movq 0x28(%rdi), %r14
cmpl %ebx, (%r14)
je 0x4f92
movl $0x1, %r15d
movslq %r15d, %r15
movq 0x28(%rdi,%r15,8), %r14
incl %r15d
cmpl %ebx, (%r14)
jne 0x4f82
cmpl $0x2, 0xc(%r14)
jg 0x4fd9
decl %r11d
imull %edx, %r11d
addl %r10d, %r11d
movslq %r11d, %rdx
cmpl %esi, (%rcx,%rdx,4)
jne 0x4fd5
movl (%r8,%rdx,4), %ecx
cmpl (%r9), %ecx
je 0x4fd5
movq 0x28(%rdi), %rdx
cmpl %ecx, (%rdx)
je 0x4fcf
movl $0x1, %esi
movslq %esi, %rsi
movq 0x28(%rdi,%rsi,8), %rdx
incl %esi
cmpl %ecx, (%rdx)
jne 0x4fc1
cmpl $0x2, 0xc(%rdx)
jg 0x4fd9
movw $0x8000, %ax            # imm = 0x8000
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq