// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl -0x14(%rbp), %edi
xorl %esi, %esi
callq 0x826c0
subl $0x5, %eax
movl %eax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x83697
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x20(%rbp)
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x836a9
movl -0x30(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0x836b6
movq $0x0, -0x8(%rbp)
jmp 0x839d8
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x836fb
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jae 0x836ee
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x3c(%rbp)
jmp 0x836f0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x836c4
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movl -0x3c(%rbp), %esi
leaq -0x44c(%rbp), %rdi
callq 0x859d0
movl $0x42030, %edi          # imm = 0x42030
callq 0xce6a0
movq %rax, -0x458(%rbp)
cmpq $0x0, -0x458(%rbp)
jne 0x8374f
movq -0x38(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x839d8
movl $0x0, -0x2c(%rbp)
cmpl $0x102, -0x2c(%rbp)     # imm = 0x102
jge 0x83789
movq -0x458(%rbp), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x418, %rax, %rax      # imm = 0x418
addq %rax, %rdi
movl $0x4, %esi
callq 0x85aa0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x83756
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
leaq -0x498(%rbp), %rdi
callq 0x85b70
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movl (%rax), %eax
addq %rax, %rsi
leaq -0x498(%rbp), %rdi
callq 0x85ba0
leaq -0x498(%rbp), %rdi
callq 0x85bc0
movb $0x0, -0x499(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x8397c
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
leaq -0x44c(%rbp), %rdi
leaq -0x498(%rbp), %rsi
movzwl %ax, %edx
callq 0x85c20
movl $0x0, -0x4a0(%rbp)
movq -0x10(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x2c(%rbp)
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x499(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x4a9(%rbp)
jae 0x83851
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movzbl -0x499(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x4a9(%rbp)
movb -0x4a9(%rbp), %al
testb $0x1, %al
jne 0x8385d
jmp 0x83877
movl -0x4a0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4a0(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x83823
movzbl -0x499(%rbp), %eax
movl %eax, -0x4a4(%rbp)
cmpl $0x4, -0x4a0(%rbp)
jge 0x8389b
movl -0x4a0(%rbp), %eax
movl %eax, -0x4b0(%rbp)
jmp 0x838a8
movl $0x3, %eax
movl %eax, -0x4b0(%rbp)
jmp 0x838a8
movl -0x4b0(%rbp), %eax
movl %eax, -0x4a8(%rbp)
movq -0x458(%rbp), %rdi
movslq -0x4a4(%rbp), %rax
imulq $0x418, %rax, %rax      # imm = 0x418
addq %rax, %rdi
movl -0x4a8(%rbp), %eax
leaq -0x498(%rbp), %rsi
movzwl %ax, %edx
callq 0x85d00
movl -0x4a8(%rbp), %ecx
movl -0x4a0(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4a0(%rbp)
movl -0x4a4(%rbp), %eax
movzbl -0x499(%rbp), %ecx
cmpl %ecx, %eax
jne 0x83912
movl $0x100, -0x4a4(%rbp)    # imm = 0x100
jmp 0x83930
cmpl $0x101, -0x4a4(%rbp)    # imm = 0x101
setl %al
andb $0x1, %al
movzbl %al, %eax
addl -0x4a4(%rbp), %eax
movl %eax, -0x4a4(%rbp)
cmpl $0x3, -0x4a8(%rbp)
jne 0x83968
cmpl $0x0, -0x4a0(%rbp)
jne 0x83968
movq -0x458(%rbp), %rdi
movslq -0x4a4(%rbp), %rax
imulq $0x418, %rax, %rax      # imm = 0x418
addq %rax, %rdi
leaq -0x498(%rbp), %rsi
xorl %edx, %edx
callq 0x85d00
jmp 0x8396a
cmpl $0x0, -0x4a0(%rbp)
jne 0x83884
jmp 0x837d0
leaq -0x498(%rbp), %rdi
callq 0x85de0
cmpl $0x0, %eax
jge 0x839ac
movq -0x458(%rbp), %rdi
callq 0xce8f0
movq -0x38(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x839d8
leaq -0x498(%rbp), %rdi
callq 0x85e20
addq $0x1, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x458(%rbp), %rdi
callq 0xce8f0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
nopw %cs:(%rax,%rax)