// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_uncompress_O1_RLE
static
unsigned char *arith_uncompress_O1_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 =
        htscodecs_tls_alloc(256 * sizeof(*byte_model));
    if (!byte_model) {
        free(out_free);
        return NULL;
    }
    for (i = 0; i < 256; i++)
        SIMPLE_MODEL(256,_init)(&byte_model[i], m);

    SIMPLE_MODEL(NSYM,_) *run_model =
        htscodecs_tls_alloc(NSYM * sizeof(*run_model));
    if (!run_model) {
        htscodecs_tls_free(byte_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);

    unsigned char last = 0;
    for (i = 0; i < out_sz; i++) {
        out[i] = SIMPLE_MODEL(256, _decodeSymbol)(&byte_model[last], &rc);
        //fprintf(stderr, "lit %c (ctx %c)\n", out[i], last);
        last = out[i];
        int run = 0, r = 0, rctx = last;

        do {
            r = SIMPLE_MODEL(NSYM, _decodeSymbol)(&run_model[rctx], &rc);
            if (rctx == last)
                rctx = 256;
            else
                rctx += (rctx < NSYM-1);
            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(byte_model);
        htscodecs_tls_free(run_model);
        free(out_free);
        return NULL;
    }

    htscodecs_tls_free(byte_model);
    htscodecs_tls_free(run_model);
    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, 0x10(%rsp)
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %r13
movzbl (%rdi), %ebx
testl %ebx, %ebx
movl $0x100, %ebp            # imm = 0x100
cmovnel %ebx, %ebp
movl $0x41000, %edi          # imm = 0x41000
callq 0x7e144
testq %rax, %rax
je 0x5b65a
movq %rax, %r14
movl %ebp, %eax
leaq 0xa(%r14), %rcx
xorl %edx, %edx
movl $0xffef, %esi           # imm = 0xFFEF
movl $0x0, %edi
testl %ebp, %ebp
je 0x5b1a2
xorl %edi, %edi
movw %di, (%rcx,%rdi,4)
movw $0x1, -0x2(%rcx,%rdi,4)
incq %rdi
cmpq %rdi, %rax
jne 0x5b189
movl %ebx, %edi
testl %ebx, %ebx
je 0x5b1bb
movl %edi, %edi
movw %di, (%rcx,%rdi,4)
movw $0x0, -0x2(%rcx,%rdi,4)
incq %rdi
cmpq $0x100, %rdi            # imm = 0x100
jne 0x5b1a4
imulq $0x410, %rdx, %rdi      # imm = 0x410
addq %r14, %rdi
movl %ebp, (%rdi)
movl %esi, 0x4(%rdi)
movl %esi, 0x40c(%rdi)
movw $0x0, 0x408(%rdi)
incq %rdx
addq $0x410, %rcx            # imm = 0x410
cmpq $0x100, %rdx            # imm = 0x100
jne 0x5b17e
movl %r12d, %ebx
movl $0x42030, %edi          # imm = 0x42030
callq 0x7e144
testq %rax, %rax
je 0x5b65f
movq %rax, %r12
addq $0x1a, %rax
xorl %ecx, %ecx
movaps 0x4081e(%rip), %xmm0    # 0x9ba30
movabsq $0xffef00000004, %rdx   # imm = 0xFFEF00000004
movq 0x10(%rsp), %r11
imulq $0x418, %rcx, %rdi      # imm = 0x418
leaq (%r12,%rdi), %rsi
movups %xmm0, 0x8(%r12,%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 0x5b234
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 0x5b221
movq %r14, 0x20(%rsp)
movl %ebx, %eax
movl %ebx, %r14d
addq %r13, %r14
xorl %ebp, %ebp
movq %r14, %rbx
cmpl $0x6, %eax
jb 0x5b2b2
xorl %ebp, %ebp
movl $0x1, %eax
movl %ebp, %ecx
shll $0x8, %ecx
movzbl (%r13,%rax), %ebp
orl %ecx, %ebp
incq %rax
cmpl $0x6, %eax
jne 0x5b296
addq $0x6, %r13
movq %r13, %rbx
testl %r11d, %r11d
je 0x5b64e
leal -0x2(%r11), %eax
movl %eax, 0x34(%rsp)
movq 0x20(%rsp), %rax
addq $0xc, %rax
movq %rax, 0x40(%rsp)
leaq 0xc(%r12), %rax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movq %r12, 0x28(%rsp)
movq %r15, 0x38(%rsp)
movzbl %al, %eax
imulq $0x410, %rax, %rcx      # imm = 0x410
movq 0x20(%rsp), %rax
movl (%rax,%rcx), %edi
leal -0x1(%rdi), %eax
cmpl %r13d, %eax
jae 0x5b332
movl %r13d, %eax
xorl %edx, %edx
divl %edi
movl %eax, %r13d
movl %ebp, %eax
xorl %edx, %edx
divl %r13d
cmpl $0xffef, %eax           # imm = 0xFFEF
jbe 0x5b334
jmp 0x5b365
xorl %eax, %eax
movq 0x20(%rsp), %rdx
addq %rcx, %rdx
xorl %r10d, %r10d
movq $-0x4, %rsi
movl %r10d, %r9d
movzwl 0xc(%rdx,%rsi), %r8d
leal (%r9,%r8), %r10d
addq $0x4, %rsi
cmpl %eax, %r10d
jbe 0x5b346
cmpq $0x400, %rsi            # imm = 0x400
jle 0x5b36c
xorl %ecx, %ecx
jmp 0x5b425
imull %r13d, %r9d
subl %r9d, %ebp
imull %r8d, %r13d
cmpl $0xffffff, %r13d        # imm = 0xFFFFFF
ja 0x5b3b1
cmpq %r14, %rbx
jae 0x5b3a9
movl %ebp, %eax
shll $0x8, %eax
movzbl (%rbx), %ebp
incq %rbx
orl %eax, %ebp
movl %r13d, %eax
shll $0x8, %eax
cmpl $0x10000, %r13d         # imm = 0x10000
movl %eax, %r13d
jb 0x5b380
movl %eax, %r13d
jmp 0x5b3b1
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %r8d
movw %r8w, 0x8(%rdx,%rsi)
addl $0x10, %edi
movl %edi, (%rdx)
cmpl $0xfff0, %edi           # imm = 0xFFF0
jb 0x5b405
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %eax
testw %ax, %ax
je 0x5b405
addq 0x40(%rsp), %rcx
xorl %edi, %edi
movzwl %ax, %r8d
shrl %r8d
subl %r8d, %eax
movw %ax, -0x4(%rcx)
movzwl %ax, %eax
addl %eax, %edi
movzwl (%rcx), %eax
addq $0x4, %rcx
testw %ax, %ax
jne 0x5b3de
movl %edi, (%rdx)
movzwl 0x8(%rdx,%rsi), %r8d
movzwl 0xa(%rdx,%rsi), %ecx
cmpw 0x4(%rdx,%rsi), %r8w
jbe 0x5b425
movl 0x4(%rdx,%rsi), %eax
movl %eax, 0x8(%rdx,%rsi)
movw %r8w, 0x4(%rdx,%rsi)
movw %cx, 0x6(%rdx,%rsi)
movslq 0x8(%rsp), %rax
movb %cl, (%r15,%rax)
movl %ecx, 0x1c(%rsp)
movzbl %cl, %esi
xorl %edx, %edx
movl %esi, %edi
movl %edx, %ecx
movslq %edi, %rax
imulq $0x418, %rax, %r8       # imm = 0x418
movl (%r12,%r8), %r10d
leal -0x1(%r10), %eax
cmpl %r13d, %eax
jae 0x5b473
xorl %r15d, %r15d
movl %r13d, %eax
xorl %edx, %edx
divl %r10d
movl %eax, %r13d
movl %ebp, %eax
xorl %edx, %edx
divl %r13d
cmpl $0xffef, %eax           # imm = 0xFFEF
jbe 0x5b475
jmp 0x5b583
xorl %eax, %eax
leaq (%r12,%r8), %rdx
xorl %r12d, %r12d
movq $-0x4, %r9
movl %r12d, %r15d
movzwl 0xc(%rdx,%r9), %r11d
leal (%r15,%r11), %r12d
addq $0x4, %r9
cmpl %eax, %r12d
jbe 0x5b483
cmpq $0x408, %r9             # imm = 0x408
jle 0x5b4b4
xorl %r15d, %r15d
movq 0x10(%rsp), %r11
movq 0x28(%rsp), %r12
jmp 0x5b583
imull %r13d, %r15d
subl %r15d, %ebp
imull %r11d, %r13d
cmpl $0xffffff, %r13d        # imm = 0xFFFFFF
movq 0x28(%rsp), %r12
ja 0x5b4fe
cmpq %r14, %rbx
jae 0x5b4f6
movl %ebp, %eax
shll $0x8, %eax
movzbl (%rbx), %ebp
incq %rbx
orl %eax, %ebp
movl %r13d, %eax
shll $0x8, %eax
cmpl $0x10000, %r13d         # imm = 0x10000
movl %eax, %r13d
jb 0x5b4cd
movl %eax, %r13d
jmp 0x5b4fe
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %r11d
movw %r11w, 0x8(%rdx,%r9)
addl $0x10, %r10d
movl %r10d, (%rdx)
cmpl $0xfff0, %r10d          # imm = 0xFFF0
jb 0x5b55a
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %eax
testw %ax, %ax
je 0x5b55a
addq 0x50(%rsp), %r8
xorl %r10d, %r10d
movzwl %ax, %r11d
shrl %r11d
subl %r11d, %eax
movw %ax, -0x4(%r8)
movzwl %ax, %eax
addl %eax, %r10d
movzwl (%r8), %eax
addq $0x4, %r8
testw %ax, %ax
jne 0x5b52f
movl %r10d, (%rdx)
movzwl 0x8(%rdx,%r9), %r11d
movzwl 0xa(%rdx,%r9), %r15d
cmpw 0x4(%rdx,%r9), %r11w
jbe 0x5b57e
movl 0x4(%rdx,%r9), %eax
movl %eax, 0x8(%rdx,%r9)
movw %r11w, 0x4(%rdx,%r9)
movw %r15w, 0x6(%rdx,%r9)
movq 0x10(%rsp), %r11
movzwl %r15w, %eax
xorl %edx, %edx
cmpl $0x101, %edi            # imm = 0x101
setl %dl
addl %edi, %edx
cmpl %esi, %edi
movl %edx, %edi
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %edi
leal (%rcx,%rax), %edx
cmpw $0x3, %ax
jne 0x5b5b2
cmpl %r11d, %edx
jb 0x5b439
movq 0x8(%rsp), %rsi
leal 0x1(%rsi), %r15d
testl %edx, %edx
je 0x5b62a
cmpl %r11d, %r15d
jae 0x5b62a
movslq %r15d, %rdi
addq 0x38(%rsp), %rdi
leal (%rcx,%rax), %r12d
decl %r12d
movl 0x34(%rsp), %eax
movl %eax, %edx
subl 0x8(%rsp), %edx
movq %rdx, 0x48(%rsp)
cmpl %edx, %r12d
cmovbl %r12d, %edx
incq %rdx
movzbl 0x1c(%rsp), %esi
callq 0x4260
movq 0x10(%rsp), %r11
movq 0x48(%rsp), %rax
cmpl %eax, %r12d
cmovbl %r12d, %eax
movq %rax, %rcx
movq 0x8(%rsp), %rax
addl %ecx, %eax
addl $0x2, %eax
addl $-0x1, %r12d
jae 0x5b622
incl %r15d
cmpl %r11d, %r15d
jb 0x5b614
movl %eax, %r15d
movq 0x28(%rsp), %r12
movl %r15d, %eax
movq %rax, 0x8(%rsp)
cmpl %r11d, %r15d
movq 0x38(%rsp), %r15
movl 0x1c(%rsp), %eax
jb 0x5b2fe
cmpl $0x0, 0x4(%rsp)
jns 0x5b64e
xorl %r15d, %r15d
movq 0x20(%rsp), %rdi
callq 0x7e26a
jmp 0x5b665
xorl %r15d, %r15d
jmp 0x5b66d
xorl %r15d, %r15d
movq %r14, %r12
movq %r12, %rdi
callq 0x7e26a
movq %r15, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq