// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/extended/condenseq_creator.c
// Function: ces_c_extend_seeds_window
static int ces_c_extend_seeds_window(GtCondenseqCreator *ces_c,
                                     GtCondenseqLink *best_link,
                                     GtError *err)
{
  int had_err = 0;
  GtRange query_bounds,
          subject_bounds;
  GtKmerStartpos match_positions;
  GtCondenseqCreatorWindow *win = &ces_c->window;
  GtCondenseqCreatorXdrop *xdrop = &ces_c->xdrop;
  GtUword best_match = GT_UNDEF_UWORD,
          idx_cur,
          querypos = ces_c->main_pos - ces_c->windowsize + 1;
  const unsigned int max_win_idx = ces_c->windowsize - 1;
  unsigned int idx_win;
  GtXdropbest empty = {0,0,0,0,0};
  const bool forward = true;
  subject_bounds.end =
    subject_bounds.start = 0;

  *xdrop->left = empty;
  *xdrop->right = empty;

  match_positions = win->pos_arrs[GT_CONDENSEQ_CREATOR_WINDOWIDX(win, 0)];

  /* nothing there or window not full */
  if (match_positions.no_positions == 0 ||
      ces_c->window.count != ces_c->windowsize)
    return had_err;

  /* get bounds for current, .end is exclusive */
  query_bounds.start = ces_c->current_orig_start;
  query_bounds.end = ces_c->current_seq_start + ces_c->current_seq_len;
  gt_assert(query_bounds.start <= querypos);
  if (!(querypos <= query_bounds.end - ces_c->windowsize)) {
    gt_error_set(err, "querypos: " GT_WU ", not smaller end (" GT_WU
                 ") - windowsize (%u) (xdrop calls: " GT_WU " )",
                 querypos,
                 query_bounds.end,
                 ces_c->windowsize,
                 ces_c_xdrops);
    had_err = -1;
  }

  if (!had_err) {
    for (idx_win = 0; idx_win <= max_win_idx; idx_win++) {
      win->idxs[idx_win] = 0;
    }

    if (query_bounds.start < querypos) {
      gt_seqabstract_reinit_encseq(!forward,
                                   GT_READMODE_FORWARD,
                                   xdrop->current_seq_bwd,
                                   ces_c->input_es,
                                   querypos - query_bounds.start,
                                   query_bounds.start);
    }
    if (querypos < query_bounds.end) {
      gt_seqabstract_reinit_encseq(forward,
                                   GT_READMODE_FORWARD,
                                   xdrop->current_seq_fwd,
                                   ces_c->input_es,
                                   query_bounds.end - querypos,
                                   querypos);
    }
  }

  /* iterate over all known match_positions of left kmer */
  for (idx_cur = 0;
       !had_err && idx_cur < match_positions.no_positions;
       idx_cur++)
  {
    bool found = false;
    GtUword subjectpos = match_positions.startpos[idx_cur],
            new_uid = match_positions.unique_ids[idx_cur];
    /* end == subjectpos should not be possible as this would be a separator */
    if (subject_bounds.end <= subjectpos || subject_bounds.end == 0) {
      gt_assert(new_uid != ces_c->ces->uds_nelems);
      subject_bounds.start = ces_c->ces->uniques[new_uid].orig_startpos;
      subject_bounds.end = subject_bounds.start +
        ces_c->ces->uniques[new_uid].len;
      gt_assert(subject_bounds.start <= subjectpos &&
                subjectpos + ces_c->kmersize <= subject_bounds.end);
    }
    /* check if new position is already covered by current best alignment */
    if (best_match == GT_UNDEF_UWORD ||
        /* ivalue is a length (within unique) -> best + ivalue is outside of
           best alignment */
        subjectpos >= best_match + xdrop->right->ivalue) {
      /* start with search for right hit at end of window */
      for (idx_win = ces_c->windowsize - 1;
           !had_err && !found && idx_win >= ces_c->kmersize;
           idx_win--) {
        GtKmerStartpos j_primes;
        j_primes.startpos =
          win->pos_arrs[GT_CONDENSEQ_CREATOR_WINDOWIDX(win, idx_win)].startpos;
        j_primes.no_positions =
          win->pos_arrs[GT_CONDENSEQ_CREATOR_WINDOWIDX(win,
                                                       idx_win)].no_positions;
        /* If 0, there are no known match_positions for kmer at this window
           position. */
        if (j_primes.no_positions != 0) {
          GtUword j_prime_idx = win->idxs[idx_win],
                  j_prime = j_primes.startpos[j_prime_idx];
          /* advance to at least the window */
          while (j_prime_idx < j_primes.no_positions &&
                 subjectpos + ces_c->kmersize - 1 > j_prime) {
            j_prime_idx++;
            j_prime = j_primes.startpos[j_prime_idx];
          }
          /* hit within window? */
          if (j_prime_idx < j_primes.no_positions &&
              subjectpos + ces_c->windowsize > j_prime) {
            found = true;
            had_err = ces_c_xdrop(ces_c,
                                  subjectpos, querypos,
                                  query_bounds,
                                  subject_bounds,
                                  new_uid,
                                  best_link,
                                  &best_match,
                                  err);
          }
          /* within each position array, remember last highest position, start
             there, because subjectpos increases each iteration */
          win->idxs[idx_win] = j_prime_idx;
        }
      }
    }
  }

  if (!had_err) {
    if (best_link->len < ces_c->min_align_len)
      best_link->len = 0;
    else {
      gt_assert(best_link->orig_startpos >= query_bounds.start);
      gt_assert(best_link->orig_startpos + best_link->len <= query_bounds.end);
    }
  }
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %r12
movq %rdi, %r14
movq $-0x1, 0x68(%rsp)
movq 0xf0(%rdi), %rdx
movl 0x13c(%rdi), %ebx
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq 0x98(%rdi), %rax
xorl %r9d, %r9d
movq %r9, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq 0xa0(%rdi), %rax
movq %r9, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq 0xb0(%rdi), %rax
movl 0xc0(%rdi), %ecx
movl 0xc4(%rdi), %r10d
cmpl %r10d, %ecx
movl %r10d, %edi
cmovbl %r9d, %edi
subl %edi, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %r11
testq %r11, %r11
je 0x1354f6
movl 0x13c(%r14), %r8d
cmpl %r8d, %r10d
jne 0x1354f6
subq %rbx, %rdx
incq %rdx
movq 0xc8(%r14), %rdi
movq %rdi, 0x40(%rsp)
cmpq %rdi, %rdx
jb 0x135515
movq %rsi, 0x50(%rsp)
movq (%rax,%rcx,8), %rsi
movq %rsi, 0x38(%rsp)
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0xa0(%rsp)
movq 0xd0(%r14), %r13
addq 0xe0(%r14), %r13
movq %r13, 0x48(%rsp)
subq %r8, %r13
xorl %r9d, %r9d
cmpq %r13, %rdx
setbe %r15b
movq %rdx, 0x30(%rsp)
movq %r11, 0x58(%rsp)
jbe 0x135235
movq 0x3944d4(%rip), %r9     # 0x4c96e8
leaq 0x24e09e(%rip), %rsi    # 0x3832b9
movq %r12, %rdi
movq 0x48(%rsp), %rcx
xorl %eax, %eax
callq 0x1019cf
movq 0x30(%rsp), %rdx
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpq %r13, %rdx
ja 0x1354c2
movq %r9, %rbp
movq 0xb8(%r14), %rdi
cmpq $0x1, %rbx
adcq $0x0, %rbx
shlq $0x3, %rbx
xorl %esi, %esi
movq %rbx, %rdx
callq 0x173a0
movq 0x30(%rsp), %r10
movq %r10, %r8
subq 0x40(%rsp), %r8
jbe 0x13528a
movq (%r14), %rcx
movq 0x80(%r14), %rdx
xorl %edi, %edi
xorl %esi, %esi
movq 0x40(%rsp), %r9
callq 0x1ec1ee
movq 0x30(%rsp), %r10
movq 0x48(%rsp), %r8
subq %r10, %r8
movq 0x38(%rsp), %rbx
jbe 0x1352b4
movq (%r14), %rcx
movq 0x78(%r14), %rdx
movl $0x1, %edi
xorl %esi, %esi
movq %r10, %r9
callq 0x1ec1ee
movq 0x30(%rsp), %r10
cmpq %r13, %r10
movq %rbp, %r9
movq 0x58(%rsp), %r11
ja 0x1354c2
movq %r12, 0x88(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x60(%rsp)
xorl %ebp, %ebp
movq (%rbx,%rbp,8), %r13
movq 0xa0(%rsp), %rax
movq (%rax,%rbp,8), %r12
movq 0x60(%rsp), %rax
cmpq %r13, %rax
ja 0x135344
movq 0x28(%r14), %rax
cmpq 0x98(%rax), %r12
je 0x135510
movq 0x10(%rax), %rax
leaq (%r12,%r12,4), %rcx
movq 0x18(%rax,%rcx,8), %rdx
movq %rdx, 0x70(%rsp)
movl 0x20(%rax,%rcx,8), %eax
addq %rdx, %rax
movq %rax, 0x78(%rsp)
cmpq %r13, %rdx
ja 0x13550b
movq %rax, %rcx
movl 0x138(%r14), %eax
addq %r13, %rax
cmpq %rcx, %rax
movq %rcx, %rax
ja 0x13550b
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rax
cmpq $-0x1, %rax
je 0x135367
movq 0xa0(%r14), %rcx
addq (%rcx), %rax
cmpq %rax, %r13
jb 0x1354ad
testl %r9d, %r9d
je 0x135377
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
jmp 0x1354ad
movl 0x13c(%r14), %ebx
leaq -0x1(%r13), %rax
movq %rax, 0x98(%rsp)
xorl %r9d, %r9d
xorl %eax, %eax
movq %r12, 0x90(%rsp)
testb $0x1, %al
jne 0x1354a8
decl %ebx
movl 0x138(%r14), %edx
cmpl %edx, %ebx
jb 0x1354a8
movq 0xb0(%r14), %rdi
movl 0xc0(%r14), %ecx
addl %ebx, %ecx
movl 0xc4(%r14), %esi
cmpl %esi, %ecx
movl $0x0, %r8d
cmovbl %r8d, %esi
subl %esi, %ecx
leaq (%rcx,%rcx,2), %r8
movq 0x10(%rdi,%r8,8), %rsi
testq %rsi, %rsi
je 0x13541e
movq 0xb8(%r14), %rcx
movl %ebx, %r12d
movq (%rcx,%r12,8), %r15
movb $0x1, %cl
cmpq %rsi, %r15
jae 0x13548f
movq (%rdi,%r8,8), %rdi
addq 0x98(%rsp), %rdx
movq (%rdi,%r15,8), %r8
cmpq %r8, %rdx
jbe 0x135422
incq %r15
cmpq %r15, %rsi
jne 0x135408
movq %rsi, %r15
jmp 0x13548f
movb $0x1, %cl
jmp 0x13549a
movl 0x13c(%r14), %edx
addq %r13, %rdx
cmpq %r8, %rdx
jbe 0x13548f
movq %r13, %rsi
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movq %r10, %rdx
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x90(%rsp), %r9
callq 0x13663d
movq 0x58(%rsp), %r11
movq 0x30(%rsp), %r10
xorl %r9d, %r9d
testl %eax, %eax
sete %cl
movb $0x1, %al
movq 0xb8(%r14), %rdx
movq %r15, (%rdx,%r12,8)
testb %cl, %cl
jne 0x135397
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %rbx
testl %r9d, %r9d
sete %r15b
jne 0x1354c2
incq %rbp
cmpq %r11, %rbp
jb 0x1352d9
testb %r15b, %r15b
je 0x1354f6
movq 0x50(%rsp), %rcx
movl 0x10(%rcx), %eax
cmpq %rax, 0x100(%r14)
jbe 0x1354e1
movl $0x0, 0x10(%rcx)
jmp 0x1354f6
movq 0x8(%rcx), %rcx
cmpq 0x40(%rsp), %rcx
jb 0x13551a
addq %rax, %rcx
cmpq 0x48(%rsp), %rcx
ja 0x13551f
movl %r9d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3ea17
callq 0x3ea50
callq 0x3eafb
callq 0x3eac2
callq 0x3ea89