// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/rANS_static.c
// Function: rans_uncompress_O0
static
unsigned char *rans_uncompress_O0(unsigned char *in, unsigned int in_size,
                                  unsigned int *out_size) {
    /* Load in the static tables */
    unsigned char *cp = in + 9;
    unsigned char *cp_end = in + in_size;
    const uint32_t mask = (1u << TF_SHIFT)-1;
    int i, j, rle;
    unsigned int x, y;
    unsigned int out_sz, in_sz;
    char *out_buf;
    RansState R[4];
    RansState m[4];
    uint16_t sfreq[TOTFREQ+32];
    uint16_t ssym [TOTFREQ+32]; // faster, but only needs uint8_t
    uint32_t sbase[TOTFREQ+16]; // faster, but only needs uint16_t

    if (in_size < 26) // Need at least this many bytes just to start
        return NULL;

    if (*in++ != 0) // Order-0 check
        return NULL;
    
    in_sz  = ((in[0])<<0) | ((in[1])<<8) | ((in[2])<<16) | (((uint32_t)in[3])<<24);
    out_sz = ((in[4])<<0) | ((in[5])<<8) | ((in[6])<<16) | (((uint32_t)in[7])<<24);
    if (in_sz != in_size-9)
        return NULL;

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

    // For speeding up the fuzzer only.
    // Small input can lead to large uncompressed data.
    // We reject this as it just slows things up instead of testing more code
    // paths (once we've verified a few times for large data).
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    if (out_sz > 100000)
        return NULL;
#endif

    out_buf = malloc(out_sz);
    if (!out_buf)
        return NULL;

    //fprintf(stderr, "out_sz=%d\n", out_sz);

    // Precompute reverse lookup of frequency.
    rle = x = y = 0;
    j = *cp++;
    do {
        int F, C;
        if (cp > cp_end - 16) goto cleanup; // Not enough input bytes left
        if ((F = *cp++) >= 128) {
            F &= ~128;
            F = ((F & 127) << 8) | *cp++;
        }
        C = x;

        if (x + F > TOTFREQ)
            goto cleanup;

        for (y = 0; y < F; y++) {
            ssym [y + C] = j;
            sfreq[y + C] = F;
            sbase[y + C] = y;
        }
        x += F;

        if (!rle && j+1 == *cp) {
            j = *cp++;
            rle = *cp++;
        } else if (rle) {
            rle--;
            j++;
            if (j > 255)
                goto cleanup;
        } else {
            j = *cp++;
        }
    } while(j);

    if (x < TOTFREQ-1 || x > TOTFREQ)
        goto cleanup;
    if (x != TOTFREQ) {
        // Protection against accessing uninitialised memory in the case
        // where SUM(freqs) == 4095 and not 4096.
        ssym [x] = ssym [x-1];
        sfreq[x] = sfreq[x-1];
        sbase[x] = sbase[x-1]+1;
    }

    // 16 bytes of cp here. Also why cp - 16 in above loop.
    if (cp > cp_end - 16) goto cleanup; // Not enough input bytes left

    RansDecInit(&R[0], &cp); if (R[0] < RANS_BYTE_L) goto cleanup;
    RansDecInit(&R[1], &cp); if (R[1] < RANS_BYTE_L) goto cleanup;
    RansDecInit(&R[2], &cp); if (R[2] < RANS_BYTE_L) goto cleanup;
    RansDecInit(&R[3], &cp); if (R[3] < RANS_BYTE_L) goto cleanup;

    int out_end = (out_sz&~3);
    cp_end -= 8; // within 8 for simplicity of loop below
    // 2 x likely() here harms gcc 7.5 by about 8% rate drop, but only in O2
    for (i=0; likely(i < out_end); i+=4) {
        //                              /curr code
        // gcc7  O2 513/497   562/556++ 556/547 ok
        // gcc7  O3 566/552   569/553   581/563+
        // gcc10 O2 544/538   563/547   541/537-?
        // gcc10 O3 531/519   546/530   575/546+
        // gcc11 O2 512/490   588/540   540/535 mid
        // gcc11 O3 482/471   553/541   549/535
        // gcc12 O2 533/526   544/534   539/535
        // gcc12 O3 548/533   502/497-- 553/527 ok
        // clang10  555/542   564/549   560/541
        // clang13  560/553   572/559   556/559
        m[0] = R[0] & mask;
        R[0] = sfreq[m[0]] * (R[0] >> TF_SHIFT) + sbase[m[0]];

        m[1] = R[1] & mask;
        R[1] = sfreq[m[1]] * (R[1] >> TF_SHIFT) + sbase[m[1]];

        m[2] = R[2] & mask;
        R[2] = sfreq[m[2]] * (R[2] >> TF_SHIFT) + sbase[m[2]];

        m[3] = R[3] & mask;
        R[3] = sfreq[m[3]] * (R[3] >> TF_SHIFT) + sbase[m[3]];

        // likely() here harms gcc12 -O3
        if (cp<cp_end) {
            RansDecRenorm2(&R[0], &R[1], &cp);
            RansDecRenorm2(&R[2], &R[3], &cp);
        } else {
            RansDecRenormSafe(&R[0], &cp, cp_end+8);
            RansDecRenormSafe(&R[1], &cp, cp_end+8);
            RansDecRenormSafe(&R[2], &cp, cp_end+8);
            RansDecRenormSafe(&R[3], &cp, cp_end+8);
        }

        out_buf[i+0] = ssym[m[0]];
        out_buf[i+1] = ssym[m[1]];
        out_buf[i+2] = ssym[m[2]];
        out_buf[i+3] = ssym[m[3]];
    }


    switch(out_sz&3) {
    case 3:
        out_buf[out_end + 2] = ssym[R[2] & mask];
        // fall-through
    case 2:
        out_buf[out_end + 1] = ssym[R[1] & mask];
        // fall-through
    case 1:
        out_buf[out_end] = ssym[R[0] & mask];
        // fall-through
    default:
        break;
    }
    
    *out_size = out_sz;
    return (unsigned char *)out_buf;

 cleanup:
    free(out_buf);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8150, %rsp           # imm = 0x8150
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x9, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0xfff, -0x34(%rbp)     # imm = 0xFFF
cmpl $0x1a, -0x14(%rbp)
jae 0xc603a
movq $0x0, -0x8(%rbp)
jmp 0xc6699
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0xc605e
movq $0x0, -0x8(%rbp)
jmp 0xc6699
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
shll $0x0, %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
shll $0x18, %ecx
orl %ecx, %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
shll $0x0, %eax
movq -0x10(%rbp), %rcx
movzbl 0x5(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
shll $0x18, %ecx
orl %ecx, %eax
movl %eax, -0x4c(%rbp)
movl -0x50(%rbp), %eax
movl -0x14(%rbp), %ecx
subl $0x9, %ecx
cmpl %ecx, %eax
je 0xc60e1
movq $0x0, -0x8(%rbp)
jmp 0xc6699
cmpl $0x7fffffff, -0x4c(%rbp) # imm = 0x7FFFFFFF
jb 0xc60f7
movq $0x0, -0x8(%rbp)
jmp 0xc6699
movl -0x4c(%rbp), %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xc6119
movq $0x0, -0x8(%rbp)
jmp 0xc6699
movl $0x0, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movzbl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $-0x10, %rcx
cmpq %rcx, %rax
jbe 0xc6159
jmp 0xc6688
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movzbl (%rax), %eax
movl %eax, -0x8144(%rbp)
cmpl $0x80, %eax
jl 0xc61af
movl -0x8144(%rbp), %eax
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
movl %eax, -0x8144(%rbp)
movl -0x8144(%rbp), %eax
andl $0x7f, %eax
shll $0x8, %eax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movzbl (%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x8144(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x8148(%rbp)
movl -0x44(%rbp), %eax
addl -0x8144(%rbp), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jbe 0xc61cd
jmp 0xc6688
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x8144(%rbp), %eax
jae 0xc6234
movl -0x3c(%rbp), %eax
movw %ax, %cx
movl -0x48(%rbp), %eax
addl -0x8148(%rbp), %eax
movl %eax, %eax
movw %cx, -0x4100(%rbp,%rax,2)
movl -0x8144(%rbp), %eax
movw %ax, %cx
movl -0x48(%rbp), %eax
addl -0x8148(%rbp), %eax
movl %eax, %eax
movw %cx, -0x20c0(%rbp,%rax,2)
movl -0x48(%rbp), %ecx
movl -0x48(%rbp), %eax
addl -0x8148(%rbp), %eax
movl %eax, %eax
movl %ecx, -0x8140(%rbp,%rax,4)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xc61d4
movl -0x8144(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0xc6283
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movq -0x28(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0xc6283
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movzbl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movzbl (%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0xc62c2
cmpl $0x0, -0x40(%rbp)
je 0xc62ab
movl -0x40(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0xff, -0x3c(%rbp)
jle 0xc62a9
jmp 0xc6688
jmp 0xc62c0
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movzbl (%rax), %eax
movl %eax, -0x3c(%rbp)
jmp 0xc62c2
jmp 0xc62c4
cmpl $0x0, -0x3c(%rbp)
jne 0xc6143
cmpl $0xfff, -0x44(%rbp)     # imm = 0xFFF
jb 0xc62e0
cmpl $0x1000, -0x44(%rbp)    # imm = 0x1000
jbe 0xc62e5
jmp 0xc6688
cmpl $0x1000, -0x44(%rbp)    # imm = 0x1000
je 0xc6340
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movw -0x4100(%rbp,%rax,2), %cx
movl -0x44(%rbp), %eax
movw %cx, -0x4100(%rbp,%rax,2)
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movw -0x20c0(%rbp,%rax,2), %cx
movl -0x44(%rbp), %eax
movw %cx, -0x20c0(%rbp,%rax,2)
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl -0x8140(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl -0x44(%rbp), %eax
movl %ecx, -0x8140(%rbp,%rax,4)
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $-0x10, %rcx
cmpq %rcx, %rax
jbe 0xc6356
jmp 0xc6688
leaq -0x70(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xc77a0
cmpl $0x800000, -0x70(%rbp)  # imm = 0x800000
jae 0xc6371
jmp 0xc6688
leaq -0x70(%rbp), %rdi
addq $0x4, %rdi
leaq -0x28(%rbp), %rsi
callq 0xc77a0
cmpl $0x800000, -0x6c(%rbp)  # imm = 0x800000
jae 0xc6390
jmp 0xc6688
leaq -0x70(%rbp), %rdi
addq $0x8, %rdi
leaq -0x28(%rbp), %rsi
callq 0xc77a0
cmpl $0x800000, -0x68(%rbp)  # imm = 0x800000
jae 0xc63af
jmp 0xc6688
leaq -0x70(%rbp), %rdi
addq $0xc, %rdi
leaq -0x28(%rbp), %rsi
callq 0xc77a0
cmpl $0x800000, -0x64(%rbp)  # imm = 0x800000
jae 0xc63ce
jmp 0xc6688
movl -0x4c(%rbp), %eax
andl $-0x4, %eax
movl %eax, -0x814c(%rbp)
movq -0x30(%rbp), %rax
addq $-0x8, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x814c(%rbp), %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0xc65d6
movl -0x70(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movzwl -0x20c0(%rbp,%rax,2), %eax
movl -0x70(%rbp), %ecx
shrl $0xc, %ecx
imull %ecx, %eax
movl -0x80(%rbp), %ecx
addl -0x8140(%rbp,%rcx,4), %eax
movl %eax, -0x70(%rbp)
movl -0x6c(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movzwl -0x20c0(%rbp,%rax,2), %eax
movl -0x6c(%rbp), %ecx
shrl $0xc, %ecx
imull %ecx, %eax
movl -0x7c(%rbp), %ecx
addl -0x8140(%rbp,%rcx,4), %eax
movl %eax, -0x6c(%rbp)
movl -0x68(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movzwl -0x20c0(%rbp,%rax,2), %eax
movl -0x68(%rbp), %ecx
shrl $0xc, %ecx
imull %ecx, %eax
movl -0x78(%rbp), %ecx
addl -0x8140(%rbp,%rcx,4), %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movzwl -0x20c0(%rbp,%rax,2), %eax
movl -0x64(%rbp), %ecx
shrl $0xc, %ecx
imull %ecx, %eax
movl -0x74(%rbp), %ecx
addl -0x8140(%rbp,%rcx,4), %eax
movl %eax, -0x64(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0xc64f4
leaq -0x70(%rbp), %rdi
leaq -0x70(%rbp), %rsi
addq $0x4, %rsi
leaq -0x28(%rbp), %rdx
callq 0xc7880
leaq -0x70(%rbp), %rdi
addq $0x8, %rdi
leaq -0x70(%rbp), %rsi
addq $0xc, %rsi
leaq -0x28(%rbp), %rdx
callq 0xc7880
jmp 0xc6554
leaq -0x70(%rbp), %rdi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
leaq -0x28(%rbp), %rsi
callq 0xc7950
leaq -0x70(%rbp), %rdi
addq $0x4, %rdi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
leaq -0x28(%rbp), %rsi
callq 0xc7950
leaq -0x70(%rbp), %rdi
addq $0x8, %rdi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
leaq -0x28(%rbp), %rsi
callq 0xc7950
leaq -0x70(%rbp), %rdi
addq $0xc, %rdi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
leaq -0x28(%rbp), %rsi
callq 0xc7950
movl -0x80(%rbp), %eax
movw -0x4100(%rbp,%rax,2), %ax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x7c(%rbp), %eax
movw -0x4100(%rbp,%rax,2), %ax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x78(%rbp), %eax
movw -0x4100(%rbp,%rax,2), %ax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x74(%rbp), %eax
movw -0x4100(%rbp,%rax,2), %ax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x38(%rbp)
jmp 0xc63ed
movl -0x4c(%rbp), %eax
andl $0x3, %eax
movl %eax, -0x8150(%rbp)
subl $0x1, %eax
je 0xc6651
jmp 0xc65e9
movl -0x8150(%rbp), %eax
subl $0x2, %eax
je 0xc662a
jmp 0xc65f6
movl -0x8150(%rbp), %eax
subl $0x3, %eax
jne 0xc6673
jmp 0xc6603
movl -0x68(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, %eax
movw -0x4100(%rbp,%rax,2), %ax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x814c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x6c(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, %eax
movw -0x4100(%rbp,%rax,2), %ax
movb %al, %dl
movq -0x58(%rbp), %rax
movl -0x814c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x70(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, %eax
movw -0x4100(%rbp,%rax,2), %ax
movb %al, %dl
movq -0x58(%rbp), %rax
movslq -0x814c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0xc6675
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc6699
movq -0x58(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x8150, %rsp           # imm = 0x8150
popq %rbp
retq
nopw %cs:(%rax,%rax)