// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %rbx
movq (%rdi), %rcx
movl (%rcx), %edi
movslq 0x290f3(%rip), %rax     # 0x3f2b8
movl %eax, %r8d
subl %esi, %r8d
movl %edi, %edx
subl %r8d, %edx
movl %edx, -0x2c(%rbp)
js 0x16374
movl %edi, -0x40(%rbp)
movq %rax, -0x38(%rbp)
movl %esi, -0x44(%rbp)
movslq %esi, %rax
testl %r8d, %r8d
movq %rax, -0x50(%rbp)
movl %r8d, -0x3c(%rbp)
jle 0x1626d
movl %r8d, %r14d
leaq (,%rax,8), %r13
xorl %r15d, %r15d
xorl %r12d, %r12d
leaq (,%r15,8), %rax
addq %r13, %rax
leaq 0x323aa(%rip), %rcx     # 0x485c0
movq (%rcx,%rax), %rdi
callq 0x8ba5
callq 0xf8e6
testl %eax, %eax
jle 0x16234
movq (%rbx), %rcx
movl 0x4(%rcx,%r15,4), %edx
cmpl %edx, %eax
jle 0x16258
cmpl $0x0, 0x100189(%rip)    # 0x1163c4
je 0x16374
movl $0x1, 0x100175(%rip)    # 0x1163c0
movq (%rbx), %rcx
movl 0x4(%rcx,%r15,4), %edx
movl $0x1, %eax
imull %r12d, %edx
leal (%rax,%rdx), %r12d
decl %r12d
incq %r15
cmpq %r15, %r14
jne 0x16204
jmp 0x16270
xorl %r12d, %r12d
movl -0x44(%rbp), %eax
movl %eax, 0x2903f(%rip)     # 0x3f2b8
movl -0x3c(%rbp), %eax
cmpl %eax, -0x40(%rbp)
jne 0x1628e
movslq %r12d, %rax
movq 0x68(%rcx,%rax,8), %rdi
jmp 0x16361
jle 0x162dc
movq -0x38(%rbp), %rax
leaq (,%rax,4), %rax
movq -0x50(%rbp), %r15
leaq (,%r15,4), %rdx
subq %rdx, %rax
addq %rcx, %rax
addq $0x4, %rax
movl -0x2c(%rbp), %ecx
movl $0x1, %r14d
xorl %edx, %edx
imull (%rax,%rdx,4), %r14d
incq %rdx
cmpl %edx, %ecx
jne 0x162bd
movl %r14d, %edi
callq 0x7893
testl %r14d, %r14d
movq -0x38(%rbp), %r9
jg 0x162f4
jmp 0x16322
movl $0x1, %r14d
movl $0x1, %edi
callq 0x7893
movq -0x38(%rbp), %r9
movq -0x50(%rbp), %r15
imull %r14d, %r12d
movslq %r12d, %rdx
movl %r14d, %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 0x16308
movq (%rax), %rcx
movl -0x2c(%rbp), %edx
movl %edx, (%rcx)
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
shlq $0x2, %r9
shlq $0x2, %r15
subq %r15, %r9
addq $0x4, %r9
xorl %edx, %edx
movq (%rbx), %rsi
addq %r9, %rsi
movl (%rsi,%rdx,4), %esi
movq (%rax), %rdi
movl %esi, 0x4(%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x16346
movq %rax, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
leaq 0x1882c(%rip), %rdi     # 0x2eba7
callq 0x780b