#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 ssize_t;

/* Variables and functions */
scalar_t__ ENOSPC;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int open(char *, int, int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ warn(char *);
int /*<<< orphan*/ warnx(char *, int, int);
int write(int, char *, int);
void fill_blocks(void) {
  char block[1024];
  ssize_t len;
  int fd, i;
  fd = open("0", O_CREAT | O_TRUNC | O_RDWR, 0600);
  if (fd < 0)
    err(-1, "fill_blocks: open(%s)", "0");
  bzero(block, 1024);
  errno = 0;
  while (1) {
    len = write(fd, block, 1024);
    if (len < 0)
      break;
    if (len != 1024) {
      warnx("fill_blocks: write(%d) returned %zd", 1024, len);
      close(fd);
      (void)unlink("0");
      exit(-1);
    }
  }
  if (errno != ENOSPC) {
    warn("fill_blocks: write");
    close(fd);
    (void)unlink("0");
    exit(-1);
  }
  for (i = 0; i < 200; i++) {
    len = write(fd, block, 1024);
    if (len < 0 && errno != ENOSPC) {
      warn("fill_blocks: write after ENOSPC");
      close(fd);
      (void)unlink("0");
      exit(-1);
    }
  }
  close(fd);
  (void)unlink("0");
}


x86 assembly (clang, -O0):
<fill_blocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    0x2e45(%rip),%rax
or     (%rax),%esi
mov    0x2e24(%rip),%rax
or     (%rax),%esi
lea    0xe43(%rip),%rdi
mov    $0x180,%edx
call   1090 <open@plt>
mov    %eax,-0x408(%rbp)
cmpl   $0x0,-0x408(%rbp)
jge    11f2 <fill_blocks+0x62>
mov    $0xffffffff,%edi
lea    0xe1c(%rip),%rsi
lea    0xe13(%rip),%rdx
call   1080 <err@plt>
lea    -0x400(%rbp),%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
mov    0x2dbe(%rip),%rax
movq   $0x0,(%rax)
mov    -0x408(%rbp),%edi
lea    -0x400(%rbp),%rsi
mov    $0x400,%edx
call   1050 <write@plt>
mov    %eax,-0x404(%rbp)
cmpl   $0x0,-0x404(%rbp)
jge    1240 <fill_blocks+0xb0>
jmp    128d <fill_blocks+0xfd>
cmpl   $0x400,-0x404(%rbp)
je     1288 <fill_blocks+0xf8>
mov    -0x404(%rbp),%edx
lea    0xdbb(%rip),%rdi
mov    $0x400,%esi
call   1060 <warnx@plt>
mov    -0x408(%rbp),%edi
call   1070 <close@plt>
lea    0xd87(%rip),%rdi
call   1030 <unlink@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    1211 <fill_blocks+0x81>
mov    0x2d34(%rip),%rax
mov    (%rax),%rax
mov    0x2d22(%rip),%rcx
cmp    (%rcx),%rax
je     12d4 <fill_blocks+0x144>
lea    0xd8e(%rip),%rdi
call   1040 <warn@plt>
mov    -0x408(%rbp),%edi
call   1070 <close@plt>
lea    0xd3b(%rip),%rdi
call   1030 <unlink@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x40c(%rbp)
cmpl   $0xc8,-0x40c(%rbp)
jge    1378 <fill_blocks+0x1e8>
mov    -0x408(%rbp),%edi
lea    -0x400(%rbp),%rsi
mov    $0x400,%edx
call   1050 <write@plt>
mov    %eax,-0x404(%rbp)
cmpl   $0x0,-0x404(%rbp)
jge    135f <fill_blocks+0x1cf>
mov    0x2ca9(%rip),%rax
mov    (%rax),%rax
mov    0x2c97(%rip),%rcx
cmp    (%rcx),%rax
je     135f <fill_blocks+0x1cf>
lea    0xd16(%rip),%rdi
call   1040 <warn@plt>
mov    -0x408(%rbp),%edi
call   1070 <close@plt>
lea    0xcb0(%rip),%rdi
call   1030 <unlink@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    1364 <fill_blocks+0x1d4>
mov    -0x40c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40c(%rbp)
jmp    12de <fill_blocks+0x14e>
mov    -0x408(%rbp),%edi
call   1070 <close@plt>
lea    0xc76(%rip),%rdi
call   1030 <unlink@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_blocks>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    0x2e52(%rip),%rax
mov    0x2e43(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
lea    0xe3f(%rip),%rdi
mov    $0x180,%edx
call   1090 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11e9 <fill_blocks+0x59>
lea    0xe2a(%rip),%rsi
lea    0xe21(%rip),%rdx
mov    $0xffffffff,%edi
call   1080 <err@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   10a0 <bzero@plt>
mov    0x2dc8(%rip),%r15
movq   $0x0,(%r15)
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1050 <write@plt>
test   %eax,%eax
js     123f <fill_blocks+0xaf>
cmp    $0x400,%eax
je     1210 <fill_blocks+0x80>
lea    0xde7(%rip),%rdi
mov    $0x400,%esi
mov    %eax,%edx
call   1060 <warnx@plt>
jmp    128d <fill_blocks+0xfd>
mov    (%r15),%rax
mov    0x2d77(%rip),%r12
cmp    (%r12),%rax
jne    12cc <fill_blocks+0x13c>
mov    $0xc8,%ebp
mov    %rsp,%r14
jmp    1265 <fill_blocks+0xd5>
nopl   0x0(%rax)
add    $0xffffffff,%ebp
je     12aa <fill_blocks+0x11a>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1050 <write@plt>
test   %eax,%eax
jns    1260 <fill_blocks+0xd0>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1260 <fill_blocks+0xd0>
lea    0xdc7(%rip),%rdi
call   1040 <warn@plt>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xd65(%rip),%rdi
call   1030 <unlink@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xd48(%rip),%rdi
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <unlink@plt>
lea    0xd69(%rip),%rdi
jmp    1288 <fill_blocks+0xf8>

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"fill_blocks: open(%s)\00"
@errno = global i64 0
@.str.2 = [36 x i8] c"fill_blocks: write(%d) returned %zd\00"
@ENOSPC = global i64 0
@.str.3 = [19 x i8] c"fill_blocks: write\00"
@.str.4 = [32 x i8] c"fill_blocks: write after ENOSPC\00"
define void @fill_blocks() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = load i32, i32* @O_RDWR
%9 = or i32 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %9, i32 384)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @err(i32 -1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%17 = call i32 @bzero(i8* %16, i32 1024)
store i64 0, i64* @errno
br label %18
18: ; preds = %15, %35
%19 = load i32, i32* %3
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%21 = call i32 @write(i32 %19, i8* %20, i32 1024)
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
br label %36
25: ; preds = %18
%26 = load i32, i32* %2
%27 = icmp ne i32 %26, 1024
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i32, i32* %2
%30 = call i32 @warnx(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 1024, i32 %29)
%31 = load i32, i32* %3
%32 = call i32 @close(i32 %31)
%33 = call i32 @unlink(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %25
br label %18
36: ; preds = %24
%37 = load i64, i64* @errno
%38 = load i64, i64* @ENOSPC
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = call i32 @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* %3
%43 = call i32 @close(i32 %42)
%44 = call i32 @unlink(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %36
store i32 0, i32* %4
br label %47
47: ; preds = %67, %46
%48 = load i32, i32* %4
%49 = icmp slt i32 %48, 200
br i1 %49, label %50, label %70
50: ; preds = %47
%51 = load i32, i32* %3
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%53 = call i32 @write(i32 %51, i8* %52, i32 1024)
store i32 %53, i32* %2
%54 = load i32, i32* %2
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %50
%57 = load i64, i64* @errno
%58 = load i64, i64* @ENOSPC
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = call i32 @warn(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32, i32* %3
%63 = call i32 @close(i32 %62)
%64 = call i32 @unlink(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %56, %50
br label %67
67: ; preds = %66
%68 = load i32, i32* %4
%69 = add nsw i32 %68, 1
store i32 %69, i32* %4
br label %47
70: ; preds = %47
%71 = load i32, i32* %3
%72 = call i32 @close(i32 %71)
%73 = call i32 @unlink(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.1 = [22 x i8] c"fill_blocks: open(%s)\00"
@errno = global i64 0
@.str.2 = [36 x i8] c"fill_blocks: write(%d) returned %zd\00"
@ENOSPC = global i64 0
@.str.3 = [19 x i8] c"fill_blocks: write\00"
@.str.4 = [32 x i8] c"fill_blocks: write after ENOSPC\00"
define void @fill_blocks() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_TRUNC
%5 = or i32 %4, %3
%6 = load i32, i32* @O_RDWR
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %7, i32 384)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @err(i32 -1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i32 @bzero(i8* %2, i32 1024)
store i64 0, i64* @errno
br label %14
14: ; preds = %17, %12
%15 = call i32 @write(i32 %8, i8* %2, i32 1024)
%16 = icmp slt i32 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %14
%18 = icmp eq i32 %15, 1024
br i1 %18, label %14, label %19
19: ; preds = %17
%20 = tail call i32 @warnx(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 1024, i32 %15)
%21 = tail call i32 @close(i32 %8)
%22 = tail call i32 @unlink(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %14
%25 = load i64, i64* @errno
%26 = load i64, i64* @ENOSPC
%27 = icmp eq i64 %25, %26
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = tail call i32 @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%30 = tail call i32 @close(i32 %8)
%31 = tail call i32 @unlink(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = tail call i32 @exit(i32 -1)
unreachable
33: ; preds = %24, %46
%34 = phi i32 [ %47, %46 ], [ 0, %24 ]
%35 = call i32 @write(i32 %8, i8* %2, i32 1024)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = load i64, i64* @errno
%39 = load i64, i64* @ENOSPC
%40 = icmp eq i64 %38, %39
br i1 %40, label %46, label %41
41: ; preds = %37
%42 = tail call i32 @warn(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%43 = tail call i32 @close(i32 %8)
%44 = tail call i32 @unlink(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%45 = tail call i32 @exit(i32 -1)
unreachable
46: ; preds = %33, %37
%47 = add nuw nsw i32 %34, 1
%48 = icmp eq i32 %47, 200
br i1 %48, label %49, label %33
49: ; preds = %46
%50 = tail call i32 @close(i32 %8)
%51 = tail call i32 @unlink(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}