#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int writeFile(int /*<<< orphan*/ *);
int writeFileWithName(const char *OutputName) {
  int RetVal;
  FILE *OutputFile;
  if (!OutputName || !OutputName[0])
    return -1;
  OutputFile = fopen(OutputName, "a");
  if (!OutputFile)
    return -1;
  RetVal = writeFile(OutputFile);
  fclose(OutputFile);
  return RetVal;
}


x86 assembly (clang, -O0):
<writeFileWithName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1154 <writeFileWithName+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1160 <writeFileWithName+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <writeFileWithName+0x76>
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <writeFileWithName+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <writeFileWithName+0x76>
mov    -0x20(%rbp),%rdi
call   1040 <writeFile@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFileWithName>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     1167 <writeFileWithName+0x37>
cmpb   $0x0,(%rdi)
je     1167 <writeFileWithName+0x37>
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1167 <writeFileWithName+0x37>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <writeFile@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    116c <writeFileWithName+0x3c>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
define i32 @writeFileWithName(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %8, %1
store i32 -1, i32* %2
br label %26
14: ; preds = %8
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %5
%17 = load i32*, i32** %5
%18 = icmp ne i32* %17, null
br i1 %18, label %20, label %19
19: ; preds = %14
store i32 -1, i32* %2
br label %26
20: ; preds = %14
%21 = load i32*, i32** %5
%22 = call i32 @writeFile(i32* %21)
store i32 %22, i32* %4
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %26
26: ; preds = %20, %19, %13
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
define i32 @writeFileWithName(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @writeFile(i32* %7)
%11 = tail call i32 @fclose(i32* %7)
br label %12
12: ; preds = %6, %1, %3, %9
%13 = phi i32 [ %10, %9 ], [ -1, %3 ], [ -1, %1 ], [ -1, %6 ]
ret i32 %13
}