#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 fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int FileCopy(FILE *in, FILE *out) {
  int result;
  unsigned char *buf;
  buf = (unsigned char *)malloc(16384);
  do {
    result = fread(buf, 16384, 1, in);
    fwrite(buf, result, 1, out);
  } while (result == 16384);
  free(buf);
  return 1;
}


x86 assembly (clang, -O0):
<FileCopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4000,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1060 <fwrite@plt>
cmpl   $0x4000,-0x14(%rbp)
je     115e <FileCopy+0x1e>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileCopy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x4000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x4000,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
cmp    $0x4000,%ebp
je     1160 <FileCopy+0x20>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FileCopy(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = call i64 @malloc(i32 16384)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %6
br label %9
9: ; preds = %17, %2
%10 = load i8*, i8** %6
%11 = load i32*, i32** %3
%12 = call i32 @fread(i8* %10, i32 16384, i32 1, i32* %11)
store i32 %12, i32* %5
%13 = load i8*, i8** %6
%14 = load i32, i32* %5
%15 = load i32*, i32** %4
%16 = call i32 @fwrite(i8* %13, i32 %14, i32 1, i32* %15)
br label %17
17: ; preds = %9
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 16384
br i1 %19, label %9, label %20
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = call i32 @free(i8* %21)
ret i32 1
}

LLVM IR (-O2):
define i32 @FileCopy(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i64 @malloc(i32 16384)
%4 = inttoptr i64 %3 to i8*
br label %5
5: ; preds = %5, %2
%6 = tail call i32 @fread(i8* %4, i32 16384, i32 1, i32* %0)
%7 = tail call i32 @fwrite(i8* %4, i32 %6, i32 1, i32* %1)
%8 = icmp eq i32 %6, 16384
br i1 %8, label %5, label %9
9: ; preds = %5
%10 = tail call i32 @free(i8* %4)
ret i32 1
}