#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 /*<<< 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 terminate.\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);
    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");
  while (1) {
    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    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   10e0 <inotify_init1@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1246 <main+0x86>
lea    0xe07(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d79(%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    0xddf(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1322 <main+0x162>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    0x2ceb(%rip),%rax
mov    (%rax),%edx
mov    0x2d12(%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    130f <main+0x14f>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd5f(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd66(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    1314 <main+0x154>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1283 <main+0xc3>
movl   $0x2,-0x2c(%rbp)
mov    0x2c70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2cac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xd1a(%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    13b8 <main+0x1f8>
mov    0x2c42(%rip),%rax
mov    (%rax),%rax
mov    0x2c20(%rip),%rcx
cmp    (%rcx),%rax
jne    139e <main+0x1de>
jmp    1361 <main+0x1a1>
lea    0xce6(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
jle    1459 <main+0x299>
mov    -0x48(%rbp),%eax
mov    0x2c1c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     142c <main+0x26c>
jmp    13dc <main+0x21c>
mov    0x2bbd(%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    1412 <main+0x252>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1422 <main+0x262>
jmp    1427 <main+0x267>
jmp    13dc <main+0x21c>
jmp    145e <main+0x29e>
mov    -0x3c(%rbp),%eax
mov    0x2bb2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1454 <main+0x294>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1090 <handle_events@plt>
jmp    1459 <main+0x299>
jmp    1361 <main+0x1a1>
lea    0xc2b(%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    0x2b24(%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,%r12
cmp    $0x1,%edi
jg     11fd <main+0x2d>
mov    (%r12),%rsi
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1369 <main+0x199>
mov    %edi,%ebx
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dc6(%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    1364 <main+0x194>
mov    %ebx,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
test   %rax,%rax
jne    124b <main+0x7b>
lea    0xde3(%rip),%rdi
jmp    1364 <main+0x194>
mov    %rax,%r13
mov    %ebx,0xc(%rsp)
mov    %ebx,%ebp
mov    $0x1,%ebx
mov    0x2d30(%rip),%r15
mov    0x2d59(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rsi
mov    (%r14),%edx
or     (%r15),%edx
mov    0x8(%rsp),%edi
call   10b0 <inotify_add_watch@plt>
mov    %eax,0x0(%r13,%rbx,4)
cmp    $0xffffffff,%eax
je     133b <main+0x16b>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1270 <main+0xa0>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%rsp),%ecx
mov    %ecx,0x1c(%rsp)
mov    %eax,0x20(%rsp)
lea    0xdb1(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rbx
mov    0x2cf0(%rip),%r14
mov    0x2cd1(%rip),%r15
mov    0xc(%rsp),%ebp
jmp    12f8 <main+0x128>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14),%rax
cmp    (%r15),%rax
jne    135d <main+0x18d>
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    0x2cce(%rip),%rax
mov    (%rax),%eax
test   %eax,0x18(%rsp)
jne    1377 <main+0x1a7>
test   %eax,0x24(%rsp)
je     12f8 <main+0x128>
mov    0x8(%rsp),%edi
mov    %r13,%rsi
mov    %ebp,%edx
mov    %r12,%rcx
call   10a0 <handle_events@plt>
jmp    12f8 <main+0x128>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
mov    (%r12,%rbx,8),%rdx
lea    0xce1(%rip),%rsi
call   1090 <fprintf@plt>
lea    0xce8(%rip),%rdi
jmp    1364 <main+0x194>
lea    0xcf1(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    0x7(%rsp),%rbx
mov    0x2c1d(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
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    0xcdb(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x2bd8(%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 = [31 x i8] c"Press ENTER key to terminate.\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
@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 ([31 x i8], [31 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 = %79, %41
%43 = load i32, i32* %8
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %82
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 = call i32 @inotify_add_watch(i32 %47, i8* %52, i32 %55)
%57 = load i32*, i32** %10
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
store i32 %56, i32* %60
%61 = load i32*, i32** %10
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %78
67: ; preds = %46
%68 = load i32, i32* @stderr
%69 = load i8**, i8*** %5
%70 = load i32, i32* %8
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8*, i8** %69, i64 %71
%73 = load i8*, i8** %72
%74 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %73)
%75 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %46
br label %79
79: ; preds = %78
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
store i32 %81, i32* %8
br label %42
82: ; preds = %42
store i32 2, i32* %11
%83 = load i32, i32* @STDIN_FILENO
%84 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%85 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %84, i32 0, i32 0
store i32 %83, i32* %85
%86 = load i32, i32* @POLLIN
%87 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%88 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %87, i32 0, i32 1
store i32 %86, i32* %88
%89 = load i32, i32* %7
%90 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 1
%91 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %90, i32 0, i32 0
store i32 %89, i32* %91
%92 = load i32, i32* @POLLIN
%93 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 1
%94 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %93, i32 0, i32 1
store i32 %92, i32* %94
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %96
96: ; preds = %82, %106, %148
%97 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%98 = load i32, i32* %11
%99 = call i32 @poll(%struct.pollfd* %97, i32 %98, i32 -1)
store i32 %99, i32* %9
%100 = load i32, i32* %9
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %111
102: ; preds = %96
%103 = load i64, i64* @errno
%104 = load i64, i64* @EINTR
%105 = icmp eq i64 %103, %104
br i1 %105, label %106, label %107
106: ; preds = %102
br label %96
107: ; preds = %102
%108 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%109 = load i32, i32* @EXIT_FAILURE
%110 = call i32 @exit(i32 %109)
unreachable
111: ; preds = %96
%112 = load i32, i32* %9
%113 = icmp sgt i32 %112, 0
br i1 %113, label %114, label %148
114: ; preds = %111
%115 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%116 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %115, i32 0, i32 2
%117 = load i32, i32* %116
%118 = load i32, i32* @POLLIN
%119 = and i32 %117, %118
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %134
121: ; preds = %114
br label %122
122: ; preds = %132, %121
%123 = load i32, i32* @STDIN_FILENO
%124 = call i64 @read(i32 %123, i8* %6, i32 1)
%125 = icmp sgt i64 %124, 0
br i1 %125, label %126, label %130
126: ; preds = %122
%127 = load i8, i8* %6
%128 = sext i8 %127 to i32
%129 = icmp ne i32 %128, 10
br label %130
130: ; preds = %126, %122
%131 = phi i1 [ false, %122 ], [ %129, %126 ]
br i1 %131, label %132, label %133
132: ; preds = %130
br label %122
133: ; preds = %130
br label %149
134: ; preds = %114
%135 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 1
%136 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %135, i32 0, i32 2
%137 = load i32, i32* %136
%138 = load i32, i32* @POLLIN
%139 = and i32 %137, %138
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %147
141: ; preds = %134
%142 = load i32, i32* %7
%143 = load i32*, i32** %10
%144 = load i32, i32* %4
%145 = load i8**, i8*** %5
%146 = call i32 @handle_events(i32 %142, i32* %143, i32 %144, i8** %145)
br label %147
147: ; preds = %141, %134
br label %148
148: ; preds = %147, %111
br label %96
149: ; preds = %133
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%151 = load i32, i32* %7
%152 = call i32 @close(i32 %151)
%153 = load i32*, i32** %10
%154 = call i32 @free(i32* %153)
%155 = load i32, i32* @EXIT_SUCCESS
%156 = call i32 @exit(i32 %155)
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
@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 = [30 x i8] c"Press ENTER key to terminate.\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 ([30 x i8], [30 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, %49
%31 = phi i64 [ 1, %24 ], [ %50, %49 ]
%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 = tail call i32 @inotify_add_watch(i32 %15, i8* %33, i32 %36)
%38 = getelementptr inbounds i32, i32* %22, i64 %31
store i32 %37, i32* %38
%39 = icmp eq i32 %37, -1
br i1 %39, label %40, label %49
40: ; preds = %30
%41 = and i64 %31, 4294967295
%42 = getelementptr inbounds i8*, i8** %1, i64 %41
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %42
%45 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @exit(i32 %47)
unreachable
49: ; preds = %30
%50 = add nuw nsw i64 %31, 1
%51 = icmp eq i64 %50, %25
br i1 %51, label %52, label %30
52: ; preds = %49
%53 = load i32, i32* @STDIN_FILENO
%54 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%55 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
store i32 %53, i32* %55
%56 = load i32, i32* @POLLIN
%57 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 1
store i32 %56, i32* %57
%58 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 0
store i32 %15, i32* %58
%59 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 1
store i32 %56, i32* %59
%60 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%61 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 2
%62 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 2
br label %63
63: ; preds = %76, %52
%64 = call i32 @poll(%struct.pollfd* %54, i32 2, i32 -1)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %74
66: ; preds = %63
%67 = load i64, i64* @errno
%68 = load i64, i64* @EINTR
%69 = icmp eq i64 %67, %68
br i1 %69, label %76, label %70
70: ; preds = %66
%71 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %63
%75 = icmp sgt i32 %64, 0
br i1 %75, label %77, label %76
76: ; preds = %74, %93, %89, %66
br label %63
77: ; preds = %74
%78 = load i32, i32* %61
%79 = load i32, i32* @POLLIN
%80 = and i32 %79, %78
%81 = icmp eq i32 %80, 0
br i1 %81, label %89, label %82
82: ; preds = %77, %82
%83 = load i32, i32* @STDIN_FILENO
%84 = call i64 @read(i32 %83, i8* %3, i32 1)
%85 = icmp sgt i64 %84, 0
%86 = load i8, i8* %3
%87 = icmp ne i8 %86, 10
%88 = select i1 %85, i1 %87, i1 false
br i1 %88, label %82, label %95
89: ; preds = %77
%90 = load i32, i32* %62
%91 = and i32 %90, %79
%92 = icmp eq i32 %91, 0
br i1 %92, label %76, label %93
93: ; preds = %89
%94 = call i32 @handle_events(i32 %15, i32* %22, i32 %0, i8** %1)
br label %76
95: ; preds = %82
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
%97 = call i32 @close(i32 %15)
%98 = call i32 @free(i32* %22)
%99 = load i32, i32* @EXIT_SUCCESS
%100 = call i32 @exit(i32 %99)
unreachable
}