// File: /workspace/github_c_makefile_star2_O3/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, %r15
movl %ecx, %ebx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rdx
leaq 0x34(%rsp), %r13
movl %esi, (%r13)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rcx
callq 0x1f284
leaq 0x30(%rsp), %r12
movl %ebx, (%r12)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x1f284
leaq 0x393c3(%rip), %rdi     # 0x58472
callq 0x2090
leaq 0x392fd(%rip), %rdi     # 0x583b8
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x20f0
movslq (%r13), %rbx
movl (%r12), %ebp
leaq 0x39310(%rip), %rdi     # 0x583e5
movl %ebx, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x20f0
leaq 0x28(%rsp), %rax
movq (%rax), %rdi
leaq 0x20(%rsp), %rax
movq (%rax), %r14
testq %rbx, %rbx
jle 0x1f1e8
movslq %ebp, %rdx
xorl %eax, %eax
movswq (%rdi,%rax,2), %rcx
movzwl (%r15,%rcx,4), %ecx
movw %cx, (%rdi,%rax,2)
movswq (%r14,%rax,2), %rcx
movzwl (%r15,%rcx,4), %ecx
movw %cx, (%r14,%rax,2)
incq %rax
cmpq %rax, %rbx
jne 0x1f0fe
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %r15
testl %ebx, %ebx
jle 0x1f1fd
xorl %ecx, %ecx
xorl %esi, %esi
movl $0x0, 0x8(%rsp)
movzwl (%rdi,%rcx,2), %r8d
testw %r8w, %r8w
js 0x1f1d0
movzwl (%r14,%rcx,2), %r9d
testw %r9w, %r9w
js 0x1f1d0
cmpl %ebp, %esi
jge 0x1f183
movslq %esi, %r10
leaq (%r12,%r10,2), %rax
movq %rdx, %r11
subq %r10, %r11
xorl %r10d, %r10d
cmpw %r8w, (%rax,%r10,2)
jge 0x1f180
incq %r10
cmpq %r10, %r11
jne 0x1f16f
jmp 0x1f1b2
addl %r10d, %esi
cmpl %ebp, %esi
jge 0x1f1b9
movslq %esi, %r10
leaq (%r12,%r10,2), %r11
leaq (%r15,%r10,2), %r13
movq %rdx, %rax
subq %r10, %rax
xorl %r10d, %r10d
cmpw %r8w, (%r11,%r10,2)
jne 0x1f1b6
cmpw %r9w, (%r13,%r10,2)
jge 0x1f1b6
incq %r10
cmpq %r10, %rax
jne 0x1f19b
movl %ebp, %esi
jmp 0x1f1b9
addl %r10d, %esi
movslq %esi, %rax
cmpw (%r12,%rax,2), %r8w
jne 0x1f1d0
cmpw (%r15,%rax,2), %r9w
jne 0x1f1d0
incl 0x8(%rsp)
incl %esi
incq %rcx
cmpq %rbx, %rcx
jne 0x1f141
cvtsi2ssl 0x8(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
jmp 0x1f200
movq 0x18(%rsp), %r12
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x10(%rsp), %r15
jmp 0x1f206
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x2050
movq %r14, %rdi
callq 0x2050
movq %r12, %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2050
imull %ebx, %ebp
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
cvtss2sd %xmm0, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f241
sqrtsd %xmm0, %xmm0
jmp 0x1f246
callq 0x22a0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x8(%rsp)
cvtss2sd %xmm0, %xmm0
leaq 0x391aa(%rip), %rdi     # 0x58412
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