// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movl $0x40, %edi
callq 0x69d0
testq %rax, %rax
je 0x564f4
movq %rax, %rbx
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x5638a
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
movl %eax, (%rbx)
jmp 0x5639a
callq 0x6af76
movl %eax, (%rbx)
cmpl $-0x1, %eax
je 0x564ec
leaq 0x7(%rsp), %rsi
movb %al, (%rsi)
xorl %edi, %edi
movl $0x1, %edx
callq 0x64b0
movq %rax, %r15
movq (%r14), %rdi
movq 0x8(%rdi), %rax
cmpq %rax, 0x10(%rdi)
jbe 0x563cd
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rdi)
movzbl (%rax), %eax
movl %eax, 0x8(%rbx)
jmp 0x563de
callq 0x6af76
movl %eax, 0x8(%rbx)
cmpl $-0x1, %eax
je 0x564ec
leaq 0x7(%rsp), %rsi
movb %al, (%rsi)
movl %r15d, %edi
movl $0x1, %edx
callq 0x64b0
leaq 0x8(%rsp), %rdx
movl %eax, (%rdx)
leaq 0xc(%rbx), %rsi
movq %r14, %rdi
callq 0x545f8
cmpl $-0x1, %eax
je 0x564ec
leaq 0x10(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x545f8
cmpl $-0x1, %eax
je 0x564ec
leaq 0x14(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x545f8
cmpl $-0x1, %eax
je 0x564ec
movl (%rbx), %ebp
testl %ebp, %ebp
je 0x564b5
movslq 0x10(%rbx), %r15
movq %r15, 0x28(%rbx)
movq %r15, %rdi
callq 0x69d0
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x564ec
movl %ebp, 0xc(%rsp)
movq (%r14), %rbp
movq 0x8(%rbp), %rsi
movq 0x10(%rbp), %r12
subq %rsi, %r12
cmpq %r15, %r12
movq %r15, %r13
cmovbq %r12, %r13
movq %rax, %rdi
movq %r13, %rdx
movq %rax, 0x10(%rsp)
callq 0x6570
addq %r13, 0x8(%rbp)
cmpq %r15, %r12
jae 0x56508
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
movq %rsi, %r12
movq %r15, %rdx
movq %r13, %rcx
callq 0x6b0a3
movq %rax, %r13
jmp 0x5650d
movslq 0x14(%rbx), %r15
movq %r15, 0x28(%rbx)
movq %r15, %rdi
callq 0x69d0
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x564ec
movq %rax, %r12
movq (%r14), %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x55f97
cmpq %r15, %rax
je 0x56516
movq %r12, %rdi
callq 0x68a0
movq %rbx, %rdi
callq 0x68a0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r12
cmpq %r15, %r13
movl 0xc(%rsp), %ebp
jne 0x564e4
cmpl $0x300, 0xc(%r14)       # imm = 0x300
jl 0x56559
movq %rbx, %rsi
addq $0x18, %rsi
movq %r14, %rdi
callq 0x55f12
cmpl $-0x1, %eax
je 0x564ec
movl 0x8(%rsp), %edi
movq 0x20(%rbx), %r14
testq %r14, %r14
leaq 0x41f0e(%rip), %rsi     # 0x98454
cmovneq %r14, %rsi
movl 0x28(%rbx), %edx
callq 0x64b0
cmpl %eax, 0x18(%rbx)
jne 0x56574
movl (%rbx), %ebp
movl %ebp, 0x4(%rbx)
movl $0x0, 0x1c(%rbx)
movq $0x0, 0x30(%rbx)
movl $0x7, 0x38(%rbx)
jmp 0x564f6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x76ec
jmp 0x564f4