#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 mntent {
  int /*<<< orphan*/ mnt_dir;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
scalar_t__ endmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fanotify_init(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct mntent *getmntent(int /*<<< orphan*/ *);
int /*<<< orphan*/ mark(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ pr_error(char *);
int /*<<< orphan*/ *setmntent(char *, char *);
int /*<<< orphan*/ stderr;
int fnotify_event_init(void) {
  int fan_fd, count = 0;
  FILE *mounts;
  struct mntent *mount;
  if ((fan_fd = fanotify_init(0, 0)) < 0)
    pr_error("cannot initialize fanotify");
  if ((mounts = setmntent("/proc/self/mounts", "r")) == NULL) {
    (void)close(fan_fd);
    pr_error("setmntent cannot get mount points from /proc/self/mounts");
  }
  while ((mount = getmntent(mounts)) != NULL)
    (void)mark(fan_fd, mount->mnt_dir, &count);
  if (endmntent(mounts) < 0) {
    (void)close(fan_fd);
    pr_error("endmntent failed");
  }
  if (!count) {
    (void)fprintf(stderr, "no mount points could be monitored\n");
    (void)close(fan_fd);
    exit(EXIT_FAILURE);
  }
  return fan_fd;
}


x86 assembly (clang, -O0):
<fnotify_event_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1050 <fanotify_init@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11c0 <fnotify_event_init+0x30>
lea    0xe45(%rip),%rdi
call   1030 <pr_error@plt>
lea    0xe7d(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   10a0 <setmntent@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11f5 <fnotify_event_init+0x65>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
lea    0xe2d(%rip),%rdi
call   1030 <pr_error@plt>
jmp    11fa <fnotify_event_init+0x6a>
mov    -0x10(%rbp),%rdi
call   1090 <getmntent@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1228 <fnotify_event_init+0x98>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1080 <mark@plt>
jmp    11fa <fnotify_event_init+0x6a>
mov    -0x10(%rbp),%rdi
call   1040 <endmntent@plt>
cmp    $0x0,%rax
jge    124f <fnotify_event_init+0xbf>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
lea    0xe0c(%rip),%rdi
call   1030 <pr_error@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1284 <fnotify_event_init+0xf4>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnotify_event_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
xor    %edi,%edi
xor    %esi,%esi
call   1050 <fanotify_init@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    11bc <fnotify_event_init+0x2c>
lea    0xe49(%rip),%rdi
call   1030 <pr_error@plt>
lea    0xe81(%rip),%rdi
lea    0xe51(%rip),%rsi
call   10a0 <setmntent@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11eb <fnotify_event_init+0x5b>
mov    %r14d,%edi
call   1060 <close@plt>
lea    0xe37(%rip),%rdi
call   1030 <pr_error@plt>
mov    %rbx,%rdi
call   1090 <getmntent@plt>
test   %rax,%rax
je     121a <fnotify_event_init+0x8a>
lea    0xc(%rsp),%rbp
nopl   (%rax)
mov    (%rax),%esi
mov    %r14d,%edi
mov    %rbp,%rdx
call   1080 <mark@plt>
mov    %rbx,%rdi
call   1090 <getmntent@plt>
test   %rax,%rax
jne    1200 <fnotify_event_init+0x70>
mov    %rbx,%rdi
call   1040 <endmntent@plt>
test   %rax,%rax
jns    123b <fnotify_event_init+0xab>
mov    %r14d,%edi
call   1060 <close@plt>
lea    0xe20(%rip),%rdi
call   1030 <pr_error@plt>
cmpl   $0x0,0xc(%rsp)
je     124e <fnotify_event_init+0xbe>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.mntent = type { i32 }
@.str = [27 x i8] c"cannot initialize fanotify\00"
@.str.1 = [18 x i8] c"/proc/self/mounts\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [57 x i8] c"setmntent cannot get mount points from /proc/self/mounts\00"
@.str.4 = [17 x i8] c"endmntent failed\00"
@stderr = global i32 0
@.str.5 = [36 x i8] c"no mount points could be monitored\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @fnotify_event_init() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.mntent*
store i32 0, i32* %2
%5 = call i32 @fanotify_init(i32 0, i32 0)
store i32 %5, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @pr_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32* @setmntent(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* %1
%14 = call i32 @close(i32 %13)
%15 = call i32 @pr_error(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %12, %9
br label %17
17: ; preds = %21, %16
%18 = load i32*, i32** %3
%19 = call %struct.mntent* @getmntent(i32* %18)
store %struct.mntent* %19, %struct.mntent** %4
%20 = icmp ne %struct.mntent* %19, null
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* %1
%23 = load %struct.mntent*, %struct.mntent** %4
%24 = getelementptr inbounds %struct.mntent, %struct.mntent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @mark(i32 %22, i32 %25, i32* %2)
br label %17
27: ; preds = %17
%28 = load i32*, i32** %3
%29 = call i64 @endmntent(i32* %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* %1
%33 = call i32 @close(i32 %32)
%34 = call i32 @pr_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %31, %27
%36 = load i32, i32* %2
%37 = icmp ne i32 %36, 0
br i1 %37, label %45, label %38
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* %1
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %35
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
%struct.mntent = type { i32 }
@.str = [27 x i8] c"cannot initialize fanotify\00"
@.str.1 = [18 x i8] c"/proc/self/mounts\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [57 x i8] c"setmntent cannot get mount points from /proc/self/mounts\00"
@.str.4 = [17 x i8] c"endmntent failed\00"
@stderr = global i32 0
@.str.5 = [36 x i8] c"no mount points could be monitored\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @fnotify_event_init() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @fanotify_init(i32 0, i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @pr_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i32* @setmntent(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @close(i32 %3)
%12 = tail call i32 @pr_error(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %10, %7
%14 = call %struct.mntent* @getmntent(i32* %8)
%15 = icmp eq %struct.mntent* %14, null
br i1 %15, label %23, label %16
16: ; preds = %13, %16
%17 = phi %struct.mntent* [ %21, %16 ], [ %14, %13 ]
%18 = getelementptr inbounds %struct.mntent, %struct.mntent* %17, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @mark(i32 %3, i32 %19, i32* %1)
%21 = call %struct.mntent* @getmntent(i32* %8)
%22 = icmp eq %struct.mntent* %21, null
br i1 %22, label %23, label %16
23: ; preds = %16, %13
%24 = call i64 @endmntent(i32* %8)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @close(i32 %3)
%28 = call i32 @pr_error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %1
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @close(i32 %3)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %29
ret i32 %3
}