// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, 0x8(%rsp)
movq %rdi, %rbx
callq 0x2cfa
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x3bc0(%rbx)
leaq 0x408(%rbx), %r14
movl $0x0, 0x400(%rbx)
xorl %r15d, %r15d
movl $0x3fc, %edx            # imm = 0x3FC
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2140
movl $0x1f60, %edx           # imm = 0x1F60
movq %r14, %rdi
xorl %esi, %esi
callq 0x2140
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
callq 0x366e
movq 0x2348(%rbx), %rax
movq %rax, %xmm1
punpckldq 0x659e(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x65a6(%rip), %xmm1     # 0xb0d0
movsd 0x64f6(%rip), %xmm0     # 0xb028
testq %rax, %rax
je 0x4b4f
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(%r15), %ebp
cmpl $0x1d, %r15d
jb 0x4b9c
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ebp, %xmm2
divsd %xmm1, %xmm3
movapd %xmm0, %xmm1
divsd %xmm2, %xmm1
divsd %xmm1, %xmm3
addsd 0x6516(%rip), %xmm3     # 0xb0a0
andpd 0x655e(%rip), %xmm3     # 0xb0f0
ucomisd 0x650e(%rip), %xmm3     # 0xb0a8
jbe 0x4ba4
movl %ebp, %r15d
jmp 0x4b00
movq 0xb41d(%rip), %r14      # 0xffc8
leaq 0x6874(%rip), %rsi      # 0xb426
movl $0xc, %edx
movq %r14, %rdi
callq 0x22b0
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x23d0
movq %rax, %r14
leaq 0x685c(%rip), %rsi      # 0xb433
movl $0xc, %edx
movq %rax, %rdi
callq 0x22b0
movq 0x2348(%rbx), %rax
movsd 0x6435(%rip), %xmm0     # 0xb028
testq %rax, %rax
je 0x4c25
movsd 0x2358(%rbx), %xmm0
movq %rax, %xmm1
punpckldq 0x64b3(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x64bb(%rip), %xmm1     # 0xb0d0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movq %r14, %rdi
callq 0x23d0
movq %rax, %r14
leaq 0x6809(%rip), %rsi      # 0xb440
movl $0x7, %edx
movq %rax, %rdi
callq 0x22b0
movq %r14, %rdi
movl %ebp, %esi
callq 0x2430
leaq 0x67f3(%rip), %rsi      # 0xb448
movl $0xc, %edx
movq %rax, %rdi
callq 0x22b0
movq 0x2348(%rbx), %rax
testq %rax, %rax
movsd 0x63b4(%rip), %xmm0     # 0xb028
je 0x4ca3
movsd 0x2358(%rbx), %xmm0
movq %rax, %xmm2
punpckldq 0x6435(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x643d(%rip), %xmm2     # 0xb0d0
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq