// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_xpack_decode_init
cram_codec *cram_xpack_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;

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

    c->codec  = E_XPACK;
    if (option == E_LONG)
        c->decode = cram_xpack_decode_long;
    else if (option == E_INT)
        c->decode = cram_xpack_decode_int;
    else if (option == E_BYTE_ARRAY || option == E_BYTE)
        c->decode = cram_xpack_decode_char;
    else {
        fprintf(stderr, "BYTE_ARRAYs not supported by this codec\n");
        goto malformed;
    }
    c->free = cram_xpack_decode_free;
    c->size = cram_xpack_decode_size;
    c->get_block = cram_xpack_get_block;
    c->describe = NULL;

    c->u.xpack.nbits = vv->varint_get32(&cp, endp, NULL);
    c->u.xpack.nval  = vv->varint_get32(&cp, endp, NULL);
    if (c->u.xpack.nbits >= 8  || c->u.xpack.nbits < 0 ||
        c->u.xpack.nval  > 256 || c->u.xpack.nval < 0)
        goto malformed;
    int i;
    for (i = 0; i < c->u.xpack.nval; i++) {
        uint32_t v = vv->varint_get32(&cp, endp, NULL);
        if (v >= 256)
            goto malformed;
        c->u.xpack.rmap[i] = v; // reverse map: e.g 0-3 to P,A,C,K
    }

    int encoding = vv->varint_get32(&cp, endp, NULL);
    int sub_size = vv->varint_get32(&cp, endp, NULL);
    if (sub_size < 0 || endp - cp < sub_size)
        goto malformed;
    c->u.xpack.sub_codec = cram_decoder_init(hdr, encoding, cp, sub_size,
                                             option, version, vv);
    if (c->u.xpack.sub_codec == NULL)
        goto malformed;
    cp += sub_size;

    if (cp - data != size
        || c->u.xpack.nbits < 0 || c->u.xpack.nbits > 8 * sizeof(int64_t)) {
    malformed:
        fprintf(stderr, "Malformed xpack header stream\n");
        cram_xpack_decode_free(c);
        return NULL;
    }

    return c;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %r15d
movl %r8d, %r12d
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r13
movq %rsi, 0x8(%rsp)
pushq $0x1
popq %rdi
movl $0x880, %esi            # imm = 0x880
callq 0x4300
testq %rax, %rax
je 0x709f3
movq %rax, %rbx
movl $0x33, (%rax)
cmpl $0x2, %r12d
movl %r15d, 0x14(%rsp)
movq %r12, 0x30(%rsp)
movq %r13, 0x28(%rsp)
je 0x7086b
cmpl $0x1, %r12d
jne 0x70876
movl %ebp, %ecx
leaq -0x2a6(%rip), %rax      # 0x705c3
jmp 0x7088d
movl %ebp, %ecx
leaq -0x317(%rip), %rax      # 0x7055d
jmp 0x7088d
leal -0x3(%r12), %eax
cmpl $0x2, %eax
jae 0x709b3
movl %ebp, %ecx
leaq -0x23f(%rip), %rax      # 0x7064e
movq 0x70(%rsp), %rbp
movslq %ecx, %rcx
movq %r14, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
leaq (%r14,%rcx), %r13
movq %rax, 0x28(%rbx)
leaq -0x119(%rip), %rax      # 0x70795
movq %rax, 0x20(%rbx)
leaq -0x105(%rip), %rax      # 0x707b4
movq %rax, 0x40(%rbx)
leaq -0xe6(%rip), %rax       # 0x707de
movq %rax, 0x50(%rbx)
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x18(%rbp)
movq %rax, %r12
movl %r12d, 0x60(%rbx)
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *0x18(%rbp)
movq %rax, %rbp
movl %ebp, 0x78(%rbx)
cmpl $0x7, %r12d
ja 0x709cf
cmpl $0x100, %ebp            # imm = 0x100
ja 0x709cf
andl $0x1ff, %ebp            # imm = 0x1FF
xorl %r14d, %r14d
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
movq 0x70(%rsp), %rax
callq *0x18(%rax)
movq %rax, %r12
cmpq %rbp, %r14
jae 0x70943
cmpl $0xff, %r12d
ja 0x709cf
movl %r12d, 0x7c(%rbx,%r14,4)
incq %r14
jmp 0x70914
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
xorl %edx, %edx
movq 0x70(%rsp), %rax
callq *0x18(%rax)
testl %eax, %eax
js 0x709cf
movq 0x8(%rsp), %rdx
subq %rdx, %r13
movl %eax, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cmpq %r15, %r13
jl 0x709cf
movq 0x70(%rsp), %rcx
movq %rcx, (%rsp)
movq 0x28(%rsp), %rdi
movl %r12d, %esi
movl %eax, %ecx
movq 0x30(%rsp), %r8
movl 0x14(%rsp), %r9d
callq 0x70a07
movq %rax, 0x70(%rbx)
testq %rax, %rax
je 0x709cf
addq 0x8(%rsp), %r15
movq %r15, 0x8(%rsp)
subq 0x20(%rsp), %r15
cmpq 0x18(%rsp), %r15
je 0x709f5
jmp 0x709cf
movq 0x2d61e(%rip), %rax     # 0x9dfd8
movq (%rax), %rcx
leaq 0x13957(%rip), %rdi     # 0x8431b
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
callq 0x49b0
movq 0x2d602(%rip), %rax     # 0x9dfd8
movq (%rax), %rcx
leaq 0x13964(%rip), %rdi     # 0x84344
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
callq 0x49b0
movq %rbx, %rdi
callq 0x70795
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq