// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/ltr/ltrharvest_stream.c
// Function: searchforbestTSDandormotifatborders
static void searchforbestTSDandormotifatborders(const SubRepeatInfo
                                                                 *subrepeatinfo,
                                                const GtLTRharvestStream *lo,
                                                LTRboundaries *boundaries,
                                                LTRMotifmismatches *mismatches)
{
  GtUword motifpos1,
                motifpos2,
                back, forward,
                oldleftLTR_5  = boundaries->leftLTR_5,
                oldrightLTR_3 = boundaries->rightLTR_3,
                difffromoldboundary1 = 0,
                difffromoldboundary2 = 0;
  LTRMotifmismatches tmp_mm;
  Repeat *rep;

  if (subrepeatinfo->repeats.nextfreeRepeat > 0)
  {
    boundaries->tsd = true;
  }
  boundaries->motif_near_tsd = false;

  for (rep = subrepeatinfo->repeats.spaceRepeat;
       rep < subrepeatinfo->repeats.spaceRepeat +
             subrepeatinfo->repeats.nextfreeRepeat; rep++)
  {
    /* motifpos1 is the first position after the left repeat */
    motifpos1 = rep->pos1 + rep->len;
    /* motifpos2 is two positions before the right repeat */
    motifpos2 = rep->pos1 + rep->offset - 2;

    for (back = 0; back < rep->len - subrepeatinfo->tsd_lmin + 1; back++)
    {
      for (forward = 0;
           forward < rep->len - subrepeatinfo->tsd_lmin + 1 - back;
           forward++)
      {
        tmp_mm.left = tmp_mm.right = 0;
        if (gt_encseq_get_encoded_char(/* Random access */ lo->encseq,
                                       motifpos1 - back, GT_READMODE_FORWARD)
            != lo->motif->firstleft)
        {
          tmp_mm.left++;
        }
        if (gt_encseq_get_encoded_char(/* Random access */ lo->encseq,
                                              motifpos1 + 1 - back,
                                              GT_READMODE_FORWARD)
            != lo->motif->secondleft)
        {
          tmp_mm.left++;
        }
        if (gt_encseq_get_encoded_char(/* Random access */ lo->encseq,
                                              motifpos2 + forward,
                                              GT_READMODE_FORWARD)
            != lo->motif->firstright)
        {
          tmp_mm.right++;
        }
        if (gt_encseq_get_encoded_char(/* Random access */ lo->encseq,
                                              motifpos2 + 1 + forward,
                                              GT_READMODE_FORWARD)
            != lo->motif->secondright)
        {
          tmp_mm.right++;
        }

        if (tmp_mm.left <= lo->motif->allowedmismatches
            && tmp_mm.right <= lo->motif->allowedmismatches)
        {
          const GtUword tsd_len = rep->len - back - forward;

          /* TSD length not too big */
          if (tsd_len <= subrepeatinfo->tsd_lmax)
          {
            if (!boundaries->motif_near_tsd)
            {
              GtUword max, min;

              /* save number of mismatches */
              *mismatches = tmp_mm;

              /* adjust boundaries */
              boundaries->motif_near_tsd = true;
              boundaries->leftLTR_5  = motifpos1 - back;
              boundaries->rightLTR_3 = motifpos2 + 1 + forward;

              /* store TSD length */
              boundaries->lenleftTSD = boundaries->lenrightTSD = tsd_len;

              max = GT_MAX(oldleftLTR_5, boundaries->leftLTR_5);
              min = GT_MIN(oldleftLTR_5, boundaries->leftLTR_5);
              difffromoldboundary1 = max - min;

              max = GT_MAX(oldrightLTR_3, boundaries->rightLTR_3);
              min = GT_MIN(oldrightLTR_3, boundaries->rightLTR_3);
              difffromoldboundary2 = max - min;

            } else
            {
              GtUword max, min, difffromnewboundary1,
                   difffromnewboundary2;

              /* test if hit is nearer to old boundaries than previous hit */
              max = GT_MAX(oldleftLTR_5, motifpos1 - back);
              min = GT_MIN(oldleftLTR_5, motifpos1 - back);
              difffromnewboundary1 = max - min;
              max = GT_MAX(oldrightLTR_3, motifpos2 + 1 + forward);
              min = GT_MIN(oldrightLTR_3, motifpos2 + 1 + forward);
              difffromnewboundary2 = max - min;

              if (difffromnewboundary1 + difffromnewboundary2 <
                  difffromoldboundary1 + difffromoldboundary2)
              {
                /* save number of mismatches */
                *mismatches = tmp_mm;

                /* adjust boundaries */
                boundaries->leftLTR_5  = motifpos1 - back;
                boundaries->rightLTR_3 = motifpos2 + 1 + forward;

                /* store TSD length */
                boundaries->lenleftTSD = boundaries->lenrightTSD = tsd_len;

                difffromoldboundary1 = difffromnewboundary1;
                difffromoldboundary2 = difffromnewboundary2;
              }
            }
          }
        }
      }
    }
  }
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movq %rcx, 0xc8(%rsp)
movq 0xd0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xa0(%rsp)
movq 0xd0(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x98(%rsp)
movq $0x0, 0x90(%rsp)
movq $0x0, 0x88(%rsp)
movq 0xe0(%rsp), %rax
cmpq $0x0, 0x10(%rax)
jbe 0x3124b2
movq 0xd0(%rsp), %rax
movb $0x1, 0x38(%rax)
movq 0xd0(%rsp), %rax
movb $0x0, 0x39(%rax)
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq 0xe0(%rsp), %rcx
movq (%rcx), %rcx
movq 0xe0(%rsp), %rdx
movq 0x10(%rdx), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x312b7d
movq 0x78(%rsp), %rax
movq (%rax), %rax
movq 0x78(%rsp), %rcx
addq 0x10(%rcx), %rax
movq %rax, 0xc0(%rsp)
movq 0x78(%rsp), %rax
movq (%rax), %rax
movq 0x78(%rsp), %rcx
addq 0x8(%rcx), %rax
subq $0x2, %rax
movq %rax, 0xb8(%rsp)
movq $0x0, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq 0x78(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0xe0(%rsp), %rdx
subq 0x18(%rdx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x312b68
movq $0x0, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
movq 0x78(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq 0xe0(%rsp), %rdx
subq 0x18(%rdx), %rcx
addq $0x1, %rcx
subq 0xb0(%rsp), %rcx
cmpq %rcx, %rax
jae 0x312b4d
movl $0x0, 0x84(%rsp)
movl $0x0, 0x80(%rsp)
movq 0xd8(%rsp), %rax
movq 0xd8(%rax), %rdi
movq 0xc0(%rsp), %rsi
subq 0xb0(%rsp), %rsi
xorl %edx, %edx
callq 0xa9da0
movzbl %al, %eax
movq 0xd8(%rsp), %rcx
movq 0x88(%rcx), %rcx
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
je 0x31260b
movl 0x80(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x80(%rsp)
movq 0xd8(%rsp), %rax
movq 0xd8(%rax), %rdi
movq 0xc0(%rsp), %rsi
addq $0x1, %rsi
subq 0xb0(%rsp), %rsi
xorl %edx, %edx
callq 0xa9da0
movzbl %al, %eax
movq 0xd8(%rsp), %rcx
movq 0x88(%rcx), %rcx
movzbl 0x9(%rcx), %ecx
cmpl %ecx, %eax
je 0x312660
movl 0x80(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x80(%rsp)
movq 0xd8(%rsp), %rax
movq 0xd8(%rax), %rdi
movq 0xb8(%rsp), %rsi
addq 0xa8(%rsp), %rsi
xorl %edx, %edx
callq 0xa9da0
movzbl %al, %eax
movq 0xd8(%rsp), %rcx
movq 0x88(%rcx), %rcx
movzbl 0xa(%rcx), %ecx
cmpl %ecx, %eax
je 0x3126b1
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
movq 0xd8(%rsp), %rax
movq 0xd8(%rax), %rdi
movq 0xb8(%rsp), %rsi
addq $0x1, %rsi
addq 0xa8(%rsp), %rsi
xorl %edx, %edx
callq 0xa9da0
movzbl %al, %eax
movq 0xd8(%rsp), %rcx
movq 0x88(%rcx), %rcx
movzbl 0xb(%rcx), %ecx
cmpl %ecx, %eax
je 0x312706
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
movl 0x80(%rsp), %eax
movq 0xd8(%rsp), %rcx
movq 0x88(%rcx), %rcx
cmpl 0xc(%rcx), %eax
ja 0x312b32
movl 0x84(%rsp), %eax
movq 0xd8(%rsp), %rcx
movq 0x88(%rcx), %rcx
cmpl 0xc(%rcx), %eax
ja 0x312b32
movq 0x78(%rsp), %rax
movq 0x10(%rax), %rax
subq 0xb0(%rsp), %rax
subq 0xa8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq 0xe0(%rsp), %rcx
cmpq 0x20(%rcx), %rax
ja 0x312b30
movq 0xd0(%rsp), %rax
testb $0x1, 0x39(%rax)
jne 0x31292c
movq 0xc8(%rsp), %rax
movq 0x80(%rsp), %rcx
movq %rcx, (%rax)
movq 0xd0(%rsp), %rax
movb $0x1, 0x39(%rax)
movq 0xc0(%rsp), %rcx
subq 0xb0(%rsp), %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0xb8(%rsp), %rcx
addq $0x1, %rcx
addq 0xa8(%rsp), %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x70(%rsp), %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0xd0(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0xa0(%rsp), %rax
movq 0xd0(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x312828
movq 0xa0(%rsp), %rax
movq %rax, 0x38(%rsp)
jmp 0x312839
movq 0xd0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0xa0(%rsp), %rax
movq 0xd0(%rsp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x312868
movq 0xa0(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x312879
movq 0xd0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rax
subq 0x60(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rax
movq 0xd0(%rsp), %rcx
cmpq 0x20(%rcx), %rax
jbe 0x3128ba
movq 0x98(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x3128cb
movq 0xd0(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x98(%rsp), %rax
movq 0xd0(%rsp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x3128fa
movq 0x98(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x31290b
movq 0xd0(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rax
subq 0x60(%rsp), %rax
movq %rax, 0x88(%rsp)
jmp 0x312b2e
movq 0xa0(%rsp), %rax
movq 0xc0(%rsp), %rcx
subq 0xb0(%rsp), %rcx
cmpq %rcx, %rax
jbe 0x312958
movq 0xa0(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x31296d
movq 0xc0(%rsp), %rax
subq 0xb0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0xa0(%rsp), %rax
movq 0xc0(%rsp), %rcx
subq 0xb0(%rsp), %rcx
cmpq %rcx, %rax
jae 0x3129a3
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x3129b8
movq 0xc0(%rsp), %rax
subq 0xb0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x98(%rsp), %rax
movq 0xb8(%rsp), %rcx
addq $0x1, %rcx
addq 0xa8(%rsp), %rcx
cmpq %rcx, %rax
jbe 0x312a01
movq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0x312a1a
movq 0xb8(%rsp), %rax
addq $0x1, %rax
addq 0xa8(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x98(%rsp), %rax
movq 0xb8(%rsp), %rcx
addq $0x1, %rcx
addq 0xa8(%rsp), %rcx
cmpq %rcx, %rax
jae 0x312a53
movq 0x98(%rsp), %rax
movq %rax, (%rsp)
jmp 0x312a6b
movq 0xb8(%rsp), %rax
addq $0x1, %rax
addq 0xa8(%rsp), %rax
movq %rax, (%rsp)
movq (%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
addq 0x40(%rsp), %rax
movq 0x90(%rsp), %rcx
addq 0x88(%rsp), %rcx
cmpq %rcx, %rax
jae 0x312b2c
movq 0xc8(%rsp), %rax
movq 0x80(%rsp), %rcx
movq %rcx, (%rax)
movq 0xc0(%rsp), %rcx
subq 0xb0(%rsp), %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0xb8(%rsp), %rcx
addq $0x1, %rcx
addq 0xa8(%rsp), %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x70(%rsp), %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0xd0(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x48(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x88(%rsp)
jmp 0x312b2e
jmp 0x312b30
jmp 0x312b32
jmp 0x312b34
movq 0xa8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa8(%rsp)
jmp 0x312572
jmp 0x312b4f
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0x31253c
jmp 0x312b6a
movq 0x78(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x78(%rsp)
jmp 0x3124ce
addq $0xe8, %rsp
retq
nopw %cs:(%rax,%rax)