// File: j-faria[P]kima/examples/trends/../../DNest4/code/SamplerImpl.h
// Function: DNest4::Sampler<RVmodel>::update_level_assignment(unsigned int, unsigned int)
void Sampler<ModelType>::update_level_assignment(unsigned int thread,
													unsigned int which)
{
	// Reference to the RNG for this thread
	RNG& rng = rngs[thread];

	// Reference to this thread's copy of levels
	std::vector<Level>& _levels = copies_of_levels[thread];

	// Generate proposal
	int proposal = static_cast<int>(level_assignments[which])
						+ static_cast<int>(pow(10., 2.*rng.rand())*rng.randn());

	// If the proposal was to not move, go +- one level
	if(proposal == static_cast<int>(level_assignments[which]))
		proposal = ((rng.rand() < 0.5)?(proposal-1):(proposal+1));

	// Wrap into allowed range
	proposal = DNest4::mod(proposal, static_cast<int>(_levels.size()));

	// Acceptance probability
	double log_A = -_levels[proposal].get_log_X()
					+ _levels[level_assignments[which]].get_log_X();

	// Pushing up part
	log_A += log_push(proposal) - log_push(level_assignments[which]);

	// Enforce uniform exploration part (if all levels exist)
	if(_levels.size() == options.max_num_levels)
		log_A += options.beta*log((double)(_levels[level_assignments[which]].get_tries() + 1)/(double)(_levels[proposal].get_tries() + 1));

	// Prevent exponentiation of huge numbers
	if(log_A > 0.)
		log_A = 0.;

	// Make a LikelihoodType for the proposal
	if(rng.rand() <= exp(log_A) && _levels[proposal].get_log_likelihood() < log_likelihoods[which])
	{
		// Accept
		level_assignments[which] = static_cast<unsigned int>(proposal);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x48(%rbp)
addq $0x678, %rdi            # imm = 0x678
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xa8770
movq -0x48(%rbp), %rdi
movq %rax, -0x18(%rbp)
addq $0x648, %rdi            # imm = 0x648
movl -0xc(%rbp), %eax
movl %eax, %esi
callq 0xaa000
movq -0x48(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0xf8, %rdi
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0xabd30
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb26f0
movsd 0xb8fa(%rip), %xmm1     # 0xb7150
mulsd %xmm0, %xmm1
movsd 0xbece(%rip), %xmm0     # 0xb7730
callq 0x6820
movsd %xmm0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb2720
movl -0x4c(%rbp), %eax
movq -0x48(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
addq $0xf8, %rdi
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0xabd30
movq %rax, %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jne 0xab8e6
movq -0x18(%rbp), %rdi
callq 0xb26f0
movaps %xmm0, %xmm1
movsd 0xb8d2(%rip), %xmm0     # 0xb7198
ucomisd %xmm1, %xmm0
jbe 0xab8d7
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xab8e0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x20(%rbp), %rdi
callq 0xa41f0
movl -0x6c(%rbp), %edi
movl %eax, %esi
callq 0xb3430
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0xaa4b0
movq %rax, %rdi
callq 0xa9370
movq -0x48(%rbp), %rdi
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
addq $0xf8, %rdi
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0xabd30
movq -0x68(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xaa4b0
movq %rax, %rdi
callq 0xa9370
movq -0x48(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x24(%rbp), %esi
callq 0xacd30
movq -0x48(%rbp), %rdi
movsd %xmm0, -0x58(%rbp)
addq $0xf8, %rdi
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0xabd30
movq -0x48(%rbp), %rdi
movl (%rax), %esi
callq 0xacd30
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
subsd %xmm1, %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0xa41f0
movq -0x48(%rbp), %rcx
movl 0x48(%rcx), %ecx
cmpq %rcx, %rax
jne 0xaba68
movq -0x48(%rbp), %rdi
movsd 0x58(%rdi), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
addq $0xf8, %rdi
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0xabd30
movq -0x88(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0xaa4b0
movq %rax, %rdi
callq 0xa9400
incl %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0xaa4b0
movq %rax, %rdi
callq 0xa9400
movsd -0x80(%rbp), %xmm0
incl %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
callq 0x6430
movaps %xmm0, %xmm2
movsd -0x78(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xaba7e
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb26f0
movsd %xmm0, -0x90(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x6870
movsd -0x90(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0xabb13
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0xaa4b0
movq %rax, %rdi
callq 0xa9390
movq -0x48(%rbp), %rdi
movq %rax, -0x98(%rbp)
addq $0xe0, %rdi
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0xa2260
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0xb1a20
testb $0x1, %al
jne 0xabaed
jmp 0xabb13
movq -0x48(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, -0x9c(%rbp)
addq $0xf8, %rdi
movl -0x10(%rbp), %eax
movl %eax, %esi
callq 0xabd30
movl -0x9c(%rbp), %ecx
movl %ecx, (%rax)
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)