#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 char);
int /*<<< orphan*/ fputc(char const, int /*<<< orphan*/ *);
scalar_t__ iscntrl(unsigned char);
int /*<<< orphan*/ isprint(unsigned char);
void fputs_quoted(const char *data, FILE *out) {
  const char *p;
  fputc('"', out);
  for (p = data; p && *p; p++) {
    if ((unsigned char)*p == 0x22 || (unsigned char)*p == 0x5c ||
        (unsigned char)*p == 0x60 || (unsigned char)*p == 0x24 ||
        !isprint((unsigned char)*p) || iscntrl((unsigned char)*p)) {
      fprintf(out, "\\x%02x", (unsigned char)*p);
    } else
      fputc(*p, out);
  }
  fputc('"', out);
}


x86 assembly (clang, -O0):
<fputs_quoted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x22,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     1186 <fputs_quoted+0x46>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1196 <fputs_quoted+0x56>
jmp    1245 <fputs_quoted+0x105>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x22,%eax
je     1201 <fputs_quoted+0xc1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5c,%eax
je     1201 <fputs_quoted+0xc1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x60,%eax
je     1201 <fputs_quoted+0xc1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x24,%eax
je     1201 <fputs_quoted+0xc1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1060 <isprint@plt>
cmp    $0x0,%eax
je     1201 <fputs_quoted+0xc1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%rax
je     121d <fputs_quoted+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xdf0(%rip),%rsi
movzbl (%rax),%edx
call   1050 <fprintf@plt>
jmp    122f <fputs_quoted+0xef>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1234 <fputs_quoted+0xf4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1166 <fputs_quoted+0x26>
mov    -0x10(%rbp),%rsi
mov    $0x22,%edi
call   1040 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputs_quoted>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x22,%edi
call   1040 <fputc@plt>
test   %rbx,%rbx
je     11c4 <fputs_quoted+0x84>
lea    0xe9c(%rip),%r15
movabs $0x4400000000000005,%r12
jmp    1182 <fputs_quoted+0x42>
movzbl (%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
lea    -0x22(%rax),%ecx
cmp    $0x3e,%cl
ja     1196 <fputs_quoted+0x56>
movzbl %cl,%ecx
bt     %rcx,%r12
jb     1170 <fputs_quoted+0x30>
test   %al,%al
je     11c4 <fputs_quoted+0x84>
movzbl %al,%edi
call   1060 <isprint@plt>
test   %eax,%eax
je     1170 <fputs_quoted+0x30>
movzbl (%rbx),%edi
call   1030 <iscntrl@plt>
test   %rax,%rax
jne    1170 <fputs_quoted+0x30>
movsbl (%rbx),%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbx
jmp    1182 <fputs_quoted+0x42>
mov    $0x22,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <fputc@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"\\x%02x\00"
define void @fputs_quoted(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %4
%7 = call i32 @fputc(i8 signext 34, i32* %6)
%8 = load i8*, i8** %3
store i8* %8, i8** %5
br label %9
9: ; preds = %60, %2
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br label %17
17: ; preds = %12, %9
%18 = phi i1 [ false, %9 ], [ %16, %12 ]
br i1 %18, label %19, label %63
19: ; preds = %17
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %22, 34
br i1 %23, label %49, label %24
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp eq i32 %27, 92
br i1 %28, label %49, label %29
29: ; preds = %24
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 96
br i1 %33, label %49, label %34
34: ; preds = %29
%35 = load i8*, i8** %5
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 36
br i1 %38, label %49, label %39
39: ; preds = %34
%40 = load i8*, i8** %5
%41 = load i8, i8* %40
%42 = call i32 @isprint(i8 zeroext %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = call i64 @iscntrl(i8 zeroext %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44, %39, %34, %29, %24, %19
%50 = load i32*, i32** %4
%51 = load i8*, i8** %5
%52 = load i8, i8* %51
%53 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %52)
br label %59
54: ; preds = %44
%55 = load i8*, i8** %5
%56 = load i8, i8* %55
%57 = load i32*, i32** %4
%58 = call i32 @fputc(i8 signext %56, i32* %57)
br label %59
59: ; preds = %54, %49
br label %60
60: ; preds = %59
%61 = load i8*, i8** %5
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %5
br label %9
63: ; preds = %17
%64 = load i32*, i32** %4
%65 = call i32 @fputc(i8 signext 34, i32* %64)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"\\x%02x\00"
define void @fputs_quoted(i8* %0, i32* nocapture %1) {
%3 = tail call i32 @fputc(i8 signext 34, i32* %1)
%4 = icmp eq i8* %0, null
br i1 %4, label %23, label %5
5: ; preds = %2, %21
%6 = phi i8* [ %22, %21 ], [ %0, %2 ]
%7 = load i8, i8* %6
switch i8 %7, label %8 [
i8 0, label %23
i8 34, label %15
i8 92, label %15
i8 96, label %15
i8 36, label %15
]
8: ; preds = %5
%9 = tail call i32 @isprint(i8 zeroext %7)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i8, i8* %6
%13 = tail call i64 @iscntrl(i8 zeroext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %5, %5, %5, %5, %11, %8
%16 = load i8, i8* %6
%17 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %16)
br label %21
18: ; preds = %11
%19 = load i8, i8* %6
%20 = tail call i32 @fputc(i8 signext %19, i32* %1)
br label %21
21: ; preds = %15, %18
%22 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
23: ; preds = %5, %2
%24 = tail call i32 @fputc(i8 signext 34, i32* %1)
ret void
}