// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0x17bc0
movq %rax, %r15
movq 0x50(%rbx), %rdi
movl (%rdi), %r8d
testl %r8d, %r8d
je 0x33eb13
movq %r15, %rcx
shrq $0x21, %rcx
movl %r15d, %eax
shll $0xb, %eax
xorl %eax, %ecx
xorl %r15d, %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 0x33eb06
testb $0x1, %bpl
jne 0x33eaef
movq 0x18(%rdi), %r14
movl %eax, %r12d
cmpq %r15, (%r14,%r12,8)
je 0x33eb06
addl %edx, %eax
cmpl %r8d, %eax
movl %r8d, %ecx
cmovbl %r9d, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0x33eac2
movl %r8d, %eax
jmp 0x33eb15
shrl %cl, %r11d
testb $0x3, %r11b
cmovnel %r8d, %eax
jmp 0x33eb15
xorl %eax, %eax
cmpl %r8d, %eax
je 0x33eb6c
movl %eax, %eax
leaq (%rax,%rax,2), %r14
shlq $0x3, %r14
addq 0x20(%rdi), %r14
cmpl $0x0, 0x38(%rbx)
je 0x33eb35
movl $0x0, 0x3c(%rbx)
movq %r15, 0x30(%rbx)
movl (%r14), %eax
movl %eax, 0x38(%rbx)
movq 0x20(%rbx), %rdi
movq 0x8(%r14), %rsi
movl $0x10000, %edx          # imm = 0x10000
callq 0x17660
movq 0x10(%rbx), %rdi
movq 0x10(%r14), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x17cf0
cmpl $0x0, (%r14)
jne 0x33ec83
movq 0x10(%rbx), %rcx
movq %rsp, %rdi
movl $0x1, %esi
movl $0x12, %edx
callq 0x17b40
testl %eax, %eax
je 0x33ebb6
cmpl $0x12, %eax
jne 0x33ec73
cmpb $0x1f, (%rsp)
jne 0x33ebaa
cmpb $-0x75, 0x1(%rsp)
jne 0x33ebaa
cmpb $0x8, 0x2(%rsp)
jne 0x33ebaa
testb $0x4, 0x3(%rsp)
jne 0x33ebc4
leaq 0xb200a(%rip), %rax     # 0x3f0bbb
jmp 0x33ec7a
movl $0x0, 0x38(%rbx)
xorl %ebp, %ebp
jmp 0x33ec83
cmpw $0x6, 0xa(%rsp)
jne 0x33ebaa
cmpb $0x42, 0xc(%rsp)
jne 0x33ebaa
cmpb $0x43, 0xd(%rsp)
jne 0x33ebaa
cmpw $0x2, 0xe(%rsp)
jne 0x33ebaa
movzwl 0x10(%rsp), %r14d
movq 0x28(%rbx), %rdi
movzwl 0x10(%rsp), %eax
movw %ax, 0x10(%rdi)
movdqa (%rsp), %xmm0
movdqu %xmm0, (%rdi)
leaq -0x11(%r14), %r12
addq $0x12, %rdi
movq 0x10(%rbx), %rcx
movl $0x1, %esi
movq %r12, %rdx
callq 0x17b40
cmpl %eax, %r12d
jne 0x33ec73
movq %rax, 0x20(%rsp)
pxor %xmm0, %xmm0
leaq 0x28(%rsp), %rdi
movdqu %xmm0, 0x40(%rdi)
movq 0x28(%rbx), %rax
addq $0x12, %rax
movq %rax, (%rdi)
addl $-0xf, %r14d
movl %r14d, 0x8(%rdi)
movq 0x20(%rbx), %rax
movq %rax, 0x18(%rdi)
movl 0x18(%rbx), %eax
movl %eax, 0x20(%rdi)
leaq 0x992bd(%rip), %rdx     # 0x3d7f14
movl $0xfffffff1, %esi       # imm = 0xFFFFFFF1
movl $0x70, %ecx
callq 0x278da6
testl %eax, %eax
je 0x33ec97
leaq 0xb1fea(%rip), %rax     # 0x3f0c5b
jmp 0x33ecc7
leaq 0xb1f35(%rip), %rax     # 0x3f0baf
movq %rax, 0x48(%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), %r12
movq %r12, %rdi
movl $0x4, %esi
callq 0x278efe
movl %eax, %ebp
movq %r12, %rdi
callq 0x27a8f6
cmpl $0x1, %ebp
jne 0x33ecc0
testl %eax, %eax
je 0x33ed61
leaq 0xb1fa8(%rip), %rax     # 0x3f0c6f
movq %rax, 0x48(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x33ec7e
cmpl $0x0, 0x38(%rbx)
je 0x33ece1
movl $0x0, 0x3c(%rbx)
movq %r15, 0x30(%rbx)
movl %eax, 0x38(%rbx)
movl 0x40(%rbx), %eax
cmpl $0x10001, %eax          # imm = 0x10001
jl 0x33ebbd
movq 0x50(%rbx), %r15
movl 0x4(%r15), %ecx
shll $0x10, %ecx
addl $0x10000, %ecx          # imm = 0x10000
cmpl %eax, %ecx
jbe 0x33edb0
movl (%r15), %eax
testl %eax, %eax
je 0x33edb0
movq 0x10(%r15), %rdx
testb $0x3, (%rdx)
je 0x33ed6a
movl $0x1, %r12d
movl $0x2, %esi
cmpl %r12d, %eax
je 0x33edb0
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 0x33ed2e
decl %r12d
cmpl %eax, %r12d
setb %al
jmp 0x33ed7a
movl 0x50(%rsp), %eax
jmp 0x33ecd0
movl $0x3, %r14d
xorl %r12d, %r12d
movb $0x1, %al
xorl %r13d, %r13d
xorl %ebp, %ebp
testb %al, %al
je 0x33edb0
movq 0x20(%r15), %rax
movl %r12d, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x17fe8
cmpl %r12d, (%r15)
je 0x33edb0
movq 0x10(%r15), %rax
movl (%rax,%r13,4), %ecx
testl %r14d, %ecx
jne 0x33edb0
btsl %ebp, %ecx
movl %ecx, (%rax,%r13,4)
decl 0x4(%r15)
movq 0x30(%rbx), %r12
movl 0x8(%r15), %eax
cmpl 0xc(%r15), %eax
jb 0x33edda
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 0x33f4b4
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 0x33ee96
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 0x33ee70
testb $0x1, %bpl
jne 0x33ee53
movq 0x18(%r15), %r14
movl %edi, %r13d
cmpq %r12, (%r14,%r13,8)
je 0x33ee70
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 0x33ee26
jmp 0x33ee73
movl %r9d, %ecx
movl %ecx, %esi
cmpl %r9d, %ecx
jne 0x33ee96
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), %edi
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %edi, %r9d
shrl %cl, %r9d
movl %esi, %edx
testb $0x2, %r9b
jne 0x33eeda
testb $0x1, %r9b
je 0x33ebbd
movl $0x3, %esi
shll %cl, %esi
movq 0x18(%r15), %rcx
movq %r12, (%rcx,%rdx,8)
notl %esi
andl %esi, %edi
movl %edi, (%r8,%rax,4)
incl 0x4(%r15)
jmp 0x33ef09
movq 0x18(%r15), %rsi
movl $0x3, %r9d
shll %cl, %r9d
movq %r12, (%rsi,%rdx,8)
notl %r9d
andl %r9d, %edi
movl %edi, (%r8,%rax,4)
movq 0x4(%r15), %xmm0
pcmpeqd %xmm1, %xmm1
psubd %xmm1, %xmm0
movq %xmm0, 0x4(%r15)
movq 0x20(%r15), %r14
leaq (%rdx,%rdx,2), %r15
movl 0x38(%rbx), %eax
movl %eax, (%r14,%r15,8)
movq 0x20(%rsp), %rax
addl $0x12, %eax
cltq
addq 0x30(%rbx), %rax
movq %rax, 0x10(%r14,%r15,8)
movl $0x10000, %edi          # imm = 0x10000
callq 0x17ff0
movq %rax, 0x8(%r14,%r15,8)
movq 0x20(%rbx), %rsi
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
callq 0x17660
jmp 0x33ebbd