// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/core/countingsort.c
// Function: gt_countingsort
void gt_countingsort(void *out, const void *in, size_t elem_size,
                     GtUword size, GtUword max_elemvalue,
                     void *data, GtGetElemvalue get_elemvalue)
{
  GtUword i, k, *c;
  gt_assert(out && in && elem_size && size && max_elemvalue && get_elemvalue);

  /* allocate count array */
  c = gt_calloc(sizeof (GtUword), max_elemvalue + 1);

  /* count number of elements of a given value */
  for (i = 0; i < size; i++) {
    k = get_elemvalue((const char*) in + elem_size * i, data);
    gt_assert(k <= max_elemvalue);
    c[k]++;
  }

  /* compute running sum of the count array */
  for (i = 1; i <= max_elemvalue; i++)
    c[i] += c[i-1];

  /* sorting (stable) */
  for (i = size; i > 0; i--) {
    k = get_elemvalue((const char*) in + elem_size * (i-1), data);
    memcpy((char*) out + elem_size * (c[k] - 1),
           (const char*) in + elem_size * (i-1), elem_size);
    c[k]--;
  }

  gt_free(c);
}

// Assembly:
subq $0x48, %rsp
movq 0x50(%rsp), %rax
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0xa26a7
cmpq $0x0, 0x38(%rsp)
je 0xa26a7
cmpq $0x0, 0x30(%rsp)
je 0xa26a7
cmpq $0x0, 0x28(%rsp)
je 0xa26a7
cmpq $0x0, 0x20(%rsp)
je 0xa26a7
cmpq $0x0, 0x50(%rsp)
jne 0xa26df
movq 0x5998f2(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x47395b(%rip), %rsi    # 0x516013
leaq 0x49154c(%rip), %rdx    # 0x533c0b
leaq 0x491586(%rip), %rcx    # 0x533c4c
leaq 0x49158f(%rip), %r8     # 0x533c5c
movl $0x1d, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0xa26e1
movq 0x20(%rsp), %rsi
addq $0x1, %rsi
movl $0x8, %edi
leaq 0x491566(%rip), %rdx    # 0x533c5c
movl $0x20, %ecx
callq 0xe83c0
movq %rax, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x28(%rsp), %rax
jae 0xa27af
movq 0x50(%rsp), %rax
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rcx
imulq 0x10(%rsp), %rcx
addq %rcx, %rdi
movq 0x18(%rsp), %rsi
callq *%rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x20(%rsp), %rax
jbe 0xa2785
movq 0x59984c(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x4738b5(%rip), %rsi    # 0x516013
leaq 0x49150f(%rip), %rdx    # 0x533c74
leaq 0x4914e0(%rip), %rcx    # 0x533c4c
leaq 0x4914e9(%rip), %r8     # 0x533c5c
movl $0x25, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0xa2787
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0xa270d
movq $0x1, 0x10(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x20(%rsp), %rax
ja 0xa27f6
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0xa27b8
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jbe 0xa28a5
movq 0x50(%rsp), %rax
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rdx
subq $0x1, %rdx
imulq %rdx, %rcx
addq %rcx, %rdi
movq 0x18(%rsp), %rsi
callq *%rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rax
movq (%rsp), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
subq $0x1, %rcx
imulq %rcx, %rax
addq %rax, %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
subq $0x1, %rcx
imulq %rcx, %rax
addq %rax, %rsi
movq 0x30(%rsp), %rdx
callq 0x19610
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
addq $-0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0xa2800
movq (%rsp), %rdi
leaq 0x4913ac(%rip), %rsi    # 0x533c5c
movl $0x35, %edx
callq 0xe88c0
addq $0x48, %rsp
retq
nop