#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *prepare_output(char **, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
scalar_t__ streq(char *, char *);
FILE *create_output(int dump_only, char *ofn, char **pret, int *child_pid) {
  FILE *output;
  if (dump_only && (ofn == NULL || streq(ofn, "-")))
    output = stdout;
  else if (dump_only && ofn)
    output = fopen(ofn, "w");
  else
    output = prepare_output(pret, ofn, child_pid);
  if (!output)
    fprintf(stderr, "failed to create output.\n");
  return output;
}


x86 assembly (clang, -O0):
<create_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1199 <create_output+0x59>
cmpq   $0x0,-0x10(%rbp)
je     1186 <create_output+0x46>
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1030 <streq@plt>
cmp    $0x0,%rax
je     1199 <create_output+0x59>
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11e1 <create_output+0xa1>
cmpl   $0x0,-0x4(%rbp)
je     11c7 <create_output+0x87>
cmpq   $0x0,-0x10(%rbp)
je     11c7 <create_output+0x87>
mov    -0x10(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    11dc <create_output+0x9c>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <prepare_output@plt>
mov    %rax,-0x28(%rbp)
jmp    11e1 <create_output+0xa1>
cmpq   $0x0,-0x28(%rbp)
jne    1201 <create_output+0xc1>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_output>:
push   %rbx
mov    %rsi,%rbx
test   %edi,%edi
je     1172 <create_output+0x32>
test   %rbx,%rbx
je     1161 <create_output+0x21>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
call   1030 <streq@plt>
test   %rax,%rax
je     1182 <create_output+0x42>
mov    0x2e70(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    11ae <create_output+0x6e>
jmp    1199 <create_output+0x59>
mov    %rdx,%rdi
mov    %rbx,%rsi
mov    %rcx,%rdx
call   1060 <prepare_output@plt>
jmp    1191 <create_output+0x51>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
jne    11ae <create_output+0x6e>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"failed to create output.\0A\00"
define i32* @create_output(i32 %0, i8* %1, i8** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i32* %3, i32** %8
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %4
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = call i64 @streq(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15, %12
%20 = load i32*, i32** @stdout
store i32* %20, i32** %9
br label %36
21: ; preds = %15, %4
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i8*, i8** %6
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %9
br label %35
30: ; preds = %24, %21
%31 = load i8**, i8*** %7
%32 = load i8*, i8** %6
%33 = load i32*, i32** %8
%34 = call i32* @prepare_output(i8** %31, i8* %32, i32* %33)
store i32* %34, i32** %9
br label %35
35: ; preds = %30, %27
br label %36
36: ; preds = %35, %19
%37 = load i32*, i32** %9
%38 = icmp ne i32* %37, null
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %39, %36
%43 = load i32*, i32** %9
ret i32* %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"failed to create output.\0A\00"
define i32* @create_output(i32 %0, i8* %1, i8** %2, i32* %3) {
%5 = icmp eq i32 %0, 0
br i1 %5, label %15, label %6
6: ; preds = %4
%7 = icmp eq i8* %1, null
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = tail call i64 @streq(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8, %6
%12 = load i32*, i32** @stdout
br label %17
13: ; preds = %8
%14 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %17
15: ; preds = %4
%16 = tail call i32* @prepare_output(i8** %2, i8* %1, i32* %3)
br label %17
17: ; preds = %13, %15, %11
%18 = phi i32* [ %12, %11 ], [ %14, %13 ], [ %16, %15 ]
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %20, %17
ret i32* %18
}