// File: macfergus[P]baduk/cppsrc/baduk/agent.cpp
// Function: baduk::RandomBot::selectMove(baduk::GameState const&)
Move RandomBot::selectMove(GameState const& game_state) {
    thread_local static std::vector<Point> candidates;
    Board const& board = game_state.board();

    candidates.reserve(board.numRows() * board.numCols());
    candidates.clear();

    for (unsigned int r = 0; r < board.numRows(); ++r) {
        for (unsigned int c = 0; c < board.numCols(); ++c) {
            const Point candidate(r, c);
            if (game_state.isMoveLegal(Play(candidate)) &&
                    !isPointAnEye(
                        board, candidate, game_state.nextPlayer())) {
                assert(board.isEmpty(candidate));
                candidates.push_back(candidate);
            }
        }
    }

    if (candidates.empty()) {
        return Pass();
    }
    std::uniform_int_distribution<unsigned int> dist(0, candidates.size() - 1);
    return candidates[dist(rng_)];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movb %fs:-0x8, %al
cmpb $0x0, %al
jne 0xff26
movq %fs:0x0, %rax
leaq -0x20(%rax), %rdi
movq %rdi, -0x88(%rbp)
callq 0x10290
movq -0x88(%rbp), %rsi
leaq 0x4af(%rip), %rdi       # 0x103c0
leaq 0x432f8(%rip), %rdx     # 0x53210
callq 0x3360
movb $0x1, %fs:-0x8
movq -0x20(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, -0x28(%rbp)
movq %fs:0x0, %rax
leaq -0x20(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rdi
callq 0xb6a0
movl %eax, -0x8c(%rbp)
movq -0x28(%rbp), %rdi
callq 0xb6c0
movq -0x98(%rbp), %rdi
movl %eax, %ecx
movl -0x8c(%rbp), %eax
imull %ecx, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x10420
movq %fs:0x0, %rax
leaq -0x20(%rax), %rdi
callq 0x10520
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0x28(%rbp), %rdi
callq 0xb6a0
movl %eax, %ecx
movl -0x9c(%rbp), %eax
cmpl %ecx, %eax
jae 0x100f3
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0xa0(%rbp)
movq -0x28(%rbp), %rdi
callq 0xb6c0
movl %eax, %ecx
movl -0xa0(%rbp), %eax
cmpl %ecx, %eax
jae 0x100e3
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
leaq -0x38(%rbp), %rdi
callq 0x9dc0
movq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x54(%rbp)
movq -0x54(%rbp), %rsi
leaq -0x4c(%rbp), %rdi
callq 0x10540
leaq -0x44(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x10560
movq -0xb0(%rbp), %rdi
movq (%rdi), %rax
leaq -0x44(%rbp), %rsi
callq *0x30(%rax)
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xa1(%rbp)
jne 0x10043
jmp 0x10072
movq -0x28(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x20(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0xb8(%rbp), %rdi
movl %eax, %edx
leaq -0x38(%rbp), %rsi
callq 0xf960
xorb $-0x1, %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x1007e
jmp 0x100d3
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rax
movq %rax, -0x5c(%rbp)
movq -0x5c(%rbp), %rsi
callq 0x3c650
testb $0x1, %al
jne 0x10099
jmp 0x1009b
jmp 0x100ba
leaq 0x33382(%rip), %rdi     # 0x43424
leaq 0x33394(%rip), %rsi     # 0x4343d
movl $0x4a, %edx
leaq 0x3339f(%rip), %rcx     # 0x43454
callq 0x3140
movq %fs:0x0, %rax
leaq -0x20(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x10590
jmp 0x100d5
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xffc3
jmp 0x100e5
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xff9a
movq %fs:0x0, %rax
leaq -0x20(%rax), %rdi
callq 0x10600
testb $0x1, %al
jne 0x1010e
jmp 0x1011d
leaq -0xc(%rbp), %rdi
leaq -0x5d(%rbp), %rsi
callq 0x10640
jmp 0x10187
movq %fs:0x0, %rax
leaq -0x20(%rax), %rdi
callq 0x10670
subq $0x1, %rax
movl %eax, %edx
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x10690
movq -0x80(%rbp), %rsi
movq %fs:0x0, %rax
leaq -0x20(%rax), %rax
movq %rax, -0xc0(%rbp)
addq $0x8, %rsi
leaq -0x68(%rbp), %rdi
callq 0x106e0
movq -0xc0(%rbp), %rdi
movl %eax, %eax
movl %eax, %esi
callq 0x106c0
movq %rax, %rsi
leaq -0xc(%rbp), %rdi
callq 0x10710
movl -0x4(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0xc(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movb -0x70(%rbp), %dl
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop