char const *renderchar(unsigned char c) {
  static char buf[5];
  char *s = buf;
  for (;;) {
    if (c < 32) {
      *s++ = '^';
      *s++ = '@' + c;
      *s++ = '\0';
      return buf;
    }
    if (c < 0177) {
      *s++ = c;
      *s++ = '\0';
      return buf;
    }
    if (c == 0177) {
      *s++ = '^';
      *s++ = '?';
      *s++ = '\0';
      return buf;
    }
    c -= 128;
    *s++ = 'M';
    *s++ = '-';
  }
}


x86 assembly (clang, -O0):
<renderchar>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x9(%rbp)
lea    0x2f10(%rip),%rax
mov    %rax,-0x18(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x20,%eax
jge    1170 <renderchar+0x70>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5e,(%rax)
movzbl -0x9(%rbp),%eax
add    $0x40,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
lea    0x2eba(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123b <renderchar+0x13b>
movzbl -0x9(%rbp),%eax
cmp    $0x7f,%eax
jge    11b3 <renderchar+0xb3>
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
lea    0x2e77(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123b <renderchar+0x13b>
movzbl -0x9(%rbp),%eax
cmp    $0x7f,%eax
jne    1206 <renderchar+0x106>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5e,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x3f,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
lea    0x2e24(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123b <renderchar+0x13b>
movzbl -0x9(%rbp),%eax
sub    $0x80,%eax
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x4d,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
jmp    1115 <renderchar+0x15>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<renderchar>:
cmp    $0x20,%dil
jae    110f <renderchar+0xf>
lea    0x2f14(%rip),%rax
jmp    1144 <renderchar+0x44>
lea    0x2f0c(%rip),%rax
cs nopw 0x0(%rax,%rax,1)
cmp    $0x7e,%dil
jbe    1155 <renderchar+0x55>
cmp    $0x7f,%dil
je     115b <renderchar+0x5b>
movw   $0x2d4d,-0x1(%rax)
add    $0x2,%rax
add    $0x80,%dil
cmp    $0x20,%dil
jae    1120 <renderchar+0x20>
add    $0xffffffffffffffff,%rax
movb   $0x5e,(%rax)
add    $0x40,%dil
mov    %dil,0x1(%rax)
add    $0x2,%rax
jmp    1165 <renderchar+0x65>
mov    %dil,-0x1(%rax)
jmp    1165 <renderchar+0x65>
movw   $0x3f5e,-0x1(%rax)
add    $0x1,%rax
movb   $0x0,(%rax)
lea    0x2eb2(%rip),%rax
ret

LLVM IR (-O0):
@renderchar.buf = internal global [5 x i8] zeroinitializer
define i8* @renderchar(i8 zeroext %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
store i8 %0, i8* %3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @renderchar.buf, i64 0, i64 0), i8** %4
br label %5
5: ; preds = %41, %1
%6 = load i8, i8* %3
%7 = zext i8 %6 to i32
%8 = icmp slt i32 %7, 32
br i1 %8, label %9, label %20
9: ; preds = %5
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %4
store i8 94, i8* %10
%12 = load i8, i8* %3
%13 = zext i8 %12 to i32
%14 = add nsw i32 64, %13
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %4
store i8 %15, i8* %16
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %4
store i8 0, i8* %18
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @renderchar.buf, i64 0, i64 0), i8** %2
br label %50
20: ; preds = %5
%21 = load i8, i8* %3
%22 = zext i8 %21 to i32
%23 = icmp slt i32 %22, 127
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8, i8* %3
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
store i8 %25, i8* %26
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 0, i8* %28
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @renderchar.buf, i64 0, i64 0), i8** %2
br label %50
30: ; preds = %20
%31 = load i8, i8* %3
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 127
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
store i8 94, i8* %35
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
store i8 63, i8* %37
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %4
store i8 0, i8* %39
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @renderchar.buf, i64 0, i64 0), i8** %2
br label %50
41: ; preds = %30
%42 = load i8, i8* %3
%43 = zext i8 %42 to i32
%44 = sub nsw i32 %43, 128
%45 = trunc i32 %44 to i8
store i8 %45, i8* %3
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
store i8 77, i8* %46
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %4
store i8 45, i8* %48
br label %5
50: ; preds = %34, %24, %9
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
@renderchar.buf = internal global [5 x i8] zeroinitializer
define i8* @renderchar(i8 zeroext %0) {
%2 = icmp ult i8 %0, 32
br i1 %2, label %3, label %9
3: ; preds = %20, %1
%4 = phi i8 [ %0, %1 ], [ %21, %20 ]
%5 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @renderchar.buf, i64 0, i64 0), %1 ], [ %23, %20 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8 94, i8* %5
%7 = add nuw nsw i8 %4, 64
%8 = getelementptr inbounds i8, i8* %5, i64 2
store i8 %7, i8* %6
br label %25
9: ; preds = %1, %20
%10 = phi i8* [ %23, %20 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @renderchar.buf, i64 0, i64 0), %1 ]
%11 = phi i8 [ %21, %20 ], [ %0, %1 ]
%12 = icmp ult i8 %11, 127
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %11, i8* %10
br label %25
15: ; preds = %9
%16 = icmp eq i8 %11, 127
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = getelementptr inbounds i8, i8* %10, i64 1
store i8 94, i8* %10
%19 = getelementptr inbounds i8, i8* %10, i64 2
store i8 63, i8* %18
br label %25
20: ; preds = %15
%21 = xor i8 %11, -128
%22 = getelementptr inbounds i8, i8* %10, i64 1
store i8 77, i8* %10
%23 = getelementptr inbounds i8, i8* %10, i64 2
store i8 45, i8* %22
%24 = icmp ult i8 %21, 32
br i1 %24, label %3, label %9
25: ; preds = %17, %13, %3
%26 = phi i8* [ %19, %17 ], [ %14, %13 ], [ %8, %3 ]
store i8 0, i8* %26
ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @renderchar.buf, i64 0, i64 0)
}