#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 */
int /*<<< orphan*/ RLIMIT_CORE;
int /*<<< orphan*/ RLIMIT_NOFILE;
int RLIM_INFINITY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ stderr;
void set_rlimit() {
  struct rlimit rlim, rlim_new;
  if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
    rlim_new.rlim_cur = rlim_new.rlim_max = 100000;
    if (setrlimit(RLIMIT_NOFILE, &rlim_new) != 0) {
      fprintf(stderr, "set rlimit file failure\n");
      exit(0);
    }
  }
  if (getrlimit(RLIMIT_CORE, &rlim) == 0) {
    rlim_new.rlim_cur = rlim_new.rlim_max = RLIM_INFINITY;
    if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) {
      fprintf(stderr, "set rlimit core failure\n");
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<set_rlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <getrlimit@plt>
cmp    $0x0,%rax
jne    11af <set_rlimit+0x6f>
movl   $0x186a0,-0xc(%rbp)
movl   $0x186a0,-0x10(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
je     11aa <set_rlimit+0x6a>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    11af <set_rlimit+0x6f>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <getrlimit@plt>
cmp    $0x0,%rax
jne    1217 <set_rlimit+0xd7>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
je     1212 <set_rlimit+0xd2>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
jmp    1217 <set_rlimit+0xd7>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_rlimit>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e94(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1060 <getrlimit@plt>
test   %rax,%rax
jne    117a <set_rlimit+0x3a>
movabs $0x186a0000186a0,%rax
mov    %rax,(%rsp)
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
jne    11b7 <set_rlimit+0x77>
mov    0x2e67(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1060 <getrlimit@plt>
test   %rax,%rax
jne    11b1 <set_rlimit+0x71>
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
jne    11c9 <set_rlimit+0x89>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
jmp    11d9 <set_rlimit+0x99>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIMIT_NOFILE = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"set rlimit file failure\0A\00"
@RLIMIT_CORE = global i32 0
@RLIM_INFINITY = global i32 0
@.str.1 = [25 x i8] c"set rlimit core failure\0A\00"
define void @set_rlimit() {
%1 = alloca %struct.rlimit
%2 = alloca %struct.rlimit
%3 = load i32, i32* @RLIMIT_NOFILE
%4 = call i64 @getrlimit(i32 %3, %struct.rlimit* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %0
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
store i32 100000, i32* %7
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
store i32 100000, i32* %8
%9 = load i32, i32* @RLIMIT_NOFILE
%10 = call i64 @setrlimit(i32 %9, %struct.rlimit* %2)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %6
br label %17
17: ; preds = %16, %0
%18 = load i32, i32* @RLIMIT_CORE
%19 = call i64 @getrlimit(i32 %18, %struct.rlimit* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = load i32, i32* @RLIM_INFINITY
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
store i32 %22, i32* %24
%25 = load i32, i32* @RLIMIT_CORE
%26 = call i64 @setrlimit(i32 %25, %struct.rlimit* %2)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %21
br label %33
33: ; preds = %32, %17
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIMIT_NOFILE = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"set rlimit file failure\0A\00"
@RLIMIT_CORE = global i32 0
@RLIM_INFINITY = global i32 0
@.str.1 = [25 x i8] c"set rlimit core failure\0A\00"
define void @set_rlimit() {
%1 = alloca %struct.rlimit
%2 = alloca %struct.rlimit
%3 = bitcast %struct.rlimit* %1 to i8*
%4 = bitcast %struct.rlimit* %2 to i8*
%5 = load i32, i32* @RLIMIT_NOFILE
%6 = call i64 @getrlimit(i32 %5, %struct.rlimit* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %0
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
store i32 100000, i32* %9
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
store i32 100000, i32* %10
%11 = load i32, i32* @RLIMIT_NOFILE
%12 = call i64 @setrlimit(i32 %11, %struct.rlimit* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %8, %0
%19 = load i32, i32* @RLIMIT_CORE
%20 = call i64 @getrlimit(i32 %19, %struct.rlimit* %1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %33
22: ; preds = %18
%23 = load i32, i32* @RLIM_INFINITY
%24 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* @RLIMIT_CORE
%27 = call i64 @setrlimit(i32 %26, %struct.rlimit* %2)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %22, %18
ret void
}