#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 rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_AS;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getrlimit(int /*<<< orphan*/, struct rlimit *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
int main() {
  struct rlimit rl;
  getrlimit(RLIMIT_AS, &rl);
  printf("\n Default value is : %lld\n", (long long int)rl.rlim_cur);
  rl.rlim_cur = 100;
  setrlimit(RLIMIT_AS, &rl);
  getrlimit(RLIMIT_AS, &rl);
  printf("\n Default value now is : %lld\n", (long long int)rl.rlim_cur);
  char *ptr = NULL;
  ptr = (char *)malloc(1024);
  if (NULL == ptr) {
    printf("\n Memory allocation failed\n");
    return -1;
  }
  free(ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1070 <getrlimit@plt>
movslq -0x8(%rbp),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x64,-0x8(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <setrlimit@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1070 <getrlimit@plt>
movslq -0x8(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x10(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11fc <main+0xac>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <main+0xbc>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e71(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <getrlimit@plt>
movslq 0x8(%rsp),%rsi
lea    0xe75(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x64,0x8(%rsp)
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   1070 <setrlimit@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   1080 <getrlimit@plt>
movslq 0x8(%rsp),%rsi
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x400,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11df <main+0x7f>
mov    %rax,%rdi
call   1030 <free@plt>
jmp    11f1 <main+0x91>
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i32 }
@RLIMIT_AS = global i32 0
@.str = [27 x i8] c"\0A Default value is : %lld\0A\00"
@.str.1 = [31 x i8] c"\0A Default value now is : %lld\0A\00"
@.str.2 = [28 x i8] c"\0A Memory allocation failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rlimit
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @RLIMIT_AS
%5 = call i32 @getrlimit(i32 %4, %struct.rlimit* %2)
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%7 = load i32, i32* %6
%8 = sext i32 %7 to i64
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
store i32 100, i32* %10
%11 = load i32, i32* @RLIMIT_AS
%12 = call i32 @setrlimit(i32 %11, %struct.rlimit* %2)
%13 = load i32, i32* @RLIMIT_AS
%14 = call i32 @getrlimit(i32 %13, %struct.rlimit* %2)
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i64 %17)
store i8* null, i8** %3
%19 = call i64 @malloc(i32 1024)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = icmp eq i8* null, %21
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %28
25: ; preds = %0
%26 = load i8*, i8** %3
%27 = call i32 @free(i8* %26)
store i32 0, i32* %1
br label %28
28: ; preds = %25, %23
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
%struct.rlimit = type { i32 }
@RLIMIT_AS = global i32 0
@.str = [27 x i8] c"\0A Default value is : %lld\0A\00"
@.str.1 = [31 x i8] c"\0A Default value now is : %lld\0A\00"
@str = [27 x i8] c"\0A Memory allocation failed\00"
define i32 @main() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = load i32, i32* @RLIMIT_AS
%4 = call i32 @getrlimit(i32 %3, %struct.rlimit* %1)
%5 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = sext i32 %6 to i64
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %7)
store i32 100, i32* %5
%9 = load i32, i32* @RLIMIT_AS
%10 = call i32 @setrlimit(i32 %9, %struct.rlimit* %1)
%11 = load i32, i32* @RLIMIT_AS
%12 = call i32 @getrlimit(i32 %11, %struct.rlimit* %1)
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i64 %14)
%16 = call i64 @malloc(i32 1024)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %23
20: ; preds = %0
%21 = inttoptr i64 %16 to i8*
%22 = call i32 @free(i8* %21)
br label %23
23: ; preds = %20, %18
%24 = phi i32 [ -1, %18 ], [ 0, %20 ]
ret i32 %24
}