#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 const *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char const *);
void prepend_to_env(const char *item, const char *var) {
  char *old_value = getenv(var);
  const size_t putenv_arg_len =
      strlen(var) + 1 + strlen(item) + 1 + strlen(old_value) + 1;
  char putenv_arg[putenv_arg_len];
  putenv_arg[0] = 0;
  strcat(putenv_arg, var);
  strcat(putenv_arg, "=");
  strcat(putenv_arg, item);
  strcat(putenv_arg, ";");
  strcat(putenv_arg, old_value);
  putenv(putenv_arg);
}


x86 assembly (clang, -O0):
<prepend_to_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    -0x3c(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x3(%rax,%rcx,1),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
movb   $0x0,(%rdi)
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x38(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1050 <putenv@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepend_to_env>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r13d,%ebx
add    %ebx,%eax
add    $0x3,%eax
cltq
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rcx
mov    %rcx,%rbx
sub    %rax,%rbx
neg    %rax
mov    %rbx,%rsp
movb   $0x0,(%rcx,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strcat@plt>
lea    0xe4d(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
lea    0xe35(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1050 <putenv@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c";\00"
define void @prepend_to_env(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i8* @getenv(i8* %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = add nsw i32 %16, 1
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %17, %19
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %7
%25 = alloca i8, i64 %23
store i64 %23, i64* %8
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 0, i8* %26
%27 = load i8*, i8** %4
%28 = call i32 @strcat(i8* %25, i8* %27)
%29 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = load i8*, i8** %3
%31 = call i32 @strcat(i8* %25, i8* %30)
%32 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = load i8*, i8** %5
%34 = call i32 @strcat(i8* %25, i8* %33)
%35 = call i32 @putenv(i8* %25)
%36 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c";\00"
define void @prepend_to_env(i8* %0, i8* %1) {
%3 = tail call i8* @getenv(i8* %1)
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strlen(i8* %3)
%7 = add i32 %4, 3
%8 = add i32 %7, %5
%9 = add i32 %8, %6
%10 = sext i32 %9 to i64
%11 = alloca i8, i64 %10
store i8 0, i8* %11
%12 = call i32 @strcat(i8* %11, i8* %1)
%13 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @strcat(i8* %11, i8* %0)
%15 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @strcat(i8* %11, i8* %3)
%17 = call i32 @putenv(i8* %11)
ret void
}