// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
movq $-0x1, 0x28(%rsp)
movq 0x98(%rdi), %rcx
movq 0xf0(%rdi), %r14
movl 0x13c(%rdi), %edx
xorl %eax, %eax
movq %rax, 0x20(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0xa0(%rdi), %rcx
movq %rax, 0x20(%rcx)
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0xb0(%rdi), %rcx
movl 0xc0(%rdi), %esi
movl 0xc4(%rdi), %r8d
cmpl %r8d, %esi
movl %r8d, %edi
cmovbl %eax, %edi
subl %edi, %esi
leaq (%rsi,%rsi,2), %rsi
movq 0x10(%rcx,%rsi,8), %rdi
movq %rdi, 0x48(%rsp)
testq %rdi, %rdi
je 0x12f3bb
cmpl 0x13c(%r15), %r8d
jne 0x12f3bb
subq %rdx, %r14
incq %r14
movq 0xc8(%r15), %rax
movq %rax, (%rsp)
cmpq %rax, %r14
jb 0x12f3d4
movq 0xd0(%r15), %r12
addq 0xe0(%r15), %r12
movq %r12, %rax
subq %r8, %rax
cmpq %rax, %r14
jbe 0x12f146
movq 0x38f5c5(%rip), %r9     # 0x4be6e8
leaq 0x24ae71(%rip), %rsi    # 0x379f9b
movq 0x18(%rsp), %rdi
movq %r14, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0xfcb67
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x12f3bb
movq (%rcx,%rsi,8), %rax
movq %rax, 0x40(%rsp)
movq 0x8(%rcx,%rsi,8), %rax
movq %rax, 0x38(%rsp)
movq 0xb8(%r15), %rdi
cmpq $0x1, %rdx
adcq $0x0, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x173a0
movq %r14, %r8
subq (%rsp), %r8
jbe 0x12f193
movq (%r15), %rcx
movq 0x80(%r15), %rdx
xorl %edi, %edi
xorl %esi, %esi
movq (%rsp), %r9
callq 0x1e2956
movq %rbx, 0x10(%rsp)
movq %r12, 0x8(%rsp)
subq %r14, %r12
jbe 0x12f1bb
movq (%r15), %rcx
movq 0x78(%r15), %rdx
movl $0x1, %edi
xorl %esi, %esi
movq %r12, %r8
movq %r14, %r9
callq 0x1e2956
movq %r14, 0x30(%rsp)
xorl %edx, %edx
xorl %r14d, %r14d
xorl %r10d, %r10d
movq 0x40(%rsp), %rax
movq (%rax,%rdx,8), %rsi
movq 0x38(%rsp), %rax
movq (%rax,%rdx,8), %r11
cmpq %rsi, %r10
ja 0x12f221
movq 0x28(%r15), %rax
cmpq 0x98(%rax), %r11
je 0x12f3cf
movq 0x10(%rax), %rax
leaq (%r11,%r11,4), %rcx
movq 0x18(%rax,%rcx,8), %r14
cmpq %rsi, %r14
ja 0x12f3ca
movl 0x20(%rax,%rcx,8), %r10d
addq %r14, %r10
movl 0x138(%r15), %eax
addq %rsi, %rax
cmpq %r10, %rax
ja 0x12f3ca
movq 0x28(%rsp), %rax
cmpq $-0x1, %rax
je 0x12f242
movq 0xa0(%r15), %rcx
addq (%rcx), %rax
cmpq %rax, %rsi
jae 0x12f242
xorl %eax, %eax
jmp 0x12f373
movq %rdx, 0x20(%rsp)
movl 0x13c(%r15), %r12d
leaq -0x1(%rsi), %r13
movq %rsi, 0x60(%rsp)
movq %r10, 0x58(%rsp)
movq %r13, 0x50(%rsp)
decl %r12d
movl 0x138(%r15), %edx
cmpl %edx, %r12d
jb 0x12f36c
movq 0xb0(%r15), %rdi
movl 0xc0(%r15), %eax
addl %r12d, %eax
movl 0xc4(%r15), %r8d
xorl %ecx, %ecx
cmpl %r8d, %eax
cmovbl %ecx, %r8d
subl %r8d, %eax
leaq (%rax,%rax,2), %r8
movq 0x10(%rdi,%r8,8), %r9
testq %r9, %r9
je 0x12f2dc
movq 0xb8(%r15), %rax
movl %r12d, %ebx
movq (%rax,%rbx,8), %rbp
cmpq %r9, %rbp
jae 0x12f351
movq (%rdi,%r8,8), %rcx
addq %r13, %rdx
movq (%rcx,%rbp,8), %rdi
cmpq %rdi, %rdx
jbe 0x12f2e0
incq %rbp
cmpq %rbp, %r9
jne 0x12f2c4
xorl %ecx, %ecx
movq %r9, %rbp
jmp 0x12f353
xorl %edx, %edx
jmp 0x12f359
movl 0x13c(%r15), %ecx
addq %rsi, %rcx
cmpq %rdi, %rcx
jbe 0x12f351
subq $0x8, %rsp
movq %r15, %rdi
movq 0x38(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movq %r14, %r9
pushq 0x20(%rsp)
leaq 0x38(%rsp), %rax
pushq %rax
pushq 0x28(%rsp)
pushq %r11
pushq %r10
movq %r11, %r13
callq 0x13041b
movq %r13, %r11
movq 0x80(%rsp), %r13
movq 0x90(%rsp), %rsi
movq 0x88(%rsp), %r10
addq $0x30, %rsp
testl %eax, %eax
setne %dl
movq 0xb8(%r15), %rax
movb $0x1, %cl
jmp 0x12f355
xorl %ecx, %ecx
xorl %edx, %edx
movq %rbp, (%rax,%rbx,8)
testb %dl, %dl
jne 0x12f365
testb %cl, %cl
je 0x12f261
movzbl %dl, %eax
negl %eax
jmp 0x12f36e
xorl %eax, %eax
movq 0x20(%rsp), %rdx
testl %eax, %eax
jne 0x12f385
incq %rdx
cmpq 0x48(%rsp), %rdx
jb 0x12f1c8
testl %eax, %eax
movq 0x10(%rsp), %rcx
jne 0x12f3bb
movl 0x10(%rcx), %eax
cmpq %rax, 0x100(%r15)
jbe 0x12f3a5
movl $0x0, 0x10(%rcx)
xorl %eax, %eax
jmp 0x12f3bb
movq 0x8(%rcx), %rcx
cmpq (%rsp), %rcx
jb 0x12f3d9
addq %rax, %rcx
xorl %eax, %eax
cmpq 0x8(%rsp), %rcx
ja 0x12f3de
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3df99
callq 0x3dfd2
callq 0x3e07d
callq 0x3e044
callq 0x3e00b