// File: /workspace/github_c_makefile_star2_O2/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, 0x1c(%rsp)
movl %r8d, %r14d
movl %edx, %r13d
movq %rsi, %r12
movq %rdi, 0x28(%rsp)
movq %rsi, 0x10(%rsp)
andl $0x0, 0xc(%rsp)
pushq $0x1
popq %rdi
movl $0x880, %esi            # imm = 0x880
callq 0x4300
testq %rax, %rax
je 0x71c2f
movq %rax, %rbx
movl $0x34, (%rax)
cmpl $0x2, %r14d
movq %r14, 0x30(%rsp)
je 0x71a4a
cmpl $0x1, %r14d
jne 0x71a53
leaq -0x2bc(%rip), %rax      # 0x7178c
jmp 0x71a67
leaq -0x2c9(%rip), %rax      # 0x71788
jmp 0x71a67
leal -0x3(%r14), %eax
cmpl $0x2, %eax
jae 0x71c44
leaq -0xfd(%rip), %rax       # 0x7196a
movq 0x70(%rsp), %r8
movslq %r13d, %rcx
addq %rcx, %r12
movq %rax, 0x28(%rbx)
leaq -0xc5(%rip), %rax       # 0x719b8
movq %rax, 0x20(%rbx)
leaq -0x2f8(%rip), %rax      # 0x71790
movq %rax, 0x40(%rbx)
leaq -0x150(%rip), %rax      # 0x71943
movq %rax, 0x50(%rbx)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rbx, 0x20(%rsp)
movq %rax, 0x88(%rbx)
leaq 0x10(%rsp), %r13
leaq 0xc(%rsp), %rbp
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r8, %r14
callq *0x18(%r8)
movq %rax, %r15
xorl %ebx, %ebx
cmpl %r15d, %ebx
jge 0x71b04
cmpl $0xff, %ebx
ja 0x71b04
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x18(%r14)
testl $0xffffff00, %eax       # imm = 0xFFFFFF00
jne 0x71b00
movzbl %al, %eax
movq 0x20(%rsp), %rcx
movl $0x1, 0x90(%rcx,%rax,4)
incl %ebx
jmp 0x71acc
leaq 0x10(%rsp), %r13
leaq 0xc(%rsp), %rbp
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x18(%r14)
movq %rax, %r15
movq 0x20(%rsp), %rax
movl %r15d, 0x60(%rax)
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rax, %r13
callq *0x18(%r14)
testl %eax, %eax
js 0x71c0b
movq 0x10(%rsp), %rdx
movq %r12, %rcx
subq %rdx, %rcx
movl %eax, %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
cmpq %rbx, %rcx
jl 0x71c0b
movq %r14, (%rsp)
pushq $0x1
popq %r8
movq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %eax, %ecx
movl 0x1c(%rsp), %r9d
callq 0x70a07
movq %rax, 0x78(%r13)
testq %rax, %rax
je 0x71c0b
leaq 0x10(%rsp), %r13
addq %rbx, (%r13)
leaq 0xc(%rsp), %rbp
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq *0x18(%r14)
movq %rax, %r15
movq 0x20(%rsp), %rax
movl %r15d, 0x64(%rax)
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq 0x20(%rsp), %r13
callq *0x18(%r14)
testl %eax, %eax
js 0x71c0b
movq 0x10(%rsp), %rdx
subq %rdx, %r12
movl %eax, %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
cmpq %rbx, %r12
jl 0x71c0b
movq %r14, (%rsp)
movq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %eax, %ecx
movq 0x30(%rsp), %r8
movl 0x1c(%rsp), %r9d
callq 0x70a07
movq %rax, 0x80(%r13)
testq %rax, %rax
je 0x71c0b
addq %rbx, 0x10(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x71c32
movq 0x2c3c6(%rip), %rax     # 0x9dfd8
movq (%rax), %rcx
leaq 0x127bb(%rip), %rdi     # 0x843d7
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x49b0
movq %r13, %rdi
callq 0x719b8
xorl %r13d, %r13d
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2c38d(%rip), %rax     # 0x9dfd8
movq (%rax), %rcx
leaq 0x126c6(%rip), %rdi     # 0x8431b
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
callq 0x49b0
movq %rbx, %rdi
callq 0x45c0
jmp 0x71c2f