#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*/ fatal(char *, char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ set_binary_mode(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char const *);
FILE *open_outfile(const char *name) {
  if (strcmp("-", name) == 0) {
    set_binary_mode(stdout);
    return stdout;
  } else {
    FILE *file = fopen(name, "wb");
    if (!file)
      fatal("Failed to open output file '%s'", name);
    return file;
  }
}


x86 assembly (clang, -O0):
<open_outfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1188 <open_outfile+0x48>
mov    0x2e73(%rip),%rax
mov    (%rax),%rdi
call   1050 <set_binary_mode@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11bf <open_outfile+0x7f>
mov    -0x10(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b7 <open_outfile+0x77>
mov    -0x10(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1060 <fatal@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_outfile>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116e <open_outfile+0x2e>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     1182 <open_outfile+0x42>
pop    %rbx
ret
mov    0x2e6b(%rip),%rbx
mov    (%rbx),%rdi
call   1050 <set_binary_mode@plt>
mov    (%rbx),%rax
pop    %rbx
ret
lea    0xe7c(%rip),%rdi
mov    %rbx,%rsi
call   1060 <fatal@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [32 x i8] c"Failed to open output file '%s'\00"
define i32* @open_outfile(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32*, i32** @stdout
%10 = call i32 @set_binary_mode(i32* %9)
%11 = load i32*, i32** @stdout
store i32* %11, i32** %2
br label %22
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %4
%15 = load i32*, i32** %4
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = call i32 @fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %12
%21 = load i32*, i32** %4
store i32* %21, i32** %2
br label %22
22: ; preds = %20, %8
%23 = load i32*, i32** %2
ret i32* %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [32 x i8] c"Failed to open output file '%s'\00"
define i32* @open_outfile(i8* %0) {
%2 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32*, i32** @stdout
%6 = tail call i32 @set_binary_mode(i32* %5)
%7 = load i32*, i32** @stdout
br label %13
8: ; preds = %1
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %8, %11, %4
%14 = phi i32* [ %7, %4 ], [ null, %11 ], [ %9, %8 ]
ret i32* %14
}