#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 /*<<< orphan*/ _exit(int);
int atoi(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *);
main(int argc, char *argv[]) {
  char *buf;
  int i, npages;
  npages = atoi(argv[1]);
  if (npages < 1) {
    printf("invalid argument\n");
    _exit(1);
  }
  buf = (char *)malloc((size_t)npages * (size_t)4096);
  if (buf == NULL) {
    printf("malloc failed\n");
    _exit(1);
  }
  while (1) {
    for (i = 0; i < npages; i++)
      buf[(i * (size_t)4096)] = '*';
  }
}


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    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jge    1186 <main+0x46>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
movslq -0x20(%rbp),%rdi
shl    $0xc,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b8 <main+0x78>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
jmp    11bd <main+0x7d>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11ee <main+0xae>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0xc,%rcx
movb   $0x2a,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c4 <main+0x84>
jmp    11bd <main+0x7d>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    1202 <main+0xc2>
mov    %eax,%ebx
mov    %rbx,%rdi
shl    $0xc,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     120b <main+0xcb>
lea    -0x1(%rbx),%r9
mov    %ebx,%edx
and    $0x3,%edx
and    $0xfffffffc,%ebx
lea    0x3000(%rax),%r8
mov    %rdx,%rdi
shl    $0xc,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x3,%r9
jae    11a0 <main+0x60>
xor    %esi,%esi
jmp    11d8 <main+0x98>
nopw   0x0(%rax,%rax,1)
mov    %r8,%rcx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x2a,-0x3000(%rcx)
movb   $0x2a,-0x2000(%rcx)
movb   $0x2a,-0x1000(%rcx)
movb   $0x2a,(%rcx)
add    $0x4,%rsi
add    $0x4000,%rcx
cmp    %rsi,%rbx
jne    11b0 <main+0x70>
test   %rdx,%rdx
je     1190 <main+0x50>
shl    $0xc,%rsi
add    %rax,%rsi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movb   $0x2a,(%rsi,%rcx,1)
add    $0x1000,%rcx
cmp    %rcx,%rdi
jne    11f0 <main+0xb0>
jmp    1190 <main+0x50>
lea    0xe05(%rip),%rdi
jmp    1212 <main+0xd2>
lea    0xdee(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"invalid argument\0A\00"
@.str.1 = [15 x i8] c"malloc failed\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @_exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4096
%22 = call i64 @malloc(i64 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @_exit(i32 1)
unreachable
29: ; preds = %18
br label %30
30: ; preds = %29, %44
store i32 0, i32* %7
br label %31
31: ; preds = %41, %30
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 4096
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 42, i8* %40
br label %41
41: ; preds = %35
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %31
44: ; preds = %31
br label %30
}

LLVM IR (-O2):
@str = [14 x i8] c"malloc failed\00"
@str.2 = [17 x i8] c"invalid argument\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.2, i64 0, i64 0))
%9 = tail call i32 @_exit(i32 1)
unreachable
10: ; preds = %2
%11 = zext i32 %5 to i64
%12 = shl nuw nsw i64 %11, 12
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = add nsw i64 %11, -1
%18 = and i64 %11, 3
%19 = icmp ult i64 %17, 3
%20 = and i64 %11, 4294967292
%21 = icmp eq i64 %18, 0
br label %36
22: ; preds = %10
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @_exit(i32 1)
unreachable
25: ; preds = %37, %36
%26 = phi i64 [ 0, %36 ], [ %51, %37 ]
br i1 %21, label %35, label %27
27: ; preds = %25, %27
%28 = phi i64 [ %32, %27 ], [ %26, %25 ]
%29 = phi i64 [ %33, %27 ], [ 0, %25 ]
%30 = shl nuw nsw i64 %28, 12
%31 = getelementptr inbounds i8, i8* %14, i64 %30
store i8 42, i8* %31
%32 = add nuw nsw i64 %28, 1
%33 = add i64 %29, 1
%34 = icmp eq i64 %33, %18
br i1 %34, label %35, label %27
35: ; preds = %27, %25
br label %36
36: ; preds = %16, %35
br i1 %19, label %25, label %37
37: ; preds = %36, %37
%38 = phi i64 [ %51, %37 ], [ 0, %36 ]
%39 = phi i64 [ %52, %37 ], [ 0, %36 ]
%40 = shl nuw nsw i64 %38, 12
%41 = getelementptr inbounds i8, i8* %14, i64 %40
store i8 42, i8* %41
%42 = shl i64 %38, 12
%43 = or i64 %42, 4096
%44 = getelementptr inbounds i8, i8* %14, i64 %43
store i8 42, i8* %44
%45 = shl i64 %38, 12
%46 = or i64 %45, 8192
%47 = getelementptr inbounds i8, i8* %14, i64 %46
store i8 42, i8* %47
%48 = shl i64 %38, 12
%49 = or i64 %48, 12288
%50 = getelementptr inbounds i8, i8* %14, i64 %49
store i8 42, i8* %50
%51 = add nuw nsw i64 %38, 4
%52 = add i64 %39, 4
%53 = icmp eq i64 %52, %20
br i1 %53, label %25, label %37
}