#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 /*<<< orphan*/ RLIM_INFINITY;
int /*<<< orphan*/ err_sys(char *, char const *);
scalar_t__ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ printf(char *, ...);
void pr_limit(const char *name, int resource) {
  struct rlimit limit;
  if (getrlimit(resource, &limit) < 0) {
    err_sys("getrlimit error for %s", name);
  }
  printf("%-14s ", name);
  if (limit.rlim_cur == RLIM_INFINITY) {
    printf("(infinite) ");
  } else {
    printf("%10ld ", limit.rlim_cur);
  }
  if (limit.rlim_max == RLIM_INFINITY) {
    printf("(infinite) ");
  } else {
    printf("%10ld ", limit.rlim_max);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<pr_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <getrlimit@plt>
cmp    $0x0,%rax
jge    1165 <pr_limit+0x35>
mov    -0x8(%rbp),%rsi
lea    0xea0(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x8(%rbp),%rsi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%eax
jne    119c <pr_limit+0x6c>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ad <pr_limit+0x7d>
mov    -0x14(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%eax
jne    11d2 <pr_limit+0xa2>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e3 <pr_limit+0xb3>
mov    -0x18(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_limit>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%eax
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1060 <getrlimit@plt>
test   %rax,%rax
jns    116a <pr_limit+0x2a>
lea    0xe9e(%rip),%rdi
mov    %rbx,%rsi
call   1040 <err_sys@plt>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x2e5a(%rip),%rbx
cmp    (%rbx),%esi
jne    119a <pr_limit+0x5a>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a8 <pr_limit+0x68>
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
cmp    (%rbx),%esi
jne    11c0 <pr_limit+0x80>
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ce <pr_limit+0x8e>
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@.str = [23 x i8] c"getrlimit error for %s\00"
@.str.1 = [7 x i8] c"%-14s \00"
@RLIM_INFINITY = global i32 0
@.str.2 = [12 x i8] c"(infinite) \00"
@.str.3 = [7 x i8] c"%10ld \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @pr_limit(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.rlimit
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i64 @getrlimit(i32 %6, %struct.rlimit* %5)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @err_sys(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %9, %2
%13 = load i8*, i8** %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load i32, i32* @RLIM_INFINITY
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %25
21: ; preds = %12
%22 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 1
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %21, %19
%26 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i32, i32* @RLIM_INFINITY
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %36
32: ; preds = %25
%33 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32, %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@.str = [23 x i8] c"getrlimit error for %s\00"
@.str.1 = [7 x i8] c"%-14s \00"
@RLIM_INFINITY = global i32 0
@.str.2 = [12 x i8] c"(infinite) \00"
@.str.3 = [7 x i8] c"%10ld \00"
define void @pr_limit(i8* %0, i32 %1) {
%3 = alloca %struct.rlimit
%4 = bitcast %struct.rlimit* %3 to i8*
%5 = call i64 @getrlimit(i32 %1, %struct.rlimit* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @err_sys(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
%12 = load i32, i32* %11
%13 = load i32, i32* @RLIM_INFINITY
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %9
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %12)
br label %19
19: ; preds = %17, %15
%20 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* @RLIM_INFINITY
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %28
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %28
28: ; preds = %26, %24
%29 = call i32 @putchar(i32 10)
ret void
}