#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 */
scalar_t__ EINVAL;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ putenv(char *);
int unsetenv_p(char *);
void test_unsetenv_p() {
  int ret;
  putenv("REMOVE_THIS=JAVA");
  ret = unsetenv_p(NULL);
  assert(errno == EINVAL);
  assert(ret == -1);
  assert(getenv("REMOVE_THIS") != NULL);
  ret = unsetenv_p("");
  assert(errno == EINVAL);
  assert(ret == -1);
  assert(getenv("REMOVE_THIS") != NULL);
  ret = unsetenv_p("REMOVE_THIS=");
  assert(errno == EINVAL);
  assert(ret == -1);
  assert(getenv("REMOVE_THIS") != NULL);
  ret = unsetenv_p("REMOVE_THIS");
  assert(ret == 0);
  assert(getenv("REMOVE_THIS") == NULL);
}


x86 assembly (clang, -O0):
<test_unsetenv_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <putenv@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <unsetenv_p@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0xffffffff,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe78(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe73(%rip),%rdi
call   1060 <unsetenv_p@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0xffffffff,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe1a(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe09(%rip),%rdi
call   1060 <unsetenv_p@plt>
mov    %eax,-0x4(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%rax
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0xffffffff,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xdbc(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xd9f(%rip),%rdi
call   1060 <unsetenv_p@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xd7f(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_unsetenv_p>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
call   1040 <putenv@plt>
xor    %edi,%edi
call   1060 <unsetenv_p@plt>
mov    %eax,%ebx
mov    0x2e7d(%rip),%r14
mov    (%r14),%rax
mov    0x2e6b(%rip),%r15
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmp    $0xffffffff,%ebx
sete   %dil
call   1050 <assert@plt>
lea    0xe81(%rip),%rbx
mov    %rbx,%rdi
call   1030 <getenv@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
lea    0xe7c(%rip),%rdi
call   1060 <unsetenv_p@plt>
mov    %eax,%ebp
mov    (%r14),%rax
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmp    $0xffffffff,%ebp
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
lea    0xe2d(%rip),%rdi
call   1060 <unsetenv_p@plt>
mov    %eax,%ebp
mov    (%r14),%rax
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmp    $0xffffffff,%ebp
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1060 <unsetenv_p@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <assert@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"REMOVE_THIS=JAVA\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [12 x i8] c"REMOVE_THIS\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [13 x i8] c"REMOVE_THIS=\00"
define void @test_unsetenv_p() {
%1 = alloca i32
%2 = call i32 @putenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @unsetenv_p(i8* null)
store i32 %3, i32* %1
%4 = load i64, i64* @errno
%5 = load i64, i64* @EINVAL
%6 = icmp eq i64 %4, %5
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, -1
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i32* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @unsetenv_p(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
store i32 %17, i32* %1
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINVAL
%20 = icmp eq i64 %18, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, -1
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32* %27, null
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i32 @unsetenv_p(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 %31, i32* %1
%32 = load i64, i64* @errno
%33 = load i64, i64* @EINVAL
%34 = icmp eq i64 %32, %33
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i32, i32* %1
%38 = icmp eq i32 %37, -1
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = call i32* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp ne i32* %41, null
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = call i32 @unsetenv_p(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 %45, i32* %1
%46 = load i32, i32* %1
%47 = icmp eq i32 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = call i32* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp eq i32* %50, null
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"REMOVE_THIS=JAVA\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [12 x i8] c"REMOVE_THIS\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [13 x i8] c"REMOVE_THIS=\00"
define void @test_unsetenv_p() {
%1 = tail call i32 @putenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @unsetenv_p(i8* null)
%3 = load i64, i64* @errno
%4 = load i64, i64* @EINVAL
%5 = icmp eq i64 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp eq i32 %2, -1
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i32* %11, null
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @unsetenv_p(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINVAL
%18 = icmp eq i64 %16, %17
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = icmp eq i32 %15, -1
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = tail call i32* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp ne i32* %24, null
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = tail call i32 @unsetenv_p(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%29 = load i64, i64* @errno
%30 = load i64, i64* @EINVAL
%31 = icmp eq i64 %29, %30
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
%34 = icmp eq i32 %28, -1
%35 = zext i1 %34 to i32
%36 = tail call i32 @assert(i32 %35)
%37 = tail call i32* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp ne i32* %37, null
%39 = zext i1 %38 to i32
%40 = tail call i32 @assert(i32 %39)
%41 = tail call i32 @unsetenv_p(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp eq i32 %41, 0
%43 = zext i1 %42 to i32
%44 = tail call i32 @assert(i32 %43)
%45 = tail call i32* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i32* %45, null
%47 = zext i1 %46 to i32
%48 = tail call i32 @assert(i32 %47)
ret void
}