// File: /workspace/github_cpp_makefile_star2_O2/j-faria[P]kima/examples/trends/../../DNest4/code/SamplerImpl.h
// Function: DNest4::Sampler<RVmodel>::do_bookkeeping()
void Sampler<ModelType>::do_bookkeeping()
{
	bool created_level = false;

	// Create a new level?
	if(!enough_levels(levels) &&
        (all_above.size() >= options.new_level_interval))
	{
		// Create the level
		std::sort(all_above.begin(), all_above.end());
		int index = static_cast<int>((1. - 1./compression)*all_above.size());
		std::cout<<"# Creating level "<<levels.size()<<" with log likelihood = ";
		std::cout<<std::setprecision(12);
		std::cout<<all_above[index].get_value()<<"."<<std::endl;

		levels.push_back(Level(all_above[index]));
		all_above.erase(all_above.begin(), all_above.begin() + index + 1);
		for(auto& a:above)
			a.clear();

		// If last level
		if(enough_levels(levels))
		{
            // Regularisation
            double reg = options.new_level_interval*sqrt(options.lambda);
			Level::renormalise_visits(levels, static_cast<int>(reg));
			all_above.clear();
            options.max_num_levels = levels.size();
            std::cout<<"# Done creating levels."<<std::endl;
		}
		else
		{
			// If it's not the last level, look for lagging particles
			kill_lagging_particles();
		}

		created_level = true;
	}

	// Recalculate log_X values of levels
	Level::recalculate_log_X(levels, compression,
                        options.new_level_interval*sqrt(options.lambda));

	// Save levels if one was created
	if(created_level)
		save_levels();

	if(count_mcmc_steps_since_save >= options.save_interval)
	{
		save_particle();

		// If a level was not created, save anyway because of the time
		if(!created_level)
			save_levels();
	}

    // Check for a new record holder
    auto indices = argsort(log_likelihoods);
    if(best_ever_log_likelihood < log_likelihoods[indices.back()])
    {
        best_ever_particle = particles[indices.back()];
        best_ever_log_likelihood = log_likelihoods[indices.back()];
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x630(%rdi), %r14
movq %r14, %rsi
callq 0x36288
testb %al, %al
jne 0x35b72
movq 0x668(%rbx), %rsi
movq 0x660(%rbx), %rdi
movq %rsi, %rax
subq %rdi, %rax
sarq $0x4, %rax
movl 0x3c(%rbx), %ecx
cmpq %rcx, %rax
jae 0x35b79
xorl %ebp, %ebp
jmp 0x35d5e
leaq 0x660(%rbx), %r15
callq 0x371ac
movsd 0x64a3(%rip), %xmm0     # 0x3c030
movapd %xmm0, %xmm1
divsd 0x30(%rbx), %xmm1
subsd %xmm1, %xmm0
movq 0x668(%rbx), %rax
subq 0x660(%rbx), %rax
sarq $0x4, %rax
movq %rax, %xmm1
punpckldq 0x6457(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x645f(%rip), %xmm1     # 0x3c020
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %ebp
movq 0x2e3bc(%rip), %r12     # 0x63f98
leaq 0x15dfb(%rip), %rsi     # 0x4b9de
movq %r12, %rdi
callq 0x6430
movq %rax, %rdi
movq 0x638(%rbx), %rax
subq 0x630(%rbx), %rax
pushq $0x38
popq %r13
cqto
idivq %r13
movq %rax, %rsi
callq 0x62f0
leaq 0x15ddc(%rip), %rsi     # 0x4b9f0
movq %rax, %rdi
callq 0x6430
movq (%r12), %rax
movq -0x18(%rax), %rax
movq $0xc, 0x8(%r12,%rax)
movslq %ebp, %rbp
movq 0x660(%rbx), %rax
shlq $0x4, %rbp
movsd (%rax,%rbp), %xmm0
movq %r12, %rdi
callq 0x6610
leaq 0x165b0(%rip), %rsi     # 0x4c1ff
movq %rax, %rdi
callq 0x6430
movq %rax, %rdi
callq 0x61c0
movq 0x660(%rbx), %rsi
addq %rbp, %rsi
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x3807c
movq %r14, %rdi
movq %r12, %rsi
callq 0x377b0
movq 0x660(%rbx), %rsi
leaq (%rsi,%rbp), %rdx
addq $0x10, %rdx
movq %r15, %rdi
callq 0x36d32
movq 0x6a0(%rbx), %rax
movq 0x6a8(%rbx), %rcx
cmpq %rcx, %rax
je 0x35cbe
movq (%rax), %rdx
cmpq %rdx, 0x8(%rax)
je 0x35cb8
movq %rdx, 0x8(%rax)
addq $0x18, %rax
jmp 0x35ca6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36288
testb %al, %al
je 0x35cea
movl 0x3c(%rbx), %eax
cvtsi2sd %rax, %xmm2
movsd 0x50(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x35cf4
sqrtsd %xmm0, %xmm0
jmp 0x35d03
movq %rbx, %rdi
callq 0x36d38
jmp 0x35d5b
movsd %xmm2, (%rsp)
callq 0x63a0
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %esi
movq %r14, %rdi
callq 0x381a4
movq 0x660(%rbx), %rax
cmpq %rax, 0x668(%rbx)
je 0x35d2a
movq %rax, 0x668(%rbx)
movq 0x638(%rbx), %rax
subq 0x630(%rbx), %rax
cqto
idivq %r13
movl %eax, 0x48(%rbx)
movq 0x2e251(%rip), %rdi     # 0x63f98
leaq 0x15cba(%rip), %rsi     # 0x4ba08
callq 0x6430
movq %rax, %rdi
callq 0x61c0
movb $0x1, %bpl
movsd 0x30(%rbx), %xmm2
movl 0x3c(%rbx), %eax
cvtsi2sd %rax, %xmm3
movsd 0x50(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x35d80
sqrtsd %xmm0, %xmm0
jmp 0x35d9b
movsd %xmm2, (%rsp)
movsd %xmm3, 0x8(%rsp)
callq 0x63a0
movsd 0x8(%rsp), %xmm3
movsd (%rsp), %xmm2
mulsd %xmm3, %xmm0
cvttsd2si %xmm0, %rsi
movq %r14, %rdi
movaps %xmm2, %xmm0
callq 0x38094
testb %bpl, %bpl
je 0x35dbc
movq %rbx, %rdi
callq 0x353c4
movl 0x694(%rbx), %eax
cmpl 0x40(%rbx), %eax
jb 0x35ddc
movq %rbx, %rdi
callq 0x36ff8
testb %bpl, %bpl
jne 0x35ddc
movq %rbx, %rdi
callq 0x353c4
leaq 0xe0(%rbx), %r14
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x33b03
leaq 0x620(%rbx), %r15
movq 0x8(%r12), %rax
movq -0x8(%rax), %rsi
shlq $0x4, %rsi
addq 0xe0(%rbx), %rsi
movq %r15, %rdi
callq 0x3843c
testb %al, %al
je 0x35e55
movq 0x18(%rsp), %rax
imulq $0x510, -0x8(%rax), %rsi # imm = 0x510
addq 0xc8(%rbx), %rsi
addq $0x110, %rbx            # imm = 0x110
movq %rbx, %rdi
callq 0x33b6a
movq 0x18(%rsp), %rax
movq -0x8(%rax), %rax
movq (%r14), %rcx
shlq $0x4, %rax
movups (%rcx,%rax), %xmm0
movups %xmm0, (%r15)
leaq 0x10(%rsp), %rdi
callq 0x34592
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x34592
movq %rbx, %rdi
callq 0x66e0
nop