// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %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 $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x1, -0x1c(%rbp)
jge 0xe1edd
jmp 0xe204d
movl $0x880, %edi            # imm = 0x880
callq 0x4650
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xe1efe
movq $0x0, -0x8(%rbp)
jmp 0xe2078
movq -0x30(%rbp), %rax
movl $0x1, (%rax)
movl -0x28(%rbp), %eax
sarl $0x8, %eax
cmpl $0x4, %eax
jl 0xe1f61
movl -0x20(%rbp), %eax
subl $0x1, %eax
jne 0xe1f5a
jmp 0xe1f1d
cmpl $0x5, -0x24(%rbp)
jne 0xe1f34
movq -0x30(%rbp), %rax
leaq 0x162(%rip), %rcx       # 0xe2090
movq %rcx, 0x28(%rax)
jmp 0xe1f58
cmpl $0x3, -0x24(%rbp)
je 0xe1f40
cmpl $0x4, -0x24(%rbp)
jne 0xe1f51
movq -0x30(%rbp), %rax
leaq -0x29b(%rip), %rcx      # 0xe1cb0
movq %rcx, 0x28(%rax)
jmp 0xe1f56
jmp 0xe204d
jmp 0xe1f58
jmp 0xe1f5f
jmp 0xe204d
jmp 0xe1fc1
cmpl $0x1, -0x24(%rbp)
jne 0xe1f78
movq -0x30(%rbp), %rax
leaq -0x5a2(%rip), %rcx      # 0xe19d0
movq %rcx, 0x28(%rax)
jmp 0xe1fbf
cmpl $0x2, -0x24(%rbp)
jne 0xe1f8f
movq -0x30(%rbp), %rax
leaq -0x3c9(%rip), %rcx      # 0xe1bc0
movq %rcx, 0x28(%rax)
jmp 0xe1fbd
cmpl $0x4, -0x24(%rbp)
je 0xe1f9b
cmpl $0x3, -0x24(%rbp)
jne 0xe1fac
movq -0x30(%rbp), %rax
leaq -0x2f6(%rip), %rcx      # 0xe1cb0
movq %rcx, 0x28(%rax)
jmp 0xe1fbb
movq -0x30(%rbp), %rax
leaq 0xd9(%rip), %rcx        # 0xe2090
movq %rcx, 0x28(%rax)
jmp 0xe1fbd
jmp 0xe1fbf
jmp 0xe1fc1
movq -0x30(%rbp), %rax
leaq -0x21c(%rip), %rcx      # 0xe1db0
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
leaq -0x1fb(%rip), %rcx      # 0xe1de0
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rax
leaq -0x1ba(%rip), %rcx      # 0xe1e30
movq %rcx, 0x50(%rax)
movq -0x30(%rbp), %rax
leaq -0x199(%rip), %rcx      # 0xe1e60
movq %rcx, 0x58(%rax)
movq 0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rcx
addq %rcx, %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 -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
je 0xe2039
jmp 0xe204d
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xe2078
movl $0x1, %edi
leaq 0x16d0b(%rip), %rsi     # 0xf8d64
leaq 0x16d1e(%rip), %rdx     # 0xf8d7e
movb $0x0, %al
callq 0x1b030
movq -0x30(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)