// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_xrle_decode_init
cram_codec *cram_xrle_decode_init(cram_block_compression_hdr *hdr,
                                  char *data, int size,
                                  enum cram_encoding codec,
                                  enum cram_external_type option,
                                  int version, varint_vec *vv) {
    cram_codec *c;
    char *cp = data;
    char *endp = data+size;
    int err = 0;

    if (!(c = calloc(1, sizeof(*c))))
        return NULL;

    c->codec  = E_XRLE;
    if (option == E_LONG)
        c->decode = cram_xrle_decode_long;
    else if (option == E_INT)
        c->decode = cram_xrle_decode_int;
    else if (option == E_BYTE_ARRAY || option == E_BYTE)
        c->decode = cram_xrle_decode_char;
    else {
        fprintf(stderr, "BYTE_ARRAYs not supported by this codec\n");
        free(c);
        return NULL;
    }
    c->free   = cram_xrle_decode_free;
    c->size   = cram_xrle_decode_size;
    c->get_block = cram_xrle_get_block;
    c->describe = NULL;
    c->u.xrle.cur_len = 0;
    c->u.xrle.cur_lit = -1;

    // RLE map
    int i, j, nrle = vv->varint_get32(&cp, endp, &err);
    memset(c->u.xrle.rep_score, 0, 256*sizeof(*c->u.xrle.rep_score));
    for (i = 0; i < nrle && i < 256; i++) {
        j = vv->varint_get32(&cp, endp, &err);
        if (j >= 0 && j < 256)
            c->u.xrle.rep_score[j] = 1;
    }

    // Length and literal sub encodings
    c->u.xrle.len_encoding = vv->varint_get32(&cp, endp, &err);
    int sub_size = vv->varint_get32(&cp, endp, &err);
    if (sub_size < 0 || endp - cp < sub_size)
        goto malformed;
    c->u.xrle.len_codec = cram_decoder_init(hdr, c->u.xrle.len_encoding,
                                            cp, sub_size, E_INT, version, vv);
    if (c->u.xrle.len_codec == NULL)
        goto malformed;
    cp += sub_size;

    c->u.xrle.lit_encoding = vv->varint_get32(&cp, endp, &err);
    sub_size = vv->varint_get32(&cp, endp, &err);
    if (sub_size < 0 || endp - cp < sub_size)
        goto malformed;
    c->u.xrle.lit_codec = cram_decoder_init(hdr, c->u.xrle.lit_encoding,
                                            cp, sub_size, option, version, vv);
    if (c->u.xrle.lit_codec == NULL)
        goto malformed;
    cp += sub_size;

    if (err)
        goto malformed;

    return c;

 malformed:
    fprintf(stderr, "Malformed xrle header stream\n");
    cram_xrle_decode_free(c);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x24(%rsp)
movl %r8d, %ebx
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, 0x28(%rsp)
movq %rsi, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x1, %edi
movl $0x880, %esi            # imm = 0x880
callq 0x4300
testq %rax, %rax
je 0x91d2a
movq %rax, %r13
movq %r13, 0x18(%rsp)
movl $0x34, (%r13)
cmpl $0x2, %ebx
movq %rbx, 0x30(%rsp)
je 0x91b5d
cmpl $0x1, %ebx
jne 0x91b66
leaq -0x2cc(%rip), %rax      # 0x9188f
jmp 0x91b79
leaq -0x2db(%rip), %rax      # 0x91889
jmp 0x91b79
leal -0x3(%rbx), %eax
cmpl $0x2, %eax
jae 0x91d3f
leaq -0x105(%rip), %rax      # 0x91a74
movq 0x70(%rsp), %rbx
movslq %ebp, %rcx
addq %rcx, %r12
movq 0x18(%rsp), %rcx
movq %rax, 0x28(%rcx)
leaq -0xd2(%rip), %rax       # 0x91ac2
movq %rax, 0x20(%rcx)
leaq -0x30a(%rip), %rax      # 0x91895
movq %rax, 0x40(%rcx)
leaq -0x15d(%rip), %rax      # 0x91a4d
movq %rax, 0x50(%rcx)
movq $0x0, 0x58(%rcx)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x88(%rcx)
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
movq %r12, %rsi
callq *0x18(%rbx)
movq %rax, %rbp
addq $0x90, %r13
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
xorl %esi, %esi
callq 0x4260
testl %ebp, %ebp
jle 0x91c2f
decl %ebp
movl $0xff, %eax
cmpl %eax, %ebp
cmovael %eax, %ebp
incl %ebp
leaq 0x10(%rsp), %r15
leaq 0xc(%rsp), %r14
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq *0x18(%rbx)
testl $0xffffff00, %eax       # imm = 0xFFFFFF00
jne 0x91c2b
movzbl %al, %eax
movl $0x1, (%r13,%rax,4)
decl %ebp
jne 0x91c0c
leaq 0x10(%rsp), %r14
leaq 0xc(%rsp), %r15
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq *0x18(%rbx)
movq 0x18(%rsp), %r13
movl %eax, 0x60(%r13)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq *0x18(%rbx)
testl %eax, %eax
movl 0x24(%rsp), %ebp
js 0x91d22
movq 0x10(%rsp), %rdx
movq %r12, %rcx
subq %rdx, %rcx
movl %eax, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cmpq %r15, %rcx
jl 0x91d22
movl 0x60(%r13), %esi
movq %rbx, (%rsp)
movq 0x28(%rsp), %rdi
movl %eax, %ecx
movl $0x1, %r8d
movl %ebp, %r9d
callq 0x90872
movq %rax, 0x78(%r13)
testq %rax, %rax
je 0x91d22
leaq 0x10(%rsp), %r14
addq %r15, (%r14)
leaq 0xc(%rsp), %r15
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq *0x18(%rbx)
movl %eax, 0x64(%r13)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq *0x18(%rbx)
testl %eax, %eax
js 0x91d22
movq 0x10(%rsp), %rdx
subq %rdx, %r12
movl %eax, %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
cmpq %r14, %r12
jl 0x91d22
movl 0x64(%r13), %esi
movq %rbx, (%rsp)
movq 0x28(%rsp), %rdi
movl %eax, %ecx
movq 0x30(%rsp), %r8
movl %ebp, %r9d
callq 0x90872
movq %rax, 0x80(%r13)
testq %rax, %rax
je 0x91d22
addq %r14, 0x10(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x91d2d
movq %r13, %rdi
callq 0x4ccc
xorl %r13d, %r13d
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rdi
callq 0x4ca3
jmp 0x91d2a