#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 {
  int wd;
  int mask;
  int cookie;
  int len;
  char *name;
};

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int IN_CREATE;
int IN_DELETE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ do_analysis();
int inotify_add_watch(int, char *, int);
int inotify_init();
int /*<<< orphan*/ inotify_rm_watch(int, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int /*<<< orphan*/);
int main() {
  int fd, wd, len;
  char buf[1024 * (sizeof(struct inotify_event))];
  struct inotify_event *ie = NULL;
  fd = inotify_init();
  if (fd != -1)
    printf("fd = %d\n", fd);
  else {
    printf("init failed\n");
    return -1;
  }
  wd = inotify_add_watch(fd, "./lib/", IN_CREATE | IN_DELETE);
  if (wd != -1)
    printf("wd = %d\n", wd);
  else {
    printf("addwatch failed\n");
    return -1;
  }
  while (len = read(fd, buf, BUFSIZ)) {
    if (len) {
      printf("%d readed\n", len);
      do_analysis();
    } else {
      printf("read failed\n");
      return -1;
    }
    ie = (struct inotify_event *)&buf[0];
    if (ie) {
      printf("wd %d, mask %d, ck %d, len %d, name %s\n", ie->wd, ie->mask,
             ie->cookie, ie->len, ie->name);
    } else
      printf("ie null\n");
  }
  inotify_rm_watch(fd, wd);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x6020,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x6018(%rbp)
mov    $0x0,%al
call   1070 <inotify_init@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     11b7 <main+0x47>
mov    -0x8(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d1 <main+0x61>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1328 <main+0x1b8>
mov    -0x8(%rbp),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
mov    0x2e04(%rip),%rax
or     (%rax),%edx
lea    0xe29(%rip),%rsi
call   1080 <inotify_add_watch@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
je     1215 <main+0xa5>
mov    -0xc(%rbp),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122f <main+0xbf>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1328 <main+0x1b8>
jmp    1234 <main+0xc4>
mov    -0x8(%rbp),%edi
lea    -0x6010(%rbp),%rsi
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
call   1050 <read@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     130e <main+0x19e>
cmpl   $0x0,-0x10(%rbp)
je     127f <main+0x10f>
mov    -0x10(%rbp),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <do_analysis@plt>
jmp    1299 <main+0x129>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1328 <main+0x1b8>
lea    -0x6010(%rbp),%rax
mov    %rax,-0x6018(%rbp)
cmpq   $0x0,-0x6018(%rbp)
je     12fb <main+0x18b>
mov    -0x6018(%rbp),%rax
mov    (%rax),%esi
mov    -0x6018(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x6018(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x6018(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0x6018(%rbp),%rax
mov    0x10(%rax),%r9
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1309 <main+0x199>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1234 <main+0xc4>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <inotify_rm_watch@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x6020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x6008,%rsp
xor    %eax,%eax
call   1080 <inotify_init@plt>
cmp    $0xffffffff,%eax
je     1278 <main+0xf8>
mov    %eax,%ebx
lea    0xe56(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e16(%rip),%rax
mov    0x2e27(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe3d(%rip),%rsi
mov    %ebx,%edi
call   1090 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
je     1281 <main+0x101>
mov    %eax,%r15d
lea    0xe2a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2de2(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rsi
mov    %ebx,%edi
call   1060 <read@plt>
test   %eax,%eax
je     1263 <main+0xe3>
lea    0xe0b(%rip),%r12
lea    0xe0f(%rip),%r13
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <do_analysis@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1060 <read@plt>
test   %eax,%eax
jne    1220 <main+0xa0>
mov    %ebx,%edi
mov    %r15d,%esi
call   10a0 <inotify_rm_watch@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1292 <main+0x112>
lea    0xdcd(%rip),%rdi
jmp    1288 <main+0x108>
lea    0xdd0(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x6008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.inotify_event = type { i32, i32, i32, i32, i8* }
@.str = [9 x i8] c"fd = %d\0A\00"
@.str.1 = [13 x i8] c"init failed\0A\00"
@.str.2 = [7 x i8] c"./lib/\00"
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@.str.3 = [9 x i8] c"wd = %d\0A\00"
@.str.4 = [17 x i8] c"addwatch failed\0A\00"
@BUFSIZ = global i32 0
@.str.5 = [11 x i8] c"%d readed\0A\00"
@.str.6 = [13 x i8] c"read failed\0A\00"
@.str.7 = [40 x i8] c"wd %d, mask %d, ck %d, len %d, name %s\0A\00"
@.str.8 = [9 x i8] c"ie null\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [24576 x i8]
%6 = alloca %struct.inotify_event*
store i32 0, i32* %1
store %struct.inotify_event* null, %struct.inotify_event** %6
%7 = call i32 (...) @inotify_init()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %75
15: ; preds = %10
%16 = load i32, i32* %2
%17 = load i32, i32* @IN_CREATE
%18 = load i32, i32* @IN_DELETE
%19 = or i32 %17, %18
%20 = call i32 @inotify_add_watch(i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %28
26: ; preds = %15
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %75
28: ; preds = %23
br label %29
29: ; preds = %68, %28
%30 = load i32, i32* %2
%31 = getelementptr inbounds [24576 x i8], [24576 x i8]* %5, i64 0, i64 0
%32 = load i32, i32* @BUFSIZ
%33 = call i32 @read(i32 %30, i8* %31, i32 %32)
store i32 %33, i32* %4
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %69
35: ; preds = %29
%36 = load i32, i32* %4
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i32, i32* %4
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = call i32 (...) @do_analysis()
br label %44
42: ; preds = %35
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %75
44: ; preds = %38
%45 = getelementptr inbounds [24576 x i8], [24576 x i8]* %5, i64 0, i64 0
%46 = bitcast i8* %45 to %struct.inotify_event*
store %struct.inotify_event* %46, %struct.inotify_event** %6
%47 = load %struct.inotify_event*, %struct.inotify_event** %6
%48 = icmp ne %struct.inotify_event* %47, null
br i1 %48, label %49, label %66
49: ; preds = %44
%50 = load %struct.inotify_event*, %struct.inotify_event** %6
%51 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load %struct.inotify_event*, %struct.inotify_event** %6
%54 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = load %struct.inotify_event*, %struct.inotify_event** %6
%57 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %56, i32 0, i32 2
%58 = load i32, i32* %57
%59 = load %struct.inotify_event*, %struct.inotify_event** %6
%60 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %59, i32 0, i32 3
%61 = load i32, i32* %60
%62 = load %struct.inotify_event*, %struct.inotify_event** %6
%63 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %62, i32 0, i32 4
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i32 %52, i32 %55, i32 %58, i32 %61, i8* %64)
br label %68
66: ; preds = %44
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %68
68: ; preds = %66, %49
br label %29
69: ; preds = %29
%70 = load i32, i32* %2
%71 = load i32, i32* %3
%72 = call i32 @inotify_rm_watch(i32 %70, i32 %71)
%73 = load i32, i32* %2
%74 = call i32 @close(i32 %73)
store i32 0, i32* %1
br label %75
75: ; preds = %69, %42, %26, %13
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
%struct.inotify_event = type { i32, i32, i32, i32, i8* }
@.str = [9 x i8] c"fd = %d\0A\00"
@.str.2 = [7 x i8] c"./lib/\00"
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@.str.3 = [9 x i8] c"wd = %d\0A\00"
@BUFSIZ = global i32 0
@.str.5 = [11 x i8] c"%d readed\0A\00"
@.str.7 = [40 x i8] c"wd %d, mask %d, ck %d, len %d, name %s\0A\00"
@str = [12 x i8] c"init failed\00"
@str.9 = [16 x i8] c"addwatch failed\00"
define i32 @main() {
%1 = alloca [24576 x i8]
%2 = getelementptr inbounds [24576 x i8], [24576 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @inotify_init()
%4 = icmp eq i32 %3, -1
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%7 = load i32, i32* @IN_CREATE
%8 = load i32, i32* @IN_DELETE
%9 = or i32 %8, %7
%10 = tail call i32 @inotify_add_watch(i32 %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %29, label %14
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %47
14: ; preds = %5
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%16 = load i32, i32* @BUFSIZ
%17 = call i32 @read(i32 %3, i8* %2, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %44, label %19
19: ; preds = %14
%20 = bitcast [24576 x i8]* %1 to i32*
%21 = getelementptr inbounds [24576 x i8], [24576 x i8]* %1, i64 0, i64 4
%22 = bitcast i8* %21 to i32*
%23 = getelementptr inbounds [24576 x i8], [24576 x i8]* %1, i64 0, i64 8
%24 = bitcast i8* %23 to i32*
%25 = getelementptr inbounds [24576 x i8], [24576 x i8]* %1, i64 0, i64 12
%26 = bitcast i8* %25 to i32*
%27 = getelementptr inbounds [24576 x i8], [24576 x i8]* %1, i64 0, i64 16
%28 = bitcast i8* %27 to i8**
br label %31
29: ; preds = %5
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
br label %47
31: ; preds = %19, %31
%32 = phi i32 [ %17, %19 ], [ %42, %31 ]
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = tail call i32 (...) @do_analysis()
%35 = load i32, i32* %20
%36 = load i32, i32* %22
%37 = load i32, i32* %24
%38 = load i32, i32* %26
%39 = load i8*, i8** %28
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), i32 %35, i32 %36, i32 %37, i32 %38, i8* %39)
%41 = load i32, i32* @BUFSIZ
%42 = call i32 @read(i32 %3, i8* %2, i32 %41)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %31
44: ; preds = %31, %14
%45 = tail call i32 @inotify_rm_watch(i32 %3, i32 %10)
%46 = tail call i32 @close(i32 %3)
br label %47
47: ; preds = %44, %29, %12
%48 = phi i32 [ 0, %44 ], [ -1, %29 ], [ -1, %12 ]
ret i32 %48
}