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

/* Variables and functions */
int BUFSIZ;
size_t fread(char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ min(int, scalar_t__);
uint32_t copy_bytes(FILE *dest, FILE *src, uint32_t n) {
  char buf[BUFSIZ];
  uint32_t i = 0;
  while (i < n) {
    size_t r = fread(buf, 1, min(BUFSIZ, n - i), src);
    fwrite(buf, 1, r, dest);
    i += r;
    if (r < BUFSIZ)
      break;
  }
  return i;
}


x86 assembly (clang, -O0):
<copy_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11f7 <copy_bytes+0xc7>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
sub    -0x30(%rbp),%rsi
call   1040 <min@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2dff(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jae    11f2 <copy_bytes+0xc2>
jmp    11f7 <copy_bytes+0xc7>
jmp    1178 <copy_bytes+0x48>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_bytes>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,-0x30(%rbp)
mov    %rdi,%r15
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%r13
mov    %rdi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
cmp    %r12,%rbx
jge    11bb <copy_bytes+0x8b>
mov    %r12,%rsi
sub    %rbx,%rsi
call   1040 <min@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    -0x30(%rbp),%rcx
call   1030 <fread@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1050 <fwrite@plt>
add    %r14,%rbx
mov    0x2e2d(%rip),%rax
movslq (%rax),%rdi
cmp    %rdi,%r14
jae    1170 <copy_bytes+0x40>
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 @copy_bytes(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
store i64 0, i64* %9
br label %15
15: ; preds = %38, %3
%16 = load i64, i64* %9
%17 = load i64, i64* %6
%18 = icmp slt i64 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
%20 = load i32, i32* @BUFSIZ
%21 = load i64, i64* %6
%22 = load i64, i64* %9
%23 = sub nsw i64 %21, %22
%24 = call i32 @min(i32 %20, i64 %23)
%25 = load i32*, i32** %5
%26 = call i64 @fread(i8* %14, i32 1, i32 %24, i32* %25)
store i64 %26, i64* %10
%27 = load i64, i64* %10
%28 = load i32*, i32** %4
%29 = call i32 @fwrite(i8* %14, i32 1, i64 %27, i32* %28)
%30 = load i64, i64* %10
%31 = load i64, i64* %9
%32 = add i64 %31, %30
store i64 %32, i64* %9
%33 = load i64, i64* %10
%34 = load i32, i32* @BUFSIZ
%35 = sext i32 %34 to i64
%36 = icmp ult i64 %33, %35
br i1 %36, label %37, label %38
37: ; preds = %19
br label %39
38: ; preds = %19
br label %15
39: ; preds = %37, %15
%40 = load i64, i64* %9
%41 = load i8*, i8** %7
ret i64 %40
}

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