#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 utimbuf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EPERM;
int /*<<< orphan*/ errno;
scalar_t__ is_licensed_prog();
scalar_t__ is_protected_file(char const *);
int real_utime(char const *, struct utimbuf const *);
int evil_utime(const char *filename, const struct utimbuf *times) {
  int ret = 0;
  if (is_licensed_prog())
    goto green;
  if (is_protected_file(filename))
    goto red;
green:
  ret = real_utime(filename, times);
  return ret;
red:
  errno = EPERM;
  return -1;
}


x86 assembly (clang, -O0):
<evil_utime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <is_licensed_prog@plt>
cmp    $0x0,%rax
je     115d <evil_utime+0x2d>
jmp    117a <evil_utime+0x4a>
mov    -0x10(%rbp),%rdi
call   1050 <is_protected_file@plt>
cmp    $0x0,%rax
je     1175 <evil_utime+0x45>
jmp    1195 <evil_utime+0x65>
jmp    117a <evil_utime+0x4a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <real_utime@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <evil_utime+0x7e>
mov    0x2e34(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3b(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evil_utime>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <is_licensed_prog@plt>
test   %rax,%rax
je     1158 <evil_utime+0x28>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <real_utime@plt>
mov    %rbx,%rdi
call   1050 <is_protected_file@plt>
test   %rax,%rax
je     1146 <evil_utime+0x16>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    0x2e6b(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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