#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
FILE *openoutfile(const char *filename) {
  FILE *F = fopen(filename, "wb");
  if (F == NULL) {
    fprintf(stderr, "Couldn't open output file %s\n", filename);
    perror("Error was ");
    exit(-1);
  };
  return F;
}


x86 assembly (clang, -O0):
<openoutfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119a <openoutfile+0x5a>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1030 <fprintf@plt>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openoutfile>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1157 <openoutfile+0x17>
pop    %rbx
ret
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
lea    0xeab(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Couldn't open output file %s\0A\00"
@.str.2 = [11 x i8] c"Error was \00"
define i32* @openoutfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %1
%15 = load i32*, i32** %3
ret i32* %15
}

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