// File: /workspace/github_c_makefile_star2_O0/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
subq $0x70, %rsp
callq 0x91d0
movq %rax, -0x28(%rbp)
callq 0x91d0
movq %rax, -0x20(%rbp)
movl 0x2ff98(%rip), %eax     # 0x582b8
movl %eax, -0x4(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x28760
movl 0x2ff82(%rip), %eax     # 0x582b8
subl -0x4(%rbp), %eax
movl %eax, -0xc(%rbp)
cmpq $0x0, 0x10708c(%rip)    # 0x12f3d0
je 0x28352
movq 0x107083(%rip), %rdi    # 0x12f3d0
callq 0x7040
cmpq $0x0, 0x10707e(%rip)    # 0x12f3d8
je 0x28368
movq 0x107075(%rip), %rdi    # 0x12f3d8
callq 0x7040
movslq -0xc(%rbp), %rax
shlq $0x3, %rax
movl %eax, %edi
callq 0x7930
movq %rax, 0x107052(%rip)    # 0x12f3d0
movslq -0xc(%rbp), %rax
shlq $0x3, %rax
movl %eax, %edi
callq 0x7930
movq %rax, 0x107044(%rip)    # 0x12f3d8
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x28463
movl -0x4(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x39209(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rdi
callq 0x9110
callq 0x12760
callq 0xc290
callq 0x91d0
movq %rax, -0x30(%rbp)
movl -0x4(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x391dd(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rdi
callq 0x9110
callq 0x12670
callq 0xc290
callq 0x91d0
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x5, %eax
jne 0x28419
movq -0x38(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x5, %eax
je 0x28425
leaq 0x21453(%rip), %rdi     # 0x49873
callq 0x78d0
movq -0x30(%rbp), %rax
movsd (%rax), %xmm0
movq 0x106f9c(%rip), %rax    # 0x12f3d0
movslq -0x8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movsd (%rax), %xmm0
movq 0x106f8c(%rip), %rax    # 0x12f3d8
movslq -0x8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2839b
movl -0x4(%rbp), %eax
movl %eax, 0x2fe4c(%rip)     # 0x582b8
movq 0x106f5d(%rip), %rax    # 0x12f3d0
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x58(%rbp)
movq 0x106f4b(%rip), %rax    # 0x12f3d8
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x58(%rbp), %xmm2
movsd -0x60(%rbp), %xmm1
mulsd -0x60(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x285a0
movq 0x106ef0(%rip), %rax    # 0x12f3d0
movslq -0x8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x58(%rbp), %xmm2
movq 0x106ee3(%rip), %rax    # 0x12f3d8
movslq -0x8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd -0x60(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movq 0x106ebc(%rip), %rax    # 0x12f3d8
movslq -0x8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x58(%rbp), %xmm2
movq 0x106e9f(%rip), %rax    # 0x12f3d0
movslq -0x8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd -0x60(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
movq 0x106e5c(%rip), %rax    # 0x12f3d0
movslq -0x8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x70(%rbp), %xmm0
movq 0x106e4f(%rip), %rax    # 0x12f3d8
movslq -0x8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x284c8
movq 0x106e29(%rip), %rax    # 0x12f3d0
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0x1caf8(%rip), %xmm0    # 0x450b0
movsd %xmm0, (%rax,%rcx,8)
movq 0x106e14(%rip), %rax    # 0x12f3d8
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
cmpl $0x1, -0xc(%rbp)
jle 0x286c9
movq 0x106dea(%rip), %rdi    # 0x12f3d0
movq 0x106deb(%rip), %rsi    # 0x12f3d8
movl -0xc(%rbp), %edx
leaq -0x40(%rbp), %rcx
leaq -0x48(%rbp), %r8
callq 0x28800
movsd -0x40(%rbp), %xmm1
movaps 0x1cb37(%rip), %xmm0    # 0x45140
pand %xmm0, %xmm1
movsd -0x48(%rbp), %xmm2
movaps 0x1cb27(%rip), %xmm0    # 0x45140
pand %xmm0, %xmm2
movsd 0x1cabb(%rip), %xmm0    # 0x450e0
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28637
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x48(%rbp), %xmm1
movaps 0x1cafd(%rip), %xmm0    # 0x45140
pand %xmm0, %xmm1
movsd -0x40(%rbp), %xmm2
movaps 0x1caed(%rip), %xmm0    # 0x45140
pand %xmm0, %xmm2
movsd 0x1ca81(%rip), %xmm0    # 0x450e0
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28671
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x40(%rbp), %xmm0
callq 0xe5e0
movsd -0x48(%rbp), %xmm0
callq 0xe5e0
movq 0xfc454(%rip), %rdi     # 0x124ae0
callq 0x9110
callq 0xc280
callq 0xc660
movq 0x106d2e(%rip), %rdi    # 0x12f3d0
movq 0x106d2f(%rip), %rsi    # 0x12f3d8
movl -0xc(%rbp), %edx
movsd -0x40(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
callq 0x28bf0
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x285d5
movl 0x2fbe9(%rip), %eax     # 0x582b8
subl -0x4(%rbp), %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x286e9
movq 0x3631e(%rip), %rdi     # 0x5ea00
callq 0x9110
jmp 0x28755
cmpl $0x1, -0xc(%rbp)
jne 0x286f1
jmp 0x28755
movl -0xc(%rbp), %edi
callq 0x9750
movl -0xc(%rbp), %edi
callq 0x7970
movq %rax, -0x18(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x28743
movl -0x4(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x38e9c(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x8(%rbp), %rcx
movq %rdx, 0x68(%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2870c
movl -0x4(%rbp), %eax
movl %eax, 0x2fb6c(%rip)     # 0x582b8
movq -0x18(%rbp), %rdi
callq 0x9110
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)