// File: /workspace/github_c_makefile_star2_O0/felipelouza[P]egap/tools/lib/suffix_array.c
// Function: suffix_array_check
int_t suffix_array_check(unsigned char *T, int_t *SA,  size_t n, int cs, unsigned char sentinel){

  int_t i,j,k;
  
  for (i = 0; i < n-1;  i++) {
    size_t min = SA[i+1]<SA[i]?(n-SA[i]):(n-SA[i+1]);
    if (!sleq(T, SA[i], SA[i+1], min, cs, sentinel)){

      printf("#%" PRIdN ") %" PRIdN ", %" PRIdN "&\n", i, SA[i], SA[i+1]);

      for(j=SA[i], k=SA[i+1]; (j<SA[i]+5); j++, k++)
        printf("%" PRIdN " | %" PRIdN "\n", chr(j), chr(k));
      printf("\n");

      return 0;
    }
  }

  unsigned char *tmp = (unsigned char*) malloc(n*sizeof(unsigned char));

  for (i = 0; i < n;  i++) 
    tmp[i] = 0;

  for (i = 0; i < n;  i++) 
    tmp[SA[i]] = 1;
  
  for (i = 0; i < n;  i++){ 
    if(!tmp[i]){
      free(tmp);
      fprintf(stderr, "Error: is not a permutation\n");
      return 0;
    }
  }

  free(tmp);
  
return 1;  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movb %al, -0x25(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x6bcb
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0x6a4b
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
movq %rax, -0x58(%rbp)
jmp 0x6a60
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq 0x8(%rcx,%rdx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq -0x48(%rbp), %rcx
movl -0x24(%rbp), %r8d
movzbl -0x25(%rbp), %r9d
callq 0x67e0
cmpq $0x0, %rax
jne 0x6bb8
movq -0x30(%rbp), %rsi
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rcx
leaq 0xb095(%rip), %rdi      # 0x11b5a
movb $0x0, %al
callq 0x20f0
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
addq $0x5, %rcx
cmpq %rcx, %rax
jge 0x6b9d
movslq -0x24(%rbp), %rax
cmpq $0x8, %rax
jne 0x6b26
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
jmp 0x6b36
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movslq -0x24(%rbp), %rax
cmpq $0x8, %rax
jne 0x6b5a
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
jmp 0x6b6a
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
leaq 0xaff2(%rip), %rdi      # 0x11b6b
movb $0x0, %al
callq 0x20f0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6aed
leaq 0xa5c9(%rip), %rdi      # 0x1116d
movb $0x0, %al
callq 0x20f0
movq $0x0, -0x8(%rbp)
jmp 0x6ca8
jmp 0x6bba
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x6a05
movq -0x20(%rbp), %rdi
shlq $0x0, %rdi
callq 0x10960
movq %rax, -0x50(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x6c08
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x6be4
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x6c3c
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movb $0x1, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x6c10
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x6c97
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
jne 0x6c87
movq -0x50(%rbp), %rdi
callq 0x10ad0
movq 0xe38c(%rip), %rax      # 0x14ff8
movq (%rax), %rdi
leaq 0xaf00(%rip), %rsi      # 0x11b76
movb $0x0, %al
callq 0x2190
movq $0x0, -0x8(%rbp)
jmp 0x6ca8
jmp 0x6c89
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x6c44
movq -0x50(%rbp), %rdi
callq 0x10ad0
movq $0x1, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)