// File: /workspace/github_c_makefile_star2_O0/Cyan4973[P]FiniteStateEntropy/programs/../lib/fse_compress.c
// Function: FSE_writeNCount_generic
static size_t
FSE_writeNCount_generic (void* header, size_t headerBufferSize,
                   const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog,
                         unsigned writeIsSafe)
{
    BYTE* const ostart = (BYTE*) header;
    BYTE* out = ostart;
    BYTE* const oend = ostart + headerBufferSize;
    int nbBits;
    const int tableSize = 1 << tableLog;
    int remaining;
    int threshold;
    U32 bitStream = 0;
    int bitCount = 0;
    unsigned symbol = 0;
    unsigned const alphabetSize = maxSymbolValue + 1;
    int previousIs0 = 0;

    /* Table Size */
    bitStream += (tableLog-FSE_MIN_TABLELOG) << bitCount;
    bitCount  += 4;

    /* Init */
    remaining = tableSize+1;   /* +1 for extra accuracy */
    threshold = tableSize;
    nbBits = tableLog+1;

    while ((symbol < alphabetSize) && (remaining>1)) {  /* stops at 1 */
        if (previousIs0) {
            unsigned start = symbol;
            while ((symbol < alphabetSize) && !normalizedCounter[symbol]) symbol++;
            if (symbol == alphabetSize) break;   /* incorrect distribution */
            while (symbol >= start+24) {
                start+=24;
                bitStream += 0xFFFFU << bitCount;
                if ((!writeIsSafe) && (out > oend-2))
                    return ERROR(dstSize_tooSmall);   /* Buffer overflow */
                out[0] = (BYTE) bitStream;
                out[1] = (BYTE)(bitStream>>8);
                out+=2;
                bitStream>>=16;
            }
            while (symbol >= start+3) {
                start+=3;
                bitStream += 3 << bitCount;
                bitCount += 2;
            }
            bitStream += (symbol-start) << bitCount;
            bitCount += 2;
            if (bitCount>16) {
                if ((!writeIsSafe) && (out > oend - 2))
                    return ERROR(dstSize_tooSmall);   /* Buffer overflow */
                out[0] = (BYTE)bitStream;
                out[1] = (BYTE)(bitStream>>8);
                out += 2;
                bitStream >>= 16;
                bitCount -= 16;
        }   }
        {   int count = normalizedCounter[symbol++];
            int const max = (2*threshold-1) - remaining;
            remaining -= count < 0 ? -count : count;
            count++;   /* +1 for extra accuracy */
            if (count>=threshold)
                count += max;   /* [0..max[ [max..threshold[ (...) [threshold+max 2*threshold[ */
            bitStream += count << bitCount;
            bitCount  += nbBits;
            bitCount  -= (count<max);
            previousIs0  = (count==1);
            if (remaining<1) return ERROR(GENERIC);
            while (remaining<threshold) { nbBits--; threshold>>=1; }
        }
        if (bitCount>16) {
            if ((!writeIsSafe) && (out > oend - 2))
                return ERROR(dstSize_tooSmall);   /* Buffer overflow */
            out[0] = (BYTE)bitStream;
            out[1] = (BYTE)(bitStream>>8);
            out += 2;
            bitStream >>= 16;
            bitCount -= 16;
    }   }

    if (remaining != 1)
        return ERROR(GENERIC);  /* incorrect normalized distribution */
    assert(symbol <= alphabetSize);

    /* flush remaining bitStream */
    if ((!writeIsSafe) && (out > oend - 2))
        return ERROR(dstSize_tooSmall);   /* Buffer overflow */
    out[0] = (BYTE)bitStream;
    out[1] = (BYTE)(bitStream>>8);
    out+= (bitCount+7) /8;

    return (out-ostart);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x28(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x50(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x28(%rbp), %eax
subl $0x5, %eax
movl -0x60(%rbp), %ecx
shll %cl, %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x60(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x60(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x64(%rbp), %ecx
xorl %eax, %eax
cmpl -0x68(%rbp), %ecx
movb %al, -0x79(%rbp)
jae 0x11422
cmpl $0x1, -0x54(%rbp)
setg %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x1142e
jmp 0x116e2
cmpl $0x0, -0x6c(%rbp)
je 0x115ae
movl -0x64(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x64(%rbp), %ecx
xorl %eax, %eax
cmpl -0x68(%rbp), %ecx
movb %al, -0x7a(%rbp)
jae 0x1145f
movq -0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
cmpw $0x0, (%rax,%rcx,2)
setne %al
xorb $-0x1, %al
movb %al, -0x7a(%rbp)
movb -0x7a(%rbp), %al
testb $0x1, %al
jne 0x11468
jmp 0x11473
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x1143e
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
jne 0x11480
jmp 0x116e2
jmp 0x11482
movl -0x64(%rbp), %eax
movl -0x70(%rbp), %ecx
addl $0x18, %ecx
cmpl %ecx, %eax
jb 0x114fd
movl -0x70(%rbp), %eax
addl $0x18, %eax
movl %eax, -0x70(%rbp)
movl -0x60(%rbp), %ecx
movl $0xffff, %eax           # imm = 0xFFFF
shll %cl, %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x114cc
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
addq $-0x2, %rcx
cmpq %rcx, %rax
jbe 0x114cc
movq $-0x2, -0x8(%rbp)
jmp 0x1175a
movl -0x5c(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movl -0x5c(%rbp), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movl -0x5c(%rbp), %eax
shrl $0x10, %eax
movl %eax, -0x5c(%rbp)
jmp 0x11482
jmp 0x114ff
movl -0x64(%rbp), %eax
movl -0x70(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jb 0x11530
movl -0x70(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x70(%rbp)
movl -0x60(%rbp), %ecx
movl $0x3, %eax
shll %cl, %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x60(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x60(%rbp)
jmp 0x114ff
movl -0x64(%rbp), %eax
subl -0x70(%rbp), %eax
movl -0x60(%rbp), %ecx
shll %cl, %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x60(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x60(%rbp)
cmpl $0x10, -0x60(%rbp)
jle 0x115ac
cmpl $0x0, -0x2c(%rbp)
jne 0x11574
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
addq $-0x2, %rcx
cmpq %rcx, %rax
jbe 0x11574
movq $-0x2, -0x8(%rbp)
jmp 0x1175a
movl -0x5c(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movl -0x5c(%rbp), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movl -0x5c(%rbp), %eax
shrl $0x10, %eax
movl %eax, -0x5c(%rbp)
movl -0x60(%rbp), %eax
subl $0x10, %eax
movl %eax, -0x60(%rbp)
jmp 0x115ae
movq -0x20(%rbp), %rax
movl -0x64(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x64(%rbp)
movl %ecx, %ecx
movswl (%rax,%rcx,2), %eax
movl %eax, -0x74(%rbp)
movl -0x58(%rbp), %eax
shll %eax
subl $0x1, %eax
subl -0x54(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x74(%rbp)
jge 0x115e4
xorl %eax, %eax
subl -0x74(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x115ea
movl -0x74(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %ecx
movl -0x54(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x58(%rbp), %eax
jl 0x1160f
movl -0x78(%rbp), %eax
addl -0x74(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl -0x60(%rbp), %ecx
shll %cl, %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x4c(%rbp), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x78(%rbp), %eax
setl %al
andb $0x1, %al
movzbl %al, %ecx
movl -0x60(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x60(%rbp)
cmpl $0x1, -0x74(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x6c(%rbp)
cmpl $0x1, -0x54(%rbp)
jge 0x1165e
movq $-0x1, -0x8(%rbp)
jmp 0x1175a
jmp 0x11660
movl -0x54(%rbp), %eax
cmpl -0x58(%rbp), %eax
jge 0x1167b
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x58(%rbp), %eax
sarl %eax
movl %eax, -0x58(%rbp)
jmp 0x11660
cmpl $0x10, -0x60(%rbp)
jle 0x116dd
cmpl $0x0, -0x2c(%rbp)
jne 0x116a5
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
addq $-0x2, %rcx
cmpq %rcx, %rax
jbe 0x116a5
movq $-0x2, -0x8(%rbp)
jmp 0x1175a
movl -0x5c(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movl -0x5c(%rbp), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movl -0x5c(%rbp), %eax
shrl $0x10, %eax
movl %eax, -0x5c(%rbp)
movl -0x60(%rbp), %eax
subl $0x10, %eax
movl %eax, -0x60(%rbp)
jmp 0x1140b
cmpl $0x1, -0x54(%rbp)
je 0x116f2
movq $-0x1, -0x8(%rbp)
jmp 0x1175a
cmpl $0x0, -0x2c(%rbp)
jne 0x11713
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
addq $-0x2, %rcx
cmpq %rcx, %rax
jbe 0x11713
movq $-0x2, -0x8(%rbp)
jmp 0x1175a
movl -0x5c(%rbp), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movl -0x5c(%rbp), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x60(%rbp), %eax
addl $0x7, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq