// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_io.c
// Function: cram_uncompress_block
int cram_uncompress_block(cram_block *b) {
    char *uncomp;
    size_t uncomp_size = 0;

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    // Pretend the CRC was OK so the fuzzer doesn't have to get it right
    b->crc32_checked = 1;
#endif

    if (b->crc32_checked == 0) {
        uint32_t crc = crc32(b->crc_part, b->data ? b->data : (uc *)"", b->alloc);
        b->crc32_checked = 1;
        if (crc != b->crc32) {
            hts_log_error("Block CRC32 failure");
            return -1;
        }
    }

    if (b->uncomp_size == 0) {
        // blank block
        b->method = RAW;
        return 0;
    }
    assert(b->uncomp_size >= 0); // cram_read_block should ensure this

    switch (b->method) {
    case RAW:
        return 0;

    case GZIP:
        uncomp_size = b->uncomp_size;
        uncomp = zlib_mem_inflate((char *)b->data, b->comp_size, &uncomp_size);

        if (!uncomp)
            return -1;
        if (uncomp_size != b->uncomp_size) {
            free(uncomp);
            return -1;
        }
        free(b->data);
        b->data = (unsigned char *)uncomp;
        b->alloc = uncomp_size;
        b->method = RAW;
        break;

#ifdef HAVE_LIBBZ2
    case BZIP2: {
        unsigned int usize = b->uncomp_size;
        if (!(uncomp = malloc(usize)))
            return -1;
        if (BZ_OK != BZ2_bzBuffToBuffDecompress(uncomp, &usize,
                                                (char *)b->data, b->comp_size,
                                                0, 0)) {
            free(uncomp);
            return -1;
        }
        free(b->data);
        b->data = (unsigned char *)uncomp;
        b->alloc = usize;
        b->method = RAW;
        b->uncomp_size = usize; // Just in case it differs
        break;
    }
#else
    case BZIP2:
        hts_log_error("Bzip2 compression is not compiled into this version. Please rebuild and try again");
        return -1;
#endif

#ifdef HAVE_LIBLZMA
    case LZMA:
        uncomp = lzma_mem_inflate((char *)b->data, b->comp_size, &uncomp_size);
        if (!uncomp)
            return -1;
        if (uncomp_size != b->uncomp_size) {
            free(uncomp);
            return -1;
        }
        free(b->data);
        b->data = (unsigned char *)uncomp;
        b->alloc = uncomp_size;
        b->method = RAW;
        break;
#else
    case LZMA:
        hts_log_error("Lzma compression is not compiled into this version. Please rebuild and try again");
        return -1;
        break;
#endif

    case RANS: {
        unsigned int usize = b->uncomp_size, usize2;
        uncomp = (char *)rans_uncompress(b->data, b->comp_size, &usize2);
        if (!uncomp)
            return -1;
        if (usize != usize2) {
            free(uncomp);
            return -1;
        }
        free(b->data);
        b->data = (unsigned char *)uncomp;
        b->alloc = usize2;
        b->method = RAW;
        b->uncomp_size = usize2; // Just in case it differs
        //fprintf(stderr, "Expanded %d to %d\n", b->comp_size, b->uncomp_size);
        break;
    }

    case FQZ: {
        uncomp_size = b->uncomp_size;
        uncomp = fqz_decompress((char *)b->data, b->comp_size, &uncomp_size, NULL, 0);
        if (!uncomp)
            return -1;
        free(b->data);
        b->data = (unsigned char *)uncomp;
        b->alloc = uncomp_size;
        b->method = RAW;
        b->uncomp_size = uncomp_size;
        break;
    }

    case RANS_PR0: {
        unsigned int usize = b->uncomp_size, usize2;
        uncomp = (char *)rans_uncompress_4x16(b->data, b->comp_size, &usize2);
        if (!uncomp)
            return -1;
        if (usize != usize2) {
            free(uncomp);
            return -1;
        }
        b->orig_method = RANSPR;
        free(b->data);
        b->data = (unsigned char *)uncomp;
        b->alloc = usize2;
        b->method = RAW;
        b->uncomp_size = usize2; // Just incase it differs
        //fprintf(stderr, "Expanded %d to %d\n", b->comp_size, b->uncomp_size);
        break;
    }

    case ARITH_PR0: {
        unsigned int usize = b->uncomp_size, usize2;
        uncomp = (char *)arith_uncompress_to(b->data, b->comp_size, NULL, &usize2);
        if (!uncomp)
            return -1;
        if (usize != usize2) {
            free(uncomp);
            return -1;
        }
        b->orig_method = ARITH;
        free(b->data);
        b->data = (unsigned char *)uncomp;
        b->alloc = usize2;
        b->method = RAW;
        b->uncomp_size = usize2; // Just incase it differs
        //fprintf(stderr, "Expanded %d to %d\n", b->comp_size, b->uncomp_size);
        break;
    }

    case TOK3: {
        uint32_t out_len;
        uint8_t *cp = tok3_decode_names(b->data, b->comp_size, &out_len);
        if (!cp)
            return -1;
        b->orig_method = TOK3;
        b->method = RAW;
        free(b->data);
        b->data = cp;
        b->alloc = out_len;
        b->uncomp_size = out_len;
        break;
    }

    default:
        return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movq $0x0, 0x8(%rsp)
cmpl $0x0, 0x48(%rdi)
jne 0x4cf27
movl 0x4c(%rbx), %edi
movq 0x20(%rbx), %rax
testq %rax, %rax
leaq 0x48e62(%rip), %rsi     # 0x95d6d
cmovneq %rax, %rsi
movl 0x28(%rbx), %edx
callq 0x4320
movl $0x1, 0x48(%rbx)
cmpl %eax, 0x18(%rbx)
jne 0x4cfae
movl 0x14(%rbx), %r15d
testq %r15, %r15
je 0x4cfa0
testl %r15d, %r15d
js 0x4d30e
movl (%rbx), %r14d
cmpq $0x8, %r14
ja 0x4d2f3
leaq 0x4d35b(%rip), %rax     # 0x9a2a8
movslq (%rax,%r14,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x8(%rsp), %rdx
movq %r15, (%rdx)
movq 0x20(%rbx), %rdi
movslq 0x10(%rbx), %rsi
callq 0x4c45d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x4d2f9
movq %rax, %r15
movq 0x8(%rsp), %r12
movslq 0x14(%rbx), %rax
cmpq %rax, %r12
jne 0x4d2bb
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movq %r12, 0x28(%rbx)
movl $0x0, (%rbx)
xorl %r14d, %r14d
jmp 0x4d2f9
leaq 0x4deea(%rip), %rsi     # 0x9ae9f
leaq 0x4def9(%rip), %rdx     # 0x9aeb5
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x4d2f3
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x79c22
testq %rax, %rax
je 0x4d2f3
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
je 0x4d1ad
jmp 0x4d2eb
movl %r15d, 0x10(%rsp)
movq %r15, %rdi
callq 0x4680
testq %rax, %rax
je 0x4d2f3
movq %rax, %r15
movq 0x20(%rbx), %rdx
movl 0x10(%rbx), %ecx
leaq 0x10(%rsp), %rsi
xorl %r14d, %r14d
movq %rax, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x4560
testl %eax, %eax
je 0x4d211
movq %r15, %rdi
jmp 0x4d2ee
movq 0x20(%rbx), %r15
movslq 0x10(%rbx), %r13
leaq 0x10(%rsp), %r14
movl $0x88, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x4260
movl $0x9, %edi
callq 0x4980
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x4110
testl %eax, %eax
jne 0x4d2f3
movq %r13, 0x18(%rsp)
movq %r15, 0x10(%rsp)
testl %r13d, %r13d
je 0x4d234
xorl %r15d, %r15d
leaq 0x10(%rsp), %r12
xorl %ebp, %ebp
xorl %r14d, %r14d
movq %r15, %rcx
subq %rbp, %rcx
cmpq %rcx, %r13
jbe 0x4d0ce
leaq (%r15,%r13,4), %r15
addq $0x8000, %r15           # imm = 0x8000
movq %r14, %rdi
movq %r15, %rsi
callq 0x4840
testq %rax, %rax
je 0x4d2e1
movq %r15, %rcx
subq %rbp, %rcx
movq %rax, %r14
movq %rcx, 0x30(%rsp)
addq %r14, %rbp
movq %rbp, 0x28(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x41b0
cmpl $0x2, %eax
jae 0x4d2c5
cmpl $0x1, %eax
je 0x4d237
movq 0x18(%rsp), %r13
movq 0x38(%rsp), %rbp
testq %r13, %r13
jne 0x4d09b
jmp 0x4d237
leaq 0x8(%rsp), %rdx
movq %r15, (%rdx)
movq 0x20(%rbx), %rdi
movslq 0x10(%rbx), %rsi
xorl %r14d, %r14d
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x5f793
testq %rax, %rax
je 0x4d2f3
movq %rax, %r15
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movq 0x8(%rsp), %rax
jmp 0x4d222
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x6523b
testq %rax, %rax
je 0x4d2f3
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
jne 0x4d2eb
movl $0x5, 0x4(%rbx)
jmp 0x4d1ad
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rcx
xorl %edx, %edx
callq 0x5a814
testq %rax, %rax
je 0x4d2f3
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
jne 0x4d2eb
movl $0x6, 0x4(%rbx)
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r14, 0x20(%rbx)
movl 0x10(%rsp), %eax
movq %rax, 0x28(%rbx)
movl $0x0, (%rbx)
jmp 0x4d209
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x7cb8e
testq %rax, %rax
je 0x4d2f3
movq %rax, %r14
movabsq $0x800000000, %rax      # imm = 0x800000000
movq %rax, (%rbx)
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r14, 0x20(%rbx)
movl 0x10(%rsp), %eax
movq %rax, 0x28(%rbx)
movl %eax, 0x14(%rbx)
jmp 0x4cfa6
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movl 0x10(%rsp), %eax
movq %rax, 0x28(%rbx)
movl $0x0, (%rbx)
movl %eax, 0x14(%rbx)
jmp 0x4d2f9
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdi
movl $0x3, %esi
callq 0x41b0
cmpl $0x2, %eax
jb 0x4d25b
leaq 0x4e1af(%rip), %rsi     # 0x9b401
leaq 0x4e1d8(%rip), %rdx     # 0x9b431
jmp 0x4d2d3
leaq 0x10(%rsp), %r12
movq 0x28(%r12), %rsi
cmpq $0x1, %rsi
adcq $0x0, %rsi
movq %r14, %rdi
callq 0x4840
movq %rax, %r15
testq %rax, %rax
cmoveq %r14, %r15
movq 0x28(%r12), %r13
movq %r13, 0x8(%rsp)
movq %r12, %rdi
callq 0x4730
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x4d2f9
movslq 0x14(%rbx), %rax
cmpq %rax, %r13
jne 0x4d2bb
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movq %r13, 0x28(%rbx)
jmp 0x4cfa0
movq %r15, %rdi
callq 0x45c0
jmp 0x4d2f9
leaq 0x4e135(%rip), %rsi     # 0x9b401
leaq 0x4e13f(%rip), %rdx     # 0x9b412
movl $0x1, %edi
movl %eax, %ecx
xorl %eax, %eax
callq 0x13de5
leaq 0x10(%rsp), %rdi
callq 0x4730
movq %r14, %rdi
callq 0x45c0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4dbb4(%rip), %rdi     # 0x9aec9
leaq 0x4db1e(%rip), %rsi     # 0x9ae3a
leaq 0x4dbba(%rip), %rcx     # 0x9aedd
movl $0x63b, %edx            # imm = 0x63B
callq 0x42f0