// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/mFILE.c
// Function: mfflush
int mfflush(mFILE *mf) {
    if (!mf->fp)
        return 0;

    /* FIXME: only do this when opened in write mode */
    if (mf == m_channel[1] || mf == m_channel[2]) {
        if (mf->flush_pos < mf->size) {
            size_t bytes = mf->size - mf->flush_pos;
            if (fwrite(mf->data + mf->flush_pos, 1, bytes, mf->fp) < bytes)
                return -1;
            if (0 != fflush(mf->fp))
                return -1;
        }

        /* Stdout & stderr are non-seekable streams so throw away the data */
        mf->offset = mf->size = mf->flush_pos = 0;
    }

    /* only flush when opened in write mode */
    if (mf->mode & MF_WRITE) {
        if (mf->flush_pos < mf->size) {
            size_t bytes = mf->size - mf->flush_pos;
            if (!(mf->mode & MF_MODEX)) {
                fseek(mf->fp, mf->flush_pos, SEEK_SET);
            }
            if (fwrite(mf->data + mf->flush_pos, 1, bytes, mf->fp) < bytes)
                return -1;
            if (0 != fflush(mf->fp))
                return -1;
        }
        if (ftell(mf->fp) != -1 &&
            ftruncate(fileno(mf->fp), ftell(mf->fp)) == -1)
            return -1;
        mf->flush_pos = mf->size;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x80622
movl $0x0, -0x4(%rbp)
jmp 0x807f5
movq -0x10(%rbp), %rax
cmpq 0x9224b(%rip), %rax     # 0x112878
je 0x80640
movq -0x10(%rbp), %rax
cmpq 0x92246(%rip), %rax     # 0x112880
jne 0x806e3
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x806bf
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x30(%rcx), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x49b0
cmpq -0x18(%rbp), %rax
jae 0x8069d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x807f5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4580
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x806bd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x807f5
jmp 0x806bf
movq -0x10(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x807ee
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x80798
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x30(%rcx), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
jne 0x80745
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
xorl %edx, %edx
callq 0x4520
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
addq 0x30(%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x49b0
cmpq -0x20(%rbp), %rax
jae 0x80779
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x807f5
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4580
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x80796
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x807f5
jmp 0x80798
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4030
cmpq $-0x1, %rax
je 0x807de
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x44d0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4030
movl -0x24(%rbp), %edi
movq %rax, %rsi
callq 0x4680
cmpl $-0x1, %eax
jne 0x807de
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x807f5
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop