#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_CREATE;
int IN_DELETE;
int IN_MODIFY;
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);
  }
  printf("%d\n", i);
  wd[i] = inotify_add_watch(fd, dir, IN_CREATE | IN_MODIFY | IN_DELETE);
  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)
          return (-1);
        if (sendConnect(sock))
          return (-1);
        if (handle_events(sock, fd, wd, 1, dir) < 0)
          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    0x2dce(%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    1490 <inotify+0x2b0>
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    1490 <inotify+0x2b0>
mov    -0x1c(%rbp),%esi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
mov    0x2d6c(%rip),%rax
or     (%rax),%edx
mov    0x2d4b(%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    12e4 <inotify+0x104>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd52(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0xd59(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1490 <inotify+0x2b0>
movl   $0x2,-0x2c(%rbp)
mov    0x2cae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xd22(%rip),%rdi
mov    $0x0,%al
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    1378 <inotify+0x198>
mov    0x2c70(%rip),%rax
mov    (%rax),%rax
mov    0x2c56(%rip),%rcx
cmp    (%rcx),%rax
jne    1360 <inotify+0x180>
jmp    1323 <inotify+0x143>
lea    0xd01(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1490 <inotify+0x2b0>
cmpl   $0x0,-0x20(%rbp)
jle    147a <inotify+0x29a>
mov    -0x48(%rbp),%eax
mov    0x2c54(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13ec <inotify+0x20c>
jmp    139c <inotify+0x1bc>
mov    0x2bfd(%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    13d2 <inotify+0x1f2>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    13e2 <inotify+0x202>
jmp    13e7 <inotify+0x207>
jmp    139c <inotify+0x1bc>
jmp    147f <inotify+0x29f>
mov    -0x3c(%rbp),%eax
mov    0x2bea(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1475 <inotify+0x295>
mov    $0x0,%al
call   10f0 <getsockfd@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1421 <inotify+0x241>
movl   $0xffffffff,-0x4(%rbp)
jmp    1490 <inotify+0x2b0>
mov    -0x54(%rbp),%edi
call   1080 <sendConnect@plt>
cmp    $0x0,%rax
je     143f <inotify+0x25f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1490 <inotify+0x2b0>
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    146d <inotify+0x28d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1490 <inotify+0x2b0>
mov    -0x54(%rbp),%edi
call   1070 <releasesockfd@plt>
jmp    147a <inotify+0x29a>
jmp    1323 <inotify+0x143>
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    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1110 <inotify_init1@plt>
cmp    $0xffffffff,%eax
je     13a2 <inotify+0x1b2>
mov    %eax,%r12d
mov    $0x1,%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
test   %rax,%rax
je     13b0 <inotify+0x1c0>
mov    %rax,%rbx
lea    0xdd6(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d61(%rip),%rax
mov    0x2d9a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2d77(%rip),%rax
or     (%rax),%edx
mov    %r12d,%edi
mov    0x10(%rsp),%rsi
call   10d0 <inotify_add_watch@plt>
mov    %eax,(%rbx)
cmp    $0xffffffff,%eax
je     13be <inotify+0x1ce>
mov    %rbx,0x18(%rsp)
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2d4c(%rip),%r13
mov    0x0(%r13),%eax
mov    %eax,0x24(%rsp)
mov    %r12d,0x2c(%rsp)
mov    %eax,0x30(%rsp)
lea    0xd97(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rbx
mov    0x2cfb(%rip),%r14
mov    0x2ce4(%rip),%r15
jmp    12dc <inotify+0xec>
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%rax
cmp    (%r15),%rax
jne    13e6 <inotify+0x1f6>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   10e0 <poll@plt>
cmp    $0xffffffff,%eax
je     12d0 <inotify+0xe0>
test   %eax,%eax
jle    12dc <inotify+0xec>
mov    0x0(%r13),%eax
test   %eax,0x28(%rsp)
jne    1347 <inotify+0x157>
test   %eax,0x34(%rsp)
je     12dc <inotify+0xec>
xor    %eax,%eax
call   1100 <getsockfd@plt>
test   %eax,%eax
js     138e <inotify+0x19e>
mov    %eax,%ebp
mov    %eax,%edi
call   1090 <sendConnect@plt>
test   %rax,%rax
jne    138e <inotify+0x19e>
mov    %ebp,%edi
mov    %r12d,%esi
mov    0x18(%rsp),%rdx
mov    $0x1,%ecx
mov    0x10(%rsp),%r8
call   10c0 <handle_events@plt>
test   %rax,%rax
js     138e <inotify+0x19e>
mov    %ebp,%edi
call   1080 <releasesockfd@plt>
jmp    12dc <inotify+0xec>
lea    0xf(%rsp),%rbx
mov    0x2c4d(%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    137c <inotify+0x18c>
cmpb   $0xa,0xf(%rsp)
jne    1360 <inotify+0x170>
mov    %r12d,%edi
call   1060 <close@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc57(%rip),%rdi
call   10f0 <perror@plt>
jmp    138e <inotify+0x19e>
lea    0xc57(%rip),%rdi
call   10f0 <perror@plt>
jmp    138e <inotify+0x19e>
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
lea    0xc4b(%rip),%rsi
mov    0x10(%rsp),%rdx
call   10b0 <fprintf@plt>
lea    0xc4d(%rip),%rdi
call   10f0 <perror@plt>
jmp    138e <inotify+0x19e>
lea    0xc51(%rip),%rdi
call   10f0 <perror@plt>
jmp    138e <inotify+0x19e>

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

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