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


x86 assembly (clang, -O0):
<pr_limits>:
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    1161 <pr_limits+0x31>
lea    0xea4(%rip),%rdi
call   1040 <perror@plt>
mov    -0x8(%rbp),%rsi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%eax
jne    1198 <pr_limits+0x68>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a9 <pr_limits+0x79>
mov    -0x14(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%eax
jne    11ce <pr_limits+0x9e>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11df <pr_limits+0xaf>
mov    -0x18(%rbp),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_limits>:
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
js     11cf <pr_limits+0x8f>
lea    0xea8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x2e69(%rip),%rbx
cmp    (%rbx),%esi
jne    118b <pr_limits+0x4b>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1199 <pr_limits+0x59>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
cmp    (%rbx),%esi
jne    11b1 <pr_limits+0x71>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11bf <pr_limits+0x7f>
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe2a(%rip),%rdi
call   1050 <perror@plt>
jmp    115b <pr_limits+0x1b>

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