// File: /workspace/github_cpp_makefile_star2_O3/macfergus[P]baduk/cppsrc/baduk/scoring.cpp
// Function: baduk::evaluateTerritory(baduk::Board const&)
TerritoryMap evaluateTerritory(Board const& board) {
    TerritoryMap tmap;

    for (unsigned int r = 0; r < board.numRows(); ++r) {
        for (unsigned int c = 0; c < board.numCols(); ++c) {
            const Point p(r, c);
            if (board.isEmpty(p)) {
                // If it is empty, figure out the surrounding stones. If
                // they are exclusively one color, it's territory. Otherwise
                // it's dame.
                const auto boundary = collectBoundary(board, p);
                if (boundary.isOnlyBlack()) {
                    tmap.set(p, PointStatus::black);
                } else if (boundary.isOnlyWhite()) {
                    tmap.set(p, PointStatus::white);
                } else {
                    tmap.set(p, PointStatus::neutral);
                }
            } else {
                // If it contains a stone, count it for that color (chinese
                // style)
                const auto stone = board.at(p);
                if (stone == Stone::black) {
                    tmap.set(p, PointStatus::black);
                } else {
                    // not empty, not black, must be white
                    tmap.set(p, PointStatus::white);
                }
            }
        }
    }

    return tmap;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5b48, %rsp           # imm = 0x5B48
movq %rdi, %rbx
leaq 0x8(%rdi), %rax
movl $0x0, 0x8(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x10(%rdi)
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movq %rcx, 0x28(%rdi)
movl 0x8(%rsi), %ecx
testl %ecx, %ecx
je 0x5485
movq %rsi, %r14
movl 0xc(%rsi), %eax
xorl %r12d, %r12d
leaq 0x5b38(%rsp), %r15
movabsq $0x100000000, %rbp      # imm = 0x100000000
testl %eax, %eax
movl $0x0, %eax
je 0x5477
movq %r12, 0x5b40(%rsp)
xorl %r13d, %r13d
movq %r14, %rdi
movq %r12, %rsi
callq 0xf80a
testb %al, %al
je 0x53e5
movl $0xb66, %ecx            # imm = 0xB66
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
callq 0x4fc9
movl %eax, %edx
shrl $0x8, %edx
movl %eax, %ecx
xorb $0x1, %cl
orb %cl, %dl
testb $0x1, %dl
je 0x540f
btl $0x8, %eax
setae %al
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x543f
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x593e
jmp 0x5407
movq %r14, %rdi
movq %r12, %rsi
callq 0x1017e
testl %eax, %eax
je 0x5424
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x593e
movl $0x1, (%rax)
jmp 0x5458
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x593e
jmp 0x5437
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x593e
movl $0x0, (%rax)
jmp 0x5458
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x593e
movl $0x2, (%rax)
incq %r13
movl 0xc(%r14), %eax
addq %rbp, %r12
cmpq %rax, %r13
jb 0x538a
movl 0x8(%r14), %ecx
movq 0x5b40(%rsp), %r12
incq %r12
movl %ecx, %edx
cmpq %rdx, %r12
jb 0x5372
movq %rbx, %rax
addq $0x5b48, %rsp           # imm = 0x5B48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x549e
jmp 0x549e
movq %rax, %r14
movq %rbx, %rdi
callq 0x5a8c
movq %r14, %rdi
callq 0x32b0