// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %r8, %r14
movq %rcx, %r15
movl %edx, %r12d
movq %rsi, %r13
movl %edi, %ebp
movq 0x68(%rsp), %r8
leaq 0x1c(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %rsi, %rdi
movq %rsi, 0x20(%rsp)
movl %r12d, %esi
callq 0x1a785
leaq 0x1c(%rsp), %rax
movl (%rax), %ecx
movl %ecx, 0x14(%rsp)
leaq 0x18(%rsp), %rax
movl (%rax), %r8d
movl %r12d, 0x10(%rsp)
movslq %r12d, %r12
movq 0x68(%rsp), %rax
leaq (%rax,%r12,8), %rax
movl %ebp, %edi
movq %r13, %rsi
movl %r12d, %edx
movl %r8d, %r13d
movq %rbx, %r9
pushq %rax
pushq 0x68(%rsp)
callq 0x1ad8f
addq $0x8, %rsp
movl %ebp, 0x14(%rsp)
movl %ebp, %edi
movl %r13d, %ebp
movq 0x28(%rsp), %rsi
movl 0x1c(%rsp), %r13d
movl %r12d, %edx
movl %r13d, %ecx
movl %ebp, %r8d
movq %r15, %r9
pushq 0x68(%rsp)
pushq %rbx
pushq %r14
callq 0x1b198
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0x1a534
cmpl $0x0, 0xc(%rsp)
movl 0x10(%rsp), %r12d
je 0x1a41d
movl %r12d, %edi
movq %rbx, %rsi
movq 0x60(%rsp), %rdx
movl %r13d, %ecx
movl %ebp, %r8d
movq 0x68(%rsp), %r9
callq 0x1cdd3
testl %r12d, %r12d
jle 0x1a53b
movl %r12d, %ecx
leaq (,%rcx,8), %rdx
xorl %r10d, %r10d
movl $0x1, %esi
movapd 0x219ff(%rip), %xmm0    # 0x3be40
movsd 0x219c7(%rip), %xmm1    # 0x3be10
movq %rbx, %r8
movq 0x60(%rsp), %r9
xorl %eax, %eax
leaq 0x1(%r10), %r11
movsd (%r15,%r10,8), %xmm2
movl %r10d, %ebp
movapd %xmm2, %xmm3
cmpq %rcx, %r11
jae 0x1a491
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, %rcx
jne 0x1a473
movslq %ebp, %rdi
movsd %xmm2, (%r15,%rdi,8)
movsd %xmm3, (%r15,%r10,8)
movsd (%r14,%rdi,8), %xmm2
movsd (%r14,%r10,8), %xmm3
movsd %xmm3, (%r14,%rdi,8)
movsd %xmm2, (%r14,%r10,8)
leaq (%rbx,%rdi,8), %r12
movq 0x60(%rsp), %r13
leaq (%r13,%rdi,8), %r13
movq %rcx, %rbp
xorl %edi, %edi
movsd (%r12,%rdi), %xmm2
movsd (%r8,%rdi), %xmm3
movsd %xmm3, (%r12,%rdi)
movsd %xmm2, (%r8,%rdi)
movsd (%r13,%rdi), %xmm2
movsd (%r9,%rdi), %xmm3
movsd %xmm3, (%r13,%rdi)
movsd %xmm2, (%r9,%rdi)
addq %rdx, %rdi
decq %rbp
jne 0x1a4cb
movsd (%r14,%r10,8), %xmm2
andpd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
movl $0x1, %edi
cmoval %edi, %eax
incq %rsi
addq $0x8, %r9
addq $0x8, %r8
movq %r11, %r10
cmpq %rcx, %r11
jne 0x1a453
jmp 0x1a53d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1a53d
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq