// File: j-faria[P]kima/examples/trends/../../DNest4/code/SamplerImpl.h
// Function: DNest4::Sampler<RVmodel>::enough_levels(std::vector<DNest4::Level, std::allocator<DNest4::Level>> const&) const
bool Sampler<ModelType>::enough_levels(const std::vector<Level>& l) const
{
    if(options.max_num_levels == 0)
    {
        // Check level spacing (in terms of log likelihood)
        // over last n levels
        int num_levels_to_check = static_cast<int>(30*sqrt(0.02*l.size()));
        if(num_levels_to_check < 30)
            return false;

        int k = l.size() - 1;
        double tot = 0.0;
        double max = -1E300;
        for(int i=0; i<num_levels_to_check; ++i)
        {
            double diff = l[k].get_log_likelihood().get_value()
                             - l[k-1].get_log_likelihood().get_value();
            tot += diff;
            if(diff > max)
                max = diff;
            --k;
        }
        if(tot / num_levels_to_check < 0.75 && max < 1.0)
            return true;
        else
            return false;
    }

    // Just compare with the value from OPTIONS
    return (l.size() >= options.max_num_levels);   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, 0x48(%rax)
jne 0xabca8
movq -0x18(%rbp), %rdi
callq 0xa41f0
movq %rax, %xmm1
movaps 0xb4b9(%rip), %xmm0     # 0xb7010
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xb4bd(%rip), %xmm0     # 0xb7020
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x19d8e(%rip), %xmm0    # 0xc5908
mulsd %xmm1, %xmm0
callq 0x6410
movaps %xmm0, %xmm1
movsd 0x19d72(%rip), %xmm0    # 0xc5900
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x1e, -0x1c(%rbp)
jge 0xabba8
movb $0x0, -0x1(%rbp)
jmp 0xabcc3
movq -0x18(%rbp), %rdi
callq 0xa41f0
subq $0x1, %rax
movl %eax, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0xb628(%rip), %xmm0     # 0xb71f0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xabc71
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rsi
callq 0xaa4f0
movq %rax, %rdi
callq 0xa9390
movq %rax, %rdi
callq 0xa93a0
movsd %xmm0, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movl -0x20(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0xaa4f0
movq %rax, %rdi
callq 0xa9390
movq %rax, %rdi
callq 0xa93a0
movaps %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x40(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0xabc5a
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xabbd4
movsd -0x28(%rbp), %xmm1
cvtsi2sdl -0x1c(%rbp), %xmm0
divsd %xmm0, %xmm1
movsd 0xba41(%rip), %xmm0     # 0xb76c8
ucomisd %xmm1, %xmm0
jbe 0xabca2
movsd 0xb39b(%rip), %xmm0     # 0xb7030
ucomisd -0x30(%rbp), %xmm0
jbe 0xabca2
movb $0x1, -0x1(%rbp)
jmp 0xabcc3
movb $0x0, -0x1(%rbp)
jmp 0xabcc3
movq -0x18(%rbp), %rdi
callq 0xa41f0
movq -0x48(%rbp), %rcx
movl 0x48(%rcx), %ecx
cmpq %rcx, %rax
setae %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nop