#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*/ cwd;

/* Variables and functions */
int /*<<< orphan*/ *getcwd(char *, int);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *);
char *getFileLocation(int temp) {
  char cwd[1024];
  if (getcwd(cwd, sizeof(cwd)) != NULL) {
    if (temp == 1) {
      size_t bufferSize = snprintf(NULL, 0, "%s/userstories.tmp", cwd) + 1;
      char *buffer = malloc(bufferSize);
      snprintf(buffer, bufferSize, "%s/userstories.tmp", cwd);
      return buffer;
    }
    size_t bufferSize = snprintf(NULL, 0, "%s/userstories.md", cwd) + 1;
    char *buffer = malloc(bufferSize);
    snprintf(buffer, bufferSize, "%s/userstories.md", cwd);
    return buffer;
  } else {
    perror("getcwd() error");
  }
}


x86 assembly (clang, -O0):
<getFileLocation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%rax
je     1247 <getFileLocation+0x107>
cmpl   $0x1,-0xc(%rbp)
jne    11dd <getFileLocation+0x9d>
lea    -0x410(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
lea    0xe7b(%rip),%rdx
mov    %rsi,%rdi
call   1030 <snprintf@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rdi
mov    -0x418(%rbp),%rsi
lea    -0x410(%rbp),%rcx
lea    0xe38(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x420(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1253 <getFileLocation+0x113>
lea    -0x410(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
lea    0xe24(%rip),%rdx
mov    %rsi,%rdi
call   1030 <snprintf@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x430(%rbp)
mov    -0x430(%rbp),%rdi
mov    -0x428(%rbp),%rsi
lea    -0x410(%rbp),%rcx
lea    0xde1(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x430(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1253 <getFileLocation+0x113>
lea    0xdd7(%rip),%rdi
call   1060 <perror@plt>
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileLocation>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
test   %rax,%rax
je     11bd <getFileLocation+0x7d>
cmp    $0x1,%ebx
jne    1170 <getFileLocation+0x30>
lea    0xe92(%rip),%r14
jmp    1177 <getFileLocation+0x37>
lea    0xe9c(%rip),%r14
mov    %rsp,%r15
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1030 <snprintf@plt>
add    $0x1,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe61(%rip),%rdi
call   1060 <perror@plt>
jmp    11ab <getFileLocation+0x6b>

LLVM IR (-O0):
@.str = [19 x i8] c"%s/userstories.tmp\00"
@.str.1 = [18 x i8] c"%s/userstories.md\00"
@.str.2 = [15 x i8] c"getcwd() error\00"
define i8* @getFileLocation(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store i32 %0, i32* %3
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = call i32* @getcwd(i8* %9, i32 1024)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %39
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%17 = call i32 @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = call i8* @malloc(i64 %20)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = load i64, i64* %5
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%25 = call i32 @snprintf(i8* %22, i64 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %6
store i8* %26, i8** %2
br label %41
27: ; preds = %12
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = call i32 @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
store i64 %31, i64* %7
%32 = load i64, i64* %7
%33 = call i8* @malloc(i64 %32)
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = load i64, i64* %7
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%37 = call i32 @snprintf(i8* %34, i64 %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %8
store i8* %38, i8** %2
br label %41
39: ; preds = %1
%40 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %15, %27, %39
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
@.str = [19 x i8] c"%s/userstories.tmp\00"
@.str.1 = [18 x i8] c"%s/userstories.md\00"
@.str.2 = [15 x i8] c"getcwd() error\00"
define i8* @getFileLocation(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32* @getcwd(i8* %3, i32 1024)
%5 = icmp eq i32* %4, null
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = icmp eq i32 %0, 1
br i1 %7, label %8, label %14
8: ; preds = %6
%9 = call i32 @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %3)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = call i8* @malloc(i64 %11)
%13 = call i32 @snprintf(i8* %12, i64 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %22
14: ; preds = %6
%15 = call i32 @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = call i8* @malloc(i64 %17)
%19 = call i32 @snprintf(i8* %18, i64 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %22
20: ; preds = %1
%21 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %14, %8
%23 = phi i8* [ %12, %8 ], [ %18, %14 ], [ undef, %20 ]
ret i8* %23
}