#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 char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
void createNfImage() {
  unsigned int imgSize = (4096 * 2048);
  int i;
  unsigned char buf[4096];
  FILE *outf;
  outf = fopen("nf_img.bin", "wb+");
  memset(buf, 0xff, 4096);
  for (i = 0; i < 2048; i++) {
    fwrite(buf, 4096, 1, outf);
  }
  fclose(outf);
}


x86 assembly (clang, -O0):
<createNfImage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x800000,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x800,-0x8(%rbp)
jge    11c1 <createNfImage+0x81>
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rcx
mov    $0x1000,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1189 <createNfImage+0x49>
mov    -0x1018(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createNfImage>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    $0x800,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x1000,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
add    $0xffffffff,%ebp
jne    1180 <createNfImage+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"nf_img.bin\00"
@.str.1 = [4 x i8] c"wb+\00"
define void @createNfImage() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4096 x i8]
%4 = alloca i32*
store i32 8388608, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 255, i32 4096)
store i32 0, i32* %2
br label %8
8: ; preds = %15, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 2048
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32 @fwrite(i8* %12, i32 4096, i32 1, i32* %13)
br label %15
15: ; preds = %11
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %8
18: ; preds = %8
%19 = load i32*, i32** %4
%20 = call i32 @fclose(i32* %19)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"nf_img.bin\00"
@.str.1 = [4 x i8] c"wb+\00"
define void @createNfImage() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @memset(i8* %2, i32 255, i32 4096)
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 0, %0 ], [ %8, %5 ]
%7 = call i32 @fwrite(i8* %2, i32 4096, i32 1, i32* %3)
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i32 %8, 2048
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = call i32 @fclose(i32* %3)
ret void
}