#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*/ checkFile(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
int fprintf(int /*<<< orphan*/ *, char *, char *, char *, char *);
int /*<<< orphan*/ getFileLocation(int /*<<< orphan*/);
int writeStory(char *role, char *feature, char *reason) {
  checkFile(getFileLocation(0));
  FILE *fw = fopen(getFileLocation(0), "a");
  int length =
      fprintf(fw, "- [ ] as a %s I can %s so that %s\n", role, feature, reason);
  fclose(fw);
  return length;
}


x86 assembly (clang, -O0):
<writeStory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %edi,%edi
call   1050 <getFileLocation@plt>
mov    %eax,%edi
call   1030 <checkFile@plt>
xor    %edi,%edi
call   1050 <getFileLocation@plt>
mov    %eax,%edi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeStory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %edi,%edi
call   1050 <getFileLocation@plt>
mov    %eax,%edi
call   1030 <checkFile@plt>
xor    %edi,%edi
call   1050 <getFileLocation@plt>
lea    0xe83(%rip),%rsi
mov    %eax,%edi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe74(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <fprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [35 x i8] c"- [ ] as a %s I can %s so that %s\0A\00"
define i32 @writeStory(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = call i32 @getFileLocation(i32 0)
%10 = call i32 @checkFile(i32 %9)
%11 = call i32 @getFileLocation(i32 0)
%12 = call i32* @fopen(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %15, i8* %16)
store i32 %17, i32* %8
%18 = load i32*, i32** %7
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* %8
ret i32 %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [35 x i8] c"- [ ] as a %s I can %s so that %s\0A\00"
define i32 @writeStory(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @getFileLocation(i32 0)
%5 = tail call i32 @checkFile(i32 %4)
%6 = tail call i32 @getFileLocation(i32 0)
%7 = tail call i32* @fopen(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
%9 = tail call i32 @fclose(i32* %7)
ret i32 %8
}