// File: /workspace/github_c_makefile_star2_O3/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
movl 0x350d5(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0xa50f
leal -0x1(%rax), %ecx
movl %ecx, 0x350bc(%rip)     # 0x3f2b8
cmpl $0x1, %eax
jbe 0xa50f
leaq 0x3e3b4(%rip), %rdx     # 0x485c0
movq (%rdx,%rcx,8), %r14
addl $-0x2, %eax
movl %eax, 0x3509f(%rip)     # 0x3f2b8
movq (%rdx,%rax,8), %rbx
cmpb $0x7, 0x10(%rbx)
movb 0x10(%r14), %al
jne 0xa242
cmpb $0x7, %al
movq %r14, %rax
cmoveq %rbx, %rax
cmovneq %rbx, %r14
cmpb $0x7, 0x10(%rax)
movq %rax, %rbx
jne 0xa24a
jmp 0xa2ce
cmpb $0x7, %al
jne 0xa493
cmpb $0x7, 0x10(%r14)
jne 0xa2ce
movq %r14, %rdi
callq 0x9638
movq %rax, %r14
movq (%rax), %rax
movslq 0x64(%rax), %r15
testq %r15, %r15
jle 0xa2c6
xorl %r12d, %r12d
movl $0xfffe795f, %r13d      # imm = 0xFFFE795F
movq %rbx, %rdi
callq 0x8ba5
movq (%r14), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl 0x35022(%rip), %eax     # 0x3f2b8
leal (%rax,%r13), %ecx
cmpl %r13d, %ecx
jbe 0xa50f
decl %eax
movl %eax, 0x3500d(%rip)     # 0x3f2b8
leaq 0x3e30e(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rax
movq (%r14), %rcx
movq %rax, 0x68(%rcx,%r12,8)
incq %r12
cmpq %r12, %r15
jne 0xa271
movq %r14, %rdi
jmp 0xa4fc
movq (%rbx), %rax
movslq (%rax), %rdx
movl (%rax,%rdx,4), %esi
movq (%r14), %rcx
movq %rsi, -0x30(%rbp)
cmpl 0x4(%rcx), %esi
jne 0xa51b
movq %r14, -0x50(%rbp)
movq %rbx, -0x58(%rbp)
movl (%rcx), %esi
movq %rdx, -0x70(%rbp)
movq %rsi, -0x68(%rbp)
addl %esi, %edx
cmpl $0x1b, %edx
jge 0xa527
movl 0x64(%rax), %eax
cltd
movq -0x30(%rbp), %rsi
idivl %esi
movl %eax, %ebx
movl 0x64(%rcx), %eax
cltd
idivl %esi
movl %eax, -0x34(%rbp)
movl %eax, %edi
imull %ebx, %edi
callq 0x7893
testl %ebx, %ebx
jle 0xa44c
movl -0x34(%rbp), %r12d
movl %ebx, %edx
movq %rdx, -0x78(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq %rax, -0x88(%rbp)
movq -0x58(%rbp), %r13
cmpl $0x0, -0x34(%rbp)
jle 0xa42c
movl -0x48(%rbp), %edx
addq $0xd, %rdx
movq %rdx, -0x80(%rbp)
movq -0x40(%rbp), %rdx
imulq %r12, %rdx
movq %rdx, -0x90(%rbp)
movl $0xd, %edx
movq %rdx, -0x60(%rbp)
xorl %edi, %edi
movq %rdi, -0x98(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0xa3ca
movq -0x30(%rbp), %r15
movq -0x80(%rbp), %rbx
movq -0x60(%rbp), %r14
movq (%r13), %rax
movq (%rax,%rbx,8), %rdi
callq 0x8ba5
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r14,8), %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
addq %r12, %r14
incq %rbx
decq %r15
jne 0xa398
movq -0x30(%rbp), %rdi
callq 0xadb3
movl 0x34edf(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %edx       # imm = 0xFFFE795F
leal (%rax,%rdx), %ecx
cmpl %edx, %ecx
movq -0x98(%rbp), %rdi
jbe 0xa50f
decl %eax
movl %eax, 0x34ec0(%rip)     # 0x3f2b8
leaq 0x3e1c1(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rsi
movq -0x88(%rbp), %rax
movq (%rax), %rcx
movq -0x90(%rbp), %rdx
addq %rdi, %rdx
movq %rsi, 0x68(%rcx,%rdx,8)
incq %rdi
incq -0x60(%rbp)
cmpq %r12, %rdi
jne 0xa37f
movq -0x40(%rbp), %rsi
incq %rsi
movq -0x48(%rbp), %rdx
addl -0x30(%rbp), %edx
movq %rdx, -0x48(%rbp)
movq %rsi, -0x40(%rbp)
cmpq -0x78(%rbp), %rsi
jne 0xa350
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %rdx
addl %ecx, %edx
addl $-0x2, %edx
movq (%rax), %rcx
testl %edx, %edx
je 0xa4bb
movl %edx, (%rcx)
movq -0x58(%rbp), %rdi
movq (%rdi), %rcx
movl (%rcx), %ecx
cmpl $0x2, %ecx
jl 0xa4c1
decl %ecx
movl %ecx, %r9d
xorl %ecx, %ecx
movq -0x50(%rbp), %r8
movq (%rdi), %rdx
movl 0x4(%rdx,%rcx,4), %edx
movq (%rax), %rsi
movl %edx, 0x4(%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %r9
jne 0xa47b
jmp 0xa4c8
movq %rbx, %rdi
callq 0x8ba5
movq %r14, %rdi
callq 0x8ba5
movl $0x2, %edi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xacef
movq 0x68(%rcx), %rdi
jmp 0xa4fc
xorl %r9d, %r9d
movq -0x50(%rbp), %r8
movq (%r8), %rcx
movslq (%rcx), %rcx
cmpq $0x2, %rcx
jl 0xa4f9
leaq 0x4(,%r9,4), %r9
decq %rcx
xorl %edx, %edx
movq (%r8), %rsi
movl 0x8(%rsi,%rdx,4), %esi
movq (%rax), %rdi
addq %r9, %rdi
movl %esi, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0xa4e1
movq %rax, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
leaq 0x24a2b(%rip), %rdi     # 0x2ef41
callq 0x780b
leaq 0x1fecb(%rip), %rdi     # 0x2a3ed
callq 0x780b
leaq 0x1fed4(%rip), %rdi     # 0x2a402
callq 0x780b