#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 *, unsigned int);
int /*<<< orphan*/ strcpy(char *, char *);
void char_to_escape(char *dest, unsigned int c) {
  switch (c) {
  case '\r':
    strcpy(dest, "\\r");
    break;
  case '\n':
    strcpy(dest, "\\n");
    break;
  case '\t':
    strcpy(dest, "\\t");
    break;
  case '\f':
    strcpy(dest, "\\f");
    break;
  default:
    sprintf(dest, "\\%03o", c);
    break;
  }
}


x86 assembly (clang, -O0):
<char_to_escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xfffffff7,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x4,%eax
ja     11ac <char_to_escape+0x8c>
mov    -0x18(%rbp),%rax
lea    0xeb1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bf <char_to_escape+0x9f>
mov    -0x8(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bf <char_to_escape+0x9f>
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bf <char_to_escape+0x9f>
mov    -0x8(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11bf <char_to_escape+0x9f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe66(%rip),%rsi
call   1040 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_escape>:
mov    %esi,%edx
lea    -0x9(%rdx),%eax
cmp    $0x4,%eax
ja     1152 <char_to_escape+0x32>
lea    0xecf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed9(%rip),%rsi
jmp    1030 <strcpy@plt>
lea    0xeca(%rip),%rsi
jmp    1030 <strcpy@plt>
lea    0xec7(%rip),%rsi
jmp    1040 <sprintf@plt>
lea    0xeb8(%rip),%rsi
jmp    1030 <strcpy@plt>
lea    0xea3(%rip),%rsi
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\\r\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"\\t\00"
@.str.3 = [3 x i8] c"\\f\00"
@.str.4 = [6 x i8] c"\\%03o\00"
define void @char_to_escape(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
switch i32 %5, label %18 [
i32 13, label %6
i32 10, label %9
i32 9, label %12
i32 12, label %15
]
6: ; preds = %2
%7 = load i8*, i8** %3
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %22
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %22
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %22
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %15, %12, %9, %6
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\r\00"
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"\\t\00"
@.str.3 = [3 x i8] c"\\f\00"
@.str.4 = [6 x i8] c"\\%03o\00"
define void @char_to_escape(i8* %0, i32 %1) {
switch i32 %1, label %11 [
i32 13, label %3
i32 10, label %5
i32 9, label %7
i32 12, label %9
]
3: ; preds = %2
%4 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %13
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %13
7: ; preds = %2
%8 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %13
9: ; preds = %2
%10 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %13
11: ; preds = %2
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %1)
br label %13
13: ; preds = %11, %9, %7, %5, %3
ret void
}