// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_external_decode_init
cram_codec *cram_external_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 = NULL;
    char *cp = data;

    if (size < 1)
        goto malformed;

    if (!(c = malloc(sizeof(*c))))
        return NULL;

    c->codec  = E_EXTERNAL;
    if (CRAM_MAJOR_VERS(version) >= 4) {
        // Version 4 does not permit integer data to be encoded as a
        // series of bytes.  This is used purely for bytes, either
        // singular or declared as arrays
        switch (codec) {
        case E_EXTERNAL:
            if (option == E_BYTE_ARRAY_BLOCK)
                c->decode = cram_external_decode_block;
            else if (option == E_BYTE || option == E_BYTE_ARRAY)
                c->decode = cram_external_decode_char;
            else
                goto malformed;
            break;
        default:
            goto malformed;
        }
    } else {
        // CRAM 3 and earlier encodes integers as EXTERNAL.  We need
        // use the option field to indicate the input data format so
        // we know which serialisation format to use.
        if (option == E_INT)
            c->decode = cram_external_decode_int;
        else if (option == E_LONG)
            c->decode = cram_external_decode_long;
        else if (option == E_BYTE_ARRAY || option == E_BYTE)
            c->decode = cram_external_decode_char;
        else
            c->decode = cram_external_decode_block;
    }
    c->free   = cram_external_decode_free;
    c->size   = cram_external_decode_size;
    c->get_block = cram_external_get_block;
    c->describe = cram_external_describe;

    c->u.external.content_id = vv->varint_get32(&cp, data+size, NULL);

    if (cp - data != size)
        goto malformed;

    c->u.external.type = option;

    return c;

 malformed:
    hts_log_error("Malformed external header stream");
    free(c);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, (%rsp)
testl %edx, %edx
jle 0x8bc69
movl %r9d, %r13d
movl %r8d, %r14d
movl %ecx, %r12d
movl %edx, %ebp
movq %rsi, %r15
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x8bd25
movq %rax, %rbx
movl $0x1, (%rax)
cmpl $0x400, %r13d           # imm = 0x400
jl 0x8bc70
cmpl $0x1, %r12d
jne 0x8bd03
cmpl $0x5, %r14d
je 0x8bca0
leal -0x3(%r14), %eax
cmpl $0x1, %eax
jbe 0x8bc97
jmp 0x8bd03
xorl %ebx, %ebx
jmp 0x8bd03
cmpl $0x2, %r14d
je 0x8bc85
cmpl $0x1, %r14d
jne 0x8bc8e
leaq -0x4a3(%rip), %rax      # 0x8b7e0
jmp 0x8bca7
leaq -0x3a6(%rip), %rax      # 0x8b8e6
jmp 0x8bca7
leal -0x3(%r14), %eax
cmpl $0x1, %eax
ja 0x8bca0
leaq -0x2b2(%rip), %rax      # 0x8b9ec
jmp 0x8bca7
leaq 0x92(%rip), %rax        # 0x8bd39
movq %rax, 0x28(%rbx)
movq 0x40(%rsp), %rax
leaq -0x1f3(%rip), %rcx      # 0x8bac4
movq %rcx, 0x20(%rbx)
leaq -0x1f4(%rip), %rcx      # 0x8bace
movq %rcx, 0x40(%rbx)
leaq -0x169(%rip), %rcx      # 0x8bb64
movq %rcx, 0x50(%rbx)
leaq -0xf0(%rip), %rcx       # 0x8bbe8
movq %rcx, 0x58(%rbx)
movl %ebp, %r13d
leaq (%r15,%r13), %rsi
movq %rsp, %r12
movq %r12, %rdi
xorl %edx, %edx
callq *0x18(%rax)
movl %eax, 0x60(%rbx)
movq (%r12), %rax
subq %r15, %rax
cmpq %r13, %rax
jne 0x8bd03
movl %r14d, 0x64(%rbx)
jmp 0x8bd27
leaq 0x16c02(%rip), %rsi     # 0xa290c
leaq 0x16c15(%rip), %rdx     # 0xa2926
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movq %rbx, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq