// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/simulation.c
// Function: Torsional_confchange
void Torsional_confchange(double *diff_phi, char *diff_type,
			  struct bond *bonds_ini,
			  struct Jacobian *J, struct Reference Ref1,
			  struct ali_atoms ali_a,
			  double Tors_fluct,
			  atom *atoms1, int natoms1, char *nameout,
			  struct axe *axes, int naxes,
			  struct residue *seq, int nres,
			  struct chain *chains, int Nchain, 
			  atom *atoms2, int natoms2,
			  struct Para_simul Para_simul,
			  struct Normal_Mode *NM,
			  char *mode_name, int NMODES, float rmsd_thr)
{
  int i, a;
  int IT_MAX=Para_simul.NSTEPS; // 100 
  float STEP_MAX=Para_simul.STEP_MAX, STEP_MIN=Para_simul.STEP_MIN; //0.3 0.001
  float A_MAX=Para_simul.ANGLE, PDB_STEP=0.33;
  printf("Interpolating conformation change with %d %s modes\n",
	 NMODES, mode_name);
  
  // Initial bonds
  Set_bonds_measure(bonds_ini, natoms1, atoms1);
  struct bond bonds[natoms1], bonds_tmp[natoms1];
  Copy_bonds(bonds, bonds_ini, natoms1);
  printf("Internal coordinates of initial structure\n");
  double phi_ini[naxes], phi_opt[naxes]; 
  Internal_coordinates(phi_ini, naxes, bonds_ini, natoms1);
  double diff_phi0[naxes]; for(i=0; i<naxes; i++)diff_phi0[i]=0;

  // Set references 
  /*char SEL[4]="EB"; // "EB" "ALL"
  struct Reference Ref1, Ref2;
  int N_ref=Set_reference(&Ref1, 0, SEL, atoms1, 0, natoms1);
  printf("Change reference atoms to %s n=%d\n",SEL, Ref1.N_ref);
  int N_Cart=3*N_ref; Ref1.N_Cart=N_Cart;
  int first_kin[naxes], last_kin[naxes];
  Change_kin(first_kin, last_kin, axes, naxes, natoms1, Ref1);
  struct Jacobian J; Allocate_Jacobian(&J, naxes, Ref1.N_Cart);
  */
  //int N_ref=Ref1.N_ref;
  int N_ali=ali_a.N_ref, N_Cart=3*N_ali;
  double Mass_tot=0; for(i=0; i<Ref1.N_ref; i++)Mass_tot+=Ref1.mass_atom[i];

  float coord_ref_1[N_Cart], coord_ref_2[N_Cart];
  Write_ref_coord_atom(coord_ref_1, N_ali, atoms1, ali_a.ali1);
  Write_ref_coord_atom(coord_ref_2, N_ali, atoms2, ali_a.ali2);
  float coord1[N_Cart], coord2[N_Cart], coord_pdb[N_Cart]; //coord_kin[N_Cart]; 
  for(i=0; i<N_Cart; i++){
    coord1[i]=coord_ref_1[i]; coord2[i]=coord1[i];
    coord_pdb[i]=coord1[i]; //coord_kin[i]=coord1[i];
  }


  float *coord_new=coord1, *coord_old=coord2, *mass_ref=Ref1.mass_atom;
  float coord_all[3*natoms1]; Put_coord(coord_all, bonds_ini, natoms1);
  float Ene=Energy_clashes(coord_all, natoms1);

  // Print rmsd
  char namermsd[200];
  sprintf(namermsd, "%s_%s_rmsd.dat", nameout, diff_type);
  FILE *file_rmsd=fopen(namermsd, "w");
  printf("Opening %s\n", namermsd);
  fprintf(file_rmsd,
	  "# Interpolating conformation change with %d %s modes\n",
	  NMODES, mode_name);
  fprintf(file_rmsd,"# RMSD_step: max= %.2g min= %.2g max. steps %d\n",
	  STEP_MAX, STEP_MIN, IT_MAX);
  fprintf(file_rmsd,"# E_clash(PDB)= %.2g\n", Ene);
  // Superimpose second structure to first one
  float RMSD_kf=rmsd_mclachlan_f(coord_ref_1, coord_ref_2, ali_a.mass, N_ali);
  float RMSD_ki=0, RMSD_step=0, RMSD_opt=RMSD_kf;
  printf("Initial RMSD: %.2f\n\n", RMSD_kf);
  fprintf(file_rmsd,"# RMSD= %.3f\n", RMSD_kf);
  fprintf(file_rmsd,"# RMSD_ki RMSD_kf RMSD_step E_clash factor accept\n");
  fprintf(file_rmsd, "%.3f\t%.3f\t%.3f\t%.2g\t%.2g\t%d\n",
	  RMSD_ki, RMSD_kf, RMSD_step, Ene, 1.0, 1);

  // Opening file for printing PDB
  FILE *file_pdb=NULL;
  float coord_all_1[3*natoms1], mass[natoms1], rmsd;
  for(i=0; i<natoms1; i++)mass[i]=Mass(atoms1+i);
  if(strcmp(diff_type, "standard")!=0){
    char pdbout[200];
    sprintf(pdbout, "%s_confchange_%s.pdb", nameout, diff_type);
    file_pdb=fopen(pdbout, "w");
    printf("Writing trajectory in PDB format in %s\n", pdbout);
    Print_seqres(file_pdb, chains, Nchain);
    Put_coord(coord_all_1, bonds_ini, natoms1);
    Print_PDB(file_pdb, atoms1, natoms1, coord_all_1, seq, 0, 0.0);
  }

  float c_amax[NMODES];
  for (i=0; i<NMODES; i++){
    float *mode=NM->Tors[i], max=fabs(mode[0]); 
    for(a=1; a<naxes; a++)if(fabs(mode[a])>max)max=fabs(mode[a]);
    c_amax[i]=A_MAX/max; // Maximum coefficient of mode i for phi<A_MAX
  }

  int accept=1, iter, exit=0, k_pdb=0;
  //float FRAC=0.0;
  float Mass_sqrt=sqrt(Mass_tot), c_thr=rmsd_thr*Mass_sqrt;
  double skip_tot=0; int nskip=0;
  for(iter=0; iter<IT_MAX; iter++){

    /*// Update Jacobian matrix WRONG!!!!
      rmsd=rmsd_mclachlan_f(coord_kin, coord_old, mass_ref, N_ali);
    if((rmsd>RMSD_TOL)){
      printf("Computing kinetic energy\n");
      // Kinetic energy must be computed with new atoms!!!!
      for(i=0;i<N_Cart;i++)coord_kin[i]=coord_old[i];
      atom atoms_t[natoms1]; Copy_atoms_bonds(atoms_t, bonds, natoms1);
      Compute_kinetic(J, axes, naxes, atoms_t, natoms1, Ref1, 0);
      }*/

    // Difference of coordinates
    float Diff_Cart[N_Cart];
    for(i=0;i<N_Cart;i++)Diff_Cart[i]=coord_ref_2[i]-coord_old[i];
    float tors_coeff[naxes];
    for(i=0; i<naxes; i++){
	tors_coeff[i]=
	  Scalar_product_weighted(Diff_Cart, J->Jacobian_ar[i],
				  Ref1.mass_coord, N_Cart);
      }

    // Compute angles
    double diff_step[naxes], diff_all[naxes];
    for(a=0; a<naxes; a++)diff_step[a]=0;
    double rstep=0, factor=1, excess=1;
    float c_lin[NMODES];
    for (i=0; i<NMODES; i++){
      float *mode=NM->Tors[i]; 
      double c=0; for(a=0; a<naxes; a++)c+=tors_coeff[a]*mode[a];
      if(fabs(c)>excess*c_amax[i])excess=fabs(c)/c_amax[i];
      c_lin[i]=c; rstep+=c*c;
    }
    rstep=1.1*sqrt(rstep/Mass_tot);
    if(rstep<STEP_MIN){exit=1; goto print;}
    factor=rstep/STEP_MAX;
    if(excess>factor)factor=excess;

    //float thr=FRAC*RMSD_kf*Mass_sqrt; if(thr<c_thr)thr=c_thr;
    int skip=0;
    for (i=0; i<NMODES; i++){
      float c=c_lin[i]; if(factor>1)c/=factor;
      if(fabs(c)<c_thr){skip++; continue;}
      float *mode=NM->Tors[i];
      for(a=0; a<naxes; a++)diff_step[a]+=c*mode[a];
    }
    skip_tot+=skip; nskip++;
    float max=0;
    for(i=0; i<naxes; i++)if(fabs(diff_step[i])>max)max=fabs(diff_step[i]);
    if(max>A_MAX){
      float f=A_MAX/max;
      printf("WARNING, too large angle= %.2f ", max);
      printf("Reducing d_phi by a factor %.2g\n", f);
      rstep/=f; for(i=0; i<naxes; i++)diff_step[i]*=f;
    }
    if(rstep<STEP_MIN){exit=1; goto print;}

    // Move atoms
    float reduce_step=1; factor=1;
    while(1){ // loop on amplitudes
      for(i=0; i<naxes; i++)diff_all[i]=diff_phi0[i]+diff_step[i];
      Copy_bonds(bonds_tmp, bonds_ini, natoms1);
      Build_up(bonds_tmp, natoms1, diff_all, naxes);
      accept=Write_RMSD(&reduce_step, &RMSD_opt, &RMSD_kf,
			STEP_MIN, STEP_MAX, factor, iter, file_rmsd,
			bonds_tmp, coord_all, natoms1, ali_a,
			coord_new,coord_old,coord_ref_1,coord_ref_2);
      if(accept)break;
      factor*=reduce_step; rstep*=reduce_step;
      if(rstep<STEP_MIN){
	printf("Too small amplitude (%.2g), exiting\n", factor);
	accept=0; break;
      }
      printf("Reducing amplitude by factor %.2g\n", reduce_step);
      for(i=0; i<naxes; i++)diff_step[i]*=reduce_step;
    } // End loop amplitude 


    if(accept==0){
      exit=1;
    }else{
      exit=(RMSD_opt < RMSD_TOL);
      // Store conformation
      Copy_bonds(bonds, bonds_tmp, natoms1);
      Internal_coordinates(phi_opt, naxes, bonds, natoms1);
      for(i=0; i<naxes; i++)diff_phi0[i]=phi_opt[i]-phi_ini[i];
    }

    // Print PDB
  print:
    if(file_pdb){
      rmsd=rmsd_mclachlan_f(coord_pdb, coord_new, mass_ref, N_ali);
      if((rmsd > PDB_STEP)|| exit){
	k_pdb++;
	for(i=0; i<N_Cart; i++)coord_pdb[i]=coord_new[i];
	RMSD_ki=rmsd_mclachlan_f(coord_all_1, coord_all, mass, natoms1);
	Print_PDB(file_pdb,atoms1,natoms1,coord_all,seq,k_pdb,RMSD_ki);
      }
    }
    printf("\n");
    if(exit){
      printf("Exiting iterations, rmsd= %.2f\n",RMSD_opt);
      break;
    }

    float *tmp=coord_old; coord_old=coord_new; coord_new=tmp;

  }

  // Take final coordinates from bonds
  fprintf(file_rmsd, "# Final RMSD:\n");
  float reduce_step;
  Write_RMSD(&reduce_step, &RMSD_opt, &RMSD_kf, STEP_MIN, 100, // = STEP_MAX
	     1.00, iter, file_rmsd, bonds, coord_all, natoms1, ali_a,
	     coord_new,coord_ref_1,coord_ref_1,coord_ref_2);
  printf("Final RMSD= %.2f\n", RMSD_kf);

  printf("Storing internal coordinates\n");
  Internal_coordinates(phi_opt, naxes, bonds, natoms1);
  for(i=0; i<naxes; i++)diff_phi[i]=phi_opt[i]-phi_ini[i];
  Periodic_angles(diff_phi, axes, naxes);

  Copy_bonds(bonds, bonds_ini, natoms1);
  Build_up(bonds, natoms1, diff_phi, naxes);
  fprintf(file_rmsd, "# Reconstructed RMSD:\n");
  Write_RMSD(&reduce_step, &RMSD_opt, &RMSD_kf, STEP_MIN, 100,
	     1.00, iter, file_rmsd, bonds, coord_all, natoms1,
	     ali_a, coord_new, coord_ref_1,coord_ref_1,coord_ref_2);
  printf("%d %s modes, reconstructed RMSD= %.2f\n", NMODES,mode_name,RMSD_kf);
  printf("Mean number of skipped modes out of %d: %.1f\n",
	 NMODES, skip_tot/nskip);
  fprintf(file_rmsd, "# Mean number of skipped modes out of %d: %.1f",
	  NMODES, skip_tot/nskip);
  fprintf(file_rmsd, " threshold= %.3f A\n", rmsd_thr);


  fclose(file_rmsd);
  if(file_pdb)fclose(file_pdb);
  //Empty_Ref(&Ref1);
  //Change_kin_back(axes, naxes, first_kin, last_kin);
  //Empty_Jacobian(J);
  if(0)Compute_kinetic(J, axes, naxes, atoms1, natoms1, Ref1,0);
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x328, %rsp            # imm = 0x328
movss %xmm1, -0xbc(%rbp)
movl %r9d, %r12d
movq %r8, %r14
movq %rcx, -0x1b0(%rbp)
movq %rdx, %rbx
movq %rsi, -0x90(%rbp)
movq %rdi, -0x168(%rbp)
movl 0xf8(%rbp), %esi
movq 0xf0(%rbp), %rdx
movss 0xac(%rbp), %xmm0
movss %xmm0, -0xc4(%rbp)
movss 0xb0(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss 0xb4(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movl 0x70(%rbp), %r13d
movl 0xb8(%rbp), %eax
movl %eax, -0x2c(%rbp)
leaq 0x2485c(%rip), %rdi     # 0x5507a
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x20f0
movq %rbx, %rdi
movl %r12d, %esi
movq %r14, -0xd0(%rbp)
movq %r14, %rdx
callq 0x139f6
movl %r12d, %ecx
movq %rsp, %rdi
movq %rcx, -0x70(%rbp)
imulq $0xc0, %rcx, %rax
subq %rax, %rdi
movq %rdi, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x158(%rbp)
movq %rcx, %rsp
movq %rdi, -0xf8(%rbp)
movq %rbx, %rsi
movl %r12d, %edx
callq 0x301ca
leaq 0x2536c(%rip), %rdi     # 0x55be9
callq 0x2090
movq %rsp, %rdi
leaq 0xf(,%r13,8), %r14
andq $-0x10, %r14
subq %r14, %rdi
movq %rdi, %rsp
movq %rsp, %rax
subq %r14, %rax
movq %rax, -0x130(%rbp)
movq %rax, %rsp
movq %rdi, -0x138(%rbp)
movl %r13d, %esi
movq %rbx, -0xe8(%rbp)
movq %rbx, %rdx
movq %r12, -0x80(%rbp)
movl %r12d, %ecx
callq 0x154b8
movq %rsp, %rdx
movq %r14, -0x198(%rbp)
subq %r14, %rdx
movq %rdx, %rsp
testl %r13d, %r13d
movl $0x0, %ebx
cmovgl %r13d, %ebx
cmpq %r15, %rbx
je 0x308f2
andq $0x0, (%rdx,%r15,8)
incq %r15
jmp 0x308e3
leaq 0x40(%rbp), %r15
movl 0x18(%r15), %eax
movq %rax, -0x108(%rbp)
leaq 0x10(%rbp), %rcx
movl (%rcx), %eax
movq 0x10(%rcx), %rsi
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
xorpd %xmm0, %xmm0
movsd %xmm0, -0xb8(%rbp)
cmpq %rcx, %rax
je 0x3093d
cvtss2sd (%rsi,%rcx,4), %xmm0
movsd -0xb8(%rbp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
incq %rcx
jmp 0x30916
movq %rsi, -0x178(%rbp)
movq %rdx, -0xa8(%rbp)
movq -0x108(%rbp), %r15
leal (%r15,%r15,2), %r13d
leaq 0xf(,%r13,4), %r12
andq $-0x10, %r12
movq %rsp, %rdi
subq %r12, %rdi
movq %rdi, %rsp
movq %rsp, %r14
subq %r12, %r14
movq %r14, %rsp
leaq 0x40(%rbp), %rax
movq (%rax), %rcx
movq %rdi, -0xb0(%rbp)
movl %r15d, %esi
movq -0xd0(%rbp), %rdx
callq 0x2f97d
leaq 0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movq %r14, -0x88(%rbp)
movq %r14, %rdi
movl %r15d, %esi
movq 0x98(%rbp), %rdx
callq 0x2f97d
movq %rsp, %rdx
subq %r12, %rdx
movq %rdx, %rsp
movq %rsp, %r14
subq %r12, %r14
movq %r14, %rsp
movq %rsp, %rsi
movq %r12, -0x190(%rbp)
subq %r12, %rsi
movq %rsi, %rsp
xorl %eax, %eax
testl %r13d, %r13d
movq %r13, -0x1a8(%rbp)
cmovlel %eax, %r13d
movq -0xb0(%rbp), %rcx
cmpq %rax, %r13
je 0x30a0a
movss (%rcx,%rax,4), %xmm0
movss %xmm0, (%rdx,%rax,4)
movss %xmm0, (%r14,%rax,4)
movss %xmm0, (%rsi,%rax,4)
incq %rax
jmp 0x309eb
movq %r13, -0xd8(%rbp)
movq %rsi, -0xa0(%rbp)
movq %rdx, -0x40(%rbp)
movq -0x80(%rbp), %r12
leal (%r12,%r12,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rax, -0x120(%rbp)
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
movq %r15, %rdi
movq -0xe8(%rbp), %rsi
movl %r12d, %edx
callq 0x2f358
movq %r15, -0xf0(%rbp)
movq %r15, %rdi
movl %r12d, %esi
callq 0x2f3a6
movss %xmm0, -0x78(%rbp)
leaq 0x245ed(%rip), %rsi     # 0x5505d
xorl %r13d, %r13d
leaq -0x350(%rbp), %r12
movq %r12, %rdi
movq 0x60(%rbp), %rdx
movq -0x90(%rbp), %rcx
xorl %eax, %eax
callq 0x2260
leaq 0x206ba(%rip), %rsi     # 0x51150
movq %r12, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x245c4(%rip), %rdi     # 0x5506c
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x245bf(%rip), %rsi     # 0x55078
movq %r15, %rdi
movl 0xf8(%rbp), %edx
movq 0xf0(%rbp), %rcx
xorl %eax, %eax
callq 0x2190
cvtss2sd -0xc4(%rbp), %xmm0
cvtss2sd -0x50(%rbp), %xmm1
leaq 0x245ca(%rip), %rsi     # 0x550ae
movq %r15, %rdi
movsd %xmm0, -0x170(%rbp)
movsd %xmm1, -0x118(%rbp)
movl -0x2c(%rbp), %edx
movb $0x2, %al
callq 0x2190
cvtss2sd -0x78(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x245cc(%rip), %rsi     # 0x550de
movq %r15, %rdi
movb $0x1, %al
callq 0x2190
leaq 0x40(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0xb0(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x108(%rbp), %rcx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
movss %xmm0, -0x34(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x78(%rbp)
leaq 0x24598(%rip), %rdi     # 0x550f4
movb $0x1, %al
callq 0x20f0
leaq 0x2459f(%rip), %rsi     # 0x55109
movq %r15, %rdi
movsd -0x78(%rbp), %xmm0
movb $0x1, %al
callq 0x2190
leaq 0x24597(%rip), %rdi     # 0x55117
pushq $0x32
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2280
leaq 0x245b5(%rip), %rsi     # 0x5514a
movsd 0x1a4ab(%rip), %xmm4    # 0x4b048
pushq $0x1
popq %rdx
xorps %xmm0, %xmm0
xorps %xmm2, %xmm2
movq %r15, -0x110(%rbp)
movq %r15, %rdi
movsd -0x78(%rbp), %xmm1
movsd -0x48(%rbp), %xmm3
movb $0x5, %al
callq 0x2190
movq %rsp, %rax
subq -0x120(%rbp), %rax
movq %rax, -0x100(%rbp)
movq %rax, %rsp
movq %rsp, %rcx
movq -0x70(%rbp), %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x150(%rbp)
movq %rcx, %rsp
movq -0x80(%rbp), %rax
testl %eax, %eax
movl $0x0, %r15d
cmovgl %eax, %r15d
movq -0xd0(%rbp), %r12
cmpq %r13, %r15
je 0x30c2f
movq %r12, %rdi
callq 0x233c9
movq -0x150(%rbp), %rax
movss %xmm0, (%rax,%r13,4)
incq %r13
addq $0x70, %r12
jmp 0x30c0c
leaq 0x24531(%rip), %rsi     # 0x55167
movq -0x90(%rbp), %r12
movq %r12, %rdi
callq 0x2180
xorl %r15d, %r15d
testl %eax, %eax
je 0x30ced
leaq 0x24519(%rip), %rsi     # 0x55170
leaq -0x280(%rbp), %r13
movq %r13, %rdi
movq 0x60(%rbp), %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2260
leaq 0x204da(%rip), %rsi     # 0x51150
movq %r13, %rdi
callq 0x2210
movq %rax, %r12
leaq 0x244fd(%rip), %rdi     # 0x55185
movq %r13, %rsi
xorl %eax, %eax
callq 0x20f0
movq %r12, %rdi
movq 0x88(%rbp), %rsi
movl 0x90(%rbp), %edx
callq 0x2f827
movq -0x100(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0x80(%rbp), %r13
movl %r13d, %edx
callq 0x2f358
xorps %xmm0, %xmm0
movq %r12, -0xe0(%rbp)
movq %r12, %rdi
movq -0xd0(%rbp), %rsi
movl %r13d, %edx
movq -0x100(%rbp), %rcx
movq 0x78(%rbp), %r8
xorl %r9d, %r9d
callq 0x2f4bd
jmp 0x30cfc
movq $0x0, -0xe0(%rbp)
movq -0x80(%rbp), %r13
movss -0x4c(%rbp), %xmm2
movq -0x88(%rbp), %r12
movsd -0xb8(%rbp), %xmm0
pushq $0x1
popq %rsi
movl 0xf8(%rbp), %ecx
movl %ecx, %eax
movq %rsp, %rdx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rax, -0x188(%rbp)
subq %rax, %rdx
movq %rdx, -0x78(%rbp)
movq %rdx, %rsp
movl 0x70(%rbp), %eax
cltq
testl %ecx, %ecx
movl $0x0, %edx
cmovgl %ecx, %edx
movq %rdx, -0x90(%rbp)
movaps 0x204d8(%rip), %xmm3    # 0x51230
cmpq -0x90(%rbp), %r15
je 0x30db1
movq 0xe8(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq (%rcx,%r15,8), %rcx
movss (%rcx), %xmm0
andps %xmm3, %xmm0
movq %rsi, %rdx
cmpq %rax, %rdx
jge 0x30d93
movss (%rcx,%rdx,4), %xmm1
andps %xmm3, %xmm1
maxss %xmm0, %xmm1
incq %rdx
movaps %xmm1, %xmm0
jmp 0x30d7a
movaps %xmm2, %xmm1
divss %xmm0, %xmm1
movq -0x78(%rbp), %rcx
movss %xmm1, (%rcx,%r15,4)
incq %r15
movsd -0xb8(%rbp), %xmm0
jmp 0x30d58
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x30dc0
sqrtsd %xmm0, %xmm0
jmp 0x30dc5
callq 0x2290
movq -0x40(%rbp), %rcx
movq -0xd8(%rbp), %rdx
cvtsd2ss %xmm0, %xmm0
mulss -0xbc(%rbp), %xmm0
movss %xmm0, -0x120(%rbp)
xorl %edi, %edi
movl -0x2c(%rbp), %eax
testl %eax, %eax
movl $0x0, %esi
movq %rsi, -0x140(%rbp)
cmovlel %edi, %eax
movl %eax, -0x2c(%rbp)
movl 0x70(%rbp), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rax, -0x180(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x98(%rbp)
movl $0x0, -0xc0(%rbp)
xorl %eax, %eax
cmpl -0x2c(%rbp), %eax
movq %rcx, -0x40(%rbp)
je 0x31474
movq %r14, %rsi
movl %eax, -0x30(%rbp)
movq %rsp, -0x148(%rbp)
movq %rsp, %r14
subq -0x190(%rbp), %r14
movq %r14, %rsp
xorl %eax, %eax
cmpq %rax, %rdx
je 0x30e6e
movss (%r12,%rax,4), %xmm0
subss (%rsi,%rax,4), %xmm0
movss %xmm0, (%r14,%rax,4)
incq %rax
jmp 0x30e53
movq %rsi, -0x160(%rbp)
movq %rsp, %r15
subq -0x180(%rbp), %r15
movq %r15, %rsp
leaq 0x10(%rbp), %rax
movq 0x18(%rax), %r12
xorl %r13d, %r13d
cmpq %r13, %rbx
je 0x30ebe
movq -0x1b0(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdi
movq %r12, %rdx
movq -0x1a8(%rbp), %rcx
callq 0xfd1e
movss %xmm0, (%r15,%r13,4)
incq %r13
jmp 0x30e8d
movq %rsp, %r12
movq -0x198(%rbp), %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
xorl %eax, %eax
movsd 0x1a167(%rip), %xmm5    # 0x4b048
cmpq %rax, %rbx
je 0x30ef0
andq $0x0, (%r12,%rax,8)
incq %rax
jmp 0x30ee1
movq %rsp, %r13
subq -0x188(%rbp), %r13
movq %r13, %rsp
xorps %xmm0, %xmm0
xorl %eax, %eax
movapd %xmm5, %xmm7
cmpq -0x90(%rbp), %rax
je 0x30f96
movq 0xe8(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq (%rcx,%rax,8), %rcx
xorpd %xmm1, %xmm1
xorl %edx, %edx
cmpq %rdx, %rbx
je 0x30f45
movss (%r15,%rdx,4), %xmm2
mulss (%rcx,%rdx,4), %xmm2
cvtss2sd %xmm2, %xmm2
addsd %xmm2, %xmm1
incq %rdx
jmp 0x30f28
movapd %xmm1, %xmm2
andpd 0x202ef(%rip), %xmm2    # 0x51240
movq -0x78(%rbp), %rcx
cvtss2sd (%rcx,%rax,4), %xmm3
movapd %xmm7, %xmm4
mulsd %xmm3, %xmm4
cmpltsd %xmm2, %xmm4
divsd %xmm3, %xmm2
andpd %xmm4, %xmm2
andnpd %xmm7, %xmm4
orpd %xmm2, %xmm4
cvtsd2ss %xmm1, %xmm2
movss %xmm2, (%r13,%rax,4)
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
movapd %xmm4, %xmm7
jmp 0x30f06
divsd -0xb8(%rbp), %xmm0
ucomisd 0x1a0aa(%rip), %xmm0    # 0x4b050
jb 0x30fae
sqrtsd %xmm0, %xmm1
jmp 0x30fc9
movapd %xmm7, -0x70(%rbp)
callq 0x2290
movapd -0x70(%rbp), %xmm7
movsd 0x1a083(%rip), %xmm5    # 0x4b048
movapd %xmm0, %xmm1
movss -0x4c(%rbp), %xmm4
movq -0xa8(%rbp), %rdi
movaps 0x20254(%rip), %xmm6    # 0x51230
mulsd 0x23cc4(%rip), %xmm1    # 0x54ca8
movb $0x1, %r15b
movsd -0x118(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x30ffe
movq -0x80(%rbp), %r13
jmp 0x31373
movsd %xmm1, -0x48(%rbp)
divsd -0x170(%rbp), %xmm1
maxsd %xmm1, %xmm7
xorl %eax, %eax
xorl %ecx, %ecx
cmpq -0x90(%rbp), %rax
je 0x31083
ucomisd %xmm5, %xmm7
movss (%r13,%rax,4), %xmm0
jbe 0x31035
cvtss2sd %xmm0, %xmm0
divsd %xmm7, %xmm0
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, %xmm1
andps %xmm6, %xmm1
movss -0x120(%rbp), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x3104f
incl %ecx
incq %rax
jmp 0x31013
movq 0xe8(%rbp), %rdx
movq 0x40(%rdx), %rdx
movq (%rdx,%rax,8), %rdx
xorl %esi, %esi
cmpq %rsi, %rbx
je 0x3104a
movss (%rdx,%rsi,4), %xmm1
mulss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
addsd (%r12,%rsi,8), %xmm1
movsd %xmm1, (%r12,%rsi,8)
incq %rsi
jmp 0x31060
cvtsi2sd %ecx, %xmm0
movsd -0x98(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x98(%rbp)
xorpd %xmm0, %xmm0
xorl %eax, %eax
movq -0x80(%rbp), %r13
cmpq %rax, %rbx
je 0x310d2
movsd (%r12,%rax,8), %xmm1
movapd %xmm1, %xmm2
andpd 0x20184(%rip), %xmm2    # 0x51240
cvtss2sd %xmm0, %xmm3
ucomisd %xmm3, %xmm2
jbe 0x310cd
cvtsd2ss %xmm1, %xmm0
andps %xmm6, %xmm0
incq %rax
jmp 0x310a5
ucomiss %xmm4, %xmm0
jbe 0x3113a
divss %xmm0, %xmm4
movss %xmm4, -0x70(%rbp)
cvtss2sd %xmm0, %xmm0
leaq 0x240c2(%rip), %rdi     # 0x551ad
movb $0x1, %al
callq 0x20f0
cvtss2sd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq 0x240ca(%rip), %rdi     # 0x551cd
movb $0x1, %al
callq 0x20f0
movsd -0x70(%rbp), %xmm2
movsd 0x19f31(%rip), %xmm5    # 0x4b048
movq -0xa8(%rbp), %rdi
xorl %eax, %eax
cmpq %rax, %rbx
je 0x31141
movsd (%r12,%rax,8), %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, (%r12,%rax,8)
incq %rax
jmp 0x31120
movsd -0x48(%rbp), %xmm1
jmp 0x3114a
movsd -0x48(%rbp), %xmm1
divsd %xmm2, %xmm1
incl -0xc0(%rbp)
movsd -0x118(%rbp), %xmm0
movsd %xmm1, -0x48(%rbp)
ucomisd %xmm1, %xmm0
ja 0x31373
movl $0x3f800000, -0xc8(%rbp) # imm = 0x3F800000
xorl %eax, %eax
cmpq %rax, %rbx
je 0x3118e
movsd (%rdi,%rax,8), %xmm0
addsd (%r12,%rax,8), %xmm0
movsd %xmm0, (%r14,%rax,8)
incq %rax
jmp 0x31173
movq -0x158(%rbp), %r15
movq %r15, %rdi
movq -0xe8(%rbp), %rsi
movl %r13d, %edx
movsd %xmm5, -0x70(%rbp)
callq 0x301ca
movq %r15, %rdi
movl %r13d, %esi
movq %r14, %rdx
movl 0x70(%rbp), %ecx
callq 0x13d70
cvtsd2ss -0x70(%rbp), %xmm2
subq $0x50, %rsp
leaq 0x40(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x20(%rsp)
movups %xmm0, 0x10(%rsp)
movq -0x88(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0xb0(%rbp), %rax
movq %rax, 0x40(%rsp)
movq -0x160(%rbp), %rax
movq %rax, 0x38(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x30(%rsp)
movl %r13d, 0x8(%rsp)
movq -0xf0(%rbp), %rax
movq %rax, (%rsp)
leaq -0xc8(%rbp), %rdi
leaq -0x34(%rbp), %rsi
leaq -0x54(%rbp), %rdx
movss -0x50(%rbp), %xmm0
movss -0xc4(%rbp), %xmm1
movl -0x30(%rbp), %ecx
movq -0x110(%rbp), %r8
movq %r15, %r9
callq 0x31729
addq $0x50, %rsp
testl %eax, %eax
jne 0x312da
cvtss2sd -0xc8(%rbp), %xmm3
movsd -0x70(%rbp), %xmm2
mulsd %xmm3, %xmm2
movsd -0x48(%rbp), %xmm1
mulsd %xmm3, %xmm1
movsd -0x118(%rbp), %xmm0
ucomisd %xmm1, %xmm0
movapd %xmm2, %xmm0
ja 0x31362
movsd %xmm0, -0x70(%rbp)
movsd %xmm1, -0x48(%rbp)
leaq 0x23f80(%rip), %rdi     # 0x55213
movaps %xmm3, %xmm0
movb $0x1, %al
movsd %xmm3, -0x1a0(%rbp)
callq 0x20f0
movsd -0x1a0(%rbp), %xmm1
xorl %eax, %eax
movq -0xa8(%rbp), %rdi
cmpq %rax, %rbx
je 0x312d0
movsd (%r12,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r12,%rax,8)
incq %rax
jmp 0x312b6
movsd -0x70(%rbp), %xmm5
jmp 0x31171
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x70(%rbp)
movss 0x32bd0(%rip), %xmm0    # 0x63ebc
movss %xmm0, -0x48(%rbp)
movq -0xf8(%rbp), %r14
movq %r14, %rdi
movq -0x158(%rbp), %rsi
movl %r13d, %edx
callq 0x301ca
movq -0x130(%rbp), %r12
movq %r12, %rdi
movl 0x70(%rbp), %esi
movq %r14, %rdx
movl %r13d, %ecx
callq 0x154b8
xorl %eax, %eax
movq -0x138(%rbp), %rcx
movq -0xa8(%rbp), %rdx
movq -0xa0(%rbp), %rdi
cmpq %rax, %rbx
je 0x31353
movsd (%r12,%rax,8), %xmm0
subsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rdx,%rax,8)
incq %rax
jmp 0x31339
movss -0x48(%rbp), %xmm0
ucomiss -0x70(%rbp), %xmm0
seta %r15b
jmp 0x3137a
movb $0x1, %r15b
leaq 0x23e82(%rip), %rdi     # 0x551ee
movb $0x1, %al
callq 0x20f0
movq -0xa0(%rbp), %rdi
cmpq $0x0, -0xe0(%rbp)
movq -0x88(%rbp), %r12
je 0x31444
movq -0x40(%rbp), %rsi
movq -0x178(%rbp), %rdx
movq -0x108(%rbp), %rcx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
ucomiss 0x23943(%rip), %xmm0    # 0x54cf4
seta %al
orb %r15b, %al
testb $0x1, %al
je 0x31444
xorl %eax, %eax
movq -0x40(%rbp), %rcx
movq -0xa0(%rbp), %rdx
movq -0xd8(%rbp), %rsi
cmpq %rax, %rsi
je 0x313e7
movss (%rcx,%rax,4), %xmm0
movss %xmm0, (%rdx,%rax,4)
incq %rax
jmp 0x313d3
movb %r15b, -0x70(%rbp)
movq -0x140(%rbp), %r15
incl %r15d
movq -0x100(%rbp), %rdi
movq -0xf0(%rbp), %r14
movq %r14, %rsi
movq -0x150(%rbp), %rdx
movl %r13d, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movq -0xe0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movl %r13d, %edx
movq %r14, %rcx
movq 0x78(%rbp), %r8
movq %r15, -0x140(%rbp)
movl %r15d, %r9d
movb -0x70(%rbp), %r15b
callq 0x2f4bd
pushq $0xa
popq %rdi
callq 0x2060
testb %r15b, %r15b
jne 0x3147a
movq -0x148(%rbp), %rsp
movl -0x30(%rbp), %eax
incl %eax
movq -0x40(%rbp), %r14
movq -0x160(%rbp), %rcx
movq -0xd8(%rbp), %rdx
jmp 0x30e2a
movl -0x2c(%rbp), %r14d
jmp 0x31498
cvtss2sd -0x34(%rbp), %xmm0
leaq 0x23db0(%rip), %rdi     # 0x55236
movb $0x1, %al
callq 0x20f0
movq -0x148(%rbp), %rsp
movl -0x30(%rbp), %r14d
leaq 0x23db7(%rip), %rdi     # 0x55256
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
movq -0x110(%rbp), %r15
movq %r15, %rcx
callq 0x2280
subq $0x50, %rsp
leaq 0x40(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x20(%rsp)
movups %xmm0, 0x10(%rsp)
movq %r12, 0x48(%rsp)
movq -0xb0(%rbp), %rax
movq %rax, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x30(%rsp)
movl %r13d, 0x8(%rsp)
movq -0xf0(%rbp), %rax
movq %rax, (%rsp)
leaq -0x124(%rbp), %rdi
leaq -0x34(%rbp), %rsi
leaq -0x54(%rbp), %rdx
movss 0x19b01(%rip), %xmm1    # 0x4b014
movss 0x19af5(%rip), %xmm2    # 0x4b010
movss -0x50(%rbp), %xmm0
movl %r14d, -0x30(%rbp)
movl %r14d, %ecx
movq %r15, %r8
movq -0xf8(%rbp), %r12
movq %r12, %r9
callq 0x31729
addq $0x50, %rsp
leaq -0x54(%rbp), %rax
cvtss2sd (%rax), %xmm0
leaq 0x23d19(%rip), %rdi     # 0x55265
movb $0x1, %al
callq 0x20f0
leaq 0x24713(%rip), %rdi     # 0x55c6d
callq 0x2090
movq -0x130(%rbp), %rdi
movl 0x70(%rbp), %esi
movq %r12, %rdx
movq %rdi, %r12
movl %r13d, %ecx
callq 0x154b8
xorl %eax, %eax
movq -0x168(%rbp), %r14
movq -0x138(%rbp), %rcx
cmpq %rax, %rbx
je 0x315a2
movsd (%r12,%rax,8), %xmm0
subsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r14,%rax,8)
incq %rax
jmp 0x31587
movq %r14, %rdi
movq 0x68(%rbp), %rsi
movl 0x70(%rbp), %ebx
movl %ebx, %edx
callq 0x2bbb8
movq -0xf8(%rbp), %r12
movq %r12, %rdi
movq -0xe8(%rbp), %rsi
movl %r13d, %edx
callq 0x301ca
movq %r12, %rdi
movl %r13d, %esi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x13d70
leaq 0x23c94(%rip), %rdi     # 0x55277
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
movq -0x110(%rbp), %r14
movq %r14, %rcx
callq 0x2280
subq $0x50, %rsp
leaq 0x40(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x20(%rsp)
movups %xmm0, 0x10(%rsp)
movq -0x88(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0xb0(%rbp), %rax
movq %rax, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movq -0x40(%rbp), %rax
movq %rax, 0x30(%rsp)
movl %r13d, 0x8(%rsp)
movq -0xf0(%rbp), %rax
movq %rax, (%rsp)
leaq -0x124(%rbp), %rdi
leaq -0x34(%rbp), %rsi
leaq -0x54(%rbp), %rbx
movss 0x199b6(%rip), %xmm1    # 0x4b014
movss 0x199aa(%rip), %xmm2    # 0x4b010
movq %rbx, %rdx
movss -0x50(%rbp), %xmm0
movl -0x30(%rbp), %ecx
movq %r14, %r8
movq %r12, %r9
callq 0x31729
addq $0x50, %rsp
cvtss2sd (%rbx), %xmm0
leaq 0x23c03(%rip), %rdi     # 0x5528e
movl 0xf8(%rbp), %ebx
movl %ebx, %esi
movq 0xf0(%rbp), %rdx
movb $0x1, %al
callq 0x20f0
cvtsi2sdl -0xc0(%rbp), %xmm1
movsd -0x98(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
leaq 0x23bf1(%rip), %rdi     # 0x552b5
movl %ebx, %esi
movb $0x1, %al
callq 0x20f0
leaq 0x23c0f(%rip), %rsi     # 0x552e3
movq %r14, %rdi
movl %ebx, %edx
movsd -0x98(%rbp), %xmm0
movb $0x1, %al
callq 0x2190
cvtss2sd -0xbc(%rbp), %xmm0
leaq 0x23c1b(%rip), %rsi     # 0x55312
movq %r14, %rdi
movb $0x1, %al
callq 0x2190
movq %r14, %rdi
callq 0x20c0
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x3171a
callq 0x20c0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq