// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: inner
void
inner(void)
{
	int i, j, k, n, mcol, mrow, ncol, ndim, nrow;
	struct atom *p1, *p2, *p3;

	p2 = pop();
	p1 = pop();

	if (!istensor(p1) && !istensor(p2)) {
		push(p1);
		push(p2);
		multiply();
		return;
	}

	if (istensor(p1) && !istensor(p2)) {
		p3 = p1;
		p1 = p2;
		p2 = p3;
	}

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

	k = p1->u.tensor->ndim - 1;

	ncol = p1->u.tensor->dim[k];
	mrow = p2->u.tensor->dim[0];

	if (ncol != mrow)
		stopf("inner: dimension err");

	ndim = p1->u.tensor->ndim + p2->u.tensor->ndim - 2;

	if (ndim > MAXDIM)
		stopf("inner: rank exceeds max");

	//	nrow is the number of rows in p1
	//
	//	mcol is the number of columns p2
	//
	//	Example:
	//
	//	A[3][3][4] B[4][4][3]
	//
	//	  3  3				nrow = 3 * 3 = 9
	//
	//	                4  3		mcol = 4 * 3 = 12

	nrow = p1->u.tensor->nelem / ncol;
	mcol = p2->u.tensor->nelem / mrow;

	p3 = alloc_tensor(nrow * mcol);

	for (i = 0; i < nrow; i++) {
		for (j = 0; j < mcol; j++) {
			for (k = 0; k < ncol; k++) {
				push(p1->u.tensor->elem[i * ncol + k]);
				push(p2->u.tensor->elem[k * mcol + j]);
				multiply();
			}
			add_terms(ncol);
			p3->u.tensor->elem[i * mcol + j] = pop();
		}
	}

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

	// dim info

	p3->u.tensor->ndim = ndim;

	k = 0;

	n = p1->u.tensor->ndim - 1;

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

	n = p2->u.tensor->ndim;

	for (i = 1; i < n; i++)
		p3->u.tensor->dim[k++] = p2->u.tensor->dim[i];

	push(p3);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
callq 0x868d
movq %rax, %r14
callq 0x868d
movq %rax, %rbx
cmpb $0x7, 0x10(%rax)
movb 0x10(%r14), %al
jne 0x97c3
cmpb $0x7, %al
movq %r14, %rax
cmoveq %rbx, %rax
cmovneq %rbx, %r14
cmpb $0x7, 0x10(%rax)
movq %rax, %rbx
jne 0x97cb
jmp 0x9823
cmpb $0x7, %al
jne 0x99f0
cmpb $0x7, 0x10(%r14)
jne 0x9823
movq %r14, %rdi
callq 0x8f1b
movq %rax, %r14
movq (%rax), %rax
movl 0x64(%rax), %r15d
xorl %r12d, %r12d
testl %r15d, %r15d
cmovlel %r12d, %r15d
cmpq %r12, %r15
je 0x9a13
movq %rbx, %rdi
callq 0x861b
movq (%r14), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x861b
callq 0x9fae
callq 0x868d
movq (%r14), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
jmp 0x97ee
movq (%rbx), %rax
movslq (%rax), %rdx
movslq (%rax,%rdx,4), %rsi
movq (%r14), %rcx
movq %rsi, -0x48(%rbp)
cmpl 0x4(%rcx), %esi
jne 0x9a2f
movq %r14, -0x50(%rbp)
movl (%rcx), %esi
leal (%rsi,%rdx), %edi
cmpl $0x1b, %edi
jge 0x9a3b
movq %rbx, %r14
addl %esi, %edx
addl $-0x2, %edx
movl %edx, -0x3c(%rbp)
movl 0x64(%rax), %eax
cltd
movq -0x48(%rbp), %rbx
idivl %ebx
movl %eax, %r12d
movl 0x64(%rcx), %eax
cltd
idivl %ebx
movl %eax, %r15d
movl %eax, %edi
imull %r12d, %edi
callq 0x77da
movslq %r15d, %r13
xorl %ecx, %ecx
testl %ebx, %ebx
movl $0x0, %edx
cmovgl %ebx, %edx
movq %rdx, -0x68(%rbp)
testl %r13d, %r13d
movl $0x0, %edx
cmovgl %r13d, %edx
movq %rdx, -0x80(%rbp)
movq %rax, -0x30(%rbp)
testl %r12d, %r12d
cmovlel %ecx, %r12d
movq %r12, -0x60(%rbp)
shlq $0x3, %rbx
movq %rbx, -0x58(%rbp)
pushq $0x68
popq %rax
movq %rax, -0x38(%rbp)
cmpq -0x60(%rbp), %rcx
je 0x9979
movq %rcx, %rax
imulq %r13, %rax
movq %rax, -0x70(%rbp)
pushq $0xd
popq %r15
xorl %esi, %esi
movq %rcx, -0x78(%rbp)
cmpq -0x80(%rbp), %rsi
je 0x9969
movq %rsi, -0x88(%rbp)
movq %r15, -0x90(%rbp)
movq -0x38(%rbp), %r12
movq -0x68(%rbp), %rbx
subq $0x1, %rbx
jb 0x992b
movq (%r14), %rax
movq (%rax,%r12), %rdi
callq 0x861b
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r15,8), %rdi
callq 0x861b
callq 0x9fae
addq $0x8, %r12
addq %r13, %r15
jmp 0x98fb
movq -0x48(%rbp), %rdi
callq 0xa0fd
callq 0x868d
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq -0x70(%rbp), %rdx
movq -0x88(%rbp), %rsi
addq %rsi, %rdx
movq %rax, 0x68(%rcx,%rdx,8)
incq %rsi
movq -0x90(%rbp), %r15
incq %r15
movq -0x78(%rbp), %rcx
jmp 0x98db
incq %rcx
movq -0x38(%rbp), %rax
addq -0x58(%rbp), %rax
jmp 0x98b8
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl -0x3c(%rbp), %ecx
testl %ecx, %ecx
je 0x9a18
movl %ecx, (%rax)
movq (%r14), %rax
movl (%rax), %ecx
cmpl $0x2, %ecx
pushq $0x1
popq %rax
cmovgel %ecx, %eax
decl %eax
xorl %ecx, %ecx
movq -0x50(%rbp), %r8
cmpq %rcx, %rax
je 0x99bf
movq (%r14), %rdx
movl 0x4(%rdx,%rcx,4), %edx
movq -0x30(%rbp), %rsi
movq (%rsi), %rsi
movl %edx, 0x4(%rsi,%rcx,4)
incq %rcx
jmp 0x99a3
movq (%r8), %rcx
movslq (%rcx), %rcx
shlq $0x2, %rax
pushq $0x1
popq %rdx
cmpq %rcx, %rdx
jge 0x99ea
movq (%r8), %rsi
movl 0x4(%rsi,%rdx,4), %esi
movq -0x30(%rbp), %rdi
movq (%rdi), %rdi
addq %rax, %rdi
movl %esi, (%rdi,%rdx,4)
incq %rdx
jmp 0x99cc
movq -0x30(%rbp), %rdi
jmp 0x9a1c
movq %rbx, %rdi
callq 0x861b
movq %r14, %rdi
callq 0x861b
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9fae
movq %r14, %rdi
jmp 0x9a1c
movq 0x68(%rax), %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
leaq 0x199ef(%rip), %rdi     # 0x23425
callq 0x7756
leaq 0x199f8(%rip), %rdi     # 0x2343a
callq 0x7756