// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/bgzf.c
// Function: bgzf_read
ssize_t bgzf_read(BGZF *fp, void *data, size_t length)
{
    ssize_t bytes_read = 0;
    uint8_t *output = (uint8_t*)data;
    if (length <= 0) return 0;
    assert(fp->is_write == 0);
    while (bytes_read < length) {
        int copy_length, available = fp->block_length - fp->block_offset;
        uint8_t *buffer;
        if (available <= 0) {
            int ret = bgzf_read_block(fp);
            if (ret != 0) {
                hts_log_error("Read block operation failed with error %d after %zd of %zu bytes", fp->errcode, bytes_read, length);
                fp->errcode |= BGZF_ERR_ZLIB;
                return -1;
            }
            available = fp->block_length - fp->block_offset;
            if (available == 0) {
                if (fp->block_length == 0)
                    break; // EOF

                // Offset was at end of block (see commit e9863a0)
                fp->block_address = bgzf_htell(fp);
                fp->block_offset = fp->block_length = 0;
                continue;
            } else if (available < 0) {
                // Block offset was set to an invalid coordinate
                hts_log_error("BGZF block offset %d set beyond block size %d",
                              fp->block_offset, fp->block_length);
                fp->errcode |= BGZF_ERR_MISUSE;
                return -1;
            }
        }
        copy_length = length - bytes_read < available? length - bytes_read : available;
        buffer = (uint8_t*)fp->uncompressed_block;
        memcpy(output, buffer + fp->block_offset, copy_length);
        fp->block_offset += copy_length;
        output += copy_length;
        bytes_read += copy_length;

        // For raw gzip streams this avoids short reads.
        if (fp->block_offset == fp->block_length) {
            fp->block_address = bgzf_htell(fp);
            fp->block_offset = fp->block_length = 0;
        }
    }

    fp->uncompressed_address += bytes_read;

    return bytes_read;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdx, %rdx
je 0xc0b5
movq %rdi, %r14
testb $0x2, 0x2(%rdi)
jne 0xc0dd
movq %rdx, %r15
movq %rsi, %r12
xorl %ebx, %ebx
movl 0x8(%r14), %r13d
subl 0x10(%r14), %r13d
jg 0xbfd3
movq %r14, %rdi
callq 0xae60
testl %eax, %eax
je 0xc03f
movzwl (%r14), %ecx
movl $0x1, %ebp
movl $0x1, %edi
leaq 0x8bc5c(%rip), %rsi     # 0x97c11
leaq 0x8bc5f(%rip), %rdx     # 0x97c1b
movq %rbx, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x14378
xorl %eax, %eax
orb $0x1, (%r14)
testb %al, %al
je 0xc027
movq %r15, %rax
subq %rbx, %rax
movslq %r13d, %rcx
cmpq %rcx, %rax
cmovaeq %rcx, %rax
movslq 0x10(%r14), %rsi
addq 0x28(%r14), %rsi
movslq %eax, %rbp
movq %r12, %rdi
movq %rbp, %rdx
callq 0x43c0
movl 0x10(%r14), %eax
addl %ebp, %eax
movl %eax, 0x10(%r14)
addq %rbp, %r12
addq %rbp, %rbx
xorl %ebp, %ebp
cmpl 0x8(%r14), %eax
jne 0xc027
movq %r14, %rdi
callq 0xb812
movq %rax, 0x18(%r14)
xorl %ebp, %ebp
movl %ebp, 0x8(%r14)
movl %ebp, 0x10(%r14)
testl %ebp, %ebp
je 0xc034
cmpl $0x2, %ebp
jne 0xc0b9
cmpq %r15, %rbx
jb 0xbf86
jmp 0xc0be
movl 0x8(%r14), %r8d
movl 0x10(%r14), %ecx
movl %r8d, %r13d
subl %ecx, %r13d
je 0xc05a
js 0xc07c
xorl %ebp, %ebp
movb $0x1, %al
jmp 0xbfcf
testl %r8d, %r8d
je 0xc0a6
movq %r14, %rdi
callq 0xb812
movq %rax, 0x18(%r14)
xorl %eax, %eax
movl %eax, 0x8(%r14)
movl %eax, 0x10(%r14)
movl $0x2, %ebp
jmp 0xc0ad
movl $0x1, %ebp
movl $0x1, %edi
leaq 0x8bb84(%rip), %rsi     # 0x97c11
leaq 0x8bbc8(%rip), %rdx     # 0x97c5c
xorl %eax, %eax
callq 0x14378
xorl %eax, %eax
orb $0x8, (%r14)
jmp 0xbfcf
xorl %eax, %eax
movl $0x3, %ebp
xorl %r13d, %r13d
jmp 0xbfcf
xorl %ebx, %ebx
jmp 0xc0cb
cmpl $0x3, %ebp
jne 0xc0c4
addq %rbx, 0x20(%r14)
jmp 0xc0cb
movq $-0x1, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8baea(%rip), %rdi     # 0x97bce
leaq 0x8baf5(%rip), %rsi     # 0x97be0
leaq 0x8baf5(%rip), %rcx     # 0x97be7
movl $0x4dc, %edx            # imm = 0x4DC
callq 0x42f0