// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/htscodecs/htscodecs/rle.c
// Function: hts_rle_decode
uint8_t *hts_rle_decode(uint8_t *lit, uint64_t lit_len,
                        uint8_t *run, uint64_t run_len,
                        uint8_t *rle_syms, int rle_nsyms,
                        uint8_t *out, uint64_t *out_len) {
    uint64_t j;
    uint8_t *run_end = run + run_len;

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

    int saved[256] = {0};
    for (j = 0; j < rle_nsyms; j++)
        saved[rle_syms[j]] = 1;

    uint8_t *lit_end = lit + lit_len;
    uint8_t *out_end = out + *out_len;
    uint8_t *outp = out;

    while (lit < lit_end) {
        if (outp >= out_end)
            goto err;

        uint8_t b = *lit;
        if (saved[b]) {
            uint32_t rlen;
            run += var_get_u32(run, run_end, &rlen);
            if (rlen) {
                if (outp + rlen >= out_end)
                    goto err;
                memset(outp, b, rlen+1);
                outp += rlen+1;
            } else {
                *outp++ = b;
            }
        } else {
            *outp++ = b;
        }
        lit++;
    }

    *out_len = outp-out;
    return out;

 err:
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movl %r9d, %ebp
movq %r8, %r13
movq %rcx, %rbx
movq %rdx, (%rsp)
movq %rsi, %r14
movq %rdi, %r12
leaq 0x10(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x4260
testl %ebp, %ebp
je 0x7ae0f
movslq %ebp, %rax
xorl %ecx, %ecx
movzbl (%r13,%rcx), %edx
movl $0x1, 0x10(%rsp,%rdx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x7adf9
movq 0x450(%rsp), %rbp
testq %r14, %r14
movq (%rsp), %rdi
jle 0x7af2e
addq %rdi, %rbx
addq %r12, %r14
movq 0x458(%rsp), %rax
movq (%rax), %r9
addq %rbp, %r9
movq %rdi, %r15
movq %rbx, 0x8(%rsp)
cmpq %r9, %rbp
jae 0x7af46
movzbl (%r12), %eax
cmpl $0x0, 0x10(%rsp,%rax,4)
je 0x7aef3
testq %rdi, %rdi
je 0x7ae87
movq %rbx, %rcx
subq %r15, %rcx
cmpq $0x6, %rcx
jge 0x7ae87
cmpq %rbx, %r15
jae 0x7aef3
movsbl (%r15), %r13d
testl %r13d, %r13d
js 0x7af07
movl $0x1, %ecx
jmp 0x7aebb
xorl %edx, %edx
xorl %r13d, %r13d
movzbl (%r15,%rdx), %esi
movl %r13d, %ecx
shll $0x7, %ecx
movl %esi, %r13d
andl $0x7f, %r13d
orl %ecx, %r13d
leaq 0x1(%rdx), %rcx
testb %sil, %sil
jns 0x7aeb2
cmpl $0x5, %edx
movq %rcx, %rdx
jne 0x7ae8c
addq %r15, %rcx
subl %r15d, %ecx
movslq %ecx, %rcx
addq %rcx, %r15
testl %r13d, %r13d
je 0x7aef3
movl %r13d, %ecx
addq %rbp, %rcx
cmpq %r9, %rcx
jae 0x7af46
incl %r13d
movzbl %al, %esi
movq %rbp, %rdi
movq %r13, %rdx
movq %r9, %rbx
callq 0x4260
movq %rbx, %r9
movq 0x8(%rsp), %rbx
movq (%rsp), %rdi
addq %r13, %rbp
jmp 0x7aef9
movb %al, (%rbp)
incq %rbp
incq %r12
cmpq %r14, %r12
jb 0x7ae40
jmp 0x7af2e
xorl %r13d, %r13d
movq %r15, %rcx
movzbl (%rcx), %edx
incq %rcx
movl %r13d, %esi
shll $0x7, %esi
movl %edx, %r13d
andl $0x7f, %r13d
orl %esi, %r13d
testb %dl, %dl
jns 0x7aeb5
cmpq %rbx, %rcx
jb 0x7af0d
jmp 0x7aeb5
movq 0x450(%rsp), %rax
subq %rax, %rbp
movq 0x458(%rsp), %rcx
movq %rbp, (%rcx)
jmp 0x7af48
xorl %eax, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq