#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 MAP_ANONYMOUS;
int MAP_PRIVATE;
int PROT_READ;
int PROT_WRITE;
int atoi(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ mmap(int /*<<< orphan*/, int, int, int, int /*<<< orphan*/,
                int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char *ptr;
  int size = -1;
  int loops = -1;
  if (argc > 1) {
    size = atoi(argv[1]);
  }
  if (argc > 2) {
    loops = atoi(argv[2]);
  }
  if (size <= 0) {
    printf("no size specified\n");
    return 0;
  }
  if (loops <= 0) {
    printf("no loops specified\n");
    return 0;
  }
  printf("Size: %dMB\n", size);
  printf("Loops: %d\n", loops);
  size *= 1024 * 1024;
  ptr = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
                     MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
  if (ptr) {
    for (; loops; --loops) {
      int i;
      for (i = 0; i < size; ++i) {
        *(ptr + i) = loops;
      }
      printf(".");
      fflush(stdout);
    }
    printf("\n");
    munmap(ptr, size);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    118e <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11a8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     11cc <main+0x7c>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ea <main+0x19a>
cmpl   $0x0,-0x20(%rbp)
jg     11f0 <main+0xa0>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ea <main+0x19a>
mov    -0x1c(%rbp),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
mov    0x2da2(%rip),%rax
or     (%rax),%edx
mov    0x2d89(%rip),%rax
mov    (%rax),%ecx
mov    0x2da0(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    %r9d,%edi
mov    %r9d,%r8d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12e3 <main+0x193>
jmp    1264 <main+0x114>
cmpl   $0x0,-0x20(%rbp)
je     12c9 <main+0x179>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    129f <main+0x14f>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1275 <main+0x125>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1264 <main+0x114>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <munmap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jl     128c <main+0x10c>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
cmp    $0x2,%ebp
jne    11b5 <main+0x35>
test   %r14d,%r14d
jg     1295 <main+0x115>
jmp    128c <main+0x10c>
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
test   %r14d,%r14d
jle    128c <main+0x10c>
mov    %eax,%ebp
test   %eax,%eax
jle    1295 <main+0x115>
lea    0xe28(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe23(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
shl    $0x14,%r14d
mov    0x2dfb(%rip),%rax
mov    0x2dcc(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2db1(%rip),%rax
mov    0x2dca(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
test   %rax,%rax
je     12a1 <main+0x121>
mov    %rax,%r15
cmp    $0x2,%r14d
mov    $0x1,%ebx
cmovge %r14d,%ebx
mov    0x2d82(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1070 <memset@plt>
mov    $0x2e,%edi
call   1030 <putchar@plt>
mov    (%r12),%edi
call   1080 <fflush@plt>
add    $0xffffffff,%ebp
jne    1250 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1090 <munmap@plt>
jmp    12a1 <main+0x121>
lea    0xd97(%rip),%rdi
jmp    129c <main+0x11c>
lea    0xd7b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"no size specified\0A\00"
@.str.1 = [20 x i8] c"no loops specified\0A\00"
@.str.2 = [12 x i8] c"Size: %dMB\0A\00"
@.str.3 = [11 x i8] c"Loops: %d\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.4 = [2 x i8] c".\00"
@stdout = global i32 0
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
store i32 -1, i32* %8
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
br label %17
17: ; preds = %12, %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 2
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %8
br label %25
25: ; preds = %20, %17
%26 = load i32, i32* %7
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %85
30: ; preds = %25
%31 = load i32, i32* %8
%32 = icmp sle i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %85
35: ; preds = %30
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %7
%41 = mul nsw i32 %40, 1048576
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = load i32, i32* @PROT_READ
%44 = load i32, i32* @PROT_WRITE
%45 = or i32 %43, %44
%46 = load i32, i32* @MAP_PRIVATE
%47 = load i32, i32* @MAP_ANONYMOUS
%48 = or i32 %46, %47
%49 = call i64 @mmap(i32 0, i32 %42, i32 %45, i32 %48, i32 0, i32 0)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %6
%51 = load i8*, i8** %6
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %84
53: ; preds = %35
br label %54
54: ; preds = %76, %53
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %79
57: ; preds = %54
store i32 0, i32* %9
br label %58
58: ; preds = %69, %57
%59 = load i32, i32* %9
%60 = load i32, i32* %7
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %72
62: ; preds = %58
%63 = load i32, i32* %8
%64 = trunc i32 %63 to i8
%65 = load i8*, i8** %6
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 %64, i8* %68
br label %69
69: ; preds = %62
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
store i32 %71, i32* %9
br label %58
72: ; preds = %58
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* @stdout
%75 = call i32 @fflush(i32 %74)
br label %76
76: ; preds = %72
%77 = load i32, i32* %8
%78 = add nsw i32 %77, -1
store i32 %78, i32* %8
br label %54
79: ; preds = %54
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%81 = load i8*, i8** %6
%82 = load i32, i32* %7
%83 = call i32 @munmap(i8* %81, i32 %82)
br label %84
84: ; preds = %79, %35
store i32 0, i32* %3
br label %85
85: ; preds = %84, %33, %28
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@.str.2 = [12 x i8] c"Size: %dMB\0A\00"
@.str.3 = [11 x i8] c"Loops: %d\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_ANONYMOUS = global i32 0
@stdout = global i32 0
@str = [19 x i8] c"no loops specified\00"
@str.6 = [18 x i8] c"no size specified\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp eq i32 %0, 2
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp slt i32 %7, 1
br i1 %13, label %16, label %18
14: ; preds = %4
%15 = icmp slt i32 %7, 1
br i1 %15, label %16, label %20
16: ; preds = %2, %14, %9
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
br label %49
18: ; preds = %9
%19 = icmp slt i32 %12, 1
br i1 %19, label %20, label %22
20: ; preds = %14, %18
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %49
22: ; preds = %18
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%25 = shl nsw i32 %7, 20
%26 = load i32, i32* @PROT_READ
%27 = load i32, i32* @PROT_WRITE
%28 = or i32 %27, %26
%29 = load i32, i32* @MAP_PRIVATE
%30 = load i32, i32* @MAP_ANONYMOUS
%31 = or i32 %30, %29
%32 = tail call i64 @mmap(i32 0, i32 %25, i32 %28, i32 %31, i32 0, i32 0)
%33 = inttoptr i64 %32 to i8*
%34 = icmp eq i64 %32, 0
br i1 %34, label %49, label %35
35: ; preds = %22
%36 = call i32 @llvm.smax.i32(i32 %25, i32 1)
%37 = zext i32 %36 to i64
br label %38
38: ; preds = %35, %38
%39 = phi i32 [ %44, %38 ], [ %12, %35 ]
%40 = trunc i32 %39 to i8
%41 = tail call i32 @putchar(i32 46)
%42 = load i32, i32* @stdout
%43 = tail call i32 @fflush(i32 %42)
%44 = add nsw i32 %39, -1
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %38
46: ; preds = %38
%47 = tail call i32 @putchar(i32 10)
%48 = tail call i32 @munmap(i8* %33, i32 %25)
br label %49
49: ; preds = %22, %46, %20, %16
ret i32 0
}