// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq 0x18(%rdx), %rax
cvtsi2ssl (%rax), %xmm0
callq 0x5450
movss %xmm0, 0x4(%rsp)
andq $0x0, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x8(%r12), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movl %eax, %r13d
cltq
movl %ebx, 0x34(%rsp)
testb %bl, %bl
pushq $0x1
popq %rsi
cmovneq %rax, %rsi
leaq 0x10(%rsp), %rdi
callq 0xa3aa
movss 0x4(%rsp), %xmm0
addss %xmm0, %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x8ae6(%rip), %xmm0     # 0x20014
movss %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
movl %ebx, 0xc(%rsp)
cmpl %r13d, %ebx
jge 0x1760e
movq 0x8(%r12), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %ebx, %edx
callq *0x30(%rax)
movl 0xc(%rsp), %ebx
testb %al, %al
je 0x17607
movslq %ebx, %rax
movq 0x18(%r14), %rdx
movl 0x4(%rdx,%rax,4), %ecx
testl %ecx, %ecx
je 0x17633
cmpl $0x0, (%rdx)
jle 0x1764e
movss 0x38(%r12), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jne 0x1759a
movq (%r14), %rdx
movss 0x4(%rdx,%rax,4), %xmm0
xorps 0x8ae6(%rip), %xmm0     # 0x20080
testb %bpl, %bpl
je 0x175b8
cvtsi2ss %ecx, %xmm1
movss 0x4(%rsp), %xmm2
divss %xmm1, %xmm2
sqrtss %xmm2, %xmm1
mulss %xmm1, %xmm0
movaps %xmm0, %xmm1
movq (%r14), %rcx
addss 0x4(%rcx,%rax,4), %xmm1
ucomiss 0x8(%rsp), %xmm1
ja 0x17607
jae 0x175e1
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x175db
movq %rax, 0x18(%rsp)
movss %xmm1, 0x8(%rsp)
cmpb $0x0, 0x34(%rsp)
jne 0x175f4
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
jne 0x17607
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x8804
movl 0xc(%rsp), %ebx
incl %ebx
jmp 0x17536
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdi
cmpq %rdi, %rax
je 0x1766d
subq %rax, %rdi
shrq $0x2, %rdi
callq 0xb503
movl %eax, %eax
movq 0x10(%rsp), %rcx
movl (%rcx,%rax,4), %ebx
leaq 0x10(%rsp), %rdi
callq 0x85dc
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa019(%rip), %rdi      # 0x2166e
leaq 0x9ed6(%rip), %rsi      # 0x21532
leaq 0xa01f(%rip), %rcx      # 0x21682
movl $0x12c, %edx            # imm = 0x12C
callq 0x51b0
leaq 0xa093(%rip), %rdi      # 0x21707
leaq 0x9eb7(%rip), %rsi      # 0x21532
leaq 0xa000(%rip), %rcx      # 0x21682
movl $0x13c, %edx            # imm = 0x13C
callq 0x51b0
jmp 0x17692
jmp 0x17692
jmp 0x17692
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x85dc
movq %rbx, %rdi
callq 0x5410
nop