#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int isValidFileName(char *filePath) {
  char tmp[strlen(filePath + 1)];
  strcpy(tmp, filePath);
  struct stat st;
  if (stat(filePath, &st) == -1) {
    if (errno == EACCES) {
      fprintf(stderr, "input file %s cannot be opened - access denies\n",
              filePath);
      exit(1);
    }
    if (errno == ENOENT) {
      fprintf(stderr, "input file %s does not exist\n", filePath);
      exit(1);
    }
  }
  if (S_ISDIR(st.st_mode)) {
    fprintf(stderr, "input file %s is a directory\n", filePath);
    exit(1);
  }
  if (!S_ISREG(st.st_mode)) {
    fprintf(stderr, "input file %s is not in the right format\n", filePath);
    exit(1);
  }
  return 1;
}


x86 assembly (clang, -O0):
<isValidFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    1248 <isValidFileName+0xd8>
mov    0x2e00(%rip),%rax
mov    (%rax),%rax
mov    0x2e0e(%rip),%rcx
cmp    (%rcx),%rax
jne    1206 <isValidFileName+0x96>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe09(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%rax
mov    0x2da9(%rip),%rcx
cmp    (%rcx),%rax
jne    1243 <isValidFileName+0xd3>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdfc(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1248 <isValidFileName+0xd8>
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     127d <isValidFileName+0x10d>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xde0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%edi
call   1080 <S_ISREG@plt>
cmp    $0x0,%eax
jne    12b1 <isValidFileName+0x141>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdca(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    $0x1,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isValidFileName>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
mov    %rsp,%rdi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    -0x18(%rbp),%rsi
mov    %r14,%rdi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    11d5 <isValidFileName+0x65>
mov    0x2e16(%rip),%rax
mov    (%rax),%rax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%rax
je     1221 <isValidFileName+0xb1>
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
je     1233 <isValidFileName+0xc3>
mov    -0x18(%rbp),%ebx
mov    %ebx,%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
jne    11fd <isValidFileName+0x8d>
mov    %ebx,%edi
call   1080 <S_ISREG@plt>
test   %eax,%eax
je     120f <isValidFileName+0x9f>
mov    $0x1,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
jmp    1243 <isValidFileName+0xd3>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
jmp    1243 <isValidFileName+0xd3>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
jmp    1243 <isValidFileName+0xd3>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@EACCES = global i64 0
@stderr = global i32 0
@.str = [48 x i8] c"input file %s cannot be opened - access denies\0A\00"
@ENOENT = global i64 0
@.str.1 = [30 x i8] c"input file %s does not exist\0A\00"
@.str.2 = [30 x i8] c"input file %s is a directory\0A\00"
@.str.3 = [42 x i8] c"input file %s is not in the right format\0A\00"
define i32 @isValidFileName(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.stat
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = call i32 @strlen(i8* %7)
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = load i8*, i8** %2
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @stat(i8* %14, %struct.stat* %5)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %36
17: ; preds = %1
%18 = load i64, i64* @errno
%19 = load i64, i64* @EACCES
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %2
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = load i64, i64* @errno
%28 = load i64, i64* @ENOENT
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %2
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %26
br label %36
36: ; preds = %35, %1
%37 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i64 @S_ISDIR(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %2
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %36
%47 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%48 = load i32, i32* %47
%49 = call i32 @S_ISREG(i32 %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %2
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %46
%57 = load i8*, i8** %3
ret i32 1
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@EACCES = global i64 0
@stderr = global i32 0
@.str = [48 x i8] c"input file %s cannot be opened - access denies\0A\00"
@ENOENT = global i64 0
@.str.1 = [30 x i8] c"input file %s does not exist\0A\00"
@.str.2 = [30 x i8] c"input file %s is a directory\0A\00"
@.str.3 = [42 x i8] c"input file %s is not in the right format\0A\00"
define i32 @isValidFileName(i8* %0) {
%2 = alloca %struct.stat
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = tail call i32 @strlen(i8* %3)
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @strcpy(i8* %6, i8* %0)
%8 = bitcast %struct.stat* %2 to i8*
%9 = call i32 @stat(i8* %0, %struct.stat* %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %26
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @EACCES
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %0)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %12, %20
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19, %1
%27 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%28 = load i32, i32* %27
%29 = call i64 @S_ISDIR(i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %26
%36 = call i32 @S_ISREG(i32 %28)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %35
ret i32 1
}