// File: /workspace/github_cpp_makefile_star2_O1/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 $0x168, %rsp            # imm = 0x168
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq (%rdi), %rax
movq %rdx, %rsi
callq *0x30(%rax)
movq 0x10(%r14), %rax
leaq 0x27230(%rip), %rcx     # 0x3dff0
leaq 0x158(%rsp), %rdx
movq %rcx, (%rdx)
movq %rax, 0x8(%rdx)
movq %rdx, 0x40(%rbx)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1020a
movq %rax, %r12
movl $0x0, 0x18(%rax)
xorl %eax, %eax
movq %rax, 0x20(%r12)
movl $0xffffffff, 0x10(%r12) # imm = 0xFFFFFFFF
movb $0x1, %cl
movb %cl, 0x5(%r12)
leaq 0xe0(%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 %cl, 0x5c(%rdi)
movq %rax, 0x60(%rdi)
movq %r15, %rsi
callq 0xd546
leaq 0xe0(%rsp), %rsi
movq %r12, 0x70(%rsi)
leaq 0x10(%rsp), %rdi
callq 0x17504
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x173c2
cmpb $0x0, 0x13c(%rsp)
jne 0x16e8c
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x16e8c
callq 0x6340
movq 0x10(%rsp), %r12
cmpq 0x18(%rsp), %r12
je 0x171d8
leaq 0x64(%rsp), %rbx
leaq 0xe0(%rsp), %r15
leaq 0x60(%rsp), %r13
leaq 0xe4(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x40(%rax)
movb $0x1, 0x13c(%rsp)
movq %rcx, 0x140(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0xd546
movq 0x70(%r12), %rax
movq %rax, 0x150(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x172e2
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x20(%rax)
testb %al, %al
je 0x17063
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x150(%rsp), %rax
movss 0x18(%rax), %xmm0
cvttss2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subss 0x160d1(%rip), %xmm0    # 0x2d018
cvttss2si %xmm0, %rsi
andq %rcx, %rsi
orq %rax, %rsi
movq %r13, %rdi
callq 0x17334
movq 0x150(%rsp), %rax
movq %rax, (%rsp)
testq %rax, %rax
je 0x16f97
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x16f82
movq %rax, (%rsi)
addq $0x8, 0x68(%rsp)
jmp 0x16f8d
movq %r13, %rdi
movq %rsp, %rdx
callq 0x17bfa
movq (%rsp), %rax
movq 0x20(%rax), %rax
jmp 0x16f62
movl $0x6, %edx
movq 0x28035(%rip), %rdi     # 0x3efd8
leaq 0x16eae(%rip), %rsi     # 0x2de58
callq 0x62e0
movq 0x68(%rsp), %r12
subq 0x60(%rsp), %r12
sarq $0x3, %r12
cmpq $0x1, %r12
je 0x16ff5
movq 0x60(%rsp), %rax
movq -0x10(%rax,%r12,8), %rax
movl 0x10(%rax), %esi
movq 0x28001(%rip), %rdi     # 0x3efd8
callq 0x6400
decq %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x16e71(%rip), %rsi     # 0x2de5f
callq 0x62e0
jmp 0x16fbd
movl $0x2, %edx
movq 0x27fd7(%rip), %rdi     # 0x3efd8
leaq 0x16e59(%rip), %rsi     # 0x2de61
callq 0x62e0
movq 0x68(%rsp), %rsi
subq 0x60(%rsp), %rsi
sarq $0x3, %rsi
decq %rsi
movq 0x27fb3(%rip), %rdi     # 0x3efd8
callq 0x61d0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x6270
movsbl %al, %esi
movq %r12, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61e0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x17063
callq 0x6260
xorl %r12d, %r12d
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
cmpl %eax, %r12d
jge 0x171ac
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %r12d, %edx
callq *0x30(%rax)
testb %al, %al
je 0x171a4
movq 0x8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl %r12d, %edx
leaq 0x40(%rsp), %rcx
callq *0x60(%rax)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rax
subq %rsi, %rax
cmpq $0x78, %rax
jne 0x1720b
movq 0x38(%rsp), %rdi
callq 0x1020a
movq %rax, %rbp
movq 0x150(%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 0x17116
movss (%rbp), %xmm1
movaps %xmm1, %xmm2
addss %xmm0, %xmm2
addss 0x18(%rbp), %xmm1
ucomiss %xmm1, %xmm2
jae 0x171a4
movss %xmm0, 0x18(%rbp)
movq 0x150(%rsp), %rax
movq %rax, 0x20(%rbp)
movl %r12d, 0x10(%rbp)
movb $0x1, %cl
movb %cl, 0x5(%rbp)
movq 0x40(%rsp), %rsi
xorl %eax, %eax
movq %rax, 0x40(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rbx)
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movb %cl, 0xbc(%rsp)
movq %rax, 0xc0(%rsp)
movq %r13, %rdi
callq 0xd546
movq %rbp, 0xd0(%rsp)
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x17504
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x173c2
cmpb $0x0, 0xbc(%rsp)
jne 0x171a4
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x171a4
callq 0x6340
incl %r12d
jmp 0x17066
cmpb $0x0, 0x13c(%rsp)
jne 0x171c8
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x171c8
callq 0x6340
movq 0x10(%rsp), %r12
cmpq 0x18(%rsp), %r12
jne 0x16eae
movq 0x38(%rsp), %rax
movq $0x0, 0x40(%rax)
leaq 0x40(%rsp), %rdi
callq 0xe35c
leaq 0x10(%rsp), %rdi
callq 0x17d14
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16c52(%rip), %rdi     # 0x2de64
leaq 0x16c60(%rip), %rsi     # 0x2de79
leaq 0x16c72(%rip), %rcx     # 0x2de92
movl $0x97, %edx
callq 0x61c0
jmp 0x17230
jmp 0x17230
jmp 0x17276
movq %rax, %rbx
jmp 0x17295
jmp 0x17276
jmp 0x17262
jmp 0x17262
jmp 0x17276
jmp 0x17276
jmp 0x17276
movq %rax, %rbx
cmpb $0x0, 0xbc(%rsp)
jne 0x17279
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x17279
callq 0x6340
jmp 0x17279
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x17279
callq 0x6260
jmp 0x17279
movq %rax, %rbx
cmpb $0x0, 0x13c(%rsp)
jne 0x17295
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x17295
callq 0x6340
leaq 0x40(%rsp), %rdi
callq 0xe35c
leaq 0x10(%rsp), %rdi
callq 0x17d14
movq %rbx, %rdi
callq 0x6410
nop