#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 IN_CREATE;
int IN_DELETE;
int IN_ISDIR;
int /*<<< orphan*/ close(int);
int inotify_add_watch(int, char *, int);
int inotify_init();
int /*<<< orphan*/ inotify_rm_watch(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int main() {
  int length, i = 0;
  int fd;
  int wd;
  char buffer[(1024 * ((sizeof(struct inotify_event)) + 16))];
  fd = inotify_init();
  if (fd < 0) {
    perror("inotify_init");
  }
  wd = inotify_add_watch(fd, "/tmp", IN_CREATE | IN_DELETE);
  length = read(fd, buffer, (1024 * ((sizeof(struct inotify_event)) + 16)));
  if (length < 0) {
    perror("read");
  }
  while (i < length) {
    struct inotify_event *event = (struct inotify_event *)&buffer[i];
    if (event->len) {
      if (event->mask & IN_CREATE) {
        if (event->mask & IN_ISDIR) {
          printf("New directory %s created.\n", event->name);
        } else {
          printf("New file %s created.\n", event->name);
        }
      } else if (event->mask & IN_DELETE) {
        if (event->mask & IN_ISDIR) {
          printf("Directory %s deleted.\n", event->name);
        } else {
          printf("File %s deleted.\n", event->name);
        }
      }
    }
    i += (sizeof(struct inotify_event)) + event->len;
  }
  inotify_rm_watch(fd, wd);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa030,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1060 <inotify_init@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11a9 <main+0x39>
lea    0xe5c(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    0x2e2c(%rip),%rax
or     (%rax),%edx
lea    0xe48(%rip),%rsi
call   1070 <inotify_add_watch@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
lea    -0xa020(%rbp),%rsi
mov    $0xa000,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11fa <main+0x8a>
lea    0xe1d(%rip),%rdi
call   1080 <perror@plt>
jmp    11ff <main+0x8f>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1336 <main+0x1c6>
movslq -0xc(%rbp),%rcx
lea    -0xa020(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0xa028(%rbp)
mov    -0xa028(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1318 <main+0x1a8>
mov    -0xa028(%rbp),%rax
mov    (%rax),%eax
mov    0x2d8e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12a0 <main+0x130>
mov    -0xa028(%rbp),%rax
mov    (%rax),%eax
mov    0x2d83(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1284 <main+0x114>
mov    -0xa028(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd9d(%rip),%rdi
call   1030 <printf@plt>
jmp    129b <main+0x12b>
mov    -0xa028(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd9c(%rip),%rdi
call   1030 <printf@plt>
jmp    1313 <main+0x1a3>
mov    -0xa028(%rbp),%rax
mov    (%rax),%eax
mov    0x2d38(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     130e <main+0x19e>
mov    -0xa028(%rbp),%rax
mov    (%rax),%eax
mov    0x2d15(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12f2 <main+0x182>
mov    -0xa028(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd60(%rip),%rdi
call   1030 <printf@plt>
jmp    1309 <main+0x199>
mov    -0xa028(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd5b(%rip),%rdi
call   1030 <printf@plt>
jmp    130e <main+0x19e>
jmp    1313 <main+0x1a3>
jmp    1318 <main+0x1a8>
mov    -0xa028(%rbp),%rax
mov    0x10(%rax),%rcx
add    $0x18,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    11ff <main+0x8f>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1090 <inotify_rm_watch@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0xa030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa018,%rsp
xor    %eax,%eax
call   1060 <inotify_init@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1257 <main+0xe7>
mov    0x2e37(%rip),%r12
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
or     (%r12),%edx
lea    0xe60(%rip),%rsi
mov    %ebx,%edi
call   1070 <inotify_add_watch@plt>
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xa000,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1268 <main+0xf8>
je     1274 <main+0x104>
mov    %eax,%ebp
xor    %r13d,%r13d
mov    0x2dfd(%rip),%r14
jmp    11fd <main+0x8d>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
add    %r15d,%r13d
add    $0x18,%r13d
cmp    %ebp,%r13d
jge    1274 <main+0x104>
movslq %r13d,%rax
mov    0x20(%rsp,%rax,1),%r15
test   %r15,%r15
je     11f1 <main+0x81>
mov    0x10(%rsp,%rax,1),%ecx
test   %ecx,(%r12)
je     1230 <main+0xc0>
mov    0x18(%rsp,%rax,1),%rsi
test   %ecx,(%r14)
je     11e5 <main+0x75>
lea    0xdf2(%rip),%rdi
jmp    11ec <main+0x7c>
nopw   0x0(%rax,%rax,1)
mov    0x2db1(%rip),%rdx
test   %ecx,(%rdx)
je     11f1 <main+0x81>
mov    0x18(%rsp,%rax,1),%rsi
test   %ecx,(%r14)
je     124e <main+0xde>
lea    0xdfc(%rip),%rdi
jmp    11ec <main+0x7c>
lea    0xe0a(%rip),%rdi
jmp    11ec <main+0x7c>
lea    0xda2(%rip),%rdi
call   1080 <perror@plt>
jmp    1192 <main+0x22>
lea    0xda3(%rip),%rdi
call   1080 <perror@plt>
mov    %ebx,%edi
mov    0xc(%rsp),%esi
call   1090 <inotify_rm_watch@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0xa018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"inotify_init\00"
@.str.1 = [5 x i8] c"/tmp\00"
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@.str.2 = [5 x i8] c"read\00"
@IN_ISDIR = global i32 0
@.str.3 = [27 x i8] c"New directory %s created.\0A\00"
@.str.4 = [22 x i8] c"New file %s created.\0A\00"
@.str.5 = [23 x i8] c"Directory %s deleted.\0A\00"
@.str.6 = [18 x i8] c"File %s deleted.\0A\00"
define i32 @main() {
%1 = alloca [40960 x i8]
%2 = getelementptr inbounds [40960 x i8], [40960 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @inotify_init()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = load i32, i32* @IN_CREATE
%9 = load i32, i32* @IN_DELETE
%10 = or i32 %9, %8
%11 = tail call i32 @inotify_add_watch(i32 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @read(i32 %3, i8* %2, i32 40960)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %63
16: ; preds = %7
%17 = icmp eq i32 %12, 0
br i1 %17, label %63, label %18
18: ; preds = %16, %58
%19 = phi i32 [ %61, %58 ], [ 0, %16 ]
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [40960 x i8], [40960 x i8]* %1, i64 0, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 16
%23 = bitcast i8* %22 to i64*
%24 = load i64, i64* %23
%25 = icmp eq i64 %24, 0
br i1 %25, label %58, label %26
26: ; preds = %18
%27 = bitcast i8* %21 to i32*
%28 = load i32, i32* %27
%29 = load i32, i32* @IN_CREATE
%30 = and i32 %29, %28
%31 = icmp eq i32 %30, 0
br i1 %31, label %43, label %32
32: ; preds = %26
%33 = load i32, i32* @IN_ISDIR
%34 = and i32 %33, %28
%35 = icmp eq i32 %34, 0
%36 = getelementptr inbounds i8, i8* %21, i64 8
%37 = bitcast i8* %36 to i8**
%38 = load i8*, i8** %37
br i1 %35, label %41, label %39
39: ; preds = %32
%40 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %38)
br label %58
41: ; preds = %32
%42 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %38)
br label %58
43: ; preds = %26
%44 = load i32, i32* @IN_DELETE
%45 = and i32 %44, %28
%46 = icmp eq i32 %45, 0
br i1 %46, label %58, label %47
47: ; preds = %43
%48 = load i32, i32* @IN_ISDIR
%49 = and i32 %48, %28
%50 = icmp eq i32 %49, 0
%51 = getelementptr inbounds i8, i8* %21, i64 8
%52 = bitcast i8* %51 to i8**
%53 = load i8*, i8** %52
br i1 %50, label %56, label %54
54: ; preds = %47
%55 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %53)
br label %58
56: ; preds = %47
%57 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %53)
br label %58
58: ; preds = %41, %39, %54, %56, %43, %18
%59 = trunc i64 %24 to i32
%60 = add i32 %19, 24
%61 = add i32 %60, %59
%62 = icmp slt i32 %61, %12
br i1 %62, label %18, label %63
63: ; preds = %58, %14, %16
%64 = tail call i32 @inotify_rm_watch(i32 %3, i32 %11)
%65 = tail call i32 @close(i32 %3)
ret i32 0
}