// File: /workspace/github_c_makefile_star2_O0/georgeweigt[P]eigenmath/eigenmath.c
// Function: promote_tensor
void
promote_tensor(void)
{
	int i, j, k, ndim1, ndim2, nelem1, nelem2;
	struct atom *p1, *p2, *p3;

	p1 = pop();

	if (!istensor(p1)) {
		push(p1);
		return;
	}

	ndim1 = p1->u.tensor->ndim;
	nelem1 = p1->u.tensor->nelem;

	// check

	p2 = p1->u.tensor->elem[0];

	for (i = 1; i < nelem1; i++) {
		p3 = p1->u.tensor->elem[i];
		if (!compatible_dimensions(p2, p3))
			stopf("tensor dimensions");
	}

	if (!istensor(p2)) {
		push(p1);
		return; // all elements are scalars
	}

	ndim2 = p2->u.tensor->ndim;
	nelem2 = p2->u.tensor->nelem;

	if (ndim1 + ndim2 > MAXDIM)
		stopf("rank exceeds max");

	// alloc

	p3 = alloc_tensor(nelem1 * nelem2);

	// merge dimensions

	k = 0;

	for (i = 0; i < ndim1; i++)
		p3->u.tensor->dim[k++] = p1->u.tensor->dim[i];

	for (i = 0; i < ndim2; i++)
		p3->u.tensor->dim[k++] = p2->u.tensor->dim[i];

	p3->u.tensor->ndim = ndim1 + ndim2;

	// merge elements

	k = 0;

	for (i = 0; i < nelem1; i++) {
		p2 = p1->u.tensor->elem[i];
		for (j = 0; j < nelem2; j++)
			p3->u.tensor->elem[k++] = p2->u.tensor->elem[j];
	}

	push(p3);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
callq 0x91d0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7, %eax
je 0x351bc
movq -0x28(%rbp), %rdi
callq 0x9110
jmp 0x353ab
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x68(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x35232
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movq 0x68(%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xccb0
cmpl $0x0, %eax
jne 0x35225
leaq 0x10051(%rip), %rdi     # 0x45271
callq 0x78d0
jmp 0x35227
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x351eb
movq -0x30(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x7, %eax
je 0x3524d
movq -0x28(%rbp), %rdi
callq 0x9110
jmp 0x353ab
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x10(%rbp), %eax
addl -0x14(%rbp), %eax
cmpl $0x18, %eax
jle 0x3527d
leaq 0x10141(%rip), %rdi     # 0x453b9
callq 0x78d0
movl -0x18(%rbp), %edi
imull -0x1c(%rbp), %edi
callq 0x79b0
movq %rax, -0x38(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x352d6
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq -0x38(%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 0x3529b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x35318
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq -0x38(%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 0x352dd
movl -0x10(%rbp), %ecx
addl -0x14(%rbp), %ecx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl %ecx, (%rax)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x353a2
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movq 0x68(%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x35395
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x8(%rbp), %rcx
movq 0x68(%rax,%rcx,8), %rdx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl -0xc(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0xc(%rbp)
movslq %ecx, %rcx
movq %rdx, 0x68(%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x35358
jmp 0x35397
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x35335
movq -0x38(%rbp), %rdi
callq 0x9110
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)