// File: /workspace/github_cpp_makefile_star2_O1/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bgzf.c
// Function: bgzf_read_block
int
bgzf_read_block(BGZF* fp)
{
    bgzf_byte_t header[BLOCK_HEADER_LENGTH];
	int count, size = 0;
#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;
    }
    int 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);
    int 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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movq 0x48(%rdi), %rdi
movq 0x8(%rax), %r12
movl (%rdi), %r8d
testl %r8d, %r8d
je 0xfc9b
movq %r12, %rcx
shrq $0x21, %rcx
movl %r12d, %eax
shll $0xb, %eax
xorl %eax, %ecx
xorl %r12d, %ecx
xorl %r9d, %r9d
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
movl %edx, %esi
leal -0x1(%r8), %r10d
movl %ecx, %eax
xorl %edx, %edx
divl %r10d
incl %edx
movq 0x10(%rdi), %r10
movl %esi, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl (%r10,%rcx,4), %r11d
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %r11d, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0xfc8e
testb $0x1, %bpl
jne 0xfc77
movq 0x18(%rdi), %r14
movl %eax, %r15d
cmpq %r12, (%r14,%r15,8)
je 0xfc8e
addl %edx, %eax
cmpl %r8d, %eax
movl %r8d, %ecx
cmovbl %r9d, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0xfc4a
movl %r8d, %eax
jmp 0xfc9d
shrl %cl, %r11d
testb $0x3, %r11b
cmovnel %r8d, %eax
jmp 0xfc9d
xorl %eax, %eax
cmpl %r8d, %eax
je 0xfcf4
movl %eax, %eax
leaq (%rax,%rax,2), %r14
shlq $0x3, %r14
addq 0x20(%rdi), %r14
cmpl $0x0, 0x30(%rbx)
je 0xfcbd
movl $0x0, 0x34(%rbx)
movq %r12, 0x28(%rbx)
movl (%r14), %eax
movl %eax, 0x30(%rbx)
movq 0x18(%rbx), %rdi
movq 0x8(%r14), %rsi
movl $0x10000, %edx          # imm = 0x10000
callq 0x3680
movq 0x8(%rbx), %rdi
movq 0x10(%r14), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x1c579
cmpl $0x0, (%r14)
jne 0xfdfd
movq 0x8(%rbx), %rdi
movq %rsp, %rsi
movl $0x12, %edx
callq 0x1c4bd
testl %eax, %eax
je 0xfd39
cmpl $0x12, %eax
jne 0xfded
cmpb $0x1f, (%rsp)
jne 0xfd2d
cmpb $-0x75, 0x1(%rsp)
jne 0xfd2d
cmpb $0x8, 0x2(%rsp)
jne 0xfd2d
testb $0x4, 0x3(%rsp)
jne 0xfd47
leaq 0x163a8(%rip), %rax     # 0x260dc
jmp 0xfdf4
movl $0x0, 0x30(%rbx)
xorl %ebp, %ebp
jmp 0xfdfd
cmpw $0x6, 0xa(%rsp)
jne 0xfd2d
cmpb $0x42, 0xc(%rsp)
jne 0xfd2d
cmpb $0x43, 0xd(%rsp)
jne 0xfd2d
cmpw $0x2, 0xe(%rsp)
jne 0xfd2d
movzwl 0x10(%rsp), %r14d
movq 0x20(%rbx), %rsi
movzwl 0x10(%rsp), %eax
movw %ax, 0x10(%rsi)
movaps (%rsp), %xmm0
movups %xmm0, (%rsi)
leaq -0x11(%r14), %r15
movq 0x8(%rbx), %rdi
addq $0x12, %rsi
movq %r15, %rdx
callq 0x1c4bd
cmpl %eax, %r15d
jne 0xfded
movq %rax, 0x20(%rsp)
xorps %xmm0, %xmm0
leaq 0x28(%rsp), %rdi
movups %xmm0, 0x40(%rdi)
movq 0x20(%rbx), %rax
addq $0x12, %rax
movq %rax, (%rdi)
addl $-0xf, %r14d
movl %r14d, 0x8(%rdi)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%rdi)
movl 0x10(%rbx), %eax
movl %eax, 0x20(%rdi)
leaq 0x163ab(%rip), %rdx     # 0x2617c
movl $0xfffffff1, %esi       # imm = 0xFFFFFFF1
movl $0x70, %ecx
callq 0x3210
testl %eax, %eax
je 0xfe11
leaq 0x16398(%rip), %rax     # 0x26183
jmp 0xfe41
leaq 0x162dc(%rip), %rax     # 0x260d0
movq %rax, 0x40(%rbx)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movl $0x4, %esi
callq 0x3270
movl %eax, %ebp
movq %r15, %rdi
callq 0x30a0
cmpl $0x1, %ebp
jne 0xfe3a
testl %eax, %eax
je 0xfedb
leaq 0x16356(%rip), %rax     # 0x26197
movq %rax, 0x40(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0xfdf8
cmpl $0x0, 0x30(%rbx)
je 0xfe5b
movl $0x0, 0x34(%rbx)
movq %r12, 0x28(%rbx)
movl %eax, 0x30(%rbx)
movl 0x38(%rbx), %eax
cmpl $0x10001, %eax          # imm = 0x10001
jl 0xfd40
movq 0x48(%rbx), %r15
movl 0x4(%r15), %ecx
shll $0x10, %ecx
addl $0x10000, %ecx          # imm = 0x10000
cmpl %eax, %ecx
jbe 0xff2a
movl (%r15), %eax
testl %eax, %eax
je 0xff2a
movq 0x10(%r15), %rdx
testb $0x3, (%rdx)
je 0xfee4
movl $0x1, %r12d
movl $0x2, %esi
cmpl %r12d, %eax
je 0xff2a
movl %r12d, %r13d
shrl $0x4, %r13d
movl %esi, %ebp
andl $0x1e, %ebp
movl $0x3, %r14d
movl %ebp, %ecx
shll %cl, %r14d
incl %r12d
addl $0x2, %esi
testl %r14d, (%rdx,%r13,4)
jne 0xfea8
decl %r12d
cmpl %eax, %r12d
setb %al
jmp 0xfef4
movl 0x50(%rsp), %eax
jmp 0xfe4a
movl $0x3, %r14d
xorl %r12d, %r12d
movb $0x1, %al
xorl %r13d, %r13d
xorl %ebp, %ebp
testb %al, %al
je 0xff2a
movq 0x20(%r15), %rax
movl %r12d, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x32c0
cmpl %r12d, (%r15)
je 0xff2a
movq 0x10(%r15), %rax
movl (%rax,%r13,4), %ecx
testl %r14d, %ecx
jne 0xff2a
btsl %ebp, %ecx
movl %ecx, (%rax,%r13,4)
decl 0x4(%r15)
movq 0x28(%rbx), %r12
movl 0x8(%r15), %eax
cmpl 0xc(%r15), %eax
jb 0xff54
movl (%r15), %eax
movl 0x4(%r15), %ecx
addl %ecx, %ecx
xorl %esi, %esi
cmpl %eax, %ecx
sbbl %esi, %esi
orl $0x1, %esi
addl %eax, %esi
movq %r15, %rdi
callq 0x107a9
movl (%r15), %r9d
movq %r12, %rdi
shrq $0x21, %rdi
movl %r12d, %eax
shll $0xb, %eax
xorl %eax, %edi
xorl %r12d, %edi
xorl %r10d, %r10d
movl %edi, %eax
xorl %edx, %edx
divl %r9d
movl %edx, %esi
movq 0x10(%r15), %r8
movl %edx, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %eax
leal (%rsi,%rsi), %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x10010
leal -0x1(%r9), %ecx
movl %edi, %eax
xorl %edx, %edx
divl %ecx
incl %edx
movl %esi, %edi
movl %r9d, %eax
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r8,%rcx,4), %r11d
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %r11d, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0xffea
testb $0x1, %bpl
jne 0xffcd
movq 0x18(%r15), %r14
movl %edi, %r13d
cmpq %r12, (%r14,%r13,8)
je 0xffea
btl %ecx, %r11d
cmovbl %edi, %eax
addl %edx, %edi
cmpl %r9d, %edi
movl %r9d, %ecx
cmovbl %r10d, %ecx
subl %ecx, %edi
movl %eax, %ecx
cmpl %esi, %edi
jne 0xffa0
jmp 0xffed
movl %r9d, %ecx
movl %ecx, %esi
cmpl %r9d, %ecx
jne 0x10010
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r8,%rcx,4), %edx
leal (%rdi,%rdi), %ecx
shrl %cl, %edx
cmpl %r9d, %eax
cmovel %edi, %eax
testb $0x2, %dl
cmovel %edi, %eax
movl %eax, %esi
movl %esi, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %edx
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %edx, %edi
shrl %cl, %edi
movl %esi, %esi
testb $0x2, %dil
jne 0x10052
testb $0x1, %dil
je 0xfd40
movl $0x3, %edi
shll %cl, %edi
movq 0x18(%r15), %rcx
movq %r12, (%rcx,%rsi,8)
notl %edi
andl %edi, %edx
movl %edx, (%r8,%rax,4)
incl 0x4(%r15)
jmp 0x10071
movl $0x3, %edi
shll %cl, %edi
movq 0x18(%r15), %rcx
movq %r12, (%rcx,%rsi,8)
notl %edi
andl %edi, %edx
movl %edx, (%r8,%rax,4)
incl 0x4(%r15)
incl 0x8(%r15)
movq 0x20(%r15), %r14
leaq (%rsi,%rsi,2), %r15
movl 0x30(%rbx), %eax
movl %eax, (%r14,%r15,8)
movq 0x20(%rsp), %rax
addl $0x12, %eax
cltq
addq 0x28(%rbx), %rax
movq %rax, 0x10(%r14,%r15,8)
movl $0x10000, %edi          # imm = 0x10000
callq 0x31d0
movq %rax, 0x8(%r14,%r15,8)
movq 0x18(%rbx), %rsi
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
callq 0x3680
jmp 0xfd40