#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*/ FILE;

/* Variables and functions */
int S_IXGRP;
int S_IXUSR;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
int main(int argc, char **argv) {
  if (argc > 1) {
    struct stat sb;
    FILE *fp;
    printf("%s is %s executable for user.\n", argv[1],
           stat(argv[1], &sb) == 0 && sb.st_mode & S_IXUSR ? "" : "not");
    printf("%s is %s executable for group.\n", argv[1],
           stat(argv[1], &sb) == 0 && sb.st_mode & S_IXGRP ? "" : "not");
    printf("Triggering fopen...");
    fp = fopen("argv[1]", "rw");
  } else {
    printf(
        "Proper argument not supplied, please supply a file and try again\n\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1256 <main+0x126>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jne    1194 <main+0x64>
mov    -0x18(%rbp),%eax
mov    0x2e5f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x21(%rbp),%cl
lea    0xe7d(%rip),%rdx
lea    0xefb(%rip),%rax
test   $0x1,%cl
cmovne %rax,%rdx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x31(%rbp)
jne    1202 <main+0xd2>
mov    -0x18(%rbp),%eax
mov    0x2de9(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x31(%rbp),%cl
lea    0xe0f(%rip),%rdx
lea    0xe8d(%rip),%rax
test   $0x1,%cl
cmovne %rax,%rdx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe16(%rip),%rdi
lea    0xe17(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    1264 <main+0x134>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jl     1205 <main+0xc5>
mov    %rsi,%r14
mov    0x8(%rsi),%r15
lea    0x8(%rsp),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <stat@plt>
mov    0x2e74(%rip),%rcx
mov    (%rcx),%ecx
and    0x8(%rsp),%ecx
lea    0xec1(%rip),%rbx
lea    0xe97(%rip),%r13
mov    %r13,%rdx
cmovne %rbx,%rdx
test   %rax,%rax
cmovne %r13,%rdx
lea    0xe63(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r14),%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <stat@plt>
mov    0x2e23(%rip),%rcx
mov    (%rcx),%ecx
and    0x8(%rsp),%ecx
cmove  %r13,%rbx
test   %rax,%rax
cmovne %r13,%rbx
lea    0xe4e(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe60(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1060 <fopen@plt>
jmp    1211 <main+0xd1>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [31 x i8] c"%s is %s executable for user.\0A\00"
@S_IXUSR = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c"not\00"
@.str.3 = [32 x i8] c"%s is %s executable for group.\0A\00"
@S_IXGRP = global i32 0
@.str.4 = [20 x i8] c"Triggering fopen...\00"
@.str.5 = [8 x i8] c"argv[1]\00"
@.str.6 = [3 x i8] c"rw\00"
@.str.7 = [67 x i8] c"Proper argument not supplied, please supply a file and try again\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %51
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @stat(i8* %16, %struct.stat* %6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %10
%20 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* @S_IXUSR
%23 = and i32 %21, %22
%24 = icmp ne i32 %23, 0
br label %25
25: ; preds = %19, %10
%26 = phi i1 [ false, %10 ], [ %24, %19 ]
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @stat(i8* %35, %struct.stat* %6)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %25
%39 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load i32, i32* @S_IXGRP
%42 = and i32 %40, %41
%43 = icmp ne i32 %42, 0
br label %44
44: ; preds = %38, %25
%45 = phi i1 [ false, %25 ], [ %43, %38 ]
%46 = zext i1 %45 to i64
%47 = select i1 %45, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %32, i8* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %50, i32** %7
br label %53
51: ; preds = %2
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.7, i64 0, i64 0))
br label %53
53: ; preds = %51, %44
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [31 x i8] c"%s is %s executable for user.\0A\00"
@S_IXUSR = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [4 x i8] c"not\00"
@.str.3 = [32 x i8] c"%s is %s executable for group.\0A\00"
@S_IXGRP = global i32 0
@.str.4 = [20 x i8] c"Triggering fopen...\00"
@.str.5 = [8 x i8] c"argv[1]\00"
@.str.6 = [3 x i8] c"rw\00"
@str = [66 x i8] c"Proper argument not supplied, please supply a file and try again\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %31
5: ; preds = %2
%6 = bitcast %struct.stat* %3 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i64 @stat(i8* %8, %struct.stat* %3)
%10 = icmp eq i64 %9, 0
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IXUSR
%14 = and i32 %13, %12
%15 = icmp ne i32 %14, 0
%16 = select i1 %10, i1 %15, i1 false
%17 = select i1 %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %17)
%19 = load i8*, i8** %7
%20 = call i64 @stat(i8* %19, %struct.stat* %3)
%21 = icmp eq i64 %20, 0
%22 = load i32, i32* %11
%23 = load i32, i32* @S_IXGRP
%24 = and i32 %23, %22
%25 = icmp ne i32 %24, 0
%26 = select i1 %21, i1 %25, i1 false
%27 = select i1 %26, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %33
31: ; preds = %2
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %31, %5
ret i32 0
}