// File: /workspace/github_c_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %r10
leaq (%rdx,%rcx,2), %rbx
movzwl (%r8), %r9d
movl $0x1, %ebp
movl %r9d, %ecx
shlq %cl, %rbp
leaq (%rdi,%rsi), %r11
addq $-0x8, %r11
movl $0x1, %eax
leal -0x1(%r9), %ecx
movl $0x1, %esi
shll %cl, %esi
movq %r9, -0x10(%rsp)
testq %r9, %r9
movslq %esi, %rcx
cmoveq %rax, %rcx
leaq 0x4(%r8), %r14
leaq (%r8,%rcx,4), %r15
addq $0x4, %r15
movabsq $0x3fffffffc, %r12      # imm = 0x3FFFFFFFC
testb $0x1, %r10b
jne 0xa1d5
xorl %eax, %eax
xorl %esi, %esi
movq %rdi, %r13
jmp 0xa23c
movzwl -0x2(%rbx), %eax
addq $-0x2, %rbx
movslq (%r15,%rax,8), %r8
movl 0x4(%r15,%rax,8), %r9d
addq %rbp, %r9
movq %r9, %rsi
shrq $0x10, %rsi
movq %r9, %rax
shrq $0xe, %rax
andq %r12, %rax
leaq 0xaf0f(%rip), %rcx      # 0x15110
movl (%rax,%rcx), %eax
andl %ebp, %eax
movl %esi, %ecx
sarq %cl, %rbp
leaq (%r14,%rbp,2), %rcx
shrq $0x13, %r9
movl %r9d, %r13d
andl $0x1fffffff, %r13d      # imm = 0x1FFFFFFF
addq %rdi, %r13
cmpq %r11, %r13
cmovaq %r11, %r13
movzwl (%rcx,%r8,2), %ebp
movq %rax, (%rdi)
andl $0x7, %esi
shll $0x3, %r9d
movl %r9d, %ecx
shrq %cl, %rax
movq %rdi, -0x8(%rsp)
testb $0x2, %r10b
je 0xa2f2
movzwl -0x2(%rbx), %edi
movl 0x4(%r15,%rdi,8), %ecx
addq %rbp, %rcx
movq %rcx, %r8
shrq $0x10, %r8
shrq $0xe, %rcx
andq %r12, %rcx
leaq 0xaea4(%rip), %r10      # 0x15110
movl (%rcx,%r10), %r9d
andl %ebp, %r9d
movl %esi, %ecx
shlq %cl, %r9
movl %r8d, %ecx
sarq %cl, %rbp
movslq (%r15,%rdi,8), %rdi
leal (%r8,%rsi), %ecx
leaq (%r14,%rbp,2), %rsi
movzwl (%rsi,%rdi,2), %ebp
movzwl -0x4(%rbx), %edi
addq $-0x4, %rbx
movl 0x4(%r15,%rdi,8), %esi
addq %rbp, %rsi
shrq $0x10, %rsi
movl %ebp, %r8d
andl (%r10,%rsi,4), %r8d
shlq %cl, %r8
movslq (%r15,%rdi,8), %rdi
orq %rax, %r9
orq %r8, %r9
leal (%rsi,%rcx), %r8d
movl %esi, %ecx
shrq %cl, %rbp
leaq (%r14,%rbp,2), %rax
movl %r8d, %r10d
shrl $0x3, %r10d
addq %r13, %r10
cmpq %r11, %r10
cmovaq %r11, %r10
movzwl (%rax,%rdi,2), %ebp
movq %r9, (%r13)
movl %r8d, %esi
andb $-0x8, %r8b
movl %r8d, %ecx
shrq %cl, %r9
andl $0x7, %esi
movq %r9, %rax
movq %r10, %r13
cmpq %rdx, %rbx
jbe 0xa412
leaq 0xae0e(%rip), %r10      # 0x15110
movzwl -0x2(%rbx), %ecx
movslq (%r15,%rcx,8), %rdi
movl 0x4(%r15,%rcx,8), %ecx
addq %rbp, %rcx
movq %rcx, %r8
shrq $0xe, %rcx
andq %r12, %rcx
movl (%rcx,%r10), %r9d
andl %ebp, %r9d
movl %esi, %ecx
shlq %cl, %r9
shrq $0x10, %r8
orq %rax, %r9
addl %r8d, %esi
movl %r8d, %ecx
sarq %cl, %rbp
leaq (%r14,%rbp,2), %rax
movzwl (%rax,%rdi,2), %edi
movzwl -0x4(%rbx), %ebp
movl 0x4(%r15,%rbp,8), %r8d
addq %rdi, %r8
shrq $0x10, %r8
movl %edi, %eax
andl (%r10,%r8,4), %eax
movl %esi, %ecx
shlq %cl, %rax
movslq (%r15,%rbp,8), %rbp
orq %r9, %rax
addl %r8d, %esi
movl %r8d, %ecx
shrq %cl, %rdi
leaq (%r14,%rdi,2), %rcx
movzwl (%rcx,%rbp,2), %edi
movzwl -0x6(%rbx), %ebp
movl 0x4(%r15,%rbp,8), %r8d
addq %rdi, %r8
shrq $0x10, %r8
movl %edi, %r9d
andl (%r10,%r8,4), %r9d
movl %esi, %ecx
shlq %cl, %r9
movslq (%r15,%rbp,8), %rbp
orq %rax, %r9
addl %r8d, %esi
movl %r8d, %ecx
shrq %cl, %rdi
leaq (%r14,%rdi,2), %rax
movzwl (%rax,%rbp,2), %edi
movzwl -0x8(%rbx), %ebp
movl 0x4(%r15,%rbp,8), %r8d
addq %rdi, %r8
shrq $0x10, %r8
movl %edi, %eax
andl (%r10,%r8,4), %eax
movl %esi, %ecx
shlq %cl, %rax
addq $-0x8, %rbx
movslq (%r15,%rbp,8), %rbp
orq %r9, %rax
leal (%r8,%rsi), %r9d
movl %r8d, %ecx
shrq %cl, %rdi
leaq (%r14,%rdi,2), %rcx
movl %r9d, %r8d
shrl $0x3, %r8d
addq %r13, %r8
cmpq %r11, %r8
cmovaq %r11, %r8
movzwl (%rcx,%rbp,2), %ebp
movq %rax, (%r13)
movl %r9d, %esi
andb $-0x8, %r9b
movl %r9d, %ecx
shrq %cl, %rax
andl $0x7, %esi
movq %r8, %r13
cmpq %rdx, %rbx
ja 0xa302
jmp 0xa415
movq %r13, %r8
leaq 0xacf4(%rip), %rcx      # 0x15110
movq -0x10(%rsp), %rdx
andl (%rcx,%rdx,4), %ebp
movl %esi, %ecx
shlq %cl, %rbp
orq %rax, %rbp
leal (%rdx,%rsi), %ecx
movl %ecx, %eax
shrl $0x3, %eax
movq %rbp, (%r8)
addq %r8, %rax
cmpq %r11, %rax
cmovaq %r11, %rax
movl %ecx, %edx
andl $0x7, %edx
andb $-0x8, %cl
shrq %cl, %rbp
btsq %rdx, %rbp
incl %edx
movl %edx, %ecx
shrl $0x3, %ecx
addq %rax, %rcx
cmpq %r11, %rcx
cmovaq %r11, %rcx
andl $0x7, %edx
cmpl $0x1, %edx
movq -0x8(%rsp), %rsi
adcq $-0x1, %rsi
movq %rbp, (%rax)
movq %rcx, %rdx
subq %rsi, %rdx
xorl %eax, %eax
cmpq %r11, %rcx
cmovbq %rdx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq