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

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ X_OK;
int access(char *, int /*<<< orphan*/);
int execv(char *, char **);
int /*<<< orphan*/ print_strings(char **, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int run(char *fname, char **args) {
  if (access(fname, F_OK) != -1) {
    if (access(fname, X_OK) != -1) {
      printf("Running command:\n");
      printf("%s ", fname);
      print_strings(args, " ", 1);
      return execv(fname, args);
    } else {
      printf("No executable permission for %s", fname);
      return -1;
    }
  } else {
    printf("File %s doesn't exist\n", fname);
    return -1;
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
je     11ee <run+0xae>
mov    -0x10(%rbp),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0xffffffff,%eax
je     11d0 <run+0x90>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x1,%edx
call   1050 <print_strings@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <execv@plt>
mov    %eax,-0x4(%rbp)
jmp    1207 <run+0xc7>
mov    -0x10(%rbp),%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <run+0xc7>
mov    -0x10(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11c6 <run+0x76>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
cmp    $0xffffffff,%eax
je     11cf <run+0x7f>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe5b(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1060 <print_strings@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <execv@plt>
lea    0xe57(%rip),%rdi
jmp    11d6 <run+0x86>
lea    0xe2e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@F_OK = global i32 0
@X_OK = global i32 0
@.str = [18 x i8] c"Running command:\0A\00"
@.str.1 = [4 x i8] c"%s \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [32 x i8] c"No executable permission for %s\00"
@.str.4 = [23 x i8] c"File %s doesn't exist\0A\00"
define i32 @run(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
store i8* %0, i8** %4
store i8** %1, i8*** %5
%6 = load i8*, i8** %4
%7 = load i32, i32* @F_OK
%8 = call i32 @access(i8* %6, i32 %7)
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %27
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i32, i32* @X_OK
%13 = call i32 @access(i8* %11, i32 %12)
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8**, i8*** %5
%20 = call i32 @print_strings(i8** %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%21 = load i8*, i8** %4
%22 = load i8**, i8*** %5
%23 = call i32 @execv(i8* %21, i8** %22)
store i32 %23, i32* %3
br label %30
24: ; preds = %10
%25 = load i8*, i8** %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %25)
store i32 -1, i32* %3
br label %30
27: ; preds = %2
%28 = load i8*, i8** %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %28)
store i32 -1, i32* %3
br label %30
30: ; preds = %27, %24, %15
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@F_OK = global i32 0
@X_OK = global i32 0
@.str.1 = [4 x i8] c"%s \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [32 x i8] c"No executable permission for %s\00"
@.str.4 = [23 x i8] c"File %s doesn't exist\0A\00"
@str = [17 x i8] c"Running command:\00"
define i32 @run(i8* %0, i8** %1) {
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = load i32, i32* @X_OK
%8 = tail call i32 @access(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = tail call i32 @print_strings(i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%14 = tail call i32 @execv(i8* %0, i8** %1)
br label %19
15: ; preds = %6
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %19
17: ; preds = %2
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %15, %10
%20 = phi i32 [ %14, %10 ], [ -1, %15 ], [ -1, %17 ]
ret i32 %20
}