char *ascii2rtf(str)
register unsigned char *str;
{
  static char unsigned buf[512];
  register unsigned char c, *pb = buf;
  while (*pb = c = *str++) {
    switch (c) {
    case '"':
      strcpy(pb, "\\ldblquote");
      pb += 10;
      break;
    case '\'':
      strcpy(pb, "\\lquote");
      pb += 7;
      break;
    case '\\':
      strcpy(pb, "\\\\");
      pb += 2;
      break;
    case '{':
      strcpy(pb, "\\{");
      pb += 2;
      break;
    default:
      if ((c < ' ') || (c > '~')) {
        sprintf(pb, "\\'%02x", c);
        pb += 3;
      }
    case '\n':
      ++pb;
    }
  }
  return ((char *)buf);
}


x86 assembly (clang, -O0):
<ascii2rtf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f0d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rcx
mov    %al,(%rcx)
cmp    $0x0,%al
je     1288 <ascii2rtf+0x168>
movzbl -0x9(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xa,%eax
je     1277 <ascii2rtf+0x157>
jmp    116e <ascii2rtf+0x4e>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     11b2 <ascii2rtf+0x92>
jmp    117f <ascii2rtf+0x5f>
mov    -0x1c(%rbp),%eax
sub    $0x27,%eax
je     11d3 <ascii2rtf+0xb3>
jmp    1190 <ascii2rtf+0x70>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
je     11f4 <ascii2rtf+0xd4>
jmp    11a1 <ascii2rtf+0x81>
mov    -0x1c(%rbp),%eax
sub    $0x7b,%eax
je     1215 <ascii2rtf+0xf5>
jmp    1236 <ascii2rtf+0x116>
mov    -0x18(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    1283 <ascii2rtf+0x163>
mov    -0x18(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x18(%rbp)
jmp    1283 <ascii2rtf+0x163>
mov    -0x18(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    1283 <ascii2rtf+0x163>
mov    -0x18(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    1283 <ascii2rtf+0x163>
movzbl -0x9(%rbp),%eax
cmp    $0x20,%eax
jl     1250 <ascii2rtf+0x130>
movzbl -0x9(%rbp),%eax
cmp    $0x7e,%eax
jle    1272 <ascii2rtf+0x152>
mov    -0x18(%rbp),%rdi
movzbl -0x9(%rbp),%edx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
jmp    1277 <ascii2rtf+0x157>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1137 <ascii2rtf+0x17>
lea    0x2db1(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ascii2rtf>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    (%rdi),%al
mov    %al,0x2f1f(%rip)
test   %al,%al
je     11f4 <ascii2rtf+0xe4>
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0x2f09(%rip),%r14
movabs $0x6f75716c62646c5c,%r12
71 75 6f
lea    0xec9(%rip),%r15
movabs $0x65746f75716c5c,%r13
jmp    1176 <ascii2rtf+0x66>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
movzbl (%rbx),%eax
mov    %al,(%r14)
add    $0x1,%rbx
test   %al,%al
je     11f4 <ascii2rtf+0xe4>
cmp    $0x26,%al
jle    11a0 <ascii2rtf+0x90>
cmp    $0x27,%al
je     11b9 <ascii2rtf+0xa9>
cmp    $0x5c,%al
je     11c2 <ascii2rtf+0xb2>
cmp    $0x7b,%al
jne    11d3 <ascii2rtf+0xc3>
movb   $0x0,0x2(%r14)
movw   $0x7b5c,(%r14)
add    $0x2,%r14
jmp    1164 <ascii2rtf+0x54>
nopw   0x0(%rax,%rax,1)
cmp    $0xa,%al
je     1160 <ascii2rtf+0x50>
cmp    $0x22,%al
jne    11d3 <ascii2rtf+0xc3>
mov    %r12,(%r14)
movl   $0x65746f,0x7(%r14)
add    $0xa,%r14
jmp    1164 <ascii2rtf+0x54>
mov    %r13,(%r14)
add    $0x7,%r14
jmp    1164 <ascii2rtf+0x54>
movb   $0x0,0x2(%r14)
movw   $0x5c5c,(%r14)
add    $0x2,%r14
jmp    1164 <ascii2rtf+0x54>
lea    -0x7f(%rax),%ecx
cmp    $0xa0,%cl
ja     1160 <ascii2rtf+0x50>
movzbl %al,%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x3,%r14
jmp    1160 <ascii2rtf+0x50>
lea    0x2e45(%rip),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ascii2rtf.buf = internal global [512 x i8] zeroinitializer
@.str = [11 x i8] c"\\ldblquote\00"
@.str.1 = [8 x i8] c"\\lquote\00"
@.str.2 = [3 x i8] c"\\\\\00"
@.str.3 = [3 x i8] c"\\{\00"
@.str.4 = [7 x i8] c"\\'%02x\00"
define i8* @ascii2rtf(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @ascii2rtf.buf, i64 0, i64 0), i8** %4
br label %5
5: ; preds = %53, %1
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %2
%8 = load i8, i8* %6
store i8 %8, i8* %3
%9 = load i8*, i8** %4
store i8 %8, i8* %9
%10 = icmp ne i8 %8, 0
br i1 %10, label %11, label %54
11: ; preds = %5
%12 = load i8, i8* %3
%13 = zext i8 %12 to i32
switch i32 %13, label %34 [
i32 34, label %14
i32 39, label %19
i32 92, label %24
i32 123, label %29
i32 10, label %50
]
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = call i8* @strcpy(i8* %15, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 10
store i8* %18, i8** %4
br label %53
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = call i8* @strcpy(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 7
store i8* %23, i8** %4
br label %53
24: ; preds = %11
%25 = load i8*, i8** %4
%26 = call i8* @strcpy(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 2
store i8* %28, i8** %4
br label %53
29: ; preds = %11
%30 = load i8*, i8** %4
%31 = call i8* @strcpy(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8* %33, i8** %4
br label %53
34: ; preds = %11
%35 = load i8, i8* %3
%36 = zext i8 %35 to i32
%37 = icmp slt i32 %36, 32
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load i8, i8* %3
%40 = zext i8 %39 to i32
%41 = icmp sgt i32 %40, 126
br i1 %41, label %42, label %49
42: ; preds = %38, %34
%43 = load i8*, i8** %4
%44 = load i8, i8* %3
%45 = zext i8 %44 to i32
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 3
store i8* %48, i8** %4
br label %49
49: ; preds = %42, %38
br label %50
50: ; preds = %11, %49
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %4
br label %53
53: ; preds = %50, %29, %24, %19, %14
br label %5
54: ; preds = %5
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @ascii2rtf.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@ascii2rtf.buf = internal global [512 x i8] zeroinitializer
@.str = [11 x i8] c"\\ldblquote\00"
@.str.2 = [3 x i8] c"\\\\\00"
@.str.3 = [3 x i8] c"\\{\00"
@.str.4 = [7 x i8] c"\\'%02x\00"
define i8* @ascii2rtf(i8* nocapture %0) {
%2 = load i8, i8* %0
store i8 %2, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @ascii2rtf.buf, i64 0, i64 0)
%3 = icmp eq i8 %2, 0
br i1 %3, label %32, label %4
4: ; preds = %1, %28
%5 = phi i8 [ %30, %28 ], [ %2, %1 ]
%6 = phi i8* [ %8, %28 ], [ %0, %1 ]
%7 = phi i8* [ %29, %28 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @ascii2rtf.buf, i64 0, i64 0), %1 ]
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = zext i8 %5 to i32
switch i8 %5, label %19 [
i8 34, label %10
i8 39, label %12
i8 92, label %15
i8 123, label %17
i8 10, label %25
]
10: ; preds = %4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(11) %7, i8* align 1 dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 11, i1 false)
%11 = getelementptr inbounds i8, i8* %7, i64 10
br label %28
12: ; preds = %4
%13 = bitcast i8* %7 to i64*
store i64 28556994708335708, i64* %13
%14 = getelementptr inbounds i8, i8* %7, i64 7
br label %28
15: ; preds = %4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %7, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 3, i1 false)
%16 = getelementptr inbounds i8, i8* %7, i64 2
br label %28
17: ; preds = %4
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %7, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 3, i1 false)
%18 = getelementptr inbounds i8, i8* %7, i64 2
br label %28
19: ; preds = %4
%20 = add i8 %5, -127
%21 = icmp ult i8 %20, -95
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%24 = getelementptr inbounds i8, i8* %7, i64 3
br label %25
25: ; preds = %22, %19, %4
%26 = phi i8* [ %24, %22 ], [ %7, %19 ], [ %7, %4 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
br label %28
28: ; preds = %25, %17, %15, %12, %10
%29 = phi i8* [ %27, %25 ], [ %18, %17 ], [ %16, %15 ], [ %14, %12 ], [ %11, %10 ]
%30 = load i8, i8* %8
store i8 %30, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %4
32: ; preds = %28, %1
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @ascii2rtf.buf, i64 0, i64 0)
}