// File: /workspace/github_c_makefile_star2_O3/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 0xd1c4
testl %eax, %eax
je 0x1ca14
movq %rbx, %rdi
callq 0x1cc49
movl 0x228fd(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x1cc3d
decl %eax
movl %eax, 0x228e5(%rip)     # 0x3f2b8
leaq 0x2bbe6(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rdi
movb 0x10(%rdi), %al
cmpb $0x1, %al
leaq 0x29016(%rip), %rbx     # 0x45a00
movq %rbx, %rcx
cmoveq %rdi, %rcx
movq (%rcx), %rcx
cmpq 0x2b8ad(%rip), %rcx     # 0x482a8
je 0x1cad4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
cmpb $0x4, 0x10(%rbx)
movq 0x8(%rbx), %rsi
jne 0x1ca6e
cmpl $0x1, -0x4(%rsi)
jne 0x1ca6e
cmpl $0x1, (%rsi)
jne 0x1ca6e
movq (%r15), %rdi
movq (%rbx), %rsi
callq 0x85a7
movq %rax, %r14
movl $0x1, %edi
callq 0x7b1f
movzbl 0x10(%rbx), %ecx
cmpl $0x5, %ecx
je 0x1cc14
cmpl $0x4, %ecx
jne 0x1cc22
cmpb $0x1, 0x12(%rbx)
jne 0x1cc22
xorl %edi, %edi
movq %rax, %rsi
movq %r14, %rdx
jmp 0x1cc2a
movq (%rbx), %rdi
callq 0x80ac
movq %rax, %r13
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x839d
movq %rax, %r14
leaq -0x4(%r13), %r12
cmpl $0x1, -0x4(%r13)
jne 0x1ca9e
cmpl $0x0, (%r13)
je 0x1cb28
movq (%r15), %rdi
movq %r13, %rsi
callq 0x85a7
movq %rax, %r13
movl $0x1, %edi
callq 0x7b1f
movzbl 0x10(%rbx), %ecx
cmpl $0x5, %ecx
je 0x1cb11
cmpl $0x4, %ecx
jne 0x1cb1b
cmpb $0x1, 0x12(%rbx)
jne 0x1cb1b
xorl %edi, %edi
movq %rax, %rsi
movq %r13, %rdx
jmp 0x1cb23
addq $0x8, %rdi
cmpb $0x1, %al
cmovneq %rbx, %rdi
movq (%rdi), %r14
cmpb $0x1, 0x10(%r14)
jne 0x1cb02
movq (%r14), %rdi
callq 0x8ba5
leaq 0x8(%r14), %rax
cmpb $0x1, 0x10(%r14)
cmovneq %rbx, %rax
movq (%rax), %r14
jmp 0x1cae1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
ja 0x1caca
xorl %edi, %edi
movq %r13, %rsi
movq %rax, %rdx
callq 0xbf3e
movq %r12, %rdi
callq 0x7040
decl 0x26626(%rip)           # 0x4315c
movq (%r15), %rdi
cmpl $0x1, -0x4(%rdi)
jne 0x1cb44
cmpl $0x0, (%rdi)
jns 0x1cbb8
movq 0x8(%rbx), %rsi
callq 0x89b8
testq %rax, %rax
je 0x1cbb8
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
callq 0x85a7
movq %rax, %r15
movl $0x1, %edi
callq 0x7b1f
movq %rax, %r12
addq $-0x4, %r13
movq %r13, %rdi
callq 0x7040
movl 0x265d9(%rip), %r13d    # 0x4315c
addq $-0x4, %r14
movq %r14, %rdi
callq 0x7040
addl $-0x2, %r13d
movl %r13d, 0x265c2(%rip)    # 0x4315c
movzbl 0x10(%rbx), %eax
cmpl $0x5, %eax
je 0x1cc00
cmpl $0x4, %eax
jne 0x1cc0a
cmpb $0x1, 0x12(%rbx)
jne 0x1cc0a
xorl %edi, %edi
movq %r12, %rsi
movq %r15, %rdx
jmp 0x1cc2a
movq 0x2b6f1(%rip), %rdi     # 0x482b0
callq 0x8ba5
movq %r15, %rdi
callq 0x8ba5
movzbl 0x12(%rbx), %r15d
movq 0x8(%rbx), %rdi
callq 0x7e97
movl %r15d, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0xbf3e
movl $0x3, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b7d
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
ja 0x1cbae
xorl %edi, %edi
movq %r15, %rsi
movq %r12, %rdx
jmp 0x1cc2a
xorpd %xmm0, %xmm0
ucomisd (%rbx), %xmm0
ja 0x1ca61
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 0xbf3e
leaq 0x122fd(%rip), %rdi     # 0x2ef41
callq 0x780b