// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: kronecker
void
kronecker(void)
{
	int h, i, j, k, l, m, n, p, q;
	struct atom *p1, *p2, *p3;

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

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

	if (p1->u.tensor->ndim > 2 || p2->u.tensor->ndim > 2)
		stopf("kronecker");

	m = p1->u.tensor->dim[0];
	n = p1->u.tensor->ndim == 1 ? 1 : p1->u.tensor->dim[1];

	p = p2->u.tensor->dim[0];
	q = p2->u.tensor->ndim == 1 ? 1 : p2->u.tensor->dim[1];

	p3 = alloc_tensor(m * n * p * q);

	// result matrix has (m * p) rows and (n * q) columns

	h = 0;

	for (i = 0; i < m; i++)
		for (j = 0; j < p; j++)
			for (k = 0; k < n; k++)
				for (l = 0; l < q; l++) {
					push(p1->u.tensor->elem[n * i + k]);
					push(p2->u.tensor->elem[q * j + l]);
					multiply();
					p3->u.tensor->elem[h++] = pop();
				}

	// dim info

	p3->u.tensor->ndim = n * q == 1 ? 1 : 2;

	p3->u.tensor->dim[0] = m * p;

	if (n * q > 1)
		p3->u.tensor->dim[1] = n * q;

	push(p3);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
callq 0x868d
movq %rax, %rbx
callq 0x868d
movq %rax, -0x38(%rbp)
cmpb $0x7, 0x10(%rax)
jne 0x15265
cmpb $0x7, 0x10(%rbx)
jne 0x15265
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movl (%rcx), %esi
cmpl $0x2, %esi
jg 0x152c6
movq (%rbx), %rax
movl (%rax), %edx
cmpl $0x3, %edx
jge 0x152c6
movq %rbx, -0xa0(%rbp)
pushq $0x1
popq %r14
movl %r14d, %ebx
cmpl $0x1, %esi
je 0x150f9
movl 0x8(%rcx), %ebx
movl 0x4(%rcx), %ecx
movl 0x4(%rax), %esi
cmpl $0x1, %edx
je 0x15108
movl 0x8(%rax), %r14d
movq %rsi, %r12
movl %r12d, %edi
movq %rcx, %r15
imull %r15d, %edi
movl %ebx, %eax
imull %r14d, %eax
movl %edi, -0x3c(%rbp)
movl %eax, -0x40(%rbp)
imull %eax, %edi
callq 0x77da
movq %rax, -0x50(%rbp)
xorl %eax, %eax
testl %r14d, %r14d
movl $0x0, %r13d
cmovgl %r14d, %r13d
testl %ebx, %ebx
movl $0x0, %ecx
cmovgl %ebx, %ecx
movq %rcx, -0x90(%rbp)
movslq %r14d, %rcx
testl %r12d, %r12d
cmovlel %eax, %r12d
movq %r12, -0x70(%rbp)
movslq %ebx, %rax
movq %rax, -0x58(%rbp)
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
movq %r15, -0x60(%rbp)
negq %r13
shlq $0x3, %rcx
movq %rcx, -0x68(%rbp)
xorl %edx, %edx
cmpq -0x60(%rbp), %rax
je 0x15289
movq %rax, %rcx
imulq -0x58(%rbp), %rcx
movq %rcx, -0x78(%rbp)
pushq $0x68
popq %rcx
movq %rcx, -0x30(%rbp)
xorl %esi, %esi
movq %rax, -0x80(%rbp)
cmpq -0x70(%rbp), %rsi
je 0x1525d
xorl %ecx, %ecx
movq %rsi, -0x88(%rbp)
cmpq -0x90(%rbp), %rcx
je 0x15249
movq -0x78(%rbp), %rax
movq %rcx, -0x98(%rbp)
leaq (%rcx,%rax), %r12
movl %edx, -0x44(%rbp)
movslq %edx, %rbx
addq $0xd, %rbx
movq -0x30(%rbp), %r15
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x15229
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x861b
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r15), %rdi
callq 0x861b
callq 0x9fae
callq 0x868d
movq -0x50(%rbp), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx,%rbx,8)
decq %r14
incq %rbx
addq $0x8, %r15
jmp 0x151df
movl -0x44(%rbp), %edx
subl %r14d, %edx
movq -0x98(%rbp), %rcx
incq %rcx
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rsi
jmp 0x151b2
incq %rsi
movq -0x30(%rbp), %rcx
addq -0x68(%rbp), %rcx
movq %rcx, -0x30(%rbp)
jmp 0x1519f
incq %rax
jmp 0x1517c
movq -0x38(%rbp), %rdi
callq 0x861b
movq %rbx, %rdi
callq 0x861b
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9fae
xorl %eax, %eax
movl -0x40(%rbp), %edx
cmpl $0x1, %edx
setne %al
incl %eax
movq -0x50(%rbp), %rdi
movq (%rdi), %rcx
movl %eax, (%rcx)
movq (%rdi), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, 0x4(%rax)
cmpl $0x2, %edx
jl 0x152b3
movq (%rdi), %rax
movl %edx, 0x8(%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
leaq 0x125ea(%rip), %rdi     # 0x278b7
callq 0x7756