// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movss %xmm2, -0x40(%rbp)
movss %xmm1, -0x60(%rbp)
movq %r9, -0xc0(%rbp)
movq %r8, -0xa8(%rbp)
movl %ecx, %r14d
movq %rdx, %r13
movss %xmm0, -0x3c(%rbp)
movl %esi, %r12d
movq %rdi, %rbx
leaq 0x2480a(%rip), %rdi     # 0x5b52d
xorl %eax, %eax
callq 0x20f0
cmpl $0x0, 0x427d7(%rip)     # 0x79508
jne 0x36d4a
movl $0x1, 0x427cb(%rip)     # 0x79508
callq 0x32e47
movq %rax, %rdi
callq 0x5050c
movl %r12d, %eax
testl %r12d, %r12d
movq %rax, -0x48(%rbp)
jle 0x36d70
movq -0x48(%rbp), %rax
leaq (,%rax,8), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2110
movq -0x48(%rbp), %rax
leaq 0x10(%rbp), %rcx
movq %rsp, %rdx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rdx
movq %rdx, -0x78(%rbp)
movq %rdx, %rsp
testl %r12d, %r12d
jle 0x36dad
movq -0x48(%rbp), %rax
leaq (,%rax,4), %rdx
movq -0x78(%rbp), %rdi
xorl %esi, %esi
callq 0x2110
leaq 0x10(%rbp), %rcx
movl %r14d, %edi
movq %rsp, %r15
movq %rdi, %rax
shlq $0x6, %rax
leaq (%rax,%rax,2), %rax
subq %rax, %r15
movq %r15, %rsp
movl 0x1c(%rcx), %eax
movq %rsp, %rdx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rdx
movq %rdx, -0x58(%rbp)
movq %rdx, %rsp
testl %r12d, %r12d
jle 0x370d1
movl 0x18(%rcx), %r8d
movq 0x10(%rcx), %rax
movq %rax, -0x90(%rbp)
leaq 0x8(%r15), %rax
movq %rax, -0xa0(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl $0x0, -0x30(%rbp)
movq %rbx, -0xb8(%rbp)
movl %r12d, -0x2c(%rbp)
movq %rdi, -0xb0(%rbp)
movq %r8, -0x50(%rbp)
movl %ecx, -0x38(%rbp)
xorl %eax, %eax
callq 0x50647
movq -0x78(%rbp), %rsi
movq -0x48(%rbp), %rdx
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
leal -0x1(%r12), %r9d
cmpl %eax, %r12d
cmovlel %r9d, %eax
xorl %r10d, %r10d
xorl %ecx, %ecx
cmpl $0x0, (%rsi,%r10,4)
jne 0x36e69
cmpl %eax, %ecx
je 0x36e74
incl %ecx
incq %r10
cmpq %r10, %rdx
jne 0x36e5c
movl %edx, %r10d
cmpl -0x2c(%rbp), %r10d
leaq 0x10(%rbp), %rax
jne 0x36e8d
movl %r12d, %edx
movl -0x2c(%rbp), %r12d
movl -0x38(%rbp), %ecx
jmp 0x370af
movl %r9d, -0x5c(%rbp)
movq %r10, -0x70(%rbp)
movl %r10d, %ecx
movq %rcx, -0x88(%rbp)
movl $0x1, (%rsi,%rcx,4)
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl -0x2c(%rbp), %r12d
movq %rax, -0x98(%rbp)
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
mulss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x88(%rbp), %rax
movsd %xmm0, (%rbx,%rax,8)
movq $0x0, 0x28(%r15)
testl %r14d, %r14d
jle 0x36fb9
movl %r14d, %r12d
xorl %ebx, %ebx
xorl %r14d, %r14d
leaq (%rbx,%r13), %rsi
leaq (%r15,%rbx), %rdi
movl $0xc0, %edx
callq 0x21a0
testl %r14d, %r14d
je 0x36f2d
movq 0x28(%r13,%rbx), %rax
subq %r13, %rax
shrq $0x6, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
cltq
leaq (%rax,%rax,2), %rax
shlq $0x6, %rax
addq %r15, %rax
movq %rax, 0x28(%r15,%rbx)
incl %r14d
addq $0xc0, %rbx
cmpl %r14d, %r12d
jne 0x36ef2
movq %r15, %rdi
movl %r12d, %r14d
movl %r12d, %esi
movq -0xb8(%rbp), %rbx
movq %rbx, %rdx
movl -0x2c(%rbp), %r12d
movl %r12d, %ecx
callq 0x154bb
testl %r14d, %r14d
movq -0xb0(%rbp), %rdi
movq -0x50(%rbp), %rcx
movq -0x80(%rbp), %r9
jle 0x36fd2
movq -0xa0(%rbp), %rax
xorl %r8d, %r8d
movq 0x38(%rbp), %rdx
leaq (%r8,%r8,2), %rsi
shlq $0x6, %rsi
cmpl $0x0, 0x20(%r15,%rsi)
js 0x36fd2
xorl %esi, %esi
xorps %xmm0, %xmm0
cvtsd2ss (%rax,%rsi,2), %xmm0
movss %xmm0, (%rdx,%rsi)
addq $0x4, %rsi
cmpq $0xc, %rsi
jne 0x36f8f
incq %r8
addq $0xc0, %rax
addq %rsi, %rdx
cmpq %rdi, %r8
jne 0x36f7d
jmp 0x36fd2
movq %r15, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movl %r12d, %ecx
callq 0x154bb
movq -0x80(%rbp), %r9
movq -0x50(%rbp), %rcx
testl %ecx, %ecx
movq 0x38(%rbp), %rdi
jle 0x3700f
xorl %eax, %eax
movq -0x58(%rbp), %r8
movl (%r9,%rax,4), %edx
leal (%rdx,%rdx,2), %edx
movslq %edx, %rdx
leaq (%rdi,%rdx,4), %rsi
xorl %edx, %edx
movss (%rsi,%rdx), %xmm0
movss %xmm0, (%r8,%rdx)
addq $0x4, %rdx
cmpl $0xc, %edx
jne 0x36ff0
incq %rax
addq %rdx, %r8
cmpq %rcx, %rax
jne 0x36fe0
movq -0xc0(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x90(%rbp), %rdx
callq 0x4e010
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movss -0x40(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x37066
movq -0xa8(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x90(%rbp), %rdx
movq -0x50(%rbp), %rcx
movss %xmm1, -0x64(%rbp)
callq 0x4e010
movss -0x64(%rbp), %xmm1
cvtsd2ss %xmm0, %xmm0
ucomiss -0x60(%rbp), %xmm0
ja 0x37083
movq -0x98(%rbp), %rcx
leal 0x2(%rcx), %eax
testl %ecx, %ecx
js 0x36eb6
movl -0x30(%rbp), %eax
movl %eax, %ecx
movq -0x70(%rbp), %r10
jmp 0x37097
movq -0x70(%rbp), %r10
movl %r10d, -0x34(%rbp)
movss %xmm1, -0x40(%rbp)
movq -0x98(%rbp), %rcx
movq -0x88(%rbp), %rax
movq $0x0, (%rbx,%rax,8)
movl %ecx, -0x30(%rbp)
movl -0x38(%rbp), %ecx
movl -0x5c(%rbp), %edx
cmpl %r12d, %r10d
je 0x370c4
movl %r12d, %eax
incl %ecx
movl %edx, %r12d
cmpl %eax, %ecx
jne 0x36e29
xorps %xmm0, %xmm0
cvtsi2ssl -0x30(%rbp), %xmm0
movl -0x34(%rbp), %esi
jmp 0x370da
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
testl %esi, %esi
js 0x370f0
mulss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movl %esi, %eax
movsd %xmm0, (%rbx,%rax,8)
jmp 0x37103
leaq 0x24405(%rip), %rdi     # 0x5b4fc
xorl %eax, %eax
callq 0x20f0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq