// File: /workspace/github_c_makefile_star2_O3/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 $0xc8, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0x17bc0
movq %rax, %r15
movq 0x50(%rbx), %rdi
movl (%rdi), %r8d
testl %r8d, %r8d
je 0x333d67
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 0x333d5a
testb $0x1, %bpl
jne 0x333d46
movq 0x18(%rdi), %r14
movl %eax, %r12d
cmpq %r15, (%r14,%r12,8)
je 0x333d5a
addl %edx, %eax
cmpl %r8d, %eax
movl %r8d, %ecx
cmovbl %r9d, %ecx
subl %ecx, %eax
cmpl %esi, %eax
jne 0x333d19
jmp 0x333dc0
shrl %cl, %r11d
testb $0x3, %r11b
cmovnel %r8d, %eax
jmp 0x333d69
xorl %eax, %eax
cmpl %r8d, %eax
je 0x333dc0
movl %eax, %eax
leaq (%rax,%rax,2), %r14
shlq $0x3, %r14
addq 0x20(%rdi), %r14
cmpl $0x0, 0x38(%rbx)
je 0x333d89
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 0x333ef2
movq 0x10(%rbx), %rcx
movq %rsp, %rdi
movl $0x1, %esi
movl $0x12, %edx
callq 0x17b40
cmpl $0x12, %eax
je 0x333df1
testl %eax, %eax
jne 0x333ed9
movl $0x0, 0x38(%rbx)
xorl %ebp, %ebp
jmp 0x333ef2
cmpb $0x1f, (%rsp)
jne 0x333ee2
cmpb $-0x75, 0x1(%rsp)
jne 0x333ee2
cmpb $0x8, 0x2(%rsp)
jne 0x333ee2
testb $0x4, 0x3(%rsp)
je 0x333ee2
cmpw $0x6, 0xa(%rsp)
jne 0x333ee2
cmpb $0x42, 0xc(%rsp)
jne 0x333ee2
cmpb $0x43, 0xd(%rsp)
jne 0x333ee2
cmpw $0x2, 0xe(%rsp)
jne 0x333ee2
movzwl 0x10(%rsp), %r13d
movq 0x28(%rbx), %rdi
movzwl 0x10(%rsp), %eax
movw %ax, 0x10(%rdi)
movapd (%rsp), %xmm0
movupd %xmm0, (%rdi)
leaq -0x11(%r13), %r12
addq $0x12, %rdi
movq 0x10(%rbx), %rcx
movl $0x1, %esi
movq %r12, %rdx
callq 0x17b40
movq %rax, %r14
cmpl %r14d, %r12d
jne 0x333ed9
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %rdi
movupd %xmm0, 0x40(%rdi)
movq 0x28(%rbx), %rax
addq $0x12, %rax
movq %rax, (%rdi)
addl $-0xf, %r13d
movl %r13d, 0x8(%rdi)
movq 0x20(%rbx), %rax
movq %rax, 0x18(%rdi)
movl 0x18(%rbx), %eax
movl %eax, 0x20(%rdi)
leaq 0x9a8fb(%rip), %rdx     # 0x3ce7b8
movl $0xfffffff1, %esi       # imm = 0xFFFFFFF1
movl $0x70, %ecx
callq 0x26f236
testl %eax, %eax
je 0x333f06
leaq 0xb35d4(%rip), %rax     # 0x3e74ab
jmp 0x333ee9
leaq 0xb351f(%rip), %rax     # 0x3e73ff
jmp 0x333ee9
leaq 0xb3522(%rip), %rax     # 0x3e740b
movq %rax, 0x48(%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), %r12
movq %r12, %rdi
movl $0x4, %esi
callq 0x26f394
movl %eax, %ebp
xorl $0x1, %ebp
movq %r12, %rdi
callq 0x270f60
orl %ebp, %eax
jne 0x333fb9
movl 0x78(%rsp), %eax
testl %eax, %eax
js 0x333eed
cmpl $0x0, 0x38(%rbx)
je 0x333f42
movl $0x0, 0x3c(%rbx)
movq %r15, 0x30(%rbx)
movl %eax, 0x38(%rbx)
movl 0x40(%rbx), %ecx
cmpl $0x10001, %ecx          # imm = 0x10001
jl 0x333dea
movq 0x50(%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 0x333fb4
testl %eax, %eax
je 0x333fc5
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 0x333fca
incl %r12d
addq $0xc, %rdx
addl $0x2, %edi
cmpl %r12d, %eax
jne 0x333f88
movl %eax, %r12d
jmp 0x333fff
leaq 0xb34ff(%rip), %rax     # 0x3e74bf
jmp 0x333ee9
xorl %r12d, %r12d
jmp 0x333fff
movq 0x20(%r13), %rax
movq (%rax,%rdx,2), %rdi
callq 0x17fe8
movl (%r13), %edx
cmpl %r12d, %edx
je 0x333fff
movq 0x10(%r13), %rax
movl (%rax,%r15,4), %ecx
movl %edx, %r12d
testl %r14d, %ecx
jne 0x333fff
btsl %ebp, %ecx
movl %ecx, (%rax,%r15,4)
decl 0x4(%r13)
movl (%r13), %r12d
movq 0x30(%rbx), %r15
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
jb 0x3342a5
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 0xb331f(%rip), %rdx     # 0x3e7350
leal -0x2(%rsi), %edi
decl %esi
cmpl %ecx, (%rdx,%rdi,4)
ja 0x334031
movl %esi, %ecx
movl (%rdx,%rcx,4), %ebp
cvtsi2sd %rbp, %xmm0
mulsd 0x96273(%rip), %xmm0    # 0x3ca2c0
addsd 0x21df3(%rip), %xmm0    # 0x355e48
cvttsd2si %xmm0, %rcx
cmpl %ecx, %eax
jae 0x3342a5
movq %rcx, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movl %ebp, %eax
shrl $0x4, %eax
leaq 0x4(,%rax,4), %r14
movq %r14, %rdi
callq 0x17ff0
movq %rax, %r15
movq %rax, %rdi
movl $0xaa, %esi
movq %r14, %rdx
callq 0x173a0
cmpl %ebp, %r12d
jae 0x3340c6
movq 0x18(%r13), %rdi
leaq (,%rbp,8), %r12
movq %r12, %rsi
callq 0x17ff8
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rdi
leaq (%r12,%r12,2), %rsi
callq 0x17ff8
movq %rax, 0x20(%r13)
movl (%r13), %r12d
testl %r12d, %r12d
je 0x33427c
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 0x334242
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 0x334191
incl %edx
addl %edx, %esi
xorl %eax, %eax
cmpl %ebp, %esi
jb 0x334172
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 0x334168
notl %r12d
andl %r11d, %r12d
movl %r12d, (%r15,%rax,4)
cmpl (%r13), %esi
jae 0x334217
movl (%r9,%rax,4), %r9d
shrl %cl, %r9d
movq 0x18(%r13), %rdx
testb $0x3, %r9b
jne 0x33421b
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 0x334128
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 0x3340d5
cmpl %ebp, %r12d
jbe 0x33427c
movq 0x18(%r13), %rdi
leaq (,%rbp,8), %r12
movq %r12, %rsi
callq 0x17ff8
movq %rax, 0x18(%r13)
movq 0x20(%r13), %rdi
leaq (%r12,%r12,2), %rsi
callq 0x17ff8
movq %rax, 0x20(%r13)
movq 0x10(%r13), %rdi
callq 0x17fe8
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 0x3342a8
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 0x3342df
movl %esi, %eax
jmp 0x334357
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 0x33433d
testb $0x1, %r11b
jne 0x33431c
movq 0x18(%r13), %r11
movl %edi, %r14d
cmpq %r15, (%r11,%r14,8)
je 0x33433d
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 0x3342ee
movb $0x1, %cl
movl %ebp, %edx
cmpl %ebp, %eax
je 0x33434b
jmp 0x334357
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 0x33439d
testb $0x1, %dil
je 0x333dea
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 0x3343ce
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 0x38(%rbx), %eax
movl %eax, (%r14,%r15,8)
movq 0x28(%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 0x333dea