#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ errno;
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ syswarn(int, int /*<<< orphan*/, char *, char *);
scalar_t__ write(int, char *, int);
void file_flush(int fd, char *fname, int isempt) {
  static char blnk[] = "\0";
  if (!isempt)
    return;
  if (lseek(fd, (off_t)-1, SEEK_CUR) < 0) {
    syswarn(1, errno, "Failed seek on file %s", fname);
    return;
  }
  if (write(fd, blnk, 1) < 0)
    syswarn(1, errno, "Failed write to file %s", fname);
  return;
}


x86 assembly (clang, -O0):
<file_flush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1151 <file_flush+0x21>
jmp    11d5 <file_flush+0xa5>
mov    -0x4(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    1194 <file_flush+0x64>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edi
lea    0xe76(%rip),%rdx
call   1040 <syswarn@plt>
jmp    11d5 <file_flush+0xa5>
mov    -0x4(%rbp),%edi
lea    0x2e9e(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    11d0 <file_flush+0xa0>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edi
lea    0xe4c(%rip),%rdx
call   1040 <syswarn@plt>
jmp    11d5 <file_flush+0xa5>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_flush>:
push   %rbp
push   %rbx
push   %rax
test   %edx,%edx
je     116c <file_flush+0x3c>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ea5(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1050 <lseek@plt>
test   %rax,%rax
js     1173 <file_flush+0x43>
lea    0x2ee1(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <write@plt>
test   %rax,%rax
js     117c <file_flush+0x4c>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe86(%rip),%rdx
jmp    1183 <file_flush+0x53>
lea    0xe94(%rip),%rdx
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <syswarn@plt>

LLVM IR (-O0):
@file_flush.blnk = internal global [2 x i8] zeroinitializer
@SEEK_CUR = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"Failed seek on file %s\00"
@.str.1 = [24 x i8] c"Failed write to file %s\00"
define void @file_flush(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %3
br label %28
10: ; preds = %3
%11 = load i32, i32* %4
%12 = load i32, i32* @SEEK_CUR
%13 = call i64 @lseek(i32 %11, i32 -1, i32 %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @errno
%17 = load i8*, i8** %5
%18 = call i32 @syswarn(i32 1, i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %28
19: ; preds = %10
%20 = load i32, i32* %4
%21 = call i64 @write(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @file_flush.blnk, i64 0, i64 0), i32 1)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @errno
%25 = load i8*, i8** %5
%26 = call i32 @syswarn(i32 1, i32 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %19
br label %28
28: ; preds = %27, %15, %9
ret void
}

LLVM IR (-O2):
@file_flush.blnk = internal global [2 x i8] zeroinitializer
@SEEK_CUR = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"Failed seek on file %s\00"
@.str.1 = [24 x i8] c"Failed write to file %s\00"
define void @file_flush(i32 %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = load i32, i32* @SEEK_CUR
%7 = tail call i64 @lseek(i32 %0, i32 -1, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call i64 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @file_flush.blnk, i64 0, i64 0), i32 1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9, %5
%13 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %9 ]
%14 = load i32, i32* @errno
%15 = tail call i32 @syswarn(i32 1, i32 %14, i8* %13, i8* %1)
br label %16
16: ; preds = %12, %9, %3
ret void
}