// File: /workspace/github_c_makefile_star2_O3/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 0x1ce766(%rip), %rsi    # 0x3b65b1
movl $0x1d8, %edx            # imm = 0x1D8
callq 0x104226
movq %rax, 0x10(%rsp)
movl 0x14(%r14), %eax
testl %eax, %eax
je 0x1e8259
xorl %edx, %edx
movq $0x0, 0x20(%rsp)
movq %r13, 0x28(%rsp)
movq 0x20(%r14), %rcx
movq %rdx, 0x30(%rsp)
movl (%rcx,%rdx,4), %r12d
testl %eax, %eax
je 0x1e7f1d
movq 0x40(%r14), %rcx
movl $0x1, %ebp
xorl %ebx, %ebx
movq (%rcx,%r12,8), %rsi
movb -0x1(%rsi,%rbp), %dl
cmpq %rbx, %r12
je 0x1e7f03
cmpb $0x0, (%rsi,%rbp)
jne 0x1e7f03
testb %dl, %dl
je 0x1e82ff
movq %r13, %rdi
leaq 0x1ce729(%rip), %rsi    # 0x3b65e4
movl %r12d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x103fe1
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x1e8318
movq %rax, %r15
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x1e835d
addq 0x20(%rsp), %r15
subq %rax, %r15
movq 0x40(%r14), %rcx
movq (%rcx,%r12,8), %rax
movb $0x1, (%rax,%rbp)
movl 0x14(%r14), %eax
movq %r15, 0x20(%rsp)
jmp 0x1e7f0b
testb %dl, %dl
jne 0x1e82fa
incq %rbx
movl %eax, %edx
addq $0x10, %rbp
cmpq %rdx, %rbx
jb 0x1e7e96
movq %r14, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x1e835d
movq %rax, %rbx
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x1e835d
cmpq %rax, %rbx
jae 0x1e8084
cmpl $0x0, 0x14(%r14)
movq 0x10(%rsp), %r15
je 0x1e7f6f
xorl %ebx, %ebx
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x1e835d
movq %rax, (%r15,%rbx,8)
incq %rbx
movl 0x14(%r14), %eax
cmpq %rax, %rbx
jb 0x1e7f52
movq %r14, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x1e835d
cmpq %rax, (%r15,%r12,8)
jbe 0x1e8304
movq %rax, %rbp
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x1fc8da
cmpq %rbp, (%r15,%r12,8)
jbe 0x1e8075
movq %rax, %rsi
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x1e7fb1
movq (%rax,%rbp,8), %r13
jmp 0x1e7fb8
movq (%rsi), %rax
movl (%rax,%rbp,4), %r13d
testq %r13, %r13
je 0x1e8063
movq 0x8(%r14), %rdi
leaq -0x1(%r13), %r15
movl 0x10(%r14), %edx
movq %rsi, %rbx
movq %r15, %rsi
callq 0xe7bbc
movq %rbx, %rsi
cmpb $-0x3, %al
ja 0x1e8063
movq 0x38(%r14), %rcx
movzbl %al, %edi
movl %edi, %eax
shll $0x4, %eax
cmpb $0x0, 0x1(%rcx,%rax)
jne 0x1e8063
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x1e800f
movq 0x10(%rsp), %r13
movq (%r13,%rdi,8), %rcx
movq %r15, (%rax,%rcx,8)
jmp 0x1e8041
movabsq $0x100000001, %rax      # imm = 0x100000001
cmpq %rax, %r13
jae 0x1e8313
movq (%rsi), %rax
testq %rax, %rax
je 0x1e8313
decl %r13d
movq 0x10(%rsp), %rdx
movq (%rdx,%rdi,8), %rcx
movl %r13d, (%rax,%rcx,4)
movq %rdx, %r13
testq %r15, %r15
jne 0x1e805e
movq (%r13,%rdi,8), %rsi
movq %rdi, %r15
movq 0x8(%rsp), %rdi
callq 0x1fc820
movq %r15, %rdi
movq %rbx, %rsi
incq (%r13,%rdi,8)
incq %rbp
movq 0x10(%rsp), %rax
cmpq (%rax,%r12,8), %rbp
jb 0x1e7fa2
movq 0x8(%rsp), %rdi
callq 0x1fc94f
movq 0x28(%rsp), %r13
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x1e8318
movq %rax, %rbx
movl 0x14(%r14), %edx
movq %r14, %rdi
movl %r12d, %esi
callq 0x1e8318
cmpq %rax, %rbx
jae 0x1e820a
cmpl $0x0, 0x14(%r14)
je 0x1e80dd
xorl %ebx, %ebx
movq 0x10(%rsp), %r15
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x1e8318
decq %rax
movq %rax, (%r15,%rbx,8)
incq %rbx
movl 0x14(%r14), %edx
cmpq %rdx, %rbx
jb 0x1e80bb
jmp 0x1e80e4
xorl %edx, %edx
movq 0x10(%rsp), %r15
movq %r14, %rdi
movl %r12d, %esi
callq 0x1e8318
testq %rax, %rax
je 0x1e8309
movl 0x14(%r14), %edx
movq %r14, %rdi
movl %r12d, %esi
callq 0x1e8318
movq %rax, %rbp
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x1fc8da
movq %rax, %rsi
movq (%r15,%r12,8), %rax
incq %rax
cmpq %rax, %rbp
jbe 0x1e81fb
decq %rbp
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x1e813b
movq (%rax,%rbp,8), %r13
jmp 0x1e8142
movq (%rsi), %rax
movl (%rax,%rbp,4), %r13d
testq %r13, %r13
je 0x1e81ed
movq 0x8(%r14), %rdi
leaq -0x1(%r13), %r15
movl 0x10(%r14), %edx
movq %rsi, %rbx
movq %r15, %rsi
callq 0xe7bbc
movq %rbx, %rsi
cmpb $-0x3, %al
ja 0x1e81ed
movq 0x38(%r14), %rcx
movzbl %al, %edi
movl %edi, %eax
shll $0x4, %eax
cmpb $0x0, 0x1(%rcx,%rax)
jne 0x1e81ed
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x1e8199
movq 0x10(%rsp), %r13
movq (%r13,%rdi,8), %rcx
movq %r15, (%rax,%rcx,8)
jmp 0x1e81cb
movabsq $0x100000001, %rax      # imm = 0x100000001
cmpq %rax, %r13
jae 0x1e830e
movq (%rsi), %rax
testq %rax, %rax
je 0x1e830e
decl %r13d
movq 0x10(%rsp), %rdx
movq (%rdx,%rdi,8), %rcx
movl %r13d, (%rax,%rcx,4)
movq %rdx, %r13
testq %r15, %r15
jne 0x1e81e8
movq (%r13,%rdi,8), %rsi
movq %rdi, %r15
movq 0x8(%rsp), %rdi
callq 0x1fc820
movq %r15, %rdi
movq %rbx, %rsi
decq (%r13,%rdi,8)
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rax
jmp 0x1e811d
movq 0x8(%rsp), %rdi
callq 0x1fc94f
movq 0x28(%rsp), %r13
movl 0x14(%r14), %eax
testq %rax, %rax
je 0x1e8236
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 0x1e8219
movq %rax, %rcx
jmp 0x1e8238
xorl %ecx, %ecx
movq 0x38(%r14), %rdx
shlq $0x4, %r12
movb $0x1, 0x1(%rdx,%r12)
movq 0x30(%rsp), %rdx
incq %rdx
cmpq %rcx, %rdx
jb 0x1e7e76
jmp 0x1e8262
movq $0x0, 0x20(%rsp)
leaq 0x1ce348(%rip), %rsi    # 0x3b65b1
movq 0x10(%rsp), %rdi
movl $0x20e, %edx            # imm = 0x20E
callq 0x1045eb
movq 0x20(%rsp), %rbx
movq %rbx, %xmm0
punpckldq 0x15f656(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x15f65e(%rip), %xmm0   # 0x3478f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movq 0x8(%r14), %rdi
callq 0xe7b9c
movq %rax, %xmm0
punpckldq 0x15f626(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x15f62e(%rip), %xmm0   # 0x3478f0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x1ce38b(%rip), %rsi    # 0x3b666a
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 0x103fe1
callq 0x76db4
callq 0x76d7b
callq 0x76ded
callq 0x76e98
callq 0x76e5f
callq 0x76e26