#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 len;
  int mask;
  int wd;
  int cookie;
  char *name;
};
typedef int int32_t;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ GetMask(int);
int IN_ACCESS;
int /*<<< orphan*/ IN_ALL_EVENTS;
int IN_ATTRIB;
int IN_CLOSE_NOWRITE;
int IN_CLOSE_WRITE;
int IN_CREATE;
int IN_DELETE;
int IN_DELETE_SELF;
int IN_MODIFY;
int IN_MOVED_FROM;
int IN_MOVED_TO;
int IN_MOVE_SELF;
int IN_OPEN;
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char **args) {
  if (argc <= 1) {
    printf("no folder to watch!\n");
    return 1;
  }
  int fd = inotify_init();
  if (-1 == fd) {
    perror("init error\n");
    return 2;
  }
  int i;
  int ret;
  int32_t mask = IN_ACCESS | IN_ATTRIB | IN_CLOSE_WRITE | IN_CLOSE_NOWRITE |
                 IN_CREATE | IN_DELETE | IN_DELETE_SELF | IN_MODIFY |
                 IN_MOVE_SELF | IN_MOVED_FROM | IN_MOVED_TO | IN_OPEN;
  for (i = 0; i < argc; i++) {
    ret = inotify_add_watch(fd, args[i], IN_ALL_EVENTS);
    if (-1 == ret) {
      perror("add_watch error\n");
      return 3;
    }
  }
  struct inotify_event *ev;
  char buff[1024];
  while (true) {
    memset(buff, 0, sizeof(buff));
    ret = read(fd, buff, sizeof(buff));
    if (-1 == ret) {
      perror("read error\n");
      return 4;
    }
    buff[ret] = '\0';
    ev = (struct inotify_event *)&buff;
    printf("filename: %d\n", ev->len);
    GetMask(ev->mask);
    printf("watch fd: %d, mask: %d, cookie: %d, name: %s\n", ev->wd, ev->mask,
           ev->cookie, ev->name);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11ad <main+0x3d>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1374 <main+0x204>
mov    $0x0,%al
call   1070 <inotify_init@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    11dd <main+0x6d>
lea    0xe49(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1374 <main+0x204>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    0x2df3(%rip),%rcx
or     (%rcx),%eax
mov    0x2dda(%rip),%rcx
or     (%rcx),%eax
mov    0x2dd9(%rip),%rcx
or     (%rcx),%eax
mov    0x2d90(%rip),%rcx
or     (%rcx),%eax
mov    0x2db7(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5e(%rip),%rcx
or     (%rcx),%eax
mov    0x2dcd(%rip),%rcx
or     (%rcx),%eax
mov    0x2d74(%rip),%rcx
or     (%rcx),%eax
mov    0x2d73(%rip),%rcx
or     (%rcx),%eax
mov    0x2d72(%rip),%rcx
or     (%rcx),%eax
mov    0x2d39(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b8 <main+0x148>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    0x2d1b(%rip),%rax
mov    (%rax),%edx
call   1080 <inotify_add_watch@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    12a5 <main+0x135>
lea    0xd8d(%rip),%rdi
call   1090 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    1374 <main+0x204>
jmp    12aa <main+0x13a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1253 <main+0xe3>
jmp    12bd <main+0x14d>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    130d <main+0x19d>
lea    0xd36(%rip),%rdi
call   1090 <perror@plt>
movl   $0x4,-0x4(%rbp)
jmp    1374 <main+0x204>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <GetMask@plt>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%r8
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12bd <main+0x14d>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
cmp    $0x1,%edi
jg     11b9 <main+0x39>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%r15
mov    %edi,%r14d
xor    %eax,%eax
call   1080 <inotify_init@plt>
cmp    $0xffffffff,%eax
jne    11de <main+0x5e>
lea    0xe2e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%eax
jmp    11a7 <main+0x27>
mov    %eax,%r13d
mov    %r14d,%ebp
xor    %ebx,%ebx
mov    0x2df3(%rip),%r14
nopl   (%rax)
mov    (%r15,%rbx,8),%rsi
mov    (%r14),%edx
mov    %r13d,%edi
call   1090 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
je     12c1 <main+0x141>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11f0 <main+0x70>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     12ab <main+0x12b>
lea    0xdea(%rip),%r14
lea    0xdf1(%rip),%r15
mov    %rsp,%r12
nopl   0x0(%rax)
cltq
movb   $0x0,(%rsp,%rax,1)
mov    (%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
call   1050 <GetMask@plt>
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    1250 <main+0xd0>
lea    0xd6b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x4,%eax
jmp    11a7 <main+0x27>
lea    0xd44(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%eax
jmp    11a7 <main+0x27>

LLVM IR (-O0):
%struct.inotify_event = type { i32, i32, i32, i32, i8* }
@.str = [21 x i8] c"no folder to watch!\0A\00"
@.str.1 = [12 x i8] c"init error\0A\00"
@IN_ACCESS = global i32 0
@IN_ATTRIB = global i32 0
@IN_CLOSE_WRITE = global i32 0
@IN_CLOSE_NOWRITE = global i32 0
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@IN_DELETE_SELF = global i32 0
@IN_MODIFY = global i32 0
@IN_MOVE_SELF = global i32 0
@IN_MOVED_FROM = global i32 0
@IN_MOVED_TO = global i32 0
@IN_OPEN = global i32 0
@IN_ALL_EVENTS = global i32 0
@.str.2 = [17 x i8] c"add_watch error\0A\00"
@.str.3 = [12 x i8] c"read error\0A\00"
@.str.4 = [14 x i8] c"filename: %d\0A\00"
@.str.5 = [46 x i8] c"watch fd: %d, mask: %d, cookie: %d, name: %s\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 i32
%9 = alloca i32
%10 = alloca %struct.inotify_event*
%11 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %104
16: ; preds = %2
%17 = call i32 (...) @inotify_init()
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 -1, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %104
22: ; preds = %16
%23 = load i32, i32* @IN_ACCESS
%24 = load i32, i32* @IN_ATTRIB
%25 = or i32 %23, %24
%26 = load i32, i32* @IN_CLOSE_WRITE
%27 = or i32 %25, %26
%28 = load i32, i32* @IN_CLOSE_NOWRITE
%29 = or i32 %27, %28
%30 = load i32, i32* @IN_CREATE
%31 = or i32 %29, %30
%32 = load i32, i32* @IN_DELETE
%33 = or i32 %31, %32
%34 = load i32, i32* @IN_DELETE_SELF
%35 = or i32 %33, %34
%36 = load i32, i32* @IN_MODIFY
%37 = or i32 %35, %36
%38 = load i32, i32* @IN_MOVE_SELF
%39 = or i32 %37, %38
%40 = load i32, i32* @IN_MOVED_FROM
%41 = or i32 %39, %40
%42 = load i32, i32* @IN_MOVED_TO
%43 = or i32 %41, %42
%44 = load i32, i32* @IN_OPEN
%45 = or i32 %43, %44
store i32 %45, i32* %9
store i32 0, i32* %7
br label %46
46: ; preds = %64, %22
%47 = load i32, i32* %7
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %67
50: ; preds = %46
%51 = load i32, i32* %6
%52 = load i8**, i8*** %5
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = load i32, i32* @IN_ALL_EVENTS
%58 = call i32 @inotify_add_watch(i32 %51, i8* %56, i32 %57)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp eq i32 -1, %59
br i1 %60, label %61, label %63
61: ; preds = %50
%62 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 3, i32* %3
br label %104
63: ; preds = %50
br label %64
64: ; preds = %63
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %46
67: ; preds = %46
br label %68
68: ; preds = %67, %78
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%70 = call i32 @memset(i8* %69, i32 0, i32 1024)
%71 = load i32, i32* %6
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%73 = call i32 @read(i32 %71, i8* %72, i32 1024)
store i32 %73, i32* %8
%74 = load i32, i32* %8
%75 = icmp eq i32 -1, %74
br i1 %75, label %76, label %78
76: ; preds = %68
%77 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 4, i32* %3
br label %104
78: ; preds = %68
%79 = load i32, i32* %8
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %80
store i8 0, i8* %81
%82 = bitcast [1024 x i8]* %11 to %struct.inotify_event*
store %struct.inotify_event* %82, %struct.inotify_event** %10
%83 = load %struct.inotify_event*, %struct.inotify_event** %10
%84 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %83, i32 0, i32 0
%85 = load i32, i32* %84
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %85)
%87 = load %struct.inotify_event*, %struct.inotify_event** %10
%88 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %87, i32 0, i32 1
%89 = load i32, i32* %88
%90 = call i32 @GetMask(i32 %89)
%91 = load %struct.inotify_event*, %struct.inotify_event** %10
%92 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %91, i32 0, i32 2
%93 = load i32, i32* %92
%94 = load %struct.inotify_event*, %struct.inotify_event** %10
%95 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %94, i32 0, i32 1
%96 = load i32, i32* %95
%97 = load %struct.inotify_event*, %struct.inotify_event** %10
%98 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %97, i32 0, i32 3
%99 = load i32, i32* %98
%100 = load %struct.inotify_event*, %struct.inotify_event** %10
%101 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %100, i32 0, i32 4
%102 = load i8*, i8** %101
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %93, i32 %96, i32 %99, i8* %102)
br label %68
104: ; preds = %76, %61, %20, %14
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"init error\0A\00"
@IN_ACCESS = global i32 0
@IN_ATTRIB = global i32 0
@IN_CLOSE_WRITE = global i32 0
@IN_CLOSE_NOWRITE = global i32 0
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@IN_DELETE_SELF = global i32 0
@IN_MODIFY = global i32 0
@IN_MOVE_SELF = global i32 0
@IN_MOVED_FROM = global i32 0
@IN_MOVED_TO = global i32 0
@IN_OPEN = global i32 0
@IN_ALL_EVENTS = global i32 0
@.str.2 = [17 x i8] c"add_watch error\0A\00"
@.str.3 = [12 x i8] c"read error\0A\00"
@.str.4 = [14 x i8] c"filename: %d\0A\00"
@.str.5 = [46 x i8] c"watch fd: %d, mask: %d, cookie: %d, name: %s\0A\00"
@str = [20 x i8] c"no folder to watch!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %59
7: ; preds = %2
%8 = tail call i32 (...) @inotify_init()
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = zext i32 %0 to i64
br label %16
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %59
14: ; preds = %16
%15 = icmp eq i64 %23, %11
br i1 %15, label %26, label %16
16: ; preds = %10, %14
%17 = phi i64 [ 0, %10 ], [ %23, %14 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = load i32, i32* @IN_ALL_EVENTS
%21 = tail call i32 @inotify_add_watch(i32 %8, i8* %19, i32 %20)
%22 = icmp eq i32 %21, -1
%23 = add nuw nsw i64 %17, 1
br i1 %22, label %24, label %14
24: ; preds = %16
%25 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %59
26: ; preds = %14
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i32 0, i32 1024)
%29 = call i32 @read(i32 %8, i8* %27, i32 1024)
%30 = icmp eq i32 %29, -1
br i1 %30, label %41, label %31
31: ; preds = %26
%32 = bitcast [1024 x i8]* %3 to i32*
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
%34 = bitcast i8* %33 to i32*
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 8
%36 = bitcast i8* %35 to i32*
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 12
%38 = bitcast i8* %37 to i32*
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 16
%40 = bitcast i8* %39 to i8**
br label %43
41: ; preds = %43, %26
%42 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %59
43: ; preds = %31, %43
%44 = phi i32 [ %29, %31 ], [ %57, %43 ]
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %45
store i8 0, i8* %46
%47 = load i32, i32* %32
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %34
%50 = call i32 @GetMask(i32 %49)
%51 = load i32, i32* %36
%52 = load i32, i32* %34
%53 = load i32, i32* %38
%54 = load i8*, i8** %40
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.5, i64 0, i64 0), i32 %51, i32 %52, i32 %53, i8* %54)
%56 = call i32 @memset(i8* %27, i32 0, i32 1024)
%57 = call i32 @read(i32 %8, i8* %27, i32 1024)
%58 = icmp eq i32 %57, -1
br i1 %58, label %41, label %43
59: ; preds = %12, %41, %24, %5
%60 = phi i32 [ 1, %5 ], [ 2, %12 ], [ 3, %24 ], [ 4, %41 ]
ret i32 %60
}