// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movss %xmm0, 0x4(%rsp)
movq %rdx, %rbx
movq %rsi, %r13
leaq 0x38(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movq %rdi, %r14
leaq 0x8(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %rdx, %rdi
callq 0xcf18
movq %rax, %r12
cmpb $0x0, 0x4(%rax)
jne 0x10589
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0xa4d8
leaq 0x58(%rsp), %rsi
movq %r12, 0x70(%rsi)
leaq 0x38(%rsp), %rdi
callq 0xe788
leaq 0x58(%rsp), %rdi
callq 0x8e90
movb $0x1, 0x5(%r12)
movb $0x1, %al
movl %eax, (%rsp)
leaq 0x58(%rsp), %r13
leaq 0x8(%rsp), %r15
leaq 0xd0(%rsp), %rbp
movq %r14, 0x50(%rsp)
leaq 0x38(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x106d0
movq 0x40(%rsp), %rsi
addq $0x10, %rsi
movq %r13, %rdi
callq 0xe794
movq %r15, %rdi
movq %r13, %rsi
callq 0xe7e4
leaq 0x38(%rsp), %rdi
callq 0xe9be
movq (%r14), %rax
movq %r14, %rdi
movq %r13, %rsi
callq *0x20(%rax)
testb %al, %al
jne 0x106c3
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd74c
movq %rax, %rcx
shrq $0x20, %rcx
movd %ecx, %xmm0
movq 0xc8(%rsp), %rcx
subss (%rcx), %xmm0
andps 0xfa48(%rip), %xmm0     # 0x20060
ucomiss 0x4(%rsp), %xmm0
jbe 0x1062b
movl $0x0, (%rsp)
jmp 0x106c3
movq (%r14), %r8
movq %r14, %rdi
movq %r13, %rsi
movl %eax, %edx
leaq 0x20(%rsp), %rcx
callq *0x60(%r8)
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
cqto
pushq $0x78
popq %rcx
idivq %rcx
movl %eax, %eax
imulq $0x78, %rax, %r14
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x106b9
movq 0x20(%rsp), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0xcf18
movq %rax, %r12
cmpb $0x0, 0x4(%rax)
jne 0x106b3
cmpb $0x0, 0x5(%r12)
jne 0x106b3
movq 0x20(%rsp), %rsi
addq %r15, %rsi
movq %rbp, %rdi
callq 0xa4d8
movq %r12, 0x140(%rsp)
leaq 0x38(%rsp), %rdi
movq %rbp, %rsi
callq 0xe788
movq %rbp, %rdi
callq 0x8e90
movb $0x1, 0x5(%r12)
addq $0x78, %r15
jmp 0x1065a
movq 0x50(%rsp), %r14
leaq 0x8(%rsp), %r15
movq %r13, %rdi
callq 0x8e90
jmp 0x105a5
movl (%rsp), %ebp
testb $0x1, %bpl
je 0x106fa
cmpq %r15, 0x8(%rsp)
je 0x10735
movq 0x10(%rsp), %rax
movq 0x80(%rax), %rax
movb $0x1, 0x4(%rax)
movq %r15, %rdi
callq 0xe9be
jmp 0x106d9
cmpq %r15, 0x8(%rsp)
je 0x10735
movq 0x10(%rsp), %rsi
addq $0x10, %rsi
movq %rbx, %rdi
callq 0xd74c
shrq $0x20, %rax
movq 0x10(%rsp), %rcx
movq 0x80(%rcx), %rcx
movl %eax, (%rcx)
movb $0x0, 0x5(%rcx)
incl 0x50(%rbx)
movq %r15, %rdi
callq 0xe9be
jmp 0x106fa
leaq 0x20(%rsp), %rdi
callq 0xb53c
leaq 0x8(%rsp), %rdi
callq 0xe98e
leaq 0x38(%rsp), %rdi
callq 0xe98e
andb $0x1, %bpl
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10790
jmp 0x10775
jmp 0x10775
jmp 0x10775
jmp 0x10790
movq %rax, %rbx
jmp 0x1079d
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x8e90
jmp 0x10793
jmp 0x10790
jmp 0x10790
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x8e90
leaq 0x20(%rsp), %rdi
callq 0xb53c
leaq 0x8(%rsp), %rdi
callq 0xe98e
leaq 0x38(%rsp), %rdi
callq 0xe98e
movq %rbx, %rdi
callq 0x5410
nop