// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: power
void
power(void)
{
	int h, i, n;
	struct atom *p1, *BASE, *EXPO;

	EXPO = pop();
	BASE = pop();

	if (istensor(BASE) && istensor(EXPO)) {
		push_symbol(POWER);
		push(BASE);
		push(EXPO);
		list(3);
		return;
	}

	if (istensor(EXPO)) {
		p1 = copy_tensor(EXPO);
		n = p1->u.tensor->nelem;
		for (i = 0; i < n; i++) {
			push(BASE);
			push(p1->u.tensor->elem[i]);
			power();
			p1->u.tensor->elem[i] = pop();
		}
		push(p1);
		return;
	}

	if (istensor(BASE)) {
		p1 = copy_tensor(BASE);
		n = p1->u.tensor->nelem;
		for (i = 0; i < n; i++) {
			push(p1->u.tensor->elem[i]);
			push(EXPO);
			power();
			p1->u.tensor->elem[i] = pop();
		}
		push(p1);
		return;
	}

	if (BASE == symbol(EXP1) && isdouble(EXPO)) {
		push_double(M_E);
		BASE = pop();
	}

	if (BASE == symbol(PI) && isdouble(EXPO)) {
		push_double(M_PI);
		BASE = pop();
	}

	if (isnum(BASE) && isnum(EXPO)) {
		power_numbers(BASE, EXPO);
		return;
	}

	// expr^0

	if (iszero(EXPO)) {
		push_integer(1);
		return;
	}

	// 0^expr

	if (iszero(BASE)) {
		push_symbol(POWER);
		push(BASE);
		push(EXPO);
		list(3);
		return;
	}

	// 1^expr

	if (isplusone(BASE)) {
		push_integer(1);
		return;
	}

	// expr^1

	if (isplusone(EXPO)) {
		push(BASE);
		return;
	}

	// BASE is an integer?

	if (isinteger(BASE)) {
		// raise each factor in BASE to power EXPO
		// EXPO is not numerical, that case was handled by power_numbers() above
		h = tos;
		push(BASE);
		factor_factor();
		n = tos - h;
		for (i = 0; i < n; i++) {
			p1 = stack[h + i];
			if (car(p1) == symbol(POWER)) {
				push_symbol(POWER);
				push(cadr(p1)); // base
				push(caddr(p1)); // expo
				push(EXPO);
				multiply();
				list(3);
			} else {
				push_symbol(POWER);
				push(p1);
				push(EXPO);
				list(3);
			}
			stack[h + i] = pop();
		}
		if (n > 1) {
			sort_factors(n);
			list(n);
			push_symbol(MULTIPLY);
			swap();
			cons(); // prepend MULTIPLY to list
		}
		return;
	}

	// BASE is a numerical fraction?

	if (isfraction(BASE)) {
		// power numerator, power denominator
		// EXPO is not numerical, that case was handled by power_numbers() above
		push(BASE);
		numerator();
		push(EXPO);
		power();
		push(BASE);
		denominator();
		push(EXPO);
		negate();
		power();
		multiply();
		return;
	}

	// BASE = e ?

	if (BASE == symbol(EXP1)) {
		power_natural_number(EXPO);
		return;
	}

	// (a + b) ^ c

	if (car(BASE) == symbol(ADD)) {
		power_sum(BASE, EXPO);
		return;
	}

	// (a b) ^ c  -->  (a ^ c) (b ^ c)

	if (car(BASE) == symbol(MULTIPLY)) {
		h = tos;
		p1 = cdr(BASE);
		while (iscons(p1)) {
			push(car(p1));
			push(EXPO);
			power();
			p1 = cdr(p1);
		}
		multiply_factors(tos - h);
		return;
	}

	// (a ^ b) ^ c  -->  a ^ (b c)

	if (car(BASE) == symbol(POWER)) {
		push(cadr(BASE));
		push(caddr(BASE));
		push(EXPO);
		multiply_expand(); // always expand products of exponents
		power();
		return;
	}

	// none of the above

	push_symbol(POWER);
	push(BASE);
	push(EXPO);
	list(3);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x34f51(%rip), %r15     # 0x3e9f0
callq 0x868d
movq %rax, %rbx
callq 0x868d
movq %rax, %r14
cmpb $0x7, 0x10(%rax)
movb 0x10(%rbx), %al
je 0x9c4a
cmpb $0x7, %al
je 0x9c84
cmpb $0x5, %al
jne 0x9ae6
cmpq 0x377e9(%rip), %r14     # 0x412b8
jne 0x9ae6
movsd 0x19657(%rip), %xmm0    # 0x23130
callq 0xaf59
callq 0x868d
movq %rax, %r14
cmpq 0x35553(%rip), %r14     # 0x3f040
jne 0x9b0a
cmpb $0x5, 0x10(%rbx)
jne 0x9b0a
movsd 0x1963b(%rip), %xmm0    # 0x23138
callq 0xaf59
callq 0x868d
movq %rax, %r14
movb 0x10(%r14), %r12b
movl %r12d, %eax
andb $-0x2, %al
cmpb $0x4, %al
jne 0x9b24
movb 0x10(%rbx), %al
andb $-0x2, %al
cmpb $0x4, %al
je 0x9f86
movq %rbx, %rdi
callq 0xa641
testl %eax, %eax
jne 0x9c34
movq %r14, %rdi
callq 0xa641
testl %eax, %eax
jne 0x9c52
movq %r14, %rdi
callq 0xa95a
testl %eax, %eax
jne 0x9c34
movq %rbx, %rdi
callq 0xa95a
testl %eax, %eax
jne 0x9f70
movq %r14, %rdi
callq 0x8b5d
testl %eax, %eax
jne 0x9cd9
movq %r14, %rdi
callq 0x17b57
testl %eax, %eax
jne 0x9e4b
cmpq 0x3772d(%rip), %r14     # 0x412b8
je 0x9e97
cmpb $0x1, %r12b
movq %r15, %rcx
cmoveq %r14, %rcx
sete %al
movq (%rcx), %rcx
cmpq 0x376e7(%rip), %rcx     # 0x41290
je 0x9ead
cmpq 0x376e2(%rip), %rcx     # 0x41298
je 0x9ec6
movq 0x376dd(%rip), %rdi     # 0x412a0
cmpq %rdi, %rcx
jne 0x9c59
leaq 0x8(%r14), %r13
cmpb $0x1, %r12b
movq %r15, %rax
cmoveq %r13, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %r15, %rax
movq (%rax), %rdi
callq 0x861b
cmpb $0x1, 0x10(%r14)
cmovneq %r15, %r13
movq (%r13), %rax
cmpb $0x1, 0x10(%rax)
jne 0x9c07
movq 0x8(%rax), %rax
jmp 0x9c0e
movq 0x34de2(%rip), %rax     # 0x3e9f0
cmpb $0x1, 0x10(%rax)
movq %r15, %rcx
jne 0x9c1a
movq %rax, %rcx
movq (%rcx), %rdi
callq 0x861b
movq %rbx, %rdi
callq 0x861b
callq 0x16b50
jmp 0x9a9f
pushq $0x1
popq %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa426
cmpb $0x7, %al
jne 0x9f23
movq 0x37647(%rip), %rdi     # 0x412a0
callq 0x861b
movq %r14, %rdi
callq 0x861b
movq %rbx, %rdi
callq 0x861b
pushq $0x3
popq %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x85eb
movq %rbx, %rdi
callq 0x8f1b
movq %rax, %rbx
movq (%rax), %rax
movl 0x64(%rax), %r15d
xorl %r12d, %r12d
testl %r15d, %r15d
cmovlel %r12d, %r15d
cmpq %r12, %r15
je 0x9cd1
movq %r14, %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x861b
callq 0x9a87
callq 0x868d
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
jmp 0x9ca0
movq %rbx, %rdi
jmp 0x9f73
movslq 0x2e5c8(%rip), %r12     # 0x382a8
movq %r14, %rdi
callq 0x861b
callq 0x1540f
movl 0x2e5b5(%rip), %eax     # 0x382a8
subl %r12d, %eax
xorl %r14d, %r14d
testl %eax, %eax
movl $0x0, %ecx
movl %eax, -0x34(%rbp)
cmovgl %eax, %ecx
movq %rcx, -0x48(%rbp)
shlq $0x3, %r12
leaq 0x3789b(%rip), %r13     # 0x415b0
movq %rbx, -0x40(%rbp)
movq %r12, -0x30(%rbp)
cmpq %r14, -0x48(%rbp)
je 0x9e0d
leaq (%r12,%r14,8), %rax
movq (%r13,%rax), %r12
cmpb $0x1, 0x10(%r12)
leaq 0x34cb3(%rip), %rbx     # 0x3e9f0
movq %rbx, %rax
cmoveq %r12, %rax
movq (%rax), %r15
movq 0x37552(%rip), %r13     # 0x412a0
movq %r13, %rdi
callq 0x861b
cmpq %r13, %r15
je 0x9d79
movq %r12, %rdi
callq 0x861b
movq -0x40(%rbp), %rdi
callq 0x861b
movq -0x30(%rbp), %r12
leaq 0x37839(%rip), %r13     # 0x415b0
jmp 0x9de8
cmpb $0x1, 0x10(%r12)
leaq 0x8(%r12), %r15
movq %rbx, %rax
cmoveq %r15, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %rbx, %rax
movq (%rax), %rdi
callq 0x861b
cmpb $0x1, 0x10(%r12)
cmovneq %rbx, %r15
movq (%r15), %rax
cmpb $0x1, 0x10(%rax)
jne 0x9db7
movq 0x8(%rax), %rax
jmp 0x9dbe
movq 0x34c32(%rip), %rax     # 0x3e9f0
cmpb $0x1, 0x10(%rax)
movq -0x30(%rbp), %r12
leaq 0x377e3(%rip), %r13     # 0x415b0
jne 0x9dd2
movq %rax, %rbx
movq (%rbx), %rdi
callq 0x861b
movq -0x40(%rbp), %rdi
callq 0x861b
callq 0x9fae
leaq (,%r14,8), %r15
pushq $0x3
popq %rdi
callq 0x85eb
callq 0x868d
addq %r12, %r15
movq %rax, (%r13,%r15)
incq %r14
jmp 0x9d1d
movl -0x34(%rbp), %ebx
cmpl $0x2, %ebx
jl 0x9f9f
movl %ebx, %edi
callq 0x162a3
movl %ebx, %edi
callq 0x85eb
movq 0x3746a(%rip), %rdi     # 0x41298
callq 0x861b
callq 0xa49b
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x865c
movq %r14, %rdi
callq 0x861b
callq 0xca1a
movq %rbx, %rdi
callq 0x861b
callq 0x9a87
movq %r14, %rdi
callq 0x861b
callq 0xca2e
movq %rbx, %rdi
callq 0x861b
callq 0x975f
callq 0x9a87
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9fae
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17b7e
movq %r14, %rdi
movq %rbx, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17de0
movl 0x2e3db(%rip), %r15d    # 0x382a8
leaq 0x34b1c(%rip), %r12     # 0x3e9f0
addq $0x8, %r14
testb $0x1, %al
cmoveq %r12, %r14
movq (%r14), %r14
cmpb $0x1, 0x10(%r14)
jne 0x9f07
movq (%r14), %rdi
callq 0x861b
movq %rbx, %rdi
callq 0x861b
callq 0x9a87
cmpb $0x1, 0x10(%r14)
sete %al
jmp 0x9ed4
movl 0x2e39b(%rip), %edi     # 0x382a8
subl %r15d, %edi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa04c
movq %r14, %rdi
callq 0x8f1b
movq %rax, %r14
movq (%rax), %rax
movl 0x64(%rax), %r15d
xorl %r12d, %r12d
testl %r15d, %r15d
cmovlel %r12d, %r15d
cmpq %r12, %r15
je 0x9f70
movq (%r14), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x861b
movq %rbx, %rdi
callq 0x861b
callq 0x9a87
callq 0x868d
movq (%r14), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
jmp 0x9f3f
movq %r14, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
movq %r14, %rdi
movq %rbx, %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17857
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq