#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 {
  scalar_t__ rlim_max;
  scalar_t__ rlim_cur;
};
typedef scalar_t__ rlim_t;
typedef int /*<<< orphan*/ intmax_t;

/* Variables and functions */
int /*<<< orphan*/ die(char *, char const *, int /*<<< orphan*/);
scalar_t__ setrlimit(int, struct rlimit *);
void setup_rlim(const char *res_name, int res, rlim_t limit) {
  struct rlimit rl = {.rlim_cur = limit, .rlim_max = limit};
  if (setrlimit(res, &rl) < 0)
    die("setrlimit(%s, %jd)", res_name, (intmax_t)limit);
}


x86 assembly (clang, -O0):
<setup_rlim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <setrlimit@plt>
cmp    $0x0,%rax
jge    116f <setup_rlim+0x4f>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xe96(%rip),%rdi
call   1040 <die@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_rlim>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %esi,%eax
mov    %rdi,%r14
mov    %rdx,0x8(%rsp)
mov    %rdx,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1030 <setrlimit@plt>
test   %rax,%rax
jns    115b <setup_rlim+0x3b>
lea    0xeaf(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <die@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@.str = [19 x i8] c"setrlimit(%s, %jd)\00"
define void @setup_rlim(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca %struct.rlimit
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 0
%9 = load i64, i64* %6
store i64 %9, i64* %8
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %7, i32 0, i32 1
%11 = load i64, i64* %6
store i64 %11, i64* %10
%12 = load i32, i32* %5
%13 = call i64 @setrlimit(i32 %12, %struct.rlimit* %7)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = load i64, i64* %6
%18 = trunc i64 %17 to i32
%19 = call i32 @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %18)
br label %20
20: ; preds = %15, %3
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@.str = [19 x i8] c"setrlimit(%s, %jd)\00"
define void @setup_rlim(i8* %0, i32 %1, i64 %2) {
%4 = alloca %struct.rlimit
%5 = bitcast %struct.rlimit* %4 to i8*
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 0
store i64 %2, i64* %6
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %4, i64 0, i32 1
store i64 %2, i64* %7
%8 = call i64 @setrlimit(i32 %1, %struct.rlimit* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = trunc i64 %2 to i32
%12 = call i32 @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %11)
br label %13
13: ; preds = %10, %3
ret void
}