// File: /workspace/github_c_makefile_star2_O1/georgeweigt[P]eigenmath/eigenmath.c
// Function: reduce_radical_rational
struct atom *
reduce_radical_rational(int h, struct atom *COEF)
{
	int i, k;
	struct atom *p1, *p2, *NUMER, *DENOM, *BASE, *EXPO;

	if (isplusone(COEF) || isminusone(COEF))
		return COEF; // COEF has no factors, no cancellation is possible

	push(COEF);
	absfunc();
	p1 = pop();

	push(p1);
	numerator();
	NUMER = pop();

	push(p1);
	denominator();
	DENOM = pop();

	k = 0;

	for (i = h; i < tos; i++) {
		p1 = stack[i];
		if (!isradical(p1))
			continue;
		BASE = cadr(p1);
		EXPO = caddr(p1);
		if (isnegativenumber(EXPO)) {
			mod_integers(NUMER, BASE);
			p2 = pop();
			if (iszero(p2)) {
				push(NUMER);
				push(BASE);
				divide();
				NUMER = pop();
				push_symbol(POWER);
				push(BASE);
				push_integer(1);
				push(EXPO);
				add();
				list(3);
				stack[i] = pop();
				k++;
			}
		} else {
			mod_integers(DENOM, BASE);
			p2 = pop();
			if (iszero(p2)) {
				push(DENOM);
				push(BASE);
				divide();
				DENOM = pop();
				push_symbol(POWER);
				push(BASE);
				push_integer(-1);
				push(EXPO);
				add();
				list(3);
				stack[i] = pop();
				k++;
			}
		}
	}

	if (k) {
		push(NUMER);
		push(DENOM);
		divide();
		if (isnegativenumber(COEF))
			negate();
		COEF = pop();
	}

	return COEF;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %r12d
movq %rsi, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
jne 0x18df2
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
jne 0x18df2
movq %rbx, %rdi
callq 0x8b01
callq 0x9be7
callq 0x8b78
movq %rax, %r15
movq %rax, %rdi
callq 0x8b01
callq 0xdee7
callq 0xad38
callq 0x8b78
callq 0x8b78
movq %rax, %r14
movq %r15, %rdi
callq 0x8b01
callq 0xdee7
callq 0x8b78
callq 0x8b78
movq %rax, %r13
movb $0x1, %al
cmpl %r12d, 0x216b4(%rip)    # 0x3a2b8
jle 0x18dee
movq %r14, -0x38(%rbp)
movq %rbx, -0x48(%rbp)
movslq %r12d, %r14
leaq 0x2a9a4(%rip), %rax     # 0x435c0
leaq (%rax,%r14,8), %r15
movl $0x0, -0x2c(%rbp)
movq %r13, %rbx
movq (%r15), %r12
movq %r12, %rdi
callq 0x18f9e
testl %eax, %eax
je 0x18dc5
leaq 0x8(%r12), %rax
cmpb $0x1, 0x10(%r12)
leaq 0x27db1(%rip), %rdi     # 0x40a00
cmovneq %rdi, %rax
movq (%rax), %rax
movb 0x10(%rax), %dl
leaq 0x8(%rax), %rcx
cmpb $0x1, %dl
cmovneq %rdi, %rax
movq %rdi, %rsi
cmoveq %rcx, %rsi
movq (%rsi), %rsi
cmpb $0x1, 0x10(%rsi)
movq %rdi, %rsi
jne 0x18c88
cmpb $0x1, %dl
leaq 0x27d7f(%rip), %rdx     # 0x40a00
cmovneq %rdx, %rcx
movq (%rcx), %rsi
movq (%rax), %r13
movq (%rsi), %r12
movzbl 0x10(%r12), %eax
cmpl $0x5, %eax
je 0x18cad
cmpl $0x4, %eax
jne 0x18d23
cmpb $0x1, 0x12(%r12)
sete %al
jmp 0x18cba
xorpd %xmm0, %xmm0
ucomisd (%r12), %xmm0
seta %al
testb %al, %al
je 0x18d23
movq %rbx, -0x40(%rbp)
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x17f1f
callq 0x8b78
movq %rax, %rdi
callq 0xaece
testl %eax, %eax
je 0x18dc1
movq %rbx, %rdi
callq 0x8b01
movq %r13, %rdi
callq 0x8b01
movq 0xf86f3(%rip), %rdi     # 0x1113f0
callq 0x8b01
callq 0xa234
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
movq %rax, -0x38(%rbp)
leaq 0xeddb7(%rip), %rbx     # 0x106ad8
jmp 0x18d7e
movq %rbx, %rdi
movq %r13, %rsi
callq 0x17f1f
callq 0x8b78
movq %rax, %rdi
callq 0xaece
testl %eax, %eax
je 0x18dc5
movq %rbx, %rdi
callq 0x8b01
movq %r13, %rdi
callq 0x8b01
movq 0xf8696(%rip), %rdi     # 0x1113f0
callq 0x8b01
callq 0xa234
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
movq %rax, -0x40(%rbp)
leaq 0xf8672(%rip), %rbx     # 0x1113f0
movq 0x2a52b(%rip), %rdi     # 0x432b0
callq 0x8b01
movq %r13, %rdi
callq 0x8b01
movq (%rbx), %rdi
callq 0x8b01
movq %r12, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa975
movl $0x3, %edi
callq 0x8ad9
callq 0x8b78
movq %rax, (%r15)
incl -0x2c(%rbp)
movq -0x40(%rbp), %rbx
incq %r14
movslq 0x214e9(%rip), %rax     # 0x3a2b8
addq $0x8, %r15
cmpq %rax, %r14
jl 0x18c2a
movq %rbx, %r13
cmpl $0x0, -0x2c(%rbp)
sete %al
movq -0x48(%rbp), %rbx
movq -0x38(%rbp), %r14
testb %al, %al
je 0x18e04
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x8b01
movq %r13, %rdi
callq 0x8b01
movq 0xf85d5(%rip), %rdi     # 0x1113f0
callq 0x8b01
callq 0xa234
movl $0x2, %edi
callq 0xa8bb
movzbl 0x10(%rbx), %eax
cmpl $0x5, %eax
je 0x18e46
cmpl $0x4, %eax
jne 0x18e6b
cmpb $0x1, 0x12(%rbx)
sete %al
jmp 0x18e51
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
seta %al
testb %al, %al
je 0x18e6b
movq 0xf8594(%rip), %rdi     # 0x1113f0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b78