#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void write_ff(FILE *output_file, size_t size) {
  char buf[4096];
  int offset;
  memset(buf, 0xff, sizeof(buf));
  for (offset = 0; offset + sizeof(buf) < size; offset += sizeof(buf)) {
    if (fwrite(buf, sizeof(buf), 1, output_file) < 0)
      do {
        fprintf(stderr,
                "Can not write 0xff to output_file"
                ": %s\n",
                strerror(errno));
        if (1)
          exit(1);
      } while (0);
  }
  if (offset < size) {
    offset = size - offset;
    if (fwrite(buf, offset, 1, output_file) < 0)
      do {
        fprintf(stderr,
                "Can not write partition to output_file"
                ": %s\n",
                strerror(errno));
        if (1)
          exit(1);
      } while (0);
  }
}


x86 assembly (clang, -O0):
<write_ff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
movl   $0x0,-0x1014(%rbp)
movslq -0x1014(%rbp),%rax
add    $0x1000,%rax
cmp    -0x10(%rbp),%rax
jae    121c <write_ff+0xcc>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1000,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0x0,%rax
jge    11ff <write_ff+0xaf>
jmp    11c3 <write_ff+0x73>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1018(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1018(%rbp),%edi
mov    %rax,%rdx
lea    0xe10(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1204 <write_ff+0xb4>
movslq -0x1014(%rbp),%rax
add    $0x1000,%rax
mov    %eax,-0x1014(%rbp)
jmp    1183 <write_ff+0x33>
movslq -0x1014(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12ac <write_ff+0x15c>
mov    -0x10(%rbp),%rax
movslq -0x1014(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1014(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1014(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0x0,%rax
jge    12a7 <write_ff+0x157>
jmp    126b <write_ff+0x11b>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x101c(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x101c(%rbp),%edi
mov    %rax,%rdx
lea    0xd8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    12ac <write_ff+0x15c>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_ff>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xff,%esi
mov    $0x1000,%edx
call   1030 <memset@plt>
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movslq %ecx,%rax
lea    0x1000(%rax),%rbx
cmp    %r12,%rbx
jae    11de <write_ff+0x8e>
mov    %r15,%rdi
mov    $0x1000,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rcx
test   %rax,%rax
jns    1180 <write_ff+0x30>
mov    0x2e2d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe36(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmp    %r12,%rax
jae    11fe <write_ff+0xae>
sub    %ecx,%r12d
mov    %rsp,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
test   %rax,%rax
js     120d <write_ff+0xbd>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dcc(%rip),%rax
mov    (%rax),%ebx
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xdfc(%rip),%rsi
jmp    11ca <write_ff+0x7a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Can not write 0xff to output_file: %s\0A\00"
@errno = global i32 0
@.str.1 = [44 x i8] c"Can not write partition to output_file: %s\0A\00"
define void @write_ff(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca [4096 x i8]
%6 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 255, i32 4096)
store i32 0, i32* %6
br label %9
9: ; preds = %29, %2
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = add i64 %11, 4096
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %9
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i64 @fwrite(i8* %16, i32 4096, i32 1, i32* %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %15
br label %21
21: ; preds = %20
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; No predecessors!
br label %28
28: ; preds = %27, %15
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = add i64 %31, 4096
%33 = trunc i64 %32 to i32
store i32 %33, i32* %6
br label %9
34: ; preds = %9
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = load i64, i64* %4
%38 = icmp ult i64 %36, %37
br i1 %38, label %39, label %59
39: ; preds = %34
%40 = load i64, i64* %4
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = sub i64 %40, %42
%44 = trunc i64 %43 to i32
store i32 %44, i32* %6
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%46 = load i32, i32* %6
%47 = load i32*, i32** %3
%48 = call i64 @fwrite(i8* %45, i32 %46, i32 1, i32* %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %39
br label %51
51: ; preds = %50
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; No predecessors!
br label %58
58: ; preds = %57, %39
br label %59
59: ; preds = %58, %34
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Can not write 0xff to output_file: %s\0A\00"
@errno = global i32 0
@.str.1 = [44 x i8] c"Can not write partition to output_file: %s\0A\00"
define void @write_ff(i32* nocapture %0, i64 %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 255, i32 4096)
br label %6
6: ; preds = %12, %2
%7 = phi i64 [ 0, %2 ], [ %10, %12 ]
%8 = shl i64 %7, 32
%9 = ashr exact i64 %8, 32
%10 = add nsw i64 %9, 4096
%11 = icmp ult i64 %10, %1
br i1 %11, label %12, label %21
12: ; preds = %6
%13 = call i64 @fwrite(i8* %4, i32 4096, i32 1, i32* %0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %6
%22 = icmp ult i64 %9, %1
br i1 %22, label %23, label %34
23: ; preds = %21
%24 = sub i64 %1, %7
%25 = trunc i64 %24 to i32
%26 = call i64 @fwrite(i8* %4, i32 %25, i32 1, i32* %0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %23, %21
ret void
}