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

	// sum over tensor elements?

	if (lengthf(p1) == 2) {
		push(cadr(p1));
		evalf();
		p1 = pop();
		if (!istensor(p1)) {
			push(p1);
			return;
		}
		n = p1->u.tensor->nelem;
		for (i = 0; i < n; i++)
			push(p1->u.tensor->elem[i]);
		add_terms(n);
		return;
	}

	p2 = cadr(p1);
	if (!isusersymbol(p2))
		stopf("sum: index symbol err");

	push(caddr(p1));
	evalf();
	p3 = pop();
	if (!issmallinteger(p3))
		stopf("sum: index range err");
	push(p3);
	j = pop_integer();

	push(cadddr(p1));
	evalf();
	p3 = pop();
	if (!issmallinteger(p3))
		stopf("sum: index range err");
	push(p3);
	k = pop_integer();

	p1 = caddddr(p1);

	save_symbol(p2);

	h = tos;

	for (;;) {
		push_integer(j);
		p3 = pop();
		set_symbol(p2, p3, symbol(NIL));
		push(p1);
		evalg();
		if (j == k)
			break;
		if (j < k)
			j++;
		else
			j--;
		if (tos - h == 1000)
			add_terms(1000); // to prevent stack overflow
	}

	add_terms(tos - h);

	p1 = pop();
	restore_symbol();
	push(p1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
callq 0x86c3
leaq 0x8(%r15), %r13
cmpb $0x1, 0x10(%r15)
leaq 0x2279d(%rip), %rcx     # 0x3e9f0
movq %rcx, %rdx
cmoveq %r13, %rdx
movq (%rdx), %rdx
movb 0x10(%rdx), %sil
cmpb $0x1, %sil
movq %rcx, %rdi
cmoveq %rdx, %rdi
movq (%rdi), %rbx
cmpl $0x2, %eax
jne 0x1c2c1
movq %rbx, %rdi
callq 0x861b
callq 0x8fbb
callq 0x868d
movq %rax, %rbx
cmpb $0x7, 0x10(%rax)
jne 0x1c5b1
movq (%rbx), %rax
movl 0x64(%rax), %r14d
xorl %r15d, %r15d
testl %r14d, %r14d
movl $0x0, %r12d
cmovgl %r14d, %r12d
cmpq %r15, %r12
je 0x1c2d7
movq (%rbx), %rax
movq 0x68(%rax,%r15,8), %rdi
callq 0x861b
incq %r15
jmp 0x1c2aa
cmpb $0x3, 0x10(%rbx)
jne 0x1c5df
cmpb $0x1, %sil
jne 0x1c2ed
movq 0x8(%rdx), %rax
jmp 0x1c2f4
movl %r14d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0fd
movq 0x226fc(%rip), %rax     # 0x3e9f0
cmpb $0x1, 0x10(%rax)
jne 0x1c2fd
movq %rax, %rcx
movq (%rcx), %rdi
callq 0x861b
callq 0x8fbb
callq 0x868d
movq %rax, %r14
movq %rax, %rdi
callq 0x126ab
testl %eax, %eax
je 0x1c5d3
movq %r14, %rdi
callq 0x861b
callq 0xd9d9
cmpb $0x1, 0x10(%r15)
leaq 0x226b5(%rip), %rcx     # 0x3e9f0
movq %rcx, %rdx
cmoveq %r13, %rdx
movl %eax, %r14d
movq (%rdx), %rax
cmpb $0x1, 0x10(%rax)
jne 0x1c35e
movq 0x8(%rax), %rdx
cmpb $0x1, 0x10(%rdx)
jne 0x1c37e
movq 0x8(%rdx), %rdx
jmp 0x1c385
movq 0x2268b(%rip), %rax     # 0x3e9f0
cmpb $0x1, 0x10(%rax)
jne 0x1c3a5
movq 0x8(%rax), %rax
cmpb $0x1, 0x10(%rax)
jne 0x1c3a5
movq 0x22674(%rip), %rax     # 0x3e9f0
jmp 0x1c38f
movq 0x2266b(%rip), %rdx     # 0x3e9f0
cmpb $0x1, 0x10(%rdx)
jne 0x1c3a5
movq 0x8(%rax), %rax
cmpb $0x1, 0x10(%rax)
jne 0x1c39b
addq $0x8, %rax
jmp 0x1c3a2
leaq 0x2264e(%rip), %rax     # 0x3e9f0
movq (%rax), %rcx
movq (%rcx), %rdi
callq 0x861b
callq 0x8fbb
callq 0x868d
movq %rax, %r12
movq %rax, %rdi
callq 0x126ab
testl %eax, %eax
je 0x1c5d3
movq %r12, %rdi
callq 0x861b
callq 0xd9d9
cmpb $0x1, 0x10(%r15)
leaq 0x2260d(%rip), %rcx     # 0x3e9f0
cmovneq %rcx, %r13
movl %eax, %r15d
movq (%r13), %rax
movb 0x10(%rax), %dl
cmpb $0x1, %dl
jne 0x1c413
movq 0x8(%rax), %rsi
cmpb $0x1, 0x10(%rsi)
jne 0x1c448
movq 0x8(%rsi), %rsi
cmpb $0x1, 0x10(%rsi)
je 0x1c455
leaq 0x225df(%rip), %rsi     # 0x3e9f0
jmp 0x1c46a
movq 0x225d6(%rip), %rsi     # 0x3e9f0
cmpb $0x1, 0x10(%rsi)
jne 0x1c52a
movq 0x8(%rsi), %rsi
cmpb $0x1, 0x10(%rsi)
movq 0x225bd(%rip), %rsi     # 0x3e9f0
movb 0x10(%rsi), %dil
jne 0x1c47e
cmpb $0x1, %dil
je 0x1c45f
leaq 0x225aa(%rip), %rsi     # 0x3e9f0
jmp 0x1c463
movq 0x225a1(%rip), %rsi     # 0x3e9f0
cmpb $0x1, 0x10(%rsi)
jne 0x1c4ac
movq 0x8(%rax), %rsi
cmpb $0x1, 0x10(%rsi)
jne 0x1c43f
addq $0x8, %rsi
movq (%rsi), %rsi
addq $0x8, %rsi
movq (%rsi), %rsi
cmpb $0x1, 0x10(%rsi)
jne 0x1c52a
cmpb $0x1, %dl
jne 0x1c488
jmp 0x1c4b9
cmpb $0x1, %dil
jne 0x1c52a
movq 0x22561(%rip), %rcx     # 0x3e9f0
leaq 0x2255a(%rip), %rax     # 0x3e9f0
cmpb $0x1, 0x10(%rcx)
jne 0x1c527
movq 0x8(%rcx), %rcx
cmpb $0x1, 0x10(%rcx)
je 0x1c4fc
jmp 0x1c527
movq 0x2253d(%rip), %rsi     # 0x3e9f0
cmpb $0x1, 0x10(%rsi)
jne 0x1c52a
movq 0x8(%rax), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0x1c4e6
movq 0x8(%rcx), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0x1c520
cmpb $0x1, %dl
jne 0x1c4fc
movq 0x8(%rax), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0x1c5c7
addq $0x8, %rax
jmp 0x1c510
leaq 0x22503(%rip), %rax     # 0x3e9f0
movq 0x224fc(%rip), %rcx     # 0x3e9f0
cmpb $0x1, 0x10(%rcx)
je 0x1c517
jmp 0x1c527
leaq 0x224ed(%rip), %rax     # 0x3e9f0
movq 0x224e6(%rip), %rcx     # 0x3e9f0
cmpb $0x1, 0x10(%rcx)
jne 0x1c517
movq (%rax), %rax
addq $0x8, %rax
movq (%rax), %rax
addq $0x8, %rax
jmp 0x1c527
leaq 0x224c9(%rip), %rax     # 0x3e9f0
movq (%rax), %rcx
movq (%rcx), %r12
movq %rbx, %rdi
callq 0xd63f
movl 0x1bd6c(%rip), %r13d    # 0x382a8
movl %r14d, %edi
callq 0xa426
callq 0x868d
movq 0x224a0(%rip), %rdx     # 0x3e9f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x12721
movq %r12, %rdi
callq 0x861b
callq 0x8f7d
cmpl %r15d, %r14d
je 0x1c596
setl %al
movzbl %al, %eax
leal (%r14,%rax,2), %r14d
decl %r14d
movl 0x1bd28(%rip), %eax     # 0x382a8
subl %r13d, %eax
cmpl $0x3e8, %eax            # imm = 0x3E8
jne 0x1c53c
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xa0fd
jmp 0x1c53c
movl 0x1bd0c(%rip), %edi     # 0x382a8
subl %r13d, %edi
callq 0xa0fd
callq 0x868d
movq %rax, %rbx
callq 0xd684
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
leaq 0x22422(%rip), %rax     # 0x3e9f0
jmp 0x1c517
leaq 0xb5aa(%rip), %rdi      # 0x27b84
callq 0x7756
leaq 0xb588(%rip), %rdi      # 0x27b6e
callq 0x7756