// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movq 0x2160(%rsp), %r14
testq %r14, %r14
jne 0x7aa17
leaq (%r12,%r12), %rdi
callq 0x4680
movq %rax, %r14
testq %rax, %rax
je 0x7adb6
leaq 0x20(%rsp), %rdi
movl $0x840, %edx            # imm = 0x840
xorl %esi, %esi
callq 0x4260
movslq (%rbx), %rax
testq %rax, %rax
je 0x7aa52
xorl %ecx, %ecx
movq 0x8(%rsp), %r9
movzbl (%rbp,%rcx), %edx
movq $0x1, 0x20(%rsp,%rdx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x7aa37
jmp 0x7ac26
cmpq $0x100, %r12            # imm = 0x100
jbe 0x7abc9
movq %r14, 0x10(%rsp)
movq %rbx, 0x18(%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, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq $-0x4, %r14
je 0x7ab56
xorl %ebx, %ebx
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
cmpq %r14, %rbx
jb 0x7aabb
cmpq %r12, %rbx
jae 0x7ab83
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 %rbx, %r12
jne 0x7ab5b
xorl %eax, %eax
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r14
movdqa 0x10a0(%rsp,%rax,8), %xmm0
paddq 0x18e0(%rsp,%rax,8), %xmm0
paddq 0x860(%rsp,%rax,8), %xmm0
paddq 0x20(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0x20(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x7ab8f
movq 0x8(%rsp), %r9
jmp 0x7ac03
testq %r12, %r12
movq 0x8(%rsp), %r9
je 0x7ac03
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %eax, %eax
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
cmpq %rax, %r12
jne 0x7abda
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x0, 0x20(%rsp,%rcx,8)
jle 0x7ac18
movslq %eax, %rdx
incl %eax
movb %cl, (%rbp,%rdx)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x7ac07
movl %eax, (%rbx)
movq 0x2168(%rsp), %rax
testq %r12, %r12
je 0x7ad97
xorl %ecx, %ecx
xorl %edx, %edx
xorl %r8d, %r8d
movzbl (%r13,%r8), %edi
movb %dil, (%r14,%rcx)
cmpq $0x0, 0x20(%rsp,%rdi,8)
jle 0x7ac89
movq %r8, %rsi
cmpq %r12, %r8
jae 0x7ac6d
movq %r8, %rsi
cmpb %dil, (%r13,%rsi)
jne 0x7ac6d
incq %rsi
cmpq %rsi, %r12
jne 0x7ac5b
movq %r12, %rsi
decq %rsi
movq %rsi, %rdi
subq %r8, %rdi
cmpl $0x7f, %edi
ja 0x7ac91
movb %dil, (%r15,%rdx)
movl $0x1, %edi
jmp 0x7ad80
movq %r8, %rsi
jmp 0x7ad83
movl %edi, %r8d
cmpl $0x3fff, %edi           # imm = 0x3FFF
ja 0x7acbb
shrl $0x7, %r8d
orb $-0x80, %r8b
movb %r8b, (%r15,%rdx)
andb $0x7f, %dil
movb %dil, 0x1(%r15,%rdx)
movl $0x2, %edi
jmp 0x7ad80
cmpl $0x1fffff, %edi         # imm = 0x1FFFFF
ja 0x7acf2
shrl $0xe, %r8d
orb $-0x80, %r8b
movb %r8b, (%r15,%rdx)
movl %edi, %r8d
shrl $0x7, %r8d
orb $-0x80, %r8b
movb %r8b, 0x1(%r15,%rdx)
andb $0x7f, %dil
movb %dil, 0x2(%r15,%rdx)
movl $0x3, %edi
jmp 0x7ad80
cmpl $0xfffffff, %edi        # imm = 0xFFFFFFF
ja 0x7ad36
shrl $0x15, %r8d
orb $-0x80, %r8b
movb %r8b, (%r15,%rdx)
movl %edi, %r8d
shrl $0xe, %r8d
orb $-0x80, %r8b
movb %r8b, 0x1(%r15,%rdx)
movl %edi, %r8d
shrl $0x7, %r8d
orb $-0x80, %r8b
movb %r8b, 0x2(%r15,%rdx)
andb $0x7f, %dil
movb %dil, 0x3(%r15,%rdx)
movl $0x4, %edi
jmp 0x7ad80
shrl $0x1c, %r8d
orb $-0x80, %r8b
movb %r8b, (%r15,%rdx)
movl %edi, %r8d
shrl $0x15, %r8d
orb $-0x80, %r8b
movb %r8b, 0x1(%r15,%rdx)
movl %edi, %r8d
shrl $0xe, %r8d
orb $-0x80, %r8b
movb %r8b, 0x2(%r15,%rdx)
movl %edi, %r8d
shrl $0x7, %r8d
orb $-0x80, %r8b
movb %r8b, 0x3(%r15,%rdx)
andb $0x7f, %dil
movb %dil, 0x4(%r15,%rdx)
movl $0x5, %edi
addq %rdi, %rdx
incq %rcx
incq %rsi
movq %rsi, %r8
cmpq %r12, %rsi
jb 0x7ac3e
jmp 0x7ad9b
xorl %edx, %edx
xorl %ecx, %ecx
movq %rdx, (%r9)
movq %rcx, (%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 0x7ada1