// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/consensus_sa.c
// Function: compatible
static bool compatible(const ConsensusSA *csa,
                       GtUword sa_1, GtUword sa_2)
{
  GtArray *exons_sa_1, *exons_sa_2;
  GtRange range_sa_1, range_sa_2;
  GtUword i, j, num_of_exons_1, num_of_exons_2,
                start_1 = GT_UNDEF_UWORD, start_2 = GT_UNDEF_UWORD;
  bool start_values_set = false;
  const GtUword fuzzlength = 0; /* XXX */

  gt_assert(csa);

  /* check strands */
  if (extract_strand(csa, sa_1) != extract_strand(csa, sa_2)) return false;

  /* init */
  exons_sa_1 = gt_array_new(sizeof (GtRange));
  exons_sa_2 = gt_array_new(sizeof (GtRange));

  /* get ranges */
  range_sa_1 = extract_genomic_range(csa, sa_1);
  range_sa_2 = extract_genomic_range(csa, sa_2);

  if (!gt_range_overlap(&range_sa_1, &range_sa_2)) {
    gt_array_delete(exons_sa_1);
    gt_array_delete(exons_sa_2);
    return false;
  }

  /* get exons */
  extract_exons(csa, exons_sa_1, sa_1);
  extract_exons(csa, exons_sa_2, sa_2);

  /* determine the first overlapping exon pair */
  i = 0;
  j = 0;
  num_of_exons_1 = gt_array_size(exons_sa_1);
  num_of_exons_2 = gt_array_size(exons_sa_2);
  while (i < num_of_exons_1 && j < num_of_exons_2) {
    if (gt_range_overlap(gt_array_get(exons_sa_1, i),
                         gt_array_get(exons_sa_2, j))) {
      start_1 = i;
      start_2 = j;
      start_values_set = true;
      break;
    }
    if (((GtRange*) gt_array_get(exons_sa_1, i))->start <
        ((GtRange*) gt_array_get(exons_sa_2, j))->start) {
      i++;
    }
    else
      j++;
  }
  if (!start_values_set) {
    gt_array_delete(exons_sa_1);
    gt_array_delete(exons_sa_2);
    return false;
  }
  /* from now on the start values are set */

  gt_assert(start_1 != GT_UNDEF_UWORD && start_2 != GT_UNDEF_UWORD);
  if (!(start_1 == 0 || start_2 == 0)) {
    /* no first segment could be maped */
    gt_array_delete(exons_sa_1);
    gt_array_delete(exons_sa_2);
    return false;
  }

  while (start_1 < num_of_exons_1 && start_2 < num_of_exons_2) {
    range_sa_1 = *((GtRange*) gt_array_get(exons_sa_1, start_1));
    range_sa_2 = *((GtRange*) gt_array_get(exons_sa_2, start_2));

    if (gt_range_overlap(&range_sa_1, &range_sa_2)) {
      /* analyze acceptor sites */

      /* see if at least one exon has a acceptor site (on the left).
         in this case additional checks have to be performed.
         Otherwise, this exons are compatible (on the left side)
         because they overlap */
      if (has_acceptor_site(exons_sa_1, start_1) ||
          has_acceptor_site(exons_sa_2, start_2)) {
        if (has_acceptor_site(exons_sa_1, start_1) &&
            has_acceptor_site(exons_sa_2, start_2) &&
            range_sa_1.start!= range_sa_2.start) {
          /* the acceptor sites are different */
          gt_array_delete(exons_sa_1);
          gt_array_delete(exons_sa_2);
          return false;
        }
        else if (has_acceptor_site(exons_sa_1, start_1) &&
                 range_sa_2.start + fuzzlength < range_sa_1.start) {
          /* not within fuzzlength */
          gt_array_delete(exons_sa_1);
          gt_array_delete(exons_sa_2);
          return false;
        }
        else if (has_acceptor_site(exons_sa_2, start_2) &&
                 range_sa_1.start + fuzzlength < range_sa_2.start) {
          /* not within fuzzlength */
          gt_array_delete(exons_sa_1);
          gt_array_delete(exons_sa_2);
          return false;
        }
      }
      /* analyze donor sites */

      /* see if at least one exon has a donor site (on the right).
         in this case additional checks have to be performed.
         Otherwise, this exons are compatible (on the right side)
         because they overlap */
      if (has_donor_site(exons_sa_1, start_1) ||
          has_donor_site(exons_sa_2, start_2)) {
        if (has_donor_site(exons_sa_1, start_1) &&
            has_donor_site(exons_sa_2, start_2) &&
            range_sa_1.end != range_sa_2.end) {
          /* the donor sites are different */
          gt_array_delete(exons_sa_1);
          gt_array_delete(exons_sa_2);
          return false;
        }
        else if (has_donor_site(exons_sa_1, start_1) &&
                 range_sa_2.end - fuzzlength > range_sa_1.end) {
          /* not within fuzzlength */
          gt_array_delete(exons_sa_1);
          gt_array_delete(exons_sa_2);
          return false;
        }
        else if (has_donor_site(exons_sa_2, start_2) &&
                 range_sa_1.end - fuzzlength > range_sa_2.end) {
          /* not within fuzzlength */
          gt_array_delete(exons_sa_1);
          gt_array_delete(exons_sa_2);
          return false;
        }
      }
    }
    else {
      /* no overlap: two ordered segments do not overlap each other */
      gt_array_delete(exons_sa_1);
      gt_array_delete(exons_sa_2);
      return false;
    }
    start_1++;
    start_2++;
  }

  /* passed all tests */
  gt_array_delete(exons_sa_1);
  gt_array_delete(exons_sa_2);
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r12
callq 0xc997c
movl %eax, %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0xc997c
cmpl %eax, %ebx
jne 0xc97d6
pushq $0x10
popq %r14
movq %r14, %rdi
callq 0x4b380
movq %rax, %rbx
movq %r14, %rdi
callq 0x4b380
movq %rax, %r14
movq %r12, %rdi
movq %r13, %rsi
callq 0xc9657
leaq 0x10(%rsp), %rbp
movq %rax, (%rbp)
movq %rdx, 0x8(%rbp)
movq %r12, %rdi
movq %r15, %rsi
callq 0xc9657
movq %rsp, %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq %rbp, %rdi
callq 0x5d0a4
testb %al, %al
je 0xc9957
movq %r12, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0xc9a00
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xc9a00
movq %rbx, %rdi
callq 0x4b988
movq %rax, 0x20(%rsp)
movq %r14, %rdi
callq 0x4b988
movq %rax, %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpq 0x20(%rsp), %rbp
jae 0xc995a
cmpq %r12, %r13
jae 0xc995a
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4b48e
movq %rax, %r15
movq %r14, %rdi
movq %r13, %rsi
callq 0x4b48e
movq %r15, %rdi
movq %rax, %rsi
callq 0x5d0a4
testb %al, %al
jne 0xc97de
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4b48e
movq (%rax), %r15
movq %r14, %rdi
movq %r13, %rsi
callq 0x4b48e
movq (%rax), %rax
cmpq %rax, %r15
sbbq $-0x1, %r13
cmpq %rax, %r15
adcq $0x0, %rbp
jmp 0xc976b
xorl %r15d, %r15d
jmp 0xc996a
testq %rbp, %rbp
sete %al
testq %r13, %r13
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xc9957
cmpq 0x20(%rsp), %rbp
setae %al
cmpq %r12, %r13
setae %r15b
orb %al, %r15b
jne 0xc995a
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4b48e
movups (%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4b48e
movups (%rax), %xmm0
movaps %xmm0, (%rsp)
leaq 0x10(%rsp), %rdi
movq %rsp, %rsi
callq 0x5d0a4
testb %al, %al
je 0xc995a
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc9acd
testb %al, %al
jne 0xc9865
movq %r14, %rdi
movq %r13, %rsi
callq 0xc9acd
testb %al, %al
je 0xc98ce
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc9acd
testb %al, %al
je 0xc9892
movq %r14, %rdi
movq %r13, %rsi
callq 0xc9acd
testb %al, %al
je 0xc9892
movq 0x10(%rsp), %rax
cmpq (%rsp), %rax
jne 0xc995a
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc9acd
testb %al, %al
je 0xc98b0
movq (%rsp), %rax
cmpq 0x10(%rsp), %rax
jb 0xc995a
movq %r14, %rdi
movq %r13, %rsi
callq 0xc9acd
testb %al, %al
je 0xc98ce
movq 0x10(%rsp), %rax
cmpq (%rsp), %rax
jb 0xc995a
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc9b19
testb %al, %al
jne 0xc98ec
movq %r14, %rdi
movq %r13, %rsi
callq 0xc9b19
testb %al, %al
je 0xc994c
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc9b19
testb %al, %al
je 0xc9916
movq %r14, %rdi
movq %r13, %rsi
callq 0xc9b19
testb %al, %al
je 0xc9916
movq 0x18(%rsp), %rax
cmpq 0x8(%rsp), %rax
jne 0xc995a
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc9b19
testb %al, %al
je 0xc9931
movq 0x8(%rsp), %rax
cmpq 0x18(%rsp), %rax
ja 0xc995a
movq %r14, %rdi
movq %r13, %rsi
callq 0xc9b19
testb %al, %al
je 0xc994c
movq 0x18(%rsp), %rax
cmpq 0x8(%rsp), %rax
ja 0xc995a
incq %rbp
incq %r13
jmp 0xc97f5
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x4c19d
movq %r14, %rdi
callq 0x4c19d
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq