// File: bonetblai[P]mdp-engine/ctp3/../engine/policy.h
// Function: std::pair<float, float> Online::Evaluation::evaluation_with_stdev<state_t>(Online::Policy::policy_t<state_t> const&, state_t const&, unsigned int, unsigned int, bool)
inline std::pair<float, float>
  evaluation_with_stdev(const Policy::policy_t<T> &policy,
                        const T &s,
                        unsigned number_trials,
                        unsigned max_depth,
                        bool verbose = false) {
    float sum = 0;
    std::vector<float> values;
    values.reserve(number_trials);
    if( verbose ) std::cout << "#trials=" << number_trials << ":";
    for( unsigned trial = 0; trial < number_trials; ++trial ) {
        if( verbose ) std::cout << " " << trial << std::flush;
        values.push_back(evaluation_trial(policy, s, max_depth));
        sum += values.back();
        if( verbose ) {
            std::cout << "(" << std::setprecision(1) << sum/(1+trial) << ")"
                      << std::flush;
        }
    }
    if( verbose ) std::cout << std::endl;

    // compute average
    float avg = 0;
    for( unsigned i = 0; i < number_trials; ++i ) {
        avg += values[i];
    }
    avg /= number_trials;

    // compute stdev
    float stdev = 0;
    for( unsigned i = 0; i < number_trials; ++i ) {
        stdev += (avg - values[i]) * (avg - values[i]);
    }
    stdev = sqrt(stdev) / (number_trials - 1);
    return std::make_pair(avg, stdev);
}

// Assembly:
subq $0xe8, %rsp
movb %r8b, %al
movq %rdi, 0xd8(%rsp)
movq %rsi, 0xd0(%rsp)
movl %edx, 0xcc(%rsp)
movl %ecx, 0xc8(%rsp)
andb $0x1, %al
movb %al, 0xc7(%rsp)
movl $0x0, 0xc0(%rsp)
leaq 0xa8(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x5b440
movq 0x78(%rsp), %rdi
movl 0xcc(%rsp), %eax
movl %eax, %esi
callq 0x5b450
jmp 0x5b023
testb $0x1, 0xc7(%rsp)
je 0x5b09a
movq 0x27f9c(%rip), %rdi     # 0x82fd0
leaq 0x3282(%rip), %rsi      # 0x5e2bd
callq 0x6330
movq %rax, 0x70(%rsp)
jmp 0x5b047
movq 0x70(%rsp), %rdi
movl 0xcc(%rsp), %esi
callq 0x6440
movq %rax, 0x68(%rsp)
jmp 0x5b05f
movq 0x68(%rsp), %rdi
leaq 0x2d87(%rip), %rsi      # 0x5ddf2
callq 0x6330
jmp 0x5b072
jmp 0x5b09a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x3e950
jmp 0x5b42a
movl $0x0, 0x98(%rsp)
movl 0x98(%rsp), %eax
cmpl 0xcc(%rsp), %eax
jae 0x5b243
testb $0x1, 0xc7(%rsp)
je 0x5b10a
movq 0x27f06(%rip), %rdi     # 0x82fd0
leaq 0x2e25(%rip), %rsi      # 0x5def6
callq 0x6330
movq %rax, 0x60(%rsp)
jmp 0x5b0dd
movq 0x60(%rsp), %rdi
movl 0x98(%rsp), %esi
callq 0x6440
movq %rax, 0x58(%rsp)
jmp 0x5b0f5
movq 0x58(%rsp), %rdi
movq 0x27ed7(%rip), %rsi     # 0x82fd8
callq 0x6370
jmp 0x5b108
jmp 0x5b10a
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movl 0xc8(%rsp), %edx
callq 0x3c7c0
movss %xmm0, 0x54(%rsp)
jmp 0x5b12e
movss 0x54(%rsp), %xmm0
movss %xmm0, 0x94(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x94(%rsp), %rsi
callq 0x5b560
jmp 0x5b154
leaq 0xa8(%rsp), %rdi
callq 0x5b590
movss (%rax), %xmm0
addss 0xc0(%rsp), %xmm0
movss %xmm0, 0xc0(%rsp)
testb $0x1, 0xc7(%rsp)
je 0x5b22b
movq 0x27e44(%rip), %rdi     # 0x82fd0
leaq 0x2eaf(%rip), %rsi      # 0x5e042
callq 0x6330
movq %rax, 0x48(%rsp)
jmp 0x5b19f
movl $0x1, %edi
callq 0x5b5d0
movl %eax, 0x44(%rsp)
jmp 0x5b1af
movq 0x48(%rsp), %rdi
movl 0x44(%rsp), %eax
movl %eax, 0x90(%rsp)
movl 0x90(%rsp), %esi
callq 0x64b0
movq %rax, 0x38(%rsp)
jmp 0x5b1d2
movq 0x38(%rsp), %rdi
movss 0xc0(%rsp), %xmm0
movl 0x98(%rsp), %eax
incl %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
callq 0x6270
movq %rax, 0x30(%rsp)
jmp 0x5b1fe
movq 0x30(%rsp), %rdi
leaq 0x21e3(%rip), %rsi      # 0x5d3ed
callq 0x6330
movq %rax, 0x28(%rsp)
jmp 0x5b216
movq 0x28(%rsp), %rdi
movq 0x27db6(%rip), %rsi     # 0x82fd8
callq 0x6370
jmp 0x5b229
jmp 0x5b22b
jmp 0x5b22d
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x5b0a5
testb $0x1, 0xc7(%rsp)
je 0x5b264
movq 0x27d7c(%rip), %rdi     # 0x82fd0
movq 0x27d5d(%rip), %rsi     # 0x82fb8
callq 0x6370
jmp 0x5b262
jmp 0x5b264
xorps %xmm0, %xmm0
movss %xmm0, 0x8c(%rsp)
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
cmpl 0xcc(%rsp), %eax
jae 0x5b2ca
movl 0x88(%rsp), %eax
movl %eax, %esi
leaq 0xa8(%rsp), %rdi
callq 0x3fe30
movss (%rax), %xmm0
addss 0x8c(%rsp), %xmm0
movss %xmm0, 0x8c(%rsp)
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0x5b27b
movl 0xcc(%rsp), %eax
cvtsi2ss %rax, %xmm1
movss 0x8c(%rsp), %xmm0
divss %xmm1, %xmm0
movss %xmm0, 0x8c(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x84(%rsp)
movl $0x0, 0x80(%rsp)
movl 0x80(%rsp), %eax
cmpl 0xcc(%rsp), %eax
jae 0x5b3ad
movss 0x8c(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movl 0x80(%rsp), %eax
movl %eax, %esi
leaq 0xa8(%rsp), %rdi
callq 0x3fe30
movss 0x1c(%rsp), %xmm0
subss (%rax), %xmm0
movss %xmm0, 0x24(%rsp)
movss 0x8c(%rsp), %xmm0
movss %xmm0, 0x20(%rsp)
movl 0x80(%rsp), %eax
movl %eax, %esi
leaq 0xa8(%rsp), %rdi
callq 0x3fe30
movss 0x20(%rsp), %xmm1
movss 0x24(%rsp), %xmm0
subss (%rax), %xmm1
mulss %xmm1, %xmm0
addss 0x84(%rsp), %xmm0
movss %xmm0, 0x84(%rsp)
movl 0x80(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x80(%rsp)
jmp 0x5b303
movss 0x84(%rsp), %xmm0
callq 0x5b5f0
movss %xmm0, 0x18(%rsp)
jmp 0x5b3c3
movss 0x18(%rsp), %xmm0
movl 0xcc(%rsp), %eax
decl %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss %xmm0, 0x84(%rsp)
leaq 0x8c(%rsp), %rdi
leaq 0x84(%rsp), %rsi
callq 0x19f80
movaps %xmm0, (%rsp)
jmp 0x5b3ff
movaps (%rsp), %xmm0
movlpd %xmm0, 0xe0(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x3e950
movsd 0xe0(%rsp), %xmm0
addq $0xe8, %rsp
retq
movq 0xa0(%rsp), %rdi
callq 0x6520
nopw (%rax,%rax)