#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 */
char *GetHomeDir();
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *PrependHome(const char *filename, char *buf, int buflen) {
  const char *homedir;
  int home_len, file_len;
  homedir = GetHomeDir();
  home_len = strlen(homedir);
  file_len = strlen(filename);
  if ((home_len + 1 + file_len) >= buflen) {
    buf[0] = '\0';
  } else {
    strcpy(buf, homedir);
    strcat(buf, "/");
    strcat(buf, filename);
  }
  return buf;
}


x86 assembly (clang, -O0):
<PrependHome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1050 <GetHomeDir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
add    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1194 <PrependHome+0x54>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11be <PrependHome+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrependHome>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <GetHomeDir@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %ebp,%eax
add    $0x1,%eax
cmp    %r12d,%eax
jge    119e <PrependHome+0x5e>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
jmp    11a1 <PrependHome+0x61>
movb   $0x0,(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @PrependHome(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = call i8* (...) @GetHomeDir()
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %8
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %9
%15 = load i32, i32* %8
%16 = add nsw i32 %15, 1
%17 = load i32, i32* %9
%18 = add nsw i32 %16, %17
%19 = load i32, i32* %6
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 0, i8* %23
br label %33
24: ; preds = %3
%25 = load i8*, i8** %5
%26 = load i8*, i8** %7
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %5
%29 = call i32 @strcat(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = load i8*, i8** %5
%31 = load i8*, i8** %4
%32 = call i32 @strcat(i8* %30, i8* %31)
br label %33
33: ; preds = %24, %21
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @PrependHome(i8* %0, i8* returned %1, i32 %2) {
%4 = tail call i8* (...) @GetHomeDir()
%5 = tail call i32 @strlen(i8* %4)
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %5, 1
%8 = add nsw i32 %7, %6
%9 = icmp slt i32 %8, %2
br i1 %9, label %11, label %10
10: ; preds = %3
store i8 0, i8* %1
br label %15
11: ; preds = %3
%12 = tail call i32 @strcpy(i8* %1, i8* %4)
%13 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @strcat(i8* %1, i8* %0)
br label %15
15: ; preds = %11, %10
ret i8* %1
}