#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 {
  unsigned long long rlim_cur;
  unsigned long long rlim_max;
};

/* Variables and functions */
unsigned long long RLIM_INFINITY;
scalar_t__ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(int);
void pr_limits(char *name, int resource) {
  struct rlimit limit;
  unsigned long long lim;
  if (getrlimit(resource, &limit) < 0) {
    perror("getrlimit");
  }
  printf("%-17s ", name);
  if (limit.rlim_cur == RLIM_INFINITY) {
    printf("(infinite)");
  } else {
    lim = limit.rlim_cur;
    printf("%10lld ", lim);
  }
  if (limit.rlim_max == RLIM_INFINITY) {
    printf("  (infinite)");
  } else {
    lim = limit.rlim_max;
    printf("%10lld ", lim);
  }
  putchar((int)'\n');
}


x86 assembly (clang, -O0):
<pr_limits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <getrlimit@plt>
cmp    $0x0,%rax
jge    1171 <pr_limits+0x31>
lea    0xe94(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
jne    11aa <pr_limits+0x6a>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c4 <pr_limits+0x84>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
jne    11eb <pr_limits+0xab>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1205 <pr_limits+0xc5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_limits>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%eax
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    %eax,%edi
call   1060 <getrlimit@plt>
test   %rax,%rax
js     11d0 <pr_limits+0x90>
lea    0xeaa(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rsi
mov    0x2e6b(%rip),%rbx
cmp    (%rbx),%rsi
jne    118a <pr_limits+0x4a>
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1198 <pr_limits+0x58>
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
cmp    (%rbx),%rsi
jne    11b2 <pr_limits+0x72>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <pr_limits+0x80>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe29(%rip),%rdi
call   1050 <perror@plt>
jmp    1159 <pr_limits+0x19>

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

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