#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*/ snprintf(char *, int, char *, unsigned char);
int /*<<< orphan*/ strncpy(char *, char *, int);
const char *escape_character(char ch, char (*buf)[5]) {
  switch (ch) {
  case '\x00':
    strncpy(*buf, "\\0", 5);
    break;
  case '\x07':
    strncpy(*buf, "\\a", 5);
    break;
  case '\x08':
    strncpy(*buf, "\\b", 5);
    break;
  case '\x0c':
    strncpy(*buf, "\\f", 5);
    break;
  case '\x0a':
    strncpy(*buf, "\\n", 5);
    break;
  case '\x0d':
    strncpy(*buf, "\\r", 5);
    break;
  case '\x09':
    strncpy(*buf, "\\t", 5);
    break;
  case '\x0b':
    strncpy(*buf, "\\v", 5);
    break;
  case '\\':
    strncpy(*buf, "\\\\", 5);
    break;
  case '\'':
    strncpy(*buf, "\\\'", 5);
    break;
  case '\"':
    strncpy(*buf, "\\\"", 5);
    break;
  default:
    if (ch >= '\x20' && ch < '\x7f')
      snprintf(*buf, 5, "%c", ch);
    else
      snprintf(*buf, 5, "\\x%02x", (unsigned char)ch);
  }
  (*buf)[4] = '\0';
  return (char *)buf;
}


x86 assembly (clang, -O0):
<escape_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x5c,%eax
ja     1277 <escape_character+0x157>
mov    -0x18(%rbp),%rax
lea    0xeb0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0x1010(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xff9(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xfe2(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xfcb(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xfb4(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xf9d(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xf86(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xf6f(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xf58(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xf41(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rdi
lea    0xf2a(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncpy@plt>
jmp    12cd <escape_character+0x1ad>
movsbl -0x1(%rbp),%eax
cmp    $0x20,%eax
jl     12af <escape_character+0x18f>
movsbl -0x1(%rbp),%eax
cmp    $0x7f,%eax
jge    12af <escape_character+0x18f>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
lea    0xef4(%rip),%rdx
movzbl -0x1(%rbp),%ecx
call   1040 <snprintf@plt>
jmp    12c8 <escape_character+0x1a8>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
lea    0xed9(%rip),%rdx
movzbl -0x1(%rbp),%ecx
call   1040 <snprintf@plt>
jmp    12cd <escape_character+0x1ad>
mov    -0x10(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_character>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x5c,%edi
ja     1144 <escape_character+0x24>
mov    %edi,%eax
lea    0xece(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0x1032(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    -0x20(%rdi),%eax
movzbl %dil,%ecx
cmp    $0x5e,%al
ja     11c6 <escape_character+0xa6>
lea    0x103f(%rip),%rdx
jmp    11cd <escape_character+0xad>
lea    0x1018(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0x1012(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0x1015(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0x1006(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0x1006(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0xff1(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0xfee(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0xff4(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0xfe8(%rip),%rsi
jmp    11b0 <escape_character+0x90>
lea    0xfdc(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4(%rbx)
mov    %rbx,%rax
pop    %rbx
ret
lea    0xfcb(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <snprintf@plt>
jmp    11bd <escape_character+0x9d>

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

LLVM IR (-O2):
@.str = [3 x i8] c"\\0\00"
@.str.1 = [3 x i8] c"\\a\00"
@.str.2 = [3 x i8] c"\\b\00"
@.str.3 = [3 x i8] c"\\f\00"
@.str.4 = [3 x i8] c"\\n\00"
@.str.5 = [3 x i8] c"\\r\00"
@.str.6 = [3 x i8] c"\\t\00"
@.str.7 = [3 x i8] c"\\v\00"
@.str.8 = [3 x i8] c"\\\\\00"
@.str.9 = [3 x i8] c"\\'\00"
@.str.10 = [3 x i8] c"\\\22\00"
@.str.11 = [3 x i8] c"%c\00"
@.str.12 = [7 x i8] c"\\x%02x\00"
define i8* @escape_character(i8 signext %0, [5 x i8]* %1) {
%3 = sext i8 %0 to i32
switch i32 %3, label %37 [
i32 0, label %4
i32 7, label %7
i32 8, label %10
i32 12, label %13
i32 10, label %16
i32 13, label %19
i32 9, label %22
i32 11, label %25
i32 92, label %28
i32 39, label %31
i32 34, label %34
]
4: ; preds = %2
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%6 = tail call i32 @strncpy(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 5)
br label %45
7: ; preds = %2
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%9 = tail call i32 @strncpy(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 5)
br label %45
10: ; preds = %2
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%12 = tail call i32 @strncpy(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 5)
br label %45
13: ; preds = %2
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%15 = tail call i32 @strncpy(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 5)
br label %45
16: ; preds = %2
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%18 = tail call i32 @strncpy(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 5)
br label %45
19: ; preds = %2
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%21 = tail call i32 @strncpy(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 5)
br label %45
22: ; preds = %2
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%24 = tail call i32 @strncpy(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 5)
br label %45
25: ; preds = %2
%26 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%27 = tail call i32 @strncpy(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 5)
br label %45
28: ; preds = %2
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%30 = tail call i32 @strncpy(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 5)
br label %45
31: ; preds = %2
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%33 = tail call i32 @strncpy(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 5)
br label %45
34: ; preds = %2
%35 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%36 = tail call i32 @strncpy(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 5)
br label %45
37: ; preds = %2
%38 = add i8 %0, -32
%39 = icmp ult i8 %38, 95
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
br i1 %39, label %41, label %43
41: ; preds = %37
%42 = tail call i32 @snprintf(i8* %40, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8 zeroext %0)
br label %45
43: ; preds = %37
%44 = tail call i32 @snprintf(i8* %40, i32 5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8 zeroext %0)
br label %45
45: ; preds = %41, %43, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %4
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 4
store i8 0, i8* %46
%47 = getelementptr [5 x i8], [5 x i8]* %1, i64 0, i64 0
ret i8* %47
}