// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
callq 0x8b78
movq %rax, %rbx
callq 0x8b78
movl 0x210c4(%rip), %r14d    # 0x3a2b8
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1957f
movl 0x210b3(%rip), %ebx     # 0x3a2b8
movq 0xf81c4(%rip), %rdi     # 0x1113d0
testq %rdi, %rdi
je 0x19216
callq 0x7040
subl %r14d, %ebx
movq 0xf81b8(%rip), %rdi     # 0x1113d8
testq %rdi, %rdi
je 0x1922a
callq 0x7040
movl %r14d, -0x44(%rbp)
movslq %r14d, %rax
movq %rax, -0x50(%rbp)
leal (,%rbx,8), %r14d
movl %r14d, %edi
callq 0x7810
movq %rax, 0xf8184(%rip)     # 0x1113d0
movl %r14d, %edi
callq 0x7810
movq %rax, 0xf817d(%rip)     # 0x1113d8
testl %ebx, %ebx
jle 0x192ff
movl %ebx, %eax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0x60(%rbp)
xorl %r13d, %r13d
leaq 0x2a33d(%rip), %r15     # 0x435c0
movq -0x60(%rbp), %rax
leaq (%rax,%r13,8), %r12
movq (%r15,%r12), %rdi
callq 0x8b01
callq 0xe371
callq 0xa7fa
callq 0x8b78
movq %rax, %r14
movq (%r15,%r12), %rdi
callq 0x8b01
callq 0xe28b
callq 0xa7fa
callq 0x8b78
cmpb $0x5, 0x10(%r14)
jne 0x19573
cmpb $0x5, 0x10(%rax)
jne 0x19573
movsd (%r14), %xmm0
movq 0xf80f1(%rip), %rcx     # 0x1113d0
movsd %xmm0, (%rcx,%r13,8)
movsd (%rax), %xmm0
movq 0xf80e8(%rip), %rax     # 0x1113d8
movsd %xmm0, (%rax,%r13,8)
incq %r13
cmpq %r13, -0x30(%rbp)
jne 0x19283
movl -0x44(%rbp), %r13d
movl %r13d, 0x20fae(%rip)    # 0x3a2b8
movq 0xf80bf(%rip), %rax     # 0x1113d0
movslq %ebx, %rsi
leaq -0x1(%rsi), %rcx
movq 0xf80b9(%rip), %rdx     # 0x1113d8
cmpl $0x2, %ebx
jl 0x19395
movsd -0x8(%rax,%rsi,8), %xmm0
movsd -0x8(%rdx,%rsi,8), %xmm1
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm3
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
cmpl $0x2, %ecx
movl $0x1, %esi
cmovgel %ecx, %esi
xorl %edi, %edi
movsd (%rax,%rdi,8), %xmm3
movsd (%rdx,%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, (%rax,%rdi,8)
movsd %xmm4, (%rdx,%rdi,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x19351
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rsi, (%rax,%rcx,8)
movq $0x0, (%rdx,%rcx,8)
cmpl $0x2, %ebx
jl 0x194c0
leaq -0x40(%rbp), %r14
leaq -0x38(%rbp), %r15
movb $0x5, %r12b
movq 0xf800a(%rip), %rdi     # 0x1113d0
movq 0xf800b(%rip), %rsi     # 0x1113d8
movl %ebx, %edx
movq %r14, %rcx
movq %r15, %r8
callq 0x19618
movsd -0x40(%rbp), %xmm1
movapd 0xcd19(%rip), %xmm2     # 0x26100
andpd %xmm2, %xmm1
movsd -0x38(%rbp), %xmm0
andpd %xmm2, %xmm0
movapd %xmm0, %xmm2
mulsd 0xcd48(%rip), %xmm2     # 0x26148
ucomisd %xmm1, %xmm2
jbe 0x1940e
movq $0x0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm1
movapd %xmm1, -0x60(%rbp)
andpd 0xcce0(%rip), %xmm1     # 0x26100
mulsd 0xcd20(%rip), %xmm1     # 0x26148
ucomisd %xmm0, %xmm1
jbe 0x19436
movq $0x0, -0x38(%rbp)
callq 0x74ec
movb %r12b, 0x10(%rax)
movaps -0x60(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8b01
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x74ec
movb %r12b, 0x10(%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8b01
movq 0xed666(%rip), %rdi     # 0x106ae0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movl $0x2, %edi
callq 0xa975
movq 0xf7f36(%rip), %rdi     # 0x1113d0
movq 0xf7f37(%rip), %rsi     # 0x1113d8
movl %ebx, %edx
movapd -0x60(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
callq 0x19a44
leal -0x1(%rbx), %eax
cmpl $0x2, %ebx
movl %eax, %ebx
jg 0x193bf
movslq 0x20df1(%rip), %rax     # 0x3a2b8
movl %eax, %ebx
subl %r13d, %ebx
jne 0x194da
movq 0x2752b(%rip), %rdi     # 0x40a00
jmp 0x19560
cmpl $0x1, %ebx
jne 0x194ee
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a0cb(%rip), %r14     # 0x435c0
leaq (%r14,%rax,8), %rdi
movslq %ebx, %rsi
leaq (,%rsi,8), %rax
subq %rax, %rdi
leaq -0x1068f(%rip), %rcx    # 0x8e7f
movl $0x8, %edx
callq 0x70a0
movl %ebx, %edi
callq 0x7850
movq (%rax), %rcx
movl $0x1, (%rcx)
movq (%rax), %rcx
movl %ebx, 0x4(%rcx)
testl %ebx, %ebx
movq -0x50(%rbp), %r8
jle 0x19556
movl %ebx, %ecx
shlq $0x3, %r8
xorl %edx, %edx
leaq (%r8,%rdx,8), %rsi
movq (%r14,%rsi), %rsi
movq (%rax), %rdi
movq %rsi, 0x68(%rdi,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x1953e
movl %r13d, 0x20d5b(%rip)    # 0x3a2b8
movq %rax, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
leaq 0x11329(%rip), %rdi     # 0x2a8a3
callq 0x77c8