// File: /workspace/github_cpp_makefile_star2_O3/twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::divbwt(unsigned char const*, unsigned char*, int*, int)
int
divbwt(const unsigned char *T, unsigned char *U, int *A, int n) {
  int *B;
  int *bucket_A, *bucket_B;
  int m, pidx, i;

  /* Check arguments. */
  if((T == NULL) || (U == NULL) || (n < 0)) { return -1; }
  else if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; }

  if((B = A) == NULL) { B = (int *)malloc((size_t)(n + 1) * sizeof(int)); }
  bucket_A = (int *)malloc(BUCKET_A_SIZE * sizeof(int));
  bucket_B = (int *)malloc(BUCKET_B_SIZE * sizeof(int));

  /* Burrows-Wheeler Transform. */
  if((B != NULL) && (bucket_A != NULL) && (bucket_B != NULL)) {
    m = sort_typeBstar(T, B, bucket_A, bucket_B, n);
    pidx = construct_BWT(T, B, bucket_A, bucket_B, n, m);

    /* Copy to output string. */
    U[0] = T[n - 1];
    for(i = 0; i < pidx; ++i) { U[i + 1] = (unsigned char)B[i]; }
    for(i += 1; i < n; ++i) { U[i] = (unsigned char)B[i]; }
    pidx += 1;
  } else {
    pidx = -2;
  }

  free(bucket_B);
  free(bucket_A);
  if(A == NULL) { free(B); }

  return pidx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %dil
orb %al, %dil
testl %ecx, %ecx
sets %al
orb %dil, %al
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jne 0x28cd1
cmpl $0x1, %ecx
ja 0x28a2b
xorl %r15d, %r15d
cmpl $0x1, %ecx
jne 0x28cd1
movb (%rbx), %al
movb %al, (%rsi)
movl $0x1, %r15d
jmp 0x28cd1
movq %rcx, 0x8(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdx, %r12
movq %rdx, 0x20(%rsp)
testq %rdx, %rdx
jne 0x28a56
movl 0x8(%rsp), %eax
leaq 0x4(,%rax,4), %rdi
callq 0x4230
movq %rax, %r12
movl $0x400, %edi            # imm = 0x400
callq 0x4230
movq %rax, %r14
movl $0x40000, %edi          # imm = 0x40000
callq 0x4230
movq %rax, %rbp
testq %r12, %r12
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
testq %rbp, %rbp
sete %al
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
orb %cl, %al
jne 0x28cb1
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, 0x10(%rsp)
movq %r14, %rdx
movq %rbp, %rcx
movq 0x8(%rsp), %r8
callq 0x26060
testl %eax, %eax
jle 0x28b8b
leaq -0x4(%r12), %rax
movl $0xfe, %ecx
leal 0x1(%rcx), %esi
movl %ecx, %edx
shll $0x8, %edx
orl %edx, %esi
movslq %esi, %rsi
movslq (%rbp,%rsi,4), %rsi
leaq (%r12,%rsi,4), %rsi
movq 0x10(%rsp), %rdi
movslq 0x4(%rdi,%rcx,4), %rdi
leaq (%rax,%rdi,4), %rdi
cmpq %rdi, %rsi
ja 0x28b81
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movslq %edx, %r8
xorl %r9d, %r9d
movslq (%rdi), %r13
testq %r13, %r13
jle 0x28b37
leal -0x1(%r13), %r14d
movzbl (%rbx,%r14), %r11d
movl %r11d, %r15d
notl %r15d
movl %r15d, (%rdi)
xorl %r15d, %r15d
cmpl $0x1, %r13d
je 0x28b2d
movl %r13d, %r15d
negl %r15d
cmpb %r11b, -0x2(%rbx,%r13)
cmoval %r15d, %r14d
movl %r14d, %r15d
cmpl %r11d, %r10d
jne 0x28b44
movl %r10d, %r11d
jmp 0x28b6a
testl %r13d, %r13d
je 0x28b74
notl %r13d
movl %r13d, (%rdi)
jmp 0x28b74
testl %r10d, %r10d
js 0x28b5b
subq %r12, %r9
shrq $0x2, %r9
orl %edx, %r10d
movslq %r10d, %r10
movl %r9d, (%rbp,%r10,4)
movq %r8, %r9
orq %r11, %r9
movslq (%rbp,%r9,4), %r9
leaq (%r12,%r9,4), %r9
movl %r15d, (%r9)
addq $-0x4, %r9
movl %r11d, %r10d
addq $-0x4, %rdi
cmpq %rdi, %rsi
jbe 0x28af8
subq $0x1, %rcx
jae 0x28abf
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rcx
leal -0x1(%rcx), %eax
movzbl (%rbx,%rax), %edx
movslq (%rsi,%rdx,4), %rsi
movl %ecx, %ecx
movzbl -0x2(%rbx,%rcx), %r8d
cmpb %dl, %r8b
notl %r8d
cmovael %eax, %r8d
leaq 0x4(%r12,%rsi,4), %rdi
movl %r8d, -0x4(%rdi)
leaq (%r12,%rcx,4), %rsi
movq %r12, %rax
movq %r12, %r8
movslq (%r8), %r11
testq %r11, %r11
jle 0x28c24
leal -0x1(%r11), %r14d
movzbl (%rbx,%r14), %r9d
movl %r9d, (%r8)
xorl %r10d, %r10d
cmpl $0x1, %r11d
je 0x28bf6
movzbl -0x2(%rbx,%r11), %r11d
movl %r14d, %r10d
cmpb %r9b, %r11b
jae 0x28bf6
notl %r11d
movl %r11d, %r10d
cmpl %r9d, %edx
je 0x28c1b
subq %r12, %rdi
shrq $0x2, %rdi
movl %edx, %edx
movq 0x10(%rsp), %r11
movl %edi, (%r11,%rdx,4)
movl %r9d, %edx
movslq (%r11,%rdx,4), %rdx
leaq (%r12,%rdx,4), %rdi
movl %r9d, %edx
movl %r10d, (%rdi)
addq $0x4, %rdi
jmp 0x28c34
testl %r11d, %r11d
je 0x28c31
notl %r11d
movl %r11d, (%r8)
jmp 0x28c34
movq %r8, %rax
addq $0x4, %r8
cmpq %rsi, %r8
jb 0x28bc5
subq %r12, %rax
shrq $0x2, %rax
movb -0x1(%rbx,%rcx), %cl
movq 0x18(%rsp), %r8
movb %cl, (%r8)
testl %eax, %eax
jle 0x28c78
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
movq 0x8(%rsp), %r9
movb (%r12,%rdx,4), %sil
movb %sil, 0x1(%r8,%rdx)
incq %rdx
cmpq %rdx, %rcx
jne 0x28c63
movl %eax, %ecx
jmp 0x28c7f
xorl %ecx, %ecx
movq 0x8(%rsp), %r9
leal 0x1(%rcx), %edx
cmpl %r9d, %edx
jge 0x28ca8
movl %ecx, %ecx
addq %rcx, %r8
leaq (%r12,%rcx,4), %rdx
movl $0x1, %esi
movb (%rdx,%rsi,4), %dil
movb %dil, (%r8,%rsi)
incq %rsi
leal (%rcx,%rsi), %edi
cmpl %r9d, %edi
jl 0x28c95
leal 0x1(%rax), %r15d
movq 0x10(%rsp), %r14
movq %rbp, %rdi
callq 0x4200
movq %r14, %rdi
callq 0x4200
cmpq $0x0, 0x20(%rsp)
jne 0x28cd1
movq %r12, %rdi
callq 0x4200
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq