// File: /workspace/github_cpp_makefile_star2_O3/j-faria[P]kima/examples/trends/../../DNest4/code/SamplerImpl.h
// Function: DNest4::Sampler<RVmodel>::kill_lagging_particles()
void Sampler<ModelType>::kill_lagging_particles()
{
	// Count the number of deletions
	static unsigned int deletions = 0;

	// Flag each particle as good or bad
	std::vector<bool> good(num_threads*options.num_particles, true);

	// How good is the best particle?
	double max_log_push = -std::numeric_limits<double>::max();

	unsigned int num_bad = 0;
    double kill_probability = 0.0;
	for(size_t i=0; i<particles.size(); ++i)
	{
		if(log_push(level_assignments[i]) > max_log_push)
			max_log_push = log_push(level_assignments[i]);
        kill_probability = pow(1.0 - 1.0/(1.0 + exp(-log_push(level_assignments[i]) - 4.0)), 3);

		if(rngs[0].rand() <= kill_probability)
		{
			good[i] = false;
			++num_bad;
		}
	}

	if(num_bad < num_threads*options.num_particles)
	{
		// Replace bad particles with copies of good ones
		for(size_t i=0; i<particles.size(); ++i)
		{
			if(!good[i])
			{
				// Choose a replacement particle. Higher prob
				// of selecting better particles.
				int i_copy;
				do
				{
					i_copy = rngs[0].rand_int(num_threads*options.num_particles);
				}while(!good[i_copy] ||
			        rngs[0].rand() >= exp(log_push(level_assignments[i_copy]) - max_log_push));

				particles[i] = particles[i_copy];
				log_likelihoods[i] = log_likelihoods[i_copy];
				level_assignments[i] = level_assignments[i_copy];
				++deletions;

				std::cout<<"# Replacing lagging particle.";
				std::cout<<" This has happened "<<deletions;
				std::cout<<" times."<<std::endl;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
movl 0x38(%rdi), %esi
imull 0x28(%rdi), %esi
leaq 0xf(%rsp), %rdx
movb $0x1, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0xe(%rsp), %rcx
callq 0x192a0
movq 0xd0(%rbx), %rax
movabsq $0x2c3f35ba781948b1, %r15 # imm = 0x2C3F35BA781948B1
cmpq 0xc8(%rbx), %rax
je 0x37733
movsd 0xb235(%rip), %xmm0     # 0x42850
movsd %xmm0, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x3f(%rbp), %r13
xorl %r12d, %r12d
movq 0xf8(%rbx), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
callq 0x37402
ucomisd 0x10(%rsp), %xmm0
jbe 0x3765f
movq 0xf8(%rbx), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
callq 0x37402
movsd %xmm0, 0x10(%rsp)
movq 0xf8(%rbx), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
callq 0x37402
movsd 0xb1de(%rip), %xmm1     # 0x42858
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x6730
movsd 0x59a1(%rip), %xmm2     # 0x3d030
addsd %xmm2, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd 0x6015(%rip), %xmm1     # 0x3d6c0
callq 0x66f0
movsd %xmm0, 0x18(%rsp)
movq 0x678(%rbx), %rdi
callq 0x39a4e
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x37709
leaq 0x3f(%r14), %rax
testq %r14, %r14
cmovnsq %r14, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x20(%rsp), %rax
movq %r14, %rcx
andq %r13, %rcx
xorl %edx, %edx
cmpq %rbp, %rcx
setbe %dl
movq $-0x2, %rsi
movl %r14d, %ecx
rolq %cl, %rsi
andq %rsi, -0x8(%rax,%rdx,8)
incl %r12d
incq %r14
movq 0xc8(%rbx), %rax
movq 0xd0(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r15, %rdx
cmpq %rdx, %r14
jb 0x3762b
jmp 0x37747
xorl %r12d, %r12d
movsd 0xb112(%rip), %xmm0     # 0x42850
movsd %xmm0, 0x10(%rsp)
movq %rax, %rcx
movl 0x38(%rbx), %edx
imull 0x28(%rbx), %edx
cmpl %edx, %r12d
jae 0x37924
cmpq %rax, %rcx
je 0x37924
xorl %r12d, %r12d
leaq 0x3f(%rbp), %r13
movq 0x1882a(%rip), %r14     # 0x4ff98
leaq 0x3f(%r12), %rdx
testq %r12, %r12
cmovnsq %r12, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq 0x20(%rsp), %rdx
movq %r12, %rsi
andq %r13, %rsi
xorl %edi, %edi
cmpq %rbp, %rsi
setbe %dil
movq -0x8(%rdx,%rdi,8), %rdx
btq %r12, %rdx
jb 0x3790a
movq 0x678(%rbx), %rdi
movl 0x38(%rbx), %esi
imull 0x28(%rbx), %esi
callq 0x39bf8
movslq %eax, %r15
leal 0x3f(%r15), %eax
testl %r15d, %r15d
cmovnsl %r15d, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x20(%rsp), %rax
movq %r15, %rcx
andq %r13, %rcx
xorl %edx, %edx
cmpq %rbp, %rcx
setbe %dl
movq -0x8(%rax,%rdx,8), %rax
btq %r15, %rax
jae 0x377a5
movq 0x678(%rbx), %rdi
callq 0x39a4e
movsd %xmm0, 0x18(%rsp)
movq 0xf8(%rbx), %rax
movl (%rax,%r15,4), %esi
movq %rbx, %rdi
callq 0x37402
subsd 0x10(%rsp), %xmm0
callq 0x6730
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x377a5
movq 0xc8(%rbx), %rax
imulq $0x510, %r15, %rsi      # imm = 0x510
addq %rax, %rsi
imulq $0x510, %r12, %rdi      # imm = 0x510
addq %rax, %rdi
callq 0x33c8c
movq 0xe0(%rbx), %rax
movq %r15, %rcx
shlq $0x4, %rcx
movq %r12, %rdx
shlq $0x4, %rdx
movupd (%rax,%rcx), %xmm0
movupd %xmm0, (%rax,%rdx)
movq 0xf8(%rbx), %rax
movl (%rax,%r15,4), %ecx
movl %ecx, (%rax,%r12,4)
incl 0x18d0f(%rip)           # 0x50590
movl $0x1d, %edx
movq %r14, %rdi
leaq 0xd2d3(%rip), %rsi      # 0x44b63
callq 0x64a0
movl $0x13, %edx
movq %r14, %rdi
leaq 0xd2dd(%rip), %rsi      # 0x44b81
callq 0x64a0
movl 0x18ce1(%rip), %esi     # 0x50590
movq %r14, %rdi
callq 0x62f0
movl $0x7, %edx
movq %r14, %rdi
leaq 0xd2cf(%rip), %rsi      # 0x44b95
callq 0x64a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x6430
movsbl %al, %esi
movq %r14, %rdi
callq 0x6030
movq %rax, %rdi
callq 0x6300
movq 0xc8(%rbx), %rax
movq 0xd0(%rbx), %rcx
movabsq $0x2c3f35ba781948b1, %r15 # imm = 0x2C3F35BA781948B1
incq %r12
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r15, %rdx
cmpq %rdx, %r12
jb 0x3776e
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3793b
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x37950
jmp 0x37950
jmp 0x37950
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3796a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
movq %rbx, %rdi
callq 0x6710