// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_io.c
// Function: cram_read_block
cram_block *cram_read_block(cram_fd *fd) {
    cram_block *b = malloc(sizeof(*b));
    unsigned char c;
    uint32_t crc = 0;
    if (!b)
        return NULL;

    //fprintf(stderr, "Block at %d\n", (int)ftell(fd->fp));

    if (-1 == (b->method      = hgetc(fd->fp))) { free(b); return NULL; }
    c = b->method; crc = crc32(crc, &c, 1);
    if (-1 == (b->content_type= hgetc(fd->fp))) { free(b); return NULL; }
    c = b->content_type; crc = crc32(crc, &c, 1);
    if (-1 == fd->vv.varint_decode32_crc(fd, &b->content_id, &crc))  { free(b); return NULL; }
    if (-1 == fd->vv.varint_decode32_crc(fd, &b->comp_size, &crc))   { free(b); return NULL; }
    if (-1 == fd->vv.varint_decode32_crc(fd, &b->uncomp_size, &crc)) { free(b); return NULL; }

    //fprintf(stderr, "  method %d, ctype %d, cid %d, csize %d, ucsize %d\n",
    //      b->method, b->content_type, b->content_id, b->comp_size, b->uncomp_size);

    if (b->method == RAW) {
        if (b->uncomp_size < 0 || b->comp_size != b->uncomp_size) {
            free(b);
            return NULL;
        }
        b->alloc = b->uncomp_size;
        if (!(b->data = malloc(b->uncomp_size))){ free(b); return NULL; }
        if (b->uncomp_size != hread(fd->fp, b->data, b->uncomp_size)) {
            free(b->data);
            free(b);
            return NULL;
        }
    } else {
        if (b->comp_size < 0 || b->uncomp_size < 0) {
            free(b);
            return NULL;
        }
        b->alloc = b->comp_size;
        if (!(b->data = malloc(b->comp_size)))  { free(b); return NULL; }
        if (b->comp_size != hread(fd->fp, b->data, b->comp_size)) {
            free(b->data);
            free(b);
            return NULL;
        }
    }

    if (CRAM_MAJOR_VERS(fd->version) >= 3) {
        if (-1 == int32_decode(fd, (int32_t *)&b->crc32)) {
            free(b->data);
            free(b);
            return NULL;
        }

        b->crc32_checked = fd->ignore_md5;
        b->crc_part = crc;
    } else {
        b->crc32_checked = 1; // CRC not present
    }

    b->orig_method = b->method;
    b->idx = 0;
    b->byte = 0;
    b->bit = 7; // MSB

    return b;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movl $0x50, %edi
callq 0x4680
testq %rax, %rax
je 0x4c87a
movq %rax, %rbx
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x4c6f4
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
movl %eax, (%rbx)
jmp 0x4c704
callq 0xee9b
movl %eax, (%rbx)
cmpl $-0x1, %eax
je 0x4c872
leaq 0x3(%rsp), %rsi
movb %al, (%rsi)
xorl %edi, %edi
movl $0x1, %edx
callq 0x4320
movq %rax, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x4c737
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
movl %eax, 0x8(%rbx)
jmp 0x4c748
callq 0xee9b
movl %eax, 0x8(%rbx)
cmpl $-0x1, %eax
je 0x4c872
leaq 0x3(%rsp), %rsi
movb %al, (%rsi)
movl %r15d, %edi
movl $0x1, %edx
callq 0x4320
leaq 0x4(%rsp), %rdx
movl %eax, (%rdx)
leaq 0xc(%rbx), %rsi
movq %r14, %rdi
callq *0x8990(%r14)
cmpl $-0x1, %eax
je 0x4c872
leaq 0x10(%rbx), %r15
leaq 0x4(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq *0x8990(%r14)
cmpl $-0x1, %eax
je 0x4c872
leaq 0x14(%rbx), %r12
leaq 0x4(%rsp), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq *0x8990(%r14)
cmpl $-0x1, %eax
je 0x4c872
cmpl $0x0, (%rbx)
je 0x4c802
movslq (%r15), %r15
testq %r15, %r15
js 0x4c872
cmpl $0x0, (%r12)
js 0x4c872
movq %r15, 0x28(%rbx)
movq %r15, %rdi
callq 0x4680
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x4c872
movq (%r14), %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x4b15c
cmpq %r15, %rax
je 0x4c838
jmp 0x4c869
movslq (%r12), %r12
testq %r12, %r12
js 0x4c872
cmpl %r12d, (%r15)
jne 0x4c872
movq %r12, 0x28(%rbx)
movq %r12, %rdi
callq 0x4680
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x4c872
movq (%r14), %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x4b15c
cmpq %r12, %rax
jne 0x4c869
cmpl $0x300, 0xc(%r14)       # imm = 0x300
jl 0x4c88b
movq %rbx, %rsi
addq $0x18, %rsi
movq (%r14), %rdi
callq 0x4c8af
cmpl $-0x1, %eax
je 0x4c869
movl 0x22c(%r14), %eax
movl %eax, 0x48(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x4c(%rbx)
jmp 0x4c892
movq 0x20(%rbx), %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0x1, 0x48(%rbx)
movl (%rbx), %eax
movl %eax, 0x4(%rbx)
movl $0x0, 0x1c(%rbx)
movq $0x0, 0x30(%rbx)
movl $0x7, 0x38(%rbx)
jmp 0x4c87c