// File: /workspace/github_c_makefile_star2_O1/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 0x2ea03(%rip), %rcx     # 0x40a00
cmovneq %rcx, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmoveq %rax, %rcx
movq (%rcx), %rdi
callq 0x8b01
callq 0x95e2
callq 0xa7fa
callq 0x8b78
cmpb $0x7, 0x10(%rax)
jne 0x1232f
movq %rax, %r14
movq (%rax), %rax
cmpl $0x2, (%rax)
jne 0x1232f
movl 0x4(%rax), %ecx
cmpl 0x8(%rax), %ecx
jne 0x1232f
movq (%r14), %rax
movslq 0x4(%rax), %r15
testq %r15, %r15
jle 0x12088
movq (%r14), %rax
addq $0x68, %rax
leaq (,%r15,8), %rcx
xorl %edx, %edx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
cmpb $0x5, 0x10(%rdi)
jne 0x1232f
incq %rsi
cmpq %rsi, %r15
jne 0x12067
incq %rdx
addq %rcx, %rax
cmpq %r15, %rdx
jne 0x12065
cmpl $0x2, %r15d
jl 0x12107
leal -0x1(%r15), %eax
movq (%r14), %rcx
leaq (,%r15,8), %rdx
leaq (%rcx,%r15,8), %rsi
addq $0x68, %rsi
leaq 0x8(,%r15,8), %rdi
addq $0x70, %rcx
leaq -0x1(%r15), %r8
xorl %r9d, %r9d
movapd 0x14040(%rip), %xmm0    # 0x26100
movsd 0x14060(%rip), %xmm1    # 0x26128
incq %r9
xorl %r10d, %r10d
movq %rsi, %r11
movq (%rcx,%r10,8), %rbx
movsd (%rbx), %xmm2
movq (%r11), %rbx
subsd (%rbx), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0x1232f
addq %rdx, %r11
incq %r10
cmpq %r10, %r8
jne 0x120d1
addq %rdi, %rsi
addq %rdi, %rcx
decq %r8
cmpq %rax, %r9
jne 0x120c8
movq 0xff2a2(%rip), %rdi     # 0x1113b0
testq %rdi, %rdi
je 0x12118
callq 0x7040
movq 0xff299(%rip), %rdi     # 0x1113b8
testq %rdi, %rdi
je 0x12129
callq 0x7040
movl %r15d, %eax
imull %eax, %eax
movq %rax, -0x30(%rbp)
leal (,%rax,8), %r12d
movl %r12d, %edi
callq 0x7810
movq %rax, 0xff266(%rip)     # 0x1113b0
movl %r12d, %edi
callq 0x7810
movq %rax, 0xff25f(%rip)     # 0x1113b8
testl %r15d, %r15d
jle 0x121f9
movq 0xff247(%rip), %rcx     # 0x1113b0
leaq (,%r15,8), %rdx
leaq (%rcx,%r15,8), %rsi
leaq 0x8(,%r15,8), %rdi
movl $0x1, %r8d
xorl %r9d, %r9d
xorl %r10d, %r10d
movq (%r14), %r11
movl %r15d, %r12d
imull %r10d, %r12d
addq %r10, %r12
movq 0x68(%r11,%r12,8), %r11
movsd (%r11), %xmm0
movsd %xmm0, (%rcx,%r12,8)
incq %r10
cmpq %r15, %r10
jae 0x121eb
movq %r15, %r11
movq %r9, %r12
movq %rsi, %r13
movq (%r14), %rbx
movq 0x70(%rbx,%r12), %rbx
movsd (%rbx), %xmm0
movsd %xmm0, 0x8(%rcx,%r12)
movq (%r14), %rbx
movq 0x70(%rbx,%r12), %rbx
movsd (%rbx), %xmm0
movsd %xmm0, (%r13)
addq %rdx, %r13
addq $0x8, %r12
decq %r11
cmpq %r11, %r8
jne 0x121b7
incq %r8
addq %rdi, %rsi
addq %rdi, %r9
cmpq %r15, %r10
jne 0x12189
testl %r15d, %r15d
jle 0x12267
leaq 0x8(%rax), %rcx
leaq (,%r15,8), %rdx
leaq 0x8(,%r15,8), %rsi
leaq (%rax,%r15,8), %rdi
leaq -0x1(%r15), %r8
xorl %r9d, %r9d
movabsq $0x3ff0000000000000, %r10 # imm = 0x3FF0000000000000
xorl %r11d, %r11d
movl %r15d, %ebx
imull %r11d, %ebx
leaq (%rax,%r11,8), %r14
movq %r10, (%r14,%rbx,8)
incq %r11
cmpq %r15, %r11
jae 0x12259
movq %rdi, %r14
xorl %r12d, %r12d
movq %r9, (%rcx,%r12,8)
movq %r9, (%r14)
incq %r12
addq %rdx, %r14
cmpq %r12, %r8
jne 0x12247
addq %rsi, %rcx
addq %rsi, %rdi
decq %r8
cmpq %r15, %r11
jne 0x1222a
movq 0xff142(%rip), %rdi     # 0x1113b0
movq %rax, %rsi
movl %r15d, %edx
callq 0x1233b
movq -0x30(%rbp), %rdi
callq 0x7850
movq %rax, %r14
movq (%rax), %rax
movl $0x2, (%rax)
movq (%r14), %rax
movl %r15d, 0x4(%rax)
movq (%r14), %rax
movl %r15d, 0x8(%rax)
testl %r15d, %r15d
jle 0x12319
leaq (,%r15,8), %rax
movq %rax, -0x38(%rbp)
movl $0x68, %r12d
xorl %r13d, %r13d
movq %r15, %rbx
movq %r13, -0x40(%rbp)
movq %r12, -0x48(%rbp)
movq 0xff0f0(%rip), %rax     # 0x1113b8
movsd (%rax,%r13,8), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x74ec
movb $0x5, 0x10(%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rax, %rdi
callq 0x8b01
callq 0x8b78
movq (%r14), %rcx
movq %rax, (%rcx,%r12)
addq $0x8, %r12
addq %r15, %r13
decq %rbx
jne 0x122c1
movq -0x40(%rbp), %r13
incq %r13
movq -0x48(%rbp), %r12
addq -0x38(%rbp), %r12
cmpq %r15, %r13
jne 0x122b6
movq %r14, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
leaq 0x13fe2(%rip), %rdi     # 0x26318
callq 0x77c8