// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/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 == itf8_decode_crc(fd, &b->content_id, &crc))  { free(b); return NULL; }
    if (-1 == itf8_decode_crc(fd, &b->comp_size, &crc))   { free(b); return NULL; }
    if (-1 == itf8_decode_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) {
	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 {
	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);
	    return NULL;
	}

	crc = crc32(crc, b->data ? b->data : (uc *)"", b->alloc);
	if (crc != b->crc32) {
	    fprintf(stderr, "Block CRC32 failure\n");
	    free(b->data);
	    free(b);
	    return NULL;
	}
    }

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

    return b;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %r14
pushq $0x40
popq %rdi
callq 0x46f0
testq %rax, %rax
je 0x27cae
movq %rax, %rbx
movq (%r14), %rdi
callq 0x266a9
movl %eax, (%rbx)
cmpl $-0x1, %eax
je 0x27ca6
leaq 0xb(%rsp), %rsi
movb %al, (%rsi)
pushq $0x1
popq %rdx
xorl %edi, %edi
callq 0x43b0
movq %rax, %r15
movq (%r14), %rdi
callq 0x266a9
movl %eax, 0x8(%rbx)
cmpl $-0x1, %eax
je 0x27ca6
leaq 0xb(%rsp), %rsi
movb %al, (%rsi)
movl %r15d, %edi
pushq $0x1
popq %rdx
callq 0x43b0
leaq 0xc(%rsp), %rdx
movl %eax, (%rdx)
leaq 0xc(%rbx), %rsi
movq %r14, %rdi
callq 0x266c3
cmpl $-0x1, %eax
je 0x27ca6
leaq 0x10(%rbx), %rsi
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
callq 0x266c3
cmpl $-0x1, %eax
je 0x27ca6
leaq 0x14(%rbx), %rsi
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
callq 0x266c3
cmpl $-0x1, %eax
je 0x27ca6
movl (%rbx), %ebp
testl %ebp, %ebp
je 0x27c17
movslq 0x10(%rbx), %r15
jmp 0x27c1b
movslq 0x14(%rbx), %r15
movq %r15, 0x28(%rbx)
movq %r15, %rdi
callq 0x46f0
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x27ca6
movq %rax, %r12
movq (%r14), %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x277fd
cmpq %r15, %rax
jne 0x27c9e
cmpl $0x300, 0xc(%r14)       # imm = 0x300
jl 0x27c89
movq %rbx, %rsi
addq $0x18, %rsi
movq %r14, %rdi
callq 0x277cc
cmpl $-0x1, %eax
je 0x27ca6
movl 0xc(%rsp), %edi
movq 0x20(%rbx), %r14
testq %r14, %r14
leaq 0x1bf76(%rip), %rsi     # 0x43bec
cmovneq %r14, %rsi
movl 0x28(%rbx), %edx
callq 0x43b0
cmpl %eax, 0x18(%rbx)
jne 0x27cc0
movl (%rbx), %ebp
movl %ebp, 0x4(%rbx)
andl $0x0, 0x1c(%rbx)
andq $0x0, 0x30(%rbx)
movl $0x7, 0x38(%rbx)
jmp 0x27cb0
movq %r12, %rdi
callq 0x4600
movq %rbx, %rdi
callq 0x4600
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x2f309(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0x1dc83(%rip), %rdi     # 0x45954
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
movq %r14, %rdi
jmp 0x27ca1