// File: /workspace/github_c_makefile_star2_O3/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
movl 0x26634(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x18ef5
leal -0x1(%rax), %ecx
movl %ecx, 0x2661b(%rip)     # 0x3f2b8
cmpl $0x1, %eax
jbe 0x18ef5
leaq 0x2f913(%rip), %rdx     # 0x485c0
movq (%rdx,%rcx,8), %rbx
addl $-0x2, %eax
movl %eax, 0x265fe(%rip)     # 0x3f2b8
movq (%rdx,%rax,8), %rax
movq %rax, -0x40(%rbp)
cmpb $0x7, 0x10(%rax)
jne 0x18ecc
cmpb $0x7, 0x10(%rbx)
jne 0x18ecc
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movl (%rcx), %esi
cmpl $0x2, %esi
jg 0x18f01
movq (%rbx), %rax
movl (%rax), %edx
cmpl $0x3, %edx
jge 0x18f01
movl 0x4(%rcx), %edi
movq %rdi, -0x50(%rbp)
movl $0x1, -0x30(%rbp)
movl $0x1, -0x2c(%rbp)
cmpl $0x1, %esi
je 0x18d16
movl 0x8(%rcx), %ecx
movl %ecx, -0x2c(%rbp)
movq %rbx, -0x98(%rbp)
movl 0x4(%rax), %ecx
movq %rcx, -0x38(%rbp)
cmpl $0x1, %edx
je 0x18d2f
movl 0x8(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movl %eax, %edi
movq -0x50(%rbp), %rbx
imull %ebx, %edi
movl -0x2c(%rbp), %eax
imull -0x30(%rbp), %eax
movl %edi, -0x44(%rbp)
movl %eax, -0x48(%rbp)
imull %eax, %edi
callq 0x7893
movq %rax, %rdi
testl %ebx, %ebx
jle 0x18e93
movl -0x2c(%rbp), %eax
movq %rax, -0x88(%rbp)
movl -0x30(%rbp), %eax
movq %rax, -0x70(%rbp)
xorl %ecx, %ecx
xorl %r12d, %r12d
cmpl $0x0, -0x38(%rbp)
movq %rcx, -0x58(%rbp)
jle 0x18e82
movl -0x2c(%rbp), %eax
imull %ecx, %eax
movq %rax, -0x78(%rbp)
xorl %eax, %eax
xorl %ecx, %ecx
movq %rcx, -0x60(%rbp)
cmpl $0x0, -0x2c(%rbp)
movq %rax, -0x68(%rbp)
jle 0x18e6a
movl %eax, %eax
addq $0xd, %rax
movq %rax, -0x80(%rbp)
xorl %ecx, %ecx
cmpl $0x0, -0x30(%rbp)
movq %rcx, -0x90(%rbp)
jle 0x18e53
movq -0x78(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movslq %r12d, %r14
addq $0xd, %r14
movq -0x70(%rbp), %r15
movq -0x80(%rbp), %r13
movq %rdi, %rbx
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq -0xa0(%rbp), %rcx
movq 0x68(%rax,%rcx,8), %rdi
callq 0x8ba5
movq -0x98(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movl 0x264a0(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %edx       # imm = 0xFFFE795F
leal (%rax,%rdx), %ecx
cmpl %edx, %ecx
jbe 0x18ef5
decl %eax
movl %eax, 0x26488(%rip)     # 0x3f2b8
leaq 0x2f789(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rax
movq %rbx, %rdi
movq (%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r13
incq %r14
incl %r12d
decq %r15
jne 0x18dda
movq -0x90(%rbp), %rcx
incq %rcx
cmpq -0x88(%rbp), %rcx
jne 0x18dac
movq -0x60(%rbp), %rcx
incq %rcx
movq -0x68(%rbp), %rax
addl -0x30(%rbp), %eax
cmpq -0x38(%rbp), %rcx
jne 0x18d8e
movq -0x58(%rbp), %rcx
incq %rcx
cmpq -0x50(%rbp), %rcx
jne 0x18d72
xorl %eax, %eax
movl -0x48(%rbp), %edx
cmpl $0x1, %edx
setne %al
incl %eax
movq (%rdi), %rcx
movl %eax, (%rcx)
movq (%rdi), %rax
movl -0x44(%rbp), %ecx
movl %ecx, 0x4(%rax)
cmpl $0x2, %edx
jl 0x18eb9
movq (%rdi), %rax
movl %edx, 0x8(%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
movq -0x40(%rbp), %rdi
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
movl $0x2, %edi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xacef
leaq 0x16045(%rip), %rdi     # 0x2ef41
callq 0x780b
leaq 0x15977(%rip), %rdi     # 0x2e87f
callq 0x780b