// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl %esi, %r15d
movq %rdi, %r13
movzbl (%rdi), %eax
testl %eax, %eax
movl $0x100, %ebx            # imm = 0x100
cmovnel %eax, %ebx
movl $0x41000, %edi          # imm = 0x41000
callq 0x8060c
testq %rax, %rax
je 0x5e043
movq %rax, %r12
movl %ebx, %eax
leaq 0xa(%r12), %rcx
xorl %edx, %edx
movl $0xffef, %esi           # imm = 0xFFEF
movl $0x0, %edi
testl %ebx, %ebx
je 0x5db74
xorl %edi, %edi
movw %di, (%rcx,%rdi,4)
movw $0x1, -0x2(%rcx,%rdi,4)
incq %rdi
cmpq %rdi, %rax
jne 0x5db61
cmpl $0xff, %edi
ja 0x5db95
movl %edi, %edi
movw %di, (%rcx,%rdi,4)
movw $0x0, -0x2(%rcx,%rdi,4)
incq %rdi
cmpq $0x100, %rdi            # imm = 0x100
jne 0x5db7e
imulq $0x410, %rdx, %rdi      # imm = 0x410
addq %r12, %rdi
movl %ebx, (%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 0x5db56
movl $0x42030, %edi          # imm = 0x42030
callq 0x8060c
testq %rax, %rax
je 0x5e048
leaq 0xa(%rax), %rbx
movq %rax, (%rsp)
leaq 0x1a(%rax), %rcx
xorl %edx, %edx
movabsq $0xffef00000004, %rsi   # imm = 0xFFEF00000004
movl $0x418, %edi            # imm = 0x418
movq 0x10(%rsp), %r11
imulq $0x418, %rdx, %r8       # imm = 0x418
addq (%rsp), %r8
xorl %r9d, %r9d
movw %r9w, (%rbx,%r9,4)
movw $0x1, -0x2(%rbx,%r9,4)
incq %r9
cmpq $0x4, %r9
jne 0x5dc09
xorl %r9d, %r9d
leal 0x4(%r9), %r10d
movw %r10w, (%rcx,%r9,4)
movw $0x0, -0x2(%rcx,%r9,4)
incq %r9
cmpq $0xfe, %r9
jne 0x5dc22
movq %rsi, (%r8)
movl $0xffef, 0x414(%r8) # imm = 0xFFEF
movw $0x0, 0x410(%r8)
incq %rdx
addq %rdi, %rbx
addq %rdi, %rcx
cmpq $0x102, %rdx            # imm = 0x102
jne 0x5dbfb
movl %r15d, %ebx
addq %r13, %rbx
xorl %ebp, %ebp
movq %rbx, 0x30(%rsp)
cmpl $0x6, %r15d
jb 0x5dc9f
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 0x5dc83
addq $0x6, %r13
movq %r13, %rbx
testl %r11d, %r11d
je 0x5e035
movq %r14, 0x18(%rsp)
leal -0x2(%r11), %eax
movl %eax, 0x24(%rsp)
leaq 0xc(%r12), %rax
movq %rax, 0x38(%rsp)
movq (%rsp), %r14
leaq 0xc(%r14), %rax
movq %rax, 0x50(%rsp)
xorl %r15d, %r15d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r10d, %r10d
movl $0x0, 0xc(%rsp)
movq %r12, 0x48(%rsp)
movzbl %r15b, %eax
imulq $0x410, %rax, %rcx      # imm = 0x410
movl (%r12,%rcx), %edi
leal -0x1(%rdi), %eax
cmpl %r13d, %eax
jae 0x5dd0f
movl %r13d, %eax
xorl %edx, %edx
divl %edi
movl %eax, %r13d
movl %ebp, %eax
xorl %edx, %edx
divl %r13d
jmp 0x5dd11
xorl %eax, %eax
xorl %r15d, %r15d
cmpl $0xffef, %eax           # imm = 0xFFEF
ja 0x5de0b
leaq (%r12,%rcx), %rdx
movq $-0x4, %rsi
movl %r15d, %r9d
movzwl 0xc(%rdx,%rsi), %r8d
leal (%r9,%r8), %r15d
addq $0x4, %rsi
cmpl %eax, %r15d
jbe 0x5dd2a
cmpq $0x400, %rsi            # imm = 0x400
jle 0x5dd51
xorl %r15d, %r15d
jmp 0x5de0b
imull %r13d, %r9d
subl %r9d, %ebp
imull %r8d, %r13d
cmpl $0xffffff, %r13d        # imm = 0xFFFFFF
ja 0x5dd98
cmpq 0x30(%rsp), %rbx
jae 0x5dd90
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 0x5dd65
movl %eax, %r13d
jmp 0x5dd98
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %r8d
movw %r8w, 0x8(%rdx,%rsi)
addl $0x10, %edi
movl %edi, (%rdx)
cmpl $0xfff0, %edi           # imm = 0xFFF0
jb 0x5dde6
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %eax
testw %ax, %ax
je 0x5dde6
addq 0x38(%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 0x5ddc5
movl %edi, (%rdx)
movzwl 0x8(%rdx,%rsi), %eax
movzwl 0xa(%rdx,%rsi), %r15d
cmpw 0x4(%rdx,%rsi), %ax
jbe 0x5de0b
movl 0x4(%rdx,%rsi), %ecx
movl %ecx, 0x8(%rdx,%rsi)
movw %ax, 0x4(%rdx,%rsi)
movw %r15w, 0x6(%rdx,%rsi)
movq %r10, 0x28(%rsp)
movslq %r10d, %rax
movq 0x18(%rsp), %rcx
movb %r15b, (%rcx,%rax)
movzbl %r15b, %esi
xorl %edx, %edx
movl %esi, %edi
movl %edx, %ecx
movslq %edi, %rax
imulq $0x418, %rax, %r8       # imm = 0x418
movl (%r14,%r8), %r10d
leal -0x1(%r10), %eax
cmpl %r13d, %eax
jae 0x5de51
movl %r13d, %eax
xorl %edx, %edx
divl %r10d
movl %eax, %r13d
movl %ebp, %eax
xorl %edx, %edx
divl %r13d
jmp 0x5de53
xorl %eax, %eax
xorl %r12d, %r12d
cmpl $0xffef, %eax           # imm = 0xFFEF
ja 0x5df75
leaq (%r14,%r8), %rdx
movq $-0x4, %r9
movl %r12d, %r14d
movzwl 0xc(%rdx,%r9), %r11d
leal (%r14,%r11), %r12d
addq $0x4, %r9
cmpl %eax, %r12d
jbe 0x5de6c
cmpq $0x408, %r9             # imm = 0x408
jle 0x5de9c
xorl %r12d, %r12d
movq 0x10(%rsp), %r11
movq (%rsp), %r14
jmp 0x5df75
imull %r13d, %r14d
subl %r14d, %ebp
imull %r11d, %r13d
cmpl $0xffffff, %r13d        # imm = 0xFFFFFF
ja 0x5dee2
movq (%rsp), %r14
movq 0x30(%rsp), %r12
cmpq %r12, %rbx
jae 0x5dee8
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 0x5deb9
movl %eax, %r13d
jmp 0x5def0
movq (%rsp), %r14
jmp 0x5def0
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %r11d
movw %r11w, 0x8(%rdx,%r9)
addl $0x10, %r10d
movl %r10d, (%rdx)
cmpl $0xfff0, %r10d          # imm = 0xFFF0
jb 0x5df46
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %eax
testw %ax, %ax
je 0x5df46
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 0x5df21
movl %r10d, (%rdx)
movzwl 0x8(%rdx,%r9), %eax
movzwl 0xa(%rdx,%r9), %r12d
cmpw 0x4(%rdx,%r9), %ax
jbe 0x5df70
movl 0x4(%rdx,%r9), %r8d
movl %r8d, 0x8(%rdx,%r9)
movw %ax, 0x4(%rdx,%r9)
movw %r12w, 0x6(%rdx,%r9)
movq 0x10(%rsp), %r11
movzwl %r12w, %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 0x5dfa4
cmpl %r11d, %edx
jb 0x5de24
movq 0x28(%rsp), %rsi
leal 0x1(%rsi), %r12d
testl %edx, %edx
je 0x5e015
cmpl %r11d, %r12d
jae 0x5e015
movslq %r12d, %rdi
addq 0x18(%rsp), %rdi
leal (%rcx,%rax), %r14d
decl %r14d
movl 0x24(%rsp), %eax
movl %eax, %edx
subl %esi, %edx
movq %rdx, 0x40(%rsp)
cmpl %edx, %r14d
cmovbl %r14d, %edx
incq %rdx
movzbl %r15b, %esi
callq 0x4260
movq 0x10(%rsp), %r11
movq 0x40(%rsp), %rax
cmpl %eax, %r14d
cmovbl %r14d, %eax
movq 0x28(%rsp), %rcx
addl %ecx, %eax
addl $0x2, %eax
addl $-0x1, %r14d
jae 0x5e00e
incl %r12d
cmpl %r11d, %r12d
jb 0x5e000
movl %eax, %r12d
movq (%rsp), %r14
movl %r12d, %r10d
cmpl %r11d, %r12d
movq 0x48(%rsp), %r12
jb 0x5dce5
cmpl $0x0, 0xc(%rsp)
movq 0x18(%rsp), %r14
jns 0x5e035
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x80732
movq (%rsp), %rdi
jmp 0x5e04e
xorl %r14d, %r14d
jmp 0x5e053
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x80732
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq