// File: /workspace/github_c_makefile_star2_O2/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 %rsi, %r12
movq 0x668(%rsp), %r13
leal -0x1(%r9), %ecx
pushq $0x1
popq %rdx
movl %edx, %eax
shll %cl, %eax
leal -0x2(%r9), %ecx
shll %cl, %edx
movl %r8d, 0xc(%rsp)
leal (%rax,%r8,2), %ecx
cmpl $0xd, %r9d
movl $0x400, %esi            # imm = 0x400
cmovael %edx, %esi
addl %esi, %ecx
addl $0x3, %ecx
cmpq %r13, %rcx
jbe 0x81da
pushq $-0x5
popq %rbp
jmp 0x8347
cmpq $0x2, %rbx
jae 0x81e7
xorl %ebp, %ebp
jmp 0x8347
movq %rdi, 0x10(%rsp)
movq 0x660(%rsp), %rcx
leal (%rax,%r8,2), %eax
addl $0x3, %eax
leaq (%rcx,%rax,4), %r10
shlq $0x2, %rax
subq %rax, %r13
testl %r8d, %r8d
jne 0x8213
movl $0xff, 0xc(%rsp)
testl %r9d, %r9d
pushq $0xb
popq %r14
cmovnel %r9d, %r14d
leaq 0x220(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r10, 0x18(%rsp)
movq %r10, %r8
movq %r13, %r9
callq 0x6f00
movq %rax, %rbp
cmpq $-0x9, %rax
ja 0x8347
cmpq %rbx, %rbp
jne 0x825a
pushq $0x1
jmp 0x81d4
cmpq $0x1, %rbp
sete %al
movq %rbx, %rcx
shrq $0x7, %rcx
cmpq %rcx, %rbp
setb %cl
orb %al, %cl
jne 0x81e0
movl 0xc(%rsp), %ebp
movl %r14d, %edi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x7b47
leaq 0x20(%rsp), %rdi
leaq 0x220(%rsp), %rdx
movl %eax, %r14d
movl %eax, %esi
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x7b4f
cmpq $-0x9, %rax
ja 0x8344
movl 0xc(%rsp), %ecx
leaq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
movl %r14d, %r8d
callq 0x788a
movq %rax, %rbp
cmpq $-0x9, %rax
ja 0x8347
movl 0xc(%rsp), %edx
leaq 0x20(%rsp), %rsi
movq 0x660(%rsp), %rdi
movl %r14d, %ecx
movq 0x18(%rsp), %r8
movq %r13, %r9
callq 0x76bc
cmpq $-0x9, %rax
ja 0x8344
movq 0x10(%rsp), %rax
leaq (%rax,%rbp), %r14
subq %rbp, %r12
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq 0x660(%rsp), %r8
callq 0x7eeb
movq %rax, %rbp
cmpq $-0x9, %rax
ja 0x8347
testq %rbp, %rbp
je 0x81e0
addq %rbp, %r14
subq 0x10(%rsp), %r14
decq %rbx
xorl %ebp, %ebp
cmpq %rbx, %r14
cmovbq %r14, %rbp
jmp 0x8347
movq %rax, %rbp
movq %rbp, %rax
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq