#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*/ isprint(char);
size_t snprintf(char *, size_t, char *, ...);
size_t chrtos(char *buf, size_t size, char byte) {
  size_t len = 0;
  switch (byte) {
  case '\\':
  case '"':
    len = snprintf(buf, size, "\"\\%c\"", byte);
    break;
  case '\n':
    len = snprintf(buf, size, "\"\\n\"");
    break;
  case '\r':
    len = snprintf(buf, size, "\"\\r\"");
    break;
  case '\t':
    len = snprintf(buf, size, "\"\\t\"");
    break;
  case '\a':
    len = snprintf(buf, size, "\"\\a\"");
    break;
  case '\b':
    len = snprintf(buf, size, "\"\\b\"");
    break;
  default:
    if (isprint(byte))
      len = snprintf(buf, size, "\"%c\"", byte);
    else
      len = snprintf(buf, size, "\"\\x%02x\"", (unsigned char)byte);
    break;
  }
  return len;
}


x86 assembly (clang, -O0):
<chrtos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movq   $0x0,-0x20(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x7,%eax
je     1238 <chrtos+0x118>
jmp    1152 <chrtos+0x32>
mov    -0x24(%rbp),%eax
sub    $0x8,%eax
je     1257 <chrtos+0x137>
jmp    1163 <chrtos+0x43>
mov    -0x24(%rbp),%eax
sub    $0x9,%eax
je     1219 <chrtos+0xf9>
jmp    1174 <chrtos+0x54>
mov    -0x24(%rbp),%eax
sub    $0xa,%eax
je     11db <chrtos+0xbb>
jmp    1185 <chrtos+0x65>
mov    -0x24(%rbp),%eax
sub    $0xd,%eax
je     11fa <chrtos+0xda>
jmp    1196 <chrtos+0x76>
mov    -0x24(%rbp),%eax
sub    $0x22,%eax
je     11b8 <chrtos+0x98>
jmp    11a7 <chrtos+0x87>
mov    -0x24(%rbp),%eax
sub    $0x5c,%eax
jne    1276 <chrtos+0x156>
jmp    11b8 <chrtos+0x98>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsbl -0x11(%rbp),%ecx
lea    0xe35(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    12ce <chrtos+0x1ae>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe1c(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    12ce <chrtos+0x1ae>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe02(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    12ce <chrtos+0x1ae>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xde8(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    12ce <chrtos+0x1ae>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xdce(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    12ce <chrtos+0x1ae>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xdb4(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    12ce <chrtos+0x1ae>
movsbl -0x11(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%eax
je     12ab <chrtos+0x18b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsbl -0x11(%rbp),%ecx
lea    0xd84(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    12c9 <chrtos+0x1a9>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movzbl -0x11(%rbp),%ecx
lea    0xd66(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %rax,-0x20(%rbp)
jmp    12ce <chrtos+0x1ae>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chrtos>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
lea    -0x7(%rbx),%eax
cmp    $0x1b,%eax
ja     114e <chrtos+0x2e>
lea    0xec4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf39(%rip),%rdx
jmp    11a5 <chrtos+0x85>
cmp    $0x5c,%ebx
jne    115c <chrtos+0x3c>
lea    0xf16(%rip),%rdx
jmp    116f <chrtos+0x4f>
movsbl %bl,%edi
call   1040 <isprint@plt>
test   %eax,%eax
je     11b7 <chrtos+0x97>
lea    0xf20(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <snprintf@plt>
lea    0xf00(%rip),%rdx
jmp    11a5 <chrtos+0x85>
lea    0xeed(%rip),%rdx
jmp    11a5 <chrtos+0x85>
lea    0xeda(%rip),%rdx
jmp    11a5 <chrtos+0x85>
lea    0xed6(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <snprintf@plt>
movzbl %bl,%ecx
lea    0xed3(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
jmp    1177 <chrtos+0x57>

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

LLVM IR (-O2):
@.str = [6 x i8] c"\22\\%c\22\00"
@.str.1 = [5 x i8] c"\22\\n\22\00"
@.str.2 = [5 x i8] c"\22\\r\22\00"
@.str.3 = [5 x i8] c"\22\\t\22\00"
@.str.4 = [5 x i8] c"\22\\a\22\00"
@.str.5 = [5 x i8] c"\22\\b\22\00"
@.str.6 = [5 x i8] c"\22%c\22\00"
@.str.7 = [9 x i8] c"\22\\x%02x\22\00"
define i64 @chrtos(i8* %0, i64 %1, i8 signext %2) {
%4 = sext i8 %2 to i32
switch i32 %4, label %17 [
i32 92, label %5
i32 34, label %5
i32 10, label %7
i32 13, label %9
i32 9, label %11
i32 7, label %13
i32 8, label %15
]
5: ; preds = %3, %3
%6 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %25
7: ; preds = %3
%8 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %25
9: ; preds = %3
%10 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %25
11: ; preds = %3
%12 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %25
13: ; preds = %3
%14 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %25
15: ; preds = %3
%16 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %25
17: ; preds = %3
%18 = tail call i32 @isprint(i8 signext %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %4)
br label %25
22: ; preds = %17
%23 = zext i8 %2 to i32
%24 = tail call i64 (i8*, i64, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %20, %22, %15, %13, %11, %9, %7, %5
%26 = phi i64 [ %21, %20 ], [ %24, %22 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
ret i64 %26
}