// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: nroots
void
nroots(void)
{
	int h, i, n;
	struct atom *A, *P, *X, *RE, *IM;
	double ar, ai, d, xr, xi, yr, yi;
	static double *cr, *ci;

	X = pop();
	P = pop();

	h = tos;

	coeffs(P, X); // put coeffs on stack

	n = tos - h; // number of coeffs on stack

	if (cr)
		free(cr);
	if (ci)
		free(ci);

	cr = alloc_mem(n * sizeof (double));
	ci = alloc_mem(n * sizeof (double));

	// convert coeffs to floating point

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

		push(stack[h + i]);
		real();
		floatfunc();
		RE = pop();

		push(stack[h + i]);
		imag();
		floatfunc();
		IM = pop();

		if (!isdouble(RE) || !isdouble(IM))
			stopf("nroots: coeffs");

		cr[i] = RE->u.d;
		ci[i] = IM->u.d;
	}

	tos = h; // pop all

	// divide p(x) by leading coeff

	xr = cr[n - 1];
	xi = ci[n - 1];

	d = xr * xr + xi * xi;

	for (i = 0; i < n - 1; i++) {
		yr = (cr[i] * xr + ci[i] * xi) / d;
		yi = (ci[i] * xr - cr[i] * xi) / d;
		cr[i] = yr;
		ci[i] = yi;
	}

	cr[n - 1] = 1.0;
	ci[n - 1] = 0.0;

	// find roots

	while (n > 1) {

		nfindroot(cr, ci, n, &ar, &ai);

		if (fabs(ar) < DELTA * fabs(ai))
			ar = 0.0;

		if (fabs(ai) < DELTA * fabs(ar))
			ai = 0.0;

		// push root

		push_double(ar);
		push_double(ai);
		push(imaginaryunit);
		multiply();
		add();

		// divide p(x) by x - a

		nreduce(cr, ci, n, ar, ai);

		// note: leading coeff of p(x) is still 1

		n--;
	}

	n = tos - h; // number of roots on stack

	if (n == 0) {
		push_symbol(NIL); // no roots
		return;
	}

	if (n == 1)
		return; // one root

	sort(n);

	A = alloc_vector(n);

	for (i = 0; i < n; i++)
		A->u.tensor->elem[i] = stack[h + i];

	tos = h; // pop all

	push(A);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
callq 0x868d
movq %rax, %rbx
callq 0x868d
movl 0x215d2(%rip), %r14d    # 0x382a8
movq %rax, %rdi
movq %rbx, %rsi
callq 0x16fdc
movslq 0x215c0(%rip), %rbx     # 0x382a8
movl %r14d, -0x2c(%rbp)
movslq %r14d, %r13
subq %r13, %rbx
movq 0xf86c7(%rip), %rdi     # 0x10f3c0
callq 0x7040
movq 0xf86c3(%rip), %rdi     # 0x10f3c8
callq 0x7040
leal (,%rbx,8), %r14d
movl %r14d, %edi
callq 0x779c
movq %rax, 0xf869f(%rip)     # 0x10f3c0
movl %r14d, %edi
callq 0x779c
movq %rax, 0xf8698(%rip)     # 0x10f3c8
xorl %r15d, %r15d
testl %ebx, %ebx
movl $0x0, %ecx
cmovgl %ebx, %ecx
movq %rcx, -0x60(%rbp)
shlq $0x3, %r13
movq %r13, -0x38(%rbp)
cmpq %r15, -0x60(%rbp)
je 0x16dd5
movq -0x38(%rbp), %rax
leaq (%rax,%r15,8), %r13
leaq 0x2a84e(%rip), %r12     # 0x415b0
movq (%r12,%r13), %rdi
callq 0x861b
callq 0xd2cc
callq 0x9fbd
callq 0x868d
movq %rax, %r14
movq (%r12,%r13), %rdi
callq 0x861b
callq 0xd208
callq 0x9fbd
callq 0x868d
cmpb $0x5, 0x10(%r14)
jne 0x16fd0
cmpb $0x5, 0x10(%rax)
jne 0x16fd0
movsd (%r14), %xmm0
movq 0xf860a(%rip), %rcx     # 0x10f3c0
movsd %xmm0, (%rcx,%r15,8)
movsd (%rax), %xmm0
movq 0xf8601(%rip), %rax     # 0x10f3c8
movsd %xmm0, (%rax,%r15,8)
incq %r15
jmp 0x16d49
movl -0x2c(%rbp), %r12d
movl %r12d, 0x214c8(%rip)    # 0x382a8
movq 0xf85d9(%rip), %rcx     # 0x10f3c0
leaq -0x1(%rbx), %rdx
movsd -0x8(%rcx,%rbx,8), %xmm0
movsd -0x8(%rax,%rbx,8), %xmm1
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm3
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
cmpq %rsi, %rdx
je 0x16e58
movsd (%rcx,%rsi,8), %xmm3
movsd (%rax,%rsi,8), %xmm4
movapd %xmm1, %xmm5
mulsd %xmm4, %xmm5
movapd %xmm1, %xmm6
mulsd %xmm3, %xmm6
mulsd %xmm0, %xmm3
addsd %xmm5, %xmm3
divsd %xmm2, %xmm3
mulsd %xmm0, %xmm4
subsd %xmm6, %xmm4
divsd %xmm2, %xmm4
movsd %xmm3, (%rcx,%rsi,8)
movsd %xmm4, (%rax,%rsi,8)
incq %rsi
jmp 0x16e12
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, -0x8(%rcx,%rbx,8)
andq $0x0, -0x8(%rax,%rbx,8)
leaq -0x48(%rbp), %r14
leaq -0x40(%rbp), %r15
cmpl $0x2, %ebx
jl 0x16f51
movq 0xf853b(%rip), %rdi     # 0x10f3c0
movq 0xf853c(%rip), %rsi     # 0x10f3c8
movl %ebx, %edx
movq %r14, %rcx
movq %r15, %r8
callq 0x17070
movsd -0x48(%rbp), %xmm3
movapd %xmm3, %xmm1
movapd 0xc276(%rip), %xmm2     # 0x23120
andpd %xmm2, %xmm1
movsd -0x40(%rbp), %xmm4
movapd %xmm4, %xmm0
andpd %xmm2, %xmm0
movapd %xmm0, %xmm2
mulsd 0xc2c1(%rip), %xmm2     # 0x23188
ucomisd %xmm1, %xmm2
jbe 0x16ed6
andq $0x0, -0x48(%rbp)
xorpd %xmm3, %xmm3
movapd %xmm3, %xmm1
andpd 0xc23e(%rip), %xmm1     # 0x23120
mulsd 0xc29e(%rip), %xmm1     # 0x23188
ucomisd %xmm0, %xmm1
jbe 0x16ef9
andq $0x0, -0x40(%rbp)
xorpd %xmm4, %xmm4
movapd %xmm4, -0x60(%rbp)
movapd %xmm3, %xmm0
movapd %xmm3, -0x70(%rbp)
callq 0xaf59
movaps -0x60(%rbp), %xmm0
callq 0xaf59
movq 0xedbb4(%rip), %rdi     # 0x104ad0
callq 0x861b
callq 0x9fae
callq 0xa1f6
movq 0xf848e(%rip), %rdi     # 0x10f3c0
movq 0xf848f(%rip), %rsi     # 0x10f3c8
movl %ebx, %edx
movapd -0x70(%rbp), %xmm0
movapd -0x60(%rbp), %xmm1
callq 0x17300
decl %ebx
jmp 0x16e75
movl 0x21351(%rip), %ebx     # 0x382a8
subl %r12d, %ebx
jne 0x16f65
movq 0x27a8d(%rip), %rdi     # 0x3e9f0
jmp 0x16fbd
cmpl $0x1, %ebx
jne 0x16f79
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %edi
callq 0x88d6
movl %ebx, %edi
callq 0x77b7
movq %rax, %rdi
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
cmpq %rax, %rbx
je 0x16fb6
movq -0x38(%rbp), %rcx
leaq (%rcx,%rax,8), %rcx
leaq 0x2a60b(%rip), %rdx     # 0x415b0
movq (%rdx,%rcx), %rcx
movq (%rdi), %rdx
movq %rcx, 0x68(%rdx,%rax,8)
incq %rax
jmp 0x16f91
movl %r12d, 0x212eb(%rip)    # 0x382a8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
leaq 0x10924(%rip), %rdi     # 0x278fb
callq 0x7756