#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 {
  int /*<<< orphan*/ rlim_max;
  int /*<<< orphan*/ rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getrlimit(int, struct rlimit *);
int /*<<< orphan*/ printf(char *, char const *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void do_limit(int limit, const char *limit_string, struct rlimit *rlim) {
  if (getrlimit(limit, rlim))
    fprintf(stderr, "Failed in getrlimit\n");
  printf("%15s=%2d: cur=%20lu,     max=%20lu\n", limit_string, limit,
         rlim->rlim_cur, rlim->rlim_max);
}


x86 assembly (clang, -O0):
<do_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <getrlimit@plt>
cmp    $0x0,%rax
je     116e <do_limit+0x3e>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x4(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8d
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_limit>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rdx,%rsi
call   1050 <getrlimit@plt>
test   %rax,%rax
je     115e <do_limit+0x2e>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%r8d
mov    0x4(%rbx),%ecx
lea    0xeaa(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Failed in getrlimit\0A\00"
@.str.1 = [36 x i8] c"%15s=%2d: cur=%20lu, max=%20lu\0A\00"
define void @do_limit(i32 %0, i8* %1, %struct.rlimit* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.rlimit*
store i32 %0, i32* %4
store i8* %1, i8** %5
store %struct.rlimit* %2, %struct.rlimit** %6
%7 = load i32, i32* %4
%8 = load %struct.rlimit*, %struct.rlimit** %6
%9 = call i64 @getrlimit(i32 %7, %struct.rlimit* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %3
%15 = load i8*, i8** %5
%16 = load i32, i32* %4
%17 = load %struct.rlimit*, %struct.rlimit** %6
%18 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load %struct.rlimit*, %struct.rlimit** %6
%21 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %16, i32 %19, i32 %22)
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Failed in getrlimit\0A\00"
@.str.1 = [36 x i8] c"%15s=%2d: cur=%20lu, max=%20lu\0A\00"
define void @do_limit(i32 %0, i8* %1, %struct.rlimit* %2) {
%4 = tail call i64 @getrlimit(i32 %0, %struct.rlimit* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %6, %3
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %0, i32 %11, i32 %13)
ret void
}