// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bgzf.c
// Function: bgzf_read_block
int bgzf_read_block(BGZF *fp)
{
	uint8_t header[BLOCK_HEADER_LENGTH], *compressed_block;
	int count, size = 0, block_length, remaining;
	int64_t block_address;
	block_address = _bgzf_tell((_bgzf_file_t)fp->fp);
	if (fp->cache_size && load_block_from_cache(fp, block_address)) return 0;
	count = _bgzf_read(fp->fp, header, sizeof(header));
	if (count == 0) { // no data read
		fp->block_length = 0;
		return 0;
	}
	if (count != sizeof(header) || !check_header(header)) {
		fp->errcode |= BGZF_ERR_HEADER;
		return -1;
	}
	size = count;
	block_length = unpackInt16((uint8_t*)&header[16]) + 1; // +1 because when writing this number, we used "-1"
	compressed_block = (uint8_t*)fp->compressed_block;
	memcpy(compressed_block, header, BLOCK_HEADER_LENGTH);
	remaining = block_length - BLOCK_HEADER_LENGTH;
	count = _bgzf_read(fp->fp, &compressed_block[BLOCK_HEADER_LENGTH], remaining);
	if (count != remaining) {
		fp->errcode |= BGZF_ERR_IO;
		return -1;
	}
	size += count;
	if ((count = inflate_block(fp, block_length)) < 0) return -1;
	if (fp->block_length != 0) fp->block_offset = 0; // Do not reset offset if this read follows a seek.
	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 0x30(%rdi), %rax
movq 0x8(%rax), %r12
cmpl $0x0, 0x4(%rdi)
je 0x17541
movq 0x28(%rbx), %rdi
movl (%rdi), %r8d
testl %r8d, %r8d
je 0x174ec
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 0x174df
testb $0x1, %bpl
jne 0x174c8
movq 0x18(%rdi), %r14
movl %eax, %r15d
cmpq %r12, (%r14,%r15,8)
je 0x174df
addl %edx, %eax
cmpl %r8d, %eax
movl %r8d, %ecx
cmovbl %r9d, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0x1749b
movl %r8d, %eax
jmp 0x174ee
shrl %cl, %r11d
testb $0x3, %r11b
cmovnel %r8d, %eax
jmp 0x174ee
xorl %eax, %eax
cmpl %r8d, %eax
je 0x17541
movl %eax, %eax
leaq (%rax,%rax,2), %r14
shlq $0x3, %r14
addq 0x20(%rdi), %r14
cmpl $0x0, 0x8(%rbx)
je 0x1750e
movl $0x0, 0xc(%rbx)
movq %r12, 0x10(%rbx)
movl (%r14), %eax
movl %eax, 0x8(%rbx)
movq 0x18(%rbx), %rdi
movq 0x8(%r14), %rsi
movl $0x10000, %edx          # imm = 0x10000
callq 0x3370
movq 0x30(%rbx), %rdi
movq 0x10(%r14), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x158e6
cmpl $0x0, (%r14)
jne 0x17589
movq 0x30(%rbx), %rdi
movq %rsp, %rsi
movl $0x12, %edx
callq 0x1582a
testl %eax, %eax
je 0x17580
cmpl $0x12, %eax
jne 0x17576
cmpb $0x1f, (%rsp)
jne 0x17576
cmpb $-0x75, 0x1(%rsp)
jne 0x17576
cmpb $0x8, 0x2(%rsp)
jne 0x17576
testb $0x4, 0x3(%rsp)
jne 0x1759d
orb $0x2, (%rbx)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x17589
movl $0x0, 0x8(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpw $0x6, 0xa(%rsp)
jne 0x17576
cmpb $0x42, 0xc(%rsp)
jne 0x17576
cmpb $0x43, 0xd(%rsp)
jne 0x17576
cmpw $0x2, 0xe(%rsp)
jne 0x17576
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 0x30(%rbx), %rdi
addq $0x12, %rsi
movq %r15, %rdx
callq 0x1582a
cmpl %eax, %r15d
jne 0x17709
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 $0x10000, 0x20(%rdi)    # imm = 0x10000
leaq 0x4153(%rip), %rdx      # 0x1b77f
movl $0xfffffff1, %esi       # imm = 0xFFFFFFF1
movl $0x70, %ecx
callq 0x34c0
testl %eax, %eax
jne 0x17668
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movl $0x4, %esi
callq 0x30e0
movl %eax, %ebp
movq %r15, %rdi
callq 0x3380
cmpl $0x1, %ebp
jne 0x17668
testl %eax, %eax
je 0x17711
orb $0x1, (%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x17579
cmpl $0x0, 0x8(%rbx)
je 0x17685
movl $0x0, 0xc(%rbx)
movq %r12, 0x10(%rbx)
movl %eax, 0x8(%rbx)
movl 0x4(%rbx), %eax
cmpl $0x10001, %eax          # imm = 0x10001
jl 0x17587
movq 0x28(%rbx), %r15
movl 0x4(%r15), %ecx
shll $0x10, %ecx
addl $0x10000, %ecx          # imm = 0x10000
cmpl %eax, %ecx
jbe 0x17760
movl (%r15), %eax
testl %eax, %eax
je 0x17760
movq 0x10(%r15), %rdx
testb $0x3, (%rdx)
je 0x1771a
movl $0x1, %r12d
movl $0x2, %esi
cmpl %r12d, %eax
je 0x17760
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 0x176d2
decl %r12d
cmpl %eax, %r12d
setb %al
jmp 0x1772a
orb $0x4, (%rbx)
jmp 0x17579
movl 0x50(%rsp), %eax
jmp 0x17670
movl $0x3, %r14d
xorl %r12d, %r12d
movb $0x1, %al
xorl %r13d, %r13d
xorl %ebp, %ebp
testb %al, %al
je 0x17760
movq 0x20(%r15), %rax
movl %r12d, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdi
callq 0x3060
cmpl %r12d, (%r15)
je 0x17760
movq 0x10(%r15), %rax
movl (%rax,%r13,4), %ecx
testl %r14d, %ecx
jne 0x17760
btsl %ebp, %ecx
movl %ecx, (%rax,%r13,4)
decl 0x4(%r15)
movq 0x10(%rbx), %r12
movl 0x8(%r15), %eax
cmpl 0xc(%r15), %eax
jb 0x1778a
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 0x1844c
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 0x17846
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 0x17820
testb $0x1, %bpl
jne 0x17803
movq 0x18(%r15), %r14
movl %edi, %r13d
cmpq %r12, (%r14,%r13,8)
je 0x17820
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 0x177d6
jmp 0x17823
movl %r9d, %ecx
movl %ecx, %esi
cmpl %r9d, %ecx
jne 0x17846
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 0x17888
testb $0x1, %dil
je 0x17587
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 0x178a7
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 0x8(%rbx), %eax
movl %eax, (%r14,%r15,8)
movq 0x20(%rsp), %rax
addl $0x12, %eax
cltq
addq 0x10(%rbx), %rax
movq %rax, 0x10(%r14,%r15,8)
movl $0x10000, %edi          # imm = 0x10000
callq 0x33e0
movq %rax, 0x8(%r14,%r15,8)
movq 0x18(%rbx), %rsi
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
callq 0x3370
jmp 0x17587