#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ setrlimit(int, struct rlimit *);
void set_limit(int res, int limit) {
  struct rlimit rlim;
  rlim.rlim_cur = rlim.rlim_max = limit;
  if (setrlimit(res, &rlim) != 0) {
    printf("limit %d fail", res);
    perror("Set limit fail");
    exit(3);
    ;
  }
}


x86 assembly (clang, -O0):
<set_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
je     1192 <set_limit+0x52>
mov    -0x4(%rbp),%esi
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_limit>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,0xc(%rsp)
mov    %esi,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
jne    1164 <set_limit+0x24>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe95(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
lea    0xe95(%rip),%rdi
call   1050 <perror@plt>
mov    $0x3,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@.str = [14 x i8] c"limit %d fail\00"
@.str.1 = [15 x i8] c"Set limit fail\00"
define void @set_limit(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 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
store i32 %6, i32* %8
%9 = load i32, i32* %3
%10 = call i64 @setrlimit(i32 %9, %struct.rlimit* %5)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* %3
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 3)
unreachable
17: ; preds = %2
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@.str = [14 x i8] c"limit %d fail\00"
@.str.1 = [15 x i8] c"Set limit fail\00"
define void @set_limit(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 1
store i32 %1, i32* %5
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i32 %1, i32* %6
%7 = call i64 @setrlimit(i32 %0, %struct.rlimit* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %0)
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 3)
unreachable
13: ; preds = %2
ret void
}