#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 */
scalar_t__ EINTR;
int IN_ALL_EVENTS;
int IN_ATTRIB;
int IN_CLOSE_WRITE;
int IN_CREATE;
int IN_DELETE;
int IN_MODIFY;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int inotify_add_watch(int, char *, int);
int inotify_init();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd;
  char buf[(1024 * ((sizeof(struct inotify_event)) + 16))];
  int len, i = 0;
  fd = inotify_init();
  if (fd < 0)
    fprintf(stderr, "ERROR: inotify_init\n");
  int wd;
  wd = inotify_add_watch(fd, "/tmp/device/android-device-log.txt",
                         IN_MODIFY | IN_CREATE | IN_DELETE | IN_ATTRIB |
                             IN_CLOSE_WRITE | IN_ALL_EVENTS);
  if (wd < 0)
    fprintf(stderr, "ERROR: inotify_add_watch\n");
  len = read(fd, buf, (1024 * ((sizeof(struct inotify_event)) + 16)));
  if (len < 0) {
    if (errno == EINTR)
      fprintf(stderr, "need to reissue system call\n");
    else
      perror("read");
  } else if (!len) {
    while (i < len) {
      struct inotify_event *event;
      event = (struct inotify_event *)&buf[i];
      printf("wd=%d mask=%u cookie=%u len=%u\n", event->wd, event->mask,
             event->cookie, event->len);
      if (event->len)
        printf("name=%s\n", event->name);
      i += (sizeof(struct inotify_event)) + event->len;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xa028(%rbp)
mov    $0x0,%al
call   1060 <inotify_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ac <main+0x4c>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    0x2df1(%rip),%rax
or     (%rax),%edx
mov    0x2e08(%rip),%rax
or     (%rax),%edx
mov    0x2e0f(%rip),%rax
or     (%rax),%edx
mov    0x2dfe(%rip),%rax
or     (%rax),%edx
mov    0x2dbd(%rip),%rax
or     (%rax),%edx
lea    0xe29(%rip),%rsi
call   1070 <inotify_add_watch@plt>
mov    %eax,-0xa02c(%rbp)
cmpl   $0x0,-0xa02c(%rbp)
jge    1219 <main+0xb9>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0xa020(%rbp),%rsi
mov    $0xa000,%edx
call   1040 <read@plt>
mov    %eax,-0xa024(%rbp)
cmpl   $0x0,-0xa024(%rbp)
jge    1285 <main+0x125>
mov    0x2d71(%rip),%rax
mov    (%rax),%rax
mov    0x2d57(%rip),%rcx
cmp    (%rcx),%rax
jne    1274 <main+0x114>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1280 <main+0x120>
lea    0xdf4(%rip),%rdi
call   1080 <perror@plt>
jmp    134f <main+0x1ef>
cmpl   $0x0,-0xa024(%rbp)
jne    134a <main+0x1ea>
jmp    1297 <main+0x137>
mov    -0xa028(%rbp),%eax
cmp    -0xa024(%rbp),%eax
jge    1345 <main+0x1e5>
movslq -0xa028(%rbp),%rcx
lea    -0xa020(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0xa038(%rbp)
mov    -0xa038(%rbp),%rax
mov    (%rax),%esi
mov    -0xa038(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0xa038(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0xa038(%rbp),%rax
mov    0xc(%rax),%r8d
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xa038(%rbp),%rax
cmpl   $0x0,0xc(%rax)
je     1321 <main+0x1c1>
mov    -0xa038(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xa038(%rbp),%rax
movslq 0xc(%rax),%rcx
add    $0x18,%rcx
movslq -0xa028(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa028(%rbp)
jmp    1297 <main+0x137>
jmp    134a <main+0x1ea>
jmp    134f <main+0x1ef>
xor    %eax,%eax
add    $0xa040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xa000,%rsp
xor    %eax,%eax
call   1050 <inotify_init@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    117a <main+0x2a>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e6f(%rip),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e3d(%rip),%rax
or     (%rax),%edx
mov    0x2e44(%rip),%rax
or     (%rax),%edx
mov    0x2e33(%rip),%rax
or     (%rax),%edx
mov    0x2df2(%rip),%rax
or     (%rax),%edx
lea    0xe5e(%rip),%rsi
mov    %ebx,%edi
call   1060 <inotify_add_watch@plt>
test   %eax,%eax
jns    11d7 <main+0x87>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xa000,%edx
call   1030 <read@plt>
test   %eax,%eax
jns    1215 <main+0xc5>
mov    0x2dc7(%rip),%rax
mov    (%rax),%rax
mov    0x2dad(%rip),%rcx
cmp    (%rcx),%rax
jne    1220 <main+0xd0>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0xa000,%rsp
pop    %rbx
ret
lea    0xe48(%rip),%rdi
call   1070 <perror@plt>
jmp    1215 <main+0xc5>

LLVM IR (-O0):
%struct.inotify_event = type { i32, i32, i32, i32, i8* }
@stderr = global i32 0
@.str = [21 x i8] c"ERROR: inotify_init\0A\00"
@.str.1 = [35 x i8] c"/tmp/device/android-device-log.txt\00"
@IN_MODIFY = global i32 0
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@IN_ATTRIB = global i32 0
@IN_CLOSE_WRITE = global i32 0
@IN_ALL_EVENTS = global i32 0
@.str.2 = [26 x i8] c"ERROR: inotify_add_watch\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.3 = [29 x i8] c"need to reissue system call\0A\00"
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [32 x i8] c"wd=%d mask=%u cookie=%u len=%u\0A\00"
@.str.6 = [9 x i8] c"name=%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [40960 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.inotify_event*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%12 = call i32 (...) @inotify_init()
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %2
%19 = load i32, i32* %6
%20 = load i32, i32* @IN_MODIFY
%21 = load i32, i32* @IN_CREATE
%22 = or i32 %20, %21
%23 = load i32, i32* @IN_DELETE
%24 = or i32 %22, %23
%25 = load i32, i32* @IN_ATTRIB
%26 = or i32 %24, %25
%27 = load i32, i32* @IN_CLOSE_WRITE
%28 = or i32 %26, %27
%29 = load i32, i32* @IN_ALL_EVENTS
%30 = or i32 %28, %29
%31 = call i32 @inotify_add_watch(i32 %19, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %18
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %34, %18
%38 = load i32, i32* %6
%39 = getelementptr inbounds [40960 x i8], [40960 x i8]* %7, i64 0, i64 0
%40 = call i32 @read(i32 %38, i8* %39, i32 40960)
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %37
%44 = load i64, i64* @errno
%45 = load i64, i64* @EINTR
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %52
50: ; preds = %43
%51 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
br label %100
53: ; preds = %37
%54 = load i32, i32* %8
%55 = icmp ne i32 %54, 0
br i1 %55, label %99, label %56
56: ; preds = %53
br label %57
57: ; preds = %88, %56
%58 = load i32, i32* %9
%59 = load i32, i32* %8
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %98
61: ; preds = %57
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [40960 x i8], [40960 x i8]* %7, i64 0, i64 %63
%65 = bitcast i8* %64 to %struct.inotify_event*
store %struct.inotify_event* %65, %struct.inotify_event** %11
%66 = load %struct.inotify_event*, %struct.inotify_event** %11
%67 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %66, i32 0, i32 0
%68 = load i32, i32* %67
%69 = load %struct.inotify_event*, %struct.inotify_event** %11
%70 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = load %struct.inotify_event*, %struct.inotify_event** %11
%73 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %72, i32 0, i32 2
%74 = load i32, i32* %73
%75 = load %struct.inotify_event*, %struct.inotify_event** %11
%76 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %75, i32 0, i32 3
%77 = load i32, i32* %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %68, i32 %71, i32 %74, i32 %77)
%79 = load %struct.inotify_event*, %struct.inotify_event** %11
%80 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %79, i32 0, i32 3
%81 = load i32, i32* %80
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %61
%84 = load %struct.inotify_event*, %struct.inotify_event** %11
%85 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %84, i32 0, i32 4
%86 = load i8*, i8** %85
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %86)
br label %88
88: ; preds = %83, %61
%89 = load %struct.inotify_event*, %struct.inotify_event** %11
%90 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %89, i32 0, i32 3
%91 = load i32, i32* %90
%92 = sext i32 %91 to i64
%93 = add i64 24, %92
%94 = load i32, i32* %9
%95 = sext i32 %94 to i64
%96 = add i64 %95, %93
%97 = trunc i64 %96 to i32
store i32 %97, i32* %9
br label %57
98: ; preds = %57
br label %99
99: ; preds = %98, %53
br label %100
100: ; preds = %99, %52
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"ERROR: inotify_init\0A\00"
@.str.1 = [35 x i8] c"/tmp/device/android-device-log.txt\00"
@IN_MODIFY = global i32 0
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@IN_ATTRIB = global i32 0
@IN_CLOSE_WRITE = global i32 0
@IN_ALL_EVENTS = global i32 0
@.str.2 = [26 x i8] c"ERROR: inotify_add_watch\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.3 = [29 x i8] c"need to reissue system call\0A\00"
@.str.4 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [40960 x i8]
%4 = getelementptr inbounds [40960 x i8], [40960 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @inotify_init()
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = load i32, i32* @IN_MODIFY
%12 = load i32, i32* @IN_CREATE
%13 = or i32 %12, %11
%14 = load i32, i32* @IN_DELETE
%15 = or i32 %13, %14
%16 = load i32, i32* @IN_ATTRIB
%17 = or i32 %15, %16
%18 = load i32, i32* @IN_CLOSE_WRITE
%19 = or i32 %17, %18
%20 = load i32, i32* @IN_ALL_EVENTS
%21 = or i32 %19, %20
%22 = tail call i32 @inotify_add_watch(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %10
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %24, %10
%28 = call i32 @read(i32 %5, i8* %4, i32 40960)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINTR
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %39
37: ; preds = %30
%38 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %39
39: ; preds = %27, %34, %37
ret i32 0
}