// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %r8, %r15
movq %rdx, %r9
movq %rsi, %rbx
movq %rdi, %r14
xorl %edx, %edx
leaq 0xc(%rsp), %r8
movl %edx, (%r8)
leaq 0x8(%rsp), %rax
movl %edx, (%rax)
movq %rcx, (%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movl $0x100, %esi            # imm = 0x100
movq %rax, %rcx
callq 0x740e
cmpq $-0x9, %rax
ja 0xa591
movl 0xc(%rsp), %esi
movq $-0x5, %rcx
cmpq $0xc, %rsi
ja 0xa594
movl 0x8(%rsp), %edx
movl (%rbx), %edi
incl %edi
movq $-0x7, %rcx
cmpl %edi, %edx
ja 0xa594
testl %esi, %esi
je 0xa4c3
xorl %ecx, %ecx
xorl %edi, %edi
movl 0x54(%rsp,%rcx,4), %r8d
shll %cl, %r8d
addl %edi, %r8d
movl %edi, 0x54(%rsp,%rcx,4)
incq %rcx
movl %r8d, %edi
cmpq %rcx, %rsi
jne 0xa4a9
movl $0x0, (%r15)
testq %rdx, %rdx
je 0xa50c
leal 0x1(%rsi), %ecx
movl (%r15), %edi
xorl %r8d, %r8d
xorl %r9d, %r9d
movb 0x90(%rsp,%r9), %r10b
movl %ecx, %r11d
subb %r10b, %r11b
xorl %ebp, %ebp
testb %r10b, %r10b
sete %bpl
movzbl %r11b, %r10d
cmovel %r8d, %r10d
orl %ebp, %edi
movb %r10b, 0x2(%r14,%r9,4)
incq %r9
cmpq %r9, %rdx
jne 0xa4db
movl %edi, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x3c(%rsp)
movaps %xmm0, 0x30(%rsp)
movups %xmm0, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
testq %rdx, %rdx
je 0xa53d
xorl %ecx, %ecx
movzbl 0x2(%r14,%rcx,4), %edi
incw 0x30(%rsp,%rdi,2)
incq %rcx
cmpq %rcx, %rdx
jne 0xa52a
movw $0x0, 0x12(%rsp,%rsi,2)
testl %esi, %esi
je 0xa562
xorl %ecx, %ecx
movl %esi, %edi
movw %cx, 0x10(%rsp,%rsi,2)
addw 0x30(%rsp,%rsi,2), %cx
movzwl %cx, %ecx
shrl %ecx
decq %rsi
decl %edi
jne 0xa54c
testq %rdx, %rdx
je 0xa58d
xorl %ecx, %ecx
movzbl 0x2(%r14,%rcx,4), %esi
movzwl 0x10(%rsp,%rsi,2), %edi
movl %edi, %r8d
incl %r8d
movw %r8w, 0x10(%rsp,%rsi,2)
movw %di, (%r14,%rcx,4)
incq %rcx
cmpq %rcx, %rdx
jne 0xa569
decl %edx
movl %edx, (%rbx)
movq %rax, %rcx
movq %rcx, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq