// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/reads2twobit.c
// Function: gt_reads2twobit_sort
void gt_reads2twobit_sort(GtReads2Twobit *r2t, GtCompareWithData cmp,
    void *cmp_data)
{
  GtTwobitencoding *tbe, *tbe_next, offset;
  GtUword i, *order;

  gt_assert(r2t != NULL);

  order = gt_malloc(sizeof (*order) * r2t->nofseqs);
  for (i = 0; i < r2t->nofseqs; i++)
    order[i] = i;

  gt_qsort_r(order, (size_t)r2t->nofseqs, sizeof *order, cmp_data, cmp);

  tbe = gt_malloc(sizeof (*tbe) *
      GT_DIVBYUNITSIN2BITENC(r2t->total_seqlength) + 2UL);

  offset = 0;
  tbe_next = tbe;
  for (i = 0; i < r2t->nofseqs; i++)
  {
    tbe_next = gt_reads2twobit_write_encoded(r2t, order[i], tbe_next, offset,
        &offset);
    if (r2t->seqlen_eqlen == 0)
    {
      /* recycle order memory to store new seppos */
      order[i] = (order[i] == 0)
        ? r2t->seppos[0]
        : r2t->seppos[order[i]] - (r2t->seppos[order[i] - 1UL] + 1UL);
      if (i > 0)
        order[i] += (order[i - 1UL] + 1UL);
    }
  }

  gt_free(r2t->twobitencoding);
  r2t->twobitencoding = tbe;

  if (r2t->seqlen_eqlen == 0)
  {
    gt_free(r2t->seppos);
    r2t->seppos = order;
  }
  else
  {
    gt_free(order);
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
testq %rdi, %rdi
je 0x18ba15
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movq 0x40(%rdi), %rdi
shlq $0x3, %rdi
leaq 0x1c6d6b(%rip), %rsi    # 0x352656
movl $0x86e, %edx            # imm = 0x86E
callq 0x93160
movq %rax, %r14
xorl %eax, %eax
movq 0x40(%rbx), %rsi
cmpq %rsi, %rax
jae 0x18b90c
movq %rax, (%r14,%rax,8)
incq %rax
jmp 0x18b8fa
pushq $0x8
popq %rdx
movq %r14, %rdi
movq %r12, %rcx
movq %r15, %r8
callq 0x9d5a0
movq 0x60(%rbx), %rax
shrq $0x5, %rax
leaq 0x2(,%rax,8), %rdi
leaq 0x1c6d22(%rip), %rsi    # 0x352656
movl $0x875, %edx            # imm = 0x875
callq 0x93160
leaq 0x8(%rsp), %r12
andq $0x0, (%r12)
movq %rax, %r15
xorl %r13d, %r13d
cmpq 0x40(%rbx), %r13
jae 0x18b9ad
movq (%r14,%r13,8), %rsi
movq 0x8(%rsp), %rcx
movq %rbx, %rdi
movq %rax, %rdx
movq %r12, %r8
callq 0x18aa77
cmpq $0x0, 0x48(%rbx)
jne 0x18b9a8
movq (%r14,%r13,8), %rdx
movq 0x38(%rbx), %rsi
testq %rdx, %rdx
je 0x18b98d
movq -0x8(%rsi,%rdx,8), %rcx
notq %rcx
addq (%rsi,%rdx,8), %rcx
jmp 0x18b990
movq (%rsi), %rcx
movq %rcx, (%r14,%r13,8)
testq %r13, %r13
je 0x18b9a8
movq -0x8(%r14,%r13,8), %rdx
addq %rdx, %rcx
incq %rcx
movq %rcx, (%r14,%r13,8)
incq %r13
jmp 0x18b94e
movq 0x10(%rbx), %rdi
leaq 0x1c6c9e(%rip), %rsi    # 0x352656
movl $0x888, %edx            # imm = 0x888
callq 0x936f9
movq %r15, 0x10(%rbx)
cmpq $0x0, 0x48(%rbx)
je 0x18b9ee
leaq 0x1c6c82(%rip), %rsi    # 0x352656
movq %r14, %rdi
movl $0x892, %edx            # imm = 0x892
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x936f9
movq 0x38(%rbx), %rdi
leaq 0x1c6c5d(%rip), %rsi    # 0x352656
movl $0x88d, %edx            # imm = 0x88D
callq 0x936f9
movq %r14, 0x38(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x2ac54c(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1595ed(%rip), %rsi    # 0x2e5013
leaq 0x1c6c42(%rip), %rdx    # 0x35266f
leaq 0x1c70d3(%rip), %rcx    # 0x352b07
leaq 0x1c6c1b(%rip), %r8     # 0x352656
movl $0x86c, %r9d            # imm = 0x86C
xorl %eax, %eax
callq 0x17a50
callq 0x17390