// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/seed-extend.c
// Function: gt_extend_sesp
static bool gt_extend_sesp(bool forxdrop,
                           void *info,
                           const GtSeqorEncseq *dbes,
                           const GtSeqorEncseq *queryes,
                           const GtSeedextendSeqpair *sesp)
{
  GtProcessinfo_and_querymatchspaceptr *info_querymatch
    = (GtProcessinfo_and_querymatchspaceptr *) info;
  GtGreedyextendmatchinfo *greedyextendmatchinfo = NULL;
  GtXdropmatchinfo *xdropmatchinfo = NULL;
  GtUword u_left_ext, v_left_ext, u_right_ext, v_right_ext, r_urightbound;
  GtXdropscore total_score = 0;
  GtFTsequenceResources ufsr, vfsr;
  GtFtPolished_point left_best_polished_point = {0,0,0,0,0},
                     right_best_polished_point = {0,0,0,0,0};
  const bool rightextension = true;
  const GtUword vseqstartpos = queryes->encseq != NULL
                                  ? sesp->query_seqstart : 0;

  if (sesp->same_encseq && sesp->dbseqnum == sesp->queryseqnum &&
      sesp->dbstart_relative + sesp->seedlength - 1 >=
      sesp->querystart_relative)
  {
    return NULL;
  }
  if (forxdrop)
  {
    xdropmatchinfo = info_querymatch->processinfo;
    xdropmatchinfo->best_left.ivalue = 0;
    xdropmatchinfo->best_left.jvalue = 0;
    xdropmatchinfo->best_left.score = 0;
    xdropmatchinfo->best_right.ivalue = 0;
    xdropmatchinfo->best_right.jvalue = 0;
    xdropmatchinfo->best_right.score = 0;
  } else
  {
    greedyextendmatchinfo = info_querymatch->processinfo;
    gt_greedy_extend_init(&ufsr,
                          &vfsr,
                          dbes,
                          queryes,
                          sesp->query_readmode,
                          sesp->query_seqlen,
                          greedyextendmatchinfo);
  }
  if (sesp->dbstart_relative > 0 && sesp->querystart_relative > 0)
  { /* there is something to align on the left of the seed */
    const GtUword uoffset = sesp->db_seqstart,
                  ulen = sesp->dbstart_relative,
      /* stop extension at left instance of seed or querystart,
         whichever is larger */
      r_voffset = (sesp->same_encseq &&
                   sesp->dbseqnum == sesp->queryseqnum)
                     ? sesp->dbstart_relative + sesp->seedlength : 0;
    GtUword vlen;

    gt_assert(r_voffset <= sesp->querystart_relative);
    vlen = sesp->querystart_relative - r_voffset;
    if (ulen > 0 && vlen > 0)
    {
      if (forxdrop)
      {
        gt_seqabstract_reinit_generic(!rightextension,
                                      GT_READMODE_FORWARD,
                                      xdropmatchinfo->useq,
                                      dbes,
                                      ulen,
                                      uoffset,
                                      sesp->db_seqstart,
                                      sesp->dbseqlength);
        gt_seqabstract_reinit_generic(!rightextension,
                                      sesp->query_readmode,
                                      xdropmatchinfo->vseq,
                                      queryes,
                                      vlen,
                                      sesp->query_seqstart + r_voffset,
                                      sesp->query_seqstart,
                                      sesp->query_seqlen);
  #ifdef SKDEBUG
        gt_xdrop_show_context(!rightextension,xdropmatchinfo);
  #endif
        gt_evalxdroparbitscoresextend(!rightextension,
                                      &xdropmatchinfo->best_left,
                                      xdropmatchinfo->res,
                                      xdropmatchinfo->useq,
                                      xdropmatchinfo->vseq,
                                      xdropmatchinfo->belowscore);
      } else
      {
        (void) front_prune_edist_inplace(!rightextension,
                                         &greedyextendmatchinfo->
                                            frontspace_reservoir,
                                         &left_best_polished_point,
                                         greedyextendmatchinfo->
                                             left_front_trace,
                                         greedyextendmatchinfo->pol_info,
                                         greedyextendmatchinfo->trimstrategy,
                                         greedyextendmatchinfo->history,
                                         greedyextendmatchinfo->
                                             perc_mat_history,
                                         greedyextendmatchinfo->
                                            maxalignedlendifference,
                                         greedyextendmatchinfo->showfrontinfo,
                                         sesp->seedlength,
                                         &ufsr,
                                         uoffset,
                                         ulen,
                                         /* as the readmode for the
                                            sequence u is always forward,
                                            we do not need the start position
                                            of the sequence for u. As the
                                            readmode for v can be reversed,
                                            we need the start of the sequence
                                            to correctly obtain the offset
                                            when using the reverse mode */
                                         vseqstartpos,
                                         &vfsr,
                                         sesp->query_seqstart + r_voffset,
                                         vlen,
                                         greedyextendmatchinfo->cam_generic,
                                         greedyextendmatchinfo->trimstat);
      }
    }
  }
  if (forxdrop)
  {
    u_left_ext = xdropmatchinfo->best_left.ivalue;
    v_left_ext = xdropmatchinfo->best_left.jvalue;
#ifdef SKDEBUG
    extensioncoords_show(true,!rightextension,u_left_ext,v_left_ext,
                         xdropmatchinfo->best_left.score);
#endif
  } else
  {
    u_left_ext = left_best_polished_point.row;
    gt_assert(left_best_polished_point.alignedlen >= u_left_ext);
    v_left_ext = left_best_polished_point.alignedlen - u_left_ext;
#ifdef SKDEBUG
    extensioncoords_show(false,!rightextension,u_left_ext,v_left_ext,
                         (GtWord) left_best_polished_point.distance);
#endif
  }
  if (sesp->same_encseq && sesp->dbseqnum == sesp->queryseqnum)
  {
    gt_assert(sesp->querystart_relative >= v_left_ext);
    r_urightbound = GT_MIN(sesp->dbseqlength,
                         sesp->querystart_relative - v_left_ext);
  } else
  {
    r_urightbound = sesp->dbseqlength;
  }
  if (sesp->dbstart_relative + sesp->seedlength < r_urightbound &&
      sesp->querystart_relative + sesp->seedlength < sesp->query_seqlen)
  { /* there is something to align on the right of the seed */
    /* stop extension at right instance of extended seed */
    const GtUword ulen = r_urightbound -
                         (sesp->dbstart_relative + sesp->seedlength);
    const GtUword vlen = sesp->query_seqlen -
                         (sesp->querystart_relative + sesp->seedlength);
    if (forxdrop)
    {
      gt_seqabstract_reinit_generic(rightextension,
                                    GT_READMODE_FORWARD,
                                    xdropmatchinfo->useq,
                                    dbes,
                                    ulen,
                                    sesp->db_seqstart +
                                         gt_sesp_db_seedpos(sesp) +
                                         sesp->seedlength,
                                    sesp->db_seqstart,
                                    sesp->dbseqlength);
      gt_seqabstract_reinit_generic(rightextension,
                                    sesp->query_readmode,
                                    xdropmatchinfo->vseq,
                                    queryes,
                                    vlen,
                                    sesp->query_seqstart +
                                      gt_sesp_query_seedpos(sesp) +
                                      sesp->seedlength,
                                    sesp->query_seqstart,
                                    sesp->query_seqlen);
#ifdef SKDEBUG
      gt_xdrop_show_context(rightextension,xdropmatchinfo);
#endif
      gt_evalxdroparbitscoresextend(rightextension,
                                    &xdropmatchinfo->best_right,
                                    xdropmatchinfo->res,
                                    xdropmatchinfo->useq,
                                    xdropmatchinfo->vseq,
                                    xdropmatchinfo->belowscore);
    } else
    {
      (void) front_prune_edist_inplace(rightextension,
                                       &greedyextendmatchinfo->
                                          frontspace_reservoir,
                                       &right_best_polished_point,
                                       greedyextendmatchinfo->right_front_trace,
                                       greedyextendmatchinfo->pol_info,
                                       greedyextendmatchinfo->trimstrategy,
                                       greedyextendmatchinfo->history,
                                       greedyextendmatchinfo->perc_mat_history,
                                       greedyextendmatchinfo->
                                          maxalignedlendifference,
                                       greedyextendmatchinfo->showfrontinfo,
                                       sesp->seedlength,
                                       &ufsr,
                                       sesp->db_seqstart +
                                         gt_sesp_db_seedpos(sesp) +
                                         sesp->seedlength,
                                       ulen,
                                       vseqstartpos,
                                       &vfsr,
                                       sesp->query_seqstart +
                                         gt_sesp_query_seedpos(sesp) +
                                         sesp->seedlength,
                                       vlen,
                                       greedyextendmatchinfo->cam_generic,
                                       greedyextendmatchinfo->trimstat);
    }
  }
  if (forxdrop)
  {
    u_right_ext = xdropmatchinfo->best_right.ivalue;
    v_right_ext = xdropmatchinfo->best_right.jvalue;
#ifdef SKDEBUG
    extensioncoords_show(true,rightextension,u_right_ext,v_right_ext,
                         xdropmatchinfo->best_right.score);
#endif
    total_score
      = (GtXdropscore) sesp->seedlength * xdropmatchinfo->arbitscores.mat +
        xdropmatchinfo->best_left.score +
        xdropmatchinfo->best_right.score;
  } else
  {
    u_right_ext = right_best_polished_point.row;
    gt_assert(right_best_polished_point.alignedlen >= u_right_ext);
    v_right_ext = right_best_polished_point.alignedlen - u_right_ext;
#ifdef SKDEBUG
    extensioncoords_show(false,rightextension,u_right_ext,v_right_ext,
                         (GtWord) right_best_polished_point.distance);
#endif
    if (greedyextendmatchinfo->check_extend_symmetry)
    {
      gt_assert(right_best_polished_point.alignedlen ==
                left_best_polished_point.alignedlen);
      gt_assert(u_right_ext == u_left_ext);
      gt_assert(right_best_polished_point.distance ==
                left_best_polished_point.distance);
    }
  }
  return gt_combine_extensions(
                 forxdrop,
                 info_querymatch,
                 dbes,
                 queryes,
                 sesp,
                 u_left_ext,
                 v_left_ext,
                 u_right_ext,
                 v_right_ext,
                 forxdrop ? total_score : 0,
                 forxdrop ? 0 : (left_best_polished_point.distance +
                                 right_best_polished_point.distance),
                 forxdrop ? 0 : (left_best_polished_point.max_mismatches +
                                 right_best_polished_point.max_mismatches));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %r8, %rbx
movq %rdx, %r12
xorl %r8d, %r8d
movq %r8, 0x60(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq %r8, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
cmpq %r8, 0x8(%rcx)
je 0x1e1830
movq 0x30(%rbx), %r8
cmpb $0x1, 0x4c(%rbx)
jne 0x1e1857
movq (%rbx), %rax
cmpq 0x20(%rbx), %rax
jne 0x1e1857
movq 0x18(%rbx), %rax
movq 0x40(%rbx), %rdx
addq %rdx, %rax
decq %rax
cmpq 0x38(%rbx), %rax
jae 0x1e1b52
movq (%rsi), %rbp
testb %dil, %dil
movq %rcx, 0x10(%rsp)
movq %rsi, 0xa8(%rsp)
movq %r8, 0x30(%rsp)
je 0x1e188a
movups %xmm0, 0x18(%rbp)
xorl %eax, %eax
movq %rax, 0x28(%rbp)
movups %xmm0, 0x40(%rbp)
movq %rax, 0x50(%rbp)
movq %rbp, %r14
xorl %ebp, %ebp
jmp 0x1e18bc
movl 0x48(%rbx), %r8d
movq 0x28(%rbx), %r9
subq $0x8, %rsp
movl %edi, %r14d
leaq 0x120(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movq %r12, %rdx
pushq %rbp
callq 0x1e0e5a
movl %r14d, %edi
addq $0x10, %rsp
xorl %r14d, %r14d
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x1e18f3
movq 0x38(%rbx), %r15
testq %r15, %r15
je 0x1e18f3
movq 0x10(%rbx), %r10
cmpb $0x1, 0x4c(%rbx)
jne 0x1e18fd
movq (%rbx), %rcx
cmpq 0x20(%rbx), %rcx
jne 0x1e18fd
movq 0x40(%rbx), %r13
addq %rax, %r13
subq %r13, %r15
jb 0x1e1e3b
jne 0x1e1900
testb %dil, %dil
jne 0x1e196f
jmp 0x1e19f7
xorl %r13d, %r13d
movl %edi, 0x4(%rsp)
testb %dil, %dil
je 0x1e197c
movq 0x70(%r14), %rdx
xorl %edi, %edi
xorl %esi, %esi
movq %r12, %rcx
movq %rax, %r8
movq %r10, %r9
pushq 0x8(%rbx)
pushq %r10
callq 0x1e1e40
addq $0x10, %rsp
movl 0x48(%rbx), %esi
movq 0x78(%r14), %rdx
movq 0x30(%rbx), %rax
addq %rax, %r13
xorl %edi, %edi
movq 0x10(%rsp), %rcx
movq %r15, %r8
movq %r13, %r9
pushq 0x28(%rbx)
pushq %rax
callq 0x1e1e40
addq $0x10, %rsp
leaq 0x18(%r14), %rsi
movq 0x70(%r14), %rcx
movq 0x78(%r14), %r8
movq 0x10(%r14), %rdx
movq 0x68(%r14), %r9
xorl %edi, %edi
callq 0x203536
movl 0x4(%rsp), %edi
movq 0x18(%r14), %rdx
movq 0x20(%r14), %r9
jmp 0x1e1a0a
leaq 0x98(%rbp), %rsi
movq (%rbp), %rcx
movq 0x10(%rbp), %r8
movl 0xb0(%rbp), %r9d
movzbl 0xbd(%rbp), %edx
movq %rdx, 0x8(%rsp)
addq 0x30(%rbx), %r13
movq %r12, %r11
movzbl 0xc2(%rbp), %r12d
leaq 0x40(%rsp), %rdx
xorl %edi, %edi
pushq 0x50(%rbp)
pushq %r12
movq %r11, %r12
pushq %r15
pushq %r13
leaq 0xf8(%rsp), %r11
pushq %r11
pushq 0x58(%rsp)
pushq %rax
pushq %r10
leaq 0x158(%rsp), %rax
pushq %rax
pushq 0x40(%rbx)
pushq 0x58(%rsp)
pushq 0x20(%rbp)
pushq 0x28(%rbp)
pushq 0x18(%rbp)
callq 0x31d1d5
addq $0x70, %rsp
movl 0x4(%rsp), %edi
movq 0x40(%rsp), %r9
movq 0x48(%rsp), %rdx
subq %rdx, %r9
jb 0x1e1e18
cmpb $0x1, 0x4c(%rbx)
movq %r12, 0x38(%rsp)
jne 0x1e1a38
movq (%rbx), %rax
cmpq 0x20(%rbx), %rax
jne 0x1e1a38
movq 0x38(%rbx), %r13
subq %r9, %r13
jb 0x1e1e27
movq 0x8(%rbx), %rax
cmpq %r13, %rax
cmovbq %rax, %r13
jmp 0x1e1a3c
movq 0x8(%rbx), %r13
movq 0x40(%rbx), %r12
movq 0x18(%rbx), %rax
addq %r12, %rax
subq %rax, %r13
movq %rdx, 0x8(%rsp)
jbe 0x1e1b2d
movq 0x38(%rbx), %rax
addq %r12, %rax
movq 0x28(%rbx), %rcx
subq %rax, %rcx
jbe 0x1e1b2d
movq %rcx, 0x20(%rsp)
movq %r9, 0x28(%rsp)
movl %edi, 0x4(%rsp)
testb %dil, %dil
je 0x1e1b59
movq 0x70(%r14), %r12
movq 0x10(%rbx), %r15
movq %rbx, %rdi
callq 0x1e0625
addq %rax, %r15
addq 0x40(%rbx), %r15
movl $0x1, %edi
xorl %esi, %esi
movq %r12, %rdx
movq 0x38(%rsp), %rcx
movq %r13, %r8
movq %r15, %r9
pushq 0x8(%rbx)
pushq 0x10(%rbx)
callq 0x1e1e40
addq $0x10, %rsp
movl 0x48(%rbx), %ebp
movq 0x78(%r14), %r13
movq 0x30(%rbx), %r15
movq %rbx, %rdi
callq 0x1e0635
addq %rax, %r15
addq 0x40(%rbx), %r15
movl $0x1, %edi
movl %ebp, %esi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %r15, %r9
pushq 0x28(%rbx)
pushq 0x30(%rbx)
callq 0x1e1e40
addq $0x10, %rsp
leaq 0x40(%r14), %rsi
movq 0x70(%r14), %rcx
movq 0x78(%r14), %r8
movq 0x10(%r14), %rdx
movq 0x68(%r14), %r9
movl $0x1, %edi
callq 0x203536
movq 0x40(%rbx), %r12
movl 0x4(%rsp), %edi
movq 0x28(%rsp), %r9
movq 0x8(%rsp), %rdx
jmp 0x1e1b36
testb %dil, %dil
je 0x1e1c67
movq 0x40(%r14), %r13
movq 0x48(%r14), %r15
movslq (%r14), %r10
imulq %r12, %r10
addq 0x28(%r14), %r10
addq 0x50(%r14), %r10
jmp 0x1e1cbe
xorl %eax, %eax
jmp 0x1e1e01
leaq 0x98(%rbp), %rax
movq %rax, 0x70(%rsp)
movq 0x8(%rbp), %rax
movq %rax, 0x80(%rsp)
movq 0x10(%rbp), %rax
movq %rax, 0x78(%rsp)
movl 0xb0(%rbp), %eax
movl %eax, 0x1c(%rsp)
movq 0x18(%rbp), %rax
movq %rax, 0xa0(%rsp)
movq 0x28(%rbp), %rax
movq %rax, 0x98(%rsp)
movq 0x20(%rbp), %rax
movq %rax, 0x90(%rsp)
movzbl 0xbd(%rbp), %eax
movq %rax, 0x88(%rsp)
movq 0x10(%rbx), %r14
movq %rbx, %rdi
callq 0x1e0625
movq %rax, %r15
addq %r14, %r15
addq 0x40(%rbx), %r15
movq 0x30(%rbx), %r14
movq %rbx, %rdi
callq 0x1e0635
addq %r14, %rax
addq 0x40(%rbx), %rax
movzbl 0xc2(%rbp), %r10d
leaq 0xd8(%rsp), %r11
leaq 0x118(%rsp), %r14
leaq 0xb0(%rsp), %rdx
movl $0x1, %edi
movq 0x70(%rsp), %rsi
movq 0x80(%rsp), %rcx
movq 0x78(%rsp), %r8
movl 0x1c(%rsp), %r9d
pushq 0x50(%rbp)
pushq %r10
pushq 0x30(%rsp)
pushq %rax
pushq %r11
pushq 0x58(%rsp)
pushq %r13
pushq %r15
pushq %r14
pushq %r12
pushq 0xd8(%rsp)
pushq 0xe8(%rsp)
pushq 0xf8(%rsp)
pushq 0x108(%rsp)
callq 0x31d1d5
addq $0x70, %rsp
movl 0x4(%rsp), %edi
movq 0x28(%rsp), %r9
movq 0x8(%rsp), %rdx
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %r13
movq %rax, %r15
subq %r13, %r15
jb 0x1e1e1d
cmpb $0x1, 0xbc(%rbp)
jne 0x1e1cbb
cmpq 0x40(%rsp), %rax
jne 0x1e1e2c
cmpq %rdx, %r13
jne 0x1e1e31
movq 0xc0(%rsp), %rax
cmpq 0x50(%rsp), %rax
jne 0x1e1e36
xorl %r10d, %r10d
movq %rdx, %r13
jmp 0x1e1cbe
xorl %r10d, %r10d
movq 0xd0(%rsp), %rax
addq 0x60(%rsp), %rax
movq 0x40(%rbx), %rcx
addq %rdx, %r13
addq %rcx, %r13
addq %r9, %r15
addq %rcx, %r15
leaq (%r15,%r13), %rsi
xorl %ebp, %ebp
testb %dil, %dil
cmoveq %rax, %rbp
je 0x1e1d14
testq %r10, %r10
js 0x1e1d34
subq %r10, %rsi
jb 0x1e1e22
movabsq $0x5555555555555556, %rcx # imm = 0x5555555555555556
movq %rsi, %rax
imulq %rcx
movq %rdx, %r14
shrq $0x3f, %r14
addq %rdx, %r14
jmp 0x1e1d5a
movq 0xc0(%rsp), %r14
addq 0x50(%rsp), %r14
movq %r14, %rdi
movq %r9, %r12
callq 0x1bac84
movq %r12, %r9
movq %rax, %r10
jmp 0x1e1d5a
addq %r10, %rsi
movabsq $0x5555555555555555, %rcx # imm = 0x5555555555555555
movq %rsi, %rax
imulq %rcx
movq %rdx, %r14
subq %rsi, %r14
movq %r14, %rax
shrq $0x3f, %rax
sarq %r14
addq %rax, %r14
movq 0x18(%rbx), %r11
movq %r11, %r8
subq 0x8(%rsp), %r8
movq 0xa8(%rsp), %rdx
jb 0x1e1e13
movq 0x38(%rbx), %r12
movq %r12, %rax
subq %r9, %rax
jb 0x1e1e13
movq %r8, 0x20(%rdx)
leaq (%r8,%r13), %rcx
decq %rcx
movq %rcx, 0x28(%rdx)
movq %rax, 0x30(%rdx)
leaq -0x1(%r15,%rax), %rcx
movq %rcx, 0x38(%rdx)
movq %r14, 0x40(%rdx)
movq %rbp, 0x48(%rdx)
movq 0x8(%rdx), %rdi
testq %rdi, %rdi
je 0x1e1dff
movq 0x18(%rdx), %rsi
movq 0x10(%rbx), %r9
movq (%rbx), %rcx
movzbl 0x4c(%rbx), %edx
movq %rdx, 0x8(%rsp)
movq %r13, %rdx
pushq $0x0
pushq 0x40(%rbx)
pushq %r12
pushq %r11
pushq 0x28(%rbx)
pushq 0x30(%rbx)
pushq 0x40(%rsp)
pushq 0x70(%rsp)
pushq %rax
pushq %r15
pushq 0x20(%rbx)
pushq 0x60(%rsp)
pushq %rbp
pushq %r14
pushq %r10
pushq 0x8(%rbx)
callq 0x1bbef3
addq $0x80, %rsp
jmp 0x1e1e01
movb $0x1, %al
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x74fae
callq 0x74e91
callq 0x74f75
callq 0x74fe7
callq 0x7501e
callq 0x74eca
callq 0x74f03
callq 0x74f3c
callq 0x74e58