// File: /workspace/github_c_makefile_star2_O1/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 0x8e69e
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 0x8e75a
movq %rax, %rbx
movl $0x1, (%rax)
cmpl $0x400, %r13d           # imm = 0x400
jl 0x8e6a5
cmpl $0x1, %r12d
jne 0x8e738
cmpl $0x5, %r14d
je 0x8e6d5
leal -0x3(%r14), %eax
cmpl $0x1, %eax
jbe 0x8e6cc
jmp 0x8e738
xorl %ebx, %ebx
jmp 0x8e738
cmpl $0x2, %r14d
je 0x8e6ba
cmpl $0x1, %r14d
jne 0x8e6c3
leaq -0x4f4(%rip), %rax      # 0x8e1c4
jmp 0x8e6dc
leaq -0x3e7(%rip), %rax      # 0x8e2da
jmp 0x8e6dc
leal -0x3(%r14), %eax
cmpl $0x1, %eax
ja 0x8e6d5
leaq -0x2e3(%rip), %rax      # 0x8e3f0
jmp 0x8e6dc
leaq 0x92(%rip), %rax        # 0x8e76e
movq %rax, 0x28(%rbx)
movq 0x40(%rsp), %rax
leaq -0x214(%rip), %rcx      # 0x8e4d8
movq %rcx, 0x20(%rbx)
leaq -0x215(%rip), %rcx      # 0x8e4e2
movq %rcx, 0x40(%rbx)
leaq -0x17c(%rip), %rcx      # 0x8e586
movq %rcx, 0x50(%rbx)
leaq -0xf0(%rip), %rcx       # 0x8e61d
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 0x8e738
movl %r14d, 0x64(%rbx)
jmp 0x8e75c
leaq 0x16a4d(%rip), %rsi     # 0xa518c
leaq 0x16a60(%rip), %rdx     # 0xa51a6
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
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