#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 */
scalar_t__ ENOTDIR;
int /*<<< orphan*/ F_OK;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ _access(char *, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int pathIsDirectory(char *path) {
  struct stat s;
  if (stat(path, &s) == 0) {
    if (S_ISDIR(s.st_mode))
      return !(_access(path, F_OK) == ENOTDIR);
  }
  return 0;
}


x86 assembly (clang, -O0):
<pathIsDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    1198 <pathIsDirectory+0x68>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1193 <pathIsDirectory+0x63>
mov    -0x10(%rbp),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1040 <_access@plt>
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    119f <pathIsDirectory+0x6f>
jmp    1198 <pathIsDirectory+0x68>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathIsDirectory>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <stat@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1173 <pathIsDirectory+0x43>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
je     1173 <pathIsDirectory+0x43>
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <_access@plt>
mov    0x2e8e(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@F_OK = global i32 0
@ENOTDIR = global i64 0
define i32 @pathIsDirectory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @stat(i8* %5, %struct.stat* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i64 @S_ISDIR(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = load i32, i32* @F_OK
%16 = call i64 @_access(i8* %14, i32 %15)
%17 = load i64, i64* @ENOTDIR
%18 = icmp eq i64 %16, %17
%19 = xor i1 %18, true
%20 = zext i1 %19 to i32
store i32 %20, i32* %2
br label %23
21: ; preds = %8
br label %22
22: ; preds = %21, %1
store i32 0, i32* %2
br label %23
23: ; preds = %22, %13
%24 = load i32, i32* %2
ret i32 %24
}

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