// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, 0xa8(%rsp)
movq %rdi, %r9
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movq 0x30(%rdi), %r8
movq $-0x1, 0x90(%rsp)
movq 0x98(%rdi), %rax
xorl %ecx, %ecx
movq %rcx, 0x20(%rax)
movupd %xmm0, 0x10(%rax)
movupd %xmm0, (%rax)
movq 0xa0(%rdi), %rax
movq %rcx, 0x20(%rax)
movupd %xmm0, 0x10(%rax)
movupd %xmm0, (%rax)
movq $0x0, 0x48(%rsp)
movq %rcx, 0x68(%rsp)
movq 0xb0(%rdi), %rax
movl 0xc0(%rdi), %ecx
testl %ecx, %ecx
jne 0x1346fb
movl 0xc4(%r9), %ecx
decl %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq %rdx, 0xc0(%rsp)
testq %rdx, %rdx
je 0x134e3e
movl 0xc4(%r9), %edx
cmpl 0x13c(%r9), %edx
jne 0x134e3e
movq %rsi, 0x78(%rsp)
movq (%rax,%rcx,8), %rdx
movq %rdx, 0xb8(%rsp)
movq 0x8(%rax,%rcx,8), %rax
movq %rax, 0xb0(%rsp)
movq 0xf0(%r9), %rax
movq %rax, 0x88(%rsp)
movq 0xd0(%r9), %rax
addq 0xe0(%r9), %rax
movq %rax, 0x50(%rsp)
movq 0xc8(%r9), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
xorl %r13d, %r13d
movq %r9, 0x30(%rsp)
movq %r8, 0x38(%rsp)
movq 0xb8(%rsp), %rax
movq (%rax,%r13,8), %r14
movq 0x88(%rsp), %rbx
subq %r14, %rbx
jbe 0x134e5a
movq 0xb0(%rsp), %rax
movq (%rax,%r13,8), %rbp
movq 0x68(%rsp), %r12
cmpq %r14, %r12
setae %al
testq %r12, %r12
setne %cl
testb %cl, %al
jne 0x134872
testq %r12, %r12
je 0x134820
movq 0x8(%r8), %r15
testq %r15, %r15
je 0x134820
movq 0x88(%rsp), %rsi
subq %r12, %rsi
movq %r15, %rdi
callq 0x1368b6
movq 0x38(%rsp), %r8
movq 0x30(%rsp), %r9
movq 0x8(%r15), %rcx
cmpq %rcx, %rax
jb 0x134820
cmpq %rbx, (%rax)
jbe 0x134820
cmpq %r12, 0x8(%rax)
ja 0x134820
movq $-0x1, 0x8(%rax)
incq 0x38(%r15)
addq $-0x10, %rax
jmp 0x1347fe
movq 0x28(%r9), %rax
cmpq 0x98(%rax), %rbp
je 0x134e6e
movq 0x10(%rax), %rax
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
movq 0x18(%rax,%rcx,8), %rdx
movq %rdx, 0x60(%rsp)
movl 0x20(%rax,%rcx,8), %eax
addq %rdx, %rax
movq %rax, 0x68(%rsp)
cmpq %r14, %rdx
ja 0x134e55
movl 0x138(%r9), %ecx
addq %r14, %rcx
cmpq %rax, %rcx
ja 0x134e55
movq %rbp, 0x58(%rsp)
movq (%r8), %rax
movq $-0x1, %rcx
movq $-0x1, %rbp
testq %rax, %rax
je 0x13489e
cmpq %rbx, 0x10(%rax)
jbe 0x134e64
movq (%rax), %rax
movq (%rax,%rbx,8), %rbp
movq 0x8(%r8), %rdi
testq %rdi, %rdi
je 0x1348f3
movq %rbx, 0x98(%rsp)
movq %rbx, %rsi
callq 0x1368b6
movq 0x38(%rsp), %r8
movq %rax, %r15
movq 0x8(%r8), %rax
cmpq 0x8(%rax), %r15
jae 0x1348fb
movq 0x10(%rax), %rdi
leaq 0x98(%rsp), %rsi
callq 0x16e015
testq %rax, %rax
je 0x13494a
cmpq %rbx, (%rax)
movq 0x30(%rsp), %r9
movq 0x38(%rsp), %r8
je 0x134941
jmp 0x134e82
xorl %r15d, %r15d
movq %rbp, %r12
jmp 0x13496a
movq 0x8(%r15), %rcx
cmpq %rbx, (%r15)
jne 0x13490b
movq 0x30(%rsp), %r9
jmp 0x134967
cmpq $-0x1, %rcx
movl $0x0, %ecx
cmovneq %rcx, %r15
movq 0x10(%rax), %rdi
leaq 0x98(%rsp), %rsi
callq 0x16e015
testq %rax, %rax
je 0x134956
cmpq %rbx, (%rax)
movq 0x30(%rsp), %r9
movq 0x38(%rsp), %r8
jne 0x134ea5
movq 0x8(%rax), %rcx
movq %rax, %r15
jmp 0x134967
movq $-0x1, %rcx
xorl %r15d, %r15d
jmp 0x13495d
movq $-0x1, %rcx
movq 0x30(%rsp), %r9
movq 0x38(%rsp), %r8
movq %rcx, %r12
cmpq $0x0, (%r8)
je 0x134986
cmpq $0x0, 0x8(%r8)
je 0x134986
cmpq $-0x1, %rcx
je 0x134986
cmpq %rcx, %rbp
jne 0x134e69
cmpq $-0x1, %r12
sete %al
movq 0x60(%rsp), %rbp
cmpq %rbp, %r12
setb %cl
orb %al, %cl
jne 0x134ac6
movq %r14, %rax
subq %r12, %rax
jbe 0x134e73
movl 0x138(%r9), %ecx
cmpq %rcx, %rax
jbe 0x134ac6
movl 0x13c(%r9), %ecx
cmpq %rcx, %rax
ja 0x134ac6
leaq (%r12,%rbx), %r10
cmpq 0x40(%rsp), %r10
jb 0x134e8c
cmpq %r10, 0x50(%rsp)
jb 0x134e87
movq 0x90(%rsp), %rax
cmpq $-0x1, %rax
je 0x134a07
movq 0xa0(%r9), %rcx
addq (%rcx), %rax
cmpq %rax, %r12
jbe 0x134ac6
movq %r10, %r8
subq 0x40(%rsp), %r8
movq %r10, 0x80(%rsp)
jbe 0x134a3e
movq (%r9), %rcx
movq 0x80(%r9), %rdx
xorl %edi, %edi
xorl %esi, %esi
movq 0x40(%rsp), %r9
callq 0x1ec1ee
movq 0x80(%rsp), %r10
movq 0x30(%rsp), %r9
movq 0x50(%rsp), %r8
subq %r10, %r8
jbe 0x134a6b
movq (%r9), %rcx
movq 0x78(%r9), %rdx
movl $0x1, %edi
xorl %esi, %esi
movq %r10, %r9
callq 0x1ec1ee
movq 0x80(%rsp), %r10
movq 0x30(%rsp), %r9
movapd 0x60(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r9, %rdi
movq %r12, %rsi
movq %r10, %rdx
movq 0x40(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x58(%rsp), %r9
callq 0x13663d
movq 0x30(%rsp), %r9
movq %rax, 0x48(%rsp)
movq 0x38(%rsp), %r8
movq 0x30(%r9), %rax
cmpq %rbx, 0x120(%r9)
jbe 0x134ada
movq %rbx, 0x120(%r9)
cmpq %rbx, 0x128(%r9)
jae 0x134aea
movq %rbx, 0x128(%r9)
movq (%rax), %rcx
testq %rcx, %rcx
je 0x134b23
movq (%rcx), %rcx
movq (%rcx,%rbx,8), %rdx
cmpq $-0x1, %rdx
sete %sil
cmpq %rbp, %rdx
setb %dil
orb %sil, %dil
jne 0x134b1f
movl 0x138(%r9), %esi
addq %rsi, %rdx
decq %rdx
cmpq %r14, %rdx
jae 0x134b23
movq %r14, (%rcx,%rbx,8)
movq 0x8(%rax), %r12
testq %r12, %r12
je 0x134df0
testq %r15, %r15
je 0x134b6c
movq %rbx, (%r15)
movq 0x8(%r15), %rax
cmpq $-0x1, %rax
sete %cl
cmpq %rbp, %rax
setb %dl
orb %cl, %dl
jne 0x134b63
movl 0x138(%r9), %ecx
addq %rcx, %rax
decq %rax
cmpq %r14, %rax
jae 0x134df0
movq %r14, 0x8(%r15)
jmp 0x134df0
movq 0x20(%r12), %rax
cmpq 0x28(%r12), %rax
jne 0x134d8c
movq 0x48(%r12), %rcx
movq %rcx, %rax
shrq $0x2, %rax
movabsq $0x28f5c28f5c28f5c3, %rdx # imm = 0x28F5C28F5C28F5C3
mulq %rdx
shrq $0x2, %rdx
movq 0x30(%rsp), %rax
movl 0x140(%rax), %eax
imulq %rdx, %rax
cmpq 0x38(%r12), %rax
jae 0x134c04
movq 0x8(%r12), %rax
testq %rcx, %rcx
jle 0x134be1
shlq $0x4, %rcx
addq %rax, %rcx
movq %rax, %rdx
cmpq $-0x1, 0x8(%rdx)
je 0x134bd6
movupd (%rdx), %xmm0
movupd %xmm0, (%rax)
addq $0x10, %rax
addq $0x10, %rdx
cmpq %rcx, %rdx
jb 0x134bc3
jmp 0x134be4
movq %rax, %rdx
cmpq %rdx, %rax
jae 0x134eaa
subq 0x8(%r12), %rax
sarq $0x4, %rax
movq %rax, 0x48(%r12)
movq $0x0, 0x38(%r12)
cmpq $0x0, 0x18(%r12)
jne 0x134c1b
movq 0x10(%r12), %rdi
callq 0x16ed2f
movq %rax, 0x18(%r12)
movq 0x18(%r12), %rdi
callq 0x16edec
movq 0x20(%r12), %rsi
movq 0x30(%r12), %rax
movq 0x48(%r12), %rcx
addq %rsi, %rcx
cmpq %rax, %rcx
jb 0x134cab
movq %rax, %xmm0
punpckldq 0x21bc97(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x21bc9f(%rip), %xmm0   # 0x3508f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x21c0b3(%rip), %xmm1   # 0x350d18
cvttsd2si %xmm1, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x21c0a7(%rip), %xmm1   # 0x350d20
cvttsd2si %xmm1, %rdx
andq %rcx, %rdx
orq %rax, %rdx
addq %rdx, %rsi
movq %rsi, 0x30(%r12)
movq 0x8(%r12), %rdi
shlq $0x4, %rsi
leaq 0x24dd08(%rip), %rdx    # 0x3829a4
movl $0xec, %ecx
callq 0x1094e6
movq %rax, 0x8(%r12)
movq 0x48(%r12), %r15
movq 0x8(%r12), %rcx
movq 0x20(%r12), %rbp
leaq (%r15,%rbp), %rax
movq %rax, 0x48(%r12)
cmpq 0x30(%r12), %rax
jae 0x134e9b
movq %rcx, 0x58(%rsp)
cmpq %rax, 0x40(%r12)
jae 0x134cdf
movq %rax, 0x40(%r12)
movq 0x10(%r12), %rdi
callq 0x16e681
cmpq %rax, %rbp
jne 0x134ea0
shlq $0x4, %r15
movq 0x58(%rsp), %rcx
leaq (%rcx,%r15), %rax
addq %rcx, %r15
addq $-0x10, %r15
shlq $0x4, %rbp
addq %rax, %rbp
addq $-0x10, %rbp
movq 0x18(%r12), %rdi
callq 0x16efa2
testq %rax, %rax
je 0x134d6d
cmpq 0x8(%r12), %r15
jb 0x134d4f
movq (%r15), %rcx
movq (%rax), %rdx
cmpq %rdx, %rcx
jbe 0x134d46
movupd (%r15), %xmm0
movupd %xmm0, (%rbp)
addq $-0x10, %rbp
addq $-0x10, %r15
jmp 0x134d20
cmpq %rdx, %rcx
jae 0x134e5f
movupd (%rax), %xmm0
movupd %xmm0, (%rbp)
addq $-0x10, %rbp
decq 0x20(%r12)
movq 0x18(%r12), %rdi
callq 0x16eef0
jmp 0x134d1b
cmpq %r15, %rbp
jne 0x134e91
cmpq $0x0, 0x20(%r12)
jne 0x134e96
movq 0x10(%r12), %rdi
callq 0x16df27
movq (%r12), %rax
movq 0x20(%r12), %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rsi
movq %r14, 0x8(%rax,%rcx)
movq %rbx, (%rax,%rcx)
movq 0x10(%r12), %rdi
leaq 0x98(%rsp), %rdx
callq 0x16e310
cmpb $0x0, 0x98(%rsp)
je 0x134e78
movq 0x10(%r12), %rdi
movq 0x20(%r12), %rbx
incq %rbx
movq %rbx, 0x20(%r12)
callq 0x16e681
cmpq %rax, %rbx
jne 0x134e7d
movq 0x30(%rsp), %r9
movq 0x38(%rsp), %r8
cmpl $0x0, 0x48(%rsp)
jne 0x134e08
incq %r13
cmpq 0xc0(%rsp), %r13
jb 0x13478d
cmpl $0x0, 0x48(%rsp)
jne 0x134e3e
movq 0x78(%rsp), %rcx
movl 0x10(%rcx), %eax
cmpq %rax, 0x100(%r9)
jbe 0x134e29
movl $0x0, 0x10(%rcx)
jmp 0x134e3e
movq 0x8(%rcx), %rcx
cmpq 0x40(%rsp), %rcx
jb 0x134eaf
addq %rax, %rcx
cmpq 0x50(%rsp), %rcx
ja 0x134eb4
movq 0x48(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3e888
callq 0x3e486
callq 0x3e6f9
callq 0x3e4bf
callq 0x3e56a
callq 0x3e8c1
callq 0x3e5a3
callq 0x3e7a4
callq 0x3e7dd
callq 0x3e531
callq 0x3e5dc
callq 0x3e615
callq 0x3e732
callq 0x3e76b
callq 0x3e687
callq 0x3e6c0
callq 0x3e4f8
callq 0x3e64e
callq 0x3e84f
callq 0x3e816