#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;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stderr;
void pr_limits(char *name, int resource) {
  struct rlimit limit;
  unsigned long long lim;
  if (getrlimit(resource, &limit) < 0)
    fprintf(stderr, "getrlimit error for %s", name);
  fprintf(stderr, "%-14s  ", name);
  if (limit.rlim_cur == RLIM_INFINITY) {
    fprintf(stderr, "(infinite)  ");
  } else {
    lim = limit.rlim_cur;
    fprintf(stderr, "%10lld  ", lim);
  }
  if (limit.rlim_max == RLIM_INFINITY) {
    fprintf(stderr, "(infinite)");
  } else {
    lim = limit.rlim_max;
    fprintf(stderr, "%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   1050 <getrlimit@plt>
cmp    $0x0,%rax
jge    1170 <pr_limits+0x40>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%rax
jne    11bb <pr_limits+0x8b>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11de <pr_limits+0xae>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    0x2def(%rip),%rcx
cmp    (%rcx),%rax
jne    120e <pr_limits+0xde>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1231 <pr_limits+0x101>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_limits>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%eax
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1050 <getrlimit@plt>
test   %rax,%rax
jns    1167 <pr_limits+0x37>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e72(%rip),%r14
mov    (%r14),%edi
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x8(%rsp),%rdx
mov    0x2e4a(%rip),%rbx
mov    (%r14),%edi
cmp    (%rbx),%rdx
jne    11a6 <pr_limits+0x76>
lea    0xe82(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11b4 <pr_limits+0x84>
lea    0xe7f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x10(%rsp),%rdx
mov    (%r14),%edi
cmp    (%rbx),%rdx
jne    11d1 <pr_limits+0xa1>
lea    0xe6d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11df <pr_limits+0xaf>
lea    0xe68(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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