// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl -0x14(%rbp), %edi
xorl %esi, %esi
callq 0x826c0
subl $0x5, %eax
movl %eax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x84087
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x20(%rbp)
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x84099
movl -0x30(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0x840a6
movq $0x0, -0x8(%rbp)
jmp 0x841c7
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x840eb
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jae 0x840de
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x3c(%rbp)
jmp 0x840e0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x840b4
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movl -0x3c(%rbp), %esi
leaq -0x44c(%rbp), %rdi
callq 0x859d0
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
leaq -0x490(%rbp), %rdi
callq 0x85b70
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movl (%rax), %eax
addq %rax, %rsi
leaq -0x490(%rbp), %rdi
callq 0x85ba0
leaq -0x490(%rbp), %rdi
callq 0x85bc0
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x84183
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
leaq -0x44c(%rbp), %rdi
leaq -0x490(%rbp), %rsi
movzwl %ax, %edx
callq 0x85c20
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x8414e
leaq -0x490(%rbp), %rdi
callq 0x85de0
cmpl $0x0, %eax
jge 0x841a7
movq -0x38(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x841c7
leaq -0x490(%rbp), %rdi
callq 0x85e20
addq $0x1, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x490, %rsp            # imm = 0x490
popq %rbp
retq
nopw %cs:(%rax,%rax)