#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;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int IN_CREATE;
int IN_DELETE;
int IN_MODIFY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int inotify_add_watch(int, char *, int);
int inotify_init();
int /*<<< orphan*/ inotify_rm_watch(int, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  int watch;
  int length;
  struct inotify_event *event;
  char buffer[(1024 * ((sizeof(struct inotify_event)) + 16))];
  char *path = argv[1];
  char *buffer_pointer;
  if (argc != 2) {
    printf("Usage: %s [directory]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  printf("Watching %s for contacts.\n", path);
  fd = inotify_init();
  watch = inotify_add_watch(fd, path, IN_CREATE | IN_MODIFY | IN_DELETE);
  while (1) {
    length = read(fd, buffer, (1024 * ((sizeof(struct inotify_event)) + 16)));
    if (length < 0) {
      fprintf(stderr, "Error reading into file descriptor\n");
      exit(EXIT_FAILURE);
    }
    for (buffer_pointer = buffer; buffer_pointer < buffer + length;) {
      event = (struct inotify_event *)buffer_pointer;
      if (event->mask & IN_CREATE) {
        printf("%s created\n", event->name);
      } else if (event->mask & IN_MODIFY) {
        printf("%s modified\n", event->name);
      } else if (event->mask & IN_DELETE) {
        printf("%s deleted\n", event->name);
      }
      buffer_pointer += sizeof(struct inotify_event) + event->len;
    }
  }
  inotify_rm_watch(fd, watch);
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xa038(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0xa038(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <inotify_init@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xa038(%rbp),%rsi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    0x2e06(%rip),%rax
or     (%rax),%edx
mov    0x2ded(%rip),%rax
or     (%rax),%edx
call   1070 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xa030(%rbp),%rsi
mov    $0xa000,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1241 <main+0xe1>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0xa030(%rbp),%rax
mov    %rax,-0xa040(%rbp)
mov    -0xa040(%rbp),%rax
lea    -0xa030(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    132f <main+0x1cf>
mov    -0xa040(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    0x2d43(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12a9 <main+0x149>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdb7(%rip),%rdi
call   1030 <printf@plt>
jmp    1310 <main+0x1b0>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    0x2d3a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12da <main+0x17a>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd92(%rip),%rdi
call   1030 <printf@plt>
jmp    130b <main+0x1ab>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    0x2cf9(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1306 <main+0x1a6>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd6e(%rip),%rdi
call   1030 <printf@plt>
jmp    130b <main+0x1ab>
jmp    1310 <main+0x1b0>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
add    $0x18,%rax
add    -0xa040(%rbp),%rax
mov    %rax,-0xa040(%rbp)
jmp    124f <main+0xef>
jmp    11fd <main+0x9d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa018,%rsp
cmp    $0x2,%edi
jne    11e9 <main+0x89>
mov    0x8(%rsi),%r14
lea    0xe96(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <inotify_init@plt>
mov    0x2e31(%rip),%rbx
mov    0x2e52(%rip),%r13
mov    0x0(%r13),%edx
or     (%rbx),%edx
mov    %eax,%ebp
mov    0x2e33(%rip),%rax
or     (%rax),%edx
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <inotify_add_watch@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,0xc(%rsp)
mov    %ebp,%edi
mov    $0xa000,%edx
call   1040 <read@plt>
test   %eax,%eax
jns    1206 <main+0xa6>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f8 <main+0x98>
mov    (%rsi),%rsi
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe49(%rip),%rbp
lea    0xe4e(%rip),%r14
jmp    1237 <main+0xd7>
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xa000,%edx
call   1040 <read@plt>
test   %eax,%eax
js     11d2 <main+0x72>
test   %eax,%eax
je     1220 <main+0xc0>
mov    %eax,%eax
lea    (%rsp,%rax,1),%r12
add    $0x10,%r12
lea    0x10(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r15),%eax
mov    %rbp,%rdi
test   %eax,(%rbx)
jne    1280 <main+0x120>
mov    %r14,%rdi
test   %eax,0x0(%r13)
jne    1280 <main+0x120>
lea    0xe05(%rip),%rdi
mov    0x2d6f(%rip),%rcx
test   %eax,(%rcx)
je     1289 <main+0x129>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%r15),%rsi
call   1030 <printf@plt>
mov    0x10(%r15),%rax
add    %rax,%r15
add    $0x18,%r15
cmp    %r12,%r15
jb     1250 <main+0xf0>
jmp    1220 <main+0xc0>

LLVM IR (-O0):
%struct.inotify_event = type { i32, i8*, i64 }
@.str = [23 x i8] c"Usage: %s [directory]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"Watching %s for contacts.\0A\00"
@IN_CREATE = global i32 0
@IN_MODIFY = global i32 0
@IN_DELETE = global i32 0
@stderr = global i32 0
@.str.2 = [36 x i8] c"Error reading into file descriptor\0A\00"
@.str.3 = [12 x i8] c"%s created\0A\00"
@.str.4 = [13 x i8] c"%s modified\0A\00"
@.str.5 = [12 x i8] c"%s deleted\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.inotify_event*
%10 = alloca [40960 x i8]
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %11
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = load i8*, i8** %11
%27 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = call i32 (...) @inotify_init()
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = load i8*, i8** %11
%31 = load i32, i32* @IN_CREATE
%32 = load i32, i32* @IN_MODIFY
%33 = or i32 %31, %32
%34 = load i32, i32* @IN_DELETE
%35 = or i32 %33, %34
%36 = call i32 @inotify_add_watch(i32 %29, i8* %30, i32 %35)
store i32 %36, i32* %7
br label %37
37: ; preds = %25, %104
%38 = load i32, i32* %6
%39 = getelementptr inbounds [40960 x i8], [40960 x i8]* %10, i64 0, i64 0
%40 = call i32 @read(i32 %38, i8* %39, i32 40960)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %37
%49 = getelementptr inbounds [40960 x i8], [40960 x i8]* %10, i64 0, i64 0
store i8* %49, i8** %12
br label %50
50: ; preds = %97, %48
%51 = load i8*, i8** %12
%52 = getelementptr inbounds [40960 x i8], [40960 x i8]* %10, i64 0, i64 0
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = icmp ult i8* %51, %55
br i1 %56, label %57, label %104
57: ; preds = %50
%58 = load i8*, i8** %12
%59 = bitcast i8* %58 to %struct.inotify_event*
store %struct.inotify_event* %59, %struct.inotify_event** %9
%60 = load %struct.inotify_event*, %struct.inotify_event** %9
%61 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = load i32, i32* @IN_CREATE
%64 = and i32 %62, %63
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %57
%67 = load %struct.inotify_event*, %struct.inotify_event** %9
%68 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %67, i32 0, i32 1
%69 = load i8*, i8** %68
%70 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %69)
br label %97
71: ; preds = %57
%72 = load %struct.inotify_event*, %struct.inotify_event** %9
%73 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = load i32, i32* @IN_MODIFY
%76 = and i32 %74, %75
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %71
%79 = load %struct.inotify_event*, %struct.inotify_event** %9
%80 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %79, i32 0, i32 1
%81 = load i8*, i8** %80
%82 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %81)
br label %96
83: ; preds = %71
%84 = load %struct.inotify_event*, %struct.inotify_event** %9
%85 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %84, i32 0, i32 0
%86 = load i32, i32* %85
%87 = load i32, i32* @IN_DELETE
%88 = and i32 %86, %87
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %95
90: ; preds = %83
%91 = load %struct.inotify_event*, %struct.inotify_event** %9
%92 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %91, i32 0, i32 1
%93 = load i8*, i8** %92
%94 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %93)
br label %95
95: ; preds = %90, %83
br label %96
96: ; preds = %95, %78
br label %97
97: ; preds = %96, %66
%98 = load %struct.inotify_event*, %struct.inotify_event** %9
%99 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %98, i32 0, i32 2
%100 = load i64, i64* %99
%101 = add i64 24, %100
%102 = load i8*, i8** %12
%103 = getelementptr inbounds i8, i8* %102, i64 %101
store i8* %103, i8** %12
br label %50
104: ; preds = %50
br label %37
}

LLVM IR (-O2):
@.str = [23 x i8] c"Usage: %s [directory]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"Watching %s for contacts.\0A\00"
@IN_CREATE = global i32 0
@IN_MODIFY = global i32 0
@IN_DELETE = global i32 0
@stderr = global i32 0
@.str.2 = [36 x i8] c"Error reading into file descriptor\0A\00"
@.str.3 = [12 x i8] c"%s created\0A\00"
@.str.4 = [13 x i8] c"%s modified\0A\00"
@.str.5 = [12 x i8] c"%s deleted\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [40960 x i8]
%4 = getelementptr inbounds [40960 x i8], [40960 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%15 = tail call i32 (...) @inotify_init()
%16 = load i32, i32* @IN_CREATE
%17 = load i32, i32* @IN_MODIFY
%18 = or i32 %17, %16
%19 = load i32, i32* @IN_DELETE
%20 = or i32 %18, %19
%21 = tail call i32 @inotify_add_watch(i32 %15, i8* %6, i32 %20)
%22 = call i32 @read(i32 %15, i8* %4, i32 40960)
%23 = icmp slt i32 %22, 0
br i1 %23, label %32, label %27
24: ; preds = %58, %27
%25 = call i32 @read(i32 %15, i8* %4, i32 40960)
%26 = icmp slt i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %13, %24
%28 = phi i32 [ %25, %24 ], [ %22, %13 ]
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [40960 x i8], [40960 x i8]* %3, i64 0, i64 %29
%31 = icmp eq i32 %28, 0
br i1 %31, label %24, label %37
32: ; preds = %24, %13
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %27, %58
%38 = phi i8* [ %63, %58 ], [ %4, %27 ]
%39 = bitcast i8* %38 to i32*
%40 = load i32, i32* %39
%41 = load i32, i32* @IN_CREATE
%42 = and i32 %41, %40
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %37
%45 = load i32, i32* @IN_MODIFY
%46 = and i32 %45, %40
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i32, i32* @IN_DELETE
%50 = and i32 %49, %40
%51 = icmp eq i32 %50, 0
br i1 %51, label %58, label %52
52: ; preds = %48, %44, %37
%53 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %37 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %44 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), %48 ]
%54 = getelementptr inbounds i8, i8* %38, i64 8
%55 = bitcast i8* %54 to i8**
%56 = load i8*, i8** %55
%57 = call i32 @printf(i8* %53, i8* %56)
br label %58
58: ; preds = %52, %48
%59 = getelementptr inbounds i8, i8* %38, i64 16
%60 = bitcast i8* %59 to i64*
%61 = load i64, i64* %60
%62 = add i64 %61, 24
%63 = getelementptr inbounds i8, i8* %38, i64 %62
%64 = icmp ult i8* %63, %30
br i1 %64, label %37, label %24
}