// File: bonetblai[P]mdp-engine/ctp3/../engine/aot.h
// Function: Online::Policy::AOT::aot_t<state_t>::fetch_node(state_t const&, unsigned int, bool) const
std::pair<state_node_t<T>*, bool> fetch_node(const T &state, unsigned depth, bool debug = false) const {
        typename hash_t<T>::iterator it = table_.find(std::make_pair(&state, depth));
        if( it == table_.end() ) {
            if( debug ) std::cout << "fetch_node: node was NOT-FOUND" << std::endl;
            ++num_nodes_;
            state_node_t<T> *node = new state_node_t<T>(state, depth);
            table_.insert(std::make_pair(std::make_pair(&node->state_, depth),
                                         node));
            if( problem_.terminal(state) ) {
                if( debug ) std::cout << "fetch_node: node is TERMINAL" << std::endl;
                node->value_ = 0;
                node->is_goal_ = true;
            } else if( problem_.dead_end(state) ) {
                if( debug ) std::cout << "fetch_node: node is DEAD-END" << std::endl;
                node->value_ = problem_.dead_end_value();
                node->is_dead_end_ = true;
            } else {
                if( debug ) std::cout << "fetch_node: node is REGULAR" << std::endl;
                node->value_ = evaluate(state, depth);
                node->nsamples_ = leaf_nsamples_;
            }
            return std::make_pair(node, false);
        } else {
            if( debug ) std::cout << "fetch_node: node was FOUND!" << std::endl;
            bool re_evaluated = false;
            if( it->second->is_leaf() && !it->second->is_dead_end_ && !it->second->is_goal_ && (heuristic_ == 0) ) {
                // resample: throw other rollouts to get better estimation. Only done when heuristic_ == 0
                float old_val = it->second->value_;
                float new_val = old_val * it->second->nsamples_ + evaluate(state, depth);
                it->second->nsamples_ += leaf_nsamples_;
                it->second->value_ = new_val / it->second->nsamples_;
                re_evaluated = true;
            }
            return std::make_pair(it->second, re_evaluated);
        }
    }

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movb %cl, %al
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movl %edx, 0x124(%rsp)
andb $0x1, %al
movb %al, 0x123(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x40(%rsp)
addq $0x60, %rax
movq %rax, 0x38(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0x124(%rsp), %rsi
callq 0x4d5a0
movq 0x38(%rsp), %rdi
movl %edx, 0xf8(%rsp)
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x108(%rsp)
movl 0xf8(%rsp), %eax
movl %eax, 0x110(%rsp)
leaq 0x108(%rsp), %rsi
callq 0x4d570
movq 0x40(%rsp), %rdi
movq %rax, 0x118(%rsp)
addq $0x58, %rdi
callq 0x4d3a0
movq %rax, 0xe8(%rsp)
leaq 0x118(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x4d5d0
testb $0x1, %al
jne 0x4ca1f
jmp 0x4cce0
testb $0x1, 0x123(%rsp)
je 0x4ca4b
movq 0x365a0(%rip), %rdi     # 0x82fd0
leaq 0x130c6(%rip), %rsi     # 0x5fafd
callq 0x6330
movq %rax, %rdi
movq 0x36572(%rip), %rsi     # 0x82fb8
callq 0x6370
movq 0x40(%rsp), %rax
movl 0x50(%rax), %ecx
incl %ecx
movl %ecx, 0x50(%rax)
movl $0xc0, %edi
callq 0x6340
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x30(%rsp)
movq 0x128(%rsp), %rsi
movl 0x124(%rsp), %edx
callq 0x4d5f0
jmp 0x4ca83
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0xe0(%rsp)
addq $0x60, %rax
movq %rax, 0x28(%rsp)
movq 0xe0(%rsp), %rax
addq $0x18, %rax
movq %rax, 0xa0(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x124(%rsp), %rsi
callq 0x4d5a0
movl %edx, 0x98(%rsp)
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0xa8(%rsp)
movl 0x98(%rsp), %eax
movl %eax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x4d6f0
movq 0x28(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x4d6a0
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x80(%rsp)
movb %dl, 0x88(%rsp)
movq 0x8(%rax), %rdi
movq 0x128(%rsp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
testb $0x1, %al
jne 0x4cb52
jmp 0x4cbc7
testb $0x1, 0x123(%rsp)
je 0x4cba3
movq 0x3646d(%rip), %rdi     # 0x82fd0
leaq 0x12fb2(%rip), %rsi     # 0x5fb1c
callq 0x6330
movq %rax, %rdi
movq 0x3643f(%rip), %rsi     # 0x82fb8
callq 0x6370
jmp 0x4cba3
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
callq 0x6310
jmp 0x4cecd
movq 0xe0(%rsp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rax)
movq 0xe0(%rsp), %rax
movb $0x1, 0x88(%rax)
jmp 0x4cca3
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x128(%rsp), %rsi
movq (%rdi), %rax
callq *0x28(%rax)
testb $0x1, %al
jne 0x4cbe4
jmp 0x4cc3c
testb $0x1, 0x123(%rsp)
je 0x4cc10
movq 0x363db(%rip), %rdi     # 0x82fd0
leaq 0x12f3d(%rip), %rsi     # 0x5fb39
callq 0x6330
movq %rax, %rdi
movq 0x363ad(%rip), %rsi     # 0x82fb8
callq 0x6370
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3cbe0
movq 0xe0(%rsp), %rax
movss %xmm0, 0x8(%rax)
movq 0xe0(%rsp), %rax
movb $0x1, 0x89(%rax)
jmp 0x4cca1
testb $0x1, 0x123(%rsp)
je 0x4cc68
movq 0x36383(%rip), %rdi     # 0x82fd0
leaq 0x12f02(%rip), %rsi     # 0x5fb56
callq 0x6330
movq %rax, %rdi
movq 0x36355(%rip), %rsi     # 0x82fb8
callq 0x6370
movq 0x40(%rsp), %rdi
movq 0x128(%rsp), %rsi
movl 0x124(%rsp), %edx
callq 0x4d720
movq 0x40(%rsp), %rax
movq 0xe0(%rsp), %rcx
movss %xmm0, 0x8(%rcx)
movl 0x44(%rax), %ecx
movq 0xe0(%rsp), %rax
movl %ecx, 0x10(%rax)
jmp 0x4cca3
movb $0x0, 0x7f(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0x7f(%rsp), %rsi
callq 0x4d830
movb %dl, 0x70(%rsp)
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x138(%rsp)
movb 0x70(%rsp), %al
movb %al, 0x140(%rsp)
jmp 0x4ceb6
testb $0x1, 0x123(%rsp)
je 0x4cd0c
movq 0x362df(%rip), %rdi     # 0x82fd0
leaq 0x12e7a(%rip), %rsi     # 0x5fb72
callq 0x6330
movq %rax, %rdi
movq 0x362b1(%rip), %rsi     # 0x82fb8
callq 0x6370
movb $0x0, 0x67(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x4d860
movq 0x10(%rax), %rdi
callq 0x46ec0
testb $0x1, %al
jne 0x4cd30
jmp 0x4ce77
leaq 0x118(%rsp), %rdi
callq 0x4d860
movq 0x10(%rax), %rax
testb $0x1, 0x89(%rax)
jne 0x4ce77
leaq 0x118(%rsp), %rdi
callq 0x4d860
movq 0x10(%rax), %rax
testb $0x1, 0x88(%rax)
jne 0x4ce77
movq 0x40(%rsp), %rax
cmpq $0x0, 0x98(%rax)
jne 0x4ce77
leaq 0x118(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4d860
movq 0x18(%rsp), %rdi
movq 0x10(%rax), %rax
movss 0x8(%rax), %xmm0
movss %xmm0, 0x60(%rsp)
movss 0x60(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
callq 0x4d860
movss 0xc(%rsp), %xmm0
movq 0x40(%rsp), %rdi
movq 0x10(%rax), %rax
movl 0x10(%rax), %eax
cvtsi2ss %rax, %xmm1
mulss %xmm1, %xmm0
movss %xmm0, 0x10(%rsp)
movq 0x128(%rsp), %rsi
movl 0x124(%rsp), %edx
callq 0x4d720
movq 0x40(%rsp), %rax
movq 0x18(%rsp), %rdi
movaps %xmm0, %xmm1
movss 0x10(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x5c(%rsp)
movl 0x44(%rax), %eax
movl %eax, 0x14(%rsp)
callq 0x4d860
movl 0x14(%rsp), %edx
movq 0x18(%rsp), %rdi
movq 0x10(%rax), %rax
movl 0x10(%rax), %ecx
addl %edx, %ecx
movl %ecx, 0x10(%rax)
movss 0x5c(%rsp), %xmm0
movss %xmm0, 0x20(%rsp)
callq 0x4d860
movss 0x20(%rsp), %xmm0
movq 0x10(%rax), %rax
movl 0x10(%rax), %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss %xmm0, 0x24(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x4d860
movss 0x24(%rsp), %xmm0
movq 0x10(%rax), %rax
movss %xmm0, 0x8(%rax)
movb $0x1, 0x67(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x4d860
movq %rax, %rdi
addq $0x10, %rdi
leaq 0x67(%rsp), %rsi
callq 0x4d880
movb %dl, 0x50(%rsp)
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x138(%rsp)
movb 0x50(%rsp), %al
movb %al, 0x140(%rsp)
movq 0x138(%rsp), %rax
movb 0x140(%rsp), %dl
addq $0x148, %rsp            # imm = 0x148
retq
movq 0xd8(%rsp), %rdi
callq 0x6520
nopw (%rax,%rax)