// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
movq %r8, %r14
movq %rcx, %r15
movl %edx, %ebp
movq %rsi, 0x8(%rsp)
movl %edi, (%rsp)
movq 0x68(%rsp), %r8
leaq 0x24(%rsp), %r13
leaq 0x20(%rsp), %rbx
movq %rsi, %rdi
movl %edx, %esi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x16f75
movl (%r13), %r12d
movl (%rbx), %ebx
movslq %ebp, %r13
movq 0x68(%rsp), %rax
leaq (%rax,%r13,8), %rax
movl (%rsp), %edi
movq 0x8(%rsp), %rsi
movl %r13d, %edx
movl %r12d, %ecx
movl %ebx, %r8d
movq 0x10(%rsp), %r9
pushq %rax
pushq 0x68(%rsp)
callq 0x1745b
popq %rax
popq %rcx
subq $0x8, %rsp
movl 0x8(%rsp), %edi
movq 0x10(%rsp), %rsi
movl %r13d, %edx
movl %r12d, 0x10(%rsp)
movl %r12d, %ecx
movl %ebx, 0x24(%rsp)
movl %ebx, %r8d
movq %r15, %r9
pushq 0x68(%rsp)
pushq 0x20(%rsp)
pushq %r14
callq 0x177e6
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0x16d2d
cmpl $0x0, (%rsp)
movq 0x60(%rsp), %r12
je 0x16c1e
movl %ebp, %edi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
movl 0x8(%rsp), %ecx
movl 0x1c(%rsp), %r8d
movq 0x68(%rsp), %r9
callq 0x19152
xorl %ecx, %ecx
testl %ebp, %ebp
movl $0x0, %edx
cmovgl %ebp, %edx
movq 0x10(%rsp), %r10
movl %ebp, %eax
movq %rax, (%rsp)
shlq $0x3, %r13
pushq $0x1
popq %rdi
movapd 0x1021c(%rip), %xmm0    # 0x26e60
movsd 0x101e4(%rip), %xmm1    # 0x26e30
movq %r12, %r9
movq %r10, %rbx
xorl %eax, %eax
movq %r12, %r8
cmpq %rdx, %rcx
je 0x16d30
movsd (%r15,%rcx,8), %xmm2
movq %rdi, %r12
movl %ecx, %r11d
movapd %xmm2, %xmm3
cmpl %ebp, %r12d
jge 0x16c90
movsd (%r15,%r12,8), %xmm4
ucomisd %xmm3, %xmm4
cmoval %r12d, %r11d
maxsd %xmm3, %xmm4
incq %r12
movapd %xmm4, %xmm3
jmp 0x16c70
movslq %r11d, %rsi
movsd %xmm2, (%r15,%rsi,8)
movsd %xmm3, (%r15,%rcx,8)
movsd (%r14,%rsi,8), %xmm2
movsd (%r14,%rcx,8), %xmm3
movsd %xmm3, (%r14,%rsi,8)
movsd %xmm2, (%r14,%rcx,8)
leaq (%rbx,%rsi,8), %r11
leaq (%r8,%rsi,8), %r12
xorl %r8d, %r8d
movq (%rsp), %rsi
subq $0x1, %rsi
jb 0x16d01
movsd (%r11,%r8), %xmm2
movsd (%r10,%r8), %xmm3
movsd %xmm3, (%r11,%r8)
movsd %xmm2, (%r10,%r8)
movsd (%r12,%r8), %xmm2
movsd (%r9,%r8), %xmm3
movsd %xmm3, (%r12,%r8)
movsd %xmm2, (%r9,%r8)
addq %r13, %r8
jmp 0x16cc6
movsd (%r14,%rcx,8), %xmm2
incq %rcx
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
pushq $0x1
popq %rsi
cmoval %esi, %eax
incq %rdi
addq $0x8, %r10
addq $0x8, %r9
movq 0x60(%rsp), %r8
jmp 0x16c57
pushq $-0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq