// File: /workspace/github_cpp_makefile_star2_O1/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, %r14d
movl %edx, %r15d
movq 0x48(%rsp), %r10
movl 0x79ee(%rip), %eax      # 0xc18c
imull %ecx, %eax
addl %edx, %eax
cltq
movl $0x1, (%r8,%rax,4)
movq (%rdi), %rax
movl 0x79d6(%rip), %ecx      # 0xc18c
imull %r14d, %ecx
leal (%rcx,%r15), %edx
movslq %edx, %rdx
cmpl %esi, (%rax,%rdx,4)
jne 0x47ce
movq %r10, %rbx
jmp 0x490e
movq %r8, %r12
movl %esi, %ebp
movq %rdi, %r13
movq 0x40(%rsp), %rbx
addl %r15d, %ecx
incl %ecx
movslq %ecx, %rcx
cmpl $-0x1, (%rax,%rcx,4)
je 0x481d
cmpl $0x0, (%r12,%rcx,4)
jne 0x481d
leal 0x1(%r15), %edx
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %ecx
movq %r12, %r8
movq %r9, (%rsp)
movq (%rsp), %r9
pushq %r10
pushq %rbx
callq 0x4782
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rcx
movl 0x7965(%rip), %eax      # 0xc18c
imull %r14d, %eax
addl %r15d, %eax
decl %eax
cltq
cmpl $-0x1, (%rcx,%rax,4)
je 0x486c
cmpl $0x0, (%r12,%rax,4)
jne 0x486c
leal -0x1(%r15), %edx
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %ecx
movq %r12, %r8
movq %r9, (%rsp)
movq (%rsp), %r9
pushq %r10
pushq %rbx
callq 0x4782
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rdx
leal 0x1(%r14), %ecx
movl 0x7912(%rip), %eax      # 0xc18c
imull %ecx, %eax
addl %r15d, %eax
cltq
cmpl $-0x1, (%rdx,%rax,4)
je 0x48b8
cmpl $0x0, (%r12,%rax,4)
jne 0x48b8
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
movq %r12, %r8
movq %r9, (%rsp)
movq (%rsp), %r9
pushq %r10
pushq %rbx
callq 0x4782
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rdx
leal -0x1(%r14), %ecx
movl 0x78c6(%rip), %eax      # 0xc18c
imull %ecx, %eax
addl %r15d, %eax
cltq
cmpl $-0x1, (%rdx,%rax,4)
je 0x48f8
cmpl $0x0, (%r12,%rax,4)
jne 0x48f8
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
movq %r12, %r8
movq %r9, %r12
pushq %r10
pushq %rbx
callq 0x4782
movq %r12, %r9
addq $0x10, %rsp
imull 0x788c(%rip), %r14d     # 0xc18c
addl %r15d, %r14d
movslq %r14d, %rax
movl $0x1, (%r9,%rax,4)
incl (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop