// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/bgzf.c
// Function: bgzf_flush
int bgzf_flush(BGZF *fp)
{
    if (!fp->is_write) return 0;
#ifdef BGZF_MT
    if (fp->mt) {
        int ret = 0;
        if (fp->block_offset) ret = mt_queue(fp);
        if (!ret) ret = mt_flush_queue(fp);

        // We maintain mt->block_address when threading as the
        // main code can call bgzf_tell without any locks.
        // (The result from tell are wrong, but we only care about the last
        // 16-bits worth except for the final flush process.
        pthread_mutex_lock(&fp->mt->idx_m);
        fp->block_address = fp->mt->block_address;
        pthread_mutex_unlock(&fp->mt->idx_m);

        return ret;
    }
#endif

    if (!fp->is_compressed) {
        return hflush(fp->fp);
    }

    while (fp->block_offset > 0) {
        int block_length;
        if ( fp->idx_build_otf )
        {
            bgzf_index_add_block(fp);
            fp->idx->ublock_addr += fp->block_offset;
        }
        block_length = deflate_block(fp, fp->block_offset);
        if (block_length < 0) {
            hts_log_debug("Deflate block operation failed: %s", bgzf_zerr(block_length, NULL));
            return -1;
        }
        if (hwrite(fp->fp, fp->compressed_block, block_length) != block_length) {
            hts_log_error("File write failed (wrong size)");
            fp->errcode |= BGZF_ERR_IO; // possibly truncated file
            return -1;
        }
        fp->block_address += block_length;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x11, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xf849
movl $0x0, -0x4(%rbp)
jmp 0xf9fb
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0xf8ca
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0xf871
movq -0x10(%rbp), %rdi
callq 0xfa10
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0xf883
movq -0x10(%rbp), %rdi
callq 0xfbf0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0xe0, %rdi
callq 0x4730
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x70(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0xe0, %rdi
callq 0x4330
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xf9fb
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xf8f0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x143b0
movl %eax, -0x4(%rbp)
jmp 0xf9fb
jmp 0xf8f2
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0xf9f4
movq -0x10(%rbp), %rax
cmpl $0x0, 0x58(%rax)
je 0xf92b
movq -0x10(%rbp), %rdi
callq 0xdb40
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %esi
callq 0xfcc0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jge 0xf979
movl -0x18(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
callq 0xcd40
movq %rax, %rcx
movl $0x5, %edi
leaq 0xdf564(%rip), %rsi     # 0xeeec3
leaq 0xdf568(%rip), %rdx     # 0xeeece
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf9fb
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movslq -0x18(%rbp), %rdx
callq 0xfdc0
movslq -0x18(%rbp), %rcx
cmpq %rcx, %rax
je 0xf9df
movl $0x1, %edi
leaq 0xdf51c(%rip), %rsi     # 0xeeec3
leaq 0xdf543(%rip), %rdx     # 0xeeef1
movb $0x0, %al
callq 0x1b030
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 0xf9fb
movslq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
jmp 0xf8f2
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)