// File: /workspace/github_c_makefile_star2_O3/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, %r14
movl %esi, %ebp
movq %rdi, %r12
movl %esi, %r13d
cvtsi2sd %r13, %xmm0
mulsd 0x40d5a(%rip), %xmm0    # 0x9ada8
addsd 0x419c2(%rip), %xmm0    # 0x9ba18
addsd 0x419b2(%rip), %xmm0    # 0x9ba10
addsd 0x419ba(%rip), %xmm0    # 0x9ba20
cvttsd2si %xmm0, %rax
addl $-0x5, %eax
testq %rdx, %rdx
je 0x5a082
movq %rdx, %r15
xorl %ebx, %ebx
cmpl (%r14), %eax
jbe 0x5a09b
jmp 0x5a438
movl %eax, (%r14)
movl %eax, %edi
callq 0x4680
movq %rax, %r15
movq %rax, %rbx
testq %rax, %rax
je 0x5a436
movl $0x41000, %edi          # imm = 0x41000
callq 0x7e144
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x5a0d0
testl %ebp, %ebp
movq %rbx, 0x38(%rsp)
je 0x5a0dd
xorl %eax, %eax
xorl %edx, %edx
movzbl (%r12,%rax), %ecx
cmpl %ecx, %edx
cmovbel %ecx, %edx
incq %rax
cmpq %rax, %r13
jne 0x5a0bc
jmp 0x5a0df
movq %rbx, %rdi
callq 0x45c0
jmp 0x5a436
xorl %edx, %edx
leal 0x1(%rdx), %eax
movb %al, (%r15)
movq 0x10(%rsp), %rsi
leaq 0xa(%rsi), %rcx
movl %edx, %edx
addq $0xe, %rsi
xorl %edi, %edi
movl $0xffef, %r8d           # imm = 0xFFEF
movl $0x410, %r9d            # imm = 0x410
imulq $0x410, %rdi, %r10      # imm = 0x410
addq 0x10(%rsp), %r10
xorl %r11d, %r11d
movw %r11w, (%rcx,%r11,4)
movw $0x1, -0x2(%rcx,%r11,4)
incq %r11
cmpq %r11, %rax
jne 0x5a111
movq %rdx, %r11
cmpl $0xfe, %edx
ja 0x5a14e
leaq 0x1(%r11), %rbx
movw %bx, (%rsi,%r11,4)
movw $0x0, -0x2(%rsi,%r11,4)
movq %rbx, %r11
cmpq $0xff, %rbx
jne 0x5a131
movl %eax, (%r10)
movl %r8d, 0x4(%r10)
movl %r8d, 0x40c(%r10)
movw $0x0, 0x408(%r10)
incq %rdi
addq %r9, %rcx
addq %r9, %rsi
cmpq $0x100, %rdi            # imm = 0x100
jne 0x5a102
leaq 0x1(%r15), %rdi
movq %r14, 0x30(%rsp)
movl (%r14), %r9d
movq %r15, 0x28(%rsp)
addq %r15, %r9
xorl %r15d, %r15d
testl %ebp, %ebp
movq %rdi, 0x20(%rsp)
je 0x5a383
movq %r13, 0x48(%rsp)
movq 0x10(%rsp), %rax
addq $0xc, %rax
movq %rax, 0x40(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r10d, %r10d
xorl %edx, %edx
xorl %r11d, %r11d
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
xorl %ecx, %ecx
xorl %esi, %esi
movq %rdi, %r13
movq %r12, 0x50(%rsp)
movzbl %dl, %edx
imulq $0x410, %rdx, %r14      # imm = 0x410
movzbl (%r12,%r10), %edx
movq 0x10(%rsp), %rdi
leaq (%rdi,%r14), %r15
addq $0x8, %r15
cmpw %dx, 0xa(%rdi,%r14)
movq %r10, 0x58(%rsp)
jne 0x5a200
xorl %r12d, %r12d
jmp 0x5a217
xorl %r12d, %r12d
movq %r15, %rdi
movzwl (%r15), %r8d
addq $0x4, %r15
addl %r8d, %r12d
cmpw %dx, 0x6(%rdi)
jne 0x5a203
movq 0x10(%rsp), %rdx
addq %r14, %rdx
movzwl (%r15), %edi
movq %rdx, 0x18(%rsp)
movl (%rdx), %r8d
xorl %edx, %edx
divl %r8d
movl %eax, %ebx
imull %eax, %r12d
imull %edi, %ebx
addl %r11d, %r12d
adcl $0x0, %esi
cmpl $0xffffff, %ebx         # imm = 0xFFFFFF
ja 0x5a2e7
movl %esi, %r8d
movl %esi, %edi
cmpl $0xff000000, %r12d      # imm = 0xFF000000
jb 0x5a261
testl %edi, %edi
jne 0x5a261
incl %ebp
jmp 0x5a2b3
movl %ebp, %edx
movq %r9, %rax
subq %r13, %rax
cmpq %rdx, %rax
jle 0x5a2bb
addl %ecx, %r8d
leaq 0x1(%r13), %rdi
movb %r8b, (%r13)
testl %ebp, %ebp
je 0x5a2a3
decb %sil
movzbl %sil, %esi
movq %r13, 0x60(%rsp)
movq %r9, %r13
callq 0x4260
movq %r13, %r9
decl %ebp
movq 0x60(%rsp), %rax
leaq (%rax,%rbp), %rdi
addq $0x2, %rdi
movl %r12d, %ecx
shrl $0x18, %ecx
xorl %esi, %esi
movq %rdi, %r13
xorl %ebp, %ebp
xorl %r8d, %r8d
shll $0x8, %r12d
xorl %edi, %edi
jmp 0x5a2c3
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl %ebx, %eax
shll $0x8, %eax
cmpl $0x10000, %ebx          # imm = 0x10000
movl %eax, %ebx
jb 0x5a250
movzwl (%r15), %edi
movq 0x18(%rsp), %rbx
movl (%rbx), %r8d
movl %r12d, %r11d
jmp 0x5a2f1
movl %ebx, %eax
movl %r12d, %r11d
movq 0x18(%rsp), %rbx
addl $0x10, %edi
movw %di, (%r15)
addl $0x10, %r8d
movl %r8d, (%rbx)
cmpl $0xfff0, %r8d           # imm = 0xFFF0
movq 0x50(%rsp), %r12
movq 0x58(%rsp), %r10
jb 0x5a34f
movl $0x0, (%rbx)
movzwl 0x8(%rbx), %edx
testw %dx, %dx
je 0x5a34f
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 0x5a328
movl %edi, (%rbx)
movzwl (%r15), %edi
cmpw -0x4(%r15), %di
jbe 0x5a367
movq -0x4(%r15), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, -0x4(%r15)
movb (%r12,%r10), %dl
incq %r10
cmpq 0x48(%rsp), %r10
jne 0x5a1d2
shrl $0x1f, 0xc(%rsp)
xorl %r15d, %r15d
jmp 0x5a397
movq %rdi, %r13
xorl %esi, %esi
xorl %ecx, %ecx
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
xorl %r11d, %r11d
movl $0x5, %ebx
cmpl $0xff000000, %r11d      # imm = 0xFF000000
setae %dl
testl %esi, %esi
sete %al
andb %dl, %al
movl %ebp, %ebp
movq %r9, %rdx
subq %r13, %rdx
movl %ebx, %edi
testb %al, %al
jne 0x5a3c6
cmpq %rbp, %rdx
jg 0x5a3ca
decl %edi
jne 0x5a3b7
jmp 0x5a422
incl %ebp
jmp 0x5a40a
addl %esi, %ecx
leaq 0x1(%r13), %rdi
movb %cl, (%r13)
testq %rbp, %rbp
je 0x5a3ff
decb %sil
movzbl %sil, %esi
movq %rbp, %rdx
movq %r9, %r14
movl %r11d, %r12d
callq 0x4260
movl %r12d, %r11d
movq %r14, %r9
leal -0x1(%rbp), %eax
leaq (%rax,%r13), %rdi
addq $0x2, %rdi
movl %r11d, %ecx
shrl $0x18, %ecx
xorl %ebp, %ebp
movq %rdi, %r13
shll $0x8, %r11d
incl %r15d
decl %ebx
xorl %esi, %esi
cmpl $0x5, %r15d
jne 0x5a39c
cmpb $0x0, 0xc(%rsp)
je 0x5a44a
movq 0x38(%rsp), %rdi
callq 0x45c0
movq 0x10(%rsp), %rdi
callq 0x7e26a
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl 0x20(%rsp), %r13d
incl %r13d
movq 0x30(%rsp), %rax
movl %r13d, (%rax)
movq 0x10(%rsp), %rdi
callq 0x7e26a
movq 0x28(%rsp), %rbx
jmp 0x5a438