#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 */
int /*<<< orphan*/ chdir(char *);
char *getenv(char *);
int /*<<< orphan*/ setenv(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ umask(int);
void prepenv() {
  umask(022);
  chdir("/");
  const char *con = getenv("console");
  if (!con)
    con = "/dev/console";
  setenv("CONSOLE", con, 0);
  setenv("HOME", "/", 0);
  setenv("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 0);
  setenv("PWD", "/", 0);
  setenv("TERM", "linux", 0);
  setenv("USER", "root", 0);
}


x86 assembly (clang, -O0):
<prepenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x12,%edi
call   1060 <umask@plt>
lea    0xea7(%rip),%rdi
call   1050 <chdir@plt>
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1184 <prepenv+0x44>
lea    0xe82(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe7a(%rip),%rdi
lea    0xe5c(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe6a(%rip),%rdi
lea    0xe68(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe78(%rip),%rdi
lea    0xe32(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe67(%rip),%rdi
lea    0xe65(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe5d(%rip),%rdi
lea    0xe5b(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepenv>:
push   %rbx
mov    $0x12,%edi
call   1060 <umask@plt>
lea    0xeae(%rip),%rbx
mov    %rbx,%rdi
call   1050 <chdir@plt>
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe92(%rip),%rsi
cmovne %rax,%rsi
lea    0xe94(%rip),%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe8e(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe82(%rip),%rdi
lea    0xe80(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe83(%rip),%rdi
lea    0xe81(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe79(%rip),%rdi
lea    0xe77(%rip),%rsi
xor    %edx,%edx
pop    %rbx
jmp    1040 <setenv@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [8 x i8] c"console\00"
@.str.2 = [13 x i8] c"/dev/console\00"
@.str.3 = [8 x i8] c"CONSOLE\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [5 x i8] c"PATH\00"
@.str.6 = [30 x i8] c"/usr/sbin:/usr/bin:/sbin:/bin\00"
@.str.7 = [4 x i8] c"PWD\00"
@.str.8 = [5 x i8] c"TERM\00"
@.str.9 = [6 x i8] c"linux\00"
@.str.10 = [5 x i8] c"USER\00"
@.str.11 = [5 x i8] c"root\00"
define void @prepenv() {
%1 = alloca i8*
%2 = call i32 @umask(i32 18)
%3 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %8
8: ; preds = %7, %0
%9 = load i8*, i8** %1
%10 = call i32 @setenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32 0)
%11 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0)
%12 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 0)
%13 = call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0)
%14 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 0)
%15 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 0)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [8 x i8] c"console\00"
@.str.2 = [13 x i8] c"/dev/console\00"
@.str.3 = [8 x i8] c"CONSOLE\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [5 x i8] c"PATH\00"
@.str.6 = [30 x i8] c"/usr/sbin:/usr/bin:/sbin:/bin\00"
@.str.7 = [4 x i8] c"PWD\00"
@.str.8 = [5 x i8] c"TERM\00"
@.str.9 = [6 x i8] c"linux\00"
@.str.10 = [5 x i8] c"USER\00"
@.str.11 = [5 x i8] c"root\00"
define void @prepenv() {
%1 = tail call i32 @umask(i32 18)
%2 = tail call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %3
%6 = tail call i32 @setenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %5, i32 0)
%7 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 0)
%9 = tail call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 0)
%11 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 0)
ret void
}