// File: /workspace/github_c_makefile_star2_O1/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 0x15ea0
testq %rax, %rax
je 0x935ea
cmpl $-0x1, %r14d
jne 0x935aa
cmpl $0x2, %ebp
jl 0x9356c
cmpb $0x1f, (%rbx)
jne 0x9356c
movl $0x1, %r14d
cmpb $-0x75, 0x1(%rbx)
je 0x935aa
cmpl $0x4, %ebp
jl 0x93589
cmpb $0x42, 0x1(%rbx)
jne 0x93589
cmpb $0x5a, 0x2(%rbx)
jne 0x93589
movl $0x2, %r14d
cmpb $0x68, 0x3(%rbx)
je 0x935aa
cmpl $0x7, %ebp
jl 0x935a4
movl $0x587a37fd, %ecx       # imm = 0x587A37FD
xorl (%rbx), %ecx
movzwl 0x4(%rbx), %edx
xorl $0x5a, %edx
orl %ecx, %edx
je 0x93704
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, (%rax)
decl %r14d
cmpl $0x7, %r14d
ja 0x935ec
leaq 0x438af(%rip), %rcx     # 0xd6e6c
movslq (%rcx,%r14,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
cmpl $0x9, %ebp
jl 0x935ec
movzbl 0x8(%rbx), %ecx
cmpl $0x2, %ecx
je 0x9371b
cmpl $0x4, %ecx
je 0x9370f
movl $0x5, 0x4(%rax)
jmp 0x935ec
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
movl $0x4, 0x20(%rax)
testl %ebp, %ebp
jle 0x936f8
cmpb $0x1, (%rbx)
jne 0x936f8
movl $0x1, 0x8(%rax)
jmp 0x935ec
cmpl $0x9, %ebp
jl 0x935ec
movzbl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x9370f
cmpl $0x1, %ecx
jne 0x935ec
movl $0xb, 0x4(%rax)
jmp 0x935ec
cmpl $0x4, %ebp
jl 0x935ec
movzbl 0x3(%rbx), %ecx
leal -0x31(%rcx), %edx
cmpb $0x8, %dl
ja 0x935ec
addl $-0x30, %ecx
movl %ecx, 0x4(%rax)
jmp 0x935ec
testl %ebp, %ebp
jle 0x935ec
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 0x935ec
testl %ebp, %ebp
jle 0x935ec
movzbl (%rbx), %ecx
movl %ecx, %edx
andl $0x3, %edx
movl %edx, 0x8(%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)
movl %ecx, %edx
shrl $0x4, %edx
andl $0x1, %edx
movl %edx, 0x1c(%rax)
shrl $0x2, %ecx
andl $0x1, %ecx
movl %ecx, 0x24(%rax)
jmp 0x935ec
movl $0x0, 0x8(%rax)
jmp 0x935ec
movl $0x3, %r14d
jmp 0x935aa
movl $0x1, 0x4(%rax)
jmp 0x935ec
movl $0x9, 0x4(%rax)
jmp 0x935ec