#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*/ TRACE3(char *, int, char const *);
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);
  TRACE3("DIRSYNC %-3d (%s)\n", fd, zDirname);
  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    0x2e91(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe8c(%rip),%rdi
call   1030 <TRACE3@plt>
cmpl   $0x0,-0x14(%rbp)
jge    118f <sqlite3UnixSyncDirectory+0x4f>
movl   $0xe,-0x4(%rbp)
jmp    11bf <sqlite3UnixSyncDirectory+0x7f>
mov    -0x14(%rbp),%edi
call   1050 <fsync@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x18(%rbp)
je     11b8 <sqlite3UnixSyncDirectory+0x78>
movl   $0x50a,-0x4(%rbp)
jmp    11bf <sqlite3UnixSyncDirectory+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3UnixSyncDirectory>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xea0(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1030 <TRACE3@plt>
test   %ebx,%ebx
js     118a <sqlite3UnixSyncDirectory+0x4a>
mov    %ebx,%edi
call   1050 <fsync@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
test   %ebp,%ebp
mov    $0x50a,%eax
cmove  %ebp,%eax
jmp    118f <sqlite3UnixSyncDirectory+0x4f>
mov    $0xe,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [19 x i8] c"DIRSYNC %-3d (%s)\0A\00"
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 = load i8*, i8** %3
%12 = call i32 @TRACE3(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %11)
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 14, i32* %2
br label %25
16: ; preds = %1
%17 = load i32, i32* %4
%18 = call i32 @fsync(i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 1290, i32* %2
br label %25
24: ; preds = %16
store i32 0, i32* %2
br label %25
25: ; preds = %24, %23, %15
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [19 x i8] c"DIRSYNC %-3d (%s)\0A\00"
define i32 @sqlite3UnixSyncDirectory(i8* %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2, i32 0)
%4 = tail call i32 @TRACE3(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %0)
%5 = icmp slt i32 %3, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = tail call i32 @fsync(i32 %3)
%8 = tail call i32 @close(i32 %3)
%9 = icmp eq i32 %7, 0
%10 = select i1 %9, i32 0, i32 1290
br label %11
11: ; preds = %6, %1
%12 = phi i32 [ 14, %1 ], [ %10, %6 ]
ret i32 %12
}