// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_compress_O0_RLE
static
unsigned char *arith_compress_O0_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;
    SIMPLE_MODEL(256,_init)(&byte_model, m);

    SIMPLE_MODEL(NSYM,_) *run_model =
        htscodecs_tls_alloc(NSYM * sizeof(*run_model));
    if (!run_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, &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(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(run_model);
    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x498, %rsp            # imm = 0x498
movq %rcx, %r12
movq %rdi, 0x48(%rsp)
movl %esi, 0x1c(%rsp)
movl %esi, %ebx
cvtsi2sd %rbx, %xmm0
mulsd 0x4225f(%rip), %xmm0    # 0x9dbb0
addsd 0x42ebf(%rip), %xmm0    # 0x9e818
addsd 0x42217(%rip), %xmm0    # 0x9db78
addsd 0x42eb7(%rip), %xmm0    # 0x9e820
cvttsd2si %xmm0, %r14
addl $-0x5, %r14d
testq %rdx, %rdx
je 0x5b97e
movq %rdx, %r15
xorl %eax, %eax
jmp 0x5b98d
movl %r14d, (%r12)
movl %r14d, %edi
callq 0x4680
movq %rax, %r15
testq %r15, %r15
je 0x5c188
cmpl (%r12), %r14d
ja 0x5c188
movq %rax, 0x50(%rsp)
cmpl $0x0, 0x1c(%rsp)
je 0x5b9cc
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x48(%rsp), %rsi
movl %ecx, %edx
movzbl (%rsi,%rax), %ecx
cmpl %ecx, %edx
cmoval %edx, %ecx
incq %rax
cmpq %rax, %rbx
jne 0x5b9b5
incl %ecx
jmp 0x5b9d1
movl $0x1, %ecx
movl %ecx, %eax
movb %cl, (%r15)
xorl %ecx, %ecx
movw %cx, 0x92(%rsp,%rcx,4)
movw $0x1, 0x90(%rsp,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x5b9d8
leaq -0x1(%rcx), %rdx
cmpq $0xfe, %rdx
ja 0x5ba1d
movw %cx, 0x92(%rsp,%rcx,4)
movw $0x0, 0x90(%rsp,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x5b9ff
movl %eax, 0x88(%rsp)
movl $0xffef, %eax           # imm = 0xFFEF
movl %eax, 0x8c(%rsp)
movl %eax, 0x494(%rsp)
movw $0x0, 0x490(%rsp)
movl $0x42030, %edi          # imm = 0x42030
callq 0x8060c
testq %rax, %rax
je 0x5c17e
movq %rax, %r14
addq $0xa, %rax
leaq 0x1a(%r14), %rcx
xorl %edx, %edx
movabsq $0xffef00000004, %rsi   # imm = 0xFFEF00000004
movl $0x418, %edi            # imm = 0x418
imulq $0x418, %rdx, %r8       # imm = 0x418
addq %r14, %r8
xorl %r9d, %r9d
movw %r9w, (%rax,%r9,4)
movw $0x1, -0x2(%rax,%r9,4)
incq %r9
cmpq $0x4, %r9
jne 0x5ba7d
xorl %r9d, %r9d
leal 0x4(%r9), %r10d
movw %r10w, (%rcx,%r9,4)
movw $0x0, -0x2(%rcx,%r9,4)
incq %r9
cmpq $0xfe, %r9
jne 0x5ba96
movq %rsi, (%r8)
movl $0xffef, 0x414(%r8) # imm = 0xFFEF
movw $0x0, 0x410(%r8)
incq %rdx
addq %rdi, %rax
addq %rdi, %rcx
cmpq $0x102, %rdx            # imm = 0x102
jne 0x5ba70
leaq 0x1(%r15), %rdx
movq %r12, 0x70(%rsp)
movl (%r12), %r11d
movq %r15, 0x78(%rsp)
addq %r15, %r11
movl 0x1c(%rsp), %eax
testl %eax, %eax
movq %r11, 0x40(%rsp)
movq %rdx, 0x68(%rsp)
je 0x5c0cb
negl %eax
movq %rax, 0x80(%rsp)
leaq 0xc(%r14), %rax
movq %rax, 0x58(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %esi, %esi
xorl %ecx, %ecx
movq %rdx, %r8
movq %r14, 0x60(%rsp)
movslq %r13d, %rdi
movq 0x48(%rsp), %rdx
movq %rdi, 0x10(%rsp)
movzbl (%rdx,%rdi), %edx
leaq 0x90(%rsp), %r15
movl $0x0, %edi
cmpw %dx, 0x92(%rsp)
je 0x5bb83
movq %r8, %rbx
movl %r9d, %ebp
xorl %edi, %edi
movq %r15, %r8
movzwl (%r15), %r9d
addq $0x4, %r15
addl %r9d, %edi
cmpw %dx, 0x6(%r8)
jne 0x5bb68
movl %ebp, %r9d
movq %rbx, %r8
movzwl (%r15), %ebp
xorl %edx, %edx
divl 0x88(%rsp)
imull %eax, %edi
imull %eax, %ebp
addl %edi, %r12d
adcl $0x0, %ecx
cmpl $0xffffff, %ebp         # imm = 0xFFFFFF
movq %r13, 0x28(%rsp)
ja 0x5bc37
cmpl $0xff000000, %r12d      # imm = 0xFF000000
jb 0x5bbbf
testl %ecx, %ecx
jne 0x5bbbf
incl %r10d
jmp 0x5bc16
movl %r10d, %edx
movq %r11, %rax
subq %r8, %rax
cmpq %rdx, %rax
jle 0x5bc1c
addl %ecx, %esi
leaq 0x1(%r8), %rdi
movb %sil, (%r8)
testl %r10d, %r10d
je 0x5bc0b
decb %cl
movzbl %cl, %esi
movq %r10, %r13
movl %r9d, %ebx
movq %r8, 0x30(%rsp)
callq 0x4260
movl %ebx, %r9d
movq 0x40(%rsp), %r11
decl %r13d
movq 0x30(%rsp), %rax
leaq (%rax,%r13), %rdi
addq $0x2, %rdi
xorl %r10d, %r10d
movl %r12d, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r8
shll $0x8, %r12d
jmp 0x5bc22
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %ebp, %eax
shll $0x8, %eax
cmpl $0x10000, %ebp          # imm = 0x10000
movl %eax, %ebp
jb 0x5bbad
jmp 0x5bc39
movl %ebp, %eax
addw $0x10, (%r15)
movl 0x88(%rsp), %edx
addl $0x10, %edx
movl %edx, 0x88(%rsp)
cmpl $0xfff0, %edx           # imm = 0xFFF0
movl %r9d, %ebp
jb 0x5bcad
movl $0x0, 0x88(%rsp)
movzwl 0x90(%rsp), %edx
testw %dx, %dx
je 0x5bcad
movq %r8, %rbx
xorl %edi, %edi
leaq 0x94(%rsp), %r8
movzwl %dx, %r9d
shrl %r9d
subl %r9d, %edx
movw %dx, -0x4(%r8)
movzwl %dx, %edx
addl %edx, %edi
movzwl (%r8), %edx
addq $0x4, %r8
testw %dx, %dx
jne 0x5bc7f
movl %edi, 0x88(%rsp)
movl %ebp, %r9d
movq %rbx, %r8
movq %r10, %r13
movzwl (%r15), %edx
cmpw -0x4(%r15), %dx
jbe 0x5bcc0
rolq $0x20, -0x4(%r15)
movq 0x48(%rsp), %rdi
movq 0x10(%rsp), %r15
movzbl (%rdi,%r15), %edx
movl %edx, 0x20(%rsp)
incq %r15
xorl %ebx, %ebx
movl 0x1c(%rsp), %r10d
cmpl %r10d, %r15d
jae 0x5bd36
movq %r8, %rbx
movq 0x28(%rsp), %rdx
notl %edx
addl %r10d, %edx
movl %edx, 0xc(%rsp)
movq %r15, %rdx
addq %rdi, %rdx
movq %r15, 0x10(%rsp)
movl %r15d, %edi
addq 0x80(%rsp), %rdi
xorl %r8d, %r8d
movl 0x20(%rsp), %r15d
cmpb %r15b, (%rdx,%r8)
jne 0x5bd40
incq %r8
movl %edi, %r9d
addl %r8d, %r9d
movl %ebp, %r9d
jne 0x5bd0c
movl %r10d, %edx
movq %rdx, 0x28(%rsp)
movq %rbx, %r8
movl 0xc(%rsp), %ebx
jmp 0x5bd55
movl %r15d, %edx
movq %rdx, 0x28(%rsp)
jmp 0x5bd55
movq 0x10(%rsp), %rdx
addl %r8d, %edx
movq %rdx, 0x28(%rsp)
movl %r8d, %edx
movq %rbx, %r8
movl %edx, %ebx
movl 0x20(%rsp), %ebp
movq %r13, %r10
cmpl $0x3, %ebx
movl $0x3, %r15d
movl %ebx, 0xc(%rsp)
cmovll %ebx, %r15d
movl %ebp, 0x24(%rsp)
movslq %ebp, %rdx
imulq $0x418, %rdx, %rbp      # imm = 0x418
leaq (%r14,%rbp), %rbx
addq $0x8, %rbx
xorl %r13d, %r13d
cmpw %r15w, 0xa(%r14,%rbp)
je 0x5bda5
xorl %r13d, %r13d
movq %rbx, %rdx
movzwl (%rbx), %edi
addq $0x4, %rbx
addl %edi, %r13d
cmpw %r15w, 0x6(%rdx)
jne 0x5bd91
leaq (%r14,%rbp), %rdi
movzwl (%rbx), %r14d
xorl %edx, %edx
movq %rdi, 0x10(%rsp)
divl (%rdi)
imull %eax, %r13d
imull %eax, %r14d
addl %r12d, %r13d
adcl $0x0, %ecx
cmpl $0xffffff, %r14d        # imm = 0xFFFFFF
movl %r15d, 0x3c(%rsp)
ja 0x5be72
movq 0x10(%rsp), %r12
cmpl $0xff000000, %r13d      # imm = 0xFF000000
jb 0x5bded
testl %ecx, %ecx
jne 0x5bded
incl %r10d
jmp 0x5be4e
movl %r10d, %edx
movq %r11, %rax
subq %r8, %rax
cmpq %rdx, %rax
jle 0x5be54
addl %ecx, %esi
leaq 0x1(%r8), %rdi
movb %sil, (%r8)
testl %r10d, %r10d
je 0x5be43
decb %cl
movzbl %cl, %esi
movq %r10, %r12
movl %r9d, %r15d
movq %r8, 0x30(%rsp)
callq 0x4260
movl %r15d, %r9d
movl 0x3c(%rsp), %r15d
movq 0x40(%rsp), %r11
decl %r12d
movq 0x30(%rsp), %rax
leaq (%rax,%r12), %rdi
addq $0x2, %rdi
movq 0x10(%rsp), %r12
xorl %r10d, %r10d
movl %r13d, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r8
shll $0x8, %r13d
jmp 0x5be5a
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %r14d, %eax
shll $0x8, %eax
cmpl $0x10000, %r14d         # imm = 0x10000
movl %eax, %r14d
jb 0x5bddb
jmp 0x5be7a
movl %r14d, %eax
movq 0x10(%rsp), %r12
addw $0x10, (%rbx)
movl (%r12), %edx
addl $0x10, %edx
movl %edx, (%r12)
cmpl $0xfff0, %edx           # imm = 0xFFF0
movq 0x60(%rsp), %r14
jb 0x5bedf
movl $0x0, (%r12)
movzwl 0x8(%r12), %edx
testw %dx, %dx
je 0x5bedf
movq %r8, %r15
addq 0x58(%rsp), %rbp
xorl %edi, %edi
movzwl %dx, %r8d
shrl %r8d
subl %r8d, %edx
movw %dx, -0x4(%rbp)
movzwl %dx, %edx
addl %edx, %edi
movzwl (%rbp), %edx
addq $0x4, %rbp
testw %dx, %dx
jne 0x5beb3
movl %edi, (%r12)
movq %r15, %r8
movl 0x3c(%rsp), %r15d
movzwl (%rbx), %edx
cmpw -0x4(%rbx), %dx
jbe 0x5beed
rolq $0x20, -0x4(%rbx)
xorl %edx, %edx
movl 0x24(%rsp), %edi
cmpl $0x101, %edi            # imm = 0x101
setl %dl
addl %edi, %edx
cmpl 0x20(%rsp), %edi
movl %edx, %ebp
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %ebp
movl 0xc(%rsp), %ebx
cmpl $0x3, %ebx
setge %dl
subl %r15d, %ebx
sete %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x5bf5d
movl %ebx, 0xc(%rsp)
movslq %ebp, %rdx
imulq $0x418, %rdx, %rbx      # imm = 0x418
leaq (%r14,%rbx), %r15
addq $0x8, %r15
cmpw $0x0, 0xa(%r14,%rbx)
je 0x5bf65
xorl %r12d, %r12d
movzwl (%r15), %edx
addl %edx, %r12d
cmpw $0x0, 0x6(%r15)
leaq 0x4(%r15), %r15
jne 0x5bf48
jmp 0x5bf68
movl %r13d, %r12d
jmp 0x5c0b1
xorl %r12d, %r12d
leaq (%r14,%rbx), %rdi
movzwl (%r15), %r14d
xorl %edx, %edx
movq %rdi, 0x10(%rsp)
divl (%rdi)
imull %eax, %r12d
imull %eax, %r14d
addl %r13d, %r12d
adcl $0x0, %ecx
cmpl $0xffffff, %r14d        # imm = 0xFFFFFF
ja 0x5c033
movq 0x10(%rsp), %r13
movl %ebp, 0x24(%rsp)
cmpl $0xff000000, %r12d      # imm = 0xFF000000
jb 0x5bfaf
testl %ecx, %ecx
jne 0x5bfaf
incl %r10d
jmp 0x5c00f
movl %r10d, %edx
movq %r11, %rax
subq %r8, %rax
cmpq %rdx, %rax
jle 0x5c015
addl %ecx, %esi
leaq 0x1(%r8), %rdi
movb %sil, (%r8)
testl %r10d, %r10d
je 0x5c004
decb %cl
movzbl %cl, %esi
movq %r10, %r13
movl %r9d, %ebp
movq %r8, 0x30(%rsp)
callq 0x4260
movl %ebp, %r9d
movl 0x24(%rsp), %ebp
movq 0x40(%rsp), %r11
decl %r13d
movq 0x30(%rsp), %rax
leaq (%rax,%r13), %rdi
addq $0x2, %rdi
movq 0x10(%rsp), %r13
xorl %r10d, %r10d
movl %r12d, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r8
shll $0x8, %r12d
jmp 0x5c01b
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %r14d, %eax
shll $0x8, %eax
cmpl $0x10000, %r14d         # imm = 0x10000
movl %eax, %r14d
jb 0x5bf9d
jmp 0x5c03b
movl %r14d, %eax
movq 0x10(%rsp), %r13
addw $0x10, (%r15)
movl (%r13), %edx
addl $0x10, %edx
movl %edx, (%r13)
cmpl $0xfff0, %edx           # imm = 0xFFF0
movq 0x60(%rsp), %r14
jb 0x5c09d
movl $0x0, (%r13)
movzwl 0x8(%r13), %edx
testw %dx, %dx
je 0x5c09d
movq %r8, %r13
addq 0x58(%rsp), %rbx
xorl %edi, %edi
movzwl %dx, %r8d
shrl %r8d
subl %r8d, %edx
movw %dx, -0x4(%rbx)
movzwl %dx, %edx
addl %edx, %edi
movzwl (%rbx), %edx
addq $0x4, %rbx
testw %dx, %dx
jne 0x5c074
movq 0x10(%rsp), %rdx
movl %edi, (%rdx)
movq %r13, %r8
movzwl (%r15), %edx
cmpw -0x4(%r15), %dx
jbe 0x5c0ad
rolq $0x20, -0x4(%r15)
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
jne 0x5bd5c
movq 0x28(%rsp), %r13
cmpl 0x1c(%rsp), %r13d
jb 0x5bb38
jmp 0x5c0db
xorl %ecx, %ecx
movq %rdx, %r8
xorl %esi, %esi
xorl %r10d, %r10d
xorl %r9d, %r9d
xorl %r12d, %r12d
movl $0x5, %ebx
cmpl $0xff000000, %r12d      # imm = 0xFF000000
jb 0x5c0f2
testl %ecx, %ecx
jne 0x5c0f2
incl %r10d
jmp 0x5c142
movl %r10d, %edx
movq %r11, %rax
subq %r8, %rax
cmpq %rdx, %rax
jle 0x5c148
addl %ecx, %esi
leaq 0x1(%r8), %rdi
movb %sil, (%r8)
testl %r10d, %r10d
je 0x5c137
decb %cl
movzbl %cl, %esi
movq %r10, %r15
movl %r9d, %ebp
movq %r8, %r13
callq 0x4260
movl %ebp, %r9d
movq 0x40(%rsp), %r11
decl %r15d
leaq (%r15,%r13), %rdi
addq $0x2, %rdi
xorl %r10d, %r10d
movl %r12d, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r8
shll $0x8, %r12d
jmp 0x5c14e
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
decl %ebx
jne 0x5c0e0
testl %r9d, %r9d
js 0x5c176
subl 0x68(%rsp), %r8d
incl %r8d
movq 0x70(%rsp), %rax
movl %r8d, (%rax)
movq %r14, %rdi
callq 0x80732
movq 0x78(%rsp), %rax
jmp 0x5c18a
movq %r14, %rdi
callq 0x80732
movq 0x50(%rsp), %rdi
callq 0x45c0
xorl %eax, %eax
addq $0x498, %rsp            # imm = 0x498
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq