// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/extended/condenseq_creator.c
// Function: ces_c_extend_seeds_diags
static int ces_c_extend_seeds_diags(GtCondenseqCreator *ces_c,
                                    GtCondenseqLink *best_link,
                                    GtError *err)
{
  int had_err = 0;
  GtRange query_bounds,
          subject_bounds = {0,0};
  GtKmerStartpos subject_positions;
  GtCondenseqCreatorWindow *win = &ces_c->window;
  GtCondenseqCreatorXdrop *xdrop = &ces_c->xdrop;
  CesCDiags *diags = ces_c->diagonals;
  GtUword best_match = GT_UNDEF_UWORD,
          subject_idx, querypos;
  GtXdropbest empty = {0,0,0,0,0};
  const bool forward = true;

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

  subject_bounds.end = 0;

  subject_positions = win->pos_arrs[GT_CONDENSEQ_CREATOR_LAST_WIN(win)];

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

  querypos = ces_c->main_pos;

  /* get bounds for current */
  query_bounds.start = ces_c->current_orig_start;
  query_bounds.end = ces_c->current_seq_start + ces_c->current_seq_len;

#ifdef GT_CONDENSEQ_LIMIT
  subject_positions.no_positions =
    subject_positions.no_positions > GT_CONDENSEQ_LIMIT ?
    GT_CONDENSEQ_LIMIT :
    subject_positions.no_positions;
#endif

  for (subject_idx = 0;
       !had_err && subject_idx < subject_positions.no_positions;
       ++subject_idx) {
    GtUword d,
            subjectpos = subject_positions.startpos[subject_idx],
            new_id = subject_positions.unique_ids[subject_idx],
            j_prime;
    CesCDiag *overwrite_diag = NULL;

    gt_assert(subjectpos < querypos);
    d = querypos - subjectpos;

    if (subject_bounds.end < subjectpos || subject_bounds.end == 0) {
      if (subject_bounds.end != 0) {
        ces_c_sparse_diags_mark(diags->sparse,
                                subject_bounds.end,
                                querypos - subject_bounds.end,
                                d);
      }
      gt_assert(new_id != ces_c->ces->uds_nelems);
      subject_bounds.start = ces_c->ces->uniques[new_id].orig_startpos;
      subject_bounds.end = subject_bounds.start +
        ces_c->ces->uniques[new_id].len;
      gt_assert(subject_bounds.start <= subjectpos &&
                subjectpos + ces_c->kmersize <= subject_bounds.end);
    }

    if ((j_prime = ces_c_diags_get(diags, d,
                                   &overwrite_diag)) != GT_UNDEF_UWORD &&
        j_prime >= subject_bounds.start) {
      GtUword distance;
      gt_assert(j_prime < subjectpos);
      distance = subjectpos - j_prime;

      if (distance > (GtUword) ces_c->kmersize &&
          distance <= (GtUword) ces_c->windowsize) {
        GtUword i_prime;

        /* as querypos > i' and d = querypos - subjectpos = i' - j',
           i' = d + j' can not overflow */
        i_prime = d + j_prime;
        gt_assert(i_prime >= query_bounds.start);
        gt_assert(i_prime <= query_bounds.end);

        /* subjectpos and j_prime are from the same unique sequences.
           j' position has to be outside of the current best alignment. (only
           checks for '>' because the previous querypos was smaller) */
        if (best_match == GT_UNDEF_UWORD ||
            j_prime > best_match + xdrop->right->ivalue) {
          if (query_bounds.start < i_prime) {
            gt_seqabstract_reinit_encseq(!forward,
                                         GT_READMODE_FORWARD,
                                         xdrop->current_seq_bwd,
                                         ces_c->input_es,
                                         i_prime - query_bounds.start,
                                         query_bounds.start);
          }
          if (i_prime < query_bounds.end) {
            gt_seqabstract_reinit_encseq(forward,
                                         GT_READMODE_FORWARD,
                                         xdrop->current_seq_fwd,
                                         ces_c->input_es,
                                         query_bounds.end - i_prime,
                                         i_prime);
          }
          had_err = ces_c_xdrop(ces_c,
                                j_prime, i_prime,
                                query_bounds,
                                subject_bounds,
                                new_id,
                                best_link,
                                &best_match,
                                err);
        }
      }
    }
    ces_c_diags_set(ces_c, d, subjectpos, subject_bounds.start, overwrite_diag);
  }

#ifdef GT_CONDENSEQ_CREATOR_DIAGS_DEBUG
  if (diags->full != NULL) {
    gt_log_log("I: " GT_WU " FULL", querypos);
    for (subject_idx = 0; subject_idx < diags->full->nextfree; subject_idx++) {
      if (diags->full->space[subject_idx] != GT_UNDEF_UWORD)
        gt_log_log("D: " GT_WU ", I: " GT_WU,
                   subject_idx, diags->full->space[subject_idx]);
    }
  }
  if (diags->sparse != NULL) {
    GtRBTreeIter *iter;
    CesCDiag *diag;
    if (diags->sparse->add_iterator == NULL)
      diags->sparse->add_iterator =
        gt_rbtree_iter_new_from_first(diags->sparse->add_tree);
    gt_rbtree_iter_reset_from_first(diags->sparse->add_iterator);
    iter = diags->sparse->add_iterator;
    gt_log_log("I: " GT_WU " array:", querypos);
    for (subject_idx = 0;
         subject_idx < diags->sparse->nextfree;
         subject_idx++) {
      if (diags->sparse->space[subject_idx].j != GT_UNDEF_UWORD)
        gt_log_log("D: " GT_WU ", J: " GT_WU,
                   diags->sparse->space[subject_idx].d,
                   diags->sparse->space[subject_idx].j);
      else
        gt_log_log("D: " GT_WU ", J: X", diags->sparse->space[subject_idx].d);
    }
    gt_log_log("tree:");
    diag = gt_rbtree_iter_data(iter);
    while (diag != NULL) {
      gt_log_log("D: " GT_WU ", J: " GT_WU, diag->d, diag->j);
      diag = gt_rbtree_iter_next(iter);
    }
  }
#endif

  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 %r14
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x128(%rsp)
movq %rsi, 0x120(%rsp)
movq %rdx, 0x118(%rsp)
movl $0x0, 0x114(%rsp)
leaq 0xf0(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x19360
movq 0x128(%rsp), %rax
addq $0xb0, %rax
movq %rax, 0xd0(%rsp)
movq 0x128(%rsp), %rax
addq $0x58, %rax
movq %rax, 0xc8(%rsp)
movq 0x128(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0xc0(%rsp)
movq $-0x1, 0xb8(%rsp)
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x19360
movb $0x1, 0x7f(%rsp)
movq 0xc8(%rsp), %rax
movq 0x40(%rax), %rdi
leaq 0x80(%rsp), %rsi
movl $0x28, %edx
callq 0x19610
movq 0xc8(%rsp), %rax
movq 0x48(%rax), %rdi
leaq 0x80(%rsp), %rsi
movl $0x28, %edx
callq 0x19610
movq $0x0, 0xf8(%rsp)
movq 0xd0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0xd0(%rsp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x14344e
movq 0xd0(%rsp), %rax
movl 0x14(%rax), %eax
subl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x143460
movq 0xd0(%rsp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rax
movl 0x34(%rsp), %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, 0xd8(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0xe0(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0xe8(%rsp)
cmpq $0x0, 0xe8(%rsp)
je 0x1434be
movq 0x128(%rsp), %rax
movl 0xc4(%rax), %eax
movq 0x128(%rsp), %rcx
cmpl 0x13c(%rcx), %eax
je 0x1434d1
movl 0x114(%rsp), %eax
movl %eax, 0x134(%rsp)
jmp 0x143b3f
movq 0x128(%rsp), %rax
movq 0xf0(%rax), %rax
movq %rax, 0xa8(%rsp)
movq 0x128(%rsp), %rax
movq 0xc8(%rax), %rax
movq %rax, 0x100(%rsp)
movq 0x128(%rsp), %rax
movq 0xe0(%rax), %rax
movq 0x128(%rsp), %rcx
addq 0xd0(%rcx), %rax
movq %rax, 0x108(%rsp)
movq $0x0, 0xb0(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x114(%rsp)
movb %al, 0x33(%rsp)
jne 0x143558
movq 0xb0(%rsp), %rax
cmpq 0xe8(%rsp), %rax
setb %al
movb %al, 0x33(%rsp)
movb 0x33(%rsp), %al
testb $0x1, %al
jne 0x143565
jmp 0x143a3d
movq 0xd8(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x68(%rsp)
movq 0xe0(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x68(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jb 0x1435e7
movq 0x4f89ea(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d2a53(%rip), %rsi    # 0x516013
leaq 0x4088d1(%rip), %rdx    # 0x54be98
leaq 0x4088e0(%rip), %rcx    # 0x54beae
leaq 0x408419(%rip), %r8     # 0x54b9ee
movl $0x34f, %r9d            # imm = 0x34F
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1435e9
movq 0xa8(%rsp), %rax
subq 0x68(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0xf8(%rsp), %rax
cmpq 0x68(%rsp), %rax
jb 0x143619
cmpq $0x0, 0xf8(%rsp)
jne 0x143767
cmpq $0x0, 0xf8(%rsp)
je 0x143652
movq 0xc0(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0xf8(%rsp), %rsi
movq 0xa8(%rsp), %rdx
subq 0xf8(%rsp), %rdx
movq 0x70(%rsp), %rcx
callq 0x146430
jmp 0x143654
movq 0x60(%rsp), %rax
movq 0x128(%rsp), %rcx
movq 0x28(%rcx), %rcx
cmpq 0x98(%rcx), %rax
jne 0x1436a6
movq 0x4f892b(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d2994(%rip), %rsi    # 0x516013
leaq 0x408841(%rip), %rdx    # 0x54bec7
leaq 0x408821(%rip), %rcx    # 0x54beae
leaq 0x40835a(%rip), %r8     # 0x54b9ee
movl $0x359, %r9d            # imm = 0x359
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1436a8
movq 0x128(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, 0x60(%rsp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, 0xf0(%rsp)
movq 0xf0(%rsp), %rax
movq 0x128(%rsp), %rcx
movq 0x28(%rcx), %rcx
movq 0x10(%rcx), %rcx
imulq $0x28, 0x60(%rsp), %rdx
addq %rdx, %rcx
movl 0x20(%rcx), %ecx
addq %rcx, %rax
movq %rax, 0xf8(%rsp)
movq 0xf0(%rsp), %rax
cmpq 0x68(%rsp), %rax
ja 0x14372b
movq 0x68(%rsp), %rax
movq 0x128(%rsp), %rcx
movl 0x138(%rcx), %ecx
addq %rcx, %rax
cmpq 0xf8(%rsp), %rax
jbe 0x143763
movq 0x4f886e(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d28d7(%rip), %rsi    # 0x516013
leaq 0x4087a5(%rip), %rdx    # 0x54bee8
leaq 0x408764(%rip), %rcx    # 0x54beae
leaq 0x40829d(%rip), %r8     # 0x54b9ee
movl $0x35e, %r9d            # imm = 0x35E
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x143765
jmp 0x143767
movq 0xc0(%rsp), %rdi
movq 0x70(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x1464f0
movq %rax, 0x58(%rsp)
cmpq $-0x1, %rax
je 0x143a00
movq 0x58(%rsp), %rax
cmpq 0xf0(%rsp), %rax
jb 0x143a00
jmp 0x1437a2
movq 0x58(%rsp), %rax
cmpq 0x68(%rsp), %rax
jb 0x1437e6
movq 0x4f87eb(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d2854(%rip), %rsi    # 0x516013
leaq 0x40877b(%rip), %rdx    # 0x54bf41
leaq 0x4086e1(%rip), %rcx    # 0x54beae
leaq 0x40821a(%rip), %r8     # 0x54b9ee
movl $0x365, %r9d            # imm = 0x365
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1437e8
movq 0x68(%rsp), %rax
subq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq 0x128(%rsp), %rcx
movl 0x138(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x1439fe
movq 0x48(%rsp), %rax
movq 0x128(%rsp), %rcx
movl 0x13c(%rcx), %ecx
cmpq %rcx, %rax
ja 0x1439fe
movq 0x70(%rsp), %rax
addq 0x58(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
cmpq 0x100(%rsp), %rax
jae 0x143885
movq 0x4f874c(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d27b5(%rip), %rsi    # 0x516013
leaq 0x4086f1(%rip), %rdx    # 0x54bf56
leaq 0x408642(%rip), %rcx    # 0x54beae
leaq 0x40817b(%rip), %r8     # 0x54b9ee
movl $0x36f, %r9d            # imm = 0x36F
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x143887
jmp 0x143889
movq 0x40(%rsp), %rax
cmpq 0x108(%rsp), %rax
jbe 0x1438d0
movq 0x4f8701(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d276a(%rip), %rsi    # 0x516013
leaq 0x4086c4(%rip), %rdx    # 0x54bf74
leaq 0x4085f7(%rip), %rcx    # 0x54beae
leaq 0x408130(%rip), %r8     # 0x54b9ee
movl $0x370, %r9d            # imm = 0x370
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1438d2
cmpq $-0x1, 0xb8(%rsp)
je 0x143902
movq 0x58(%rsp), %rax
movq 0xb8(%rsp), %rcx
movq 0xc8(%rsp), %rdx
movq 0x48(%rdx), %rdx
addq (%rdx), %rcx
cmpq %rcx, %rax
jbe 0x1439fc
movq 0x100(%rsp), %rax
cmpq 0x40(%rsp), %rax
jae 0x143946
movq 0xc8(%rsp), %rax
movq 0x28(%rax), %rdx
movq 0x128(%rsp), %rax
movq (%rax), %rcx
movq 0x40(%rsp), %r8
subq 0x100(%rsp), %r8
movq 0x100(%rsp), %r9
xorl %esi, %esi
movl %esi, %edi
callq 0x2b0bc0
movq 0x40(%rsp), %rax
cmpq 0x108(%rsp), %rax
jae 0x14398a
movq 0xc8(%rsp), %rax
movq 0x20(%rax), %rdx
movq 0x128(%rsp), %rax
movq (%rax), %rcx
movq 0x108(%rsp), %r8
subq 0x40(%rsp), %r8
movq 0x40(%rsp), %r9
movl $0x1, %edi
xorl %esi, %esi
callq 0x2b0bc0
movq 0x128(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x60(%rsp), %r9
movq 0x120(%rsp), %r11
movq 0x118(%rsp), %rax
movq 0x100(%rsp), %rcx
movq 0x108(%rsp), %r8
leaq 0xf0(%rsp), %rbx
leaq 0xb8(%rsp), %r10
movq (%rbx), %r14
movq %r14, (%rsp)
movq 0x8(%rbx), %rbx
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x1467f0
movl %eax, 0x114(%rsp)
jmp 0x1439fe
jmp 0x143a00
movq 0x128(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0xf0(%rsp), %rcx
movq 0x50(%rsp), %r8
callq 0x146d10
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0x143531
cmpl $0x0, 0x114(%rsp)
jne 0x143b31
movq 0x120(%rsp), %rax
movl 0x10(%rax), %eax
movq 0x128(%rsp), %rcx
cmpq 0x100(%rcx), %rax
jae 0x143a7b
movq 0x120(%rsp), %rax
movl $0x0, 0x10(%rax)
jmp 0x143b2f
jmp 0x143a7d
movq 0x120(%rsp), %rax
movq 0x8(%rax), %rax
cmpq 0x100(%rsp), %rax
jae 0x143acb
movq 0x4f8506(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d256f(%rip), %rsi    # 0x516013
leaq 0x4084e5(%rip), %rdx    # 0x54bf90
leaq 0x4083fc(%rip), %rcx    # 0x54beae
leaq 0x407f35(%rip), %r8     # 0x54b9ee
movl $0x3be, %r9d            # imm = 0x3BE
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x143acd
jmp 0x143acf
movq 0x120(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x120(%rsp), %rcx
movl 0x10(%rcx), %ecx
addq %rcx, %rax
cmpq 0x108(%rsp), %rax
jbe 0x143b2b
movq 0x4f84a6(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x3d250f(%rip), %rsi    # 0x516013
leaq 0x4084b4(%rip), %rdx    # 0x54bfbf
leaq 0x40839c(%rip), %rcx    # 0x54beae
leaq 0x407ed5(%rip), %r8     # 0x54b9ee
movl $0x3bf, %r9d            # imm = 0x3BF
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x143b2d
jmp 0x143b2f
jmp 0x143b31
movl 0x114(%rsp), %eax
movl %eax, 0x134(%rsp)
movl 0x134(%rsp), %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r14
retq
nopw %cs:(%rax,%rax)