// File: 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:
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rdi, 0x2a0(%rsp)
movq %rsi, 0x298(%rsp)
movq %rdx, 0x290(%rsp)
movq 0x2a0(%rsp), %rdi
movq %rdi, 0x78(%rsp)
movq 0x290(%rsp), %rsi
movq (%rdi), %rax
movq 0x30(%rax), %rax
callq *%rax
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x280(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x20c30
movq 0x80(%rsp), %rsi
movq 0x290(%rsp), %rdi
callq 0x20c70
leaq 0x260(%rsp), %rdi
callq 0x2e4b0
jmp 0x2dd2f
leaq 0x238(%rsp), %rdi
callq 0x1a4a0
movq 0x290(%rsp), %rdi
movq 0x298(%rsp), %rsi
callq 0x20ca0
movq %rax, 0x70(%rsp)
jmp 0x2dd58
movq 0x70(%rsp), %rax
movq %rax, 0x230(%rsp)
movq 0x230(%rsp), %rdi
xorps %xmm0, %xmm0
callq 0x2e4e0
jmp 0x2dd77
movq 0x230(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2e500
jmp 0x2dd8a
movq 0x230(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x263b0
movq 0x230(%rsp), %rdi
callq 0x23090
movq 0x298(%rsp), %rsi
leaq 0x1b8(%rsp), %rdi
leaq 0x230(%rsp), %rdx
callq 0x21f90
jmp 0x2ddc8
leaq 0x260(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x2e520
jmp 0x2dddf
leaq 0x1b8(%rsp), %rdi
callq 0x21fd0
leaq 0x260(%rsp), %rdi
callq 0x2e580
movb %al, 0x6f(%rsp)
jmp 0x2ddff
movb 0x6f(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2de0e
jmp 0x2e39b
leaq 0x260(%rsp), %rdi
callq 0x2e5a0
movq %rax, 0x60(%rsp)
jmp 0x2de22
movq 0x60(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x26340
jmp 0x2de36
leaq 0x260(%rsp), %rdi
callq 0x2e5b0
jmp 0x2de45
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
leaq 0x140(%rsp), %rsi
callq *%rax
movb %al, 0x5f(%rsp)
jmp 0x2de65
movb 0x5f(%rsp), %al
testb $0x1, %al
jne 0x2de72
jmp 0x2e0b8
leaq 0x128(%rsp), %rdi
callq 0x2e600
movq 0x1b0(%rsp), %rdi
callq 0x2e720
movss %xmm0, 0x58(%rsp)
jmp 0x2de94
movss 0x58(%rsp), %xmm0
movss 0x2f172(%rip), %xmm2    # 0x5d014
movaps %xmm0, %xmm1
subss %xmm2, %xmm1
cvttss2si %xmm1, %rax
cvttss2si %xmm0, %rsi
movq %rsi, %rcx
sarq $0x3f, %rcx
andq %rcx, %rax
orq %rax, %rsi
leaq 0x128(%rsp), %rdi
callq 0x2e610
jmp 0x2decf
movq 0x1b0(%rsp), %rax
movq %rax, 0x120(%rsp)
cmpq $0x0, 0x120(%rsp)
je 0x2dfc1
leaq 0x128(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x2e730
jmp 0x2df05
jmp 0x2df07
movq 0x120(%rsp), %rdi
callq 0x2e7a0
movq %rax, 0x50(%rsp)
jmp 0x2df1b
movq 0x50(%rsp), %rax
movq %rax, 0x120(%rsp)
jmp 0x2dedf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x2e3f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x2e3db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x21fd0
jmp 0x2e3db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
jmp 0x2e38c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x2e7f0
jmp 0x2e38c
movq 0x55008(%rip), %rdi     # 0x82fd0
leaq 0x2fe19(%rip), %rsi     # 0x5dde8
callq 0x6330
jmp 0x2dfd6
leaq 0x128(%rsp), %rdi
callq 0x2e7b0
subq $0x1, %rax
movq %rax, 0x118(%rsp)
cmpq $0x0, 0x118(%rsp)
jbe 0x2e05a
movq 0x118(%rsp), %rsi
decq %rsi
leaq 0x128(%rsp), %rdi
callq 0x2e7d0
movq (%rax), %rdi
callq 0x26dc0
movl %eax, %esi
movq 0x54fad(%rip), %rdi     # 0x82fd0
callq 0x6510
movq %rax, 0x48(%rsp)
jmp 0x2e02f
movq 0x48(%rsp), %rdi
leaq 0x2fdb4(%rip), %rsi     # 0x5ddef
callq 0x6330
jmp 0x2e042
jmp 0x2e044
movq 0x118(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x118(%rsp)
jmp 0x2dfef
movq 0x54f6f(%rip), %rdi     # 0x82fd0
leaq 0x2fd89(%rip), %rsi     # 0x5ddf1
callq 0x6330
movq %rax, 0x40(%rsp)
jmp 0x2e074
leaq 0x128(%rsp), %rdi
callq 0x2e7b0
movq 0x40(%rsp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x60c0
movq %rax, 0x38(%rsp)
jmp 0x2e098
movq 0x38(%rsp), %rdi
movq 0x54f14(%rip), %rsi     # 0x82fb8
callq 0x6370
jmp 0x2e0ab
leaq 0x128(%rsp), %rdi
callq 0x2e7f0
movl $0x0, 0x114(%rsp)
movq 0x78(%rsp), %rax
movl 0x114(%rsp), %ecx
movl %ecx, 0x30(%rsp)
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq 0x140(%rsp), %rsi
callq *%rax
movl %eax, 0x34(%rsp)
jmp 0x2e0ee
movl 0x30(%rsp), %eax
movl 0x34(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2e37a
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x114(%rsp), %edx
movq (%rdi), %rax
movq 0x30(%rax), %rax
leaq 0x140(%rsp), %rsi
callq *%rax
movb %al, 0x2f(%rsp)
jmp 0x2e125
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x2e132
jmp 0x2e362
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x114(%rsp), %edx
movq (%rdi), %rax
movq 0x60(%rax), %rax
leaq 0x140(%rsp), %rsi
leaq 0x238(%rsp), %rcx
callq *%rax
jmp 0x2e15d
leaq 0x238(%rsp), %rdi
callq 0x17030
cmpq $0x1, %rax
jne 0x2e172
jmp 0x2e191
leaq 0x2fc7b(%rip), %rdi     # 0x5ddf4
leaq 0x2fc89(%rip), %rsi     # 0x5de09
movl $0x97, %edx
leaq 0x2fc96(%rip), %rcx     # 0x5de22
callq 0x6220
movq 0x290(%rsp), %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x238(%rsp), %rdi
callq 0x1a4b0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x20ca0
movq %rax, 0x20(%rsp)
jmp 0x2e1c3
movq 0x20(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0x2e720
movss %xmm0, 0x14(%rsp)
jmp 0x2e1e5
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x114(%rsp), %edx
movq (%rdi), %rax
movq 0x48(%rax), %rax
leaq 0x140(%rsp), %rsi
callq *%rax
movss %xmm0, 0x10(%rsp)
jmp 0x2e20e
movss 0x10(%rsp), %xmm1
movss 0x14(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x104(%rsp)
movq 0x108(%rsp), %rdi
callq 0x22ea0
testb $0x1, %al
jne 0x2e23a
jmp 0x2e29c
movss 0x104(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x108(%rsp), %rdi
callq 0x2e850
movss %xmm0, 0xc(%rsp)
jmp 0x2e25e
movss 0xc(%rsp), %xmm1
movss 0x8(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rsp)
movq 0x108(%rsp), %rdi
callq 0x2e860
movss %xmm0, 0x4(%rsp)
jmp 0x2e288
movss 0x4(%rsp), %xmm0
movss (%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x2e360
movq 0x108(%rsp), %rdi
movss 0x104(%rsp), %xmm0
callq 0x2e4e0
jmp 0x2e2b4
movq 0x108(%rsp), %rdi
movq 0x1b0(%rsp), %rsi
callq 0x2e500
jmp 0x2e2cb
movq 0x108(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x263b0
movq 0x108(%rsp), %rdi
callq 0x23090
xorl %eax, %eax
movl %eax, %esi
leaq 0x238(%rsp), %rdi
callq 0x1a4b0
movq %rax, %rsi
leaq 0x88(%rsp), %rdi
leaq 0x108(%rsp), %rdx
callq 0x262b0
jmp 0x2e317
leaq 0x260(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x2e520
jmp 0x2e32e
leaq 0x88(%rsp), %rdi
callq 0x21fd0
jmp 0x2e360
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x21fd0
jmp 0x2e38c
jmp 0x2e362
jmp 0x2e364
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x2e0c3
leaq 0x140(%rsp), %rdi
callq 0x21fd0
jmp 0x2ddec
leaq 0x140(%rsp), %rdi
callq 0x21fd0
jmp 0x2e3db
movq 0x290(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20c70
leaq 0x238(%rsp), %rdi
callq 0x1a510
leaq 0x260(%rsp), %rdi
callq 0x2e880
leaq 0x280(%rsp), %rdi
callq 0x21630
addq $0x2a8, %rsp            # imm = 0x2A8
retq
leaq 0x238(%rsp), %rdi
callq 0x1a510
leaq 0x260(%rsp), %rdi
callq 0x2e880
leaq 0x280(%rsp), %rdi
callq 0x21630
movq 0x258(%rsp), %rdi
callq 0x6520
nop