// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/match/sfx-bentsedg.c
// Function: bs_insertionsortmaxdepth
static void bs_insertionsortmaxdepth(GtBentsedgresources *bsr,
                                     GtUword subbucketleft,
                                     GtUword width,
                                     GtUword offset,
                                     GtUword sortmaxdepth)
{
  GtUword sval1, sval2, pm, pl, startpos1, startpos2,
                lcplen = 0, idx = 0;
  int retval;
  bool tempb;
  GtCommonunits commonunits;

  bsr->countinsertionsort++;
  for (pm = 1UL; pm < width; pm++)
  {
    for (pl = pm; pl > 0; pl--)
    {
      sval1 = gt_suffixsortspace_get(bsr->sssp,subbucketleft,pl-1);
      sval2 = gt_suffixsortspace_get(bsr->sssp,subbucketleft,pl);
      if (bsr->sfxstrategy->cmpcharbychar)
      {
        GtUword endpos1, endpos2;

        endpos1 = sval1+sortmaxdepth;
        if (endpos1 > bsr->totallength)
        {
          endpos1 = bsr->totallength;
        }
        endpos2 = sval2+sortmaxdepth;
        if (endpos2 > bsr->totallength)
        {
          endpos2 = bsr->totallength;
        }
        startpos1 = sval1+offset;
        if (startpos1 < bsr->totallength)
        {
          gt_encseq_reader_reinit_with_readmode(bsr->esr1, bsr->encseq,
                                                bsr->readmode, startpos1);
        }
        startpos2 = sval2+offset;
        if (startpos2 < bsr->totallength)
        {
          gt_encseq_reader_reinit_with_readmode(bsr->esr2, bsr->encseq,
                                                bsr->readmode, startpos2);
        }
        for (;;)
        {
          GtUword ccs, cct;
          GtUchar tmp1, tmp2;

          ccs = DEREFSTOPPOSSEQ(tmp1,startpos1,endpos1,bsr->esr1);
          cct = DEREFSTOPPOSSEQ(tmp2,startpos2,endpos2,bsr->esr2);
          lcplen = startpos2 - sval2;
          if (lcplen == sortmaxdepth)
          {
            retval = 0;
            break;
          }
          gt_assert(lcplen < sortmaxdepth);
          if (ccs != cct)
          {
            retval = (ccs < cct) ? -1 : 1;
            break;
          }
          startpos1++;
          startpos2++;
        }
      } else
      {
        gt_assert(offset < sortmaxdepth);
        retval = gt_encseq_compare_viatwobitencoding(&commonunits,
                                                     bsr->encseq,
                                                     bsr->encseq,
                                                     bsr->readmode,
                                                     bsr->esr1,
                                                     bsr->esr2,
                                                     sval1,
                                                     sval2,
                                                     offset,
                                                     sortmaxdepth);
        lcplen = commonunits.finaldepth;
        gt_assert(lcplen <= sortmaxdepth);
        if (lcplen == sortmaxdepth)
        {
          gt_assert(retval == 0);
        }
      }
#ifdef SKDEBUG
      printf("cmp "GT_WU" and "GT_WU": retval = %d, lcplen = "GT_WU"\n",
             sval1, sval2, retval, (GtUword) lcplen);
#endif
      if (bsr->tableoflcpvalues != NULL)
      {
        if (pl < pm && retval > 0)
        {
          gt_lcptab_update(bsr->tableoflcpvalues,subbucketleft,pl+1,
                           gt_lcptab_getvalue(bsr->tableoflcpvalues,
                                              subbucketleft,pl));
        }
        gt_lcptab_update(bsr->tableoflcpvalues,subbucketleft,pl,lcplen);
      }
      if (retval < 0)
      {
        break;
      }
      idx = pl;
      if (retval == 0)
      {
        gt_assert(idx > 0);
        bsr->equalwithprevious[idx] = true;
        break;
      }
      gt_suffixsortspace_set(bsr->sssp,subbucketleft,pl-1,sval2);
      gt_suffixsortspace_set(bsr->sssp,subbucketleft,pl,sval1);
      tempb = bsr->equalwithprevious[idx-1];
      bsr->equalwithprevious[idx-1] = bsr->equalwithprevious[idx];
      bsr->equalwithprevious[idx] = tempb;
    }
  }
  if (idx > 0)
  {
    GtUword equalsrangewidth = 0,
            bucketleftidx = gt_suffixsortspace_bucketleftidx_get(bsr->sssp);

#ifdef SKDEBUG
    printf("ordered suffix "GT_WU"\n",gt_suffixsortspace_get(bsr->sssp,
                                                         subbucketleft,0));
#endif
    for (idx = 1UL; idx < width; idx++)
    {
#ifdef SKDEBUG
      printf("ordered suffix "GT_WU", equalwithprevious=%s\n",
              gt_suffixsortspace_get(bsr->sssp,subbucketleft,idx),
              bsr->equalwithprevious[idx] ? "true" : "false");
#endif
      if (bsr->equalwithprevious[idx])
      {
        bsr->equalwithprevious[idx] = false;
        equalsrangewidth++;
      } else
      {
        if (equalsrangewidth > 0)
        {
#ifdef SKDEBUG
          printf("process interval of width "GT_WU"\n",
                 equalsrangewidth + 1);
#endif
          if (bsr->processunsortedsuffixrange != NULL)
          {
            bsr->processunsortedsuffixrange(bsr->processunsortedsuffixrangeinfo,
                                            bsr->sssp,
                                            bucketleftidx + subbucketleft
                                                          + idx - 1
                                                          - equalsrangewidth,
                                            equalsrangewidth + 1, sortmaxdepth);
          }
          equalsrangewidth = 0;
        }
      }
    }
    if (equalsrangewidth > 0)
    {
#ifdef SKDEBUG
      printf("process interval of width "GT_WU"\n",
             equalsrangewidth + 1);
#endif
      if (bsr->processunsortedsuffixrange != NULL)
      {
        bsr->processunsortedsuffixrange(bsr->processunsortedsuffixrangeinfo,
                                        bsr->sssp,
                                        bucketleftidx + subbucketleft + width
                                                      - 1 - equalsrangewidth,
                                        equalsrangewidth + 1, sortmaxdepth);
      }
    }
  }
}

// Assembly:
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movq %rcx, 0xe0(%rsp)
movq %r8, 0xd8(%rsp)
movq $0x0, 0xa0(%rsp)
movq $0x0, 0x98(%rsp)
movq 0xf8(%rsp), %rax
movq 0x68(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x68(%rax)
movq $0x1, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
cmpq 0xe8(%rsp), %rax
jae 0x2b6695
movq 0xc0(%rsp), %rax
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jbe 0x2b667a
movq 0xf8(%rsp), %rax
movq 0x48(%rax), %rdi
movq 0xf0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
subq $0x1, %rdx
callq 0x2e9ec0
movq %rax, 0xd0(%rsp)
movq 0xf8(%rsp), %rax
movq 0x48(%rax), %rdi
movq 0xf0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
callq 0x2e9ec0
movq %rax, 0xc8(%rsp)
movq 0xf8(%rsp), %rax
movq 0x40(%rax), %rax
testb $0x1, 0x2c(%rax)
je 0x2b62b0
movq 0xd0(%rsp), %rax
addq 0xd8(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq 0xf8(%rsp), %rcx
cmpq 0xb0(%rcx), %rax
jbe 0x2b6018
movq 0xf8(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0x78(%rsp)
movq 0xc8(%rsp), %rax
addq 0xd8(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq 0xf8(%rsp), %rcx
cmpq 0xb0(%rcx), %rax
jbe 0x2b6057
movq 0xf8(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0xd0(%rsp), %rax
addq 0xe0(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq 0xf8(%rsp), %rcx
cmpq 0xb0(%rcx), %rax
jae 0x2b60b7
movq 0xf8(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0xf8(%rsp), %rax
movq (%rax), %rsi
movq 0xf8(%rsp), %rax
movl 0x18(%rax), %edx
movq 0xb0(%rsp), %rcx
callq 0xabdb0
movq 0xc8(%rsp), %rax
addq 0xe0(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
movq 0xf8(%rsp), %rcx
cmpq 0xb0(%rcx), %rax
jae 0x2b6117
movq 0xf8(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0xf8(%rsp), %rax
movq (%rax), %rsi
movq 0xf8(%rsp), %rax
movl 0x18(%rax), %edx
movq 0xa8(%rsp), %rcx
callq 0xabdb0
jmp 0x2b6119
movq 0xb0(%rsp), %rax
cmpq 0x78(%rsp), %rax
jae 0x2b6153
movq 0xf8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xaae30
movb %al, 0x5f(%rsp)
movzbl %al, %eax
cmpl $0xfe, %eax
jge 0x2b6153
movzbl 0x5f(%rsp), %eax
movq %rax, 0x40(%rsp)
jmp 0x2b6166
movq 0xb0(%rsp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0xa8(%rsp), %rax
cmpq 0x70(%rsp), %rax
jae 0x2b61aa
movq 0xf8(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0xaae30
movb %al, 0x5e(%rsp)
movzbl %al, %eax
cmpl $0xfe, %eax
jge 0x2b61aa
movzbl 0x5e(%rsp), %eax
movq %rax, 0x38(%rsp)
jmp 0x2b61bd
movq 0xa8(%rsp), %rax
addq $0x100, %rax            # imm = 0x100
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xa8(%rsp), %rax
subq 0xc8(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jne 0x2b6201
movl $0x0, 0x94(%rsp)
jmp 0x2b62ab
jmp 0x2b6203
movq 0xa0(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jb 0x2b624d
movq 0x385d84(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x25fded(%rip), %rsi    # 0x516013
leaq 0x2d2608(%rip), %rdx    # 0x588835
leaq 0x2d2617(%rip), %rcx    # 0x58884b
leaq 0x2d2335(%rip), %r8     # 0x588570
movl $0x1a9, %r9d            # imm = 0x1A9
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2b624f
movq 0x68(%rsp), %rax
cmpq 0x60(%rsp), %rax
je 0x2b627e
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rsi
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rsi, %rdx
cmovbl %ecx, %eax
movl %eax, 0x94(%rsp)
jmp 0x2b62ab
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
movq 0xa8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa8(%rsp)
jmp 0x2b6119
jmp 0x2b6436
jmp 0x2b62b2
movq 0xe0(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jb 0x2b62fc
movq 0x385cd5(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x25fd3e(%rip), %rsi    # 0x516013
leaq 0x2d2a7a(%rip), %rdx    # 0x588d56
leaq 0x2d2568(%rip), %rcx    # 0x58884b
leaq 0x2d2286(%rip), %r8     # 0x588570
movl $0x1b4, %r9d            # imm = 0x1B4
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2b62fe
movq 0xf8(%rsp), %rax
movq (%rax), %rsi
movq 0xf8(%rsp), %rax
movq (%rax), %rdx
movq 0xf8(%rsp), %rax
movl 0x18(%rax), %ecx
movq 0xf8(%rsp), %rax
movq 0x8(%rax), %r8
movq 0xf8(%rsp), %rax
movq 0x10(%rax), %r9
movq 0xd0(%rsp), %rbx
movq 0xc8(%rsp), %r11
movq 0xe0(%rsp), %r10
movq 0xd8(%rsp), %rax
leaq 0x80(%rsp), %rdi
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0xb53f0
movl %eax, 0x94(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jbe 0x2b63d8
movq 0x385bf9(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x25fc62(%rip), %rsi    # 0x516013
leaq 0x2d24ac(%rip), %rdx    # 0x588864
leaq 0x2d248c(%rip), %rcx    # 0x58884b
leaq 0x2d21aa(%rip), %r8     # 0x588570
movl $0x1c0, %r9d            # imm = 0x1C0
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2b63da
movq 0xa0(%rsp), %rax
cmpq 0xd8(%rsp), %rax
jne 0x2b6434
jmp 0x2b63ee
cmpl $0x0, 0x94(%rsp)
je 0x2b6430
movq 0x385ba1(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x25fc0a(%rip), %rsi    # 0x516013
leaq 0x283915(%rip), %rdx    # 0x539d25
leaq 0x2d2434(%rip), %rcx    # 0x58884b
leaq 0x2d2152(%rip), %r8     # 0x588570
movl $0x1c3, %r9d            # imm = 0x1C3
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2b6432
jmp 0x2b6434
jmp 0x2b6436
movq 0xf8(%rsp), %rax
cmpq $0x0, 0x38(%rax)
je 0x2b64f5
movq 0xb8(%rsp), %rax
cmpq 0xc0(%rsp), %rax
jae 0x2b64cc
cmpl $0x0, 0x94(%rsp)
jle 0x2b64cc
movq 0xf8(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xb8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x30(%rsp)
movq 0xf8(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0xf0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
callq 0x2b6840
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %rax, %rcx
callq 0x2b5700
movq 0xf8(%rsp), %rax
movq 0x38(%rax), %rdi
movq 0xf0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq 0xa0(%rsp), %rcx
callq 0x2b5700
cmpl $0x0, 0x94(%rsp)
jge 0x2b6504
jmp 0x2b667a
movq 0xb8(%rsp), %rax
movq %rax, 0x98(%rsp)
cmpl $0x0, 0x94(%rsp)
jne 0x2b6585
jmp 0x2b6520
cmpq $0x0, 0x98(%rsp)
ja 0x2b6563
movq 0x385a6e(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x25fad7(%rip), %rsi    # 0x516013
leaq 0x2839d0(%rip), %rdx    # 0x539f13
leaq 0x2d2301(%rip), %rcx    # 0x58884b
leaq 0x2d201f(%rip), %r8     # 0x588570
movl $0x1db, %r9d            # imm = 0x1DB
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2b6565
movq 0xf8(%rsp), %rax
movq 0x2c0(%rax), %rax
movq 0x98(%rsp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x2b667a
movq 0xf8(%rsp), %rax
movq 0x48(%rax), %rdi
movq 0xf0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
subq $0x1, %rdx
movq 0xc8(%rsp), %rcx
callq 0x2ea0a0
movq 0xf8(%rsp), %rax
movq 0x48(%rax), %rdi
movq 0xf0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq 0xd0(%rsp), %rcx
callq 0x2ea0a0
movq 0xf8(%rsp), %rax
movq 0x2c0(%rax), %rax
movq 0x98(%rsp), %rcx
subq $0x1, %rcx
movb (%rax,%rcx), %al
andb $0x1, %al
movb %al, 0x93(%rsp)
movq 0xf8(%rsp), %rax
movq 0x2c0(%rax), %rax
movq 0x98(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0xf8(%rsp), %rax
movq 0x2c0(%rax), %rax
movq 0x98(%rsp), %rcx
subq $0x1, %rcx
andb $0x1, %dl
movb %dl, (%rax,%rcx)
movb 0x93(%rsp), %dl
movq 0xf8(%rsp), %rax
movq 0x2c0(%rax), %rax
movq 0x98(%rsp), %rcx
andb $0x1, %dl
movb %dl, (%rax,%rcx)
movq 0xb8(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xb8(%rsp)
jmp 0x2b5f5e
jmp 0x2b667c
movq 0xc0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc0(%rsp)
jmp 0x2b5f38
cmpq $0x0, 0x98(%rsp)
jbe 0x2b682f
movq $0x0, 0x50(%rsp)
movq 0xf8(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x2ea3a0
movq %rax, 0x48(%rsp)
movq $0x1, 0x98(%rsp)
movq 0x98(%rsp), %rax
cmpq 0xe8(%rsp), %rax
jae 0x2b67bf
movq 0xf8(%rsp), %rax
movq 0x2c0(%rax), %rax
movq 0x98(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x2b672d
movq 0xf8(%rsp), %rax
movq 0x2c0(%rax), %rax
movq 0x98(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x2b67a4
cmpq $0x0, 0x50(%rsp)
jbe 0x2b67a2
movq 0xf8(%rsp), %rax
cmpq $0x0, 0x50(%rax)
je 0x2b6799
movq 0xf8(%rsp), %rax
movq 0x50(%rax), %rax
movq 0xf8(%rsp), %rcx
movq 0x58(%rcx), %rdi
movq 0xf8(%rsp), %rcx
movq 0x48(%rcx), %rsi
movq 0x48(%rsp), %rdx
addq 0xf0(%rsp), %rdx
addq 0x98(%rsp), %rdx
subq $0x1, %rdx
subq 0x50(%rsp), %rdx
movq 0x50(%rsp), %rcx
addq $0x1, %rcx
movq 0xd8(%rsp), %r8
callq *%rax
movq $0x0, 0x50(%rsp)
jmp 0x2b67a4
jmp 0x2b67a6
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
jmp 0x2b66cf
cmpq $0x0, 0x50(%rsp)
jbe 0x2b682d
movq 0xf8(%rsp), %rax
cmpq $0x0, 0x50(%rax)
je 0x2b682b
movq 0xf8(%rsp), %rax
movq 0x50(%rax), %rax
movq 0xf8(%rsp), %rcx
movq 0x58(%rcx), %rdi
movq 0xf8(%rsp), %rcx
movq 0x48(%rcx), %rsi
movq 0x48(%rsp), %rdx
addq 0xf0(%rsp), %rdx
addq 0xe8(%rsp), %rdx
subq $0x1, %rdx
subq 0x50(%rsp), %rdx
movq 0x50(%rsp), %rcx
addq $0x1, %rcx
movq 0xd8(%rsp), %r8
callq *%rax
jmp 0x2b682d
jmp 0x2b682f
addq $0x100, %rsp            # imm = 0x100
popq %rbx
retq
nopl (%rax,%rax)