// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/d_diagonalize.c
// Function: f_Diagonalize
void f_Diagonalize(int N, float **MATRIX, float *eigen_values,
		   float **eigen_vector, int SIGN)
{
  double **eigen_vt, *a; float *m;
  int jacobi_rotations=0, i, j, k, ik, ir;
  int *i_rank=malloc(N*sizeof(int));

  double *e_vector= dvector( (long)1, (long)N);
  double *eigen_va= dvector( (long)1, (long)N);
  double **a_matrix= dmatrix( (long)1, (long)N, (long)1, (long)N);
  double **v_matrix= NULL;

  /* fill matrix a_matrix. Indeces from 1 to N! */
  for(i=0; i<N; i++){
    a=a_matrix[i+1]; m=MATRIX[i];
    //for(j=0; j<N; j++)a[j+1]= m[j];
    if(SIGN<0){for(j=0; j<N; j++)a[j+1]=-m[j];}
    else{for(j=0; j<N; j++)a[j+1]= m[j];}
  }

  // obtain eigensystem with tridimensional reduction
  tred2( a_matrix, (int)N, eigen_va, e_vector);
  if( tqli(eigen_va, e_vector, (int)N, a_matrix)){
    eigen_vt=a_matrix;
  }else{
    // tqli failed 
    // reconstruct matrix a_matrix (destroyed by tred2/tqli!)
    printf("tqli routine has failed, trying jacobi\n");
    for(i=0; i<N; i++){
      a=a_matrix[i+1]; m=MATRIX[i];
      //for(j=0; j<N; j++)a[j+1]= m[j];
      if(SIGN<0){for(j=0; j<N; j++)a[j+1]=-m[j];}
      else{for(j=0; j<N; j++)a[j+1]= m[j];}
    }
    // obtain eigensystem with jacobi routine
    v_matrix=dmatrix( (long)1, (long)N, (long)1, (long)N);
    jacobi( a_matrix, N, eigen_va, v_matrix, &jacobi_rotations);
    eigen_vt=v_matrix;
  }

  // Sort:
  d_sort(eigen_va+1, N, i_rank);
  if(SIGN<0) for(j=1; j<=N; j++)eigen_va[j]=-eigen_va[j];
  /* d_sort(eigen_va+1, N, i_rank);
     if(SIGN<0) for(j=1; j<=N; j++)eigen_va[j]=-eigen_va[j];*/
  // eigsrt(eigen_va, eigen_vt, N);

  // Transpose and shift indices. Omit lambda < E_THR
  ik=0; // int ilow=N-1;
  for(i=0; i<N; i++){
    //ir=i+1; k=ik; ik++;
    ir=i_rank[i]+1;
    /*if(select && (select[ir]==0)){
      k=ilow; ilow--; if(selected)selected[k]=0;
      }else{*/
    k=ik; ik++;
    //}
    eigen_values[k]=eigen_va[ir];
    for(j=1; j<=N; j++){
      eigen_vector[k][j-1]=eigen_vt[j][ir];
    }
  }

  free_dvector(e_vector, 1, N);
  free_dvector(eigen_va, 1, N);
  free_dmatrix(a_matrix, 1, N, 1, N);
  if(v_matrix)free_dmatrix(v_matrix, 1, N, 1, N);
  free(i_rank);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl $0x0, -0x44(%rbp)
movslq -0x4(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x60(%rbp)
movslq -0x4(%rbp), %rsi
movl $0x1, %edi
callq 0x6bc10
movq %rax, -0x68(%rbp)
movslq -0x4(%rbp), %rsi
movl $0x1, %edi
callq 0x6bc10
movq %rax, -0x70(%rbp)
movslq -0x4(%rbp), %rsi
movslq -0x4(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rdi
callq 0x6bdc0
movq %rax, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6a7f4
movq -0x78(%rbp), %rax
movl -0x48(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x6a7a5
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6a7a3
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x38(%rbp), %rax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6a760
jmp 0x6a7e4
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6a7e2
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x38(%rbp), %rax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6a7ac
jmp 0x6a7e4
jmp 0x6a7e6
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6a722
movq -0x78(%rbp), %rdi
movl -0x4(%rbp), %esi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
callq 0x6ca50
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl -0x4(%rbp), %edx
movq -0x78(%rbp), %rcx
callq 0x6db90
cmpl $0x0, %eax
je 0x6a82e
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x6a94e
leaq 0x18bcd(%rip), %rdi     # 0x83402
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6a915
movq -0x78(%rbp), %rax
movl -0x48(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x6a8c6
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6a8c4
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x38(%rbp), %rax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6a881
jmp 0x6a905
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6a903
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x38(%rbp), %rax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6a8cd
jmp 0x6a905
jmp 0x6a907
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6a843
movslq -0x4(%rbp), %rsi
movslq -0x4(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rdi
callq 0x6bdc0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movl -0x4(%rbp), %esi
movq -0x70(%rbp), %rdx
movq -0x80(%rbp), %rcx
leaq -0x44(%rbp), %r8
callq 0x6d0f0
movq -0x80(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
movl -0x4(%rbp), %esi
movq -0x60(%rbp), %rdx
callq 0x6aae0
cmpl $0x0, -0x24(%rbp)
jge 0x6a9b5
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x6a9b3
movq -0x70(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x70(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6a96f
jmp 0x6a9b5
movl $0x0, -0x54(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6aa6a
movq -0x60(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x70(%rbp), %rax
movslq -0x58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x18(%rbp), %rax
movslq -0x50(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x6aa5a
movq -0x30(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x58(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x20(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6aa14
jmp 0x6aa5c
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6a9c3
movq -0x68(%rbp), %rdi
movslq -0x4(%rbp), %rdx
movl $0x1, %esi
callq 0x6c650
movq -0x70(%rbp), %rdi
movslq -0x4(%rbp), %rdx
movl $0x1, %esi
callq 0x6c650
movq -0x78(%rbp), %rdi
movslq -0x4(%rbp), %rdx
movslq -0x4(%rbp), %r8
movl $0x1, %ecx
movq %rcx, %rsi
callq 0x6c6f0
cmpq $0x0, -0x80(%rbp)
je 0x6aac7
movq -0x80(%rbp), %rdi
movslq -0x4(%rbp), %rdx
movslq -0x4(%rbp), %r8
movl $0x1, %ecx
movq %rcx, %rsi
callq 0x6c6f0
movq -0x60(%rbp), %rdi
callq 0x1040
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)