// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl (%rdi), %eax
xorl %ebx, %ebx
btl $0x11, %eax
jae 0xb75e
movq %rdi, %r14
movq 0x48(%rdi), %r13
testq %r13, %r13
je 0xb6a9
cmpl $0x0, 0x10(%r14)
pushq $-0x1
popq %rbx
je 0xb64f
movq %r14, %rdi
callq 0xb7b6
testl %eax, %eax
jne 0xb738
movq 0x48(%r14), %r13
leaq 0x30(%r13), %r15
movq %r15, %rdi
callq 0x4750
leaq 0x8(%rsp), %r12
cmpl $0x0, 0x58(%r13)
je 0xb71b
movq 0x20(%r13), %rdi
callq 0x2bf78
movl %eax, %ebp
movq %r15, %rdi
callq 0x4340
testl %ebp, %ebp
jne 0xb738
andq $0x0, 0x8(%rsp)
movq $0x989680, 0x10(%rsp)   # imm = 0x989680
movq %r12, %rdi
xorl %esi, %esi
callq 0x4100
movq %r15, %rdi
callq 0x4750
jmp 0xb660
btl $0x1e, %eax
jb 0xb6c6
movq 0x40(%r14), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd64f
movl 0x10(%r14), %esi
testl %esi, %esi
jle 0xb75e
cmpl $0x0, 0x58(%r14)
je 0xb6ed
movq %r14, %rdi
callq 0xa757
movslq 0x10(%r14), %rsi
movq 0x50(%r14), %rax
addq %rsi, 0x10(%rax)
movq %r14, %rdi
callq 0xb8b0
testl %eax, %eax
js 0xb76f
movq 0x30(%r14), %rsi
movq 0x40(%r14), %rdi
movl %eax, %r15d
movq %r15, %rdx
callq 0xb9a0
cmpq %r15, %rax
jne 0xb795
addq %r15, 0x18(%r14)
jmp 0xb6c6
movq %r15, %rdi
callq 0x4340
movq 0x20(%r13), %rdi
callq 0x2cb1f
testl %eax, %eax
jne 0xb738
xorl %ebx, %ebx
cmpw (%r14), %bx
sbbl %ebx, %ebx
movl $0xe0, %r15d
movq 0x48(%r14), %rdi
addq %r15, %rdi
callq 0x4750
movq 0x48(%r14), %rdi
movq 0x70(%rdi), %rax
movq %rax, 0x18(%r14)
addq %r15, %rdi
callq 0x4340
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
xorl %esi, %esi
callq 0x9cf6
leaq 0x6b52f(%rip), %rsi     # 0x76cae
leaq 0x6b533(%rip), %rdx     # 0x76cb9
pushq $0x5
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x110c6
jmp 0xb7b1
leaq 0x6b512(%rip), %rsi     # 0x76cae
leaq 0x6b539(%rip), %rdx     # 0x76cdc
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
orb $0x4, (%r14)
pushq $-0x1
popq %rbx
jmp 0xb75e