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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *getcwd(char *, int);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
extern char *Test_get_file_path(const char *filename) {
  int path_len;
  char *path, cwd[1024 + 1];
  if (getcwd(cwd, 1024) == NULL) {
    printf("Could not get current working directory...\n");
    exit(1);
  }
  path_len = strlen(cwd) + strlen("/data/") + strlen(filename) + 1;
  if ((path = malloc(path_len)) == NULL) {
    printf("Could not allocate file path...\n");
    exit(1);
  }
  strncpy(path, cwd, strlen(cwd));
  strncpy(path + strlen(cwd), "/data/", strlen("/data/"));
  strncpy(path + strlen(cwd) + strlen("/data/"), filename, strlen(filename));
  path[path_len - 1] = '\0';
  return path;
}


x86 assembly (clang, -O0):
<Test_get_file_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1060 <getcwd@plt>
cmp    $0x0,%rax
jne    11a0 <Test_get_file_path+0x40>
lea    0xe6f(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x428(%rbp)
lea    0xe73(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x428(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x424(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x424(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1213 <Test_get_file_path+0xb3>
lea    0xe2f(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x468(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x460(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x468(%rbp),%rdi
mov    -0x460(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x458(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x458(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x450(%rbp)
lea    0xdab(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x450(%rbp),%rdi
mov    %eax,%edx
lea    0xd96(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x448(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x440(%rbp)
lea    0xd5d(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x440(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x438(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x438(%rbp),%rdi
mov    -0x430(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Test_get_file_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%rbp
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   1060 <getcwd@plt>
test   %rax,%rax
je     126c <Test_get_file_path+0x10c>
lea    0x10(%rsp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0xe61(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
add    %ebx,%r15d
mov    %rbp,0x8(%rsp)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    (%rbx,%r15,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1275 <Test_get_file_path+0x115>
mov    %rax,%r13
add    %ebx,%r15d
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
add    %r13,%rbx
lea    0xdfd(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbp
add    %r13,%rbp
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
add    %rbp,%rbx
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movslq %r15d,%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %r13,%rax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb4(%rip),%rdi
jmp    127c <Test_get_file_path+0x11c>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"Could not get current working directory...\0A\00"
@.str.1 = [7 x i8] c"/data/\00"
@.str.2 = [33 x i8] c"Could not allocate file path...\0A\00"
define i8* @Test_get_file_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [1025 x i8]
store i8* %0, i8** %2
%6 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%7 = call i32* @getcwd(i8* %6, i32 1024)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = add nsw i32 %14, %15
%17 = load i8*, i8** %2
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %16, %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %4
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %12
%25 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %12
%28 = load i8*, i8** %4
%29 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%30 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @strncpy(i8* %28, i8* %29, i32 %31)
%33 = load i8*, i8** %4
%34 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @strncpy(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i8*, i8** %4
%41 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
%45 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8*, i8** %2
%49 = load i8*, i8** %2
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @strncpy(i8* %47, i8* %48, i32 %50)
%52 = load i8*, i8** %4
%53 = load i32, i32* %3
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8 0, i8* %56
%57 = load i8*, i8** %4
ret i8* %57
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"/data/\00"
@str = [32 x i8] c"Could not allocate file path...\00"
@str.3 = [43 x i8] c"Could not get current working directory...\00"
define i8* @Test_get_file_path(i8* %0) {
%2 = alloca [1025 x i8]
%3 = getelementptr inbounds [1025 x i8], [1025 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 %6, label %9
6: ; preds = %1
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.3, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = call i32 @strlen(i8* %3)
%11 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = add nsw i32 %11, %10
%13 = call i32 @strlen(i8* %0)
%14 = add nsw i32 %12, %13
%15 = add nsw i32 %14, 1
%16 = call i8* @malloc(i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %9
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %9
%22 = call i32 @strlen(i8* %3)
%23 = call i32 @strncpy(i8* %16, i8* %3, i32 %22)
%24 = call i32 @strlen(i8* %3)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %16, i64 %25
%27 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @strncpy(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @strlen(i8* %3)
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %16, i64 %30
%32 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @strlen(i8* %0)
%36 = call i32 @strncpy(i8* %34, i8* %0, i32 %35)
%37 = sext i32 %14 to i64
%38 = getelementptr inbounds i8, i8* %16, i64 %37
store i8 0, i8* %38
ret i8* %16
}