const char *html_replace(char ch, char *buf) {
  switch (ch) {
  case '<':
    return "&lt;";
  case '>':
    return "&gt;";
  case '"':
    return "&quot;";
  case '\'':
    return "&#039;";
  case '&':
    return "&amp;";
  default:
    break;
  }
  buf[0] = ch;
  buf[1] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<html_replace>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
movsbl -0x9(%rbp),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x1c,%eax
ja     1188 <html_replace+0x88>
mov    -0x20(%rbp),%rax
lea    0xed1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf35(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <html_replace+0xa6>
lea    0xf2a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <html_replace+0xa6>
lea    0xf1f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <html_replace+0xa6>
lea    0xf16(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <html_replace+0xa6>
lea    0xf0d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <html_replace+0xa6>
jmp    118d <html_replace+0x8d>
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<html_replace>:
lea    -0x22(%rdi),%ecx
cmp    $0x1c,%ecx
ja     1127 <html_replace+0x27>
lea    0xf65(%rip),%rax
lea    0xeea(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
lea    0xf58(%rip),%rax
ret
mov    %dil,(%rsi)
movb   $0x0,0x1(%rsi)
mov    %rsi,%rax
ret
lea    0xf53(%rip),%rax
ret
lea    0xf44(%rip),%rax
ret
lea    0xf30(%rip),%rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"&lt;\00"
@.str.1 = [5 x i8] c"&gt;\00"
@.str.2 = [7 x i8] c"&quot;\00"
@.str.3 = [7 x i8] c"&;\00"
@.str.4 = [6 x i8] c"&amp;\00"
define i8* @html_replace(i8 signext %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
store i8 %0, i8* %4
store i8* %1, i8** %5
%6 = load i8, i8* %4
%7 = sext i8 %6 to i32
switch i32 %7, label %13 [
i32 60, label %8
i32 62, label %9
i32 34, label %10
i32 39, label %11
i32 38, label %12
]
8: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
br label %21
9: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %21
10: ; preds = %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %21
11: ; preds = %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %21
12: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %21
13: ; preds = %2
br label %14
14: ; preds = %13
%15 = load i8, i8* %4
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 %15, i8* %17
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %19
%20 = load i8*, i8** %5
store i8* %20, i8** %3
br label %21
21: ; preds = %14, %12, %11, %10, %9, %8
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@.str = [5 x i8] c"&lt;\00"
@.str.1 = [5 x i8] c"&gt;\00"
@.str.2 = [7 x i8] c"&quot;\00"
@.str.3 = [7 x i8] c"&;\00"
@.str.4 = [6 x i8] c"&amp;\00"
define i8* @html_replace(i8 signext %0, i8* writeonly %1) {
%3 = sext i8 %0 to i32
switch i32 %3, label %8 [
i32 60, label %10
i32 62, label %4
i32 34, label %5
i32 39, label %6
i32 38, label %7
]
4: ; preds = %2
br label %10
5: ; preds = %2
br label %10
6: ; preds = %2
br label %10
7: ; preds = %2
br label %10
8: ; preds = %2
store i8 %0, i8* %1
%9 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %9
br label %10
10: ; preds = %2, %8, %7, %6, %5, %4
%11 = phi i8* [ %1, %8 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %7 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %6 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %2 ]
ret i8* %11
}