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

	p1 = pop();

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

	if (car(p1) == symbol(ADD)) {
		p1 = cdr(p1);
		h = tos;
		while (iscons(p1)) {
			push(car(p1));
			rect();
			p1 = cdr(p1);
		}
		add_terms(tos - h);
		return;
	}

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

	if (car(p1) != symbol(POWER)) {
		push(p1);
		return;
	}

	BASE = cadr(p1);
	EXPO = caddr(p1);

	// handle sum in exponent

	if (car(EXPO) == symbol(ADD)) {
		p1 = cdr(EXPO);
		h = tos;
		while (iscons(p1)) {
			push_symbol(POWER);
			push(BASE);
			push(car(p1));
			list(3);
			rect();
			p1 = cdr(p1);
		}
		multiply_factors(tos - h);
		return;
	}

	// return mag(p1) * cos(arg(p1)) + i sin(arg(p1)))

	push(p1);
	magfunc();

	push(p1);
	argfunc();
	p2 = pop();

	push(p2);
	cosfunc();

	push(imaginaryunit);
	push(p2);
	sinfunc();
	multiply();

	add();

	multiply();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x868d
movq %rax, %rbx
movzbl 0x10(%rax), %edx
movq %rax, %rcx
cmpl $0x1, %edx
je 0x12950
cmpl $0x7, %edx
jne 0x12949
movq %rbx, %rdi
callq 0x8f1b
movq %rax, %rbx
movq (%rax), %rax
movl 0x64(%rax), %r14d
xorl %r15d, %r15d
testl %r14d, %r14d
cmovlel %r15d, %r14d
cmpq %r15, %r14
je 0x1298a
movq (%rbx), %rax
movq 0x68(%rax,%r15,8), %rdi
callq 0x861b
callq 0x128dd
callq 0x868d
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r15,8)
incq %r15
jmp 0x12920
leaq 0x2c0a0(%rip), %rcx     # 0x3e9f0
movq 0x2e939(%rip), %rax     # 0x41290
cmpq %rax, (%rcx)
je 0x129a0
cmpb $0x1, %dl
leaq 0x2c08a(%rip), %rcx     # 0x3e9f0
movq %rcx, %rsi
cmoveq %rbx, %rsi
movq (%rsi), %rsi
cmpq 0x2e921(%rip), %rsi     # 0x41298
je 0x129ff
cmpq 0x2e91c(%rip), %rsi     # 0x412a0
je 0x12a5e
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
addq $0x8, %rbx
cmpb $0x1, %dl
leaq 0x2c042(%rip), %r15     # 0x3e9f0
cmovneq %r15, %rbx
movl 0x258ef(%rip), %r14d    # 0x382a8
movq (%rbx), %r12
cmpb $0x1, 0x10(%r12)
jne 0x129e3
movq (%r12), %rdi
callq 0x861b
callq 0x128dd
leaq 0x8(%r12), %rbx
cmpb $0x1, 0x10(%r12)
cmovneq %r15, %rbx
jmp 0x129b9
movl 0x258bf(%rip), %edi     # 0x382a8
subl %r14d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0fd
addq $0x8, %rbx
cmpb $0x1, %dl
leaq 0x2bfe3(%rip), %r15     # 0x3e9f0
cmovneq %r15, %rbx
movl 0x25890(%rip), %r14d    # 0x382a8
movq (%rbx), %r12
cmpb $0x1, 0x10(%r12)
jne 0x12a42
movq (%r12), %rdi
callq 0x861b
callq 0x128dd
leaq 0x8(%r12), %rbx
cmpb $0x1, 0x10(%r12)
cmovneq %r15, %rbx
jmp 0x12a18
movl 0x25860(%rip), %edi     # 0x382a8
subl %r14d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa04c
movq %rbx, %rsi
addq $0x8, %rsi
cmpb $0x1, %dl
cmovneq %rcx, %rsi
movq (%rsi), %rdx
cmpb $0x1, 0x10(%rdx)
jne 0x12a82
movq (%rdx), %r14
movq 0x8(%rdx), %rdx
cmpb $0x1, 0x10(%rdx)
jmp 0x12a90
movq 0x2bf67(%rip), %rdx     # 0x3e9f0
cmpb $0x1, 0x10(%rdx)
movq %rdx, %r14
movq %rcx, %rsi
jne 0x12a98
movq %rdx, %rsi
movq (%rsi), %r15
movb 0x10(%r15), %dl
cmpb $0x1, %dl
cmoveq %r15, %rcx
cmpq %rax, (%rcx)
je 0x12b10
movq %rbx, %rdi
callq 0x861b
callq 0xd79d
movq %rbx, %rdi
callq 0x861b
callq 0xcd92
callq 0x868d
movq %rax, %rbx
movq %rax, %rdi
callq 0x861b
callq 0xe086
movq 0xf1fef(%rip), %rdi     # 0x104ad0
callq 0x861b
movq %rbx, %rdi
callq 0x861b
callq 0xe75b
callq 0x9fae
callq 0xa1f6
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9fae
addq $0x8, %r15
cmpb $0x1, %dl
leaq 0x2bed2(%rip), %r13     # 0x3e9f0
cmovneq %r13, %r15
movl 0x2577f(%rip), %r12d    # 0x382a8
pushq $0x3
popq %rbx
movq (%r15), %r15
cmpb $0x1, 0x10(%r15)
jne 0x12b7c
movq 0x2e763(%rip), %rdi     # 0x412a0
callq 0x861b
movq %r14, %rdi
callq 0x861b
cmpb $0x1, 0x10(%r15)
movq %r13, %rax
cmoveq %r15, %rax
movq (%rax), %rdi
callq 0x861b
movl %ebx, %edi
callq 0x85eb
callq 0x128dd
cmpb $0x1, 0x10(%r15)
je 0x12b76
movq %r13, %r15
jmp 0x12b2c
addq $0x8, %r15
jmp 0x12b2c
movl 0x25726(%rip), %edi     # 0x382a8
subl %r12d, %edi
jmp 0x12a4b