// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, %r15
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %sil
orb %al, %sil
testl %ecx, %ecx
sets %al
orb %sil, %al
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jne 0x3f6f5
movq %rdi, %rbx
cmpl $0x1, %ecx
jg 0x3f448
jne 0x3f440
movb (%rbx), %al
movb %al, (%r15)
movl %ecx, %r14d
jmp 0x3f6f5
movq %rcx, 0x8(%rsp)
movq %rdx, %r12
movq %rdx, 0x20(%rsp)
testq %rdx, %rdx
jne 0x3f46e
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 %r14, %rdx
movq %rax, %rbp
testq %r12, %r12
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
testq %rbp, %rbp
sete %al
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
orb %cl, %al
jne 0x3f6d2
movq %r15, 0x18(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movq %rdx, 0x10(%rsp)
movq %rbp, %rcx
movq 0x8(%rsp), %r8
callq 0x3cc47
testl %eax, %eax
jle 0x3f5ac
leaq -0x4(%r12), %rax
movl $0xfe, %ecx
movq %rcx, %rdx
shlq $0x8, %rdx
leal 0x1(%rcx), %esi
movl %edx, %edi
orl %esi, %edi
movslq %edi, %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 0x3f5a2
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movslq %edx, %r8
xorl %r9d, %r9d
movslq (%rdi), %r13
testq %r13, %r13
jle 0x3f558
leal -0x1(%r13), %r15d
movzbl (%rbx,%r15), %r11d
movl %r11d, %r14d
notl %r14d
movl %r14d, (%rdi)
xorl %r14d, %r14d
cmpl $0x1, %r13d
je 0x3f54e
movl %r13d, %r14d
negl %r14d
cmpb %r11b, -0x2(%rbx,%r13)
cmoval %r14d, %r15d
movl %r15d, %r14d
cmpl %r11d, %r10d
jne 0x3f565
movl %r10d, %r11d
jmp 0x3f58b
testl %r13d, %r13d
je 0x3f595
notl %r13d
movl %r13d, (%rdi)
jmp 0x3f595
testl %r10d, %r10d
js 0x3f57c
subq %r12, %r9
shrq $0x2, %r9
orl %edx, %r10d
movslq %r10d, %r10
movl %r9d, (%rbp,%r10,4)
movq %r11, %r9
orq %r8, %r9
movslq (%rbp,%r9,4), %r9
leaq (%r12,%r9,4), %r9
movl %r14d, (%r9)
addq $-0x4, %r9
movl %r11d, %r10d
addq $-0x4, %rdi
cmpq %rdi, %rsi
jbe 0x3f519
subq $0x1, %rcx
jae 0x3f4dc
movq 0x8(%rsp), %rcx
leal -0x1(%rcx), %eax
movzbl (%rbx,%rax), %r13d
movq 0x10(%rsp), %rdx
movslq (%rdx,%r13,4), %rsi
movl %ecx, %ecx
movzbl -0x2(%rbx,%rcx), %r8d
cmpb %r13b, %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
movq 0x18(%rsp), %r15
movslq (%r8), %r11
testq %r11, %r11
jle 0x3f651
leal -0x1(%r11), %r14d
movzbl (%rbx,%r14), %r9d
movl %r9d, (%r8)
xorl %r10d, %r10d
cmpl $0x1, %r11d
je 0x3f61d
movzbl -0x2(%rbx,%r11), %r11d
movl %r14d, %r10d
cmpb %r9b, %r11b
jae 0x3f61d
notl %r11d
movl %r11d, %r10d
cmpl %r9d, %r13d
je 0x3f643
subq %r12, %rdi
shrq $0x2, %rdi
movl %r13d, %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, %r13d
movl %r10d, (%rdi)
addq $0x4, %rdi
movq 0x10(%rsp), %rdx
jmp 0x3f661
testl %r11d, %r11d
je 0x3f65e
notl %r11d
movl %r11d, (%r8)
jmp 0x3f661
movq %r8, %rax
addq $0x4, %r8
cmpq %rsi, %r8
jb 0x3f5ec
subq %r12, %rax
shrq $0x2, %rax
movb -0x1(%rbx,%rcx), %cl
movb %cl, (%r15)
testl %eax, %eax
jle 0x3f69e
movl %eax, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movq 0x8(%rsp), %r8
movb (%r12,%rcx,4), %sil
movb %sil, 0x1(%r15,%rcx)
incq %rcx
cmpq %rcx, %rdi
jne 0x3f68b
jmp 0x3f6a5
xorl %ecx, %ecx
movq 0x8(%rsp), %r8
leal 0x1(%rcx), %esi
cmpl %r8d, %esi
jge 0x3f6ce
movl %ecx, %ecx
addq %rcx, %r15
leaq (%r12,%rcx,4), %r9
movl $0x1, %esi
movb (%r9,%rsi,4), %dil
movb %dil, (%r15,%rsi)
incq %rsi
leal (%rcx,%rsi), %edi
cmpl %r8d, %edi
jl 0x3f6bb
leal 0x1(%rax), %r14d
movq %rbp, %rdi
movq %rdx, %rbx
callq 0x4200
movq %rbx, %rdi
callq 0x4200
cmpq $0x0, 0x20(%rsp)
jne 0x3f6f5
movq %r12, %rdi
callq 0x4200
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq