// File: /workspace/github_c_makefile_star2_O3/georgeweigt[P]eigenmath/eigenmath.c
// Function: asubst
void
asubst(void)
{
	int h, i, n;
	struct atom *p1, *p2, *p3;

	p3 = pop(); // new expr
	p2 = pop(); // old expr
	p1 = pop(); // expr

	if (p2 == symbol(NIL) || p3 == symbol(NIL)) {
		push(p1);
		return;
	}

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

	if (equal(p1, p2)) {
		push(p3);
		return;
	}

	if (!iscons(p1)) {
		push(p1);
		return;
	}

	// depth first

	h = tos;

	push(car(p1)); // func name
	p1 = cdr(p1);

	while (iscons(p1)) {
		push(car(p1));
		push(p2);
		push(p3);
		asubst();
		p1 = cdr(p1);
	}

	list(tos - h);

	evalf(); // normalize

	p1 = pop();

	if (addcmp(p1, p2)) {
		push(p1);
		push(p2);
		subtract();
		push(p3);
		add();
		return;
	}

	if (mulcmp(p1, p2) || powcmp(p1, p2)) {
		push(p1);
		push(p2);
		divide();
		push(p3);
		multiply();
		return;
	}

	push(p1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x2b464(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x140b2
leal -0x1(%rax), %ecx
movl %ecx, 0x2b44b(%rip)     # 0x3f2b8
cmpl $0x1, %eax
jbe 0x140b2
leaq 0x34743(%rip), %rdx     # 0x485c0
movq (%rdx,%rcx,8), %r12
leal -0x2(%rax), %ecx
movl %ecx, 0x2b42e(%rip)     # 0x3f2b8
cmpl $0x2, %eax
je 0x140b2
movq (%rdx,%rcx,8), %r14
addl $-0x3, %eax
movl %eax, 0x2b418(%rip)     # 0x3f2b8
movq (%rdx,%rax,8), %r15
movq 0x31b55(%rip), %rax     # 0x45a00
cmpq %rax, %r14
sete %cl
cmpq %rax, %r12
sete %al
orb %cl, %al
cmpb $0x1, %al
je 0x1409c
cmpb $0x7, 0x10(%r15)
jne 0x13f52
movq %r14, -0x30(%rbp)
movq %r12, %r14
movq %r15, %rdi
callq 0x9638
movq %rax, %r15
movq (%rax), %rax
movslq 0x64(%rax), %r13
testq %r13, %r13
jle 0x1409c
xorl %r12d, %r12d
movl $0xfffe795f, %ebx       # imm = 0xFFFE795F
movq (%r15), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x8ba5
movq -0x30(%rbp), %rdi
callq 0x8ba5
movq %r14, %rdi
callq 0x8ba5
callq 0x13e40
movl 0x2b399(%rip), %eax     # 0x3f2b8
leal (%rax,%rbx), %ecx
cmpl %ebx, %ecx
jbe 0x140b2
decl %eax
movl %eax, 0x2b386(%rip)     # 0x3f2b8
leaq 0x34687(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rax
movq (%r15), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
cmpq %r12, %r13
jne 0x13ef6
jmp 0x1409c
movq %r15, %rdi
movq %r14, %rsi
callq 0x8d48
testl %eax, %eax
je 0x13fc1
cmpb $0x1, 0x10(%r15)
jne 0x1409c
movl 0x2b345(%rip), %r13d    # 0x3f2b8
movq (%r15), %rdi
callq 0x8ba5
cmpb $0x1, 0x10(%r15)
leaq 0x8(%r15), %rax
leaq 0x31a75(%rip), %rbx     # 0x45a00
cmovneq %rbx, %rax
movq (%rax), %r15
cmpb $0x1, 0x10(%r15)
jne 0x13fc9
movq (%r15), %rdi
callq 0x8ba5
movq %r14, %rdi
callq 0x8ba5
movq %r12, %rdi
callq 0x8ba5
callq 0x13e40
leaq 0x8(%r15), %rax
cmpb $0x1, 0x10(%r15)
jmp 0x13f8b
movq %r12, %rdi
jmp 0x1409f
movl 0x2b2e9(%rip), %edi     # 0x3f2b8
subl %r13d, %edi
callq 0x8b7d
callq 0x96e2
movl 0x2b2d6(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x140b2
decl %eax
movl %eax, 0x2b2be(%rip)     # 0x3f2b8
leaq 0x345bf(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x140be
testl %eax, %eax
je 0x14049
movq %r15, %rdi
callq 0x8ba5
movq %r14, %rdi
callq 0x8ba5
callq 0xbfb4
movq %r12, %rdi
callq 0x8ba5
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xadb3
movq %r15, %rdi
movq %r14, %rsi
callq 0x1417c
testl %eax, %eax
jne 0x14067
movq %r15, %rdi
movq %r14, %rsi
callq 0x14265
testl %eax, %eax
je 0x1409c
movq %r15, %rdi
callq 0x8ba5
movq %r14, %rdi
callq 0x8ba5
callq 0xe218
movq %r12, %rdi
callq 0x8ba5
movl $0x2, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xacef
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
leaq 0x1ae88(%rip), %rdi     # 0x2ef41
callq 0x780b