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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ 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*/ *);
int copy_file_objects(FILE *source, FILE *target) {
  char buffer[BUFSIZ];
  size_t read;
  do {
    read = fread(buffer, 1, sizeof(buffer), source);
    fwrite(buffer, 1, read, target);
  } while (!feof(source) && !feof(target));
  return (ferror(source) || ferror(target)) ? -1 : 0;
}


x86 assembly (clang, -O0):
<copy_file_objects>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
jne    11df <copy_file_objects+0x9f>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1180 <copy_file_objects+0x40>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x3a(%rbp)
jne    1218 <copy_file_objects+0xd8>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%dl
xor    %eax,%eax
mov    $0xffffffff,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file_objects>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    0x2e88(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11ae <copy_file_objects+0x6e>
mov    %r14,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1170 <copy_file_objects+0x30>
mov    %r12,%rdi
call   1030 <ferror@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11d0 <copy_file_objects+0x90>
mov    %r14,%rdi
call   1030 <ferror@plt>
neg    %rax
sbb    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define i32 @copy_file_objects(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
br label %12
12: ; preds = %28, %2
%13 = trunc i64 %9 to i32
%14 = load i32*, i32** %3
%15 = call i64 @fread(i8* %11, i32 1, i32 %13, i32* %14)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = load i32*, i32** %4
%18 = call i32 @fwrite(i8* %11, i32 1, i64 %16, i32* %17)
br label %19
19: ; preds = %12
%20 = load i32*, i32** %3
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = load i32*, i32** %4
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br label %28
28: ; preds = %23, %19
%29 = phi i1 [ false, %19 ], [ %27, %23 ]
br i1 %29, label %12, label %30
30: ; preds = %28
%31 = load i32*, i32** %3
%32 = call i64 @ferror(i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i32*, i32** %4
%36 = call i64 @ferror(i32* %35)
%37 = icmp ne i64 %36, 0
br label %38
38: ; preds = %34, %30
%39 = phi i1 [ true, %30 ], [ %37, %34 ]
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 -1, i32 0
%42 = load i8*, i8** %5
ret i32 %41
}

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