// File: /workspace/github_c_makefile_star2_O1/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 $0x428, %rsp            # imm = 0x428
movl %r9d, %ebp
movq %r8, %rbx
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r12
leaq 0x20(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x4260
testl %ebp, %ebp
je 0x7cefe
movslq %ebp, %rax
xorl %ecx, %ecx
movzbl (%rbx,%rcx), %edx
movl $0x1, 0x20(%rsp,%rdx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x7ceea
addq %r13, %r15
movq %r14, %r8
movq %r12, %r9
addq %r12, %r8
movq 0x468(%rsp), %rax
movq (%rax), %r10
movq 0x460(%rsp), %rbp
addq %rbp, %r10
movq %r13, %r12
movq %r13, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq %r10, (%rsp)
cmpq %r8, %r9
jae 0x7d05c
cmpq %r10, %rbp
jae 0x7d058
movzbl (%r9), %eax
cmpl $0x0, 0x20(%rsp,%rax,4)
je 0x7cf78
testq %r13, %r13
je 0x7cf83
movq %r15, %rcx
subq %r12, %rcx
cmpq $0x6, %rcx
jge 0x7cf83
cmpq %r15, %r12
jae 0x7cfb4
movsbl (%r12), %ebx
testl %ebx, %ebx
js 0x7d02f
movl $0x1, %edx
jmp 0x7cfb8
movb %al, (%rbp)
incq %rbp
jmp 0x7d01e
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 0x7cfa9
cmpl $0x5, %edx
movq %rcx, %rdx
jne 0x7cf87
addq %r12, %rcx
subl %r12d, %ecx
movslq %ecx, %rdx
jmp 0x7cfb8
xorl %ebx, %ebx
xorl %edx, %edx
testl %ebx, %ebx
je 0x7d002
movl %ebx, %ecx
addq %rbp, %rcx
xorl %r14d, %r14d
cmpq %r10, %rcx
jae 0x7d00f
incl %ebx
movzbl %al, %esi
movq %rbp, %rdi
movq %rdx, 0x18(%rsp)
movq %rbx, %rdx
movq %r8, %r13
movq %r9, %r15
callq 0x4260
movq 0x18(%rsp), %rdx
movq (%rsp), %r10
movq %r15, %r9
movq %r13, %r8
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %r13
addq %rbx, %rbp
jmp 0x7d00b
movb %al, (%rbp)
incq %rbp
xorl %r14d, %r14d
movb $0x1, %al
jmp 0x7d017
movl $0x7, %r14d
xorl %eax, %eax
addq %rdx, %r12
testb %al, %al
je 0x7d024
incq %r9
xorl %r14d, %r14d
testl %r14d, %r14d
je 0x7cf31
jmp 0x7d058
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 0x7cfac
cmpq %r15, %rcx
jb 0x7d034
jmp 0x7cfac
xorl %eax, %eax
jmp 0x7d072
movq 0x460(%rsp), %rax
subq %rax, %rbp
movq 0x468(%rsp), %rcx
movq %rbp, (%rcx)
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq