#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_ACCESS;
int IN_MODIFY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int inotify_add_watch(int, char *, int);
int inotify_init();
size_t optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "Usage: test_inotify [-r] file_name\n");
    exit(1);
  }
  int fd, wd, arg;
  int mask = IN_MODIFY;
  while ((arg = getopt(argc, argv, "pr")) != -1) {
    switch (arg) {
    case 'r':
      mask |= IN_ACCESS;
      break;
    default:
      fprintf(stderr, "Usage: test_inotify [-r] file_name\n");
      exit(1);
    }
  }
  fd = inotify_init();
  if (fd < 0) {
    perror("inotify_init:bad file descriptor");
    exit(1);
  }
  wd = inotify_add_watch(fd, argv[optind], mask);
  if (wd < 0) {
    perror("test_inotify:watch denied");
    exit(1);
  }
  exit(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)
jge    119f <main+0x3f>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1213 <main+0xb3>
mov    -0x1c(%rbp),%eax
sub    $0x72,%eax
jne    11ef <main+0x8f>
jmp    11db <main+0x7b>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    120e <main+0xae>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11ab <main+0x4b>
mov    $0x0,%al
call   1040 <inotify_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123d <main+0xdd>
lea    0xdf9(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x2d95(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%edx
call   1050 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    127d <main+0x11d>
lea    0xdda(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jle    11c1 <main+0x61>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e77(%rip),%rax
mov    (%rax),%ebp
lea    0xea2(%rip),%r15
mov    0x2e47(%rip),%r12
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    $0x72,%eax
jne    11a8 <main+0x48>
or     (%r12),%ebp
jmp    1190 <main+0x30>
cmp    $0xffffffff,%eax
jne    11c1 <main+0x61>
xor    %eax,%eax
call   1040 <inotify_init@plt>
test   %eax,%eax
jns    11e0 <main+0x80>
lea    0xe68(%rip),%rdi
jmp    1202 <main+0xa2>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2df9(%rip),%rcx
mov    (%rcx),%rcx
mov    (%r14,%rcx,8),%rsi
mov    %eax,%edi
mov    %ebp,%edx
call   1050 <inotify_add_watch@plt>
test   %eax,%eax
jns    1211 <main+0xb1>
lea    0xe46(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: test_inotify [-r] file_name\0A\00"
@IN_MODIFY = global i32 0
@.str.1 = [3 x i8] c"pr\00"
@IN_ACCESS = global i32 0
@.str.2 = [33 x i8] c"inotify_init:bad file descriptor\00"
@optind = global i64 0
@.str.3 = [26 x i8] c"test_inotify:watch denied\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @IN_MODIFY
store i32 %17, i32* %9
br label %18
18: ; preds = %33, %16
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @getopt(i32 %19, i8** %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %21, i32* %8
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %34
23: ; preds = %18
%24 = load i32, i32* %8
switch i32 %24, label %29 [
i32 114, label %25
]
25: ; preds = %23
%26 = load i32, i32* @IN_ACCESS
%27 = load i32, i32* %9
%28 = or i32 %27, %26
store i32 %28, i32* %9
br label %33
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %25
br label %18
34: ; preds = %18
%35 = call i32 (...) @inotify_init()
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %34
%42 = load i32, i32* %6
%43 = load i8**, i8*** %5
%44 = load i64, i64* @optind
%45 = getelementptr inbounds i8*, i8** %43, i64 %44
%46 = load i8*, i8** %45
%47 = load i32, i32* %9
%48 = call i32 @inotify_add_watch(i32 %42, i8* %46, i32 %47)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %41
%52 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %41
%55 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: test_inotify [-r] file_name\0A\00"
@IN_MODIFY = global i32 0
@.str.1 = [3 x i8] c"pr\00"
@IN_ACCESS = global i32 0
@.str.2 = [33 x i8] c"inotify_init:bad file descriptor\00"
@optind = global i64 0
@.str.3 = [26 x i8] c"test_inotify:watch denied\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = load i32, i32* @IN_MODIFY
br label %10
10: ; preds = %13, %8
%11 = phi i32 [ %9, %8 ], [ %15, %13 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %12, label %16 [
i32 -1, label %20
i32 114, label %13
]
13: ; preds = %10
%14 = load i32, i32* @IN_ACCESS
%15 = or i32 %14, %11
br label %10
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = tail call i32 (...) @inotify_init()
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = load i64, i64* @optind
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = tail call i32 @inotify_add_watch(i32 %21, i8* %29, i32 %11)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %26
%36 = tail call i32 @exit(i32 0)
unreachable
}