#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 setenv_p(char *, char *, int);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
void test_setenv_p() {
  int ret;
  ret = setenv_p(NULL, "Idris", 0);
  assert(errno == EINVAL);
  assert(ret == -1);
  ret = setenv_p("", "Python", 0);
  assert(errno == EINVAL);
  assert(ret == -1);
  ret = setenv_p("Supi=", "Haskell", 0);
  assert(errno == EINVAL);
  assert(ret == -1);
  putenv("PROGLANG=C");
  ret = setenv_p("PROGLANG", "Rust", 0);
  assert(ret == 0);
  assert(strcmp(getenv("PROGLANG"), "C") == 0);
  ret = setenv_p("PROGLANG", "Rust", 1);
  assert(ret == 0);
  assert(strcmp(getenv("PROGLANG"), "Rust") == 0);
  ret = setenv_p("STILLGREAT", "C", 0);
  assert(ret == 0);
  assert(strcmp(getenv("STILLGREAT"), "C") == 0);
}


x86 assembly (clang, -O0):
<test_setenv_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
lea    0xe9d(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0xffffffff,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xe6c(%rip),%rdi
lea    0xe59(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%rax
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0xffffffff,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xe1d(%rip),%rdi
lea    0xe1c(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
mov    %eax,-0x4(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%rax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0xffffffff,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xde1(%rip),%rdi
call   1050 <putenv@plt>
lea    0xde0(%rip),%rdi
lea    0xde2(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xdb7(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xda7(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xd8c(%rip),%rdi
lea    0xd8e(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv_p@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xd60(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xd5b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xd43(%rip),%rdi
lea    0xd2c(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
lea    0xd1a(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
lea    0xcfc(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_setenv_p>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rsi
xor    %edi,%edi
xor    %edx,%edx
call   1040 <setenv_p@plt>
mov    %eax,%ebx
mov    0x2e72(%rip),%r14
mov    (%r14),%rax
mov    0x2e60(%rip),%r15
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
cmp    $0xffffffff,%ebx
sete   %dil
call   1070 <assert@plt>
lea    0xe77(%rip),%rdi
lea    0xe64(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
mov    %eax,%ebx
mov    (%r14),%rax
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
cmp    $0xffffffff,%ebx
sete   %dil
call   1070 <assert@plt>
lea    0xe3c(%rip),%rdi
lea    0xe3b(%rip),%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
mov    %eax,%ebx
mov    (%r14),%rax
xor    %edi,%edi
cmp    (%r15),%rax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
cmp    $0xffffffff,%ebx
sete   %dil
call   1070 <assert@plt>
lea    0xe14(%rip),%rdi
call   1050 <putenv@plt>
lea    0xe13(%rip),%rbx
lea    0xe15(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
lea    0xde1(%rip),%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <setenv_p@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
lea    0xd95(%rip),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <setenv_p@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <assert@plt>

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

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