// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
callq 0x8b78
movq %rax, %rbx
movzbl 0x10(%rax), %edx
movq %rax, %rcx
cmpl $0x1, %edx
je 0x14618
cmpl $0x7, %edx
jne 0x14611
movq %rbx, %rdi
callq 0x953d
movq %rax, %rbx
movq (%rax), %rax
movslq 0x64(%rax), %r14
testq %r14, %r14
jle 0x1464e
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x68(%rax,%r15,8), %rdi
callq 0x8b01
callq 0x145aa
callq 0x8b78
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r15,8)
incq %r15
cmpq %r15, %r14
jne 0x145e8
jmp 0x1464e
leaq 0x2c3e8(%rip), %rcx     # 0x40a00
movq 0x2ec81(%rip), %rax     # 0x432a0
cmpq %rax, (%rcx)
je 0x1465e
cmpb $0x1, %dl
leaq 0x2c3d2(%rip), %rcx     # 0x40a00
movq %rcx, %rsi
cmoveq %rbx, %rsi
movq (%rsi), %rsi
cmpq 0x2ec69(%rip), %rsi     # 0x432a8
je 0x146b4
cmpq 0x2ec68(%rip), %rsi     # 0x432b0
je 0x146f8
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
addq $0x8, %rbx
cmpb $0x1, %dl
leaq 0x2c394(%rip), %r15     # 0x40a00
cmovneq %r15, %rbx
movl 0x25c41(%rip), %r14d    # 0x3a2b8
movq (%rbx), %rbx
cmpb $0x1, 0x10(%rbx)
jne 0x1469e
movq (%rbx), %rdi
callq 0x8b01
callq 0x145aa
leaq 0x8(%rbx), %rax
cmpb $0x1, 0x10(%rbx)
cmovneq %r15, %rax
movq (%rax), %rbx
jmp 0x1467a
movl 0x25c14(%rip), %edi     # 0x3a2b8
subl %r14d, %edi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa975
addq $0x8, %rbx
cmpb $0x1, %dl
leaq 0x2c33e(%rip), %r15     # 0x40a00
cmovneq %r15, %rbx
movl 0x25beb(%rip), %r14d    # 0x3a2b8
movq (%rbx), %rbx
cmpb $0x1, 0x10(%rbx)
jne 0x14833
movq (%rbx), %rdi
callq 0x8b01
callq 0x145aa
leaq 0x8(%rbx), %rax
cmpb $0x1, 0x10(%rbx)
cmovneq %r15, %rax
movq (%rax), %rbx
jmp 0x146d0
movq %rbx, %rsi
addq $0x8, %rsi
cmpb $0x1, %dl
cmovneq %rcx, %rsi
movq (%rsi), %rdx
movb 0x10(%rdx), %dil
leaq 0x8(%rdx), %rsi
cmpb $0x1, %dil
cmovneq %rcx, %rdx
movq %rcx, %r8
cmoveq %rsi, %r8
movq (%r8), %r8
cmpb $0x1, 0x10(%r8)
movq %rcx, %r8
jne 0x1473f
cmpb $0x1, %dil
leaq 0x2c2c8(%rip), %rdi     # 0x40a00
cmoveq %rsi, %rdi
movq (%rdi), %r8
movq (%r8), %rsi
movb 0x10(%rsi), %dil
cmpb $0x1, %dil
cmoveq %rsi, %rcx
cmpq %rax, (%rcx)
je 0x147b9
movq %rbx, %rdi
callq 0x8b01
callq 0xe8e3
movq %rbx, %rdi
callq 0x8b01
callq 0xddb0
callq 0x8b78
movq %rax, %rbx
movq %rax, %rdi
callq 0x8b01
callq 0xf2ab
movq 0xf2357(%rip), %rdi     # 0x106ae0
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
callq 0xfade
movl $0x2, %edi
callq 0xa8bb
movl $0x2, %edi
callq 0xa975
movl $0x2, %edi
jmp 0x1483c
addq $0x8, %rsi
cmpb $0x1, %dil
leaq 0x2c238(%rip), %r15     # 0x40a00
cmovneq %r15, %rsi
movl 0x25ae5(%rip), %r14d    # 0x3a2b8
movq (%rsi), %r12
cmpb $0x1, 0x10(%r12)
jne 0x14833
movq (%rdx), %rbx
movq 0x2eac8(%rip), %rdi     # 0x432b0
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
cmpb $0x1, 0x10(%r12)
movq %r15, %rax
cmoveq %r12, %rax
movq (%rax), %rdi
callq 0x8b01
movl $0x3, %edi
callq 0x8ad9
callq 0x145aa
leaq 0x8(%r12), %rax
cmpb $0x1, 0x10(%r12)
cmovneq %r15, %rax
movq (%rax), %r12
cmpb $0x1, 0x10(%r12)
je 0x147e1
movl 0x25a7f(%rip), %edi     # 0x3a2b8
subl %r14d, %edi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa8bb