#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 */
long atoi(char *);
int /*<<< orphan*/ exit(int);
int *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  size_t nbytes = atoi(argv[1]) * 1024l * 1024;
  int *a = malloc(nbytes);
  int i;
  if (a == NULL)
    exit(1);
  printf("Allocated %zu bytes at %p\n", nbytes, a);
  for (;;) {
    for (i = 0; i < nbytes / sizeof(int); i++)
      a[i] = i;
    printf("Looped\n");
  }
}


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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
shl    $0xa,%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <main+0x51>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
mov    -0x18(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
jae    11df <main+0x9f>
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ae <main+0x6e>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a7 <main+0x67>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %rax,%r14
mov    %rax,%r15
shl    $0x14,%r15
mov    %r15,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     1322 <main+0x1d2>
mov    %rax,%r12
lea    0xf07(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
shr    $0x2,%r15
cmp    $0x2,%r15
mov    $0x1,%ebx
cmovae %r15,%rbx
mov    %rbx,%r13
and    $0xfffffffffffc0000,%r13
lea    -0x8(%r13),%rbp
shr    $0x3,%rbp
mov    %r12,%rax
add    $0x70,%rax
mov    %rax,(%rsp)
add    $0x1,%rbp
lea    0xedc(%rip),%r15
movdqa 0xe39(%rip),%xmm3
movdqa 0xe41(%rip),%xmm4
movdqa 0xe49(%rip),%xmm5
movdqa 0xe51(%rip),%xmm6
movdqa 0xe59(%rip),%xmm7
movdqa 0xe60(%rip),%xmm8
movdqa 0xe67(%rip),%xmm9
movdqa 0xe6e(%rip),%xmm10
jmp    126b <main+0x11b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1030 <puts@plt>
movdqa 0xe4f(%rip),%xmm10
movdqa 0xe36(%rip),%xmm9
movdqa 0xe1d(%rip),%xmm8
movdqa 0xe05(%rip),%xmm7
movdqa 0xded(%rip),%xmm6
movdqa 0xdd5(%rip),%xmm5
movdqa 0xdbd(%rip),%xmm4
movdqa 0xda5(%rip),%xmm3
test   %r14,%r14
je     1220 <main+0xd0>
cmp    $0x8,%rbx
jae    1280 <main+0x130>
xor    %eax,%eax
jmp    1310 <main+0x1c0>
nopl   (%rax)
mov    %rbp,%rax
mov    (%rsp),%rcx
movdqa 0xd71(%rip),%xmm0
nop
movdqa %xmm0,%xmm1
paddd  %xmm3,%xmm1
movdqu %xmm0,-0x70(%rcx)
movdqu %xmm1,-0x60(%rcx)
movdqa %xmm0,%xmm1
paddd  %xmm4,%xmm1
movdqa %xmm0,%xmm2
paddd  %xmm5,%xmm2
movdqu %xmm1,-0x50(%rcx)
movdqu %xmm2,-0x40(%rcx)
movdqa %xmm0,%xmm1
paddd  %xmm6,%xmm1
movdqa %xmm0,%xmm2
paddd  %xmm7,%xmm2
movdqu %xmm1,-0x30(%rcx)
movdqu %xmm2,-0x20(%rcx)
movdqa %xmm0,%xmm1
paddd  %xmm8,%xmm1
movdqa %xmm0,%xmm2
paddd  %xmm9,%xmm2
movdqu %xmm1,-0x10(%rcx)
movdqu %xmm2,(%rcx)
paddd  %xmm10,%xmm0
sub    $0xffffffffffffff80,%rcx
add    $0xfffffffffffffffc,%rax
jne    1290 <main+0x140>
mov    %r13,%rax
cmp    %r13,%rbx
je     1220 <main+0xd0>
nopl   0x0(%rax)
mov    %eax,(%r12,%rax,4)
add    $0x1,%rax
cmp    %rax,%rbx
jne    1310 <main+0x1c0>
jmp    1220 <main+0xd0>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Allocated %zu bytes at %p\0A\00"
@.str.1 = [8 x i8] c"Looped\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%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 i64 @atoi(i8* %11)
%13 = mul nsw i64 %12, 1024
%14 = mul nsw i64 %13, 1024
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = call i32* @malloc(i64 %15)
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i64, i64* %6
%23 = load i32*, i32** %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %22, i32* %23)
br label %25
25: ; preds = %41, %21
store i32 0, i32* %8
br label %26
26: ; preds = %38, %25
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = load i64, i64* %6
%30 = udiv i64 %29, 4
%31 = icmp ult i64 %28, %30
br i1 %31, label %32, label %41
32: ; preds = %26
%33 = load i32, i32* %8
%34 = load i32*, i32** %7
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 %33, i32* %37
br label %38
38: ; preds = %32
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %26
41: ; preds = %26
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %25
}

LLVM IR (-O2):
@.str = [27 x i8] c"Allocated %zu bytes at %p\0A\00"
@str = [7 x i8] c"Looped\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 i64 @atoi(i8* %4)
%6 = shl nsw i64 %5, 20
%7 = tail call i32* @malloc(i64 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %6, i32* %7)
%13 = lshr exact i64 %6, 2
%14 = icmp eq i64 %5, 0
%15 = call i64 @llvm.umax.i64(i64 %13, i64 1)
%16 = and i64 %15, 4611686018427125760
%17 = add nsw i64 %16, -8
%18 = lshr exact i64 %17, 3
%19 = icmp ult i64 %15, 8
%20 = and i64 %15, 4611686018427125760
%21 = icmp eq i64 %15, %20
br label %22
22: ; preds = %68, %11
br i1 %14, label %68, label %23
23: ; preds = %22
br i1 %19, label %60, label %24
24: ; preds = %23, %24
%25 = phi i64 [ %54, %24 ], [ 0, %23 ]
%26 = phi <4 x i32> [ %55, %24 ], [ <i32 0, i32 1, i32 2, i32 3>, %23 ]
%27 = phi i64 [ %56, %24 ], [ 0, %23 ]
%28 = add <4 x i32> %26, <i32 4, i32 4, i32 4, i32 4>
%29 = getelementptr inbounds i32, i32* %7, i64 %25
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %30
%31 = getelementptr inbounds i32, i32* %29, i64 4
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %32
%33 = or i64 %25, 8
%34 = add <4 x i32> %26, <i32 8, i32 8, i32 8, i32 8>
%35 = add <4 x i32> %26, <i32 12, i32 12, i32 12, i32 12>
%36 = getelementptr inbounds i32, i32* %7, i64 %33
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> %34, <4 x i32>* %37
%38 = getelementptr inbounds i32, i32* %36, i64 4
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> %35, <4 x i32>* %39
%40 = or i64 %25, 16
%41 = add <4 x i32> %26, <i32 16, i32 16, i32 16, i32 16>
%42 = add <4 x i32> %26, <i32 20, i32 20, i32 20, i32 20>
%43 = getelementptr inbounds i32, i32* %7, i64 %40
%44 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> %41, <4 x i32>* %44
%45 = getelementptr inbounds i32, i32* %43, i64 4
%46 = bitcast i32* %45 to <4 x i32>*
store <4 x i32> %42, <4 x i32>* %46
%47 = or i64 %25, 24
%48 = add <4 x i32> %26, <i32 24, i32 24, i32 24, i32 24>
%49 = add <4 x i32> %26, <i32 28, i32 28, i32 28, i32 28>
%50 = getelementptr inbounds i32, i32* %7, i64 %47
%51 = bitcast i32* %50 to <4 x i32>*
store <4 x i32> %48, <4 x i32>* %51
%52 = getelementptr inbounds i32, i32* %50, i64 4
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> %49, <4 x i32>* %53
%54 = add nuw i64 %25, 32
%55 = add <4 x i32> %26, <i32 32, i32 32, i32 32, i32 32>
%56 = add i64 %27, 4
%57 = or i64 %27, 3
%58 = icmp eq i64 %57, %18
br i1 %58, label %59, label %24
59: ; preds = %24
br i1 %21, label %68, label %60
60: ; preds = %23, %59
%61 = phi i64 [ 0, %23 ], [ %20, %59 ]
br label %62
62: ; preds = %60, %62
%63 = phi i64 [ %66, %62 ], [ %61, %60 ]
%64 = getelementptr inbounds i32, i32* %7, i64 %63
%65 = trunc i64 %63 to i32
store i32 %65, i32* %64
%66 = add nuw nsw i64 %63, 1
%67 = icmp eq i64 %66, %15
br i1 %67, label %68, label %62
68: ; preds = %62, %59, %22
%69 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %22
}