// File: /workspace/github_c_makefile_star2_O1/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 0x2b3b8(%rip), %rsi     # 0x5a771
leaq -0x260(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2260
leaq 0x27e6f(%rip), %rsi     # 0x57240
movq %r14, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x228f8(%rip), %rdi     # 0x51cdb
movq %r14, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x2b38a(%rip), %rsi     # 0x5a77e
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2190
xorps %xmm0, %xmm0
cvtss2sd -0x2c(%rbp), %xmm0
leaq 0x2b380(%rip), %rsi     # 0x5a790
movq %r15, %rdi
movb $0x1, %al
callq 0x2190
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 0x2f44e
leaq (,%r13,4), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2110
movq 0x30(%r12), %r14
testl %r13d, %r13d
jle 0x2f4e4
movq 0xb8(%r12), %rax
movq 0xc0(%r12), %rcx
xorl %edx, %edx
movss 0x21b8e(%rip), %xmm0    # 0x51004
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edi, %edi
movaps %xmm0, %xmm1
cmpl $0x0, (%rbx,%rdi,4)
jne 0x2f49c
movss (%r14,%rdi,4), %xmm2
ucomiss %xmm1, %xmm2
jb 0x2f49c
cmpl $0x0, (%rcx,%rdi,4)
je 0x2f49c
movl %edi, %esi
movaps %xmm2, %xmm1
incq %rdi
cmpq %rdi, %r13
jne 0x2f480
testl %esi, %esi
js 0x2f4b6
movl %esi, (%rax,%rdx,4)
movl %esi, %edi
movl $0x1, (%rbx,%rdi,4)
jmp 0x2f4d8
xorl %edi, %edi
movl %edx, %r8d
cmpl $0x0, (%rcx,%rdi,4)
jne 0x2f4d0
movslq %r8d, %r8
movl %edi, (%rax,%r8,4)
incl %r8d
cmpl %r13d, %r8d
je 0x2f4d8
incq %rdi
cmpq %rdi, %r13
jne 0x2f4bb
testl %esi, %esi
js 0x2f4e4
incq %rdx
cmpq %r13, %rdx
jne 0x2f476
leaq 0x37cb1(%rip), %rax     # 0x6719c
movss (%rax), %xmm2
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movsd 0x2a7fa(%rip), %xmm1    # 0x59cf8
divsd %xmm0, %xmm1
mulss %xmm2, %xmm2
cvtss2sd %xmm2, %xmm2
divsd 0x2a7ee(%rip), %xmm2    # 0x59d00
leaq 0x2b287(%rip), %rsi     # 0x5a7a0
movq %r15, %rdi
movb $0x3, %al
callq 0x2190
leaq 0x2b2d7(%rip), %rdi     # 0x5a801
movl $0x18, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
leaq 0x2b2d7(%rip), %rdi     # 0x5a81a
movl $0xb, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
cmpl $0x0, -0x34(%rbp)
je 0x2f574
leaq 0x2b2c4(%rip), %rdi     # 0x5a826
movl $0x16, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
leaq 0x2b2c2(%rip), %rdi     # 0x5a83d
movl $0x12, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
movq 0x78(%r12), %rax
movq %rax, -0xc0(%rbp)
testq %rax, %rax
je 0x2f5b7
leaq 0x2b2ab(%rip), %rdi     # 0x5a850
movl $0x9, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
movq 0x70(%r12), %rax
movq %rax, -0xb8(%rbp)
testq %rax, %rax
je 0x2f5e1
leaq 0x2b28b(%rip), %rdi     # 0x5a85a
movl $0xb, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
cmpl $0x0, -0x30(%rbp)
je 0x2f600
leaq 0x2b278(%rip), %rdi     # 0x5a866
movl $0xa, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
movq 0x98(%r12), %rax
movq %rax, -0x50(%rbp)
movss (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x2f61b
jnp 0x2f64d
leaq 0x2b24f(%rip), %rdi     # 0x5a871
movl $0x1a, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
leaq 0x2b251(%rip), %rdi     # 0x5a88c
movl $0x23, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x2280
movl $0xa, %edi
movq %r15, %rsi
callq 0x2140
testl %r13d, %r13d
jle 0x2f96c
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 0x2f960
xorps %xmm0, %xmm0
cvtss2sd (%r14,%r12,4), %xmm0
movq -0xb0(%rbp), %rax
cmpl $0x0, (%rax,%r12,4)
jne 0x2f73a
movl $0x23, %edi
movq %r15, %rsi
movsd %xmm0, -0x88(%rbp)
callq 0x2140
movsd -0x88(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd (%r14,%r12,4), %xmm0
movq %r15, %rdi
leaq 0x2b15a(%rip), %rsi     # 0x5a8b0
movl %r12d, %edx
movsd %xmm1, -0x58(%rbp)
movb $0x2, %al
callq 0x2190
movq -0xa0(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r15, %rdi
leaq 0x2b14e(%rip), %rsi     # 0x5a8cd
movb $0x1, %al
callq 0x2190
cmpl $0x0, -0x34(%rbp)
je 0x2f7b7
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 0x2b116(%rip), %rsi     # 0x5a8c6
movb $0x2, %al
callq 0x2190
movq -0xa8(%rbp), %rax
movss (%rax,%r12,4), %xmm0
mulss -0x44(%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0x21868(%rip), %xmm0    # 0x51040
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x2b0ef(%rip), %rsi     # 0x5a8d5
movb $0x1, %al
callq 0x2190
movq -0x98(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r15, %rdi
movq %r15, %r14
leaq 0x2b0d3(%rip), %r15     # 0x5a8dd
movq %r15, %rsi
movb $0x1, %al
callq 0x2190
movq -0xc0(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r14, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x2190
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 0x2190
cmpl $0x0, -0x30(%rbp)
je 0x2f875
movq -0x78(%rbp), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r12,4), %xmm0
movq %r15, %rdi
leaq 0x2df71(%rip), %rsi     # 0x5d7df
movb $0x1, %al
callq 0x2190
movq -0x50(%rbp), %rax
movss (%rax), %xmm0
ucomiss 0x21788(%rip), %xmm0    # 0x5100c
movq -0x90(%rbp), %r14
jne 0x2f893
jnp 0x2f953
movq -0x70(%rbp), %rax
movss (%rax,%r12,4), %xmm0
xorpd %xmm2, %xmm2
ucomiss %xmm2, %xmm0
jbe 0x2f8ba
movq -0x40(%rbp), %rax
movss (%rax,%r12,4), %xmm1
movl $0x1, %edx
ucomiss %xmm2, %xmm1
ja 0x2f8d1
ucomiss %xmm0, %xmm2
jbe 0x2f8cf
movl $0x1, %edx
movq -0x40(%rbp), %rax
ucomiss (%rax,%r12,4), %xmm2
ja 0x2f8d1
xorl %edx, %edx
andps 0x27a48(%rip), %xmm0    # 0x57320
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x2afff(%rip), %rsi     # 0x5a8e5
movb $0x1, %al
callq 0x2190
xorps %xmm2, %xmm2
movq -0x50(%rbp), %rax
movss (%rax,%r12,4), %xmm0
ucomiss %xmm2, %xmm0
jbe 0x2f913
movq -0x40(%rbp), %rax
movss (%rax,%r12,4), %xmm1
movl $0x1, %edx
ucomiss %xmm2, %xmm1
ja 0x2f92a
ucomiss %xmm0, %xmm2
jbe 0x2f928
movl $0x1, %edx
movq -0x40(%rbp), %rax
ucomiss (%rax,%r12,4), %xmm2
ja 0x2f92a
xorl %edx, %edx
andps 0x279ef(%rip), %xmm0    # 0x57320
cvtss2sd %xmm0, %xmm0
movq -0x68(%rbp), %rax
xorps %xmm1, %xmm1
cvtss2sd (%rax,%r12,4), %xmm1
movq %r15, %rdi
leaq 0x2afa2(%rip), %rsi     # 0x5a8ee
movb $0x2, %al
callq 0x2190
movl $0xa, %edi
movq %r15, %rsi
callq 0x2140
incq %rbx
cmpq %rbx, %r13
jne 0x2f6f2
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