// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x1, %edi
movl $0x880, %esi            # imm = 0x880
callq 0x42f0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xe4fcf
movq $0x0, -0x8(%rbp)
jmp 0xe523b
movq -0x30(%rbp), %rax
movl $0x33, (%rax)
cmpl $0x2, -0x24(%rbp)
jne 0xe4ff0
movq -0x30(%rbp), %rax
leaq -0x57a(%rip), %rcx      # 0xe4a70
movq %rcx, 0x28(%rax)
jmp 0xe5045
cmpl $0x1, -0x24(%rbp)
jne 0xe5007
movq -0x30(%rbp), %rax
leaq -0x4d1(%rip), %rcx      # 0xe4b30
movq %rcx, 0x28(%rax)
jmp 0xe5043
cmpl $0x4, -0x24(%rbp)
je 0xe5013
cmpl $0x3, -0x24(%rbp)
jne 0xe5024
movq -0x30(%rbp), %rax
leaq -0x3fe(%rip), %rcx      # 0xe4c20
movq %rcx, 0x28(%rax)
jmp 0xe5041
movq 0x27fb5(%rip), %rax     # 0x10cfe0
movq (%rax), %rdi
leaq 0x13e4e(%rip), %rsi     # 0xf8e83
movb $0x0, %al
callq 0x46d0
jmp 0xe5208
jmp 0xe5043
jmp 0xe5045
movq -0x30(%rbp), %rax
leaq -0x1c0(%rip), %rcx      # 0xe4e90
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
leaq -0x17f(%rip), %rcx      # 0xe4ee0
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rax
leaq -0x13e(%rip), %rcx      # 0xe4f30
movq %rcx, 0x50(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x58(%rax)
movq 0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rsi
leaq -0x38(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x60(%rax)
movq 0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rsi
leaq -0x38(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x30(%rbp), %rax
cmpl $0x8, 0x60(%rax)
jge 0xe50e7
movq -0x30(%rbp), %rax
cmpl $0x0, 0x60(%rax)
jl 0xe50e7
movq -0x30(%rbp), %rax
cmpl $0x100, 0x78(%rax)      # imm = 0x100
jg 0xe50e7
movq -0x30(%rbp), %rax
cmpl $0x0, 0x78(%rax)
jge 0xe50ec
jmp 0xe5208
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x78(%rcx), %eax
jge 0xe5140
movq 0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rsi
leaq -0x38(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, -0x48(%rbp)
cmpl $0x100, -0x48(%rbp)     # imm = 0x100
jb 0xe5126
jmp 0xe5208
movl -0x48(%rbp), %edx
movq -0x30(%rbp), %rax
movslq -0x44(%rbp), %rcx
movl %edx, 0x7c(%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xe50f3
movq 0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rsi
leaq -0x38(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, -0x4c(%rbp)
movq 0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x40(%rbp), %rsi
leaq -0x38(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %edx
callq *%rax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0xe518c
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movslq -0x50(%rbp), %rcx
cmpq %rcx, %rax
jge 0xe518e
jmp 0xe5208
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
movq -0x38(%rbp), %rdx
movl -0x50(%rbp), %ecx
movl -0x24(%rbp), %r8d
movl -0x28(%rbp), %r9d
movq 0x10(%rbp), %rax
movq %rax, (%rsp)
callq 0xe5250
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x70(%rax)
jne 0xe51c9
jmp 0xe5208
movl -0x50(%rbp), %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jne 0xe5206
movq -0x30(%rbp), %rax
cmpl $0x0, 0x60(%rax)
jl 0xe5206
movq -0x30(%rbp), %rax
movslq 0x60(%rax), %rax
cmpq $0x40, %rax
jbe 0xe5233
jmp 0xe5208
movq 0x27dd1(%rip), %rax     # 0x10cfe0
movq (%rax), %rdi
leaq 0x13c93(%rip), %rsi     # 0xf8eac
movb $0x0, %al
callq 0x46d0
movq -0x30(%rbp), %rdi
callq 0xe4e90
movq $0x0, -0x8(%rbp)
jmp 0xe523b
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)