// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r15
movl %esi, %ebp
movq %rdi, 0x10(%rsp)
movl %esi, %r13d
cvtsi2sd %r13, %xmm0
mulsd 0x410e9(%rip), %xmm0    # 0x9dbb0
addsd 0x41d49(%rip), %xmm0    # 0x9e818
addsd 0x410a1(%rip), %xmm0    # 0x9db78
addsd 0x41d41(%rip), %xmm0    # 0x9e820
cvttsd2si %xmm0, %rbx
addl $-0x5, %ebx
testq %rdx, %rdx
je 0x5caf4
movq %rdx, %r14
xorl %r12d, %r12d
jmp 0x5cb04
movl %ebx, (%r15)
movl %ebx, %edi
callq 0x4680
movq %rax, %r14
movq %rax, %r12
testq %r14, %r14
je 0x5ce9e
cmpl (%r15), %ebx
ja 0x5ce9e
movl $0x41000, %edi          # imm = 0x41000
callq 0x8060c
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x5cb4e
testl %ebp, %ebp
je 0x5cb5b
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x10(%rsp), %rsi
movl %ecx, %edx
movzbl (%rsi,%rax), %ecx
cmpl %ecx, %edx
cmoval %edx, %ecx
incq %rax
cmpq %rax, %r13
jne 0x5cb37
incl %ecx
jmp 0x5cb60
movq %r12, %rdi
callq 0x45c0
jmp 0x5ce9e
movl $0x1, %ecx
movl %ecx, %eax
movb %cl, (%r14)
movq 0x8(%rsp), %rdx
leaq 0xa(%rdx), %rcx
addq $0xe, %rdx
xorl %esi, %esi
movl $0xffef, %edi           # imm = 0xFFEF
movl $0x410, %r8d            # imm = 0x410
imulq $0x410, %rsi, %r9       # imm = 0x410
addq 0x8(%rsp), %r9
movq %rdx, %rbx
xorl %r10d, %r10d
movq %rbx, %r11
movw %r10w, (%rcx,%r10,4)
movw $0x1, -0x2(%rcx,%r10,4)
incq %r10
addq $0x4, %rbx
cmpq %r10, %rax
jne 0x5cb91
leaq -0x1(%r10), %rbx
cmpq $0xfe, %rbx
ja 0x5cbd5
movw %r10w, (%r11)
movw $0x0, -0x2(%r11)
incq %r10
addq $0x4, %r11
cmpq $0x100, %r10            # imm = 0x100
jne 0x5cbba
movl %eax, (%r9)
movl %edi, 0x4(%r9)
movl %edi, 0x40c(%r9)
movw $0x0, 0x408(%r9)
incq %rsi
addq %r8, %rcx
addq %r8, %rdx
cmpq $0x100, %rsi            # imm = 0x100
jne 0x5cb7f
movq %r12, 0x20(%rsp)
leaq 0x1(%r14), %rsi
movq %r15, 0x30(%rsp)
movl (%r15), %r11d
movq %r14, 0x38(%rsp)
addq %r14, %r11
testl %ebp, %ebp
movq %r11, 0x18(%rsp)
movq %rsi, 0x28(%rsp)
je 0x5cdea
movq %r13, 0x48(%rsp)
movq 0x8(%rsp), %rax
addq $0xc, %rax
movq %rax, 0x40(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
xorl %edx, %edx
xorl %ebp, %ebp
xorl %r9d, %r9d
xorl %ebx, %ebx
movq %rsi, %r13
xorl %esi, %esi
xorl %ecx, %ecx
movq 0x10(%rsp), %r10
movzbl %dl, %edx
imulq $0x410, %rdx, %r14      # imm = 0x410
movq %r8, 0x58(%rsp)
movzbl (%r10,%r8), %edx
movq 0x8(%rsp), %rdi
leaq (%rdi,%r14), %r15
addq $0x8, %r15
cmpw %dx, 0xa(%rdi,%r14)
jne 0x5cc87
xorl %edi, %edi
jmp 0x5cca4
movl %r9d, %r12d
xorl %edi, %edi
movq %r15, %r8
movzwl (%r15), %r9d
addq $0x4, %r15
addl %r9d, %edi
cmpw %dx, 0x6(%r8)
jne 0x5cc8c
movl %r12d, %r9d
movq 0x8(%rsp), %rdx
leaq (%rdx,%r14), %r8
movzwl (%r15), %r12d
xorl %edx, %edx
movq %r8, 0x50(%rsp)
divl (%r8)
imull %eax, %edi
imull %eax, %r12d
addl %edi, %ebp
adcl $0x0, %ecx
cmpl $0xffffff, %r12d        # imm = 0xFFFFFF
ja 0x5cd62
cmpl $0xff000000, %ebp       # imm = 0xFF000000
setae %al
testl %ecx, %ecx
sete %dl
testb %dl, %al
je 0x5ccea
incl %ebx
jmp 0x5cd3f
movl %ebx, %edx
movq %r11, %rax
subq %r13, %rax
cmpq %rdx, %rax
jle 0x5cd44
addl %ecx, %esi
leaq 0x1(%r13), %rdi
movb %sil, (%r13)
testl %ebx, %ebx
je 0x5cd35
decb %cl
movzbl %cl, %esi
movq %r13, 0x60(%rsp)
movl %r9d, %r13d
callq 0x4260
movl %r13d, %r9d
movq 0x18(%rsp), %r11
movq 0x10(%rsp), %r10
decl %ebx
movq 0x60(%rsp), %rax
leaq (%rax,%rbx), %rdi
addq $0x2, %rdi
xorl %ebx, %ebx
movl %ebp, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r13
shll $0x8, %ebp
jmp 0x5cd4a
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %r12d, %eax
shll $0x8, %eax
cmpl $0x10000, %r12d         # imm = 0x10000
movl %eax, %r12d
jb 0x5ccd4
jmp 0x5cd65
movl %r12d, %eax
addw $0x10, (%r15)
movq 0x50(%rsp), %r12
movl (%r12), %edx
addl $0x10, %edx
movl %edx, (%r12)
cmpl $0xfff0, %edx           # imm = 0xFFF0
jb 0x5cdc1
movl $0x0, (%r12)
movzwl 0x8(%r12), %edx
testw %dx, %dx
je 0x5cdc1
addq 0x40(%rsp), %r14
xorl %edi, %edi
movzwl %dx, %r8d
shrl %r8d
subl %r8d, %edx
movw %dx, -0x4(%r14)
movzwl %dx, %edx
addl %edx, %edi
movzwl (%r14), %edx
addq $0x4, %r14
testw %dx, %dx
jne 0x5cd9c
movl %edi, (%r12)
movzwl (%r15), %edx
cmpw -0x4(%r15), %dx
jbe 0x5cdd1
rolq $0x20, -0x4(%r15)
movq 0x58(%rsp), %r8
movb (%r10,%r8), %dl
incq %r8
cmpq 0x48(%rsp), %r8
jne 0x5cc5a
jmp 0x5cdf8
xorl %ecx, %ecx
movq %rsi, %r13
xorl %esi, %esi
xorl %ebx, %ebx
xorl %r9d, %r9d
xorl %ebp, %ebp
movl $0x5, %r14d
cmpl $0xff000000, %ebp       # imm = 0xFF000000
jb 0x5ce0e
testl %ecx, %ecx
jne 0x5ce0e
incl %ebx
jmp 0x5ce54
movl %ebx, %edx
movq %r11, %rax
subq %r13, %rax
cmpq %rdx, %rax
jle 0x5ce59
addl %ecx, %esi
leaq 0x1(%r13), %rdi
movb %sil, (%r13)
testl %ebx, %ebx
je 0x5ce4a
decb %cl
movzbl %cl, %esi
movl %r9d, %r15d
callq 0x4260
movl %r15d, %r9d
movq 0x18(%rsp), %r11
decl %ebx
leaq (%rbx,%r13), %rdi
addq $0x2, %rdi
xorl %ebx, %ebx
movl %ebp, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r13
shll $0x8, %ebp
jmp 0x5ce5f
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
decl %r14d
jne 0x5cdfe
testl %r9d, %r9d
js 0x5ce8a
subl 0x28(%rsp), %r13d
incl %r13d
movq 0x30(%rsp), %rax
movl %r13d, (%rax)
movq 0x8(%rsp), %rdi
callq 0x80732
movq 0x38(%rsp), %rax
jmp 0x5cea0
movq 0x20(%rsp), %rdi
callq 0x45c0
movq 0x8(%rsp), %rdi
callq 0x80732
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq