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

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ SQLITE_IOERR_DELETE;
int /*<<< orphan*/ SQLITE_IOERR_DIR_FSYNC;
int SQLITE_OK;
scalar_t__ errno;
scalar_t__ fsync(int);
int openDirectory(char const *, int *);
int /*<<< orphan*/ robust_close(int /*<<< orphan*/, int, int);
int unixLogErrorAtLine(int /*<<< orphan*/, char *, char const *, int);
int unlink(char const *);
int unixDelete(sqlite3_vfs *NotUsed, const char *zPath, int dirSync) {
  int rc = SQLITE_OK;
  (void)(NotUsed);
  if (unlink(zPath) == (-1) && errno != ENOENT) {
    return unixLogErrorAtLine(SQLITE_IOERR_DELETE, "unlink", zPath, 1399);
  }
  if (dirSync) {
    int fd;
    rc = openDirectory(zPath, &fd);
    if (rc == SQLITE_OK) {
      if (fsync(fd)) {
        rc = unixLogErrorAtLine(SQLITE_IOERR_DIR_FSYNC, "fsync", zPath, 1406);
      }
      robust_close(0, fd, 1408);
    }
  }
  return rc;
}


x86 assembly (clang, -O0):
<unixDelete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    11c1 <unixDelete+0x71>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    0x2e2e(%rip),%rcx
cmp    (%rcx),%rax
je     11c1 <unixDelete+0x71>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe51(%rip),%rsi
mov    $0x577,%ecx
call   1040 <unixLogErrorAtLine@plt>
mov    %eax,-0x4(%rbp)
jmp    123a <unixDelete+0xea>
cmpl   $0x0,-0x1c(%rbp)
je     1234 <unixDelete+0xe4>
mov    -0x18(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1050 <openDirectory@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%eax
jne    122f <unixDelete+0xdf>
mov    -0x24(%rbp),%edi
call   1060 <fsync@plt>
cmp    $0x0,%rax
je     1220 <unixDelete+0xd0>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf4(%rip),%rsi
mov    $0x57e,%ecx
call   1040 <unixLogErrorAtLine@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%esi
xor    %edi,%edi
mov    $0x580,%edx
call   1070 <robust_close@plt>
jmp    1234 <unixDelete+0xe4>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unixDelete>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    0x2e85(%rip),%r15
mov    (%r15),%ebp
mov    %rsi,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1189 <unixDelete+0x39>
mov    0x2e56(%rip),%rax
mov    (%rax),%rax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%rax
jne    11eb <unixDelete+0x9b>
test   %ebx,%ebx
je     11de <unixDelete+0x8e>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1050 <openDirectory@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    11de <unixDelete+0x8e>
mov    0x4(%rsp),%edi
call   1060 <fsync@plt>
test   %rax,%rax
je     11ce <unixDelete+0x7e>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    %r14,%rdx
mov    $0x57e,%ecx
call   1040 <unixLogErrorAtLine@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%esi
xor    %edi,%edi
mov    $0x580,%edx
call   1070 <robust_close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    %r14,%rdx
mov    $0x577,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <unixLogErrorAtLine@plt>

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@SQLITE_IOERR_DELETE = global i32 0
@.str = [7 x i8] c"unlink\00"
@SQLITE_IOERR_DIR_FSYNC = global i32 0
@.str.1 = [6 x i8] c"fsync\00"
define i32 @unixDelete(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* @SQLITE_OK
store i32 %10, i32* %8
%11 = load i32*, i32** %5
%12 = load i8*, i8** %6
%13 = call i32 @unlink(i8* %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %3
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENOENT
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @SQLITE_IOERR_DELETE
%21 = load i8*, i8** %6
%22 = call i32 @unixLogErrorAtLine(i32 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %21, i32 1399)
store i32 %22, i32* %4
br label %46
23: ; preds = %15, %3
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %44
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = call i32 @openDirectory(i8* %27, i32* %9)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = load i32, i32* @SQLITE_OK
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %43
32: ; preds = %26
%33 = load i32, i32* %9
%34 = call i64 @fsync(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i32, i32* @SQLITE_IOERR_DIR_FSYNC
%38 = load i8*, i8** %6
%39 = call i32 @unixLogErrorAtLine(i32 %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 1406)
store i32 %39, i32* %8
br label %40
40: ; preds = %36, %32
%41 = load i32, i32* %9
%42 = call i32 @robust_close(i32 0, i32 %41, i32 1408)
br label %43
43: ; preds = %40, %26
br label %44
44: ; preds = %43, %23
%45 = load i32, i32* %8
store i32 %45, i32* %4
br label %46
46: ; preds = %44, %19
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@SQLITE_IOERR_DELETE = global i32 0
@.str = [7 x i8] c"unlink\00"
@SQLITE_IOERR_DIR_FSYNC = global i32 0
@.str.1 = [6 x i8] c"fsync\00"
define i32 @unixDelete(i32* nocapture readnone %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = load i32, i32* @SQLITE_OK
%6 = tail call i32 @unlink(i8* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* @SQLITE_IOERR_DELETE
%14 = tail call i32 @unixLogErrorAtLine(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1, i32 1399)
br label %35
15: ; preds = %8, %3
%16 = icmp eq i32 %2, 0
br i1 %16, label %35, label %17
17: ; preds = %15
%18 = bitcast i32* %4 to i8*
%19 = call i32 @openDirectory(i8* %1, i32* %4)
%20 = load i32, i32* @SQLITE_OK
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = load i32, i32* %4
%24 = call i64 @fsync(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i32, i32* @SQLITE_IOERR_DIR_FSYNC
%28 = call i32 @unixLogErrorAtLine(i32 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 1406)
br label %29
29: ; preds = %26, %22
%30 = phi i32 [ %28, %26 ], [ %19, %22 ]
%31 = load i32, i32* %4
%32 = call i32 @robust_close(i32 0, i32 %31, i32 1408)
br label %33
33: ; preds = %29, %17
%34 = phi i32 [ %30, %29 ], [ %19, %17 ]
br label %35
35: ; preds = %15, %33, %12
%36 = phi i32 [ %14, %12 ], [ %34, %33 ], [ %5, %15 ]
ret i32 %36
}