// File: /workspace/github_c_makefile_star2_O2/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 %r8, %r12
movl %ecx, -0x2c(%rbp)
movq %rdx, -0x80(%rbp)
movq %rsi, %rbx
movq 0x1f0(%rbp), %r14
leaq 0x1a8(%rbp), %rcx
movl 0x58(%rbp), %eax
leal (%rax,%rax,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rsi
subq %rax, %rsi
movq %rsi, %rsp
movq %rsp, %r8
subq %rax, %r8
movq %r8, %rsp
movl 0x4(%rcx), %edx
movq %rsp, %r10
leaq 0xf(,%rdx,4), %rax
andq $-0x10, %rax
subq %rax, %r10
movq %r10, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
xorl %eax, %eax
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
cmpq %rax, %rcx
je 0x334c0
movss (%r12,%rax,4), %xmm1
movss %xmm1, (%r15,%rax,4)
incq %rax
jmp 0x334aa
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm2
movq %r9, -0x50(%rbp)
movl %edi, -0x3c(%rbp)
movq %rsi, -0x78(%rbp)
movq %r8, -0x70(%rbp)
movq %r10, -0x68(%rbp)
jbe 0x334f5
movaps %xmm2, %xmm1
divss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x33504
sqrtsd %xmm0, %xmm1
jmp 0x33517
movsd 0x17b4b(%rip), %xmm0    # 0x4b048
movsd %xmm0, -0x48(%rbp)
jmp 0x3352e
movss %xmm2, -0x38(%rbp)
callq 0x2290
movss -0x38(%rbp), %xmm2
movapd %xmm0, %xmm1
cvtss2sd %xmm2, %xmm0
leaq 0x21f9c(%rip), %rdi     # 0x554be
movsd %xmm1, -0x48(%rbp)
movb $0x2, %al
callq 0x20f0
testq %rbx, %rbx
leaq 0x2200d(%rip), %rax     # 0x55545
leaq 0x21fbf(%rip), %r13     # 0x554fe
cmoveq %rax, %r13
cmpl $0x0, -0x2c(%rbp)
je 0x3356f
testq %rbx, %rbx
leaq 0x21f8e(%rip), %rax     # 0x554e1
leaq 0x21f94(%rip), %rsi     # 0x554ee
cmoveq %rax, %rsi
leaq -0xf0(%rbp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2260
leaq -0x1c0(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2260
cmpl $0x0, -0x2c(%rbp)
je 0x335a1
leaq 0x1dbc0(%rip), %rsi     # 0x51150
leaq -0xf0(%rbp), %rdi
callq 0x2210
movq %rax, %r13
jmp 0x335a4
xorl %r13d, %r13d
leaq 0x1dba5(%rip), %rsi     # 0x51150
leaq -0x1c0(%rbp), %rdi
callq 0x2210
movq %rax, %r14
leaq 0x21f4d(%rip), %rdi     # 0x5550e
pushq $0x2e
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x2280
movq -0x50(%rbp), %rsi
testq %rsi, %rsi
je 0x335f3
leaq 0x1a8(%rbp), %rax
movq 0x10(%rax), %rdx
movl (%rax), %ecx
movq %r12, %rdi
callq 0x47a64
cvtsd2ss %xmm0, %xmm2
jmp 0x335fb
movss 0x17a09(%rip), %xmm2    # 0x4b004
leaq 0x160(%rbp), %rsi
movl 0x68(%rbp), %r11d
movl %r11d, %eax
movq %rsp, %rdx
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %rdx
movq %rdx, %rsp
movsd 0x1dc7a(%rip), %xmm0    # 0x512a0
movsd -0x48(%rbp), %xmm3
mulsd %xmm3, %xmm0
movl -0x3c(%rbp), %r8d
cvtsi2sd %r8d, %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm1
testq %rbx, %rbx
movq %r13, -0x58(%rbp)
movq %r14, -0x38(%rbp)
je 0x33681
xorl %eax, %eax
testl %r11d, %r11d
movl $0x0, %ecx
cmovgl %r11d, %ecx
movq -0x50(%rbp), %r9
cmpq %rax, %rcx
je 0x3367b
movss (%rbx,%rax,4), %xmm0
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, (%rdx,%rax,8)
incq %rax
jmp 0x3365f
movb $0x54, -0x30(%rbp)
jmp 0x33689
movb $0x52, -0x30(%rbp)
movq -0x50(%rbp), %r9
cvtsd2ss %xmm3, %xmm0
subq $0x230, %rsp            # imm = 0x230
leaq 0x188(%rsp), %rdi
pushq $0x9
popq %rcx
rep  movsq (%rsi), %es:(%rdi)
leaq 0xb8(%rsp), %rdi
pushq $0x1a
popq %rcx
leaq 0x90(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x1a8(%rbp), %r10
movups (%r10), %xmm5
movups 0x10(%r10), %xmm4
movups 0x20(%r10), %xmm3
movups %xmm3, 0x1f0(%rsp)
movups %xmm4, 0x1e0(%rsp)
movups %xmm5, 0x1d0(%rsp)
leaq 0x10(%rbp), %r14
movups (%r14), %xmm6
movups 0x10(%r14), %xmm5
movups 0x20(%r14), %xmm4
movups 0x2c(%r14), %xmm3
movups %xmm3, 0x64(%rsp)
movups %xmm4, 0x58(%rsp)
movups %xmm5, 0x48(%rsp)
movups %xmm6, 0x38(%rsp)
movl 0x1f8(%rbp), %ebx
movl %ebx, 0x220(%rsp)
movq 0x1f0(%rbp), %rax
movq %rax, 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 %r11d, 0x90(%rsp)
movl 0x58(%rbp), %ecx
movl %ecx, 0x80(%rsp)
movq 0x50(%rbp), %r13
movq %r13, 0x78(%rsp)
movq %r9, 0x30(%rsp)
movq %r12, 0x28(%rsp)
movq -0x58(%rbp), %rcx
movq %rcx, 0x20(%rsp)
movq -0x38(%rbp), %rcx
movq %rcx, 0x18(%rsp)
movl -0x2c(%rbp), %ecx
movl %ecx, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq -0x68(%rbp), %rcx
movq %rcx, (%rsp)
movzbl -0x30(%rbp), %edi
movl %r8d, %esi
xorl %ecx, %ecx
movss %xmm0, -0x48(%rbp)
movq %r10, %rbx
movq -0x78(%rbp), %r8
movq -0x70(%rbp), %r9
movss %xmm2, -0x30(%rbp)
movss %xmm1, -0x5c(%rbp)
callq 0x3395f
addq $0x230, %rsp            # imm = 0x230
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x3390e
subq $0x230, %rsp            # imm = 0x230
leaq 0x188(%rsp), %rdi
pushq $0x9
popq %rcx
leaq 0x160(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0xb8(%rsp), %rdi
pushq $0x1a
popq %rcx
leaq 0x90(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x1f0(%rsp)
movups %xmm1, 0x1e0(%rsp)
movups %xmm0, 0x1d0(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups 0x2c(%r14), %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 %r13, 0x78(%rsp)
movq -0x50(%rbp), %rcx
movq %rcx, 0x30(%rsp)
movq %r12, 0x28(%rsp)
movq %r15, 0x8(%rsp)
movq -0x58(%rbp), %rcx
movq %rcx, 0x20(%rsp)
movq -0x38(%rbp), %rcx
movq %rcx, 0x18(%rsp)
movl -0x2c(%rbp), %ecx
movl %ecx, 0x10(%rsp)
movq -0x68(%rbp), %rcx
movq %rcx, (%rsp)
pushq $0x43
popq %rdi
movl -0x3c(%rbp), %esi
movq -0x78(%rbp), %r8
movq -0x70(%rbp), %r9
xorl %edx, %edx
movq %rax, %rcx
movss -0x48(%rbp), %xmm0
movss -0x5c(%rbp), %xmm1
movss -0x30(%rbp), %xmm2
callq 0x3395f
addq $0x230, %rsp            # imm = 0x230
leaq 0x2161e(%rip), %rdi     # 0x54f33
leaq -0x1c0(%rbp), %rsi
xorl %eax, %eax
callq 0x20f0
movq -0x38(%rbp), %rdi
callq 0x20c0
cmpl $0x0, -0x2c(%rbp)
je 0x33950
leaq 0x21700(%rip), %rdi     # 0x55039
leaq -0xf0(%rbp), %rsi
xorl %eax, %eax
callq 0x20f0
movq -0x58(%rbp), %rdi
callq 0x20c0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq