// File: jeffreyan11[P]go-engine/board.cpp
// Function: Board::getTerritory(int, int, int, int*, int*, int&, int&)
void Board::getTerritory(Player blocker, int x, int y, Stone *visited,
    Stone *territory, int &territorySize, int &boundarySize) {
    visited[index(x, y)] = 1;

    // Record the boundary of the region we are flood filling
    if (pieces[index(x, y)] == blocker) {
        boundarySize++;
        return;
    }

    Stone east = pieces[index(x+1, y)];
    // Flood fill outwards
    if (east != -1 && visited[index(x+1, y)] == 0)
        getTerritory(blocker, x+1, y, visited, territory, territorySize, boundarySize);
    // Else we are on the edge of the board

    Stone west = pieces[index(x-1, y)];
    if (west != -1 && visited[index(x-1, y)] == 0)
        getTerritory(blocker, x-1, y, visited, territory, territorySize, boundarySize);

    Stone north = pieces[index(x, y+1)];
    if (north != -1 && visited[index(x, y+1)] == 0)
        getTerritory(blocker, x, y+1, visited, territory, territorySize, boundarySize);

    Stone south = pieces[index(x, y-1)];
    if (south != -1 && visited[index(x, y-1)] == 0)
        getTerritory(blocker, x, y-1, visited, territory, territorySize, boundarySize);

    territory[index(x, y)] = 1;
    territorySize++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x8bc0
movq -0x50(%rbp), %rcx
movl %eax, %edx
movq -0x48(%rbp), %rax
movslq %edx, %rdx
movl $0x1, (%rcx,%rdx,4)
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl -0xc(%rbp), %eax
jne 0x673a
movq 0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x697e
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movl -0x10(%rbp), %edi
addl $0x1, %edi
movl -0x14(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
je 0x67bb
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x10(%rbp), %edi
addl $0x1, %edi
movl -0x14(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x67bb
movq -0x48(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
addl $0x1, %edx
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq 0x10(%rbp), %r10
movq 0x18(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x66b0
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x10(%rbp), %edi
subl $0x1, %edi
movl -0x14(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x68(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
cmpl $-0x1, -0x30(%rbp)
je 0x683c
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x10(%rbp), %edi
subl $0x1, %edi
movl -0x14(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x70(%rbp), %rax
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x683c
movq -0x48(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
subl $0x1, %edx
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq 0x10(%rbp), %r10
movq 0x18(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x66b0
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
addl $0x1, %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x78(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
cmpl $-0x1, -0x34(%rbp)
je 0x68bd
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
addl $0x1, %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x80(%rbp), %rax
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x68bd
movq -0x48(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq 0x10(%rbp), %r10
movq 0x18(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x66b0
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
subl $0x1, %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x88(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
cmpl $-0x1, -0x38(%rbp)
je 0x694a
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
subl $0x1, %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x90(%rbp), %rax
movslq %ecx, %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x694a
movq -0x48(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq 0x10(%rbp), %r10
movq 0x18(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x66b0
movq -0x28(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x10(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x8bc0
movl %eax, %ecx
movq -0x98(%rbp), %rax
movslq %ecx, %rcx
movl $0x1, (%rax,%rcx,4)
movq 0x10(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)