// File: /workspace/github_c_makefile_star2_O2/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, %r14
movl %ecx, %ebp
movq %rdx, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movl %edi, 0x4(%rsp)
movq 0x60(%rsp), %r13
leaq 0x4(,%r9,4), %rdi
leaq 0x1ba530(%rip), %rsi    # 0x358071
movq %rdi, 0x20(%rsp)
movl $0x8e, %edx
callq 0x93160
movq %rax, %r15
movl (%r13), %ecx
pushq $0x1
popq %rax
cmpq %rbx, %rax
ja 0x19db6f
movl (%r13,%rax,4), %edx
movl %ecx, (%r15,%rdx,4)
incq %rax
movl %edx, %ecx
jmp 0x19db5a
movq %rbx, %rax
shrq $0x20, %rax
jne 0x19dcf3
movl (%r13), %eax
movq 0x8(%rsp), %rcx
andq $0x0, (%rcx)
movq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rcx
xorl %esi, %esi
xorl %edi, %edi
cmpq %rbx, %rsi
je 0x19dc4a
cmpq %rax, %rsi
jne 0x19dbb3
andl $0x0, (%r15,%rax,4)
jmp 0x19dc3f
movl (%r15,%rsi,4), %r11d
cmpl %r11d, %esi
movl %r11d, %r8d
cmoval %esi, %r8d
movq %rbx, %r9
subq %r8, %r9
movq 0x18(%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 0x19dc0b
movb (%rcx,%rdi), %dl
cmpb $-0x2, %dl
setae %r12b
leaq 0x1(%rdi), %r11
cmpb (%r10,%rdi), %dl
jne 0x19dc05
movq %r11, %rdi
andb %bpl, %r12b
je 0x19dbe4
decq %r11
movq %r11, %r8
movq %r8, %rdx
shrq $0x20, %rdx
jne 0x19dcbb
movl %r8d, (%r15,%rsi,4)
testq %r8, %r8
je 0x19dc3d
cmpq %r8, 0x10(%rsp)
jae 0x19dc35
movq 0x8(%rsp), %rdx
movq %r8, (%rdx)
movq %r8, 0x10(%rsp)
decq %r8
movq %r8, %rdi
jmp 0x19dc3f
xorl %edi, %edi
incq %rsi
incq %rcx
jmp 0x19db9b
cmpb $0x0, 0x4(%rsp)
jne 0x19dca9
leaq 0x1ba419(%rip), %rsi    # 0x358071
movq 0x20(%rsp), %rdi
movl $0xc3, %edx
callq 0x93160
movq %rax, %r12
xorl %eax, %eax
cmpq %rax, %r14
je 0x19dc83
movl (%r13,%rax,4), %ecx
movl (%r15,%rcx,4), %ecx
movl %ecx, (%r12,%rax,4)
incq %rax
jmp 0x19dc6c
leaq 0x1ba3e7(%rip), %rsi    # 0x358071
movq %r15, %rdi
movl $0xc9, %edx
callq 0x936f9
cmpq %rbx, %r14
ja 0x19dca6
andl $0x0, (%r12,%r14,4)
incq %r14
jmp 0x19dc97
movq %r12, %r15
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x29a2a6(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x147347(%rip), %rsi    # 0x2e5013
leaq 0x1ba3ec(%rip), %rdx    # 0x3580bf
leaq 0x1ba404(%rip), %rcx    # 0x3580de
leaq 0x1ba390(%rip), %r8     # 0x358071
movl $0xaf, %r9d
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x29a26e(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x14730f(%rip), %rsi    # 0x2e5013
leaq 0x1ba37d(%rip), %rdx    # 0x358088
leaq 0x1ba3cc(%rip), %rcx    # 0x3580de
leaq 0x1ba358(%rip), %r8     # 0x358071
movl $0x98, %r9d
jmp 0x19dce7