// File: /workspace/github_c_makefile_star2_O3/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, %r12d
movl %edi, %ebx
movslq %edi, %r14
leaq 0x2917b(%rip), %rax     # 0x485c0
movq (%rax,%r14,8), %r15
movq %r15, %rdi
callq 0xb477
testl %eax, %eax
je 0x1f461
movq 0x23ce4(%rip), %rdi     # 0x43140
jmp 0x1f731
testl %r12d, %r12d
movq %rbx, -0x40(%rbp)
jle 0x1f56a
movq %r12, -0x30(%rbp)
movl %r12d, %eax
movq %rax, -0x38(%rbp)
leaq (,%r14,8), %r13
xorl %eax, %eax
movl $0xfffe795f, %ebx       # imm = 0xFFFE795F
leaq 0x29131(%rip), %rcx     # 0x485c0
movq %r14, -0x48(%rbp)
movq %rax, -0x50(%rbp)
addq %r14, %rax
movq (%rcx,%rax,8), %rdi
cmpb $0x4, 0x10(%rdi)
jne 0x1f4b7
movq 0x8(%rdi), %rax
cmpl $0x1, -0x4(%rax)
jne 0x1f4b7
cmpl $0x1, (%rax)
je 0x1f549
callq 0x8ba5
callq 0xe26e
movl 0x1fdf1(%rip), %eax     # 0x3f2b8
leal (%rax,%rbx), %ecx
cmpl %ebx, %ecx
jbe 0x1f74a
decl %eax
movl %eax, 0x1fdde(%rip)     # 0x3f2b8
leaq 0x290df(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %r15
xorl %r12d, %r12d
leaq (,%r12,8), %rax
addq %r13, %rax
movq (%rcx,%rax), %rdi
movq %rcx, %r14
callq 0x8ba5
movq %r15, %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl 0x1fda1(%rip), %eax     # 0x3f2b8
leal (%rax,%rbx), %ecx
cmpl %ebx, %ecx
jbe 0x1f74a
leaq (,%r12,8), %rcx
decl %eax
movl %eax, 0x1fd86(%rip)     # 0x3f2b8
movq (%r14,%rax,8), %rax
addq %r13, %rcx
movq %rax, (%r14,%rcx)
incq %r12
cmpq %r12, -0x38(%rbp)
movq %r14, %rcx
jne 0x1f4e8
movq -0x50(%rbp), %rax
incq %rax
cmpq -0x38(%rbp), %rax
movq -0x48(%rbp), %r14
jne 0x1f493
movq (%rcx,%r14,8), %r15
movq -0x30(%rbp), %r12
movq -0x40(%rbp), %rbx
movl 0x1fd47(%rip), %r14d    # 0x3f2b8
movq %r15, %rdi
callq 0x8ba5
callq 0xf8e6
movl %eax, %edi
callq 0x1f865
movslq 0x1fd2c(%rip), %r15     # 0x3f2b8
leal (%rbx,%r12), %eax
decl %eax
cltq
leaq 0x29025(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rdi
callq 0x8ba5
callq 0xf8e6
movl %eax, %edi
callq 0x1f865
movl %r14d, -0x30(%rbp)
cmpl %r15d, %r14d
jge 0x1f718
movslq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movl 0x1fced(%rip), %eax     # 0x3f2b8
movq %r15, %rcx
shlq $0x3, %rcx
movq %rcx, -0x50(%rbp)
movl %eax, %ecx
subl %r15d, %ecx
movq %rcx, -0x48(%rbp)
movl $0xfffe795f, %ebx       # imm = 0xFFFE795F
movq %r15, -0x60(%rbp)
movl %eax, -0x54(%rbp)
cmpl %eax, %r15d
jge 0x1f6fd
xorl %r14d, %r14d
leaq 0x28fc2(%rip), %r13     # 0x485c0
movq -0x38(%rbp), %rax
movq (%r13,%rax,8), %rdi
callq 0x8ba5
movq -0x50(%rbp), %rax
leaq (%rax,%r14,8), %rax
movq (%r13,%rax), %rdi
callq 0x8ba5
callq 0xe218
movl 0x1fc8f(%rip), %eax     # 0x3f2b8
leal (%rax,%rbx), %ecx
cmpl %ebx, %ecx
jbe 0x1f74a
decl %eax
movl %eax, 0x1fc7c(%rip)     # 0x3f2b8
movq (%r13,%rax,8), %r15
movq -0x40(%rbp), %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x1f8dd
movl 0x1fc62(%rip), %eax     # 0x3f2b8
leal (%rax,%rbx), %ecx
cmpl %ebx, %ecx
jbe 0x1f74a
decl %eax
movl %eax, 0x1fc4f(%rip)     # 0x3f2b8
movq (%r13,%rax,8), %rdi
callq 0xb477
testl %eax, %eax
jne 0x1f725
movq %r15, %rdi
callq 0x8ba5
movq 0xf6d66(%rip), %rdi     # 0x1163f0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl 0x1fc19(%rip), %eax     # 0x3f2b8
leal (%rax,%rbx), %ecx
cmpl %ebx, %ecx
jbe 0x1f74a
decl %eax
movl %eax, 0x1fc06(%rip)     # 0x3f2b8
leaq 0x28f07(%rip), %r13     # 0x485c0
movq (%r13,%rax,8), %r15
movq -0x40(%rbp), %rdi
movl %r12d, %esi
movq %r15, %rdx
callq 0x1f8dd
movl 0x1fbe5(%rip), %eax     # 0x3f2b8
leal (%rax,%rbx), %ecx
cmpl %ebx, %ecx
jbe 0x1f74a
decl %eax
movl %eax, 0x1fbd6(%rip)     # 0x3f2b8
movq (%r13,%rax,8), %rdi
callq 0xb477
testl %eax, %eax
jne 0x1f725
incq %r14
cmpl %r14d, -0x48(%rbp)
jne 0x1f5f7
movq -0x38(%rbp), %rcx
incq %rcx
movq -0x60(%rbp), %r15
movq %rcx, -0x38(%rbp)
cmpl %ecx, %r15d
movl -0x54(%rbp), %eax
jne 0x1f5eb
movl -0x30(%rbp), %eax
movl %eax, 0x1fb97(%rip)     # 0x3f2b8
xorl %eax, %eax
jmp 0x1f73b
movl -0x30(%rbp), %eax
movl %eax, 0x1fb8a(%rip)     # 0x3f2b8
movq %r15, %rdi
callq 0x8ba5
movl $0x1, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf7f0(%rip), %rdi      # 0x2ef41
callq 0x780b