#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 *getenv(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *xmalloc(scalar_t__);
char *prepend_srcdir(const char *fname) {
  static const char *srcdir;
  char *result;
  if (!srcdir && !(srcdir = getenv("srcdir")))
    srcdir = ".";
  result = xmalloc(strlen(srcdir) + 1 + strlen(fname) + 1);
  strcpy(result, srcdir);
  strcat(result, "/");
  strcat(result, fname);
  return result;
}


x86 assembly (clang, -O0):
<prepend_srcdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,0x2eec(%rip)
jne    1195 <prepend_srcdir+0x45>
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ed3(%rip)
cmp    $0x0,%rax
jne    1195 <prepend_srcdir+0x45>
lea    0xe79(%rip),%rax
mov    %rax,0x2ebb(%rip)
mov    0x2eb4(%rip),%rdi
call   1050 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x18(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7f(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepend_srcdir>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2ef2(%rip),%rdi
test   %rdi,%rdi
jne    1184 <prepend_srcdir+0x34>
lea    0xe96(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe8e(%rip),%rdi
cmovne %rax,%rdi
mov    %rdi,0x2ecc(%rip)
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1060 <xmalloc@plt>
mov    %rax,%rbx
mov    0x2ea5(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@prepend_srcdir.srcdir = internal unnamed_addr global i8* null
@.str = [7 x i8] c"srcdir\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c"/\00"
define i8* @prepend_srcdir(i8* %0) {
%2 = load i8*, i8** @prepend_srcdir.srcdir
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
%7 = select i1 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %5
store i8* %7, i8** @prepend_srcdir.srcdir
br label %8
8: ; preds = %4, %1
%9 = phi i8* [ %7, %4 ], [ %2, %1 ]
%10 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = add i64 %10, 2
%13 = add i64 %12, %11
%14 = tail call i8* @xmalloc(i64 %13)
%15 = load i8*, i8** @prepend_srcdir.srcdir
%16 = tail call i32 @strcpy(i8* %14, i8* %15)
%17 = tail call i32 @strcat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @strcat(i8* %14, i8* %0)
ret i8* %14
}