#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char **, int);
int open(char *, char *);
int /*<<< orphan*/ read(int, char **, int);
int main(int argc, char *argv[]) {
  int i = 0, randfp;
  char buffer[1024 * 1024];
  char *x;
  randfp = open("/dev/urandom", "r");
  for (; i < 100; i++) {
    x = malloc(1024 * 1024);
    read(randfp, &buffer, 1024 * 1024);
    memcpy(x, &buffer, 1024 * 1024);
  }
  x = "crashme :-)";
  free(x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11db <main+0x8b>
mov    $0x100000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x100028(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x100020(%rbp),%rsi
mov    $0x100000,%edx
call   1040 <read@plt>
mov    -0x100028(%rbp),%rdi
lea    -0x100020(%rbp),%rsi
mov    $0x100000,%edx
call   1050 <memcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1186 <main+0x36>
lea    0xe2d(%rip),%rax
mov    %rax,-0x100028(%rbp)
mov    -0x100028(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x100030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x100008,%rsp
lea    0xe9c(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <open@plt>
mov    %eax,%r14d
mov    $0x64,%ebx
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    $0x100000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x100000,%edx
call   1040 <read@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x100000,%edx
call   1050 <memcpy@plt>
add    $0xffffffff,%ebx
jne    1180 <main+0x30>
lea    0xe56(%rip),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x100008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"crashme :-)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1048576 x i8]
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %7
br label %11
11: ; preds = %22, %2
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 100
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = call i8* @malloc(i32 1048576)
store i8* %15, i8** %9
%16 = load i32, i32* %7
%17 = bitcast [1048576 x i8]* %8 to i8**
%18 = call i32 @read(i32 %16, i8** %17, i32 1048576)
%19 = load i8*, i8** %9
%20 = bitcast [1048576 x i8]* %8 to i8**
%21 = call i32 @memcpy(i8* %19, i8** %20, i32 1048576)
br label %22
22: ; preds = %14
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %11
25: ; preds = %11
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %9
%26 = load i8*, i8** %9
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"crashme :-)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1048576 x i8]
%4 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast [1048576 x i8]* %3 to i8**
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %12, %7 ]
%9 = call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%10 = call i32 @read(i32 %5, i8** %6, i32 1048576)
%11 = call i32 @memcpy(i8* %9, i8** %6, i32 1048576)
%12 = add nuw nsw i32 %8, 1
%13 = icmp eq i32 %12, 100
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = call i32 @free(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}