#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 main(int argc, char *argv[], char *envp[]) {
  int i;
  for (i = 0; envp[i] != NULL; i++) {
    printf("%s\n", envp[i]);
  }
  printf("\nPATH=%s\n\n", getenv("PATH"));
  putenv("PATH=/usr/bin");
  printf("PATH=%s\n", getenv("PATH"));
  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)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     118a <main+0x5a>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <main+0x21>
lea    0xe7a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
call   1050 <putenv@plt>
lea    0xe53(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    (%rdx),%rsi
test   %rsi,%rsi
je     1164 <main+0x34>
mov    %rdx,%rbx
add    $0x8,%rbx
lea    0xed9(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    (%rbx),%rsi
add    $0x8,%rbx
test   %rsi,%rsi
jne    1150 <main+0x20>
lea    0xea0(%rip),%rbx
mov    %rbx,%rdi
call   1030 <getenv@plt>
lea    0xe86(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
call   1050 <putenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
lea    0xe81(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [11 x i8] c"\0APATH=%s\0A\0A\00"
@.str.2 = [5 x i8] c"PATH\00"
@.str.3 = [14 x i8] c"PATH=/usr/bin\00"
@.str.4 = [9 x i8] c"PATH=%s\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 0, i32* %8
br label %9
9: ; preds = %23, %3
%10 = load i8**, i8*** %7
%11 = load i32, i32* %8
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %26
16: ; preds = %9
%17 = load i8**, i8*** %7
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %9
26: ; preds = %9
%27 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @putenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%30 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [11 x i8] c"\0APATH=%s\0A\0A\00"
@.str.2 = [5 x i8] c"PATH\00"
@.str.3 = [14 x i8] c"PATH=/usr/bin\00"
@.str.4 = [9 x i8] c"PATH=%s\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 %14, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %10, %6 ], [ 0, %3 ]
%8 = phi i8* [ %12, %6 ], [ %4, %3 ]
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = add nuw i64 %7, 1
%11 = getelementptr inbounds i8*, i8** %2, i64 %10
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %6
14: ; preds = %6, %3
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = tail call i32 @putenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %18)
ret i32 0
}