#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 */

/* Variables and functions */
int MCL_CURRENT;
int MCL_FUTURE;
int /*<<< orphan*/ M_MMAP_MAX;
int /*<<< orphan*/ M_TRIM_THRESHOLD;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ mallopt(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ mlockall(int);
int main(int argc, char *argv[]) {
  unsigned char *buffer;
  int i;
  if (!mlockall(MCL_CURRENT | MCL_FUTURE))
    mallopt(M_TRIM_THRESHOLD, -1UL);
  mallopt(M_MMAP_MAX, 0);
  buffer = malloc((100 * 1024 * 1024));
  if (!buffer)
    exit(-1);
  for (i = 0; i < (100 * 1024 * 1024); i += 4 * 1024)
    buffer[i] = 0;
  free(buffer);
  while (1)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e7a(%rip),%rax
or     (%rax),%edi
call   1060 <mlockall@plt>
cmp    $0x0,%eax
jne    119b <main+0x4b>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffffffffffff,%rsi
call   1040 <mallopt@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <mallopt@plt>
mov    $0x6400000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <main+0x80>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x6400000,-0x1c(%rbp)
jge    1200 <main+0xb0>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1000,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d7 <main+0x87>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1209 <main+0xb9>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e70(%rip),%rax
mov    0x2e91(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   1060 <mlockall@plt>
test   %eax,%eax
jne    1181 <main+0x31>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffffffffffff,%rsi
call   1040 <mallopt@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <mallopt@plt>
mov    $0x6400000,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1212 <main+0xc2>
mov    $0xfffffffffffff000,%rcx
nopw   0x0(%rax,%rax,1)
movb   $0x0,0x1000(%rax,%rcx,1)
movb   $0x0,0x2000(%rax,%rcx,1)
movb   $0x0,0x3000(%rax,%rcx,1)
movb   $0x0,0x4000(%rax,%rcx,1)
movb   $0x0,0x5000(%rax,%rcx,1)
movb   $0x0,0x6000(%rax,%rcx,1)
movb   $0x0,0x7000(%rax,%rcx,1)
movb   $0x0,0x8000(%rax,%rcx,1)
add    $0x8000,%rcx
cmp    $0x63ff000,%rcx
jb     11b0 <main+0x60>
mov    %rax,%rdi
call   1030 <free@plt>
nopl   0x0(%rax,%rax,1)
jmp    1210 <main+0xc0>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@M_TRIM_THRESHOLD = global i32 0
@M_MMAP_MAX = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @MCL_CURRENT
%9 = load i32, i32* @MCL_FUTURE
%10 = or i32 %8, %9
%11 = call i32 @mlockall(i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32, i32* @M_TRIM_THRESHOLD
%15 = call i32 @mallopt(i32 %14, i64 -1)
br label %16
16: ; preds = %13, %2
%17 = load i32, i32* @M_MMAP_MAX
%18 = call i32 @mallopt(i32 %17, i64 0)
%19 = call i8* @malloc(i32 104857600)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %16
store i32 0, i32* %7
br label %25
25: ; preds = %33, %24
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 104857600
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %28
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 4096
store i32 %35, i32* %7
br label %25
36: ; preds = %25
%37 = load i8*, i8** %6
%38 = call i32 @free(i8* %37)
br label %39
39: ; preds = %36, %39
br label %39
}

LLVM IR (-O2):
@MCL_CURRENT = global i32 0
@MCL_FUTURE = global i32 0
@M_TRIM_THRESHOLD = global i32 0
@M_MMAP_MAX = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @MCL_CURRENT
%4 = load i32, i32* @MCL_FUTURE
%5 = or i32 %4, %3
%6 = tail call i32 @mlockall(i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @M_TRIM_THRESHOLD
%10 = tail call i32 @mallopt(i32 %9, i64 -1)
br label %11
11: ; preds = %8, %2
%12 = load i32, i32* @M_MMAP_MAX
%13 = tail call i32 @mallopt(i32 %12, i64 0)
%14 = tail call dereferenceable_or_null(104857600) i8* @malloc(i32 104857600)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %11, %18
%19 = phi i64 [ %35, %18 ], [ 0, %11 ]
%20 = getelementptr inbounds i8, i8* %14, i64 %19
store i8 0, i8* %20
%21 = or i64 %19, 4096
%22 = getelementptr inbounds i8, i8* %14, i64 %21
store i8 0, i8* %22
%23 = or i64 %19, 8192
%24 = getelementptr inbounds i8, i8* %14, i64 %23
store i8 0, i8* %24
%25 = or i64 %19, 12288
%26 = getelementptr inbounds i8, i8* %14, i64 %25
store i8 0, i8* %26
%27 = or i64 %19, 16384
%28 = getelementptr inbounds i8, i8* %14, i64 %27
store i8 0, i8* %28
%29 = or i64 %19, 20480
%30 = getelementptr inbounds i8, i8* %14, i64 %29
store i8 0, i8* %30
%31 = or i64 %19, 24576
%32 = getelementptr inbounds i8, i8* %14, i64 %31
store i8 0, i8* %32
%33 = or i64 %19, 28672
%34 = getelementptr inbounds i8, i8* %14, i64 %33
store i8 0, i8* %34
%35 = add nuw nsw i64 %19, 32768
%36 = icmp ult i64 %33, 104853504
br i1 %36, label %18, label %37
37: ; preds = %18
%38 = tail call i32 @free(i8* %14)
br label %39
39: ; preds = %39, %37
br label %39
}