char *underline(s)
char *s;
{
  static char ulbuf[16];
  register char *u = ulbuf;
  while (*s) {
    if (*s != ' ') {
      *u++ = '_';
      *u++ = '\b';
    }
    *u++ = *s++;
  }
  *u = '\0';
  return (ulbuf);
}


x86 assembly (clang, -O0):
<underline>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
lea    0x2f21(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     117b <underline+0x7b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1154 <underline+0x54>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5f,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x8,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1113 <underline+0x13>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2ea7(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<underline>:
lea    0x2f29(%rip),%rax
jmp    111a <underline+0x1a>
nopl   0x0(%rax)
add    $0x1,%rdi
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rdi),%ecx
cmp    $0x20,%cl
je     1110 <underline+0x10>
test   %cl,%cl
je     1134 <underline+0x34>
movw   $0x85f,(%rax)
add    $0x2,%rax
movzbl (%rdi),%ecx
jmp    1110 <underline+0x10>
movb   $0x0,(%rax)
lea    0x2ef2(%rip),%rax
ret

LLVM IR (-O0):
@underline.ulbuf = internal global [16 x i8] zeroinitializer
define i8* @underline(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @underline.ulbuf, i64 0, i64 0), i8** %3
br label %4
4: ; preds = %18, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 32
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %3
store i8 95, i8* %14
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %3
store i8 8, i8* %16
br label %18
18: ; preds = %13, %8
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
%21 = load i8, i8* %19
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 %21, i8* %22
br label %4
24: ; preds = %4
%25 = load i8*, i8** %3
store i8 0, i8* %25
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @underline.ulbuf, i64 0, i64 0)
}

LLVM IR (-O2):
@underline.ulbuf = internal global [16 x i8] zeroinitializer
define i8* @underline(i8* nocapture %0) {
br label %2
2: ; preds = %10, %1
%3 = phi i8* [ %0, %1 ], [ %13, %10 ]
%4 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @underline.ulbuf, i64 0, i64 0), %1 ], [ %14, %10 ]
%5 = load i8, i8* %3
switch i8 %5, label %6 [
i8 0, label %15
i8 32, label %10
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %4, i64 1
store i8 95, i8* %4
%8 = getelementptr inbounds i8, i8* %4, i64 2
store i8 8, i8* %7
%9 = load i8, i8* %3
br label %10
10: ; preds = %2, %6
%11 = phi i8 [ %9, %6 ], [ %5, %2 ]
%12 = phi i8* [ %8, %6 ], [ %4, %2 ]
%13 = getelementptr inbounds i8, i8* %3, i64 1
%14 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %11, i8* %12
br label %2
15: ; preds = %2
store i8 0, i8* %4
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @underline.ulbuf, i64 0, i64 0)
}