// File: /workspace/github_cpp_makefile_star2_O3/twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::divsufsort(unsigned char const*, int*, int)
int
divsufsort(const unsigned char *T, int *SA, int n) {
  int *bucket_A, *bucket_B;
  int m;
  int err = 0;

  /* Check arguments. */
  if((T == NULL) || (SA == NULL) || (n < 0)) { return -1; }
  else if(n == 0) { return 0; }
  else if(n == 1) { SA[0] = 0; return 0; }
  else if(n == 2) { m = (T[0] < T[1]); SA[m ^ 1] = 0, SA[m] = 1; return 0; }

  bucket_A = (int *)malloc(BUCKET_A_SIZE * sizeof(int));
  bucket_B = (int *)malloc(BUCKET_B_SIZE * sizeof(int));

  /* Suffixsort. */
  if((bucket_A != NULL) && (bucket_B != NULL)) {
    m = sort_typeBstar(T, SA, bucket_A, bucket_B, n);
    construct_SA(T, SA, bucket_A, bucket_B, n, m);
  } else {
    err = -2;
  }

  free(bucket_B);
  free(bucket_A);

  return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
testl %edx, %edx
sets %al
orb %cl, %al
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jne 0x2604f
movl %edx, %r13d
testl %edx, %edx
je 0x25e8e
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x2, %r13d
je 0x25e68
cmpl $0x1, %r13d
jne 0x25e96
movl $0x0, (%rbx)
jmp 0x25e87
movb (%r14), %al
xorl %ecx, %ecx
xorl %edx, %edx
cmpb 0x1(%r14), %al
setb %cl
setae %dl
movl $0x0, (%rbx,%rdx,4)
movl $0x1, (%rbx,%rcx,4)
xorl %ebp, %ebp
jmp 0x2604f
movl %r13d, %ebp
jmp 0x2604f
movl $0x400, %edi            # imm = 0x400
callq 0x4230
movq %rax, %r15
movl $0x40000, %edi          # imm = 0x40000
callq 0x4230
movq %rax, %r12
testq %r15, %r15
sete %al
testq %r12, %r12
sete %cl
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
orb %al, %cl
jne 0x2603f
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, 0x8(%rsp)
movq %r15, %rdx
movq %r12, %rcx
movl %r13d, %r8d
callq 0x26060
testl %eax, %eax
jle 0x25faa
leaq -0x4(%rbx), %rax
movq %rax, 0x10(%rsp)
movl $0xfe, %ecx
leal 0x1(%rcx), %eax
movl %ecx, %edx
shll $0x8, %edx
orl %edx, %eax
cltq
movslq (%r12,%rax,4), %rax
leaq (%rbx,%rax,4), %rsi
movq 0x8(%rsp), %rax
movslq 0x4(%rax,%rcx,4), %rax
movq 0x10(%rsp), %rdi
leaq (%rdi,%rax,4), %rdi
cmpq %rdi, %rsi
ja 0x25fa0
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movslq %edx, %r8
xorl %r9d, %r9d
movslq (%rdi), %r15
movl %r15d, %eax
notl %eax
movl %eax, (%rdi)
testq %r15, %r15
jle 0x25f97
leal -0x1(%r15), %eax
movzbl (%r14,%rax), %r11d
xorl %ebp, %ebp
cmpl $0x1, %r15d
je 0x25f5f
movl %r15d, %ebp
negl %ebp
cmpb %r11b, -0x2(%r14,%r15)
cmoval %ebp, %eax
movl %eax, %ebp
cmpl %r11d, %r10d
jne 0x25f69
movl %r10d, %r11d
jmp 0x25f8d
testl %r10d, %r10d
js 0x25f7f
subq %rbx, %r9
shrq $0x2, %r9
orl %edx, %r10d
movslq %r10d, %rax
movl %r9d, (%r12,%rax,4)
movq %r8, %rax
orq %r11, %rax
movslq (%r12,%rax,4), %rax
leaq (%rbx,%rax,4), %r9
movl %ebp, (%r9)
addq $-0x4, %r9
movl %r11d, %r10d
addq $-0x4, %rdi
cmpq %rdi, %rsi
jbe 0x25f30
subq $0x1, %rcx
jae 0x25ef8
leal -0x1(%r13), %edx
movzbl (%r14,%rdx), %eax
movl %r13d, %ecx
movl %r13d, %esi
negl %esi
cmpb %al, -0x2(%r14,%rcx)
cmovael %edx, %esi
movq 0x8(%rsp), %r15
movslq (%r15,%rax,4), %rdi
movl %esi, (%rbx,%rdi,4)
xorl %ebp, %ebp
cmpl $0x1, %r13d
jb 0x2603f
leaq (%rbx,%rdi,4), %r10
leaq (%rbx,%rcx,4), %rcx
addq $0x4, %r10
movq %rbx, %rsi
movslq (%rsi), %r9
testq %r9, %r9
jle 0x26030
movl %r9d, %edi
decl %edi
movzbl (%r14,%rdi), %r8d
je 0x26001
cmpb %r8b, -0x2(%r14,%r9)
jae 0x26007
negl %r9d
movl %r9d, %edi
cmpl %r8d, %eax
je 0x26027
subq %rbx, %r10
shrq $0x2, %r10
movl %eax, %eax
movl %r10d, (%r15,%rax,4)
movl %r8d, %eax
movslq (%r15,%rax,4), %rax
leaq (%rbx,%rax,4), %r10
movl %r8d, %eax
movl %edi, (%r10)
addq $0x4, %r10
jmp 0x26036
notl %r9d
movl %r9d, (%rsi)
addq $0x4, %rsi
cmpq %rcx, %rsi
jb 0x25fe6
movq %r12, %rdi
callq 0x4200
movq %r15, %rdi
callq 0x4200
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq