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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setrlimit(int, struct rlimit *);
char *strerror(int /*<<< orphan*/);
void setlimit(int resource, rlim_t n) {
  struct rlimit limit;
  limit.rlim_cur = limit.rlim_max = n;
  if (setrlimit(resource, &limit) < 0) {
    printf("error %s\n", strerror(errno));
    error(NULL);
  } else {
  }
}


x86 assembly (clang, -O0):
<setlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
jge    1198 <setlimit+0x58>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <error@plt>
jmp    119d <setlimit+0x5d>
jmp    119d <setlimit+0x5d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setlimit>:
push   %rax
mov    %esi,(%rsp)
mov    %esi,0x4(%rsp)
mov    %rsp,%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
js     1157 <setlimit+0x17>
pop    %rax
ret
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe94(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <error@plt>
pop    %rax
ret

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

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