#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*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void pr_limits(char *name, int resource) {
  struct rlimit limit;
  unsigned long long lim;
  if (getrlimit(resource, &limit) != 0) {
    printf("getrlimit error for %s\n", name);
  }
  printf("%-14s ", name);
  if (limit.rlim_cur == RLIM_INFINITY) {
    printf("(infinity) ");
  } else {
    lim = limit.rlim_cur;
    printf("%10lld ", lim);
  }
  if (limit.rlim_max == RLIM_INFINITY) {
    printf("(infinity) ");
  } 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   1050 <getrlimit@plt>
cmp    $0x0,%rax
je     1167 <pr_limits+0x37>
mov    -0x8(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
jne    11a0 <pr_limits+0x70>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ba <pr_limits+0x8a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
jne    11e1 <pr_limits+0xb1>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fb <pr_limits+0xcb>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe37(%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   1050 <getrlimit@plt>
test   %rax,%rax
je     115a <pr_limits+0x2a>
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rsi
mov    0x2e6a(%rip),%rbx
cmp    (%rbx),%rsi
jne    118b <pr_limits+0x5b>
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1199 <pr_limits+0x69>
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
cmp    (%rbx),%rsi
jne    11b3 <pr_limits+0x83>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c1 <pr_limits+0x91>
lea    0xe71(%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 }
@.str = [24 x i8] c"getrlimit error for %s\0A\00"
@.str.1 = [7 x i8] c"%-14s \00"
@RLIM_INFINITY = global i64 0
@.str.2 = [12 x i8] c"(infinity) \00"
@.str.3 = [8 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 ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %2
%14 = load i8*, i8** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @RLIM_INFINITY
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %27
22: ; preds = %13
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 0
%24 = load i64, i64* %23
store i64 %24, i64* %6
%25 = load i64, i64* %6
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i64 %25)
br label %27
27: ; preds = %22, %20
%28 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 1
%29 = load i64, i64* %28
%30 = load i64, i64* @RLIM_INFINITY
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %39
34: ; preds = %27
%35 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i32 0, i32 1
%36 = load i64, i64* %35
store i64 %36, i64* %6
%37 = load i64, i64* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i64 %37)
br label %39
39: ; preds = %34, %32
%40 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@.str = [24 x i8] c"getrlimit error for %s\0A\00"
@.str.1 = [7 x i8] c"%-14s \00"
@RLIM_INFINITY = global i64 0
@.str.2 = [12 x i8] c"(infinity) \00"
@.str.3 = [8 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 eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 ([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 ([12 x i8], [12 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 ([12 x i8], [12 x i8]* @.str.2, 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(i8 signext 10)
ret void
}