// File: /workspace/github_cpp_makefile_star2_O1/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
movl 0x38(%rdi), %esi
imull 0x28(%rdi), %esi
leaq 0xf(%rsp), %rdx
movb $0x1, (%rdx)
leaq 0x20(%rsp), %rdi
leaq 0xe(%rsp), %rcx
callq 0x1998a
movq 0xd0(%rbx), %rax
cmpq 0xc8(%rbx), %rax
je 0x39c91
movsd 0xb783(%rip), %xmm0     # 0x452f0
movsd %xmm0, 0x10(%rsp)
xorl %r14d, %r14d
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
movabsq $0x2c3f35ba781948b1, %r12 # imm = 0x2C3F35BA781948B1
leaq 0x3f(%r15), %r13
xorl %ebp, %ebp
movq 0xf8(%rbx), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
callq 0x39968
ucomisd 0x10(%rsp), %xmm0
jbe 0x39bc4
movq 0xf8(%rbx), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
callq 0x39968
movsd %xmm0, 0x10(%rsp)
movq 0xf8(%rbx), %rax
movl (%rax,%r14,4), %esi
movq %rbx, %rdi
callq 0x39968
movsd 0xb719(%rip), %xmm1     # 0x452f8
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x6730
movsd 0x543c(%rip), %xmm2     # 0x3f030
addsd %xmm2, %xmm0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
movapd %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd 0x5a88(%rip), %xmm1     # 0x3f698
callq 0x66f0
movsd %xmm0, 0x18(%rsp)
movq 0x678(%rbx), %rdi
callq 0x3c02c
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x39c6d
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 %r15, %rcx
setbe %dl
movq $-0x2, %rsi
movl %r14d, %ecx
rolq %cl, %rsi
andq %rsi, -0x8(%rax,%rdx,8)
incl %ebp
movq 0xd0(%rbx), %rax
subq 0xc8(%rbx), %rax
incq %r14
sarq $0x4, %rax
imulq %r12, %rax
cmpq %rax, %r14
jb 0x39b90
jmp 0x39ca1
xorl %ebp, %ebp
movsd 0xb655(%rip), %xmm0     # 0x452f0
movsd %xmm0, 0x10(%rsp)
movl 0x38(%rbx), %eax
imull 0x28(%rbx), %eax
cmpl %eax, %ebp
jae 0x39e89
movq 0xd0(%rbx), %rax
cmpq 0xc8(%rbx), %rax
je 0x39e89
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
xorl %r15d, %r15d
leaq 0x3f(%rbp), %r12
movq 0x192bc(%rip), %r14     # 0x52f98
leaq 0x3f(%r15), %rax
testq %r15, %r15
cmovnsq %r15, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x20(%rsp), %rax
movq %r15, %rcx
andq %r12, %rcx
xorl %edx, %edx
cmpq %rbp, %rcx
setbe %dl
movq -0x8(%rax,%rdx,8), %rax
btq %r15, %rax
jb 0x39e5d
movq 0x678(%rbx), %rdi
movl 0x38(%rbx), %esi
imull 0x28(%rbx), %esi
callq 0x3c1d6
movslq %eax, %r13
leaq 0x3f(%r13), %rax
testq %r13, %r13
cmovnsq %r13, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x20(%rsp), %rax
movq %r13, %rcx
andq %r12, %rcx
xorl %edx, %edx
cmpq %rbp, %rcx
setbe %dl
movq -0x8(%rax,%rdx,8), %rax
btq %r13, %rax
jae 0x39d11
movq 0x678(%rbx), %rdi
callq 0x3c02c
movsd %xmm0, 0x18(%rsp)
movq 0xf8(%rbx), %rax
movl (%rax,%r13,4), %esi
movq %rbx, %rdi
callq 0x39968
subsd 0x10(%rsp), %xmm0
callq 0x6730
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x39d11
movq 0xc8(%rbx), %rax
imulq $0x510, %r13, %rsi      # imm = 0x510
addq %rax, %rsi
imulq $0x510, %r15, %rdi      # imm = 0x510
addq %rax, %rdi
callq 0x3621c
movq 0xe0(%rbx), %rax
movq %r13, %rcx
shlq $0x4, %rcx
movq %r15, %rdx
shlq $0x4, %rdx
movupd (%rax,%rcx), %xmm0
movupd %xmm0, (%rax,%rdx)
movq 0xf8(%rbx), %rax
movl (%rax,%r13,4), %ecx
movl %ecx, (%rax,%r15,4)
incl 0x197a4(%rip)           # 0x53590
movl $0x1d, %edx
movq %r14, %rdi
leaq 0xd898(%rip), %rsi      # 0x47693
callq 0x64a0
movl $0x13, %edx
movq %r14, %rdi
leaq 0xd8a2(%rip), %rsi      # 0x476b1
callq 0x64a0
movl 0x19776(%rip), %esi     # 0x53590
movq %r14, %rdi
callq 0x62f0
movl $0x7, %edx
movq %r14, %rdi
leaq 0xd894(%rip), %rsi      # 0x476c5
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 0xd0(%rbx), %rax
subq 0xc8(%rbx), %rax
incq %r15
sarq $0x4, %rax
movabsq $0x2c3f35ba781948b1, %rcx # imm = 0x2C3F35BA781948B1
imulq %rcx, %rax
cmpq %rax, %r15
jb 0x39cdc
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x39eb9
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x39ece
jmp 0x39ece
jmp 0x39ece
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x39f01
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
callq 0x6710
nop