unsigned char unescape(unsigned char c) {
  static unsigned char escapes[] = "#&!*$";
  static unsigned char escaped[] = "\r\n<>@";
  int i = 0;
  if (c > 127)
    return c;
  while (escapes[i]) {
    if (escapes[i] == c)
      return escaped[i];
    i++;
  }
  return '?';
}


x86 assembly (clang, -O0):
<unescape>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movl   $0x0,-0x8(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x7f,%eax
jle    1129 <unescape+0x29>
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1186 <unescape+0x86>
jmp    112e <unescape+0x2e>
movslq -0x8(%rbp),%rcx
lea    0x2ee7(%rip),%rax
cmpb   $0x0,(%rax,%rcx,1)
je     1182 <unescape+0x82>
movslq -0x8(%rbp),%rcx
lea    0x2ed2(%rip),%rax
movzbl (%rax,%rcx,1),%eax
movzbl -0x2(%rbp),%ecx
cmp    %ecx,%eax
jne    1174 <unescape+0x74>
movslq -0x8(%rbp),%rcx
lea    0x2ebd(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x1(%rbp)
jmp    1186 <unescape+0x86>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112e <unescape+0x2e>
movb   $0x3f,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<unescape>:
test   %dil,%dil
js     1139 <unescape+0x39>
add    $0xdf,%dil
mov    $0x3f,%al
cmp    $0x9,%dil
ja     1138 <unescape+0x38>
movzbl %dil,%ecx
mov    $0x22d,%edx
bt     %ecx,%edx
jae    1138 <unescape+0x38>
movsbq %dil,%rax
lea    0xede(%rip),%rcx
mov    (%rcx,%rax,8),%rax
lea    0xecb(%rip),%rcx
mov    (%rax,%rcx,1),%al
ret
mov    %edi,%eax
ret

LLVM IR (-O0):
@unescape.escapes = internal global [6 x i8] c"#&!*$\00"
@unescape.escaped = internal global [6 x i8] c"\0D\0A<>@\00"
define zeroext i8 @unescape(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
store i8 %0, i8* %3
store i32 0, i32* %4
%5 = load i8, i8* %3
%6 = zext i8 %5 to i32
%7 = icmp sgt i32 %6, 127
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i8, i8* %3
store i8 %9, i8* %2
br label %35
10: ; preds = %1
br label %11
11: ; preds = %31, %10
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [6 x i8], [6 x i8]* @unescape.escapes, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %11
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [6 x i8], [6 x i8]* @unescape.escapes, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = load i8, i8* %3
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [6 x i8], [6 x i8]* @unescape.escaped, i64 0, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %2
br label %35
31: ; preds = %17
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %11
34: ; preds = %11
store i8 63, i8* %2
br label %35
35: ; preds = %34, %26, %8
%36 = load i8, i8* %2
ret i8 %36
}

LLVM IR (-O2):
@unescape.escaped = internal unnamed_addr constant [6 x i8] c"\0D\0A<>@\00"
@switch.table.unescape = [10 x i64] [i64 2, i64 0, i64 0, i64 4, i64 0, i64 1, i64 0, i64 0, i64 0, i64 3]
define zeroext i8 @unescape(i8 zeroext %0) {
%2 = icmp slt i8 %0, 0
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = add i8 %0, -33
%5 = icmp ult i8 %4, 10
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = zext i8 %4 to i16
%8 = lshr i16 557, %7
%9 = and i16 %8, 1
%10 = icmp eq i16 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %6
%12 = sext i8 %4 to i64
%13 = getelementptr inbounds [10 x i64], [10 x i64]* @switch.table.unescape, i64 0, i64 %12
%14 = load i64, i64* %13
%15 = getelementptr inbounds [6 x i8], [6 x i8]* @unescape.escaped, i64 0, i64 %14
%16 = load i8, i8* %15
br label %17
17: ; preds = %6, %3, %1, %11
%18 = phi i8 [ %16, %11 ], [ %0, %1 ], [ 63, %3 ], [ 63, %6 ]
ret i8 %18
}