// File: bonetblai[P]mdp-engine/ctp3/../engine/uct.h
// Function: Online::Policy::UCT::uct_t<state_t>::search_tree(state_t const&, unsigned int) const
float search_tree(const T &s, unsigned depth) const {
#ifdef DEBUG
        std::cout << std::setw(2*depth) << "" << "search_tree(" << s << "):";
#endif

        if( (depth == horizon_) || problem_.terminal(s) ) {
#ifdef DEBUG
            std::cout << " end" << std::endl;
#endif
            return 0;
        }

        if( problem_.dead_end(s) ) {
#ifdef DEBUG
            std::cout << " dead-end" << std::endl;
#endif
            return problem_.dead_end_value();
        }

        typename hash_t<T>::iterator it = table_.find(std::make_pair(depth, s));

        if( it == table_.end() ) {
            std::vector<float> values(1 + problem_.number_actions(s), 0);
            std::vector<int> counts(1 + problem_.number_actions(s), 0);
            table_.insert(std::make_pair(std::make_pair(depth, s), data_t(values, counts)));
            float value = evaluate(s, depth);
#ifdef DEBUG
            std::cout << " insert in tree w/ value=" << value << std::endl;
#endif
            return value;
        } else {
            // select action for this node and increase counts
            Problem::action_t a = select_action(s, it->second, depth, true, random_ties_);
            ++it->second.counts_[0];
            ++it->second.counts_[1+a];

            // sample next state
            std::pair<const T, bool> p = problem_.sample(s, a);
            float cost = problem_.cost(s, a);

#ifdef DEBUG
            std::cout << " count=" << it->second.counts_[0]-1
                      << " fetch " << std::setprecision(5) << it->second.values_[1+a]
                      << " a=" << a
                      << " next=" << p.first
                      << std::endl;
#endif

            // do recursion and update value
            float &old_value = it->second.values_[1+a];
            float n = it->second.counts_[1+a];
            float new_value = cost + problem_.discount() * search_tree(p.first, 1 + depth);
            old_value += (new_value - old_value) / n;
            return new_value;
        }
    }

// Assembly:
subq $0x3f8, %rsp            # imm = 0x3F8
movq %rdi, 0x3e8(%rsp)
movq %rsi, 0x3e0(%rsp)
movl %edx, 0x3dc(%rsp)
movq 0x3e8(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movl 0x3dc(%rsp), %eax
cmpl 0x34(%rcx), %eax
je 0x3ee4a
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x3e0(%rsp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
testb $0x1, %al
jne 0x3ee4a
jmp 0x3ee5b
xorps %xmm0, %xmm0
movss %xmm0, 0x3f4(%rsp)
jmp 0x3f513
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x3e0(%rsp), %rsi
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x3ee7b
jmp 0x3ee9a
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3cbe0
movss %xmm0, 0x3f4(%rsp)
jmp 0x3f513
movq 0x88(%rsp), %rax
addq $0x48, %rax
movq %rax, 0x70(%rsp)
movq 0x3e0(%rsp), %rdx
leaq 0x358(%rsp), %rdi
movq %rdi, 0x78(%rsp)
leaq 0x3dc(%rsp), %rsi
callq 0x3fa80
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x3f540
movq %rax, 0x80(%rsp)
jmp 0x3eee6
movq 0x80(%rsp), %rax
movq %rax, 0x3d0(%rsp)
leaq 0x358(%rsp), %rdi
callq 0x3e930
movq 0x88(%rsp), %rdi
addq $0x40, %rdi
callq 0x3f630
movq %rax, 0x340(%rsp)
leaq 0x3d0(%rsp), %rdi
leaq 0x340(%rsp), %rsi
callq 0x3fac0
testb $0x1, %al
jne 0x3ef3a
jmp 0x3f27b
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x3e0(%rsp), %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
incl %eax
cltq
movq %rax, 0x60(%rsp)
movl $0x0, 0x324(%rsp)
leaq 0x323(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x3fae0
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rcx
leaq 0x328(%rsp), %rdi
leaq 0x324(%rsp), %rdx
callq 0x3faf0
jmp 0x3ef9e
leaq 0x323(%rsp), %rdi
callq 0x3fb70
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x3e0(%rsp), %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movl %eax, 0x5c(%rsp)
jmp 0x3efce
movl 0x5c(%rsp), %eax
incl %eax
cltq
movq %rax, 0x48(%rsp)
movl $0x0, 0x304(%rsp)
leaq 0x303(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x3fb80
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rcx
leaq 0x308(%rsp), %rdi
leaq 0x304(%rsp), %rdx
callq 0x3fb90
jmp 0x3f019
leaq 0x303(%rsp), %rdi
callq 0x3fc10
movq 0x88(%rsp), %rax
addq $0x48, %rax
movq %rax, 0x40(%rsp)
movq 0x3e0(%rsp), %rdx
leaq 0x1e0(%rsp), %rdi
leaq 0x3dc(%rsp), %rsi
callq 0x3fa80
jmp 0x3f056
leaq 0x1b0(%rsp), %rdi
leaq 0x328(%rsp), %rsi
leaq 0x308(%rsp), %rdx
callq 0x3fcb0
jmp 0x3f075
leaq 0x258(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
leaq 0x1b0(%rsp), %rdx
callq 0x3fc70
jmp 0x3f094
movq 0x40(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x3fc20
movb %dl, 0x37(%rsp)
movq %rax, 0x38(%rsp)
jmp 0x3f0b1
movb 0x37(%rsp), %al
movq 0x38(%rsp), %rcx
movq %rcx, 0x1a0(%rsp)
movb %al, 0x1a8(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x3fd20
leaq 0x1b0(%rsp), %rdi
callq 0x3e900
leaq 0x1e0(%rsp), %rdi
callq 0x3e930
movq 0x88(%rsp), %rdi
movq 0x3e0(%rsp), %rsi
movl 0x3dc(%rsp), %edx
callq 0x3fd50
movss %xmm0, 0x30(%rsp)
jmp 0x3f114
movss 0x30(%rsp), %xmm0
movss %xmm0, 0x19c(%rsp)
movss 0x19c(%rsp), %xmm0
movss %xmm0, 0x3f4(%rsp)
leaq 0x308(%rsp), %rdi
callq 0xdfb0
leaq 0x328(%rsp), %rdi
callq 0x3e950
jmp 0x3f513
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x358(%rsp), %rdi
callq 0x3e930
jmp 0x3f524
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x323(%rsp), %rdi
callq 0x3fb70
jmp 0x3f524
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x3f269
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x303(%rsp), %rdi
callq 0x3fc10
jmp 0x3f269
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x3f25c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x3f24f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x3f242
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x258(%rsp), %rdi
callq 0x3fd20
leaq 0x1b0(%rsp), %rdi
callq 0x3e900
leaq 0x1e0(%rsp), %rdi
callq 0x3e930
leaq 0x308(%rsp), %rdi
callq 0xdfb0
leaq 0x328(%rsp), %rdi
callq 0x3e950
jmp 0x3f524
movq 0x3e0(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x3d0(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x3fa60
movq 0x18(%rsp), %rsi
movq 0x88(%rsp), %rdi
movq %rax, %rdx
addq $0x78, %rdx
movl 0x3dc(%rsp), %ecx
movzbl 0x3c(%rdi), %r9d
andl $0x1, %r9d
movl $0x1, %r8d
callq 0x3f660
movq 0x20(%rsp), %rdi
movl %eax, 0x198(%rsp)
callq 0x3fa60
movq %rax, %rdi
addq $0x90, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xdcf0
movq 0x20(%rsp), %rdi
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
callq 0x3fa60
movq %rax, %rdi
addq $0x90, %rdi
movl 0x198(%rsp), %eax
incl %eax
movslq %eax, %rsi
callq 0xdcf0
movq %rax, %rcx
movq 0x88(%rsp), %rax
movl (%rcx), %edx
incl %edx
movl %edx, (%rcx)
movq 0x8(%rax), %rsi
movq 0x3e0(%rsp), %rdx
movl 0x198(%rsp), %ecx
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x19da0
movq 0x28(%rsp), %rsi
leaq 0x120(%rsp), %rdi
callq 0x3fdf0
jmp 0x3f362
leaq 0xa8(%rsp), %rdi
callq 0x19f70
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x3e0(%rsp), %rsi
movl 0x198(%rsp), %edx
movq (%rdi), %rax
movq 0x48(%rax), %rax
callq *%rax
movss %xmm0, 0x14(%rsp)
jmp 0x3f39b
movss 0x14(%rsp), %xmm0
movss %xmm0, 0xa4(%rsp)
leaq 0x3d0(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x3fa60
movq %rax, %rdi
addq $0x78, %rdi
movl 0x198(%rsp), %eax
incl %eax
movslq %eax, %rsi
callq 0x3fe30
movq (%rsp), %rdi
movq %rax, 0x98(%rsp)
callq 0x3fa60
movq %rax, %rdi
addq $0x90, %rdi
movl 0x198(%rsp), %eax
incl %eax
movslq %eax, %rsi
callq 0xdcf0
movq %rax, %rcx
movq 0x88(%rsp), %rax
cvtsi2ssl (%rcx), %xmm0
movss %xmm0, 0x94(%rsp)
movss 0xa4(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x8(%rax), %rdi
callq 0x28980
movq 0x88(%rsp), %rdi
movss %xmm0, 0xc(%rsp)
movl 0x3dc(%rsp), %edx
incl %edx
leaq 0x120(%rsp), %rsi
callq 0x3edf0
movss %xmm0, 0x10(%rsp)
jmp 0x3f45b
movss 0x8(%rsp), %xmm0
movss 0x10(%rsp), %xmm2
movss 0xc(%rsp), %xmm1
mulss %xmm2, %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x90(%rsp)
movss 0x90(%rsp), %xmm0
movq 0x98(%rsp), %rax
subss (%rax), %xmm0
divss 0x94(%rsp), %xmm0
movq 0x98(%rsp), %rax
addss (%rax), %xmm0
movss %xmm0, (%rax)
movss 0x90(%rsp), %xmm0
movss %xmm0, 0x3f4(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x3fe50
jmp 0x3f513
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x19f70
jmp 0x3f524
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x120(%rsp), %rdi
callq 0x3fe50
jmp 0x3f524
movss 0x3f4(%rsp), %xmm0
addq $0x3f8, %rsp            # imm = 0x3F8
retq
movq 0x350(%rsp), %rdi
callq 0x6520
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)