// File: /workspace/github_c_makefile_star2_O1/felipelouza[P]egap/tools/lib/lcp_array.c
// Function: lcp_array_check_phi
int lcp_array_check_phi(unsigned char *T, int_t *SA, int_t *LCP, uint_t n, int cs, unsigned char separator){
  
  uint_t i;
  uint64_t sum=0;
  int_t maximum=0;
  int_t previous_lcp = 1;

  uint_t *ISA = (uint_t* ) malloc(n * sizeof(uint_t));
  find_inverse(SA, n, ISA);

  for(i=1;i<n;i++) {

    int_t k=ISA[i]; 
    if(k==0) continue;

    int_t j=SA[ISA[i]-1];
    int_t h=previous_lcp-1;

    for(h=0;i+h<n && j+h<n;h++) if(chr(i+h)!=chr(j+h) || (chr(i+h)==separator && chr(j+h)==separator)) break;

    if(LCP[k]!=h) {
    printf("%" PRIdN " %" PRIdN "\t%" PRIdN "\n",k,j, previous_lcp);
      fprintf(stdout,"isNotLCP! Incorrect LCP value: LCP[%" PRIdN "]=%" PRIdN "!=%" PRIdN "\t(%" PRIdN ")\n", k, LCP[k],h, SA[i]);
      //return 0;
    }
    sum+=LCP[i];
    maximum=max(maximum, LCP[i]);

    previous_lcp = max(1,LCP[i]);
  }
  
  printf("LCP_mean = %.2lf\n", (double)sum/(double)n);
  printf("LCP_max = %" PRIdN "\n", maximum);

  fprintf(stderr, "%.2lf\t %" PRIdN "\n", (double)sum/(double)n, maximum);

  free(ISA);
  
return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %ebx
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, (%rsp)
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
leaq (,%rcx,8), %rdi
callq 0x9fd2
testq %r14, %r14
je 0x24e7
xorl %edx, %edx
movq (%r15,%rdx,8), %rcx
movq %rdx, (%rax,%rcx,8)
incq %rdx
cmpq %rdx, %r14
jne 0x24d7
cmpq $0x2, %r14
movq %rax, 0x8(%rsp)
jb 0x266f
movq %r15, 0x18(%rsp)
movzbl %bl, %ecx
movq %rcx, 0x20(%rsp)
movq 0x10(%rsp), %rcx
leaq 0x8(%rcx), %r13
leaq 0x1(%rcx), %r12
pushq $0x1
popq %rcx
movq %rcx, %r15
xorl %esi, %esi
xorl %r10d, %r10d
movq (%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0x2636
movq %rsi, 0x40(%rsp)
movq 0x18(%rsp), %rdx
movq %rdi, %r11
movq -0x8(%rdx,%rdi,8), %rdx
movq 0x10(%rsp), %rsi
leaq (%rsi,%rdx,8), %r9
addq %rdx, %rsi
xorl %ebx, %ebx
leaq (%rdx,%rbx), %rdi
cmpq %r14, %rdi
jae 0x25b4
cmpl $0x8, %ebp
jne 0x255d
movq (%r13,%rbx,8), %rdi
jmp 0x2562
movzbl (%r12,%rbx), %edi
cmpl $0x8, %ebp
jne 0x256d
movq (%r9,%rbx,8), %r8
jmp 0x2572
movzbl (%rsi,%rbx), %r8d
cmpq %r8, %rdi
jne 0x25b4
cmpl $0x8, %ebp
jne 0x2583
movq (%r13,%rbx,8), %rdi
jmp 0x2588
movzbl (%r12,%rbx), %edi
cmpq 0x20(%rsp), %rdi
jne 0x25a5
cmpl $0x8, %ebp
jne 0x259a
movq (%r9,%rbx,8), %rdi
jmp 0x259e
movzbl (%rsi,%rbx), %edi
cmpq 0x20(%rsp), %rdi
je 0x25b4
leaq (%r15,%rbx), %rdi
incq %rdi
incq %rbx
cmpq %r14, %rdi
jb 0x2548
movq (%rsp), %r8
cmpq %rbx, (%r8,%r11,8)
je 0x2618
leaq 0x94ba(%rip), %rdi      # 0xba7f
movq %r11, %rsi
xorl %eax, %eax
movq %r10, 0x38(%rsp)
movq %r11, 0x30(%rsp)
callq 0x20f0
movq 0xc9e8(%rip), %rax      # 0xefc8
movq (%rax), %rdi
movq (%rsp), %rax
movq 0x30(%rsp), %rdx
movq (%rax,%rdx,8), %rcx
movq 0x18(%rsp), %rax
movq (%rax,%r15,8), %r9
leaq 0x9419(%rip), %rsi      # 0xba19
movq %rbx, %r8
xorl %eax, %eax
callq 0x2190
movq (%rsp), %r8
movq 0x38(%rsp), %r10
movq 0x8(%rsp), %rax
movq (%r8,%r15,8), %rcx
movq 0x40(%rsp), %rsi
addq %rcx, %rsi
cmpq %rcx, %r10
cmovleq %rcx, %r10
cmpq $0x2, %rcx
pushq $0x1
popq %rdx
cmovlq %rdx, %rcx
incq %r15
addq $0x8, %r13
incq %r12
cmpq %r14, %r15
jne 0x251b
movq %rsi, %xmm1
punpckldq 0x89ba(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x89c2(%rip), %xmm1     # 0xb020
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movq %r10, %rbx
jmp 0x2675
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
movq %r14, %xmm2
punpckldq 0x898e(%rip), %xmm2 # xmm2 = xmm2[0],mem[0],xmm2[1],mem[1]
subpd 0x8996(%rip), %xmm2     # 0xb020
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
leaq 0x93b7(%rip), %rdi      # 0xba5e
movb $0x1, %al
callq 0x20f0
leaq 0x93bb(%rip), %rdi      # 0xba70
movq %rbx, %rsi
xorl %eax, %eax
callq 0x20f0
movq 0xc932(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0x93bc(%rip), %rsi      # 0xba8c
movaps 0x20(%rsp), %xmm0
movq %rbx, %rdx
movb $0x1, %al
callq 0x2190
movq 0x8(%rsp), %rdi
callq 0xa089
pushq $0x1
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq