// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_external.c
// Function: cram_expand_method
cram_method_details *cram_expand_method(uint8_t *data, int32_t size,
                                        enum cram_block_method comp) {
    cram_method_details *cm = calloc(1, sizeof(*cm));
    if (!cm)
        return NULL;

    const char *xz_header = "\xFD""7zXZ"; // including nul

    if (comp == CRAM_COMP_UNKNOWN) {
        // Auto-detect
        if (size > 1 && data[0] == 0x1f && data[1] == 0x8b)
            comp = CRAM_COMP_GZIP;
        else if (size > 3 && data[1] == 'B' && data[2] == 'Z'
                 && data[3] == 'h')
            comp = CRAM_COMP_BZIP2;
        else if (size > 6 && memcmp(xz_header, data, 6) == 0)
            comp = CRAM_COMP_LZMA;
        else
            comp = CRAM_COMP_UNKNOWN;
    }
    cm->method = comp;

    // Interrogate the compressed data stream to fill out additional fields.
    switch (comp) {
    case CRAM_COMP_GZIP:
        if (size > 8) {
            if (data[8] == 4)
                cm->level = 1;
            else if (data[8] == 2)
                cm->level = 9;
            else
                cm->level = 5;
        }
        break;

    case CRAM_COMP_BZIP2:
        if (size > 3 && data[3] >= '1' && data[3] <= '9')
            cm->level = data[3]-'0';
        break;

    case CRAM_COMP_RANS4x8:
        cm->Nway = 4;
        if (size > 0 && data[0] == 1)
            cm->order = 1;
        else
            cm->order = 0;
        break;

    case CRAM_COMP_RANSNx16:
        if (size > 0) {
            cm->order  = data[0] & 1;
            cm->Nway   = data[0] & RANS_ORDER_X32    ? 32 : 4;
            cm->rle    = data[0] & RANS_ORDER_RLE    ?  1 : 0;
            cm->pack   = data[0] & RANS_ORDER_PACK   ?  1 : 0;
            cm->cat    = data[0] & RANS_ORDER_CAT    ?  1 : 0;
            cm->stripe = data[0] & RANS_ORDER_STRIPE ?  1 : 0;
            cm->nosz   = data[0] & RANS_ORDER_NOSZ   ?  1 : 0;
        }
        break;

    case CRAM_COMP_ARITH:
        if (size > 0) {
            // Not in a public header, but the same transforms as rANSNx16
            cm->order  = data[0] & 3;
            cm->rle    = data[0] & RANS_ORDER_RLE    ?  1 : 0;
            cm->pack   = data[0] & RANS_ORDER_PACK   ?  1 : 0;
            cm->cat    = data[0] & RANS_ORDER_CAT    ?  1 : 0;
            cm->stripe = data[0] & RANS_ORDER_STRIPE ?  1 : 0;
            cm->nosz   = data[0] & RANS_ORDER_NOSZ   ?  1 : 0;
            cm->ext    = data[0] & 4 /*external*/    ?  1 : 0;
        }
        break;

    case CRAM_COMP_TOK3:
        if (size > 8) {
            if (data[8] == 1)
                cm->level = 11;
            else if (data[8] == 0)
                cm->level = 1;
        }
        break;

    default:
        break;
    }

    return cm;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %r14d
movl %esi, %ebp
movq %rdi, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x15e90
testq %rax, %rax
je 0x908f0
cmpl $-0x1, %r14d
je 0x9074b
movl %r14d, (%rax)
decl %r14d
cmpl $0x7, %r14d
ja 0x908f0
leaq 0x44802(%rip), %rcx     # 0xd4f20
movslq (%rcx,%r14,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
cmpl $0x4, %ebp
jl 0x908f0
movzbl 0x3(%rbx), %ecx
leal -0x31(%rcx), %edx
cmpb $0x8, %dl
ja 0x908f0
addl $-0x30, %ecx
movl %ecx, 0x4(%rax)
jmp 0x908f0
cmpl $0x2, %ebp
jl 0x908e9
cmpb $0x1f, (%rbx)
jne 0x90790
cmpb $-0x75, 0x1(%rbx)
jne 0x90790
movl $0x1, (%rax)
cmpl $0x9, %ebp
jl 0x908f0
movzbl 0x8(%rbx), %ecx
cmpl $0x2, %ecx
je 0x908fe
cmpl $0x4, %ecx
je 0x908f5
movl $0x5, 0x4(%rax)
jmp 0x908f0
cmpl $0x4, %ebp
jb 0x908e9
cmpb $0x42, 0x1(%rbx)
jne 0x908d2
cmpb $0x5a, 0x2(%rbx)
jne 0x908d2
cmpb $0x68, 0x3(%rbx)
jne 0x908d2
movl $0x2, (%rax)
jmp 0x908f0
movl $0x4, 0x20(%rax)
testl %ebp, %ebp
jle 0x908f0
cmpb $0x1, (%rbx)
jne 0x908f0
movl $0x1, 0x8(%rax)
jmp 0x908f0
cmpl $0x9, %ebp
jl 0x908f0
movzbl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x908f5
cmpl $0x1, %ecx
jne 0x908f0
movl $0xb, 0x4(%rax)
jmp 0x908f0
testl %ebp, %ebp
jle 0x908f0
movzbl (%rbx), %ecx
movl %ecx, %edx
andl $0x1, %edx
testb $0x4, %cl
movl $0x4, %esi
movl $0x20, %edi
cmovel %esi, %edi
movl %edx, 0x8(%rax)
movl %edi, 0x20(%rax)
movl %ecx, %edx
shrl $0x6, %edx
andl $0x1, %edx
movl %edx, 0xc(%rax)
movl %ecx, %edx
shrl $0x7, %edx
movl %edx, 0x10(%rax)
movl %ecx, %edx
shrl $0x5, %edx
andl $0x1, %edx
movl %edx, 0x18(%rax)
movl %ecx, %edx
shrl $0x3, %edx
andl $0x1, %edx
movl %edx, 0x14(%rax)
shrl $0x4, %ecx
andl $0x1, %ecx
movl %ecx, 0x1c(%rax)
jmp 0x908f0
testl %ebp, %ebp
jle 0x908f0
movzbl (%rbx), %ecx
movl %ecx, %edx
shrb $0x6, %dl
movzbl %dl, %edx
shll $0x8, %edx
orl %ecx, %edx
movd %edx, %xmm0
pand 0x44683(%rip), %xmm0    # 0xd4f10
pxor %xmm1, %xmm1
punpcklbw %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3],xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
movq %xmm0, 0x8(%rax)
movl %ecx, %edx
shrl $0x7, %edx
movl %edx, 0x10(%rax)
movl %ecx, %edx
shrl $0x5, %edx
andl $0x1, %edx
movl %edx, 0x18(%rax)
movl %ecx, %edx
shrl $0x3, %edx
andl $0x1, %edx
movl %edx, 0x14(%rax)
movl %ecx, %edx
shrl $0x4, %edx
andl $0x1, %edx
movl %edx, 0x1c(%rax)
shrl $0x2, %ecx
andl $0x1, %ecx
movl %ecx, 0x24(%rax)
jmp 0x908f0
cmpl $0x7, %ebp
jb 0x908e9
movl $0x587a37fd, %ecx       # imm = 0x587A37FD
xorl (%rbx), %ecx
movzwl 0x4(%rbx), %edx
xorl $0x5a, %edx
orl %ecx, %edx
je 0x90907
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, (%rax)
popq %rbx
popq %r14
popq %rbp
retq
movl $0x1, 0x4(%rax)
jmp 0x908f0
movl $0x9, 0x4(%rax)
jmp 0x908f0
movl $0x3, %ecx
jmp 0x908ee