#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ ferror(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
void direct_copy_to_end(FILE *in, FILE *out) {
  char buf[4096];
  while (!feof(in) && !ferror(in)) {
    size_t bytes_read = fread(buf, 1, 4096, in);
    (void)fwrite(buf, 1, bytes_read, out);
  }
}


x86 assembly (clang, -O0):
<direct_copy_to_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1019(%rbp)
jne    1186 <direct_copy_to_end+0x46>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1019(%rbp)
mov    -0x1019(%rbp),%al
test   $0x1,%al
jne    1199 <direct_copy_to_end+0x59>
jmp    11db <direct_copy_to_end+0x9b>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
mov    %rax,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    1153 <direct_copy_to_end+0x13>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<direct_copy_to_end>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <feof@plt>
test   %eax,%eax
jne    11a0 <direct_copy_to_end+0x60>
mov    %rsp,%r15
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    11a0 <direct_copy_to_end+0x60>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1160 <direct_copy_to_end+0x20>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @direct_copy_to_end(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [4096 x i8]
%6 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
br label %7
7: ; preds = %18, %2
%8 = load i32*, i32** %3
%9 = call i32 @feof(i32* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = call i32 @ferror(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br label %16
16: ; preds = %11, %7
%17 = phi i1 [ false, %7 ], [ %15, %11 ]
br i1 %17, label %18, label %26
18: ; preds = %16
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %3
%21 = call i64 @fread(i8* %19, i32 1, i32 4096, i32* %20)
store i64 %21, i64* %6
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%23 = load i64, i64* %6
%24 = load i32*, i32** %4
%25 = call i32 @fwrite(i8* %22, i32 1, i64 %23, i32* %24)
br label %7
26: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @direct_copy_to_end(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @feof(i32* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %2, %10
%8 = tail call i32 @ferror(i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = call i64 @fread(i8* %4, i32 1, i32 4096, i32* %0)
%12 = call i32 @fwrite(i8* %4, i32 1, i64 %11, i32* %1)
%13 = tail call i32 @feof(i32* %0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %7, label %15
15: ; preds = %7, %10, %2
ret void
}