#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);
char const tolower(char const);
char const toupper(char const);
void fputs_quoted_case(const char *data, FILE *out, int dir) {
  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(dir == 1 ? toupper(*p) : dir == -1 ? tolower(*p) : *p, out);
  }
  fputc('"', out);
}


x86 assembly (clang, -O0):
<fputs_quoted_case>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x22,%edi
call   1050 <fputc@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     11a9 <fputs_quoted_case+0x49>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11b9 <fputs_quoted_case+0x59>
jmp    12b7 <fputs_quoted_case+0x157>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x22,%eax
je     1224 <fputs_quoted_case+0xc4>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5c,%eax
je     1224 <fputs_quoted_case+0xc4>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x60,%eax
je     1224 <fputs_quoted_case+0xc4>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x24,%eax
je     1224 <fputs_quoted_case+0xc4>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1080 <isprint@plt>
cmp    $0x0,%eax
je     1224 <fputs_quoted_case+0xc4>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1040 <iscntrl@plt>
cmp    $0x0,%rax
je     1240 <fputs_quoted_case+0xe0>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
lea    0xdcd(%rip),%rsi
movzbl (%rax),%edx
call   1060 <fprintf@plt>
jmp    12a1 <fputs_quoted_case+0x141>
cmpl   $0x1,-0x14(%rbp)
jne    1261 <fputs_quoted_case+0x101>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
mov    %eax,-0x28(%rbp)
jmp    1292 <fputs_quoted_case+0x132>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1282 <fputs_quoted_case+0x122>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1070 <tolower@plt>
movsbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    128c <fputs_quoted_case+0x12c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    12a6 <fputs_quoted_case+0x146>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1189 <fputs_quoted_case+0x29>
mov    -0x10(%rbp),%rsi
mov    $0x22,%edi
call   1050 <fputc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputs_quoted_case>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    $0x22,%edi
call   1050 <fputc@plt>
test   %rbp,%rbp
je     121d <fputs_quoted_case+0xbd>
lea    0xe75(%rip),%r15
movabs $0x4400000000000005,%r12
jmp    11b3 <fputs_quoted_case+0x53>
nopw   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbp
movzbl 0x0(%rbp),%eax
lea    -0x22(%rax),%ecx
cmp    $0x3e,%cl
ja     11c8 <fputs_quoted_case+0x68>
movzbl %cl,%ecx
bt     %rcx,%r12
jb     11a0 <fputs_quoted_case+0x40>
test   %al,%al
je     121d <fputs_quoted_case+0xbd>
movzbl %al,%edi
call   1080 <isprint@plt>
test   %eax,%eax
je     11a0 <fputs_quoted_case+0x40>
movzbl 0x0(%rbp),%edi
call   1040 <iscntrl@plt>
test   %rax,%rax
jne    11a0 <fputs_quoted_case+0x40>
cmp    $0xffffffff,%r14d
je     11fd <fputs_quoted_case+0x9d>
cmp    $0x1,%r14d
jne    1208 <fputs_quoted_case+0xa8>
movsbl 0x0(%rbp),%edi
call   1030 <toupper@plt>
jmp    120c <fputs_quoted_case+0xac>
movsbl 0x0(%rbp),%edi
call   1070 <tolower@plt>
jmp    120c <fputs_quoted_case+0xac>
movzbl 0x0(%rbp),%eax
movsbl %al,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbp
jmp    11b3 <fputs_quoted_case+0x53>
mov    $0x22,%edi
mov    %rbx,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fputc@plt>

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

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