// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, 0x8(%rsp)
movq %rdi, %rbx
cmpl $0x0, 0x48(%rdi)
jne 0x3f965
movl 0x4c(%rbx), %edi
movq 0x20(%rbx), %rax
testq %rax, %rax
leaq 0x3840d(%rip), %rsi     # 0x77d56
cmovneq %rax, %rsi
movl 0x28(%rbx), %edx
callq 0x4320
movl $0x1, 0x48(%rbx)
cmpl %eax, 0x18(%rbx)
jne 0x3f9e7
movl 0x14(%rbx), %r15d
testq %r15, %r15
je 0x3f9dc
testl %r15d, %r15d
js 0x3fd35
movl (%rbx), %r14d
cmpq $0x8, %r14
ja 0x3fd1c
leaq 0x3c88d(%rip), %rax     # 0x7c218
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 0x3f23a
pushq $-0x1
popq %r14
testq %rax, %rax
je 0x3fd20
movq %rax, %r15
movq 0x8(%rsp), %r12
movslq 0x14(%rbx), %rax
cmpq %rax, %r12
jne 0x3fce6
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movq %r12, 0x28(%rbx)
andl $0x0, (%rbx)
xorl %r14d, %r14d
jmp 0x3fd20
leaq 0x3d2b1(%rip), %rsi     # 0x7cc9f
leaq 0x3d2c0(%rip), %rdx     # 0x7ccb5
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x3fd1c
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x6026e
testq %rax, %rax
je 0x3fd1c
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
je 0x3fbe2
jmp 0x3fd14
movl %r15d, 0x10(%rsp)
movq %r15, %rdi
callq 0x4680
testq %rax, %rax
je 0x3fd1c
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 0x3fc43
movq %r15, %rdi
jmp 0x3fd17
movq 0x20(%rbx), %r15
movslq 0x10(%rbx), %r13
leaq 0x10(%rsp), %r14
movl $0x88, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x4260
pushq $0x9
popq %rdi
callq 0x4980
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x4110
testl %eax, %eax
jne 0x3fd1c
movq %r13, 0x18(%rsp)
movq %r15, 0x10(%rsp)
testl %r13d, %r13d
je 0x3fc63
xorl %r15d, %r15d
leaq 0x10(%rsp), %r12
xorl %ebp, %ebp
xorl %r14d, %r14d
movq %r15, %rcx
subq %rbp, %rcx
cmpq %rcx, %r13
jbe 0x3fb03
leaq (%r15,%r13,4), %r15
addq $0x8000, %r15           # imm = 0x8000
movq %r14, %rdi
movq %r15, %rsi
callq 0x4840
testq %rax, %rax
je 0x3fd0a
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 0x3fcf0
cmpl $0x1, %eax
je 0x3fc66
movq 0x18(%rsp), %r13
movq 0x38(%rsp), %rbp
testq %r13, %r13
jne 0x3fad0
jmp 0x3fc66
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 0x4d259
testq %rax, %rax
je 0x3fd1c
movq %rax, %r15
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movq 0x8(%rsp), %rax
jmp 0x3fc54
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x513e8
testq %rax, %rax
je 0x3fd1c
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
jne 0x3fd14
movl $0x5, 0x4(%rbx)
jmp 0x3fbe2
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rcx
xorl %edx, %edx
callq 0x4a3c1
testq %rax, %rax
je 0x3fd1c
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
jne 0x3fd14
movl $0x6, 0x4(%rbx)
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r14, 0x20(%rbx)
movl 0x10(%rsp), %eax
movq %rax, 0x28(%rbx)
andl $0x0, (%rbx)
jmp 0x3fc3b
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x62d34
testq %rax, %rax
je 0x3fd1c
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 0x3f9df
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movl 0x10(%rsp), %eax
movq %rax, 0x28(%rbx)
andl $0x0, (%rbx)
movl %eax, 0x14(%rbx)
jmp 0x3fd20
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x41b0
cmpl $0x2, %eax
jb 0x3fc88
leaq 0x3d57d(%rip), %rsi     # 0x7d1fc
leaq 0x3d5a6(%rip), %rdx     # 0x7d22c
jmp 0x3fcfe
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
pushq $-0x1
popq %r14
testq %r15, %r15
je 0x3fd20
movslq 0x14(%rbx), %rax
cmpq %rax, %r13
jne 0x3fce6
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movq %r13, 0x28(%rbx)
jmp 0x3f9dc
movq %r15, %rdi
callq 0x45c0
jmp 0x3fd20
leaq 0x3d505(%rip), %rsi     # 0x7d1fc
leaq 0x3d50f(%rip), %rdx     # 0x7d20d
pushq $0x1
popq %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x110c6
leaq 0x10(%rsp), %rdi
callq 0x4730
movq %r14, %rdi
callq 0x45c0
pushq $-0x1
popq %r14
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3cf8d(%rip), %rdi     # 0x7ccc9
leaq 0x3cef7(%rip), %rsi     # 0x7cc3a
leaq 0x3cf93(%rip), %rcx     # 0x7ccdd
movl $0x63b, %edx            # imm = 0x63B
callq 0x42f0