// File: /workspace/github_c_makefile_star2_O2/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
leaq 0xc(%rsp), %r8
andl $0x0, (%r8)
leaq 0x8(%rsp), %rax
andl $0x0, (%rax)
movq %rcx, (%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movl $0x100, %esi            # imm = 0x100
movq %rax, %rcx
callq 0x6aad
cmpq $-0x9, %rax
ja 0x9382
movl 0xc(%rsp), %esi
cmpq $0xc, %rsi
jbe 0x928c
pushq $-0x5
jmp 0x929a
movl 0x8(%rsp), %edx
movl (%rbx), %ecx
incl %ecx
cmpl %ecx, %edx
jbe 0x92a0
pushq $-0x7
popq %rax
jmp 0x9382
xorl %ecx, %ecx
xorl %edi, %edi
cmpq %rcx, %rsi
je 0x92c0
movl 0x54(%rsp,%rcx,4), %r8d
shll %cl, %r8d
addl %edi, %r8d
movl %edi, 0x54(%rsp,%rcx,4)
incq %rcx
movl %r8d, %edi
jmp 0x92a4
andl $0x0, (%r15)
leal 0x1(%rsi), %ecx
xorl %edi, %edi
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpq %r9, %rdx
je 0x9303
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
movl %r8d, (%r15)
movb %r10b, 0x2(%r14,%r9,4)
incq %r9
jmp 0x92cf
xorps %xmm0, %xmm0
movups %xmm0, 0x3c(%rsp)
movaps %xmm0, 0x30(%rsp)
movups %xmm0, 0x1c(%rsp)
movaps %xmm0, 0x10(%rsp)
xorl %ecx, %ecx
cmpq %rcx, %rdx
je 0x9331
movzbl 0x2(%r14,%rcx,4), %edi
incw 0x30(%rsp,%rdi,2)
incq %rcx
jmp 0x931c
andw $0x0, 0x12(%rsp,%rsi,2)
xorl %ecx, %ecx
movq %rsi, %rdi
subq $0x1, %rdi
jb 0x9356
movw %cx, 0x10(%rsp,%rsi,2)
addw 0x30(%rsp,%rsi,2), %cx
movzwl %cx, %ecx
shrl %ecx
movq %rdi, %rsi
jmp 0x933c
xorl %ecx, %ecx
cmpq %rcx, %rdx
je 0x937e
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
jmp 0x9358
decl %edx
movl %edx, (%rbx)
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq