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

/* Variables and functions */
scalar_t__ EPERM;
int /*<<< orphan*/ RLIMIT_AS;
int /*<<< orphan*/ RLIMIT_CORE;
int /*<<< orphan*/ RLIMIT_FSIZE;
int /*<<< orphan*/ RLIMIT_NOFILE;
void *RLIM_INFINITY;
int /*<<< orphan*/ _SC_OPEN_MAX;
int /*<<< orphan*/ err_exit(char *);
scalar_t__ errno;
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int sysconf(int /*<<< orphan*/);
void _setrlimit(void) {
  struct rlimit r, r2;
  r.rlim_cur = r.rlim_max = RLIM_INFINITY;
  if (setrlimit(RLIMIT_FSIZE, &r) < 0)
    err_exit("setrlimit RLIMIT_FSIZE");
  r.rlim_cur = r.rlim_max = 1048576;
  r2.rlim_cur = r2.rlim_max = sysconf(_SC_OPEN_MAX);
  if (setrlimit(RLIMIT_NOFILE, &r) < 0)
    if (errno != EPERM || setrlimit(RLIMIT_NOFILE, &r2) < 0)
      err_exit("setrlimit RLIMIT_NOFILE");
  r.rlim_cur = r.rlim_max = RLIM_INFINITY;
  r.rlim_cur = r.rlim_max = RLIM_INFINITY;
  if (setrlimit(RLIMIT_CORE, &r) < 0)
    err_exit("setrlimit RLIMIT_CORE");
  r.rlim_cur = r.rlim_max = RLIM_INFINITY;
  if (setrlimit(RLIMIT_AS, &r) < 0)
    err_exit("setrlimit RLIMIT_AS");
}


x86 assembly (clang, -O0):
<_setrlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
mov    %eax,-0x8(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
jge    1170 <_setrlimit+0x40>
lea    0xe95(%rip),%rdi
call   1030 <err_exit@plt>
movl   $0x100000,-0x4(%rbp)
movl   $0x100000,-0x8(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
jge    11f5 <_setrlimit+0xc5>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    0x2de9(%rip),%rcx
cmp    (%rcx),%rax
jne    11e4 <_setrlimit+0xb4>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
jge    11f0 <_setrlimit+0xc0>
lea    0xe2c(%rip),%rdi
call   1030 <err_exit@plt>
jmp    11f5 <_setrlimit+0xc5>
mov    0x2dbc(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
mov    %eax,-0x8(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
mov    %eax,-0x8(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
jge    123d <_setrlimit+0x10d>
lea    0xdf7(%rip),%rdi
call   1030 <err_exit@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
mov    %eax,-0x8(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
jge    1275 <_setrlimit+0x145>
lea    0xdd5(%rip),%rdi
call   1030 <err_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_setrlimit>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e7a(%rip),%r14
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    %eax,0x8(%rsp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
jns    116d <_setrlimit+0x3d>
lea    0xe98(%rip),%rdi
call   1030 <err_exit@plt>
movabs $0x10000000100000,%rax
mov    %rax,0x8(%rsp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
mov    %eax,0x14(%rsp)
mov    %eax,0x10(%rsp)
mov    0x2e47(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
jns    11dd <_setrlimit+0xad>
mov    0x2e17(%rip),%rax
mov    (%rax),%rax
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%rax
jne    11d1 <_setrlimit+0xa1>
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
jns    11dd <_setrlimit+0xad>
lea    0xe3f(%rip),%rdi
call   1030 <err_exit@plt>
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    %eax,0x8(%rsp)
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
jns    120c <_setrlimit+0xdc>
lea    0xe28(%rip),%rdi
call   1030 <err_exit@plt>
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    %eax,0x8(%rsp)
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
jns    123b <_setrlimit+0x10b>
lea    0xe0f(%rip),%rdi
call   1030 <err_exit@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIM_INFINITY = global i8* null
@RLIMIT_FSIZE = global i32 0
@.str = [23 x i8] c"setrlimit RLIMIT_FSIZE\00"
@_SC_OPEN_MAX = global i32 0
@RLIMIT_NOFILE = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@.str.1 = [24 x i8] c"setrlimit RLIMIT_NOFILE\00"
@RLIMIT_CORE = global i32 0
@.str.2 = [22 x i8] c"setrlimit RLIMIT_CORE\00"
@RLIMIT_AS = global i32 0
@.str.3 = [20 x i8] c"setrlimit RLIMIT_AS\00"
define void @_setrlimit() {
%1 = alloca %struct.rlimit
%2 = alloca %struct.rlimit
%3 = load i8*, i8** @RLIM_INFINITY
%4 = ptrtoint i8* %3 to i32
%5 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 %4, i32* %5
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 %4, i32* %6
%7 = load i32, i32* @RLIMIT_FSIZE
%8 = call i64 @setrlimit(i32 %7, %struct.rlimit* %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @err_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 1048576, i32* %13
%14 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 1048576, i32* %14
%15 = load i32, i32* @_SC_OPEN_MAX
%16 = call i32 @sysconf(i32 %15)
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i32, i32* @RLIMIT_NOFILE
%20 = call i64 @setrlimit(i32 %19, %struct.rlimit* %1)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %12
%23 = load i64, i64* @errno
%24 = load i64, i64* @EPERM
%25 = icmp ne i64 %23, %24
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i32, i32* @RLIMIT_NOFILE
%28 = call i64 @setrlimit(i32 %27, %struct.rlimit* %2)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26, %22
%31 = call i32 @err_exit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
br label %33
33: ; preds = %32, %12
%34 = load i8*, i8** @RLIM_INFINITY
%35 = ptrtoint i8* %34 to i32
%36 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 %35, i32* %36
%37 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i8*, i8** @RLIM_INFINITY
%39 = ptrtoint i8* %38 to i32
%40 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 %39, i32* %40
%41 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 %39, i32* %41
%42 = load i32, i32* @RLIMIT_CORE
%43 = call i64 @setrlimit(i32 %42, %struct.rlimit* %1)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %33
%46 = call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %33
%48 = load i8*, i8** @RLIM_INFINITY
%49 = ptrtoint i8* %48 to i32
%50 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 %49, i32* %50
%51 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 %49, i32* %51
%52 = load i32, i32* @RLIMIT_AS
%53 = call i64 @setrlimit(i32 %52, %struct.rlimit* %1)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %47
%56 = call i32 @err_exit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55, %47
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIM_INFINITY = global i8* null
@RLIMIT_FSIZE = global i32 0
@.str = [23 x i8] c"setrlimit RLIMIT_FSIZE\00"
@_SC_OPEN_MAX = global i32 0
@RLIMIT_NOFILE = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@.str.1 = [24 x i8] c"setrlimit RLIMIT_NOFILE\00"
@RLIMIT_CORE = global i32 0
@.str.2 = [22 x i8] c"setrlimit RLIMIT_CORE\00"
@RLIMIT_AS = global i32 0
@.str.3 = [20 x i8] c"setrlimit RLIMIT_AS\00"
define void @_setrlimit() {
%1 = alloca %struct.rlimit
%2 = alloca %struct.rlimit
%3 = bitcast %struct.rlimit* %1 to i8*
%4 = bitcast %struct.rlimit* %2 to i8*
%5 = load i8*, i8** @RLIM_INFINITY
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
store i32 %7, i32* %9
%10 = load i32, i32* @RLIMIT_FSIZE
%11 = call i64 @setrlimit(i32 %10, %struct.rlimit* %1)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @err_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
store i32 1048576, i32* %8
store i32 1048576, i32* %9
%16 = load i32, i32* @_SC_OPEN_MAX
%17 = call i32 @sysconf(i32 %16)
%18 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
store i32 %17, i32* %19
%20 = load i32, i32* @RLIMIT_NOFILE
%21 = call i64 @setrlimit(i32 %20, %struct.rlimit* %1)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %15
%24 = load i64, i64* @errno
%25 = load i64, i64* @EPERM
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @RLIMIT_NOFILE
%29 = call i64 @setrlimit(i32 %28, %struct.rlimit* %2)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27, %23
%32 = call i32 @err_exit(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %27, %31, %15
%34 = load i8*, i8** @RLIM_INFINITY
%35 = ptrtoint i8* %34 to i64
%36 = trunc i64 %35 to i32
store i32 %36, i32* %8
store i32 %36, i32* %9
%37 = load i32, i32* @RLIMIT_CORE
%38 = call i64 @setrlimit(i32 %37, %struct.rlimit* %1)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 @err_exit(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %33
%43 = load i8*, i8** @RLIM_INFINITY
%44 = ptrtoint i8* %43 to i64
%45 = trunc i64 %44 to i32
store i32 %45, i32* %8
store i32 %45, i32* %9
%46 = load i32, i32* @RLIMIT_AS
%47 = call i64 @setrlimit(i32 %46, %struct.rlimit* %1)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %42
%50 = call i32 @err_exit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %42
ret void
}