// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
callq 0x91d0
movq %rax, -0x38(%rbp)
callq 0x91d0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7, %eax
je 0xb530
movq -0x38(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7, %eax
je 0xb530
movq -0x30(%rbp), %rdi
callq 0x9110
movq -0x38(%rbp), %rdi
callq 0x9110
callq 0xc280
jmp 0xb839
movq -0x30(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7, %eax
jne 0xb562
movq -0x38(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7, %eax
je 0xb562
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7, %eax
je 0xb5fd
movq -0x38(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7, %eax
jne 0xb5fd
movq -0x38(%rbp), %rdi
callq 0xa550
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0xb5ef
movq -0x30(%rbp), %rdi
callq 0x9110
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movq 0x68(%rax,%rcx,8), %rdi
callq 0x9110
callq 0xc280
callq 0x91d0
movq %rax, %rdx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movq %rdx, 0x68(%rax,%rcx,8)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xb5a1
movq -0x38(%rbp), %rdi
callq 0x9110
jmp 0xb839
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0xb63f
leaq 0x39d63(%rip), %rdi     # 0x4539d
callq 0x78d0
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
addl (%rcx), %eax
subl $0x2, %eax
movl %eax, -0x20(%rbp)
cmpl $0x18, -0x20(%rbp)
jle 0xb669
leaq 0x39d4e(%rip), %rdi     # 0x453b2
callq 0x78d0
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
cltd
idivl -0x1c(%rbp)
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
cltd
idivl -0x18(%rbp)
movl %eax, -0x14(%rbp)
movl -0x24(%rbp), %edi
imull -0x14(%rbp), %edi
callq 0x79b0
movq %rax, -0x40(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xb763
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xb753
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xb71c
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl -0x4(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0xc(%rbp), %ecx
movslq %ecx, %rcx
movq 0x68(%rax,%rcx,8), %rdi
callq 0x9110
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl -0xc(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x8(%rbp), %ecx
movslq %ecx, %rcx
movq 0x68(%rax,%rcx,8), %rdi
callq 0x9110
callq 0xc280
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xb6c8
movl -0x1c(%rbp), %edi
callq 0xc520
callq 0x91d0
movq %rax, %rdx
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x4(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x8(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, 0x68(%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xb6b5
jmp 0xb755
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xb6a2
cmpl $0x0, -0x20(%rbp)
jne 0xb77e
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq 0x68(%rax), %rdi
callq 0x9110
jmp 0xb839
movl -0x20(%rbp), %ecx
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl %ecx, (%rax)
movl $0x0, -0xc(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0xb7e2
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0xc(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0xc(%rbp)
movslq %ecx, %rcx
movl %edx, 0x4(%rax,%rcx,4)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xb7a7
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0xb830
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0xc(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0xc(%rbp)
movslq %ecx, %rcx
movl %edx, 0x4(%rax,%rcx,4)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xb7f5
movq -0x40(%rbp), %rdi
callq 0x9110
addq $0x40, %rsp
popq %rbp
retq
nop