// File: /workspace/github_c_makefile_star2_O1/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 0x8060c
testq %rax, %rax
je 0x5e7e1
movq %rax, %rdi
movzbl (%r14), %ecx
testl %ecx, %ecx
movl $0x100, %eax            # imm = 0x100
cmovnel %ecx, %eax
leaq 0xa(%rdi), %rcx
xorl %edx, %edx
movl $0xffef, %esi           # imm = 0xFFEF
movl $0x0, %r8d
testl %eax, %eax
je 0x5e5d9
xorl %r8d, %r8d
movw %r8w, (%rcx,%r8,4)
movw $0x1, -0x2(%rcx,%r8,4)
incq %r8
cmpq %r8, %rax
jne 0x5e5c4
cmpl $0xff, %r8d
ja 0x5e5fe
movl %r8d, %r8d
movw %r8w, (%rcx,%r8,4)
movw $0x0, -0x2(%rcx,%r8,4)
incq %r8
cmpq $0x100, %r8             # imm = 0x100
jne 0x5e5e5
imulq $0x410, %rdx, %r8       # imm = 0x410
addq %rdi, %r8
movl %eax, (%r8)
movl %esi, 0x4(%r8)
movl %esi, 0x40c(%r8)
movw $0x0, 0x408(%r8)
incq %rdx
addq $0x410, %rcx            # imm = 0x410
cmpq $0x100, %rdx            # imm = 0x100
jne 0x5e5b7
movl %r15d, %r8d
addq %r14, %r8
xorl %ecx, %ecx
movq %r8, %r9
cmpl $0x6, %r15d
jb 0x5e666
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 0x5e64b
addq $0x6, %r14
movq %r14, %r9
testl %ebp, %ebp
je 0x5e7da
movl %ebp, %r10d
leaq 0xc(%rdi), %rax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r11d, %r11d
movl $0x0, 0x4(%rsp)
movq %r10, 0x8(%rsp)
movzbl %r11b, %eax
imulq $0x410, %rax, %r15      # imm = 0x410
movl (%rdi,%r15), %r13d
leal -0x1(%r13), %eax
cmpl %esi, %eax
jae 0x5e6ba
movl %esi, %eax
xorl %edx, %edx
divl %r13d
movl %eax, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
jmp 0x5e6bc
xorl %eax, %eax
xorl %r11d, %r11d
cmpl $0xffef, %eax           # imm = 0xFFEF
ja 0x5e7c1
movq %rbx, %r10
leaq (%rdi,%r15), %rdx
movq $-0x4, %r12
movl %r11d, %ebx
movzwl 0xc(%rdx,%r12), %ebp
leal (%rbx,%rbp), %r11d
addq $0x4, %r12
cmpl %eax, %r11d
jbe 0x5e6d8
cmpq $0x400, %r12            # imm = 0x400
jle 0x5e6ff
xorl %r11d, %r11d
jmp 0x5e7b9
imull %esi, %ebx
subl %ebx, %ecx
imull %ebp, %esi
cmpl $0xffffff, %esi         # imm = 0xFFFFFF
ja 0x5e73d
cmpq %r8, %r9
jae 0x5e735
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 0x5e70f
movl %eax, %esi
jmp 0x5e73d
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
addl $0x10, %ebp
movw %bp, 0x8(%rdx,%r12)
addl $0x10, %r13d
movl %r13d, (%rdx)
cmpl $0xfff0, %r13d          # imm = 0xFFF0
jb 0x5e78f
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %eax
testw %ax, %ax
je 0x5e78f
addq 0x10(%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 0x5e76d
movl %r11d, (%rdx)
movzwl 0x8(%rdx,%r12), %eax
movzwl 0xa(%rdx,%r12), %r11d
cmpw 0x4(%rdx,%r12), %ax
jbe 0x5e7b9
movl 0x4(%rdx,%r12), %ebx
movl %ebx, 0x8(%rdx,%r12)
movw %ax, 0x4(%rdx,%r12)
movw %r11w, 0x6(%rdx,%r12)
movq %r10, %rbx
movq 0x8(%rsp), %r10
movb %r11b, (%rbx,%r14)
incq %r14
cmpq %r10, %r14
jne 0x5e692
cmpl $0x0, 0x4(%rsp)
jns 0x5e7da
xorl %ebx, %ebx
callq 0x80732
jmp 0x5e7e3
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq