// File: /workspace/github_c_makefile_star2_O3/georgeweigt[P]eigenmath/eigenmath.c
// Function: factor_factor
void
factor_factor(void)
{
	uint32_t *numer, *denom;
	struct atom *INPUT, *BASE, *EXPO;

	INPUT = pop();

	if (car(INPUT) == symbol(POWER)) {

		BASE = cadr(INPUT);
		EXPO = caddr(INPUT);

		if (!isrational(BASE) || !isrational(EXPO)) {
			push(INPUT); // cannot factor
			return;
		}

		if (isminusone(BASE)) {
			push(INPUT); // -1 to the M
			return;
		}

		if (isnegativenumber(BASE)) {
			push_symbol(POWER);
			push_integer(-1);
			push(EXPO);
			list(3); // leave on stack
		}

		numer = BASE->u.q.a;
		denom = BASE->u.q.b;

		if (!MEQUAL(numer, 1))
			factor_bignum(numer, EXPO);

		if (!MEQUAL(denom, 1)) {
			// flip sign of exponent
			push(EXPO);
			negate();
			EXPO = pop();
			factor_bignum(denom, EXPO);
		}

		return;
	}

	if (!isrational(INPUT) || iszero(INPUT) || isplusone(INPUT) || isminusone(INPUT)) {
		push(INPUT);
		return;
	}

	if (isnegativenumber(INPUT))
		push_integer(-1);

	numer = INPUT->u.q.a;
	denom = INPUT->u.q.b;

	if (!MEQUAL(numer, 1))
		factor_bignum(numer, one);

	if (!MEQUAL(denom, 1))
		factor_bignum(denom, minusone);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x261e2(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x192de
decl %eax
movl %eax, 0x261ca(%rip)     # 0x3f2b8
leaq 0x2f4cb(%rip), %r13     # 0x485c0
movq (%r13,%rax,8), %rbx
movb 0x10(%rbx), %cl
cmpb $0x1, %cl
leaq 0x2c8f9(%rip), %rax     # 0x45a00
movq %rax, %rdx
cmoveq %rbx, %rdx
movq 0x2f19b(%rip), %r14     # 0x482b0
cmpq %r14, (%rdx)
je 0x191b6
cmpb $0x4, %cl
jne 0x19214
movq %rbx, %rdi
callq 0xb477
testl %eax, %eax
jne 0x19214
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xd1c4
testl %eax, %eax
jne 0x19214
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0xd1c4
testl %eax, %eax
jne 0x19214
cmpb $0x1, 0x12(%rbx)
jne 0x1917d
movq 0xfd278(%rip), %rdi     # 0x1163f0
callq 0x8ba5
movq (%rbx), %rdi
movq 0x8(%rbx), %rbx
cmpl $0x1, -0x4(%rdi)
jne 0x1918f
cmpl $0x1, (%rdi)
je 0x1919b
movq 0xf2942(%rip), %rsi     # 0x10bad8
callq 0x23bae
cmpl $0x1, -0x4(%rbx)
jne 0x191aa
cmpl $0x1, (%rbx)
je 0x1927c
movq 0xfd23f(%rip), %rsi     # 0x1163f0
jmp 0x192c8
leaq 0x8(%rbx), %rdx
cmpb $0x1, %cl
cmovneq %rax, %rdx
movq (%rdx), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0x191d9
movq (%rcx), %r15
movq 0x8(%rcx), %rcx
cmpb $0x1, 0x10(%rcx)
je 0x191e9
jmp 0x191ec
movq 0x2c820(%rip), %rcx     # 0x45a00
cmpb $0x1, 0x10(%rcx)
movq %rcx, %r15
jne 0x191ec
movq %rcx, %rax
cmpb $0x4, 0x10(%r15)
jne 0x19214
movq (%rax), %r12
cmpb $0x4, 0x10(%r12)
jne 0x19214
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0xd1c4
testl %eax, %eax
je 0x1922a
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
cmpb $0x1, 0x12(%r15)
jne 0x19257
movq %r14, %rdi
callq 0x8ba5
movq 0xfd1b0(%rip), %rdi     # 0x1163f0
callq 0x8ba5
movq %r12, %rdi
callq 0x8ba5
movl $0x3, %edi
callq 0x8b7d
movq (%r15), %rdi
movq 0x8(%r15), %rbx
cmpl $0x1, -0x4(%rdi)
jne 0x19269
cmpl $0x1, (%rdi)
je 0x19271
movq %r12, %rsi
callq 0x23bae
cmpl $0x1, -0x4(%rbx)
jne 0x1928b
cmpl $0x1, (%rbx)
jne 0x1928b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x8ba5
movq 0xfd156(%rip), %rdi     # 0x1163f0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl 0x26009(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x192de
decl %eax
movl %eax, 0x25ff5(%rip)     # 0x3f2b8
movq (%r13,%rax,8), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x23bae
leaq 0x15c5c(%rip), %rdi     # 0x2ef41
callq 0x780b