copy_file(old, new, size) int new, old;
int size;
{
  int len;
  int buffer[8196];
  for (; size > 0; size -= len) {
    len = (((size) < (sizeof(buffer))) ? (size) : (sizeof(buffer)));
    if (read(old, buffer, len) != len) {
      perror("Read failure on a.out file");
      exit(1);
    }
    if (write(new, buffer, len) != len) {
      perror("Write failure in a.out file");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8040,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1218 <copy_file+0xd8>
movslq -0x10(%rbp),%rax
cmp    $0x8010,%rax
jae    117e <copy_file+0x3e>
movslq -0x10(%rbp),%rax
mov    %rax,-0x8038(%rbp)
jmp    118f <copy_file+0x4f>
mov    $0x8010,%eax
mov    %rax,-0x8038(%rbp)
jmp    118f <copy_file+0x4f>
mov    -0x8038(%rbp),%rax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x8030(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1040 <read@plt>
cmp    -0x14(%rbp),%eax
je     11ce <copy_file+0x8e>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x8030(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
je     1203 <copy_file+0xc3>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1208 <copy_file+0xc8>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    1154 <copy_file+0x14>
mov    -0x4(%rbp),%eax
add    $0x8040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x8010,%rsp
test   %edx,%edx
jle    119a <copy_file+0x5a>
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rsp,%r12
xchg   %ax,%ax
cmp    $0x8010,%ebx
mov    $0x8010,%ebp
cmovb  %ebx,%ebp
mov    %r15d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <read@plt>
cmp    %ebp,%eax
jne    11aa <copy_file+0x6a>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    %ebp,%eax
jne    11b3 <copy_file+0x73>
sub    %ebp,%ebx
test   %ebx,%ebx
jg     1160 <copy_file+0x20>
add    $0x8010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe4f(%rip),%rdi
jmp    11ba <copy_file+0x7a>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Read failure on a.out file\00"
@.str.1 = [28 x i8] c"Write failure in a.out file\00"
define i32 @copy_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [8196 x i32]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
br label %10
10: ; preds = %42, %3
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %46
13: ; preds = %10
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = icmp ult i64 %15, 32784
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
br label %21
20: ; preds = %13
br label %21
21: ; preds = %20, %17
%22 = phi i64 [ %19, %17 ], [ 32784, %20 ]
%23 = trunc i64 %22 to i32
store i32 %23, i32* %8
%24 = load i32, i32* %5
%25 = getelementptr inbounds [8196 x i32], [8196 x i32]* %9, i64 0, i64 0
%26 = load i32, i32* %8
%27 = call i32 (i32, i32*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i32*, i32, ...)*)(i32 %24, i32* %25, i32 %26)
%28 = load i32, i32* %8
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
unreachable
32: ; preds = %21
%33 = load i32, i32* %6
%34 = getelementptr inbounds [8196 x i32], [8196 x i32]* %9, i64 0, i64 0
%35 = load i32, i32* %8
%36 = call i32 (i32, i32*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i32*, i32, ...)*)(i32 %33, i32* %34, i32 %35)
%37 = load i32, i32* %8
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
unreachable
41: ; preds = %32
br label %42
42: ; preds = %41
%43 = load i32, i32* %8
%44 = load i32, i32* %7
%45 = sub nsw i32 %44, %43
store i32 %45, i32* %7
br label %10
46: ; preds = %10
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@.str = [27 x i8] c"Read failure on a.out file\00"
@.str.1 = [28 x i8] c"Write failure in a.out file\00"
define i32 @copy_file(i32 %0, i32 %1, i32 %2) {
%4 = alloca [8196 x i32]
%5 = bitcast [8196 x i32]* %4 to i8*
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %25
7: ; preds = %3
%8 = getelementptr inbounds [8196 x i32], [8196 x i32]* %4, i64 0, i64 0
br label %11
9: ; preds = %19
%10 = icmp sgt i32 %22, 0
br i1 %10, label %11, label %25
11: ; preds = %7, %9
%12 = phi i32 [ %2, %7 ], [ %22, %9 ]
%13 = icmp ult i32 %12, 32784
%14 = select i1 %13, i32 %12, i32 32784
%15 = call i32 (i32, i32*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i32*, i32, ...)*)(i32 %0, i32* %8, i32 %14)
%16 = icmp eq i32 %15, %14
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
unreachable
19: ; preds = %11
%20 = call i32 (i32, i32*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i32*, i32, ...)*)(i32 %1, i32* %8, i32 %14)
%21 = icmp eq i32 %20, %14
%22 = sub nsw i32 %12, %14
br i1 %21, label %9, label %23
23: ; preds = %19
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
unreachable
25: ; preds = %9, %3
ret i32 undef
}