// File: /workspace/github_c_makefile_star2_O1/josch[P]stride/measure.c
// Function: Sov
int Sov(char *Asn1, int L1, char *Asn2, int L2, char SecStr, float Threshold, float *Q2)
{
  int Bound1[MAX_ASSIGN][2], Bound2[MAX_ASSIGN][2], Length1[MAX_ASSIGN], 
      Length2[MAX_ASSIGN], NSeg1, NSeg2;
  int Overlap, MaxOverlap, TP=0, FN=0;
  register int i, j;

  NSeg1 = Boundaries(Asn1,L1,SecStr,Bound1);
  NSeg2 = Boundaries(Asn2,L2,SecStr,Bound2);
  

  for(i=0; i<NSeg1; i++)
    Length1[i] = Bound1[i][1]-Bound1[i][0]+1;

  for(j=0; j<NSeg2; j++)
    Length2[j] = Bound2[j][1]-Bound2[j][0]+1;
									    
  for(i=0; i<NSeg1; i++) {
    MaxOverlap = 0;
    for(j=0; j<NSeg2; j++) {
      
      if( Bound1[i][0] > Bound2[j][1] || Bound1[i][1] < Bound2[j][0] ) /*No overlap */
	Overlap = 0;
      else if ( Bound2[j][0] >= Bound1[i][0] && Bound2[j][1] <= Bound1[i][1] ) /* j inside i */
	Overlap = Length2[j];
      else if ( Bound1[i][0] <= Bound2[j][0] ) /* j shifted to the right with respect to i */ 
	Overlap = Minimum(Bound2[j][1]-Bound2[j][0],Bound1[i][1]-Bound2[j][0])+1;
      else if( Bound1[i][0] >= Bound2[j][0] ) /* i shifted to the right with respect to j */
	Overlap = Minimum(Bound2[j][1]-Bound2[j][0],Bound2[j][1]-Bound1[i][0])+1;
      else
	Overlap = Length1[i]; /* i inside j */
      if( Overlap > MaxOverlap ) MaxOverlap = Overlap;
    }
    if( (float)MaxOverlap/(float)Length1[i] >= Threshold ) 
      TP++;
    else
      FN++;
  }
  if( TP+FN != 0 )
    *Q2 = (float)TP/((float)TP+(float)FN);
  else
    *Q2 = -1.0;
/*  O  = (float)TP/((float)TP+(float)FN);*/
  return(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2ef8, %rsp           # imm = 0x2EF8
movq %r9, 0x8(%rsp)
movss %xmm0, 0x4(%rsp)
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, %r12
leaq 0xfb0(%rsp), %rcx
movl %r8d, %edx
callq 0x4fe2
movl %eax, %ebp
leaq 0x10(%rsp), %rcx
movq %r12, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x4fe2
movl %ebp, %ecx
testl %ebp, %ebp
jle 0x17bf1
xorl %edx, %edx
movl 0xfb4(%rsp,%rdx,8), %esi
subl 0xfb0(%rsp,%rdx,8), %esi
incl %esi
movl %esi, 0x2720(%rsp,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x17bd2
movl %eax, %edx
testl %eax, %eax
jle 0x17c12
xorl %esi, %esi
movl 0x14(%rsp,%rsi,8), %edi
subl 0x10(%rsp,%rsi,8), %edi
incl %edi
movl %edi, 0x1f50(%rsp,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x17bf9
testl %ebp, %ebp
movss 0x4(%rsp), %xmm2
jle 0x17ce2
xorl %r8d, %r8d
xorl %edi, %edi
xorl %esi, %esi
testl %eax, %eax
jle 0x17cb4
movl 0xfb0(%rsp,%r8,8), %r9d
xorl %r10d, %r10d
xorl %r11d, %r11d
movl 0x14(%rsp,%r10,8), %ebp
movl %ebp, %r14d
movl $0x0, %r13d
subl %r9d, %r14d
jl 0x17c9b
movl 0xfb4(%rsp,%r8,8), %r15d
movl 0x10(%rsp,%r10,8), %r12d
cmpl %r12d, %r15d
jl 0x17c9b
cmpl %r9d, %r12d
setl %r13b
cmpl %r15d, %ebp
setg %bl
orb %r13b, %bl
je 0x17c81
cmpl %r9d, %r12d
jge 0x17c8b
incl %r14d
movl %r14d, %r13d
jmp 0x17c9b
movl 0x1f50(%rsp,%r10,4), %r13d
jmp 0x17c9b
cmpl %r15d, %ebp
cmovll %ebp, %r15d
subl %r12d, %r15d
incl %r15d
movl %r15d, %r13d
cmpl %r11d, %r13d
cmovgl %r13d, %r11d
incq %r10
cmpq %r10, %rdx
jne 0x17c3d
xorps %xmm0, %xmm0
cvtsi2ss %r11d, %xmm0
jmp 0x17cb7
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x2720(%rsp,%r8,4), %xmm1
divss %xmm1, %xmm0
ucomiss %xmm2, %xmm0
sbbl $-0x1, %esi
ucomiss %xmm2, %xmm0
adcl $0x0, %edi
incq %r8
cmpq %rcx, %r8
jne 0x17c27
jmp 0x17ce6
xorl %esi, %esi
xorl %edi, %edi
movl %esi, %eax
addl %edi, %eax
je 0x17d04
xorps %xmm0, %xmm0
cvtsi2ss %esi, %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %edi, %xmm1
addss %xmm0, %xmm1
divss %xmm1, %xmm0
jmp 0x17d0c
movss 0x3238(%rip), %xmm0     # 0x1af44
movq 0x8(%rsp), %rax
movss %xmm0, (%rax)
movl $0x1, %eax
addq $0x2ef8, %rsp           # imm = 0x2EF8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq