// File: /workspace/github_c_makefile_star2_O3/Cyan4973[P]FiniteStateEntropy/programs/../lib/huf_compress.c
// Function: HUF_compress_internal
static size_t
HUF_compress_internal (void* dst, size_t dstSize,
                 const void* src, size_t srcSize,
                       unsigned maxSymbolValue, unsigned huffLog,
                       HUF_nbStreams_e nbStreams,
                       void* workSpace, size_t wkspSize,
                       HUF_CElt* oldHufTable, HUF_repeat* repeat, int preferRepeat,
                 const int bmi2)
{
    HUF_compress_tables_t* const table = (HUF_compress_tables_t*)workSpace;
    BYTE* const ostart = (BYTE*)dst;
    BYTE* const oend = ostart + dstSize;
    BYTE* op = ostart;

    HUF_STATIC_ASSERT(sizeof(*table) <= HUF_WORKSPACE_SIZE);

    /* checks & inits */
    if (((size_t)workSpace & 3) != 0) return ERROR(GENERIC);  /* must be aligned on 4-bytes boundaries */
    if (wkspSize < HUF_WORKSPACE_SIZE) return ERROR(workSpace_tooSmall);
    if (!srcSize) return 0;  /* Uncompressed */
    if (!dstSize) return 0;  /* cannot fit anything within dst budget */
    if (srcSize > HUF_BLOCKSIZE_MAX) return ERROR(srcSize_wrong);   /* current block size limit */
    if (huffLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
    if (maxSymbolValue > HUF_SYMBOLVALUE_MAX) return ERROR(maxSymbolValue_tooLarge);
    if (!maxSymbolValue) maxSymbolValue = HUF_SYMBOLVALUE_MAX;
    if (!huffLog) huffLog = HUF_TABLELOG_DEFAULT;

    /* Heuristic : If old table is valid, use it for small inputs */
    if (preferRepeat && repeat && *repeat == HUF_repeat_valid) {
        return HUF_compressCTable_internal(ostart, op, oend,
                                           src, srcSize,
                                           nbStreams, oldHufTable, bmi2);
    }

    /* Scan input and build symbol stats */
    {   CHECK_V_F(largest, HIST_count_wksp (table->count, &maxSymbolValue, (const BYTE*)src, srcSize, workSpace, wkspSize) );
        if (largest == srcSize) { *ostart = ((const BYTE*)src)[0]; return 1; }   /* single symbol, rle */
        if (largest <= (srcSize >> 7)+4) return 0;   /* heuristic : probably not compressible enough */
    }

    /* Check validity of previous table */
    if ( repeat
      && *repeat == HUF_repeat_check
      && !HUF_validateCTable(oldHufTable, table->count, maxSymbolValue)) {
        *repeat = HUF_repeat_none;
    }
    /* Heuristic : use existing table for small inputs */
    if (preferRepeat && repeat && *repeat != HUF_repeat_none) {
        return HUF_compressCTable_internal(ostart, op, oend,
                                           src, srcSize,
                                           nbStreams, oldHufTable, bmi2);
    }

    /* Build Huffman Tree */
    huffLog = HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue);
    {   size_t const maxBits = HUF_buildCTable_wksp(table->CTable, table->count,
                                            maxSymbolValue, huffLog,
                                            &table->buildCTable_wksp, sizeof(table->buildCTable_wksp));
        CHECK_F(maxBits);
        huffLog = (U32)maxBits;
        /* Zero unused symbols in CTable, so we can check it for validity */
        memset(table->CTable + (maxSymbolValue + 1), 0,
               sizeof(table->CTable) - ((maxSymbolValue + 1) * sizeof(HUF_CElt)));
    }

    /* Write table description header */
    {   CHECK_V_F(hSize, HUF_writeCTable (op, dstSize, table->CTable, maxSymbolValue, huffLog) );
        /* Check if using previous huffman table is beneficial */
        if (repeat && *repeat != HUF_repeat_none) {
            size_t const oldSize = HUF_estimateCompressedSize(oldHufTable, table->count, maxSymbolValue);
            size_t const newSize = HUF_estimateCompressedSize(table->CTable, table->count, maxSymbolValue);
            if (oldSize <= hSize + newSize || hSize + 12 >= srcSize) {
                return HUF_compressCTable_internal(ostart, op, oend,
                                                   src, srcSize,
                                                   nbStreams, oldHufTable, bmi2);
        }   }

        /* Use the new huffman table */
        if (hSize + 12ul >= srcSize) { return 0; }
        op += hSize;
        if (repeat) { *repeat = HUF_repeat_none; }
        if (oldHufTable)
            memcpy(oldHufTable, table->CTable, sizeof(table->CTable));  /* Save new table */
    }
    return HUF_compressCTable_internal(ostart, op, oend,
                                       src, srcSize,
                                       nbStreams, table->CTable, bmi2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x68(%rsp), %rbp
movl %r8d, 0xc(%rsp)
movq $-0x1, %r12
testb $0x3, %bpl
jne 0xbfbd
movl %r9d, %eax
movq 0x70(%rsp), %r9
movq $-0x8, %r12
cmpq $0x1900, %r9            # imm = 0x1900
jb 0xbfbd
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r13
testq %rcx, %rcx
sete %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
je 0xbed7
xorl %r12d, %r12d
jmp 0xbfbd
movq $-0x3, %r12
cmpq $0x20000, %rbx          # imm = 0x20000
ja 0xbfbd
movq $-0x5, %r12
cmpl $0xc, %eax
ja 0xbfbd
movq $-0x6, %r12
cmpl $0xff, %r8d
ja 0xbfbd
movq %rdi, %r15
movl 0x88(%rsp), %ecx
movq 0x80(%rsp), %rsi
testl %r8d, %r8d
jne 0xbf2e
movl $0xff, 0xc(%rsp)
movl 0x90(%rsp), %r10d
movl 0x60(%rsp), %r11d
leaq (%r15,%r13), %rdx
testl %eax, %eax
movl $0xb, %edi
cmovnel %eax, %edi
testl %ecx, %ecx
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0xbf80
cmpl $0x2, (%rsi)
jne 0xbf80
movq %r15, %rdi
movq %r15, %rsi
movq %r14, %rcx
movq %rbx, %r8
movl %r11d, %r9d
pushq %r10
pushq 0x80(%rsp)
callq 0xc504
addq $0x38, %rsp
jmp 0xbfc4
movb %cl, 0x20(%rsp)
movl %edi, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
leaq 0xc(%rsp), %rsi
movq %rbp, %rdi
movq %r14, %rdx
movq %rbx, %rcx
movq %rbp, %r8
callq 0x7f84
movq %rax, %r12
cmpq $-0x9, %rax
ja 0xbfbd
cmpq %rbx, %r12
jne 0xbfcf
movb (%r14), %al
movb %al, (%r15)
movl $0x1, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rax
shrq $0x7, %rax
addq $0x4, %rax
cmpq %rax, %r12
jbe 0xbecf
movq 0x80(%rsp), %r10
testq %r10, %r10
movl 0x10(%rsp), %edi
je 0xc056
movl (%r10), %eax
cmpl $0x1, %eax
jne 0xc047
movl 0xc(%rsp), %ecx
movl $0x1, %eax
testl %ecx, %ecx
js 0xc047
incq %rcx
xorl %edx, %edx
xorl %esi, %esi
movq 0x78(%rsp), %r9
cmpl $0x0, (%rbp,%rdx,4)
setne %r11b
cmpb $0x0, 0x2(%r9,%rdx,4)
sete %r8b
andb %r11b, %r8b
movzbl %r8b, %r8d
orl %r8d, %esi
incq %rdx
cmpq %rdx, %rcx
jne 0xc015
testl %esi, %esi
je 0xc047
movl $0x0, (%r10)
jmp 0xc056
testl %eax, %eax
sete %al
orb %al, 0x20(%rsp)
je 0xc163
movl 0xc(%rsp), %edx
movq %rbx, %rsi
movl $0x1, %ecx
callq 0x8f99
leaq 0x400(%rbp), %rdi
movl 0xc(%rsp), %edx
leaq 0x800(%rbp), %r8
movl $0x1100, %r9d           # imm = 0x1100
movq %rdi, 0x10(%rsp)
movq %rbp, %rsi
movl %eax, %ecx
callq 0xb344
movq %rax, %r12
cmpq $-0x9, %rax
ja 0xbfbd
movl 0xc(%rsp), %eax
movq %rax, 0x20(%rsp)
incl %eax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
shlq $0x2, %rax
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
xorl %esi, %esi
callq 0x10c0
movq %r15, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
movq %rdx, %r13
movq 0x20(%rsp), %rcx
movl %r12d, %r8d
callq 0xa98a
movq %rax, %r12
cmpq $-0x9, %rax
ja 0xbfbd
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0xc18a
cmpl $0x0, (%rax)
je 0xc19a
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
js 0xc163
incq %rcx
xorl %edx, %edx
xorl %eax, %eax
movq 0x78(%rsp), %rdi
movzbl 0x2(%rdi,%rdx,4), %esi
imull (%rbp,%rdx,4), %esi
addq %rsi, %rax
incq %rdx
cmpq %rdx, %rcx
jne 0xc118
xorl %esi, %esi
xorl %edx, %edx
movzbl 0x402(%rbp,%rsi,4), %edi
imull (%rbp,%rsi,4), %edi
addq %rdi, %rdx
incq %rsi
cmpq %rsi, %rcx
jne 0xc131
leaq 0xc(%r12), %rcx
cmpq %rbx, %rcx
jae 0xc163
shrq $0x3, %rax
shrq $0x3, %rdx
addq %r12, %rdx
cmpq %rdx, %rax
ja 0xc1a8
movq %r15, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
movl 0x60(%rsp), %r9d
movl 0x90(%rsp), %eax
pushq %rax
pushq 0x80(%rsp)
jmp 0xc1f0
leaq 0xc(%r12), %rax
cmpq %rbx, %rax
jae 0xbecf
jmp 0xc1b6
leaq 0xc(%r12), %rax
cmpq %rbx, %rax
jae 0xbecf
movq 0x80(%rsp), %rax
movl $0x0, (%rax)
addq %r15, %r12
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xc1d0
movl $0x400, %edx            # imm = 0x400
movq %r13, %rsi
callq 0x1130
movq %r15, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
movl 0x60(%rsp), %r9d
movl 0x90(%rsp), %eax
pushq %rax
pushq %r13
callq 0xc504
addq $0x10, %rsp
movq %rax, %r12
jmp 0xbfbd