// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: eval_eigenvec
void
eval_eigenvec(struct atom *p1)
{
	int i, j, n;
	static double *D, *Q;

	push(cadr(p1));
	evalf();
	floatfunc();
	p1 = pop();

	if (!issquarematrix(p1))
		stopf("eigenvec");

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

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (!isdouble(p1->u.tensor->elem[n * i + j]))
				stopf("eigenvec");

	for (i = 0; i < n - 1; i++)
		for (j = i + 1; j < n; j++)
			if (fabs(p1->u.tensor->elem[n * i + j]->u.d - p1->u.tensor->elem[n * j + i]->u.d) > 1e-10)
				stopf("eigenvec");

	if (D)
		free(D);
	if (Q)
		free(Q);

	D = alloc_mem(n * n * sizeof (double));
	Q = alloc_mem(n * n * sizeof (double));

	// initialize D

	for (i = 0; i < n; i++) {
		D[n * i + i] = p1->u.tensor->elem[n * i + i]->u.d;
		for (j = i + 1; j < n; j++) {
			D[n * i + j] = p1->u.tensor->elem[n * i + j]->u.d;
			D[n * j + i] = p1->u.tensor->elem[n * i + j]->u.d;
		}
	}

	// initialize Q

	for (i = 0; i < n; i++) {
		Q[n * i + i] = 1.0;
		for (j = i + 1; j < n; j++) {
			Q[n * i + j] = 0.0;
			Q[n * j + i] = 0.0;
		}
	}

	eigenvec(D, Q, n);

	p1 = alloc_matrix(n, n);

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			push_double(Q[n * j + i]); // transpose
			p1->u.tensor->elem[n * i + j] = pop();
		}
	}

	push(p1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpb $0x1, 0x10(%rdi)
leaq 0x8(%rdi), %rax
leaq 0x2e186(%rip), %rcx     # 0x3e9f0
cmovneq %rcx, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmoveq %rax, %rcx
movq (%rcx), %rdi
callq 0x861b
callq 0x8fbb
callq 0x9fbd
callq 0x868d
movq %rax, %r14
movq %rax, %rdi
callq 0xb291
testl %eax, %eax
je 0x10b1e
movq (%r14), %rax
movl 0x4(%rax), %r15d
movslq %r15d, %r12
xorl %ecx, %ecx
testl %r12d, %r12d
movl $0x0, %r13d
cmovgl %r15d, %r13d
leaq 0x68(%rax), %rdx
leaq (,%r12,8), %rsi
movq %rsi, -0x30(%rbp)
cmpq %r13, %rcx
je 0x108f3
xorl %esi, %esi
cmpq %rsi, %r15
je 0x108ea
movq (%rdx,%rsi,8), %rdi
incq %rsi
cmpb $0x5, 0x10(%rdi)
je 0x108d3
jmp 0x10b1e
incq %rcx
addq -0x30(%rbp), %rdx
jmp 0x108cc
cmpl $0x2, %r15d
pushq $0x1
popq %rcx
movl %ecx, %edx
cmovgel %r15d, %edx
decl %edx
leaq 0x8(,%r12,8), %rsi
leaq (%rax,%r12,8), %rdi
addq $0x68, %rdi
addq $0x70, %rax
xorl %r8d, %r8d
movapd 0x127ff(%rip), %xmm0    # 0x23120
movsd 0x1283f(%rip), %xmm1    # 0x23168
cmpq %rdx, %r8
je 0x10971
movslq %ecx, %r9
incq %r8
movq %rdi, %r10
movq %rax, %r11
cmpq %r12, %r9
jge 0x10967
movq (%r11), %rbx
movsd (%rbx), %xmm2
movq (%r10), %rbx
subsd (%rbx), %xmm2
andpd %xmm0, %xmm2
incq %r9
addq $0x8, %r11
addq -0x30(%rbp), %r10
ucomisd %xmm1, %xmm2
jbe 0x1093a
jmp 0x10b1e
incl %ecx
addq %rsi, %rax
addq %rsi, %rdi
jmp 0x10929
movq 0xfea28(%rip), %rdi     # 0x10f3a0
callq 0x7040
movq 0xfea24(%rip), %rdi     # 0x10f3a8
callq 0x7040
movl %r15d, %ebx
imull %r15d, %ebx
shll $0x3, %ebx
movl %ebx, %edi
callq 0x779c
movq %rax, 0xfe9ff(%rip)     # 0x10f3a0
movl %ebx, %edi
callq 0x779c
movq %rax, 0xfe9f9(%rip)     # 0x10f3a8
pushq $0x1
popq %rcx
xorl %edx, %edx
movq 0xfe9e5(%rip), %rdi     # 0x10f3a0
xorl %esi, %esi
cmpq %r13, %rsi
je 0x10a30
movslq %ecx, %r8
movq %r12, %r9
subq %r8, %r9
leaq (%rdx,%r8), %r10
imulq %r12, %r8
addq %rsi, %r8
movq (%r14), %r11
movq %rsi, %rbx
imulq %r12, %rbx
addq %rsi, %rbx
movq 0x68(%r11,%rbx,8), %r11
movsd (%r11), %xmm0
movsd %xmm0, (%rdi,%rbx,8)
subq $0x1, %r9
jb 0x10a26
movq (%r14), %r11
movq 0x68(%r11,%r10,8), %r11
movsd (%r11), %xmm0
movsd %xmm0, (%rdi,%r10,8)
movq (%r14), %r11
movq 0x68(%r11,%r10,8), %r11
movsd (%r11), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r10
addq %r12, %r8
jmp 0x109f2
incq %rsi
incl %ecx
addq %r12, %rdx
jmp 0x109bd
pushq $0x1
popq %rcx
xorl %edx, %edx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
movq %rax, %r8
movq %rax, %r9
cmpq %r13, %rdx
je 0x10a8d
movslq %ecx, %r10
movq -0x30(%rbp), %r11
imulq %r10, %r11
addq %r8, %r11
movq %rdx, %rbx
imulq %r12, %rbx
leaq (%rax,%rbx,8), %rbx
movq %rsi, (%rbx,%rdx,8)
cmpq %r10, %r12
je 0x10a7e
andq $0x0, (%r9,%r10,8)
andq $0x0, (%r11)
incq %r10
addq -0x30(%rbp), %r11
jmp 0x10a67
incq %rdx
incl %ecx
addq -0x30(%rbp), %r9
addq $0x8, %r8
jmp 0x10a45
movq %rax, %rsi
movl %r15d, %edx
callq 0x10b2a
movl %r15d, %edi
movl %r15d, %esi
callq 0x782d
movq %rax, %r14
pushq $0x68
popq %rax
xorl %ebx, %ebx
movq %r15, -0x40(%rbp)
movq %r13, -0x38(%rbp)
cmpq %r13, %rbx
je 0x10b08
movq %rax, -0x50(%rbp)
movq %rax, %r13
movq %rbx, -0x48(%rbp)
subq $0x1, %r15
jb 0x10aef
movq 0xfe8d8(%rip), %rax     # 0x10f3a8
movsd (%rax,%rbx,8), %xmm0
callq 0xaf59
callq 0x868d
movq (%r14), %rcx
movq %rax, (%rcx,%r13)
addq %r12, %rbx
addq $0x8, %r13
jmp 0x10ac3
movq -0x48(%rbp), %rbx
incq %rbx
movq -0x50(%rbp), %rax
addq -0x30(%rbp), %rax
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r13
jmp 0x10ab3
movq %r14, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
leaq 0x1284b(%rip), %rdi     # 0x23370
callq 0x7756