#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 inotify_event {
  int wd;
  int mask;
};
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
scalar_t__ EINTR;
int IN_CLOSE_WRITE;
int IN_CREATE;
int IN_IGNORED;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int inotify_add_watch(int, char *, int);
int inotify_init();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, struct inotify_event *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/ *,
                           int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(
        stderr,
        "iwatch v0.6 - execute a command as soon as a watched file changes.\n");
    fprintf(stderr, "Usage: %s file... command\n", argv[0]);
    return -1;
  }
  char *command = argv[argc - 1];
  char **files = argv + 1;
  size_t file_count = argc - 2;
  int watch_ids[file_count];
  int event_queue = inotify_init();
  if (event_queue == -1) {
    perror("inotify_init");
    return -1;
  }
  for (size_t i = 0; i < file_count; i++) {
    int watch_id =
        inotify_add_watch(event_queue, files[i], IN_CREATE | IN_CLOSE_WRITE);
    watch_ids[i] = watch_id;
    if (watch_id == -1)
      fprintf(stderr, "Can't watch %s: %s\n", files[i], strerror(errno));
  }
  printf("Watching for changes, use ctrl + c to exit.\n");
  char buffer[4096];
  struct inotify_event *event = (void *)buffer;
  while (true) {
    int bytes_read = 0;
    do {
      bytes_read = read(event_queue, event, sizeof(buffer));
    } while (bytes_read == -1 && errno == EINTR);
    if (bytes_read == -1) {
      perror("Read of event structure failed");
      break;
    }
    size_t i;
    for (i = 0; i < file_count; i++) {
      if (watch_ids[i] == event->wd)
        break;
    }
    char *file = (i < file_count) ? files[i] : "unknown file";
    if (event->mask & IN_IGNORED) {
      printf("File %s deleted or filesystem unmounted. Exiting.\n", file);
      break;
    } else if (event->mask & IN_CREATE) {
      printf("File created in %s, executing: %s\n", file, command);
    } else if (event->mask & IN_CLOSE_WRITE) {
      printf("File %s written to, executing: %s\n", file, command);
    }
    if (event->mask & IN_CREATE || event->mask & IN_CLOSE_WRITE) {
      pid_t child = fork();
      if (child == 0) {
        execl("/bin/bash", "/bin/bash", "-c", command, NULL);
      } else {
        waitpid(child, NULL, 0);
      }
    }
  }
  close(event_queue);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1214 <main+0x64>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    160d <main+0x45d>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0xfffffffe,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1080(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1070 <inotify_init@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    129f <main+0xef>
lea    0xdd8(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    1606 <main+0x456>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1360 <main+0x1b0>
mov    -0x3c(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    0x2cf5(%rip),%rax
mov    (%rax),%edx
mov    0x2d0c(%rip),%rax
or     (%rax),%edx
call   1080 <inotify_add_watch@plt>
mov    %eax,%ecx
mov    -0x1080(%rbp),%rax
mov    %ecx,-0x4c(%rbp)
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    134a <main+0x19a>
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x108c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x1088(%rbp)
mov    0x2ca4(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x108c(%rbp),%edi
mov    -0x1088(%rbp),%rdx
mov    %rax,%rcx
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    134f <main+0x19f>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    12a7 <main+0xf7>
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1050(%rbp),%rax
mov    %rax,-0x1058(%rbp)
jmp    1381 <main+0x1d1>
movl   $0x0,-0x105c(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x1058(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x105c(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x105c(%rbp)
mov    %al,-0x108d(%rbp)
jne    13d7 <main+0x227>
mov    0x2c07(%rip),%rax
mov    (%rax),%rax
mov    0x2bed(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x108d(%rbp)
mov    -0x108d(%rbp),%al
test   $0x1,%al
jne    138b <main+0x1db>
cmpl   $0xffffffff,-0x105c(%rbp)
jne    1403 <main+0x253>
lea    0xcb4(%rip),%rdi
call   10a0 <perror@plt>
jmp    15f0 <main+0x440>
movq   $0x0,-0x1068(%rbp)
mov    -0x1068(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1460 <main+0x2b0>
mov    -0x1080(%rbp),%rax
mov    -0x1068(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x1058(%rbp),%rcx
cmp    (%rcx),%eax
jne    1444 <main+0x294>
jmp    1460 <main+0x2b0>
jmp    1449 <main+0x299>
mov    -0x1068(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1068(%rbp)
jmp    140e <main+0x25e>
mov    -0x1068(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    148c <main+0x2dc>
mov    -0x20(%rbp),%rax
mov    -0x1068(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x1098(%rbp)
jmp    149f <main+0x2ef>
lea    0xc39(%rip),%rax
mov    %rax,-0x1098(%rbp)
jmp    149f <main+0x2ef>
mov    -0x1098(%rbp),%rax
mov    %rax,-0x1070(%rbp)
mov    -0x1058(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2b3a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14e3 <main+0x333>
mov    -0x1070(%rbp),%rsi
lea    0xc02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    15f0 <main+0x440>
mov    -0x1058(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2acc(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     151d <main+0x36d>
mov    -0x1070(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xbfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1557 <main+0x3a7>
mov    -0x1058(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2ab2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1552 <main+0x3a2>
mov    -0x1070(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xbe4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1557 <main+0x3a7>
jmp    155c <main+0x3ac>
mov    -0x1058(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2a53(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1594 <main+0x3e4>
mov    -0x1058(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2a57(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     15eb <main+0x43b>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x1078(%rbp)
cmpq   $0x0,-0x1078(%rbp)
jne    15d4 <main+0x424>
mov    -0x18(%rbp),%rcx
lea    0xb97(%rip),%rsi
lea    0xb9a(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   10c0 <execl@plt>
jmp    15e6 <main+0x436>
mov    -0x1078(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <waitpid@plt>
jmp    15eb <main+0x43b>
jmp    137c <main+0x1cc>
mov    -0x3c(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rsi,%r13
cmp    $0x2,%edi
jg     1211 <main+0x51>
mov    0x2ded(%rip),%rbx
mov    (%rbx),%edi
lea    0xe14(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
mov    0x0(%r13),%rdx
lea    0xe44(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1414 <main+0x254>
mov    %edi,%r12d
mov    %rsp,%rbx
lea    -0x1(%r12),%eax
mov    0x0(%r13,%rax,8),%rax
mov    %rax,-0x40(%rbp)
add    $0xfffffffe,%r12d
mov    %rsp,%r14
lea    0xf(,%r12,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
xor    %eax,%eax
call   1080 <inotify_init@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     1423 <main+0x263>
mov    %rbx,-0x48(%rbp)
xor    %r15d,%r15d
mov    %r13,-0x38(%rbp)
jmp    1269 <main+0xa9>
xchg   %ax,%ax
add    $0x1,%r15
cmp    %r15,%r12
je     12d0 <main+0x110>
mov    0x8(%r13,%r15,8),%rsi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
mov    0x2d42(%rip),%rax
or     (%rax),%edx
mov    -0x2c(%rbp),%edi
call   1090 <inotify_add_watch@plt>
mov    %eax,(%r14,%r15,4)
cmp    $0xffffffff,%eax
jne    1260 <main+0xa0>
mov    0x2d38(%rip),%rax
mov    (%rax),%r13d
mov    -0x38(%rbp),%rax
mov    0x8(%rax,%r15,8),%rbx
mov    0x2d1d(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    %r13d,%edi
mov    -0x38(%rbp),%r13
lea    0xdab(%rip),%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1260 <main+0xa0>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
lea    -0x1050(%rbp),%r13
mov    0x2cce(%rip),%r15
jmp    12fc <main+0x13c>
nopl   0x0(%rax)
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    -0x2c(%rbp),%edi
mov    %r13,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    1320 <main+0x160>
mov    (%r15),%rcx
mov    0x2cad(%rip),%rdx
cmp    %rcx,(%rdx)
je     12fc <main+0x13c>
cmp    $0xffffffff,%eax
je     1436 <main+0x276>
mov    -0x1050(%rbp),%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %eax,(%r14,%rcx,4)
je     1360 <main+0x1a0>
add    $0x1,%rcx
cmp    %rcx,%r12
jne    1340 <main+0x180>
lea    0xd49(%rip),%rsi
jmp    1369 <main+0x1a9>
nopl   0x0(%rax,%rax,1)
mov    -0x38(%rbp),%rax
mov    0x8(%rax,%rcx,8),%rsi
mov    -0x104c(%rbp),%ebx
mov    0x2c82(%rip),%rax
test   %ebx,(%rax)
jne    13f5 <main+0x235>
lea    0xd5e(%rip),%rdi
mov    0x2c38(%rip),%rax
test   %ebx,(%rax)
jne    139e <main+0x1de>
lea    0xd6f(%rip),%rdi
mov    0x2c46(%rip),%rax
test   %ebx,(%rax)
je     13a9 <main+0x1e9>
mov    -0x40(%rbp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c10(%rip),%rax
test   %ebx,(%rax)
jne    13c3 <main+0x203>
mov    0x2c25(%rip),%rax
test   %ebx,(%rax)
je     12fc <main+0x13c>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
jne    12f0 <main+0x130>
lea    0xd4b(%rip),%rdi
mov    %rdi,%rsi
lea    0xd4b(%rip),%rdx
mov    -0x40(%rbp),%rcx
xor    %r8d,%r8d
call   10d0 <execl@plt>
jmp    12fc <main+0x13c>
lea    0xcb0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
mov    -0x48(%rbp),%rbx
mov    %rbx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc35(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1411 <main+0x251>
lea    0xc43(%rip),%rdi
call   10b0 <perror@plt>
jmp    1403 <main+0x243>

LLVM IR (-O0):
%struct.inotify_event = type { i32, i32 }
@stderr = global i32 0
@.str = [68 x i8] c"iwatch v0.6 - execute a command as soon as a watched file changes.\0A\00"
@.str.1 = [27 x i8] c"Usage: %s file... command\0A\00"
@.str.2 = [13 x i8] c"inotify_init\00"
@IN_CREATE = global i32 0
@IN_CLOSE_WRITE = global i32 0
@.str.3 = [20 x i8] c"Can't watch %s: %s\0A\00"
@errno = global i64 0
@.str.4 = [45 x i8] c"Watching for changes, use ctrl + c to exit.\0A\00"
@EINTR = global i64 0
@.str.5 = [31 x i8] c"Read of event structure failed\00"
@.str.6 = [13 x i8] c"unknown file\00"
@IN_IGNORED = global i32 0
@.str.7 = [51 x i8] c"File %s deleted or filesystem unmounted. Exiting.\0A\00"
@.str.8 = [35 x i8] c"File created in %s, executing: %s\0A\00"
@.str.9 = [35 x i8] c"File %s written to, executing: %s\0A\00"
@.str.10 = [10 x i8] c"/bin/bash\00"
@.str.11 = [3 x i8] c"-c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
%15 = alloca [4096 x i8]
%16 = alloca %struct.inotify_event*
%17 = alloca i32
%18 = alloca i64
%19 = alloca i8*
%20 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %31
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 -1, i32* %3
br label %202
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = load i32, i32* %4
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %32, i64 %35
%37 = load i8*, i8** %36
store i8* %37, i8** %6
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
store i8** %39, i8*** %7
%40 = load i32, i32* %4
%41 = sub nsw i32 %40, 2
%42 = sext i32 %41 to i64
store i64 %42, i64* %8
%43 = load i64, i64* %8
%44 = call i8* @llvm.stacksave()
store i8* %44, i8** %9
%45 = alloca i32, i64 %43
store i64 %43, i64* %10
%46 = call i32 (...) @inotify_init()
store i32 %46, i32* %11
%47 = load i32, i32* %11
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %31
%50 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %12
br label %200
51: ; preds = %31
store i64 0, i64* %13
br label %52
52: ; preds = %81, %51
%53 = load i64, i64* %13
%54 = load i64, i64* %8
%55 = icmp ult i64 %53, %54
br i1 %55, label %56, label %84
56: ; preds = %52
%57 = load i32, i32* %11
%58 = load i8**, i8*** %7
%59 = load i64, i64* %13
%60 = getelementptr inbounds i8*, i8** %58, i64 %59
%61 = load i8*, i8** %60
%62 = load i32, i32* @IN_CREATE
%63 = load i32, i32* @IN_CLOSE_WRITE
%64 = or i32 %62, %63
%65 = call i32 @inotify_add_watch(i32 %57, i8* %61, i32 %64)
store i32 %65, i32* %14
%66 = load i32, i32* %14
%67 = load i64, i64* %13
%68 = getelementptr inbounds i32, i32* %45, i64 %67
store i32 %66, i32* %68
%69 = load i32, i32* %14
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %80
71: ; preds = %56
%72 = load i32, i32* @stderr
%73 = load i8**, i8*** %7
%74 = load i64, i64* %13
%75 = getelementptr inbounds i8*, i8** %73, i64 %74
%76 = load i8*, i8** %75
%77 = load i64, i64* @errno
%78 = call i8* @strerror(i64 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %76, i8* %78)
br label %80
80: ; preds = %71, %56
br label %81
81: ; preds = %80
%82 = load i64, i64* %13
%83 = add i64 %82, 1
store i64 %83, i64* %13
br label %52
84: ; preds = %52
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%86 = getelementptr inbounds [4096 x i8], [4096 x i8]* %15, i64 0, i64 0
%87 = bitcast i8* %86 to %struct.inotify_event*
store %struct.inotify_event* %87, %struct.inotify_event** %16
br label %88
88: ; preds = %196, %84
br label %89
89: ; preds = %88
store i32 0, i32* %17
br label %90
90: ; preds = %101, %89
%91 = load i32, i32* %11
%92 = load %struct.inotify_event*, %struct.inotify_event** %16
%93 = call i32 @read(i32 %91, %struct.inotify_event* %92, i32 4096)
store i32 %93, i32* %17
br label %94
94: ; preds = %90
%95 = load i32, i32* %17
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %101
97: ; preds = %94
%98 = load i64, i64* @errno
%99 = load i64, i64* @EINTR
%100 = icmp eq i64 %98, %99
br label %101
101: ; preds = %97, %94
%102 = phi i1 [ false, %94 ], [ %100, %97 ]
br i1 %102, label %90, label %103
103: ; preds = %101
%104 = load i32, i32* %17
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %108
106: ; preds = %103
%107 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %197
108: ; preds = %103
store i64 0, i64* %18
br label %109
109: ; preds = %123, %108
%110 = load i64, i64* %18
%111 = load i64, i64* %8
%112 = icmp ult i64 %110, %111
br i1 %112, label %113, label %126
113: ; preds = %109
%114 = load i64, i64* %18
%115 = getelementptr inbounds i32, i32* %45, i64 %114
%116 = load i32, i32* %115
%117 = load %struct.inotify_event*, %struct.inotify_event** %16
%118 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %117, i32 0, i32 0
%119 = load i32, i32* %118
%120 = icmp eq i32 %116, %119
br i1 %120, label %121, label %122
121: ; preds = %113
br label %126
122: ; preds = %113
br label %123
123: ; preds = %122
%124 = load i64, i64* %18
%125 = add i64 %124, 1
store i64 %125, i64* %18
br label %109
126: ; preds = %121, %109
%127 = load i64, i64* %18
%128 = load i64, i64* %8
%129 = icmp ult i64 %127, %128
br i1 %129, label %130, label %135
130: ; preds = %126
%131 = load i8**, i8*** %7
%132 = load i64, i64* %18
%133 = getelementptr inbounds i8*, i8** %131, i64 %132
%134 = load i8*, i8** %133
br label %136
135: ; preds = %126
br label %136
136: ; preds = %135, %130
%137 = phi i8* [ %134, %130 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), %135 ]
store i8* %137, i8** %19
%138 = load %struct.inotify_event*, %struct.inotify_event** %16
%139 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %138, i32 0, i32 1
%140 = load i32, i32* %139
%141 = load i32, i32* @IN_IGNORED
%142 = and i32 %140, %141
%143 = icmp ne i32 %142, 0
br i1 %143, label %144, label %147
144: ; preds = %136
%145 = load i8*, i8** %19
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), i8* %145)
br label %197
147: ; preds = %136
%148 = load %struct.inotify_event*, %struct.inotify_event** %16
%149 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %148, i32 0, i32 1
%150 = load i32, i32* %149
%151 = load i32, i32* @IN_CREATE
%152 = and i32 %150, %151
%153 = icmp ne i32 %152, 0
br i1 %153, label %154, label %158
154: ; preds = %147
%155 = load i8*, i8** %19
%156 = load i8*, i8** %6
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %155, i8* %156)
br label %170
158: ; preds = %147
%159 = load %struct.inotify_event*, %struct.inotify_event** %16
%160 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %159, i32 0, i32 1
%161 = load i32, i32* %160
%162 = load i32, i32* @IN_CLOSE_WRITE
%163 = and i32 %161, %162
%164 = icmp ne i32 %163, 0
br i1 %164, label %165, label %169
165: ; preds = %158
%166 = load i8*, i8** %19
%167 = load i8*, i8** %6
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* %166, i8* %167)
br label %169
169: ; preds = %165, %158
br label %170
170: ; preds = %169, %154
br label %171
171: ; preds = %170
%172 = load %struct.inotify_event*, %struct.inotify_event** %16
%173 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %172, i32 0, i32 1
%174 = load i32, i32* %173
%175 = load i32, i32* @IN_CREATE
%176 = and i32 %174, %175
%177 = icmp ne i32 %176, 0
br i1 %177, label %185, label %178
178: ; preds = %171
%179 = load %struct.inotify_event*, %struct.inotify_event** %16
%180 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %179, i32 0, i32 1
%181 = load i32, i32* %180
%182 = load i32, i32* @IN_CLOSE_WRITE
%183 = and i32 %181, %182
%184 = icmp ne i32 %183, 0
br i1 %184, label %185, label %196
185: ; preds = %178, %171
%186 = call i64 (...) @fork()
store i64 %186, i64* %20
%187 = load i64, i64* %20
%188 = icmp eq i64 %187, 0
br i1 %188, label %189, label %192
189: ; preds = %185
%190 = load i8*, i8** %6
%191 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %190, i32* null)
br label %195
192: ; preds = %185
%193 = load i64, i64* %20
%194 = call i32 @waitpid(i64 %193, i32* null, i32 0)
br label %195
195: ; preds = %192, %189
br label %196
196: ; preds = %195, %178
br label %88
197: ; preds = %144, %106
%198 = load i32, i32* %11
%199 = call i32 @close(i32 %198)
store i32 0, i32* %3
store i32 1, i32* %12
br label %200
200: ; preds = %197, %49
%201 = load i8*, i8** %9
br label %202
202: ; preds = %200, %23
%203 = load i32, i32* %3
ret i32 %203
}

LLVM IR (-O2):
%struct.inotify_event = type { i32, i32 }
@stderr = global i32 0
@.str = [68 x i8] c"iwatch v0.6 - execute a command as soon as a watched file changes.\0A\00"
@.str.1 = [27 x i8] c"Usage: %s file... command\0A\00"
@.str.2 = [13 x i8] c"inotify_init\00"
@IN_CREATE = global i32 0
@IN_CLOSE_WRITE = global i32 0
@.str.3 = [20 x i8] c"Can't watch %s: %s\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.5 = [31 x i8] c"Read of event structure failed\00"
@.str.6 = [13 x i8] c"unknown file\00"
@IN_IGNORED = global i32 0
@.str.7 = [51 x i8] c"File %s deleted or filesystem unmounted. Exiting.\0A\00"
@.str.8 = [35 x i8] c"File created in %s, executing: %s\0A\00"
@.str.9 = [35 x i8] c"File %s written to, executing: %s\0A\00"
@.str.10 = [10 x i8] c"/bin/bash\00"
@.str.11 = [3 x i8] c"-c\00"
@str = [44 x i8] c"Watching for changes, use ctrl + c to exit.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %113
11: ; preds = %2
%12 = add nsw i32 %0, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = add nsw i32 %0, -2
%18 = zext i32 %17 to i64
%19 = tail call i8* @llvm.stacksave()
%20 = alloca i32, i64 %18
%21 = tail call i32 (...) @inotify_init()
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %32
23: ; preds = %11
%24 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %111
25: ; preds = %48
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%28 = bitcast [4096 x i8]* %3 to %struct.inotify_event*
%29 = bitcast [4096 x i8]* %3 to i32*
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 4
%31 = bitcast i8* %30 to i32*
br label %51
32: ; preds = %11, %48
%33 = phi i64 [ %49, %48 ], [ 0, %11 ]
%34 = getelementptr inbounds i8*, i8** %16, i64 %33
%35 = load i8*, i8** %34
%36 = load i32, i32* @IN_CREATE
%37 = load i32, i32* @IN_CLOSE_WRITE
%38 = or i32 %37, %36
%39 = tail call i32 @inotify_add_watch(i32 %21, i8* %35, i32 %38)
%40 = getelementptr inbounds i32, i32* %20, i64 %33
store i32 %39, i32* %40
%41 = icmp eq i32 %39, -1
br i1 %41, label %42, label %48
42: ; preds = %32
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %34
%45 = load i64, i64* @errno
%46 = tail call i8* @strerror(i64 %45)
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %44, i8* %46)
br label %48
48: ; preds = %42, %32
%49 = add nuw nsw i64 %33, 1
%50 = icmp eq i64 %49, %18
br i1 %50, label %25, label %32
51: ; preds = %58, %25
%52 = call i32 @read(i32 %21, %struct.inotify_event* %28, i32 4096)
%53 = icmp eq i32 %52, -1
%54 = load i64, i64* @errno
%55 = load i64, i64* @EINTR
%56 = icmp eq i64 %54, %55
%57 = select i1 %53, i1 %56, i1 false
br i1 %57, label %58, label %59
58: ; preds = %51, %105, %107, %98
br label %51
59: ; preds = %51
br i1 %53, label %62, label %60
60: ; preds = %59
%61 = load i32, i32* %29
br label %64
62: ; preds = %59
%63 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %109
64: ; preds = %60, %69
%65 = phi i64 [ 0, %60 ], [ %70, %69 ]
%66 = getelementptr inbounds i32, i32* %20, i64 %65
%67 = load i32, i32* %66
%68 = icmp eq i32 %67, %61
br i1 %68, label %72, label %69
69: ; preds = %64
%70 = add nuw nsw i64 %65, 1
%71 = icmp eq i64 %70, %18
br i1 %71, label %75, label %64
72: ; preds = %64
%73 = getelementptr inbounds i8*, i8** %16, i64 %65
%74 = load i8*, i8** %73
br label %75
75: ; preds = %69, %72
%76 = phi i8* [ %74, %72 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), %69 ]
%77 = load i32, i32* %31
%78 = load i32, i32* @IN_IGNORED
%79 = and i32 %78, %77
%80 = icmp eq i32 %79, 0
br i1 %80, label %83, label %81
81: ; preds = %75
%82 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0), i8* %76)
br label %109
83: ; preds = %75
%84 = load i32, i32* @IN_CREATE
%85 = and i32 %84, %77
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %83
%88 = load i32, i32* @IN_CLOSE_WRITE
%89 = and i32 %88, %77
%90 = icmp eq i32 %89, 0
br i1 %90, label %94, label %91
91: ; preds = %87, %83
%92 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), %83 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), %87 ]
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %92, i8* %76, i8* %15)
br label %94
94: ; preds = %91, %87
%95 = load i32, i32* @IN_CREATE
%96 = and i32 %95, %77
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %94
%99 = load i32, i32* @IN_CLOSE_WRITE
%100 = and i32 %99, %77
%101 = icmp eq i32 %100, 0
br i1 %101, label %58, label %102
102: ; preds = %98, %94
%103 = tail call i64 (...) @fork()
%104 = icmp eq i64 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %102
%106 = tail call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %15, i32* null)
br label %58
107: ; preds = %102
%108 = tail call i32 @waitpid(i64 %103, i32* null, i32 0)
br label %58
109: ; preds = %62, %81
%110 = tail call i32 @close(i32 %21)
br label %111
111: ; preds = %109, %23
%112 = phi i32 [ -1, %23 ], [ 0, %109 ]
tail call void @llvm.stackrestore(i8* %19)
br label %113
113: ; preds = %111, %5
%114 = phi i32 [ -1, %5 ], [ %112, %111 ]
ret i32 %114
}