// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_compress_O1_RLE
static
unsigned char *arith_compress_O1_RLE(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 =
        htscodecs_tls_alloc(256 * sizeof(*byte_model));
    if (!byte_model) {
        free(out_free);
        return NULL;
    }
    for (i = 0; i < 256; i++)
        SIMPLE_MODEL(256,_init)(&byte_model[i], m);

    SIMPLE_MODEL(NSYM,_) *run_model =
        htscodecs_tls_alloc(NSYM * sizeof(*run_model));
    if (!run_model) {
        htscodecs_tls_free(byte_model);
        free(out_free);
        return NULL;
    }
    for (i = 0; i < NSYM; i++)
        SIMPLE_MODEL(NSYM,_init)(&run_model[i], MAX_RUN);

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

    unsigned char last = 0;
    for (i = 0; i < in_size;) {
        //SIMPLE_MODEL(256, _encodeSymbol)(&byte_model, &rc, in[i]);
        SIMPLE_MODEL(256, _encodeSymbol)(&byte_model[last], &rc, in[i]);
        //fprintf(stderr, "lit %c (ctx %c)\n", in[i], last);
        int run = 0;
        last = in[i++];
        while (i < in_size && in[i] == last/* && run < MAX_RUN-1*/)
            run++, i++;
        int rctx = last;
        do {
            int c = run < MAX_RUN ? run : MAX_RUN-1;
            SIMPLE_MODEL(NSYM, _encodeSymbol)(&run_model[rctx], &rc, c);
            run -= c;

            if (rctx == last)
                rctx = 256;
            else
                rctx += (rctx < NSYM-1);
            if (c == MAX_RUN-1 && run == 0)
                SIMPLE_MODEL(NSYM, _encodeSymbol)(&run_model[rctx], &rc, 0);
        } while (run);
    }

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

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

    //fprintf(stderr, "RLE %d to %d\n", in_size, *out_size);

    htscodecs_tls_free(byte_model);
    htscodecs_tls_free(run_model);
    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rcx, %rbx
movl %esi, %ebp
movl %esi, %r14d
cvtsi2sd %r14, %xmm0
mulsd 0x4169c(%rip), %xmm0    # 0x9ada8
addsd 0x42304(%rip), %xmm0    # 0x9ba18
addsd 0x422f4(%rip), %xmm0    # 0x9ba10
addsd 0x422fc(%rip), %xmm0    # 0x9ba20
cvttsd2si %xmm0, %rcx
addl $-0x5, %ecx
testq %rdx, %rdx
movq %rdi, 0x60(%rsp)
je 0x59741
xorl %eax, %eax
cmpl (%rbx), %ecx
jbe 0x5975b
jmp 0x59fe7
movl %ecx, (%rbx)
movl %ecx, %edi
callq 0x4680
movq 0x60(%rsp), %rdi
movq %rax, %rdx
testq %rax, %rax
je 0x59fe5
testl %ebp, %ebp
movl %ebp, 0x14(%rsp)
movq %rax, 0x50(%rsp)
movq %rbx, %r15
je 0x59782
xorl %eax, %eax
xorl %ebx, %ebx
movzbl (%rdi,%rax), %ecx
cmpl %ecx, %ebx
cmovbel %ecx, %ebx
incq %rax
cmpq %rax, %r14
jne 0x5976f
jmp 0x59784
xorl %ebx, %ebx
leal 0x1(%rbx), %ebp
movq %rdx, 0x70(%rsp)
movb %bpl, (%rdx)
movl $0x41000, %edi          # imm = 0x41000
callq 0x7e144
testq %rax, %rax
je 0x59fdb
movq %rax, %r14
movl %ebp, %eax
leaq 0xa(%r14), %rcx
xorl %edx, %edx
movl $0xffef, %esi           # imm = 0xFFEF
imulq $0x410, %rdx, %rdi      # imm = 0x410
addq %r14, %rdi
xorl %r8d, %r8d
movw %r8w, (%rcx,%r8,4)
movw $0x1, -0x2(%rcx,%r8,4)
incq %r8
cmpq %r8, %rax
jne 0x597bf
movq %rax, %r8
cmpl $0xfe, %ebx
ja 0x597f8
movw %r8w, (%rcx,%r8,4)
movw $0x0, -0x2(%rcx,%r8,4)
incq %r8
cmpq $0x100, %r8             # imm = 0x100
jne 0x597df
movl %ebp, (%rdi)
movl %esi, 0x4(%rdi)
movl %esi, 0x40c(%rdi)
movw $0x0, 0x408(%rdi)
incq %rdx
addq $0x410, %rcx            # imm = 0x410
cmpq $0x100, %rdx            # imm = 0x100
jne 0x597b2
movl $0x42030, %edi          # imm = 0x42030
callq 0x7e144
testq %rax, %rax
je 0x59f16
movq %rax, 0x18(%rsp)
addq $0x1a, %rax
xorl %ecx, %ecx
movdqa 0x421eb(%rip), %xmm0    # 0x9ba30
movabsq $0xffef00000004, %rdx   # imm = 0xFFEF00000004
movl 0x14(%rsp), %r9d
imulq $0x418, %rcx, %rdi      # imm = 0x418
movq 0x18(%rsp), %r8
leaq (%r8,%rdi), %rsi
movdqu %xmm0, 0x8(%r8,%rdi)
xorl %edi, %edi
leal 0x4(%rdi), %r8d
movw %r8w, (%rax,%rdi,4)
movw $0x0, -0x2(%rax,%rdi,4)
incq %rdi
cmpq $0xfe, %rdi
jne 0x5986d
movq %rdx, (%rsi)
movl $0xffef, 0x414(%rsi)    # imm = 0xFFEF
movw $0x0, 0x410(%rsi)
incq %rcx
addq $0x418, %rax            # imm = 0x418
cmpq $0x102, %rcx            # imm = 0x102
jne 0x59854
movq 0x70(%rsp), %rax
leaq 0x1(%rax), %rdx
movq %r15, 0x90(%rsp)
movl (%r15), %r11d
addq %rax, %r11
movl $0x0, 0x10(%rsp)
testl %r9d, %r9d
movq %r11, 0x48(%rsp)
movq %rdx, 0x88(%rsp)
je 0x59f1e
movq %r14, 0x58(%rsp)
leaq 0xc(%r14), %rax
movq %rax, 0x98(%rsp)
movl %r9d, %eax
negl %eax
movq %rax, 0xa0(%rsp)
movq 0x18(%rsp), %rax
addq $0xc, %rax
movq %rax, 0x78(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq $0x0, 0x38(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x8(%rsp)
xorl %r10d, %r10d
xorl %esi, %esi
xorl %ecx, %ecx
xorl %edi, %edi
movq %rdx, %r9
movzbl 0x38(%rsp), %edx
imulq $0x410, %rdx, %r13      # imm = 0x410
movl %edi, 0xc(%rsp)
movslq %edi, %rdi
movq 0x60(%rsp), %rdx
movq %rdi, 0x30(%rsp)
movzbl (%rdx,%rdi), %edx
movq 0x58(%rsp), %rdi
leaq (%rdi,%r13), %r12
addq $0x8, %r12
cmpw %dx, 0xa(%rdi,%r13)
jne 0x59971
xorl %r15d, %r15d
jmp 0x59989
xorl %r15d, %r15d
movq %r12, %rdi
movzwl (%r12), %r8d
addq $0x4, %r12
addl %r8d, %r15d
cmpw %dx, 0x6(%rdi)
jne 0x59974
movq 0x58(%rsp), %rdx
addq %r13, %rdx
movzwl (%r12), %edi
movq %rdx, 0x28(%rsp)
movl (%rdx), %r8d
xorl %edx, %edx
divl %r8d
movl %eax, %r14d
imull %eax, %r15d
imull %edi, %r14d
addl %ebp, %r15d
adcl $0x0, %ecx
cmpl $0xffffff, %r14d        # imm = 0xFFFFFF
ja 0x59a62
movl %ecx, %r8d
movl %ecx, %edi
cmpl $0xff000000, %r15d      # imm = 0xFF000000
jb 0x599d8
testl %edi, %edi
jne 0x599d8
incl %r10d
jmp 0x59a25
movl %r10d, %edx
movq %r11, %rax
subq %r9, %rax
cmpq %rdx, %rax
jle 0x59a2d
addl %esi, %r8d
leaq 0x1(%r9), %rdi
movb %r8b, (%r9)
testl %r10d, %r10d
je 0x59a14
decb %cl
movzbl %cl, %esi
movq %r9, %rbx
movq %r10, %rbp
callq 0x4260
movq 0x48(%rsp), %r11
decl %ebp
leaq (%rbx,%rbp), %rdi
addq $0x2, %rdi
movl %r15d, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r9
xorl %r10d, %r10d
xorl %r8d, %r8d
shll $0x8, %r15d
xorl %edi, %edi
jmp 0x59a35
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl %r14d, %eax
shll $0x8, %eax
cmpl $0x10000, %r14d         # imm = 0x10000
movl %eax, %r14d
jb 0x599c6
movq %r10, 0x20(%rsp)
movzwl (%r12), %edi
movq 0x28(%rsp), %rbx
movl (%rbx), %r8d
movl %r15d, %ebp
jmp 0x59a72
movq %r10, 0x20(%rsp)
movl %r14d, %eax
movl %r15d, %ebp
movq 0x28(%rsp), %rbx
addl $0x10, %edi
movw %di, (%r12)
addl $0x10, %r8d
movl %r8d, (%rbx)
cmpl $0xfff0, %r8d           # imm = 0xFFF0
movq 0x18(%rsp), %r10
jb 0x59ad1
movl $0x0, (%rbx)
movzwl 0x8(%rbx), %edx
testw %dx, %dx
je 0x59ad1
addq 0x98(%rsp), %r13
xorl %edi, %edi
movzwl %dx, %r8d
shrl %r8d
subl %r8d, %edx
movw %dx, -0x4(%r13)
movzwl %dx, %edx
addl %edx, %edi
movzwl (%r13), %edx
addq $0x4, %r13
testw %dx, %dx
jne 0x59aa8
movl %edi, (%rbx)
movzwl (%r12), %edi
cmpw -0x4(%r12), %di
jbe 0x59aec
movq -0x4(%r12), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, -0x4(%r12)
movq 0x60(%rsp), %rdi
movq 0x30(%rsp), %r12
movb (%rdi,%r12), %dl
movq %rdx, 0x38(%rsp)
incq %r12
xorl %r15d, %r15d
movl 0x14(%rsp), %edx
cmpl %edx, %r12d
jae 0x59b52
movl 0xc(%rsp), %r8d
notl %r8d
movl %r8d, %r15d
addl %edx, %r15d
movq %r12, %rdx
addq %rdi, %rdx
movl %r12d, %edi
addq 0xa0(%rsp), %rdi
xorl %r8d, %r8d
movq 0x38(%rsp), %rbx
cmpb %bl, (%rdx,%r8)
jne 0x59b57
incq %r8
movq %r9, %r14
movl %edi, %r9d
addl %r8d, %r9d
movq %r14, %r9
jne 0x59b30
movl 0x14(%rsp), %edi
jmp 0x59b5e
movl %r12d, %edi
jmp 0x59b5e
leal (%r12,%r8), %edi
movl %r8d, %r15d
movzbl 0x38(%rsp), %edx
movl %edx, 0x6c(%rsp)
movl %edx, %r14d
movl %edi, 0xc(%rsp)
cmpl $0x3, %r15d
movl $0x3, %r8d
movl %r15d, 0x30(%rsp)
cmovll %r15d, %r8d
movslq %r14d, %rdx
imulq $0x418, %rdx, %r15      # imm = 0x418
leaq (%r10,%r15), %r12
addq $0x8, %r12
xorl %r13d, %r13d
cmpw %r8w, 0xa(%r10,%r15)
movl %r14d, 0x28(%rsp)
movl %r8d, 0x40(%rsp)
je 0x59bc1
xorl %r13d, %r13d
movq %r12, %rdx
movzwl (%r12), %edi
addq $0x4, %r12
addl %edi, %r13d
cmpw %r8w, 0x6(%rdx)
jne 0x59bab
leaq (%r10,%r15), %rdx
movzwl (%r12), %edi
movq %rdx, 0x80(%rsp)
movl (%rdx), %r8d
xorl %edx, %edx
divl %r8d
movl %eax, %r14d
imull %eax, %r13d
imull %edi, %r14d
addl %ebp, %r13d
adcl $0x0, %ecx
cmpl $0xffffff, %r14d        # imm = 0xFFFFFF
ja 0x59c93
movl %ecx, %r8d
movl %ecx, %edi
movq 0x20(%rsp), %rbx
cmpl $0xff000000, %r13d      # imm = 0xFF000000
jb 0x59c13
testl %edi, %edi
jne 0x59c13
incl %ebx
jmp 0x59c5a
movl %ebx, %edx
movq %r11, %rax
subq %r9, %rax
cmpq %rdx, %rax
jle 0x59c62
addl %esi, %r8d
leaq 0x1(%r9), %rdi
movb %r8b, (%r9)
testl %ebx, %ebx
je 0x59c4a
decb %cl
movzbl %cl, %esi
movq %r9, %rbp
callq 0x4260
movq 0x48(%rsp), %r11
decl %ebx
leaq (%rbx,%rbp), %rdi
addq $0x2, %rdi
movl %r13d, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r9
xorl %ebx, %ebx
xorl %r8d, %r8d
shll $0x8, %r13d
xorl %edi, %edi
jmp 0x59c6a
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl %r14d, %eax
shll $0x8, %eax
cmpl $0x10000, %r14d         # imm = 0x10000
movl %eax, %r14d
jb 0x59c02
movq %rbx, 0x20(%rsp)
movzwl (%r12), %edi
movq 0x80(%rsp), %r14
movl (%r14), %r8d
jmp 0x59c9e
movl %r14d, %eax
movq 0x80(%rsp), %r14
addl $0x10, %edi
movw %di, (%r12)
addl $0x10, %r8d
movl %r8d, (%r14)
cmpl $0xfff0, %r8d           # imm = 0xFFF0
movq 0x18(%rsp), %r10
movl 0x28(%rsp), %ebx
jb 0x59d06
movl $0x0, (%r14)
movzwl 0x8(%r14), %edx
testw %dx, %dx
movl 0x40(%rsp), %ebp
je 0x59d0a
addq 0x78(%rsp), %r15
xorl %edi, %edi
movzwl %dx, %r8d
shrl %r8d
subl %r8d, %edx
movw %dx, -0x4(%r15)
movzwl %dx, %edx
addl %edx, %edi
movzwl (%r15), %edx
addq $0x4, %r15
testw %dx, %dx
jne 0x59cdb
movl %edi, (%r14)
movzwl (%r12), %edi
jmp 0x59d0a
movl 0x40(%rsp), %ebp
cmpw -0x4(%r12), %di
jbe 0x59d25
movq -0x4(%r12), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, -0x4(%r12)
xorl %edx, %edx
cmpl $0x101, %ebx            # imm = 0x101
setl %dl
addl %ebx, %edx
cmpl 0x6c(%rsp), %ebx
movl %edx, %r14d
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %r14d
movl 0x30(%rsp), %r15d
cmpl $0x3, %r15d
setge %dl
subl %ebp, %r15d
sete %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x59d97
movl %r15d, 0x30(%rsp)
movslq %r14d, %rdx
imulq $0x418, %rdx, %r15      # imm = 0x418
leaq (%r10,%r15), %rbx
addq $0x8, %rbx
cmpw $0x0, 0xa(%r10,%r15)
movl %r14d, 0x28(%rsp)
je 0x59da3
xorl %ebp, %ebp
movzwl (%rbx), %edx
addl %edx, %ebp
cmpw $0x0, 0x6(%rbx)
leaq 0x4(%rbx), %rbx
jne 0x59d85
jmp 0x59da5
movl %r13d, %ebp
movl 0xc(%rsp), %edi
jmp 0x59ef2
xorl %ebp, %ebp
addq %r15, %r10
movzwl (%rbx), %edi
movl (%r10), %r8d
xorl %edx, %edx
divl %r8d
movl %eax, %r14d
imull %eax, %ebp
imull %edi, %r14d
addl %r13d, %ebp
adcl $0x0, %ecx
cmpl $0xffffff, %r14d        # imm = 0xFFFFFF
ja 0x59e6d
movq %r10, 0x40(%rsp)
movl %ecx, %r8d
movl %ecx, %edi
movq 0x20(%rsp), %r12
cmpl $0xff000000, %ebp       # imm = 0xFF000000
jb 0x59df0
testl %edi, %edi
jne 0x59df0
incl %r12d
jmp 0x59e3a
movl %r12d, %edx
movq %r11, %rax
subq %r9, %rax
cmpq %rdx, %rax
jle 0x59e41
addl %esi, %r8d
leaq 0x1(%r9), %rdi
movb %r8b, (%r9)
testl %r12d, %r12d
je 0x59e2a
decb %cl
movzbl %cl, %esi
movq %r9, %r13
callq 0x4260
movq 0x48(%rsp), %r11
decl %r12d
leaq (%r12,%r13), %rdi
addq $0x2, %rdi
movl %ebp, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r9
xorl %r12d, %r12d
xorl %r8d, %r8d
shll $0x8, %ebp
xorl %edi, %edi
jmp 0x59e49
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl %r14d, %eax
shll $0x8, %eax
cmpl $0x10000, %r14d         # imm = 0x10000
movl %eax, %r14d
jb 0x59ddf
movq %r12, 0x20(%rsp)
movzwl (%rbx), %edi
movq 0x40(%rsp), %r10
movl (%r10), %r8d
jmp 0x59e70
movl %r14d, %eax
addl $0x10, %edi
movw %di, (%rbx)
addl $0x10, %r8d
movl %r8d, (%r10)
cmpl $0xfff0, %r8d           # imm = 0xFFF0
movq %r10, %rdx
movq 0x18(%rsp), %r10
movl 0x28(%rsp), %r14d
jb 0x59ed4
movl $0x0, (%rdx)
movq %rdx, %r12
movzwl 0x8(%rdx), %edx
testw %dx, %dx
je 0x59ed4
addq 0x78(%rsp), %r15
xorl %edi, %edi
movzwl %dx, %r8d
shrl %r8d
subl %r8d, %edx
movw %dx, -0x4(%r15)
movzwl %dx, %edx
addl %edx, %edi
movzwl (%r15), %edx
addq $0x4, %r15
testw %dx, %dx
jne 0x59eac
movl %edi, (%r12)
movzwl (%rbx), %edi
cmpw -0x4(%rbx), %di
jbe 0x59ee9
movq -0x4(%rbx), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, -0x4(%rbx)
movl 0xc(%rsp), %edi
movl 0x30(%rsp), %r15d
testl %r15d, %r15d
jne 0x59b6e
cmpl 0x14(%rsp), %edi
movq 0x20(%rsp), %r10
jb 0x59936
shrl $0x1f, 0x8(%rsp)
movq 0x58(%rsp), %r14
jmp 0x59f32
movq %r14, %rdi
jmp 0x59fd6
movq %rdx, %r9
xorl %ecx, %ecx
xorl %esi, %esi
xorl %r10d, %r10d
movl $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movl $0x5, %ebx
cmpl $0xff000000, %ebp       # imm = 0xFF000000
setae %dl
testl %ecx, %ecx
sete %al
andb %dl, %al
movl %r10d, %r10d
movq %r11, %rdx
subq %r9, %rdx
movl %ebx, %edi
testb %al, %al
jne 0x59f61
cmpq %r10, %rdx
jg 0x59f6a
decl %edi
jne 0x59f52
jmp 0x59fc9
incl %r10d
movl 0x10(%rsp), %eax
jmp 0x59fac
addl %ecx, %esi
leaq 0x1(%r9), %rdi
movb %sil, (%r9)
testq %r10, %r10
je 0x59f9d
decb %cl
movzbl %cl, %esi
movq %r10, %rdx
movq %r9, %r15
movq %r10, %r12
callq 0x4260
movq 0x48(%rsp), %r11
leal -0x1(%r12), %eax
leaq (%r15,%rax), %rdi
addq $0x2, %rdi
movl 0x10(%rsp), %eax
movl %ebp, %esi
shrl $0x18, %esi
xorl %r10d, %r10d
movq %rdi, %r9
shll $0x8, %ebp
incl %eax
decl %ebx
xorl %ecx, %ecx
movl %eax, 0x10(%rsp)
cmpl $0x5, %eax
jne 0x59f37
cmpb $0x0, 0x8(%rsp)
je 0x59ff9
movq %r14, %rdi
callq 0x7e26a
movq 0x18(%rsp), %rdi
callq 0x7e26a
movq 0x50(%rsp), %rdi
callq 0x45c0
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl 0x88(%rsp), %r9d
incl %r9d
movq 0x90(%rsp), %rax
movl %r9d, (%rax)
movq %r14, %rdi
callq 0x7e26a
movq 0x18(%rsp), %rdi
callq 0x7e26a
movq 0x70(%rsp), %rax
jmp 0x59fe7