#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 *calloc(scalar_t__, int);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void set_path(char **dest, char *src) {
  char *root = getenv("server_home");
  *dest = calloc(2048 + strlen(root) + strlen(src), sizeof(char));
  if (*src != '/')
    sprintf(*dest, "%s/%s", root, src);
  else
    strcpy(*dest, src);
}


x86 assembly (clang, -O0):
<set_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe99(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x800,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11d7 <set_path+0x87>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe3f(%rip),%rsi
call   1070 <sprintf@plt>
jmp    11e7 <set_path+0x97>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_path>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xe9b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x800,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%r15)
cmpb   $0x2f,(%r12)
jne    11b5 <set_path+0x65>
mov    %rax,%rdi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>
lea    0xe50(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %r12,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <sprintf@plt>

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

LLVM IR (-O2):
@.str = [12 x i8] c"server_home\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define void @set_path(i8** nocapture writeonly %0, i8* %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = add nsw i64 %4, 2048
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = add nsw i64 %5, %6
%8 = tail call i8* @calloc(i64 %7, i32 1)
store i8* %8, i8** %0
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 47
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %1)
br label %15
13: ; preds = %2
%14 = tail call i32 @strcpy(i8* %8, i8* %1)
br label %15
15: ; preds = %13, %11
ret void
}