// File: karel-brinda[P]ococo/ext/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 0x56642
movl $0x0, -0x4(%rbp)
jmp 0x56815
movq -0x10(%rbp), %rax
cmpq 0x341eb(%rip), %rax     # 0x8a838
je 0x56660
movq -0x10(%rbp), %rax
cmpq 0x341e6(%rip), %rax     # 0x8a840
jne 0x56703
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x566df
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 0x4b20
cmpq -0x18(%rbp), %rax
jae 0x566bd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x56815
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4680
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x566dd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x56815
jmp 0x566df
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 0x5680e
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x567b8
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 0x56765
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
xorl %edx, %edx
callq 0x4650
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 0x4b20
cmpq -0x20(%rbp), %rax
jae 0x56799
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x56815
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4680
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x567b6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x56815
jmp 0x567b8
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4030
cmpq $-0x1, %rax
je 0x567fe
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x45e0
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x4030
movl -0x24(%rbp), %edi
movq %rax, %rsi
callq 0x47d0
cmpl $-0x1, %eax
jne 0x567fe
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x56815
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