#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 rlimit {
  int rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_NOFILE;
int /*<<< orphan*/ Warning(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int poll_get_max_fds(void) {
  struct rlimit lim;
  int res;
  res = getrlimit(RLIMIT_NOFILE, &lim);
  if (res) {
    Warning("POLL:"
            " getrlimit failed: %s\n",
            strerror(errno));
    return 4096;
  }
  return lim.rlim_cur;
}


x86 assembly (clang, -O0):
<poll_get_max_fds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1040 <getrlimit@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117f <poll_get_max_fds+0x4f>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe92(%rip),%rdi
call   1030 <Warning@plt>
movl   $0x1000,-0x4(%rbp)
jmp    1185 <poll_get_max_fds+0x55>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poll_get_max_fds>:
push   %rax
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <getrlimit@plt>
test   %eax,%eax
je     1169 <poll_get_max_fds+0x39>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xea5(%rip),%rdi
mov    %eax,%esi
call   1030 <Warning@plt>
mov    $0x1000,%eax
pop    %rcx
ret
mov    (%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.rlimit = type { i32 }
@RLIMIT_NOFILE = global i32 0
@.str = [28 x i8] c"POLL: getrlimit failed: %s\0A\00"
@errno = global i32 0
define i32 @poll_get_max_fds() {
%1 = alloca i32
%2 = alloca %struct.rlimit
%3 = alloca i32
%4 = load i32, i32* @RLIMIT_NOFILE
%5 = call i32 @getrlimit(i32 %4, %struct.rlimit* %2)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 @Warning(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 4096, i32* %1
br label %15
12: ; preds = %0
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %1
br label %15
15: ; preds = %12, %8
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
%struct.rlimit = type { i32 }
@RLIMIT_NOFILE = global i32 0
@.str = [28 x i8] c"POLL: getrlimit failed: %s\0A\00"
@errno = global i32 0
define i32 @poll_get_max_fds() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = load i32, i32* @RLIMIT_NOFILE
%4 = call i32 @getrlimit(i32 %3, %struct.rlimit* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 @Warning(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %13
10: ; preds = %0
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%12 = load i32, i32* %11
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ 4096, %6 ], [ %12, %10 ]
ret i32 %14
}