// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r15d
movl %edx, %r14d
movl %esi, %ebp
movq 0x48(%rsp), %r10
movl 0x79f0(%rip), %eax      # 0xc18c
imull %ecx, %eax
addl %edx, %eax
cltq
movl $0x1, (%r8,%rax,4)
movq (%rdi), %rdx
movl 0x79d8(%rip), %eax      # 0xc18c
movl %eax, %ecx
imull %r15d, %ecx
leal (%rcx,%r14), %esi
movslq %esi, %rsi
cmpl %ebp, (%rdx,%rsi,4)
jne 0x47ce
movq %r10, %rbx
jmp 0x4917
movq %r8, %r12
movq %rdi, %r13
movq 0x40(%rsp), %rbx
leal (%rcx,%r14), %esi
incl %esi
movslq %esi, %rsi
cmpl $-0x1, (%rdx,%rsi,4)
je 0x482c
cmpl $0x0, (%r12,%rsi,4)
jne 0x482c
leal 0x1(%r14), %edx
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %ecx
movq %r12, %r8
movq %r9, (%rsp)
movq (%rsp), %r9
pushq %r10
pushq %rbx
callq 0x477e
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rdx
movl 0x7966(%rip), %eax      # 0xc18c
movl %eax, %ecx
imull %r15d, %ecx
addl %r14d, %ecx
decl %ecx
movslq %ecx, %rcx
cmpl $-0x1, (%rdx,%rcx,4)
je 0x4878
cmpl $0x0, (%r12,%rcx,4)
jne 0x4878
leal -0x1(%r14), %edx
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %ecx
movq %r12, %r8
movq %r9, (%rsp)
movq (%rsp), %r9
pushq %r10
pushq %rbx
callq 0x477e
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rdx
movl 0x7914(%rip), %eax      # 0xc18c
leal 0x1(%r15), %ecx
movl %eax, %esi
imull %ecx, %esi
addl %r14d, %esi
movslq %esi, %rsi
cmpl $-0x1, (%rdx,%rsi,4)
je 0x48c7
cmpl $0x0, (%r12,%rsi,4)
jne 0x48c7
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r12, %r8
movq %r9, (%rsp)
movq (%rsp), %r9
pushq %r10
pushq %rbx
callq 0x477e
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rdx
movl 0x78c5(%rip), %eax      # 0xc18c
leal -0x1(%r15), %ecx
movl %eax, %esi
imull %ecx, %esi
addl %r14d, %esi
movslq %esi, %rsi
cmpl $-0x1, (%rdx,%rsi,4)
je 0x4906
cmpl $0x0, (%r12,%rsi,4)
jne 0x4906
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r12, %r8
movq %r9, %r12
pushq %r10
pushq %rbx
callq 0x477e
movq %r12, %r9
addq $0x10, %rsp
movl 0x7886(%rip), %eax      # 0xc18c
imull %r15d, %eax
addl %r14d, %eax
cltq
movl $0x1, (%r9,%rax,4)
incl (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq