#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 /*<<< orphan*/ IN_ALL_EVENTS;
scalar_t__ close(int);
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init();
scalar_t__ inotify_rm_watch(int, int);
int /*<<< orphan*/ printf(char *);
int main(void) {
  int fd, wd;
  if (-1 == (fd = inotify_init())) {
    printf("inotify_init failed\n");
    return 1;
  }
  if (0 > (wd = inotify_add_watch(fd, ".", IN_ALL_EVENTS))) {
    printf("inotify_add_watch failed\n");
    return 2;
  }
  if (0 != inotify_rm_watch(fd, wd)) {
    printf("inotify_rm_watch failed\n");
    return 3;
  }
  if (0 != close(fd)) {
    printf("close failed\n");
    return 4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <inotify_init@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1190 <main+0x40>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1235 <main+0xe5>
mov    -0x8(%rbp),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
lea    0xe72(%rip),%rsi
call   1060 <inotify_add_watch@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jle    11cf <main+0x7f>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1235 <main+0xe5>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <inotify_rm_watch@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1200 <main+0xb0>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1235 <main+0xe5>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     122e <main+0xde>
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1235 <main+0xe5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <inotify_init@plt>
cmp    $0xffffffff,%eax
je     1196 <main+0x46>
mov    %eax,%ebx
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    0xe91(%rip),%rsi
mov    %ebx,%edi
call   1060 <inotify_add_watch@plt>
test   %eax,%eax
js     11a4 <main+0x54>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <inotify_rm_watch@plt>
test   %rax,%rax
je     11b2 <main+0x62>
mov    $0x3,%ebx
lea    0xe7b(%rip),%rdi
jmp    11ca <main+0x7a>
mov    $0x1,%ebx
lea    0xe9e(%rip),%rdi
jmp    11ca <main+0x7a>
mov    $0x2,%ebx
lea    0xe77(%rip),%rdi
jmp    11ca <main+0x7a>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
je     11d3 <main+0x83>
mov    $0x4,%ebx
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret
xor    %ebx,%ebx
jmp    11cf <main+0x7f>

LLVM IR (-O0):
@.str = [21 x i8] c"inotify_init failed\0A\00"
@.str.1 = [2 x i8] c".\00"
@IN_ALL_EVENTS = global i32 0
@.str.2 = [26 x i8] c"inotify_add_watch failed\0A\00"
@.str.3 = [25 x i8] c"inotify_rm_watch failed\0A\00"
@.str.4 = [14 x i8] c"close failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @inotify_init()
store i32 %4, i32* %2
%5 = icmp eq i32 -1, %4
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %29
8: ; preds = %0
%9 = load i32, i32* %2
%10 = load i32, i32* @IN_ALL_EVENTS
%11 = call i32 @inotify_add_watch(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %10)
store i32 %11, i32* %3
%12 = icmp sgt i32 0, %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %1
br label %29
15: ; preds = %8
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = call i64 @inotify_rm_watch(i32 %16, i32 %17)
%19 = icmp ne i64 0, %18
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %1
br label %29
22: ; preds = %15
%23 = load i32, i32* %2
%24 = call i64 @close(i32 %23)
%25 = icmp ne i64 0, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 4, i32* %1
br label %29
28: ; preds = %22
store i32 0, i32* %1
br label %29
29: ; preds = %28, %26, %20, %13, %6
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c".\00"
@IN_ALL_EVENTS = global i32 0
@str = [13 x i8] c"close failed\00"
@str.5 = [24 x i8] c"inotify_rm_watch failed\00"
@str.6 = [25 x i8] c"inotify_add_watch failed\00"
@str.7 = [20 x i8] c"inotify_init failed\00"
define i32 @main() {
%1 = tail call i32 (...) @inotify_init()
%2 = icmp eq i32 %1, -1
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = load i32, i32* @IN_ALL_EVENTS
%5 = tail call i32 @inotify_add_watch(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = tail call i64 @inotify_rm_watch(i32 %1, i32 %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i64 @close(i32 %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10, %7, %3, %0
%14 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0), %0 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0), %3 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0), %7 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), %10 ]
%15 = phi i32 [ 1, %0 ], [ 2, %3 ], [ 3, %7 ], [ 4, %10 ]
%16 = tail call i32 @puts(i8* dereferenceable(1) %14)
br label %17
17: ; preds = %13, %10
%18 = phi i32 [ 0, %10 ], [ %15, %13 ]
ret i32 %18
}