#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;
};

/* Variables and functions */
int _error(char *, int);
scalar_t__ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ setrlimit(int, struct rlimit *);
int main(void) {
  int ret = 0;
  int limits[] = {-1};
  size_t i;
  struct rlimit rl;
  for (i = 0; limits[i] != -1; i++) {
    if (getrlimit(limits[i], &rl) != 0) {
      ret |= _error("getrlimit", 2);
      continue;
    }
    printf("%d: %lld (%lld)\n", limits[i], rl.rlim_cur, rl.rlim_max);
    if (setrlimit(limits[i], &rl) != 0)
      ret |= _error("setrlimit", 3);
  }
  if (i == 0)
    ret = 4;
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0xea4(%rip),%eax
mov    %eax,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,-0xc(%rbp,%rax,4)
je     120f <main+0xcf>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp,%rax,4),%edi
lea    -0x20(%rbp),%rsi
call   1060 <getrlimit@plt>
cmp    $0x0,%rax
je     11ad <main+0x6d>
lea    0xe6c(%rip),%rdi
mov    $0x2,%esi
call   1040 <_error@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11fe <main+0xbe>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp,%rax,4),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp,%rax,4),%edi
lea    -0x20(%rbp),%rsi
call   1050 <setrlimit@plt>
cmp    $0x0,%rax
je     11f9 <main+0xb9>
lea    0xe36(%rip),%rdi
mov    $0x3,%esi
call   1040 <_error@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11fe <main+0xbe>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1167 <main+0x27>
cmpq   $0x0,-0x18(%rbp)
jne    1221 <main+0xe1>
movl   $0x4,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
mov    $0x4,%eax
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@__const.main.limits = [1 x i32] [i32 -1]
@.str = [10 x i8] c"getrlimit\00"
@.str.1 = [17 x i8] c"%d: %lld (%lld)\0A\00"
@.str.2 = [10 x i8] c"setrlimit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1 x i32]
%4 = alloca i64
%5 = alloca %struct.rlimit
store i32 0, i32* %1
store i32 0, i32* %2
%6 = bitcast [1 x i32]* %3 to i8*
store i64 0, i64* %4
br label %7
7: ; preds = %41, %0
%8 = load i64, i64* %4
%9 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 %8
%10 = load i32, i32* %9
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %44
12: ; preds = %7
%13 = load i64, i64* %4
%14 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = call i64 @getrlimit(i32 %15, %struct.rlimit* %5)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = call i32 @_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 2)
%20 = load i32, i32* %2
%21 = or i32 %20, %19
store i32 %21, i32* %2
br label %41
22: ; preds = %12
%23 = load i64, i64* %4
%24 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %27, i32 %29)
%31 = load i64, i64* %4
%32 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i64 @setrlimit(i32 %33, %struct.rlimit* %5)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %22
%37 = call i32 @_error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 3)
%38 = load i32, i32* %2
%39 = or i32 %38, %37
store i32 %39, i32* %2
br label %40
40: ; preds = %36, %22
br label %41
41: ; preds = %40, %18
%42 = load i64, i64* %4
%43 = add i64 %42, 1
store i64 %43, i64* %4
br label %7
44: ; preds = %7
%45 = load i64, i64* %4
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 4, i32* %2
br label %48
48: ; preds = %47, %44
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
define i32 @main() {
ret i32 4
}