// File: /workspace/github_cpp_makefile_star2_O3/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 $0xc8, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movq 0x48(%rbx), %r8
movq 0x8(%rdi), %r12
movl (%r8), %r9d
testl %r9d, %r9d
je 0x102ca
movq %r12, %rcx
shrq $0x21, %rcx
movl %r12d, %eax
shll $0xb, %eax
xorl %eax, %ecx
xorl %r12d, %ecx
xorl %r10d, %r10d
movl %ecx, %eax
xorl %edx, %edx
divl %r9d
movl %edx, %esi
leal -0x1(%r9), %r11d
movl %ecx, %eax
xorl %edx, %edx
divl %r11d
incl %edx
movq 0x10(%r8), %r11
movl %esi, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl (%r11,%rcx,4), %ebp
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %ebp, %r14d
shrl %cl, %r14d
testb $0x2, %r14b
jne 0x102be
testb $0x1, %r14b
jne 0x102aa
movq 0x18(%r8), %r14
movl %eax, %r15d
cmpq %r12, (%r14,%r15,8)
je 0x102be
addl %edx, %eax
cmpl %r9d, %eax
movl %r9d, %ecx
cmovbl %r10d, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0x1027c
jmp 0x10327
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %r9d, %eax
jmp 0x102cc
xorl %eax, %eax
cmpl %r9d, %eax
je 0x10327
movl %eax, %eax
leaq (%rax,%rax,2), %r14
shlq $0x3, %r14
addq 0x20(%r8), %r14
cmpl $0x0, 0x30(%rbx)
je 0x102ec
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 0x1cb7b
cmpl $0x0, (%r14)
jne 0x10447
movq 0x8(%rbx), %rdi
movq %rsp, %rsi
movl $0x12, %edx
callq 0x1cabb
cmpl $0x12, %eax
je 0x1034f
testl %eax, %eax
jne 0x1042e
movl $0x0, 0x30(%rbx)
xorl %ebp, %ebp
jmp 0x10447
cmpb $0x1f, (%rsp)
jne 0x10437
cmpb $-0x75, 0x1(%rsp)
jne 0x10437
cmpb $0x8, 0x2(%rsp)
jne 0x10437
testb $0x4, 0x3(%rsp)
je 0x10437
cmpw $0x6, 0xa(%rsp)
jne 0x10437
cmpb $0x42, 0xc(%rsp)
jne 0x10437
cmpb $0x43, 0xd(%rsp)
jne 0x10437
cmpw $0x2, 0xe(%rsp)
jne 0x10437
movzwl 0x10(%rsp), %r13d
movq 0x20(%rbx), %rsi
movw %r13w, 0x10(%rsi)
movapd (%rsp), %xmm0
movupd %xmm0, (%rsi)
leaq -0x11(%r13), %r15
movq 0x8(%rbx), %rdi
addq $0x12, %rsi
movq %r15, %rdx
callq 0x1cabb
movq %rax, %r14
cmpl %r14d, %r15d
jne 0x1042e
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movupd %xmm0, 0x40(%rdi)
movq 0x20(%rbx), %rax
addq $0x12, %rax
movq %rax, (%rdi)
addl $-0xf, %r13d
movl %r13d, 0x8(%rdi)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%rdi)
movl 0x10(%rbx), %eax
movl %eax, 0x20(%rdi)
leaq 0x14dba(%rip), %rdx     # 0x251cc
movl $0xfffffff1, %esi       # imm = 0xFFFFFFF1
movl $0x70, %ecx
callq 0x3210
testl %eax, %eax
je 0x1045b
leaq 0x14da7(%rip), %rax     # 0x251d3
jmp 0x1043e
leaq 0x14ceb(%rip), %rax     # 0x25120
jmp 0x1043e
leaq 0x14cee(%rip), %rax     # 0x2512c
movq %rax, 0x40(%rbx)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x50(%rsp), %r15
movq %r15, %rdi
movl $0x4, %esi
callq 0x3270
movl %eax, %ebp
xorl $0x1, %ebp
movq %r15, %rdi
callq 0x30a0
orl %ebp, %eax
jne 0x1050e
movl 0x78(%rsp), %eax
testl %eax, %eax
js 0x10442
cmpl $0x0, 0x30(%rbx)
je 0x10497
movl $0x0, 0x34(%rbx)
movq %r12, 0x28(%rbx)
movl %eax, 0x30(%rbx)
movl 0x38(%rbx), %ecx
cmpl $0x10001, %ecx          # imm = 0x10001
jl 0x10348
movq 0x48(%rbx), %r13
movl (%r13), %eax
movl 0x4(%r13), %edx
shll $0x10, %edx
addl $0x10000, %edx          # imm = 0x10000
cmpl %ecx, %edx
movq %r14, 0x28(%rsp)
jbe 0x10509
testl %eax, %eax
je 0x1051a
movq 0x10(%r13), %rsi
movl $0x4, %edx
xorl %edi, %edi
xorl %r12d, %r12d
movl %edi, %ebp
andl $0x1e, %ebp
movl $0x3, %r14d
movl %ebp, %ecx
shll %cl, %r14d
movl %r12d, %r15d
shrl $0x4, %r15d
testl %r14d, (%rsi,%r15,4)
je 0x1051f
incl %r12d
addq $0xc, %rdx
addl $0x2, %edi
cmpl %r12d, %eax
jne 0x104dd
movl %eax, %r12d
jmp 0x10554
leaq 0x14cd2(%rip), %rax     # 0x251e7
jmp 0x1043e
xorl %r12d, %r12d
jmp 0x10554
movq 0x20(%r13), %rax
movq (%rax,%rdx,2), %rdi
callq 0x32c0
movl (%r13), %edx
cmpl %r12d, %edx
je 0x10554
movq 0x10(%r13), %rax
movl (%rax,%r15,4), %ecx
movl %edx, %r12d
testl %r14d, %ecx
jne 0x10554
btsl %ebp, %ecx
movl %ecx, (%rax,%r15,4)
decl 0x4(%r13)
movl (%r13), %r12d
movq 0x28(%rbx), %r15
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
jb 0x107fa
movl 0x4(%r13), %eax
leal (%rax,%rax), %edx
xorl %ecx, %ecx
cmpl %r12d, %edx
sbbl %ecx, %ecx
orl $0x1, %ecx
addl %r12d, %ecx
movl $0x21, %esi
leaq 0x14cea(%rip), %rdx     # 0x25270
leal -0x2(%rsi), %edi
decl %esi
cmpl %ecx, (%rdx,%rdi,4)
ja 0x10586
movl %esi, %ecx
movl (%rdx,%rcx,4), %ebp
cvtsi2sd %rbp, %xmm0
mulsd 0x1302e(%rip), %xmm0    # 0x235d0
addsd 0x12f4e(%rip), %xmm0    # 0x234f8
cvttsd2si %xmm0, %rcx
cmpl %ecx, %eax
jae 0x107fa
movq %rcx, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movl %ebp, %eax
shrl $0x4, %eax
leaq 0x4(,%rax,4), %r14
movq %r14, %rdi
callq 0x31d0
movq %rax, %r15
movq %rax, %rdi
movl $0xaa, %esi
movq %r14, %rdx
callq 0x3060
cmpl %ebp, %r12d
jae 0x1061b
movq 0x18(%r13), %rdi
leaq (,%rbp,8), %r12
movq %r12, %rsi
callq 0x3610
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rdi
leaq (%r12,%r12,2), %rsi
callq 0x3610
movq %rax, 0x20(%r13)
movl (%r13), %r12d
testl %r12d, %r12d
je 0x107d1
leal -0x1(%rbp), %edi
xorl %r8d, %r8d
movq 0x10(%r13), %r9
movl %r8d, %eax
shrl $0x4, %eax
movl (%r9,%rax,4), %edx
leal (%r8,%r8), %ecx
andl $0x1e, %ecx
movl %edx, %esi
shrl %cl, %esi
testb $0x3, %sil
jne 0x10797
movq 0x18(%r13), %rsi
movl %r8d, %r11d
movq (%rsi,%r11,8), %r10
movq 0x20(%r13), %rsi
leaq (%r11,%r11,2), %r11
movq 0x10(%rsi,%r11,8), %r14
movq %r14, 0x60(%rsp)
movupd (%rsi,%r11,8), %xmm0
movapd %xmm0, 0x50(%rsp)
btsl %ecx, %edx
movl %edx, (%r9,%rax,4)
movq %r10, %rcx
shrq $0x21, %rcx
movl %r10d, %eax
shll $0xb, %eax
xorl %eax, %ecx
xorl %r10d, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %ebp
movl %edx, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %edi
movl %esi, %eax
movl %esi, %ecx
addl %esi, %ecx
andl $0x1e, %ecx
movl $0x2, %r12d
shll %cl, %r12d
shrl $0x4, %eax
movl (%r15,%rax,4), %r11d
testl %r11d, %r12d
jne 0x106e6
incl %edx
addl %edx, %esi
xorl %eax, %eax
cmpl %ebp, %esi
jb 0x106c7
movl %ebp, %eax
subl %eax, %esi
movl %esi, %eax
shrl $0x4, %eax
movl (%r15,%rax,4), %r11d
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl $0x2, %r12d
shll %cl, %r12d
testl %r11d, %r12d
je 0x106bd
notl %r12d
andl %r11d, %r12d
movl %r12d, (%r15,%rax,4)
cmpl (%r13), %esi
jae 0x1076c
movl (%r9,%rax,4), %r9d
shrl %cl, %r9d
movq 0x18(%r13), %rdx
testb $0x3, %r9b
jne 0x10770
movl %esi, %esi
movq (%rdx,%rsi,8), %r11
movq %r10, (%rdx,%rsi,8)
movq 0x20(%r13), %rdx
leaq (%rsi,%rsi,2), %rsi
movq 0x10(%rdx,%rsi,8), %r9
movq %r9, 0x40(%rsp)
movups (%rdx,%rsi,8), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x60(%rsp), %r9
movq %r9, 0x10(%rdx,%rsi,8)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rdx,%rsi,8)
movq 0x40(%rsp), %rdx
movq %rdx, 0x60(%rsp)
movapd 0x30(%rsp), %xmm0
movapd %xmm0, 0x50(%rsp)
movl $0x1, %edx
shll %cl, %edx
movq 0x10(%r13), %r9
orl %edx, (%r9,%rax,4)
movq %r11, %r10
jmp 0x1067d
movq 0x18(%r13), %rdx
movl %esi, %eax
movq %r10, (%rdx,%rax,8)
movq 0x20(%r13), %rcx
leaq (%rax,%rax,2), %rax
movq 0x60(%rsp), %rdx
movq %rdx, 0x10(%rcx,%rax,8)
movapd 0x50(%rsp), %xmm0
movupd %xmm0, (%rcx,%rax,8)
movl (%r13), %r12d
incl %r8d
cmpl %r12d, %r8d
jne 0x1062a
cmpl %ebp, %r12d
jbe 0x107d1
movq 0x18(%r13), %rdi
leaq (,%rbp,8), %r12
movq %r12, %rsi
callq 0x3610
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rdi
leaq (%r12,%r12,2), %rsi
callq 0x3610
movq %rax, 0x20(%r13)
movq 0x10(%r13), %rdi
callq 0x32c0
movq %r15, 0x10(%r13)
movl %ebp, (%r13)
movl 0x4(%r13), %eax
movl %eax, 0x8(%r13)
movq 0x18(%rsp), %rax
movl %eax, 0xc(%r13)
movq 0x20(%rsp), %r15
jmp 0x107fd
movl %r12d, %ebp
movq %r15, %rdi
shrq $0x21, %rdi
movl %r15d, %eax
shll $0xb, %eax
xorl %eax, %edi
xorl %r15d, %edi
xorl %r9d, %r9d
movl %edi, %eax
xorl %edx, %edx
divl %ebp
movl %edx, %esi
movq 0x10(%r13), %r8
movl %edx, %eax
shrl $0x4, %eax
movl (%r8,%rax,4), %eax
leal (%rsi,%rsi), %ecx
shrl %cl, %eax
testb $0x2, %al
je 0x10834
movl %esi, %eax
jmp 0x108ac
leal -0x1(%rbp), %ecx
movl %edi, %eax
xorl %edx, %edx
divl %ecx
incl %edx
movl %esi, %edi
movl %ebp, %eax
movl %edi, %ecx
shrl $0x4, %ecx
movl (%r8,%rcx,4), %r10d
leal (%rdi,%rdi), %ecx
andl $0x1e, %ecx
movl %r10d, %r11d
shrl %cl, %r11d
testb $0x2, %r11b
jne 0x10892
testb $0x1, %r11b
jne 0x10871
movq 0x18(%r13), %r11
movl %edi, %r14d
cmpq %r15, (%r11,%r14,8)
je 0x10892
btl %ecx, %r10d
cmovbl %edi, %eax
addl %edx, %edi
cmpl %ebp, %edi
movl %ebp, %ecx
cmovbl %r9d, %ecx
subl %ecx, %edi
cmpl %esi, %edi
jne 0x10843
movb $0x1, %cl
movl %ebp, %edx
cmpl %ebp, %eax
je 0x108a0
jmp 0x108ac
shrl %cl, %r10d
testb $0x2, %r10b
sete %cl
movl %eax, %edx
movl %edi, %esi
cmpl %ebp, %edx
cmovel %esi, %edx
testb %cl, %cl
cmovnel %esi, %edx
movl %edx, %eax
movl %eax, %edx
shrl $0x4, %edx
movl (%r8,%rdx,4), %esi
leal (%rax,%rax), %ecx
andl $0x1e, %ecx
movl %esi, %edi
shrl %cl, %edi
testb $0x2, %dil
jne 0x108f2
testb $0x1, %dil
je 0x10348
movq 0x18(%r13), %rdi
movl $0x3, %r9d
shll %cl, %r9d
movl %eax, %eax
movq %r15, (%rdi,%rax,8)
notl %r9d
andl %r9d, %esi
movl %esi, (%r8,%rdx,4)
incl 0x4(%r13)
jmp 0x10923
movq 0x18(%r13), %rdi
movl %eax, %eax
movl $0x3, %r9d
shll %cl, %r9d
movq %r15, (%rdi,%rax,8)
notl %r9d
andl %r9d, %esi
movl %esi, (%r8,%rdx,4)
movq 0x4(%r13), %xmm0
pcmpeqd %xmm1, %xmm1
psubd %xmm1, %xmm0
movq %xmm0, 0x4(%r13)
movq 0x20(%r13), %r14
leaq (%rax,%rax,2), %r15
movl 0x30(%rbx), %eax
movl %eax, (%r14,%r15,8)
movq 0x28(%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 0x10348