// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/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;

    // Reading an uncompressed file
    if ( !fp->is_compressed )
    {
        count = hread(fp->fp, fp->uncompressed_block, BGZF_MAX_BLOCK_SIZE);
        if ( count==0 )
        {
            fp->block_length = 0;
            return 0;
        }
        if (fp->block_length != 0) fp->block_offset = 0;
        fp->block_address += count;
        fp->block_length = count;
        return 0;
    }

    // Reading compressed file
    int64_t block_address;
    block_address = htell(fp->fp);
    if ( fp->is_gzip && fp->gz_stream ) // is this is a initialized gzip stream?
    {
        count = inflate_gzip_block(fp, 0);
        if ( count<0 )
        {
            fp->errcode |= BGZF_ERR_ZLIB;
            return -1;
        }
        fp->block_length = count;
        fp->block_address = block_address;
        return 0;
    }
    if (fp->cache_size && load_block_from_cache(fp, block_address)) return 0;
    count = hread(fp->fp, header, sizeof(header));
    if (count == 0) { // no data read
        fp->block_length = 0;
        return 0;
    }
    int ret;
    if ( count != sizeof(header) || (ret=check_header(header))==-2 )
    {
        fp->errcode |= BGZF_ERR_HEADER;
        return -1;
    }
    if ( ret==-1 )
    {
        // GZIP, not BGZF
        uint8_t *cblock = (uint8_t*)fp->compressed_block;
        memcpy(cblock, header, sizeof(header));
        count = hread(fp->fp, cblock+sizeof(header), BGZF_BLOCK_SIZE - sizeof(header)) + sizeof(header);
        int nskip = 10;

        // Check optional fields to skip: FLG.FNAME,FLG.FCOMMENT,FLG.FHCRC,FLG.FEXTRA
        // Note: Some of these fields are untested, I did not have appropriate data available
        if ( header[3] & 0x4 ) // FLG.FEXTRA
        {
            nskip += unpackInt16(&cblock[nskip]) + 2;
        }
        if ( header[3] & 0x8 ) // FLG.FNAME
        {
            while ( nskip<count && cblock[nskip] ) nskip++;
            nskip++;
        }
        if ( header[3] & 0x10 ) // FLG.FCOMMENT
        {
            while ( nskip<count && cblock[nskip] ) nskip++;
            nskip++;
        }
        if ( header[3] & 0x2 ) nskip += 2;  //  FLG.FHCRC

        /* FIXME: Should handle this better.  There's no reason why
           someone shouldn't include a massively long comment in their
           gzip stream. */
        if ( nskip >= count )
        {
            fp->errcode |= BGZF_ERR_HEADER;
            return -1;
        }

        fp->is_gzip = 1;
        fp->gz_stream = (z_stream*) calloc(1,sizeof(z_stream));
        int ret = inflateInit2(fp->gz_stream, -15);
        if (ret != Z_OK)
        {
            fp->errcode |= BGZF_ERR_ZLIB;
            return -1;
        }
        fp->gz_stream->avail_in = count - nskip;
        fp->gz_stream->next_in  = cblock + nskip;
        count = inflate_gzip_block(fp, 1);
        if ( count<0 )
        {
            fp->errcode |= BGZF_ERR_ZLIB;
            return -1;
        }
        fp->block_length = count;
        fp->block_address = block_address;
        if ( fp->idx_build_otf ) return -1; // cannot build index for gzip
        return 0;
    }
    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 = hread(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;
    if ( fp->idx_build_otf )
    {
        bgzf_index_add_block(fp);
        fp->idx->ublock_addr += count;
    }
    cache_block(fp, size);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x9ba39
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movl $0x10000, %edx          # imm = 0x10000
callq 0x9bf30
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x9b9fe
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x9bf18
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x9ba13
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movslq -0x3c(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x9bf18
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x9bfd0
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x9bac6
movq -0x10(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x9bac6
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x9c000
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x9baa4
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bf18
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x9bf18
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9baee
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x9c160
cmpl $0x0, %eax
je 0x9baee
movl $0x0, -0x4(%rbp)
jmp 0x9bf18
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
leaq -0x30(%rbp), %rsi
movl $0x12, %edx
callq 0x9bf30
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x9bb24
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x9bf18
movslq -0x3c(%rbp), %rax
cmpq $0x12, %rax
jne 0x9bb3f
leaq -0x30(%rbp), %rdi
callq 0x9c260
movl %eax, -0x54(%rbp)
cmpl $-0x2, %eax
jne 0x9bb6c
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x2, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bf18
cmpl $-0x1, -0x54(%rbp)
jne 0x9bdf3
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movw -0x20(%rbp), %cx
movw %cx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x60(%rbp), %rsi
addq $0x12, %rsi
movl $0xfeee, %edx           # imm = 0xFEEE
callq 0x9bf30
addq $0x12, %rax
movl %eax, -0x3c(%rbp)
movl $0xa, -0x64(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x9bbea
movq -0x60(%rbp), %rdi
movslq -0x64(%rbp), %rax
addq %rax, %rdi
callq 0x9c330
addl $0x2, %eax
addl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x9bc37
jmp 0x9bbf8
movl -0x64(%rbp), %ecx
xorl %eax, %eax
cmpl -0x3c(%rbp), %ecx
movb %al, -0x69(%rbp)
jge 0x9bc1a
movq -0x60(%rbp), %rax
movslq -0x64(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x9bc23
jmp 0x9bc2e
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x9bbf8
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x9bc84
jmp 0x9bc45
movl -0x64(%rbp), %ecx
xorl %eax, %eax
cmpl -0x3c(%rbp), %ecx
movb %al, -0x6a(%rbp)
jge 0x9bc67
movq -0x60(%rbp), %rax
movslq -0x64(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x6a(%rbp)
movb -0x6a(%rbp), %al
testb $0x1, %al
jne 0x9bc70
jmp 0x9bc7b
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x9bc45
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movzbl -0x2d(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x9bc99
movl -0x64(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x9bcce
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x2, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bf18
movq -0x10(%rbp), %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
movl $0x1, %edi
movl $0x70, %esi
callq 0x6460
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movl $0xfffffff1, %esi       # imm = 0xFFFFFFF1
leaq 0x46991(%rip), %rdx     # 0xe26a1
movl $0x70, %ecx
callq 0x65d0
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x68(%rbp)
je 0x9bd50
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bf18
movl -0x3c(%rbp), %ecx
subl -0x64(%rbp), %ecx
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x60(%rbp), %rcx
movslq -0x64(%rbp), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x9c000
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x9bdbb
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x1, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bf18
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x9bde7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bf18
movl $0x0, -0x4(%rbp)
jmp 0x9bf18
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x9c330
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movw -0x20(%rbp), %cx
movw %cx, 0x10(%rax)
movl -0x44(%rbp), %eax
subl $0x12, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0x12, %rsi
movslq -0x48(%rbp), %rdx
callq 0x9bf30
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x9be8d
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x4, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bf18
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x9c350
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jge 0x9beb3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x9bf18
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x9bec8
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x9bf05
movq -0x10(%rbp), %rdi
callq 0x9c490
movslq -0x3c(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x9c650
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)