// File: /workspace/github_cpp_makefile_star2_O1/bonetblai[P]mdp-engine/ctp3/../engine/uct.h
// Function: Online::Policy::UCT::uct_t<state_t>::select_action(state_t const&, Online::Policy::UCT::data_t const&, int, bool, bool) const
Problem::action_t select_action(const T &state,
                                    const data_t &data,
                                    int depth,
                                    bool add_bonus,
                                    bool random_ties) const {
        float log_ns = logf(data.counts_[0]);
        std::vector<Problem::action_t> best_actions;
        int nactions = problem_.number_actions(state);
        float best_value = std::numeric_limits<float>::max();

        best_actions.reserve(random_ties ? nactions : 1);
        for( Problem::action_t a = 0; a < nactions; ++a ) {
            if( problem_.applicable(state, a) ) {
                // if this action has never been taken in this node, select it
                if( data.counts_[1+a] == 0 ) {
                    return a;
                }

                // compute score of action adding bonus (if applicable)
                assert(data.counts_[0] > 0);
                float par = parameter_ == 0 ? -data.values_[1+a] : parameter_;
                float bonus = add_bonus ? par * sqrtf(2 * log_ns / data.counts_[1+a]) : 0;
                float value = data.values_[1+a] + bonus;

                // update best action so far
                if( value <= best_value ) {
                    if( value < best_value ) {
                        best_value = value;
                        best_actions.clear();
                    }
                    if( random_ties || best_actions.empty() )
                        best_actions.push_back(a);
                }
            }
        }
        assert(!best_actions.empty());
        return best_actions[Random::random(best_actions.size())];
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %ebx
movl %r8d, 0x34(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq 0x18(%rdx), %rax
cvtsi2ssl (%rax), %xmm0
callq 0x6450
movss %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x8(%r12), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movl %eax, %r13d
cltq
testb %bl, %bl
movl $0x1, %esi
cmovneq %rax, %rsi
leaq 0x10(%rsp), %rdi
callq 0xd076
movl $0x0, 0x4(%rsp)
testl %r13d, %r13d
setg %bpl
jle 0x214a2
movl %ebx, 0x30(%rsp)
movss 0x8(%rsp), %xmm0
addss %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
xorl %edx, %edx
movss 0xbc70(%rip), %xmm0     # 0x2d014
movss %xmm0, 0xc(%rsp)
movq 0x8(%r12), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x30(%rax)
testb %al, %al
je 0x21489
movl 0x4(%rsp), %ebx
movslq %ebx, %rax
movq 0x18(%r14), %rdx
movl 0x4(%rdx,%rax,4), %ecx
testl %ecx, %ecx
je 0x214a2
cmpl $0x0, (%rdx)
jle 0x214fc
movss 0x38(%r12), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jne 0x213ff
movq (%r14), %rdx
movss 0x4(%rdx,%rax,4), %xmm0
xorps 0xbc41(%rip), %xmm0     # 0x2d040
cmpb $0x0, 0x34(%rsp)
je 0x21425
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
movss 0x8(%rsp), %xmm2
divss %xmm1, %xmm2
xorps %xmm1, %xmm1
sqrtss %xmm2, %xmm1
mulss %xmm1, %xmm0
movaps %xmm0, %xmm1
movq (%r14), %rcx
addss 0x4(%rcx,%rax,4), %xmm1
ucomiss 0xc(%rsp), %xmm1
ja 0x21489
jae 0x2144e
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x21448
movq %rax, 0x18(%rsp)
movss %xmm1, 0xc(%rsp)
cmpb $0x0, 0x30(%rsp)
jne 0x21461
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
jne 0x21489
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2147a
movl %ebx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x21489
leaq 0x10(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0xb4a0
movl 0x4(%rsp), %edx
incl %edx
movl %edx, 0x4(%rsp)
cmpl %r13d, %edx
setl %bpl
jl 0x213aa
jmp 0x214a2
testb $0x1, %bpl
jne 0x214dc
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rbx
cmpq %rbx, %rax
je 0x2151b
subq %rax, %rbx
shrq $0x2, %rbx
cmpl $0x1, %ebx
je 0x214d2
testl %ebx, %ebx
je 0x2153a
callq 0x6200
xorl %edx, %edx
divl %ebx
jmp 0x214d4
xorl %edx, %edx
movq 0x10(%rsp), %rax
movl (%rax,%rdx,4), %ebx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x214eb
callq 0x6260
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd1ee(%rip), %rdi      # 0x2e6f1
leaq 0xd0ab(%rip), %rsi      # 0x2e5b5
leaq 0xd1f4(%rip), %rcx      # 0x2e705
movl $0x12c, %edx            # imm = 0x12C
callq 0x61c0
leaq 0xd268(%rip), %rdi      # 0x2e78a
leaq 0xd08c(%rip), %rsi      # 0x2e5b5
leaq 0xd1d5(%rip), %rcx      # 0x2e705
movl $0x13c, %edx            # imm = 0x13C
callq 0x61c0
leaq 0xc0df(%rip), %rdi      # 0x2d620
leaq 0xc0e0(%rip), %rsi      # 0x2d628
leaq 0xc0ec(%rip), %rcx      # 0x2d63b
movl $0x3a, %edx
callq 0x61c0
jmp 0x2155f
jmp 0x2155f
jmp 0x2155f
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x21571
callq 0x6260
movq %rbx, %rdi
callq 0x6410
nop