#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__ setrlimit(int, struct rlimit *);
int /*<<< orphan*/ writeResult(int, char *, int /*<<< orphan*/,
                               int /*<<< orphan*/, char *);
void setLimit(int resource, int limit) {
  struct rlimit lim;
  lim.rlim_cur = lim.rlim_max = limit;
  if (setrlimit(resource, &lim) != 0) {
    writeResult(-1, "Set limit Error", 0, 0, "null");
  }
}


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,-0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <setrlimit@plt>
cmp    $0x0,%rax
je     1169 <setLimit+0x49>
mov    $0xffffffff,%edi
lea    0xea7(%rip),%rsi
xor    %ecx,%ecx
lea    0xeae(%rip),%r8
mov    %ecx,%edx
call   1030 <writeResult@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setLimit>:
push   %rax
mov    %esi,0x4(%rsp)
mov    %esi,(%rsp)
mov    %rsp,%rsi
call   1040 <setrlimit@plt>
test   %rax,%rax
je     1151 <setLimit+0x31>
lea    0xec4(%rip),%rsi
lea    0xecd(%rip),%r8
mov    $0xffffffff,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <writeResult@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@.str = [16 x i8] c"Set limit Error\00"
@.str.1 = [5 x i8] c"null\00"
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 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 %14
12: ; preds = %2
%13 = call i32 @writeResult(i32 -1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@.str = [16 x i8] c"Set limit Error\00"
@.str.1 = [5 x i8] c"null\00"
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 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 %11, label %9
9: ; preds = %2
%10 = call i32 @writeResult(i32 -1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
ret void
}