#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ abort();
long atoi(int /*<<< orphan*/);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
scalar_t__ malloc(long);
int /*<<< orphan*/ optarg;
int main(int argc, char *argv[]) {
  long bufsize = 1024 * 1024;
  long loops = 0;
  int opt;
  while ((opt = getopt(argc, argv, "M:")) != -1) {
    switch (opt) {
    case 'M':
      loops = atoi(optarg);
      break;
    default:
      errx(EXIT_FAILURE, "Usage: %s [-M MEGA]", argv[0]);
    }
  }
  if (loops == 0) {
    errx(EXIT_FAILURE, "Usage: %s [-M MEGA]", argv[0]);
  }
  for (int i = 0; i < loops; ++i) {
    uint8_t *buf = (uint8_t *)malloc(bufsize * sizeof(uint8_t));
    if (buf == NULL) {
      err(EXIT_FAILURE, "malloc");
    }
  }
  abort();
  exit(EXIT_FAILURE);
}


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)
movq   $0x100000,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     11ee <main+0x8e>
mov    -0x24(%rbp),%eax
sub    $0x4d,%eax
jne    11cd <main+0x6d>
jmp    11b6 <main+0x56>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %rax,-0x20(%rbp)
jmp    11e9 <main+0x89>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1f(%rip),%rsi
call   1040 <errx@plt>
jmp    1186 <main+0x26>
cmpq   $0x0,-0x20(%rbp)
jne    1215 <main+0xb5>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf3(%rip),%rsi
call   1040 <errx@plt>
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    126e <main+0x10e>
mov    -0x18(%rbp),%rdi
shl    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125b <main+0xfb>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
call   1050 <err@plt>
jmp    1260 <main+0x100>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    121c <main+0xbc>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe86(%rip),%r15
mov    0x2e57(%rip),%r13
lea    0xe7b(%rip),%r12
jmp    11a0 <main+0x40>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %rax,%r14
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
cmp    $0x4d,%eax
je     118a <main+0x2a>
cmp    $0xffffffff,%eax
je     11c8 <main+0x68>
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
mov    %r12,%rsi
call   1040 <errx@plt>
jmp    11a0 <main+0x40>
test   %r14,%r14
jne    11e7 <main+0x87>
mov    0x0(%r13),%edi
mov    (%rbx),%rdx
lea    0xe28(%rip),%rsi
call   1040 <errx@plt>
xor    %eax,%eax
call   1030 <abort@plt>
jle    1223 <main+0xc3>
lea    0xe27(%rip),%rbx
jmp    1206 <main+0xa6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffffffffffff,%r14
je     1223 <main+0xc3>
mov    $0x400000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
jne    1200 <main+0xa0>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
call   1050 <err@plt>
jmp    1200 <main+0xa0>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"M:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"Usage: %s [-M MEGA]\00"
@.str.2 = [7 x i8] c"malloc\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1048576, i64* %6
store i64 0, i64* %7
br label %11
11: ; preds = %27, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %8
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i32, i32* %8
switch i32 %17, label %21 [
i32 77, label %18
]
18: ; preds = %16
%19 = load i32, i32* @optarg
%20 = call i64 @atoi(i32 %19)
store i64 %20, i64* %7
br label %27
21: ; preds = %16
%22 = load i32, i32* @EXIT_FAILURE
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @errx(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %21, %18
br label %11
28: ; preds = %11
%29 = load i64, i64* %7
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i32, i32* @EXIT_FAILURE
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @errx(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %31, %28
store i32 0, i32* %9
br label %38
38: ; preds = %54, %37
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = load i64, i64* %7
%42 = icmp slt i64 %40, %41
br i1 %42, label %43, label %57
43: ; preds = %38
%44 = load i64, i64* %6
%45 = mul i64 %44, 4
%46 = call i64 @malloc(i64 %45)
%47 = inttoptr i64 %46 to i32*
store i32* %47, i32** %10
%48 = load i32*, i32** %10
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @err(i32 %51, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %50, %43
br label %54
54: ; preds = %53
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %38
57: ; preds = %38
%58 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"M:\00"
@optarg = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"Usage: %s [-M MEGA]\00"
@.str.2 = [7 x i8] c"malloc\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %7, %2
%4 = phi i64 [ %9, %7 ], [ 0, %2 ]
br label %5
5: ; preds = %3, %10
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %10 [
i32 -1, label %14
i32 77, label %7
]
7: ; preds = %5
%8 = load i32, i32* @optarg
%9 = tail call i64 @atoi(i32 %8)
br label %3
10: ; preds = %5
%11 = load i32, i32* @EXIT_FAILURE
%12 = load i8*, i8** %1
%13 = tail call i32 @errx(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %5
14: ; preds = %5
%15 = icmp eq i64 %4, 0
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = load i32, i32* @EXIT_FAILURE
%18 = load i8*, i8** %1
%19 = tail call i32 @errx(i32 %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %22
20: ; preds = %14
%21 = icmp sgt i64 %4, 0
br i1 %21, label %24, label %22
22: ; preds = %31, %16, %20
%23 = tail call i32 (...) @abort()
unreachable
24: ; preds = %20, %31
%25 = phi i64 [ %32, %31 ], [ 0, %20 ]
%26 = tail call i64 @malloc(i64 4194304)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @err(i32 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %28, %24
%32 = add nuw nsw i64 %25, 1
%33 = icmp eq i64 %32, %4
br i1 %33, label %22, label %24
}