// File: /workspace/github_c_makefile_star2_O2/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, 0x60(%rsp)
movq %rdi, %r14
orq $-0x1, 0x68(%rsp)
movq 0xf0(%rdi), %r10
movl 0x13c(%rdi), %r9d
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq 0x98(%rdi), %rcx
andq $0x0, 0x20(%rcx)
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0xa0(%rdi), %rcx
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
andq $0x0, 0x20(%rcx)
movq 0xb0(%rdi), %rcx
movl 0xc0(%rdi), %edx
movl 0xc4(%rdi), %r8d
xorl %eax, %eax
cmpl %r8d, %edx
movl %r8d, %edi
cmovbl %eax, %edi
subl %edi, %edx
imulq $0x18, %rdx, %rdx
movq 0x10(%rcx,%rdx), %rdi
movq %rdi, 0x98(%rsp)
testq %rdi, %rdi
je 0xc5118
cmpl 0x13c(%r14), %r8d
jne 0xc5118
subq %r9, %r10
incq %r10
movq 0xc8(%r14), %rdi
movq %rdi, 0x30(%rsp)
cmpq %rdi, %r10
jb 0xc5190
movq (%rcx,%rdx), %rdi
movq %rdi, 0x90(%rsp)
movq 0xd0(%r14), %r11
addq 0xe0(%r14), %r11
movq 0x8(%rcx,%rdx), %rcx
movq %rcx, 0x88(%rsp)
movq %r11, %rcx
subq %r8, %rcx
cmpq %rcx, %r10
movq %r10, 0x40(%rsp)
movq %r11, 0x38(%rsp)
movq %rsi, 0x58(%rsp)
jbe 0xc4e80
movq 0x378840(%rip), %r9     # 0x43d698
leaq 0x25548a(%rip), %rsi    # 0x31a2e9
movq 0x60(%rsp), %rdi
movq %r10, %rdx
movq %r11, %rcx
xorl %eax, %eax
callq 0x89dbb
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %r10
pushq $-0x1
popq %rbx
jmp 0xc4eee
movq 0xb8(%r14), %rcx
xorl %edx, %edx
cmpq %rdx, %r9
je 0xc4e98
andq $0x0, (%rcx,%rdx,8)
incq %rdx
jmp 0xc4e89
movq %r10, %r8
subq 0x30(%rsp), %r8
jbe 0xc4ec4
movq (%r14), %rcx
movq 0x80(%r14), %rdx
xorl %edi, %edi
xorl %esi, %esi
movq 0x30(%rsp), %r9
callq 0x191910
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %r10
xorl %ebx, %ebx
movq %r11, %r8
subq %r10, %r8
jbe 0xc4eee
movq (%r14), %rcx
movq 0x78(%r14), %rdx
pushq $0x1
popq %rdi
xorl %ebx, %ebx
xorl %esi, %esi
movq %r10, %r9
callq 0x191910
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %r10
xorl %edi, %edi
xorl %esi, %esi
testl %ebx, %ebx
jne 0xc50db
cmpq 0x98(%rsp), %rsi
jae 0xc50db
movq 0x90(%rsp), %rax
movq (%rax,%rsi,8), %rbx
movq 0x88(%rsp), %rax
movq (%rax,%rsi,8), %r8
cmpq %rbx, %rdi
ja 0xc4f70
movq 0x28(%r14), %rax
cmpq 0x98(%rax), %r8
je 0xc5158
movq 0x10(%rax), %rax
imulq $0x28, %r8, %rcx
movq 0x18(%rax,%rcx), %rdx
movq %rdx, 0x70(%rsp)
movl 0x20(%rax,%rcx), %edi
addq %rdx, %rdi
movq %rdi, 0x78(%rsp)
cmpq %rbx, %rdx
ja 0xc512a
movl 0x138(%r14), %eax
addq %rbx, %rax
cmpq %rdi, %rax
ja 0xc512a
movq 0x68(%rsp), %rax
cmpq $-0x1, %rax
je 0xc4f91
movq 0xa0(%r14), %rcx
addq (%rcx), %rax
cmpq %rax, %rbx
jae 0xc4f91
xorl %ebx, %ebx
jmp 0xc50d3
movq %r8, 0xa0(%rsp)
movq %rdi, 0x48(%rsp)
movq %rsi, 0x50(%rsp)
movl 0x13c(%r14), %r12d
leaq -0x1(%rbx), %r15
xorl %ecx, %ecx
xorl %eax, %eax
testl %eax, %eax
jne 0xc50bc
testb $0x1, %cl
jne 0xc50bc
decl %r12d
movl 0x138(%r14), %esi
cmpl %esi, %r12d
jb 0xc50c7
movq 0xb0(%r14), %rdx
movl 0xc0(%r14), %eax
addl %r12d, %eax
movl 0xc4(%r14), %edi
xorl %ecx, %ecx
cmpl %edi, %eax
cmovbl %ecx, %edi
subl %edi, %eax
imulq $0x18, %rax, %rdi
movq 0x10(%rdx,%rdi), %r8
movl $0x0, %eax
testq %r8, %r8
je 0xc4fb2
movq (%rdx,%rdi), %rax
movq 0xb8(%r14), %rdx
movl %r12d, %r13d
movq (%rdx,%r13,8), %rbp
addq %r15, %rsi
cmpq %rbp, %r8
movq %rbp, %rdi
cmovaq %r8, %rdi
cmpq %r8, %rbp
jae 0xc503c
movq (%rax,%rbp,8), %r9
cmpq %r9, %rsi
jbe 0xc5040
incq %rbp
jmp 0xc5029
xorl %ecx, %ecx
jmp 0xc50b1
movl 0x13c(%r14), %eax
addq %rbx, %rax
xorl %ecx, %ecx
cmpq %r9, %rax
jbe 0xc50ae
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r10, %rdx
movq 0x30(%rsp), %rcx
movq %r11, %r8
movq 0xa0(%rsp), %r9
callq 0xc6764
movq 0x38(%rsp), %r11
movq 0x40(%rsp), %r10
movq 0xb8(%r14), %rdx
movb $0x1, %cl
movq %rbp, %rdi
jmp 0xc50b3
movq %rbp, %rdi
xorl %eax, %eax
movq %rdi, (%rdx,%r13,8)
jmp 0xc4fb2
negl %eax
movl $0x0, %ebx
sbbl %ebx, %ebx
jmp 0xc50c9
xorl %ebx, %ebx
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdi
incq %rsi
jmp 0xc4ef2
testl %ebx, %ebx
movq 0x58(%rsp), %rcx
pushq $-0x1
popq %rax
jne 0xc5118
movl 0x10(%rcx), %eax
cmpq %rax, 0x100(%r14)
jbe 0xc50fb
andl $0x0, 0x10(%rcx)
xorl %eax, %eax
jmp 0xc5118
movq 0x8(%rcx), %rcx
cmpq 0x30(%rsp), %rcx
jb 0xc51be
addq %rax, %rcx
xorl %eax, %eax
cmpq %r11, %rcx
ja 0xc51ec
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x372e37(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x21fed8(%rip), %rsi    # 0x2e5013
leaq 0x254d8c(%rip), %rdx    # 0x319ece
leaq 0x255186(%rip), %rcx    # 0x31a2cf
leaq 0x254884(%rip), %r8     # 0x3199d4
movl $0x28f, %r9d            # imm = 0x28F
jmp 0xc5184
movq 0x372e09(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x21feaa(%rip), %rsi    # 0x2e5013
leaq 0x2551c4(%rip), %rdx    # 0x31a334
leaq 0x255158(%rip), %rcx    # 0x31a2cf
leaq 0x254856(%rip), %r8     # 0x3199d4
movl $0x28a, %r9d            # imm = 0x28A
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x372dd1(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x21fe72(%rip), %rsi    # 0x2e5013
leaq 0x255108(%rip), %rdx    # 0x31a2b0
leaq 0x255120(%rip), %rcx    # 0x31a2cf
leaq 0x25481e(%rip), %r8     # 0x3199d4
movl $0x25e, %r9d            # imm = 0x25E
jmp 0xc5184
movq 0x372da3(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x21fe44(%rip), %rsi    # 0x2e5013
leaq 0x254da0(%rip), %rdx    # 0x319f76
leaq 0x2550f2(%rip), %rcx    # 0x31a2cf
leaq 0x2547f0(%rip), %r8     # 0x3199d4
movl $0x2c4, %r9d            # imm = 0x2C4
jmp 0xc5184
movq 0x372d75(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x21fe16(%rip), %rsi    # 0x2e5013
leaq 0x254da1(%rip), %rdx    # 0x319fa5
leaq 0x2550c4(%rip), %rcx    # 0x31a2cf
leaq 0x2547c2(%rip), %r8     # 0x3199d4
movl $0x2c5, %r9d            # imm = 0x2C5
jmp 0xc5184