// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x2a48f3
movq 0x3976de(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x271747(%rip), %rsi    # 0x516013
leaq 0x2e06f6(%rip), %rdx    # 0x584fc9
leaq 0x2e0b8b(%rip), %rcx    # 0x585465
leaq 0x2e06cf(%rip), %r8     # 0x584fb0
movl $0x86c, %r9d            # imm = 0x86C
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x2a48f5
movq 0x40(%rsp), %rax
movq 0x40(%rax), %rdi
shlq $0x3, %rdi
leaq 0x2e06a7(%rip), %rsi    # 0x584fb0
movl $0x86e, %edx            # imm = 0x86E
callq 0xe80f0
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x40(%rsp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x2a4954
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x2a4921
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x40(%rax), %rsi
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
movl $0x8, %edx
callq 0xfb9e0
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rdi
shrq $0x5, %rdi
shlq $0x3, %rdi
addq $0x2, %rdi
leaq 0x2e061e(%rip), %rsi    # 0x584fb0
movl $0x875, %edx            # imm = 0x875
callq 0xe80f0
movq %rax, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq 0x40(%rsp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x2a4ace
movq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0x2a2d60
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x2a4ab9
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x2a4a30
movq 0x40(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movq %rax, (%rsp)
jmp 0x2a4a75
movq 0x40(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq (%rax,%rcx,8), %rax
movq 0x40(%rsp), %rcx
movq 0x38(%rcx), %rcx
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq (%rdx,%rsi,8), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
addq $0x1, %rcx
subq %rcx, %rax
movq %rax, (%rsp)
movq (%rsp), %rdx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
cmpq $0x0, 0x10(%rsp)
jbe 0x2a4ab7
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x2a4ab9
jmp 0x2a4abb
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x2a49bd
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x2e04d2(%rip), %rsi    # 0x584fb0
movl $0x888, %edx            # imm = 0x888
callq 0xe88c0
movq 0x28(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x40(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x2a4b2c
movq 0x40(%rsp), %rax
movq 0x38(%rax), %rdi
leaq 0x2e049e(%rip), %rsi    # 0x584fb0
movl $0x88d, %edx            # imm = 0x88D
callq 0xe88c0
movq 0x8(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x38(%rax)
jmp 0x2a4b42
movq 0x8(%rsp), %rdi
leaq 0x2e0478(%rip), %rsi    # 0x584fb0
movl $0x892, %edx            # imm = 0x892
callq 0xe88c0
addq $0x48, %rsp
retq
nopw (%rax,%rax)