#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;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
FILE *open_outputfile(char *filename) {
  FILE *fh;
  printf("INFO: open_outputfile(): going to open output file '%s'\n", filename);
  fh = fopen(filename, "we");
  if (fh == (FILE *)0) {
    printf("FATAL ERROR: open_outputfile(): couldn't open file '%s' for "
           "writing: %s\n",
           filename, strerror(errno));
    printf("             execution aborted.\n");
    exit(EXIT_FAILURE);
  }
  return (fh);
}


x86 assembly (clang, -O0):
<open_outputfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xed0(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c4 <open_outputfile+0x84>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_outputfile>:
push   %rbx
mov    %rdi,%rbx
lea    0xea5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecd(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     117b <open_outputfile+0x2b>
pop    %rbx
ret
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xeac(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"INFO: open_outputfile(): going to open output file '%s'\0A\00"
@.str.1 = [3 x i8] c"we\00"
@.str.2 = [73 x i8] c"FATAL ERROR: open_outputfile(): couldn't open file '%s' for writing: %s\0A\00"
@errno = global i32 0
@.str.3 = [33 x i8] c" execution aborted.\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @open_outputfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %1
%19 = load i32*, i32** %3
ret i32* %19
}

LLVM IR (-O2):
@.str = [57 x i8] c"INFO: open_outputfile(): going to open output file '%s'\0A\00"
@.str.1 = [3 x i8] c"we\00"
@.str.2 = [73 x i8] c"FATAL ERROR: open_outputfile(): couldn't open file '%s' for writing: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@str = [32 x i8] c" execution aborted.\00"
define noalias i32* @open_outputfile(i8* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
ret i32* %3
}