// File: /workspace/github_c_makefile_star2_O3/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 0xb178
movl %ecx, %ebx
movq %rsi, %r15
movq %rdi, %r14
movb $0x0, 0xb(%rsp)
leal 0x1(%r8), %eax
cmpl $0x2, %eax
jb 0xaf9e
movl %eax, %ecx
leaq 0xe(%rcx), %rax
addq $-0x2, %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movl %r8d, %ecx
andq $-0x10, %rax
negq %rax
xorl %esi, %esi
movdqa 0x86a0(%rip), %xmm3     # 0x13090
movdqa 0x86a8(%rip), %xmm4     # 0x130a0
movdqa 0x86b0(%rip), %xmm5     # 0x130b0
movdqa 0x86b8(%rip), %xmm6     # 0x130c0
movdqa 0x86c0(%rip), %xmm7     # 0x130d0
movdqa 0x86c7(%rip), %xmm8     # 0x130e0
movdqa 0x86ce(%rip), %xmm9     # 0x130f0
pcmpeqd %xmm10, %xmm10
xorl %edi, %edi
movq %rdi, %xmm11
pshufd $0x44, %xmm11, %xmm11   # xmm11 = xmm11[0,1,0,1]
movdqa %xmm11, %xmm13
por %xmm8, %xmm13
movdqa %xmm0, %xmm12
pxor %xmm9, %xmm12
pxor %xmm9, %xmm13
movdqa %xmm13, %xmm15
pcmpgtd %xmm12, %xmm15
pshufd $0xa0, %xmm15, %xmm14   # xmm14 = xmm15[0,0,2,2]
pshuflw $0xe8, %xmm14, %xmm1    # xmm1 = xmm14[0,2,2,3,4,5,6,7]
pcmpeqd %xmm12, %xmm13
pshufd $0xf5, %xmm13, %xmm13   # xmm13 = xmm13[1,1,3,3]
pshuflw $0xe8, %xmm13, %xmm2    # xmm2 = xmm13[0,2,2,3,4,5,6,7]
pand %xmm1, %xmm2
pshufd $0xf5, %xmm15, %xmm15   # xmm15 = xmm15[1,1,3,3]
pshuflw $0xe8, %xmm15, %xmm1    # xmm1 = xmm15[0,2,2,3,4,5,6,7]
por %xmm2, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
movd %xmm1, %r8d
testb $0x1, %r8b
je 0xaaa5
leal (%rcx,%rsi), %r8d
movb %r8b, 0xc(%rsp,%rdi)
pand %xmm14, %xmm13
por %xmm15, %xmm13
packssdw %xmm13, %xmm13
pxor %xmm10, %xmm13
packssdw %xmm13, %xmm13
packsswb %xmm13, %xmm13
movd %xmm13, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0xaade
leal (%rcx,%rsi), %r8d
decb %r8b
movb %r8b, 0xd(%rsp,%rdi)
movdqa %xmm11, %xmm1
por %xmm7, %xmm1
pxor %xmm9, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm12, %xmm2
pshufd $0xa0, %xmm2, %xmm13    # xmm13 = xmm2[0,0,2,2]
pcmpeqd %xmm12, %xmm1
pshufd $0xf5, %xmm1, %xmm14    # xmm14 = xmm1[1,1,3,3]
movdqa %xmm14, %xmm1
pand %xmm13, %xmm1
pshufd $0xf5, %xmm2, %xmm15    # xmm15 = xmm2[1,1,3,3]
por %xmm15, %xmm1
packssdw %xmm1, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
packsswb %xmm1, %xmm1
movd %xmm1, %r8d
shrl $0x10, %r8d
testb $0x1, %r8b
je 0xab48
leal (%rcx,%rsi), %r8d
addb $-0x2, %r8b
movb %r8b, 0xe(%rsp,%rdi)
pshufhw $0x84, %xmm13, %xmm1    # xmm1 = xmm13[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm14, %xmm2    # xmm2 = xmm14[0,1,2,3,4,5,4,6]
pand %xmm1, %xmm2
pshufhw $0x84, %xmm15, %xmm1    # xmm1 = xmm15[0,1,2,3,4,5,4,6]
por %xmm2, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
packsswb %xmm1, %xmm1
movd %xmm1, %r8d
shrl $0x18, %r8d
testb $0x1, %r8b
je 0xab8b
leal (%rcx,%rsi), %r8d
addb $-0x3, %r8b
movb %r8b, 0xf(%rsp,%rdi)
movdqa %xmm11, %xmm1
por %xmm6, %xmm1
pxor %xmm9, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm12, %xmm2
pshufd $0xa0, %xmm2, %xmm14    # xmm14 = xmm2[0,0,2,2]
pshuflw $0xe8, %xmm14, %xmm15   # xmm15 = xmm14[0,2,2,3,4,5,6,7]
pcmpeqd %xmm12, %xmm1
pshufd $0xf5, %xmm1, %xmm13    # xmm13 = xmm1[1,1,3,3]
pshuflw $0xe8, %xmm13, %xmm1    # xmm1 = xmm13[0,2,2,3,4,5,6,7]
pand %xmm15, %xmm1
pshufd $0xf5, %xmm2, %xmm15    # xmm15 = xmm2[1,1,3,3]
pshuflw $0xe8, %xmm15, %xmm2    # xmm2 = xmm15[0,2,2,3,4,5,6,7]
por %xmm1, %xmm2
pxor %xmm10, %xmm2
packssdw %xmm2, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x2, %xmm1, %r8d
testb $0x1, %r8b
je 0xabfa
leal (%rcx,%rsi), %r8d
addb $-0x4, %r8b
movb %r8b, 0x10(%rsp,%rdi)
pand %xmm14, %xmm13
por %xmm15, %xmm13
packssdw %xmm13, %xmm13
pxor %xmm10, %xmm13
packssdw %xmm13, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x2, %xmm1, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0xac34
leal (%rcx,%rsi), %r8d
addb $-0x5, %r8b
movb %r8b, 0x11(%rsp,%rdi)
movdqa %xmm11, %xmm1
por %xmm5, %xmm1
pxor %xmm9, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm12, %xmm2
pshufd $0xa0, %xmm2, %xmm13    # xmm13 = xmm2[0,0,2,2]
pcmpeqd %xmm12, %xmm1
pshufd $0xf5, %xmm1, %xmm14    # xmm14 = xmm1[1,1,3,3]
movdqa %xmm14, %xmm1
pand %xmm13, %xmm1
pshufd $0xf5, %xmm2, %xmm15    # xmm15 = xmm2[1,1,3,3]
por %xmm15, %xmm1
packssdw %xmm1, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x3, %xmm1, %r8d
testb $0x1, %r8b
je 0xac9b
leal (%rcx,%rsi), %r8d
addb $-0x6, %r8b
movb %r8b, 0x12(%rsp,%rdi)
pshufhw $0x84, %xmm13, %xmm1    # xmm1 = xmm13[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm14, %xmm2    # xmm2 = xmm14[0,1,2,3,4,5,4,6]
pand %xmm1, %xmm2
pshufhw $0x84, %xmm15, %xmm1    # xmm1 = xmm15[0,1,2,3,4,5,4,6]
por %xmm2, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x3, %xmm1, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0xacdf
leal (%rcx,%rsi), %r8d
addb $-0x7, %r8b
movb %r8b, 0x13(%rsp,%rdi)
movdqa %xmm11, %xmm1
por %xmm4, %xmm1
pxor %xmm9, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm12, %xmm2
pshufd $0xa0, %xmm2, %xmm14    # xmm14 = xmm2[0,0,2,2]
pshuflw $0xe8, %xmm14, %xmm15   # xmm15 = xmm14[0,2,2,3,4,5,6,7]
pcmpeqd %xmm12, %xmm1
pshufd $0xf5, %xmm1, %xmm13    # xmm13 = xmm1[1,1,3,3]
pshuflw $0xe8, %xmm13, %xmm1    # xmm1 = xmm13[0,2,2,3,4,5,6,7]
pand %xmm15, %xmm1
pshufd $0xf5, %xmm2, %xmm15    # xmm15 = xmm2[1,1,3,3]
pshuflw $0xe8, %xmm15, %xmm2    # xmm2 = xmm15[0,2,2,3,4,5,6,7]
por %xmm1, %xmm2
pxor %xmm10, %xmm2
packssdw %xmm2, %xmm2
packsswb %xmm2, %xmm1
pextrw $0x4, %xmm1, %r8d
testb $0x1, %r8b
je 0xad4e
leal (%rcx,%rsi), %r8d
addb $-0x8, %r8b
movb %r8b, 0x14(%rsp,%rdi)
pand %xmm14, %xmm13
por %xmm15, %xmm13
packssdw %xmm13, %xmm13
pxor %xmm10, %xmm13
packssdw %xmm13, %xmm13
packsswb %xmm13, %xmm1
pextrw $0x4, %xmm1, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0xad89
leal (%rcx,%rsi), %r8d
addb $-0x9, %r8b
movb %r8b, 0x15(%rsp,%rdi)
movdqa %xmm11, %xmm1
por %xmm3, %xmm1
pxor %xmm9, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm12, %xmm2
pshufd $0xa0, %xmm2, %xmm13    # xmm13 = xmm2[0,0,2,2]
pcmpeqd %xmm12, %xmm1
pshufd $0xf5, %xmm1, %xmm14    # xmm14 = xmm1[1,1,3,3]
movdqa %xmm14, %xmm1
pand %xmm13, %xmm1
pshufd $0xf5, %xmm2, %xmm15    # xmm15 = xmm2[1,1,3,3]
por %xmm15, %xmm1
packssdw %xmm1, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x5, %xmm1, %r8d
testb $0x1, %r8b
je 0xadf0
leal (%rcx,%rsi), %r8d
addb $-0xa, %r8b
movb %r8b, 0x16(%rsp,%rdi)
pshufhw $0x84, %xmm13, %xmm1    # xmm1 = xmm13[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm14, %xmm2    # xmm2 = xmm14[0,1,2,3,4,5,4,6]
pand %xmm1, %xmm2
pshufhw $0x84, %xmm15, %xmm1    # xmm1 = xmm15[0,1,2,3,4,5,4,6]
por %xmm2, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x5, %xmm1, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0xae34
leal (%rcx,%rsi), %r8d
addb $-0xb, %r8b
movb %r8b, 0x17(%rsp,%rdi)
movdqa %xmm11, %xmm1
por 0x823f(%rip), %xmm1     # 0x13080
pxor %xmm9, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm12, %xmm2
pshufd $0xa0, %xmm2, %xmm14    # xmm14 = xmm2[0,0,2,2]
pshuflw $0xe8, %xmm14, %xmm15   # xmm15 = xmm14[0,2,2,3,4,5,6,7]
pcmpeqd %xmm12, %xmm1
pshufd $0xf5, %xmm1, %xmm13    # xmm13 = xmm1[1,1,3,3]
pshuflw $0xe8, %xmm13, %xmm1    # xmm1 = xmm13[0,2,2,3,4,5,6,7]
pand %xmm15, %xmm1
pshufd $0xf5, %xmm2, %xmm15    # xmm15 = xmm2[1,1,3,3]
pshuflw $0xe8, %xmm15, %xmm2    # xmm2 = xmm15[0,2,2,3,4,5,6,7]
por %xmm1, %xmm2
pxor %xmm10, %xmm2
packssdw %xmm2, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x6, %xmm1, %r8d
testb $0x1, %r8b
je 0xaea7
leal (%rcx,%rsi), %r8d
addb $-0xc, %r8b
movb %r8b, 0x18(%rsp,%rdi)
pand %xmm14, %xmm13
por %xmm15, %xmm13
packssdw %xmm13, %xmm13
pxor %xmm10, %xmm13
packssdw %xmm13, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x6, %xmm1, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0xaee1
leal (%rcx,%rsi), %r8d
addb $-0xd, %r8b
movb %r8b, 0x19(%rsp,%rdi)
por 0x8186(%rip), %xmm11    # 0x13070
pxor %xmm9, %xmm11
movdqa %xmm11, %xmm1
pcmpgtd %xmm12, %xmm1
pshufd $0xa0, %xmm1, %xmm13    # xmm13 = xmm1[0,0,2,2]
pcmpeqd %xmm12, %xmm11
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
movdqa %xmm11, %xmm2
pand %xmm13, %xmm2
pshufd $0xf5, %xmm1, %xmm12    # xmm12 = xmm1[1,1,3,3]
por %xmm12, %xmm2
packssdw %xmm2, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x7, %xmm1, %r8d
testb $0x1, %r8b
je 0xaf49
leal (%rcx,%rsi), %r8d
addb $-0xe, %r8b
movb %r8b, 0x1a(%rsp,%rdi)
pshufhw $0x84, %xmm13, %xmm1    # xmm1 = xmm13[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm11, %xmm2    # xmm2 = xmm11[0,1,2,3,4,5,4,6]
pand %xmm1, %xmm2
pshufhw $0x84, %xmm12, %xmm1    # xmm1 = xmm12[0,1,2,3,4,5,4,6]
por %xmm2, %xmm1
pxor %xmm10, %xmm1
packssdw %xmm1, %xmm1
packsswb %xmm1, %xmm1
pextrw $0x7, %xmm1, %r8d
shrl $0x8, %r8d
testb $0x1, %r8b
je 0xaf8d
leal (%rcx,%rsi), %r8d
addb $-0xf, %r8b
movb %r8b, 0x1b(%rsp,%rdi)
addq $0x10, %rdi
addq $-0x10, %rsi
cmpq %rsi, %rax
jne 0xaa29
testl %ebx, %ebx
je 0xb116
movl %ebx, %r12d
xorl %eax, %eax
movzbl 0x2(%rdx,%rax,4), %ecx
movb 0xb(%rsp,%rcx), %cl
movb %cl, 0x90(%rsp,%rax)
incq %rax
cmpq %rax, %r12
jne 0xafab
leaq 0x1(%r14), %r13
movl $0xc, 0x4(%rsp)
cmpl $0x1, %ebx
je 0xb11d
leaq 0x50(%rsp), %rdi
leaq 0x4(%rsp), %rsi
leaq 0x90(%rsp), %rdx
movq %r12, %rcx
callq 0x7bf2
cmpl %ebx, %eax
sete %cl
cmpl $0x1, %eax
sete %al
orb %cl, %al
jne 0xb11d
movq %r15, 0x18(%rsp)
movl 0x4(%rsp), %edx
movl $0x6, %edi
movq %r12, %rsi
callq 0x8fe3
movl %eax, %r15d
movl 0x4(%rsp), %r8d
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movl %eax, %esi
movq %r12, %rcx
callq 0x9031
cmpq $-0x9, %rax
ja 0xb175
movq %r14, 0x20(%rsp)
movq 0x18(%rsp), %rax
leaq -0x1(%rax), %rbp
movl 0x4(%rsp), %ecx
leaq 0x30(%rsp), %rdx
movq %r13, %rdi
movq %rbp, %rsi
movl %r15d, %r8d
callq 0x8cd3
movq %rax, %r14
cmpq $-0x9, %rax
ja 0xb18d
movq %rbp, 0x28(%rsp)
movl 0x4(%rsp), %edx
leaq 0x1d0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x190(%rsp), %r8
movl $0x40, %r9d
movl %r15d, %ecx
callq 0x8af8
cmpq $-0x9, %rax
ja 0xb175
leaq (%r14,%r13), %rbp
movq 0x28(%rsp), %rsi
subq %r14, %rsi
leaq 0x90(%rsp), %rdx
leaq 0x1d0(%rsp), %r8
movq %rbp, %rdi
movq %r12, %rcx
callq 0x969a
cmpq $-0x9, %rax
ja 0xb175
testq %rax, %rax
je 0xb192
addq %rax, %rbp
subq %r13, %rbp
cmpq $-0x9, %rbp
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r15
ja 0xb178
cmpq $0x2, %rbp
setb %al
movl %ebx, %ecx
shrl %ecx
cmpq %rcx, %rbp
setae %cl
orb %al, %cl
jne 0xb11d
movb %bpl, (%r14)
incq %rbp
jmp 0xb178
leaq 0x1(%r14), %r13
xorl %r12d, %r12d
movq $-0x1, %rbp
cmpl $0x80, %ebx
ja 0xb178
leal 0x1(%rbx), %eax
shrl %eax
incl %eax
movq $-0x2, %rbp
cmpq %r15, %rax
ja 0xb178
leal 0x7f(%rbx), %ecx
movb %cl, (%r14)
movb $0x0, 0x90(%rsp,%r12)
testl %ebx, %ebx
je 0xb175
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 0xb154
movq %rax, %rbp
movq %rbp, %rax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rbp
jmp 0xb178
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r15
jmp 0xb11d