// File: /workspace/github_c_makefile_star2_O3/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, %r14d
movl %edx, %r13d
movq %rsi, %r12
movq %rdi, 0x28(%rsp)
movq %rsi, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x1, %edi
movl $0x880, %esi            # imm = 0x880
callq 0x4300
testq %rax, %rax
je 0x8f37c
movq %rax, %rbx
movl $0x34, (%rax)
cmpl $0x2, %r14d
movq %r14, 0x30(%rsp)
je 0x8f1c6
cmpl $0x1, %r14d
jne 0x8f1cf
leaq -0x2c6(%rip), %rax      # 0x8eefe
jmp 0x8f1e3
leaq -0x2d5(%rip), %rax      # 0x8eef8
jmp 0x8f1e3
leal -0x3(%r14), %eax
cmpl $0x2, %eax
jae 0x8f390
leaq -0x102(%rip), %rax      # 0x8f0e1
movq 0x70(%rsp), %r14
movslq %r13d, %rcx
addq %rcx, %r12
movq %rax, 0x28(%rbx)
leaq -0xca(%rip), %rax       # 0x8f12f
movq %rax, 0x20(%rbx)
leaq -0x300(%rip), %rax      # 0x8ef04
movq %rax, 0x40(%rbx)
leaq -0x155(%rip), %rax      # 0x8f0ba
movq %rax, 0x50(%rbx)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x88(%rbx)
leaq 0x18(%rsp), %rdi
leaq 0x14(%rsp), %rdx
movq %r12, %rsi
callq *0x18(%r14)
movq %rax, %r13
testl %r13d, %r13d
jle 0x8f280
decl %r13d
movl $0xff, %eax
cmpl %eax, %r13d
cmovael %eax, %r13d
incl %r13d
leaq 0x18(%rsp), %rbp
leaq 0x14(%rsp), %r15
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq *0x18(%r14)
testl $0xffffff00, %eax       # imm = 0xFFFFFF00
jne 0x8f27b
movzbl %al, %eax
movl $0x1, 0x90(%rbx,%rax,4)
decl %r13d
jne 0x8f259
leaq 0x18(%rsp), %r15
leaq 0x14(%rsp), %rbp
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x18(%r14)
movq %rax, %r13
movl %r13d, 0x60(%rbx)
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x18(%r14)
testl %eax, %eax
js 0x8f374
movq 0x18(%rsp), %rdx
movq %r12, %rcx
subq %rdx, %rcx
movl %eax, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
cmpq %rbp, %rcx
jl 0x8f374
movq %r14, (%rsp)
movq 0x28(%rsp), %rdi
movl %r13d, %esi
movl %eax, %ecx
movl $0x1, %r8d
movl 0x24(%rsp), %r9d
callq 0x8df2c
movq %rax, 0x78(%rbx)
testq %rax, %rax
je 0x8f374
leaq 0x18(%rsp), %r15
addq %rbp, (%r15)
leaq 0x14(%rsp), %rbp
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x18(%r14)
movq %rax, %r13
movl %r13d, 0x64(%rbx)
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x18(%r14)
testl %eax, %eax
js 0x8f374
movq 0x18(%rsp), %rdx
subq %rdx, %r12
movl %eax, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cmpq %r15, %r12
jl 0x8f374
movq %r14, (%rsp)
movq 0x28(%rsp), %rdi
movl %r13d, %esi
movl %eax, %ecx
movq 0x30(%rsp), %r8
movl 0x24(%rsp), %r9d
callq 0x8df2c
movq %rax, 0x80(%rbx)
testq %rax, %rax
je 0x8f374
addq %r15, 0x18(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0x8f37e
movq %rbx, %rdi
callq 0x4ce4
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x4cbb
jmp 0x8f37c