// File: /workspace/github_cpp_makefile_star2_O2/j-faria[P]kima/examples/trends/../../DNest4/code/SamplerImpl.h
// Function: DNest4::Sampler<RVmodel>::run_thread(unsigned int)
void Sampler<ModelType>::run_thread(unsigned int thread)
{
	// Alternate between MCMC and bookkeeping
	while(true)
	{
		// Thread zero takes full responsibility for some tasks
		// Setting up copies of levels
		if(thread == 0)
		{
			// Each thread will write over its own copy of the levels
			for(unsigned int i=0; i<num_threads; ++i)
				copies_of_levels[i] = levels;
		}

#ifndef NO_THREADS
		// Wait for all threads to get here before proceeding
		barrier->wait();
#endif

		// Check for termination
		if(options.max_num_saves != 0 && count_saves != 0 &&
				(count_saves%options.max_num_saves == 0))
			return;

		// Do the MCMC (all threads do this!)
		mcmc_thread(thread);

#ifndef NO_THREADS
		barrier->wait();
#endif

		// Thread zero takes full responsibility for some tasks
		if(thread == 0)
		{
			// Count the MCMC steps done
			count_mcmc_steps += num_threads*options.thread_steps;
            count_mcmc_steps_since_save += num_threads*options.thread_steps;

			// Go through copies of levels and apply diffs to levels
			std::vector<Level> levels_orig = levels;
			for(const auto& _levels: copies_of_levels)
			{
				for(size_t i=0; i<levels.size(); ++i)
				{
					levels[i].increment_accepts(_levels[i].get_accepts()
														- levels_orig[i].get_accepts());
					levels[i].increment_tries(_levels[i].get_tries()
														- levels_orig[i].get_tries());
					levels[i].increment_visits(_levels[i].get_visits()
														- levels_orig[i].get_visits());
					levels[i].increment_exceeds(_levels[i].get_exceeds()
														- levels_orig[i].get_exceeds());
				}
			}

			// Combine into a single vector
			for(auto& a: above)
			{
				for(const auto& element: a)
					all_above.push_back(element);
				a.clear();
			}

			// Do the bookkeeping
			do_bookkeeping();
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, 0x4(%rsp)
movq %rdi, %r14
leaq 0x630(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0x660(%rdi), %r12
cmpl $0x0, 0x4(%rsp)
je 0x356f7
movq 0x20(%r14), %rdi
callq 0x37a3e
movl 0x60(%r14), %ecx
testl %ecx, %ecx
je 0x3558d
movl 0x690(%r14), %eax
testl %eax, %eax
je 0x3558d
xorl %edx, %edx
divl %ecx
testl %edx, %edx
je 0x35727
movq %r14, %rdi
movl 0x4(%rsp), %ebx
movl %ebx, %esi
callq 0x35a00
movq 0x20(%r14), %rdi
callq 0x37a3e
testl %ebx, %ebx
jne 0x35565
movl 0x44(%r14), %eax
imull 0x28(%r14), %eax
addq %rax, 0x698(%r14)
addl %eax, 0x694(%r14)
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x342ea
movq 0x648(%r14), %rcx
movq 0x650(%r14), %rsi
movq 0x630(%r14), %rdi
movq 0x638(%r14), %rax
subq %rdi, %rax
cqto
pushq $0x38
popq %r8
idivq %r8
pushq $0x28
popq %r11
cmpq %rsi, %rcx
je 0x3569b
movq 0x10(%rsp), %rdx
movq %r11, %r8
movq %rax, %r9
subq $0x1, %r9
jb 0x35692
movq (%rcx), %r10
movdqu (%r10,%r8), %xmm0
movdqu (%rdx,%r8), %xmm1
psubq %xmm1, %xmm0
psllq $0x20, %xmm0
pshufd $0xed, %xmm0, %xmm0     # xmm0 = xmm0[1,3,2,3]
movdqa %xmm0, %xmm1
psrad $0x1f, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqu -0x10(%rdi,%r8), %xmm1
movdqu (%rdi,%r8), %xmm2
paddq %xmm0, %xmm2
movdqu %xmm2, (%rdi,%r8)
movdqu -0x10(%r10,%r8), %xmm0
movdqu -0x10(%rdx,%r8), %xmm2
psubq %xmm2, %xmm0
psllq $0x20, %xmm0
pshufd $0xed, %xmm0, %xmm0     # xmm0 = xmm0[1,3,2,3]
movdqa %xmm0, %xmm2
psrad $0x1f, %xmm2
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
paddq %xmm1, %xmm0
movdqu %xmm0, -0x10(%rdi,%r8)
addq $0x38, %r8
jmp 0x3560e
addq $0x18, %rcx
jmp 0x355fa
movq 0x6a0(%r14), %r13
movq 0x6a8(%r14), %r15
cmpq %r15, %r13
je 0x356e0
movq (%r13), %rbp
movq 0x8(%r13), %rbx
cmpq %rbx, %rbp
je 0x356cc
movq %r12, %rdi
movq %rbp, %rsi
callq 0x35b10
addq $0x10, %rbp
jmp 0x356b6
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
je 0x356da
movq %rax, 0x8(%r13)
addq $0x18, %r13
jmp 0x356a9
movq %r14, %rdi
callq 0x35b2e
leaq 0x10(%rsp), %rdi
callq 0x2168a
jmp 0x3555a
xorl %r15d, %r15d
xorl %r13d, %r13d
movl 0x28(%r14), %eax
cmpq %rax, %r13
jae 0x35565
movq 0x648(%r14), %rdi
addq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x35906
incq %r13
addq $0x18, %r15
jmp 0x356fd
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x35738
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x2168a
movq %rbx, %rdi
callq 0x66e0
nop