// File: /workspace/github_c_makefile_star2_O3/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
movl %esi, %ebp
movq %rdx, %rsi
movq %rdi, %r13
movl %ebp, %ebx
cvtsi2sd %rbx, %xmm0
mulsd 0x41f47(%rip), %xmm0    # 0x9ada8
addsd 0x42baf(%rip), %xmm0    # 0x9ba18
addsd 0x42b9f(%rip), %xmm0    # 0x9ba10
addsd 0x42ba7(%rip), %xmm0    # 0x9ba20
cvttsd2si %xmm0, %rdx
addl $-0x5, %edx
testq %rsi, %rsi
je 0x58e91
xorl %eax, %eax
cmpl (%rcx), %edx
jbe 0x58eac
jmp 0x596b5
movl %edx, (%rcx)
movl %edx, %edi
movq %rcx, %r14
callq 0x4680
movq %r14, %rcx
movq %rax, %rsi
testq %rax, %rax
je 0x596b3
movq %rcx, 0x50(%rsp)
testl %ebp, %ebp
je 0x58ece
xorl %ecx, %ecx
xorl %edi, %edi
movzbl (%r13,%rcx), %edx
cmpl %edx, %edi
cmovbel %edx, %edi
incq %rcx
cmpq %rcx, %rbx
jne 0x58eb9
jmp 0x58ed0
xorl %edi, %edi
movl %edi, %ecx
incl %edi
movq %rsi, 0x58(%rsp)
movb %dil, (%rsi)
leaq 0x1(%rcx), %rdx
xorl %esi, %esi
movw %si, 0x92(%rsp,%rsi,4)
movw $0x1, 0x90(%rsp,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x58ee2
movq %rax, 0x60(%rsp)
cmpl $0xfe, %ecx
ja 0x58f2b
leaq 0x1(%rcx), %rdx
movw %dx, 0x96(%rsp,%rcx,4)
movw $0x0, 0x94(%rsp,%rcx,4)
movq %rdx, %rcx
cmpq $0xff, %rdx
jne 0x58f09
movl %edi, 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 0x7e144
testq %rax, %rax
je 0x596a9
movq %rax, %r15
addq $0x1a, %rax
xorl %ecx, %ecx
movdqa 0x42abd(%rip), %xmm0    # 0x9ba30
movabsq $0xffef00000004, %rdx   # imm = 0xFFEF00000004
imulq $0x418, %rcx, %rdi      # imm = 0x418
leaq (%r15,%rdi), %rsi
movdqu %xmm0, 0x8(%r15,%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 0x58f91
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 0x58f7d
movq 0x58(%rsp), %rax
leaq 0x1(%rax), %rdx
movq 0x50(%rsp), %rcx
movl (%rcx), %r11d
addq %rax, %r11
testl %ebp, %ebp
movq %r11, 0x30(%rsp)
movq %rdx, 0x78(%rsp)
je 0x59602
movl %ebp, %eax
negl %eax
movq %rax, 0x80(%rsp)
leaq 0xc(%r15), %rax
movq %rax, 0x70(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
xorl %ebx, %ebx
movl $0x0, 0x4(%rsp)
xorl %r9d, %r9d
xorl %esi, %esi
xorl %ecx, %ecx
movq %rdx, %r10
movq %r15, 0x40(%rsp)
movl %ebp, 0x2c(%rsp)
movq %r13, 0x68(%rsp)
movq %r8, 0x38(%rsp)
movslq %r8d, %rdx
movq %rdx, 0x18(%rsp)
movzbl (%r13,%rdx), %edx
leaq 0x90(%rsp), %r13
movl $0x0, %ebp
cmpw %dx, 0x92(%rsp)
je 0x5907b
xorl %ebp, %ebp
movq %r13, %rdi
movzwl (%r13), %r8d
addq $0x4, %r13
addl %r8d, %ebp
cmpw %dx, 0x6(%rdi)
jne 0x59066
movzwl (%r13), %edi
movl 0x88(%rsp), %r8d
xorl %edx, %edx
divl %r8d
movl %eax, %r15d
imull %eax, %ebp
imull %edi, %r15d
addl %ebx, %ebp
adcl $0x0, %ecx
cmpl $0xffffff, %r15d        # imm = 0xFFFFFF
ja 0x59141
movl %ecx, %r8d
movl %ecx, %edi
movl 0x4(%rsp), %ebx
cmpl $0xff000000, %ebp       # imm = 0xFF000000
jb 0x590c3
testl %edi, %edi
jne 0x590c3
incl %r9d
jmp 0x59110
movl %r9d, %edx
movq %r11, %rax
subq %r10, %rax
cmpq %rdx, %rax
jle 0x59117
addl %esi, %r8d
leaq 0x1(%r10), %rdi
movb %r8b, (%r10)
testl %r9d, %r9d
je 0x59100
decb %cl
movzbl %cl, %esi
movq %r10, %r14
movq %r9, %r12
callq 0x4260
movq 0x30(%rsp), %r11
decl %r12d
leaq (%r14,%r12), %rdi
addq $0x2, %rdi
movl %ebp, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r10
xorl %r9d, %r9d
xorl %r8d, %r8d
shll $0x8, %ebp
xorl %edi, %edi
jmp 0x5911c
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %r15d, %eax
shll $0x8, %eax
cmpl $0x10000, %r15d         # imm = 0x10000
movl %eax, %r15d
jb 0x590b2
movl %ebx, 0x4(%rsp)
movzwl (%r13), %edi
movl 0x88(%rsp), %r8d
jmp 0x59144
movl %r15d, %eax
movl %ebp, %ebx
addl $0x10, %edi
movw %di, (%r13)
addl $0x10, %r8d
movl %r8d, 0x88(%rsp)
cmpl $0xfff0, %r8d           # imm = 0xFFF0
movq 0x40(%rsp), %r15
movq 0x38(%rsp), %r12
movq 0x18(%rsp), %rbp
jb 0x591c7
movl $0x0, 0x88(%rsp)
movzwl 0x90(%rsp), %edx
testw %dx, %dx
je 0x591c7
movq %r9, %r14
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 0x59197
movl %edi, 0x88(%rsp)
movzwl (%r13), %edi
movq %r14, %r9
movq %r10, 0x20(%rsp)
cmpw -0x4(%r13), %di
jbe 0x591e4
movq -0x4(%r13), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, -0x4(%r13)
movq 0x68(%rsp), %rdi
movzbl (%rdi,%rbp), %edx
movl %edx, 0x14(%rsp)
incq %rbp
xorl %r14d, %r14d
movl 0x2c(%rsp), %r10d
cmpl %r10d, %ebp
jae 0x59240
notl %r12d
movl %r12d, %r14d
addl %r10d, %r14d
movq %rbp, %rdx
addq %rdi, %rdx
movq %rbp, %r12
movl %ebp, %edi
addq 0x80(%rsp), %rdi
xorl %r8d, %r8d
movl 0x14(%rsp), %ebp
cmpb %bpl, (%rdx,%r8)
jne 0x59244
incq %r8
movq %r9, %r13
movl %edi, %r9d
addl %r8d, %r9d
movq %r13, %r9
jne 0x59220
movl %r10d, %edx
jmp 0x5924b
movl %ebp, %edx
jmp 0x5924b
leal (%r12,%r8), %edx
movl %r8d, %r14d
movq %rdx, 0x38(%rsp)
movl 0x14(%rsp), %ebp
movq 0x20(%rsp), %r10
cmpl $0x3, %r14d
movl $0x3, %edx
movl %r14d, 0x20(%rsp)
cmovll %r14d, %edx
movl %edx, %r8d
movl %ebp, 0x18(%rsp)
movslq %ebp, %rdx
imulq $0x418, %rdx, %r14      # imm = 0x418
leaq (%r15,%r14), %r13
addq $0x8, %r13
xorl %r12d, %r12d
cmpw %r8w, 0xa(%r15,%r14)
movl %r8d, 0x4c(%rsp)
je 0x592ad
xorl %r12d, %r12d
movq %r13, %rdx
movzwl (%r13), %edi
addq $0x4, %r13
addl %edi, %r12d
cmpw %r8w, 0x6(%rdx)
jne 0x59297
leaq (%r15,%r14), %rdx
movzwl (%r13), %edi
movq %rdx, 0x8(%rsp)
movl (%rdx), %r8d
xorl %edx, %edx
divl %r8d
movl %eax, %r15d
imull %eax, %r12d
imull %edi, %r15d
addl %ebx, %r12d
adcl $0x0, %ecx
cmpl $0xffffff, %r15d        # imm = 0xFFFFFF
ja 0x59383
movl %ecx, %r8d
movl %ecx, %edi
movl 0x4(%rsp), %ebx
cmpl $0xff000000, %r12d      # imm = 0xFF000000
jb 0x592fc
testl %edi, %edi
jne 0x592fc
incl %r9d
jmp 0x59351
movl %r9d, %edx
movq %r11, %rax
subq %r10, %rax
cmpq %rdx, %rax
jle 0x59359
addl %esi, %r8d
leaq 0x1(%r10), %rdi
movb %r8b, (%r10)
testl %r9d, %r9d
je 0x59340
decb %cl
movzbl %cl, %esi
movl %ebx, 0x4(%rsp)
movq %r10, %rbx
movq %r9, %rbp
callq 0x4260
movq 0x30(%rsp), %r11
decl %ebp
leaq (%rbx,%rbp), %rdi
addq $0x2, %rdi
movl 0x4(%rsp), %ebx
movl %r12d, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r10
xorl %r9d, %r9d
xorl %r8d, %r8d
shll $0x8, %r12d
xorl %edi, %edi
jmp 0x5935e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %r15d, %eax
shll $0x8, %eax
cmpl $0x10000, %r15d         # imm = 0x10000
movl %eax, %r15d
jb 0x592ea
movzwl (%r13), %edi
movq 0x8(%rsp), %rdx
movl (%rdx), %r8d
jmp 0x5938f
movl %r15d, %eax
movl 0x4(%rsp), %ebx
movq 0x8(%rsp), %rdx
addl $0x10, %edi
movw %di, (%r13)
addl $0x10, %r8d
movl %r8d, (%rdx)
cmpl $0xfff0, %r8d           # imm = 0xFFF0
movq 0x40(%rsp), %r15
jb 0x593ef
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %edx
testw %dx, %dx
je 0x593ef
addq 0x70(%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 0x593c2
movq 0x8(%rsp), %rdx
movl %edi, (%rdx)
movzwl (%r13), %edi
cmpw -0x4(%r13), %di
jbe 0x59407
movq -0x4(%r13), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, -0x4(%r13)
xorl %edx, %edx
movl 0x18(%rsp), %edi
cmpl $0x101, %edi            # imm = 0x101
setl %dl
addl %edi, %edx
cmpl 0x14(%rsp), %edi
movl %edx, %ebp
movl $0x100, %edx            # imm = 0x100
cmovel %edx, %ebp
movl 0x20(%rsp), %r14d
cmpl $0x3, %r14d
setge %dl
subl 0x4c(%rsp), %r14d
sete %dil
andb %dl, %dil
cmpb $0x1, %dil
movl %ebx, 0x4(%rsp)
jne 0x59483
movl %r14d, 0x20(%rsp)
movl %ebp, 0x18(%rsp)
movslq %ebp, %rdx
imulq $0x418, %rdx, %r14      # imm = 0x418
leaq (%r15,%r14), %r13
addq $0x8, %r13
cmpw $0x0, 0xa(%r15,%r14)
je 0x5948b
xorl %ebx, %ebx
movzwl (%r13), %edx
addl %edx, %ebx
cmpw $0x0, 0x6(%r13)
leaq 0x4(%r13), %r13
jne 0x5946e
jmp 0x5948d
movl %r12d, %ebx
jmp 0x595db
xorl %ebx, %ebx
leaq (%r15,%r14), %rdx
movzwl (%r13), %edi
movq %rdx, 0x8(%rsp)
movl (%rdx), %r8d
xorl %edx, %edx
divl %r8d
movl %eax, %r15d
imull %eax, %ebx
imull %edi, %r15d
addl %r12d, %ebx
adcl $0x0, %ecx
cmpl $0xffffff, %r15d        # imm = 0xFFFFFF
ja 0x59552
movl %ecx, %r8d
movl %ecx, %edi
cmpl $0xff000000, %ebx       # imm = 0xFF000000
jb 0x594d6
testl %edi, %edi
jne 0x594d6
incl %r9d
jmp 0x59522
movl %r9d, %edx
movq %r11, %rax
subq %r10, %rax
cmpq %rdx, %rax
jle 0x59529
addl %esi, %r8d
leaq 0x1(%r10), %rdi
movb %r8b, (%r10)
testl %r9d, %r9d
je 0x59512
decb %cl
movzbl %cl, %esi
movq %r10, %r12
movq %r9, %rbp
callq 0x4260
movq 0x30(%rsp), %r11
decl %ebp
leaq (%r12,%rbp), %rdi
addq $0x2, %rdi
movl %ebx, %esi
shrl $0x18, %esi
xorl %ecx, %ecx
movq %rdi, %r10
xorl %r9d, %r9d
xorl %r8d, %r8d
shll $0x8, %ebx
xorl %edi, %edi
jmp 0x59531
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl %r15d, %eax
shll $0x8, %eax
cmpl $0x10000, %r15d         # imm = 0x10000
movl %eax, %r15d
jb 0x594c5
movzwl (%r13), %edi
movq 0x8(%rsp), %rdx
movl (%rdx), %r8d
jmp 0x5955a
movl %r15d, %eax
movq 0x8(%rsp), %rdx
addl $0x10, %edi
movw %di, (%r13)
addl $0x10, %r8d
movl %r8d, (%rdx)
cmpl $0xfff0, %r8d           # imm = 0xFFF0
movq 0x40(%rsp), %r15
jb 0x595ba
movl $0x0, (%rdx)
movzwl 0x8(%rdx), %edx
testw %dx, %dx
je 0x595ba
addq 0x70(%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 0x5958d
movq 0x8(%rsp), %rdx
movl %edi, (%rdx)
movzwl (%r13), %edi
cmpw -0x4(%r13), %di
jbe 0x595d2
movq -0x4(%r13), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, -0x4(%r13)
movl 0x20(%rsp), %r14d
movl 0x18(%rsp), %ebp
testl %r14d, %r14d
jne 0x59259
movl 0x2c(%rsp), %ebp
movq 0x38(%rsp), %r8
cmpl %ebp, %r8d
movq 0x68(%rsp), %r13
jb 0x5903a
shrl $0x1f, 0x4(%rsp)
jmp 0x59616
xorl %ecx, %ecx
movq %rdx, %r10
xorl %esi, %esi
xorl %r9d, %r9d
movl $0x0, 0x4(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movl $0x5, %r14d
cmpl $0xff000000, %ebx       # imm = 0xFF000000
setae %dl
testl %ecx, %ecx
sete %al
andb %dl, %al
movl %r9d, %r9d
movq %r11, %rdx
subq %r10, %rdx
movl %r14d, %edi
testb %al, %al
jne 0x59649
cmpq %r9, %rdx
jg 0x5964e
decl %edi
jne 0x5963a
jmp 0x596a1
incl %r9d
jmp 0x5968b
addl %ecx, %esi
leaq 0x1(%r10), %rdi
movb %sil, (%r10)
testq %r9, %r9
je 0x59680
decb %cl
movzbl %cl, %esi
movq %r9, %rdx
movq %r10, %r12
movq %r9, %r13
callq 0x4260
movq 0x30(%rsp), %r11
leal -0x1(%r13), %eax
leaq (%r12,%rax), %rdi
addq $0x2, %rdi
movl %ebx, %esi
shrl $0x18, %esi
xorl %r9d, %r9d
movq %rdi, %r10
shll $0x8, %ebx
incl %ebp
decl %r14d
xorl %ecx, %ecx
cmpl $0x5, %ebp
jne 0x5961e
cmpb $0x0, 0x4(%rsp)
je 0x596c7
movq %r15, %rdi
callq 0x7e26a
movq 0x60(%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
subl 0x78(%rsp), %r10d
incl %r10d
movq 0x50(%rsp), %rax
movl %r10d, (%rax)
movq %r15, %rdi
callq 0x7e26a
movq 0x58(%rsp), %rax
jmp 0x596b5