#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 *, char const);
int /*<<< orphan*/ isprint(char const);
int /*<<< orphan*/ putc(char const, int /*<<< orphan*/ *);
scalar_t__ strchr(char const *, char const);
int strlen(char const *);
void FormatPrintEscapedString(FILE *stream, const char *string, int length,
                              const char *escapableChars) {
  if (length < 0)
    length = strlen(string);
  while (length > 0) {
    if (!isprint(*string) || *string == '\\' ||
        (escapableChars && strchr(escapableChars, *string))) {
      fprintf(stream, "\\x%02X", *string & 0xFF);
    } else {
      putc(*string, stream);
    }
    string++;
    length--;
  }
}


x86 assembly (clang, -O0):
<FormatPrintEscapedString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117d <FormatPrintEscapedString+0x2d>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
jmp    1182 <FormatPrintEscapedString+0x32>
cmpl   $0x0,-0x14(%rbp)
jle    1226 <FormatPrintEscapedString+0xd6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1070 <isprint@plt>
cmp    $0x0,%eax
je     11d6 <FormatPrintEscapedString+0x86>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     11d6 <FormatPrintEscapedString+0x86>
cmpq   $0x0,-0x20(%rbp)
je     11fa <FormatPrintEscapedString+0xaa>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11fa <FormatPrintEscapedString+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
and    $0xff,%eax
lea    0xe13(%rip),%rsi
movsbl %al,%edx
call   1060 <fprintf@plt>
jmp    120c <FormatPrintEscapedString+0xbc>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <FormatPrintEscapedString+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FormatPrintEscapedString>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
test   %edx,%edx
js     116d <FormatPrintEscapedString+0x1d>
test   %ebp,%ebp
jg     117b <FormatPrintEscapedString+0x2b>
jmp    11e2 <FormatPrintEscapedString+0x92>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %ebp,%ebp
jle    11e2 <FormatPrintEscapedString+0x92>
add    $0x1,%ebp
lea    0xe7b(%rip),%r12
jmp    11aa <FormatPrintEscapedString+0x5a>
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <fprintf@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    11e2 <FormatPrintEscapedString+0x92>
movsbl (%rbx),%edi
call   1070 <isprint@plt>
test   %eax,%eax
je     1190 <FormatPrintEscapedString+0x40>
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1190 <FormatPrintEscapedString+0x40>
test   %r14,%r14
je     11d5 <FormatPrintEscapedString+0x85>
movsbl %al,%esi
mov    %r14,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1190 <FormatPrintEscapedString+0x40>
movzbl (%rbx),%eax
movsbl %al,%edi
mov    %r15,%rsi
call   1050 <putc@plt>
jmp    119e <FormatPrintEscapedString+0x4e>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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