// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movb %r9b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movb %al, -0x25(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x1, -0x48(%rbp)
movq -0x20(%rbp), %rdi
shlq $0x3, %rdi
callq 0x10960
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x6cc0
movq $0x1, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x795a
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x76c1
jmp 0x7949
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x30(%rbp), %rcx
addq -0x68(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x69(%rbp)
jae 0x7716
movq -0x60(%rbp), %rax
addq -0x68(%rbp), %rax
cmpq -0x20(%rbp), %rax
setb %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x7722
jmp 0x7855
movslq -0x24(%rbp), %rax
cmpq $0x8, %rax
jne 0x7742
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
addq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
jmp 0x7756
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
addq -0x68(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
movslq -0x24(%rbp), %rax
cmpq $0x8, %rax
jne 0x7781
movq -0x8(%rbp), %rax
movq -0x60(%rbp), %rcx
addq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
jmp 0x7798
movq -0x8(%rbp), %rax
movq -0x60(%rbp), %rcx
addq -0x68(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq %rcx, %rax
jne 0x7840
movslq -0x24(%rbp), %rax
cmpq $0x8, %rax
jne 0x77cf
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
addq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x90(%rbp)
jmp 0x77e6
movq -0x8(%rbp), %rax
movq -0x30(%rbp), %rcx
addq -0x68(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movzbl -0x25(%rbp), %ecx
cmpq %rcx, %rax
jne 0x7842
movslq -0x24(%rbp), %rax
cmpq $0x8, %rax
jne 0x7819
movq -0x8(%rbp), %rax
movq -0x60(%rbp), %rcx
addq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
jmp 0x7830
movq -0x8(%rbp), %rax
movq -0x60(%rbp), %rcx
addq -0x68(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movzbl -0x25(%rbp), %ecx
cmpq %rcx, %rax
jne 0x7842
jmp 0x7855
jmp 0x7844
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x76f1
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x68(%rbp), %rax
je 0x78b9
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x48(%rbp), %rcx
leaq 0xa37f(%rip), %rdi      # 0x11bf9
movb $0x0, %al
callq 0x20f0
movq 0xd740(%rip), %rax      # 0x14fc8
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x68(%rbp), %r8
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rsi
movq (%rax,%rsi,8), %r9
leaq 0xa2e1(%rip), %rsi      # 0x11b93
movb $0x0, %al
callq 0x2190
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jle 0x78ec
movq -0x40(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x78ff
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rdx
movl $0x1, %eax
cmpq (%rcx,%rdx,8), %rax
jle 0x792b
movl $0x1, %eax
movq %rax, -0xa8(%rbp)
jmp 0x793e
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x7697
movq -0x38(%rbp), %xmm0
movaps 0x96ea(%rip), %xmm3     # 0x11050
movaps %xmm3, -0xd0(%rbp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x96e7(%rip), %xmm2     # 0x11060
movaps %xmm2, -0xc0(%rbp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x20(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0xa226(%rip), %rdi      # 0x11bd8
movb $0x1, %al
callq 0x20f0
movq -0x40(%rbp), %rsi
leaq 0xa226(%rip), %rdi      # 0x11bea
xorl %eax, %eax
callq 0x20f0
movaps -0xd0(%rbp), %xmm3
movaps -0xc0(%rbp), %xmm2
movq 0xd618(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
movq -0x38(%rbp), %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x20(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq -0x40(%rbp), %rdx
leaq 0xa1e4(%rip), %rsi      # 0x11c06
movb $0x1, %al
callq 0x2190
movq -0x50(%rbp), %rdi
callq 0x10ad0
movl $0x1, %eax
addq $0xd0, %rsp
popq %rbp
retq