int unparse_character(from, to)
char from;
char *to;
{
  char *x = to;
  switch (from) {
  case '\b':
    *x++ = '\\';
    *x++ = 'b';
    break;
  case '\f':
    *x++ = '\\';
    *x++ = 'f';
    break;
  case '\n':
    *x++ = '\\';
    *x++ = 'n';
    break;
  case '\r':
    *x++ = '\\';
    *x++ = 'r';
    break;
  case '\t':
    *x++ = '\\';
    *x++ = 't';
    break;
  case '\\':
    *x++ = '\\';
    *x++ = '\\';
    break;
  case '\'':
    *x++ = '\\';
    *x++ = '\'';
    break;
  case '^':
    *x++ = '\\';
    *x++ = '^';
    break;
  default:
    if (isascii(from))
      if (iscntrl(from)) {
        sprintf(x, "^%c", from == '\177' ? '?' : from + '@');
        x += 2;
      } else
        *x++ = from;
    else {
      sprintf(x, "\\%03o", from);
      x += 4;
    }
    break;
  }
  *x = '\0';
  return (x - to);
}


x86 assembly (clang, -O0):
<unparse_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x8,%eax
je     11d6 <unparse_character+0xa6>
jmp    115f <unparse_character+0x2f>
mov    -0x1c(%rbp),%eax
sub    $0x9,%eax
je     127a <unparse_character+0x14a>
jmp    1170 <unparse_character+0x40>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     1228 <unparse_character+0xf8>
jmp    1181 <unparse_character+0x51>
mov    -0x1c(%rbp),%eax
sub    $0xc,%eax
je     11ff <unparse_character+0xcf>
jmp    1192 <unparse_character+0x62>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     1251 <unparse_character+0x121>
jmp    11a3 <unparse_character+0x73>
mov    -0x1c(%rbp),%eax
sub    $0x27,%eax
je     12cc <unparse_character+0x19c>
jmp    11b4 <unparse_character+0x84>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
je     12a3 <unparse_character+0x173>
jmp    11c5 <unparse_character+0x95>
mov    -0x1c(%rbp),%eax
sub    $0x5e,%eax
je     12f5 <unparse_character+0x1c5>
jmp    131e <unparse_character+0x1ee>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x62,(%rax)
jmp    13d6 <unparse_character+0x2a6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x66,(%rax)
jmp    13d6 <unparse_character+0x2a6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x6e,(%rax)
jmp    13d6 <unparse_character+0x2a6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x72,(%rax)
jmp    13d6 <unparse_character+0x2a6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x74,(%rax)
jmp    13d6 <unparse_character+0x2a6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
jmp    13d6 <unparse_character+0x2a6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x27,(%rax)
jmp    13d6 <unparse_character+0x2a6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5e,(%rax)
jmp    13d6 <unparse_character+0x2a6>
movsbl -0x1(%rbp),%edi
mov    $0x0,%al
call   1050 <isascii@plt>
cmp    $0x0,%eax
je     13af <unparse_character+0x27f>
movsbl -0x1(%rbp),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%eax
je     1396 <unparse_character+0x266>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x7f,%eax
jne    1366 <unparse_character+0x236>
mov    $0x3f,%eax
mov    %eax,-0x2c(%rbp)
jmp    1370 <unparse_character+0x240>
movsbl -0x1(%rbp),%eax
add    $0x40,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xc82(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    13aa <unparse_character+0x27a>
mov    -0x1(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    13d1 <unparse_character+0x2a1>
mov    -0x18(%rbp),%rdi
movsbl -0x1(%rbp),%edx
lea    0xc46(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    13d6 <unparse_character+0x2a6>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unparse_character>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
movsbl %bpl,%ebx
lea    -0x8(%rbx),%eax
cmp    $0x1f,%eax
ja     1164 <unparse_character+0x34>
lea    0xeb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movw   $0x625c,(%r14)
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
cmp    $0x5c,%ebx
je     1208 <unparse_character+0xd8>
cmp    $0x5e,%ebx
jne    1181 <unparse_character+0x51>
movw   $0x5e5c,(%r14)
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <isascii@plt>
test   %eax,%eax
je     1214 <unparse_character+0xe4>
mov    %ebx,%edi
call   1030 <iscntrl@plt>
test   %eax,%eax
je     122d <unparse_character+0xfd>
shl    $0x18,%ebp
add    $0x40,%ebx
cmp    $0x7f000000,%ebp
mov    $0x3f,%edx
cmovne %ebx,%edx
lea    0xec4(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
movw   $0x745c,(%r14)
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
movw   $0x6e5c,(%r14)
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
movw   $0x665c,(%r14)
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
movw   $0x725c,(%r14)
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
movw   $0x275c,(%r14)
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
movw   $0x5c5c,(%r14)
lea    0x2(%r14),%rax
jmp    1234 <unparse_character+0x104>
lea    0xe69(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0x4(%r14),%rax
jmp    1234 <unparse_character+0x104>
lea    0x1(%r14),%rax
mov    %bpl,(%r14)
movb   $0x0,(%rax)
sub    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"^%c\00"
@.str.1 = [6 x i8] c"\\%03o\00"
define i32 @unparse_character(i32 %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8*
%6 = trunc i32 %0 to i8
store i8 %6, i8* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %5
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
switch i32 %9, label %50 [
i32 8, label %10
i32 12, label %15
i32 10, label %20
i32 13, label %25
i32 9, label %30
i32 92, label %35
i32 39, label %40
i32 94, label %45
]
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %5
store i8 92, i8* %11
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
store i8 98, i8* %13
br label %88
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %5
store i8 92, i8* %16
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
store i8 102, i8* %18
br label %88
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
store i8 92, i8* %21
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 110, i8* %23
br label %88
25: ; preds = %2
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
store i8 92, i8* %26
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
store i8 114, i8* %28
br label %88
30: ; preds = %2
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
store i8 92, i8* %31
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %5
store i8 116, i8* %33
br label %88
35: ; preds = %2
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %5
store i8 92, i8* %36
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
store i8 92, i8* %38
br label %88
40: ; preds = %2
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %5
store i8 92, i8* %41
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %5
store i8 39, i8* %43
br label %88
45: ; preds = %2
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %5
store i8 92, i8* %46
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %5
store i8 94, i8* %48
br label %88
50: ; preds = %2
%51 = load i8, i8* %3
%52 = sext i8 %51 to i32
%53 = call i32 (i32, ...) bitcast (i32 (...)* @isascii to i32 (i32, ...)*)(i32 %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %80
55: ; preds = %50
%56 = load i8, i8* %3
%57 = sext i8 %56 to i32
%58 = call i32 @iscntrl(i32 %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %75
60: ; preds = %55
%61 = load i8*, i8** %5
%62 = load i8, i8* %3
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 127
br i1 %64, label %65, label %66
65: ; preds = %60
br label %70
66: ; preds = %60
%67 = load i8, i8* %3
%68 = sext i8 %67 to i32
%69 = add nsw i32 %68, 64
br label %70
70: ; preds = %66, %65
%71 = phi i32 [ 63, %65 ], [ %69, %66 ]
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %71)
%73 = load i8*, i8** %5
%74 = getelementptr inbounds i8, i8* %73, i64 2
store i8* %74, i8** %5
br label %79
75: ; preds = %55
%76 = load i8, i8* %3
%77 = load i8*, i8** %5
%78 = getelementptr inbounds i8, i8* %77, i32 1
store i8* %78, i8** %5
store i8 %76, i8* %77
br label %79
79: ; preds = %75, %70
br label %87
80: ; preds = %50
%81 = load i8*, i8** %5
%82 = load i8, i8* %3
%83 = sext i8 %82 to i32
%84 = call i32 (i8*, i8*, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %83)
%85 = load i8*, i8** %5
%86 = getelementptr inbounds i8, i8* %85, i64 4
store i8* %86, i8** %5
br label %87
87: ; preds = %80, %79
br label %88
88: ; preds = %87, %45, %40, %35, %30, %25, %20, %15, %10
%89 = load i8*, i8** %5
store i8 0, i8* %89
%90 = load i8*, i8** %5
%91 = load i8*, i8** %4
%92 = ptrtoint i8* %90 to i64
%93 = ptrtoint i8* %91 to i64
%94 = sub i64 %92, %93
%95 = trunc i64 %94 to i32
ret i32 %95
}

LLVM IR (-O2):
@.str = [4 x i8] c"^%c\00"
@.str.1 = [6 x i8] c"\\%03o\00"
define i32 @unparse_character(i32 %0, i8* %1) {
%3 = trunc i32 %0 to i8
%4 = shl i32 %0, 24
%5 = ashr exact i32 %4, 24
switch i32 %5, label %30 [
i32 8, label %6
i32 12, label %9
i32 10, label %12
i32 13, label %15
i32 9, label %18
i32 92, label %21
i32 39, label %24
i32 94, label %27
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %1, i64 1
store i8 92, i8* %1
%8 = getelementptr inbounds i8, i8* %1, i64 2
store i8 98, i8* %7
br label %47
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %1, i64 1
store i8 92, i8* %1
%11 = getelementptr inbounds i8, i8* %1, i64 2
store i8 102, i8* %10
br label %47
12: ; preds = %2
%13 = getelementptr inbounds i8, i8* %1, i64 1
store i8 92, i8* %1
%14 = getelementptr inbounds i8, i8* %1, i64 2
store i8 110, i8* %13
br label %47
15: ; preds = %2
%16 = getelementptr inbounds i8, i8* %1, i64 1
store i8 92, i8* %1
%17 = getelementptr inbounds i8, i8* %1, i64 2
store i8 114, i8* %16
br label %47
18: ; preds = %2
%19 = getelementptr inbounds i8, i8* %1, i64 1
store i8 92, i8* %1
%20 = getelementptr inbounds i8, i8* %1, i64 2
store i8 116, i8* %19
br label %47
21: ; preds = %2
%22 = getelementptr inbounds i8, i8* %1, i64 1
store i8 92, i8* %1
%23 = getelementptr inbounds i8, i8* %1, i64 2
store i8 92, i8* %22
br label %47
24: ; preds = %2
%25 = getelementptr inbounds i8, i8* %1, i64 1
store i8 92, i8* %1
%26 = getelementptr inbounds i8, i8* %1, i64 2
store i8 39, i8* %25
br label %47
27: ; preds = %2
%28 = getelementptr inbounds i8, i8* %1, i64 1
store i8 92, i8* %1
%29 = getelementptr inbounds i8, i8* %1, i64 2
store i8 94, i8* %28
br label %47
30: ; preds = %2
%31 = tail call i32 (i32, ...) bitcast (i32 (...)* @isascii to i32 (i32, ...)*)(i32 %5)
%32 = icmp eq i32 %31, 0
br i1 %32, label %44, label %33
33: ; preds = %30
%34 = tail call i32 @iscntrl(i32 %5)
%35 = icmp eq i32 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %33
%37 = icmp eq i32 %4, 2130706432
%38 = add nsw i32 %5, 64
%39 = select i1 %37, i32 63, i32 %38
%40 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds i8, i8* %1, i64 2
br label %47
42: ; preds = %33
%43 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %3, i8* %1
br label %47
44: ; preds = %30
%45 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%46 = getelementptr inbounds i8, i8* %1, i64 4
br label %47
47: ; preds = %44, %42, %36, %27, %24, %21, %18, %15, %12, %9, %6
%48 = phi i8* [ %41, %36 ], [ %43, %42 ], [ %46, %44 ], [ %29, %27 ], [ %26, %24 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ], [ %14, %12 ], [ %11, %9 ], [ %8, %6 ]
store i8 0, i8* %48
%49 = ptrtoint i8* %48 to i64
%50 = ptrtoint i8* %1 to i64
%51 = sub i64 %49, %50
%52 = trunc i64 %51 to i32
ret i32 %52
}