// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_uncompress_O1
static
unsigned char *arith_uncompress_O1(unsigned char *in, unsigned int in_size,
                                   unsigned char *out, unsigned int out_sz) {
    RangeCoder rc;
    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;
    }

    unsigned int m = in[0] ? in[0] : 256, i;
    for (i = 0; i < 256; i++)
        SIMPLE_MODEL(256,_init)(&byte_model[i], m);

    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);
        last = out[i];
    }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %r14
movl $0x41000, %edi          # imm = 0x41000
callq 0x7e144
testq %rax, %rax
je 0x5bdc8
movq %rax, %rdi
movzbl (%r14), %eax
testl %eax, %eax
movl $0x100, %ecx            # imm = 0x100
cmovnel %eax, %ecx
leaq 0xa(%rdi), %rdx
xorl %esi, %esi
movl $0xffef, %r8d           # imm = 0xFFEF
movl $0x0, %r9d
testl %ecx, %ecx
je 0x5bbcf
xorl %r9d, %r9d
movw %r9w, (%rdx,%r9,4)
movw $0x1, -0x2(%rdx,%r9,4)
incq %r9
cmpq %r9, %rcx
jne 0x5bbb3
movl %eax, %r9d
testl %eax, %eax
je 0x5bbeb
movl %r9d, %r9d
movw %r9w, (%rdx,%r9,4)
movw $0x0, -0x2(%rdx,%r9,4)
incq %r9
cmpq $0x100, %r9             # imm = 0x100
jne 0x5bbd2
imulq $0x410, %rsi, %r9       # imm = 0x410
addq %rdi, %r9
movl %ecx, (%r9)
movl %r8d, 0x4(%r9)
movl %r8d, 0x40c(%r9)
movw $0x0, 0x408(%r9)
incq %rsi
addq $0x410, %rdx            # imm = 0x410
cmpq $0x100, %rsi            # imm = 0x100
jne 0x5bba6
movl %r15d, %r8d
addq %r14, %r8
xorl %ecx, %ecx
movq %r8, %r9
cmpl $0x6, %r15d
jb 0x5bc53
xorl %ecx, %ecx
movl $0x1, %eax
movl %ecx, %edx
shll $0x8, %edx
movzbl (%r14,%rax), %ecx
orl %edx, %ecx
incq %rax
cmpl $0x6, %eax
jne 0x5bc38
addq $0x6, %r14
movq %r14, %r9
testl %ebp, %ebp
je 0x5bdc1
movl %ebp, %eax
movq %rax, 0x10(%rsp)
leaq 0xc(%rdi), %rax
movq %rax, 0x8(%rsp)
xorl %r14d, %r14d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movl $0x0, 0x4(%rsp)
movzbl %bpl, %eax
imulq $0x410, %rax, %r15      # imm = 0x410
movl (%rdi,%r15), %r13d
leal -0x1(%r13), %eax
cmpl %esi, %eax
jae 0x5bcb1
xorl %ebp, %ebp
movl %esi, %eax
xorl %edx, %edx
divl %r13d
movl %eax, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
cmpl $0xffef, %eax           # imm = 0xFFEF
jbe 0x5bcb3
jmp 0x5bda6
xorl %eax, %eax
movq %rbx, %r10
leaq (%rdi,%r15), %rdx
xorl %ebx, %ebx
movq $-0x4, %r12
movl %ebx, %ebp
movzwl 0xc(%rdx,%r12), %r11d
leal (%r11,%rbp), %ebx
addq $0x4, %r12
cmpl %eax, %ebx
jbe 0x5bcc3
cmpq $0x400, %r12            # imm = 0x400
jle 0x5bce7
xorl %ebp, %ebp
jmp 0x5bda3
imull %esi, %ebp
subl %ebp, %ecx
imull %r11d, %esi
cmpl $0xffffff, %esi         # imm = 0xFFFFFF
ja 0x5bd26
cmpq %r8, %r9
jae 0x5bd1e
movl %ecx, %eax
shll $0x8, %eax
movzbl (%r9), %ecx
incq %r9
orl %eax, %ecx
movl %esi, %eax
shll $0x8, %eax
cmpl $0x10000, %esi          # imm = 0x10000
movl %eax, %esi
jb 0x5bcf8
movl %eax, %esi
jmp 0x5bd26
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %r11d
movw %r11w, 0x8(%rdx,%r12)
addl $0x10, %r13d
movl %r13d, (%rdx)
cmpl $0xfff0, %r13d          # imm = 0xFFF0
jb 0x5bd7f
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %eax
testw %ax, %ax
je 0x5bd7f
addq 0x8(%rsp), %r15
xorl %r11d, %r11d
movzwl %ax, %ebx
shrl %ebx
subl %ebx, %eax
movw %ax, -0x4(%r15)
movzwl %ax, %eax
addl %eax, %r11d
movzwl (%r15), %eax
addq $0x4, %r15
testw %ax, %ax
jne 0x5bd57
movl %r11d, (%rdx)
movzwl 0x8(%rdx,%r12), %r11d
movzwl 0xa(%rdx,%r12), %ebp
cmpw 0x4(%rdx,%r12), %r11w
jbe 0x5bda3
movl 0x4(%rdx,%r12), %eax
movl %eax, 0x8(%rdx,%r12)
movw %r11w, 0x4(%rdx,%r12)
movw %bp, 0x6(%rdx,%r12)
movq %r10, %rbx
movb %bpl, (%rbx,%r14)
incq %r14
cmpq 0x10(%rsp), %r14
jne 0x5bc7d
cmpl $0x0, 0x4(%rsp)
jns 0x5bdc1
xorl %ebx, %ebx
callq 0x7e26a
jmp 0x5bdca
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq