// File: /workspace/github_c_makefile_star2_O1/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 0x94e7
cmpq $0x2, %rbx
jae 0x931f
xorl %ebp, %ebp
jmp 0x94e7
movq %rdi, %r14
movq %rsi, 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 0x934e
movl $0xff, 0x4(%rsp)
testl %r9d, %r9d
movl $0xb, %r12d
cmovnel %r9d, %r12d
leaq 0x220(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %r10, 0x18(%rsp)
movq %r10, %r8
movq %r13, %r9
callq 0x7929
movq %rax, %rbp
cmpq $-0x9, %rax
ja 0x9391
cmpq %rbx, %rbp
jne 0x9395
movl $0x1, %ebp
xorl %eax, %eax
jmp 0x93ae
cmpq $0x1, %rbp
jne 0x939f
xorl %eax, %eax
jmp 0x93ac
movq %rbx, %rax
shrq $0x7, %rax
cmpq %rax, %rbp
setae %al
xorl %ebp, %ebp
testb %al, %al
je 0x94e7
movq %r14, 0x8(%rsp)
movl 0x4(%rsp), %r14d
leal -0x1(%rbx), %eax
bsrl %eax, %eax
xorl $-0x20, %eax
addl $0x1e, %eax
bsrl %ebx, %ecx
xorl $-0x20, %ecx
addl $0x21, %ecx
bsrl %r14d, %edx
xorl $-0x20, %edx
addl $0x22, %edx
cmpl %edx, %ecx
cmovbl %ecx, %edx
cmpl %r12d, %eax
cmovael %r12d, %eax
cmpl %eax, %edx
cmoval %edx, %eax
cmpl $0x6, %eax
movl $0x5, %ecx
cmovael %eax, %ecx
cmpl $0xc, %ecx
movl $0xc, %r12d
cmovbl %ecx, %r12d
leaq 0x20(%rsp), %rdi
leaq 0x220(%rsp), %rdx
movl %r12d, %esi
movq %rbx, %rcx
movl %r14d, %r8d
callq 0x8a6c
cmpq $-0x8, %rax
cmovaeq %rax, %rbp
jae 0x94e7
leaq 0x20(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %r14d, %ecx
movl %r12d, %r8d
callq 0x86d4
xorl %r14d, %r14d
cmpq $-0x8, %rax
cmovbq %rax, %r14
cmovaeq %rax, %rbp
jae 0x94e7
movl 0x4(%rsp), %edx
leaq 0x20(%rsp), %rsi
movq 0x660(%rsp), %rdi
movl %r12d, %ecx
movq 0x18(%rsp), %r8
movq %r13, %r9
callq 0x84f4
cmpq $-0x8, %rax
cmovaeq %rax, %rbp
jae 0x94e7
movq 0x8(%rsp), %rax
leaq (%rax,%r14), %r12
movq 0x10(%rsp), %rsi
subq %r14, %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
movq 0x660(%rsp), %r8
callq 0x8e2f
cmpq $-0x9, %rax
ja 0x94c4
testq %rax, %rax
je 0x94cb
addq %rax, %r12
movb $0x1, %cl
jmp 0x94cf
xorl %ecx, %ecx
movq %rax, %rbp
jmp 0x94cf
xorl %ecx, %ecx
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
testb %cl, %cl
je 0x94e7
subq %rax, %r12
decq %rbx
xorl %ebp, %ebp
cmpq %rbx, %r12
cmovbq %r12, %rbp
movq %rbp, %rax
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq