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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ *xfopen(char const *, char *);
void copy_file(const char *source, const char *destination) {
  FILE *in, *out;
  char buffer[BUFSIZ];
  size_t nread;
  assert(source != NULL && destination != NULL);
  in = xfopen(source, "rb");
  out = xfopen(destination, "wb");
  while ((nread = fread(buffer, 1, sizeof(buffer), in)) > 0) {
    if (fwrite(buffer, 1, nread, out) != nread)
      die("copy_file");
  }
  fclose(in);
  fclose(out);
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x39(%rbp)
je     11bb <copy_file+0x5b>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1040 <xfopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1040 <xfopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jbe    1247 <copy_file+0xe7>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
cmp    -0x38(%rbp),%rax
je     1242 <copy_file+0xe2>
lea    0xdc9(%rip),%rdi
call   1070 <die@plt>
jmp    11f0 <copy_file+0x90>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2e65(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
lea    0xe51(%rip),%rsi
mov    %r15,%rdi
call   1040 <xfopen@plt>
mov    %rax,%r15
lea    0xe42(%rip),%rsi
mov    %r12,%rdi
call   1040 <xfopen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1231 <copy_file+0xd1>
mov    %rax,%r13
jmp    120b <copy_file+0xab>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rax,%r13
test   %rax,%rax
je     1231 <copy_file+0xd1>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %r12,%rcx
call   1080 <fwrite@plt>
cmp    %r13,%rax
je     11f0 <copy_file+0x90>
lea    0xddc(%rip),%rdi
call   1070 <die@plt>
jmp    11f0 <copy_file+0x90>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [10 x i8] c"copy_file\00"
define void @copy_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br label %19
19: ; preds = %16, %2
%20 = phi i1 [ false, %2 ], [ %18, %16 ]
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %3
%24 = call i32* @xfopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %5
%25 = load i8*, i8** %4
%26 = call i32* @xfopen(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %6
br label %27
27: ; preds = %40, %19
%28 = trunc i64 %11 to i32
%29 = load i32*, i32** %5
%30 = call i64 @fread(i8* %13, i32 1, i32 %28, i32* %29)
store i64 %30, i64* %9
%31 = icmp ugt i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i64, i64* %9
%34 = load i32*, i32** %6
%35 = call i64 @fwrite(i8* %13, i32 1, i64 %33, i32* %34)
%36 = load i64, i64* %9
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 @die(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %32
br label %27
41: ; preds = %27
%42 = load i32*, i32** %5
%43 = call i32 @fclose(i32* %42)
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
%46 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [10 x i8] c"copy_file\00"
define void @copy_file(i8* %0, i8* %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp ne i8* %0, null
%7 = icmp ne i8* %1, null
%8 = and i1 %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32* @xfopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32* @xfopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 @fread(i8* %5, i32 1, i32 %3, i32* %11)
%14 = icmp eq i64 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %2, %21
%16 = phi i64 [ %22, %21 ], [ %13, %2 ]
%17 = call i64 @fwrite(i8* %5, i32 1, i64 %16, i32* %12)
%18 = icmp eq i64 %17, %16
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @die(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = call i64 @fread(i8* %5, i32 1, i32 %3, i32* %11)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %15
24: ; preds = %21, %2
%25 = tail call i32 @fclose(i32* %11)
%26 = tail call i32 @fclose(i32* %12)
ret void
}