// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/nma.c
// Function: Compare_modes
void Compare_modes(float **Cart_mode_ANM, float **Cart_mode_TNM, int N_Cart,
		   float **Tors_mode_ANM, float **Tors_mode_TNM, int N_tors,
		   float *mass_coord, char *prot_name, char *inter)
{
  // Compare torsional and cartesian normal modes
  int ia, i;
  float q;
  float *Ovlp_cart_max_TNM=malloc(N_tors*sizeof(float));
  float *Ovlp_tors_max_TNM=malloc(N_tors*sizeof(float));
  float *Ovlp_cart_max_ANM=malloc(N_Cart*sizeof(float));
  float *Ovlp_tors_max_ANM=malloc(N_Cart*sizeof(float));
  int *mode_cart_max_TNM=malloc(N_tors*sizeof(int));
  int *mode_tors_max_TNM=malloc(N_tors*sizeof(int));
  int *mode_cart_max_ANM=malloc(N_Cart*sizeof(int));
  int *mode_tors_max_ANM=malloc(N_Cart*sizeof(int));

  FILE *file_out; char outfile[200];

  sprintf(outfile, "%s_%s_compare.dat", prot_name, inter);
  file_out=fopen(outfile, "w");
  printf("Writing %s\n", outfile);

  for(i=0; i<N_tors; i++){
    Ovlp_cart_max_TNM[i]=0;
    Ovlp_tors_max_TNM[i]=0;
  }
  for(i=0; i<N_Cart; i++){
    Ovlp_cart_max_ANM[i]=0;
    Ovlp_tors_max_ANM[i]=0;
  }
  // Normalize
  for(i=0; i<N_tors; i++){
    Normalize_vector_weighted(Cart_mode_TNM[i], mass_coord, N_Cart);
    Normalize_vector(Tors_mode_TNM[i], N_tors);
  }
  for(i=0; i<N_Cart; i++){
    Normalize_vector_weighted(Cart_mode_ANM[i], mass_coord, N_Cart);
    Normalize_vector(Tors_mode_ANM[i], N_tors);
  }

  for(ia=0; ia<N_tors; ia++){
    float *Ca=Cart_mode_TNM[ia];
    for(i=0; i<N_Cart; i++){
      q=Scalar_product_weighted(Ca, Cart_mode_ANM[i], mass_coord, N_Cart);
      q*=q;
      if(q > Ovlp_cart_max_TNM[ia]){
	Ovlp_cart_max_TNM[ia]=q; mode_cart_max_TNM[ia]=i;
      }
      if(q > Ovlp_cart_max_ANM[i] ){
	Ovlp_cart_max_ANM[i]=q; mode_cart_max_ANM[i]=ia;
      }
    }
  }
  for(ia=0; ia<N_tors; ia++){
    float *Ta=Tors_mode_TNM[ia];
    for(i=0; i<N_Cart; i++){
      q=Scalar_product(Ta, Tors_mode_ANM[i],N_tors); q*=q;
      if(q > Ovlp_tors_max_TNM[ia]){
	Ovlp_tors_max_TNM[ia]=q; mode_tors_max_TNM[ia]=i;
      }
      if(q > Ovlp_tors_max_ANM[i] ){
	Ovlp_tors_max_ANM[i]=q; mode_tors_max_ANM[i]=ia;
      }
    }
  }

  fprintf(file_out, "# Max. coeff Cartesian TNM - ANM modes\n");
  fprintf(file_out, "# TNM_mode  Max.coeff^2 ANM_mode\n");
  for(i=0; i<N_tors; i++)
    fprintf(file_out, "%3d  %.3f %3d\n",
	    i, Ovlp_cart_max_TNM[i], mode_cart_max_TNM[i]);
  fprintf(file_out, "&\n");

  fprintf(file_out, "# Max. coeff Torsional TNM - ANM modes\n");
  fprintf(file_out, "# TNM_mode  Max.coeff^2 ANM_mode\n");
  for(i=0; i<N_tors; i++)
    fprintf(file_out, "%3d\t%.3f\t%3d\n",
	    i, Ovlp_tors_max_TNM[i], mode_tors_max_TNM[i]);
  fprintf(file_out, "&\n");

  fprintf(file_out, "# Max. coeff Cartesian ANM - TNM modes\n");
  fprintf(file_out, "# ANM_mode  Max.coeff^2  TNM_mode\n");
  for(i=0; i<N_Cart; i++)
    fprintf(file_out, "%3d\t%.3f\t%3d\n",
	    i, Ovlp_cart_max_ANM[i], mode_cart_max_ANM[i]);
  fprintf(file_out, "&\n");

  fprintf(file_out, "# Max. coeff Torsional ANM - TNM modes\n");
  fprintf(file_out, "# ANM_mode  Max.coeff^2  TNM_mode\n");
  for(i=0; i<N_Cart; i++)
    fprintf(file_out, "%3d\t%.3f\t%3d\n",
	    i, Ovlp_tors_max_ANM[i], mode_tors_max_ANM[i]);
  fprintf(file_out, "&\n");

  fclose(file_out);
  free(Ovlp_cart_max_TNM); free(mode_cart_max_TNM);
  free(Ovlp_tors_max_TNM); free(mode_tors_max_TNM);
  free(Ovlp_cart_max_ANM); free(mode_cart_max_ANM);
  free(Ovlp_tors_max_ANM); free(mode_tors_max_ANM);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %r9d, %r15d
movq %r8, 0x68(%rsp)
movq %rcx, 0x38(%rsp)
movl %edx, %r12d
movq %rsi, 0x60(%rsp)
movq %rdi, %r14
movslq %r9d, %rbp
leaq (,%rbp,4), %rbx
movq %rbx, %rdi
callq 0x21e0
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x21e0
movq %rax, 0x20(%rsp)
movl %r12d, 0x4(%rsp)
movslq %r12d, %r13
shlq $0x2, %r13
movq %r13, %rdi
callq 0x21e0
movq %rax, 0x18(%rsp)
movq %r13, %rdi
callq 0x21e0
movq %rax, %r12
movq %rbx, %rdi
callq 0x21e0
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
callq 0x21e0
movq %rax, 0x30(%rsp)
movq %r13, %rdi
callq 0x21e0
movq %rax, 0x48(%rsp)
movq %r13, %rdi
callq 0x21e0
movq %rax, 0x28(%rsp)
leaq 0x30795(%rip), %rsi     # 0x58f49
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
movq 0x178(%rsp), %rdx
movq 0x180(%rsp), %rcx
xorl %eax, %eax
callq 0x2270
leaq 0x2ea26(%rip), %rsi     # 0x57200
movq %rbx, %rdi
callq 0x2220
movq %rax, 0x50(%rsp)
leaq 0x29561(%rip), %rdi     # 0x51d4f
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
movl %r15d, (%rsp)
movl %r15d, %r13d
testl %ebp, %ebp
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %r15
jle 0x2882c
leaq (,%r13,4), %rbx
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2110
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2110
movq %r13, 0x8(%rsp)
movl 0x4(%rsp), %r15d
movl %r15d, %r13d
testl %r15d, %r15d
jle 0x28862
leaq (,%r13,4), %rbx
movq 0x18(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2110
movq %r12, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2110
movq %r12, 0x58(%rsp)
movq 0x170(%rsp), %rbp
cmpl $0x0, (%rsp)
movq 0x60(%rsp), %rcx
jle 0x288b5
xorl %ebx, %ebx
movq (%rcx,%rbx,8), %rdi
movq %rbp, %rsi
movl %r15d, %edx
movl %r15d, %r12d
movq %rcx, %r15
callq 0x1085e
movq 0x68(%rsp), %rax
movq (%rax,%rbx,8), %rdi
movl (%rsp), %esi
callq 0x107f7
movq %r15, %rcx
movl %r12d, %r15d
movq 0x8(%rsp), %rax
incq %rbx
cmpq %rbx, %rax
jne 0x2887c
testl %r15d, %r15d
movq 0x38(%rsp), %r12
jle 0x288e4
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x1085e
movq (%r12,%rbx,8), %rdi
movl (%rsp), %esi
callq 0x107f7
incq %rbx
cmpq %rbx, %r13
jne 0x288c1
cmpl $0x0, (%rsp)
movq 0x58(%rsp), %r12
jle 0x28a6c
xorl %r12d, %r12d
testl %r15d, %r15d
jle 0x2895b
movq 0x60(%rsp), %rax
movq (%rax,%r12,8), %rbx
xorl %r15d, %r15d
movq (%r14,%r15,8), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
movl %r13d, %ecx
callq 0x107c4
mulss %xmm0, %xmm0
movq 0x10(%rsp), %rax
ucomiss (%rax,%r12,4), %xmm0
movq 0x40(%rsp), %rcx
jbe 0x28938
movss %xmm0, (%rax,%r12,4)
movl %r15d, (%rcx,%r12,4)
movq 0x18(%rsp), %rax
ucomiss (%rax,%r15,4), %xmm0
movq 0x48(%rsp), %rcx
jbe 0x28953
movss %xmm0, (%rax,%r15,4)
movl %r12d, (%rcx,%r15,4)
incq %r15
cmpq %r15, %r13
jne 0x28907
incq %r12
cmpq 0x8(%rsp), %r12
movl 0x4(%rsp), %r15d
jne 0x288f6
cmpl $0x0, (%rsp)
movq 0x58(%rsp), %r12
jle 0x28a6c
xorl %r14d, %r14d
movq 0x20(%rsp), %rbp
movq 0x38(%rsp), %rcx
testl %r15d, %r15d
jle 0x289e5
movq 0x68(%rsp), %rax
movq (%rax,%r14,8), %rbx
xorl %r15d, %r15d
movq (%rcx,%r15,8), %rsi
movq %rbx, %rdi
movl (%rsp), %edx
callq 0x10796
mulss %xmm0, %xmm0
ucomiss (%rbp,%r14,4), %xmm0
jbe 0x289c2
movss %xmm0, (%rbp,%r14,4)
movq 0x30(%rsp), %rax
movl %r15d, (%rax,%r14,4)
ucomiss (%r12,%r15,4), %xmm0
jbe 0x289d8
movss %xmm0, (%r12,%r15,4)
movq 0x28(%rsp), %rax
movl %r14d, (%rax,%r15,4)
incq %r15
cmpq %r15, %r13
movq 0x38(%rsp), %rcx
jne 0x28997
incq %r14
cmpq 0x8(%rsp), %r14
movl 0x4(%rsp), %r15d
jne 0x28986
leaq 0x30560(%rip), %rdi     # 0x58f5b
movl $0x27, %esi
movl $0x1, %edx
movq 0x50(%rsp), %r14
movq %r14, %rcx
callq 0x2290
leaq 0x3056a(%rip), %rdi     # 0x58f83
movl $0x21, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2290
cmpl $0x0, (%rsp)
jle 0x28b32
xorl %ebx, %ebx
movq 0x40(%rsp), %r15
movq 0x10(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%rbx,4), %xmm0
movl (%r15,%rbx,4), %ecx
movq %r14, %rdi
leaq 0x3054e(%rip), %rsi     # 0x58fa5
movl %ebx, %edx
movb $0x1, %al
callq 0x21a0
incq %rbx
cmpq %rbx, 0x8(%rsp)
jne 0x28a3c
jmp 0x28aa8
leaq 0x304e8(%rip), %rdi     # 0x58f5b
movl $0x27, %esi
movl $0x1, %edx
movq 0x50(%rsp), %r14
movq %r14, %rcx
callq 0x2290
leaq 0x304f2(%rip), %rdi     # 0x58f83
movl $0x21, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2290
movq 0x20(%rsp), %rbp
leaq 0x2f63c(%rip), %rdi     # 0x580eb
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2290
leaq 0x304ec(%rip), %rdi     # 0x58fb4
movl $0x27, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2290
leaq 0x304a2(%rip), %rdi     # 0x58f83
movl $0x21, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2290
movq %r14, %rax
cmpl $0x0, (%rsp)
movq 0x30(%rsp), %r15
jle 0x28b80
xorl %ebx, %ebx
xorps %xmm0, %xmm0
cvtss2sd (%rbp,%rbx,4), %xmm0
movl (%r15,%rbx,4), %ecx
movq %rax, %rdi
leaq 0x304c2(%rip), %rsi     # 0x58fdc
movl %ebx, %edx
movb $0x1, %al
callq 0x21a0
movq %r14, %rax
incq %rbx
cmpq %rbx, 0x8(%rsp)
jne 0x28b03
jmp 0x28b80
leaq 0x2f5b2(%rip), %rdi     # 0x580eb
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2290
leaq 0x30462(%rip), %rdi     # 0x58fb4
movl $0x27, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2290
leaq 0x30418(%rip), %rdi     # 0x58f83
movl $0x21, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2290
movq %r14, %rax
leaq 0x2f564(%rip), %rdi     # 0x580eb
movl $0x2, %esi
movl $0x1, %edx
movq %rax, %rcx
movq %rax, %rbx
callq 0x2290
leaq 0x30447(%rip), %rdi     # 0x58fea
movl $0x27, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2290
leaq 0x30456(%rip), %rdi     # 0x59012
movl $0x22, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2290
cmpl $0x0, 0x4(%rsp)
jle 0x28ca2
movq %rbx, %rax
xorl %ebx, %ebx
movq 0x48(%rsp), %r14
movq 0x18(%rsp), %rcx
xorps %xmm0, %xmm0
cvtss2sd (%rcx,%rbx,4), %xmm0
movl (%r14,%rbx,4), %ecx
movq %rax, %rdi
leaq 0x303de(%rip), %rsi     # 0x58fdc
movl %ebx, %edx
movq %rax, %r15
movb $0x1, %al
callq 0x21a0
movq %r15, %rax
incq %rbx
cmpq %rbx, %r13
jne 0x28be3
leaq 0x2f4cf(%rip), %rdi     # 0x580eb
movl $0x2, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x2290
leaq 0x30400(%rip), %rdi     # 0x59035
movl $0x27, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
leaq 0x303c4(%rip), %rdi     # 0x59012
movl $0x22, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
movq %r15, %rax
cmpl $0x0, 0x4(%rsp)
movq 0x28(%rsp), %r14
jle 0x28cf5
xorl %ebx, %ebx
xorps %xmm0, %xmm0
cvtss2sd (%r12,%rbx,4), %xmm0
movl (%r14,%rbx,4), %ecx
movq %rax, %rdi
leaq 0x30350(%rip), %rsi     # 0x58fdc
movl %ebx, %edx
movb $0x1, %al
callq 0x21a0
movq %r15, %rax
incq %rbx
cmpq %rbx, %r13
jne 0x28c75
jmp 0x28cf5
leaq 0x2f442(%rip), %rdi     # 0x580eb
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2290
leaq 0x30373(%rip), %rdi     # 0x59035
movl $0x27, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2290
leaq 0x30337(%rip), %rdi     # 0x59012
movl $0x22, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2290
movq 0x28(%rsp), %r14
movq %rbx, %rax
leaq 0x2f3ef(%rip), %rdi     # 0x580eb
movl $0x2, %esi
movl $0x1, %edx
movq %rax, %rcx
movq %rax, %rbx
callq 0x2290
movq %rbx, %rdi
callq 0x20c0
movq 0x10(%rsp), %rdi
callq 0x2050
movq 0x40(%rsp), %rdi
callq 0x2050
movq %rbp, %rdi
callq 0x2050
movq 0x30(%rsp), %rdi
callq 0x2050
movq 0x18(%rsp), %rdi
callq 0x2050
movq 0x48(%rsp), %rdi
callq 0x2050
movq %r12, %rdi
callq 0x2050
movq %r14, %rdi
callq 0x2050
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq