#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 inotify_event {
  int mask;
  char *name;
  scalar_t__ len;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ event;

/* Variables and functions */
int IN_ACCESS;
int IN_ALL_EVENTS;
int IN_ISDIR;
int IN_MODIFY;
int IN_OPEN;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errQuit(char *);
int inotify_add_watch(int, char *, int);
int inotify_init();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, struct inotify_event *, int);
int /*<<< orphan*/ usageAndQuit(char *);
int main(int argc, char *argv[]) {
  int watch_events;
  int notifyFd;
  struct inotify_event event;
  ssize_t len;
  if (argc != 3) {
    usageAndQuit(argv[0]);
  }
  switch (argv[1][0]) {
  case 'o':
    watch_events = IN_OPEN;
    break;
  case 'r':
    watch_events = IN_ACCESS;
    break;
  case 'w':
    watch_events = IN_MODIFY;
    break;
  case 'a':
    watch_events = IN_ALL_EVENTS;
    break;
  default:
    usageAndQuit(argv[0]);
  }
  notifyFd = inotify_init();
  if (notifyFd == -1) {
    errQuit("inotify_init1");
  }
  if (inotify_add_watch(notifyFd, argv[2], watch_events) == -1) {
    errQuit("inotify_add_watch");
  }
  while (1) {
    len = read(notifyFd, &event, sizeof(event));
    if (len <= 0) {
      errQuit("read");
    }
    if (event.mask & IN_OPEN)
      printf("IN_OPEN: ");
    if (event.mask & IN_ACCESS)
      printf("IN_ACCESS: ");
    if (event.mask & IN_MODIFY)
      printf("IN_MODIFY: ");
    if (event.len)
      printf("%s", event.name);
    if (event.mask & IN_ISDIR)
      printf(" [dir]\n");
    else
      printf(" [file]\n");
  }
  close(notifyFd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <usageAndQuit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x16,%eax
ja     1201 <main+0xa1>
mov    -0x40(%rbp),%rax
lea    0xe4c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    120d <main+0xad>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    120d <main+0xad>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    120d <main+0xad>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    120d <main+0xad>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <usageAndQuit@plt>
mov    $0x0,%al
call   1060 <inotify_init@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    122d <main+0xcd>
lea    0xe34(%rip),%rdi
call   1080 <errQuit@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x14(%rbp),%edx
call   1070 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
jne    1255 <main+0xf5>
lea    0xe1a(%rip),%rdi
call   1080 <errQuit@plt>
jmp    125a <main+0xfa>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x18,%edx
call   1050 <read@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jg     1286 <main+0x126>
lea    0xdfb(%rip),%rdi
call   1080 <errQuit@plt>
mov    -0x30(%rbp),%eax
mov    0x2d28(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12a9 <main+0x149>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
mov    0x2d1d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12cc <main+0x16c>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
mov    0x2d1a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12ef <main+0x18f>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     130c <main+0x1ac>
mov    -0x28(%rbp),%rsi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
mov    0x2cca(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1334 <main+0x1d4>
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1342 <main+0x1e2>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125a <main+0xfa>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
cmp    $0x3,%edi
je     118f <main+0x1f>
mov    0x0(%rbp),%rdi
call   1030 <usageAndQuit@plt>
mov    0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff9f,%eax
cmp    $0x16,%eax
ja     11b7 <main+0x47>
lea    0xe5b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e13(%rip),%rax
jmp    11db <main+0x6b>
mov    0x0(%rbp),%rdi
call   1030 <usageAndQuit@plt>
jmp    11de <main+0x6e>
mov    0x2def(%rip),%rax
jmp    11db <main+0x6b>
mov    0x2dfe(%rip),%rax
jmp    11db <main+0x6b>
mov    0x2e15(%rip),%rax
mov    (%rax),%r14d
xor    %eax,%eax
call   1070 <inotify_init@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11f8 <main+0x88>
lea    0xe69(%rip),%rdi
call   1090 <errQuit@plt>
mov    0x10(%rbp),%rsi
mov    %ebx,%edi
mov    %r14d,%edx
call   1080 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
jne    1217 <main+0xa7>
lea    0xe58(%rip),%rdi
call   1090 <errQuit@plt>
mov    0x2db2(%rip),%r13
mov    0x2dcb(%rip),%rbp
mov    0x2db4(%rip),%r15
lea    0xe73(%rip),%r14
jmp    1245 <main+0xd5>
cs nopw 0x0(%rax,%rax,1)
nop
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %rsp,%rsi
mov    $0x18,%edx
call   1060 <read@plt>
test   %rax,%rax
jg     1265 <main+0xf5>
lea    0xe1c(%rip),%rdi
call   1090 <errQuit@plt>
mov    (%rsp),%r12d
mov    0x2d48(%rip),%rax
test   %r12d,(%rax)
je     1283 <main+0x113>
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r12d,0x0(%r13)
je     1297 <main+0x127>
lea    0xdfb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r12d,0x0(%rbp)
je     12ab <main+0x13b>
lea    0xdf3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpq   $0x0,0x10(%rsp)
je     12c6 <main+0x156>
mov    0x8(%rsp),%rsi
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
and    (%r15),%r12d
je     1240 <main+0xd0>
lea    0xdd5(%rip),%rdi
jmp    1240 <main+0xd0>

LLVM IR (-O0):
%struct.inotify_event = type { i32, i8*, i64 }
@IN_OPEN = global i32 0
@IN_ACCESS = global i32 0
@IN_MODIFY = global i32 0
@IN_ALL_EVENTS = global i32 0
@.str = [14 x i8] c"inotify_init1\00"
@.str.1 = [18 x i8] c"inotify_add_watch\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [10 x i8] c"IN_OPEN: \00"
@.str.4 = [12 x i8] c"IN_ACCESS: \00"
@.str.5 = [12 x i8] c"IN_MODIFY: \00"
@.str.6 = [3 x i8] c"%s\00"
@IN_ISDIR = global i32 0
@.str.7 = [8 x i8] c" [dir]\0A\00"
@.str.8 = [9 x i8] c" [file]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.inotify_event
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usageAndQuit(i8* %15)
br label %17
17: ; preds = %12, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %32 [
i32 111, label %24
i32 114, label %26
i32 119, label %28
i32 97, label %30
]
24: ; preds = %17
%25 = load i32, i32* @IN_OPEN
store i32 %25, i32* %6
br label %37
26: ; preds = %17
%27 = load i32, i32* @IN_ACCESS
store i32 %27, i32* %6
br label %37
28: ; preds = %17
%29 = load i32, i32* @IN_MODIFY
store i32 %29, i32* %6
br label %37
30: ; preds = %17
%31 = load i32, i32* @IN_ALL_EVENTS
store i32 %31, i32* %6
br label %37
32: ; preds = %17
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @usageAndQuit(i8* %35)
br label %37
37: ; preds = %32, %30, %28, %26, %24
%38 = call i32 (...) @inotify_init()
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @errQuit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = load i32, i32* %7
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = load i32, i32* %6
%49 = call i32 @inotify_add_watch(i32 %44, i8* %47, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %43
%52 = call i32 @errQuit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %51, %43
br label %54
54: ; preds = %53, %103
%55 = load i32, i32* %7
%56 = call i64 @read(i32 %55, %struct.inotify_event* %8, i32 24)
store i64 %56, i64* %9
%57 = load i64, i64* %9
%58 = icmp sle i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 @errQuit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %59, %54
%62 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %8, i32 0, i32 0
%63 = load i32, i32* %62
%64 = load i32, i32* @IN_OPEN
%65 = and i32 %63, %64
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67, %61
%70 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %8, i32 0, i32 0
%71 = load i32, i32* %70
%72 = load i32, i32* @IN_ACCESS
%73 = and i32 %71, %72
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %69
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %77
77: ; preds = %75, %69
%78 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %8, i32 0, i32 0
%79 = load i32, i32* %78
%80 = load i32, i32* @IN_MODIFY
%81 = and i32 %79, %80
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %77
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %85
85: ; preds = %83, %77
%86 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %8, i32 0, i32 2
%87 = load i64, i64* %86
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %85
%90 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %8, i32 0, i32 1
%91 = load i8*, i8** %90
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %91)
br label %93
93: ; preds = %89, %85
%94 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %8, i32 0, i32 0
%95 = load i32, i32* %94
%96 = load i32, i32* @IN_ISDIR
%97 = and i32 %95, %96
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %93
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %103
101: ; preds = %93
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %103
103: ; preds = %101, %99
br label %54
}

LLVM IR (-O2):
%struct.inotify_event = type { i32, i8*, i64 }
@IN_OPEN = global i32 0
@IN_ACCESS = global i32 0
@IN_MODIFY = global i32 0
@IN_ALL_EVENTS = global i32 0
@.str = [14 x i8] c"inotify_init1\00"
@.str.1 = [18 x i8] c"inotify_add_watch\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [10 x i8] c"IN_OPEN: \00"
@.str.4 = [12 x i8] c"IN_ACCESS: \00"
@.str.5 = [12 x i8] c"IN_MODIFY: \00"
@.str.6 = [3 x i8] c"%s\00"
@IN_ISDIR = global i32 0
@str = [8 x i8] c" [file]\00"
@str.9 = [7 x i8] c" [dir]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.inotify_event
%4 = bitcast %struct.inotify_event* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usageAndQuit(i8* %7)
br label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %22 [
i32 111, label %14
i32 114, label %16
i32 119, label %18
i32 97, label %20
]
14: ; preds = %9
%15 = load i32, i32* @IN_OPEN
br label %25
16: ; preds = %9
%17 = load i32, i32* @IN_ACCESS
br label %25
18: ; preds = %9
%19 = load i32, i32* @IN_MODIFY
br label %25
20: ; preds = %9
%21 = load i32, i32* @IN_ALL_EVENTS
br label %25
22: ; preds = %9
%23 = load i8*, i8** %1
%24 = tail call i32 @usageAndQuit(i8* %23)
br label %25
25: ; preds = %22, %20, %18, %16, %14
%26 = phi i32 [ undef, %22 ], [ %21, %20 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ]
%27 = tail call i32 (...) @inotify_init()
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 @errQuit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = tail call i32 @inotify_add_watch(i32 %27, i8* %33, i32 %26)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = tail call i32 @errQuit(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %31
%39 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %3, i64 0, i32 0
%40 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %3, i64 0, i32 2
%41 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %3, i64 0, i32 1
br label %42
42: ; preds = %72, %38
%43 = call i64 @read(i32 %27, %struct.inotify_event* %3, i32 24)
%44 = icmp slt i64 %43, 1
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = tail call i32 @errQuit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
%48 = load i32, i32* %39
%49 = load i32, i32* @IN_OPEN
%50 = and i32 %49, %48
%51 = icmp eq i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %47
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %47
%55 = load i32, i32* @IN_ACCESS
%56 = and i32 %55, %48
%57 = icmp eq i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %54
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %54
%61 = load i32, i32* @IN_MODIFY
%62 = and i32 %61, %48
%63 = icmp eq i32 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %60
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
%67 = load i64, i64* %40
%68 = icmp eq i64 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %66
%70 = load i8*, i8** %41
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %69, %66
%73 = load i32, i32* @IN_ISDIR
%74 = and i32 %73, %48
%75 = icmp eq i32 %74, 0
%76 = select i1 %75, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str.9, i64 0, i64 0)
%77 = tail call i32 @puts(i8* dereferenceable(1) %76)
br label %42
}