#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*/ memset(int *, char, int);
int /*<<< orphan*/ printf(char *);
int main() {
  int i = 0;
  printf("malloc, memset and write\n");
  int64_t *buf = (int64_t *)malloc(640 * 1024 * 1024 * sizeof(int64_t));
  memset(buf, '\0', 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    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    $0xa0000000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xa0000000,%edx
call   1040 <memset@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x28000000,-0x8(%rbp)
jge    11a1 <main+0x71>
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    1177 <main+0x47>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@.str = [26 x i8] c"malloc, memset 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 ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @malloc(i32 -1610612736)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = call i32 @memset(i32* %7, i8 signext 0, i32 -1610612736)
store i32 0, i32* %2
br label %9
9: ; preds = %17, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 671088640
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32*, i32** %3
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
store i32 1, i32* %16
br label %17
17: ; preds = %12
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %9
20: ; preds = %9
ret i32 0
}

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