#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 pollfd {
  int fd;
  int events;
  int revents;
};
typedef int nfds_t;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int IN_CLOSE;
int IN_MOVE;
int /*<<< orphan*/ IN_NONBLOCK;
int IN_OPEN;
int POLLIN;
int STDIN_FILENO;
int *calloc(int, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ handle_events(int, int *, int, char **);
int inotify_add_watch(int, char *, int);
int inotify_init1(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char buf;
  int fd, i, poll_num;
  int *wd;
  nfds_t nfds;
  struct pollfd fds[2];
  if (argc < 2) {
    printf("Usage: %s PATH [PATH ...]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  printf("Press ENTER key to exit.\n");
  fd = inotify_init1(IN_NONBLOCK);
  if (fd == -1) {
    perror("inotify_init1");
    exit(EXIT_FAILURE);
  }
  wd = calloc(argc, sizeof(int));
  if (wd == NULL) {
    perror("calloc");
    exit(EXIT_FAILURE);
  }
  for (i = 1; i < argc; i++) {
    wd[i] = inotify_add_watch(fd, argv[i], IN_OPEN | IN_CLOSE | IN_MOVE);
    if (wd[i] == -1) {
      fprintf(stderr, "Cannot watch '%s'\n", argv[i]);
      perror("inotify_add_watch");
      exit(EXIT_FAILURE);
    }
  }
  nfds = 2;
  fds[0].fd = STDIN_FILENO;
  fds[0].events = POLLIN;
  fds[1].fd = fd;
  fds[1].events = POLLIN;
  printf("Listening for events.\n");
  for (;;) {
    poll_num = poll(fds, nfds, -1);
    if (poll_num == -1) {
      if (errno == EINTR)
        continue;
      perror("poll");
      exit(EXIT_FAILURE);
    }
    if (poll_num > 0) {
      if (fds[0].revents & POLLIN) {
        while (read(STDIN_FILENO, &buf, 1) > 0 && buf != '\n')
          continue;
        break;
      }
      if (fds[1].revents & POLLIN) {
        handle_events(fd, wd, argc, argv);
      }
    }
  }
  printf("Listening for events stopped.\n");
  close(fd);
  free(wd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1203 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   10e0 <inotify_init1@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1246 <main+0x86>
lea    0xe02(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    127c <main+0xbc>
lea    0xdda(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    132b <main+0x16b>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    0x2ce3(%rip),%rax
mov    (%rax),%edx
mov    0x2d0a(%rip),%rax
or     (%rax),%edx
mov    0x2d31(%rip),%rax
or     (%rax),%edx
call   10a0 <inotify_add_watch@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
jne    1318 <main+0x158>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd51(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd58(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    131d <main+0x15d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1283 <main+0xc3>
movl   $0x2,-0x2c(%rbp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    $0xffffffff,%edx
call   10b0 <poll@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    13c1 <main+0x201>
mov    0x2c31(%rip),%rax
mov    (%rax),%rax
mov    0x2c0f(%rip),%rcx
cmp    (%rcx),%rax
jne    13a7 <main+0x1e7>
jmp    136a <main+0x1aa>
lea    0xcd8(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jle    1462 <main+0x2a2>
mov    -0x48(%rbp),%eax
mov    0x2c0b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1435 <main+0x275>
jmp    13e5 <main+0x225>
mov    0x2bac(%rip),%rax
mov    (%rax),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x51(%rbp)
jle    141b <main+0x25b>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    142b <main+0x26b>
jmp    1430 <main+0x270>
jmp    13e5 <main+0x225>
jmp    1467 <main+0x2a7>
mov    -0x3c(%rbp),%eax
mov    0x2ba1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     145d <main+0x29d>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1090 <handle_events@plt>
jmp    1462 <main+0x2a2>
jmp    136a <main+0x1aa>
lea    0xc1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r13
cmp    $0x1,%edi
jg     11fd <main+0x2d>
mov    0x0(%r13),%rsi
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    136a <main+0x19a>
mov    %edi,%ebp
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   10f0 <inotify_init1@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
jne    122e <main+0x5e>
lea    0xdf2(%rip),%rdi
jmp    1365 <main+0x195>
mov    %ebp,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
test   %rax,%rax
jne    124b <main+0x7b>
lea    0xde3(%rip),%rdi
jmp    1365 <main+0x195>
mov    %rax,%r12
mov    %ebp,0xc(%rsp)
mov    %ebp,%ebp
mov    $0x1,%ebx
mov    0x2d58(%rip),%r14
mov    0x2d81(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rsi
mov    (%r14),%edx
mov    0x2d09(%rip),%rax
or     (%rax),%edx
or     (%r15),%edx
mov    0x8(%rsp),%edi
call   10b0 <inotify_add_watch@plt>
mov    %eax,(%r12,%rbx,4)
cmp    $0xffffffff,%eax
je     133b <main+0x16b>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <main+0xa0>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%rsp),%ecx
mov    %ecx,0x1c(%rsp)
mov    %eax,0x20(%rsp)
lea    0xda3(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rbx
mov    0x2cdf(%rip),%r14
mov    0x2cc0(%rip),%r15
mov    0xc(%rsp),%ebp
jmp    12f8 <main+0x128>
xchg   %ax,%ax
mov    (%r14),%rax
cmp    (%r15),%rax
jne    135e <main+0x18e>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   10c0 <poll@plt>
cmp    $0xffffffff,%eax
je     12f0 <main+0x120>
test   %eax,%eax
jle    12f8 <main+0x128>
mov    0x2cc6(%rip),%rax
mov    (%rax),%eax
test   %eax,0x18(%rsp)
jne    1378 <main+0x1a8>
test   %eax,0x24(%rsp)
je     12f8 <main+0x128>
mov    0x8(%rsp),%edi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r13,%rcx
call   10a0 <handle_events@plt>
jmp    12f8 <main+0x128>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13,%rbx,8),%rdx
lea    0xce0(%rip),%rsi
call   1090 <fprintf@plt>
lea    0xce7(%rip),%rdi
jmp    1365 <main+0x195>
lea    0xcf0(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0x7(%rsp),%rbx
mov    0x2c14(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %rax,%rax
jle    13ac <main+0x1dc>
cmpb   $0xa,0x7(%rsp)
jne    1390 <main+0x1c0>
lea    0xcd6(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [27 x i8] c"Usage: %s PATH [PATH ...]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [26 x i8] c"Press ENTER key to exit.\0A\00"
@IN_NONBLOCK = global i32 0
@.str.2 = [14 x i8] c"inotify_init1\00"
@.str.3 = [7 x i8] c"calloc\00"
@IN_OPEN = global i32 0
@IN_CLOSE = global i32 0
@IN_MOVE = global i32 0
@stderr = global i32 0
@.str.4 = [19 x i8] c"Cannot watch '%s'\0A\00"
@.str.5 = [18 x i8] c"inotify_add_watch\00"
@STDIN_FILENO = global i32 0
@POLLIN = global i32 0
@.str.6 = [23 x i8] c"Listening for events.\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.7 = [5 x i8] c"poll\00"
@.str.8 = [31 x i8] c"Listening for events stopped.\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 i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [2 x %struct.pollfd]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @IN_NONBLOCK
%25 = call i32 @inotify_init1(i32 %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
%33 = load i32, i32* %4
%34 = call i32* @calloc(i32 %33, i32 4)
store i32* %34, i32** %10
%35 = load i32*, i32** %10
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %32
store i32 1, i32* %8
br label %42
42: ; preds = %81, %41
%43 = load i32, i32* %8
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %84
46: ; preds = %42
%47 = load i32, i32* %7
%48 = load i8**, i8*** %5
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = load i32, i32* @IN_OPEN
%54 = load i32, i32* @IN_CLOSE
%55 = or i32 %53, %54
%56 = load i32, i32* @IN_MOVE
%57 = or i32 %55, %56
%58 = call i32 @inotify_add_watch(i32 %47, i8* %52, i32 %57)
%59 = load i32*, i32** %10
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
store i32 %58, i32* %62
%63 = load i32*, i32** %10
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %80
69: ; preds = %46
%70 = load i32, i32* @stderr
%71 = load i8**, i8*** %5
%72 = load i32, i32* %8
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %75)
%77 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %46
br label %81
81: ; preds = %80
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %42
84: ; preds = %42
store i32 2, i32* %11
%85 = load i32, i32* @STDIN_FILENO
%86 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%87 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %86, i32 0, i32 0
store i32 %85, i32* %87
%88 = load i32, i32* @POLLIN
%89 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%90 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %89, i32 0, i32 1
store i32 %88, i32* %90
%91 = load i32, i32* %7
%92 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 1
%93 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %92, i32 0, i32 0
store i32 %91, i32* %93
%94 = load i32, i32* @POLLIN
%95 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 1
%96 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %95, i32 0, i32 1
store i32 %94, i32* %96
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %98
98: ; preds = %150, %108, %84
%99 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%100 = load i32, i32* %11
%101 = call i32 @poll(%struct.pollfd* %99, i32 %100, i32 -1)
store i32 %101, i32* %9
%102 = load i32, i32* %9
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %113
104: ; preds = %98
%105 = load i64, i64* @errno
%106 = load i64, i64* @EINTR
%107 = icmp eq i64 %105, %106
br i1 %107, label %108, label %109
108: ; preds = %104
br label %98
109: ; preds = %104
%110 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%111 = load i32, i32* @EXIT_FAILURE
%112 = call i32 @exit(i32 %111)
unreachable
113: ; preds = %98
%114 = load i32, i32* %9
%115 = icmp sgt i32 %114, 0
br i1 %115, label %116, label %150
116: ; preds = %113
%117 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%118 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %117, i32 0, i32 2
%119 = load i32, i32* %118
%120 = load i32, i32* @POLLIN
%121 = and i32 %119, %120
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %136
123: ; preds = %116
br label %124
124: ; preds = %134, %123
%125 = load i32, i32* @STDIN_FILENO
%126 = call i64 @read(i32 %125, i8* %6, i32 1)
%127 = icmp sgt i64 %126, 0
br i1 %127, label %128, label %132
128: ; preds = %124
%129 = load i8, i8* %6
%130 = sext i8 %129 to i32
%131 = icmp ne i32 %130, 10
br label %132
132: ; preds = %128, %124
%133 = phi i1 [ false, %124 ], [ %131, %128 ]
br i1 %133, label %134, label %135
134: ; preds = %132
br label %124
135: ; preds = %132
br label %151
136: ; preds = %116
%137 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 1
%138 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %137, i32 0, i32 2
%139 = load i32, i32* %138
%140 = load i32, i32* @POLLIN
%141 = and i32 %139, %140
%142 = icmp ne i32 %141, 0
br i1 %142, label %143, label %149
143: ; preds = %136
%144 = load i32, i32* %7
%145 = load i32*, i32** %10
%146 = load i32, i32* %4
%147 = load i8**, i8*** %5
%148 = call i32 @handle_events(i32 %144, i32* %145, i32 %146, i8** %147)
br label %149
149: ; preds = %143, %136
br label %150
150: ; preds = %149, %113
br label %98
151: ; preds = %135
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%153 = load i32, i32* %7
%154 = call i32 @close(i32 %153)
%155 = load i32*, i32** %10
%156 = call i32 @free(i32* %155)
%157 = load i32, i32* @EXIT_SUCCESS
%158 = call i32 @exit(i32 %157)
unreachable
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@.str = [27 x i8] c"Usage: %s PATH [PATH ...]\0A\00"
@EXIT_FAILURE = global i32 0
@IN_NONBLOCK = global i32 0
@.str.2 = [14 x i8] c"inotify_init1\00"
@.str.3 = [7 x i8] c"calloc\00"
@IN_OPEN = global i32 0
@IN_CLOSE = global i32 0
@IN_MOVE = global i32 0
@stderr = global i32 0
@.str.4 = [19 x i8] c"Cannot watch '%s'\0A\00"
@.str.5 = [18 x i8] c"inotify_add_watch\00"
@STDIN_FILENO = global i32 0
@POLLIN = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str.7 = [5 x i8] c"poll\00"
@EXIT_SUCCESS = global i32 0
@str = [25 x i8] c"Press ENTER key to exit.\00"
@str.9 = [22 x i8] c"Listening for events.\00"
@str.10 = [30 x i8] c"Listening for events stopped.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8
%4 = alloca [2 x %struct.pollfd]
%5 = bitcast [2 x %struct.pollfd]* %4 to i8*
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* @IN_NONBLOCK
%15 = tail call i32 @inotify_init1(i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %12
%22 = tail call i32* @calloc(i32 %0, i32 4)
%23 = icmp eq i32* %22, null
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = zext i32 %0 to i64
br label %30
26: ; preds = %21
%27 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %24, %51
%31 = phi i64 [ 1, %24 ], [ %52, %51 ]
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = load i32, i32* @IN_OPEN
%35 = load i32, i32* @IN_CLOSE
%36 = or i32 %35, %34
%37 = load i32, i32* @IN_MOVE
%38 = or i32 %36, %37
%39 = tail call i32 @inotify_add_watch(i32 %15, i8* %33, i32 %38)
%40 = getelementptr inbounds i32, i32* %22, i64 %31
store i32 %39, i32* %40
%41 = icmp eq i32 %39, -1
br i1 %41, label %42, label %51
42: ; preds = %30
%43 = and i64 %31, 4294967295
%44 = getelementptr inbounds i8*, i8** %1, i64 %43
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %44
%47 = tail call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = tail call i32 @exit(i32 %49)
unreachable
51: ; preds = %30
%52 = add nuw nsw i64 %31, 1
%53 = icmp eq i64 %52, %25
br i1 %53, label %54, label %30
54: ; preds = %51
%55 = load i32, i32* @STDIN_FILENO
%56 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%57 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
store i32 %55, i32* %57
%58 = load i32, i32* @POLLIN
%59 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 1
store i32 %58, i32* %59
%60 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 0
store i32 %15, i32* %60
%61 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 1
store i32 %58, i32* %61
%62 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%63 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 2
%64 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 2
br label %65
65: ; preds = %78, %54
%66 = call i32 @poll(%struct.pollfd* %56, i32 2, i32 -1)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %76
68: ; preds = %65
%69 = load i64, i64* @errno
%70 = load i64, i64* @EINTR
%71 = icmp eq i64 %69, %70
br i1 %71, label %78, label %72
72: ; preds = %68
%73 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %65
%77 = icmp sgt i32 %66, 0
br i1 %77, label %79, label %78
78: ; preds = %76, %95, %91, %68
br label %65
79: ; preds = %76
%80 = load i32, i32* %63
%81 = load i32, i32* @POLLIN
%82 = and i32 %81, %80
%83 = icmp eq i32 %82, 0
br i1 %83, label %91, label %84
84: ; preds = %79, %84
%85 = load i32, i32* @STDIN_FILENO
%86 = call i64 @read(i32 %85, i8* %3, i32 1)
%87 = icmp sgt i64 %86, 0
%88 = load i8, i8* %3
%89 = icmp ne i8 %88, 10
%90 = select i1 %87, i1 %89, i1 false
br i1 %90, label %84, label %97
91: ; preds = %79
%92 = load i32, i32* %64
%93 = and i32 %92, %81
%94 = icmp eq i32 %93, 0
br i1 %94, label %78, label %95
95: ; preds = %91
%96 = call i32 @handle_events(i32 %15, i32* %22, i32 %0, i8** %1)
br label %78
97: ; preds = %84
%98 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
%99 = call i32 @close(i32 %15)
%100 = call i32 @free(i32* %22)
%101 = load i32, i32* @EXIT_SUCCESS
%102 = call i32 @exit(i32 %101)
unreachable
}