// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movq %rdi, %r14
leaq 0x630(%rdi), %r13
leaq 0x660(%rdi), %r12
movl %esi, 0x4(%rsp)
movq %r13, 0x8(%rsp)
testl %ebp, %ebp
jne 0x37ce4
cmpl $0x0, 0x28(%r14)
je 0x37ce4
xorl %ebx, %ebx
xorl %r15d, %r15d
movq 0x648(%r14), %rdi
addq %rbx, %rdi
movq %r13, %rsi
callq 0x380ee
incq %r15
movl 0x28(%r14), %eax
addq $0x18, %rbx
cmpq %rax, %r15
jb 0x37cc2
movq 0x20(%r14), %rdi
callq 0x3a898
movl 0x60(%r14), %ecx
testl %ecx, %ecx
je 0x37d0c
movl 0x690(%r14), %eax
testl %eax, %eax
je 0x37d0c
xorl %edx, %edx
divl %ecx
testl %edx, %edx
je 0x37e90
movq %r14, %rdi
movl %ebp, %esi
callq 0x3821a
movq 0x20(%r14), %rdi
callq 0x3a898
testl %ebp, %ebp
jne 0x37cb2
movl 0x44(%r14), %eax
imull 0x28(%r14), %eax
addq %rax, 0x698(%r14)
addl %eax, 0x694(%r14)
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x3673a
movq 0x648(%r14), %rax
movq 0x650(%r14), %rcx
cmpq %rcx, %rax
je 0x37df9
movq 0x630(%r14), %rdx
movq 0x638(%r14), %rsi
movq %rsi, %rdi
subq %rdx, %rdi
sarq $0x3, %rdi
movabsq $0x6db6db6db6db6db7, %r8 # imm = 0x6DB6DB6DB6DB6DB7
imulq %r8, %rdi
movq 0x10(%rsp), %r8
cmpq $0x1, %rdi
adcq $0x0, %rdi
cmpq %rdx, %rsi
je 0x37df0
movq (%rax), %r9
movl $0x30, %r10d
movq %rdi, %r11
movl -0x8(%r9,%r10), %ebx
subl -0x8(%r8,%r10), %ebx
movslq %ebx, %rbx
addq %rbx, -0x8(%rdx,%r10)
movl (%r9,%r10), %ebx
subl (%r8,%r10), %ebx
movslq %ebx, %rbx
addq %rbx, (%rdx,%r10)
movl -0x18(%r9,%r10), %ebx
subl -0x18(%r8,%r10), %ebx
movslq %ebx, %rbx
addq %rbx, -0x18(%rdx,%r10)
movl -0x10(%r9,%r10), %ebx
subl -0x10(%r8,%r10), %ebx
movslq %ebx, %rbx
addq %rbx, -0x10(%rdx,%r10)
addq $0x38, %r10
decq %r11
jne 0x37da2
addq $0x18, %rax
cmpq %rcx, %rax
jne 0x37d91
movq 0x6a0(%r14), %r13
movq 0x6a8(%r14), %rbx
cmpq %rbx, %r13
je 0x37e5f
movq (%r13), %rbp
movq 0x8(%r13), %r15
cmpq %r15, %rbp
je 0x37e4b
movq 0x668(%r14), %rsi
cmpq 0x670(%r14), %rsi
je 0x37e3a
movups (%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x668(%r14)
jmp 0x37e45
movq %r12, %rdi
movq %rbp, %rdx
callq 0x399fe
addq $0x10, %rbp
jmp 0x37e14
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
je 0x37e59
movq %rax, 0x8(%r13)
addq $0x18, %r13
jmp 0x37e07
movq %r14, %rdi
callq 0x38352
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movl 0x4(%rsp), %ebp
movq 0x8(%rsp), %r13
je 0x37cb2
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
jmp 0x37cb2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x37ea1
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x37ebb
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
movq %rbx, %rdi
callq 0x6710
nop