// File: /workspace/github_c_makefile_star2_O1/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, %r12
leaq 0x265ee(%rip), %r15     # 0x435c0
movq (%r15,%r12,8), %rdi
callq 0xaece
testl %eax, %eax
je 0x1cfeb
movq 0x2115a(%rip), %rdi     # 0x3e140
jmp 0x1d1f7
movl %r14d, -0x50(%rbp)
movq %rbx, -0x58(%rbp)
testl %ebx, %ebx
jle 0x1d09b
movl -0x58(%rbp), %edx
leaq (,%r12,8), %rcx
xorl %eax, %eax
movq %r12, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
movq %rax, -0x48(%rbp)
addq %r12, %rax
movq (%r15,%rax,8), %rdi
cmpb $0x4, 0x10(%rdi)
jne 0x1d030
movq 0x8(%rdi), %rax
cmpl $0x1, -0x4(%rax)
jne 0x1d030
cmpl $0x1, (%rax)
je 0x1d087
movq %rcx, %rbx
callq 0x8b01
callq 0xdee7
callq 0x8b78
callq 0x8b78
movq %rbx, %rcx
movq %rax, %r14
xorl %r13d, %r13d
leaq (%rcx,%r13,8), %r12
movq (%r15,%r12), %rdi
callq 0x8b01
movq %r14, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
movq -0x38(%rbp), %rdx
movq %rbx, %rcx
movq %rax, (%r15,%r12)
incq %r13
cmpq %r13, %rdx
jne 0x1d050
movq -0x48(%rbp), %rax
incq %rax
cmpq %rdx, %rax
movq -0x40(%rbp), %r12
jne 0x1d010
movl 0x1d217(%rip), %ebx     # 0x3a2b8
movq (%r15,%r12,8), %rdi
callq 0x8b01
callq 0xeb5b
movl %eax, %edi
callq 0x1d2d2
movslq 0x1d1fb(%rip), %r13     # 0x3a2b8
movq -0x58(%rbp), %r14
leal (%r12,%r14), %eax
decl %eax
cltq
movq (%r15,%rax,8), %rdi
callq 0x8b01
callq 0xeb5b
movl %eax, %edi
callq 0x1d2d2
movl %ebx, -0x2c(%rbp)
cmpl %r13d, %ebx
movl -0x50(%rbp), %r12d
jge 0x1d1de
movslq -0x2c(%rbp), %rax
movq %rax, -0x38(%rbp)
movl 0x1d1bc(%rip), %eax     # 0x3a2b8
movq %r13, %rcx
shlq $0x3, %rcx
movq %rcx, -0x48(%rbp)
movl %eax, %ecx
subl %r13d, %ecx
movq %rcx, -0x40(%rbp)
movq %r13, -0x60(%rbp)
movl %eax, -0x4c(%rbp)
cmpl %eax, %r13d
jge 0x1d1c3
xorl %ebx, %ebx
movq -0x38(%rbp), %rax
movq (%r15,%rax,8), %rdi
callq 0x8b01
movq -0x48(%rbp), %rax
leaq (%rax,%rbx,8), %rax
movq %r15, %r13
movq (%r15,%rax), %rdi
callq 0x8b01
callq 0xd9a4
callq 0x8b78
movq %rax, %r15
movl %r12d, %edi
movl %r14d, %esi
movq %rax, %rdx
callq 0x1d34a
callq 0x8b78
movq %rax, %rdi
callq 0xaece
testl %eax, %eax
jne 0x1d1eb
movq %r15, %rdi
callq 0x8b01
movq 0xf4272(%rip), %rdi     # 0x1113f0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
movq %rax, %r15
movl %r12d, %edi
movl %r14d, %esi
movq %rax, %rdx
callq 0x1d34a
callq 0x8b78
movq %rax, %rdi
callq 0xaece
testl %eax, %eax
jne 0x1d1eb
incq %rbx
cmpl %ebx, -0x40(%rbp)
movq %r13, %r15
jne 0x1d122
movq -0x38(%rbp), %rcx
incq %rcx
movq -0x60(%rbp), %r13
movq %rcx, -0x38(%rbp)
cmpl %ecx, %r13d
movl -0x4c(%rbp), %eax
jne 0x1d117
movl -0x2c(%rbp), %eax
movl %eax, 0x1d0d1(%rip)     # 0x3a2b8
xorl %eax, %eax
jmp 0x1d201
movl -0x2c(%rbp), %eax
movl %eax, 0x1d0c4(%rip)     # 0x3a2b8
movq %r15, %rdi
callq 0x8b01
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq