#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 {
  scalar_t__ rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_AS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void getlimit(void) {
  struct rlimit info;
  if (getrlimit(RLIMIT_AS, &info) != 0) {
    fputs("failed to load Limits\n", stderr);
    fputs(strerror(errno), stderr);
  }
  printf("Limits of memory: %d\n", (long)info.rlim_max);
}


x86 assembly (clang, -O0):
<getlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <getrlimit@plt>
cmp    $0x0,%rax
je     1198 <getlimit+0x58>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    -0x8(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlimit>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <getrlimit@plt>
test   %rax,%rax
je     118a <getlimit+0x4a>
mov    0x2e7c(%rip),%rbx
mov    (%rbx),%esi
lea    0xe93(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    (%rbx),%esi
mov    %rax,%rdi
call   1040 <fputs@plt>
mov    0x8(%rsp),%rsi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rlimit = type { i64 }
@RLIMIT_AS = global i32 0
@.str = [23 x i8] c"failed to load Limits\0A\00"
@stderr = global i32 0
@errno = global i32 0
@.str.1 = [22 x i8] c"Limits of memory: %d\0A\00"
define void @getlimit() {
%1 = alloca %struct.rlimit
%2 = load i32, i32* @RLIMIT_AS
%3 = call i64 @getrlimit(i32 %2, %struct.rlimit* %1)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = load i32, i32* @stderr
%11 = call i32 @fputs(i8* %9, i32 %10)
br label %12
12: ; preds = %5, %0
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%14 = load i64, i64* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %14)
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i64 }
@RLIMIT_AS = global i32 0
@.str = [23 x i8] c"failed to load Limits\0A\00"
@stderr = global i32 0
@errno = global i32 0
@.str.1 = [22 x i8] c"Limits of memory: %d\0A\00"
define void @getlimit() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = load i32, i32* @RLIMIT_AS
%4 = call i64 @getrlimit(i32 %3, %struct.rlimit* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* %10, i32 %11)
br label %13
13: ; preds = %6, %0
%14 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%15 = load i64, i64* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %15)
ret void
}