#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 int /*<<< orphan*/ res;

/* Variables and functions */
#define RLIMIT_CPU 131
#define RLIMIT_DATA 130
#define RLIMIT_FSIZE 129
#define RLIMIT_NPROC 128
scalar_t__ RLIM_INFINITY;
int /*<<< orphan*/ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ setrlimit(int, struct rlimit *);
void removeLimits() {
  static int res[] = {RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE, RLIMIT_NPROC};
  for (unsigned i = 0; i < sizeof(res) / sizeof(int); i++) {
    struct rlimit rl;
    getrlimit(res[i], &rl);
    if (rl.rlim_max < RLIM_INFINITY) {
      rl.rlim_max = RLIM_INFINITY;
      setrlimit(res[i], &rl);
      getrlimit(res[i], &rl);
    }
    if (rl.rlim_cur < rl.rlim_max) {
      rl.rlim_cur = rl.rlim_max;
      setrlimit(res[i], &rl);
    }
  }
}


x86 assembly (clang, -O0):
<removeLimits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    $0x4,%rax
jae    11e7 <removeLimits+0xc7>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
lea    0x2ef8(%rip),%rax
mov    (%rax,%rcx,4),%edi
lea    -0x18(%rbp),%rsi
call   1040 <getrlimit@plt>
mov    -0x18(%rbp),%rax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%rax
jge    11a6 <removeLimits+0x86>
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
lea    0x2ebe(%rip),%rax
mov    (%rax,%rcx,4),%edi
lea    -0x18(%rbp),%rsi
call   1030 <setrlimit@plt>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
lea    0x2ea6(%rip),%rax
mov    (%rax,%rcx,4),%edi
lea    -0x18(%rbp),%rsi
call   1040 <getrlimit@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11d4 <removeLimits+0xb4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
lea    0x2e78(%rip),%rax
mov    (%rax,%rcx,4),%edi
lea    -0x18(%rbp),%rsi
call   1030 <setrlimit@plt>
jmp    11d9 <removeLimits+0xb9>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112f <removeLimits+0xf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeLimits>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
mov    $0x83,%edi
call   1040 <getrlimit@plt>
mov    0x8(%rsp),%rax
mov    0x2e9e(%rip),%r14
mov    (%r14),%rcx
cmp    %rcx,%rax
jge    1173 <removeLimits+0x53>
mov    %rcx,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    $0x83,%edi
mov    %rbx,%rsi
call   1030 <setrlimit@plt>
mov    $0x83,%edi
mov    %rbx,%rsi
call   1040 <getrlimit@plt>
mov    0x8(%rsp),%rax
cmp    %rax,0x10(%rsp)
jge    118e <removeLimits+0x6e>
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x83,%edi
call   1030 <setrlimit@plt>
lea    0x8(%rsp),%rsi
mov    $0x82,%edi
call   1040 <getrlimit@plt>
mov    0x8(%rsp),%rax
mov    (%r14),%rcx
cmp    %rcx,%rax
jge    11d3 <removeLimits+0xb3>
mov    %rcx,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    $0x82,%edi
mov    %rbx,%rsi
call   1030 <setrlimit@plt>
mov    $0x82,%edi
mov    %rbx,%rsi
call   1040 <getrlimit@plt>
mov    0x8(%rsp),%rax
cmp    %rax,0x10(%rsp)
jge    11ee <removeLimits+0xce>
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x82,%edi
call   1030 <setrlimit@plt>
lea    0x8(%rsp),%rsi
mov    $0x81,%edi
call   1040 <getrlimit@plt>
mov    0x8(%rsp),%rax
mov    (%r14),%rcx
cmp    %rcx,%rax
jge    1233 <removeLimits+0x113>
mov    %rcx,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    $0x81,%edi
mov    %rbx,%rsi
call   1030 <setrlimit@plt>
mov    $0x81,%edi
mov    %rbx,%rsi
call   1040 <getrlimit@plt>
mov    0x8(%rsp),%rax
cmp    %rax,0x10(%rsp)
jge    124e <removeLimits+0x12e>
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x81,%edi
call   1030 <setrlimit@plt>
lea    0x8(%rsp),%rsi
mov    $0x80,%edi
call   1040 <getrlimit@plt>
mov    0x8(%rsp),%rax
mov    (%r14),%rcx
cmp    %rcx,%rax
jge    1293 <removeLimits+0x173>
mov    %rcx,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    $0x80,%edi
mov    %rbx,%rsi
call   1030 <setrlimit@plt>
mov    $0x80,%edi
mov    %rbx,%rsi
call   1040 <getrlimit@plt>
mov    0x8(%rsp),%rax
cmp    %rax,0x10(%rsp)
jge    12ae <removeLimits+0x18e>
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x80,%edi
call   1030 <setrlimit@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@removeLimits.res = internal global [4 x i32] [i32 131, i32 130, i32 129, i32 128]
@RLIM_INFINITY = global i64 0
define void @removeLimits() {
%1 = alloca i32
%2 = alloca %struct.rlimit
store i32 0, i32* %1
br label %3
3: ; preds = %46, %0
%4 = load i32, i32* %1
%5 = zext i32 %4 to i64
%6 = icmp ult i64 %5, 4
br i1 %6, label %7, label %49
7: ; preds = %3
%8 = load i32, i32* %1
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [4 x i32], [4 x i32]* @removeLimits.res, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = call i32 @getrlimit(i32 %11, %struct.rlimit* %2)
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @RLIM_INFINITY
%16 = icmp slt i64 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %7
%18 = load i64, i64* @RLIM_INFINITY
%19 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
store i64 %18, i64* %19
%20 = load i32, i32* %1
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [4 x i32], [4 x i32]* @removeLimits.res, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @setrlimit(i32 %23, %struct.rlimit* %2)
%25 = load i32, i32* %1
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [4 x i32], [4 x i32]* @removeLimits.res, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 @getrlimit(i32 %28, %struct.rlimit* %2)
br label %30
30: ; preds = %17, %7
%31 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
%32 = load i64, i64* %31
%33 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%34 = load i64, i64* %33
%35 = icmp slt i64 %32, %34
br i1 %35, label %36, label %45
36: ; preds = %30
%37 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
store i64 %38, i64* %39
%40 = load i32, i32* %1
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds [4 x i32], [4 x i32]* @removeLimits.res, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = call i32 @setrlimit(i32 %43, %struct.rlimit* %2)
br label %45
45: ; preds = %36, %30
br label %46
46: ; preds = %45
%47 = load i32, i32* %1
%48 = add i32 %47, 1
store i32 %48, i32* %1
br label %3
49: ; preds = %3
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@RLIM_INFINITY = global i64 0
define void @removeLimits() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%4 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
%5 = call i32 @getrlimit(i32 131, %struct.rlimit* %1)
%6 = load i64, i64* %3
%7 = load i64, i64* @RLIM_INFINITY
%8 = icmp slt i64 %6, %7
br i1 %8, label %9, label %13
9: ; preds = %0
store i64 %7, i64* %3
%10 = call i32 @setrlimit(i32 131, %struct.rlimit* %1)
%11 = call i32 @getrlimit(i32 131, %struct.rlimit* %1)
%12 = load i64, i64* %3
br label %13
13: ; preds = %9, %0
%14 = phi i64 [ %12, %9 ], [ %6, %0 ]
%15 = load i64, i64* %4
%16 = icmp slt i64 %15, %14
br i1 %16, label %17, label %19
17: ; preds = %13
store i64 %14, i64* %4
%18 = call i32 @setrlimit(i32 131, %struct.rlimit* %1)
br label %19
19: ; preds = %17, %13
%20 = call i32 @getrlimit(i32 130, %struct.rlimit* %1)
%21 = load i64, i64* %3
%22 = load i64, i64* @RLIM_INFINITY
%23 = icmp slt i64 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %19
store i64 %22, i64* %3
%25 = call i32 @setrlimit(i32 130, %struct.rlimit* %1)
%26 = call i32 @getrlimit(i32 130, %struct.rlimit* %1)
%27 = load i64, i64* %3
br label %28
28: ; preds = %24, %19
%29 = phi i64 [ %27, %24 ], [ %21, %19 ]
%30 = load i64, i64* %4
%31 = icmp slt i64 %30, %29
br i1 %31, label %32, label %34
32: ; preds = %28
store i64 %29, i64* %4
%33 = call i32 @setrlimit(i32 130, %struct.rlimit* %1)
br label %34
34: ; preds = %32, %28
%35 = call i32 @getrlimit(i32 129, %struct.rlimit* %1)
%36 = load i64, i64* %3
%37 = load i64, i64* @RLIM_INFINITY
%38 = icmp slt i64 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %34
store i64 %37, i64* %3
%40 = call i32 @setrlimit(i32 129, %struct.rlimit* %1)
%41 = call i32 @getrlimit(i32 129, %struct.rlimit* %1)
%42 = load i64, i64* %3
br label %43
43: ; preds = %39, %34
%44 = phi i64 [ %42, %39 ], [ %36, %34 ]
%45 = load i64, i64* %4
%46 = icmp slt i64 %45, %44
br i1 %46, label %47, label %49
47: ; preds = %43
store i64 %44, i64* %4
%48 = call i32 @setrlimit(i32 129, %struct.rlimit* %1)
br label %49
49: ; preds = %47, %43
%50 = call i32 @getrlimit(i32 128, %struct.rlimit* %1)
%51 = load i64, i64* %3
%52 = load i64, i64* @RLIM_INFINITY
%53 = icmp slt i64 %51, %52
br i1 %53, label %54, label %58
54: ; preds = %49
store i64 %52, i64* %3
%55 = call i32 @setrlimit(i32 128, %struct.rlimit* %1)
%56 = call i32 @getrlimit(i32 128, %struct.rlimit* %1)
%57 = load i64, i64* %3
br label %58
58: ; preds = %54, %49
%59 = phi i64 [ %57, %54 ], [ %51, %49 ]
%60 = load i64, i64* %4
%61 = icmp slt i64 %60, %59
br i1 %61, label %62, label %64
62: ; preds = %58
store i64 %59, i64* %4
%63 = call i32 @setrlimit(i32 128, %struct.rlimit* %1)
br label %64
64: ; preds = %62, %58
ret void
}