// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_compress_O1
static
unsigned char *arith_compress_O1(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;

    SIMPLE_MODEL(256,_) *byte_model =
        htscodecs_tls_alloc(256 * sizeof(*byte_model));
    if (!byte_model) {
        free(out_free);
        return NULL;
    }
    unsigned int m = 0;
    if (1 || in_size > 1000) {
        for (i = 0; i < in_size; i++)
            if (m < in[i])
                m = in[i];
        //fprintf(stderr, "%d max %d\n", in_size, m);
        m++;
    }
    *out = m;
    for (i = 0; i < 256; i++)
        SIMPLE_MODEL(256,_init)(&byte_model[i], m);

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

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

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

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

    htscodecs_tls_free(byte_model);
    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
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 0x83e57
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 0x83e69
movl -0x30(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0x83e76
movq $0x0, -0x8(%rbp)
jmp 0x84020
movl $0x41000, %edi          # imm = 0x41000
callq 0xce6a0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x83ea1
movq -0x38(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x84020
movl $0x0, -0x44(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x83ee6
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jae 0x83ed9
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x44(%rbp)
jmp 0x83edb
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x83eaf
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movl $0x0, -0x2c(%rbp)
cmpl $0x100, -0x2c(%rbp)     # imm = 0x100
jge 0x83f2f
movq -0x40(%rbp), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x410, %rax, %rax      # imm = 0x410
addq %rax, %rdi
movl -0x44(%rbp), %esi
callq 0x859d0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x83f01
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
leaq -0x88(%rbp), %rdi
callq 0x85b70
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movl (%rax), %eax
addq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x85ba0
leaq -0x88(%rbp), %rdi
callq 0x85bc0
movb $0x0, -0x89(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x83fca
movq -0x40(%rbp), %rdi
movzbl -0x89(%rbp), %eax
imulq $0x410, %rax, %rax      # imm = 0x410
addq %rax, %rdi
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
leaq -0x88(%rbp), %rsi
movzwl %ax, %edx
callq 0x85c20
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x89(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x83f76
leaq -0x88(%rbp), %rdi
callq 0x85de0
cmpl $0x0, %eax
jge 0x83ff7
movq -0x38(%rbp), %rdi
callq 0x45a0
movq -0x40(%rbp), %rdi
callq 0xce8f0
movq $0x0, -0x8(%rbp)
jmp 0x84020
leaq -0x88(%rbp), %rdi
callq 0x85e20
addq $0x1, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rdi
callq 0xce8f0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)