// File: /workspace/github_cpp_makefile_star2_O2/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 0x6ec6(%rip), %eax      # 0xb174
imull %ecx, %eax
addl %edx, %eax
cltq
movl $0x1, (%r8,%rax,4)
movq (%rdi), %rdx
movl 0x6eae(%rip), %eax      # 0xb174
movl %eax, %ecx
imull %r15d, %ecx
leal (%rcx,%r14), %esi
movslq %esi, %rsi
cmpl %ebp, (%rdx,%rsi,4)
jne 0x42e0
movq %r10, %rbx
jmp 0x4429
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 0x433e
cmpl $0x0, (%r12,%rsi,4)
jne 0x433e
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 0x4290
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rdx
movl 0x6e3c(%rip), %eax      # 0xb174
movl %eax, %ecx
imull %r15d, %ecx
addl %r14d, %ecx
decl %ecx
movslq %ecx, %rcx
cmpl $-0x1, (%rdx,%rcx,4)
je 0x438a
cmpl $0x0, (%r12,%rcx,4)
jne 0x438a
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 0x4290
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rdx
movl 0x6dea(%rip), %eax      # 0xb174
leal 0x1(%r15), %ecx
movl %eax, %esi
imull %ecx, %esi
addl %r14d, %esi
movslq %esi, %rsi
cmpl $-0x1, (%rdx,%rsi,4)
je 0x43d9
cmpl $0x0, (%r12,%rsi,4)
jne 0x43d9
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r12, %r8
movq %r9, (%rsp)
movq (%rsp), %r9
pushq %r10
pushq %rbx
callq 0x4290
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
addq $0x10, %rsp
movq (%r13), %rdx
movl 0x6d9b(%rip), %eax      # 0xb174
leal -0x1(%r15), %ecx
movl %eax, %esi
imull %ecx, %esi
addl %r14d, %esi
movslq %esi, %rsi
cmpl $-0x1, (%rdx,%rsi,4)
je 0x4418
cmpl $0x0, (%r12,%rsi,4)
jne 0x4418
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r12, %r8
movq %r9, %r12
pushq %r10
pushq %rbx
callq 0x4290
movq %r12, %r9
addq $0x10, %rsp
movl 0x6d5c(%rip), %eax      # 0xb174
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