#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*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
void set_path(void) {
  char *home = getenv("HOME");
  char path[4096];
  snprintf(path, 4095, "%s:%s", home, getenv("PATH"));
  setenv("PATH", path, 1);
}


x86 assembly (clang, -O0):
<set_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
lea    0xebe(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1020(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1018(%rbp)
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x1020(%rbp),%rdi
mov    -0x1018(%rbp),%rcx
mov    %rax,%r8
mov    $0xfff,%esi
lea    0xe78(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xebd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xeb9(%rip),%r14
mov    %r14,%rdi
call   1030 <getenv@plt>
lea    0xea4(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xfff,%esi
mov    %rbx,%rcx
mov    %rax,%r8
call   1050 <snprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [6 x i8] c"%s:%s\00"
@.str.2 = [5 x i8] c"PATH\00"
define void @set_path() {
%1 = alloca i8*
%2 = alloca [4096 x i8]
%3 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @snprintf(i8* %4, i32 4095, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %6)
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%9 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %8, i32 1)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [6 x i8] c"%s:%s\00"
@.str.2 = [5 x i8] c"PATH\00"
define void @set_path() {
%1 = alloca [4096 x i8]
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%5 = call i32 @snprintf(i8* %3, i32 4095, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %4)
%6 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 1)
ret void
}