// File: /workspace/github_c_makefile_star2_O3/Cyan4973[P]FiniteStateEntropy/programs/../lib/fse_compress.c
// Function: FSE_compress_wksp
size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
{
    BYTE* const ostart = (BYTE*) dst;
    BYTE* op = ostart;
    BYTE* const oend = ostart + dstSize;

    unsigned count[FSE_MAX_SYMBOL_VALUE+1];
    S16   norm[FSE_MAX_SYMBOL_VALUE+1];
    FSE_CTable* CTable = (FSE_CTable*)workSpace;
    size_t const CTableSize = FSE_CTABLE_SIZE_U32(tableLog, maxSymbolValue);
    void* scratchBuffer = (void*)(CTable + CTableSize);
    size_t const scratchBufferSize = wkspSize - (CTableSize * sizeof(FSE_CTable));

    /* init conditions */
    if (wkspSize < FSE_WKSP_SIZE_U32(tableLog, maxSymbolValue)) return ERROR(tableLog_tooLarge);
    if (srcSize <= 1) return 0;  /* Not compressible */
    if (!maxSymbolValue) maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
    if (!tableLog) tableLog = FSE_DEFAULT_TABLELOG;

    /* Scan input and build symbol stats */
    {   CHECK_V_F(maxCount, HIST_count_wksp(count, &maxSymbolValue, src, srcSize, scratchBuffer, scratchBufferSize) );
        if (maxCount == srcSize) return 1;   /* only a single symbol in src : rle */
        if (maxCount == 1) return 0;         /* each symbol present maximum once => not compressible */
        if (maxCount < (srcSize >> 7)) return 0;   /* Heuristic : not compressible enough */
    }

    tableLog = FSE_optimalTableLog(tableLog, srcSize, maxSymbolValue);
    CHECK_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue) );

    /* Write table description header */
    {   CHECK_V_F(nc_err, FSE_writeNCount(op, oend-op, norm, maxSymbolValue, tableLog) );
        op += nc_err;
    }

    /* Compress */
    CHECK_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, scratchBufferSize) );
    {   CHECK_V_F(cSize, FSE_compress_usingCTable(op, oend - op, src, srcSize, CTable) );
        if (cSize == 0) return 0;   /* not enough space for compressed data */
        op += cSize;
    }

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

    return op-ostart;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x628, %rsp            # imm = 0x628
movq %rcx, %rbx
movq %rdx, %r15
movq 0x668(%rsp), %r13
movl %r8d, 0x4(%rsp)
leal -0x1(%r9), %ecx
movl $0x1, %edx
movl $0x1, %eax
shll %cl, %eax
leal -0x2(%r9), %ecx
shll %cl, %edx
cmpl $0xd, %r9d
movl $0x400, %ecx            # imm = 0x400
cmovael %edx, %ecx
leal (%rax,%r8,2), %edx
addl %edx, %ecx
addl $0x3, %ecx
movq $-0x5, %rbp
cmpq %r13, %rcx
ja 0x9cff
cmpq $0x2, %rbx
jae 0x9b47
xorl %ebp, %ebp
jmp 0x9cff
movq %rsi, %r12
movq %rdi, 0x8(%rsp)
movq 0x660(%rsp), %rcx
leal (%rax,%r8,2), %eax
addl $0x3, %eax
leaq (%rcx,%rax,4), %rbp
shlq $0x2, %rax
subq %rax, %r13
testl %r8d, %r8d
jne 0x9b76
movl $0xff, 0x4(%rsp)
testl %r9d, %r9d
movl $0xb, %r14d
cmovnel %r9d, %r14d
leaq 0x220(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq %r13, %r9
callq 0x7f84
cmpq $-0x9, %rax
ja 0x9cfc
movq %rbp, 0x18(%rsp)
movl $0x1, %ebp
cmpq %rbx, %rax
je 0x9cff
cmpq $0x1, %rax
sete %cl
movq %rbx, %rdx
shrq $0x7, %rdx
cmpq %rdx, %rax
setb %al
orb %cl, %al
jne 0x9b40
movq %rdx, 0x10(%rsp)
movl 0x4(%rsp), %r8d
leal -0x1(%rbx), %eax
bsrl %eax, %eax
xorl $-0x20, %eax
addl $0x1e, %eax
bsrl %ebx, %ecx
xorl $-0x20, %ecx
addl $0x21, %ecx
bsrl %r8d, %edx
xorl $-0x20, %edx
addl $0x22, %edx
cmpl %edx, %ecx
cmovbl %ecx, %edx
cmpl %r14d, %eax
cmovael %r14d, %eax
cmpl %eax, %edx
cmoval %edx, %eax
cmpl $0x6, %eax
movl $0x5, %ecx
cmovael %eax, %ecx
cmpl $0xc, %ecx
movl $0xc, %r14d
cmovbl %ecx, %r14d
leaq 0x20(%rsp), %rdi
leaq 0x220(%rsp), %rdx
movl %r14d, %esi
movq %rbx, %rcx
callq 0x9031
cmpq $-0x9, %rax
ja 0x9cfc
movl 0x4(%rsp), %ecx
leaq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movl %r14d, %r8d
callq 0x8cd3
movq %rax, %rbp
cmpq $-0x9, %rax
ja 0x9cff
movl 0x4(%rsp), %edx
leaq 0x20(%rsp), %rsi
movl %r14d, %ecx
movq 0x660(%rsp), %r14
movq %r14, %rdi
movq 0x18(%rsp), %r8
movq %r13, %r9
callq 0x8af8
cmpq $-0x9, %rax
ja 0x9cfc
movq 0x8(%rsp), %rax
leaq (%rax,%rbp), %r13
subq %rbp, %r12
movq 0x10(%rsp), %rax
addq %rbx, %rax
addq $0xc, %rax
xorl %r9d, %r9d
cmpq %r12, %rax
setbe %r9b
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r14, %r8
callq 0x96b4
movq %rax, %rbp
cmpq $-0x9, %rax
ja 0x9cff
testq %rbp, %rbp
je 0x9b40
addq %rbp, %r13
subq 0x8(%rsp), %r13
decq %rbx
xorl %ebp, %ebp
cmpq %rbx, %r13
cmovbq %r13, %rbp
jmp 0x9cff
movq %rax, %rbp
movq %rbp, %rax
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq