// File: /workspace/github_c_makefile_star2_O0/Cyan4973[P]FiniteStateEntropy/programs/../lib/huf_compress.c
// Function: HUF_sort
static void HUF_sort(nodeElt* huffNode, const unsigned* count, U32 maxSymbolValue, rankPos* rankPosition)
{
    U32 n;

    memset(rankPosition, 0, sizeof(*rankPosition) * RANK_POSITION_TABLE_SIZE);
    for (n=0; n<=maxSymbolValue; n++) {
        U32 r = BIT_highbit32(count[n] + 1);
        rankPosition[r].base ++;
    }
    for (n=30; n>0; n--) rankPosition[n-1].base += rankPosition[n].base;
    for (n=0; n<32; n++) rankPosition[n].current = rankPosition[n].base;
    for (n=0; n<=maxSymbolValue; n++) {
        U32 const c = count[n];
        U32 const r = BIT_highbit32(c+1) + 1;
        U32 pos = rankPosition[r].current++;
        while ((pos > rankPosition[r].base) && (c > huffNode[pos-1].count)) {
            huffNode[pos] = huffNode[pos-1];
            pos--;
        }
        huffNode[pos].count = c;
        huffNode[pos].byte  = (BYTE)n;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10c0
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
ja 0x15a96
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %edi
addl $0x1, %edi
callq 0x16c10
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl -0x28(%rbp), %ecx
movl (%rax,%rcx,8), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x15a5e
movl $0x1e, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jbe 0x15aca
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,8), %edx
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
addl (%rax,%rcx,8), %edx
movl %edx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x15a9d
movl $0x0, -0x24(%rbp)
cmpl $0x20, -0x24(%rbp)
jae 0x15af7
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,8), %edx
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x15ad1
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
ja 0x15bc9
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
addl $0x1, %edi
callq 0x16c10
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rcx
movl -0x30(%rbp), %eax
movl %eax, %edx
movl 0x4(%rcx,%rdx,8), %eax
movl %eax, %esi
addl $0x1, %esi
movl %esi, 0x4(%rcx,%rdx,8)
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rdx
movl -0x30(%rbp), %eax
movl %eax, %esi
xorl %eax, %eax
cmpl (%rdx,%rsi,8), %ecx
movb %al, -0x35(%rbp)
jbe 0x15b6f
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl -0x34(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
cmpl (%rcx,%rdx,8), %eax
seta %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x15b78
jmp 0x15b9e
movq -0x8(%rbp), %rax
movl -0x34(%rbp), %ecx
movq -0x8(%rbp), %rdx
movl -0x34(%rbp), %esi
subl $0x1, %esi
movl %esi, %esi
movq (%rdx,%rsi,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x15b41
movl -0x2c(%rbp), %edx
movq -0x8(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %edx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x34(%rbp), %ecx
movb %dl, 0x6(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x15afe
addq $0x40, %rsp
popq %rbp
retq
nop