#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 st_mode;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENAMETOOLONG;
int /*<<< orphan*/ S_ISDIR(int);
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int _path_set_err(int, char *, size_t, char *, char const *, ...);
int /*<<< orphan*/ errno;
scalar_t__ lstat(char *, struct stat *);
int path_canonicalize(char const *, char *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *strrchr(char *, char);
int path_is_accessible(const char *path, char *errbuf, size_t errbuflen) {
  int n;
  char buf[4096];
  struct stat st;
  char *p;
  n = path_canonicalize(path, buf, sizeof(buf));
  if (n < 0) {
    return (_path_set_err(-1, errbuf, errbuflen,
                          "cannot canonicalize \"%s\": %s", path,
                          strerror(errno)));
  }
  if (n >= sizeof(buf)) {
    errno = ENAMETOOLONG;
    return (_path_set_err(
        -1, errbuf, errbuflen,
        "cannot canonicalize \"%s\": exceeded max path length", path));
  }
  if (lstat(buf, &st) < 0) {
    return (_path_set_err(-1, errbuf, errbuflen, "cannot stat \"%s\": %s", buf,
                          strerror(errno)));
  }
  if (!S_ISDIR(st.st_mode)) {
    if ((p = strrchr(buf, '/'))) {
      *p = '\0';
    }
  }
  while (buf[0] != '\0') {
    if (lstat(buf, &st) < 0) {
      return (_path_set_err(-1, errbuf, errbuflen, "cannot stat \"%s\": %s",
                            buf, strerror(errno)));
    }
    if (!S_ISDIR(st.st_mode)) {
      errno = EINVAL;
      return (_path_set_err(-1, errbuf, errbuflen,
                            "cannot check \"%s\": unexpected file type", buf));
    }
    if ((st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) !=
        (S_IXUSR | S_IXGRP | S_IXOTH)) {
      return (_path_set_err(0, errbuf, errbuflen,
                            "execute permissions for all required on \"%s\"",
                            buf));
    }
    if (!(p = strrchr(buf, '/'))) {
      errno = EINVAL;
      return (_path_set_err(-1, errbuf, errbuflen,
                            "cannot check \"%s\": internal error", buf));
    }
    if ((p == buf) && (buf[1] != '\0')) {
      p++;
    }
    *p = '\0';
  }
  return (1);
}


x86 assembly (clang, -O0):
<path_is_accessible>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1090,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <path_canonicalize@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11fb <path_is_accessible+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1058(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1050(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1048(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1058(%rbp),%rsi
mov    -0x1050(%rbp),%rdx
mov    -0x1048(%rbp),%r8
mov    %eax,%r9d
mov    $0xffffffff,%edi
lea    0xe14(%rip),%rcx
mov    $0x0,%al
call   1060 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    150c <path_is_accessible+0x3ac>
movslq -0x24(%rbp),%rax
cmp    $0x1000,%rax
jb     1244 <path_is_accessible+0xe4>
mov    0x2da6(%rip),%rax
mov    (%rax),%ecx
mov    0x2dad(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%r8
mov    $0xffffffff,%edi
lea    0xde8(%rip),%rcx
mov    $0x0,%al
call   1060 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    150c <path_is_accessible+0x3ac>
lea    -0x1030(%rbp),%rdi
lea    -0x1038(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
jge    12c6 <path_is_accessible+0x166>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1070(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1068(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1070(%rbp),%rsi
mov    -0x1068(%rbp),%rdx
mov    -0x1060(%rbp),%r8
mov    %eax,%r9d
mov    $0xffffffff,%edi
lea    0xd99(%rip),%rcx
mov    $0x0,%al
call   1060 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    150c <path_is_accessible+0x3ac>
mov    -0x1038(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    130b <path_is_accessible+0x1ab>
lea    -0x1030(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x1040(%rbp)
cmp    $0x0,%rax
je     1306 <path_is_accessible+0x1a6>
mov    -0x1040(%rbp),%rax
movb   $0x0,(%rax)
jmp    130b <path_is_accessible+0x1ab>
jmp    1310 <path_is_accessible+0x1b0>
movsbl -0x1030(%rbp),%eax
cmp    $0x0,%eax
je     1505 <path_is_accessible+0x3a5>
lea    -0x1030(%rbp),%rdi
lea    -0x1038(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
jge    13a2 <path_is_accessible+0x242>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1088(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1080(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1078(%rbp)
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1088(%rbp),%rsi
mov    -0x1080(%rbp),%rdx
mov    -0x1078(%rbp),%r8
mov    %eax,%r9d
mov    $0xffffffff,%edi
lea    0xcbd(%rip),%rcx
mov    $0x0,%al
call   1060 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    150c <path_is_accessible+0x3ac>
mov    -0x1038(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    13f2 <path_is_accessible+0x292>
mov    0x2c03(%rip),%rax
mov    (%rax),%ecx
mov    0x2c02(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%r8
mov    $0xffffffff,%edi
lea    0xc82(%rip),%rcx
mov    $0x0,%al
call   1060 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    150c <path_is_accessible+0x3ac>
mov    -0x1038(%rbp),%eax
mov    0x2be1(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2bd0(%rip),%rdx
or     (%rdx),%ecx
mov    0x2bd7(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
mov    0x2bc4(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2bb3(%rip),%rdx
or     (%rdx),%ecx
mov    0x2bba(%rip),%rdx
or     (%rdx),%ecx
cmp    %ecx,%eax
je     145f <path_is_accessible+0x2ff>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%r8
xor    %edi,%edi
lea    0xc3d(%rip),%rcx
mov    $0x0,%al
call   1060 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    150c <path_is_accessible+0x3ac>
lea    -0x1030(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x1040(%rbp)
cmp    $0x0,%rax
jne    14bd <path_is_accessible+0x35d>
mov    0x2b38(%rip),%rax
mov    (%rax),%ecx
mov    0x2b37(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%r8
mov    $0xffffffff,%edi
lea    0xc0c(%rip),%rcx
mov    $0x0,%al
call   1060 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    150c <path_is_accessible+0x3ac>
mov    -0x1040(%rbp),%rax
lea    -0x1030(%rbp),%rcx
cmp    %rcx,%rax
jne    14f6 <path_is_accessible+0x396>
movsbl -0x102f(%rbp),%eax
cmp    $0x0,%eax
je     14f6 <path_is_accessible+0x396>
mov    -0x1040(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1040(%rbp)
mov    -0x1040(%rbp),%rax
movb   $0x0,(%rax)
jmp    1310 <path_is_accessible+0x1b0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1090,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_is_accessible>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x10(%rsp),%rsi
mov    $0x1000,%edx
call   1070 <path_canonicalize@plt>
test   %eax,%eax
js     11c7 <path_is_accessible+0x67>
cmp    $0x1000,%eax
jb     11ef <path_is_accessible+0x8f>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    0x2e24(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe70(%rip),%rcx
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <_path_set_err@plt>
jmp    12fd <path_is_accessible+0x19d>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe24(%rip),%rcx
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%r8
jmp    12f3 <path_is_accessible+0x193>
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rsi
mov    %r13,%rdi
call   1050 <lstat@plt>
test   %rax,%rax
js     12ce <path_is_accessible+0x16e>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
jne    122e <path_is_accessible+0xce>
lea    0x10(%rsp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     122e <path_is_accessible+0xce>
movb   $0x0,(%rax)
mov    $0x1,%ebp
cmpb   $0x0,0x10(%rsp)
je     12ff <path_is_accessible+0x19f>
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <lstat@plt>
test   %rax,%rax
js     12ce <path_is_accessible+0x16e>
mov    0x8(%rsp),%ebx
mov    %ebx,%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
je     1313 <path_is_accessible+0x1b3>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    0x2d5d(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5c(%rip),%rcx
or     (%rcx),%eax
not    %ebx
test   %ebx,%eax
jne    132e <path_is_accessible+0x1ce>
mov    %r13,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     133e <path_is_accessible+0x1de>
cmp    %r13,%rax
sete   %cl
cmpb   $0x0,0x11(%rsp)
setne  %dl
and    %cl,%dl
movzbl %dl,%ecx
movb   $0x0,(%rax,%rcx,1)
cmpb   $0x0,0x10(%rsp)
jne    1250 <path_is_accessible+0xf0>
jmp    12ff <path_is_accessible+0x19f>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xd6d(%rip),%rcx
lea    0x10(%rsp),%r8
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %eax,%r9d
xor    %eax,%eax
call   1060 <_path_set_err@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ca6(%rip),%rax
mov    (%rax),%eax
mov    0x2ca5(%rip),%rcx
mov    %eax,(%rcx)
lea    0xd39(%rip),%rcx
jmp    1357 <path_is_accessible+0x1f7>
lea    0xd58(%rip),%rcx
lea    0x10(%rsp),%r8
xor    %edi,%edi
jmp    1361 <path_is_accessible+0x201>
mov    0x2c7b(%rip),%rax
mov    (%rax),%eax
mov    0x2c7a(%rip),%rcx
mov    %eax,(%rcx)
lea    0xd63(%rip),%rcx
lea    0x10(%rsp),%r8
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r14,%rdx
jmp    11bb <path_is_accessible+0x5b>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [29 x i8] c"cannot canonicalize \22%s\22: %s\00"
@errno = global i32 0
@ENAMETOOLONG = global i32 0
@.str.1 = [51 x i8] c"cannot canonicalize \22%s\22: exceeded max path length\00"
@.str.2 = [21 x i8] c"cannot stat \22%s\22: %s\00"
@EINVAL = global i32 0
@.str.3 = [40 x i8] c"cannot check \22%s\22: unexpected file type\00"
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
@.str.4 = [45 x i8] c"execute permissions for all required on \22%s\22\00"
@.str.5 = [34 x i8] c"cannot check \22%s\22: internal error\00"
define i32 @path_is_accessible(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca [4096 x i8]
%10 = alloca %struct.stat
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%12 = load i8*, i8** %5
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%14 = call i32 @path_canonicalize(i8* %12, i8* %13, i32 4096)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = load i64, i64* %7
%20 = load i8*, i8** %5
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %18, i64 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %22)
store i32 %23, i32* %4
br label %130
24: ; preds = %3
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = icmp uge i64 %26, 4096
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i32, i32* @ENAMETOOLONG
store i32 %29, i32* @errno
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = load i8*, i8** %5
%33 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %30, i64 %31, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 %33, i32* %4
br label %130
34: ; preds = %24
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%36 = call i64 @lstat(i8* %35, %struct.stat* %10)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = load i64, i64* %7
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%42 = load i32, i32* @errno
%43 = call i32 @strerror(i32 %42)
%44 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %39, i64 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %43)
store i32 %44, i32* %4
br label %130
45: ; preds = %34
%46 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @S_ISDIR(i32 %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %57, label %50
50: ; preds = %45
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%52 = call i8* @strrchr(i8* %51, i8 signext 47)
store i8* %52, i8** %11
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = load i8*, i8** %11
store i8 0, i8* %55
br label %56
56: ; preds = %54, %50
br label %57
57: ; preds = %56, %45
br label %58
58: ; preds = %127, %57
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %129
63: ; preds = %58
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%65 = call i64 @lstat(i8* %64, %struct.stat* %10)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %74
67: ; preds = %63
%68 = load i8*, i8** %6
%69 = load i64, i64* %7
%70 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%71 = load i32, i32* @errno
%72 = call i32 @strerror(i32 %71)
%73 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %68, i64 %69, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %70, i32 %72)
store i32 %73, i32* %4
br label %130
74: ; preds = %63
%75 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i32 @S_ISDIR(i32 %76)
%78 = icmp ne i32 %77, 0
br i1 %78, label %85, label %79
79: ; preds = %74
%80 = load i32, i32* @EINVAL
store i32 %80, i32* @errno
%81 = load i8*, i8** %6
%82 = load i64, i64* %7
%83 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%84 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %81, i64 %82, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %83)
store i32 %84, i32* %4
br label %130
85: ; preds = %74
%86 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%87 = load i32, i32* %86
%88 = load i32, i32* @S_IXUSR
%89 = load i32, i32* @S_IXGRP
%90 = or i32 %88, %89
%91 = load i32, i32* @S_IXOTH
%92 = or i32 %90, %91
%93 = and i32 %87, %92
%94 = load i32, i32* @S_IXUSR
%95 = load i32, i32* @S_IXGRP
%96 = or i32 %94, %95
%97 = load i32, i32* @S_IXOTH
%98 = or i32 %96, %97
%99 = icmp ne i32 %93, %98
br i1 %99, label %100, label %105
100: ; preds = %85
%101 = load i8*, i8** %6
%102 = load i64, i64* %7
%103 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%104 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 0, i8* %101, i64 %102, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %103)
store i32 %104, i32* %4
br label %130
105: ; preds = %85
%106 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%107 = call i8* @strrchr(i8* %106, i8 signext 47)
store i8* %107, i8** %11
%108 = icmp ne i8* %107, null
br i1 %108, label %115, label %109
109: ; preds = %105
%110 = load i32, i32* @EINVAL
store i32 %110, i32* @errno
%111 = load i8*, i8** %6
%112 = load i64, i64* %7
%113 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%114 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %111, i64 %112, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %113)
store i32 %114, i32* %4
br label %130
115: ; preds = %105
%116 = load i8*, i8** %11
%117 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%118 = icmp eq i8* %116, %117
br i1 %118, label %119, label %127
119: ; preds = %115
%120 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 1
%121 = load i8, i8* %120
%122 = sext i8 %121 to i32
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %127
124: ; preds = %119
%125 = load i8*, i8** %11
%126 = getelementptr inbounds i8, i8* %125, i32 1
store i8* %126, i8** %11
br label %127
127: ; preds = %124, %119, %115
%128 = load i8*, i8** %11
store i8 0, i8* %128
br label %58
129: ; preds = %58
store i32 1, i32* %4
br label %130
130: ; preds = %129, %109, %100, %79, %67, %38, %28, %17
%131 = load i32, i32* %4
ret i32 %131
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [29 x i8] c"cannot canonicalize \22%s\22: %s\00"
@errno = global i32 0
@ENAMETOOLONG = global i32 0
@.str.1 = [51 x i8] c"cannot canonicalize \22%s\22: exceeded max path length\00"
@.str.2 = [21 x i8] c"cannot stat \22%s\22: %s\00"
@EINVAL = global i32 0
@.str.3 = [40 x i8] c"cannot check \22%s\22: unexpected file type\00"
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
@.str.4 = [45 x i8] c"execute permissions for all required on \22%s\22\00"
@.str.5 = [34 x i8] c"cannot check \22%s\22: internal error\00"
define i32 @path_is_accessible(i8* %0, i8* %1, i64 %2) {
%4 = alloca [4096 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.stat* %5 to i8*
%8 = call i32 @path_canonicalize(i8* %0, i8* %6, i32 4096)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %1, i64 %2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %12)
br label %79
14: ; preds = %3
%15 = icmp ugt i32 %8, 4095
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = load i32, i32* @ENAMETOOLONG
store i32 %17, i32* @errno
%18 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %1, i64 %2, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %79
19: ; preds = %14
%20 = call i64 @lstat(i8* %6, %struct.stat* %5)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %1, i64 %2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 %24)
br label %79
26: ; preds = %19
%27 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @S_ISDIR(i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = call i8* @strrchr(i8* %6, i8 signext 47)
%33 = icmp eq i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %31
store i8 0, i8* %32
br label %35
35: ; preds = %31, %34, %26
%36 = load i8, i8* %6
%37 = icmp eq i8 %36, 0
br i1 %37, label %79, label %38
38: ; preds = %35
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 1
br label %40
40: ; preds = %38, %70
%41 = call i64 @lstat(i8* %6, %struct.stat* %5)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* @errno
%45 = call i32 @strerror(i32 %44)
%46 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %1, i64 %2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %6, i32 %45)
br label %79
47: ; preds = %40
%48 = load i32, i32* %27
%49 = call i32 @S_ISDIR(i32 %48)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i32, i32* @EINVAL
store i32 %52, i32* @errno
%53 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %1, i64 %2, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %79
54: ; preds = %47
%55 = load i32, i32* @S_IXUSR
%56 = load i32, i32* @S_IXGRP
%57 = or i32 %56, %55
%58 = load i32, i32* @S_IXOTH
%59 = or i32 %57, %58
%60 = and i32 %59, %48
%61 = icmp eq i32 %60, %59
br i1 %61, label %64, label %62
62: ; preds = %54
%63 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 0, i8* %1, i64 %2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %79
64: ; preds = %54
%65 = call i8* @strrchr(i8* %6, i8 signext 47)
%66 = icmp eq i8* %65, null
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load i32, i32* @EINVAL
store i32 %68, i32* @errno
%69 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %1, i64 %2, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %6)
br label %79
70: ; preds = %64
%71 = icmp eq i8* %65, %6
%72 = load i8, i8* %39
%73 = icmp ne i8 %72, 0
%74 = select i1 %71, i1 %73, i1 false
%75 = zext i1 %74 to i64
%76 = getelementptr i8, i8* %65, i64 %75
store i8 0, i8* %76
%77 = load i8, i8* %6
%78 = icmp eq i8 %77, 0
br i1 %78, label %79, label %40
79: ; preds = %70, %35, %67, %62, %51, %43, %22, %16, %10
%80 = phi i32 [ %13, %10 ], [ %18, %16 ], [ %25, %22 ], [ %46, %43 ], [ %63, %62 ], [ %69, %67 ], [ %53, %51 ], [ 1, %35 ], [ 1, %70 ]
ret i32 %80
}