#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 {
  char *rlim_cur;
  char *rlim_max;
};

/* Variables and functions */
char *RLIM_INFINITY;
int /*<<< orphan*/ err_sys(char *, char *);
scalar_t__ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(int);
void pr_limits(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);
  }
  putchar((int)'\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    -0x20(%rbp),%rsi
call   1060 <getrlimit@plt>
cmp    $0x0,%rax
jge    1175 <pr_limits+0x35>
mov    -0x8(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x8(%rbp),%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    11ae <pr_limits+0x6e>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11c0 <pr_limits+0x80>
mov    -0x20(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%rax
jne    11e7 <pr_limits+0xa7>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f9 <pr_limits+0xb9>
mov    -0x18(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%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
jns    1168 <pr_limits+0x28>
lea    0xea0(%rip),%rdi
mov    %rbx,%rsi
call   1040 <err_sys@plt>
lea    0xea8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%rsi
mov    0x2e5c(%rip),%rbx
cmp    (%rbx),%rsi
je     1199 <pr_limits+0x59>
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a7 <pr_limits+0x67>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rsi
cmp    (%rbx),%rsi
je     11c1 <pr_limits+0x81>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11cf <pr_limits+0x8f>
lea    0xe55(%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 { i8*, i8* }
@.str = [23 x i8] c"getrlimit error for %s\00"
@.str.1 = [6 x i8] c"%-14s\00"
@RLIM_INFINITY = global i8* null
@.str.2 = [11 x i8] c"(infinite)\00"
@.str.3 = [6 x i8] c"%10ld\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 %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 ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = load i8*, i8** @RLIM_INFINITY
%18 = icmp eq i8* %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 %25
21: ; preds = %12
%22 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %19
%26 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 1
%27 = load i8*, i8** %26
%28 = load i8*, i8** @RLIM_INFINITY
%29 = icmp eq i8* %27, %28
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 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 1
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %32, %30
%37 = call i32 @putchar(i32 10)
ret void
}

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