// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %r15d
movl %esi, %ebp
movq %rdi, %r14
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
callq 0x15f40
movq %rax, %rbx
testq %rax, %rax
je 0x75e42
cmpl $-0x1, %r15d
je 0x75c92
movl %r15d, (%rbx)
decl %r15d
cmpl $0x7, %r15d
ja 0x75e42
leaq 0x35fec(%rip), %rax     # 0xabc50
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
cmpl $0x4, %ebp
jl 0x75e42
movzbl 0x3(%r14), %eax
leal -0x31(%rax), %ecx
cmpb $0x8, %cl
ja 0x75e42
addl $-0x30, %eax
movl %eax, 0x4(%rbx)
jmp 0x75e42
cmpl $0x2, %ebp
jl 0x75e3d
cmpb $0x1f, (%r14)
jne 0x75cda
cmpb $-0x75, 0x1(%r14)
jne 0x75cda
movl $0x1, (%rbx)
cmpl $0x9, %ebp
jl 0x75e42
movzbl 0x8(%r14), %eax
cmpl $0x2, %eax
je 0x75e59
cmpl $0x4, %eax
je 0x75e50
movl $0x5, 0x4(%rbx)
jmp 0x75e42
cmpl $0x4, %ebp
jb 0x75e3d
cmpb $0x42, 0x1(%r14)
jne 0x75e22
cmpb $0x5a, 0x2(%r14)
jne 0x75e22
cmpb $0x68, 0x3(%r14)
jne 0x75e22
movl $0x2, (%rbx)
jmp 0x75e42
movl $0x4, 0x20(%rbx)
testl %ebp, %ebp
jle 0x75e42
cmpb $0x1, (%r14)
jne 0x75e42
movl $0x1, 0x8(%rbx)
jmp 0x75e42
cmpl $0x9, %ebp
jl 0x75e42
movzbl 0x8(%r14), %eax
testl %eax, %eax
je 0x75e50
cmpl $0x1, %eax
jne 0x75e42
movl $0xb, 0x4(%rbx)
jmp 0x75e42
testl %ebp, %ebp
jle 0x75e42
movzbl (%r14), %eax
movl %eax, %ecx
andl $0x1, %ecx
testb $0x4, %al
pushq $0x4
popq %rdx
pushq $0x20
popq %rsi
cmovel %edx, %esi
movl %ecx, 0x8(%rbx)
movl %esi, 0x20(%rbx)
movl %eax, %ecx
shrl $0x6, %ecx
andl $0x1, %ecx
movl %ecx, 0xc(%rbx)
movl %eax, %ecx
shrl $0x7, %ecx
movl %ecx, 0x10(%rbx)
movl %eax, %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
movl %ecx, 0x18(%rbx)
movl %eax, %ecx
shrl $0x3, %ecx
andl $0x1, %ecx
movl %ecx, 0x14(%rbx)
shrl $0x4, %eax
andl $0x1, %eax
movl %eax, 0x1c(%rbx)
jmp 0x75e42
testl %ebp, %ebp
jle 0x75e42
movzbl (%r14), %eax
movl %eax, %ecx
shrb $0x6, %cl
movzbl %cl, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movd %ecx, %xmm0
pand 0x35e63(%rip), %xmm0    # 0xabc40
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(%rbx)
movl %eax, %ecx
shrl $0x7, %ecx
movl %ecx, 0x10(%rbx)
movl %eax, %ecx
shrl $0x5, %ecx
andl $0x1, %ecx
movl %ecx, 0x18(%rbx)
movl %eax, %ecx
shrl $0x3, %ecx
andl $0x1, %ecx
movl %ecx, 0x14(%rbx)
movl %eax, %ecx
shrl $0x4, %ecx
andl $0x1, %ecx
movl %ecx, 0x1c(%rbx)
shrl $0x2, %eax
andl $0x1, %eax
movl %eax, 0x24(%rbx)
jmp 0x75e42
cmpl $0x7, %ebp
jb 0x75e3d
leaq 0x35ed7(%rip), %rdi     # 0xabd05
pushq $0x6
popq %rdx
movq %r14, %rsi
callq 0x15510
testl %eax, %eax
je 0x75e62
pushq $-0x1
popq %rax
movl %eax, (%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x4(%rbx)
jmp 0x75e42
movl $0x9, 0x4(%rbx)
jmp 0x75e42
pushq $0x3
jmp 0x75e3f