// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/allostery.c
// Function: Binding_sites
void Binding_sites(int *site,
		   float *Prof_dir, float **Coup_dir,
		   float *Prof_coord, float **Coup_coord,
		   float *Prof_proximity, float **Coup_proximity, 
		   float *Prof_deformation, float **Coup_deformation,
		   //float *Prof_deformation_dist,float **Coup_deformation_dist,
		   float *Prof_dr_dir, float **Coup_dr_dir,
		   int *atomres, char **pdbres, char *amm, 
		   int Na, char *chain, int Nchain,
		   struct residue *seq, int Nres,
		   char *pdb, char *nameout1, char *SITES)
{
  int numran=1000; int i, j, k;
  
  int NMAX=1000;
  int *site_res[NMAX], nres_site[NMAX];
  char *chain_res[NMAX], *description[NMAX], file_site[200];
  int PRINT_SITE=1;  // Print active site read in the PDB?
  printf("Reading binding sites\n");
  int N_sites=
    Read_sites(site_res, nres_site, chain_res, description, file_site,
	       NMAX, SITES, pdb, chain, Nchain, seq, Nres,PRINT_SITE);
  printf("%d binding sites read\n", N_sites);
  if(N_sites==0)return;

  /*
  int NMAX=1000, SMAX=80, N_sites=0;
  int nres_site[NMAX]; char *chain_res[NMAX];
  for(i=0; i<NMAX; i++)chain_res[i]=malloc(SMAX*sizeof(char));
  char *description[NMAX]; for(i=0; i<NMAX; i++)description[i]=NULL;
  int **site_res=Allocate_mat2_i(NMAX,SMAX);
  char file_site[200];
  if(SITES[0]!='\0'){
    N_sites=Read_sites_file(site_res, chain_res, nres_site, description,
			    SITES, chain, seq, Nres, NMAX, SMAX);
    if(N_sites)strcpy(file_site, SITES);
  }
  if(N_sites==0){
    N_sites=Read_sites_PDB(site_res, chain_res, nres_site, description,
			   pdb, chain, seq, Nres, NMAX, SMAX);
    if(N_sites)strcpy(file_site, pdb);
    // Print site
    if(PRINT_SITE && N_sites)
      Print_sites(site_res, nres_site, description, N_sites,
		  seq, pdb, chain);
  }
  if(N_sites==0)return;
  for(i=0; i<N_sites; i++){
    if(description[i]==NULL){
      description[i]=malloc(10*sizeof(char));
      sprintf(description[i], "site%d", i+1);
    }else{
      char *ptr=description[i];
      while(*ptr!='\0'){
	if(*ptr=='\n'){*ptr='\0'; break;} ptr++;
      } 
    }
  }
  int S_sites=0;
  for(i=0; i<N_sites; i++){
    if(nres_site[i]>0)S_sites++;
  }
  if(S_sites==0)return;
  */

  // Testing active sites
  int numcoup=5, icoup=0;
  float *prof[numcoup], **coup[numcoup];
  char name_p[numcoup][40];
  if(Coup_dir){
    prof[icoup]=Prof_dir;
    coup[icoup]=Coup_dir;
    strcpy(name_p[icoup], "directionality");
    icoup++;
  }
  if(Coup_coord){
    prof[icoup]=Prof_coord;
    coup[icoup]=Coup_coord;
    strcpy(name_p[icoup], "coordination");
    icoup++;
  }
  if(Coup_proximity){
    prof[icoup]=Prof_proximity;
    coup[icoup]=Coup_proximity;
    strcpy(name_p[icoup], "proximity");
    icoup++;
  }
  if(Coup_deformation){
    prof[icoup]=Prof_deformation;
    coup[icoup]=Coup_deformation;
    strcpy(name_p[icoup], "deformation");
    icoup++;
  }
  if(Coup_dr_dir){
    prof[icoup]=Prof_dr_dir;
    coup[icoup]=Coup_dr_dir;
    strcpy(name_p[icoup], "covariance");
    icoup++;
  }

  /*if(Coup_deformation_dist){
    prof[icoup]=Prof_deformation_dist;
    coup[icoup]=Coup_deformation_dist;
    strcpy(name_p[icoup], "deformation_dist");
    icoup++;
    }*/

  int *site_res_ran[numran];
  for(j=0; j<numran; j++)
    site_res_ran[j]=malloc(Nres*sizeof(int *));

  char nameout[200];
  sprintf(nameout, "%s.binding_sites.dat", nameout1);
  FILE *file_out=fopen(nameout, "w");
  printf("Writing %s\n", nameout);
  fprintf(file_out, "# read binding sites in file %s\n", file_site);
  fprintf(file_out, "# profile type %c\n", PROF_TYPE);
  fprintf(file_out, "# N= %d, %d random sites\n", Na, numran);
  fprintf(file_out, "### 1=nres\t2=nchain"); j=3;
  for(k=0; k<icoup; k++){
    fprintf(file_out, "\t%d=<%s_prof>\t%d=Z(%s_prof)\t%d=P>(%s_prof)",
	    j, name_p[k], j+1, name_p[k], j+2, name_p[k]); j+=3;
    if(PRINT_RAN){
      fprintf(file_out, "\t%d=E(%s_p_ran>)\t%d=sigma(%s_p_ran>)",
	      j, name_p[k], j+1, name_p[k]); j+=2;
    }
    fprintf(file_out, "\t%d=<%s_coup>\t%d=Z(%s_coup)\t%d=P>(%s_coup)",
	    j, name_p[k], j+1, name_p[k], j+2, name_p[k]); j+=3;
    if(PRINT_RAN){
      fprintf(file_out, "\t%d=E(%s_p_ran>)\t%d=sigma(%s_p_ran>)",
	      j, name_p[k], j+1, name_p[k]); j+=2;
    }
  }
  fprintf(file_out, "\n");

  // Set chains
  char res_chain[Nres]; for(i=0; i<Nres; i++)res_chain[i]=seq[i].chain;
  char lab_chain[Nres]; int ini_chain[Nres], end_chain[Nres], ichain[Nres];
  //int Nchain=
  Count_chains(ichain, ini_chain, end_chain, lab_chain,res_chain, NULL, Nres);

  struct site_results site_results[numcoup], *res;
  int atom_site[Na]; for(i=0; i<Na; i++)atom_site[i]=0;
  int min_chain[Na], max_chain[Na], all_chain[Na];
  char chain_lab[Na];
  for(i=0; i<N_sites; i++){
    int nr=nres_site[i]; //if(nr<=1)continue;
    int *isite=site_res[i];
    int nchain=Count_chains(ichain, min_chain, max_chain, chain_lab,
			    chain_res[i], isite, nr);
    Identify_chains(all_chain, chain_lab, nchain, lab_chain, Nchain);
    fprintf(file_out, "## %s\n", description[i]);
    fprintf(file_out, "%d\t%d", nr, nchain);
    for(j=0; j<numran; j++){
      Random_sites(site_res_ran[j], nr, isite,
		   ichain, min_chain, max_chain, all_chain, nchain,
		   ini_chain, end_chain);
    }
    res=site_results;
    for(k=0; k<icoup; k++){
      Test_site(res, atom_site, prof[k], coup[k], Na,
		isite, site_res_ran, numran, nr, atomres);
      fprintf(file_out, "\t%.3g\t%.1f\t%.3f",
	      res->prof, res->Z_p, res->P_p);
      if(PRINT_RAN)
	fprintf(file_out, "\t%.3g\t%.1f", res->p_ran1, res->p_ran2);
      fprintf(file_out, "\t%.3g\t%.1f\t%.3f",
	      res->coup, res->Z_c, res->P_c); //->c_ran1
      if(PRINT_RAN)
	fprintf(file_out, "\t%.3g\t%.1f", res->c_ran1, res->c_ran2);
      res++;
    }
    fprintf(file_out, "\n");
  }
  fclose(file_out);

  // Profile for binding residues
  /*float ave_p[icoup];
  for(k=0; k<icoup; k++){
    double sum=0; float *p=prof[k];
    for(i=0; i<Na; i++)sum+=p[i];
    ave_p[k]=sum/Na;
    }*/

  sprintf(nameout, "%s.binding_residues.dat", nameout1);
  file_out=fopen(nameout, "w");
  printf("Writing %s\n", nameout);
  fprintf(file_out, "#res\taa\tchain");
  for(k=0; k<icoup; k++){
    fprintf(file_out, "\t%s_p", name_p[k]);
  }
  fprintf(file_out, "\n");
  for(i=0; i<Na; i++){
    site[i]=0;
    if(atom_site[i]==0)continue;
    if(atom_site[i]<0){
      int r=-atom_site[i];
      printf("WARNING, reference atom of res. %d  %c%s%c does not exist",
	     r, seq[r].amm, seq[r].pdbres, seq[r].chain);
      continue;
    }
    site[i]=1;
    //fprintf(file_out, "%s\t%c\t%c", pdbres[i], amm[i], chain[i]);
    fprintf(file_out, "%s\t%c\t%c", seq[i].pdbres, seq[i].amm, seq[i].chain);
    for(k=0; k<icoup; k++){
      fprintf(file_out, "\t%.3g", prof[k][i]); ///ave_p[k]
    }
    fprintf(file_out, "\n");
  }
  fclose(file_out);

  // Test pairs of sites
  if(N_sites<2){
    for(j=0; j<numran; j++)free(site_res_ran[j]);
    return;
  }
  sprintf(nameout, "%s.pairs_sites.dat", nameout1);
  printf("Writing %s\n", nameout);
  file_out=fopen(nameout, "w");
  fprintf(file_out, "# read binding sites in file %s\n", file_site);
  fprintf(file_out, "# profile type %c\n", PROF_TYPE);
  fprintf(file_out, "# N= %d, %d random sites\n", Na, numran);
  fprintf(file_out, "###1=nres1\t2=nres2\t3=overlap"); j=4;
  for(k=0; k<icoup; k++){
    fprintf(file_out, "\t%d=<%s_coup>\t%d=Z(%s_coup)\t%d=P>(%s_coup)",
	    j, name_p[k], j+1, name_p[k], j+2, name_p[k]); j+=3;
  }
  fprintf(file_out, "\n");

  int coupled_site[Nres];
  char chain_site[Nres];
  for(i=0; i<N_sites; i++){
    int n1=nres_site[i]; if(n1<=0)continue;
    int *isite=site_res[i];
    for(k=0; k<n1; k++){
      coupled_site[k]=isite[k]; chain_site[k]=chain_res[i][k];
    }
    for(j=i+1; j<N_sites; j++){
      int n2=nres_site[j]; if(n2<=0)continue;
      int *jsite=site_res[j], l=n1;
      for(k=0; k<n2; k++){
	coupled_site[l]=jsite[k]; chain_site[l]=chain_res[j][k]; l++;
      }
      int nchain=Count_chains(ichain, min_chain, max_chain, chain_lab,
			      chain_site, coupled_site, l);
      Identify_chains(all_chain, chain_lab, nchain, lab_chain, Nchain);
      for(k=0; k<numran; k++){
	Random_sites(site_res_ran[k], l, coupled_site,
		     ichain, min_chain, max_chain, all_chain, nchain,
		     ini_chain, end_chain);
      }
      fprintf(file_out, "## %s\t%s", description[i], description[j]);
      if(Nchain>1)fprintf(file_out, "\t%d chains", nchain);
      fprintf(file_out, "\n");
      int q=Site_overlap(isite, n1, jsite, n2);
      fprintf(file_out, "%d\t%d\t%d", n1, n2, q);
      res=site_results;
      for(k=0; k<icoup; k++){
	Test_pairs(res, atom_site, prof[k], coup[k], Na,
		   coupled_site, site_res_ran, numran, n1, l, atomres);
	fprintf(file_out, "\t%.3g\t%.1f\t%.3f",
		res->coup, res->Z_c, res->P_c);
	res++;
      }
      fprintf(file_out, "\n");
    }
  }
  fclose(file_out);
  for(j=0; j<numran; j++)free(site_res_ran[j]);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6fe8, %rsp           # imm = 0x6FE8
movq %r9, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %rcx, -0x60(%rbp)
movq %rdx, %r12
movq %rsi, -0x58(%rbp)
movq %rdi, -0x70(%rbp)
movl 0x70(%rbp), %ebx
movl 0x60(%rbp), %r14d
movq 0x78(%rbp), %r15
movq 0x58(%rbp), %r13
leaq 0x18fca(%rip), %rdi     # 0x5dcaf
callq 0x2090
subq $0x8, %rsp
leaq -0x7010(%rbp), %rdi
leaq -0x1250(%rbp), %rsi
leaq -0x50d0(%rbp), %rdx
leaq -0x3190(%rbp), %rcx
leaq -0x2b0(%rbp), %r8
movl $0x3e8, %r9d            # imm = 0x3E8
pushq $0x1
pushq %rbx
pushq 0x68(%rbp)
pushq %r14
pushq %r13
pushq %r15
pushq 0x88(%rbp)
callq 0x48755
addq $0x40, %rsp
movl %eax, %ebx
leaq 0x1895e(%rip), %rdi     # 0x5d699
movq $0x0, -0x30(%rbp)
movl %eax, %esi
xorl %eax, %eax
callq 0x20f0
movl %ebx, -0x68(%rbp)
testl %ebx, %ebx
je 0x45aba
movq %rsp, %r11
addq $-0x30, %r11
movq %r11, %rsp
movq %rsp, %rcx
addq $-0x30, %rcx
movq %rcx, %rsp
movq %rsp, %rdx
addq $-0xd0, %rdx
movq %rdx, %rsp
testq %r12, %r12
je 0x44dab
movq -0x58(%rbp), %rax
movq %rax, (%r11)
movq %r12, (%rcx)
movabsq $0x7974696c616e6f, %rax # imm = 0x7974696C616E6F
movq %rax, 0x7(%rdx)
movabsq $0x6f69746365726964, %rax # imm = 0x6F69746365726964
movq %rax, (%rdx)
movl $0x1, %eax
movq %rax, -0x30(%rbp)
movq %rdx, -0x48(%rbp)
movq %rcx, -0xb0(%rbp)
movq 0x10(%rbp), %rax
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x44e10
movq -0x30(%rbp), %rsi
movl %esi, %ecx
leal (,%rsi,8), %edx
movq -0x60(%rbp), %r8
movq %r8, (%r11,%rdx)
movq -0xb0(%rbp), %r9
movq %rdi, (%r9,%rdx)
leaq (%rcx,%rcx,4), %rcx
movabsq $0x6e6f6974616e69, %rdx # imm = 0x6E6F6974616E69
movq -0x48(%rbp), %r10
movq %rdx, 0x5(%r10,%rcx,8)
movabsq $0x616e6964726f6f63, %rdx # imm = 0x616E6964726F6F63
movq %rdx, (%r10,%rcx,8)
incl %esi
movq %rsi, -0x30(%rbp)
jmp 0x44e1b
movq -0xb0(%rbp), %r9
movq -0x48(%rbp), %r10
movq 0x20(%rbp), %rcx
testq %rax, %rax
je 0x44e5d
movq -0x30(%rbp), %rdi
movl %edi, %edx
leal (,%rdi,8), %esi
movq -0x38(%rbp), %r8
movq %r8, (%r11,%rsi)
movq %rax, (%r9,%rsi)
leaq (%rdx,%rdx,4), %rax
movabsq $0x74696d69786f7270, %rdx # imm = 0x74696D69786F7270
movq %rdx, (%r10,%rax,8)
movw $0x79, 0x8(%r10,%rax,8)
incl %edi
movq %rdi, -0x30(%rbp)
movq 0x30(%rbp), %rax
testq %rcx, %rcx
je 0x44ea3
movq 0x18(%rbp), %rdx
movq -0x30(%rbp), %r8
movl %r8d, %esi
leal (,%r8,8), %edi
movq %rdx, (%r11,%rdi)
movq %rcx, (%r9,%rdi)
leaq (%rsi,%rsi,4), %rcx
movabsq $0x74616d726f666564, %rdx # imm = 0x74616D726F666564
movq %rdx, (%r10,%rcx,8)
movl $0x6e6f69, 0x8(%r10,%rcx,8) # imm = 0x6E6F69
incl %r8d
movq %r8, -0x30(%rbp)
testq %rax, %rax
movq %r11, -0x78(%rbp)
je 0x44ee6
movq 0x28(%rbp), %rcx
movq -0x30(%rbp), %rdi
movl %edi, %edx
leal (,%rdi,8), %esi
movq %rcx, (%r11,%rsi)
movq %rax, (%r9,%rsi)
leaq (%rdx,%rdx,4), %rax
movabsq $0x6e61697261766f63, %rcx # imm = 0x6E61697261766F63
movq %rcx, (%r10,%rax,8)
movl $0x65636e, 0x7(%r10,%rax,8) # imm = 0x65636E
incl %edi
movq %rdi, -0x30(%rbp)
movl 0x50(%rbp), %r12d
movq %rsp, %r15
addq $-0x1f40, %r15          # imm = 0xE0C0
movq %r15, %rsp
movl 0x70(%rbp), %eax
movslq %eax, %rbx
shlq $0x3, %rbx
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x21d0
movq %rax, (%r15,%r14,8)
incq %r14
cmpq $0x3e8, %r14            # imm = 0x3E8
jne 0x44f04
movq %r15, -0x40(%rbp)
leaq 0x187bc(%rip), %rsi     # 0x5d6e3
leaq -0x1e0(%rbp), %rbx
movq %rbx, %rdi
movq 0x80(%rbp), %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x122fa(%rip), %rsi     # 0x57240
movq %rbx, %rdi
callq 0x2210
movq %rax, %r13
leaq 0xcd83(%rip), %rdi      # 0x51cdb
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x1878f(%rip), %rsi     # 0x5d6f8
leaq -0x2b0(%rbp), %rdx
movq %r13, %rdi
xorl %eax, %eax
callq 0x2190
leaq 0x222c3(%rip), %rax     # 0x67244
movsbl (%rax), %edx
leaq 0x1878e(%rip), %rsi     # 0x5d719
movq %r13, %rdi
xorl %eax, %eax
callq 0x2190
leaq 0x18790(%rip), %rsi     # 0x5d72c
movq %r13, %rdi
movl %r12d, %edx
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %eax, %eax
callq 0x2190
leaq 0x18791(%rip), %rdi     # 0x5d746
movl $0x13, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2280
movq -0x30(%rbp), %rax
movl %eax, %r14d
testl %eax, %eax
movq %r14, -0x88(%rbp)
movq %r13, -0x50(%rbp)
jle 0x450b3
movl $0x3, %ebx
movq -0x48(%rbp), %r12
leal 0x1(%rbx), %r8d
leal 0x2(%rbx), %r10d
movq %r13, %rdi
leaq 0x1875e(%rip), %rsi     # 0x5d75a
movl %ebx, %edx
movq %r12, %rcx
movq %r12, %r9
xorl %eax, %eax
pushq %r12
pushq %r10
callq 0x2190
addq $0x10, %rsp
movq %r13, %r15
leal 0x3(%rbx), %r13d
cmpl $0x0, 0x35a6f(%rip)     # 0x7aa90
je 0x45047
leal 0x4(%rbx), %r8d
movq %r15, %rdi
leaq 0x18754(%rip), %rsi     # 0x5d785
movl %r13d, %edx
movq %r12, %rcx
movq %r12, %r9
xorl %eax, %eax
callq 0x2190
addl $0x5, %ebx
movl %ebx, %r13d
leal 0x1(%r13), %r8d
leal 0x2(%r13), %r10d
movq %r15, %rdi
leaq 0x18751(%rip), %rsi     # 0x5d7aa
movl %r13d, %edx
movq %r12, %rcx
movq %r12, %r9
xorl %eax, %eax
pushq %r12
pushq %r10
callq 0x2190
addq $0x10, %rsp
leal 0x3(%r13), %ebx
cmpl $0x0, 0x35a14(%rip)     # 0x7aa90
je 0x450a2
leal 0x4(%r13), %r8d
movq %r15, %rdi
leaq 0x186f9(%rip), %rsi     # 0x5d785
movl %ebx, %edx
movq %r12, %rcx
movq %r12, %r9
xorl %eax, %eax
callq 0x2190
addl $0x5, %r13d
movl %r13d, %ebx
addq $0x28, %r12
decq %r14
movq -0x50(%rbp), %r13
jne 0x44fea
movl $0xa, %edi
movq %r13, %rsi
callq 0x2140
movl 0x70(%rbp), %eax
movq %rax, %rcx
movl %ecx, %eax
movq %rsp, %r8
leaq 0xf(%rax), %rdi
andq $-0x10, %rdi
subq %rdi, %r8
movq %r8, %rsp
testl %ecx, %ecx
jle 0x450fa
movq 0x68(%rbp), %rcx
addq $0xc, %rcx
xorl %edx, %edx
movb (%rcx), %sil
movb %sil, (%r8,%rdx)
incq %rdx
addq $0x20, %rcx
cmpq %rdx, %rax
jne 0x450e7
movq %rsp, %rcx
movq %rdi, -0xd0(%rbp)
subq %rdi, %rcx
movq %rcx, %rsp
movq %rsp, %r14
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, %rsp
movq %rsp, %rdi
movq %rax, -0xc8(%rbp)
subq %rax, %rdi
movq %rdi, %rsp
subq $0x8, %rsp
movq %rdi, -0xc0(%rbp)
movq %r14, %rsi
movq %rdx, -0xf8(%rbp)
movq %rcx, -0x108(%rbp)
xorl %r9d, %r9d
movl 0x70(%rbp), %eax
pushq %rax
callq 0x46c33
addq $0x10, %rsp
movq %rsp, %rax
addq $-0xd0, %rax
movq %rax, -0xe8(%rbp)
movq %rax, %rsp
movl 0x50(%rbp), %eax
movl %eax, %r15d
movq %rsp, %r12
leaq 0xf(,%r15,4), %rbx
andq $-0x10, %rbx
subq %rbx, %r12
movq %r12, %rsp
testl %eax, %eax
jle 0x451a8
leaq (,%r15,4), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2110
movq %r12, -0x90(%rbp)
movq %r14, -0x100(%rbp)
movq %rsp, %rax
subq %rbx, %rax
movq %rax, -0x60(%rbp)
movq %rax, %rsp
movq %rsp, %rax
subq %rbx, %rax
movq %rax, -0x58(%rbp)
movq %rax, %rsp
movq %rsp, %rax
subq %rbx, %rax
movq %rax, -0xb8(%rbp)
movq %rax, %rsp
movq %rsp, %rcx
movq %r15, -0xa0(%rbp)
leaq 0xf(%r15), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xf0(%rbp)
movq %rcx, %rsp
movl -0x68(%rbp), %eax
movl %eax, %ecx
movq %rcx, -0xd8(%rbp)
testl %eax, %eax
jle 0x4545a
xorl %r14d, %r14d
movl -0x1250(%rbp,%r14,4), %r12d
movq -0x7010(%rbp,%r14,8), %r9
movq -0x50d0(%rbp,%r14,8), %r8
subq $0x8, %rsp
movq -0xc0(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0xf0(%rbp), %rbx
movq %rbx, %rcx
movq %r9, -0x98(%rbp)
pushq %r12
callq 0x46c33
addq $0x10, %rsp
movq %r13, %r15
movl %eax, %r13d
movq -0xb8(%rbp), %rdi
movq %rbx, %rsi
movl %eax, %edx
movq -0x108(%rbp), %rcx
movl 0x60(%rbp), %r8d
callq 0x46cc3
movq %r14, -0xa8(%rbp)
movq -0x3190(%rbp,%r14,8), %rdx
movq %r15, %rdi
leaq 0x14f21(%rip), %rsi     # 0x5a1b9
xorl %eax, %eax
callq 0x2190
movq %r15, %rdi
leaq 0x185fd(%rip), %rsi     # 0x5d8a6
movq %r12, -0x38(%rbp)
movl %r12d, %edx
movq %r13, -0x80(%rbp)
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2190
xorl %ebx, %ebx
movq -0x40(%rbp), %r12
movq -0x100(%rbp), %r14
movq -0xc0(%rbp), %r13
movq -0xf8(%rbp), %r15
movq (%r12,%rbx,8), %rdi
movq -0x38(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq %r13, %rcx
movq -0x60(%rbp), %r8
movq -0x58(%rbp), %r9
pushq %r15
pushq %r14
pushq -0x80(%rbp)
pushq -0xb8(%rbp)
callq 0x47ca6
addq $0x20, %rsp
incq %rbx
cmpq $0x3e8, %rbx            # imm = 0x3E8
jne 0x452d9
cmpl $0x0, -0x30(%rbp)
movl 0x50(%rbp), %r12d
movq -0x78(%rbp), %r14
jle 0x45432
xorl %ebx, %ebx
movq -0xe8(%rbp), %r13
movq (%r14,%rbx,8), %rdx
movq -0xb0(%rbp), %rax
movq (%rax,%rbx,8), %rcx
movq %r13, %rdi
movq -0x90(%rbp), %rsi
movl %r12d, %r8d
movq -0x98(%rbp), %r9
pushq 0x38(%rbp)
pushq -0x38(%rbp)
pushq $0x3e8                  # imm = 0x3E8
pushq -0x40(%rbp)
callq 0x47161
addq $0x20, %rsp
xorps %xmm0, %xmm0
cvtss2sd (%r13), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x8(%r13), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x4(%r13), %xmm2
movq -0x50(%rbp), %r15
movq %r15, %rdi
leaq 0x18442(%rip), %rsi     # 0x5d7d5
movb $0x3, %al
callq 0x2190
cmpl $0x0, 0x356ef(%rip)     # 0x7aa90
je 0x453c6
xorps %xmm0, %xmm0
cvtss2sd 0x18(%r13), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x1c(%r13), %xmm1
movq %r15, %rdi
leaq 0x18426(%rip), %rsi     # 0x5d7e5
movb $0x2, %al
callq 0x2190
xorps %xmm0, %xmm0
cvtss2sd 0xc(%r13), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x14(%r13), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x10(%r13), %xmm2
movq %r15, %rdi
leaq 0x183ea(%rip), %rsi     # 0x5d7d5
movb $0x3, %al
callq 0x2190
cmpl $0x0, 0x35697(%rip)     # 0x7aa90
je 0x4541e
xorps %xmm0, %xmm0
cvtss2sd 0x20(%r13), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x24(%r13), %xmm1
movq %r15, %rdi
leaq 0x183ce(%rip), %rsi     # 0x5d7e5
movb $0x2, %al
callq 0x2190
addq $0x28, %r13
incq %rbx
cmpq %rbx, -0x88(%rbp)
jne 0x45330
movl $0xa, %edi
movq -0x50(%rbp), %r13
movq %r13, %rsi
callq 0x2140
movq -0xa8(%rbp), %r14
incq %r14
cmpq -0xd8(%rbp), %r14
jne 0x45216
movq %r13, %rdi
callq 0x20c0
leaq 0x18387(%rip), %rsi     # 0x5d7f0
leaq -0x1e0(%rbp), %r14
movq %r14, %rdi
movq 0x80(%rbp), %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x11db8(%rip), %rsi     # 0x57240
movq %r14, %rdi
callq 0x2210
movq %rax, %rbx
leaq 0xc841(%rip), %rdi      # 0x51cdb
movq %r14, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x1835d(%rip), %rdi     # 0x5d808
movl $0xd, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x2280
cmpl $0x0, -0x30(%rbp)
jle 0x454ee
leaq 0x1834c(%rip), %r14     # 0x5d816
movq -0x88(%rbp), %r12
movq -0x48(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2190
addq $0x28, %r15
decq %r12
jne 0x454d5
movl $0xa, %edi
movq %rbx, -0x38(%rbp)
movq %rbx, %rsi
callq 0x2140
cmpl $0x0, 0x50(%rbp)
movq -0x70(%rbp), %r14
movq -0x90(%rbp), %r15
movq -0xa0(%rbp), %r12
jle 0x45605
leaq 0x123a2(%rip), %rbx     # 0x578c4
xorl %r13d, %r13d
movl $0x0, (%r14,%r13,4)
movl (%r15,%r13,4), %esi
testl %esi, %esi
je 0x455f9
js 0x455ce
movl $0x1, (%r14,%r13,4)
movq %r13, %rax
shlq $0x5, %rax
movq 0x68(%rbp), %rcx
leaq (%rcx,%rax), %rdx
addq $0xd, %rdx
movsbl 0x6(%rdx), %ecx
movsbl -0x1(%rdx), %r8d
movq -0x38(%rbp), %rdi
leaq 0x182e8(%rip), %rsi     # 0x5d856
xorl %eax, %eax
callq 0x2190
cmpl $0x0, -0x30(%rbp)
movq -0x88(%rbp), %r15
movq -0x78(%rbp), %r12
jle 0x455ac
xorl %r14d, %r14d
movq (%r12,%r14,8), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax,%r13,4), %xmm0
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x2190
incq %r14
cmpq %r14, %r15
jne 0x45589
movl $0xa, %edi
movq -0x38(%rbp), %rsi
callq 0x2140
movq -0x70(%rbp), %r14
movq -0x90(%rbp), %r15
movq -0xa0(%rbp), %r12
jmp 0x455f9
negl %esi
movq %rsi, %rax
shlq $0x5, %rax
movq 0x68(%rbp), %rcx
addq %rax, %rcx
addq $0xd, %rcx
movsbl 0x6(%rcx), %edx
movsbl -0x1(%rcx), %r8d
leaq 0x1822a(%rip), %rdi     # 0x5d81c
xorl %eax, %eax
callq 0x20f0
incq %r13
cmpq %r12, %r13
jne 0x45525
movq -0x38(%rbp), %rdi
callq 0x20c0
cmpl $0x1, -0x68(%rbp)
jg 0x45634
xorl %ebx, %ebx
movq -0x40(%rbp), %r14
movq (%r14,%rbx,8), %rdi
callq 0x2050
incq %rbx
cmpq $0x3e8, %rbx            # imm = 0x3E8
jne 0x4561a
jmp 0x45aba
leaq 0x18224(%rip), %rsi     # 0x5d85f
leaq -0x1e0(%rbp), %rbx
movq %rbx, %rdi
movq 0x80(%rbp), %rdx
xorl %eax, %eax
callq 0x2260
leaq 0xc681(%rip), %rdi      # 0x51cdb
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
leaq 0x11bd5(%rip), %rsi     # 0x57240
movq %rbx, %rdi
callq 0x2210
movq %rax, %r13
leaq 0x1807b(%rip), %rsi     # 0x5d6f8
leaq -0x2b0(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x2190
leaq 0x21baf(%rip), %rax     # 0x67244
movsbl (%rax), %edx
leaq 0x1807a(%rip), %rsi     # 0x5d719
movq %r13, %rdi
xorl %eax, %eax
callq 0x2190
leaq 0x1807c(%rip), %rsi     # 0x5d72c
movq %r13, %rdi
movl 0x50(%rbp), %edx
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %eax, %eax
callq 0x2190
leaq 0x181a9(%rip), %rdi     # 0x5d872
movl $0x1, %eax
movq %rax, -0xe0(%rbp)
movl $0x1c, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x2280
cmpl $0x0, -0x30(%rbp)
movq -0x48(%rbp), %r12
jle 0x4573a
movq -0x88(%rbp), %rax
leaq (%rax,%rax,2), %r14
leaq 0x180a7(%rip), %rbx     # 0x5d7aa
xorl %r15d, %r15d
leal 0x4(%r15), %edx
leal 0x5(%r15), %r8d
leal 0x6(%r15), %r10d
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rcx
movq %r12, %r9
xorl %eax, %eax
pushq %r12
pushq %r10
callq 0x2190
addq $0x10, %rsp
addq $0x28, %r12
addq $0x3, %r15
cmpq %r15, %r14
jne 0x45706
movl $0xa, %edi
movq %r13, %rsi
callq 0x2140
movq %rsp, %r9
subq -0xc8(%rbp), %r9
movq %r9, %rsp
movq %rsp, %r8
subq -0xd0(%rbp), %r8
movq %r8, %rsp
movl -0x68(%rbp), %eax
cmpl $0x2, %eax
movl $0x1, %ecx
cmovgel %eax, %ecx
movq %rcx, -0x110(%rbp)
xorl %r10d, %r10d
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0xb8(%rbp), %r14
movq %r13, -0x50(%rbp)
movq %r8, -0xc8(%rbp)
movq %r9, -0x38(%rbp)
movl -0x1250(%rbp,%r10,4), %r11d
testl %r11d, %r11d
jle 0x45a80
movq -0x7010(%rbp,%r10,8), %rbx
movq -0x50d0(%rbp,%r10,8), %rax
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edi
movl %edi, (%r9,%rcx,4)
movb (%rax,%rcx), %dil
movb %dil, (%r8,%rcx)
incq %rcx
cmpq %rcx, %r11
jne 0x457ba
leaq 0x1(%r10), %rax
cmpq -0xd8(%rbp), %rax
jae 0x45a80
leaq (%r8,%r11), %rdi
leaq (%r9,%r11,4), %r12
movq -0xe0(%rbp), %rax
movq %r10, -0x70(%rbp)
movq %r11, -0x80(%rbp)
movq %rbx, -0x68(%rbp)
movq %rdi, -0x48(%rbp)
movq %r12, -0xd0(%rbp)
movl -0x1250(%rbp,%rax,4), %ecx
movq %rcx, -0xa8(%rbp)
testl %ecx, %ecx
jle 0x45a70
movq -0x7010(%rbp,%rax,8), %rbx
movq %rax, -0x78(%rbp)
movq -0x50d0(%rbp,%rax,8), %rax
xorl %r15d, %r15d
movq -0xa8(%rbp), %r10
movl (%rbx,%r15,4), %ecx
movl %ecx, (%r12,%r15,4)
movb (%rax,%r15), %cl
movb %cl, (%rdi,%r15)
incq %r15
cmpq %r15, %r10
jne 0x4583c
movq %rbx, -0xa0(%rbp)
addq %r11, %r15
subq $0x8, %rsp
movq -0xc0(%rbp), %rdi
movq -0xf0(%rbp), %rbx
movq %rbx, %rcx
pushq %r15
callq 0x46c33
addq $0x10, %rsp
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, -0x98(%rbp)
movl %eax, %edx
movq -0x108(%rbp), %rcx
movl 0x60(%rbp), %r8d
callq 0x46cc3
xorl %r12d, %r12d
movq -0x100(%rbp), %rbx
movq %r14, %r13
movq -0xf8(%rbp), %r14
movq -0x40(%rbp), %rax
movq (%rax,%r12,8), %rdi
movl %r15d, %esi
movq -0x38(%rbp), %rdx
movq -0xc0(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x58(%rbp), %r9
pushq %r14
pushq %rbx
pushq -0x98(%rbp)
pushq %r13
callq 0x47ca6
addq $0x20, %rsp
incq %r12
cmpq $0x3e8, %r12            # imm = 0x3E8
jne 0x458b1
movq -0x98(%rbp), %r12
movq -0x70(%rbp), %rax
movq -0x3190(%rbp,%rax,8), %rdx
movq -0x78(%rbp), %rax
movq -0x3190(%rbp,%rax,8), %rcx
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
leaq 0x17f73(%rip), %rsi     # 0x5d88f
xorl %eax, %eax
callq 0x2190
movl 0x60(%rbp), %eax
cmpl $0x2, %eax
jl 0x4593f
movq %rbx, %rdi
leaq 0x17f63(%rip), %rsi     # 0x5d898
movl %r12d, %edx
xorl %eax, %eax
callq 0x2190
movl $0xa, %edi
movq %rbx, %rsi
callq 0x2140
movq -0x68(%rbp), %rdi
movq -0x80(%rbp), %r13
movl %r13d, %esi
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %r12
movl %r12d, %ecx
callq 0x495d2
movq %rbx, %rdi
leaq 0x17f2c(%rip), %rsi     # 0x5d8a3
movl %r13d, %edx
movl %r12d, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0x2190
cmpl $0x0, -0x30(%rbp)
movq -0xb0(%rbp), %rcx
movq -0x40(%rbp), %rdx
movl 0x50(%rbp), %r13d
movq 0x38(%rbp), %rax
movq -0x90(%rbp), %rsi
jle 0x45a2e
xorl %r14d, %r14d
movq -0xe8(%rbp), %rbx
movq %rcx, %r12
movq (%rcx,%r14,8), %rcx
subq $0x8, %rsp
movq %rbx, %rdi
movl %r13d, %r8d
movq -0x38(%rbp), %r9
pushq %rax
pushq %r15
pushq -0x80(%rbp)
pushq $0x3e8                  # imm = 0x3E8
pushq %rdx
callq 0x478b5
addq $0x30, %rsp
xorps %xmm0, %xmm0
cvtss2sd 0xc(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x14(%rbx), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x10(%rbx), %xmm2
movq -0x50(%rbp), %rdi
leaq 0x17dd3(%rip), %rsi     # 0x5d7d5
movb $0x3, %al
callq 0x2190
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdi
movq 0x38(%rbp), %rax
movq -0x40(%rbp), %rdx
movq %r12, %rcx
addq $0x28, %rbx
incq %r14
cmpq %r14, %rdi
jne 0x459b5
movl $0xa, %edi
movq -0x50(%rbp), %r13
movq %r13, %rsi
callq 0x2140
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0xb8(%rbp), %r14
movq -0x38(%rbp), %r9
movq -0xc8(%rbp), %r8
movq -0x70(%rbp), %r10
movq -0x80(%rbp), %r11
movq -0x48(%rbp), %rdi
movq -0xd0(%rbp), %r12
movq -0x78(%rbp), %rax
incq %rax
cmpq -0xd8(%rbp), %rax
jne 0x45808
incq %r10
incq -0xe0(%rbp)
cmpq -0x110(%rbp), %r10
jne 0x45797
movq %r13, %rdi
callq 0x20c0
xorl %ebx, %ebx
movq -0x40(%rbp), %r14
movq (%r14,%rbx,8), %rdi
callq 0x2050
incq %rbx
cmpq $0x3e8, %rbx            # imm = 0x3E8
jne 0x45aa5
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq