// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: findroot
int
findroot(int h, int n)
{
	int i, j, m, p, q, r;
	struct atom *A, *C, *PA;

	// check constant term

	if (iszero(stack[h])) {
		push_integer(0); // root is zero
		return 1;
	}

	// eliminate denominators

	for (i = 0; i < n; i++) {
		C = stack[h + i];
		if (isinteger(C))
			continue;
		push(C);
		denominator();
		C = pop();
		for (j = 0; j < n; j++) {
			push(stack[h + j]);
			push(C);
			multiply();
			stack[h + j] = pop();
		}
	}

	p = tos;

	push(stack[h]);
	m = pop_integer();
	divisors(m); // divisors of constant term

	q = tos;

	push(stack[h + n - 1]);
	m = pop_integer();
	divisors(m); // divisors of leading coeff

	r = tos;

	for (i = p; i < q; i++) {
		for (j = q; j < r; j++) {

			// try positive A

			push(stack[i]);
			push(stack[j]);
			divide();
			A = pop();

			horner(h, n, A);

			PA = pop(); // polynomial evaluated at A

			if (iszero(PA)) {
				tos = p; // pop all
				push(A);
				return 1; // root on stack
			}

			// try negative A

			push(A);
			negate();
			A = pop();

			horner(h, n, A);

			PA = pop(); // polynomial evaluated at A

			if (iszero(PA)) {
				tos = p; // pop all
				push(A);
				return 1; // root on stack
			}
		}
	}

	tos = p; // pop all

	return 0; // no root
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebx
movl %edi, %r14d
movslq %edi, %r15
leaq 0x273b9(%rip), %rax     # 0x415b0
movq (%rax,%r15,8), %rdi
callq 0xa641
testl %eax, %eax
je 0x1a210
xorl %edi, %edi
callq 0xa426
jmp 0x1a3f0
movl %r14d, -0x4c(%rbp)
xorl %ecx, %ecx
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
movq %rax, -0x30(%rbp)
movq %rbx, -0x58(%rbp)
movl %ebx, %r13d
leaq (,%r15,8), %rax
movq %rax, -0x48(%rbp)
movq %r15, -0x38(%rbp)
cmpq -0x30(%rbp), %rcx
je 0x1a2bc
movq %rcx, -0x40(%rbp)
leaq (%rcx,%r15), %rax
leaq 0x27360(%rip), %rcx     # 0x415b0
movq (%rcx,%rax,8), %r15
movq %r15, %rdi
callq 0x8b5d
testl %eax, %eax
je 0x1a26d
movq -0x40(%rbp), %rcx
incq %rcx
movq -0x38(%rbp), %r15
jmp 0x1a23b
movq %r15, %rdi
callq 0x861b
callq 0xca2e
callq 0x868d
movq %rax, %r15
xorl %ebx, %ebx
cmpq %rbx, %r13
je 0x1a260
movq -0x48(%rbp), %rax
leaq (%rax,%rbx,8), %r12
leaq 0x27318(%rip), %r14     # 0x415b0
movq (%r14,%r12), %rdi
callq 0x861b
movq %r15, %rdi
callq 0x861b
callq 0x9fae
callq 0x868d
movq %rax, (%r14,%r12)
incq %rbx
jmp 0x1a284
movl 0x1dfe6(%rip), %ebx     # 0x382a8
leaq 0x272e7(%rip), %r12     # 0x415b0
movq (%r12,%r15,8), %rdi
callq 0x861b
callq 0xd9d9
movl %eax, %edi
callq 0x1a4c2
movq %r15, %rcx
movslq 0x1dfc0(%rip), %r15     # 0x382a8
movq -0x58(%rbp), %rax
addl %ecx, %eax
decl %eax
cltq
movq (%r12,%rax,8), %rdi
callq 0x861b
callq 0xd9d9
movl %eax, %edi
callq 0x1a4c2
movslq 0x1df9a(%rip), %rax     # 0x382a8
movq %rax, -0x48(%rbp)
movl %ebx, -0x30(%rbp)
movslq %ebx, %rax
leaq (%r12,%r15,8), %r14
movq %r15, -0x60(%rbp)
movq %r14, -0x38(%rbp)
movl -0x4c(%rbp), %r13d
cmpq %r15, %rax
jge 0x1a402
movq %r15, %rbx
movq %rax, -0x40(%rbp)
cmpq -0x48(%rbp), %rbx
jge 0x1a3cf
movq (%r12,%rax,8), %rdi
callq 0x861b
movq (%r14), %rdi
callq 0x861b
callq 0xca0b
callq 0x868d
movq %rax, %r15
movl %r13d, %edi
movq -0x58(%rbp), %r12
movl %r12d, %esi
movq %rax, %rdx
callq 0x1a53c
callq 0x868d
movq %rax, %rdi
callq 0xa641
testl %eax, %eax
jne 0x1a3df
movq %r15, %rdi
callq 0x861b
callq 0x975f
callq 0x868d
movq %rax, %r15
movl %r13d, %edi
movl %r12d, %esi
movq %rax, %rdx
callq 0x1a53c
callq 0x868d
movq %rax, %rdi
callq 0xa641
incq %rbx
addq $0x8, %r14
testl %eax, %eax
leaq 0x271ed(%rip), %r12     # 0x415b0
movq -0x40(%rbp), %rax
je 0x1a338
jmp 0x1a3df
incq %rax
movq -0x60(%rbp), %r15
movq -0x38(%rbp), %r14
jmp 0x1a328
movl -0x30(%rbp), %eax
movl %eax, 0x1dec0(%rip)     # 0x382a8
movq %r15, %rdi
callq 0x861b
pushq $0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x30(%rbp), %eax
movl %eax, 0x1de9d(%rip)     # 0x382a8
xorl %eax, %eax
jmp 0x1a3f3