// File: /workspace/github_c_makefile_star2_O2/Cyan4973[P]FiniteStateEntropy/programs/../lib/fseU16.c
// Function: FSE_compressU16_usingCTable
size_t FSE_compressU16_usingCTable (void* dst, size_t maxDstSize,
                              const U16*  src, size_t srcSize,
                              const FSE_CTable* ct)
{
    const U16* const istart = src;
    const U16* const iend = istart + srcSize;
    const U16* ip;

    BYTE* op = (BYTE*) dst;
    BIT_CStream_t bitC;
    FSE_CState_t CState;


    /* init */
    BIT_initCStream(&bitC, op, maxDstSize);
    FSE_initCState(&CState, ct);

    ip=iend;

    /* join to even */
    if (srcSize & 1) {
        FSE_encodeSymbol(&bitC, &CState, *--ip);
        BIT_flushBits(&bitC);
    }

    /* join to mod 4 */
    if (srcSize & 2) {
        FSE_encodeSymbol(&bitC, &CState, *--ip);
        FSE_encodeSymbol(&bitC, &CState, *--ip);
        BIT_flushBits(&bitC);
    }

    /* 2 or 4 encoding per loop */
    while (ip>istart) {
        FSE_encodeSymbol(&bitC, &CState, *--ip);

        if (sizeof(size_t)*8 < FSE_MAX_TABLELOG*2+7 )  /* This test must be static */
            BIT_flushBits(&bitC);

        FSE_encodeSymbol(&bitC, &CState, *--ip);

        if (sizeof(size_t)*8 > FSE_MAX_TABLELOG*4+7 ) {  /* This test must be static */
            FSE_encodeSymbol(&bitC, &CState, *--ip);
            FSE_encodeSymbol(&bitC, &CState, *--ip);
        }
        BIT_flushBits(&bitC);
    }

    FSE_flushCState(&bitC, &CState);
    return BIT_closeCStream(&bitC);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r14
andq $0x0, (%rsp)
andl $0x0, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
addq %rdi, %rsi
addq $-0x8, %rsi
movq %rsi, 0x20(%rsp)
movzwl (%r8), %eax
pushq $0x1
popq %r9
movq %r9, %r10
movl %eax, %ecx
shlq %cl, %r10
movq %rdx, %rbx
leal -0x1(%rax), %ecx
pushq $0x1
popq %rdx
shll %cl, %edx
leaq (%rbx,%r14,2), %r12
leaq 0x4(%r8), %rcx
testl %eax, %eax
movq %r10, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movslq %edx, %rcx
cmoveq %r9, %rcx
leaq (%r8,%rcx,4), %rcx
addq $0x4, %rcx
movq %rcx, 0x38(%rsp)
movl %eax, 0x40(%rsp)
testb $0x1, %r14b
jne 0x8918
xorl %edx, %edx
xorl %eax, %eax
jmp 0x8969
movzwl -0x2(%r12), %edx
addq $-0x2, %r12
movq %rsp, %r15
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x8aea
movl 0x8(%r15), %ecx
movl %ecx, %edi
shrl $0x3, %edi
movq 0x18(%r15), %rax
movq (%r15), %rdx
movq %rdx, (%rax)
addq %rax, %rdi
movq 0x20(%r15), %rsi
cmpq %rsi, %rdi
cmovaq %rsi, %rdi
movq %rdi, 0x18(%r15)
movl %ecx, %eax
andl $0x7, %eax
movl %eax, 0x8(%r15)
andb $-0x8, %cl
shrq %cl, %rdx
movq %rdx, (%r15)
testb $0x2, %r14b
je 0x89d4
movzwl -0x2(%r12), %edx
movq %rsp, %r14
leaq 0x28(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x8aea
movzwl -0x4(%r12), %edx
addq $-0x4, %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x8aea
movl 0x8(%r14), %ecx
movl %ecx, %edi
shrl $0x3, %edi
movq 0x18(%r14), %rax
movq (%r14), %rdx
movq %rdx, (%rax)
addq %rax, %rdi
movq 0x20(%r14), %rsi
cmpq %rsi, %rdi
cmovaq %rsi, %rdi
movq %rdi, 0x18(%r14)
movl %ecx, %eax
andl $0x7, %eax
movl %eax, 0x8(%r14)
andb $-0x8, %cl
shrq %cl, %rdx
movq %rdx, (%r14)
movq %rsp, %r14
leaq 0x28(%rsp), %r15
cmpq %rbx, %r12
jbe 0x8a6e
movzwl -0x2(%r12), %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x8aea
movzwl -0x4(%r12), %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x8aea
movzwl -0x6(%r12), %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x8aea
movzwl -0x8(%r12), %edx
addq $-0x8, %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x8aea
movl 0x8(%rsp), %ecx
movl %ecx, %edi
shrl $0x3, %edi
movq 0x18(%rsp), %rax
movq (%rsp), %rdx
movq %rdx, (%rax)
addq %rax, %rdi
movq 0x20(%rsp), %rsi
cmpq %rsi, %rdi
cmovaq %rsi, %rdi
movq %rdi, 0x18(%rsp)
movl %ecx, %eax
andl $0x7, %eax
movl %eax, 0x8(%rsp)
andb $-0x8, %cl
shrq %cl, %rdx
movq %rdx, (%rsp)
jmp 0x89dc
movl 0x28(%rsp), %r8d
movl 0x40(%rsp), %r9d
leaq 0x85e1(%rip), %rcx      # 0x11060
andl (%rcx,%r9,4), %r8d
movl %eax, %ecx
shlq %cl, %r8
orq %rdx, %r8
leal (%r9,%rax), %ecx
movl %ecx, %r9d
shrl $0x3, %r9d
addq %rdi, %r9
cmpq %rsi, %r9
cmovaq %rsi, %r9
movq %r8, (%rdi)
movl %ecx, %edx
andb $-0x8, %cl
shrq %cl, %r8
andl $0x7, %edx
btsq %rdx, %r8
incl %edx
movl %edx, %eax
shrl $0x3, %eax
movq %r8, (%r9)
addq %r9, %rax
cmpq %rsi, %rax
cmovaq %rsi, %rax
cmpq %rsi, %rax
jae 0x8adc
andl $0x7, %edx
cmpl $0x1, %edx
sbbq $-0x1, %rax
subq 0x10(%rsp), %rax
jmp 0x8ade
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq