#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ isprint(int);
void print_char(int c, FILE *fh) {
  if (isprint(c)) {
    fputc(c, fh);
    return;
  }
  switch (c) {
  case '\a':
    fputs("\\a", fh);
    return;
  case '\b':
    fputs("\\b", fh);
    return;
  case '\f':
    fputs("\\f", fh);
    return;
  case '\n':
    fputs("\\n", fh);
    return;
  case '\r':
    fputs("\\r", fh);
    return;
  case '\t':
    fputs("\\t", fh);
    return;
  default:
    break;
  }
  fprintf(fh, "\\x%X", c);
}


x86 assembly (clang, -O0):
<print_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     1172 <print_char+0x32>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <fputc@plt>
jmp    1231 <print_char+0xf1>
mov    -0x4(%rbp),%eax
add    $0xfffffff9,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     1219 <print_char+0xd9>
mov    -0x18(%rbp),%rax
lea    0xe6e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1030 <fputs@plt>
jmp    1231 <print_char+0xf1>
mov    -0x10(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1030 <fputs@plt>
jmp    1231 <print_char+0xf1>
mov    -0x10(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1030 <fputs@plt>
jmp    1231 <print_char+0xf1>
mov    -0x10(%rbp),%rsi
lea    0xe40(%rip),%rdi
call   1030 <fputs@plt>
jmp    1231 <print_char+0xf1>
mov    -0x10(%rbp),%rsi
lea    0xe2e(%rip),%rdi
call   1030 <fputs@plt>
jmp    1231 <print_char+0xf1>
mov    -0x10(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1030 <fputs@plt>
jmp    1231 <print_char+0xf1>
jmp    121e <print_char+0xde>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe02(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_char>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
call   1050 <isprint@plt>
test   %rax,%rax
je     1164 <print_char+0x24>
mov    %ebx,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fputc@plt>
lea    -0x7(%rbx),%eax
cmp    $0x6,%eax
ja     11a0 <print_char+0x60>
lea    0xe8d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe99(%rip),%rdi
jmp    11c8 <print_char+0x88>
lea    0xe93(%rip),%rdi
jmp    11c8 <print_char+0x88>
lea    0xe96(%rip),%rdi
jmp    11c8 <print_char+0x88>
lea    0xe87(%rip),%rdi
jmp    11c8 <print_char+0x88>
lea    0xe87(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fprintf@plt>
lea    0xe63(%rip),%rdi
jmp    11c8 <print_char+0x88>
lea    0xe60(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <fwrite@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\\a\00"
@.str.1 = [3 x i8] c"\\b\00"
@.str.2 = [3 x i8] c"\\f\00"
@.str.3 = [3 x i8] c"\\n\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [3 x i8] c"\\t\00"
@.str.6 = [5 x i8] c"\\x%X\00"
define void @print_char(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
store i32 %0, i32* %3
store i32* %1, i32** %4
%5 = load i32, i32* %3
%6 = call i64 @isprint(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* %3
%10 = load i32*, i32** %4
%11 = call i32 @fputc(i32 %9, i32* %10)
br label %37
12: ; preds = %2
%13 = load i32, i32* %3
switch i32 %13, label %32 [
i32 7, label %14
i32 8, label %17
i32 12, label %20
i32 10, label %23
i32 13, label %26
i32 9, label %29
]
14: ; preds = %12
%15 = load i32*, i32** %4
%16 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %15)
br label %37
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
br label %37
20: ; preds = %12
%21 = load i32*, i32** %4
%22 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %21)
br label %37
23: ; preds = %12
%24 = load i32*, i32** %4
%25 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %24)
br label %37
26: ; preds = %12
%27 = load i32*, i32** %4
%28 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %27)
br label %37
29: ; preds = %12
%30 = load i32*, i32** %4
%31 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %30)
br label %37
32: ; preds = %12
br label %33
33: ; preds = %32
%34 = load i32*, i32** %4
%35 = load i32, i32* %3
%36 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %33, %29, %26, %23, %20, %17, %14, %8
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\a\00"
@.str.1 = [3 x i8] c"\\b\00"
@.str.2 = [3 x i8] c"\\f\00"
@.str.3 = [3 x i8] c"\\n\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [3 x i8] c"\\t\00"
@.str.6 = [5 x i8] c"\\x%X\00"
define void @print_char(i32 %0, i32* nocapture %1) {
%3 = tail call i64 @isprint(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @fputc(i32 %0, i32* %1)
br label %22
7: ; preds = %2
switch i32 %0, label %20 [
i32 7, label %8
i32 8, label %10
i32 12, label %12
i32 10, label %14
i32 13, label %16
i32 9, label %18
]
8: ; preds = %7
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %22
10: ; preds = %7
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %22
12: ; preds = %7
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %22
14: ; preds = %7
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %22
16: ; preds = %7
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %22
18: ; preds = %7
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %1)
br label %22
20: ; preds = %7
%21 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %0)
br label %22
22: ; preds = %20, %18, %16, %14, %12, %10, %8, %5
ret void
}