copy_rest(old, new) int new, old;
{
  int buffer[4096];
  int len;
  while ((len = read(old, buffer, sizeof(buffer))) > 0)
    if (write(new, buffer, len) != len)
      break;
  if (len != 0) {
    perror("Unable to copy the rest of the file");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<copy_rest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    $0x4000,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,-0x4014(%rbp)
cmp    $0x0,%eax
jle    11a3 <copy_rest+0x63>
mov    -0xc(%rbp),%edi
lea    -0x4010(%rbp),%rsi
mov    -0x4014(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    -0x4014(%rbp),%eax
je     119e <copy_rest+0x5e>
jmp    11a3 <copy_rest+0x63>
jmp    1151 <copy_rest+0x11>
cmpl   $0x0,-0x4014(%rbp)
je     11c8 <copy_rest+0x88>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_rest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4008,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    $0x4000,%edx
mov    %r15d,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <read@plt>
test   %eax,%eax
jle    11a3 <copy_rest+0x63>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    %ebp,%eax
je     1160 <copy_rest+0x20>
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jne    118b <copy_rest+0x4b>
add    $0x4008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Unable to copy the rest of the file\00"
define i32 @copy_rest(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4096 x i32]
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %4
%10 = getelementptr inbounds [4096 x i32], [4096 x i32]* %6, i64 0, i64 0
%11 = call i32 (i32, i32*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i32*, i64, ...)*)(i32 %9, i32* %10, i64 16384)
store i32 %11, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = load i32, i32* %5
%15 = getelementptr inbounds [4096 x i32], [4096 x i32]* %6, i64 0, i64 0
%16 = load i32, i32* %7
%17 = call i32 (i32, i32*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i32*, i32, ...)*)(i32 %14, i32* %15, i32 %16)
%18 = load i32, i32* %7
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %13
br label %22
21: ; preds = %13
br label %8
22: ; preds = %20, %8
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
unreachable
27: ; preds = %22
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [36 x i8] c"Unable to copy the rest of the file\00"
define i32 @copy_rest(i32 %0, i32 %1) {
%3 = alloca [4096 x i32]
%4 = bitcast [4096 x i32]* %3 to i8*
%5 = getelementptr inbounds [4096 x i32], [4096 x i32]* %3, i64 0, i64 0
br label %6
6: ; preds = %9, %2
%7 = call i32 (i32, i32*, i64, ...) bitcast (i32 (...)* @read to i32 (i32, i32*, i64, ...)*)(i32 %0, i32* %5, i64 16384)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = call i32 (i32, i32*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i32*, i32, ...)*)(i32 %1, i32* %5, i32 %7)
%11 = icmp eq i32 %10, %7
br i1 %11, label %6, label %14
12: ; preds = %6
%13 = icmp eq i32 %7, 0
br i1 %13, label %16, label %14
14: ; preds = %9, %12
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @perror to i32 (i8*, ...)*)(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
unreachable
16: ; preds = %12
ret i32 undef
}