#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 *, char *);
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;
  char buf[(10 * (sizeof(struct inotify_event) + NAME_MAX + 1))];
  ssize_t numRead;
  char *p;
  struct inotify_event *event;
  if (argc != 2) {
    printf("usage: %s file\n", argv[0]);
    exit(-1);
  }
  inotifyFD = inotify_init();
  if (inotifyFD == -1) {
    printf("%s inotify_init() failure\n", argv[0]);
    exit(-2);
  }
  wd = inotify_add_watch(inotifyFD, argv[1], IN_ALL_EVENTS);
  if (wd == -1) {
    printf("%s inotify_add_watch() failure\n", argv[0]);
    exit(-3);
  }
  printf("Watching %s.\n", argv[1]);
  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, argv[1]);
      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,-0x20(%rbp)
lea    0x69(%rcx,%rcx,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d0 <main+0x70>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3f(%rip),%rdi
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    1201 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
call   1070 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1244 <main+0xe4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    $0xfffffffd,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2d6a(%rip),%rax
movslq (%rax),%rax
add    $0x8,%rax
add    $0x1,%rax
imul   $0xa,%rax,%rax
mov    %eax,%edx
call   1050 <read@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jg     12a8 <main+0x148>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdc0(%rip),%rdi
call   1040 <printf@plt>
mov    $0xfffffffc,%edi
call   1080 <exit@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rcx
cmp    %rcx,%rax
jae    12f6 <main+0x196>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <displayInotifyEvent@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
add    $0x8,%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    12b0 <main+0x150>
jmp    1258 <main+0xf8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    0x2e58(%rip),%r15
movslq (%r15),%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    $0x2,%edi
jne    11be <main+0x5e>
xor    %eax,%eax
call   1060 <inotify_init@plt>
cmp    $0xffffffff,%eax
jne    11d8 <main+0x78>
mov    (%r12),%rsi
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
mov    (%r12),%rsi
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    %eax,%ebx
mov    0x8(%r12),%rsi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
call   1070 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
jne    120e <main+0xae>
mov    (%r12),%rsi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xfffffffd,%edi
call   1080 <exit@plt>
mov    0x8(%r12),%rsi
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
mov    (%r15),%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,1),%edx
add    $0x5a,%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <read@plt>
test   %rax,%rax
jle    128b <main+0x12b>
mov    %rax,%r13
mov    %ebx,-0x2c(%rbp)
mov    %r14,%rbx
add    %r14,%r13
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%r12),%rsi
mov    %rbx,%rdi
call   1030 <displayInotifyEvent@plt>
mov    (%rbx),%rax
add    %rax,%rbx
add    $0x8,%rbx
cmp    %r13,%rbx
jb     1250 <main+0xf0>
mov    (%r15),%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,1),%edx
add    $0x5a,%edx
mov    -0x2c(%rbp),%edi
mov    %r14,%rsi
call   1050 <read@plt>
mov    %rax,%r13
test   %rax,%rax
jg     1240 <main+0xe0>
mov    (%r12),%rsi
lea    0xdc3(%rip),%rdi
call   1040 <printf@plt>
mov    $0xfffffffc,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
%struct.inotify_event = type { i64 }
@NAME_MAX = global i32 0
@.str = [16 x i8] c"usage: %s file\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 = [14 x i8] c"Watching %s.\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 eq i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 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 %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 -2)
unreachable
20: ; preds = %13
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @IN_ALL_EVENTS
%24 = tail call i32 @inotify_add_watch(i32 %14, i8* %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i8*, i8** %1
%28 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = tail call i32 @exit(i32 -3)
unreachable
30: ; preds = %20
%31 = load i8*, i8** %21
%32 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @NAME_MAX
%34 = mul i32 %33, 10
%35 = add i32 %34, 90
%36 = call i64 @read(i32 %14, i8* %7, i32 %35)
%37 = icmp slt i64 %36, 1
br i1 %37, label %47, label %44
38: ; preds = %51
%39 = load i32, i32* @NAME_MAX
%40 = mul i32 %39, 10
%41 = add i32 %40, 90
%42 = call i64 @read(i32 %14, i8* %7, i32 %41)
%43 = icmp slt i64 %42, 1
br i1 %43, label %47, label %44
44: ; preds = %30, %38
%45 = phi i64 [ %42, %38 ], [ %36, %30 ]
%46 = getelementptr inbounds i8, i8* %7, i64 %45
br label %51
47: ; preds = %38, %30
%48 = load i8*, i8** %1
%49 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 -4)
unreachable
51: ; preds = %44, %51
%52 = phi i8* [ %59, %51 ], [ %7, %44 ]
%53 = bitcast i8* %52 to %struct.inotify_event*
%54 = load i8*, i8** %21
%55 = call i32 @displayInotifyEvent(%struct.inotify_event* %53, i8* %54)
%56 = bitcast i8* %52 to i64*
%57 = load i64, i64* %56
%58 = add i64 %57, 8
%59 = getelementptr inbounds i8, i8* %52, i64 %58
%60 = icmp ult i8* %59, %46
br i1 %60, label %51, label %38
}