#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 *, char *);
scalar_t__ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
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);
  }
  printf("%-14s  ", 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('\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    117e <pr_limits+0x3e>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe87(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%rax
jne    11b7 <pr_limits+0x77>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d1 <pr_limits+0x91>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%rax
jne    11f8 <pr_limits+0xb8>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1212 <pr_limits+0xd2>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe35(%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
jns    1171 <pr_limits+0x31>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rsi
mov    0x2e4b(%rip),%rbx
cmp    (%rbx),%rsi
jne    11a2 <pr_limits+0x62>
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b0 <pr_limits+0x70>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
cmp    (%rbx),%rsi
jne    11ca <pr_limits+0x8a>
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d8 <pr_limits+0x98>
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbx
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 @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 i8*, i8** %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%18 = load i64, i64* %17
%19 = load i64, i64* @RLIM_INFINITY
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %28
23: ; preds = %14
%24 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%25 = load i64, i64* %24
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %23, %21
%29 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 1
%30 = load i64, i64* %29
%31 = load i64, i64* @RLIM_INFINITY
%32 = icmp eq i64 %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 %40
35: ; preds = %28
%36 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 1
%37 = load i64, i64* %36
store i64 %37, i64* %6
%38 = load i64, i64* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %38)
br label %40
40: ; preds = %35, %33
%41 = call i32 @putchar(i8 signext 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 @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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* @RLIM_INFINITY
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %20
18: ; preds = %10
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %13)
br label %20
20: ; preds = %18, %16
%21 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
%22 = load i64, i64* %21
%23 = load i64, i64* @RLIM_INFINITY
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %29
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %22)
br label %29
29: ; preds = %27, %25
%30 = call i32 @putchar(i8 signext 10)
ret void
}