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

/* Variables and functions */
unsigned long fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, unsigned long, int /*<<< orphan*/ *);
unsigned long fcopy(FILE *dst, FILE *src) {
  char buf[16384];
  unsigned long sz = 0, this_sz;
  do {
    this_sz = fread(buf, 1, sizeof(buf), src);
    if (this_sz) {
      fwrite(buf, 1, this_sz, dst);
      sz += this_sz;
    }
  } while (this_sz != 0);
  return sz;
}


x86 assembly (clang, -O0):
<fcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x4018(%rbp)
lea    -0x4010(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4000,%edx
call   1030 <fread@plt>
mov    %rax,-0x4020(%rbp)
cmpq   $0x0,-0x4020(%rbp)
je     119e <fcopy+0x7e>
lea    -0x4010(%rbp),%rdi
mov    -0x4020(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    -0x4020(%rbp),%rax
add    -0x4018(%rbp),%rax
mov    %rax,-0x4018(%rbp)
jmp    11a3 <fcopy+0x83>
cmpq   $0x0,-0x4020(%rbp)
jne    113e <fcopy+0x1e>
mov    -0x4018(%rbp),%rax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcopy>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4000,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1195 <fcopy+0x75>
mov    %rax,%rbx
xor    %r13d,%r13d
mov    %rsp,%r12
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <fwrite@plt>
add    %rbx,%r13
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x4000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <fcopy+0x40>
jmp    1198 <fcopy+0x78>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x4000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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