#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 */
scalar_t__ EOF;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fputc(int, int /*<<< orphan*/ *);
void write_to_disk(const char *filename, int num_pages) {
  FILE *f = fopen(filename, "w");
  assert(f && "unable to open file.");
  for (int i = 0; i < 4096 * num_pages; ++i) {
    assert(fputc(i, f) != EOF && "error writing file.");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<write_to_disk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
je     117d <write_to_disk+0x3d>
mov    $0x1,%al
mov    %al,-0x1d(%rbp)
jmp    117d <write_to_disk+0x3d>
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0xc,%ecx
cmp    %ecx,%eax
jge    11eb <write_to_disk+0xab>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <fputc@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e2e(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x1e(%rbp)
je     11d0 <write_to_disk+0x90>
mov    $0x1,%al
mov    %al,-0x1e(%rbp)
jmp    11d0 <write_to_disk+0x90>
mov    -0x1e(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1191 <write_to_disk+0x51>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_disk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
test   %ebp,%ebp
jle    11af <write_to_disk+0x6f>
shl    $0xc,%ebp
cmp    $0x2,%ebp
mov    $0x1,%ebx
cmovge %ebp,%ebx
xor    %ebp,%ebp
mov    0x2e67(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
cmp    (%r15),%rax
setne  %dil
call   1050 <assert@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1190 <write_to_disk+0x50>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [21 x i8] c"unable to open file.\00"
@EOF = global i64 0
@.str.2 = [20 x i8] c"error writing file.\00"
define void @write_to_disk(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
br label %12
12: ; preds = %11, %2
%13 = phi i1 [ false, %2 ], [ true, %11 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
store i32 0, i32* %6
br label %16
16: ; preds = %32, %12
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = mul nsw i32 4096, %18
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %35
21: ; preds = %16
%22 = load i32, i32* %6
%23 = load i32*, i32** %5
%24 = call i64 @fputc(i32 %22, i32* %23)
%25 = load i64, i64* @EOF
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %21
br label %28
28: ; preds = %27, %21
%29 = phi i1 [ false, %21 ], [ true, %27 ]
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
br label %32
32: ; preds = %28
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %16
35: ; preds = %16
%36 = load i32*, i32** %5
%37 = call i32 @fclose(i32* %36)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@EOF = global i64 0
define void @write_to_disk(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i32* %3, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = shl i32 %1, 12
%10 = call i32 @llvm.smax.i32(i32 %9, i32 1)
br label %13
11: ; preds = %13, %2
%12 = tail call i32 @fclose(i32* %3)
ret void
13: ; preds = %8, %13
%14 = phi i32 [ %20, %13 ], [ 0, %8 ]
%15 = tail call i64 @fputc(i32 %14, i32* %3)
%16 = load i64, i64* @EOF
%17 = icmp ne i64 %15, %16
%18 = zext i1 %17 to i32
%19 = tail call i32 @assert(i32 %18)
%20 = add nuw nsw i32 %14, 1
%21 = icmp eq i32 %20, %10
br i1 %21, label %11, label %13
}