// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/sfx-linlcp.c
// Function: gt_plain_lcp_phialgorithm
unsigned int *gt_plain_lcp_phialgorithm(bool onlyplcp,
                                        GtUword *maxlcp,
                                        const GtUchar *sequence,
                                        bool withspecial,
                                        GtUword partwidth,
                                        GtUword totallength,
                                        const unsigned int *suftab)
{
  unsigned int *plcptab, *phitab, pos, suftab0, previousvalue;
  GtUword idx, lcpvalue = 0;

  phitab = gt_malloc(sizeof (*phitab) * (totallength+1));
  previousvalue = suftab[0];
  for (idx = 1UL; idx <= totallength; idx++)
  {
    unsigned int currentvalue = suftab[idx];
    phitab[currentvalue] = previousvalue;
    previousvalue = currentvalue;
  }
  plcptab = phitab; /* overlay both arrays */
  suftab0 = suftab[0];
  gt_assert(totallength <= (GtUword) UINT_MAX);
  *maxlcp = 0;
  for (pos = 0; pos < (unsigned int) totallength; pos++)
  {
    if (pos != suftab0)
    {
      const unsigned int currentphitab = phitab[pos];
      const GtUword lastoffset = totallength - GT_MAX(pos,currentphitab);
      const GtUchar *ptr1 = sequence + pos,
                    *ptr2 = sequence + currentphitab;

      while (lcpvalue < lastoffset)
      {
        GtUchar cc1 = ptr1[lcpvalue];
        GtUchar cc2 = ptr2[lcpvalue];
        if (cc1 == cc2 && (!withspecial || GT_ISNOTSPECIAL(cc1)))
        {
          lcpvalue++;
        } else
        {
          break;
        }
      }
      gt_assert(lcpvalue <= (GtUword) UINT_MAX);
      plcptab[pos] = (unsigned int) lcpvalue;
      if (lcpvalue > 0)
      {
        if (*maxlcp < lcpvalue)
        {
          *maxlcp = lcpvalue;
        }
        lcpvalue--;
      }
    } else
    {
      plcptab[pos] = 0;
    }
  }
  if (onlyplcp)
  {
    return plcptab;
  } else
  {
    unsigned int *lcptab = gt_malloc(sizeof (*lcptab) * (totallength+1));

    for (idx = 0; idx < partwidth; idx++)
    {
      lcptab[idx] = plcptab[suftab[idx]];
    }
    gt_free(plcptab);
    for (idx = partwidth; idx <= totallength; idx++)
    {
      lcptab[idx] = 0;
    }
    return lcptab;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movq %r8, 0x18(%rsp)
movl %ecx, %r13d
movq %rdx, 0x10(%rsp)
movq %rsi, %r14
movl %edi, 0x4(%rsp)
movq 0x60(%rsp), %rbp
leaq 0x4(,%r9,4), %rdi
leaq 0x1ca8be(%rip), %rsi    # 0x3b7c11
movq %rdi, 0x20(%rsp)
movl $0x8e, %edx
callq 0x104226
movq %rax, %r15
testq %rbx, %rbx
je 0x1ed475
movl (%rbp), %ecx
leaq 0x1(%rbx), %rdx
cmpq $0x3, %rdx
movl $0x2, %eax
cmovaeq %rdx, %rax
movl $0x1, %edx
movl (%rbp,%rdx,4), %esi
movl %ecx, (%r15,%rsi,4)
incq %rdx
movl %esi, %ecx
cmpq %rdx, %rax
jne 0x1ed387
movq %rbx, %rax
shrq $0x20, %rax
jne 0x1ed507
movl (%rbp), %eax
movq $0x0, (%r14)
testq %rbx, %rbx
je 0x1ed47c
movq $0x0, 0x8(%rsp)
movq 0x10(%rsp), %rcx
xorl %esi, %esi
xorl %edi, %edi
cmpq %rax, %rsi
jne 0x1ed3dd
movl $0x0, (%r15,%rax,4)
jmp 0x1ed464
movl (%r15,%rsi,4), %r11d
cmpl %r11d, %esi
movl %r11d, %r8d
cmoval %esi, %r8d
movq %rbx, %r9
subq %r8, %r9
movq 0x10(%rsp), %rdx
leaq (%rdx,%r11), %r10
cmpq %r11, %rsi
cmovaq %rsi, %r11
movq %rbx, %r8
subq %r11, %r8
cmpq %r8, %rdi
cmovaq %rdi, %r8
cmpq %r9, %rdi
jae 0x1ed435
movb (%rcx,%rdi), %dl
cmpb $-0x2, %dl
setae %r12b
leaq 0x1(%rdi), %r11
cmpb (%r10,%rdi), %dl
jne 0x1ed42f
movq %r11, %rdi
andb %r13b, %r12b
je 0x1ed40e
decq %r11
movq %r11, %r8
movq %r8, %rdx
shrq $0x20, %rdx
jne 0x1ed502
movl %r8d, (%r15,%rsi,4)
testq %r8, %r8
je 0x1ed462
cmpq %r8, 0x8(%rsp)
jae 0x1ed45a
movq %r8, (%r14)
movq %r8, 0x8(%rsp)
decq %r8
movq %r8, %rdi
jmp 0x1ed464
xorl %edi, %edi
incq %rsi
incq %rcx
cmpq %rbx, %rsi
jne 0x1ed3cb
jmp 0x1ed47c
movq $0x0, (%r14)
cmpb $0x0, 0x4(%rsp)
je 0x1ed488
movq %r15, %r12
jmp 0x1ed4f0
leaq 0x1ca782(%rip), %rsi    # 0x3b7c11
movq 0x20(%rsp), %rdi
movl $0xc3, %edx
callq 0x104226
movq %rax, %r12
movq 0x18(%rsp), %r14
testq %r14, %r14
je 0x1ed4c1
xorl %eax, %eax
movl (%rbp,%rax,4), %ecx
movl (%r15,%rcx,4), %ecx
movl %ecx, (%r12,%rax,4)
incq %rax
cmpq %rax, %r14
jne 0x1ed4ad
leaq 0x1ca749(%rip), %rsi    # 0x3b7c11
movq %r15, %rdi
movl $0xc9, %edx
callq 0x1045eb
cmpq %rbx, %r14
ja 0x1ed4f0
leaq (%r12,%r14,4), %rdi
subq %r14, %rbx
leaq 0x4(,%rbx,4), %rdx
xorl %esi, %esi
callq 0x173a0
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x78cef
callq 0x78cb6