#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);
char *getenv(char *);
int /*<<< orphan*/ printf(char *);
char *strdup(char *);
int /*<<< orphan*/ strncat(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *build_full_filename(const char *filename) {
  char *tmp;
  char buf[(10000)];
  tmp = getenv("HOME");
  if (tmp == NULL) {
    printf("Please set HOME environnement variable");
    exit(-1);
  }
  strncpy(buf, tmp, (10000));
  strncat(buf, filename, (10000));
  return strdup(buf);
}


x86 assembly (clang, -O0):
<build_full_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2720,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <build_full_filename+0x40>
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    -0x2720(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2710,%edx
call   1040 <strncpy@plt>
lea    -0x2720(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x2710,%edx
call   1060 <strncat@plt>
lea    -0x2720(%rbp),%rdi
call   1080 <strdup@plt>
add    $0x2720,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_full_filename>:
push   %r14
push   %rbx
sub    $0x2718,%rsp
mov    %rdi,%r14
lea    0xe8c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11b4 <build_full_filename+0x54>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x2710,%edx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2710,%edx
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1080 <strdup@plt>
add    $0x2718,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [39 x i8] c"Please set HOME environnement variable\00"
define i8* @build_full_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [10000 x i8]
store i8* %0, i8** %2
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %1
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 10000)
%15 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%16 = load i8*, i8** %2
%17 = call i32 @strncat(i8* %15, i8* %16, i32 10000)
%18 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%19 = call i8* @strdup(i8* %18)
ret i8* %19
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [39 x i8] c"Please set HOME environnement variable\00"
define noalias i8* @build_full_filename(i8* %0) {
%2 = alloca [10000 x i8]
%3 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %1
%10 = call i32 @strncpy(i8* %3, i8* %4, i32 10000)
%11 = call i32 @strncat(i8* %3, i8* %0, i32 10000)
%12 = call i8* @strdup(i8* %3)
ret i8* %12
}