#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*/ assert(int);
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
scalar_t__ strcmp(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ unsetenv(char *);
int main(void) {
  char *val1 = "x";
  char *val2 = "xx";
  char *val3 = "xxx";
  setenv("MYVAR", val1, 0);
  assert(0 == strcmp(getenv("MYVAR"), val1));
  setenv("MYVAR", val2, 1);
  assert(0 == strcmp(getenv("MYVAR"), val2));
  setenv("MYVAR", val3, 0);
  assert(0 == strcmp(getenv("MYVAR"), val2));
  putenv("MYVAR=xxxx");
  assert(0 == strcmp(getenv("MYVAR"), "xxxx"));
  unsetenv("MYVAR");
  assert(NULL == getenv("MYVAR"));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe8d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xe57(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x18(%rbp),%rsi
lea    0xe26(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    0xe15(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x20(%rbp),%rsi
lea    0xde4(%rip),%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
lea    0xdd6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xdaf(%rip),%rdi
call   1050 <putenv@plt>
lea    0xd9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    0xd9a(%rip),%rsi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xd6d(%rip),%rdi
call   1080 <unsetenv@plt>
lea    0xd61(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%r15
lea    0xe9c(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
lea    0xe66(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
lea    0xe2d(%rip),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
lea    0xdf4(%rip),%rdi
call   1050 <putenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
lea    0xde6(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %r15,%rdi
call   1080 <unsetenv@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"x\00"
@.str.1 = [3 x i8] c"xx\00"
@.str.2 = [4 x i8] c"xxx\00"
@.str.3 = [6 x i8] c"MYVAR\00"
@.str.4 = [11 x i8] c"MYVAR=xxxx\00"
@.str.5 = [5 x i8] c"xxxx\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %4
%5 = load i8*, i8** %2
%6 = call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %5, i32 0)
%7 = call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = call i64 @strcmp(i32* %7, i8* %8)
%10 = icmp eq i64 0, %9
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %3
%14 = call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %13, i32 1)
%15 = call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%16 = load i8*, i8** %3
%17 = call i64 @strcmp(i32* %15, i8* %16)
%18 = icmp eq i64 0, %17
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %4
%22 = call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %21, i32 0)
%23 = call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%24 = load i8*, i8** %3
%25 = call i64 @strcmp(i32* %23, i8* %24)
%26 = icmp eq i64 0, %25
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @putenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%31 = call i64 @strcmp(i32* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp eq i64 0, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i32 @unsetenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i32* null, %36
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"x\00"
@.str.1 = [3 x i8] c"xx\00"
@.str.2 = [4 x i8] c"xxx\00"
@.str.3 = [6 x i8] c"MYVAR\00"
@.str.4 = [11 x i8] c"MYVAR=xxxx\00"
@.str.5 = [5 x i8] c"xxxx\00"
define i32 @main() {
%1 = tail call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 0)
%2 = tail call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call i64 @strcmp(i32* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 1)
%8 = tail call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i64 @strcmp(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 @setenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 0)
%14 = tail call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i64 @strcmp(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 @putenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i64 @strcmp(i32* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i32 @unsetenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%26 = tail call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i32* %26, null
%28 = zext i1 %27 to i32
%29 = tail call i32 @assert(i32 %28)
ret i32 0
}