#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 *, unsigned int);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ isprint(unsigned char);
void print_quoted(FILE *file, unsigned char *s, int len) {
  for (int i = 0; i < len; i++) {
    switch (s[i]) {
    case '\n':
      fputs("\\n", file);
      continue;
    case '\r':
      fputs("\\r", file);
      continue;
    case '\t':
      fputs("\\t", file);
      continue;
    default:;
    }
    if (isprint(s[i]))
      fputc(s[i], file);
    else
      fprintf(file, "\\x%2.2X", (unsigned)s[i]);
  }
}


x86 assembly (clang, -O0):
<print_quoted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    124f <print_quoted+0x10f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x9,%eax
je     11cf <print_quoted+0x8f>
jmp    1183 <print_quoted+0x43>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     11a5 <print_quoted+0x65>
jmp    1194 <print_quoted+0x54>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     11ba <print_quoted+0x7a>
jmp    11e4 <print_quoted+0xa4>
mov    -0x8(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1030 <fputs@plt>
jmp    1241 <print_quoted+0x101>
mov    -0x8(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1030 <fputs@plt>
jmp    1241 <print_quoted+0x101>
mov    -0x8(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1030 <fputs@plt>
jmp    1241 <print_quoted+0x101>
jmp    11e9 <print_quoted+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     1220 <print_quoted+0xe0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1040 <fputc@plt>
jmp    123c <print_quoted+0xfc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xdd2(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1241 <print_quoted+0x101>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115a <print_quoted+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_quoted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    11ff <print_quoted+0xbf>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%ebp
xor    %r15d,%r15d
lea    0xe9e(%rip),%r12
lea    0xe94(%rip),%r13
jmp    118e <print_quoted+0x4e>
xchg   %ax,%ax
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %r14,%rcx
call   1060 <fwrite@plt>
add    $0x1,%r15
cmp    %r15,%rbp
je     11ff <print_quoted+0xbf>
movzbl (%rbx,%r15,1),%eax
cmp    $0x9,%al
je     11b0 <print_quoted+0x70>
cmp    $0xd,%al
je     1170 <print_quoted+0x30>
cmp    $0xa,%al
jne    11d0 <print_quoted+0x90>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r13,%rdi
jmp    117d <print_quoted+0x3d>
xchg   %ax,%ax
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe45(%rip),%rdi
jmp    117d <print_quoted+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl %al,%edi
call   1050 <isprint@plt>
movzbl (%rbx,%r15,1),%edx
test   %rax,%rax
je     11ee <print_quoted+0xae>
mov    %edx,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    1185 <print_quoted+0x45>
mov    %r14,%rdi
lea    0xe11(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1185 <print_quoted+0x45>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"\\n\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\t\00"
@.str.3 = [8 x i8] c"\\x%2.2X\00"
define void @print_quoted(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %8
7: ; preds = %27, %3
ret void
8: ; preds = %5, %27
%9 = phi i64 [ 0, %5 ], [ %28, %27 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %18 [
i8 10, label %12
i8 13, label %14
i8 9, label %16
]
12: ; preds = %8
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %27
14: ; preds = %8
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %27
16: ; preds = %8
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %27
18: ; preds = %8
%19 = tail call i64 @isprint(i8 zeroext %11)
%20 = icmp eq i64 %19, 0
%21 = load i8, i8* %10
br i1 %20, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @fputc(i8 zeroext %21, i32* %0)
br label %27
24: ; preds = %18
%25 = zext i8 %21 to i32
%26 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %22, %24, %16, %14, %12
%28 = add nuw nsw i64 %9, 1
%29 = icmp eq i64 %28, %6
br i1 %29, label %7, label %8
}