// File: /workspace/github_c_makefile_star2_O3/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
movb 0x10(%rdi), %al
cmpb $0x1, %al
jne 0x21fbf
movl $0x2, %ecx
movq %r15, %rdx
movq 0x8(%rdx), %rdx
decl %ecx
cmpb $0x1, 0x10(%rdx)
je 0x21fab
testl %ecx, %ecx
je 0x220dd
leaq 0x8(%r15), %r13
cmpb $0x1, %al
leaq 0x23a34(%rip), %rax     # 0x45a00
movq %rax, %rcx
cmoveq %r13, %rcx
movq (%rcx), %rcx
movb 0x10(%rcx), %dl
cmpb $0x1, %dl
movq %rax, %rsi
cmoveq %rcx, %rsi
movq (%rsi), %rbx
cmpb $0x3, 0x10(%rbx)
jne 0x2244d
cmpb $0x1, %dl
jne 0x21ffb
movq 0x8(%rcx), %rcx
jmp 0x22002
movq 0x239fe(%rip), %rcx     # 0x45a00
cmpb $0x1, 0x10(%rcx)
jne 0x2200b
movq %rcx, %rax
movq (%rax), %rdi
callq 0x8ba5
callq 0x96e2
movl 0x1d29a(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x22429
decl %eax
movl %eax, 0x1d282(%rip)     # 0x3f2b8
leaq 0x26583(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %r14
movq %r14, %rdi
callq 0x15ac2
testl %eax, %eax
je 0x22441
movq %r14, %rdi
callq 0x8ba5
callq 0xf8e6
cmpb $0x1, 0x10(%r15)
leaq 0x23996(%rip), %rcx     # 0x45a00
movq %rcx, %rdx
cmoveq %r13, %rdx
movl %eax, %r14d
movq (%rdx), %rax
cmpb $0x1, 0x10(%rax)
jne 0x2208d
movq 0x8(%rax), %rdx
cmpb $0x1, 0x10(%rdx)
jne 0x220b5
movq 0x8(%rdx), %rdx
jmp 0x220bc
movq 0x2396c(%rip), %rax     # 0x45a00
cmpb $0x1, 0x10(%rax)
jne 0x22174
movq 0x8(%rax), %rax
cmpb $0x1, 0x10(%rax)
jne 0x22174
movq 0x2394d(%rip), %rax     # 0x45a00
jmp 0x220ca
movq 0x23944(%rip), %rdx     # 0x45a00
cmpb $0x1, 0x10(%rdx)
jne 0x22174
movq 0x8(%rax), %rax
cmpb $0x1, 0x10(%rax)
jne 0x2216a
addq $0x8, %rax
jmp 0x22171
movq 0x8(%r15), %rax
cmpb $0x1, 0x10(%rax)
leaq 0x23914(%rip), %rcx     # 0x45a00
cmoveq %rax, %rcx
movq (%rcx), %rdi
callq 0x8ba5
callq 0x96e2
movl 0x1d1b5(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x22429
decl %eax
movl %eax, 0x1d19d(%rip)     # 0x3f2b8
leaq 0x2649e(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rbx
cmpb $0x7, 0x10(%rbx)
jne 0x22407
movq (%rbx), %rax
movslq 0x64(%rax), %r14
testq %r14, %r14
jle 0x22154
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x68(%rax,%r15,8), %rdi
callq 0x8ba5
incq %r15
cmpq %r15, %r14
jne 0x2213f
movl %r14d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xadb3
leaq 0x2388f(%rip), %rax     # 0x45a00
movq (%rax), %rcx
movq (%rcx), %rdi
callq 0x8ba5
callq 0x96e2
movl 0x1d131(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x22429
decl %eax
movl %eax, 0x1d119(%rip)     # 0x3f2b8
leaq 0x2641a(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %r12
movq %r12, %rdi
callq 0x15ac2
testl %eax, %eax
je 0x22441
movq %r12, %rdi
callq 0x8ba5
callq 0xf8e6
cmpb $0x1, 0x10(%r15)
leaq 0x2382d(%rip), %rcx     # 0x45a00
cmovneq %rcx, %r13
movl %eax, -0x2c(%rbp)
movq (%r13), %rax
movb 0x10(%rax), %dl
cmpb $0x1, %dl
jne 0x22203
movq 0x8(%rax), %rsi
cmpb $0x1, 0x10(%rsi)
jne 0x22238
movq 0x8(%rsi), %rsi
cmpb $0x1, 0x10(%rsi)
je 0x22245
leaq 0x237ff(%rip), %rsi     # 0x45a00
jmp 0x2225a
movq 0x237f6(%rip), %rsi     # 0x45a00
cmpb $0x1, 0x10(%rsi)
jne 0x2231a
movq 0x8(%rsi), %rsi
cmpb $0x1, 0x10(%rsi)
movq 0x237dd(%rip), %rsi     # 0x45a00
movb 0x10(%rsi), %dil
jne 0x2226e
cmpb $0x1, %dil
je 0x2224f
leaq 0x237ca(%rip), %rsi     # 0x45a00
jmp 0x22253
movq 0x237c1(%rip), %rsi     # 0x45a00
cmpb $0x1, 0x10(%rsi)
jne 0x2229c
movq 0x8(%rax), %rsi
cmpb $0x1, 0x10(%rsi)
jne 0x2222f
addq $0x8, %rsi
movq (%rsi), %rsi
addq $0x8, %rsi
movq (%rsi), %rsi
cmpb $0x1, 0x10(%rsi)
jne 0x2231a
cmpb $0x1, %dl
jne 0x22278
jmp 0x222a9
cmpb $0x1, %dil
jne 0x2231a
movq 0x23781(%rip), %rcx     # 0x45a00
leaq 0x2377a(%rip), %rax     # 0x45a00
cmpb $0x1, 0x10(%rcx)
jne 0x22317
movq 0x8(%rcx), %rcx
cmpb $0x1, 0x10(%rcx)
je 0x222ec
jmp 0x22317
movq 0x2375d(%rip), %rsi     # 0x45a00
cmpb $0x1, 0x10(%rsi)
jne 0x2231a
movq 0x8(%rax), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0x222d6
movq 0x8(%rcx), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0x22310
cmpb $0x1, %dl
jne 0x222ec
movq 0x8(%rax), %rcx
cmpb $0x1, 0x10(%rcx)
jne 0x2241d
addq $0x8, %rax
jmp 0x22300
leaq 0x23723(%rip), %rax     # 0x45a00
movq 0x2371c(%rip), %rcx     # 0x45a00
cmpb $0x1, 0x10(%rcx)
je 0x22307
jmp 0x22317
leaq 0x2370d(%rip), %rax     # 0x45a00
movq 0x23706(%rip), %rcx     # 0x45a00
cmpb $0x1, 0x10(%rcx)
jne 0x22307
movq (%rax), %rax
addq $0x8, %rax
movq (%rax), %rax
addq $0x8, %rax
jmp 0x22317
leaq 0x236e9(%rip), %rax     # 0x45a00
movq (%rax), %rcx
movq (%rcx), %r12
movq %rbx, %rdi
callq 0xf3a6
movl 0x1cf8c(%rip), %r13d    # 0x3f2b8
movl %r14d, %edi
callq 0xb1be
movl 0x1cf7e(%rip), %eax     # 0x3f2b8
leal -0x186a1(%rax), %ecx
cmpl $0xfffe7960, %ecx       # imm = 0xFFFE7960
jb 0x22429
decl %eax
movl %eax, 0x1cf64(%rip)     # 0x3f2b8
cmpb $0x3, 0x10(%rbx)
jne 0x22435
movq 0x2369b(%rip), %rcx     # 0x45a00
movl %eax, %eax
leaq 0x26252(%rip), %rdx     # 0x485c0
movq (%rdx,%rax,8), %rax
movl 0x8(%rbx), %edx
leaq 0xe9774(%rip), %rsi     # 0x10baf0
movq %rax, (%rsi,%rdx,8)
movl 0x8(%rbx), %eax
leaq 0xeebc6(%rip), %rdx     # 0x110f50
movq %rcx, (%rdx,%rax,8)
movq %r12, %rdi
callq 0x8ba5
callq 0x96a4
cmpl -0x2c(%rbp), %r14d
je 0x223cf
setl %r15b
movl 0x1cf0d(%rip), %eax     # 0x3f2b8
subl %r13d, %eax
cmpl $0x3e8, %eax            # imm = 0x3E8
jne 0x223bf
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xadb3
movzbl %r15b, %eax
leal (%r14,%rax,2), %r14d
decl %r14d
jmp 0x2232c
movl 0x1cee3(%rip), %edi     # 0x3f2b8
subl %r13d, %edi
callq 0xadb3
movl 0x1ced5(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x22429
decl %eax
movl %eax, 0x1cec1(%rip)     # 0x3f2b8
leaq 0x261c2(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rbx
callq 0xf40c
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
leaq 0x235dc(%rip), %rax     # 0x45a00
jmp 0x22307
leaq 0xcb11(%rip), %rdi      # 0x2ef41
callq 0x780b
leaq 0xcb5e(%rip), %rdi      # 0x2ef9a
callq 0x780b
leaq 0xc704(%rip), %rdi      # 0x2eb4c
callq 0x780b
leaq 0xc6e2(%rip), %rdi      # 0x2eb36
callq 0x780b