#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 */
char *Get_Campaign_Filename();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
FILE *Create_Campaign_File() {
  char *filename;
  FILE *camp_file;
  filename = Get_Campaign_Filename();
  if (!filename)
    return NULL;
  camp_file = fopen(filename, "w");
  if (!camp_file)
    printf("Unable to open file %s\n", filename);
  free(filename);
  return camp_file;
}


x86 assembly (clang, -O0):
<Create_Campaign_File>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <Get_Campaign_Filename@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <Create_Campaign_File+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    11ab <Create_Campaign_File+0x6b>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <Create_Campaign_File+0x5a>
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Create_Campaign_File>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <Get_Campaign_Filename@plt>
test   %rax,%rax
je     1184 <Create_Campaign_File+0x44>
mov    %rax,%rbx
lea    0xea3(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    117c <Create_Campaign_File+0x3c>
lea    0xe8e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"Unable to open file %s\0A\00"
define i32* @Create_Campaign_File() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i32*
%4 = call i8* (...) @Get_Campaign_Filename()
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32* null, i32** %1
br label %20
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %8
%17 = load i8*, i8** %2
%18 = call i32 @free(i8* %17)
%19 = load i32*, i32** %3
store i32* %19, i32** %1
br label %20
20: ; preds = %16, %7
%21 = load i32*, i32** %1
ret i32* %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"Unable to open file %s\0A\00"
define noalias i32* @Create_Campaign_File() {
%1 = tail call i8* (...) @Get_Campaign_Filename()
%2 = icmp eq i8* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @free(i8* %1)
br label %10
10: ; preds = %0, %8
%11 = phi i32* [ %4, %8 ], [ null, %0 ]
ret i32* %11
}