// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
leaq 0x367b4(%rip), %r13     # 0x40a00
callq 0x8b78
movq %rax, %rbx
callq 0x8b78
movq %rax, %r14
movb 0x10(%rax), %al
cmpb $0x7, %al
jne 0xa26d
cmpb $0x7, 0x10(%rbx)
je 0xa45f
movb 0x10(%rbx), %cl
cmpb $0x7, %cl
je 0xa493
cmpb $0x7, %al
je 0xa4e1
cmpb $0x5, %cl
jne 0xa2b5
cmpq 0x3903b(%rip), %r14     # 0x432c8
jne 0xa2b5
callq 0x74ec
movb $0x5, 0x10(%rax)
movabsq $0x4005bf0a8b145769, %rcx # imm = 0x4005BF0A8B145769
movq %rcx, (%rax)
movq %rax, %rdi
callq 0x8b01
callq 0x8b78
movq %rax, %r14
cmpq 0x36d94(%rip), %r14     # 0x41050
jne 0xa2ea
cmpb $0x5, 0x10(%rbx)
jne 0xa2ea
callq 0x74ec
movb $0x5, 0x10(%rax)
movabsq $0x400921fb54442d18, %rcx # imm = 0x400921FB54442D18
movq %rcx, (%rax)
movq %rax, %rdi
callq 0x8b01
callq 0x8b78
movq %rax, %r14
movb 0x10(%r14), %r12b
movl %r12d, %eax
andb $-0x2, %al
cmpb $0x4, %al
jne 0xa304
movb 0x10(%rbx), %al
andb $-0x2, %al
cmpb $0x4, %al
je 0xa5c5
movq %rbx, %rdi
callq 0xaece
testl %eax, %eax
jne 0xa453
movq %r14, %rdi
callq 0xaece
testl %eax, %eax
jne 0xa45f
movq %r14, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
jne 0xa453
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
jne 0xa52a
cmpb $0x4, %r12b
jne 0xa38e
movq 0x8(%r14), %rax
cmpl $0x1, -0x4(%rax)
jne 0xa371
cmpl $0x1, (%rax)
je 0xa645
cmpb $0x4, %r12b
jne 0xa38e
movq 0x8(%r14), %rax
cmpl $0x1, -0x4(%rax)
jne 0xa5de
cmpl $0x1, (%rax)
jne 0xa5de
cmpq 0x38f33(%rip), %r14     # 0x432c8
je 0xa540
cmpb $0x1, %r12b
movq %r13, %rax
cmoveq %r14, %rax
movq (%rax), %rax
cmpq 0x38ef0(%rip), %rax     # 0x432a0
je 0xa556
cmpq 0x38eeb(%rip), %rax     # 0x432a8
je 0xa56f
movq 0x38ee6(%rip), %rdi     # 0x432b0
cmpq %rdi, %rax
jne 0xa466
leaq 0x8(%r14), %r15
cmpb $0x1, %r12b
movq %r13, %rax
cmoveq %r15, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %r13, %rax
movq (%rax), %rdi
callq 0x8b01
cmpb $0x1, 0x10(%r14)
cmovneq %r13, %r15
movq (%r15), %rax
movb 0x10(%rax), %cl
addq $0x8, %rax
cmpb $0x1, %cl
movq %r13, %rdx
cmoveq %rax, %rdx
movq (%rdx), %rdx
cmpb $0x1, 0x10(%rdx)
movq %r13, %rdx
jne 0xa428
cmpb $0x1, %cl
cmovneq %r13, %rax
movq (%rax), %rdx
movq (%rdx), %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
incl 0xfc692(%rip)           # 0x106ad0
movl $0x2, %edi
callq 0xa8bb
decl 0xfc682(%rip)           # 0x106ad0
jmp 0xa24c
movq 0xfc67e(%rip), %rdi     # 0x106ad8
jmp 0xa52d
movq 0x38e4a(%rip), %rdi     # 0x432b0
callq 0x8b01
movq %r14, %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movl $0x3, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ad9
movq %rbx, %rdi
callq 0x953d
movq %rax, %rbx
movq (%rax), %rax
movslq 0x64(%rax), %r15
testq %r15, %r15
jle 0xa4dc
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x8b01
callq 0xa234
callq 0x8b78
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0xa4ad
movq %rbx, %rdi
jmp 0xa52d
movq %r14, %rdi
callq 0x953d
movq %rax, %r14
movq (%rax), %rax
movslq 0x64(%rax), %r15
testq %r15, %r15
jle 0xa52a
xorl %r12d, %r12d
movq (%r14), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
callq 0xa234
callq 0x8b78
movq (%r14), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0xa4fb
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1a4b3
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1a6b2
addq $0x8, %r14
cmpb $0x1, %r12b
leaq 0x36482(%rip), %r12     # 0x40a00
cmovneq %r12, %r14
movl 0x2fd2f(%rip), %r15d    # 0x3a2b8
movq (%r14), %r14
cmpb $0x1, 0x10(%r14)
jne 0xa5ba
movq (%r14), %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
callq 0xa234
leaq 0x8(%r14), %rax
cmpb $0x1, 0x10(%r14)
cmovneq %r12, %rax
movq (%rax), %r14
jmp 0xa58c
movl 0x2fcf8(%rip), %edi     # 0x3a2b8
subl %r15d, %edi
jmp 0xa632
movq %r14, %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1a092
movq %r14, %rdi
callq 0x8b01
callq 0xd9c4
movq %rbx, %rdi
callq 0x8b01
callq 0xa234
movq %r14, %rdi
callq 0x8b01
callq 0xdee7
callq 0x8b78
movq %rbx, %rdi
callq 0x8b01
movq 0x106dd7(%rip), %rdi    # 0x1113f0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
callq 0xa234
movl $0x2, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa8bb
movslq 0x2fc6c(%rip), %r12     # 0x3a2b8
movq %r14, %rdi
callq 0x8b01
callq 0x1752f
movl 0x2fc59(%rip), %eax     # 0x3a2b8
subl %r12d, %eax
movl %eax, -0x2c(%rbp)
movl %eax, %eax
movq %rax, -0x40(%rbp)
jle 0xa777
shlq $0x3, %r12
xorl %r14d, %r14d
leaq 0x38f41(%rip), %r13     # 0x435c0
movq %r12, -0x38(%rbp)
leaq (%r12,%r14,8), %rax
movq (%r13,%rax), %r12
cmpb $0x1, 0x10(%r12)
leaq 0x36367(%rip), %rax     # 0x40a00
cmoveq %r12, %rax
movq (%rax), %r15
movq 0x38c09(%rip), %r13     # 0x432b0
movq %r13, %rdi
callq 0x8b01
cmpq %r13, %r15
je 0xa6c6
movq %r12, %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
jmp 0xa740
cmpb $0x1, 0x10(%r12)
leaq 0x8(%r12), %r15
leaq 0x36328(%rip), %r13     # 0x40a00
movq %r13, %rax
cmoveq %r15, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %r13, %rax
movq (%rax), %rdi
callq 0x8b01
cmpb $0x1, 0x10(%r12)
cmovneq %r13, %r15
movq (%r15), %rax
movb 0x10(%rax), %cl
addq $0x8, %rax
cmpb $0x1, %cl
movq %r13, %rdx
cmoveq %rax, %rdx
movq (%rdx), %rdx
cmpb $0x1, 0x10(%rdx)
movq %r13, %rdx
jne 0xa726
cmpb $0x1, %cl
cmovneq %r13, %rax
movq (%rax), %rdx
movq (%rdx), %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movq -0x38(%rbp), %r12
leaq 0x38e75(%rip), %r13     # 0x435c0
leaq (,%r14,8), %r15
movl $0x3, %edi
callq 0x8ad9
callq 0x8b78
addq %r12, %r15
movq %rax, (%r13,%r15)
incq %r14
cmpq %r14, -0x40(%rbp)
jne 0xa683
movl -0x2c(%rbp), %ebx
cmpl $0x2, %ebx
jl 0xa7dc
movslq 0x2fb32(%rip), %rax     # 0x3a2b8
leaq 0x38e33(%rip), %rcx     # 0x435c0
leaq (%rcx,%rax,8), %rdi
movq -0x40(%rbp), %rsi
leaq (,%rsi,8), %rax
subq %rax, %rdi
leaq 0xe103(%rip), %rcx      # 0x188aa
movl $0x8, %edx
callq 0x70a0
movl %ebx, %edi
callq 0x8ad9
movq 0x38ae9(%rip), %rdi     # 0x432a8
callq 0x8b01
callq 0xad38
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b47
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq