// File: /workspace/github_c_makefile_star2_O2/Cyan4973[P]FiniteStateEntropy/programs/../lib/huf_compress.c
// Function: HUF_writeCTable
size_t HUF_writeCTable (void* dst, size_t maxDstSize,
                        const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog)
{
    BYTE bitsToWeight[HUF_TABLELOG_MAX + 1];   /* precomputed conversion table */
    BYTE huffWeight[HUF_SYMBOLVALUE_MAX];
    BYTE* op = (BYTE*)dst;
    U32 n;

     /* check conditions */
    if (maxSymbolValue > HUF_SYMBOLVALUE_MAX) return ERROR(maxSymbolValue_tooLarge);

    /* convert to weight */
    bitsToWeight[0] = 0;
    for (n=1; n<huffLog+1; n++)
        bitsToWeight[n] = (BYTE)(huffLog + 1 - n);
    for (n=0; n<maxSymbolValue; n++)
        huffWeight[n] = bitsToWeight[CTable[n].nbBits];

    /* attempt weights compression by FSE */
    {   CHECK_V_F(hSize, HUF_compressWeights(op+1, maxDstSize-1, huffWeight, maxSymbolValue) );
        if ((hSize>1) & (hSize < maxSymbolValue/2)) {   /* FSE compressed */
            op[0] = (BYTE)hSize;
            return hSize+1;
    }   }

    /* write raw values as 4-bits (max : 15) */
    if (maxSymbolValue > (256-128)) return ERROR(GENERIC);   /* should not happen : likely means source cannot be compressed */
    if (((maxSymbolValue+1)/2) + 1 > maxDstSize) return ERROR(dstSize_tooSmall);   /* not enough space within dst buffer */
    op[0] = (BYTE)(128 /*special case*/ + (maxSymbolValue-1));
    huffWeight[maxSymbolValue] = 0;   /* to be sure it doesn't cause msan issue in final combination */
    for (n=0; n<maxSymbolValue; n+=2)
        op[(n/2)+1] = (BYTE)((huffWeight[n] << 4) + huffWeight[n+1]);
    return ((maxSymbolValue+1)/2) + 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
cmpl $0xff, %ecx
jbe 0x9039
pushq $-0x6
popq %rbp
jmp 0x91e3
movl %ecx, %ebx
movq %rsi, %r12
movq %rdi, %r14
movb $0x0, 0x23(%rsp)
leal 0x1(%r8), %eax
pushq $0x1
popq %rcx
cmpq %rax, %rcx
jae 0x905f
movb %r8b, 0x23(%rsp,%rcx)
incq %rcx
decb %r8b
jmp 0x904d
movl %ebx, %r15d
xorl %eax, %eax
cmpq %rax, %r15
je 0x907e
movzbl 0x2(%rdx,%rax,4), %ecx
movb 0x23(%rsp,%rcx), %cl
movb %cl, 0x90(%rsp,%rax)
incq %rax
jmp 0x9064
leaq 0x1(%r14), %r13
movl $0xc, 0x8(%rsp)
cmpl $0x2, %ebx
jae 0x9093
xorl %ebp, %ebp
jmp 0x90b4
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
movq %r15, %rcx
callq 0x6c36
cmpl %ebx, %eax
jne 0x90e7
pushq $0x1
popq %rbp
cmpq $0x2, %rbp
setb %al
movl %ebx, %ecx
shrl %ecx
cmpq %rcx, %rbp
setae %cl
orb %al, %cl
jne 0x90d4
movb %bpl, (%r14)
incq %rbp
jmp 0x91e3
cmpl $0x80, %ebx
jbe 0x91cd
pushq $-0x1
jmp 0x9033
cmpl $0x1, %eax
je 0x908f
movl 0x8(%rsp), %edx
pushq $0x6
popq %rdi
movq %r15, %rsi
callq 0x7b47
movl 0x8(%rsp), %r8d
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movl %eax, 0xc(%rsp)
movl %eax, %esi
movq %r15, %rcx
callq 0x7b4f
cmpq $-0x9, %rax
ja 0x91e0
leaq -0x1(%r12), %rbp
movl 0x8(%rsp), %ecx
leaq 0x30(%rsp), %rdx
movq %r13, %rdi
movq %rbp, %rsi
movl 0xc(%rsp), %r8d
callq 0x788a
cmpq $-0x9, %rax
ja 0x91e0
movq %rax, 0x10(%rsp)
movq %rbp, 0x18(%rsp)
movl 0x8(%rsp), %edx
leaq 0x1d0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x190(%rsp), %r8
pushq $0x40
popq %r9
movl 0xc(%rsp), %ecx
callq 0x76bc
cmpq $-0x9, %rax
ja 0x91e0
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %rbp
movq 0x18(%rsp), %rsi
subq %rax, %rsi
leaq 0x90(%rsp), %rdx
leaq 0x1d0(%rsp), %r8
movq %rbp, %rdi
movq %r15, %rcx
callq 0x7eeb
cmpq $-0x9, %rax
ja 0x91e0
testq %rax, %rax
je 0x908f
addq %rax, %rbp
subq %r13, %rbp
cmpq $-0x9, %rbp
jbe 0x90b4
jmp 0x91e3
leal 0x1(%rbx), %ebp
shrl %ebp
incl %ebp
cmpq %r12, %rbp
jbe 0x91f8
pushq $-0x2
jmp 0x9033
movq %rax, %rbp
movq %rbp, %rax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addb $0x7f, %bl
movb %bl, (%r14)
movb $0x0, 0x90(%rsp,%r15)
xorl %eax, %eax
cmpq %r15, %rax
jae 0x91e3
movb 0x90(%rsp,%rax), %cl
shlb $0x4, %cl
addb 0x91(%rsp,%rax), %cl
movb %cl, (%r13)
addq $0x2, %rax
incq %r13
jmp 0x9209