// File: /workspace/github_cpp_makefile_star2_O3/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 0x36646
testb %al, %al
jne 0x35e2c
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 0x35e33
xorl %ebp, %ebp
jmp 0x36118
cmpq %r15, %r12
je 0x35e6b
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x37bbb
movq %r12, %rdi
movq %r15, %rsi
callq 0x37c6e
movq 0x660(%rbx), %r15
movq 0x668(%rbx), %rax
jmp 0x35e6e
movq %r15, %rax
subq %r15, %rax
movsd 0x71b7(%rip), %xmm0     # 0x3d030
movapd %xmm0, %xmm1
divsd 0x30(%rbx), %xmm1
subsd %xmm1, %xmm0
sarq $0x4, %rax
movq %rax, %xmm1
punpckldq 0x7179(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x7181(%rip), %xmm1     # 0x3d020
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %ebp
movq 0x1a0de(%rip), %r15     # 0x4ff98
leaq 0xec60(%rip), %rsi      # 0x44b21
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 0xec36(%rip), %rsi      # 0x44b33
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 0xf42f(%rip), %rsi      # 0x4536f
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 0x38c46
movq 0x638(%rbx), %rsi
cmpq 0x640(%rbx), %rsi
je 0x35fcc
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 0x35fd9
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x380f4
movq 0x660(%rbx), %r12
addq %r12, %r13
addq $0x10, %r13
cmpq %r13, %r12
je 0x36027
movq 0x668(%rbx), %rdx
subq %r13, %rdx
je 0x3600f
movq %r12, %rdi
movq %r13, %rsi
callq 0x6650
movq 0x668(%rbx), %rax
movq %rax, %rcx
jmp 0x36015
movq %r13, %rax
movq %r13, %rcx
subq %r13, %rax
addq %rax, %r12
cmpq %r12, %rcx
je 0x36027
movq %r12, 0x668(%rbx)
movq 0x6a0(%rbx), %rax
movq 0x6a8(%rbx), %rcx
cmpq %rcx, %rax
je 0x3604d
movq (%rax), %rdx
cmpq %rdx, 0x8(%rax)
je 0x36047
movq %rdx, 0x8(%rax)
addq $0x18, %rax
jmp 0x36035
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36646
testb %al, %al
je 0x3607c
movl 0x3c(%rbx), %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
movsd 0x50(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x36089
sqrtsd %xmm0, %xmm0
jmp 0x36098
movq %rbx, %rdi
callq 0x375bc
jmp 0x36115
movsd %xmm2, (%rsp)
callq 0x63b0
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %esi
movq %r14, %rdi
callq 0x38d90
movq 0x660(%rbx), %rax
cmpq %rax, 0x668(%rbx)
je 0x360bf
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 0xea6a(%rip), %rsi      # 0x44b4b
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 0x3613a
sqrtsd %xmm0, %xmm0
jmp 0x36155
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 0x38c60
testb %bpl, %bpl
je 0x36176
movq %rbx, %rdi
callq 0x354f2
movl 0x694(%rbx), %eax
cmpl 0x40(%rbx), %eax
jb 0x36196
movq %rbx, %rdi
callq 0x37972
testb %bpl, %bpl
jne 0x36196
movq %rbx, %rdi
callq 0x354f2
leaq 0xe0(%rbx), %r14
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x33b58
leaq 0x620(%rbx), %r15
movq 0x8(%r12), %rax
movq -0x8(%rax), %rsi
shlq $0x4, %rsi
addq 0xe0(%rbx), %rsi
movq %r15, %rdi
callq 0x3906e
testb %al, %al
je 0x3620f
movq 0x18(%rsp), %rax
imulq $0x510, -0x8(%rax), %rsi # imm = 0x510
addq 0xc8(%rbx), %rsi
addq $0x110, %rbx            # imm = 0x110
movq %rbx, %rdi
callq 0x33c8c
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 0x36226
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 0x3624f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
movq %rbx, %rdi
callq 0x6710
nop