// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %rax
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
testl %edx, %edx
sets %al
orb %cl, %al
je 0x14633
pushq $-0x1
popq %r13
jmp 0x14845
movl %edx, %r13d
testl %edx, %edx
je 0x14845
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x2, %r13d
je 0x14655
cmpl $0x1, %r13d
jne 0x14679
andl $0x0, (%rbx)
jmp 0x14671
movb (%r14), %al
xorl %ecx, %ecx
xorl %edx, %edx
cmpb 0x1(%r14), %al
setb %cl
setae %dl
andl $0x0, (%rbx,%rdx,4)
movl $0x1, (%rbx,%rcx,4)
xorl %r13d, %r13d
jmp 0x14845
movl $0x400, %edi            # imm = 0x400
callq 0x4240
movq %rax, %r15
movl $0x40000, %edi          # imm = 0x40000
callq 0x4240
movq %rax, %r12
testq %r15, %r15
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
jne 0x147a0
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movl %r13d, %r8d
callq 0x14857
testl %eax, %eax
jle 0x147a9
movl $0xfe, %eax
testl %eax, %eax
js 0x147a9
movl %eax, %edx
shll $0x8, %edx
leal 0x1(%rax), %ecx
orl %edx, %ecx
movslq %ecx, %rcx
movslq (%r12,%rcx,4), %rcx
leaq (%rbx,%rcx,4), %rsi
movl %eax, %ecx
movslq 0x4(%r15,%rcx,4), %rcx
leaq (%rbx,%rcx,4), %rbp
movslq %edx, %rcx
movq %rcx, (%rsp)
xorl %r8d, %r8d
pushq $-0x1
popq %r10
addq $-0x4, %rbp
cmpq %rbp, %rsi
ja 0x14799
movslq (%rbp), %rcx
leaq -0x4(%rbp), %r9
movl %ecx, %r11d
notl %r11d
movl %r11d, (%rbp)
movq %r9, %rbp
testq %rcx, %rcx
jle 0x14702
movq %r15, %rdi
movq %r12, %r15
leal -0x1(%rcx), %r12d
movzbl (%r14,%r12), %r11d
xorl %ebp, %ebp
cmpl $0x1, %ecx
je 0x1474b
movl %ecx, %ebp
negl %ebp
cmpb %r11b, -0x2(%r14,%rcx)
cmoval %ebp, %r12d
movl %r12d, %ebp
cmpl %r11d, %r10d
movq %r15, %r12
jne 0x1475b
movl %r10d, %r11d
movq %rdi, %r15
jmp 0x14783
testl %r10d, %r10d
movq %rdi, %r15
js 0x14774
subq %rbx, %r8
shrq $0x2, %r8
orl %edx, %r10d
movslq %r10d, %rcx
movl %r8d, (%r12,%rcx,4)
movq (%rsp), %rcx
orq %r11, %rcx
movslq (%r12,%rcx,4), %rcx
leaq (%rbx,%rcx,4), %r8
addq $0x4, %r9
movl %ebp, (%r8)
addq $-0x4, %r8
movq %r9, %rbp
movl %r11d, %r10d
jmp 0x146fe
decl %eax
jmp 0x146c8
pushq $-0x2
popq %r13
jmp 0x14835
leal -0x1(%r13), %ecx
movzbl (%r14,%rcx), %eax
movslq (%r15,%rax,4), %rdx
movl %r13d, %edi
negl %r13d
cmpb %al, -0x2(%r14,%rdi)
cmovael %ecx, %r13d
leaq (%rbx,%rdx,4), %rsi
addq $0x4, %rsi
movl %r13d, -0x4(%rsi)
leaq (%rbx,%rdi,4), %rcx
movq %rbx, %rdx
cmpq %rcx, %rdx
jae 0x14832
movslq (%rdx), %r9
testq %r9, %r9
jle 0x14826
movl %r9d, %edi
decl %edi
movzbl (%r14,%rdi), %r8d
je 0x147f8
cmpb %r8b, -0x2(%r14,%r9)
jae 0x147fe
negl %r9d
movl %r9d, %edi
cmpl %r8d, %eax
je 0x1481e
subq %rbx, %rsi
shrq $0x2, %rsi
movl %eax, %eax
movl %esi, (%r15,%rax,4)
movl %r8d, %eax
movslq (%r15,%rax,4), %rax
leaq (%rbx,%rax,4), %rsi
movl %r8d, %eax
movl %edi, (%rsi)
addq $0x4, %rsi
jmp 0x1482c
notl %r9d
movl %r9d, (%rdx)
addq $0x4, %rdx
jmp 0x147d8
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x4200
movq %r15, %rdi
callq 0x4200
movl %r13d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq