#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*/ b;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ferror(int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int fcopy(FILE *fo, FILE *fi) {
  int readlen;
  char b[2048];
  while ((readlen = fread(b, 1, sizeof(b), fi)) != 0) {
    fwrite(b, 1, readlen, fo);
  }
  return (ferror(fi) || ferror(fo));
}


x86 assembly (clang, -O0):
<fcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1186 <fcopy+0x56>
lea    -0x820(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
jmp    1143 <fcopy+0x13>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x821(%rbp)
jne    11ba <fcopy+0x8a>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x821(%rbp)
mov    -0x821(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcopy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbp
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x1,%r14d
mov    $0x1,%esi
mov    $0x800,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     119b <fcopy+0x6b>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r15,%rcx
call   1050 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jne    1170 <fcopy+0x40>
mov    %rbp,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    11ba <fcopy+0x8a>
mov    %r15,%rdi
call   1030 <ferror@plt>
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
mov    %r14d,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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