// File: /workspace/github_c_makefile_star2_O2/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 0x6efd3
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 0x6f08d
movq %rax, %rbx
movl $0x1, (%rax)
cmpl $0x400, %r13d           # imm = 0x400
jl 0x6efda
cmpl $0x1, %r12d
jne 0x6f06d
cmpl $0x5, %r14d
je 0x6f00a
leal -0x3(%r14), %eax
cmpl $0x1, %eax
jbe 0x6f001
jmp 0x6f06d
xorl %ebx, %ebx
jmp 0x6f06d
cmpl $0x2, %r14d
je 0x6efef
cmpl $0x1, %r14d
jne 0x6eff8
leaq -0x2ad(%rip), %rax      # 0x6ed40
jmp 0x6f011
leaq -0x1b3(%rip), %rax      # 0x6ee43
jmp 0x6f011
leal -0x3(%r14), %eax
cmpl $0x1, %eax
ja 0x6f00a
leaq -0x13b(%rip), %rax      # 0x6eecd
jmp 0x6f011
leaq 0x90(%rip), %rax        # 0x6f0a1
movq %rax, 0x28(%rbx)
movq 0x40(%rsp), %rax
leaq -0xf4(%rip), %rcx       # 0x6ef2d
movq %rcx, 0x20(%rbx)
leaq -0xfa(%rip), %rcx       # 0x6ef32
movq %rcx, 0x40(%rbx)
leaq -0xed(%rip), %rcx       # 0x6ef4a
movq %rcx, 0x50(%rbx)
leaq -0xf0(%rip), %rcx       # 0x6ef52
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 0x6f06d
movl %r14d, 0x64(%rbx)
jmp 0x6f08f
leaq 0x15188(%rip), %rsi     # 0x841fc
leaq 0x1519b(%rip), %rdx     # 0x84216
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
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