// File: /workspace/github_c_makefile_star2_O1/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 %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r12
movzbl (%rdi), %edx
testl %edx, %edx
movl $0x100, %eax            # imm = 0x100
cmovnel %edx, %eax
testl %eax, %eax
je 0x5e0aa
movl %eax, %edx
xorl %esi, %esi
movw %si, 0x52(%rsp,%rsi,4)
movw $0x1, 0x50(%rsp,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x5e094
jmp 0x5e0ac
xorl %esi, %esi
movq %rcx, 0x10(%rsp)
cmpl $0xff, %esi
ja 0x5e0d3
movl %esi, %ecx
movw %cx, 0x52(%rsp,%rcx,4)
movw $0x0, 0x50(%rsp,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x5e0bb
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 0x8060c
testq %rax, %rax
je 0x5e54c
movq %rax, %r14
addq $0xa, %rax
leaq 0x1a(%r14), %rcx
xorl %edx, %edx
movabsq $0xffef00000004, %rsi   # imm = 0xFFEF00000004
movl $0x418, %edi            # imm = 0x418
imulq $0x418, %rdx, %r8       # imm = 0x418
addq %r14, %r8
xorl %r9d, %r9d
movw %r9w, (%rax,%r9,4)
movw $0x1, -0x2(%rax,%r9,4)
incq %r9
cmpq $0x4, %r9
jne 0x5e12d
xorl %r9d, %r9d
leal 0x4(%r9), %r10d
movw %r10w, (%rcx,%r9,4)
movw $0x0, -0x2(%rcx,%r9,4)
incq %r9
cmpq $0xfe, %r9
jne 0x5e146
movq %rsi, (%r8)
movl $0xffef, 0x414(%r8) # imm = 0xFFEF
movw $0x0, 0x410(%r8)
incq %rdx
addq %rdi, %rax
addq %rdi, %rcx
cmpq $0x102, %rdx            # imm = 0x102
jne 0x5e120
movq %rbx, 0x20(%rsp)
movl %r15d, %ebx
addq %r12, %rbx
xorl %ebp, %ebp
movq %rbx, %r13
cmpl $0x6, %r15d
movq 0x10(%rsp), %r10
jb 0x5e1ca
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 0x5e1af
addq $0x6, %r12
movq %r12, %r13
testl %r10d, %r10d
je 0x5e545
leal -0x2(%r10), %eax
movl %eax, 0x34(%rsp)
leaq 0xc(%r14), %rax
movq %rax, 0x40(%rsp)
xorl %r8d, %r8d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0x0, 0xc(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x18(%rsp)
movl 0x48(%rsp), %esi
leal -0x1(%rsi), %eax
cmpl %r12d, %eax
jae 0x5e21e
movl %r12d, %eax
xorl %edx, %edx
divl %esi
movl %eax, %r12d
movl %ebp, %eax
xorl %edx, %edx
divl %r12d
jmp 0x5e220
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0xffef, %eax           # imm = 0xFFEF
ja 0x5e31b
movq %r8, %r9
movq $-0x4, %rdx
movl %ecx, %r8d
movzwl 0x54(%rsp,%rdx), %edi
leal (%r8,%rdi), %ecx
addq $0x4, %rdx
cmpl %eax, %ecx
jbe 0x5e237
cmpq $0x400, %rdx            # imm = 0x400
jle 0x5e25e
xorl %ecx, %ecx
movq %r9, %r8
jmp 0x5e31b
imull %r12d, %r8d
subl %r8d, %ebp
imull %edi, %r12d
movq %r9, %r8
cmpl $0xffffff, %r12d        # imm = 0xFFFFFF
ja 0x5e2a8
cmpq %rbx, %r13
jae 0x5e2a0
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 0x5e275
movl %eax, %r12d
jmp 0x5e2a8
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 0x5e2f8
movl $0x0, 0x48(%rsp)
movzwl 0x50(%rsp), %eax
testw %ax, %ax
je 0x5e2f8
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 0x5e2d8
movl %ecx, 0x48(%rsp)
movzwl 0x50(%rsp,%rdx), %eax
movzwl 0x52(%rsp,%rdx), %ecx
cmpw 0x4c(%rsp,%rdx), %ax
jbe 0x5e31b
movl 0x4c(%rsp,%rdx), %esi
movl %esi, 0x50(%rsp,%rdx)
movw %ax, 0x4c(%rsp,%rdx)
movw %cx, 0x4e(%rsp,%rdx)
movq %r8, 0x38(%rsp)
movslq %r8d, %rax
movq 0x20(%rsp), %rdx
movb %cl, (%rdx,%rax)
movzbl %cl, %edi
xorl %edx, %edx
movl %edi, %r8d
movl %edx, %esi
movslq %r8d, %rax
imulq $0x418, %rax, %r9       # imm = 0x418
movl (%r14,%r9), %r11d
leal -0x1(%r11), %eax
cmpl %r12d, %eax
jae 0x5e360
movl %r12d, %eax
xorl %edx, %edx
divl %r11d
movl %eax, %r12d
movl %ebp, %eax
xorl %edx, %edx
divl %r12d
jmp 0x5e362
xorl %eax, %eax
xorl %r15d, %r15d
cmpl $0xffef, %eax           # imm = 0xFFEF
ja 0x5e48f
leaq (%r14,%r9), %rdx
movq $-0x4, %r10
movl %r15d, %ebx
movzwl 0xc(%rdx,%r10), %r14d
leal (%rbx,%r14), %r15d
addq $0x4, %r10
cmpl %eax, %r15d
jbe 0x5e37b
cmpq $0x408, %r10            # imm = 0x408
jle 0x5e3b1
xorl %r15d, %r15d
movq 0x10(%rsp), %r10
movq 0x28(%rsp), %r14
movq 0x18(%rsp), %rbx
jmp 0x5e48f
imull %r12d, %ebx
subl %ebx, %ebp
imull %r14d, %r12d
cmpl $0xffffff, %r12d        # imm = 0xFFFFFF
ja 0x5e3f4
movq 0x18(%rsp), %rbx
cmpq %rbx, %r13
jae 0x5e3fb
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 0x5e3c9
movl %eax, %r12d
jmp 0x5e403
movq 0x18(%rsp), %rbx
jmp 0x5e403
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %r14d
movw %r14w, 0x8(%rdx,%r10)
addl $0x10, %r11d
movl %r11d, (%rdx)
cmpl $0xfff0, %r11d          # imm = 0xFFF0
movq 0x28(%rsp), %r14
jb 0x5e460
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %eax
testw %ax, %ax
je 0x5e460
addq 0x40(%rsp), %r9
xorl %r11d, %r11d
movzwl %ax, %ebx
shrl %ebx
subl %ebx, %eax
movw %ax, -0x4(%r9)
movzwl %ax, %eax
addl %eax, %r11d
movzwl (%r9), %eax
addq $0x4, %r9
testw %ax, %ax
jne 0x5e439
movl %r11d, (%rdx)
movq 0x18(%rsp), %rbx
movzwl 0x8(%rdx,%r10), %eax
movzwl 0xa(%rdx,%r10), %r15d
cmpw 0x4(%rdx,%r10), %ax
jbe 0x5e48a
movl 0x4(%rdx,%r10), %r9d
movl %r9d, 0x8(%rdx,%r10)
movw %ax, 0x4(%rdx,%r10)
movw %r15w, 0x6(%rdx,%r10)
movq 0x10(%rsp), %r10
movzwl %r15w, %eax
xorl %edx, %edx
cmpl $0x101, %r8d            # imm = 0x101
setl %dl
addl %r8d, %edx
cmpl %edi, %r8d
movl %edx, %r8d
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %r8d
leal (%rsi,%rax), %edx
cmpw $0x3, %ax
jne 0x5e4c3
cmpl %r10d, %edx
jb 0x5e333
movq 0x38(%rsp), %r8
leal 0x1(%r8), %r14d
testl %edx, %edx
je 0x5e52d
cmpl %r10d, %r14d
jae 0x5e52d
movslq %r14d, %rdi
addq 0x20(%rsp), %rdi
leal (%rsi,%rax), %r15d
decl %r15d
movl 0x34(%rsp), %eax
movl %eax, %ebx
subl %r8d, %ebx
cmpl %ebx, %r15d
movl %ebx, %edx
cmovbl %r15d, %edx
incq %rdx
movzbl %cl, %esi
callq 0x4260
movq 0x10(%rsp), %r10
cmpl %ebx, %r15d
cmovbl %r15d, %ebx
movq 0x38(%rsp), %rax
addl %ebx, %eax
addl $0x2, %eax
movq 0x18(%rsp), %rbx
addl $-0x1, %r15d
jae 0x5e52a
incl %r14d
cmpl %r10d, %r14d
jb 0x5e51c
movl %eax, %r14d
movl %r14d, %r8d
cmpl %r10d, %r14d
movq 0x28(%rsp), %r14
jb 0x5e1ff
cmpl $0x0, 0xc(%rsp)
js 0x5e550
movq 0x20(%rsp), %rbx
jmp 0x5e552
xorl %ebx, %ebx
jmp 0x5e55a
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x80732
movq %rbx, %rax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq