// File: /workspace/github_cpp_makefile_star2_O3/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 0x3574c
cmpl $0x0, 0x28(%r14)
je 0x3574c
xorl %ebx, %ebx
xorl %r15d, %r15d
movq 0x648(%r14), %rdi
addq %rbx, %rdi
movq %r13, %rsi
callq 0x35b80
incq %r15
movl 0x28(%r14), %eax
addq $0x18, %rbx
cmpq %rax, %r15
jb 0x3572a
movq 0x20(%r14), %rdi
callq 0x382f8
movl 0x60(%r14), %ecx
testl %ecx, %ecx
je 0x35774
movl 0x690(%r14), %eax
testl %eax, %eax
je 0x35774
xorl %edx, %edx
divl %ecx
testl %edx, %edx
je 0x35932
movq %r14, %rdi
movl %ebp, %esi
callq 0x35cb0
movq 0x20(%r14), %rdi
callq 0x382f8
testl %ebp, %ebp
jne 0x3571a
movl 0x44(%r14), %eax
imull 0x28(%r14), %eax
addq %rax, 0x698(%r14)
addl %eax, 0x694(%r14)
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x341aa
movq 0x648(%r14), %rax
movq 0x650(%r14), %rcx
cmpq %rcx, %rax
je 0x35896
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 0x35889
movq (%rax), %r9
movl $0x28, %r10d
movq %rdi, %r11
movdqu (%r9,%r10), %xmm0
movdqu (%r8,%r10), %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(%rdx,%r10), %xmm1
movdqu (%rdx,%r10), %xmm2
paddq %xmm0, %xmm2
movdqu %xmm2, (%rdx,%r10)
movdqu -0x10(%r9,%r10), %xmm0
movdqu -0x10(%r8,%r10), %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(%rdx,%r10)
addq $0x38, %r10
decq %r11
jne 0x3580e
addq $0x18, %rax
cmpq %rcx, %rax
jne 0x357f9
movq 0x6a0(%r14), %r13
movq 0x6a8(%r14), %rbx
cmpq %rbx, %r13
je 0x35901
movq (%r13), %rbp
movq 0x8(%r13), %r15
cmpq %r15, %rbp
je 0x358fb
movq 0x668(%r14), %rsi
cmpq 0x670(%r14), %rsi
je 0x358d9
movdqu (%rbp), %xmm0
movdqu %xmm0, (%rsi)
addq $0x10, 0x668(%r14)
jmp 0x358e4
movq %r12, %rdi
movq %rbp, %rdx
callq 0x37498
addq $0x10, %rbp
cmpq %r15, %rbp
jne 0x358b6
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
je 0x358fb
movq %rax, 0x8(%r13)
addq $0x18, %r13
jmp 0x358a4
movq %r14, %rdi
callq 0x35de8
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
movl 0x4(%rsp), %ebp
movq 0x8(%rsp), %r13
je 0x3571a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
jmp 0x3571a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x35943
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3595d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6460
movq %rbx, %rdi
callq 0x6710
nop