// File: /workspace/github_cpp_makefile_star2_O3/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 0x7f0d(%rip), %eax      # 0xc18c
imull %r8d, %eax
addl %ecx, %eax
cltq
movl $0x1, (%r9,%rax,4)
movq (%rdi), %rax
movl 0x7ef4(%rip), %ecx      # 0xc18c
movl %ecx, %edx
imull %r8d, %edx
leal (%rdx,%rbx), %esi
incl %esi
movslq %esi, %rsi
movl (%rax,%rsi,4), %edi
cmpl %ebp, %edi
je 0x43a9
movq %r9, %r15
movl %r8d, %r14d
movq 0x40(%rsp), %r9
cmpl %r12d, %edi
jne 0x42ff
cmpl $0x0, (%r15,%rsi,4)
jne 0x42ff
leal 0x1(%rbx), %ecx
movq %r9, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %r14d, %r8d
movq %r15, %r9
callq 0x4264
testb %al, %al
je 0x43a9
movq (%r13), %rax
movl 0x7e98(%rip), %ecx      # 0xc18c
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 0x43a9
cmpl %r12d, %esi
jne 0x434a
cmpl $0x0, (%r15,%rdx,4)
jne 0x434a
leal -0x1(%rbx), %ecx
movq %r9, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %r14d, %r8d
movq %r15, %r9
callq 0x4264
testb %al, %al
je 0x43a9
movq (%r13), %rax
movl 0x7e47(%rip), %ecx      # 0xc18c
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 0x43a9
cmpl %r12d, %esi
jne 0x4395
cmpl $0x0, (%r15,%rdx,4)
jne 0x4395
movq %r9, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %ebx, %ecx
movq %r15, %r9
callq 0x4264
testb %al, %al
je 0x43a9
movq (%r13), %rax
movl 0x7dfc(%rip), %ecx      # 0xc18c
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 0x43ba
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r12d, %eax
jne 0x43e6
cmpl $0x0, (%r15,%rcx,4)
jne 0x43e6
movq %r9, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %ebx, %ecx
movq %r9, %r12
movq %r15, %r9
callq 0x4264
movq %r12, %r9
testb %al, %al
je 0x43a9
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 0x43ab
nop