// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/htscodecs/htscodecs/rANS_static32x16pr.c
// Function: rans_uncompress_O0_32x16
unsigned char *rans_uncompress_O0_32x16(unsigned char *in,
                                        unsigned int in_size,
                                        unsigned char *out,
                                        unsigned int out_sz) {
    if (in_size < 16) // 4-states at least
        return NULL;

    if (out_sz >= INT_MAX)
        return NULL; // protect against some overflow cases

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    if (out_sz > 100000)
        return NULL;
#endif

    /* Load in the static tables */
    unsigned char *cp = in, *out_free = NULL;
    unsigned char *cp_end = in + in_size;
    int i;
    uint32_t s3[TOTFREQ]; // For TF_SHIFT <= 12

    if (!out)
        out_free = out = malloc(out_sz);
    if (!out)
        return NULL;

    // Precompute reverse lookup of frequency.
    uint32_t F[256] = {0}, fsum;
    int fsz = decode_freq(cp, cp_end, F, &fsum);
    if (!fsz)
        goto err;
    cp += fsz;

    normalise_freq_shift(F, fsum, TOTFREQ);

    // Build symbols; fixme, do as part of decode, see the _d variant
    if (rans_F_to_s3(F, TF_SHIFT, s3))
        goto err;

    if (cp_end - cp < NX * 4)
        goto err;

    int z;
    RansState R[NX];
    for (z = 0; z < NX; z++) {
        RansDecInit(&R[z], &cp);
        if (R[z] < RANS_BYTE_L)
            goto err;
    }

    int out_end = (out_sz&~(NX-1));
    const uint32_t mask = (1u << TF_SHIFT)-1;
    cp_end -= NX*2; // worst case for renorm bytes

    // assume NX is divisible by 4
    assert(NX%4==0);

    // Unsafe loop with no ptr overflow checking within loop itself
    for (i=0; likely(i < out_end && cp < cp_end); i+=NX) {
        for (z = 0; z < NX; z+=4) {
            uint32_t S[4];
            S[0] = s3[R[z+0] & mask];
            S[1] = s3[R[z+1] & mask];
            S[2] = s3[R[z+2] & mask];
            S[3] = s3[R[z+3] & mask];

            R[z+0] = (S[0]>>(TF_SHIFT+8)) * (R[z+0] >> TF_SHIFT)
                + ((S[0]>>8) & mask);
            R[z+1] = (S[1]>>(TF_SHIFT+8)) * (R[z+1] >> TF_SHIFT)
                + ((S[1]>>8) & mask);
            R[z+2] = (S[2]>>(TF_SHIFT+8)) * (R[z+2] >> TF_SHIFT)
                + ((S[2]>>8) & mask);
            R[z+3] = (S[3]>>(TF_SHIFT+8)) * (R[z+3] >> TF_SHIFT)
                + ((S[3]>>8) & mask);

            out[i+z+0] = S[0];
            out[i+z+1] = S[1];
            out[i+z+2] = S[2];
            out[i+z+3] = S[3];

            RansDecRenorm(&R[z+0], &cp);
            RansDecRenorm(&R[z+1], &cp);
            RansDecRenorm(&R[z+2], &cp);
            RansDecRenorm(&R[z+3], &cp);

            if (NX%8==0) {
                z += 4;
                S[0] = s3[R[z+0] & mask];
                S[1] = s3[R[z+1] & mask];
                S[2] = s3[R[z+2] & mask];
                S[3] = s3[R[z+3] & mask];

                R[z+0] = (S[0]>>(TF_SHIFT+8)) * (R[z+0] >> TF_SHIFT)
                    + ((S[0]>>8) & mask);
                R[z+1] = (S[1]>>(TF_SHIFT+8)) * (R[z+1] >> TF_SHIFT)
                    + ((S[1]>>8) & mask);
                R[z+2] = (S[2]>>(TF_SHIFT+8)) * (R[z+2] >> TF_SHIFT)
                    + ((S[2]>>8) & mask);
                R[z+3] = (S[3]>>(TF_SHIFT+8)) * (R[z+3] >> TF_SHIFT)
                    + ((S[3]>>8) & mask);

                out[i+z+0] = S[0];
                out[i+z+1] = S[1];
                out[i+z+2] = S[2];
                out[i+z+3] = S[3];

                RansDecRenorm(&R[z+0], &cp);
                RansDecRenorm(&R[z+1], &cp);
                RansDecRenorm(&R[z+2], &cp);
                RansDecRenorm(&R[z+3], &cp);
            }
        }
    }

    // Safe loop
    for (; i < out_end; i+=NX) {
        for (z = 0; z < NX; z+=4) {
            uint32_t S[4];
            S[0] = s3[R[z+0] & mask];
            S[1] = s3[R[z+1] & mask];
            S[2] = s3[R[z+2] & mask];
            S[3] = s3[R[z+3] & mask];

            R[z+0] = (S[0]>>(TF_SHIFT+8)) * (R[z+0] >> TF_SHIFT)
                + ((S[0]>>8) & mask);
            R[z+1] = (S[1]>>(TF_SHIFT+8)) * (R[z+1] >> TF_SHIFT)
                + ((S[1]>>8) & mask);
            R[z+2] = (S[2]>>(TF_SHIFT+8)) * (R[z+2] >> TF_SHIFT)
                + ((S[2]>>8) & mask);
            R[z+3] = (S[3]>>(TF_SHIFT+8)) * (R[z+3] >> TF_SHIFT)
                + ((S[3]>>8) & mask);

            out[i+z+0] = S[0];
            out[i+z+1] = S[1];
            out[i+z+2] = S[2];
            out[i+z+3] = S[3];

            RansDecRenormSafe(&R[z+0], &cp, cp_end+NX*2);
            RansDecRenormSafe(&R[z+1], &cp, cp_end+NX*2);
            RansDecRenormSafe(&R[z+2], &cp, cp_end+NX*2);
            RansDecRenormSafe(&R[z+3], &cp, cp_end+NX*2);
        }
    }

    for (z = out_sz & (NX-1); z-- > 0; )
        out[out_end + z] = s3[R[z] & mask];

    //fprintf(stderr, "    0 Decoded %d bytes\n", (int)(cp-in)); //c-size

    return out;

 err:
    free(out_free);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x44b8, %rsp           # imm = 0x44B8
cmpl $0x10, %esi
setb %al
movq %rcx, 0x20(%rsp)
cmpl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
setae %cl
orb %al, %cl
jne 0x5d231
movl %esi, %r12d
movq %rdi, %r15
xorl %ebp, %ebp
movq %rdx, 0x18(%rsp)
testq %rdx, %rdx
je 0x5d0f2
xorl %ecx, %ecx
jmp 0x5d10c
movl 0x20(%rsp), %edi
callq 0x4680
movq %rax, %rcx
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x5d231
movq %rcx, 0x10(%rsp)
movl %r12d, %r12d
leaq (%r15,%r12), %rbx
leaq 0xb0(%rsp), %r13
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
xorl %esi, %esi
callq 0x4260
movq %r15, %rdi
movq %rbx, 0x8(%rsp)
movq %rbx, %rsi
movq %r13, %rdx
callq 0x5ef6e
movslq %eax, %r13
addq %r15, %r13
xorl %r14d, %r14d
cmpq $0x400, %r14            # imm = 0x400
je 0x5d187
cmpl $0x0, 0xb0(%rsp,%r14)
je 0x5d181
leaq (%rsp,%r14), %rbx
addq $0xb0, %rbx
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x5edb6
cltq
addq %rax, %r13
addl (%rbx), %ebp
addq $0x4, %r14
jmp 0x5d14b
subq %r15, %r13
testl %r13d, %r13d
je 0x5d227
movslq %r13d, %rbx
leaq 0xb0(%rsp), %rdi
movl %ebp, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x5d71a
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x100, %rax            # imm = 0x100
je 0x5d1f0
movl 0xb0(%rsp,%rax,4), %edx
movl $0x1000, %esi           # imm = 0x1000
subl %ecx, %esi
leal -0x1(%rdx), %edi
cmpl %esi, %edi
jae 0x5d1eb
movl %edx, %esi
shll $0x14, %esi
addl %eax, %esi
subl $0x1, %edx
jb 0x5d1eb
movslq %ecx, %rcx
movl %esi, 0x4b0(%rsp,%rcx,4)
incl %ecx
addl $0x100, %esi            # imm = 0x100
jmp 0x5d1d2
incq %rax
jmp 0x5d1ae
cmpl $0x1000, %ecx           # imm = 0x1000
jne 0x5d227
subq %rbx, %r12
cmpq $0x80, %r12
jl 0x5d227
addq %rbx, %r15
xorl %eax, %eax
cmpq $0x80, %rax
je 0x5d245
movl (%r15,%rax), %ecx
movl %ecx, 0x30(%rsp,%rax)
cmpl $0x8000, %ecx           # imm = 0x8000
jb 0x5d227
addq $0x4, %rax
jmp 0x5d209
movq 0x10(%rsp), %rdi
callq 0x45c0
xorl %eax, %eax
addq $0x44b8, %rsp           # imm = 0x44B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rcx
andl $0x7fffffe0, %ecx       # imm = 0x7FFFFFE0
movq %rcx, 0x10(%rsp)
movq 0x8(%rsp), %rcx
addq $-0x40, %rcx
movq %rcx, 0x28(%rsp)
movq 0x18(%rsp), %rcx
leaq 0x3(%rcx), %rsi
leaq 0x7(%rcx), %r9
addq %rax, %r15
xorl %edi, %edi
movl $0xfff, %r10d           # imm = 0xFFF
cmpq 0x10(%rsp), %rdi
jae 0x5d6d3
cmpq 0x28(%rsp), %r15
jae 0x5d6d3
xorl %r11d, %r11d
cmpq $0x1f, %r11
ja 0x5d52f
movl 0x30(%rsp,%r11,4), %ecx
movl 0x34(%rsp,%r11,4), %ebp
movl %ecx, %eax
andl %r10d, %eax
movl 0x4b0(%rsp,%rax,4), %r8d
movl %ebp, %eax
andl %r10d, %eax
movl 0x4b0(%rsp,%rax,4), %r12d
movl 0x38(%rsp,%r11,4), %edx
movl %edx, %eax
andl %r10d, %eax
movl 0x4b0(%rsp,%rax,4), %r14d
movl 0x3c(%rsp,%r11,4), %eax
movl %eax, %ebx
andl %r10d, %ebx
movl 0x4b0(%rsp,%rbx,4), %r13d
movl %r8d, %ebx
movb %r8b, -0x7(%r9,%r11)
shrl $0x14, %r8d
shrl $0xc, %ecx
imull %r8d, %ecx
shrl $0x8, %ebx
andl %r10d, %ebx
addl %ecx, %ebx
movl %r12d, %ecx
movb %r12b, -0x6(%r9,%r11)
shrl $0x14, %r12d
shrl $0xc, %ebp
imull %r12d, %ebp
shrl $0x8, %ecx
andl %r10d, %ecx
addl %ebp, %ecx
movl %r14d, %r8d
movb %r14b, -0x5(%r9,%r11)
shrl $0x14, %r14d
shrl $0xc, %edx
imull %r14d, %edx
shrl $0x8, %r8d
andl %r10d, %r8d
addl %edx, %r8d
movl %r13d, %ebp
movb %r13b, -0x4(%r9,%r11)
shrl $0x14, %r13d
shrl $0xc, %eax
imull %r13d, %eax
shrl $0x8, %ebp
andl %r10d, %ebp
addl %eax, %ebp
movzwl (%r15), %eax
movl %ebx, %edx
shll $0x10, %edx
orl %eax, %edx
xorl %eax, %eax
cmpl $0x8000, %ebx           # imm = 0x8000
cmovbl %edx, %ebx
leaq 0x2(%r15), %rax
cmovbq %rax, %r15
movl %ebx, 0x30(%rsp,%r11,4)
movzwl (%r15), %eax
movl %ecx, %edx
shll $0x10, %edx
orl %eax, %edx
xorl %eax, %eax
cmpl $0x8000, %ecx           # imm = 0x8000
cmovbl %edx, %ecx
leaq 0x2(%r15), %rax
cmovbq %rax, %r15
movl %ecx, 0x34(%rsp,%r11,4)
movzwl (%r15), %eax
movl %r8d, %edx
shll $0x10, %edx
orl %eax, %edx
xorl %eax, %eax
cmpl $0x8000, %r8d           # imm = 0x8000
cmovbl %edx, %r8d
leaq 0x2(%r15), %rax
cmovbq %rax, %r15
movl %r8d, 0x38(%rsp,%r11,4)
movzwl (%r15), %eax
movl %ebp, %edx
shll $0x10, %edx
orl %eax, %edx
xorl %eax, %eax
cmpl $0x8000, %ebp           # imm = 0x8000
cmovbl %edx, %ebp
leaq 0x2(%r15), %rax
cmovbq %rax, %r15
movl %ebp, 0x3c(%rsp,%r11,4)
movl 0x40(%rsp,%r11,4), %r14d
movl 0x44(%rsp,%r11,4), %ebp
movl %r14d, %eax
andl %r10d, %eax
movl 0x4b0(%rsp,%rax,4), %r8d
movl %ebp, %eax
andl %r10d, %eax
movl 0x4b0(%rsp,%rax,4), %r12d
movl 0x48(%rsp,%r11,4), %edx
movl %edx, %eax
andl %r10d, %eax
movl 0x4b0(%rsp,%rax,4), %ecx
movl 0x4c(%rsp,%r11,4), %eax
movl %eax, %ebx
andl %r10d, %ebx
movl 0x4b0(%rsp,%rbx,4), %r13d
movl %r8d, %ebx
movb %r8b, -0x3(%r9,%r11)
shrl $0x14, %r8d
shrl $0xc, %r14d
imull %r8d, %r14d
shrl $0x8, %ebx
andl %r10d, %ebx
addl %r14d, %ebx
movl %r12d, %r8d
movb %r12b, -0x2(%r9,%r11)
shrl $0x14, %r12d
shrl $0xc, %ebp
imull %r12d, %ebp
shrl $0x8, %r8d
andl %r10d, %r8d
addl %ebp, %r8d
movl %ecx, %ebp
movb %cl, -0x1(%r9,%r11)
shrl $0x14, %ecx
shrl $0xc, %edx
imull %ecx, %edx
shrl $0x8, %ebp
andl %r10d, %ebp
addl %edx, %ebp
movl %r13d, %ecx
movb %r13b, (%r9,%r11)
shrl $0x14, %r13d
shrl $0xc, %eax
imull %r13d, %eax
shrl $0x8, %ecx
andl %r10d, %ecx
addl %eax, %ecx
movzwl (%r15), %eax
movl %ebx, %edx
shll $0x10, %edx
orl %eax, %edx
xorl %eax, %eax
cmpl $0x8000, %ebx           # imm = 0x8000
cmovbl %edx, %ebx
leaq 0x2(%r15), %rax
cmovbq %rax, %r15
movl %ebx, 0x40(%rsp,%r11,4)
movzwl (%r15), %eax
movl %r8d, %edx
shll $0x10, %edx
orl %eax, %edx
xorl %eax, %eax
cmpl $0x8000, %r8d           # imm = 0x8000
cmovbl %edx, %r8d
leaq 0x2(%r15), %rax
cmovbq %rax, %r15
movl %r8d, 0x44(%rsp,%r11,4)
movzwl (%r15), %eax
movl %ebp, %edx
shll $0x10, %edx
orl %eax, %edx
xorl %eax, %eax
cmpl $0x8000, %ebp           # imm = 0x8000
cmovbl %edx, %ebp
leaq 0x2(%r15), %rax
cmovbq %rax, %r15
movl %ebp, 0x48(%rsp,%r11,4)
movzwl (%r15), %eax
movl %ecx, %edx
shll $0x10, %edx
orl %eax, %edx
xorl %eax, %eax
cmpl $0x8000, %ecx           # imm = 0x8000
cmovbl %edx, %ecx
leaq 0x2(%r15), %rax
cmovbq %rax, %r15
movl %ecx, 0x4c(%rsp,%r11,4)
addq $0x8, %r11
jmp 0x5d294
addq $0x20, %rdi
addq $0x20, %rsi
addq $0x20, %r9
jmp 0x5d27b
xorl %eax, %eax
cmpq $0x1f, %rax
ja 0x5d6cb
movl 0x30(%rsp,%rax,4), %r9d
movl 0x34(%rsp,%rax,4), %r8d
movl $0xfff, %r11d           # imm = 0xFFF
movl %r9d, %ecx
andl %r11d, %ecx
movl 0x4b0(%rsp,%rcx,4), %r10d
movl %r8d, %ecx
andl %r11d, %ecx
movl 0x4b0(%rsp,%rcx,4), %ebx
movl 0x38(%rsp,%rax,4), %edx
movl %edx, %ecx
andl %r11d, %ecx
movl 0x4b0(%rsp,%rcx,4), %ebp
movl 0x3c(%rsp,%rax,4), %r12d
movl %r12d, %ecx
andl %r11d, %ecx
movl 0x4b0(%rsp,%rcx,4), %r14d
movl %r10d, %ecx
shrl $0x14, %ecx
shrl $0xc, %r9d
imull %ecx, %r9d
movl %r10d, %ecx
shrl $0x8, %ecx
andl %r11d, %ecx
addl %r9d, %ecx
movl %ecx, 0x30(%rsp,%rax,4)
movl %ebx, %r9d
shrl $0x14, %r9d
shrl $0xc, %r8d
imull %r9d, %r8d
movl %ebx, %r9d
shrl $0x8, %r9d
andl %r11d, %r9d
addl %r8d, %r9d
movl %r9d, 0x34(%rsp,%rax,4)
movl %ebp, %r8d
shrl $0x14, %r8d
shrl $0xc, %edx
imull %r8d, %edx
movl %ebp, %r8d
shrl $0x8, %r8d
andl %r11d, %r8d
addl %edx, %r8d
movl %r8d, 0x38(%rsp,%rax,4)
movl %r14d, %edx
shrl $0x14, %edx
shrl $0xc, %r12d
imull %edx, %r12d
movl %r14d, %edx
shrl $0x8, %edx
andl %r11d, %edx
addl %r12d, %edx
movl %edx, 0x3c(%rsp,%rax,4)
movb %r10b, -0x3(%rsi,%rax)
movb %bl, -0x2(%rsi,%rax)
movb %bpl, -0x1(%rsi,%rax)
movb %r14b, (%rsi,%rax)
cmpl $0x7fff, %ecx           # imm = 0x7FFF
ja 0x5d64e
leaq 0x1(%r15), %r10
cmpq 0x8(%rsp), %r10
jae 0x5d64e
movzwl (%r15), %r10d
shll $0x10, %ecx
orl %r10d, %ecx
addq $0x2, %r15
movl %ecx, 0x30(%rsp,%rax,4)
cmpl $0x7fff, %r9d           # imm = 0x7FFF
ja 0x5d676
leaq 0x1(%r15), %rcx
cmpq 0x8(%rsp), %rcx
jae 0x5d676
movzwl (%r15), %ecx
shll $0x10, %r9d
orl %ecx, %r9d
addq $0x2, %r15
movl %r9d, 0x34(%rsp,%rax,4)
cmpl $0x7fff, %r8d           # imm = 0x7FFF
ja 0x5d69e
leaq 0x1(%r15), %rcx
cmpq 0x8(%rsp), %rcx
jae 0x5d69e
movzwl (%r15), %ecx
shll $0x10, %r8d
orl %ecx, %r8d
addq $0x2, %r15
movl %r8d, 0x38(%rsp,%rax,4)
cmpl $0x7fff, %edx           # imm = 0x7FFF
ja 0x5d6c2
leaq 0x1(%r15), %rcx
cmpq 0x8(%rsp), %rcx
jae 0x5d6c2
movzwl (%r15), %ecx
shll $0x10, %edx
orl %ecx, %edx
addq $0x2, %r15
movl %edx, 0x3c(%rsp,%rax,4)
addq $0x4, %rax
jmp 0x5d542
addq $0x20, %rdi
addq $0x20, %rsi
cmpq 0x10(%rsp), %rdi
jb 0x5d540
movq 0x20(%rsp), %rdi
andl $0x1f, %edi
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax), %rsi
decq %rsi
movl $0xfff, %ecx            # imm = 0xFFF
testq %rdi, %rdi
jle 0x5d233
movl 0x2c(%rsp,%rdi,4), %edx
andl %ecx, %edx
movb 0x4b0(%rsp,%rdx,4), %dl
movb %dl, (%rsi,%rdi)
decq %rdi
jmp 0x5d6fc