// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/simulation.c
// Function: Optimize_amplitude
float Optimize_amplitude(struct bond *bonds_min, float *f_min,
			 float *Diff_Tors, int naxes,
			 struct bond *bonds,
			 int natoms1, struct Reference Ref1,
			 float *coord_ref_2)
{
  float EPS=0.005, RMSD_min=10000, RMSD_RRR=0; *f_min=-1;
  struct bond bonds_tmp[natoms1];
  float f[3], y[3], fmin=0.01, fmax=20; int i;
  f[0]=1.3; f[1]=1; f[2]=0.7;
  printf("Optimizing amplitude f of torsion angle change:\n");
  for(i=0; i<3; i++){
    y[i]=Compute_RMSD(f[i],Diff_Tors,naxes,
		      bonds,bonds_tmp,natoms1,Ref1,coord_ref_2);
    printf("RMSD=%.5f f=%.5f\n", y[i], f[i]);
    if(f[i]==1)RMSD_RRR=y[i];
    if(y[i]<RMSD_min){
      RMSD_min=y[i]; *f_min=f[i]; Copy_bonds(bonds_min, bonds_tmp, natoms1);
    }
    y[i]=exp(-y[i]);
  }

  for(int iter=0; iter<20; iter++){
    float ff=Find_max_quad(f[0],f[1],f[2],y[0],y[1],y[2],fmin,fmax);
    float yy=Compute_RMSD(ff, Diff_Tors, naxes, bonds, bonds_tmp, natoms1,
			  Ref1, coord_ref_2);
    printf("RMSD=%.5f f=%.5f\n", yy, ff);
    if(yy<RMSD_min){
      RMSD_min=yy; *f_min=ff; Copy_bonds(bonds_min, bonds_tmp, natoms1);
    }else{
      if(iter>10)break;
    }
    yy=exp(-yy);
    if(ff<f[0]){
      if((f[0]-ff)<EPS)break;
      f[2]=f[1]; y[2]=y[1]; f[1]=f[0]; y[1]=y[0]; f[0]=ff; y[0]=yy;
    }else if(ff < f[1]){
      if(((f[1]-ff)<EPS)||((ff-f[0])<EPS))break;
      f[2]=f[1]; y[2]=y[1]; f[1]=ff; y[1]=yy;
    }else if(ff < f[2]){
      if(((f[2]-ff)<EPS)||((ff-f[1])<EPS))break;
      f[0]=f[1]; y[0]=y[1]; f[1]=ff; y[1]=yy;
    }else{
      if((ff-f[2])<EPS)break;
      f[0]=f[1]; y[0]=y[1]; f[1]=f[2]; y[1]=y[2]; f[2]=ff; y[2]=yy;
    }
  }
  printf("RMSD RRR= %.4f factor= %.4g\n", RMSD_RRR, 1.0);
  printf("Minimal RMSD= %.4f factor= %.4g\n", RMSD_min, *f_min);
  return(RMSD_min);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x40(%rbp), %rax
leaq 0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x3ba3d70a, -0x30(%rbp) # imm = 0x3BA3D70A
movl $0x461c4000, -0x34(%rbp) # imm = 0x461C4000
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0xbf800000, (%rax)     # imm = 0xBF800000
movl -0x2c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x40(%rbp)
movq %rax, %rcx
shlq $0x6, %rcx
leaq (%rcx,%rcx,2), %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x80(%rbp)
movq %rcx, %rsp
movq %rax, -0x48(%rbp)
movss 0x28a3a(%rip), %xmm0    # 0x7c3e8
movss %xmm0, -0x64(%rbp)
movss 0x226cd(%rip), %xmm0    # 0x76088
movss %xmm0, -0x68(%rbp)
movss 0x2c698(%rip), %xmm0    # 0x80060
movss %xmm0, -0x54(%rbp)
movss 0x226bb(%rip), %xmm0    # 0x76090
movss %xmm0, -0x50(%rbp)
movss 0x2c67a(%rip), %xmm0    # 0x8005c
movss %xmm0, -0x4c(%rbp)
leaq 0x2d6a3(%rip), %rdi     # 0x81091
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x6c(%rbp)
cmpl $0x3, -0x6c(%rbp)
jge 0x53b31
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %rax
movslq -0x6c(%rbp), %rdx
movss -0x54(%rbp,%rdx,4), %xmm0
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %r8d
movq 0x40(%rbp), %r9
subq $0x30, %rsp
movups (%rax), %xmm1
movups 0x10(%rax), %xmm2
movups 0x20(%rax), %xmm3
movq %rsp, %rax
movups %xmm3, 0x20(%rax)
movups %xmm2, 0x10(%rax)
movups %xmm1, (%rax)
callq 0x53e40
addq $0x30, %rsp
movslq -0x6c(%rbp), %rax
movss %xmm0, -0x60(%rbp,%rax,4)
movslq -0x6c(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm0
cvtss2sd %xmm0, %xmm0
movslq -0x6c(%rbp), %rax
movss -0x54(%rbp,%rax,4), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x2d641(%rip), %rdi     # 0x810c2
movb $0x2, %al
callq 0x10d0
movslq -0x6c(%rbp), %rax
movss -0x54(%rbp,%rax,4), %xmm0
movss 0x225f6(%rip), %xmm1    # 0x76090
ucomiss %xmm1, %xmm0
jne 0x53ab0
jp 0x53ab0
movslq -0x6c(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm0
movss %xmm0, -0x38(%rbp)
movslq -0x6c(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm1
movss -0x34(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53af5
movq -0x80(%rbp), %rsi
movslq -0x6c(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm0
movss %xmm0, -0x34(%rbp)
movslq -0x6c(%rbp), %rax
movss -0x54(%rbp,%rax,4), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
callq 0x4adb0
movslq -0x6c(%rbp), %rax
movss -0x60(%rbp,%rax,4), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1230
cvtsd2ss %xmm0, %xmm0
movslq -0x6c(%rbp), %rax
movss %xmm0, -0x60(%rbp,%rax,4)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x539fc
movl $0x0, -0x70(%rbp)
cmpl $0x14, -0x70(%rbp)
jge 0x53de9
movss -0x54(%rbp), %xmm0
movss -0x50(%rbp), %xmm1
movss -0x4c(%rbp), %xmm2
movss -0x60(%rbp), %xmm3
movss -0x5c(%rbp), %xmm4
movss -0x58(%rbp), %xmm5
movss -0x64(%rbp), %xmm6
movss -0x68(%rbp), %xmm7
callq 0x5cf00
movq -0x88(%rbp), %rax
movq -0x80(%rbp), %rcx
movss %xmm0, -0x74(%rbp)
movss -0x74(%rbp), %xmm0
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %r8d
movq 0x40(%rbp), %r9
subq $0x30, %rsp
movups (%rax), %xmm1
movups 0x10(%rax), %xmm2
movups 0x20(%rax), %xmm3
movq %rsp, %rax
movups %xmm3, 0x20(%rax)
movups %xmm2, 0x10(%rax)
movups %xmm1, (%rax)
callq 0x53e40
addq $0x30, %rsp
movss %xmm0, -0x78(%rbp)
movss -0x78(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x74(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x2d4e7(%rip), %rdi     # 0x810c2
movb $0x2, %al
callq 0x10d0
movss -0x78(%rbp), %xmm1
movss -0x34(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53c1a
movq -0x80(%rbp), %rsi
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x34(%rbp)
movss -0x74(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, (%rax)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
callq 0x4adb0
jmp 0x53c27
cmpl $0xa, -0x70(%rbp)
jle 0x53c25
jmp 0x53de9
jmp 0x53c27
movss -0x78(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1230
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x78(%rbp)
movss -0x74(%rbp), %xmm1
movss -0x54(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53cb4
movss -0x54(%rbp), %xmm1
subss -0x74(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53c73
jmp 0x53de9
movss -0x50(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x54(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x60(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x74(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x60(%rbp)
jmp 0x53dd9
movss -0x74(%rbp), %xmm1
movss -0x50(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53d1d
movss -0x50(%rbp), %xmm1
subss -0x74(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
ja 0x53ceb
movss -0x74(%rbp), %xmm1
subss -0x54(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53cf0
jmp 0x53de9
movss -0x50(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x74(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
jmp 0x53dd7
movss -0x74(%rbp), %xmm1
movss -0x4c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53d83
movss -0x4c(%rbp), %xmm1
subss -0x74(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
ja 0x53d54
movss -0x74(%rbp), %xmm1
subss -0x50(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53d59
jmp 0x53de9
movss -0x50(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x74(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
jmp 0x53dd5
movss -0x74(%rbp), %xmm1
subss -0x4c(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x53d99
jmp 0x53de9
movss -0x50(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x4c(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x74(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
jmp 0x53dd7
jmp 0x53dd9
jmp 0x53ddb
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x53b38
movss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x2d2db(%rip), %rdi     # 0x810d4
movsd 0x22247(%rip), %xmm1    # 0x76048
movb $0x2, %al
callq 0x10d0
movss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movss (%rax), %xmm1
cvtss2sd %xmm1, %xmm1
leaq 0x2d2cd(%rip), %rdi     # 0x810f1
movb $0x2, %al
callq 0x10d0
movss -0x34(%rbp), %xmm0
movq -0x40(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)