// File: /workspace/github_c_makefile_star2_O1/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, 0x14(%rsp)
movsd %xmm1, 0x50(%rsp)
movapd %xmm0, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, 0x18(%rsp)
movl $0x0, 0x4(%rsp)
movslq %esi, %r12
movl $0x8, %esi
movq %r12, %rdi
callq 0x2260
movq %rax, %r13
movl $0x8, %esi
movq %r12, %rdi
callq 0x2260
movapd 0x30(%rsp), %xmm5
movq %rax, %rbx
movl %ebp, %r14d
movq %r12, %rcx
testl %r12d, %r12d
je 0x16564
xorl %eax, %eax
movapd 0x5194(%rip), %xmm0     # 0x1b6c0
xorpd %xmm1, %xmm1
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 0x16530
movq %rcx, %r12
movl %r12d, %edi
movl %r12d, 0x10(%rsp)
movq %r15, %rsi
movq 0x20(%rsp), %rdx
callq *0x18(%rsp)
movsd %xmm0, 0x8(%rsp)
leaq 0x4(%rsp), %rax
movl $0x1, (%rax)
shlq $0x3, %r12
movq %r12, 0x48(%rsp)
cmpl $0x0, 0x10(%rsp)
sete 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movq 0x48(%rsp), %rdx
callq 0x22e0
movq 0x18(%rsp), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq 0x20(%rsp), %rcx
movsd 0x8(%rsp), %xmm0
movq %rbx, %r8
leaq 0x4(%rsp), %r9
callq 0x167b3
movsd 0x8(%rsp), %xmm1
movapd %xmm0, %xmm5
ucomisd %xmm0, %xmm1
jbe 0x16727
testl %ebp, %ebp
movapd 0x50c5(%rip), %xmm6     # 0x1b6c0
je 0x16654
xorl %eax, %eax
movsd (%r15,%rax,8), %xmm0
movsd (%r13,%rax,8), %xmm1
movsd (%rbx,%rax,8), %xmm2
andpd %xmm6, %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 0x165ff
movl 0x4(%rsp), %r12d
cmpl 0x14(%rsp), %r12d
jge 0x16731
movl %ebp, %edi
movq %r13, %rsi
movq 0x20(%rsp), %rdx
movsd %xmm5, 0x8(%rsp)
callq *0x18(%rsp)
incl %r12d
movl %r12d, 0x4(%rsp)
movq 0x18(%rsp), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq 0x20(%rsp), %rcx
movq %rbx, %r8
leaq 0x4(%rsp), %r9
callq 0x167b3
movsd 0x8(%rsp), %xmm5
ucomisd %xmm5, %xmm0
jae 0x16735
testl %ebp, %ebp
movapd 0x500a(%rip), %xmm2     # 0x1b6c0
movsd 0x295a(%rip), %xmm3     # 0x19018
je 0x16735
movsd (%r13), %xmm4
subsd (%r15), %xmm4
andpd %xmm2, %xmm4
movsd (%rbx), %xmm1
andpd %xmm2, %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm1, %xmm4
movb 0x10(%rsp), %al
ja 0x16719
movl $0x1, %ecx
cmpq %rcx, %r14
sete %al
je 0x16735
movsd (%r13,%rcx,8), %xmm4
subsd (%r15,%rcx,8), %xmm4
andpd %xmm2, %xmm4
movsd (%rbx,%rcx,8), %xmm1
andpd %xmm2, %xmm1
mulsd %xmm3, %xmm1
incq %rcx
ucomisd %xmm1, %xmm4
jbe 0x166ea
movapd %xmm5, %xmm1
testb %al, %al
je 0x165e3
jmp 0x16735
movapd %xmm5, %xmm0
movapd %xmm1, %xmm5
jmp 0x16735
movapd %xmm5, %xmm0
movsd 0x28(%rsp), %xmm2
ucomisd 0x50(%rsp), %xmm2
movapd 0x30(%rsp), %xmm1
jb 0x16788
movl 0x14(%rsp), %eax
cmpl %eax, 0x4(%rsp)
jge 0x16788
movsd %xmm5, 0x8(%rsp)
mulsd %xmm1, %xmm2
movsd %xmm2, 0x28(%rsp)
testl %ebp, %ebp
je 0x165ab
xorl %eax, %eax
movsd (%rbx,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
cmpq %rax, %r14
jne 0x1676d
jmp 0x165ab
movq %r13, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0x2060
movq %rbx, %rdi
callq 0x2060
movsd 0x8(%rsp), %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq