// File: /workspace/github_c_makefile_star2_O2/waynebhayes[P]SAHap/src/Genome.cpp
// Function: SAHap::Genome::findPbad(double, unsigned long long)
double Genome::findPbad(double temperature, iteration_t iterations) {
	this->shuffle();

	this->t = temperature;
	this->ResetBuffers();

	double sumPbad = 0.0, prevSumPbad;
	int i = 0;
	do {
		this->iteration();
		// cout << "[simann] temp=" << this->t << ", mec=" << this->mec() << endl;
		double newPbad = this->pBad.getAverage();
		prevSumPbad = sumPbad;
		sumPbad += newPbad;
		++i;
		// below, we compute the previous and current average and demand they agree to some precision
	} while (i < 30 || fabs(prevSumPbad/(i-1) / (sumPbad/i) - 1) > 1e-3); // stabilize to at least this relative precision

	cout << "temperature " << temperature << " gives Pbad " << this->pBad.getAverage() << " after " << i << " iterations\n";

	return this->pBad.getAverage();
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movsd %xmm0, 0x8(%rsp)
movq %rdi, %rbx
callq 0x28ac
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x3bc0(%rbx)
movq %rbx, %rdi
callq 0x32fe
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x3008
movq 0x2348(%rbx), %rax
movq %rax, %xmm1
punpckldq 0x5e4d(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x5e55(%rip), %xmm1     # 0xa030
movsd 0x5eed(%rip), %xmm0     # 0xa0d0
testq %rax, %rax
je 0x4200
movsd 0x2358(%rbx), %xmm0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movapd 0x10(%rsp), %xmm3
addsd %xmm3, %xmm0
leal 0x1(%r14), %ebp
cmpl $0x1d, %r14d
jb 0x4253
movd %ebp, %xmm1
movd %r14d, %xmm2
punpckldq %xmm1, %xmm2    # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
cvtdq2pd %xmm2, %xmm1
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
divpd %xmm1, %xmm3
movapd %xmm3, %xmm1
unpckhpd %xmm3, %xmm1            # xmm1 = xmm1[1],xmm3[1]
divsd %xmm1, %xmm3
addsd 0x5eff(%rip), %xmm3     # 0xa140
andpd 0x5e57(%rip), %xmm3     # 0xa0a0
ucomisd 0x5ef7(%rip), %xmm3     # 0xa148
jbe 0x4261
movl %ebp, %r14d
movapd %xmm0, 0x10(%rsp)
jmp 0x41b7
movq 0xbd60(%rip), %rdi      # 0xffc8
leaq 0x6217(%rip), %rsi      # 0xa486
callq 0x2230
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x23a0
leaq 0x620a(%rip), %rsi      # 0xa493
movq %rax, %rdi
callq 0x2230
movq 0x2348(%rbx), %rcx
movsd 0x5e30(%rip), %xmm0     # 0xa0d0
testq %rcx, %rcx
je 0x42d2
movsd 0x2358(%rbx), %xmm0
movq %rcx, %xmm1
punpckldq 0x5d66(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x5d6e(%rip), %xmm1     # 0xa030
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movq %rax, %rdi
callq 0x23a0
leaq 0x61bf(%rip), %rsi      # 0xa4a0
movq %rax, %rdi
callq 0x2230
movq %rax, %rdi
movl %ebp, %esi
callq 0x23f0
leaq 0x61ae(%rip), %rsi      # 0xa4a8
movq %rax, %rdi
callq 0x2230
movq 0x2348(%rbx), %rax
testq %rax, %rax
movsd 0x5dbc(%rip), %xmm0     # 0xa0d0
je 0x4343
movsd 0x2358(%rbx), %xmm0
movq %rax, %xmm2
punpckldq 0x5cf5(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x5cfd(%rip), %xmm2     # 0xa030
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq