#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 *, ...);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int main(int argc, char *argv[], char *envp[]) {
  char **ptr;
  for (ptr = envp; *ptr != 0; ptr++) {
    printf("env is :%s\n", *ptr);
  }
  printf("\n\n---------------My environment variable---------\n\n");
  printf("USERNAME is :%s\n", getenv("USERNAME"));
  putenv("USERNAME=Ryanqiu");
  printf("USERNAME is :%s\n", getenv("USERNAME"));
  setenv("USERNAME", "RyanQiu", 0);
  printf("USERNAME is :%s\n", getenv("USERNAME"));
  setenv("USERNAME", "RyanQiu", 1);
  printf("USERNAME is :%s\n", getenv("USERNAME"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1196 <main+0x56>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1162 <main+0x22>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
call   1060 <putenv@plt>
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe60(%rip),%rdi
lea    0xe73(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe4b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe2e(%rip),%rdi
lea    0xe41(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xe16(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    (%rdx),%rsi
test   %rsi,%rsi
je     1186 <main+0x36>
mov    %rdx,%rbx
add    $0x8,%rbx
lea    0xe95(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1170 <main+0x20>
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
lea    0xe84(%rip),%rbx
mov    %rbx,%rdi
call   1030 <getenv@plt>
lea    0xe64(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1070 <putenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe5a(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1050 <setenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"env is :%s\0A\00"
@.str.1 = [52 x i8] c"\0A\0A---------------My environment variable---------\0A\0A\00"
@.str.2 = [17 x i8] c"USERNAME is :%s\0A\00"
@.str.3 = [9 x i8] c"USERNAME\00"
@.str.4 = [17 x i8] c"USERNAME=Ryanqiu\00"
@.str.5 = [8 x i8] c"RyanQiu\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8**
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = load i8**, i8*** %7
store i8** %9, i8*** %8
br label %10
10: ; preds = %18, %3
%11 = load i8**, i8*** %8
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i8**, i8*** %8
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %14
%19 = load i8**, i8*** %8
%20 = getelementptr inbounds i8*, i8** %19, i32 1
store i8** %20, i8*** %8
br label %10
21: ; preds = %10
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%23 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @putenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%26 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 0)
%29 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 1)
%32 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"env is :%s\0A\00"
@.str.2 = [17 x i8] c"USERNAME is :%s\0A\00"
@.str.3 = [9 x i8] c"USERNAME\00"
@.str.4 = [17 x i8] c"USERNAME=Ryanqiu\00"
@.str.5 = [8 x i8] c"RyanQiu\00"
@str = [51 x i8] c"\0A\0A---------------My environment variable---------\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture %2) {
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %3, %6
%7 = phi i8* [ %11, %6 ], [ %4, %3 ]
%8 = phi i8** [ %10, %6 ], [ %2, %3 ]
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %7)
%10 = getelementptr inbounds i8*, i8** %8, i64 1
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %6
13: ; preds = %6, %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 @putenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 0)
%21 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = tail call i32 @setenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 1)
%24 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %24)
ret i32 0
}