#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);
scalar_t__ fileExists(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
FILE *openIfAppropriate(char *fn, int wantFile, int overwrite) {
  FILE *fd = NULL;
  if (wantFile) {
    if (fileExists(fn) && !overwrite) {
      fprintf(stderr, "output file '%s' exists, will not overwrite.\n", fn);
      exit(-1);
    }
    fd = fopen(fn, "w");
  }
  return fd;
}


x86 assembly (clang, -O0):
<openIfAppropriate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b8 <openIfAppropriate+0x78>
mov    -0x8(%rbp),%rdi
call   1030 <fileExists@plt>
cmp    $0x0,%rax
je     11a4 <openIfAppropriate+0x64>
cmpl   $0x0,-0x10(%rbp)
jne    11a4 <openIfAppropriate+0x64>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe6b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openIfAppropriate>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
je     116f <openIfAppropriate+0x2f>
mov    %edx,%ebp
mov    %rdi,%rbx
call   1030 <fileExists@plt>
test   %ebp,%ebp
jne    115a <openIfAppropriate+0x1a>
test   %rax,%rax
jne    1178 <openIfAppropriate+0x38>
lea    0xecd(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fopen@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"output file '%s' exists, will not overwrite.\0A\00"
@.str.1 = [2 x i8] c"w\00"
define i32* @openIfAppropriate(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32* null, i32** %7
%8 = load i32, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i64 @fileExists(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %4
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %14, %10
%23 = load i8*, i8** %4
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %7
br label %25
25: ; preds = %22, %3
%26 = load i32*, i32** %7
ret i32* %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"output file '%s' exists, will not overwrite.\0A\00"
@.str.1 = [2 x i8] c"w\00"
define noalias i32* @openIfAppropriate(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = tail call i64 @fileExists(i8* %0)
%7 = icmp eq i64 %6, 0
%8 = icmp ne i32 %2, 0
%9 = or i1 %8, %7
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %5
%15 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
%17 = phi i32* [ %15, %14 ], [ null, %3 ]
ret i32* %17
}