// File: /workspace/github_cpp_makefile_star2_O1/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 0x38bac
testb %al, %al
jne 0x38396
movq 0x668(%rbx), %r15
movq 0x660(%rbx), %r12
movq %r15, %rax
subq %r12, %rax
sarq $0x4, %rax
movl 0x3c(%rbx), %ecx
cmpq %rcx, %rax
jae 0x3839d
xorl %ebp, %ebp
jmp 0x38672
cmpq %r15, %r12
je 0x383c5
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x3a153
movq %r12, %rdi
movq %r15, %rsi
callq 0x3a206
movsd 0x6c63(%rip), %xmm0     # 0x3f030
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 0x6c17(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x6c1f(%rip), %xmm1     # 0x3f020
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %ebp
movq 0x1ab7c(%rip), %r15     # 0x52f98
leaq 0xf22e(%rip), %rsi      # 0x47651
movl $0x11, %edx
movq %r15, %rdi
callq 0x64a0
movq 0x638(%rbx), %rax
subq 0x630(%rbx), %rax
sarq $0x3, %rax
movabsq $0x6db6db6db6db6db7, %rsi # imm = 0x6DB6DB6DB6DB6DB7
imulq %rax, %rsi
movq %r15, %rdi
callq 0x62f0
leaq 0xf204(%rip), %rsi      # 0x47663
movl $0x17, %edx
movq %rax, %rdi
callq 0x64a0
movq (%r15), %rax
movq -0x18(%rax), %rax
movq $0xc, 0x8(%r15,%rax)
movslq %ebp, %r13
movq 0x660(%rbx), %rax
shlq $0x4, %r13
movsd (%rax,%r13), %xmm0
movq %r15, %rdi
callq 0x6630
movq %rax, %r12
leaq 0xf9cd(%rip), %rsi      # 0x47e6f
movl $0x1, %edx
movq %rax, %rdi
callq 0x64a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x6430
movsbl %al, %esi
movq %r12, %rdi
callq 0x6030
movq %rax, %rdi
callq 0x6300
movq 0x660(%rbx), %rsi
addq %r13, %rsi
leaq 0x10(%rsp), %rdi
callq 0x3b1e6
movq 0x638(%rbx), %rsi
cmpq 0x640(%rbx), %rsi
je 0x3852e
movq 0x40(%rsp), %rax
movq %rax, 0x30(%rsi)
movupd 0x10(%rsp), %xmm0
movupd 0x20(%rsp), %xmm1
movupd 0x30(%rsp), %xmm2
movupd %xmm2, 0x20(%rsi)
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x38, 0x638(%rbx)
jmp 0x3853b
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x3a694
movq 0x660(%rbx), %r12
addq %r12, %r13
addq $0x10, %r13
cmpq %r13, %r12
je 0x38581
movq 0x668(%rbx), %rdx
subq %r13, %rdx
je 0x38565
movq %r12, %rdi
movq %r13, %rsi
callq 0x6650
movq 0x668(%rbx), %rax
movq %rax, %rcx
subq %r13, %rcx
addq %rcx, %r12
cmpq %r12, %rax
je 0x38581
movq %r12, 0x668(%rbx)
movq 0x6a0(%rbx), %rax
movq 0x6a8(%rbx), %rcx
cmpq %rcx, %rax
je 0x385a7
movq (%rax), %rdx
cmpq %rdx, 0x8(%rax)
je 0x385a1
movq %rdx, 0x8(%rax)
addq $0x18, %rax
jmp 0x3858f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x38bac
testb %al, %al
je 0x385d6
movl 0x3c(%rbx), %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
movsd 0x50(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x385e3
sqrtsd %xmm0, %xmm0
jmp 0x385f2
movq %rbx, %rdi
callq 0x39b22
jmp 0x3866f
movsd %xmm2, (%rsp)
callq 0x63b0
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %esi
movq %r14, %rdi
callq 0x3b336
movq 0x660(%rbx), %rax
cmpq %rax, 0x668(%rbx)
je 0x38619
movq %rax, 0x668(%rbx)
movq 0x638(%rbx), %rax
subq 0x630(%rbx), %rax
shrq $0x3, %rax
imull $0xb6db6db7, %eax, %eax # imm = 0xB6DB6DB7
movl %eax, 0x48(%rbx)
leaq 0xf040(%rip), %rsi      # 0x4767b
movl $0x17, %edx
movq %r15, %rdi
callq 0x64a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x6430
movsbl %al, %esi
movq %r15, %rdi
callq 0x6030
movq %rax, %rdi
callq 0x6300
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 0x38694
sqrtsd %xmm0, %xmm0
jmp 0x386af
movsd %xmm2, (%rsp)
movsd %xmm3, 0x8(%rsp)
callq 0x63b0
movsd 0x8(%rsp), %xmm3
movsd (%rsp), %xmm2
mulsd %xmm3, %xmm0
cvttsd2si %xmm0, %rsi
movq %r14, %rdi
movaps %xmm2, %xmm0
callq 0x3b200
testb %bpl, %bpl
je 0x386d0
movq %rbx, %rdi
callq 0x37a8a
movl 0x694(%rbx), %eax
cmpl 0x40(%rbx), %eax
jb 0x386f0
movq %rbx, %rdi
callq 0x39f0a
testb %bpl, %bpl
jne 0x386f0
movq %rbx, %rdi
callq 0x37a8a
leaq 0xe0(%rbx), %r14
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x3616e
leaq 0x620(%rbx), %r15
movq 0x8(%r12), %rax
movq -0x8(%rax), %rsi
shlq $0x4, %rsi
addq 0xe0(%rbx), %rsi
movq %r15, %rdi
callq 0x3b61c
testb %al, %al
je 0x38769
movq 0x18(%rsp), %rax
imulq $0x510, -0x8(%rax), %rsi # imm = 0x510
addq 0xc8(%rbx), %rsi
addq $0x110, %rbx            # imm = 0x110
movq %rbx, %rdi
callq 0x3621c
movq 0x18(%rsp), %rax
movq -0x8(%rax), %rax
movq (%r14), %rcx
shlq $0x4, %rax
movups (%rcx,%rax), %xmm0
movups %xmm0, (%r15)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x38780
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x387a9
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
movq %rbx, %rdi
callq 0x6710
nop