#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, ...);
void escape(char *s, char *t) {
  unsigned char c;
  while (c = *t) {
    switch (c) {
    case '\t':
      s += sprintf(s, "\\t");
      break;
    case '\n':
      s += sprintf(s, "\\n");
      break;
    default:
      if (c >= 0x20 && c <= 0x7e)
        *(s++) = c;
      else
        s += sprintf(s, "\\x%02X", c);
    }
    t++;
  }
  *t = 0;
}


x86 assembly (clang, -O0):
<escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
cmp    $0x0,%al
je     1214 <escape+0x104>
movzbl -0x11(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x9,%eax
je     1157 <escape+0x47>
jmp    1146 <escape+0x36>
mov    -0x18(%rbp),%eax
sub    $0xa,%eax
je     117e <escape+0x6e>
jmp    11a5 <escape+0x95>
mov    -0x8(%rbp),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1203 <escape+0xf3>
mov    -0x8(%rbp),%rdi
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1203 <escape+0xf3>
movzbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jl     11d8 <escape+0xc8>
movzbl -0x11(%rbp),%eax
cmp    $0x7e,%eax
jg     11d8 <escape+0xc8>
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    11fe <escape+0xee>
mov    -0x8(%rbp),%rdi
movzbl -0x11(%rbp),%edx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1203 <escape+0xf3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <escape+0x10>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    (%rsi),%al
test   %al,%al
je     1188 <escape+0x78>
mov    %rdi,%r14
lea    0xede(%rip),%r15
jmp    114b <escape+0x3b>
nopw   0x0(%rax,%rax,1)
movb   $0x0,0x2(%r14)
movw   $0x6e5c,(%r14)
add    $0x2,%r14
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1188 <escape+0x78>
cmp    $0xa,%al
je     1130 <escape+0x20>
cmp    $0x9,%al
jne    1160 <escape+0x50>
movb   $0x0,0x2(%r14)
movw   $0x745c,(%r14)
jmp    113b <escape+0x2b>
lea    -0x20(%rax),%ecx
cmp    $0x5e,%cl
ja     1171 <escape+0x61>
mov    %al,(%r14)
add    $0x1,%r14
jmp    113f <escape+0x2f>
movzbl %al,%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
cltq
add    %rax,%r14
jmp    113f <escape+0x2f>
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\t\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [7 x i8] c"\\x%02X\00"
define void @escape(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %6
6: ; preds = %46, %2
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
store i8 %8, i8* %5
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %49
10: ; preds = %6
%11 = load i8, i8* %5
%12 = zext i8 %11 to i32
switch i32 %12, label %25 [
i32 9, label %13
i32 10, label %19
]
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %3
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8* %18, i8** %3
br label %46
19: ; preds = %10
%20 = load i8*, i8** %3
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = load i8*, i8** %3
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %3
br label %46
25: ; preds = %10
%26 = load i8, i8* %5
%27 = zext i8 %26 to i32
%28 = icmp sge i32 %27, 32
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i8, i8* %5
%31 = zext i8 %30 to i32
%32 = icmp sle i32 %31, 126
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i8, i8* %5
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
store i8 %34, i8* %35
br label %45
37: ; preds = %29, %25
%38 = load i8*, i8** %3
%39 = load i8, i8* %5
%40 = zext i8 %39 to i32
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i8*, i8** %3
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %3
br label %45
45: ; preds = %37, %33
br label %46
46: ; preds = %45, %19, %13
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %4
br label %6
49: ; preds = %6
%50 = load i8*, i8** %4
store i8 0, i8* %50
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\t\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [7 x i8] c"\\x%02X\00"
define void @escape(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %28, label %5
5: ; preds = %2, %23
%6 = phi i8 [ %26, %23 ], [ %3, %2 ]
%7 = phi i8* [ %24, %23 ], [ %0, %2 ]
%8 = phi i8* [ %25, %23 ], [ %1, %2 ]
%9 = zext i8 %6 to i32
switch i8 %6, label %14 [
i8 9, label %10
i8 10, label %12
]
10: ; preds = %5
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, i64 0, i64 0), i64 3, i1 false)
%11 = getelementptr inbounds i8, i8* %7, i64 2
br label %23
12: ; preds = %5
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.1, i64 0, i64 0), i64 3, i1 false)
%13 = getelementptr inbounds i8, i8* %7, i64 2
br label %23
14: ; preds = %5
%15 = add i8 %6, -32
%16 = icmp ult i8 %15, 95
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %6, i8* %7
br label %23
19: ; preds = %14
%20 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %7, i64 %21
br label %23
23: ; preds = %17, %19, %12, %10
%24 = phi i8* [ %18, %17 ], [ %22, %19 ], [ %13, %12 ], [ %11, %10 ]
%25 = getelementptr inbounds i8, i8* %8, i64 1
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %5
28: ; preds = %23, %2
%29 = phi i8* [ %1, %2 ], [ %25, %23 ]
store i8 0, i8* %29
ret void
}