// File: /workspace/github_c_makefile_star2_O3/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 $0x8fd8, %rsp           # imm = 0x8FD8
movl %r9d, %ebp
movl %r8d, %r14d
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movl %r8d, 0x4(%rsp)
leaq 0x250(%rsp), %rdi
movl $0x47c, %edx            # imm = 0x47C
xorl %esi, %esi
callq 0x10c0
cmpq $0x2, %rbx
jae 0xa4d7
movq %rbx, %r13
jmp 0xa61b
movq %r13, 0x8(%rsp)
testl %r14d, %r14d
je 0xa500
testl %ebp, %ebp
movl $0xc, %eax
cmovel %eax, %ebp
movq $-0x6, %r13
cmpl $0x11e, %r14d           # imm = 0x11E
jbe 0xa50c
jmp 0xa61b
movl $0x11e, 0x4(%rsp)       # imm = 0x11E
testl %ebp, %ebp
je 0xa51d
movq $-0x5, %r13
cmpl $0xd, %ebp
jbe 0xa522
jmp 0xa61b
movl $0xc, %ebp
leaq 0x250(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xa0d6
cmpq $-0x9, %rax
ja 0xa618
movl $0x1, %r13d
cmpq %rbx, %rax
je 0xa61b
movl 0x4(%rsp), %r14d
movl %ebp, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x8fe3
movl %eax, %ebp
leaq 0x10(%rsp), %rdi
leaq 0x250(%rsp), %rdx
movl %eax, %esi
movq %rbx, %rcx
movl %r14d, %r8d
callq 0x9031
cmpq $-0x9, %rax
ja 0xa618
leaq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movl %r14d, %ecx
movl %ebp, %r8d
callq 0x8cd3
movq %rax, %r13
cmpq $-0x9, %rax
ja 0xa61b
leaq 0x6d0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x4fd0(%rsp), %r8
movl $0x4000, %r9d           # imm = 0x4000
movl %r14d, %edx
movl %ebp, %ecx
callq 0x9d6c
cmpq $-0x8, %rax
jae 0xa618
movq 0x8(%rsp), %rbp
movq %rbp, %r14
addq %r13, %r14
subq %r13, %r12
leaq 0x6d0(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xa169
addq %r14, %rax
subq %rbp, %rax
leaq -0x2(,%rbx,2), %rcx
xorl %r13d, %r13d
cmpq %rcx, %rax
cmovbq %rax, %r13
jmp 0xa61b
movq %rax, %r13
movq %r13, %rax
addq $0x8fd8, %rsp           # imm = 0x8FD8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq