#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read(int, char *, int);
int grab_max_element_count(void) {
  int fd;
  char buf[64] = {0};
  fd = open("/proc/sys/fs/inotify/max_user_watches", O_RDONLY);
  if (fd >= 0) {
    read(fd, buf, 64);
  } else {
    perror("open()");
    exit(EXIT_FAILURE);
  }
  return atoi(buf);
}


x86 assembly (clang, -O0):
<grab_max_element_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     11b0 <grab_max_element_count+0x50>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1040 <read@plt>
jmp    11ca <grab_max_element_count+0x6a>
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x50(%rbp),%rdi
call   1070 <atoi@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grab_max_element_count>:
push   %rbx
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1040 <open@plt>
test   %eax,%eax
js     11a4 <grab_max_element_count+0x54>
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1030 <read@plt>
mov    %rbx,%rdi
call   1060 <atoi@plt>
add    $0x40,%rsp
pop    %rbx
ret
lea    0xe7b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"/proc/sys/fs/inotify/max_user_watches\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@EXIT_FAILURE = global i32 0
define i32 @grab_max_element_count() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = bitcast [64 x i8]* %2 to i8*
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* %1
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 64)
br label %16
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%18 = call i32 @atoi(i8* %17)
ret i32 %18
}

LLVM IR (-O2):
@.str = [38 x i8] c"/proc/sys/fs/inotify/max_user_watches\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@EXIT_FAILURE = global i32 0
define i32 @grab_max_element_count() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @read(i32 %4, i8* %2, i32 64)
%8 = call i32 @atoi(i8* %2)
ret i32 %8
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
}