#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, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, unsigned long, int /*<<< orphan*/ *);
void fncpy(FILE *dst, FILE *src, unsigned long n) {
  char buf[16384];
  while (n > 0) {
    unsigned long n_copy = n;
    if (n_copy > 16384)
      n_copy = 16384;
    fread(buf, 1, n_copy, src);
    fwrite(buf, 1, n_copy, dst);
    n -= n_copy;
  }
}


x86 assembly (clang, -O0):
<fncpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11b8 <fncpy+0x98>
mov    -0x18(%rbp),%rax
mov    %rax,-0x4028(%rbp)
cmpq   $0x4000,-0x4028(%rbp)
jbe    1169 <fncpy+0x49>
movq   $0x4000,-0x4028(%rbp)
lea    -0x4020(%rbp),%rdi
mov    -0x4028(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
lea    -0x4020(%rbp),%rdi
mov    -0x4028(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    -0x4028(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1137 <fncpy+0x17>
add    $0x4030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fncpy>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4000,%rsp
test   %rdx,%rdx
je     118b <fncpy+0x6b>
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x4000,%r13
mov    $0x4000,%ebx
cmovb  %r13,%rbx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1040 <fwrite@plt>
sub    %rbx,%r13
jne    1150 <fncpy+0x30>
add    $0x4000,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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