#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__ pid_t;

/* Variables and functions */
int F_OK;
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int X_OK;
int /*<<< orphan*/ abort();
scalar_t__ access(char const *, int);
int /*<<< orphan*/ close(int);
int creat(char const *, int);
int errno;
int /*<<< orphan*/ execl(char *, char *, char *, char const *, char *);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ unlink(char const *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int fd;
  pid_t pid;
  const char *name = argv[1];
  int status;
  fd = creat(name, S_IRWXU | S_IRWXG | S_IRWXO);
  close(fd);
  unlink(name);
  fd = creat(name, S_IRWXU | S_IRWXG | S_IRWXO);
  close(fd);
  if ((pid = fork()) < 0) {
    printf("fork failed\n");
    abort();
  }
  if (pid == 0) {
    execl("/bin/chmod", "chmod", "a-x", name, (char *)NULL);
    printf("Execl exited with error %d\n", errno);
    abort();
  }
  wait(&status);
  if (access(name, F_OK | X_OK) == 0) {
    printf("access shows that x-access to file %s is not removed\n", name);
    abort();
  }
  unlink(name);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    0x2e12(%rip),%rax
or     (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
call   1080 <creat@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x28(%rbp),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    0x2dda(%rip),%rax
or     (%rax),%esi
mov    0x2de9(%rip),%rax
or     (%rax),%esi
call   1080 <creat@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1243 <main+0xb3>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x0,-0x20(%rbp)
jne    128f <main+0xff>
mov    -0x28(%rbp),%rcx
lea    0xdb4(%rip),%rdi
lea    0xdb2(%rip),%rsi
lea    0xdb1(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <execl@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x2c(%rbp),%rdi
call   10a0 <wait@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
mov    0x2d24(%rip),%rax
or     (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    12d6 <main+0x146>
mov    -0x28(%rbp),%rsi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x28(%rbp),%rdi
call   1040 <unlink@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e31(%rip),%r14
mov    0x2e22(%rip),%r15
mov    (%r15),%eax
or     (%r14),%eax
mov    0x8(%rsi),%rbx
mov    0x2e29(%rip),%r12
or     (%r12),%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <creat@plt>
mov    %eax,%edi
call   1070 <close@plt>
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    (%r15),%esi
or     (%r14),%esi
or     (%r12),%esi
mov    %rbx,%rdi
call   1090 <creat@plt>
mov    %eax,%edi
call   1070 <close@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
js     124a <main+0xaa>
je     125d <main+0xbd>
lea    0x4(%rsp),%rdi
call   10b0 <wait@plt>
mov    0x2d94(%rip),%rax
mov    0x2dad(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1080 <access@plt>
test   %rax,%rax
je     129b <main+0xfb>
mov    %rbx,%rdi
call   1040 <unlink@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe10(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xd9c(%rip),%rdi
lea    0xd9a(%rip),%rsi
lea    0xd99(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   10a0 <execl@plt>
mov    0x2d3c(%rip),%rax
mov    (%rax),%esi
lea    0xd82(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xd89(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str = [13 x i8] c"fork failed\0A\00"
@.str.1 = [11 x i8] c"/bin/chmod\00"
@.str.2 = [6 x i8] c"chmod\00"
@.str.3 = [4 x i8] c"a-x\00"
@.str.4 = [28 x i8] c"Execl exited with error %d\0A\00"
@errno = global i32 0
@F_OK = global i32 0
@X_OK = global i32 0
@.str.5 = [54 x i8] c"access shows that x-access to file %s is not removed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = load i32, i32* @S_IRWXU
%15 = load i32, i32* @S_IRWXG
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IRWXO
%18 = or i32 %16, %17
%19 = call i32 @creat(i8* %13, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i32 @close(i32 %20)
%22 = load i8*, i8** %8
%23 = call i32 @unlink(i8* %22)
%24 = load i8*, i8** %8
%25 = load i32, i32* @S_IRWXU
%26 = load i32, i32* @S_IRWXG
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IRWXO
%29 = or i32 %27, %28
%30 = call i32 @creat(i8* %24, i32 %29)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
%33 = call i64 (...) @fork()
store i64 %33, i64* %7
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%37 = call i32 (...) @abort()
unreachable
38: ; preds = %2
%39 = load i64, i64* %7
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i8*, i8** %8
%43 = call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %42, i8* null)
%44 = load i32, i32* @errno
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = call i32 (...) @abort()
unreachable
47: ; preds = %38
%48 = call i32 @wait(i32* %9)
%49 = load i8*, i8** %8
%50 = load i32, i32* @F_OK
%51 = load i32, i32* @X_OK
%52 = or i32 %50, %51
%53 = call i64 @access(i8* %49, i32 %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %47
%56 = load i8*, i8** %8
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = call i32 (...) @abort()
unreachable
59: ; preds = %47
%60 = load i8*, i8** %8
%61 = call i32 @unlink(i8* %60)
ret i32 0
}

LLVM IR (-O2):
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [11 x i8] c"/bin/chmod\00"
@.str.2 = [6 x i8] c"chmod\00"
@.str.3 = [4 x i8] c"a-x\00"
@.str.4 = [28 x i8] c"Execl exited with error %d\0A\00"
@errno = global i32 0
@F_OK = global i32 0
@X_OK = global i32 0
@.str.5 = [54 x i8] c"access shows that x-access to file %s is not removed\0A\00"
@str = [12 x i8] c"fork failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @S_IRWXU
%8 = load i32, i32* @S_IRWXG
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRWXO
%11 = or i32 %9, %10
%12 = tail call i32 @creat(i8* %5, i32 %11)
%13 = tail call i32 @close(i32 %12)
%14 = tail call i32 @unlink(i8* %5)
%15 = load i32, i32* @S_IRWXU
%16 = load i32, i32* @S_IRWXG
%17 = or i32 %16, %15
%18 = load i32, i32* @S_IRWXO
%19 = or i32 %17, %18
%20 = tail call i32 @creat(i8* %5, i32 %19)
%21 = tail call i32 @close(i32 %20)
%22 = tail call i64 (...) @fork()
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%26 = tail call i32 (...) @abort()
unreachable
27: ; preds = %2
%28 = icmp eq i64 %22, 0
br i1 %28, label %29, label %34
29: ; preds = %27
%30 = tail call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* null)
%31 = load i32, i32* @errno
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = tail call i32 (...) @abort()
unreachable
34: ; preds = %27
%35 = call i32 @wait(i32* %3)
%36 = load i32, i32* @F_OK
%37 = load i32, i32* @X_OK
%38 = or i32 %37, %36
%39 = call i64 @access(i8* %5, i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%43 = call i32 (...) @abort()
unreachable
44: ; preds = %34
%45 = call i32 @unlink(i8* %5)
ret i32 0
}