// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/confchange.c
// Function: Print_modes_confchange
void Print_modes_confchange(char *name2, char *nameout2,
			    struct Normal_Mode NM, struct Tors Diff,
			    int ANM, float M_sqrt, float rmsd,
			    int anharmonic,float xkappa)
{
  /***************** Normal modes confchange ********************/

  char nameout[400];
  sprintf(nameout, "%s.Modes.dat", nameout2);
  FILE *file_out=fopen(nameout, "w");
  printf("Writing %s\n", nameout);
  fprintf(file_out, "# Conf.change %s\n", name2);
  fprintf(file_out, "# kappa=  %.3f\n",xkappa);

  /*float *sigma2;
  if(anharmonic){
    fprintf(file_out, "# Omega2 corrected for anharmonicity\n");
    sigma2=NM.sigma2_anhar;
  }else{
    sigma2=NM.sigma2;
    }*/


  // Compute confchange and copy on normal modes

  // Sort on c2
  int sorted [NM.N], i, k;
  for(i=0;i<NM.N; i++)sorted[i]=0;
  float *c2=NM.confchange2;
  for(k=0; k<NM.N; k++){
    int ik=-1; float cmax=-1; 
    for (i=0;i<NM.N; i++){
      if((sorted[i]==0)&&(c2[i]>=cmax)&&(NM.select[i])){
	cmax=c2[i]; ik=i;
      }
    }
    if(ik>=0){
      NM.sort[k]=ik; sorted[ik]=1;
    }else{ // nothing found
      ik=k;
      for (i=0;i<NM.N; i++){
	if(NM.select[i]==0){NM.sort[ik]=i; ik++; if(ik==NM.N)break;}
      }
      break;
    }
  }

  // Print lines
  fprintf(file_out, "# Frequency reported in internal units: %.3f ps^(-1),"
	  " kT/h/ is %.3g internal units (om-2)= %.3g\n",
	  Freq_unit, 0.385/Freq_unit, Freq_unit*Freq_unit/0.1482);
  fprintf(file_out,"# mode pc_confch cumul  ");
  fprintf(file_out,"om-2(harm) ");
  if(anharmonic)fprintf(file_out, "om-2(corr) om-2(anha) ");
  fprintf(file_out,"   RMSD  Coll_cart");
  if(NM.MW_Tors_coll)fprintf(file_out, "  Coll_MW");
  if(NM.Tors_coll)fprintf(file_out, "  Coll_tors");

  //fprintf(file_out, "# mode\tContr_to_confchange\tCumulative");
  //if(anharmonic)fprintf(file_out, "\tOmega^(-2)_anharm");
  //fprintf(file_out, "\tOmega^(-2) RMSD ");
  //fprintf(file_out, "\tColl.(cart)\tColl.(MWtors)\tColl.(tors)");
  if(ANM)fprintf(file_out, "\tTors_frac"); //force_coeff
  if(NM.Anharmonicity[0]){
    fprintf(file_out, "\tAnharm_Str Str_confchange");
    fprintf(file_out, "\tAnharm_Ene\tEne_confchange\tMax_RMSD");
  }
  fprintf(file_out, "\n");

  //float N_sqrt=sqrt(NM.N_Cart/3);
  double sum_coeff_C=0; //sum_B=0;
  for(k=0; k<NM.N; k++){
    int ik=NM.sort[k]; if(ik<0)continue;
    sum_coeff_C+=c2[ik];
    //sum_B+=NM.sigma2[ik];
    if(NM.select[ik]==0)fprintf(file_out,"#");

    fprintf(file_out, "%6d  %8.3g %5.3f     ",ik, c2[ik], sum_coeff_C);
    fprintf(file_out, "%7.4g  ",NM.sigma2[ik]);
    if(anharmonic)fprintf(file_out,"%7.4g  %7.4g  ",
			  xkappa*NM.sigma2_anhar[ik],NM.sigma2_anhar[ik]);
    fprintf(file_out, "  %8.3g", 1./(M_sqrt*NM.omega[ik]));
    fprintf(file_out, "  %5.3f", NM.Cart_coll[ik]);
    fprintf(file_out, "  %5.3f", NM.MW_Tors_coll[ik]);
    fprintf(file_out, "  %5.3f", NM.Tors_coll[ik]);
	    
    if(ANM)fprintf(file_out,"\t%.3f",NM.Tors_frac[ik]);
    if(NM.Anharmonicity[0]){
      int dir;
      if(((NM.Anharm_struct[ik]>0)&&(Diff.coeff[ik]>0))||
	 ((NM.Anharm_struct[ik]<0)&&(Diff.coeff[ik]<0))){dir=1;}
      else{dir=0;}
      fprintf(file_out,"\t%.3f\t%d",
	      fabs(NM.Anharm_struct[ik]),dir);
      if(((NM.Anharmonicity[ik]>0)&&(Diff.coeff[ik]>0))||
	 ((NM.Anharmonicity[ik]<0)&&(Diff.coeff[ik]<0))){dir=1;}
      else{dir=0;}
      fprintf(file_out,"\t%.3f\t%d\t%.2f",
	      fabs(NM.Anharmonicity[ik]),dir, NM.Max_RMSD[ik]);
    }
    fprintf(file_out, "\n");
  }
  //free(c2);
  fclose(file_out);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movss %xmm2, -0x2c(%rbp)
movl %ecx, -0x34(%rbp)
movss %xmm0, -0x44(%rbp)
movl %edx, -0x30(%rbp)
movq %rsi, %rdx
movq %rdi, %rbx
leaq 0x10(%rbp), %r12
leaq 0x2b630(%rip), %rsi     # 0x5a715
leaq -0x260(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2270
leaq 0x28103(%rip), %rsi     # 0x57200
movq %r14, %rdi
callq 0x2220
movq %rax, %r15
leaq 0x22c40(%rip), %rdi     # 0x51d4f
movq %r14, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x2b602(%rip), %rsi     # 0x5a722
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x21a0
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
leaq 0x2b5f8(%rip), %rsi     # 0x5a734
movq %r15, %rdi
movb $0x1, %al
callq 0x21a0
movq %rsp, -0x60(%rbp)
movl (%r12), %r13d
movq %rsp, %rbx
leaq 0xf(,%r13,4), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
testl %r13d, %r13d
jle 0x2f1ed
leaq (,%r13,4), %rdx
movq %r12, %r14
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2110
movq %r14, %rcx
movq 0x30(%r14), %r14
movq 0xb8(%rcx), %rax
movq %rcx, %rdi
movq 0xc0(%rcx), %rcx
movss 0x21f6c(%rip), %xmm0    # 0x51110
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %esi, %esi
movaps %xmm0, %xmm1
cmpl $0x0, (%rbx,%rsi,4)
jne 0x2f1ca
movss (%r14,%rsi,4), %xmm2
ucomiss %xmm1, %xmm2
jb 0x2f1ca
cmpl $0x0, (%rcx,%rsi,4)
je 0x2f1ca
movl %esi, %edx
movaps %xmm2, %xmm1
incq %rsi
cmpq %rsi, %r13
jne 0x2f1ae
testl %edx, %edx
js 0x2f1f4
movl %edx, (%rax,%r12,4)
movl %edx, %edx
movl $0x1, (%rbx,%rdx,4)
incq %r12
cmpq %r13, %r12
jne 0x2f1a4
jmp 0x2f213
movq 0x30(%r12), %r14
jmp 0x2f216
xorl %edx, %edx
cmpl $0x0, (%rcx,%rdx,4)
jne 0x2f20b
movslq %r12d, %r12
movl %edx, (%rax,%r12,4)
incl %r12d
cmpl %r13d, %r12d
je 0x2f213
incq %rdx
cmpq %rdx, %r13
jne 0x2f1f6
movq %rdi, %r12
leaq 0x37f7f(%rip), %rax     # 0x6719c
movss (%rax), %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x2aa70(%rip), %xmm1    # 0x59ca0
divsd %xmm0, %xmm1
mulss %xmm2, %xmm2
cvtss2sd %xmm2, %xmm2
divsd 0x2aa64(%rip), %xmm2    # 0x59ca8
leaq 0x2b4f9(%rip), %rsi     # 0x5a744
movq %r15, %rdi
movb $0x3, %al
callq 0x21a0
leaq 0x2b549(%rip), %rdi     # 0x5a7a5
movl $0x18, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
leaq 0x2b549(%rip), %rdi     # 0x5a7be
movl $0xb, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
cmpl $0x0, -0x34(%rbp)
je 0x2f2a6
leaq 0x2b536(%rip), %rdi     # 0x5a7ca
movl $0x16, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
leaq 0x2b534(%rip), %rdi     # 0x5a7e1
movl $0x12, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
movq 0x78(%r12), %rax
movq %rax, -0xc0(%rbp)
testq %rax, %rax
je 0x2f2e9
leaq 0x2b51d(%rip), %rdi     # 0x5a7f4
movl $0x9, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
movq 0x70(%r12), %rax
movq %rax, -0xb8(%rbp)
testq %rax, %rax
je 0x2f313
leaq 0x2b4fd(%rip), %rdi     # 0x5a7fe
movl $0xb, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
cmpl $0x0, -0x30(%rbp)
je 0x2f332
leaq 0x2b4ea(%rip), %rdi     # 0x5a80a
movl $0xa, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
movq 0x98(%r12), %rax
movq %rax, -0x50(%rbp)
movss (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x2f34d
jnp 0x2f37f
leaq 0x2b4c1(%rip), %rdi     # 0x5a815
movl $0x1a, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
leaq 0x2b4c3(%rip), %rdi     # 0x5a830
movl $0x23, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2290
movl $0xa, %edi
movq %r15, %rsi
callq 0x2140
testl %r13d, %r13d
jle 0x2f6a0
leaq 0xe0(%rbp), %rax
movq 0xb8(%r12), %rcx
movq %rcx, -0xc8(%rbp)
movq 0xc0(%r12), %rcx
movq %rcx, -0xb0(%rbp)
movq 0x18(%r12), %rcx
movq %rcx, -0xa8(%rbp)
movq 0x28(%r12), %rcx
movq %rcx, -0xa0(%rbp)
movq 0x88(%r12), %rcx
movq %rcx, -0x80(%rbp)
movq 0x68(%r12), %rcx
movq %rcx, -0x98(%rbp)
movq 0x60(%r12), %rcx
movq %rcx, -0x78(%rbp)
movq 0xa0(%r12), %rcx
movq %rcx, -0x70(%rbp)
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq 0xb0(%r12), %rax
movq %rax, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
xorl %ebx, %ebx
movq %r14, -0x90(%rbp)
movq -0xc8(%rbp), %rax
movslq (%rax,%rbx,4), %r12
testq %r12, %r12
js 0x2f694
xorps %xmm2, %xmm2
cvtss2sd (%r14,%r12,4), %xmm2
movq -0xb0(%rbp), %rax
cmpl $0x0, (%rax,%r12,4)
movaps %xmm2, %xmm0
jne 0x2f478
movl $0x23, %edi
movq %r15, %rsi
movsd %xmm2, -0x88(%rbp)
callq 0x2140
movsd -0x88(%rbp), %xmm2
xorps %xmm0, %xmm0
cvtss2sd (%r14,%r12,4), %xmm0
movsd -0x58(%rbp), %xmm1
addsd %xmm2, %xmm1
movq %r15, %rdi
leaq 0x2b3c9(%rip), %rsi     # 0x5a854
movl %r12d, %edx
movsd %xmm1, -0x58(%rbp)
movb $0x2, %al
callq 0x21a0
movq -0xa0(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r15, %rdi
leaq 0x2b3bd(%rip), %rsi     # 0x5a871
movb $0x1, %al
callq 0x21a0
cmpl $0x0, -0x34(%rbp)
je 0x2f4ec
movq -0x80(%rbp), %rax
movss (%rax,%r12,4), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x2b385(%rip), %rsi     # 0x5a86a
movb $0x2, %al
callq 0x21a0
movq -0xa8(%rbp), %rax
movss (%rax,%r12,4), %xmm0
mulss -0x44(%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0x21c3b(%rip), %xmm0    # 0x51148
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x2b35e(%rip), %rsi     # 0x5a879
movb $0x1, %al
callq 0x21a0
movq -0x98(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r15, %rdi
movq %r15, %r14
leaq 0x2b342(%rip), %r15     # 0x5a881
movq %r15, %rsi
movb $0x1, %al
callq 0x21a0
movq -0xc0(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r14, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x21a0
movq -0xb8(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r14, %rdi
movq %r15, %rsi
movq %r14, %r15
movb $0x1, %al
callq 0x21a0
cmpl $0x0, -0x30(%rbp)
je 0x2f5aa
movq -0x78(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r15, %rdi
leaq 0x2e20c(%rip), %rsi     # 0x5d7af
movb $0x1, %al
callq 0x21a0
movq -0x50(%rbp), %rax
movss (%rax), %xmm0
ucomiss 0x21b5f(%rip), %xmm0    # 0x51118
movq -0x90(%rbp), %r14
jne 0x2f5c8
jnp 0x2f687
movq -0x70(%rbp), %rax
movss (%rax,%r12,4), %xmm0
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
jbe 0x2f5ee
movq -0x40(%rbp), %rax
movss (%rax,%r12,4), %xmm1
movl $0x1, %edx
ucomiss %xmm2, %xmm1
ja 0x2f605
ucomiss %xmm0, %xmm2
jbe 0x2f603
movl $0x1, %edx
movq -0x40(%rbp), %rax
ucomiss (%rax,%r12,4), %xmm2
ja 0x2f605
xorl %edx, %edx
andps 0x27cd4(%rip), %xmm0    # 0x572e0
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x2b26f(%rip), %rsi     # 0x5a889
movb $0x1, %al
callq 0x21a0
xorps %xmm2, %xmm2
movq -0x50(%rbp), %rax
movss (%rax,%r12,4), %xmm0
ucomiss %xmm2, %xmm0
jbe 0x2f647
movq -0x40(%rbp), %rax
movss (%rax,%r12,4), %xmm1
movl $0x1, %edx
ucomiss %xmm2, %xmm1
ja 0x2f65e
ucomiss %xmm0, %xmm2
jbe 0x2f65c
movl $0x1, %edx
movq -0x40(%rbp), %rax
ucomiss (%rax,%r12,4), %xmm2
ja 0x2f65e
xorl %edx, %edx
andps 0x27c7b(%rip), %xmm0    # 0x572e0
cvtss2sd %xmm0, %xmm0
movq -0x68(%rbp), %rax
xorps %xmm1, %xmm1
cvtss2sd (%rax,%r12,4), %xmm1
movq %r15, %rdi
leaq 0x2b212(%rip), %rsi     # 0x5a892
movb $0x2, %al
callq 0x21a0
movl $0xa, %edi
movq %r15, %rsi
callq 0x2140
incq %rbx
cmpq %rbx, %r13
jne 0x2f424
movq %r15, %rdi
callq 0x20c0
movq -0x60(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq