#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 */
typedef scalar_t__ time_t;
struct stat {
  scalar_t__ st_size;
  scalar_t__ st_dev;
  scalar_t__ st_ino;
  int /*<<< orphan*/ member_0;
};
struct pollfd {
  scalar_t__ st_size;
  scalar_t__ st_dev;
  scalar_t__ st_ino;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ stats;
typedef scalar_t__ off_t;
typedef int /*<<< orphan*/ dummy;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fstat(int, struct stat *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int open(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int poll(struct stat *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printstat(int /*<<< orphan*/ *, struct stat *);
int stat(char const *, struct stat *);
scalar_t__ statchanged(struct stat *, struct stat *);
int ndn_filewatch(const char *path, FILE *out, off_t minsize, off_t maxsize,
                  time_t maxsec, int msecstable, int msecpoll) {
  int fd = -1;
  int res = 0;
  unsigned i = 0;
  const unsigned int nbuf = 4;
  struct stat stats[4];
  struct stat *curr = NULL;
  struct stat *prev = NULL;
  struct stat statname = {0};
  struct pollfd dummy[1];
  time_t elapsed = 0;
  unsigned elapsedms = 0;
  unsigned stablems = 0;
  memset(stats, 0, sizeof(stats));
  memset(dummy, 0, sizeof(dummy));
  errno = EINVAL;
  if (msecpoll < 1)
    return (-1);
  if (msecstable < 1)
    return (-1);
  fd = open(path, O_RDONLY, 0);
  if (fd < 0)
    return (-1);
  for (i = 0;;) {
    curr = &(stats[i % nbuf]);
    res = fstat(fd, curr);
    if (res == -1)
      break;
    if (prev == NULL || statchanged(prev, curr)) {
      printstat(out, curr);
      prev = curr;
      stablems = 0;
      if (maxsize != 0 && curr->st_size > maxsize) {
        res = -2;
        break;
      }
      i++;
    } else {
      stablems += msecpoll;
      if (stablems >= msecstable && curr->st_size >= minsize) {
        res = 0;
        break;
      }
    }
    res = poll(dummy, 0, msecpoll);
    if (res != 0)
      abort();
    elapsedms += msecpoll;
    if (elapsed + elapsedms / 1000 > maxsec) {
      res = -3;
      break;
    }
    if (elapsedms >= 3000) {
      elapsed += elapsedms / 1000;
      elapsedms %= 1000;
      res = stat(path, &statname);
      if (res < 0 || statname.st_dev != curr->st_dev ||
          statname.st_ino != curr->st_ino) {
        res = -4;
        break;
      }
      fflush(out);
    }
  }
  close(fd);
  fflush(out);
  return (res);
}


x86 assembly (clang, -O0):
<ndn_filewatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
movl   $0xffffffff,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x4,-0x44(%rbp)
movq   $0x0,-0xd8(%rbp)
movq   $0x0,-0xe0(%rbp)
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
movq   $0x0,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
movl   $0x0,-0x130(%rbp)
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%ecx
mov    0x2d78(%rip),%rax
mov    %ecx,(%rax)
cmpl   $0x1,0x10(%rbp)
jge    1278 <ndn_filewatch+0xd8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1508 <ndn_filewatch+0x368>
cmpl   $0x1,-0x34(%rbp)
jge    128e <ndn_filewatch+0xee>
movl   $0xffffffff,-0x4(%rbp)
jmp    1508 <ndn_filewatch+0x368>
mov    -0x10(%rbp),%rdi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    12bb <ndn_filewatch+0x11b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1508 <ndn_filewatch+0x368>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
and    $0x3,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    -0xd0(%rbp),%rax
shl    $0x5,%rcx
add    %rcx,%rax
mov    %rax,-0xd8(%rbp)
mov    -0x38(%rbp),%edi
mov    -0xd8(%rbp),%rsi
call   10c0 <fstat@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1302 <ndn_filewatch+0x162>
jmp    14f1 <ndn_filewatch+0x351>
cmpq   $0x0,-0xe0(%rbp)
je     132d <ndn_filewatch+0x18d>
mov    -0xe0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
call   1070 <statchanged@plt>
cmp    $0x0,%rax
je     138e <ndn_filewatch+0x1ee>
mov    -0x18(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
call   1040 <printstat@plt>
mov    -0xd8(%rbp),%rax
mov    %rax,-0xe0(%rbp)
movl   $0x0,-0x130(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1380 <ndn_filewatch+0x1e0>
mov    -0xd8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
jle    1380 <ndn_filewatch+0x1e0>
movl   $0xfffffffe,-0x3c(%rbp)
jmp    14f1 <ndn_filewatch+0x351>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    13d1 <ndn_filewatch+0x231>
mov    0x10(%rbp),%eax
add    -0x130(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    -0x130(%rbp),%eax
cmp    -0x34(%rbp),%eax
jb     13cc <ndn_filewatch+0x22c>
mov    -0xd8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
jl     13cc <ndn_filewatch+0x22c>
movl   $0x0,-0x3c(%rbp)
jmp    14f1 <ndn_filewatch+0x351>
jmp    13d1 <ndn_filewatch+0x231>
lea    -0x120(%rbp),%rdi
mov    0x10(%rbp),%edx
xor    %esi,%esi
call   10a0 <poll@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     13f6 <ndn_filewatch+0x256>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x10(%rbp),%eax
add    -0x12c(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x12c(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x138(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
cmp    -0x30(%rbp),%rax
jle    1446 <ndn_filewatch+0x2a6>
movl   $0xfffffffd,-0x3c(%rbp)
jmp    14f1 <ndn_filewatch+0x351>
cmpl   $0xbb8,-0x12c(%rbp)
jb     14ec <ndn_filewatch+0x34c>
mov    -0x12c(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%eax
add    -0x128(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x12c(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x12c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1080 <stat@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     14d7 <ndn_filewatch+0x337>
mov    -0xf8(%rbp),%rax
mov    -0xd8(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    14d7 <ndn_filewatch+0x337>
mov    -0xf0(%rbp),%rax
mov    -0xd8(%rbp),%rcx
cmp    0x10(%rcx),%rax
je     14e3 <ndn_filewatch+0x343>
movl   $0xfffffffc,-0x3c(%rbp)
jmp    14f1 <ndn_filewatch+0x351>
mov    -0x18(%rbp),%rdi
call   1090 <fflush@plt>
jmp    12c2 <ndn_filewatch+0x122>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rdi
call   1090 <fflush@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndn_filewatch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %r9d,%ebx
mov    %r8,0x40(%rsp)
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbp
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
lea    0x90(%rsp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0x70(%rsp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    0x2dcf(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%r14d
test   %ebx,%ebx
jle    141c <ndn_filewatch+0x27c>
cmpl   $0x0,0x150(%rsp)
jle    141c <ndn_filewatch+0x27c>
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %edx,%edx
call   10b0 <open@plt>
test   %eax,%eax
js     141c <ndn_filewatch+0x27c>
lea    0x90(%rsp),%r14
mov    %eax,0x8(%rsp)
mov    %eax,%edi
mov    %r14,%rsi
call   10c0 <fstat@plt>
cmp    $0xffffffff,%eax
je     13f3 <ndn_filewatch+0x253>
mov    %rbp,0x30(%rsp)
mov    %r12,0x28(%rsp)
mov    %r15,0x38(%rsp)
mov    %ebx,0x1c(%rsp)
xor    %r12d,%r12d
movl   $0x0,0xc(%rsp)
xor    %r13d,%r13d
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xor    %ebp,%ebp
xor    %r15d,%r15d
mov    0x150(%rsp),%ebx
jmp    12da <ndn_filewatch+0x13a>
nopw   0x0(%rax,%rax,1)
mov    %r15d,%r12d
and    $0x3,%r12d
mov    %r12,%rax
shl    $0x5,%rax
lea    (%rsp,%rax,1),%r14
add    $0x90,%r14
mov    0x8(%rsp),%edi
mov    %r14,%rsi
call   10c0 <fstat@plt>
cmp    $0xffffffff,%eax
mov    0x150(%rsp),%ebx
mov    0x48(%rsp),%rbp
je     13f3 <ndn_filewatch+0x253>
test   %rbp,%rbp
je     12f3 <ndn_filewatch+0x153>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <statchanged@plt>
test   %rax,%rax
je     13d0 <ndn_filewatch+0x230>
mov    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1040 <printstat@plt>
mov    0x38(%rsp),%rax
test   %rax,%rax
je     1313 <ndn_filewatch+0x173>
cmp    %rax,(%r14)
jg     1403 <ndn_filewatch+0x263>
add    $0x1,%r15d
xor    %ecx,%ecx
mov    %r14,%rbp
mov    %rbp,0x48(%rsp)
mov    %ecx,0xc(%rsp)
lea    0x70(%rsp),%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   10a0 <poll@plt>
test   %eax,%eax
jne    1431 <ndn_filewatch+0x291>
add    %ebx,%r13d
imul   $0x10624dd3,%r13,%rbp
shr    $0x26,%rbp
mov    0x20(%rsp),%rax
lea    (%rax,%rbp,1),%rbx
cmp    0x40(%rsp),%rbx
jg     13fb <ndn_filewatch+0x25b>
cmp    $0xbb8,%r13d
jb     12a0 <ndn_filewatch+0x100>
mov    0x30(%rsp),%rdi
lea    0x50(%rsp),%rsi
call   1080 <stat@plt>
mov    $0xfffffffc,%r14d
test   %eax,%eax
js     1409 <ndn_filewatch+0x269>
mov    0x58(%rsp),%rax
shl    $0x5,%r12
cmp    0x98(%rsp,%r12,1),%rax
jne    1409 <ndn_filewatch+0x269>
mov    0x60(%rsp),%rax
cmp    0xa0(%rsp,%r12,1),%rax
jne    1409 <ndn_filewatch+0x269>
imul   $0x3e8,%ebp,%eax
sub    %eax,%r13d
mov    0x10(%rsp),%rdi
call   1090 <fflush@plt>
mov    %rbx,0x20(%rsp)
jmp    12a0 <ndn_filewatch+0x100>
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%ecx
add    %ebx,%ecx
cmp    0x1c(%rsp),%ecx
jb     131c <ndn_filewatch+0x17c>
mov    0x28(%rsp),%rax
cmp    %rax,(%r14)
jl     131c <ndn_filewatch+0x17c>
xor    %r14d,%r14d
jmp    1409 <ndn_filewatch+0x269>
mov    $0xffffffff,%r14d
jmp    1409 <ndn_filewatch+0x269>
mov    $0xfffffffd,%r14d
jmp    1409 <ndn_filewatch+0x269>
mov    $0xfffffffe,%r14d
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0x10(%rsp),%rdi
call   1090 <fflush@plt>
mov    %r14d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i64, i64, i32 }
%struct.pollfd = type { i64, i64, i64, i32 }
@EINVAL = global i32 0
@errno = global i32 0
@O_RDONLY = global i32 0
define i32 @ndn_filewatch(i8* %0, i32* %1, i64 %2, i64 %3, i64 %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca [4 x %struct.stat]
%21 = alloca %struct.stat*
%22 = alloca %struct.stat*
%23 = alloca %struct.stat
%24 = alloca [1 x %struct.pollfd]
%25 = alloca i64
%26 = alloca i32
%27 = alloca i32
store i8* %0, i8** %9
store i32* %1, i32** %10
store i64 %2, i64* %11
store i64 %3, i64* %12
store i64 %4, i64* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 -1, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i32 4, i32* %19
store %struct.stat* null, %struct.stat** %21
store %struct.stat* null, %struct.stat** %22
%28 = bitcast %struct.stat* %23 to i8*
store i64 0, i64* %25
store i32 0, i32* %26
store i32 0, i32* %27
%29 = getelementptr inbounds [4 x %struct.stat], [4 x %struct.stat]* %20, i64 0, i64 0
%30 = call i32 @memset(%struct.stat* %29, i32 0, i32 128)
%31 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %24, i64 0, i64 0
%32 = bitcast %struct.pollfd* %31 to %struct.stat*
%33 = call i32 @memset(%struct.stat* %32, i32 0, i32 32)
%34 = load i32, i32* @EINVAL
store i32 %34, i32* @errno
%35 = load i32, i32* %15
%36 = icmp slt i32 %35, 1
br i1 %36, label %37, label %38
37: ; preds = %7
store i32 -1, i32* %8
br label %162
38: ; preds = %7
%39 = load i32, i32* %14
%40 = icmp slt i32 %39, 1
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 -1, i32* %8
br label %162
42: ; preds = %38
%43 = load i8*, i8** %9
%44 = load i32, i32* @O_RDONLY
%45 = call i32 @open(i8* %43, i32 %44, i32 0)
store i32 %45, i32* %16
%46 = load i32, i32* %16
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
store i32 -1, i32* %8
br label %162
49: ; preds = %42
store i32 0, i32* %18
br label %50
50: ; preds = %155, %49
%51 = load i32, i32* %18
%52 = urem i32 %51, 4
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds [4 x %struct.stat], [4 x %struct.stat]* %20, i64 0, i64 %53
store %struct.stat* %54, %struct.stat** %21
%55 = load i32, i32* %16
%56 = load %struct.stat*, %struct.stat** %21
%57 = call i32 @fstat(i32 %55, %struct.stat* %56)
store i32 %57, i32* %17
%58 = load i32, i32* %17
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %61
60: ; preds = %50
br label %156
61: ; preds = %50
%62 = load %struct.stat*, %struct.stat** %22
%63 = icmp eq %struct.stat* %62, null
br i1 %63, label %69, label %64
64: ; preds = %61
%65 = load %struct.stat*, %struct.stat** %22
%66 = load %struct.stat*, %struct.stat** %21
%67 = call i64 @statchanged(%struct.stat* %65, %struct.stat* %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %86
69: ; preds = %64, %61
%70 = load i32*, i32** %10
%71 = load %struct.stat*, %struct.stat** %21
%72 = call i32 @printstat(i32* %70, %struct.stat* %71)
%73 = load %struct.stat*, %struct.stat** %21
store %struct.stat* %73, %struct.stat** %22
store i32 0, i32* %27
%74 = load i64, i64* %12
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %83
76: ; preds = %69
%77 = load %struct.stat*, %struct.stat** %21
%78 = getelementptr inbounds %struct.stat, %struct.stat* %77, i32 0, i32 0
%79 = load i64, i64* %78
%80 = load i64, i64* %12
%81 = icmp sgt i64 %79, %80
br i1 %81, label %82, label %83
82: ; preds = %76
store i32 -2, i32* %17
br label %156
83: ; preds = %76, %69
%84 = load i32, i32* %18
%85 = add i32 %84, 1
store i32 %85, i32* %18
br label %101
86: ; preds = %64
%87 = load i32, i32* %15
%88 = load i32, i32* %27
%89 = add i32 %88, %87
store i32 %89, i32* %27
%90 = load i32, i32* %27
%91 = load i32, i32* %14
%92 = icmp uge i32 %90, %91
br i1 %92, label %93, label %100
93: ; preds = %86
%94 = load %struct.stat*, %struct.stat** %21
%95 = getelementptr inbounds %struct.stat, %struct.stat* %94, i32 0, i32 0
%96 = load i64, i64* %95
%97 = load i64, i64* %11
%98 = icmp sge i64 %96, %97
br i1 %98, label %99, label %100
99: ; preds = %93
store i32 0, i32* %17
br label %156
100: ; preds = %93, %86
br label %101
101: ; preds = %100, %83
%102 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %24, i64 0, i64 0
%103 = bitcast %struct.pollfd* %102 to %struct.stat*
%104 = load i32, i32* %15
%105 = call i32 @poll(%struct.stat* %103, i32 0, i32 %104)
store i32 %105, i32* %17
%106 = load i32, i32* %17
%107 = icmp ne i32 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %101
%109 = call i32 (...) @abort()
unreachable
110: ; preds = %101
%111 = load i32, i32* %15
%112 = load i32, i32* %26
%113 = add i32 %112, %111
store i32 %113, i32* %26
%114 = load i64, i64* %25
%115 = load i32, i32* %26
%116 = udiv i32 %115, 1000
%117 = zext i32 %116 to i64
%118 = add nsw i64 %114, %117
%119 = load i64, i64* %13
%120 = icmp sgt i64 %118, %119
br i1 %120, label %121, label %122
121: ; preds = %110
store i32 -3, i32* %17
br label %156
122: ; preds = %110
%123 = load i32, i32* %26
%124 = icmp uge i32 %123, 3000
br i1 %124, label %125, label %155
125: ; preds = %122
%126 = load i32, i32* %26
%127 = udiv i32 %126, 1000
%128 = zext i32 %127 to i64
%129 = load i64, i64* %25
%130 = add nsw i64 %129, %128
store i64 %130, i64* %25
%131 = load i32, i32* %26
%132 = urem i32 %131, 1000
store i32 %132, i32* %26
%133 = load i8*, i8** %9
%134 = call i32 @stat(i8* %133, %struct.stat* %23)
store i32 %134, i32* %17
%135 = load i32, i32* %17
%136 = icmp slt i32 %135, 0
br i1 %136, label %151, label %137
137: ; preds = %125
%138 = getelementptr inbounds %struct.stat, %struct.stat* %23, i32 0, i32 1
%139 = load i64, i64* %138
%140 = load %struct.stat*, %struct.stat** %21
%141 = getelementptr inbounds %struct.stat, %struct.stat* %140, i32 0, i32 1
%142 = load i64, i64* %141
%143 = icmp ne i64 %139, %142
br i1 %143, label %151, label %144
144: ; preds = %137
%145 = getelementptr inbounds %struct.stat, %struct.stat* %23, i32 0, i32 2
%146 = load i64, i64* %145
%147 = load %struct.stat*, %struct.stat** %21
%148 = getelementptr inbounds %struct.stat, %struct.stat* %147, i32 0, i32 2
%149 = load i64, i64* %148
%150 = icmp ne i64 %146, %149
br i1 %150, label %151, label %152
151: ; preds = %144, %137, %125
store i32 -4, i32* %17
br label %156
152: ; preds = %144
%153 = load i32*, i32** %10
%154 = call i32 @fflush(i32* %153)
br label %155
155: ; preds = %152, %122
br label %50
156: ; preds = %151, %121, %99, %82, %60
%157 = load i32, i32* %16
%158 = call i32 @close(i32 %157)
%159 = load i32*, i32** %10
%160 = call i32 @fflush(i32* %159)
%161 = load i32, i32* %17
store i32 %161, i32* %8
br label %162
162: ; preds = %156, %48, %41, %37
%163 = load i32, i32* %8
ret i32 %163
}

LLVM IR (-O2):
%struct.stat = type { i64, i64, i64, i32 }
%struct.pollfd = type { i64, i64, i64, i32 }
@EINVAL = global i32 0
@errno = global i32 0
@O_RDONLY = global i32 0
define i32 @ndn_filewatch(i8* nocapture %0, i32* %1, i64 %2, i64 %3, i64 %4, i32 %5, i32 %6) {
%8 = alloca [4 x %struct.stat]
%9 = alloca %struct.stat
%10 = alloca [1 x %struct.pollfd]
%11 = bitcast [4 x %struct.stat]* %8 to i8*
%12 = bitcast %struct.stat* %9 to i8*
%13 = bitcast [1 x %struct.pollfd]* %10 to i8*
%14 = getelementptr inbounds [4 x %struct.stat], [4 x %struct.stat]* %8, i64 0, i64 0
%15 = call i32 @memset(%struct.stat* %14, i32 0, i32 128)
%16 = bitcast [1 x %struct.pollfd]* %10 to %struct.stat*
%17 = call i32 @memset(%struct.stat* %16, i32 0, i32 32)
%18 = load i32, i32* @EINVAL
store i32 %18, i32* @errno
%19 = icmp slt i32 %6, 1
%20 = icmp slt i32 %5, 1
%21 = or i1 %20, %19
br i1 %21, label %104, label %22
22: ; preds = %7
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %0, i32 %23, i32 0)
%25 = icmp slt i32 %24, 0
br i1 %25, label %104, label %26
26: ; preds = %22
%27 = call i32 @fstat(i32 %24, %struct.stat* %14)
%28 = icmp eq i32 %27, -1
br i1 %28, label %100, label %29
29: ; preds = %26
%30 = icmp eq i64 %3, 0
%31 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 1
%32 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 2
br label %33
33: ; preds = %29, %92
%34 = phi %struct.stat* [ %14, %29 ], [ %97, %92 ]
%35 = phi i64 [ 0, %29 ], [ %96, %92 ]
%36 = phi i32 [ 0, %29 ], [ %63, %92 ]
%37 = phi i32 [ 0, %29 ], [ %94, %92 ]
%38 = phi i64 [ 0, %29 ], [ %93, %92 ]
%39 = phi %struct.stat* [ null, %29 ], [ %62, %92 ]
%40 = phi i32 [ 0, %29 ], [ %61, %92 ]
%41 = icmp eq %struct.stat* %39, null
br i1 %41, label %45, label %42
42: ; preds = %33
%43 = call i64 @statchanged(%struct.stat* %39, %struct.stat* %34)
%44 = icmp eq i64 %43, 0
br i1 %44, label %53, label %45
45: ; preds = %42, %33
%46 = call i32 @printstat(i32* %1, %struct.stat* %34)
br i1 %30, label %51, label %47
47: ; preds = %45
%48 = getelementptr inbounds %struct.stat, %struct.stat* %34, i64 0, i32 0
%49 = load i64, i64* %48
%50 = icmp sgt i64 %49, %3
br i1 %50, label %100, label %51
51: ; preds = %47, %45
%52 = add i32 %40, 1
br label %60
53: ; preds = %42
%54 = add i32 %36, %6
%55 = icmp ult i32 %54, %5
br i1 %55, label %60, label %56
56: ; preds = %53
%57 = getelementptr inbounds %struct.stat, %struct.stat* %34, i64 0, i32 0
%58 = load i64, i64* %57
%59 = icmp slt i64 %58, %2
br i1 %59, label %60, label %100
60: ; preds = %53, %56, %51
%61 = phi i32 [ %52, %51 ], [ %40, %56 ], [ %40, %53 ]
%62 = phi %struct.stat* [ %34, %51 ], [ %39, %56 ], [ %39, %53 ]
%63 = phi i32 [ 0, %51 ], [ %54, %56 ], [ %54, %53 ]
%64 = call i32 @poll(%struct.stat* %16, i32 0, i32 %6)
%65 = icmp eq i32 %64, 0
br i1 %65, label %68, label %66
66: ; preds = %60
%67 = call i32 (...) @abort()
unreachable
68: ; preds = %60
%69 = add i32 %37, %6
%70 = udiv i32 %69, 1000
%71 = urem i32 %69, 1000
%72 = zext i32 %70 to i64
%73 = add nsw i64 %38, %72
%74 = icmp sgt i64 %73, %4
br i1 %74, label %100, label %75
75: ; preds = %68
%76 = icmp ugt i32 %69, 2999
br i1 %76, label %77, label %92
77: ; preds = %75
%78 = call i32 @stat(i8* %0, %struct.stat* %9)
%79 = icmp slt i32 %78, 0
br i1 %79, label %100, label %80
80: ; preds = %77
%81 = load i64, i64* %31
%82 = getelementptr inbounds [4 x %struct.stat], [4 x %struct.stat]* %8, i64 0, i64 %35, i32 1
%83 = load i64, i64* %82
%84 = icmp eq i64 %81, %83
br i1 %84, label %85, label %100
85: ; preds = %80
%86 = load i64, i64* %32
%87 = getelementptr inbounds [4 x %struct.stat], [4 x %struct.stat]* %8, i64 0, i64 %35, i32 2
%88 = load i64, i64* %87
%89 = icmp eq i64 %86, %88
br i1 %89, label %90, label %100
90: ; preds = %85
%91 = call i32 @fflush(i32* %1)
br label %92
92: ; preds = %90, %75
%93 = phi i64 [ %73, %90 ], [ %38, %75 ]
%94 = phi i32 [ %71, %90 ], [ %69, %75 ]
%95 = and i32 %61, 3
%96 = zext i32 %95 to i64
%97 = getelementptr inbounds [4 x %struct.stat], [4 x %struct.stat]* %8, i64 0, i64 %96
%98 = call i32 @fstat(i32 %24, %struct.stat* %97)
%99 = icmp eq i32 %98, -1
br i1 %99, label %100, label %33
100: ; preds = %92, %47, %56, %68, %85, %80, %77, %26
%101 = phi i32 [ -1, %26 ], [ -4, %77 ], [ -4, %80 ], [ -4, %85 ], [ -3, %68 ], [ 0, %56 ], [ -2, %47 ], [ -1, %92 ]
%102 = call i32 @close(i32 %24)
%103 = call i32 @fflush(i32* %1)
br label %104
104: ; preds = %22, %7, %100
%105 = phi i32 [ %101, %100 ], [ -1, %7 ], [ -1, %22 ]
ret i32 %105
}