copy1(file_name) char *file_name;
{
  int fd, bytes_read;
  char inbuf[512];
  if ((fd = open(file_name, 0)) < 0)
    pexit("can't open ", file_name);
  do {
    bytes_read = read(fd, inbuf, 512);
    if (bytes_read < 0)
      pexit("read error on file ", file_name);
    if (bytes_read > 0)
      wr_out(inbuf, bytes_read);
  } while (bytes_read > 0);
  flush();
  close(fd);
}


x86 assembly (clang, -O0):
<copy1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    119a <copy1+0x3a>
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1080 <pexit@plt>
jmp    119f <copy1+0x3f>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
mov    $0x0,%al
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11d4 <copy1+0x74>
mov    -0x10(%rbp),%rsi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1080 <pexit@plt>
cmpl   $0x0,-0x18(%rbp)
jle    11ef <copy1+0x8f>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x0,%al
call   1040 <wr_out@plt>
jmp    11f4 <copy1+0x94>
cmpl   $0x0,-0x18(%rbp)
jg     119f <copy1+0x3f>
mov    $0x0,%al
call   1030 <flush@plt>
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy1>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
xor    %esi,%esi
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    118e <copy1+0x2e>
lea    0xe7c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <pexit@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x200,%edx
xor    %eax,%eax
call   1060 <read@plt>
test   %eax,%eax
js     11d5 <copy1+0x75>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
test   %eax,%eax
je     11e6 <copy1+0x86>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <wr_out@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %eax,%eax
call   1060 <read@plt>
test   %eax,%eax
jns    11b0 <copy1+0x50>
lea    0xe30(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <pexit@plt>
xor    %eax,%eax
call   1030 <flush@plt>
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <close@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"can't open \00"
@.str.1 = [20 x i8] c"read error on file \00"
define i32 @copy1(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %7, i32 0)
store i32 %8, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @pexit to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %1
br label %14
14: ; preds = %31, %13
%15 = load i32, i32* %4
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%17 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %15, i8* %16, i32 512)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @pexit to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %14
%24 = load i32, i32* %5
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @wr_out to i32 (i8*, i32, ...)*)(i8* %27, i32 %28)
br label %30
30: ; preds = %26, %23
br label %31
31: ; preds = %30
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 0
br i1 %33, label %14, label %34
34: ; preds = %31
%35 = call i32 (...) @flush()
%36 = load i32, i32* %4
%37 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %36)
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str = [12 x i8] c"can't open \00"
@.str.1 = [20 x i8] c"read error on file \00"
define i32 @copy1(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %0, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @pexit to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %1
%9 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %4, i8* %3, i32 512)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %16, %8
%12 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @pexit to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
13: ; preds = %8, %16
%14 = phi i32 [ %18, %16 ], [ %9, %8 ]
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @wr_out to i32 (i8*, i32, ...)*)(i8* %3, i32 %14)
%18 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %4, i8* %3, i32 512)
%19 = icmp slt i32 %18, 0
br i1 %19, label %11, label %13
20: ; preds = %13, %11
%21 = call i32 (...) @flush()
%22 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %4)
ret i32 undef
}