// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
movq %rdx, 0x60(%rsp)
movq 0x30(%rdi), %r8
movq $-0x1, 0x48(%rsp)
movq 0x98(%rdi), %rcx
xorl %eax, %eax
movq %rax, 0x20(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x10(%rcx)
movupd %xmm0, (%rcx)
movq 0xa0(%rdi), %rcx
movq %rax, 0x20(%rcx)
movupd %xmm0, 0x10(%rcx)
movupd %xmm0, (%rcx)
movq 0xb0(%rdi), %r9
movl 0xc0(%rdi), %ecx
testl %ecx, %ecx
jne 0x12e681
movl 0xc4(%rdi), %ecx
decl %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%r9,%rcx,8), %rdx
movq %rdx, 0x80(%rsp)
testq %rdx, %rdx
je 0x12ed9a
movl 0xc4(%rdi), %edx
cmpl 0x13c(%rdi), %edx
jne 0x12ed9a
movq %rsi, 0x38(%rsp)
movq (%r9,%rcx,8), %rdx
movq %rdx, 0x78(%rsp)
movq 0x8(%r9,%rcx,8), %rax
movq %rax, 0x70(%rsp)
movq 0xf0(%rdi), %rax
movq %rax, 0x40(%rsp)
movq 0xc8(%rdi), %rax
movq %rax, 0x10(%rsp)
movq 0xd0(%rdi), %rax
addq 0xe0(%rdi), %rax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r10d, %r10d
movq %rdi, (%rsp)
movq %r8, 0x8(%rsp)
movq 0x78(%rsp), %rax
movq (%rax,%r15,8), %r9
movq 0x40(%rsp), %rbx
subq %r9, %rbx
jbe 0x12edac
movq 0x70(%rsp), %rax
movq (%rax,%r15,8), %rbp
testq %r14, %r14
je 0x12e732
cmpq %r9, %r14
jae 0x12e7d6
testq %r14, %r14
je 0x12e78e
movq 0x8(%r8), %r12
testq %r12, %r12
je 0x12e78e
movq 0x40(%rsp), %rdx
subq %r14, %rdx
movq 0x8(%r12), %rdi
movq 0x48(%r12), %rsi
movq %r9, %r13
callq 0x130680
movq %r13, %r9
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movq 0x8(%r12), %rcx
cmpq %rcx, %rax
jb 0x12e78e
cmpq %rbx, (%rax)
jbe 0x12e78e
cmpq %r14, 0x8(%rax)
ja 0x12e78e
movq $-0x1, 0x8(%rax)
incq 0x38(%r12)
addq $-0x10, %rax
jmp 0x12e76b
movq 0x28(%rdi), %rax
cmpq 0x98(%rax), %rbp
je 0x12edc5
movq 0x10(%rax), %rax
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
movq 0x18(%rax,%rcx,8), %r10
cmpq %r9, %r10
ja 0x12edb1
movl 0x20(%rax,%rcx,8), %r14d
addq %r10, %r14
movl 0x138(%rdi), %eax
addq %r9, %rax
cmpq %r14, %rax
ja 0x12edb1
movq (%r8), %rax
movq $-0x1, %rcx
movq $-0x1, %r13
testq %rax, %rax
je 0x12e7fd
cmpq %rbx, 0x10(%rax)
jbe 0x12edbb
movq (%rax), %rdx
movq (%rdx,%rbx,8), %r13
movq %rbp, 0x30(%rsp)
movq 0x8(%r8), %rdx
testq %rdx, %rdx
je 0x12e86c
movq %r15, 0x18(%rsp)
movq %r14, %r15
movq %r10, %r14
movq %r9, %r12
movq %rbx, 0x50(%rsp)
movq 0x8(%rdx), %rdi
movq 0x48(%rdx), %rsi
movq %rbx, %rdx
callq 0x130680
movq 0x8(%rsp), %r8
movq %rax, %rbp
movq 0x8(%r8), %rax
cmpq 0x8(%rax), %rbp
jae 0x12e876
movq 0x10(%rax), %rdi
leaq 0x50(%rsp), %rsi
callq 0x1660cc
testq %rax, %rax
je 0x12e8c7
cmpq %rbx, (%rax)
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
movq %r12, %r9
movq %r14, %r10
je 0x12e8be
jmp 0x12edd9
xorl %ebp, %ebp
movq %r13, %r12
jmp 0x12e8f6
movq 0x8(%rbp), %rcx
cmpq %rbx, (%rbp)
jne 0x12e886
movq (%rsp), %rdi
jmp 0x12e8e2
cmpq $-0x1, %rcx
movl $0x0, %ecx
cmovneq %rcx, %rbp
movq 0x10(%rax), %rdi
leaq 0x50(%rsp), %rsi
callq 0x1660cc
testq %rax, %rax
je 0x12e8d2
cmpq %rbx, (%rax)
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
movq %r12, %r9
movq %r14, %r10
jne 0x12ee01
movq 0x8(%rax), %rcx
movq %rax, %rbp
jmp 0x12e8e8
movq $-0x1, %rcx
xorl %ebp, %ebp
jmp 0x12e8d9
movq $-0x1, %rcx
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
movq %r12, %r9
movq %r14, %r10
movq %r15, %r14
movq (%r8), %rax
movq %rcx, %r12
movq 0x18(%rsp), %r15
testq %rax, %rax
je 0x12e911
cmpq $0x0, 0x8(%r8)
je 0x12e911
cmpq $-0x1, %rcx
je 0x12e911
cmpq %rcx, %r13
jne 0x12edb6
xorl %eax, %eax
cmpq $-0x1, %r12
je 0x12ea3d
cmpq %r10, %r12
jb 0x12ea3d
movq %r9, %rdx
subq %r12, %rdx
jbe 0x12edca
movl 0x138(%rdi), %ecx
cmpq %rcx, %rdx
jbe 0x12ea3d
movl 0x13c(%rdi), %ecx
cmpq %rcx, %rdx
ja 0x12ea3d
leaq (%r12,%rbx), %r13
cmpq 0x10(%rsp), %r13
jb 0x12ede3
cmpq %r13, 0x20(%rsp)
jb 0x12edde
movq 0x48(%rsp), %rdx
cmpq $-0x1, %rdx
je 0x12e988
movq 0xa0(%rdi), %rcx
addq (%rcx), %rdx
cmpq %rdx, %r12
jbe 0x12ea3d
movq %r15, 0x18(%rsp)
movq %r14, %r15
movq %r9, 0x28(%rsp)
movq %r13, %r8
subq 0x10(%rsp), %r8
jbe 0x12e9c1
movq (%rdi), %rcx
movq 0x80(%rdi), %rdx
xorl %edi, %edi
xorl %esi, %esi
movq 0x10(%rsp), %r9
movq %r10, %r14
callq 0x1e2956
movq %r14, %r10
movq (%rsp), %rdi
movq 0x20(%rsp), %r8
subq %r13, %r8
jbe 0x12e9e7
movq (%rdi), %rcx
movq 0x78(%rdi), %rdx
movl $0x1, %edi
xorl %esi, %esi
movq %r13, %r9
movq %r10, %r14
callq 0x1e2956
movq %r14, %r10
subq $0x8, %rsp
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %r8
movq %r10, %r9
pushq 0x68(%rsp)
leaq 0x58(%rsp), %rax
pushq %rax
pushq 0x50(%rsp)
pushq 0x50(%rsp)
pushq %r15
movq %r10, %r14
callq 0x13041b
movq %r14, %r10
movq %r15, %r14
movq 0x30(%rsp), %rdi
addq $0x30, %rsp
movq 0x8(%rsp), %r8
movq 0x28(%rsp), %r9
movq 0x18(%rsp), %r15
movq 0x30(%rdi), %r11
cmpq %rbx, 0x120(%rdi)
jbe 0x12ea51
movq %rbx, 0x120(%rdi)
cmpq %rbx, 0x128(%rdi)
jae 0x12ea61
movq %rbx, 0x128(%rdi)
movq (%r11), %rcx
testq %rcx, %rcx
je 0x12ea90
movq (%rcx), %rcx
movq (%rcx,%rbx,8), %rdx
cmpq $-0x1, %rdx
je 0x12ea8c
cmpq %r10, %rdx
jb 0x12ea8c
movl 0x138(%rdi), %esi
addq %rsi, %rdx
decq %rdx
cmpq %r9, %rdx
jae 0x12ea90
movq %r9, (%rcx,%rbx,8)
movq 0x8(%r11), %r13
testq %r13, %r13
je 0x12ed4e
testq %rbp, %rbp
je 0x12ead3
movq %rbx, (%rbp)
movq 0x8(%rbp), %rdx
cmpq $-0x1, %rdx
je 0x12eaca
cmpq %r10, %rdx
jb 0x12eaca
movl 0x138(%rdi), %ecx
addq %rdx, %rcx
decq %rcx
cmpq %r9, %rcx
jae 0x12ed4e
movq %r9, 0x8(%rbp)
jmp 0x12ed4e
movq %rax, 0x30(%rsp)
movq %r10, 0x18(%rsp)
movq 0x20(%r13), %rax
cmpq 0x28(%r13), %rax
jne 0x12ecf0
movq 0x48(%r13), %rcx
movq %rcx, %rax
shrq $0x2, %rax
movabsq $0x28f5c28f5c28f5c3, %rdx # imm = 0x28F5C28F5C28F5C3
mulq %rdx
shrq $0x2, %rdx
movq (%rsp), %rax
movl 0x140(%rax), %eax
imulq %rdx, %rax
cmpq 0x38(%r13), %rax
jae 0x12eb6b
testq %rcx, %rcx
jle 0x12edf2
movq 0x8(%r13), %rax
shlq $0x4, %rcx
addq %rax, %rcx
movq %rax, %rdx
cmpq $-0x1, 0x8(%rdx)
je 0x12eb45
movupd (%rdx), %xmm0
movupd %xmm0, (%rax)
addq $0x10, %rax
addq $0x10, %rdx
cmpq %rcx, %rdx
jb 0x12eb32
cmpq %rdx, %rax
jae 0x12edf2
subq 0x8(%r13), %rax
sarq $0x4, %rax
movq %rax, 0x48(%r13)
movq $0x0, 0x38(%r13)
movq %r9, 0x28(%rsp)
movq 0x18(%r13), %rdi
testq %rdi, %rdi
jne 0x12eb89
movq 0x10(%r13), %rdi
callq 0x166d95
movq %rax, %rdi
movq %rax, 0x18(%r13)
callq 0x166e52
movq 0x48(%r13), %rbp
movq 0x20(%r13), %r12
movq 0x30(%r13), %rcx
leaq (%r12,%rbp), %rdx
cmpq %rcx, %rdx
jae 0x12eba9
movq 0x8(%r13), %rax
jmp 0x12ec28
movq %rcx, %xmm0
punpckldq 0x218d2a(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x218d32(%rip), %xmm0   # 0x3478f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x219146(%rip), %xmm1   # 0x347d18
cvttsd2si %xmm1, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x21913a(%rip), %xmm1   # 0x347d20
cvttsd2si %xmm1, %rdx
andq %rcx, %rdx
orq %rax, %rdx
addq %rdx, %r12
movq %r12, 0x30(%r13)
movq 0x8(%r13), %rdi
shlq $0x4, %r12
movq %r12, %rsi
leaq 0x24aa7c(%rip), %rdx    # 0x379686
movl $0xec, %ecx
callq 0x104461
movq %rax, 0x8(%r13)
movq 0x48(%r13), %rbp
movq 0x20(%r13), %r12
movq 0x30(%r13), %rcx
leaq (%r12,%rbp), %rdx
movq %rdx, 0x48(%r13)
cmpq %rcx, %rdx
jae 0x12edf7
movq %rax, 0x68(%rsp)
cmpq %rdx, 0x40(%r13)
jae 0x12ec44
movq %rdx, 0x40(%r13)
movq 0x10(%r13), %rdi
callq 0x1666fd
cmpq %rax, %r12
jne 0x12edfc
shlq $0x4, %rbp
movq 0x68(%rsp), %rcx
leaq (%rcx,%rbp), %rax
addq %rcx, %rbp
addq $-0x10, %rbp
shlq $0x4, %r12
addq %rax, %r12
addq $-0x10, %r12
movq 0x18(%r13), %rdi
callq 0x166ff0
testq %rax, %rax
je 0x12ecca
cmpq 0x8(%r13), %rbp
jb 0x12ecad
movq (%rax), %rcx
cmpq %rcx, (%rbp)
jbe 0x12eca7
movupd (%rbp), %xmm0
movupd %xmm0, (%r12)
addq $-0x10, %r12
addq $-0x10, %rbp
jmp 0x12ec83
jae 0x12edc0
movupd (%rax), %xmm0
movupd %xmm0, (%r12)
addq $-0x10, %r12
decq 0x20(%r13)
movq 0x18(%r13), %rdi
callq 0x166f4a
jmp 0x12ec7e
cmpq %rbp, %r12
jne 0x12ede8
cmpq $0x0, 0x20(%r13)
jne 0x12eded
movq 0x10(%r13), %rdi
callq 0x165fe3
movq 0x20(%r13), %rax
movq 0x28(%rsp), %r9
movq (%r13), %rcx
shlq $0x4, %rax
leaq (%rcx,%rax), %rsi
movq %r9, 0x8(%rcx,%rax)
movq %rbx, (%rcx,%rax)
movq 0x10(%r13), %rdi
leaq 0x50(%rsp), %rdx
callq 0x1663b6
cmpb $0x0, 0x50(%rsp)
je 0x12edcf
movq 0x10(%r13), %rdi
movq 0x20(%r13), %rbx
incq %rbx
movq %rbx, 0x20(%r13)
callq 0x1666fd
cmpq %rax, %rbx
jne 0x12edd4
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %rax
testl %eax, %eax
jne 0x12ed63
incq %r15
cmpq 0x80(%rsp), %r15
jb 0x12e704
testl %eax, %eax
movq 0x38(%rsp), %rcx
jne 0x12ed9a
movl 0x10(%rcx), %eax
cmpq %rax, 0x100(%rdi)
jbe 0x12ed83
movl $0x0, 0x10(%rcx)
xorl %eax, %eax
jmp 0x12ed9a
movq 0x8(%rcx), %rcx
cmpq 0x10(%rsp), %rcx
jb 0x12ee06
addq %rax, %rcx
xorl %eax, %eax
cmpq 0x20(%rsp), %rcx
ja 0x12ee0b
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3da08
callq 0x3de0a
callq 0x3daec
callq 0x3da41
callq 0x3dc7b
callq 0x3de43
callq 0x3db25
callq 0x3dd26
callq 0x3dd5f
callq 0x3dab3
callq 0x3db5e
callq 0x3db97
callq 0x3dcb4
callq 0x3dced
callq 0x3dbd0
callq 0x3dc09
callq 0x3dc42
callq 0x3da7a
callq 0x3ddd1
callq 0x3dd98