#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 IN_ATTRIB;
int IN_CREATE;
int IN_DELETE;
int IN_DELETE_SELF;
int IN_MODIFY;
int IN_MOVED_FROM;
int IN_MOVED_TO;
int /*<<< orphan*/ IN_NONBLOCK;
int POLLIN;
int STDIN_FILENO;
int *calloc(int, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(int *);
int getsockfd();
scalar_t__ handle_events(int, 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*/ releasesockfd(int);
scalar_t__ sendConnect(int);
int /*<<< orphan*/ stderr;
int inotify(char dir[]) {
  char buf;
  int fd, i, poll_num;
  int *wd;
  nfds_t nfds;
  struct pollfd fds[2];
  i = 0;
  fd = inotify_init1(IN_NONBLOCK);
  if (fd == -1) {
    perror("inotify_init1");
    return (-1);
  }
  wd = calloc(1, sizeof(int));
  if (wd == NULL) {
    perror("calloc");
    return (-1);
  }
  wd[i] = inotify_add_watch(fd, dir,
                            IN_ATTRIB | IN_CREATE | IN_MODIFY | IN_DELETE |
                                IN_DELETE_SELF | IN_MOVED_FROM | IN_MOVED_TO);
  if (wd[i] == -1) {
    fprintf(stderr, "Cannot watch '%s'\n", dir);
    perror("inotify_add_watch");
    return (-1);
  }
  nfds = 2;
  fds[0].fd = STDIN_FILENO;
  fds[0].events = POLLIN;
  fds[1].fd = fd;
  fds[1].events = POLLIN;
  printf("Listening for events. Use enter to exit.\n");
  while (1) {
    poll_num = poll(fds, nfds, -1);
    if (poll_num == -1) {
      if (errno == EINTR)
        continue;
      perror("poll");
      return (-1);
    }
    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) {
        int sock = getsockfd();
        if (sock < 0) {
          printf("errorsock\n");
          return (-1);
        }
        if (sendConnect(sock)) {
          printf("errorSendsock\n");
          return (-1);
        }
        if (handle_events(sock, fd, wd, 1, dir) < 0) {
          printf("errorHandle\n");
          return (-1);
        }
        releasesockfd(sock);
      }
    }
  }
  close(fd);
  free(wd);
}


x86 assembly (clang, -O0):
<inotify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1100 <inotify_init1@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1226 <inotify+0x46>
lea    0xdeb(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c5 <inotify+0x2e5>
mov    $0x1,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125c <inotify+0x7c>
lea    0xdc3(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c5 <inotify+0x2e5>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
mov    0x2d25(%rip),%rax
or     (%rax),%edx
mov    0x2d74(%rip),%rax
or     (%rax),%edx
mov    0x2d4b(%rip),%rax
or     (%rax),%edx
mov    0x2cea(%rip),%rax
or     (%rax),%edx
mov    0x2d11(%rip),%rax
or     (%rax),%edx
mov    0x2d18(%rip),%rax
or     (%rax),%edx
call   10c0 <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    12f7 <inotify+0x117>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd3b(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xd42(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c5 <inotify+0x2e5>
movl   $0x2,-0x2c(%rbp)
mov    0x2c83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2cb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xd0b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    $0xffffffff,%edx
call   10d0 <poll@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1389 <inotify+0x1a9>
mov    0x2c47(%rip),%rax
mov    (%rax),%rax
mov    0x2c2d(%rip),%rcx
cmp    (%rcx),%rax
jne    1371 <inotify+0x191>
jmp    1334 <inotify+0x154>
lea    0xcec(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c5 <inotify+0x2e5>
cmpl   $0x0,-0x20(%rbp)
jle    14af <inotify+0x2cf>
mov    -0x48(%rbp),%eax
mov    0x2c3b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13fd <inotify+0x21d>
jmp    13ad <inotify+0x1cd>
mov    0x2bd4(%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,-0x55(%rbp)
jle    13e3 <inotify+0x203>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    13f3 <inotify+0x213>
jmp    13f8 <inotify+0x218>
jmp    13ad <inotify+0x1cd>
jmp    14b4 <inotify+0x2d4>
mov    -0x3c(%rbp),%eax
mov    0x2bd1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14aa <inotify+0x2ca>
mov    $0x0,%al
call   10f0 <getsockfd@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    143e <inotify+0x25e>
lea    0xc3c(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c5 <inotify+0x2e5>
mov    -0x54(%rbp),%edi
call   1080 <sendConnect@plt>
cmp    $0x0,%rax
je     1468 <inotify+0x288>
lea    0xc1d(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c5 <inotify+0x2e5>
mov    -0x54(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%r8
mov    $0x1,%ecx
call   10b0 <handle_events@plt>
cmp    $0x0,%rax
jge    14a2 <inotify+0x2c2>
lea    0xbf2(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c5 <inotify+0x2e5>
mov    -0x54(%rbp),%edi
call   1070 <releasesockfd@plt>
jmp    14af <inotify+0x2cf>
jmp    1334 <inotify+0x154>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inotify>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,0x10(%rsp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1100 <inotify_init1@plt>
cmp    $0xffffffff,%eax
je     13ba <inotify+0x1da>
mov    %eax,%r12d
mov    $0x1,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
test   %rax,%rax
je     13c3 <inotify+0x1e3>
mov    %rax,%rbx
mov    0x2db1(%rip),%rax
mov    0x2d62(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2daf(%rip),%rax
or     (%rax),%edx
mov    0x2d86(%rip),%rax
or     (%rax),%edx
mov    0x2d25(%rip),%rax
or     (%rax),%edx
mov    0x2d4c(%rip),%rax
or     (%rax),%edx
mov    0x2d53(%rip),%rax
or     (%rax),%edx
mov    %r12d,%edi
mov    0x10(%rsp),%rsi
call   10c0 <inotify_add_watch@plt>
mov    %eax,(%rbx)
cmp    $0xffffffff,%eax
je     13cc <inotify+0x1ec>
mov    %rbx,0x18(%rsp)
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2d40(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x24(%rsp)
mov    %r12d,0x2c(%rsp)
mov    %eax,0x30(%rsp)
lea    0xd90(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rbx
mov    0x2ce0(%rip),%r13
mov    0x2cc9(%rip),%r15
jmp    12dd <inotify+0xfd>
nopl   0x0(%rax)
mov    0x0(%r13),%rax
cmp    (%r15),%rax
jne    13ef <inotify+0x20f>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   10d0 <poll@plt>
cmp    $0xffffffff,%eax
je     12d0 <inotify+0xf0>
test   %eax,%eax
jle    12dd <inotify+0xfd>
mov    (%r14),%eax
test   %eax,0x28(%rsp)
jne    1347 <inotify+0x167>
test   %eax,0x34(%rsp)
je     12dd <inotify+0xfd>
xor    %eax,%eax
call   10f0 <getsockfd@plt>
test   %eax,%eax
js     1390 <inotify+0x1b0>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <sendConnect@plt>
test   %rax,%rax
jne    139e <inotify+0x1be>
mov    %ebp,%edi
mov    %r12d,%esi
mov    0x18(%rsp),%rdx
mov    $0x1,%ecx
mov    0x10(%rsp),%r8
call   10b0 <handle_events@plt>
test   %rax,%rax
js     13ac <inotify+0x1cc>
mov    %ebp,%edi
call   1070 <releasesockfd@plt>
jmp    12dd <inotify+0xfd>
lea    0xf(%rsp),%rbx
mov    0x2c35(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    137c <inotify+0x19c>
cmpb   $0xa,0xf(%rsp)
jne    1360 <inotify+0x180>
mov    %r12d,%edi
call   1050 <close@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
jmp    13fb <inotify+0x21b>
lea    0xceb(%rip),%rdi
call   1040 <puts@plt>
jmp    13fb <inotify+0x21b>
lea    0xccf(%rip),%rdi
call   1040 <puts@plt>
jmp    13fb <inotify+0x21b>
lea    0xcb5(%rip),%rdi
call   1040 <puts@plt>
jmp    13fb <inotify+0x21b>
lea    0xc3f(%rip),%rdi
jmp    13f6 <inotify+0x216>
lea    0xc44(%rip),%rdi
jmp    13f6 <inotify+0x216>
mov    0x2bdd(%rip),%rax
mov    (%rax),%edi
lea    0xc39(%rip),%rsi
mov    0x10(%rsp),%rdx
call   10a0 <fprintf@plt>
lea    0xc3b(%rip),%rdi
jmp    13f6 <inotify+0x216>
lea    0xc44(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@IN_NONBLOCK = global i32 0
@.str = [14 x i8] c"inotify_init1\00"
@.str.1 = [7 x i8] c"calloc\00"
@IN_ATTRIB = global i32 0
@IN_CREATE = global i32 0
@IN_MODIFY = global i32 0
@IN_DELETE = global i32 0
@IN_DELETE_SELF = global i32 0
@IN_MOVED_FROM = global i32 0
@IN_MOVED_TO = global i32 0
@stderr = global i32 0
@.str.2 = [19 x i8] c"Cannot watch '%s'\0A\00"
@.str.3 = [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.5 = [5 x i8] c"poll\00"
@str = [41 x i8] c"Listening for events. Use enter to exit.\00"
@str.9 = [12 x i8] c"errorHandle\00"
@str.10 = [14 x i8] c"errorSendsock\00"
@str.11 = [10 x i8] c"errorsock\00"
define i32 @inotify(i8* %0) {
%2 = alloca i8
%3 = alloca [2 x %struct.pollfd]
%4 = bitcast [2 x %struct.pollfd]* %3 to i8*
%5 = load i32, i32* @IN_NONBLOCK
%6 = tail call i32 @inotify_init1(i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %94
10: ; preds = %1
%11 = tail call i32* @calloc(i32 1, i32 4)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %94
15: ; preds = %10
%16 = load i32, i32* @IN_ATTRIB
%17 = load i32, i32* @IN_CREATE
%18 = or i32 %17, %16
%19 = load i32, i32* @IN_MODIFY
%20 = or i32 %18, %19
%21 = load i32, i32* @IN_DELETE
%22 = or i32 %20, %21
%23 = load i32, i32* @IN_DELETE_SELF
%24 = or i32 %22, %23
%25 = load i32, i32* @IN_MOVED_FROM
%26 = or i32 %24, %25
%27 = load i32, i32* @IN_MOVED_TO
%28 = or i32 %26, %27
%29 = tail call i32 @inotify_add_watch(i32 %6, i8* %0, i32 %28)
store i32 %29, i32* %11
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %15
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%34 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %94
35: ; preds = %15
%36 = load i32, i32* @STDIN_FILENO
%37 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 0
%38 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 0, i32 0
store i32 %36, i32* %38
%39 = load i32, i32* @POLLIN
%40 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 0, i32 1
store i32 %39, i32* %40
%41 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 1, i32 0
store i32 %6, i32* %41
%42 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 1, i32 1
store i32 %39, i32* %42
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%44 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 0, i32 2
%45 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 1, i32 2
br label %46
46: ; preds = %57, %35
%47 = call i32 @poll(%struct.pollfd* %37, i32 2, i32 -1)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %55
49: ; preds = %46
%50 = load i64, i64* @errno
%51 = load i64, i64* @EINTR
%52 = icmp eq i64 %50, %51
br i1 %52, label %57, label %53
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %94
55: ; preds = %46
%56 = icmp sgt i32 %47, 0
br i1 %56, label %58, label %57
57: ; preds = %55, %70, %89, %49
br label %46
58: ; preds = %55
%59 = load i32, i32* %44
%60 = load i32, i32* @POLLIN
%61 = and i32 %60, %59
%62 = icmp eq i32 %61, 0
br i1 %62, label %70, label %63
63: ; preds = %58, %63
%64 = load i32, i32* @STDIN_FILENO
%65 = call i64 @read(i32 %64, i8* %2, i32 1)
%66 = icmp sgt i64 %65, 0
%67 = load i8, i8* %2
%68 = icmp ne i8 %67, 10
%69 = select i1 %66, i1 %68, i1 false
br i1 %69, label %63, label %91
70: ; preds = %58
%71 = load i32, i32* %45
%72 = and i32 %71, %60
%73 = icmp eq i32 %72, 0
br i1 %73, label %57, label %74
74: ; preds = %70
%75 = call i32 (...) @getsockfd()
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %74
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.11, i64 0, i64 0))
br label %94
79: ; preds = %74
%80 = call i64 @sendConnect(i32 %75)
%81 = icmp eq i64 %80, 0
br i1 %81, label %84, label %82
82: ; preds = %79
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
br label %94
84: ; preds = %79
%85 = call i64 @handle_events(i32 %75, i32 %6, i32* %11, i32 1, i8* %0)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %84
%88 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %94
89: ; preds = %84
%90 = call i32 @releasesockfd(i32 %75)
br label %57
91: ; preds = %63
%92 = call i32 @close(i32 %6)
%93 = call i32 @free(i32* %11)
br label %94
94: ; preds = %77, %82, %87, %91, %53, %31, %13, %8
ret i32 -1
}