// File: /workspace/github_cpp_makefile_star2_O2/jeffreyan11[P]go-engine/board.cpp
// Function: Board::getLocalMoves(unsigned short)
MoveList Board::getLocalMoves(Move m) {
    MoveList localMoves;

    if (m == MOVE_PASS)
        return localMoves;
    int x = getX(m);
    int y = getY(m);
    assert(pieces[index(x, y)] != EMPTY);

    Chain *node = nullptr;
    searchChainsByID(node, chainID[index(x, y)]);
    for (int i = 0; i < node->liberties; i++)
        localMoves.add(node->libertyList[i]);

    if (chainID[index(x+1, y)]
     && chainID[index(x+1, y)] != chainID[index(x, y)]) {
        node = nullptr;
        searchChainsByID(node, chainID[index(x+1, y)]);
        for (int i = 0; i < node->liberties; i++)
            localMoves.add(node->libertyList[i]);
    }

    if (chainID[index(x-1, y)]
     && chainID[index(x-1, y)] != chainID[index(x, y)]
     && chainID[index(x-1, y)] != chainID[index(x+1, y)]) {
        node = nullptr;
        searchChainsByID(node, chainID[index(x-1, y)]);
        for (int i = 0; i < node->liberties; i++)
            localMoves.add(node->libertyList[i]);
    }

    if (chainID[index(x, y+1)]
     && chainID[index(x, y+1)] != chainID[index(x, y)]
     && chainID[index(x, y+1)] != chainID[index(x+1, y)]
     && chainID[index(x, y+1)] != chainID[index(x-1, y)]) {
        node = nullptr;
        searchChainsByID(node, chainID[index(x, y+1)]);
        for (int i = 0; i < node->liberties; i++)
            localMoves.add(node->libertyList[i]);
    }

    if (chainID[index(x, y-1)]
     && chainID[index(x, y-1)] != chainID[index(x, y)]
     && chainID[index(x, y-1)] != chainID[index(x+1, y)]
     && chainID[index(x, y-1)] != chainID[index(x-1, y)]
     && chainID[index(x, y-1)] != chainID[index(x, y+1)]) {
        node = nullptr;
        searchChainsByID(node, chainID[index(x, y-1)]);
        for (int i = 0; i < node->liberties; i++)
            localMoves.add(node->libertyList[i]);
    }

    return localMoves;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
andl $0x0, 0x400(%rdi)
cmpl $0x8000, %edx           # imm = 0x8000
je 0x4e4d
movq %rsi, %r14
movzwl %dx, %r13d
movq %rsp, %r15
andq $0x0, (%r15)
shrl $0x8, %r13d
movzbl %dl, %ebp
movq 0x20(%rsi), %rax
movl 0x65b3(%rip), %ecx      # 0xb174
imull %ebp, %ecx
addl %r13d, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq %rsi, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
movl 0xc(%rax), %ecx
xorl %r12d, %r12d
testl %ecx, %ecx
cmovlel %r12d, %ecx
cmpq %r12, %rcx
je 0x4bff
movzwl 0x410(%rax,%r12,2), %edx
movw %dx, (%rbx,%r12,2)
incq %r12
jmp 0x4be7
movl %r12d, 0x400(%rbx)
movq 0x20(%r14), %rax
movl 0x6564(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %ebp, %esi
leal (%rsi,%r13), %edx
incl %edx
movslq %edx, %rdx
movl (%rax,%rdx,4), %edx
testl %edx, %edx
je 0x4c83
leal (%rsi,%r13), %edi
movslq %edi, %rdi
cmpl (%rax,%rdi,4), %edx
je 0x4c83
movq %rsp, %r15
andq $0x0, (%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rax
movl 0xc(%rax), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
addl %ecx, %ecx
cmpq %rdx, %rcx
je 0x4c6d
movzwl 0x410(%rax,%rdx), %esi
movw %si, (%rbx,%r12,2)
addq $0x2, %rdx
incq %r12
jmp 0x4c52
movl %r12d, 0x400(%rbx)
movq 0x20(%r14), %rax
movl 0x64f6(%rip), %ecx      # 0xb174
movl %ecx, %esi
imull %ebp, %esi
leal 0x1(%r13), %r8d
leal (%rsi,%r13), %edx
decl %edx
movslq %edx, %rdx
movl (%rax,%rdx,4), %edx
testl %edx, %edx
je 0x4d0c
leal (%rsi,%r13), %edi
movslq %edi, %rdi
cmpl (%rax,%rdi,4), %edx
je 0x4d0c
addl %r8d, %esi
movslq %esi, %rsi
cmpl (%rax,%rsi,4), %edx
je 0x4d0c
movq %r8, 0x8(%rsp)
movq %rsp, %r15
andq $0x0, (%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rcx
movl 0xc(%rcx), %edx
xorl %eax, %eax
testl %edx, %edx
cmovlel %eax, %edx
movl %r12d, %esi
cmpq %rax, %rdx
je 0x4cf3
leaq (%rsi,%rax), %rdi
movzwl 0x410(%rcx,%rax,2), %r8d
movl %edi, %edi
movw %r8w, (%rbx,%rdi,2)
incq %rax
jmp 0x4cd5
addl %eax, %r12d
movl %r12d, 0x400(%rbx)
movq 0x20(%r14), %rax
movl 0x646d(%rip), %ecx      # 0xb174
movq 0x8(%rsp), %r8
leal -0x1(%r13), %r9d
leal 0x1(%rbp), %r15d
movl %ecx, %edx
imull %r15d, %edx
addl %r13d, %edx
movslq %edx, %rdx
movl (%rax,%rdx,4), %edx
testl %edx, %edx
je 0x4dbb
movl %ecx, %esi
imull %ebp, %esi
leal (%rsi,%r13), %edi
movslq %edi, %rdi
cmpl (%rax,%rdi,4), %edx
je 0x4dbb
leal (%rsi,%r8), %edi
movslq %edi, %rdi
cmpl (%rax,%rdi,4), %edx
je 0x4dbb
addl %r9d, %esi
movslq %esi, %rsi
cmpl (%rax,%rsi,4), %edx
je 0x4dbb
movl %r9d, 0x14(%rsp)
movq %r8, 0x8(%rsp)
movq %rsp, %rsi
andq $0x0, (%rsi)
movq %r14, %rdi
callq 0x5100
movq %rsp, %rax
movq (%rax), %rcx
movl 0xc(%rcx), %edx
xorl %eax, %eax
testl %edx, %edx
cmovlel %eax, %edx
movl %r12d, %esi
cmpq %rax, %rdx
je 0x4d9d
leaq (%rsi,%rax), %rdi
movzwl 0x410(%rcx,%rax,2), %r8d
movl %edi, %edi
movw %r8w, (%rbx,%rdi,2)
incq %rax
jmp 0x4d7f
addl %eax, %r12d
movl %r12d, 0x400(%rbx)
movq 0x20(%r14), %rax
movl 0x63c3(%rip), %ecx      # 0xb174
movq 0x8(%rsp), %r8
movl 0x14(%rsp), %r9d
leal -0x1(%rbp), %edx
imull %ecx, %edx
addl %r13d, %edx
movslq %edx, %rdx
movl (%rax,%rdx,4), %edx
testl %edx, %edx
je 0x4e4d
imull %ecx, %ebp
leal (%rbp,%r13), %esi
movslq %esi, %rsi
cmpl (%rax,%rsi,4), %edx
je 0x4e4d
addl %ebp, %r8d
movslq %r8d, %rsi
cmpl (%rax,%rsi,4), %edx
je 0x4e4d
addl %r9d, %ebp
movslq %ebp, %rsi
cmpl (%rax,%rsi,4), %edx
je 0x4e4d
imull %r15d, %ecx
addl %r13d, %ecx
movslq %ecx, %rcx
cmpl (%rax,%rcx,4), %edx
je 0x4e4d
movq %rsp, %r15
andq $0x0, (%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x5100
movq (%r15), %rcx
movl 0xc(%rcx), %edx
xorl %eax, %eax
testl %edx, %edx
cmovlel %eax, %edx
movl %r12d, %esi
cmpq %rax, %rdx
je 0x4e43
leaq (%rsi,%rax), %rdi
movzwl 0x410(%rcx,%rax,2), %r8d
movl %edi, %edi
movw %r8w, (%rbx,%rdi,2)
incq %rax
jmp 0x4e25
addl %eax, %r12d
movl %r12d, 0x400(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop