// File: /workspace/github_c_makefile_star2_O2/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, %r12
movl %ecx, %ebx
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rdx
leaq 0xc(%rsp), %rcx
movl %esi, (%rcx)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x1d738
leaq 0x34(%rsp), %r14
movl %ebx, (%r14)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1d738
leaq 0x34e29(%rip), %rdi     # 0x523d2
callq 0x2090
leaq 0x34d63(%rip), %rdi     # 0x52318
xorl %r13d, %r13d
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x20f0
leaq 0xc(%rsp), %rax
movl (%rax), %ebx
movl (%r14), %ebp
movslq %ebp, %r14
leaq 0x34d6e(%rip), %rdi     # 0x52345
movl %ebx, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x20f0
leaq 0x28(%rsp), %rax
movq (%rax), %rdi
leaq 0x20(%rsp), %rax
movq (%rax), %r15
testl %ebx, %ebx
movl $0x0, %eax
movl %ebx, (%rsp)
cmovgl %ebx, %eax
cmpq %r13, %rax
je 0x1d628
movswq (%rdi,%r13,2), %rcx
movzwl (%r12,%rcx,4), %ecx
movw %cx, (%rdi,%r13,2)
movswq (%r15,%r13,2), %rcx
movzwl (%r12,%rcx,4), %ecx
movw %cx, (%r15,%r13,2)
incq %r13
jmp 0x1d600
movq 0x18(%rsp), %r13
xorl %ecx, %ecx
movq 0x10(%rsp), %r12
xorl %ebx, %ebx
xorl %edx, %edx
cmpq %rax, %rcx
je 0x1d6b5
movzwl (%rdi,%rcx,2), %esi
testw %si, %si
js 0x1d6b0
movzwl (%r15,%rcx,2), %r8d
testw %r8w, %r8w
js 0x1d6b0
movslq %edx, %r9
cmpl %ebp, %r9d
movl %ebp, %edx
cmovgl %r9d, %edx
cmpq %r14, %r9
jge 0x1d672
cmpw %si, (%r13,%r9,2)
jge 0x1d66f
incq %r9
jmp 0x1d65d
movl %r9d, %edx
movslq %edx, %rdx
cmpl %ebp, %edx
movl %ebp, %r9d
cmovgl %edx, %r9d
cmpq %r14, %rdx
jge 0x1d697
cmpw %si, (%r13,%rdx,2)
jne 0x1d69a
cmpw %r8w, (%r12,%rdx,2)
jge 0x1d69a
incq %rdx
jmp 0x1d67e
movl %r9d, %edx
movslq %edx, %r9
cmpw (%r13,%r9,2), %si
jne 0x1d6b0
cmpw (%r12,%r9,2), %r8w
jne 0x1d6b0
incl %ebx
incl %edx
incq %rcx
jmp 0x1d638
callq 0x2050
movq %r15, %rdi
callq 0x2050
movq %r13, %rdi
callq 0x2050
movq %r12, %rdi
callq 0x2050
cvtsi2ss %ebx, %xmm0
cvtss2sd %xmm0, %xmm2
imull (%rsp), %ebp
cvtsi2ss %ebp, %xmm0
cvtss2sd %xmm0, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1d6f6
sqrtsd %xmm0, %xmm0
jmp 0x1d705
movsd %xmm2, (%rsp)
callq 0x2290
movsd (%rsp), %xmm2
divsd %xmm0, %xmm2
cvtsd2ss %xmm2, %xmm0
movss %xmm0, (%rsp)
cvtss2sd %xmm0, %xmm0
leaq 0x34c55(%rip), %rdi     # 0x52372
movb $0x1, %al
callq 0x20f0
movss (%rsp), %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq