#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 mode_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISREG(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ fchmod(int, int);
int fileIsExec(char *, int, struct stat *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, ...);
char *realpath(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int execpermfix(const char *name, int noop, bool verbose) {
  int fd = 0;
  struct stat st;
  char *fullname;
  int exec;
  mode_t mode;
  if ((fullname = realpath(name, NULL)) == NULL) {
    fprintf(stderr, "%s: realpath error %s\n", name, strerror(errno));
    return 1;
  }
  if ((fd = open(fullname, O_RDONLY)) < 0) {
    fprintf(stderr, "%s: open error %s\n", fullname, strerror(errno));
    free(fullname);
    return 1;
  }
  if (fstat(fd, &st) != 0) {
    fprintf(stderr, "%s: fstat error %s\n", fullname, strerror(errno));
    free(fullname);
    close(fd);
    return 1;
  }
  if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) {
    if (verbose)
      printf("%s skipped, neither a file nor a directory\n", fullname);
    free(fullname);
    close(fd);
    return 0;
  }
  exec = 0;
  if (S_ISDIR(st.st_mode))
    exec = 1;
  else if (S_ISREG(st.st_mode))
    exec = fileIsExec(fullname, fd, &st);
  if (exec < 0) {
    free(fullname);
    close(fd);
    return -1;
  }
  if (verbose)
    printf("%s: file is %sexecutable\n", name, exec ? "" : "not ");
  mode = st.st_mode;
  if (exec)
    mode |= (mode & 0444) >> 2;
  else
    mode &= ~0111;
  if (mode == st.st_mode) {
    if (verbose)
      printf("%s: %o would not be changed\n", name, st.st_mode);
    free(fullname);
    close(fd);
    return 0;
  }
  if (noop) {
    if (verbose)
      printf("%s: %o would change to %o\n", name, st.st_mode, mode);
    free(fullname);
    close(fd);
    return 0;
  }
  if (fchmod(fd, mode) < 0) {
    fprintf(stderr, "%s: chmod error %s\n", name, strerror(errno));
    free(fullname);
    close(fd);
    return 1;
  }
  if (verbose)
    printf("%s: %o changed to %o\n", name, st.st_mode, mode);
  free(fullname);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<execpermfix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <realpath@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1238 <execpermfix+0x78>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd9(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1579 <execpermfix+0x3b9>
mov    -0x28(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12a3 <execpermfix+0xe3>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd8e(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1579 <execpermfix+0x3b9>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   10e0 <fstat@plt>
cmp    $0x0,%rax
je     130e <execpermfix+0x14e>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xd3e(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1579 <execpermfix+0x3b9>
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    136b <execpermfix+0x1ab>
mov    -0x20(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
jne    136b <execpermfix+0x1ab>
cmpl   $0x0,-0x18(%rbp)
je     134e <execpermfix+0x18e>
mov    -0x28(%rbp),%rsi
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1579 <execpermfix+0x3b9>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1390 <execpermfix+0x1d0>
movl   $0x1,-0x2c(%rbp)
jmp    13ba <execpermfix+0x1fa>
mov    -0x20(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     13b5 <execpermfix+0x1f5>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   10a0 <fileIsExec@plt>
mov    %eax,-0x2c(%rbp)
jmp    13ba <execpermfix+0x1fa>
cmpl   $0x0,-0x2c(%rbp)
jge    13e1 <execpermfix+0x221>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1579 <execpermfix+0x3b9>
cmpl   $0x0,-0x18(%rbp)
je     1415 <execpermfix+0x255>
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%ecx
lea    0xc8b(%rip),%rdx
lea    0xca5(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     143b <execpermfix+0x27b>
mov    -0x30(%rbp),%eax
and    $0x124,%eax
sar    $0x2,%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1444 <execpermfix+0x284>
mov    -0x30(%rbp),%eax
and    $0xffffffb6,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    148c <execpermfix+0x2cc>
cmpl   $0x0,-0x18(%rbp)
je     146f <execpermfix+0x2af>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xc21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1579 <execpermfix+0x3b9>
cmpl   $0x0,-0x14(%rbp)
je     14d5 <execpermfix+0x315>
cmpl   $0x0,-0x18(%rbp)
je     14b8 <execpermfix+0x2f8>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xbf5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1579 <execpermfix+0x3b9>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   10b0 <fchmod@plt>
cmp    $0x0,%rax
jge    153f <execpermfix+0x37f>
mov    0x2ae7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2acb(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xba4(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1579 <execpermfix+0x3b9>
cmpl   $0x0,-0x18(%rbp)
je     1561 <execpermfix+0x3a1>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xb7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execpermfix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbp
xor    %esi,%esi
call   1080 <realpath@plt>
test   %rax,%rax
je     1257 <execpermfix+0x97>
mov    %rax,%rbx
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     128c <execpermfix+0xcc>
mov    %eax,%r14d
mov    %rsp,%rsi
mov    %eax,%edi
call   10e0 <fstat@plt>
test   %rax,%rax
je     12c9 <execpermfix+0x109>
mov    0x2dbf(%rip),%rax
mov    (%rax),%ebp
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xdfa(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0x1,%eax
jmp    141c <execpermfix+0x25c>
mov    0x2d7a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd8b(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    141c <execpermfix+0x25c>
mov    0x2d45(%rip),%rax
mov    (%rax),%ebp
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd6d(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
jmp    141c <execpermfix+0x25c>
mov    (%rsp),%r13d
mov    %r13d,%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
jne    12eb <execpermfix+0x12b>
mov    %r13d,%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     13f4 <execpermfix+0x234>
mov    %r13d,%edi
call   1050 <S_ISDIR@plt>
mov    $0x1,%ecx
test   %rax,%rax
je     1386 <execpermfix+0x1c6>
test   %r15d,%r15d
je     1331 <execpermfix+0x171>
test   %ecx,%ecx
lea    0xd75(%rip),%rax
lea    0xd8f(%rip),%rdx
cmove  %rax,%rdx
lea    0xd49(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
mov    %ecx,%r13d
call   1040 <printf@plt>
mov    %r13d,%ecx
mov    (%rsp),%edx
mov    %edx,%eax
shr    $0x2,%eax
and    $0x49,%eax
or     %edx,%eax
mov    %edx,%r13d
and    $0xffffffb6,%r13d
test   %ecx,%ecx
cmovne %eax,%r13d
cmp    %edx,%r13d
jne    136f <execpermfix+0x1af>
test   %r15d,%r15d
je     140a <execpermfix+0x24a>
lea    0xd29(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    140a <execpermfix+0x24a>
test   %r12d,%r12d
je     13c6 <execpermfix+0x206>
test   %r15d,%r15d
je     140a <execpermfix+0x24a>
lea    0xd22(%rip),%rdi
jmp    13e5 <execpermfix+0x225>
mov    %r13d,%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     142b <execpermfix+0x26b>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   10a0 <fileIsExec@plt>
mov    %eax,%ecx
test   %eax,%eax
jns    1301 <execpermfix+0x141>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0xffffffff,%eax
jmp    141c <execpermfix+0x25c>
mov    %r14d,%edi
mov    %r13d,%esi
call   10b0 <fchmod@plt>
test   %rax,%rax
js     1432 <execpermfix+0x272>
test   %r15d,%r15d
je     140a <execpermfix+0x24a>
mov    (%rsp),%edx
lea    0xcf0(%rip),%rdi
mov    %rbp,%rsi
mov    %r13d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    140a <execpermfix+0x24a>
test   %r15d,%r15d
je     140a <execpermfix+0x24a>
lea    0xc3e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
jmp    1301 <execpermfix+0x141>
mov    0x2b9f(%rip),%rax
mov    (%rax),%r15d
mov    0x2b8d(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xc70(%rip),%rsi
mov    %r15d,%edi
mov    %rbp,%rdx
jmp    1235 <execpermfix+0x75>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"%s: realpath error %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"%s: open error %s\0A\00"
@.str.2 = [20 x i8] c"%s: fstat error %s\0A\00"
@.str.3 = [44 x i8] c"%s skipped, neither a file nor a directory\0A\00"
@.str.4 = [26 x i8] c"%s: file is %sexecutable\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [5 x i8] c"not \00"
@.str.7 = [29 x i8] c"%s: %o would not be changed\0A\00"
@.str.8 = [27 x i8] c"%s: %o would change to %o\0A\00"
@.str.9 = [20 x i8] c"%s: chmod error %s\0A\00"
@.str.10 = [22 x i8] c"%s: %o changed to %o\0A\00"
define i32 @execpermfix(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
%13 = load i8*, i8** %5
%14 = call i8* @realpath(i8* %13, i32* null)
store i8* %14, i8** %10
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %5
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %20)
store i32 1, i32* %4
br label %182
22: ; preds = %3
%23 = load i8*, i8** %10
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %23, i32 %24)
store i32 %25, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %10
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %31)
%33 = load i8*, i8** %10
%34 = call i32 @free(i8* %33)
store i32 1, i32* %4
br label %182
35: ; preds = %22
%36 = load i32, i32* %8
%37 = call i64 @fstat(i32 %36, %struct.stat* %9)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %10
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* %43)
%45 = load i8*, i8** %10
%46 = call i32 @free(i8* %45)
%47 = load i32, i32* %8
%48 = call i32 @close(i32 %47)
store i32 1, i32* %4
br label %182
49: ; preds = %35
%50 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i64 @S_ISDIR(i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %70, label %54
54: ; preds = %49
%55 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i64 @S_ISREG(i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %70, label %59
59: ; preds = %54
%60 = load i32, i32* %7
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i8*, i8** %10
%64 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %62, %59
%66 = load i8*, i8** %10
%67 = call i32 @free(i8* %66)
%68 = load i32, i32* %8
%69 = call i32 @close(i32 %68)
store i32 0, i32* %4
br label %182
70: ; preds = %54, %49
store i32 0, i32* %11
%71 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%72 = load i32, i32* %71
%73 = call i64 @S_ISDIR(i32 %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %70
store i32 1, i32* %11
br label %86
76: ; preds = %70
%77 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%78 = load i32, i32* %77
%79 = call i64 @S_ISREG(i32 %78)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %76
%82 = load i8*, i8** %10
%83 = load i32, i32* %8
%84 = call i32 @fileIsExec(i8* %82, i32 %83, %struct.stat* %9)
store i32 %84, i32* %11
br label %85
85: ; preds = %81, %76
br label %86
86: ; preds = %85, %75
%87 = load i32, i32* %11
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %94
89: ; preds = %86
%90 = load i8*, i8** %10
%91 = call i32 @free(i8* %90)
%92 = load i32, i32* %8
%93 = call i32 @close(i32 %92)
store i32 -1, i32* %4
br label %182
94: ; preds = %86
%95 = load i32, i32* %7
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %104
97: ; preds = %94
%98 = load i8*, i8** %5
%99 = load i32, i32* %11
%100 = icmp ne i32 %99, 0
%101 = zext i1 %100 to i64
%102 = select i1 %100, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0)
%103 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %98, i8* %102)
br label %104
104: ; preds = %97, %94
%105 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%106 = load i32, i32* %105
store i32 %106, i32* %12
%107 = load i32, i32* %11
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %115
109: ; preds = %104
%110 = load i32, i32* %12
%111 = and i32 %110, 292
%112 = ashr i32 %111, 2
%113 = load i32, i32* %12
%114 = or i32 %113, %112
store i32 %114, i32* %12
br label %118
115: ; preds = %104
%116 = load i32, i32* %12
%117 = and i32 %116, -74
store i32 %117, i32* %12
br label %118
118: ; preds = %115, %109
%119 = load i32, i32* %12
%120 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%121 = load i32, i32* %120
%122 = icmp eq i32 %119, %121
br i1 %122, label %123, label %136
123: ; preds = %118
%124 = load i32, i32* %7
%125 = icmp ne i32 %124, 0
br i1 %125, label %126, label %131
126: ; preds = %123
%127 = load i8*, i8** %5
%128 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%129 = load i32, i32* %128
%130 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %127, i32 %129)
br label %131
131: ; preds = %126, %123
%132 = load i8*, i8** %10
%133 = call i32 @free(i8* %132)
%134 = load i32, i32* %8
%135 = call i32 @close(i32 %134)
store i32 0, i32* %4
br label %182
136: ; preds = %118
%137 = load i32, i32* %6
%138 = icmp ne i32 %137, 0
br i1 %138, label %139, label %153
139: ; preds = %136
%140 = load i32, i32* %7
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %148
142: ; preds = %139
%143 = load i8*, i8** %5
%144 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%145 = load i32, i32* %144
%146 = load i32, i32* %12
%147 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %143, i32 %145, i32 %146)
br label %148
148: ; preds = %142, %139
%149 = load i8*, i8** %10
%150 = call i32 @free(i8* %149)
%151 = load i32, i32* %8
%152 = call i32 @close(i32 %151)
store i32 0, i32* %4
br label %182
153: ; preds = %136
%154 = load i32, i32* %8
%155 = load i32, i32* %12
%156 = call i64 @fchmod(i32 %154, i32 %155)
%157 = icmp slt i64 %156, 0
br i1 %157, label %158, label %168
158: ; preds = %153
%159 = load i32, i32* @stderr
%160 = load i8*, i8** %5
%161 = load i32, i32* @errno
%162 = call i8* @strerror(i32 %161)
%163 = call i32 @fprintf(i32 %159, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %160, i8* %162)
%164 = load i8*, i8** %10
%165 = call i32 @free(i8* %164)
%166 = load i32, i32* %8
%167 = call i32 @close(i32 %166)
store i32 1, i32* %4
br label %182
168: ; preds = %153
%169 = load i32, i32* %7
%170 = icmp ne i32 %169, 0
br i1 %170, label %171, label %177
171: ; preds = %168
%172 = load i8*, i8** %5
%173 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%174 = load i32, i32* %173
%175 = load i32, i32* %12
%176 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %172, i32 %174, i32 %175)
br label %177
177: ; preds = %171, %168
%178 = load i8*, i8** %10
%179 = call i32 @free(i8* %178)
%180 = load i32, i32* %8
%181 = call i32 @close(i32 %180)
store i32 0, i32* %4
br label %182
182: ; preds = %177, %158, %148, %131, %89, %65, %39, %27, %16
%183 = load i32, i32* %4
ret i32 %183
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"%s: realpath error %s\0A\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"%s: open error %s\0A\00"
@.str.2 = [20 x i8] c"%s: fstat error %s\0A\00"
@.str.3 = [44 x i8] c"%s skipped, neither a file nor a directory\0A\00"
@.str.4 = [26 x i8] c"%s: file is %sexecutable\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [5 x i8] c"not \00"
@.str.7 = [29 x i8] c"%s: %o would not be changed\0A\00"
@.str.8 = [27 x i8] c"%s: %o would change to %o\0A\00"
@.str.9 = [20 x i8] c"%s: chmod error %s\0A\00"
@.str.10 = [22 x i8] c"%s: %o changed to %o\0A\00"
define i32 @execpermfix(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = tail call i8* @realpath(i8* %0, i32* null)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %11)
br label %107
13: ; preds = %3
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %6, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %20)
%22 = tail call i32 @free(i8* %6)
br label %107
23: ; preds = %13
%24 = call i64 @fstat(i32 %15, %struct.stat* %4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = tail call i8* @strerror(i32 %28)
%30 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* %29)
%31 = tail call i32 @free(i8* %6)
%32 = tail call i32 @close(i32 %15)
br label %107
33: ; preds = %23
%34 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%35 = load i32, i32* %34
%36 = tail call i64 @S_ISDIR(i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %33
%39 = tail call i64 @S_ISREG(i32 %35)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = icmp eq i32 %2, 0
br i1 %42, label %45, label %43
43: ; preds = %41
%44 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %45
45: ; preds = %43, %41
%46 = tail call i32 @free(i8* %6)
%47 = tail call i32 @close(i32 %15)
br label %107
48: ; preds = %38, %33
%49 = tail call i64 @S_ISDIR(i32 %35)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %60
51: ; preds = %48
%52 = tail call i64 @S_ISREG(i32 %35)
%53 = icmp eq i64 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %51
%55 = call i32 @fileIsExec(i8* %6, i32 %15, %struct.stat* %4)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = call i32 @free(i8* %6)
%59 = call i32 @close(i32 %15)
br label %107
60: ; preds = %48, %51, %54
%61 = phi i32 [ %55, %54 ], [ 1, %48 ], [ 0, %51 ]
%62 = icmp eq i32 %2, 0
br i1 %62, label %67, label %63
63: ; preds = %60
%64 = icmp eq i32 %61, 0
%65 = select i1 %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
%66 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %65)
br label %67
67: ; preds = %63, %60
%68 = load i32, i32* %34
%69 = icmp eq i32 %61, 0
%70 = lshr i32 %68, 2
%71 = and i32 %70, 73
%72 = or i32 %71, %68
%73 = and i32 %68, -74
%74 = select i1 %69, i32 %73, i32 %72
%75 = icmp eq i32 %74, %68
br i1 %75, label %76, label %82
76: ; preds = %67
br i1 %62, label %79, label %77
77: ; preds = %76
%78 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %0, i32 %68)
br label %79
79: ; preds = %77, %76
%80 = call i32 @free(i8* %6)
%81 = call i32 @close(i32 %15)
br label %107
82: ; preds = %67
%83 = icmp eq i32 %1, 0
br i1 %83, label %90, label %84
84: ; preds = %82
br i1 %62, label %87, label %85
85: ; preds = %84
%86 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %0, i32 %68, i32 %74)
br label %87
87: ; preds = %85, %84
%88 = call i32 @free(i8* %6)
%89 = call i32 @close(i32 %15)
br label %107
90: ; preds = %82
%91 = call i64 @fchmod(i32 %15, i32 %74)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %100
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = load i32, i32* @errno
%96 = call i8* @strerror(i32 %95)
%97 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i8* %0, i8* %96)
%98 = call i32 @free(i8* %6)
%99 = call i32 @close(i32 %15)
br label %107
100: ; preds = %90
br i1 %62, label %104, label %101
101: ; preds = %100
%102 = load i32, i32* %34
%103 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %0, i32 %102, i32 %74)
br label %104
104: ; preds = %101, %100
%105 = call i32 @free(i8* %6)
%106 = call i32 @close(i32 %15)
br label %107
107: ; preds = %104, %93, %87, %79, %57, %45, %26, %17, %8
%108 = phi i32 [ 1, %8 ], [ 1, %17 ], [ 1, %26 ], [ -1, %57 ], [ 0, %79 ], [ 0, %87 ], [ 1, %93 ], [ 0, %104 ], [ 0, %45 ]
ret i32 %108
}