// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bcftools/kmin.c
// Function: kmin_brent
double kmin_brent(kmin1_f func, double a, double b, void *data, double tol, double *xmin)
{
	double bound, u, r, q, fu, tmp, fa, fb, fc, c;
	const double gold1 = 1.6180339887;
	const double gold2 = 0.3819660113;
	const double tiny = 1e-20;
	const int max_iter = 100;

	double e, d, w, v, mid, tol1, tol2, p, eold, fv, fw;
	int iter;

	fa = func(a, data); fb = func(b, data);
	if (fb > fa) { // swap, such that f(a) > f(b)
		tmp = a; a = b; b = tmp;
		tmp = fa; fa = fb; fb = tmp;
	}
	c = b + gold1 * (b - a), fc = func(c, data); // golden section extrapolation
	while (fb > fc) {
		bound = b + 100.0 * (c - b); // the farthest point where we want to go
		r = (b - a) * (fb - fc);
		q = (b - c) * (fb - fa);
		if (fabs(q - r) < tiny) { // avoid 0 denominator
			tmp = q > r? tiny : 0.0 - tiny;
		} else tmp = q - r;
		u = b - ((b - c) * q - (b - a) * r) / (2.0 * tmp); // u is the parabolic extrapolation point
		if ((b > u && u > c) || (b < u && u < c)) { // u lies between b and c
			fu = func(u, data);
			if (fu < fc) { // (b,u,c) bracket the minimum
				a = b; b = u; fa = fb; fb = fu;
				break;
			} else if (fu > fb) { // (a,b,u) bracket the minimum
				c = u; fc = fu;
				break;
			}
			u = c + gold1 * (c - b); fu = func(u, data); // golden section extrapolation
		} else if ((c > u && u > bound) || (c < u && u < bound)) { // u lies between c and bound
			fu = func(u, data);
			if (fu < fc) { // fb > fc > fu
				b = c; c = u; u = c + gold1 * (c - b);
				fb = fc; fc = fu; fu = func(u, data);
			} else { // (b,c,u) bracket the minimum
				a = b; b = c; c = u;
				fa = fb; fb = fc; fc = fu;
				break;
			}
		} else if ((u > bound && bound > c) || (u < bound && bound < c)) { // u goes beyond the bound
			u = bound; fu = func(u, data);
		} else { // u goes the other way around, use golden section extrapolation
			u = c + gold1 * (c - b); fu = func(u, data);
		}
		a = b; b = c; c = u;
		fa = fb; fb = fc; fc = fu;
	}
	if (a > c) u = a, a = c, c = u; // swap

	// now, a<b<c, fa>fb and fb<fc, move on to Brent's algorithm
	e = d = 0.0;
	w = v = b; fv = fw = fb;
	for (iter = 0; iter != max_iter; ++iter) {
		mid = 0.5 * (a + c);
		tol2 = 2.0 * (tol1 = tol * fabs(b) + tiny);
		if (fabs(b - mid) <= (tol2 - 0.5 * (c - a))) {
			*xmin = b; return fb; // found
		}
		if (fabs(e) > tol1) {
			// related to parabolic interpolation
			r = (b - w) * (fb - fv);
			q = (b - v) * (fb - fw);
			p = (b - v) * q - (b - w) * r;
			q = 2.0 * (q - r);
			if (q > 0.0) p = 0.0 - p;
			else q = 0.0 - q;
			eold = e; e = d;
			if (fabs(p) >= fabs(0.5 * q * eold) || p <= q * (a - b) || p >= q * (c - b)) {
				d = gold2 * (e = (b >= mid ? a - b : c - b));
			} else {
				d = p / q; u = b + d; // actual parabolic interpolation happens here
				if (u - a < tol2 || c - u < tol2)
					d = (mid > b)? tol1 : 0.0 - tol1;
			}
		} else d = gold2 * (e = (b >= mid ? a - b : c - b)); // golden section interpolation
		u = fabs(d) >= tol1 ? b + d : b + (d > 0.0? tol1 : -tol1);
		fu = func(u, data);
		if (fu <= fb) { // u is the minimum point so far
			if (u >= b) a = b;
			else c = b;
			v = w; w = b; b = u; fv = fw; fw = fb; fb = fu;
		} else { // adjust (a,c) and (u,v,w)
			if (u < b) a = u;
			else c = u;
			if (fu <= fw || w == b) {
				v = w; w = u;
				fv = fw; fw = fu;
			} else if (fu <= fv || v == b || v == w) {
				v = u; fv = fu;
			}
		}
	}
	*xmin = b;
	return fb;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xb0, %rsp
movq %rdx, %rbx
movsd %xmm2, 0x88(%rsp)
movq %rsi, %r14
movsd %xmm1, 0x30(%rsp)
movq %rdi, %r15
movsd %xmm0, 0x10(%rsp)
movq %rsi, %rdi
callq *%r15
movsd %xmm0, 0x28(%rsp)
movsd 0x30(%rsp), %xmm0
movq %r14, %rdi
callq *%r15
movsd 0x28(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16c6e
movsd %xmm0, 0x8(%rsp)
movsd 0x10(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
jmp 0x16c86
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd 0x30(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movsd %xmm1, 0x50(%rsp)
movapd %xmm1, %xmm0
movsd %xmm2, 0x30(%rsp)
subsd %xmm2, %xmm0
mulsd 0x4c8e(%rip), %xmm0     # 0x1b930
addsd %xmm1, %xmm0
movapd %xmm0, 0x40(%rsp)
movq %r14, %rdi
callq *%r15
movsd 0x28(%rsp), %xmm10
ucomisd %xmm0, %xmm10
jbe 0x16f38
movapd %xmm0, %xmm11
leaq 0x4c50(%rip), %r12      # 0x1b920
movsd 0x50(%rsp), %xmm6
movapd %xmm6, %xmm7
movapd 0x40(%rsp), %xmm12
movsd 0x30(%rsp), %xmm13
movsd 0x8(%rsp), %xmm4
movapd %xmm6, %xmm1
subsd %xmm13, %xmm1
movapd %xmm10, %xmm2
subsd %xmm11, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm6, %xmm0
subsd %xmm12, %xmm0
movapd %xmm10, %xmm3
subsd %xmm4, %xmm3
mulsd %xmm0, %xmm3
xorl %eax, %eax
ucomisd %xmm2, %xmm3
seta %al
mulsd %xmm3, %xmm0
subsd %xmm2, %xmm3
movapd %xmm3, %xmm4
andpd 0x4a48(%rip), %xmm4     # 0x1b780
movsd (%r12,%rax,8), %xmm5
cmpltsd 0x47a9(%rip), %xmm4     # 0x1b4f0
andpd %xmm4, %xmm5
andnpd %xmm3, %xmm4
orpd %xmm5, %xmm4
mulsd %xmm1, %xmm2
subsd %xmm2, %xmm0
addsd %xmm4, %xmm4
divsd %xmm4, %xmm0
movapd %xmm12, %xmm3
subsd %xmm6, %xmm3
subsd %xmm0, %xmm7
movapd %xmm3, %xmm2
mulsd 0x4bbc(%rip), %xmm2     # 0x1b938
ucomisd %xmm7, %xmm6
movapd %xmm7, 0x10(%rsp)
movsd %xmm6, 0x50(%rsp)
movsd %xmm11, 0x8(%rsp)
movapd %xmm12, 0x40(%rsp)
jbe 0x16da3
ucomisd %xmm12, %xmm7
ja 0x16db0
ucomisd %xmm6, %xmm7
jbe 0x16e20
ucomisd %xmm7, %xmm12
jbe 0x16e20
movapd %xmm3, 0x60(%rsp)
movsd %xmm13, 0x30(%rsp)
movsd %xmm10, 0x28(%rsp)
movapd %xmm7, %xmm0
movq %r14, %rdi
callq *%r15
movsd 0x8(%rsp), %xmm11
movapd %xmm0, %xmm8
ucomisd %xmm0, %xmm11
ja 0x16f4c
movsd 0x28(%rsp), %xmm10
ucomisd %xmm10, %xmm8
movsd 0x50(%rsp), %xmm6
movapd 0x40(%rsp), %xmm0
ja 0x16f62
movapd 0x60(%rsp), %xmm2
mulsd 0x4b1f(%rip), %xmm2     # 0x1b930
addsd %xmm0, %xmm2
movapd %xmm0, 0x10(%rsp)
jmp 0x16ed3
addsd %xmm6, %xmm2
ucomisd %xmm7, %xmm12
jbe 0x16e31
ucomisd %xmm2, %xmm7
ja 0x16e3e
ucomisd %xmm12, %xmm7
jbe 0x16e81
ucomisd %xmm7, %xmm2
jbe 0x16e81
movapd %xmm7, %xmm0
movq %r14, %rdi
callq *%r15
movsd 0x8(%rsp), %xmm10
ucomisd %xmm0, %xmm10
jbe 0x173c0
movapd 0x10(%rsp), %xmm1
movapd %xmm1, %xmm2
movapd 0x40(%rsp), %xmm6
subsd %xmm6, %xmm2
mulsd 0x4aba(%rip), %xmm2     # 0x1b930
addsd %xmm1, %xmm2
movapd %xmm0, %xmm11
jmp 0x16ed3
movapd %xmm12, %xmm0
cmpltpd %xmm2, %xmm0
movapd %xmm2, %xmm1
cmpltpd %xmm7, %xmm1
andpd %xmm0, %xmm1
movd %xmm1, %eax
testb $0x1, %al
jne 0x16ecc
movapd %xmm2, %xmm0
cmpltpd %xmm12, %xmm0
cmpltpd %xmm2, %xmm7
andpd %xmm0, %xmm7
movd %xmm7, %eax
testb $0x1, %al
jne 0x16ecc
mulsd 0x4a6d(%rip), %xmm3     # 0x1b930
addsd %xmm12, %xmm3
movapd %xmm3, %xmm2
movapd %xmm12, 0x10(%rsp)
movapd %xmm2, 0x50(%rsp)
movsd %xmm6, 0x30(%rsp)
movsd %xmm11, 0x40(%rsp)
movsd %xmm10, 0x8(%rsp)
movapd %xmm2, %xmm0
movq %r14, %rdi
callq *%r15
movsd 0x8(%rsp), %xmm4
movsd 0x30(%rsp), %xmm13
movapd 0x50(%rsp), %xmm9
movsd 0x40(%rsp), %xmm8
movapd %xmm0, %xmm11
ucomisd %xmm0, %xmm8
movapd 0x10(%rsp), %xmm7
movapd %xmm7, %xmm6
movapd %xmm9, %xmm12
movapd %xmm8, %xmm10
ja 0x16cee
jmp 0x16f79
movapd %xmm10, %xmm8
movapd 0x40(%rsp), %xmm9
movsd 0x50(%rsp), %xmm7
jmp 0x16f72
movapd 0x40(%rsp), %xmm9
movsd 0x50(%rsp), %xmm13
movapd 0x10(%rsp), %xmm7
jmp 0x16f79
movapd %xmm10, %xmm8
movapd 0x10(%rsp), %xmm9
movapd %xmm6, %xmm7
movsd 0x30(%rsp), %xmm13
movapd %xmm13, %xmm10
maxsd %xmm9, %xmm10
minsd %xmm13, %xmm9
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movl $0x64, %ebp
movapd 0x47e0(%rip), %xmm12    # 0x1b780
movapd %xmm8, %xmm0
movapd %xmm7, %xmm11
movapd %xmm7, %xmm5
xorpd %xmm15, %xmm15
movapd %xmm8, %xmm14
movapd %xmm10, %xmm1
addsd %xmm9, %xmm1
mulsd 0x20b6(%rip), %xmm1     # 0x19080
movapd %xmm7, %xmm13
movapd 0x47a9(%rip), %xmm4     # 0x1b780
andpd %xmm4, %xmm13
mulsd 0x88(%rsp), %xmm13
addsd 0x4501(%rip), %xmm13    # 0x1b4f0
movapd %xmm13, %xmm2
addsd %xmm13, %xmm2
movapd %xmm7, %xmm3
subsd %xmm1, %xmm3
andpd %xmm4, %xmm3
movapd %xmm10, %xmm4
subsd %xmm9, %xmm4
mulsd 0x4849(%rip), %xmm4     # 0x1b860
addsd %xmm2, %xmm4
ucomisd %xmm3, %xmm4
jae 0x173a3
movapd %xmm15, %xmm3
andpd %xmm12, %xmm3
ucomisd %xmm13, %xmm3
movsd %xmm11, 0x90(%rsp)
movsd %xmm5, 0x8(%rsp)
jbe 0x1713b
movapd %xmm7, %xmm4
subsd %xmm5, %xmm4
movapd %xmm14, %xmm5
subsd %xmm0, %xmm5
mulsd %xmm4, %xmm5
movapd %xmm7, %xmm6
subsd %xmm11, %xmm6
movapd %xmm14, %xmm3
subsd %xmm8, %xmm3
mulsd %xmm6, %xmm3
mulsd %xmm5, %xmm4
mulsd %xmm3, %xmm6
subsd %xmm4, %xmm6
subsd %xmm5, %xmm3
addsd %xmm3, %xmm3
xorpd %xmm5, %xmm5
subsd %xmm6, %xmm5
xorpd %xmm4, %xmm4
cmpltsd %xmm3, %xmm4
movapd 0x46dc(%rip), %xmm11    # 0x1b780
andpd %xmm11, %xmm3
andpd %xmm4, %xmm5
andnpd %xmm6, %xmm4
orpd %xmm5, %xmm4
movapd %xmm4, %xmm5
andpd %xmm11, %xmm5
movapd %xmm3, %xmm6
mulsd 0x1fb6(%rip), %xmm6     # 0x19080
mulsd %xmm6, %xmm15
andpd %xmm11, %xmm15
ucomisd %xmm15, %xmm5
jae 0x1713b
movapd %xmm9, %xmm5
subsd %xmm7, %xmm5
mulsd %xmm3, %xmm5
ucomisd %xmm4, %xmm5
jae 0x1713b
movapd %xmm10, %xmm5
subsd %xmm7, %xmm5
mulsd %xmm3, %xmm5
ucomisd %xmm5, %xmm4
jae 0x1713b
divsd %xmm3, %xmm4
movapd %xmm7, %xmm3
addsd %xmm4, %xmm3
movapd %xmm3, %xmm5
subsd %xmm9, %xmm5
ucomisd %xmm5, %xmm2
ja 0x17371
movapd %xmm10, %xmm5
subsd %xmm3, %xmm5
ucomisd %xmm5, %xmm2
ja 0x17371
movapd 0x70(%rsp), %xmm5
jmp 0x17166
cmpnlesd %xmm7, %xmm1
movapd %xmm1, %xmm2
andpd %xmm10, %xmm2
andnpd %xmm9, %xmm1
orpd %xmm2, %xmm1
subsd %xmm7, %xmm1
movapd %xmm1, %xmm4
mulsd 0x47de(%rip), %xmm4     # 0x1b940
movapd %xmm1, %xmm5
movapd %xmm5, 0x60(%rsp)
movsd %xmm14, 0x28(%rsp)
movsd %xmm0, 0x98(%rsp)
movapd %xmm10, 0x30(%rsp)
movapd %xmm9, 0x50(%rsp)
movsd %xmm8, 0x40(%rsp)
movapd %xmm4, %xmm1
andpd %xmm12, %xmm1
ucomisd %xmm13, %xmm1
movapd %xmm4, %xmm0
jae 0x171c9
xorpd %xmm0, %xmm0
cmpltsd %xmm4, %xmm0
movapd %xmm0, %xmm1
andpd %xmm13, %xmm1
xorpd 0x4680(%rip), %xmm13    # 0x1b840
andnpd %xmm13, %xmm0
orpd %xmm1, %xmm0
movapd %xmm4, 0x70(%rsp)
addsd %xmm7, %xmm0
movapd %xmm0, 0xa0(%rsp)
movq %r14, %rdi
movapd %xmm7, 0x10(%rsp)
callq *%r15
movsd 0x28(%rsp), %xmm9
ucomisd %xmm0, %xmm9
jae 0x172bc
movapd 0xa0(%rsp), %xmm6
movapd 0x10(%rsp), %xmm7
ucomisd %xmm6, %xmm7
movapd %xmm6, %xmm2
movsd 0x40(%rsp), %xmm8
movapd 0x50(%rsp), %xmm1
movapd 0x30(%rsp), %xmm10
movsd 0x98(%rsp), %xmm11
ja 0x17235
movapd %xmm1, %xmm2
movapd %xmm6, %xmm1
cmpltsd %xmm7, %xmm1
andpd %xmm1, %xmm10
andnpd %xmm6, %xmm1
orpd %xmm1, %xmm10
ucomisd %xmm0, %xmm8
movapd 0x4526(%rip), %xmm12    # 0x1b780
movsd 0x8(%rsp), %xmm4
movapd 0x60(%rsp), %xmm15
movsd 0x90(%rsp), %xmm5
jae 0x1732e
ucomisd %xmm7, %xmm4
jne 0x17282
jnp 0x1732e
ucomisd %xmm0, %xmm11
jae 0x17347
ucomisd %xmm7, %xmm5
jne 0x17299
jnp 0x17347
ucomisd %xmm4, %xmm5
jne 0x172a5
jnp 0x17347
movapd %xmm9, %xmm1
movapd %xmm4, %xmm3
movapd %xmm5, %xmm4
movapd %xmm11, %xmm0
jmp 0x17354
movapd 0xa0(%rsp), %xmm7
movapd 0x10(%rsp), %xmm3
ucomisd %xmm3, %xmm7
movsd 0x40(%rsp), %xmm4
movapd 0x50(%rsp), %xmm5
movapd 0x30(%rsp), %xmm6
jb 0x172e7
movapd %xmm3, %xmm5
movapd %xmm3, %xmm2
cmpnlesd %xmm7, %xmm2
movapd %xmm2, %xmm1
andpd %xmm3, %xmm1
andnpd %xmm6, %xmm2
orpd %xmm1, %xmm2
movapd %xmm0, %xmm1
movapd %xmm2, %xmm10
movapd %xmm5, %xmm2
movapd %xmm4, %xmm0
movapd %xmm9, %xmm8
movapd 0x4461(%rip), %xmm12    # 0x1b780
movsd 0x8(%rsp), %xmm4
movapd 0x60(%rsp), %xmm15
jmp 0x17354
movapd %xmm9, %xmm1
movapd %xmm6, %xmm3
movapd %xmm8, %xmm5
movapd %xmm0, %xmm8
movapd %xmm5, %xmm0
jmp 0x17354
movapd %xmm9, %xmm1
movapd %xmm4, %xmm3
movapd %xmm6, %xmm4
movapd %xmm2, %xmm9
movapd %xmm4, %xmm11
movapd %xmm3, %xmm5
movapd %xmm1, %xmm14
decl %ebp
jne 0x16fb8
jmp 0x173a8
xorpd %xmm2, %xmm2
subsd %xmm13, %xmm2
movapd 0x70(%rsp), %xmm5
movapd %xmm7, %xmm3
cmpltsd %xmm1, %xmm3
movapd %xmm3, %xmm1
andnpd %xmm2, %xmm1
andpd %xmm13, %xmm3
orpd %xmm1, %xmm3
movapd %xmm3, %xmm4
jmp 0x17166
movapd %xmm14, %xmm1
movsd %xmm7, (%rbx)
movapd %xmm1, %xmm0
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movapd %xmm10, %xmm8
movaps 0x10(%rsp), %xmm9
movaps 0x40(%rsp), %xmm7
movsd 0x50(%rsp), %xmm13
jmp 0x16f79