// File: /workspace/github_cpp_makefile_star2_O3/adamnovak[P]rlcsa/suffixarray.cpp
// Function: CSA::SuffixArray::getLCPArray(bool) const
uint*
SuffixArray::getLCPArray(bool getPLCP) const
{
  if(!(this->isOk())) { return 0; }

  uint* plcp = new uint[this->data_size];
  for(uint i = 0; i < this->data_size; i++) { plcp[i] = this->data_size; }

  // Fill in the irreducible PLCP values.
  for(uint i = 0; i < this->sequences; i++)
  {
    plcp[this->original_sa[i]] = 0;
  }
  for(uint i = this->sequences; i < this->data_size; i++)
  {
    uint j = this->original_sa[i - 1], k = this->original_sa[i];
    if(j == 0 || k == 0 || this->data[j - 1] != this->data[k - 1] || this->data[j - 1] == 0)
    {
      uint temp = 0;
      while(this->data[j + temp] == this->data[k + temp] && this->data[j + temp] != 0) { temp++; }
      plcp[k] = temp;
    }
  }

  // Fill in the rest of the values.
  for(uint i = 1; i < this->data_size; i++)
  {
    if(plcp[i] >= this->data_size) { plcp[i] = plcp[i - 1] - 1; }
  }
  if(getPLCP) { return plcp; }

  // Convert to LCP array.
  uint* lcp = new uint[this->getSize()];
  for(uint i = 0; i < this->getSize(); i++)
  {
    lcp[i] = plcp[this->sa[i]];
  }
  delete[] plcp;

  return lcp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpb $0x1, (%rdi)
jne 0xfb66
movl %esi, %ebp
movq %rdi, %r14
movl 0x28(%rdi), %r12d
leaq (,%r12,4), %rdi
callq 0x3030
movq %rax, %rbx
testq %r12, %r12
je 0xfaa2
leaq -0x1(%r12), %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0xc(,%r12,4), %rax
andq $-0x10, %rax
movdqa 0x895b(%rip), %xmm1     # 0x18330
movdqa 0x8963(%rip), %xmm2     # 0x18340
xorl %ecx, %ecx
movdqa 0x8969(%rip), %xmm3     # 0x18350
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x8969(%rip), %xmm5     # 0x18360
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %edx
notl %edx
testb $0x1, %dl
je 0xfa2f
movl %r12d, (%rbx,%rcx)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0xfa42
movl %r12d, 0x4(%rbx,%rcx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %edx
testb $0x1, %dl
je 0xfa7e
movl %r12d, 0x8(%rbx,%rcx)
pextrw $0x4, %xmm6, %edx
testb $0x1, %dl
je 0xfa8d
movl %r12d, 0xc(%rbx,%rcx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0xf9f7
movl 0x2c(%r14), %r13d
testq %r13, %r13
je 0xfac3
movq 0x18(%r14), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movl $0x0, (%rbx,%rdx,4)
incq %rcx
cmpq %rcx, %r13
jne 0xfab1
cmpl %r13d, %r12d
jbe 0xfb3a
movq 0x8(%r14), %rax
movq 0x18(%r14), %rcx
movq %r13, %rdx
leal -0x1(%rdx), %esi
movl (%rcx,%rsi,4), %edi
movl (%rcx,%rdx,4), %r8d
movl %r8d, %esi
testl %edi, %edi
sete %r9b
testl %r8d, %r8d
sete %r8b
orb %r9b, %r8b
je 0xfb1b
xorl %r8d, %r8d
leal (%rdi,%r8), %r9d
movb (%rax,%r9), %r10b
leal 0x1(%r8), %r9d
testb %r10b, %r10b
je 0xfb12
addl %esi, %r8d
cmpb (%rax,%r8), %r10b
movl %r9d, %r8d
je 0xfaf5
decl %r9d
movl %r9d, (%rbx,%rsi,4)
jmp 0xfb32
leal -0x1(%rdi), %r8d
movb (%rax,%r8), %r8b
testb %r8b, %r8b
je 0xfaf2
leal -0x1(%rsi), %r9d
cmpb (%rax,%r9), %r8b
jne 0xfaf2
incq %rdx
cmpq %r12, %rdx
jne 0xfad3
cmpl $0x2, %r12d
jb 0xfb5c
movl $0x1, %eax
cmpl %r12d, (%rbx,%rax,4)
jb 0xfb54
movl -0x4(%rbx,%rax,4), %ecx
decl %ecx
movl %ecx, (%rbx,%rax,4)
incq %rax
cmpq %rax, %r12
jne 0xfb45
testb %bpl, %bpl
je 0xfb6b
movq %rbx, %r15
jmp 0xfba6
xorl %r15d, %r15d
jmp 0xfba6
movl %r12d, %ebp
subl %r13d, %ebp
leaq (,%rbp,4), %rdi
callq 0x3030
movq %rax, %r15
cmpl %r13d, %r12d
je 0xfb9e
movq 0x10(%r14), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movl (%rbx,%rdx,4), %edx
movl %edx, (%r15,%rcx,4)
incq %rcx
cmpq %rcx, %rbp
jne 0xfb8c
movq %rbx, %rdi
callq 0x3300
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq