char *conv_text(s, t)
char *s, *t;
{
  char *r;
  r = s;
  while (*t != '\0') {
    switch (*t) {
    case '\t':
      *s++ = '\\';
      *s++ = 't';
      break;
    case '\n':
      *s++ = '\\';
      *s++ = 'n';
      break;
    case '\r':
      *s++ = '\\';
      *s++ = 'r';
      break;
    case '"':
    case '\\':
      *s++ = '\\';
      *s++ = *t;
      break;
    default: {
      if ((*t & 0177) > 31 && (*t & 0177) < 127)
        *s++ = *t;
      else {
        *s++ = '\\';
        sprintf(s, "%o", *t);
        while (*s != '\0')
          s++;
      }
    }
    }
    t++;
  }
  *s = '\0';
  return (r);
}


x86 assembly (clang, -O0):
<conv_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12e6 <conv_text+0x1d6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x9,%eax
je     1194 <conv_text+0x84>
jmp    1150 <conv_text+0x40>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     11bd <conv_text+0xad>
jmp    1161 <conv_text+0x51>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     11e6 <conv_text+0xd6>
jmp    1172 <conv_text+0x62>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     120f <conv_text+0xff>
jmp    1183 <conv_text+0x73>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
je     120f <conv_text+0xff>
jmp    123d <conv_text+0x12d>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x74,(%rax)
jmp    12d5 <conv_text+0x1c5>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x6e,(%rax)
jmp    12d5 <conv_text+0x1c5>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x72,(%rax)
jmp    12d5 <conv_text+0x1c5>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    12d5 <conv_text+0x1c5>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0x7f,%eax
cmp    $0x1f,%eax
jle    127f <conv_text+0x16f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0x7f,%eax
cmp    $0x7f,%eax
jge    127f <conv_text+0x16f>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    12d0 <conv_text+0x1c0>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%edx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12cb <conv_text+0x1bb>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    12aa <conv_text+0x19a>
jmp    12d0 <conv_text+0x1c0>
jmp    12d5 <conv_text+0x1c5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1128 <conv_text+0x18>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conv_text>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    (%rsi),%al
test   %al,%al
je     11cf <conv_text+0xbf>
mov    %rsi,%r13
lea    0xf38(%rip),%r15
lea    0xec9(%rip),%r12
mov    %r14,%rbx
jmp    1160 <conv_text+0x50>
nopl   0x0(%rax)
movb   $0x5c,(%rbx)
mov    0x0(%r13),%al
mov    %al,0x1(%rbx)
add    $0x2,%rbx
mov    %rbx,%rdi
mov    0x1(%r13),%al
add    $0x1,%r13
mov    %rdi,%rbx
test   %al,%al
je     11cf <conv_text+0xbf>
movsbl %al,%ecx
lea    -0x9(%rcx),%edx
cmp    $0x19,%edx
ja     1180 <conv_text+0x70>
movslq (%r12,%rdx,4),%rdx
add    %r12,%rdx
jmp    *%rdx
movw   $0x745c,(%rbx)
jmp    114a <conv_text+0x3a>
nopl   0x0(%rax,%rax,1)
cmp    $0x5c,%ecx
je     1140 <conv_text+0x30>
and    $0x7f,%ecx
lea    0x1(%rbx),%rdi
cmp    $0x20,%ecx
jb     11a8 <conv_text+0x98>
cmp    $0x7f,%ecx
je     11a8 <conv_text+0x98>
mov    %al,(%rbx)
jmp    1151 <conv_text+0x41>
movw   $0x6e5c,(%rbx)
jmp    114a <conv_text+0x3a>
movw   $0x725c,(%rbx)
jmp    114a <conv_text+0x3a>
movb   $0x5c,(%rbx)
movsbl 0x0(%r13),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%rdi
cmpb   $0x0,0x1(%rbx)
mov    %rdi,%rbx
jne    11c0 <conv_text+0xb0>
jmp    1151 <conv_text+0x41>
movb   $0x0,(%rdi)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%o\00"
define i8* @conv_text(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %73, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %76
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %38 [
i32 9, label %16
i32 10, label %21
i32 13, label %26
i32 34, label %31
i32 92, label %31
]
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
store i8 92, i8* %17
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
store i8 116, i8* %19
br label %73
21: ; preds = %12
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 92, i8* %22
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
store i8 110, i8* %24
br label %73
26: ; preds = %12
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %3
store i8 92, i8* %27
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
store i8 114, i8* %29
br label %73
31: ; preds = %12, %12
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
store i8 92, i8* %32
%34 = load i8*, i8** %4
%35 = load i8, i8* %34
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
store i8 %35, i8* %36
br label %73
38: ; preds = %12
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = and i32 %41, 127
%43 = icmp sgt i32 %42, 31
br i1 %43, label %44, label %55
44: ; preds = %38
%45 = load i8*, i8** %4
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = and i32 %47, 127
%49 = icmp slt i32 %48, 127
br i1 %49, label %50, label %55
50: ; preds = %44
%51 = load i8*, i8** %4
%52 = load i8, i8* %51
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %3
store i8 %52, i8* %53
br label %72
55: ; preds = %44, %38
%56 = load i8*, i8** %3
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %3
store i8 92, i8* %56
%58 = load i8*, i8** %3
%59 = load i8*, i8** %4
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = call i32 (i8*, i8*, ...) @sprintf(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %68, %55
%64 = load i8*, i8** %3
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i8*, i8** %3
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %3
br label %63
71: ; preds = %63
br label %72
72: ; preds = %71, %50
br label %73
73: ; preds = %72, %31, %26, %21, %16
%74 = load i8*, i8** %4
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %4
br label %7
76: ; preds = %7
%77 = load i8*, i8** %3
store i8 0, i8* %77
%78 = load i8*, i8** %5
ret i8* %78
}

LLVM IR (-O2):
@.str = [3 x i8] c"%o\00"
define i8* @conv_text(i8* returned %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %44, label %5
5: ; preds = %2, %39
%6 = phi i8 [ %42, %39 ], [ %3, %2 ]
%7 = phi i8* [ %40, %39 ], [ %0, %2 ]
%8 = phi i8* [ %41, %39 ], [ %1, %2 ]
%9 = sext i8 %6 to i32
switch i32 %9, label %23 [
i32 9, label %10
i32 10, label %13
i32 13, label %16
i32 34, label %19
i32 92, label %19
]
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%12 = getelementptr inbounds i8, i8* %7, i64 2
store i8 116, i8* %11
br label %39
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%15 = getelementptr inbounds i8, i8* %7, i64 2
store i8 110, i8* %14
br label %39
16: ; preds = %5
%17 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%18 = getelementptr inbounds i8, i8* %7, i64 2
store i8 114, i8* %17
br label %39
19: ; preds = %5, %5
%20 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
%21 = load i8, i8* %8
%22 = getelementptr inbounds i8, i8* %7, i64 2
store i8 %21, i8* %20
br label %39
23: ; preds = %5
%24 = and i32 %9, 127
%25 = icmp ult i32 %24, 32
%26 = icmp eq i32 %24, 127
%27 = or i1 %25, %26
%28 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %27, label %30, label %29
29: ; preds = %23
store i8 %6, i8* %7
br label %39
30: ; preds = %23
store i8 92, i8* %7
%31 = load i8, i8* %8
%32 = sext i8 %31 to i32
%33 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %34, %30
%35 = phi i8* [ %28, %30 ], [ %38, %34 ]
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
%38 = getelementptr inbounds i8, i8* %35, i64 1
br i1 %37, label %39, label %34
39: ; preds = %34, %29, %19, %16, %13, %10
%40 = phi i8* [ %28, %29 ], [ %22, %19 ], [ %18, %16 ], [ %15, %13 ], [ %12, %10 ], [ %35, %34 ]
%41 = getelementptr inbounds i8, i8* %8, i64 1
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %5
44: ; preds = %39, %2
%45 = phi i8* [ %0, %2 ], [ %40, %39 ]
store i8 0, i8* %45
ret i8* %0
}