// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/align_tnm.c
// Function: Align_chains
int Align_chains(int *Nmut, char *AAwt, int *Posmut, char *AAmut,
		 struct Ali_score *ali, int *last_ali_res,
		 int *Nchain, float SEQID_THR, 
		 struct chain *chains1, int Nchain1,
		 struct residue *seq1, char *pdbid1,
		 struct chain *chains2, int Nchain2,
		 struct residue *seq2, char *pdbid2)
{
  float seqid_min=0.4, si_tol=0.05; // seqid_max=0.9;

  // Sequence alignment parameters
  int VBS=0;  // Verbose:
  int IDE=1;  // Use identity to score alignment
  int GAP=7;  // Gap opening penalty

  *Nchain=Nchain1;
  if(Nchain2<Nchain1){
    printf("WARNING, different number of chains: ");
    printf("%d (%s) and %d (%s)\n", Nchain1, pdbid1, Nchain2, pdbid2);
    if(Nchain2<Nchain1){printf("Exiting the program\n"); exit(8);}
    printf("Considering only the %d best matching chains\n", *Nchain);
  }

  ali->mammoth=0;
  ali->aligned=0;
  ali->ngaps=0;
  ali->seq_id=0;

  //Cluster chains_by_sequence identity
  // Alignments
  int nmax=Max_length(chains1, Nchain1)+Max_length(chains2, Nchain2);
  int **ali_all[Nchain1], *nali[Nchain1];
  int seqid[Nchain1][Nchain2];

  // Clusters
  int ic1, ic2, i;
  int ncl=0, n1cl[Nchain1], n2cl[Nchain1],*i1cl[Nchain1], *i2cl[Nchain1];
  for(ic1=0; ic1<Nchain1; ic1++){
    ali_all[ic1]=malloc(Nchain2*sizeof(int *));
    nali[ic1]=malloc(Nchain2*sizeof(int));
    i1cl[ic1]=malloc(Nchain1*sizeof(int));
    i2cl[ic1]=malloc(Nchain2*sizeof(int));
  }
  int cl2[Nchain2]; //cl1[Nchain1], 
  for(i=0; i<Nchain1; i++){n1cl[i]=0; n2cl[i]=0;}  //cl1[i]=-1; 
  for(i=0; i<Nchain2; i++)cl2[i]=-1;

  for(ic1=0; ic1< Nchain1; ic1++){
    struct chain *chp1=chains1+ic1;
    int n1=chp1->nres;
    chp1->match=-1;

    int seqid_opt=0, ic2_opt=-1;      
    for(ic2=0; ic2< Nchain2; ic2++){
      struct chain *chp2=chains2+ic2;
      int n2=chp2->nres, na;

      printf("Aligning chains %d %c prot1 L=%d and %d %c prot2 L=%d\n",
	     ic1, chp1->label, n1, ic2, chp2->label, n2);

      int nmax_seqres=chp1->N_seqres+chp1->N_seqres;
      char ali1[nmax_seqres], ali2[nmax_seqres];

      if(n1 <= MIN_ALI_LEN){
	// Trivial alignment for peptides or nucleic acids
	printf("Trivial alignment for peptide or nucleic acid\n");
	na=n1;
	for(i=0; i<n1; i++){
	  ali1[i]=chp1->seq[i];
	  if(i<n2){ali2[i]=chp2->seq[i];}
	  else{ali2[i]='-';}
	}
      }else{
	int al=alignNW(chp1->seqres, chp1->N_seqres,
		       chp2->seqres, chp2->N_seqres,
		       VBS,IDE,GAP, ali1, ali2, &na);
	if(al==0){printf("ERROR, alignment failed\n"); exit(8);}
      }

      // Transform the alignment of seqres into an alignment of
      // structured residues (seq)
      ali_all[ic1][ic2]=malloc(nmax*sizeof(int));
      nali[ic1][ic2]=PDB_ali(ali_all[ic1][ic2], &(seqid[ic1][ic2]),
			     na, ali1, chp1, n1, ali2, chp2, n2);
 
      printf("Seq.id= %d alignment length %d\n",
	     seqid[ic1][ic2],nali[ic1][ic2]);

      // Best matching chain
      if(seqid[ic1][ic2] > seqid_opt){
	seqid_opt=seqid[ic1][ic2]; ic2_opt=ic2;
      }
    } // end ic2

    printf("Best match: chain %d seqid= %d n=%d chain %d",
	   ic1, chp1->nres, seqid_opt, ic2_opt);
    if(ic2_opt>=0)printf(" n=%d\n", chains2[ic2_opt].nres);
    if(ic2_opt<0 || (seqid_opt<seqid_min && n1>MIN_ALI_LEN)){
      // If short chain (peptide) accept the match even for low identity
      printf("\nERROR, could not reliably match chain %d\n", ic1);
      exit(8);
    }

    /* float ss=(float)seqid_opt/n1;
       if(ss < SEQID_THR){
       printf("WARNING! Low sequence identity %.1f\%\n", ss*100);
       printf("Performing structure alignment with Mammoth\n");
       ali->mamm_score=
       Mammoth_ali(&aligned, &seqid_opt, &psi, chp1->alignres,
       chp1, seq1, chp2, seq2);
       ali->mammoth=1;
       ali->psi+=sqrt(n1*n2)*psi;
       }*/
    
    int icl, seqid_thr;
    if(cl2[ic2_opt]>=0){icl=cl2[ic2_opt];} // already clustered
    else{icl=ncl; ncl++;}
    if(seqid_opt>=seqid_min){seqid_thr=seqid_opt-si_tol;}
    else{seqid_thr=seqid_min;}

    // Set clusters
    i1cl[icl][n1cl[icl]]=ic1; n1cl[icl]++; //cl1[ic1]=icl; 
    for(ic2=0; ic2< Nchain2; ic2++){
      if((seqid[ic1][ic2]>=seqid_thr)&&(cl2[ic2]!=icl)){
	cl2[ic2]=icl; i2cl[icl][n2cl[icl]]=ic2; n2cl[icl]++;
      }
    }
  } // end ic1

  if(ncl==0){
    printf("ERROR, no sequence clusters could be found\n"); exit(8);
  }

  for(int ic=0; ic<ncl; ic++){
    Superimpose_cluster(chains1, Nchain1, chains2, Nchain2,
			i1cl[ic], n1cl[ic], i2cl[ic], n2cl[ic],
			ali_all, nali);
  }


  *Nmut=0;
  int nres1=0, nres2=0;
  // Store alignments
  for(ic1=0; ic1<Nchain1; ic1++){
    struct chain *chp1=chains1+ic1;
    int n1=chp1->nres;
    ic2=chp1->match;
    if(ic2<0){
      printf("ERROR, chain %d %c n=%d could not be superimposed\n",
	     ic1, chp1->label, n1); exit(8);
    }
    
    chp1->alignres=malloc(n1*sizeof(int));
   
    struct chain *chp2=chains2+ic2;
    int n2=chp2->nres;
    chp2->match=ic1;
    nres1+=n1; nres2+=n2;
    int *al=ali_all[ic1][ic2];
   
    // Print alignment
    printf("Protein_1: ");
    for(i=0; i<n1; i++)printf("%c", chp1->seq[i]);
    printf("\nProtein_2: ");
    for(i=0; i<n1; i++){
      if(al[i]>=0){printf("%c", chp2->seq[al[i]]);}
      else{printf("-");}
    }
    printf("\n");
    
    // Store alignment, count mutations
    int seq_id=0, ngap=0, gap=1;
    printf("Alignment: ");
    for(i=0; i<n1; i++){
      if(al[i]>=0){
	if(gap)gap=0;
	if(chp1->seq[i]==chp2->seq[al[i]]){
	  seq_id++;
	}else{ // Mutation
	  Posmut[*Nmut]=i;
	  AAwt[*Nmut]=chp1->seq[i];
	  AAmut[*Nmut]=chp2->seq[al[i]];
	  (*Nmut)++;
	} 
	chp1->alignres[i]=al[i];
	printf("%c",chp2->seq[al[i]]);
      }else{
	chp1->alignres[i]=-1;
	printf("-");
	ngap++;
	if(gap==0){ali->ngaps++; gap=1;}
      }
    }
    printf("\n");

    if(gap)ali->ngaps--; 
    ali->seq_id+=seq_id;
    int aligned=n1-ngap;
    ali->aligned+=aligned;
  } // end ic1

  printf("%d mutations: ", *Nmut); int NMUT=1000;
  for(i=0; i<*Nmut; i++){
    if(*Nmut==NMUT)break;
    printf(" %c%s%c", AAwt[i],seq1[Posmut[i]].pdbres,AAmut[i]);
  }
  printf("\n");
  
  ali->seq_id/=ali->aligned; ali->seq_id*=100;
  float norm=sqrt((float)nres1*nres2);
  ali->psi/=norm;
  //ali->aligned/=norm;
  ali->aligned/=nres1;

  ali->alignres=malloc(nres1*sizeof(int)); i=0;
  for(ic1=0; ic1< *Nchain; ic1++){
    struct chain *chp1=chains1+ic1;
    int n1=chp1->nres, i1, ini2=(chains2+chp1->match)->ini_res;
    for(i1=0; i1<n1; i1++){
      if(chp1->alignres[i1]>=0){
	ali->alignres[i]=chp1->alignres[i1]+ini2;
      }else{
	ali->alignres[i]=-1;
      }
      i++;
    }
  }

  // last aligned residue
  for(i=nres1-1; i>=0; i--){
    if(ali->alignres[i]>=0){
      *last_ali_res=i+1; break;
    }
  }

  for(ic1=0; ic1<Nchain1; ic1++){
    for(i=0; i<Nchain2; i++)free(ali_all[ic1][i]);
    free(ali_all[ic1]);
    free(nali[ic1]);
    free(i1cl[ic1]);
    free(i2cl[ic1]);
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x1d0, %rsp            # imm = 0x1D0
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movl 0x40(%rbp), %eax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movss %xmm0, -0x44(%rbp)
movss 0x5fb8f(%rip), %xmm0    # 0x76084
movss %xmm0, -0x48(%rbp)
movss 0x5fb7a(%rip), %xmm0    # 0x7607c
movss %xmm0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x1, -0x54(%rbp)
movl $0x7, -0x58(%rbp)
movl 0x20(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movl 0x40(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0x1658b
leaq 0x64d06(%rip), %rdi     # 0x7b23a
movb $0x0, %al
callq 0x10d0
movl 0x20(%rbp), %esi
movq 0x30(%rbp), %rdx
movl 0x40(%rbp), %ecx
movq 0x50(%rbp), %r8
leaq 0x64d10(%rip), %rdi     # 0x7b260
movb $0x0, %al
callq 0x10d0
movl 0x40(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0x16577
leaq 0x6004f(%rip), %rdi     # 0x765b5
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movq 0x10(%rbp), %rax
movl (%rax), %esi
leaq 0x64cf1(%rip), %rdi     # 0x7b275
movb $0x0, %al
callq 0x10d0
movq -0x38(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
movq 0x18(%rbp), %rdi
movl 0x20(%rbp), %esi
callq 0x17860
movl %eax, -0x1bc(%rbp)
movq 0x38(%rbp), %rdi
movl 0x40(%rbp), %esi
callq 0x17860
movl %eax, %ecx
movl -0x1bc(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl 0x20(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x68(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x1b8(%rbp)
movq %rcx, %rsp
movq %rax, -0x70(%rbp)
movl 0x20(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x1b0(%rbp)
movq %rcx, %rsp
movq %rax, -0x78(%rbp)
movl 0x20(%rbp), %eax
movl %eax, %ecx
movl 0x40(%rbp), %eax
movq %rax, -0x1a8(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x1a0(%rbp)
movq %rdx, %rsp
movq %rcx, -0x80(%rbp)
movq %rax, -0x88(%rbp)
movl $0x0, -0x98(%rbp)
movl 0x20(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x198(%rbp)
movq %rcx, %rsp
movq %rax, -0xa0(%rbp)
movl 0x20(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x190(%rbp)
movq %rcx, %rsp
movq %rax, -0xa8(%rbp)
movl 0x20(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x188(%rbp)
movq %rcx, %rsp
movq %rax, -0xb0(%rbp)
movl 0x20(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x180(%rbp)
movq %rcx, %rsp
movq %rax, -0xb8(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0x167c2
movslq 0x40(%rbp), %rdi
shlq $0x3, %rdi
callq 0x1180
movq %rax, %rdx
movq -0x1b8(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq 0x40(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, %rdx
movq -0x1b0(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq 0x20(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, %rdx
movq -0x188(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq 0x40(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, %rdx
movq -0x180(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x16717
movl 0x40(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x1c8(%rbp)
movq %rcx, %rsp
movq %rax, -0xc0(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0x16838
movq -0x190(%rbp), %rax
movq -0x198(%rbp), %rcx
movslq -0x94(%rbp), %rdx
movl $0x0, (%rcx,%rdx,4)
movslq -0x94(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x167f2
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl 0x40(%rbp), %eax
jge 0x16873
movq -0x1c8(%rbp), %rax
movslq -0x94(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x16842
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0x16f33
movq 0x18(%rbp), %rax
movslq -0x8c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0xc8(%rbp), %rax
movl $0xffffffff, 0x40(%rax) # imm = 0xFFFFFFFF
movl $0x0, -0xd0(%rbp)
movl $0xffffffff, -0xd4(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl 0x40(%rbp), %eax
jge 0x16cf7
movq 0x38(%rbp), %rax
movslq -0x90(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xe4(%rbp)
movl -0x8c(%rbp), %esi
movq -0xc8(%rbp), %rax
movsbl 0x34(%rax), %edx
movl -0xcc(%rbp), %ecx
movl -0x90(%rbp), %r8d
movq -0xe0(%rbp), %rax
movsbl 0x34(%rax), %r9d
movl -0xe4(%rbp), %edi
subq $0x10, %rsp
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x6494a(%rip), %rdi     # 0x7b2a3
xorl %eax, %eax
callq 0x10d0
addq $0x10, %rsp
movq -0xc8(%rbp), %rax
movl 0x60(%rax), %eax
addl %eax, %eax
movl %eax, -0xec(%rbp)
movl -0xec(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0xf8(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x1d8(%rbp)
movq %rcx, %rsp
movq %rax, -0x100(%rbp)
movl -0xec(%rbp), %eax
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x1d0(%rbp)
movq %rcx, %rsp
movq %rax, -0x108(%rbp)
movl -0xcc(%rbp), %eax
leaq 0x763f3(%rip), %rcx     # 0x8cdd0
cmpl (%rcx), %eax
jg 0x16aa4
leaq 0x648ee(%rip), %rdi     # 0x7b2da
movb $0x0, %al
callq 0x10d0
movl -0xcc(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0xcc(%rbp), %eax
jge 0x16a9f
movq -0x1d8(%rbp), %rax
movq -0xc8(%rbp), %rcx
movq 0x50(%rcx), %rcx
movslq -0x94(%rbp), %rdx
movb (%rcx,%rdx), %dl
movslq -0x94(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x94(%rbp), %eax
cmpl -0xe4(%rbp), %eax
jge 0x16a77
movq -0x1d0(%rbp), %rax
movq -0xe0(%rbp), %rcx
movq 0x50(%rcx), %rcx
movslq -0x94(%rbp), %rdx
movb (%rcx,%rdx), %dl
movslq -0x94(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x16a89
movq -0x1d0(%rbp), %rax
movslq -0x94(%rbp), %rcx
movb $0x2d, (%rax,%rcx)
jmp 0x16a8b
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x16a09
jmp 0x16b44
movq -0x1d0(%rbp), %r10
movq -0x1d8(%rbp), %r11
movq -0xc8(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0xc8(%rbp), %rax
movl 0x60(%rax), %esi
movq -0xe0(%rbp), %rax
movq 0x58(%rax), %rdx
movq -0xe0(%rbp), %rax
movl 0x60(%rax), %ecx
movl -0x50(%rbp), %eax
movw %ax, %r8w
movl -0x54(%rbp), %eax
movw %ax, %r9w
movl -0x58(%rbp), %ebx
leaq -0xe8(%rbp), %rax
subq $0x20, %rsp
movswl %r8w, %r8d
movswl %r9w, %r9d
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x6f610
addq $0x20, %rsp
movl %eax, -0x10c(%rbp)
cmpl $0x0, -0x10c(%rbp)
jne 0x16b42
leaq 0x647d8(%rip), %rdi     # 0x7b309
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x16b44
movslq -0x5c(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq -0x1d8(%rbp), %rcx
movq -0x1d0(%rbp), %r11
movq -0x1a8(%rbp), %rdx
movq -0x1a0(%rbp), %rsi
movq %rax, %r9
movq -0x1b8(%rbp), %rax
movslq -0x8c(%rbp), %rdi
movq (%rax,%rdi,8), %rdi
movslq -0x90(%rbp), %r8
movq %r9, (%rdi,%r8,8)
movslq -0x8c(%rbp), %rdi
movq (%rax,%rdi,8), %rax
movslq -0x90(%rbp), %rdi
movq (%rax,%rdi,8), %rdi
movslq -0x8c(%rbp), %rax
imulq %rdx, %rax
shlq $0x2, %rax
addq %rax, %rsi
movslq -0x90(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movl -0xe8(%rbp), %edx
movq -0xc8(%rbp), %r8
movl -0xcc(%rbp), %r9d
movq -0xe0(%rbp), %r10
movl -0xe4(%rbp), %eax
subq $0x20, %rsp
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x178c0
movq -0x1a8(%rbp), %rsi
movq -0x1a0(%rbp), %rcx
addq $0x20, %rsp
movl %eax, %r8d
movq -0x1b0(%rbp), %rax
movslq -0x8c(%rbp), %rdx
movq (%rax,%rdx,8), %rdx
movslq -0x90(%rbp), %rdi
movl %r8d, (%rdx,%rdi,4)
movslq -0x8c(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movslq -0x90(%rbp), %rdx
movl (%rcx,%rdx,4), %esi
movslq -0x8c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x646be(%rip), %rdi     # 0x7b322
movb $0x0, %al
callq 0x10d0
movq -0x1a8(%rbp), %rdx
movq -0x1a0(%rbp), %rax
movslq -0x8c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0xd0(%rbp), %eax
jle 0x16cd9
movq -0x1a0(%rbp), %rax
movq -0x1a8(%rbp), %rdx
movslq -0x8c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xd0(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0xd4(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, %rsp
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x168e1
movl -0x8c(%rbp), %esi
movq -0xc8(%rbp), %rax
movl 0x1c(%rax), %edx
movl -0xd0(%rbp), %ecx
movl -0xd4(%rbp), %r8d
leaq 0x64627(%rip), %rdi     # 0x7b342
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0xd4(%rbp)
jl 0x16d4e
movq 0x38(%rbp), %rax
movslq -0xd4(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %esi
leaq 0x65cf6(%rip), %rdi     # 0x7ca3d
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0xd4(%rbp)
jl 0x16d7a
cvtsi2ssl -0xd0(%rbp), %xmm1
movss -0x48(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x16d98
movl -0xcc(%rbp), %eax
leaq 0x7605a(%rip), %rcx     # 0x8cdd0
cmpl (%rcx), %eax
jle 0x16d98
movl -0x8c(%rbp), %esi
leaq 0x645e8(%rip), %rdi     # 0x7b36f
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movq -0x1c8(%rbp), %rax
movslq -0xd4(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x16dc5
movq -0x1c8(%rbp), %rax
movslq -0xd4(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x110(%rbp)
jmp 0x16de0
movl -0x98(%rbp), %eax
movl %eax, -0x110(%rbp)
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
cvtsi2ssl -0xd0(%rbp), %xmm0
ucomiss -0x48(%rbp), %xmm0
jb 0x16e07
cvtsi2ssl -0xd0(%rbp), %xmm0
subss -0x4c(%rbp), %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x114(%rbp)
jmp 0x16e12
cvttss2si -0x48(%rbp), %eax
movl %eax, -0x114(%rbp)
movq -0x198(%rbp), %rax
movq -0x188(%rbp), %rcx
movl -0x8c(%rbp), %esi
movslq -0x110(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x110(%rbp), %rdx
movslq (%rax,%rdx,4), %rdx
movl %esi, (%rcx,%rdx,4)
movslq -0x110(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x90(%rbp)
movl -0x90(%rbp), %eax
cmpl 0x40(%rbp), %eax
jge 0x16f1d
movq -0x1a0(%rbp), %rax
movq -0x1a8(%rbp), %rdx
movslq -0x8c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x114(%rbp), %eax
jl 0x16f07
movq -0x1c8(%rbp), %rax
movslq -0x90(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x110(%rbp), %eax
je 0x16f07
movq -0x190(%rbp), %rax
movq -0x180(%rbp), %rcx
movq -0x1c8(%rbp), %rdx
movl -0x110(%rbp), %edi
movslq -0x90(%rbp), %rsi
movl %edi, (%rdx,%rsi,4)
movl -0x90(%rbp), %esi
movslq -0x110(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x110(%rbp), %rdx
movslq (%rax,%rdx,4), %rdx
movl %esi, (%rcx,%rdx,4)
movslq -0x110(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x16f09
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x16e59
jmp 0x16f1f
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1687d
cmpl $0x0, -0x98(%rbp)
jne 0x16f54
leaq 0x64457(%rip), %rdi     # 0x7b39a
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movl $0x0, -0x118(%rbp)
movl -0x118(%rbp), %eax
cmpl -0x98(%rbp), %eax
jge 0x17008
movq -0x1b0(%rbp), %rax
movq -0x1b8(%rbp), %r10
movq -0x190(%rbp), %r11
movq -0x180(%rbp), %rbx
movq -0x198(%rbp), %r9
movq -0x188(%rbp), %r8
movq 0x18(%rbp), %rdi
movl 0x20(%rbp), %esi
movq 0x38(%rbp), %rdx
movl 0x40(%rbp), %ecx
movslq -0x118(%rbp), %r14
movq (%r8,%r14,8), %r8
movslq -0x118(%rbp), %r14
movl (%r9,%r14,4), %r9d
movslq -0x118(%rbp), %r14
movq (%rbx,%r14,8), %rbx
movslq -0x118(%rbp), %r14
movl (%r11,%r14,4), %r11d
subq $0x20, %rsp
movq %rbx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x17a70
addq $0x20, %rsp
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x16f5e
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x11c(%rbp)
movl $0x0, -0x120(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0x174ac
movq 0x18(%rbp), %rax
movslq -0x8c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x12c(%rbp)
movq -0x128(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
jge 0x170b0
movl -0x8c(%rbp), %esi
movq -0x128(%rbp), %rax
movsbl 0x34(%rax), %edx
movl -0x12c(%rbp), %ecx
leaq 0x64327(%rip), %rdi     # 0x7b3c6
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
movslq -0x12c(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, %rdx
movq -0x1b8(%rbp), %rax
movq -0x128(%rbp), %rcx
movq %rdx, 0x38(%rcx)
movq 0x38(%rbp), %rcx
movslq -0x90(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rcx
movq %rcx, -0x138(%rbp)
movq -0x138(%rbp), %rcx
movl 0x1c(%rcx), %ecx
movl %ecx, -0x13c(%rbp)
movl -0x8c(%rbp), %edx
movq -0x138(%rbp), %rcx
movl %edx, 0x40(%rcx)
movl -0x12c(%rbp), %ecx
addl -0x11c(%rbp), %ecx
movl %ecx, -0x11c(%rbp)
movl -0x13c(%rbp), %ecx
addl -0x120(%rbp), %ecx
movl %ecx, -0x120(%rbp)
movslq -0x8c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x148(%rbp)
leaq 0x642a3(%rip), %rdi     # 0x7b3f9
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jge 0x171aa
movq -0x128(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x94(%rbp), %rcx
movsbl (%rax,%rcx), %esi
leaq 0x6baa4(%rip), %rdi     # 0x82c36
movb $0x0, %al
callq 0x10d0
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x17167
leaq 0x64254(%rip), %rdi     # 0x7b405
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jge 0x17236
movq -0x148(%rbp), %rax
movslq -0x94(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x17215
movq -0x138(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x148(%rbp), %rcx
movslq -0x94(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsbl (%rax,%rcx), %esi
leaq 0x6ba2a(%rip), %rdi     # 0x82c36
movb $0x0, %al
callq 0x10d0
jmp 0x17223
leaq 0x646e1(%rip), %rdi     # 0x7b8fd
movb $0x0, %al
callq 0x10d0
jmp 0x17225
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x171c2
leaq 0x66e3b(%rip), %rdi     # 0x7e078
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x14c(%rbp)
movl $0x0, -0x150(%rbp)
movl $0x1, -0x154(%rbp)
leaq 0x641a9(%rip), %rdi     # 0x7b412
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl -0x12c(%rbp), %eax
jge 0x17438
movq -0x148(%rbp), %rax
movslq -0x94(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x173ca
cmpl $0x0, -0x154(%rbp)
je 0x172b7
movl $0x0, -0x154(%rbp)
movq -0x128(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x94(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x138(%rbp), %rcx
movq 0x50(%rcx), %rcx
movq -0x148(%rbp), %rdx
movslq -0x94(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x17303
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x17373
movl -0x94(%rbp), %edx
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x128(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x94(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movb %dl, (%rax,%rcx)
movq -0x138(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x148(%rbp), %rcx
movslq -0x94(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movb (%rax,%rcx), %dl
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq (%rcx), %rcx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x148(%rbp), %rax
movslq -0x94(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x128(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x94(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x138(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x148(%rbp), %rcx
movslq -0x94(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsbl (%rax,%rcx), %esi
leaq 0x6b875(%rip), %rdi     # 0x82c36
movb $0x0, %al
callq 0x10d0
jmp 0x17422
movq -0x128(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x94(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
leaq 0x64513(%rip), %rdi     # 0x7b8fd
movb $0x0, %al
callq 0x10d0
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
cmpl $0x0, -0x154(%rbp)
jne 0x17420
movq -0x38(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movl $0x1, -0x154(%rbp)
jmp 0x17422
jmp 0x17424
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x1727a
leaq 0x66c39(%rip), %rdi     # 0x7e078
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0x154(%rbp)
je 0x1745c
movq -0x38(%rbp), %rax
movl 0x10(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x10(%rax)
cvtsi2ssl -0x14c(%rbp), %xmm0
movq -0x38(%rbp), %rax
addss (%rax), %xmm0
movss %xmm0, (%rax)
movl -0x12c(%rbp), %eax
subl -0x150(%rbp), %eax
movl %eax, -0x158(%rbp)
cvtsi2ssl -0x158(%rbp), %xmm0
movq -0x38(%rbp), %rax
addss 0x4(%rax), %xmm0
movss %xmm0, 0x4(%rax)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x17030
movq -0x18(%rbp), %rax
movl (%rax), %esi
leaq 0x63f65(%rip), %rdi     # 0x7b41e
movb $0x0, %al
callq 0x10d0
movl $0x3e8, -0x15c(%rbp)    # imm = 0x3E8
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1754d
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl -0x15c(%rbp), %eax
jne 0x174f2
jmp 0x1754d
movq -0x20(%rbp), %rax
movslq -0x94(%rbp), %rcx
movsbl (%rax,%rcx), %esi
movq 0x28(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x94(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
shlq $0x5, %rax
addq %rax, %rdx
addq $0xd, %rdx
movq -0x30(%rbp), %rax
movslq -0x94(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
leaq 0x63ef8(%rip), %rdi     # 0x7b42d
movb $0x0, %al
callq 0x10d0
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x174d4
leaq 0x66b24(%rip), %rdi     # 0x7e078
movb $0x0, %al
callq 0x10d0
movq -0x38(%rbp), %rax
movss 0x4(%rax), %xmm1
movq -0x38(%rbp), %rax
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movq -0x38(%rbp), %rax
movss 0x5eb30(%rip), %xmm0    # 0x760b0
mulss (%rax), %xmm0
movss %xmm0, (%rax)
cvtsi2ssl -0x11c(%rbp), %xmm0
cvtsi2ssl -0x120(%rbp), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x160(%rbp)
movss -0x160(%rbp), %xmm1
movq -0x38(%rbp), %rax
movss 0x8(%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, 0x8(%rax)
cvtsi2ssl -0x11c(%rbp), %xmm1
movq -0x38(%rbp), %rax
movss 0x4(%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, 0x4(%rax)
movslq -0x11c(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movl $0x0, -0x94(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x17720
movq 0x18(%rbp), %rax
movslq -0x8c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x16c(%rbp)
movq 0x38(%rbp), %rax
movq -0x168(%rbp), %rcx
movslq 0x40(%rcx), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x174(%rbp)
movl $0x0, -0x170(%rbp)
movl -0x170(%rbp), %eax
cmpl -0x16c(%rbp), %eax
jge 0x1770a
movq -0x168(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x170(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x176d1
movq -0x168(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x170(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl -0x174(%rbp), %edx
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x94(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x176e7
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x94(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x17678
jmp 0x1770c
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x17614
movl -0x11c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x94(%rbp)
jl 0x17771
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x94(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jl 0x1775e
movl -0x94(%rbp), %ecx
addl $0x1, %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
jmp 0x17771
jmp 0x17760
movl -0x94(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x1772f
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0x17842
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
cmpl 0x40(%rbp), %eax
jge 0x177d2
movq -0x1b8(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x94(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1040
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x17794
movq -0x1b8(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1040
movq -0x1b0(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1040
movq -0x188(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1040
movq -0x180(%rbp), %rax
movslq -0x8c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1040
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1777b
movq -0x68(%rbp), %rax
movq %rax, %rsp
xorl %eax, %eax
leaq -0x10(%rbp), %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)