#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_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char);
int /*<<< orphan*/ printf(char *, char *, char *, int /*<<< orphan*/);
char *stderr;
int /*<<< orphan*/ strerror(scalar_t__);
FILE *open_sesame(char *name, char mode) {
  FILE *stream;
  errno = 0;
  stream = fopen(name, mode);
  if (stream == NULL) {
    printf(stderr, "I/O error: Couldn’t open file %s; %s\n", name,
           strerror(errno));
    exit(EXIT_FAILURE);
  } else
    return stream;
}


x86 assembly (clang, -O0):
<open_sesame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    0x2e7f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c5 <open_sesame+0x85>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
lea    0xe4e(%rip),%rsi
call   1030 <printf@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_sesame>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2e89(%rip),%r15
movq   $0x0,(%r15)
call   1040 <fopen@plt>
test   %rax,%rax
je     1166 <open_sesame+0x26>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e73(%rip),%rax
mov    (%rax),%r14
mov    (%r15),%rdi
call   1060 <strerror@plt>
lea    0xe81(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1030 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i8* null
@.str = [40 x i8] c"I/O error: Couldn\E2\80\99t open file %s; %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @open_sesame(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32*
store i8* %0, i8** %3
store i8 %1, i8* %4
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = load i8, i8* %4
%8 = call i32* @fopen(i8* %6, i8 signext %7)
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i8*, i8** @stderr
%13 = load i8*, i8** %3
%14 = load i64, i64* @errno
%15 = call i32 @strerror(i64 %14)
%16 = call i32 @printf(i8* %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i32*, i32** %5
ret i32* %20
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i8* null
@.str = [40 x i8] c"I/O error: Couldn\E2\80\99t open file %s; %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @open_sesame(i8* %0, i8 signext %1) {
store i64 0, i64* @errno
%3 = tail call i32* @fopen(i8* %0, i8 signext %1)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i8*, i8** @stderr
%7 = load i64, i64* @errno
%8 = tail call i32 @strerror(i64 %7)
%9 = tail call i32 @printf(i8* %6, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
ret i32* %3
}