#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 */
int /*<<< orphan*/ EXIT_FAILURE;
char *RLIM_INFINITY;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stderr;
void pr_limits(char *name, int resource) {
  struct rlimit limit;
  if (getrlimit(resource, &limit) < 0) {
    fprintf(stderr, "Err. getrlimit() %s\n", name);
    exit(EXIT_FAILURE);
  }
  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   1070 <getrlimit@plt>
cmp    $0x0,%rax
jge    119c <pr_limits+0x4c>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%rax
jne    11d5 <pr_limits+0x85>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e7 <pr_limits+0x97>
mov    -0x20(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%rax
jne    120e <pr_limits+0xbe>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1220 <pr_limits+0xd0>
mov    -0x18(%rbp),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <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   1070 <getrlimit@plt>
test   %rax,%rax
js     11e0 <pr_limits+0x90>
lea    0xea5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rsi
mov    0x2e4b(%rip),%rbx
cmp    (%rbx),%rsi
je     119a <pr_limits+0x4a>
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a8 <pr_limits+0x58>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
cmp    (%rbx),%rsi
je     11c2 <pr_limits+0x72>
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d0 <pr_limits+0x80>
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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

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