// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x1c410
testb $0x1, %al
jne 0x1bf72
movq $0x0, -0x8(%rbp)
jmp 0x1c20a
movq -0x58(%rbp), %rax
movl 0x28(%rax), %eax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x58(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl 0x28(%rcx), %eax
jae 0x1bfcd
movq -0x58(%rbp), %rax
movl 0x28(%rax), %edx
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1bfa5
movl $0x0, -0x28(%rbp)
movq -0x58(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x2c(%rcx), %eax
jae 0x1c004
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x18(%rcx), %rcx
movl -0x28(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movl $0x0, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1bfd4
movq -0x58(%rbp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x58(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x28(%rcx), %eax
jae 0x1c110
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x30(%rbp)
movq 0x18(%rax), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x1c08e
cmpl $0x0, -0x34(%rbp)
je 0x1c08e
movq -0x58(%rbp), %rcx
movq 0x8(%rcx), %rax
movl -0x30(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
movzbl (%rax,%rdx), %eax
movq 0x8(%rcx), %rcx
movl -0x34(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x1c08e
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1c100
movl $0x0, -0x38(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rcx
movl -0x30(%rbp), %edx
addl -0x38(%rbp), %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
movq 0x8(%rax), %rax
movl -0x34(%rbp), %edx
addl -0x38(%rbp), %edx
movl %edx, %edx
movzbl (%rax,%rdx), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x59(%rbp)
jne 0x1c0df
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x30(%rbp), %ecx
addl -0x38(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x1c0e8
jmp 0x1c0f3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1c095
movl -0x38(%rbp), %edx
movq -0x20(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x1c102
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1c00e
movl $0x1, -0x3c(%rbp)
movq -0x58(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x28(%rcx), %eax
jae 0x1c15f
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %edx
movl (%rax,%rdx,4), %eax
cmpl 0x28(%rcx), %eax
jb 0x1c152
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
subl $0x1, %edx
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x1c154
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1c117
testb $0x1, -0x11(%rbp)
je 0x1c172
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1c20a
movq -0x58(%rbp), %rdi
callq 0x1c3f0
movl %eax, %eax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %eax
movl %eax, -0x60(%rbp)
callq 0x1c3f0
movl %eax, %ecx
movl -0x60(%rbp), %eax
cmpl %ecx, %eax
jae 0x1c1eb
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x10(%rcx), %rcx
movl -0x4c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %edx
movq -0x48(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1c1a9
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x1c202
movq -0x68(%rbp), %rdi
callq 0x33e0
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)