// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, 0x10(%rbp)
jne 0xe983
movq $-0x3, -0x8(%rbp)
jmp 0xec62
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
movq %rax, -0x50(%rbp)
cmpq $0x80, -0x50(%rbp)
jb 0xea53
movq -0x50(%rbp), %rax
subq $0x7f, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
shrq %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
cmpq 0x10(%rbp), %rax
jbe 0xe9d2
movq $-0x3, -0x8(%rbp)
jmp 0xec62
movq -0x58(%rbp), %rax
cmpq -0x18(%rbp), %rax
jb 0xe9e9
movq $-0x4, -0x8(%rbp)
jmp 0xec62
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpq -0x58(%rbp), %rax
jae 0xea51
movq -0x48(%rbp), %rax
movl -0x5c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
sarl $0x4, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x5c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movq -0x48(%rbp), %rax
movl -0x5c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
andl $0xf, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movl -0x5c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x5c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x5c(%rbp)
jmp 0xe9fc
jmp 0xeab9
movq -0x50(%rbp), %rax
addq $0x1, %rax
cmpq 0x10(%rbp), %rax
jbe 0xea6e
movq $-0x3, -0x8(%rbp)
jmp 0xec62
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
movq -0x48(%rbp), %rdx
addq $0x1, %rdx
movq -0x50(%rbp), %rcx
leaq -0x160(%rbp), %r8
movl $0x6, %r9d
callq 0x103b0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0xe390
cmpl $0x0, %eax
je 0xeab7
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xec62
jmp 0xeab9
movq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x34, %edx
callq 0x10c0
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x164(%rbp)
movl -0x164(%rbp), %eax
cmpq -0x58(%rbp), %rax
jae 0xeb4f
movq -0x10(%rbp), %rax
movl -0x164(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0xc, %eax
jl 0xeb06
movq $-0x4, -0x8(%rbp)
jmp 0xec62
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movl -0x164(%rbp), %edx
movzbl (%rcx,%rdx), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl -0x164(%rbp), %ecx
movzbl (%rax,%rcx), %ecx
movl $0x1, %eax
shll %cl, %eax
sarl %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0xeada
cmpl $0x0, -0x3c(%rbp)
jne 0xeb62
movq $-0x4, -0x8(%rbp)
jmp 0xec62
movl -0x3c(%rbp), %edi
callq 0xec70
addl $0x1, %eax
movl %eax, -0x168(%rbp)
cmpl $0xc, -0x168(%rbp)
jbe 0xeb89
movq $-0x4, -0x8(%rbp)
jmp 0xec62
movl -0x168(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl -0x168(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x16c(%rbp)
movl -0x16c(%rbp), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x170(%rbp)
movl -0x170(%rbp), %edi
callq 0xec70
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x174(%rbp)
movl -0x170(%rbp), %edi
callq 0xec70
addl $0x1, %eax
movl %eax, -0x178(%rbp)
movl -0x174(%rbp), %eax
cmpl -0x170(%rbp), %eax
je 0xebfd
movq $-0x4, -0x8(%rbp)
jmp 0xec62
movl -0x178(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x178(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x20(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jb 0xec3c
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xec46
movq $-0x4, -0x8(%rbp)
jmp 0xec62
movq -0x58(%rbp), %rax
addq $0x1, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
nop