#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 {
  scalar_t__ len;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ IN_ALL_EVENTS;
int NAME_MAX;
int /*<<< orphan*/ displayInotifyEvent(struct inotify_event *);
int /*<<< orphan*/ exit(int);
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init();
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ read(int, char *, int);
int main(int argc, char **argv) {
  int inotifyFD, wd, j;
  char buf[(10 * (sizeof(struct inotify_event) + NAME_MAX + 1))];
  ssize_t numRead;
  char *p;
  struct inotify_event *event;
  if (argc < 2) {
    printf("%s pathname . . .\n", argv[0]);
    exit(-1);
  }
  inotifyFD = inotify_init();
  if (inotifyFD == -1) {
    printf("%s inotify_init() failure\n", argv[0]);
    exit(-2);
  }
  for (j = 1; j < argc; j++) {
    wd = inotify_add_watch(inotifyFD, argv[j], IN_ALL_EVENTS);
    if (wd == -1) {
      printf("%s inotify_add_watch() failure\n", argv[0]);
      exit(-3);
    }
    printf("Watching %s using wd %d\n", argv[j], wd);
  }
  for (;;) {
    numRead = read(inotifyFD, buf,
                   (10 * (sizeof(struct inotify_event) + NAME_MAX + 1)));
    if (numRead <= 0) {
      printf("%s failed to read inotifyFD\n", argv[0]);
      exit(-4);
    }
    for (p = buf; p < buf + numRead;) {
      event = (struct inotify_event *)p;
      displayInotifyEvent(event);
      p += sizeof(struct inotify_event) + event->len;
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
movslq (%rax),%rcx
add    %rcx,%rcx
lea    0x5a(%rcx,%rcx,4),%rax
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
lea    0x69(%rcx,%rcx,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d2 <main+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1060 <inotify_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1205 <main+0xa5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    128c <main+0x12c>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
call   1070 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1261 <main+0x101>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xfffffffd,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x18(%rbp),%edx
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120c <main+0xac>
jmp    1291 <main+0x131>
mov    -0x50(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2d31(%rip),%rax
movslq (%rax),%rax
add    $0x8,%rax
add    $0x1,%rax
imul   $0xa,%rax,%rax
mov    %eax,%edx
call   1050 <read@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jg     12e3 <main+0x183>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xfffffffc,%edi
call   1080 <exit@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x40(%rbp),%rax
add    -0x38(%rbp),%rcx
cmp    %rcx,%rax
jae    1329 <main+0x1c9>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <displayInotifyEvent@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
add    $0x8,%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12eb <main+0x18b>
jmp    1291 <main+0x131>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    0x2e58(%rip),%rax
movslq (%rax),%rax
lea    (%rax,%rax,4),%rax
mov    %rsp,%r14
add    %rax,%rax
add    $0x69,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmp    $0x1,%edi
jg     11b4 <main+0x54>
mov    0x0(%r13),%rsi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    %edi,%ebx
xor    %eax,%eax
call   1060 <inotify_init@plt>
cmp    $0xffffffff,%eax
jne    11de <main+0x7e>
mov    0x0(%r13),%rsi
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
mov    %eax,%r15d
mov    %ebx,%ebx
mov    $0x1,%r12d
nopl   0x0(%rax)
mov    0x0(%r13,%r12,8),%rsi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
call   1070 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
je     12c8 <main+0x168>
mov    0x0(%r13,%r12,8),%rsi
lea    0xe33(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r12
cmp    %r12,%rbx
jne    11f0 <main+0x90>
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,1),%edx
add    $0x5a,%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   1050 <read@plt>
test   %rax,%rax
jle    12ac <main+0x14c>
mov    %rax,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %r14,%r12
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <displayInotifyEvent@plt>
mov    (%rbx),%rax
add    %rax,%rbx
add    $0x8,%rbx
cmp    %r12,%rbx
jb     1270 <main+0x110>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,1),%edx
add    $0x5a,%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   1050 <read@plt>
mov    %rax,%r12
test   %rax,%rax
jg     1260 <main+0x100>
mov    0x0(%r13),%rsi
lea    0xdb0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xfffffffc,%edi
call   1080 <exit@plt>
mov    0x0(%r13),%rsi
lea    0xd5b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xfffffffd,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.inotify_event = type { i64 }
@NAME_MAX = global i32 0
@.str = [19 x i8] c"%s pathname . . .\0A\00"
@.str.1 = [27 x i8] c"%s inotify_init() failure\0A\00"
@IN_ALL_EVENTS = global i32 0
@.str.2 = [32 x i8] c"%s inotify_add_watch() failure\0A\00"
@.str.3 = [25 x i8] c"Watching %s using wd %d\0A\00"
@.str.4 = [29 x i8] c"%s failed to read inotifyFD\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca %struct.inotify_event*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @NAME_MAX
%15 = sext i32 %14 to i64
%16 = add i64 8, %15
%17 = add i64 %16, 1
%18 = mul i64 10, %17
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %9
%20 = alloca i8, i64 %18
store i64 %18, i64* %10
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 2
br i1 %22, label %23, label %29
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %2
%30 = call i32 (...) @inotify_init()
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 -2)
unreachable
39: ; preds = %29
store i32 1, i32* %8
br label %40
40: ; preds = %69, %39
%41 = load i32, i32* %8
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %72
44: ; preds = %40
%45 = load i32, i32* %6
%46 = load i8**, i8*** %5
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = load i32, i32* @IN_ALL_EVENTS
%52 = call i32 @inotify_add_watch(i32 %45, i8* %50, i32 %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %61
55: ; preds = %44
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 -3)
unreachable
61: ; preds = %44
%62 = load i8**, i8*** %5
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %65
%67 = load i32, i32* %7
%68 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %66, i32 %67)
br label %69
69: ; preds = %61
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %40
72: ; preds = %40
br label %73
73: ; preds = %107, %72
%74 = load i32, i32* %6
%75 = load i32, i32* @NAME_MAX
%76 = sext i32 %75 to i64
%77 = add i64 8, %76
%78 = add i64 %77, 1
%79 = mul i64 10, %78
%80 = trunc i64 %79 to i32
%81 = call i64 @read(i32 %74, i8* %20, i32 %80)
store i64 %81, i64* %11
%82 = load i64, i64* %11
%83 = icmp sle i64 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %73
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 0
%87 = load i8*, i8** %86
%88 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %87)
%89 = call i32 @exit(i32 -4)
unreachable
90: ; preds = %73
store i8* %20, i8** %12
br label %91
91: ; preds = %96, %90
%92 = load i8*, i8** %12
%93 = load i64, i64* %11
%94 = getelementptr inbounds i8, i8* %20, i64 %93
%95 = icmp ult i8* %92, %94
br i1 %95, label %96, label %107
96: ; preds = %91
%97 = load i8*, i8** %12
%98 = bitcast i8* %97 to %struct.inotify_event*
store %struct.inotify_event* %98, %struct.inotify_event** %13
%99 = load %struct.inotify_event*, %struct.inotify_event** %13
%100 = call i32 @displayInotifyEvent(%struct.inotify_event* %99)
%101 = load %struct.inotify_event*, %struct.inotify_event** %13
%102 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %101, i32 0, i32 0
%103 = load i64, i64* %102
%104 = add i64 8, %103
%105 = load i8*, i8** %12
%106 = getelementptr inbounds i8, i8* %105, i64 %104
store i8* %106, i8** %12
br label %91
107: ; preds = %91
br label %73
}

LLVM IR (-O2):
%struct.inotify_event = type { i64 }
@NAME_MAX = global i32 0
@.str = [19 x i8] c"%s pathname . . .\0A\00"
@.str.1 = [27 x i8] c"%s inotify_init() failure\0A\00"
@IN_ALL_EVENTS = global i32 0
@.str.2 = [32 x i8] c"%s inotify_add_watch() failure\0A\00"
@.str.3 = [25 x i8] c"Watching %s using wd %d\0A\00"
@.str.4 = [29 x i8] c"%s failed to read inotifyFD\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @NAME_MAX
%4 = sext i32 %3 to i64
%5 = mul nsw i64 %4, 10
%6 = add nsw i64 %5, 90
%7 = alloca i8, i64 %6
%8 = icmp slt i32 %0, 2
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = tail call i32 (...) @inotify_init()
%15 = icmp eq i32 %14, -1
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = zext i32 %0 to i64
br label %28
18: ; preds = %13
%19 = load i8*, i8** %1
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 -2)
unreachable
22: ; preds = %39
%23 = load i32, i32* @NAME_MAX
%24 = mul i32 %23, 10
%25 = add i32 %24, 90
%26 = call i64 @read(i32 %14, i8* %7, i32 %25)
%27 = icmp slt i64 %26, 1
br i1 %27, label %53, label %50
28: ; preds = %16, %39
%29 = phi i64 [ 1, %16 ], [ %42, %39 ]
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* @IN_ALL_EVENTS
%33 = tail call i32 @inotify_add_watch(i32 %14, i8* %31, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %28
%36 = load i8*, i8** %1
%37 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = tail call i32 @exit(i32 -3)
unreachable
39: ; preds = %28
%40 = load i8*, i8** %30
%41 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %40, i32 %33)
%42 = add nuw nsw i64 %29, 1
%43 = icmp eq i64 %42, %17
br i1 %43, label %22, label %28
44: ; preds = %57
%45 = load i32, i32* @NAME_MAX
%46 = mul i32 %45, 10
%47 = add i32 %46, 90
%48 = call i64 @read(i32 %14, i8* %7, i32 %47)
%49 = icmp slt i64 %48, 1
br i1 %49, label %53, label %50
50: ; preds = %22, %44
%51 = phi i64 [ %48, %44 ], [ %26, %22 ]
%52 = getelementptr inbounds i8, i8* %7, i64 %51
br label %57
53: ; preds = %44, %22
%54 = load i8*, i8** %1
%55 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 -4)
unreachable
57: ; preds = %50, %57
%58 = phi i8* [ %64, %57 ], [ %7, %50 ]
%59 = bitcast i8* %58 to %struct.inotify_event*
%60 = call i32 @displayInotifyEvent(%struct.inotify_event* %59)
%61 = bitcast i8* %58 to i64*
%62 = load i64, i64* %61
%63 = add i64 %62, 8
%64 = getelementptr inbounds i8, i8* %58, i64 %63
%65 = icmp ult i8* %64, %52
br i1 %65, label %57, label %44
}