#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*/ puts(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int main() {
  char *p = getenv("JAVA_HOME");
  if (p)
    puts(p);
  setenv("cpp", "chenzongquan", 1);
  p = getenv("cpp");
  if (p)
    puts(p);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1163 <main+0x33>
mov    -0x10(%rbp),%rdi
call   1040 <puts@plt>
lea    0xea0(%rip),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
lea    0xe88(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119f <main+0x6f>
mov    -0x10(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     114a <main+0x1a>
mov    %rax,%rdi
call   1040 <puts@plt>
lea    0xeb9(%rip),%rbx
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117a <main+0x4a>
mov    %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"JAVA_HOME\00"
@.str.1 = [4 x i8] c"cpp\00"
@.str.2 = [13 x i8] c"chenzongquan\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i8*, i8** %2
%8 = call i32 @puts(i8* %7)
br label %9
9: ; preds = %6, %0
%10 = call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 1)
%11 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = call i32 @puts(i8* %15)
br label %17
17: ; preds = %14, %9
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [10 x i8] c"JAVA_HOME\00"
@.str.1 = [4 x i8] c"cpp\00"
@.str.2 = [13 x i8] c"chenzongquan\00"
define i32 @main() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @puts(i8* %1)
br label %5
5: ; preds = %3, %0
%6 = tail call i32 @setenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 1)
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @puts(i8* %7)
br label %11
11: ; preds = %9, %5
ret i32 0
}