// File: /workspace/github_cpp_makefile_star2_O1/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)
cmpl $0x0, 0x8(%rsi)
je 0x549a
movq %rsi, %r14
movq $0x0, 0x5b40(%rsp)
leaq 0x5b38(%rsp), %r15
movabsq $0x100000000, %rbp      # imm = 0x100000000
cmpl $0x0, 0xc(%r14)
je 0x547a
movq 0x5b40(%rsp), %r12
xorl %r13d, %r13d
movq %r14, %rdi
movq %r12, %rsi
callq 0xfe32
testb %al, %al
je 0x53f4
movl $0xb66, %ecx            # imm = 0xB66
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r12, %rdi
callq 0x4ff1
movl %eax, %ecx
shrl $0x8, %ecx
movl %eax, %edx
notb %dl
orb %cl, %dl
testb $0x1, %dl
je 0x541e
btl $0x8, %eax
setae %cl
orb %al, %cl
testb $0x1, %cl
jne 0x544e
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5950
jmp 0x5416
movq %r14, %rdi
movq %r12, %rsi
callq 0x10848
testl %eax, %eax
je 0x5433
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5950
movl $0x1, (%rax)
jmp 0x5467
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5950
jmp 0x5446
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5950
movl $0x0, (%rax)
jmp 0x5467
movq %r12, 0x5b38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5950
movl $0x2, (%rax)
incq %r13
movl 0xc(%r14), %eax
addq %rbp, %r12
cmpq %rax, %r13
jb 0x539c
movq 0x5b40(%rsp), %rdx
incq %rdx
movl 0x8(%r14), %eax
movq %rdx, 0x5b40(%rsp)
cmpq %rax, %rdx
jb 0x5386
movq %rbx, %rax
addq $0x5b48, %rsp           # imm = 0x5B48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x54b3
jmp 0x54b3
movq %rax, %r14
movq %rbx, %rdi
callq 0x5a8a
movq %r14, %rdi
callq 0x32b0