// File: /workspace/github_c_makefile_star2_O3/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 $0x458, %rsp            # imm = 0x458
movq %rcx, 0x18(%rsp)
movq %rdx, %r14
movl %esi, %ebx
movq %rdi, %r12
movzbl (%rdi), %ecx
testl %ecx, %ecx
movl $0x100, %eax            # imm = 0x100
cmovnel %ecx, %eax
testl %eax, %eax
je 0x5b6cc
movl %eax, %edx
xorl %esi, %esi
movw %si, 0x52(%rsp,%rsi,4)
movw $0x1, 0x50(%rsp,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x5b6b2
testl %ecx, %ecx
jne 0x5b6ce
jmp 0x5b6e8
xorl %ecx, %ecx
movl %ecx, %ecx
movw %cx, 0x52(%rsp,%rcx,4)
movw $0x0, 0x50(%rsp,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x5b6d0
movl %eax, 0x48(%rsp)
movl $0xffef, %eax           # imm = 0xFFEF
movl %eax, 0x4c(%rsp)
movl %eax, 0x454(%rsp)
movw $0x0, 0x450(%rsp)
movl $0x42030, %edi          # imm = 0x42030
callq 0x7e144
testq %rax, %rax
je 0x5bb45
movq %rax, %r15
addq $0x1a, %rax
xorl %ecx, %ecx
movaps 0x40307(%rip), %xmm0    # 0x9ba30
movabsq $0xffef00000004, %rdx   # imm = 0xFFEF00000004
movq 0x18(%rsp), %r10
imulq $0x418, %rcx, %rdi      # imm = 0x418
leaq (%r15,%rdi), %rsi
movups %xmm0, 0x8(%r15,%rdi)
xorl %edi, %edi
leal 0x4(%rdi), %r8d
movw %r8w, (%rax,%rdi,4)
movw $0x0, -0x2(%rax,%rdi,4)
incq %rdi
cmpq $0xfe, %rdi
jne 0x5b74b
movq %rdx, (%rsi)
movl $0xffef, 0x414(%rsi)    # imm = 0xFFEF
movw $0x0, 0x410(%rsi)
incq %rcx
addq $0x418, %rax            # imm = 0x418
cmpq $0x102, %rcx            # imm = 0x102
jne 0x5b738
movl %ebx, %eax
movl %ebx, %ebx
addq %r12, %rbx
xorl %ebp, %ebp
movq %rbx, %r13
cmpl $0x6, %eax
jb 0x5b7c2
xorl %ebp, %ebp
movl $0x1, %eax
movl %ebp, %ecx
shll $0x8, %ecx
movzbl (%r12,%rax), %ebp
orl %ecx, %ebp
incq %rax
cmpl $0x6, %eax
jne 0x5b7a7
addq $0x6, %r12
movq %r12, %r13
testl %r10d, %r10d
je 0x5bb3b
leal -0x2(%r10), %eax
movl %eax, 0x28(%rsp)
leaq 0xc(%r15), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x10(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0x0, 0xc(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x30(%rsp)
movl 0x48(%rsp), %esi
leal -0x1(%rsi), %eax
cmpl %r12d, %eax
jae 0x5b828
xorl %ecx, %ecx
movl %r12d, %eax
xorl %edx, %edx
divl %esi
movl %eax, %r12d
movl %ebp, %eax
xorl %edx, %edx
divl %r12d
cmpl $0xffef, %eax           # imm = 0xFFEF
jbe 0x5b82a
jmp 0x5b912
xorl %eax, %eax
xorl %r8d, %r8d
movq $-0x4, %rdx
movl %r8d, %ecx
movzwl 0x54(%rsp,%rdx), %edi
leal (%rcx,%rdi), %r8d
addq $0x4, %rdx
cmpl %eax, %r8d
jbe 0x5b834
cmpq $0x400, %rdx            # imm = 0x400
jle 0x5b859
xorl %ecx, %ecx
jmp 0x5b912
imull %r12d, %ecx
subl %ecx, %ebp
imull %edi, %r12d
cmpl $0xffffff, %r12d        # imm = 0xFFFFFF
ja 0x5b89f
cmpq %rbx, %r13
jae 0x5b897
movl %ebp, %eax
shll $0x8, %eax
movzbl (%r13), %ebp
incq %r13
orl %eax, %ebp
movl %r12d, %eax
shll $0x8, %eax
cmpl $0x10000, %r12d         # imm = 0x10000
movl %eax, %r12d
jb 0x5b86c
movl %eax, %r12d
jmp 0x5b89f
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %edi
movw %di, 0x50(%rsp,%rdx)
addl $0x10, %esi
movl %esi, 0x48(%rsp)
cmpl $0xfff0, %esi           # imm = 0xFFF0
jb 0x5b8f4
movl $0x0, 0x48(%rsp)
movzwl 0x50(%rsp), %eax
testw %ax, %ax
je 0x5b8f4
xorl %ecx, %ecx
leaq 0x54(%rsp), %rsi
movzwl %ax, %edi
shrl %edi
subl %edi, %eax
movw %ax, -0x4(%rsi)
movzwl %ax, %eax
addl %eax, %ecx
movzwl (%rsi), %eax
addq $0x4, %rsi
testw %ax, %ax
jne 0x5b8cf
movl %ecx, 0x48(%rsp)
movzwl 0x50(%rsp,%rdx), %edi
movzwl 0x52(%rsp,%rdx), %ecx
cmpw 0x4c(%rsp,%rdx), %di
jbe 0x5b912
movl 0x4c(%rsp,%rdx), %eax
movl %eax, 0x50(%rsp,%rdx)
movw %di, 0x4c(%rsp,%rdx)
movw %cx, 0x4e(%rsp,%rdx)
movslq 0x10(%rsp), %rax
movb %cl, (%r14,%rax)
movl %ecx, 0x2c(%rsp)
movzbl %cl, %edi
xorl %ecx, %ecx
movl %edi, %r8d
movl %ecx, %esi
movslq %r8d, %rax
imulq $0x418, %rax, %r9       # imm = 0x418
movl (%r15,%r9), %r11d
leal -0x1(%r11), %eax
cmpl %r12d, %eax
jae 0x5b961
xorl %r14d, %r14d
movl %r12d, %eax
xorl %edx, %edx
divl %r11d
movl %eax, %r12d
movl %ebp, %eax
xorl %edx, %edx
divl %r12d
cmpl $0xffef, %eax           # imm = 0xFFEF
jbe 0x5b963
jmp 0x5ba6f
xorl %eax, %eax
leaq (%r15,%r9), %rdx
xorl %r15d, %r15d
movq $-0x4, %r10
movl %r15d, %r14d
movzwl 0xc(%rdx,%r10), %ecx
leal (%r14,%rcx), %r15d
addq $0x4, %r10
cmpl %eax, %r15d
jbe 0x5b971
cmpq $0x408, %r10            # imm = 0x408
jle 0x5b9a2
xorl %r14d, %r14d
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r15
jmp 0x5ba6f
imull %r12d, %r14d
subl %r14d, %ebp
imull %ecx, %r12d
cmpl $0xffffff, %r12d        # imm = 0xFFFFFF
movq 0x20(%rsp), %r15
ja 0x5b9ee
cmpq %rbx, %r13
jae 0x5b9e6
movl %ebp, %eax
shll $0x8, %eax
movzbl (%r13), %ebp
incq %r13
orl %eax, %ebp
movl %r12d, %eax
shll $0x8, %eax
cmpl $0x10000, %r12d         # imm = 0x10000
movl %eax, %r12d
jb 0x5b9bb
movl %eax, %r12d
jmp 0x5b9ee
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %ecx
movw %cx, 0x8(%rdx,%r10)
addl $0x10, %r11d
movl %r11d, (%rdx)
cmpl $0xfff0, %r11d          # imm = 0xFFF0
jb 0x5ba46
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %eax
testw %ax, %ax
je 0x5ba46
addq 0x40(%rsp), %r9
xorl %ecx, %ecx
movzwl %ax, %r11d
shrl %r11d
subl %r11d, %eax
movw %ax, -0x4(%r9)
movzwl %ax, %eax
addl %eax, %ecx
movzwl (%r9), %eax
addq $0x4, %r9
testw %ax, %ax
jne 0x5ba1d
movl %ecx, (%rdx)
movzwl 0x8(%rdx,%r10), %ecx
movzwl 0xa(%rdx,%r10), %r14d
cmpw 0x4(%rdx,%r10), %cx
jbe 0x5ba6a
movl 0x4(%rdx,%r10), %eax
movl %eax, 0x8(%rdx,%r10)
movw %cx, 0x4(%rdx,%r10)
movw %r14w, 0x6(%rdx,%r10)
movq 0x18(%rsp), %r10
movzwl %r14w, %eax
xorl %ecx, %ecx
cmpl $0x101, %r8d            # imm = 0x101
setl %cl
addl %r8d, %ecx
cmpl %edi, %r8d
movl %ecx, %r8d
movl $0x100, %ecx            # imm = 0x100
cmovel %ecx, %r8d
leal (%rsi,%rax), %ecx
cmpw $0x3, %ax
jne 0x5baa3
cmpl %r10d, %ecx
jb 0x5b927
movq 0x10(%rsp), %rdx
leal 0x1(%rdx), %r14d
testl %ecx, %ecx
je 0x5bb1b
cmpl %r10d, %r14d
jae 0x5bb1b
movslq %r14d, %rdi
addq 0x30(%rsp), %rdi
leal (%rsi,%rax), %r15d
decl %r15d
movl 0x28(%rsp), %eax
movl %eax, %edx
subl 0x10(%rsp), %edx
movq %rdx, 0x38(%rsp)
cmpl %edx, %r15d
cmovbl %r15d, %edx
incq %rdx
movzbl 0x2c(%rsp), %esi
callq 0x4260
movq 0x18(%rsp), %r10
movq 0x38(%rsp), %rax
cmpl %eax, %r15d
cmovbl %r15d, %eax
movq %rax, %rcx
movq 0x10(%rsp), %rax
addl %ecx, %eax
addl $0x2, %eax
addl $-0x1, %r15d
jae 0x5bb13
incl %r14d
cmpl %r10d, %r14d
jb 0x5bb05
movl %eax, %r14d
movq 0x20(%rsp), %r15
movl %r14d, %eax
movq %rax, 0x10(%rsp)
cmpl %r10d, %r14d
movq 0x30(%rsp), %r14
jb 0x5b7fd
cmpl $0x0, 0xc(%rsp)
jns 0x5bb3b
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x7e26a
jmp 0x5bb48
xorl %r14d, %r14d
movq %r14, %rax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq