#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*/ errno;
scalar_t__ is_licensed_prog();
scalar_t__ is_protected_entry(char const *);
int real_unlink(char const *);
int evil_unlink(const char *pathname) {
  int ret = 0;
  if (is_licensed_prog())
    goto green;
  if (is_protected_entry(pathname))
    goto red;
green:
  ret = real_unlink(pathname);
  return ret;
red:
  errno = EPERM;
  return -1;
}


x86 assembly (clang, -O0):
<evil_unlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <is_licensed_prog@plt>
cmp    $0x0,%rax
je     1159 <evil_unlink+0x29>
jmp    1176 <evil_unlink+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <is_protected_entry@plt>
cmp    $0x0,%rax
je     1171 <evil_unlink+0x41>
jmp    118d <evil_unlink+0x5d>
jmp    1176 <evil_unlink+0x46>
mov    -0x10(%rbp),%rdi
call   1050 <real_unlink@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <evil_unlink+0x76>
mov    0x2e3c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e43(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evil_unlink>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <is_licensed_prog@plt>
test   %rax,%rax
je     1149 <evil_unlink+0x19>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <real_unlink@plt>
mov    %rbx,%rdi
call   1030 <is_protected_entry@plt>
test   %rax,%rax
je     1140 <evil_unlink+0x10>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    0x2e7a(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EPERM = global i32 0
@errno = global i32 0
define i32 @evil_unlink(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%5 = call i64 (...) @is_licensed_prog()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
br label %14
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @is_protected_entry(i8* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
br label %18
13: ; preds = %8
br label %14
14: ; preds = %13, %7
%15 = load i8*, i8** %3
%16 = call i32 @real_unlink(i8* %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %20
18: ; preds = %12
%19 = load i32, i32* @EPERM
store i32 %19, i32* @errno
store i32 -1, i32* %2
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@EPERM = global i32 0
@errno = global i32 0
define i32 @evil_unlink(i8* %0) {
%2 = tail call i64 (...) @is_licensed_prog()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i64 @is_protected_entry(i8* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4, %1
%8 = tail call i32 @real_unlink(i8* %0)
br label %11
9: ; preds = %4
%10 = load i32, i32* @EPERM
store i32 %10, i32* @errno
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ %8, %7 ], [ -1, %9 ]
ret i32 %12
}