#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*/ fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
void fcpy(FILE *to, FILE *from, long len) {
  char buf[5000];
  size_t count;
  for (; len > 0; len -= count) {
    count = (len > 5000 ? 5000 : len);
    fread(buf, sizeof(char), count, from);
    if (to != NULL)
      fwrite(buf, sizeof(char), count, to);
  }
}


x86 assembly (clang, -O0):
<fcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11d9 <fcpy+0xb9>
cmpq   $0x1388,-0x18(%rbp)
jle    1161 <fcpy+0x41>
mov    $0x1388,%eax
mov    %rax,-0x13b0(%rbp)
jmp    116c <fcpy+0x4c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x13b0(%rbp)
mov    -0x13b0(%rbp),%rax
mov    %rax,-0x13a8(%rbp)
lea    -0x13a0(%rbp),%rdi
mov    -0x13a8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmpq   $0x0,-0x8(%rbp)
je     11bd <fcpy+0x9d>
lea    -0x13a0(%rbp),%rdi
mov    -0x13a8(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
jmp    11c2 <fcpy+0xa2>
mov    -0x13a8(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1137 <fcpy+0x17>
add    $0x13b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcpy>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1390,%rsp
test   %rdx,%rdx
jle    1193 <fcpy+0x73>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%r12
jmp    1155 <fcpy+0x35>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
sub    %r13,%rbx
jle    1193 <fcpy+0x73>
cmp    $0x1388,%rbx
mov    $0x1388,%r13d
cmovb  %rbx,%r13
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %r14,%rcx
call   1030 <fread@plt>
test   %r15,%r15
je     1150 <fcpy+0x30>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %r15,%rcx
call   1040 <fwrite@plt>
jmp    1150 <fcpy+0x30>
add    $0x1390,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @fcpy(i32* %0, i32* nocapture %1, i64 %2) {
%4 = alloca [5000 x i8]
%5 = getelementptr inbounds [5000 x i8], [5000 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i64 %2, 0
br i1 %6, label %7, label %19
7: ; preds = %3
%8 = icmp eq i32* %0, null
br label %9
9: ; preds = %7, %16
%10 = phi i64 [ %2, %7 ], [ %17, %16 ]
%11 = icmp ult i64 %10, 5000
%12 = select i1 %11, i64 %10, i64 5000
%13 = call i32 @fread(i8* %5, i32 1, i64 %12, i32* %1)
br i1 %8, label %16, label %14
14: ; preds = %9
%15 = call i32 @fwrite(i8* %5, i32 1, i64 %12, i32* %0)
br label %16
16: ; preds = %9, %14
%17 = sub nsw i64 %10, %12
%18 = icmp sgt i64 %17, 0
br i1 %18, label %9, label %19
19: ; preds = %16, %3
ret void
}