// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/simulation.c
// Function: Torsional_confchange_RRR
void Torsional_confchange_RRR(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, int NMODES)
{
  int IT_MAX=Para_simul.NSTEPS; int i;
  float STEP_MAX=Para_simul.STEP_MAX, STEP_MIN=Para_simul.STEP_MIN;
  float A_MAX=Para_simul.ANGLE;
  int FAIL_MAX=4;
  printf("Interpolating conformation change with steps\n");
  
  // 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;

  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];
  }

  struct Tors Diff; 
  Allocate_tors(&Diff, naxes, N_Cart, naxes); //N_modes

  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 torsional steps\n");
  fprintf(file_rmsd,"# RMSD_step: max= %.2g min= %.2g N.steps %d\n",
	  STEP_MAX, STEP_MIN, IT_MAX);
  //fprintf(file_rmsd,"# max. angular change (end) %.2g\n", D_MAX_MIN);
  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 Tors_RMSD= %.3f\n", RMSD_kf, Tors_fluct);
  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, 0.0, 1);

  // Opening file for printing PDB
  FILE *file_pdb=NULL;
  float coord_all_1[3*natoms1], mass[natoms1];
  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);
  }
 
  double Mass_tot=0; for(i=0; i<Ref1.N_ref; i++)Mass_tot+=Ref1.mass_atom[i];
  int accept=1, imax=-1, iter, exit, k_fail=0, k_pdb=0,
    fit_fail=0, regression=1; 
  float Lambda=0; int l_Lambda=1; //float rmsd=100
  for(iter=0; iter<IT_MAX; iter++){

    double diff_step[naxes], diff_all[naxes];
    if(regression==1){
      //if(iter)rmsd=rmsd_mclachlan_f(coord_kin, coord_old, mass_ref, N_ali);
      if((iter==0)){//||(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);
	l_Lambda=1;
      }
      for(i=0;i<N_Cart;i++)Diff.Cart[i]=coord_ref_2[i]-coord_old[i];
      if(iter==0){
	if(Convert_cart2torsion_fit(&Diff, Ref1, J, nameout, 'C', &Lambda)<0){
	  printf("WARNING, ridge regression failed\n");
	  accept=0; k_fail++; fit_fail++; goto test;
	}
      }else{
	if(l_Lambda){
	  printf("Computing T+Lambda, Lambda= %.3f\n", Lambda);
	  l_Lambda=0; for(i=0;i<naxes; i++)J->T[i][i]*=(1+Lambda);
	}
	if(Tors_step(&Diff,J->T,J->Jacobian_ar,Ref1.mass_coord,naxes,N_Cart)){
	  printf("WARNING, fast regression failed\n");
	  accept=0; k_fail++; fit_fail++; regression=0; continue;
	}	
      }
      for(i=0; i<naxes; i++)diff_step[i]=Diff.Tors[i];
    }else{
      goto test;
      // Move angles one by one
      imax=Torsional_confchange_1angle(diff_step, naxes, Para_simul.ANGLE,
				       bonds, natoms1, ali_a,
				       coord_ref_1, coord_ref_2,
				       STEP_MIN, RMSD_opt,
				       atoms1, coord_all);
      if(imax<0){
	accept=0; k_fail++; goto test;
      }
      fprintf(file_rmsd, "# 1angle, angle= %.2g i=%d %c:\n",
	      Para_simul.ANGLE, imax, axes[imax].type);
      printf("# angle= %.2g i=%d %c:\n",
	     Para_simul.ANGLE, imax, axes[imax].type);
    }

    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);
      for(i=0; i<naxes; i++)diff_step[i]*=f;
    }

    float factor=1., reduce_step=1;
    /**/
    while(1){ // loop on amplitudes
      
      // Move atoms
      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;
      if((factor<0.005)||(reduce_step<0.0001)){
	printf("Too small amplitude (%.2g), exiting\n", factor);
	accept=0; break;
      }
      printf("Reducing amplitude by factor %.2g\n", reduce_step);
      if(regression){
	for(i=0; i<naxes; i++)diff_step[i]*=reduce_step;
      }else{
	diff_step[imax]*=reduce_step;
      }

    } // End loop amplitude

      /**/
    /*
      Copy_bonds(bonds_tmp, bonds_ini, natoms1);
      RMSD_kf=Optimize_amplitude(bonds_tmp,&factor,diff_tors,naxes,
				 bonds,natoms1,Ref1, coord_ref_2);
      accept=Write_RMSD(&reduce_step, &RMSD_opt, &RMSD_kf,
			STEP_MIN, STEP_MAX, factor, iter, file_rmsd,
			bonds, coord_all, natoms1, ali_a,
			coord_new,coord_old,coord_ref_1,coord_ref_2);
    
      if(accept && (RMSD_step>STEP_MAX)){ // Reduce factor
	factor*=(STEP_MAX/RMSD_step);
	for(i=0; i<naxes; i++)diff_step[i]*=factor;
	Build_up(bonds, natoms1, diff_tors, naxes);
	accept=Write_RMSD(&reduce_step,&RMSD_opt, &RMSD_kf,
			  STEP_MIN, STEP_MAX, factor, iter, file_rmsd,
			  bonds, coord_all, natoms1, ali_a,
			  coord_new,coord_old,coord_ref_1,coord_ref_2);
      }
      // Switch coordinates
      if(accept)Copy_bonds(bonds_old, bonds, natoms1);
    }
    */
      /**/
  test:
    exit=(RMSD_opt < RMSD_TOL);
    if(accept==0){
      k_fail++;
      if(k_fail>=2)exit=1;
      if(regression){
	fit_fail++; regression=0;
      }else if(fit_fail<FAIL_MAX){
	regression=1;
      }
      if(exit==0)continue;
    }else{
      // 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];
      k_fail=0;
      if(regression){fit_fail=0;}
      else if(fit_fail<FAIL_MAX){regression=1;}
    }

    // Print PDB
    if(file_pdb){
      float rmsd=rmsd_mclachlan_f(coord_pdb, coord_new, mass_ref, N_ali);
      if((rmsd > Para_simul.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, k_fail= %d fit_fail= %d\n",k_fail,fit_fail);
      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("Reconstructed RMSD= %.2f\n", RMSD_kf);

  fclose(file_rmsd);
  if(file_pdb)fclose(file_pdb);
  Empty_tors(Diff);
  //Empty_Ref(&Ref1);
  //Change_kin_back(axes, naxes, first_kin, last_kin);
  //Empty_Jacobian(J);
  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 $0x318, %rsp            # imm = 0x318
movl %r9d, %r13d
movq %r8, %r14
movsd %xmm0, -0x70(%rbp)
movq %rcx, -0x40(%rbp)
movq %rdx, %rbx
movq %rsi, -0x78(%rbp)
movq %rdi, -0x148(%rbp)
leaq 0xa8(%rbp), %rax
movl 0x70(%rbp), %r15d
movss 0x4(%rax), %xmm0
movss %xmm0, -0xc4(%rbp)
movss 0x8(%rax), %xmm0
movss %xmm0, -0x80(%rbp)
movss 0xc(%rax), %xmm0
movss %xmm0, -0xbc(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x4c(%rbp)
leaq 0x24124(%rip), %rdi     # 0x55bbc
callq 0x2090
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, -0xb0(%rbp)
movq %r14, %rdx
callq 0x139f6
movl %r13d, %ecx
movq %rsp, %rdi
movq %rcx, -0x30(%rbp)
imulq $0xc0, %rcx, %rax
subq %rax, %rdi
movq %rdi, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x140(%rbp)
movq %rcx, %rsp
movq %rdi, -0xd0(%rbp)
movq %rbx, %rsi
movl %r13d, %edx
callq 0x301ca
leaq 0x240f7(%rip), %rdi     # 0x55be9
callq 0x2090
movq %rsp, %rdi
leaq 0xf(,%r15,8), %r14
andq $-0x10, %r14
subq %r14, %rdi
movq %rdi, %rsp
movq %rsp, %rax
subq %r14, %rax
movq %rax, -0x128(%rbp)
movq %rax, %rsp
movq %rdi, -0x130(%rbp)
movl %r15d, %esi
movq %rbx, -0xf0(%rbp)
movq %rbx, %rdx
movq %r13, -0x58(%rbp)
movl %r13d, %ecx
callq 0x154b8
movq %rsp, %rcx
movq %r14, -0x168(%rbp)
subq %r14, %rcx
movq %rcx, %rsp
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %r14d
cmovgl %r15d, %r14d
cmpq %rax, %r14
je 0x31b6a
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x31b5b
movq %rcx, -0x98(%rbp)
leaq 0x40(%rbp), %rax
movl 0x18(%rax), %ebx
leal (%rbx,%rbx,2), %r12d
leaq 0xf(,%r12,4), %r15
andq $-0x10, %r15
movq %rsp, %rdi
subq %r15, %rdi
movq %rdi, %rsp
movq %rsp, %r13
subq %r15, %r13
movq %r13, %rsp
movq (%rax), %rcx
movq %rdi, -0xb8(%rbp)
movl %ebx, %esi
movq -0xb0(%rbp), %rdx
callq 0x2f97d
leaq 0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movq %r13, -0x38(%rbp)
movq %r13, %rdi
movq %rbx, -0x120(%rbp)
movl %ebx, %esi
movq 0x98(%rbp), %rdx
callq 0x2f97d
movq %rsp, %rdx
subq %r15, %rdx
movq %rdx, %rsp
movq %rsp, %r8
subq %r15, %r8
movq %r8, %rsp
movq %rsp, %rsi
subq %r15, %rsi
movq %rsi, %rsp
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %edi
movq %r12, -0x118(%rbp)
cmovgl %r12d, %edi
movq -0xb8(%rbp), %rcx
cmpq %rax, %rdi
je 0x31c2c
movss (%rcx,%rax,4), %xmm0
movss %xmm0, (%rdx,%rax,4)
movss %xmm0, (%r8,%rax,4)
movss %xmm0, (%rsi,%rax,4)
incq %rax
jmp 0x31c0d
movq %r8, -0x60(%rbp)
movq %rdi, -0x68(%rbp)
movq %rsi, -0x138(%rbp)
movq %rdx, -0xa0(%rbp)
leaq -0x1a8(%rbp), %rdi
movl 0x70(%rbp), %ecx
movl %ecx, %esi
movq -0x118(%rbp), %rdx
callq 0x10444
leaq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x160(%rbp)
movq -0x58(%rbp), %r12
leal (%r12,%r12,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rax, -0xe8(%rbp)
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movq %rbx, %rdi
movq -0xf0(%rbp), %rsi
movl %r12d, %edx
callq 0x2f358
movq %rbx, -0xf8(%rbp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x2f3a6
movss %xmm0, -0x48(%rbp)
leaq 0x233a0(%rip), %rsi     # 0x5505d
xorl %r15d, %r15d
leaq -0x340(%rbp), %rbx
movq %rbx, %rdi
movq 0x60(%rbp), %rdx
movq -0x78(%rbp), %rcx
xorl %eax, %eax
callq 0x2260
leaq 0x1f470(%rip), %rsi     # 0x51150
movq %rbx, %rdi
callq 0x2210
movq %rax, %r13
leaq 0x2337a(%rip), %rdi     # 0x5506c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x23623(%rip), %rdi     # 0x55326
pushq $0x39
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
movq %r13, %rcx
callq 0x2280
cvtss2sd -0xc4(%rbp), %xmm0
cvtss2sd -0x80(%rbp), %xmm1
leaq 0x23638(%rip), %rsi     # 0x55360
movq %r13, %rdi
movl -0x4c(%rbp), %edx
movb $0x2, %al
callq 0x2190
cvtss2sd -0x48(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
leaq 0x23395(%rip), %rsi     # 0x550de
movq %r13, %rdi
movb $0x1, %al
callq 0x2190
leaq 0x40(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0xb8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x120(%rbp), %rcx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xa4(%rbp)
movss %xmm0, -0x84(%rbp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x2335e(%rip), %rdi     # 0x550f4
movb $0x1, %al
callq 0x20f0
leaq 0x235e9(%rip), %rsi     # 0x5538d
movq %r13, %rdi
movsd -0x48(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
movb $0x2, %al
callq 0x2190
leaq 0x23358(%rip), %rdi     # 0x55117
pushq $0x32
popq %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x2280
leaq 0x23376(%rip), %rsi     # 0x5514a
pushq $0x1
popq %rdx
xorps %xmm0, %xmm0
xorpd %xmm2, %xmm2
xorps %xmm4, %xmm4
movq %r13, -0x100(%rbp)
movq %r13, %rdi
movsd -0x48(%rbp), %xmm1
movsd -0x90(%rbp), %xmm3
movb $0x5, %al
callq 0x2190
movq %rsp, %rax
subq -0xe8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq %rax, %rsp
movq %rsp, %r12
movq -0x30(%rbp), %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq -0x58(%rbp), %rax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
movq -0xb0(%rbp), %rbx
cmpq %r15, %r13
je 0x31e5f
movq %rbx, %rdi
callq 0x233c9
movss %xmm0, (%r12,%r15,4)
incq %r15
addq $0x70, %rbx
jmp 0x31e43
movq %r12, -0x158(%rbp)
leaq 0x232fa(%rip), %rsi     # 0x55167
movq -0x78(%rbp), %r15
movq %r15, %rdi
callq 0x2180
xorl %ecx, %ecx
testl %eax, %eax
je 0x31f1f
leaq 0x232e6(%rip), %rsi     # 0x55170
leaq -0x270(%rbp), %rbx
movq %rbx, %rdi
movq 0x60(%rbp), %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x2260
leaq 0x1f2a7(%rip), %rsi     # 0x51150
movq %rbx, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x232ca(%rip), %rdi     # 0x55185
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
movq %r15, %rdi
movq 0x88(%rbp), %rsi
movl 0x90(%rbp), %edx
callq 0x2f827
movq -0x110(%rbp), %r12
movq %r12, %rdi
movq -0xf0(%rbp), %rsi
movq -0x58(%rbp), %rbx
movl %ebx, %edx
callq 0x2f358
xorps %xmm0, %xmm0
movq %r15, -0xd8(%rbp)
movq %r15, %rdi
movq -0xb0(%rbp), %rsi
movl %ebx, %edx
movq %r12, %rcx
movq 0x78(%rbp), %r8
xorl %r9d, %r9d
callq 0x2f4bd
xorl %ecx, %ecx
jmp 0x31f2a
movq $0x0, -0xd8(%rbp)
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %r8
movq -0x98(%rbp), %r13
leaq -0x270(%rbp), %rax
andl $0x0, (%rax)
movl -0x4c(%rbp), %eax
testl %eax, %eax
cmovlel %ecx, %eax
movl %eax, -0x4c(%rbp)
imulq $0x70, -0x30(%rbp), %rax
movq %rax, -0x150(%rbp)
movl $0x0, -0xc0(%rbp)
xorl %ebx, %ebx
pushq $0x1
popq %rax
movl %eax, -0x70(%rbp)
movl %eax, -0x7c(%rbp)
xorl %r12d, %r12d
movl %eax, %r9d
cmpl -0x4c(%rbp), %r12d
je 0x32665
movl %ebx, -0x90(%rbp)
movq %rsp, -0xe8(%rbp)
movq %rsp, %r15
movq -0x168(%rbp), %rax
subq %rax, %r15
movq %r15, %rsp
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
cmpl $0x1, -0x70(%rbp)
movq %r8, -0x60(%rbp)
movl %r12d, -0x48(%rbp)
jne 0x32451
movq %rcx, -0xe0(%rbp)
testl %r12d, %r12d
jne 0x32067
leaq 0x23c3d(%rip), %rdi     # 0x55c13
callq 0x2090
movq %rsp, -0x30(%rbp)
movq %rsp, %rdi
subq -0x150(%rbp), %rdi
movq %rdi, -0x78(%rbp)
movq %rdi, %rsp
movq -0xd0(%rbp), %rsi
movq -0x58(%rbp), %r13
movl %r13d, %edx
callq 0x32938
subq $0x30, %rsp
leaq 0x10(%rbp), %rax
movups (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movupd 0x20(%rax), %xmm2
movupd %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq -0x40(%rbp), %rdi
movq 0x68(%rbp), %rsi
movl 0x70(%rbp), %edx
movq -0x78(%rbp), %rcx
movl %r13d, %r8d
movq -0x98(%rbp), %r13
xorl %r9d, %r9d
callq 0x1eb7c
movq -0x60(%rbp), %r8
movq -0x68(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rsi
addq $0x30, %rsp
movq -0x30(%rbp), %rsp
pushq $0x1
popq %rax
movl %eax, -0x7c(%rbp)
movq -0x1a0(%rbp), %rax
xorl %ecx, %ecx
cmpq %rcx, %rdi
je 0x3208a
movss (%rdx,%rcx,4), %xmm0
subss (%r8,%rcx,4), %xmm0
movss %xmm0, (%rax,%rcx,4)
incq %rcx
jmp 0x32070
testl %r12d, %r12d
je 0x3215e
cmpl $0x0, -0x7c(%rbp)
je 0x320e9
cvtss2sd -0x270(%rbp), %xmm0
leaq 0x23303(%rip), %rdi     # 0x553ab
movb $0x1, %al
callq 0x20f0
movq -0x40(%rbp), %rsi
movss -0x270(%rbp), %xmm0
addss 0x18f4d(%rip), %xmm0    # 0x4b010
cvtss2sd %xmm0, %xmm0
xorl %eax, %eax
cmpq %rax, %r14
je 0x320e9
movq 0x20(%rsi), %rcx
movq (%rcx,%rax,8), %rcx
movsd (%rcx,%rax,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rax,8)
incq %rax
jmp 0x320c9
movq 0x10(%rsi), %rdx
movq 0x20(%rsi), %rsi
leaq 0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq -0x1a8(%rbp), %rdi
movl 0x70(%rbp), %r8d
movq -0x118(%rbp), %r9
callq 0x32971
testl %eax, %eax
je 0x321d8
leaq 0x23b0d(%rip), %rdi     # 0x55c2c
callq 0x2090
movq -0xe0(%rbp), %rax
incl %eax
movl -0x90(%rbp), %ebx
incl %ebx
movl $0x0, -0x70(%rbp)
movl %eax, %r11d
movl $0x0, -0x7c(%rbp)
xorl %r9d, %r9d
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %rdi
jmp 0x32650
subq $0x30, %rsp
leaq 0x10(%rbp), %rax
movups (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movupd 0x20(%rax), %xmm2
movupd %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq -0x1a8(%rbp), %rdi
movq 0x60(%rbp), %rdx
pushq $0x43
popq %rcx
leaq -0x270(%rbp), %r8
callq 0x23c8c
addq $0x30, %rsp
testl %eax, %eax
jns 0x321df
leaq 0x23aa0(%rip), %rdi     # 0x55c4c
callq 0x2090
movq -0xe0(%rbp), %rcx
incl %ecx
incl -0x90(%rbp)
xorl %r9d, %r9d
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %r8
jmp 0x32451
movl $0x0, -0x7c(%rbp)
movq -0x190(%rbp), %rax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x321fd
cvtss2sd (%rax,%rcx,4), %xmm0
movsd %xmm0, (%r15,%rcx,8)
incq %rcx
jmp 0x321e8
xorps %xmm0, %xmm0
xorl %eax, %eax
cmpq %rax, %r14
je 0x32233
movsd (%r15,%rax,8), %xmm1
movapd %xmm1, %xmm2
andpd 0x1f027(%rip), %xmm2    # 0x51240
cvtss2sd %xmm0, %xmm3
ucomisd %xmm3, %xmm2
jbe 0x3222e
cvtsd2ss %xmm1, %xmm0
andps 0x1f002(%rip), %xmm0    # 0x51230
incq %rax
jmp 0x32202
ucomiss -0xbc(%rbp), %xmm0
jbe 0x32298
movss -0xbc(%rbp), %xmm1
divss %xmm0, %xmm1
movss %xmm1, -0x30(%rbp)
cvtss2sd %xmm0, %xmm0
leaq 0x22f55(%rip), %rdi     # 0x551ad
movb $0x1, %al
callq 0x20f0
cvtss2sd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x22f5d(%rip), %rdi     # 0x551cd
movb $0x1, %al
callq 0x20f0
movsd -0x30(%rbp), %xmm1
xorl %eax, %eax
cmpq %rax, %r14
je 0x32298
movsd (%r15,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x3227e
movl $0x3f800000, -0xc8(%rbp) # imm = 0x3F800000
movss 0x18d66(%rip), %xmm1    # 0x4b010
xorl %eax, %eax
cmpq %rax, %r14
je 0x322c8
movsd (%r13,%rax,8), %xmm0
addsd (%r15,%rax,8), %xmm0
movsd %xmm0, (%rbx,%rax,8)
incq %rax
jmp 0x322ac
movq -0x140(%rbp), %r13
movq %r13, %rdi
movq -0xf0(%rbp), %rsi
movq -0x58(%rbp), %r12
movl %r12d, %edx
movss %xmm1, -0x30(%rbp)
callq 0x301ca
movq %r13, %rdi
movl %r12d, %esi
movq %rbx, %rdx
movl 0x70(%rbp), %ecx
callq 0x13d70
subq $0x50, %rsp
leaq 0x40(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x20(%rsp)
movups %xmm0, 0x10(%rsp)
movq -0x38(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0xb8(%rbp), %rax
movq %rax, 0x40(%rsp)
movq -0x60(%rbp), %rax
movq %rax, 0x38(%rsp)
movq -0xa0(%rbp), %rax
movq %rax, 0x30(%rsp)
movl %r12d, 0x8(%rsp)
movl -0x48(%rbp), %r12d
movq -0xf8(%rbp), %rax
movq %rax, (%rsp)
leaq -0xc8(%rbp), %rdi
leaq -0x84(%rbp), %rsi
leaq -0xa4(%rbp), %rdx
movss -0x80(%rbp), %xmm0
movss -0xc4(%rbp), %xmm1
movss -0x30(%rbp), %xmm2
movl %r12d, %ecx
movq -0x100(%rbp), %r8
movq %r13, %r9
callq 0x31729
addq $0x50, %rsp
testl %eax, %eax
jne 0x3242f
movss -0xc8(%rbp), %xmm1
movss -0x30(%rbp), %xmm3
mulss %xmm1, %xmm3
cvtss2sd %xmm3, %xmm0
movsd 0x1e4ec(%rip), %xmm2    # 0x508a0
ucomisd %xmm0, %xmm2
ja 0x3241c
movaps %xmm3, %xmm2
cvtss2sd %xmm1, %xmm3
movsd 0x1d74f(%rip), %xmm1    # 0x4fb18
ucomisd %xmm3, %xmm1
ja 0x3241c
movss %xmm2, -0x30(%rbp)
leaq 0x22e38(%rip), %rdi     # 0x55213
movaps %xmm3, %xmm0
movb $0x1, %al
movsd %xmm3, -0x78(%rbp)
callq 0x20f0
movsd -0x78(%rbp), %xmm1
xorl %eax, %eax
movq -0x98(%rbp), %r13
cmpq %rax, %r14
je 0x32412
movsd (%r15,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x323f8
movss -0x30(%rbp), %xmm1
jmp 0x322aa
leaq 0x22dcb(%rip), %rdi     # 0x551ee
movb $0x1, %al
callq 0x20f0
xorl %r9d, %r9d
jmp 0x32433
pushq $0x1
popq %r9
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %r8
movq -0x98(%rbp), %r13
movq -0xe0(%rbp), %rcx
movss -0x84(%rbp), %xmm0
movss 0x31a5b(%rip), %xmm1    # 0x63ebc
ucomiss %xmm0, %xmm1
seta %r15b
movl %r9d, -0x30(%rbp)
testl %r9d, %r9d
je 0x324da
movq -0xd0(%rbp), %rbx
movq %rbx, %rdi
movq -0x140(%rbp), %rsi
movq -0x58(%rbp), %r12
movl %r12d, %edx
callq 0x301ca
movq -0x128(%rbp), %rdi
movl 0x70(%rbp), %esi
movq %rbx, %rdx
movq %rdi, %rbx
movl %r12d, %ecx
callq 0x154b8
xorl %eax, %eax
movq -0x130(%rbp), %rcx
cmpq %rax, %r14
je 0x324ca
movsd (%rbx,%rax,8), %xmm0
subsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r13,%rax,8)
incq %rax
jmp 0x324af
xorl %r11d, %r11d
cmpl $0x0, -0x70(%rbp)
je 0x3251e
xorl %ebx, %ebx
pushq $0x1
popq %rax
jmp 0x3252c
leal 0x1(%rcx), %r11d
xorl %ebx, %ebx
cmpl $0x0, -0x70(%rbp)
sete %al
setne %bl
movl -0x90(%rbp), %r10d
cmpl $0x4, %r10d
movq %rcx, %r9
setl %cl
addl %r10d, %ebx
andb %al, %cl
movzbl %cl, %eax
movl %eax, -0x70(%rbp)
movb $0x1, %r15b
testl %r9d, %r9d
jg 0x32533
ucomiss %xmm0, %xmm1
ja 0x32533
xorl %r9d, %r9d
movq %r8, %rax
jmp 0x32650
xorl %eax, %eax
movl -0x90(%rbp), %ebx
cmpl $0x4, %ebx
setl %al
movl %eax, -0x70(%rbp)
movl -0x48(%rbp), %r12d
movl %r11d, -0x78(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0x3261d
movq -0x138(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x160(%rbp), %rdx
movq -0x120(%rbp), %rcx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
leaq 0xa8(%rbp), %rax
ucomiss 0x1c(%rax), %xmm0
seta %al
orb %r15b, %al
testb $0x1, %al
je 0x3261d
xorl %eax, %eax
movq -0xa0(%rbp), %rcx
movq -0x138(%rbp), %rdx
movq -0x68(%rbp), %rsi
cmpq %rax, %rsi
je 0x325ab
movss (%rcx,%rax,4), %xmm0
movss %xmm0, (%rdx,%rax,4)
incq %rax
jmp 0x32597
movb %r15b, -0x90(%rbp)
movl -0xc0(%rbp), %r15d
incl %r15d
movq -0x110(%rbp), %rdi
movq -0xf8(%rbp), %r13
movq %r13, %rsi
movq -0x158(%rbp), %rdx
movq -0x58(%rbp), %r12
movl %r12d, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movq -0xd8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movl %r12d, %edx
movl -0x48(%rbp), %r12d
movq %r13, %rcx
movq -0x98(%rbp), %r13
movq 0x78(%rbp), %r8
movl %r15d, -0xc0(%rbp)
movl %r15d, %r9d
movb -0x90(%rbp), %r15b
callq 0x2f4bd
pushq $0xa
popq %rdi
callq 0x2060
testb %r15b, %r15b
jne 0x3266b
movq -0xa0(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x68(%rbp), %rdi
movl -0x30(%rbp), %r9d
movl -0x78(%rbp), %r11d
movq -0xe8(%rbp), %rsp
incl %r12d
movl %r11d, %ecx
movq %rax, %r8
jmp 0x31f7d
movl -0x4c(%rbp), %r13d
jmp 0x32688
leaq 0x22d5b(%rip), %rdi     # 0x553cd
movl -0x78(%rbp), %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x20f0
movq -0xe8(%rbp), %rsp
movl %r12d, %r13d
leaq 0x22bc7(%rip), %rdi     # 0x55256
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
movq -0x100(%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 -0x38(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0xb8(%rbp), %rax
movq %rax, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movq -0xa0(%rbp), %rax
movq %rax, 0x30(%rsp)
movq -0x58(%rbp), %r12
movl %r12d, 0x8(%rsp)
movq -0xf8(%rbp), %rax
movq %rax, (%rsp)
leaq -0x104(%rbp), %rdi
leaq -0x84(%rbp), %rsi
leaq -0xa4(%rbp), %rbx
movss 0x18900(%rip), %xmm1    # 0x4b014
movss 0x188f4(%rip), %xmm2    # 0x4b010
movq %rbx, %rdx
movss -0x80(%rbp), %xmm0
movl %r13d, -0x48(%rbp)
movl %r13d, %ecx
movq %r15, %r8
movq -0xd0(%rbp), %r15
movq %r15, %r9
callq 0x31729
addq $0x50, %rsp
cvtss2sd (%rbx), %xmm0
leaq 0x22b19(%rip), %rdi     # 0x55265
movb $0x1, %al
callq 0x20f0
leaq 0x23513(%rip), %rdi     # 0x55c6d
callq 0x2090
movq -0x128(%rbp), %rbx
movq %rbx, %rdi
movl 0x70(%rbp), %esi
movq %r15, %rdx
movl %r12d, %ecx
callq 0x154b8
xorl %eax, %eax
movq -0x148(%rbp), %r15
movq -0x130(%rbp), %rcx
cmpq %rax, %r14
je 0x327a1
movsd (%rbx,%rax,8), %xmm0
subsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rax
jmp 0x32787
movq %r15, %rdi
movq 0x68(%rbp), %rsi
movl 0x70(%rbp), %ebx
movl %ebx, %edx
callq 0x2bbb8
movq -0xd0(%rbp), %r14
movq %r14, %rdi
movq -0xf0(%rbp), %rsi
movq -0x58(%rbp), %r12
movl %r12d, %edx
callq 0x301ca
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
movl %ebx, %ecx
callq 0x13d70
leaq 0x22a91(%rip), %rdi     # 0x55277
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
movq -0x100(%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 -0x38(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0xb8(%rbp), %rax
movq %rax, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movq -0xa0(%rbp), %rax
movq %rax, 0x30(%rsp)
movl %r12d, 0x8(%rsp)
movq -0xf8(%rbp), %rax
movq %rax, (%rsp)
leaq -0x104(%rbp), %rdi
leaq -0x84(%rbp), %rsi
leaq -0xa4(%rbp), %rbx
movss 0x187ad(%rip), %xmm1    # 0x4b014
movss 0x187a1(%rip), %xmm2    # 0x4b010
movq %rbx, %rdx
movss -0x80(%rbp), %xmm0
movl -0x48(%rbp), %ecx
movq %r15, %r8
movq %r14, %r9
callq 0x31729
addq $0x50, %rsp
cvtss2sd (%rbx), %xmm0
leaq 0x22b66(%rip), %rdi     # 0x553fa
movb $0x1, %al
callq 0x20f0
movq %r15, %rdi
callq 0x20c0
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x328b4
callq 0x20c0
subq $0x40, %rsp
movups -0x1a8(%rbp), %xmm0
movups -0x198(%rbp), %xmm1
movups -0x188(%rbp), %xmm2
movups -0x178(%rbp), %xmm3
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x104a1
popq %rax
popq %rcx
leaq 0x10(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq -0x40(%rbp), %rdi
movq 0x68(%rbp), %rsi
movl 0x70(%rbp), %edx
movq -0xb0(%rbp), %rcx
movq -0x58(%rbp), %r8
xorl %r9d, %r9d
callq 0x1eb7c
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq