// File: 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:
subq $0xb8, %rsp
movl %r8d, 0x20(%rsp)
movl %ecx, %eax
movl 0x20(%rsp), %ecx
movl %eax, 0x24(%rsp)
movq %rdx, %rax
movl 0x24(%rsp), %edx
movq %rax, 0x28(%rsp)
movq %rsi, %rax
movq 0x28(%rsp), %rsi
movq %rax, 0x30(%rsp)
movq %rdi, %r8
movq 0x30(%rsp), %rdi
movb %r9b, %al
movq %r8, 0xa8(%rsp)
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movl %edx, 0x94(%rsp)
andb $0x1, %cl
movb %cl, 0x93(%rsp)
andb $0x1, %al
movb %al, 0x92(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x98(%rsp), %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12b30
cvtsi2ssl (%rax), %xmm0
callq 0x6570
movss %xmm0, 0x8c(%rsp)
leaq 0x70(%rsp), %rdi
callq 0xe840
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0xa0(%rsp), %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, 0x40(%rsp)
jmp 0x3f72a
movl 0x40(%rsp), %eax
movl %eax, 0x6c(%rsp)
callq 0x23160
movss %xmm0, 0x58(%rsp)
testb $0x1, 0x92(%rsp)
je 0x3f751
movl 0x6c(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x3f75c
movl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x3f75c
movl 0x1c(%rsp), %eax
movslq %eax, %rsi
leaq 0x70(%rsp), %rdi
callq 0x163b0
jmp 0x3f76f
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x3f9cb
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0xa0(%rsp), %rsi
movl 0x54(%rsp), %edx
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movb %al, 0x1b(%rsp)
jmp 0x3f7a9
movb 0x1b(%rsp), %al
testb $0x1, %al
jne 0x3f7b6
jmp 0x3f9b9
movq 0x98(%rsp), %rdi
addq $0x18, %rdi
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x12b30
cmpl $0x0, (%rax)
jne 0x3f80b
movl 0x54(%rsp), %eax
movl %eax, 0xb4(%rsp)
movl $0x1, 0x50(%rsp)
jmp 0x3fa38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x70(%rsp), %rdi
callq 0xdfb0
jmp 0x3fa51
movq 0x98(%rsp), %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12b30
cmpl $0x0, (%rax)
jle 0x3f827
jmp 0x3f846
leaq 0x1ee53(%rip), %rdi     # 0x5e681
leaq 0x1ed10(%rip), %rsi     # 0x5e545
movl $0x12c, %edx            # imm = 0x12C
leaq 0x1ee54(%rip), %rcx     # 0x5e695
callq 0x6220
movq 0x38(%rsp), %rax
movss 0x38(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x3f88a
jp 0x3f88a
movq 0x98(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x424f0
movss (%rax), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x14(%rsp)
jmp 0x3f89a
movq 0x38(%rsp), %rax
movss 0x38(%rax), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x4c(%rsp)
testb $0x1, 0x93(%rsp)
je 0x3f912
movss 0x4c(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0x1d754(%rip), %xmm0    # 0x5d018
mulss 0x8c(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x98(%rsp), %rdi
addq $0x18, %rdi
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x12b30
movss 0x8(%rsp), %xmm1
movss 0xc(%rsp), %xmm0
cvtsi2ssl (%rax), %xmm2
divss %xmm2, %xmm1
sqrtss %xmm1, %xmm1
mulss %xmm1, %xmm0
movss %xmm0, 0x10(%rsp)
jmp 0x3f91d
xorps %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
jmp 0x3f91d
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x48(%rsp)
movq 0x98(%rsp), %rdi
movl 0x54(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x424f0
movss (%rax), %xmm0
addss 0x48(%rsp), %xmm0
movss %xmm0, 0x44(%rsp)
movss 0x44(%rsp), %xmm1
movss 0x58(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x3f9b7
movss 0x44(%rsp), %xmm1
movss 0x58(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3f988
movss 0x44(%rsp), %xmm0
movss %xmm0, 0x58(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x38350
testb $0x1, 0x92(%rsp)
jne 0x3f9a2
leaq 0x70(%rsp), %rdi
callq 0x1a320
testb $0x1, %al
jne 0x3f9a2
jmp 0x3f9b5
leaq 0x70(%rsp), %rdi
leaq 0x54(%rsp), %rsi
callq 0xedb0
jmp 0x3f9b3
jmp 0x3f9b5
jmp 0x3f9b7
jmp 0x3f9b9
jmp 0x3f9bb
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x3f777
leaq 0x70(%rsp), %rdi
callq 0x1a320
xorb $-0x1, %al
testb $0x1, %al
jne 0x3f9dd
jmp 0x3f9df
jmp 0x3f9fe
leaq 0x1ed34(%rip), %rdi     # 0x5e71a
leaq 0x1eb58(%rip), %rsi     # 0x5e545
movl $0x13c, %edx            # imm = 0x13C
leaq 0x1ec9c(%rip), %rcx     # 0x5e695
callq 0x6220
leaq 0x70(%rsp), %rdi
callq 0xdcb0
movl %eax, %edi
callq 0x1a370
movl %eax, 0x4(%rsp)
jmp 0x3fa15
movl 0x4(%rsp), %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x70(%rsp), %rdi
callq 0xdcf0
movl (%rax), %eax
movl %eax, 0xb4(%rsp)
movl $0x1, 0x50(%rsp)
leaq 0x70(%rsp), %rdi
callq 0xdfb0
movl 0xb4(%rsp), %eax
addq $0xb8, %rsp
retq
movq 0x60(%rsp), %rdi
callq 0x6520
nopl (%rax,%rax)