// File: /workspace/github_c_makefile_star2_O2/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, 0x28(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movl 0x14(%rdi), %edi
shlq $0x3, %rdi
leaq 0x1bf29b(%rip), %rsi    # 0x356a11
movl $0x1d8, %edx            # imm = 0x1D8
callq 0x93160
movq %rax, (%rsp)
movl 0x14(%r14), %eax
xorl %edi, %edi
movq $0x0, 0x20(%rsp)
movl %eax, %ecx
cmpq %rcx, %rdi
jae 0x197b44
movq 0x20(%r14), %rcx
movq %rdi, 0x30(%rsp)
movl (%rcx,%rdi,4), %r12d
pushq $0x1
popq %rbp
xorl %ebx, %ebx
movl %eax, %ecx
cmpq %rcx, %rbx
jae 0x197842
movq 0x40(%r14), %rcx
movq (%rcx,%r12,8), %rdx
movb -0x1(%rdx,%rbp), %cl
cmpb $0x0, (%rdx,%rbp)
jne 0x19782e
cmpq %rbx, %r12
je 0x19782e
testb %cl, %cl
je 0x197bdb
movq 0x28(%rsp), %rdi
leaq 0x1bf25e(%rip), %rsi    # 0x356a44
movl %r12d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x92e71
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x197cff
movq %rax, %r15
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x197d9a
addq 0x20(%rsp), %r15
subq %rax, %r15
movq 0x40(%r14), %rax
movq (%rax,%r12,8), %rax
movb $0x1, (%rax,%rbp)
movl 0x14(%r14), %eax
movq %r15, 0x20(%rsp)
jmp 0x197836
testb %cl, %cl
jne 0x197c09
incq %rbx
addq $0x10, %rbp
jmp 0x1977b0
movq %r14, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x197d9a
movq %rax, %rbx
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x197d9a
cmpq %rax, %rbx
jae 0x197999
xorl %ebx, %ebx
movl 0x14(%r14), %eax
movq %r14, %rdi
cmpq %rax, %rbx
jae 0x19788e
movl %ebx, %esi
movl %r12d, %edx
callq 0x197d9a
movq (%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x19786b
movl %r12d, %esi
xorl %edx, %edx
callq 0x197d9a
movq %rax, %rbp
movq (%rsp), %rax
cmpq %rbp, (%rax,%r12,8)
jbe 0x197cce
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x1af79b
movq %rax, %rdx
movq (%rsp), %rax
cmpq (%rax,%r12,8), %rbp
jae 0x19798f
movq 0x8(%rdx), %rax
testq %rax, %rax
je 0x1978d5
movq (%rax,%rbp,8), %r13
jmp 0x1978dc
movq (%rdx), %rax
movl (%rax,%rbp,4), %r13d
testq %r13, %r13
je 0x197987
movq 0x8(%r14), %rdi
leaq -0x1(%r13), %r15
movq %rdx, %rbx
movl 0x10(%r14), %edx
movq %r15, %rsi
callq 0x705e4
movq %rbx, %rdx
cmpb $-0x3, %al
ja 0x197987
movq 0x38(%r14), %rcx
movzbl %al, %esi
movl %esi, %eax
shll $0x4, %eax
cmpb $0x0, 0x1(%rcx,%rax)
jne 0x197987
movq 0x8(%rdx), %rax
testq %rax, %rax
je 0x197931
movq (%rsp), %rcx
movq (%rcx,%rsi,8), %rcx
movq %r15, (%rax,%rcx,8)
jmp 0x19795f
movabsq $0x100000001, %rax      # imm = 0x100000001
cmpq %rax, %r13
jae 0x197c41
movq (%rdx), %rax
testq %rax, %rax
je 0x197c41
decl %r13d
movq (%rsp), %rcx
movq (%rcx,%rsi,8), %rcx
movl %r13d, (%rax,%rcx,4)
testq %r15, %r15
jne 0x19797f
movq (%rsp), %rax
movq %rsi, %r15
movq (%rax,%rsi,8), %rsi
movq 0x18(%rsp), %rdi
callq 0x1af681
movq %r15, %rsi
movq %rbx, %rdx
movq (%rsp), %rax
incq (%rax,%rsi,8)
incq %rbp
jmp 0x1978b8
movq 0x18(%rsp), %rdi
callq 0x1af869
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x197cff
movq %rax, %rbx
movl 0x14(%r14), %edx
movq %r14, %rdi
movl %r12d, %esi
callq 0x197cff
cmpq %rax, %rbx
jae 0x197b05
xorl %ebx, %ebx
movl 0x14(%r14), %edx
movq %r14, %rdi
cmpq %rdx, %rbx
jae 0x1979ea
movl %ebx, %esi
movl %r12d, %edx
callq 0x197cff
decq %rax
movq (%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x1979c4
movl %r12d, %esi
callq 0x197cff
testq %rax, %rax
je 0x197c9d
movl 0x14(%r14), %edx
movq %r14, %rdi
movl %r12d, %esi
callq 0x197cff
movq %rax, %rbp
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x1af79b
movq %rax, %rdx
movq (%rsp), %rax
movq (%rax,%r12,8), %rax
incq %rax
cmpq %rax, %rbp
jbe 0x197afb
movq 0x8(%rdx), %rax
testq %rax, %rax
je 0x197a40
movq -0x8(%rax,%rbp,8), %r13
jmp 0x197a48
movq (%rdx), %rax
movl -0x4(%rax,%rbp,4), %r13d
testq %r13, %r13
je 0x197af3
movq 0x8(%r14), %rdi
leaq -0x1(%r13), %r15
movq %rdx, %rbx
movl 0x10(%r14), %edx
movq %r15, %rsi
callq 0x705e4
movq %rbx, %rdx
cmpb $-0x3, %al
ja 0x197af3
movq 0x38(%r14), %rcx
movzbl %al, %esi
movl %esi, %eax
shll $0x4, %eax
cmpb $0x0, 0x1(%rcx,%rax)
jne 0x197af3
movq 0x8(%rdx), %rax
testq %rax, %rax
je 0x197a9d
movq (%rsp), %rcx
movq (%rcx,%rsi,8), %rcx
movq %r15, (%rax,%rcx,8)
jmp 0x197acb
movabsq $0x100000001, %rax      # imm = 0x100000001
cmpq %rax, %r13
jae 0x197c6f
movq (%rdx), %rax
testq %rax, %rax
je 0x197c6f
decl %r13d
movq (%rsp), %rcx
movq (%rcx,%rsi,8), %rcx
movl %r13d, (%rax,%rcx,4)
testq %r15, %r15
jne 0x197aeb
movq (%rsp), %rax
movq %rsi, %r15
movq (%rax,%rsi,8), %rsi
movq 0x18(%rsp), %rdi
callq 0x1af681
movq %r15, %rsi
movq %rbx, %rdx
movq (%rsp), %rax
decq (%rax,%rsi,8)
decq %rbp
jmp 0x197a1c
movq 0x18(%rsp), %rdi
callq 0x1af869
movl 0x14(%r14), %eax
xorl %ecx, %ecx
movq 0x30(%rsp), %rdi
cmpq %rcx, %rax
je 0x197b2e
movq 0x40(%r14), %rdx
movq (%rdx,%rcx,8), %rdx
movq %r12, %rsi
shlq $0x4, %rsi
movb $0x1, 0x1(%rdx,%rsi)
incq %rcx
jmp 0x197b10
movq 0x38(%r14), %rcx
shlq $0x4, %r12
movb $0x1, 0x1(%rcx,%r12)
incq %rdi
jmp 0x197793
leaq 0x1beec6(%rip), %rsi    # 0x356a11
movq (%rsp), %rdi
movl $0x20e, %edx            # imm = 0x20E
callq 0x936f9
movq 0x20(%rsp), %rbx
movq %rbx, %xmm0
punpckldq 0x14fd75(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x14fd7d(%rip), %xmm0   # 0x2e78f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
movq 0x8(%r14), %rdi
callq 0x7055e
movq %rax, %xmm0
punpckldq 0x14fd46(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x14fd4e(%rip), %xmm0   # 0x2e78f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd (%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x1bef0c(%rip), %rsi    # 0x356aca
movq 0x28(%rsp), %rdi
movq %rbx, %rdx
movb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x92e71
movq 0x2a0386(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x14d427(%rip), %rsi    # 0x2e5013
leaq 0x1bee66(%rip), %rdx    # 0x356a59
leaq 0x1bee30(%rip), %rcx    # 0x356a2a
leaq 0x1bee10(%rip), %r8     # 0x356a11
movl $0x1e0, %r9d            # imm = 0x1E0
jmp 0x197c35
movq 0x2a0358(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x14d3f9(%rip), %rsi    # 0x2e5013
leaq 0x1bee37(%rip), %rdx    # 0x356a58
leaq 0x1bee02(%rip), %rcx    # 0x356a2a
leaq 0x1bede2(%rip), %r8     # 0x356a11
movl $0x1e7, %r9d            # imm = 0x1E7
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x2a0320(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x14d3c1(%rip), %rsi    # 0x2e5013
leaq 0x1bf0b7(%rip), %rdx    # 0x356d10
leaq 0x1bf096(%rip), %rcx    # 0x356cf6
leaq 0x1bedaa(%rip), %r8     # 0x356a11
movl $0x1a1, %r9d            # imm = 0x1A1
jmp 0x197c35
movq 0x2a02f2(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x14d393(%rip), %rsi    # 0x2e5013
leaq 0x1bf089(%rip), %rdx    # 0x356d10
leaq 0x1bf0d1(%rip), %rcx    # 0x356d5f
leaq 0x1bed7c(%rip), %r8     # 0x356a11
movl $0x1bc, %r9d            # imm = 0x1BC
jmp 0x197c35
movq 0x2a02c4(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x14d365(%rip), %rsi    # 0x2e5013
leaq 0x1beddb(%rip), %rdx    # 0x356a90
leaq 0x1bed6e(%rip), %rcx    # 0x356a2a
leaq 0x1bed4e(%rip), %r8     # 0x356a11
movl $0x200, %r9d            # imm = 0x200
jmp 0x197c35
movq 0x2a0293(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x14d334(%rip), %rsi    # 0x2e5013
leaq 0x1beff5(%rip), %rdx    # 0x356cdb
leaq 0x1bf009(%rip), %rcx    # 0x356cf6
leaq 0x1bed1d(%rip), %r8     # 0x356a11
movl $0x194, %r9d            # imm = 0x194
jmp 0x197c35