// File: /workspace/github_c_makefile_star2_O0/georgeweigt[P]eigenmath/eigenmath.c
// Function: roots
void
roots(void)
{
	int h, i, j, k, n;
	struct atom *A, *P, *X;

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

	h = tos;

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

	k = tos;

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

	// check coeffs

	for (i = 0; i < n; i++)
		if (!isrational(stack[h + i]))
			stopf("roots: coeffs");

	// find roots

	while (n > 1) {

		if (findroot(h, n) == 0)
			break; // no root found

		// A is the root

		A = stack[tos - 1];

		// divide p(x) by X - A

		reduce(h, n, A);

		n--;
	}

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

	if (n == 0) {
		tos = h; // pop all
		push_symbol(NIL); // no roots
		return;
	}

	sort(n); // sort roots

	// eliminate repeated roots

	for (i = 0; i < n - 1; i++)
		if (equal(stack[k + i], stack[k + i + 1])) {
			for (j = i + 1; j < n - 1; j++)
				stack[k + j] = stack[k + j + 1];
			i--;
			n--;
		}

	if (n == 1) {
		A = stack[k];
		tos = h; // pop all
		push(A); // one root
		return;
	}

	A = alloc_vector(n);

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

	tos = h; // pop all

	push(A);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
callq 0x91d0
movq %rax, -0x30(%rbp)
callq 0x91d0
movq %rax, -0x28(%rbp)
movl 0x29388(%rip), %eax     # 0x582b8
movl %eax, -0x4(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x28760
movl 0x29372(%rip), %eax     # 0x582b8
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
subl -0x4(%rbp), %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2ef97
movl -0x4(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x3264f(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rax
movzbl 0x10(%rax), %eax
cmpl $0x4, %eax
je 0x2ef8a
leaq 0x1a8ef(%rip), %rdi     # 0x49874
callq 0x78d0
jmp 0x2ef8c
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2ef59
jmp 0x2ef99
cmpl $0x1, -0x14(%rbp)
jle 0x2efe6
movl -0x4(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x2f170
cmpl $0x0, %eax
jne 0x2efb1
jmp 0x2efe6
movl 0x29301(%rip), %eax     # 0x582b8
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x325fc(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movl -0x4(%rbp), %edi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x2f410
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2ef99
movl 0x292cc(%rip), %eax     # 0x582b8
subl -0x10(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2f012
movl -0x4(%rbp), %eax
movl %eax, 0x292b7(%rip)     # 0x582b8
movq 0x2f9f8(%rip), %rdi     # 0x5ea00
callq 0x9110
jmp 0x2f15e
movl -0x14(%rbp), %edi
callq 0x9750
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2f0d5
movl -0x10(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x3257e(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rdi
movl -0x10(%rbp), %eax
addl -0x8(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x32567(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rsi
callq 0x93b0
cmpl $0x0, %eax
jne 0x2f0c5
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2f0b3
movl -0x10(%rbp), %eax
addl -0xc(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x32530(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rdx
movl -0x10(%rbp), %eax
addl -0xc(%rbp), %eax
movslq %eax, %rcx
leaq 0x3251c(%rip), %rax     # 0x615c0
movq %rdx, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x2f070
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2f0c7
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2f021
cmpl $0x1, -0x14(%rbp)
jne 0x2f102
movslq -0x10(%rbp), %rcx
leaq 0x324da(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movl -0x4(%rbp), %eax
movl %eax, 0x291c1(%rip)     # 0x582b8
movq -0x20(%rbp), %rdi
callq 0x9110
jmp 0x2f15e
movl -0x14(%rbp), %edi
callq 0x7970
movq %rax, -0x20(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2f14c
movl -0x10(%rbp), %eax
addl -0x8(%rbp), %eax
movslq %eax, %rcx
leaq 0x32493(%rip), %rax     # 0x615c0
movq (%rax,%rcx,8), %rdx
movq -0x20(%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 0x2f115
movl -0x4(%rbp), %eax
movl %eax, 0x29163(%rip)     # 0x582b8
movq -0x20(%rbp), %rdi
callq 0x9110
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)