// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r9, -0x110(%rbp)
movq %rcx, -0x100(%rbp)
movq %rdx, -0xf8(%rbp)
movq %rsi, -0xf0(%rbp)
movq %rdi, -0x90(%rbp)
movl 0x40(%rbp), %r15d
movl 0x20(%rbp), %r12d
movq 0x10(%rbp), %rax
movl %r12d, (%rax)
cmpl %r12d, %r15d
jl 0x110c4
movq 0x38(%rbp), %r14
andl $0x0, 0x20(%r8)
andl $0x0, 0x10(%r8)
movq 0x18(%rbp), %rdi
movq %r8, -0x88(%rbp)
andq $0x0, (%r8)
movl %r12d, %esi
callq 0x11109
movl %eax, -0x50(%rbp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x11109
movl %eax, %ebx
movl %r12d, %ecx
movq %rsp, %rdx
leaq 0xf(,%rcx,8), %rax
andq $-0x10, %rax
subq %rax, %rdx
movq %rdx, -0x98(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0xc8(%rbp)
movq %rdx, %rsp
movl %r15d, %edx
movq %rdx, -0xb8(%rbp)
imulq %rcx, %rdx
leaq 0xf(,%rdx,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rsi
subq %rdx, %rsi
movq %rsi, -0xe0(%rbp)
movq %rsi, %rsp
movq %rsp, %rdx
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %rdx
movq %rdx, -0xc0(%rbp)
movq %rdx, %rsp
movq %rsp, %r10
subq %rcx, %r10
movq %r10, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x80(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x60(%rbp)
movq %rcx, %rsp
movslq %r15d, %r14
leaq (,%r14,8), %r15
shlq $0x2, %r14
movl %r12d, %ecx
movslq %r12d, %r12
shlq $0x2, %r12
xorl %r13d, %r13d
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movq %rax, -0x68(%rbp)
movq %r10, -0x58(%rbp)
cmpq %r13, -0x68(%rbp)
je 0x1066b
movq %r15, %rdi
callq 0x21d0
movq -0x98(%rbp), %rcx
movq %rax, (%rcx,%r13,8)
movq %r14, %rdi
callq 0x21d0
movq -0xc8(%rbp), %rcx
movq %rax, (%rcx,%r13,8)
movq %r12, %rdi
callq 0x21d0
movq -0x80(%rbp), %rcx
movq %rax, (%rcx,%r13,8)
movq %r14, %rdi
callq 0x21d0
movq -0x58(%rbp), %r10
movq -0x60(%rbp), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
jmp 0x10616
movq %rsp, %r11
movq -0xb8(%rbp), %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r11
movq %r11, %rsp
xorl %eax, %eax
movq -0x60(%rbp), %r13
movq 0x18(%rbp), %rsi
movq -0xc0(%rbp), %rcx
cmpq %rax, -0x68(%rbp)
je 0x106ac
andl $0x0, (%rcx,%rax,4)
andl $0x0, (%r10,%rax,4)
incq %rax
jmp 0x10698
xorl %eax, %eax
movl 0x40(%rbp), %edx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
movq %rcx, -0xa8(%rbp)
cmpq %rax, -0xa8(%rbp)
je 0x106d5
orl $-0x1, (%r11,%rax,4)
incq %rax
jmp 0x106c2
addl -0x50(%rbp), %ebx
shlq $0x2, %rbx
movq %rbx, -0x128(%rbp)
movq -0xb8(%rbp), %rax
leaq (,%rax,4), %rax
movq %rax, -0x118(%rbp)
movq -0xe0(%rbp), %r8
xorl %r15d, %r15d
xorl %ebx, %ebx
movq %r11, -0x120(%rbp)
cmpq -0x68(%rbp), %r15
je 0x10b37
movq %r8, -0xe8(%rbp)
movl %ebx, -0xd4(%rbp)
imulq $0x70, %r15, %rax
movl 0x1c(%rsi,%rax), %edx
orl $-0x1, 0x40(%rsi,%rax)
addq %rax, %rsi
movq %r15, %rax
imulq -0xb8(%rbp), %rax
movq -0xe0(%rbp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, -0xb0(%rbp)
xorl %r12d, %r12d
testl %edx, %edx
movl $0x0, %eax
movl %edx, -0x74(%rbp)
cmovgl %edx, %eax
movq %rax, -0x108(%rbp)
pushq $-0x1
popq %rbx
xorl %r14d, %r14d
movq %r15, -0xa0(%rbp)
movq %rsi, -0x38(%rbp)
cmpq -0xa8(%rbp), %r12
je 0x10a2d
movl %ebx, -0xd8(%rbp)
movl %r14d, -0x2c(%rbp)
imulq $0x70, %r12, %rax
movq 0x38(%rbp), %rcx
leaq (%rcx,%rax), %r10
movslq 0x1c(%rcx,%rax), %r14
movsbl 0x34(%rsi), %edx
movsbl 0x34(%rcx,%rax), %r9d
subq $0x8, %rsp
leaq 0x3f94e(%rip), %rdi     # 0x50103
movl %r15d, %esi
movl -0x74(%rbp), %r15d
movl %r15d, %ecx
movq %r12, -0x70(%rbp)
movl %r12d, %r8d
movq %r10, %r12
xorl %eax, %eax
pushq %r14
callq 0x20f0
movq -0x38(%rbp), %rcx
addq $0x10, %rsp
movq %rsp, -0x130(%rbp)
movl 0x60(%rcx), %eax
addl %eax, %eax
movq %rsp, %r13
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
leaq 0x54609(%rip), %rax     # 0x64e10
cmpl (%rax), %r15d
movq %r12, -0xd0(%rbp)
jle 0x1084c
movq 0x58(%rcx), %rdi
movl 0x60(%rcx), %esi
movq 0x58(%r12), %rdx
movl 0x60(%r12), %ecx
xorl %r8d, %r8d
pushq $0x1
popq %r9
leaq -0x78(%rbp), %rax
pushq %rax
pushq %rbx
pushq %r13
pushq $0x7
callq 0x46f0c
addq $0x20, %rsp
testl %eax, %eax
je 0x11079
movl -0x78(%rbp), %r15d
jmp 0x10893
leaq 0x3fbcf(%rip), %rdi     # 0x50422
callq 0x2090
movq -0x38(%rbp), %rdx
movl %r15d, -0x78(%rbp)
xorl %eax, %eax
movq -0x108(%rbp), %rsi
movq %r12, %rdi
cmpq %rax, %rsi
je 0x10893
movq 0x50(%rdx), %rcx
movb (%rcx,%rax), %cl
movb %cl, (%r13,%rax)
movb $0x2d, %cl
cmpq %r14, %rax
jge 0x1088b
movq 0x50(%rdi), %rcx
movb (%rcx,%rax), %cl
movb %cl, (%rbx,%rax)
incq %rax
jmp 0x1086c
movq -0x128(%rbp), %rdi
callq 0x21d0
movq -0x98(%rbp), %rcx
movq -0xa0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x70(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
movq -0xb0(%rbp), %rcx
andl $0x0, (%rcx,%rdx,4)
xorl %ecx, %ecx
movq -0x108(%rbp), %rdx
cmpq %rcx, %rdx
je 0x108db
orl $-0x1, (%rax,%rcx,4)
incq %rcx
jmp 0x108cd
xorl %edx, %edx
testl %r15d, %r15d
movl $0x0, %ecx
movq %rcx, -0x40(%rbp)
cmovlel %edx, %r15d
xorl %ecx, %ecx
movq $0x0, -0x50(%rbp)
xorl %edi, %edi
xorl %edx, %edx
cmpq %rcx, %r15
je 0x109d6
movb $0x2d, %r9b
cmpb $0x2d, (%r13,%rcx)
jne 0x1091b
xorl %r11d, %r11d
movb $0x2d, %r10b
pushq $-0x1
popq %r8
jmp 0x1094c
movq -0x38(%rbp), %r10
movq 0x68(%r10), %r8
movq -0x50(%rbp), %rsi
movslq %esi, %rsi
movslq (%r8,%rsi,4), %r8
incl %esi
movq %rsi, -0x50(%rbp)
testq %r8, %r8
js 0x10946
movq 0x50(%r10), %r10
movb (%r10,%r8), %r10b
movb $0x1, %r11b
jmp 0x1094c
xorl %r11d, %r11d
movb $0x2d, %r10b
movl %edx, %r14d
movb %r10b, (%r13,%r14)
cmpb $0x2d, (%rbx,%rcx)
jne 0x10960
pushq $-0x1
popq %r12
jmp 0x10993
movq %rbx, %rsi
movq %r13, %rbx
movq %r15, %r13
movq -0xd0(%rbp), %r15
movq 0x68(%r15), %r12
movslq %edi, %rdi
movslq (%r12,%rdi,4), %r12
incl %edi
testq %r12, %r12
js 0x1098a
movq 0x50(%r15), %r9
movb (%r9,%r12), %r9b
movq %r13, %r15
movq %rbx, %r13
movq %rsi, %rbx
movb %r9b, (%rbx,%r14)
testb %r11b, %r11b
je 0x109c1
movl %r8d, %r11d
movl %r12d, (%rax,%r11,4)
cmpb %r9b, %r10b
jne 0x109c1
movq -0x40(%rbp), %rsi
incl %esi
movq -0xb0(%rbp), %r9
movq -0x70(%rbp), %r10
movq %rsi, -0x40(%rbp)
movl %esi, (%r9,%r10,4)
andl %r8d, %r12d
notl %r12d
shrl $0x1f, %r12d
addl %r12d, %edx
incq %rcx
jmp 0x108fb
movq -0xc8(%rbp), %rax
movq -0xa0(%rbp), %r15
movq (%rax,%r15,8), %rax
movq -0x70(%rbp), %r12
movl %edx, (%rax,%r12,4)
leaq 0x3f743(%rip), %rdi     # 0x5013a
movq -0x40(%rbp), %r13
movl %r13d, %esi
xorl %eax, %eax
callq 0x20f0
movl -0x2c(%rbp), %r14d
cmpl %r14d, %r13d
movl -0xd8(%rbp), %ebx
cmovgl %r12d, %ebx
cmovgl %r13d, %r14d
movq -0x130(%rbp), %rsp
incq %r12
movq -0x38(%rbp), %rsi
jmp 0x10778
movl 0x1c(%rsi), %edx
leaq 0x3f723(%rip), %rdi     # 0x5015a
movl %r15d, %esi
movl %r14d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x20f0
testl %ebx, %ebx
js 0x1108d
movl %ebx, %ebx
imulq $0x70, %rbx, %rax
movq 0x38(%rbp), %rcx
movl 0x1c(%rcx,%rax), %esi
leaq 0x40e20(%rip), %rdi     # 0x51884
xorl %eax, %eax
callq 0x20f0
testl %r14d, %r14d
jne 0x10a82
leaq 0x54399(%rip), %rax     # 0x64e10
movl -0x74(%rbp), %ecx
cmpl (%rax), %ecx
jg 0x1108d
movq -0x120(%rbp), %r11
movl (%r11,%rbx,4), %eax
testl %eax, %eax
movl %eax, %ecx
movl -0xd4(%rbp), %ebx
cmovsl %ebx, %ecx
shrl $0x1f, %eax
testl %r14d, %r14d
cvtsi2ss %r14d, %xmm0
addss 0x3f617(%rip), %xmm0    # 0x500c4
cvttss2si %xmm0, %edx
cmovel %r14d, %edx
movslq %ecx, %rsi
movq -0x80(%rbp), %rdi
movq (%rdi,%rsi,8), %rdi
movq -0xc0(%rbp), %r9
movslq (%r9,%rsi,4), %r8
movl %r15d, (%rdi,%r8,4)
leal 0x1(%r8), %edi
movl %edi, (%r9,%rsi,4)
xorl %edi, %edi
movq -0x60(%rbp), %r13
movq -0x58(%rbp), %r10
movq -0xe8(%rbp), %r8
cmpq %rdi, -0xa8(%rbp)
je 0x10b22
cmpl %edx, (%r8,%rdi,4)
jl 0x10b1d
cmpl %ecx, (%r11,%rdi,4)
je 0x10b1d
movl %ecx, (%r11,%rdi,4)
movq (%r13,%rsi,8), %r8
movslq (%r10,%rsi,4), %r9
movl %edi, (%r8,%r9,4)
leal 0x1(%r9), %r8d
movl %r8d, (%r10,%rsi,4)
movq -0xe8(%rbp), %r8
incq %rdi
jmp 0x10ae8
addl %eax, %ebx
incq %r15
addq -0x118(%rbp), %r8
movq 0x18(%rbp), %rsi
jmp 0x1070c
testl %ebx, %ebx
je 0x110fd
movl %ebx, %eax
movq %rax, -0x50(%rbp)
xorl %ebx, %ebx
cmpq -0x50(%rbp), %rbx
je 0x10c38
movq -0x80(%rbp), %rax
movq (%rax,%rbx,8), %r12
movq -0xc0(%rbp), %rax
movl (%rax,%rbx,4), %r15d
movq (%r13,%rbx,8), %r13
movl (%r10,%rbx,4), %r14d
cmpl %r14d, %r15d
je 0x10b90
leaq 0x3f7e2(%rip), %rdi     # 0x5035b
movl %r15d, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x20f0
cmpl $0x1, %r15d
jne 0x110bb
movq %r12, %rdi
movl %r15d, %esi
movl 0x20(%rbp), %edx
pushq $0x1
popq %rcx
callq 0x1185a
movq %r13, %rdi
movl %r14d, %esi
movl 0x40(%rbp), %edx
pushq $0x2
popq %rcx
callq 0x1185a
cmpl $0x1, %r15d
jne 0x10bbe
movq 0x18(%rbp), %rsi
jmp 0x10beb
cmpl $0x2, %r14d
movq 0x18(%rbp), %rsi
jne 0x10c0b
cmpl $0x2, %r15d
jne 0x10c0b
cmpl $0x0, 0x52c4b(%rip)     # 0x63820
je 0x10c0b
movl 0x4(%r13), %eax
movslq (%r12), %rcx
imulq $0x70, %rcx, %rcx
movl %eax, 0x40(%rsi,%rcx)
addq $0x4, %r12
movq -0x58(%rbp), %r10
movl (%r13), %eax
movslq (%r12), %rcx
imulq $0x70, %rcx, %rcx
movl %eax, 0x40(%rsi,%rcx)
incq %rbx
movq -0x60(%rbp), %r13
jmp 0x10b47
testl %r15d, %r15d
movl $0x0, %eax
cmovlel %eax, %r15d
xorl %eax, %eax
movq -0x58(%rbp), %r10
cmpq %rax, %r15
je 0x10bff
movl (%r13,%rax,4), %ecx
movslq (%r12,%rax,4), %rdx
imulq $0x70, %rdx, %rdx
movl %ecx, 0x40(%rsi,%rdx)
incq %rax
jmp 0x10c1d
movq -0x90(%rbp), %rax
andl $0x0, (%rax)
xorl %r14d, %r14d
xorl %r12d, %r12d
movl $0x0, -0x2c(%rbp)
cmpq -0x68(%rbp), %r14
je 0x10e78
imulq $0x70, %r14, %rax
leaq (%rsi,%rax), %r13
movslq 0x1c(%rsi,%rax), %r15
movslq 0x40(%rsi,%rax), %rbx
testq %rbx, %rbx
js 0x110a0
leaq (,%r15,4), %rdi
callq 0x21d0
movq %rax, 0x38(%r13)
imulq $0x70, %rbx, %rax
movq 0x38(%rbp), %rcx
leaq (%rcx,%rax), %rdx
movq %rdx, -0x50(%rbp)
movl 0x1c(%rcx,%rax), %edx
movl %edx, -0xa0(%rbp)
movl %r14d, 0x40(%rcx,%rax)
addl %r15d, -0x2c(%rbp)
movq -0x98(%rbp), %rax
movq %r14, -0x70(%rbp)
movq (%rax,%r14,8), %rax
movq (%rax,%rbx,8), %r14
leaq 0x3f523(%rip), %rdi     # 0x501e5
xorl %eax, %eax
callq 0x20f0
testl %r15d, %r15d
movq %r15, %rax
movl $0x0, %r15d
movq %rax, -0xb0(%rbp)
cmovgl %eax, %r15d
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x10cf9
movq 0x50(%r13), %rax
movsbl (%rax,%rbx), %edi
callq 0x2060
incq %rbx
jmp 0x10ce2
leaq 0x3f4f1(%rip), %rdi     # 0x501f1
xorl %eax, %eax
callq 0x20f0
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x10d30
movslq (%r14,%rbx,4), %rax
pushq $0x2d
popq %rdi
testq %rax, %rax
js 0x10d26
movq -0x50(%rbp), %rcx
movq 0x50(%rcx), %rcx
movsbl (%rcx,%rax), %edi
callq 0x2060
incq %rbx
jmp 0x10d09
movl %r12d, -0xd0(%rbp)
pushq $0xa
popq %rdi
callq 0x2060
xorl %r12d, %r12d
leaq 0x3f4b5(%rip), %rdi     # 0x501fe
xorl %eax, %eax
callq 0x20f0
movl $0x0, -0x40(%rbp)
movl $0x0, -0x38(%rbp)
pushq $0x1
popq %rbx
cmpq %r12, %r15
je 0x10e1c
movslq (%r14,%r12,4), %rax
testq %rax, %rax
js 0x10d8e
movq 0x50(%r13), %rdx
movb (%rdx,%r12), %sil
movq -0x50(%rbp), %rdi
movq 0x50(%rdi), %rcx
cmpb (%rcx,%rax), %sil
jne 0x10db5
incl -0x40(%rbp)
jmp 0x10dfd
movq 0x38(%r13), %rax
orl $-0x1, (%rax,%r12,4)
pushq $0x2d
popq %rdi
callq 0x2060
incl -0x38(%rbp)
testl %ebx, %ebx
jne 0x10db0
movq -0x88(%rbp), %rax
incl 0x10(%rax)
pushq $0x1
popq %rbx
jmp 0x10e14
movq -0x90(%rbp), %rsi
movslq (%rsi), %rax
movq -0xf8(%rbp), %rcx
movl %r12d, (%rcx,%rax,4)
movb (%rdx,%r12), %al
movslq (%rsi), %rcx
movq -0xf0(%rbp), %rdx
movb %al, (%rdx,%rcx)
movq 0x50(%rdi), %rax
movslq (%r14,%r12,4), %rcx
movb (%rax,%rcx), %al
movslq (%rsi), %rcx
movq -0x100(%rbp), %rdx
movb %al, (%rdx,%rcx)
incl (%rsi)
movl (%r14,%r12,4), %eax
movq 0x50(%rdi), %rcx
movq 0x38(%r13), %rdx
movl %eax, (%rdx,%r12,4)
movslq (%r14,%r12,4), %rax
movsbl (%rcx,%rax), %edi
callq 0x2060
xorl %ebx, %ebx
incq %r12
jmp 0x10d61
pushq $0xa
popq %rdi
callq 0x2060
testl %ebx, %ebx
movq -0x88(%rbp), %rax
je 0x10e32
decl 0x10(%rax)
movl -0xd0(%rbp), %r12d
addl -0xa0(%rbp), %r12d
movq -0xb0(%rbp), %rcx
subl -0x38(%rbp), %ecx
movd %ecx, %xmm0
movd -0x40(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2ps %xmm1, %xmm0
movsd (%rax), %xmm1
addps %xmm0, %xmm1
movlps %xmm1, (%rax)
movq -0x70(%rbp), %r14
incq %r14
movq -0x60(%rbp), %r13
movq 0x18(%rbp), %rsi
jmp 0x10c4f
movq -0x90(%rbp), %rax
movl (%rax), %esi
leaq 0x3f382(%rip), %rdi     # 0x5020a
xorl %eax, %eax
callq 0x20f0
leaq 0x3f383(%rip), %rbx     # 0x50219
xorl %r14d, %r14d
movq -0x90(%rbp), %rax
movslq (%rax), %rax
cmpq %rax, %r14
jge 0x10ef1
cmpl $0x3e8, %eax            # imm = 0x3E8
je 0x10ef1
movq -0xf0(%rbp), %rax
movsbl (%rax,%r14), %esi
movq -0xf8(%rbp), %rax
movslq (%rax,%r14,4), %rax
shlq $0x5, %rax
movq 0x28(%rbp), %rcx
leaq (%rcx,%rax), %rdx
addq $0xd, %rdx
movq -0x100(%rbp), %rax
movsbl (%rax,%r14), %ecx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x20f0
incq %r14
jmp 0x10e99
pushq $0xa
popq %rdi
callq 0x2060
movq -0x88(%rbp), %rax
movss (%rax), %xmm0
divss 0x4(%rax), %xmm0
mulss 0x3a103(%rip), %xmm0    # 0x4b014
movl -0x2c(%rbp), %ecx
cvtsi2ss %ecx, %xmm2
movss %xmm0, (%rax)
cvtsi2ss %r12d, %xmm0
mulss %xmm2, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x10f33
sqrtss %xmm0, %xmm0
jmp 0x10f43
movaps %xmm2, -0x50(%rbp)
callq 0x21c0
movaps -0x50(%rbp), %xmm2
movl -0x2c(%rbp), %ecx
movq -0x88(%rbp), %rbx
movsd 0x4(%rbx), %xmm1
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
divps %xmm2, %xmm1
movlps %xmm1, 0x4(%rbx)
movslq %ecx, %rdi
shlq $0x2, %rdi
callq 0x21d0
movq %rax, 0x18(%rbx)
movq 0x10(%rbp), %rcx
movl (%rcx), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
pushq $-0x1
popq %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rcx, %rdi
je 0x10fdf
imulq $0x70, %rdi, %r11
movq 0x18(%rbp), %rbx
leaq (%rbx,%r11), %r9
movl 0x1c(%rbx,%r11), %r10d
movslq 0x40(%rbx,%r11), %r11
imulq $0x70, %r11, %r11
movq 0x38(%rbp), %rbx
movl 0x18(%rbx,%r11), %r11d
movslq %r8d, %r8
testl %r10d, %r10d
cmovlel %edx, %r10d
leaq (%rax,%r8,4), %r14
xorl %ebx, %ebx
cmpq %rbx, %r10
je 0x10fd7
movq 0x38(%r9), %r15
movl (%r15,%rbx,4), %r15d
leal (%r15,%r11), %r12d
testl %r15d, %r15d
cmovsl %esi, %r12d
movl %r12d, (%r14,%rbx,4)
incq %rbx
jmp 0x10fb6
incq %rdi
addq %rbx, %r8
jmp 0x10f7e
movl -0x2c(%rbp), %edx
movl %edx, %ecx
leaq (%rax,%rcx,4), %rax
addq $-0x4, %rax
testl %edx, %edx
jle 0x11006
decl %edx
cmpl $0x0, (%rax)
leaq -0x4(%rax), %rax
js 0x10fec
incl %edx
movq -0x110(%rbp), %rax
movl %edx, (%rax)
xorl %r14d, %r14d
cmpq -0x68(%rbp), %r14
je 0x11068
movq -0x98(%rbp), %rax
movq (%rax,%r14,8), %rbx
xorl %r15d, %r15d
cmpq %r15, -0xa8(%rbp)
je 0x11034
movq (%rbx,%r15,8), %rdi
callq 0x2050
incq %r15
jmp 0x1101d
movq %rbx, %rdi
callq 0x2050
movq -0xc8(%rbp), %rax
movq (%rax,%r14,8), %rdi
callq 0x2050
movq -0x80(%rbp), %rax
movq (%rax,%r14,8), %rdi
callq 0x2050
movq (%r13,%r14,8), %rdi
callq 0x2050
incq %r14
jmp 0x11009
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3f38a(%rip), %rdi     # 0x5040a
callq 0x2090
pushq $0x8
popq %rdi
callq 0x2270
leaq 0x3f0f3(%rip), %rdi     # 0x50187
movl %r15d, %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x11085
movsbl 0x34(%r13), %edx
leaq 0x3f106(%rip), %rdi     # 0x501b2
movl %r14d, %esi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x20f0
jmp 0x11085
leaq 0x3ef59(%rip), %rdi     # 0x5001b
jmp 0x11080
movq 0x50(%rbp), %rbx
movq 0x30(%rbp), %r14
leaq 0x3eff5(%rip), %rdi     # 0x500c8
xorl %eax, %eax
callq 0x20f0
leaq 0x3f00d(%rip), %rdi     # 0x500ee
movl %r12d, %esi
movq %r14, %rdx
movl %r15d, %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x20f0
leaq 0x3e072(%rip), %rdi     # 0x4f16d
jmp 0x11080
leaq 0x3f2db(%rip), %rdi     # 0x503df
jmp 0x11080