// File: /workspace/github_c_makefile_star2_O2/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), %r13
leaq 0x287b1(%rip), %rsi     # 0x54675
xorl %r12d, %r12d
leaq -0x260(%rbp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x2260
leaq 0x25271(%rip), %rsi     # 0x51150
movq %r14, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x1fdb6(%rip), %rdi     # 0x4bca7
movq %r14, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x28780(%rip), %rsi     # 0x54682
movq %r15, %rdi
movq %rbx, %rdx
movq %r13, %rbx
xorl %eax, %eax
callq 0x2190
cvtss2sd -0x2c(%rbp), %xmm0
leaq 0x28776(%rip), %rsi     # 0x54694
movq %r15, %rdi
movb $0x1, %al
callq 0x2190
movq %rsp, -0x70(%rbp)
movl (%r13), %eax
movq %rsp, %rdx
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
subq %rcx, %rdx
movq %rdx, %rsp
testl %eax, %eax
movl $0x0, %r9d
cmovgl %eax, %r9d
cmpq %r12, %r9
je 0x2bf60
andl $0x0, (%rdx,%r12,4)
incq %r12
jmp 0x2bf51
movq 0x30(%rbx), %r14
movq 0xb8(%rbx), %r10
movq 0xc0(%rbx), %r12
xorl %ecx, %ecx
movss 0x1f088(%rip), %xmm0    # 0x4b004
pushq $-0x1
popq %rsi
cmpq %r9, %rcx
je 0x2bfeb
xorl %r8d, %r8d
movl %esi, %edi
movaps %xmm0, %xmm1
cmpq %r8, %rax
je 0x2bfb5
cmpl $0x0, (%rdx,%r8,4)
jne 0x2bfb0
movss (%r14,%r8,4), %xmm2
ucomiss %xmm1, %xmm2
jb 0x2bfb0
cmpl $0x0, (%r12,%r8,4)
je 0x2bfb0
movl %r8d, %edi
movaps %xmm2, %xmm1
incq %r8
jmp 0x2bf8c
testl %edi, %edi
js 0x2bfcb
movl %edi, (%r10,%rcx,4)
movl %edi, %edi
movl $0x1, (%rdx,%rdi,4)
incq %rcx
jmp 0x2bf7f
xorl %edx, %edx
cmpq %rdx, %r9
je 0x2bfeb
cmpl $0x0, (%r12,%rdx,4)
jne 0x2bfe6
movslq %ecx, %rcx
movl %edx, (%r10,%rcx,4)
incl %ecx
cmpl %eax, %ecx
je 0x2bfeb
incq %rdx
jmp 0x2bfcd
movq %r10, -0x50(%rbp)
movq %r9, -0x58(%rbp)
leaq 0x361a2(%rip), %rax     # 0x6219c
movss (%rax), %xmm2
cvtss2sd %xmm2, %xmm0
movsd 0x27bf6(%rip), %xmm1    # 0x53c00
divsd %xmm0, %xmm1
mulss %xmm2, %xmm2
cvtss2sd %xmm2, %xmm2
divsd 0x27bea(%rip), %xmm2    # 0x53c08
leaq 0x2867f(%rip), %rsi     # 0x546a4
movq %r15, %rdi
movb $0x3, %al
callq 0x2190
leaq 0x286cf(%rip), %rdi     # 0x54705
pushq $0x18
popq %rsi
pushq $0x1
popq %r13
movq %r13, %rdx
movq %r15, %rcx
callq 0x2280
leaq 0x286cf(%rip), %rdi     # 0x5471e
pushq $0xb
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2280
cmpl $0x0, -0x34(%rbp)
je 0x2c078
leaq 0x286c0(%rip), %rdi     # 0x5472a
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2280
leaq 0x286c2(%rip), %rdi     # 0x54741
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2280
movq 0x78(%rbx), %rax
movq %rax, -0xc8(%rbp)
testq %rax, %rax
je 0x2c0b2
leaq 0x286b0(%rip), %rdi     # 0x54754
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2280
movq 0x70(%rbx), %rax
movq %rax, -0xc0(%rbp)
testq %rax, %rax
je 0x2c0d7
leaq 0x28695(%rip), %rdi     # 0x5475e
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2280
cmpl $0x0, -0x30(%rbp)
je 0x2c0f2
leaq 0x28686(%rip), %rdi     # 0x5476a
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2280
movq 0x98(%rbx), %rax
movq %rax, -0x60(%rbp)
movss (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x2c10c
jnp 0x2c136
leaq 0x28662(%rip), %rdi     # 0x54775
pushq $0x1a
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2280
leaq 0x28668(%rip), %rdi     # 0x54790
pushq $0x23
popq %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2280
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0x2140
movq 0x18(%rbx), %rax
movq %rax, -0xb8(%rbp)
movq 0x28(%rbx), %rax
movq %rax, -0xb0(%rbp)
movq 0x88(%rbx), %rax
movq %rax, -0x90(%rbp)
movq 0x68(%rbx), %rax
movq %rax, -0xa8(%rbp)
movq 0x60(%rbx), %rax
movq %rax, -0x88(%rbp)
movq 0xa0(%rbx), %rax
movq %rax, -0x80(%rbp)
leaq 0xe0(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq 0xb0(%rbx), %rax
movq %rax, -0x78(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
xorl %ebx, %ebx
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %r12, -0xa0(%rbp)
cmpq %rbx, %rax
je 0x2c40a
movslq (%rcx,%rbx,4), %r13
testq %r13, %r13
js 0x2c402
cvtss2sd (%r14,%r13,4), %xmm2
cmpl $0x0, (%r12,%r13,4)
movaps %xmm2, %xmm0
jne 0x2c200
pushq $0x23
popq %rdi
movq %r15, %rsi
movsd %xmm2, -0x98(%rbp)
callq 0x2140
movsd -0x98(%rbp), %xmm2
cvtss2sd (%r14,%r13,4), %xmm0
movsd -0x68(%rbp), %xmm1
addsd %xmm2, %xmm1
movq %r15, %rdi
leaq 0x285a1(%rip), %rsi     # 0x547b4
movl %r13d, %edx
movsd %xmm1, -0x68(%rbp)
movb $0x2, %al
callq 0x2190
movq -0xb0(%rbp), %rax
cvtss2sd (%rax,%r13,4), %xmm0
movq %r15, %rdi
leaq 0x28598(%rip), %rsi     # 0x547d1
movb $0x1, %al
callq 0x2190
cmpl $0x0, -0x34(%rbp)
je 0x2c271
movq -0x90(%rbp), %rax
movss (%rax,%r13,4), %xmm0
cvtss2sd %xmm0, %xmm1
mulss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x28560(%rip), %rsi     # 0x547ca
movb $0x2, %al
callq 0x2190
movq -0xb8(%rbp), %rax
movss (%rax,%r13,4), %xmm0
mulss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x1edb9(%rip), %xmm0    # 0x4b048
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x2853c(%rip), %rsi     # 0x547d9
movb $0x1, %al
callq 0x2190
movq -0xa8(%rbp), %rax
cvtss2sd (%rax,%r13,4), %xmm0
movq %r15, %rdi
leaq 0x28526(%rip), %r12     # 0x547e1
movq %r12, %rsi
movb $0x1, %al
callq 0x2190
movq -0xc8(%rbp), %rax
cvtss2sd (%rax,%r13,4), %xmm0
movq %r15, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x2190
movq -0xc0(%rbp), %rax
cvtss2sd (%rax,%r13,4), %xmm0
movq %r15, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x2190
cmpl $0x0, -0x30(%rbp)
je 0x2c31d
movq -0x88(%rbp), %rax
cvtss2sd (%rax,%r13,4), %xmm0
movq %r15, %rdi
leaq 0x2b409(%rip), %rsi     # 0x5771f
movb $0x1, %al
callq 0x2190
movq -0x60(%rbp), %rax
movss (%rax), %xmm0
ucomiss 0x1ece0(%rip), %xmm0    # 0x4b00c
movq -0xa0(%rbp), %r12
jne 0x2c33b
jnp 0x2c3ef
movq -0x80(%rbp), %rax
movss (%rax,%r13,4), %xmm0
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
jbe 0x2c35f
movq -0x40(%rbp), %rax
movss (%rax,%r13,4), %xmm1
ucomiss %xmm2, %xmm1
pushq $0x1
popq %rdx
ja 0x2c374
ucomiss %xmm0, %xmm2
jbe 0x2c372
movq -0x40(%rbp), %rax
ucomiss (%rax,%r13,4), %xmm2
pushq $0x1
popq %rdx
ja 0x2c374
xorl %edx, %edx
andps 0x24eb5(%rip), %xmm0    # 0x51230
cvtss2sd %xmm0, %xmm0
movq %r15, %rdi
leaq 0x28460(%rip), %rsi     # 0x547e9
movb $0x1, %al
callq 0x2190
xorps %xmm2, %xmm2
movq -0x60(%rbp), %rax
movss (%rax,%r13,4), %xmm0
ucomiss %xmm2, %xmm0
jbe 0x2c3b4
movq -0x40(%rbp), %rax
movss (%rax,%r13,4), %xmm1
ucomiss %xmm2, %xmm1
pushq $0x1
popq %rdx
ja 0x2c3c9
ucomiss %xmm0, %xmm2
jbe 0x2c3c7
movq -0x40(%rbp), %rax
ucomiss (%rax,%r13,4), %xmm2
pushq $0x1
popq %rdx
ja 0x2c3c9
xorl %edx, %edx
andps 0x24e60(%rip), %xmm0    # 0x51230
cvtss2sd %xmm0, %xmm0
movq -0x78(%rbp), %rax
cvtss2sd (%rax,%r13,4), %xmm1
movq %r15, %rdi
leaq 0x2840a(%rip), %rsi     # 0x547f2
movb $0x2, %al
callq 0x2190
pushq $0xa
popq %rdi
movq %r15, %rsi
callq 0x2140
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
incq %rbx
jmp 0x2c1b9
movq %r15, %rdi
callq 0x20c0
movq -0x70(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq