// File: /workspace/github_c_makefile_star2_O1/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 $0xf8, %rsp
movq %r9, -0xf8(%rbp)
movq %rcx, -0xe8(%rbp)
movq %rdx, -0xe0(%rbp)
movq %rsi, -0xd8(%rbp)
movq %rdi, -0x98(%rbp)
movl 0x20(%rbp), %r15d
movq 0x10(%rbp), %rax
movl %r15d, (%rax)
cmpl %r15d, 0x40(%rbp)
jl 0x121b7
movq 0x18(%rbp), %rsi
xorl %r12d, %r12d
movl %r12d, 0x20(%r8)
movl %r12d, 0x10(%r8)
movq %r8, -0x88(%rbp)
movq $0x0, (%r8)
movl %r15d, %eax
movq %rax, -0x50(%rbp)
movl $0x0, %r13d
testl %r15d, %r15d
jle 0x11575
imulq $0x70, -0x50(%rbp), %rax
xorl %ecx, %ecx
xorl %r13d, %r13d
movl 0x1c(%rsi,%rcx), %edx
cmpl %r13d, %edx
cmovgl %edx, %r13d
addq $0x70, %rcx
cmpq %rcx, %rax
jne 0x11561
movq 0x38(%rbp), %rsi
movl 0x40(%rbp), %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
testl %eax, %eax
jle 0x115a4
imulq $0x70, -0x58(%rbp), %rax
xorl %ecx, %ecx
xorl %r12d, %r12d
movl 0x1c(%rsi,%rcx), %edx
cmpl %r12d, %edx
cmovgl %edx, %r12d
addq $0x70, %rcx
cmpq %rcx, %rax
jne 0x11590
movq %rsp, %rcx
movq -0x50(%rbp), %rsi
leaq 0xf(,%rsi,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0xb8(%rbp)
movq %rcx, %rsp
movq -0x58(%rbp), %rcx
imulq %rsi, %rcx
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdx
subq %rcx, %rdx
movq %rdx, -0xc0(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
leaq 0xf(,%rsi,4), %rcx
andq $-0x10, %rcx
subq %rcx, %rdx
movq %rdx, -0xa0(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
subq %rcx, %rdx
movq %rdx, -0xa8(%rbp)
movq %rdx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
cmpl $0x0, 0x20(%rbp)
jle 0x116b4
movslq 0x40(%rbp), %rbx
leaq (,%rbx,8), %rax
movq %rax, -0x30(%rbp)
shlq $0x2, %rbx
movq -0x50(%rbp), %rax
leaq (,%rax,4), %rax
movq %rax, -0x40(%rbp)
xorl %r14d, %r14d
movq -0x30(%rbp), %rdi
callq 0x21d0
movq -0x70(%rbp), %rcx
movq %rax, (%rcx,%r14,8)
movq %rbx, %rdi
callq 0x21d0
movq -0xb8(%rbp), %rcx
movq %rax, (%rcx,%r14,8)
movq -0x40(%rbp), %rdi
callq 0x21d0
movq -0x90(%rbp), %rcx
movq %rax, (%rcx,%r14,8)
movq %rbx, %rdi
callq 0x21d0
movq %rax, (%r15,%r14,8)
incq %r14
cmpq %r14, -0x50(%rbp)
jne 0x11667
movq %r15, -0xb0(%rbp)
movq %rsp, %rcx
movq -0x58(%rbp), %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0xc8(%rbp)
movq %rcx, %rsp
movl 0x20(%rbp), %eax
testl %eax, %eax
movq -0xa8(%rbp), %r14
jle 0x11716
movq -0x50(%rbp), %rax
leaq (,%rax,4), %rbx
movq -0xa0(%rbp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2110
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2110
movl 0x20(%rbp), %eax
cmpl $0x0, 0x40(%rbp)
jle 0x1173c
movq -0x58(%rbp), %rax
leaq (,%rax,4), %rdx
movq -0xc8(%rbp), %rdi
movl $0xff, %esi
callq 0x2110
movl 0x20(%rbp), %eax
testl %eax, %eax
jle 0x11b8f
addl %r13d, %r12d
movl %r12d, %eax
shlq $0x2, %rax
movq %rax, -0x110(%rbp)
movq -0x58(%rbp), %r9
leaq (,%r9,4), %rax
movq %rax, -0x100(%rbp)
movq -0xc0(%rbp), %r8
xorl %r12d, %r12d
movl $0x0, -0x38(%rbp)
movq 0x18(%rbp), %r11
movq 0x38(%rbp), %r13
movq %r8, -0xd0(%rbp)
imulq $0x70, %r12, %rax
leaq (%r11,%rax), %rcx
movq %rcx, -0x30(%rbp)
movl 0x1c(%r11,%rax), %edx
movl $0xffffffff, 0x40(%r11,%rax) # imm = 0xFFFFFFFF
cmpl $0x0, 0x40(%rbp)
movq %rdx, -0xf0(%rbp)
movq %r12, -0x48(%rbp)
jle 0x11a50
movq %r12, %rax
imulq %r9, %rax
movq -0xc0(%rbp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, -0x60(%rbp)
leaq (,%rdx,4), %rax
movq %rax, -0x108(%rbp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %ebx, %ebx
xorl %ecx, %ecx
movl %r15d, -0x34(%rbp)
movl %ecx, -0x78(%rbp)
imulq $0x70, %rbx, %rax
movq %rbx, %r8
leaq (%rax,%r13), %rbx
movslq 0x1c(%r13,%rax), %r15
movq -0x30(%rbp), %r14
movsbl 0x34(%r14), %edx
movsbl 0x34(%r13,%rax), %r9d
subq $0x8, %rsp
leaq 0x4499c(%rip), %rdi     # 0x561b3
movl %r12d, %esi
movq -0xf0(%rbp), %r13
movl %r13d, %ecx
movq %r8, -0x68(%rbp)
xorl %eax, %eax
pushq %r15
callq 0x20f0
movq %r14, %rcx
addq $0x10, %rsp
movq %rsp, -0x118(%rbp)
movl 0x60(%r14), %eax
addl %eax, %eax
movq %rsp, %r12
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
leaq 0x585aa(%rip), %rax     # 0x69e10
cmpl (%rax), %r13d
jle 0x1189f
movq 0x58(%rcx), %rdi
movl 0x60(%rcx), %esi
movq 0x58(%rbx), %rdx
movl 0x60(%rbx), %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
leaq -0x7c(%rbp), %rax
pushq %rax
pushq %r14
pushq %r12
pushq $0x7
callq 0x4d35b
addq $0x20, %rsp
testl %eax, %eax
jne 0x118df
jmp 0x12168
leaq 0x44c2c(%rip), %rdi     # 0x564d2
callq 0x2090
movl %r13d, -0x7c(%rbp)
testl %r13d, %r13d
jle 0x118df
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rax
xorl %ecx, %ecx
movb (%rax,%rcx), %dl
movb %dl, (%r12,%rcx)
movb $0x2d, %dl
cmpq %r15, %rcx
jge 0x118d3
movq 0x50(%rbx), %rdx
movb (%rdx,%rcx), %dl
movb %dl, (%r14,%rcx)
incq %rcx
cmpq %rcx, %r13
jne 0x118be
movq -0x110(%rbp), %rdi
callq 0x21d0
movq %rax, %rdx
movq -0x70(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x7c(%rbp), %r15d
movq -0x60(%rbp), %rax
movl $0x0, (%rax,%rcx,4)
testl %r13d, %r13d
jle 0x11930
movq %rdx, %r13
movq %rdx, %rdi
movl $0xff, %esi
movq -0x108(%rbp), %rdx
callq 0x2110
movq %r13, %rdx
testl %r15d, %r15d
movq -0x30(%rbp), %r13
jle 0x119f0
movq %rdx, -0x40(%rbp)
xorl %eax, %eax
xorl %edx, %edx
xorl %ecx, %ecx
xorl %esi, %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
cmpb $0x2d, (%r12,%rax)
je 0x11961
movq 0x68(%r13), %rdi
movslq %esi, %rsi
movl (%rdi,%rsi,4), %edi
incl %esi
movl %edi, %r8d
testl %edi, %edi
js 0x11972
movq 0x50(%r13), %r9
movb (%r9,%r8), %r9b
jmp 0x11975
movb $0x2d, %r9b
movl %edx, %r10d
movb %r9b, (%r12,%r10)
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpb $0x2d, (%r14,%rax)
je 0x11996
movq 0x68(%rbx), %r9
movslq %ecx, %rcx
movl (%r9,%rcx,4), %r9d
incl %ecx
testl %r9d, %r9d
js 0x119ac
movq 0x50(%rbx), %r11
movl %r9d, %r13d
movb (%r11,%r13), %r11b
movq -0x30(%rbp), %r13
jmp 0x119af
movb $0x2d, %r11b
movb %r11b, (%r14,%r10)
testl %edi, %edi
js 0x119d5
movq -0x40(%rbp), %r11
movl %r9d, (%r11,%r8,4)
movb (%r12,%r10), %r8b
cmpb (%r14,%r10), %r8b
jne 0x119d5
movq -0x60(%rbp), %r8
movq -0x68(%rbp), %r10
incl (%r8,%r10,4)
andl %edi, %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %edx
incq %rax
cmpq %rax, %r15
jne 0x11949
jmp 0x119f2
xorl %edx, %edx
movq -0xb8(%rbp), %rax
movq -0x48(%rbp), %r12
movq (%rax,%r12,8), %rax
movq -0x68(%rbp), %rbx
movl %edx, (%rax,%rbx,4)
movq -0x60(%rbp), %rax
movl (%rax,%rbx,4), %r13d
leaq 0x447d3(%rip), %rdi     # 0x561ea
movl %r13d, %esi
xorl %eax, %eax
callq 0x20f0
movl -0x78(%rbp), %ecx
cmpl %ecx, %r13d
movl -0x34(%rbp), %r15d
cmovgl %ebx, %r15d
cmovgl %r13d, %ecx
movq -0x118(%rbp), %rsp
incq %rbx
movq -0x58(%rbp), %r9
cmpq %r9, %rbx
movq 0x38(%rbp), %r13
jne 0x117e6
jmp 0x11a58
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq %r9, %r14
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %edx
leaq 0x447a1(%rip), %rdi     # 0x5620a
movl %r12d, %esi
movl %ecx, -0x78(%rbp)
movl %r15d, %r8d
xorl %eax, %eax
callq 0x20f0
movl %r15d, %ebx
testl %r15d, %r15d
js 0x11a98
imulq $0x70, %rbx, %rax
movl 0x1c(%r13,%rax), %esi
leaq 0x45ed3(%rip), %rdi     # 0x57964
xorl %eax, %eax
callq 0x20f0
testl %r15d, %r15d
movq -0x50(%rbp), %r10
movq -0xa8(%rbp), %r15
movq -0xc8(%rbp), %r12
movl -0x78(%rbp), %esi
js 0x1217e
testl %esi, %esi
jne 0x11ad0
leaq 0x5834f(%rip), %rax     # 0x69e10
movq -0xf0(%rbp), %rcx
cmpl (%rax), %ecx
jg 0x1217e
movl (%r12,%rbx,4), %eax
testl %eax, %eax
movl %eax, %ecx
cmovsl -0x38(%rbp), %ecx
testl %esi, %esi
xorps %xmm0, %xmm0
cvtsi2ss %esi, %xmm0
addss 0x44687(%rip), %xmm0    # 0x56174
cvttss2si %xmm0, %edx
cmovel %esi, %edx
movslq %ecx, %rsi
movq -0xa0(%rbp), %r11
movslq (%r11,%rsi,4), %rdi
leal 0x1(%rdi), %r8d
movq -0x90(%rbp), %r9
movq (%r9,%rsi,8), %r9
movq -0x48(%rbp), %rbx
movl %ebx, (%r9,%rdi,4)
movl %r8d, (%r11,%rsi,4)
cmpl $0x0, 0x40(%rbp)
movq 0x18(%rbp), %r11
movq -0xb0(%rbp), %rbx
movq -0xd0(%rbp), %r8
movq %r14, %r9
jle 0x11b70
xorl %edi, %edi
cmpl %edx, (%r8,%rdi,4)
jl 0x11b68
cmpl %ecx, (%r12,%rdi,4)
je 0x11b68
movl %ecx, (%r12,%rdi,4)
movq (%rbx,%rsi,8), %r8
movslq (%r15,%rsi,4), %r9
movl %edi, (%r8,%r9,4)
leal 0x1(%r9), %r8d
movq %r14, %r9
movl %r8d, (%r15,%rsi,4)
movq -0xd0(%rbp), %r8
incq %rdi
cmpq %rdi, %r9
jne 0x11b3a
shrl $0x1f, %eax
addl %eax, -0x38(%rbp)
movq -0x48(%rbp), %r12
incq %r12
addq -0x100(%rbp), %r8
cmpq %r10, %r12
jne 0x11781
jmp 0x11b9a
movl $0x0, -0x38(%rbp)
movq 0x18(%rbp), %r11
cmpl $0x0, -0x38(%rbp)
je 0x121f3
movl 0x20(%rbp), %edx
jle 0x11ca7
movl -0x38(%rbp), %eax
movq %rax, -0x30(%rbp)
xorl %ebx, %ebx
movq -0x90(%rbp), %rax
movq (%rax,%rbx,8), %r14
movq -0xa0(%rbp), %rax
movl (%rax,%rbx,4), %r12d
movq -0xb0(%rbp), %rax
movq (%rax,%rbx,8), %r15
movq -0xa8(%rbp), %rax
movl (%rax,%rbx,4), %r13d
cmpl %r13d, %r12d
je 0x11c08
leaq 0x4481d(%rip), %rdi     # 0x5640b
movl %r12d, %esi
movl %r13d, %edx
xorl %eax, %eax
callq 0x20f0
movl 0x20(%rbp), %edx
cmpq $0x1, %r12
jne 0x121ae
movq %r14, %rdi
movl %r12d, %esi
movl $0x1, %ecx
callq 0x129da
movq %r15, %rdi
movl %r13d, %esi
movl 0x40(%rbp), %edx
movl $0x2, %ecx
callq 0x129da
cmpq $0x1, %r12
jne 0x11c37
movq 0x18(%rbp), %r11
jmp 0x11c64
cmpl $0x2, %r13d
movq 0x18(%rbp), %r11
jne 0x11c85
cmpl $0x2, %r12d
jne 0x11c85
cmpl $0x0, 0x56bd2(%rip)     # 0x68820
je 0x11c85
movl 0x4(%r15), %eax
movslq (%r14), %rcx
imulq $0x70, %rcx, %rcx
movl %eax, 0x40(%r11,%rcx)
addq $0x4, %r14
movl (%r15), %eax
movslq (%r14), %rcx
imulq $0x70, %rcx, %rcx
movl %eax, 0x40(%r11,%rcx)
incq %rbx
cmpq -0x30(%rbp), %rbx
movl 0x20(%rbp), %edx
jne 0x11bb6
jmp 0x11ca7
testl %r12d, %r12d
jle 0x11c73
xorl %eax, %eax
movl (%r15,%rax,4), %ecx
movslq (%r14,%rax,4), %rdx
imulq $0x70, %rdx, %rdx
movl %ecx, 0x40(%r11,%rdx)
incq %rax
cmpq %rax, %r12
jne 0x11c8c
jmp 0x11c73
movq -0x98(%rbp), %rax
movl $0x0, (%rax)
testl %edx, %edx
jle 0x11f1c
xorl %r15d, %r15d
movl $0x0, -0x34(%rbp)
movl $0x0, -0x48(%rbp)
movq 0x38(%rbp), %r14
imulq $0x70, %r15, %rax
leaq (%r11,%rax), %r12
movslq 0x1c(%r11,%rax), %r13
movslq 0x40(%r11,%rax), %rbx
testq %rbx, %rbx
js 0x12192
leaq (,%r13,4), %rdi
callq 0x21d0
movq %rax, 0x38(%r12)
imulq $0x70, %rbx, %rcx
movl %r15d, 0x40(%r14,%rcx)
movl -0x48(%rbp), %eax
movq %rcx, -0x40(%rbp)
addl 0x1c(%r14,%rcx), %eax
movl %eax, -0x48(%rbp)
movq %r15, -0x78(%rbp)
movq -0x70(%rbp), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%rbx,8), %r14
leaq 0x44568(%rip), %rdi     # 0x56295
xorl %eax, %eax
callq 0x20f0
testl %r13d, %r13d
jle 0x11d51
xorl %ebx, %ebx
movq 0x50(%r12), %rax
movsbl (%rax,%rbx), %edi
callq 0x2060
incq %rbx
cmpq %rbx, %r13
jne 0x11d3b
movq -0x40(%rbp), %r15
addq 0x38(%rbp), %r15
leaq 0x44541(%rip), %rdi     # 0x562a1
xorl %eax, %eax
callq 0x20f0
testl %r13d, %r13d
jle 0x11d93
xorl %ebx, %ebx
movslq (%r14,%rbx,4), %rax
testq %rax, %rax
js 0x11d81
movq 0x50(%r15), %rcx
movsbl (%rcx,%rax), %edi
jmp 0x11d86
movl $0x2d, %edi
callq 0x2060
incq %rbx
cmpq %rbx, %r13
jne 0x11d6e
movl $0xa, %edi
callq 0x2060
xorl %ebx, %ebx
leaq 0x44508(%rip), %rdi     # 0x562ae
xorl %eax, %eax
callq 0x20f0
testl %r13d, %r13d
jle 0x11ea7
movq %r15, -0x40(%rbp)
xorl %ebx, %ebx
movl $0x1, %r15d
movl $0x0, -0x68(%rbp)
movl $0x0, -0x60(%rbp)
movslq (%r14,%rbx,4), %rcx
testq %rcx, %rcx
setns %al
movl %eax, -0x30(%rbp)
js 0x11df9
movq 0x50(%r12), %rax
movb (%rax,%rbx), %dl
movq -0x40(%rbp), %rdi
movq 0x50(%rdi), %rsi
cmpb (%rsi,%rcx), %dl
jne 0x11e28
incl -0x60(%rbp)
jmp 0x11e66
movq 0x38(%r12), %rax
movl $0xffffffff, (%rax,%rbx,4) # imm = 0xFFFFFFFF
movl $0x2d, %edi
callq 0x2060
incl -0x68(%rbp)
movl $0x1, %eax
testl %r15d, %r15d
jne 0x11e85
movq -0x88(%rbp), %rcx
incl 0x10(%rcx)
jmp 0x11e85
movq -0x98(%rbp), %rsi
movslq (%rsi), %rcx
movq -0xe0(%rbp), %rdx
movl %ebx, (%rdx,%rcx,4)
movb (%rax,%rbx), %al
movslq (%rsi), %rcx
movq -0xd8(%rbp), %rdx
movb %al, (%rdx,%rcx)
movq 0x50(%rdi), %rax
movslq (%r14,%rbx,4), %rcx
movb (%rax,%rcx), %al
movslq (%rsi), %rcx
movq -0xe8(%rbp), %rdx
movb %al, (%rdx,%rcx)
incl (%rsi)
movl (%r14,%rbx,4), %eax
movq 0x38(%r12), %rcx
movl %eax, (%rcx,%rbx,4)
movq 0x50(%rdi), %rax
movslq (%r14,%rbx,4), %rcx
movsbl (%rax,%rcx), %edi
callq 0x2060
xorl %eax, %eax
incq %rbx
movl %eax, %r15d
cmpq %rbx, %r13
jne 0x11dd0
cvtsi2ssl -0x60(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movl -0x68(%rbp), %ebx
movl -0x30(%rbp), %r14d
jmp 0x11eb2
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
xorl %r14d, %r14d
movl $0xa, %edi
callq 0x2060
testb %r14b, %r14b
movq -0x50(%rbp), %r12
movq 0x38(%rbp), %r14
movq -0x88(%rbp), %rax
jne 0x11ed3
decl 0x10(%rax)
addl %r13d, -0x34(%rbp)
movss -0x40(%rbp), %xmm1
addss (%rax), %xmm1
subl %ebx, %r13d
xorps %xmm0, %xmm0
cvtsi2ss %r13d, %xmm0
movss %xmm1, (%rax)
addss 0x4(%rax), %xmm0
movss %xmm0, 0x4(%rax)
movq -0x78(%rbp), %r15
incq %r15
cmpq %r12, %r15
movq 0x18(%rbp), %r11
jne 0x11cd1
xorps %xmm0, %xmm0
cvtsi2ssl -0x48(%rbp), %xmm0
movss %xmm0, -0x30(%rbp)
jmp 0x11f2f
movl $0x0, -0x34(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x50(%rbp), %r12
movq -0x98(%rbp), %rbx
movl (%rbx), %esi
leaq 0x4437b(%rip), %rdi     # 0x562ba
xorl %eax, %eax
callq 0x20f0
movl (%rbx), %eax
testl %eax, %eax
setle %cl
cmpl $0x3e8, %eax            # imm = 0x3E8
sete %al
orb %cl, %al
jne 0x11fbf
movq 0x28(%rbp), %r14
movl $0x1, %r15d
leaq 0x4435f(%rip), %rbx     # 0x562c9
movq -0xd8(%rbp), %rax
movsbl -0x1(%rax,%r15), %esi
movq -0xe0(%rbp), %rax
movslq -0x4(%rax,%r15,4), %rax
shlq $0x5, %rax
leaq (%r14,%rax), %rdx
addq $0xd, %rdx
movq -0xe8(%rbp), %rax
movsbl -0x1(%rax,%r15), %ecx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x20f0
movq -0x98(%rbp), %rax
movslq (%rax), %rax
cmpq %rax, %r15
jge 0x11fbf
incq %r15
cmpl $0x3e8, %eax            # imm = 0x3E8
jne 0x11f6a
movl $0xa, %edi
callq 0x2060
movq -0x88(%rbp), %rax
movss (%rax), %xmm0
divss 0x4(%rax), %xmm0
mulss 0x3f033(%rip), %xmm0    # 0x51014
movss %xmm0, (%rax)
movl -0x34(%rbp), %r14d
cvtsi2ss %r14d, %xmm3
movss -0x30(%rbp), %xmm0
mulss %xmm3, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x12005
sqrtss %xmm0, %xmm0
jmp 0x1201b
movss %xmm3, -0x30(%rbp)
callq 0x21c0
movss -0x30(%rbp), %xmm3
movq -0x88(%rbp), %rax
movq 0x38(%rbp), %rbx
movss 0x4(%rax), %xmm1
movss 0x8(%rax), %xmm2
divss %xmm0, %xmm2
movss %xmm2, 0x8(%rax)
divss %xmm3, %xmm1
movss %xmm1, 0x4(%rax)
movslq %r14d, %rdi
shlq $0x2, %rdi
movq %rax, %r14
callq 0x21d0
movq %rax, 0x18(%r14)
movq 0x10(%rbp), %rcx
movslq (%rcx), %rcx
testq %rcx, %rcx
movq 0x18(%rbp), %r11
jle 0x120c3
xorl %edx, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edi, %edi
imulq $0x70, %rdx, %r9
movslq 0x1c(%r11,%r9), %r8
testq %r8, %r8
jle 0x120bb
leaq (%r11,%r9), %r10
movslq 0x40(%r11,%r9), %r9
imulq $0x70, %r9, %r9
movl 0x18(%rbx,%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 0x12095
addl %r11d, %edi
movq 0x18(%rbp), %r11
movq 0x38(%rbp), %rbx
incq %rdx
cmpq %rcx, %rdx
jne 0x12067
movl -0x34(%rbp), %edx
movl %edx, %ecx
incl %edx
testl %ecx, %ecx
jle 0x120e4
decl %edx
cmpl $0x0, -0x4(%rax,%rcx,4)
leaq -0x1(%rcx), %rcx
js 0x120ca
movq -0xf8(%rbp), %rax
movl %edx, (%rax)
cmpl $0x0, 0x20(%rbp)
jle 0x12157
xorl %ebx, %ebx
movq -0x58(%rbp), %r13
cmpl $0x0, 0x40(%rbp)
jle 0x12112
movq -0x70(%rbp), %rax
movq (%rax,%rbx,8), %r14
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x2050
incq %r15
cmpq %r15, %r13
jne 0x12101
movq -0x70(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2050
movq -0xb8(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2050
movq -0x90(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2050
movq -0xb0(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2050
incq %rbx
cmpq %r12, %rbx
jne 0x120f0
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4434b(%rip), %rdi     # 0x564ba
callq 0x2090
movl $0x8, %edi
callq 0x2270
leaq 0x440b2(%rip), %rdi     # 0x56237
movq -0x48(%rbp), %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x12174
movsbl 0x34(%r12), %edx
leaq 0x440c3(%rip), %rdi     # 0x56262
movl %r15d, %esi
movl %r13d, %ecx
xorl %eax, %eax
callq 0x20f0
jmp 0x12174
leaq 0x43f0a(%rip), %rdi     # 0x560bf
jmp 0x1216f
movq 0x50(%rbp), %rbx
movq 0x30(%rbp), %r14
leaq 0x43fb2(%rip), %rdi     # 0x56178
xorl %eax, %eax
callq 0x20f0
leaq 0x43fca(%rip), %rdi     # 0x5619e
movl %r15d, %esi
movq %r14, %rdx
movl 0x40(%rbp), %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x20f0
leaq 0x42ffb(%rip), %rdi     # 0x551e9
jmp 0x1216f
leaq 0x44295(%rip), %rdi     # 0x5648f
jmp 0x1216f