// File: /workspace/github_c_makefile_star2_O1/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 0x4f89a
movl 0x4c(%rbx), %edi
movq 0x20(%rbx), %rax
testq %rax, %rax
leaq 0x4944b(%rip), %rsi     # 0x98ccd
cmovneq %rax, %rsi
movl 0x28(%rbx), %edx
callq 0x4320
movl $0x1, 0x48(%rbx)
cmpl %eax, 0x18(%rbx)
jne 0x4f8f9
movl 0x14(%rbx), %r15d
testq %r15, %r15
je 0x4fc52
testl %r15d, %r15d
js 0x4fc7a
movl (%rbx), %r14d
cmpq $0x8, %r14
ja 0x4fb65
leaq 0x4d984(%rip), %rax     # 0x9d248
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 0x4ec27
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x4fc5b
movq %rax, %r15
jmp 0x4fc31
leaq 0x4e3a7(%rip), %rsi     # 0x9dca7
leaq 0x4e3b6(%rip), %rdx     # 0x9dcbd
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x4fb65
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x7bca2
testq %rax, %rax
je 0x4fb65
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
je 0x4fafd
jmp 0x4fb5d
movl %r15d, 0x10(%rsp)
movq %r15, %rdi
callq 0x4680
testq %rax, %rax
je 0x4fb65
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 0x4fb70
movq %r15, %rdi
jmp 0x4fb60
movq 0x20(%rbx), %r12
movslq 0x10(%rbx), %r13
leaq 0x10(%rsp), %r14
xorl %r15d, %r15d
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 0x4fc26
movq %r13, 0x18(%rsp)
movq %r12, 0x10(%rsp)
testl %r13d, %r13d
je 0x4fb93
xorl %r15d, %r15d
leaq 0x10(%rsp), %r12
xorl %ebp, %ebp
xorl %r13d, %r13d
movq 0x18(%rsp), %rax
movq %r15, %rcx
subq %rbp, %rcx
cmpq %rcx, %rax
jbe 0x4fa1c
leaq (%r15,%rax,4), %r15
addq $0x8000, %r15           # imm = 0x8000
movq %r13, %rdi
movq %r15, %rsi
callq 0x4840
movq %rax, %r14
testq %rax, %rax
jne 0x4fa1f
jmp 0x4fc11
movq %r13, %r14
movq %r15, %rax
subq %rbp, %rax
movq %rax, 0x30(%rsp)
addq %r14, %rbp
movq %rbp, 0x28(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x41b0
cmpl $0x2, %eax
jae 0x4fbf2
cmpl $0x1, %eax
je 0x4fb96
movq 0x38(%rsp), %rbp
cmpq $0x0, 0x18(%rsp)
movq %r14, %r13
jne 0x4f9e9
jmp 0x4fb96
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 0x62152
testq %rax, %rax
je 0x4fb65
movq %rax, %r15
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movq 0x8(%rsp), %rax
jmp 0x4fb81
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x67d07
testq %rax, %rax
je 0x4fb65
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
jne 0x4fb5d
movl $0x5, 0x4(%rbx)
jmp 0x4fafd
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rcx
xorl %edx, %edx
callq 0x5d1f5
testq %rax, %rax
je 0x4fb65
movq %rax, %r14
cmpl 0x10(%rsp), %r15d
jne 0x4fb5d
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 0x4fb55
movq 0x20(%rbx), %rdi
movl 0x10(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x7eddc
testq %rax, %rax
je 0x4fb65
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 0x4fc58
movq %r14, %rdi
callq 0x45c0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x4fc5b
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 0x4fc5b
xorl %r14d, %r14d
leaq 0x10(%rsp), %rdi
movl $0x3, %esi
callq 0x41b0
cmpl $0x2, %eax
jb 0x4fbba
leaq 0x4e658(%rip), %rsi     # 0x9e209
leaq 0x4e681(%rip), %rdx     # 0x9e239
jmp 0x4fc00
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), %rax
movq %rax, 0x8(%rsp)
movq %r12, %rdi
callq 0x4730
jmp 0x4fc26
leaq 0x4e610(%rip), %rsi     # 0x9e209
leaq 0x4e61a(%rip), %rdx     # 0x9e21a
movl $0x1, %edi
movl %eax, %ecx
xorl %eax, %eax
callq 0x14378
movq %r14, %r13
leaq 0x10(%rsp), %rdi
callq 0x4730
movq %r13, %rdi
callq 0x45c0
xorl %r15d, %r15d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x4fc5b
movslq 0x14(%rbx), %rax
cmpq %rax, 0x8(%rsp)
jne 0x4fc70
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %r15, 0x20(%rbx)
movq 0x8(%rsp), %rax
movq %rax, 0x28(%rbx)
movl $0x0, (%rbx)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x45c0
jmp 0x4fc5b
leaq 0x4e050(%rip), %rdi     # 0x9dcd1
leaq 0x4dfba(%rip), %rsi     # 0x9dc42
leaq 0x4e056(%rip), %rcx     # 0x9dce5
movl $0x63b, %edx            # imm = 0x63B
callq 0x42f0