// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/align_tnm.c
// Function: Superimpose_cluster
void Superimpose_cluster(struct chain *chains1, int Nchain1,
			 struct chain *chains2, int Nchain2,
			 int *i1cl, int n1cl, int *i2cl, int n2cl,
			 int ***ali_all, int **nali)
{
  if(n1cl!=n2cl){
    printf("WARNING, different number of chains in clusters of PDB1 (%d) "
	   "and PDB2 (%d)\n", n1cl, n2cl);
    if(n1cl!=1){printf("Exiting\n"); exit(8);}
  }
  Test_chains(i1cl, n1cl, chains1, Nchain1, 1);
  Test_chains(i2cl, n2cl, chains2, Nchain2, 2);

  if(n1cl==1){chains1[i1cl[0]].match=i2cl[0]; return;}
  if(Invert_dimer && n1cl==2 && n2cl==2){
    chains1[i1cl[0]].match=i2cl[1];
    chains1[i1cl[1]].match=i2cl[0]; return;
  }
  for(int i=0; i<n1cl; i++)chains1[i1cl[i]].match=i2cl[i];
  return;

  int ncompl=n1cl, *ichain2[ncompl], i;
  for(i=0; i<ncompl; i++)ichain2[i]=malloc(ncompl*sizeof(int));

  if(ncompl==2 || ncompl>=7){
    // Circular permutations
    for(i=0; i<ncompl; i++){
      int ij=i, j;
      for(j=0; j<ncompl; j++){
	ichain2[i][j]=i2cl[ij]; ij++; if(ij==ncompl)ij=0;
	if(ichain2[i][j]<0 || ichain2[i][j]>=Nchain2){
	  printf("ERROR in circular perm., wrong chain %d\n",
		 ichain2[i][j]); exit(8);
	}
      }
    }
  }else{
    Superimpose_centers(ichain2, ncompl, chains1, Nchain1, chains2, Nchain2,
			i1cl, i2cl, ali_all, nali);
  }

  // Find largest RMSD
  float RMSD_max=-1; int imax=-1;
  for(i=0; i<ncompl; i++){
    float RMSD=Superimpose_complex(ichain2, ncompl, chains1, Nchain1,
				   chains2,Nchain2,i1cl,i2cl, ali_all, nali);
    if(RMSD>RMSD_max){RMSD_max=RMSD; imax=i;}
  }
  if(imax<0){
    printf("ERROR, optimal superimposition could not be found\n");
    exit(8);
  }

  for(i=0; i<n1cl; i++){
    chains1[i1cl[i]].match=ichain2[imax][i];
  }
  for(i=0; i<ncompl; i++)free(ichain2[i]);

  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl 0x18(%rbp), %eax
je 0x17ad9
movl -0x2c(%rbp), %esi
movl 0x18(%rbp), %edx
leaq 0x63abd(%rip), %rdi     # 0x7b56f
movb $0x0, %al
callq 0x10d0
cmpl $0x1, -0x2c(%rbp)
je 0x17ad7
leaq 0x636f5(%rip), %rdi     # 0x7b1bb
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
callq 0x1210
jmp 0x17ad9
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x8(%rbp), %rdx
movl -0xc(%rbp), %ecx
movl $0x1, %r8d
callq 0x185f0
movq 0x10(%rbp), %rdi
movl 0x18(%rbp), %esi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl $0x2, %r8d
callq 0x185f0
cmpl $0x1, -0x2c(%rbp)
jne 0x17b31
movq 0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rdx
movslq (%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x40(%rax)
jmp 0x17bc1
cmpl $0x0, 0x73ca8(%rip)     # 0x8b7e0
je 0x17b80
cmpl $0x2, -0x2c(%rbp)
jne 0x17b80
cmpl $0x2, 0x18(%rbp)
jne 0x17b80
movq 0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rdx
movslq (%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x40(%rax)
movq 0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rdx
movslq 0x4(%rdx), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x40(%rax)
jmp 0x17bc1
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x17bbf
movq 0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rdx
movslq -0x30(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x40(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x17b87
jmp 0x17bc1
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)