#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 stat {
  scalar_t__ st_size;
};
struct fanotify_event_metadata {
  scalar_t__ vers;
  int fd;
  size_t pid;
  int mask;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ procfd_path;
typedef int /*<<< orphan*/ procexe_path;
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EAGAIN;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ FANOTIFY_METADATA_VERSION;
int FAN_ACCESS;
int FAN_CLOSE_NOWRITE;
int FAN_CLOSE_WRITE;
struct fanotify_event_metadata *
FAN_EVENT_NEXT(struct fanotify_event_metadata const *, int);
scalar_t__ FAN_EVENT_OK(struct fanotify_event_metadata const *, int);
int FAN_MODIFY;
int FAN_OPEN;
int PATH_MAX;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, void *, int);
int readlink(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *timestamp();
void handle_events(int fd) {
  const struct fanotify_event_metadata *metadata;
  struct fanotify_event_metadata buf[200];
  ssize_t len;
  char path[PATH_MAX];
  ssize_t path_len;
  char procexe_path[PATH_MAX];
  char procfd_path[PATH_MAX];
  struct stat st;
  for (;;) {
    len = read(fd, (void *)&buf, sizeof(buf));
    if (len == -1 && errno != EAGAIN) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    if (len <= 0)
      break;
    metadata = buf;
    while (FAN_EVENT_OK(metadata, len)) {
      if (metadata->vers != FANOTIFY_METADATA_VERSION) {
        fprintf(stderr, "Mismatch of fanotify metadata version.\n");
        exit(EXIT_FAILURE);
      }
      if (metadata->fd >= 0) {
        printf("[%s] pid %d ", timestamp(), metadata->pid);
        if (fstat(metadata->fd, &st) != 0) {
          perror("fstat");
          exit(EXIT_FAILURE);
        }
        snprintf(procexe_path, sizeof(procexe_path), "/proc/%d/exe",
                 (int)metadata->pid);
        path_len = readlink(procexe_path, path, sizeof(path) - 1);
        if (path_len > 0) {
          path[path_len] = '\0';
          printf("(%s) ", path);
        }
        if (metadata->mask & FAN_OPEN) {
          printf("opens ");
        }
        if (metadata->mask & FAN_MODIFY) {
          printf("modifies ");
        }
        if (metadata->mask & FAN_ACCESS) {
          printf("reads ");
        }
        if (metadata->mask & FAN_CLOSE_WRITE) {
          printf("closes ");
        }
        if (metadata->mask & FAN_CLOSE_NOWRITE) {
          printf("closes (no write) ");
        }
        snprintf(procfd_path, sizeof(procfd_path), "/proc/self/fd/%d",
                 metadata->fd);
        path_len = readlink(procfd_path, path, sizeof(path) - 1);
        if (path_len == -1) {
          perror("readlink");
          exit(EXIT_FAILURE);
        }
        path[path_len] = '\0';
        printf("%s (size %zu)\n", path, (size_t)st.st_size);
        fflush(stdout);
        close(metadata->fd);
      }
      metadata = FAN_EVENT_NEXT(metadata, len);
    }
  }
}


x86 assembly (clang, -O0):
<handle_events>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1980,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x1978(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x1920(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x1970(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x1928(%rbp)
mov    (%rax),%ecx
mov    %rcx,-0x1968(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x1960(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x1938(%rbp)
mov    (%rax),%eax
mov    %rax,-0x1958(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1950(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x1940(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1910(%rbp),%rsi
mov    $0x1900,%edx
call   1090 <read@plt>
mov    %eax,-0x1914(%rbp)
cmpl   $0xffffffff,-0x1914(%rbp)
jne    12cb <handle_events+0xfb>
mov    0x2d02(%rip),%rax
mov    (%rax),%rax
mov    0x2cd8(%rip),%rcx
cmp    (%rcx),%rax
je     12cb <handle_events+0xfb>
lea    0xd48(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x1914(%rbp)
jg     12dd <handle_events+0x10d>
jmp    15aa <handle_events+0x3da>
lea    -0x1910(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1914(%rbp),%esi
call   10a0 <FAN_EVENT_OK@plt>
cmp    $0x0,%rax
je     15a5 <handle_events+0x3d5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2cc9(%rip),%rcx
cmp    (%rcx),%rax
je     133b <handle_events+0x16b>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,0x8(%rax)
jl     158d <handle_events+0x3bd>
mov    $0x0,%al
call   1050 <timestamp@plt>
mov    %rax,%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
lea    -0x1948(%rbp),%rsi
call   10f0 <fstat@plt>
cmp    $0x0,%rax
je     13a0 <handle_events+0x1d0>
lea    0xcad(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x1960(%rbp),%rdi
mov    -0x1968(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %eax,%ecx
lea    0xc7f(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x1960(%rbp),%rdi
mov    -0x1970(%rbp),%rsi
mov    -0x1978(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1040 <readlink@plt>
mov    %eax,-0x192c(%rbp)
cmpl   $0x0,-0x192c(%rbp)
jle    1419 <handle_events+0x249>
mov    -0x1970(%rbp),%rsi
movslq -0x192c(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xc3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%eax
mov    0x2b81(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1440 <handle_events+0x270>
lea    0xc1a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%eax
mov    0x2b92(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1467 <handle_events+0x297>
lea    0xbfa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%eax
mov    0x2b53(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     148e <handle_events+0x2be>
lea    0xbdd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%eax
mov    0x2b34(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14b5 <handle_events+0x2e5>
lea    0xbbd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%eax
mov    0x2afd(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14dc <handle_events+0x30c>
lea    0xb9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1950(%rbp),%rdi
mov    -0x1958(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xb8c(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x1950(%rbp),%rdi
mov    -0x1970(%rbp),%rsi
mov    -0x1978(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%edx
call   1040 <readlink@plt>
mov    %eax,-0x192c(%rbp)
cmpl   $0xffffffff,-0x192c(%rbp)
jne    154c <handle_events+0x37c>
lea    0xb5e(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2a53(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x1970(%rbp),%rsi
movslq -0x192c(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
mov    -0x1948(%rbp),%rdx
lea    0xb34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2a16(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1914(%rbp),%esi
call   1030 <FAN_EVENT_NEXT@plt>
mov    %rax,-0x10(%rbp)
jmp    12e8 <handle_events+0x118>
jmp    1270 <handle_events+0xa0>
mov    -0x1920(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_events>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1928,%rsp
mov    %rsp,-0x48(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
mov    %rcx,-0x30(%rbp)
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%eax
mov    %rsp,%r13
mov    %rax,-0x40(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
lea    -0x1950(%rbp),%rsi
mov    %edi,-0x34(%rbp)
mov    $0x1900,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     1466 <handle_events+0x296>
mov    %eax,%r15d
mov    -0x30(%rbp),%rax
add    $0xffffffff,%eax
mov    %rax,-0x30(%rbp)
jmp    1280 <handle_events+0xb0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x34(%rbp),%edi
lea    -0x1950(%rbp),%rsi
mov    $0x1900,%edx
call   1090 <read@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1466 <handle_events+0x296>
test   %r15d,%r15d
jle    147c <handle_events+0x2ac>
lea    -0x1950(%rbp),%rdi
mov    %r15d,%esi
call   10a0 <FAN_EVENT_OK@plt>
test   %rax,%rax
je     1260 <handle_events+0x90>
lea    -0x1950(%rbp),%r12
jmp    1335 <handle_events+0x165>
nopl   0x0(%rax)
mov    0x8(%r12),%ecx
mov    %r14,%rdi
mov    -0x40(%rbp),%rsi
lea    0xdc3(%rip),%rdx
call   1070 <snprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    -0x30(%rbp),%rdx
call   1040 <readlink@plt>
cmp    $0xffffffff,%eax
je     14a6 <handle_events+0x2d6>
cltq
movb   $0x0,(%rbx,%rax,1)
mov    -0x50(%rbp),%rdx
lea    0xdaf(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
mov    0x8(%r12),%edi
call   1080 <close@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1030 <FAN_EVENT_NEXT@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15d,%esi
call   10a0 <FAN_EVENT_OK@plt>
test   %rax,%rax
je     1260 <handle_events+0x90>
mov    (%r12),%rax
mov    0x2c98(%rip),%rcx
cmp    (%rcx),%rax
jne    148f <handle_events+0x2bf>
cmpl   $0x0,0x8(%r12)
js     1313 <handle_events+0x143>
xor    %eax,%eax
call   1050 <timestamp@plt>
mov    0x10(%r12),%rdx
lea    0xcc9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%r12),%edi
lea    -0x50(%rbp),%rsi
call   10f0 <fstat@plt>
test   %rax,%rax
jne    14af <handle_events+0x2df>
mov    0x10(%r12),%ecx
mov    %r13,%rdi
mov    -0x40(%rbp),%rsi
lea    0xca8(%rip),%rdx
call   1070 <snprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    -0x30(%rbp),%rdx
call   1040 <readlink@plt>
test   %eax,%eax
jle    13c7 <handle_events+0x1f7>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
lea    0xc90(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%r12),%eax
mov    0x2bd5(%rip),%rcx
test   %eax,(%rcx)
je     13ea <handle_events+0x21a>
lea    0xc75(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%r12),%eax
mov    0x2bef(%rip),%rcx
test   %eax,(%rcx)
je     1408 <handle_events+0x238>
lea    0xc5e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%r12),%eax
mov    0x2bb9(%rip),%rcx
test   %eax,(%rcx)
je     1426 <handle_events+0x256>
lea    0xc4a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%r12),%eax
mov    0x2ba3(%rip),%rcx
test   %eax,(%rcx)
je     1444 <handle_events+0x274>
lea    0xc33(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%r12),%eax
mov    0x2b75(%rip),%rcx
test   %eax,(%rcx)
je     12b0 <handle_events+0xe0>
lea    0xc19(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12b0 <handle_events+0xe0>
mov    0x2b33(%rip),%rax
mov    (%rax),%rax
mov    0x2b09(%rip),%rcx
cmp    (%rcx),%rax
jne    14c9 <handle_events+0x2f9>
mov    -0x48(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b1a(%rip),%rax
mov    (%rax),%edi
lea    0xb66(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    14bb <handle_events+0x2eb>
lea    0xbea(%rip),%rdi
jmp    14b6 <handle_events+0x2e6>
lea    0xb84(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2ad6(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0xb30(%rip),%rdi
jmp    14b6 <handle_events+0x2e6>

LLVM IR (-O0):
%struct.fanotify_event_metadata = type { i64, i32, i64, i32 }
%struct.stat = type { i64 }
@PATH_MAX = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@FANOTIFY_METADATA_VERSION = global i64 0
@stderr = global i32 0
@.str.1 = [40 x i8] c"Mismatch of fanotify metadata version.\0A\00"
@.str.2 = [13 x i8] c"[%s] pid %d \00"
@.str.3 = [6 x i8] c"fstat\00"
@.str.4 = [13 x i8] c"/proc/%d/exe\00"
@.str.5 = [6 x i8] c"(%s) \00"
@FAN_OPEN = global i32 0
@.str.6 = [7 x i8] c"opens \00"
@FAN_MODIFY = global i32 0
@.str.7 = [10 x i8] c"modifies \00"
@FAN_ACCESS = global i32 0
@.str.8 = [7 x i8] c"reads \00"
@FAN_CLOSE_WRITE = global i32 0
@.str.9 = [8 x i8] c"closes \00"
@FAN_CLOSE_NOWRITE = global i32 0
@.str.10 = [19 x i8] c"closes (no write) \00"
@.str.11 = [17 x i8] c"/proc/self/fd/%d\00"
@.str.12 = [9 x i8] c"readlink\00"
@.str.13 = [15 x i8] c"%s (size %zu)\0A\00"
@stdout = global i32 0
define void @handle_events(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.fanotify_event_metadata*
%4 = alloca [200 x %struct.fanotify_event_metadata]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca %struct.stat
store i32 %0, i32* %2
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
store i64 %17, i64* %9
%19 = load i32, i32* @PATH_MAX
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
store i64 %20, i64* %10
br label %22
22: ; preds = %172, %1
%23 = load i32, i32* %2
%24 = bitcast [200 x %struct.fanotify_event_metadata]* %4 to i8*
%25 = call i32 @read(i32 %23, i8* %24, i32 6400)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %36
28: ; preds = %22
%29 = load i64, i64* @errno
%30 = load i64, i64* @EAGAIN
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %28, %22
%37 = load i32, i32* %5
%38 = icmp sle i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %36
br label %173
40: ; preds = %36
%41 = getelementptr inbounds [200 x %struct.fanotify_event_metadata], [200 x %struct.fanotify_event_metadata]* %4, i64 0, i64 0
store %struct.fanotify_event_metadata* %41, %struct.fanotify_event_metadata** %3
br label %42
42: ; preds = %168, %40
%43 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%44 = load i32, i32* %5
%45 = call i64 @FAN_EVENT_OK(%struct.fanotify_event_metadata* %43, i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %172
47: ; preds = %42
%48 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%49 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %48, i32 0, i32 0
%50 = load i64, i64* %49
%51 = load i64, i64* @FANOTIFY_METADATA_VERSION
%52 = icmp ne i64 %50, %51
br i1 %52, label %53, label %58
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %47
%59 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%60 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = icmp sge i32 %61, 0
br i1 %62, label %63, label %168
63: ; preds = %58
%64 = call i8* (...) @timestamp()
%65 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%66 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %65, i32 0, i32 2
%67 = load i64, i64* %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %64, i64 %67)
%69 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%70 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = call i64 @fstat(i32 %71, %struct.stat* %11)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %63
%75 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %63
%79 = trunc i64 %17 to i32
%80 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%81 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %80, i32 0, i32 2
%82 = load i64, i64* %81
%83 = trunc i64 %82 to i32
%84 = call i32 @snprintf(i8* %18, i32 %79, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %83)
%85 = sub i64 %13, 1
%86 = trunc i64 %85 to i32
%87 = call i32 @readlink(i8* %18, i8* %15, i32 %86)
store i32 %87, i32* %8
%88 = load i32, i32* %8
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %95
90: ; preds = %78
%91 = load i32, i32* %8
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %15, i64 %92
store i8 0, i8* %93
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %15)
br label %95
95: ; preds = %90, %78
%96 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%97 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %96, i32 0, i32 3
%98 = load i32, i32* %97
%99 = load i32, i32* @FAN_OPEN
%100 = and i32 %98, %99
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %95
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %104
104: ; preds = %102, %95
%105 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%106 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %105, i32 0, i32 3
%107 = load i32, i32* %106
%108 = load i32, i32* @FAN_MODIFY
%109 = and i32 %107, %108
%110 = icmp ne i32 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %104
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %113
113: ; preds = %111, %104
%114 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%115 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %114, i32 0, i32 3
%116 = load i32, i32* %115
%117 = load i32, i32* @FAN_ACCESS
%118 = and i32 %116, %117
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %113
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %122
122: ; preds = %120, %113
%123 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%124 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %123, i32 0, i32 3
%125 = load i32, i32* %124
%126 = load i32, i32* @FAN_CLOSE_WRITE
%127 = and i32 %125, %126
%128 = icmp ne i32 %127, 0
br i1 %128, label %129, label %131
129: ; preds = %122
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %131
131: ; preds = %129, %122
%132 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%133 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %132, i32 0, i32 3
%134 = load i32, i32* %133
%135 = load i32, i32* @FAN_CLOSE_NOWRITE
%136 = and i32 %134, %135
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %140
138: ; preds = %131
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %140
140: ; preds = %138, %131
%141 = trunc i64 %20 to i32
%142 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%143 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %142, i32 0, i32 1
%144 = load i32, i32* %143
%145 = call i32 @snprintf(i8* %21, i32 %141, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i32 %144)
%146 = sub i64 %13, 1
%147 = trunc i64 %146 to i32
%148 = call i32 @readlink(i8* %21, i8* %15, i32 %147)
store i32 %148, i32* %8
%149 = load i32, i32* %8
%150 = icmp eq i32 %149, -1
br i1 %150, label %151, label %155
151: ; preds = %140
%152 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%153 = load i32, i32* @EXIT_FAILURE
%154 = call i32 @exit(i32 %153)
unreachable
155: ; preds = %140
%156 = load i32, i32* %8
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds i8, i8* %15, i64 %157
store i8 0, i8* %158
%159 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%160 = load i64, i64* %159
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i8* %15, i64 %160)
%162 = load i32, i32* @stdout
%163 = call i32 @fflush(i32 %162)
%164 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%165 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %164, i32 0, i32 1
%166 = load i32, i32* %165
%167 = call i32 @close(i32 %166)
br label %168
168: ; preds = %155, %58
%169 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%170 = load i32, i32* %5
%171 = call %struct.fanotify_event_metadata* @FAN_EVENT_NEXT(%struct.fanotify_event_metadata* %169, i32 %170)
store %struct.fanotify_event_metadata* %171, %struct.fanotify_event_metadata** %3
br label %42
172: ; preds = %42
br label %22
173: ; preds = %39
%174 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
%struct.fanotify_event_metadata = type { i64, i32, i64, i32 }
%struct.stat = type { i64 }
@PATH_MAX = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@FANOTIFY_METADATA_VERSION = global i64 0
@stderr = global i32 0
@.str.1 = [40 x i8] c"Mismatch of fanotify metadata version.\0A\00"
@.str.2 = [13 x i8] c"[%s] pid %d \00"
@.str.3 = [6 x i8] c"fstat\00"
@.str.4 = [13 x i8] c"/proc/%d/exe\00"
@.str.5 = [6 x i8] c"(%s) \00"
@FAN_OPEN = global i32 0
@.str.6 = [7 x i8] c"opens \00"
@FAN_MODIFY = global i32 0
@.str.7 = [10 x i8] c"modifies \00"
@FAN_ACCESS = global i32 0
@.str.8 = [7 x i8] c"reads \00"
@FAN_CLOSE_WRITE = global i32 0
@.str.9 = [8 x i8] c"closes \00"
@FAN_CLOSE_NOWRITE = global i32 0
@.str.10 = [19 x i8] c"closes (no write) \00"
@.str.11 = [17 x i8] c"/proc/self/fd/%d\00"
@.str.12 = [9 x i8] c"readlink\00"
@.str.13 = [15 x i8] c"%s (size %zu)\0A\00"
@stdout = global i32 0
define void @handle_events(i32 %0) {
%2 = alloca [200 x %struct.fanotify_event_metadata]
%3 = alloca %struct.stat
%4 = bitcast [200 x %struct.fanotify_event_metadata]* %2 to i8*
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = alloca i8, i64 %10
%13 = bitcast %struct.stat* %3 to i8*
%14 = call i32 @read(i32 %0, i8* %4, i32 6400)
%15 = icmp eq i32 %14, -1
br i1 %15, label %23, label %16
16: ; preds = %1
%17 = getelementptr inbounds [200 x %struct.fanotify_event_metadata], [200 x %struct.fanotify_event_metadata]* %2, i64 0, i64 0
%18 = add i32 %5, -1
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %31
20: ; preds = %132, %34
%21 = call i32 @read(i32 %0, i8* %4, i32 6400)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %31
23: ; preds = %20, %1
%24 = load i64, i64* @errno
%25 = load i64, i64* @EAGAIN
%26 = icmp eq i64 %24, %25
br i1 %26, label %136, label %27
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %16, %20
%32 = phi i32 [ %14, %16 ], [ %21, %20 ]
%33 = icmp slt i32 %32, 1
br i1 %33, label %136, label %34
34: ; preds = %31
%35 = call i64 @FAN_EVENT_OK(%struct.fanotify_event_metadata* %17, i32 %32)
%36 = icmp eq i64 %35, 0
br i1 %36, label %20, label %37
37: ; preds = %34, %132
%38 = phi %struct.fanotify_event_metadata* [ %133, %132 ], [ %17, %34 ]
%39 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %38, i64 0, i32 0
%40 = load i64, i64* %39
%41 = load i64, i64* @FANOTIFY_METADATA_VERSION
%42 = icmp eq i64 %40, %41
br i1 %42, label %48, label %43
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %37
%49 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %38, i64 0, i32 1
%50 = load i32, i32* %49
%51 = icmp sgt i32 %50, -1
br i1 %51, label %52, label %132
52: ; preds = %48
%53 = call i8* (...) @timestamp()
%54 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %38, i64 0, i32 2
%55 = load i64, i64* %54
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %53, i64 %55)
%57 = load i32, i32* %49
%58 = call i64 @fstat(i32 %57, %struct.stat* %3)
%59 = icmp eq i64 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %52
%61 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %52
%65 = load i64, i64* %54
%66 = trunc i64 %65 to i32
%67 = call i32 @snprintf(i8* %11, i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %66)
%68 = call i32 @readlink(i8* %11, i8* %8, i32 %18)
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %64
%71 = zext i32 %68 to i64
%72 = getelementptr inbounds i8, i8* %8, i64 %71
store i8 0, i8* %72
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %8)
br label %74
74: ; preds = %70, %64
%75 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %38, i64 0, i32 3
%76 = load i32, i32* %75
%77 = load i32, i32* @FAN_OPEN
%78 = and i32 %77, %76
%79 = icmp eq i32 %78, 0
br i1 %79, label %83, label %80
80: ; preds = %74
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%82 = load i32, i32* %75
br label %83
83: ; preds = %80, %74
%84 = phi i32 [ %82, %80 ], [ %76, %74 ]
%85 = load i32, i32* @FAN_MODIFY
%86 = and i32 %85, %84
%87 = icmp eq i32 %86, 0
br i1 %87, label %91, label %88
88: ; preds = %83
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%90 = load i32, i32* %75
br label %91
91: ; preds = %88, %83
%92 = phi i32 [ %90, %88 ], [ %84, %83 ]
%93 = load i32, i32* @FAN_ACCESS
%94 = and i32 %93, %92
%95 = icmp eq i32 %94, 0
br i1 %95, label %99, label %96
96: ; preds = %91
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%98 = load i32, i32* %75
br label %99
99: ; preds = %96, %91
%100 = phi i32 [ %98, %96 ], [ %92, %91 ]
%101 = load i32, i32* @FAN_CLOSE_WRITE
%102 = and i32 %101, %100
%103 = icmp eq i32 %102, 0
br i1 %103, label %107, label %104
104: ; preds = %99
%105 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%106 = load i32, i32* %75
br label %107
107: ; preds = %104, %99
%108 = phi i32 [ %106, %104 ], [ %100, %99 ]
%109 = load i32, i32* @FAN_CLOSE_NOWRITE
%110 = and i32 %109, %108
%111 = icmp eq i32 %110, 0
br i1 %111, label %114, label %112
112: ; preds = %107
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %114
114: ; preds = %112, %107
%115 = load i32, i32* %49
%116 = call i32 @snprintf(i8* %12, i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i32 %115)
%117 = call i32 @readlink(i8* %12, i8* %8, i32 %18)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %123
119: ; preds = %114
%120 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%121 = load i32, i32* @EXIT_FAILURE
%122 = call i32 @exit(i32 %121)
unreachable
123: ; preds = %114
%124 = sext i32 %117 to i64
%125 = getelementptr inbounds i8, i8* %8, i64 %124
store i8 0, i8* %125
%126 = load i64, i64* %19
%127 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i8* %8, i64 %126)
%128 = load i32, i32* @stdout
%129 = call i32 @fflush(i32 %128)
%130 = load i32, i32* %49
%131 = call i32 @close(i32 %130)
br label %132
132: ; preds = %123, %48
%133 = call %struct.fanotify_event_metadata* @FAN_EVENT_NEXT(%struct.fanotify_event_metadata* %38, i32 %32)
%134 = call i64 @FAN_EVENT_OK(%struct.fanotify_event_metadata* %133, i32 %32)
%135 = icmp eq i64 %134, 0
br i1 %135, label %20, label %37
136: ; preds = %31, %23
ret void
}