#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 IN_CREATE;
int IN_DELETE;
int /*<<< orphan*/ close(int);
int inotify_add_watch(int, char *, int);
int inotify_init();
int inotify_rm_watch(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ watch_inotify_events(int);
int main(int argc, char **argv) {
  int InotifyFd;
  int ret;
  if (argc != 2) {
    printf("Usage: %s <dir>\n", argv[0]);
    return -1;
  }
  InotifyFd = inotify_init();
  if (InotifyFd == -1) {
    printf("inotify_init error!\n");
    return -1;
  }
  ret = inotify_add_watch(InotifyFd, argv[1], IN_CREATE | IN_DELETE);
  watch_inotify_events(InotifyFd);
  if (inotify_rm_watch(InotifyFd, ret) == -1) {
    printf("notify_rm_watch error!\n");
    return -1;
  }
  close(InotifyFd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <main+0xd9>
mov    $0x0,%al
call   1060 <inotify_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11cf <main+0x6f>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <main+0xd9>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
mov    0x2dfe(%rip),%rax
or     (%rax),%edx
call   1070 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <watch_inotify_events@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1080 <inotify_rm_watch@plt>
cmp    $0xffffffff,%eax
jne    122a <main+0xca>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <main+0xd9>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11c8 <main+0x58>
xor    %eax,%eax
call   1070 <inotify_init@plt>
cmp    $0xffffffff,%eax
je     11db <main+0x6b>
mov    %eax,%ebp
mov    0x8(%rbx),%rsi
mov    0x2e44(%rip),%rax
mov    0x2e4d(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %ebp,%edi
call   1080 <inotify_add_watch@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <watch_inotify_events@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1090 <inotify_rm_watch@plt>
cmp    $0xffffffff,%eax
je     11e4 <main+0x74>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    11f5 <main+0x85>
mov    (%rbx),%rsi
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f0 <main+0x80>
lea    0xe46(%rip),%rdi
jmp    11eb <main+0x7b>
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Usage: %s <dir>\0A\00"
@.str.1 = [21 x i8] c"inotify_init error!\0A\00"
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@.str.2 = [24 x i8] c"notify_rm_watch error!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 -1, i32* %3
br label %41
15: ; preds = %2
%16 = call i32 (...) @inotify_init()
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %41
21: ; preds = %15
%22 = load i32, i32* %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @IN_CREATE
%27 = load i32, i32* @IN_DELETE
%28 = or i32 %26, %27
%29 = call i32 @inotify_add_watch(i32 %22, i8* %25, i32 %28)
store i32 %29, i32* %7
%30 = load i32, i32* %6
%31 = call i32 @watch_inotify_events(i32 %30)
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = call i32 @inotify_rm_watch(i32 %32, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %21
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %41
38: ; preds = %21
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
store i32 0, i32* %3
br label %41
41: ; preds = %38, %36, %19, %10
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [17 x i8] c"Usage: %s <dir>\0A\00"
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@str = [23 x i8] c"notify_rm_watch error!\00"
@str.3 = [20 x i8] c"inotify_init error!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %26
7: ; preds = %2
%8 = tail call i32 (...) @inotify_init()
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.3, i64 0, i64 0))
br label %26
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @IN_CREATE
%16 = load i32, i32* @IN_DELETE
%17 = or i32 %16, %15
%18 = tail call i32 @inotify_add_watch(i32 %8, i8* %14, i32 %17)
%19 = tail call i32 @watch_inotify_events(i32 %8)
%20 = tail call i32 @inotify_rm_watch(i32 %8, i32 %18)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %26
24: ; preds = %12
%25 = tail call i32 @close(i32 %8)
br label %26
26: ; preds = %24, %22, %10, %4
%27 = phi i32 [ -1, %4 ], [ -1, %10 ], [ -1, %22 ], [ 0, %24 ]
ret i32 %27
}