// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rcx, %r14
movq %rdx, (%rsp)
movq %rsi, %r12
movq %rdi, %r13
leaq 0x10(%rsp), %rdi
xorl %r15d, %r15d
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x4260
movslq %ebp, %rax
cmpq %r15, %rax
je 0x6144f
movzbl (%rbx,%r15), %ecx
movl $0x1, 0x10(%rsp,%rcx,4)
incq %r15
jmp 0x61438
movq (%rsp), %rdi
addq %rdi, %r14
movq %r12, %r15
addq %r13, %r15
movq 0x458(%rsp), %rax
movq (%rax), %r9
movq 0x450(%rsp), %rbp
addq %rbp, %r9
movq %rdi, %r12
cmpq %r15, %r13
jae 0x61566
cmpq %r9, %rbp
jae 0x61562
movzbl (%r13), %eax
cmpl $0x0, 0x10(%rsp,%rax,4)
je 0x61532
testq %rdi, %rdi
je 0x614c3
movq %r14, %rcx
subq %r12, %rcx
cmpq $0x6, %rcx
jge 0x614c3
cmpq %r14, %r12
jae 0x61532
movsbl (%r12), %ebx
testl %ebx, %ebx
js 0x61540
pushq $0x1
popq %rcx
jmp 0x614f2
xorl %edx, %edx
xorl %ebx, %ebx
movzbl (%r12,%rdx), %esi
movl %ebx, %ecx
shll $0x7, %ecx
movl %esi, %ebx
andl $0x7f, %ebx
orl %ecx, %ebx
leaq 0x1(%rdx), %rcx
testb %sil, %sil
jns 0x614e9
cmpl $0x5, %edx
movq %rcx, %rdx
jne 0x614c7
addq %r12, %rcx
subl %r12d, %ecx
movslq %ecx, %rcx
addq %rcx, %r12
testl %ebx, %ebx
je 0x61532
movl %ebx, %ecx
addq %rbp, %rcx
cmpq %r9, %rcx
jae 0x61562
incl %ebx
movzbl %al, %esi
movq %rbp, %rdi
movq %rbx, %rdx
movq %r13, 0x8(%rsp)
movq %r14, %r13
movq %r9, %r14
callq 0x4260
movq %r14, %r9
movq %r13, %r14
movq 0x8(%rsp), %r13
movq (%rsp), %rdi
addq %rbx, %rbp
jmp 0x61538
movb %al, (%rbp)
incq %rbp
incq %r13
jmp 0x61475
xorl %ebx, %ebx
movq %r12, %rcx
movzbl (%rcx), %edx
incq %rcx
movl %ebx, %esi
shll $0x7, %esi
movl %edx, %ebx
andl $0x7f, %ebx
orl %esi, %ebx
testb %dl, %dl
jns 0x614ec
cmpq %r14, %rcx
jb 0x61545
jmp 0x614ec
xorl %eax, %eax
jmp 0x6157c
movq 0x450(%rsp), %rax
subq %rax, %rbp
movq 0x458(%rsp), %rcx
movq %rbp, (%rcx)
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq