#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*/ Fwrite(unsigned char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, unsigned char, int);
void FillWithByte(unsigned char byte, size_t size, FILE *stream) {
  static unsigned char buf[1024];
  memset(buf, byte, 1024);
  while (size) {
    size_t csz = size;
    if (csz > 1024)
      csz = 1024;
    Fwrite(buf, csz, stream);
    size -= csz;
  }
}


x86 assembly (clang, -O0):
<FillWithByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x1(%rbp),%al
movzbl %al,%esi
lea    0x2efd(%rip),%rdi
mov    $0x400,%edx
call   1040 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     119e <FillWithByte+0x7e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x400,-0x20(%rbp)
jbe    1176 <FillWithByte+0x56>
movq   $0x400,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0x2ebb(%rip),%rdi
call   1030 <Fwrite@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    114d <FillWithByte+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FillWithByte>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%esi
lea    0x2f09(%rip),%rdi
mov    $0x400,%edx
call   1040 <memset@plt>
test   %r12,%r12
je     1173 <FillWithByte+0x53>
lea    0x2ef3(%rip),%r15
nopl   (%rax)
cmp    $0x400,%r12
mov    $0x400,%ebx
cmovb  %r12,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <Fwrite@plt>
sub    %rbx,%r12
jne    1150 <FillWithByte+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@FillWithByte.buf = internal global [1024 x i8] zeroinitializer
define void @FillWithByte(i8 zeroext %0, i64 %1, i32* %2) {
%4 = alloca i8
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
store i8 %0, i8* %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%8 = load i8, i8* %4
%9 = call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @FillWithByte.buf, i64 0, i64 0), i8 zeroext %8, i32 1024)
br label %10
10: ; preds = %18, %3
%11 = load i64, i64* %5
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load i64, i64* %5
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = icmp ugt i64 %15, 1024
br i1 %16, label %17, label %18
17: ; preds = %13
store i64 1024, i64* %7
br label %18
18: ; preds = %17, %13
%19 = load i64, i64* %7
%20 = load i32*, i32** %6
%21 = call i32 @Fwrite(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @FillWithByte.buf, i64 0, i64 0), i64 %19, i32* %20)
%22 = load i64, i64* %7
%23 = load i64, i64* %5
%24 = sub i64 %23, %22
store i64 %24, i64* %5
br label %10
25: ; preds = %10
ret void
}

LLVM IR (-O2):
@FillWithByte.buf = internal global [1024 x i8] zeroinitializer
define void @FillWithByte(i8 zeroext %0, i64 %1, i32* %2) {
%4 = tail call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @FillWithByte.buf, i64 0, i64 0), i8 zeroext %0, i32 1024)
%5 = icmp eq i64 %1, 0
br i1 %5, label %13, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %11, %6 ], [ %1, %3 ]
%8 = icmp ult i64 %7, 1024
%9 = select i1 %8, i64 %7, i64 1024
%10 = tail call i32 @Fwrite(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @FillWithByte.buf, i64 0, i64 0), i64 %9, i32* %2)
%11 = sub i64 %7, %9
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %6
13: ; preds = %6, %3
ret void
}