// File: /workspace/github_c_makefile_star2_O1/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 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 0x179d9
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 0x179ba
movl %eax, %edx
testl %eax, %eax
jle 0x179fa
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 0x179e1
testl %ebp, %ebp
movss 0xc(%rsp), %xmm2
jle 0x17a8e
xorl %r8d, %r8d
xorl %esi, %esi
xorl %edi, %edi
testl %eax, %eax
jle 0x17a64
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 0x17a29
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
jmp 0x17a67
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 0x17a0f
jmp 0x17a92
xorl %edi, %edi
xorl %esi, %esi
testl %eax, %eax
jle 0x17b26
xorl %eax, %eax
xorl %r8d, %r8d
testl %ebp, %ebp
jle 0x17af4
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 0x17ab3
xorps %xmm0, %xmm0
cvtsi2ss %r14d, %xmm0
jmp 0x17af7
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 0x17a9f
xorps %xmm0, %xmm0
cvtsi2ss %r8d, %xmm0
jmp 0x17b29
xorps %xmm0, %xmm0
movq 0x2f30(%rsp), %rax
movl %edi, %ecx
addl %esi, %ecx
jne 0x17b47
movl $0xbf800000, (%rbx)     # imm = 0xBF800000
movss 0x33ff(%rip), %xmm0     # 0x1af44
jmp 0x17b65
xorps %xmm1, %xmm1
cvtsi2ss %edi, %xmm1
xorps %xmm2, %xmm2
cvtsi2ss %esi, %xmm2
addss %xmm1, %xmm2
divss %xmm2, %xmm1
movss %xmm1, (%rbx)
divss %xmm2, %xmm0
movss %xmm0, (%rax)
movl $0x1, %eax
addq $0x2ef8, %rsp           # imm = 0x2EF8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq