#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*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
char *malloc(size_t);
int main() {
  size_t i, n = 512;
  char *buffer = malloc(n);
  for (i = 0; i < n; i++)
    buffer[i] = '0';
  FILE *f;
  f = fopen("zero512.bin", "w");
  fwrite(buffer, 1, n, f);
  fclose(f);
  free(buffer);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x200,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a7 <main+0x57>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    117c <main+0x2c>
lea    0xe52(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x200,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x200,%edx
mov    %rax,%rdi
mov    $0x30,%esi
call   1050 <memset@plt>
lea    0xe76(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    $0x200,%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"zero512.bin\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32*
store i32 0, i32* %1
store i64 512, i64* %3
%6 = load i64, i64* %3
%7 = call i8* @malloc(i64 %6)
store i8* %7, i8** %4
store i64 0, i64* %2
br label %8
8: ; preds = %16, %0
%9 = load i64, i64* %2
%10 = load i64, i64* %3
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i64, i64* %2
%15 = getelementptr inbounds i8, i8* %13, i64 %14
store i8 48, i8* %15
br label %16
16: ; preds = %12
%17 = load i64, i64* %2
%18 = add i64 %17, 1
store i64 %18, i64* %2
br label %8
19: ; preds = %8
%20 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %5
%21 = load i8*, i8** %4
%22 = load i64, i64* %3
%23 = load i32*, i32** %5
%24 = call i32 @fwrite(i8* %21, i32 1, i64 %22, i32* %23)
%25 = load i32*, i32** %5
%26 = call i32 @fclose(i32* %25)
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [12 x i8] c"zero512.bin\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(512) i8* @malloc(i64 512)
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @fwrite(i8* %1, i32 1, i64 512, i32* %2)
%4 = tail call i32 @fclose(i32* %2)
%5 = tail call i32 @free(i8* %1)
ret i32 0
}