// File: /workspace/github_c_makefile_star2_O0/Cyan4973[P]FiniteStateEntropy/programs/../lib/huf_compress.c
// Function: HUF_readCTable
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned* hasZeroWeights)
{
    BYTE huffWeight[HUF_SYMBOLVALUE_MAX + 1];   /* init not required, even though some static analyzer may complain */
    U32 rankVal[HUF_TABLELOG_ABSOLUTEMAX + 1];   /* large enough for values from 0 to 16 */
    U32 tableLog = 0;
    U32 nbSymbols = 0;

    /* get symbol weights */
    CHECK_V_F(readSize, HUF_readStats(huffWeight, HUF_SYMBOLVALUE_MAX+1, rankVal, &nbSymbols, &tableLog, src, srcSize));

    /* check result */
    if (tableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
    if (nbSymbols > *maxSymbolValuePtr+1) return ERROR(maxSymbolValue_tooSmall);

    /* Prepare base value per rank */
    {   U32 n, nextRankStart = 0;
        for (n=1; n<=tableLog; n++) {
            U32 current = nextRankStart;
            nextRankStart += (rankVal[n] << (n-1));
            rankVal[n] = current;
    }   }

    /* fill nbBits */
    *hasZeroWeights = 0;
    {   U32 n; for (n=0; n<nbSymbols; n++) {
            const U32 w = huffWeight[n];
            *hasZeroWeights |= (w == 0);
            CTable[n].nbBits = (BYTE)(tableLog + 1 - w) & -(w != 0);
    }   }

    /* fill val */
    {   U16 nbPerRank[HUF_TABLELOG_MAX+2]  = {0};  /* support w=0=>n=tableLog+1 */
        U16 valPerRank[HUF_TABLELOG_MAX+2] = {0};
        { U32 n; for (n=0; n<nbSymbols; n++) nbPerRank[CTable[n].nbBits]++; }
        /* determine stating value per rank */
        valPerRank[tableLog+1] = 0;   /* for w==0 */
        {   U16 min = 0;
            U32 n; for (n=tableLog; n>0; n--) {  /* start at n=tablelog <-> w=1 */
                valPerRank[n] = min;     /* get starting value within each rank */
                min += nbPerRank[n];
                min >>= 1;
        }   }
        /* assign value within rank, symbol order */
        { U32 n; for (n=0; n<nbSymbols; n++) CTable[n].val = valPerRank[CTable[n].nbBits]++; }
    }

    *maxSymbolValuePtr = nbSymbols - 1;
    return readSize;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl $0x0, -0x174(%rbp)
movl $0x0, -0x178(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x170(%rbp), %rdx
movq -0x20(%rbp), %r9
movq -0x28(%rbp), %rax
movl $0x100, %esi            # imm = 0x100
leaq -0x178(%rbp), %rcx
leaq -0x174(%rbp), %r8
movq %rax, (%rsp)
callq 0xe940
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rdi
callq 0x151f0
cmpl $0x0, %eax
je 0x1529d
movq -0x180(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x15552
cmpl $0xc, -0x174(%rbp)
jbe 0x152b3
movq $-0x5, -0x8(%rbp)
jmp 0x15552
movl -0x178(%rbp), %eax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jbe 0x152d3
movq $-0x7, -0x8(%rbp)
jmp 0x15552
movl $0x0, -0x188(%rbp)
movl $0x1, -0x184(%rbp)
movl -0x184(%rbp), %eax
cmpl -0x174(%rbp), %eax
ja 0x15349
movl -0x188(%rbp), %eax
movl %eax, -0x18c(%rbp)
movl -0x184(%rbp), %eax
movl -0x170(%rbp,%rax,4), %eax
movl -0x184(%rbp), %ecx
subl $0x1, %ecx
shll %cl, %eax
addl -0x188(%rbp), %eax
movl %eax, -0x188(%rbp)
movl -0x18c(%rbp), %ecx
movl -0x184(%rbp), %eax
movl %ecx, -0x170(%rbp,%rax,4)
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
jmp 0x152e7
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x190(%rbp)
movl -0x190(%rbp), %eax
cmpl -0x178(%rbp), %eax
jae 0x153e2
movl -0x190(%rbp), %eax
movzbl -0x130(%rbp,%rax), %eax
movl %eax, -0x194(%rbp)
cmpl $0x0, -0x194(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x30(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
movl -0x174(%rbp), %eax
addl $0x1, %eax
subl -0x194(%rbp), %eax
movzbl %al, %eax
cmpl $0x0, -0x194(%rbp)
setne %cl
andb $0x1, %cl
movzbl %cl, %edx
xorl %ecx, %ecx
subl %edx, %ecx
andl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x190(%rbp), %ecx
movb %dl, 0x2(%rax,%rcx,4)
movl -0x190(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x190(%rbp)
jmp 0x1535d
leaq -0x1b0(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x10c0
leaq -0x1d0(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x10c0
movl $0x0, -0x1d4(%rbp)
movl -0x1d4(%rbp), %eax
cmpl -0x178(%rbp), %eax
jae 0x15454
movq -0x10(%rbp), %rax
movl -0x1d4(%rbp), %ecx
movzbl 0x2(%rax,%rcx,4), %eax
movw -0x1b0(%rbp,%rax,2), %cx
addw $0x1, %cx
movw %cx, -0x1b0(%rbp,%rax,2)
movl -0x1d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d4(%rbp)
jmp 0x15412
movl -0x174(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movw $0x0, -0x1d0(%rbp,%rax,2)
movw $0x0, -0x1d6(%rbp)
movl -0x174(%rbp), %eax
movl %eax, -0x1dc(%rbp)
cmpl $0x0, -0x1dc(%rbp)
jbe 0x154db
movw -0x1d6(%rbp), %cx
movl -0x1dc(%rbp), %eax
movw %cx, -0x1d0(%rbp,%rax,2)
movl -0x1dc(%rbp), %eax
movzwl -0x1b0(%rbp,%rax,2), %ecx
movzwl -0x1d6(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x1d6(%rbp)
movzwl -0x1d6(%rbp), %eax
sarl %eax
movw %ax, -0x1d6(%rbp)
movl -0x1dc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1dc(%rbp)
jmp 0x1547e
movl $0x0, -0x1e0(%rbp)
movl -0x1e0(%rbp), %eax
cmpl -0x178(%rbp), %eax
jae 0x15538
movq -0x10(%rbp), %rax
movl -0x1e0(%rbp), %ecx
movzbl 0x2(%rax,%rcx,4), %eax
movw -0x1d0(%rbp,%rax,2), %dx
movw %dx, %cx
addw $0x1, %cx
movw %cx, -0x1d0(%rbp,%rax,2)
movq -0x10(%rbp), %rax
movl -0x1e0(%rbp), %ecx
movw %dx, (%rax,%rcx,4)
movl -0x1e0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e0(%rbp)
jmp 0x154e5
movl -0x178(%rbp), %ecx
subl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x180(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
nop