int _write(fd, buf, nbytes)
int fd;
char *buf;
int nbytes;
{
  int i;
  for (i = 0; i < nbytes; i++) {
    if (*(buf + i) == '\n') {
      outbyte('\r');
    }
    outbyte(*(buf + i));
  }
  return (nbytes);
}


x86 assembly (clang, -O0):
<_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1177 <_write+0x67>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1156 <_write+0x46>
mov    $0xd,%edi
mov    $0x0,%al
call   1030 <outbyte@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1030 <outbyte@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1129 <_write+0x19>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
test   %edx,%edx
jle    115d <_write+0x4d>
mov    %rsi,%rbx
mov    %r14d,%r15d
xor    %ebp,%ebp
jmp    1143 <_write+0x33>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
xor    %eax,%eax
call   1030 <outbyte@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
je     115d <_write+0x4d>
movzbl (%rbx,%rbp,1),%eax
cmp    $0xa,%al
jne    1130 <_write+0x20>
mov    $0xd,%edi
xor    %eax,%eax
call   1030 <outbyte@plt>
movzbl (%rbx,%rbp,1),%eax
jmp    1130 <_write+0x20>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_write(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %30, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %33
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 (i32, ...) bitcast (i32 (...)* @outbyte to i32 (i32, ...)*)(i32 13)
br label %22
22: ; preds = %20, %12
%23 = load i8*, i8** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = call i32 (i32, ...) bitcast (i32 (...)* @outbyte to i32 (i32, ...)*)(i32 %28)
br label %30
30: ; preds = %22
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %8
33: ; preds = %8
%34 = load i32, i32* %6
ret i32 %34
}

LLVM IR (-O2):
define i32 @_write(i32 %0, i8* nocapture %1, i32 returned %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %21
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %15
%8 = phi i64 [ 0, %5 ], [ %19, %15 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = tail call i32 (i32, ...) bitcast (i32 (...)* @outbyte to i32 (i32, ...)*)(i32 13)
%14 = load i8, i8* %9
br label %15
15: ; preds = %12, %7
%16 = phi i8 [ %14, %12 ], [ %10, %7 ]
%17 = sext i8 %16 to i32
%18 = tail call i32 (i32, ...) bitcast (i32 (...)* @outbyte to i32 (i32, ...)*)(i32 %17)
%19 = add nuw nsw i64 %8, 1
%20 = icmp eq i64 %19, %6
br i1 %20, label %21, label %7
21: ; preds = %15, %3
ret i32 %2
}