// File: /workspace/github_cpp_makefile_star2_O2/bonetblai[P]mdp-engine/ctp3/../engine/simple_astar.h
// Function: Algorithm::simple_astar_t<state_t>::solve(state_t const&, Problem::hash_t<state_t>&) const
virtual void solve(const T &s, Problem::hash_t<T> &hash) const {
        reset_stats(hash);
        Heuristic::wrapper_t<T> eval_function(heuristic_);
        hash.set_eval_function(&eval_function);

        priority_queue_t open;
        std::vector<std::pair<T, float> > outcomes;

        Hash::data_t *dptr = hash.data_ptr(s);
        dptr->set_g(0);
        dptr->set_parent(0);
        dptr->set_action(Problem::noop);
        dptr->mark();
        open.push(std::make_pair(s, dptr));

#ifdef DEBUG
        std::cout << "PUSH " << "state" ///s
                  << " w/ g=" << dptr->g()
                  << " and h=" << dptr->h()
                  << " => f=" << dptr->f()
                  << std::endl;
        std::cout << "queue.sz=" << open.size() << std::endl;
#endif

        while( !open.empty() ) {
            std::pair<T, Hash::data_t*> n = open.top();
            open.pop();

#ifdef DEBUG
            std::cout << "POP  " << "state: " << n.first
                      << " w/ g=" << n.second->g()
                      << " and h=" << n.second->h()
                      << " => f=" << n.second->f()
                      << std::endl;
            std::cout << "queue.sz=" << open.size() << std::endl;

            std::vector<const Hash::data_t*> path;
            path.reserve(n.second->g());
            for( const Hash::data_t *dptr = n.second; dptr != 0; dptr = dptr->parent() )
                path.push_back(dptr);

            std::cout << "path=<";
            for( size_t i = path.size() - 1; i > 0; --i )
                std::cout << path[i-1]->action() << ",";
            std::cout << ">" << std::endl;
#endif

            // check for termination
            if( problem_.terminal(n.first) ) {
#ifdef DEBUG
                std::cout << "GOAL FOUND!" << std::endl;
#endif

                std::vector<const Hash::data_t*> plan;
                plan.reserve(n.second->g());
                for( const Hash::data_t *dptr = n.second; dptr != 0; dptr = dptr->parent() )
                    plan.push_back(dptr);

                std::cout << "plan=<";
                for( size_t i = plan.size() - 1; i > 0; --i )
                    std::cout << plan[i-1]->action() << ",";
                std::cout << ">:" << plan.size() - 1 << std::endl;

                //return (int)n.second->g(); // NEED FIX
            }

            // expand state
            for( Problem::action_t a = 0; a < problem_.number_actions(n.first); ++a ) {
                if( problem_.applicable(n.first, a) ) {
                    problem_.next(n.first, a, outcomes);
                    assert(outcomes.size() == 1);
                    Hash::data_t *ptr = hash.data_ptr(outcomes[0].first);
                    float g = n.second->g() + problem_.cost(n.first, a);
                    if( !ptr->marked() || (g + ptr->h() < ptr->f()) ) {
                        ptr->set_g(g);
                        ptr->set_parent(n.second);
                        ptr->set_action(a);
                        ptr->mark();
                        open.push(std::make_pair(outcomes[0].first, ptr));
#ifdef DEBUG
                        std::cout << "PUSH " << "state: " <<outcomes[0].first
                                  << " w/ g=" << ptr->g()
                                  << " and h=" << ptr->h()
                                  << " => f=" << ptr->f()
                                  << std::endl;
                        std::cout << "queue.sz=" << open.size() << std::endl;
#endif
                    }
                }
            }
        }
        //return std::numeric_limits<size_t>::max(); // NEED FIX
        hash.set_eval_function(0);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq (%rdi), %rax
movq %rdx, %rsi
callq *0x30(%rax)
movq 0x10(%r14), %rax
leaq 0x22dec(%rip), %rcx     # 0x341a0
leaq 0x148(%rsp), %rdx
movq %rcx, (%rdx)
movq %rax, 0x8(%rdx)
movq %rdx, 0x40(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0xcf18
movq %rax, %r12
andl $0x0, 0x18(%rax)
andq $0x0, 0x20(%rax)
orl $-0x1, 0x10(%rax)
movb $0x1, 0x5(%rax)
leaq 0xd0(%rsp), %rdi
movq %r15, %rsi
callq 0xa4d8
leaq 0xd0(%rsp), %rsi
movq %r12, 0x70(%rsi)
leaq 0x30(%rsp), %rdi
callq 0x1174a
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
callq 0x8e90
leaq 0x50(%rsp), %r13
movq %rsp, %r12
movq 0x30(%rsp), %rsi
cmpq 0x38(%rsp), %rsi
je 0x11674
movq %r15, %rdi
callq 0xe794
leaq 0x30(%rsp), %rdi
callq 0x11760
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x20(%rax)
testb %al, %al
je 0x1156f
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movq 0x140(%rsp), %rax
movss 0x18(%rax), %xmm0
cvttss2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subss 0xeb75(%rip), %xmm0     # 0x20018
cvttss2si %xmm0, %rsi
andq %rcx, %rsi
orq %rax, %rsi
movq %r13, %rdi
callq 0x1177a
leaq 0x140(%rsp), %rax
movq (%rax), %rax
movq %rax, (%rsp)
testq %rax, %rax
je 0x114df
movq %r13, %rdi
movq %r12, %rsi
callq 0x1180a
movq (%rsp), %rax
addq $0x20, %rax
jmp 0x114be
movq 0x23af2(%rip), %rdi     # 0x34fd8
leaq 0xf926(%rip), %rsi      # 0x20e13
callq 0x5290
movq 0x58(%rsp), %r12
subq 0x50(%rsp), %r12
sarq $0x3, %r12
cmpq $0x1, %r12
je 0x11533
movq 0x50(%rsp), %rax
movq -0x10(%rax,%r12,8), %rax
movl 0x10(%rax), %esi
movq 0x23abe(%rip), %rdi     # 0x34fd8
callq 0x5400
decq %r12
movq %rax, %rdi
leaq 0xf8ee(%rip), %rsi      # 0x20e1a
callq 0x5290
jmp 0x11500
movq 0x23a9e(%rip), %rdi     # 0x34fd8
leaq 0xf8db(%rip), %rsi      # 0x20e1c
callq 0x5290
movq 0x58(%rsp), %rsi
subq 0x50(%rsp), %rsi
sarq $0x3, %rsi
decq %rsi
movq %rax, %rdi
callq 0x51c0
movq %rax, %rdi
callq 0x5130
movq %r13, %rdi
callq 0x11efa
xorl %r12d, %r12d
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
cmpl %eax, %r12d
jge 0x11667
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %r12d, %edx
callq *0x30(%rax)
testb %al, %al
je 0x1165f
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %r12d, %edx
leaq 0x10(%rsp), %rcx
callq *0x60(%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
cmpq $0x78, %rax
jne 0x1169f
movq %rbx, %rdi
callq 0xcf18
movq %rax, %rbp
movq 0x140(%rsp), %rax
movss 0x18(%rax), %xmm0
movss %xmm0, 0xc(%rsp)
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %r12d, %edx
callq *0x48(%rax)
addss 0xc(%rsp), %xmm0
cmpb $0x1, 0x5(%rbp)
jne 0x1161c
movss (%rbp), %xmm1
movaps %xmm1, %xmm2
addss %xmm0, %xmm2
addss 0x18(%rbp), %xmm1
ucomiss %xmm1, %xmm2
jae 0x1165f
movss %xmm0, 0x18(%rbp)
movq 0x140(%rsp), %rax
movq %rax, 0x20(%rbp)
movl %r12d, 0x10(%rbp)
movb $0x1, 0x5(%rbp)
movq 0x10(%rsp), %rsi
movq %r13, %rdi
callq 0xa4d8
movq %rbp, 0xc0(%rsp)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x1174a
movq %r13, %rdi
callq 0x8e90
incl %r12d
jmp 0x11572
movq %r15, %rdi
callq 0x8e90
jmp 0x1143a
andq $0x0, 0x40(%rbx)
leaq 0x10(%rsp), %rdi
callq 0xb53c
leaq 0x30(%rsp), %rdi
callq 0x11f08
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf779(%rip), %rdi      # 0x20e1f
leaq 0xf787(%rip), %rsi      # 0x20e34
leaq 0xf799(%rip), %rcx      # 0x20e4d
movl $0x97, %edx
callq 0x51b0
jmp 0x116f3
jmp 0x116c4
jmp 0x116c4
movq %rax, %rbx
jmp 0x11703
jmp 0x116f3
jmp 0x116e4
jmp 0x116f3
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x8e90
jmp 0x116f6
jmp 0x116f3
jmp 0x116f3
jmp 0x116e4
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x11efa
jmp 0x116f6
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x8e90
leaq 0x10(%rsp), %rdi
callq 0xb53c
leaq 0x30(%rsp), %rdi
callq 0x11f08
movq %rbx, %rdi
callq 0x5410
nop