// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_uncompress_O1_RLE
static
unsigned char *arith_uncompress_O1_RLE(unsigned char *in, unsigned int in_size,
                                       unsigned char *out, unsigned int out_sz) {
    RangeCoder rc;
    int i;
    unsigned int m = in[0] ? in[0] : 256;
    unsigned char *out_free = NULL;

    if (!out)
        out_free = out = malloc(out_sz);
    if (!out)
        return NULL;

    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);

    RC_SetInput(&rc, (char *)in+1, (char *)in+in_size);
    RC_StartDecode(&rc);

    unsigned char last = 0;
    for (i = 0; i < out_sz; i++) {
        out[i] = SIMPLE_MODEL(256, _decodeSymbol)(&byte_model[last], &rc);
        //fprintf(stderr, "lit %c (ctx %c)\n", out[i], last);
        last = out[i];
        int run = 0, r = 0, rctx = last;

        do {
            r = SIMPLE_MODEL(NSYM, _decodeSymbol)(&run_model[rctx], &rc);
            if (rctx == last)
                rctx = 256;
            else
                rctx += (rctx < NSYM-1);
            run += r;
        } while (r == MAX_RUN-1 && run < out_sz);
        while (run-- && i+1 < out_sz)
            out[++i] = last;
    }

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x84fd4
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x9c(%rbp)
jmp 0x84fe1
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x9c(%rbp)
jmp 0x84fe1
movl -0x9c(%rbp), %eax
movl %eax, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x8500b
movl -0x24(%rbp), %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x20(%rbp)
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x8501f
movq $0x0, -0x8(%rbp)
jmp 0x852f2
movl $0x41000, %edi          # imm = 0x41000
callq 0xce6a0
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x8504a
movq -0x78(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x852f2
movl $0x0, -0x6c(%rbp)
cmpl $0x100, -0x6c(%rbp)     # imm = 0x100
jge 0x8507f
movq -0x80(%rbp), %rdi
movslq -0x6c(%rbp), %rax
imulq $0x410, %rax, %rax      # imm = 0x410
addq %rax, %rdi
movl -0x70(%rbp), %esi
callq 0x859d0
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x85051
movl $0x42030, %edi          # imm = 0x42030
callq 0xce6a0
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jne 0x850b9
movq -0x80(%rbp), %rdi
callq 0xce8f0
movq -0x78(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x852f2
movl $0x0, -0x6c(%rbp)
cmpl $0x102, -0x6c(%rbp)     # imm = 0x102
jge 0x850f3
movq -0x88(%rbp), %rdi
movslq -0x6c(%rbp), %rax
imulq $0x418, %rax, %rax      # imm = 0x418
addq %rax, %rdi
movl $0x4, %esi
callq 0x85aa0
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x850c0
movq -0x10(%rbp), %rsi
addq $0x1, %rsi
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %eax
addq %rax, %rdx
leaq -0x68(%rbp), %rdi
callq 0x860a0
leaq -0x68(%rbp), %rdi
callq 0x860e0
movb $0x0, -0x89(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x8529f
movq -0x80(%rbp), %rdi
movzbl -0x89(%rbp), %eax
imulq $0x410, %rax, %rax      # imm = 0x410
addq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x861a0
movb %al, %dl
movq -0x20(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x89(%rbp)
movl $0x0, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movzbl -0x89(%rbp), %eax
movl %eax, -0x98(%rbp)
movq -0x88(%rbp), %rdi
movslq -0x98(%rbp), %rax
imulq $0x418, %rax, %rax      # imm = 0x418
addq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x862e0
movzwl %ax, %eax
movl %eax, -0x94(%rbp)
movl -0x98(%rbp), %eax
movzbl -0x89(%rbp), %ecx
cmpl %ecx, %eax
jne 0x851d5
movl $0x100, -0x98(%rbp)     # imm = 0x100
jmp 0x851f3
cmpl $0x101, -0x98(%rbp)     # imm = 0x101
setl %al
andb $0x1, %al
movzbl %al, %eax
addl -0x98(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x94(%rbp), %eax
addl -0x90(%rbp), %eax
movl %eax, -0x90(%rbp)
xorl %eax, %eax
cmpl $0x3, -0x94(%rbp)
movb %al, -0x9d(%rbp)
jne 0x85228
movl -0x90(%rbp), %eax
cmpl -0x24(%rbp), %eax
setb %al
movb %al, -0x9d(%rbp)
movb -0x9d(%rbp), %al
testb $0x1, %al
jne 0x8518e
jmp 0x85238
movl -0x90(%rbp), %ecx
movl %ecx, %eax
addl $-0x1, %eax
movl %eax, -0x90(%rbp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x9e(%rbp)
je 0x85268
movl -0x6c(%rbp), %eax
addl $0x1, %eax
cmpl -0x24(%rbp), %eax
setb %al
movb %al, -0x9e(%rbp)
movb -0x9e(%rbp), %al
testb $0x1, %al
jne 0x85274
jmp 0x8528f
movb -0x89(%rbp), %dl
movq -0x20(%rbp), %rax
movl -0x6c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x6c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x85238
jmp 0x85291
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x85125
leaq -0x68(%rbp), %rdi
callq 0x86420
cmpl $0x0, %eax
jge 0x852d5
movq -0x80(%rbp), %rdi
callq 0xce8f0
movq -0x88(%rbp), %rdi
callq 0xce8f0
movq -0x78(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x852f2
movq -0x80(%rbp), %rdi
callq 0xce8f0
movq -0x88(%rbp), %rdi
callq 0xce8f0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nop