// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movslq 0x24235(%rip), %rdx     # 0x3f2b8
movl $0xfffe795f, %eax       # imm = 0xFFFE795F
leal (%rdx,%rax), %ecx
cmpl %eax, %ecx
jbe 0x1b4ad
leal -0x1(%rdx), %eax
movl %eax, 0x2421c(%rip)     # 0x3f2b8
cmpl $0x1, %edx
jbe 0x1b4ad
movl %eax, %eax
leaq 0x2d512(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rsi
movq %rdx, -0x68(%rbp)
leaq -0x2(%rdx), %rbx
movl %ebx, 0x241f8(%rip)     # 0x3f2b8
movl %ebx, %r15d
movq (%rcx,%r15,8), %rdi
callq 0x1b4c5
movl 0x241e6(%rip), %eax     # 0x3f2b8
movl %eax, -0x40(%rbp)
movq 0xfb2f4(%rip), %rdi     # 0x1163d0
testq %rdi, %rdi
je 0x1b0e6
callq 0x7040
movl -0x40(%rbp), %eax
movl %eax, %r12d
subl %ebx, %r12d
movq 0xfb2e2(%rip), %rdi     # 0x1163d8
testq %rdi, %rdi
je 0x1b100
callq 0x7040
movq %rbx, -0x78(%rbp)
leal (,%r12,8), %r14d
movl %r14d, %edi
callq 0x7853
movq %rax, 0xfb2b5(%rip)     # 0x1163d0
movl %r14d, %edi
callq 0x7853
movq %rax, 0xfb2ae(%rip)     # 0x1163d8
testl %r12d, %r12d
movq %r12, -0x70(%rbp)
jle 0x1b214
movl %r12d, %eax
movq %rax, -0x60(%rbp)
shlq $0x3, %r15
xorl %r13d, %r13d
movl $0xfffe795f, %r12d      # imm = 0xFFFE795F
leaq 0x2d46e(%rip), %rdx     # 0x485c0
leaq (%r15,%r13,8), %rax
movq (%rdx,%rax), %rdi
movq %rdx, %r14
callq 0x8ba5
callq 0xeef9
callq 0xac30
movl 0x24146(%rip), %eax     # 0x3f2b8
leal (%rax,%r12), %ecx
cmpl %r12d, %ecx
jbe 0x1b4ad
leaq (,%r13,8), %rcx
decl %eax
movl %eax, 0x24129(%rip)     # 0x3f2b8
movq (%r14,%rax,8), %rbx
addq %r15, %rcx
movq (%r14,%rcx), %rdi
callq 0x8ba5
callq 0xeda7
callq 0xac30
movl 0x24109(%rip), %eax     # 0x3f2b8
leal (%rax,%r12), %ecx
cmpl %r12d, %ecx
jbe 0x1b4ad
decl %eax
movl %eax, 0x240f4(%rip)     # 0x3f2b8
cmpb $0x5, 0x10(%rbx)
leaq 0x2d3f1(%rip), %rdx     # 0x485c0
jne 0x1b4b9
movq (%rdx,%rax,8), %rax
cmpb $0x5, 0x10(%rax)
jne 0x1b4b9
movsd (%rbx), %xmm0
movq 0xfb1e2(%rip), %rcx     # 0x1163d0
movsd %xmm0, (%rcx,%r13,8)
movsd (%rax), %xmm0
movq 0xfb1d9(%rip), %rax     # 0x1163d8
movsd %xmm0, (%rax,%r13,8)
incq %r13
cmpq %r13, -0x60(%rbp)
jne 0x1b152
jmp 0x1b21b
movq 0xfb1b5(%rip), %rcx     # 0x1163d0
movq -0x78(%rbp), %r12
movl %r12d, 0x24092(%rip)    # 0x3f2b8
movq -0x70(%rbp), %r8
movslq %r8d, %rsi
leaq -0x1(%rsi), %rdx
cmpl $0x1, %r8d
jle 0x1b407
movsd -0x8(%rcx,%rsi,8), %xmm0
movsd -0x8(%rax,%rsi,8), %xmm1
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm3
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
movl %edx, %esi
xorl %edi, %edi
movsd (%rcx,%rdi,8), %xmm3
movsd (%rax,%rdi,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,%rdi,8)
movsd %xmm4, (%rax,%rdi,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x1b25f
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rsi, (%rcx,%rdx,8)
movq $0x0, (%rax,%rdx,8)
cmpl $0x2, %r8d
movl -0x40(%rbp), %ebx
jl 0x1b41d
subl -0x68(%rbp), %ebx
addl $0x3, %ebx
leaq -0x50(%rbp), %r14
leaq -0x48(%rbp), %r15
movb $0x5, %r13b
decl %ebx
movq 0xfb0f0(%rip), %rdi     # 0x1163d0
movq 0xfb0f1(%rip), %rsi     # 0x1163d8
movl %ebx, %edx
movq %r14, %rcx
movq %r15, %r8
callq 0x1b5fe
movsd -0x50(%rbp), %xmm3
movapd %xmm3, %xmm1
movapd 0xee1b(%rip), %xmm2     # 0x2a120
andpd %xmm2, %xmm1
movsd -0x48(%rbp), %xmm4
movapd %xmm4, %xmm0
andpd %xmm2, %xmm0
movapd %xmm0, %xmm2
mulsd 0xee46(%rip), %xmm2     # 0x2a168
ucomisd %xmm1, %xmm2
jbe 0x1b334
movq $0x0, -0x50(%rbp)
xorpd %xmm3, %xmm3
movapd %xmm3, -0x60(%rbp)
movapd %xmm3, %xmm1
andpd 0xeddb(%rip), %xmm1     # 0x2a120
mulsd 0xee1b(%rip), %xmm1     # 0x2a168
ucomisd %xmm0, %xmm1
jbe 0x1b35f
movq $0x0, -0x48(%rbp)
xorpd %xmm4, %xmm4
movapd %xmm4, -0x40(%rbp)
callq 0x74dc
movb %r13b, 0x10(%rax)
movaps -0x60(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8ba5
callq 0x74dc
movb %r13b, 0x10(%rax)
movaps -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8ba5
movq 0xf0743(%rip), %rdi     # 0x10bae0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl $0x2, %edi
callq 0xadb3
movq 0xfb013(%rip), %rdi     # 0x1163d0
movq 0xfb014(%rip), %rsi     # 0x1163d8
movl %ebx, %edx
movapd -0x60(%rbp), %xmm0
movapd -0x40(%rbp), %xmm1
callq 0x1b97f
cmpl $0x2, %ebx
jg 0x1b2d7
movslq 0x23ed3(%rip), %rax     # 0x3f2b8
movl %eax, %ebx
subl %r12d, %ebx
leaq 0x2d1cf(%rip), %rcx     # 0x485c0
je 0x1b41d
cmpl $0x1, %ebx
jne 0x1b437
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rsi, (%rcx,%rdx,8)
movq $0x0, (%rax,%rdx,8)
movq 0x2a5dc(%rip), %rdi     # 0x45a00
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
leaq (%rcx,%rax,8), %rdi
movslq %ebx, %rsi
leaq (,%rsi,8), %rax
subq %rax, %rdi
leaq -0x1251b(%rip), %rcx    # 0x8f35
movl $0x8, %edx
callq 0x70a0
movl %ebx, %edi
callq 0x7893
leaq 0x2d158(%rip), %r9      # 0x485c0
movq (%rax), %rcx
movl $0x1, (%rcx)
movq (%rax), %rcx
movl %ebx, 0x4(%rcx)
testl %ebx, %ebx
jle 0x1b49e
movl %ebx, %ecx
movq %r12, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
leaq (%rdx,%rsi,8), %rdi
movq (%r9,%rdi), %rdi
movq (%rax), %r8
movq %rdi, 0x68(%r8,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x1b486
movl %r12d, 0x23e13(%rip)    # 0x3f2b8
movq %rax, %rdi
jmp 0x1b424
leaq 0x13a8d(%rip), %rdi     # 0x2ef41
callq 0x780b
leaq 0x13403(%rip), %rdi     # 0x2e8c3
callq 0x780b