// File: /workspace/github_c_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
movq %r9, -0x118(%rbp)
movq %rcx, -0x100(%rbp)
movq %rdx, -0xf8(%rbp)
movq %rsi, -0xf0(%rbp)
movl 0x40(%rbp), %ecx
movl 0x20(%rbp), %r15d
movq 0x10(%rbp), %rax
movl %r15d, (%rax)
cmpl %r15d, %ecx
jl 0x11d72
movq 0x18(%rbp), %r10
xorl %r12d, %r12d
movl %r12d, 0x20(%r8)
movl %r12d, 0x10(%r8)
movq $0x0, (%r8)
movl %r15d, %esi
movl $0x0, %r13d
testl %r15d, %r15d
jle 0x110a1
imulq $0x70, %rsi, %rax
xorl %ecx, %ecx
xorl %r13d, %r13d
movl 0x1c(%r10,%rcx), %edx
cmpl %r13d, %edx
cmovgl %edx, %r13d
addq $0x70, %rcx
cmpq %rcx, %rax
jne 0x1108c
movq %rdi, -0xa8(%rbp)
movq %r8, -0x88(%rbp)
movq 0x38(%rbp), %r15
movl 0x40(%rbp), %eax
movq %rax, %rcx
movl %ecx, %eax
movq %rax, -0x50(%rbp)
testl %ecx, %ecx
jle 0x110e2
imulq $0x70, -0x50(%rbp), %rax
xorl %ecx, %ecx
xorl %r12d, %r12d
movl 0x1c(%r15,%rcx), %edx
cmpl %r12d, %edx
cmovgl %edx, %r12d
addq $0x70, %rcx
cmpq %rcx, %rax
jne 0x110cd
movq %rsp, %rcx
leaq 0xf(,%rsi,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xb0(%rbp)
movq %rcx, %rsp
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movq -0x50(%rbp), %rdx
movq %rdx, %rcx
imulq %rsi, %rcx
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0xe8(%rbp)
movq %rdi, %rsp
movq %rsp, %rdi
leaq 0xf(,%rsi,4), %rcx
andq $-0x10, %rcx
subq %rcx, %rdi
movq %rdi, -0xd0(%rbp)
movq %rdi, %rsp
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0xc8(%rbp)
movq %rdi, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xa0(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
cmpl $0x0, 0x20(%rbp)
movq %rsi, -0x98(%rbp)
movq %rbx, -0xd8(%rbp)
jle 0x11263
movl 0x40(%rbp), %eax
movslq %eax, %r14
leaq (,%r14,8), %rax
movq %rax, -0x48(%rbp)
shlq $0x2, %r14
leaq (,%rsi,4), %rax
movq %rax, -0x40(%rbp)
xorl %ebx, %ebx
movq -0x90(%rbp), %r15
movq -0x48(%rbp), %rdi
callq 0x21e0
movq -0xb0(%rbp), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r14, %rdi
callq 0x21e0
movq -0xd8(%rbp), %rcx
movq %rax, (%rcx,%rbx,8)
movq -0x40(%rbp), %rdi
callq 0x21e0
movq -0xa0(%rbp), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r14, %rdi
callq 0x21e0
movq %rax, (%r15,%rbx,8)
incq %rbx
cmpq %rbx, -0x98(%rbp)
jne 0x111bd
movq -0x40(%rbp), %r14
movq %rsp, %rcx
movq -0x50(%rbp), %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
cmpl $0x0, 0x20(%rbp)
jle 0x11259
movq -0xd0(%rbp), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x2110
movq -0xc8(%rbp), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x2110
movq 0x18(%rbp), %r10
movq 0x38(%rbp), %r15
jmp 0x1127c
movq %rsp, %rcx
leaq 0xf(,%rdx,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
movl 0x40(%rbp), %eax
testl %eax, %eax
jle 0x112a1
movq -0x50(%rbp), %rax
leaq (,%rax,4), %rdx
movq -0x78(%rbp), %rdi
movl $0xff, %esi
callq 0x2110
movq 0x18(%rbp), %r10
cmpl $0x0, 0x20(%rbp)
jle 0x11d69
addl %r13d, %r12d
movl %r12d, %eax
shlq $0x2, %rax
movq %rax, -0x130(%rbp)
movq -0x50(%rbp), %r14
leaq (,%r14,4), %rax
movq %rax, -0x120(%rbp)
movq -0xe8(%rbp), %r8
xorl %esi, %esi
movl $0x0, -0x64(%rbp)
movq %r8, -0x108(%rbp)
imulq $0x70, %rsi, %rax
leaq (%r10,%rax), %r13
movl 0x1c(%r10,%rax), %edx
movl $0xffffffff, 0x40(%r10,%rax) # imm = 0xFFFFFFFF
movq %rsi, %rax
imulq %r14, %rax
movq -0xe8(%rbp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, -0xb8(%rbp)
movq %rdx, -0x110(%rbp)
leaq (,%rdx,4), %rax
movq %rax, -0x128(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
xorl %r12d, %r12d
movq %r13, -0x70(%rbp)
movq %rsi, -0x58(%rbp)
movl %eax, -0xdc(%rbp)
movl %r12d, -0xe0(%rbp)
imulq $0x70, %r8, %rax
leaq (%r15,%rax), %rcx
movq %rcx, -0x40(%rbp)
movslq 0x1c(%r15,%rax), %rbx
movsbl 0x34(%r13), %edx
movsbl 0x34(%r15,%rax), %r9d
subq $0x8, %rsp
leaq 0x44e59(%rip), %rdi     # 0x561cb
movq -0x110(%rbp), %r12
movl %r12d, %ecx
movq %r8, -0x60(%rbp)
xorl %eax, %eax
pushq %rbx
callq 0x20f0
addq $0x10, %rsp
movq %rsp, -0x138(%rbp)
movl 0x60(%r13), %eax
addl %eax, %eax
movq %rsp, %r14
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
leaq 0x58a56(%rip), %rax     # 0x69e10
cmpl (%rax), %r12d
movq -0x40(%rbp), %rax
jle 0x113fd
movq 0x58(%r13), %rdi
movl 0x60(%r13), %esi
movq 0x58(%rax), %rdx
movl 0x60(%rax), %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
leaq -0x7c(%rbp), %rax
pushq %rax
pushq %r15
pushq %r14
pushq $0x7
callq 0x4d315
addq $0x20, %rsp
testl %eax, %eax
je 0x11d1b
movl -0x7c(%rbp), %r13d
jmp 0x11447
leaq 0x450e6(%rip), %rdi     # 0x564ea
callq 0x2090
movl %r12d, -0x7c(%rbp)
movl %r12d, %r13d
testl %r12d, %r12d
jle 0x11447
movq -0x70(%rbp), %rax
movq 0x50(%rax), %rax
xorl %ecx, %ecx
movq -0x40(%rbp), %rsi
movb (%rax,%rcx), %dl
movb %dl, (%r14,%rcx)
movb $0x2d, %dl
cmpq %rbx, %rcx
jge 0x11438
movq 0x50(%rsi), %rdx
movb (%rdx,%rcx), %dl
movb %dl, (%r15,%rcx)
incq %rcx
cmpq %rcx, %r12
jne 0x11423
movl %r12d, %r13d
movq -0x130(%rbp), %rdi
callq 0x21e0
movq %rax, %rbx
movq -0xb0(%rbp), %rax
movq -0x58(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq -0x60(%rbp), %rcx
movq %rbx, (%rax,%rcx,8)
movq -0xb8(%rbp), %rax
movl $0x0, (%rax,%rcx,4)
testl %r12d, %r12d
jle 0x11494
movq %rbx, %rdi
movl $0xff, %esi
movq -0x128(%rbp), %rdx
callq 0x2110
testl %r13d, %r13d
jle 0x11576
movq %rbx, -0xc0(%rbp)
movl %r13d, %eax
movq $0x0, -0x48(%rbp)
xorl %ecx, %ecx
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movb $0x2d, %r10b
cmpb $0x2d, (%r14,%rcx)
jne 0x114d4
xorl %ebx, %ebx
movb $0x2d, %r11b
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
jmp 0x114fb
movq -0x70(%rbp), %r11
movq 0x68(%r11), %r9
movslq %edi, %rdi
movslq (%r9,%rdi,4), %r9
incl %edi
testq %r9, %r9
js 0x114f6
movq 0x50(%r11), %r11
movb (%r11,%r9), %r11b
movb $0x1, %bl
jmp 0x114fb
xorl %ebx, %ebx
movb $0x2d, %r11b
movl %edx, %r12d
movb %r11b, (%r14,%r12)
cmpb $0x2d, (%r15,%rcx)
je 0x11527
movq -0x40(%rbp), %r13
movq 0x68(%r13), %r8
movslq %esi, %rsi
movslq (%r8,%rsi,4), %r8
incl %esi
testq %r8, %r8
js 0x11527
movq 0x50(%r13), %r10
movb (%r10,%r8), %r10b
movb %r10b, (%r15,%r12)
testb %bl, %bl
je 0x1155b
movl %r9d, %ebx
movq -0xc0(%rbp), %r12
movl %r8d, (%r12,%rbx,4)
cmpb %r10b, %r11b
jne 0x1155b
movq -0x48(%rbp), %rbx
incl %ebx
movq -0xb8(%rbp), %r10
movq -0x60(%rbp), %r11
movq %rbx, -0x48(%rbp)
movl %ebx, (%r10,%r11,4)
andl %r9d, %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %edx
incq %rcx
cmpq %rcx, %rax
jne 0x114b7
jmp 0x11580
movq $0x0, -0x48(%rbp)
xorl %edx, %edx
movq -0xd8(%rbp), %rax
movq -0x58(%rbp), %rbx
movq (%rax,%rbx,8), %rax
movq -0x60(%rbp), %r14
movl %edx, (%rax,%r14,4)
leaq 0x44c64(%rip), %rdi     # 0x56202
movq -0x48(%rbp), %r15
movl %r15d, %esi
xorl %eax, %eax
callq 0x20f0
movq %r14, %r8
movl -0xe0(%rbp), %r12d
cmpl %r12d, %r15d
movl -0xdc(%rbp), %eax
cmovgl %r8d, %eax
cmovgl %r15d, %r12d
movq %rbx, %rsi
movq -0x138(%rbp), %rsp
incq %r8
movq -0x50(%rbp), %r14
cmpq %r14, %r8
movq 0x38(%rbp), %r15
movq -0x70(%rbp), %r13
jne 0x1133e
movl 0x1c(%r13), %edx
leaq 0x44c2e(%rip), %rdi     # 0x56222
movq %rsi, %r13
movl %r12d, %ecx
movl %eax, %ebx
movl %eax, %r8d
xorl %eax, %eax
callq 0x20f0
testl %ebx, %ebx
js 0x11d31
movl %ebx, %ebx
imulq $0x70, %rbx, %rax
movl 0x1c(%r15,%rax), %esi
leaq 0x46304(%rip), %rdi     # 0x57924
xorl %eax, %eax
callq 0x20f0
testl %r12d, %r12d
jne 0x11642
leaq 0x587dd(%rip), %rax     # 0x69e10
movq -0x110(%rbp), %rcx
cmpl (%rax), %ecx
jg 0x11d31
movq -0x78(%rbp), %rax
movl (%rax,%rbx,4), %ecx
testl %ecx, %ecx
movl %ecx, %eax
movl -0x64(%rbp), %edx
cmovsl %edx, %eax
shrl $0x1f, %ecx
addl %ecx, %edx
movl %edx, -0x64(%rbp)
testl %r12d, %r12d
cvtsi2ss %r12d, %xmm0
addss 0x44b11(%rip), %xmm0    # 0x5617c
cvttss2si %xmm0, %ecx
cmovel %r12d, %ecx
movslq %eax, %rdx
movq -0xa0(%rbp), %rsi
movq (%rsi,%rdx,8), %rsi
movq -0xd0(%rbp), %r8
movslq (%r8,%rdx,4), %rdi
movl %r13d, (%rsi,%rdi,4)
leal 0x1(%rdi), %esi
movl %esi, (%r8,%rdx,4)
xorl %esi, %esi
movq -0x98(%rbp), %r9
movq 0x18(%rbp), %r10
movq -0x90(%rbp), %r11
movq -0xc8(%rbp), %rbx
movq -0x108(%rbp), %r8
cmpl %ecx, (%r8,%rsi,4)
jl 0x116e9
movq -0x78(%rbp), %rdi
cmpl %eax, (%rdi,%rsi,4)
je 0x116e9
movq -0x78(%rbp), %rdi
movl %eax, (%rdi,%rsi,4)
movq (%r11,%rdx,8), %rdi
movslq (%rbx,%rdx,4), %r8
movl %esi, (%rdi,%r8,4)
leal 0x1(%r8), %edi
movq -0x108(%rbp), %r8
movl %edi, (%rbx,%rdx,4)
incq %rsi
cmpq %rsi, %r14
jne 0x116b9
movq %r13, %rsi
incq %rsi
addq -0x120(%rbp), %r8
cmpq %r9, %rsi
jne 0x112df
movl -0x64(%rbp), %eax
testl %eax, %eax
je 0x11d69
movl %eax, %eax
movq %rax, -0x40(%rbp)
xorl %ebx, %ebx
movq -0xa0(%rbp), %rax
movq (%rax,%rbx,8), %r14
movq -0xd0(%rbp), %rax
movl (%rax,%rbx,4), %r12d
movq -0x90(%rbp), %rax
movq (%rax,%rbx,8), %r15
movq -0xc8(%rbp), %rax
movl (%rax,%rbx,4), %r13d
cmpl %r13d, %r12d
jne 0x117a3
movq %r14, %rdi
movl %r12d, %esi
movl 0x20(%rbp), %edx
movl $0x1, %ecx
callq 0x12983
movq %r15, %rdi
movl %r12d, %esi
movl 0x40(%rbp), %edx
movl $0x2, %ecx
callq 0x12983
cmpq $0x1, %r12
je 0x117e9
cmpl $0x2, %r12d
movq 0x18(%rbp), %rsi
jne 0x1180a
cmpl $0x0, 0x57094(%rip)     # 0x68820
je 0x1180a
movl 0x4(%r15), %eax
movslq (%r14), %rcx
imulq $0x70, %rcx, %rcx
movl %eax, 0x40(%rsi,%rcx)
addq $0x4, %r14
jmp 0x117ed
leaq 0x44c79(%rip), %rdi     # 0x56423
movl %r12d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
cmpq $0x1, %r12
jne 0x11d60
movq %r14, %rdi
movl $0x1, %esi
movl 0x20(%rbp), %edx
movl $0x1, %ecx
callq 0x12983
movq %r15, %rdi
movl %r13d, %esi
movl 0x40(%rbp), %edx
movl $0x2, %ecx
callq 0x12983
movq 0x18(%rbp), %rsi
movl (%r15), %eax
movslq (%r14), %rcx
imulq $0x70, %rcx, %rcx
movl %eax, 0x40(%rsi,%rcx)
incq %rbx
cmpq -0x40(%rbp), %rbx
jne 0x1171a
jmp 0x1182b
testl %r12d, %r12d
jle 0x117fb
xorl %eax, %eax
movl (%r15,%rax,4), %ecx
movslq (%r14,%rax,4), %rdx
imulq $0x70, %rdx, %rdx
movl %ecx, 0x40(%rsi,%rdx)
incq %rax
cmpq %rax, %r12
jne 0x11811
jmp 0x117fb
movq -0xa8(%rbp), %rbx
movl $0x0, (%rbx)
movl 0x20(%rbp), %r12d
testl %r12d, %r12d
movq -0x50(%rbp), %r13
jle 0x11af4
xorl %r14d, %r14d
movl $0x0, -0x58(%rbp)
movl $0x0, -0x60(%rbp)
imulq $0x70, %r14, %rax
leaq (%rsi,%rax), %r12
movslq 0x1c(%rsi,%rax), %r15
movslq 0x40(%rsi,%rax), %rbx
testq %rbx, %rbx
js 0x11d44
leaq (,%r15,4), %rdi
callq 0x21e0
movq %rax, 0x38(%r12)
imulq $0x70, %rbx, %rax
movq 0x38(%rbp), %rdx
leaq (%rdx,%rax), %rcx
movq %rcx, -0x48(%rbp)
movl %r14d, 0x40(%rdx,%rax)
movl -0x60(%rbp), %ecx
addl 0x1c(%rdx,%rax), %ecx
movl %ecx, -0x60(%rbp)
movq -0xb0(%rbp), %rax
movq %r14, -0xb8(%rbp)
movq (%rax,%r14,8), %rax
movq (%rax,%rbx,8), %r14
leaq 0x449ea(%rip), %rdi     # 0x562ad
xorl %eax, %eax
callq 0x20f0
movq %r15, -0x40(%rbp)
testl %r15d, %r15d
jle 0x11934
xorl %ebx, %ebx
movq -0x40(%rbp), %r15
movq 0x50(%r12), %rax
movsbl (%rax,%rbx), %edi
callq 0x2060
incq %rbx
cmpq %rbx, %r15
jne 0x118d9
leaq 0x449c3(%rip), %rdi     # 0x562b9
xorl %eax, %eax
callq 0x20f0
testl %r15d, %r15d
jle 0x11a70
xorl %ebx, %ebx
movq -0x48(%rbp), %r15
movslq (%r14,%rbx,4), %rax
testq %rax, %rax
js 0x1191f
movq 0x50(%r15), %rcx
movsbl (%rcx,%rax), %edi
jmp 0x11924
movl $0x2d, %edi
callq 0x2060
incq %rbx
cmpq %rbx, -0x40(%rbp)
jne 0x1190c
jmp 0x11942
leaq 0x4497e(%rip), %rdi     # 0x562b9
xorl %eax, %eax
callq 0x20f0
movl $0xa, %edi
callq 0x2060
leaq 0x44973(%rip), %rdi     # 0x562c6
xorl %eax, %eax
callq 0x20f0
movq -0x40(%rbp), %rbx
testl %ebx, %ebx
jle 0x11a8b
xorl %ebx, %ebx
movl $0x1, %r13d
movl $0x0, -0x70(%rbp)
movl $0x0, -0xc0(%rbp)
movslq (%r14,%rbx,4), %r15
testq %r15, %r15
js 0x119a9
movq 0x50(%r12), %rcx
movb (%rcx,%rbx), %dl
movq -0x48(%rbp), %rdi
movq 0x50(%rdi), %rax
cmpb (%rax,%r15), %dl
jne 0x119d8
incl -0xc0(%rbp)
movl %r15d, %ecx
jmp 0x11a1e
movq 0x38(%r12), %rax
movl $0xffffffff, (%rax,%rbx,4) # imm = 0xFFFFFFFF
movl $0x2d, %edi
callq 0x2060
incl -0x70(%rbp)
movl $0x1, %eax
testl %r13d, %r13d
jne 0x11a35
movq -0x88(%rbp), %rcx
incl 0x10(%rcx)
jmp 0x11a35
movq -0xa8(%rbp), %rsi
movslq (%rsi), %rax
movq -0xf8(%rbp), %rdx
movl %ebx, (%rdx,%rax,4)
movb (%rcx,%rbx), %al
movslq (%rsi), %rcx
movq -0xf0(%rbp), %rdx
movb %al, (%rdx,%rcx)
movq 0x50(%rdi), %rax
movslq (%r14,%rbx,4), %rcx
movb (%rax,%rcx), %al
movslq (%rsi), %rcx
movq -0x100(%rbp), %rdx
movb %al, (%rdx,%rcx)
incl (%rsi)
movl (%r14,%rbx,4), %ecx
movq 0x50(%rdi), %rax
movq 0x38(%r12), %rdx
movl %ecx, (%rdx,%rbx,4)
movslq (%r14,%rbx,4), %rcx
movsbl (%rax,%rcx), %edi
callq 0x2060
xorl %eax, %eax
incq %rbx
movl %eax, %r13d
cmpq %rbx, -0x40(%rbp)
jne 0x1197f
movl $0xa, %edi
callq 0x2060
cvtsi2ssl -0xc0(%rbp), %xmm0
testl %r15d, %r15d
movq -0x50(%rbp), %r13
movq -0x88(%rbp), %rax
movq -0x40(%rbp), %rbx
movl -0x70(%rbp), %ecx
jns 0x11aa4
jmp 0x11aa1
movq %r15, %rbx
movl $0xa, %edi
callq 0x2060
leaq 0x44842(%rip), %rdi     # 0x562c6
xorl %eax, %eax
callq 0x20f0
movl $0xa, %edi
callq 0x2060
xorps %xmm0, %xmm0
xorl %ecx, %ecx
movq -0x88(%rbp), %rax
decl 0x10(%rax)
addl %ebx, -0x58(%rbp)
subl %ecx, %ebx
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movsd (%rax), %xmm1
addps %xmm0, %xmm1
movlps %xmm1, (%rax)
movq -0xb8(%rbp), %r14
incq %r14
cmpq -0x98(%rbp), %r14
movq 0x18(%rbp), %rsi
jne 0x1185a
movq -0xa8(%rbp), %rbx
movl (%rbx), %esi
xorps %xmm0, %xmm0
cvtsi2ssl -0x60(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movl 0x20(%rbp), %r12d
jmp 0x11b05
xorl %esi, %esi
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
movl $0x0, -0x58(%rbp)
leaq 0x447c6(%rip), %rdi     # 0x562d2
xorl %eax, %eax
callq 0x20f0
movl (%rbx), %eax
testl %eax, %eax
setle %cl
cmpl $0x3e8, %eax            # imm = 0x3E8
sete %al
orb %cl, %al
jne 0x11b8c
movl $0x1, %r14d
leaq 0x447ae(%rip), %rbx     # 0x562e1
movq -0xf0(%rbp), %rax
movsbl -0x1(%rax,%r14), %esi
movq -0xf8(%rbp), %rax
movslq -0x4(%rax,%r14,4), %rax
shlq $0x5, %rax
movq 0x28(%rbp), %rcx
leaq (%rcx,%rax), %rdx
addq $0xd, %rdx
movq -0x100(%rbp), %rax
movsbl -0x1(%rax,%r14), %ecx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x20f0
movq -0xa8(%rbp), %rax
movslq (%rax), %rax
cmpq %rax, %r14
jge 0x11b8c
incq %r14
cmpl $0x3e8, %eax            # imm = 0x3E8
jne 0x11b33
movl $0xa, %edi
callq 0x2060
movq -0x88(%rbp), %rbx
movss (%rbx), %xmm0
divss 0x4(%rbx), %xmm0
mulss 0x3f572(%rip), %xmm0    # 0x51120
movss %xmm0, (%rbx)
movl -0x58(%rbp), %eax
cvtsi2ss %eax, %xmm2
movss -0x40(%rbp), %xmm0
mulss %xmm2, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x11bd0
sqrtss %xmm0, %xmm0
jmp 0x11be0
movaps %xmm2, -0x40(%rbp)
callq 0x21d0
movaps -0x40(%rbp), %xmm2
movl -0x58(%rbp), %eax
movsd 0x4(%rbx), %xmm1
unpcklps %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1]
divps %xmm2, %xmm1
movlps %xmm1, 0x4(%rbx)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x21e0
movq %rax, 0x18(%rbx)
movq 0x10(%rbp), %rcx
movslq (%rcx), %rcx
testq %rcx, %rcx
movq 0x18(%rbp), %r11
movq 0x38(%rbp), %r15
jle 0x11c78
xorl %edx, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edi, %edi
imulq $0x70, %rdx, %r9
movslq 0x1c(%r11,%r9), %r8
testq %r8, %r8
jle 0x11c70
leaq (%r11,%r9), %r10
movslq 0x40(%r11,%r9), %r9
imulq $0x70, %r9, %r9
movl 0x18(%r15,%r9), %r9d
movq 0x38(%r10), %r10
movslq %edi, %r11
leaq (%rax,%r11,4), %rbx
xorl %r11d, %r11d
movl (%r10,%r11,4), %r14d
leal (%r14,%r9), %r15d
testl %r14d, %r14d
cmovsl %esi, %r15d
movl %r15d, (%rbx,%r11,4)
incq %r11
cmpq %r11, %r8
jne 0x11c4a
addl %r11d, %edi
movq 0x18(%rbp), %r11
movq 0x38(%rbp), %r15
incq %rdx
cmpq %rcx, %rdx
jne 0x11c1c
movl -0x58(%rbp), %edx
movl %edx, %ecx
leaq (%rax,%rcx,4), %rax
addq $-0x4, %rax
testl %edx, %edx
jle 0x11c9f
decl %edx
cmpl $0x0, (%rax)
leaq -0x4(%rax), %rax
js 0x11c85
incl %edx
movq -0x118(%rbp), %rax
movl %edx, (%rax)
testl %r12d, %r12d
movq -0xb0(%rbp), %r12
jle 0x11d0a
xorl %r14d, %r14d
movq (%r12,%r14,8), %rbx
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x2050
incq %r15
cmpq %r15, %r13
jne 0x11cb5
movq %rbx, %rdi
callq 0x2050
movq -0xd8(%rbp), %rax
movq (%rax,%r14,8), %rdi
callq 0x2050
movq -0xa0(%rbp), %rax
movq (%rax,%r14,8), %rdi
callq 0x2050
movq -0x90(%rbp), %rax
movq (%rax,%r14,8), %rdi
callq 0x2050
incq %r14
cmpq -0x98(%rbp), %r14
jne 0x11cae
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x447b0(%rip), %rdi     # 0x564d2
callq 0x2090
movl $0x8, %edi
callq 0x2280
leaq 0x44517(%rip), %rdi     # 0x5624f
movl %r13d, %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x11d27
movsbl 0x34(%r12), %edx
leaq 0x44529(%rip), %rdi     # 0x5627a
movl %r14d, %esi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x20f0
jmp 0x11d27
leaq 0x44364(%rip), %rdi     # 0x560cb
jmp 0x11d22
leaq 0x44737(%rip), %rdi     # 0x564a7
jmp 0x11d22
movq 0x50(%rbp), %rbx
movq 0x30(%rbp), %r14
leaq 0x4440f(%rip), %rdi     # 0x56190
xorl %eax, %eax
callq 0x20f0
leaq 0x44427(%rip), %rdi     # 0x561b6
movl %r15d, %esi
movq %r14, %rdx
movl 0x40(%rbp), %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x20f0
leaq 0x4346c(%rip), %rdi     # 0x55215
jmp 0x11d22