#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 */

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int make_disk(char *name) {
  int f, cnt;
  char buf[4096];
  if (!name) {
    fprintf(stderr, "make_disk: invalid file name\n");
    return -1;
  }
  if ((f = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) {
    perror("make_disk: cannot open file");
    return -1;
  }
  memset(buf, 0, 4096);
  for (cnt = 0; cnt < 8192; ++cnt)
    write(f, buf, 4096);
  close(f);
  return 0;
}


x86 assembly (clang, -O0):
<make_disk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <make_disk+0x3b>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1240 <make_disk+0xe0>
mov    -0x10(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    0x2e49(%rip),%rax
or     (%rax),%esi
mov    0x2e38(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11e8 <make_disk+0x88>
lea    0xe47(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1240 <make_disk+0xe0>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2000,-0x18(%rbp)
jge    1231 <make_disk+0xd1>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1202 <make_disk+0xa2>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_disk>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
test   %rdi,%rdi
je     11df <make_disk+0x7f>
mov    0x2e49(%rip),%rax
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e67(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
test   %eax,%eax
js     1205 <make_disk+0xa5>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
mov    $0x2000,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    11c0 <make_disk+0x60>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11f9 <make_disk+0x99>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe12(%rip),%rdi
call   1080 <perror@plt>
jmp    11f4 <make_disk+0x94>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"make_disk: invalid file name\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [28 x i8] c"make_disk: cannot open file\00"
define i32 @make_disk(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4096 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %39
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %13, i32 %18, i32 420)
store i32 %19, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %39
23: ; preds = %12
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 4096)
store i32 0, i32* %5
br label %26
26: ; preds = %33, %23
%27 = load i32, i32* %5
%28 = icmp slt i32 %27, 8192
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %4
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%32 = call i32 @write(i32 %30, i8* %31, i32 4096)
br label %33
33: ; preds = %29
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %26
36: ; preds = %26
%37 = load i32, i32* %4
%38 = call i32 @close(i32 %37)
store i32 0, i32* %2
br label %39
39: ; preds = %36, %21, %9
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"make_disk: invalid file name\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [28 x i8] c"make_disk: cannot open file\00"
define i32 @make_disk(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %27
8: ; preds = %1
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = tail call i32 @open(i8* %0, i32 %13, i32 420)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %27
18: ; preds = %8
%19 = call i32 @memset(i8* %3, i32 0, i32 4096)
br label %20
20: ; preds = %18, %20
%21 = phi i32 [ 0, %18 ], [ %23, %20 ]
%22 = call i32 @write(i32 %14, i8* %3, i32 4096)
%23 = add nuw nsw i32 %21, 1
%24 = icmp eq i32 %23, 8192
br i1 %24, label %25, label %20
25: ; preds = %20
%26 = call i32 @close(i32 %14)
br label %27
27: ; preds = %25, %16, %5
%28 = phi i32 [ -1, %16 ], [ 0, %25 ], [ -1, %5 ]
ret i32 %28
}