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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(unsigned long *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main() {
  FILE *f;
  unsigned long l = 0, m = 1;
  f = fopen("Image", "wb");
  if (!f) {
    printf("fopen fail\n");
    return -1;
  }
  for (l = 0; l < (1 * 1024 * 1024); l++)
    fwrite(&m, 4, 1, f);
  fclose(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <main+0x59>
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <main+0xa0>
movq   $0x0,-0x18(%rbp)
cmpq   $0x100000,-0x18(%rbp)
jae    11d7 <main+0x97>
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a1 <main+0x61>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x1,0x8(%rsp)
lea    0xea7(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a7 <main+0x67>
mov    %rax,%r15
mov    $0x100000,%ebx
lea    0x8(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
add    $0xffffffffffffffff,%rbx
jne    1180 <main+0x40>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11b8 <main+0x78>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Image\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [12 x i8] c"fopen fail\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %3
store i64 1, i64* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %23
10: ; preds = %0
store i64 0, i64* %3
br label %11
11: ; preds = %17, %10
%12 = load i64, i64* %3
%13 = icmp ult i64 %12, 1048576
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32*, i32** %2
%16 = call i32 @fwrite(i64* %4, i32 4, i32 1, i32* %15)
br label %17
17: ; preds = %14
%18 = load i64, i64* %3
%19 = add i64 %18, 1
store i64 %19, i64* %3
br label %11
20: ; preds = %11
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %20, %8
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"Image\00"
@.str.1 = [3 x i8] c"wb\00"
@str = [11 x i8] c"fopen fail\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 1, i64* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %14
7: ; preds = %0, %7
%8 = phi i64 [ %10, %7 ], [ 0, %0 ]
%9 = call i32 @fwrite(i64* %1, i32 4, i32 1, i32* %3)
%10 = add nuw nsw i64 %8, 1
%11 = icmp eq i64 %10, 1048576
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = tail call i32 @fclose(i32* %3)
br label %14
14: ; preds = %12, %5
%15 = phi i32 [ 0, %12 ], [ -1, %5 ]
ret i32 %15
}