// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %r9, %rbx
movq %r8, 0x10(%rsp)
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %r12
movl %edi, 0x4(%rsp)
movq 0x50(%rsp), %r14
leaq 0x4(,%r9,4), %rdi
leaq 0x1ca748(%rip), %rsi    # 0x3c126a
movq %rdi, 0x8(%rsp)
movl $0x8e, %edx
callq 0x1092b2
movq %rax, %r15
testq %rbx, %rbx
je 0x1f6b64
movl (%r14), %ecx
leaq 0x1(%rbx), %rdx
cmpq $0x3, %rdx
movl $0x2, %eax
cmovaeq %rdx, %rax
movl $0x1, %edx
movl (%r14,%rdx,4), %esi
movl %ecx, (%r15,%rsi,4)
incq %rdx
movl %esi, %ecx
cmpq %rdx, %rax
jne 0x1f6b52
movq %rbx, %rax
shrq $0x20, %rax
jne 0x1f6c9f
movl (%r14), %eax
movq $0x0, (%r12)
testq %rbx, %rbx
je 0x1f6c14
xorl %ecx, %ecx
xorb $0x1, %bpl
xorl %edx, %edx
cmpq %rax, %rcx
jne 0x1f6b9c
movl $0x0, (%r15,%rcx,4)
jmp 0x1f6c08
movl (%r15,%rcx,4), %esi
cmpl %esi, %ecx
movl %esi, %r8d
cmoval %ecx, %r8d
movq %rbx, %rdi
subq %r8, %rdi
leaq (%rcx,%r13), %r8
addq %r13, %rsi
cmpq %rdi, %rdx
jae 0x1f6be1
movb (%r8,%rdx), %r9b
cmpb (%rsi,%rdx), %r9b
sete %r10b
cmpb $-0x2, %r9b
setb %r9b
orb %bpl, %r9b
andb %r10b, %r9b
movzbl %r9b, %r9d
addq %r9, %rdx
testb %r9b, %r9b
jne 0x1f6bb6
movq %rdx, %rsi
shrq $0x20, %rsi
jne 0x1f6c9a
movl %edx, (%r15,%rcx,4)
testq %rdx, %rdx
je 0x1f6c06
cmpq %rdx, (%r12)
jae 0x1f6c01
movq %rdx, (%r12)
decq %rdx
jmp 0x1f6c08
xorl %edx, %edx
incq %rcx
cmpq %rbx, %rcx
jne 0x1f6b8d
cmpb $0x0, 0x4(%rsp)
je 0x1f6c20
movq %r15, %r12
jmp 0x1f6c88
leaq 0x1ca643(%rip), %rsi    # 0x3c126a
movq 0x8(%rsp), %rdi
movl $0xc3, %edx
callq 0x1092b2
movq %rax, %r12
movq 0x10(%rsp), %r13
testq %r13, %r13
je 0x1f6c59
xorl %eax, %eax
movl (%r14,%rax,4), %ecx
movl (%r15,%rcx,4), %ecx
movl %ecx, (%r12,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x1f6c45
leaq 0x1ca60a(%rip), %rsi    # 0x3c126a
movq %r15, %rdi
movl $0xc9, %edx
callq 0x109670
cmpq %rbx, %r13
ja 0x1f6c88
leaq (%r12,%r13,4), %rdi
subq %r13, %rbx
leaq 0x4(,%rbx,4), %rdx
xorl %esi, %esi
callq 0x173a0
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x7a9ee
callq 0x7a9b5