#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*/ perror(char const *);
int /*<<< orphan*/ *stdout;
FILE *export_open(const char *file) {
  FILE *result;
  if (file == NULL || (file[0] == '-' && file[1] == '\0'))
    return stdout;
  if ((result = fopen(file, "w")) == NULL) {
    perror(file);
    exit(1);
  }
  return result;
}


x86 assembly (clang, -O0):
<export_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1168 <export_open+0x38>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    117b <export_open+0x4b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    117b <export_open+0x4b>
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <export_open+0x84>
mov    -0x10(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ac <export_open+0x7c>
mov    -0x10(%rbp),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_open>:
push   %rbx
test   %rdi,%rdi
je     115a <export_open+0x2a>
mov    %rdi,%rbx
cmpb   $0x2d,(%rdi)
jne    1144 <export_open+0x14>
cmpb   $0x0,0x1(%rbx)
je     115a <export_open+0x2a>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <fopen@plt>
test   %rax,%rax
je     1166 <export_open+0x36>
pop    %rbx
ret
mov    0x2e7f(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stdout = global i32* null
@.str = [2 x i8] c"w\00"
define i32* @export_open(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 45
br i1 %12, label %13, label %21
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13, %1
%20 = load i32*, i32** @stdout
store i32* %20, i32** %2
br label %31
21: ; preds = %13, %7
%22 = load i8*, i8** %3
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %4
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = call i32 @perror(i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i32*, i32** %4
store i32* %30, i32** %2
br label %31
31: ; preds = %29, %19
%32 = load i32*, i32** %2
ret i32* %32
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [2 x i8] c"w\00"
define i32* @export_open(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %10, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 45
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6, %1
%11 = load i32*, i32** @stdout
br label %18
12: ; preds = %6, %3
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @perror(i8* %0)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12, %10
%19 = phi i32* [ %11, %10 ], [ %13, %12 ]
ret i32* %19
}