#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 scalar_t__ uid_t;
struct stat {
  int st_mode;
  scalar_t__ st_uid;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENAMETOOLONG;
int /*<<< orphan*/ S_ISDIR(int);
int S_ISVTX;
int S_IWGRP;
int S_IWOTH;
int _path_set_err(int, char *, size_t, char *, char const *, ...);
int /*<<< orphan*/ errno;
scalar_t__ geteuid();
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_secure(const char *path, char *errbuf, size_t errbuflen) {
  int n;
  char buf[4096];
  struct stat st;
  char *p;
  uid_t euid;
  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';
    }
  }
  euid = geteuid();
  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_uid != 0) && (st.st_uid != euid)) {
      return (_path_set_err(0, errbuf, errbuflen, "invalid ownership of \"%s\"",
                            buf));
    }
    if ((st.st_mode & S_IWGRP) && !(st.st_mode & S_ISVTX)) {
      return (_path_set_err(0, errbuf, errbuflen,
                            "group-writable permissions set on \"%s\"", buf));
    }
    if ((st.st_mode & S_IWOTH) && !(st.st_mode & S_ISVTX)) {
      return (_path_set_err(0, errbuf, errbuflen,
                            "world-writable permissions set 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_secure>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10a0,%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   1080 <path_canonicalize@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    120b <path_is_secure+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1068(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1058(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1068(%rbp),%rsi
mov    -0x1060(%rbp),%rdx
mov    -0x1058(%rbp),%r8
mov    %eax,%r9d
mov    $0xffffffff,%edi
lea    0xe04(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
movslq -0x24(%rbp),%rax
cmp    $0x1000,%rax
jb     1254 <path_is_secure+0xe4>
mov    0x2d9e(%rip),%rax
mov    (%rax),%ecx
mov    0x2da5(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%r8
mov    $0xffffffff,%edi
lea    0xdd8(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
lea    -0x1030(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
call   1060 <lstat@plt>
cmp    $0x0,%rax
jge    12d6 <path_is_secure+0x166>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1080(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1078(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1070(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1080(%rbp),%rsi
mov    -0x1078(%rbp),%rdx
mov    -0x1070(%rbp),%r8
mov    %eax,%r9d
mov    $0xffffffff,%edi
lea    0xd89(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
mov    -0x1040(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    131b <path_is_secure+0x1ab>
lea    -0x1030(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x1048(%rbp)
cmp    $0x0,%rax
je     1316 <path_is_secure+0x1a6>
mov    -0x1048(%rbp),%rax
movb   $0x0,(%rax)
jmp    131b <path_is_secure+0x1ab>
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %rax,-0x1050(%rbp)
movsbl -0x1030(%rbp),%eax
cmp    $0x0,%eax
je     15a8 <path_is_secure+0x438>
lea    -0x1030(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
call   1060 <lstat@plt>
cmp    $0x0,%rax
jge    13bb <path_is_secure+0x24b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1098(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1090(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1088(%rbp)
mov    0x2c4f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1098(%rbp),%rsi
mov    -0x1090(%rbp),%rdx
mov    -0x1088(%rbp),%r8
mov    %eax,%r9d
mov    $0xffffffff,%edi
lea    0xca4(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
mov    -0x1040(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    140b <path_is_secure+0x29b>
mov    0x2bf2(%rip),%rax
mov    (%rax),%ecx
mov    0x2bf1(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%r8
mov    $0xffffffff,%edi
lea    0xc69(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
cmpq   $0x0,-0x1038(%rbp)
je     1454 <path_is_secure+0x2e4>
mov    -0x1038(%rbp),%rax
cmp    -0x1050(%rbp),%rax
je     1454 <path_is_secure+0x2e4>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%r8
xor    %edi,%edi
lea    0xc48(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
mov    -0x1040(%rbp),%eax
mov    0x2b7f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14ab <path_is_secure+0x33b>
mov    -0x1040(%rbp),%eax
mov    0x2b6f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    14ab <path_is_secure+0x33b>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%r8
xor    %edi,%edi
lea    0xc0b(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
mov    -0x1040(%rbp),%eax
mov    0x2af8(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1502 <path_is_secure+0x392>
mov    -0x1040(%rbp),%eax
mov    0x2b18(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1502 <path_is_secure+0x392>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%r8
xor    %edi,%edi
lea    0xbdb(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
lea    -0x1030(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x1048(%rbp)
cmp    $0x0,%rax
jne    1560 <path_is_secure+0x3f0>
mov    0x2a9d(%rip),%rax
mov    (%rax),%ecx
mov    0x2a9c(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x1030(%rbp),%r8
mov    $0xffffffff,%edi
lea    0xba4(%rip),%rcx
mov    $0x0,%al
call   1070 <_path_set_err@plt>
mov    %eax,-0x4(%rbp)
jmp    15af <path_is_secure+0x43f>
mov    -0x1048(%rbp),%rax
lea    -0x1030(%rbp),%rcx
cmp    %rcx,%rax
jne    1599 <path_is_secure+0x429>
movsbl -0x102f(%rbp),%eax
cmp    $0x0,%eax
je     1599 <path_is_secure+0x429>
mov    -0x1048(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1048(%rbp)
mov    -0x1048(%rbp),%rax
movb   $0x0,(%rax)
jmp    1329 <path_is_secure+0x1b9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_is_secure>:
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   1080 <path_canonicalize@plt>
test   %eax,%eax
js     11d0 <path_is_secure+0x60>
cmp    $0x1000,%eax
jb     11f8 <path_is_secure+0x88>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    0x2e1c(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe60(%rip),%rcx
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%r8
jmp    1393 <path_is_secure+0x223>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe1b(%rip),%rcx
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%r8
jmp    1321 <path_is_secure+0x1b1>
lea    0x10(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <lstat@plt>
test   %rax,%rax
js     12fc <path_is_secure+0x18c>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
jne    1234 <path_is_secure+0xc4>
lea    0x10(%rsp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1234 <path_is_secure+0xc4>
movb   $0x0,(%rax)
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    $0x1,%ebp
cmpb   $0x0,0x10(%rsp)
je     139c <path_is_secure+0x22c>
mov    %rax,%r12
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %rsp,%rsi
call   1060 <lstat@plt>
test   %rax,%rax
js     12fc <path_is_secure+0x18c>
mov    (%rsp),%r13d
mov    %r13d,%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
je     132d <path_is_secure+0x1bd>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     128b <path_is_secure+0x11b>
cmp    %r12,%rax
jne    1348 <path_is_secure+0x1d8>
mov    0x2d4e(%rip),%rax
test   %r13d,(%rax)
je     12a7 <path_is_secure+0x137>
mov    0x2d4a(%rip),%rax
test   %r13d,(%rax)
je     1376 <path_is_secure+0x206>
mov    0x2d02(%rip),%rax
test   %r13d,(%rax)
je     12c3 <path_is_secure+0x153>
mov    0x2d2e(%rip),%rax
test   %r13d,(%rax)
je     137f <path_is_secure+0x20f>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1351 <path_is_secure+0x1e1>
cmp    %rbx,%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_secure+0xe0>
jmp    139c <path_is_secure+0x22c>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd3f(%rip),%rcx
lea    0x10(%rsp),%r8
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %eax,%r9d
xor    %eax,%eax
call   1070 <_path_set_err@plt>
jmp    139a <path_is_secure+0x22a>
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
mov    0x2c93(%rip),%rcx
mov    %eax,(%rcx)
lea    0xd1f(%rip),%rcx
jmp    136a <path_is_secure+0x1fa>
lea    0xd3e(%rip),%rcx
jmp    1386 <path_is_secure+0x216>
mov    0x2c70(%rip),%rax
mov    (%rax),%eax
mov    0x2c6f(%rip),%rcx
mov    %eax,(%rcx)
lea    0xd8b(%rip),%rcx
lea    0x10(%rsp),%r8
mov    $0xffffffff,%edi
jmp    138d <path_is_secure+0x21d>
lea    0xd2a(%rip),%rcx
jmp    1386 <path_is_secure+0x216>
lea    0xd48(%rip),%rcx
lea    0x10(%rsp),%r8
xor    %edi,%edi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <_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

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@.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"
@.str.4 = [26 x i8] c"invalid ownership of \22%s\22\00"
@S_IWGRP = global i32 0
@S_ISVTX = global i32 0
@.str.5 = [39 x i8] c"group-writable permissions set on \22%s\22\00"
@S_IWOTH = global i32 0
@.str.6 = [39 x i8] c"world-writable permissions set on \22%s\22\00"
@.str.7 = [34 x i8] c"cannot check \22%s\22: internal error\00"
define i32 @path_is_secure(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*
%12 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%13 = load i8*, i8** %5
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%15 = call i32 @path_canonicalize(i8* %13, i8* %14, i32 4096)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %3
%19 = load i8*, i8** %6
%20 = load i64, i64* %7
%21 = load i8*, i8** %5
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %19, i64 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %23)
store i32 %24, i32* %4
br label %160
25: ; preds = %3
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = icmp uge i64 %27, 4096
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i32, i32* @ENAMETOOLONG
store i32 %30, i32* @errno
%31 = load i8*, i8** %6
%32 = load i64, i64* %7
%33 = load i8*, i8** %5
%34 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %31, i64 %32, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i32 %34, i32* %4
br label %160
35: ; preds = %25
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%37 = call i64 @lstat(i8* %36, %struct.stat* %10)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = load i64, i64* %7
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%43 = load i32, i32* @errno
%44 = call i32 @strerror(i32 %43)
%45 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %40, i64 %41, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %42, i32 %44)
store i32 %45, i32* %4
br label %160
46: ; preds = %35
%47 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @S_ISDIR(i32 %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %58, label %51
51: ; preds = %46
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%53 = call i8* @strrchr(i8* %52, i8 signext 47)
store i8* %53, i8** %11
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = load i8*, i8** %11
store i8 0, i8* %56
br label %57
57: ; preds = %55, %51
br label %58
58: ; preds = %57, %46
%59 = call i64 (...) @geteuid()
store i64 %59, i64* %12
br label %60
60: ; preds = %157, %58
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %159
65: ; preds = %60
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%67 = call i64 @lstat(i8* %66, %struct.stat* %10)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %65
%70 = load i8*, i8** %6
%71 = load i64, i64* %7
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%73 = load i32, i32* @errno
%74 = call i32 @strerror(i32 %73)
%75 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %70, i64 %71, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %72, i32 %74)
store i32 %75, i32* %4
br label %160
76: ; preds = %65
%77 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%78 = load i32, i32* %77
%79 = call i32 @S_ISDIR(i32 %78)
%80 = icmp ne i32 %79, 0
br i1 %80, label %87, label %81
81: ; preds = %76
%82 = load i32, i32* @EINVAL
store i32 %82, i32* @errno
%83 = load i8*, i8** %6
%84 = load i64, i64* %7
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%86 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %83, i64 %84, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %85)
store i32 %86, i32* %4
br label %160
87: ; preds = %76
%88 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%89 = load i64, i64* %88
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %101
91: ; preds = %87
%92 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%93 = load i64, i64* %92
%94 = load i64, i64* %12
%95 = icmp ne i64 %93, %94
br i1 %95, label %96, label %101
96: ; preds = %91
%97 = load i8*, i8** %6
%98 = load i64, i64* %7
%99 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%100 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 0, i8* %97, i64 %98, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %99)
store i32 %100, i32* %4
br label %160
101: ; preds = %91, %87
%102 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%103 = load i32, i32* %102
%104 = load i32, i32* @S_IWGRP
%105 = and i32 %103, %104
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %118
107: ; preds = %101
%108 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%109 = load i32, i32* %108
%110 = load i32, i32* @S_ISVTX
%111 = and i32 %109, %110
%112 = icmp ne i32 %111, 0
br i1 %112, label %118, label %113
113: ; preds = %107
%114 = load i8*, i8** %6
%115 = load i64, i64* %7
%116 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%117 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 0, i8* %114, i64 %115, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %116)
store i32 %117, i32* %4
br label %160
118: ; preds = %107, %101
%119 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%120 = load i32, i32* %119
%121 = load i32, i32* @S_IWOTH
%122 = and i32 %120, %121
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %135
124: ; preds = %118
%125 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%126 = load i32, i32* %125
%127 = load i32, i32* @S_ISVTX
%128 = and i32 %126, %127
%129 = icmp ne i32 %128, 0
br i1 %129, label %135, label %130
130: ; preds = %124
%131 = load i8*, i8** %6
%132 = load i64, i64* %7
%133 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%134 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 0, i8* %131, i64 %132, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %133)
store i32 %134, i32* %4
br label %160
135: ; preds = %124, %118
%136 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%137 = call i8* @strrchr(i8* %136, i8 signext 47)
store i8* %137, i8** %11
%138 = icmp ne i8* %137, null
br i1 %138, label %145, label %139
139: ; preds = %135
%140 = load i32, i32* @EINVAL
store i32 %140, i32* @errno
%141 = load i8*, i8** %6
%142 = load i64, i64* %7
%143 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%144 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 -1, i8* %141, i64 %142, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %143)
store i32 %144, i32* %4
br label %160
145: ; preds = %135
%146 = load i8*, i8** %11
%147 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%148 = icmp eq i8* %146, %147
br i1 %148, label %149, label %157
149: ; preds = %145
%150 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 1
%151 = load i8, i8* %150
%152 = sext i8 %151 to i32
%153 = icmp ne i32 %152, 0
br i1 %153, label %154, label %157
154: ; preds = %149
%155 = load i8*, i8** %11
%156 = getelementptr inbounds i8, i8* %155, i32 1
store i8* %156, i8** %11
br label %157
157: ; preds = %154, %149, %145
%158 = load i8*, i8** %11
store i8 0, i8* %158
br label %60
159: ; preds = %60
store i32 1, i32* %4
br label %160
160: ; preds = %159, %139, %130, %113, %96, %81, %69, %39, %29, %18
%161 = load i32, i32* %4
ret i32 %161
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@.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"
@.str.4 = [26 x i8] c"invalid ownership of \22%s\22\00"
@S_IWGRP = global i32 0
@S_ISVTX = global i32 0
@.str.5 = [39 x i8] c"group-writable permissions set on \22%s\22\00"
@S_IWOTH = global i32 0
@.str.6 = [39 x i8] c"world-writable permissions set on \22%s\22\00"
@.str.7 = [34 x i8] c"cannot check \22%s\22: internal error\00"
define i32 @path_is_secure(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 %98
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 %98
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 %98
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 = call i64 (...) @geteuid()
%37 = load i8, i8* %6
%38 = icmp eq i8 %37, 0
br i1 %38, label %98, label %39
39: ; preds = %35
%40 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 1
br label %42
42: ; preds = %39, %89
%43 = call i64 @lstat(i8* %6, %struct.stat* %5)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* @errno
%47 = call i32 @strerror(i32 %46)
%48 = 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 %47)
br label %98
49: ; preds = %42
%50 = load i32, i32* %27
%51 = call i32 @S_ISDIR(i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* @EINVAL
store i32 %54, i32* @errno
%55 = 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 %98
56: ; preds = %49
%57 = load i64, i64* %40
%58 = icmp eq i64 %57, 0
%59 = icmp eq i64 %57, %36
%60 = select i1 %58, i1 true, i1 %59
br i1 %60, label %63, label %61
61: ; preds = %56
%62 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 0, i8* %1, i64 %2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %98
63: ; preds = %56
%64 = load i32, i32* @S_IWGRP
%65 = and i32 %64, %50
%66 = icmp eq i32 %65, 0
br i1 %66, label %73, label %67
67: ; preds = %63
%68 = load i32, i32* @S_ISVTX
%69 = and i32 %68, %50
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 0, i8* %1, i64 %2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %6)
br label %98
73: ; preds = %67, %63
%74 = load i32, i32* @S_IWOTH
%75 = and i32 %74, %50
%76 = icmp eq i32 %75, 0
br i1 %76, label %83, label %77
77: ; preds = %73
%78 = load i32, i32* @S_ISVTX
%79 = and i32 %78, %50
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %77
%82 = call i32 (i32, i8*, i64, i8*, i8*, ...) @_path_set_err(i32 0, i8* %1, i64 %2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %6)
br label %98
83: ; preds = %77, %73
%84 = call i8* @strrchr(i8* %6, i8 signext 47)
%85 = icmp eq i8* %84, null
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32, i32* @EINVAL
store i32 %87, i32* @errno
%88 = 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.7, i64 0, i64 0), i8* %6)
br label %98
89: ; preds = %83
%90 = icmp eq i8* %84, %6
%91 = load i8, i8* %41
%92 = icmp ne i8 %91, 0
%93 = select i1 %90, i1 %92, i1 false
%94 = zext i1 %93 to i64
%95 = getelementptr i8, i8* %84, i64 %94
store i8 0, i8* %95
%96 = load i8, i8* %6
%97 = icmp eq i8 %96, 0
br i1 %97, label %98, label %42
98: ; preds = %89, %35, %86, %81, %71, %61, %53, %45, %22, %16, %10
%99 = phi i32 [ %13, %10 ], [ %18, %16 ], [ %25, %22 ], [ %48, %45 ], [ %62, %61 ], [ %88, %86 ], [ %82, %81 ], [ %72, %71 ], [ %55, %53 ], [ 1, %35 ], [ 1, %89 ]
ret i32 %99
}