// File: /workspace/github_c_makefile_star2_O0/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
subq $0x90, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
callq 0x91d0
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movl 0x64(%rax), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0x4(%rbp)
jl 0x35fc8
movl -0x4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x35fc8
cmpl $0x1, -0x8(%rbp)
jl 0x35fc8
movl -0x8(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x35fd4
leaq 0x13b7d(%rip), %rdi     # 0x49b4c
callq 0x78d0
movl -0x4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x88(%rbp), %rdi
callq 0xa550
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movslq -0x8(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq -0x90(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,4)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
movq -0x90(%rbp), %rax
movq (%rax), %rax
movslq -0x8(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,4)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x36067
movslq -0xc(%rbp), %rax
movl $0x0, -0x80(%rbp,%rax,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x36048
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3619e
movl $0x0, -0x14(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3611d
movl -0x10(%rbp), %eax
cmpl -0x4(%rbp), %eax
jne 0x360bf
movl -0x14(%rbp), %eax
movq -0x88(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x8(%rbp), %rdx
imull 0x4(%rcx,%rdx,4), %eax
movslq -0x8(%rbp), %rcx
addl -0x80(%rbp,%rcx,4), %eax
movl %eax, -0x14(%rbp)
jmp 0x3610d
movl -0x10(%rbp), %eax
cmpl -0x8(%rbp), %eax
jne 0x360ea
movl -0x14(%rbp), %eax
movq -0x88(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x4(%rbp), %rdx
imull 0x4(%rcx,%rdx,4), %eax
movslq -0x4(%rbp), %rcx
addl -0x80(%rbp,%rcx,4), %eax
movl %eax, -0x14(%rbp)
jmp 0x3610b
movl -0x14(%rbp), %eax
movq -0x88(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x10(%rbp), %rdx
imull 0x4(%rcx,%rdx,4), %eax
movslq -0x10(%rbp), %rcx
addl -0x80(%rbp,%rcx,4), %eax
movl %eax, -0x14(%rbp)
jmp 0x3610d
jmp 0x3610f
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x36088
movq -0x88(%rbp), %rax
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movq 0x68(%rax,%rcx,8), %rdx
movq -0x90(%rbp), %rax
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, 0x68(%rax,%rcx,8)
movl -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jl 0x3618e
movslq -0x10(%rbp), %rcx
movl -0x80(%rbp,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp,%rcx,4)
movq -0x88(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x10(%rbp), %rdx
cmpl 0x4(%rcx,%rdx,4), %eax
jge 0x36177
jmp 0x3618e
movslq -0x10(%rbp), %rax
movl $0x0, -0x80(%rbp,%rax,4)
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x3614c
jmp 0x36190
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3606e
movq -0x90(%rbp), %rdi
callq 0x9110
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)