// File: /workspace/github_c_makefile_star2_O0/Cyan4973[P]FiniteStateEntropy/programs/../lib/entropy_common.c
// Function: FSE_readNCount
size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
                 const void* headerBuffer, size_t hbSize)
{
    const BYTE* const istart = (const BYTE*) headerBuffer;
    const BYTE* const iend = istart + hbSize;
    const BYTE* ip = istart;
    int nbBits;
    int remaining;
    int threshold;
    U32 bitStream;
    int bitCount;
    unsigned charnum = 0;
    int previous0 = 0;

    if (hbSize < 4) {
        /* This function only works when hbSize >= 4 */
        char buffer[4] = {0};
        memcpy(buffer, headerBuffer, hbSize);
        {   size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr,
                                                    buffer, sizeof(buffer));
            if (FSE_isError(countSize)) return countSize;
            if (countSize > hbSize) return ERROR(corruption_detected);
            return countSize;
    }   }
    assert(hbSize >= 4);

    /* init */
    memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0]));   /* all symbols not present in NCount have a frequency of 0 */
    bitStream = MEM_readLE32(ip);
    nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG;   /* extract tableLog */
    if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
    bitStream >>= 4;
    bitCount = 4;
    *tableLogPtr = nbBits;
    remaining = (1<<nbBits)+1;
    threshold = 1<<nbBits;
    nbBits++;

    while ((remaining>1) & (charnum<=*maxSVPtr)) {
        if (previous0) {
            unsigned n0 = charnum;
            while ((bitStream & 0xFFFF) == 0xFFFF) {
                n0 += 24;
                if (ip < iend-5) {
                    ip += 2;
                    bitStream = MEM_readLE32(ip) >> bitCount;
                } else {
                    bitStream >>= 16;
                    bitCount   += 16;
            }   }
            while ((bitStream & 3) == 3) {
                n0 += 3;
                bitStream >>= 2;
                bitCount += 2;
            }
            n0 += bitStream & 3;
            bitCount += 2;
            if (n0 > *maxSVPtr) return ERROR(maxSymbolValue_tooSmall);
            while (charnum < n0) normalizedCounter[charnum++] = 0;
            if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
                assert((bitCount >> 3) <= 3); /* For first condition to work */
                ip += bitCount>>3;
                bitCount &= 7;
                bitStream = MEM_readLE32(ip) >> bitCount;
            } else {
                bitStream >>= 2;
        }   }
        {   int const max = (2*threshold-1) - remaining;
            int count;

            if ((bitStream & (threshold-1)) < (U32)max) {
                count = bitStream & (threshold-1);
                bitCount += nbBits-1;
            } else {
                count = bitStream & (2*threshold-1);
                if (count >= threshold) count -= max;
                bitCount += nbBits;
            }

            count--;   /* extra accuracy */
            remaining -= count < 0 ? -count : count;   /* -1 means +1 */
            normalizedCounter[charnum++] = (short)count;
            previous0 = !count;
            while (remaining < threshold) {
                nbBits--;
                threshold >>= 1;
            }

            if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
                ip += bitCount>>3;
                bitCount &= 7;
            } else {
                bitCount -= (int)(8 * (iend - 4 - ip));
                ip = iend - 4;
            }
            bitStream = MEM_readLE32(ip) >> (bitCount & 31);
    }   }   /* while ((remaining>1) & (charnum<=*maxSVPtr)) */
    if (remaining != 1) return ERROR(corruption_detected);
    if (bitCount > 32) return ERROR(corruption_detected);
    *maxSVPtr = charnum-1;

    ip += (bitCount+7)>>3;
    return ip-istart;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
cmpq $0x4, -0x30(%rbp)
jae 0xe52f
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x10c0
leaq -0x68(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x1120
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x68(%rbp), %rcx
movl $0x4, %r8d
callq 0xe460
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0xe390
cmpl $0x0, %eax
je 0xe50b
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xe8e4
movq -0x70(%rbp), %rax
cmpq -0x30(%rbp), %rax
jbe 0xe522
movq $-0x4, -0x8(%rbp)
jmp 0xe8e4
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xe8e4
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
shlq %rdx
xorl %esi, %esi
callq 0x10c0
movq -0x48(%rbp), %rdi
callq 0xe900
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
andl $0xf, %eax
addl $0x5, %eax
movl %eax, -0x4c(%rbp)
cmpl $0xf, -0x4c(%rbp)
jle 0xe575
movq $-0x5, -0x8(%rbp)
jmp 0xe8e4
movl -0x58(%rbp), %eax
shrl $0x4, %eax
movl %eax, -0x58(%rbp)
movl $0x4, -0x5c(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x4c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x54(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x1, -0x50(%rbp)
setg %al
andb $0x1, %al
movzbl %al, %eax
movl -0x60(%rbp), %ecx
movq -0x18(%rbp), %rdx
cmpl (%rdx), %ecx
setbe %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xe892
cmpl $0x0, -0x64(%rbp)
je 0xe72c
movl -0x60(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x58(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0xe649
movl -0x74(%rbp), %eax
addl $0x18, %eax
movl %eax, -0x74(%rbp)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
addq $-0x5, %rcx
cmpq %rcx, %rax
jae 0xe635
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0xe900
movl -0x5c(%rbp), %ecx
shrl %cl, %eax
movl %eax, -0x58(%rbp)
jmp 0xe647
movl -0x58(%rbp), %eax
shrl $0x10, %eax
movl %eax, -0x58(%rbp)
movl -0x5c(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x5c(%rbp)
jmp 0xe5ed
jmp 0xe64b
movl -0x58(%rbp), %eax
andl $0x3, %eax
cmpl $0x3, %eax
jne 0xe673
movl -0x74(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x74(%rbp)
movl -0x58(%rbp), %eax
shrl $0x2, %eax
movl %eax, -0x58(%rbp)
movl -0x5c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x5c(%rbp)
jmp 0xe64b
movl -0x58(%rbp), %eax
andl $0x3, %eax
addl -0x74(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x5c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x5c(%rbp)
movl -0x74(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0xe6a0
movq $-0x7, -0x8(%rbp)
jmp 0xe8e4
jmp 0xe6a2
movl -0x60(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0xe6c3
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x60(%rbp)
movl %ecx, %ecx
movw $0x0, (%rax,%rcx,2)
jmp 0xe6a2
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
addq $-0x7, %rcx
cmpq %rcx, %rax
jbe 0xe6f1
movq -0x48(%rbp), %rax
movl -0x5c(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
ja 0xe721
movl -0x5c(%rbp), %ecx
sarl $0x3, %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x5c(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x5c(%rbp)
movq -0x48(%rbp), %rdi
callq 0xe900
movl -0x5c(%rbp), %ecx
shrl %cl, %eax
movl %eax, -0x58(%rbp)
jmp 0xe72a
movl -0x58(%rbp), %eax
shrl $0x2, %eax
movl %eax, -0x58(%rbp)
jmp 0xe72c
movl -0x54(%rbp), %eax
shll %eax
subl $0x1, %eax
subl -0x50(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x58(%rbp), %eax
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl -0x78(%rbp), %eax
jae 0xe766
movl -0x58(%rbp), %eax
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x7c(%rbp)
movl -0x4c(%rbp), %eax
subl $0x1, %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0xe792
movl -0x58(%rbp), %eax
movl -0x54(%rbp), %ecx
shll %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x54(%rbp), %eax
jl 0xe789
movl -0x78(%rbp), %ecx
movl -0x7c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x7c(%rbp)
movl -0x4c(%rbp), %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x7c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
jge 0xe7ab
xorl %eax, %eax
subl -0x7c(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0xe7b1
movl -0x7c(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %ecx
movl -0x50(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x50(%rbp)
movl -0x7c(%rbp), %eax
movw %ax, %dx
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x60(%rbp)
movl %ecx, %ecx
movw %dx, (%rax,%rcx,2)
cmpl $0x0, -0x7c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x64(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0xe803
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x54(%rbp), %eax
sarl %eax
movl %eax, -0x54(%rbp)
jmp 0xe7e8
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
addq $-0x7, %rcx
cmpq %rcx, %rax
jbe 0xe831
movq -0x48(%rbp), %rax
movl -0x5c(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
addq $-0x4, %rcx
cmpq %rcx, %rax
ja 0xe850
movl -0x5c(%rbp), %ecx
sarl $0x3, %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x5c(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x5c(%rbp)
jmp 0xe879
movq -0x40(%rbp), %rax
addq $-0x4, %rax
movq -0x48(%rbp), %rcx
subq %rcx, %rax
shlq $0x3, %rax
movl %eax, %ecx
movl -0x5c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x5c(%rbp)
movq -0x40(%rbp), %rax
addq $-0x4, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0xe900
movl -0x5c(%rbp), %ecx
andl $0x1f, %ecx
shrl %cl, %eax
movl %eax, -0x58(%rbp)
jmp 0xe5b4
cmpl $0x1, -0x50(%rbp)
je 0xe8a2
movq $-0x4, -0x8(%rbp)
jmp 0xe8e4
cmpl $0x20, -0x5c(%rbp)
jle 0xe8b2
movq $-0x4, -0x8(%rbp)
jmp 0xe8e4
movl -0x60(%rbp), %ecx
subl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x5c(%rbp), %ecx
addl $0x7, %ecx
sarl $0x3, %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)