// File: grogers0[P]dots_and_boxes/BasicMoveDeciders.cpp
// Function: Board::decide_move_nocheap()
Edge Board::decide_move_nocheap()
{
    std::vector<Edge> take_square_moves, give_square_moves, other_moves;

    std::for_each(edge_begin(), edge_end(), [&] (Edge edge)
            {
                if (!this->is_move_valid(edge))
                    return;
                bool take_square = false, give_square = false;
                this->for_each_adjacent_node(edge, [&] (const Node &node)
                    {
                        switch (this->degree(node)) {
                            case 3: take_square = true; break;
                            case 2: give_square = true; break;
                        }
                    });
                if (take_square) {
                    take_square_moves.push_back(edge);
                } else if (give_square) {
                    give_square_moves.push_back(edge);
                } else {
                    other_moves.push_back(edge);
                }
            });

    if (!take_square_moves.empty()) {
        return take_square_moves.front();
    } else {
        int r = 0;

        int fd = open("/dev/urandom", O_RDONLY);
        read(fd, &r, sizeof(r));
        close(fd);

        if (!other_moves.empty()) {
            return other_moves[r % other_moves.size()];
        } else {
            assert(!give_square_moves.empty());
            return give_square_moves[r % give_square_moves.size()];
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x7be0
leaq -0x40(%rbp), %rdi
callq 0x7be0
leaq -0x58(%rbp), %rdi
callq 0x7be0
movq -0x130(%rbp), %rdi
callq 0x7c00
movl %edx, -0x124(%rbp)
movq %rax, -0x120(%rbp)
jmp 0x72f0
movq -0x130(%rbp), %rdi
movl -0x124(%rbp), %eax
movq -0x120(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x60(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x68(%rbp)
callq 0x7c60
movl %edx, -0x13c(%rbp)
movq %rax, -0x138(%rbp)
jmp 0x7333
movq -0x130(%rbp), %rax
movl -0x13c(%rbp), %ecx
movq -0x138(%rbp), %rdx
movq %rdx, -0xa8(%rbp)
movl %ecx, -0xa0(%rbp)
movl -0xa0(%rbp), %ecx
movl %ecx, -0x90(%rbp)
movq -0xa8(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movq %rax, -0xc8(%rbp)
leaq -0x28(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl -0x60(%rbp), %eax
movl %eax, -0xf0(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rsi
movl -0xf0(%rbp), %edx
movl -0x90(%rbp), %eax
movl %eax, -0x100(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rcx
movl -0x100(%rbp), %r8d
movups -0xc8(%rbp), %xmm0
movups -0xb8(%rbp), %xmm1
movq %rsp, %rax
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0xe8(%rbp), %rdi
callq 0x75b0
jmp 0x7405
leaq -0x28(%rbp), %rdi
callq 0x7d70
testb $0x1, %al
jne 0x745b
leaq -0x28(%rbp), %rdi
callq 0x7db0
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x10c(%rbp)
jmp 0x7573
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x7d00
leaq -0x40(%rbp), %rdi
callq 0x7d00
leaq -0x28(%rbp), %rdi
callq 0x7d00
jmp 0x759a
movl $0x0, -0x110(%rbp)
leaq 0x2f43(%rip), %rdi      # 0xa3af
xorl %esi, %esi
movb %sil, %al
callq 0x21a0
movl %eax, -0x140(%rbp)
jmp 0x747e
movl -0x140(%rbp), %eax
movl %eax, -0x114(%rbp)
movl -0x114(%rbp), %edi
leaq -0x110(%rbp), %rsi
movl $0x4, %edx
callq 0x2350
jmp 0x74a3
movl -0x114(%rbp), %edi
callq 0x2460
jmp 0x74b0
leaq -0x58(%rbp), %rdi
callq 0x7d70
testb $0x1, %al
jne 0x7500
movslq -0x110(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x7ce0
movq %rax, %rcx
movq -0x148(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rsi
leaq -0x58(%rbp), %rdi
callq 0x7cc0
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x10c(%rbp)
jmp 0x7573
leaq -0x40(%rbp), %rdi
callq 0x7d70
xorb $-0x1, %al
testb $0x1, %al
jne 0x7511
jmp 0x7513
jmp 0x7532
leaq 0x2ea2(%rip), %rdi      # 0xa3bc
leaq 0x2eb6(%rip), %rsi      # 0xa3d7
movl $0x56, %edx
leaq 0x2ec0(%rip), %rcx      # 0xa3ed
callq 0x2150
movslq -0x110(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7ce0
movq %rax, %rcx
movq -0x150(%rbp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rsi
leaq -0x40(%rbp), %rdi
callq 0x7cc0
movl (%rax), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x10c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x7d00
leaq -0x40(%rbp), %rdi
callq 0x7d00
leaq -0x28(%rbp), %rdi
callq 0x7d00
movl -0x4(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x2400
nopw %cs:(%rax,%rax)