// File: /workspace/github_c_makefile_star2_O3/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 0x2cf8
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 0x364c
movq 0x2348(%rbx), %rax
movq %rax, %xmm1
punpckldq 0x6566(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x656e(%rip), %xmm1     # 0xb030
movsd 0x6636(%rip), %xmm0     # 0xb100
testq %rax, %rax
je 0x4ae7
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 0x4b3a
movd %ebp, %xmm1
movd %r15d, %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 0x6648(%rip), %xmm3     # 0xb170
andpd 0x6570(%rip), %xmm3     # 0xb0a0
ucomisd 0x6640(%rip), %xmm3     # 0xb178
jbe 0x4b42
movl %ebp, %r15d
jmp 0x4a98
movq 0xb47f(%rip), %r14      # 0xffc8
leaq 0x6966(%rip), %rsi      # 0xb4b6
movl $0xc, %edx
movq %r14, %rdi
callq 0x22b0
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x23d0
movq %rax, %r14
leaq 0x694e(%rip), %rsi      # 0xb4c3
movl $0xc, %edx
movq %rax, %rdi
callq 0x22b0
movq 0x2348(%rbx), %rax
movsd 0x656f(%rip), %xmm0     # 0xb100
testq %rax, %rax
je 0x4bc3
movsd 0x2358(%rbx), %xmm0
movq %rax, %xmm1
punpckldq 0x6475(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x647d(%rip), %xmm1     # 0xb030
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 0x68fb(%rip), %rsi      # 0xb4d0
movl $0x7, %edx
movq %rax, %rdi
callq 0x22b0
movq %r14, %rdi
movl %ebp, %esi
callq 0x2430
leaq 0x68e5(%rip), %rsi      # 0xb4d8
movl $0xc, %edx
movq %rax, %rdi
callq 0x22b0
movq 0x2348(%rbx), %rax
testq %rax, %rax
movsd 0x64ee(%rip), %xmm0     # 0xb100
je 0x4c41
movsd 0x2358(%rbx), %xmm0
movq %rax, %xmm2
punpckldq 0x63f7(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x63ff(%rip), %xmm2     # 0xb030
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