// File: /workspace/github_c_makefile_star2_O3/dapogon[P]cellcoal/src/eigen.c
// Function: eigen
int eigen(int job, double AA[], int n, double rr[], double ri[], double vr[], double vi[], double work[])
{
/*  double work[n*2]: working space
*/
    int low,hi,i,j,k, it, istate=0;
    double tiny=sqrt(pow((double)BASE,(double)(1-DIGITS))), t;

    balance(AA,n,&low,&hi,work);
    elemhess(job,AA,n,low,hi,vr,vi, (int*)(work+n));
    if (-1 == realeig(job,AA,n,low,hi,rr,ri,vr,vi)) return (-1);
    if (job) unbalance(n,vr,vi,low,hi,work);

/* sort, added by Z. Yang */
   for (i=0; i<n; i++) {
       for (j=i+1,it=i,t=rr[i]; j<n; j++)
           if (t<rr[j]) { t=rr[j]; it=j; }
       rr[it]=rr[i];   rr[i]=t;
       t=ri[it];       ri[it]=ri[i];  ri[i]=t;
       for (k=0; k<n; k++) {
          t=vr[k*n+it];  vr[k*n+it]=vr[k*n+i];  vr[k*n+i]=t;
          t=vi[k*n+it];  vi[k*n+it]=vi[k*n+i];  vi[k*n+i]=t;
       }
       if (fabs(ri[i])>tiny) istate=1;
   }

    return (istate) ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %r8, %r14
movq %rcx, %r15
movl %edx, %r13d
movq %rsi, %r12
movl %edi, %ebx
movq 0x68(%rsp), %r8
leaq 0x24(%rsp), %rbp
leaq 0x20(%rsp), %rcx
movq %rsi, %rdi
movq %rsi, 0x10(%rsp)
movl %edx, %esi
movq %rbp, %rdx
callq 0x1aa9f
movl (%rbp), %ecx
movl %ecx, 0x4(%rsp)
leaq 0x20(%rsp), %rax
movl (%rax), %ebp
movl %r13d, 0x1c(%rsp)
movslq %r13d, %r13
movq 0x68(%rsp), %rax
leaq (%rax,%r13,8), %rax
movl %ebx, %edi
movq %r12, %rsi
movl %r13d, %edx
movl %ebp, %r8d
movq 0x8(%rsp), %r12
movq %r12, %r9
pushq %rax
pushq 0x68(%rsp)
callq 0x1b069
addq $0x8, %rsp
movl %ebx, 0x20(%rsp)
movl %ebx, %edi
movq 0x18(%rsp), %rsi
movl %r13d, %edx
movl 0xc(%rsp), %ecx
movl %ebp, 0x18(%rsp)
movl %ebp, %r8d
movq %r15, %r9
pushq 0x68(%rsp)
pushq %r12
pushq %r14
callq 0x1b47b
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0x1a855
cmpl $0x0, 0x18(%rsp)
movl 0x1c(%rsp), %ebx
je 0x1a73a
movl %ebx, %edi
movq 0x8(%rsp), %rsi
movq 0x60(%rsp), %rdx
movl 0x4(%rsp), %ecx
movl 0x10(%rsp), %r8d
movq 0x68(%rsp), %r9
callq 0x1d16c
testl %ebx, %ebx
jle 0x1a85c
movl %ebx, %edi
leaq (,%r13,8), %rdx
xorl %r10d, %r10d
movl $0x1, %esi
movapd 0x107a4(%rip), %xmm0    # 0x2af00
movsd 0x1076c(%rip), %xmm1    # 0x2aed0
movq 0x8(%rsp), %r8
movq 0x60(%rsp), %r9
xorl %eax, %eax
leaq 0x1(%r10), %r11
movsd (%r15,%r10,8), %xmm2
cmpq %r13, %r11
jge 0x1a7a9
movq %rsi, %r12
movapd %xmm2, %xmm4
movl %r10d, %ebp
movsd (%r15,%r12,8), %xmm3
ucomisd %xmm4, %xmm3
cmoval %r12d, %ebp
maxsd %xmm4, %xmm3
incq %r12
movapd %xmm3, %xmm4
cmpq %r12, %rdi
jne 0x1a789
jmp 0x1a7b0
movl %r10d, %ebp
movapd %xmm2, %xmm3
movslq %ebp, %rcx
movsd %xmm2, (%r15,%rcx,8)
movsd %xmm3, (%r15,%r10,8)
movsd (%r14,%rcx,8), %xmm2
movsd (%r14,%r10,8), %xmm3
movsd %xmm3, (%r14,%rcx,8)
movsd %xmm2, (%r14,%r10,8)
movq 0x8(%rsp), %rbx
leaq (%rbx,%rcx,8), %r12
movq 0x60(%rsp), %rbx
leaq (%rbx,%rcx,8), %rbp
movq %rdi, %rcx
xorl %ebx, %ebx
movsd (%r12,%rbx), %xmm2
movsd (%r8,%rbx), %xmm3
movsd %xmm3, (%r12,%rbx)
movsd %xmm2, (%r8,%rbx)
movsd (%rbp,%rbx), %xmm2
movsd (%r9,%rbx), %xmm3
movsd %xmm3, (%rbp,%rbx)
movsd %xmm2, (%r9,%rbx)
addq %rdx, %rbx
decq %rcx
jne 0x1a7ee
movsd (%r14,%r10,8), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
movl $0x1, %ecx
cmoval %ecx, %eax
incq %rsi
addq $0x8, %r9
addq $0x8, %r8
movq %r11, %r10
cmpq %rdi, %r11
jne 0x1a770
jmp 0x1a85e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1a85e
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq