// File: /workspace/github_c_makefile_star2_O1/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 0x7cb0f
leaq (%r12,%r12), %rdi
callq 0x4680
movq %rax, %r14
testq %rax, %rax
je 0x7cea8
leaq 0x20(%rsp), %rdi
movl $0x840, %edx            # imm = 0x840
xorl %esi, %esi
callq 0x4260
movslq (%rbx), %rax
testq %rax, %rax
je 0x7cb4a
xorl %ecx, %ecx
movq 0x8(%rsp), %r9
movzbl (%rbp,%rcx), %edx
movq $0x1, 0x20(%rsp,%rdx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x7cb2f
jmp 0x7cd13
cmpq $0x100, %r12            # imm = 0x100
jbe 0x7ccb6
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 0x7cc4e
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 0x7cbb3
cmpq %r12, %rbx
jae 0x7cc7b
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 0x7cc53
xorl %eax, %eax
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r14
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
cmpq $0x100, %rax            # imm = 0x100
jne 0x7cc87
movq 0x8(%rsp), %r9
jmp 0x7ccf0
testq %r12, %r12
movq 0x8(%rsp), %r9
je 0x7ccf0
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 0x7ccc7
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x0, 0x20(%rsp,%rcx,8)
jle 0x7cd05
movslq %eax, %rdx
incl %eax
movb %cl, (%rbp,%rdx)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x7ccf4
movl %eax, (%rbx)
movq 0x2168(%rsp), %rax
testq %r12, %r12
je 0x7ce89
xorl %ecx, %ecx
xorl %edx, %edx
xorl %r8d, %r8d
movb (%r13,%r8), %sil
movb %sil, (%r14,%rcx)
movzbl (%r13,%r8), %edi
cmpq $0x0, 0x20(%rsp,%rdi,8)
jle 0x7cd7b
movq %r8, %rsi
cmpq %r12, %r8
jae 0x7cd5f
movq %r8, %rsi
cmpb %dil, (%r13,%rsi)
jne 0x7cd5f
incq %rsi
cmpq %rsi, %r12
jne 0x7cd4d
movq %r12, %rsi
decq %rsi
movq %rsi, %rdi
subq %r8, %rdi
cmpl $0x7f, %edi
ja 0x7cd83
movb %dil, (%r15,%rdx)
movl $0x1, %edi
jmp 0x7ce72
movq %r8, %rsi
jmp 0x7ce75
movl %edi, %r8d
cmpl $0x3fff, %edi           # imm = 0x3FFF
ja 0x7cdad
shrl $0x7, %r8d
orb $-0x80, %r8b
movb %r8b, (%r15,%rdx)
andb $0x7f, %dil
movb %dil, 0x1(%r15,%rdx)
movl $0x2, %edi
jmp 0x7ce72
cmpl $0x1fffff, %edi         # imm = 0x1FFFFF
ja 0x7cde4
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 0x7ce72
cmpl $0xfffffff, %edi        # imm = 0xFFFFFFF
ja 0x7ce28
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 0x7ce72
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 0x7cd2b
jmp 0x7ce8d
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 0x7ce93