// File: /workspace/github_c_makefile_star2_O1/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), %r12
movl %r8d, 0x8(%rsp)
movq $-0x1, %r13
testb $0x3, %r12b
jne 0xb3b4
movl %r9d, %eax
movq 0x70(%rsp), %r9
movq $-0x8, %r13
cmpq $0x1900, %r9            # imm = 0x1900
jb 0xb3b4
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %rbp
testq %rcx, %rcx
sete %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
je 0xb00d
xorl %r13d, %r13d
jmp 0xb3b4
movq $-0x3, %r13
cmpq $0x20000, %rbx          # imm = 0x20000
ja 0xb3b4
movq $-0x5, %r13
cmpl $0xc, %eax
ja 0xb3b4
movq $-0x6, %r13
cmpl $0xff, %r8d
ja 0xb3b4
movq %rdi, %r15
movl 0x88(%rsp), %ecx
movq 0x80(%rsp), %rsi
testl %r8d, %r8d
jne 0xb064
movl $0xff, 0x8(%rsp)
movl 0x90(%rsp), %r10d
movl 0x60(%rsp), %r11d
leaq (%r15,%rbp), %rdx
testl %eax, %eax
movl $0xb, %edi
cmovnel %eax, %edi
testl %ecx, %ecx
setne %al
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xb0bc
cmpl $0x2, (%rsi)
jne 0xb0bc
movq %r15, %rdi
movq %r15, %rsi
movq %r14, %rcx
movq %rbx, %r8
movl %r11d, %r9d
pushq %r10
pushq 0x80(%rsp)
callq 0xb6ca
addq $0x38, %rsp
jmp 0xb3bb
movb %cl, 0x10(%rsp)
movl %edi, 0xc(%rsp)
movq %rdx, 0x18(%rsp)
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
movq %r12, %r8
callq 0x7929
movq %rax, %r13
cmpq $-0x9, %rax
ja 0xb102
cmpq %rbx, %r13
movq 0x78(%rsp), %r10
jne 0xb10b
movb (%r14), %al
movb %al, (%r15)
movl $0x1, %r13d
xorl %eax, %eax
jmp 0xb11f
xorl %eax, %eax
movq 0x78(%rsp), %r10
jmp 0xb11f
movq %rbx, %rax
shrq $0x7, %rax
addq $0x4, %rax
cmpq %rax, %r13
seta %al
xorl %r13d, %r13d
movq 0x80(%rsp), %rcx
testb %al, %al
je 0xb3b4
testq %rcx, %rcx
je 0xb17e
cmpl $0x1, (%rcx)
jne 0xb17e
movl 0x8(%rsp), %eax
testl %eax, %eax
js 0xb17e
incq %rax
xorl %ecx, %ecx
xorl %edx, %edx
cmpl $0x0, (%r12,%rcx,4)
setne %sil
cmpb $0x0, 0x2(%r10,%rcx,4)
sete %dil
andb %sil, %dil
movzbl %dil, %esi
orl %esi, %edx
incq %rcx
cmpq %rcx, %rax
jne 0xb148
testl %edx, %edx
movq 0x80(%rsp), %rcx
je 0xb17e
movl $0x0, (%rcx)
cmpb $0x0, 0x10(%rsp)
je 0xb1af
cmpl $0x0, (%rcx)
je 0xb1af
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 %r10
jmp 0xb3a8
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %edi
movq %rbx, %rsi
movl $0x1, %ecx
callq 0x89d4
leaq 0x400(%r12), %rdi
movl 0x8(%rsp), %edx
leaq 0x800(%r12), %r8
movl $0x1100, %r9d           # imm = 0x1100
movq %rdi, 0x10(%rsp)
movq %r12, %rsi
movl %eax, 0xc(%rsp)
movl %eax, %ecx
callq 0xa5ad
movq %rax, %rcx
cmpq $-0x8, %rax
cmovaeq %rax, %r13
jae 0xb22e
movl 0x8(%rsp), %eax
incl %eax
movq %rcx, 0x20(%rsp)
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 0x20(%rsp), %rcx
movl %ecx, 0xc(%rsp)
cmpq $-0x9, %rcx
ja 0xb3b4
movl 0x8(%rsp), %ecx
movq %r15, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rdx
movl 0xc(%rsp), %r8d
callq 0xa1b6
movq %rax, %rbp
cmpq $-0x9, %rax
ja 0xb2a1
movq 0x80(%rsp), %rcx
testq %rcx, %rcx
je 0xb2af
cmpl $0x0, (%rcx)
movq 0x78(%rsp), %r10
je 0xb345
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
js 0xb2b9
leaq 0x1(%rcx), %rdx
xorl %esi, %esi
xorl %eax, %eax
movzbl 0x2(%r10,%rsi,4), %edi
imull (%r12,%rsi,4), %edi
addq %rdi, %rax
incq %rsi
cmpq %rsi, %rdx
jne 0xb285
shrq $0x3, %rax
jmp 0xb2bb
movq %rbp, %r13
xorl %r12d, %r12d
movq %r15, %rbp
jmp 0xb381
movq 0x78(%rsp), %r10
jmp 0xb345
xorl %eax, %eax
testl %ecx, %ecx
js 0xb2e5
incq %rcx
xorl %esi, %esi
xorl %edx, %edx
movzbl 0x402(%r12,%rsi,4), %edi
imull (%r12,%rsi,4), %edi
addq %rdi, %rdx
incq %rsi
cmpq %rsi, %rcx
jne 0xb2c6
shrq $0x3, %rdx
jmp 0xb2e7
xorl %edx, %edx
addq %rbp, %rdx
cmpq %rdx, %rax
seta %al
leaq 0xc(%rbp), %rcx
cmpq %rbx, %rcx
setb %r12b
andb %al, %r12b
jne 0xb334
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 %r10
callq 0xb6ca
movq 0x88(%rsp), %r10
addq $0x10, %rsp
movq %rax, %r13
testb %r12b, %r12b
movq 0x80(%rsp), %rcx
je 0xb2a4
leaq 0xc(%rbp), %rax
cmpq %rbx, %rax
jae 0xb378
testq %rcx, %rcx
je 0xb359
movl $0x0, (%rcx)
addq %r15, %rbp
movb $0x1, %r12b
testq %r10, %r10
je 0xb381
movl $0x400, %edx            # imm = 0x400
movq %r10, %rdi
movq 0x10(%rsp), %rsi
callq 0x1130
jmp 0xb381
xorl %r12d, %r12d
movq %r15, %rbp
xorl %r13d, %r13d
testb %r12b, %r12b
je 0xb3b4
movq %r15, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
movl 0x60(%rsp), %r9d
movl 0x90(%rsp), %eax
pushq %rax
pushq 0x18(%rsp)
callq 0xb6ca
addq $0x10, %rsp
movq %rax, %r13
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq