// File: /workspace/github_c_makefile_star2_O1/Cyan4973[P]FiniteStateEntropy/programs/../lib/entropy_common.c
// Function: HUF_readStats
size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
                     U32* nbSymbolsPtr, U32* tableLogPtr,
                     const void* src, size_t srcSize)
{
    U32 weightTotal;
    const BYTE* ip = (const BYTE*) src;
    size_t iSize;
    size_t oSize;

    if (!srcSize) return ERROR(srcSize_wrong);
    iSize = ip[0];
    /* memset(huffWeight, 0, hwSize);   *//* is not necessary, even though some analyzer complain ... */

    if (iSize >= 128) {  /* special header */
        oSize = iSize - 127;
        iSize = ((oSize+1)/2);
        if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
        if (oSize >= hwSize) return ERROR(corruption_detected);
        ip += 1;
        {   U32 n;
            for (n=0; n<oSize; n+=2) {
                huffWeight[n]   = ip[n/2] >> 4;
                huffWeight[n+1] = ip[n/2] & 15;
    }   }   }
    else  {   /* header compressed with FSE (normal case) */
        FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)];  /* 6 is max possible tableLog for HUF header (maybe even 5, to be tested) */
        if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
        oSize = FSE_decompress_wksp(huffWeight, hwSize-1, ip+1, iSize, fseWorkspace, 6);   /* max (hwSize-1) values decoded, as last one is implied */
        if (FSE_isError(oSize)) return oSize;
    }

    /* collect weight stats */
    memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
    weightTotal = 0;
    {   U32 n; for (n=0; n<oSize; n++) {
            if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
            rankStats[huffWeight[n]]++;
            weightTotal += (1 << huffWeight[n]) >> 1;
    }   }
    if (weightTotal == 0) return ERROR(corruption_detected);

    /* get last non-null symbol weight (implied, total must be 2^n) */
    {   U32 const tableLog = BIT_highbit32(weightTotal) + 1;
        if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
        *tableLogPtr = tableLog;
        /* determine last weight */
        {   U32 const total = 1 << tableLog;
            U32 const rest = total - weightTotal;
            U32 const verif = 1 << BIT_highbit32(rest);
            U32 const lastWeight = BIT_highbit32(rest) + 1;
            if (verif != rest) return ERROR(corruption_detected);    /* last value must be a clean power of 2 */
            huffWeight[oSize] = (BYTE)lastWeight;
            rankStats[lastWeight]++;
    }   }

    /* check tree construction validity */
    if ((rankStats[1] < 2) || (rankStats[1] & 1)) return ERROR(corruption_detected);   /* by construction : at least 2 elts of rank 1, must be even */

    /* results */
    *nbSymbolsPtr = (U32)(oSize+1);
    return iSize+1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movq %rdx, %r15
movq 0x140(%rsp), %rdx
movq $-0x3, %rax
testq %rdx, %rdx
je 0x75f2
movq %r8, %r13
movq %rcx, %rbx
movq %rdi, %r12
movzbl (%r9), %r14d
testb %r14b, %r14b
js 0x747d
cmpq %rdx, %r14
jae 0x74d4
decq %rsi
incq %r9
movq %rsp, %r8
movq %r12, %rdi
movq %r9, %rdx
movq %r14, %rcx
movl $0x6, %r9d
callq 0x8432
movq %rax, %rdx
cmpq $-0x8, %rax
setb %cl
jmp 0x74d6
leaq -0x7e(%r14), %rcx
shrq %rcx
cmpq %rdx, %rcx
jae 0x75f2
addq $-0x7f, %r14
movq $-0x4, %rax
cmpq %rsi, %r14
jae 0x75f2
testq %r14, %r14
je 0x74cc
incq %r9
xorl %eax, %eax
movb (%r9), %dl
shrb $0x4, %dl
movb %dl, (%r12,%rax)
movb (%r9), %dl
andb $0xf, %dl
movb %dl, 0x1(%r12,%rax)
addq $0x2, %rax
incq %r9
cmpl %eax, %r14d
ja 0x74ab
movq %r14, %rdx
movq %rcx, %r14
jmp 0x74de
xorl %ecx, %ecx
testb %cl, %cl
je 0x75f2
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r15)
movups %xmm0, 0x10(%r15)
movups %xmm0, (%r15)
movl $0x0, 0x30(%r15)
xorl %esi, %esi
testq %rdx, %rdx
setne %cl
je 0x7550
movb (%r12), %r8b
cmpb $0xb, %r8b
ja 0x7549
xorl %esi, %esi
movl $0x1, %edi
movq %r12, %r9
movzbl %r8b, %ecx
incl (%r15,%rcx,4)
movl %esi, %r8d
movb (%r9), %cl
movl $0x1, %esi
shll %cl, %esi
sarl %esi
addl %r8d, %esi
movl %edi, %edi
cmpq %rdi, %rdx
seta %cl
jbe 0x7550
leaq (%r12,%rdi), %r9
movb (%r12,%rdi), %r8b
incl %edi
cmpb $0xb, %r8b
jbe 0x7515
movq $-0x4, %rax
testb %cl, %cl
jne 0x75f2
testl %esi, %esi
je 0x756f
bsrl %esi, %ecx
movq $-0x4, %rdi
cmpl $0xb, %ecx
jbe 0x7578
xorl %esi, %esi
jmp 0x75c6
movq $-0x4, %rax
jmp 0x75f2
movl %ecx, %r8d
xorl $0x1f, %r8d
movl $0x20, %r9d
movl $0x2, %r10d
shll %cl, %r10d
subl %r8d, %r9d
subl %esi, %r10d
bsrl %r10d, %ecx
movl $0x1, %esi
shll %cl, %esi
movl $0x20, %r8d
movl %r9d, (%r13)
cmpl %r10d, %esi
sete %sil
jne 0x75c6
xorl $0x1f, %ecx
subl %ecx, %r8d
movb %r8b, (%r12,%rdx)
incl (%r15,%r8,4)
movb $0x1, %sil
movq %rax, %rdi
movq %rdi, %rax
testb %sil, %sil
je 0x75f2
movl 0x4(%r15), %ecx
cmpl $0x2, %ecx
setb %sil
movq $-0x4, %rax
orb %sil, %cl
testb $0x1, %cl
jne 0x75f2
incl %edx
movl %edx, (%rbx)
incq %r14
movq %r14, %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop