#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*/ perror(char *);
int /*<<< orphan*/ stderr;
FILE *open_file_or_die(char *file_name, char *mode) {
  FILE *fp = fopen(file_name, mode);
  if (fp == 0) {
    perror("fopen");
    fprintf(stderr, "Couldn't open file \"%s\" for mode \"%s\".\n", file_name,
            mode);
    exit(1);
  }
  return fp;
}


x86 assembly (clang, -O0):
<open_file_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119f <open_file_or_die+0x5f>
lea    0xe8d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe76(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file_or_die>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <fopen@plt>
test   %rax,%rax
je     115c <open_file_or_die+0x1c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe9d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"fopen\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"Couldn't open file \22%s\22 for mode \22%s\22.\0A\00"
define i32* @open_file_or_die(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 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %6, i8* %7)
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32*, i32** %5
ret i32* %19
}

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