// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/condenseq.c
// Function: gt_condenseq_each_redundant_range
GtUword gt_condenseq_each_redundant_range(
                                      const GtCondenseq *condenseq,
                                      GtUword uid,
                                      GtRange urange,
                                      GtUword left_extend,
                                      GtUword right_extend,
                                      GtCondenseqProcessExtractedRange callback,
                                      void *callback_data,
                                      GtError *err)
{
  int had_err = 0;
  GtUword num_ranges = (GtUword) 1,
          linkidx,
          orig_seqnum,
          orig_seqstart,
          orig_seqend;
  const GtCondenseqUnique *unique;
  GtRange extract;

  gt_assert(condenseq != NULL);
  gt_assert(uid < condenseq->uds_nelems);
  gt_assert(urange.start <= urange.end);

  unique = &condenseq->uniques[uid];

  /* handle unique itself */
  orig_seqnum = gt_condenseq_pos2seqnum(condenseq, unique->orig_startpos);
  orig_seqstart = gt_condenseq_seqstartpos(condenseq, orig_seqnum);
  orig_seqend = orig_seqstart + condenseq_seqlength_help(condenseq, orig_seqnum,
                                                         orig_seqstart) - 1;
  extract.start = unique->orig_startpos + urange.start;
  extract.start = extract.start < left_extend ?
    0 : extract.start - left_extend;
  extract.start = extract.start < orig_seqstart ?
    orig_seqstart : extract.start;
  extract.end = unique->orig_startpos + urange.end + right_extend;
  extract.end = extract.end > orig_seqend ?
    orig_seqend : extract.end;

  gt_assert(extract.start <= extract.end);
  had_err = callback(callback_data, orig_seqnum, extract, err);

  for (linkidx = 0;
       !had_err && linkidx < unique->links.nextfreeuint32_t;
       ++linkidx) {
    const GtCondenseqLink *link =
      &condenseq->links[unique->links.spaceuint32_t[linkidx]];

    /* the second part is a little heuristic, the len of the link could be
       completely comprised of insertions, which would place it downstream of
       urange.start. But we assume ~ similar lengths for links and their unique
       counterpart */
    if (!(urange.end < link->unique_offset ||
        urange.start > link->unique_offset + link->len - 1)) {
      GtUword shift;
      orig_seqnum = gt_condenseq_pos2seqnum(condenseq, link->orig_startpos);
      orig_seqstart = gt_condenseq_seqstartpos(condenseq, orig_seqnum);
      orig_seqend = orig_seqstart + condenseq_seqlength_help(condenseq,
                                                             orig_seqnum,
                                                             orig_seqstart) - 1;
      extract.start = link->orig_startpos < left_extend ?
        0 : link->orig_startpos - left_extend;
      if (urange.start < link->unique_offset) {
        shift = link->unique_offset - urange.start;
        extract.start = extract.start < shift ?
          0 : extract.start - shift;
      }
      else {
        shift = urange.start - link->unique_offset;
        extract.start += shift;
      }
      extract.start = extract.start < orig_seqstart ?
        orig_seqstart : extract.start;
      /* see heuristic note above */
      extract.end = link->orig_startpos + right_extend + link->len;
      if (urange.end < link->unique_offset + link->len - 1) {
        shift = (link->unique_offset + link->len - 1) - urange.end;
        extract.end = extract.end < shift ?
          0 : extract.end - shift;
      }
      else {
        shift = urange.end - (link->unique_offset + link->len - 1);
        extract.end += shift;
      }
      extract.end = extract.end > orig_seqend ?
        orig_seqend : extract.end;
      gt_assert(extract.start <= extract.end);
      had_err = callback(callback_data, orig_seqnum, extract, err);
      num_ranges++;
    }
  }

  if (!had_err)
    return num_ranges;
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x10(%rsp)
testq %rdi, %rdi
je 0xc320d
movq %rdi, %r13
cmpq %rsi, 0x98(%rdi)
jbe 0xc323e
cmpq %rcx, %rdx
movq %rcx, 0x8(%rsp)
ja 0xc326c
movq %rdx, %r12
movq 0x10(%r13), %rbp
imulq $0x28, %rsi, %r15
movq 0x18(%rbp,%r15), %rsi
movq %r13, %rdi
callq 0xc1180
movq %rax, %rbx
movq %r13, %rdi
movq %rax, %rsi
callq 0xc1196
movq %rax, %r14
movq %r13, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xc11d4
movq 0x18(%rbp,%r15), %rsi
movq %r12, (%rsp)
leaq (%rsi,%r12), %rcx
xorl %edx, %edx
subq 0x10(%rsp), %rcx
cmovaeq %rcx, %rdx
cmpq %r14, %rdx
cmovbeq %r14, %rdx
leaq -0x1(%r14,%rax), %rax
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %r14
addq %r14, %rcx
addq %rsi, %rcx
cmpq %rax, %rcx
cmovaeq %rax, %rcx
cmpq %rcx, %rdx
ja 0xc329a
movq 0x70(%rsp), %r8
movq 0x68(%rsp), %rdi
addq %r15, %rbp
movq %rbx, %rsi
callq *0x60(%rsp)
pushq $0x1
popq %rdi
xorl %r12d, %r12d
movq (%rsp), %rsi
testl %eax, %eax
jne 0xc31c8
cmpq 0x10(%rbp), %r12
jae 0xc31ca
movq 0x8(%r13), %r15
movq (%rbp), %rax
movl (%rax,%r12,4), %edx
shlq $0x5, %rdx
movl 0x18(%r15,%rdx), %ecx
xorl %eax, %eax
cmpq %r14, %rcx
ja 0xc31c0
addq %rdx, %r15
movl 0x10(%r15), %edx
addl %edx, %ecx
decl %ecx
cmpq %rsi, %rcx
jb 0xc31c0
movq %rdi, 0x20(%rsp)
movq 0x8(%r15), %rsi
movq %r13, %rdi
callq 0xc1180
movq %rax, %rbx
movq %r13, %rdi
movq %rax, %rsi
callq 0xc1196
movq %rax, %r14
movq %r13, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xc11d4
movq (%rsp), %r8
movq 0x8(%r15), %rcx
movq %rcx, %rdx
subq 0x10(%rsp), %rdx
movl $0x0, %edi
cmovaeq %rdx, %rdi
movl 0x18(%r15), %esi
movq %rsi, %rdx
subq %r8, %rdx
jbe 0xc3147
subq %rdx, %rdi
movl $0x0, %edx
cmovaeq %rdi, %rdx
jmp 0xc3150
addq %r8, %rdi
subq %rsi, %rdi
movq %rdi, %rdx
cmpq %r14, %rdx
cmovbeq %r14, %rdx
addq 0x18(%rsp), %rcx
movl 0x10(%r15), %edi
addq %rdi, %rcx
addl %esi, %edi
decl %edi
movq %rdi, %rsi
movq 0x8(%rsp), %r8
subq %r8, %rsi
jbe 0xc3182
subq %rsi, %rcx
movl $0x0, %esi
cmovaeq %rcx, %rsi
jmp 0xc318b
movq %r8, %rsi
subq %rdi, %rsi
addq %rcx, %rsi
leaq (%r14,%rax), %rcx
decq %rcx
cmpq %rcx, %rsi
cmovbq %rsi, %rcx
cmpq %rcx, %rdx
ja 0xc31dc
movq 0x68(%rsp), %rdi
movq %rbx, %rsi
movq 0x70(%rsp), %r8
callq *0x60(%rsp)
movq 0x20(%rsp), %rdi
incq %rdi
movq 0x8(%rsp), %r14
movq (%rsp), %rsi
incq %r12
jmp 0xc309e
xorl %edi, %edi
movq %rdi, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x374d85(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x221e26(%rip), %rsi    # 0x2e5013
leaq 0x2563f0(%rip), %rdx    # 0x3195e4
leaq 0x2563ac(%rip), %rcx    # 0x3195a7
leaq 0x255d72(%rip), %r8     # 0x318f74
movl $0x3fa, %r9d            # imm = 0x3FA
jmp 0xc32c6
movq 0x374d54(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x221df5(%rip), %rsi    # 0x2e5013
leaq 0x255d24(%rip), %rdx    # 0x318f49
leaq 0x25637b(%rip), %rcx    # 0x3195a7
leaq 0x255d41(%rip), %r8     # 0x318f74
movl $0x3b7, %r9d            # imm = 0x3B7
jmp 0xc32c6
movq 0x374d23(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x221dc4(%rip), %rsi    # 0x2e5013
leaq 0x2560ed(%rip), %rdx    # 0x319343
leaq 0x25634a(%rip), %rcx    # 0x3195a7
leaq 0x255d10(%rip), %r8     # 0x318f74
movl $0x3b8, %r9d            # imm = 0x3B8
jmp 0xc32c6
movq 0x374cf5(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x221d96(%rip), %rsi    # 0x2e5013
leaq 0x256345(%rip), %rdx    # 0x3195c9
leaq 0x25631c(%rip), %rcx    # 0x3195a7
leaq 0x255ce2(%rip), %r8     # 0x318f74
movl $0x3b9, %r9d            # imm = 0x3B9
jmp 0xc32c6
movq 0x374cc7(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x221d68(%rip), %rsi    # 0x2e5013
leaq 0x256332(%rip), %rdx    # 0x3195e4
leaq 0x2562ee(%rip), %rcx    # 0x3195a7
leaq 0x255cb4(%rip), %r8     # 0x318f74
movl $0x3cb, %r9d            # imm = 0x3CB
xorl %eax, %eax
callq 0x17a50
callq 0x17390