#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 */
struct timeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EPERM;
int /*<<< orphan*/ errno;
scalar_t__ is_licensed_prog();
scalar_t__ is_protected_atfile(int, char const *);
int real_futimesat(int, char const *, struct timeval const *);
int evil_futimesat(int dirfd, const char *pathname,
                   const struct timeval times[2]) {
  int ret = 0;
  if (is_licensed_prog())
    goto green;
  if (is_protected_atfile(dirfd, pathname))
    goto red;
green:
  ret = real_futimesat(dirfd, pathname, times);
  return ret;
red:
  errno = EPERM;
  return -1;
}


x86 assembly (clang, -O0):
<evil_futimesat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <is_licensed_prog@plt>
cmp    $0x0,%rax
je     1160 <evil_futimesat+0x30>
jmp    1180 <evil_futimesat+0x50>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <is_protected_atfile@plt>
cmp    $0x0,%rax
je     117b <evil_futimesat+0x4b>
jmp    119e <evil_futimesat+0x6e>
jmp    1180 <evil_futimesat+0x50>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <real_futimesat@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b7 <evil_futimesat+0x87>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e32(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evil_futimesat>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <is_licensed_prog@plt>
test   %rax,%rax
je     1159 <evil_futimesat+0x29>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <real_futimesat@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <is_protected_atfile@plt>
test   %rax,%rax
je     1148 <evil_futimesat+0x18>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    0x2e68(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@EPERM = global i32 0
@errno = global i32 0
define i32 @evil_futimesat(i32 %0, i8* %1, %struct.timeval* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.timeval*
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store %struct.timeval* %2, %struct.timeval** %7
store i32 0, i32* %8
%9 = call i64 (...) @is_licensed_prog()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
br label %19
12: ; preds = %3
%13 = load i32, i32* %5
%14 = load i8*, i8** %6
%15 = call i64 @is_protected_atfile(i32 %13, i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %25
18: ; preds = %12
br label %19
19: ; preds = %18, %11
%20 = load i32, i32* %5
%21 = load i8*, i8** %6
%22 = load %struct.timeval*, %struct.timeval** %7
%23 = call i32 @real_futimesat(i32 %20, i8* %21, %struct.timeval* %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
store i32 %24, i32* %4
br label %27
25: ; preds = %17
%26 = load i32, i32* @EPERM
store i32 %26, i32* @errno
store i32 -1, i32* %4
br label %27
27: ; preds = %25, %19
%28 = load i32, i32* %4
ret i32 %28
}

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