// File: /workspace/github_c_makefile_star2_O2/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)
testb $0x3, %bpl
je 0x9cb2
pushq $-0x1
jmp 0x9cc5
movl %r9d, %eax
movq 0x70(%rsp), %r9
cmpq $0x1900, %r9            # imm = 0x1900
jae 0x9cd9
pushq $-0x8
popq %r13
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
testq %rcx, %rcx
sete %cl
testq %rsi, %rsi
sete %dl
orb %cl, %dl
je 0x9cf7
xorl %r13d, %r13d
jmp 0x9cc7
cmpq $0x20000, %rbx          # imm = 0x20000
jbe 0x9d04
pushq $-0x3
jmp 0x9cc5
cmpl $0xc, %eax
jbe 0x9d0d
pushq $-0x5
jmp 0x9cc5
cmpl $0xff, %r8d
jbe 0x9d1a
pushq $-0x6
jmp 0x9cc5
movq %rdi, %r15
movl 0x88(%rsp), %ecx
movq 0x80(%rsp), %rsi
testl %r8d, %r8d
jne 0x9d39
movl $0xff, 0xc(%rsp)
movl 0x90(%rsp), %r10d
movl 0x60(%rsp), %r11d
leaq (%r15,%r12), %rdx
testl %eax, %eax
pushq $0xb
popq %rdi
cmovnel %eax, %edi
testl %ecx, %ecx
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x9d8c
cmpl $0x2, (%rsi)
jne 0x9d8c
movq %r15, %rdi
movq %r15, %rsi
movq %r14, %rcx
movq %rbx, %r8
movl %r11d, %r9d
pushq %r10
pushq 0x80(%rsp)
callq 0xa28d
addq $0x38, %rsp
jmp 0x9cce
movb %cl, 0x10(%rsp)
movl %edi, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
leaq 0xc(%rsp), %rsi
movq %rbp, %rdi
movq %r14, %rdx
movq %rbx, %rcx
movq %rbp, %r8
callq 0x6f00
movq %rax, %r13
cmpq $-0x9, %rax
ja 0x9cc7
cmpq %rbx, %r13
jne 0x9dce
movb (%r14), %al
movb %al, (%r15)
pushq $0x1
jmp 0x9cc5
movq %rbx, %rax
shrq $0x7, %rax
addq $0x4, %rax
cmpq %rax, %r13
jbe 0x9cf2
movq 0x80(%rsp), %r13
testq %r13, %r13
je 0x9e2f
movl (%r13), %eax
cmpl $0x1, %eax
jne 0x9e20
movl 0xc(%rsp), %edx
movq 0x78(%rsp), %rdi
movq %rbp, %rsi
callq 0x992b
testl %eax, %eax
je 0x9e19
cmpb $0x0, 0x10(%rsp)
jne 0x9e2f
jmp 0x9f13
andl $0x0, (%r13)
xorl %eax, %eax
testl %eax, %eax
sete %al
orb %al, 0x10(%rsp)
je 0x9f13
movl 0xc(%rsp), %edx
movl 0x18(%rsp), %edi
movq %rbx, %rsi
callq 0x9010
leaq 0x400(%rbp), %rdi
movl 0xc(%rsp), %edx
leaq 0x800(%rbp), %r8
movl $0x1100, %r9d           # imm = 0x1100
movq %rdi, 0x18(%rsp)
movq %rbp, %rsi
movq %rdx, 0x10(%rsp)
movl %eax, %ecx
callq 0x9398
movq %rax, %r13
cmpq $-0x9, %rax
ja 0x9cc7
movq 0x10(%rsp), %rax
incl %eax
movq 0x18(%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 %r12, %rsi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movl %r13d, %r8d
callq 0x9018
movq %rax, %r13
cmpq $-0x9, %rax
ja 0x9cc7
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x9f47
cmpl $0x0, (%rax)
je 0x9f56
movl 0xc(%rsp), %r12d
movq 0x78(%rsp), %rdi
movq %rbp, %rsi
movl %r12d, %edx
callq 0x9907
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
movl %r12d, %edx
callq 0x9907
leaq 0xc(%r13), %rcx
cmpq %rbx, %rcx
jae 0x9f13
addq %r13, %rax
cmpq %rax, 0x10(%rsp)
ja 0x9f5a
movq %r15, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
movl 0x60(%rsp), %r9d
movl 0x90(%rsp), %eax
pushq %rax
pushq 0x80(%rsp)
callq 0xa28d
popq %rcx
popq %rdx
movq %rax, %r13
jmp 0x9cc7
leaq 0xc(%r13), %rax
cmpq %rbx, %rax
jae 0x9cf2
jmp 0x9f6e
leaq 0xc(%r13), %rcx
cmpq %rbx, %rcx
jae 0x9cf2
movq 0x80(%rsp), %rax
andl $0x0, (%rax)
addq %r15, %r13
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
movq 0x18(%rsp), %r12
je 0x9f8d
movl $0x400, %edx            # imm = 0x400
movq %r12, %rsi
callq 0x1130
movq %r15, %rdi
movq %r13, %rsi
movq 0x20(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
movl 0x60(%rsp), %r9d
movl 0x90(%rsp), %eax
pushq %rax
pushq %r12
jmp 0x9f38