// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x148(%rbp)
cmpl $0xff, -0x24(%rbp)
jbe 0x14daf
movq $-0x6, -0x8(%rbp)
jmp 0x14fac
movb $0x0, -0x35(%rbp)
movl $0x1, -0x14c(%rbp)
movl -0x14c(%rbp), %eax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x14df6
movl -0x28(%rbp), %eax
addl $0x1, %eax
subl -0x14c(%rbp), %eax
movb %al, %cl
movl -0x14c(%rbp), %eax
movb %cl, -0x35(%rbp,%rax)
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x14dbd
movl $0x0, -0x14c(%rbp)
movl -0x14c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x14e3c
movq -0x20(%rbp), %rax
movl -0x14c(%rbp), %ecx
movzbl 0x2(%rax,%rcx,4), %eax
movb -0x35(%rbp,%rax), %cl
movl -0x14c(%rbp), %eax
movb %cl, -0x140(%rbp,%rax)
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x14e00
movq -0x148(%rbp), %rdi
addq $0x1, %rdi
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
leaq -0x140(%rbp), %rdx
movl -0x24(%rbp), %eax
movl %eax, %ecx
callq 0x14fc0
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rdi
callq 0x151f0
cmpl $0x0, %eax
je 0x14e88
movq -0x158(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x14fac
cmpq $0x1, -0x158(%rbp)
seta %al
andb $0x1, %al
movzbl %al, %eax
movq -0x158(%rbp), %rcx
movl -0x24(%rbp), %edx
shrl %edx
movl %edx, %edx
cmpq %rdx, %rcx
setb %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x14edf
movq -0x158(%rbp), %rax
movb %al, %cl
movq -0x148(%rbp), %rax
movb %cl, (%rax)
movq -0x158(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x14fac
cmpl $0x80, -0x24(%rbp)
jbe 0x14ef5
movq $-0x1, -0x8(%rbp)
jmp 0x14fac
movl -0x24(%rbp), %eax
addl $0x1, %eax
shrl %eax
addl $0x1, %eax
movl %eax, %eax
cmpq -0x18(%rbp), %rax
jbe 0x14f15
movq $-0x2, -0x8(%rbp)
jmp 0x14fac
movl -0x24(%rbp), %eax
subl $0x1, %eax
addl $0x80, %eax
movb %al, %cl
movq -0x148(%rbp), %rax
movb %cl, (%rax)
movl -0x24(%rbp), %eax
movb $0x0, -0x140(%rbp,%rax)
movl $0x0, -0x14c(%rbp)
movl -0x14c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x14f9b
movl -0x14c(%rbp), %eax
movzbl -0x140(%rbp,%rax), %eax
shll $0x4, %eax
movl -0x14c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl -0x140(%rbp,%rcx), %ecx
addl %ecx, %eax
movb %al, %dl
movq -0x148(%rbp), %rax
movl -0x14c(%rbp), %ecx
shrl %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x14c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x14c(%rbp)
jmp 0x14f40
movl -0x24(%rbp), %eax
addl $0x1, %eax
shrl %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax)