#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int random();
void makeFile1G(FILE *fd) {
  char buf[1024 * 1024];
  int64_t k = 0;
  int64_t wsize = 0;
  int64_t i = 0, j = 0;
  for (i = 0; i < 1024; i++) {
    memset(buf, 0, 1024 * 1024);
    for (j = 0; j < 1024 * 1024; j++) {
      buf[j] = (random() % 256);
    }
    while (wsize < 1024 * 1024) {
      k = fwrite(buf + wsize, 1, 1024 * 1024 - wsize, fd);
      wsize += k;
    }
  }
}


x86 assembly (clang, -O0):
<makeFile1G>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100020,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x100014(%rbp)
movl   $0x0,-0x100018(%rbp)
movl   $0x0,-0x10001c(%rbp)
movl   $0x0,-0x100020(%rbp)
movl   $0x0,-0x10001c(%rbp)
cmpl   $0x400,-0x10001c(%rbp)
jge    1256 <makeFile1G+0x126>
lea    -0x100010(%rbp),%rdi
xor    %esi,%esi
mov    $0x100000,%edx
call   1030 <memset@plt>
movl   $0x0,-0x100020(%rbp)
cmpl   $0x100000,-0x100020(%rbp)
jge    11e1 <makeFile1G+0xb1>
mov    $0x0,%al
call   1040 <random@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
movslq -0x100020(%rbp),%rax
mov    %cl,-0x100010(%rbp,%rax,1)
mov    -0x100020(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100020(%rbp)
jmp    119e <makeFile1G+0x6e>
jmp    11e6 <makeFile1G+0xb6>
cmpl   $0x100000,-0x100018(%rbp)
jge    123d <makeFile1G+0x10d>
lea    -0x100010(%rbp),%rdi
movslq -0x100018(%rbp),%rax
add    %rax,%rdi
mov    $0x100000,%edx
sub    -0x100018(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    %eax,-0x100014(%rbp)
mov    -0x100014(%rbp),%eax
add    -0x100018(%rbp),%eax
mov    %eax,-0x100018(%rbp)
jmp    11e6 <makeFile1G+0xb6>
jmp    1242 <makeFile1G+0x112>
mov    -0x10001c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10001c(%rbp)
jmp    1171 <makeFile1G+0x41>
add    $0x100020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeFile1G>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100000,%rsp
mov    %rdi,%r12
mov    %rsp,%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
jmp    115d <makeFile1G+0x2d>
nopl   0x0(%rax)
add    $0x1,%r15d
cmp    $0x400,%r15d
je     11b9 <makeFile1G+0x89>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100000,%edx
call   1030 <memset@plt>
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <random@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x100000,%rbx
jne    1170 <makeFile1G+0x40>
cmp    $0xfffff,%ebp
jg     1150 <makeFile1G+0x20>
nop
movslq %ebp,%rbx
lea    (%rsp,%rbx,1),%rdi
mov    $0x100000,%edx
sub    %ebx,%edx
mov    $0x1,%esi
mov    %r12,%rcx
call   1050 <fwrite@plt>
mov    %eax,%ebp
add    %ebx,%ebp
cmp    $0x100000,%ebp
jl     1190 <makeFile1G+0x60>
jmp    1150 <makeFile1G+0x20>
add    $0x100000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @makeFile1G(i32* %0) {
%2 = alloca i32*
%3 = alloca [1048576 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %6
br label %8
8: ; preds = %44, %1
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1024
br i1 %10, label %11, label %47
11: ; preds = %8
%12 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 1048576)
store i32 0, i32* %7
br label %14
14: ; preds = %24, %11
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 1048576
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = call i32 (...) @random()
%19 = srem i32 %18, 256
%20 = trunc i32 %19 to i8
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 %22
store i8 %20, i8* %23
br label %24
24: ; preds = %17
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %14
27: ; preds = %14
br label %28
28: ; preds = %31, %27
%29 = load i32, i32* %5
%30 = icmp slt i32 %29, 1048576
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 0
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %5
%37 = sub nsw i32 1048576, %36
%38 = load i32*, i32** %2
%39 = call i32 @fwrite(i8* %35, i32 1, i32 %37, i32* %38)
store i32 %39, i32* %4
%40 = load i32, i32* %4
%41 = load i32, i32* %5
%42 = add nsw i32 %41, %40
store i32 %42, i32* %5
br label %28
43: ; preds = %28
br label %44
44: ; preds = %43
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %8
47: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @makeFile1G(i32* nocapture %0) {
%2 = alloca [1048576 x i8]
%3 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %1, %25
%5 = phi i32 [ 0, %1 ], [ %27, %25 ]
%6 = phi i32 [ 0, %1 ], [ %26, %25 ]
%7 = call i32 @memset(i8* %3, i32 0, i32 1048576)
br label %10
8: ; preds = %10
%9 = icmp slt i32 %6, 1048576
br i1 %9, label %17, label %25
10: ; preds = %4, %10
%11 = phi i64 [ 0, %4 ], [ %15, %10 ]
%12 = call i32 (...) @random()
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %2, i64 0, i64 %11
store i8 %13, i8* %14
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, 1048576
br i1 %16, label %8, label %10
17: ; preds = %8, %17
%18 = phi i32 [ %23, %17 ], [ %6, %8 ]
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %2, i64 0, i64 %19
%21 = sub nsw i32 1048576, %18
%22 = call i32 @fwrite(i8* %20, i32 1, i32 %21, i32* %0)
%23 = add nsw i32 %22, %18
%24 = icmp slt i32 %23, 1048576
br i1 %24, label %17, label %25
25: ; preds = %17, %8
%26 = phi i32 [ %6, %8 ], [ %23, %17 ]
%27 = add nuw nsw i32 %5, 1
%28 = icmp eq i32 %27, 1024
br i1 %28, label %29, label %4
29: ; preds = %25
ret void
}