// File: /workspace/github_c_makefile_star2_O2/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 $0xd8, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0x17b50
movq %rax, %r15
movq 0x50(%rbx), %rdi
movl (%rdi), %r8d
testl %r8d, %r8d
je 0x2d62ba
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 0x2d62ad
testb $0x1, %bpl
jne 0x2d6299
movq 0x18(%rdi), %r14
movl %eax, %r12d
cmpq %r15, (%r14,%r12,8)
je 0x2d62ad
addl %edx, %eax
cmpl %r8d, %eax
movl %r8d, %ecx
cmovbl %r9d, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0x2d626c
jmp 0x2d630c
shrl %cl, %r11d
testb $0x3, %r11b
cmovnel %r8d, %eax
jmp 0x2d62bc
xorl %eax, %eax
cmpl %r8d, %eax
je 0x2d630c
movl %eax, %eax
imulq $0x18, %rax, %r14
addq 0x20(%rdi), %r14
cmpl $0x0, 0x38(%rbx)
je 0x2d62d5
andl $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 0x17630
movq 0x10(%rbx), %rdi
movq 0x10(%r14), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x17c70
cmpl $0x0, (%r14)
jne 0x2d642f
movq 0x10(%rbx), %rcx
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rsi
pushq $0x12
popq %rdx
callq 0x17ad0
pushq $-0x1
popq %rbp
cmpl $0x12, %eax
je 0x2d633b
testl %eax, %eax
jne 0x2d641b
andl $0x0, 0x38(%rbx)
xorl %ebp, %ebp
jmp 0x2d642f
cmpb $0x1f, 0x10(%rsp)
jne 0x2d6424
cmpb $-0x75, 0x11(%rsp)
jne 0x2d6424
cmpb $0x8, 0x12(%rsp)
jne 0x2d6424
testb $0x4, 0x13(%rsp)
je 0x2d6424
cmpw $0x6, 0x1a(%rsp)
jne 0x2d6424
cmpb $0x42, 0x1c(%rsp)
jne 0x2d6424
cmpb $0x43, 0x1d(%rsp)
jne 0x2d6424
cmpw $0x2, 0x1e(%rsp)
jne 0x2d6424
movzwl 0x20(%rsp), %r14d
movq 0x28(%rbx), %rdi
movw %r14w, 0x10(%rdi)
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rdi)
leaq -0x11(%r14), %r12
addq $0x12, %rdi
movq 0x10(%rbx), %rcx
pushq $0x1
popq %rsi
movq %r12, %rdx
callq 0x17ad0
movq %rax, %r13
cmpl %r13d, %r12d
jne 0x2d641b
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rdi
movupd %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 0x987f1(%rip), %rdx     # 0x36ebf4
pushq $-0xf
popq %rsi
pushq $0x70
popq %rcx
callq 0x21bfdf
testl %eax, %eax
je 0x2d6443
leaq 0xb1382(%rip), %rax     # 0x38779b
jmp 0x2d642b
leaq 0xb12cd(%rip), %rax     # 0x3876ef
jmp 0x2d642b
leaq 0xb12d0(%rip), %rax     # 0x3876fb
movq %rax, 0x48(%rbx)
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x38(%rsp)
leaq 0x60(%rsp), %r12
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x21c115
movl %eax, %r13d
xorl $0x1, %r13d
movq %r12, %rdi
callq 0x21ddfd
orl %r13d, %eax
jne 0x2d64e8
movl 0x88(%rsp), %eax
testl %eax, %eax
js 0x2d642f
cmpl $0x0, 0x38(%rbx)
je 0x2d6481
andl $0x0, 0x3c(%rbx)
movq %r15, 0x30(%rbx)
movl %eax, 0x38(%rbx)
movl 0x40(%rbx), %ecx
cmpl $0x10001, %ecx          # imm = 0x10001
jl 0x2d6334
movq 0x50(%rbx), %r13
movl (%r13), %eax
movl 0x4(%r13), %edx
shll $0x10, %edx
addl $0x10000, %edx          # imm = 0x10000
pushq $0x3
popq %r10
cmpl %ecx, %edx
jbe 0x2d64f4
xorl %edx, %edx
xorl %r12d, %r12d
cmpl %r12d, %eax
je 0x2d64f4
movq 0x10(%r13), %rsi
movl %edx, %ebp
andl $0x1e, %ebp
movl %r10d, %r15d
movl %ebp, %ecx
shll %cl, %r15d
movl %r12d, %r14d
shrl $0x4, %r14d
testl %r15d, (%rsi,%r14,4)
je 0x2d6824
incl %r12d
addl $0x2, %edx
jmp 0x2d64b9
leaq 0xb12c0(%rip), %rax     # 0x3877af
jmp 0x2d642b
movl %eax, %r12d
movq 0x30(%rbx), %rax
movq %rax, 0x8(%rsp)
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
jb 0x2d6724
movl 0x4(%r13), %eax
leal (%rax,%rax), %edx
xorl %ecx, %ecx
cmpl %r12d, %edx
sbbl %ecx, %ecx
orl $0x1, %ecx
addl %r12d, %ecx
pushq $0x21
popq %rsi
leaq 0xb1114(%rip), %rdx     # 0x387640
leal -0x2(%rsi), %edi
decl %esi
cmpl %ecx, (%rdx,%rdi,4)
ja 0x2d652c
movl %esi, %ecx
movl (%rdx,%rcx,4), %ebp
cvtsi2sd %rbp, %xmm0
mulsd 0x940a0(%rip), %xmm0    # 0x36a5e8
addsd 0x1f908(%rip), %xmm0    # 0x2f5e58
cvttsd2si %xmm0, %rcx
cmpl %ecx, %eax
jae 0x2d6724
movq %rcx, 0x28(%rsp)
movl %ebp, %eax
shrl $0x4, %eax
leaq 0x4(,%rax,4), %r14
movq %r14, %rdi
callq 0x17f50
movq %rax, %r15
movq %rax, %rdi
movl $0xaa, %esi
movq %r14, %rdx
callq 0x17380
cmpl %ebp, %r12d
jae 0x2d65b5
movq 0x18(%r13), %rdi
leaq (,%rbp,8), %rsi
callq 0x17f58
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rdi
imulq $0x18, %rbp, %rsi
callq 0x17f58
movq %rax, 0x20(%r13)
leal -0x1(%rbp), %edi
xorl %r8d, %r8d
pushq $0x2
popq %r10
xorl %r9d, %r9d
cmpl (%r13), %r9d
je 0x2d6729
movq 0x10(%r13), %r12
movl %r9d, %eax
shrl $0x4, %eax
movl (%r12,%rax,4), %edx
leal (%r9,%r9), %ecx
andl $0x1e, %ecx
movl %edx, %esi
shrl %cl, %esi
testb $0x3, %sil
jne 0x2d671c
movq 0x18(%r13), %rsi
movq %r9, 0x30(%rsp)
movl %r9d, %r9d
movq (%rsi,%r9,8), %r14
movq 0x20(%r13), %rsi
imulq $0x18, %r9, %r9
movq 0x10(%rsi,%r9), %r11
movq %r11, 0x70(%rsp)
movupd (%rsi,%r9), %xmm0
movapd %xmm0, 0x60(%rsp)
btsl %ecx, %edx
movl %edx, (%r12,%rax,4)
movq %r14, %rcx
shrq $0x21, %rcx
movl %r14d, %eax
shll $0xb, %eax
xorl %eax, %ecx
xorl %r14d, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %ebp
movl %edx, %esi
movl %ecx, %eax
xorl %edx, %edx
divl %edi
incl %edx
movl %esi, %eax
shrl $0x4, %eax
movl (%r15,%rax,4), %r11d
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %r10d, %r9d
shll %cl, %r9d
testl %r11d, %r9d
jne 0x2d666e
addl %edx, %esi
cmpl %ebp, %esi
movl %ebp, %eax
cmovbl %r8d, %eax
subl %eax, %esi
jmp 0x2d6646
notl %r9d
andl %r9d, %r11d
movl %r11d, (%r15,%rax,4)
movl %esi, %edx
cmpl (%r13), %esi
jae 0x2d66f2
movl (%r12,%rax,4), %r9d
shrl %cl, %r9d
movq 0x18(%r13), %rsi
testb $0x3, %r9b
jne 0x2d66f6
movq (%rsi,%rdx,8), %r9
movq %r14, (%rsi,%rdx,8)
movq 0x20(%r13), %rsi
imulq $0x18, %rdx, %rdx
movq 0x10(%rsi,%rdx), %r11
movq %r11, 0x50(%rsp)
movups (%rsi,%rdx), %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x70(%rsp), %r11
movq %r11, 0x10(%rsi,%rdx)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsi,%rdx)
movq 0x50(%rsp), %rdx
movq %rdx, 0x70(%rsp)
movapd 0x40(%rsp), %xmm0
movapd %xmm0, 0x60(%rsp)
pushq $0x1
popq %rdx
shll %cl, %edx
movq 0x10(%r13), %r12
orl %edx, (%r12,%rax,4)
movq %r9, %r14
jmp 0x2d6624
movq 0x18(%r13), %rsi
movq %r14, (%rsi,%rdx,8)
movq 0x20(%r13), %rax
imulq $0x18, %rdx, %rcx
movq 0x70(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx)
movapd 0x60(%rsp), %xmm0
movupd %xmm0, (%rax,%rcx)
movq 0x30(%rsp), %r9
incl %r9d
jmp 0x2d65c2
movl %r12d, %ebp
jmp 0x2d677a
cmpl %ebp, %r9d
jbe 0x2d6754
movq 0x18(%r13), %rdi
leaq (,%rbp,8), %rsi
callq 0x17f58
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rdi
imulq $0x18, %rbp, %rsi
callq 0x17f58
movq %rax, 0x20(%r13)
movq 0x10(%r13), %rdi
callq 0x17f48
movq %r15, 0x10(%r13)
movl %ebp, (%r13)
movl 0x4(%r13), %eax
movl %eax, 0x8(%r13)
movq 0x28(%rsp), %rax
movl %eax, 0xc(%r13)
pushq $0x3
popq %r10
movq 0x8(%rsp), %rcx
movq %rcx, %rdi
shrq $0x21, %rdi
movl %ecx, %eax
shll $0xb, %eax
xorl %eax, %edi
xorl %ecx, %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 0x2d67b7
movl %esi, %eax
jmp 0x2d688f
movl %r10d, %r15d
leal -0x1(%rbp), %ecx
movl %edi, %eax
xorl %edx, %edx
divl %ecx
incl %edx
movl %esi, %edi
movl %ebp, %eax
movq 0x8(%rsp), %r12
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 0x2d6872
testb $0x1, %r11b
jne 0x2d6800
movq 0x18(%r13), %r11
movl %edi, %r14d
cmpq %r12, (%r11,%r14,8)
je 0x2d6872
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 0x2d67ce
movb $0x1, %cl
movl %ebp, %edx
cmpl %ebp, %eax
movl %r15d, %r10d
je 0x2d6883
jmp 0x2d688f
movq 0x20(%r13), %rax
movl %r12d, %ecx
imulq $0x18, %rcx, %rcx
movq 0x8(%rax,%rcx), %rdi
callq 0x17f48
pushq $0x3
popq %r10
movl (%r13), %edx
cmpl %r12d, %edx
je 0x2d64f7
movq 0x10(%r13), %rax
movl (%rax,%r14,4), %ecx
movl %edx, %r12d
testl %r15d, %ecx
jne 0x2d64f7
btsl %ebp, %ecx
movl %ecx, (%rax,%r14,4)
decl 0x4(%r13)
movl (%r13), %r12d
jmp 0x2d64f7
shrl %cl, %r10d
testb $0x2, %r10b
sete %cl
movl %eax, %edx
movl %edi, %esi
movl %r15d, %r10d
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 0x2d68d4
testb $0x1, %dil
je 0x2d6334
movq 0x18(%r13), %rdi
shll %cl, %r10d
movl %eax, %eax
movq 0x8(%rsp), %rcx
movq %rcx, (%rdi,%rax,8)
notl %r10d
andl %r10d, %esi
movl %esi, (%r8,%rdx,4)
incl 0x4(%r13)
jmp 0x2d6904
movq 0x18(%r13), %rdi
movl %eax, %eax
shll %cl, %r10d
movq 0x8(%rsp), %rcx
movq %rcx, (%rdi,%rax,8)
notl %r10d
andl %r10d, %esi
movl %esi, (%r8,%rdx,4)
movq 0x4(%r13), %xmm0
pcmpeqd %xmm1, %xmm1
psubd %xmm1, %xmm0
movq %xmm0, 0x4(%r13)
movq 0x20(%r13), %r14
imulq $0x18, %rax, %r15
movl 0x38(%rbx), %eax
movl %eax, (%r14,%r15)
movq 0x38(%rsp), %rax
addl $0x12, %eax
cltq
addq 0x30(%rbx), %rax
movq %rax, 0x10(%r14,%r15)
movl $0x10000, %edi          # imm = 0x10000
callq 0x17f50
movq %rax, 0x8(%r14,%r15)
movq 0x20(%rbx), %rsi
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
callq 0x17630
jmp 0x2d6334