// File: /workspace/github_c_makefile_star2_O1/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
movq $-0x6, %rbp
cmpl $0xff, %ecx
ja 0xa3eb
movl %ecx, %ebx
movq %rdi, %r14
movb $0x0, 0x23(%rsp)
leal 0x1(%r8), %eax
cmpl $0x2, %eax
jb 0xa204
movl %eax, %eax
movl $0x1, %ecx
movb %r8b, 0x23(%rsp,%rcx)
incq %rcx
decb %r8b
cmpq %rcx, %rax
jne 0xa1f4
movl %ebx, %r12d
testl %ebx, %ebx
je 0xa225
xorl %eax, %eax
movzbl 0x2(%rdx,%rax,4), %ecx
movb 0x23(%rsp,%rcx), %cl
movb %cl, 0x90(%rsp,%rax)
incq %rax
cmpq %rax, %r12
jne 0xa20d
leaq 0x1(%r14), %r13
movl $0xc, 0x4(%rsp)
cmpl $0x2, %ebx
jae 0xa23d
xorl %ebp, %ebp
jmp 0xa365
movq %rsi, 0x8(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x4(%rsp), %rsi
leaq 0x90(%rsp), %rdx
movq %r12, %rcx
callq 0x760e
xorl %ebp, %ebp
cmpl %ebx, %eax
sete %bpl
cmpl $0x1, %eax
sete %al
movl %ebp, %ecx
orb %al, %cl
jne 0xa360
movl 0x4(%rsp), %edx
movl $0x6, %edi
movq %r12, %rsi
callq 0x8a1e
movl %eax, %r15d
movl 0x4(%rsp), %r8d
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movl %eax, %esi
movq %r12, %rcx
callq 0x8a6c
cmpq $-0x8, %rax
cmovaeq %rax, %rbp
jae 0xa360
movq 0x8(%rsp), %rax
leaq -0x1(%rax), %rsi
movl 0x4(%rsp), %ecx
leaq 0x30(%rsp), %rdx
movq %r13, %rdi
movq %rsi, 0x18(%rsp)
movl %r15d, %r8d
callq 0x86d4
xorl %ecx, %ecx
cmpq $-0x8, %rax
cmovbq %rax, %rcx
cmovaeq %rax, %rbp
jae 0xa360
movq %rcx, 0x10(%rsp)
movl 0x4(%rsp), %edx
leaq 0x1d0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x190(%rsp), %r8
movl $0x40, %r9d
movl %r15d, %ecx
callq 0x84f4
cmpq $-0x8, %rax
cmovaeq %rax, %rbp
jae 0xa360
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %r15
movq 0x18(%rsp), %rsi
subq %rax, %rsi
leaq 0x90(%rsp), %rdx
leaq 0x1d0(%rsp), %r8
movq %r15, %rdi
movq %r12, %rcx
callq 0x8e2f
cmpq $-0x9, %rax
ja 0xa400
testq %rax, %rax
je 0xa407
addq %rax, %r15
movb $0x1, %cl
jmp 0xa40b
movq 0x8(%rsp), %rsi
cmpq $-0x9, %rbp
ja 0xa386
cmpq $0x2, %rbp
setb %al
movl %ebx, %ecx
shrl %ecx
cmpq %rcx, %rbp
setae %cl
orb %al, %cl
jne 0xa38a
movb %bpl, (%r14)
incq %rbp
xorl %eax, %eax
jmp 0xa38c
movb $0x1, %al
testb %al, %al
je 0xa3eb
movq $-0x1, %rbp
cmpl $0x80, %ebx
ja 0xa3eb
leal 0x1(%rbx), %eax
shrl %eax
incl %eax
movq $-0x2, %rbp
cmpq %rsi, %rax
ja 0xa3eb
leal 0x7f(%rbx), %ecx
movb %cl, (%r14)
movb $0x0, 0x90(%rsp,%r12)
testl %ebx, %ebx
je 0xa3e8
xorl %ecx, %ecx
movb 0x90(%rsp,%rcx), %dl
shlb $0x4, %dl
addb 0x91(%rsp,%rcx), %dl
movb %dl, (%r13)
addq $0x2, %rcx
incq %r13
cmpq %r12, %rcx
jb 0xa3c7
movq %rax, %rbp
movq %rbp, %rax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ecx, %ecx
movq %rax, %rbp
jmp 0xa40b
xorl %ecx, %ecx
xorl %ebp, %ebp
movq 0x8(%rsp), %rsi
testb %cl, %cl
je 0xa365
subq %r13, %r15
movq %r15, %rbp
jmp 0xa365