// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/d_diagonalize.c
// Function: dd_Diagonalize
void dd_Diagonalize(int N, double **MATRIX, double *eigen_values,
		    double **eigen_vector, int SIGN)
{
  double **eigen_vt, *a; double *m;
  int jacobi_rotations=0, i, j, k, ik, ilow, 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 */
  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!) */
    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 */
    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:
  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
  float E_THR=0;
  ik=0; ilow=N-1;
  for(i=0; i<N; i++){
    //ir=i+1;  k=ik; ik++;
    ir=i_rank[i]+1;
    if(fabs(eigen_va[ir])<=E_THR){k=ilow; ilow--;}
    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 $0x90, %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, -0x68(%rbp)
movslq -0x4(%rbp), %rsi
movl $0x1, %edi
callq 0x6bc10
movq %rax, -0x70(%rbp)
movslq -0x4(%rbp), %rsi
movl $0x1, %edi
callq 0x6bc10
movq %rax, -0x78(%rbp)
movslq -0x4(%rbp), %rsi
movslq -0x4(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rdi
callq 0x6bdc0
movq %rax, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6b228
movq -0x80(%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)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6b21b
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %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 0x6b1e9
jmp 0x6b21d
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6b1b5
movq -0x80(%rbp), %rdi
movl -0x4(%rbp), %esi
movq -0x78(%rbp), %rdx
movq -0x70(%rbp), %rcx
callq 0x6ca50
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x4(%rbp), %edx
movq -0x80(%rbp), %rcx
callq 0x6db90
cmpl $0x0, %eax
je 0x6b262
movq -0x80(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x6b31e
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6b2dc
movq -0x80(%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)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6b2cf
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %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 0x6b29d
jmp 0x6b2d1
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6b269
movslq -0x4(%rbp), %rsi
movslq -0x4(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rdi
callq 0x6bdc0
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
movl -0x4(%rbp), %esi
movq -0x78(%rbp), %rdx
movq -0x88(%rbp), %rcx
leaq -0x44(%rbp), %r8
callq 0x6d0f0
movq -0x88(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x6b371
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x6b36f
movq -0x78(%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 -0x78(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6b32b
jmp 0x6b371
movq -0x78(%rbp), %rdi
addq $0x8, %rdi
movl -0x4(%rbp), %esi
movq -0x68(%rbp), %rdx
callq 0x6aae0
cmpl $0x0, -0x24(%rbp)
jge 0x6b3d8
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x6b3d6
movq -0x78(%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 -0x78(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6b392
jmp 0x6b3d8
xorps %xmm0, %xmm0
movss %xmm0, -0x8c(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x6b4d4
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x78(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movaps 0x11065(%rip), %xmm0    # 0x7c490
pand %xmm0, %xmm1
movss -0x8c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x6b452
movl -0x58(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x6b461
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x78(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x18(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x6b4c4
movq -0x30(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x5c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6b482
jmp 0x6b4c6
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6b3fa
movq -0x70(%rbp), %rdi
movslq -0x4(%rbp), %rdx
movl $0x1, %esi
callq 0x6c650
movq -0x78(%rbp), %rdi
movslq -0x4(%rbp), %rdx
movl $0x1, %esi
callq 0x6c650
movq -0x80(%rbp), %rdi
movslq -0x4(%rbp), %rdx
movslq -0x4(%rbp), %r8
movl $0x1, %ecx
movq %rcx, %rsi
callq 0x6c6f0
cmpq $0x0, -0x88(%rbp)
je 0x6b537
movq -0x88(%rbp), %rdi
movslq -0x4(%rbp), %rdx
movslq -0x4(%rbp), %r8
movl $0x1, %ecx
movq %rcx, %rsi
callq 0x6c6f0
movq -0x68(%rbp), %rdi
callq 0x1040
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)