// File: /workspace/github_c_makefile_star2_O1/georgeweigt[P]eigenmath/eigenmath.c
// Function: indexfunc
void
indexfunc(struct atom *T, int h)
{
	int i, k, m, n, r, t, w;
	struct atom *p1;

	m = T->u.tensor->ndim;

	n = tos - h;

	r = m - n; // rank of result

	if (r < 0)
		stopf("index error");

	k = 0;

	for (i = 0; i < n; i++) {
		push(stack[h + i]);
		t = pop_integer();
		if (t < 1 || t > T->u.tensor->dim[i]) {
			if (shuntflag) {
				errorflag = 1;
				t = 1;
			} else
				stopf("index error");
		}
		k = k * T->u.tensor->dim[i] + t - 1;
	}

	tos = h; // pop all

	if (r == 0) {
		push(T->u.tensor->elem[k]); // scalar result
		return;
	}

	w = 1;

	for (i = n; i < m; i++)
		w *= T->u.tensor->dim[i];

	k *= w;

	p1 = alloc_tensor(w);

	for (i = 0; i < w; i++)
		p1->u.tensor->elem[i] = T->u.tensor->elem[k + i];

	p1->u.tensor->ndim = r;

	for (i = 0; i < r; i++)
		p1->u.tensor->dim[i] = T->u.tensor->dim[n + i];

	push(p1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq (%rdi), %rax
movl (%rax), %edx
movslq 0x2596d(%rip), %rax     # 0x3a2b8
movl %eax, %edi
subl %esi, %edi
movl %edx, %ecx
subl %edi, %ecx
js 0x14ad6
movl %edx, -0x34(%rbp)
movl %ecx, -0x2c(%rbp)
movq %rax, -0x40(%rbp)
testl %edi, %edi
movl %esi, -0x38(%rbp)
movl %edi, -0x30(%rbp)
jle 0x149d9
movslq %esi, %r15
movl %edi, %r14d
shlq $0x3, %r15
xorl %r12d, %r12d
xorl %r13d, %r13d
leaq (%r15,%r12,8), %rax
leaq 0x2ec38(%rip), %rcx     # 0x435c0
movq (%rcx,%rax), %rdi
callq 0x8b01
callq 0xeb5b
testl %eax, %eax
jle 0x149a4
movq (%rbx), %rcx
cmpl 0x4(%rcx,%r12,4), %eax
jle 0x149c0
cmpl $0x0, 0xfca19(%rip)     # 0x1113c4
je 0x14ad6
movl $0x1, 0xfca05(%rip)     # 0x1113c0
movl $0x1, %eax
movq (%rbx), %rcx
imull 0x4(%rcx,%r12,4), %r13d
addl %eax, %r13d
decl %r13d
incq %r12
cmpq %r12, %r14
jne 0x1497d
jmp 0x149dc
xorl %r13d, %r13d
movl -0x38(%rbp), %r14d
movl %r14d, 0x258d1(%rip)    # 0x3a2b8
movl -0x34(%rbp), %r12d
movl -0x30(%rbp), %eax
cmpl %eax, %r12d
jne 0x14a03
movq (%rbx), %rax
movslq %r13d, %rcx
movq 0x68(%rax,%rcx,8), %rdi
jmp 0x14ac3
movl $0x1, %r15d
jle 0x14a3c
movq (%rbx), %rax
movq -0x40(%rbp), %rcx
leaq (,%rcx,4), %rcx
movslq %r14d, %rdx
shlq $0x2, %rdx
subq %rdx, %rcx
addq %rcx, %rax
addq $0x4, %rax
movl -0x2c(%rbp), %ecx
xorl %edx, %edx
imull (%rax,%rdx,4), %r15d
incq %rdx
cmpl %edx, %ecx
jne 0x14a30
movl %r15d, %edi
callq 0x7850
testl %r15d, %r15d
jle 0x14a77
imull %r15d, %r13d
movslq %r13d, %rdx
movl %r15d, %ecx
leaq 0x68(,%rdx,8), %rdx
xorl %esi, %esi
movq (%rbx), %rdi
addq %rdx, %rdi
movq (%rdi,%rsi,8), %rdi
movq (%rax), %r8
movq %rdi, 0x68(%r8,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x14a5d
movq (%rax), %rcx
movl -0x2c(%rbp), %edx
movl %edx, (%rcx)
cmpl -0x30(%rbp), %r12d
movq -0x40(%rbp), %r8
je 0x14ac0
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
shlq $0x2, %r8
movslq %r14d, %rdx
shlq $0x2, %rdx
subq %rdx, %r8
addq $0x4, %r8
xorl %edx, %edx
movq (%rbx), %rsi
addq %r8, %rsi
movl (%rsi,%rdx,4), %esi
movq (%rax), %rdi
movl %esi, 0x4(%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x14aa8
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
leaq 0x160aa(%rip), %rdi     # 0x2ab87
callq 0x77c8