#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 */

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int O_ACCMODE;
int O_RDONLY;
int /*<<< orphan*/ PHYSFS_setErrorCode(scalar_t__);
scalar_t__ errcodeFromErrno();
int fcntl(int const, int /*<<< orphan*/);
int fsync(int const);
int __PHYSFS_platformFlush(void *opaque) {
  const int fd = *((int *)opaque);
  if ((fcntl(fd, F_GETFL) & O_ACCMODE) != O_RDONLY)
    do {
      if (fsync(fd) == -1) {
        if (errcodeFromErrno())
          PHYSFS_setErrorCode(errcodeFromErrno());
        return 0;
      }
    } while (0);
  return 1;
}


x86 assembly (clang, -O0):
<__PHYSFS_platformFlush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1030 <fcntl@plt>
mov    0x2e83(%rip),%rcx
and    (%rcx),%eax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%eax
je     11ca <__PHYSFS_platformFlush+0x8a>
jmp    1183 <__PHYSFS_platformFlush+0x43>
mov    -0x14(%rbp),%edi
call   1050 <fsync@plt>
cmp    $0xffffffff,%eax
jne    11c0 <__PHYSFS_platformFlush+0x80>
mov    $0x0,%al
call   1040 <errcodeFromErrno@plt>
cmp    $0x0,%rax
je     11b4 <__PHYSFS_platformFlush+0x74>
mov    $0x0,%al
call   1040 <errcodeFromErrno@plt>
mov    %rax,%rdi
call   1060 <PHYSFS_setErrorCode@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <__PHYSFS_platformFlush+0x91>
jmp    11c5 <__PHYSFS_platformFlush+0x85>
jmp    11ca <__PHYSFS_platformFlush+0x8a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__PHYSFS_platformFlush>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%ebp
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1030 <fcntl@plt>
mov    0x2e94(%rip),%rcx
and    (%rcx),%eax
mov    0x2e7b(%rip),%rcx
mov    $0x1,%ebx
cmp    (%rcx),%eax
je     1199 <__PHYSFS_platformFlush+0x59>
mov    %ebp,%edi
call   1050 <fsync@plt>
cmp    $0xffffffff,%eax
jne    1199 <__PHYSFS_platformFlush+0x59>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <errcodeFromErrno@plt>
test   %rax,%rax
je     1199 <__PHYSFS_platformFlush+0x59>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <errcodeFromErrno@plt>
mov    %rax,%rdi
call   1060 <PHYSFS_setErrorCode@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_ACCMODE = global i32 0
@O_RDONLY = global i32 0
define i32 @__PHYSFS_platformFlush(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = bitcast i8* %5 to i32*
%7 = load i32, i32* %6
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = load i32, i32* @F_GETFL
%10 = call i32 @fcntl(i32 %8, i32 %9)
%11 = load i32, i32* @O_ACCMODE
%12 = and i32 %10, %11
%13 = load i32, i32* @O_RDONLY
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %1
br label %16
16: ; preds = %15
%17 = load i32, i32* %4
%18 = call i32 @fsync(i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = call i64 (...) @errcodeFromErrno()
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i64 (...) @errcodeFromErrno()
%25 = call i32 @PHYSFS_setErrorCode(i64 %24)
br label %26
26: ; preds = %23, %20
store i32 0, i32* %2
br label %30
27: ; preds = %16
br label %28
28: ; preds = %27
br label %29
29: ; preds = %28, %1
store i32 1, i32* %2
br label %30
30: ; preds = %29, %26
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_ACCMODE = global i32 0
@O_RDONLY = global i32 0
define i32 @__PHYSFS_platformFlush(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = load i32, i32* @F_GETFL
%5 = tail call i32 @fcntl(i32 %3, i32 %4)
%6 = load i32, i32* @O_ACCMODE
%7 = and i32 %6, %5
%8 = load i32, i32* @O_RDONLY
%9 = icmp eq i32 %7, %8
br i1 %9, label %19, label %10
10: ; preds = %1
%11 = tail call i32 @fsync(i32 %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = tail call i64 (...) @errcodeFromErrno()
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i64 (...) @errcodeFromErrno()
%18 = tail call i32 @PHYSFS_setErrorCode(i64 %17)
br label %19
19: ; preds = %1, %10, %13, %16
%20 = phi i32 [ 0, %16 ], [ 0, %13 ], [ 1, %10 ], [ 1, %1 ]
ret i32 %20
}