#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 *);
int fwrite(char *, size_t, 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];
  size_t offset;
  memset(buf, 0xff, sizeof(buf));
  for (offset = 0; offset + sizeof(buf) < size; offset += sizeof(buf)) {
    if (fwrite(buf, sizeof(buf), 1, output_file) != 1)
      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) != 1)
      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>
movq   $0x0,-0x1018(%rbp)
mov    -0x1018(%rbp),%rax
add    $0x1000,%rax
cmp    -0x10(%rbp),%rax
jae    121d <write_ff+0xcd>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1000,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     11ff <write_ff+0xaf>
jmp    11c3 <write_ff+0x73>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x101c(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x101c(%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>
mov    -0x1018(%rbp),%rax
add    $0x1000,%rax
mov    %rax,-0x1018(%rbp)
jmp    1184 <write_ff+0x34>
mov    -0x1018(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12ab <write_ff+0x15b>
mov    -0x10(%rbp),%rax
sub    -0x1018(%rbp),%rax
mov    %rax,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
je     12a6 <write_ff+0x156>
jmp    126a <write_ff+0x11a>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1020(%rbp)
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x1020(%rbp),%edi
mov    %rax,%rdx
lea    0xd90(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    12ab <write_ff+0x15b>
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)
lea    0x1000(%rcx),%rbx
cmp    %r12,%rbx
jae    11db <write_ff+0x8b>
mov    $0x1000,%esi
mov    %r15,%rdi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rcx
cmp    $0x1,%eax
je     1180 <write_ff+0x30>
mov    0x2e30(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe39(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmp    %r12,%rcx
jae    11fb <write_ff+0xab>
sub    %rcx,%r12
mov    %rsp,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
cmp    $0x1,%eax
jne    120a <write_ff+0xba>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dcf(%rip),%rax
mov    (%rax),%ebx
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xdff(%rip),%rsi
jmp    11c7 <write_ff+0x77>

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 i64
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 i64 0, i64* %6
br label %9
9: ; preds = %28, %2
%10 = load i64, i64* %6
%11 = add i64 %10, 4096
%12 = load i64, i64* %4
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %9
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32 @fwrite(i8* %15, i64 4096, i32 1, i32* %16)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %27
19: ; preds = %14
br label %20
20: ; preds = %19
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; No predecessors!
br label %27
27: ; preds = %26, %14
br label %28
28: ; preds = %27
%29 = load i64, i64* %6
%30 = add i64 %29, 4096
store i64 %30, i64* %6
br label %9
31: ; preds = %9
%32 = load i64, i64* %6
%33 = load i64, i64* %4
%34 = icmp ult i64 %32, %33
br i1 %34, label %35, label %53
35: ; preds = %31
%36 = load i64, i64* %4
%37 = load i64, i64* %6
%38 = sub i64 %36, %37
store i64 %38, i64* %6
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%40 = load i64, i64* %6
%41 = load i32*, i32** %3
%42 = call i32 @fwrite(i8* %39, i64 %40, i32 1, i32* %41)
%43 = icmp ne i32 %42, 1
br i1 %43, label %44, label %52
44: ; preds = %35
br label %45
45: ; preds = %44
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; No predecessors!
br label %52
52: ; preds = %51, %35
br label %53
53: ; preds = %52, %31
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 = %10, %2
%7 = phi i64 [ 0, %2 ], [ %8, %10 ]
%8 = add i64 %7, 4096
%9 = icmp ult i64 %8, %1
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = call i32 @fwrite(i8* %4, i64 4096, i32 1, i32* %0)
%12 = icmp eq i32 %11, 1
br i1 %12, label %6, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %6
%20 = icmp ult i64 %7, %1
br i1 %20, label %21, label %31
21: ; preds = %19
%22 = sub i64 %1, %7
%23 = call i32 @fwrite(i8* %4, i64 %22, i32 1, i32* %0)
%24 = icmp eq i32 %23, 1
br i1 %24, label %31, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21, %19
ret void
}