#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 */

/* Variables and functions */
int FILENAME_MAX;
int /*<<< orphan*/ IN_ALL_EVENTS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ get_event(int, char *);
int /*<<< orphan*/ handle_error(int /*<<< orphan*/);
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  char target[FILENAME_MAX];
  int result;
  int fd;
  int wd;
  if (argc < 2) {
    fprintf(stderr, "Watching the current directory\n");
    strcpy(target, ".");
  } else {
    fprintf(stderr, "Watching %s\n", argv[1]);
    strcpy(target, argv[1]);
  }
  fd = inotify_init();
  if (fd < 0) {
    handle_error(errno);
    return 1;
  }
  wd = inotify_add_watch(fd, target, IN_ALL_EVENTS);
  if (wd < 0) {
    handle_error(errno);
    return 1;
  }
  while (1) {
    get_event(fd, target);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d8 <main+0x78>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1208 <main+0xa8>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    $0x0,%al
call   1050 <inotify_init@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    123d <main+0xdd>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1080 <handle_error@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    129b <main+0x13b>
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%edi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
call   1060 <inotify_add_watch@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1280 <main+0x120>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1080 <handle_error@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    129b <main+0x13b>
jmp    1285 <main+0x125>
jmp    128a <main+0x12a>
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%edi
call   1070 <get_event@plt>
jmp    1285 <main+0x125>
mov    -0x18(%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   %rbx
push   %rax
mov    %edi,%eax
mov    0x2e75(%rip),%rcx
mov    (%rcx),%ecx
mov    %rsp,%r15
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r15
mov    %r15,%rsp
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%edi
cmp    $0x1,%eax
jg     11ab <main+0x4b>
lea    0xe65(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe77(%rip),%rsi
jmp    11c4 <main+0x64>
mov    %rsi,%r14
mov    0x8(%rsi),%rdx
lea    0xe69(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x8(%r14),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1050 <inotify_init@plt>
test   %eax,%eax
js     11fc <main+0x9c>
mov    %eax,%ebx
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r15,%rsi
call   1060 <inotify_add_watch@plt>
test   %eax,%eax
js     11fc <main+0x9c>
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <get_event@plt>
jmp    11f0 <main+0x90>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1080 <handle_error@plt>
mov    $0x1,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Watching the current directory\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [13 x i8] c"Watching %s\0A\00"
@errno = global i32 0
@IN_ALL_EVENTS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @FILENAME_MAX
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %32
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strcpy(i8* %15, i8* %30)
br label %32
32: ; preds = %22, %18
%33 = call i32 (...) @inotify_init()
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32, i32* @errno
%38 = call i32 @handle_error(i32 %37)
store i32 1, i32* %3
store i32 1, i32* %11
br label %53
39: ; preds = %32
%40 = load i32, i32* %9
%41 = load i32, i32* @IN_ALL_EVENTS
%42 = call i32 @inotify_add_watch(i32 %40, i8* %15, i32 %41)
store i32 %42, i32* %10
%43 = load i32, i32* %10
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = load i32, i32* @errno
%47 = call i32 @handle_error(i32 %46)
store i32 1, i32* %3
store i32 1, i32* %11
br label %53
48: ; preds = %39
br label %49
49: ; preds = %50, %48
br label %50
50: ; preds = %49
%51 = load i32, i32* %9
%52 = call i32 @get_event(i32 %51, i8* %15)
br label %49
53: ; preds = %45, %36
%54 = load i8*, i8** %6
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"Watching the current directory\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [13 x i8] c"Watching %s\0A\00"
@errno = global i32 0
@IN_ALL_EVENTS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @FILENAME_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp slt i32 %0, 2
%7 = load i32, i32* @stderr
br i1 %6, label %8, label %10
8: ; preds = %2
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %15
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %11
br label %15
15: ; preds = %10, %8
%16 = phi i8* [ %14, %10 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %8 ]
%17 = call i32 @strcpy(i8* %5, i8* %16)
%18 = call i32 (...) @inotify_init()
%19 = icmp slt i32 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %15
%21 = load i32, i32* @IN_ALL_EVENTS
%22 = call i32 @inotify_add_watch(i32 %18, i8* %5, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20, %24
%25 = call i32 @get_event(i32 %18, i8* %5)
br label %24
26: ; preds = %20, %15
%27 = load i32, i32* @errno
%28 = call i32 @handle_error(i32 %27)
ret i32 1
}