#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*/ LOG_INFO;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ closelog();
char *getenv(char *);
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *);
int tag_file_opened(const char *path) {
  static const char *watched_path_prefix = NULL;
  if (watched_path_prefix == NULL) {
    watched_path_prefix = getenv("WATCHED_PATH_PREFIX");
  }
  if (strncmp(path, watched_path_prefix, strlen(watched_path_prefix)) == 0) {
    openlog("daryl_fopen_shim", 0, LOG_USER);
    syslog(LOG_INFO, "ATTEMPTING TO OPEN: %s", path);
    closelog();
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<tag_file_opened>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,0x2ee4(%rip)
jne    118d <tag_file_opened+0x2d>
lea    0xe7f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ecb(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ebc(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2eb1(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1208 <tag_file_opened+0xa8>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
lea    0xe3f(%rip),%rdi
xor    %esi,%esi
call   1080 <openlog@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1070 <syslog@plt>
mov    $0x0,%al
call   1040 <closelog@plt>
movl   $0x1,-0x4(%rbp)
jmp    120f <tag_file_opened+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag_file_opened>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eea(%rip),%rbx
test   %rbx,%rbx
jne    1189 <tag_file_opened+0x29>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %rax,0x2ecf(%rip)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11e3 <tag_file_opened+0x83>
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
lea    0xe5c(%rip),%rdi
xor    %esi,%esi
call   1080 <openlog@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
mov    %r14,%rdx
call   1070 <syslog@plt>
xor    %eax,%eax
call   1040 <closelog@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@tag_file_opened.watched_path_prefix = internal global i8* null
@.str = [20 x i8] c"WATCHED_PATH_PREFIX\00"
@.str.1 = [17 x i8] c"daryl_fopen_shim\00"
@LOG_USER = global i32 0
@LOG_INFO = global i32 0
@.str.2 = [23 x i8] c"ATTEMPTING TO OPEN: %s\00"
define i32 @tag_file_opened(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** @tag_file_opened.watched_path_prefix
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** @tag_file_opened.watched_path_prefix
br label %8
8: ; preds = %6, %1
%9 = load i8*, i8** %3
%10 = load i8*, i8** @tag_file_opened.watched_path_prefix
%11 = load i8*, i8** @tag_file_opened.watched_path_prefix
%12 = call i32 @strlen(i8* %11)
%13 = call i64 @strncmp(i8* %9, i8* %10, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %8
%16 = load i32, i32* @LOG_USER
%17 = call i32 @openlog(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %16)
%18 = load i32, i32* @LOG_INFO
%19 = load i8*, i8** %3
%20 = call i32 @syslog(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = call i32 (...) @closelog()
store i32 1, i32* %2
br label %23
22: ; preds = %8
store i32 0, i32* %2
br label %23
23: ; preds = %22, %15
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@tag_file_opened.watched_path_prefix = internal unnamed_addr global i8* null
@.str = [20 x i8] c"WATCHED_PATH_PREFIX\00"
@.str.1 = [17 x i8] c"daryl_fopen_shim\00"
@LOG_USER = global i32 0
@LOG_INFO = global i32 0
@.str.2 = [23 x i8] c"ATTEMPTING TO OPEN: %s\00"
define i32 @tag_file_opened(i8* %0) {
%2 = load i8*, i8** @tag_file_opened.watched_path_prefix
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** @tag_file_opened.watched_path_prefix
br label %6
6: ; preds = %4, %1
%7 = phi i8* [ %5, %4 ], [ %2, %1 ]
%8 = tail call i32 @strlen(i8* %7)
%9 = tail call i64 @strncmp(i8* %0, i8* %7, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i32, i32* @LOG_USER
%13 = tail call i32 @openlog(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %12)
%14 = load i32, i32* @LOG_INFO
%15 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%16 = tail call i32 (...) @closelog()
br label %17
17: ; preds = %6, %11
%18 = phi i32 [ 1, %11 ], [ 0, %6 ]
ret i32 %18
}