// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_compress_O0
static
unsigned char *arith_compress_O0(unsigned char *in, unsigned int in_size,
                                 unsigned char *out, unsigned int *out_size) {
    int i, bound = arith_compress_bound(in_size,0)-5; // -5 for order/size
    unsigned char *out_free = NULL;

    if (!out) {
        *out_size = bound;
        out_free = out = malloc(*out_size);
    }
    if (!out || bound > *out_size)
        return NULL;

    unsigned int m = 0;
    for (i = 0; i < in_size; i++)
        if (m < in[i])
            m = in[i];
    m++;
    *out = m;

    SIMPLE_MODEL(256,_) byte_model;
    SIMPLE_MODEL(256,_init)(&byte_model, m);

    RangeCoder rc;
    RC_SetOutput(&rc, (char *)out+1);
    RC_SetOutputEnd(&rc, (char *)out + *out_size);
    RC_StartEncode(&rc);

    for (i = 0; i < in_size; i++)
        SIMPLE_MODEL(256, _encodeSymbol)(&byte_model, &rc, in[i]);

    if (RC_FinishEncode(&rc) < 0) {
        free(out_free);
        return NULL;
    }

    // Finalise block size and return it
    *out_size = RC_OutSize(&rc)+1;

    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rcx, %r14
movl %esi, %ebp
movq %rdi, %r13
movl %esi, %r15d
cvtsi2sd %r15, %xmm0
mulsd 0x40cd8(%rip), %xmm0    # 0x9dbb0
addsd 0x41938(%rip), %xmm0    # 0x9e818
addsd 0x40c90(%rip), %xmm0    # 0x9db78
addsd 0x41930(%rip), %xmm0    # 0x9e820
cvttsd2si %xmm0, %rbx
addl $-0x5, %ebx
testq %rdx, %rdx
je 0x5cf01
xorl %eax, %eax
jmp 0x5cf0e
movl %ebx, (%r14)
movl %ebx, %edi
callq 0x4680
movq %rax, %rdx
testq %rdx, %rdx
je 0x5d1d4
cmpl (%r14), %ebx
ja 0x5d1d4
movq %rax, 0x10(%rsp)
testl %ebp, %ebp
je 0x5cf46
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %esi
movzbl (%r13,%rax), %ecx
cmpl %ecx, %esi
cmoval %esi, %ecx
incq %rax
cmpq %rax, %r15
jne 0x5cf2d
incl %ecx
jmp 0x5cf4b
movl $0x1, %ecx
movl %ecx, %eax
movb %cl, (%rdx)
xorl %ecx, %ecx
movw %cx, 0x52(%rsp,%rcx,4)
movw $0x1, 0x50(%rsp,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x5cf51
leaq -0x1(%rcx), %rsi
cmpq $0xfe, %rsi
ja 0x5cf8a
movw %cx, 0x52(%rsp,%rcx,4)
movw $0x0, 0x50(%rsp,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x5cf72
movl %eax, 0x48(%rsp)
movl $0xffef, %eax           # imm = 0xFFEF
movl %eax, 0x4c(%rsp)
movl %eax, 0x454(%rsp)
movw $0x0, 0x450(%rsp)
leaq 0x1(%rdx), %r12
movq %r14, 0x20(%rsp)
movl (%r14), %r10d
movq %rdx, 0x28(%rsp)
addq %rdx, %r10
testl %ebp, %ebp
movq %r10, 0x8(%rsp)
movq %r12, 0x18(%rsp)
je 0x5d138
movq %r15, 0x30(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %edi, %edi
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %esi, %esi
xorl %ecx, %ecx
movq %r13, 0x38(%rsp)
movq %rdi, 0x40(%rsp)
movzbl (%r13,%rdi), %edx
leaq 0x50(%rsp), %rbx
movl $0x0, %edi
cmpw %dx, 0x52(%rsp)
je 0x5d01e
xorl %edi, %edi
movq %rbx, %r8
movzwl (%rbx), %r9d
addq $0x4, %rbx
addl %r9d, %edi
cmpw %dx, 0x6(%r8)
jne 0x5d009
movzwl (%rbx), %r13d
xorl %edx, %edx
divl 0x48(%rsp)
imull %eax, %edi
imull %eax, %r13d
addl %edi, %ebp
adcl $0x0, %ecx
cmpl $0xffffff, %r13d        # imm = 0xFFFFFF
ja 0x5d0b8
cmpl $0xff000000, %ebp       # imm = 0xFF000000
setae %al
testl %ecx, %ecx
sete %dl
testb %dl, %al
je 0x5d054
incl %r14d
jmp 0x5d099
movl %r14d, %edx
movq %r10, %rax
subq %r12, %rax
cmpq %rdx, %rax
jle 0x5d09e
addl %ecx, %esi
leaq 0x1(%r12), %rdi
movb %sil, (%r12)
testl %r14d, %r14d
je 0x5d08f
decb %cl
movzbl %cl, %esi
callq 0x4260
movq 0x8(%rsp), %r10
decl %r14d
leaq (%r12,%r14), %rdi
addq $0x2, %rdi
xorl %r14d, %r14d
movl %ebp, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r12
shll $0x8, %ebp
jmp 0x5d0a4
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movl %r13d, %eax
shll $0x8, %eax
cmpl $0x10000, %r13d         # imm = 0x10000
movl %eax, %r13d
jb 0x5d03d
jmp 0x5d0bb
movl %r13d, %eax
addw $0x10, (%rbx)
movl 0x48(%rsp), %edx
addl $0x10, %edx
movl %edx, 0x48(%rsp)
cmpl $0xfff0, %edx           # imm = 0xFFF0
movq 0x38(%rsp), %r13
jb 0x5d115
movl $0x0, 0x48(%rsp)
movzwl 0x50(%rsp), %edx
testw %dx, %dx
je 0x5d115
xorl %edi, %edi
leaq 0x54(%rsp), %r8
movzwl %dx, %r9d
shrl %r9d
subl %r9d, %edx
movw %dx, -0x4(%r8)
movzwl %dx, %edx
addl %edx, %edi
movzwl (%r8), %edx
addq $0x4, %r8
testw %dx, %dx
jne 0x5d0f0
movl %edi, 0x48(%rsp)
movzwl (%rbx), %edx
cmpw -0x4(%rbx), %dx
jbe 0x5d123
rolq $0x20, -0x4(%rbx)
movq 0x40(%rsp), %rdi
incq %rdi
cmpq 0x30(%rsp), %rdi
jne 0x5cfeb
jmp 0x5d144
xorl %ecx, %ecx
xorl %esi, %esi
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebp, %ebp
movl $0x5, %ebx
cmpl $0xff000000, %ebp       # imm = 0xFF000000
jb 0x5d15a
testl %ecx, %ecx
jne 0x5d15a
incl %r14d
jmp 0x5d19f
movl %r14d, %edx
movq %r10, %rax
subq %r12, %rax
cmpq %rdx, %rax
jle 0x5d1a4
addl %ecx, %esi
leaq 0x1(%r12), %rdi
movb %sil, (%r12)
testl %r14d, %r14d
je 0x5d195
decb %cl
movzbl %cl, %esi
callq 0x4260
movq 0x8(%rsp), %r10
decl %r14d
leaq (%r12,%r14), %rdi
addq $0x2, %rdi
xorl %r14d, %r14d
movl %ebp, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r12
shll $0x8, %ebp
jmp 0x5d1aa
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
decl %ebx
jne 0x5d149
testl %r15d, %r15d
js 0x5d1ca
subl 0x18(%rsp), %r12d
incl %r12d
movq 0x20(%rsp), %rax
movl %r12d, (%rax)
movq 0x28(%rsp), %rax
jmp 0x5d1d6
movq 0x10(%rsp), %rdi
callq 0x45c0
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq