// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/bgzf.c
// Function: bgzf_read
int
bgzf_read(BGZF* fp, void* data, int length)
{
    if (length <= 0) {
        return 0;
    }
    if (fp->open_mode != 'r') {
        report_error(fp, "file not open for reading");
        return -1;
    }

    int bytes_read = 0;
    bgzf_byte_t* output = data;
    while (bytes_read < length) {
        int copy_length, available = fp->block_length - fp->block_offset;
		bgzf_byte_t *buffer;
        if (available <= 0) {
            if (bgzf_read_block(fp) != 0) {
                return -1;
            }
            available = fp->block_length - fp->block_offset;
            if (available <= 0) {
                break;
            }
        }
        copy_length = bgzf_min(length-bytes_read, available);
        buffer = fp->uncompressed_block;
        memcpy(output, buffer + fp->block_offset, copy_length);
        fp->block_offset += copy_length;
        output += copy_length;
        bytes_read += copy_length;
    }
    if (fp->block_offset == fp->block_length) {
#ifdef _USE_KNETFILE
        fp->block_address = knet_tell(fp->x.fpr);
#else
        fp->block_address = ftello(fp->file);
#endif
        fp->block_offset = 0;
        fp->block_length = 0;
    }
    return bytes_read;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movl %edx, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jg 0x4f76e6
movl $0x0, 0x34(%rsp)
jmp 0x4f7849
movq 0x28(%rsp), %rax
movsbl 0x4(%rax), %eax
cmpl $0x72, %eax
je 0x4f7712
movq 0x28(%rsp), %rdi
leaq 0xc55e0(%rip), %rsi     # 0x5bcce0
callq 0x4f72e0
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0x4f7849
movl $0x0, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jge 0x4f77fd
movq 0x28(%rsp), %rax
movl 0x38(%rax), %eax
movq 0x28(%rsp), %rcx
subl 0x3c(%rcx), %eax
movl %eax, 0x8(%rsp)
cmpl $0x0, 0x8(%rsp)
jg 0x4f7788
movq 0x28(%rsp), %rdi
callq 0x4f6fc0
cmpl $0x0, %eax
je 0x4f7769
movl $0xffffffff, 0x34(%rsp) # imm = 0xFFFFFFFF
jmp 0x4f7849
movq 0x28(%rsp), %rax
movl 0x38(%rax), %eax
movq 0x28(%rsp), %rcx
subl 0x3c(%rcx), %eax
movl %eax, 0x8(%rsp)
cmpl $0x0, 0x8(%rsp)
jg 0x4f7786
jmp 0x4f77fd
jmp 0x4f7788
movl 0x1c(%rsp), %edi
subl 0x18(%rsp), %edi
movl 0x8(%rsp), %esi
callq 0x4f7860
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, (%rsp)
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
movq 0x28(%rsp), %rax
movslq 0x3c(%rax), %rax
addq %rax, %rsi
movslq 0xc(%rsp), %rdx
callq 0x19610
movl 0xc(%rsp), %ecx
movq 0x28(%rsp), %rax
addl 0x3c(%rax), %ecx
movl %ecx, 0x3c(%rax)
movl 0xc(%rsp), %ecx
movq 0x10(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movl 0xc(%rsp), %eax
addl 0x18(%rsp), %eax
movl %eax, 0x18(%rsp)
jmp 0x4f7724
movq 0x28(%rsp), %rax
movl 0x3c(%rax), %eax
movq 0x28(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jne 0x4f7841
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x19af0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x28(%rsp), %rax
movl $0x0, 0x3c(%rax)
movq 0x28(%rsp), %rax
movl $0x0, 0x38(%rax)
movl 0x18(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)