#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;
};

/* Variables and functions */
scalar_t__ EINTR;
int EXIT_FAILURE;
int /*<<< orphan*/ daemonize();
scalar_t__ errno;
int /*<<< orphan*/ get_configfile_path();
int get_inotify_events(char *);
int /*<<< orphan*/ get_options(int, char **);
int /*<<< orphan*/ init_watches(int /*<<< orphan*/);
int /*<<< orphan*/ log_notice(char *);
int /*<<< orphan*/ parse_inotify_event(struct inotify_event *);
int main(int argc, char *argv[]) {
  get_options(argc, argv);
  daemonize();
  init_watches(get_configfile_path());
  char events[(1024 * ((sizeof(struct inotify_event)) + 16))];
  while (1) {
    int length = get_inotify_events(events);
    if (length < 0) {
      if (errno == EINTR) {
        log_notice("Inotify events read function was interrupted, probably OS "
                   "was going to suspend.");
        continue;
      }
      break;
    }
    for (int i = 0; i < length;
         i += (sizeof(struct inotify_event)) +
              ((struct inotify_event *)&events[i])->len) {
      parse_inotify_event((struct inotify_event *)&events[i]);
    }
  }
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x6020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <get_options@plt>
mov    $0x0,%al
call   1030 <daemonize@plt>
mov    $0x0,%al
call   1050 <get_configfile_path@plt>
mov    %eax,%edi
call   1040 <init_watches@plt>
lea    -0x6010(%rbp),%rdi
call   1070 <get_inotify_events@plt>
mov    %eax,-0x6014(%rbp)
cmpl   $0x0,-0x6014(%rbp)
jge    11f9 <main+0x89>
mov    0x2e10(%rip),%rax
mov    (%rax),%rax
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%rax
jne    11f4 <main+0x84>
lea    0xe16(%rip),%rdi
call   1090 <log_notice@plt>
jmp    11aa <main+0x3a>
jmp    1258 <main+0xe8>
movl   $0x0,-0x6018(%rbp)
mov    -0x6018(%rbp),%eax
cmp    -0x6014(%rbp),%eax
jge    1253 <main+0xe3>
movslq -0x6018(%rbp),%rax
lea    -0x6010(%rbp),%rdi
add    %rax,%rdi
call   1060 <parse_inotify_event@plt>
movslq -0x6018(%rbp),%rax
mov    -0x6010(%rbp,%rax,1),%rcx
ff
add    $0x8,%rcx
movslq -0x6018(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x6018(%rbp)
jmp    1203 <main+0x93>
jmp    11aa <main+0x3a>
mov    0x2d79(%rip),%rax
mov    (%rax),%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
call   1080 <get_options@plt>
xor    %eax,%eax
call   1030 <daemonize@plt>
xor    %eax,%eax
call   1050 <get_configfile_path@plt>
mov    %eax,%edi
call   1040 <init_watches@plt>
mov    %rsp,%r13
mov    0x2e3b(%rip),%r15
mov    0x2e24(%rip),%r12
lea    0xe4d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
call   1070 <get_inotify_events@plt>
test   %eax,%eax
js     1200 <main+0x90>
je     11c0 <main+0x50>
mov    %eax,%ebp
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %eax,%rbx
lea    (%rsp,%rbx,1),%rdi
call   1060 <parse_inotify_event@plt>
mov    (%rsp,%rbx,1),%eax
add    %ebx,%eax
add    $0x8,%eax
cmp    %ebp,%eax
jl     11e0 <main+0x70>
jmp    11c0 <main+0x50>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1213 <main+0xa3>
mov    %r14,%rdi
call   1090 <log_notice@plt>
jmp    11c0 <main+0x50>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
add    $0x6008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.inotify_event = type { i64 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [80 x i8] c"Inotify events read function was interrupted, probably OS was going to suspend.\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [24576 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @get_options(i32 %9, i8** %10)
%12 = call i32 (...) @daemonize()
%13 = call i32 (...) @get_configfile_path()
%14 = call i32 @init_watches(i32 %13)
br label %15
15: ; preds = %2, %24, %50
%16 = getelementptr inbounds [24576 x i8], [24576 x i8]* %6, i64 0, i64 0
%17 = call i32 @get_inotify_events(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i64, i64* @errno
%22 = load i64, i64* @EINTR
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @log_notice(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
br label %15
26: ; preds = %20
br label %51
27: ; preds = %15
store i32 0, i32* %8
br label %28
28: ; preds = %38, %27
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %50
32: ; preds = %28
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [24576 x i8], [24576 x i8]* %6, i64 0, i64 %34
%36 = bitcast i8* %35 to %struct.inotify_event*
%37 = call i32 @parse_inotify_event(%struct.inotify_event* %36)
br label %38
38: ; preds = %32
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [24576 x i8], [24576 x i8]* %6, i64 0, i64 %40
%42 = bitcast i8* %41 to %struct.inotify_event*
%43 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %42, i32 0, i32 0
%44 = load i64, i64* %43
%45 = add i64 8, %44
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = add i64 %47, %45
%49 = trunc i64 %48 to i32
store i32 %49, i32* %8
br label %28
50: ; preds = %28
br label %15
51: ; preds = %26
%52 = load i32, i32* @EXIT_FAILURE
ret i32 %52
}

LLVM IR (-O2):
%struct.inotify_event = type { i64 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [80 x i8] c"Inotify events read function was interrupted, probably OS was going to suspend.\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [24576 x i8]
%4 = tail call i32 @get_options(i32 %0, i8** %1)
%5 = tail call i32 (...) @daemonize()
%6 = tail call i32 (...) @get_configfile_path()
%7 = tail call i32 @init_watches(i32 %6)
%8 = getelementptr inbounds [24576 x i8], [24576 x i8]* %3, i64 0, i64 0
br label %9
9: ; preds = %14, %2
%10 = call i32 @get_inotify_events(i8* %8)
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = icmp eq i32 %10, 0
br i1 %13, label %14, label %21
14: ; preds = %21, %12, %19
br label %9
15: ; preds = %9
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = call i32 @log_notice(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
br label %14
21: ; preds = %12, %21
%22 = phi i32 [ %31, %21 ], [ 0, %12 ]
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [24576 x i8], [24576 x i8]* %3, i64 0, i64 %23
%25 = bitcast i8* %24 to %struct.inotify_event*
%26 = call i32 @parse_inotify_event(%struct.inotify_event* %25)
%27 = bitcast i8* %24 to i64*
%28 = load i64, i64* %27
%29 = trunc i64 %28 to i32
%30 = add i32 %22, 8
%31 = add i32 %30, %29
%32 = icmp slt i32 %31, %10
br i1 %32, label %21, label %14
33: ; preds = %15
%34 = load i32, i32* @EXIT_FAILURE
ret i32 %34
}