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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fexists(char const *);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
FILE *getFile(const char *fname, const char *mode) {
  if (fexists(fname)) {
    fprintf(stderr, "\t-> File exists: %s exiting... Terminate\n", fname);
    exit(0);
  }
  FILE *fp = NULL;
  if (NULL == (fp = fopen(fname, mode))) {
    fprintf(stderr, "\t-> Error opening File handle for file:%s\n", fname);
    exit(0);
  }
  return fp;
}


x86 assembly (clang, -O0):
<getFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fexists@plt>
cmp    $0x0,%rax
je     1183 <getFile+0x43>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11ca <getFile+0x8a>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFile>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <fexists@plt>
test   %rax,%rax
jne    116c <getFile+0x2c>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117e <getFile+0x3e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
jmp    118e <getFile+0x4e>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"\09-> File exists: %s exiting... Terminate\0A\00"
@.str.1 = [43 x i8] c"\09-> Error opening File handle for file:%s\0A\00"
define i32* @getFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i64 @fexists(i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
store i32* null, i32** %5
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i32* @fopen(i8* %15, i8* %16)
store i32* %17, i32** %5
%18 = icmp eq i32* null, %17
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %3
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %14
%25 = load i32*, i32** %5
ret i32* %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"\09-> File exists: %s exiting... Terminate\0A\00"
@.str.1 = [43 x i8] c"\09-> Error opening File handle for file:%s\0A\00"
define noalias i32* @getFile(i8* %0, i8* nocapture %1) {
%3 = tail call i64 @fexists(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = tail call i32* @fopen(i8* %0, i8* %1)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %9
ret i32* %10
}