#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 *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ unsetenv(char *);
int main(int argc, char *argv[]) {
  (void)argc;
  (void)argv;
  setenv("SETENV", "setenv", 1);
  putenv("PUTENV=putenv");
  printf("SETENV = %s\n", getenv("SETENV"));
  printf("PUTENV = %s\n", getenv("PUTENV"));
  setenv("SETENV", "setenv_good", 1);
  putenv("PUTENV=putenv_good");
  printf("SETENV = %s\n", getenv("SETENV"));
  printf("PUTENV = %s\n", getenv("PUTENV"));
  setenv("SETENV", "setenv_bad", 0);
  setenv("NEWENV", "newenv_good", 0);
  printf("SETENV = %s\n", getenv("SETENV"));
  printf("NEWENV = %s\n", getenv("NEWENV"));
  unsetenv("SETENV");
  unsetenv("NEWENV");
  printf("SETENV = %s\n", getenv("SETENV"));
  printf("NEWENV = %s\n", getenv("NEWENV"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xe89(%rip),%rdi
call   1060 <putenv@plt>
lea    0xe6f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe7c(%rip),%rdi
call   1050 <printf@plt>
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe39(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xe6a(%rip),%rdi
call   1060 <putenv@plt>
lea    0xe15(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe22(%rip),%rdi
call   1050 <printf@plt>
lea    0xe30(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe14(%rip),%rdi
call   1050 <printf@plt>
lea    0xddf(%rip),%rdi
lea    0xe34(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe31(%rip),%rdi
lea    0xe31(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xdb5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
lea    0xe01(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe05(%rip),%rdi
call   1050 <printf@plt>
lea    0xd7f(%rip),%rdi
call   1070 <unsetenv@plt>
lea    0xdda(%rip),%rdi
call   1070 <unsetenv@plt>
lea    0xd67(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xd74(%rip),%rdi
call   1050 <printf@plt>
lea    0xdb3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xdb7(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%r15
lea    0xea1(%rip),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xe94(%rip),%rdi
call   1060 <putenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
lea    0xe8e(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    0xe96(%rip),%r12
mov    %r12,%rdi
call   1030 <getenv@plt>
lea    0xe7a(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    0xe7c(%rip),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xe74(%rip),%rdi
call   1060 <putenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    0xe55(%rip),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe4f(%rip),%rbx
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
lea    0xe2f(%rip),%r12
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1070 <unsetenv@plt>
mov    %rbx,%rdi
call   1070 <unsetenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"SETENV\00"
@.str.1 = [7 x i8] c"setenv\00"
@.str.2 = [14 x i8] c"PUTENV=putenv\00"
@.str.3 = [13 x i8] c"SETENV = %s\0A\00"
@.str.4 = [13 x i8] c"PUTENV = %s\0A\00"
@.str.5 = [7 x i8] c"PUTENV\00"
@.str.6 = [12 x i8] c"setenv_good\00"
@.str.7 = [19 x i8] c"PUTENV=putenv_good\00"
@.str.8 = [11 x i8] c"setenv_bad\00"
@.str.9 = [7 x i8] c"NEWENV\00"
@.str.10 = [12 x i8] c"newenv_good\00"
@.str.11 = [13 x i8] c"NEWENV = %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = load i8**, i8*** %5
%8 = call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%9 = call i32 @putenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 1)
%15 = call i32 @putenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%16 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 0)
%21 = call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 0)
%22 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%25 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %24)
%26 = call i32 @unsetenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @unsetenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%28 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%31 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"SETENV\00"
@.str.1 = [7 x i8] c"setenv\00"
@.str.2 = [14 x i8] c"PUTENV=putenv\00"
@.str.3 = [13 x i8] c"SETENV = %s\0A\00"
@.str.4 = [13 x i8] c"PUTENV = %s\0A\00"
@.str.5 = [7 x i8] c"PUTENV\00"
@.str.6 = [12 x i8] c"setenv_good\00"
@.str.7 = [19 x i8] c"PUTENV=putenv_good\00"
@.str.8 = [11 x i8] c"setenv_bad\00"
@.str.9 = [7 x i8] c"NEWENV\00"
@.str.10 = [12 x i8] c"newenv_good\00"
@.str.11 = [13 x i8] c"NEWENV = %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
%4 = tail call i32 @putenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%9 = tail call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 1)
%10 = tail call i32 @putenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = tail call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 0)
%16 = tail call i32 @setenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 0)
%17 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%20 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %19)
%21 = tail call i32 @unsetenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @unsetenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%23 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%26 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* %25)
ret i32 0
}