// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/contacts.c
// Function: Contact_overlap
float Contact_overlap(struct interaction *Int_list1, int N_int1,
		      struct interaction *Int_list2, int N_int2, int *alires)
{
  // Make contact matrix 1
  short *cont1_i, *cont1_j; int Nc1=N_int1;
  Write_contact_list(&cont1_i, &cont1_j, Int_list1, &Nc1);
  short *cont2_i, *cont2_j; int Nc2=N_int2;
  Write_contact_list(&cont2_i, &cont2_j, Int_list2, &Nc2);
  printf("Computing contact overlap\n");
  printf("Initial number of contacts: PDB1 %d PDB2 %d\n", N_int1, N_int2);
  printf("After identifying residues: PDB1 %d PDB2 %d\n", Nc1, Nc2);
  int k;
  for(k=0; k<Nc1; k++){
    cont1_i[k]=alires[cont1_i[k]];
    cont1_j[k]=alires[cont1_j[k]];
  }
  int overlap=0, k2=0;
  for(k=0; k<Nc1; k++){
    if((cont1_i[k]<0)||(cont1_j[k]<0))continue;
    while((k2<Nc2)&&(cont2_i[k2] < cont1_i[k]))k2++;
    while((k2<Nc2)&&(cont2_i[k2]== cont1_i[k])&&
	  (cont2_j[k2] < cont1_j[k]))k2++;
    if((cont1_i[k]==cont2_i[k2])&&(cont1_j[k]==cont2_j[k2])){
      overlap++; k2++;
    }
  }
  free(cont1_i);free(cont1_j); //modyves: was never freed
  free(cont2_i);free(cont2_j); //modyves: was never freed
  float q=(float)overlap/sqrt((float)(Nc1*Nc2));
  printf("Contact overlap: %.3f\n", q);
  return(q);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r14
movl %ecx, %ebx
movq %rdx, %r12
movl %esi, %ebp
movq %rdi, %rdx
leaq 0x34(%rsp), %r15
movl %esi, (%r15)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r15, %rcx
callq 0x1f9e9
leaq 0x30(%rsp), %r13
movl %ebx, (%r13)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1f9e9
leaq 0x38c9c(%rip), %rdi     # 0x584b2
callq 0x2090
leaq 0x38bd6(%rip), %rdi     # 0x583f8
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x20f0
movslq (%r15), %rbx
movl (%r13), %ebp
leaq 0x38bea(%rip), %rdi     # 0x58425
movl %ebx, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
testq %rbx, %rbx
jle 0x1f87b
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
xorl %edx, %edx
movswq (%rax,%rdx,2), %rsi
movzwl (%r14,%rsi,4), %esi
movw %si, (%rax,%rdx,2)
movswq (%rcx,%rdx,2), %rsi
movzwl (%r14,%rsi,4), %esi
movw %si, (%rcx,%rdx,2)
incq %rdx
cmpq %rdx, %rbx
jne 0x1f857
xorps %xmm0, %xmm0
testl %ebx, %ebx
jle 0x1f95a
movslq %ebp, %r9
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
xorl %r8d, %r8d
xorl %r10d, %r10d
movl $0x0, 0x8(%rsp)
movzwl (%rcx,%r8,2), %r11d
testw %r11w, %r11w
js 0x1f941
movzwl (%rdx,%r8,2), %r14d
testw %r14w, %r14w
js 0x1f941
cmpl %ebp, %r10d
jge 0x1f8f1
movslq %r10d, %r15
leaq (%rsi,%r15,2), %rax
movq %r9, %r12
subq %r15, %r12
xorl %r15d, %r15d
cmpw %r11w, (%rax,%r15,2)
jge 0x1f8ee
incq %r15
cmpq %r15, %r12
jne 0x1f8da
movl %ebp, %r10d
jmp 0x1f8f1
addl %r15d, %r10d
cmpl %ebp, %r10d
jge 0x1f929
movslq %r10d, %r15
leaq (%rsi,%r15,2), %r12
leaq (%rdi,%r15,2), %r13
movq %r9, %rax
subq %r15, %rax
xorl %r15d, %r15d
cmpw %r11w, (%r12,%r15,2)
jne 0x1f926
cmpw %r14w, (%r13,%r15,2)
jge 0x1f926
incq %r15
cmpq %r15, %rax
jne 0x1f90a
movl %ebp, %r10d
jmp 0x1f929
addl %r15d, %r10d
movslq %r10d, %rax
cmpw (%rsi,%rax,2), %r11w
jne 0x1f941
cmpw (%rdi,%rax,2), %r14w
jne 0x1f941
incl 0x8(%rsp)
incl %r10d
incq %r8
cmpq %rbx, %r8
jne 0x1f8ab
xorps %xmm0, %xmm0
cvtsi2ssl 0x8(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %rdi
callq 0x2050
movq 0x10(%rsp), %rdi
callq 0x2050
movq 0x28(%rsp), %rdi
callq 0x2050
movq 0x20(%rsp), %rdi
callq 0x2050
imull %ebx, %ebp
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd 0x316c2(%rip), %xmm0    # 0x51060
jb 0x1f9a6
sqrtsd %xmm0, %xmm0
jmp 0x1f9ab
callq 0x2290
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x8(%rsp)
cvtss2sd %xmm0, %xmm0
leaq 0x38a85(%rip), %rdi     # 0x58452
movb $0x1, %al
callq 0x20f0
movss 0x8(%rsp), %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq