// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/esa-mmsearch.c
// Function: gt_querysubstringmatchiterator_next
int gt_querysubstringmatchiterator_next(GtQuerysubstringmatchiterator *qsmi,
                                        GtError *err)
{
  gt_assert(qsmi != NULL);
  while (true)
  {
    if (qsmi->query_seqlen < qsmi->userdefinedleastlength)
    {
      if (qsmi->seqit != NULL)
      {
        int retval = gt_seq_iterator_next(qsmi->seqit,
                                          &qsmi->query_for_seqit,
                                          &qsmi->query_seqlen,
                                          &qsmi->desc,
                                          err);
        if (retval < 0)
        {
          return -1; /* error */
        }
        if (retval == 0)
        {
          return 1; /* no more sequences */
        }
        gt_assert(qsmi->query_seqlen > 0 && qsmi->query_for_seqit != NULL);
        qsmi->queryrep.sequence = qsmi->query_for_seqit;
      } else
      {
        if (qsmi->queryunitnum == qsmi->query_encseq_numofsequences)
        {
          return 1;
        }
        qsmi->queryrep.startpos = gt_encseq_seqstartpos(qsmi->queryrep.encseq,
                                                        qsmi->queryunitnum);
        qsmi->query_seqlen = gt_encseq_seqlength(qsmi->queryrep.encseq,
                                                 qsmi->queryunitnum);
      }
      gt_assert(qsmi->query_seqlen > 0);
      qsmi->queryrep.seqlen = qsmi->query_seqlen;
      qsmi->querysubstring.currentoffset = 0;
    }
    if (qsmi->query_seqlen >= qsmi->userdefinedleastlength)
    {
      if (!qsmi->mmsi_defined)
      {
        gt_mmsearchiterator_reinit(qsmi->mmsi,
                                   qsmi->dbencseq,
                                   qsmi->suftabpart,
                                   0, /* l */
                                   qsmi->numberofsuffixes - 1, /* r */
                                   0, /* offset */
                                   qsmi->db_readmode,
                                   &qsmi->querysubstring,
                                   qsmi->userdefinedleastlength);
        qsmi->mmsi_defined = true;
      } else
      {
        if (gt_mmsearchiterator_next(&qsmi->dbstart,qsmi->mmsi))
        {
          GtUword extend;

          if (gt_mmsearch_isleftmaximal(qsmi->dbencseq,
                                        qsmi->db_readmode,
                                        qsmi->dbstart,
                                        &qsmi->querysubstring))
          {
            extend = gt_mmsearch_extendright(qsmi->dbencseq,
                                             qsmi->mmsi->esr,
                                             qsmi->db_readmode,
                                             qsmi->totallength,
                                             qsmi->dbstart +
                                               qsmi->userdefinedleastlength,
                                             &qsmi->querysubstring,
                                             qsmi->userdefinedleastlength);
            qsmi->matchlength = qsmi->userdefinedleastlength + extend;
            return 0;
          }
        } else
        {
          qsmi->mmsi_defined = false;
          if (qsmi->querysubstring.currentoffset +
              qsmi->userdefinedleastlength < qsmi->query_seqlen)
          {
            qsmi->querysubstring.currentoffset++;
          } else
          {
            qsmi->query_seqlen = 0;
            qsmi->queryunitnum++;
          }
        }
      }
    } else
    {
      qsmi->query_seqlen = 0;
      qsmi->queryunitnum++;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x150a36
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x78(%rdi), %r12
leaq 0x70(%rdi), %r13
leaq 0xa8(%rdi), %rbp
leaq 0x60(%rdi), %r14
leaq 0x88(%rdi), %rax
movq %rax, (%rsp)
movq 0x28(%rbx), %r10
movq 0x78(%rbx), %rax
cmpq %r10, %rax
jae 0x1508c7
movq 0x80(%rbx), %rdi
testq %rdi, %rdi
je 0x15087c
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0xa62e5
testl %eax, %eax
js 0x15097e
je 0x15097a
movq (%r12), %rax
testq %rax, %rax
je 0x1509d0
movq (%r13), %rcx
testq %rcx, %rcx
je 0x1509d0
movq %rcx, 0x38(%rbx)
jmp 0x1508ba
movq 0x98(%rbx), %rsi
cmpq 0xa0(%rbx), %rsi
je 0x15097a
movq 0x40(%rbx), %rdi
callq 0x74d9c
movq %rax, 0x50(%rbx)
movq 0x40(%rbx), %rdi
movq 0x98(%rbx), %rsi
callq 0x75173
movq %rax, 0x78(%rbx)
testq %rax, %rax
je 0x1509fe
movq %rax, 0x58(%rbx)
andq $0x0, 0x68(%rbx)
movq 0x28(%rbx), %r10
cmpq %r10, %rax
jae 0x1508dd
andq $0x0, 0x78(%rbx)
incq 0x98(%rbx)
jmp 0x150820
movq 0x30(%rbx), %rax
cmpb $0x0, 0xb0(%rbx)
je 0x150919
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x14fc8c
testb %al, %al
je 0x150952
movq (%rbx), %rdi
movl 0x10(%rbx), %esi
movq 0x88(%rbx), %rdx
movq %r14, %rcx
callq 0x150ef2
testb %al, %al
je 0x150820
jmp 0x150990
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x18(%rbx), %r8
decq %r8
movl 0x10(%rbx), %r11d
subq $0x8, %rsp
movq %rax, %rdi
xorl %ecx, %ecx
xorl %r9d, %r9d
pushq %r10
pushq %r14
pushq %r11
callq 0x150a64
addq $0x20, %rsp
movb $0x1, 0xb0(%rbx)
jmp 0x150820
movb $0x0, 0xb0(%rbx)
movq 0x68(%rbx), %rax
movq 0x28(%rbx), %rcx
addq %rax, %rcx
cmpq 0x78(%rbx), %rcx
jae 0x1508cc
incq %rax
movq %rax, 0x68(%rbx)
jmp 0x150820
pushq $0x1
jmp 0x150980
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rdi
movq 0x30(%rbx), %rax
movq 0x28(%rax), %rsi
movl 0x10(%rbx), %edx
movq 0x20(%rbx), %rcx
movq 0x28(%rbx), %rax
movq 0x88(%rbx), %r8
addq %rax, %r8
subq $0x8, %rsp
movq %r14, %r9
pushq %rax
callq 0x150f38
addq $0x10, %rsp
addq 0x28(%rbx), %rax
movq %rax, 0x90(%rbx)
xorl %eax, %eax
jmp 0x150981
movq 0x2e7591(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x194632(%rip), %rsi    # 0x2e5013
leaq 0x1f4535(%rip), %rdx    # 0x344f1d
leaq 0x1f450a(%rip), %rcx    # 0x344ef9
leaq 0x1f422c(%rip), %r8     # 0x344c22
movl $0x367, %r9d            # imm = 0x367
jmp 0x150a2a
movq 0x2e7563(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x194604(%rip), %rsi    # 0x2e5013
leaq 0x1f453f(%rip), %rdx    # 0x344f55
leaq 0x1f44dc(%rip), %rcx    # 0x344ef9
leaq 0x1f41fe(%rip), %r8     # 0x344c22
movl $0x374, %r9d            # imm = 0x374
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x2e752b(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1945cc(%rip), %rsi    # 0x2e5013
leaq 0x1f4330(%rip), %rdx    # 0x344d7e
leaq 0x1f44a4(%rip), %rcx    # 0x344ef9
leaq 0x1f41c6(%rip), %r8     # 0x344c22
movl $0x353, %r9d            # imm = 0x353
jmp 0x150a2a