#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 *append3(char *, char *, char const *);
int /*<<< orphan*/ check_retval(int, char *);
int get_gcc_version_string(int *, int *);
char *getenv(char *);
int setenv(char *, char *, int const);
int /*<<< orphan*/ unsetenv(char *);
void update_environment(char *base_path) {
  int r;
  int gcc_major = 0, gcc_minor = 0;
  const int overwrite = 1;
  char *pin_ld_library_path = 0;
  char *new_ld_library_path = 0;
  const char *pin_runtime_dir = "runtime";
  const char *glibc_lib_dir = "glibc";
  const char *cpp_lib_dir = "cpplibs";
  char *ld_library_path = 0;
  char *ld_assume_kernel = 0;
  char *base_path64 = 0;
  char *pin_runtime_libs64 = 0;
  char *pin_glibc_libs64 = 0;
  char *pin_cpp_libs64 = 0;
  char *incoming_ld_preload = 0;
  char *incoming_ld_bind_now = 0;
  int getGccPassed = 0;
  base_path64 = append3(base_path, "/", "intel64");
  pin_runtime_libs64 = append3(base_path64, "/", pin_runtime_dir);
  pin_glibc_libs64 = append3(pin_runtime_libs64, "/", glibc_lib_dir);
  pin_cpp_libs64 = append3(pin_runtime_libs64, "/", cpp_lib_dir);
  ;
  ld_library_path = getenv("LD_LIBRARY_PATH");
  pin_ld_library_path = ld_library_path;
  pin_ld_library_path = append3(pin_glibc_libs64, ":", pin_ld_library_path);
  getGccPassed = get_gcc_version_string(&gcc_major, &gcc_minor);
  if (!getGccPassed || gcc_major < 4 || (gcc_major == 4 && gcc_minor < 5)) {
    pin_ld_library_path = append3(pin_cpp_libs64, ":", pin_ld_library_path);
  }
  pin_ld_library_path = append3(pin_runtime_libs64, ":", pin_ld_library_path);
  new_ld_library_path = ld_library_path;
  if (!getGccPassed || gcc_major < 4 || (gcc_major == 4 && gcc_minor < 5)) {
    new_ld_library_path = append3(pin_cpp_libs64, ":", new_ld_library_path);
  }
  new_ld_library_path = append3(pin_runtime_libs64, ":", new_ld_library_path);
  r = setenv("PIN_LD_RESTORE_REQUIRED", "t", overwrite);
  check_retval(r, "setenv PIN_LD_RESTORE_REQUIRED");
  r = setenv("PIN_VM_LD_LIBRARY_PATH", pin_ld_library_path, overwrite);
  check_retval(r, "setenv PIN_VM_LD_LIBRARY_PATH");
  if (ld_library_path) {
    r = setenv("PIN_APP_LD_LIBRARY_PATH", ld_library_path, overwrite);
    check_retval(r, "setenv PIN_APP_LD_LIBRARY_PATH");
  }
  r = setenv("LD_LIBRARY_PATH", new_ld_library_path, overwrite);
  check_retval(r, "setenv LD_LIBRARY_PATH");
  ld_assume_kernel = getenv("LD_ASSUME_KERNEL");
  if (ld_assume_kernel) {
    r = setenv("PIN_APP_LD_ASSUME_KERNEL", ld_assume_kernel, overwrite);
    check_retval(r, "setenv PIN_APP_LD_ASSUME_KERNEL");
    unsetenv("LD_ASSUME_KERNEL");
  }
  incoming_ld_bind_now = getenv("LD_BIND_NOW");
  if (incoming_ld_bind_now) {
    r = setenv("PIN_APP_LD_BIND_NOW", incoming_ld_bind_now, overwrite);
    check_retval(r, "setenv PIN_APP_LD_BIND_NOW");
    unsetenv("LD_BIND_NOW");
  }
  incoming_ld_preload = getenv("LD_PRELOAD");
  if (incoming_ld_preload) {
    r = setenv("PIN_APP_LD_PRELOAD", incoming_ld_preload, overwrite);
    check_retval(r, "setenv PIN_APP_LD_PRELOAD");
    unsetenv("LD_PRELOAD");
  }
}


x86 assembly (clang, -O0):
<update_environment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe65(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe62(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe5d(%rip),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
movq   $0x0,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe0c(%rip),%rsi
lea    0xe07(%rip),%rdx
call   1060 <append3@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xded(%rip),%rsi
call   1060 <append3@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xdd5(%rip),%rsi
call   1060 <append3@plt>
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xdbd(%rip),%rsi
call   1060 <append3@plt>
mov    %rax,-0x70(%rbp)
lea    0xe1e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd97(%rip),%rsi
call   1060 <append3@plt>
mov    %rax,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <get_gcc_version_string@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     12d0 <update_environment+0x170>
cmpl   $0x4,-0x10(%rbp)
jl     12d0 <update_environment+0x170>
cmpl   $0x4,-0x10(%rbp)
jne    12e8 <update_environment+0x188>
cmpl   $0x5,-0x14(%rbp)
jge    12e8 <update_environment+0x188>
mov    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd41(%rip),%rsi
call   1060 <append3@plt>
mov    %rax,-0x20(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd29(%rip),%rsi
call   1060 <append3@plt>
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     1333 <update_environment+0x1d3>
cmpl   $0x4,-0x10(%rbp)
jl     1333 <update_environment+0x1d3>
cmpl   $0x4,-0x10(%rbp)
jne    134b <update_environment+0x1eb>
cmpl   $0x5,-0x14(%rbp)
jge    134b <update_environment+0x1eb>
mov    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xcde(%rip),%rsi
call   1060 <append3@plt>
mov    %rax,-0x28(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xcc6(%rip),%rsi
call   1060 <append3@plt>
mov    %rax,-0x28(%rbp)
lea    0xcc1(%rip),%rdi
lea    0xcb1(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xc9c(%rip),%rsi
call   1070 <check_retval@plt>
mov    -0x20(%rbp),%rsi
lea    0xcb2(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xc94(%rip),%rsi
call   1070 <check_retval@plt>
cmpq   $0x0,-0x48(%rbp)
je     13e6 <update_environment+0x286>
mov    -0x48(%rbp),%rsi
lea    0xc9e(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xc80(%rip),%rsi
call   1070 <check_retval@plt>
mov    -0x28(%rbp),%rsi
lea    0xc96(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xc78(%rip),%rsi
call   1070 <check_retval@plt>
lea    0xc92(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     145b <update_environment+0x2fb>
mov    -0x50(%rbp),%rsi
lea    0xc6b(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xc4d(%rip),%rsi
call   1070 <check_retval@plt>
lea    0xc50(%rip),%rdi
call   1080 <unsetenv@plt>
lea    0xc64(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     14a9 <update_environment+0x349>
mov    -0x80(%rbp),%rsi
lea    0xc3d(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xc1f(%rip),%rsi
call   1070 <check_retval@plt>
lea    0xc22(%rip),%rdi
call   1080 <unsetenv@plt>
lea    0xc31(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     14f7 <update_environment+0x397>
mov    -0x78(%rbp),%rsi
lea    0xc0a(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xbec(%rip),%rsi
call   1070 <check_retval@plt>
lea    0xbef(%rip),%rdi
call   1080 <unsetenv@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_environment>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xe95(%rip),%rbx
lea    0xe90(%rip),%rdx
mov    %rbx,%rsi
call   1060 <append3@plt>
lea    0xe69(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <append3@plt>
mov    %rax,%r13
lea    0xe5c(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <append3@plt>
mov    %rax,%rbp
lea    0xe4d(%rip),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <append3@plt>
mov    %rax,%r15
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xe3b(%rip),%rsi
mov    %rbp,%rdi
mov    %rax,%rdx
call   1060 <append3@plt>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <get_gcc_version_string@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1215 <update_environment+0xb5>
cmpl   $0x4,0x4(%rsp)
jl     1215 <update_environment+0xb5>
jne    122a <update_environment+0xca>
cmpl   $0x4,(%rsp)
jg     122a <update_environment+0xca>
lea    0xe04(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1060 <append3@plt>
mov    %rax,%rbx
lea    0xdef(%rip),%rsi
mov    %r13,%rdi
mov    %rbx,%rdx
call   1060 <append3@plt>
mov    %rax,%r12
test   %ebp,%ebp
je     1258 <update_environment+0xf8>
cmpl   $0x4,0x4(%rsp)
jl     1258 <update_environment+0xf8>
mov    %r14,%rdx
jne    126d <update_environment+0x10d>
cmpl   $0x4,(%rsp)
mov    %r14,%rdx
jg     126d <update_environment+0x10d>
lea    0xdc1(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1060 <append3@plt>
mov    %rax,%rdx
lea    0xdac(%rip),%rsi
mov    %r13,%rdi
call   1060 <append3@plt>
mov    %rax,%rbx
lea    0xda5(%rip),%rdi
lea    0xd95(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xd86(%rip),%rsi
mov    %eax,%edi
call   1070 <check_retval@plt>
lea    0xd9e(%rip),%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xd83(%rip),%rsi
mov    %eax,%edi
call   1070 <check_retval@plt>
test   %r14,%r14
je     12ee <update_environment+0x18e>
lea    0xd95(%rip),%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xd7a(%rip),%rsi
mov    %eax,%edi
call   1070 <check_retval@plt>
lea    0xd92(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xd77(%rip),%rsi
mov    %eax,%edi
call   1070 <check_retval@plt>
lea    0xd8f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     134f <update_environment+0x1ef>
lea    0xd76(%rip),%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xd5b(%rip),%rsi
mov    %eax,%edi
call   1070 <check_retval@plt>
lea    0xd5c(%rip),%rdi
call   1080 <unsetenv@plt>
lea    0xd70(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     138e <update_environment+0x22e>
lea    0xd57(%rip),%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xd3c(%rip),%rsi
mov    %eax,%edi
call   1070 <check_retval@plt>
lea    0xd3d(%rip),%rdi
call   1080 <unsetenv@plt>
lea    0xd4c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     13cd <update_environment+0x26d>
lea    0xd33(%rip),%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xd18(%rip),%rsi
mov    %eax,%edi
call   1070 <check_retval@plt>
lea    0xd19(%rip),%rdi
call   1080 <unsetenv@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"runtime\00"
@.str.1 = [6 x i8] c"glibc\00"
@.str.2 = [8 x i8] c"cpplibs\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [8 x i8] c"intel64\00"
@.str.5 = [16 x i8] c"LD_LIBRARY_PATH\00"
@.str.6 = [2 x i8] c":\00"
@.str.7 = [24 x i8] c"PIN_LD_RESTORE_REQUIRED\00"
@.str.8 = [2 x i8] c"t\00"
@.str.9 = [31 x i8] c"setenv PIN_LD_RESTORE_REQUIRED\00"
@.str.10 = [23 x i8] c"PIN_VM_LD_LIBRARY_PATH\00"
@.str.11 = [30 x i8] c"setenv PIN_VM_LD_LIBRARY_PATH\00"
@.str.12 = [24 x i8] c"PIN_APP_LD_LIBRARY_PATH\00"
@.str.13 = [31 x i8] c"setenv PIN_APP_LD_LIBRARY_PATH\00"
@.str.14 = [23 x i8] c"setenv LD_LIBRARY_PATH\00"
@.str.15 = [17 x i8] c"LD_ASSUME_KERNEL\00"
@.str.16 = [25 x i8] c"PIN_APP_LD_ASSUME_KERNEL\00"
@.str.17 = [32 x i8] c"setenv PIN_APP_LD_ASSUME_KERNEL\00"
@.str.18 = [12 x i8] c"LD_BIND_NOW\00"
@.str.19 = [20 x i8] c"PIN_APP_LD_BIND_NOW\00"
@.str.20 = [27 x i8] c"setenv PIN_APP_LD_BIND_NOW\00"
@.str.21 = [11 x i8] c"LD_PRELOAD\00"
@.str.22 = [19 x i8] c"PIN_APP_LD_PRELOAD\00"
@.str.23 = [26 x i8] c"setenv PIN_APP_LD_PRELOAD\00"
define void @update_environment(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 1, i32* %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %11
store i8* null, i8** %12
store i8* null, i8** %13
store i8* null, i8** %14
store i8* null, i8** %15
store i8* null, i8** %16
store i8* null, i8** %17
store i8* null, i8** %18
store i8* null, i8** %19
store i32 0, i32* %20
%21 = load i8*, i8** %2
%22 = call i8* @append3(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
store i8* %22, i8** %14
%23 = load i8*, i8** %14
%24 = load i8*, i8** %9
%25 = call i8* @append3(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %24)
store i8* %25, i8** %15
%26 = load i8*, i8** %15
%27 = load i8*, i8** %10
%28 = call i8* @append3(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %27)
store i8* %28, i8** %16
%29 = load i8*, i8** %15
%30 = load i8*, i8** %11
%31 = call i8* @append3(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %30)
store i8* %31, i8** %17
%32 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
store i8* %32, i8** %12
%33 = load i8*, i8** %12
store i8* %33, i8** %7
%34 = load i8*, i8** %16
%35 = load i8*, i8** %7
%36 = call i8* @append3(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %35)
store i8* %36, i8** %7
%37 = call i32 @get_gcc_version_string(i32* %4, i32* %5)
store i32 %37, i32* %20
%38 = load i32, i32* %20
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %1
%41 = load i32, i32* %4
%42 = icmp slt i32 %41, 4
br i1 %42, label %49, label %43
43: ; preds = %40
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 4
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i32, i32* %5
%48 = icmp slt i32 %47, 5
br i1 %48, label %49, label %53
49: ; preds = %46, %40, %1
%50 = load i8*, i8** %17
%51 = load i8*, i8** %7
%52 = call i8* @append3(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %51)
store i8* %52, i8** %7
br label %53
53: ; preds = %49, %46, %43
%54 = load i8*, i8** %15
%55 = load i8*, i8** %7
%56 = call i8* @append3(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %55)
store i8* %56, i8** %7
%57 = load i8*, i8** %12
store i8* %57, i8** %8
%58 = load i32, i32* %20
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %53
%61 = load i32, i32* %4
%62 = icmp slt i32 %61, 4
br i1 %62, label %69, label %63
63: ; preds = %60
%64 = load i32, i32* %4
%65 = icmp eq i32 %64, 4
br i1 %65, label %66, label %73
66: ; preds = %63
%67 = load i32, i32* %5
%68 = icmp slt i32 %67, 5
br i1 %68, label %69, label %73
69: ; preds = %66, %60, %53
%70 = load i8*, i8** %17
%71 = load i8*, i8** %8
%72 = call i8* @append3(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %71)
store i8* %72, i8** %8
br label %73
73: ; preds = %69, %66, %63
%74 = load i8*, i8** %15
%75 = load i8*, i8** %8
%76 = call i8* @append3(i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %75)
store i8* %76, i8** %8
%77 = call i32 @setenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
store i32 %77, i32* %3
%78 = load i32, i32* %3
%79 = call i32 @check_retval(i32 %78, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%80 = load i8*, i8** %7
%81 = call i32 @setenv(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %80, i32 1)
store i32 %81, i32* %3
%82 = load i32, i32* %3
%83 = call i32 @check_retval(i32 %82, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
%84 = load i8*, i8** %12
%85 = icmp ne i8* %84, null
br i1 %85, label %86, label %91
86: ; preds = %73
%87 = load i8*, i8** %12
%88 = call i32 @setenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %87, i32 1)
store i32 %88, i32* %3
%89 = load i32, i32* %3
%90 = call i32 @check_retval(i32 %89, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
br label %91
91: ; preds = %86, %73
%92 = load i8*, i8** %8
%93 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %92, i32 1)
store i32 %93, i32* %3
%94 = load i32, i32* %3
%95 = call i32 @check_retval(i32 %94, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0))
%96 = call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0))
store i8* %96, i8** %13
%97 = load i8*, i8** %13
%98 = icmp ne i8* %97, null
br i1 %98, label %99, label %105
99: ; preds = %91
%100 = load i8*, i8** %13
%101 = call i32 @setenv(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0), i8* %100, i32 1)
store i32 %101, i32* %3
%102 = load i32, i32* %3
%103 = call i32 @check_retval(i32 %102, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.17, i64 0, i64 0))
%104 = call i32 @unsetenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0))
br label %105
105: ; preds = %99, %91
%106 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
store i8* %106, i8** %19
%107 = load i8*, i8** %19
%108 = icmp ne i8* %107, null
br i1 %108, label %109, label %115
109: ; preds = %105
%110 = load i8*, i8** %19
%111 = call i32 @setenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.19, i64 0, i64 0), i8* %110, i32 1)
store i32 %111, i32* %3
%112 = load i32, i32* %3
%113 = call i32 @check_retval(i32 %112, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0))
%114 = call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
br label %115
115: ; preds = %109, %105
%116 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.21, i64 0, i64 0))
store i8* %116, i8** %18
%117 = load i8*, i8** %18
%118 = icmp ne i8* %117, null
br i1 %118, label %119, label %125
119: ; preds = %115
%120 = load i8*, i8** %18
%121 = call i32 @setenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.22, i64 0, i64 0), i8* %120, i32 1)
store i32 %121, i32* %3
%122 = load i32, i32* %3
%123 = call i32 @check_retval(i32 %122, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.23, i64 0, i64 0))
%124 = call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.21, i64 0, i64 0))
br label %125
125: ; preds = %119, %115
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"runtime\00"
@.str.1 = [6 x i8] c"glibc\00"
@.str.2 = [8 x i8] c"cpplibs\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [8 x i8] c"intel64\00"
@.str.5 = [16 x i8] c"LD_LIBRARY_PATH\00"
@.str.6 = [2 x i8] c":\00"
@.str.7 = [24 x i8] c"PIN_LD_RESTORE_REQUIRED\00"
@.str.8 = [2 x i8] c"t\00"
@.str.9 = [31 x i8] c"setenv PIN_LD_RESTORE_REQUIRED\00"
@.str.10 = [23 x i8] c"PIN_VM_LD_LIBRARY_PATH\00"
@.str.11 = [30 x i8] c"setenv PIN_VM_LD_LIBRARY_PATH\00"
@.str.12 = [24 x i8] c"PIN_APP_LD_LIBRARY_PATH\00"
@.str.13 = [31 x i8] c"setenv PIN_APP_LD_LIBRARY_PATH\00"
@.str.14 = [23 x i8] c"setenv LD_LIBRARY_PATH\00"
@.str.15 = [17 x i8] c"LD_ASSUME_KERNEL\00"
@.str.16 = [25 x i8] c"PIN_APP_LD_ASSUME_KERNEL\00"
@.str.17 = [32 x i8] c"setenv PIN_APP_LD_ASSUME_KERNEL\00"
@.str.18 = [12 x i8] c"LD_BIND_NOW\00"
@.str.19 = [20 x i8] c"PIN_APP_LD_BIND_NOW\00"
@.str.20 = [27 x i8] c"setenv PIN_APP_LD_BIND_NOW\00"
@.str.21 = [11 x i8] c"LD_PRELOAD\00"
@.str.22 = [19 x i8] c"PIN_APP_LD_PRELOAD\00"
@.str.23 = [26 x i8] c"setenv PIN_APP_LD_PRELOAD\00"
define void @update_environment(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i8* @append3(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%7 = tail call i8* @append3(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = tail call i8* @append3(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i8* @append3(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%11 = tail call i8* @append3(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %10)
%12 = call i32 @get_gcc_version_string(i32* %2, i32* %3)
%13 = icmp eq i32 %12, 0
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 4
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %22, label %17
17: ; preds = %1
%18 = icmp eq i32 %14, 4
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 5
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %22, label %24
22: ; preds = %17, %1
%23 = call i8* @append3(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %11)
br label %24
24: ; preds = %22, %17
%25 = phi i8* [ %23, %22 ], [ %11, %17 ]
%26 = call i8* @append3(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, 4
%29 = select i1 %13, i1 true, i1 %28
br i1 %29, label %35, label %30
30: ; preds = %24
%31 = icmp eq i32 %27, 4
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 5
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %35, label %37
35: ; preds = %30, %24
%36 = call i8* @append3(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %10)
br label %37
37: ; preds = %35, %30
%38 = phi i8* [ %36, %35 ], [ %10, %30 ]
%39 = call i8* @append3(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%40 = call i32 @setenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32 1)
%41 = call i32 @check_retval(i32 %40, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%42 = call i32 @setenv(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %26, i32 1)
%43 = call i32 @check_retval(i32 %42, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
%44 = icmp eq i8* %10, null
br i1 %44, label %48, label %45
45: ; preds = %37
%46 = call i32 @setenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %10, i32 1)
%47 = call i32 @check_retval(i32 %46, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
br label %48
48: ; preds = %45, %37
%49 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %39, i32 1)
%50 = call i32 @check_retval(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0))
%51 = call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0))
%52 = icmp eq i8* %51, null
br i1 %52, label %57, label %53
53: ; preds = %48
%54 = call i32 @setenv(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0), i8* %51, i32 1)
%55 = call i32 @check_retval(i32 %54, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.17, i64 0, i64 0))
%56 = call i32 @unsetenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0))
br label %57
57: ; preds = %53, %48
%58 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
%59 = icmp eq i8* %58, null
br i1 %59, label %64, label %60
60: ; preds = %57
%61 = call i32 @setenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.19, i64 0, i64 0), i8* %58, i32 1)
%62 = call i32 @check_retval(i32 %61, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0))
%63 = call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
br label %64
64: ; preds = %60, %57
%65 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.21, i64 0, i64 0))
%66 = icmp eq i8* %65, null
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = call i32 @setenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.22, i64 0, i64 0), i8* %65, i32 1)
%69 = call i32 @check_retval(i32 %68, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.23, i64 0, i64 0))
%70 = call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.21, i64 0, i64 0))
br label %71
71: ; preds = %67, %64
ret void
}