void write_line(int fd, char *buf) {
  int len = strlen(buf);
  char eol[] = "\r";
  info(3, "%s: sending '%s'\n", __func__, buf);
  write_loop(fd, buf, len);
  write_loop(fd, eol, 2);
}


x86 assembly (clang, -O0):
<write_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    0xeae(%rip),%ax
mov    %ax,-0x16(%rbp)
mov    -0x10(%rbp),%rcx
mov    $0x3,%edi
lea    0xe9c(%rip),%rsi
lea    0xea7(%rip),%rdx
mov    $0x0,%al
call   1050 <info@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1040 <write_loop@plt>
mov    -0x4(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x2,%edx
mov    $0x0,%al
call   1040 <write_loop@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_line>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
movw   $0xd,0xe(%rsp)
lea    0xeaa(%rip),%rsi
lea    0xeb5(%rip),%rdx
mov    $0x3,%edi
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <info@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <write_loop@plt>
lea    0xe(%rsp),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <write_loop@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.write_line.eol = [2 x i8] c"\0D\00"
@.str = [18 x i8] c"%s: sending '%s'\0A\00"
@__func__.write_line = [11 x i8] c"write_line\00"
define void @write_line(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [2 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
%10 = bitcast [2 x i8]* %6 to i8*
%11 = load i8*, i8** %4
%12 = call i32 (i32, i8*, i8*, i8*, ...) bitcast (i32 (...)* @info to i32 (i32, i8*, i8*, i8*, ...)*)(i32 3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__func__.write_line, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %3
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write_loop to i32 (i32, i8*, i32, ...)*)(i32 %13, i8* %14, i32 %15)
%17 = load i32, i32* %3
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%19 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write_loop to i32 (i32, i8*, i32, ...)*)(i32 %17, i8* %18, i32 2)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"%s: sending '%s'\0A\00"
@__func__.write_line = [11 x i8] c"write_line\00"
define void @write_line(i32 %0, i8* %1) {
%3 = alloca i16
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = trunc i64 %4 to i32
%6 = bitcast i16* %3 to i8*
store i16 13, i16* %3
%7 = tail call i32 (i32, i8*, i8*, i8*, ...) bitcast (i32 (...)* @info to i32 (i32, i8*, i8*, i8*, ...)*)(i32 3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__func__.write_line, i64 0, i64 0), i8* %1)
%8 = tail call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write_loop to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %1, i32 %5)
%9 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write_loop to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %6, i32 2)
ret void
}