// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: power_numbers_factor
void
power_numbers_factor(struct atom *BASE, struct atom *EXPO)
{
	uint32_t *a, *b, *n, *q, *r;
	struct atom *p0;

	if (isminusone(BASE)) {
		power_minusone(EXPO);
		p0 = pop();
		if (car(p0) == symbol(MULTIPLY)) {
			p0 = cdr(p0);
			while (iscons(p0)) {
				push(car(p0));
				p0 = cdr(p0);
			}
		} else
			push(p0);
		return;
	}

	if (isinteger(EXPO)) {
		a = mpow(BASE->u.q.a, EXPO->u.q.a);
		b = mint(1);
		if (isnegativenumber(EXPO))
			push_bignum(MPLUS, b, a); // reciprocate
		else
			push_bignum(MPLUS, a, b);
		return;
	}

	// EXPO.a          r
	// ------ == q + ------
	// EXPO.b        EXPO.b

	q = mdiv(EXPO->u.q.a, EXPO->u.q.b);
	r = mmod(EXPO->u.q.a, EXPO->u.q.b);

	// process q

	if (!MZERO(q)) {
		a = mpow(BASE->u.q.a, q);
		b = mint(1);
		if (isnegativenumber(EXPO))
			push_bignum(MPLUS, b, a); // reciprocate
		else
			push_bignum(MPLUS, a, b);
	}

	mfree(q);

	// process r

	if (MLENGTH(BASE->u.q.a) == 1 && BASE->u.q.a[0] <= 0x7fffffff) {
		// BASE is less than 2^31, hence BASE is a prime number, no root
		push_symbol(POWER);
		push(BASE);
		push_bignum(EXPO->sign, r, mcopy(EXPO->u.q.b)); // r used here, r is not leaked
		list(3);
		return;
	}

	// BASE was too big to factor, try finding root

	n = mroot(BASE->u.q.a, EXPO->u.q.b);

	if (n == NULL) {
		// no root
		push_symbol(POWER);
		push(BASE);
		push_bignum(EXPO->sign, r, mcopy(EXPO->u.q.b)); // r used here, r is not leaked
		list(3);
		return;
	}

	// raise n to rth power

	a = mpow(n, r);
	b = mint(1);

	mfree(n);
	mfree(r);

	if (isnegativenumber(EXPO))
		push_bignum(MPLUS, b, a); // reciprocate
	else
		push_bignum(MPLUS, a, b);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r15
callq 0xbfac
testl %eax, %eax
je 0x1808b
movq %rbx, %rdi
callq 0x18200
callq 0x868d
movq %rax, %rbx
cmpb $0x1, 0x10(%rax)
leaq 0x269c2(%rip), %r14     # 0x3e9f0
movq %rax, %rcx
cmovneq %r14, %rcx
sete %al
movq (%rcx), %rcx
cmpq 0x29256(%rip), %rcx     # 0x41298
je 0x18069
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
movq (%rbx), %rdi
callq 0x861b
cmpb $0x1, 0x10(%rbx)
sete %al
addq $0x8, %rbx
testb $0x1, %al
cmoveq %r14, %rbx
movq (%rbx), %rbx
cmpb $0x1, 0x10(%rbx)
je 0x1805a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x8b5d
testl %eax, %eax
je 0x180c9
movq (%r15), %rdi
movq (%rbx), %rsi
callq 0x81cc
movq %rax, %r14
pushq $0x1
popq %rdi
callq 0x7a09
movq %rax, %r15
movq %rbx, %rdi
callq 0x8c2a
xorl %edi, %edi
testl %eax, %eax
je 0x18126
movq %r15, %rsi
movq %r14, %rdx
jmp 0x1819e
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x7e20
movq %rax, %r12
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x8025
movq %rax, -0x30(%rbp)
cmpl $0x1, -0x4(%r12)
jne 0x180f7
cmpl $0x0, (%r12)
je 0x18136
movq (%r15), %rdi
movq %r12, %rsi
callq 0x81cc
movq %rax, %r13
pushq $0x1
popq %rdi
callq 0x7a09
movq %rax, %r14
movq %rbx, %rdi
callq 0x8c2a
xorl %edi, %edi
testl %eax, %eax
je 0x1812b
movq %r14, %rsi
movq %r13, %rdx
jmp 0x18131
movq %r14, %rsi
jmp 0x1819b
movq %r13, %rsi
movq %r14, %rdx
callq 0xb015
movq %r12, %rdi
callq 0x7ad9
movq (%r15), %rdi
cmpl $0x1, -0x4(%rdi)
jne 0x1814c
cmpl $0x0, (%rdi)
jns 0x181b1
movq 0x8(%rbx), %rsi
callq 0x84cd
testq %rax, %rax
je 0x181b1
movq %rax, %r13
movq %rax, %rdi
movq -0x30(%rbp), %r14
movq %r14, %rsi
callq 0x81cc
movq %rax, %r15
pushq $0x1
popq %rdi
callq 0x7a09
movq %rax, %r12
movq %r13, %rdi
callq 0x7ad9
movq %r14, %rdi
callq 0x7ad9
movq %rbx, %rdi
callq 0x8c2a
xorl %edi, %edi
testl %eax, %eax
je 0x181f8
movq %r12, %rsi
movq %r15, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb015
movq 0x290e8(%rip), %rdi     # 0x412a0
callq 0x861b
movq %r15, %rdi
callq 0x861b
movzbl 0x12(%rbx), %r14d
movq 0x8(%rbx), %rdi
callq 0x7c9c
movl %r14d, %edi
movq -0x30(%rbp), %rsi
movq %rax, %rdx
callq 0xb015
pushq $0x3
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x85eb
movq %r15, %rsi
movq %r12, %rdx
jmp 0x1819e