char *replace(char *p, char c) {
  switch (c) {
  case 'A':
    *p++ = '\xc3';
    *p++ = '\x84';
    break;
  case 'B':
    *p++ = '\xc3';
    *p++ = '\x96';
    break;
  case 'C':
    *p++ = '\xc3';
    *p++ = '\x9c';
    break;
  case 'D':
    *p++ = '\xc3';
    *p++ = '\xa4';
    break;
  case '!':
    *p++ = '\xc3';
    *p++ = '\x97';
    break;
  case '=':
    *p++ = '\xe2';
    *p++ = '\x80';
    *p++ = '\x94';
    break;
  case '~':
    *p++ = '\xf0';
    *p++ = '\x9d';
    *p++ = '\x85';
    *p++ = '\x9e';
    break;
  }
  return p;
}


x86 assembly (clang, -O0):
<replace>:
push   %rbp
mov    %rsp,%rbp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x21,%eax
je     122d <replace+0x12d>
jmp    1123 <replace+0x23>
mov    -0x10(%rbp),%eax
sub    $0x3d,%eax
je     1256 <replace+0x156>
jmp    1134 <replace+0x34>
mov    -0x10(%rbp),%eax
sub    $0x41,%eax
je     1189 <replace+0x89>
jmp    1145 <replace+0x45>
mov    -0x10(%rbp),%eax
sub    $0x42,%eax
je     11b2 <replace+0xb2>
jmp    1156 <replace+0x56>
mov    -0x10(%rbp),%eax
sub    $0x43,%eax
je     11db <replace+0xdb>
jmp    1167 <replace+0x67>
mov    -0x10(%rbp),%eax
sub    $0x44,%eax
je     1204 <replace+0x104>
jmp    1178 <replace+0x78>
mov    -0x10(%rbp),%eax
sub    $0x7e,%eax
je     1291 <replace+0x191>
jmp    12d9 <replace+0x1d9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xc3,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x84,(%rax)
jmp    12d9 <replace+0x1d9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xc3,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x96,(%rax)
jmp    12d9 <replace+0x1d9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xc3,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x9c,(%rax)
jmp    12d9 <replace+0x1d9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xc3,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xa4,(%rax)
jmp    12d9 <replace+0x1d9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xc3,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x97,(%rax)
jmp    12d9 <replace+0x1d9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xe2,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x80,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x94,(%rax)
jmp    12d9 <replace+0x1d9>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xf0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x9d,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x85,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x9e,(%rax)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace>:
mov    %rdi,%rax
lea    -0x21(%rsi),%ecx
cmp    $0x23,%ecx
ja     1125 <replace+0x25>
lea    0xeee(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
movw   $0x97c3,(%rax)
add    $0x2,%rax
ret
cmp    $0x7e,%esi
jne    1142 <replace+0x42>
movl   $0x9e859df0,(%rax)
add    $0x4,%rax
ret
movw   $0x80e2,(%rax)
movb   $0x94,0x2(%rax)
add    $0x3,%rax
ret
movw   $0x84c3,(%rax)
add    $0x2,%rax
ret
movw   $0x96c3,(%rax)
add    $0x2,%rax
ret
movw   $0x9cc3,(%rax)
add    $0x2,%rax
ret
movw   $0xa4c3,(%rax)
add    $0x2,%rax
ret

LLVM IR (-O0):
define i8* @replace(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
switch i32 %6, label %48 [
i32 65, label %7
i32 66, label %12
i32 67, label %17
i32 68, label %22
i32 33, label %27
i32 61, label %32
i32 126, label %39
]
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %3
store i8 -61, i8* %8
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %3
store i8 -124, i8* %10
br label %48
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
store i8 -61, i8* %13
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
store i8 -106, i8* %15
br label %48
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
store i8 -61, i8* %18
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
store i8 -100, i8* %20
br label %48
22: ; preds = %2
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
store i8 -61, i8* %23
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
store i8 -92, i8* %25
br label %48
27: ; preds = %2
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
store i8 -61, i8* %28
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %3
store i8 -105, i8* %30
br label %48
32: ; preds = %2
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
store i8 -30, i8* %33
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
store i8 -128, i8* %35
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %3
store i8 -108, i8* %37
br label %48
39: ; preds = %2
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %3
store i8 -16, i8* %40
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %3
store i8 -99, i8* %42
%44 = load i8*, i8** %3
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %3
store i8 -123, i8* %44
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %3
store i8 -98, i8* %46
br label %48
48: ; preds = %2, %39, %32, %27, %22, %17, %12, %7
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
define i8* @replace(i8* writeonly %0, i8 signext %1) {
%3 = sext i8 %1 to i32
switch i32 %3, label %28 [
i32 65, label %4
i32 66, label %7
i32 67, label %10
i32 68, label %13
i32 33, label %16
i32 61, label %19
i32 126, label %23
]
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -61, i8* %0
%6 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -124, i8* %5
br label %28
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -61, i8* %0
%9 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -106, i8* %8
br label %28
10: ; preds = %2
%11 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -61, i8* %0
%12 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -100, i8* %11
br label %28
13: ; preds = %2
%14 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -61, i8* %0
%15 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -92, i8* %14
br label %28
16: ; preds = %2
%17 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -61, i8* %0
%18 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -105, i8* %17
br label %28
19: ; preds = %2
%20 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -30, i8* %0
%21 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -128, i8* %20
%22 = getelementptr inbounds i8, i8* %0, i64 3
store i8 -108, i8* %21
br label %28
23: ; preds = %2
%24 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -16, i8* %0
%25 = getelementptr inbounds i8, i8* %0, i64 2
store i8 -99, i8* %24
%26 = getelementptr inbounds i8, i8* %0, i64 3
store i8 -123, i8* %25
%27 = getelementptr inbounds i8, i8* %0, i64 4
store i8 -98, i8* %26
br label %28
28: ; preds = %2, %23, %19, %16, %13, %10, %7, %4
%29 = phi i8* [ %0, %2 ], [ %27, %23 ], [ %22, %19 ], [ %18, %16 ], [ %15, %13 ], [ %12, %10 ], [ %9, %7 ], [ %6, %4 ]
ret i8* %29
}