#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 MAP_ANON;
char *MAP_FAILED;
int MAP_PRIVATE;
int /*<<< orphan*/ PROT_NONE;
int /*<<< orphan*/ RLIMIT_AS;
int getpagesize();
int /*<<< orphan*/ getrlimit(int /*<<< orphan*/, struct rlimit *);
char *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
void use_up_memory(void) {
  struct rlimit rl;
  getrlimit(RLIMIT_AS, &rl);
  rl.rlim_cur = 10 * 1024 * 1024;
  setrlimit(RLIMIT_AS, &rl);
  char *c;
  int PAGESIZE = getpagesize();
  while (1) {
    c = mmap(NULL, PAGESIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
    if (c == MAP_FAILED)
      break;
  }
}


x86 assembly (clang, -O0):
<use_up_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1060 <getrlimit@plt>
movl   $0xa00000,-0x8(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1040 <setrlimit@plt>
mov    $0x0,%al
call   1050 <getpagesize@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    0x2e40(%rip),%rax
mov    (%rax),%ecx
mov    0x2e2f(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%rax
jne    11ca <use_up_memory+0x8a>
jmp    11cf <use_up_memory+0x8f>
jmp    117d <use_up_memory+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<use_up_memory>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e84(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <getrlimit@plt>
movl   $0xa00000,0x8(%rsp)
mov    (%r14),%edi
mov    %rbx,%rsi
call   1040 <setrlimit@plt>
xor    %eax,%eax
call   1050 <getpagesize@plt>
mov    %eax,%ebx
mov    0x2e69(%rip),%r14
mov    0x2e42(%rip),%r15
mov    0x2e33(%rip),%r12
mov    0x2e24(%rip),%r13
nopl   0x0(%rax)
mov    (%r14),%edx
mov    (%r12),%ecx
or     (%r15),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
cmp    0x0(%r13),%rax
jne    11a0 <use_up_memory+0x60>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.rlimit = type { i32 }
@RLIMIT_AS = global i32 0
@PROT_NONE = global i32 0
@MAP_ANON = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
define void @use_up_memory() {
%1 = alloca %struct.rlimit
%2 = alloca i8*
%3 = alloca i32
%4 = load i32, i32* @RLIMIT_AS
%5 = call i32 @getrlimit(i32 %4, %struct.rlimit* %1)
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 10485760, i32* %6
%7 = load i32, i32* @RLIMIT_AS
%8 = call i32 @setrlimit(i32 %7, %struct.rlimit* %1)
%9 = call i32 (...) @getpagesize()
store i32 %9, i32* %3
br label %10
10: ; preds = %0, %21
%11 = load i32, i32* %3
%12 = load i32, i32* @PROT_NONE
%13 = load i32, i32* @MAP_ANON
%14 = load i32, i32* @MAP_PRIVATE
%15 = or i32 %13, %14
%16 = call i8* @mmap(i32* null, i32 %11, i32 %12, i32 %15, i32 -1, i32 0)
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = load i8*, i8** @MAP_FAILED
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %10
br label %22
21: ; preds = %10
br label %10
22: ; preds = %20
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32 }
@RLIMIT_AS = global i32 0
@PROT_NONE = global i32 0
@MAP_ANON = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
define void @use_up_memory() {
%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
store i32 10485760, i32* %5
%6 = load i32, i32* @RLIMIT_AS
%7 = call i32 @setrlimit(i32 %6, %struct.rlimit* %1)
%8 = call i32 (...) @getpagesize()
br label %9
9: ; preds = %9, %0
%10 = load i32, i32* @PROT_NONE
%11 = load i32, i32* @MAP_ANON
%12 = load i32, i32* @MAP_PRIVATE
%13 = or i32 %12, %11
%14 = call i8* @mmap(i32* null, i32 %8, i32 %10, i32 %13, i32 -1, i32 0)
%15 = load i8*, i8** @MAP_FAILED
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %9
17: ; preds = %9
ret void
}