// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
xorps %xmm0, %xmm0
cmpl %edx, 0x34(%rdi)
je 0x2122d
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
movq 0x8(%rdi), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
xorps %xmm0, %xmm0
testb %al, %al
jne 0x2122d
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x28(%rax)
testb %al, %al
je 0x20e83
movq 0x8(%r14), %rax
movss 0xc(%rax), %xmm0
jmp 0x2122d
leaq 0x48(%r14), %r12
leaq 0x80(%rsp), %rdi
movl %ebx, -0x8(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rdi)
movups %xmm0, 0x14(%rdi)
movups %xmm0, 0x24(%rdi)
movups %xmm0, 0x34(%rdi)
xorl %eax, %eax
movq %rax, 0x44(%rdi)
movb $0x1, 0x5c(%rdi)
movq %rax, 0x60(%rdi)
movq %r15, %rsi
callq 0xd546
leaq 0x78(%rsp), %rsi
movq %r12, %rdi
callq 0x21fb4
movq %rax, %r13
cmpb $0x0, 0xdc(%rsp)
jne 0x20ee7
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x20ee7
callq 0x6340
testq %r13, %r13
je 0x21039
movq %r13, %rdx
subq $-0x80, %rdx
movzbl 0x3c(%r14), %r9d
movq %r14, %rdi
movq %r15, %rsi
movl %ebx, %ecx
movl $0x1, %r8d
callq 0x21306
movl %eax, %ebp
movq 0x98(%r13), %rax
incl (%rax)
movslq %ebp, %r12
incl 0x4(%rax,%r12,4)
movq 0x8(%r14), %rsi
leaq 0x120(%rsp), %rdi
movq %r15, %rdx
movl %ebp, %ecx
callq 0xe0cc
xorl %eax, %eax
leaq 0x78(%rsp), %rdi
movq %rax, 0x44(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x34(%rdi)
movups %xmm0, 0x24(%rdi)
movups %xmm0, 0x14(%rdi)
movups %xmm0, 0x4(%rdi)
movb $0x1, 0x5c(%rdi)
movq %rax, 0x60(%rdi)
leaq 0x120(%rsp), %rsi
callq 0xd546
movb 0x190(%rsp), %al
movb %al, 0xe8(%rsp)
cmpb $0x0, 0x17c(%rsp)
jne 0x20f95
movq 0x180(%rsp), %rdi
testq %rdi, %rdi
je 0x20f95
callq 0x6340
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %ebp, %edx
callq *0x48(%rax)
movss %xmm0, 0x8(%rsp)
incq %r12
movq 0x80(%r13), %r15
movq 0x98(%r13), %rax
movl (%rax,%r12,4), %ebp
movq 0x8(%r14), %rax
movss 0x8(%rax), %xmm0
movss %xmm0, 0xc(%rsp)
incl %ebx
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
movl %ebx, %edx
callq 0x20e2a
cvtsi2ss %ebp, %xmm3
mulss 0xc(%rsp), %xmm0
addss 0x8(%rsp), %xmm0
movss (%r15,%r12,4), %xmm1
movaps %xmm0, %xmm2
subss %xmm1, %xmm2
divss %xmm3, %xmm2
addss %xmm1, %xmm2
movss %xmm2, (%r15,%r12,4)
cmpb $0x0, 0xd4(%rsp)
jne 0x2122d
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x2122d
movss %xmm0, 0x8(%rsp)
callq 0x6340
jmp 0x21227
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
incl %eax
movslq %eax, %rsi
leaq 0x78(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x60(%rsp), %rdi
leaq 0x120(%rsp), %rcx
callq 0x2157a
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
incl %eax
movslq %eax, %rsi
leaq 0x78(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x48(%rsp), %rdi
leaq 0x120(%rsp), %rcx
callq 0x216f6
leaq 0x128(%rsp), %r13
movl %ebx, -0x8(%r13)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%r13)
movups %xmm0, 0x14(%r13)
movups %xmm0, 0x24(%r13)
movups %xmm0, 0x34(%r13)
xorl %eax, %eax
movq %rax, 0x44(%r13)
movb $0x1, 0x5c(%r13)
movq %rax, 0x60(%r13)
movq %r13, %rdi
movq %r15, %rsi
callq 0xd546
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x2186a
movl 0x120(%rsp), %eax
leaq 0x80(%rsp), %rdi
movl %eax, -0x8(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rdi)
movups %xmm0, 0x14(%rdi)
movups %xmm0, 0x24(%rdi)
movups %xmm0, 0x34(%rdi)
xorl %eax, %eax
movq %rax, 0x44(%rdi)
movb $0x1, 0x5c(%rdi)
movq %rax, 0x60(%rdi)
movq %r13, %rsi
callq 0xd546
movaps 0x10(%rsp), %xmm0
leaq 0x78(%rsp), %rsi
movups %xmm0, 0x78(%rsi)
movq 0x20(%rsp), %rax
movq %rax, 0x88(%rsi)
xorps %xmm1, %xmm1
movaps %xmm1, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movups 0x28(%rsp), %xmm0
movups %xmm0, 0x90(%rsi)
movq 0x38(%rsp), %rcx
movq %rcx, 0xa0(%rsi)
movups %xmm1, 0x28(%rsp)
movq %rax, 0x38(%rsp)
movq %r12, %rdi
callq 0x21a3a
movq 0x108(%rsp), %rdi
testq %rdi, %rdi
je 0x21188
callq 0x6260
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x2119a
callq 0x6260
cmpb $0x0, 0xdc(%rsp)
jne 0x211b6
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x211b6
callq 0x6340
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x211c5
callq 0x6260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x211d4
callq 0x6260
cmpb $0x0, 0x184(%rsp)
jne 0x211f0
movq 0x188(%rsp), %rdi
testq %rdi, %rdi
je 0x211f0
callq 0x6340
movq %r14, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x218e0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
movss %xmm0, 0x8(%rsp)
je 0x21218
callq 0x6260
movss 0x8(%rsp), %xmm0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x2122d
callq 0x6260
movss 0x8(%rsp), %xmm0
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x21280
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x218a6
jmp 0x21253
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x20e08
jmp 0x21262
movq %rax, %rbx
cmpb $0x0, 0x184(%rsp)
jne 0x21283
movq 0x188(%rsp), %rdi
testq %rdi, %rdi
je 0x21283
callq 0x6340
jmp 0x21283
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x21299
callq 0x6260
jmp 0x21299
jmp 0x21296
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x212fe
callq 0x6260
jmp 0x212fe
movq %rax, %rbx
jmp 0x212fe
jmp 0x212b1
movq %rax, %rbx
cmpb $0x0, 0xd4(%rsp)
jne 0x212fe
movq 0xd8(%rsp), %rdi
jmp 0x212f4
movq %rax, %rbx
cmpb $0x0, 0x17c(%rsp)
jne 0x212fe
movq 0x180(%rsp), %rdi
jmp 0x212f4
movq %rax, %rbx
cmpb $0x0, 0xdc(%rsp)
jne 0x212fe
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x212fe
callq 0x6340
movq %rbx, %rdi
callq 0x6410