#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*/ bzero(char *, size_t);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printAndFail(char *);
void createZeroFile(char *filename, size_t size) {
  FILE *f = fopen(filename, "w");
  if (!f) {
    printAndFail("Cannot create file");
  }
  char *block = (char *)malloc(size);
  bzero(block, size);
  if (fwrite(block, 1, size, f) != size) {
    printAndFail("Cannot write data 1");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<createZeroFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119b <createZeroFile+0x3b>
lea    0xe6c(%rip),%rdi
call   1040 <printAndFail@plt>
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <bzero@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
cmp    -0x10(%rbp),%rax
je     11e1 <createZeroFile+0x81>
lea    0xe39(%rip),%rdi
call   1040 <printAndFail@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createZeroFile>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1188 <createZeroFile+0x28>
lea    0xe7f(%rip),%rdi
call   1040 <printAndFail@plt>
mov    %r15,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <bzero@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    %r15,%rax
je     11c2 <createZeroFile+0x62>
lea    0xe58(%rip),%rdi
call   1040 <printAndFail@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [19 x i8] c"Cannot create file\00"
@.str.2 = [20 x i8] c"Cannot write data 1\00"
define void @createZeroFile(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %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 %13, label %11
11: ; preds = %2
%12 = call i32 @printAndFail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i64, i64* %4
%15 = call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = load i64, i64* %4
%19 = call i32 @bzero(i8* %17, i64 %18)
%20 = load i8*, i8** %6
%21 = load i64, i64* %4
%22 = load i32*, i32** %5
%23 = call i64 @fwrite(i8* %20, i32 1, i64 %21, i32* %22)
%24 = load i64, i64* %4
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %13
%27 = call i32 @printAndFail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %13
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [19 x i8] c"Cannot create file\00"
@.str.2 = [20 x i8] c"Cannot write data 1\00"
define void @createZeroFile(i8* nocapture %0, i64 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printAndFail(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = tail call i64 @malloc(i64 %1)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @bzero(i8* %9, i64 %1)
%11 = tail call i64 @fwrite(i8* %9, i32 1, i64 %1, i32* %3)
%12 = icmp eq i64 %11, %1
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 @printAndFail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = tail call i32 @fclose(i32* %3)
ret void
}