#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*/ EPERM;
int /*<<< orphan*/ debug(char *);
int /*<<< orphan*/ errno;
scalar_t__ fileinpath(char const *, char *);
scalar_t__ getenv(char *);
int sys_unlink(char const *);
int unlink(const char *path) {
  if (fileinpath(path, "SUDO_ALLOWED") || getenv("SYS_UNLINK")) {
    return sys_unlink(path);
  }
  debug("unlink: ");
  errno = EPERM;
  return -1;
}


x86 assembly (clang, -O0):
<unlink>:
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 <unlink+0x3c>
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     118d <unlink+0x4d>
mov    -0x10(%rbp),%rdi
call   1060 <sys_unlink@plt>
mov    %eax,-0x4(%rbp)
jmp    11b2 <unlink+0x72>
lea    0xe84(%rip),%rdi
call   1040 <debug@plt>
mov    0x2e30(%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):
<unlink>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
call   1050 <fileinpath@plt>
test   %rax,%rax
jne    1166 <unlink+0x26>
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116f <unlink+0x2f>
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <sys_unlink@plt>
lea    0xea2(%rip),%rdi
call   1040 <debug@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    0x2e55(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"SUDO_ALLOWED\00"
@.str.1 = [11 x i8] c"SYS_UNLINK\00"
@.str.2 = [9 x i8] c"unlink: \00"
@EPERM = global i32 0
@errno = global i32 0
define i32 @unlink(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 ([13 x i8], [13 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_unlink(i8* %11)
store i32 %12, i32* %2
br label %16
13: ; preds = %7
%14 = call i32 @debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* @EPERM
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 = [13 x i8] c"SUDO_ALLOWED\00"
@.str.1 = [11 x i8] c"SYS_UNLINK\00"
@.str.2 = [9 x i8] c"unlink: \00"
@EPERM = global i32 0
@errno = global i32 0
define i32 @unlink(i8* %0) {
%2 = tail call i64 @fileinpath(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 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_unlink(i8* %0)
br label %12
9: ; preds = %4
%10 = tail call i32 @debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EPERM
store i32 %11, i32* @errno
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ %8, %7 ], [ -1, %9 ]
ret i32 %13
}