// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/bgzf.c
// Function: bgzf_read_block
int
bgzf_read_block(BGZF* fp)
{
    bgzf_byte_t header[BLOCK_HEADER_LENGTH];
	int count, size = 0, block_length, remaining;
#ifdef _USE_KNETFILE
    int64_t block_address = knet_tell(fp->x.fpr);
	if (load_block_from_cache(fp, block_address)) return 0;
    count = knet_read(fp->x.fpr, header, sizeof(header));
#else
    int64_t block_address = ftello(fp->file);
	if (load_block_from_cache(fp, block_address)) return 0;
    count = fread(header, 1, sizeof(header), fp->file);
#endif
    if (count == 0) {
        fp->block_length = 0;
        return 0;
    }
	size = count;
    if (count != sizeof(header)) {
        report_error(fp, "read failed");
        return -1;
    }
    if (!check_header(header)) {
        report_error(fp, "invalid block header");
        return -1;
    }
    block_length = unpackInt16((uint8_t*)&header[16]) + 1;
    bgzf_byte_t* compressed_block = (bgzf_byte_t*) fp->compressed_block;
    memcpy(compressed_block, header, BLOCK_HEADER_LENGTH);
    remaining = block_length - BLOCK_HEADER_LENGTH;
#ifdef _USE_KNETFILE
    count = knet_read(fp->x.fpr, &compressed_block[BLOCK_HEADER_LENGTH], remaining);
#else
    count = fread(&compressed_block[BLOCK_HEADER_LENGTH], 1, remaining, fp->file);
#endif
    if (count != remaining) {
        report_error(fp, "read failed");
        return -1;
    }
	size += count;
    count = inflate_block(fp, block_length);
    if (count < 0) return -1;
    if (fp->block_length != 0) {
        // Do not reset offset if this read follows a seek.
        fp->block_offset = 0;
    }
    fp->block_address = block_address;
    fp->block_length = count;
	cache_block(fp, size);
    return 0;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsp, %rax
movq %rax, 0x40(%rsp)
movl $0x0, 0x38(%rsp)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x19af0
movq %rax, 0x28(%rsp)
movq 0x48(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x4f7200
cmpl $0x0, %eax
je 0x4f7015
movl $0x0, 0x54(%rsp)
movl $0x1, 0x24(%rsp)
jmp 0x4f71ed
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rcx
movq %rsp, %rdi
movl $0x1, %esi
movl $0x12, %edx
callq 0x19a70
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jne 0x4f705c
movq 0x48(%rsp), %rax
movl $0x0, 0x38(%rax)
movl $0x0, 0x54(%rsp)
movl $0x1, 0x24(%rsp)
jmp 0x4f71ed
movl 0x3c(%rsp), %eax
movl %eax, 0x38(%rsp)
movslq 0x3c(%rsp), %rax
cmpq $0x12, %rax
je 0x4f7095
movq 0x48(%rsp), %rdi
leaq 0xc5c44(%rip), %rsi     # 0x5bccbf
callq 0x4f72e0
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x24(%rsp)
jmp 0x4f71ed
movq %rsp, %rdi
callq 0x4f7300
cmpl $0x0, %eax
jne 0x4f70c8
movq 0x48(%rsp), %rdi
leaq 0xc5c1d(%rip), %rsi     # 0x5bcccb
callq 0x4f72e0
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x24(%rsp)
jmp 0x4f71ed
movq %rsp, %rdi
addq $0x10, %rdi
callq 0x4f73d0
addl $0x1, %eax
movl %eax, 0x34(%rsp)
movq 0x48(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, (%rax)
movq 0x8(%rsp), %rcx
movq %rcx, 0x8(%rax)
movw 0x10(%rsp), %cx
movw %cx, 0x10(%rax)
movl 0x34(%rsp), %eax
subl $0x12, %eax
movl %eax, 0x30(%rsp)
movq 0x18(%rsp), %rdi
addq $0x12, %rdi
movslq 0x30(%rsp), %rdx
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rcx
movl $0x1, %esi
callq 0x19a70
movl %eax, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x30(%rsp), %eax
je 0x4f7167
movq 0x48(%rsp), %rdi
leaq 0xc5b72(%rip), %rsi     # 0x5bccbf
callq 0x4f72e0
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x24(%rsp)
jmp 0x4f71ed
movl 0x3c(%rsp), %eax
addl 0x38(%rsp), %eax
movl %eax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x4f73f0
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jge 0x4f719e
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
movl $0x1, 0x24(%rsp)
jmp 0x4f71ed
movq 0x48(%rsp), %rax
cmpl $0x0, 0x38(%rax)
je 0x4f71b5
movq 0x48(%rsp), %rax
movl $0x0, 0x3c(%rax)
movq 0x28(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x30(%rax)
movl 0x3c(%rsp), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x38(%rax)
movq 0x48(%rsp), %rdi
movl 0x38(%rsp), %esi
callq 0x4f7540
movl $0x0, 0x54(%rsp)
movl $0x1, 0x24(%rsp)
movq 0x40(%rsp), %rax
movq %rax, %rsp
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nop