#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 O_RDONLY;
int /*<<< orphan*/ close(int);
int fsync(int);
int open(char const *, int, int /*<<< orphan*/);
int sqlite3UnixSyncDirectory(const char *zDirname) {
  int fd;
  int r;
  fd = open(zDirname, O_RDONLY | 0, 0);
  ;
  if (fd < 0) {
    return 14;
  }
  r = fsync(fd);
  close(fd);
  ;
  if (r) {
    return (10 | (5 << 8));
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<sqlite3UnixSyncDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    116c <sqlite3UnixSyncDirectory+0x3c>
movl   $0xe,-0x4(%rbp)
jmp    119c <sqlite3UnixSyncDirectory+0x6c>
mov    -0x14(%rbp),%edi
call   1040 <fsync@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x18(%rbp)
je     1195 <sqlite3UnixSyncDirectory+0x65>
movl   $0x50a,-0x4(%rbp)
jmp    119c <sqlite3UnixSyncDirectory+0x6c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3UnixSyncDirectory>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <open@plt>
test   %eax,%eax
js     1165 <sqlite3UnixSyncDirectory+0x35>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <fsync@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
test   %ebp,%ebp
mov    $0x50a,%eax
cmove  %ebp,%eax
jmp    116a <sqlite3UnixSyncDirectory+0x3a>
mov    $0xe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @sqlite3UnixSyncDirectory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = or i32 %7, 0
%9 = call i32 @open(i8* %6, i32 %8, i32 0)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 14, i32* %2
br label %22
13: ; preds = %1
%14 = load i32, i32* %4
%15 = call i32 @fsync(i32 %14)
store i32 %15, i32* %5
%16 = load i32, i32* %4
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 1290, i32* %2
br label %22
21: ; preds = %13
store i32 0, i32* %2
br label %22
22: ; preds = %21, %20, %12
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @sqlite3UnixSyncDirectory(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2, i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i32 @fsync(i32 %3)
%7 = tail call i32 @close(i32 %3)
%8 = icmp eq i32 %6, 0
%9 = select i1 %8, i32 0, i32 1290
br label %10
10: ; preds = %5, %1
%11 = phi i32 [ 14, %1 ], [ %9, %5 ]
ret i32 %11
}