#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 int64_t;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int main() {
  int i = 0;
  printf("malloc and write!\n");
  int64_t *buf = (int64_t *)malloc(640 * 1024 * 1024 * sizeof(int64_t));
  for (i = 0; i < 640 * 1024 * 1024; i++) {
    buf[i] = 0x0000000000000001;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
mov    $0xa0000000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x28000000,-0x8(%rbp)
jge    1181 <main+0x61>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1157 <main+0x37>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa0000000,%edi
call   1040 <malloc@plt>
mov    $0x3c,%ecx
movaps 0xebd(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movups %xmm0,-0xf0(%rax,%rcx,4)
ff
movups %xmm0,-0xe0(%rax,%rcx,4)
ff
movups %xmm0,-0xd0(%rax,%rcx,4)
ff
movups %xmm0,-0xc0(%rax,%rcx,4)
ff
movups %xmm0,-0xb0(%rax,%rcx,4)
ff
movups %xmm0,-0xa0(%rax,%rcx,4)
ff
movups %xmm0,-0x90(%rax,%rcx,4)
ff
movups %xmm0,-0x80(%rax,%rcx,4)
movups %xmm0,-0x70(%rax,%rcx,4)
movups %xmm0,-0x60(%rax,%rcx,4)
movups %xmm0,-0x50(%rax,%rcx,4)
movups %xmm0,-0x40(%rax,%rcx,4)
movups %xmm0,-0x30(%rax,%rcx,4)
movups %xmm0,-0x20(%rax,%rcx,4)
movups %xmm0,-0x10(%rax,%rcx,4)
movups %xmm0,(%rax,%rcx,4)
add    $0x40,%rcx
cmp    $0x2800003c,%rcx
jne    1150 <main+0x30>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"malloc and write!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @malloc(i32 -1610612736)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %3
store i32 0, i32* %2
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 671088640
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = load i32*, i32** %3
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %11, i64 %13
store i32 1, i32* %14
br label %15
15: ; preds = %10
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %7
18: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@str = [18 x i8] c"malloc and write!\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 @malloc(i32 -1610612736)
%3 = inttoptr i64 %2 to i32*
br label %4
4: ; preds = %4, %0
%5 = phi i64 [ 0, %0 ], [ %45, %4 ]
%6 = getelementptr inbounds i32, i32* %3, i64 %5
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %7
%8 = getelementptr inbounds i32, i32* %6, i64 4
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %9
%10 = or i64 %5, 8
%11 = getelementptr inbounds i32, i32* %3, i64 %10
%12 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %12
%13 = getelementptr inbounds i32, i32* %11, i64 4
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %14
%15 = or i64 %5, 16
%16 = getelementptr inbounds i32, i32* %3, i64 %15
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %17
%18 = getelementptr inbounds i32, i32* %16, i64 4
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %19
%20 = or i64 %5, 24
%21 = getelementptr inbounds i32, i32* %3, i64 %20
%22 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %22
%23 = getelementptr inbounds i32, i32* %21, i64 4
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %24
%25 = or i64 %5, 32
%26 = getelementptr inbounds i32, i32* %3, i64 %25
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %27
%28 = getelementptr inbounds i32, i32* %26, i64 4
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %29
%30 = or i64 %5, 40
%31 = getelementptr inbounds i32, i32* %3, i64 %30
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %32
%33 = getelementptr inbounds i32, i32* %31, i64 4
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %34
%35 = or i64 %5, 48
%36 = getelementptr inbounds i32, i32* %3, i64 %35
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %37
%38 = getelementptr inbounds i32, i32* %36, i64 4
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %39
%40 = or i64 %5, 56
%41 = getelementptr inbounds i32, i32* %3, i64 %40
%42 = bitcast i32* %41 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %42
%43 = getelementptr inbounds i32, i32* %41, i64 4
%44 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %44
%45 = add nuw nsw i64 %5, 64
%46 = icmp eq i64 %45, 671088640
br i1 %46, label %47, label %4
47: ; preds = %4
ret i32 0
}