#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 *alloca(scalar_t__);
char *getenv(char *);
int set_path(char const *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
scalar_t__ strlen(char const *);
int add_path(const char *path) {
  char *val, *nval;
  if (!(val = getenv("SRAY_DATA_PATH"))) {
    return set_path(path);
  }
  nval = alloca(strlen(val) + strlen(path) + 2);
  sprintf(nval, "%s:%s", path, val);
  return set_path(nval);
}


x86 assembly (clang, -O0):
<add_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1187 <add_path+0x37>
mov    -0x10(%rbp),%rdi
call   1070 <set_path@plt>
mov    %eax,-0x4(%rbp)
jmp    11d5 <add_path+0x85>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe4b(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <set_path@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_path>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a7 <add_path+0x57>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <alloca@plt>
mov    %rax,%r15
lea    0xe79(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <sprintf@plt>
mov    %r15,%r14
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <set_path@plt>

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

LLVM IR (-O2):
@.str = [15 x i8] c"SRAY_DATA_PATH\00"
@.str.1 = [6 x i8] c"%s:%s\00"
define i32 @add_path(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = tail call i64 @strlen(i8* %2)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add i64 %5, 2
%8 = add i64 %7, %6
%9 = tail call i8* @alloca(i64 %8)
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %2)
br label %11
11: ; preds = %1, %4
%12 = phi i8* [ %9, %4 ], [ %0, %1 ]
%13 = tail call i32 @set_path(i8* %12)
ret i32 %13
}