// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_uncompress_O0_RLE
static
unsigned char *arith_uncompress_O0_RLE(unsigned char *in, unsigned int in_size,
                                       unsigned char *out, unsigned int out_sz) {
    RangeCoder rc;
    int i;
    unsigned int m = in[0] ? in[0] : 256;
    unsigned char *out_free = NULL;

    if (!out)
        out_free = out = malloc(out_sz);
    if (!out)
        return NULL;

    SIMPLE_MODEL(256,_) byte_model;
    SIMPLE_MODEL(256,_init)(&byte_model, m);

    SIMPLE_MODEL(NSYM,_) *run_model =
        htscodecs_tls_alloc(NSYM * sizeof(*run_model));
    if (!run_model) {
        free(out_free);
        return NULL;
    }

    for (i = 0; i < NSYM; i++)
        SIMPLE_MODEL(NSYM,_init)(&run_model[i], MAX_RUN);

    RC_SetInput(&rc, (char *)in+1, (char *)in+in_size);
    RC_StartDecode(&rc);

    for (i = 0; i < out_sz; i++) {
        unsigned char last;
        last = out[i] = SIMPLE_MODEL(256, _decodeSymbol)(&byte_model, &rc);
        //fprintf(stderr, "lit %c\n", last);
        int run = 0, r = 0, rctx = out[i];
        do {
            r = SIMPLE_MODEL(NSYM, _decodeSymbol)(&run_model[rctx], &rc);
            if (rctx == last)
                rctx = 256;
            else
                rctx += (rctx < NSYM-1);
            //fprintf(stderr, "run %d (ctx %d, %d)\n", r, last, l);
            run += r;
        } while (r == MAX_RUN-1 && run < out_sz);
        while (run-- && i+1 < out_sz)
            out[++i] = last;
    }

    if (RC_FinishDecode(&rc) < 0) {
        htscodecs_tls_free(run_model);
        free(out_free);
        return NULL;
    }

    htscodecs_tls_free(run_model);
    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movl %ecx, %ebp
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %r15
movzbl (%rdi), %eax
testl %eax, %eax
movl $0x100, %esi            # imm = 0x100
cmovnel %eax, %esi
leaq 0x68(%rsp), %rdi
callq 0x4b089
movl $0x42030, %edi          # imm = 0x42030
callq 0x6412c
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x4afce
xorl %ebx, %ebx
cmpq $0x42030, %rbx          # imm = 0x42030
je 0x4aed1
movq 0x8(%rsp), %rax
leaq (%rax,%rbx), %rdi
callq 0x4b0da
addq $0x418, %rbx            # imm = 0x418
jmp 0x4aeb1
leaq 0x1(%r15), %rax
movl %r12d, %ecx
addq %r15, %rcx
leaq 0x28(%rsp), %rdi
movq %rax, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movq %rcx, 0x28(%rdi)
callq 0x4b357
leaq 0x1(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
movq %r14, 0x18(%rsp)
cmpl %ebp, %r12d
jae 0x4afb7
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4b3a2
movl %eax, %r13d
movq %r12, 0x20(%rsp)
movslq %r12d, %rbx
movb %r13b, (%r14,%rbx)
movzbl %r13b, %r12d
xorl %edx, %edx
movl %r12d, %ecx
movl %edx, %r15d
movslq %ecx, %r14
imulq $0x418, %r14, %rdi      # imm = 0x418
addq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4b444
movzwl %ax, %eax
xorl %ecx, %ecx
cmpl $0x101, %r14d           # imm = 0x101
setl %cl
addl %r14d, %ecx
cmpl %r12d, %r14d
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %ecx
cmpw $0x3, %ax
jne 0x4af79
leal (%r15,%rax), %edx
cmpl %ebp, %edx
jb 0x4af32
addq 0x10(%rsp), %rbx
movq 0x20(%rsp), %r12
leal 0x1(%r12), %ecx
addl %eax, %r15d
negl %r15d
xorl %eax, %eax
movl %r15d, %edx
addl %eax, %edx
je 0x4afa7
leal (%rcx,%rax), %edx
cmpl %ebp, %edx
jae 0x4afa7
movb %r13b, (%rbx,%rax)
incq %rax
jmp 0x4af90
addl %eax, %r12d
incl %r12d
movq 0x18(%rsp), %r14
jmp 0x4af02
xorl %eax, %eax
cmpl $0x0, 0x60(%rsp)
cmovsq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x64291
jmp 0x4afd1
xorl %r14d, %r14d
movq %r14, %rax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq