#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 pid;
  int mask;
  int /*<<< orphan*/ fd;
};

/* Variables and functions */
int FAN_CLOSE_WRITE;
int FAN_OPEN_PERM;
int PATH_MAX;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ get_file_path_from_fd(int /*<<< orphan*/, char *, int);
scalar_t__ get_program_name_from_pid(int, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void event_process(struct fanotify_event_metadata *event) {
  char path[PATH_MAX];
  printf("===================================================\n");
  printf("Received event in path '%s'",
         get_file_path_from_fd(event->fd, path, PATH_MAX) ? path : "unknown");
  printf(" pid=%d (%s): \n", event->pid,
         (get_program_name_from_pid(event->pid, path, PATH_MAX) ? path
                                                                : "unknown"));
  if (event->mask & FAN_CLOSE_WRITE)
    printf("\tFAN_CLOSE_WRITE\n");
  if (event->mask & FAN_OPEN_PERM)
    printf("\tFAN_OPEN_PERM\n");
  fflush(stdout);
  close(event->fd);
  printf("****************************************************\n");
}


x86 assembly (clang, -O0):
<event_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
call   1030 <get_file_path_from_fd@plt>
cmp    $0x0,%rax
je     11c6 <event_process+0x76>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11d6 <event_process+0x86>
lea    0xe84(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11d6 <event_process+0x86>
mov    -0x28(%rbp),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
call   1070 <get_program_name_from_pid@plt>
cmp    $0x0,%rax
je     1220 <event_process+0xd0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1230 <event_process+0xe0>
lea    0xe2a(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1230 <event_process+0xe0>
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2d8d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     126c <event_process+0x11c>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2d56(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1293 <event_process+0x143>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <close@plt>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<event_process>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e78(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%edi
mov    (%r12),%edx
mov    %rbx,%rsi
call   1040 <get_file_path_from_fd@plt>
test   %rax,%rax
lea    0xe69(%rip),%r13
mov    %rbx,%rsi
cmove  %r13,%rsi
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%r15d
mov    (%r12),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1080 <get_program_name_from_pid@plt>
test   %rax,%rax
cmove  %r13,%rbx
lea    0xe3c(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%r14),%eax
mov    0x2de0(%rip),%rcx
test   %eax,(%rcx)
je     1214 <event_process+0xb4>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%r14),%eax
mov    0x2db5(%rip),%rcx
test   %eax,(%rcx)
je     122b <event_process+0xcb>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x8(%r14),%edi
call   1060 <close@plt>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.fanotify_event_metadata = type { i32, i32, i32 }
@PATH_MAX = global i32 0
@.str = [53 x i8] c"===================================================\0A\00"
@.str.1 = [28 x i8] c"Received event in path '%s'\00"
@.str.2 = [8 x i8] c"unknown\00"
@.str.3 = [16 x i8] c" pid=%d (%s): \0A\00"
@FAN_CLOSE_WRITE = global i32 0
@.str.4 = [18 x i8] c"\09FAN_CLOSE_WRITE\0A\00"
@FAN_OPEN_PERM = global i32 0
@.str.5 = [16 x i8] c"\09FAN_OPEN_PERM\0A\00"
@stdout = global i32 0
@.str.6 = [54 x i8] c"****************************************************\0A\00"
define void @event_process(%struct.fanotify_event_metadata* %0) {
%2 = alloca %struct.fanotify_event_metadata*
%3 = alloca i8*
%4 = alloca i64
store %struct.fanotify_event_metadata* %0, %struct.fanotify_event_metadata** %2
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %3
%8 = alloca i8, i64 %6
store i64 %6, i64* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%10 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%11 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %10, i32 0, i32 2
%12 = load i32, i32* %11
%13 = load i32, i32* @PATH_MAX
%14 = call i64 @get_file_path_from_fd(i32 %12, i8* %8, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
br label %18
17: ; preds = %1
br label %18
18: ; preds = %17, %16
%19 = phi i8* [ %8, %16 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %17 ]
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%22 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%25 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @PATH_MAX
%28 = call i64 @get_program_name_from_pid(i32 %26, i8* %8, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %18
br label %32
31: ; preds = %18
br label %32
32: ; preds = %31, %30
%33 = phi i8* [ %8, %30 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %31 ]
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %23, i8* %33)
%35 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%36 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = load i32, i32* @FAN_CLOSE_WRITE
%39 = and i32 %37, %38
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %32
%44 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%45 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = load i32, i32* @FAN_OPEN_PERM
%48 = and i32 %46, %47
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %43
%53 = load i32, i32* @stdout
%54 = call i32 @fflush(i32 %53)
%55 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%56 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %55, i32 0, i32 2
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0))
%60 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
%struct.fanotify_event_metadata = type { i32, i32, i32 }
@PATH_MAX = global i32 0
@.str.1 = [28 x i8] c"Received event in path '%s'\00"
@.str.2 = [8 x i8] c"unknown\00"
@.str.3 = [16 x i8] c" pid=%d (%s): \0A\00"
@FAN_CLOSE_WRITE = global i32 0
@FAN_OPEN_PERM = global i32 0
@stdout = global i32 0
@str = [52 x i8] c"===================================================\00"
@str.7 = [53 x i8] c"****************************************************\00"
@str.8 = [15 x i8] c"\09FAN_OPEN_PERM\00"
@str.9 = [17 x i8] c"\09FAN_CLOSE_WRITE\00"
define void @event_process(%struct.fanotify_event_metadata* nocapture %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %0, i64 0, i32 2
%7 = load i32, i32* %6
%8 = load i32, i32* @PATH_MAX
%9 = call i64 @get_file_path_from_fd(i32 %7, i8* %4, i32 %8)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %4
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %0, i64 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @PATH_MAX
%16 = call i64 @get_program_name_from_pid(i32 %14, i8* %4, i32 %15)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %4
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %14, i8* %18)
%20 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %0, i64 0, i32 1
%21 = load i32, i32* %20
%22 = load i32, i32* @FAN_CLOSE_WRITE
%23 = and i32 %22, %21
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %1
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
%27 = load i32, i32* %20
br label %28
28: ; preds = %25, %1
%29 = phi i32 [ %27, %25 ], [ %21, %1 ]
%30 = load i32, i32* @FAN_OPEN_PERM
%31 = and i32 %30, %29
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %28
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = load i32, i32* @stdout
%37 = call i32 @fflush(i32 %36)
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0))
ret void
}