const char *show_tilde(const char *str) {
  static char buf[4096];
  char *bufptr;
  bufptr = buf;
  for (; *str != '\0'; str++, bufptr++) {
    if (*str == '*')
      *bufptr = '~';
    else
      *bufptr = *str;
  }
  *bufptr = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<show_tilde>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
lea    0x2f21(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     116d <show_tilde+0x6d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    113f <show_tilde+0x3f>
mov    -0x10(%rbp),%rax
movb   $0x7e,(%rax)
jmp    114b <show_tilde+0x4b>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1150 <show_tilde+0x50>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1113 <show_tilde+0x13>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2eb5(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_tilde>:
xor    %ecx,%ecx
lea    0x2f27(%rip),%rax
jmp    1118 <show_tilde+0x18>
nopl   0x0(%rax,%rax,1)
mov    %sil,(%rcx,%rax,1)
add    $0x1,%rcx
movzbl (%rdi,%rcx,1),%edx
mov    $0x7e,%sil
cmp    $0x2a,%dl
je     1110 <show_tilde+0x10>
test   %dl,%dl
je     112c <show_tilde+0x2c>
mov    %edx,%esi
jmp    1110 <show_tilde+0x10>
movb   $0x0,(%rcx,%rax,1)
ret

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

LLVM IR (-O2):
@show_tilde.buf = internal global [4096 x i8] zeroinitializer
define i8* @show_tilde(i8* nocapture %0) {
br label %2
2: ; preds = %7, %1
%3 = phi i8* [ %0, %1 ], [ %9, %7 ]
%4 = phi i8* [ getelementptr inbounds ([4096 x i8], [4096 x i8]* @show_tilde.buf, i64 0, i64 0), %1 ], [ %10, %7 ]
%5 = load i8, i8* %3
switch i8 %5, label %6 [
i8 0, label %11
i8 42, label %7
]
6: ; preds = %2
br label %7
7: ; preds = %2, %6
%8 = phi i8 [ %5, %6 ], [ 126, %2 ]
store i8 %8, i8* %4
%9 = getelementptr inbounds i8, i8* %3, i64 1
%10 = getelementptr inbounds i8, i8* %4, i64 1
br label %2
11: ; preds = %2
store i8 0, i8* %4
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @show_tilde.buf, i64 0, i64 0)
}