// File: /workspace/github_c_makefile_star2_O3/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 0x7a21
cmpq $-0x9, %rax
ja 0xb328
movl 0xc(%rsp), %esi
movq $-0x5, %rcx
cmpq $0xc, %rsi
ja 0xb32b
movl 0x8(%rsp), %edx
movl (%rbx), %edi
incl %edi
movq $-0x7, %rcx
cmpl %edi, %edx
ja 0xb32b
testl %esi, %esi
je 0xb241
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 0xb227
movl $0x0, (%r15)
testq %rdx, %rdx
je 0xb2bd
leal 0x1(%rsi), %ecx
xorl %edi, %edi
xorl %r9d, %r9d
xorl %r8d, %r8d
movb 0x90(%rsp,%r9), %r10b
movl %ecx, %r11d
subb %r10b, %r11b
xorl %ebp, %ebp
testb %r10b, %r10b
sete %bpl
movzbl %r11b, %r10d
cmovel %edi, %r10d
orl %ebp, %r8d
movb %r10b, 0x2(%r14,%r9,4)
incq %r9
cmpq %r9, %rdx
jne 0xb258
movl %r8d, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x3c(%rsp)
movaps %xmm0, 0x30(%rsp)
movups %xmm0, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
testq %rdx, %rdx
je 0xb2d4
xorl %ecx, %ecx
movzbl 0x2(%r14,%rcx,4), %edi
incw 0x30(%rsp,%rdi,2)
incq %rcx
cmpq %rcx, %rdx
jne 0xb2a8
jmp 0xb2d4
xorps %xmm0, %xmm0
movups %xmm0, 0x3c(%rsp)
movaps %xmm0, 0x30(%rsp)
movups %xmm0, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
movw $0x0, 0x12(%rsp,%rsi,2)
testl %esi, %esi
je 0xb2f9
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 0xb2e3
testq %rdx, %rdx
je 0xb324
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 0xb300
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