#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*/ FSETLOCKING_BYCALLER;
int /*<<< orphan*/ __fsetlocking(int /*<<< orphan*/ *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
FILE *openForPrint(char *filename) {
  FILE *outFile;
  if (strcmp(filename, "stdout") == 0)
    outFile = stdout;
  else
    outFile = fopen(filename, "w");
  if (outFile == NULL) {
    fprintf(stderr, "Failure to open output file: %s.  Error number:%d\n",
            filename, errno);
    exit(1);
  }
  __fsetlocking(outFile, FSETLOCKING_BYCALLER);
  return outFile;
}


x86 assembly (clang, -O0):
<openForPrint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1189 <openForPrint+0x39>
mov    0x2e53(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    119d <openForPrint+0x4d>
mov    -0x8(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d4 <openForPrint+0x84>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    0x2e1c(%rip),%rax
mov    (%rax),%ecx
lea    0xe44(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
call   1050 <__fsetlocking@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openForPrint>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     119b <openForPrint+0x4b>
lea    0xe98(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     11aa <openForPrint+0x5a>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <__fsetlocking@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e2e(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    117f <openForPrint+0x2f>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%ecx
lea    0xe46(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"stdout\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"Failure to open output file: %s. Error number:%d\0A\00"
@errno = global i32 0
@FSETLOCKING_BYCALLER = global i32 0
define i32* @openForPrint(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32*, i32** @stdout
store i32* %8, i32** %3
br label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
br label %12
12: ; preds = %9, %7
%13 = load i32*, i32** %3
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %2
%18 = load i32, i32* @errno
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = load i32*, i32** %3
%23 = load i32, i32* @FSETLOCKING_BYCALLER
%24 = call i32 @__fsetlocking(i32* %22, i32 %23)
%25 = load i32*, i32** %3
ret i32* %25
}

LLVM IR (-O2):
@.str = [7 x i8] c"stdout\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"Failure to open output file: %s. Error number:%d\0A\00"
@errno = global i32 0
@FSETLOCKING_BYCALLER = global i32 0
define i32* @openForPrint(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32*, i32** @stdout
br label %8
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %4
%9 = phi i32* [ %5, %4 ], [ %7, %6 ]
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = load i32, i32* @FSETLOCKING_BYCALLER
%18 = tail call i32 @__fsetlocking(i32* %9, i32 %17)
ret i32* %9
}