#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);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
FILE *openFile(FILE *fp, char *fname, char *mode) {
  fp = fopen(fname, mode);
  if (fp == NULL) {
    fprintf(stderr, "Cannot open file %s for %s.\n", fname, mode);
    exit(1);
  }
  fprintf(stderr, "opened %s in mode %s.\n", fname, mode);
  return fp;
}


x86 assembly (clang, -O0):
<openFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1187 <openFile+0x57>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe88(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe7e(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openFile>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
test   %rbx,%rbx
je     1172 <openFile+0x42>
lea    0xebf(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <fprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe87(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Cannot open file %s for %s.\0A\00"
@.str.1 = [23 x i8] c"opened %s in mode %s.\0A\00"
define i32* @openFile(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%7 = load i8*, i8** %5
%8 = load i8*, i8** %6
%9 = call i32* @fopen(i8* %7, i8* %8)
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
%23 = load i32*, i32** %4
ret i32* %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Cannot open file %s for %s.\0A\00"
@.str.1 = [23 x i8] c"opened %s in mode %s.\0A\00"
define noalias i32* @openFile(i32* nocapture readnone %0, i8* %1, i8* %2) {
%4 = tail call i32* @fopen(i8* %1, i8* %2)
%5 = icmp eq i32* %4, null
%6 = load i32, i32* @stderr
br i1 %5, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
ret i32* %4
}