// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
callq 0x8b78
movq %rax, %rbx
callq 0x8b78
movq %rax, %r12
movb 0x10(%rax), %al
cmpb $0x7, %al
jne 0xa14e
cmpb $0x7, 0x10(%rbx)
movq %rbx, %rax
cmoveq %r12, %rax
cmovneq %r12, %rbx
movq %rax, %r12
cmpb $0x7, 0x10(%r12)
je 0x9f95
cmpb $0x7, 0x10(%rbx)
jne 0x9f95
movq %rbx, %rdi
callq 0x953d
movq %rax, %rbx
movq (%rax), %rax
movslq 0x64(%rax), %r15
testq %r15, %r15
jle 0x9f8d
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x68(%rax,%r14,8), %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
movq (%rbx), %rcx
movq %rax, 0x68(%rcx,%r14,8)
incq %r14
cmpq %r14, %r15
jne 0x9f59
movq %rbx, %rdi
jmp 0xa1c9
movq (%r12), %rax
movslq (%rax), %rcx
movl (%rax,%rcx,4), %r14d
movq (%rbx), %rax
movl 0x4(%rax), %ecx
cmpl %ecx, %r14d
jne 0xa1dc
movq (%r12), %rax
movl (%rax), %eax
movq (%rbx), %rdx
movl (%rdx), %edx
leal (%rdx,%rax), %esi
cmpl $0x1b, %esi
jge 0xa1e8
addl %edx, %eax
addl $-0x2, %eax
movl %eax, -0x4c(%rbp)
movq %r12, -0x58(%rbp)
movq (%r12), %rax
movl 0x64(%rax), %eax
cltd
idivl %r14d
movl %eax, %r15d
movq %rbx, -0x48(%rbp)
movq (%rbx), %rax
movl 0x64(%rax), %eax
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movl %eax, %edi
imull %r15d, %edi
callq 0x7850
movq %rax, %r9
testl %r15d, %r15d
jle 0xa114
movl -0x2c(%rbp), %eax
movl %r15d, %ecx
movq %rcx, -0x78(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq %r9, -0x88(%rbp)
movq %r14, -0x60(%rbp)
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %r12
movq -0x58(%rbp), %r13
cmpl $0x0, -0x2c(%rbp)
jle 0xa0f4
movl -0x40(%rbp), %ecx
addq $0xd, %rcx
movq %rcx, -0x80(%rbp)
movq -0x38(%rbp), %rcx
imulq %rax, %rcx
movq %rcx, -0x90(%rbp)
movl $0xd, %ecx
movq %rcx, -0x68(%rbp)
xorl %esi, %esi
movq %rsi, -0x98(%rbp)
testl %r14d, %r14d
jle 0xa0af
movq -0x60(%rbp), %rbx
movq -0x80(%rbp), %r14
movq -0x68(%rbp), %r15
movq (%r13), %rax
movq (%rax,%r14,8), %rdi
callq 0x8b01
movq (%r12), %rax
movq (%rax,%r15,8), %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
addq -0x70(%rbp), %r15
incq %r14
decq %rbx
jne 0xa07f
movq -0x60(%rbp), %r14
movl %r14d, %edi
callq 0xa975
callq 0x8b78
movq -0x88(%rbp), %r9
movq (%r9), %rcx
movq -0x90(%rbp), %rdx
movq -0x98(%rbp), %rsi
addq %rsi, %rdx
movq %rax, 0x68(%rcx,%rdx,8)
incq %rsi
incq -0x68(%rbp)
movq -0x70(%rbp), %rax
cmpq %rax, %rsi
jne 0xa067
movq -0x38(%rbp), %rdx
incq %rdx
movq -0x40(%rbp), %rcx
addl %r14d, %ecx
movq %rcx, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
cmpq -0x78(%rbp), %rdx
jne 0xa038
movq (%r9), %rax
movl -0x4c(%rbp), %ecx
testl %ecx, %ecx
je 0xa189
movl %ecx, (%rax)
movq -0x58(%rbp), %rdi
movq (%rdi), %rax
movl (%rax), %ecx
cmpl $0x2, %ecx
jl 0xa18f
decl %ecx
xorl %eax, %eax
movq -0x48(%rbp), %r8
movq (%rdi), %rdx
movl 0x4(%rdx,%rax,4), %edx
movq (%r9), %rsi
movl %edx, 0x4(%rsi,%rax,4)
incq %rax
cmpq %rax, %rcx
jne 0xa136
jmp 0xa195
cmpb $0x7, 0x10(%rbx)
jne 0xa161
cmpb $0x7, %al
je 0x9f1f
jmp 0x9f31
movq %r12, %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa8bb
movq 0x68(%rax), %rdi
jmp 0xa1c9
xorl %eax, %eax
movq -0x48(%rbp), %r8
movq (%r8), %rcx
movslq (%rcx), %rcx
cmpq $0x2, %rcx
jl 0xa1c6
leaq 0x4(,%rax,4), %rax
decq %rcx
xorl %edx, %edx
movq (%r8), %rsi
movl 0x8(%rsi,%rdx,4), %esi
movq (%r9), %rdi
addq %rax, %rdi
movl %esi, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0xa1ae
movq %r9, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
leaq 0x1c1ea(%rip), %rdi     # 0x263cd
callq 0x77c8
leaq 0x1c1f3(%rip), %rdi     # 0x263e2
callq 0x77c8