// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/nma.c
// Function: Compare_anisou
int Compare_anisou(float ***aniso_pred, float ***aniso_exp, int nca,
		   char *model, char *inter, char *file_name, char *prot_name,
		   int N, int *weight, float *dot_aniso, float *ov_aniso,
		   float *delta_aniso)
{
  //FILE *file_out=fopen(file_name, "a");
  int ica, i, j, n_sum=0;
  float sum_overlap=0, sum_dot=0, sum_delta=0;
  float delta, overlap, dot, dd;
  float **e_vec1=Allocate_mat2_f(3,3), e_val1[3];
  float **e_vec2=Allocate_mat2_f(3,3), e_val2[3];
  float **e_vec12=Allocate_mat2_f(3,3), e_val12[3];
  float **u_12=Allocate_mat2_f(3,3);

  for(ica=0; ica<nca; ica++){
    if(weight[ica]){
      float **u1=aniso_exp[ica],  norm1=0;
      float **u2=aniso_pred[ica], norm2=0;
      float prod_lambda=1.0, prod_lambda_12=1.0;
      float isotropy;

      // Exclude quasi-spherical distributions, isotropy >= 0.5
      f_Diagonalize(3, u1, e_val1, e_vec1, 1);
      isotropy=e_val1[2]/e_val1[0]; //printf("%.2f\n", anisotropy);
      if(isotropy >= 0.5)continue;
      n_sum++;

      /****************  Overlap *********************/
      // Normalize by the trace
      for(i=0; i<3; i++)norm1+=u1[i][i];
      for(i=0; i<3; i++)norm2+=u2[i][i];
      for(i=0; i<3; i++)for(j=i; j<3; j++){
	  u1[i][j]/=norm1; u2[i][j]/=norm2;
	  u_12[i][j]=u1[i][j]+u2[i][j];
	}
      for(i=0; i<3; i++)for(j=0; j<i; j++){
	  u1[i][j]=u1[j][i]; u2[i][j]=u2[j][i]; u_12[i][j]=u_12[j][i];
	}

      for(i=0; i<3; i++)e_val1[i]/=norm1;
      f_Diagonalize(3, u2, e_val2, e_vec2, 1);
      f_Diagonalize(3, u_12, e_val12, e_vec12, 1);
      for(i=0; i<3; i++){
	prod_lambda*=(e_val1[i]*e_val2[i]);
	prod_lambda_12*=e_val12[i];
      }
      overlap=sqrt(8.*sqrt(prod_lambda)/prod_lambda_12);
      sum_overlap += overlap;
      // printf("overlap: %.3f\n", overlap);

      /*****   dot product   **************/
      /*
	dot=0; dot_norm=0;
	for(i=0; i<3; i++){
	float w=e_val1[i]*e_val2[i];
	dot+=w*Scalar_product_3(e_vec1[i], e_vec2[i]);
	dot_norm+=w;
	}
	dot /= dot_norm;
      */
      dot=Scalar_product_3(e_vec1[0], e_vec2[0]);
      if(dot<0){dot=-dot;} sum_dot += dot;

      /***********   delta   **************/
      delta=0;           // delta = sqrt(sum_ij(U1_ij-U2_ij)^2/9)
      for(i=0; i<3; i++){
	dd=u1[i][i]-u2[i][i]; delta+=dd*dd;
	for(j=0; j<i; j++){dd=u1[i][j]-u2[i][j]; delta+=2*dd*dd;}
      }
      sum_delta+=delta;

      /*
      //fprintf(file_out, "%6.3f %6.3f\n", overlap, dot);
      for(i=0; i<3; i++)for(j=0; j<=i; j++){
      fprintf(file_out, "%6.3f %6.3f ", u1[i][j], u2[i][j]);
      }
      fprintf(file_out, "\n");
      */
    }
  }
  *ov_aniso=sum_overlap/n_sum;
  *dot_aniso=sum_dot/n_sum;
  *delta_aniso=sqrt(sum_delta/(9*n_sum));

  /*
    fprintf(file_out, "%6.3f  %s %8s %6.3f %2.0f %8s %3d\n",
	  sum_overlap/n_sum, model, inter, sum_dot/n_sum, n_sum, prot_name, N);
  fclose(file_out);
  */

  // Clean
  Empty_matrix_f(e_vec1, 3);
  Empty_matrix_f(e_vec2, 3);
  Empty_matrix_f(e_vec12, 3);
  Empty_matrix_f(u_12, 3);

  return(n_sum);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x40(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
movl $0x3, %esi
movl %esi, %edi
callq 0x69360
movq %rax, -0x68(%rbp)
movl $0x3, %esi
movl %esi, %edi
callq 0x69360
movq %rax, -0x80(%rbp)
movl $0x3, %esi
movl %esi, %edi
callq 0x69360
movq %rax, -0x98(%rbp)
movl $0x3, %esi
movl %esi, %edi
callq 0x69360
movq %rax, -0xb0(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x38eaa
movq 0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x38e9a
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xb8(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0xbc(%rbp)
movq -0x8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xc8(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0xcc(%rbp)
movss 0x3d6f9(%rip), %xmm0    # 0x76090
movss %xmm0, -0xd0(%rbp)
movss 0x3d6e9(%rip), %xmm0    # 0x76090
movss %xmm0, -0xd4(%rbp)
movq -0xb8(%rbp), %rsi
leaq -0x74(%rbp), %rdx
movq -0x68(%rbp), %rcx
movl $0x3, %edi
movl $0x1, %r8d
callq 0x6a6a0
movss -0x6c(%rbp), %xmm0
divss -0x74(%rbp), %xmm0
movss %xmm0, -0xd8(%rbp)
movss -0xd8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3d614(%rip), %xmm1    # 0x76008
ucomisd %xmm1, %xmm0
jb 0x389ff
jmp 0x38e9c
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x38a48
movq -0xb8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
addss -0xbc(%rbp), %xmm0
movss %xmm0, -0xbc(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x38a0f
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x38a88
movq -0xc8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
addss -0xcc(%rbp), %xmm0
movss %xmm0, -0xcc(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x38a4f
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x38b61
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x3, -0x3c(%rbp)
jge 0x38b51
movss -0xbc(%rbp), %xmm1
movq -0xb8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movss -0xcc(%rbp), %xmm1
movq -0xc8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movq -0xb8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0xc8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
addss (%rax,%rcx,4), %xmm0
movq -0xb0(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x38a9f
jmp 0x38b53
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x38a8f
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x38c33
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x38c23
movq -0xb8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0xb8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0xc8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0xc8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq -0xb0(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0xb0(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x38b79
jmp 0x38c25
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x38b68
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x38c67
movss -0xbc(%rbp), %xmm1
movslq -0x38(%rbp), %rax
movss -0x74(%rbp,%rax,4), %xmm0
divss %xmm1, %xmm0
movss %xmm0, -0x74(%rbp,%rax,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x38c3a
movq -0xc8(%rbp), %rsi
leaq -0x8c(%rbp), %rdx
movq -0x80(%rbp), %rcx
movl $0x3, %edi
movl $0x1, %r8d
callq 0x6a6a0
movq -0xb0(%rbp), %rsi
leaq -0xa4(%rbp), %rdx
movq -0x98(%rbp), %rcx
movl $0x3, %edi
movl $0x1, %r8d
callq 0x6a6a0
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x38d0a
movslq -0x38(%rbp), %rax
movss -0x74(%rbp,%rax,4), %xmm0
movslq -0x38(%rbp), %rax
mulss -0x8c(%rbp,%rax,4), %xmm0
mulss -0xd0(%rbp), %xmm0
movss %xmm0, -0xd0(%rbp)
movslq -0x38(%rbp), %rax
movss -0xa4(%rbp,%rax,4), %xmm0
mulss -0xd4(%rbp), %xmm0
movss %xmm0, -0xd4(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x38cb5
movss -0xd0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
movaps %xmm0, %xmm1
movsd 0x4374a(%rip), %xmm0    # 0x7c470
mulsd %xmm1, %xmm0
movss -0xd4(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm0
callq 0x1220
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x54(%rbp), %xmm0
addss -0x44(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rdi
movq -0x80(%rbp), %rax
movq (%rax), %rsi
callq 0x14ba0
movss %xmm0, -0x58(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x58(%rbp), %xmm0
jbe 0x38d8f
movss -0x58(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
addss -0x48(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x50(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x38e8b
movq -0xb8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0xc8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
subss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
movss -0x5c(%rbp), %xmm2
movss -0x50(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x50(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x38e7b
movq -0xb8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq -0xc8(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x3c(%rbp), %rcx
subss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x5c(%rbp)
movss 0x3d240(%rip), %xmm0    # 0x76094
mulss -0x5c(%rbp), %xmm0
movss -0x5c(%rbp), %xmm2
movss -0x50(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x50(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x38e0f
jmp 0x38e7d
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x38dad
movss -0x50(%rbp), %xmm0
addss -0x4c(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
jmp 0x38e9c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x38935
movss -0x44(%rbp), %xmm0
cvtsi2ssl -0x40(%rbp), %xmm1
divss %xmm1, %xmm0
movq 0x30(%rbp), %rax
movss %xmm0, (%rax)
movss -0x48(%rbp), %xmm0
cvtsi2ssl -0x40(%rbp), %xmm1
divss %xmm1, %xmm0
movq 0x28(%rbp), %rax
movss %xmm0, (%rax)
movss -0x4c(%rbp), %xmm0
imull $0x9, -0x40(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
cvtsd2ss %xmm0, %xmm0
movq 0x38(%rbp), %rax
movss %xmm0, (%rax)
movq -0x68(%rbp), %rdi
movl $0x3, %esi
callq 0x69240
movq -0x80(%rbp), %rdi
movl $0x3, %esi
callq 0x69240
movq -0x98(%rbp), %rdi
movl $0x3, %esi
callq 0x69240
movq -0xb0(%rbp), %rdi
movl $0x3, %esi
callq 0x69240
movl -0x40(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)