#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 */
scalar_t__ clearenv();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
scalar_t__ setenv(char *, char const *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unsetenv(char *);
void simplify_env() {
  unsetenv("LD_PRELOAD");
  const char *home = getenv("HOME");
  const char *path = getenv("PATH");
  const char *display = getenv("DISPLAY");
  if (clearenv() != 0) {
    fprintf(stderr, "Could not clear environment..");
  }
  if (setenv("PATH", path, 1) != 0) {
    fprintf(stderr, "setenv PATH failed.\n");
  }
  if (setenv("HOME", home, 1) != 0) {
    fprintf(stderr, "setenv HOME failed.\n");
  }
  if (display && setenv("DISPLAY", display, 1) != 0) {
    fprintf(stderr, "setenv DISPLAY failed.\n");
  }
}


x86 assembly (clang, -O0):
<simplify_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1070 <unsetenv@plt>
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <clearenv@plt>
cmp    $0x0,%rax
je     11ba <simplify_env+0x6a>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
cmp    $0x0,%rax
je     11ee <simplify_env+0x9e>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe12(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
cmp    $0x0,%rax
je     1222 <simplify_env+0xd2>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1060 <fprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     1261 <simplify_env+0x111>
mov    -0x18(%rbp),%rsi
lea    0xddd(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
cmp    $0x0,%rax
je     1261 <simplify_env+0x111>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplify_env>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
call   1070 <unsetenv@plt>
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xe99(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <clearenv@plt>
test   %rax,%rax
je     11af <simplify_env+0x5f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe5a(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
test   %rax,%rax
je     11dd <simplify_env+0x8d>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe27(%rip),%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
test   %rax,%rax
je     120b <simplify_env+0xbb>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1060 <fprintf@plt>
test   %r15,%r15
je     1243 <simplify_env+0xf3>
lea    0xdfe(%rip),%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
test   %rax,%rax
je     1243 <simplify_env+0xf3>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <fprintf@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"LD_PRELOAD\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [5 x i8] c"PATH\00"
@.str.3 = [8 x i8] c"DISPLAY\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"Could not clear environment..\00"
@.str.5 = [21 x i8] c"setenv PATH failed.\0A\00"
@.str.6 = [21 x i8] c"setenv HOME failed.\0A\00"
@.str.7 = [24 x i8] c"setenv DISPLAY failed.\0A\00"
define void @simplify_env() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %5, i8** %1
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %6, i8** %2
%7 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i8* %7, i8** %3
%8 = call i64 (...) @clearenv()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %10, %0
%14 = load i8*, i8** %2
%15 = call i64 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 1)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %20
20: ; preds = %17, %13
%21 = load i8*, i8** %1
%22 = call i64 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 1)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %27
27: ; preds = %24, %20
%28 = load i8*, i8** %3
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = call i64 @setenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %31, i32 1)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
br label %37
37: ; preds = %34, %30, %27
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"LD_PRELOAD\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [5 x i8] c"PATH\00"
@.str.3 = [8 x i8] c"DISPLAY\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"Could not clear environment..\00"
@.str.5 = [21 x i8] c"setenv PATH failed.\0A\00"
@.str.6 = [21 x i8] c"setenv HOME failed.\0A\00"
@.str.7 = [24 x i8] c"setenv DISPLAY failed.\0A\00"
define void @simplify_env() {
%1 = tail call i32 @unsetenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i64 (...) @clearenv()
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %10
10: ; preds = %7, %0
%11 = tail call i64 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %16
16: ; preds = %13, %10
%17 = tail call i64 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
%23 = icmp eq i8* %4, null
br i1 %23, label %30, label %24
24: ; preds = %22
%25 = tail call i64 @setenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
br label %30
30: ; preds = %27, %24, %22
ret void
}