// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x968, %rsp            # imm = 0x968
movq %rcx, %r15
movq %rdx, %r14
movl %esi, %r13d
movq %rdi, 0x18(%rsp)
pushq $0x1
popq %rsi
movl %r13d, %edi
callq 0x4edbc
cmpl $0x20, %r13d
jae 0x5d78b
xorl %eax, %eax
addq $0x968, %rsp            # imm = 0x968
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r12d
leal -0x14(%r12), %ebx
testq %r14, %r14
je 0x5d7a1
xorl %eax, %eax
cmpl (%r15), %ebx
ja 0x5d779
jmp 0x5d7b3
movl %ebx, (%r15)
movl %ebx, %edi
callq 0x4680
movq %rax, %r14
testq %rax, %rax
je 0x5d777
movq %rax, 0x58(%rsp)
movq %r15, 0x78(%rsp)
addl $-0x15, %r12d
movq %r14, 0x10(%rsp)
testb $0x1, %r14b
cmovel %ebx, %r12d
movq %r12, 0x50(%rsp)
movl $0x100000, %edi         # imm = 0x100000
callq 0x6412c
testq %rax, %rax
je 0x5d96e
movq %rax, %r12
movl $0x100, %edi            # imm = 0x100
movl $0x400, %esi            # imm = 0x400
callq 0x6426c
testq %rax, %rax
je 0x5dd96
movq %rax, %r15
leaq 0x140(%rsp), %rdi
movl $0x420, %edx            # imm = 0x420
xorl %esi, %esi
callq 0x4260
movl %r13d, %r14d
shrl $0x5, %r14d
movl %r13d, %ebx
movq 0x18(%rsp), %r10
addq %r10, %rbx
pushq $-0x1
popq %rbp
cmpl $0x7a120, %r13d         # imm = 0x7A120
movq %r13, 0x70(%rsp)
jbe 0x5d97d
movl $0x100, %edi            # imm = 0x100
movl $0x40c, %esi            # imm = 0x40C
callq 0x6426c
testq %rax, %rax
je 0x5dd50
leaq -0x8(%rbx), %rdx
xorl %esi, %esi
movq 0x18(%rsp), %rcx
cmpq %rdx, %rcx
jae 0x5d90c
movzbl (%rcx), %r8d
movzbl 0x1(%rcx), %r9d
movzbl 0x2(%rcx), %r10d
movzbl 0x3(%rcx), %edi
movzbl %sil, %esi
shll $0xa, %esi
addq %r15, %rsi
incl (%rsi,%r8,4)
imulq $0x40c, %r8, %rsi       # imm = 0x40C
addq %rax, %rsi
incl (%rsi,%r9,4)
shll $0xa, %r9d
addq %r15, %r9
incl (%r9,%r10,4)
imulq $0x40c, %r10, %rsi      # imm = 0x40C
addq %rax, %rsi
incl (%rsi,%rdi,4)
movzbl 0x4(%rcx), %r8d
movzbl 0x5(%rcx), %r9d
movzbl 0x6(%rcx), %r10d
movzbl 0x7(%rcx), %esi
shll $0xa, %edi
addq %r15, %rdi
incl (%rdi,%r8,4)
imulq $0x40c, %r8, %rdi       # imm = 0x40C
addq %rax, %rdi
incl (%rdi,%r9,4)
addq $0x8, %rcx
shll $0xa, %r9d
addq %r15, %r9
incl (%r9,%r10,4)
imulq $0x40c, %r10, %rdi      # imm = 0x40C
addq %rax, %rdi
incl (%rdi,%rsi,4)
jmp 0x5d862
movzbl (%rcx), %esi
incq %rcx
shll $0xa, %edx
addq %r15, %rdx
incl (%rdx,%rsi,4)
movzbl %sil, %edx
cmpq %rbx, %rcx
jb 0x5d8fd
incl 0x140(%rsp,%rdx,4)
xorl %ecx, %ecx
movq %rax, %rdx
movq %r15, %rsi
cmpq $0x100, %rcx            # imm = 0x100
je 0x5da63
xorl %edi, %edi
xorl %r8d, %r8d
cmpq $0x100, %rdi            # imm = 0x100
je 0x5d953
movl (%rsi,%rdi,4), %r9d
addl (%rdx,%rdi,4), %r9d
movl %r9d, (%rsi,%rdi,4)
addl %r9d, %r8d
incq %rdi
jmp 0x5d936
addl %r8d, 0x140(%rsp,%rcx,4)
incq %rcx
addq $0x400, %rsi            # imm = 0x400
addq $0x40c, %rdx            # imm = 0x40C
jmp 0x5d924
movq 0x58(%rsp), %rdi
callq 0x45c0
jmp 0x5d777
leaq -0x8(%rbx), %rcx
xorl %edx, %edx
movq %r10, %rax
cmpq %rcx, %rax
jae 0x5da1f
movzbl (%rax), %edi
movzbl 0x1(%rax), %r8d
movzbl 0x2(%rax), %r9d
movzbl 0x3(%rax), %esi
movzbl %dl, %edx
shll $0xa, %edx
addq %r15, %rdx
incl (%rdx,%rdi,4)
shll $0xa, %edi
addq %r15, %rdi
incl (%rdi,%r8,4)
shll $0xa, %r8d
addq %r15, %r8
incl (%r8,%r9,4)
shll $0xa, %r9d
addq %r15, %r9
incl (%r9,%rsi,4)
movzbl 0x4(%rax), %r8d
movzbl 0x5(%rax), %r9d
movzbl 0x6(%rax), %edi
movzbl 0x7(%rax), %edx
shll $0xa, %esi
addq %r15, %rsi
incl (%rsi,%r8,4)
shll $0xa, %r8d
addq %r15, %r8
incl (%r8,%r9,4)
addq $0x8, %rax
shll $0xa, %r9d
addq %r15, %r9
incl (%r9,%rdi,4)
shll $0xa, %edi
addq %r15, %rdi
incl (%rdi,%rdx,4)
jmp 0x5d986
movzbl (%rax), %edx
incq %rax
shll $0xa, %ecx
addq %r15, %rcx
incl (%rcx,%rdx,4)
movzbl %dl, %ecx
cmpq %rbx, %rax
jb 0x5da10
incl 0x140(%rsp,%rcx,4)
xorl %eax, %eax
movq %r15, %rcx
cmpq $0x100, %rax            # imm = 0x100
je 0x5da70
xorl %edx, %edx
xorl %esi, %esi
cmpq $0x100, %rdx            # imm = 0x100
je 0x5da50
addl (%rcx,%rdx,4), %esi
incq %rdx
jmp 0x5da3f
addl %esi, 0x140(%rsp,%rax,4)
incq %rax
addq $0x400, %rcx            # imm = 0x400
jmp 0x5da33
movq %rax, %rdi
callq 0x64291
movq 0x18(%rsp), %r10
pushq $0x1f
popq %rax
movl %r14d, %ecx
leaq (%r10,%rcx), %rdx
subq $0x1, %rax
jb 0x5da8c
movzbl (%rdx), %esi
incl (%r15,%rsi,4)
addq %rcx, %rdx
jmp 0x5da7a
movq %r14, 0x30(%rsp)
leaq 0x140(%rsp), %rsi
movl (%rsi), %ebp
addl $0x1f, %ebp
pushq $0x1
popq %rbx
movl %ebx, (%rsi)
movq 0x10(%rsp), %r14
leaq 0x1(%r14), %rdi
movb $0x0, (%r14)
movq %rdi, 0x48(%rsp)
callq 0x5ee3c
cltq
addq %r14, %rax
incq %rax
movq %rax, 0x8(%rsp)
leaq 0x140(%rsp), %r14
movl %ebp, (%r14)
leaq 0x560(%rsp), %rbp
movl $0x400, %edx            # imm = 0x400
movq %rbp, %rdi
xorl %esi, %esi
callq 0x4260
movq %r14, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbp, %rcx
xorl %ebp, %ebp
callq 0x4fa19
movl %eax, %r13d
movl %r13d, %ecx
shll %cl, %ebx
movl %ebx, 0x44(%rsp)
movq %r12, %rax
movq %r15, %rbx
movq %r15, 0x60(%rsp)
movl %r13d, 0x20(%rsp)
cmpq $0x100, %rbp            # imm = 0x100
je 0x5dc83
movl 0x140(%rsp,%rbp,4), %esi
testl %esi, %esi
je 0x5dc6e
movq %rax, 0x68(%rsp)
movl 0x560(%rsp,%rbp,4), %eax
movl $0x400, %ecx            # imm = 0x400
cmpl %ecx, %eax
movl $0x400, %r14d           # imm = 0x400
cmovbl %eax, %r14d
cmpl $0xa, %r13d
cmovnel %eax, %r14d
movq %rbp, %r13
shlq $0xa, %r13
addq %r15, %r13
movq %r13, %rdi
movl %r14d, %edx
callq 0x5ce27
testl %eax, %eax
js 0x5dd3b
movq %rbp, 0x38(%rsp)
movl %r14d, 0x140(%rsp,%rbp,4)
xorl %r14d, %r14d
movq 0x8(%rsp), %r15
xorl %eax, %eax
cmpq $0x100, %r14            # imm = 0x100
je 0x5dbdd
cmpl $0x0, 0x140(%rsp,%r14,4)
je 0x5dbd8
movl (%rbx,%r14,4), %esi
testl %esi, %esi
je 0x5dbcf
testl %eax, %eax
je 0x5dbbe
decl %eax
cltq
subq %rax, %r15
movb %al, (%r15)
incq %r15
movl (%rbx,%r14,4), %esi
movq %r15, %rdi
callq 0x5eeba
movl %eax, %eax
addq %rax, %r15
xorl %eax, %eax
jmp 0x5dbd8
incl %eax
movb $0x0, (%r15)
incq %r15
incq %r14
jmp 0x5db8d
testl %eax, %eax
je 0x5dbee
decl %eax
cltq
subq %rax, %r15
movb %al, (%r15)
incq %r15
movq 0x8(%rsp), %rax
movq 0x38(%rsp), %r14
subl %eax, %r15d
shlq $0x20, %r15
movl 0x140(%rsp,%r14,4), %esi
movq %r13, %rdi
movl 0x44(%rsp), %ebp
movl %ebp, %edx
callq 0x5d71a
movl %ebp, 0x140(%rsp,%r14,4)
xorl %r13d, %r13d
movq 0x68(%rsp), %rbp
xorl %r14d, %r14d
cmpq $0x100, %r13            # imm = 0x100
je 0x5dc51
movl (%rbx,%r13,4), %edx
movq %rbp, %rdi
movl %r14d, %esi
movl 0x20(%rsp), %ecx
callq 0x5cf4a
addl (%rbx,%r13,4), %r14d
incq %r13
addq $0x10, %rbp
jmp 0x5dc28
sarq $0x20, %r15
addq %r15, 0x8(%rsp)
movq 0x60(%rsp), %r15
movl 0x20(%rsp), %r13d
movq 0x38(%rsp), %rbp
movq 0x68(%rsp), %rax
incq %rbp
addq $0x400, %rbx            # imm = 0x400
addq $0x1000, %rax           # imm = 0x1000
jmp 0x5db18
movl %r13d, %eax
shlb $0x4, %al
movq 0x10(%rsp), %rcx
movb %al, (%rcx)
movq 0x8(%rsp), %r14
movq %r14, %rbx
subq %rcx, %rbx
cmpq $0x3e9, %rbx            # imm = 0x3E9
jl 0x5dd49
movl %r14d, %ebp
movq 0x48(%rsp), %rdi
subl %edi, %ebp
leaq 0xc0(%rsp), %rcx
movl %ebp, %esi
xorl %edx, %edx
callq 0x4ee61
movq %rax, %r15
testq %rax, %rax
je 0x5dd1d
movl 0xc0(%rsp), %r13d
leal 0x6(%r13), %eax
cmpq %rax, %rbx
jbe 0x5dd1d
movq 0x10(%rsp), %rax
orb $0x1, (%rax)
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5eeba
movl %eax, %r14d
addq %rbx, %r14
movq %r14, %rdi
movl %r13d, %esi
callq 0x5eeba
movl %eax, %eax
addq %r14, %rax
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x43c0
addq %r13, %r14
movq %r14, 0x8(%rsp)
movq %r15, %rdi
callq 0x45c0
movq 0x30(%rsp), %r14
movq 0x60(%rsp), %r15
movl 0x20(%rsp), %r13d
jmp 0x5dd5d
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
pushq $-0x1
popq %r13
movq 0x30(%rsp), %r14
jmp 0x5dd5d
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movl %ebp, %r13d
movq %r15, %rdi
callq 0x64291
testl %r13d, %r13d
js 0x5dd96
movslq 0x50(%rsp), %rsi
addq 0x10(%rsp), %rsi
xorl %eax, %eax
movq 0x18(%rsp), %rdx
movq 0x70(%rsp), %r13
cmpq $0x20, %rax
je 0x5ddad
movl $0x8000, 0x560(%rsp,%rax,4) # imm = 0x8000
incq %rax
jmp 0x5dd80
movq 0x58(%rsp), %rdi
callq 0x45c0
movq %r12, %rdi
callq 0x64291
jmp 0x5d777
movq %rsi, 0x28(%rsp)
leal -0x2(%r14), %eax
xorl %ecx, %ecx
cmpq $0x20, %rcx
je 0x5ddcd
movl %eax, 0xc0(%rsp,%rcx,4)
incq %rcx
addl %r14d, %eax
jmp 0x5ddb8
xorl %eax, %eax
cmpq $0x20, %rax
je 0x5dded
movslq 0xc0(%rsp,%rax,4), %rcx
movb 0x1(%rdx,%rcx), %cl
movb %cl, 0x80(%rsp,%rax)
incq %rax
jmp 0x5ddcf
movq %rsi, 0x20(%rsp)
leal -0x1(%r13), %eax
movb (%rdx,%rax), %al
leal -0x2(%r13), %ebp
andl $-0x20, %r13d
addl $-0x2, %r13d
leaq 0x28(%rsp), %r15
cmpl %r13d, %ebp
jle 0x5de41
movl %ebp, %ecx
movq 0x18(%rsp), %rdx
movzbl (%rdx,%rcx), %ebx
movl %ebx, %ecx
shll $0xc, %ecx
movzbl %al, %edx
shll $0x4, %edx
addq %r12, %rdx
addq %rcx, %rdx
leaq 0x5dc(%rsp), %rdi
movq %r15, %rsi
callq 0x5d041
decl %ebp
movl %ebx, %eax
jmp 0x5de0a
movl %ebp, 0x13c(%rsp)
movb %al, 0x9f(%rsp)
xorl %eax, %eax
movq 0x18(%rsp), %rdx
cmpq $0x20, %rax
je 0x5de74
movslq 0xc0(%rsp,%rax,4), %rcx
addq %rdx, %rcx
movq %rcx, 0x140(%rsp,%rax,8)
incq %rax
jmp 0x5de56
movq 0x28(%rsp), %rax
leaq 0x9f(%rsp), %rsi
pushq $0x1f
popq %rdi
leaq 0xa0(%rsp), %r8
cmpq %rdx, 0x140(%rsp)
jb 0x5df97
leaq 0x5dc(%rsp), %r9
movq %rsi, %r10
leaq 0x238(%rsp), %r11
movq %rdi, %r15
testq %r15, %r15
js 0x5df8d
movq %r8, %rcx
xorl %ebp, %ebp
cmpq $-0x4, %rbp
je 0x5def6
movq (%r11,%rbp,8), %rbx
movzbl (%rbx), %r13d
movzbl (%r10,%rbp), %r14d
movb %r13b, (%r10,%rbp)
shll $0xc, %r13d
shll $0x4, %r14d
addq %r12, %r14
addq %r13, %r14
movq %r14, (%rcx)
decq %rbx
movq %rbx, (%r11,%rbp,8)
decq %rbp
addq $0x8, %rcx
jmp 0x5debe
movq %r9, %rcx
xorl %ebp, %ebp
cmpq $0x4, %rbp
je 0x5df33
movl (%rcx), %ebx
movq 0xa0(%rsp,%rbp,8), %r14
movl %ebx, %r13d
shrl $0x10, %r13d
xorl %edx, %edx
cmpl (%r14), %ebx
seta %dl
movw %bx, -0x2(%rax)
cmovbel %ebx, %r13d
addl %edx, %edx
subq %rdx, %rax
movl %r13d, (%rcx)
incq %rbp
addq $-0x4, %rcx
jmp 0x5defb
movq %r9, %rbp
xorl %ebx, %ebx
cmpq $0x4, %rbx
je 0x5df78
movl (%rbp), %edx
movq 0xa0(%rsp,%rbx,8), %r14
movl 0x4(%r14), %r13d
imulq %rdx, %r13
movb 0xe(%r14), %cl
shrq %cl, %r13
movzwl 0xc(%r14), %ecx
imull %r13d, %ecx
movl 0x8(%r14), %r14d
addl %edx, %r14d
addl %ecx, %r14d
movl %r14d, (%rbp)
incq %rbx
addq $-0x4, %rbp
jmp 0x5df38
addq $-0x4, %r15
addq $-0x20, %r11
addq $-0x4, %r10
addq $-0x10, %r9
jmp 0x5deb0
movq 0x18(%rsp), %rdx
jmp 0x5de8c
leaq 0x28(%rsp), %r14
movq %rax, (%r14)
pushq $0x1f
popq %rbx
testl %ebx, %ebx
js 0x5dfcd
movl %ebx, %eax
leaq (%rsp,%rax,4), %rdi
addq $0x560, %rdi            # imm = 0x560
movzbl 0x80(%rsp,%rax), %edx
shll $0x4, %edx
addq %r12, %rdx
movq %r14, %rsi
callq 0x5d041
decl %ebx
jmp 0x5dfa2
pushq $0x1f
popq %rcx
movq 0x28(%rsp), %rsi
xorl %eax, %eax
movq 0x8(%rsp), %rdi
testl %ecx, %ecx
js 0x5dff5
movl %ecx, %edx
movl 0x560(%rsp,%rdx,4), %edx
movl %edx, -0x4(%rsi,%rax)
decl %ecx
addq $-0x4, %rax
jmp 0x5dfdc
movq 0x50(%rsp), %r8
addl %edi, %r8d
movq 0x10(%rsp), %rbx
subl %ebx, %edi
movq 0x20(%rsp), %rdx
subq %rsi, %rdx
subq %rax, %rdx
subl %esi, %r8d
subl %eax, %r8d
movq 0x78(%rsp), %rcx
movl %r8d, (%rcx)
addq %rbx, %rdi
addq %rax, %rsi
callq 0x4830
movq %r12, %rdi
callq 0x64291
movq %rbx, %rax
jmp 0x5d779