#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*/ isgraph(char);
int /*<<< orphan*/ sprintf(char *, char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void formatChar(char *str, char ch) {
  switch (ch) {
  case '\r':
    strcpy(str, "CR ");
    break;
  case '\n':
    strcpy(str, "LF ");
    break;
  case ' ':
    strcpy(str, "SP ");
    break;
  case 27:
    strcpy(str, "^[ ");
    break;
  case 3:
    strcpy(str, "^C ");
    break;
  default:
    if (isgraph(ch))
      sprintf(str, "%c ", ch);
    else
      sprintf(str, "%02x ", ch);
    break;
  }
}


x86 assembly (clang, -O0):
<formatChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
add    $0xfffffffd,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x1d,%eax
ja     11d5 <formatChar+0xa5>
mov    -0x18(%rbp),%rax
lea    0xe9d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
lea    0xf01(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1219 <formatChar+0xe9>
mov    -0x8(%rbp),%rdi
lea    0xef0(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1219 <formatChar+0xe9>
mov    -0x8(%rbp),%rdi
lea    0xedf(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1219 <formatChar+0xe9>
mov    -0x8(%rbp),%rdi
lea    0xece(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1219 <formatChar+0xe9>
mov    -0x8(%rbp),%rdi
lea    0xebd(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1219 <formatChar+0xe9>
movsbl -0x9(%rbp),%edi
call   1050 <isgraph@plt>
cmp    $0x0,%eax
je     1200 <formatChar+0xd0>
mov    -0x8(%rbp),%rdi
lea    0xe9a(%rip),%rsi
movsbl -0x9(%rbp),%edx
call   1040 <sprintf@plt>
jmp    1214 <formatChar+0xe4>
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
movsbl -0x9(%rbp),%edx
call   1040 <sprintf@plt>
jmp    1219 <formatChar+0xe9>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<formatChar>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    -0x3(%rsi),%eax
cmp    $0x1d,%eax
ja     1157 <formatChar+0x27>
lea    0xebb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf33(%rip),%rsi
jmp    1191 <formatChar+0x61>
movsbl %sil,%ebp
mov    %ebp,%edi
call   1050 <isgraph@plt>
test   %eax,%eax
je     119f <formatChar+0x6f>
lea    0xf1f(%rip),%rsi
jmp    11a6 <formatChar+0x76>
lea    0xf06(%rip),%rsi
jmp    1191 <formatChar+0x61>
lea    0xef9(%rip),%rsi
jmp    1191 <formatChar+0x61>
lea    0xefc(%rip),%rsi
jmp    1191 <formatChar+0x61>
lea    0xeef(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <strcpy@plt>
lea    0xeea(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"CR \00"
@.str.1 = [4 x i8] c"LF \00"
@.str.2 = [4 x i8] c"SP \00"
@.str.3 = [4 x i8] c"^[ \00"
@.str.4 = [4 x i8] c"^C \00"
@.str.5 = [4 x i8] c"%c \00"
@.str.6 = [6 x i8] c"%02x \00"
define void @formatChar(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
switch i32 %6, label %22 [
i32 13, label %7
i32 10, label %10
i32 32, label %13
i32 27, label %16
i32 3, label %19
]
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %35
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %35
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %35
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %35
19: ; preds = %2
%20 = load i8*, i8** %3
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %35
22: ; preds = %2
%23 = load i8, i8* %4
%24 = call i32 @isgraph(i8 signext %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i8*, i8** %3
%28 = load i8, i8* %4
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8 signext %28)
br label %34
30: ; preds = %22
%31 = load i8*, i8** %3
%32 = load i8, i8* %4
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8 signext %32)
br label %34
34: ; preds = %30, %26
br label %35
35: ; preds = %34, %19, %16, %13, %10, %7
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"CR \00"
@.str.1 = [4 x i8] c"LF \00"
@.str.2 = [4 x i8] c"SP \00"
@.str.3 = [4 x i8] c"^[ \00"
@.str.4 = [4 x i8] c"^C \00"
@.str.5 = [4 x i8] c"%c \00"
@.str.6 = [6 x i8] c"%02x \00"
define void @formatChar(i8* %0, i8 signext %1) {
%3 = sext i8 %1 to i32
switch i32 %3, label %14 [
i32 13, label %4
i32 10, label %6
i32 32, label %8
i32 27, label %10
i32 3, label %12
]
4: ; preds = %2
%5 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %21
6: ; preds = %2
%7 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %21
8: ; preds = %2
%9 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %21
10: ; preds = %2
%11 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %21
12: ; preds = %2
%13 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %21
14: ; preds = %2
%15 = tail call i32 @isgraph(i8 signext %1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8 signext %1)
br label %21
19: ; preds = %14
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8 signext %1)
br label %21
21: ; preds = %17, %19, %12, %10, %8, %6, %4
ret void
}