// File: /workspace/github_c_makefile_star2_O3/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 0x3268e(%rip), %rcx     # 0x45a00
cmovneq %rcx, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmoveq %rax, %rcx
movq (%rcx), %rdi
callq 0x8ba5
callq 0x96e2
callq 0xac30
movl 0x2bf1f(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0x136ef
decl %eax
movl %eax, 0x2bf07(%rip)     # 0x3f2b8
leaq 0x35208(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %r13
cmpb $0x7, 0x10(%r13)
jne 0x136e3
movq (%r13), %rax
cmpl $0x2, (%rax)
jne 0x136e3
movl 0x4(%rax), %r12d
cmpl 0x8(%rax), %r12d
jne 0x136e3
testl %r12d, %r12d
jle 0x13493
leaq 0x68(%rax), %rdx
leaq (,%r12,8), %rcx
xorl %esi, %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
cmpb $0x5, 0x10(%r8)
jne 0x136e3
incq %rdi
cmpq %rdi, %r12
jne 0x133fb
incq %rsi
addq %rcx, %rdx
cmpq %r12, %rsi
jne 0x133f9
cmpl $0x1, %r12d
je 0x13493
leal -0x1(%r12), %edx
leaq (%rax,%r12,8), %rsi
addq $0x68, %rsi
leaq 0x8(,%r12,8), %rdi
addq $0x70, %rax
leaq -0x1(%r12), %r8
xorl %r9d, %r9d
movapd 0x16cd4(%rip), %xmm0    # 0x2a120
movsd 0x16cf4(%rip), %xmm1    # 0x2a148
incq %r9
xorl %r10d, %r10d
movq %rsi, %r11
movq (%rax,%r10,8), %rbx
movsd (%rbx), %xmm2
movq (%r11), %rbx
subsd (%rbx), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0x136e3
addq %rcx, %r11
incq %r10
cmpq %r10, %r8
jne 0x1345d
addq %rdi, %rsi
addq %rdi, %rax
decq %r8
cmpq %rdx, %r9
jne 0x13454
movq 0x102f16(%rip), %rdi    # 0x1163b0
testq %rdi, %rdi
je 0x134a4
callq 0x7040
movq 0x102f0d(%rip), %rdi    # 0x1163b8
testq %rdi, %rdi
je 0x134b5
callq 0x7040
movl %r12d, %r14d
imull %r14d, %r14d
leal (,%r14,8), %ebx
movl %ebx, %edi
callq 0x7853
movq %rax, 0x102ede(%rip)    # 0x1163b0
movl %ebx, %edi
callq 0x7853
movq %rax, 0x102ed8(%rip)    # 0x1163b8
testl %r12d, %r12d
movq %r12, -0x30(%rbp)
jle 0x135ec
movq 0x102ebc(%rip), %rsi    # 0x1163b0
leaq (,%r12,8), %rcx
leaq (%rsi,%r12,8), %rdi
leaq 0x8(,%r12,8), %rdx
movl $0x1, %r8d
xorl %r9d, %r9d
xorl %r10d, %r10d
movq (%r13), %r11
movl %r12d, %ebx
imull %r10d, %ebx
addq %r10, %rbx
movq 0x68(%r11,%rbx,8), %r11
movsd (%r11), %xmm0
movsd %xmm0, (%rsi,%rbx,8)
incq %r10
cmpq %r12, %r10
jae 0x1357b
movq -0x30(%rbp), %r11
movq %r9, %rbx
movq %rdi, %r15
movq (%r13), %r12
movq 0x70(%r12,%rbx), %r12
movsd (%r12), %xmm0
movsd %xmm0, 0x8(%rsi,%rbx)
movq (%r13), %r12
movq 0x70(%r12,%rbx), %r12
movsd (%r12), %xmm0
movsd %xmm0, (%r15)
addq %rcx, %r15
addq $0x8, %rbx
decq %r11
cmpq %r11, %r8
jne 0x13543
incq %r8
addq %rdx, %rdi
addq %rdx, %r9
movq -0x30(%rbp), %r12
cmpq %r12, %r10
jne 0x13514
testl %r12d, %r12d
jle 0x135ec
leaq 0x8(%rax), %rsi
leaq (%rax,%r12,8), %rdi
leaq -0x1(%r12), %r8
xorl %r9d, %r9d
movabsq $0x3ff0000000000000, %r10 # imm = 0x3FF0000000000000
xorl %r11d, %r11d
movl %r12d, %ebx
imull %r11d, %ebx
leaq (%rax,%r11,8), %r15
movq %r10, (%r15,%rbx,8)
incq %r11
cmpq %r12, %r11
jae 0x135de
movq %rdi, %rbx
xorl %r15d, %r15d
movq %r9, (%rsi,%r15,8)
movq %r9, (%rbx)
incq %r15
addq %rcx, %rbx
cmpq %r15, %r8
jne 0x135cc
addq %rdx, %rsi
addq %rdx, %rdi
decq %r8
cmpq %r12, %r11
jne 0x135af
movq 0x102dbd(%rip), %rdi    # 0x1163b0
movq %rax, %rsi
movl %r12d, %edx
callq 0x136fb
movl %r14d, %edi
callq 0x7893
movq %rax, %r14
movq (%rax), %rax
movl $0x2, (%rax)
movq (%r14), %rax
movl %r12d, 0x4(%rax)
movq (%r14), %rax
movl %r12d, 0x8(%rax)
testl %r12d, %r12d
jle 0x136cd
movq %r12, %rbx
leaq (,%r12,8), %rax
movq %rax, -0x38(%rbp)
movl $0x68, %r15d
xorl %r13d, %r13d
movl $0xfffe795f, %r12d      # imm = 0xFFFE795F
movq %r13, -0x40(%rbp)
movq %r15, -0x48(%rbp)
movq 0x102d62(%rip), %rax    # 0x1163b8
movsd (%rax,%r13,8), %xmm0
movsd %xmm0, -0x50(%rbp)
callq 0x74dc
movb $0x5, 0x10(%rax)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8ba5
movl 0x2bc37(%rip), %eax     # 0x3f2b8
leal (%rax,%r12), %ecx
cmpl %r12d, %ecx
jbe 0x136ef
decl %eax
movl %eax, 0x2bc26(%rip)     # 0x3f2b8
leaq 0x34f27(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rax
movq (%r14), %rcx
movq %rax, (%rcx,%r15)
addq $0x8, %r15
addq -0x30(%rbp), %r13
decq %rbx
jne 0x1364f
movq -0x40(%rbp), %r13
incq %r13
movq -0x48(%rbp), %r15
addq -0x38(%rbp), %r15
movq -0x30(%rbp), %rbx
cmpq %rbx, %r13
jne 0x13647
movq %r14, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
leaq 0x16c4e(%rip), %rdi     # 0x2a338
callq 0x780b
leaq 0x1b84b(%rip), %rdi     # 0x2ef41
callq 0x780b