// File: /workspace/github_c_makefile_star2_O1/georgeweigt[P]eigenmath/eigenmath.c
// Function: transpose
void
transpose(int n, int m)
{
	int i, j, k, ndim, nelem;
	int index[MAXDIM];
	struct atom *p1, *p2;

	p1 = pop();

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

	if (n < 1 || n > ndim || m < 1 || m > ndim)
		stopf("transpose: index error");

	n--; // make zero based
	m--;

	p2 = copy_tensor(p1);

	// interchange indices n and m

	p2->u.tensor->dim[n] = p1->u.tensor->dim[m];
	p2->u.tensor->dim[m] = p1->u.tensor->dim[n];

	for (i = 0; i < ndim; i++)
		index[i] = 0;

	for (i = 0; i < nelem; i++) {

		k = 0;

		for (j = 0; j < ndim; j++) {
			if (j == n)
				k = k * p1->u.tensor->dim[m] + index[m];
			else if (j == m)
				k = k * p1->u.tensor->dim[n] + index[n];
			else
				k = k * p1->u.tensor->dim[j] + index[j];
		}

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

		// increment index

		for (j = ndim - 1; j >= 0; j--) {
			if (++index[j] < p1->u.tensor->dim[j])
				break;
			index[j] = 0;
		}
	}

	push(p2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %esi, %r14d
movl %edi, %r15d
callq 0x8b78
testl %r15d, %r15d
jle 0x20a4b
movq %rax, %rbx
movq (%rax), %rax
movl (%rax), %ecx
cmpl %r14d, %ecx
jl 0x20a4b
testl %r14d, %r14d
jle 0x20a4b
cmpl %r15d, %ecx
jl 0x20a4b
movl 0x64(%rax), %eax
movq %rax, -0x40(%rbp)
movslq %r15d, %r15
movslq %r14d, %r13
movq %rbx, %rdi
movq %rcx, -0x30(%rbp)
callq 0x953d
movq (%rbx), %rcx
movl (%rcx,%r13,4), %edx
movq (%rax), %rcx
movl %edx, (%rcx,%r15,4)
movq (%rbx), %rcx
movl (%rcx,%r15,4), %edx
movq %rax, -0x38(%rbp)
movq (%rax), %rcx
movl %edx, (%rcx,%r13,4)
movq -0x30(%rbp), %rcx
testl %ecx, %ecx
jle 0x20925
leaq (,%rcx,4), %rdx
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x7130
movq -0x30(%rbp), %rcx
cmpl $0x0, -0x40(%rbp)
jle 0x20a31
decq %r15
decq %r13
leaq -0xb0(,%r15,4), %rax
addq %rbp, %rax
leaq -0xb0(,%r13,4), %r8
addq %rbp, %r8
movl %r13d, %edx
movl %r15d, %esi
shlq $0x2, %rsi
shlq $0x2, %rdx
leaq (,%rcx,4), %rdi
leaq 0x1(%rcx), %r9
movq %r9, -0x48(%rbp)
xorl %r9d, %r9d
testl %ecx, %ecx
jle 0x209ce
xorl %r11d, %r11d
xorl %r10d, %r10d
cmpq %r11, %rsi
jne 0x2098b
movq (%rbx), %rcx
leaq (%rcx,%r13,4), %r14
addq $0x4, %r14
movq %r8, %rcx
jmp 0x209b3
movq (%rbx), %rcx
cmpq %r11, %rdx
jne 0x209a0
addq $0x4, %rcx
leaq (%rcx,%r15,4), %r14
movq %rax, %rcx
jmp 0x209b3
leaq (%rcx,%r11), %r14
addq $0x4, %r14
leaq (%r11,%rbp), %rcx
addq $-0xb0, %rcx
movslq (%r14), %r14
movslq %r10d, %r12
imulq %r14, %r12
movslq (%rcx), %r10
addq %r12, %r10
addq $0x4, %r11
cmpq %r11, %rdi
jne 0x20976
jmp 0x209d1
xorl %r10d, %r10d
movq (%rbx), %rcx
movq 0x68(%rcx,%r9,8), %rcx
movq -0x38(%rbp), %r11
movq (%r11), %r11
movq %rcx, 0x68(%r11,%r10,8)
cmpl $0x0, -0x30(%rbp)
jle 0x20a20
movq (%rbx), %r10
movq -0x48(%rbp), %r11
movl -0xb8(%rbp,%r11,4), %ecx
incl %ecx
movl %ecx, -0xb8(%rbp,%r11,4)
cmpl -0x4(%r10,%r11,4), %ecx
jl 0x20a20
movl $0x0, -0xb8(%rbp,%r11,4)
decq %r11
cmpq $0x1, %r11
jg 0x209f2
incq %r9
cmpq -0x40(%rbp), %r9
movq -0x30(%rbp), %rcx
jne 0x2096c
movq -0x38(%rbp), %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
leaq 0xa12a(%rip), %rdi      # 0x2ab7c
callq 0x77c8