#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*/ assert(int /*<<< orphan*/);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
size_t fcopy(FILE *restrict out, FILE *restrict in) {
  char buffer[BUFSIZ];
  size_t inbytes;
  size_t outbytes;
  assert(out != NULL);
  assert(in != NULL);
  outbytes = 0;
  do {
    inbytes = fread(buffer, 1, sizeof(buffer), in);
    outbytes += fwrite(buffer, 1, inbytes, out);
  } while (inbytes > 0);
  return outbytes;
}


x86 assembly (clang, -O0):
<fcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%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,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
ja     119c <fcopy+0x6c>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcopy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rcx
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
mov    %rax,-0x30(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
xor    %edi,%edi
mov    %rcx,%r12
test   %rcx,%rcx
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
mov    %rbx,%r15
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x1,%esi
mov    -0x30(%rbp),%rdx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r12,%rcx
call   1050 <fwrite@plt>
add    %rax,%rbx
test   %r14,%r14
jne    1190 <fcopy+0x60>
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define i64 @fcopy(i32* noalias %0, i32* noalias %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32*, i32** %3
%14 = icmp ne i32* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32*, i32** %4
%18 = icmp ne i32* %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
store i64 0, i64* %8
br label %21
21: ; preds = %30, %2
%22 = trunc i64 %10 to i32
%23 = load i32*, i32** %4
%24 = call i64 @fread(i8* %12, i32 1, i32 %22, i32* %23)
store i64 %24, i64* %7
%25 = load i64, i64* %7
%26 = load i32*, i32** %3
%27 = call i64 @fwrite(i8* %12, i32 1, i64 %25, i32* %26)
%28 = load i64, i64* %8
%29 = add i64 %28, %27
store i64 %29, i64* %8
br label %30
30: ; preds = %21
%31 = load i64, i64* %7
%32 = icmp ugt i64 %31, 0
br i1 %32, label %21, label %33
33: ; preds = %30
%34 = load i64, i64* %8
%35 = load i8*, i8** %5
ret i64 %34
}

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