#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 ||
        !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    1225 <fputs_quoted+0xe5>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x22,%eax
je     11e1 <fputs_quoted+0xa1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5c,%eax
je     11e1 <fputs_quoted+0xa1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1060 <isprint@plt>
cmp    $0x0,%eax
je     11e1 <fputs_quoted+0xa1>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%rax
je     11fd <fputs_quoted+0xbd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
lea    0xe10(%rip),%rsi
movzbl (%rax),%edx
call   1050 <fprintf@plt>
jmp    120f <fputs_quoted+0xcf>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1214 <fputs_quoted+0xd4>
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   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x22,%edi
call   1040 <fputc@plt>
test   %rbx,%rbx
je     11bb <fputs_quoted+0x7b>
lea    0xe9f(%rip),%r15
jmp    1182 <fputs_quoted+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x22,%al
je     1170 <fputs_quoted+0x30>
cmp    $0x5c,%al
je     1170 <fputs_quoted+0x30>
test   %al,%al
je     11bb <fputs_quoted+0x7b>
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
pop    %rbx
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 = %50, %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 %53
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 %39, 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 %39, label %29
29: ; preds = %24
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = call i32 @isprint(i8 zeroext %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i8*, i8** %5
%36 = load i8, i8* %35
%37 = call i64 @iscntrl(i8 zeroext %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34, %29, %24, %19
%40 = load i32*, i32** %4
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %42)
br label %49
44: ; preds = %34
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = load i32*, i32** %4
%48 = call i32 @fputc(i8 signext %46, i32* %47)
br label %49
49: ; preds = %44, %39
br label %50
50: ; preds = %49
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %5
br label %9
53: ; preds = %17
%54 = load i32*, i32** %4
%55 = call i32 @fputc(i8 signext 34, i32* %54)
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
]
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, %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
}