#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
scalar_t__ S_ISDIR(int);
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int chmod(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ helpAndLeave(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pexit(char *);
int stat(char *, struct stat *);
int main(int argc, char *argv[]) {
  if (argc == 1) {
    helpAndLeave(argv[0], EXIT_FAILURE);
  }
  struct stat info;
  mode_t mode;
  int i;
  for (i = 1; i < argc; ++i) {
    if (stat(argv[i], &info) == -1) {
      pexit("stat");
    }
    mode = info.st_mode;
    mode |= S_IRUSR | S_IRGRP | S_IROTH;
    if (S_ISDIR(info.st_mode)) {
      mode |= S_IXUSR | S_IXGRP | S_IXOTH;
    } else {
      if ((info.st_mode & S_IXUSR) || (info.st_mode & S_IXGRP) ||
          (info.st_mode & S_IXOTH)) {
        mode |= S_IXUSR | S_IXGRP | S_IXOTH;
      }
    }
    if (chmod(argv[i], mode) == -1) {
      pexit("chmod");
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1195 <main+0x35>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndLeave@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d2 <main+0x172>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    11d2 <main+0x72>
lea    0xe33(%rip),%rdi
call   1080 <pexit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    0x2de0(%rip),%rcx
or     (%rcx),%eax
mov    0x2dcf(%rip),%rcx
or     (%rcx),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1231 <main+0xd1>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    0x2dbd(%rip),%rcx
or     (%rcx),%eax
mov    0x2dc4(%rip),%rcx
or     (%rcx),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1296 <main+0x136>
mov    -0x18(%rbp),%eax
mov    0x2da5(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1270 <main+0x110>
mov    -0x18(%rbp),%eax
mov    0x2d88(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1270 <main+0x110>
mov    -0x18(%rbp),%eax
mov    0x2d83(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1291 <main+0x131>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
mov    0x2d58(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5f(%rip),%rcx
or     (%rcx),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1296 <main+0x136>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <chmod@plt>
cmp    $0xffffffff,%eax
jne    12bf <main+0x15f>
lea    0xd4b(%rip),%rdi
call   1080 <pexit@plt>
jmp    12c4 <main+0x164>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119c <main+0x3c>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x1,%edi
jne    118a <main+0x2a>
mov    0x0(%r13),%rdi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
call   1060 <helpAndLeave@plt>
jmp    1265 <main+0x105>
jle    1265 <main+0x105>
mov    %edi,%r15d
mov    $0x1,%r12d
mov    0x2e48(%rip),%r14
jmp    11bd <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12
cmp    %r12,%r15
je     1265 <main+0x105>
mov    0x0(%r13,%r12,8),%rdi
mov    %rsp,%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    11db <main+0x7b>
lea    0xe2a(%rip),%rdi
call   1080 <pexit@plt>
mov    (%rsp),%ebx
mov    0x2dcb(%rip),%rax
mov    (%rax),%ebp
or     %ebx,%ebp
mov    0x2dd8(%rip),%rax
or     (%rax),%ebp
mov    0x2dc7(%rip),%rax
or     (%rax),%ebp
mov    %ebx,%edi
call   1030 <S_ISDIR@plt>
mov    0x2dd7(%rip),%rcx
mov    (%rcx),%ecx
test   %rax,%rax
je     1220 <main+0xc0>
or     %ebp,%ecx
mov    0x2dbf(%rip),%rax
or     (%rax),%ecx
jmp    123a <main+0xda>
nopl   (%rax)
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %ecx,%edx
or     %eax,%edx
test   %ebx,%edx
jne    1236 <main+0xd6>
test   %ebx,(%r14)
je     123f <main+0xdf>
or     %ebp,%ecx
or     %eax,%ecx
or     (%r14),%ecx
mov    %ecx,%ebp
mov    0x0(%r13,%r12,8),%rdi
mov    %ebp,%esi
call   1050 <chmod@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x50>
lea    0xdaa(%rip),%rdi
call   1080 <pexit@plt>
jmp    11b0 <main+0x50>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [5 x i8] c"stat\00"
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
@.str.1 = [6 x i8] c"chmod\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @helpAndLeave(i8* %14, i32 %15)
br label %17
17: ; preds = %11, %2
store i32 1, i32* %8
br label %18
18: ; preds = %93, %17
%19 = load i32, i32* %8
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %96
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @stat(i8* %27, %struct.stat* %6)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %22
%33 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%34 = load i32, i32* %33
store i32 %34, i32* %7
%35 = load i32, i32* @S_IRUSR
%36 = load i32, i32* @S_IRGRP
%37 = or i32 %35, %36
%38 = load i32, i32* @S_IROTH
%39 = or i32 %37, %38
%40 = load i32, i32* %7
%41 = or i32 %40, %39
store i32 %41, i32* %7
%42 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i64 @S_ISDIR(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %32
%47 = load i32, i32* @S_IXUSR
%48 = load i32, i32* @S_IXGRP
%49 = or i32 %47, %48
%50 = load i32, i32* @S_IXOTH
%51 = or i32 %49, %50
%52 = load i32, i32* %7
%53 = or i32 %52, %51
store i32 %53, i32* %7
br label %81
54: ; preds = %32
%55 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%56 = load i32, i32* %55
%57 = load i32, i32* @S_IXUSR
%58 = and i32 %56, %57
%59 = icmp ne i32 %58, 0
br i1 %59, label %72, label %60
60: ; preds = %54
%61 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%62 = load i32, i32* %61
%63 = load i32, i32* @S_IXGRP
%64 = and i32 %62, %63
%65 = icmp ne i32 %64, 0
br i1 %65, label %72, label %66
66: ; preds = %60
%67 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%68 = load i32, i32* %67
%69 = load i32, i32* @S_IXOTH
%70 = and i32 %68, %69
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %80
72: ; preds = %66, %60, %54
%73 = load i32, i32* @S_IXUSR
%74 = load i32, i32* @S_IXGRP
%75 = or i32 %73, %74
%76 = load i32, i32* @S_IXOTH
%77 = or i32 %75, %76
%78 = load i32, i32* %7
%79 = or i32 %78, %77
store i32 %79, i32* %7
br label %80
80: ; preds = %72, %66
br label %81
81: ; preds = %80, %46
%82 = load i8**, i8*** %5
%83 = load i32, i32* %8
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
%87 = load i32, i32* %7
%88 = call i32 @chmod(i8* %86, i32 %87)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %81
%91 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %92
92: ; preds = %90, %81
br label %93
93: ; preds = %92
%94 = load i32, i32* %8
%95 = add nsw i32 %94, 1
store i32 %95, i32* %8
br label %18
96: ; preds = %18
%97 = load i32, i32* @EXIT_SUCCESS
%98 = call i32 @exit(i32 %97)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [5 x i8] c"stat\00"
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@S_IXUSR = global i32 0
@S_IXGRP = global i32 0
@S_IXOTH = global i32 0
@.str.1 = [6 x i8] c"chmod\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @helpAndLeave(i8* %6, i32 %7)
%9 = bitcast %struct.stat* %3 to i8*
br label %67
10: ; preds = %2
%11 = bitcast %struct.stat* %3 to i8*
%12 = icmp sgt i32 %0, 1
br i1 %12, label %13, label %67
13: ; preds = %10
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = zext i32 %0 to i64
br label %16
16: ; preds = %13, %64
%17 = phi i64 [ 1, %13 ], [ %65, %64 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @stat(i8* %19, %struct.stat* %3)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = load i32, i32* %14
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IRGRP
%28 = load i32, i32* @S_IROTH
%29 = or i32 %26, %25
%30 = or i32 %29, %27
%31 = or i32 %30, %28
%32 = tail call i64 @S_ISDIR(i32 %25)
%33 = icmp eq i64 %32, 0
%34 = load i32, i32* @S_IXUSR
br i1 %33, label %41, label %35
35: ; preds = %24
%36 = load i32, i32* @S_IXGRP
%37 = load i32, i32* @S_IXOTH
%38 = or i32 %34, %31
%39 = or i32 %38, %36
%40 = or i32 %39, %37
br label %57
41: ; preds = %24
%42 = and i32 %34, %25
%43 = icmp eq i32 %42, 0
%44 = load i32, i32* @S_IXGRP
%45 = and i32 %44, %25
%46 = icmp eq i32 %45, 0
%47 = select i1 %43, i1 %46, i1 false
br i1 %47, label %48, label %52
48: ; preds = %41
%49 = load i32, i32* @S_IXOTH
%50 = and i32 %49, %25
%51 = icmp eq i32 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %41, %48
%53 = load i32, i32* @S_IXOTH
%54 = or i32 %34, %31
%55 = or i32 %54, %44
%56 = or i32 %55, %53
br label %57
57: ; preds = %48, %52, %35
%58 = phi i32 [ %40, %35 ], [ %56, %52 ], [ %31, %48 ]
%59 = load i8*, i8** %18
%60 = tail call i32 @chmod(i8* %59, i32 %58)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = tail call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %64
64: ; preds = %57, %62
%65 = add nuw nsw i64 %17, 1
%66 = icmp eq i64 %65, %15
br i1 %66, label %67, label %16
67: ; preds = %64, %5, %10
%68 = load i32, i32* @EXIT_SUCCESS
%69 = tail call i32 @exit(i32 %68)
unreachable
}