#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 fanotify_event_metadata {
  int mask;
  int pid;
  int /*<<< orphan*/ fd;
};
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ exe;
typedef int /*<<< orphan*/ cmdline;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
struct fanotify_event_metadata *FAN_EVENT_NEXT(struct fanotify_event_metadata *,
                                               int);
scalar_t__ FAN_EVENT_OK(struct fanotify_event_metadata *, int);
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int cmdlineByPID(int, char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exeByPID(int, char *, int);
int /*<<< orphan*/ fileByFD(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ lprintf(int, char *, ...);
int /*<<< orphan*/ printf(char *, int, char *, char *, char *, char *, char *,
                          char *);
int read(int const, char *, int);
int /*<<< orphan*/ sprintmask(int, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
void faLoop(const int fanotify) {
  int buffer_len;
  char buffer[4096], mask[256], path[PATH_MAX + 1], exe[PATH_MAX + 1],
      cmdline[8192];
  struct fanotify_event_metadata *metadata;
  for (;;) {
    buffer_len = read(fanotify, buffer, sizeof(buffer));
    metadata = (struct fanotify_event_metadata *)&buffer;
    while (FAN_EVENT_OK(metadata, buffer_len)) {
      if (metadata->mask & 0) {
        lprintf(2, "Queue overflow");
        continue;
      }
      fileByFD(metadata->fd, path, sizeof(path));
      exeByPID(metadata->pid, exe, sizeof(exe));
      if (cmdlineByPID(metadata->pid, cmdline, sizeof(cmdline)) == -1) {
        lprintf(2, "Could not read commandline for %d: %s", metadata->pid,
                strerror(errno));
      }
      sprintmask(metadata->mask, mask);
      printf("pid:%d exe:%s %s%s%sevents:[%s]: %s\n", metadata->pid, exe,
             (strlen(cmdline) > 0 ? "args:[" : ""), cmdline,
             (strlen(cmdline) > 0 ? "] " : ""), mask, path);
      close(metadata->fd);
      metadata = FAN_EVENT_NEXT(metadata, buffer_len);
    }
  }
}


x86 assembly (clang, -O0):
<faLoop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3180,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rcx,-0x3158(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x1118(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x3150(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x1120(%rbp)
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x3148(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x3140(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x1128(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
mov    %eax,-0x8(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x3138(%rbp)
mov    -0x3138(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1090 <FAN_EVENT_OK@plt>
cmp    $0x0,%rax
je     1435 <faLoop+0x275>
mov    -0x3138(%rbp),%rax
mov    (%rax),%eax
and    $0x0,%eax
cmp    $0x0,%eax
je     12a6 <faLoop+0xe6>
mov    $0x2,%edi
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   10c0 <lprintf@plt>
jmp    1260 <faLoop+0xa0>
mov    -0x3150(%rbp),%rsi
mov    -0x3158(%rbp),%rax
mov    -0x3138(%rbp),%rcx
mov    0x8(%rcx),%edi
mov    %eax,%edx
call   1040 <fileByFD@plt>
mov    -0x3140(%rbp),%rsi
mov    -0x3148(%rbp),%rax
mov    -0x3138(%rbp),%rcx
mov    0x4(%rcx),%edi
mov    %eax,%edx
call   10a0 <exeByPID@plt>
mov    -0x3138(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x3130(%rbp),%rsi
mov    $0x2000,%edx
call   10e0 <cmdlineByPID@plt>
cmp    $0xffffffff,%eax
jne    1341 <faLoop+0x181>
mov    -0x3138(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x315c(%rbp)
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x315c(%rbp),%edx
mov    %eax,%ecx
mov    $0x2,%edi
lea    0xcd5(%rip),%rsi
mov    $0x0,%al
call   10c0 <lprintf@plt>
mov    -0x3138(%rbp),%rax
mov    (%rax),%edi
lea    -0x1110(%rbp),%rsi
call   10b0 <sprintmask@plt>
mov    -0x3138(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x3174(%rbp)
lea    -0x3130(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdx
lea    0xcdd(%rip),%rax
lea    0xcd7(%rip),%rcx
cmp    $0x0,%rdx
cmovg  %rcx,%rax
mov    %rax,-0x3170(%rbp)
lea    -0x3130(%rbp),%rax
mov    %rax,-0x3168(%rbp)
lea    -0x3130(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3174(%rbp),%esi
mov    -0x3140(%rbp),%rdx
mov    -0x3170(%rbp),%rcx
mov    -0x3168(%rbp),%r8
mov    %rax,%r10
mov    -0x3150(%rbp),%rax
lea    0xc81(%rip),%r9
lea    0xc82(%rip),%rdi
cmp    $0x0,%r10
cmovg  %rdi,%r9
lea    -0x1110(%rbp),%r10
lea    0xc40(%rip),%rdi
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <printf@plt>
add    $0x10,%rsp
mov    -0x3138(%rbp),%rax
mov    0x8(%rax),%edi
call   1070 <close@plt>
mov    -0x3138(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <FAN_EVENT_NEXT@plt>
mov    %rax,-0x3138(%rbp)
jmp    1260 <faLoop+0xa0>
jmp    123b <faLoop+0x7b>

x86 assembly (clang, -O2):
<faLoop>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3128,%rsp
mov    %edi,-0x2c(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
nopl   0x0(%rax)
mov    -0x2c(%rbp),%edi
lea    -0x1150(%rbp),%rbx
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1080 <read@plt>
mov    %rbx,%rdi
mov    %eax,-0x30(%rbp)
mov    %eax,%esi
call   1090 <FAN_EVENT_OK@plt>
test   %rax,%rax
je     1210 <faLoop+0x50>
lea    -0x1150(%rbp),%r14
lea    -0x114c(%rbp),%r13
lea    -0x1148(%rbp),%r12
jmp    12fd <faLoop+0x13d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%edi
lea    -0x150(%rbp),%rsi
call   10b0 <sprintmask@plt>
mov    0x0(%r13),%ebx
lea    -0x3150(%rbp),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
lea    0xdbe(%rip),%r9
mov    %r9,%rcx
lea    0xdb5(%rip),%rax
cmovg  %rax,%rcx
lea    0xdb1(%rip),%rax
cmovg  %rax,%r9
lea    0xd7a(%rip),%rdi
mov    %ebx,%esi
mov    -0x38(%rbp),%rdx
mov    %r15,%r8
push   -0x40(%rbp)
lea    -0x150(%rbp),%rax
push   %rax
call   1060 <printf@plt>
add    $0x10,%rsp
mov    (%r12),%edi
call   1070 <close@plt>
mov    %r14,%rdi
mov    -0x30(%rbp),%ebx
mov    %ebx,%esi
call   1030 <FAN_EVENT_NEXT@plt>
mov    %rax,%r14
lea    0x8(%rax),%r12
lea    0x4(%rax),%r13
mov    %rax,%rdi
mov    %ebx,%esi
call   1090 <FAN_EVENT_OK@plt>
test   %rax,%rax
je     1210 <faLoop+0x50>
mov    (%r12),%edi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rbx
mov    %ebx,%edx
call   1040 <fileByFD@plt>
mov    0x0(%r13),%edi
mov    -0x38(%rbp),%rsi
mov    %ebx,%edx
call   10a0 <exeByPID@plt>
mov    0x0(%r13),%edi
lea    -0x3150(%rbp),%rsi
mov    $0x2000,%edx
call   10e0 <cmdlineByPID@plt>
cmp    $0xffffffff,%eax
jne    1260 <faLoop+0xa0>
mov    0x0(%r13),%r15d
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    $0x2,%edi
lea    0xca5(%rip),%rsi
mov    %r15d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   10c0 <lprintf@plt>
jmp    1260 <faLoop+0xa0>

LLVM IR (-O0):
%struct.fanotify_event_metadata = type { i32, i32, i32 }
@PATH_MAX = global i32 0
@.str = [15 x i8] c"Queue overflow\00"
@.str.1 = [38 x i8] c"Could not read commandline for %d: %s\00"
@errno = global i32 0
@.str.2 = [37 x i8] c"pid:%d exe:%s %s%s%sevents:[%s]: %s\0A\00"
@.str.3 = [7 x i8] c"args:[\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [3 x i8] c"] \00"
define void @faLoop(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [8192 x i8]
%10 = alloca %struct.fanotify_event_metadata*
store i32 %0, i32* %2
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, 1
%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 = add nsw i32 %16, 1
%18 = zext i32 %17 to i64
%19 = alloca i8, i64 %18
store i64 %18, i64* %8
br label %20
20: ; preds = %91, %1
%21 = load i32, i32* %2
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%23 = call i32 @read(i32 %21, i8* %22, i32 4096)
store i32 %23, i32* %3
%24 = bitcast [4096 x i8]* %4 to %struct.fanotify_event_metadata*
store %struct.fanotify_event_metadata* %24, %struct.fanotify_event_metadata** %10
br label %25
25: ; preds = %62, %36, %20
%26 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%27 = load i32, i32* %3
%28 = call i64 @FAN_EVENT_OK(%struct.fanotify_event_metadata* %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %91
30: ; preds = %25
%31 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%32 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, 0
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 (i32, i8*, ...) @lprintf(i32 2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %25
38: ; preds = %30
%39 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%40 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = trunc i64 %13 to i32
%43 = call i32 @fileByFD(i32 %41, i8* %15, i32 %42)
%44 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%45 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = trunc i64 %18 to i32
%48 = call i32 @exeByPID(i32 %46, i8* %19, i32 %47)
%49 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%50 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%53 = call i32 @cmdlineByPID(i32 %51, i8* %52, i32 8192)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %62
55: ; preds = %38
%56 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%57 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %56, i32 0, i32 1
%58 = load i32, i32* %57
%59 = load i32, i32* @errno
%60 = call i32 @strerror(i32 %59)
%61 = call i32 (i32, i8*, ...) @lprintf(i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %58, i32 %60)
br label %62
62: ; preds = %55, %38
%63 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%64 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %63, i32 0, i32 0
%65 = load i32, i32* %64
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%67 = call i32 @sprintmask(i32 %65, i8* %66)
%68 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%69 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %68, i32 0, i32 1
%70 = load i32, i32* %69
%71 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%72 = call i64 @strlen(i8* %71)
%73 = icmp sgt i64 %72, 0
%74 = zext i1 %73 to i64
%75 = select i1 %73, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%76 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%77 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%78 = call i64 @strlen(i8* %77)
%79 = icmp sgt i64 %78, 0
%80 = zext i1 %79 to i64
%81 = select i1 %79, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%83 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %70, i8* %19, i8* %75, i8* %76, i8* %81, i8* %82, i8* %15)
%84 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%85 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %84, i32 0, i32 2
%86 = load i32, i32* %85
%87 = call i32 @close(i32 %86)
%88 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %10
%89 = load i32, i32* %3
%90 = call %struct.fanotify_event_metadata* @FAN_EVENT_NEXT(%struct.fanotify_event_metadata* %88, i32 %89)
store %struct.fanotify_event_metadata* %90, %struct.fanotify_event_metadata** %10
br label %25
91: ; preds = %25
br label %20
}

LLVM IR (-O2):
%struct.fanotify_event_metadata = type { i32, i32, i32 }
@PATH_MAX = global i32 0
@.str.1 = [38 x i8] c"Could not read commandline for %d: %s\00"
@errno = global i32 0
@.str.2 = [37 x i8] c"pid:%d exe:%s %s%s%sevents:[%s]: %s\0A\00"
@.str.3 = [7 x i8] c"args:[\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [3 x i8] c"] \00"
define void @faLoop(i32 %0) {
%2 = alloca [4096 x i8]
%3 = alloca [256 x i8]
%4 = alloca [8192 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @PATH_MAX
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = alloca i8, i64 %9
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%13 = bitcast [4096 x i8]* %2 to %struct.fanotify_event_metadata*
%14 = bitcast [4096 x i8]* %2 to i32*
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 8
%16 = bitcast i8* %15 to i32*
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 4
%18 = bitcast i8* %17 to i32*
br label %19
19: ; preds = %23, %1
%20 = call i32 @read(i32 %0, i8* %5, i32 4096)
%21 = call i64 @FAN_EVENT_OK(%struct.fanotify_event_metadata* %13, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %41, %19
br label %19
24: ; preds = %19, %41
%25 = phi %struct.fanotify_event_metadata* [ %52, %41 ], [ %13, %19 ]
%26 = phi i32* [ %55, %41 ], [ %18, %19 ]
%27 = phi i32* [ %54, %41 ], [ %16, %19 ]
%28 = phi i32* [ %53, %41 ], [ %14, %19 ]
%29 = load i32, i32* %27
%30 = call i32 @fileByFD(i32 %29, i8* %10, i32 %8)
%31 = load i32, i32* %26
%32 = call i32 @exeByPID(i32 %31, i8* %11, i32 %8)
%33 = load i32, i32* %26
%34 = call i32 @cmdlineByPID(i32 %33, i8* %12, i32 8192)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %41
36: ; preds = %24
%37 = load i32, i32* %26
%38 = load i32, i32* @errno
%39 = call i32 @strerror(i32 %38)
%40 = call i32 (i32, i8*, ...) @lprintf(i32 2, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %39)
br label %41
41: ; preds = %36, %24
%42 = load i32, i32* %28
%43 = call i32 @sprintmask(i32 %42, i8* %6)
%44 = load i32, i32* %26
%45 = call i64 @strlen(i8* %12)
%46 = icmp sgt i64 %45, 0
%47 = select i1 %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%48 = select i1 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0)
%49 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %44, i8* %11, i8* %47, i8* %12, i8* %48, i8* %6, i8* %10)
%50 = load i32, i32* %27
%51 = call i32 @close(i32 %50)
%52 = call %struct.fanotify_event_metadata* @FAN_EVENT_NEXT(%struct.fanotify_event_metadata* %25, i32 %20)
%53 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %52, i64 0, i32 0
%54 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %52, i64 0, i32 2
%55 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %52, i64 0, i32 1
%56 = call i64 @FAN_EVENT_OK(%struct.fanotify_event_metadata* %52, i32 %20)
%57 = icmp eq i64 %56, 0
br i1 %57, label %23, label %24
}