#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ IN_OPEN;
int NAME_MAX;
int /*<<< orphan*/ checkDatabase();
int /*<<< orphan*/ displayInotifyEvent(struct inotify_event *, char **);
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int inotify_init();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_usage(char **);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ read(int, char *, int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int inotifyFd, wd, j;
  char buf[(10 * (sizeof(struct inotify_event) + NAME_MAX + 1))];
  ssize_t numRead;
  char *p;
  struct inotify_event *event;
  if (argc != 2) {
    print_usage(argv);
  } else {
    if ((strcmp(argv[1], "--gtk") != 0) && (strcmp(argv[1], "--qt") != 0)) {
      print_usage(argv);
    } else {
      checkDatabase();
      inotifyFd = inotify_init();
      if (inotifyFd < 0) {
        perror("inotify_init");
      }
      wd = inotify_add_watch(inotifyFd, "/usr/bin/pacman", IN_OPEN);
      if (wd == -1)
        perror("inotify_add_watch");
      printf("Watching '/usr/bin/pacman' using wd %d\n", wd);
      for (;;) {
        numRead = read(inotifyFd, buf,
                       (10 * (sizeof(struct inotify_event) + NAME_MAX + 1)));
        if (numRead < 0) {
          perror("read");
        }
        for (p = buf; p < buf + numRead;) {
          event = (struct inotify_event *)p;
          displayInotifyEvent(event, argv);
          p += sizeof(struct inotify_event) + event->len;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e23(%rip),%rax
movslq (%rax),%rcx
add    %rcx,%rcx
lea    0x5a(%rcx,%rcx,4),%rax
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
lea    0x69(%rcx,%rcx,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f1 <main+0x61>
mov    -0x10(%rbp),%rdi
call   10a0 <print_usage@plt>
jmp    1335 <main+0x1a5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe00(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     123b <main+0xab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde8(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     123b <main+0xab>
mov    -0x10(%rbp),%rdi
call   10a0 <print_usage@plt>
jmp    1330 <main+0x1a0>
mov    $0x0,%al
call   10b0 <checkDatabase@plt>
mov    $0x0,%al
call   1070 <inotify_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1262 <main+0xd2>
lea    0xdae(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
mov    0x2d6c(%rip),%rax
mov    (%rax),%edx
lea    0xda3(%rip),%rsi
call   1080 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1293 <main+0x103>
lea    0xd9a(%rip),%rdi
call   1090 <perror@plt>
mov    -0x18(%rbp),%esi
lea    0xd9d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x50(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2d20(%rip),%rax
movslq (%rax),%rax
add    $0x8,%rax
add    $0x1,%rax
imul   $0xa,%rax,%rax
mov    %eax,%edx
call   1050 <read@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jge    12e1 <main+0x151>
lea    0xd86(%rip),%rdi
call   1090 <perror@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rcx
mov    -0x40(%rbp),%rax
add    -0x38(%rbp),%rcx
cmp    %rcx,%rax
jae    132b <main+0x19b>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <displayInotifyEvent@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
add    $0x8,%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12e9 <main+0x159>
jmp    12a2 <main+0x112>
jmp    1335 <main+0x1a5>
mov    -0x28(%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   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    0x2e28(%rip),%rax
movslq (%rax),%rax
lea    (%rax,%rax,4),%rax
mov    %rsp,%r12
add    %rax,%rax
add    $0x69,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmp    $0x2,%edi
jne    11f2 <main+0x62>
mov    0x8(%r13),%rdi
lea    0xe2d(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120b <main+0x7b>
mov    0x8(%r13),%rdi
lea    0xe1e(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120b <main+0x7b>
mov    %r13,%rdi
call   10a0 <print_usage@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   10b0 <checkDatabase@plt>
xor    %eax,%eax
call   1070 <inotify_init@plt>
mov    %eax,%r15d
test   %eax,%eax
js     12bc <main+0x12c>
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
lea    0xde4(%rip),%rsi
mov    %r15d,%edi
call   1080 <inotify_add_watch@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12cd <main+0x13d>
lea    0xdec(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
jmp    126c <main+0xdc>
nopw   0x0(%rax,%rax,1)
lea    0xdfb(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,1),%edx
add    $0x5a,%edx
mov    %r15d,%edi
mov    %r12,%rsi
call   1050 <read@plt>
test   %rax,%rax
js     1260 <main+0xd0>
je     126c <main+0xdc>
mov    %rax,%rbx
add    %r12,%rbx
mov    %r12,%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <displayInotifyEvent@plt>
mov    (%r14),%rax
add    %rax,%r14
add    $0x8,%r14
cmp    %rbx,%r14
jb     12a0 <main+0x110>
jmp    126c <main+0xdc>
lea    0xd48(%rip),%rdi
call   1090 <perror@plt>
jmp    1224 <main+0x94>
lea    0xd54(%rip),%rdi
call   1090 <perror@plt>
jmp    1247 <main+0xb7>

LLVM IR (-O0):
%struct.inotify_event = type { i64 }
@NAME_MAX = global i32 0
@.str = [6 x i8] c"--gtk\00"
@.str.1 = [5 x i8] c"--qt\00"
@.str.2 = [13 x i8] c"inotify_init\00"
@.str.3 = [16 x i8] c"/usr/bin/pacman\00"
@IN_OPEN = global i32 0
@.str.4 = [18 x i8] c"inotify_add_watch\00"
@.str.5 = [40 x i8] c"Watching '/usr/bin/pacman' using wd %d\0A\00"
@.str.6 = [5 x i8] c"read\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 i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca %struct.inotify_event*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @NAME_MAX
%15 = sext i32 %14 to i64
%16 = add i64 8, %15
%17 = add i64 %16, 1
%18 = mul i64 10, %17
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %9
%20 = alloca i8, i64 %18
store i64 %18, i64* %10
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 2
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = call i32 @print_usage(i8** %24)
br label %92
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %26
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i8**, i8*** %5
%40 = call i32 @print_usage(i8** %39)
br label %91
41: ; preds = %32, %26
%42 = call i32 (...) @checkDatabase()
%43 = call i32 (...) @inotify_init()
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
%49 = load i32, i32* %6
%50 = load i32, i32* @IN_OPEN
%51 = call i32 @inotify_add_watch(i32 %49, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %50)
store i32 %51, i32* %7
%52 = load i32, i32* %7
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
%57 = load i32, i32* %7
%58 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %90, %56
%60 = load i32, i32* %6
%61 = load i32, i32* @NAME_MAX
%62 = sext i32 %61 to i64
%63 = add i64 8, %62
%64 = add i64 %63, 1
%65 = mul i64 10, %64
%66 = trunc i64 %65 to i32
%67 = call i64 @read(i32 %60, i8* %20, i32 %66)
store i64 %67, i64* %11
%68 = load i64, i64* %11
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %59
%71 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %72
72: ; preds = %70, %59
store i8* %20, i8** %12
br label %73
73: ; preds = %78, %72
%74 = load i8*, i8** %12
%75 = load i64, i64* %11
%76 = getelementptr inbounds i8, i8* %20, i64 %75
%77 = icmp ult i8* %74, %76
br i1 %77, label %78, label %90
78: ; preds = %73
%79 = load i8*, i8** %12
%80 = bitcast i8* %79 to %struct.inotify_event*
store %struct.inotify_event* %80, %struct.inotify_event** %13
%81 = load %struct.inotify_event*, %struct.inotify_event** %13
%82 = load i8**, i8*** %5
%83 = call i32 @displayInotifyEvent(%struct.inotify_event* %81, i8** %82)
%84 = load %struct.inotify_event*, %struct.inotify_event** %13
%85 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %84, i32 0, i32 0
%86 = load i64, i64* %85
%87 = add i64 8, %86
%88 = load i8*, i8** %12
%89 = getelementptr inbounds i8, i8* %88, i64 %87
store i8* %89, i8** %12
br label %73
90: ; preds = %73
br label %59
91: ; preds = %38
br label %92
92: ; preds = %91, %23
%93 = load i8*, i8** %9
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
%struct.inotify_event = type { i64 }
@NAME_MAX = global i32 0
@.str = [6 x i8] c"--gtk\00"
@.str.1 = [5 x i8] c"--qt\00"
@.str.2 = [13 x i8] c"inotify_init\00"
@.str.3 = [16 x i8] c"/usr/bin/pacman\00"
@IN_OPEN = global i32 0
@.str.4 = [18 x i8] c"inotify_add_watch\00"
@.str.5 = [40 x i8] c"Watching '/usr/bin/pacman' using wd %d\0A\00"
@.str.6 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32, i32* @NAME_MAX
%4 = sext i32 %3 to i64
%5 = mul nsw i64 %4, 10
%6 = add nsw i64 %5, 90
%7 = alloca i8, i64 %6
%8 = icmp eq i32 %0, 2
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @print_usage(i8** %1)
br label %57
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %11
%17 = load i8*, i8** %12
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @print_usage(i8** %1)
br label %57
22: ; preds = %16, %11
%23 = tail call i32 (...) @checkDatabase()
%24 = tail call i32 (...) @inotify_init()
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* @IN_OPEN
%30 = tail call i32 @inotify_add_watch(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %30)
br label %36
36: ; preds = %44, %34
%37 = load i32, i32* @NAME_MAX
%38 = mul i32 %37, 10
%39 = add i32 %38, 90
%40 = call i64 @read(i32 %24, i8* %7, i32 %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %48, %42, %45
br label %36
45: ; preds = %36
%46 = getelementptr inbounds i8, i8* %7, i64 %40
%47 = icmp eq i64 %40, 0
br i1 %47, label %44, label %48
48: ; preds = %45, %48
%49 = phi i8* [ %55, %48 ], [ %7, %45 ]
%50 = bitcast i8* %49 to %struct.inotify_event*
%51 = call i32 @displayInotifyEvent(%struct.inotify_event* %50, i8** %1)
%52 = bitcast i8* %49 to i64*
%53 = load i64, i64* %52
%54 = add i64 %53, 8
%55 = getelementptr inbounds i8, i8* %49, i64 %54
%56 = icmp ult i8* %55, %46
br i1 %56, label %48, label %44
57: ; preds = %20, %9
ret i32 0
}