// File: /workspace/github_c_makefile_star2_O0/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
subq $0x100, %rsp            # imm = 0x100
leaq 0x50(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
leaq 0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl -0x10(%rbp), %esi
leaq 0x31cf5(%rip), %rdi     # 0x808ae
xorl %eax, %eax
movb %al, -0xe1(%rbp)
callq 0x10d0
movb -0xe1(%rbp), %al
movq 0x48(%rbp), %rdi
movl -0x10(%rbp), %edx
leaq 0x31cd2(%rip), %rsi     # 0x808ac
callq 0x1150
movl -0xc(%rbp), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
movq %rsp, %rcx
movq %rcx, -0x30(%rbp)
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0xd8(%rbp)
movq %rdi, %rsp
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0x49770
movq -0xd8(%rbp), %rdx
movq -0xc0(%rbp), %rax
movl -0xc(%rbp), %ecx
movq %rcx, %rsi
shlq $0x6, %rsi
leaq (%rsi,%rsi,2), %rdi
movq %rsp, %rsi
subq %rdi, %rsi
movq %rsi, -0xe0(%rbp)
movq %rsi, %rsp
movq %rcx, -0x40(%rbp)
movl (%rax), %ecx
movl %ecx, -0x44(%rbp)
movl -0x24(%rbp), %ecx
leaq 0xf(,%rcx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdi
subq %rsi, %rdi
movq %rdi, -0xd0(%rbp)
movq %rdi, %rsp
movq %rcx, -0x50(%rbp)
movl -0x24(%rbp), %ecx
leaq 0xf(,%rcx,4), %r8
andq $-0x10, %r8
movq %rsp, %rsi
subq %r8, %rsi
movq %rsi, -0xc8(%rbp)
movq %rsi, %rsp
movq %rcx, -0x58(%rbp)
movl -0x44(%rbp), %esi
movq 0x28(%rax), %rcx
callq 0x4a1d0
movq -0xd8(%rbp), %rdx
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl -0x44(%rbp), %esi
movq 0x28(%rax), %rcx
callq 0x4a1d0
movq -0xd0(%rbp), %rdx
movq -0xc8(%rbp), %rcx
movq -0xc0(%rbp), %rax
movq %rdx, -0x60(%rbp)
movq %rcx, -0x68(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x74(%rbp)
movl $0x0, -0x88(%rbp)
movq -0xf0(%rbp), %rcx
movl -0x88(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x4f35e
movl -0x10(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x98(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xf8(%rbp)
movq %rcx, %rsp
movq %rax, -0xa0(%rbp)
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x4ed90
movq -0xf8(%rbp), %rax
movslq -0x90(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x4ed5e
movss 0x312bc(%rip), %xmm0    # 0x80054
movss %xmm0, -0xa4(%rbp)
movl $0xffffffff, -0xa8(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0xac(%rbp)
movl $0x1, -0xb0(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x4efb9
movq -0xe0(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq -0xf0(%rbp), %rcx
movss 0xc(%rcx), %xmm0
cvtss2sd %xmm0, %xmm0
movslq -0x8c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0x4adb0
movq -0xf8(%rbp), %rdx
movq -0xe0(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %ecx
callq 0x1c4f0
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdi
movl -0xc(%rbp), %edx
callq 0x49770
movq -0xd8(%rbp), %rdx
movq -0xc0(%rbp), %rax
movq -0x60(%rbp), %rdi
movl -0x44(%rbp), %esi
movq 0x28(%rax), %rcx
callq 0x4a1d0
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x78(%rbp)
movss -0x78(%rbp), %xmm1
movss -0xa4(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4eeac
movl -0x8c(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl $0x1, -0xac(%rbp)
movss -0x78(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
movq -0xe0(%rbp), %rdi
movq -0xf8(%rbp), %rax
movq -0xf0(%rbp), %rcx
movss 0xc(%rcx), %xmm0
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
cvtss2sd %xmm0, %xmm0
movslq -0x8c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0x4adb0
movq -0xf8(%rbp), %rdx
movq -0xe0(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %ecx
callq 0x1c4f0
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdi
movl -0xc(%rbp), %edx
callq 0x49770
movq -0xd8(%rbp), %rdx
movq -0xc0(%rbp), %rax
movq -0x60(%rbp), %rdi
movl -0x44(%rbp), %esi
movq 0x28(%rax), %rcx
callq 0x4a1d0
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x78(%rbp)
movss -0x78(%rbp), %xmm1
movss -0xa4(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4ef8f
movl -0x8c(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl $0xffffffff, -0xac(%rbp) # imm = 0xFFFFFFFF
movss -0x78(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
movq -0xf8(%rbp), %rax
movslq -0x8c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x4edc8
cmpl $0x0, -0xa8(%rbp)
jge 0x4efe5
movl -0xa8(%rbp), %esi
leaq 0x318ae(%rip), %rdi     # 0x8087d
movb $0x0, %al
callq 0x10d0
movl $0x1, -0xb4(%rbp)
jmp 0x4f31f
movq -0xf0(%rbp), %rax
movss 0xc(%rax), %xmm0
movss %xmm0, -0xb8(%rbp)
movss 0x2d3df(%rip), %xmm0    # 0x7c3e0
movss %xmm0, -0x78(%rbp)
jmp 0x4f008
movq -0xe0(%rbp), %rdi
movq -0xf8(%rbp), %rax
cvtsi2ssl -0xac(%rbp), %xmm0
mulss -0xb8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movslq -0xa8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %edx
callq 0x4adb0
movq -0xf8(%rbp), %rdx
movq -0xe0(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %ecx
callq 0x1c4f0
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdi
movl -0xc(%rbp), %edx
callq 0x49770
movq -0xd8(%rbp), %rdx
movq -0xc0(%rbp), %rax
movq -0x60(%rbp), %rdi
movl -0x44(%rbp), %esi
movq 0x28(%rax), %rcx
callq 0x4a1d0
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x78(%rbp)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x80(%rbp)
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0x44(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x7c(%rbp)
movl -0x88(%rbp), %esi
addl $0x1, %esi
movss -0x78(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x80(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0xb8(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
leaq 0x317c7(%rip), %rdi     # 0x808db
movb $0x3, %al
callq 0x10d0
movq -0xd8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x49810
movss %xmm0, -0x84(%rbp)
movq 0x48(%rbp), %rdi
movss -0x7c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x78(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x80(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0xb8(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
movss -0x84(%rbp), %xmm4
cvtss2sd %xmm4, %xmm4
movl -0xb0(%rbp), %edx
leaq 0x31394(%rip), %rsi     # 0x8050a
movb $0x5, %al
callq 0x1150
movq 0x48(%rbp), %rdi
callq 0x1190
movss -0x80(%rbp), %xmm0
ucomiss %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x4f1b5
movss -0x78(%rbp), %xmm0
ucomiss %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x4f1b5
movss -0x7c(%rbp), %xmm0
ucomiss %xmm0, %xmm0
setp %al
testb $0x1, %al
jne 0x4f1b5
jmp 0x4f1c4
movl $0x1, -0xb4(%rbp)
jmp 0x4f31f
movss -0x78(%rbp), %xmm1
movss -0x74(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4f275
movq -0xf0(%rbp), %rax
movss -0x80(%rbp), %xmm1
movss 0x4(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4f219
movq -0xe0(%rbp), %rsi
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x74(%rbp)
movl $0x1, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %edx
callq 0x4adb0
jmp 0x4f2ee
movq -0xf0(%rbp), %rax
movl $0x0, -0xb0(%rbp)
movss 0x4(%rax), %xmm0
divss -0x80(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x30e38(%rip), %xmm1    # 0x80078
mulsd %xmm0, %xmm1
movss -0xb8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xb8(%rbp)
movss -0x80(%rbp), %xmm1
movss 0x8(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4f271
jmp 0x4f2ee
jmp 0x4f273
jmp 0x4f2cd
movq -0xf0(%rbp), %rax
movss -0x80(%rbp), %xmm1
movss 0x8(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4f28d
jmp 0x4f2ee
movl $0x0, -0xb0(%rbp)
movss -0xb8(%rbp), %xmm0
movss 0x26ded(%rip), %xmm1    # 0x76094
divss %xmm1, %xmm0
movss %xmm0, -0xb8(%rbp)
movss -0xb8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x31644(%rip), %rdi     # 0x8090a
movb $0x1, %al
callq 0x10d0
movss -0xb8(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x2b937(%rip), %xmm0    # 0x7ac18
ucomisd %xmm1, %xmm0
jbe 0x4f2e9
jmp 0x4f2ee
jmp 0x4f006
cmpl $0x0, -0xb0(%rbp)
je 0x4f309
movss -0x78(%rbp), %xmm1
movss 0x3cb7c(%rip), %xmm0    # 0x8be80
ucomiss %xmm1, %xmm0
jbe 0x4f315
movl $0x2, -0xb4(%rbp)
jmp 0x4f31f
movl $0x0, -0xb4(%rbp)
movq -0x98(%rbp), %rax
movq %rax, %rsp
movl -0xb4(%rbp), %eax
movl %eax, -0xfc(%rbp)
testl %eax, %eax
je 0x4f348
jmp 0x4f33b
movl -0xfc(%rbp), %eax
subl $0x2, %eax
je 0x4f35e
jmp 0x4f368
jmp 0x4f34a
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x4ed0e
movl $0x0, -0xb4(%rbp)
movq -0x30(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)