#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("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);
}


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,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x20(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
call   1030 <get_file_path_from_fd@plt>
cmp    $0x0,%rax
je     11b4 <event_process+0x64>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11c4 <event_process+0x74>
lea    0xe61(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11c4 <event_process+0x74>
mov    -0x28(%rbp),%rsi
lea    0xe31(%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    0x2e00(%rip),%rax
mov    (%rax),%edx
call   1070 <get_program_name_from_pid@plt>
cmp    $0x0,%rax
je     120e <event_process+0xbe>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    121e <event_process+0xce>
lea    0xe07(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    121e <event_process+0xce>
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2d9f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     125a <event_process+0x10a>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2d68(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1281 <event_process+0x131>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <close@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),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%rdi),%edi
mov    %rbx,%rsi
call   1040 <get_file_path_from_fd@plt>
test   %rax,%rax
lea    0xe77(%rip),%r13
mov    %rbx,%rsi
cmove  %r13,%rsi
lea    0xe4d(%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    0xe4a(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%r14),%eax
mov    0x2dee(%rip),%rcx
test   %eax,(%rcx)
je     1206 <event_process+0xa6>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%r14),%eax
mov    0x2dc3(%rip),%rcx
test   %eax,(%rcx)
je     121d <event_process+0xbd>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x8(%r14),%edi
call   1060 <close@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 = [28 x i8] c"Received event in path '%s'\00"
@.str.1 = [8 x i8] c"unknown\00"
@.str.2 = [16 x i8] c" pid=%d (%s): \0A\00"
@FAN_CLOSE_WRITE = global i32 0
@.str.3 = [18 x i8] c"\09FAN_CLOSE_WRITE\0A\00"
@FAN_OPEN_PERM = global i32 0
@.str.4 = [16 x i8] c"\09FAN_OPEN_PERM\0A\00"
@stdout = global i32 0
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 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%10 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %9, i32 0, i32 2
%11 = load i32, i32* %10
%12 = load i32, i32* @PATH_MAX
%13 = call i64 @get_file_path_from_fd(i32 %11, i8* %8, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
br label %17
16: ; preds = %1
br label %17
17: ; preds = %16, %15
%18 = phi i8* [ %8, %15 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %16 ]
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%21 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%24 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* @PATH_MAX
%27 = call i64 @get_program_name_from_pid(i32 %25, i8* %8, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %17
br label %31
30: ; preds = %17
br label %31
31: ; preds = %30, %29
%32 = phi i8* [ %8, %29 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %30 ]
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %32)
%34 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%35 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = load i32, i32* @FAN_CLOSE_WRITE
%38 = and i32 %36, %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %31
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %31
%43 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%44 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = load i32, i32* @FAN_OPEN_PERM
%47 = and i32 %45, %46
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %42
%52 = load i32, i32* @stdout
%53 = call i32 @fflush(i32 %52)
%54 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %2
%55 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %54, i32 0, i32 2
%56 = load i32, i32* %55
%57 = call i32 @close(i32 %56)
%58 = load i8*, i8** %3
ret void
}

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