// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/simulation.c
// Function: Torsional_confchange_1angle_old
void Torsional_confchange_1angle_old(struct bond *bonds, int natoms1,
				     int naxes, struct Reference Ref1,
				     float *coord_ref_1, float *coord_ref_2,
				     int N_Cart, atom *atoms1,FILE *file_rmsd,
				     struct Para_simul Para_simul)
{
  printf("Changing %d internal coordinates one by one\n", naxes);
  fprintf(file_rmsd, "# Changing %d internal coordinates one by one\n",naxes);

  float coord_all[3*natoms1];
  Put_coord(coord_all, bonds, natoms1);
  struct bond bonds2[natoms1];
  int N_ref=Ref1.N_ref;
  float coord1[N_Cart], coord2[N_Cart];
  Write_ref_coord(coord1, N_ref, coord_all, Ref1.atom_num);
  Write_ref_coord(coord2, N_ref, coord_all, Ref1.atom_num);
  float *coord_new=coord1, *coord_old=coord2;
  
  float *mass_ref=Ref1.mass_atom;
  float RMSD_opt=rmsd_mclachlan_f(coord_ref_2, coord_new, mass_ref, N_ref);
  float RMSD_kf, RMSD_ki, RMSD_step, Ene;

  for(int iter=0; iter<Para_simul.NSTEPS; iter++){ //ITER_MAX_1
    
    int i, j;
    double diff_tors[naxes]; for(j=0; j<naxes; j++)diff_tors[j]=0;
    float RMSD_min=10000000;
    int i_min=-1, dir_min=0, accept=1;

    for(i=0; i<naxes; i++){

      // Change internal coordinate i in positive direction
      diff_tors[i]=Para_simul.ANGLE;
      Copy_bonds(bonds2, bonds, natoms1);
      Build_up(bonds2, natoms1, diff_tors, naxes);
      Put_coord(coord_all, bonds2, natoms1);
      Write_ref_coord(coord_new, N_ref, coord_all, Ref1.atom_num);
      RMSD_kf=rmsd_mclachlan_f(coord_ref_2, coord_new, mass_ref, N_ref);
      if(RMSD_kf<RMSD_min){i_min=i; dir_min=1; RMSD_min=RMSD_kf;}

      // Change internal coordinate i in negative direction
      diff_tors[i]=-Para_simul.ANGLE;
      Copy_bonds(bonds2, bonds, natoms1);
      Build_up(bonds2, natoms1, diff_tors, naxes);
      Put_coord(coord_all, bonds2, natoms1);
      Write_ref_coord(coord_new, N_ref, coord_all, Ref1.atom_num);
      RMSD_kf=rmsd_mclachlan_f(coord_ref_2, coord_new, mass_ref, N_ref);
      if(RMSD_kf<RMSD_min){i_min=i; dir_min=-1; RMSD_min=RMSD_kf;}

      diff_tors[i]=0;
    }

    if(i_min<0){
      printf("\nERROR, internal coordinate %d does not exist\n", i_min);
      return;
    }

    float d_max=Para_simul.ANGLE;
    RMSD_kf=1000;
    while(1){
      diff_tors[i_min]=dir_min*d_max;
      Copy_bonds(bonds2, bonds, natoms1);
      Build_up(bonds2, natoms1, diff_tors, naxes);
      Put_coord(coord_all, bonds2, natoms1);
      Write_ref_coord(coord_new, N_ref, coord_all, Ref1.atom_num);
      RMSD_kf=rmsd_mclachlan_f(coord_ref_2, coord_new, mass_ref, N_ref);
      RMSD_step=rmsd_mclachlan_f(coord_old, coord_new, mass_ref, N_ref);
      RMSD_ki=rmsd_mclachlan_f(coord_ref_1, coord_new, mass_ref, N_ref);
      printf("iter= %d RMSD_kf= %.3f step= %.3f angle= %.2g\n",
	     iter+1, RMSD_kf, RMSD_step, d_max);
      Ene=Energy_clashes(coord_all, natoms1);
      fprintf(file_rmsd, "%.3f\t%.3f\t%.3f\t%.2g\t%.2g\t%d\n",
	      RMSD_ki, RMSD_kf, RMSD_step, d_max, Ene, accept);
      fflush(file_rmsd);
      if(isnan(RMSD_step)||isnan(RMSD_kf)||isnan(RMSD_ki))return;

      if(RMSD_kf < RMSD_opt){
	if(RMSD_step<Para_simul.STEP_MAX){
	  RMSD_opt=RMSD_kf; accept=1;
	  Copy_bonds(bonds, bonds2, natoms1);
	  break;
	}else{
	  accept=0; d_max*=0.98*(Para_simul.STEP_MAX/RMSD_step);
	  if(RMSD_step<Para_simul.STEP_MIN)break;
	}
      }else{
	if(RMSD_step<Para_simul.STEP_MIN)break;
	accept=0; d_max/=2;  // Reduce step
	printf("Reducing max. step to %.2g \n", d_max);
      }
      if(d_max<0.0001)break;
    }

    if((accept==0)||(RMSD_kf < RMSD_TOL))break;


  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %r9d, %r12d
movq %r8, -0x80(%rbp)
movq %rcx, -0xe8(%rbp)
movl %edx, %r15d
movl %edx, -0x40(%rbp)
movl %esi, %r13d
movq %rdi, %r14
movq 0x48(%rbp), %rbx
leaq 0x22658(%rip), %rdi     # 0x55445
movl %edx, %esi
xorl %eax, %eax
callq 0x20f0
leaq 0x22646(%rip), %rsi     # 0x55443
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2190
leal (%r13,%r13,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movq %rbx, %rdi
movq %r14, -0x78(%rbp)
movq %r14, %rsi
movl %r13d, %edx
callq 0x2f358
movq %r13, -0x98(%rbp)
movl %r13d, %eax
movq %rsp, %rcx
imulq $0xc0, %rax, %rax
subq %rax, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
movl 0x10(%rbp), %r14d
movl %r12d, %eax
movq %rsp, %r13
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
movq 0x38(%rbp), %r12
movq %r13, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x2f9b8
movq %r15, -0xe0(%rbp)
movq %r15, %rdi
movl %r14d, %esi
movq %rbx, -0xd0(%rbp)
movq %rbx, %rdx
movq %r12, -0xa8(%rbp)
movq %r12, %rcx
callq 0x2f9b8
movq 0x20(%rbp), %rdx
movq -0x80(%rbp), %rdi
movq %r13, -0xc8(%rbp)
movq %r13, %rsi
movq %rdx, -0xa0(%rbp)
movl %r14d, -0x50(%rbp)
movl %r14d, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
movl 0x60(%rbp), %ecx
movl -0x40(%rbp), %esi
movl %esi, %eax
movss 0x5c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm0
movsd %xmm0, -0x110(%rbp)
movaps 0x1d95b(%rip), %xmm0    # 0x50860
movaps %xmm1, -0x120(%rbp)
xorps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x108(%rbp)
testl %esi, %esi
movl $0x0, %edx
cmovgl %esi, %edx
xorl %edi, %edi
movss 0x54(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
testl %ecx, %ecx
movl $0x0, %esi
movq %rsi, -0x68(%rbp)
cmovlel %edi, %ecx
movl %ecx, -0xac(%rbp)
movss 0x58(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
movq %rax, -0xd8(%rbp)
movq %rdx, -0xc0(%rbp)
movq -0x68(%rbp), %rax
cmpl -0xac(%rbp), %eax
je 0x33418
movq %rsp, -0xb8(%rbp)
movq %rsp, %rax
subq -0xd8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq %rax, %rsp
xorl %eax, %eax
cmpq %rax, %rdx
je 0x32fac
movq -0x88(%rbp), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x32f96
xorl %ecx, %ecx
movss 0x21d42(%rip), %xmm0    # 0x54cf8
pushq $-0x1
popq %rsi
movl $0x0, -0x48(%rbp)
cmpq %rcx, %rdx
je 0x3313c
movss %xmm0, -0x2c(%rbp)
movsd -0x110(%rbp), %xmm0
movq -0x88(%rbp), %rbx
movsd %xmm0, (%rbx,%rcx,8)
movq -0x90(%rbp), %r14
movq %r14, %rdi
movl %esi, -0x3c(%rbp)
movq -0x78(%rbp), %rsi
movq -0x98(%rbp), %r13
movl %r13d, %edx
movq %rcx, -0x38(%rbp)
callq 0x301ca
movq %r14, %rdi
movl %r13d, %esi
movq %rbx, %rdx
movl -0x40(%rbp), %ecx
callq 0x13d70
movq -0xd0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x2f358
movq -0xc8(%rbp), %r12
movq %r12, %rdi
movl -0x50(%rbp), %r15d
movl %r15d, %esi
movq %rbx, %rdx
movq -0xa8(%rbp), %rcx
callq 0x2f9b8
movq -0x80(%rbp), %rdi
movq %r12, %rsi
movq -0xa0(%rbp), %rdx
movl %r15d, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x70(%rbp)
minss -0x2c(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movsd -0x108(%rbp), %xmm0
movq -0x38(%rbp), %rax
movq -0x88(%rbp), %r15
movsd %xmm0, (%r15,%rax,8)
movq %r14, %rdi
movq -0x78(%rbp), %rsi
movl %r13d, %edx
callq 0x301ca
movq %r14, %rdi
movl %r13d, %esi
movq %r15, %rdx
movl -0x40(%rbp), %ecx
callq 0x13d70
movq %rbx, %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x2f358
movq %r12, %rdi
movl -0x50(%rbp), %r14d
movl %r14d, %esi
movq %rbx, %rdx
movq -0xa8(%rbp), %rcx
callq 0x2f9b8
movq -0x80(%rbp), %rdi
movq %r12, %rsi
movq -0xa0(%rbp), %rdx
movl %r14d, %ecx
callq 0x47a64
movl -0x3c(%rbp), %esi
movq -0xc0(%rbp), %rdx
cvtsd2ss %xmm0, %xmm0
movss -0x4c(%rbp), %xmm2
ucomiss %xmm0, %xmm2
cmoval -0x38(%rbp), %esi
movss -0x2c(%rbp), %xmm1
ucomiss -0x70(%rbp), %xmm1
pushq $0x1
popq %rax
movl -0x48(%rbp), %ecx
cmoval %eax, %ecx
cmoval -0x38(%rbp), %esi
ucomiss %xmm0, %xmm2
pushq $-0x1
popq %rax
cmoval %eax, %ecx
movl %ecx, -0x48(%rbp)
movq -0x38(%rbp), %rcx
andq $0x0, (%r15,%rcx,8)
minss %xmm2, %xmm0
incq %rcx
jmp 0x32fc0
testl %esi, %esi
js 0x33403
cvtsi2ssl -0x48(%rbp), %xmm0
movss %xmm0, -0xb0(%rbp)
movl %esi, %eax
movq %rax, -0xf0(%rbp)
movq -0x68(%rbp), %rax
incl %eax
movq %rax, -0x68(%rbp)
pushq $0x1
popq %r14
movaps -0x120(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
movl %r14d, -0x4c(%rbp)
movss -0x38(%rbp), %xmm0
mulss -0xb0(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x88(%rbp), %rbx
movq -0xf0(%rbp), %rax
movsd %xmm0, (%rbx,%rax,8)
movq -0x90(%rbp), %r15
movq %r15, %rdi
movq -0x78(%rbp), %rsi
movq -0x98(%rbp), %r14
movl %r14d, %edx
callq 0x301ca
movq %r15, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movl -0x40(%rbp), %ecx
callq 0x13d70
movq -0xd0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x2f358
movq -0xc8(%rbp), %r13
movq %r13, %rdi
movl -0x50(%rbp), %r15d
movl %r15d, %esi
movq %rbx, %rdx
movq -0xa8(%rbp), %rcx
callq 0x2f9b8
movq -0x80(%rbp), %rdi
movq %r13, %rsi
movq -0xa0(%rbp), %r12
movq %r12, %rdx
movl %r15d, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
movq -0xe0(%rbp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movl %r15d, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x48(%rbp)
movq -0xe8(%rbp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movl %r15d, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
cvtss2sd -0x2c(%rbp), %xmm0
movsd %xmm0, -0x100(%rbp)
cvtss2sd -0x48(%rbp), %xmm1
movsd %xmm1, -0xf8(%rbp)
cvtss2sd -0x38(%rbp), %xmm2
movsd %xmm2, -0x70(%rbp)
leaq 0x221ea(%rip), %rdi     # 0x55472
movq -0x68(%rbp), %rsi
movb $0x3, %al
callq 0x20f0
movq %rbx, %rdi
movl %r14d, %esi
movl -0x4c(%rbp), %r14d
callq 0x2f3a6
cvtss2sd -0x3c(%rbp), %xmm1
cvtss2sd %xmm0, %xmm4
movq 0x48(%rbp), %rbx
movq %rbx, %rdi
leaq 0x21e91(%rip), %rsi     # 0x5514a
movaps %xmm1, %xmm0
movsd -0x100(%rbp), %xmm1
movsd -0xf8(%rbp), %xmm2
movsd -0x70(%rbp), %xmm3
movl %r14d, %edx
movb $0x5, %al
callq 0x2190
movq %rbx, %rdi
callq 0x21e0
movss -0x48(%rbp), %xmm2
movss -0x2c(%rbp), %xmm1
ucomiss %xmm2, %xmm2
jp 0x33411
ucomiss %xmm1, %xmm1
jp 0x33411
movss -0x3c(%rbp), %xmm0
ucomiss %xmm0, %xmm0
jp 0x33411
movss -0x5c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x3335c
movss -0x54(%rbp), %xmm0
ucomiss %xmm2, %xmm0
ja 0x333b0
movss -0x58(%rbp), %xmm0
ucomiss %xmm2, %xmm0
ja 0x333d5
movss -0x54(%rbp), %xmm0
divss %xmm2, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x21970(%rip), %xmm0    # 0x54cb8
mulsd -0x70(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
cvtss2sd %xmm0, %xmm2
jmp 0x33399
movss -0x58(%rbp), %xmm0
ucomiss %xmm2, %xmm0
ja 0x333d8
movss -0x38(%rbp), %xmm0
mulss 0x1c7a1(%rip), %xmm0    # 0x4fb14
movss %xmm0, -0x38(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x22119(%rip), %rdi     # 0x554a1
movb $0x1, %al
callq 0x20f0
movsd -0x48(%rbp), %xmm2
movss -0x2c(%rbp), %xmm1
xorl %r14d, %r14d
movsd 0x1c774(%rip), %xmm0    # 0x4fb18
ucomisd %xmm2, %xmm0
jbe 0x33174
jmp 0x333d8
movq -0x78(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdx
callq 0x301ca
movss -0x2c(%rbp), %xmm1
movb $0x1, %al
movss %xmm1, -0x5c(%rbp)
jmp 0x333de
xorl %r14d, %r14d
testl %r14d, %r14d
setne %al
movq -0xb8(%rbp), %rsp
testb %al, %al
movq -0xc0(%rbp), %rdx
je 0x33418
movss 0x30ac4(%rip), %xmm0    # 0x63ebc
ucomiss %xmm1, %xmm0
jbe 0x32f69
jmp 0x33418
leaq 0x2200a(%rip), %rdi     # 0x55414
xorl %eax, %eax
callq 0x20f0
movq -0xb8(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq