// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movw $0x8000, %r14w          # imm = 0x8000
cmpl $0x8000, %edx           # imm = 0x8000
je 0x4b6b
movl %esi, %ebp
movq %rdi, %rbx
movzwl %dx, %r12d
shrl $0x8, %r12d
movzbl %dl, %r13d
movq (%rdi), %rax
movl 0x6c59(%rip), %ecx      # 0xb174
imull %r13d, %ecx
leal (%r12,%rcx), %edx
incl %edx
movslq %edx, %rdx
cmpl %esi, (%rax,%rdx,4)
jne 0x46bf
leaq 0x10(%rsp), %r14
andq $0x0, (%r14)
movq 0x20(%rbx), %rax
movl (%rax,%rdx,4), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5100
movq (%r14), %rdi
cmpl $0x1, 0xc(%rdi)
movq (%rbx), %rax
movl 0x6c18(%rip), %ecx      # 0xb174
jne 0x46bb
movzwl 0x410(%rdi), %r14d
movl %r14d, %r9d
shrl $0x8, %r9d
movzbl %r14b, %r15d
movl %ecx, %esi
imull %r15d, %esi
leal (%r9,%rsi), %edx
incl %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x45cd
movq 0x20(%rbx), %r8
movl (%r8,%rdx,4), %edx
cmpl (%rdi), %edx
je 0x45cd
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6bb2(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %r15d, %esi
movq 0x8(%rsp), %r9
leal (%r9,%rsi), %edx
decl %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x461d
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x461d
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6b5c(%rip), %ecx      # 0xb174
movq 0x8(%rsp), %r9
leal 0x1(%r15), %edx
imull %ecx, %edx
addl %r9d, %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x4671
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x4671
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6b08(%rip), %ecx      # 0xb174
movq 0x8(%rsp), %r9
decl %r15d
imull %ecx, %r15d
addl %r9d, %r15d
movslq %r15d, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x46bb
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x46bb
movq %rsp, %r15
andq $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6ab9(%rip), %ecx      # 0xb174
imull %r13d, %ecx
addl %r12d, %ecx
decl %ecx
movslq %ecx, %rcx
cmpl %ebp, (%rax,%rcx,4)
jne 0x4851
leaq 0x10(%rsp), %r14
andq $0x0, (%r14)
movq 0x20(%rbx), %rax
movl (%rax,%rcx,4), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5100
movq (%r14), %rdi
cmpl $0x1, 0xc(%rdi)
jne 0x4851
movzwl 0x410(%rdi), %r14d
movl %r14d, %r9d
shrl $0x8, %r9d
movzbl %r14b, %r15d
movq (%rbx), %rax
movl 0x6a60(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %r15d, %esi
leal (%r9,%rsi), %edx
incl %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x476c
movq 0x20(%rbx), %r8
movl (%r8,%rdx,4), %edx
cmpl (%rdi), %edx
je 0x476c
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6a13(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %r15d, %esi
movq 0x8(%rsp), %r9
leal (%r9,%rsi), %edx
decl %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x47bc
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x47bc
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x69bd(%rip), %ecx      # 0xb174
movq 0x8(%rsp), %r9
leal 0x1(%r15), %edx
imull %ecx, %edx
addl %r9d, %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x4810
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x4810
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6969(%rip), %ecx      # 0xb174
movq 0x8(%rsp), %r9
decl %r15d
imull %ecx, %r15d
addl %r9d, %r15d
movslq %r15d, %rcx
cmpl %ebp, (%rax,%rcx,4)
jne 0x4851
movq 0x20(%rbx), %rax
movl (%rax,%rcx,4), %edx
movq 0x10(%rsp), %rax
cmpl (%rax), %edx
je 0x4851
movq %rsp, %r15
andq $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rcx
leal 0x1(%r13), %eax
imull 0x6915(%rip), %eax      # 0xb174
addl %r12d, %eax
cltq
cmpl %ebp, (%rcx,%rax,4)
jne 0x49ee
leaq 0x10(%rsp), %r14
andq $0x0, (%r14)
movq 0x20(%rbx), %rcx
movl (%rcx,%rax,4), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5100
movq (%r14), %rdi
cmpl $0x1, 0xc(%rdi)
jne 0x49ee
movzwl 0x410(%rdi), %r14d
movl %r14d, %r9d
shrl $0x8, %r9d
movzbl %r14b, %r15d
movq (%rbx), %rax
movl 0x68c3(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %r15d, %esi
leal (%r9,%rsi), %edx
incl %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x4909
movq 0x20(%rbx), %r8
movl (%r8,%rdx,4), %edx
cmpl (%rdi), %edx
je 0x4909
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6876(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %r15d, %esi
movq 0x8(%rsp), %r9
leal (%r9,%rsi), %edx
decl %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x4959
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x4959
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6820(%rip), %ecx      # 0xb174
movq 0x8(%rsp), %r9
leal 0x1(%r15), %edx
imull %ecx, %edx
addl %r9d, %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x49ad
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x49ad
movq %r9, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %rbx, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x67cc(%rip), %ecx      # 0xb174
movq 0x8(%rsp), %r9
decl %r15d
imull %ecx, %r15d
addl %r9d, %r15d
movslq %r15d, %rcx
cmpl %ebp, (%rax,%rcx,4)
jne 0x49ee
movq 0x20(%rbx), %rax
movl (%rax,%rcx,4), %edx
movq 0x10(%rsp), %rax
cmpl (%rax), %edx
je 0x49ee
movq %rsp, %r15
andq $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rcx
decl %r13d
imull 0x6778(%rip), %r13d     # 0xb174
addl %r12d, %r13d
movslq %r13d, %rax
cmpl %ebp, (%rcx,%rax,4)
jne 0x4b66
leaq 0x10(%rsp), %r14
andq $0x0, (%r14)
movq 0x20(%rbx), %rcx
movl (%rcx,%rax,4), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5100
movq (%r14), %rdi
cmpl $0x1, 0xc(%rdi)
jne 0x4b66
movzwl 0x410(%rdi), %r14d
movl %r14d, %r12d
shrl $0x8, %r12d
movzbl %r14b, %r13d
movq (%rbx), %rax
movl 0x6725(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %r13d, %esi
leal (%r12,%rsi), %edx
incl %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x4a9d
movq 0x20(%rbx), %r8
movl (%r8,%rdx,4), %edx
cmpl (%rdi), %edx
je 0x4a9d
movq %rsp, %r15
andq $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x66dd(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %r13d, %esi
leal (%r12,%rsi), %edx
decl %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x4ae3
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x4ae3
movq %rsp, %r15
andq $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x6691(%rip), %ecx      # 0xb174
leal 0x1(%r13), %edx
imull %ecx, %edx
addl %r12d, %edx
movslq %edx, %rdx
cmpl %ebp, (%rax,%rdx,4)
jne 0x4b29
movq 0x20(%rbx), %rsi
movl (%rsi,%rdx,4), %edx
movq 0x10(%rsp), %rsi
cmpl (%rsi), %edx
je 0x4b29
movq %rsp, %r15
andq $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movq (%rbx), %rax
movl 0x664b(%rip), %ecx      # 0xb174
decl %r13d
imull %ecx, %r13d
addl %r12d, %r13d
movslq %r13d, %rcx
cmpl %ebp, (%rax,%rcx,4)
jne 0x4b66
movq 0x20(%rbx), %rax
movl (%rax,%rcx,4), %edx
movq 0x10(%rsp), %rax
cmpl (%rax), %edx
je 0x4b66
movq %rsp, %r15
andq $0x0, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
cmpl $0x2, 0xc(%rax)
jg 0x4b6b
movw $0x8000, %r14w          # imm = 0x8000
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop