#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_response {
  int dummy;
};
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 fanotify_response response;
  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,-0x1980(%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,-0x1978(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x1928(%rbp)
mov    (%rax),%ecx
mov    %rcx,-0x1970(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x1968(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x1938(%rbp)
mov    (%rax),%eax
mov    %rax,-0x1960(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1958(%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    -0x1950(%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    -0x1968(%rbp),%rdi
mov    -0x1970(%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    -0x1968(%rbp),%rdi
mov    -0x1978(%rbp),%rsi
mov    -0x1980(%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    -0x1978(%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    -0x1958(%rbp),%rdi
mov    -0x1960(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xb8c(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x1958(%rbp),%rdi
mov    -0x1978(%rbp),%rsi
mov    -0x1980(%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    -0x1978(%rbp),%rsi
movslq -0x192c(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
mov    -0x1950(%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.fanotify_response = type { 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.fanotify_response
%12 = alloca %struct.stat
store i32 %0, i32* %2
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = alloca i8, i64 %14
store i64 %14, i64* %7
%17 = load i32, i32* @PATH_MAX
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %9
%20 = load i32, i32* @PATH_MAX
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
store i64 %21, i64* %10
br label %23
23: ; preds = %173, %1
%24 = load i32, i32* %2
%25 = bitcast [200 x %struct.fanotify_event_metadata]* %4 to i8*
%26 = call i32 @read(i32 %24, i8* %25, i32 6400)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i64, i64* @errno
%31 = load i64, i64* @EAGAIN
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %29, %23
%38 = load i32, i32* %5
%39 = icmp sle i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
br label %174
41: ; preds = %37
%42 = getelementptr inbounds [200 x %struct.fanotify_event_metadata], [200 x %struct.fanotify_event_metadata]* %4, i64 0, i64 0
store %struct.fanotify_event_metadata* %42, %struct.fanotify_event_metadata** %3
br label %43
43: ; preds = %169, %41
%44 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%45 = load i32, i32* %5
%46 = call i64 @FAN_EVENT_OK(%struct.fanotify_event_metadata* %44, i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %173
48: ; preds = %43
%49 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%50 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %49, i32 0, i32 0
%51 = load i64, i64* %50
%52 = load i64, i64* @FANOTIFY_METADATA_VERSION
%53 = icmp ne i64 %51, %52
br i1 %53, label %54, label %59
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %48
%60 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%61 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %60, i32 0, i32 1
%62 = load i32, i32* %61
%63 = icmp sge i32 %62, 0
br i1 %63, label %64, label %169
64: ; preds = %59
%65 = call i8* (...) @timestamp()
%66 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%67 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %66, i32 0, i32 2
%68 = load i64, i64* %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %65, i64 %68)
%70 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%71 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %70, i32 0, i32 1
%72 = load i32, i32* %71
%73 = call i64 @fstat(i32 %72, %struct.stat* %12)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %64
%76 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %64
%80 = trunc i64 %18 to i32
%81 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%82 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %81, i32 0, i32 2
%83 = load i64, i64* %82
%84 = trunc i64 %83 to i32
%85 = call i32 @snprintf(i8* %19, i32 %80, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %84)
%86 = sub i64 %14, 1
%87 = trunc i64 %86 to i32
%88 = call i32 @readlink(i8* %19, i8* %16, i32 %87)
store i32 %88, i32* %8
%89 = load i32, i32* %8
%90 = icmp sgt i32 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %79
%92 = load i32, i32* %8
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %16, i64 %93
store i8 0, i8* %94
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %16)
br label %96
96: ; preds = %91, %79
%97 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%98 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %97, i32 0, i32 3
%99 = load i32, i32* %98
%100 = load i32, i32* @FAN_OPEN
%101 = and i32 %99, %100
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %96
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %105
105: ; preds = %103, %96
%106 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%107 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %106, i32 0, i32 3
%108 = load i32, i32* %107
%109 = load i32, i32* @FAN_MODIFY
%110 = and i32 %108, %109
%111 = icmp ne i32 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %105
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %114
114: ; preds = %112, %105
%115 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%116 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %115, i32 0, i32 3
%117 = load i32, i32* %116
%118 = load i32, i32* @FAN_ACCESS
%119 = and i32 %117, %118
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %114
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %123
123: ; preds = %121, %114
%124 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%125 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %124, i32 0, i32 3
%126 = load i32, i32* %125
%127 = load i32, i32* @FAN_CLOSE_WRITE
%128 = and i32 %126, %127
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %123
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %132
132: ; preds = %130, %123
%133 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%134 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %133, i32 0, i32 3
%135 = load i32, i32* %134
%136 = load i32, i32* @FAN_CLOSE_NOWRITE
%137 = and i32 %135, %136
%138 = icmp ne i32 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %132
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %141
141: ; preds = %139, %132
%142 = trunc i64 %21 to i32
%143 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%144 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %143, i32 0, i32 1
%145 = load i32, i32* %144
%146 = call i32 @snprintf(i8* %22, i32 %142, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i32 %145)
%147 = sub i64 %14, 1
%148 = trunc i64 %147 to i32
%149 = call i32 @readlink(i8* %22, i8* %16, i32 %148)
store i32 %149, i32* %8
%150 = load i32, i32* %8
%151 = icmp eq i32 %150, -1
br i1 %151, label %152, label %156
152: ; preds = %141
%153 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%154 = load i32, i32* @EXIT_FAILURE
%155 = call i32 @exit(i32 %154)
unreachable
156: ; preds = %141
%157 = load i32, i32* %8
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8, i8* %16, i64 %158
store i8 0, i8* %159
%160 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%161 = load i64, i64* %160
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0), i8* %16, i64 %161)
%163 = load i32, i32* @stdout
%164 = call i32 @fflush(i32 %163)
%165 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%166 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %165, i32 0, i32 1
%167 = load i32, i32* %166
%168 = call i32 @close(i32 %167)
br label %169
169: ; preds = %156, %59
%170 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %3
%171 = load i32, i32* %5
%172 = call %struct.fanotify_event_metadata* @FAN_EVENT_NEXT(%struct.fanotify_event_metadata* %170, i32 %171)
store %struct.fanotify_event_metadata* %172, %struct.fanotify_event_metadata** %3
br label %43
173: ; preds = %43
br label %23
174: ; preds = %40
%175 = 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
}