// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/rANS_static32x16pr.c
// Function: rans_compress_O1_32x16
unsigned char *rans_compress_O1_32x16(unsigned char *in,
                                      unsigned int in_size,
                                      unsigned char *out,
                                      unsigned int *out_size) {
    unsigned char *cp, *out_end, *out_free = NULL;
    unsigned int tab_size;
    int bound = rans_compress_bound_4x16(in_size,1)-20, z;
    RansState ransN[NX];

    if (in_size < NX) // force O0 instead
        return NULL;

    if (!out) {
        *out_size = bound;
        out_free = out = malloc(*out_size);
    }
    if (!out || bound > *out_size)
        return NULL;

    if (((size_t)out)&1)
        bound--;
    out_end = out + bound;

    RansEncSymbol (*syms)[256] = htscodecs_tls_alloc(256 * (sizeof(*syms)));
    if (!syms) {
        free(out_free);
        return NULL;
    }

    cp = out;
    int shift = encode_freq1(in, in_size, 32, syms, &cp); 
    if (shift < 0) {
        free(out_free);
        htscodecs_tls_free(syms);
        return NULL;
    }
    tab_size = cp - out;

    for (z = 0; z < NX; z++)
      RansEncInit(&ransN[z]);

    uint8_t* ptr = out_end;

    int iN[NX], isz4 = in_size/NX, i;
    for (z = 0; z < NX; z++)
        iN[z] = (z+1)*isz4-2;

    unsigned char lN[NX];
    for (z = 0; z < NX; z++)
        lN[z] = in[iN[z]+1];

    // Deal with the remainder
    z = NX-1;
    lN[z] = in[in_size-1];
    for (iN[z] = in_size-2; iN[z] > NX*isz4-2; iN[z]--) {
        unsigned char c = in[iN[z]];
        RansEncPutSymbol(&ransN[z], &ptr, &syms[c][lN[z]]);
        lN[z] = c;
    }

    unsigned char *i32[NX];
    for (i = 0; i < NX; i++)
        i32[i] = &in[iN[i]];

    for (; likely(i32[0] >= in); ) {
        uint16_t *ptr16 = (uint16_t *)ptr;
        for (z = NX-1; z >= 0; z-=4) {
            RansEncSymbol *sy[4];
            int k;

            for (k = 0; k < 4; k++) {
                sy[k] = &syms[*i32[z-k]][lN[z-k]];
                lN[z-k] = *i32[z-k]--;
            }

            // RansEncPutSymbol added in-situ
            for (k = 0; k < 4; k++) {
                int c = ransN[z-k] > sy[k]->x_max;
#ifdef HTSCODECS_LITTLE_ENDIAN
                ptr16[-1] = ransN[z-k];
#else
                ((uint8_t *)&ptr16[-1])[0] = ransN[z-k];
                ((uint8_t *)&ptr16[-1])[1] = ransN[z-k]>>8;
#endif
                ptr16 -= c;
                //ransN[z-k] >>= c<<4;
                ransN[z-k] = c ? ransN[z-k]>>16 : ransN[z-k];
            }

            for (k = 0; k < 4; k++) {
                uint64_t r64 = ransN[z-k];
                uint32_t q = (r64 * sy[k]->rcp_freq) >> sy[k]->rcp_shift;
                ransN[z-k] += sy[k]->bias + q*sy[k]->cmpl_freq;
            }
        }
        ptr = (uint8_t *)ptr16;
    }

    for (z = NX-1; z>=0; z--)
        RansEncPutSymbol(&ransN[z], &ptr, &syms[0][lN[z]]);

    for (z = NX-1; z>=0; z--)
        RansEncFlush(&ransN[z], &ptr);

    *out_size = (out_end - ptr) + tab_size;

    cp = out;
    memmove(out + tab_size, ptr, out_end-ptr);

    htscodecs_tls_free(syms);
    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x300, %rsp            # imm = 0x300
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movl -0x14(%rbp), %edi
movl $0x1, %esi
callq 0x8e2d0
subl $0x14, %eax
movl %eax, -0x48(%rbp)
cmpl $0x20, -0x14(%rbp)
jae 0xc0b58
movq $0x0, -0x8(%rbp)
jmp 0xc11de
cmpq $0x0, -0x20(%rbp)
jne 0xc0b7d
movl -0x48(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x20(%rbp)
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xc0b8f
movl -0x48(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0xc0b9c
movq $0x0, -0x8(%rbp)
jmp 0xc11de
movq -0x20(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0xc0bb3
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movslq -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x100000, %edi         # imm = 0x100000
callq 0xce6a0
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
jne 0xc0bf3
movq -0x40(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0xc11de
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0xd8(%rbp), %rcx
movl $0x20, %edx
leaq -0x30(%rbp), %r8
callq 0xc11f0
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0xdc(%rbp)
jge 0xc0c48
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0xd8(%rbp), %rdi
callq 0xce8f0
movq $0x0, -0x8(%rbp)
jmp 0xc11de
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x44(%rbp)
movl $0x0, -0x4c(%rbp)
cmpl $0x20, -0x4c(%rbp)
jge 0xc0c85
movslq -0x4c(%rbp), %rax
leaq -0xd0(%rbp), %rdi
shlq $0x2, %rax
addq %rax, %rdi
callq 0xbfa40
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xc0c5d
movq -0x38(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl -0x14(%rbp), %eax
shrl $0x5, %eax
movl %eax, -0x174(%rbp)
movl $0x0, -0x4c(%rbp)
cmpl $0x20, -0x4c(%rbp)
jge 0xc0ccf
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
imull -0x174(%rbp), %ecx
subl $0x2, %ecx
movslq -0x4c(%rbp), %rax
movl %ecx, -0x170(%rbp,%rax,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xc0ca3
movl $0x0, -0x4c(%rbp)
cmpl $0x20, -0x4c(%rbp)
jge 0xc0d0a
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl -0x170(%rbp,%rcx,4), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movslq -0x4c(%rbp), %rax
movb %cl, -0x1a0(%rbp,%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xc0cd6
movl $0x1f, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %cl
movslq -0x4c(%rbp), %rax
movb %cl, -0x1a0(%rbp,%rax)
movl -0x14(%rbp), %ecx
subl $0x2, %ecx
movslq -0x4c(%rbp), %rax
movl %ecx, -0x170(%rbp,%rax,4)
movslq -0x4c(%rbp), %rax
movl -0x170(%rbp,%rax,4), %eax
movl -0x174(%rbp), %ecx
shll $0x5, %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jle 0xc0de5
movq -0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movslq -0x170(%rbp,%rcx,4), %rcx
movb (%rax,%rcx), %al
movb %al, -0x1a1(%rbp)
movslq -0x4c(%rbp), %rax
leaq -0xd0(%rbp), %rdi
shlq $0x2, %rax
addq %rax, %rdi
movq -0xd8(%rbp), %rdx
movzbl -0x1a1(%rbp), %eax
shlq $0xc, %rax
addq %rax, %rdx
movslq -0x4c(%rbp), %rax
movzbl -0x1a0(%rbp,%rax), %eax
shlq $0x4, %rax
addq %rax, %rdx
leaq -0xe8(%rbp), %rsi
callq 0xbfa60
movb -0x1a1(%rbp), %cl
movslq -0x4c(%rbp), %rax
movb %cl, -0x1a0(%rbp,%rax)
movslq -0x4c(%rbp), %rax
movl -0x170(%rbp,%rax,4), %ecx
addl $-0x1, %ecx
movl %ecx, -0x170(%rbp,%rax,4)
jmp 0xc0d3c
movl $0x0, -0x178(%rbp)
cmpl $0x20, -0x178(%rbp)
jge 0xc0e2e
movq -0x10(%rbp), %rcx
movslq -0x178(%rbp), %rax
movslq -0x170(%rbp,%rax,4), %rax
addq %rax, %rcx
movslq -0x178(%rbp), %rax
movq %rcx, -0x2b0(%rbp,%rax,8)
movl -0x178(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x178(%rbp)
jmp 0xc0def
jmp 0xc0e30
movq -0x2b0(%rbp), %rax
cmpq -0x10(%rbp), %rax
setae %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0xc10fc
movq -0xe8(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movl $0x1f, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0xc10e9
movl $0x0, -0x2e4(%rbp)
cmpl $0x4, -0x2e4(%rbp)
jge 0xc0f1d
movq -0xd8(%rbp), %rcx
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movq -0x2b0(%rbp,%rax,8), %rax
movzbl (%rax), %eax
shlq $0xc, %rax
addq %rax, %rcx
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movzbl -0x1a0(%rbp,%rax), %eax
shlq $0x4, %rax
addq %rax, %rcx
movslq -0x2e4(%rbp), %rax
movq %rcx, -0x2e0(%rbp,%rax,8)
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
movslq %eax, %rcx
movq -0x2b0(%rbp,%rcx,8), %rax
movq %rax, %rdx
addq $-0x1, %rdx
movq %rdx, -0x2b0(%rbp,%rcx,8)
movb (%rax), %cl
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movb %cl, -0x1a0(%rbp,%rax)
movl -0x2e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2e4(%rbp)
jmp 0xc0e78
movl $0x0, -0x2e4(%rbp)
cmpl $0x4, -0x2e4(%rbp)
jge 0xc1011
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movl -0xd0(%rbp,%rax,4), %eax
movslq -0x2e4(%rbp), %rcx
movq -0x2e0(%rbp,%rcx,8), %rcx
cmpl (%rcx), %eax
seta %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2e8(%rbp)
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movl -0xd0(%rbp,%rax,4), %eax
movw %ax, %cx
movq -0x2b8(%rbp), %rax
movw %cx, -0x2(%rax)
movl -0x2e8(%rbp), %ecx
movq -0x2b8(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x2b8(%rbp)
cmpl $0x0, -0x2e8(%rbp)
je 0xc0fcd
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movl -0xd0(%rbp,%rax,4), %eax
shrl $0x10, %eax
movl %eax, -0x2f8(%rbp)
jmp 0xc0fe5
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movl -0xd0(%rbp,%rax,4), %eax
movl %eax, -0x2f8(%rbp)
movl -0x2f8(%rbp), %ecx
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movl %ecx, -0xd0(%rbp,%rax,4)
movl -0x2e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2e4(%rbp)
jmp 0xc0f27
movl $0x0, -0x2e4(%rbp)
cmpl $0x4, -0x2e4(%rbp)
jge 0xc10d9
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
movl -0xd0(%rbp,%rax,4), %eax
movq %rax, -0x2f0(%rbp)
movq -0x2f0(%rbp), %rax
movslq -0x2e4(%rbp), %rcx
movq -0x2e0(%rbp,%rcx,8), %rcx
movl 0x4(%rcx), %ecx
imulq %rcx, %rax
movslq -0x2e4(%rbp), %rcx
movq -0x2e0(%rbp,%rcx,8), %rcx
movzwl 0xe(%rcx), %ecx
movl %ecx, %ecx
shrq %cl, %rax
movl %eax, -0x2f4(%rbp)
movslq -0x2e4(%rbp), %rax
movq -0x2e0(%rbp,%rax,8), %rax
movl 0x8(%rax), %ecx
movl -0x2f4(%rbp), %eax
movslq -0x2e4(%rbp), %rdx
movq -0x2e0(%rbp,%rdx,8), %rdx
movzwl 0xc(%rdx), %edx
imull %edx, %eax
addl %eax, %ecx
movl -0x4c(%rbp), %eax
subl -0x2e4(%rbp), %eax
cltq
addl -0xd0(%rbp,%rax,4), %ecx
movl %ecx, -0xd0(%rbp,%rax,4)
movl -0x2e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2e4(%rbp)
jmp 0xc101b
jmp 0xc10db
movl -0x4c(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x4c(%rbp)
jmp 0xc0e64
movq -0x2b8(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0xc0e30
movl $0x1f, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0xc114c
movslq -0x4c(%rbp), %rax
leaq -0xd0(%rbp), %rdi
shlq $0x2, %rax
addq %rax, %rdi
movq -0xd8(%rbp), %rdx
movslq -0x4c(%rbp), %rax
movzbl -0x1a0(%rbp,%rax), %eax
shlq $0x4, %rax
addq %rax, %rdx
leaq -0xe8(%rbp), %rsi
callq 0xbfa60
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xc1103
movl $0x1f, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0xc1182
movslq -0x4c(%rbp), %rax
leaq -0xd0(%rbp), %rdi
shlq $0x2, %rax
addq %rax, %rdi
leaq -0xe8(%rbp), %rsi
callq 0xbfbb0
movl -0x4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xc1153
movq -0x38(%rbp), %rax
movq -0xe8(%rbp), %rcx
subq %rcx, %rax
movl -0x44(%rbp), %ecx
addq %rcx, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movl -0x44(%rbp), %eax
addq %rax, %rdi
movq -0xe8(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0xe8(%rbp), %rax
subq %rax, %rdx
callq 0x4810
movq -0xd8(%rbp), %rdi
callq 0xce8f0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
nopl (%rax,%rax)