#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 int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ IN_ALL_EVENTS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_event(struct inotify_event *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char **argv) {
  int fd, wfd;
  int nums;
  char buf[sizeof(struct inotify_event) * 10];
  struct inotify_event *event;
  char *p;
  if (argc != 2) {
    printf("Usage: %s <path>\n", argv[0]);
    exit(EXIT_SUCCESS);
  }
  if ((fd = inotify_init()) < 0) {
    perror("inotify_init() ");
    exit(EXIT_FAILURE);
  }
  if ((wfd = inotify_add_watch(fd, argv[1], IN_ALL_EVENTS)) < 0) {
    perror("inotify_add_watch() ");
    exit(EXIT_FAILURE);
  }
  printf("Watch %s using wfd %d.\n", argv[1], wfd);
  for (;;) {
    if ((nums = read(fd, buf, sizeof(buf))) <= 0) {
      perror("read() ");
      exit(EXIT_FAILURE);
    }
    printf("Read %d bytes from fd %d.\n", nums, fd);
    for (p = buf; p < buf + nums;) {
      event = (struct inotify_event *)p;
      print_event(event);
      p += sizeof(struct inotify_event) + event->len;
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1060 <inotify_init@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11e3 <main+0x73>
lea    0xe42(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
call   1070 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1222 <main+0xb2>
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%edx
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x50,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jg     1272 <main+0x102>
lea    0xdf0(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
lea    -0x70(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    12cf <main+0x15f>
mov    -0x80(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   1040 <print_event@plt>
mov    -0x78(%rbp),%rax
mov    (%rax),%rax
add    $0x8,%rax
add    -0x80(%rbp),%rax
mov    %rax,-0x80(%rbp)
jmp    128e <main+0x11e>
jmp    123b <main+0xcb>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    119b <main+0x2b>
xor    %eax,%eax
call   1060 <inotify_init@plt>
test   %eax,%eax
jns    11ba <main+0x4a>
lea    0xe7c(%rip),%rdi
jmp    1275 <main+0x105>
mov    (%r14),%rsi
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %eax,%r12d
mov    0x8(%r14),%rsi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
call   1070 <inotify_add_watch@plt>
test   %eax,%eax
jns    11e2 <main+0x72>
lea    0xe45(%rip),%rdi
jmp    1275 <main+0x105>
mov    0x8(%r14),%rsi
lea    0xe4a(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%r14
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    126e <main+0xfe>
mov    %eax,%ebp
lea    0xe41(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rbx
mov    %r14,%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1040 <print_event@plt>
mov    0x0(%rbp),%rax
add    %rax,%rbp
add    $0x8,%rbp
cmp    %rbx,%rbp
jb     1240 <main+0xd0>
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1220 <main+0xb0>
lea    0xdda(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.inotify_event = type { i64 }
@.str = [18 x i8] c"Usage: %s <path>\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [16 x i8] c"inotify_init() \00"
@EXIT_FAILURE = global i32 0
@IN_ALL_EVENTS = global i32 0
@.str.2 = [21 x i8] c"inotify_add_watch() \00"
@.str.3 = [24 x i8] c"Watch %s using wfd %d.\0A\00"
@.str.4 = [8 x i8] c"read() \00"
@.str.5 = [27 x i8] c"Read %d bytes from fd %d.\0A\00"
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 [80 x i8]
%10 = alloca %struct.inotify_event*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_SUCCESS
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = call i32 (...) @inotify_init()
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %21
%29 = load i32, i32* %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* @IN_ALL_EVENTS
%34 = call i32 @inotify_add_watch(i32 %29, i8* %32, i32 %33)
store i32 %34, i32* %7
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %28
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = load i32, i32* %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %43, i32 %44)
br label %46
46: ; preds = %78, %40
%47 = load i32, i32* %6
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 80)
store i32 %49, i32* %8
%50 = icmp sle i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %46
%56 = load i32, i32* %8
%57 = load i32, i32* %6
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %56, i32 %57)
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
store i8* %59, i8** %11
br label %60
60: ; preds = %67, %55
%61 = load i8*, i8** %11
%62 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = icmp ult i8* %61, %65
br i1 %66, label %67, label %78
67: ; preds = %60
%68 = load i8*, i8** %11
%69 = bitcast i8* %68 to %struct.inotify_event*
store %struct.inotify_event* %69, %struct.inotify_event** %10
%70 = load %struct.inotify_event*, %struct.inotify_event** %10
%71 = call i32 @print_event(%struct.inotify_event* %70)
%72 = load %struct.inotify_event*, %struct.inotify_event** %10
%73 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %72, i32 0, i32 0
%74 = load i64, i64* %73
%75 = add i64 8, %74
%76 = load i8*, i8** %11
%77 = getelementptr inbounds i8, i8* %76, i64 %75
store i8* %77, i8** %11
br label %60
78: ; preds = %60
br label %46
}

LLVM IR (-O2):
%struct.inotify_event = type { i64 }
@.str = [18 x i8] c"Usage: %s <path>\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [16 x i8] c"inotify_init() \00"
@EXIT_FAILURE = global i32 0
@IN_ALL_EVENTS = global i32 0
@.str.2 = [21 x i8] c"inotify_add_watch() \00"
@.str.3 = [24 x i8] c"Watch %s using wfd %d.\0A\00"
@.str.4 = [8 x i8] c"read() \00"
@.str.5 = [27 x i8] c"Read %d bytes from fd %d.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_SUCCESS
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = tail call i32 (...) @inotify_init()
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %11
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @IN_ALL_EVENTS
%22 = tail call i32 @inotify_add_watch(i32 %12, i8* %20, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %18
%29 = load i8*, i8** %19
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %29, i32 %22)
%31 = call i32 @read(i32 %12, i8* %4, i32 80)
%32 = icmp slt i32 %31, 1
br i1 %32, label %36, label %40
33: ; preds = %45
%34 = call i32 @read(i32 %12, i8* %4, i32 80)
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %40
36: ; preds = %33, %28
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %28, %33
%41 = phi i32 [ %34, %33 ], [ %31, %28 ]
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %41, i32 %12)
%43 = zext i32 %41 to i64
%44 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %43
br label %45
45: ; preds = %40, %45
%46 = phi i8* [ %52, %45 ], [ %4, %40 ]
%47 = bitcast i8* %46 to %struct.inotify_event*
%48 = call i32 @print_event(%struct.inotify_event* %47)
%49 = bitcast i8* %46 to i64*
%50 = load i64, i64* %49
%51 = add i64 %50, 8
%52 = getelementptr inbounds i8, i8* %46, i64 %51
%53 = icmp ult i8* %52, %44
br i1 %53, label %45, label %33
}