#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 dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int stat(char *, struct stat *);
int checkFile(char *fileLocation) {
  struct stat buffer;
  int exist = stat(fileLocation, &buffer);
  if (exist != 0) {
    FILE *filewtr;
    printf("%s not found. Creating...\n", fileLocation);
    if ((filewtr = fopen(fileLocation, "w")) != NULL) {
      fclose(filewtr);
      printf("%s created sucessfully\n", fileLocation);
    } else {
      printf("Failed to create file %s\n", fileLocation);
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<checkFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d8 <checkFile+0x98>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11b2 <checkFile+0x72>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
jmp    11d3 <checkFile+0x93>
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <checkFile+0xa4>
jmp    11d8 <checkFile+0x98>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkFile>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %eax,%eax
je     118e <checkFile+0x4e>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1197 <checkFile+0x57>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    0x2e53(%rip),%r14
lea    0xe91(%rip),%rdi
jmp    11a5 <checkFile+0x65>
mov    0x2e43(%rip),%r14
jmp    11ad <checkFile+0x6d>
mov    0x2e42(%rip),%r14
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    (%r14),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [27 x i8] c"%s not found. Creating...\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [24 x i8] c"%s created sucessfully\0A\00"
@.str.3 = [26 x i8] c"Failed to create file %s\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @checkFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @stat(i8* %7, %struct.stat* %4)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %3
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i32*, i32** %6
%19 = call i32 @fclose(i32* %18)
%20 = load i8*, i8** %3
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %26
22: ; preds = %11
%23 = load i8*, i8** %3
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %2
br label %29
26: ; preds = %17
br label %27
27: ; preds = %26, %1
%28 = load i32, i32* @EXIT_SUCCESS
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %22
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [27 x i8] c"%s not found. Creating...\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [24 x i8] c"%s created sucessfully\0A\00"
@.str.3 = [26 x i8] c"Failed to create file %s\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @checkFile(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @fclose(i32* %8)
br label %12
12: ; preds = %6, %10
%13 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), %10 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), %6 ]
%14 = phi i32* [ @EXIT_SUCCESS, %10 ], [ @EXIT_FAILURE, %6 ]
%15 = tail call i32 @printf(i8* %13, i8* %0)
br label %16
16: ; preds = %12, %1
%17 = phi i32* [ @EXIT_SUCCESS, %1 ], [ %14, %12 ]
%18 = load i32, i32* %17
ret i32 %18
}