#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*/ EINVAL;
int /*<<< orphan*/ debug(char *);
int /*<<< orphan*/ errno;
scalar_t__ fileinpath(char const *, char *);
scalar_t__ getenv(char *);
int sys_unsetenv(char const *);
int unsetenv(const char *name) {
  if (fileinpath(name, "SUDO_TOUCHENV") || getenv("SYS_SETENV")) {
    return sys_unsetenv(name);
  }
  debug("unsetenv: ");
  errno = EINVAL;
  return -1;
}


x86 assembly (clang, -O0):
<unsetenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fileinpath@plt>
cmp    $0x0,%rax
jne    117c <unsetenv+0x3c>
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     118d <unsetenv+0x4d>
mov    -0x10(%rbp),%rdi
call   1060 <sys_unsetenv@plt>
mov    %eax,-0x4(%rbp)
jmp    11b2 <unsetenv+0x72>
lea    0xe85(%rip),%rdi
call   1040 <debug@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%ecx
mov    0x2e37(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unsetenv>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
call   1050 <fileinpath@plt>
test   %rax,%rax
jne    1166 <unsetenv+0x26>
lea    0xeb2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116f <unsetenv+0x2f>
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <sys_unsetenv@plt>
lea    0xea3(%rip),%rdi
call   1040 <debug@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
mov    0x2e55(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"SUDO_TOUCHENV\00"
@.str.1 = [11 x i8] c"SYS_SETENV\00"
@.str.2 = [11 x i8] c"unsetenv: \00"
@EINVAL = global i32 0
@errno = global i32 0
define i32 @unsetenv(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @fileinpath(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7, %1
%11 = load i8*, i8** %3
%12 = call i32 @sys_unsetenv(i8* %11)
store i32 %12, i32* %2
br label %16
13: ; preds = %7
%14 = call i32 @debug(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @EINVAL
store i32 %15, i32* @errno
store i32 -1, i32* %2
br label %16
16: ; preds = %13, %10
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@.str = [14 x i8] c"SUDO_TOUCHENV\00"
@.str.1 = [11 x i8] c"SYS_SETENV\00"
@.str.2 = [11 x i8] c"unsetenv: \00"
@EINVAL = global i32 0
@errno = global i32 0
define i32 @unsetenv(i8* %0) {
%2 = tail call i64 @fileinpath(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i64 @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4, %1
%8 = tail call i32 @sys_unsetenv(i8* %0)
br label %12
9: ; preds = %4
%10 = tail call i32 @debug(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EINVAL
store i32 %11, i32* @errno
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ %8, %7 ], [ -1, %9 ]
ret i32 %13
}