// File: /workspace/github_cpp_makefile_star2_O1/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 0x7eeb(%rip), %eax      # 0xc18c
imull %r8d, %eax
addl %ecx, %eax
cltq
movl $0x1, (%r9,%rax,4)
movq (%rdi), %rcx
movl 0x7ed2(%rip), %eax      # 0xc18c
imull %r8d, %eax
addl %ebx, %eax
incl %eax
cltq
movl (%rcx,%rax,4), %ecx
cmpl %edx, %ecx
je 0x43c7
movq %r9, %r15
movl %r8d, %r14d
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %r13
movq 0x40(%rsp), %rdx
cmpl %esi, %ecx
jne 0x4314
cmpl $0x0, (%r15,%rax,4)
jne 0x4314
leal 0x1(%rbx), %ecx
movq %rdx, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %r14d, %r8d
movq %r15, %r9
callq 0x428e
movq 0x40(%rsp), %rdx
testb %al, %al
je 0x43c7
movq (%r13), %rcx
movl 0x7e6e(%rip), %eax      # 0xc18c
imull %r14d, %eax
addl %ebx, %eax
decl %eax
cltq
movl (%rcx,%rax,4), %ecx
cmpl %ebp, %ecx
je 0x43c7
cmpl %r12d, %ecx
jne 0x4362
cmpl $0x0, (%r15,%rax,4)
jne 0x4362
leal -0x1(%rbx), %ecx
movq %rdx, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %r14d, %r8d
movq %r15, %r9
callq 0x428e
movq 0x40(%rsp), %rdx
testb %al, %al
je 0x43c7
movq (%r13), %rcx
leal 0x1(%r14), %r8d
movl 0x7e1c(%rip), %eax      # 0xc18c
imull %r8d, %eax
addl %ebx, %eax
cltq
movl (%rcx,%rax,4), %ecx
cmpl %ebp, %ecx
je 0x43c7
cmpl %r12d, %ecx
jne 0x43aa
cmpl $0x0, (%r15,%rax,4)
jne 0x43aa
movq %rdx, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
movl %ebx, %ecx
movq %r15, %r9
callq 0x428e
movq 0x40(%rsp), %rdx
testb %al, %al
je 0x43c7
movq (%r13), %rcx
leal -0x1(%r14), %r8d
movl 0x7dd4(%rip), %eax      # 0xc18c
imull %r8d, %eax
addl %ebx, %eax
cltq
movl (%rcx,%rax,4), %ecx
cmpl %ebp, %ecx
jne 0x43d8
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r12d, %ecx
jne 0x4404
cmpl $0x0, (%r15,%rax,4)
jne 0x4404
movq %rdx, (%rsp)
movq %r13, %rdi
movl %r12d, %esi
movq %rdx, %r12
movl %ebp, %edx
movl %ebx, %ecx
movq %r15, %r9
callq 0x428e
movq %r12, %rdx
testb %al, %al
je 0x43c7
shll $0x8, %ebx
orl %r14d, %ebx
movl 0x400(%rdx), %eax
movw %bx, (%rdx,%rax,2)
incl %eax
movl %eax, 0x400(%rdx)
movb $0x1, %al
jmp 0x43c9