int copy_block(f, t)
int f, t;
{
  int bytes;
  char buf[4096];
  if ((bytes = read(f, buf, 4096)) > 0) {
    if (write(t, buf, bytes) != bytes) {
      perror("write");
      exit(1);
    }
  } else if (bytes < 0) {
    perror("read");
  }
  return bytes;
}


x86 assembly (clang, -O0):
<copy_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    11ad <copy_block+0x6d>
mov    -0x8(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    -0xc(%rbp),%eax
je     11a8 <copy_block+0x68>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11ca <copy_block+0x8a>
cmpl   $0x0,-0xc(%rbp)
jge    11c5 <copy_block+0x85>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <perror@plt>
jmp    11ca <copy_block+0x8a>
mov    -0xc(%rbp),%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_block>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%ebp
mov    %rsp,%rsi
mov    $0x1000,%edx
xor    %eax,%eax
call   1040 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    118a <copy_block+0x4a>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    %ebx,%eax
je     119a <copy_block+0x5a>
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jns    119a <copy_block+0x5a>
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1050 <perror@plt>
mov    %ebx,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret

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

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