// File: /workspace/github_c_makefile_star2_O3/ugobas[P]tnm/simulation.c
// Function: Simulate_confchange
void Simulate_confchange(int N_frames, float *tors_dir, float *d_Cart,
			 int PRINT_SIMUL_PDB, float RMSD_NM,
			 float *coord_1, float *coord_2, float rmsd,
			 struct Para_simul Para_simul,
			 atom *atoms, int natoms,
			 struct axe *axe, int naxes,
			 struct bond *bonds,
			 struct residue *seq, int nres,
			 int N_diso, struct Normal_Mode NM,
			 struct Jacobian J, struct Reference Ref,
			 struct interaction *Int_list, int N_int,
			 char *INT_TYPE, float s0, char *nameout,
			 double tors2, int anhar)
{
  int i, Ini_ch=1, n3=3*natoms;
  float coord_all[n3], coord_opt[n3];
  float coord_ref[Ref.N_Cart], coord_ref2[Ref.N_Cart];
  for(i=0; i<Ref.N_Cart; i++)coord_ref2[i]=coord_1[i];

  // Compute factor for simulations
  double factor=1.00;
  if(rmsd >0 ){
    factor=sqrt(rmsd/RMSD_NM);
    printf("RMSD= %.2f (observed) factor=%.2f\n", rmsd, factor);
  }


  // Open files
  FILE *file_pdb=NULL, *file_out; char name_pdb[100], name_out[200];
  if(tors_dir==NULL){
      if(PRINT_SIMUL_PDB)sprintf(name_pdb, "%s_simul.pdb", nameout);
      sprintf(name_out, "%s_simul.dat", nameout);
  }else{
    if(PRINT_SIMUL_PDB)sprintf(name_pdb, "%s_pred_mut.pdb", nameout);
    sprintf(name_out, "%s_pred_mut.dat", nameout);
  }
  if(PRINT_SIMUL_PDB)file_pdb=fopen(name_pdb, "w");
  file_out=fopen(name_out, "w");
  fprintf(file_out, "#step rmsd_previous rmsd_ini rmsd_end E_clash\n");

  // Simulations
  float rmsd0=-1;
  if(coord_2){
    rmsd0=rmsd_mclachlan_f(coord_1, coord_2, Ref.mass_atom, Ref.N_ref);
  }

  char type='R'; // Random ensemble
  float coeff=3*factor/N_frames;
  double d_phi[naxes];
  if(tors_dir){   // Move along a predefined torsional direction   
    for(i=0; i<naxes; i++)d_phi[i]=tors_dir[i]*coeff;
    type='T'; // torsional displacement
  }
  Make_conformations(type, N_frames, d_phi, NULL, factor, coeff, rmsd0,
		     coord_all, coord_opt, coord_ref, coord_ref2, 
		     PRINT_SIMUL_PDB, file_out, file_pdb,
		     coord_1, coord_2, Para_simul,
		     atoms, natoms, axe, naxes, bonds, seq, nres, N_diso,
		     NM, J, Ref, Int_list, N_int, INT_TYPE, s0, nameout,
		     anhar);
  if(d_Cart){
    Make_conformations('C', N_frames, NULL, d_Cart, factor, coeff, rmsd0,
		       coord_all, coord_opt, coord_ref, coord_ref2, 
		       PRINT_SIMUL_PDB, file_out, file_pdb,
		       coord_1, coord_2, Para_simul,
		       atoms, natoms, axe, naxes, bonds, seq, nres, N_diso,
		       NM, J, Ref, Int_list, N_int, INT_TYPE, s0, nameout,
		       anhar);
  }
  printf("Distances printed in %s\n", name_out); fclose(file_out);
  if(PRINT_SIMUL_PDB){
    printf("Simulated structures printed in %s\n", name_pdb);
    fclose(file_pdb);
  }
  if(Ini_ch==0){Empty_tors(Diff_s); free(ali_sim.alignres); Ini_ch=1;}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movaps %xmm1, %xmm2
movq %r9, -0x50(%rbp)
movq %r8, %r12
movl %ecx, %r15d
movq %rdx, -0x80(%rbp)
movq %rsi, %r14
movl %edi, -0x48(%rbp)
movl 0x58(%rbp), %eax
leal (%rax,%rax,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x68(%rbp)
movq %rcx, %rsp
movl 0x1ac(%rbp), %edx
movq %rsp, %rcx
leaq 0xf(,%rdx,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x60(%rbp)
movq %rcx, %rsp
testl %edx, %edx
jle 0x37932
shlq $0x2, %rdx
movq -0x60(%rbp), %rdi
movq %r12, %rsi
movss %xmm2, -0x38(%rbp)
movss %xmm0, -0x40(%rbp)
callq 0x21b0
movss -0x40(%rbp), %xmm0
movss -0x38(%rbp), %xmm2
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm2
movq %rbx, -0x70(%rbp)
jbe 0x3795e
movaps %xmm2, %xmm1
divss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x3796d
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0x37980
movsd 0x197e2(%rip), %xmm0    # 0x51148
movsd %xmm0, -0x40(%rbp)
jmp 0x3799a
movss %xmm2, -0x38(%rbp)
callq 0x22a0
movss -0x38(%rbp), %xmm2
movapd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
leaq 0x23bd0(%rip), %rdi     # 0x5b55e
movsd %xmm1, -0x40(%rbp)
movb $0x2, %al
callq 0x20f0
movq 0x1f0(%rbp), %rdx
testq %r14, %r14
leaq 0x23c3a(%rip), %rax     # 0x5b5e5
leaq 0x23bec(%rip), %rbx     # 0x5b59e
cmoveq %rax, %rbx
testl %r15d, %r15d
je 0x379e5
testq %r14, %r14
leaq 0x23bbc(%rip), %rax     # 0x5b581
leaq 0x23bc2(%rip), %rsi     # 0x5b58e
cmoveq %rax, %rsi
leaq -0xf0(%rbp), %rdi
xorl %eax, %eax
callq 0x2270
movq 0x1f0(%rbp), %rdx
leaq -0x1c0(%rbp), %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2270
testl %r15d, %r15d
movl %r15d, -0x44(%rbp)
je 0x37a18
leaq 0x1f7fa(%rip), %rsi     # 0x57200
leaq -0xf0(%rbp), %rdi
callq 0x2220
movq %rax, -0x38(%rbp)
jmp 0x37a20
movq $0x0, -0x38(%rbp)
leaq 0x1a8(%rbp), %rbx
leaq 0x1f7d2(%rip), %rsi     # 0x57200
leaq -0x1c0(%rbp), %rdi
callq 0x2220
leaq 0x23b6d(%rip), %rdi     # 0x5b5ae
movl $0x2e, %esi
movl $0x1, %edx
movq %rax, %r13
movq %rax, %rcx
callq 0x2290
movq -0x50(%rbp), %rsi
testq %rsi, %rsi
je 0x37a7c
movq 0x10(%rbx), %rdx
movq %rbx, %r15
movl (%rbx), %ecx
movq %r12, %rbx
movq %r12, %rdi
callq 0x4dfa0
xorps %xmm2, %xmm2
cvtsd2ss %xmm0, %xmm2
jmp 0x37a8a
movq %rbx, %r15
movq %r12, %rbx
movss 0x19686(%rip), %xmm2    # 0x51110
leaq 0x160(%rbp), %rdi
movq 0x70(%rbp), %r12
movq 0x50(%rbp), %rsi
movl 0x68(%rbp), %r11d
movl %r11d, %ecx
movq %rsp, %rdx
leaq 0xf(,%rcx,8), %rax
andq $-0x10, %rax
subq %rax, %rdx
movq %rdx, %rsp
movsd 0x1f883(%rip), %xmm0    # 0x57340
movsd -0x40(%rbp), %xmm3
mulsd %xmm3, %xmm0
movl -0x48(%rbp), %r8d
xorps %xmm1, %xmm1
cvtsi2sd %r8d, %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
testq %r14, %r14
movq -0x38(%rbp), %r9
movq %r13, %r10
je 0x37b1a
movq %rsi, %r13
testl %r11d, %r11d
movq %rdi, %rsi
jle 0x37b11
xorl %eax, %eax
movss (%r14,%rax,4), %xmm0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, (%rdx,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x37af6
movq %r12, %r14
movb $0x54, -0x2c(%rbp)
jmp 0x37b27
movq %r12, %r14
movq %rsi, %r13
movb $0x52, -0x2c(%rbp)
movq %rdi, %rsi
xorps %xmm0, %xmm0
cvtsd2ss %xmm3, %xmm0
subq $0x230, %rsp            # imm = 0x230
leaq 0x188(%rsp), %rdi
movl $0x9, %ecx
rep  movsq (%rsi), %es:(%rdi)
leaq 0xb8(%rsp), %rdi
movl $0x1a, %ecx
leaq 0x90(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movups (%r15), %xmm5
movups 0x10(%r15), %xmm4
movups 0x20(%r15), %xmm3
movups %xmm3, 0x1f0(%rsp)
movups %xmm4, 0x1e0(%rsp)
movups %xmm5, 0x1d0(%rsp)
leaq 0x10(%rbp), %r12
movups (%r12), %xmm6
movups 0x10(%r12), %xmm5
movups 0x20(%r12), %xmm4
movups 0x2c(%r12), %xmm3
movups %xmm3, 0x64(%rsp)
movups %xmm4, 0x58(%rsp)
movups %xmm5, 0x48(%rsp)
movups %xmm6, 0x38(%rsp)
movl 0x1f8(%rbp), %ecx
movl %ecx, 0x220(%rsp)
movq 0x1f0(%rbp), %rcx
movq %rcx, 0x218(%rsp)
movl 0x80(%rbp), %ecx
movl %ecx, 0xa8(%rsp)
movq 0x78(%rbp), %rcx
movq %rcx, 0xa0(%rsp)
movq %r14, 0x98(%rsp)
movl %r11d, 0x90(%rsp)
movl 0x58(%rbp), %eax
movl %eax, 0x80(%rsp)
movq %r13, 0x78(%rsp)
movq -0x50(%rbp), %rcx
movq %rcx, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq %r10, 0x18(%rsp)
movl -0x44(%rbp), %ecx
movl %ecx, 0x10(%rsp)
movq -0x60(%rbp), %r14
movq %r14, 0x8(%rsp)
movq -0x78(%rbp), %r13
movq %r13, (%rsp)
movzbl -0x2c(%rbp), %edi
movl %r8d, %esi
xorl %ecx, %ecx
movss %xmm0, -0x2c(%rbp)
movq -0x70(%rbp), %r8
movq %r9, -0x38(%rbp)
movq -0x68(%rbp), %r9
movq %r10, -0x40(%rbp)
movss %xmm2, -0x58(%rbp)
movss %xmm1, -0x54(%rbp)
callq 0x37e0b
addq $0x230, %rsp            # imm = 0x230
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x37dba
subq $0x230, %rsp            # imm = 0x230
movl $0x9, %ecx
leaq 0x188(%rsp), %rdi
leaq 0x160(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movl $0x1a, %ecx
leaq 0xb8(%rsp), %rdi
leaq 0x90(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x1f0(%rsp)
movups %xmm1, 0x1e0(%rsp)
movups %xmm0, 0x1d0(%rsp)
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups 0x2c(%r12), %xmm3
movups %xmm3, 0x64(%rsp)
movups %xmm2, 0x58(%rsp)
movups %xmm1, 0x48(%rsp)
movups %xmm0, 0x38(%rsp)
movl 0x1f8(%rbp), %ecx
movl %ecx, 0x220(%rsp)
movq 0x1f0(%rbp), %rcx
movq %rcx, 0x218(%rsp)
movl 0x80(%rbp), %ecx
movl %ecx, 0xa8(%rsp)
movq 0x78(%rbp), %rcx
movq %rcx, 0xa0(%rsp)
movq 0x70(%rbp), %rcx
movq %rcx, 0x98(%rsp)
movl 0x68(%rbp), %ecx
movl %ecx, 0x90(%rsp)
movl 0x58(%rbp), %ecx
movl %ecx, 0x80(%rsp)
movq 0x50(%rbp), %rcx
movq %rcx, 0x78(%rsp)
movq -0x50(%rbp), %rcx
movq %rcx, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
movq %r14, 0x8(%rsp)
movq %r13, (%rsp)
movq -0x38(%rbp), %rcx
movq %rcx, 0x20(%rsp)
movq -0x40(%rbp), %rcx
movq %rcx, 0x18(%rsp)
movl -0x44(%rbp), %ecx
movl %ecx, 0x10(%rsp)
movl $0x43, %edi
movl -0x48(%rbp), %esi
movq -0x70(%rbp), %r8
movq -0x68(%rbp), %r9
xorl %edx, %edx
movq %rax, %rcx
movss -0x2c(%rbp), %xmm0
movss -0x54(%rbp), %xmm1
movss -0x58(%rbp), %xmm2
callq 0x37e0b
addq $0x230, %rsp            # imm = 0x230
leaq 0x23212(%rip), %rdi     # 0x5afd3
leaq -0x1c0(%rbp), %rsi
xorl %eax, %eax
callq 0x20f0
movq -0x40(%rbp), %rdi
callq 0x20c0
cmpl $0x0, -0x44(%rbp)
je 0x37dfc
leaq 0x232f4(%rip), %rdi     # 0x5b0d9
leaq -0xf0(%rbp), %rsi
xorl %eax, %eax
callq 0x20f0
movq -0x38(%rbp), %rdi
callq 0x20c0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq