// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/rle.c
// Function: hts_rle_encode
uint8_t *hts_rle_encode(uint8_t *data, uint64_t data_len,
                        uint8_t *run,  uint64_t *run_len,
                        uint8_t *rle_syms, int *rle_nsyms,
                        uint8_t *out, uint64_t *out_len) {
    uint64_t i, j, k;
    if (!out)
        if (!(out = malloc(data_len*2)))
            return NULL;

    // Two pass:  Firstly compute which symbols are worth using RLE on.
    int64_t saved[256+MAGIC] = {0};

    if (*rle_nsyms) {
        for (i = 0; i < *rle_nsyms; i++)
            saved[rle_syms[i]] = 1;
    } else {
        // Writes back to rle_syms and rle_nsyms
        rle_find_syms(data, data_len, saved, rle_syms, rle_nsyms);
    }

    // 2nd pass: perform RLE itself to out[] and run[] arrays.
    for (i = j = k = 0; i < data_len; i++) {
        out[k++] = data[i];
        if (saved[data[i]] > 0) {
            int rlen = i;
            int last = data[i];
            while (i < data_len && data[i] == last)
                i++;
            i--;
            rlen = i-rlen;

            j += var_put_u32(&run[j], NULL, rlen);
        }
    }
    
    *run_len = j;
    *out_len = k;
    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8a0, %rsp            # imm = 0x8A0
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, 0x10(%rbp)
jne 0xc7a77
movq -0x18(%rbp), %rdi
shlq %rdi
callq 0x4650
movq %rax, 0x10(%rbp)
cmpq $0x0, %rax
jne 0xc7a75
movq $0x0, -0x8(%rbp)
jmp 0xc7c26
jmp 0xc7a77
leaq -0x890(%rbp), %rdi
xorl %esi, %esi
movl $0x840, %edx            # imm = 0x840
callq 0x4250
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0xc7ad3
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
cmpq %rcx, %rax
jae 0xc7ad1
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq $0x1, -0x890(%rbp,%rax,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xc7a9b
jmp 0xc7aef
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x890(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
callq 0xc7c40
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0xc7c08
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movb (%rax,%rcx), %dl
movq 0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpq $0x0, -0x890(%rbp,%rax,8)
jle 0xc7bf5
movq -0x40(%rbp), %rax
movl %eax, -0x894(%rbp)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x898(%rbp)
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq -0x18(%rbp), %rcx
movb %al, -0x899(%rbp)
jae 0xc7b9a
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl -0x898(%rbp), %eax
sete %al
movb %al, -0x899(%rbp)
movb -0x899(%rbp), %al
testb $0x1, %al
jne 0xc7ba6
jmp 0xc7bb4
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xc7b6d
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movslq -0x894(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x894(%rbp)
movq -0x20(%rbp), %rdi
addq -0x48(%rbp), %rdi
movl -0x894(%rbp), %edx
xorl %eax, %eax
movl %eax, %esi
callq 0xc7fe0
cltq
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xc7bf7
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xc7b07
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x8a0, %rsp            # imm = 0x8A0
popq %rbp
retq
nopw %cs:(%rax,%rax)