#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*/ clearerr(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
void fwritestream(FILE *from, FILE *to) {
  clearerr(from);
  clearerr(to);
  char buf[1024];
  while (feof(from) == 0 && ferror(from) == 0 && ferror(to) == 0) {
    size_t readl = fread(buf, 1, 1024, from);
    fwrite(buf, 1, readl, to);
  }
}


x86 assembly (clang, -O0):
<fwritestream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <clearerr@plt>
mov    -0x10(%rbp),%rdi
call   1060 <clearerr@plt>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x419(%rbp)
jne    11c7 <fwritestream+0x77>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x419(%rbp)
jne    11c7 <fwritestream+0x77>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x419(%rbp)
mov    -0x419(%rbp),%al
test   $0x1,%al
jne    11da <fwritestream+0x8a>
jmp    121c <fwritestream+0xcc>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    1175 <fwritestream+0x25>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwritestream>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <clearerr@plt>
mov    %r14,%rdi
call   1060 <clearerr@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
je     1189 <fwritestream+0x39>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    117c <fwritestream+0x2c>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    117c <fwritestream+0x2c>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
je     1190 <fwritestream+0x40>
jmp    117c <fwritestream+0x2c>

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

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