// File: /workspace/github_c_makefile_star2_O1/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
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
je 0x1a9b3
movq %rbx, %rdi
callq 0x1abf4
callq 0x8b78
movb 0x10(%rax), %cl
cmpb $0x1, %cl
leaq 0x2607a(%rip), %rbx     # 0x40a00
movq %rbx, %rdx
cmoveq %rax, %rdx
movq (%rdx), %rdx
cmpq 0x28911(%rip), %rdx     # 0x432a8
je 0x1aa65
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
cmpb $0x4, 0x10(%rbx)
jne 0x1aa02
movq 0x8(%rbx), %rax
cmpl $0x1, -0x4(%rax)
jne 0x1aa02
cmpl $0x1, (%rax)
jne 0x1aa02
movq (%r15), %rdi
movq (%rbx), %rsi
callq 0x851d
movq %rax, %r14
movl $0x1, %edi
callq 0x7ad5
movzbl 0x10(%rbx), %ecx
cmpl $0x5, %ecx
je 0x1abc0
cmpl $0x4, %ecx
jne 0x1abd9
cmpb $0x1, 0x12(%rbx)
sete %cl
jmp 0x1abcb
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x8049
movq %rax, %r13
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x830f
movq %rax, %r14
leaq -0x4(%r13), %r12
cmpl $0x1, -0x4(%r13)
jne 0x1aa36
cmpl $0x0, (%r13)
je 0x1aac2
movq (%r15), %rdi
movq %r13, %rsi
callq 0x851d
movq %rax, %r13
movl $0x1, %edi
callq 0x7ad5
movzbl 0x10(%rbx), %ecx
cmpl $0x5, %ecx
je 0x1aa9c
cmpl $0x4, %ecx
jne 0x1aab5
cmpb $0x1, 0x12(%rbx)
sete %cl
jmp 0x1aaa7
addq $0x8, %rax
cmpb $0x1, %cl
cmovneq %rbx, %rax
movq (%rax), %r14
cmpb $0x1, 0x10(%r14)
jne 0x1aa8d
movq (%r14), %rdi
callq 0x8b01
leaq 0x8(%r14), %rax
cmpb $0x1, 0x10(%r14)
jmp 0x1aa6c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
seta %cl
testb %cl, %cl
je 0x1aab5
xorl %edi, %edi
movq %rax, %rsi
movq %r13, %rdx
jmp 0x1aabd
xorl %edi, %edi
movq %r13, %rsi
movq %rax, %rdx
callq 0xb9f7
movq %r12, %rdi
callq 0x7040
decl 0x2368c(%rip)           # 0x3e15c
movq (%r15), %rdi
cmpl $0x1, -0x4(%rdi)
jne 0x1aade
cmpl $0x0, (%rdi)
jns 0x1ab55
movq 0x8(%rbx), %rsi
callq 0x893c
testq %rax, %rax
je 0x1ab55
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
callq 0x851d
movq %rax, %r15
movl $0x1, %edi
callq 0x7ad5
movq %rax, %r12
addq $-0x4, %r13
movq %r13, %rdi
callq 0x7040
movl 0x2363f(%rip), %r13d    # 0x3e15c
leal -0x1(%r13), %eax
movl %eax, 0x23635(%rip)     # 0x3e15c
addq $-0x4, %r14
movq %r14, %rdi
callq 0x7040
addl $-0x2, %r13d
movl %r13d, 0x2361e(%rip)    # 0x3e15c
movzbl 0x10(%rbx), %eax
cmpl $0x5, %eax
je 0x1ab9d
cmpl $0x4, %eax
jne 0x1abb6
cmpb $0x1, 0x12(%rbx)
sete %al
jmp 0x1aba8
movq 0x28754(%rip), %rdi     # 0x432b0
callq 0x8b01
movq %r15, %rdi
callq 0x8b01
movzbl 0x12(%rbx), %r15d
movq 0x8(%rbx), %rdi
callq 0x7e34
movl %r15d, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0xb9f7
movl $0x3, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ad9
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
seta %al
testb %al, %al
je 0x1abb6
xorl %edi, %edi
movq %r12, %rsi
movq %r15, %rdx
jmp 0x1abe1
xorl %edi, %edi
movq %r15, %rsi
movq %r12, %rdx
jmp 0x1abe1
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
seta %cl
testb %cl, %cl
je 0x1abd9
xorl %edi, %edi
movq %rax, %rsi
movq %r14, %rdx
jmp 0x1abe1
xorl %edi, %edi
movq %r14, %rsi
movq %rax, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb9f7