// File: /workspace/github_c_makefile_star2_O2/Cyan4973[P]FiniteStateEntropy/programs/../lib/fseU16.c
// Function: FSE_compressU16
size_t FSE_compressU16(void* dst, size_t maxDstSize,
       const unsigned short* src, size_t srcSize,
       unsigned maxSymbolValue, unsigned tableLog)
{
    const U16* const istart = src;
    const U16* ip = istart;

    BYTE* const ostart = (BYTE*) dst;
    BYTE* const omax = ostart + maxDstSize;
    BYTE* op = ostart;

    U32   counting[FSE_MAX_SYMBOL_VALUE+1] = {0};
    S16   norm[FSE_MAX_SYMBOL_VALUE+1];

    /* checks */
    if (srcSize <= 1) return srcSize;
    if (!maxSymbolValue) maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
    if (!tableLog) tableLog = FSE_DEFAULT_TABLELOG;
    if (maxSymbolValue > FSE_MAX_SYMBOL_VALUE) return ERROR(maxSymbolValue_tooLarge);
    if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);

    /* Scan for stats */
    {   size_t const maxCount = FSE_countU16 (counting, &maxSymbolValue, ip, srcSize);
        if (FSE_isError(maxCount)) return maxCount;
        if (maxCount == srcSize) return 1;   /* src contains one constant element x srcSize times. Use RLE compression. */
    }
    /* Normalize */
    tableLog = FSE_optimalTableLog(tableLog, srcSize, maxSymbolValue);
    {   size_t const errorCode = FSE_normalizeCount (norm, tableLog, counting, srcSize, maxSymbolValue);
        if (FSE_isError(errorCode)) return errorCode;
    }
    /* Write table description header */
    {   size_t const NSize = FSE_writeNCount (op, omax-op, norm, maxSymbolValue, tableLog);
        if (FSE_isError(NSize)) return NSize;
        op += NSize;
    }
    /* Compress */
    {   FSE_CTable CTable[FSE_CTABLE_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)];
        size_t const errorCode = FSE_buildCTableU16 (CTable, norm, maxSymbolValue, tableLog);
        if (FSE_isError(errorCode)) return errorCode;
        op += FSE_compressU16_usingCTable (op, omax - op, ip, srcSize, CTable);
    }

    /* check compressibility */
    if ( (size_t)(op-ostart) >= (size_t)(srcSize-1)*(sizeof(U16)) )
        return 0;   /* no compression */

    return op-ostart;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4fd8, %rsp           # imm = 0x4FD8
movl %r9d, %ebp
movl %r8d, %r13d
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movl %r8d, 0x4(%rsp)
leaq 0x250(%rsp), %rdi
movl $0x47c, %edx            # imm = 0x47C
xorl %esi, %esi
callq 0x10c0
cmpq $0x2, %rbx
jb 0x8c95
testl %r13d, %r13d
je 0x8b9b
testl %ebp, %ebp
pushq $0xc
popq %rax
cmovel %eax, %ebp
cmpl $0x11e, %r13d           # imm = 0x11E
jbe 0x8ba7
pushq $-0x6
jmp 0x8bdc
movl $0x11e, 0x4(%rsp)       # imm = 0x11E
testl %ebp, %ebp
je 0x8bb0
cmpl $0xd, %ebp
jbe 0x8bb3
pushq $-0x5
jmp 0x8bdc
pushq $0xc
popq %rbp
leaq 0x250(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x8811
cmpq $-0x9, %rax
ja 0x8c92
cmpq %rbx, %rax
jne 0x8be2
pushq $0x1
popq %rbx
jmp 0x8c95
movl 0x4(%rsp), %r13d
movl %ebp, %edi
movq %rbx, %rsi
movl %r13d, %edx
callq 0x7b47
movl %eax, %ebp
leaq 0x10(%rsp), %rdi
leaq 0x250(%rsp), %rdx
movl %eax, %esi
movq %rbx, %rcx
movl %r13d, %r8d
callq 0x7b4f
cmpq $-0x9, %rax
ja 0x8c92
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
movl %r13d, %ecx
movl %ebp, %r8d
callq 0x788a
cmpq $-0x9, %rax
ja 0x8c92
movq %rax, 0x8(%rsp)
leaq 0x6d0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl %r13d, %edx
movl %ebp, %ecx
callq 0x865a
cmpq $-0x8, %rax
jae 0x8c92
movq 0x8(%rsp), %rax
leaq (%r14,%rax), %r13
subq %rax, %r12
leaq 0x6d0(%rsp), %r8
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x8897
addq %r13, %rax
subq %r14, %rax
leaq -0x2(,%rbx,2), %rcx
xorl %ebx, %ebx
cmpq %rcx, %rax
cmovbq %rax, %rbx
jmp 0x8c95
movq %rax, %rbx
movq %rbx, %rax
addq $0x4fd8, %rsp           # imm = 0x4FD8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq