// File: /workspace/github_cpp_makefile_star2_O2/jeffreyan11[P]go-engine/board.cpp
// Function: Board::isSurrounded(int, int, int, int, int*, GoArrayList<unsigned short>&)
bool Board::isSurrounded(Player victim, Player open, int x, int y,
    Stone *visited, MoveList &captured) {
    visited[index(x, y)] = 1;

    Stone east = pieces[index(x+1, y)];
    // If we are next to a non-blocker and non-victim, then we are not surrounded
    if (east == open)
        return false;
    // If we next to victim, we need to recursively see if the entire group
    // is surrounded
    else if (east == victim && visited[index(x+1, y)] == 0)
        if (!isSurrounded(victim, open, x+1, y, visited, captured))
            return false;
    // Else the piece is surrounded by a blocker or edge

    Stone west = pieces[index(x-1, y)];
    if (west == open)
        return false;
    else if (west == victim && visited[index(x-1, y)] == 0)
        if (!isSurrounded(victim, open, x-1, y, visited, captured))
            return false;

    Stone north = pieces[index(x, y+1)];
    if (north == open)
        return false;
    else if (north == victim && visited[index(x, y+1)] == 0)
        if (!isSurrounded(victim, open, x, y+1, visited, captured))
            return false;

    Stone south = pieces[index(x, y-1)];
    if (south == open)
        return false;
    else if (south == victim && visited[index(x, y-1)] == 0)
        if (!isSurrounded(victim, open, x, y-1, visited, captured))
            return false;

    // If we got here, we are surrounded on all four sides
    captured.add(coordToMove(x, y));
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebx
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %r13
movl 0x736f(%rip), %eax      # 0xb174
imull %r8d, %eax
addl %ecx, %eax
cltq
movl $0x1, (%r9,%rax,4)
movq (%rdi), %rax
movl 0x7356(%rip), %ecx      # 0xb174
movl %ecx, %edx
imull %r8d, %edx
leal (%rdx,%rbx), %esi
incl %esi
movslq %esi, %rsi
movl (%rax,%rsi,4), %edi
cmpl %ebp, %edi
je 0x3f2f
movq %r9, %r15
movl %r8d, %r14d
movq 0x40(%rsp), %r9
cmpl %r12d, %edi
jne 0x3e85
cmpl $0x0, (%r15,%rsi,4)
jne 0x3e85
leal 0x1(%rbx), %ecx
movq %r9, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %r14d, %r8d
movq %r15, %r9
callq 0x3dea
testb %al, %al
je 0x3f2f
movq (%r13), %rax
movl 0x72fa(%rip), %ecx      # 0xb174
movl %ecx, %edx
imull %r14d, %edx
movq 0x40(%rsp), %r9
addl %ebx, %edx
decl %edx
movslq %edx, %rdx
movl (%rax,%rdx,4), %esi
cmpl %ebp, %esi
je 0x3f2f
cmpl %r12d, %esi
jne 0x3ed0
cmpl $0x0, (%r15,%rdx,4)
jne 0x3ed0
leal -0x1(%rbx), %ecx
movq %r9, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %r14d, %r8d
movq %r15, %r9
callq 0x3dea
testb %al, %al
je 0x3f2f
movq (%r13), %rax
movl 0x72a9(%rip), %ecx      # 0xb174
movq 0x40(%rsp), %r9
leal 0x1(%r14), %r8d
movl %ecx, %edx
imull %r8d, %edx
addl %ebx, %edx
movslq %edx, %rdx
movl (%rax,%rdx,4), %esi
cmpl %ebp, %esi
je 0x3f2f
cmpl %r12d, %esi
jne 0x3f1b
cmpl $0x0, (%r15,%rdx,4)
jne 0x3f1b
movq %r9, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %ebx, %ecx
movq %r15, %r9
callq 0x3dea
testb %al, %al
je 0x3f2f
movq (%r13), %rax
movl 0x725e(%rip), %ecx      # 0xb174
movq 0x40(%rsp), %r9
leal -0x1(%r14), %r8d
imull %r8d, %ecx
addl %ebx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl %ebp, %eax
jne 0x3f40
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r12d, %eax
jne 0x3f6c
cmpl $0x0, (%r15,%rcx,4)
jne 0x3f6c
movq %r9, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %ebx, %ecx
movq %r9, %r12
movq %r15, %r9
callq 0x3dea
movq %r12, %r9
testb %al, %al
je 0x3f2f
shll $0x8, %ebx
orl %r14d, %ebx
movl 0x400(%r9), %eax
movw %bx, (%r9,%rax,2)
incl %eax
movl %eax, 0x400(%r9)
movb $0x1, %al
jmp 0x3f31
nop