// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/match/sfx-copysort.c
// Function: gt_copysort_derivesorting
void gt_copysort_derivesorting(const GtBucketspec2 *bucketspec2,
                               GtSuffixsortspace *suffixsortspace,
                               GtLogger *logger)
{
  GtUword hardwork = 0, *targetoffset;
  unsigned int idx, idxsource, source, second;

  targetoffset = gt_malloc(sizeof (*targetoffset) * bucketspec2->numofchars);
  for (idxsource = 0; idxsource<bucketspec2->numofchars; idxsource++)
  {
    source = bucketspec2->order[idxsource];
    for (second = 0; second < bucketspec2->numofchars; second++)
    {
      if (!bucketspec2->subbuckettab[source][second].sorted && source != second)
      {
        gt_assert(bucketspec2->subbuckettab[source][second].hardworktodo);
        gt_logger_log(logger,"hard work for %u %u",source,second);
        hardwork += getendidx(bucketspec2,source,second) -
                    getstartidx(bucketspec2,source,second);
        bucketspec2->subbuckettab[source][second].sorted = true;
      } else
      {
        gt_assert(!bucketspec2->subbuckettab[source][second].hardworktodo);
      }
    }
    if (getstartidx(bucketspec2,source,0) <
        getstartidx(bucketspec2,source,source))
    {
      for (idx = 0; idx < bucketspec2->numofchars; idx++)
      {
        targetoffset[idx] = getstartidx(bucketspec2,idx,source);
      }
      gt_copysort_forwardderive(bucketspec2,
                    suffixsortspace,
                    targetoffset,
                    source,
                    getstartidx(bucketspec2,source,0));
    }
    if (getendidx(bucketspec2,source,source) <
        getendidx(bucketspec2,source,bucketspec2->numofchars))
    {
      for (idx = 0; idx < bucketspec2->numofchars; idx++)
      {
        /* do not need to assert that getendidx(idx,source) > 0, as later the
           value stored in targetoffset is incremented */
        targetoffset[idx] = getendidx(bucketspec2,idx,source) - 1;
      }
      gt_assert(getendidx(bucketspec2,source,bucketspec2->numofchars) > 0);
      gt_copysort_backwardderive(bucketspec2,
                                 suffixsortspace,
                                 targetoffset,
                                 source,
                                 getendidx(bucketspec2,source,
                                           bucketspec2->numofchars) - 1);
    }
    for (idx = 0; idx < bucketspec2->numofchars; idx++)
    {
      bucketspec2->subbuckettab[idx][source].sorted = true;
    }
    bucketspec2->superbuckettab[source].sorted = true;
  }
  gt_free(targetoffset);
  gt_logger_log(logger,"hardwork = "GT_WU" (%.2f)",
                hardwork,
                (double) hardwork/gt_encseq_total_length(bucketspec2->encseq));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r13
movq %rsi, 0x8(%rsp)
movq %rdi, %r14
movl 0x14(%rdi), %edi
shlq $0x3, %rdi
leaq 0x1ce617(%rip), %rsi    # 0x3bfbd1
movl $0x1d8, %edx            # imm = 0x1D8
callq 0x1092b2
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x14(%r14)
je 0x1f19bd
xorl %ecx, %ecx
movq $0x0, 0x20(%rsp)
movq %r13, 0x28(%rsp)
movq 0x20(%r14), %rax
movl (%rax,%rcx,4), %r12d
cmpl $0x0, 0x14(%r14)
movq %rcx, 0x30(%rsp)
je 0x1f168c
movl $0x1, %ebp
xorl %ebx, %ebx
movq 0x40(%r14), %rax
movq (%rax,%r12,8), %rcx
movb -0x1(%rcx,%rbp), %al
cmpb $0x0, (%rcx,%rbp)
jne 0x1f1670
cmpq %rbx, %r12
je 0x1f1670
testb %al, %al
je 0x1f1a63
movq %r13, %rdi
leaq 0x1ce5d8(%rip), %rsi    # 0x3bfc04
movl %r12d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x10906e
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x1f1a7c
movq %rax, %r15
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x1f1ac1
addq 0x20(%rsp), %r15
subq %rax, %r15
movq 0x40(%r14), %rax
movq (%rax,%r12,8), %rax
movb $0x1, (%rax,%rbp)
movq %r15, 0x20(%rsp)
jmp 0x1f1678
testb %al, %al
jne 0x1f1a5e
incq %rbx
movl 0x14(%r14), %eax
addq $0x10, %rbp
cmpq %rax, %rbx
jb 0x1f1603
movq %r14, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x1f1ac1
movq %rax, %rbx
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x1f1ac1
cmpq %rax, %rbx
jae 0x1f17f3
cmpl $0x0, 0x14(%r14)
movq 0x10(%rsp), %r15
je 0x1f16de
xorl %ebx, %ebx
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x1f1ac1
movq %rax, (%r15,%rbx,8)
incq %rbx
movl 0x14(%r14), %eax
cmpq %rax, %rbx
jb 0x1f16c1
movq %r14, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x1f1ac1
cmpq %rax, (%r15,%r12,8)
jbe 0x1f1a68
movq %rax, %rbp
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x205fd8
cmpq %rbp, (%r15,%r12,8)
jbe 0x1f17e4
movq %rax, %rsi
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x1f1720
movq (%rax,%rbp,8), %r13
jmp 0x1f1727
movq (%rsi), %rax
movl (%rax,%rbp,4), %r13d
testq %r13, %r13
je 0x1f17d2
movq 0x8(%r14), %rdi
leaq -0x1(%r13), %r15
movl 0x10(%r14), %edx
movq %rsi, %rbx
movq %r15, %rsi
callq 0xec1f8
movq %rbx, %rsi
cmpb $-0x3, %al
ja 0x1f17d2
movq 0x38(%r14), %rcx
movzbl %al, %edi
movl %edi, %eax
shll $0x4, %eax
cmpb $0x0, 0x1(%rcx,%rax)
jne 0x1f17d2
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x1f177e
movq 0x10(%rsp), %r13
movq (%r13,%rdi,8), %rcx
movq %r15, (%rax,%rcx,8)
jmp 0x1f17b0
movabsq $0x100000001, %rax      # imm = 0x100000001
cmpq %rax, %r13
jae 0x1f1a77
movq (%rsi), %rax
testq %rax, %rax
je 0x1f1a77
decl %r13d
movq 0x10(%rsp), %rdx
movq (%rdx,%rdi,8), %rcx
movl %r13d, (%rax,%rcx,4)
movq %rdx, %r13
testq %r15, %r15
jne 0x1f17cd
movq (%r13,%rdi,8), %rsi
movq %rdi, %r15
movq 0x8(%rsp), %rdi
callq 0x205f1e
movq %r15, %rdi
movq %rbx, %rsi
incq (%r13,%rdi,8)
incq %rbp
movq 0x10(%rsp), %rax
cmpq (%rax,%r12,8), %rbp
jb 0x1f1711
movq 0x8(%rsp), %rdi
callq 0x20604d
movq 0x28(%rsp), %r13
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x1f1a7c
movq %rax, %rbx
movl 0x14(%r14), %edx
movq %r14, %rdi
movl %r12d, %esi
callq 0x1f1a7c
cmpq %rax, %rbx
jae 0x1f1971
movl 0x14(%r14), %edx
testl %edx, %edx
movq 0x10(%rsp), %r15
je 0x1f184b
xorl %ebx, %ebx
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x1f1a7c
decq %rax
movq %rax, (%r15,%rbx,8)
incq %rbx
movl 0x14(%r14), %edx
cmpq %rdx, %rbx
jb 0x1f182b
movq %r14, %rdi
movl %r12d, %esi
callq 0x1f1a7c
testq %rax, %rax
je 0x1f1a6d
movl 0x14(%r14), %edx
movq %r14, %rdi
movl %r12d, %esi
callq 0x1f1a7c
movq %rax, %rbp
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x205fd8
movq %rax, %rsi
movq (%r15,%r12,8), %rax
incq %rax
cmpq %rax, %rbp
jbe 0x1f1962
decq %rbp
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x1f18a2
movq (%rax,%rbp,8), %r13
jmp 0x1f18a9
movq (%rsi), %rax
movl (%rax,%rbp,4), %r13d
testq %r13, %r13
je 0x1f1954
movq 0x8(%r14), %rdi
leaq -0x1(%r13), %r15
movl 0x10(%r14), %edx
movq %rsi, %rbx
movq %r15, %rsi
callq 0xec1f8
movq %rbx, %rsi
cmpb $-0x3, %al
ja 0x1f1954
movq 0x38(%r14), %rcx
movzbl %al, %edi
movl %edi, %eax
shll $0x4, %eax
cmpb $0x0, 0x1(%rcx,%rax)
jne 0x1f1954
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x1f1900
movq 0x10(%rsp), %r13
movq (%r13,%rdi,8), %rcx
movq %r15, (%rax,%rcx,8)
jmp 0x1f1932
movabsq $0x100000001, %rax      # imm = 0x100000001
cmpq %rax, %r13
jae 0x1f1a72
movq (%rsi), %rax
testq %rax, %rax
je 0x1f1a72
decl %r13d
movq 0x10(%rsp), %rdx
movq (%rdx,%rdi,8), %rcx
movl %r13d, (%rax,%rcx,4)
movq %rdx, %r13
testq %r15, %r15
jne 0x1f194f
movq (%r13,%rdi,8), %rsi
movq %rdi, %r15
movq 0x8(%rsp), %rdi
callq 0x205f1e
movq %r15, %rdi
movq %rbx, %rsi
decq (%r13,%rdi,8)
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rax
jmp 0x1f1884
movq 0x8(%rsp), %rdi
callq 0x20604d
movq 0x28(%rsp), %r13
movl 0x14(%r14), %eax
testq %rax, %rax
je 0x1f1998
movq 0x40(%r14), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movq %r12, %rdi
shlq $0x4, %rdi
movb $0x1, 0x1(%rsi,%rdi)
incq %rdx
cmpq %rdx, %rax
jne 0x1f1980
movq 0x38(%r14), %rax
shlq $0x4, %r12
movb $0x1, 0x1(%rax,%r12)
movq 0x30(%rsp), %rcx
incq %rcx
movl 0x14(%r14), %eax
cmpq %rax, %rcx
jb 0x1f15e4
jmp 0x1f19c6
movq $0x0, 0x20(%rsp)
leaq 0x1ce204(%rip), %rsi    # 0x3bfbd1
movq 0x10(%rsp), %rdi
movl $0x20e, %edx            # imm = 0x20E
callq 0x109670
movq 0x20(%rsp), %rbx
movq %rbx, %xmm0
punpckldq 0x15eef2(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x15eefa(%rip), %xmm0   # 0x3508f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movq 0x8(%r14), %rdi
callq 0xec1d8
movq %rax, %xmm0
punpckldq 0x15eec2(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x15eeca(%rip), %xmm0   # 0x3508f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x1ce247(%rip), %rsi    # 0x3bfc8a
movq %r13, %rdi
movq %rbx, %rdx
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10906e
callq 0x78a41
callq 0x78a08
callq 0x78a7a
callq 0x78b25
callq 0x78aec
callq 0x78ab3