#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 *, int);
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", (int)(unsigned char)ch);
  }
  (*buf)[4] = '\0';
  return *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
movsbl -0x1(%rbp),%ecx
mov    $0x5,%esi
lea    0xef0(%rip),%rdx
call   1040 <snprintf@plt>
jmp    12c8 <escape_character+0x1a8>
mov    -0x10(%rbp),%rdi
movzbl -0x1(%rbp),%ecx
mov    $0x5,%esi
lea    0xed5(%rip),%rdx
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
mov    %edi,%ecx
cmp    $0x5c,%edi
ja     1146 <escape_character+0x26>
mov    %ecx,%eax
lea    0xecc(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
lea    0x1030(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    -0x20(%rcx),%eax
cmp    $0x5e,%al
ja     11d3 <escape_character+0xb3>
lea    0x103d(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
jmp    11e5 <escape_character+0xc5>
lea    0x100b(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0x1005(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0x1008(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0xff9(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0xff9(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0xfe4(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0xfe1(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0xfe7(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0xfdb(%rip),%rsi
jmp    11bd <escape_character+0x9d>
lea    0xfcf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x4(%rbx)
mov    %rbx,%rax
pop    %rbx
ret
movzbl %cl,%ecx
lea    0xfbb(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <snprintf@plt>
jmp    11ca <escape_character+0xaa>

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 %72
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 %72
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 %72
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 %72
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 %72
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 %72
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 %72
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 %72
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 %72
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 %72
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 %72
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 %65
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 %65
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 = sext i8 %62 to i32
%64 = call i32 @snprintf(i8* %61, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i32 %63)
br label %71
65: ; preds = %55, %51
%66 = load [5 x i8]*, [5 x i8]** %4
%67 = getelementptr inbounds [5 x i8], [5 x i8]* %66, i64 0, i64 0
%68 = load i8, i8* %3
%69 = zext i8 %68 to i32
%70 = call i32 @snprintf(i8* %67, i32 5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %65, %59
br label %72
72: ; preds = %71, %47, %43, %39, %35, %31, %27, %23, %19, %15, %11, %7
%73 = load [5 x i8]*, [5 x i8]** %4
%74 = getelementptr inbounds [5 x i8], [5 x i8]* %73, i64 0, i64 4
store i8 0, i8* %74
%75 = load [5 x i8]*, [5 x i8]** %4
%76 = getelementptr inbounds [5 x i8], [5 x i8]* %75, i64 0, i64 0
ret i8* %76
}

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 %46
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 %46
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 %46
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 %46
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 %46
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 %46
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 %46
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 %46
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 %46
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 %46
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 %46
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), i32 %3)
br label %46
43: ; preds = %37
%44 = zext i8 %0 to i32
%45 = tail call i32 @snprintf(i8* %40, i32 5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %41, %43, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %4
%47 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 4
store i8 0, i8* %47
%48 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
ret i8* %48
}