// File: /workspace/github_c_makefile_star2_O1/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 $0x8fe8, %rsp           # imm = 0x8FE8
movl %r9d, %r13d
movl %r8d, %ebp
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movl %r8d, 0x4(%rsp)
leaq 0x260(%rsp), %rdi
movl $0x47c, %edx            # imm = 0x47C
xorl %esi, %esi
callq 0x10c0
cmpq $0x2, %rbx
jae 0x9cd4
movq %rbx, %r13
jmp 0x9e48
testl %ebp, %ebp
jne 0x9ce0
movl $0x11e, 0x4(%rsp)       # imm = 0x11E
testl %r13d, %r13d
movl $0xc, %ebp
cmovnel %r13d, %ebp
movq $-0x6, %r13
cmpl $0x11e, 0x4(%rsp)       # imm = 0x11E
ja 0x9e48
movq $-0x5, %r13
cmpl $0xd, %ebp
ja 0x9e48
leaq 0x260(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x98cf
cmpq %rbx, %rax
sete %cl
cmpq $-0x8, %rax
setae %dl
movl $0x1, %r13d
cmovaeq %rax, %r13
orb %cl, %dl
jne 0x9e48
movq %r14, 0x18(%rsp)
movl 0x4(%rsp), %r14d
movl %ebp, %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x8a1e
movl %eax, %ebp
leaq 0x20(%rsp), %rdi
leaq 0x260(%rsp), %rdx
movl %eax, %esi
movq %rbx, %rcx
movl %r14d, 0x8(%rsp)
movl %r14d, %r8d
callq 0x8a6c
cmpq $-0x8, %rax
cmovaeq %rax, %r13
jae 0x9e48
leaq 0x20(%rsp), %rdx
movq 0x18(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movl 0x8(%rsp), %ecx
movl %ebp, 0xc(%rsp)
movl %ebp, %r8d
callq 0x86d4
xorl %ebp, %ebp
cmpq $-0x8, %rax
cmovbq %rax, %rbp
cmovaeq %rax, %r13
jae 0x9e48
leaq (%r14,%rbp), %rax
movq %rax, 0x10(%rsp)
leaq 0x6e0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x4fe0(%rsp), %r8
movl $0x4000, %r9d           # imm = 0x4000
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
callq 0x9554
cmpq $-0x9, %rax
ja 0x9e25
subq %rbp, %r12
leaq 0x6e0(%rsp), %r8
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r15
callq 0x9962
addq %rax, %rbp
movq %r15, %rax
jmp 0x9e2d
movq %rax, %r13
movq 0x10(%rsp), %rbp
cmpq $-0x9, %rax
ja 0x9e48
subq %r14, %rbp
leaq -0x2(,%rbx,2), %rax
xorl %r13d, %r13d
cmpq %rax, %rbp
cmovbq %rbp, %r13
movq %r13, %rax
addq $0x8fe8, %rsp           # imm = 0x8FE8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq