// File: /workspace/github_c_makefile_star2_O3/josch[P]stride/measure.c
// Function: Presnell
int Presnell(char *Asn1, int L1, char *Asn2, int L2, char SecStr, float Threshold, 
	     float *Q2, float *O)
{
  int Boundaries(char *Asn, int L, char SecondStr, int (*Bound)[2]);
  int Bound1[MAX_ASSIGN][2], Bound2[MAX_ASSIGN][2], Length1[MAX_ASSIGN], 
      Length2[MAX_ASSIGN], NSeg1, NSeg2;
  int Overlap, MaxOverlap, TP=0, FP=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++) {
      Overlap = Minimum(Bound1[i][1],Bound2[j][1])-Maximum(Bound1[i][0],Bound2[j][0])+1;
      if( Overlap > MaxOverlap ) MaxOverlap = Overlap;
    }
    if( (float)MaxOverlap/(float)Length1[i] >= Threshold ) 
      TP++;
    else
      FN++;
  }

  for(i=0; i<NSeg2; i++) {
    MaxOverlap = 0;
    for(j=0; j<NSeg1; j++) {
      Overlap = Minimum(Bound2[i][1],Bound1[j][1])-Maximum(Bound2[i][0],Bound1[j][0])+1;
      if( Overlap > MaxOverlap ) MaxOverlap = Overlap;
    }
    if( (float)MaxOverlap/(float)Length2[i] < Threshold ) 
      FP++;
  }

  if( TP+FN != 0 ) {
    *Q2 = (float)TP/((float)TP+(float)FN);
    *O = (float)FP/((float)TP+(float)FN);
  }
  else {
    *Q2 = -1.0;
    *O = -1.0;
  }

  return(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2ef8, %rsp           # imm = 0x2EF8
movq %r9, %rbx
movss %xmm0, 0xc(%rsp)
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, %r12
leaq 0xfb0(%rsp), %rcx
movl %r8d, %edx
callq 0x4f0a
movl %eax, %ebp
leaq 0x10(%rsp), %rcx
movq %r12, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x4f0a
movl %ebp, %ecx
testl %ebp, %ebp
jle 0x17887
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 0x17868
movl %eax, %edx
testl %eax, %eax
jle 0x178a8
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 0x1788f
testl %ebp, %ebp
movss 0xc(%rsp), %xmm2
jle 0x1793c
xorl %r8d, %r8d
xorl %esi, %esi
xorl %edi, %edi
testl %eax, %eax
jle 0x17912
movl 0xfb0(%rsp,%r8,8), %r9d
movl 0xfb4(%rsp,%r8,8), %r10d
xorl %r11d, %r11d
xorl %r14d, %r14d
movl 0x14(%rsp,%r11,8), %r15d
cmpl %r15d, %r10d
cmovll %r10d, %r15d
movl 0x10(%rsp,%r11,8), %r12d
cmpl %r12d, %r9d
cmovgl %r9d, %r12d
movl %r14d, %r13d
subl %r12d, %r15d
leal 0x1(%r15), %r14d
cmpl %r13d, %r15d
cmovll %r13d, %r14d
incq %r11
cmpq %r11, %rdx
jne 0x178d7
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
jmp 0x17915
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x2720(%rsp,%r8,4), %xmm1
divss %xmm1, %xmm0
ucomiss %xmm2, %xmm0
sbbl $-0x1, %edi
ucomiss %xmm2, %xmm0
adcl $0x0, %esi
incq %r8
cmpq %rcx, %r8
jne 0x178bd
jmp 0x17940
xorl %edi, %edi
xorl %esi, %esi
testl %eax, %eax
jle 0x179d4
xorl %eax, %eax
xorl %r8d, %r8d
testl %ebp, %ebp
jle 0x179a2
movl 0x10(%rsp,%rax,8), %r9d
movl 0x14(%rsp,%rax,8), %r10d
xorl %r11d, %r11d
xorl %r14d, %r14d
movl 0xfb4(%rsp,%r11,8), %r15d
cmpl %r15d, %r10d
cmovll %r10d, %r15d
movl 0xfb0(%rsp,%r11,8), %r12d
cmpl %r12d, %r9d
cmovgl %r9d, %r12d
movl %r14d, %r13d
subl %r12d, %r15d
leal 0x1(%r15), %r14d
cmpl %r13d, %r15d
cmovll %r13d, %r14d
incq %r11
cmpq %r11, %rcx
jne 0x17961
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
jmp 0x179a5
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x1f50(%rsp,%rax,4), %xmm1
divss %xmm1, %xmm0
xorl %r9d, %r9d
ucomiss %xmm0, %xmm2
seta %r9b
addl %r9d, %r8d
incq %rax
cmpq %rdx, %rax
jne 0x1794d
xorps %xmm1, %xmm1
cvtsi2ss %r8d, %xmm1
jmp 0x179d7
xorps %xmm1, %xmm1
movq 0x2f30(%rsp), %rax
movl %edi, %ecx
addl %esi, %ecx
jne 0x179ee
movaps 0x3554(%rip), %xmm0     # 0x1af40
jmp 0x17a0a
xorps %xmm0, %xmm0
cvtsi2ss %edi, %xmm0
xorps %xmm2, %xmm2
cvtsi2ss %esi, %xmm2
addss %xmm0, %xmm2
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
shufps $0x0, %xmm2, %xmm2      # xmm2 = xmm2[0,0,0,0]
divps %xmm2, %xmm0
movss %xmm0, (%rbx)
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss %xmm0, (%rax)
movl $0x1, %eax
addq $0x2ef8, %rsp           # imm = 0x2EF8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq