// File: /workspace/github_c_makefile_star2_O0/georgeweigt[P]eigenmath/eigenmath.c
// Function: nfindroot
void
nfindroot(double cr[], double ci[], int n, double *par, double *pai)
{
	int i, j;
	double d;
	double ar, br, dfr, dxr, far, fbr, xr, yr;
	double ai, bi, dfi, dxi, fai, fbi, xi, yi;

	// if const term is zero then root is zero

	// note: use exact zero, not "close to zero"

	// term will be exactly zero from coeffs(), no need for arbitrary cutoff

	if (cr[0] == 0.0 && ci[0] == 0.0) {
		*par = 0.0;
		*pai = 0.0;
		return;
	}

	// secant method

	for (i = 0; i < 100; i++) {

		ar = urandom();
		ai = urandom();

		fata(cr, ci, n, ar, ai, &far, &fai);

		br = ar;
		bi = ai;

		fbr = far;
		fbi = fai;

		ar = urandom();
		ai = urandom();

		for (j = 0; j < 1000; j++) {

			fata(cr, ci, n, ar, ai, &far, &fai);

			if (zabs(far, fai) < EPSILON) {
				*par = ar;
				*pai = ai;
				return;
			}

			if (zabs(far, fai) < zabs(fbr, fbi)) {

				xr = ar;
				xi = ai;

				ar = br;
				ai = bi;

				br = xr;
				bi = xi;

				xr = far;
				xi = fai;

				far = fbr;
				fai = fbi;

				fbr = xr;
				fbi = xi;
			}

			// dx = b - a

			dxr = br - ar;
			dxi = bi - ai;

			// df = fb - fa

			dfr = fbr - far;
			dfi = fbi - fai;

			// y = dx / df

			d = dfr * dfr + dfi * dfi;

			if (d == 0.0)
				break;

			yr = (dxr * dfr + dxi * dfi) / d;
			yi = (dxi * dfr - dxr * dfi) / d;

			// a = b - y * fb

			ar = br - (yr * fbr - yi * fbi);
			ai = bi - (yr * fbi + yi * fbr);
		}
	}

	stopf("nroots: convergence error");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2885f
jp 0x2885f
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2885f
jp 0x2885f
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x28(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x28bda
movl $0x0, -0x2c(%rbp)
cmpl $0x64, -0x2c(%rbp)
jge 0x28bce
callq 0x28d60
movsd %xmm0, -0x40(%rbp)
callq 0x28d60
movsd %xmm0, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movsd -0x40(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
leaq -0x60(%rbp), %rcx
leaq -0xa0(%rbp), %r8
callq 0x28da0
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
callq 0x28d60
movsd %xmm0, -0x40(%rbp)
callq 0x28d60
movsd %xmm0, -0x80(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x3e8, -0x30(%rbp)     # imm = 0x3E8
jge 0x28bbe
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movsd -0x40(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
leaq -0x60(%rbp), %rcx
leaq -0xa0(%rbp), %r8
callq 0x28da0
movsd -0x60(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm1
callq 0x28ec0
movaps %xmm0, %xmm1
movsd 0x1c7a4(%rip), %xmm0    # 0x450e8
ucomisd %xmm1, %xmm0
jbe 0x28969
movsd -0x40(%rbp), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x80(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x28bda
movsd -0x60(%rbp), %xmm0
movsd -0xa0(%rbp), %xmm1
callq 0x28ec0
movsd %xmm0, -0xc0(%rbp)
movsd -0x68(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
callq 0x28ec0
movsd -0xc0(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x28a3d
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x48(%rbp), %xmm0
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x88(%rbp), %xmm0
subsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x68(%rbp), %xmm0
subsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0xa8(%rbp), %xmm0
subsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x50(%rbp), %xmm2
movsd -0x90(%rbp), %xmm1
mulsd -0x90(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x28ac4
jp 0x28ac4
jmp 0x28bbe
movsd -0x58(%rbp), %xmm0
movsd -0x50(%rbp), %xmm2
movsd -0x98(%rbp), %xmm1
mulsd -0x90(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x98(%rbp), %xmm0
movsd -0x50(%rbp), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd -0x90(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0x68(%rbp), %xmm3
movsd -0xb8(%rbp), %xmm2
mulsd -0xa8(%rbp), %xmm2
movq %xmm2, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x88(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
movsd -0xa8(%rbp), %xmm3
movsd -0xb8(%rbp), %xmm2
mulsd -0x68(%rbp), %xmm2
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x288f5
jmp 0x28bc0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x28866
leaq 0x20cad(%rip), %rdi     # 0x49882
callq 0x78d0
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)