// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x20(%rbp)
ja 0xe658
movq $0x0, -0x8(%rbp)
jmp 0xe8b0
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x11, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xe66b
jmp 0xe68a
leaq 0xe0761(%rip), %rdi     # 0xeedd3
leaq 0xe076c(%rip), %rsi     # 0xeede5
movl $0x4dc, %edx            # imm = 0x4DC
leaq 0xe0767(%rip), %rcx     # 0xeedec
callq 0x42e0
jmp 0xe68c
movq -0x28(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0xe898
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jg 0xe7d9
movq -0x10(%rbp), %rdi
callq 0xceb0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0xe723
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movq -0x28(%rbp), %r8
movq -0x20(%rbp), %r9
movl $0x1, %edi
leaq 0xe072f(%rip), %rsi     # 0xeee16
leaq 0xe0732(%rip), %rdx     # 0xeee20
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xe8b0
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0xe778
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xe749
jmp 0xe898
movq -0x10(%rbp), %rdi
callq 0xdd80
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
jmp 0xe68c
cmpl $0x0, -0x38(%rbp)
jge 0xe7d5
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %r8d
movl $0x1, %edi
leaq 0xe067d(%rip), %rsi     # 0xeee16
leaq 0xe06c1(%rip), %rdx     # 0xeee61
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x8, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0xe8b0
jmp 0xe7d7
jmp 0xe7d9
movq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
movslq -0x38(%rbp), %rcx
cmpq %rcx, %rax
jae 0xe7f8
movq -0x20(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0xe800
movslq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rax
addq %rax, %rsi
movslq -0x34(%rbp), %rdx
callq 0x43b0
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movl -0x34(%rbp), %ecx
movq -0x30(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movslq -0x34(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0xe893
movq -0x10(%rbp), %rdi
callq 0xdd80
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
jmp 0xe68c
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)