// File: /workspace/github_c_makefile_star2_O1/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
callq 0x8b78
movq %rax, %rbx
movzbl 0x10(%rax), %r14d
cmpl $0x1, %r14d
leaq 0x294ab(%rip), %rax     # 0x40a00
movq %rax, %rcx
cmoveq %rbx, %rcx
movq 0x2bd4d(%rip), %r15     # 0x432b0
cmpq %r15, (%rcx)
je 0x175d6
cmpl $0x4, %r14d
jne 0x17646
movq %rbx, %rdi
callq 0xaece
testl %eax, %eax
jne 0x17646
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
jne 0x17646
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
jne 0x17646
cmpl $0x5, %r14d
je 0x176fc
cmpl $0x4, %r14d
jne 0x17717
cmpb $0x1, 0x12(%rbx)
sete %al
jmp 0x17707
movq %rbx, %rcx
addq $0x8, %rcx
cmpl $0x1, %r14d
cmovneq %rax, %rcx
movq (%rcx), %rsi
movb 0x10(%rsi), %dl
leaq 0x8(%rsi), %rcx
cmpb $0x1, %dl
cmovneq %rax, %rsi
movq %rax, %rdi
cmoveq %rcx, %rdi
movq (%rsi), %r12
movq (%rdi), %rsi
cmpb $0x1, 0x10(%rsi)
jne 0x1761a
cmpb $0x1, %dl
leaq 0x293ed(%rip), %rax     # 0x40a00
cmoveq %rcx, %rax
movq (%rax), %rax
movzbl 0x10(%r12), %r13d
cmpl $0x4, %r13d
jne 0x17646
movq (%rax), %r14
cmpb $0x4, 0x10(%r14)
jne 0x17646
movq %r12, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
je 0x1765c
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
cmpl $0x5, %r13d
je 0x17673
cmpl $0x4, %r13d
jne 0x176aa
cmpb $0x1, 0x12(%r12)
sete %al
jmp 0x17680
xorpd %xmm0, %xmm0
ucomisd (%r12), %xmm0
seta %al
testb %al, %al
je 0x176aa
movq %r15, %rdi
callq 0x8b01
movq 0xf9d5d(%rip), %rdi     # 0x1113f0
callq 0x8b01
movq %r14, %rdi
callq 0x8b01
movl $0x3, %edi
callq 0x8ad9
movq (%r12), %rdi
movq 0x8(%r12), %rbx
cmpl $0x1, -0x4(%rdi)
jne 0x176be
cmpl $0x1, (%rdi)
je 0x176c6
movq %r14, %rsi
callq 0x20c4a
cmpl $0x1, -0x4(%rbx)
jne 0x176d1
cmpl $0x1, (%rbx)
je 0x17740
movq %r14, %rdi
callq 0x8b01
movq 0xf9d10(%rip), %rdi     # 0x1113f0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
movq %rbx, %rdi
movq %rax, %rsi
jmp 0x17759
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
seta %al
testb %al, %al
je 0x17717
movq 0xf9cde(%rip), %rdi     # 0x1113f0
callq 0x8b01
movq (%rbx), %rdi
movq 0x8(%rbx), %rbx
cmpl $0x1, -0x4(%rdi)
jne 0x17729
cmpl $0x1, (%rdi)
je 0x17735
movq 0xef3a8(%rip), %rsi     # 0x106ad8
callq 0x20c4a
cmpl $0x1, -0x4(%rbx)
jne 0x1774f
cmpl $0x1, (%rbx)
jne 0x1774f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf9c9a(%rip), %rsi     # 0x1113f0
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20c4a