// File: bonetblai[P]mdp-engine/ctp3/../engine/plain_check.h
// Function: bool Algorithm::check_solved<state_t>(Problem::problem_t<state_t> const&, state_t const&, Problem::hash_t<state_t>&, float)
bool check_solved(const Problem::problem_t<T> &problem,
                  const T &s,
                  Problem::hash_t<T> &hash,
                  float epsilon) {
    std::list<std::pair<T, Hash::data_t*> > open, closed;

    std::vector<std::pair<T, float> > outcomes;
    Hash::data_t *dptr = hash.data_ptr(s);
    if( !dptr->solved() ) {
        open.push_back(std::make_pair(s, dptr));
        dptr->mark();
    }

    bool rv = true;
    while( !open.empty() ) {
        std::pair<T, Hash::data_t*> n = open.back();
        closed.push_back(n);
        open.pop_back();
        if( problem.terminal(n.first) ) continue;

        std::pair<Problem::action_t, float> p = hash.best_q_value(n.first);
        if( fabs(p.second - n.second->value()) > epsilon ) {
            rv = false;
            continue;
        }

        problem.next(n.first, p.first, outcomes);
        unsigned osize = outcomes.size();

        for( unsigned i = 0; i < osize; ++ i ) {
            Hash::data_t *dptr = hash.data_ptr(outcomes[i].first);
            if( !dptr->solved() && !dptr->marked() ) {
                open.push_back(std::make_pair(outcomes[i].first, dptr));
                dptr->mark();
            }
        }
    }

    if( rv ) {
        while( !closed.empty() ) {
            closed.back().second->solve();
            closed.pop_back();
        }
    } else {
        while( !closed.empty() ) {
            std::pair<Problem::action_t, float> p = hash.best_q_value(closed.back().first);
            closed.back().second->update(p.second);
            closed.back().second->unmark();
            hash.inc_updates();
            closed.pop_back();
        }
    }
    return rv;
}

// Assembly:
subq $0x268, %rsp            # imm = 0x268
movq %rdi, 0x260(%rsp)
movq %rsi, 0x258(%rsp)
movq %rdx, 0x250(%rsp)
movss %xmm0, 0x24c(%rsp)
leaq 0x230(%rsp), %rdi
callq 0x24840
leaq 0x218(%rsp), %rdi
callq 0x24840
leaq 0x200(%rsp), %rdi
callq 0x1a4a0
movq 0x250(%rsp), %rdi
movq 0x258(%rsp), %rsi
callq 0x20ca0
movq %rax, 0x48(%rsp)
jmp 0x2affb
movq 0x48(%rsp), %rax
movq %rax, 0x1f8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x20d90
testb $0x1, %al
jne 0x2b0ae
movq 0x258(%rsp), %rsi
leaq 0x170(%rsp), %rdi
leaq 0x1f8(%rsp), %rdx
callq 0x21f90
jmp 0x2b03c
leaq 0x230(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x26270
jmp 0x2b053
leaq 0x170(%rsp), %rdi
callq 0x21fd0
movq 0x1f8(%rsp), %rdi
callq 0x23090
jmp 0x2b0ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x2b4b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x21fd0
jmp 0x2b4b1
movb $0x1, 0x16f(%rsp)
leaq 0x230(%rsp), %rdi
callq 0x24f20
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b0ce
jmp 0x2b376
leaq 0x230(%rsp), %rdi
callq 0x26d40
movq %rax, %rsi
leaq 0xf0(%rsp), %rdi
callq 0x26340
jmp 0x2b0ed
leaq 0x218(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x26490
jmp 0x2b104
leaq 0x230(%rsp), %rdi
callq 0x26d80
movq 0x260(%rsp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
leaq 0xf0(%rsp), %rsi
callq *%rax
movb %al, 0x47(%rsp)
jmp 0x2b130
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x2b13a
jmp 0x2b163
movl $0x2, 0xec(%rsp)
jmp 0x2b340
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
jmp 0x2b364
movq 0x250(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x22eb0
movq %rax, 0x38(%rsp)
jmp 0x2b17f
movq 0x38(%rsp), %rax
movq %rax, 0xe4(%rsp)
movss 0xe8(%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
movq 0x160(%rsp), %rdi
callq 0x22fc0
movaps %xmm0, %xmm1
movss 0x34(%rsp), %xmm0
subss %xmm1, %xmm0
callq 0x22fa0
ucomiss 0x24c(%rsp), %xmm0
jbe 0x2b1dc
movb $0x0, 0x16f(%rsp)
movl $0x2, 0xec(%rsp)
jmp 0x2b340
movq 0x260(%rsp), %rdi
movl 0xe4(%rsp), %edx
movq (%rdi), %rax
movq 0x60(%rax), %rax
leaq 0xf0(%rsp), %rsi
leaq 0x200(%rsp), %rcx
callq *%rax
jmp 0x2b206
leaq 0x200(%rsp), %rdi
callq 0x17030
movl %eax, 0xe0(%rsp)
movl $0x0, 0xdc(%rsp)
movl 0xdc(%rsp), %eax
cmpl 0xe0(%rsp), %eax
jae 0x2b335
movq 0x250(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0xdc(%rsp), %eax
movl %eax, %esi
leaq 0x200(%rsp), %rdi
callq 0x1a4b0
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x20ca0
movq %rax, 0x28(%rsp)
jmp 0x2b270
movq 0x28(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x20d90
testb $0x1, %al
jne 0x2b31d
movq 0xd0(%rsp), %rdi
callq 0x22ea0
testb $0x1, %al
jne 0x2b31d
movl 0xdc(%rsp), %eax
movl %eax, %esi
leaq 0x200(%rsp), %rdi
callq 0x1a4b0
movq %rax, %rsi
leaq 0x58(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
callq 0x262b0
jmp 0x2b2d0
leaq 0x230(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x26270
jmp 0x2b2e4
leaq 0x58(%rsp), %rdi
callq 0x21fd0
movq 0xd0(%rsp), %rdi
callq 0x23090
jmp 0x2b31d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f0(%rsp)
movl %eax, 0x1ec(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x21fd0
jmp 0x2b364
jmp 0x2b31f
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x2b225
movl $0x0, 0xec(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x21fd0
movl 0xec(%rsp), %eax
testl %eax, %eax
je 0x2b35f
jmp 0x2b35a
jmp 0x2b0b6
jmp 0x2b0b6
leaq 0xf0(%rsp), %rdi
callq 0x21fd0
jmp 0x2b4b1
testb $0x1, 0x16f(%rsp)
je 0x2b3c1
jmp 0x2b382
leaq 0x218(%rsp), %rdi
callq 0x24f20
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b397
jmp 0x2b3bc
leaq 0x218(%rsp), %rdi
callq 0x26d40
movq 0x70(%rax), %rdi
callq 0x22e90
leaq 0x218(%rsp), %rdi
callq 0x26d80
jmp 0x2b382
jmp 0x2b466
jmp 0x2b3c3
leaq 0x218(%rsp), %rdi
callq 0x24f20
xorb $-0x1, %al
testb $0x1, %al
jne 0x2b3db
jmp 0x2b464
movq 0x250(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x26d40
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x22eb0
movq %rax, 0x18(%rsp)
jmp 0x2b409
movq 0x18(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x26d40
movq 0x70(%rax), %rdi
movss 0x54(%rsp), %xmm0
callq 0x22fd0
leaq 0x218(%rsp), %rdi
callq 0x26d40
movq 0x70(%rax), %rdi
callq 0x215b0
movq 0x250(%rsp), %rdi
callq 0x22ff0
leaq 0x218(%rsp), %rdi
callq 0x26d80
jmp 0x2b3c3
jmp 0x2b466
movb 0x16f(%rsp), %al
movb %al, 0xf(%rsp)
movl $0x1, 0xec(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x1a510
leaq 0x218(%rsp), %rdi
callq 0x25630
leaq 0x230(%rsp), %rdi
callq 0x25630
movb 0xf(%rsp), %al
andb $0x1, %al
addq $0x268, %rsp            # imm = 0x268
retq
leaq 0x200(%rsp), %rdi
callq 0x1a510
leaq 0x218(%rsp), %rdi
callq 0x25630
leaq 0x230(%rsp), %rdi
callq 0x25630
movq 0x1f0(%rsp), %rdi
callq 0x6520
nopw %cs:(%rax,%rax)
nop