// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/simulation.c
// Function: Simulate_ensemble_Cart
void Simulate_ensemble_Cart(int N_struct, float factor, char *name,
			    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,
			    int anhar)
{
  float *sigma2;
  if(anhar){sigma2=NM.sigma2_anhar;}
  else{sigma2=NM.sigma2;}

  if(natoms!=Ref.N_ref){
    printf("WARNING, cannot simulate Cartesian ensemble\n"); return;
  }
  idum=IDUM;
  int i, k, n3=3*natoms, N_Cart=Ref.N_Cart, N_ref=Ref.N_ref;

  atom atoms_sim[natoms]; float mass[natoms];
  for(i=0; i<natoms; i++){
    atoms_sim[i]=atoms[i];
    mass[i]=Mass(atoms+i);
  }
  float coord_all_1[n3], coord_all[n3];
  Write_all_coord_atom(coord_all_1, atoms, natoms);
  float coord_ref_1[N_Cart]; // coord_ref[N_Cart];
  Write_ref_coord_atom(coord_ref_1, N_ref, atoms, Ref.atom_num);

  // Open files
  char name_pdb[100], name_out[200];
  sprintf(name_pdb, "%s_%s_ensemble_Cart.pdb", nameout, name);
  FILE *file_pdb=fopen(name_pdb, "w");
  sprintf(name_out, "%s_%s_ensemble_Cart.dat", nameout, name);
  FILE *file_out=fopen(name_out, "w");
  fprintf(file_out, "#struct rmsd\n");
  if(anhar){
    fprintf(file_out, "# Omega2 corrected for anharmonicity\n");
    fprintf(file_pdb, "REMARK Omega2 corrected for anharmonicity\n");
  }

  // Initialization for Examine_confchange
  if(Ini_ch){
    Allocate_tors(&Diff_s, naxes, N_Cart, NM.N);
    ali_sim.alignres=malloc(nres*sizeof(int));
    Ini_ch=0;
  }
  ali_sim.seq_id=100; ali_sim.mammoth=0;
  for(i=0; i<nres; i++)ali_sim.alignres[i]=i;
  char summary3[400];
  sprintf(summary3, "Summary_%s_ensemble.dat", nameout);

  struct ali_atoms ali_a; Copy_ali(&ali_a, Ref);
  float dx[N_Cart], sigma[NM.N];
  for(k=0; k<NM.N; k++){
    if(sigma2[k]>0){sigma[k]=sqrt(sigma2[k]);}
    else{sigma[k]=0;}
  }
  // Write initial PDB
  Print_PDB(file_pdb, atoms, natoms, coord_all_1, seq, 0, 0.00);
  fprintf(file_out, "%d %.3f\n", 0, 0.0);
  for(k=1; k<=N_struct; k++){
    Extract_dx(dx, NM.Cart, sigma, NM.N, N_Cart, factor, &idum);
    for(i=0; i<N_Cart; i++){
      coord_all[i]=coord_ref_1[i]+dx[i];
    }
    float rmsd=rmsd_mclachlan_f(coord_all_1, coord_all, mass, natoms);
    fprintf(file_out, "%d %.3f\n", k, rmsd);
    Print_PDB(file_pdb, atoms, natoms, coord_all, seq, k, rmsd);
    Put_atoms(atoms_sim, coord_all, natoms);
    /*Examine_confchange(&Diff_s, bonds, axe, NULL, 0, summary3, nameout, "",
		       atoms, coord_ref_1, seq, nres, N_diso, natoms,
		       atoms_sim, coord_ref, seq, nres, N_diso, natoms,  //&J, 
		       Ref, ali_a, Int_list, N_int, INT_TYPE, s0, NM.N, NM,
		       k, ali_sim, Para_simul, k, NULL, NULL, NULL, 0, anhar);
    */
  }
  printf("Distances printed in %s\n", name_out); fclose(file_out);
  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
subq $0x3e0, %rsp            # imm = 0x3E0
movl 0x1d8(%rbp), %eax
movq 0x1d0(%rbp), %rax
movq 0x1c8(%rbp), %rax
movl 0x1c0(%rbp), %eax
movq 0x1b8(%rbp), %rax
leaq 0x188(%rbp), %rax
movq %rax, -0x3a8(%rbp)
leaq 0x70(%rbp), %rax
movq %rax, -0x3a0(%rbp)
movl 0x68(%rbp), %eax
movl 0x60(%rbp), %eax
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movl %edi, -0x4(%rbp)
movss %xmm0, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movss %xmm1, -0x30(%rbp)
cmpl $0x0, 0x1d8(%rbp)
je 0x4af00
movq -0x3a0(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x4af0f
movq -0x3a0(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x3a8(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl (%rcx), %eax
je 0x4af30
leaq 0x3541e(%rip), %rdi     # 0x80342
movb $0x0, %al
callq 0x10d0
jmp 0x4b4f6
movq -0x3a8(%rbp), %rax
movq $-0xb2a3, 0x5158e(%rip) # imm = 0xFFFF4D5D
movl -0x1c(%rbp), %edx
movl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
movl %ecx, -0x44(%rbp)
movl 0x4(%rax), %ecx
movl %ecx, -0x48(%rbp)
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x1c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x58(%rbp)
imulq $0x70, %rax, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x3b8(%rbp)
movq %rcx, %rsp
movq %rax, -0x60(%rbp)
movl -0x1c(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x3b0(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4b006
movq -0x3b8(%rbp), %rdi
movslq -0x3c(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x3c(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rsi
movl $0x70, %edx
callq 0x1160
movq -0x18(%rbp), %rdi
movslq -0x3c(%rbp), %rax
imulq $0x70, %rax, %rax
addq %rax, %rdi
callq 0x351c0
movq -0x3b0(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4afa4
movl -0x44(%rbp), %eax
leaq 0xf(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x3d0(%rbp)
movq %rdi, %rsp
movq %rax, -0x70(%rbp)
movl -0x44(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x3c8(%rbp)
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x4a300
movq -0x3a8(%rbp), %rax
movl -0x48(%rbp), %ecx
leaq 0xf(,%rcx,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rdi
subq %rdx, %rdi
movq %rdi, -0x3c0(%rbp)
movq %rdi, %rsp
movq %rcx, -0x80(%rbp)
movl -0x4c(%rbp), %esi
movq -0x18(%rbp), %rdx
movq 0x28(%rax), %rcx
callq 0x4a130
leaq -0xf0(%rbp), %rdi
movq 0x1d0(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x352c4(%rip), %rsi     # 0x8036f
movb $0x0, %al
callq 0x1200
leaq -0xf0(%rbp), %rdi
leaq 0x312b2(%rip), %rsi     # 0x7c372
callq 0x11b0
movq %rax, -0x1c8(%rbp)
leaq -0x1c0(%rbp), %rdi
movq 0x1d0(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x352a2(%rip), %rsi     # 0x80387
movb $0x0, %al
callq 0x1200
leaq -0x1c0(%rbp), %rdi
leaq 0x31278(%rip), %rsi     # 0x7c372
callq 0x11b0
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rdi
leaq 0x3528b(%rip), %rsi     # 0x8039f
movb $0x0, %al
callq 0x1150
cmpl $0x0, 0x1d8(%rbp)
je 0x4b14e
movq -0x1d0(%rbp), %rdi
leaq 0x350f2(%rip), %rsi     # 0x80224
movb $0x0, %al
callq 0x1150
movq -0x1c8(%rbp), %rdi
leaq 0x35103(%rip), %rsi     # 0x8024a
movb $0x0, %al
callq 0x1150
cmpl $0x0, 0x40d2f(%rip)     # 0x8be84
je 0x4b190
movq -0x3a0(%rbp), %rax
movl -0x2c(%rbp), %esi
movl -0x48(%rbp), %edx
movl (%rax), %ecx
leaq 0x5136b(%rip), %rdi     # 0x9c4d8
callq 0x163a0
movslq 0x60(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, 0x513aa(%rip)     # 0x9c530
movl $0x0, 0x40cf4(%rip)     # 0x8be84
movss 0x2af18(%rip), %xmm0    # 0x760b0
movss %xmm0, 0x51378(%rip)    # 0x9c518
movl $0x0, 0x5138e(%rip)     # 0x9c538
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x60(%rbp), %eax
jge 0x4b1d5
movl -0x3c(%rbp), %edx
movq 0x5136d(%rip), %rax     # 0x9c530
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4b1b1
movq 0x1d0(%rbp), %rdx
leaq 0x351ca(%rip), %rsi     # 0x803ad
xorl %eax, %eax
leaq -0x360(%rbp), %rdi
callq 0x1200
movq -0x3a8(%rbp), %rax
subq $0x30, %rsp
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x380(%rbp), %rdi
callq 0x4b500
movq -0x3a0(%rbp), %rax
addq $0x30, %rsp
movl -0x48(%rbp), %ecx
leaq 0xf(,%rcx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x3e0(%rbp)
movq %rdx, %rsp
movq %rcx, -0x388(%rbp)
movl (%rax), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x3d8(%rbp)
movq %rcx, %rsp
movq %rax, -0x390(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x3a0(%rbp), %rcx
movl -0x40(%rbp), %eax
cmpl (%rcx), %eax
jge 0x4b2ed
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x4b2cd
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
movq -0x3d8(%rbp), %rax
cvtsd2ss %xmm0, %xmm0
movslq -0x40(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x4b2e0
movq -0x3d8(%rbp), %rax
movslq -0x40(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
jmp 0x4b2e2
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4b27e
movq -0x3d0(%rbp), %rcx
movq -0x1c8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq 0x58(%rbp), %r8
xorl %r9d, %r9d
xorps %xmm0, %xmm0
callq 0x49a60
movq -0x1d0(%rbp), %rdi
leaq 0x350a6(%rip), %rsi     # 0x803c5
xorl %edx, %edx
xorps %xmm0, %xmm0
movb $0x1, %al
callq 0x1150
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x4(%rbp), %eax
jg 0x4b453
movq -0x3d8(%rbp), %rdx
movq -0x3e0(%rbp), %rdi
movq -0x3a0(%rbp), %rax
movq 0x38(%rax), %rsi
movl (%rax), %ecx
movl -0x48(%rbp), %r8d
movss -0x8(%rbp), %xmm0
leaq 0x51167(%rip), %r9      # 0x9c4d0
callq 0x49e70
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x4b3b8
movq -0x3c8(%rbp), %rax
movq -0x3e0(%rbp), %rcx
movq -0x3c0(%rbp), %rdx
movslq -0x3c(%rbp), %rsi
movss (%rdx,%rsi,4), %xmm0
movslq -0x3c(%rbp), %rdx
addss (%rcx,%rdx,4), %xmm0
movslq -0x3c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4b375
movq -0x3c8(%rbp), %rsi
movq -0x3b0(%rbp), %rdx
movq -0x3d0(%rbp), %rdi
movl -0x1c(%rbp), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x394(%rbp)
movq -0x1d0(%rbp), %rdi
movl -0x40(%rbp), %edx
movss -0x394(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x34fc7(%rip), %rsi     # 0x803c5
movb $0x1, %al
callq 0x1150
movq -0x3c8(%rbp), %rcx
movq -0x1c8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq 0x58(%rbp), %r8
movl -0x40(%rbp), %r9d
movss -0x394(%rbp), %xmm0
callq 0x49a60
movq -0x3b8(%rbp), %rdi
movq -0x3c8(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x4a270
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4b332
leaq -0x1c0(%rbp), %rsi
leaq 0x34e3a(%rip), %rdi     # 0x8029b
movb $0x0, %al
callq 0x10d0
movq -0x1d0(%rbp), %rdi
callq 0x10a0
leaq -0xf0(%rbp), %rsi
leaq 0x34f4c(%rip), %rdi     # 0x803ce
movb $0x0, %al
callq 0x10d0
movq -0x1c8(%rbp), %rdi
callq 0x10a0
cmpl $0x0, 0x409e8(%rip)     # 0x8be84
jne 0x4b4ef
subq $0x40, %rsp
movups 0x5105f(%rip), %xmm0    # 0x9c508
movq %rsp, %rax
movups %xmm0, 0x30(%rax)
movups 0x51041(%rip), %xmm0    # 0x9c4f8
movups %xmm0, 0x20(%rax)
movups 0x51026(%rip), %xmm0    # 0x9c4e8
movups %xmm0, 0x10(%rax)
movups 0x5100b(%rip), %xmm0    # 0x9c4d8
movups %xmm0, (%rax)
callq 0x16450
addq $0x40, %rsp
movq 0x51050(%rip), %rdi     # 0x9c530
callq 0x1040
movl $0x1, 0x40995(%rip)     # 0x8be84
movq -0x58(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)