// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x18(%rbp), %rax
andq $0x3, %rax
cmpq $0x0, %rax
je 0x1653b
movq $-0x1, -0x8(%rbp)
jmp 0x16921
cmpq $0x1900, 0x20(%rbp)     # imm = 0x1900
jae 0x16552
movq $-0x8, -0x8(%rbp)
jmp 0x16921
cmpq $0x0, -0x28(%rbp)
jne 0x16566
movq $0x0, -0x8(%rbp)
jmp 0x16921
cmpq $0x0, -0x18(%rbp)
jne 0x1657a
movq $0x0, -0x8(%rbp)
jmp 0x16921
cmpq $0x20000, -0x28(%rbp)   # imm = 0x20000
jbe 0x16591
movq $-0x3, -0x8(%rbp)
jmp 0x16921
cmpl $0xc, -0x30(%rbp)
jbe 0x165a4
movq $-0x5, -0x8(%rbp)
jmp 0x16921
cmpl $0xff, -0x2c(%rbp)
jbe 0x165ba
movq $-0x6, -0x8(%rbp)
jmp 0x16921
cmpl $0x0, -0x2c(%rbp)
jne 0x165c7
movl $0xff, -0x2c(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x165d4
movl $0xb, -0x30(%rbp)
cmpl $0x0, 0x38(%rbp)
je 0x1661f
cmpq $0x0, 0x30(%rbp)
je 0x1661f
movq 0x30(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x1661f
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movl 0x10(%rbp), %r9d
movq 0x28(%rbp), %r10
movl 0x40(%rbp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x17840
movq %rax, -0x8(%rbp)
jmp 0x16921
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq 0x18(%rbp), %r8
movq 0x20(%rbp), %r9
leaq -0x2c(%rbp), %rsi
callq 0xf420
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x151f0
cmpl $0x0, %eax
je 0x1665b
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x16921
movq -0x58(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x1667e
movq -0x20(%rbp), %rax
movb (%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movq $0x1, -0x8(%rbp)
jmp 0x16921
movq -0x58(%rbp), %rax
movq -0x28(%rbp), %rcx
shrq $0x7, %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
ja 0x166a0
movq $0x0, -0x8(%rbp)
jmp 0x16921
cmpq $0x0, 0x30(%rbp)
je 0x166cf
movq 0x30(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x166cf
movq 0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x15fe0
cmpl $0x0, %eax
jne 0x166cf
movq 0x30(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x0, 0x38(%rbp)
je 0x1671a
cmpq $0x0, 0x30(%rbp)
je 0x1671a
movq 0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1671a
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movl 0x10(%rbp), %r9d
movq 0x28(%rbp), %r10
movl 0x40(%rbp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x17840
movq %rax, -0x8(%rbp)
jmp 0x16921
movl -0x30(%rbp), %edi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x14d40
movl %eax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
addq $0x400, %rdi            # imm = 0x400
movq -0x38(%rbp), %rsi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
movq -0x38(%rbp), %r8
addq $0x800, %r8             # imm = 0x800
movl $0x1100, %r9d           # imm = 0x1100
callq 0x15590
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x151f0
cmpl $0x0, %eax
je 0x1677e
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x16921
movq -0x60(%rbp), %rax
movl %eax, -0x30(%rbp)
movq -0x38(%rbp), %rdi
addq $0x400, %rdi            # imm = 0x400
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
shlq $0x2, %rax
addq %rax, %rdi
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
shlq $0x2, %rax
movl $0x400, %edx            # imm = 0x400
subq %rax, %rdx
xorl %esi, %esi
callq 0x10c0
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
addq $0x400, %rdx            # imm = 0x400
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %r8d
callq 0x14d70
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0x151f0
cmpl $0x0, %eax
je 0x167f8
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x16921
cmpq $0x0, 0x30(%rbp)
je 0x16895
movq 0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x16895
movq 0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x15f80
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rdi
addq $0x400, %rdi            # imm = 0x400
movq -0x38(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x15f80
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
addq -0x80(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x1685e
movq -0x70(%rbp), %rax
addq $0xc, %rax
cmpq -0x28(%rbp), %rax
jb 0x16893
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movl 0x10(%rbp), %r9d
movq 0x28(%rbp), %r10
movl 0x40(%rbp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x17840
movq %rax, -0x8(%rbp)
jmp 0x16921
jmp 0x16895
movq -0x70(%rbp), %rax
addq $0xc, %rax
cmpq -0x28(%rbp), %rax
jb 0x168ad
movq $0x0, -0x8(%rbp)
jmp 0x16921
movq -0x70(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x168ca
movq 0x30(%rbp), %rax
movl $0x0, (%rax)
cmpq $0x0, 0x28(%rbp)
je 0x168ea
movq 0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x400, %rsi            # imm = 0x400
movl $0x400, %edx            # imm = 0x400
callq 0x1120
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movl 0x10(%rbp), %r9d
movq -0x38(%rbp), %r10
addq $0x400, %r10            # imm = 0x400
movl 0x40(%rbp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x17840
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nop