#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*/ dump(char const **, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
int putenv(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv, const char *envp[]) {
  dump(envp, "INITIAL ENVIRONMENT: ");
  if (putenv("NVAR1=New Variable") == -1) {
    fprintf(stderr, "%s: putenv()\n", strerror(errno));
    exit(13);
  }
  if (putenv("NVAR2=New Variable 2") == -1) {
    fprintf(stderr, "%s: putenv()\n", strerror(errno));
    exit(13);
  }
  if (putenv("TERM=oink-term") == -1) {
    fprintf(stderr, "%s: putenv()\n", strerror(errno));
    exit(13);
  }
  dump(envp, "MODIFIED ENVIRONMENT:");
  sleep(1);
  printf("\ngetev( 'TERM' ) = '%s';\n", getenv("TERM"));
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1050 <dump@plt>
lea    0xe65(%rip),%rdi
call   1060 <putenv@plt>
cmp    $0xffffffff,%eax
jne    11f5 <main+0x75>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe43(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xd,%edi
call   1080 <exit@plt>
lea    0xe3b(%rip),%rdi
call   1060 <putenv@plt>
cmp    $0xffffffff,%eax
jne    1240 <main+0xc0>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xdf8(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xd,%edi
call   1080 <exit@plt>
lea    0xe05(%rip),%rdi
call   1060 <putenv@plt>
cmp    $0xffffffff,%eax
jne    128b <main+0x10b>
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xdad(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xd,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1050 <dump@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xddf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rdx,%rbx
lea    0xe75(%rip),%rsi
mov    %rdx,%rdi
call   1050 <dump@plt>
lea    0xe7c(%rip),%rdi
call   1060 <putenv@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0x7e>
lea    0xe8c(%rip),%rdi
call   1060 <putenv@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0x7e>
lea    0xe90(%rip),%rdi
call   1060 <putenv@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0x7e>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <dump@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe7f(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2ddb(%rip),%rax
mov    (%rax),%ebx
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe0d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0xd,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"INITIAL ENVIRONMENT: \00"
@.str.1 = [19 x i8] c"NVAR1=New Variable\00"
@stderr = global i32 0
@.str.2 = [14 x i8] c"%s: putenv()\0A\00"
@errno = global i32 0
@.str.3 = [21 x i8] c"NVAR2=New Variable 2\00"
@.str.4 = [15 x i8] c"TERM=oink-term\00"
@.str.5 = [22 x i8] c"MODIFIED ENVIRONMENT:\00"
@.str.6 = [26 x i8] c"\0Agetev( 'TERM' ) = '%s';\0A\00"
@.str.7 = [5 x i8] c"TERM\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%8 = load i8**, i8*** %7
%9 = call i32 @dump(i8** %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @putenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 13)
unreachable
18: ; preds = %3
%19 = call i32 @putenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 13)
unreachable
27: ; preds = %18
%28 = call i32 @putenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 13)
unreachable
36: ; preds = %27
%37 = load i8**, i8*** %7
%38 = call i32 @dump(i8** %37, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @sleep(i32 1)
%40 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%41 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"INITIAL ENVIRONMENT: \00"
@.str.1 = [19 x i8] c"NVAR1=New Variable\00"
@stderr = global i32 0
@.str.2 = [14 x i8] c"%s: putenv()\0A\00"
@errno = global i32 0
@.str.3 = [21 x i8] c"NVAR2=New Variable 2\00"
@.str.4 = [15 x i8] c"TERM=oink-term\00"
@.str.5 = [22 x i8] c"MODIFIED ENVIRONMENT:\00"
@.str.6 = [26 x i8] c"\0Agetev( 'TERM' ) = '%s';\0A\00"
@.str.7 = [5 x i8] c"TERM\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** %2) {
%4 = tail call i32 @dump(i8** %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @putenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 13)
unreachable
13: ; preds = %3
%14 = tail call i32 @putenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 13)
unreachable
22: ; preds = %13
%23 = tail call i32 @putenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = tail call i32 @exit(i32 13)
unreachable
31: ; preds = %22
%32 = tail call i32 @dump(i8** %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%33 = tail call i32 @sleep(i32 1)
%34 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%35 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %34)
ret i32 0
}