// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
callq 0x8b78
movq %rax, %rbx
callq 0x8b78
movq %rax, %rdi
cmpb $0x7, 0x10(%rax)
jne 0x173b3
cmpb $0x7, 0x10(%rbx)
jne 0x173b3
movq (%rdi), %rax
cmpl $0x2, (%rax)
jg 0x173db
movq (%rbx), %rax
cmpl $0x3, (%rax)
jge 0x173db
movq (%rdi), %rax
movl 0x4(%rax), %ecx
movq %rcx, -0x40(%rbp)
movl $0x1, %r14d
cmpl $0x1, (%rax)
movl $0x1, -0x2c(%rbp)
je 0x171f1
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movq %rdi, -0x70(%rbp)
movq %rbx, -0xa0(%rbp)
movq (%rbx), %rax
movl 0x4(%rax), %ecx
movq %rcx, -0x38(%rbp)
cmpl $0x1, (%rax)
je 0x1720f
movl 0x8(%rax), %r14d
movq -0x38(%rbp), %rax
movl %eax, %edi
movq -0x40(%rbp), %rbx
imull %ebx, %edi
movl -0x2c(%rbp), %eax
imull %r14d, %eax
movl %eax, -0x54(%rbp)
imull %eax, %edi
callq 0x7850
movq %rax, %r15
testl %ebx, %ebx
jle 0x1736f
movl -0x2c(%rbp), %eax
movq %rax, -0x88(%rbp)
movl %r14d, %eax
movq %rax, -0x68(%rbp)
movq $0x0, -0x48(%rbp)
xorl %edx, %edx
movl %r14d, -0x58(%rbp)
movq -0x70(%rbp), %r13
cmpl $0x0, -0x38(%rbp)
jle 0x1735a
movl -0x2c(%rbp), %eax
imull -0x48(%rbp), %eax
movq %rax, -0x78(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x1733a
movl -0x50(%rbp), %eax
addq $0xd, %rax
movq %rax, -0x80(%rbp)
xorl %ecx, %ecx
testl %r14d, %r14d
jle 0x1732a
movq -0x78(%rbp), %rax
movq %rcx, -0x90(%rbp)
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movslq %edx, %rdx
leaq 0xd(%rdx), %r12
addl %r14d, %edx
movq %rdx, -0x98(%rbp)
movq -0x68(%rbp), %rbx
movq -0x80(%rbp), %r14
movq (%r13), %rax
movq -0xa8(%rbp), %rcx
movq 0x68(%rax,%rcx,8), %rdi
callq 0x8b01
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r14,8), %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
callq 0x8b78
movq (%r15), %rcx
movq %rax, (%rcx,%r12,8)
incq %r14
incq %r12
decq %rbx
jne 0x172cf
movl -0x58(%rbp), %r14d
movq -0x98(%rbp), %rdx
movq -0x90(%rbp), %rcx
incq %rcx
cmpq -0x88(%rbp), %rcx
jne 0x17298
movq -0x60(%rbp), %rcx
incq %rcx
movq -0x50(%rbp), %rax
addl %r14d, %eax
movq %rax, -0x50(%rbp)
movq %rcx, -0x60(%rbp)
cmpq -0x38(%rbp), %rcx
jne 0x17281
movq -0x48(%rbp), %rcx
incq %rcx
movq %rcx, -0x48(%rbp)
cmpq -0x40(%rbp), %rcx
jne 0x1725c
xorl %eax, %eax
movl -0x54(%rbp), %edx
cmpl $0x1, %edx
setne %al
incl %eax
movq (%r15), %rcx
movl %eax, (%rcx)
movq -0x40(%rbp), %rcx
imull -0x38(%rbp), %ecx
movq (%r15), %rax
movl %ecx, 0x4(%rax)
cmpl $0x2, %edx
jl 0x1739a
movq (%r15), %rax
movl %edx, 0x8(%rax)
movq %r15, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
movl $0x2, %edi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa8bb
leaq 0x1347d(%rip), %rdi     # 0x2a85f
callq 0x77c8