// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/simulation.c
// Function: Torsional_confchange_1angle
int Torsional_confchange_1angle(double *diff_tors, int naxes, float angle,
				struct bond *bonds, int natoms1,
				struct ali_atoms ali_a,
				float *coord_ref_1, float *coord_ref_2,
				float STEP_MIN, float RMSD_min, atom *atoms1,
				float *coord_all)
{
  printf("Changing %d internal coordinates one by one\n", naxes);

  // Initialize random numbers
  if(INIRAN==0){
     INIRAN=1;
     unsigned long iran=randomgenerator();
     InitRandom( (RANDOMTYPE)iran);
  }

  int i, i_min=-1, dir_min=0;
  for(i=0; i<naxes; i++)diff_tors[i]=0;
  int tested[naxes]; for(i=0; i<naxes; i++)tested[i]=0;
  int N_to_test=naxes;

  struct bond bonds2[natoms1];
  int N_ref=ali_a.N_ref;
  float coord_new[ali_a.N_Cart];  
  float *mass_ref=ali_a.mass;
  float RMSD_kf, RMSD_step;
  for(int k=0; k<naxes; k++){
    // Change internal coordinate i in positive and negative direction
    int ran=RandomFloating()*N_to_test, iran=0;
    if(ran>=N_to_test)ran=N_to_test-1;
    for(i=0; i<naxes; i++){
      if(tested[i])continue;
      if(iran==ran)break;
      iran++;
    }
    if(i==naxes)break;

    // Test i
    tested[i]=1; N_to_test--;
    for(int dir=-1; dir<=1; dir+=2){
      diff_tors[i]=dir*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, ali_a.ali1);
      RMSD_kf=rmsd_mclachlan_f(coord_ref_2, coord_new, mass_ref, N_ref);
      if(RMSD_kf<RMSD_min){
	RMSD_step=rmsd_mclachlan_f(coord_ref_1, coord_new, mass_ref, N_ref);
	if(RMSD_step > STEP_MIN){
	  i_min=i; dir_min=dir; RMSD_min=RMSD_kf; break;
	}
      }
    }
    diff_tors[i]=0.0;
  }

  if(i_min<0){
    printf("\nERROR, internal coordinate %d does not exist\n", i_min);
    return(-1);
  }
  diff_tors[i_min]=dir_min*angle;
  return(i_min);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
leaq 0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movss %xmm0, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movss %xmm1, -0x3c(%rbp)
movss %xmm2, -0x40(%rbp)
movl -0x14(%rbp), %esi
leaq 0x320e1(%rip), %rdi     # 0x808ae
movb $0x0, %al
callq 0x10d0
cmpl $0x0, 0x4dced(%rip)     # 0x9c4c8
jne 0x4e7f9
movl $0x1, 0x4dce1(%rip)     # 0x9c4c8
callq 0x49ce0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x756e0
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x54(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4e831
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4e80e
movl -0x14(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x60(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xc0(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4e887
movq -0xc0(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4e862
movq -0xb8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, -0x6c(%rbp)
movl -0x24(%rbp), %ecx
movq %rcx, %rdx
shlq $0x6, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0xd0(%rbp)
movq %rdx, %rsp
movq %rcx, -0x78(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0x7c(%rbp)
movl 0x1c(%rax), %ecx
leaq 0xf(,%rcx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0xc8(%rbp)
movq %rdx, %rsp
movq %rcx, -0x88(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4eb09
movb $0x0, %al
callq 0x75930
cvtsi2sdl -0x6c(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movl -0xa0(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jl 0x4e941
movl -0x6c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xa0(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4e98d
movq -0xc0(%rbp), %rax
movslq -0x4c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x4e963
jmp 0x4e982
movl -0xa4(%rbp), %eax
cmpl -0xa0(%rbp), %eax
jne 0x4e973
jmp 0x4e98d
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4e948
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x4e99a
jmp 0x4eb09
movq -0xc0(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl -0x6c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x6c(%rbp)
movl $0xffffffff, -0xa8(%rbp) # imm = 0xFFFFFFFF
cmpl $0x1, -0xa8(%rbp)
jg 0x4eae5
movq -0xd0(%rbp), %rdi
cvtsi2ssl -0xa8(%rbp), %xmm0
mulss -0x18(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x4adb0
movq -0xd0(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %ecx
callq 0x1c4f0
movq -0xd0(%rbp), %rsi
movq 0x38(%rbp), %rdi
movl -0x24(%rbp), %edx
callq 0x49770
movq -0xc8(%rbp), %rdi
movq -0xb8(%rbp), %rax
movl -0x7c(%rbp), %esi
movq 0x38(%rbp), %rdx
movq (%rax), %rcx
callq 0x4a1d0
movq -0xc8(%rbp), %rsi
movq -0x38(%rbp), %rdi
movq -0x90(%rbp), %rdx
movl -0x7c(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x94(%rbp)
movss -0x94(%rbp), %xmm1
movss -0x40(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4eacf
movq -0xc8(%rbp), %rsi
movq -0x30(%rbp), %rdi
movq -0x90(%rbp), %rdx
movl -0x7c(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x98(%rbp)
movss -0x98(%rbp), %xmm0
ucomiss -0x3c(%rbp), %xmm0
jbe 0x4eacd
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x54(%rbp)
movss -0x94(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
jmp 0x4eae5
jmp 0x4eacf
jmp 0x4ead1
movl -0xa8(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xa8(%rbp)
jmp 0x4e9bf
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x4e8f7
cmpl $0x0, -0x50(%rbp)
jge 0x4eb33
movl -0x50(%rbp), %esi
leaq 0x31d64(%rip), %rdi     # 0x8087d
movb $0x0, %al
callq 0x10d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0xac(%rbp)
jmp 0x4eb5e
cvtsi2ssl -0x54(%rbp), %xmm0
mulss -0x18(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x50(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0xac(%rbp)
movq -0x60(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)