// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2128, %rsp           # imm = 0x2128
movq %r9, %rbx
movq %r8, %rbp
movq %rcx, 0x10(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movq 0x2160(%rsp), %r14
testq %r14, %r14
jne 0x6109f
leaq (%r12,%r12), %rdi
callq 0x4680
movq %rax, %r14
testq %rax, %rax
je 0x613f8
leaq 0x20(%rsp), %rdi
movl $0x840, %edx            # imm = 0x840
xorl %esi, %esi
callq 0x4260
movslq (%rbx), %rax
testq %rax, %rax
je 0x610d6
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x61284
movzbl (%rbp,%rcx), %edx
movq $0x1, 0x20(%rsp,%rdx,8)
incq %rcx
jmp 0x610ba
cmpq $0x100, %r12            # imm = 0x100
jbe 0x61230
movq %rbx, 0x8(%rsp)
leaq 0x18e0(%rsp), %rdi
xorl %ebx, %ebx
movl $0x840, %edx            # imm = 0x840
xorl %esi, %esi
callq 0x4260
leaq 0x10a0(%rsp), %rdi
movl $0x840, %edx            # imm = 0x840
xorl %esi, %esi
callq 0x4260
leaq 0x860(%rsp), %rdi
movl $0x840, %edx            # imm = 0x840
xorl %esi, %esi
callq 0x4260
movq %r12, %rax
andq $-0x4, %rax
movq %rax, 0x18(%rsp)
pushq $-0x1
popq %rax
cmpq 0x18(%rsp), %rbx
jae 0x611fa
movzbl (%r13,%rbx), %edx
xorl %esi, %esi
cmpl %edx, %eax
sete %sil
movzbl 0x1(%r13,%rbx), %edi
xorl %r8d, %r8d
cmpb %dl, %dil
sete %r8b
movzbl 0x2(%r13,%rbx), %r9d
xorl %r10d, %r10d
cmpb %dil, %r9b
sete %r10b
movzbl 0x3(%r13,%rbx), %eax
xorl %r11d, %r11d
cmpb %r9b, %al
sete %r11b
movq 0x20(%rsp,%rdx,8), %rcx
leaq -0x1(%rcx,%rsi,2), %rcx
movq %rcx, 0x20(%rsp,%rdx,8)
movq 0x18e0(%rsp,%rdi,8), %rcx
leaq -0x1(%rcx,%r8,2), %rcx
movq %rcx, 0x18e0(%rsp,%rdi,8)
movq 0x10a0(%rsp,%r9,8), %rcx
leaq -0x1(%rcx,%r10,2), %rcx
movq %rcx, 0x10a0(%rsp,%r9,8)
movq 0x860(%rsp,%rax,8), %rcx
leaq (%rcx,%r11,2), %rcx
decq %rcx
movq %rcx, 0x860(%rsp,%rax,8)
addq $0x4, %rbx
jmp 0x61135
movzbl (%r13,%rbx), %ecx
xorl %edx, %edx
cmpl %ecx, %eax
sete %dl
movq 0x20(%rsp,%rcx,8), %rax
leaq (%rax,%rdx,2), %rax
decq %rax
movq %rax, 0x20(%rsp,%rcx,8)
incq %rbx
movl %ecx, %eax
cmpq %r12, %rbx
jb 0x611d7
xorl %eax, %eax
movq 0x8(%rsp), %rbx
cmpq $0x100, %rax            # imm = 0x100
je 0x61260
movq 0x10a0(%rsp,%rax,8), %rcx
addq 0x18e0(%rsp,%rax,8), %rcx
addq 0x860(%rsp,%rax,8), %rcx
addq %rcx, 0x20(%rsp,%rax,8)
incq %rax
jmp 0x61206
pushq $-0x1
popq %rcx
xorl %eax, %eax
cmpq %rax, %r12
je 0x61260
movzbl (%r13,%rax), %edx
xorl %esi, %esi
cmpl %edx, %ecx
sete %sil
movq 0x20(%rsp,%rdx,8), %rcx
leaq (%rcx,%rsi,2), %rcx
decq %rcx
movq %rcx, 0x20(%rsp,%rdx,8)
incq %rax
movl %edx, %ecx
jmp 0x61235
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x100, %rax            # imm = 0x100
je 0x61282
cmpq $0x0, 0x20(%rsp,%rax,8)
jle 0x6127d
movslq %ecx, %rdx
incl %ecx
movb %al, (%rbp,%rdx)
incq %rax
jmp 0x61264
movl %ecx, (%rbx)
movq 0x2168(%rsp), %rax
xorl %ebp, %ebp
pushq $0x1
popq %rcx
pushq $0x2
popq %rdx
pushq $0x3
popq %rsi
pushq $0x4
popq %rdi
pushq $0x5
popq %r8
xorl %r9d, %r9d
xorl %r10d, %r10d
cmpq %r12, %rbp
jae 0x613d8
movzbl (%r13,%rbp), %ebx
movb %bl, (%r14,%r10)
cmpq $0x0, 0x20(%rsp,%rbx,8)
jle 0x612d3
movq %rbp, %r11
cmpq %r11, %r12
je 0x612db
cmpb %bl, (%r13,%r11)
jne 0x612de
incq %r11
jmp 0x612c2
movq %rbp, %r11
jmp 0x613ca
movq %r12, %r11
decq %r11
movq %r11, %rbx
subq %rbp, %rbx
cmpl $0x7f, %ebx
ja 0x612f8
movb %bl, (%r15,%r9)
movq %rcx, %rbx
jmp 0x613c7
movl %ebx, %ebp
cmpl $0x3fff, %ebx           # imm = 0x3FFF
ja 0x6131d
shrl $0x7, %ebp
orb $-0x80, %bpl
movb %bpl, (%r15,%r9)
andb $0x7f, %bl
movb %bl, 0x1(%r15,%r9)
movq %rdx, %rbx
jmp 0x613c7
cmpl $0x1fffff, %ebx         # imm = 0x1FFFFF
ja 0x6134b
shrl $0xe, %ebp
orb $-0x80, %bpl
movb %bpl, (%r15,%r9)
movl %ebx, %ebp
shrl $0x7, %ebp
orb $-0x80, %bpl
movb %bpl, 0x1(%r15,%r9)
andb $0x7f, %bl
movb %bl, 0x2(%r15,%r9)
movq %rsi, %rbx
jmp 0x613c7
cmpl $0xfffffff, %ebx        # imm = 0xFFFFFFF
ja 0x61387
shrl $0x15, %ebp
orb $-0x80, %bpl
movb %bpl, (%r15,%r9)
movl %ebx, %ebp
shrl $0xe, %ebp
orb $-0x80, %bpl
movb %bpl, 0x1(%r15,%r9)
movl %ebx, %ebp
shrl $0x7, %ebp
orb $-0x80, %bpl
movb %bpl, 0x2(%r15,%r9)
andb $0x7f, %bl
movb %bl, 0x3(%r15,%r9)
movq %rdi, %rbx
jmp 0x613c7
shrl $0x1c, %ebp
orb $-0x80, %bpl
movb %bpl, (%r15,%r9)
movl %ebx, %ebp
shrl $0x15, %ebp
orb $-0x80, %bpl
movb %bpl, 0x1(%r15,%r9)
movl %ebx, %ebp
shrl $0xe, %ebp
orb $-0x80, %bpl
movb %bpl, 0x2(%r15,%r9)
movl %ebx, %ebp
shrl $0x7, %ebp
orb $-0x80, %bpl
movb %bpl, 0x3(%r15,%r9)
andb $0x7f, %bl
movb %bl, 0x4(%r15,%r9)
movq %r8, %rbx
addq %rbx, %r9
incq %r10
incq %r11
movq %r11, %rbp
jmp 0x612a4
movq 0x10(%rsp), %rcx
movq %r9, (%rcx)
movq %r10, (%rax)
movq %r14, %rax
addq $0x2128, %rsp           # imm = 0x2128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
jmp 0x613e3