// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bcftools/kmin.c
// Function: kmin_hj
double kmin_hj(kmin_f func, int n, double *x, void *data, double r, double eps, int max_calls)
{
	double fx, fx1, *x1, *dx, radius;
	int k, n_calls = 0;
	x1 = (double*)calloc(n, sizeof(double));
	dx = (double*)calloc(n, sizeof(double));
	for (k = 0; k != n; ++k) { /* initial directions, based on MGJ */
		dx[k] = fabs(x[k]) * r;
		if (dx[k] == 0) dx[k] = r;
	}
	radius = r;
	fx1 = fx = func(n, x, data); ++n_calls;
	for (;;) {
		memcpy(x1, x, n * sizeof(double)); /* x1 = x */
		fx1 = __kmin_hj_aux(func, n, x1, data, fx, dx, &n_calls);
		while (fx1 < fx) {
			for (k = 0; k != n; ++k) {
				double t = x[k];
				dx[k] = x1[k] > x[k]? fabs(dx[k]) : 0.0 - fabs(dx[k]);
				x[k] = x1[k];
				x1[k] = x1[k] + x1[k] - t;
			}
			fx = fx1;
			if (n_calls >= max_calls) break;
			fx1 = func(n, x1, data); ++n_calls;
			fx1 = __kmin_hj_aux(func, n, x1, data, fx1, dx, &n_calls);
			if (fx1 >= fx) break;
			for (k = 0; k != n; ++k)
				if (fabs(x1[k] - x[k]) > .5 * fabs(dx[k])) break;
			if (k == n) break;
		}
		if (radius >= eps) {
			if (n_calls >= max_calls) break;
			radius *= r;
			for (k = 0; k != n; ++k) dx[k] *= r;
		} else break; /* converge */
	}
	free(x1); free(dx);
	return fx1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, 0x1c(%rsp)
movsd %xmm1, 0x50(%rsp)
movapd %xmm0, 0x40(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, 0x20(%rsp)
movslq %esi, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x2260
movq %rax, %r13
movl $0x8, %esi
movq %r14, %rdi
callq 0x2260
movq %rax, %rbx
movq %r14, 0x30(%rsp)
testl %r14d, %r14d
je 0x16904
movl %ebp, %r14d
xorl %eax, %eax
movapd 0x4ebc(%rip), %xmm0     # 0x1b780
xorpd %xmm1, %xmm1
movapd 0x40(%rsp), %xmm5
movsd (%r15,%rax,8), %xmm2
andpd %xmm0, %xmm2
mulsd %xmm5, %xmm2
movapd %xmm2, %xmm3
cmpeqsd %xmm1, %xmm3
movapd %xmm3, %xmm4
andnpd %xmm2, %xmm4
andpd %xmm5, %xmm3
orpd %xmm4, %xmm3
movlpd %xmm3, (%rbx,%rax,8)
incq %rax
cmpq %rax, %r14
jne 0x168ce
jmp 0x16907
xorl %r14d, %r14d
movl %ebp, %edi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
callq *0x20(%rsp)
movsd %xmm0, 0x10(%rsp)
leaq 0xc(%rsp), %r12
movl $0x1, (%r12)
shlq $0x3, 0x30(%rsp)
movapd 0x40(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movq 0x30(%rsp), %rdx
callq 0x22e0
movq 0x20(%rsp), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq 0x28(%rsp), %rcx
movsd 0x10(%rsp), %xmm0
movq %rbx, %r8
movq %r12, %r9
callq 0x16b03
movapd %xmm0, %xmm4
movsd 0x10(%rsp), %xmm0
ucomisd %xmm4, %xmm0
jbe 0x16a7e
movsd %xmm4, 0x10(%rsp)
testl %ebp, %ebp
movapd 0x4df2(%rip), %xmm5     # 0x1b780
je 0x169e7
xorl %eax, %eax
movsd (%r15,%rax,8), %xmm0
movsd (%r13,%rax,8), %xmm1
movsd (%rbx,%rax,8), %xmm2
andpd %xmm5, %xmm2
xorpd %xmm3, %xmm3
subsd %xmm2, %xmm3
movapd %xmm0, %xmm4
cmpltsd %xmm1, %xmm4
andpd %xmm4, %xmm2
andnpd %xmm3, %xmm4
orpd %xmm2, %xmm4
movlpd %xmm4, (%rbx,%rax,8)
movsd %xmm1, (%r15,%rax,8)
addsd %xmm1, %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%r13,%rax,8)
incq %rax
cmpq %rax, %r14
jne 0x16992
movl 0xc(%rsp), %r12d
cmpl 0x1c(%rsp), %r12d
jge 0x16acb
movl %ebp, %edi
movq %r13, %rsi
movq 0x28(%rsp), %rdx
callq *0x20(%rsp)
incl %r12d
movl %r12d, 0xc(%rsp)
movq 0x20(%rsp), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq 0x28(%rsp), %rcx
movq %rbx, %r8
leaq 0xc(%rsp), %r12
movq %r12, %r9
callq 0x16b03
movapd %xmm0, %xmm4
ucomisd 0x10(%rsp), %xmm0
jae 0x16a7e
testl %ebp, %ebp
je 0x16a7e
xorl %eax, %eax
movapd 0x4d3a(%rip), %xmm2     # 0x1b780
movsd 0x2632(%rip), %xmm3     # 0x19080
movsd (%r13,%rax,8), %xmm0
subsd (%r15,%rax,8), %xmm0
andpd %xmm2, %xmm0
movsd (%rbx,%rax,8), %xmm1
andpd %xmm2, %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
ja 0x1696e
incq %rax
cmpq %rax, %r14
jne 0x16a4e
movsd 0x38(%rsp), %xmm0
ucomisd 0x50(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
jb 0x16ad8
movl 0x1c(%rsp), %eax
cmpl %eax, 0xc(%rsp)
jge 0x16ad8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
testl %ebp, %ebp
je 0x1693a
xorl %eax, %eax
movsd (%rbx,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
cmpq %rax, %r14
jne 0x16ab0
jmp 0x1693a
movsd 0x10(%rsp), %xmm4
leaq 0xc(%rsp), %r12
jmp 0x16a7e
movq %r13, %rdi
movsd %xmm4, 0x10(%rsp)
callq 0x2060
movq %rbx, %rdi
callq 0x2060
movsd 0x10(%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq