#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
void writeFile(char *fileName) {
  FILE *log;
  log = fopen(fileName, "a");
  if (!log) {
    printf("File opening error.\n");
    exit(1);
  }
  char hello[] = "Hello Writer!\n";
  fprintf(log, "%s", hello);
  fclose(log);
}


x86 assembly (clang, -O0):
<writeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1191 <writeFile+0x41>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0xe7f(%rip),%rax
mov    %rax,-0x1f(%rbp)
mov    0xe7d(%rip),%eax
mov    %eax,-0x17(%rbp)
mov    0xe77(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xe6f(%rip),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1f(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFile>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119e <writeFile+0x4e>
mov    %rax,%rbx
movabs $0xa217265746972,%rax
mov    %rax,0x7(%rsp)
movabs $0x7257206f6c6c6548,%rax
20 57 72
mov    %rax,(%rsp)
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <fclose@plt>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [21 x i8] c"File opening error.\0A\00"
@__const.writeFile.hello = [15 x i8] c"Hello Writer!\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @writeFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [15 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = bitcast [15 x i8]* %4 to i8*
%14 = load i32*, i32** %3
%15 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%16 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %3
%18 = call i32 @fclose(i32* %17)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@__const.writeFile.hello = [15 x i8] c"Hello Writer!\0A\00"
@str = [20 x i8] c"File opening error.\00"
define void @writeFile(i8* nocapture %0) {
%2 = alloca [15 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%10 = call i32 @fputs(i8* %9, i32* %3)
%11 = tail call i32 @fclose(i32* %3)
ret void
}