#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
scalar_t__ access(char *, int);
scalar_t__ stat(char *, struct stat *);
int sqlite3UnixIsDirWritable(char *zBuf) {
  struct stat buf;
  if (zBuf == 0)
    return 0;
  if (zBuf[0] == 0)
    return 0;
  if (stat(zBuf, &buf))
    return 0;
  if (!S_ISDIR(buf.st_mode))
    return 0;
  if (access(zBuf, 07))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<sqlite3UnixIsDirWritable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <sqlite3UnixIsDirWritable+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11da <sqlite3UnixIsDirWritable+0xaa>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116f <sqlite3UnixIsDirWritable+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11da <sqlite3UnixIsDirWritable+0xaa>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     1192 <sqlite3UnixIsDirWritable+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11da <sqlite3UnixIsDirWritable+0xaa>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    11af <sqlite3UnixIsDirWritable+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    11da <sqlite3UnixIsDirWritable+0xaa>
mov    -0x10(%rbp),%rdi
mov    $0x7,%esi
call   1050 <access@plt>
cmp    $0x0,%rax
je     11d3 <sqlite3UnixIsDirWritable+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    11da <sqlite3UnixIsDirWritable+0xaa>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3UnixIsDirWritable>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     1174 <sqlite3UnixIsDirWritable+0x44>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1174 <sqlite3UnixIsDirWritable+0x44>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
jne    1174 <sqlite3UnixIsDirWritable+0x44>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
je     1174 <sqlite3UnixIsDirWritable+0x44>
mov    %rbx,%rdi
mov    $0x7,%esi
call   1050 <access@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @sqlite3UnixIsDirWritable(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %32
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %8
store i32 0, i32* %2
br label %32
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = call i64 @stat(i8* %16, %struct.stat* %4)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %2
br label %32
20: ; preds = %15
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @S_ISDIR(i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %20
store i32 0, i32* %2
br label %32
26: ; preds = %20
%27 = load i8*, i8** %3
%28 = call i64 @access(i8* %27, i32 7)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %2
br label %32
31: ; preds = %26
store i32 1, i32* %2
br label %32
32: ; preds = %31, %30, %25, %19, %14, %7
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @sqlite3UnixIsDirWritable(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %20, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = call i64 @stat(i8* %0, %struct.stat* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @S_ISDIR(i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = call i64 @access(i8* %0, i32 7)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %16, %11, %8, %5, %1
%21 = phi i32 [ 0, %1 ], [ 0, %5 ], [ 0, %8 ], [ 0, %11 ], [ %19, %16 ]
ret i32 %21
}