void output(start, past_end) char *start;
char *past_end;
{
  static char buffer[8192];
  static int bytes_in_buffer = 0;
  int bytes_to_add = past_end - start;
  int bytes_available = 8192 - bytes_in_buffer;
  if (start == 0) {
    xwrite(1, buffer, bytes_in_buffer);
    bytes_in_buffer = 0;
    return;
  }
  while (bytes_to_add >= bytes_available) {
    bcopy(start, buffer + bytes_in_buffer, bytes_available);
    bytes_to_add -= bytes_available;
    start += bytes_available;
    xwrite(1, buffer, 8192);
    bytes_in_buffer = 0;
    bytes_available = 8192;
  }
  bcopy(start, buffer + bytes_in_buffer, bytes_to_add);
  bytes_in_buffer += bytes_to_add;
}


x86 assembly (clang, -O0):
<output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    $0x2000,%eax
sub    0x4ef7(%rip),%eax
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117f <output+0x5f>
mov    0x4ee3(%rip),%edx
mov    $0x1,%edi
lea    0x2ed7(%rip),%rsi
mov    $0x0,%al
call   1030 <xwrite@plt>
movl   $0x0,0x4ec6(%rip)
jmp    1227 <output+0x107>
jmp    1184 <output+0x64>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     11f9 <output+0xd9>
mov    -0x8(%rbp),%rdi
movslq 0x4ea5(%rip),%rax
lea    0x2e9e(%rip),%rsi
add    %rax,%rsi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1040 <bcopy@plt>
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    $0x1,%edi
lea    0x2e69(%rip),%rsi
mov    $0x2000,%edx
mov    $0x0,%al
call   1030 <xwrite@plt>
movl   $0x0,0x4e53(%rip)
movl   $0x2000,-0x18(%rbp)
jmp    1184 <output+0x64>
mov    -0x8(%rbp),%rdi
movslq 0x4e3c(%rip),%rax
lea    0x2e35(%rip),%rsi
add    %rax,%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1040 <bcopy@plt>
mov    -0x14(%rbp),%eax
add    0x4e1f(%rip),%eax
mov    %eax,0x4e19(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x4f0f(%rip),%ebp
test   %rdi,%rdi
je     115a <output+0x3a>
mov    %rsi,%r12
mov    %rdi,%r15
mov    %r12d,%r14d
sub    %r15d,%r14d
movslq %ebp,%rsi
mov    $0x2000,%ebx
sub    %rsi,%rbx
cmp    %r14d,%ebx
jle    1177 <output+0x57>
mov    %r15,%rbx
jmp    1221 <output+0x101>
lea    0x2edf(%rip),%rsi
xor    %r14d,%r14d
mov    $0x1,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <xwrite@plt>
jmp    1242 <output+0x122>
lea    0x2ec2(%rip),%r13
add    %r13,%rsi
mov    %r15,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <bcopy@plt>
sub    %ebx,%r14d
add    %r15,%rbx
mov    $0x1,%edi
mov    %r13,%rsi
mov    $0x2000,%edx
xor    %eax,%eax
call   1030 <xwrite@plt>
movl   $0x0,0x4e8f(%rip)
cmp    $0x2000,%r14d
jl     121f <output+0xff>
add    %r12d,%ebp
sub    %r15d,%ebp
lea    0x2e79(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2000,%edx
xor    %eax,%eax
call   1040 <bcopy@plt>
add    $0x2000,%rbx
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x2000,%edx
xor    %eax,%eax
call   1030 <xwrite@plt>
movl   $0x0,0x4e39(%rip)
add    $0xffffe000,%ebp
cmp    $0x3fff,%ebp
ja     11d0 <output+0xb0>
mov    %ebp,%r14d
add    $0xffffe000,%r14d
xor    %ebp,%ebp
movslq %ebp,%rax
lea    0x2e15(%rip),%rsi
add    %rax,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <bcopy@plt>
add    0x4dfe(%rip),%r14d
mov    %r14d,0x4df7(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@output.buffer = internal global [8192 x i8] zeroinitializer
@output.bytes_in_buffer = internal global i32 0
define void @output(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = load i8*, i8** %3
%9 = ptrtoint i8* %7 to i64
%10 = ptrtoint i8* %8 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
store i32 %12, i32* %5
%13 = load i32, i32* @output.bytes_in_buffer
%14 = sub nsw i32 8192, %13
store i32 %14, i32* %6
%15 = load i8*, i8** %3
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* @output.bytes_in_buffer
%19 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @xwrite to i32 (i32, i8*, i32, ...)*)(i32 1, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 0), i32 %18)
store i32 0, i32* @output.bytes_in_buffer
br label %50
20: ; preds = %2
br label %21
21: ; preds = %25, %20
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = icmp sge i32 %22, %23
br i1 %24, label %25, label %40
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = load i32, i32* @output.bytes_in_buffer
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 0), i64 %28
%30 = load i32, i32* %6
%31 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @bcopy to i32 (i8*, i8*, i32, ...)*)(i8* %26, i8* %29, i32 %30)
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = sub nsw i32 %33, %32
store i32 %34, i32* %5
%35 = load i32, i32* %6
%36 = load i8*, i8** %3
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %3
%39 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @xwrite to i32 (i32, i8*, i32, ...)*)(i32 1, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 0), i32 8192)
store i32 0, i32* @output.bytes_in_buffer
store i32 8192, i32* %6
br label %21
40: ; preds = %21
%41 = load i8*, i8** %3
%42 = load i32, i32* @output.bytes_in_buffer
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 0), i64 %43
%45 = load i32, i32* %5
%46 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @bcopy to i32 (i8*, i8*, i32, ...)*)(i8* %41, i8* %44, i32 %45)
%47 = load i32, i32* %5
%48 = load i32, i32* @output.bytes_in_buffer
%49 = add nsw i32 %48, %47
store i32 %49, i32* @output.bytes_in_buffer
br label %50
50: ; preds = %40, %17
ret void
}

LLVM IR (-O2):
@output.buffer = internal global [8192 x i8] zeroinitializer
@output.bytes_in_buffer = internal unnamed_addr global i32 0
define void @output(i8* %0, i8* %1) {
%3 = ptrtoint i8* %1 to i64
%4 = ptrtoint i8* %0 to i64
%5 = sub i64 %3, %4
%6 = trunc i64 %5 to i32
%7 = load i32, i32* @output.bytes_in_buffer
%8 = sub nsw i32 8192, %7
%9 = icmp eq i8* %0, null
br i1 %9, label %21, label %10
10: ; preds = %2
%11 = icmp sgt i32 %8, %6
br i1 %11, label %31, label %12
12: ; preds = %10
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 %13
%15 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @bcopy to i32 (i8*, i8*, i32, ...)*)(i8* %0, i8* %14, i32 %8)
%16 = sub nsw i32 %6, %8
%17 = sext i32 %8 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @xwrite to i32 (i32, i8*, i32, ...)*)(i32 1, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 0), i32 8192)
store i32 0, i32* @output.bytes_in_buffer
%20 = icmp slt i32 %16, 8192
br i1 %20, label %31, label %23
21: ; preds = %2
%22 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @xwrite to i32 (i32, i8*, i32, ...)*)(i32 1, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 0), i32 %7)
br label %40
23: ; preds = %12, %23
%24 = phi i32 [ %27, %23 ], [ %16, %12 ]
%25 = phi i8* [ %28, %23 ], [ %18, %12 ]
%26 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @bcopy to i32 (i8*, i8*, i32, ...)*)(i8* %25, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 0), i32 8192)
%27 = add nsw i32 %24, -8192
%28 = getelementptr inbounds i8, i8* %25, i64 8192
%29 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @xwrite to i32 (i32, i8*, i32, ...)*)(i32 1, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 0), i32 8192)
store i32 0, i32* @output.bytes_in_buffer
%30 = icmp ult i32 %24, 16384
br i1 %30, label %31, label %23
31: ; preds = %23, %12, %10
%32 = phi i32 [ %7, %10 ], [ 0, %12 ], [ 0, %23 ]
%33 = phi i8* [ %0, %10 ], [ %18, %12 ], [ %28, %23 ]
%34 = phi i32 [ %6, %10 ], [ %16, %12 ], [ %27, %23 ]
%35 = sext i32 %32 to i64
%36 = getelementptr inbounds [8192 x i8], [8192 x i8]* @output.buffer, i64 0, i64 %35
%37 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @bcopy to i32 (i8*, i8*, i32, ...)*)(i8* %33, i8* %36, i32 %34)
%38 = load i32, i32* @output.bytes_in_buffer
%39 = add nsw i32 %38, %34
br label %40
40: ; preds = %31, %21
%41 = phi i32 [ %39, %31 ], [ 0, %21 ]
store i32 %41, i32* @output.bytes_in_buffer
ret void
}